@hyperjump/json-schema
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -8,11 +8,3 @@ import metaData from "./keywords/meta-data.js"; | ||
export const addKeyword = (keywordHandler) => { | ||
_keywords[keywordHandler.id] = { | ||
collectEvaluatedItems: (keywordValue, instance, ast, dynamicAnchors, isTop) => { | ||
return keywordHandler.interpret(keywordValue, instance, ast, dynamicAnchors, isTop) && new Set(); | ||
}, | ||
collectEvaluatedProperties: (keywordValue, instance, ast, dynamicAnchors, isTop) => { | ||
return keywordHandler.interpret(keywordValue, instance, ast, dynamicAnchors, isTop) && []; | ||
}, | ||
...keywordHandler | ||
}; | ||
_keywords[keywordHandler.id] = keywordHandler; | ||
}; | ||
@@ -19,0 +11,0 @@ |
@@ -92,2 +92,3 @@ import * as Pact from "@hyperjump/pact"; | ||
const emptyPropertyNames = []; | ||
const collectEvaluatedProperties = (url, instance, ast, dynamicAnchors, isTop = false) => { | ||
@@ -100,10 +101,24 @@ const nodes = ast[url][2]; | ||
return nodes | ||
.filter(([keywordId]) => !isTop || keywordId !== "https://json-schema.org/keyword/unevaluatedProperties") | ||
.reduce((acc, [keywordId, , keywordValue]) => { | ||
const propertyNames = acc && getKeyword(keywordId).collectEvaluatedProperties(keywordValue, instance, ast, dynamicAnchors); | ||
return propertyNames !== false && [...acc, ...propertyNames]; | ||
}, []); | ||
const accumulatedPropertyNames = []; | ||
for (const [keywordId, , keywordValue] of nodes) { | ||
if (isTop && keywordId === "https://json-schema.org/keyword/unevaluatedProperties") { | ||
continue; | ||
} | ||
const keywordHandler = getKeyword(keywordId); | ||
const propertyNames = "collectEvaluatedProperties" in keywordHandler | ||
? keywordHandler.collectEvaluatedProperties(keywordValue, instance, ast, dynamicAnchors, isTop) | ||
: keywordHandler.interpret(keywordValue, instance, ast, dynamicAnchors, isTop) && emptyPropertyNames; | ||
if (propertyNames === false) { | ||
return false; | ||
} | ||
Array.prototype.push.apply(accumulatedPropertyNames, propertyNames); | ||
} | ||
return accumulatedPropertyNames; | ||
}; | ||
const emptyItemIndexes = new Set(); | ||
const collectEvaluatedItems = (url, instance, ast, dynamicAnchors, isTop = false) => { | ||
@@ -116,10 +131,23 @@ const nodes = ast[url][2]; | ||
return nodes | ||
.filter(([keywordId]) => !isTop || keywordId !== "https://json-schema.org/keyword/unevaluatedItems") | ||
.reduce((acc, [keywordId, , keywordValue]) => { | ||
const itemIndexes = acc !== false && getKeyword(keywordId).collectEvaluatedItems(keywordValue, instance, ast, dynamicAnchors); | ||
return itemIndexes !== false && new Set([...acc, ...itemIndexes]); | ||
}, new Set()); | ||
const accumulatedItemIndexes = new Set(); | ||
for (const [keywordId, , keywordValue] of nodes) { | ||
if (isTop && keywordId === "https://json-schema.org/keyword/unevaluatedItems") { | ||
continue; | ||
} | ||
const keywordHandler = getKeyword(keywordId); | ||
const itemIndexes = "collectEvaluatedItems" in keywordHandler | ||
? keywordHandler.collectEvaluatedItems(keywordValue, instance, ast, dynamicAnchors, isTop) | ||
: keywordHandler.interpret(keywordValue, instance, ast, dynamicAnchors, isTop) && emptyItemIndexes; | ||
if (itemIndexes === false) { | ||
return false; | ||
} | ||
itemIndexes.forEach(Set.prototype.add.bind(accumulatedItemIndexes)); | ||
} | ||
return accumulatedItemIndexes; | ||
}; | ||
export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems }; |
{ | ||
"name": "@hyperjump/json-schema", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "A JSON Schema validator with support for custom keywords, vocabularies, and dialects", | ||
@@ -74,4 +74,4 @@ "type": "module", | ||
"engines": { | ||
"node": "^18.0.0" | ||
"node": ">=18.0.0" | ||
} | ||
} |
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
288875
7828