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.0.1 to 0.1.0

32

lib/index.js

@@ -16,25 +16,21 @@ 'use strict';

validate () {
validate (cb) {
const self = this;
return new Promise((resolve, reject) => {
if (!this.constructor.meta.has('schema')) {
return cb(new Error('No schema has been provided for model ' + this.constructor.name));
}
if (!this.constructor.meta.has('schema')) {
return reject(new Error('No schema has been provided for model ' + this.constructor.name));
}
const schema = this.constructor.meta.get('schema');
const validator = this.constructor.meta.get('validator');
const valid = validator.validateSchema(schema);
const schema = this.constructor.meta.get('schema');
const validator = this.constructor.meta.get('validator');
const valid = validator.validateSchema(schema);
if (!valid) {
return cb(new Error('Schema name ' + this.constructor.name + ' is not valid'));
}
validator.validate(this, schema, (err, result) => {
if (!valid) {
return reject(new Error('Schema name ' + this.constructor.name + ' is not valid'));
if (err) {
return cb(new Error('Validation has failed with message ' + err[0].message));
}
validator.validate(self, schema, (err, result) => {
if (err) {
return reject(new Error('Validation has failed with message ' + err[0].message));
}
return resolve(self);
});
return cb(null, this);
});

@@ -41,0 +37,0 @@ };

{
"name": "wadofgum-json-schema",
"version": "0.0.1",
"version": "0.1.0",
"description": "json schema validation for wadofgum models",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -7,3 +7,3 @@ ## wadofgum-json-schema [![Build Status](https://travis-ci.org/simon-p-r/wadofgum-json-schema.svg)](https://travis-ci.org/simon-pr/wadofgum-json-schema)

After extending your model with this mixin, instances of your class will have a `validate` method. This method returns a promise that resolves when validation is complete or rejects if validation fails.
After extending your model with this mixin, instances of your class will have a `validate` method which accepts a callback as its only parameter.

@@ -34,7 +34,7 @@ Simply provide a json schema for validation and then assign it to the static `schema` property on your class.

let model = new Model({ name: 'test', age: '45', dateOfBirth: '1975-10-01'});
model.validate().then(function () {
model.name; // 'test'
model.age; // 45
model.dateOfBirth; // '1975-10-01'
model.validate((err, result) => {
model.name; // 'test'
model.age; // 45
model.dateOfBirth; // '1975-10-01'
});
```

@@ -30,3 +30,3 @@ 'use strict';

user.validate().catch((err) => {
user.validate((err, result) => {

@@ -59,9 +59,8 @@ expect(err).to.exist();

const user = new User();
user.validate((err, result) => {
user.validate().catch((err) => {
expect(err).to.exist();
expect(err.message).to.contain('Schema name');
done();
}).catch(done);
});

@@ -94,4 +93,5 @@ });

user.validate().then(() => {
user.validate((err, result) => {
expect(err).to.not.exist();
expect(user.name).to.equal('John');

@@ -101,6 +101,6 @@ expect(user.age).to.equal(40);

done();
}).catch(done);
});
});
it('should fail validation data against a json schema', (done) => {
it('should fail validation with invlaid data against a z-schema', (done) => {

@@ -129,3 +129,3 @@ class User extends Wadofgum.mixin(Validation) {};

user.validate().catch((err) => {
user.validate((err, result) => {

@@ -135,6 +135,5 @@ expect(err).to.exist();

done();
}).catch(done);
});
});
});
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