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