page-schema-enginer-shun 1.0.19 → 1.0.20
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 +886 -843
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +886 -843
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +886 -843
- package/dist/index.umd.js.map +1 -1
- package/dist/style.css +2 -2
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1347,8 +1347,8 @@ var scope = {};
|
|
|
1347
1347
|
var util = {};
|
|
1348
1348
|
Object.defineProperty(util, "__esModule", { value: true });
|
|
1349
1349
|
util.checkStrictMode = util.getErrorPath = util.Type = util.useFunc = util.setEvaluated = util.evaluatedPropsToName = util.mergeEvaluated = util.eachItem = util.unescapeJsonPointer = util.escapeJsonPointer = util.escapeFragment = util.unescapeFragment = util.schemaRefOrVal = util.schemaHasRulesButRef = util.schemaHasRules = util.checkUnknownRules = util.alwaysValidSchema = util.toHash = void 0;
|
|
1350
|
-
const codegen_1$
|
|
1351
|
-
const code_1$
|
|
1350
|
+
const codegen_1$p = codegen;
|
|
1351
|
+
const code_1$9 = code$1;
|
|
1352
1352
|
function toHash(arr) {
|
|
1353
1353
|
const hash = {};
|
|
1354
1354
|
for (const item of arr)
|
|
@@ -1401,9 +1401,9 @@ function schemaRefOrVal({ topSchemaRef, schemaPath }, schema, keyword2, $data) {
|
|
|
1401
1401
|
if (typeof schema == "number" || typeof schema == "boolean")
|
|
1402
1402
|
return schema;
|
|
1403
1403
|
if (typeof schema == "string")
|
|
1404
|
-
return (0, codegen_1$
|
|
1404
|
+
return (0, codegen_1$p._)`${schema}`;
|
|
1405
1405
|
}
|
|
1406
|
-
return (0, codegen_1$
|
|
1406
|
+
return (0, codegen_1$p._)`${topSchemaRef}${schemaPath}${(0, codegen_1$p.getProperty)(keyword2)}`;
|
|
1407
1407
|
}
|
|
1408
1408
|
util.schemaRefOrVal = schemaRefOrVal;
|
|
1409
1409
|
function unescapeFragment(str) {
|
|
@@ -1435,20 +1435,20 @@ function eachItem(xs, f) {
|
|
|
1435
1435
|
util.eachItem = eachItem;
|
|
1436
1436
|
function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues, resultToName }) {
|
|
1437
1437
|
return (gen, from, to, toName) => {
|
|
1438
|
-
const res = to === void 0 ? from : to instanceof codegen_1$
|
|
1439
|
-
return toName === codegen_1$
|
|
1438
|
+
const res = to === void 0 ? from : to instanceof codegen_1$p.Name ? (from instanceof codegen_1$p.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1$p.Name ? (mergeToName(gen, to, from), from) : mergeValues(from, to);
|
|
1439
|
+
return toName === codegen_1$p.Name && !(res instanceof codegen_1$p.Name) ? resultToName(gen, res) : res;
|
|
1440
1440
|
};
|
|
1441
1441
|
}
|
|
1442
1442
|
util.mergeEvaluated = {
|
|
1443
1443
|
props: makeMergeEvaluated({
|
|
1444
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
1445
|
-
gen.if((0, codegen_1$
|
|
1444
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$p._)`${to} !== true && ${from} !== undefined`, () => {
|
|
1445
|
+
gen.if((0, codegen_1$p._)`${from} === true`, () => gen.assign(to, true), () => gen.assign(to, (0, codegen_1$p._)`${to} || {}`).code((0, codegen_1$p._)`Object.assign(${to}, ${from})`));
|
|
1446
1446
|
}),
|
|
1447
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
1447
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$p._)`${to} !== true`, () => {
|
|
1448
1448
|
if (from === true) {
|
|
1449
1449
|
gen.assign(to, true);
|
|
1450
1450
|
} else {
|
|
1451
|
-
gen.assign(to, (0, codegen_1$
|
|
1451
|
+
gen.assign(to, (0, codegen_1$p._)`${to} || {}`);
|
|
1452
1452
|
setEvaluated(gen, to, from);
|
|
1453
1453
|
}
|
|
1454
1454
|
}),
|
|
@@ -1456,8 +1456,8 @@ util.mergeEvaluated = {
|
|
|
1456
1456
|
resultToName: evaluatedPropsToName
|
|
1457
1457
|
}),
|
|
1458
1458
|
items: makeMergeEvaluated({
|
|
1459
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
1460
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
1459
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$p._)`${to} !== true && ${from} !== undefined`, () => gen.assign(to, (0, codegen_1$p._)`${from} === true ? true : ${to} > ${from} ? ${to} : ${from}`)),
|
|
1460
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$p._)`${to} !== true`, () => gen.assign(to, from === true ? true : (0, codegen_1$p._)`${to} > ${from} ? ${to} : ${from}`)),
|
|
1461
1461
|
mergeValues: (from, to) => from === true ? true : Math.max(from, to),
|
|
1462
1462
|
resultToName: (gen, items2) => gen.var("items", items2)
|
|
1463
1463
|
})
|
|
@@ -1465,21 +1465,21 @@ util.mergeEvaluated = {
|
|
|
1465
1465
|
function evaluatedPropsToName(gen, ps) {
|
|
1466
1466
|
if (ps === true)
|
|
1467
1467
|
return gen.var("props", true);
|
|
1468
|
-
const props = gen.var("props", (0, codegen_1$
|
|
1468
|
+
const props = gen.var("props", (0, codegen_1$p._)`{}`);
|
|
1469
1469
|
if (ps !== void 0)
|
|
1470
1470
|
setEvaluated(gen, props, ps);
|
|
1471
1471
|
return props;
|
|
1472
1472
|
}
|
|
1473
1473
|
util.evaluatedPropsToName = evaluatedPropsToName;
|
|
1474
1474
|
function setEvaluated(gen, props, ps) {
|
|
1475
|
-
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$
|
|
1475
|
+
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$p._)`${props}${(0, codegen_1$p.getProperty)(p)}`, true));
|
|
1476
1476
|
}
|
|
1477
1477
|
util.setEvaluated = setEvaluated;
|
|
1478
1478
|
const snippets = {};
|
|
1479
1479
|
function useFunc(gen, f) {
|
|
1480
1480
|
return gen.scopeValue("func", {
|
|
1481
1481
|
ref: f,
|
|
1482
|
-
code: snippets[f.code] || (snippets[f.code] = new code_1$
|
|
1482
|
+
code: snippets[f.code] || (snippets[f.code] = new code_1$9._Code(f.code))
|
|
1483
1483
|
});
|
|
1484
1484
|
}
|
|
1485
1485
|
util.useFunc = useFunc;
|
|
@@ -1489,11 +1489,11 @@ var Type;
|
|
|
1489
1489
|
Type2[Type2["Str"] = 1] = "Str";
|
|
1490
1490
|
})(Type || (util.Type = Type = {}));
|
|
1491
1491
|
function getErrorPath(dataProp, dataPropType, jsPropertySyntax) {
|
|
1492
|
-
if (dataProp instanceof codegen_1$
|
|
1492
|
+
if (dataProp instanceof codegen_1$p.Name) {
|
|
1493
1493
|
const isNumber = dataPropType === Type.Num;
|
|
1494
|
-
return jsPropertySyntax ? isNumber ? (0, codegen_1$
|
|
1494
|
+
return jsPropertySyntax ? isNumber ? (0, codegen_1$p._)`"[" + ${dataProp} + "]"` : (0, codegen_1$p._)`"['" + ${dataProp} + "']"` : isNumber ? (0, codegen_1$p._)`"/" + ${dataProp}` : (0, codegen_1$p._)`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")`;
|
|
1495
1495
|
}
|
|
1496
|
-
return jsPropertySyntax ? (0, codegen_1$
|
|
1496
|
+
return jsPropertySyntax ? (0, codegen_1$p.getProperty)(dataProp).toString() : "/" + escapeJsonPointer(dataProp);
|
|
1497
1497
|
}
|
|
1498
1498
|
util.getErrorPath = getErrorPath;
|
|
1499
1499
|
function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
@@ -1505,45 +1505,51 @@ function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
|
1505
1505
|
it.self.logger.warn(msg);
|
|
1506
1506
|
}
|
|
1507
1507
|
util.checkStrictMode = checkStrictMode;
|
|
1508
|
-
var names
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1508
|
+
var names = {};
|
|
1509
|
+
var hasRequiredNames;
|
|
1510
|
+
function requireNames() {
|
|
1511
|
+
if (hasRequiredNames) return names;
|
|
1512
|
+
hasRequiredNames = 1;
|
|
1513
|
+
Object.defineProperty(names, "__esModule", { value: true });
|
|
1514
|
+
const codegen_12 = codegen;
|
|
1515
|
+
const names$1 = {
|
|
1516
|
+
// validation function arguments
|
|
1517
|
+
data: new codegen_12.Name("data"),
|
|
1518
|
+
// data passed to validation function
|
|
1519
|
+
// args passed from referencing schema
|
|
1520
|
+
valCxt: new codegen_12.Name("valCxt"),
|
|
1521
|
+
// validation/data context - should not be used directly, it is destructured to the names below
|
|
1522
|
+
instancePath: new codegen_12.Name("instancePath"),
|
|
1523
|
+
parentData: new codegen_12.Name("parentData"),
|
|
1524
|
+
parentDataProperty: new codegen_12.Name("parentDataProperty"),
|
|
1525
|
+
rootData: new codegen_12.Name("rootData"),
|
|
1526
|
+
// root data - same as the data passed to the first/top validation function
|
|
1527
|
+
dynamicAnchors: new codegen_12.Name("dynamicAnchors"),
|
|
1528
|
+
// used to support recursiveRef and dynamicRef
|
|
1529
|
+
// function scoped variables
|
|
1530
|
+
vErrors: new codegen_12.Name("vErrors"),
|
|
1531
|
+
// null or array of validation errors
|
|
1532
|
+
errors: new codegen_12.Name("errors"),
|
|
1533
|
+
// counter of validation errors
|
|
1534
|
+
this: new codegen_12.Name("this"),
|
|
1535
|
+
// "globals"
|
|
1536
|
+
self: new codegen_12.Name("self"),
|
|
1537
|
+
scope: new codegen_12.Name("scope"),
|
|
1538
|
+
// JTD serialize/parse name for JSON string and position
|
|
1539
|
+
json: new codegen_12.Name("json"),
|
|
1540
|
+
jsonPos: new codegen_12.Name("jsonPos"),
|
|
1541
|
+
jsonLen: new codegen_12.Name("jsonLen"),
|
|
1542
|
+
jsonPart: new codegen_12.Name("jsonPart")
|
|
1543
|
+
};
|
|
1544
|
+
names.default = names$1;
|
|
1545
|
+
return names;
|
|
1546
|
+
}
|
|
1541
1547
|
(function(exports$1) {
|
|
1542
1548
|
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
1543
1549
|
exports$1.extendErrors = exports$1.resetErrorsCount = exports$1.reportExtraError = exports$1.reportError = exports$1.keyword$DataError = exports$1.keywordError = void 0;
|
|
1544
1550
|
const codegen_12 = codegen;
|
|
1545
1551
|
const util_12 = util;
|
|
1546
|
-
const names_12 =
|
|
1552
|
+
const names_12 = requireNames();
|
|
1547
1553
|
exports$1.keywordError = {
|
|
1548
1554
|
message: ({ keyword: keyword2 }) => (0, codegen_12.str)`must pass "${keyword2}" keyword validation`
|
|
1549
1555
|
};
|
|
@@ -1655,49 +1661,55 @@ names$1.default = names;
|
|
|
1655
1661
|
keyValues.push([E.propertyName, propertyName]);
|
|
1656
1662
|
}
|
|
1657
1663
|
})(errors);
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
const
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
gen
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1664
|
+
var hasRequiredBoolSchema;
|
|
1665
|
+
function requireBoolSchema() {
|
|
1666
|
+
if (hasRequiredBoolSchema) return boolSchema;
|
|
1667
|
+
hasRequiredBoolSchema = 1;
|
|
1668
|
+
Object.defineProperty(boolSchema, "__esModule", { value: true });
|
|
1669
|
+
boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
|
|
1670
|
+
const errors_12 = errors;
|
|
1671
|
+
const codegen_12 = codegen;
|
|
1672
|
+
const names_12 = requireNames();
|
|
1673
|
+
const boolError = {
|
|
1674
|
+
message: "boolean schema is false"
|
|
1675
|
+
};
|
|
1676
|
+
function topBoolOrEmptySchema(it) {
|
|
1677
|
+
const { gen, schema, validateName } = it;
|
|
1678
|
+
if (schema === false) {
|
|
1679
|
+
falseSchemaError(it, false);
|
|
1680
|
+
} else if (typeof schema == "object" && schema.$async === true) {
|
|
1681
|
+
gen.return(names_12.default.data);
|
|
1682
|
+
} else {
|
|
1683
|
+
gen.assign((0, codegen_12._)`${validateName}.errors`, null);
|
|
1684
|
+
gen.return(true);
|
|
1685
|
+
}
|
|
1675
1686
|
}
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1687
|
+
boolSchema.topBoolOrEmptySchema = topBoolOrEmptySchema;
|
|
1688
|
+
function boolOrEmptySchema(it, valid) {
|
|
1689
|
+
const { gen, schema } = it;
|
|
1690
|
+
if (schema === false) {
|
|
1691
|
+
gen.var(valid, false);
|
|
1692
|
+
falseSchemaError(it);
|
|
1693
|
+
} else {
|
|
1694
|
+
gen.var(valid, true);
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
boolSchema.boolOrEmptySchema = boolOrEmptySchema;
|
|
1698
|
+
function falseSchemaError(it, overrideAllErrors) {
|
|
1699
|
+
const { gen, data } = it;
|
|
1700
|
+
const cxt = {
|
|
1701
|
+
gen,
|
|
1702
|
+
keyword: "false schema",
|
|
1703
|
+
data,
|
|
1704
|
+
schema: false,
|
|
1705
|
+
schemaCode: false,
|
|
1706
|
+
schemaValue: false,
|
|
1707
|
+
params: {},
|
|
1708
|
+
it
|
|
1709
|
+
};
|
|
1710
|
+
(0, errors_12.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
1685
1711
|
}
|
|
1686
|
-
|
|
1687
|
-
boolSchema.boolOrEmptySchema = boolOrEmptySchema;
|
|
1688
|
-
function falseSchemaError(it, overrideAllErrors) {
|
|
1689
|
-
const { gen, data } = it;
|
|
1690
|
-
const cxt = {
|
|
1691
|
-
gen,
|
|
1692
|
-
keyword: "false schema",
|
|
1693
|
-
data,
|
|
1694
|
-
schema: false,
|
|
1695
|
-
schemaCode: false,
|
|
1696
|
-
schemaValue: false,
|
|
1697
|
-
params: {},
|
|
1698
|
-
it
|
|
1699
|
-
};
|
|
1700
|
-
(0, errors_1$3.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
1712
|
+
return boolSchema;
|
|
1701
1713
|
}
|
|
1702
1714
|
var dataType = {};
|
|
1703
1715
|
var rules = {};
|
|
@@ -1745,10 +1757,10 @@ applicability.shouldUseRule = shouldUseRule;
|
|
|
1745
1757
|
Object.defineProperty(dataType, "__esModule", { value: true });
|
|
1746
1758
|
dataType.reportTypeError = dataType.checkDataTypes = dataType.checkDataType = dataType.coerceAndCheckDataType = dataType.getJSONTypes = dataType.getSchemaTypes = dataType.DataType = void 0;
|
|
1747
1759
|
const rules_1 = rules;
|
|
1748
|
-
const applicability_1
|
|
1749
|
-
const errors_1
|
|
1750
|
-
const codegen_1$
|
|
1751
|
-
const util_1$
|
|
1760
|
+
const applicability_1 = applicability;
|
|
1761
|
+
const errors_1 = errors;
|
|
1762
|
+
const codegen_1$o = codegen;
|
|
1763
|
+
const util_1$n = util;
|
|
1752
1764
|
var DataType;
|
|
1753
1765
|
(function(DataType2) {
|
|
1754
1766
|
DataType2[DataType2["Correct"] = 0] = "Correct";
|
|
@@ -1780,7 +1792,7 @@ dataType.getJSONTypes = getJSONTypes;
|
|
|
1780
1792
|
function coerceAndCheckDataType(it, types2) {
|
|
1781
1793
|
const { gen, data, opts } = it;
|
|
1782
1794
|
const coerceTo = coerceToTypes(types2, opts.coerceTypes);
|
|
1783
|
-
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1
|
|
1795
|
+
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1.schemaHasRulesForType)(it, types2[0]));
|
|
1784
1796
|
if (checkTypes) {
|
|
1785
1797
|
const wrongType = checkDataTypes(types2, data, opts.strictNumbers, DataType.Wrong);
|
|
1786
1798
|
gen.if(wrongType, () => {
|
|
@@ -1799,12 +1811,12 @@ function coerceToTypes(types2, coerceTypes) {
|
|
|
1799
1811
|
}
|
|
1800
1812
|
function coerceData(it, types2, coerceTo) {
|
|
1801
1813
|
const { gen, data, opts } = it;
|
|
1802
|
-
const dataType2 = gen.let("dataType", (0, codegen_1$
|
|
1803
|
-
const coerced = gen.let("coerced", (0, codegen_1$
|
|
1814
|
+
const dataType2 = gen.let("dataType", (0, codegen_1$o._)`typeof ${data}`);
|
|
1815
|
+
const coerced = gen.let("coerced", (0, codegen_1$o._)`undefined`);
|
|
1804
1816
|
if (opts.coerceTypes === "array") {
|
|
1805
|
-
gen.if((0, codegen_1$
|
|
1817
|
+
gen.if((0, codegen_1$o._)`${dataType2} == 'object' && Array.isArray(${data}) && ${data}.length == 1`, () => gen.assign(data, (0, codegen_1$o._)`${data}[0]`).assign(dataType2, (0, codegen_1$o._)`typeof ${data}`).if(checkDataTypes(types2, data, opts.strictNumbers), () => gen.assign(coerced, data)));
|
|
1806
1818
|
}
|
|
1807
|
-
gen.if((0, codegen_1$
|
|
1819
|
+
gen.if((0, codegen_1$o._)`${coerced} !== undefined`);
|
|
1808
1820
|
for (const t of coerceTo) {
|
|
1809
1821
|
if (COERCIBLE.has(t) || t === "array" && opts.coerceTypes === "array") {
|
|
1810
1822
|
coerceSpecificType(t);
|
|
@@ -1813,63 +1825,63 @@ function coerceData(it, types2, coerceTo) {
|
|
|
1813
1825
|
gen.else();
|
|
1814
1826
|
reportTypeError(it);
|
|
1815
1827
|
gen.endIf();
|
|
1816
|
-
gen.if((0, codegen_1$
|
|
1828
|
+
gen.if((0, codegen_1$o._)`${coerced} !== undefined`, () => {
|
|
1817
1829
|
gen.assign(data, coerced);
|
|
1818
1830
|
assignParentData(it, coerced);
|
|
1819
1831
|
});
|
|
1820
1832
|
function coerceSpecificType(t) {
|
|
1821
1833
|
switch (t) {
|
|
1822
1834
|
case "string":
|
|
1823
|
-
gen.elseIf((0, codegen_1$
|
|
1835
|
+
gen.elseIf((0, codegen_1$o._)`${dataType2} == "number" || ${dataType2} == "boolean"`).assign(coerced, (0, codegen_1$o._)`"" + ${data}`).elseIf((0, codegen_1$o._)`${data} === null`).assign(coerced, (0, codegen_1$o._)`""`);
|
|
1824
1836
|
return;
|
|
1825
1837
|
case "number":
|
|
1826
|
-
gen.elseIf((0, codegen_1$
|
|
1827
|
-
|| (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$
|
|
1838
|
+
gen.elseIf((0, codegen_1$o._)`${dataType2} == "boolean" || ${data} === null
|
|
1839
|
+
|| (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$o._)`+${data}`);
|
|
1828
1840
|
return;
|
|
1829
1841
|
case "integer":
|
|
1830
|
-
gen.elseIf((0, codegen_1$
|
|
1831
|
-
|| (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$
|
|
1842
|
+
gen.elseIf((0, codegen_1$o._)`${dataType2} === "boolean" || ${data} === null
|
|
1843
|
+
|| (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$o._)`+${data}`);
|
|
1832
1844
|
return;
|
|
1833
1845
|
case "boolean":
|
|
1834
|
-
gen.elseIf((0, codegen_1$
|
|
1846
|
+
gen.elseIf((0, codegen_1$o._)`${data} === "false" || ${data} === 0 || ${data} === null`).assign(coerced, false).elseIf((0, codegen_1$o._)`${data} === "true" || ${data} === 1`).assign(coerced, true);
|
|
1835
1847
|
return;
|
|
1836
1848
|
case "null":
|
|
1837
|
-
gen.elseIf((0, codegen_1$
|
|
1849
|
+
gen.elseIf((0, codegen_1$o._)`${data} === "" || ${data} === 0 || ${data} === false`);
|
|
1838
1850
|
gen.assign(coerced, null);
|
|
1839
1851
|
return;
|
|
1840
1852
|
case "array":
|
|
1841
|
-
gen.elseIf((0, codegen_1$
|
|
1842
|
-
|| ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$
|
|
1853
|
+
gen.elseIf((0, codegen_1$o._)`${dataType2} === "string" || ${dataType2} === "number"
|
|
1854
|
+
|| ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$o._)`[${data}]`);
|
|
1843
1855
|
}
|
|
1844
1856
|
}
|
|
1845
1857
|
}
|
|
1846
1858
|
function assignParentData({ gen, parentData, parentDataProperty }, expr) {
|
|
1847
|
-
gen.if((0, codegen_1$
|
|
1859
|
+
gen.if((0, codegen_1$o._)`${parentData} !== undefined`, () => gen.assign((0, codegen_1$o._)`${parentData}[${parentDataProperty}]`, expr));
|
|
1848
1860
|
}
|
|
1849
1861
|
function checkDataType(dataType2, data, strictNums, correct = DataType.Correct) {
|
|
1850
|
-
const EQ = correct === DataType.Correct ? codegen_1$
|
|
1862
|
+
const EQ = correct === DataType.Correct ? codegen_1$o.operators.EQ : codegen_1$o.operators.NEQ;
|
|
1851
1863
|
let cond;
|
|
1852
1864
|
switch (dataType2) {
|
|
1853
1865
|
case "null":
|
|
1854
|
-
return (0, codegen_1$
|
|
1866
|
+
return (0, codegen_1$o._)`${data} ${EQ} null`;
|
|
1855
1867
|
case "array":
|
|
1856
|
-
cond = (0, codegen_1$
|
|
1868
|
+
cond = (0, codegen_1$o._)`Array.isArray(${data})`;
|
|
1857
1869
|
break;
|
|
1858
1870
|
case "object":
|
|
1859
|
-
cond = (0, codegen_1$
|
|
1871
|
+
cond = (0, codegen_1$o._)`${data} && typeof ${data} == "object" && !Array.isArray(${data})`;
|
|
1860
1872
|
break;
|
|
1861
1873
|
case "integer":
|
|
1862
|
-
cond = numCond((0, codegen_1$
|
|
1874
|
+
cond = numCond((0, codegen_1$o._)`!(${data} % 1) && !isNaN(${data})`);
|
|
1863
1875
|
break;
|
|
1864
1876
|
case "number":
|
|
1865
1877
|
cond = numCond();
|
|
1866
1878
|
break;
|
|
1867
1879
|
default:
|
|
1868
|
-
return (0, codegen_1$
|
|
1880
|
+
return (0, codegen_1$o._)`typeof ${data} ${EQ} ${dataType2}`;
|
|
1869
1881
|
}
|
|
1870
|
-
return correct === DataType.Correct ? cond : (0, codegen_1$
|
|
1871
|
-
function numCond(_cond = codegen_1$
|
|
1872
|
-
return (0, codegen_1$
|
|
1882
|
+
return correct === DataType.Correct ? cond : (0, codegen_1$o.not)(cond);
|
|
1883
|
+
function numCond(_cond = codegen_1$o.nil) {
|
|
1884
|
+
return (0, codegen_1$o.and)((0, codegen_1$o._)`typeof ${data} == "number"`, _cond, strictNums ? (0, codegen_1$o._)`isFinite(${data})` : codegen_1$o.nil);
|
|
1873
1885
|
}
|
|
1874
1886
|
}
|
|
1875
1887
|
dataType.checkDataType = checkDataType;
|
|
@@ -1878,35 +1890,35 @@ function checkDataTypes(dataTypes, data, strictNums, correct) {
|
|
|
1878
1890
|
return checkDataType(dataTypes[0], data, strictNums, correct);
|
|
1879
1891
|
}
|
|
1880
1892
|
let cond;
|
|
1881
|
-
const types2 = (0, util_1$
|
|
1893
|
+
const types2 = (0, util_1$n.toHash)(dataTypes);
|
|
1882
1894
|
if (types2.array && types2.object) {
|
|
1883
|
-
const notObj = (0, codegen_1$
|
|
1884
|
-
cond = types2.null ? notObj : (0, codegen_1$
|
|
1895
|
+
const notObj = (0, codegen_1$o._)`typeof ${data} != "object"`;
|
|
1896
|
+
cond = types2.null ? notObj : (0, codegen_1$o._)`!${data} || ${notObj}`;
|
|
1885
1897
|
delete types2.null;
|
|
1886
1898
|
delete types2.array;
|
|
1887
1899
|
delete types2.object;
|
|
1888
1900
|
} else {
|
|
1889
|
-
cond = codegen_1$
|
|
1901
|
+
cond = codegen_1$o.nil;
|
|
1890
1902
|
}
|
|
1891
1903
|
if (types2.number)
|
|
1892
1904
|
delete types2.integer;
|
|
1893
1905
|
for (const t in types2)
|
|
1894
|
-
cond = (0, codegen_1$
|
|
1906
|
+
cond = (0, codegen_1$o.and)(cond, checkDataType(t, data, strictNums, correct));
|
|
1895
1907
|
return cond;
|
|
1896
1908
|
}
|
|
1897
1909
|
dataType.checkDataTypes = checkDataTypes;
|
|
1898
1910
|
const typeError = {
|
|
1899
1911
|
message: ({ schema }) => `must be ${schema}`,
|
|
1900
|
-
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$
|
|
1912
|
+
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$o._)`{type: ${schema}}` : (0, codegen_1$o._)`{type: ${schemaValue}}`
|
|
1901
1913
|
};
|
|
1902
1914
|
function reportTypeError(it) {
|
|
1903
1915
|
const cxt = getTypeErrorContext(it);
|
|
1904
|
-
(0, errors_1
|
|
1916
|
+
(0, errors_1.reportError)(cxt, typeError);
|
|
1905
1917
|
}
|
|
1906
1918
|
dataType.reportTypeError = reportTypeError;
|
|
1907
1919
|
function getTypeErrorContext(it) {
|
|
1908
1920
|
const { gen, data, schema } = it;
|
|
1909
|
-
const schemaCode = (0, util_1$
|
|
1921
|
+
const schemaCode = (0, util_1$n.schemaRefOrVal)(it, schema, "type");
|
|
1910
1922
|
return {
|
|
1911
1923
|
gen,
|
|
1912
1924
|
keyword: "type",
|
|
@@ -1920,54 +1932,60 @@ function getTypeErrorContext(it) {
|
|
|
1920
1932
|
};
|
|
1921
1933
|
}
|
|
1922
1934
|
var defaults = {};
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
}
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
}
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
if (defaultValue === void 0)
|
|
1941
|
-
return;
|
|
1942
|
-
const childData = (0, codegen_1$r._)`${data}${(0, codegen_1$r.getProperty)(prop)}`;
|
|
1943
|
-
if (compositeRule) {
|
|
1944
|
-
(0, util_1$p.checkStrictMode)(it, `default is ignored for: ${childData}`);
|
|
1945
|
-
return;
|
|
1935
|
+
var hasRequiredDefaults;
|
|
1936
|
+
function requireDefaults() {
|
|
1937
|
+
if (hasRequiredDefaults) return defaults;
|
|
1938
|
+
hasRequiredDefaults = 1;
|
|
1939
|
+
Object.defineProperty(defaults, "__esModule", { value: true });
|
|
1940
|
+
defaults.assignDefaults = void 0;
|
|
1941
|
+
const codegen_12 = codegen;
|
|
1942
|
+
const util_12 = util;
|
|
1943
|
+
function assignDefaults(it, ty) {
|
|
1944
|
+
const { properties: properties2, items: items2 } = it.schema;
|
|
1945
|
+
if (ty === "object" && properties2) {
|
|
1946
|
+
for (const key in properties2) {
|
|
1947
|
+
assignDefault(it, key, properties2[key].default);
|
|
1948
|
+
}
|
|
1949
|
+
} else if (ty === "array" && Array.isArray(items2)) {
|
|
1950
|
+
items2.forEach((sch, i) => assignDefault(it, i, sch.default));
|
|
1951
|
+
}
|
|
1946
1952
|
}
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1953
|
+
defaults.assignDefaults = assignDefaults;
|
|
1954
|
+
function assignDefault(it, prop, defaultValue) {
|
|
1955
|
+
const { gen, compositeRule, data, opts } = it;
|
|
1956
|
+
if (defaultValue === void 0)
|
|
1957
|
+
return;
|
|
1958
|
+
const childData = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)(prop)}`;
|
|
1959
|
+
if (compositeRule) {
|
|
1960
|
+
(0, util_12.checkStrictMode)(it, `default is ignored for: ${childData}`);
|
|
1961
|
+
return;
|
|
1962
|
+
}
|
|
1963
|
+
let condition = (0, codegen_12._)`${childData} === undefined`;
|
|
1964
|
+
if (opts.useDefaults === "empty") {
|
|
1965
|
+
condition = (0, codegen_12._)`${condition} || ${childData} === null || ${childData} === ""`;
|
|
1966
|
+
}
|
|
1967
|
+
gen.if(condition, (0, codegen_12._)`${childData} = ${(0, codegen_12.stringify)(defaultValue)}`);
|
|
1950
1968
|
}
|
|
1951
|
-
|
|
1969
|
+
return defaults;
|
|
1952
1970
|
}
|
|
1953
1971
|
var keyword = {};
|
|
1954
1972
|
var code = {};
|
|
1955
1973
|
Object.defineProperty(code, "__esModule", { value: true });
|
|
1956
1974
|
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;
|
|
1957
|
-
const codegen_1$
|
|
1958
|
-
const util_1$
|
|
1959
|
-
const names_1$
|
|
1975
|
+
const codegen_1$n = codegen;
|
|
1976
|
+
const util_1$m = util;
|
|
1977
|
+
const names_1$3 = requireNames();
|
|
1960
1978
|
const util_2$1 = util;
|
|
1961
1979
|
function checkReportMissingProp(cxt, prop) {
|
|
1962
1980
|
const { gen, data, it } = cxt;
|
|
1963
1981
|
gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
|
|
1964
|
-
cxt.setParams({ missingProperty: (0, codegen_1$
|
|
1982
|
+
cxt.setParams({ missingProperty: (0, codegen_1$n._)`${prop}` }, true);
|
|
1965
1983
|
cxt.error();
|
|
1966
1984
|
});
|
|
1967
1985
|
}
|
|
1968
1986
|
code.checkReportMissingProp = checkReportMissingProp;
|
|
1969
1987
|
function checkMissingProp({ gen, data, it: { opts } }, properties2, missing) {
|
|
1970
|
-
return (0, codegen_1$
|
|
1988
|
+
return (0, codegen_1$n.or)(...properties2.map((prop) => (0, codegen_1$n.and)(noPropertyInData(gen, data, prop, opts.ownProperties), (0, codegen_1$n._)`${missing} = ${prop}`)));
|
|
1971
1989
|
}
|
|
1972
1990
|
code.checkMissingProp = checkMissingProp;
|
|
1973
1991
|
function reportMissingProp(cxt, missing) {
|
|
@@ -1979,22 +1997,22 @@ function hasPropFunc(gen) {
|
|
|
1979
1997
|
return gen.scopeValue("func", {
|
|
1980
1998
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
1981
1999
|
ref: Object.prototype.hasOwnProperty,
|
|
1982
|
-
code: (0, codegen_1$
|
|
2000
|
+
code: (0, codegen_1$n._)`Object.prototype.hasOwnProperty`
|
|
1983
2001
|
});
|
|
1984
2002
|
}
|
|
1985
2003
|
code.hasPropFunc = hasPropFunc;
|
|
1986
2004
|
function isOwnProperty(gen, data, property) {
|
|
1987
|
-
return (0, codegen_1$
|
|
2005
|
+
return (0, codegen_1$n._)`${hasPropFunc(gen)}.call(${data}, ${property})`;
|
|
1988
2006
|
}
|
|
1989
2007
|
code.isOwnProperty = isOwnProperty;
|
|
1990
2008
|
function propertyInData(gen, data, property, ownProperties) {
|
|
1991
|
-
const cond = (0, codegen_1$
|
|
1992
|
-
return ownProperties ? (0, codegen_1$
|
|
2009
|
+
const cond = (0, codegen_1$n._)`${data}${(0, codegen_1$n.getProperty)(property)} !== undefined`;
|
|
2010
|
+
return ownProperties ? (0, codegen_1$n._)`${cond} && ${isOwnProperty(gen, data, property)}` : cond;
|
|
1993
2011
|
}
|
|
1994
2012
|
code.propertyInData = propertyInData;
|
|
1995
2013
|
function noPropertyInData(gen, data, property, ownProperties) {
|
|
1996
|
-
const cond = (0, codegen_1$
|
|
1997
|
-
return ownProperties ? (0, codegen_1$
|
|
2014
|
+
const cond = (0, codegen_1$n._)`${data}${(0, codegen_1$n.getProperty)(property)} === undefined`;
|
|
2015
|
+
return ownProperties ? (0, codegen_1$n.or)(cond, (0, codegen_1$n.not)(isOwnProperty(gen, data, property))) : cond;
|
|
1998
2016
|
}
|
|
1999
2017
|
code.noPropertyInData = noPropertyInData;
|
|
2000
2018
|
function allSchemaProperties(schemaMap) {
|
|
@@ -2002,24 +2020,24 @@ function allSchemaProperties(schemaMap) {
|
|
|
2002
2020
|
}
|
|
2003
2021
|
code.allSchemaProperties = allSchemaProperties;
|
|
2004
2022
|
function schemaProperties(it, schemaMap) {
|
|
2005
|
-
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$
|
|
2023
|
+
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$m.alwaysValidSchema)(it, schemaMap[p]));
|
|
2006
2024
|
}
|
|
2007
2025
|
code.schemaProperties = schemaProperties;
|
|
2008
2026
|
function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context, passSchema) {
|
|
2009
|
-
const dataAndSchema = passSchema ? (0, codegen_1$
|
|
2027
|
+
const dataAndSchema = passSchema ? (0, codegen_1$n._)`${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
|
|
2010
2028
|
const valCxt = [
|
|
2011
|
-
[names_1$
|
|
2012
|
-
[names_1$
|
|
2013
|
-
[names_1$
|
|
2014
|
-
[names_1$
|
|
2029
|
+
[names_1$3.default.instancePath, (0, codegen_1$n.strConcat)(names_1$3.default.instancePath, errorPath)],
|
|
2030
|
+
[names_1$3.default.parentData, it.parentData],
|
|
2031
|
+
[names_1$3.default.parentDataProperty, it.parentDataProperty],
|
|
2032
|
+
[names_1$3.default.rootData, names_1$3.default.rootData]
|
|
2015
2033
|
];
|
|
2016
2034
|
if (it.opts.dynamicRef)
|
|
2017
|
-
valCxt.push([names_1$
|
|
2018
|
-
const args = (0, codegen_1$
|
|
2019
|
-
return context !== codegen_1$
|
|
2035
|
+
valCxt.push([names_1$3.default.dynamicAnchors, names_1$3.default.dynamicAnchors]);
|
|
2036
|
+
const args = (0, codegen_1$n._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
|
|
2037
|
+
return context !== codegen_1$n.nil ? (0, codegen_1$n._)`${func}.call(${context}, ${args})` : (0, codegen_1$n._)`${func}(${args})`;
|
|
2020
2038
|
}
|
|
2021
2039
|
code.callValidateCode = callValidateCode;
|
|
2022
|
-
const newRegExp = (0, codegen_1$
|
|
2040
|
+
const newRegExp = (0, codegen_1$n._)`new RegExp`;
|
|
2023
2041
|
function usePattern({ gen, it: { opts } }, pattern2) {
|
|
2024
2042
|
const u = opts.unicodeRegExp ? "u" : "";
|
|
2025
2043
|
const { regExp } = opts.code;
|
|
@@ -2027,7 +2045,7 @@ function usePattern({ gen, it: { opts } }, pattern2) {
|
|
|
2027
2045
|
return gen.scopeValue("pattern", {
|
|
2028
2046
|
key: rx.toString(),
|
|
2029
2047
|
ref: rx,
|
|
2030
|
-
code: (0, codegen_1$
|
|
2048
|
+
code: (0, codegen_1$n._)`${regExp.code === "new RegExp" ? newRegExp : (0, util_2$1.useFunc)(gen, regExp)}(${pattern2}, ${u})`
|
|
2031
2049
|
});
|
|
2032
2050
|
}
|
|
2033
2051
|
code.usePattern = usePattern;
|
|
@@ -2043,14 +2061,14 @@ function validateArray(cxt) {
|
|
|
2043
2061
|
validateItems(() => gen.break());
|
|
2044
2062
|
return valid;
|
|
2045
2063
|
function validateItems(notValid) {
|
|
2046
|
-
const len = gen.const("len", (0, codegen_1$
|
|
2064
|
+
const len = gen.const("len", (0, codegen_1$n._)`${data}.length`);
|
|
2047
2065
|
gen.forRange("i", 0, len, (i) => {
|
|
2048
2066
|
cxt.subschema({
|
|
2049
2067
|
keyword: keyword2,
|
|
2050
2068
|
dataProp: i,
|
|
2051
|
-
dataPropType: util_1$
|
|
2069
|
+
dataPropType: util_1$m.Type.Num
|
|
2052
2070
|
}, valid);
|
|
2053
|
-
gen.if((0, codegen_1$
|
|
2071
|
+
gen.if((0, codegen_1$n.not)(valid), notValid);
|
|
2054
2072
|
});
|
|
2055
2073
|
}
|
|
2056
2074
|
}
|
|
@@ -2059,7 +2077,7 @@ function validateUnion(cxt) {
|
|
|
2059
2077
|
const { gen, schema, keyword: keyword2, it } = cxt;
|
|
2060
2078
|
if (!Array.isArray(schema))
|
|
2061
2079
|
throw new Error("ajv implementation error");
|
|
2062
|
-
const alwaysValid = schema.some((sch) => (0, util_1$
|
|
2080
|
+
const alwaysValid = schema.some((sch) => (0, util_1$m.alwaysValidSchema)(it, sch));
|
|
2063
2081
|
if (alwaysValid && !it.opts.unevaluated)
|
|
2064
2082
|
return;
|
|
2065
2083
|
const valid = gen.let("valid", false);
|
|
@@ -2070,202 +2088,214 @@ function validateUnion(cxt) {
|
|
|
2070
2088
|
schemaProp: i,
|
|
2071
2089
|
compositeRule: true
|
|
2072
2090
|
}, schValid);
|
|
2073
|
-
gen.assign(valid, (0, codegen_1$
|
|
2091
|
+
gen.assign(valid, (0, codegen_1$n._)`${valid} || ${schValid}`);
|
|
2074
2092
|
const merged = cxt.mergeValidEvaluated(schCxt, schValid);
|
|
2075
2093
|
if (!merged)
|
|
2076
|
-
gen.if((0, codegen_1$
|
|
2094
|
+
gen.if((0, codegen_1$n.not)(valid));
|
|
2077
2095
|
}));
|
|
2078
2096
|
cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
|
|
2079
2097
|
}
|
|
2080
2098
|
code.validateUnion = validateUnion;
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
const
|
|
2089
|
-
const
|
|
2090
|
-
const
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
|
|
2107
|
-
checkAsyncKeyword(it, def2);
|
|
2108
|
-
const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
|
|
2109
|
-
const validateRef = useKeyword(gen, keyword2, validate2);
|
|
2110
|
-
const valid = gen.let("valid");
|
|
2111
|
-
cxt.block$data(valid, validateKeyword);
|
|
2112
|
-
cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
|
|
2113
|
-
function validateKeyword() {
|
|
2114
|
-
if (def2.errors === false) {
|
|
2115
|
-
assignValid();
|
|
2116
|
-
if (def2.modifying)
|
|
2117
|
-
modifyData(cxt);
|
|
2118
|
-
reportErrs(() => cxt.error());
|
|
2119
|
-
} else {
|
|
2120
|
-
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
2121
|
-
if (def2.modifying)
|
|
2122
|
-
modifyData(cxt);
|
|
2123
|
-
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2126
|
-
function validateAsync() {
|
|
2127
|
-
const ruleErrs = gen.let("ruleErrs", null);
|
|
2128
|
-
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)));
|
|
2129
|
-
return ruleErrs;
|
|
2130
|
-
}
|
|
2131
|
-
function validateSync() {
|
|
2132
|
-
const validateErrs = (0, codegen_1$p._)`${validateRef}.errors`;
|
|
2133
|
-
gen.assign(validateErrs, null);
|
|
2134
|
-
assignValid(codegen_1$p.nil);
|
|
2135
|
-
return validateErrs;
|
|
2136
|
-
}
|
|
2137
|
-
function assignValid(_await = def2.async ? (0, codegen_1$p._)`await ` : codegen_1$p.nil) {
|
|
2138
|
-
const passCxt = it.opts.passContext ? names_1$4.default.this : names_1$4.default.self;
|
|
2139
|
-
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
2140
|
-
gen.assign(valid, (0, codegen_1$p._)`${_await}${(0, code_1$9.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
2141
|
-
}
|
|
2142
|
-
function reportErrs(errors2) {
|
|
2143
|
-
var _a2;
|
|
2144
|
-
gen.if((0, codegen_1$p.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
|
|
2145
|
-
}
|
|
2146
|
-
}
|
|
2147
|
-
keyword.funcKeywordCode = funcKeywordCode;
|
|
2148
|
-
function modifyData(cxt) {
|
|
2149
|
-
const { gen, data, it } = cxt;
|
|
2150
|
-
gen.if(it.parentData, () => gen.assign(data, (0, codegen_1$p._)`${it.parentData}[${it.parentDataProperty}]`));
|
|
2151
|
-
}
|
|
2152
|
-
function addErrs(cxt, errs) {
|
|
2153
|
-
const { gen } = cxt;
|
|
2154
|
-
gen.if((0, codegen_1$p._)`Array.isArray(${errs})`, () => {
|
|
2155
|
-
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`);
|
|
2156
|
-
(0, errors_1$1.extendErrors)(cxt);
|
|
2157
|
-
}, () => cxt.error());
|
|
2158
|
-
}
|
|
2159
|
-
function checkAsyncKeyword({ schemaEnv }, def2) {
|
|
2160
|
-
if (def2.async && !schemaEnv.$async)
|
|
2161
|
-
throw new Error("async keyword in sync schema");
|
|
2162
|
-
}
|
|
2163
|
-
function useKeyword(gen, keyword2, result) {
|
|
2164
|
-
if (result === void 0)
|
|
2165
|
-
throw new Error(`keyword "${keyword2}" failed to compile`);
|
|
2166
|
-
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_1$p.stringify)(result) });
|
|
2167
|
-
}
|
|
2168
|
-
function validSchemaType(schema, schemaType, allowUndefined = false) {
|
|
2169
|
-
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");
|
|
2170
|
-
}
|
|
2171
|
-
keyword.validSchemaType = validSchemaType;
|
|
2172
|
-
function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def2, keyword2) {
|
|
2173
|
-
if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
|
|
2174
|
-
throw new Error("ajv implementation error");
|
|
2099
|
+
var hasRequiredKeyword;
|
|
2100
|
+
function requireKeyword() {
|
|
2101
|
+
if (hasRequiredKeyword) return keyword;
|
|
2102
|
+
hasRequiredKeyword = 1;
|
|
2103
|
+
Object.defineProperty(keyword, "__esModule", { value: true });
|
|
2104
|
+
keyword.validateKeywordUsage = keyword.validSchemaType = keyword.funcKeywordCode = keyword.macroKeywordCode = void 0;
|
|
2105
|
+
const codegen_12 = codegen;
|
|
2106
|
+
const names_12 = requireNames();
|
|
2107
|
+
const code_12 = code;
|
|
2108
|
+
const errors_12 = errors;
|
|
2109
|
+
function macroKeywordCode(cxt, def2) {
|
|
2110
|
+
const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
|
|
2111
|
+
const macroSchema = def2.macro.call(it.self, schema, parentSchema, it);
|
|
2112
|
+
const schemaRef = useKeyword(gen, keyword2, macroSchema);
|
|
2113
|
+
if (it.opts.validateSchema !== false)
|
|
2114
|
+
it.self.validateSchema(macroSchema, true);
|
|
2115
|
+
const valid = gen.name("valid");
|
|
2116
|
+
cxt.subschema({
|
|
2117
|
+
schema: macroSchema,
|
|
2118
|
+
schemaPath: codegen_12.nil,
|
|
2119
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`,
|
|
2120
|
+
topSchemaRef: schemaRef,
|
|
2121
|
+
compositeRule: true
|
|
2122
|
+
}, valid);
|
|
2123
|
+
cxt.pass(valid, () => cxt.error(true));
|
|
2175
2124
|
}
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2125
|
+
keyword.macroKeywordCode = macroKeywordCode;
|
|
2126
|
+
function funcKeywordCode(cxt, def2) {
|
|
2127
|
+
var _a;
|
|
2128
|
+
const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
|
|
2129
|
+
checkAsyncKeyword(it, def2);
|
|
2130
|
+
const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
|
|
2131
|
+
const validateRef = useKeyword(gen, keyword2, validate2);
|
|
2132
|
+
const valid = gen.let("valid");
|
|
2133
|
+
cxt.block$data(valid, validateKeyword);
|
|
2134
|
+
cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
|
|
2135
|
+
function validateKeyword() {
|
|
2136
|
+
if (def2.errors === false) {
|
|
2137
|
+
assignValid();
|
|
2138
|
+
if (def2.modifying)
|
|
2139
|
+
modifyData(cxt);
|
|
2140
|
+
reportErrs(() => cxt.error());
|
|
2141
|
+
} else {
|
|
2142
|
+
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
2143
|
+
if (def2.modifying)
|
|
2144
|
+
modifyData(cxt);
|
|
2145
|
+
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
function validateAsync() {
|
|
2149
|
+
const ruleErrs = gen.let("ruleErrs", null);
|
|
2150
|
+
gen.try(() => assignValid((0, codegen_12._)`await `), (e) => gen.assign(valid, false).if((0, codegen_12._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_12._)`${e}.errors`), () => gen.throw(e)));
|
|
2151
|
+
return ruleErrs;
|
|
2152
|
+
}
|
|
2153
|
+
function validateSync() {
|
|
2154
|
+
const validateErrs = (0, codegen_12._)`${validateRef}.errors`;
|
|
2155
|
+
gen.assign(validateErrs, null);
|
|
2156
|
+
assignValid(codegen_12.nil);
|
|
2157
|
+
return validateErrs;
|
|
2158
|
+
}
|
|
2159
|
+
function assignValid(_await = def2.async ? (0, codegen_12._)`await ` : codegen_12.nil) {
|
|
2160
|
+
const passCxt = it.opts.passContext ? names_12.default.this : names_12.default.self;
|
|
2161
|
+
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
2162
|
+
gen.assign(valid, (0, codegen_12._)`${_await}${(0, code_12.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
2163
|
+
}
|
|
2164
|
+
function reportErrs(errors2) {
|
|
2165
|
+
var _a2;
|
|
2166
|
+
gen.if((0, codegen_12.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
|
|
2167
|
+
}
|
|
2179
2168
|
}
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2169
|
+
keyword.funcKeywordCode = funcKeywordCode;
|
|
2170
|
+
function modifyData(cxt) {
|
|
2171
|
+
const { gen, data, it } = cxt;
|
|
2172
|
+
gen.if(it.parentData, () => gen.assign(data, (0, codegen_12._)`${it.parentData}[${it.parentDataProperty}]`));
|
|
2173
|
+
}
|
|
2174
|
+
function addErrs(cxt, errs) {
|
|
2175
|
+
const { gen } = cxt;
|
|
2176
|
+
gen.if((0, codegen_12._)`Array.isArray(${errs})`, () => {
|
|
2177
|
+
gen.assign(names_12.default.vErrors, (0, codegen_12._)`${names_12.default.vErrors} === null ? ${errs} : ${names_12.default.vErrors}.concat(${errs})`).assign(names_12.default.errors, (0, codegen_12._)`${names_12.default.vErrors}.length`);
|
|
2178
|
+
(0, errors_12.extendErrors)(cxt);
|
|
2179
|
+
}, () => cxt.error());
|
|
2180
|
+
}
|
|
2181
|
+
function checkAsyncKeyword({ schemaEnv }, def2) {
|
|
2182
|
+
if (def2.async && !schemaEnv.$async)
|
|
2183
|
+
throw new Error("async keyword in sync schema");
|
|
2184
|
+
}
|
|
2185
|
+
function useKeyword(gen, keyword2, result) {
|
|
2186
|
+
if (result === void 0)
|
|
2187
|
+
throw new Error(`keyword "${keyword2}" failed to compile`);
|
|
2188
|
+
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_12.stringify)(result) });
|
|
2189
|
+
}
|
|
2190
|
+
function validSchemaType(schema, schemaType, allowUndefined = false) {
|
|
2191
|
+
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");
|
|
2192
|
+
}
|
|
2193
|
+
keyword.validSchemaType = validSchemaType;
|
|
2194
|
+
function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def2, keyword2) {
|
|
2195
|
+
if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
|
|
2196
|
+
throw new Error("ajv implementation error");
|
|
2197
|
+
}
|
|
2198
|
+
const deps = def2.dependencies;
|
|
2199
|
+
if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
|
|
2200
|
+
throw new Error(`parent schema must have dependencies of ${keyword2}: ${deps.join(",")}`);
|
|
2201
|
+
}
|
|
2202
|
+
if (def2.validateSchema) {
|
|
2203
|
+
const valid = def2.validateSchema(schema[keyword2]);
|
|
2204
|
+
if (!valid) {
|
|
2205
|
+
const msg = `keyword "${keyword2}" value is invalid at path "${errSchemaPath}": ` + self.errorsText(def2.validateSchema.errors);
|
|
2206
|
+
if (opts.validateSchema === "log")
|
|
2207
|
+
self.logger.error(msg);
|
|
2208
|
+
else
|
|
2209
|
+
throw new Error(msg);
|
|
2210
|
+
}
|
|
2188
2211
|
}
|
|
2189
2212
|
}
|
|
2213
|
+
keyword.validateKeywordUsage = validateKeywordUsage;
|
|
2214
|
+
return keyword;
|
|
2190
2215
|
}
|
|
2191
|
-
keyword.validateKeywordUsage = validateKeywordUsage;
|
|
2192
2216
|
var subschema = {};
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
schema: sch,
|
|
2205
|
-
schemaPath: (0, codegen_1$o._)`${it.schemaPath}${(0, codegen_1$o.getProperty)(keyword2)}`,
|
|
2206
|
-
errSchemaPath: `${it.errSchemaPath}/${keyword2}`
|
|
2207
|
-
} : {
|
|
2208
|
-
schema: sch[schemaProp],
|
|
2209
|
-
schemaPath: (0, codegen_1$o._)`${it.schemaPath}${(0, codegen_1$o.getProperty)(keyword2)}${(0, codegen_1$o.getProperty)(schemaProp)}`,
|
|
2210
|
-
errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_1$n.escapeFragment)(schemaProp)}`
|
|
2211
|
-
};
|
|
2212
|
-
}
|
|
2213
|
-
if (schema !== void 0) {
|
|
2214
|
-
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
2215
|
-
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
2217
|
+
var hasRequiredSubschema;
|
|
2218
|
+
function requireSubschema() {
|
|
2219
|
+
if (hasRequiredSubschema) return subschema;
|
|
2220
|
+
hasRequiredSubschema = 1;
|
|
2221
|
+
Object.defineProperty(subschema, "__esModule", { value: true });
|
|
2222
|
+
subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
|
|
2223
|
+
const codegen_12 = codegen;
|
|
2224
|
+
const util_12 = util;
|
|
2225
|
+
function getSubschema(it, { keyword: keyword2, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
|
|
2226
|
+
if (keyword2 !== void 0 && schema !== void 0) {
|
|
2227
|
+
throw new Error('both "keyword" and "schema" passed, only one allowed');
|
|
2216
2228
|
}
|
|
2217
|
-
|
|
2218
|
-
schema
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
}
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2229
|
+
if (keyword2 !== void 0) {
|
|
2230
|
+
const sch = it.schema[keyword2];
|
|
2231
|
+
return schemaProp === void 0 ? {
|
|
2232
|
+
schema: sch,
|
|
2233
|
+
schemaPath: (0, codegen_12._)`${it.schemaPath}${(0, codegen_12.getProperty)(keyword2)}`,
|
|
2234
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`
|
|
2235
|
+
} : {
|
|
2236
|
+
schema: sch[schemaProp],
|
|
2237
|
+
schemaPath: (0, codegen_12._)`${it.schemaPath}${(0, codegen_12.getProperty)(keyword2)}${(0, codegen_12.getProperty)(schemaProp)}`,
|
|
2238
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_12.escapeFragment)(schemaProp)}`
|
|
2239
|
+
};
|
|
2240
|
+
}
|
|
2241
|
+
if (schema !== void 0) {
|
|
2242
|
+
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
2243
|
+
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
2244
|
+
}
|
|
2245
|
+
return {
|
|
2246
|
+
schema,
|
|
2247
|
+
schemaPath,
|
|
2248
|
+
topSchemaRef,
|
|
2249
|
+
errSchemaPath
|
|
2250
|
+
};
|
|
2251
|
+
}
|
|
2252
|
+
throw new Error('either "keyword" or "schema" must be passed');
|
|
2253
|
+
}
|
|
2254
|
+
subschema.getSubschema = getSubschema;
|
|
2255
|
+
function extendSubschemaData(subschema2, it, { dataProp, dataPropType: dpType, data, dataTypes, propertyName }) {
|
|
2256
|
+
if (data !== void 0 && dataProp !== void 0) {
|
|
2257
|
+
throw new Error('both "data" and "dataProp" passed, only one allowed');
|
|
2258
|
+
}
|
|
2259
|
+
const { gen } = it;
|
|
2260
|
+
if (dataProp !== void 0) {
|
|
2261
|
+
const { errorPath, dataPathArr, opts } = it;
|
|
2262
|
+
const nextData = gen.let("data", (0, codegen_12._)`${it.data}${(0, codegen_12.getProperty)(dataProp)}`, true);
|
|
2263
|
+
dataContextProps(nextData);
|
|
2264
|
+
subschema2.errorPath = (0, codegen_12.str)`${errorPath}${(0, util_12.getErrorPath)(dataProp, dpType, opts.jsPropertySyntax)}`;
|
|
2265
|
+
subschema2.parentDataProperty = (0, codegen_12._)`${dataProp}`;
|
|
2266
|
+
subschema2.dataPathArr = [...dataPathArr, subschema2.parentDataProperty];
|
|
2267
|
+
}
|
|
2268
|
+
if (data !== void 0) {
|
|
2269
|
+
const nextData = data instanceof codegen_12.Name ? data : gen.let("data", data, true);
|
|
2270
|
+
dataContextProps(nextData);
|
|
2271
|
+
if (propertyName !== void 0)
|
|
2272
|
+
subschema2.propertyName = propertyName;
|
|
2273
|
+
}
|
|
2274
|
+
if (dataTypes)
|
|
2275
|
+
subschema2.dataTypes = dataTypes;
|
|
2276
|
+
function dataContextProps(_nextData) {
|
|
2277
|
+
subschema2.data = _nextData;
|
|
2278
|
+
subschema2.dataLevel = it.dataLevel + 1;
|
|
2279
|
+
subschema2.dataTypes = [];
|
|
2280
|
+
it.definedProperties = /* @__PURE__ */ new Set();
|
|
2281
|
+
subschema2.parentData = it.data;
|
|
2282
|
+
subschema2.dataNames = [...it.dataNames, _nextData];
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
subschema.extendSubschemaData = extendSubschemaData;
|
|
2286
|
+
function extendSubschemaMode(subschema2, { jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors }) {
|
|
2287
|
+
if (compositeRule !== void 0)
|
|
2288
|
+
subschema2.compositeRule = compositeRule;
|
|
2289
|
+
if (createErrors !== void 0)
|
|
2290
|
+
subschema2.createErrors = createErrors;
|
|
2291
|
+
if (allErrors !== void 0)
|
|
2292
|
+
subschema2.allErrors = allErrors;
|
|
2293
|
+
subschema2.jtdDiscriminator = jtdDiscriminator;
|
|
2294
|
+
subschema2.jtdMetadata = jtdMetadata;
|
|
2295
|
+
}
|
|
2296
|
+
subschema.extendSubschemaMode = extendSubschemaMode;
|
|
2297
|
+
return subschema;
|
|
2267
2298
|
}
|
|
2268
|
-
subschema.extendSubschemaMode = extendSubschemaMode;
|
|
2269
2299
|
var resolve$2 = {};
|
|
2270
2300
|
var fastDeepEqual = function equal(a, b) {
|
|
2271
2301
|
if (a === b) return true;
|
|
@@ -2380,7 +2410,7 @@ function escapeJsonPtr(str) {
|
|
|
2380
2410
|
var jsonSchemaTraverseExports = jsonSchemaTraverse.exports;
|
|
2381
2411
|
Object.defineProperty(resolve$2, "__esModule", { value: true });
|
|
2382
2412
|
resolve$2.getSchemaRefs = resolve$2.resolveUrl = resolve$2.normalizeId = resolve$2._getFullPath = resolve$2.getFullPath = resolve$2.inlineRef = void 0;
|
|
2383
|
-
const util_1$
|
|
2413
|
+
const util_1$l = util;
|
|
2384
2414
|
const equal$3 = fastDeepEqual;
|
|
2385
2415
|
const traverse = jsonSchemaTraverseExports;
|
|
2386
2416
|
const SIMPLE_INLINED = /* @__PURE__ */ new Set([
|
|
@@ -2439,7 +2469,7 @@ function countKeys(schema) {
|
|
|
2439
2469
|
if (SIMPLE_INLINED.has(key))
|
|
2440
2470
|
continue;
|
|
2441
2471
|
if (typeof schema[key] == "object") {
|
|
2442
|
-
(0, util_1$
|
|
2472
|
+
(0, util_1$l.eachItem)(schema[key], (sch) => count += countKeys(sch));
|
|
2443
2473
|
}
|
|
2444
2474
|
if (count === Infinity)
|
|
2445
2475
|
return Infinity;
|
|
@@ -2527,516 +2557,528 @@ function getSchemaRefs(schema, baseId) {
|
|
|
2527
2557
|
}
|
|
2528
2558
|
}
|
|
2529
2559
|
resolve$2.getSchemaRefs = getSchemaRefs;
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
const
|
|
2537
|
-
const
|
|
2538
|
-
const
|
|
2539
|
-
const
|
|
2540
|
-
const
|
|
2541
|
-
const
|
|
2542
|
-
const
|
|
2543
|
-
const
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2560
|
+
var hasRequiredValidate;
|
|
2561
|
+
function requireValidate() {
|
|
2562
|
+
if (hasRequiredValidate) return validate;
|
|
2563
|
+
hasRequiredValidate = 1;
|
|
2564
|
+
Object.defineProperty(validate, "__esModule", { value: true });
|
|
2565
|
+
validate.getData = validate.KeywordCxt = validate.validateFunctionCode = void 0;
|
|
2566
|
+
const boolSchema_1 = requireBoolSchema();
|
|
2567
|
+
const dataType_12 = dataType;
|
|
2568
|
+
const applicability_12 = applicability;
|
|
2569
|
+
const dataType_2 = dataType;
|
|
2570
|
+
const defaults_1 = requireDefaults();
|
|
2571
|
+
const keyword_1 = requireKeyword();
|
|
2572
|
+
const subschema_1 = requireSubschema();
|
|
2573
|
+
const codegen_12 = codegen;
|
|
2574
|
+
const names_12 = requireNames();
|
|
2575
|
+
const resolve_12 = resolve$2;
|
|
2576
|
+
const util_12 = util;
|
|
2577
|
+
const errors_12 = errors;
|
|
2578
|
+
function validateFunctionCode(it) {
|
|
2579
|
+
if (isSchemaObj(it)) {
|
|
2580
|
+
checkKeywords(it);
|
|
2581
|
+
if (schemaCxtHasRules(it)) {
|
|
2582
|
+
topSchemaObjCode(it);
|
|
2583
|
+
return;
|
|
2584
|
+
}
|
|
2550
2585
|
}
|
|
2586
|
+
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
2551
2587
|
}
|
|
2552
|
-
|
|
2553
|
-
}
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2588
|
+
validate.validateFunctionCode = validateFunctionCode;
|
|
2589
|
+
function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
|
|
2590
|
+
if (opts.code.es5) {
|
|
2591
|
+
gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${names_12.default.valCxt}`, schemaEnv.$async, () => {
|
|
2592
|
+
gen.code((0, codegen_12._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
|
|
2593
|
+
destructureValCxtES5(gen, opts);
|
|
2594
|
+
gen.code(body);
|
|
2595
|
+
});
|
|
2596
|
+
} else {
|
|
2597
|
+
gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
function destructureValCxt(opts) {
|
|
2601
|
+
return (0, codegen_12._)`{${names_12.default.instancePath}="", ${names_12.default.parentData}, ${names_12.default.parentDataProperty}, ${names_12.default.rootData}=${names_12.default.data}${opts.dynamicRef ? (0, codegen_12._)`, ${names_12.default.dynamicAnchors}={}` : codegen_12.nil}}={}`;
|
|
2602
|
+
}
|
|
2603
|
+
function destructureValCxtES5(gen, opts) {
|
|
2604
|
+
gen.if(names_12.default.valCxt, () => {
|
|
2605
|
+
gen.var(names_12.default.instancePath, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.instancePath}`);
|
|
2606
|
+
gen.var(names_12.default.parentData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentData}`);
|
|
2607
|
+
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentDataProperty}`);
|
|
2608
|
+
gen.var(names_12.default.rootData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.rootData}`);
|
|
2609
|
+
if (opts.dynamicRef)
|
|
2610
|
+
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.dynamicAnchors}`);
|
|
2611
|
+
}, () => {
|
|
2612
|
+
gen.var(names_12.default.instancePath, (0, codegen_12._)`""`);
|
|
2613
|
+
gen.var(names_12.default.parentData, (0, codegen_12._)`undefined`);
|
|
2614
|
+
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`undefined`);
|
|
2615
|
+
gen.var(names_12.default.rootData, names_12.default.data);
|
|
2616
|
+
if (opts.dynamicRef)
|
|
2617
|
+
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`{}`);
|
|
2561
2618
|
});
|
|
2562
|
-
} else {
|
|
2563
|
-
gen.func(validateName, (0, codegen_1$n._)`${names_1$3.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
2564
2619
|
}
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
gen
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
}
|
|
2586
|
-
function
|
|
2587
|
-
|
|
2588
|
-
|
|
2620
|
+
function topSchemaObjCode(it) {
|
|
2621
|
+
const { schema, opts, gen } = it;
|
|
2622
|
+
validateFunction(it, () => {
|
|
2623
|
+
if (opts.$comment && schema.$comment)
|
|
2624
|
+
commentKeyword(it);
|
|
2625
|
+
checkNoDefault(it);
|
|
2626
|
+
gen.let(names_12.default.vErrors, null);
|
|
2627
|
+
gen.let(names_12.default.errors, 0);
|
|
2628
|
+
if (opts.unevaluated)
|
|
2629
|
+
resetEvaluated(it);
|
|
2630
|
+
typeAndKeywords(it);
|
|
2631
|
+
returnResults(it);
|
|
2632
|
+
});
|
|
2633
|
+
return;
|
|
2634
|
+
}
|
|
2635
|
+
function resetEvaluated(it) {
|
|
2636
|
+
const { gen, validateName } = it;
|
|
2637
|
+
it.evaluated = gen.const("evaluated", (0, codegen_12._)`${validateName}.evaluated`);
|
|
2638
|
+
gen.if((0, codegen_12._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_12._)`${it.evaluated}.props`, (0, codegen_12._)`undefined`));
|
|
2639
|
+
gen.if((0, codegen_12._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_12._)`${it.evaluated}.items`, (0, codegen_12._)`undefined`));
|
|
2640
|
+
}
|
|
2641
|
+
function funcSourceUrl(schema, opts) {
|
|
2642
|
+
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
2643
|
+
return schId && (opts.code.source || opts.code.process) ? (0, codegen_12._)`/*# sourceURL=${schId} */` : codegen_12.nil;
|
|
2644
|
+
}
|
|
2645
|
+
function subschemaCode(it, valid) {
|
|
2646
|
+
if (isSchemaObj(it)) {
|
|
2647
|
+
checkKeywords(it);
|
|
2648
|
+
if (schemaCxtHasRules(it)) {
|
|
2649
|
+
subSchemaObjCode(it, valid);
|
|
2650
|
+
return;
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
(0, boolSchema_1.boolOrEmptySchema)(it, valid);
|
|
2654
|
+
}
|
|
2655
|
+
function schemaCxtHasRules({ schema, self }) {
|
|
2656
|
+
if (typeof schema == "boolean")
|
|
2657
|
+
return !schema;
|
|
2658
|
+
for (const key in schema)
|
|
2659
|
+
if (self.RULES.all[key])
|
|
2660
|
+
return true;
|
|
2661
|
+
return false;
|
|
2662
|
+
}
|
|
2663
|
+
function isSchemaObj(it) {
|
|
2664
|
+
return typeof it.schema != "boolean";
|
|
2665
|
+
}
|
|
2666
|
+
function subSchemaObjCode(it, valid) {
|
|
2667
|
+
const { schema, gen, opts } = it;
|
|
2589
2668
|
if (opts.$comment && schema.$comment)
|
|
2590
2669
|
commentKeyword(it);
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
gen.
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
typeAndKeywords(it);
|
|
2597
|
-
returnResults(it);
|
|
2598
|
-
});
|
|
2599
|
-
return;
|
|
2600
|
-
}
|
|
2601
|
-
function resetEvaluated(it) {
|
|
2602
|
-
const { gen, validateName } = it;
|
|
2603
|
-
it.evaluated = gen.const("evaluated", (0, codegen_1$n._)`${validateName}.evaluated`);
|
|
2604
|
-
gen.if((0, codegen_1$n._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_1$n._)`${it.evaluated}.props`, (0, codegen_1$n._)`undefined`));
|
|
2605
|
-
gen.if((0, codegen_1$n._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_1$n._)`${it.evaluated}.items`, (0, codegen_1$n._)`undefined`));
|
|
2606
|
-
}
|
|
2607
|
-
function funcSourceUrl(schema, opts) {
|
|
2608
|
-
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
2609
|
-
return schId && (opts.code.source || opts.code.process) ? (0, codegen_1$n._)`/*# sourceURL=${schId} */` : codegen_1$n.nil;
|
|
2610
|
-
}
|
|
2611
|
-
function subschemaCode(it, valid) {
|
|
2612
|
-
if (isSchemaObj(it)) {
|
|
2613
|
-
checkKeywords(it);
|
|
2614
|
-
if (schemaCxtHasRules(it)) {
|
|
2615
|
-
subSchemaObjCode(it, valid);
|
|
2616
|
-
return;
|
|
2617
|
-
}
|
|
2670
|
+
updateContext(it);
|
|
2671
|
+
checkAsyncSchema(it);
|
|
2672
|
+
const errsCount = gen.const("_errs", names_12.default.errors);
|
|
2673
|
+
typeAndKeywords(it, errsCount);
|
|
2674
|
+
gen.var(valid, (0, codegen_12._)`${errsCount} === ${names_12.default.errors}`);
|
|
2618
2675
|
}
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
if (typeof schema == "boolean")
|
|
2623
|
-
return !schema;
|
|
2624
|
-
for (const key in schema)
|
|
2625
|
-
if (self.RULES.all[key])
|
|
2626
|
-
return true;
|
|
2627
|
-
return false;
|
|
2628
|
-
}
|
|
2629
|
-
function isSchemaObj(it) {
|
|
2630
|
-
return typeof it.schema != "boolean";
|
|
2631
|
-
}
|
|
2632
|
-
function subSchemaObjCode(it, valid) {
|
|
2633
|
-
const { schema, gen, opts } = it;
|
|
2634
|
-
if (opts.$comment && schema.$comment)
|
|
2635
|
-
commentKeyword(it);
|
|
2636
|
-
updateContext(it);
|
|
2637
|
-
checkAsyncSchema(it);
|
|
2638
|
-
const errsCount = gen.const("_errs", names_1$3.default.errors);
|
|
2639
|
-
typeAndKeywords(it, errsCount);
|
|
2640
|
-
gen.var(valid, (0, codegen_1$n._)`${errsCount} === ${names_1$3.default.errors}`);
|
|
2641
|
-
}
|
|
2642
|
-
function checkKeywords(it) {
|
|
2643
|
-
(0, util_1$l.checkUnknownRules)(it);
|
|
2644
|
-
checkRefsAndKeywords(it);
|
|
2645
|
-
}
|
|
2646
|
-
function typeAndKeywords(it, errsCount) {
|
|
2647
|
-
if (it.opts.jtd)
|
|
2648
|
-
return schemaKeywords(it, [], false, errsCount);
|
|
2649
|
-
const types2 = (0, dataType_1$1.getSchemaTypes)(it.schema);
|
|
2650
|
-
const checkedTypes = (0, dataType_1$1.coerceAndCheckDataType)(it, types2);
|
|
2651
|
-
schemaKeywords(it, types2, !checkedTypes, errsCount);
|
|
2652
|
-
}
|
|
2653
|
-
function checkRefsAndKeywords(it) {
|
|
2654
|
-
const { schema, errSchemaPath, opts, self } = it;
|
|
2655
|
-
if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_1$l.schemaHasRulesButRef)(schema, self.RULES)) {
|
|
2656
|
-
self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
|
|
2676
|
+
function checkKeywords(it) {
|
|
2677
|
+
(0, util_12.checkUnknownRules)(it);
|
|
2678
|
+
checkRefsAndKeywords(it);
|
|
2657
2679
|
}
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
(0,
|
|
2680
|
+
function typeAndKeywords(it, errsCount) {
|
|
2681
|
+
if (it.opts.jtd)
|
|
2682
|
+
return schemaKeywords(it, [], false, errsCount);
|
|
2683
|
+
const types2 = (0, dataType_12.getSchemaTypes)(it.schema);
|
|
2684
|
+
const checkedTypes = (0, dataType_12.coerceAndCheckDataType)(it, types2);
|
|
2685
|
+
schemaKeywords(it, types2, !checkedTypes, errsCount);
|
|
2663
2686
|
}
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
}
|
|
2670
|
-
function checkAsyncSchema(it) {
|
|
2671
|
-
if (it.schema.$async && !it.schemaEnv.$async)
|
|
2672
|
-
throw new Error("async schema in sync schema");
|
|
2673
|
-
}
|
|
2674
|
-
function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
|
|
2675
|
-
const msg = schema.$comment;
|
|
2676
|
-
if (opts.$comment === true) {
|
|
2677
|
-
gen.code((0, codegen_1$n._)`${names_1$3.default.self}.logger.log(${msg})`);
|
|
2678
|
-
} else if (typeof opts.$comment == "function") {
|
|
2679
|
-
const schemaPath = (0, codegen_1$n.str)`${errSchemaPath}/$comment`;
|
|
2680
|
-
const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
|
|
2681
|
-
gen.code((0, codegen_1$n._)`${names_1$3.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
|
|
2687
|
+
function checkRefsAndKeywords(it) {
|
|
2688
|
+
const { schema, errSchemaPath, opts, self } = it;
|
|
2689
|
+
if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_12.schemaHasRulesButRef)(schema, self.RULES)) {
|
|
2690
|
+
self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
|
|
2691
|
+
}
|
|
2682
2692
|
}
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
} else {
|
|
2689
|
-
gen.assign((0, codegen_1$n._)`${validateName}.errors`, names_1$3.default.vErrors);
|
|
2690
|
-
if (opts.unevaluated)
|
|
2691
|
-
assignEvaluated(it);
|
|
2692
|
-
gen.return((0, codegen_1$n._)`${names_1$3.default.errors} === 0`);
|
|
2693
|
+
function checkNoDefault(it) {
|
|
2694
|
+
const { schema, opts } = it;
|
|
2695
|
+
if (schema.default !== void 0 && opts.useDefaults && opts.strictSchema) {
|
|
2696
|
+
(0, util_12.checkStrictMode)(it, "default is ignored in the schema root");
|
|
2697
|
+
}
|
|
2693
2698
|
}
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
if (items2 instanceof codegen_1$n.Name)
|
|
2699
|
-
gen.assign((0, codegen_1$n._)`${evaluated}.items`, items2);
|
|
2700
|
-
}
|
|
2701
|
-
function schemaKeywords(it, types2, typeErrors, errsCount) {
|
|
2702
|
-
const { gen, schema, data, allErrors, opts, self } = it;
|
|
2703
|
-
const { RULES } = self;
|
|
2704
|
-
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_1$l.schemaHasRulesButRef)(schema, RULES))) {
|
|
2705
|
-
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
2706
|
-
return;
|
|
2699
|
+
function updateContext(it) {
|
|
2700
|
+
const schId = it.schema[it.opts.schemaId];
|
|
2701
|
+
if (schId)
|
|
2702
|
+
it.baseId = (0, resolve_12.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
|
|
2707
2703
|
}
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
if (
|
|
2704
|
+
function checkAsyncSchema(it) {
|
|
2705
|
+
if (it.schema.$async && !it.schemaEnv.$async)
|
|
2706
|
+
throw new Error("async schema in sync schema");
|
|
2707
|
+
}
|
|
2708
|
+
function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
|
|
2709
|
+
const msg = schema.$comment;
|
|
2710
|
+
if (opts.$comment === true) {
|
|
2711
|
+
gen.code((0, codegen_12._)`${names_12.default.self}.logger.log(${msg})`);
|
|
2712
|
+
} else if (typeof opts.$comment == "function") {
|
|
2713
|
+
const schemaPath = (0, codegen_12.str)`${errSchemaPath}/$comment`;
|
|
2714
|
+
const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
|
|
2715
|
+
gen.code((0, codegen_12._)`${names_12.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
function returnResults(it) {
|
|
2719
|
+
const { gen, schemaEnv, validateName, ValidationError, opts } = it;
|
|
2720
|
+
if (schemaEnv.$async) {
|
|
2721
|
+
gen.if((0, codegen_12._)`${names_12.default.errors} === 0`, () => gen.return(names_12.default.data), () => gen.throw((0, codegen_12._)`new ${ValidationError}(${names_12.default.vErrors})`));
|
|
2722
|
+
} else {
|
|
2723
|
+
gen.assign((0, codegen_12._)`${validateName}.errors`, names_12.default.vErrors);
|
|
2724
|
+
if (opts.unevaluated)
|
|
2725
|
+
assignEvaluated(it);
|
|
2726
|
+
gen.return((0, codegen_12._)`${names_12.default.errors} === 0`);
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
function assignEvaluated({ gen, evaluated, props, items: items2 }) {
|
|
2730
|
+
if (props instanceof codegen_12.Name)
|
|
2731
|
+
gen.assign((0, codegen_12._)`${evaluated}.props`, props);
|
|
2732
|
+
if (items2 instanceof codegen_12.Name)
|
|
2733
|
+
gen.assign((0, codegen_12._)`${evaluated}.items`, items2);
|
|
2734
|
+
}
|
|
2735
|
+
function schemaKeywords(it, types2, typeErrors, errsCount) {
|
|
2736
|
+
const { gen, schema, data, allErrors, opts, self } = it;
|
|
2737
|
+
const { RULES } = self;
|
|
2738
|
+
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_12.schemaHasRulesButRef)(schema, RULES))) {
|
|
2739
|
+
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
2717
2740
|
return;
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
(
|
|
2741
|
+
}
|
|
2742
|
+
if (!opts.jtd)
|
|
2743
|
+
checkStrictTypes(it, types2);
|
|
2744
|
+
gen.block(() => {
|
|
2745
|
+
for (const group of RULES.rules)
|
|
2746
|
+
groupKeywords(group);
|
|
2747
|
+
groupKeywords(RULES.post);
|
|
2748
|
+
});
|
|
2749
|
+
function groupKeywords(group) {
|
|
2750
|
+
if (!(0, applicability_12.shouldUseGroup)(schema, group))
|
|
2751
|
+
return;
|
|
2752
|
+
if (group.type) {
|
|
2753
|
+
gen.if((0, dataType_2.checkDataType)(group.type, data, opts.strictNumbers));
|
|
2754
|
+
iterateKeywords(it, group);
|
|
2755
|
+
if (types2.length === 1 && types2[0] === group.type && typeErrors) {
|
|
2756
|
+
gen.else();
|
|
2757
|
+
(0, dataType_2.reportTypeError)(it);
|
|
2758
|
+
}
|
|
2759
|
+
gen.endIf();
|
|
2760
|
+
} else {
|
|
2761
|
+
iterateKeywords(it, group);
|
|
2724
2762
|
}
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
iterateKeywords(it, group);
|
|
2763
|
+
if (!allErrors)
|
|
2764
|
+
gen.if((0, codegen_12._)`${names_12.default.errors} === ${errsCount || 0}`);
|
|
2728
2765
|
}
|
|
2729
|
-
if (!allErrors)
|
|
2730
|
-
gen.if((0, codegen_1$n._)`${names_1$3.default.errors} === ${errsCount || 0}`);
|
|
2731
2766
|
}
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
(
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2767
|
+
function iterateKeywords(it, group) {
|
|
2768
|
+
const { gen, schema, opts: { useDefaults } } = it;
|
|
2769
|
+
if (useDefaults)
|
|
2770
|
+
(0, defaults_1.assignDefaults)(it, group.type);
|
|
2771
|
+
gen.block(() => {
|
|
2772
|
+
for (const rule of group.rules) {
|
|
2773
|
+
if ((0, applicability_12.shouldUseRule)(schema, rule)) {
|
|
2774
|
+
keywordCode(it, rule.keyword, rule.definition, group.type);
|
|
2775
|
+
}
|
|
2741
2776
|
}
|
|
2777
|
+
});
|
|
2778
|
+
}
|
|
2779
|
+
function checkStrictTypes(it, types2) {
|
|
2780
|
+
if (it.schemaEnv.meta || !it.opts.strictTypes)
|
|
2781
|
+
return;
|
|
2782
|
+
checkContextTypes(it, types2);
|
|
2783
|
+
if (!it.opts.allowUnionTypes)
|
|
2784
|
+
checkMultipleTypes(it, types2);
|
|
2785
|
+
checkKeywordTypes(it, it.dataTypes);
|
|
2786
|
+
}
|
|
2787
|
+
function checkContextTypes(it, types2) {
|
|
2788
|
+
if (!types2.length)
|
|
2789
|
+
return;
|
|
2790
|
+
if (!it.dataTypes.length) {
|
|
2791
|
+
it.dataTypes = types2;
|
|
2792
|
+
return;
|
|
2742
2793
|
}
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
if (!it.opts.allowUnionTypes)
|
|
2750
|
-
checkMultipleTypes(it, types2);
|
|
2751
|
-
checkKeywordTypes(it, it.dataTypes);
|
|
2752
|
-
}
|
|
2753
|
-
function checkContextTypes(it, types2) {
|
|
2754
|
-
if (!types2.length)
|
|
2755
|
-
return;
|
|
2756
|
-
if (!it.dataTypes.length) {
|
|
2757
|
-
it.dataTypes = types2;
|
|
2758
|
-
return;
|
|
2794
|
+
types2.forEach((t) => {
|
|
2795
|
+
if (!includesType(it.dataTypes, t)) {
|
|
2796
|
+
strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
|
|
2797
|
+
}
|
|
2798
|
+
});
|
|
2799
|
+
narrowSchemaTypes(it, types2);
|
|
2759
2800
|
}
|
|
2760
|
-
|
|
2761
|
-
if (!
|
|
2762
|
-
strictTypesError(it,
|
|
2801
|
+
function checkMultipleTypes(it, ts) {
|
|
2802
|
+
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
|
|
2803
|
+
strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
2763
2804
|
}
|
|
2764
|
-
});
|
|
2765
|
-
narrowSchemaTypes(it, types2);
|
|
2766
|
-
}
|
|
2767
|
-
function checkMultipleTypes(it, ts) {
|
|
2768
|
-
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
|
|
2769
|
-
strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
2770
2805
|
}
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2806
|
+
function checkKeywordTypes(it, ts) {
|
|
2807
|
+
const rules2 = it.self.RULES.all;
|
|
2808
|
+
for (const keyword2 in rules2) {
|
|
2809
|
+
const rule = rules2[keyword2];
|
|
2810
|
+
if (typeof rule == "object" && (0, applicability_12.shouldUseRule)(it.schema, rule)) {
|
|
2811
|
+
const { type: type2 } = rule.definition;
|
|
2812
|
+
if (type2.length && !type2.some((t) => hasApplicableType(ts, t))) {
|
|
2813
|
+
strictTypesError(it, `missing type "${type2.join(",")}" for keyword "${keyword2}"`);
|
|
2814
|
+
}
|
|
2780
2815
|
}
|
|
2781
2816
|
}
|
|
2782
2817
|
}
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2818
|
+
function hasApplicableType(schTs, kwdT) {
|
|
2819
|
+
return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
|
|
2820
|
+
}
|
|
2821
|
+
function includesType(ts, t) {
|
|
2822
|
+
return ts.includes(t) || t === "integer" && ts.includes("number");
|
|
2823
|
+
}
|
|
2824
|
+
function narrowSchemaTypes(it, withTypes) {
|
|
2825
|
+
const ts = [];
|
|
2826
|
+
for (const t of it.dataTypes) {
|
|
2827
|
+
if (includesType(withTypes, t))
|
|
2828
|
+
ts.push(t);
|
|
2829
|
+
else if (withTypes.includes("integer") && t === "number")
|
|
2830
|
+
ts.push("integer");
|
|
2831
|
+
}
|
|
2832
|
+
it.dataTypes = ts;
|
|
2833
|
+
}
|
|
2834
|
+
function strictTypesError(it, msg) {
|
|
2835
|
+
const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
|
|
2836
|
+
msg += ` at "${schemaPath}" (strictTypes)`;
|
|
2837
|
+
(0, util_12.checkStrictMode)(it, msg, it.opts.strictTypes);
|
|
2838
|
+
}
|
|
2839
|
+
class KeywordCxt {
|
|
2840
|
+
constructor(it, def2, keyword2) {
|
|
2841
|
+
(0, keyword_1.validateKeywordUsage)(it, def2, keyword2);
|
|
2842
|
+
this.gen = it.gen;
|
|
2843
|
+
this.allErrors = it.allErrors;
|
|
2844
|
+
this.keyword = keyword2;
|
|
2845
|
+
this.data = it.data;
|
|
2846
|
+
this.schema = it.schema[keyword2];
|
|
2847
|
+
this.$data = def2.$data && it.opts.$data && this.schema && this.schema.$data;
|
|
2848
|
+
this.schemaValue = (0, util_12.schemaRefOrVal)(it, this.schema, keyword2, this.$data);
|
|
2849
|
+
this.schemaType = def2.schemaType;
|
|
2850
|
+
this.parentSchema = it.schema;
|
|
2851
|
+
this.params = {};
|
|
2852
|
+
this.it = it;
|
|
2853
|
+
this.def = def2;
|
|
2854
|
+
if (this.$data) {
|
|
2855
|
+
this.schemaCode = it.gen.const("vSchema", getData(this.$data, it));
|
|
2856
|
+
} else {
|
|
2857
|
+
this.schemaCode = this.schemaValue;
|
|
2858
|
+
if (!(0, keyword_1.validSchemaType)(this.schema, def2.schemaType, def2.allowUndefined)) {
|
|
2859
|
+
throw new Error(`${keyword2} value must be ${JSON.stringify(def2.schemaType)}`);
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
|
|
2863
|
+
this.errsCount = it.gen.const("_errs", names_12.default.errors);
|
|
2826
2864
|
}
|
|
2827
2865
|
}
|
|
2828
|
-
|
|
2829
|
-
this.
|
|
2866
|
+
result(condition, successAction, failAction) {
|
|
2867
|
+
this.failResult((0, codegen_12.not)(condition), successAction, failAction);
|
|
2830
2868
|
}
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2869
|
+
failResult(condition, successAction, failAction) {
|
|
2870
|
+
this.gen.if(condition);
|
|
2871
|
+
if (failAction)
|
|
2872
|
+
failAction();
|
|
2873
|
+
else
|
|
2874
|
+
this.error();
|
|
2875
|
+
if (successAction) {
|
|
2876
|
+
this.gen.else();
|
|
2877
|
+
successAction();
|
|
2878
|
+
if (this.allErrors)
|
|
2879
|
+
this.gen.endIf();
|
|
2880
|
+
} else {
|
|
2881
|
+
if (this.allErrors)
|
|
2882
|
+
this.gen.endIf();
|
|
2883
|
+
else
|
|
2884
|
+
this.gen.else();
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
pass(condition, failAction) {
|
|
2888
|
+
this.failResult((0, codegen_12.not)(condition), void 0, failAction);
|
|
2889
|
+
}
|
|
2890
|
+
fail(condition) {
|
|
2891
|
+
if (condition === void 0) {
|
|
2892
|
+
this.error();
|
|
2893
|
+
if (!this.allErrors)
|
|
2894
|
+
this.gen.if(false);
|
|
2895
|
+
return;
|
|
2896
|
+
}
|
|
2897
|
+
this.gen.if(condition);
|
|
2840
2898
|
this.error();
|
|
2841
|
-
if (successAction) {
|
|
2842
|
-
this.gen.else();
|
|
2843
|
-
successAction();
|
|
2844
|
-
if (this.allErrors)
|
|
2845
|
-
this.gen.endIf();
|
|
2846
|
-
} else {
|
|
2847
2899
|
if (this.allErrors)
|
|
2848
2900
|
this.gen.endIf();
|
|
2849
2901
|
else
|
|
2850
2902
|
this.gen.else();
|
|
2851
2903
|
}
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2904
|
+
fail$data(condition) {
|
|
2905
|
+
if (!this.$data)
|
|
2906
|
+
return this.fail(condition);
|
|
2907
|
+
const { schemaCode } = this;
|
|
2908
|
+
this.fail((0, codegen_12._)`${schemaCode} !== undefined && (${(0, codegen_12.or)(this.invalid$data(), condition)})`);
|
|
2909
|
+
}
|
|
2910
|
+
error(append, errorParams, errorPaths) {
|
|
2911
|
+
if (errorParams) {
|
|
2912
|
+
this.setParams(errorParams);
|
|
2913
|
+
this._error(append, errorPaths);
|
|
2914
|
+
this.setParams({});
|
|
2915
|
+
return;
|
|
2916
|
+
}
|
|
2917
|
+
this._error(append, errorPaths);
|
|
2918
|
+
}
|
|
2919
|
+
_error(append, errorPaths) {
|
|
2920
|
+
(append ? errors_12.reportExtraError : errors_12.reportError)(this, this.def.error, errorPaths);
|
|
2921
|
+
}
|
|
2922
|
+
$dataError() {
|
|
2923
|
+
(0, errors_12.reportError)(this, this.def.$dataError || errors_12.keyword$DataError);
|
|
2924
|
+
}
|
|
2925
|
+
reset() {
|
|
2926
|
+
if (this.errsCount === void 0)
|
|
2927
|
+
throw new Error('add "trackErrors" to keyword definition');
|
|
2928
|
+
(0, errors_12.resetErrorsCount)(this.gen, this.errsCount);
|
|
2929
|
+
}
|
|
2930
|
+
ok(cond) {
|
|
2859
2931
|
if (!this.allErrors)
|
|
2860
|
-
this.gen.if(
|
|
2861
|
-
return;
|
|
2932
|
+
this.gen.if(cond);
|
|
2862
2933
|
}
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
this.gen.else();
|
|
2869
|
-
}
|
|
2870
|
-
fail$data(condition) {
|
|
2871
|
-
if (!this.$data)
|
|
2872
|
-
return this.fail(condition);
|
|
2873
|
-
const { schemaCode } = this;
|
|
2874
|
-
this.fail((0, codegen_1$n._)`${schemaCode} !== undefined && (${(0, codegen_1$n.or)(this.invalid$data(), condition)})`);
|
|
2875
|
-
}
|
|
2876
|
-
error(append, errorParams, errorPaths) {
|
|
2877
|
-
if (errorParams) {
|
|
2878
|
-
this.setParams(errorParams);
|
|
2879
|
-
this._error(append, errorPaths);
|
|
2880
|
-
this.setParams({});
|
|
2881
|
-
return;
|
|
2934
|
+
setParams(obj, assign) {
|
|
2935
|
+
if (assign)
|
|
2936
|
+
Object.assign(this.params, obj);
|
|
2937
|
+
else
|
|
2938
|
+
this.params = obj;
|
|
2882
2939
|
}
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
$dataError() {
|
|
2889
|
-
(0, errors_1.reportError)(this, this.def.$dataError || errors_1.keyword$DataError);
|
|
2890
|
-
}
|
|
2891
|
-
reset() {
|
|
2892
|
-
if (this.errsCount === void 0)
|
|
2893
|
-
throw new Error('add "trackErrors" to keyword definition');
|
|
2894
|
-
(0, errors_1.resetErrorsCount)(this.gen, this.errsCount);
|
|
2895
|
-
}
|
|
2896
|
-
ok(cond) {
|
|
2897
|
-
if (!this.allErrors)
|
|
2898
|
-
this.gen.if(cond);
|
|
2899
|
-
}
|
|
2900
|
-
setParams(obj, assign) {
|
|
2901
|
-
if (assign)
|
|
2902
|
-
Object.assign(this.params, obj);
|
|
2903
|
-
else
|
|
2904
|
-
this.params = obj;
|
|
2905
|
-
}
|
|
2906
|
-
block$data(valid, codeBlock, $dataValid = codegen_1$n.nil) {
|
|
2907
|
-
this.gen.block(() => {
|
|
2908
|
-
this.check$data(valid, $dataValid);
|
|
2909
|
-
codeBlock();
|
|
2910
|
-
});
|
|
2911
|
-
}
|
|
2912
|
-
check$data(valid = codegen_1$n.nil, $dataValid = codegen_1$n.nil) {
|
|
2913
|
-
if (!this.$data)
|
|
2914
|
-
return;
|
|
2915
|
-
const { gen, schemaCode, schemaType, def: def2 } = this;
|
|
2916
|
-
gen.if((0, codegen_1$n.or)((0, codegen_1$n._)`${schemaCode} === undefined`, $dataValid));
|
|
2917
|
-
if (valid !== codegen_1$n.nil)
|
|
2918
|
-
gen.assign(valid, true);
|
|
2919
|
-
if (schemaType.length || def2.validateSchema) {
|
|
2920
|
-
gen.elseIf(this.invalid$data());
|
|
2921
|
-
this.$dataError();
|
|
2922
|
-
if (valid !== codegen_1$n.nil)
|
|
2923
|
-
gen.assign(valid, false);
|
|
2940
|
+
block$data(valid, codeBlock, $dataValid = codegen_12.nil) {
|
|
2941
|
+
this.gen.block(() => {
|
|
2942
|
+
this.check$data(valid, $dataValid);
|
|
2943
|
+
codeBlock();
|
|
2944
|
+
});
|
|
2924
2945
|
}
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2946
|
+
check$data(valid = codegen_12.nil, $dataValid = codegen_12.nil) {
|
|
2947
|
+
if (!this.$data)
|
|
2948
|
+
return;
|
|
2949
|
+
const { gen, schemaCode, schemaType, def: def2 } = this;
|
|
2950
|
+
gen.if((0, codegen_12.or)((0, codegen_12._)`${schemaCode} === undefined`, $dataValid));
|
|
2951
|
+
if (valid !== codegen_12.nil)
|
|
2952
|
+
gen.assign(valid, true);
|
|
2953
|
+
if (schemaType.length || def2.validateSchema) {
|
|
2954
|
+
gen.elseIf(this.invalid$data());
|
|
2955
|
+
this.$dataError();
|
|
2956
|
+
if (valid !== codegen_12.nil)
|
|
2957
|
+
gen.assign(valid, false);
|
|
2936
2958
|
}
|
|
2937
|
-
|
|
2959
|
+
gen.else();
|
|
2938
2960
|
}
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2961
|
+
invalid$data() {
|
|
2962
|
+
const { gen, schemaCode, schemaType, def: def2, it } = this;
|
|
2963
|
+
return (0, codegen_12.or)(wrong$DataType(), invalid$DataSchema());
|
|
2964
|
+
function wrong$DataType() {
|
|
2965
|
+
if (schemaType.length) {
|
|
2966
|
+
if (!(schemaCode instanceof codegen_12.Name))
|
|
2967
|
+
throw new Error("ajv implementation error");
|
|
2968
|
+
const st = Array.isArray(schemaType) ? schemaType : [schemaType];
|
|
2969
|
+
return (0, codegen_12._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
|
|
2970
|
+
}
|
|
2971
|
+
return codegen_12.nil;
|
|
2972
|
+
}
|
|
2973
|
+
function invalid$DataSchema() {
|
|
2974
|
+
if (def2.validateSchema) {
|
|
2975
|
+
const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
|
|
2976
|
+
return (0, codegen_12._)`!${validateSchemaRef}(${schemaCode})`;
|
|
2977
|
+
}
|
|
2978
|
+
return codegen_12.nil;
|
|
2943
2979
|
}
|
|
2944
|
-
return codegen_1$n.nil;
|
|
2945
2980
|
}
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
return nextContext;
|
|
2954
|
-
}
|
|
2955
|
-
mergeEvaluated(schemaCxt, toName) {
|
|
2956
|
-
const { it, gen } = this;
|
|
2957
|
-
if (!it.opts.unevaluated)
|
|
2958
|
-
return;
|
|
2959
|
-
if (it.props !== true && schemaCxt.props !== void 0) {
|
|
2960
|
-
it.props = util_1$l.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
|
|
2981
|
+
subschema(appl, valid) {
|
|
2982
|
+
const subschema2 = (0, subschema_1.getSubschema)(this.it, appl);
|
|
2983
|
+
(0, subschema_1.extendSubschemaData)(subschema2, this.it, appl);
|
|
2984
|
+
(0, subschema_1.extendSubschemaMode)(subschema2, appl);
|
|
2985
|
+
const nextContext = { ...this.it, ...subschema2, items: void 0, props: void 0 };
|
|
2986
|
+
subschemaCode(nextContext, valid);
|
|
2987
|
+
return nextContext;
|
|
2961
2988
|
}
|
|
2962
|
-
|
|
2963
|
-
|
|
2989
|
+
mergeEvaluated(schemaCxt, toName) {
|
|
2990
|
+
const { it, gen } = this;
|
|
2991
|
+
if (!it.opts.unevaluated)
|
|
2992
|
+
return;
|
|
2993
|
+
if (it.props !== true && schemaCxt.props !== void 0) {
|
|
2994
|
+
it.props = util_12.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
|
|
2995
|
+
}
|
|
2996
|
+
if (it.items !== true && schemaCxt.items !== void 0) {
|
|
2997
|
+
it.items = util_12.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
|
|
2998
|
+
}
|
|
2964
2999
|
}
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
3000
|
+
mergeValidEvaluated(schemaCxt, valid) {
|
|
3001
|
+
const { it, gen } = this;
|
|
3002
|
+
if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
|
|
3003
|
+
gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_12.Name));
|
|
3004
|
+
return true;
|
|
3005
|
+
}
|
|
2971
3006
|
}
|
|
2972
3007
|
}
|
|
3008
|
+
validate.KeywordCxt = KeywordCxt;
|
|
3009
|
+
function keywordCode(it, keyword2, def2, ruleType) {
|
|
3010
|
+
const cxt = new KeywordCxt(it, def2, keyword2);
|
|
3011
|
+
if ("code" in def2) {
|
|
3012
|
+
def2.code(cxt, ruleType);
|
|
3013
|
+
} else if (cxt.$data && def2.validate) {
|
|
3014
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
3015
|
+
} else if ("macro" in def2) {
|
|
3016
|
+
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
3017
|
+
} else if (def2.compile || def2.validate) {
|
|
3018
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
3022
|
+
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
3023
|
+
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
3024
|
+
let jsonPointer;
|
|
3025
|
+
let data;
|
|
3026
|
+
if ($data === "")
|
|
3027
|
+
return names_12.default.rootData;
|
|
3028
|
+
if ($data[0] === "/") {
|
|
3029
|
+
if (!JSON_POINTER.test($data))
|
|
3030
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
3031
|
+
jsonPointer = $data;
|
|
3032
|
+
data = names_12.default.rootData;
|
|
3033
|
+
} else {
|
|
3034
|
+
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
3035
|
+
if (!matches)
|
|
3036
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
3037
|
+
const up = +matches[1];
|
|
3038
|
+
jsonPointer = matches[2];
|
|
3039
|
+
if (jsonPointer === "#") {
|
|
3040
|
+
if (up >= dataLevel)
|
|
3041
|
+
throw new Error(errorMsg("property/index", up));
|
|
3042
|
+
return dataPathArr[dataLevel - up];
|
|
3043
|
+
}
|
|
3044
|
+
if (up > dataLevel)
|
|
3045
|
+
throw new Error(errorMsg("data", up));
|
|
3046
|
+
data = dataNames[dataLevel - up];
|
|
3047
|
+
if (!jsonPointer)
|
|
3048
|
+
return data;
|
|
3049
|
+
}
|
|
3050
|
+
let expr = data;
|
|
3051
|
+
const segments = jsonPointer.split("/");
|
|
3052
|
+
for (const segment of segments) {
|
|
3053
|
+
if (segment) {
|
|
3054
|
+
data = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)((0, util_12.unescapeJsonPointer)(segment))}`;
|
|
3055
|
+
expr = (0, codegen_12._)`${expr} && ${data}`;
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3058
|
+
return expr;
|
|
3059
|
+
function errorMsg(pointerType, up) {
|
|
3060
|
+
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
validate.getData = getData;
|
|
3064
|
+
return validate;
|
|
2973
3065
|
}
|
|
2974
|
-
validate.KeywordCxt = KeywordCxt;
|
|
2975
|
-
function keywordCode(it, keyword2, def2, ruleType) {
|
|
2976
|
-
const cxt = new KeywordCxt(it, def2, keyword2);
|
|
2977
|
-
if ("code" in def2) {
|
|
2978
|
-
def2.code(cxt, ruleType);
|
|
2979
|
-
} else if (cxt.$data && def2.validate) {
|
|
2980
|
-
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2981
|
-
} else if ("macro" in def2) {
|
|
2982
|
-
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
2983
|
-
} else if (def2.compile || def2.validate) {
|
|
2984
|
-
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2985
|
-
}
|
|
2986
|
-
}
|
|
2987
|
-
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
2988
|
-
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
2989
|
-
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
2990
|
-
let jsonPointer;
|
|
2991
|
-
let data;
|
|
2992
|
-
if ($data === "")
|
|
2993
|
-
return names_1$3.default.rootData;
|
|
2994
|
-
if ($data[0] === "/") {
|
|
2995
|
-
if (!JSON_POINTER.test($data))
|
|
2996
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2997
|
-
jsonPointer = $data;
|
|
2998
|
-
data = names_1$3.default.rootData;
|
|
2999
|
-
} else {
|
|
3000
|
-
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
3001
|
-
if (!matches)
|
|
3002
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
3003
|
-
const up = +matches[1];
|
|
3004
|
-
jsonPointer = matches[2];
|
|
3005
|
-
if (jsonPointer === "#") {
|
|
3006
|
-
if (up >= dataLevel)
|
|
3007
|
-
throw new Error(errorMsg("property/index", up));
|
|
3008
|
-
return dataPathArr[dataLevel - up];
|
|
3009
|
-
}
|
|
3010
|
-
if (up > dataLevel)
|
|
3011
|
-
throw new Error(errorMsg("data", up));
|
|
3012
|
-
data = dataNames[dataLevel - up];
|
|
3013
|
-
if (!jsonPointer)
|
|
3014
|
-
return data;
|
|
3015
|
-
}
|
|
3016
|
-
let expr = data;
|
|
3017
|
-
const segments = jsonPointer.split("/");
|
|
3018
|
-
for (const segment of segments) {
|
|
3019
|
-
if (segment) {
|
|
3020
|
-
data = (0, codegen_1$n._)`${data}${(0, codegen_1$n.getProperty)((0, util_1$l.unescapeJsonPointer)(segment))}`;
|
|
3021
|
-
expr = (0, codegen_1$n._)`${expr} && ${data}`;
|
|
3022
|
-
}
|
|
3023
|
-
}
|
|
3024
|
-
return expr;
|
|
3025
|
-
function errorMsg(pointerType, up) {
|
|
3026
|
-
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
3027
|
-
}
|
|
3028
|
-
}
|
|
3029
|
-
validate.getData = getData;
|
|
3030
3066
|
var validation_error = {};
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3067
|
+
var hasRequiredValidation_error;
|
|
3068
|
+
function requireValidation_error() {
|
|
3069
|
+
if (hasRequiredValidation_error) return validation_error;
|
|
3070
|
+
hasRequiredValidation_error = 1;
|
|
3071
|
+
Object.defineProperty(validation_error, "__esModule", { value: true });
|
|
3072
|
+
class ValidationError extends Error {
|
|
3073
|
+
constructor(errors2) {
|
|
3074
|
+
super("validation failed");
|
|
3075
|
+
this.errors = errors2;
|
|
3076
|
+
this.ajv = this.validation = true;
|
|
3077
|
+
}
|
|
3037
3078
|
}
|
|
3079
|
+
validation_error.default = ValidationError;
|
|
3080
|
+
return validation_error;
|
|
3038
3081
|
}
|
|
3039
|
-
validation_error.default = ValidationError;
|
|
3040
3082
|
var ref_error = {};
|
|
3041
3083
|
Object.defineProperty(ref_error, "__esModule", { value: true });
|
|
3042
3084
|
const resolve_1$1 = resolve$2;
|
|
@@ -3052,11 +3094,11 @@ var compile = {};
|
|
|
3052
3094
|
Object.defineProperty(compile, "__esModule", { value: true });
|
|
3053
3095
|
compile.resolveSchema = compile.getCompilingSchema = compile.resolveRef = compile.compileSchema = compile.SchemaEnv = void 0;
|
|
3054
3096
|
const codegen_1$m = codegen;
|
|
3055
|
-
const validation_error_1 =
|
|
3056
|
-
const names_1$2 =
|
|
3097
|
+
const validation_error_1 = requireValidation_error();
|
|
3098
|
+
const names_1$2 = requireNames();
|
|
3057
3099
|
const resolve_1 = resolve$2;
|
|
3058
3100
|
const util_1$k = util;
|
|
3059
|
-
const validate_1$1 =
|
|
3101
|
+
const validate_1$1 = requireValidate();
|
|
3060
3102
|
class SchemaEnv {
|
|
3061
3103
|
constructor(env) {
|
|
3062
3104
|
var _a;
|
|
@@ -3985,7 +4027,7 @@ uri$1.default = uri;
|
|
|
3985
4027
|
(function(exports$1) {
|
|
3986
4028
|
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
3987
4029
|
exports$1.CodeGen = exports$1.Name = exports$1.nil = exports$1.stringify = exports$1.str = exports$1._ = exports$1.KeywordCxt = void 0;
|
|
3988
|
-
var validate_12 =
|
|
4030
|
+
var validate_12 = requireValidate();
|
|
3989
4031
|
Object.defineProperty(exports$1, "KeywordCxt", { enumerable: true, get: function() {
|
|
3990
4032
|
return validate_12.KeywordCxt;
|
|
3991
4033
|
} });
|
|
@@ -4008,7 +4050,7 @@ uri$1.default = uri;
|
|
|
4008
4050
|
Object.defineProperty(exports$1, "CodeGen", { enumerable: true, get: function() {
|
|
4009
4051
|
return codegen_12.CodeGen;
|
|
4010
4052
|
} });
|
|
4011
|
-
const validation_error_12 =
|
|
4053
|
+
const validation_error_12 = requireValidation_error();
|
|
4012
4054
|
const ref_error_12 = ref_error;
|
|
4013
4055
|
const rules_12 = rules;
|
|
4014
4056
|
const compile_12 = compile;
|
|
@@ -4605,7 +4647,7 @@ ref.callRef = ref.getValidate = void 0;
|
|
|
4605
4647
|
const ref_error_1$1 = ref_error;
|
|
4606
4648
|
const code_1$8 = code;
|
|
4607
4649
|
const codegen_1$l = codegen;
|
|
4608
|
-
const names_1$1 =
|
|
4650
|
+
const names_1$1 = requireNames();
|
|
4609
4651
|
const compile_1$1 = compile;
|
|
4610
4652
|
const util_1$j = util;
|
|
4611
4653
|
const def$r = {
|
|
@@ -5489,7 +5531,7 @@ var additionalProperties = {};
|
|
|
5489
5531
|
Object.defineProperty(additionalProperties, "__esModule", { value: true });
|
|
5490
5532
|
const code_1$3 = code;
|
|
5491
5533
|
const codegen_1$5 = codegen;
|
|
5492
|
-
const names_1 =
|
|
5534
|
+
const names_1 = requireNames();
|
|
5493
5535
|
const util_1$8 = util;
|
|
5494
5536
|
const error$4 = {
|
|
5495
5537
|
message: "must NOT have additional properties",
|
|
@@ -5587,7 +5629,7 @@ const def$a = {
|
|
|
5587
5629
|
additionalProperties.default = def$a;
|
|
5588
5630
|
var properties$1 = {};
|
|
5589
5631
|
Object.defineProperty(properties$1, "__esModule", { value: true });
|
|
5590
|
-
const validate_1 =
|
|
5632
|
+
const validate_1 = requireValidate();
|
|
5591
5633
|
const code_1$2 = code;
|
|
5592
5634
|
const util_1$7 = util;
|
|
5593
5635
|
const additionalProperties_1$1 = additionalProperties;
|
|
@@ -6438,7 +6480,7 @@ const require$$3 = {
|
|
|
6438
6480
|
module2.exports.Ajv = Ajv;
|
|
6439
6481
|
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
6440
6482
|
exports$1.default = Ajv;
|
|
6441
|
-
var validate_12 =
|
|
6483
|
+
var validate_12 = requireValidate();
|
|
6442
6484
|
Object.defineProperty(exports$1, "KeywordCxt", { enumerable: true, get: function() {
|
|
6443
6485
|
return validate_12.KeywordCxt;
|
|
6444
6486
|
} });
|
|
@@ -6461,7 +6503,7 @@ const require$$3 = {
|
|
|
6461
6503
|
Object.defineProperty(exports$1, "CodeGen", { enumerable: true, get: function() {
|
|
6462
6504
|
return codegen_12.CodeGen;
|
|
6463
6505
|
} });
|
|
6464
|
-
var validation_error_12 =
|
|
6506
|
+
var validation_error_12 = requireValidation_error();
|
|
6465
6507
|
Object.defineProperty(exports$1, "ValidationError", { enumerable: true, get: function() {
|
|
6466
6508
|
return validation_error_12.default;
|
|
6467
6509
|
} });
|
|
@@ -7151,15 +7193,16 @@ const _sfc_main$4 = /* @__PURE__ */ vue.defineComponent({
|
|
|
7151
7193
|
var _a2;
|
|
7152
7194
|
return [
|
|
7153
7195
|
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList((_a2 = vue.unref(tableConfig2)) == null ? void 0 : _a2.headerButtons, (buttonItem) => {
|
|
7154
|
-
return vue.openBlock(), vue.createBlock(vue.unref(elementPlus.ElButton), {
|
|
7155
|
-
key: buttonItem.eventKey
|
|
7196
|
+
return vue.openBlock(), vue.createBlock(vue.unref(elementPlus.ElButton), vue.mergeProps({
|
|
7197
|
+
key: buttonItem.eventKey
|
|
7198
|
+
}, { ref_for: true }, buttonItem == null ? void 0 : buttonItem.eventOption, {
|
|
7156
7199
|
onClick: ($event) => onOperate({ btnConfig: buttonItem })
|
|
7157
|
-
}, {
|
|
7200
|
+
}), {
|
|
7158
7201
|
default: vue.withCtx(() => [
|
|
7159
7202
|
vue.createTextVNode(vue.toDisplayString(buttonItem.label), 1)
|
|
7160
7203
|
]),
|
|
7161
7204
|
_: 2
|
|
7162
|
-
},
|
|
7205
|
+
}, 1040, ["onClick"]);
|
|
7163
7206
|
}), 128))
|
|
7164
7207
|
];
|
|
7165
7208
|
}),
|
|
@@ -7184,7 +7227,7 @@ const _sfc_main$4 = /* @__PURE__ */ vue.defineComponent({
|
|
|
7184
7227
|
};
|
|
7185
7228
|
}
|
|
7186
7229
|
});
|
|
7187
|
-
const tablePanel = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-
|
|
7230
|
+
const tablePanel = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-2f2f7b58"]]);
|
|
7188
7231
|
const _sfc_main$3 = /* @__PURE__ */ vue.defineComponent({
|
|
7189
7232
|
__name: "input",
|
|
7190
7233
|
props: {
|