@hyperjump/json-schema 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/keywords/validation.js +40 -12
- package/lib/keywords.js +1 -9
- package/package.json +2 -2
|
@@ -89,6 +89,7 @@ const interpret = (url, instance, ast, dynamicAnchors) => {
|
|
|
89
89
|
return isValid;
|
|
90
90
|
};
|
|
91
91
|
|
|
92
|
+
const emptyPropertyNames = [];
|
|
92
93
|
const collectEvaluatedProperties = (url, instance, ast, dynamicAnchors, isTop = false) => {
|
|
93
94
|
const nodes = ast[url][2];
|
|
94
95
|
|
|
@@ -96,14 +97,28 @@ const collectEvaluatedProperties = (url, instance, ast, dynamicAnchors, isTop =
|
|
|
96
97
|
return nodes ? [] : false;
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
const accumulatedPropertyNames = [];
|
|
101
|
+
for (const [keywordId, , keywordValue] of nodes) {
|
|
102
|
+
if (isTop && keywordId === "https://json-schema.org/keyword/unevaluatedProperties") {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const keywordHandler = getKeyword(keywordId);
|
|
107
|
+
const propertyNames = "collectEvaluatedProperties" in keywordHandler
|
|
108
|
+
? keywordHandler.collectEvaluatedProperties(keywordValue, instance, ast, dynamicAnchors, isTop)
|
|
109
|
+
: keywordHandler.interpret(keywordValue, instance, ast, dynamicAnchors, isTop) && emptyPropertyNames;
|
|
110
|
+
|
|
111
|
+
if (propertyNames === false) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
Array.prototype.push.apply(accumulatedPropertyNames, propertyNames);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return accumulatedPropertyNames;
|
|
105
119
|
};
|
|
106
120
|
|
|
121
|
+
const emptyItemIndexes = new Set();
|
|
107
122
|
const collectEvaluatedItems = (url, instance, ast, dynamicAnchors, isTop = false) => {
|
|
108
123
|
const nodes = ast[url][2];
|
|
109
124
|
|
|
@@ -111,12 +126,25 @@ const collectEvaluatedItems = (url, instance, ast, dynamicAnchors, isTop = false
|
|
|
111
126
|
return nodes ? new Set() : false;
|
|
112
127
|
}
|
|
113
128
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
129
|
+
const accumulatedItemIndexes = new Set();
|
|
130
|
+
for (const [keywordId, , keywordValue] of nodes) {
|
|
131
|
+
if (isTop && keywordId === "https://json-schema.org/keyword/unevaluatedItems") {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const keywordHandler = getKeyword(keywordId);
|
|
136
|
+
const itemIndexes = "collectEvaluatedItems" in keywordHandler
|
|
137
|
+
? keywordHandler.collectEvaluatedItems(keywordValue, instance, ast, dynamicAnchors, isTop)
|
|
138
|
+
: keywordHandler.interpret(keywordValue, instance, ast, dynamicAnchors, isTop) && emptyItemIndexes;
|
|
139
|
+
|
|
140
|
+
if (itemIndexes === false) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
itemIndexes.forEach(Set.prototype.add.bind(accumulatedItemIndexes));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return accumulatedItemIndexes;
|
|
120
148
|
};
|
|
121
149
|
|
|
122
150
|
export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
|
package/lib/keywords.js
CHANGED
|
@@ -5,15 +5,7 @@ const _keywords = {};
|
|
|
5
5
|
export const getKeyword = (id) => _keywords[id] || id.startsWith("https://json-schema.org/keyword/unknown#") && { id, ...metaData };
|
|
6
6
|
|
|
7
7
|
export const addKeyword = (keywordHandler) => {
|
|
8
|
-
_keywords[keywordHandler.id] =
|
|
9
|
-
collectEvaluatedItems: (keywordValue, instance, ast, dynamicAnchors, isTop) => {
|
|
10
|
-
return keywordHandler.interpret(keywordValue, instance, ast, dynamicAnchors, isTop) && new Set();
|
|
11
|
-
},
|
|
12
|
-
collectEvaluatedProperties: (keywordValue, instance, ast, dynamicAnchors, isTop) => {
|
|
13
|
-
return keywordHandler.interpret(keywordValue, instance, ast, dynamicAnchors, isTop) && [];
|
|
14
|
-
},
|
|
15
|
-
...keywordHandler
|
|
16
|
-
};
|
|
8
|
+
_keywords[keywordHandler.id] = keywordHandler;
|
|
17
9
|
};
|
|
18
10
|
|
|
19
11
|
const _vocabularies = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperjump/json-schema",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "A JSON Schema validator with support for custom keywords, vocabularies, and dialects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./stable/index.js",
|
|
@@ -71,6 +71,6 @@
|
|
|
71
71
|
"uuid": "^9.0.0"
|
|
72
72
|
},
|
|
73
73
|
"engines": {
|
|
74
|
-
"node": "
|
|
74
|
+
"node": ">=18.0.0"
|
|
75
75
|
}
|
|
76
76
|
}
|