bookshelf-modelbase
Advanced tools
Comparing version 0.0.0 to 0.1.0
@@ -12,3 +12,13 @@ var _ = require('lodash'); | ||
initialize: function (attrs, options) { | ||
this.validation || (this.validation = Joi.any()); | ||
if (this.validate) { | ||
this.validate = Joi.object(this.validate).keys({ | ||
// id might be number or string, for optimization | ||
id: Joi.any().required(), | ||
createdAt: Joi.date().required(), | ||
updatedAt: Joi.date().required() | ||
}) | ||
} else { | ||
this.validate = Joi.object({ n: Joi.string().required() }); | ||
} | ||
this.validate || (this.validate = Joi.any()); | ||
this.on('saving', this.validateSave); | ||
@@ -20,3 +30,3 @@ }, | ||
validateSave: function () { | ||
var validation = Joi.validate(this.attributes, this.validation); | ||
var validation = Joi.validate(this.attributes, this.validate); | ||
if (validation.errors) { | ||
@@ -23,0 +33,0 @@ throw new Error(validation.errors); |
{ | ||
"name": "bookshelf-modelbase", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"description": "Extensible ModelBase for bookshelf-based model layers", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -41,4 +41,7 @@ ModelBase ![Build Status](https://travis-ci.org/bsiddiqui/bookshelf-modelbase.svg?branch=master) | ||
}, { | ||
validation: <Joi validation object, defaults to Joi.any()> | ||
// validation is passed to Joi.object(), so use a raw object | ||
validation: { | ||
firstName: Joi.string() | ||
} | ||
}) | ||
``` |
@@ -26,3 +26,3 @@ var Joi = require('joi'); | ||
it('should convert snake case to camel case', function () { | ||
expect(specimen.parse({ variable_name: 'snake_case' })) | ||
return expect(specimen.parse({ variable_name: 'snake_case' })) | ||
.to.eql({ variableName: 'snake_case' }) | ||
@@ -34,3 +34,3 @@ }); | ||
it('should convert camel case to snake case', function () { | ||
expect(specimen.format({ variableName: 'snake_case' })) | ||
return expect(specimen.format({ variableName: 'snake_case' })) | ||
.to.eql({ variable_name: 'snake_case' }) | ||
@@ -42,3 +42,3 @@ }); | ||
it('should validate own attributes', function () { | ||
expect(specimen.validateSave()).to.contain({ | ||
return expect(specimen.validateSave()).to.contain({ | ||
name: 'hello' | ||
@@ -54,3 +54,3 @@ }); | ||
it('should itself be extensible', function () { | ||
expect(ModelBase.extend({ tableName: 'test' })) | ||
return expect(ModelBase.extend({ tableName: 'test' })) | ||
.to.itself.respondTo('extend'); | ||
@@ -57,0 +57,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6426
112
47