1.0.1 • Published 7 years ago
feathers-db-validator v1.0.1
Feathers DB Validator
A DB wrapper that adds JSON Schema validation to all create, update and patch requests.
Installation
$ npm add feathers-db-validatorUsage
The DB Validator is used like any FeathersJS service adapter, and takes in one argument: options.
const createService = require('feathers-db-validator')
const FeathersNeDB = require('feathers-nedb')
const usersSchema = require('./users-schema.json')
module.exports = function () {
const app = this
app.use('/users', createService({
app,
name: 'users',
db: FeathersNeDB,
schema: usersSchema
})
app.service('users')
}Options:
app- FeathersJS app instancedb- FeathersJS database service wrapper (such as NeDB, MongoDB, or PostgreSQL)schema- JSON schema to use for validationModel- Passed to database service wrapper; if it has aschemaproperty this is used instead ofoptions.schemaaddTimestamps- If true, db validator will add "createdAt" and "updatedAt" timestamps on create, patch and update as required. Customize the field names using the parameters below. (Default: false)fieldCreatedAt- Name of the timestamp field set when models are created (default: "createdAt")fieldCreatedAt- Name of the timestamp field set when models are updated or patched (default: "updatedAt")
Bold= required. Also,schemaorModel.schemamust be defined.Any additional options are passed directly to the database service.
Licence
Copyright (c) 2018 Mesbah Mowlavi.
Licensed under the MIT license.