Create validated method by given input.
TODO / TO BE IMPLEMENTED
- checkRoles
- hooks (before, after)
- wrap params for main functions into object with attributes
- applyOptions as parameter
- pass Schema as optional param in order to omit dependencies between Mongo.Collection and SimpleSchema (for those who don't use collection2-core)
- update method for custom fields, in order to not require to update the whole document for now
0.1.2 - Added and tested getCloneMethodDefault
0.1.1 - Method validations are now rethrowing errors as meteor errors with detailed information.
######General
- All the functions make use of mdg:validated-method and require a Mongo.Collection instance and a method name.
- Before generating the method, there is a call to
checkCollection
to avoid runtime errors regarding missing collections. - All methods validate by the Mongo.Collection schema. Make sure you have a Schema attached to each collection.
- Validation errors are rethrown as Meteor.Error in order to give clients more transparency about failures.
- User access is checked at runtime (TODO: add also optional roles checking)
- The Method call parameter describes the parameters, that are necessary to be passed when using
Meteor.call
Creates and returns a validated insert method, that adds inserts a (schema-valid) document into the given collection
Method call parameter: Object insertDoc (without _id and all fields required by collection schema)
Note: denies documents that have already have an ID and thus exist in the database. If you want to clone existing documentes use getCloneMethodDefault
.
Creates and returns a validated update method, that adds updates a (schema-valid) document into the given collection.
Method call parameter: Object updateDoc (with _id and all fields required by collection schema)
Note: this method needs all required fields of the schema to be present in the updateDoc, including the _id. It is a full-document update.
Creates and returns a validated update method, that is conform the the aldeed:autoform method-update schema.
Method call parameter:
Object updateDoc with schema
updateDoc._id - the id of the doc to be updated updateDoc.modifier - the doc to be updated including all fields required by the schema.
See aldeed:autoform - method-update for more
Creates and returns a validated remove method, that is conform that removes a document by a given id.
Method call parameter: {_id:String}
Creates and returns a validated method to find a single document by id.
Method call parameter: {_id:String}
Creates and returns a validated insert method, that inserts a (schema-valid) document into the given collection by an existing document, using an exact copy of it's field entries.
Method call parameter: Object insertDoc (witg _id and all fields required by collection schema)
Basically the rateLimit form the meteor example projects. Requires your created validated methods as an array in order to rate limit their calls.
Checks if the given user by userId is a) not undefined and b) exists within the current applications user collection.
Returns true, if successful. Throws Errors, if failing.
Checks, whether a given schema is an instance of SimpleSchema
. It does not check the schema validity, which is done in each validate method.
Throws Errors, if failing.
Checks, whether a given collection is a Mongo.Collection (or extending it.) Throws Errors, if failing.
Checks, whether the given doc exists in the given collection.
Note: that it is suggested to NOT use client side allow/deny and thus deny all client actions. However, if you can't resist or for whatever good reason need to use them, here are some handy generic functions to create them. Note2: makes use of alanning:roles in order to verify client side db access. Roles require an array of strings as roles and a string as name of the group/domain.
Returns an object with insert, update and remove functions, created by getAllowInsert
, getAllowUpdate
and getAllowRemove
.
By doing so, it uses the same collection/roles/domain settings for all the three sub-calls.
Creates an insert allow method for the given collection, roles and domain.
Creates an update allow method for the given collection, roles and domain.
Creates a remove allow method for the given collection, roles and domain.
PR and feature requests are very welcome. Please use the included test
project to verify your new written code.
If you create new dependencies, please check, if they are really necessary.
You can either use watch mode tests or cli tests. In any case you need to cd into the project's test project and install the dependencies first.
cd meteor-method-factory/tests
meteor npm install
For watch mode call
meteor npm run test
For cli mode call
meteor reset #cleans the project and avoids the 'missing select error'
meteor npm run testcli