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

@hyperjump/json-schema

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hyperjump/json-schema - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

lib/keywords/unevaluatedItems.js

3

lib/common.js
const isObject = (value) => typeof value === "object" && !Array.isArray(value) && value !== null;
const escapeRegExp = (string) => string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
module.exports = { isObject };
module.exports = { isObject, escapeRegExp };

@@ -46,3 +46,5 @@ const { Core, Schema } = require("@hyperjump/json-schema-core");

"properties": keywords.properties,
"propertyNames": keywords.propertyNames
"propertyNames": keywords.propertyNames,
"unevaluatedItems": keywords.unevaluatedItems,
"unevaluatedProperties": keywords.unevaluatedProperties
});

@@ -49,0 +51,0 @@

@@ -20,2 +20,6 @@ const { Core, Schema, Instance } = require("@hyperjump/json-schema-core");

module.exports = { compile, interpret };
const collectEvaluatedItems = (keywordValue, instance, ast) => {
return interpret(keywordValue, instance, ast) && Number.MAX_SAFE_INTEGER;
};
module.exports = { compile, interpret, collectEvaluatedItems };

@@ -30,2 +30,6 @@ const { Core, Schema, Instance } = require("@hyperjump/json-schema-core");

module.exports = { compile, interpret };
const collectEvaluatedProperties = (keywordValue, instance, ast) => {
return interpret(keywordValue, instance, ast) && [new RegExp("")];
};
module.exports = { compile, interpret, collectEvaluatedProperties };

@@ -12,2 +12,16 @@ const { Core, Schema } = require("@hyperjump/json-schema-core");

module.exports = { compile, interpret };
const collectEvaluatedProperties = (allOf, instance, ast) => {
return allOf.reduce((acc, schemaUrl) => {
const propertyNames = acc && Core.collectEvaluatedProperties(schemaUrl, instance, ast);
return propertyNames && acc.concat(propertyNames);
}, []);
};
const collectEvaluatedItems = (items, instance, ast) => {
return items.reduce((acc, schemaUrl) => {
const tupleLength = acc !== false && Core.collectEvaluatedItems(schemaUrl, instance, ast);
return tupleLength !== false && Math.max(acc, tupleLength);
}, 0);
};
module.exports = { compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };

@@ -12,2 +12,16 @@ const { Core, Schema } = require("@hyperjump/json-schema-core");

module.exports = { compile, interpret };
const collectEvaluatedProperties = (anyOf, instance, ast) => {
return anyOf.reduce((acc, schemaUrl) => {
const propertyNames = Core.collectEvaluatedProperties(schemaUrl, instance, ast);
return propertyNames ? (acc || []).concat(propertyNames) : acc;
}, false);
};
const collectEvaluatedItems = (anyOf, instance, ast) => {
return anyOf.reduce((acc, schemaUrl) => {
const tupleLength = Core.collectEvaluatedItems(schemaUrl, instance, ast);
return tupleLength !== false ? Math.max(acc, tupleLength) : acc;
}, false);
};
module.exports = { compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };

@@ -20,2 +20,15 @@ const { Core, Schema, Instance } = require("@hyperjump/json-schema-core");

module.exports = { compile, interpret };
const collectEvaluatedProperties = (dependentSchemas, instance, ast) => {
const value = Instance.value(instance);
return dependentSchemas.reduce((acc, [propertyName, dependentSchema]) => {
if (!acc || !(propertyName in value)) {
return acc;
}
const propertyNames = Core.collectEvaluatedProperties(dependentSchema, instance, ast);
return propertyNames && acc.concat(propertyNames);
}, []);
};
module.exports = { compile, interpret, collectEvaluatedProperties };

@@ -29,2 +29,26 @@ const { Core, Schema } = require("@hyperjump/json-schema-core");

module.exports = { compile, interpret };
const collectEvaluatedProperties = (conditional, instance, ast) => {
const propertyNames = Core.collectEvaluatedProperties(conditional["if"], instance, ast);
const branch = propertyNames ? "then": "else";
if (conditional[branch]) {
const branchPropertyNames = Core.collectEvaluatedProperties(conditional[branch], instance, ast);
return branchPropertyNames && (propertyNames || []).concat(branchPropertyNames);
} else {
return propertyNames;
}
};
const collectEvaluatedItems = (conditional, instance, ast) => {
const tupleLength = Core.collectEvaluatedItems(conditional["if"], instance, ast);
const branch = typeof tupleLength === "number" ? "then": "else";
if (conditional[branch]) {
const branchTupleLength = Core.collectEvaluatedItems(conditional[branch], instance, ast);
return branchTupleLength !== false && Math.max(tupleLength, branchTupleLength);
} else {
return tupleLength;
}
};
module.exports = { compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };

