marchio-core-record
REST response record tool
Installation
$ npm init
$ npm install marchio-core-record --save
Modules
- marchio-core-record
Module
- marchio-core-record-factory
Factory module
marchio-core-record
Module
- marchio-core-record
- .package()
- .build(body) ⇒
Promise
- .buildUpdate(body) ⇒
Promise
- .select(body) ⇒
Promise
- .selectedFields() ⇒
Promise
- .fields(fields, body) ⇒
Promise
marchio-core-record.package()
Returns the package name
Kind: instance method of marchio-core-record
Promise
marchio-core-record.build(body) ⇒ Build a record based on the model and an input record containing original values
Kind: instance method of marchio-core-record
Returns: Promise
- that resolves to a record object containing the resulting record
Param | Type | Description |
---|---|---|
body | Object |
An object where properties represent fields from a response (like req.response) |
Example (Usage Example)
var factory = ; var modelName = 'coretest'; var model = name: modelName fields: email: type: String required: true status: type: String required: true default: "NEW" // In a real world example, password would be hashed by middleware before being saved password: type: String select: false // select: false, exclude from query results ; // normally this would come from an http method handler var req = body: email: "foo@example.com" ; factory
Promise
marchio-core-record.buildUpdate(body) ⇒ Build an update record based on the model and an input record containing original values
Kind: instance method of marchio-core-record
Returns: Promise
- that resolves to a record object containing the resulting record
Param | Type | Description |
---|---|---|
body | Object |
An object where properties represent fields from a response (like req.response) |
Example (Usage Example)
var factory = ; var modelName = 'coretest'; var model = name: modelName fields: email: type: String required: true status: type: String required: true default: "NEW" // In a real world example, password would be hashed by middleware before being saved password: type: String select: false // select: false, exclude from query results ; // normally this would come from an http method handler var req = body: email: "foo@example.com" ; factory
Promise
marchio-core-record.select(body) ⇒ Build a record based on the selected fields in a model and a record containing original values
Kind: instance method of marchio-core-record
Returns: Promise
- that resolves to a record object containing the resulting record
Param | Type | Description |
---|---|---|
body | Object |
An object where properties represent fields from a response (like req.response) |
Example (Usage Example)
var factory = ; var modelName = 'coretest'; var model = name: modelName fields: email: type: String required: true status: type: String required: true default: "NEW" // In a real world example, password would be hashed by middleware before being saved password: type: String select: false // select: false, exclude from query results ; // normally this would come from an http method handlervar req = body: email: "foo@example.com" ; var recMgr = null; factory
Promise
marchio-core-record.selectedFields() ⇒ Return a list containing the names of fields that are selected
Kind: instance method of marchio-core-record
Returns: Promise
- that resolves to a list of selected field names
Example (Usage Example)
var factory = ; var modelName = 'coretest'; var model = name: modelName fields: email: type: String required: true status: type: String required: true default: "NEW" // In a real world example, password would be hashed by middleware before being saved password: type: String select: false // select: false, exclude from query results ; // normally this would come from an http method handlervar req = body: email: "foo@example.com" ; var recMgr = null; factory;
Promise
marchio-core-record.fields(fields, body) ⇒ Build a record including all fields a list and a record containing original values
Kind: instance method of marchio-core-record
Returns: Promise
- that resolves to a record object containing the resulting record
Param | Type | Description |
---|---|---|
fields | Object |
An object where property values are objects defininig fields |
body | Object |
An object where properties represent fields from a response (like req.response) |
Example (Usage Example)
var factory = ; var modelName = 'coretest'; var model = name: modelName fields: email: type: String required: true status: type: String required: true default: "NEW" // In a real world example, password would be hashed by middleware before being saved password: type: String select: false // select: false, exclude from query results ; // normally this would come from an http method handlervar req = body: email: "foo@example.com" ; const fList = "email" "status" "password"; var recMgr = null; factory
marchio-core-record-factory
Factory module
Promise
marchio-core-record-factory.create(spec) ⇒ Factory method It takes one spec parameter that must be an object with named parameters
Kind: static method of marchio-core-record-factory
Returns: Promise
- that resolves to {module:marchio-core-record}
Param | Type | Description |
---|---|---|
spec | Object |
Named parameters object |
spec.model | Object |
Model object that must contain a fields property |
Example (Usage example)
var factory = ; var modelName = 'coretest'; var model = name: modelName fields: email: type: String required: true status: type: String required: true default: "NEW" // In a real world example, password would be hashed by middleware before being saved password: type: String select: false // select: false, exclude from query results ; factory ;
Testing
To test, go to the root folder and type (sans $):
$ npm test
Repo(s)
Contributing
In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
Version History
Version 0.1.3
- added buildUpdate method
Version 0.1.2
- added selectedFields method
Version 0.1.1
- updated documentation
Version 0.1.0
- initial release