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