@@ -51,4 +51,6 @@ const { Keywords } = require("@hyperjump/json-schema-core");

type: require("./type"),
unevaluatedItems: require("./unevaluatedItems"),
unevaluatedProperties: require("./unevaluatedProperties"),
uniqueItems: require("./uniqueItems"),
validate: Keywords.validate
};

@@ -17,3 +17,4 @@ const { Core, Schema, Instance } = require("@hyperjump/json-schema-core");

const interpret = (items, instance, ast) => {
if (!Array.isArray(Instance.value(instance))) {
const value = Instance.value(instance);
if (!Array.isArray(value)) {
return true;

@@ -29,2 +30,6 @@ }

module.exports = { compile, interpret };
const collectEvaluatedItems = (items, instance, ast) => {
return interpret(items, instance, ast) && (typeof items === "string" ? Number.MAX_SAFE_INTEGER : items.length);
};
module.exports = { compile, interpret, collectEvaluatedItems };

@@ -13,4 +13,3 @@ const { Core, Schema } = require("@hyperjump/json-schema-core");

for (const schemaUrl of oneOf) {
const isValid = Core.interpretSchema(schemaUrl, instance, ast);
if (isValid) {
if (Core.interpretSchema(schemaUrl, instance, ast)) {
validCount++;

@@ -27,2 +26,26 @@ }

module.exports = { compile, interpret };
const collectEvaluatedProperties = (oneOf, instance, ast) => {
let validCount = 0;
return oneOf.reduce((acc, schemaUrl) => {
if (validCount > 1) {
return false;
}
const propertyNames = Core.collectEvaluatedProperties(schemaUrl, instance, ast);
return propertyNames ? validCount++ === 0 && propertyNames : acc;
}, false);
};
const collectEvaluatedItems = (oneOf, instance, ast) => {
let validCount = 0;
return oneOf.reduce((acc, schemaUrl) => {
if (validCount > 1) {
return false;
}
const tupleLength = Core.collectEvaluatedItems(schemaUrl, instance, ast);
return typeof tupleLength === "number" ? validCount++ === 0 && tupleLength : acc;
}, false);
};
module.exports = { compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };

@@ -24,2 +24,6 @@ const { Core, Schema, Instance } = require("@hyperjump/json-schema-core");

module.exports = { compile, interpret };
const collectEvaluatedProperties = (patternProperties, instance, ast) => {
return interpret(patternProperties, instance, ast) && patternProperties.map(([pattern]) => pattern);
};
module.exports = { compile, interpret, collectEvaluatedProperties };
const { Core, Schema, Instance } = require("@hyperjump/json-schema-core");
const Pact = require("@hyperjump/pact");
const { isObject } = require("../common");
const { isObject, escapeRegExp } = require("../common");

@@ -20,2 +20,7 @@

module.exports = { compile, interpret };
const collectEvaluatedProperties = (properties, instance, ast) => {
return interpret(properties, instance, ast) && Object.keys(properties)
.map((propertyName) => new RegExp(`^${escapeRegExp(propertyName)}$`));
};
module.exports = { compile, interpret, collectEvaluatedProperties };
{
"name": "@hyperjump/json-schema",
"version": "0.5.0",
"version": "0.6.0",
"description": "A JSON Schema Validator",

@@ -29,4 +29,4 @@ "main": "lib/index.js",

"devDependencies": {
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-node-resolve": "^7.1.1",
"@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-node-resolve": "^7.1.3",
"chai": "^4.2.0",

@@ -38,9 +38,9 @@ "eslint": "^4.19.1",

"mocha": "^5.2.0",
"rollup": "^2.6.0",
"rollup": "^2.6.1",
"rollup-plugin-terser": "^5.3.0"
},
"dependencies": {
"@hyperjump/json-schema-core": "^0.7.0",
"@hyperjump/json-schema-core": "^0.8.0",
"fastest-stable-stringify": "^2.0.2"
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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