Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
title: onSet(value => (instance.locked ? instance.title : value))(
string({ validation: validation.create("required") })
),
snippet: onSet(value => (instance.locked ? instance.snippet : value))(string()),
url: onSet(value => (instance.locked ? instance.url : value))(
string({ validation: validation.create("required") })
),
content: onSet(value => (instance.locked ? instance.content : value))(
content({ context })
),
settings: onSet(value => (instance.locked ? instance.settings : value))(
fields({
instanceOf: PbPageSettings
})
),
version: number(),
parent: context.commodo.fields.id(),
published: flow(
onSet(value => {
// Deactivate previously published revision
if (value && value !== instance.published && instance.isExisting()) {
instance.locked = true;
instance.publishedOn = new Date();
instance.registerHookCallback("beforeSave", async () => {
// TODO: setOnce
// Deactivate previously published revision
const publishedRev: PbPage = (await PbPage.findOne({
query: { published: true, parent: instance.parent }
}): any);
if (publishedRev) {
publishedRev.published = false;
fields: onSet(value => (instance.locked ? instance.fields : value))(
fields({
list: true,
value: [],
instanceOf: FormFieldsModel
})
),
layout: onSet(value => (instance.locked ? instance.layout : value))(
object({ value: [] })
),
stats: skipOnPopulate()(fields({ instanceOf: FormStatsModel, value: {} })),
settings: onSet(value => (instance.locked ? instance.settings : value))(
fields({ instanceOf: FormSettingsModel, value: {} })
),
triggers: onSet(value => (instance.locked ? instance.triggers : value))(object()),
version: number(),
parent: string(),
publishedOn: date(),
published: onSet(value => {
if (value) {
instance.publishedOn = new Date();
if (!instance.locked) {
instance.locked = true;
}
}
return value;
})(boolean()),
locked: skipOnPopulate()(boolean({ value: false }))
})),
withHooks({
export default ({ createBase, context }) => {
const File = flow(
withName("File"),
withProps({
get src() {
const settings = context.files.getSettings();
return settings.data.srcPrefix + this.key;
}
}),
withFields({
key: setOnce()(string({ validation: validation.create("required,maxLength:200") })),
size: number(),
type: string({ validation: validation.create("maxLength:50") }),
name: string({ validation: validation.create("maxLength:100") }),
meta: object(),
tags: onSet(value => {
if (!Array.isArray(value)) {
return null;
}
return value.map(item => item.toLowerCase());
})(
string({
list: true,
validation: tags => {
if (!Array.isArray(tags)) {
return;
}