New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wadofgum-json-schema

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wadofgum-json-schema - npm Package Compare versions

Comparing version 0.4.2 to 1.0.0

2

CHANGELOG.md
## 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 @@

32

lib/index.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc