Truflux Message Schema
To install
npm install --save truflux-msg-schema
This module is used to wrap message handlers one would use with a truflux-msg module to check that the payload data conforms to a specified schema
var EnforceSchema = ; /* Lets assume that the login function must be provided with an object that must have an id number property and a password string property */ { /** * Do something */ } { socket; } var schema= type:'object' props: id : type :'number' password : type :'string' var wrappedLogin = SomeTrufluxMessageInstance;
API
/** * Wraps a function in a schema enforce to make sure that the payload matches a specified schema * @param * @param * @param * @return */
The schema object's type can be *
to allow any type, or it can be an array if you want to allow multiple types
var someSchema= type : 'object' props : bufferProperty : type : 'buffer' arrayProperty : type : 'array' booleanProperty : type : 'boolean' stringProperty : type : 'string' numberProperty : type : 'number' anyProperty : type : '*' multipleProperty : type : 'object''undefined' nestedProperty : type:'object' props: somePropert : type:'*} } } } }