serene-conformation

0.5.0 • Public • Published

serene-conformation

Validation middleware for Serene, using Conformation.

Example

import Schema from 'conformation';
import Serene from 'serene';
import SereneConformation from 'serene-conformation';
import SereneResources from 'serene-resources';
 
 
let service = new Serene();
 
let resources = {
  widgets: {
    schema: Schema.object().keys({
      name: Schema.string().required(),
      description: Schema.string()
    })
  }
};
 
// this package depends on SereneResources, which must be registered first
serene.use(new SereneResources(resources));
 
serene.use(new SereneConformation());
 
serene.use(function (request, response) {
  // this only runs if the request is valid
});

The middleware only validates requests with a body, that is:

  • create
  • update
  • replace

It wraps the schema found in the resource definition with a attributes field, so that it conforms to the SuperAPI spec, and automatically unwraps the request payload from the attributes field.

See tests for more details.

Dependents (0)

Package Sidebar

Install

npm i serene-conformation

Weekly Downloads

3

Version

0.5.0

License

ISC

Last publish

Collaborators

  • stewartml