holosphere 2.0.0-alpha11 → 2.0.0-alpha13
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/dist/{2019-D2OG2idw.js → 2019-CLMqIAfQ.js} +1722 -1668
- package/dist/{2019-D2OG2idw.js.map → 2019-CLMqIAfQ.js.map} +1 -1
- package/dist/2019-Cp3uYhyY.cjs +8 -0
- package/dist/{2019-EION3wKo.cjs.map → 2019-Cp3uYhyY.cjs.map} +1 -1
- package/dist/browser-D6cNVl0v.cjs +2 -0
- package/dist/{browser-Cq59Ij19.cjs.map → browser-D6cNVl0v.cjs.map} +1 -1
- package/dist/{browser-BSniCNqO.js → browser-nUQt1cnB.js} +2 -2
- package/dist/{browser-BSniCNqO.js.map → browser-nUQt1cnB.js.map} +1 -1
- package/dist/cjs/holosphere.cjs +1 -1
- package/dist/esm/holosphere.js +67 -50
- package/dist/{index-D-jZhliX.js → index-BN_uoxQK.js} +20324 -735
- package/dist/index-BN_uoxQK.js.map +1 -0
- package/dist/{index-Bl6rM1NW.js → index-CoAjtqsD.js} +2 -2
- package/dist/{index-Bl6rM1NW.js.map → index-CoAjtqsD.js.map} +1 -1
- package/dist/{index-Bwg3OzRM.cjs → index-Cp3tI53z.cjs} +3 -3
- package/dist/{index-Bwg3OzRM.cjs.map → index-Cp3tI53z.cjs.map} +1 -1
- package/dist/index-DJjGSwXG.cjs +13 -0
- package/dist/index-DJjGSwXG.cjs.map +1 -0
- package/dist/index-V8EHMYEY.cjs +29 -0
- package/dist/index-V8EHMYEY.cjs.map +1 -0
- package/dist/index-Z5TstN1e.js +11663 -0
- package/dist/index-Z5TstN1e.js.map +1 -0
- package/dist/indexeddb-storage-CZK5A7XH.cjs +2 -0
- package/dist/indexeddb-storage-CZK5A7XH.cjs.map +1 -0
- package/dist/{indexeddb-storage-5eiUNsHC.js → indexeddb-storage-bpA01pAU.js} +39 -2
- package/dist/indexeddb-storage-bpA01pAU.js.map +1 -0
- package/dist/{memory-storage-DMt36uZO.cjs → memory-storage-B1k8Jszd.cjs} +2 -2
- package/dist/{memory-storage-DMt36uZO.cjs.map → memory-storage-B1k8Jszd.cjs.map} +1 -1
- package/dist/{memory-storage-CI-gfmuG.js → memory-storage-BqhmytP_.js} +2 -2
- package/dist/{memory-storage-CI-gfmuG.js.map → memory-storage-BqhmytP_.js.map} +1 -1
- package/docs/FEDERATION.md +474 -0
- package/package.json +3 -1
- package/src/crypto/nostr-utils.js +7 -0
- package/src/crypto/secp256k1.js +104 -38
- package/src/federation/capabilities.js +162 -0
- package/src/federation/card-storage.js +376 -0
- package/src/federation/handshake.js +561 -9
- package/src/federation/hologram.js +194 -57
- package/src/federation/holon-registry.js +187 -0
- package/src/federation/index.js +68 -0
- package/src/federation/registry.js +164 -6
- package/src/federation/request-card.js +373 -0
- package/src/hierarchical/upcast.js +19 -3
- package/src/index.js +209 -75
- package/src/lib/federation-methods.js +527 -5
- package/src/storage/indexeddb-storage.js +41 -0
- package/src/storage/nostr-async.js +14 -5
- package/src/storage/nostr-client.js +471 -155
- package/src/storage/nostr-wrapper.js +6 -3
- package/dist/2019-EION3wKo.cjs +0 -8
- package/dist/_commonjsHelpers-C37NGDzP.cjs +0 -2
- package/dist/_commonjsHelpers-C37NGDzP.cjs.map +0 -1
- package/dist/_commonjsHelpers-CUmg6egw.js +0 -7
- package/dist/_commonjsHelpers-CUmg6egw.js.map +0 -1
- package/dist/browser-Cq59Ij19.cjs +0 -2
- package/dist/index-D-jZhliX.js.map +0 -1
- package/dist/index-Dc6Z8Aob.cjs +0 -18
- package/dist/index-Dc6Z8Aob.cjs.map +0 -1
- package/dist/indexeddb-storage-5eiUNsHC.js.map +0 -1
- package/dist/indexeddb-storage-FNFUVvTJ.cjs +0 -2
- package/dist/indexeddb-storage-FNFUVvTJ.cjs.map +0 -1
- package/dist/secp256k1-CEwJNcfV.js +0 -1890
- package/dist/secp256k1-CEwJNcfV.js.map +0 -1
- package/dist/secp256k1-CiEONUnj.cjs +0 -12
- package/dist/secp256k1-CiEONUnj.cjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getDefaultExportFromCjs } from "./
|
|
1
|
+
import { g as getDefaultExportFromCjs } from "./index-BN_uoxQK.js";
|
|
2
2
|
function _mergeNamespaces(n, m) {
|
|
3
3
|
for (var i = 0; i < m.length; i++) {
|
|
4
4
|
const e = m[i];
|
|
@@ -175,866 +175,878 @@ var code$1 = {};
|
|
|
175
175
|
exports.regexpCode = regexpCode;
|
|
176
176
|
})(code$1);
|
|
177
177
|
var scope = {};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
UsedValueState2[UsedValueState2["Started"] = 0] = "Started";
|
|
191
|
-
UsedValueState2[UsedValueState2["Completed"] = 1] = "Completed";
|
|
192
|
-
})(UsedValueState || (exports.UsedValueState = UsedValueState = {}));
|
|
193
|
-
exports.varKinds = {
|
|
194
|
-
const: new code_12.Name("const"),
|
|
195
|
-
let: new code_12.Name("let"),
|
|
196
|
-
var: new code_12.Name("var")
|
|
197
|
-
};
|
|
198
|
-
class Scope {
|
|
199
|
-
constructor({ prefixes, parent } = {}) {
|
|
200
|
-
this._names = {};
|
|
201
|
-
this._prefixes = prefixes;
|
|
202
|
-
this._parent = parent;
|
|
203
|
-
}
|
|
204
|
-
toName(nameOrPrefix) {
|
|
205
|
-
return nameOrPrefix instanceof code_12.Name ? nameOrPrefix : this.name(nameOrPrefix);
|
|
206
|
-
}
|
|
207
|
-
name(prefix) {
|
|
208
|
-
return new code_12.Name(this._newName(prefix));
|
|
209
|
-
}
|
|
210
|
-
_newName(prefix) {
|
|
211
|
-
const ng = this._names[prefix] || this._nameGroup(prefix);
|
|
212
|
-
return `${prefix}${ng.index++}`;
|
|
213
|
-
}
|
|
214
|
-
_nameGroup(prefix) {
|
|
215
|
-
var _a, _b;
|
|
216
|
-
if (((_b = (_a = this._parent) === null || _a === void 0 ? void 0 : _a._prefixes) === null || _b === void 0 ? void 0 : _b.has(prefix)) || this._prefixes && !this._prefixes.has(prefix)) {
|
|
217
|
-
throw new Error(`CodeGen: prefix "${prefix}" is not allowed in this scope`);
|
|
178
|
+
var hasRequiredScope;
|
|
179
|
+
function requireScope() {
|
|
180
|
+
if (hasRequiredScope) return scope;
|
|
181
|
+
hasRequiredScope = 1;
|
|
182
|
+
(function(exports) {
|
|
183
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
184
|
+
exports.ValueScope = exports.ValueScopeName = exports.Scope = exports.varKinds = exports.UsedValueState = void 0;
|
|
185
|
+
const code_12 = code$1;
|
|
186
|
+
class ValueError extends Error {
|
|
187
|
+
constructor(name) {
|
|
188
|
+
super(`CodeGen: "code" for ${name} not defined`);
|
|
189
|
+
this.value = name.value;
|
|
218
190
|
}
|
|
219
|
-
return this._names[prefix] = { prefix, index: 0 };
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
exports.Scope = Scope;
|
|
223
|
-
class ValueScopeName extends code_12.Name {
|
|
224
|
-
constructor(prefix, nameStr) {
|
|
225
|
-
super(nameStr);
|
|
226
|
-
this.prefix = prefix;
|
|
227
|
-
}
|
|
228
|
-
setValue(value, { property, itemIndex }) {
|
|
229
|
-
this.value = value;
|
|
230
|
-
this.scopePath = (0, code_12._)`.${new code_12.Name(property)}[${itemIndex}]`;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
exports.ValueScopeName = ValueScopeName;
|
|
234
|
-
const line = (0, code_12._)`\n`;
|
|
235
|
-
class ValueScope extends Scope {
|
|
236
|
-
constructor(opts) {
|
|
237
|
-
super(opts);
|
|
238
|
-
this._values = {};
|
|
239
|
-
this._scope = opts.scope;
|
|
240
|
-
this.opts = { ...opts, _n: opts.lines ? line : code_12.nil };
|
|
241
|
-
}
|
|
242
|
-
get() {
|
|
243
|
-
return this._scope;
|
|
244
|
-
}
|
|
245
|
-
name(prefix) {
|
|
246
|
-
return new ValueScopeName(prefix, this._newName(prefix));
|
|
247
191
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
let
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
name
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
192
|
+
var UsedValueState;
|
|
193
|
+
(function(UsedValueState2) {
|
|
194
|
+
UsedValueState2[UsedValueState2["Started"] = 0] = "Started";
|
|
195
|
+
UsedValueState2[UsedValueState2["Completed"] = 1] = "Completed";
|
|
196
|
+
})(UsedValueState || (exports.UsedValueState = UsedValueState = {}));
|
|
197
|
+
exports.varKinds = {
|
|
198
|
+
const: new code_12.Name("const"),
|
|
199
|
+
let: new code_12.Name("let"),
|
|
200
|
+
var: new code_12.Name("var")
|
|
201
|
+
};
|
|
202
|
+
class Scope {
|
|
203
|
+
constructor({ prefixes, parent } = {}) {
|
|
204
|
+
this._names = {};
|
|
205
|
+
this._prefixes = prefixes;
|
|
206
|
+
this._parent = parent;
|
|
207
|
+
}
|
|
208
|
+
toName(nameOrPrefix) {
|
|
209
|
+
return nameOrPrefix instanceof code_12.Name ? nameOrPrefix : this.name(nameOrPrefix);
|
|
210
|
+
}
|
|
211
|
+
name(prefix) {
|
|
212
|
+
return new code_12.Name(this._newName(prefix));
|
|
213
|
+
}
|
|
214
|
+
_newName(prefix) {
|
|
215
|
+
const ng = this._names[prefix] || this._nameGroup(prefix);
|
|
216
|
+
return `${prefix}${ng.index++}`;
|
|
217
|
+
}
|
|
218
|
+
_nameGroup(prefix) {
|
|
219
|
+
var _a, _b;
|
|
220
|
+
if (((_b = (_a = this._parent) === null || _a === void 0 ? void 0 : _a._prefixes) === null || _b === void 0 ? void 0 : _b.has(prefix)) || this._prefixes && !this._prefixes.has(prefix)) {
|
|
221
|
+
throw new Error(`CodeGen: prefix "${prefix}" is not allowed in this scope`);
|
|
222
|
+
}
|
|
223
|
+
return this._names[prefix] = { prefix, index: 0 };
|
|
224
|
+
}
|
|
275
225
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
226
|
+
exports.Scope = Scope;
|
|
227
|
+
class ValueScopeName extends code_12.Name {
|
|
228
|
+
constructor(prefix, nameStr) {
|
|
229
|
+
super(nameStr);
|
|
230
|
+
this.prefix = prefix;
|
|
231
|
+
}
|
|
232
|
+
setValue(value, { property, itemIndex }) {
|
|
233
|
+
this.value = value;
|
|
234
|
+
this.scopePath = (0, code_12._)`.${new code_12.Name(property)}[${itemIndex}]`;
|
|
235
|
+
}
|
|
282
236
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
237
|
+
exports.ValueScopeName = ValueScopeName;
|
|
238
|
+
const line = (0, code_12._)`\n`;
|
|
239
|
+
class ValueScope extends Scope {
|
|
240
|
+
constructor(opts) {
|
|
241
|
+
super(opts);
|
|
242
|
+
this._values = {};
|
|
243
|
+
this._scope = opts.scope;
|
|
244
|
+
this.opts = { ...opts, _n: opts.lines ? line : code_12.nil };
|
|
245
|
+
}
|
|
246
|
+
get() {
|
|
247
|
+
return this._scope;
|
|
248
|
+
}
|
|
249
|
+
name(prefix) {
|
|
250
|
+
return new ValueScopeName(prefix, this._newName(prefix));
|
|
251
|
+
}
|
|
252
|
+
value(nameOrPrefix, value) {
|
|
253
|
+
var _a;
|
|
254
|
+
if (value.ref === void 0)
|
|
255
|
+
throw new Error("CodeGen: ref must be passed in value");
|
|
256
|
+
const name = this.toName(nameOrPrefix);
|
|
257
|
+
const { prefix } = name;
|
|
258
|
+
const valueKey = (_a = value.key) !== null && _a !== void 0 ? _a : value.ref;
|
|
259
|
+
let vs = this._values[prefix];
|
|
260
|
+
if (vs) {
|
|
261
|
+
const _name = vs.get(valueKey);
|
|
262
|
+
if (_name)
|
|
263
|
+
return _name;
|
|
264
|
+
} else {
|
|
265
|
+
vs = this._values[prefix] = /* @__PURE__ */ new Map();
|
|
266
|
+
}
|
|
267
|
+
vs.set(valueKey, name);
|
|
268
|
+
const s = this._scope[prefix] || (this._scope[prefix] = []);
|
|
269
|
+
const itemIndex = s.length;
|
|
270
|
+
s[itemIndex] = value.ref;
|
|
271
|
+
name.setValue(value, { property: prefix, itemIndex });
|
|
272
|
+
return name;
|
|
273
|
+
}
|
|
274
|
+
getValue(prefix, keyOrRef) {
|
|
275
|
+
const vs = this._values[prefix];
|
|
294
276
|
if (!vs)
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const def2 = this.opts.es5 ? exports.varKinds.var : exports.varKinds.const;
|
|
304
|
-
code2 = (0, code_12._)`${code2}${def2} ${name} = ${c};${this.opts._n}`;
|
|
305
|
-
} else if (c = getCode === null || getCode === void 0 ? void 0 : getCode(name)) {
|
|
306
|
-
code2 = (0, code_12._)`${code2}${c}${this.opts._n}`;
|
|
307
|
-
} else {
|
|
308
|
-
throw new ValueError(name);
|
|
309
|
-
}
|
|
310
|
-
nameSet.set(name, UsedValueState.Completed);
|
|
277
|
+
return;
|
|
278
|
+
return vs.get(keyOrRef);
|
|
279
|
+
}
|
|
280
|
+
scopeRefs(scopeName, values = this._values) {
|
|
281
|
+
return this._reduceValues(values, (name) => {
|
|
282
|
+
if (name.scopePath === void 0)
|
|
283
|
+
throw new Error(`CodeGen: name "${name}" has no value`);
|
|
284
|
+
return (0, code_12._)`${scopeName}${name.scopePath}`;
|
|
311
285
|
});
|
|
312
286
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
Object.defineProperty(exports, "Name", { enumerable: true, get: function() {
|
|
346
|
-
return code_2.Name;
|
|
347
|
-
} });
|
|
348
|
-
var scope_2 = scope;
|
|
349
|
-
Object.defineProperty(exports, "Scope", { enumerable: true, get: function() {
|
|
350
|
-
return scope_2.Scope;
|
|
351
|
-
} });
|
|
352
|
-
Object.defineProperty(exports, "ValueScope", { enumerable: true, get: function() {
|
|
353
|
-
return scope_2.ValueScope;
|
|
354
|
-
} });
|
|
355
|
-
Object.defineProperty(exports, "ValueScopeName", { enumerable: true, get: function() {
|
|
356
|
-
return scope_2.ValueScopeName;
|
|
357
|
-
} });
|
|
358
|
-
Object.defineProperty(exports, "varKinds", { enumerable: true, get: function() {
|
|
359
|
-
return scope_2.varKinds;
|
|
360
|
-
} });
|
|
361
|
-
exports.operators = {
|
|
362
|
-
GT: new code_12._Code(">"),
|
|
363
|
-
GTE: new code_12._Code(">="),
|
|
364
|
-
LT: new code_12._Code("<"),
|
|
365
|
-
LTE: new code_12._Code("<="),
|
|
366
|
-
EQ: new code_12._Code("==="),
|
|
367
|
-
NEQ: new code_12._Code("!=="),
|
|
368
|
-
NOT: new code_12._Code("!"),
|
|
369
|
-
OR: new code_12._Code("||"),
|
|
370
|
-
AND: new code_12._Code("&&"),
|
|
371
|
-
ADD: new code_12._Code("+")
|
|
372
|
-
};
|
|
373
|
-
class Node {
|
|
374
|
-
optimizeNodes() {
|
|
375
|
-
return this;
|
|
376
|
-
}
|
|
377
|
-
optimizeNames(_names, _constants) {
|
|
378
|
-
return this;
|
|
287
|
+
scopeCode(values = this._values, usedValues, getCode) {
|
|
288
|
+
return this._reduceValues(values, (name) => {
|
|
289
|
+
if (name.value === void 0)
|
|
290
|
+
throw new Error(`CodeGen: name "${name}" has no value`);
|
|
291
|
+
return name.value.code;
|
|
292
|
+
}, usedValues, getCode);
|
|
293
|
+
}
|
|
294
|
+
_reduceValues(values, valueCode, usedValues = {}, getCode) {
|
|
295
|
+
let code2 = code_12.nil;
|
|
296
|
+
for (const prefix in values) {
|
|
297
|
+
const vs = values[prefix];
|
|
298
|
+
if (!vs)
|
|
299
|
+
continue;
|
|
300
|
+
const nameSet = usedValues[prefix] = usedValues[prefix] || /* @__PURE__ */ new Map();
|
|
301
|
+
vs.forEach((name) => {
|
|
302
|
+
if (nameSet.has(name))
|
|
303
|
+
return;
|
|
304
|
+
nameSet.set(name, UsedValueState.Started);
|
|
305
|
+
let c = valueCode(name);
|
|
306
|
+
if (c) {
|
|
307
|
+
const def2 = this.opts.es5 ? exports.varKinds.var : exports.varKinds.const;
|
|
308
|
+
code2 = (0, code_12._)`${code2}${def2} ${name} = ${c};${this.opts._n}`;
|
|
309
|
+
} else if (c = getCode === null || getCode === void 0 ? void 0 : getCode(name)) {
|
|
310
|
+
code2 = (0, code_12._)`${code2}${c}${this.opts._n}`;
|
|
311
|
+
} else {
|
|
312
|
+
throw new ValueError(name);
|
|
313
|
+
}
|
|
314
|
+
nameSet.set(name, UsedValueState.Completed);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
return code2;
|
|
318
|
+
}
|
|
379
319
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
320
|
+
exports.ValueScope = ValueScope;
|
|
321
|
+
})(scope);
|
|
322
|
+
return scope;
|
|
323
|
+
}
|
|
324
|
+
var hasRequiredCodegen;
|
|
325
|
+
function requireCodegen() {
|
|
326
|
+
if (hasRequiredCodegen) return codegen;
|
|
327
|
+
hasRequiredCodegen = 1;
|
|
328
|
+
(function(exports) {
|
|
329
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
330
|
+
exports.or = exports.and = exports.not = exports.CodeGen = exports.operators = exports.varKinds = exports.ValueScopeName = exports.ValueScope = exports.Scope = exports.Name = exports.regexpCode = exports.stringify = exports.getProperty = exports.nil = exports.strConcat = exports.str = exports._ = void 0;
|
|
331
|
+
const code_12 = code$1;
|
|
332
|
+
const scope_1 = requireScope();
|
|
333
|
+
var code_2 = code$1;
|
|
334
|
+
Object.defineProperty(exports, "_", { enumerable: true, get: function() {
|
|
335
|
+
return code_2._;
|
|
336
|
+
} });
|
|
337
|
+
Object.defineProperty(exports, "str", { enumerable: true, get: function() {
|
|
338
|
+
return code_2.str;
|
|
339
|
+
} });
|
|
340
|
+
Object.defineProperty(exports, "strConcat", { enumerable: true, get: function() {
|
|
341
|
+
return code_2.strConcat;
|
|
342
|
+
} });
|
|
343
|
+
Object.defineProperty(exports, "nil", { enumerable: true, get: function() {
|
|
344
|
+
return code_2.nil;
|
|
345
|
+
} });
|
|
346
|
+
Object.defineProperty(exports, "getProperty", { enumerable: true, get: function() {
|
|
347
|
+
return code_2.getProperty;
|
|
348
|
+
} });
|
|
349
|
+
Object.defineProperty(exports, "stringify", { enumerable: true, get: function() {
|
|
350
|
+
return code_2.stringify;
|
|
351
|
+
} });
|
|
352
|
+
Object.defineProperty(exports, "regexpCode", { enumerable: true, get: function() {
|
|
353
|
+
return code_2.regexpCode;
|
|
354
|
+
} });
|
|
355
|
+
Object.defineProperty(exports, "Name", { enumerable: true, get: function() {
|
|
356
|
+
return code_2.Name;
|
|
357
|
+
} });
|
|
358
|
+
var scope_2 = requireScope();
|
|
359
|
+
Object.defineProperty(exports, "Scope", { enumerable: true, get: function() {
|
|
360
|
+
return scope_2.Scope;
|
|
361
|
+
} });
|
|
362
|
+
Object.defineProperty(exports, "ValueScope", { enumerable: true, get: function() {
|
|
363
|
+
return scope_2.ValueScope;
|
|
364
|
+
} });
|
|
365
|
+
Object.defineProperty(exports, "ValueScopeName", { enumerable: true, get: function() {
|
|
366
|
+
return scope_2.ValueScopeName;
|
|
367
|
+
} });
|
|
368
|
+
Object.defineProperty(exports, "varKinds", { enumerable: true, get: function() {
|
|
369
|
+
return scope_2.varKinds;
|
|
370
|
+
} });
|
|
371
|
+
exports.operators = {
|
|
372
|
+
GT: new code_12._Code(">"),
|
|
373
|
+
GTE: new code_12._Code(">="),
|
|
374
|
+
LT: new code_12._Code("<"),
|
|
375
|
+
LTE: new code_12._Code("<="),
|
|
376
|
+
EQ: new code_12._Code("==="),
|
|
377
|
+
NEQ: new code_12._Code("!=="),
|
|
378
|
+
NOT: new code_12._Code("!"),
|
|
379
|
+
OR: new code_12._Code("||"),
|
|
380
|
+
AND: new code_12._Code("&&"),
|
|
381
|
+
ADD: new code_12._Code("+")
|
|
382
|
+
};
|
|
383
|
+
class Node {
|
|
384
|
+
optimizeNodes() {
|
|
385
|
+
return this;
|
|
386
|
+
}
|
|
387
|
+
optimizeNames(_names, _constants) {
|
|
388
|
+
return this;
|
|
389
|
+
}
|
|
387
390
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
391
|
+
class Def extends Node {
|
|
392
|
+
constructor(varKind, name, rhs) {
|
|
393
|
+
super();
|
|
394
|
+
this.varKind = varKind;
|
|
395
|
+
this.name = name;
|
|
396
|
+
this.rhs = rhs;
|
|
397
|
+
}
|
|
398
|
+
render({ es5, _n }) {
|
|
399
|
+
const varKind = es5 ? scope_1.varKinds.var : this.varKind;
|
|
400
|
+
const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
|
|
401
|
+
return `${varKind} ${this.name}${rhs};` + _n;
|
|
402
|
+
}
|
|
403
|
+
optimizeNames(names2, constants) {
|
|
404
|
+
if (!names2[this.name.str])
|
|
405
|
+
return;
|
|
406
|
+
if (this.rhs)
|
|
407
|
+
this.rhs = optimizeExpr(this.rhs, names2, constants);
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
410
|
+
get names() {
|
|
411
|
+
return this.rhs instanceof code_12._CodeOrName ? this.rhs.names : {};
|
|
412
|
+
}
|
|
392
413
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
414
|
+
class Assign extends Node {
|
|
415
|
+
constructor(lhs, rhs, sideEffects) {
|
|
416
|
+
super();
|
|
417
|
+
this.lhs = lhs;
|
|
418
|
+
this.rhs = rhs;
|
|
419
|
+
this.sideEffects = sideEffects;
|
|
420
|
+
}
|
|
421
|
+
render({ _n }) {
|
|
422
|
+
return `${this.lhs} = ${this.rhs};` + _n;
|
|
423
|
+
}
|
|
424
|
+
optimizeNames(names2, constants) {
|
|
425
|
+
if (this.lhs instanceof code_12.Name && !names2[this.lhs.str] && !this.sideEffects)
|
|
426
|
+
return;
|
|
397
427
|
this.rhs = optimizeExpr(this.rhs, names2, constants);
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
class Assign extends Node {
|
|
405
|
-
constructor(lhs, rhs, sideEffects) {
|
|
406
|
-
super();
|
|
407
|
-
this.lhs = lhs;
|
|
408
|
-
this.rhs = rhs;
|
|
409
|
-
this.sideEffects = sideEffects;
|
|
410
|
-
}
|
|
411
|
-
render({ _n }) {
|
|
412
|
-
return `${this.lhs} = ${this.rhs};` + _n;
|
|
413
|
-
}
|
|
414
|
-
optimizeNames(names2, constants) {
|
|
415
|
-
if (this.lhs instanceof code_12.Name && !names2[this.lhs.str] && !this.sideEffects)
|
|
416
|
-
return;
|
|
417
|
-
this.rhs = optimizeExpr(this.rhs, names2, constants);
|
|
418
|
-
return this;
|
|
419
|
-
}
|
|
420
|
-
get names() {
|
|
421
|
-
const names2 = this.lhs instanceof code_12.Name ? {} : { ...this.lhs.names };
|
|
422
|
-
return addExprNames(names2, this.rhs);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
class AssignOp extends Assign {
|
|
426
|
-
constructor(lhs, op, rhs, sideEffects) {
|
|
427
|
-
super(lhs, rhs, sideEffects);
|
|
428
|
-
this.op = op;
|
|
429
|
-
}
|
|
430
|
-
render({ _n }) {
|
|
431
|
-
return `${this.lhs} ${this.op}= ${this.rhs};` + _n;
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
class Label extends Node {
|
|
435
|
-
constructor(label) {
|
|
436
|
-
super();
|
|
437
|
-
this.label = label;
|
|
438
|
-
this.names = {};
|
|
439
|
-
}
|
|
440
|
-
render({ _n }) {
|
|
441
|
-
return `${this.label}:` + _n;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
class Break extends Node {
|
|
445
|
-
constructor(label) {
|
|
446
|
-
super();
|
|
447
|
-
this.label = label;
|
|
448
|
-
this.names = {};
|
|
449
|
-
}
|
|
450
|
-
render({ _n }) {
|
|
451
|
-
const label = this.label ? ` ${this.label}` : "";
|
|
452
|
-
return `break${label};` + _n;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
class Throw extends Node {
|
|
456
|
-
constructor(error2) {
|
|
457
|
-
super();
|
|
458
|
-
this.error = error2;
|
|
459
|
-
}
|
|
460
|
-
render({ _n }) {
|
|
461
|
-
return `throw ${this.error};` + _n;
|
|
462
|
-
}
|
|
463
|
-
get names() {
|
|
464
|
-
return this.error.names;
|
|
428
|
+
return this;
|
|
429
|
+
}
|
|
430
|
+
get names() {
|
|
431
|
+
const names2 = this.lhs instanceof code_12.Name ? {} : { ...this.lhs.names };
|
|
432
|
+
return addExprNames(names2, this.rhs);
|
|
433
|
+
}
|
|
465
434
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
435
|
+
class AssignOp extends Assign {
|
|
436
|
+
constructor(lhs, op, rhs, sideEffects) {
|
|
437
|
+
super(lhs, rhs, sideEffects);
|
|
438
|
+
this.op = op;
|
|
439
|
+
}
|
|
440
|
+
render({ _n }) {
|
|
441
|
+
return `${this.lhs} ${this.op}= ${this.rhs};` + _n;
|
|
442
|
+
}
|
|
471
443
|
}
|
|
472
|
-
|
|
473
|
-
|
|
444
|
+
class Label extends Node {
|
|
445
|
+
constructor(label) {
|
|
446
|
+
super();
|
|
447
|
+
this.label = label;
|
|
448
|
+
this.names = {};
|
|
449
|
+
}
|
|
450
|
+
render({ _n }) {
|
|
451
|
+
return `${this.label}:` + _n;
|
|
452
|
+
}
|
|
474
453
|
}
|
|
475
|
-
|
|
476
|
-
|
|
454
|
+
class Break extends Node {
|
|
455
|
+
constructor(label) {
|
|
456
|
+
super();
|
|
457
|
+
this.label = label;
|
|
458
|
+
this.names = {};
|
|
459
|
+
}
|
|
460
|
+
render({ _n }) {
|
|
461
|
+
const label = this.label ? ` ${this.label}` : "";
|
|
462
|
+
return `break${label};` + _n;
|
|
463
|
+
}
|
|
477
464
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
465
|
+
class Throw extends Node {
|
|
466
|
+
constructor(error2) {
|
|
467
|
+
super();
|
|
468
|
+
this.error = error2;
|
|
469
|
+
}
|
|
470
|
+
render({ _n }) {
|
|
471
|
+
return `throw ${this.error};` + _n;
|
|
472
|
+
}
|
|
473
|
+
get names() {
|
|
474
|
+
return this.error.names;
|
|
475
|
+
}
|
|
481
476
|
}
|
|
482
|
-
|
|
483
|
-
|
|
477
|
+
class AnyCode extends Node {
|
|
478
|
+
constructor(code2) {
|
|
479
|
+
super();
|
|
480
|
+
this.code = code2;
|
|
481
|
+
}
|
|
482
|
+
render({ _n }) {
|
|
483
|
+
return `${this.code};` + _n;
|
|
484
|
+
}
|
|
485
|
+
optimizeNodes() {
|
|
486
|
+
return `${this.code}` ? this : void 0;
|
|
487
|
+
}
|
|
488
|
+
optimizeNames(names2, constants) {
|
|
489
|
+
this.code = optimizeExpr(this.code, names2, constants);
|
|
490
|
+
return this;
|
|
491
|
+
}
|
|
492
|
+
get names() {
|
|
493
|
+
return this.code instanceof code_12._CodeOrName ? this.code.names : {};
|
|
494
|
+
}
|
|
484
495
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
496
|
+
class ParentNode extends Node {
|
|
497
|
+
constructor(nodes = []) {
|
|
498
|
+
super();
|
|
499
|
+
this.nodes = nodes;
|
|
500
|
+
}
|
|
501
|
+
render(opts) {
|
|
502
|
+
return this.nodes.reduce((code2, n) => code2 + n.render(opts), "");
|
|
503
|
+
}
|
|
504
|
+
optimizeNodes() {
|
|
505
|
+
const { nodes } = this;
|
|
506
|
+
let i = nodes.length;
|
|
507
|
+
while (i--) {
|
|
508
|
+
const n = nodes[i].optimizeNodes();
|
|
509
|
+
if (Array.isArray(n))
|
|
510
|
+
nodes.splice(i, 1, ...n);
|
|
511
|
+
else if (n)
|
|
512
|
+
nodes[i] = n;
|
|
513
|
+
else
|
|
514
|
+
nodes.splice(i, 1);
|
|
515
|
+
}
|
|
516
|
+
return nodes.length > 0 ? this : void 0;
|
|
517
|
+
}
|
|
518
|
+
optimizeNames(names2, constants) {
|
|
519
|
+
const { nodes } = this;
|
|
520
|
+
let i = nodes.length;
|
|
521
|
+
while (i--) {
|
|
522
|
+
const n = nodes[i];
|
|
523
|
+
if (n.optimizeNames(names2, constants))
|
|
524
|
+
continue;
|
|
525
|
+
subtractNames(names2, n.names);
|
|
504
526
|
nodes.splice(i, 1);
|
|
527
|
+
}
|
|
528
|
+
return nodes.length > 0 ? this : void 0;
|
|
529
|
+
}
|
|
530
|
+
get names() {
|
|
531
|
+
return this.nodes.reduce((names2, n) => addNames(names2, n.names), {});
|
|
505
532
|
}
|
|
506
|
-
return nodes.length > 0 ? this : void 0;
|
|
507
533
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
while (i--) {
|
|
512
|
-
const n = nodes[i];
|
|
513
|
-
if (n.optimizeNames(names2, constants))
|
|
514
|
-
continue;
|
|
515
|
-
subtractNames(names2, n.names);
|
|
516
|
-
nodes.splice(i, 1);
|
|
534
|
+
class BlockNode extends ParentNode {
|
|
535
|
+
render(opts) {
|
|
536
|
+
return "{" + opts._n + super.render(opts) + "}" + opts._n;
|
|
517
537
|
}
|
|
518
|
-
return nodes.length > 0 ? this : void 0;
|
|
519
538
|
}
|
|
520
|
-
|
|
521
|
-
return this.nodes.reduce((names2, n) => addNames(names2, n.names), {});
|
|
539
|
+
class Root extends ParentNode {
|
|
522
540
|
}
|
|
523
|
-
|
|
524
|
-
class BlockNode extends ParentNode {
|
|
525
|
-
render(opts) {
|
|
526
|
-
return "{" + opts._n + super.render(opts) + "}" + opts._n;
|
|
541
|
+
class Else extends BlockNode {
|
|
527
542
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
Else.kind = "else";
|
|
534
|
-
class If extends BlockNode {
|
|
535
|
-
constructor(condition, nodes) {
|
|
536
|
-
super(nodes);
|
|
537
|
-
this.condition = condition;
|
|
538
|
-
}
|
|
539
|
-
render(opts) {
|
|
540
|
-
let code2 = `if(${this.condition})` + super.render(opts);
|
|
541
|
-
if (this.else)
|
|
542
|
-
code2 += "else " + this.else.render(opts);
|
|
543
|
-
return code2;
|
|
544
|
-
}
|
|
545
|
-
optimizeNodes() {
|
|
546
|
-
super.optimizeNodes();
|
|
547
|
-
const cond = this.condition;
|
|
548
|
-
if (cond === true)
|
|
549
|
-
return this.nodes;
|
|
550
|
-
let e = this.else;
|
|
551
|
-
if (e) {
|
|
552
|
-
const ns = e.optimizeNodes();
|
|
553
|
-
e = this.else = Array.isArray(ns) ? new Else(ns) : ns;
|
|
543
|
+
Else.kind = "else";
|
|
544
|
+
class If extends BlockNode {
|
|
545
|
+
constructor(condition, nodes) {
|
|
546
|
+
super(nodes);
|
|
547
|
+
this.condition = condition;
|
|
554
548
|
}
|
|
555
|
-
|
|
556
|
-
if
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
549
|
+
render(opts) {
|
|
550
|
+
let code2 = `if(${this.condition})` + super.render(opts);
|
|
551
|
+
if (this.else)
|
|
552
|
+
code2 += "else " + this.else.render(opts);
|
|
553
|
+
return code2;
|
|
554
|
+
}
|
|
555
|
+
optimizeNodes() {
|
|
556
|
+
super.optimizeNodes();
|
|
557
|
+
const cond = this.condition;
|
|
558
|
+
if (cond === true)
|
|
559
|
+
return this.nodes;
|
|
560
|
+
let e = this.else;
|
|
561
|
+
if (e) {
|
|
562
|
+
const ns = e.optimizeNodes();
|
|
563
|
+
e = this.else = Array.isArray(ns) ? new Else(ns) : ns;
|
|
564
|
+
}
|
|
565
|
+
if (e) {
|
|
566
|
+
if (cond === false)
|
|
567
|
+
return e instanceof If ? e : e.nodes;
|
|
568
|
+
if (this.nodes.length)
|
|
569
|
+
return this;
|
|
570
|
+
return new If(not2(cond), e instanceof If ? [e] : e.nodes);
|
|
571
|
+
}
|
|
572
|
+
if (cond === false || !this.nodes.length)
|
|
573
|
+
return void 0;
|
|
574
|
+
return this;
|
|
575
|
+
}
|
|
576
|
+
optimizeNames(names2, constants) {
|
|
577
|
+
var _a;
|
|
578
|
+
this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names2, constants);
|
|
579
|
+
if (!(super.optimizeNames(names2, constants) || this.else))
|
|
580
|
+
return;
|
|
581
|
+
this.condition = optimizeExpr(this.condition, names2, constants);
|
|
582
|
+
return this;
|
|
583
|
+
}
|
|
584
|
+
get names() {
|
|
585
|
+
const names2 = super.names;
|
|
586
|
+
addExprNames(names2, this.condition);
|
|
587
|
+
if (this.else)
|
|
588
|
+
addNames(names2, this.else.names);
|
|
589
|
+
return names2;
|
|
561
590
|
}
|
|
562
|
-
if (cond === false || !this.nodes.length)
|
|
563
|
-
return void 0;
|
|
564
|
-
return this;
|
|
565
|
-
}
|
|
566
|
-
optimizeNames(names2, constants) {
|
|
567
|
-
var _a;
|
|
568
|
-
this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names2, constants);
|
|
569
|
-
if (!(super.optimizeNames(names2, constants) || this.else))
|
|
570
|
-
return;
|
|
571
|
-
this.condition = optimizeExpr(this.condition, names2, constants);
|
|
572
|
-
return this;
|
|
573
|
-
}
|
|
574
|
-
get names() {
|
|
575
|
-
const names2 = super.names;
|
|
576
|
-
addExprNames(names2, this.condition);
|
|
577
|
-
if (this.else)
|
|
578
|
-
addNames(names2, this.else.names);
|
|
579
|
-
return names2;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
If.kind = "if";
|
|
583
|
-
class For extends BlockNode {
|
|
584
|
-
}
|
|
585
|
-
For.kind = "for";
|
|
586
|
-
class ForLoop extends For {
|
|
587
|
-
constructor(iteration) {
|
|
588
|
-
super();
|
|
589
|
-
this.iteration = iteration;
|
|
590
|
-
}
|
|
591
|
-
render(opts) {
|
|
592
|
-
return `for(${this.iteration})` + super.render(opts);
|
|
593
|
-
}
|
|
594
|
-
optimizeNames(names2, constants) {
|
|
595
|
-
if (!super.optimizeNames(names2, constants))
|
|
596
|
-
return;
|
|
597
|
-
this.iteration = optimizeExpr(this.iteration, names2, constants);
|
|
598
|
-
return this;
|
|
599
|
-
}
|
|
600
|
-
get names() {
|
|
601
|
-
return addNames(super.names, this.iteration.names);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
class ForRange extends For {
|
|
605
|
-
constructor(varKind, name, from, to) {
|
|
606
|
-
super();
|
|
607
|
-
this.varKind = varKind;
|
|
608
|
-
this.name = name;
|
|
609
|
-
this.from = from;
|
|
610
|
-
this.to = to;
|
|
611
|
-
}
|
|
612
|
-
render(opts) {
|
|
613
|
-
const varKind = opts.es5 ? scope_1.varKinds.var : this.varKind;
|
|
614
|
-
const { name, from, to } = this;
|
|
615
|
-
return `for(${varKind} ${name}=${from}; ${name}<${to}; ${name}++)` + super.render(opts);
|
|
616
|
-
}
|
|
617
|
-
get names() {
|
|
618
|
-
const names2 = addExprNames(super.names, this.from);
|
|
619
|
-
return addExprNames(names2, this.to);
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
class ForIter extends For {
|
|
623
|
-
constructor(loop, varKind, name, iterable) {
|
|
624
|
-
super();
|
|
625
|
-
this.loop = loop;
|
|
626
|
-
this.varKind = varKind;
|
|
627
|
-
this.name = name;
|
|
628
|
-
this.iterable = iterable;
|
|
629
|
-
}
|
|
630
|
-
render(opts) {
|
|
631
|
-
return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
|
|
632
|
-
}
|
|
633
|
-
optimizeNames(names2, constants) {
|
|
634
|
-
if (!super.optimizeNames(names2, constants))
|
|
635
|
-
return;
|
|
636
|
-
this.iterable = optimizeExpr(this.iterable, names2, constants);
|
|
637
|
-
return this;
|
|
638
591
|
}
|
|
639
|
-
|
|
640
|
-
|
|
592
|
+
If.kind = "if";
|
|
593
|
+
class For extends BlockNode {
|
|
641
594
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
}
|
|
661
|
-
Return.kind = "return";
|
|
662
|
-
class Try extends BlockNode {
|
|
663
|
-
render(opts) {
|
|
664
|
-
let code2 = "try" + super.render(opts);
|
|
665
|
-
if (this.catch)
|
|
666
|
-
code2 += this.catch.render(opts);
|
|
667
|
-
if (this.finally)
|
|
668
|
-
code2 += this.finally.render(opts);
|
|
669
|
-
return code2;
|
|
670
|
-
}
|
|
671
|
-
optimizeNodes() {
|
|
672
|
-
var _a, _b;
|
|
673
|
-
super.optimizeNodes();
|
|
674
|
-
(_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNodes();
|
|
675
|
-
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
|
|
676
|
-
return this;
|
|
595
|
+
For.kind = "for";
|
|
596
|
+
class ForLoop extends For {
|
|
597
|
+
constructor(iteration) {
|
|
598
|
+
super();
|
|
599
|
+
this.iteration = iteration;
|
|
600
|
+
}
|
|
601
|
+
render(opts) {
|
|
602
|
+
return `for(${this.iteration})` + super.render(opts);
|
|
603
|
+
}
|
|
604
|
+
optimizeNames(names2, constants) {
|
|
605
|
+
if (!super.optimizeNames(names2, constants))
|
|
606
|
+
return;
|
|
607
|
+
this.iteration = optimizeExpr(this.iteration, names2, constants);
|
|
608
|
+
return this;
|
|
609
|
+
}
|
|
610
|
+
get names() {
|
|
611
|
+
return addNames(super.names, this.iteration.names);
|
|
612
|
+
}
|
|
677
613
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
614
|
+
class ForRange extends For {
|
|
615
|
+
constructor(varKind, name, from, to) {
|
|
616
|
+
super();
|
|
617
|
+
this.varKind = varKind;
|
|
618
|
+
this.name = name;
|
|
619
|
+
this.from = from;
|
|
620
|
+
this.to = to;
|
|
621
|
+
}
|
|
622
|
+
render(opts) {
|
|
623
|
+
const varKind = opts.es5 ? scope_1.varKinds.var : this.varKind;
|
|
624
|
+
const { name, from, to } = this;
|
|
625
|
+
return `for(${varKind} ${name}=${from}; ${name}<${to}; ${name}++)` + super.render(opts);
|
|
626
|
+
}
|
|
627
|
+
get names() {
|
|
628
|
+
const names2 = addExprNames(super.names, this.from);
|
|
629
|
+
return addExprNames(names2, this.to);
|
|
630
|
+
}
|
|
684
631
|
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
632
|
+
class ForIter extends For {
|
|
633
|
+
constructor(loop, varKind, name, iterable) {
|
|
634
|
+
super();
|
|
635
|
+
this.loop = loop;
|
|
636
|
+
this.varKind = varKind;
|
|
637
|
+
this.name = name;
|
|
638
|
+
this.iterable = iterable;
|
|
639
|
+
}
|
|
640
|
+
render(opts) {
|
|
641
|
+
return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
|
|
642
|
+
}
|
|
643
|
+
optimizeNames(names2, constants) {
|
|
644
|
+
if (!super.optimizeNames(names2, constants))
|
|
645
|
+
return;
|
|
646
|
+
this.iterable = optimizeExpr(this.iterable, names2, constants);
|
|
647
|
+
return this;
|
|
648
|
+
}
|
|
649
|
+
get names() {
|
|
650
|
+
return addNames(super.names, this.iterable.names);
|
|
651
|
+
}
|
|
692
652
|
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
653
|
+
class Func extends BlockNode {
|
|
654
|
+
constructor(name, args, async) {
|
|
655
|
+
super();
|
|
656
|
+
this.name = name;
|
|
657
|
+
this.args = args;
|
|
658
|
+
this.async = async;
|
|
659
|
+
}
|
|
660
|
+
render(opts) {
|
|
661
|
+
const _async = this.async ? "async " : "";
|
|
662
|
+
return `${_async}function ${this.name}(${this.args})` + super.render(opts);
|
|
663
|
+
}
|
|
698
664
|
}
|
|
699
|
-
|
|
700
|
-
|
|
665
|
+
Func.kind = "func";
|
|
666
|
+
class Return extends ParentNode {
|
|
667
|
+
render(opts) {
|
|
668
|
+
return "return " + super.render(opts);
|
|
669
|
+
}
|
|
701
670
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
671
|
+
Return.kind = "return";
|
|
672
|
+
class Try extends BlockNode {
|
|
673
|
+
render(opts) {
|
|
674
|
+
let code2 = "try" + super.render(opts);
|
|
675
|
+
if (this.catch)
|
|
676
|
+
code2 += this.catch.render(opts);
|
|
677
|
+
if (this.finally)
|
|
678
|
+
code2 += this.finally.render(opts);
|
|
679
|
+
return code2;
|
|
680
|
+
}
|
|
681
|
+
optimizeNodes() {
|
|
682
|
+
var _a, _b;
|
|
683
|
+
super.optimizeNodes();
|
|
684
|
+
(_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNodes();
|
|
685
|
+
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
|
|
686
|
+
return this;
|
|
687
|
+
}
|
|
688
|
+
optimizeNames(names2, constants) {
|
|
689
|
+
var _a, _b;
|
|
690
|
+
super.optimizeNames(names2, constants);
|
|
691
|
+
(_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNames(names2, constants);
|
|
692
|
+
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names2, constants);
|
|
693
|
+
return this;
|
|
694
|
+
}
|
|
695
|
+
get names() {
|
|
696
|
+
const names2 = super.names;
|
|
697
|
+
if (this.catch)
|
|
698
|
+
addNames(names2, this.catch.names);
|
|
699
|
+
if (this.finally)
|
|
700
|
+
addNames(names2, this.finally.names);
|
|
701
|
+
return names2;
|
|
702
|
+
}
|
|
707
703
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
this._extScope = extScope;
|
|
717
|
-
this._scope = new scope_1.Scope({ parent: extScope });
|
|
718
|
-
this._nodes = [new Root()];
|
|
704
|
+
class Catch extends BlockNode {
|
|
705
|
+
constructor(error2) {
|
|
706
|
+
super();
|
|
707
|
+
this.error = error2;
|
|
708
|
+
}
|
|
709
|
+
render(opts) {
|
|
710
|
+
return `catch(${this.error})` + super.render(opts);
|
|
711
|
+
}
|
|
719
712
|
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
return this._scope.name(prefix);
|
|
726
|
-
}
|
|
727
|
-
// reserves unique name in the external scope
|
|
728
|
-
scopeName(prefix) {
|
|
729
|
-
return this._extScope.name(prefix);
|
|
730
|
-
}
|
|
731
|
-
// reserves unique name in the external scope and assigns value to it
|
|
732
|
-
scopeValue(prefixOrName, value) {
|
|
733
|
-
const name = this._extScope.value(prefixOrName, value);
|
|
734
|
-
const vs = this._values[name.prefix] || (this._values[name.prefix] = /* @__PURE__ */ new Set());
|
|
735
|
-
vs.add(name);
|
|
736
|
-
return name;
|
|
737
|
-
}
|
|
738
|
-
getScopeValue(prefix, keyOrRef) {
|
|
739
|
-
return this._extScope.getValue(prefix, keyOrRef);
|
|
740
|
-
}
|
|
741
|
-
// return code that assigns values in the external scope to the names that are used internally
|
|
742
|
-
// (same names that were returned by gen.scopeName or gen.scopeValue)
|
|
743
|
-
scopeRefs(scopeName) {
|
|
744
|
-
return this._extScope.scopeRefs(scopeName, this._values);
|
|
745
|
-
}
|
|
746
|
-
scopeCode() {
|
|
747
|
-
return this._extScope.scopeCode(this._values);
|
|
748
|
-
}
|
|
749
|
-
_def(varKind, nameOrPrefix, rhs, constant) {
|
|
750
|
-
const name = this._scope.toName(nameOrPrefix);
|
|
751
|
-
if (rhs !== void 0 && constant)
|
|
752
|
-
this._constants[name.str] = rhs;
|
|
753
|
-
this._leafNode(new Def(varKind, name, rhs));
|
|
754
|
-
return name;
|
|
755
|
-
}
|
|
756
|
-
// `const` declaration (`var` in es5 mode)
|
|
757
|
-
const(nameOrPrefix, rhs, _constant) {
|
|
758
|
-
return this._def(scope_1.varKinds.const, nameOrPrefix, rhs, _constant);
|
|
759
|
-
}
|
|
760
|
-
// `let` declaration with optional assignment (`var` in es5 mode)
|
|
761
|
-
let(nameOrPrefix, rhs, _constant) {
|
|
762
|
-
return this._def(scope_1.varKinds.let, nameOrPrefix, rhs, _constant);
|
|
763
|
-
}
|
|
764
|
-
// `var` declaration with optional assignment
|
|
765
|
-
var(nameOrPrefix, rhs, _constant) {
|
|
766
|
-
return this._def(scope_1.varKinds.var, nameOrPrefix, rhs, _constant);
|
|
767
|
-
}
|
|
768
|
-
// assignment code
|
|
769
|
-
assign(lhs, rhs, sideEffects) {
|
|
770
|
-
return this._leafNode(new Assign(lhs, rhs, sideEffects));
|
|
771
|
-
}
|
|
772
|
-
// `+=` code
|
|
773
|
-
add(lhs, rhs) {
|
|
774
|
-
return this._leafNode(new AssignOp(lhs, exports.operators.ADD, rhs));
|
|
775
|
-
}
|
|
776
|
-
// appends passed SafeExpr to code or executes Block
|
|
777
|
-
code(c) {
|
|
778
|
-
if (typeof c == "function")
|
|
779
|
-
c();
|
|
780
|
-
else if (c !== code_12.nil)
|
|
781
|
-
this._leafNode(new AnyCode(c));
|
|
782
|
-
return this;
|
|
713
|
+
Catch.kind = "catch";
|
|
714
|
+
class Finally extends BlockNode {
|
|
715
|
+
render(opts) {
|
|
716
|
+
return "finally" + super.render(opts);
|
|
717
|
+
}
|
|
783
718
|
}
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
719
|
+
Finally.kind = "finally";
|
|
720
|
+
class CodeGen {
|
|
721
|
+
constructor(extScope, opts = {}) {
|
|
722
|
+
this._values = {};
|
|
723
|
+
this._blockStarts = [];
|
|
724
|
+
this._constants = {};
|
|
725
|
+
this.opts = { ...opts, _n: opts.lines ? "\n" : "" };
|
|
726
|
+
this._extScope = extScope;
|
|
727
|
+
this._scope = new scope_1.Scope({ parent: extScope });
|
|
728
|
+
this._nodes = [new Root()];
|
|
729
|
+
}
|
|
730
|
+
toString() {
|
|
731
|
+
return this._root.render(this.opts);
|
|
732
|
+
}
|
|
733
|
+
// returns unique name in the internal scope
|
|
734
|
+
name(prefix) {
|
|
735
|
+
return this._scope.name(prefix);
|
|
736
|
+
}
|
|
737
|
+
// reserves unique name in the external scope
|
|
738
|
+
scopeName(prefix) {
|
|
739
|
+
return this._extScope.name(prefix);
|
|
740
|
+
}
|
|
741
|
+
// reserves unique name in the external scope and assigns value to it
|
|
742
|
+
scopeValue(prefixOrName, value) {
|
|
743
|
+
const name = this._extScope.value(prefixOrName, value);
|
|
744
|
+
const vs = this._values[name.prefix] || (this._values[name.prefix] = /* @__PURE__ */ new Set());
|
|
745
|
+
vs.add(name);
|
|
746
|
+
return name;
|
|
747
|
+
}
|
|
748
|
+
getScopeValue(prefix, keyOrRef) {
|
|
749
|
+
return this._extScope.getValue(prefix, keyOrRef);
|
|
750
|
+
}
|
|
751
|
+
// return code that assigns values in the external scope to the names that are used internally
|
|
752
|
+
// (same names that were returned by gen.scopeName or gen.scopeValue)
|
|
753
|
+
scopeRefs(scopeName) {
|
|
754
|
+
return this._extScope.scopeRefs(scopeName, this._values);
|
|
755
|
+
}
|
|
756
|
+
scopeCode() {
|
|
757
|
+
return this._extScope.scopeCode(this._values);
|
|
758
|
+
}
|
|
759
|
+
_def(varKind, nameOrPrefix, rhs, constant) {
|
|
760
|
+
const name = this._scope.toName(nameOrPrefix);
|
|
761
|
+
if (rhs !== void 0 && constant)
|
|
762
|
+
this._constants[name.str] = rhs;
|
|
763
|
+
this._leafNode(new Def(varKind, name, rhs));
|
|
764
|
+
return name;
|
|
765
|
+
}
|
|
766
|
+
// `const` declaration (`var` in es5 mode)
|
|
767
|
+
const(nameOrPrefix, rhs, _constant) {
|
|
768
|
+
return this._def(scope_1.varKinds.const, nameOrPrefix, rhs, _constant);
|
|
769
|
+
}
|
|
770
|
+
// `let` declaration with optional assignment (`var` in es5 mode)
|
|
771
|
+
let(nameOrPrefix, rhs, _constant) {
|
|
772
|
+
return this._def(scope_1.varKinds.let, nameOrPrefix, rhs, _constant);
|
|
773
|
+
}
|
|
774
|
+
// `var` declaration with optional assignment
|
|
775
|
+
var(nameOrPrefix, rhs, _constant) {
|
|
776
|
+
return this._def(scope_1.varKinds.var, nameOrPrefix, rhs, _constant);
|
|
777
|
+
}
|
|
778
|
+
// assignment code
|
|
779
|
+
assign(lhs, rhs, sideEffects) {
|
|
780
|
+
return this._leafNode(new Assign(lhs, rhs, sideEffects));
|
|
781
|
+
}
|
|
782
|
+
// `+=` code
|
|
783
|
+
add(lhs, rhs) {
|
|
784
|
+
return this._leafNode(new AssignOp(lhs, exports.operators.ADD, rhs));
|
|
785
|
+
}
|
|
786
|
+
// appends passed SafeExpr to code or executes Block
|
|
787
|
+
code(c) {
|
|
788
|
+
if (typeof c == "function")
|
|
789
|
+
c();
|
|
790
|
+
else if (c !== code_12.nil)
|
|
791
|
+
this._leafNode(new AnyCode(c));
|
|
792
|
+
return this;
|
|
793
|
+
}
|
|
794
|
+
// returns code for object literal for the passed argument list of key-value pairs
|
|
795
|
+
object(...keyValues) {
|
|
796
|
+
const code2 = ["{"];
|
|
797
|
+
for (const [key, value] of keyValues) {
|
|
798
|
+
if (code2.length > 1)
|
|
799
|
+
code2.push(",");
|
|
800
|
+
code2.push(key);
|
|
801
|
+
if (key !== value || this.opts.es5) {
|
|
802
|
+
code2.push(":");
|
|
803
|
+
(0, code_12.addCodeArg)(code2, value);
|
|
804
|
+
}
|
|
794
805
|
}
|
|
806
|
+
code2.push("}");
|
|
807
|
+
return new code_12._Code(code2);
|
|
795
808
|
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
throw new Error('CodeGen: "else" body without "then" body');
|
|
809
|
+
// `if` clause (or statement if `thenBody` and, optionally, `elseBody` are passed)
|
|
810
|
+
if(condition, thenBody, elseBody) {
|
|
811
|
+
this._blockNode(new If(condition));
|
|
812
|
+
if (thenBody && elseBody) {
|
|
813
|
+
this.code(thenBody).else().code(elseBody).endIf();
|
|
814
|
+
} else if (thenBody) {
|
|
815
|
+
this.code(thenBody).endIf();
|
|
816
|
+
} else if (elseBody) {
|
|
817
|
+
throw new Error('CodeGen: "else" body without "then" body');
|
|
818
|
+
}
|
|
819
|
+
return this;
|
|
808
820
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
elseIf(condition) {
|
|
813
|
-
return this._elseNode(new If(condition));
|
|
814
|
-
}
|
|
815
|
-
// `else` clause - only valid after `if` or `else if` clauses
|
|
816
|
-
else() {
|
|
817
|
-
return this._elseNode(new Else());
|
|
818
|
-
}
|
|
819
|
-
// end `if` statement (needed if gen.if was used only with condition)
|
|
820
|
-
endIf() {
|
|
821
|
-
return this._endBlockNode(If, Else);
|
|
822
|
-
}
|
|
823
|
-
_for(node, forBody) {
|
|
824
|
-
this._blockNode(node);
|
|
825
|
-
if (forBody)
|
|
826
|
-
this.code(forBody).endFor();
|
|
827
|
-
return this;
|
|
828
|
-
}
|
|
829
|
-
// a generic `for` clause (or statement if `forBody` is passed)
|
|
830
|
-
for(iteration, forBody) {
|
|
831
|
-
return this._for(new ForLoop(iteration), forBody);
|
|
832
|
-
}
|
|
833
|
-
// `for` statement for a range of values
|
|
834
|
-
forRange(nameOrPrefix, from, to, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.let) {
|
|
835
|
-
const name = this._scope.toName(nameOrPrefix);
|
|
836
|
-
return this._for(new ForRange(varKind, name, from, to), () => forBody(name));
|
|
837
|
-
}
|
|
838
|
-
// `for-of` statement (in es5 mode replace with a normal for loop)
|
|
839
|
-
forOf(nameOrPrefix, iterable, forBody, varKind = scope_1.varKinds.const) {
|
|
840
|
-
const name = this._scope.toName(nameOrPrefix);
|
|
841
|
-
if (this.opts.es5) {
|
|
842
|
-
const arr = iterable instanceof code_12.Name ? iterable : this.var("_arr", iterable);
|
|
843
|
-
return this.forRange("_i", 0, (0, code_12._)`${arr}.length`, (i) => {
|
|
844
|
-
this.var(name, (0, code_12._)`${arr}[${i}]`);
|
|
845
|
-
forBody(name);
|
|
846
|
-
});
|
|
821
|
+
// `else if` clause - invalid without `if` or after `else` clauses
|
|
822
|
+
elseIf(condition) {
|
|
823
|
+
return this._elseNode(new If(condition));
|
|
847
824
|
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
return this.
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
this.
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
this.
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
825
|
+
// `else` clause - only valid after `if` or `else if` clauses
|
|
826
|
+
else() {
|
|
827
|
+
return this._elseNode(new Else());
|
|
828
|
+
}
|
|
829
|
+
// end `if` statement (needed if gen.if was used only with condition)
|
|
830
|
+
endIf() {
|
|
831
|
+
return this._endBlockNode(If, Else);
|
|
832
|
+
}
|
|
833
|
+
_for(node, forBody) {
|
|
834
|
+
this._blockNode(node);
|
|
835
|
+
if (forBody)
|
|
836
|
+
this.code(forBody).endFor();
|
|
837
|
+
return this;
|
|
838
|
+
}
|
|
839
|
+
// a generic `for` clause (or statement if `forBody` is passed)
|
|
840
|
+
for(iteration, forBody) {
|
|
841
|
+
return this._for(new ForLoop(iteration), forBody);
|
|
842
|
+
}
|
|
843
|
+
// `for` statement for a range of values
|
|
844
|
+
forRange(nameOrPrefix, from, to, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.let) {
|
|
845
|
+
const name = this._scope.toName(nameOrPrefix);
|
|
846
|
+
return this._for(new ForRange(varKind, name, from, to), () => forBody(name));
|
|
847
|
+
}
|
|
848
|
+
// `for-of` statement (in es5 mode replace with a normal for loop)
|
|
849
|
+
forOf(nameOrPrefix, iterable, forBody, varKind = scope_1.varKinds.const) {
|
|
850
|
+
const name = this._scope.toName(nameOrPrefix);
|
|
851
|
+
if (this.opts.es5) {
|
|
852
|
+
const arr = iterable instanceof code_12.Name ? iterable : this.var("_arr", iterable);
|
|
853
|
+
return this.forRange("_i", 0, (0, code_12._)`${arr}.length`, (i) => {
|
|
854
|
+
this.var(name, (0, code_12._)`${arr}[${i}]`);
|
|
855
|
+
forBody(name);
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
return this._for(new ForIter("of", varKind, name, iterable), () => forBody(name));
|
|
859
|
+
}
|
|
860
|
+
// `for-in` statement.
|
|
861
|
+
// With option `ownProperties` replaced with a `for-of` loop for object keys
|
|
862
|
+
forIn(nameOrPrefix, obj, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.const) {
|
|
863
|
+
if (this.opts.ownProperties) {
|
|
864
|
+
return this.forOf(nameOrPrefix, (0, code_12._)`Object.keys(${obj})`, forBody);
|
|
865
|
+
}
|
|
866
|
+
const name = this._scope.toName(nameOrPrefix);
|
|
867
|
+
return this._for(new ForIter("in", varKind, name, obj), () => forBody(name));
|
|
868
|
+
}
|
|
869
|
+
// end `for` loop
|
|
870
|
+
endFor() {
|
|
871
|
+
return this._endBlockNode(For);
|
|
872
|
+
}
|
|
873
|
+
// `label` statement
|
|
874
|
+
label(label) {
|
|
875
|
+
return this._leafNode(new Label(label));
|
|
876
|
+
}
|
|
877
|
+
// `break` statement
|
|
878
|
+
break(label) {
|
|
879
|
+
return this._leafNode(new Break(label));
|
|
880
|
+
}
|
|
881
|
+
// `return` statement
|
|
882
|
+
return(value) {
|
|
883
|
+
const node = new Return();
|
|
884
|
+
this._blockNode(node);
|
|
885
|
+
this.code(value);
|
|
886
|
+
if (node.nodes.length !== 1)
|
|
887
|
+
throw new Error('CodeGen: "return" should have one node');
|
|
888
|
+
return this._endBlockNode(Return);
|
|
889
|
+
}
|
|
890
|
+
// `try` statement
|
|
891
|
+
try(tryBody, catchCode, finallyCode) {
|
|
892
|
+
if (!catchCode && !finallyCode)
|
|
893
|
+
throw new Error('CodeGen: "try" without "catch" and "finally"');
|
|
894
|
+
const node = new Try();
|
|
895
|
+
this._blockNode(node);
|
|
896
|
+
this.code(tryBody);
|
|
897
|
+
if (catchCode) {
|
|
898
|
+
const error2 = this.name("e");
|
|
899
|
+
this._currNode = node.catch = new Catch(error2);
|
|
900
|
+
catchCode(error2);
|
|
901
|
+
}
|
|
902
|
+
if (finallyCode) {
|
|
903
|
+
this._currNode = node.finally = new Finally();
|
|
904
|
+
this.code(finallyCode);
|
|
905
|
+
}
|
|
906
|
+
return this._endBlockNode(Catch, Finally);
|
|
907
|
+
}
|
|
908
|
+
// `throw` statement
|
|
909
|
+
throw(error2) {
|
|
910
|
+
return this._leafNode(new Throw(error2));
|
|
911
|
+
}
|
|
912
|
+
// start self-balancing block
|
|
913
|
+
block(body, nodeCount) {
|
|
914
|
+
this._blockStarts.push(this._nodes.length);
|
|
915
|
+
if (body)
|
|
916
|
+
this.code(body).endBlock(nodeCount);
|
|
917
|
+
return this;
|
|
918
|
+
}
|
|
919
|
+
// end the current self-balancing block
|
|
920
|
+
endBlock(nodeCount) {
|
|
921
|
+
const len = this._blockStarts.pop();
|
|
922
|
+
if (len === void 0)
|
|
923
|
+
throw new Error("CodeGen: not in self-balancing block");
|
|
924
|
+
const toClose = this._nodes.length - len;
|
|
925
|
+
if (toClose < 0 || nodeCount !== void 0 && toClose !== nodeCount) {
|
|
926
|
+
throw new Error(`CodeGen: wrong number of nodes: ${toClose} vs ${nodeCount} expected`);
|
|
927
|
+
}
|
|
928
|
+
this._nodes.length = len;
|
|
929
|
+
return this;
|
|
930
|
+
}
|
|
931
|
+
// `function` heading (or definition if funcBody is passed)
|
|
932
|
+
func(name, args = code_12.nil, async, funcBody) {
|
|
933
|
+
this._blockNode(new Func(name, args, async));
|
|
934
|
+
if (funcBody)
|
|
935
|
+
this.code(funcBody).endFunc();
|
|
936
|
+
return this;
|
|
937
|
+
}
|
|
938
|
+
// end function definition
|
|
939
|
+
endFunc() {
|
|
940
|
+
return this._endBlockNode(Func);
|
|
941
|
+
}
|
|
942
|
+
optimize(n = 1) {
|
|
943
|
+
while (n-- > 0) {
|
|
944
|
+
this._root.optimizeNodes();
|
|
945
|
+
this._root.optimizeNames(this._root.names, this._constants);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
_leafNode(node) {
|
|
949
|
+
this._currNode.nodes.push(node);
|
|
950
|
+
return this;
|
|
951
|
+
}
|
|
952
|
+
_blockNode(node) {
|
|
953
|
+
this._currNode.nodes.push(node);
|
|
954
|
+
this._nodes.push(node);
|
|
955
|
+
}
|
|
956
|
+
_endBlockNode(N1, N2) {
|
|
957
|
+
const n = this._currNode;
|
|
958
|
+
if (n instanceof N1 || N2 && n instanceof N2) {
|
|
959
|
+
this._nodes.pop();
|
|
960
|
+
return this;
|
|
961
|
+
}
|
|
962
|
+
throw new Error(`CodeGen: not in block "${N2 ? `${N1.kind}/${N2.kind}` : N1.kind}"`);
|
|
963
|
+
}
|
|
964
|
+
_elseNode(node) {
|
|
965
|
+
const n = this._currNode;
|
|
966
|
+
if (!(n instanceof If)) {
|
|
967
|
+
throw new Error('CodeGen: "else" without "if"');
|
|
968
|
+
}
|
|
969
|
+
this._currNode = n.else = node;
|
|
970
|
+
return this;
|
|
971
|
+
}
|
|
972
|
+
get _root() {
|
|
973
|
+
return this._nodes[0];
|
|
974
|
+
}
|
|
975
|
+
get _currNode() {
|
|
976
|
+
const ns = this._nodes;
|
|
977
|
+
return ns[ns.length - 1];
|
|
978
|
+
}
|
|
979
|
+
set _currNode(node) {
|
|
980
|
+
const ns = this._nodes;
|
|
981
|
+
ns[ns.length - 1] = node;
|
|
917
982
|
}
|
|
918
|
-
this._nodes.length = len;
|
|
919
|
-
return this;
|
|
920
|
-
}
|
|
921
|
-
// `function` heading (or definition if funcBody is passed)
|
|
922
|
-
func(name, args = code_12.nil, async, funcBody) {
|
|
923
|
-
this._blockNode(new Func(name, args, async));
|
|
924
|
-
if (funcBody)
|
|
925
|
-
this.code(funcBody).endFunc();
|
|
926
|
-
return this;
|
|
927
983
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
984
|
+
exports.CodeGen = CodeGen;
|
|
985
|
+
function addNames(names2, from) {
|
|
986
|
+
for (const n in from)
|
|
987
|
+
names2[n] = (names2[n] || 0) + (from[n] || 0);
|
|
988
|
+
return names2;
|
|
931
989
|
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
990
|
+
function addExprNames(names2, from) {
|
|
991
|
+
return from instanceof code_12._CodeOrName ? addNames(names2, from.names) : names2;
|
|
992
|
+
}
|
|
993
|
+
function optimizeExpr(expr, names2, constants) {
|
|
994
|
+
if (expr instanceof code_12.Name)
|
|
995
|
+
return replaceName(expr);
|
|
996
|
+
if (!canOptimize(expr))
|
|
997
|
+
return expr;
|
|
998
|
+
return new code_12._Code(expr._items.reduce((items2, c) => {
|
|
999
|
+
if (c instanceof code_12.Name)
|
|
1000
|
+
c = replaceName(c);
|
|
1001
|
+
if (c instanceof code_12._Code)
|
|
1002
|
+
items2.push(...c._items);
|
|
1003
|
+
else
|
|
1004
|
+
items2.push(c);
|
|
1005
|
+
return items2;
|
|
1006
|
+
}, []));
|
|
1007
|
+
function replaceName(n) {
|
|
1008
|
+
const c = constants[n.str];
|
|
1009
|
+
if (c === void 0 || names2[n.str] !== 1)
|
|
1010
|
+
return n;
|
|
1011
|
+
delete names2[n.str];
|
|
1012
|
+
return c;
|
|
1013
|
+
}
|
|
1014
|
+
function canOptimize(e) {
|
|
1015
|
+
return e instanceof code_12._Code && e._items.some((c) => c instanceof code_12.Name && names2[c.str] === 1 && constants[c.str] !== void 0);
|
|
936
1016
|
}
|
|
937
1017
|
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
1018
|
+
function subtractNames(names2, from) {
|
|
1019
|
+
for (const n in from)
|
|
1020
|
+
names2[n] = (names2[n] || 0) - (from[n] || 0);
|
|
941
1021
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
this._nodes.push(node);
|
|
1022
|
+
function not2(x) {
|
|
1023
|
+
return typeof x == "boolean" || typeof x == "number" || x === null ? !x : (0, code_12._)`!${par(x)}`;
|
|
945
1024
|
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
return this;
|
|
951
|
-
}
|
|
952
|
-
throw new Error(`CodeGen: not in block "${N2 ? `${N1.kind}/${N2.kind}` : N1.kind}"`);
|
|
1025
|
+
exports.not = not2;
|
|
1026
|
+
const andCode = mappend(exports.operators.AND);
|
|
1027
|
+
function and(...args) {
|
|
1028
|
+
return args.reduce(andCode);
|
|
953
1029
|
}
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
}
|
|
959
|
-
this._currNode = n.else = node;
|
|
960
|
-
return this;
|
|
1030
|
+
exports.and = and;
|
|
1031
|
+
const orCode = mappend(exports.operators.OR);
|
|
1032
|
+
function or(...args) {
|
|
1033
|
+
return args.reduce(orCode);
|
|
961
1034
|
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
get _currNode() {
|
|
966
|
-
const ns = this._nodes;
|
|
967
|
-
return ns[ns.length - 1];
|
|
968
|
-
}
|
|
969
|
-
set _currNode(node) {
|
|
970
|
-
const ns = this._nodes;
|
|
971
|
-
ns[ns.length - 1] = node;
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
exports.CodeGen = CodeGen;
|
|
975
|
-
function addNames(names2, from) {
|
|
976
|
-
for (const n in from)
|
|
977
|
-
names2[n] = (names2[n] || 0) + (from[n] || 0);
|
|
978
|
-
return names2;
|
|
979
|
-
}
|
|
980
|
-
function addExprNames(names2, from) {
|
|
981
|
-
return from instanceof code_12._CodeOrName ? addNames(names2, from.names) : names2;
|
|
982
|
-
}
|
|
983
|
-
function optimizeExpr(expr, names2, constants) {
|
|
984
|
-
if (expr instanceof code_12.Name)
|
|
985
|
-
return replaceName(expr);
|
|
986
|
-
if (!canOptimize(expr))
|
|
987
|
-
return expr;
|
|
988
|
-
return new code_12._Code(expr._items.reduce((items2, c) => {
|
|
989
|
-
if (c instanceof code_12.Name)
|
|
990
|
-
c = replaceName(c);
|
|
991
|
-
if (c instanceof code_12._Code)
|
|
992
|
-
items2.push(...c._items);
|
|
993
|
-
else
|
|
994
|
-
items2.push(c);
|
|
995
|
-
return items2;
|
|
996
|
-
}, []));
|
|
997
|
-
function replaceName(n) {
|
|
998
|
-
const c = constants[n.str];
|
|
999
|
-
if (c === void 0 || names2[n.str] !== 1)
|
|
1000
|
-
return n;
|
|
1001
|
-
delete names2[n.str];
|
|
1002
|
-
return c;
|
|
1035
|
+
exports.or = or;
|
|
1036
|
+
function mappend(op) {
|
|
1037
|
+
return (x, y) => x === code_12.nil ? y : y === code_12.nil ? x : (0, code_12._)`${par(x)} ${op} ${par(y)}`;
|
|
1003
1038
|
}
|
|
1004
|
-
function
|
|
1005
|
-
return
|
|
1039
|
+
function par(x) {
|
|
1040
|
+
return x instanceof code_12.Name ? x : (0, code_12._)`(${x})`;
|
|
1006
1041
|
}
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
names2[n] = (names2[n] || 0) - (from[n] || 0);
|
|
1011
|
-
}
|
|
1012
|
-
function not2(x) {
|
|
1013
|
-
return typeof x == "boolean" || typeof x == "number" || x === null ? !x : (0, code_12._)`!${par(x)}`;
|
|
1014
|
-
}
|
|
1015
|
-
exports.not = not2;
|
|
1016
|
-
const andCode = mappend(exports.operators.AND);
|
|
1017
|
-
function and(...args) {
|
|
1018
|
-
return args.reduce(andCode);
|
|
1019
|
-
}
|
|
1020
|
-
exports.and = and;
|
|
1021
|
-
const orCode = mappend(exports.operators.OR);
|
|
1022
|
-
function or(...args) {
|
|
1023
|
-
return args.reduce(orCode);
|
|
1024
|
-
}
|
|
1025
|
-
exports.or = or;
|
|
1026
|
-
function mappend(op) {
|
|
1027
|
-
return (x, y) => x === code_12.nil ? y : y === code_12.nil ? x : (0, code_12._)`${par(x)} ${op} ${par(y)}`;
|
|
1028
|
-
}
|
|
1029
|
-
function par(x) {
|
|
1030
|
-
return x instanceof code_12.Name ? x : (0, code_12._)`(${x})`;
|
|
1031
|
-
}
|
|
1032
|
-
})(codegen);
|
|
1042
|
+
})(codegen);
|
|
1043
|
+
return codegen;
|
|
1044
|
+
}
|
|
1033
1045
|
var util = {};
|
|
1034
1046
|
Object.defineProperty(util, "__esModule", { value: true });
|
|
1035
1047
|
util.checkStrictMode = util.getErrorPath = util.Type = util.useFunc = util.setEvaluated = util.evaluatedPropsToName = util.mergeEvaluated = util.eachItem = util.unescapeJsonPointer = util.escapeJsonPointer = util.escapeFragment = util.unescapeFragment = util.schemaRefOrVal = util.schemaHasRulesButRef = util.schemaHasRules = util.checkUnknownRules = util.alwaysValidSchema = util.toHash = void 0;
|
|
1036
|
-
const codegen_1$
|
|
1037
|
-
const code_1$
|
|
1048
|
+
const codegen_1$u = requireCodegen();
|
|
1049
|
+
const code_1$9 = code$1;
|
|
1038
1050
|
function toHash(arr) {
|
|
1039
1051
|
const hash = {};
|
|
1040
1052
|
for (const item of arr)
|
|
@@ -1087,9 +1099,9 @@ function schemaRefOrVal({ topSchemaRef, schemaPath }, schema, keyword2, $data) {
|
|
|
1087
1099
|
if (typeof schema == "number" || typeof schema == "boolean")
|
|
1088
1100
|
return schema;
|
|
1089
1101
|
if (typeof schema == "string")
|
|
1090
|
-
return (0, codegen_1$
|
|
1102
|
+
return (0, codegen_1$u._)`${schema}`;
|
|
1091
1103
|
}
|
|
1092
|
-
return (0, codegen_1$
|
|
1104
|
+
return (0, codegen_1$u._)`${topSchemaRef}${schemaPath}${(0, codegen_1$u.getProperty)(keyword2)}`;
|
|
1093
1105
|
}
|
|
1094
1106
|
util.schemaRefOrVal = schemaRefOrVal;
|
|
1095
1107
|
function unescapeFragment(str) {
|
|
@@ -1121,20 +1133,20 @@ function eachItem(xs, f) {
|
|
|
1121
1133
|
util.eachItem = eachItem;
|
|
1122
1134
|
function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues, resultToName }) {
|
|
1123
1135
|
return (gen, from, to, toName) => {
|
|
1124
|
-
const res = to === void 0 ? from : to instanceof codegen_1$
|
|
1125
|
-
return toName === codegen_1$
|
|
1136
|
+
const res = to === void 0 ? from : to instanceof codegen_1$u.Name ? (from instanceof codegen_1$u.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1$u.Name ? (mergeToName(gen, to, from), from) : mergeValues(from, to);
|
|
1137
|
+
return toName === codegen_1$u.Name && !(res instanceof codegen_1$u.Name) ? resultToName(gen, res) : res;
|
|
1126
1138
|
};
|
|
1127
1139
|
}
|
|
1128
1140
|
util.mergeEvaluated = {
|
|
1129
1141
|
props: makeMergeEvaluated({
|
|
1130
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
1131
|
-
gen.if((0, codegen_1$
|
|
1142
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$u._)`${to} !== true && ${from} !== undefined`, () => {
|
|
1143
|
+
gen.if((0, codegen_1$u._)`${from} === true`, () => gen.assign(to, true), () => gen.assign(to, (0, codegen_1$u._)`${to} || {}`).code((0, codegen_1$u._)`Object.assign(${to}, ${from})`));
|
|
1132
1144
|
}),
|
|
1133
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
1145
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$u._)`${to} !== true`, () => {
|
|
1134
1146
|
if (from === true) {
|
|
1135
1147
|
gen.assign(to, true);
|
|
1136
1148
|
} else {
|
|
1137
|
-
gen.assign(to, (0, codegen_1$
|
|
1149
|
+
gen.assign(to, (0, codegen_1$u._)`${to} || {}`);
|
|
1138
1150
|
setEvaluated(gen, to, from);
|
|
1139
1151
|
}
|
|
1140
1152
|
}),
|
|
@@ -1142,8 +1154,8 @@ util.mergeEvaluated = {
|
|
|
1142
1154
|
resultToName: evaluatedPropsToName
|
|
1143
1155
|
}),
|
|
1144
1156
|
items: makeMergeEvaluated({
|
|
1145
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
1146
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
1157
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$u._)`${to} !== true && ${from} !== undefined`, () => gen.assign(to, (0, codegen_1$u._)`${from} === true ? true : ${to} > ${from} ? ${to} : ${from}`)),
|
|
1158
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$u._)`${to} !== true`, () => gen.assign(to, from === true ? true : (0, codegen_1$u._)`${to} > ${from} ? ${to} : ${from}`)),
|
|
1147
1159
|
mergeValues: (from, to) => from === true ? true : Math.max(from, to),
|
|
1148
1160
|
resultToName: (gen, items2) => gen.var("items", items2)
|
|
1149
1161
|
})
|
|
@@ -1151,21 +1163,21 @@ util.mergeEvaluated = {
|
|
|
1151
1163
|
function evaluatedPropsToName(gen, ps) {
|
|
1152
1164
|
if (ps === true)
|
|
1153
1165
|
return gen.var("props", true);
|
|
1154
|
-
const props = gen.var("props", (0, codegen_1$
|
|
1166
|
+
const props = gen.var("props", (0, codegen_1$u._)`{}`);
|
|
1155
1167
|
if (ps !== void 0)
|
|
1156
1168
|
setEvaluated(gen, props, ps);
|
|
1157
1169
|
return props;
|
|
1158
1170
|
}
|
|
1159
1171
|
util.evaluatedPropsToName = evaluatedPropsToName;
|
|
1160
1172
|
function setEvaluated(gen, props, ps) {
|
|
1161
|
-
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$
|
|
1173
|
+
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$u._)`${props}${(0, codegen_1$u.getProperty)(p)}`, true));
|
|
1162
1174
|
}
|
|
1163
1175
|
util.setEvaluated = setEvaluated;
|
|
1164
1176
|
const snippets = {};
|
|
1165
1177
|
function useFunc(gen, f) {
|
|
1166
1178
|
return gen.scopeValue("func", {
|
|
1167
1179
|
ref: f,
|
|
1168
|
-
code: snippets[f.code] || (snippets[f.code] = new code_1$
|
|
1180
|
+
code: snippets[f.code] || (snippets[f.code] = new code_1$9._Code(f.code))
|
|
1169
1181
|
});
|
|
1170
1182
|
}
|
|
1171
1183
|
util.useFunc = useFunc;
|
|
@@ -1175,11 +1187,11 @@ var Type;
|
|
|
1175
1187
|
Type2[Type2["Str"] = 1] = "Str";
|
|
1176
1188
|
})(Type || (util.Type = Type = {}));
|
|
1177
1189
|
function getErrorPath(dataProp, dataPropType, jsPropertySyntax) {
|
|
1178
|
-
if (dataProp instanceof codegen_1$
|
|
1190
|
+
if (dataProp instanceof codegen_1$u.Name) {
|
|
1179
1191
|
const isNumber = dataPropType === Type.Num;
|
|
1180
|
-
return jsPropertySyntax ? isNumber ? (0, codegen_1$
|
|
1192
|
+
return jsPropertySyntax ? isNumber ? (0, codegen_1$u._)`"[" + ${dataProp} + "]"` : (0, codegen_1$u._)`"['" + ${dataProp} + "']"` : isNumber ? (0, codegen_1$u._)`"/" + ${dataProp}` : (0, codegen_1$u._)`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")`;
|
|
1181
1193
|
}
|
|
1182
|
-
return jsPropertySyntax ? (0, codegen_1$
|
|
1194
|
+
return jsPropertySyntax ? (0, codegen_1$u.getProperty)(dataProp).toString() : "/" + escapeJsonPointer(dataProp);
|
|
1183
1195
|
}
|
|
1184
1196
|
util.getErrorPath = getErrorPath;
|
|
1185
1197
|
function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
@@ -1193,41 +1205,41 @@ function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
|
1193
1205
|
util.checkStrictMode = checkStrictMode;
|
|
1194
1206
|
var names$1 = {};
|
|
1195
1207
|
Object.defineProperty(names$1, "__esModule", { value: true });
|
|
1196
|
-
const codegen_1$
|
|
1208
|
+
const codegen_1$t = requireCodegen();
|
|
1197
1209
|
const names = {
|
|
1198
1210
|
// validation function arguments
|
|
1199
|
-
data: new codegen_1$
|
|
1211
|
+
data: new codegen_1$t.Name("data"),
|
|
1200
1212
|
// data passed to validation function
|
|
1201
1213
|
// args passed from referencing schema
|
|
1202
|
-
valCxt: new codegen_1$
|
|
1214
|
+
valCxt: new codegen_1$t.Name("valCxt"),
|
|
1203
1215
|
// validation/data context - should not be used directly, it is destructured to the names below
|
|
1204
|
-
instancePath: new codegen_1$
|
|
1205
|
-
parentData: new codegen_1$
|
|
1206
|
-
parentDataProperty: new codegen_1$
|
|
1207
|
-
rootData: new codegen_1$
|
|
1216
|
+
instancePath: new codegen_1$t.Name("instancePath"),
|
|
1217
|
+
parentData: new codegen_1$t.Name("parentData"),
|
|
1218
|
+
parentDataProperty: new codegen_1$t.Name("parentDataProperty"),
|
|
1219
|
+
rootData: new codegen_1$t.Name("rootData"),
|
|
1208
1220
|
// root data - same as the data passed to the first/top validation function
|
|
1209
|
-
dynamicAnchors: new codegen_1$
|
|
1221
|
+
dynamicAnchors: new codegen_1$t.Name("dynamicAnchors"),
|
|
1210
1222
|
// used to support recursiveRef and dynamicRef
|
|
1211
1223
|
// function scoped variables
|
|
1212
|
-
vErrors: new codegen_1$
|
|
1224
|
+
vErrors: new codegen_1$t.Name("vErrors"),
|
|
1213
1225
|
// null or array of validation errors
|
|
1214
|
-
errors: new codegen_1$
|
|
1226
|
+
errors: new codegen_1$t.Name("errors"),
|
|
1215
1227
|
// counter of validation errors
|
|
1216
|
-
this: new codegen_1$
|
|
1228
|
+
this: new codegen_1$t.Name("this"),
|
|
1217
1229
|
// "globals"
|
|
1218
|
-
self: new codegen_1$
|
|
1219
|
-
scope: new codegen_1$
|
|
1230
|
+
self: new codegen_1$t.Name("self"),
|
|
1231
|
+
scope: new codegen_1$t.Name("scope"),
|
|
1220
1232
|
// JTD serialize/parse name for JSON string and position
|
|
1221
|
-
json: new codegen_1$
|
|
1222
|
-
jsonPos: new codegen_1$
|
|
1223
|
-
jsonLen: new codegen_1$
|
|
1224
|
-
jsonPart: new codegen_1$
|
|
1233
|
+
json: new codegen_1$t.Name("json"),
|
|
1234
|
+
jsonPos: new codegen_1$t.Name("jsonPos"),
|
|
1235
|
+
jsonLen: new codegen_1$t.Name("jsonLen"),
|
|
1236
|
+
jsonPart: new codegen_1$t.Name("jsonPart")
|
|
1225
1237
|
};
|
|
1226
1238
|
names$1.default = names;
|
|
1227
1239
|
(function(exports) {
|
|
1228
1240
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1229
1241
|
exports.extendErrors = exports.resetErrorsCount = exports.reportExtraError = exports.reportError = exports.keyword$DataError = exports.keywordError = void 0;
|
|
1230
|
-
const codegen_12 =
|
|
1242
|
+
const codegen_12 = requireCodegen();
|
|
1231
1243
|
const util_12 = util;
|
|
1232
1244
|
const names_12 = names$1;
|
|
1233
1245
|
exports.keywordError = {
|
|
@@ -1341,49 +1353,55 @@ names$1.default = names;
|
|
|
1341
1353
|
keyValues.push([E.propertyName, propertyName]);
|
|
1342
1354
|
}
|
|
1343
1355
|
})(errors);
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
const
|
|
1354
|
-
|
|
1355
|
-
falseSchemaError(it, false);
|
|
1356
|
-
} else if (typeof schema == "object" && schema.$async === true) {
|
|
1357
|
-
gen.return(names_1$9.default.data);
|
|
1358
|
-
} else {
|
|
1359
|
-
gen.assign((0, codegen_1$x._)`${validateName}.errors`, null);
|
|
1360
|
-
gen.return(true);
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
boolSchema.topBoolOrEmptySchema = topBoolOrEmptySchema;
|
|
1364
|
-
function boolOrEmptySchema(it, valid) {
|
|
1365
|
-
const { gen, schema } = it;
|
|
1366
|
-
if (schema === false) {
|
|
1367
|
-
gen.var(valid, false);
|
|
1368
|
-
falseSchemaError(it);
|
|
1369
|
-
} else {
|
|
1370
|
-
gen.var(valid, true);
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
boolSchema.boolOrEmptySchema = boolOrEmptySchema;
|
|
1374
|
-
function falseSchemaError(it, overrideAllErrors) {
|
|
1375
|
-
const { gen, data } = it;
|
|
1376
|
-
const cxt = {
|
|
1377
|
-
gen,
|
|
1378
|
-
keyword: "false schema",
|
|
1379
|
-
data,
|
|
1380
|
-
schema: false,
|
|
1381
|
-
schemaCode: false,
|
|
1382
|
-
schemaValue: false,
|
|
1383
|
-
params: {},
|
|
1384
|
-
it
|
|
1356
|
+
var hasRequiredBoolSchema;
|
|
1357
|
+
function requireBoolSchema() {
|
|
1358
|
+
if (hasRequiredBoolSchema) return boolSchema;
|
|
1359
|
+
hasRequiredBoolSchema = 1;
|
|
1360
|
+
Object.defineProperty(boolSchema, "__esModule", { value: true });
|
|
1361
|
+
boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
|
|
1362
|
+
const errors_12 = errors;
|
|
1363
|
+
const codegen_12 = requireCodegen();
|
|
1364
|
+
const names_12 = names$1;
|
|
1365
|
+
const boolError = {
|
|
1366
|
+
message: "boolean schema is false"
|
|
1385
1367
|
};
|
|
1386
|
-
(
|
|
1368
|
+
function topBoolOrEmptySchema(it) {
|
|
1369
|
+
const { gen, schema, validateName } = it;
|
|
1370
|
+
if (schema === false) {
|
|
1371
|
+
falseSchemaError(it, false);
|
|
1372
|
+
} else if (typeof schema == "object" && schema.$async === true) {
|
|
1373
|
+
gen.return(names_12.default.data);
|
|
1374
|
+
} else {
|
|
1375
|
+
gen.assign((0, codegen_12._)`${validateName}.errors`, null);
|
|
1376
|
+
gen.return(true);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
boolSchema.topBoolOrEmptySchema = topBoolOrEmptySchema;
|
|
1380
|
+
function boolOrEmptySchema(it, valid) {
|
|
1381
|
+
const { gen, schema } = it;
|
|
1382
|
+
if (schema === false) {
|
|
1383
|
+
gen.var(valid, false);
|
|
1384
|
+
falseSchemaError(it);
|
|
1385
|
+
} else {
|
|
1386
|
+
gen.var(valid, true);
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
boolSchema.boolOrEmptySchema = boolOrEmptySchema;
|
|
1390
|
+
function falseSchemaError(it, overrideAllErrors) {
|
|
1391
|
+
const { gen, data } = it;
|
|
1392
|
+
const cxt = {
|
|
1393
|
+
gen,
|
|
1394
|
+
keyword: "false schema",
|
|
1395
|
+
data,
|
|
1396
|
+
schema: false,
|
|
1397
|
+
schemaCode: false,
|
|
1398
|
+
schemaValue: false,
|
|
1399
|
+
params: {},
|
|
1400
|
+
it
|
|
1401
|
+
};
|
|
1402
|
+
(0, errors_12.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
1403
|
+
}
|
|
1404
|
+
return boolSchema;
|
|
1387
1405
|
}
|
|
1388
1406
|
var dataType = {};
|
|
1389
1407
|
var rules = {};
|
|
@@ -1431,10 +1449,10 @@ applicability.shouldUseRule = shouldUseRule;
|
|
|
1431
1449
|
Object.defineProperty(dataType, "__esModule", { value: true });
|
|
1432
1450
|
dataType.reportTypeError = dataType.checkDataTypes = dataType.checkDataType = dataType.coerceAndCheckDataType = dataType.getJSONTypes = dataType.getSchemaTypes = dataType.DataType = void 0;
|
|
1433
1451
|
const rules_1 = rules;
|
|
1434
|
-
const applicability_1
|
|
1435
|
-
const errors_1
|
|
1436
|
-
const codegen_1$
|
|
1437
|
-
const util_1$
|
|
1452
|
+
const applicability_1 = applicability;
|
|
1453
|
+
const errors_1 = errors;
|
|
1454
|
+
const codegen_1$s = requireCodegen();
|
|
1455
|
+
const util_1$r = util;
|
|
1438
1456
|
var DataType;
|
|
1439
1457
|
(function(DataType2) {
|
|
1440
1458
|
DataType2[DataType2["Correct"] = 0] = "Correct";
|
|
@@ -1466,7 +1484,7 @@ dataType.getJSONTypes = getJSONTypes;
|
|
|
1466
1484
|
function coerceAndCheckDataType(it, types2) {
|
|
1467
1485
|
const { gen, data, opts } = it;
|
|
1468
1486
|
const coerceTo = coerceToTypes(types2, opts.coerceTypes);
|
|
1469
|
-
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1
|
|
1487
|
+
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1.schemaHasRulesForType)(it, types2[0]));
|
|
1470
1488
|
if (checkTypes) {
|
|
1471
1489
|
const wrongType = checkDataTypes(types2, data, opts.strictNumbers, DataType.Wrong);
|
|
1472
1490
|
gen.if(wrongType, () => {
|
|
@@ -1485,12 +1503,12 @@ function coerceToTypes(types2, coerceTypes) {
|
|
|
1485
1503
|
}
|
|
1486
1504
|
function coerceData(it, types2, coerceTo) {
|
|
1487
1505
|
const { gen, data, opts } = it;
|
|
1488
|
-
const dataType2 = gen.let("dataType", (0, codegen_1$
|
|
1489
|
-
const coerced = gen.let("coerced", (0, codegen_1$
|
|
1506
|
+
const dataType2 = gen.let("dataType", (0, codegen_1$s._)`typeof ${data}`);
|
|
1507
|
+
const coerced = gen.let("coerced", (0, codegen_1$s._)`undefined`);
|
|
1490
1508
|
if (opts.coerceTypes === "array") {
|
|
1491
|
-
gen.if((0, codegen_1$
|
|
1509
|
+
gen.if((0, codegen_1$s._)`${dataType2} == 'object' && Array.isArray(${data}) && ${data}.length == 1`, () => gen.assign(data, (0, codegen_1$s._)`${data}[0]`).assign(dataType2, (0, codegen_1$s._)`typeof ${data}`).if(checkDataTypes(types2, data, opts.strictNumbers), () => gen.assign(coerced, data)));
|
|
1492
1510
|
}
|
|
1493
|
-
gen.if((0, codegen_1$
|
|
1511
|
+
gen.if((0, codegen_1$s._)`${coerced} !== undefined`);
|
|
1494
1512
|
for (const t of coerceTo) {
|
|
1495
1513
|
if (COERCIBLE.has(t) || t === "array" && opts.coerceTypes === "array") {
|
|
1496
1514
|
coerceSpecificType(t);
|
|
@@ -1499,63 +1517,63 @@ function coerceData(it, types2, coerceTo) {
|
|
|
1499
1517
|
gen.else();
|
|
1500
1518
|
reportTypeError(it);
|
|
1501
1519
|
gen.endIf();
|
|
1502
|
-
gen.if((0, codegen_1$
|
|
1520
|
+
gen.if((0, codegen_1$s._)`${coerced} !== undefined`, () => {
|
|
1503
1521
|
gen.assign(data, coerced);
|
|
1504
1522
|
assignParentData(it, coerced);
|
|
1505
1523
|
});
|
|
1506
1524
|
function coerceSpecificType(t) {
|
|
1507
1525
|
switch (t) {
|
|
1508
1526
|
case "string":
|
|
1509
|
-
gen.elseIf((0, codegen_1$
|
|
1527
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} == "number" || ${dataType2} == "boolean"`).assign(coerced, (0, codegen_1$s._)`"" + ${data}`).elseIf((0, codegen_1$s._)`${data} === null`).assign(coerced, (0, codegen_1$s._)`""`);
|
|
1510
1528
|
return;
|
|
1511
1529
|
case "number":
|
|
1512
|
-
gen.elseIf((0, codegen_1$
|
|
1513
|
-
|| (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$
|
|
1530
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} == "boolean" || ${data} === null
|
|
1531
|
+
|| (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$s._)`+${data}`);
|
|
1514
1532
|
return;
|
|
1515
1533
|
case "integer":
|
|
1516
|
-
gen.elseIf((0, codegen_1$
|
|
1517
|
-
|| (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$
|
|
1534
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} === "boolean" || ${data} === null
|
|
1535
|
+
|| (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$s._)`+${data}`);
|
|
1518
1536
|
return;
|
|
1519
1537
|
case "boolean":
|
|
1520
|
-
gen.elseIf((0, codegen_1$
|
|
1538
|
+
gen.elseIf((0, codegen_1$s._)`${data} === "false" || ${data} === 0 || ${data} === null`).assign(coerced, false).elseIf((0, codegen_1$s._)`${data} === "true" || ${data} === 1`).assign(coerced, true);
|
|
1521
1539
|
return;
|
|
1522
1540
|
case "null":
|
|
1523
|
-
gen.elseIf((0, codegen_1$
|
|
1541
|
+
gen.elseIf((0, codegen_1$s._)`${data} === "" || ${data} === 0 || ${data} === false`);
|
|
1524
1542
|
gen.assign(coerced, null);
|
|
1525
1543
|
return;
|
|
1526
1544
|
case "array":
|
|
1527
|
-
gen.elseIf((0, codegen_1$
|
|
1528
|
-
|| ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$
|
|
1545
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} === "string" || ${dataType2} === "number"
|
|
1546
|
+
|| ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$s._)`[${data}]`);
|
|
1529
1547
|
}
|
|
1530
1548
|
}
|
|
1531
1549
|
}
|
|
1532
1550
|
function assignParentData({ gen, parentData, parentDataProperty }, expr) {
|
|
1533
|
-
gen.if((0, codegen_1$
|
|
1551
|
+
gen.if((0, codegen_1$s._)`${parentData} !== undefined`, () => gen.assign((0, codegen_1$s._)`${parentData}[${parentDataProperty}]`, expr));
|
|
1534
1552
|
}
|
|
1535
1553
|
function checkDataType(dataType2, data, strictNums, correct = DataType.Correct) {
|
|
1536
|
-
const EQ = correct === DataType.Correct ? codegen_1$
|
|
1554
|
+
const EQ = correct === DataType.Correct ? codegen_1$s.operators.EQ : codegen_1$s.operators.NEQ;
|
|
1537
1555
|
let cond;
|
|
1538
1556
|
switch (dataType2) {
|
|
1539
1557
|
case "null":
|
|
1540
|
-
return (0, codegen_1$
|
|
1558
|
+
return (0, codegen_1$s._)`${data} ${EQ} null`;
|
|
1541
1559
|
case "array":
|
|
1542
|
-
cond = (0, codegen_1$
|
|
1560
|
+
cond = (0, codegen_1$s._)`Array.isArray(${data})`;
|
|
1543
1561
|
break;
|
|
1544
1562
|
case "object":
|
|
1545
|
-
cond = (0, codegen_1$
|
|
1563
|
+
cond = (0, codegen_1$s._)`${data} && typeof ${data} == "object" && !Array.isArray(${data})`;
|
|
1546
1564
|
break;
|
|
1547
1565
|
case "integer":
|
|
1548
|
-
cond = numCond((0, codegen_1$
|
|
1566
|
+
cond = numCond((0, codegen_1$s._)`!(${data} % 1) && !isNaN(${data})`);
|
|
1549
1567
|
break;
|
|
1550
1568
|
case "number":
|
|
1551
1569
|
cond = numCond();
|
|
1552
1570
|
break;
|
|
1553
1571
|
default:
|
|
1554
|
-
return (0, codegen_1$
|
|
1572
|
+
return (0, codegen_1$s._)`typeof ${data} ${EQ} ${dataType2}`;
|
|
1555
1573
|
}
|
|
1556
|
-
return correct === DataType.Correct ? cond : (0, codegen_1$
|
|
1557
|
-
function numCond(_cond = codegen_1$
|
|
1558
|
-
return (0, codegen_1$
|
|
1574
|
+
return correct === DataType.Correct ? cond : (0, codegen_1$s.not)(cond);
|
|
1575
|
+
function numCond(_cond = codegen_1$s.nil) {
|
|
1576
|
+
return (0, codegen_1$s.and)((0, codegen_1$s._)`typeof ${data} == "number"`, _cond, strictNums ? (0, codegen_1$s._)`isFinite(${data})` : codegen_1$s.nil);
|
|
1559
1577
|
}
|
|
1560
1578
|
}
|
|
1561
1579
|
dataType.checkDataType = checkDataType;
|
|
@@ -1564,35 +1582,35 @@ function checkDataTypes(dataTypes, data, strictNums, correct) {
|
|
|
1564
1582
|
return checkDataType(dataTypes[0], data, strictNums, correct);
|
|
1565
1583
|
}
|
|
1566
1584
|
let cond;
|
|
1567
|
-
const types2 = (0, util_1$
|
|
1585
|
+
const types2 = (0, util_1$r.toHash)(dataTypes);
|
|
1568
1586
|
if (types2.array && types2.object) {
|
|
1569
|
-
const notObj = (0, codegen_1$
|
|
1570
|
-
cond = types2.null ? notObj : (0, codegen_1$
|
|
1587
|
+
const notObj = (0, codegen_1$s._)`typeof ${data} != "object"`;
|
|
1588
|
+
cond = types2.null ? notObj : (0, codegen_1$s._)`!${data} || ${notObj}`;
|
|
1571
1589
|
delete types2.null;
|
|
1572
1590
|
delete types2.array;
|
|
1573
1591
|
delete types2.object;
|
|
1574
1592
|
} else {
|
|
1575
|
-
cond = codegen_1$
|
|
1593
|
+
cond = codegen_1$s.nil;
|
|
1576
1594
|
}
|
|
1577
1595
|
if (types2.number)
|
|
1578
1596
|
delete types2.integer;
|
|
1579
1597
|
for (const t in types2)
|
|
1580
|
-
cond = (0, codegen_1$
|
|
1598
|
+
cond = (0, codegen_1$s.and)(cond, checkDataType(t, data, strictNums, correct));
|
|
1581
1599
|
return cond;
|
|
1582
1600
|
}
|
|
1583
1601
|
dataType.checkDataTypes = checkDataTypes;
|
|
1584
1602
|
const typeError = {
|
|
1585
1603
|
message: ({ schema }) => `must be ${schema}`,
|
|
1586
|
-
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$
|
|
1604
|
+
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$s._)`{type: ${schema}}` : (0, codegen_1$s._)`{type: ${schemaValue}}`
|
|
1587
1605
|
};
|
|
1588
1606
|
function reportTypeError(it) {
|
|
1589
1607
|
const cxt = getTypeErrorContext(it);
|
|
1590
|
-
(0, errors_1
|
|
1608
|
+
(0, errors_1.reportError)(cxt, typeError);
|
|
1591
1609
|
}
|
|
1592
1610
|
dataType.reportTypeError = reportTypeError;
|
|
1593
1611
|
function getTypeErrorContext(it) {
|
|
1594
1612
|
const { gen, data, schema } = it;
|
|
1595
|
-
const schemaCode = (0, util_1$
|
|
1613
|
+
const schemaCode = (0, util_1$r.schemaRefOrVal)(it, schema, "type");
|
|
1596
1614
|
return {
|
|
1597
1615
|
gen,
|
|
1598
1616
|
keyword: "type",
|
|
@@ -1606,54 +1624,60 @@ function getTypeErrorContext(it) {
|
|
|
1606
1624
|
};
|
|
1607
1625
|
}
|
|
1608
1626
|
var defaults = {};
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
}
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
if (defaultValue === void 0)
|
|
1627
|
-
return;
|
|
1628
|
-
const childData = (0, codegen_1$v._)`${data}${(0, codegen_1$v.getProperty)(prop)}`;
|
|
1629
|
-
if (compositeRule) {
|
|
1630
|
-
(0, util_1$t.checkStrictMode)(it, `default is ignored for: ${childData}`);
|
|
1631
|
-
return;
|
|
1627
|
+
var hasRequiredDefaults;
|
|
1628
|
+
function requireDefaults() {
|
|
1629
|
+
if (hasRequiredDefaults) return defaults;
|
|
1630
|
+
hasRequiredDefaults = 1;
|
|
1631
|
+
Object.defineProperty(defaults, "__esModule", { value: true });
|
|
1632
|
+
defaults.assignDefaults = void 0;
|
|
1633
|
+
const codegen_12 = requireCodegen();
|
|
1634
|
+
const util_12 = util;
|
|
1635
|
+
function assignDefaults(it, ty) {
|
|
1636
|
+
const { properties: properties2, items: items2 } = it.schema;
|
|
1637
|
+
if (ty === "object" && properties2) {
|
|
1638
|
+
for (const key in properties2) {
|
|
1639
|
+
assignDefault(it, key, properties2[key].default);
|
|
1640
|
+
}
|
|
1641
|
+
} else if (ty === "array" && Array.isArray(items2)) {
|
|
1642
|
+
items2.forEach((sch, i) => assignDefault(it, i, sch.default));
|
|
1643
|
+
}
|
|
1632
1644
|
}
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1645
|
+
defaults.assignDefaults = assignDefaults;
|
|
1646
|
+
function assignDefault(it, prop, defaultValue) {
|
|
1647
|
+
const { gen, compositeRule, data, opts } = it;
|
|
1648
|
+
if (defaultValue === void 0)
|
|
1649
|
+
return;
|
|
1650
|
+
const childData = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)(prop)}`;
|
|
1651
|
+
if (compositeRule) {
|
|
1652
|
+
(0, util_12.checkStrictMode)(it, `default is ignored for: ${childData}`);
|
|
1653
|
+
return;
|
|
1654
|
+
}
|
|
1655
|
+
let condition = (0, codegen_12._)`${childData} === undefined`;
|
|
1656
|
+
if (opts.useDefaults === "empty") {
|
|
1657
|
+
condition = (0, codegen_12._)`${condition} || ${childData} === null || ${childData} === ""`;
|
|
1658
|
+
}
|
|
1659
|
+
gen.if(condition, (0, codegen_12._)`${childData} = ${(0, codegen_12.stringify)(defaultValue)}`);
|
|
1636
1660
|
}
|
|
1637
|
-
|
|
1661
|
+
return defaults;
|
|
1638
1662
|
}
|
|
1639
1663
|
var keyword = {};
|
|
1640
1664
|
var code = {};
|
|
1641
1665
|
Object.defineProperty(code, "__esModule", { value: true });
|
|
1642
1666
|
code.validateUnion = code.validateArray = code.usePattern = code.callValidateCode = code.schemaProperties = code.allSchemaProperties = code.noPropertyInData = code.propertyInData = code.isOwnProperty = code.hasPropFunc = code.reportMissingProp = code.checkMissingProp = code.checkReportMissingProp = void 0;
|
|
1643
|
-
const codegen_1$
|
|
1644
|
-
const util_1$
|
|
1645
|
-
const names_1$
|
|
1667
|
+
const codegen_1$r = requireCodegen();
|
|
1668
|
+
const util_1$q = util;
|
|
1669
|
+
const names_1$6 = names$1;
|
|
1646
1670
|
const util_2$1 = util;
|
|
1647
1671
|
function checkReportMissingProp(cxt, prop) {
|
|
1648
1672
|
const { gen, data, it } = cxt;
|
|
1649
1673
|
gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
|
|
1650
|
-
cxt.setParams({ missingProperty: (0, codegen_1$
|
|
1674
|
+
cxt.setParams({ missingProperty: (0, codegen_1$r._)`${prop}` }, true);
|
|
1651
1675
|
cxt.error();
|
|
1652
1676
|
});
|
|
1653
1677
|
}
|
|
1654
1678
|
code.checkReportMissingProp = checkReportMissingProp;
|
|
1655
1679
|
function checkMissingProp({ gen, data, it: { opts } }, properties2, missing) {
|
|
1656
|
-
return (0, codegen_1$
|
|
1680
|
+
return (0, codegen_1$r.or)(...properties2.map((prop) => (0, codegen_1$r.and)(noPropertyInData(gen, data, prop, opts.ownProperties), (0, codegen_1$r._)`${missing} = ${prop}`)));
|
|
1657
1681
|
}
|
|
1658
1682
|
code.checkMissingProp = checkMissingProp;
|
|
1659
1683
|
function reportMissingProp(cxt, missing) {
|
|
@@ -1665,22 +1689,22 @@ function hasPropFunc(gen) {
|
|
|
1665
1689
|
return gen.scopeValue("func", {
|
|
1666
1690
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
1667
1691
|
ref: Object.prototype.hasOwnProperty,
|
|
1668
|
-
code: (0, codegen_1$
|
|
1692
|
+
code: (0, codegen_1$r._)`Object.prototype.hasOwnProperty`
|
|
1669
1693
|
});
|
|
1670
1694
|
}
|
|
1671
1695
|
code.hasPropFunc = hasPropFunc;
|
|
1672
1696
|
function isOwnProperty(gen, data, property) {
|
|
1673
|
-
return (0, codegen_1$
|
|
1697
|
+
return (0, codegen_1$r._)`${hasPropFunc(gen)}.call(${data}, ${property})`;
|
|
1674
1698
|
}
|
|
1675
1699
|
code.isOwnProperty = isOwnProperty;
|
|
1676
1700
|
function propertyInData(gen, data, property, ownProperties) {
|
|
1677
|
-
const cond = (0, codegen_1$
|
|
1678
|
-
return ownProperties ? (0, codegen_1$
|
|
1701
|
+
const cond = (0, codegen_1$r._)`${data}${(0, codegen_1$r.getProperty)(property)} !== undefined`;
|
|
1702
|
+
return ownProperties ? (0, codegen_1$r._)`${cond} && ${isOwnProperty(gen, data, property)}` : cond;
|
|
1679
1703
|
}
|
|
1680
1704
|
code.propertyInData = propertyInData;
|
|
1681
1705
|
function noPropertyInData(gen, data, property, ownProperties) {
|
|
1682
|
-
const cond = (0, codegen_1$
|
|
1683
|
-
return ownProperties ? (0, codegen_1$
|
|
1706
|
+
const cond = (0, codegen_1$r._)`${data}${(0, codegen_1$r.getProperty)(property)} === undefined`;
|
|
1707
|
+
return ownProperties ? (0, codegen_1$r.or)(cond, (0, codegen_1$r.not)(isOwnProperty(gen, data, property))) : cond;
|
|
1684
1708
|
}
|
|
1685
1709
|
code.noPropertyInData = noPropertyInData;
|
|
1686
1710
|
function allSchemaProperties(schemaMap) {
|
|
@@ -1688,24 +1712,24 @@ function allSchemaProperties(schemaMap) {
|
|
|
1688
1712
|
}
|
|
1689
1713
|
code.allSchemaProperties = allSchemaProperties;
|
|
1690
1714
|
function schemaProperties(it, schemaMap) {
|
|
1691
|
-
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$
|
|
1715
|
+
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$q.alwaysValidSchema)(it, schemaMap[p]));
|
|
1692
1716
|
}
|
|
1693
1717
|
code.schemaProperties = schemaProperties;
|
|
1694
1718
|
function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context, passSchema) {
|
|
1695
|
-
const dataAndSchema = passSchema ? (0, codegen_1$
|
|
1719
|
+
const dataAndSchema = passSchema ? (0, codegen_1$r._)`${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
|
|
1696
1720
|
const valCxt = [
|
|
1697
|
-
[names_1$
|
|
1698
|
-
[names_1$
|
|
1699
|
-
[names_1$
|
|
1700
|
-
[names_1$
|
|
1721
|
+
[names_1$6.default.instancePath, (0, codegen_1$r.strConcat)(names_1$6.default.instancePath, errorPath)],
|
|
1722
|
+
[names_1$6.default.parentData, it.parentData],
|
|
1723
|
+
[names_1$6.default.parentDataProperty, it.parentDataProperty],
|
|
1724
|
+
[names_1$6.default.rootData, names_1$6.default.rootData]
|
|
1701
1725
|
];
|
|
1702
1726
|
if (it.opts.dynamicRef)
|
|
1703
|
-
valCxt.push([names_1$
|
|
1704
|
-
const args = (0, codegen_1$
|
|
1705
|
-
return context !== codegen_1$
|
|
1727
|
+
valCxt.push([names_1$6.default.dynamicAnchors, names_1$6.default.dynamicAnchors]);
|
|
1728
|
+
const args = (0, codegen_1$r._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
|
|
1729
|
+
return context !== codegen_1$r.nil ? (0, codegen_1$r._)`${func}.call(${context}, ${args})` : (0, codegen_1$r._)`${func}(${args})`;
|
|
1706
1730
|
}
|
|
1707
1731
|
code.callValidateCode = callValidateCode;
|
|
1708
|
-
const newRegExp = (0, codegen_1$
|
|
1732
|
+
const newRegExp = (0, codegen_1$r._)`new RegExp`;
|
|
1709
1733
|
function usePattern({ gen, it: { opts } }, pattern2) {
|
|
1710
1734
|
const u = opts.unicodeRegExp ? "u" : "";
|
|
1711
1735
|
const { regExp } = opts.code;
|
|
@@ -1713,7 +1737,7 @@ function usePattern({ gen, it: { opts } }, pattern2) {
|
|
|
1713
1737
|
return gen.scopeValue("pattern", {
|
|
1714
1738
|
key: rx.toString(),
|
|
1715
1739
|
ref: rx,
|
|
1716
|
-
code: (0, codegen_1$
|
|
1740
|
+
code: (0, codegen_1$r._)`${regExp.code === "new RegExp" ? newRegExp : (0, util_2$1.useFunc)(gen, regExp)}(${pattern2}, ${u})`
|
|
1717
1741
|
});
|
|
1718
1742
|
}
|
|
1719
1743
|
code.usePattern = usePattern;
|
|
@@ -1729,14 +1753,14 @@ function validateArray(cxt) {
|
|
|
1729
1753
|
validateItems(() => gen.break());
|
|
1730
1754
|
return valid;
|
|
1731
1755
|
function validateItems(notValid) {
|
|
1732
|
-
const len = gen.const("len", (0, codegen_1$
|
|
1756
|
+
const len = gen.const("len", (0, codegen_1$r._)`${data}.length`);
|
|
1733
1757
|
gen.forRange("i", 0, len, (i) => {
|
|
1734
1758
|
cxt.subschema({
|
|
1735
1759
|
keyword: keyword2,
|
|
1736
1760
|
dataProp: i,
|
|
1737
|
-
dataPropType: util_1$
|
|
1761
|
+
dataPropType: util_1$q.Type.Num
|
|
1738
1762
|
}, valid);
|
|
1739
|
-
gen.if((0, codegen_1$
|
|
1763
|
+
gen.if((0, codegen_1$r.not)(valid), notValid);
|
|
1740
1764
|
});
|
|
1741
1765
|
}
|
|
1742
1766
|
}
|
|
@@ -1745,7 +1769,7 @@ function validateUnion(cxt) {
|
|
|
1745
1769
|
const { gen, schema, keyword: keyword2, it } = cxt;
|
|
1746
1770
|
if (!Array.isArray(schema))
|
|
1747
1771
|
throw new Error("ajv implementation error");
|
|
1748
|
-
const alwaysValid = schema.some((sch) => (0, util_1$
|
|
1772
|
+
const alwaysValid = schema.some((sch) => (0, util_1$q.alwaysValidSchema)(it, sch));
|
|
1749
1773
|
if (alwaysValid && !it.opts.unevaluated)
|
|
1750
1774
|
return;
|
|
1751
1775
|
const valid = gen.let("valid", false);
|
|
@@ -1756,202 +1780,214 @@ function validateUnion(cxt) {
|
|
|
1756
1780
|
schemaProp: i,
|
|
1757
1781
|
compositeRule: true
|
|
1758
1782
|
}, schValid);
|
|
1759
|
-
gen.assign(valid, (0, codegen_1$
|
|
1783
|
+
gen.assign(valid, (0, codegen_1$r._)`${valid} || ${schValid}`);
|
|
1760
1784
|
const merged = cxt.mergeValidEvaluated(schCxt, schValid);
|
|
1761
1785
|
if (!merged)
|
|
1762
|
-
gen.if((0, codegen_1$
|
|
1786
|
+
gen.if((0, codegen_1$r.not)(valid));
|
|
1763
1787
|
}));
|
|
1764
1788
|
cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
|
|
1765
1789
|
}
|
|
1766
1790
|
code.validateUnion = validateUnion;
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
const
|
|
1775
|
-
const
|
|
1776
|
-
const
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
|
|
1793
|
-
checkAsyncKeyword(it, def2);
|
|
1794
|
-
const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
|
|
1795
|
-
const validateRef = useKeyword(gen, keyword2, validate2);
|
|
1796
|
-
const valid = gen.let("valid");
|
|
1797
|
-
cxt.block$data(valid, validateKeyword);
|
|
1798
|
-
cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
|
|
1799
|
-
function validateKeyword() {
|
|
1800
|
-
if (def2.errors === false) {
|
|
1801
|
-
assignValid();
|
|
1802
|
-
if (def2.modifying)
|
|
1803
|
-
modifyData(cxt);
|
|
1804
|
-
reportErrs(() => cxt.error());
|
|
1805
|
-
} else {
|
|
1806
|
-
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
1807
|
-
if (def2.modifying)
|
|
1808
|
-
modifyData(cxt);
|
|
1809
|
-
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1812
|
-
function validateAsync() {
|
|
1813
|
-
const ruleErrs = gen.let("ruleErrs", null);
|
|
1814
|
-
gen.try(() => assignValid((0, codegen_1$t._)`await `), (e) => gen.assign(valid, false).if((0, codegen_1$t._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1$t._)`${e}.errors`), () => gen.throw(e)));
|
|
1815
|
-
return ruleErrs;
|
|
1816
|
-
}
|
|
1817
|
-
function validateSync() {
|
|
1818
|
-
const validateErrs = (0, codegen_1$t._)`${validateRef}.errors`;
|
|
1819
|
-
gen.assign(validateErrs, null);
|
|
1820
|
-
assignValid(codegen_1$t.nil);
|
|
1821
|
-
return validateErrs;
|
|
1822
|
-
}
|
|
1823
|
-
function assignValid(_await = def2.async ? (0, codegen_1$t._)`await ` : codegen_1$t.nil) {
|
|
1824
|
-
const passCxt = it.opts.passContext ? names_1$7.default.this : names_1$7.default.self;
|
|
1825
|
-
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
1826
|
-
gen.assign(valid, (0, codegen_1$t._)`${_await}${(0, code_1$9.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
1827
|
-
}
|
|
1828
|
-
function reportErrs(errors2) {
|
|
1829
|
-
var _a2;
|
|
1830
|
-
gen.if((0, codegen_1$t.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
keyword.funcKeywordCode = funcKeywordCode;
|
|
1834
|
-
function modifyData(cxt) {
|
|
1835
|
-
const { gen, data, it } = cxt;
|
|
1836
|
-
gen.if(it.parentData, () => gen.assign(data, (0, codegen_1$t._)`${it.parentData}[${it.parentDataProperty}]`));
|
|
1837
|
-
}
|
|
1838
|
-
function addErrs(cxt, errs) {
|
|
1839
|
-
const { gen } = cxt;
|
|
1840
|
-
gen.if((0, codegen_1$t._)`Array.isArray(${errs})`, () => {
|
|
1841
|
-
gen.assign(names_1$7.default.vErrors, (0, codegen_1$t._)`${names_1$7.default.vErrors} === null ? ${errs} : ${names_1$7.default.vErrors}.concat(${errs})`).assign(names_1$7.default.errors, (0, codegen_1$t._)`${names_1$7.default.vErrors}.length`);
|
|
1842
|
-
(0, errors_1$1.extendErrors)(cxt);
|
|
1843
|
-
}, () => cxt.error());
|
|
1844
|
-
}
|
|
1845
|
-
function checkAsyncKeyword({ schemaEnv }, def2) {
|
|
1846
|
-
if (def2.async && !schemaEnv.$async)
|
|
1847
|
-
throw new Error("async keyword in sync schema");
|
|
1848
|
-
}
|
|
1849
|
-
function useKeyword(gen, keyword2, result) {
|
|
1850
|
-
if (result === void 0)
|
|
1851
|
-
throw new Error(`keyword "${keyword2}" failed to compile`);
|
|
1852
|
-
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_1$t.stringify)(result) });
|
|
1853
|
-
}
|
|
1854
|
-
function validSchemaType(schema, schemaType, allowUndefined = false) {
|
|
1855
|
-
return !schemaType.length || schemaType.some((st) => st === "array" ? Array.isArray(schema) : st === "object" ? schema && typeof schema == "object" && !Array.isArray(schema) : typeof schema == st || allowUndefined && typeof schema == "undefined");
|
|
1856
|
-
}
|
|
1857
|
-
keyword.validSchemaType = validSchemaType;
|
|
1858
|
-
function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def2, keyword2) {
|
|
1859
|
-
if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
|
|
1860
|
-
throw new Error("ajv implementation error");
|
|
1791
|
+
var hasRequiredKeyword;
|
|
1792
|
+
function requireKeyword() {
|
|
1793
|
+
if (hasRequiredKeyword) return keyword;
|
|
1794
|
+
hasRequiredKeyword = 1;
|
|
1795
|
+
Object.defineProperty(keyword, "__esModule", { value: true });
|
|
1796
|
+
keyword.validateKeywordUsage = keyword.validSchemaType = keyword.funcKeywordCode = keyword.macroKeywordCode = void 0;
|
|
1797
|
+
const codegen_12 = requireCodegen();
|
|
1798
|
+
const names_12 = names$1;
|
|
1799
|
+
const code_12 = code;
|
|
1800
|
+
const errors_12 = errors;
|
|
1801
|
+
function macroKeywordCode(cxt, def2) {
|
|
1802
|
+
const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
|
|
1803
|
+
const macroSchema = def2.macro.call(it.self, schema, parentSchema, it);
|
|
1804
|
+
const schemaRef = useKeyword(gen, keyword2, macroSchema);
|
|
1805
|
+
if (it.opts.validateSchema !== false)
|
|
1806
|
+
it.self.validateSchema(macroSchema, true);
|
|
1807
|
+
const valid = gen.name("valid");
|
|
1808
|
+
cxt.subschema({
|
|
1809
|
+
schema: macroSchema,
|
|
1810
|
+
schemaPath: codegen_12.nil,
|
|
1811
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`,
|
|
1812
|
+
topSchemaRef: schemaRef,
|
|
1813
|
+
compositeRule: true
|
|
1814
|
+
}, valid);
|
|
1815
|
+
cxt.pass(valid, () => cxt.error(true));
|
|
1861
1816
|
}
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1817
|
+
keyword.macroKeywordCode = macroKeywordCode;
|
|
1818
|
+
function funcKeywordCode(cxt, def2) {
|
|
1819
|
+
var _a;
|
|
1820
|
+
const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
|
|
1821
|
+
checkAsyncKeyword(it, def2);
|
|
1822
|
+
const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
|
|
1823
|
+
const validateRef = useKeyword(gen, keyword2, validate2);
|
|
1824
|
+
const valid = gen.let("valid");
|
|
1825
|
+
cxt.block$data(valid, validateKeyword);
|
|
1826
|
+
cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
|
|
1827
|
+
function validateKeyword() {
|
|
1828
|
+
if (def2.errors === false) {
|
|
1829
|
+
assignValid();
|
|
1830
|
+
if (def2.modifying)
|
|
1831
|
+
modifyData(cxt);
|
|
1832
|
+
reportErrs(() => cxt.error());
|
|
1833
|
+
} else {
|
|
1834
|
+
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
1835
|
+
if (def2.modifying)
|
|
1836
|
+
modifyData(cxt);
|
|
1837
|
+
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
function validateAsync() {
|
|
1841
|
+
const ruleErrs = gen.let("ruleErrs", null);
|
|
1842
|
+
gen.try(() => assignValid((0, codegen_12._)`await `), (e) => gen.assign(valid, false).if((0, codegen_12._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_12._)`${e}.errors`), () => gen.throw(e)));
|
|
1843
|
+
return ruleErrs;
|
|
1844
|
+
}
|
|
1845
|
+
function validateSync() {
|
|
1846
|
+
const validateErrs = (0, codegen_12._)`${validateRef}.errors`;
|
|
1847
|
+
gen.assign(validateErrs, null);
|
|
1848
|
+
assignValid(codegen_12.nil);
|
|
1849
|
+
return validateErrs;
|
|
1850
|
+
}
|
|
1851
|
+
function assignValid(_await = def2.async ? (0, codegen_12._)`await ` : codegen_12.nil) {
|
|
1852
|
+
const passCxt = it.opts.passContext ? names_12.default.this : names_12.default.self;
|
|
1853
|
+
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
1854
|
+
gen.assign(valid, (0, codegen_12._)`${_await}${(0, code_12.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
1855
|
+
}
|
|
1856
|
+
function reportErrs(errors2) {
|
|
1857
|
+
var _a2;
|
|
1858
|
+
gen.if((0, codegen_12.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
|
|
1859
|
+
}
|
|
1865
1860
|
}
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1861
|
+
keyword.funcKeywordCode = funcKeywordCode;
|
|
1862
|
+
function modifyData(cxt) {
|
|
1863
|
+
const { gen, data, it } = cxt;
|
|
1864
|
+
gen.if(it.parentData, () => gen.assign(data, (0, codegen_12._)`${it.parentData}[${it.parentDataProperty}]`));
|
|
1865
|
+
}
|
|
1866
|
+
function addErrs(cxt, errs) {
|
|
1867
|
+
const { gen } = cxt;
|
|
1868
|
+
gen.if((0, codegen_12._)`Array.isArray(${errs})`, () => {
|
|
1869
|
+
gen.assign(names_12.default.vErrors, (0, codegen_12._)`${names_12.default.vErrors} === null ? ${errs} : ${names_12.default.vErrors}.concat(${errs})`).assign(names_12.default.errors, (0, codegen_12._)`${names_12.default.vErrors}.length`);
|
|
1870
|
+
(0, errors_12.extendErrors)(cxt);
|
|
1871
|
+
}, () => cxt.error());
|
|
1872
|
+
}
|
|
1873
|
+
function checkAsyncKeyword({ schemaEnv }, def2) {
|
|
1874
|
+
if (def2.async && !schemaEnv.$async)
|
|
1875
|
+
throw new Error("async keyword in sync schema");
|
|
1876
|
+
}
|
|
1877
|
+
function useKeyword(gen, keyword2, result) {
|
|
1878
|
+
if (result === void 0)
|
|
1879
|
+
throw new Error(`keyword "${keyword2}" failed to compile`);
|
|
1880
|
+
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_12.stringify)(result) });
|
|
1881
|
+
}
|
|
1882
|
+
function validSchemaType(schema, schemaType, allowUndefined = false) {
|
|
1883
|
+
return !schemaType.length || schemaType.some((st) => st === "array" ? Array.isArray(schema) : st === "object" ? schema && typeof schema == "object" && !Array.isArray(schema) : typeof schema == st || allowUndefined && typeof schema == "undefined");
|
|
1884
|
+
}
|
|
1885
|
+
keyword.validSchemaType = validSchemaType;
|
|
1886
|
+
function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def2, keyword2) {
|
|
1887
|
+
if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
|
|
1888
|
+
throw new Error("ajv implementation error");
|
|
1889
|
+
}
|
|
1890
|
+
const deps = def2.dependencies;
|
|
1891
|
+
if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
|
|
1892
|
+
throw new Error(`parent schema must have dependencies of ${keyword2}: ${deps.join(",")}`);
|
|
1893
|
+
}
|
|
1894
|
+
if (def2.validateSchema) {
|
|
1895
|
+
const valid = def2.validateSchema(schema[keyword2]);
|
|
1896
|
+
if (!valid) {
|
|
1897
|
+
const msg = `keyword "${keyword2}" value is invalid at path "${errSchemaPath}": ` + self.errorsText(def2.validateSchema.errors);
|
|
1898
|
+
if (opts.validateSchema === "log")
|
|
1899
|
+
self.logger.error(msg);
|
|
1900
|
+
else
|
|
1901
|
+
throw new Error(msg);
|
|
1902
|
+
}
|
|
1874
1903
|
}
|
|
1875
1904
|
}
|
|
1905
|
+
keyword.validateKeywordUsage = validateKeywordUsage;
|
|
1906
|
+
return keyword;
|
|
1876
1907
|
}
|
|
1877
|
-
keyword.validateKeywordUsage = validateKeywordUsage;
|
|
1878
1908
|
var subschema = {};
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
schema: sch,
|
|
1891
|
-
schemaPath: (0, codegen_1$s._)`${it.schemaPath}${(0, codegen_1$s.getProperty)(keyword2)}`,
|
|
1892
|
-
errSchemaPath: `${it.errSchemaPath}/${keyword2}`
|
|
1893
|
-
} : {
|
|
1894
|
-
schema: sch[schemaProp],
|
|
1895
|
-
schemaPath: (0, codegen_1$s._)`${it.schemaPath}${(0, codegen_1$s.getProperty)(keyword2)}${(0, codegen_1$s.getProperty)(schemaProp)}`,
|
|
1896
|
-
errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_1$r.escapeFragment)(schemaProp)}`
|
|
1897
|
-
};
|
|
1898
|
-
}
|
|
1899
|
-
if (schema !== void 0) {
|
|
1900
|
-
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
1901
|
-
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
1909
|
+
var hasRequiredSubschema;
|
|
1910
|
+
function requireSubschema() {
|
|
1911
|
+
if (hasRequiredSubschema) return subschema;
|
|
1912
|
+
hasRequiredSubschema = 1;
|
|
1913
|
+
Object.defineProperty(subschema, "__esModule", { value: true });
|
|
1914
|
+
subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
|
|
1915
|
+
const codegen_12 = requireCodegen();
|
|
1916
|
+
const util_12 = util;
|
|
1917
|
+
function getSubschema(it, { keyword: keyword2, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
|
|
1918
|
+
if (keyword2 !== void 0 && schema !== void 0) {
|
|
1919
|
+
throw new Error('both "keyword" and "schema" passed, only one allowed');
|
|
1902
1920
|
}
|
|
1903
|
-
|
|
1904
|
-
schema
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
}
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1921
|
+
if (keyword2 !== void 0) {
|
|
1922
|
+
const sch = it.schema[keyword2];
|
|
1923
|
+
return schemaProp === void 0 ? {
|
|
1924
|
+
schema: sch,
|
|
1925
|
+
schemaPath: (0, codegen_12._)`${it.schemaPath}${(0, codegen_12.getProperty)(keyword2)}`,
|
|
1926
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`
|
|
1927
|
+
} : {
|
|
1928
|
+
schema: sch[schemaProp],
|
|
1929
|
+
schemaPath: (0, codegen_12._)`${it.schemaPath}${(0, codegen_12.getProperty)(keyword2)}${(0, codegen_12.getProperty)(schemaProp)}`,
|
|
1930
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_12.escapeFragment)(schemaProp)}`
|
|
1931
|
+
};
|
|
1932
|
+
}
|
|
1933
|
+
if (schema !== void 0) {
|
|
1934
|
+
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
1935
|
+
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
1936
|
+
}
|
|
1937
|
+
return {
|
|
1938
|
+
schema,
|
|
1939
|
+
schemaPath,
|
|
1940
|
+
topSchemaRef,
|
|
1941
|
+
errSchemaPath
|
|
1942
|
+
};
|
|
1943
|
+
}
|
|
1944
|
+
throw new Error('either "keyword" or "schema" must be passed');
|
|
1945
|
+
}
|
|
1946
|
+
subschema.getSubschema = getSubschema;
|
|
1947
|
+
function extendSubschemaData(subschema2, it, { dataProp, dataPropType: dpType, data, dataTypes, propertyName }) {
|
|
1948
|
+
if (data !== void 0 && dataProp !== void 0) {
|
|
1949
|
+
throw new Error('both "data" and "dataProp" passed, only one allowed');
|
|
1950
|
+
}
|
|
1951
|
+
const { gen } = it;
|
|
1952
|
+
if (dataProp !== void 0) {
|
|
1953
|
+
const { errorPath, dataPathArr, opts } = it;
|
|
1954
|
+
const nextData = gen.let("data", (0, codegen_12._)`${it.data}${(0, codegen_12.getProperty)(dataProp)}`, true);
|
|
1955
|
+
dataContextProps(nextData);
|
|
1956
|
+
subschema2.errorPath = (0, codegen_12.str)`${errorPath}${(0, util_12.getErrorPath)(dataProp, dpType, opts.jsPropertySyntax)}`;
|
|
1957
|
+
subschema2.parentDataProperty = (0, codegen_12._)`${dataProp}`;
|
|
1958
|
+
subschema2.dataPathArr = [...dataPathArr, subschema2.parentDataProperty];
|
|
1959
|
+
}
|
|
1960
|
+
if (data !== void 0) {
|
|
1961
|
+
const nextData = data instanceof codegen_12.Name ? data : gen.let("data", data, true);
|
|
1962
|
+
dataContextProps(nextData);
|
|
1963
|
+
if (propertyName !== void 0)
|
|
1964
|
+
subschema2.propertyName = propertyName;
|
|
1965
|
+
}
|
|
1966
|
+
if (dataTypes)
|
|
1967
|
+
subschema2.dataTypes = dataTypes;
|
|
1968
|
+
function dataContextProps(_nextData) {
|
|
1969
|
+
subschema2.data = _nextData;
|
|
1970
|
+
subschema2.dataLevel = it.dataLevel + 1;
|
|
1971
|
+
subschema2.dataTypes = [];
|
|
1972
|
+
it.definedProperties = /* @__PURE__ */ new Set();
|
|
1973
|
+
subschema2.parentData = it.data;
|
|
1974
|
+
subschema2.dataNames = [...it.dataNames, _nextData];
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
subschema.extendSubschemaData = extendSubschemaData;
|
|
1978
|
+
function extendSubschemaMode(subschema2, { jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors }) {
|
|
1979
|
+
if (compositeRule !== void 0)
|
|
1980
|
+
subschema2.compositeRule = compositeRule;
|
|
1981
|
+
if (createErrors !== void 0)
|
|
1982
|
+
subschema2.createErrors = createErrors;
|
|
1983
|
+
if (allErrors !== void 0)
|
|
1984
|
+
subschema2.allErrors = allErrors;
|
|
1985
|
+
subschema2.jtdDiscriminator = jtdDiscriminator;
|
|
1986
|
+
subschema2.jtdMetadata = jtdMetadata;
|
|
1987
|
+
}
|
|
1988
|
+
subschema.extendSubschemaMode = extendSubschemaMode;
|
|
1989
|
+
return subschema;
|
|
1953
1990
|
}
|
|
1954
|
-
subschema.extendSubschemaMode = extendSubschemaMode;
|
|
1955
1991
|
var resolve$2 = {};
|
|
1956
1992
|
var fastDeepEqual = function equal(a, b) {
|
|
1957
1993
|
if (a === b) return true;
|
|
@@ -2066,7 +2102,7 @@ function escapeJsonPtr(str) {
|
|
|
2066
2102
|
var jsonSchemaTraverseExports = jsonSchemaTraverse.exports;
|
|
2067
2103
|
Object.defineProperty(resolve$2, "__esModule", { value: true });
|
|
2068
2104
|
resolve$2.getSchemaRefs = resolve$2.resolveUrl = resolve$2.normalizeId = resolve$2._getFullPath = resolve$2.getFullPath = resolve$2.inlineRef = void 0;
|
|
2069
|
-
const util_1$
|
|
2105
|
+
const util_1$p = util;
|
|
2070
2106
|
const equal$3 = fastDeepEqual;
|
|
2071
2107
|
const traverse = jsonSchemaTraverseExports;
|
|
2072
2108
|
const SIMPLE_INLINED = /* @__PURE__ */ new Set([
|
|
@@ -2125,7 +2161,7 @@ function countKeys(schema) {
|
|
|
2125
2161
|
if (SIMPLE_INLINED.has(key))
|
|
2126
2162
|
continue;
|
|
2127
2163
|
if (typeof schema[key] == "object") {
|
|
2128
|
-
(0, util_1$
|
|
2164
|
+
(0, util_1$p.eachItem)(schema[key], (sch) => count += countKeys(sch));
|
|
2129
2165
|
}
|
|
2130
2166
|
if (count === Infinity)
|
|
2131
2167
|
return Infinity;
|
|
@@ -2213,536 +2249,554 @@ function getSchemaRefs(schema, baseId) {
|
|
|
2213
2249
|
}
|
|
2214
2250
|
}
|
|
2215
2251
|
resolve$2.getSchemaRefs = getSchemaRefs;
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
const
|
|
2223
|
-
const
|
|
2224
|
-
const
|
|
2225
|
-
const
|
|
2226
|
-
const
|
|
2227
|
-
const
|
|
2228
|
-
const
|
|
2229
|
-
const
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2252
|
+
var hasRequiredValidate;
|
|
2253
|
+
function requireValidate() {
|
|
2254
|
+
if (hasRequiredValidate) return validate;
|
|
2255
|
+
hasRequiredValidate = 1;
|
|
2256
|
+
Object.defineProperty(validate, "__esModule", { value: true });
|
|
2257
|
+
validate.getData = validate.KeywordCxt = validate.validateFunctionCode = void 0;
|
|
2258
|
+
const boolSchema_1 = requireBoolSchema();
|
|
2259
|
+
const dataType_12 = dataType;
|
|
2260
|
+
const applicability_12 = applicability;
|
|
2261
|
+
const dataType_2 = dataType;
|
|
2262
|
+
const defaults_1 = requireDefaults();
|
|
2263
|
+
const keyword_1 = requireKeyword();
|
|
2264
|
+
const subschema_1 = requireSubschema();
|
|
2265
|
+
const codegen_12 = requireCodegen();
|
|
2266
|
+
const names_12 = names$1;
|
|
2267
|
+
const resolve_12 = resolve$2;
|
|
2268
|
+
const util_12 = util;
|
|
2269
|
+
const errors_12 = errors;
|
|
2270
|
+
function validateFunctionCode(it) {
|
|
2271
|
+
if (isSchemaObj(it)) {
|
|
2272
|
+
checkKeywords(it);
|
|
2273
|
+
if (schemaCxtHasRules(it)) {
|
|
2274
|
+
topSchemaObjCode(it);
|
|
2275
|
+
return;
|
|
2276
|
+
}
|
|
2236
2277
|
}
|
|
2278
|
+
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
2237
2279
|
}
|
|
2238
|
-
|
|
2239
|
-
}
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2280
|
+
validate.validateFunctionCode = validateFunctionCode;
|
|
2281
|
+
function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
|
|
2282
|
+
if (opts.code.es5) {
|
|
2283
|
+
gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${names_12.default.valCxt}`, schemaEnv.$async, () => {
|
|
2284
|
+
gen.code((0, codegen_12._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
|
|
2285
|
+
destructureValCxtES5(gen, opts);
|
|
2286
|
+
gen.code(body);
|
|
2287
|
+
});
|
|
2288
|
+
} else {
|
|
2289
|
+
gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
function destructureValCxt(opts) {
|
|
2293
|
+
return (0, codegen_12._)`{${names_12.default.instancePath}="", ${names_12.default.parentData}, ${names_12.default.parentDataProperty}, ${names_12.default.rootData}=${names_12.default.data}${opts.dynamicRef ? (0, codegen_12._)`, ${names_12.default.dynamicAnchors}={}` : codegen_12.nil}}={}`;
|
|
2294
|
+
}
|
|
2295
|
+
function destructureValCxtES5(gen, opts) {
|
|
2296
|
+
gen.if(names_12.default.valCxt, () => {
|
|
2297
|
+
gen.var(names_12.default.instancePath, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.instancePath}`);
|
|
2298
|
+
gen.var(names_12.default.parentData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentData}`);
|
|
2299
|
+
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentDataProperty}`);
|
|
2300
|
+
gen.var(names_12.default.rootData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.rootData}`);
|
|
2301
|
+
if (opts.dynamicRef)
|
|
2302
|
+
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.dynamicAnchors}`);
|
|
2303
|
+
}, () => {
|
|
2304
|
+
gen.var(names_12.default.instancePath, (0, codegen_12._)`""`);
|
|
2305
|
+
gen.var(names_12.default.parentData, (0, codegen_12._)`undefined`);
|
|
2306
|
+
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`undefined`);
|
|
2307
|
+
gen.var(names_12.default.rootData, names_12.default.data);
|
|
2308
|
+
if (opts.dynamicRef)
|
|
2309
|
+
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`{}`);
|
|
2247
2310
|
});
|
|
2248
|
-
} else {
|
|
2249
|
-
gen.func(validateName, (0, codegen_1$r._)`${names_1$6.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
2250
2311
|
}
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
gen
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
}
|
|
2272
|
-
function
|
|
2273
|
-
|
|
2274
|
-
|
|
2312
|
+
function topSchemaObjCode(it) {
|
|
2313
|
+
const { schema, opts, gen } = it;
|
|
2314
|
+
validateFunction(it, () => {
|
|
2315
|
+
if (opts.$comment && schema.$comment)
|
|
2316
|
+
commentKeyword(it);
|
|
2317
|
+
checkNoDefault(it);
|
|
2318
|
+
gen.let(names_12.default.vErrors, null);
|
|
2319
|
+
gen.let(names_12.default.errors, 0);
|
|
2320
|
+
if (opts.unevaluated)
|
|
2321
|
+
resetEvaluated(it);
|
|
2322
|
+
typeAndKeywords(it);
|
|
2323
|
+
returnResults(it);
|
|
2324
|
+
});
|
|
2325
|
+
return;
|
|
2326
|
+
}
|
|
2327
|
+
function resetEvaluated(it) {
|
|
2328
|
+
const { gen, validateName } = it;
|
|
2329
|
+
it.evaluated = gen.const("evaluated", (0, codegen_12._)`${validateName}.evaluated`);
|
|
2330
|
+
gen.if((0, codegen_12._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_12._)`${it.evaluated}.props`, (0, codegen_12._)`undefined`));
|
|
2331
|
+
gen.if((0, codegen_12._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_12._)`${it.evaluated}.items`, (0, codegen_12._)`undefined`));
|
|
2332
|
+
}
|
|
2333
|
+
function funcSourceUrl(schema, opts) {
|
|
2334
|
+
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
2335
|
+
return schId && (opts.code.source || opts.code.process) ? (0, codegen_12._)`/*# sourceURL=${schId} */` : codegen_12.nil;
|
|
2336
|
+
}
|
|
2337
|
+
function subschemaCode(it, valid) {
|
|
2338
|
+
if (isSchemaObj(it)) {
|
|
2339
|
+
checkKeywords(it);
|
|
2340
|
+
if (schemaCxtHasRules(it)) {
|
|
2341
|
+
subSchemaObjCode(it, valid);
|
|
2342
|
+
return;
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
(0, boolSchema_1.boolOrEmptySchema)(it, valid);
|
|
2346
|
+
}
|
|
2347
|
+
function schemaCxtHasRules({ schema, self }) {
|
|
2348
|
+
if (typeof schema == "boolean")
|
|
2349
|
+
return !schema;
|
|
2350
|
+
for (const key in schema)
|
|
2351
|
+
if (self.RULES.all[key])
|
|
2352
|
+
return true;
|
|
2353
|
+
return false;
|
|
2354
|
+
}
|
|
2355
|
+
function isSchemaObj(it) {
|
|
2356
|
+
return typeof it.schema != "boolean";
|
|
2357
|
+
}
|
|
2358
|
+
function subSchemaObjCode(it, valid) {
|
|
2359
|
+
const { schema, gen, opts } = it;
|
|
2275
2360
|
if (opts.$comment && schema.$comment)
|
|
2276
2361
|
commentKeyword(it);
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
gen.
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
typeAndKeywords(it);
|
|
2283
|
-
returnResults(it);
|
|
2284
|
-
});
|
|
2285
|
-
return;
|
|
2286
|
-
}
|
|
2287
|
-
function resetEvaluated(it) {
|
|
2288
|
-
const { gen, validateName } = it;
|
|
2289
|
-
it.evaluated = gen.const("evaluated", (0, codegen_1$r._)`${validateName}.evaluated`);
|
|
2290
|
-
gen.if((0, codegen_1$r._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_1$r._)`${it.evaluated}.props`, (0, codegen_1$r._)`undefined`));
|
|
2291
|
-
gen.if((0, codegen_1$r._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_1$r._)`${it.evaluated}.items`, (0, codegen_1$r._)`undefined`));
|
|
2292
|
-
}
|
|
2293
|
-
function funcSourceUrl(schema, opts) {
|
|
2294
|
-
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
2295
|
-
return schId && (opts.code.source || opts.code.process) ? (0, codegen_1$r._)`/*# sourceURL=${schId} */` : codegen_1$r.nil;
|
|
2296
|
-
}
|
|
2297
|
-
function subschemaCode(it, valid) {
|
|
2298
|
-
if (isSchemaObj(it)) {
|
|
2299
|
-
checkKeywords(it);
|
|
2300
|
-
if (schemaCxtHasRules(it)) {
|
|
2301
|
-
subSchemaObjCode(it, valid);
|
|
2302
|
-
return;
|
|
2303
|
-
}
|
|
2362
|
+
updateContext(it);
|
|
2363
|
+
checkAsyncSchema(it);
|
|
2364
|
+
const errsCount = gen.const("_errs", names_12.default.errors);
|
|
2365
|
+
typeAndKeywords(it, errsCount);
|
|
2366
|
+
gen.var(valid, (0, codegen_12._)`${errsCount} === ${names_12.default.errors}`);
|
|
2304
2367
|
}
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
if (typeof schema == "boolean")
|
|
2309
|
-
return !schema;
|
|
2310
|
-
for (const key in schema)
|
|
2311
|
-
if (self.RULES.all[key])
|
|
2312
|
-
return true;
|
|
2313
|
-
return false;
|
|
2314
|
-
}
|
|
2315
|
-
function isSchemaObj(it) {
|
|
2316
|
-
return typeof it.schema != "boolean";
|
|
2317
|
-
}
|
|
2318
|
-
function subSchemaObjCode(it, valid) {
|
|
2319
|
-
const { schema, gen, opts } = it;
|
|
2320
|
-
if (opts.$comment && schema.$comment)
|
|
2321
|
-
commentKeyword(it);
|
|
2322
|
-
updateContext(it);
|
|
2323
|
-
checkAsyncSchema(it);
|
|
2324
|
-
const errsCount = gen.const("_errs", names_1$6.default.errors);
|
|
2325
|
-
typeAndKeywords(it, errsCount);
|
|
2326
|
-
gen.var(valid, (0, codegen_1$r._)`${errsCount} === ${names_1$6.default.errors}`);
|
|
2327
|
-
}
|
|
2328
|
-
function checkKeywords(it) {
|
|
2329
|
-
(0, util_1$p.checkUnknownRules)(it);
|
|
2330
|
-
checkRefsAndKeywords(it);
|
|
2331
|
-
}
|
|
2332
|
-
function typeAndKeywords(it, errsCount) {
|
|
2333
|
-
if (it.opts.jtd)
|
|
2334
|
-
return schemaKeywords(it, [], false, errsCount);
|
|
2335
|
-
const types2 = (0, dataType_1$1.getSchemaTypes)(it.schema);
|
|
2336
|
-
const checkedTypes = (0, dataType_1$1.coerceAndCheckDataType)(it, types2);
|
|
2337
|
-
schemaKeywords(it, types2, !checkedTypes, errsCount);
|
|
2338
|
-
}
|
|
2339
|
-
function checkRefsAndKeywords(it) {
|
|
2340
|
-
const { schema, errSchemaPath, opts, self } = it;
|
|
2341
|
-
if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_1$p.schemaHasRulesButRef)(schema, self.RULES)) {
|
|
2342
|
-
self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
|
|
2368
|
+
function checkKeywords(it) {
|
|
2369
|
+
(0, util_12.checkUnknownRules)(it);
|
|
2370
|
+
checkRefsAndKeywords(it);
|
|
2343
2371
|
}
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
(0,
|
|
2372
|
+
function typeAndKeywords(it, errsCount) {
|
|
2373
|
+
if (it.opts.jtd)
|
|
2374
|
+
return schemaKeywords(it, [], false, errsCount);
|
|
2375
|
+
const types2 = (0, dataType_12.getSchemaTypes)(it.schema);
|
|
2376
|
+
const checkedTypes = (0, dataType_12.coerceAndCheckDataType)(it, types2);
|
|
2377
|
+
schemaKeywords(it, types2, !checkedTypes, errsCount);
|
|
2349
2378
|
}
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
}
|
|
2356
|
-
function checkAsyncSchema(it) {
|
|
2357
|
-
if (it.schema.$async && !it.schemaEnv.$async)
|
|
2358
|
-
throw new Error("async schema in sync schema");
|
|
2359
|
-
}
|
|
2360
|
-
function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
|
|
2361
|
-
const msg = schema.$comment;
|
|
2362
|
-
if (opts.$comment === true) {
|
|
2363
|
-
gen.code((0, codegen_1$r._)`${names_1$6.default.self}.logger.log(${msg})`);
|
|
2364
|
-
} else if (typeof opts.$comment == "function") {
|
|
2365
|
-
const schemaPath = (0, codegen_1$r.str)`${errSchemaPath}/$comment`;
|
|
2366
|
-
const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
|
|
2367
|
-
gen.code((0, codegen_1$r._)`${names_1$6.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
|
|
2379
|
+
function checkRefsAndKeywords(it) {
|
|
2380
|
+
const { schema, errSchemaPath, opts, self } = it;
|
|
2381
|
+
if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_12.schemaHasRulesButRef)(schema, self.RULES)) {
|
|
2382
|
+
self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
|
|
2383
|
+
}
|
|
2368
2384
|
}
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
} else {
|
|
2375
|
-
gen.assign((0, codegen_1$r._)`${validateName}.errors`, names_1$6.default.vErrors);
|
|
2376
|
-
if (opts.unevaluated)
|
|
2377
|
-
assignEvaluated(it);
|
|
2378
|
-
gen.return((0, codegen_1$r._)`${names_1$6.default.errors} === 0`);
|
|
2385
|
+
function checkNoDefault(it) {
|
|
2386
|
+
const { schema, opts } = it;
|
|
2387
|
+
if (schema.default !== void 0 && opts.useDefaults && opts.strictSchema) {
|
|
2388
|
+
(0, util_12.checkStrictMode)(it, "default is ignored in the schema root");
|
|
2389
|
+
}
|
|
2379
2390
|
}
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
if (items2 instanceof codegen_1$r.Name)
|
|
2385
|
-
gen.assign((0, codegen_1$r._)`${evaluated}.items`, items2);
|
|
2386
|
-
}
|
|
2387
|
-
function schemaKeywords(it, types2, typeErrors, errsCount) {
|
|
2388
|
-
const { gen, schema, data, allErrors, opts, self } = it;
|
|
2389
|
-
const { RULES } = self;
|
|
2390
|
-
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_1$p.schemaHasRulesButRef)(schema, RULES))) {
|
|
2391
|
-
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
2392
|
-
return;
|
|
2391
|
+
function updateContext(it) {
|
|
2392
|
+
const schId = it.schema[it.opts.schemaId];
|
|
2393
|
+
if (schId)
|
|
2394
|
+
it.baseId = (0, resolve_12.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
|
|
2393
2395
|
}
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
if (
|
|
2396
|
+
function checkAsyncSchema(it) {
|
|
2397
|
+
if (it.schema.$async && !it.schemaEnv.$async)
|
|
2398
|
+
throw new Error("async schema in sync schema");
|
|
2399
|
+
}
|
|
2400
|
+
function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
|
|
2401
|
+
const msg = schema.$comment;
|
|
2402
|
+
if (opts.$comment === true) {
|
|
2403
|
+
gen.code((0, codegen_12._)`${names_12.default.self}.logger.log(${msg})`);
|
|
2404
|
+
} else if (typeof opts.$comment == "function") {
|
|
2405
|
+
const schemaPath = (0, codegen_12.str)`${errSchemaPath}/$comment`;
|
|
2406
|
+
const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
|
|
2407
|
+
gen.code((0, codegen_12._)`${names_12.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
function returnResults(it) {
|
|
2411
|
+
const { gen, schemaEnv, validateName, ValidationError, opts } = it;
|
|
2412
|
+
if (schemaEnv.$async) {
|
|
2413
|
+
gen.if((0, codegen_12._)`${names_12.default.errors} === 0`, () => gen.return(names_12.default.data), () => gen.throw((0, codegen_12._)`new ${ValidationError}(${names_12.default.vErrors})`));
|
|
2414
|
+
} else {
|
|
2415
|
+
gen.assign((0, codegen_12._)`${validateName}.errors`, names_12.default.vErrors);
|
|
2416
|
+
if (opts.unevaluated)
|
|
2417
|
+
assignEvaluated(it);
|
|
2418
|
+
gen.return((0, codegen_12._)`${names_12.default.errors} === 0`);
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
function assignEvaluated({ gen, evaluated, props, items: items2 }) {
|
|
2422
|
+
if (props instanceof codegen_12.Name)
|
|
2423
|
+
gen.assign((0, codegen_12._)`${evaluated}.props`, props);
|
|
2424
|
+
if (items2 instanceof codegen_12.Name)
|
|
2425
|
+
gen.assign((0, codegen_12._)`${evaluated}.items`, items2);
|
|
2426
|
+
}
|
|
2427
|
+
function schemaKeywords(it, types2, typeErrors, errsCount) {
|
|
2428
|
+
const { gen, schema, data, allErrors, opts, self } = it;
|
|
2429
|
+
const { RULES } = self;
|
|
2430
|
+
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_12.schemaHasRulesButRef)(schema, RULES))) {
|
|
2431
|
+
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
2403
2432
|
return;
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
(
|
|
2433
|
+
}
|
|
2434
|
+
if (!opts.jtd)
|
|
2435
|
+
checkStrictTypes(it, types2);
|
|
2436
|
+
gen.block(() => {
|
|
2437
|
+
for (const group of RULES.rules)
|
|
2438
|
+
groupKeywords(group);
|
|
2439
|
+
groupKeywords(RULES.post);
|
|
2440
|
+
});
|
|
2441
|
+
function groupKeywords(group) {
|
|
2442
|
+
if (!(0, applicability_12.shouldUseGroup)(schema, group))
|
|
2443
|
+
return;
|
|
2444
|
+
if (group.type) {
|
|
2445
|
+
gen.if((0, dataType_2.checkDataType)(group.type, data, opts.strictNumbers));
|
|
2446
|
+
iterateKeywords(it, group);
|
|
2447
|
+
if (types2.length === 1 && types2[0] === group.type && typeErrors) {
|
|
2448
|
+
gen.else();
|
|
2449
|
+
(0, dataType_2.reportTypeError)(it);
|
|
2450
|
+
}
|
|
2451
|
+
gen.endIf();
|
|
2452
|
+
} else {
|
|
2453
|
+
iterateKeywords(it, group);
|
|
2410
2454
|
}
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
iterateKeywords(it, group);
|
|
2455
|
+
if (!allErrors)
|
|
2456
|
+
gen.if((0, codegen_12._)`${names_12.default.errors} === ${errsCount || 0}`);
|
|
2414
2457
|
}
|
|
2415
|
-
if (!allErrors)
|
|
2416
|
-
gen.if((0, codegen_1$r._)`${names_1$6.default.errors} === ${errsCount || 0}`);
|
|
2417
2458
|
}
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
(
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2459
|
+
function iterateKeywords(it, group) {
|
|
2460
|
+
const { gen, schema, opts: { useDefaults } } = it;
|
|
2461
|
+
if (useDefaults)
|
|
2462
|
+
(0, defaults_1.assignDefaults)(it, group.type);
|
|
2463
|
+
gen.block(() => {
|
|
2464
|
+
for (const rule of group.rules) {
|
|
2465
|
+
if ((0, applicability_12.shouldUseRule)(schema, rule)) {
|
|
2466
|
+
keywordCode(it, rule.keyword, rule.definition, group.type);
|
|
2467
|
+
}
|
|
2427
2468
|
}
|
|
2469
|
+
});
|
|
2470
|
+
}
|
|
2471
|
+
function checkStrictTypes(it, types2) {
|
|
2472
|
+
if (it.schemaEnv.meta || !it.opts.strictTypes)
|
|
2473
|
+
return;
|
|
2474
|
+
checkContextTypes(it, types2);
|
|
2475
|
+
if (!it.opts.allowUnionTypes)
|
|
2476
|
+
checkMultipleTypes(it, types2);
|
|
2477
|
+
checkKeywordTypes(it, it.dataTypes);
|
|
2478
|
+
}
|
|
2479
|
+
function checkContextTypes(it, types2) {
|
|
2480
|
+
if (!types2.length)
|
|
2481
|
+
return;
|
|
2482
|
+
if (!it.dataTypes.length) {
|
|
2483
|
+
it.dataTypes = types2;
|
|
2484
|
+
return;
|
|
2428
2485
|
}
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
if (!it.opts.allowUnionTypes)
|
|
2436
|
-
checkMultipleTypes(it, types2);
|
|
2437
|
-
checkKeywordTypes(it, it.dataTypes);
|
|
2438
|
-
}
|
|
2439
|
-
function checkContextTypes(it, types2) {
|
|
2440
|
-
if (!types2.length)
|
|
2441
|
-
return;
|
|
2442
|
-
if (!it.dataTypes.length) {
|
|
2443
|
-
it.dataTypes = types2;
|
|
2444
|
-
return;
|
|
2486
|
+
types2.forEach((t) => {
|
|
2487
|
+
if (!includesType(it.dataTypes, t)) {
|
|
2488
|
+
strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
|
|
2489
|
+
}
|
|
2490
|
+
});
|
|
2491
|
+
narrowSchemaTypes(it, types2);
|
|
2445
2492
|
}
|
|
2446
|
-
|
|
2447
|
-
if (!
|
|
2448
|
-
strictTypesError(it,
|
|
2493
|
+
function checkMultipleTypes(it, ts) {
|
|
2494
|
+
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
|
|
2495
|
+
strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
2449
2496
|
}
|
|
2450
|
-
});
|
|
2451
|
-
narrowSchemaTypes(it, types2);
|
|
2452
|
-
}
|
|
2453
|
-
function checkMultipleTypes(it, ts) {
|
|
2454
|
-
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
|
|
2455
|
-
strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
2456
2497
|
}
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2498
|
+
function checkKeywordTypes(it, ts) {
|
|
2499
|
+
const rules2 = it.self.RULES.all;
|
|
2500
|
+
for (const keyword2 in rules2) {
|
|
2501
|
+
const rule = rules2[keyword2];
|
|
2502
|
+
if (typeof rule == "object" && (0, applicability_12.shouldUseRule)(it.schema, rule)) {
|
|
2503
|
+
const { type: type2 } = rule.definition;
|
|
2504
|
+
if (type2.length && !type2.some((t) => hasApplicableType(ts, t))) {
|
|
2505
|
+
strictTypesError(it, `missing type "${type2.join(",")}" for keyword "${keyword2}"`);
|
|
2506
|
+
}
|
|
2466
2507
|
}
|
|
2467
2508
|
}
|
|
2468
2509
|
}
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2510
|
+
function hasApplicableType(schTs, kwdT) {
|
|
2511
|
+
return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
|
|
2512
|
+
}
|
|
2513
|
+
function includesType(ts, t) {
|
|
2514
|
+
return ts.includes(t) || t === "integer" && ts.includes("number");
|
|
2515
|
+
}
|
|
2516
|
+
function narrowSchemaTypes(it, withTypes) {
|
|
2517
|
+
const ts = [];
|
|
2518
|
+
for (const t of it.dataTypes) {
|
|
2519
|
+
if (includesType(withTypes, t))
|
|
2520
|
+
ts.push(t);
|
|
2521
|
+
else if (withTypes.includes("integer") && t === "number")
|
|
2522
|
+
ts.push("integer");
|
|
2523
|
+
}
|
|
2524
|
+
it.dataTypes = ts;
|
|
2525
|
+
}
|
|
2526
|
+
function strictTypesError(it, msg) {
|
|
2527
|
+
const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
|
|
2528
|
+
msg += ` at "${schemaPath}" (strictTypes)`;
|
|
2529
|
+
(0, util_12.checkStrictMode)(it, msg, it.opts.strictTypes);
|
|
2530
|
+
}
|
|
2531
|
+
class KeywordCxt {
|
|
2532
|
+
constructor(it, def2, keyword2) {
|
|
2533
|
+
(0, keyword_1.validateKeywordUsage)(it, def2, keyword2);
|
|
2534
|
+
this.gen = it.gen;
|
|
2535
|
+
this.allErrors = it.allErrors;
|
|
2536
|
+
this.keyword = keyword2;
|
|
2537
|
+
this.data = it.data;
|
|
2538
|
+
this.schema = it.schema[keyword2];
|
|
2539
|
+
this.$data = def2.$data && it.opts.$data && this.schema && this.schema.$data;
|
|
2540
|
+
this.schemaValue = (0, util_12.schemaRefOrVal)(it, this.schema, keyword2, this.$data);
|
|
2541
|
+
this.schemaType = def2.schemaType;
|
|
2542
|
+
this.parentSchema = it.schema;
|
|
2543
|
+
this.params = {};
|
|
2544
|
+
this.it = it;
|
|
2545
|
+
this.def = def2;
|
|
2546
|
+
if (this.$data) {
|
|
2547
|
+
this.schemaCode = it.gen.const("vSchema", getData(this.$data, it));
|
|
2548
|
+
} else {
|
|
2549
|
+
this.schemaCode = this.schemaValue;
|
|
2550
|
+
if (!(0, keyword_1.validSchemaType)(this.schema, def2.schemaType, def2.allowUndefined)) {
|
|
2551
|
+
throw new Error(`${keyword2} value must be ${JSON.stringify(def2.schemaType)}`);
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
|
|
2555
|
+
this.errsCount = it.gen.const("_errs", names_12.default.errors);
|
|
2512
2556
|
}
|
|
2513
2557
|
}
|
|
2514
|
-
|
|
2515
|
-
this.
|
|
2558
|
+
result(condition, successAction, failAction) {
|
|
2559
|
+
this.failResult((0, codegen_12.not)(condition), successAction, failAction);
|
|
2516
2560
|
}
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2561
|
+
failResult(condition, successAction, failAction) {
|
|
2562
|
+
this.gen.if(condition);
|
|
2563
|
+
if (failAction)
|
|
2564
|
+
failAction();
|
|
2565
|
+
else
|
|
2566
|
+
this.error();
|
|
2567
|
+
if (successAction) {
|
|
2568
|
+
this.gen.else();
|
|
2569
|
+
successAction();
|
|
2570
|
+
if (this.allErrors)
|
|
2571
|
+
this.gen.endIf();
|
|
2572
|
+
} else {
|
|
2573
|
+
if (this.allErrors)
|
|
2574
|
+
this.gen.endIf();
|
|
2575
|
+
else
|
|
2576
|
+
this.gen.else();
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
pass(condition, failAction) {
|
|
2580
|
+
this.failResult((0, codegen_12.not)(condition), void 0, failAction);
|
|
2581
|
+
}
|
|
2582
|
+
fail(condition) {
|
|
2583
|
+
if (condition === void 0) {
|
|
2584
|
+
this.error();
|
|
2585
|
+
if (!this.allErrors)
|
|
2586
|
+
this.gen.if(false);
|
|
2587
|
+
return;
|
|
2588
|
+
}
|
|
2589
|
+
this.gen.if(condition);
|
|
2526
2590
|
this.error();
|
|
2527
|
-
if (successAction) {
|
|
2528
|
-
this.gen.else();
|
|
2529
|
-
successAction();
|
|
2530
|
-
if (this.allErrors)
|
|
2531
|
-
this.gen.endIf();
|
|
2532
|
-
} else {
|
|
2533
2591
|
if (this.allErrors)
|
|
2534
2592
|
this.gen.endIf();
|
|
2535
2593
|
else
|
|
2536
2594
|
this.gen.else();
|
|
2537
2595
|
}
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2596
|
+
fail$data(condition) {
|
|
2597
|
+
if (!this.$data)
|
|
2598
|
+
return this.fail(condition);
|
|
2599
|
+
const { schemaCode } = this;
|
|
2600
|
+
this.fail((0, codegen_12._)`${schemaCode} !== undefined && (${(0, codegen_12.or)(this.invalid$data(), condition)})`);
|
|
2601
|
+
}
|
|
2602
|
+
error(append, errorParams, errorPaths) {
|
|
2603
|
+
if (errorParams) {
|
|
2604
|
+
this.setParams(errorParams);
|
|
2605
|
+
this._error(append, errorPaths);
|
|
2606
|
+
this.setParams({});
|
|
2607
|
+
return;
|
|
2608
|
+
}
|
|
2609
|
+
this._error(append, errorPaths);
|
|
2610
|
+
}
|
|
2611
|
+
_error(append, errorPaths) {
|
|
2612
|
+
(append ? errors_12.reportExtraError : errors_12.reportError)(this, this.def.error, errorPaths);
|
|
2613
|
+
}
|
|
2614
|
+
$dataError() {
|
|
2615
|
+
(0, errors_12.reportError)(this, this.def.$dataError || errors_12.keyword$DataError);
|
|
2616
|
+
}
|
|
2617
|
+
reset() {
|
|
2618
|
+
if (this.errsCount === void 0)
|
|
2619
|
+
throw new Error('add "trackErrors" to keyword definition');
|
|
2620
|
+
(0, errors_12.resetErrorsCount)(this.gen, this.errsCount);
|
|
2621
|
+
}
|
|
2622
|
+
ok(cond) {
|
|
2545
2623
|
if (!this.allErrors)
|
|
2546
|
-
this.gen.if(
|
|
2547
|
-
return;
|
|
2624
|
+
this.gen.if(cond);
|
|
2548
2625
|
}
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
this.gen.else();
|
|
2555
|
-
}
|
|
2556
|
-
fail$data(condition) {
|
|
2557
|
-
if (!this.$data)
|
|
2558
|
-
return this.fail(condition);
|
|
2559
|
-
const { schemaCode } = this;
|
|
2560
|
-
this.fail((0, codegen_1$r._)`${schemaCode} !== undefined && (${(0, codegen_1$r.or)(this.invalid$data(), condition)})`);
|
|
2561
|
-
}
|
|
2562
|
-
error(append, errorParams, errorPaths) {
|
|
2563
|
-
if (errorParams) {
|
|
2564
|
-
this.setParams(errorParams);
|
|
2565
|
-
this._error(append, errorPaths);
|
|
2566
|
-
this.setParams({});
|
|
2567
|
-
return;
|
|
2626
|
+
setParams(obj, assign) {
|
|
2627
|
+
if (assign)
|
|
2628
|
+
Object.assign(this.params, obj);
|
|
2629
|
+
else
|
|
2630
|
+
this.params = obj;
|
|
2568
2631
|
}
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
$dataError() {
|
|
2575
|
-
(0, errors_1.reportError)(this, this.def.$dataError || errors_1.keyword$DataError);
|
|
2576
|
-
}
|
|
2577
|
-
reset() {
|
|
2578
|
-
if (this.errsCount === void 0)
|
|
2579
|
-
throw new Error('add "trackErrors" to keyword definition');
|
|
2580
|
-
(0, errors_1.resetErrorsCount)(this.gen, this.errsCount);
|
|
2581
|
-
}
|
|
2582
|
-
ok(cond) {
|
|
2583
|
-
if (!this.allErrors)
|
|
2584
|
-
this.gen.if(cond);
|
|
2585
|
-
}
|
|
2586
|
-
setParams(obj, assign) {
|
|
2587
|
-
if (assign)
|
|
2588
|
-
Object.assign(this.params, obj);
|
|
2589
|
-
else
|
|
2590
|
-
this.params = obj;
|
|
2591
|
-
}
|
|
2592
|
-
block$data(valid, codeBlock, $dataValid = codegen_1$r.nil) {
|
|
2593
|
-
this.gen.block(() => {
|
|
2594
|
-
this.check$data(valid, $dataValid);
|
|
2595
|
-
codeBlock();
|
|
2596
|
-
});
|
|
2597
|
-
}
|
|
2598
|
-
check$data(valid = codegen_1$r.nil, $dataValid = codegen_1$r.nil) {
|
|
2599
|
-
if (!this.$data)
|
|
2600
|
-
return;
|
|
2601
|
-
const { gen, schemaCode, schemaType, def: def2 } = this;
|
|
2602
|
-
gen.if((0, codegen_1$r.or)((0, codegen_1$r._)`${schemaCode} === undefined`, $dataValid));
|
|
2603
|
-
if (valid !== codegen_1$r.nil)
|
|
2604
|
-
gen.assign(valid, true);
|
|
2605
|
-
if (schemaType.length || def2.validateSchema) {
|
|
2606
|
-
gen.elseIf(this.invalid$data());
|
|
2607
|
-
this.$dataError();
|
|
2608
|
-
if (valid !== codegen_1$r.nil)
|
|
2609
|
-
gen.assign(valid, false);
|
|
2632
|
+
block$data(valid, codeBlock, $dataValid = codegen_12.nil) {
|
|
2633
|
+
this.gen.block(() => {
|
|
2634
|
+
this.check$data(valid, $dataValid);
|
|
2635
|
+
codeBlock();
|
|
2636
|
+
});
|
|
2610
2637
|
}
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2638
|
+
check$data(valid = codegen_12.nil, $dataValid = codegen_12.nil) {
|
|
2639
|
+
if (!this.$data)
|
|
2640
|
+
return;
|
|
2641
|
+
const { gen, schemaCode, schemaType, def: def2 } = this;
|
|
2642
|
+
gen.if((0, codegen_12.or)((0, codegen_12._)`${schemaCode} === undefined`, $dataValid));
|
|
2643
|
+
if (valid !== codegen_12.nil)
|
|
2644
|
+
gen.assign(valid, true);
|
|
2645
|
+
if (schemaType.length || def2.validateSchema) {
|
|
2646
|
+
gen.elseIf(this.invalid$data());
|
|
2647
|
+
this.$dataError();
|
|
2648
|
+
if (valid !== codegen_12.nil)
|
|
2649
|
+
gen.assign(valid, false);
|
|
2622
2650
|
}
|
|
2623
|
-
|
|
2651
|
+
gen.else();
|
|
2624
2652
|
}
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2653
|
+
invalid$data() {
|
|
2654
|
+
const { gen, schemaCode, schemaType, def: def2, it } = this;
|
|
2655
|
+
return (0, codegen_12.or)(wrong$DataType(), invalid$DataSchema());
|
|
2656
|
+
function wrong$DataType() {
|
|
2657
|
+
if (schemaType.length) {
|
|
2658
|
+
if (!(schemaCode instanceof codegen_12.Name))
|
|
2659
|
+
throw new Error("ajv implementation error");
|
|
2660
|
+
const st = Array.isArray(schemaType) ? schemaType : [schemaType];
|
|
2661
|
+
return (0, codegen_12._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
|
|
2662
|
+
}
|
|
2663
|
+
return codegen_12.nil;
|
|
2664
|
+
}
|
|
2665
|
+
function invalid$DataSchema() {
|
|
2666
|
+
if (def2.validateSchema) {
|
|
2667
|
+
const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
|
|
2668
|
+
return (0, codegen_12._)`!${validateSchemaRef}(${schemaCode})`;
|
|
2669
|
+
}
|
|
2670
|
+
return codegen_12.nil;
|
|
2629
2671
|
}
|
|
2630
|
-
return codegen_1$r.nil;
|
|
2631
2672
|
}
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2673
|
+
subschema(appl, valid) {
|
|
2674
|
+
const subschema2 = (0, subschema_1.getSubschema)(this.it, appl);
|
|
2675
|
+
(0, subschema_1.extendSubschemaData)(subschema2, this.it, appl);
|
|
2676
|
+
(0, subschema_1.extendSubschemaMode)(subschema2, appl);
|
|
2677
|
+
const nextContext = { ...this.it, ...subschema2, items: void 0, props: void 0 };
|
|
2678
|
+
subschemaCode(nextContext, valid);
|
|
2679
|
+
return nextContext;
|
|
2680
|
+
}
|
|
2681
|
+
mergeEvaluated(schemaCxt, toName) {
|
|
2682
|
+
const { it, gen } = this;
|
|
2683
|
+
if (!it.opts.unevaluated)
|
|
2684
|
+
return;
|
|
2685
|
+
if (it.props !== true && schemaCxt.props !== void 0) {
|
|
2686
|
+
it.props = util_12.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
|
|
2687
|
+
}
|
|
2688
|
+
if (it.items !== true && schemaCxt.items !== void 0) {
|
|
2689
|
+
it.items = util_12.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
|
|
2690
|
+
}
|
|
2647
2691
|
}
|
|
2648
|
-
|
|
2649
|
-
|
|
2692
|
+
mergeValidEvaluated(schemaCxt, valid) {
|
|
2693
|
+
const { it, gen } = this;
|
|
2694
|
+
if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
|
|
2695
|
+
gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_12.Name));
|
|
2696
|
+
return true;
|
|
2697
|
+
}
|
|
2650
2698
|
}
|
|
2651
2699
|
}
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2700
|
+
validate.KeywordCxt = KeywordCxt;
|
|
2701
|
+
function keywordCode(it, keyword2, def2, ruleType) {
|
|
2702
|
+
const cxt = new KeywordCxt(it, def2, keyword2);
|
|
2703
|
+
if ("code" in def2) {
|
|
2704
|
+
def2.code(cxt, ruleType);
|
|
2705
|
+
} else if (cxt.$data && def2.validate) {
|
|
2706
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2707
|
+
} else if ("macro" in def2) {
|
|
2708
|
+
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
2709
|
+
} else if (def2.compile || def2.validate) {
|
|
2710
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
2714
|
+
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
2715
|
+
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
2716
|
+
let jsonPointer;
|
|
2717
|
+
let data;
|
|
2718
|
+
if ($data === "")
|
|
2719
|
+
return names_12.default.rootData;
|
|
2720
|
+
if ($data[0] === "/") {
|
|
2721
|
+
if (!JSON_POINTER.test($data))
|
|
2722
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2723
|
+
jsonPointer = $data;
|
|
2724
|
+
data = names_12.default.rootData;
|
|
2725
|
+
} else {
|
|
2726
|
+
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
2727
|
+
if (!matches)
|
|
2728
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2729
|
+
const up = +matches[1];
|
|
2730
|
+
jsonPointer = matches[2];
|
|
2731
|
+
if (jsonPointer === "#") {
|
|
2732
|
+
if (up >= dataLevel)
|
|
2733
|
+
throw new Error(errorMsg("property/index", up));
|
|
2734
|
+
return dataPathArr[dataLevel - up];
|
|
2735
|
+
}
|
|
2736
|
+
if (up > dataLevel)
|
|
2737
|
+
throw new Error(errorMsg("data", up));
|
|
2738
|
+
data = dataNames[dataLevel - up];
|
|
2739
|
+
if (!jsonPointer)
|
|
2740
|
+
return data;
|
|
2741
|
+
}
|
|
2742
|
+
let expr = data;
|
|
2743
|
+
const segments = jsonPointer.split("/");
|
|
2744
|
+
for (const segment of segments) {
|
|
2745
|
+
if (segment) {
|
|
2746
|
+
data = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)((0, util_12.unescapeJsonPointer)(segment))}`;
|
|
2747
|
+
expr = (0, codegen_12._)`${expr} && ${data}`;
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
2750
|
+
return expr;
|
|
2751
|
+
function errorMsg(pointerType, up) {
|
|
2752
|
+
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
2657
2753
|
}
|
|
2658
2754
|
}
|
|
2755
|
+
validate.getData = getData;
|
|
2756
|
+
return validate;
|
|
2659
2757
|
}
|
|
2660
|
-
validate.KeywordCxt = KeywordCxt;
|
|
2661
|
-
function keywordCode(it, keyword2, def2, ruleType) {
|
|
2662
|
-
const cxt = new KeywordCxt(it, def2, keyword2);
|
|
2663
|
-
if ("code" in def2) {
|
|
2664
|
-
def2.code(cxt, ruleType);
|
|
2665
|
-
} else if (cxt.$data && def2.validate) {
|
|
2666
|
-
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2667
|
-
} else if ("macro" in def2) {
|
|
2668
|
-
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
2669
|
-
} else if (def2.compile || def2.validate) {
|
|
2670
|
-
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2671
|
-
}
|
|
2672
|
-
}
|
|
2673
|
-
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
2674
|
-
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
2675
|
-
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
2676
|
-
let jsonPointer;
|
|
2677
|
-
let data;
|
|
2678
|
-
if ($data === "")
|
|
2679
|
-
return names_1$6.default.rootData;
|
|
2680
|
-
if ($data[0] === "/") {
|
|
2681
|
-
if (!JSON_POINTER.test($data))
|
|
2682
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2683
|
-
jsonPointer = $data;
|
|
2684
|
-
data = names_1$6.default.rootData;
|
|
2685
|
-
} else {
|
|
2686
|
-
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
2687
|
-
if (!matches)
|
|
2688
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2689
|
-
const up = +matches[1];
|
|
2690
|
-
jsonPointer = matches[2];
|
|
2691
|
-
if (jsonPointer === "#") {
|
|
2692
|
-
if (up >= dataLevel)
|
|
2693
|
-
throw new Error(errorMsg("property/index", up));
|
|
2694
|
-
return dataPathArr[dataLevel - up];
|
|
2695
|
-
}
|
|
2696
|
-
if (up > dataLevel)
|
|
2697
|
-
throw new Error(errorMsg("data", up));
|
|
2698
|
-
data = dataNames[dataLevel - up];
|
|
2699
|
-
if (!jsonPointer)
|
|
2700
|
-
return data;
|
|
2701
|
-
}
|
|
2702
|
-
let expr = data;
|
|
2703
|
-
const segments = jsonPointer.split("/");
|
|
2704
|
-
for (const segment of segments) {
|
|
2705
|
-
if (segment) {
|
|
2706
|
-
data = (0, codegen_1$r._)`${data}${(0, codegen_1$r.getProperty)((0, util_1$p.unescapeJsonPointer)(segment))}`;
|
|
2707
|
-
expr = (0, codegen_1$r._)`${expr} && ${data}`;
|
|
2708
|
-
}
|
|
2709
|
-
}
|
|
2710
|
-
return expr;
|
|
2711
|
-
function errorMsg(pointerType, up) {
|
|
2712
|
-
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
2713
|
-
}
|
|
2714
|
-
}
|
|
2715
|
-
validate.getData = getData;
|
|
2716
2758
|
var validation_error = {};
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2759
|
+
var hasRequiredValidation_error;
|
|
2760
|
+
function requireValidation_error() {
|
|
2761
|
+
if (hasRequiredValidation_error) return validation_error;
|
|
2762
|
+
hasRequiredValidation_error = 1;
|
|
2763
|
+
Object.defineProperty(validation_error, "__esModule", { value: true });
|
|
2764
|
+
class ValidationError extends Error {
|
|
2765
|
+
constructor(errors2) {
|
|
2766
|
+
super("validation failed");
|
|
2767
|
+
this.errors = errors2;
|
|
2768
|
+
this.ajv = this.validation = true;
|
|
2769
|
+
}
|
|
2723
2770
|
}
|
|
2771
|
+
validation_error.default = ValidationError;
|
|
2772
|
+
return validation_error;
|
|
2724
2773
|
}
|
|
2725
|
-
validation_error.default = ValidationError;
|
|
2726
2774
|
var ref_error = {};
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2775
|
+
var hasRequiredRef_error;
|
|
2776
|
+
function requireRef_error() {
|
|
2777
|
+
if (hasRequiredRef_error) return ref_error;
|
|
2778
|
+
hasRequiredRef_error = 1;
|
|
2779
|
+
Object.defineProperty(ref_error, "__esModule", { value: true });
|
|
2780
|
+
const resolve_12 = resolve$2;
|
|
2781
|
+
class MissingRefError extends Error {
|
|
2782
|
+
constructor(resolver, baseId, ref2, msg) {
|
|
2783
|
+
super(msg || `can't resolve reference ${ref2} from id ${baseId}`);
|
|
2784
|
+
this.missingRef = (0, resolve_12.resolveUrl)(resolver, baseId, ref2);
|
|
2785
|
+
this.missingSchema = (0, resolve_12.normalizeId)((0, resolve_12.getFullPath)(resolver, this.missingRef));
|
|
2786
|
+
}
|
|
2734
2787
|
}
|
|
2788
|
+
ref_error.default = MissingRefError;
|
|
2789
|
+
return ref_error;
|
|
2735
2790
|
}
|
|
2736
|
-
ref_error.default = MissingRefError;
|
|
2737
2791
|
var compile = {};
|
|
2738
2792
|
Object.defineProperty(compile, "__esModule", { value: true });
|
|
2739
2793
|
compile.resolveSchema = compile.getCompilingSchema = compile.resolveRef = compile.compileSchema = compile.SchemaEnv = void 0;
|
|
2740
|
-
const codegen_1$q =
|
|
2741
|
-
const validation_error_1 =
|
|
2794
|
+
const codegen_1$q = requireCodegen();
|
|
2795
|
+
const validation_error_1 = requireValidation_error();
|
|
2742
2796
|
const names_1$5 = names$1;
|
|
2743
2797
|
const resolve_1 = resolve$2;
|
|
2744
2798
|
const util_1$o = util;
|
|
2745
|
-
const validate_1$1 =
|
|
2799
|
+
const validate_1$1 = requireValidate();
|
|
2746
2800
|
class SchemaEnv {
|
|
2747
2801
|
constructor(env) {
|
|
2748
2802
|
var _a;
|
|
@@ -3671,11 +3725,11 @@ uri$1.default = uri;
|
|
|
3671
3725
|
(function(exports) {
|
|
3672
3726
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3673
3727
|
exports.CodeGen = exports.Name = exports.nil = exports.stringify = exports.str = exports._ = exports.KeywordCxt = void 0;
|
|
3674
|
-
var validate_12 =
|
|
3728
|
+
var validate_12 = requireValidate();
|
|
3675
3729
|
Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function() {
|
|
3676
3730
|
return validate_12.KeywordCxt;
|
|
3677
3731
|
} });
|
|
3678
|
-
var codegen_12 =
|
|
3732
|
+
var codegen_12 = requireCodegen();
|
|
3679
3733
|
Object.defineProperty(exports, "_", { enumerable: true, get: function() {
|
|
3680
3734
|
return codegen_12._;
|
|
3681
3735
|
} });
|
|
@@ -3694,11 +3748,11 @@ uri$1.default = uri;
|
|
|
3694
3748
|
Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function() {
|
|
3695
3749
|
return codegen_12.CodeGen;
|
|
3696
3750
|
} });
|
|
3697
|
-
const validation_error_12 =
|
|
3698
|
-
const ref_error_12 =
|
|
3751
|
+
const validation_error_12 = requireValidation_error();
|
|
3752
|
+
const ref_error_12 = requireRef_error();
|
|
3699
3753
|
const rules_12 = rules;
|
|
3700
3754
|
const compile_12 = compile;
|
|
3701
|
-
const codegen_2 =
|
|
3755
|
+
const codegen_2 = requireCodegen();
|
|
3702
3756
|
const resolve_12 = resolve$2;
|
|
3703
3757
|
const dataType_12 = dataType;
|
|
3704
3758
|
const util_12 = util;
|
|
@@ -4288,9 +4342,9 @@ id.default = def$B;
|
|
|
4288
4342
|
var ref = {};
|
|
4289
4343
|
Object.defineProperty(ref, "__esModule", { value: true });
|
|
4290
4344
|
ref.callRef = ref.getValidate = void 0;
|
|
4291
|
-
const ref_error_1$1 =
|
|
4345
|
+
const ref_error_1$1 = requireRef_error();
|
|
4292
4346
|
const code_1$8 = code;
|
|
4293
|
-
const codegen_1$p =
|
|
4347
|
+
const codegen_1$p = requireCodegen();
|
|
4294
4348
|
const names_1$4 = names$1;
|
|
4295
4349
|
const compile_1$2 = compile;
|
|
4296
4350
|
const util_1$n = util;
|
|
@@ -4418,7 +4472,7 @@ core$2.default = core$1;
|
|
|
4418
4472
|
var validation$2 = {};
|
|
4419
4473
|
var limitNumber = {};
|
|
4420
4474
|
Object.defineProperty(limitNumber, "__esModule", { value: true });
|
|
4421
|
-
const codegen_1$o =
|
|
4475
|
+
const codegen_1$o = requireCodegen();
|
|
4422
4476
|
const ops = codegen_1$o.operators;
|
|
4423
4477
|
const KWDs = {
|
|
4424
4478
|
maximum: { okStr: "<=", ok: ops.LTE, fail: ops.GT },
|
|
@@ -4444,7 +4498,7 @@ const def$z = {
|
|
|
4444
4498
|
limitNumber.default = def$z;
|
|
4445
4499
|
var multipleOf = {};
|
|
4446
4500
|
Object.defineProperty(multipleOf, "__esModule", { value: true });
|
|
4447
|
-
const codegen_1$n =
|
|
4501
|
+
const codegen_1$n = requireCodegen();
|
|
4448
4502
|
const error$j = {
|
|
4449
4503
|
message: ({ schemaCode }) => (0, codegen_1$n.str)`must be multiple of ${schemaCode}`,
|
|
4450
4504
|
params: ({ schemaCode }) => (0, codegen_1$n._)`{multipleOf: ${schemaCode}}`
|
|
@@ -4486,7 +4540,7 @@ function ucs2length(str) {
|
|
|
4486
4540
|
ucs2length$1.default = ucs2length;
|
|
4487
4541
|
ucs2length.code = 'require("ajv/dist/runtime/ucs2length").default';
|
|
4488
4542
|
Object.defineProperty(limitLength, "__esModule", { value: true });
|
|
4489
|
-
const codegen_1$m =
|
|
4543
|
+
const codegen_1$m = requireCodegen();
|
|
4490
4544
|
const util_1$m = util;
|
|
4491
4545
|
const ucs2length_1 = ucs2length$1;
|
|
4492
4546
|
const error$i = {
|
|
@@ -4513,7 +4567,7 @@ limitLength.default = def$x;
|
|
|
4513
4567
|
var pattern = {};
|
|
4514
4568
|
Object.defineProperty(pattern, "__esModule", { value: true });
|
|
4515
4569
|
const code_1$7 = code;
|
|
4516
|
-
const codegen_1$l =
|
|
4570
|
+
const codegen_1$l = requireCodegen();
|
|
4517
4571
|
const error$h = {
|
|
4518
4572
|
message: ({ schemaCode }) => (0, codegen_1$l.str)`must match pattern "${schemaCode}"`,
|
|
4519
4573
|
params: ({ schemaCode }) => (0, codegen_1$l._)`{pattern: ${schemaCode}}`
|
|
@@ -4534,7 +4588,7 @@ const def$w = {
|
|
|
4534
4588
|
pattern.default = def$w;
|
|
4535
4589
|
var limitProperties = {};
|
|
4536
4590
|
Object.defineProperty(limitProperties, "__esModule", { value: true });
|
|
4537
|
-
const codegen_1$k =
|
|
4591
|
+
const codegen_1$k = requireCodegen();
|
|
4538
4592
|
const error$g = {
|
|
4539
4593
|
message({ keyword: keyword2, schemaCode }) {
|
|
4540
4594
|
const comp = keyword2 === "maxProperties" ? "more" : "fewer";
|
|
@@ -4558,7 +4612,7 @@ limitProperties.default = def$v;
|
|
|
4558
4612
|
var required = {};
|
|
4559
4613
|
Object.defineProperty(required, "__esModule", { value: true });
|
|
4560
4614
|
const code_1$6 = code;
|
|
4561
|
-
const codegen_1$j =
|
|
4615
|
+
const codegen_1$j = requireCodegen();
|
|
4562
4616
|
const util_1$l = util;
|
|
4563
4617
|
const error$f = {
|
|
4564
4618
|
message: ({ params: { missingProperty } }) => (0, codegen_1$j.str)`must have required property '${missingProperty}'`,
|
|
@@ -4633,7 +4687,7 @@ const def$u = {
|
|
|
4633
4687
|
required.default = def$u;
|
|
4634
4688
|
var limitItems = {};
|
|
4635
4689
|
Object.defineProperty(limitItems, "__esModule", { value: true });
|
|
4636
|
-
const codegen_1$i =
|
|
4690
|
+
const codegen_1$i = requireCodegen();
|
|
4637
4691
|
const error$e = {
|
|
4638
4692
|
message({ keyword: keyword2, schemaCode }) {
|
|
4639
4693
|
const comp = keyword2 === "maxItems" ? "more" : "fewer";
|
|
@@ -4662,7 +4716,7 @@ equal2.code = 'require("ajv/dist/runtime/equal").default';
|
|
|
4662
4716
|
equal$1.default = equal2;
|
|
4663
4717
|
Object.defineProperty(uniqueItems, "__esModule", { value: true });
|
|
4664
4718
|
const dataType_1 = dataType;
|
|
4665
|
-
const codegen_1$h =
|
|
4719
|
+
const codegen_1$h = requireCodegen();
|
|
4666
4720
|
const util_1$k = util;
|
|
4667
4721
|
const equal_1$2 = equal$1;
|
|
4668
4722
|
const error$d = {
|
|
@@ -4722,7 +4776,7 @@ const def$s = {
|
|
|
4722
4776
|
uniqueItems.default = def$s;
|
|
4723
4777
|
var _const = {};
|
|
4724
4778
|
Object.defineProperty(_const, "__esModule", { value: true });
|
|
4725
|
-
const codegen_1$g =
|
|
4779
|
+
const codegen_1$g = requireCodegen();
|
|
4726
4780
|
const util_1$j = util;
|
|
4727
4781
|
const equal_1$1 = equal$1;
|
|
4728
4782
|
const error$c = {
|
|
@@ -4745,7 +4799,7 @@ const def$r = {
|
|
|
4745
4799
|
_const.default = def$r;
|
|
4746
4800
|
var _enum = {};
|
|
4747
4801
|
Object.defineProperty(_enum, "__esModule", { value: true });
|
|
4748
|
-
const codegen_1$f =
|
|
4802
|
+
const codegen_1$f = requireCodegen();
|
|
4749
4803
|
const util_1$i = util;
|
|
4750
4804
|
const equal_1 = equal$1;
|
|
4751
4805
|
const error$b = {
|
|
@@ -4821,7 +4875,7 @@ var applicator$1 = {};
|
|
|
4821
4875
|
var additionalItems = {};
|
|
4822
4876
|
Object.defineProperty(additionalItems, "__esModule", { value: true });
|
|
4823
4877
|
additionalItems.validateAdditionalItems = void 0;
|
|
4824
|
-
const codegen_1$e =
|
|
4878
|
+
const codegen_1$e = requireCodegen();
|
|
4825
4879
|
const util_1$h = util;
|
|
4826
4880
|
const error$a = {
|
|
4827
4881
|
message: ({ params: { len } }) => (0, codegen_1$e.str)`must NOT have more than ${len} items`,
|
|
@@ -4869,7 +4923,7 @@ var prefixItems = {};
|
|
|
4869
4923
|
var items = {};
|
|
4870
4924
|
Object.defineProperty(items, "__esModule", { value: true });
|
|
4871
4925
|
items.validateTuple = void 0;
|
|
4872
|
-
const codegen_1$d =
|
|
4926
|
+
const codegen_1$d = requireCodegen();
|
|
4873
4927
|
const util_1$g = util;
|
|
4874
4928
|
const code_1$5 = code;
|
|
4875
4929
|
const def$o = {
|
|
@@ -4929,7 +4983,7 @@ const def$n = {
|
|
|
4929
4983
|
prefixItems.default = def$n;
|
|
4930
4984
|
var items2020 = {};
|
|
4931
4985
|
Object.defineProperty(items2020, "__esModule", { value: true });
|
|
4932
|
-
const codegen_1$c =
|
|
4986
|
+
const codegen_1$c = requireCodegen();
|
|
4933
4987
|
const util_1$f = util;
|
|
4934
4988
|
const code_1$4 = code;
|
|
4935
4989
|
const additionalItems_1$1 = additionalItems;
|
|
@@ -4958,7 +5012,7 @@ const def$m = {
|
|
|
4958
5012
|
items2020.default = def$m;
|
|
4959
5013
|
var contains = {};
|
|
4960
5014
|
Object.defineProperty(contains, "__esModule", { value: true });
|
|
4961
|
-
const codegen_1$b =
|
|
5015
|
+
const codegen_1$b = requireCodegen();
|
|
4962
5016
|
const util_1$e = util;
|
|
4963
5017
|
const error$8 = {
|
|
4964
5018
|
message: ({ params: { min, max } }) => max === void 0 ? (0, codegen_1$b.str)`must contain at least ${min} valid item(s)` : (0, codegen_1$b.str)`must contain at least ${min} and no more than ${max} valid item(s)`,
|
|
@@ -5048,7 +5102,7 @@ var dependencies = {};
|
|
|
5048
5102
|
(function(exports) {
|
|
5049
5103
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5050
5104
|
exports.validateSchemaDeps = exports.validatePropertyDeps = exports.error = void 0;
|
|
5051
|
-
const codegen_12 =
|
|
5105
|
+
const codegen_12 = requireCodegen();
|
|
5052
5106
|
const util_12 = util;
|
|
5053
5107
|
const code_12 = code;
|
|
5054
5108
|
exports.error = {
|
|
@@ -5136,7 +5190,7 @@ var dependencies = {};
|
|
|
5136
5190
|
})(dependencies);
|
|
5137
5191
|
var propertyNames = {};
|
|
5138
5192
|
Object.defineProperty(propertyNames, "__esModule", { value: true });
|
|
5139
|
-
const codegen_1$a =
|
|
5193
|
+
const codegen_1$a = requireCodegen();
|
|
5140
5194
|
const util_1$d = util;
|
|
5141
5195
|
const error$7 = {
|
|
5142
5196
|
message: "property name must be valid",
|
|
@@ -5174,7 +5228,7 @@ propertyNames.default = def$k;
|
|
|
5174
5228
|
var additionalProperties = {};
|
|
5175
5229
|
Object.defineProperty(additionalProperties, "__esModule", { value: true });
|
|
5176
5230
|
const code_1$3 = code;
|
|
5177
|
-
const codegen_1$9 =
|
|
5231
|
+
const codegen_1$9 = requireCodegen();
|
|
5178
5232
|
const names_1$3 = names$1;
|
|
5179
5233
|
const util_1$c = util;
|
|
5180
5234
|
const error$6 = {
|
|
@@ -5273,7 +5327,7 @@ const def$j = {
|
|
|
5273
5327
|
additionalProperties.default = def$j;
|
|
5274
5328
|
var properties$7 = {};
|
|
5275
5329
|
Object.defineProperty(properties$7, "__esModule", { value: true });
|
|
5276
|
-
const validate_1 =
|
|
5330
|
+
const validate_1 = requireValidate();
|
|
5277
5331
|
const code_1$2 = code;
|
|
5278
5332
|
const util_1$b = util;
|
|
5279
5333
|
const additionalProperties_1$1 = additionalProperties;
|
|
@@ -5326,7 +5380,7 @@ properties$7.default = def$i;
|
|
|
5326
5380
|
var patternProperties = {};
|
|
5327
5381
|
Object.defineProperty(patternProperties, "__esModule", { value: true });
|
|
5328
5382
|
const code_1$1 = code;
|
|
5329
|
-
const codegen_1$8 =
|
|
5383
|
+
const codegen_1$8 = requireCodegen();
|
|
5330
5384
|
const util_1$a = util;
|
|
5331
5385
|
const util_2 = util;
|
|
5332
5386
|
const def$h = {
|
|
@@ -5429,7 +5483,7 @@ const def$f = {
|
|
|
5429
5483
|
anyOf.default = def$f;
|
|
5430
5484
|
var oneOf = {};
|
|
5431
5485
|
Object.defineProperty(oneOf, "__esModule", { value: true });
|
|
5432
|
-
const codegen_1$7 =
|
|
5486
|
+
const codegen_1$7 = requireCodegen();
|
|
5433
5487
|
const util_1$8 = util;
|
|
5434
5488
|
const error$5 = {
|
|
5435
5489
|
message: "must match exactly one schema in oneOf",
|
|
@@ -5502,7 +5556,7 @@ const def$d = {
|
|
|
5502
5556
|
allOf$1.default = def$d;
|
|
5503
5557
|
var _if = {};
|
|
5504
5558
|
Object.defineProperty(_if, "__esModule", { value: true });
|
|
5505
|
-
const codegen_1$6 =
|
|
5559
|
+
const codegen_1$6 = requireCodegen();
|
|
5506
5560
|
const util_1$6 = util;
|
|
5507
5561
|
const error$4 = {
|
|
5508
5562
|
message: ({ params }) => (0, codegen_1$6.str)`must match "${params.ifClause}" schema`,
|
|
@@ -5619,7 +5673,7 @@ applicator$1.default = getApplicator;
|
|
|
5619
5673
|
var format$3 = {};
|
|
5620
5674
|
var format$2 = {};
|
|
5621
5675
|
Object.defineProperty(format$2, "__esModule", { value: true });
|
|
5622
|
-
const codegen_1$5 =
|
|
5676
|
+
const codegen_1$5 = requireCodegen();
|
|
5623
5677
|
const error$3 = {
|
|
5624
5678
|
message: ({ schemaCode }) => (0, codegen_1$5.str)`must match format "${schemaCode}"`,
|
|
5625
5679
|
params: ({ schemaCode }) => (0, codegen_1$5._)`{format: ${schemaCode}}`
|
|
@@ -5741,7 +5795,7 @@ var dynamic$1 = {};
|
|
|
5741
5795
|
var dynamicAnchor$1 = {};
|
|
5742
5796
|
Object.defineProperty(dynamicAnchor$1, "__esModule", { value: true });
|
|
5743
5797
|
dynamicAnchor$1.dynamicAnchor = void 0;
|
|
5744
|
-
const codegen_1$4 =
|
|
5798
|
+
const codegen_1$4 = requireCodegen();
|
|
5745
5799
|
const names_1$2 = names$1;
|
|
5746
5800
|
const compile_1$1 = compile;
|
|
5747
5801
|
const ref_1$1 = ref;
|
|
@@ -5770,7 +5824,7 @@ dynamicAnchor$1.default = def$9;
|
|
|
5770
5824
|
var dynamicRef$1 = {};
|
|
5771
5825
|
Object.defineProperty(dynamicRef$1, "__esModule", { value: true });
|
|
5772
5826
|
dynamicRef$1.dynamicRef = void 0;
|
|
5773
|
-
const codegen_1$3 =
|
|
5827
|
+
const codegen_1$3 = requireCodegen();
|
|
5774
5828
|
const names_1$1 = names$1;
|
|
5775
5829
|
const ref_1 = ref;
|
|
5776
5830
|
const def$8 = {
|
|
@@ -5883,7 +5937,7 @@ next$1.default = next;
|
|
|
5883
5937
|
var unevaluated$1 = {};
|
|
5884
5938
|
var unevaluatedProperties = {};
|
|
5885
5939
|
Object.defineProperty(unevaluatedProperties, "__esModule", { value: true });
|
|
5886
|
-
const codegen_1$2 =
|
|
5940
|
+
const codegen_1$2 = requireCodegen();
|
|
5887
5941
|
const util_1$2 = util;
|
|
5888
5942
|
const names_1 = names$1;
|
|
5889
5943
|
const error$2 = {
|
|
@@ -5943,7 +5997,7 @@ const def$2 = {
|
|
|
5943
5997
|
unevaluatedProperties.default = def$2;
|
|
5944
5998
|
var unevaluatedItems = {};
|
|
5945
5999
|
Object.defineProperty(unevaluatedItems, "__esModule", { value: true });
|
|
5946
|
-
const codegen_1$1 =
|
|
6000
|
+
const codegen_1$1 = requireCodegen();
|
|
5947
6001
|
const util_1$1 = util;
|
|
5948
6002
|
const error$1 = {
|
|
5949
6003
|
message: ({ params: { len } }) => (0, codegen_1$1.str)`must NOT have more than ${len} items`,
|
|
@@ -5994,10 +6048,10 @@ var DiscrError;
|
|
|
5994
6048
|
DiscrError2["Mapping"] = "mapping";
|
|
5995
6049
|
})(DiscrError || (types.DiscrError = DiscrError = {}));
|
|
5996
6050
|
Object.defineProperty(discriminator, "__esModule", { value: true });
|
|
5997
|
-
const codegen_1 =
|
|
6051
|
+
const codegen_1 = requireCodegen();
|
|
5998
6052
|
const types_1 = types;
|
|
5999
6053
|
const compile_1 = compile;
|
|
6000
|
-
const ref_error_1 =
|
|
6054
|
+
const ref_error_1 = requireRef_error();
|
|
6001
6055
|
const util_1 = util;
|
|
6002
6056
|
const error = {
|
|
6003
6057
|
message: ({ params: { discrError, tagName } }) => discrError === types_1.DiscrError.Tag ? `tag "${tagName}" must be string` : `value of tag "${tagName}" must be in oneOf`,
|
|
@@ -6636,11 +6690,11 @@ jsonSchema201909.default = addMetaSchema2019;
|
|
|
6636
6690
|
module.exports.Ajv2019 = Ajv2019;
|
|
6637
6691
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6638
6692
|
exports.default = Ajv2019;
|
|
6639
|
-
var validate_12 =
|
|
6693
|
+
var validate_12 = requireValidate();
|
|
6640
6694
|
Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function() {
|
|
6641
6695
|
return validate_12.KeywordCxt;
|
|
6642
6696
|
} });
|
|
6643
|
-
var codegen_12 =
|
|
6697
|
+
var codegen_12 = requireCodegen();
|
|
6644
6698
|
Object.defineProperty(exports, "_", { enumerable: true, get: function() {
|
|
6645
6699
|
return codegen_12._;
|
|
6646
6700
|
} });
|
|
@@ -6659,11 +6713,11 @@ jsonSchema201909.default = addMetaSchema2019;
|
|
|
6659
6713
|
Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function() {
|
|
6660
6714
|
return codegen_12.CodeGen;
|
|
6661
6715
|
} });
|
|
6662
|
-
var validation_error_12 =
|
|
6716
|
+
var validation_error_12 = requireValidation_error();
|
|
6663
6717
|
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function() {
|
|
6664
6718
|
return validation_error_12.default;
|
|
6665
6719
|
} });
|
|
6666
|
-
var ref_error_12 =
|
|
6720
|
+
var ref_error_12 = requireRef_error();
|
|
6667
6721
|
Object.defineProperty(exports, "MissingRefError", { enumerable: true, get: function() {
|
|
6668
6722
|
return ref_error_12.default;
|
|
6669
6723
|
} });
|
|
@@ -6677,4 +6731,4 @@ const _2019$1 = /* @__PURE__ */ _mergeNamespaces({
|
|
|
6677
6731
|
export {
|
|
6678
6732
|
_2019$1 as _
|
|
6679
6733
|
};
|
|
6680
|
-
//# sourceMappingURL=2019-
|
|
6734
|
+
//# sourceMappingURL=2019-CLMqIAfQ.js.map
|