z-schema 6.0.2 → 7.0.0-beta.1
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/README.md +154 -134
- package/bin/z-schema +128 -124
- package/dist/Errors.js +50 -0
- package/dist/FormatValidators.js +136 -0
- package/{src → dist}/JsonValidation.js +184 -213
- package/dist/Report.js +220 -0
- package/{src → dist}/SchemaCache.js +67 -82
- package/{src → dist}/SchemaCompilation.js +89 -129
- package/dist/SchemaValidation.js +631 -0
- package/{src → dist}/Utils.js +96 -104
- package/dist/ZSchema-umd-min.js +1 -0
- package/dist/ZSchema-umd.js +13791 -0
- package/dist/ZSchema.cjs +13785 -0
- package/dist/ZSchema.js +366 -0
- package/dist/schemas/hyper-schema.json +156 -0
- package/dist/schemas/schema.json +151 -0
- package/dist/types/Errors.d.ts +44 -0
- package/dist/types/FormatValidators.d.ts +12 -0
- package/dist/types/JsonValidation.d.ts +37 -0
- package/dist/types/Report.d.ts +87 -0
- package/dist/types/SchemaCache.d.ts +26 -0
- package/dist/types/SchemaCompilation.d.ts +1 -0
- package/dist/types/SchemaValidation.d.ts +6 -0
- package/dist/types/Utils.d.ts +64 -0
- package/dist/types/ZSchema.d.ts +97 -0
- package/package.json +54 -43
- package/src/Errors.ts +56 -0
- package/src/FormatValidators.ts +136 -0
- package/src/JsonValidation.ts +624 -0
- package/src/Report.ts +337 -0
- package/src/SchemaCache.ts +189 -0
- package/src/SchemaCompilation.ts +293 -0
- package/src/SchemaValidation.ts +629 -0
- package/src/Utils.ts +286 -0
- package/src/ZSchema.ts +469 -0
- package/src/schemas/_ +0 -0
- package/dist/ZSchema-browser-min.js +0 -2
- package/dist/ZSchema-browser-min.js.map +0 -1
- package/dist/ZSchema-browser-test.js +0 -32247
- package/dist/ZSchema-browser.js +0 -12745
- package/index.d.ts +0 -175
- package/src/Errors.js +0 -60
- package/src/FormatValidators.js +0 -129
- package/src/Polyfills.js +0 -16
- package/src/Report.js +0 -299
- package/src/SchemaValidation.js +0 -619
- package/src/ZSchema.js +0 -409
package/{src → dist}/Utils.js
RENAMED
|
@@ -1,71 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.jsonSymbol = Symbol.for("z-schema/json");
|
|
4
|
-
|
|
5
|
-
exports.schemaSymbol = Symbol.for("z-schema/schema");
|
|
6
|
-
|
|
1
|
+
export const jsonSymbol = Symbol.for('z-schema/json');
|
|
2
|
+
export const schemaSymbol = Symbol.for('z-schema/schema');
|
|
7
3
|
/**
|
|
8
4
|
* @param {object} obj
|
|
9
5
|
*
|
|
10
6
|
* @returns {string[]}
|
|
11
7
|
*/
|
|
12
|
-
|
|
8
|
+
export function sortedKeys(obj) {
|
|
13
9
|
return Object.keys(obj).sort();
|
|
14
|
-
}
|
|
15
|
-
|
|
10
|
+
}
|
|
16
11
|
/**
|
|
17
12
|
*
|
|
18
13
|
* @param {string} uri
|
|
19
14
|
*
|
|
20
15
|
* @returns {boolean}
|
|
21
16
|
*/
|
|
22
|
-
|
|
17
|
+
export function isAbsoluteUri(uri) {
|
|
23
18
|
return /^https?:\/\//.test(uri);
|
|
24
|
-
}
|
|
25
|
-
|
|
19
|
+
}
|
|
26
20
|
/**
|
|
27
21
|
*
|
|
28
22
|
* @param {string} uri
|
|
29
23
|
*
|
|
30
24
|
* @returns {boolean}
|
|
31
25
|
*/
|
|
32
|
-
|
|
26
|
+
export function isRelativeUri(uri) {
|
|
33
27
|
// relative URIs that end with a hash sign, issue #56
|
|
34
28
|
return /.+#/.test(uri);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var to = typeof what;
|
|
40
|
-
|
|
41
|
-
if (to === "object") {
|
|
29
|
+
}
|
|
30
|
+
export function whatIs(what) {
|
|
31
|
+
const to = typeof what;
|
|
32
|
+
if (to === 'object') {
|
|
42
33
|
if (what === null) {
|
|
43
|
-
return
|
|
34
|
+
return 'null';
|
|
44
35
|
}
|
|
45
36
|
if (Array.isArray(what)) {
|
|
46
|
-
return
|
|
37
|
+
return 'array';
|
|
47
38
|
}
|
|
48
|
-
return
|
|
39
|
+
return 'object'; // typeof what === 'object' && what === Object(what) && !Array.isArray(what);
|
|
49
40
|
}
|
|
50
|
-
|
|
51
|
-
if (to === "number") {
|
|
41
|
+
if (to === 'number') {
|
|
52
42
|
if (Number.isFinite(what)) {
|
|
53
43
|
if (what % 1 === 0) {
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
|
|
44
|
+
return 'integer';
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return 'number';
|
|
57
48
|
}
|
|
58
49
|
}
|
|
59
50
|
if (Number.isNaN(what)) {
|
|
60
|
-
return
|
|
51
|
+
return 'not-a-number';
|
|
61
52
|
}
|
|
62
|
-
return
|
|
53
|
+
return 'unknown-number';
|
|
63
54
|
}
|
|
64
|
-
|
|
65
55
|
return to; // undefined, boolean, string, function
|
|
66
|
-
|
|
67
|
-
};
|
|
68
|
-
|
|
56
|
+
}
|
|
69
57
|
/**
|
|
70
58
|
*
|
|
71
59
|
* @param {*} json1
|
|
@@ -74,13 +62,10 @@ exports.whatIs = function (what) {
|
|
|
74
62
|
*
|
|
75
63
|
* @returns {boolean}
|
|
76
64
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
65
|
+
export function areEqual(json1, json2, options) {
|
|
79
66
|
options = options || {};
|
|
80
|
-
|
|
81
|
-
|
|
67
|
+
const caseInsensitiveComparison = options.caseInsensitiveComparison || false;
|
|
82
68
|
// http://json-schema.org/latest/json-schema-core.html#rfc.section.3.6
|
|
83
|
-
|
|
84
69
|
// Two JSON values are said to be equal if and only if:
|
|
85
70
|
// both are nulls; or
|
|
86
71
|
// both are booleans, and have the same value; or
|
|
@@ -89,15 +74,13 @@ exports.areEqual = function areEqual(json1, json2, options) {
|
|
|
89
74
|
if (json1 === json2) {
|
|
90
75
|
return true;
|
|
91
76
|
}
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
77
|
+
if (caseInsensitiveComparison === true &&
|
|
78
|
+
typeof json1 === 'string' &&
|
|
79
|
+
typeof json2 === 'string' &&
|
|
80
|
+
json1.toUpperCase() === json2.toUpperCase()) {
|
|
96
81
|
return true;
|
|
97
82
|
}
|
|
98
|
-
|
|
99
|
-
var i, len;
|
|
100
|
-
|
|
83
|
+
let i, len;
|
|
101
84
|
// both are arrays, and:
|
|
102
85
|
if (Array.isArray(json1) && Array.isArray(json2)) {
|
|
103
86
|
// have the same number of items; and
|
|
@@ -113,12 +96,11 @@ exports.areEqual = function areEqual(json1, json2, options) {
|
|
|
113
96
|
}
|
|
114
97
|
return true;
|
|
115
98
|
}
|
|
116
|
-
|
|
117
99
|
// both are objects, and:
|
|
118
|
-
if (
|
|
100
|
+
if (whatIs(json1) === 'object' && whatIs(json2) === 'object') {
|
|
119
101
|
// have the same set of property names; and
|
|
120
|
-
|
|
121
|
-
|
|
102
|
+
const keys1 = sortedKeys(json1);
|
|
103
|
+
const keys2 = sortedKeys(json2);
|
|
122
104
|
if (!areEqual(keys1, keys2, { caseInsensitiveComparison: caseInsensitiveComparison })) {
|
|
123
105
|
return false;
|
|
124
106
|
}
|
|
@@ -131,10 +113,8 @@ exports.areEqual = function areEqual(json1, json2, options) {
|
|
|
131
113
|
}
|
|
132
114
|
return true;
|
|
133
115
|
}
|
|
134
|
-
|
|
135
116
|
return false;
|
|
136
|
-
}
|
|
137
|
-
|
|
117
|
+
}
|
|
138
118
|
/**
|
|
139
119
|
*
|
|
140
120
|
* @param {*[]} arr
|
|
@@ -142,19 +122,22 @@ exports.areEqual = function areEqual(json1, json2, options) {
|
|
|
142
122
|
*
|
|
143
123
|
* @returns {boolean}
|
|
144
124
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
125
|
+
export function isUniqueArray(arr, indexes) {
|
|
126
|
+
let i;
|
|
127
|
+
let j;
|
|
128
|
+
const l = arr.length;
|
|
147
129
|
for (i = 0; i < l; i++) {
|
|
148
130
|
for (j = i + 1; j < l; j++) {
|
|
149
|
-
if (
|
|
150
|
-
if (indexes) {
|
|
131
|
+
if (areEqual(arr[i], arr[j])) {
|
|
132
|
+
if (indexes) {
|
|
133
|
+
indexes.push(i, j);
|
|
134
|
+
}
|
|
151
135
|
return false;
|
|
152
136
|
}
|
|
153
137
|
}
|
|
154
138
|
}
|
|
155
139
|
return true;
|
|
156
|
-
}
|
|
157
|
-
|
|
140
|
+
}
|
|
158
141
|
/**
|
|
159
142
|
*
|
|
160
143
|
* @param {*} bigSet
|
|
@@ -162,77 +145,84 @@ exports.isUniqueArray = function (arr, indexes) {
|
|
|
162
145
|
*
|
|
163
146
|
* @returns {*[]}
|
|
164
147
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
148
|
+
export function difference(bigSet, subSet) {
|
|
149
|
+
const arr = [];
|
|
150
|
+
let idx = bigSet.length;
|
|
168
151
|
while (idx--) {
|
|
169
152
|
if (subSet.indexOf(bigSet[idx]) === -1) {
|
|
170
153
|
arr.push(bigSet[idx]);
|
|
171
154
|
}
|
|
172
155
|
}
|
|
173
156
|
return arr;
|
|
174
|
-
}
|
|
175
|
-
|
|
157
|
+
}
|
|
176
158
|
// NOT a deep version of clone
|
|
177
|
-
|
|
178
|
-
if (typeof src ===
|
|
179
|
-
|
|
180
|
-
|
|
159
|
+
export function clone(src) {
|
|
160
|
+
if (typeof src === 'undefined') {
|
|
161
|
+
return void 0;
|
|
162
|
+
}
|
|
163
|
+
if (typeof src !== 'object' || src === null) {
|
|
164
|
+
return src;
|
|
165
|
+
}
|
|
166
|
+
let res, idx;
|
|
181
167
|
if (Array.isArray(src)) {
|
|
182
168
|
res = [];
|
|
183
169
|
idx = src.length;
|
|
184
170
|
while (idx--) {
|
|
185
171
|
res[idx] = src[idx];
|
|
186
172
|
}
|
|
187
|
-
}
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
188
175
|
res = {};
|
|
189
|
-
|
|
176
|
+
const keys = Object.keys(src);
|
|
190
177
|
idx = keys.length;
|
|
191
178
|
while (idx--) {
|
|
192
|
-
|
|
179
|
+
const key = keys[idx];
|
|
193
180
|
res[key] = src[key];
|
|
194
181
|
}
|
|
195
182
|
}
|
|
196
183
|
return res;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
184
|
+
}
|
|
185
|
+
export function cloneDeep(src) {
|
|
186
|
+
let vidx = 0;
|
|
187
|
+
const visited = new Map();
|
|
188
|
+
const cloned = [];
|
|
189
|
+
function cloneDeepInner(src) {
|
|
190
|
+
if (typeof src !== 'object' || src === null) {
|
|
191
|
+
return src;
|
|
192
|
+
}
|
|
193
|
+
let res;
|
|
194
|
+
let idx;
|
|
195
|
+
const cidx = visited.get(src);
|
|
196
|
+
if (cidx !== undefined) {
|
|
197
|
+
return cloned[cidx];
|
|
198
|
+
}
|
|
208
199
|
visited.set(src, vidx++);
|
|
209
200
|
if (Array.isArray(src)) {
|
|
210
201
|
res = [];
|
|
211
202
|
cloned.push(res);
|
|
212
203
|
idx = src.length;
|
|
213
204
|
while (idx--) {
|
|
214
|
-
res[idx] =
|
|
205
|
+
res[idx] = cloneDeepInner(src[idx]);
|
|
215
206
|
}
|
|
216
|
-
}
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
217
209
|
res = {};
|
|
218
210
|
cloned.push(res);
|
|
219
|
-
|
|
211
|
+
const keys = Object.keys(src);
|
|
220
212
|
idx = keys.length;
|
|
221
213
|
while (idx--) {
|
|
222
|
-
|
|
223
|
-
res[key] =
|
|
214
|
+
const key = keys[idx];
|
|
215
|
+
res[key] = cloneDeepInner(src[key]);
|
|
224
216
|
}
|
|
225
217
|
}
|
|
226
218
|
return res;
|
|
227
219
|
}
|
|
228
|
-
return
|
|
229
|
-
}
|
|
230
|
-
|
|
220
|
+
return cloneDeepInner(src);
|
|
221
|
+
}
|
|
231
222
|
/*
|
|
232
223
|
following function comes from punycode.js library
|
|
233
224
|
see: https://github.com/bestiejs/punycode.js
|
|
234
225
|
*/
|
|
235
|
-
/*jshint -W016*/
|
|
236
226
|
/**
|
|
237
227
|
* Creates an array containing the numeric code points of each Unicode
|
|
238
228
|
* character in the string. While JavaScript uses UCS-2 internally,
|
|
@@ -246,29 +236,31 @@ exports.cloneDeep = function (src) {
|
|
|
246
236
|
* @param {String} string The Unicode input string (UCS-2).
|
|
247
237
|
* @returns {Array} The new array of code points.
|
|
248
238
|
*/
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
239
|
+
export function ucs2decode(string) {
|
|
240
|
+
const output = [];
|
|
241
|
+
let counter = 0;
|
|
242
|
+
const length = string.length;
|
|
243
|
+
let value;
|
|
244
|
+
let extra;
|
|
255
245
|
while (counter < length) {
|
|
256
246
|
value = string.charCodeAt(counter++);
|
|
257
|
-
if (value >=
|
|
247
|
+
if (value >= 0xd800 && value <= 0xdbff && counter < length) {
|
|
258
248
|
// high surrogate, and there is a next character
|
|
259
249
|
extra = string.charCodeAt(counter++);
|
|
260
|
-
if ((extra &
|
|
261
|
-
|
|
262
|
-
|
|
250
|
+
if ((extra & 0xfc00) == 0xdc00) {
|
|
251
|
+
// low surrogate
|
|
252
|
+
output.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
263
255
|
// unmatched surrogate; only append this code unit, in case the next
|
|
264
256
|
// code unit is the high surrogate of a surrogate pair
|
|
265
257
|
output.push(value);
|
|
266
258
|
counter--;
|
|
267
259
|
}
|
|
268
|
-
}
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
269
262
|
output.push(value);
|
|
270
263
|
}
|
|
271
264
|
}
|
|
272
265
|
return output;
|
|
273
|
-
}
|
|
274
|
-
/*jshint +W016*/
|
|
266
|
+
}
|