How to use the @webiny/commodo.object function in @webiny/commodo

To help you get started, we’ve selected a few @webiny/commodo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webiny / webiny-js / packages / api-page-builder / src / plugins / models / pbMenu.model.js View on Github external
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;
};
github webiny / webiny-js / packages / api-files / src / plugins / models / file.model.js View on Github external
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.");
github webiny / webiny-js / packages / api-forms / src / plugins / models / formSubmission.model.js View on Github external
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({
github webiny / webiny-js / packages / api-forms / src / plugins / models / Form / createFieldModel.js View on Github external
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: {} })
    })();