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