@hyperjump/json-schema
Advanced tools
Comparing version 0.14.0 to 0.15.0
@@ -20,5 +20,5 @@ const { Core, Schema, Instance } = require("@hyperjump/json-schema-core"); | ||
const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => { | ||
return interpret(keywordValue, instance, ast, dynamicAnchors) && Number.MAX_SAFE_INTEGER; | ||
return interpret(keywordValue, instance, ast, dynamicAnchors) && new Set(Instance.map((item, ndx) => ndx, instance)); | ||
}; | ||
module.exports = { compile, interpret, collectEvaluatedItems }; |
@@ -17,3 +17,3 @@ const { Core, Schema } = require("@hyperjump/json-schema-core"); | ||
const propertyNames = acc && Core.collectEvaluatedProperties(schemaUrl, instance, ast, dynamicAnchors); | ||
return propertyNames && acc.concat(propertyNames); | ||
return propertyNames !== false && [...acc, ...propertyNames]; | ||
}, []); | ||
@@ -24,7 +24,7 @@ }; | ||
return items.reduce((acc, schemaUrl) => { | ||
const tupleLength = acc !== false && Core.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors); | ||
return tupleLength !== false && Math.max(acc, tupleLength); | ||
}, 0); | ||
const itemIndexes = acc !== false && Core.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors); | ||
return itemIndexes !== false && new Set([...acc, ...itemIndexes]); | ||
}, new Set()); | ||
}; | ||
module.exports = { compile, interpret, collectEvaluatedProperties, collectEvaluatedItems }; |
@@ -18,3 +18,3 @@ const { Core, Schema } = require("@hyperjump/json-schema-core"); | ||
const propertyNames = Core.collectEvaluatedProperties(schemaUrl, instance, ast, dynamicAnchors); | ||
return propertyNames ? (acc || []).concat(propertyNames) : acc; | ||
return propertyNames !== false ? [...(acc || []), ...propertyNames] : acc; | ||
}, false); | ||
@@ -25,4 +25,4 @@ }; | ||
return anyOf.reduce((acc, schemaUrl) => { | ||
const tupleLength = Core.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors); | ||
return tupleLength !== false ? Math.max(acc, tupleLength) : acc; | ||
const itemIndexes = Core.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors); | ||
return itemIndexes !== false ? new Set([...(acc || []), ...itemIndexes]) : acc; | ||
}, false); | ||
@@ -29,0 +29,0 @@ }; |
@@ -27,2 +27,8 @@ const { Core, Schema, Instance } = require("@hyperjump/json-schema-core"); | ||
module.exports = { compile, interpret }; | ||
const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => { | ||
return interpret(keywordValue) && Instance.reduce((matchedIndexes, item, itemIndex) => { | ||
return Core.interpretSchema(keywordValue.contains, item, ast, dynamicAnchors) ? matchedIndexes.add(itemIndex) : matchedIndexes; | ||
}, new Set(), instance); | ||
}; | ||
module.exports = { compile, interpret, collectEvaluatedItems }; |
@@ -20,6 +20,4 @@ const { Core, Schema, Instance } = require("@hyperjump/json-schema-core"); | ||
const collectEvaluatedProperties = (dependentSchemas, instance, ast, dynamicAnchors) => { | ||
const value = Instance.value(instance); | ||
return dependentSchemas.reduce((acc, [propertyName, dependentSchema]) => { | ||
if (!acc || !(propertyName in value)) { | ||
if (!acc || !Instance.has(propertyName, instance)) { | ||
return acc; | ||
@@ -29,3 +27,3 @@ } | ||
const propertyNames = Core.collectEvaluatedProperties(dependentSchema, instance, ast, dynamicAnchors); | ||
return propertyNames && acc.concat(propertyNames); | ||
return propertyNames !== false && acc.concat(propertyNames); | ||
}, []); | ||
@@ -32,0 +30,0 @@ }; |
@@ -36,4 +36,4 @@ const { Core, Schema } = require("@hyperjump/json-schema-core"); | ||
const collectEvaluatedItems = ([guard, block], instance, ast, dynamicAnchors) => { | ||
if (guard === undefined || Core.interpretSchema(guard, instance, ast, dynamicAnchors)) { | ||
return 0; | ||
if (guard === undefined || Core.collectEvaluatedItems(guard, instance, ast, dynamicAnchors) !== false) { | ||
return new Set(); | ||
} | ||
@@ -40,0 +40,0 @@ |
@@ -25,3 +25,2 @@ const { Keywords } = require("@hyperjump/json-schema-core"); | ||
items: require("./items"), | ||
items2020XX: require("./items2020XX"), | ||
maxItems: require("./maxItems"), | ||
@@ -28,0 +27,0 @@ maxLength: require("./maxLength"), |
@@ -29,5 +29,7 @@ const { Core, Schema, Instance } = require("@hyperjump/json-schema-core"); | ||
const collectEvaluatedItems = (items, instance, ast, dynamicAnchors) => { | ||
return interpret(items, instance, ast, dynamicAnchors) && (typeof items === "string" ? Number.MAX_SAFE_INTEGER : items.length); | ||
return interpret(items, instance, ast, dynamicAnchors) && (typeof items === "string" | ||
? new Set(Instance.map((item, itemIndex) => itemIndex, instance)) | ||
: new Set(items.map((item, itemIndex) => itemIndex))); | ||
}; | ||
module.exports = { compile, interpret, collectEvaluatedItems }; |
@@ -44,4 +44,4 @@ const { Core, Schema } = require("@hyperjump/json-schema-core"); | ||
const tupleLength = Core.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors); | ||
return typeof tupleLength === "number" ? validCount++ === 0 && tupleLength : acc; | ||
const itemIndexes = Core.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors); | ||
return itemIndexes ? validCount++ === 0 && itemIndexes : acc; | ||
}, false); | ||
@@ -48,0 +48,0 @@ }; |
@@ -38,13 +38,19 @@ const { Core, Schema } = require("@hyperjump/json-schema-core"); | ||
const blockPropertyNames = Core.collectEvaluatedProperties(block, instance, ast, dynamicAnchors); | ||
return blockPropertyNames === false ? false : guardPropertyNames.concat(blockPropertyNames); | ||
return blockPropertyNames !== false && [...guardPropertyNames, ...blockPropertyNames]; | ||
}; | ||
const collectEvaluatedItems = ([guard, block], instance, ast, dynamicAnchors) => { | ||
if (guard === undefined || !Core.interpretSchema(guard, instance, ast, dynamicAnchors)) { | ||
return 0; | ||
if (guard === undefined) { | ||
return new Set(); | ||
} | ||
return Math.max(Core.collectEvaluatedItems(guard, instance, ast, dynamicAnchors), Core.collectEvaluatedItems(block, instance, ast, dynamicAnchors)); | ||
const guardItemIndexes = Core.collectEvaluatedItems(guard, instance, ast, dynamicAnchors); | ||
if (guardItemIndexes === false) { | ||
return new Set(); | ||
} | ||
const blockItemIndexes = Core.collectEvaluatedItems(block, instance, ast, dynamicAnchors); | ||
return blockItemIndexes !== false && new Set([...guardItemIndexes, ...blockItemIndexes]); | ||
}; | ||
module.exports = { compile, interpret, collectEvaluatedProperties, collectEvaluatedItems }; |
@@ -20,4 +20,6 @@ const { Core, Schema, Instance } = require("@hyperjump/json-schema-core"); | ||
const collectEvaluatedItems = (items, instance, ast, dynamicAnchors) => interpret(items, instance, ast, dynamicAnchors) && items.length; | ||
const collectEvaluatedItems = (items, instance, ast, dynamicAnchors) => { | ||
return interpret(items, instance, ast, dynamicAnchors) && new Set(items.map((item, ndx) => ndx)); | ||
}; | ||
module.exports = { compile, interpret, collectEvaluatedItems }; |
@@ -13,11 +13,12 @@ const { Core, Schema, Instance } = require("@hyperjump/json-schema-core"); | ||
const tupleLength = Core.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors, true); | ||
return tupleLength === false || Instance.filter((item, ndx) => ndx >= tupleLength, instance) | ||
.every((item) => Core.interpretSchema(unevaluatedItems, item, ast, dynamicAnchors)); | ||
const itemIndexes = Core.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors, true); | ||
return itemIndexes === false || Instance.every((item, itemIndex) => { | ||
return itemIndexes.has(itemIndex) || Core.interpretSchema(unevaluatedItems, Instance.step(itemIndex, instance), ast, dynamicAnchors); | ||
}, instance); | ||
}; | ||
const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => { | ||
return interpret(keywordValue, instance, ast, dynamicAnchors) && Number.MAX_SAFE_INTEGER; | ||
return interpret(keywordValue, instance, ast, dynamicAnchors) && new Set(Instance.map((item, ndx) => ndx, instance)); | ||
}; | ||
module.exports = { compile, interpret, collectEvaluatedItems }; |
{ | ||
"name": "@hyperjump/json-schema", | ||
"version": "0.14.0", | ||
"version": "0.15.0", | ||
"description": "A JSON Schema Validator", | ||
@@ -42,5 +42,5 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@hyperjump/json-schema-core": "^0.18.0", | ||
"@hyperjump/json-schema-core": "^0.19.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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3951622
92
22951
+ Added@hyperjump/json-schema-core@0.19.0(transitive)
- Removed@hyperjump/json-schema-core@0.18.0(transitive)