Deprecated, please use racer-schema
- Schema validation module for Derby and Racer
- Uses 'submit' hook
- Types and validators are customizable
- Tests
- No casting (html input value - string)
- min, max validators does not validate the right way array's methods (push, insert, etc) and number's increment
npm install derby-validation
var Validation = require('derby-validation');
var options = {
schemas: {
users: { // collection
fields: { // doc fields
id: {
type: 'uuid' // type is the only required property for most types
},
name: {
type: 'string'
validators: { // besides type validation, you can add validators
required: true, // can not be null or undefined
match: /bob/, // some regex
enum: ['alice', 'bob', 'candy'] // only this values are allowed
}
},
age: {
type: 'integer', // number without a dot
default: 18, // you can use validation.createDefault(path) to create object with default values
validators: {
min: 0, // >=0
max: 150, // <=150
positive: true // >= 0
}
},
values: {
type: 'object',
fields: { // object can has fields, actually doc - is object too
birthday: {
type: 'date' // by default date is unix date
},
hobbies: {
type: 'array',
field: { // field - is type of array`s value
type: 'string' // something like: ['jazz', 'boxing', 'dendy']
}
}
}
},
roleId: {
type: 'join', // join is uuid for specific collection
collection: 'roles' // required field for join type
},
married: {
type: 'boolean'
},
email: {
type: 'email'
},
friends: {
type: 'hash', // hash is object where keys - ids of specific collection
collection: 'users', // required field for hash
field: { // type of hash`s values
type: 'object', // so hash: {user1uuid: {years: 3, info: true}, user2uuid: {years: 20, info: 'dude'}}
fields: {
years: {
type: 'number',
},
info: {
type: 'any' // can be of any type
}
}
}
}
}
}
},
types: {
// your types
},
validators: {
// you can add your validators
},
fields: {
// fields common for all collections, usually: id, dateCreated, etc
}
}
var validation = new Validation(options);
validation.setupStore(store);
- validation-example simple app with validation
Copyright (c) 2014 Vladimir Makhaev
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.