Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonpolice

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonpolice - npm Package Compare versions

Comparing version 3.4.1 to 3.5.0

1

dist/index.d.ts

@@ -9,2 +9,3 @@ import { SchemaOptions } from './global';

import './schema_string';
export { Schema } from './schema';
export declare function create(dataOrUri: any, opts?: SchemaOptions): Promise<any>;

@@ -11,0 +12,0 @@ export declare function flatten(dataOrUri: any, opts?: SchemaOptions): Promise<any>;

@@ -14,2 +14,4 @@ "use strict";

require('./schema_string');
var schema_2 = require('./schema');
exports.Schema = schema_2.Schema;
function create(dataOrUri, opts = {}) {

@@ -16,0 +18,0 @@ if (!dataOrUri) {

12

dist/schema_array.js

@@ -5,3 +5,3 @@ "use strict";

const schema_1 = require('./schema');
var seps = {
let seps = {
'csv': ',',

@@ -42,3 +42,3 @@ 'ssv': ' ',

if (typeof data === 'string') {
var sep = seps[this.data.collectionFormat || 'csv'];
let sep = seps[this.data.collectionFormat || 'csv'];
if (!sep) {

@@ -62,6 +62,6 @@ throw new global_1.SchemaError(this.scope, 'collectionFormat', this.data.collectionFormat);

else if (data.length && (global_1.enumerableAndDefined(this.data, 'items') || global_1.enumerableAndDefined(this.data, 'additionalItems'))) {
var itemsIsArray = Array.isArray(this.data.items);
var itemsIsObject = !itemsIsArray && typeof this.data.items === 'object';
var addIsObject = typeof this.data.additionalItems === 'object';
for (var i = 0; i < data.length; i++) {
let itemsIsArray = Array.isArray(this.data.items);
let itemsIsObject = !itemsIsArray && typeof this.data.items === 'object';
let addIsObject = typeof this.data.additionalItems === 'object';
for (let i = 0; i < data.length; i++) {
if (itemsIsArray && i < this.data.items.length) {

@@ -68,0 +68,0 @@ data[i] = this.data.items[i][global_1.__schema].validate(data[i], path + '/' + i);

@@ -5,7 +5,7 @@ "use strict";

const schema_1 = require('./schema');
var __salmon = Symbol();
let __salmon = Symbol();
function createDefaultProperty(schema, obj, key) {
Object.defineProperty(obj, key, {
get: () => {
var v = schema.default();
let v = schema.default();
if (typeof v === 'object') {

@@ -38,3 +38,3 @@ v[__salmon] = { obj: obj, key: key };

super.init();
var i;
let i;
if (global_1.enumerableAndDefined(this.data, 'properties')) {

@@ -67,6 +67,6 @@ for (i in this.data.properties) {

default(data) {
var def = super.default(data);
let def = super.default(data);
if (global_1.defined(def) && def !== null && typeof def === 'object') {
if (global_1.enumerableAndDefined(this.data, 'properties')) {
for (var k in this.data.properties) {
for (let k in this.data.properties) {
if (!global_1.defined(def[k])) {

@@ -84,3 +84,3 @@ createDefaultProperty(this.data.properties[k][global_1.__schema], def, k);

}
var props = Object.keys(data);
let props = Object.keys(data);
if (global_1.enumerableAndDefined(this.data, 'maxProperties') && props.length > this.data.maxProperties) {

@@ -93,3 +93,3 @@ throw new global_1.ValidationError(path, this.scope, 'maxProperties');

else {
var i, j, k, found;
let i, j, k, found;
if (global_1.enumerableAndDefined(this.data, 'required')) {

@@ -96,0 +96,0 @@ for (i = 0; i < this.data.required.length; i++) {

@@ -10,11 +10,11 @@ import { SchemaOptions } from './global';

constructor(data: any, opts: SchemaOptions);
init(): void;
default(data: any): any;
validate(data: any, path?: string): any;
validateType(data: any, path: string): any;
validateEnum(data: any, path: string): any;
validateAllOf(data: any, path: string): any;
validateAnyOf(data: any, path: string): any;
validateOneOf(data: any, path: string): any;
validateNot(data: any, path: string): any;
protected init(): void;
protected default(data: any): any;
protected validateType(data: any, path: string): any;
protected validateEnum(data: any, path: string): any;
protected validateAllOf(data: any, path: string): any;
protected validateAnyOf(data: any, path: string): any;
protected validateOneOf(data: any, path: string): any;
protected validateNot(data: any, path: string): any;
static factories: {

@@ -21,0 +21,0 @@ [type: string]: SchemaFactory;

@@ -5,3 +5,3 @@ "use strict";

const global_1 = require('./global');
var __validating = Symbol();
let __validating = Symbol();
function linkProperty(o, i, k) {

@@ -18,3 +18,3 @@ o[k] = i[k];

else {
var a = [];
let a = [];
pushProperty(a, o, k);

@@ -29,3 +29,3 @@ pushProperty(a, i, k);

}
for (var j in i[k]) {
for (let j in i[k]) {
if (!global_1.enumerableAndDefined(o[k], j)) {

@@ -62,6 +62,43 @@ linkProperty(o[k], i[k], j);

}
validate(data, path = '') {
if (this[__validating]) {
return data;
}
else {
this[__validating] = true;
}
data = this.default(data);
if (typeof data !== 'undefined') {
try {
if (global_1.enumerableAndDefined(this.data, 'type')) {
data = this.validateType(data, path);
}
if (global_1.enumerableAndDefined(this.data, 'enum')) {
data = this.validateEnum(data, path);
}
if (global_1.enumerableAndDefined(this.data, 'allOf')) {
data = this.validateAllOf(data, path);
}
if (global_1.enumerableAndDefined(this.data, 'anyOf')) {
data = this.validateAnyOf(data, path);
}
if (global_1.enumerableAndDefined(this.data, 'oneOf')) {
data = this.validateOneOf(data, path);
}
if (global_1.enumerableAndDefined(this.data, 'not')) {
data = this.validateNot(data, path);
}
}
catch (e) {
delete this[__validating];
throw e;
}
}
delete this[__validating];
return data;
}
init() {
if (global_1.enumerableAndDefined(this.data, 'allOf')) {
_.each(this.data.allOf, (data, i) => {
Schema.create(this.data.allOf[i], _.defaults(this.opts, { scope: this.scope + '/allOf/' + i }));
Schema.create(this.data.allOf[i], Object.assign(this.opts, { scope: this.scope + '/allOf/' + i }));
});

@@ -71,3 +108,3 @@ }

_.each(this.data.anyOf, (data, i) => {
Schema.create(this.data.anyOf[i], _.defaults(this.opts, { scope: this.scope + '/anyOf/' + i }));
Schema.create(this.data.anyOf[i], Object.assign(this.opts, { scope: this.scope + '/anyOf/' + i }));
});

@@ -77,11 +114,11 @@ }

_.each(this.data.oneOf, (data, i) => {
Schema.create(this.data.oneOf[i], _.defaults(this.opts, { scope: this.scope + '/oneOf/' + i }));
Schema.create(this.data.oneOf[i], Object.assign(this.opts, { scope: this.scope + '/oneOf/' + i }));
});
}
if (global_1.enumerableAndDefined(this.data, 'not')) {
Schema.create(this.data.not, _.defaults(this.opts, { scope: this.scope + '/not' }));
Schema.create(this.data.not, Object.assign(this.opts, { scope: this.scope + '/not' }));
}
}
default(data) {
var def;
let def;
if (global_1.defined(data)) {

@@ -91,3 +128,3 @@ def = data;

if (!global_1.defined(def) && global_1.enumerableAndDefined(this.data, 'allOf')) {
for (var i = 0; !def && i < this.data.allOf.length; i++) {
for (let i = 0; !def && i < this.data.allOf.length; i++) {
def = this.data.allOf[i][global_1.__schema].default();

@@ -97,3 +134,3 @@ }

if (!global_1.defined(def) && global_1.enumerableAndDefined(this.data, 'anyOf')) {
for (var i = 0; !def && i < this.data.anyOf.length; i++) {
for (let i = 0; !def && i < this.data.anyOf.length; i++) {
def = this.data.anyOf[i][global_1.__schema].default();

@@ -103,3 +140,3 @@ }

if (!global_1.defined(def) && global_1.enumerableAndDefined(this.data, 'oneOf')) {
for (var i = 0; !def && i < this.data.oneOf.length; i++) {
for (let i = 0; !def && i < this.data.oneOf.length; i++) {
def = this.data.oneOf[i][global_1.__schema].default();

@@ -113,39 +150,2 @@ }

}
validate(data, path = '') {
if (this[__validating]) {
return data;
}
else {
this[__validating] = true;
}
data = this.default(data);
if (typeof data !== 'undefined') {
try {
if (global_1.enumerableAndDefined(this.data, 'type')) {
data = this.validateType(data, path);
}
if (global_1.enumerableAndDefined(this.data, 'enum')) {
data = this.validateEnum(data, path);
}
if (global_1.enumerableAndDefined(this.data, 'allOf')) {
data = this.validateAllOf(data, path);
}
if (global_1.enumerableAndDefined(this.data, 'anyOf')) {
data = this.validateAnyOf(data, path);
}
if (global_1.enumerableAndDefined(this.data, 'oneOf')) {
data = this.validateOneOf(data, path);
}
if (global_1.enumerableAndDefined(this.data, 'not')) {
data = this.validateNot(data, path);
}
}
catch (e) {
delete this[__validating];
throw e;
}
}
delete this[__validating];
return data;
}
validateType(data, path) {

@@ -155,3 +155,4 @@ throw new global_1.SchemaError(this.scope, 'type', data.type);

validateEnum(data, path) {
for (var i = 0, found = false; !found && i < this.data.enum.length; i++) {
let found = false;
for (let i = 0; !found && i < this.data.enum.length; i++) {
found = _.isEqual(data, this.data.enum[i]);

@@ -165,3 +166,3 @@ }

validateAllOf(data, path) {
for (var i = 0; i < this.data.allOf.length; i++) {
for (let i = 0; i < this.data.allOf.length; i++) {
data = this.data.allOf[i][global_1.__schema].validate(data, path);

@@ -172,3 +173,4 @@ }

validateAnyOf(data, path) {
for (var i = 0, found = false, _data; !found && i < this.data.anyOf.length; i++) {
let found = false, _data;
for (let i = 0; !found && i < this.data.anyOf.length; i++) {
try {

@@ -186,3 +188,4 @@ _data = this.data.anyOf[i][global_1.__schema].validate(data, path);

validateOneOf(data, path) {
for (var i = 0, count = 0, _data; count < 2 && i < this.data.oneOf.length; i++) {
let count = 0, _data;
for (let i = 0; count < 2 && i < this.data.oneOf.length; i++) {
try {

@@ -212,3 +215,3 @@ _data = this.data.oneOf[i][global_1.__schema].validate(data, path);

static create(data, opts = {}) {
var schema;
let schema;
if (global_1.defined(data)) {

@@ -221,5 +224,5 @@ if (data[global_1.__schema] instanceof Schema) {

if (Array.isArray(data.type)) {
var _data = { anyOf: [] };
let _data = { anyOf: [] };
_.each(data.type, function (type) {
var _type = _.clone(data);
let _type = _.clone(data);
_type.type = type;

@@ -254,3 +257,3 @@ _data.anyOf.push(_type);

else {
var out = {};
let out = {};
// Init the data that must be taken from the outer schema

@@ -342,6 +345,6 @@ if (global_1.enumerableAndDefined(data, 'id'))

}
for (var k in i.dependencies) {
for (let k in i.dependencies) {
if (global_1.enumerableAndDefined(o.dependencies, k)) {
var _o = o.dependencies;
var _i = i.dependencies;
let _o = o.dependencies;
let _i = i.dependencies;
if (Array.isArray(_o[k]) && Array.isArray(_i[k])) {

@@ -348,0 +351,0 @@ _o[k] = _.uniq(_o[k].concat(_i[k]));

"use strict";
const _ = require('lodash');
const refs = require('jsonref');
var knownVersions = {
let knownVersions = {
'http://json-schema.org/draft-04/schema#': {

@@ -156,4 +156,4 @@ "id": "http://json-schema.org/draft-04/schema#",

};
var parsedVersions = {};
var defaultVersion = 'http://json-schema.org/draft-04/schema#';
let parsedVersions = {};
let defaultVersion = 'http://json-schema.org/draft-04/schema#';
function reset() {

@@ -188,3 +188,3 @@ parsedVersions = {};

function parseKnown() {
var p = Promise.resolve(true);
let p = Promise.resolve(true);
_.each(knownVersions, function (data, uri) {

@@ -191,0 +191,0 @@ if (!parsedVersions[uri]) {

{
"name": "jsonpolice",
"version": "3.4.1",
"version": "3.5.0",
"description": "JSON Schema parser and validator",

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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