create-ones-app 0.0.9 → 0.0.11
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 +1002 -946
- package/dist/index.js +1002 -946
- package/package.json +4 -4
- package/template/example/package-lock.json +68 -71
- package/template/example/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1281,8 +1281,8 @@ var scope = {};
|
|
|
1281
1281
|
var util = {};
|
|
1282
1282
|
Object.defineProperty(util, "__esModule", { value: true });
|
|
1283
1283
|
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;
|
|
1284
|
-
const codegen_1$
|
|
1285
|
-
const code_1$
|
|
1284
|
+
const codegen_1$s = codegen;
|
|
1285
|
+
const code_1$9 = code$1;
|
|
1286
1286
|
function toHash(arr) {
|
|
1287
1287
|
const hash = {};
|
|
1288
1288
|
for (const item of arr)
|
|
@@ -1335,9 +1335,9 @@ function schemaRefOrVal({ topSchemaRef, schemaPath }, schema, keyword2, $data) {
|
|
|
1335
1335
|
if (typeof schema == "number" || typeof schema == "boolean")
|
|
1336
1336
|
return schema;
|
|
1337
1337
|
if (typeof schema == "string")
|
|
1338
|
-
return (0, codegen_1$
|
|
1338
|
+
return (0, codegen_1$s._)`${schema}`;
|
|
1339
1339
|
}
|
|
1340
|
-
return (0, codegen_1$
|
|
1340
|
+
return (0, codegen_1$s._)`${topSchemaRef}${schemaPath}${(0, codegen_1$s.getProperty)(keyword2)}`;
|
|
1341
1341
|
}
|
|
1342
1342
|
util.schemaRefOrVal = schemaRefOrVal;
|
|
1343
1343
|
function unescapeFragment(str) {
|
|
@@ -1369,20 +1369,20 @@ function eachItem(xs, f) {
|
|
|
1369
1369
|
util.eachItem = eachItem;
|
|
1370
1370
|
function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues, resultToName }) {
|
|
1371
1371
|
return (gen, from, to, toName) => {
|
|
1372
|
-
const res = to === void 0 ? from : to instanceof codegen_1$
|
|
1373
|
-
return toName === codegen_1$
|
|
1372
|
+
const res = to === void 0 ? from : to instanceof codegen_1$s.Name ? (from instanceof codegen_1$s.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1$s.Name ? (mergeToName(gen, to, from), from) : mergeValues(from, to);
|
|
1373
|
+
return toName === codegen_1$s.Name && !(res instanceof codegen_1$s.Name) ? resultToName(gen, res) : res;
|
|
1374
1374
|
};
|
|
1375
1375
|
}
|
|
1376
1376
|
util.mergeEvaluated = {
|
|
1377
1377
|
props: makeMergeEvaluated({
|
|
1378
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
1379
|
-
gen.if((0, codegen_1$
|
|
1378
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$s._)`${to} !== true && ${from} !== undefined`, () => {
|
|
1379
|
+
gen.if((0, codegen_1$s._)`${from} === true`, () => gen.assign(to, true), () => gen.assign(to, (0, codegen_1$s._)`${to} || {}`).code((0, codegen_1$s._)`Object.assign(${to}, ${from})`));
|
|
1380
1380
|
}),
|
|
1381
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
1381
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$s._)`${to} !== true`, () => {
|
|
1382
1382
|
if (from === true) {
|
|
1383
1383
|
gen.assign(to, true);
|
|
1384
1384
|
} else {
|
|
1385
|
-
gen.assign(to, (0, codegen_1$
|
|
1385
|
+
gen.assign(to, (0, codegen_1$s._)`${to} || {}`);
|
|
1386
1386
|
setEvaluated(gen, to, from);
|
|
1387
1387
|
}
|
|
1388
1388
|
}),
|
|
@@ -1390,8 +1390,8 @@ util.mergeEvaluated = {
|
|
|
1390
1390
|
resultToName: evaluatedPropsToName
|
|
1391
1391
|
}),
|
|
1392
1392
|
items: makeMergeEvaluated({
|
|
1393
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
1394
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
1393
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$s._)`${to} !== true && ${from} !== undefined`, () => gen.assign(to, (0, codegen_1$s._)`${from} === true ? true : ${to} > ${from} ? ${to} : ${from}`)),
|
|
1394
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$s._)`${to} !== true`, () => gen.assign(to, from === true ? true : (0, codegen_1$s._)`${to} > ${from} ? ${to} : ${from}`)),
|
|
1395
1395
|
mergeValues: (from, to) => from === true ? true : Math.max(from, to),
|
|
1396
1396
|
resultToName: (gen, items2) => gen.var("items", items2)
|
|
1397
1397
|
})
|
|
@@ -1399,21 +1399,21 @@ util.mergeEvaluated = {
|
|
|
1399
1399
|
function evaluatedPropsToName(gen, ps) {
|
|
1400
1400
|
if (ps === true)
|
|
1401
1401
|
return gen.var("props", true);
|
|
1402
|
-
const props = gen.var("props", (0, codegen_1$
|
|
1402
|
+
const props = gen.var("props", (0, codegen_1$s._)`{}`);
|
|
1403
1403
|
if (ps !== void 0)
|
|
1404
1404
|
setEvaluated(gen, props, ps);
|
|
1405
1405
|
return props;
|
|
1406
1406
|
}
|
|
1407
1407
|
util.evaluatedPropsToName = evaluatedPropsToName;
|
|
1408
1408
|
function setEvaluated(gen, props, ps) {
|
|
1409
|
-
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$
|
|
1409
|
+
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$s._)`${props}${(0, codegen_1$s.getProperty)(p)}`, true));
|
|
1410
1410
|
}
|
|
1411
1411
|
util.setEvaluated = setEvaluated;
|
|
1412
1412
|
const snippets = {};
|
|
1413
1413
|
function useFunc(gen, f) {
|
|
1414
1414
|
return gen.scopeValue("func", {
|
|
1415
1415
|
ref: f,
|
|
1416
|
-
code: snippets[f.code] || (snippets[f.code] = new code_1$
|
|
1416
|
+
code: snippets[f.code] || (snippets[f.code] = new code_1$9._Code(f.code))
|
|
1417
1417
|
});
|
|
1418
1418
|
}
|
|
1419
1419
|
util.useFunc = useFunc;
|
|
@@ -1423,11 +1423,11 @@ var Type;
|
|
|
1423
1423
|
Type2[Type2["Str"] = 1] = "Str";
|
|
1424
1424
|
})(Type || (util.Type = Type = {}));
|
|
1425
1425
|
function getErrorPath(dataProp, dataPropType, jsPropertySyntax) {
|
|
1426
|
-
if (dataProp instanceof codegen_1$
|
|
1426
|
+
if (dataProp instanceof codegen_1$s.Name) {
|
|
1427
1427
|
const isNumber = dataPropType === Type.Num;
|
|
1428
|
-
return jsPropertySyntax ? isNumber ? (0, codegen_1$
|
|
1428
|
+
return jsPropertySyntax ? isNumber ? (0, codegen_1$s._)`"[" + ${dataProp} + "]"` : (0, codegen_1$s._)`"['" + ${dataProp} + "']"` : isNumber ? (0, codegen_1$s._)`"/" + ${dataProp}` : (0, codegen_1$s._)`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")`;
|
|
1429
1429
|
}
|
|
1430
|
-
return jsPropertySyntax ? (0, codegen_1$
|
|
1430
|
+
return jsPropertySyntax ? (0, codegen_1$s.getProperty)(dataProp).toString() : "/" + escapeJsonPointer(dataProp);
|
|
1431
1431
|
}
|
|
1432
1432
|
util.getErrorPath = getErrorPath;
|
|
1433
1433
|
function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
@@ -1439,45 +1439,52 @@ function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
|
1439
1439
|
it.self.logger.warn(msg);
|
|
1440
1440
|
}
|
|
1441
1441
|
util.checkStrictMode = checkStrictMode;
|
|
1442
|
-
var names
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1442
|
+
var names = {};
|
|
1443
|
+
var hasRequiredNames;
|
|
1444
|
+
function requireNames() {
|
|
1445
|
+
if (hasRequiredNames)
|
|
1446
|
+
return names;
|
|
1447
|
+
hasRequiredNames = 1;
|
|
1448
|
+
Object.defineProperty(names, "__esModule", { value: true });
|
|
1449
|
+
const codegen_12 = codegen;
|
|
1450
|
+
const names$1 = {
|
|
1451
|
+
// validation function arguments
|
|
1452
|
+
data: new codegen_12.Name("data"),
|
|
1453
|
+
// data passed to validation function
|
|
1454
|
+
// args passed from referencing schema
|
|
1455
|
+
valCxt: new codegen_12.Name("valCxt"),
|
|
1456
|
+
// validation/data context - should not be used directly, it is destructured to the names below
|
|
1457
|
+
instancePath: new codegen_12.Name("instancePath"),
|
|
1458
|
+
parentData: new codegen_12.Name("parentData"),
|
|
1459
|
+
parentDataProperty: new codegen_12.Name("parentDataProperty"),
|
|
1460
|
+
rootData: new codegen_12.Name("rootData"),
|
|
1461
|
+
// root data - same as the data passed to the first/top validation function
|
|
1462
|
+
dynamicAnchors: new codegen_12.Name("dynamicAnchors"),
|
|
1463
|
+
// used to support recursiveRef and dynamicRef
|
|
1464
|
+
// function scoped variables
|
|
1465
|
+
vErrors: new codegen_12.Name("vErrors"),
|
|
1466
|
+
// null or array of validation errors
|
|
1467
|
+
errors: new codegen_12.Name("errors"),
|
|
1468
|
+
// counter of validation errors
|
|
1469
|
+
this: new codegen_12.Name("this"),
|
|
1470
|
+
// "globals"
|
|
1471
|
+
self: new codegen_12.Name("self"),
|
|
1472
|
+
scope: new codegen_12.Name("scope"),
|
|
1473
|
+
// JTD serialize/parse name for JSON string and position
|
|
1474
|
+
json: new codegen_12.Name("json"),
|
|
1475
|
+
jsonPos: new codegen_12.Name("jsonPos"),
|
|
1476
|
+
jsonLen: new codegen_12.Name("jsonLen"),
|
|
1477
|
+
jsonPart: new codegen_12.Name("jsonPart")
|
|
1478
|
+
};
|
|
1479
|
+
names.default = names$1;
|
|
1480
|
+
return names;
|
|
1481
|
+
}
|
|
1475
1482
|
(function(exports2) {
|
|
1476
1483
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1477
1484
|
exports2.extendErrors = exports2.resetErrorsCount = exports2.reportExtraError = exports2.reportError = exports2.keyword$DataError = exports2.keywordError = void 0;
|
|
1478
1485
|
const codegen_12 = codegen;
|
|
1479
1486
|
const util_12 = util;
|
|
1480
|
-
const names_12 =
|
|
1487
|
+
const names_12 = requireNames();
|
|
1481
1488
|
exports2.keywordError = {
|
|
1482
1489
|
message: ({ keyword: keyword2 }) => (0, codegen_12.str)`must pass "${keyword2}" keyword validation`
|
|
1483
1490
|
};
|
|
@@ -1589,49 +1596,56 @@ names$1.default = names;
|
|
|
1589
1596
|
keyValues.push([E.propertyName, propertyName]);
|
|
1590
1597
|
}
|
|
1591
1598
|
})(errors);
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
const
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1599
|
+
var hasRequiredBoolSchema;
|
|
1600
|
+
function requireBoolSchema() {
|
|
1601
|
+
if (hasRequiredBoolSchema)
|
|
1602
|
+
return boolSchema;
|
|
1603
|
+
hasRequiredBoolSchema = 1;
|
|
1604
|
+
Object.defineProperty(boolSchema, "__esModule", { value: true });
|
|
1605
|
+
boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
|
|
1606
|
+
const errors_12 = errors;
|
|
1607
|
+
const codegen_12 = codegen;
|
|
1608
|
+
const names_12 = requireNames();
|
|
1609
|
+
const boolError = {
|
|
1610
|
+
message: "boolean schema is false"
|
|
1611
|
+
};
|
|
1612
|
+
function topBoolOrEmptySchema(it) {
|
|
1613
|
+
const { gen, schema, validateName } = it;
|
|
1614
|
+
if (schema === false) {
|
|
1615
|
+
falseSchemaError(it, false);
|
|
1616
|
+
} else if (typeof schema == "object" && schema.$async === true) {
|
|
1617
|
+
gen.return(names_12.default.data);
|
|
1618
|
+
} else {
|
|
1619
|
+
gen.assign((0, codegen_12._)`${validateName}.errors`, null);
|
|
1620
|
+
gen.return(true);
|
|
1621
|
+
}
|
|
1609
1622
|
}
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1623
|
+
boolSchema.topBoolOrEmptySchema = topBoolOrEmptySchema;
|
|
1624
|
+
function boolOrEmptySchema(it, valid) {
|
|
1625
|
+
const { gen, schema } = it;
|
|
1626
|
+
if (schema === false) {
|
|
1627
|
+
gen.var(valid, false);
|
|
1628
|
+
falseSchemaError(it);
|
|
1629
|
+
} else {
|
|
1630
|
+
gen.var(valid, true);
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
boolSchema.boolOrEmptySchema = boolOrEmptySchema;
|
|
1634
|
+
function falseSchemaError(it, overrideAllErrors) {
|
|
1635
|
+
const { gen, data } = it;
|
|
1636
|
+
const cxt = {
|
|
1637
|
+
gen,
|
|
1638
|
+
keyword: "false schema",
|
|
1639
|
+
data,
|
|
1640
|
+
schema: false,
|
|
1641
|
+
schemaCode: false,
|
|
1642
|
+
schemaValue: false,
|
|
1643
|
+
params: {},
|
|
1644
|
+
it
|
|
1645
|
+
};
|
|
1646
|
+
(0, errors_12.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
1619
1647
|
}
|
|
1620
|
-
|
|
1621
|
-
boolSchema.boolOrEmptySchema = boolOrEmptySchema;
|
|
1622
|
-
function falseSchemaError(it, overrideAllErrors) {
|
|
1623
|
-
const { gen, data } = it;
|
|
1624
|
-
const cxt = {
|
|
1625
|
-
gen,
|
|
1626
|
-
keyword: "false schema",
|
|
1627
|
-
data,
|
|
1628
|
-
schema: false,
|
|
1629
|
-
schemaCode: false,
|
|
1630
|
-
schemaValue: false,
|
|
1631
|
-
params: {},
|
|
1632
|
-
it
|
|
1633
|
-
};
|
|
1634
|
-
(0, errors_1$3.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
1648
|
+
return boolSchema;
|
|
1635
1649
|
}
|
|
1636
1650
|
var dataType = {};
|
|
1637
1651
|
var rules = {};
|
|
@@ -1660,29 +1674,36 @@ function getRules() {
|
|
|
1660
1674
|
}
|
|
1661
1675
|
rules.getRules = getRules;
|
|
1662
1676
|
var applicability = {};
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
}
|
|
1669
|
-
applicability.schemaHasRulesForType =
|
|
1670
|
-
function
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
+
var hasRequiredApplicability;
|
|
1678
|
+
function requireApplicability() {
|
|
1679
|
+
if (hasRequiredApplicability)
|
|
1680
|
+
return applicability;
|
|
1681
|
+
hasRequiredApplicability = 1;
|
|
1682
|
+
Object.defineProperty(applicability, "__esModule", { value: true });
|
|
1683
|
+
applicability.shouldUseRule = applicability.shouldUseGroup = applicability.schemaHasRulesForType = void 0;
|
|
1684
|
+
function schemaHasRulesForType({ schema, self }, type2) {
|
|
1685
|
+
const group = self.RULES.types[type2];
|
|
1686
|
+
return group && group !== true && shouldUseGroup(schema, group);
|
|
1687
|
+
}
|
|
1688
|
+
applicability.schemaHasRulesForType = schemaHasRulesForType;
|
|
1689
|
+
function shouldUseGroup(schema, group) {
|
|
1690
|
+
return group.rules.some((rule) => shouldUseRule(schema, rule));
|
|
1691
|
+
}
|
|
1692
|
+
applicability.shouldUseGroup = shouldUseGroup;
|
|
1693
|
+
function shouldUseRule(schema, rule) {
|
|
1694
|
+
var _a;
|
|
1695
|
+
return schema[rule.keyword] !== void 0 || ((_a = rule.definition.implements) === null || _a === void 0 ? void 0 : _a.some((kwd) => schema[kwd] !== void 0));
|
|
1696
|
+
}
|
|
1697
|
+
applicability.shouldUseRule = shouldUseRule;
|
|
1698
|
+
return applicability;
|
|
1677
1699
|
}
|
|
1678
|
-
applicability.shouldUseRule = shouldUseRule;
|
|
1679
1700
|
Object.defineProperty(dataType, "__esModule", { value: true });
|
|
1680
1701
|
dataType.reportTypeError = dataType.checkDataTypes = dataType.checkDataType = dataType.coerceAndCheckDataType = dataType.getJSONTypes = dataType.getSchemaTypes = dataType.DataType = void 0;
|
|
1681
1702
|
const rules_1 = rules;
|
|
1682
|
-
const applicability_1
|
|
1683
|
-
const errors_1
|
|
1684
|
-
const codegen_1$
|
|
1685
|
-
const util_1$
|
|
1703
|
+
const applicability_1 = requireApplicability();
|
|
1704
|
+
const errors_1 = errors;
|
|
1705
|
+
const codegen_1$r = codegen;
|
|
1706
|
+
const util_1$q = util;
|
|
1686
1707
|
var DataType;
|
|
1687
1708
|
(function(DataType2) {
|
|
1688
1709
|
DataType2[DataType2["Correct"] = 0] = "Correct";
|
|
@@ -1714,7 +1735,7 @@ dataType.getJSONTypes = getJSONTypes;
|
|
|
1714
1735
|
function coerceAndCheckDataType(it, types2) {
|
|
1715
1736
|
const { gen, data, opts } = it;
|
|
1716
1737
|
const coerceTo = coerceToTypes(types2, opts.coerceTypes);
|
|
1717
|
-
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1
|
|
1738
|
+
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1.schemaHasRulesForType)(it, types2[0]));
|
|
1718
1739
|
if (checkTypes) {
|
|
1719
1740
|
const wrongType = checkDataTypes(types2, data, opts.strictNumbers, DataType.Wrong);
|
|
1720
1741
|
gen.if(wrongType, () => {
|
|
@@ -1733,12 +1754,12 @@ function coerceToTypes(types2, coerceTypes) {
|
|
|
1733
1754
|
}
|
|
1734
1755
|
function coerceData(it, types2, coerceTo) {
|
|
1735
1756
|
const { gen, data, opts } = it;
|
|
1736
|
-
const dataType2 = gen.let("dataType", (0, codegen_1$
|
|
1737
|
-
const coerced = gen.let("coerced", (0, codegen_1$
|
|
1757
|
+
const dataType2 = gen.let("dataType", (0, codegen_1$r._)`typeof ${data}`);
|
|
1758
|
+
const coerced = gen.let("coerced", (0, codegen_1$r._)`undefined`);
|
|
1738
1759
|
if (opts.coerceTypes === "array") {
|
|
1739
|
-
gen.if((0, codegen_1$
|
|
1760
|
+
gen.if((0, codegen_1$r._)`${dataType2} == 'object' && Array.isArray(${data}) && ${data}.length == 1`, () => gen.assign(data, (0, codegen_1$r._)`${data}[0]`).assign(dataType2, (0, codegen_1$r._)`typeof ${data}`).if(checkDataTypes(types2, data, opts.strictNumbers), () => gen.assign(coerced, data)));
|
|
1740
1761
|
}
|
|
1741
|
-
gen.if((0, codegen_1$
|
|
1762
|
+
gen.if((0, codegen_1$r._)`${coerced} !== undefined`);
|
|
1742
1763
|
for (const t of coerceTo) {
|
|
1743
1764
|
if (COERCIBLE.has(t) || t === "array" && opts.coerceTypes === "array") {
|
|
1744
1765
|
coerceSpecificType(t);
|
|
@@ -1747,63 +1768,63 @@ function coerceData(it, types2, coerceTo) {
|
|
|
1747
1768
|
gen.else();
|
|
1748
1769
|
reportTypeError(it);
|
|
1749
1770
|
gen.endIf();
|
|
1750
|
-
gen.if((0, codegen_1$
|
|
1771
|
+
gen.if((0, codegen_1$r._)`${coerced} !== undefined`, () => {
|
|
1751
1772
|
gen.assign(data, coerced);
|
|
1752
1773
|
assignParentData(it, coerced);
|
|
1753
1774
|
});
|
|
1754
1775
|
function coerceSpecificType(t) {
|
|
1755
1776
|
switch (t) {
|
|
1756
1777
|
case "string":
|
|
1757
|
-
gen.elseIf((0, codegen_1$
|
|
1778
|
+
gen.elseIf((0, codegen_1$r._)`${dataType2} == "number" || ${dataType2} == "boolean"`).assign(coerced, (0, codegen_1$r._)`"" + ${data}`).elseIf((0, codegen_1$r._)`${data} === null`).assign(coerced, (0, codegen_1$r._)`""`);
|
|
1758
1779
|
return;
|
|
1759
1780
|
case "number":
|
|
1760
|
-
gen.elseIf((0, codegen_1$
|
|
1761
|
-
|| (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$
|
|
1781
|
+
gen.elseIf((0, codegen_1$r._)`${dataType2} == "boolean" || ${data} === null
|
|
1782
|
+
|| (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$r._)`+${data}`);
|
|
1762
1783
|
return;
|
|
1763
1784
|
case "integer":
|
|
1764
|
-
gen.elseIf((0, codegen_1$
|
|
1765
|
-
|| (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$
|
|
1785
|
+
gen.elseIf((0, codegen_1$r._)`${dataType2} === "boolean" || ${data} === null
|
|
1786
|
+
|| (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$r._)`+${data}`);
|
|
1766
1787
|
return;
|
|
1767
1788
|
case "boolean":
|
|
1768
|
-
gen.elseIf((0, codegen_1$
|
|
1789
|
+
gen.elseIf((0, codegen_1$r._)`${data} === "false" || ${data} === 0 || ${data} === null`).assign(coerced, false).elseIf((0, codegen_1$r._)`${data} === "true" || ${data} === 1`).assign(coerced, true);
|
|
1769
1790
|
return;
|
|
1770
1791
|
case "null":
|
|
1771
|
-
gen.elseIf((0, codegen_1$
|
|
1792
|
+
gen.elseIf((0, codegen_1$r._)`${data} === "" || ${data} === 0 || ${data} === false`);
|
|
1772
1793
|
gen.assign(coerced, null);
|
|
1773
1794
|
return;
|
|
1774
1795
|
case "array":
|
|
1775
|
-
gen.elseIf((0, codegen_1$
|
|
1776
|
-
|| ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$
|
|
1796
|
+
gen.elseIf((0, codegen_1$r._)`${dataType2} === "string" || ${dataType2} === "number"
|
|
1797
|
+
|| ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$r._)`[${data}]`);
|
|
1777
1798
|
}
|
|
1778
1799
|
}
|
|
1779
1800
|
}
|
|
1780
1801
|
function assignParentData({ gen, parentData, parentDataProperty }, expr) {
|
|
1781
|
-
gen.if((0, codegen_1$
|
|
1802
|
+
gen.if((0, codegen_1$r._)`${parentData} !== undefined`, () => gen.assign((0, codegen_1$r._)`${parentData}[${parentDataProperty}]`, expr));
|
|
1782
1803
|
}
|
|
1783
1804
|
function checkDataType(dataType2, data, strictNums, correct = DataType.Correct) {
|
|
1784
|
-
const EQ = correct === DataType.Correct ? codegen_1$
|
|
1805
|
+
const EQ = correct === DataType.Correct ? codegen_1$r.operators.EQ : codegen_1$r.operators.NEQ;
|
|
1785
1806
|
let cond;
|
|
1786
1807
|
switch (dataType2) {
|
|
1787
1808
|
case "null":
|
|
1788
|
-
return (0, codegen_1$
|
|
1809
|
+
return (0, codegen_1$r._)`${data} ${EQ} null`;
|
|
1789
1810
|
case "array":
|
|
1790
|
-
cond = (0, codegen_1$
|
|
1811
|
+
cond = (0, codegen_1$r._)`Array.isArray(${data})`;
|
|
1791
1812
|
break;
|
|
1792
1813
|
case "object":
|
|
1793
|
-
cond = (0, codegen_1$
|
|
1814
|
+
cond = (0, codegen_1$r._)`${data} && typeof ${data} == "object" && !Array.isArray(${data})`;
|
|
1794
1815
|
break;
|
|
1795
1816
|
case "integer":
|
|
1796
|
-
cond = numCond((0, codegen_1$
|
|
1817
|
+
cond = numCond((0, codegen_1$r._)`!(${data} % 1) && !isNaN(${data})`);
|
|
1797
1818
|
break;
|
|
1798
1819
|
case "number":
|
|
1799
1820
|
cond = numCond();
|
|
1800
1821
|
break;
|
|
1801
1822
|
default:
|
|
1802
|
-
return (0, codegen_1$
|
|
1823
|
+
return (0, codegen_1$r._)`typeof ${data} ${EQ} ${dataType2}`;
|
|
1803
1824
|
}
|
|
1804
|
-
return correct === DataType.Correct ? cond : (0, codegen_1$
|
|
1805
|
-
function numCond(_cond = codegen_1$
|
|
1806
|
-
return (0, codegen_1$
|
|
1825
|
+
return correct === DataType.Correct ? cond : (0, codegen_1$r.not)(cond);
|
|
1826
|
+
function numCond(_cond = codegen_1$r.nil) {
|
|
1827
|
+
return (0, codegen_1$r.and)((0, codegen_1$r._)`typeof ${data} == "number"`, _cond, strictNums ? (0, codegen_1$r._)`isFinite(${data})` : codegen_1$r.nil);
|
|
1807
1828
|
}
|
|
1808
1829
|
}
|
|
1809
1830
|
dataType.checkDataType = checkDataType;
|
|
@@ -1812,35 +1833,35 @@ function checkDataTypes(dataTypes, data, strictNums, correct) {
|
|
|
1812
1833
|
return checkDataType(dataTypes[0], data, strictNums, correct);
|
|
1813
1834
|
}
|
|
1814
1835
|
let cond;
|
|
1815
|
-
const types2 = (0, util_1$
|
|
1836
|
+
const types2 = (0, util_1$q.toHash)(dataTypes);
|
|
1816
1837
|
if (types2.array && types2.object) {
|
|
1817
|
-
const notObj = (0, codegen_1$
|
|
1818
|
-
cond = types2.null ? notObj : (0, codegen_1$
|
|
1838
|
+
const notObj = (0, codegen_1$r._)`typeof ${data} != "object"`;
|
|
1839
|
+
cond = types2.null ? notObj : (0, codegen_1$r._)`!${data} || ${notObj}`;
|
|
1819
1840
|
delete types2.null;
|
|
1820
1841
|
delete types2.array;
|
|
1821
1842
|
delete types2.object;
|
|
1822
1843
|
} else {
|
|
1823
|
-
cond = codegen_1$
|
|
1844
|
+
cond = codegen_1$r.nil;
|
|
1824
1845
|
}
|
|
1825
1846
|
if (types2.number)
|
|
1826
1847
|
delete types2.integer;
|
|
1827
1848
|
for (const t in types2)
|
|
1828
|
-
cond = (0, codegen_1$
|
|
1849
|
+
cond = (0, codegen_1$r.and)(cond, checkDataType(t, data, strictNums, correct));
|
|
1829
1850
|
return cond;
|
|
1830
1851
|
}
|
|
1831
1852
|
dataType.checkDataTypes = checkDataTypes;
|
|
1832
1853
|
const typeError = {
|
|
1833
1854
|
message: ({ schema }) => `must be ${schema}`,
|
|
1834
|
-
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$
|
|
1855
|
+
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$r._)`{type: ${schema}}` : (0, codegen_1$r._)`{type: ${schemaValue}}`
|
|
1835
1856
|
};
|
|
1836
1857
|
function reportTypeError(it) {
|
|
1837
1858
|
const cxt = getTypeErrorContext(it);
|
|
1838
|
-
(0, errors_1
|
|
1859
|
+
(0, errors_1.reportError)(cxt, typeError);
|
|
1839
1860
|
}
|
|
1840
1861
|
dataType.reportTypeError = reportTypeError;
|
|
1841
1862
|
function getTypeErrorContext(it) {
|
|
1842
1863
|
const { gen, data, schema } = it;
|
|
1843
|
-
const schemaCode = (0, util_1$
|
|
1864
|
+
const schemaCode = (0, util_1$q.schemaRefOrVal)(it, schema, "type");
|
|
1844
1865
|
return {
|
|
1845
1866
|
gen,
|
|
1846
1867
|
keyword: "type",
|
|
@@ -1854,352 +1875,380 @@ function getTypeErrorContext(it) {
|
|
|
1854
1875
|
};
|
|
1855
1876
|
}
|
|
1856
1877
|
var defaults = {};
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
return;
|
|
1876
|
-
const childData = (0, codegen_1$v._)`${data}${(0, codegen_1$v.getProperty)(prop)}`;
|
|
1877
|
-
if (compositeRule) {
|
|
1878
|
-
(0, util_1$t.checkStrictMode)(it, `default is ignored for: ${childData}`);
|
|
1879
|
-
return;
|
|
1878
|
+
var hasRequiredDefaults;
|
|
1879
|
+
function requireDefaults() {
|
|
1880
|
+
if (hasRequiredDefaults)
|
|
1881
|
+
return defaults;
|
|
1882
|
+
hasRequiredDefaults = 1;
|
|
1883
|
+
Object.defineProperty(defaults, "__esModule", { value: true });
|
|
1884
|
+
defaults.assignDefaults = void 0;
|
|
1885
|
+
const codegen_12 = codegen;
|
|
1886
|
+
const util_12 = util;
|
|
1887
|
+
function assignDefaults(it, ty) {
|
|
1888
|
+
const { properties: properties2, items: items2 } = it.schema;
|
|
1889
|
+
if (ty === "object" && properties2) {
|
|
1890
|
+
for (const key in properties2) {
|
|
1891
|
+
assignDefault(it, key, properties2[key].default);
|
|
1892
|
+
}
|
|
1893
|
+
} else if (ty === "array" && Array.isArray(items2)) {
|
|
1894
|
+
items2.forEach((sch, i) => assignDefault(it, i, sch.default));
|
|
1895
|
+
}
|
|
1880
1896
|
}
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1897
|
+
defaults.assignDefaults = assignDefaults;
|
|
1898
|
+
function assignDefault(it, prop, defaultValue) {
|
|
1899
|
+
const { gen, compositeRule, data, opts } = it;
|
|
1900
|
+
if (defaultValue === void 0)
|
|
1901
|
+
return;
|
|
1902
|
+
const childData = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)(prop)}`;
|
|
1903
|
+
if (compositeRule) {
|
|
1904
|
+
(0, util_12.checkStrictMode)(it, `default is ignored for: ${childData}`);
|
|
1905
|
+
return;
|
|
1906
|
+
}
|
|
1907
|
+
let condition = (0, codegen_12._)`${childData} === undefined`;
|
|
1908
|
+
if (opts.useDefaults === "empty") {
|
|
1909
|
+
condition = (0, codegen_12._)`${condition} || ${childData} === null || ${childData} === ""`;
|
|
1910
|
+
}
|
|
1911
|
+
gen.if(condition, (0, codegen_12._)`${childData} = ${(0, codegen_12.stringify)(defaultValue)}`);
|
|
1884
1912
|
}
|
|
1885
|
-
|
|
1913
|
+
return defaults;
|
|
1886
1914
|
}
|
|
1887
1915
|
var keyword = {};
|
|
1888
1916
|
var code = {};
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
const
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
}
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
}
|
|
1906
|
-
code.checkMissingProp = checkMissingProp;
|
|
1907
|
-
function reportMissingProp(cxt, missing) {
|
|
1908
|
-
cxt.setParams({ missingProperty: missing }, true);
|
|
1909
|
-
cxt.error();
|
|
1910
|
-
}
|
|
1911
|
-
code.reportMissingProp = reportMissingProp;
|
|
1912
|
-
function hasPropFunc(gen) {
|
|
1913
|
-
return gen.scopeValue("func", {
|
|
1914
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
1915
|
-
ref: Object.prototype.hasOwnProperty,
|
|
1916
|
-
code: (0, codegen_1$u._)`Object.prototype.hasOwnProperty`
|
|
1917
|
-
});
|
|
1918
|
-
}
|
|
1919
|
-
code.hasPropFunc = hasPropFunc;
|
|
1920
|
-
function isOwnProperty(gen, data, property) {
|
|
1921
|
-
return (0, codegen_1$u._)`${hasPropFunc(gen)}.call(${data}, ${property})`;
|
|
1922
|
-
}
|
|
1923
|
-
code.isOwnProperty = isOwnProperty;
|
|
1924
|
-
function propertyInData(gen, data, property, ownProperties) {
|
|
1925
|
-
const cond = (0, codegen_1$u._)`${data}${(0, codegen_1$u.getProperty)(property)} !== undefined`;
|
|
1926
|
-
return ownProperties ? (0, codegen_1$u._)`${cond} && ${isOwnProperty(gen, data, property)}` : cond;
|
|
1927
|
-
}
|
|
1928
|
-
code.propertyInData = propertyInData;
|
|
1929
|
-
function noPropertyInData(gen, data, property, ownProperties) {
|
|
1930
|
-
const cond = (0, codegen_1$u._)`${data}${(0, codegen_1$u.getProperty)(property)} === undefined`;
|
|
1931
|
-
return ownProperties ? (0, codegen_1$u.or)(cond, (0, codegen_1$u.not)(isOwnProperty(gen, data, property))) : cond;
|
|
1932
|
-
}
|
|
1933
|
-
code.noPropertyInData = noPropertyInData;
|
|
1934
|
-
function allSchemaProperties(schemaMap) {
|
|
1935
|
-
return schemaMap ? Object.keys(schemaMap).filter((p) => p !== "__proto__") : [];
|
|
1936
|
-
}
|
|
1937
|
-
code.allSchemaProperties = allSchemaProperties;
|
|
1938
|
-
function schemaProperties(it, schemaMap) {
|
|
1939
|
-
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$s.alwaysValidSchema)(it, schemaMap[p]));
|
|
1940
|
-
}
|
|
1941
|
-
code.schemaProperties = schemaProperties;
|
|
1942
|
-
function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context2, passSchema) {
|
|
1943
|
-
const dataAndSchema = passSchema ? (0, codegen_1$u._)`${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
|
|
1944
|
-
const valCxt = [
|
|
1945
|
-
[names_1$8.default.instancePath, (0, codegen_1$u.strConcat)(names_1$8.default.instancePath, errorPath)],
|
|
1946
|
-
[names_1$8.default.parentData, it.parentData],
|
|
1947
|
-
[names_1$8.default.parentDataProperty, it.parentDataProperty],
|
|
1948
|
-
[names_1$8.default.rootData, names_1$8.default.rootData]
|
|
1949
|
-
];
|
|
1950
|
-
if (it.opts.dynamicRef)
|
|
1951
|
-
valCxt.push([names_1$8.default.dynamicAnchors, names_1$8.default.dynamicAnchors]);
|
|
1952
|
-
const args = (0, codegen_1$u._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
|
|
1953
|
-
return context2 !== codegen_1$u.nil ? (0, codegen_1$u._)`${func}.call(${context2}, ${args})` : (0, codegen_1$u._)`${func}(${args})`;
|
|
1954
|
-
}
|
|
1955
|
-
code.callValidateCode = callValidateCode;
|
|
1956
|
-
const newRegExp = (0, codegen_1$u._)`new RegExp`;
|
|
1957
|
-
function usePattern({ gen, it: { opts } }, pattern2) {
|
|
1958
|
-
const u = opts.unicodeRegExp ? "u" : "";
|
|
1959
|
-
const { regExp } = opts.code;
|
|
1960
|
-
const rx = regExp(pattern2, u);
|
|
1961
|
-
return gen.scopeValue("pattern", {
|
|
1962
|
-
key: rx.toString(),
|
|
1963
|
-
ref: rx,
|
|
1964
|
-
code: (0, codegen_1$u._)`${regExp.code === "new RegExp" ? newRegExp : (0, util_2$1.useFunc)(gen, regExp)}(${pattern2}, ${u})`
|
|
1965
|
-
});
|
|
1966
|
-
}
|
|
1967
|
-
code.usePattern = usePattern;
|
|
1968
|
-
function validateArray(cxt) {
|
|
1969
|
-
const { gen, data, keyword: keyword2, it } = cxt;
|
|
1970
|
-
const valid = gen.name("valid");
|
|
1971
|
-
if (it.allErrors) {
|
|
1972
|
-
const validArr = gen.let("valid", true);
|
|
1973
|
-
validateItems(() => gen.assign(validArr, false));
|
|
1974
|
-
return validArr;
|
|
1975
|
-
}
|
|
1976
|
-
gen.var(valid, true);
|
|
1977
|
-
validateItems(() => gen.break());
|
|
1978
|
-
return valid;
|
|
1979
|
-
function validateItems(notValid) {
|
|
1980
|
-
const len = gen.const("len", (0, codegen_1$u._)`${data}.length`);
|
|
1981
|
-
gen.forRange("i", 0, len, (i) => {
|
|
1982
|
-
cxt.subschema({
|
|
1983
|
-
keyword: keyword2,
|
|
1984
|
-
dataProp: i,
|
|
1985
|
-
dataPropType: util_1$s.Type.Num
|
|
1986
|
-
}, valid);
|
|
1987
|
-
gen.if((0, codegen_1$u.not)(valid), notValid);
|
|
1917
|
+
var hasRequiredCode;
|
|
1918
|
+
function requireCode() {
|
|
1919
|
+
if (hasRequiredCode)
|
|
1920
|
+
return code;
|
|
1921
|
+
hasRequiredCode = 1;
|
|
1922
|
+
Object.defineProperty(code, "__esModule", { value: true });
|
|
1923
|
+
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;
|
|
1924
|
+
const codegen_12 = codegen;
|
|
1925
|
+
const util_12 = util;
|
|
1926
|
+
const names_12 = requireNames();
|
|
1927
|
+
const util_22 = util;
|
|
1928
|
+
function checkReportMissingProp(cxt, prop) {
|
|
1929
|
+
const { gen, data, it } = cxt;
|
|
1930
|
+
gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
|
|
1931
|
+
cxt.setParams({ missingProperty: (0, codegen_12._)`${prop}` }, true);
|
|
1932
|
+
cxt.error();
|
|
1988
1933
|
});
|
|
1989
1934
|
}
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
const { gen, schema, keyword: keyword2, it } = cxt;
|
|
1994
|
-
if (!Array.isArray(schema))
|
|
1995
|
-
throw new Error("ajv implementation error");
|
|
1996
|
-
const alwaysValid = schema.some((sch) => (0, util_1$s.alwaysValidSchema)(it, sch));
|
|
1997
|
-
if (alwaysValid && !it.opts.unevaluated)
|
|
1998
|
-
return;
|
|
1999
|
-
const valid = gen.let("valid", false);
|
|
2000
|
-
const schValid = gen.name("_valid");
|
|
2001
|
-
gen.block(() => schema.forEach((_sch, i) => {
|
|
2002
|
-
const schCxt = cxt.subschema({
|
|
2003
|
-
keyword: keyword2,
|
|
2004
|
-
schemaProp: i,
|
|
2005
|
-
compositeRule: true
|
|
2006
|
-
}, schValid);
|
|
2007
|
-
gen.assign(valid, (0, codegen_1$u._)`${valid} || ${schValid}`);
|
|
2008
|
-
const merged = cxt.mergeValidEvaluated(schCxt, schValid);
|
|
2009
|
-
if (!merged)
|
|
2010
|
-
gen.if((0, codegen_1$u.not)(valid));
|
|
2011
|
-
}));
|
|
2012
|
-
cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
|
|
2013
|
-
}
|
|
2014
|
-
code.validateUnion = validateUnion;
|
|
2015
|
-
Object.defineProperty(keyword, "__esModule", { value: true });
|
|
2016
|
-
keyword.validateKeywordUsage = keyword.validSchemaType = keyword.funcKeywordCode = keyword.macroKeywordCode = void 0;
|
|
2017
|
-
const codegen_1$t = codegen;
|
|
2018
|
-
const names_1$7 = names$1;
|
|
2019
|
-
const code_1$9 = code;
|
|
2020
|
-
const errors_1$1 = errors;
|
|
2021
|
-
function macroKeywordCode(cxt, def2) {
|
|
2022
|
-
const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
|
|
2023
|
-
const macroSchema = def2.macro.call(it.self, schema, parentSchema, it);
|
|
2024
|
-
const schemaRef = useKeyword(gen, keyword2, macroSchema);
|
|
2025
|
-
if (it.opts.validateSchema !== false)
|
|
2026
|
-
it.self.validateSchema(macroSchema, true);
|
|
2027
|
-
const valid = gen.name("valid");
|
|
2028
|
-
cxt.subschema({
|
|
2029
|
-
schema: macroSchema,
|
|
2030
|
-
schemaPath: codegen_1$t.nil,
|
|
2031
|
-
errSchemaPath: `${it.errSchemaPath}/${keyword2}`,
|
|
2032
|
-
topSchemaRef: schemaRef,
|
|
2033
|
-
compositeRule: true
|
|
2034
|
-
}, valid);
|
|
2035
|
-
cxt.pass(valid, () => cxt.error(true));
|
|
2036
|
-
}
|
|
2037
|
-
keyword.macroKeywordCode = macroKeywordCode;
|
|
2038
|
-
function funcKeywordCode(cxt, def2) {
|
|
2039
|
-
var _a;
|
|
2040
|
-
const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
|
|
2041
|
-
checkAsyncKeyword(it, def2);
|
|
2042
|
-
const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
|
|
2043
|
-
const validateRef = useKeyword(gen, keyword2, validate2);
|
|
2044
|
-
const valid = gen.let("valid");
|
|
2045
|
-
cxt.block$data(valid, validateKeyword);
|
|
2046
|
-
cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
|
|
2047
|
-
function validateKeyword() {
|
|
2048
|
-
if (def2.errors === false) {
|
|
2049
|
-
assignValid();
|
|
2050
|
-
if (def2.modifying)
|
|
2051
|
-
modifyData(cxt);
|
|
2052
|
-
reportErrs(() => cxt.error());
|
|
2053
|
-
} else {
|
|
2054
|
-
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
2055
|
-
if (def2.modifying)
|
|
2056
|
-
modifyData(cxt);
|
|
2057
|
-
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
2058
|
-
}
|
|
2059
|
-
}
|
|
2060
|
-
function validateAsync() {
|
|
2061
|
-
const ruleErrs = gen.let("ruleErrs", null);
|
|
2062
|
-
gen.try(() => assignValid((0, codegen_1$t._)`await `), (e) => gen.assign(valid, false).if((0, codegen_1$t._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1$t._)`${e}.errors`), () => gen.throw(e)));
|
|
2063
|
-
return ruleErrs;
|
|
1935
|
+
code.checkReportMissingProp = checkReportMissingProp;
|
|
1936
|
+
function checkMissingProp({ gen, data, it: { opts } }, properties2, missing) {
|
|
1937
|
+
return (0, codegen_12.or)(...properties2.map((prop) => (0, codegen_12.and)(noPropertyInData(gen, data, prop, opts.ownProperties), (0, codegen_12._)`${missing} = ${prop}`)));
|
|
2064
1938
|
}
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
return validateErrs;
|
|
1939
|
+
code.checkMissingProp = checkMissingProp;
|
|
1940
|
+
function reportMissingProp(cxt, missing) {
|
|
1941
|
+
cxt.setParams({ missingProperty: missing }, true);
|
|
1942
|
+
cxt.error();
|
|
2070
1943
|
}
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
1944
|
+
code.reportMissingProp = reportMissingProp;
|
|
1945
|
+
function hasPropFunc(gen) {
|
|
1946
|
+
return gen.scopeValue("func", {
|
|
1947
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
1948
|
+
ref: Object.prototype.hasOwnProperty,
|
|
1949
|
+
code: (0, codegen_12._)`Object.prototype.hasOwnProperty`
|
|
1950
|
+
});
|
|
2075
1951
|
}
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
1952
|
+
code.hasPropFunc = hasPropFunc;
|
|
1953
|
+
function isOwnProperty(gen, data, property) {
|
|
1954
|
+
return (0, codegen_12._)`${hasPropFunc(gen)}.call(${data}, ${property})`;
|
|
1955
|
+
}
|
|
1956
|
+
code.isOwnProperty = isOwnProperty;
|
|
1957
|
+
function propertyInData(gen, data, property, ownProperties) {
|
|
1958
|
+
const cond = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)(property)} !== undefined`;
|
|
1959
|
+
return ownProperties ? (0, codegen_12._)`${cond} && ${isOwnProperty(gen, data, property)}` : cond;
|
|
1960
|
+
}
|
|
1961
|
+
code.propertyInData = propertyInData;
|
|
1962
|
+
function noPropertyInData(gen, data, property, ownProperties) {
|
|
1963
|
+
const cond = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)(property)} === undefined`;
|
|
1964
|
+
return ownProperties ? (0, codegen_12.or)(cond, (0, codegen_12.not)(isOwnProperty(gen, data, property))) : cond;
|
|
1965
|
+
}
|
|
1966
|
+
code.noPropertyInData = noPropertyInData;
|
|
1967
|
+
function allSchemaProperties(schemaMap) {
|
|
1968
|
+
return schemaMap ? Object.keys(schemaMap).filter((p) => p !== "__proto__") : [];
|
|
1969
|
+
}
|
|
1970
|
+
code.allSchemaProperties = allSchemaProperties;
|
|
1971
|
+
function schemaProperties(it, schemaMap) {
|
|
1972
|
+
return allSchemaProperties(schemaMap).filter((p) => !(0, util_12.alwaysValidSchema)(it, schemaMap[p]));
|
|
1973
|
+
}
|
|
1974
|
+
code.schemaProperties = schemaProperties;
|
|
1975
|
+
function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context2, passSchema) {
|
|
1976
|
+
const dataAndSchema = passSchema ? (0, codegen_12._)`${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
|
|
1977
|
+
const valCxt = [
|
|
1978
|
+
[names_12.default.instancePath, (0, codegen_12.strConcat)(names_12.default.instancePath, errorPath)],
|
|
1979
|
+
[names_12.default.parentData, it.parentData],
|
|
1980
|
+
[names_12.default.parentDataProperty, it.parentDataProperty],
|
|
1981
|
+
[names_12.default.rootData, names_12.default.rootData]
|
|
1982
|
+
];
|
|
1983
|
+
if (it.opts.dynamicRef)
|
|
1984
|
+
valCxt.push([names_12.default.dynamicAnchors, names_12.default.dynamicAnchors]);
|
|
1985
|
+
const args = (0, codegen_12._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
|
|
1986
|
+
return context2 !== codegen_12.nil ? (0, codegen_12._)`${func}.call(${context2}, ${args})` : (0, codegen_12._)`${func}(${args})`;
|
|
1987
|
+
}
|
|
1988
|
+
code.callValidateCode = callValidateCode;
|
|
1989
|
+
const newRegExp = (0, codegen_12._)`new RegExp`;
|
|
1990
|
+
function usePattern({ gen, it: { opts } }, pattern2) {
|
|
1991
|
+
const u = opts.unicodeRegExp ? "u" : "";
|
|
1992
|
+
const { regExp } = opts.code;
|
|
1993
|
+
const rx = regExp(pattern2, u);
|
|
1994
|
+
return gen.scopeValue("pattern", {
|
|
1995
|
+
key: rx.toString(),
|
|
1996
|
+
ref: rx,
|
|
1997
|
+
code: (0, codegen_12._)`${regExp.code === "new RegExp" ? newRegExp : (0, util_22.useFunc)(gen, regExp)}(${pattern2}, ${u})`
|
|
1998
|
+
});
|
|
2079
1999
|
}
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
gen.if((0, codegen_1$t._)`Array.isArray(${errs})`, () => {
|
|
2089
|
-
gen.assign(names_1$7.default.vErrors, (0, codegen_1$t._)`${names_1$7.default.vErrors} === null ? ${errs} : ${names_1$7.default.vErrors}.concat(${errs})`).assign(names_1$7.default.errors, (0, codegen_1$t._)`${names_1$7.default.vErrors}.length`);
|
|
2090
|
-
(0, errors_1$1.extendErrors)(cxt);
|
|
2091
|
-
}, () => cxt.error());
|
|
2092
|
-
}
|
|
2093
|
-
function checkAsyncKeyword({ schemaEnv }, def2) {
|
|
2094
|
-
if (def2.async && !schemaEnv.$async)
|
|
2095
|
-
throw new Error("async keyword in sync schema");
|
|
2096
|
-
}
|
|
2097
|
-
function useKeyword(gen, keyword2, result) {
|
|
2098
|
-
if (result === void 0)
|
|
2099
|
-
throw new Error(`keyword "${keyword2}" failed to compile`);
|
|
2100
|
-
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_1$t.stringify)(result) });
|
|
2101
|
-
}
|
|
2102
|
-
function validSchemaType(schema, schemaType, allowUndefined = false) {
|
|
2103
|
-
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");
|
|
2104
|
-
}
|
|
2105
|
-
keyword.validSchemaType = validSchemaType;
|
|
2106
|
-
function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def2, keyword2) {
|
|
2107
|
-
if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
|
|
2108
|
-
throw new Error("ajv implementation error");
|
|
2109
|
-
}
|
|
2110
|
-
const deps = def2.dependencies;
|
|
2111
|
-
if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
|
|
2112
|
-
throw new Error(`parent schema must have dependencies of ${keyword2}: ${deps.join(",")}`);
|
|
2113
|
-
}
|
|
2114
|
-
if (def2.validateSchema) {
|
|
2115
|
-
const valid = def2.validateSchema(schema[keyword2]);
|
|
2116
|
-
if (!valid) {
|
|
2117
|
-
const msg = `keyword "${keyword2}" value is invalid at path "${errSchemaPath}": ` + self.errorsText(def2.validateSchema.errors);
|
|
2118
|
-
if (opts.validateSchema === "log")
|
|
2119
|
-
self.logger.error(msg);
|
|
2120
|
-
else
|
|
2121
|
-
throw new Error(msg);
|
|
2000
|
+
code.usePattern = usePattern;
|
|
2001
|
+
function validateArray(cxt) {
|
|
2002
|
+
const { gen, data, keyword: keyword2, it } = cxt;
|
|
2003
|
+
const valid = gen.name("valid");
|
|
2004
|
+
if (it.allErrors) {
|
|
2005
|
+
const validArr = gen.let("valid", true);
|
|
2006
|
+
validateItems(() => gen.assign(validArr, false));
|
|
2007
|
+
return validArr;
|
|
2122
2008
|
}
|
|
2009
|
+
gen.var(valid, true);
|
|
2010
|
+
validateItems(() => gen.break());
|
|
2011
|
+
return valid;
|
|
2012
|
+
function validateItems(notValid) {
|
|
2013
|
+
const len = gen.const("len", (0, codegen_12._)`${data}.length`);
|
|
2014
|
+
gen.forRange("i", 0, len, (i) => {
|
|
2015
|
+
cxt.subschema({
|
|
2016
|
+
keyword: keyword2,
|
|
2017
|
+
dataProp: i,
|
|
2018
|
+
dataPropType: util_12.Type.Num
|
|
2019
|
+
}, valid);
|
|
2020
|
+
gen.if((0, codegen_12.not)(valid), notValid);
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
code.validateArray = validateArray;
|
|
2025
|
+
function validateUnion(cxt) {
|
|
2026
|
+
const { gen, schema, keyword: keyword2, it } = cxt;
|
|
2027
|
+
if (!Array.isArray(schema))
|
|
2028
|
+
throw new Error("ajv implementation error");
|
|
2029
|
+
const alwaysValid = schema.some((sch) => (0, util_12.alwaysValidSchema)(it, sch));
|
|
2030
|
+
if (alwaysValid && !it.opts.unevaluated)
|
|
2031
|
+
return;
|
|
2032
|
+
const valid = gen.let("valid", false);
|
|
2033
|
+
const schValid = gen.name("_valid");
|
|
2034
|
+
gen.block(() => schema.forEach((_sch, i) => {
|
|
2035
|
+
const schCxt = cxt.subschema({
|
|
2036
|
+
keyword: keyword2,
|
|
2037
|
+
schemaProp: i,
|
|
2038
|
+
compositeRule: true
|
|
2039
|
+
}, schValid);
|
|
2040
|
+
gen.assign(valid, (0, codegen_12._)`${valid} || ${schValid}`);
|
|
2041
|
+
const merged = cxt.mergeValidEvaluated(schCxt, schValid);
|
|
2042
|
+
if (!merged)
|
|
2043
|
+
gen.if((0, codegen_12.not)(valid));
|
|
2044
|
+
}));
|
|
2045
|
+
cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
|
|
2123
2046
|
}
|
|
2047
|
+
code.validateUnion = validateUnion;
|
|
2048
|
+
return code;
|
|
2124
2049
|
}
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2050
|
+
var hasRequiredKeyword;
|
|
2051
|
+
function requireKeyword() {
|
|
2052
|
+
if (hasRequiredKeyword)
|
|
2053
|
+
return keyword;
|
|
2054
|
+
hasRequiredKeyword = 1;
|
|
2055
|
+
Object.defineProperty(keyword, "__esModule", { value: true });
|
|
2056
|
+
keyword.validateKeywordUsage = keyword.validSchemaType = keyword.funcKeywordCode = keyword.macroKeywordCode = void 0;
|
|
2057
|
+
const codegen_12 = codegen;
|
|
2058
|
+
const names_12 = requireNames();
|
|
2059
|
+
const code_12 = requireCode();
|
|
2060
|
+
const errors_12 = errors;
|
|
2061
|
+
function macroKeywordCode(cxt, def2) {
|
|
2062
|
+
const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
|
|
2063
|
+
const macroSchema = def2.macro.call(it.self, schema, parentSchema, it);
|
|
2064
|
+
const schemaRef = useKeyword(gen, keyword2, macroSchema);
|
|
2065
|
+
if (it.opts.validateSchema !== false)
|
|
2066
|
+
it.self.validateSchema(macroSchema, true);
|
|
2067
|
+
const valid = gen.name("valid");
|
|
2068
|
+
cxt.subschema({
|
|
2069
|
+
schema: macroSchema,
|
|
2070
|
+
schemaPath: codegen_12.nil,
|
|
2071
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`,
|
|
2072
|
+
topSchemaRef: schemaRef,
|
|
2073
|
+
compositeRule: true
|
|
2074
|
+
}, valid);
|
|
2075
|
+
cxt.pass(valid, () => cxt.error(true));
|
|
2146
2076
|
}
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2077
|
+
keyword.macroKeywordCode = macroKeywordCode;
|
|
2078
|
+
function funcKeywordCode(cxt, def2) {
|
|
2079
|
+
var _a;
|
|
2080
|
+
const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
|
|
2081
|
+
checkAsyncKeyword(it, def2);
|
|
2082
|
+
const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
|
|
2083
|
+
const validateRef = useKeyword(gen, keyword2, validate2);
|
|
2084
|
+
const valid = gen.let("valid");
|
|
2085
|
+
cxt.block$data(valid, validateKeyword);
|
|
2086
|
+
cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
|
|
2087
|
+
function validateKeyword() {
|
|
2088
|
+
if (def2.errors === false) {
|
|
2089
|
+
assignValid();
|
|
2090
|
+
if (def2.modifying)
|
|
2091
|
+
modifyData(cxt);
|
|
2092
|
+
reportErrs(() => cxt.error());
|
|
2093
|
+
} else {
|
|
2094
|
+
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
2095
|
+
if (def2.modifying)
|
|
2096
|
+
modifyData(cxt);
|
|
2097
|
+
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
function validateAsync() {
|
|
2101
|
+
const ruleErrs = gen.let("ruleErrs", null);
|
|
2102
|
+
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)));
|
|
2103
|
+
return ruleErrs;
|
|
2104
|
+
}
|
|
2105
|
+
function validateSync() {
|
|
2106
|
+
const validateErrs = (0, codegen_12._)`${validateRef}.errors`;
|
|
2107
|
+
gen.assign(validateErrs, null);
|
|
2108
|
+
assignValid(codegen_12.nil);
|
|
2109
|
+
return validateErrs;
|
|
2110
|
+
}
|
|
2111
|
+
function assignValid(_await = def2.async ? (0, codegen_12._)`await ` : codegen_12.nil) {
|
|
2112
|
+
const passCxt = it.opts.passContext ? names_12.default.this : names_12.default.self;
|
|
2113
|
+
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
2114
|
+
gen.assign(valid, (0, codegen_12._)`${_await}${(0, code_12.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
2115
|
+
}
|
|
2116
|
+
function reportErrs(errors2) {
|
|
2117
|
+
var _a2;
|
|
2118
|
+
gen.if((0, codegen_12.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
|
|
2150
2119
|
}
|
|
2151
|
-
return {
|
|
2152
|
-
schema,
|
|
2153
|
-
schemaPath,
|
|
2154
|
-
topSchemaRef,
|
|
2155
|
-
errSchemaPath
|
|
2156
|
-
};
|
|
2157
2120
|
}
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
}
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2121
|
+
keyword.funcKeywordCode = funcKeywordCode;
|
|
2122
|
+
function modifyData(cxt) {
|
|
2123
|
+
const { gen, data, it } = cxt;
|
|
2124
|
+
gen.if(it.parentData, () => gen.assign(data, (0, codegen_12._)`${it.parentData}[${it.parentDataProperty}]`));
|
|
2125
|
+
}
|
|
2126
|
+
function addErrs(cxt, errs) {
|
|
2127
|
+
const { gen } = cxt;
|
|
2128
|
+
gen.if((0, codegen_12._)`Array.isArray(${errs})`, () => {
|
|
2129
|
+
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`);
|
|
2130
|
+
(0, errors_12.extendErrors)(cxt);
|
|
2131
|
+
}, () => cxt.error());
|
|
2132
|
+
}
|
|
2133
|
+
function checkAsyncKeyword({ schemaEnv }, def2) {
|
|
2134
|
+
if (def2.async && !schemaEnv.$async)
|
|
2135
|
+
throw new Error("async keyword in sync schema");
|
|
2136
|
+
}
|
|
2137
|
+
function useKeyword(gen, keyword2, result) {
|
|
2138
|
+
if (result === void 0)
|
|
2139
|
+
throw new Error(`keyword "${keyword2}" failed to compile`);
|
|
2140
|
+
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_12.stringify)(result) });
|
|
2141
|
+
}
|
|
2142
|
+
function validSchemaType(schema, schemaType, allowUndefined = false) {
|
|
2143
|
+
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");
|
|
2144
|
+
}
|
|
2145
|
+
keyword.validSchemaType = validSchemaType;
|
|
2146
|
+
function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def2, keyword2) {
|
|
2147
|
+
if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
|
|
2148
|
+
throw new Error("ajv implementation error");
|
|
2149
|
+
}
|
|
2150
|
+
const deps = def2.dependencies;
|
|
2151
|
+
if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
|
|
2152
|
+
throw new Error(`parent schema must have dependencies of ${keyword2}: ${deps.join(",")}`);
|
|
2153
|
+
}
|
|
2154
|
+
if (def2.validateSchema) {
|
|
2155
|
+
const valid = def2.validateSchema(schema[keyword2]);
|
|
2156
|
+
if (!valid) {
|
|
2157
|
+
const msg = `keyword "${keyword2}" value is invalid at path "${errSchemaPath}": ` + self.errorsText(def2.validateSchema.errors);
|
|
2158
|
+
if (opts.validateSchema === "log")
|
|
2159
|
+
self.logger.error(msg);
|
|
2160
|
+
else
|
|
2161
|
+
throw new Error(msg);
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2189
2164
|
}
|
|
2165
|
+
keyword.validateKeywordUsage = validateKeywordUsage;
|
|
2166
|
+
return keyword;
|
|
2190
2167
|
}
|
|
2191
|
-
subschema
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2168
|
+
var subschema = {};
|
|
2169
|
+
var hasRequiredSubschema;
|
|
2170
|
+
function requireSubschema() {
|
|
2171
|
+
if (hasRequiredSubschema)
|
|
2172
|
+
return subschema;
|
|
2173
|
+
hasRequiredSubschema = 1;
|
|
2174
|
+
Object.defineProperty(subschema, "__esModule", { value: true });
|
|
2175
|
+
subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
|
|
2176
|
+
const codegen_12 = codegen;
|
|
2177
|
+
const util_12 = util;
|
|
2178
|
+
function getSubschema(it, { keyword: keyword2, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
|
|
2179
|
+
if (keyword2 !== void 0 && schema !== void 0) {
|
|
2180
|
+
throw new Error('both "keyword" and "schema" passed, only one allowed');
|
|
2181
|
+
}
|
|
2182
|
+
if (keyword2 !== void 0) {
|
|
2183
|
+
const sch = it.schema[keyword2];
|
|
2184
|
+
return schemaProp === void 0 ? {
|
|
2185
|
+
schema: sch,
|
|
2186
|
+
schemaPath: (0, codegen_12._)`${it.schemaPath}${(0, codegen_12.getProperty)(keyword2)}`,
|
|
2187
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`
|
|
2188
|
+
} : {
|
|
2189
|
+
schema: sch[schemaProp],
|
|
2190
|
+
schemaPath: (0, codegen_12._)`${it.schemaPath}${(0, codegen_12.getProperty)(keyword2)}${(0, codegen_12.getProperty)(schemaProp)}`,
|
|
2191
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_12.escapeFragment)(schemaProp)}`
|
|
2192
|
+
};
|
|
2193
|
+
}
|
|
2194
|
+
if (schema !== void 0) {
|
|
2195
|
+
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
2196
|
+
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
2197
|
+
}
|
|
2198
|
+
return {
|
|
2199
|
+
schema,
|
|
2200
|
+
schemaPath,
|
|
2201
|
+
topSchemaRef,
|
|
2202
|
+
errSchemaPath
|
|
2203
|
+
};
|
|
2204
|
+
}
|
|
2205
|
+
throw new Error('either "keyword" or "schema" must be passed');
|
|
2206
|
+
}
|
|
2207
|
+
subschema.getSubschema = getSubschema;
|
|
2208
|
+
function extendSubschemaData(subschema2, it, { dataProp, dataPropType: dpType, data, dataTypes, propertyName }) {
|
|
2209
|
+
if (data !== void 0 && dataProp !== void 0) {
|
|
2210
|
+
throw new Error('both "data" and "dataProp" passed, only one allowed');
|
|
2211
|
+
}
|
|
2212
|
+
const { gen } = it;
|
|
2213
|
+
if (dataProp !== void 0) {
|
|
2214
|
+
const { errorPath, dataPathArr, opts } = it;
|
|
2215
|
+
const nextData = gen.let("data", (0, codegen_12._)`${it.data}${(0, codegen_12.getProperty)(dataProp)}`, true);
|
|
2216
|
+
dataContextProps(nextData);
|
|
2217
|
+
subschema2.errorPath = (0, codegen_12.str)`${errorPath}${(0, util_12.getErrorPath)(dataProp, dpType, opts.jsPropertySyntax)}`;
|
|
2218
|
+
subschema2.parentDataProperty = (0, codegen_12._)`${dataProp}`;
|
|
2219
|
+
subschema2.dataPathArr = [...dataPathArr, subschema2.parentDataProperty];
|
|
2220
|
+
}
|
|
2221
|
+
if (data !== void 0) {
|
|
2222
|
+
const nextData = data instanceof codegen_12.Name ? data : gen.let("data", data, true);
|
|
2223
|
+
dataContextProps(nextData);
|
|
2224
|
+
if (propertyName !== void 0)
|
|
2225
|
+
subschema2.propertyName = propertyName;
|
|
2226
|
+
}
|
|
2227
|
+
if (dataTypes)
|
|
2228
|
+
subschema2.dataTypes = dataTypes;
|
|
2229
|
+
function dataContextProps(_nextData) {
|
|
2230
|
+
subschema2.data = _nextData;
|
|
2231
|
+
subschema2.dataLevel = it.dataLevel + 1;
|
|
2232
|
+
subschema2.dataTypes = [];
|
|
2233
|
+
it.definedProperties = /* @__PURE__ */ new Set();
|
|
2234
|
+
subschema2.parentData = it.data;
|
|
2235
|
+
subschema2.dataNames = [...it.dataNames, _nextData];
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
subschema.extendSubschemaData = extendSubschemaData;
|
|
2239
|
+
function extendSubschemaMode(subschema2, { jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors }) {
|
|
2240
|
+
if (compositeRule !== void 0)
|
|
2241
|
+
subschema2.compositeRule = compositeRule;
|
|
2242
|
+
if (createErrors !== void 0)
|
|
2243
|
+
subschema2.createErrors = createErrors;
|
|
2244
|
+
if (allErrors !== void 0)
|
|
2245
|
+
subschema2.allErrors = allErrors;
|
|
2246
|
+
subschema2.jtdDiscriminator = jtdDiscriminator;
|
|
2247
|
+
subschema2.jtdMetadata = jtdMetadata;
|
|
2248
|
+
}
|
|
2249
|
+
subschema.extendSubschemaMode = extendSubschemaMode;
|
|
2250
|
+
return subschema;
|
|
2201
2251
|
}
|
|
2202
|
-
subschema.extendSubschemaMode = extendSubschemaMode;
|
|
2203
2252
|
var resolve$2 = {};
|
|
2204
2253
|
var fastDeepEqual = function equal(a, b) {
|
|
2205
2254
|
if (a === b)
|
|
@@ -2324,7 +2373,7 @@ function escapeJsonPtr(str) {
|
|
|
2324
2373
|
var jsonSchemaTraverseExports = jsonSchemaTraverse.exports;
|
|
2325
2374
|
Object.defineProperty(resolve$2, "__esModule", { value: true });
|
|
2326
2375
|
resolve$2.getSchemaRefs = resolve$2.resolveUrl = resolve$2.normalizeId = resolve$2._getFullPath = resolve$2.getFullPath = resolve$2.inlineRef = void 0;
|
|
2327
|
-
const util_1$
|
|
2376
|
+
const util_1$p = util;
|
|
2328
2377
|
const equal$3 = fastDeepEqual;
|
|
2329
2378
|
const traverse = jsonSchemaTraverseExports;
|
|
2330
2379
|
const SIMPLE_INLINED = /* @__PURE__ */ new Set([
|
|
@@ -2383,7 +2432,7 @@ function countKeys(schema) {
|
|
|
2383
2432
|
if (SIMPLE_INLINED.has(key))
|
|
2384
2433
|
continue;
|
|
2385
2434
|
if (typeof schema[key] == "object") {
|
|
2386
|
-
(0, util_1$
|
|
2435
|
+
(0, util_1$p.eachItem)(schema[key], (sch) => count += countKeys(sch));
|
|
2387
2436
|
}
|
|
2388
2437
|
if (count === Infinity)
|
|
2389
2438
|
return Infinity;
|
|
@@ -2471,506 +2520,513 @@ function getSchemaRefs(schema, baseId) {
|
|
|
2471
2520
|
}
|
|
2472
2521
|
}
|
|
2473
2522
|
resolve$2.getSchemaRefs = getSchemaRefs;
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
const
|
|
2482
|
-
const
|
|
2483
|
-
const
|
|
2484
|
-
const
|
|
2485
|
-
const
|
|
2486
|
-
const
|
|
2487
|
-
const
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2523
|
+
var hasRequiredValidate;
|
|
2524
|
+
function requireValidate() {
|
|
2525
|
+
if (hasRequiredValidate)
|
|
2526
|
+
return validate;
|
|
2527
|
+
hasRequiredValidate = 1;
|
|
2528
|
+
Object.defineProperty(validate, "__esModule", { value: true });
|
|
2529
|
+
validate.getData = validate.KeywordCxt = validate.validateFunctionCode = void 0;
|
|
2530
|
+
const boolSchema_1 = requireBoolSchema();
|
|
2531
|
+
const dataType_12 = dataType;
|
|
2532
|
+
const applicability_12 = requireApplicability();
|
|
2533
|
+
const dataType_2 = dataType;
|
|
2534
|
+
const defaults_1 = requireDefaults();
|
|
2535
|
+
const keyword_1 = requireKeyword();
|
|
2536
|
+
const subschema_1 = requireSubschema();
|
|
2537
|
+
const codegen_12 = codegen;
|
|
2538
|
+
const names_12 = requireNames();
|
|
2539
|
+
const resolve_12 = resolve$2;
|
|
2540
|
+
const util_12 = util;
|
|
2541
|
+
const errors_12 = errors;
|
|
2542
|
+
function validateFunctionCode(it) {
|
|
2543
|
+
if (isSchemaObj(it)) {
|
|
2544
|
+
checkKeywords(it);
|
|
2545
|
+
if (schemaCxtHasRules(it)) {
|
|
2546
|
+
topSchemaObjCode(it);
|
|
2547
|
+
return;
|
|
2548
|
+
}
|
|
2494
2549
|
}
|
|
2550
|
+
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
2495
2551
|
}
|
|
2496
|
-
|
|
2497
|
-
}
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2552
|
+
validate.validateFunctionCode = validateFunctionCode;
|
|
2553
|
+
function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
|
|
2554
|
+
if (opts.code.es5) {
|
|
2555
|
+
gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${names_12.default.valCxt}`, schemaEnv.$async, () => {
|
|
2556
|
+
gen.code((0, codegen_12._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
|
|
2557
|
+
destructureValCxtES5(gen, opts);
|
|
2558
|
+
gen.code(body);
|
|
2559
|
+
});
|
|
2560
|
+
} else {
|
|
2561
|
+
gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
function destructureValCxt(opts) {
|
|
2565
|
+
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}}={}`;
|
|
2566
|
+
}
|
|
2567
|
+
function destructureValCxtES5(gen, opts) {
|
|
2568
|
+
gen.if(names_12.default.valCxt, () => {
|
|
2569
|
+
gen.var(names_12.default.instancePath, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.instancePath}`);
|
|
2570
|
+
gen.var(names_12.default.parentData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentData}`);
|
|
2571
|
+
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentDataProperty}`);
|
|
2572
|
+
gen.var(names_12.default.rootData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.rootData}`);
|
|
2573
|
+
if (opts.dynamicRef)
|
|
2574
|
+
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.dynamicAnchors}`);
|
|
2575
|
+
}, () => {
|
|
2576
|
+
gen.var(names_12.default.instancePath, (0, codegen_12._)`""`);
|
|
2577
|
+
gen.var(names_12.default.parentData, (0, codegen_12._)`undefined`);
|
|
2578
|
+
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`undefined`);
|
|
2579
|
+
gen.var(names_12.default.rootData, names_12.default.data);
|
|
2580
|
+
if (opts.dynamicRef)
|
|
2581
|
+
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`{}`);
|
|
2505
2582
|
});
|
|
2506
|
-
} else {
|
|
2507
|
-
gen.func(validateName, (0, codegen_1$r._)`${names_1$6.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
2508
2583
|
}
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
gen
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
}
|
|
2530
|
-
function
|
|
2531
|
-
|
|
2532
|
-
|
|
2584
|
+
function topSchemaObjCode(it) {
|
|
2585
|
+
const { schema, opts, gen } = it;
|
|
2586
|
+
validateFunction(it, () => {
|
|
2587
|
+
if (opts.$comment && schema.$comment)
|
|
2588
|
+
commentKeyword(it);
|
|
2589
|
+
checkNoDefault(it);
|
|
2590
|
+
gen.let(names_12.default.vErrors, null);
|
|
2591
|
+
gen.let(names_12.default.errors, 0);
|
|
2592
|
+
if (opts.unevaluated)
|
|
2593
|
+
resetEvaluated(it);
|
|
2594
|
+
typeAndKeywords(it);
|
|
2595
|
+
returnResults(it);
|
|
2596
|
+
});
|
|
2597
|
+
return;
|
|
2598
|
+
}
|
|
2599
|
+
function resetEvaluated(it) {
|
|
2600
|
+
const { gen, validateName } = it;
|
|
2601
|
+
it.evaluated = gen.const("evaluated", (0, codegen_12._)`${validateName}.evaluated`);
|
|
2602
|
+
gen.if((0, codegen_12._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_12._)`${it.evaluated}.props`, (0, codegen_12._)`undefined`));
|
|
2603
|
+
gen.if((0, codegen_12._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_12._)`${it.evaluated}.items`, (0, codegen_12._)`undefined`));
|
|
2604
|
+
}
|
|
2605
|
+
function funcSourceUrl(schema, opts) {
|
|
2606
|
+
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
2607
|
+
return schId && (opts.code.source || opts.code.process) ? (0, codegen_12._)`/*# sourceURL=${schId} */` : codegen_12.nil;
|
|
2608
|
+
}
|
|
2609
|
+
function subschemaCode(it, valid) {
|
|
2610
|
+
if (isSchemaObj(it)) {
|
|
2611
|
+
checkKeywords(it);
|
|
2612
|
+
if (schemaCxtHasRules(it)) {
|
|
2613
|
+
subSchemaObjCode(it, valid);
|
|
2614
|
+
return;
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
(0, boolSchema_1.boolOrEmptySchema)(it, valid);
|
|
2618
|
+
}
|
|
2619
|
+
function schemaCxtHasRules({ schema, self }) {
|
|
2620
|
+
if (typeof schema == "boolean")
|
|
2621
|
+
return !schema;
|
|
2622
|
+
for (const key in schema)
|
|
2623
|
+
if (self.RULES.all[key])
|
|
2624
|
+
return true;
|
|
2625
|
+
return false;
|
|
2626
|
+
}
|
|
2627
|
+
function isSchemaObj(it) {
|
|
2628
|
+
return typeof it.schema != "boolean";
|
|
2629
|
+
}
|
|
2630
|
+
function subSchemaObjCode(it, valid) {
|
|
2631
|
+
const { schema, gen, opts } = it;
|
|
2533
2632
|
if (opts.$comment && schema.$comment)
|
|
2534
2633
|
commentKeyword(it);
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
gen.
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
typeAndKeywords(it);
|
|
2541
|
-
returnResults(it);
|
|
2542
|
-
});
|
|
2543
|
-
return;
|
|
2544
|
-
}
|
|
2545
|
-
function resetEvaluated(it) {
|
|
2546
|
-
const { gen, validateName } = it;
|
|
2547
|
-
it.evaluated = gen.const("evaluated", (0, codegen_1$r._)`${validateName}.evaluated`);
|
|
2548
|
-
gen.if((0, codegen_1$r._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_1$r._)`${it.evaluated}.props`, (0, codegen_1$r._)`undefined`));
|
|
2549
|
-
gen.if((0, codegen_1$r._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_1$r._)`${it.evaluated}.items`, (0, codegen_1$r._)`undefined`));
|
|
2550
|
-
}
|
|
2551
|
-
function funcSourceUrl(schema, opts) {
|
|
2552
|
-
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
2553
|
-
return schId && (opts.code.source || opts.code.process) ? (0, codegen_1$r._)`/*# sourceURL=${schId} */` : codegen_1$r.nil;
|
|
2554
|
-
}
|
|
2555
|
-
function subschemaCode(it, valid) {
|
|
2556
|
-
if (isSchemaObj(it)) {
|
|
2557
|
-
checkKeywords(it);
|
|
2558
|
-
if (schemaCxtHasRules(it)) {
|
|
2559
|
-
subSchemaObjCode(it, valid);
|
|
2560
|
-
return;
|
|
2561
|
-
}
|
|
2634
|
+
updateContext(it);
|
|
2635
|
+
checkAsyncSchema(it);
|
|
2636
|
+
const errsCount = gen.const("_errs", names_12.default.errors);
|
|
2637
|
+
typeAndKeywords(it, errsCount);
|
|
2638
|
+
gen.var(valid, (0, codegen_12._)`${errsCount} === ${names_12.default.errors}`);
|
|
2562
2639
|
}
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
if (typeof schema == "boolean")
|
|
2567
|
-
return !schema;
|
|
2568
|
-
for (const key in schema)
|
|
2569
|
-
if (self.RULES.all[key])
|
|
2570
|
-
return true;
|
|
2571
|
-
return false;
|
|
2572
|
-
}
|
|
2573
|
-
function isSchemaObj(it) {
|
|
2574
|
-
return typeof it.schema != "boolean";
|
|
2575
|
-
}
|
|
2576
|
-
function subSchemaObjCode(it, valid) {
|
|
2577
|
-
const { schema, gen, opts } = it;
|
|
2578
|
-
if (opts.$comment && schema.$comment)
|
|
2579
|
-
commentKeyword(it);
|
|
2580
|
-
updateContext(it);
|
|
2581
|
-
checkAsyncSchema(it);
|
|
2582
|
-
const errsCount = gen.const("_errs", names_1$6.default.errors);
|
|
2583
|
-
typeAndKeywords(it, errsCount);
|
|
2584
|
-
gen.var(valid, (0, codegen_1$r._)`${errsCount} === ${names_1$6.default.errors}`);
|
|
2585
|
-
}
|
|
2586
|
-
function checkKeywords(it) {
|
|
2587
|
-
(0, util_1$p.checkUnknownRules)(it);
|
|
2588
|
-
checkRefsAndKeywords(it);
|
|
2589
|
-
}
|
|
2590
|
-
function typeAndKeywords(it, errsCount) {
|
|
2591
|
-
if (it.opts.jtd)
|
|
2592
|
-
return schemaKeywords(it, [], false, errsCount);
|
|
2593
|
-
const types2 = (0, dataType_1$1.getSchemaTypes)(it.schema);
|
|
2594
|
-
const checkedTypes = (0, dataType_1$1.coerceAndCheckDataType)(it, types2);
|
|
2595
|
-
schemaKeywords(it, types2, !checkedTypes, errsCount);
|
|
2596
|
-
}
|
|
2597
|
-
function checkRefsAndKeywords(it) {
|
|
2598
|
-
const { schema, errSchemaPath, opts, self } = it;
|
|
2599
|
-
if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_1$p.schemaHasRulesButRef)(schema, self.RULES)) {
|
|
2600
|
-
self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
|
|
2640
|
+
function checkKeywords(it) {
|
|
2641
|
+
(0, util_12.checkUnknownRules)(it);
|
|
2642
|
+
checkRefsAndKeywords(it);
|
|
2601
2643
|
}
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
(0,
|
|
2644
|
+
function typeAndKeywords(it, errsCount) {
|
|
2645
|
+
if (it.opts.jtd)
|
|
2646
|
+
return schemaKeywords(it, [], false, errsCount);
|
|
2647
|
+
const types2 = (0, dataType_12.getSchemaTypes)(it.schema);
|
|
2648
|
+
const checkedTypes = (0, dataType_12.coerceAndCheckDataType)(it, types2);
|
|
2649
|
+
schemaKeywords(it, types2, !checkedTypes, errsCount);
|
|
2607
2650
|
}
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
}
|
|
2614
|
-
function checkAsyncSchema(it) {
|
|
2615
|
-
if (it.schema.$async && !it.schemaEnv.$async)
|
|
2616
|
-
throw new Error("async schema in sync schema");
|
|
2617
|
-
}
|
|
2618
|
-
function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
|
|
2619
|
-
const msg = schema.$comment;
|
|
2620
|
-
if (opts.$comment === true) {
|
|
2621
|
-
gen.code((0, codegen_1$r._)`${names_1$6.default.self}.logger.log(${msg})`);
|
|
2622
|
-
} else if (typeof opts.$comment == "function") {
|
|
2623
|
-
const schemaPath = (0, codegen_1$r.str)`${errSchemaPath}/$comment`;
|
|
2624
|
-
const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
|
|
2625
|
-
gen.code((0, codegen_1$r._)`${names_1$6.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
|
|
2651
|
+
function checkRefsAndKeywords(it) {
|
|
2652
|
+
const { schema, errSchemaPath, opts, self } = it;
|
|
2653
|
+
if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_12.schemaHasRulesButRef)(schema, self.RULES)) {
|
|
2654
|
+
self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
|
|
2655
|
+
}
|
|
2626
2656
|
}
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
} else {
|
|
2633
|
-
gen.assign((0, codegen_1$r._)`${validateName}.errors`, names_1$6.default.vErrors);
|
|
2634
|
-
if (opts.unevaluated)
|
|
2635
|
-
assignEvaluated(it);
|
|
2636
|
-
gen.return((0, codegen_1$r._)`${names_1$6.default.errors} === 0`);
|
|
2657
|
+
function checkNoDefault(it) {
|
|
2658
|
+
const { schema, opts } = it;
|
|
2659
|
+
if (schema.default !== void 0 && opts.useDefaults && opts.strictSchema) {
|
|
2660
|
+
(0, util_12.checkStrictMode)(it, "default is ignored in the schema root");
|
|
2661
|
+
}
|
|
2637
2662
|
}
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
if (items2 instanceof codegen_1$r.Name)
|
|
2643
|
-
gen.assign((0, codegen_1$r._)`${evaluated}.items`, items2);
|
|
2644
|
-
}
|
|
2645
|
-
function schemaKeywords(it, types2, typeErrors, errsCount) {
|
|
2646
|
-
const { gen, schema, data, allErrors, opts, self } = it;
|
|
2647
|
-
const { RULES } = self;
|
|
2648
|
-
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_1$p.schemaHasRulesButRef)(schema, RULES))) {
|
|
2649
|
-
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
2650
|
-
return;
|
|
2663
|
+
function updateContext(it) {
|
|
2664
|
+
const schId = it.schema[it.opts.schemaId];
|
|
2665
|
+
if (schId)
|
|
2666
|
+
it.baseId = (0, resolve_12.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
|
|
2651
2667
|
}
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
if (
|
|
2668
|
+
function checkAsyncSchema(it) {
|
|
2669
|
+
if (it.schema.$async && !it.schemaEnv.$async)
|
|
2670
|
+
throw new Error("async schema in sync schema");
|
|
2671
|
+
}
|
|
2672
|
+
function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
|
|
2673
|
+
const msg = schema.$comment;
|
|
2674
|
+
if (opts.$comment === true) {
|
|
2675
|
+
gen.code((0, codegen_12._)`${names_12.default.self}.logger.log(${msg})`);
|
|
2676
|
+
} else if (typeof opts.$comment == "function") {
|
|
2677
|
+
const schemaPath = (0, codegen_12.str)`${errSchemaPath}/$comment`;
|
|
2678
|
+
const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
|
|
2679
|
+
gen.code((0, codegen_12._)`${names_12.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
function returnResults(it) {
|
|
2683
|
+
const { gen, schemaEnv, validateName, ValidationError: ValidationError2, opts } = it;
|
|
2684
|
+
if (schemaEnv.$async) {
|
|
2685
|
+
gen.if((0, codegen_12._)`${names_12.default.errors} === 0`, () => gen.return(names_12.default.data), () => gen.throw((0, codegen_12._)`new ${ValidationError2}(${names_12.default.vErrors})`));
|
|
2686
|
+
} else {
|
|
2687
|
+
gen.assign((0, codegen_12._)`${validateName}.errors`, names_12.default.vErrors);
|
|
2688
|
+
if (opts.unevaluated)
|
|
2689
|
+
assignEvaluated(it);
|
|
2690
|
+
gen.return((0, codegen_12._)`${names_12.default.errors} === 0`);
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
function assignEvaluated({ gen, evaluated, props, items: items2 }) {
|
|
2694
|
+
if (props instanceof codegen_12.Name)
|
|
2695
|
+
gen.assign((0, codegen_12._)`${evaluated}.props`, props);
|
|
2696
|
+
if (items2 instanceof codegen_12.Name)
|
|
2697
|
+
gen.assign((0, codegen_12._)`${evaluated}.items`, items2);
|
|
2698
|
+
}
|
|
2699
|
+
function schemaKeywords(it, types2, typeErrors, errsCount) {
|
|
2700
|
+
const { gen, schema, data, allErrors, opts, self } = it;
|
|
2701
|
+
const { RULES } = self;
|
|
2702
|
+
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_12.schemaHasRulesButRef)(schema, RULES))) {
|
|
2703
|
+
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
2661
2704
|
return;
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
(
|
|
2705
|
+
}
|
|
2706
|
+
if (!opts.jtd)
|
|
2707
|
+
checkStrictTypes(it, types2);
|
|
2708
|
+
gen.block(() => {
|
|
2709
|
+
for (const group of RULES.rules)
|
|
2710
|
+
groupKeywords(group);
|
|
2711
|
+
groupKeywords(RULES.post);
|
|
2712
|
+
});
|
|
2713
|
+
function groupKeywords(group) {
|
|
2714
|
+
if (!(0, applicability_12.shouldUseGroup)(schema, group))
|
|
2715
|
+
return;
|
|
2716
|
+
if (group.type) {
|
|
2717
|
+
gen.if((0, dataType_2.checkDataType)(group.type, data, opts.strictNumbers));
|
|
2718
|
+
iterateKeywords(it, group);
|
|
2719
|
+
if (types2.length === 1 && types2[0] === group.type && typeErrors) {
|
|
2720
|
+
gen.else();
|
|
2721
|
+
(0, dataType_2.reportTypeError)(it);
|
|
2722
|
+
}
|
|
2723
|
+
gen.endIf();
|
|
2724
|
+
} else {
|
|
2725
|
+
iterateKeywords(it, group);
|
|
2668
2726
|
}
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
iterateKeywords(it, group);
|
|
2727
|
+
if (!allErrors)
|
|
2728
|
+
gen.if((0, codegen_12._)`${names_12.default.errors} === ${errsCount || 0}`);
|
|
2672
2729
|
}
|
|
2673
|
-
if (!allErrors)
|
|
2674
|
-
gen.if((0, codegen_1$r._)`${names_1$6.default.errors} === ${errsCount || 0}`);
|
|
2675
2730
|
}
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
(
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2731
|
+
function iterateKeywords(it, group) {
|
|
2732
|
+
const { gen, schema, opts: { useDefaults } } = it;
|
|
2733
|
+
if (useDefaults)
|
|
2734
|
+
(0, defaults_1.assignDefaults)(it, group.type);
|
|
2735
|
+
gen.block(() => {
|
|
2736
|
+
for (const rule of group.rules) {
|
|
2737
|
+
if ((0, applicability_12.shouldUseRule)(schema, rule)) {
|
|
2738
|
+
keywordCode(it, rule.keyword, rule.definition, group.type);
|
|
2739
|
+
}
|
|
2685
2740
|
}
|
|
2741
|
+
});
|
|
2742
|
+
}
|
|
2743
|
+
function checkStrictTypes(it, types2) {
|
|
2744
|
+
if (it.schemaEnv.meta || !it.opts.strictTypes)
|
|
2745
|
+
return;
|
|
2746
|
+
checkContextTypes(it, types2);
|
|
2747
|
+
if (!it.opts.allowUnionTypes)
|
|
2748
|
+
checkMultipleTypes(it, types2);
|
|
2749
|
+
checkKeywordTypes(it, it.dataTypes);
|
|
2750
|
+
}
|
|
2751
|
+
function checkContextTypes(it, types2) {
|
|
2752
|
+
if (!types2.length)
|
|
2753
|
+
return;
|
|
2754
|
+
if (!it.dataTypes.length) {
|
|
2755
|
+
it.dataTypes = types2;
|
|
2756
|
+
return;
|
|
2686
2757
|
}
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
if (!it.opts.allowUnionTypes)
|
|
2694
|
-
checkMultipleTypes(it, types2);
|
|
2695
|
-
checkKeywordTypes(it, it.dataTypes);
|
|
2696
|
-
}
|
|
2697
|
-
function checkContextTypes(it, types2) {
|
|
2698
|
-
if (!types2.length)
|
|
2699
|
-
return;
|
|
2700
|
-
if (!it.dataTypes.length) {
|
|
2701
|
-
it.dataTypes = types2;
|
|
2702
|
-
return;
|
|
2758
|
+
types2.forEach((t) => {
|
|
2759
|
+
if (!includesType(it.dataTypes, t)) {
|
|
2760
|
+
strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
|
|
2761
|
+
}
|
|
2762
|
+
});
|
|
2763
|
+
narrowSchemaTypes(it, types2);
|
|
2703
2764
|
}
|
|
2704
|
-
|
|
2705
|
-
if (!
|
|
2706
|
-
strictTypesError(it,
|
|
2765
|
+
function checkMultipleTypes(it, ts) {
|
|
2766
|
+
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
|
|
2767
|
+
strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
2707
2768
|
}
|
|
2708
|
-
});
|
|
2709
|
-
narrowSchemaTypes(it, types2);
|
|
2710
|
-
}
|
|
2711
|
-
function checkMultipleTypes(it, ts) {
|
|
2712
|
-
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
|
|
2713
|
-
strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
2714
2769
|
}
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2770
|
+
function checkKeywordTypes(it, ts) {
|
|
2771
|
+
const rules2 = it.self.RULES.all;
|
|
2772
|
+
for (const keyword2 in rules2) {
|
|
2773
|
+
const rule = rules2[keyword2];
|
|
2774
|
+
if (typeof rule == "object" && (0, applicability_12.shouldUseRule)(it.schema, rule)) {
|
|
2775
|
+
const { type: type2 } = rule.definition;
|
|
2776
|
+
if (type2.length && !type2.some((t) => hasApplicableType(ts, t))) {
|
|
2777
|
+
strictTypesError(it, `missing type "${type2.join(",")}" for keyword "${keyword2}"`);
|
|
2778
|
+
}
|
|
2724
2779
|
}
|
|
2725
2780
|
}
|
|
2726
2781
|
}
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2782
|
+
function hasApplicableType(schTs, kwdT) {
|
|
2783
|
+
return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
|
|
2784
|
+
}
|
|
2785
|
+
function includesType(ts, t) {
|
|
2786
|
+
return ts.includes(t) || t === "integer" && ts.includes("number");
|
|
2787
|
+
}
|
|
2788
|
+
function narrowSchemaTypes(it, withTypes) {
|
|
2789
|
+
const ts = [];
|
|
2790
|
+
for (const t of it.dataTypes) {
|
|
2791
|
+
if (includesType(withTypes, t))
|
|
2792
|
+
ts.push(t);
|
|
2793
|
+
else if (withTypes.includes("integer") && t === "number")
|
|
2794
|
+
ts.push("integer");
|
|
2795
|
+
}
|
|
2796
|
+
it.dataTypes = ts;
|
|
2797
|
+
}
|
|
2798
|
+
function strictTypesError(it, msg) {
|
|
2799
|
+
const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
|
|
2800
|
+
msg += ` at "${schemaPath}" (strictTypes)`;
|
|
2801
|
+
(0, util_12.checkStrictMode)(it, msg, it.opts.strictTypes);
|
|
2802
|
+
}
|
|
2803
|
+
class KeywordCxt {
|
|
2804
|
+
constructor(it, def2, keyword2) {
|
|
2805
|
+
(0, keyword_1.validateKeywordUsage)(it, def2, keyword2);
|
|
2806
|
+
this.gen = it.gen;
|
|
2807
|
+
this.allErrors = it.allErrors;
|
|
2808
|
+
this.keyword = keyword2;
|
|
2809
|
+
this.data = it.data;
|
|
2810
|
+
this.schema = it.schema[keyword2];
|
|
2811
|
+
this.$data = def2.$data && it.opts.$data && this.schema && this.schema.$data;
|
|
2812
|
+
this.schemaValue = (0, util_12.schemaRefOrVal)(it, this.schema, keyword2, this.$data);
|
|
2813
|
+
this.schemaType = def2.schemaType;
|
|
2814
|
+
this.parentSchema = it.schema;
|
|
2815
|
+
this.params = {};
|
|
2816
|
+
this.it = it;
|
|
2817
|
+
this.def = def2;
|
|
2818
|
+
if (this.$data) {
|
|
2819
|
+
this.schemaCode = it.gen.const("vSchema", getData(this.$data, it));
|
|
2820
|
+
} else {
|
|
2821
|
+
this.schemaCode = this.schemaValue;
|
|
2822
|
+
if (!(0, keyword_1.validSchemaType)(this.schema, def2.schemaType, def2.allowUndefined)) {
|
|
2823
|
+
throw new Error(`${keyword2} value must be ${JSON.stringify(def2.schemaType)}`);
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
|
|
2827
|
+
this.errsCount = it.gen.const("_errs", names_12.default.errors);
|
|
2770
2828
|
}
|
|
2771
2829
|
}
|
|
2772
|
-
|
|
2773
|
-
this.
|
|
2830
|
+
result(condition, successAction, failAction) {
|
|
2831
|
+
this.failResult((0, codegen_12.not)(condition), successAction, failAction);
|
|
2774
2832
|
}
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2833
|
+
failResult(condition, successAction, failAction) {
|
|
2834
|
+
this.gen.if(condition);
|
|
2835
|
+
if (failAction)
|
|
2836
|
+
failAction();
|
|
2837
|
+
else
|
|
2838
|
+
this.error();
|
|
2839
|
+
if (successAction) {
|
|
2840
|
+
this.gen.else();
|
|
2841
|
+
successAction();
|
|
2842
|
+
if (this.allErrors)
|
|
2843
|
+
this.gen.endIf();
|
|
2844
|
+
} else {
|
|
2845
|
+
if (this.allErrors)
|
|
2846
|
+
this.gen.endIf();
|
|
2847
|
+
else
|
|
2848
|
+
this.gen.else();
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
pass(condition, failAction) {
|
|
2852
|
+
this.failResult((0, codegen_12.not)(condition), void 0, failAction);
|
|
2853
|
+
}
|
|
2854
|
+
fail(condition) {
|
|
2855
|
+
if (condition === void 0) {
|
|
2856
|
+
this.error();
|
|
2857
|
+
if (!this.allErrors)
|
|
2858
|
+
this.gen.if(false);
|
|
2859
|
+
return;
|
|
2860
|
+
}
|
|
2861
|
+
this.gen.if(condition);
|
|
2784
2862
|
this.error();
|
|
2785
|
-
if (successAction) {
|
|
2786
|
-
this.gen.else();
|
|
2787
|
-
successAction();
|
|
2788
|
-
if (this.allErrors)
|
|
2789
|
-
this.gen.endIf();
|
|
2790
|
-
} else {
|
|
2791
2863
|
if (this.allErrors)
|
|
2792
2864
|
this.gen.endIf();
|
|
2793
2865
|
else
|
|
2794
2866
|
this.gen.else();
|
|
2795
2867
|
}
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2868
|
+
fail$data(condition) {
|
|
2869
|
+
if (!this.$data)
|
|
2870
|
+
return this.fail(condition);
|
|
2871
|
+
const { schemaCode } = this;
|
|
2872
|
+
this.fail((0, codegen_12._)`${schemaCode} !== undefined && (${(0, codegen_12.or)(this.invalid$data(), condition)})`);
|
|
2873
|
+
}
|
|
2874
|
+
error(append, errorParams, errorPaths) {
|
|
2875
|
+
if (errorParams) {
|
|
2876
|
+
this.setParams(errorParams);
|
|
2877
|
+
this._error(append, errorPaths);
|
|
2878
|
+
this.setParams({});
|
|
2879
|
+
return;
|
|
2880
|
+
}
|
|
2881
|
+
this._error(append, errorPaths);
|
|
2882
|
+
}
|
|
2883
|
+
_error(append, errorPaths) {
|
|
2884
|
+
(append ? errors_12.reportExtraError : errors_12.reportError)(this, this.def.error, errorPaths);
|
|
2885
|
+
}
|
|
2886
|
+
$dataError() {
|
|
2887
|
+
(0, errors_12.reportError)(this, this.def.$dataError || errors_12.keyword$DataError);
|
|
2888
|
+
}
|
|
2889
|
+
reset() {
|
|
2890
|
+
if (this.errsCount === void 0)
|
|
2891
|
+
throw new Error('add "trackErrors" to keyword definition');
|
|
2892
|
+
(0, errors_12.resetErrorsCount)(this.gen, this.errsCount);
|
|
2893
|
+
}
|
|
2894
|
+
ok(cond) {
|
|
2803
2895
|
if (!this.allErrors)
|
|
2804
|
-
this.gen.if(
|
|
2805
|
-
return;
|
|
2896
|
+
this.gen.if(cond);
|
|
2806
2897
|
}
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
this.gen.else();
|
|
2813
|
-
}
|
|
2814
|
-
fail$data(condition) {
|
|
2815
|
-
if (!this.$data)
|
|
2816
|
-
return this.fail(condition);
|
|
2817
|
-
const { schemaCode } = this;
|
|
2818
|
-
this.fail((0, codegen_1$r._)`${schemaCode} !== undefined && (${(0, codegen_1$r.or)(this.invalid$data(), condition)})`);
|
|
2819
|
-
}
|
|
2820
|
-
error(append, errorParams, errorPaths) {
|
|
2821
|
-
if (errorParams) {
|
|
2822
|
-
this.setParams(errorParams);
|
|
2823
|
-
this._error(append, errorPaths);
|
|
2824
|
-
this.setParams({});
|
|
2825
|
-
return;
|
|
2898
|
+
setParams(obj, assign) {
|
|
2899
|
+
if (assign)
|
|
2900
|
+
Object.assign(this.params, obj);
|
|
2901
|
+
else
|
|
2902
|
+
this.params = obj;
|
|
2826
2903
|
}
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
$dataError() {
|
|
2833
|
-
(0, errors_1.reportError)(this, this.def.$dataError || errors_1.keyword$DataError);
|
|
2834
|
-
}
|
|
2835
|
-
reset() {
|
|
2836
|
-
if (this.errsCount === void 0)
|
|
2837
|
-
throw new Error('add "trackErrors" to keyword definition');
|
|
2838
|
-
(0, errors_1.resetErrorsCount)(this.gen, this.errsCount);
|
|
2839
|
-
}
|
|
2840
|
-
ok(cond) {
|
|
2841
|
-
if (!this.allErrors)
|
|
2842
|
-
this.gen.if(cond);
|
|
2843
|
-
}
|
|
2844
|
-
setParams(obj, assign) {
|
|
2845
|
-
if (assign)
|
|
2846
|
-
Object.assign(this.params, obj);
|
|
2847
|
-
else
|
|
2848
|
-
this.params = obj;
|
|
2849
|
-
}
|
|
2850
|
-
block$data(valid, codeBlock, $dataValid = codegen_1$r.nil) {
|
|
2851
|
-
this.gen.block(() => {
|
|
2852
|
-
this.check$data(valid, $dataValid);
|
|
2853
|
-
codeBlock();
|
|
2854
|
-
});
|
|
2855
|
-
}
|
|
2856
|
-
check$data(valid = codegen_1$r.nil, $dataValid = codegen_1$r.nil) {
|
|
2857
|
-
if (!this.$data)
|
|
2858
|
-
return;
|
|
2859
|
-
const { gen, schemaCode, schemaType, def: def2 } = this;
|
|
2860
|
-
gen.if((0, codegen_1$r.or)((0, codegen_1$r._)`${schemaCode} === undefined`, $dataValid));
|
|
2861
|
-
if (valid !== codegen_1$r.nil)
|
|
2862
|
-
gen.assign(valid, true);
|
|
2863
|
-
if (schemaType.length || def2.validateSchema) {
|
|
2864
|
-
gen.elseIf(this.invalid$data());
|
|
2865
|
-
this.$dataError();
|
|
2866
|
-
if (valid !== codegen_1$r.nil)
|
|
2867
|
-
gen.assign(valid, false);
|
|
2904
|
+
block$data(valid, codeBlock, $dataValid = codegen_12.nil) {
|
|
2905
|
+
this.gen.block(() => {
|
|
2906
|
+
this.check$data(valid, $dataValid);
|
|
2907
|
+
codeBlock();
|
|
2908
|
+
});
|
|
2868
2909
|
}
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2910
|
+
check$data(valid = codegen_12.nil, $dataValid = codegen_12.nil) {
|
|
2911
|
+
if (!this.$data)
|
|
2912
|
+
return;
|
|
2913
|
+
const { gen, schemaCode, schemaType, def: def2 } = this;
|
|
2914
|
+
gen.if((0, codegen_12.or)((0, codegen_12._)`${schemaCode} === undefined`, $dataValid));
|
|
2915
|
+
if (valid !== codegen_12.nil)
|
|
2916
|
+
gen.assign(valid, true);
|
|
2917
|
+
if (schemaType.length || def2.validateSchema) {
|
|
2918
|
+
gen.elseIf(this.invalid$data());
|
|
2919
|
+
this.$dataError();
|
|
2920
|
+
if (valid !== codegen_12.nil)
|
|
2921
|
+
gen.assign(valid, false);
|
|
2880
2922
|
}
|
|
2881
|
-
|
|
2923
|
+
gen.else();
|
|
2882
2924
|
}
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2925
|
+
invalid$data() {
|
|
2926
|
+
const { gen, schemaCode, schemaType, def: def2, it } = this;
|
|
2927
|
+
return (0, codegen_12.or)(wrong$DataType(), invalid$DataSchema());
|
|
2928
|
+
function wrong$DataType() {
|
|
2929
|
+
if (schemaType.length) {
|
|
2930
|
+
if (!(schemaCode instanceof codegen_12.Name))
|
|
2931
|
+
throw new Error("ajv implementation error");
|
|
2932
|
+
const st = Array.isArray(schemaType) ? schemaType : [schemaType];
|
|
2933
|
+
return (0, codegen_12._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
|
|
2934
|
+
}
|
|
2935
|
+
return codegen_12.nil;
|
|
2936
|
+
}
|
|
2937
|
+
function invalid$DataSchema() {
|
|
2938
|
+
if (def2.validateSchema) {
|
|
2939
|
+
const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
|
|
2940
|
+
return (0, codegen_12._)`!${validateSchemaRef}(${schemaCode})`;
|
|
2941
|
+
}
|
|
2942
|
+
return codegen_12.nil;
|
|
2887
2943
|
}
|
|
2888
|
-
return codegen_1$r.nil;
|
|
2889
2944
|
}
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2945
|
+
subschema(appl, valid) {
|
|
2946
|
+
const subschema2 = (0, subschema_1.getSubschema)(this.it, appl);
|
|
2947
|
+
(0, subschema_1.extendSubschemaData)(subschema2, this.it, appl);
|
|
2948
|
+
(0, subschema_1.extendSubschemaMode)(subschema2, appl);
|
|
2949
|
+
const nextContext = { ...this.it, ...subschema2, items: void 0, props: void 0 };
|
|
2950
|
+
subschemaCode(nextContext, valid);
|
|
2951
|
+
return nextContext;
|
|
2952
|
+
}
|
|
2953
|
+
mergeEvaluated(schemaCxt, toName) {
|
|
2954
|
+
const { it, gen } = this;
|
|
2955
|
+
if (!it.opts.unevaluated)
|
|
2956
|
+
return;
|
|
2957
|
+
if (it.props !== true && schemaCxt.props !== void 0) {
|
|
2958
|
+
it.props = util_12.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
|
|
2959
|
+
}
|
|
2960
|
+
if (it.items !== true && schemaCxt.items !== void 0) {
|
|
2961
|
+
it.items = util_12.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
|
|
2962
|
+
}
|
|
2905
2963
|
}
|
|
2906
|
-
|
|
2907
|
-
|
|
2964
|
+
mergeValidEvaluated(schemaCxt, valid) {
|
|
2965
|
+
const { it, gen } = this;
|
|
2966
|
+
if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
|
|
2967
|
+
gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_12.Name));
|
|
2968
|
+
return true;
|
|
2969
|
+
}
|
|
2908
2970
|
}
|
|
2909
2971
|
}
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2972
|
+
validate.KeywordCxt = KeywordCxt;
|
|
2973
|
+
function keywordCode(it, keyword2, def2, ruleType) {
|
|
2974
|
+
const cxt = new KeywordCxt(it, def2, keyword2);
|
|
2975
|
+
if ("code" in def2) {
|
|
2976
|
+
def2.code(cxt, ruleType);
|
|
2977
|
+
} else if (cxt.$data && def2.validate) {
|
|
2978
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2979
|
+
} else if ("macro" in def2) {
|
|
2980
|
+
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
2981
|
+
} else if (def2.compile || def2.validate) {
|
|
2982
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
2986
|
+
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
2987
|
+
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
2988
|
+
let jsonPointer;
|
|
2989
|
+
let data;
|
|
2990
|
+
if ($data === "")
|
|
2991
|
+
return names_12.default.rootData;
|
|
2992
|
+
if ($data[0] === "/") {
|
|
2993
|
+
if (!JSON_POINTER.test($data))
|
|
2994
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2995
|
+
jsonPointer = $data;
|
|
2996
|
+
data = names_12.default.rootData;
|
|
2997
|
+
} else {
|
|
2998
|
+
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
2999
|
+
if (!matches)
|
|
3000
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
3001
|
+
const up = +matches[1];
|
|
3002
|
+
jsonPointer = matches[2];
|
|
3003
|
+
if (jsonPointer === "#") {
|
|
3004
|
+
if (up >= dataLevel)
|
|
3005
|
+
throw new Error(errorMsg("property/index", up));
|
|
3006
|
+
return dataPathArr[dataLevel - up];
|
|
3007
|
+
}
|
|
3008
|
+
if (up > dataLevel)
|
|
3009
|
+
throw new Error(errorMsg("data", up));
|
|
3010
|
+
data = dataNames[dataLevel - up];
|
|
3011
|
+
if (!jsonPointer)
|
|
3012
|
+
return data;
|
|
3013
|
+
}
|
|
3014
|
+
let expr = data;
|
|
3015
|
+
const segments = jsonPointer.split("/");
|
|
3016
|
+
for (const segment of segments) {
|
|
3017
|
+
if (segment) {
|
|
3018
|
+
data = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)((0, util_12.unescapeJsonPointer)(segment))}`;
|
|
3019
|
+
expr = (0, codegen_12._)`${expr} && ${data}`;
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3022
|
+
return expr;
|
|
3023
|
+
function errorMsg(pointerType, up) {
|
|
3024
|
+
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
2915
3025
|
}
|
|
2916
3026
|
}
|
|
3027
|
+
validate.getData = getData;
|
|
3028
|
+
return validate;
|
|
2917
3029
|
}
|
|
2918
|
-
validate.KeywordCxt = KeywordCxt;
|
|
2919
|
-
function keywordCode(it, keyword2, def2, ruleType) {
|
|
2920
|
-
const cxt = new KeywordCxt(it, def2, keyword2);
|
|
2921
|
-
if ("code" in def2) {
|
|
2922
|
-
def2.code(cxt, ruleType);
|
|
2923
|
-
} else if (cxt.$data && def2.validate) {
|
|
2924
|
-
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2925
|
-
} else if ("macro" in def2) {
|
|
2926
|
-
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
2927
|
-
} else if (def2.compile || def2.validate) {
|
|
2928
|
-
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2929
|
-
}
|
|
2930
|
-
}
|
|
2931
|
-
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
2932
|
-
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
2933
|
-
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
2934
|
-
let jsonPointer;
|
|
2935
|
-
let data;
|
|
2936
|
-
if ($data === "")
|
|
2937
|
-
return names_1$6.default.rootData;
|
|
2938
|
-
if ($data[0] === "/") {
|
|
2939
|
-
if (!JSON_POINTER.test($data))
|
|
2940
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2941
|
-
jsonPointer = $data;
|
|
2942
|
-
data = names_1$6.default.rootData;
|
|
2943
|
-
} else {
|
|
2944
|
-
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
2945
|
-
if (!matches)
|
|
2946
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2947
|
-
const up = +matches[1];
|
|
2948
|
-
jsonPointer = matches[2];
|
|
2949
|
-
if (jsonPointer === "#") {
|
|
2950
|
-
if (up >= dataLevel)
|
|
2951
|
-
throw new Error(errorMsg("property/index", up));
|
|
2952
|
-
return dataPathArr[dataLevel - up];
|
|
2953
|
-
}
|
|
2954
|
-
if (up > dataLevel)
|
|
2955
|
-
throw new Error(errorMsg("data", up));
|
|
2956
|
-
data = dataNames[dataLevel - up];
|
|
2957
|
-
if (!jsonPointer)
|
|
2958
|
-
return data;
|
|
2959
|
-
}
|
|
2960
|
-
let expr = data;
|
|
2961
|
-
const segments = jsonPointer.split("/");
|
|
2962
|
-
for (const segment of segments) {
|
|
2963
|
-
if (segment) {
|
|
2964
|
-
data = (0, codegen_1$r._)`${data}${(0, codegen_1$r.getProperty)((0, util_1$p.unescapeJsonPointer)(segment))}`;
|
|
2965
|
-
expr = (0, codegen_1$r._)`${expr} && ${data}`;
|
|
2966
|
-
}
|
|
2967
|
-
}
|
|
2968
|
-
return expr;
|
|
2969
|
-
function errorMsg(pointerType, up) {
|
|
2970
|
-
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
2971
|
-
}
|
|
2972
|
-
}
|
|
2973
|
-
validate.getData = getData;
|
|
2974
3030
|
var validation_error = {};
|
|
2975
3031
|
Object.defineProperty(validation_error, "__esModule", { value: true });
|
|
2976
3032
|
class ValidationError extends Error {
|
|
@@ -2997,10 +3053,10 @@ Object.defineProperty(compile, "__esModule", { value: true });
|
|
|
2997
3053
|
compile.resolveSchema = compile.getCompilingSchema = compile.resolveRef = compile.compileSchema = compile.SchemaEnv = void 0;
|
|
2998
3054
|
const codegen_1$q = codegen;
|
|
2999
3055
|
const validation_error_1 = validation_error;
|
|
3000
|
-
const names_1$5 =
|
|
3056
|
+
const names_1$5 = requireNames();
|
|
3001
3057
|
const resolve_1 = resolve$2;
|
|
3002
3058
|
const util_1$o = util;
|
|
3003
|
-
const validate_1$1 =
|
|
3059
|
+
const validate_1$1 = requireValidate();
|
|
3004
3060
|
class SchemaEnv {
|
|
3005
3061
|
constructor(env) {
|
|
3006
3062
|
var _a;
|
|
@@ -3951,7 +4007,7 @@ uri$1.default = uri;
|
|
|
3951
4007
|
(function(exports2) {
|
|
3952
4008
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3953
4009
|
exports2.CodeGen = exports2.Name = exports2.nil = exports2.stringify = exports2.str = exports2._ = exports2.KeywordCxt = void 0;
|
|
3954
|
-
var validate_12 =
|
|
4010
|
+
var validate_12 = requireValidate();
|
|
3955
4011
|
Object.defineProperty(exports2, "KeywordCxt", { enumerable: true, get: function() {
|
|
3956
4012
|
return validate_12.KeywordCxt;
|
|
3957
4013
|
} });
|
|
@@ -4569,9 +4625,9 @@ var ref = {};
|
|
|
4569
4625
|
Object.defineProperty(ref, "__esModule", { value: true });
|
|
4570
4626
|
ref.callRef = ref.getValidate = void 0;
|
|
4571
4627
|
const ref_error_1$1 = ref_error;
|
|
4572
|
-
const code_1$8 =
|
|
4628
|
+
const code_1$8 = requireCode();
|
|
4573
4629
|
const codegen_1$p = codegen;
|
|
4574
|
-
const names_1$4 =
|
|
4630
|
+
const names_1$4 = requireNames();
|
|
4575
4631
|
const compile_1$2 = compile;
|
|
4576
4632
|
const util_1$n = util;
|
|
4577
4633
|
const def$A = {
|
|
@@ -4792,7 +4848,7 @@ const def$x = {
|
|
|
4792
4848
|
limitLength.default = def$x;
|
|
4793
4849
|
var pattern = {};
|
|
4794
4850
|
Object.defineProperty(pattern, "__esModule", { value: true });
|
|
4795
|
-
const code_1$7 =
|
|
4851
|
+
const code_1$7 = requireCode();
|
|
4796
4852
|
const codegen_1$l = codegen;
|
|
4797
4853
|
const error$h = {
|
|
4798
4854
|
message: ({ schemaCode }) => (0, codegen_1$l.str)`must match pattern "${schemaCode}"`,
|
|
@@ -4837,7 +4893,7 @@ const def$v = {
|
|
|
4837
4893
|
limitProperties.default = def$v;
|
|
4838
4894
|
var required = {};
|
|
4839
4895
|
Object.defineProperty(required, "__esModule", { value: true });
|
|
4840
|
-
const code_1$6 =
|
|
4896
|
+
const code_1$6 = requireCode();
|
|
4841
4897
|
const codegen_1$j = codegen;
|
|
4842
4898
|
const util_1$l = util;
|
|
4843
4899
|
const error$f = {
|
|
@@ -5151,7 +5207,7 @@ Object.defineProperty(items, "__esModule", { value: true });
|
|
|
5151
5207
|
items.validateTuple = void 0;
|
|
5152
5208
|
const codegen_1$d = codegen;
|
|
5153
5209
|
const util_1$g = util;
|
|
5154
|
-
const code_1$5 =
|
|
5210
|
+
const code_1$5 = requireCode();
|
|
5155
5211
|
const def$o = {
|
|
5156
5212
|
keyword: "items",
|
|
5157
5213
|
type: "array",
|
|
@@ -5211,7 +5267,7 @@ var items2020 = {};
|
|
|
5211
5267
|
Object.defineProperty(items2020, "__esModule", { value: true });
|
|
5212
5268
|
const codegen_1$c = codegen;
|
|
5213
5269
|
const util_1$f = util;
|
|
5214
|
-
const code_1$4 =
|
|
5270
|
+
const code_1$4 = requireCode();
|
|
5215
5271
|
const additionalItems_1$1 = additionalItems;
|
|
5216
5272
|
const error$9 = {
|
|
5217
5273
|
message: ({ params: { len } }) => (0, codegen_1$c.str)`must NOT have more than ${len} items`,
|
|
@@ -5330,7 +5386,7 @@ var dependencies = {};
|
|
|
5330
5386
|
exports2.validateSchemaDeps = exports2.validatePropertyDeps = exports2.error = void 0;
|
|
5331
5387
|
const codegen_12 = codegen;
|
|
5332
5388
|
const util_12 = util;
|
|
5333
|
-
const code_12 =
|
|
5389
|
+
const code_12 = requireCode();
|
|
5334
5390
|
exports2.error = {
|
|
5335
5391
|
message: ({ params: { property, depsCount, deps } }) => {
|
|
5336
5392
|
const property_ies = depsCount === 1 ? "property" : "properties";
|
|
@@ -5453,9 +5509,9 @@ const def$k = {
|
|
|
5453
5509
|
propertyNames.default = def$k;
|
|
5454
5510
|
var additionalProperties = {};
|
|
5455
5511
|
Object.defineProperty(additionalProperties, "__esModule", { value: true });
|
|
5456
|
-
const code_1$3 =
|
|
5512
|
+
const code_1$3 = requireCode();
|
|
5457
5513
|
const codegen_1$9 = codegen;
|
|
5458
|
-
const names_1$3 =
|
|
5514
|
+
const names_1$3 = requireNames();
|
|
5459
5515
|
const util_1$c = util;
|
|
5460
5516
|
const error$6 = {
|
|
5461
5517
|
message: "must NOT have additional properties",
|
|
@@ -5553,8 +5609,8 @@ const def$j = {
|
|
|
5553
5609
|
additionalProperties.default = def$j;
|
|
5554
5610
|
var properties$8 = {};
|
|
5555
5611
|
Object.defineProperty(properties$8, "__esModule", { value: true });
|
|
5556
|
-
const validate_1 =
|
|
5557
|
-
const code_1$2 =
|
|
5612
|
+
const validate_1 = requireValidate();
|
|
5613
|
+
const code_1$2 = requireCode();
|
|
5558
5614
|
const util_1$b = util;
|
|
5559
5615
|
const additionalProperties_1$1 = additionalProperties;
|
|
5560
5616
|
const def$i = {
|
|
@@ -5605,7 +5661,7 @@ const def$i = {
|
|
|
5605
5661
|
properties$8.default = def$i;
|
|
5606
5662
|
var patternProperties = {};
|
|
5607
5663
|
Object.defineProperty(patternProperties, "__esModule", { value: true });
|
|
5608
|
-
const code_1$1 =
|
|
5664
|
+
const code_1$1 = requireCode();
|
|
5609
5665
|
const codegen_1$8 = codegen;
|
|
5610
5666
|
const util_1$a = util;
|
|
5611
5667
|
const util_2 = util;
|
|
@@ -5698,7 +5754,7 @@ const def$g = {
|
|
|
5698
5754
|
not.default = def$g;
|
|
5699
5755
|
var anyOf = {};
|
|
5700
5756
|
Object.defineProperty(anyOf, "__esModule", { value: true });
|
|
5701
|
-
const code_1 =
|
|
5757
|
+
const code_1 = requireCode();
|
|
5702
5758
|
const def$f = {
|
|
5703
5759
|
keyword: "anyOf",
|
|
5704
5760
|
schemaType: "array",
|
|
@@ -5901,7 +5957,7 @@ var dynamicAnchor$1 = {};
|
|
|
5901
5957
|
Object.defineProperty(dynamicAnchor$1, "__esModule", { value: true });
|
|
5902
5958
|
dynamicAnchor$1.dynamicAnchor = void 0;
|
|
5903
5959
|
const codegen_1$5 = codegen;
|
|
5904
|
-
const names_1$2 =
|
|
5960
|
+
const names_1$2 = requireNames();
|
|
5905
5961
|
const compile_1$1 = compile;
|
|
5906
5962
|
const ref_1$1 = ref;
|
|
5907
5963
|
const def$a = {
|
|
@@ -5930,7 +5986,7 @@ var dynamicRef$1 = {};
|
|
|
5930
5986
|
Object.defineProperty(dynamicRef$1, "__esModule", { value: true });
|
|
5931
5987
|
dynamicRef$1.dynamicRef = void 0;
|
|
5932
5988
|
const codegen_1$4 = codegen;
|
|
5933
|
-
const names_1$1 =
|
|
5989
|
+
const names_1$1 = requireNames();
|
|
5934
5990
|
const ref_1 = ref;
|
|
5935
5991
|
const def$9 = {
|
|
5936
5992
|
keyword: "$dynamicRef",
|
|
@@ -6044,7 +6100,7 @@ var unevaluatedProperties = {};
|
|
|
6044
6100
|
Object.defineProperty(unevaluatedProperties, "__esModule", { value: true });
|
|
6045
6101
|
const codegen_1$3 = codegen;
|
|
6046
6102
|
const util_1$2 = util;
|
|
6047
|
-
const names_1 =
|
|
6103
|
+
const names_1 = requireNames();
|
|
6048
6104
|
const error$3 = {
|
|
6049
6105
|
message: "must NOT have unevaluated properties",
|
|
6050
6106
|
params: ({ params }) => (0, codegen_1$3._)`{unevaluatedProperty: ${params.unevaluatedProperty}}`
|
|
@@ -6960,7 +7016,7 @@ jsonSchema202012.default = addMetaSchema2020;
|
|
|
6960
7016
|
module2.exports.Ajv2020 = Ajv20202;
|
|
6961
7017
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
6962
7018
|
exports2.default = Ajv20202;
|
|
6963
|
-
var validate_12 =
|
|
7019
|
+
var validate_12 = requireValidate();
|
|
6964
7020
|
Object.defineProperty(exports2, "KeywordCxt", { enumerable: true, get: function() {
|
|
6965
7021
|
return validate_12.KeywordCxt;
|
|
6966
7022
|
} });
|