wadofgum-json-schema
Advanced tools
Comparing version 0.4.2 to 1.0.0
## Changelog | ||
+ 1.0.0 - major update due to major bump in wadofgum, meta set has been removed upstream so constructor props for class used to store schema, validator and meta about model | ||
+ 0.4.2 - updated dependencies | ||
@@ -4,0 +6,0 @@ |
@@ -7,36 +7,38 @@ 'use strict'; | ||
class Model extends baseClass { | ||
static set schema(rawSchema) { | ||
this.meta.set('metaSchema', rawSchema.metaSchema); | ||
this.meta.set('schema', rawSchema.schema); | ||
this.metaSchema = rawSchema.metaSchema; | ||
this.jSchema = rawSchema.schema; | ||
if (rawSchema.metaSchema.rids) { | ||
this.meta.set('rids', rawSchema.metaSchema.rids); | ||
this.rids = rawSchema.metaSchema.rids; | ||
} | ||
}; | ||
} | ||
static set validator(validator) { | ||
this.meta.set('validator', validator); | ||
this.valid = validator; | ||
}; | ||
} | ||
validate(cb) { | ||
if (!this.constructor.meta.has('schema')) { | ||
return cb(new Error('No schema has been provided for model ' + this.constructor.name)); | ||
const schema = this.constructor.jSchema; | ||
const validator = this.constructor.valid; | ||
const metaSchema = this.constructor.metaSchema; | ||
if (!schema) { | ||
return cb(new Error(`No schema has been provided for model ${this.constructor.name}`)); | ||
} | ||
if (!this.constructor.meta.has('validator')) { | ||
return cb(new Error('No validator has been provided for model ' + this.constructor.name)); | ||
if (!validator) { | ||
return cb(new Error(`No validator has been provided for model ${metaSchema.name}`)); | ||
} | ||
const schema = this.constructor.meta.get('schema'); | ||
const validator = this.constructor.meta.get('validator'); | ||
const metaSchema = this.constructor.meta.get('metaSchema'); | ||
validator.validate(this, schema, (err, result) => { | ||
if (err) { | ||
const error = new Error('JSON schema validation has failed for model ' + metaSchema.name); | ||
const error = new Error(`JSON schema validation has failed for model ${metaSchema.name}`); | ||
error.details = err; | ||
@@ -43,0 +45,0 @@ return cb(error, null); |
{ | ||
"name": "wadofgum-json-schema", | ||
"version": "0.4.2", | ||
"version": "1.0.0", | ||
"description": "json schema validation for wadofgum models", | ||
@@ -25,5 +25,5 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"code": "^2.0.1", | ||
"lab": "^8.0.0", | ||
"wadofgum": "^4.1.0", | ||
"code": "^2.1.0", | ||
"lab": "^10.0.0", | ||
"wadofgum": "^5.1.0", | ||
"z-schema": "^3.16.0" | ||
@@ -30,0 +30,0 @@ }, |
'use strict'; | ||
const Code = require('code'); | ||
// const Hoek = require('hoek'); | ||
const Lab = require('lab'); | ||
@@ -11,2 +10,4 @@ const Wadofgum = require('wadofgum'); | ||
// Fixtures | ||
@@ -50,5 +51,7 @@ const PersonSchema = require('./fixtures/person.js'); | ||
Person.validator = Validator; | ||
const person = new Person({ | ||
recType: 'test' | ||
}); | ||
person.validate((err, result) => { | ||
@@ -80,2 +83,3 @@ | ||
const person = new Person(); | ||
person.validate((err, result) => { | ||
@@ -111,5 +115,7 @@ | ||
Person.validator = Validator; | ||
PersonData.person.dateOfBirth = '01-10-1975'; | ||
const person = new Person(PersonData); | ||
PersonData.person.dateOfBirth = '01-10-1975'; | ||
person.validate((err, result) => { | ||
@@ -116,0 +122,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
20441
0
459