feathers-tcomb

1.0.0 • Public • Published

feathers-tcomb

validate feathers services using tcomb

install

with npm, run

npm install --save feathers-tcomb

usage

In order for this module to work, you must configure hooks on your feathers app.

var feathers = require('feathers')
var hooks = require('feathers-hooks')
var bodyParser = require('body-parser')
var memory = require('feathers-memory')
var validate = require('feathers-tcomb')
var t = require('tcomb')
 
var app = feathers()
  .configure(feathers.rest())
  .configure(hooks())
  .use(bodyParser.urlencoded({ extended: true }))
  .use('/things', memory())
 
var Thing = t.struct({
  id: t.Number,
  name: t.String
}, 'Thing')
 
validate(app.service('things'), Thing)

api

validate(service, type, [options])

Given a feathers service, a tcomb type and optional options for tcomb-validation, will add a before hook to create, update, and patch methods to validate the incoming data based on the type definition.

On an error, returns a feathers-errors BadRequest.

Package Sidebar

Install

npm i feathers-tcomb

Weekly Downloads

1

Version

1.0.0

License

ISC

Last publish

Collaborators

  • ahdinosaur