Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default ({ createBase }) => {
const PbMenu = flow(
withName("PbMenu"),
withFields({
title: string({ validation: validation.create("required") }),
slug: setOnce()(string({ validation: validation.create("required") })),
description: string(),
items: object()
}),
withHooks({
async beforeCreate() {
const existingMenu = await PbMenu.findOne({ query: { slug: this.slug } });
if (existingMenu) {
throw Error(`Menu with slug "${this.slug}" already exists.`);
}
}
})
)(createBase());
return PbMenu;
};
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;
}
if (tags.length > 15) {
throw Error("You cannot set more than 15 tags.");
instanceOf: withFields({
ip: string({ validation: validation.create("required") }),
locale: string({ validation: validation.create("required") }),
submittedOn: skipOnPopulate()(
date({ validation: validation.create("required") })
)
})()
}),
logs: fields({
list: true,
value: [],
instanceOf: withFields({
type: string({
validation: validation.create("required,in:error:warning:info:success"),
message: string(),
data: object(),
createdOn: date({ value: new Date() })
})
})()
})
})),
withHooks({
label: i18nString({ context }),
helpText: i18nString({ context }),
placeholderText: i18nString({ context }),
options: fields({
list: true,
instanceOf: withFields({
label: i18nString({ context }),
value: string({ value: "" })
})()
}),
validation: fields({
list: true,
instanceOf: withFields({
name: string({ validation: validation.create("required") }),
message: i18nString({ context }),
settings: object({ value: {} })
})()
}),
settings: object({ value: {} })
})();