seneca-joi v7.0.2

A Seneca.js plugin that validates messages using the joi module.
seneca-joi
Installation
npm install seneca-joiAnd in your code:
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.
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 valueAny 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.
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 valueContributing
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.
License
Licensed under MIT.
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago