seneca-joi

A Seneca.js plugin that validates messages using the joi module.

Showing:

Popularity

Downloads/wk

38

GitHub Stars

10

Maintenance

Last Commit

1yr ago

Contributors

7

Package

Dependencies

1

Size (min+gzip)

42.6KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Seneca

A Seneca.js plugin that validates messages using the joi module.

seneca-joi

npm version Dependency Status Build Status Maintainability Coverage Status Gitter

Installation

npm install seneca-joi

And 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 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.

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

Contributing

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.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100