jkuester:crudable

v1.1.0Published 6 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

meteor-crudable

Configure and create CRUD methods for your collections. Generated resujlts can deirectly be passed to ValidatedMethod.

Usage and Example

1const TestCollection = new Mongo.Collection('testcollection')
2
3const options = {
4  
5  // the collection for which
6  // you will generate CRUD methods
7  collection: TestCollection,
8  
9  // a prefix for your method names
10  // that will be used for generating
11  prefix: 'crudable.methods',
12  
13  // a schema as plain object
14  // no SimpleSchema instance, as
15  // there is no dependency implied.
16  schema: {
17    title: String,
18    description: String
19  },
20  
21  // set to false to prevent {} queries
22  // on operations
23  allowAll: false,
24  
25  // pass through to 
26  // ValidatedMethod constructor
27  mixins: {
28    roles: ['manageCollection'],
29    requireAuth: true,
30  },
31
32  // action specific overrides
33  read: {
34    isPublic: true,
35    allowAll: true
36  }
37}
38
39
40// get CRUD methods
41const methods = Crudable.from(options, true)

THe created object is a set of the four actions (CRUD) which each can be passed to the constructor of ValidatedMethod.

1// create
2{ 
3  collection: [object Object],
4  schema: { 
5    title: [Function: String], 
6    description: [Function: String]
7  },
8  prefix: 'crudable.methods',
9  isPublic: false,
10  allowAll: false,
11  roles: [ 'manageCollection' ],
12  requireAuth: true,
13  name: 'crudable.methods.testcollection.create',
14  validate: [Function: validate],
15  run: [Function: run] 
16}
17
18// read
19{ 
20  collection: [object Object],
21  schema: { 
22    title: [Function: String], 
23    description: [Function: String]
24  },
25  prefix: 'crudable.methods',
26  isPublic: true,
27  allowAll: true,
28  roles: [ 'manageCollection' ],
29  requireAuth: true,
30  name: 'crudable.methods.testcollection.read',
31  validate: [Function: validate],
32  run: [Function: run] 
33}
34
35// update
36{ 
37  collection: [object Object],
38  schema: { 
39    title: [Function: String], 
40    description: [Function: String]
41  },
42  prefix: 'crudable.methods',
43  isPublic: false,
44  allowAll: false,
45  roles: [ 'manageCollection' ],
46  requireAuth: true,
47  name: 'crudable.methods.testcollection.update',
48  validate: [Function: validate],
49  run: [Function: run] 
50}
51
52// delete
53{ 
54  collection: [object Object],
55  schema: { 
56    title: [Function: String], 
57    description: [Function: String]
58  },
59  prefix: 'crudable.methods',
60  isPublic: false,
61  allowAll: false,
62  roles: [ 'manageCollection' ],
63  requireAuth: true,
64  name: 'crudable.methods.testcollection.delete',
65  validate: [Function: validate],
66  run: [Function: run] 
67}

Note, that validate is affected by schema, allowAll or isPublic.