Skip to content

Latest commit

 

History

History
308 lines (226 loc) · 10.5 KB

API.md

File metadata and controls

308 lines (226 loc) · 10.5 KB

Modules

validate

Used to validate a basic type or schema.

pipePromise

$pipePromise.

microservice

Microservices pipeline.

errors

Error handler module. In order to work , the project must have an error directory in the root folder.

debug

Debug helper module.

db

Common DB functionality across different microservices.

cache

validate

Used to validate a basic type or schema.

validate.joi(objectToValidate, schema) ⇒ Promise

Kind: static method of validate
Fulfil: string Result of Joi.validate().
Reject: Error Joi Error.

Param Type Description
objectToValidate Object An object to validate.
schema Object Can be a joi type object or a plain object where every key is assigned a joi type object.

validate.joiElement(elementToValidate, type) ⇒ Promise

Kind: static method of validate
Fulfil: string Result of Joi.validate().
Reject: Error Joi Error.

Param Type Description
elementToValidate Object An element to validate.
type String Any of the classic basic primitive types.

pipePromise

$pipePromise.

pipePromise.$pipe(fnc, state, [critical]) ⇒ $pipePromise

Kind: static method of pipePromise

Param Type Description
fnc function Function to execute in the pipeline.
state Object Current state of the App.
[critical] boolean When $critical is present, an exception stop de pipe execution.

microservice

Microservices pipeline.

microservice.doFn(fnc) ⇒ Object

Wrapper function. If all is ok, the result will be { ok : true , data : {result} } When is an error in business logic, the result will be { ok : false, err : Error }.

Kind: static method of microservice

Param Type Description
fnc function Command function that must be executed.

errors

Error handler module. In order to work , the project must have an error directory in the root folder.

errors.handle(id, [err]) ⇒ Error

Generate custom errors.

Kind: static method of errors
Returns: Error - Custom Error instance.

Param Type Description
id String Id to be shown.
[err] Error Error to be added as oldError in the return object.

debug

Debug helper module.

debug.printModule(scope) ⇒ function

Kind: static method of debug
Returns: function - Pretty Print function.

Param Description
scope Scope to be added to the print function.

db

Common DB functionality across different microservices.

db.save(element, collection) ⇒ Promise

Kind: static method of db
Fulfil: Object { dataRaw, data }.
Reject: Error Error generated by Seneca Entity.

Param Type Description
element Obecjt Element to be stored in MongoDB.
collection String Collection where the element will be stored.

db.find(where, collection) ⇒ Promise

Kind: static method of db
Fulfil: Object { dataRaw, data }.
Reject: Error Error generated by Seneca Entity.

Param Type Description
where Object Query to be executed.
collection String Collection to be used.

db.findOne(where, collection) ⇒ Promise

Kind: static method of db
Fulfil: Object { dataRaw, data }.
Reject: Error Error generated by Seneca Entity.

Param Type Description
where Object Query to be executed.
collection String Collection to be used.

db.findOr(where, collection) ⇒ Promise

.

Kind: static method of db
Fulfil: Object { dataRaw, data }.
Reject: Error Error generated by Seneca Entity.

Param Type Description
where Object Query to be executed
collection String Collection to be used.

db.update(dataRaw, bundle, fields) ⇒ Promise

Kind: static method of db
Fulfil: Object Updated Object
Reject: Error The error name property will be one of the following:

Param Type Description
dataRaw Object Seneca Entity
bundle Object
fields Field to be modified

db.updateNative(where, opFields, collection) ⇒ Promise

Kind: static method of db
Fulfil: Number Elements updated.
Reject: Error Error generated by Seneca Entity.

Param Type Description
where Object Query to be executed.
opFields String Field to be modified.
collection String Collection that will be updated.

db.removeNative(where, collection) ⇒ Promise

Kind: static method of db
Fulfil: Object Confirmation.
Reject: Error Error generated by Seneca Entity.

Param Type Description
where Object Query to be executed.
collection String Collection to be used.

db.remove(where, collection) ⇒ Promise

Kind: static method of db
Fulfil: Number 1 to confirm.
Reject: Error Error

Param Type Description
where Object Query to be executed.
collection String Collection to be used.

db.populate(object, keyString, select, collection) ⇒ Promise

Kind: static method of db
Fulfil: Object The data you wanted.
Reject: Error The error name property will be one of the following:

Param Type Description
object Object Objecto op pupulate
keyString String Key field
select
collection Object Collection of the 'object' param

db.mongoObjectId() ⇒ string

Kind: static method of db
Returns: string - Generate a mongoObjectId.

cache

cache.addKey(key, value, timeout)

Add key to Redis cache. IMPORTANT! The key must include correct namespace to prevent data collisions

Kind: static method of cache

Param Type Description
key String Key to store
value String Value to store
timeout int timeout to expire keys

cache.getValue(Key) ⇒ Object

Get value from Redis cache.

Kind: static method of cache

Param Type Description
Key String to obtain value.

cache.removeKey(key) ⇒ Int

Remove key from Redis cache.

Kind: static method of cache

Param Type Description
key String Key to remove.