Seneca plugin that provides joi message validation.
npm install seneca-joi> A [Seneca.js][] plugin that validates messages using the
> joi module.
sh
npm install seneca-joi
`And in your code:
`js
require('seneca')({
legacy: {validate: false} // needed if using Seneca 2.x
})
.use('seneca-joi', {
joi: {allowUnknown: true} // example of passing in Joi options
})
`Usage
You can validate action messages by providing
joi rules as part of the
action definition.
`js
var Joi = require('joi')require('seneca')
.use('seneca-joi')
.add(
{
a: 1,
b: Joi.required()
},
function (msg, done) {
done(null, {c: msg.b})
})
.act('a:1,b:2') // valid
.act('a:1') // invalid as no b value
`Any properties in the action pattern that are not constants are
interpreted as _joi_ rules.
You can also modify or replace the Joi schema by providing a function
via the
joi$ property. This gives you full control of the Joi schema.`js
var Joi = require('joi')require('seneca')
.use('seneca-joi')
.add(
{
a: 1,
joi$: function (schema) {
return schema.keys({b: Joi.required()})
}
},
function (msg, done) {
done(null, {c: msg.b})
})
.act('a:1,b:2') // valid
.act('a:1') // invalid as no b value
``The [Senecajs org][] encourages open participation. If you feel you
can help in any way, be it with documentation, examples, extra
testing, or new features please get in touch.
[MIT]: ./LICENSE
[npm-badge]: https://badge.fury.io/js/seneca-joi.svg
[npm-url]: https://badge.fury.io/js/seneca-joi
[Senecajs org]: https://github.com/senecajs/
[Seneca.js]: https://www.npmjs.com/package/seneca
[@senecajs]: http://twitter.com/senecajs
[senecajs.org]: http://senecajs.org/
[travis-badge]: https://travis-ci.org/senecajs/seneca-joi.svg
[travis-url]: https://travis-ci.org/senecajs/seneca-joi
[gitter-badge]: https://badges.gitter.im/Join%20Chat.svg
[gitter-url]: https://gitter.im/senecajs/seneca
[github issue]: https://github.com/senecajs/seneca-joi/issues
[david-badge]: https://david-dm.org/senecajs/seneca-joi.svg
[david-url]: https://david-dm.org/senecajs/seneca-joi