jxmono / crud

:fork_and_knife: CRUD for mono
MIT License
0 stars 1 forks source link

crud

CRUD for mono

Example config with flow:

config: {
    myMiid: {
        myEvent: ['read', 'update', 'create', 'delete']
    }
}

All these events must have two parameters:

Fetch templates

If an array is send to self.emit('read') as data CRUD will fetch the templates inside the array. Normal queries for templates are working also. Templates are always initialized before returned.

CRUD object format

Client CRUD requests

Example request data:

{
    // the template that this CRUD object will be validated against
    t: 'the stringified template id',
    // the query object in MongoDB format
    q: {/*query object*/},
    // the document object (updates) in MongoDB format
    d: {/*update document*/},
    // the CRUD operation options in node-monogdb-native (NodeJs MongoDb driver) format
    o: {/*options*/},
    // don't make joins
    noJoins: true,
    // don't merge template
    noMerge: true,
    // don't return cursors for read operations
    noCursor: true,
    // perform only a count using the given query
    onlyCount: true
}

Server CRUD requests

Example request data:

Build the CRUD request object:

{
    templateId: 'the stringified template id',
    role: ObjectId('the crud role'), // link.session.crudRole
    query: {
        /* query data */
    },
    data: {
        /* data to insert/update */
    },
    noCursor: true // don't return cursors for read operations,
    onlyCount: true // perform only a count using the given query
}

and emit a crud.<operation> server-side event:

M.emit("crud.create", crudObject, callback);

Template config

myTemplate = {
    _id: myTemplateItemId,
    _tp: [_templateTemplateId],
    db: 'dbName',
    collection: 'collectionName',
    name: 'template_name',
    roles: {
        // set any combination of c, r, u or d in access
        'roleId': {access: 'crud'},
        // optional template configuration overwriting
        // the only supported template properties are: options, links, and schema
        'config': {
            'options': {
                'html': 'another/html/file.html'
            },
            'links': {
                // ...
            },
            'schema': {
                ...
            }
        }
    },
    // add a role with access rights to every item
    itemAccess: 'crud',
    options: {
        label: {
            de: 'Template Label'
        },
        order: 5,
        html: '/myTemplate.html',
        sort: [['sort.field', 1]],
        // a hidden fixed filter to display only the customers that are HB
        filters: [
            {
                field: 'filterFIeld',
                operator: 'exists',
                value: true,
                hidden: true,
                fixed: true
            }
        ]
    },
    // plug custom code
    on: {
        create: {
            myCustomEventA: [arg1, argN]
        },
        read: {
            myCustomEventB: [arg1, argN]
        },
        update: {
            myCustomEventC: [arg1, argN]
        },
        delete: {
            myCustomEventD: [arg1, argN]
        }
    },

    links: [
        // see crud links module
    ],
    schema: {
        // modm schema
    }
}

Change log

v0.6.0

v0.5.2

v0.5.1

v0.5.0

v0.4.1

v0.4.0

v0.3.8

v0.3.7

v0.3.6

v0.3.5

v0.3.4

v0.3.3

v0.3.2

v0.3.1

v0.3.0

v0.2.14

v0.2.13

v0.2.12

v0.2.10

v0.2.9

v0.2.8

v0.2.7

v0.2.6

v0.2.5

v0.2.4

v0.2.3

v0.2.2

v0.2.1

v0.2.0

v0.1.1

v0.1.0