page-schema-enginer-shun 1.0.20 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +944 -901
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +946 -903
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +944 -901
- package/dist/index.umd.js.map +1 -1
- package/dist/style.css +6 -6
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -244,6 +244,15 @@ const _sfc_main$d = /* @__PURE__ */ vue.defineComponent({
|
|
|
244
244
|
}
|
|
245
245
|
});
|
|
246
246
|
const inputNumber = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["__scopeId", "data-v-87d45394"]]);
|
|
247
|
+
let requestFn = null;
|
|
248
|
+
function setRequestClient(fn) {
|
|
249
|
+
requestFn = fn;
|
|
250
|
+
}
|
|
251
|
+
function request(options) {
|
|
252
|
+
if (!requestFn) throw new Error("请先使用 setRequestClient 注册请求客户端");
|
|
253
|
+
console.log("requestrequestrequest");
|
|
254
|
+
return requestFn(options);
|
|
255
|
+
}
|
|
247
256
|
const _hoisted_1$8 = { class: "schema-form-select-container" };
|
|
248
257
|
const _hoisted_2$2 = { class: "schema-form-select" };
|
|
249
258
|
const _hoisted_3$1 = { class: "schema-form-select-label" };
|
|
@@ -255,20 +264,102 @@ const _sfc_main$c = /* @__PURE__ */ vue.defineComponent({
|
|
|
255
264
|
const selectData = vue.ref();
|
|
256
265
|
const enumerate = vue.ref([]);
|
|
257
266
|
const tip = vue.ref();
|
|
267
|
+
const loading = vue.ref(false);
|
|
268
|
+
const isRemote = vue.computed(() => {
|
|
269
|
+
var _a;
|
|
270
|
+
return !!((_a = __props.schema.option) == null ? void 0 : _a.remote);
|
|
271
|
+
});
|
|
272
|
+
const bindAttrs = vue.computed(() => {
|
|
273
|
+
var _a;
|
|
274
|
+
const defaultProps = {
|
|
275
|
+
placeholder: "请选择",
|
|
276
|
+
clearable: true
|
|
277
|
+
};
|
|
278
|
+
if ((_a = __props.schema.option) == null ? void 0 : _a.props) {
|
|
279
|
+
return { ...defaultProps, ...__props.schema.option.props };
|
|
280
|
+
}
|
|
281
|
+
const { api, enumList, default: def2, remote, ...rest } = __props.schema.option || {};
|
|
282
|
+
return {
|
|
283
|
+
...defaultProps,
|
|
284
|
+
...rest
|
|
285
|
+
};
|
|
286
|
+
});
|
|
258
287
|
vue.watch(
|
|
259
288
|
() => __props.model,
|
|
260
289
|
() => {
|
|
261
|
-
|
|
290
|
+
var _a;
|
|
291
|
+
if (!loading.value) {
|
|
292
|
+
selectData.value = __props.model ?? ((_a = __props.schema.option) == null ? void 0 : _a.default);
|
|
293
|
+
}
|
|
262
294
|
}
|
|
263
295
|
);
|
|
264
296
|
const getValue = () => {
|
|
265
297
|
return selectData.value !== void 0 ? { [__props.ItemKey]: selectData.value } : {};
|
|
266
298
|
};
|
|
267
|
-
const
|
|
299
|
+
const fetchOptions = async (query = "") => {
|
|
268
300
|
var _a, _b;
|
|
301
|
+
const apiConfig = (_a = __props.schema.option) == null ? void 0 : _a.api;
|
|
302
|
+
if (!apiConfig || !apiConfig.url) return;
|
|
303
|
+
loading.value = true;
|
|
304
|
+
try {
|
|
305
|
+
const params = { ...apiConfig.params || {} };
|
|
306
|
+
if (isRemote.value) {
|
|
307
|
+
const searchKey = apiConfig.searchKey || "keyword";
|
|
308
|
+
params[searchKey] = query;
|
|
309
|
+
}
|
|
310
|
+
const res = await request({
|
|
311
|
+
url: apiConfig.url,
|
|
312
|
+
method: apiConfig.method || "get",
|
|
313
|
+
params: apiConfig.method === "post" ? void 0 : params,
|
|
314
|
+
data: apiConfig.method === "post" ? params : void 0
|
|
315
|
+
});
|
|
316
|
+
let list = [];
|
|
317
|
+
if (Array.isArray(res)) {
|
|
318
|
+
list = res;
|
|
319
|
+
} else if ((res == null ? void 0 : res.data) && Array.isArray(res.data)) {
|
|
320
|
+
list = res.data;
|
|
321
|
+
} else if (((_b = res == null ? void 0 : res.data) == null ? void 0 : _b.list) && Array.isArray(res.data.list)) {
|
|
322
|
+
list = res.data.list;
|
|
323
|
+
} else if ((res == null ? void 0 : res.list) && Array.isArray(res.list)) {
|
|
324
|
+
list = res.list;
|
|
325
|
+
}
|
|
326
|
+
const labelKey = apiConfig.labelKey || "label";
|
|
327
|
+
const valueKey = apiConfig.valueKey || "value";
|
|
328
|
+
enumerate.value = list.map((item) => ({
|
|
329
|
+
label: item[labelKey],
|
|
330
|
+
value: item[valueKey],
|
|
331
|
+
original: item
|
|
332
|
+
}));
|
|
333
|
+
} catch (error2) {
|
|
334
|
+
console.error("Select options load failed:", error2);
|
|
335
|
+
elementPlus.ElMessage.error(error2.message || "加载选项数据失败");
|
|
336
|
+
enumerate.value = [];
|
|
337
|
+
} finally {
|
|
338
|
+
loading.value = false;
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
let timer = null;
|
|
342
|
+
const remoteMethod = (query) => {
|
|
343
|
+
if (timer) clearTimeout(timer);
|
|
344
|
+
timer = setTimeout(() => {
|
|
345
|
+
fetchOptions(query);
|
|
346
|
+
}, 300);
|
|
347
|
+
};
|
|
348
|
+
const handleFocus = () => {
|
|
349
|
+
var _a;
|
|
350
|
+
if (!isRemote.value && ((_a = __props.schema.option) == null ? void 0 : _a.api) && enumerate.value.length === 0) {
|
|
351
|
+
fetchOptions();
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
const buildData = async () => {
|
|
355
|
+
var _a, _b, _c;
|
|
269
356
|
tip.value = null;
|
|
270
|
-
|
|
271
|
-
|
|
357
|
+
selectData.value = __props.model ?? ((_a = __props.schema.option) == null ? void 0 : _a.default);
|
|
358
|
+
if ((_b = __props.schema.option) == null ? void 0 : _b.api) {
|
|
359
|
+
await fetchOptions("");
|
|
360
|
+
} else {
|
|
361
|
+
enumerate.value = ((_c = __props.schema.option) == null ? void 0 : _c.enumList) || [];
|
|
362
|
+
}
|
|
272
363
|
};
|
|
273
364
|
const valid = () => {
|
|
274
365
|
if (selectData.value !== void 0) {
|
|
@@ -292,11 +383,14 @@ const _sfc_main$c = /* @__PURE__ */ vue.defineComponent({
|
|
|
292
383
|
return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$8, [
|
|
293
384
|
vue.createElementVNode("div", _hoisted_2$2, [
|
|
294
385
|
vue.createElementVNode("span", _hoisted_3$1, vue.toDisplayString(__props.schema.label), 1),
|
|
295
|
-
vue.createVNode(vue.unref(elementPlus.ElSelect), {
|
|
386
|
+
vue.createVNode(vue.unref(elementPlus.ElSelect), vue.mergeProps(bindAttrs.value, {
|
|
296
387
|
modelValue: selectData.value,
|
|
297
388
|
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => selectData.value = $event),
|
|
298
|
-
|
|
299
|
-
|
|
389
|
+
remote: isRemote.value,
|
|
390
|
+
filterable: isRemote.value || bindAttrs.value.filterable,
|
|
391
|
+
"remote-method": remoteMethod,
|
|
392
|
+
onFocus: handleFocus
|
|
393
|
+
}), {
|
|
300
394
|
default: vue.withCtx(() => [
|
|
301
395
|
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(enumerate.value, (item) => {
|
|
302
396
|
return vue.openBlock(), vue.createBlock(vue.unref(elementPlus.ElOption), {
|
|
@@ -307,14 +401,14 @@ const _sfc_main$c = /* @__PURE__ */ vue.defineComponent({
|
|
|
307
401
|
}), 128))
|
|
308
402
|
]),
|
|
309
403
|
_: 1
|
|
310
|
-
},
|
|
404
|
+
}, 16, ["modelValue", "remote", "filterable"]),
|
|
311
405
|
tip.value ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_4, vue.toDisplayString(tip.value), 1)) : vue.createCommentVNode("", true)
|
|
312
406
|
])
|
|
313
407
|
]);
|
|
314
408
|
};
|
|
315
409
|
}
|
|
316
410
|
});
|
|
317
|
-
const select = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["__scopeId", "data-v-
|
|
411
|
+
const select = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["__scopeId", "data-v-97c33367"]]);
|
|
318
412
|
const formItemConfig = {
|
|
319
413
|
input: {
|
|
320
414
|
component: input
|
|
@@ -1347,8 +1441,8 @@ var scope = {};
|
|
|
1347
1441
|
var util = {};
|
|
1348
1442
|
Object.defineProperty(util, "__esModule", { value: true });
|
|
1349
1443
|
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;
|
|
1350
|
-
const codegen_1$
|
|
1351
|
-
const code_1$
|
|
1444
|
+
const codegen_1$v = codegen;
|
|
1445
|
+
const code_1$a = code$1;
|
|
1352
1446
|
function toHash(arr) {
|
|
1353
1447
|
const hash = {};
|
|
1354
1448
|
for (const item of arr)
|
|
@@ -1401,9 +1495,9 @@ function schemaRefOrVal({ topSchemaRef, schemaPath }, schema, keyword2, $data) {
|
|
|
1401
1495
|
if (typeof schema == "number" || typeof schema == "boolean")
|
|
1402
1496
|
return schema;
|
|
1403
1497
|
if (typeof schema == "string")
|
|
1404
|
-
return (0, codegen_1$
|
|
1498
|
+
return (0, codegen_1$v._)`${schema}`;
|
|
1405
1499
|
}
|
|
1406
|
-
return (0, codegen_1$
|
|
1500
|
+
return (0, codegen_1$v._)`${topSchemaRef}${schemaPath}${(0, codegen_1$v.getProperty)(keyword2)}`;
|
|
1407
1501
|
}
|
|
1408
1502
|
util.schemaRefOrVal = schemaRefOrVal;
|
|
1409
1503
|
function unescapeFragment(str) {
|
|
@@ -1435,20 +1529,20 @@ function eachItem(xs, f) {
|
|
|
1435
1529
|
util.eachItem = eachItem;
|
|
1436
1530
|
function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues, resultToName }) {
|
|
1437
1531
|
return (gen, from, to, toName) => {
|
|
1438
|
-
const res = to === void 0 ? from : to instanceof codegen_1$
|
|
1439
|
-
return toName === codegen_1$
|
|
1532
|
+
const res = to === void 0 ? from : to instanceof codegen_1$v.Name ? (from instanceof codegen_1$v.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1$v.Name ? (mergeToName(gen, to, from), from) : mergeValues(from, to);
|
|
1533
|
+
return toName === codegen_1$v.Name && !(res instanceof codegen_1$v.Name) ? resultToName(gen, res) : res;
|
|
1440
1534
|
};
|
|
1441
1535
|
}
|
|
1442
1536
|
util.mergeEvaluated = {
|
|
1443
1537
|
props: makeMergeEvaluated({
|
|
1444
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
1445
|
-
gen.if((0, codegen_1$
|
|
1538
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$v._)`${to} !== true && ${from} !== undefined`, () => {
|
|
1539
|
+
gen.if((0, codegen_1$v._)`${from} === true`, () => gen.assign(to, true), () => gen.assign(to, (0, codegen_1$v._)`${to} || {}`).code((0, codegen_1$v._)`Object.assign(${to}, ${from})`));
|
|
1446
1540
|
}),
|
|
1447
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
1541
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$v._)`${to} !== true`, () => {
|
|
1448
1542
|
if (from === true) {
|
|
1449
1543
|
gen.assign(to, true);
|
|
1450
1544
|
} else {
|
|
1451
|
-
gen.assign(to, (0, codegen_1$
|
|
1545
|
+
gen.assign(to, (0, codegen_1$v._)`${to} || {}`);
|
|
1452
1546
|
setEvaluated(gen, to, from);
|
|
1453
1547
|
}
|
|
1454
1548
|
}),
|
|
@@ -1456,8 +1550,8 @@ util.mergeEvaluated = {
|
|
|
1456
1550
|
resultToName: evaluatedPropsToName
|
|
1457
1551
|
}),
|
|
1458
1552
|
items: makeMergeEvaluated({
|
|
1459
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
1460
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
1553
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$v._)`${to} !== true && ${from} !== undefined`, () => gen.assign(to, (0, codegen_1$v._)`${from} === true ? true : ${to} > ${from} ? ${to} : ${from}`)),
|
|
1554
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$v._)`${to} !== true`, () => gen.assign(to, from === true ? true : (0, codegen_1$v._)`${to} > ${from} ? ${to} : ${from}`)),
|
|
1461
1555
|
mergeValues: (from, to) => from === true ? true : Math.max(from, to),
|
|
1462
1556
|
resultToName: (gen, items2) => gen.var("items", items2)
|
|
1463
1557
|
})
|
|
@@ -1465,21 +1559,21 @@ util.mergeEvaluated = {
|
|
|
1465
1559
|
function evaluatedPropsToName(gen, ps) {
|
|
1466
1560
|
if (ps === true)
|
|
1467
1561
|
return gen.var("props", true);
|
|
1468
|
-
const props = gen.var("props", (0, codegen_1$
|
|
1562
|
+
const props = gen.var("props", (0, codegen_1$v._)`{}`);
|
|
1469
1563
|
if (ps !== void 0)
|
|
1470
1564
|
setEvaluated(gen, props, ps);
|
|
1471
1565
|
return props;
|
|
1472
1566
|
}
|
|
1473
1567
|
util.evaluatedPropsToName = evaluatedPropsToName;
|
|
1474
1568
|
function setEvaluated(gen, props, ps) {
|
|
1475
|
-
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$
|
|
1569
|
+
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$v._)`${props}${(0, codegen_1$v.getProperty)(p)}`, true));
|
|
1476
1570
|
}
|
|
1477
1571
|
util.setEvaluated = setEvaluated;
|
|
1478
1572
|
const snippets = {};
|
|
1479
1573
|
function useFunc(gen, f) {
|
|
1480
1574
|
return gen.scopeValue("func", {
|
|
1481
1575
|
ref: f,
|
|
1482
|
-
code: snippets[f.code] || (snippets[f.code] = new code_1$
|
|
1576
|
+
code: snippets[f.code] || (snippets[f.code] = new code_1$a._Code(f.code))
|
|
1483
1577
|
});
|
|
1484
1578
|
}
|
|
1485
1579
|
util.useFunc = useFunc;
|
|
@@ -1489,11 +1583,11 @@ var Type;
|
|
|
1489
1583
|
Type2[Type2["Str"] = 1] = "Str";
|
|
1490
1584
|
})(Type || (util.Type = Type = {}));
|
|
1491
1585
|
function getErrorPath(dataProp, dataPropType, jsPropertySyntax) {
|
|
1492
|
-
if (dataProp instanceof codegen_1$
|
|
1586
|
+
if (dataProp instanceof codegen_1$v.Name) {
|
|
1493
1587
|
const isNumber = dataPropType === Type.Num;
|
|
1494
|
-
return jsPropertySyntax ? isNumber ? (0, codegen_1$
|
|
1588
|
+
return jsPropertySyntax ? isNumber ? (0, codegen_1$v._)`"[" + ${dataProp} + "]"` : (0, codegen_1$v._)`"['" + ${dataProp} + "']"` : isNumber ? (0, codegen_1$v._)`"/" + ${dataProp}` : (0, codegen_1$v._)`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")`;
|
|
1495
1589
|
}
|
|
1496
|
-
return jsPropertySyntax ? (0, codegen_1$
|
|
1590
|
+
return jsPropertySyntax ? (0, codegen_1$v.getProperty)(dataProp).toString() : "/" + escapeJsonPointer(dataProp);
|
|
1497
1591
|
}
|
|
1498
1592
|
util.getErrorPath = getErrorPath;
|
|
1499
1593
|
function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
@@ -1505,51 +1599,45 @@ function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
|
1505
1599
|
it.self.logger.warn(msg);
|
|
1506
1600
|
}
|
|
1507
1601
|
util.checkStrictMode = checkStrictMode;
|
|
1508
|
-
var names = {};
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
jsonLen: new codegen_12.Name("jsonLen"),
|
|
1542
|
-
jsonPart: new codegen_12.Name("jsonPart")
|
|
1543
|
-
};
|
|
1544
|
-
names.default = names$1;
|
|
1545
|
-
return names;
|
|
1546
|
-
}
|
|
1602
|
+
var names$1 = {};
|
|
1603
|
+
Object.defineProperty(names$1, "__esModule", { value: true });
|
|
1604
|
+
const codegen_1$u = codegen;
|
|
1605
|
+
const names = {
|
|
1606
|
+
// validation function arguments
|
|
1607
|
+
data: new codegen_1$u.Name("data"),
|
|
1608
|
+
// data passed to validation function
|
|
1609
|
+
// args passed from referencing schema
|
|
1610
|
+
valCxt: new codegen_1$u.Name("valCxt"),
|
|
1611
|
+
// validation/data context - should not be used directly, it is destructured to the names below
|
|
1612
|
+
instancePath: new codegen_1$u.Name("instancePath"),
|
|
1613
|
+
parentData: new codegen_1$u.Name("parentData"),
|
|
1614
|
+
parentDataProperty: new codegen_1$u.Name("parentDataProperty"),
|
|
1615
|
+
rootData: new codegen_1$u.Name("rootData"),
|
|
1616
|
+
// root data - same as the data passed to the first/top validation function
|
|
1617
|
+
dynamicAnchors: new codegen_1$u.Name("dynamicAnchors"),
|
|
1618
|
+
// used to support recursiveRef and dynamicRef
|
|
1619
|
+
// function scoped variables
|
|
1620
|
+
vErrors: new codegen_1$u.Name("vErrors"),
|
|
1621
|
+
// null or array of validation errors
|
|
1622
|
+
errors: new codegen_1$u.Name("errors"),
|
|
1623
|
+
// counter of validation errors
|
|
1624
|
+
this: new codegen_1$u.Name("this"),
|
|
1625
|
+
// "globals"
|
|
1626
|
+
self: new codegen_1$u.Name("self"),
|
|
1627
|
+
scope: new codegen_1$u.Name("scope"),
|
|
1628
|
+
// JTD serialize/parse name for JSON string and position
|
|
1629
|
+
json: new codegen_1$u.Name("json"),
|
|
1630
|
+
jsonPos: new codegen_1$u.Name("jsonPos"),
|
|
1631
|
+
jsonLen: new codegen_1$u.Name("jsonLen"),
|
|
1632
|
+
jsonPart: new codegen_1$u.Name("jsonPart")
|
|
1633
|
+
};
|
|
1634
|
+
names$1.default = names;
|
|
1547
1635
|
(function(exports$1) {
|
|
1548
1636
|
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
1549
1637
|
exports$1.extendErrors = exports$1.resetErrorsCount = exports$1.reportExtraError = exports$1.reportError = exports$1.keyword$DataError = exports$1.keywordError = void 0;
|
|
1550
1638
|
const codegen_12 = codegen;
|
|
1551
1639
|
const util_12 = util;
|
|
1552
|
-
const names_12 =
|
|
1640
|
+
const names_12 = names$1;
|
|
1553
1641
|
exports$1.keywordError = {
|
|
1554
1642
|
message: ({ keyword: keyword2 }) => (0, codegen_12.str)`must pass "${keyword2}" keyword validation`
|
|
1555
1643
|
};
|
|
@@ -1661,55 +1749,49 @@ function requireNames() {
|
|
|
1661
1749
|
keyValues.push([E.propertyName, propertyName]);
|
|
1662
1750
|
}
|
|
1663
1751
|
})(errors);
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
const
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
gen.return(names_12.default.data);
|
|
1682
|
-
} else {
|
|
1683
|
-
gen.assign((0, codegen_12._)`${validateName}.errors`, null);
|
|
1684
|
-
gen.return(true);
|
|
1685
|
-
}
|
|
1752
|
+
Object.defineProperty(boolSchema, "__esModule", { value: true });
|
|
1753
|
+
boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
|
|
1754
|
+
const errors_1$3 = errors;
|
|
1755
|
+
const codegen_1$t = codegen;
|
|
1756
|
+
const names_1$6 = names$1;
|
|
1757
|
+
const boolError = {
|
|
1758
|
+
message: "boolean schema is false"
|
|
1759
|
+
};
|
|
1760
|
+
function topBoolOrEmptySchema(it) {
|
|
1761
|
+
const { gen, schema, validateName } = it;
|
|
1762
|
+
if (schema === false) {
|
|
1763
|
+
falseSchemaError(it, false);
|
|
1764
|
+
} else if (typeof schema == "object" && schema.$async === true) {
|
|
1765
|
+
gen.return(names_1$6.default.data);
|
|
1766
|
+
} else {
|
|
1767
|
+
gen.assign((0, codegen_1$t._)`${validateName}.errors`, null);
|
|
1768
|
+
gen.return(true);
|
|
1686
1769
|
}
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
}
|
|
1697
|
-
boolSchema.boolOrEmptySchema = boolOrEmptySchema;
|
|
1698
|
-
function falseSchemaError(it, overrideAllErrors) {
|
|
1699
|
-
const { gen, data } = it;
|
|
1700
|
-
const cxt = {
|
|
1701
|
-
gen,
|
|
1702
|
-
keyword: "false schema",
|
|
1703
|
-
data,
|
|
1704
|
-
schema: false,
|
|
1705
|
-
schemaCode: false,
|
|
1706
|
-
schemaValue: false,
|
|
1707
|
-
params: {},
|
|
1708
|
-
it
|
|
1709
|
-
};
|
|
1710
|
-
(0, errors_12.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
1770
|
+
}
|
|
1771
|
+
boolSchema.topBoolOrEmptySchema = topBoolOrEmptySchema;
|
|
1772
|
+
function boolOrEmptySchema(it, valid) {
|
|
1773
|
+
const { gen, schema } = it;
|
|
1774
|
+
if (schema === false) {
|
|
1775
|
+
gen.var(valid, false);
|
|
1776
|
+
falseSchemaError(it);
|
|
1777
|
+
} else {
|
|
1778
|
+
gen.var(valid, true);
|
|
1711
1779
|
}
|
|
1712
|
-
|
|
1780
|
+
}
|
|
1781
|
+
boolSchema.boolOrEmptySchema = boolOrEmptySchema;
|
|
1782
|
+
function falseSchemaError(it, overrideAllErrors) {
|
|
1783
|
+
const { gen, data } = it;
|
|
1784
|
+
const cxt = {
|
|
1785
|
+
gen,
|
|
1786
|
+
keyword: "false schema",
|
|
1787
|
+
data,
|
|
1788
|
+
schema: false,
|
|
1789
|
+
schemaCode: false,
|
|
1790
|
+
schemaValue: false,
|
|
1791
|
+
params: {},
|
|
1792
|
+
it
|
|
1793
|
+
};
|
|
1794
|
+
(0, errors_1$3.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
1713
1795
|
}
|
|
1714
1796
|
var dataType = {};
|
|
1715
1797
|
var rules = {};
|
|
@@ -1757,10 +1839,10 @@ applicability.shouldUseRule = shouldUseRule;
|
|
|
1757
1839
|
Object.defineProperty(dataType, "__esModule", { value: true });
|
|
1758
1840
|
dataType.reportTypeError = dataType.checkDataTypes = dataType.checkDataType = dataType.coerceAndCheckDataType = dataType.getJSONTypes = dataType.getSchemaTypes = dataType.DataType = void 0;
|
|
1759
1841
|
const rules_1 = rules;
|
|
1760
|
-
const applicability_1 = applicability;
|
|
1761
|
-
const errors_1 = errors;
|
|
1762
|
-
const codegen_1$
|
|
1763
|
-
const util_1$
|
|
1842
|
+
const applicability_1$1 = applicability;
|
|
1843
|
+
const errors_1$2 = errors;
|
|
1844
|
+
const codegen_1$s = codegen;
|
|
1845
|
+
const util_1$q = util;
|
|
1764
1846
|
var DataType;
|
|
1765
1847
|
(function(DataType2) {
|
|
1766
1848
|
DataType2[DataType2["Correct"] = 0] = "Correct";
|
|
@@ -1792,7 +1874,7 @@ dataType.getJSONTypes = getJSONTypes;
|
|
|
1792
1874
|
function coerceAndCheckDataType(it, types2) {
|
|
1793
1875
|
const { gen, data, opts } = it;
|
|
1794
1876
|
const coerceTo = coerceToTypes(types2, opts.coerceTypes);
|
|
1795
|
-
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1.schemaHasRulesForType)(it, types2[0]));
|
|
1877
|
+
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1$1.schemaHasRulesForType)(it, types2[0]));
|
|
1796
1878
|
if (checkTypes) {
|
|
1797
1879
|
const wrongType = checkDataTypes(types2, data, opts.strictNumbers, DataType.Wrong);
|
|
1798
1880
|
gen.if(wrongType, () => {
|
|
@@ -1811,12 +1893,12 @@ function coerceToTypes(types2, coerceTypes) {
|
|
|
1811
1893
|
}
|
|
1812
1894
|
function coerceData(it, types2, coerceTo) {
|
|
1813
1895
|
const { gen, data, opts } = it;
|
|
1814
|
-
const dataType2 = gen.let("dataType", (0, codegen_1$
|
|
1815
|
-
const coerced = gen.let("coerced", (0, codegen_1$
|
|
1896
|
+
const dataType2 = gen.let("dataType", (0, codegen_1$s._)`typeof ${data}`);
|
|
1897
|
+
const coerced = gen.let("coerced", (0, codegen_1$s._)`undefined`);
|
|
1816
1898
|
if (opts.coerceTypes === "array") {
|
|
1817
|
-
gen.if((0, codegen_1$
|
|
1899
|
+
gen.if((0, codegen_1$s._)`${dataType2} == 'object' && Array.isArray(${data}) && ${data}.length == 1`, () => gen.assign(data, (0, codegen_1$s._)`${data}[0]`).assign(dataType2, (0, codegen_1$s._)`typeof ${data}`).if(checkDataTypes(types2, data, opts.strictNumbers), () => gen.assign(coerced, data)));
|
|
1818
1900
|
}
|
|
1819
|
-
gen.if((0, codegen_1$
|
|
1901
|
+
gen.if((0, codegen_1$s._)`${coerced} !== undefined`);
|
|
1820
1902
|
for (const t of coerceTo) {
|
|
1821
1903
|
if (COERCIBLE.has(t) || t === "array" && opts.coerceTypes === "array") {
|
|
1822
1904
|
coerceSpecificType(t);
|
|
@@ -1825,63 +1907,63 @@ function coerceData(it, types2, coerceTo) {
|
|
|
1825
1907
|
gen.else();
|
|
1826
1908
|
reportTypeError(it);
|
|
1827
1909
|
gen.endIf();
|
|
1828
|
-
gen.if((0, codegen_1$
|
|
1910
|
+
gen.if((0, codegen_1$s._)`${coerced} !== undefined`, () => {
|
|
1829
1911
|
gen.assign(data, coerced);
|
|
1830
1912
|
assignParentData(it, coerced);
|
|
1831
1913
|
});
|
|
1832
1914
|
function coerceSpecificType(t) {
|
|
1833
1915
|
switch (t) {
|
|
1834
1916
|
case "string":
|
|
1835
|
-
gen.elseIf((0, codegen_1$
|
|
1917
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} == "number" || ${dataType2} == "boolean"`).assign(coerced, (0, codegen_1$s._)`"" + ${data}`).elseIf((0, codegen_1$s._)`${data} === null`).assign(coerced, (0, codegen_1$s._)`""`);
|
|
1836
1918
|
return;
|
|
1837
1919
|
case "number":
|
|
1838
|
-
gen.elseIf((0, codegen_1$
|
|
1839
|
-
|| (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$
|
|
1920
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} == "boolean" || ${data} === null
|
|
1921
|
+
|| (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$s._)`+${data}`);
|
|
1840
1922
|
return;
|
|
1841
1923
|
case "integer":
|
|
1842
|
-
gen.elseIf((0, codegen_1$
|
|
1843
|
-
|| (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$
|
|
1924
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} === "boolean" || ${data} === null
|
|
1925
|
+
|| (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$s._)`+${data}`);
|
|
1844
1926
|
return;
|
|
1845
1927
|
case "boolean":
|
|
1846
|
-
gen.elseIf((0, codegen_1$
|
|
1928
|
+
gen.elseIf((0, codegen_1$s._)`${data} === "false" || ${data} === 0 || ${data} === null`).assign(coerced, false).elseIf((0, codegen_1$s._)`${data} === "true" || ${data} === 1`).assign(coerced, true);
|
|
1847
1929
|
return;
|
|
1848
1930
|
case "null":
|
|
1849
|
-
gen.elseIf((0, codegen_1$
|
|
1931
|
+
gen.elseIf((0, codegen_1$s._)`${data} === "" || ${data} === 0 || ${data} === false`);
|
|
1850
1932
|
gen.assign(coerced, null);
|
|
1851
1933
|
return;
|
|
1852
1934
|
case "array":
|
|
1853
|
-
gen.elseIf((0, codegen_1$
|
|
1854
|
-
|| ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$
|
|
1935
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} === "string" || ${dataType2} === "number"
|
|
1936
|
+
|| ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$s._)`[${data}]`);
|
|
1855
1937
|
}
|
|
1856
1938
|
}
|
|
1857
1939
|
}
|
|
1858
1940
|
function assignParentData({ gen, parentData, parentDataProperty }, expr) {
|
|
1859
|
-
gen.if((0, codegen_1$
|
|
1941
|
+
gen.if((0, codegen_1$s._)`${parentData} !== undefined`, () => gen.assign((0, codegen_1$s._)`${parentData}[${parentDataProperty}]`, expr));
|
|
1860
1942
|
}
|
|
1861
1943
|
function checkDataType(dataType2, data, strictNums, correct = DataType.Correct) {
|
|
1862
|
-
const EQ = correct === DataType.Correct ? codegen_1$
|
|
1944
|
+
const EQ = correct === DataType.Correct ? codegen_1$s.operators.EQ : codegen_1$s.operators.NEQ;
|
|
1863
1945
|
let cond;
|
|
1864
1946
|
switch (dataType2) {
|
|
1865
1947
|
case "null":
|
|
1866
|
-
return (0, codegen_1$
|
|
1948
|
+
return (0, codegen_1$s._)`${data} ${EQ} null`;
|
|
1867
1949
|
case "array":
|
|
1868
|
-
cond = (0, codegen_1$
|
|
1950
|
+
cond = (0, codegen_1$s._)`Array.isArray(${data})`;
|
|
1869
1951
|
break;
|
|
1870
1952
|
case "object":
|
|
1871
|
-
cond = (0, codegen_1$
|
|
1953
|
+
cond = (0, codegen_1$s._)`${data} && typeof ${data} == "object" && !Array.isArray(${data})`;
|
|
1872
1954
|
break;
|
|
1873
1955
|
case "integer":
|
|
1874
|
-
cond = numCond((0, codegen_1$
|
|
1956
|
+
cond = numCond((0, codegen_1$s._)`!(${data} % 1) && !isNaN(${data})`);
|
|
1875
1957
|
break;
|
|
1876
1958
|
case "number":
|
|
1877
1959
|
cond = numCond();
|
|
1878
1960
|
break;
|
|
1879
1961
|
default:
|
|
1880
|
-
return (0, codegen_1$
|
|
1962
|
+
return (0, codegen_1$s._)`typeof ${data} ${EQ} ${dataType2}`;
|
|
1881
1963
|
}
|
|
1882
|
-
return correct === DataType.Correct ? cond : (0, codegen_1$
|
|
1883
|
-
function numCond(_cond = codegen_1$
|
|
1884
|
-
return (0, codegen_1$
|
|
1964
|
+
return correct === DataType.Correct ? cond : (0, codegen_1$s.not)(cond);
|
|
1965
|
+
function numCond(_cond = codegen_1$s.nil) {
|
|
1966
|
+
return (0, codegen_1$s.and)((0, codegen_1$s._)`typeof ${data} == "number"`, _cond, strictNums ? (0, codegen_1$s._)`isFinite(${data})` : codegen_1$s.nil);
|
|
1885
1967
|
}
|
|
1886
1968
|
}
|
|
1887
1969
|
dataType.checkDataType = checkDataType;
|
|
@@ -1890,35 +1972,35 @@ function checkDataTypes(dataTypes, data, strictNums, correct) {
|
|
|
1890
1972
|
return checkDataType(dataTypes[0], data, strictNums, correct);
|
|
1891
1973
|
}
|
|
1892
1974
|
let cond;
|
|
1893
|
-
const types2 = (0, util_1$
|
|
1975
|
+
const types2 = (0, util_1$q.toHash)(dataTypes);
|
|
1894
1976
|
if (types2.array && types2.object) {
|
|
1895
|
-
const notObj = (0, codegen_1$
|
|
1896
|
-
cond = types2.null ? notObj : (0, codegen_1$
|
|
1977
|
+
const notObj = (0, codegen_1$s._)`typeof ${data} != "object"`;
|
|
1978
|
+
cond = types2.null ? notObj : (0, codegen_1$s._)`!${data} || ${notObj}`;
|
|
1897
1979
|
delete types2.null;
|
|
1898
1980
|
delete types2.array;
|
|
1899
1981
|
delete types2.object;
|
|
1900
1982
|
} else {
|
|
1901
|
-
cond = codegen_1$
|
|
1983
|
+
cond = codegen_1$s.nil;
|
|
1902
1984
|
}
|
|
1903
1985
|
if (types2.number)
|
|
1904
1986
|
delete types2.integer;
|
|
1905
1987
|
for (const t in types2)
|
|
1906
|
-
cond = (0, codegen_1$
|
|
1988
|
+
cond = (0, codegen_1$s.and)(cond, checkDataType(t, data, strictNums, correct));
|
|
1907
1989
|
return cond;
|
|
1908
1990
|
}
|
|
1909
1991
|
dataType.checkDataTypes = checkDataTypes;
|
|
1910
1992
|
const typeError = {
|
|
1911
1993
|
message: ({ schema }) => `must be ${schema}`,
|
|
1912
|
-
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$
|
|
1994
|
+
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$s._)`{type: ${schema}}` : (0, codegen_1$s._)`{type: ${schemaValue}}`
|
|
1913
1995
|
};
|
|
1914
1996
|
function reportTypeError(it) {
|
|
1915
1997
|
const cxt = getTypeErrorContext(it);
|
|
1916
|
-
(0, errors_1.reportError)(cxt, typeError);
|
|
1998
|
+
(0, errors_1$2.reportError)(cxt, typeError);
|
|
1917
1999
|
}
|
|
1918
2000
|
dataType.reportTypeError = reportTypeError;
|
|
1919
2001
|
function getTypeErrorContext(it) {
|
|
1920
2002
|
const { gen, data, schema } = it;
|
|
1921
|
-
const schemaCode = (0, util_1$
|
|
2003
|
+
const schemaCode = (0, util_1$q.schemaRefOrVal)(it, schema, "type");
|
|
1922
2004
|
return {
|
|
1923
2005
|
gen,
|
|
1924
2006
|
keyword: "type",
|
|
@@ -1932,60 +2014,54 @@ function getTypeErrorContext(it) {
|
|
|
1932
2014
|
};
|
|
1933
2015
|
}
|
|
1934
2016
|
var defaults = {};
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
assignDefault(it, key, properties2[key].default);
|
|
1948
|
-
}
|
|
1949
|
-
} else if (ty === "array" && Array.isArray(items2)) {
|
|
1950
|
-
items2.forEach((sch, i) => assignDefault(it, i, sch.default));
|
|
1951
|
-
}
|
|
2017
|
+
Object.defineProperty(defaults, "__esModule", { value: true });
|
|
2018
|
+
defaults.assignDefaults = void 0;
|
|
2019
|
+
const codegen_1$r = codegen;
|
|
2020
|
+
const util_1$p = util;
|
|
2021
|
+
function assignDefaults(it, ty) {
|
|
2022
|
+
const { properties: properties2, items: items2 } = it.schema;
|
|
2023
|
+
if (ty === "object" && properties2) {
|
|
2024
|
+
for (const key in properties2) {
|
|
2025
|
+
assignDefault(it, key, properties2[key].default);
|
|
2026
|
+
}
|
|
2027
|
+
} else if (ty === "array" && Array.isArray(items2)) {
|
|
2028
|
+
items2.forEach((sch, i) => assignDefault(it, i, sch.default));
|
|
1952
2029
|
}
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
}
|
|
1967
|
-
gen.if(condition, (0, codegen_12._)`${childData} = ${(0, codegen_12.stringify)(defaultValue)}`);
|
|
2030
|
+
}
|
|
2031
|
+
defaults.assignDefaults = assignDefaults;
|
|
2032
|
+
function assignDefault(it, prop, defaultValue) {
|
|
2033
|
+
const { gen, compositeRule, data, opts } = it;
|
|
2034
|
+
if (defaultValue === void 0)
|
|
2035
|
+
return;
|
|
2036
|
+
const childData = (0, codegen_1$r._)`${data}${(0, codegen_1$r.getProperty)(prop)}`;
|
|
2037
|
+
if (compositeRule) {
|
|
2038
|
+
(0, util_1$p.checkStrictMode)(it, `default is ignored for: ${childData}`);
|
|
2039
|
+
return;
|
|
2040
|
+
}
|
|
2041
|
+
let condition = (0, codegen_1$r._)`${childData} === undefined`;
|
|
2042
|
+
if (opts.useDefaults === "empty") {
|
|
2043
|
+
condition = (0, codegen_1$r._)`${condition} || ${childData} === null || ${childData} === ""`;
|
|
1968
2044
|
}
|
|
1969
|
-
|
|
2045
|
+
gen.if(condition, (0, codegen_1$r._)`${childData} = ${(0, codegen_1$r.stringify)(defaultValue)}`);
|
|
1970
2046
|
}
|
|
1971
2047
|
var keyword = {};
|
|
1972
2048
|
var code = {};
|
|
1973
2049
|
Object.defineProperty(code, "__esModule", { value: true });
|
|
1974
2050
|
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;
|
|
1975
|
-
const codegen_1$
|
|
1976
|
-
const util_1$
|
|
1977
|
-
const names_1$
|
|
2051
|
+
const codegen_1$q = codegen;
|
|
2052
|
+
const util_1$o = util;
|
|
2053
|
+
const names_1$5 = names$1;
|
|
1978
2054
|
const util_2$1 = util;
|
|
1979
2055
|
function checkReportMissingProp(cxt, prop) {
|
|
1980
2056
|
const { gen, data, it } = cxt;
|
|
1981
2057
|
gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
|
|
1982
|
-
cxt.setParams({ missingProperty: (0, codegen_1$
|
|
2058
|
+
cxt.setParams({ missingProperty: (0, codegen_1$q._)`${prop}` }, true);
|
|
1983
2059
|
cxt.error();
|
|
1984
2060
|
});
|
|
1985
2061
|
}
|
|
1986
2062
|
code.checkReportMissingProp = checkReportMissingProp;
|
|
1987
2063
|
function checkMissingProp({ gen, data, it: { opts } }, properties2, missing) {
|
|
1988
|
-
return (0, codegen_1$
|
|
2064
|
+
return (0, codegen_1$q.or)(...properties2.map((prop) => (0, codegen_1$q.and)(noPropertyInData(gen, data, prop, opts.ownProperties), (0, codegen_1$q._)`${missing} = ${prop}`)));
|
|
1989
2065
|
}
|
|
1990
2066
|
code.checkMissingProp = checkMissingProp;
|
|
1991
2067
|
function reportMissingProp(cxt, missing) {
|
|
@@ -1997,22 +2073,22 @@ function hasPropFunc(gen) {
|
|
|
1997
2073
|
return gen.scopeValue("func", {
|
|
1998
2074
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
1999
2075
|
ref: Object.prototype.hasOwnProperty,
|
|
2000
|
-
code: (0, codegen_1$
|
|
2076
|
+
code: (0, codegen_1$q._)`Object.prototype.hasOwnProperty`
|
|
2001
2077
|
});
|
|
2002
2078
|
}
|
|
2003
2079
|
code.hasPropFunc = hasPropFunc;
|
|
2004
2080
|
function isOwnProperty(gen, data, property) {
|
|
2005
|
-
return (0, codegen_1$
|
|
2081
|
+
return (0, codegen_1$q._)`${hasPropFunc(gen)}.call(${data}, ${property})`;
|
|
2006
2082
|
}
|
|
2007
2083
|
code.isOwnProperty = isOwnProperty;
|
|
2008
2084
|
function propertyInData(gen, data, property, ownProperties) {
|
|
2009
|
-
const cond = (0, codegen_1$
|
|
2010
|
-
return ownProperties ? (0, codegen_1$
|
|
2085
|
+
const cond = (0, codegen_1$q._)`${data}${(0, codegen_1$q.getProperty)(property)} !== undefined`;
|
|
2086
|
+
return ownProperties ? (0, codegen_1$q._)`${cond} && ${isOwnProperty(gen, data, property)}` : cond;
|
|
2011
2087
|
}
|
|
2012
2088
|
code.propertyInData = propertyInData;
|
|
2013
2089
|
function noPropertyInData(gen, data, property, ownProperties) {
|
|
2014
|
-
const cond = (0, codegen_1$
|
|
2015
|
-
return ownProperties ? (0, codegen_1$
|
|
2090
|
+
const cond = (0, codegen_1$q._)`${data}${(0, codegen_1$q.getProperty)(property)} === undefined`;
|
|
2091
|
+
return ownProperties ? (0, codegen_1$q.or)(cond, (0, codegen_1$q.not)(isOwnProperty(gen, data, property))) : cond;
|
|
2016
2092
|
}
|
|
2017
2093
|
code.noPropertyInData = noPropertyInData;
|
|
2018
2094
|
function allSchemaProperties(schemaMap) {
|
|
@@ -2020,24 +2096,24 @@ function allSchemaProperties(schemaMap) {
|
|
|
2020
2096
|
}
|
|
2021
2097
|
code.allSchemaProperties = allSchemaProperties;
|
|
2022
2098
|
function schemaProperties(it, schemaMap) {
|
|
2023
|
-
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$
|
|
2099
|
+
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$o.alwaysValidSchema)(it, schemaMap[p]));
|
|
2024
2100
|
}
|
|
2025
2101
|
code.schemaProperties = schemaProperties;
|
|
2026
2102
|
function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context, passSchema) {
|
|
2027
|
-
const dataAndSchema = passSchema ? (0, codegen_1$
|
|
2103
|
+
const dataAndSchema = passSchema ? (0, codegen_1$q._)`${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
|
|
2028
2104
|
const valCxt = [
|
|
2029
|
-
[names_1$
|
|
2030
|
-
[names_1$
|
|
2031
|
-
[names_1$
|
|
2032
|
-
[names_1$
|
|
2105
|
+
[names_1$5.default.instancePath, (0, codegen_1$q.strConcat)(names_1$5.default.instancePath, errorPath)],
|
|
2106
|
+
[names_1$5.default.parentData, it.parentData],
|
|
2107
|
+
[names_1$5.default.parentDataProperty, it.parentDataProperty],
|
|
2108
|
+
[names_1$5.default.rootData, names_1$5.default.rootData]
|
|
2033
2109
|
];
|
|
2034
2110
|
if (it.opts.dynamicRef)
|
|
2035
|
-
valCxt.push([names_1$
|
|
2036
|
-
const args = (0, codegen_1$
|
|
2037
|
-
return context !== codegen_1$
|
|
2111
|
+
valCxt.push([names_1$5.default.dynamicAnchors, names_1$5.default.dynamicAnchors]);
|
|
2112
|
+
const args = (0, codegen_1$q._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
|
|
2113
|
+
return context !== codegen_1$q.nil ? (0, codegen_1$q._)`${func}.call(${context}, ${args})` : (0, codegen_1$q._)`${func}(${args})`;
|
|
2038
2114
|
}
|
|
2039
2115
|
code.callValidateCode = callValidateCode;
|
|
2040
|
-
const newRegExp = (0, codegen_1$
|
|
2116
|
+
const newRegExp = (0, codegen_1$q._)`new RegExp`;
|
|
2041
2117
|
function usePattern({ gen, it: { opts } }, pattern2) {
|
|
2042
2118
|
const u = opts.unicodeRegExp ? "u" : "";
|
|
2043
2119
|
const { regExp } = opts.code;
|
|
@@ -2045,7 +2121,7 @@ function usePattern({ gen, it: { opts } }, pattern2) {
|
|
|
2045
2121
|
return gen.scopeValue("pattern", {
|
|
2046
2122
|
key: rx.toString(),
|
|
2047
2123
|
ref: rx,
|
|
2048
|
-
code: (0, codegen_1$
|
|
2124
|
+
code: (0, codegen_1$q._)`${regExp.code === "new RegExp" ? newRegExp : (0, util_2$1.useFunc)(gen, regExp)}(${pattern2}, ${u})`
|
|
2049
2125
|
});
|
|
2050
2126
|
}
|
|
2051
2127
|
code.usePattern = usePattern;
|
|
@@ -2061,14 +2137,14 @@ function validateArray(cxt) {
|
|
|
2061
2137
|
validateItems(() => gen.break());
|
|
2062
2138
|
return valid;
|
|
2063
2139
|
function validateItems(notValid) {
|
|
2064
|
-
const len = gen.const("len", (0, codegen_1$
|
|
2140
|
+
const len = gen.const("len", (0, codegen_1$q._)`${data}.length`);
|
|
2065
2141
|
gen.forRange("i", 0, len, (i) => {
|
|
2066
2142
|
cxt.subschema({
|
|
2067
2143
|
keyword: keyword2,
|
|
2068
2144
|
dataProp: i,
|
|
2069
|
-
dataPropType: util_1$
|
|
2145
|
+
dataPropType: util_1$o.Type.Num
|
|
2070
2146
|
}, valid);
|
|
2071
|
-
gen.if((0, codegen_1$
|
|
2147
|
+
gen.if((0, codegen_1$q.not)(valid), notValid);
|
|
2072
2148
|
});
|
|
2073
2149
|
}
|
|
2074
2150
|
}
|
|
@@ -2077,7 +2153,7 @@ function validateUnion(cxt) {
|
|
|
2077
2153
|
const { gen, schema, keyword: keyword2, it } = cxt;
|
|
2078
2154
|
if (!Array.isArray(schema))
|
|
2079
2155
|
throw new Error("ajv implementation error");
|
|
2080
|
-
const alwaysValid = schema.some((sch) => (0, util_1$
|
|
2156
|
+
const alwaysValid = schema.some((sch) => (0, util_1$o.alwaysValidSchema)(it, sch));
|
|
2081
2157
|
if (alwaysValid && !it.opts.unevaluated)
|
|
2082
2158
|
return;
|
|
2083
2159
|
const valid = gen.let("valid", false);
|
|
@@ -2088,214 +2164,202 @@ function validateUnion(cxt) {
|
|
|
2088
2164
|
schemaProp: i,
|
|
2089
2165
|
compositeRule: true
|
|
2090
2166
|
}, schValid);
|
|
2091
|
-
gen.assign(valid, (0, codegen_1$
|
|
2167
|
+
gen.assign(valid, (0, codegen_1$q._)`${valid} || ${schValid}`);
|
|
2092
2168
|
const merged = cxt.mergeValidEvaluated(schCxt, schValid);
|
|
2093
2169
|
if (!merged)
|
|
2094
|
-
gen.if((0, codegen_1$
|
|
2170
|
+
gen.if((0, codegen_1$q.not)(valid));
|
|
2095
2171
|
}));
|
|
2096
2172
|
cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
|
|
2097
2173
|
}
|
|
2098
2174
|
code.validateUnion = validateUnion;
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
const
|
|
2107
|
-
const
|
|
2108
|
-
const
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
}
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
2143
|
-
if (def2.modifying)
|
|
2144
|
-
modifyData(cxt);
|
|
2145
|
-
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
2146
|
-
}
|
|
2147
|
-
}
|
|
2148
|
-
function validateAsync() {
|
|
2149
|
-
const ruleErrs = gen.let("ruleErrs", null);
|
|
2150
|
-
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)));
|
|
2151
|
-
return ruleErrs;
|
|
2152
|
-
}
|
|
2153
|
-
function validateSync() {
|
|
2154
|
-
const validateErrs = (0, codegen_12._)`${validateRef}.errors`;
|
|
2155
|
-
gen.assign(validateErrs, null);
|
|
2156
|
-
assignValid(codegen_12.nil);
|
|
2157
|
-
return validateErrs;
|
|
2158
|
-
}
|
|
2159
|
-
function assignValid(_await = def2.async ? (0, codegen_12._)`await ` : codegen_12.nil) {
|
|
2160
|
-
const passCxt = it.opts.passContext ? names_12.default.this : names_12.default.self;
|
|
2161
|
-
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
2162
|
-
gen.assign(valid, (0, codegen_12._)`${_await}${(0, code_12.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
2163
|
-
}
|
|
2164
|
-
function reportErrs(errors2) {
|
|
2165
|
-
var _a2;
|
|
2166
|
-
gen.if((0, codegen_12.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
|
|
2175
|
+
Object.defineProperty(keyword, "__esModule", { value: true });
|
|
2176
|
+
keyword.validateKeywordUsage = keyword.validSchemaType = keyword.funcKeywordCode = keyword.macroKeywordCode = void 0;
|
|
2177
|
+
const codegen_1$p = codegen;
|
|
2178
|
+
const names_1$4 = names$1;
|
|
2179
|
+
const code_1$9 = code;
|
|
2180
|
+
const errors_1$1 = errors;
|
|
2181
|
+
function macroKeywordCode(cxt, def2) {
|
|
2182
|
+
const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
|
|
2183
|
+
const macroSchema = def2.macro.call(it.self, schema, parentSchema, it);
|
|
2184
|
+
const schemaRef = useKeyword(gen, keyword2, macroSchema);
|
|
2185
|
+
if (it.opts.validateSchema !== false)
|
|
2186
|
+
it.self.validateSchema(macroSchema, true);
|
|
2187
|
+
const valid = gen.name("valid");
|
|
2188
|
+
cxt.subschema({
|
|
2189
|
+
schema: macroSchema,
|
|
2190
|
+
schemaPath: codegen_1$p.nil,
|
|
2191
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`,
|
|
2192
|
+
topSchemaRef: schemaRef,
|
|
2193
|
+
compositeRule: true
|
|
2194
|
+
}, valid);
|
|
2195
|
+
cxt.pass(valid, () => cxt.error(true));
|
|
2196
|
+
}
|
|
2197
|
+
keyword.macroKeywordCode = macroKeywordCode;
|
|
2198
|
+
function funcKeywordCode(cxt, def2) {
|
|
2199
|
+
var _a;
|
|
2200
|
+
const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
|
|
2201
|
+
checkAsyncKeyword(it, def2);
|
|
2202
|
+
const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
|
|
2203
|
+
const validateRef = useKeyword(gen, keyword2, validate2);
|
|
2204
|
+
const valid = gen.let("valid");
|
|
2205
|
+
cxt.block$data(valid, validateKeyword);
|
|
2206
|
+
cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
|
|
2207
|
+
function validateKeyword() {
|
|
2208
|
+
if (def2.errors === false) {
|
|
2209
|
+
assignValid();
|
|
2210
|
+
if (def2.modifying)
|
|
2211
|
+
modifyData(cxt);
|
|
2212
|
+
reportErrs(() => cxt.error());
|
|
2213
|
+
} else {
|
|
2214
|
+
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
2215
|
+
if (def2.modifying)
|
|
2216
|
+
modifyData(cxt);
|
|
2217
|
+
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
2167
2218
|
}
|
|
2168
2219
|
}
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
}
|
|
2174
|
-
function
|
|
2175
|
-
const
|
|
2176
|
-
gen.
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
}
|
|
2185
|
-
function
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
}
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2220
|
+
function validateAsync() {
|
|
2221
|
+
const ruleErrs = gen.let("ruleErrs", null);
|
|
2222
|
+
gen.try(() => assignValid((0, codegen_1$p._)`await `), (e) => gen.assign(valid, false).if((0, codegen_1$p._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1$p._)`${e}.errors`), () => gen.throw(e)));
|
|
2223
|
+
return ruleErrs;
|
|
2224
|
+
}
|
|
2225
|
+
function validateSync() {
|
|
2226
|
+
const validateErrs = (0, codegen_1$p._)`${validateRef}.errors`;
|
|
2227
|
+
gen.assign(validateErrs, null);
|
|
2228
|
+
assignValid(codegen_1$p.nil);
|
|
2229
|
+
return validateErrs;
|
|
2230
|
+
}
|
|
2231
|
+
function assignValid(_await = def2.async ? (0, codegen_1$p._)`await ` : codegen_1$p.nil) {
|
|
2232
|
+
const passCxt = it.opts.passContext ? names_1$4.default.this : names_1$4.default.self;
|
|
2233
|
+
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
2234
|
+
gen.assign(valid, (0, codegen_1$p._)`${_await}${(0, code_1$9.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
2235
|
+
}
|
|
2236
|
+
function reportErrs(errors2) {
|
|
2237
|
+
var _a2;
|
|
2238
|
+
gen.if((0, codegen_1$p.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
keyword.funcKeywordCode = funcKeywordCode;
|
|
2242
|
+
function modifyData(cxt) {
|
|
2243
|
+
const { gen, data, it } = cxt;
|
|
2244
|
+
gen.if(it.parentData, () => gen.assign(data, (0, codegen_1$p._)`${it.parentData}[${it.parentDataProperty}]`));
|
|
2245
|
+
}
|
|
2246
|
+
function addErrs(cxt, errs) {
|
|
2247
|
+
const { gen } = cxt;
|
|
2248
|
+
gen.if((0, codegen_1$p._)`Array.isArray(${errs})`, () => {
|
|
2249
|
+
gen.assign(names_1$4.default.vErrors, (0, codegen_1$p._)`${names_1$4.default.vErrors} === null ? ${errs} : ${names_1$4.default.vErrors}.concat(${errs})`).assign(names_1$4.default.errors, (0, codegen_1$p._)`${names_1$4.default.vErrors}.length`);
|
|
2250
|
+
(0, errors_1$1.extendErrors)(cxt);
|
|
2251
|
+
}, () => cxt.error());
|
|
2252
|
+
}
|
|
2253
|
+
function checkAsyncKeyword({ schemaEnv }, def2) {
|
|
2254
|
+
if (def2.async && !schemaEnv.$async)
|
|
2255
|
+
throw new Error("async keyword in sync schema");
|
|
2256
|
+
}
|
|
2257
|
+
function useKeyword(gen, keyword2, result) {
|
|
2258
|
+
if (result === void 0)
|
|
2259
|
+
throw new Error(`keyword "${keyword2}" failed to compile`);
|
|
2260
|
+
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_1$p.stringify)(result) });
|
|
2261
|
+
}
|
|
2262
|
+
function validSchemaType(schema, schemaType, allowUndefined = false) {
|
|
2263
|
+
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");
|
|
2264
|
+
}
|
|
2265
|
+
keyword.validSchemaType = validSchemaType;
|
|
2266
|
+
function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def2, keyword2) {
|
|
2267
|
+
if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
|
|
2268
|
+
throw new Error("ajv implementation error");
|
|
2269
|
+
}
|
|
2270
|
+
const deps = def2.dependencies;
|
|
2271
|
+
if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
|
|
2272
|
+
throw new Error(`parent schema must have dependencies of ${keyword2}: ${deps.join(",")}`);
|
|
2273
|
+
}
|
|
2274
|
+
if (def2.validateSchema) {
|
|
2275
|
+
const valid = def2.validateSchema(schema[keyword2]);
|
|
2276
|
+
if (!valid) {
|
|
2277
|
+
const msg = `keyword "${keyword2}" value is invalid at path "${errSchemaPath}": ` + self.errorsText(def2.validateSchema.errors);
|
|
2278
|
+
if (opts.validateSchema === "log")
|
|
2279
|
+
self.logger.error(msg);
|
|
2280
|
+
else
|
|
2281
|
+
throw new Error(msg);
|
|
2211
2282
|
}
|
|
2212
2283
|
}
|
|
2213
|
-
keyword.validateKeywordUsage = validateKeywordUsage;
|
|
2214
|
-
return keyword;
|
|
2215
2284
|
}
|
|
2285
|
+
keyword.validateKeywordUsage = validateKeywordUsage;
|
|
2216
2286
|
var subschema = {};
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
}
|
|
2241
|
-
if (schema !== void 0) {
|
|
2242
|
-
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
2243
|
-
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
2244
|
-
}
|
|
2245
|
-
return {
|
|
2246
|
-
schema,
|
|
2247
|
-
schemaPath,
|
|
2248
|
-
topSchemaRef,
|
|
2249
|
-
errSchemaPath
|
|
2250
|
-
};
|
|
2287
|
+
Object.defineProperty(subschema, "__esModule", { value: true });
|
|
2288
|
+
subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
|
|
2289
|
+
const codegen_1$o = codegen;
|
|
2290
|
+
const util_1$n = util;
|
|
2291
|
+
function getSubschema(it, { keyword: keyword2, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
|
|
2292
|
+
if (keyword2 !== void 0 && schema !== void 0) {
|
|
2293
|
+
throw new Error('both "keyword" and "schema" passed, only one allowed');
|
|
2294
|
+
}
|
|
2295
|
+
if (keyword2 !== void 0) {
|
|
2296
|
+
const sch = it.schema[keyword2];
|
|
2297
|
+
return schemaProp === void 0 ? {
|
|
2298
|
+
schema: sch,
|
|
2299
|
+
schemaPath: (0, codegen_1$o._)`${it.schemaPath}${(0, codegen_1$o.getProperty)(keyword2)}`,
|
|
2300
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`
|
|
2301
|
+
} : {
|
|
2302
|
+
schema: sch[schemaProp],
|
|
2303
|
+
schemaPath: (0, codegen_1$o._)`${it.schemaPath}${(0, codegen_1$o.getProperty)(keyword2)}${(0, codegen_1$o.getProperty)(schemaProp)}`,
|
|
2304
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_1$n.escapeFragment)(schemaProp)}`
|
|
2305
|
+
};
|
|
2306
|
+
}
|
|
2307
|
+
if (schema !== void 0) {
|
|
2308
|
+
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
2309
|
+
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
2251
2310
|
}
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
subschema2.
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2311
|
+
return {
|
|
2312
|
+
schema,
|
|
2313
|
+
schemaPath,
|
|
2314
|
+
topSchemaRef,
|
|
2315
|
+
errSchemaPath
|
|
2316
|
+
};
|
|
2317
|
+
}
|
|
2318
|
+
throw new Error('either "keyword" or "schema" must be passed');
|
|
2319
|
+
}
|
|
2320
|
+
subschema.getSubschema = getSubschema;
|
|
2321
|
+
function extendSubschemaData(subschema2, it, { dataProp, dataPropType: dpType, data, dataTypes, propertyName }) {
|
|
2322
|
+
if (data !== void 0 && dataProp !== void 0) {
|
|
2323
|
+
throw new Error('both "data" and "dataProp" passed, only one allowed');
|
|
2324
|
+
}
|
|
2325
|
+
const { gen } = it;
|
|
2326
|
+
if (dataProp !== void 0) {
|
|
2327
|
+
const { errorPath, dataPathArr, opts } = it;
|
|
2328
|
+
const nextData = gen.let("data", (0, codegen_1$o._)`${it.data}${(0, codegen_1$o.getProperty)(dataProp)}`, true);
|
|
2329
|
+
dataContextProps(nextData);
|
|
2330
|
+
subschema2.errorPath = (0, codegen_1$o.str)`${errorPath}${(0, util_1$n.getErrorPath)(dataProp, dpType, opts.jsPropertySyntax)}`;
|
|
2331
|
+
subschema2.parentDataProperty = (0, codegen_1$o._)`${dataProp}`;
|
|
2332
|
+
subschema2.dataPathArr = [...dataPathArr, subschema2.parentDataProperty];
|
|
2333
|
+
}
|
|
2334
|
+
if (data !== void 0) {
|
|
2335
|
+
const nextData = data instanceof codegen_1$o.Name ? data : gen.let("data", data, true);
|
|
2336
|
+
dataContextProps(nextData);
|
|
2337
|
+
if (propertyName !== void 0)
|
|
2338
|
+
subschema2.propertyName = propertyName;
|
|
2339
|
+
}
|
|
2340
|
+
if (dataTypes)
|
|
2341
|
+
subschema2.dataTypes = dataTypes;
|
|
2342
|
+
function dataContextProps(_nextData) {
|
|
2343
|
+
subschema2.data = _nextData;
|
|
2344
|
+
subschema2.dataLevel = it.dataLevel + 1;
|
|
2345
|
+
subschema2.dataTypes = [];
|
|
2346
|
+
it.definedProperties = /* @__PURE__ */ new Set();
|
|
2347
|
+
subschema2.parentData = it.data;
|
|
2348
|
+
subschema2.dataNames = [...it.dataNames, _nextData];
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
subschema.extendSubschemaData = extendSubschemaData;
|
|
2352
|
+
function extendSubschemaMode(subschema2, { jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors }) {
|
|
2353
|
+
if (compositeRule !== void 0)
|
|
2354
|
+
subschema2.compositeRule = compositeRule;
|
|
2355
|
+
if (createErrors !== void 0)
|
|
2356
|
+
subschema2.createErrors = createErrors;
|
|
2357
|
+
if (allErrors !== void 0)
|
|
2358
|
+
subschema2.allErrors = allErrors;
|
|
2359
|
+
subschema2.jtdDiscriminator = jtdDiscriminator;
|
|
2360
|
+
subschema2.jtdMetadata = jtdMetadata;
|
|
2298
2361
|
}
|
|
2362
|
+
subschema.extendSubschemaMode = extendSubschemaMode;
|
|
2299
2363
|
var resolve$2 = {};
|
|
2300
2364
|
var fastDeepEqual = function equal(a, b) {
|
|
2301
2365
|
if (a === b) return true;
|
|
@@ -2410,7 +2474,7 @@ function escapeJsonPtr(str) {
|
|
|
2410
2474
|
var jsonSchemaTraverseExports = jsonSchemaTraverse.exports;
|
|
2411
2475
|
Object.defineProperty(resolve$2, "__esModule", { value: true });
|
|
2412
2476
|
resolve$2.getSchemaRefs = resolve$2.resolveUrl = resolve$2.normalizeId = resolve$2._getFullPath = resolve$2.getFullPath = resolve$2.inlineRef = void 0;
|
|
2413
|
-
const util_1$
|
|
2477
|
+
const util_1$m = util;
|
|
2414
2478
|
const equal$3 = fastDeepEqual;
|
|
2415
2479
|
const traverse = jsonSchemaTraverseExports;
|
|
2416
2480
|
const SIMPLE_INLINED = /* @__PURE__ */ new Set([
|
|
@@ -2469,7 +2533,7 @@ function countKeys(schema) {
|
|
|
2469
2533
|
if (SIMPLE_INLINED.has(key))
|
|
2470
2534
|
continue;
|
|
2471
2535
|
if (typeof schema[key] == "object") {
|
|
2472
|
-
(0, util_1$
|
|
2536
|
+
(0, util_1$m.eachItem)(schema[key], (sch) => count += countKeys(sch));
|
|
2473
2537
|
}
|
|
2474
2538
|
if (count === Infinity)
|
|
2475
2539
|
return Infinity;
|
|
@@ -2557,528 +2621,516 @@ function getSchemaRefs(schema, baseId) {
|
|
|
2557
2621
|
}
|
|
2558
2622
|
}
|
|
2559
2623
|
resolve$2.getSchemaRefs = getSchemaRefs;
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
checkKeywords(it);
|
|
2581
|
-
if (schemaCxtHasRules(it)) {
|
|
2582
|
-
topSchemaObjCode(it);
|
|
2583
|
-
return;
|
|
2584
|
-
}
|
|
2624
|
+
Object.defineProperty(validate, "__esModule", { value: true });
|
|
2625
|
+
validate.getData = validate.KeywordCxt = validate.validateFunctionCode = void 0;
|
|
2626
|
+
const boolSchema_1 = boolSchema;
|
|
2627
|
+
const dataType_1$1 = dataType;
|
|
2628
|
+
const applicability_1 = applicability;
|
|
2629
|
+
const dataType_2 = dataType;
|
|
2630
|
+
const defaults_1 = defaults;
|
|
2631
|
+
const keyword_1 = keyword;
|
|
2632
|
+
const subschema_1 = subschema;
|
|
2633
|
+
const codegen_1$n = codegen;
|
|
2634
|
+
const names_1$3 = names$1;
|
|
2635
|
+
const resolve_1$2 = resolve$2;
|
|
2636
|
+
const util_1$l = util;
|
|
2637
|
+
const errors_1 = errors;
|
|
2638
|
+
function validateFunctionCode(it) {
|
|
2639
|
+
if (isSchemaObj(it)) {
|
|
2640
|
+
checkKeywords(it);
|
|
2641
|
+
if (schemaCxtHasRules(it)) {
|
|
2642
|
+
topSchemaObjCode(it);
|
|
2643
|
+
return;
|
|
2585
2644
|
}
|
|
2586
|
-
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
2587
|
-
}
|
|
2588
|
-
validate.validateFunctionCode = validateFunctionCode;
|
|
2589
|
-
function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
|
|
2590
|
-
if (opts.code.es5) {
|
|
2591
|
-
gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${names_12.default.valCxt}`, schemaEnv.$async, () => {
|
|
2592
|
-
gen.code((0, codegen_12._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
|
|
2593
|
-
destructureValCxtES5(gen, opts);
|
|
2594
|
-
gen.code(body);
|
|
2595
|
-
});
|
|
2596
|
-
} else {
|
|
2597
|
-
gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
2598
|
-
}
|
|
2599
|
-
}
|
|
2600
|
-
function destructureValCxt(opts) {
|
|
2601
|
-
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}}={}`;
|
|
2602
|
-
}
|
|
2603
|
-
function destructureValCxtES5(gen, opts) {
|
|
2604
|
-
gen.if(names_12.default.valCxt, () => {
|
|
2605
|
-
gen.var(names_12.default.instancePath, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.instancePath}`);
|
|
2606
|
-
gen.var(names_12.default.parentData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentData}`);
|
|
2607
|
-
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentDataProperty}`);
|
|
2608
|
-
gen.var(names_12.default.rootData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.rootData}`);
|
|
2609
|
-
if (opts.dynamicRef)
|
|
2610
|
-
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.dynamicAnchors}`);
|
|
2611
|
-
}, () => {
|
|
2612
|
-
gen.var(names_12.default.instancePath, (0, codegen_12._)`""`);
|
|
2613
|
-
gen.var(names_12.default.parentData, (0, codegen_12._)`undefined`);
|
|
2614
|
-
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`undefined`);
|
|
2615
|
-
gen.var(names_12.default.rootData, names_12.default.data);
|
|
2616
|
-
if (opts.dynamicRef)
|
|
2617
|
-
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`{}`);
|
|
2618
|
-
});
|
|
2619
2645
|
}
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
gen.
|
|
2627
|
-
gen
|
|
2628
|
-
|
|
2629
|
-
resetEvaluated(it);
|
|
2630
|
-
typeAndKeywords(it);
|
|
2631
|
-
returnResults(it);
|
|
2646
|
+
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
2647
|
+
}
|
|
2648
|
+
validate.validateFunctionCode = validateFunctionCode;
|
|
2649
|
+
function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
|
|
2650
|
+
if (opts.code.es5) {
|
|
2651
|
+
gen.func(validateName, (0, codegen_1$n._)`${names_1$3.default.data}, ${names_1$3.default.valCxt}`, schemaEnv.$async, () => {
|
|
2652
|
+
gen.code((0, codegen_1$n._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
|
|
2653
|
+
destructureValCxtES5(gen, opts);
|
|
2654
|
+
gen.code(body);
|
|
2632
2655
|
});
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
function resetEvaluated(it) {
|
|
2636
|
-
const { gen, validateName } = it;
|
|
2637
|
-
it.evaluated = gen.const("evaluated", (0, codegen_12._)`${validateName}.evaluated`);
|
|
2638
|
-
gen.if((0, codegen_12._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_12._)`${it.evaluated}.props`, (0, codegen_12._)`undefined`));
|
|
2639
|
-
gen.if((0, codegen_12._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_12._)`${it.evaluated}.items`, (0, codegen_12._)`undefined`));
|
|
2640
|
-
}
|
|
2641
|
-
function funcSourceUrl(schema, opts) {
|
|
2642
|
-
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
2643
|
-
return schId && (opts.code.source || opts.code.process) ? (0, codegen_12._)`/*# sourceURL=${schId} */` : codegen_12.nil;
|
|
2644
|
-
}
|
|
2645
|
-
function subschemaCode(it, valid) {
|
|
2646
|
-
if (isSchemaObj(it)) {
|
|
2647
|
-
checkKeywords(it);
|
|
2648
|
-
if (schemaCxtHasRules(it)) {
|
|
2649
|
-
subSchemaObjCode(it, valid);
|
|
2650
|
-
return;
|
|
2651
|
-
}
|
|
2652
|
-
}
|
|
2653
|
-
(0, boolSchema_1.boolOrEmptySchema)(it, valid);
|
|
2654
|
-
}
|
|
2655
|
-
function schemaCxtHasRules({ schema, self }) {
|
|
2656
|
-
if (typeof schema == "boolean")
|
|
2657
|
-
return !schema;
|
|
2658
|
-
for (const key in schema)
|
|
2659
|
-
if (self.RULES.all[key])
|
|
2660
|
-
return true;
|
|
2661
|
-
return false;
|
|
2662
|
-
}
|
|
2663
|
-
function isSchemaObj(it) {
|
|
2664
|
-
return typeof it.schema != "boolean";
|
|
2656
|
+
} else {
|
|
2657
|
+
gen.func(validateName, (0, codegen_1$n._)`${names_1$3.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
2665
2658
|
}
|
|
2666
|
-
|
|
2667
|
-
|
|
2659
|
+
}
|
|
2660
|
+
function destructureValCxt(opts) {
|
|
2661
|
+
return (0, codegen_1$n._)`{${names_1$3.default.instancePath}="", ${names_1$3.default.parentData}, ${names_1$3.default.parentDataProperty}, ${names_1$3.default.rootData}=${names_1$3.default.data}${opts.dynamicRef ? (0, codegen_1$n._)`, ${names_1$3.default.dynamicAnchors}={}` : codegen_1$n.nil}}={}`;
|
|
2662
|
+
}
|
|
2663
|
+
function destructureValCxtES5(gen, opts) {
|
|
2664
|
+
gen.if(names_1$3.default.valCxt, () => {
|
|
2665
|
+
gen.var(names_1$3.default.instancePath, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.instancePath}`);
|
|
2666
|
+
gen.var(names_1$3.default.parentData, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.parentData}`);
|
|
2667
|
+
gen.var(names_1$3.default.parentDataProperty, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.parentDataProperty}`);
|
|
2668
|
+
gen.var(names_1$3.default.rootData, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.rootData}`);
|
|
2669
|
+
if (opts.dynamicRef)
|
|
2670
|
+
gen.var(names_1$3.default.dynamicAnchors, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.dynamicAnchors}`);
|
|
2671
|
+
}, () => {
|
|
2672
|
+
gen.var(names_1$3.default.instancePath, (0, codegen_1$n._)`""`);
|
|
2673
|
+
gen.var(names_1$3.default.parentData, (0, codegen_1$n._)`undefined`);
|
|
2674
|
+
gen.var(names_1$3.default.parentDataProperty, (0, codegen_1$n._)`undefined`);
|
|
2675
|
+
gen.var(names_1$3.default.rootData, names_1$3.default.data);
|
|
2676
|
+
if (opts.dynamicRef)
|
|
2677
|
+
gen.var(names_1$3.default.dynamicAnchors, (0, codegen_1$n._)`{}`);
|
|
2678
|
+
});
|
|
2679
|
+
}
|
|
2680
|
+
function topSchemaObjCode(it) {
|
|
2681
|
+
const { schema, opts, gen } = it;
|
|
2682
|
+
validateFunction(it, () => {
|
|
2668
2683
|
if (opts.$comment && schema.$comment)
|
|
2669
2684
|
commentKeyword(it);
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2685
|
+
checkNoDefault(it);
|
|
2686
|
+
gen.let(names_1$3.default.vErrors, null);
|
|
2687
|
+
gen.let(names_1$3.default.errors, 0);
|
|
2688
|
+
if (opts.unevaluated)
|
|
2689
|
+
resetEvaluated(it);
|
|
2690
|
+
typeAndKeywords(it);
|
|
2691
|
+
returnResults(it);
|
|
2692
|
+
});
|
|
2693
|
+
return;
|
|
2694
|
+
}
|
|
2695
|
+
function resetEvaluated(it) {
|
|
2696
|
+
const { gen, validateName } = it;
|
|
2697
|
+
it.evaluated = gen.const("evaluated", (0, codegen_1$n._)`${validateName}.evaluated`);
|
|
2698
|
+
gen.if((0, codegen_1$n._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_1$n._)`${it.evaluated}.props`, (0, codegen_1$n._)`undefined`));
|
|
2699
|
+
gen.if((0, codegen_1$n._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_1$n._)`${it.evaluated}.items`, (0, codegen_1$n._)`undefined`));
|
|
2700
|
+
}
|
|
2701
|
+
function funcSourceUrl(schema, opts) {
|
|
2702
|
+
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
2703
|
+
return schId && (opts.code.source || opts.code.process) ? (0, codegen_1$n._)`/*# sourceURL=${schId} */` : codegen_1$n.nil;
|
|
2704
|
+
}
|
|
2705
|
+
function subschemaCode(it, valid) {
|
|
2706
|
+
if (isSchemaObj(it)) {
|
|
2707
|
+
checkKeywords(it);
|
|
2708
|
+
if (schemaCxtHasRules(it)) {
|
|
2709
|
+
subSchemaObjCode(it, valid);
|
|
2710
|
+
return;
|
|
2691
2711
|
}
|
|
2692
2712
|
}
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2713
|
+
(0, boolSchema_1.boolOrEmptySchema)(it, valid);
|
|
2714
|
+
}
|
|
2715
|
+
function schemaCxtHasRules({ schema, self }) {
|
|
2716
|
+
if (typeof schema == "boolean")
|
|
2717
|
+
return !schema;
|
|
2718
|
+
for (const key in schema)
|
|
2719
|
+
if (self.RULES.all[key])
|
|
2720
|
+
return true;
|
|
2721
|
+
return false;
|
|
2722
|
+
}
|
|
2723
|
+
function isSchemaObj(it) {
|
|
2724
|
+
return typeof it.schema != "boolean";
|
|
2725
|
+
}
|
|
2726
|
+
function subSchemaObjCode(it, valid) {
|
|
2727
|
+
const { schema, gen, opts } = it;
|
|
2728
|
+
if (opts.$comment && schema.$comment)
|
|
2729
|
+
commentKeyword(it);
|
|
2730
|
+
updateContext(it);
|
|
2731
|
+
checkAsyncSchema(it);
|
|
2732
|
+
const errsCount = gen.const("_errs", names_1$3.default.errors);
|
|
2733
|
+
typeAndKeywords(it, errsCount);
|
|
2734
|
+
gen.var(valid, (0, codegen_1$n._)`${errsCount} === ${names_1$3.default.errors}`);
|
|
2735
|
+
}
|
|
2736
|
+
function checkKeywords(it) {
|
|
2737
|
+
(0, util_1$l.checkUnknownRules)(it);
|
|
2738
|
+
checkRefsAndKeywords(it);
|
|
2739
|
+
}
|
|
2740
|
+
function typeAndKeywords(it, errsCount) {
|
|
2741
|
+
if (it.opts.jtd)
|
|
2742
|
+
return schemaKeywords(it, [], false, errsCount);
|
|
2743
|
+
const types2 = (0, dataType_1$1.getSchemaTypes)(it.schema);
|
|
2744
|
+
const checkedTypes = (0, dataType_1$1.coerceAndCheckDataType)(it, types2);
|
|
2745
|
+
schemaKeywords(it, types2, !checkedTypes, errsCount);
|
|
2746
|
+
}
|
|
2747
|
+
function checkRefsAndKeywords(it) {
|
|
2748
|
+
const { schema, errSchemaPath, opts, self } = it;
|
|
2749
|
+
if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_1$l.schemaHasRulesButRef)(schema, self.RULES)) {
|
|
2750
|
+
self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
|
|
2698
2751
|
}
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2752
|
+
}
|
|
2753
|
+
function checkNoDefault(it) {
|
|
2754
|
+
const { schema, opts } = it;
|
|
2755
|
+
if (schema.default !== void 0 && opts.useDefaults && opts.strictSchema) {
|
|
2756
|
+
(0, util_1$l.checkStrictMode)(it, "default is ignored in the schema root");
|
|
2703
2757
|
}
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2758
|
+
}
|
|
2759
|
+
function updateContext(it) {
|
|
2760
|
+
const schId = it.schema[it.opts.schemaId];
|
|
2761
|
+
if (schId)
|
|
2762
|
+
it.baseId = (0, resolve_1$2.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
|
|
2763
|
+
}
|
|
2764
|
+
function checkAsyncSchema(it) {
|
|
2765
|
+
if (it.schema.$async && !it.schemaEnv.$async)
|
|
2766
|
+
throw new Error("async schema in sync schema");
|
|
2767
|
+
}
|
|
2768
|
+
function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
|
|
2769
|
+
const msg = schema.$comment;
|
|
2770
|
+
if (opts.$comment === true) {
|
|
2771
|
+
gen.code((0, codegen_1$n._)`${names_1$3.default.self}.logger.log(${msg})`);
|
|
2772
|
+
} else if (typeof opts.$comment == "function") {
|
|
2773
|
+
const schemaPath = (0, codegen_1$n.str)`${errSchemaPath}/$comment`;
|
|
2774
|
+
const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
|
|
2775
|
+
gen.code((0, codegen_1$n._)`${names_1$3.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
|
|
2707
2776
|
}
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
}
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2777
|
+
}
|
|
2778
|
+
function returnResults(it) {
|
|
2779
|
+
const { gen, schemaEnv, validateName, ValidationError: ValidationError2, opts } = it;
|
|
2780
|
+
if (schemaEnv.$async) {
|
|
2781
|
+
gen.if((0, codegen_1$n._)`${names_1$3.default.errors} === 0`, () => gen.return(names_1$3.default.data), () => gen.throw((0, codegen_1$n._)`new ${ValidationError2}(${names_1$3.default.vErrors})`));
|
|
2782
|
+
} else {
|
|
2783
|
+
gen.assign((0, codegen_1$n._)`${validateName}.errors`, names_1$3.default.vErrors);
|
|
2784
|
+
if (opts.unevaluated)
|
|
2785
|
+
assignEvaluated(it);
|
|
2786
|
+
gen.return((0, codegen_1$n._)`${names_1$3.default.errors} === 0`);
|
|
2717
2787
|
}
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2788
|
+
}
|
|
2789
|
+
function assignEvaluated({ gen, evaluated, props, items: items2 }) {
|
|
2790
|
+
if (props instanceof codegen_1$n.Name)
|
|
2791
|
+
gen.assign((0, codegen_1$n._)`${evaluated}.props`, props);
|
|
2792
|
+
if (items2 instanceof codegen_1$n.Name)
|
|
2793
|
+
gen.assign((0, codegen_1$n._)`${evaluated}.items`, items2);
|
|
2794
|
+
}
|
|
2795
|
+
function schemaKeywords(it, types2, typeErrors, errsCount) {
|
|
2796
|
+
const { gen, schema, data, allErrors, opts, self } = it;
|
|
2797
|
+
const { RULES } = self;
|
|
2798
|
+
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_1$l.schemaHasRulesButRef)(schema, RULES))) {
|
|
2799
|
+
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
2800
|
+
return;
|
|
2801
|
+
}
|
|
2802
|
+
if (!opts.jtd)
|
|
2803
|
+
checkStrictTypes(it, types2);
|
|
2804
|
+
gen.block(() => {
|
|
2805
|
+
for (const group of RULES.rules)
|
|
2806
|
+
groupKeywords(group);
|
|
2807
|
+
groupKeywords(RULES.post);
|
|
2808
|
+
});
|
|
2809
|
+
function groupKeywords(group) {
|
|
2810
|
+
if (!(0, applicability_1.shouldUseGroup)(schema, group))
|
|
2740
2811
|
return;
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
groupKeywords(RULES.post);
|
|
2748
|
-
});
|
|
2749
|
-
function groupKeywords(group) {
|
|
2750
|
-
if (!(0, applicability_12.shouldUseGroup)(schema, group))
|
|
2751
|
-
return;
|
|
2752
|
-
if (group.type) {
|
|
2753
|
-
gen.if((0, dataType_2.checkDataType)(group.type, data, opts.strictNumbers));
|
|
2754
|
-
iterateKeywords(it, group);
|
|
2755
|
-
if (types2.length === 1 && types2[0] === group.type && typeErrors) {
|
|
2756
|
-
gen.else();
|
|
2757
|
-
(0, dataType_2.reportTypeError)(it);
|
|
2758
|
-
}
|
|
2759
|
-
gen.endIf();
|
|
2760
|
-
} else {
|
|
2761
|
-
iterateKeywords(it, group);
|
|
2812
|
+
if (group.type) {
|
|
2813
|
+
gen.if((0, dataType_2.checkDataType)(group.type, data, opts.strictNumbers));
|
|
2814
|
+
iterateKeywords(it, group);
|
|
2815
|
+
if (types2.length === 1 && types2[0] === group.type && typeErrors) {
|
|
2816
|
+
gen.else();
|
|
2817
|
+
(0, dataType_2.reportTypeError)(it);
|
|
2762
2818
|
}
|
|
2763
|
-
|
|
2764
|
-
|
|
2819
|
+
gen.endIf();
|
|
2820
|
+
} else {
|
|
2821
|
+
iterateKeywords(it, group);
|
|
2765
2822
|
}
|
|
2823
|
+
if (!allErrors)
|
|
2824
|
+
gen.if((0, codegen_1$n._)`${names_1$3.default.errors} === ${errsCount || 0}`);
|
|
2766
2825
|
}
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2826
|
+
}
|
|
2827
|
+
function iterateKeywords(it, group) {
|
|
2828
|
+
const { gen, schema, opts: { useDefaults } } = it;
|
|
2829
|
+
if (useDefaults)
|
|
2830
|
+
(0, defaults_1.assignDefaults)(it, group.type);
|
|
2831
|
+
gen.block(() => {
|
|
2832
|
+
for (const rule of group.rules) {
|
|
2833
|
+
if ((0, applicability_1.shouldUseRule)(schema, rule)) {
|
|
2834
|
+
keywordCode(it, rule.keyword, rule.definition, group.type);
|
|
2776
2835
|
}
|
|
2777
|
-
});
|
|
2778
|
-
}
|
|
2779
|
-
function checkStrictTypes(it, types2) {
|
|
2780
|
-
if (it.schemaEnv.meta || !it.opts.strictTypes)
|
|
2781
|
-
return;
|
|
2782
|
-
checkContextTypes(it, types2);
|
|
2783
|
-
if (!it.opts.allowUnionTypes)
|
|
2784
|
-
checkMultipleTypes(it, types2);
|
|
2785
|
-
checkKeywordTypes(it, it.dataTypes);
|
|
2786
|
-
}
|
|
2787
|
-
function checkContextTypes(it, types2) {
|
|
2788
|
-
if (!types2.length)
|
|
2789
|
-
return;
|
|
2790
|
-
if (!it.dataTypes.length) {
|
|
2791
|
-
it.dataTypes = types2;
|
|
2792
|
-
return;
|
|
2793
2836
|
}
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2837
|
+
});
|
|
2838
|
+
}
|
|
2839
|
+
function checkStrictTypes(it, types2) {
|
|
2840
|
+
if (it.schemaEnv.meta || !it.opts.strictTypes)
|
|
2841
|
+
return;
|
|
2842
|
+
checkContextTypes(it, types2);
|
|
2843
|
+
if (!it.opts.allowUnionTypes)
|
|
2844
|
+
checkMultipleTypes(it, types2);
|
|
2845
|
+
checkKeywordTypes(it, it.dataTypes);
|
|
2846
|
+
}
|
|
2847
|
+
function checkContextTypes(it, types2) {
|
|
2848
|
+
if (!types2.length)
|
|
2849
|
+
return;
|
|
2850
|
+
if (!it.dataTypes.length) {
|
|
2851
|
+
it.dataTypes = types2;
|
|
2852
|
+
return;
|
|
2800
2853
|
}
|
|
2801
|
-
|
|
2802
|
-
if (
|
|
2803
|
-
strictTypesError(it, "
|
|
2854
|
+
types2.forEach((t) => {
|
|
2855
|
+
if (!includesType(it.dataTypes, t)) {
|
|
2856
|
+
strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
|
|
2804
2857
|
}
|
|
2858
|
+
});
|
|
2859
|
+
narrowSchemaTypes(it, types2);
|
|
2860
|
+
}
|
|
2861
|
+
function checkMultipleTypes(it, ts) {
|
|
2862
|
+
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
|
|
2863
|
+
strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
2805
2864
|
}
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
}
|
|
2865
|
+
}
|
|
2866
|
+
function checkKeywordTypes(it, ts) {
|
|
2867
|
+
const rules2 = it.self.RULES.all;
|
|
2868
|
+
for (const keyword2 in rules2) {
|
|
2869
|
+
const rule = rules2[keyword2];
|
|
2870
|
+
if (typeof rule == "object" && (0, applicability_1.shouldUseRule)(it.schema, rule)) {
|
|
2871
|
+
const { type: type2 } = rule.definition;
|
|
2872
|
+
if (type2.length && !type2.some((t) => hasApplicableType(ts, t))) {
|
|
2873
|
+
strictTypesError(it, `missing type "${type2.join(",")}" for keyword "${keyword2}"`);
|
|
2815
2874
|
}
|
|
2816
2875
|
}
|
|
2817
2876
|
}
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
}
|
|
2861
|
-
}
|
|
2862
|
-
if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
|
|
2863
|
-
this.errsCount = it.gen.const("_errs", names_12.default.errors);
|
|
2864
|
-
}
|
|
2865
|
-
}
|
|
2866
|
-
result(condition, successAction, failAction) {
|
|
2867
|
-
this.failResult((0, codegen_12.not)(condition), successAction, failAction);
|
|
2868
|
-
}
|
|
2869
|
-
failResult(condition, successAction, failAction) {
|
|
2870
|
-
this.gen.if(condition);
|
|
2871
|
-
if (failAction)
|
|
2872
|
-
failAction();
|
|
2873
|
-
else
|
|
2874
|
-
this.error();
|
|
2875
|
-
if (successAction) {
|
|
2876
|
-
this.gen.else();
|
|
2877
|
-
successAction();
|
|
2878
|
-
if (this.allErrors)
|
|
2879
|
-
this.gen.endIf();
|
|
2880
|
-
} else {
|
|
2881
|
-
if (this.allErrors)
|
|
2882
|
-
this.gen.endIf();
|
|
2883
|
-
else
|
|
2884
|
-
this.gen.else();
|
|
2877
|
+
}
|
|
2878
|
+
function hasApplicableType(schTs, kwdT) {
|
|
2879
|
+
return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
|
|
2880
|
+
}
|
|
2881
|
+
function includesType(ts, t) {
|
|
2882
|
+
return ts.includes(t) || t === "integer" && ts.includes("number");
|
|
2883
|
+
}
|
|
2884
|
+
function narrowSchemaTypes(it, withTypes) {
|
|
2885
|
+
const ts = [];
|
|
2886
|
+
for (const t of it.dataTypes) {
|
|
2887
|
+
if (includesType(withTypes, t))
|
|
2888
|
+
ts.push(t);
|
|
2889
|
+
else if (withTypes.includes("integer") && t === "number")
|
|
2890
|
+
ts.push("integer");
|
|
2891
|
+
}
|
|
2892
|
+
it.dataTypes = ts;
|
|
2893
|
+
}
|
|
2894
|
+
function strictTypesError(it, msg) {
|
|
2895
|
+
const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
|
|
2896
|
+
msg += ` at "${schemaPath}" (strictTypes)`;
|
|
2897
|
+
(0, util_1$l.checkStrictMode)(it, msg, it.opts.strictTypes);
|
|
2898
|
+
}
|
|
2899
|
+
class KeywordCxt {
|
|
2900
|
+
constructor(it, def2, keyword2) {
|
|
2901
|
+
(0, keyword_1.validateKeywordUsage)(it, def2, keyword2);
|
|
2902
|
+
this.gen = it.gen;
|
|
2903
|
+
this.allErrors = it.allErrors;
|
|
2904
|
+
this.keyword = keyword2;
|
|
2905
|
+
this.data = it.data;
|
|
2906
|
+
this.schema = it.schema[keyword2];
|
|
2907
|
+
this.$data = def2.$data && it.opts.$data && this.schema && this.schema.$data;
|
|
2908
|
+
this.schemaValue = (0, util_1$l.schemaRefOrVal)(it, this.schema, keyword2, this.$data);
|
|
2909
|
+
this.schemaType = def2.schemaType;
|
|
2910
|
+
this.parentSchema = it.schema;
|
|
2911
|
+
this.params = {};
|
|
2912
|
+
this.it = it;
|
|
2913
|
+
this.def = def2;
|
|
2914
|
+
if (this.$data) {
|
|
2915
|
+
this.schemaCode = it.gen.const("vSchema", getData(this.$data, it));
|
|
2916
|
+
} else {
|
|
2917
|
+
this.schemaCode = this.schemaValue;
|
|
2918
|
+
if (!(0, keyword_1.validSchemaType)(this.schema, def2.schemaType, def2.allowUndefined)) {
|
|
2919
|
+
throw new Error(`${keyword2} value must be ${JSON.stringify(def2.schemaType)}`);
|
|
2885
2920
|
}
|
|
2886
2921
|
}
|
|
2887
|
-
|
|
2888
|
-
this.
|
|
2922
|
+
if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
|
|
2923
|
+
this.errsCount = it.gen.const("_errs", names_1$3.default.errors);
|
|
2889
2924
|
}
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2925
|
+
}
|
|
2926
|
+
result(condition, successAction, failAction) {
|
|
2927
|
+
this.failResult((0, codegen_1$n.not)(condition), successAction, failAction);
|
|
2928
|
+
}
|
|
2929
|
+
failResult(condition, successAction, failAction) {
|
|
2930
|
+
this.gen.if(condition);
|
|
2931
|
+
if (failAction)
|
|
2932
|
+
failAction();
|
|
2933
|
+
else
|
|
2898
2934
|
this.error();
|
|
2935
|
+
if (successAction) {
|
|
2936
|
+
this.gen.else();
|
|
2937
|
+
successAction();
|
|
2938
|
+
if (this.allErrors)
|
|
2939
|
+
this.gen.endIf();
|
|
2940
|
+
} else {
|
|
2899
2941
|
if (this.allErrors)
|
|
2900
2942
|
this.gen.endIf();
|
|
2901
2943
|
else
|
|
2902
2944
|
this.gen.else();
|
|
2903
2945
|
}
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
if (errorParams) {
|
|
2912
|
-
this.setParams(errorParams);
|
|
2913
|
-
this._error(append, errorPaths);
|
|
2914
|
-
this.setParams({});
|
|
2915
|
-
return;
|
|
2916
|
-
}
|
|
2917
|
-
this._error(append, errorPaths);
|
|
2918
|
-
}
|
|
2919
|
-
_error(append, errorPaths) {
|
|
2920
|
-
(append ? errors_12.reportExtraError : errors_12.reportError)(this, this.def.error, errorPaths);
|
|
2921
|
-
}
|
|
2922
|
-
$dataError() {
|
|
2923
|
-
(0, errors_12.reportError)(this, this.def.$dataError || errors_12.keyword$DataError);
|
|
2924
|
-
}
|
|
2925
|
-
reset() {
|
|
2926
|
-
if (this.errsCount === void 0)
|
|
2927
|
-
throw new Error('add "trackErrors" to keyword definition');
|
|
2928
|
-
(0, errors_12.resetErrorsCount)(this.gen, this.errsCount);
|
|
2929
|
-
}
|
|
2930
|
-
ok(cond) {
|
|
2946
|
+
}
|
|
2947
|
+
pass(condition, failAction) {
|
|
2948
|
+
this.failResult((0, codegen_1$n.not)(condition), void 0, failAction);
|
|
2949
|
+
}
|
|
2950
|
+
fail(condition) {
|
|
2951
|
+
if (condition === void 0) {
|
|
2952
|
+
this.error();
|
|
2931
2953
|
if (!this.allErrors)
|
|
2932
|
-
this.gen.if(
|
|
2954
|
+
this.gen.if(false);
|
|
2955
|
+
return;
|
|
2933
2956
|
}
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2957
|
+
this.gen.if(condition);
|
|
2958
|
+
this.error();
|
|
2959
|
+
if (this.allErrors)
|
|
2960
|
+
this.gen.endIf();
|
|
2961
|
+
else
|
|
2962
|
+
this.gen.else();
|
|
2963
|
+
}
|
|
2964
|
+
fail$data(condition) {
|
|
2965
|
+
if (!this.$data)
|
|
2966
|
+
return this.fail(condition);
|
|
2967
|
+
const { schemaCode } = this;
|
|
2968
|
+
this.fail((0, codegen_1$n._)`${schemaCode} !== undefined && (${(0, codegen_1$n.or)(this.invalid$data(), condition)})`);
|
|
2969
|
+
}
|
|
2970
|
+
error(append, errorParams, errorPaths) {
|
|
2971
|
+
if (errorParams) {
|
|
2972
|
+
this.setParams(errorParams);
|
|
2973
|
+
this._error(append, errorPaths);
|
|
2974
|
+
this.setParams({});
|
|
2975
|
+
return;
|
|
2939
2976
|
}
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2977
|
+
this._error(append, errorPaths);
|
|
2978
|
+
}
|
|
2979
|
+
_error(append, errorPaths) {
|
|
2980
|
+
(append ? errors_1.reportExtraError : errors_1.reportError)(this, this.def.error, errorPaths);
|
|
2981
|
+
}
|
|
2982
|
+
$dataError() {
|
|
2983
|
+
(0, errors_1.reportError)(this, this.def.$dataError || errors_1.keyword$DataError);
|
|
2984
|
+
}
|
|
2985
|
+
reset() {
|
|
2986
|
+
if (this.errsCount === void 0)
|
|
2987
|
+
throw new Error('add "trackErrors" to keyword definition');
|
|
2988
|
+
(0, errors_1.resetErrorsCount)(this.gen, this.errsCount);
|
|
2989
|
+
}
|
|
2990
|
+
ok(cond) {
|
|
2991
|
+
if (!this.allErrors)
|
|
2992
|
+
this.gen.if(cond);
|
|
2993
|
+
}
|
|
2994
|
+
setParams(obj, assign) {
|
|
2995
|
+
if (assign)
|
|
2996
|
+
Object.assign(this.params, obj);
|
|
2997
|
+
else
|
|
2998
|
+
this.params = obj;
|
|
2999
|
+
}
|
|
3000
|
+
block$data(valid, codeBlock, $dataValid = codegen_1$n.nil) {
|
|
3001
|
+
this.gen.block(() => {
|
|
3002
|
+
this.check$data(valid, $dataValid);
|
|
3003
|
+
codeBlock();
|
|
3004
|
+
});
|
|
3005
|
+
}
|
|
3006
|
+
check$data(valid = codegen_1$n.nil, $dataValid = codegen_1$n.nil) {
|
|
3007
|
+
if (!this.$data)
|
|
3008
|
+
return;
|
|
3009
|
+
const { gen, schemaCode, schemaType, def: def2 } = this;
|
|
3010
|
+
gen.if((0, codegen_1$n.or)((0, codegen_1$n._)`${schemaCode} === undefined`, $dataValid));
|
|
3011
|
+
if (valid !== codegen_1$n.nil)
|
|
3012
|
+
gen.assign(valid, true);
|
|
3013
|
+
if (schemaType.length || def2.validateSchema) {
|
|
3014
|
+
gen.elseIf(this.invalid$data());
|
|
3015
|
+
this.$dataError();
|
|
3016
|
+
if (valid !== codegen_1$n.nil)
|
|
3017
|
+
gen.assign(valid, false);
|
|
2945
3018
|
}
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
gen.assign(valid, false);
|
|
3019
|
+
gen.else();
|
|
3020
|
+
}
|
|
3021
|
+
invalid$data() {
|
|
3022
|
+
const { gen, schemaCode, schemaType, def: def2, it } = this;
|
|
3023
|
+
return (0, codegen_1$n.or)(wrong$DataType(), invalid$DataSchema());
|
|
3024
|
+
function wrong$DataType() {
|
|
3025
|
+
if (schemaType.length) {
|
|
3026
|
+
if (!(schemaCode instanceof codegen_1$n.Name))
|
|
3027
|
+
throw new Error("ajv implementation error");
|
|
3028
|
+
const st = Array.isArray(schemaType) ? schemaType : [schemaType];
|
|
3029
|
+
return (0, codegen_1$n._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
|
|
2958
3030
|
}
|
|
2959
|
-
|
|
3031
|
+
return codegen_1$n.nil;
|
|
2960
3032
|
}
|
|
2961
|
-
invalid$
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
if (schemaType.length) {
|
|
2966
|
-
if (!(schemaCode instanceof codegen_12.Name))
|
|
2967
|
-
throw new Error("ajv implementation error");
|
|
2968
|
-
const st = Array.isArray(schemaType) ? schemaType : [schemaType];
|
|
2969
|
-
return (0, codegen_12._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
|
|
2970
|
-
}
|
|
2971
|
-
return codegen_12.nil;
|
|
2972
|
-
}
|
|
2973
|
-
function invalid$DataSchema() {
|
|
2974
|
-
if (def2.validateSchema) {
|
|
2975
|
-
const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
|
|
2976
|
-
return (0, codegen_12._)`!${validateSchemaRef}(${schemaCode})`;
|
|
2977
|
-
}
|
|
2978
|
-
return codegen_12.nil;
|
|
3033
|
+
function invalid$DataSchema() {
|
|
3034
|
+
if (def2.validateSchema) {
|
|
3035
|
+
const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
|
|
3036
|
+
return (0, codegen_1$n._)`!${validateSchemaRef}(${schemaCode})`;
|
|
2979
3037
|
}
|
|
3038
|
+
return codegen_1$n.nil;
|
|
2980
3039
|
}
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
3040
|
+
}
|
|
3041
|
+
subschema(appl, valid) {
|
|
3042
|
+
const subschema2 = (0, subschema_1.getSubschema)(this.it, appl);
|
|
3043
|
+
(0, subschema_1.extendSubschemaData)(subschema2, this.it, appl);
|
|
3044
|
+
(0, subschema_1.extendSubschemaMode)(subschema2, appl);
|
|
3045
|
+
const nextContext = { ...this.it, ...subschema2, items: void 0, props: void 0 };
|
|
3046
|
+
subschemaCode(nextContext, valid);
|
|
3047
|
+
return nextContext;
|
|
3048
|
+
}
|
|
3049
|
+
mergeEvaluated(schemaCxt, toName) {
|
|
3050
|
+
const { it, gen } = this;
|
|
3051
|
+
if (!it.opts.unevaluated)
|
|
3052
|
+
return;
|
|
3053
|
+
if (it.props !== true && schemaCxt.props !== void 0) {
|
|
3054
|
+
it.props = util_1$l.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
|
|
2988
3055
|
}
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
if (!it.opts.unevaluated)
|
|
2992
|
-
return;
|
|
2993
|
-
if (it.props !== true && schemaCxt.props !== void 0) {
|
|
2994
|
-
it.props = util_12.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
|
|
2995
|
-
}
|
|
2996
|
-
if (it.items !== true && schemaCxt.items !== void 0) {
|
|
2997
|
-
it.items = util_12.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
|
|
2998
|
-
}
|
|
3056
|
+
if (it.items !== true && schemaCxt.items !== void 0) {
|
|
3057
|
+
it.items = util_1$l.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
|
|
2999
3058
|
}
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3059
|
+
}
|
|
3060
|
+
mergeValidEvaluated(schemaCxt, valid) {
|
|
3061
|
+
const { it, gen } = this;
|
|
3062
|
+
if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
|
|
3063
|
+
gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_1$n.Name));
|
|
3064
|
+
return true;
|
|
3006
3065
|
}
|
|
3007
3066
|
}
|
|
3008
|
-
validate.KeywordCxt = KeywordCxt;
|
|
3009
|
-
function keywordCode(it, keyword2, def2, ruleType) {
|
|
3010
|
-
const cxt = new KeywordCxt(it, def2, keyword2);
|
|
3011
|
-
if ("code" in def2) {
|
|
3012
|
-
def2.code(cxt, ruleType);
|
|
3013
|
-
} else if (cxt.$data && def2.validate) {
|
|
3014
|
-
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
3015
|
-
} else if ("macro" in def2) {
|
|
3016
|
-
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
3017
|
-
} else if (def2.compile || def2.validate) {
|
|
3018
|
-
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
3019
|
-
}
|
|
3020
|
-
}
|
|
3021
|
-
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
3022
|
-
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
3023
|
-
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
3024
|
-
let jsonPointer;
|
|
3025
|
-
let data;
|
|
3026
|
-
if ($data === "")
|
|
3027
|
-
return names_12.default.rootData;
|
|
3028
|
-
if ($data[0] === "/") {
|
|
3029
|
-
if (!JSON_POINTER.test($data))
|
|
3030
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
3031
|
-
jsonPointer = $data;
|
|
3032
|
-
data = names_12.default.rootData;
|
|
3033
|
-
} else {
|
|
3034
|
-
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
3035
|
-
if (!matches)
|
|
3036
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
3037
|
-
const up = +matches[1];
|
|
3038
|
-
jsonPointer = matches[2];
|
|
3039
|
-
if (jsonPointer === "#") {
|
|
3040
|
-
if (up >= dataLevel)
|
|
3041
|
-
throw new Error(errorMsg("property/index", up));
|
|
3042
|
-
return dataPathArr[dataLevel - up];
|
|
3043
|
-
}
|
|
3044
|
-
if (up > dataLevel)
|
|
3045
|
-
throw new Error(errorMsg("data", up));
|
|
3046
|
-
data = dataNames[dataLevel - up];
|
|
3047
|
-
if (!jsonPointer)
|
|
3048
|
-
return data;
|
|
3049
|
-
}
|
|
3050
|
-
let expr = data;
|
|
3051
|
-
const segments = jsonPointer.split("/");
|
|
3052
|
-
for (const segment of segments) {
|
|
3053
|
-
if (segment) {
|
|
3054
|
-
data = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)((0, util_12.unescapeJsonPointer)(segment))}`;
|
|
3055
|
-
expr = (0, codegen_12._)`${expr} && ${data}`;
|
|
3056
|
-
}
|
|
3057
|
-
}
|
|
3058
|
-
return expr;
|
|
3059
|
-
function errorMsg(pointerType, up) {
|
|
3060
|
-
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
3061
|
-
}
|
|
3062
|
-
}
|
|
3063
|
-
validate.getData = getData;
|
|
3064
|
-
return validate;
|
|
3065
3067
|
}
|
|
3068
|
+
validate.KeywordCxt = KeywordCxt;
|
|
3069
|
+
function keywordCode(it, keyword2, def2, ruleType) {
|
|
3070
|
+
const cxt = new KeywordCxt(it, def2, keyword2);
|
|
3071
|
+
if ("code" in def2) {
|
|
3072
|
+
def2.code(cxt, ruleType);
|
|
3073
|
+
} else if (cxt.$data && def2.validate) {
|
|
3074
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
3075
|
+
} else if ("macro" in def2) {
|
|
3076
|
+
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
3077
|
+
} else if (def2.compile || def2.validate) {
|
|
3078
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
3082
|
+
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
3083
|
+
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
3084
|
+
let jsonPointer;
|
|
3085
|
+
let data;
|
|
3086
|
+
if ($data === "")
|
|
3087
|
+
return names_1$3.default.rootData;
|
|
3088
|
+
if ($data[0] === "/") {
|
|
3089
|
+
if (!JSON_POINTER.test($data))
|
|
3090
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
3091
|
+
jsonPointer = $data;
|
|
3092
|
+
data = names_1$3.default.rootData;
|
|
3093
|
+
} else {
|
|
3094
|
+
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
3095
|
+
if (!matches)
|
|
3096
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
3097
|
+
const up = +matches[1];
|
|
3098
|
+
jsonPointer = matches[2];
|
|
3099
|
+
if (jsonPointer === "#") {
|
|
3100
|
+
if (up >= dataLevel)
|
|
3101
|
+
throw new Error(errorMsg("property/index", up));
|
|
3102
|
+
return dataPathArr[dataLevel - up];
|
|
3103
|
+
}
|
|
3104
|
+
if (up > dataLevel)
|
|
3105
|
+
throw new Error(errorMsg("data", up));
|
|
3106
|
+
data = dataNames[dataLevel - up];
|
|
3107
|
+
if (!jsonPointer)
|
|
3108
|
+
return data;
|
|
3109
|
+
}
|
|
3110
|
+
let expr = data;
|
|
3111
|
+
const segments = jsonPointer.split("/");
|
|
3112
|
+
for (const segment of segments) {
|
|
3113
|
+
if (segment) {
|
|
3114
|
+
data = (0, codegen_1$n._)`${data}${(0, codegen_1$n.getProperty)((0, util_1$l.unescapeJsonPointer)(segment))}`;
|
|
3115
|
+
expr = (0, codegen_1$n._)`${expr} && ${data}`;
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
return expr;
|
|
3119
|
+
function errorMsg(pointerType, up) {
|
|
3120
|
+
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
validate.getData = getData;
|
|
3066
3124
|
var validation_error = {};
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
constructor(errors2) {
|
|
3074
|
-
super("validation failed");
|
|
3075
|
-
this.errors = errors2;
|
|
3076
|
-
this.ajv = this.validation = true;
|
|
3077
|
-
}
|
|
3125
|
+
Object.defineProperty(validation_error, "__esModule", { value: true });
|
|
3126
|
+
class ValidationError extends Error {
|
|
3127
|
+
constructor(errors2) {
|
|
3128
|
+
super("validation failed");
|
|
3129
|
+
this.errors = errors2;
|
|
3130
|
+
this.ajv = this.validation = true;
|
|
3078
3131
|
}
|
|
3079
|
-
validation_error.default = ValidationError;
|
|
3080
|
-
return validation_error;
|
|
3081
3132
|
}
|
|
3133
|
+
validation_error.default = ValidationError;
|
|
3082
3134
|
var ref_error = {};
|
|
3083
3135
|
Object.defineProperty(ref_error, "__esModule", { value: true });
|
|
3084
3136
|
const resolve_1$1 = resolve$2;
|
|
@@ -3094,11 +3146,11 @@ var compile = {};
|
|
|
3094
3146
|
Object.defineProperty(compile, "__esModule", { value: true });
|
|
3095
3147
|
compile.resolveSchema = compile.getCompilingSchema = compile.resolveRef = compile.compileSchema = compile.SchemaEnv = void 0;
|
|
3096
3148
|
const codegen_1$m = codegen;
|
|
3097
|
-
const validation_error_1 =
|
|
3098
|
-
const names_1$2 =
|
|
3149
|
+
const validation_error_1 = validation_error;
|
|
3150
|
+
const names_1$2 = names$1;
|
|
3099
3151
|
const resolve_1 = resolve$2;
|
|
3100
3152
|
const util_1$k = util;
|
|
3101
|
-
const validate_1$1 =
|
|
3153
|
+
const validate_1$1 = validate;
|
|
3102
3154
|
class SchemaEnv {
|
|
3103
3155
|
constructor(env) {
|
|
3104
3156
|
var _a;
|
|
@@ -4027,7 +4079,7 @@ uri$1.default = uri;
|
|
|
4027
4079
|
(function(exports$1) {
|
|
4028
4080
|
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
4029
4081
|
exports$1.CodeGen = exports$1.Name = exports$1.nil = exports$1.stringify = exports$1.str = exports$1._ = exports$1.KeywordCxt = void 0;
|
|
4030
|
-
var validate_12 =
|
|
4082
|
+
var validate_12 = validate;
|
|
4031
4083
|
Object.defineProperty(exports$1, "KeywordCxt", { enumerable: true, get: function() {
|
|
4032
4084
|
return validate_12.KeywordCxt;
|
|
4033
4085
|
} });
|
|
@@ -4050,7 +4102,7 @@ uri$1.default = uri;
|
|
|
4050
4102
|
Object.defineProperty(exports$1, "CodeGen", { enumerable: true, get: function() {
|
|
4051
4103
|
return codegen_12.CodeGen;
|
|
4052
4104
|
} });
|
|
4053
|
-
const validation_error_12 =
|
|
4105
|
+
const validation_error_12 = validation_error;
|
|
4054
4106
|
const ref_error_12 = ref_error;
|
|
4055
4107
|
const rules_12 = rules;
|
|
4056
4108
|
const compile_12 = compile;
|
|
@@ -4647,7 +4699,7 @@ ref.callRef = ref.getValidate = void 0;
|
|
|
4647
4699
|
const ref_error_1$1 = ref_error;
|
|
4648
4700
|
const code_1$8 = code;
|
|
4649
4701
|
const codegen_1$l = codegen;
|
|
4650
|
-
const names_1$1 =
|
|
4702
|
+
const names_1$1 = names$1;
|
|
4651
4703
|
const compile_1$1 = compile;
|
|
4652
4704
|
const util_1$j = util;
|
|
4653
4705
|
const def$r = {
|
|
@@ -5531,7 +5583,7 @@ var additionalProperties = {};
|
|
|
5531
5583
|
Object.defineProperty(additionalProperties, "__esModule", { value: true });
|
|
5532
5584
|
const code_1$3 = code;
|
|
5533
5585
|
const codegen_1$5 = codegen;
|
|
5534
|
-
const names_1 =
|
|
5586
|
+
const names_1 = names$1;
|
|
5535
5587
|
const util_1$8 = util;
|
|
5536
5588
|
const error$4 = {
|
|
5537
5589
|
message: "must NOT have additional properties",
|
|
@@ -5629,7 +5681,7 @@ const def$a = {
|
|
|
5629
5681
|
additionalProperties.default = def$a;
|
|
5630
5682
|
var properties$1 = {};
|
|
5631
5683
|
Object.defineProperty(properties$1, "__esModule", { value: true });
|
|
5632
|
-
const validate_1 =
|
|
5684
|
+
const validate_1 = validate;
|
|
5633
5685
|
const code_1$2 = code;
|
|
5634
5686
|
const util_1$7 = util;
|
|
5635
5687
|
const additionalProperties_1$1 = additionalProperties;
|
|
@@ -6480,7 +6532,7 @@ const require$$3 = {
|
|
|
6480
6532
|
module2.exports.Ajv = Ajv;
|
|
6481
6533
|
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
6482
6534
|
exports$1.default = Ajv;
|
|
6483
|
-
var validate_12 =
|
|
6535
|
+
var validate_12 = validate;
|
|
6484
6536
|
Object.defineProperty(exports$1, "KeywordCxt", { enumerable: true, get: function() {
|
|
6485
6537
|
return validate_12.KeywordCxt;
|
|
6486
6538
|
} });
|
|
@@ -6503,7 +6555,7 @@ const require$$3 = {
|
|
|
6503
6555
|
Object.defineProperty(exports$1, "CodeGen", { enumerable: true, get: function() {
|
|
6504
6556
|
return codegen_12.CodeGen;
|
|
6505
6557
|
} });
|
|
6506
|
-
var validation_error_12 =
|
|
6558
|
+
var validation_error_12 = validation_error;
|
|
6507
6559
|
Object.defineProperty(exports$1, "ValidationError", { enumerable: true, get: function() {
|
|
6508
6560
|
return validation_error_12.default;
|
|
6509
6561
|
} });
|
|
@@ -6567,7 +6619,7 @@ const _sfc_main$b = /* @__PURE__ */ vue.defineComponent({
|
|
|
6567
6619
|
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(__props.schema.properties, (value, key) => {
|
|
6568
6620
|
var _a, _b;
|
|
6569
6621
|
return vue.openBlock(), vue.createElementBlock(vue.Fragment, { key }, [
|
|
6570
|
-
resolveFormItemComponent((_a = value.option) == null ? void 0 : _a.comType) ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(resolveFormItemComponent((_b = value.option) == null ? void 0 : _b.comType)), {
|
|
6622
|
+
resolveFormItemComponent((_a = value.option) == null ? void 0 : _a.comType) ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(resolveFormItemComponent((_b = value.option) == null ? void 0 : _b.comType)), vue.mergeProps({
|
|
6571
6623
|
key: 0,
|
|
6572
6624
|
ref_for: true,
|
|
6573
6625
|
ref_key: "formItemListRef",
|
|
@@ -6575,23 +6627,14 @@ const _sfc_main$b = /* @__PURE__ */ vue.defineComponent({
|
|
|
6575
6627
|
model: __props.model ? __props.model[key] : void 0,
|
|
6576
6628
|
ItemKey: key,
|
|
6577
6629
|
schema: value
|
|
6578
|
-
}, null,
|
|
6630
|
+
}, { ref_for: true }, value.option), null, 16, ["model", "ItemKey", "schema"])) : vue.createCommentVNode("", true)
|
|
6579
6631
|
], 64);
|
|
6580
6632
|
}), 128))
|
|
6581
6633
|
])) : vue.createCommentVNode("", true);
|
|
6582
6634
|
};
|
|
6583
6635
|
}
|
|
6584
6636
|
});
|
|
6585
|
-
const schemaForm = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["__scopeId", "data-v-
|
|
6586
|
-
let requestFn = null;
|
|
6587
|
-
function setRequestClient(fn) {
|
|
6588
|
-
requestFn = fn;
|
|
6589
|
-
}
|
|
6590
|
-
function request(options) {
|
|
6591
|
-
if (!requestFn) throw new Error("请先使用 setRequestClient 注册请求客户端");
|
|
6592
|
-
console.log("requestrequestrequest");
|
|
6593
|
-
return requestFn(options);
|
|
6594
|
-
}
|
|
6637
|
+
const schemaForm = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["__scopeId", "data-v-cc1d8aee"]]);
|
|
6595
6638
|
const _hoisted_1$6 = { class: "createForm" };
|
|
6596
6639
|
const _sfc_main$a = /* @__PURE__ */ vue.defineComponent({
|
|
6597
6640
|
__name: "createForm",
|