SenecaJS Merge Validate is an abstraction package made to validate/formate a message payload data.
This package uses Btime-schema-validate-package
to perform validations based on the schemas defined there.
$ npm i
$ npm i Btime/seneca-merge-validate#semver:^2 -S
function Plugin () {
const seneca = this
const Joi = require('joi')
const SenecaMergeValidate = require('seneca-merge-validate')
const senecaMergeValidate = SenecaMergeValidate(seneca)
const PICK_FIELDS = [
'field'
]
seneca.add({ role: 'plugin', cmd: 'create', credentials: '*'}, cmd_create)
function cmd_create (args, done) {
senecaMergeValidate.validate({
args,
pick: PICK_FIELDS,
schema: { name: args.role, method: args.cmd },
options: { abortEarly: false }
})
.then(params => create(params))
.then(result => done(null, result))
.catch(err => done(null, err))
}
function getValidateSchema () {
return {
field: Joi.any()
.required()
}
}
function createService (params) {
return new Promise((resolve, reject) => {
return reject({ status: false, errors: [] })
return resolve({ status: true, result: {} })
})
}
}
Error messages default to the English language, but might be different by setting the language option:
senecaMergeValidate.validate({
args,
pick: PICK_FIELDS,
schema: { name: args.role, method: args.cmd },
options: {
abortEarly: false,
language: 'pt-br'
}
})
The JOI Language Pack is used in order to allow for such translations.
You can also provide custom messages yourself by defining the language object:
const language = {
any: {
required: 'is not optional'
}
}
senecaMergeValidate.validate({
args,
pick: PICK_FIELDS,
schema: { name: args.role, method: args.cmd },
options: {
abortEarly: false,
language
}
})
All pushes must come with a new tag. The tag usage must consider semantic versions
[major version: incompatible changes].[minor version: compatible with major].[patch version: bug fixes]
git tag 1.0.0 && git push origin master --tags
$ npm test