1.0.0 • Published 8 years ago

feathers-tcomb v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
8 years ago

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.