@opentiny/next-sdk 0.1.0-alpha.1 → 0.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +829 -865
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +829 -865
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +828 -864
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/vite.config.ts +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1019,8 +1019,8 @@ var scope = {};
|
|
|
1019
1019
|
var util$7 = {};
|
|
1020
1020
|
Object.defineProperty(util$7, "__esModule", { value: true });
|
|
1021
1021
|
util$7.checkStrictMode = util$7.getErrorPath = util$7.Type = util$7.useFunc = util$7.setEvaluated = util$7.evaluatedPropsToName = util$7.mergeEvaluated = util$7.eachItem = util$7.unescapeJsonPointer = util$7.escapeJsonPointer = util$7.escapeFragment = util$7.unescapeFragment = util$7.schemaRefOrVal = util$7.schemaHasRulesButRef = util$7.schemaHasRules = util$7.checkUnknownRules = util$7.alwaysValidSchema = util$7.toHash = void 0;
|
|
1022
|
-
const codegen_1$
|
|
1023
|
-
const code_1$
|
|
1022
|
+
const codegen_1$v = codegen;
|
|
1023
|
+
const code_1$a = code$1;
|
|
1024
1024
|
function toHash$2(arr) {
|
|
1025
1025
|
const hash = {};
|
|
1026
1026
|
for (const item of arr)
|
|
@@ -1073,9 +1073,9 @@ function schemaRefOrVal({ topSchemaRef, schemaPath }, schema, keyword2, $data) {
|
|
|
1073
1073
|
if (typeof schema == "number" || typeof schema == "boolean")
|
|
1074
1074
|
return schema;
|
|
1075
1075
|
if (typeof schema == "string")
|
|
1076
|
-
return (0, codegen_1$
|
|
1076
|
+
return (0, codegen_1$v._)`${schema}`;
|
|
1077
1077
|
}
|
|
1078
|
-
return (0, codegen_1$
|
|
1078
|
+
return (0, codegen_1$v._)`${topSchemaRef}${schemaPath}${(0, codegen_1$v.getProperty)(keyword2)}`;
|
|
1079
1079
|
}
|
|
1080
1080
|
util$7.schemaRefOrVal = schemaRefOrVal;
|
|
1081
1081
|
function unescapeFragment$1(str) {
|
|
@@ -1107,20 +1107,20 @@ function eachItem(xs, f) {
|
|
|
1107
1107
|
util$7.eachItem = eachItem;
|
|
1108
1108
|
function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues: mergeValues2, resultToName }) {
|
|
1109
1109
|
return (gen, from, to, toName) => {
|
|
1110
|
-
const res = to === void 0 ? from : to instanceof codegen_1$
|
|
1111
|
-
return toName === codegen_1$
|
|
1110
|
+
const res = to === void 0 ? from : to instanceof codegen_1$v.Name ? (from instanceof codegen_1$v.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1$v.Name ? (mergeToName(gen, to, from), from) : mergeValues2(from, to);
|
|
1111
|
+
return toName === codegen_1$v.Name && !(res instanceof codegen_1$v.Name) ? resultToName(gen, res) : res;
|
|
1112
1112
|
};
|
|
1113
1113
|
}
|
|
1114
1114
|
util$7.mergeEvaluated = {
|
|
1115
1115
|
props: makeMergeEvaluated({
|
|
1116
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
1117
|
-
gen.if((0, codegen_1$
|
|
1116
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$v._)`${to} !== true && ${from} !== undefined`, () => {
|
|
1117
|
+
gen.if((0, codegen_1$v._)`${from} === true`, () => gen.assign(to, true), () => gen.assign(to, (0, codegen_1$v._)`${to} || {}`).code((0, codegen_1$v._)`Object.assign(${to}, ${from})`));
|
|
1118
1118
|
}),
|
|
1119
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
1119
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$v._)`${to} !== true`, () => {
|
|
1120
1120
|
if (from === true) {
|
|
1121
1121
|
gen.assign(to, true);
|
|
1122
1122
|
} else {
|
|
1123
|
-
gen.assign(to, (0, codegen_1$
|
|
1123
|
+
gen.assign(to, (0, codegen_1$v._)`${to} || {}`);
|
|
1124
1124
|
setEvaluated(gen, to, from);
|
|
1125
1125
|
}
|
|
1126
1126
|
}),
|
|
@@ -1128,8 +1128,8 @@ util$7.mergeEvaluated = {
|
|
|
1128
1128
|
resultToName: evaluatedPropsToName
|
|
1129
1129
|
}),
|
|
1130
1130
|
items: makeMergeEvaluated({
|
|
1131
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
1132
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
1131
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$v._)`${to} !== true && ${from} !== undefined`, () => gen.assign(to, (0, codegen_1$v._)`${from} === true ? true : ${to} > ${from} ? ${to} : ${from}`)),
|
|
1132
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$v._)`${to} !== true`, () => gen.assign(to, from === true ? true : (0, codegen_1$v._)`${to} > ${from} ? ${to} : ${from}`)),
|
|
1133
1133
|
mergeValues: (from, to) => from === true ? true : Math.max(from, to),
|
|
1134
1134
|
resultToName: (gen, items2) => gen.var("items", items2)
|
|
1135
1135
|
})
|
|
@@ -1137,21 +1137,21 @@ util$7.mergeEvaluated = {
|
|
|
1137
1137
|
function evaluatedPropsToName(gen, ps) {
|
|
1138
1138
|
if (ps === true)
|
|
1139
1139
|
return gen.var("props", true);
|
|
1140
|
-
const props = gen.var("props", (0, codegen_1$
|
|
1140
|
+
const props = gen.var("props", (0, codegen_1$v._)`{}`);
|
|
1141
1141
|
if (ps !== void 0)
|
|
1142
1142
|
setEvaluated(gen, props, ps);
|
|
1143
1143
|
return props;
|
|
1144
1144
|
}
|
|
1145
1145
|
util$7.evaluatedPropsToName = evaluatedPropsToName;
|
|
1146
1146
|
function setEvaluated(gen, props, ps) {
|
|
1147
|
-
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$
|
|
1147
|
+
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$v._)`${props}${(0, codegen_1$v.getProperty)(p)}`, true));
|
|
1148
1148
|
}
|
|
1149
1149
|
util$7.setEvaluated = setEvaluated;
|
|
1150
1150
|
const snippets = {};
|
|
1151
1151
|
function useFunc(gen, f) {
|
|
1152
1152
|
return gen.scopeValue("func", {
|
|
1153
1153
|
ref: f,
|
|
1154
|
-
code: snippets[f.code] || (snippets[f.code] = new code_1$
|
|
1154
|
+
code: snippets[f.code] || (snippets[f.code] = new code_1$a._Code(f.code))
|
|
1155
1155
|
});
|
|
1156
1156
|
}
|
|
1157
1157
|
util$7.useFunc = useFunc;
|
|
@@ -1161,11 +1161,11 @@ var Type;
|
|
|
1161
1161
|
Type2[Type2["Str"] = 1] = "Str";
|
|
1162
1162
|
})(Type || (util$7.Type = Type = {}));
|
|
1163
1163
|
function getErrorPath(dataProp, dataPropType, jsPropertySyntax) {
|
|
1164
|
-
if (dataProp instanceof codegen_1$
|
|
1164
|
+
if (dataProp instanceof codegen_1$v.Name) {
|
|
1165
1165
|
const isNumber = dataPropType === Type.Num;
|
|
1166
|
-
return jsPropertySyntax ? isNumber ? (0, codegen_1$
|
|
1166
|
+
return jsPropertySyntax ? isNumber ? (0, codegen_1$v._)`"[" + ${dataProp} + "]"` : (0, codegen_1$v._)`"['" + ${dataProp} + "']"` : isNumber ? (0, codegen_1$v._)`"/" + ${dataProp}` : (0, codegen_1$v._)`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")`;
|
|
1167
1167
|
}
|
|
1168
|
-
return jsPropertySyntax ? (0, codegen_1$
|
|
1168
|
+
return jsPropertySyntax ? (0, codegen_1$v.getProperty)(dataProp).toString() : "/" + escapeJsonPointer$1(dataProp);
|
|
1169
1169
|
}
|
|
1170
1170
|
util$7.getErrorPath = getErrorPath;
|
|
1171
1171
|
function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
@@ -1179,35 +1179,35 @@ function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
|
1179
1179
|
util$7.checkStrictMode = checkStrictMode;
|
|
1180
1180
|
var names$1 = {};
|
|
1181
1181
|
Object.defineProperty(names$1, "__esModule", { value: true });
|
|
1182
|
-
const codegen_1$
|
|
1182
|
+
const codegen_1$u = codegen;
|
|
1183
1183
|
const names = {
|
|
1184
1184
|
// validation function arguments
|
|
1185
|
-
data: new codegen_1$
|
|
1185
|
+
data: new codegen_1$u.Name("data"),
|
|
1186
1186
|
// data passed to validation function
|
|
1187
1187
|
// args passed from referencing schema
|
|
1188
|
-
valCxt: new codegen_1$
|
|
1188
|
+
valCxt: new codegen_1$u.Name("valCxt"),
|
|
1189
1189
|
// validation/data context - should not be used directly, it is destructured to the names below
|
|
1190
|
-
instancePath: new codegen_1$
|
|
1191
|
-
parentData: new codegen_1$
|
|
1192
|
-
parentDataProperty: new codegen_1$
|
|
1193
|
-
rootData: new codegen_1$
|
|
1190
|
+
instancePath: new codegen_1$u.Name("instancePath"),
|
|
1191
|
+
parentData: new codegen_1$u.Name("parentData"),
|
|
1192
|
+
parentDataProperty: new codegen_1$u.Name("parentDataProperty"),
|
|
1193
|
+
rootData: new codegen_1$u.Name("rootData"),
|
|
1194
1194
|
// root data - same as the data passed to the first/top validation function
|
|
1195
|
-
dynamicAnchors: new codegen_1$
|
|
1195
|
+
dynamicAnchors: new codegen_1$u.Name("dynamicAnchors"),
|
|
1196
1196
|
// used to support recursiveRef and dynamicRef
|
|
1197
1197
|
// function scoped variables
|
|
1198
|
-
vErrors: new codegen_1$
|
|
1198
|
+
vErrors: new codegen_1$u.Name("vErrors"),
|
|
1199
1199
|
// null or array of validation errors
|
|
1200
|
-
errors: new codegen_1$
|
|
1200
|
+
errors: new codegen_1$u.Name("errors"),
|
|
1201
1201
|
// counter of validation errors
|
|
1202
|
-
this: new codegen_1$
|
|
1202
|
+
this: new codegen_1$u.Name("this"),
|
|
1203
1203
|
// "globals"
|
|
1204
|
-
self: new codegen_1$
|
|
1205
|
-
scope: new codegen_1$
|
|
1204
|
+
self: new codegen_1$u.Name("self"),
|
|
1205
|
+
scope: new codegen_1$u.Name("scope"),
|
|
1206
1206
|
// JTD serialize/parse name for JSON string and position
|
|
1207
|
-
json: new codegen_1$
|
|
1208
|
-
jsonPos: new codegen_1$
|
|
1209
|
-
jsonLen: new codegen_1$
|
|
1210
|
-
jsonPart: new codegen_1$
|
|
1207
|
+
json: new codegen_1$u.Name("json"),
|
|
1208
|
+
jsonPos: new codegen_1$u.Name("jsonPos"),
|
|
1209
|
+
jsonLen: new codegen_1$u.Name("jsonLen"),
|
|
1210
|
+
jsonPart: new codegen_1$u.Name("jsonPart")
|
|
1211
1211
|
};
|
|
1212
1212
|
names$1.default = names;
|
|
1213
1213
|
(function(exports2) {
|
|
@@ -1327,55 +1327,49 @@ names$1.default = names;
|
|
|
1327
1327
|
keyValues.push([E.propertyName, propertyName]);
|
|
1328
1328
|
}
|
|
1329
1329
|
})(errors);
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
const
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
gen.return(names_12.default.data);
|
|
1348
|
-
} else {
|
|
1349
|
-
gen.assign((0, codegen_12._)`${validateName}.errors`, null);
|
|
1350
|
-
gen.return(true);
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
boolSchema.topBoolOrEmptySchema = topBoolOrEmptySchema;
|
|
1354
|
-
function boolOrEmptySchema(it, valid) {
|
|
1355
|
-
const { gen, schema } = it;
|
|
1356
|
-
if (schema === false) {
|
|
1357
|
-
gen.var(valid, false);
|
|
1358
|
-
falseSchemaError(it);
|
|
1359
|
-
} else {
|
|
1360
|
-
gen.var(valid, true);
|
|
1361
|
-
}
|
|
1330
|
+
Object.defineProperty(boolSchema, "__esModule", { value: true });
|
|
1331
|
+
boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
|
|
1332
|
+
const errors_1$3 = errors;
|
|
1333
|
+
const codegen_1$t = codegen;
|
|
1334
|
+
const names_1$6 = names$1;
|
|
1335
|
+
const boolError = {
|
|
1336
|
+
message: "boolean schema is false"
|
|
1337
|
+
};
|
|
1338
|
+
function topBoolOrEmptySchema(it) {
|
|
1339
|
+
const { gen, schema, validateName } = it;
|
|
1340
|
+
if (schema === false) {
|
|
1341
|
+
falseSchemaError(it, false);
|
|
1342
|
+
} else if (typeof schema == "object" && schema.$async === true) {
|
|
1343
|
+
gen.return(names_1$6.default.data);
|
|
1344
|
+
} else {
|
|
1345
|
+
gen.assign((0, codegen_1$t._)`${validateName}.errors`, null);
|
|
1346
|
+
gen.return(true);
|
|
1362
1347
|
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
schemaValue: false,
|
|
1373
|
-
params: {},
|
|
1374
|
-
it
|
|
1375
|
-
};
|
|
1376
|
-
(0, errors_12.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
1348
|
+
}
|
|
1349
|
+
boolSchema.topBoolOrEmptySchema = topBoolOrEmptySchema;
|
|
1350
|
+
function boolOrEmptySchema(it, valid) {
|
|
1351
|
+
const { gen, schema } = it;
|
|
1352
|
+
if (schema === false) {
|
|
1353
|
+
gen.var(valid, false);
|
|
1354
|
+
falseSchemaError(it);
|
|
1355
|
+
} else {
|
|
1356
|
+
gen.var(valid, true);
|
|
1377
1357
|
}
|
|
1378
|
-
|
|
1358
|
+
}
|
|
1359
|
+
boolSchema.boolOrEmptySchema = boolOrEmptySchema;
|
|
1360
|
+
function falseSchemaError(it, overrideAllErrors) {
|
|
1361
|
+
const { gen, data: data2 } = it;
|
|
1362
|
+
const cxt = {
|
|
1363
|
+
gen,
|
|
1364
|
+
keyword: "false schema",
|
|
1365
|
+
data: data2,
|
|
1366
|
+
schema: false,
|
|
1367
|
+
schemaCode: false,
|
|
1368
|
+
schemaValue: false,
|
|
1369
|
+
params: {},
|
|
1370
|
+
it
|
|
1371
|
+
};
|
|
1372
|
+
(0, errors_1$3.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
1379
1373
|
}
|
|
1380
1374
|
var dataType = {};
|
|
1381
1375
|
var rules$2 = {};
|
|
@@ -1423,10 +1417,10 @@ applicability.shouldUseRule = shouldUseRule;
|
|
|
1423
1417
|
Object.defineProperty(dataType, "__esModule", { value: true });
|
|
1424
1418
|
dataType.reportTypeError = dataType.checkDataTypes = dataType.checkDataType = dataType.coerceAndCheckDataType = dataType.getJSONTypes = dataType.getSchemaTypes = dataType.DataType = void 0;
|
|
1425
1419
|
const rules_1 = rules$2;
|
|
1426
|
-
const applicability_1 = applicability;
|
|
1427
|
-
const errors_1 = errors;
|
|
1428
|
-
const codegen_1$
|
|
1429
|
-
const util_1$
|
|
1420
|
+
const applicability_1$1 = applicability;
|
|
1421
|
+
const errors_1$2 = errors;
|
|
1422
|
+
const codegen_1$s = codegen;
|
|
1423
|
+
const util_1$q = util$7;
|
|
1430
1424
|
var DataType;
|
|
1431
1425
|
(function(DataType2) {
|
|
1432
1426
|
DataType2[DataType2["Correct"] = 0] = "Correct";
|
|
@@ -1458,7 +1452,7 @@ dataType.getJSONTypes = getJSONTypes;
|
|
|
1458
1452
|
function coerceAndCheckDataType(it, types2) {
|
|
1459
1453
|
const { gen, data: data2, opts } = it;
|
|
1460
1454
|
const coerceTo = coerceToTypes$1(types2, opts.coerceTypes);
|
|
1461
|
-
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1.schemaHasRulesForType)(it, types2[0]));
|
|
1455
|
+
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1$1.schemaHasRulesForType)(it, types2[0]));
|
|
1462
1456
|
if (checkTypes) {
|
|
1463
1457
|
const wrongType = checkDataTypes$1(types2, data2, opts.strictNumbers, DataType.Wrong);
|
|
1464
1458
|
gen.if(wrongType, () => {
|
|
@@ -1477,12 +1471,12 @@ function coerceToTypes$1(types2, coerceTypes) {
|
|
|
1477
1471
|
}
|
|
1478
1472
|
function coerceData(it, types2, coerceTo) {
|
|
1479
1473
|
const { gen, data: data2, opts } = it;
|
|
1480
|
-
const dataType2 = gen.let("dataType", (0, codegen_1$
|
|
1481
|
-
const coerced = gen.let("coerced", (0, codegen_1$
|
|
1474
|
+
const dataType2 = gen.let("dataType", (0, codegen_1$s._)`typeof ${data2}`);
|
|
1475
|
+
const coerced = gen.let("coerced", (0, codegen_1$s._)`undefined`);
|
|
1482
1476
|
if (opts.coerceTypes === "array") {
|
|
1483
|
-
gen.if((0, codegen_1$
|
|
1477
|
+
gen.if((0, codegen_1$s._)`${dataType2} == 'object' && Array.isArray(${data2}) && ${data2}.length == 1`, () => gen.assign(data2, (0, codegen_1$s._)`${data2}[0]`).assign(dataType2, (0, codegen_1$s._)`typeof ${data2}`).if(checkDataTypes$1(types2, data2, opts.strictNumbers), () => gen.assign(coerced, data2)));
|
|
1484
1478
|
}
|
|
1485
|
-
gen.if((0, codegen_1$
|
|
1479
|
+
gen.if((0, codegen_1$s._)`${coerced} !== undefined`);
|
|
1486
1480
|
for (const t of coerceTo) {
|
|
1487
1481
|
if (COERCIBLE.has(t) || t === "array" && opts.coerceTypes === "array") {
|
|
1488
1482
|
coerceSpecificType(t);
|
|
@@ -1491,63 +1485,63 @@ function coerceData(it, types2, coerceTo) {
|
|
|
1491
1485
|
gen.else();
|
|
1492
1486
|
reportTypeError(it);
|
|
1493
1487
|
gen.endIf();
|
|
1494
|
-
gen.if((0, codegen_1$
|
|
1488
|
+
gen.if((0, codegen_1$s._)`${coerced} !== undefined`, () => {
|
|
1495
1489
|
gen.assign(data2, coerced);
|
|
1496
1490
|
assignParentData(it, coerced);
|
|
1497
1491
|
});
|
|
1498
1492
|
function coerceSpecificType(t) {
|
|
1499
1493
|
switch (t) {
|
|
1500
1494
|
case "string":
|
|
1501
|
-
gen.elseIf((0, codegen_1$
|
|
1495
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} == "number" || ${dataType2} == "boolean"`).assign(coerced, (0, codegen_1$s._)`"" + ${data2}`).elseIf((0, codegen_1$s._)`${data2} === null`).assign(coerced, (0, codegen_1$s._)`""`);
|
|
1502
1496
|
return;
|
|
1503
1497
|
case "number":
|
|
1504
|
-
gen.elseIf((0, codegen_1$
|
|
1505
|
-
|| (${dataType2} == "string" && ${data2} && ${data2} == +${data2})`).assign(coerced, (0, codegen_1$
|
|
1498
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} == "boolean" || ${data2} === null
|
|
1499
|
+
|| (${dataType2} == "string" && ${data2} && ${data2} == +${data2})`).assign(coerced, (0, codegen_1$s._)`+${data2}`);
|
|
1506
1500
|
return;
|
|
1507
1501
|
case "integer":
|
|
1508
|
-
gen.elseIf((0, codegen_1$
|
|
1509
|
-
|| (${dataType2} === "string" && ${data2} && ${data2} == +${data2} && !(${data2} % 1))`).assign(coerced, (0, codegen_1$
|
|
1502
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} === "boolean" || ${data2} === null
|
|
1503
|
+
|| (${dataType2} === "string" && ${data2} && ${data2} == +${data2} && !(${data2} % 1))`).assign(coerced, (0, codegen_1$s._)`+${data2}`);
|
|
1510
1504
|
return;
|
|
1511
1505
|
case "boolean":
|
|
1512
|
-
gen.elseIf((0, codegen_1$
|
|
1506
|
+
gen.elseIf((0, codegen_1$s._)`${data2} === "false" || ${data2} === 0 || ${data2} === null`).assign(coerced, false).elseIf((0, codegen_1$s._)`${data2} === "true" || ${data2} === 1`).assign(coerced, true);
|
|
1513
1507
|
return;
|
|
1514
1508
|
case "null":
|
|
1515
|
-
gen.elseIf((0, codegen_1$
|
|
1509
|
+
gen.elseIf((0, codegen_1$s._)`${data2} === "" || ${data2} === 0 || ${data2} === false`);
|
|
1516
1510
|
gen.assign(coerced, null);
|
|
1517
1511
|
return;
|
|
1518
1512
|
case "array":
|
|
1519
|
-
gen.elseIf((0, codegen_1$
|
|
1520
|
-
|| ${dataType2} === "boolean" || ${data2} === null`).assign(coerced, (0, codegen_1$
|
|
1513
|
+
gen.elseIf((0, codegen_1$s._)`${dataType2} === "string" || ${dataType2} === "number"
|
|
1514
|
+
|| ${dataType2} === "boolean" || ${data2} === null`).assign(coerced, (0, codegen_1$s._)`[${data2}]`);
|
|
1521
1515
|
}
|
|
1522
1516
|
}
|
|
1523
1517
|
}
|
|
1524
1518
|
function assignParentData({ gen, parentData, parentDataProperty }, expr) {
|
|
1525
|
-
gen.if((0, codegen_1$
|
|
1519
|
+
gen.if((0, codegen_1$s._)`${parentData} !== undefined`, () => gen.assign((0, codegen_1$s._)`${parentData}[${parentDataProperty}]`, expr));
|
|
1526
1520
|
}
|
|
1527
1521
|
function checkDataType$1(dataType2, data2, strictNums, correct = DataType.Correct) {
|
|
1528
|
-
const EQ = correct === DataType.Correct ? codegen_1$
|
|
1522
|
+
const EQ = correct === DataType.Correct ? codegen_1$s.operators.EQ : codegen_1$s.operators.NEQ;
|
|
1529
1523
|
let cond;
|
|
1530
1524
|
switch (dataType2) {
|
|
1531
1525
|
case "null":
|
|
1532
|
-
return (0, codegen_1$
|
|
1526
|
+
return (0, codegen_1$s._)`${data2} ${EQ} null`;
|
|
1533
1527
|
case "array":
|
|
1534
|
-
cond = (0, codegen_1$
|
|
1528
|
+
cond = (0, codegen_1$s._)`Array.isArray(${data2})`;
|
|
1535
1529
|
break;
|
|
1536
1530
|
case "object":
|
|
1537
|
-
cond = (0, codegen_1$
|
|
1531
|
+
cond = (0, codegen_1$s._)`${data2} && typeof ${data2} == "object" && !Array.isArray(${data2})`;
|
|
1538
1532
|
break;
|
|
1539
1533
|
case "integer":
|
|
1540
|
-
cond = numCond((0, codegen_1$
|
|
1534
|
+
cond = numCond((0, codegen_1$s._)`!(${data2} % 1) && !isNaN(${data2})`);
|
|
1541
1535
|
break;
|
|
1542
1536
|
case "number":
|
|
1543
1537
|
cond = numCond();
|
|
1544
1538
|
break;
|
|
1545
1539
|
default:
|
|
1546
|
-
return (0, codegen_1$
|
|
1540
|
+
return (0, codegen_1$s._)`typeof ${data2} ${EQ} ${dataType2}`;
|
|
1547
1541
|
}
|
|
1548
|
-
return correct === DataType.Correct ? cond : (0, codegen_1$
|
|
1549
|
-
function numCond(_cond = codegen_1$
|
|
1550
|
-
return (0, codegen_1$
|
|
1542
|
+
return correct === DataType.Correct ? cond : (0, codegen_1$s.not)(cond);
|
|
1543
|
+
function numCond(_cond = codegen_1$s.nil) {
|
|
1544
|
+
return (0, codegen_1$s.and)((0, codegen_1$s._)`typeof ${data2} == "number"`, _cond, strictNums ? (0, codegen_1$s._)`isFinite(${data2})` : codegen_1$s.nil);
|
|
1551
1545
|
}
|
|
1552
1546
|
}
|
|
1553
1547
|
dataType.checkDataType = checkDataType$1;
|
|
@@ -1556,35 +1550,35 @@ function checkDataTypes$1(dataTypes, data2, strictNums, correct) {
|
|
|
1556
1550
|
return checkDataType$1(dataTypes[0], data2, strictNums, correct);
|
|
1557
1551
|
}
|
|
1558
1552
|
let cond;
|
|
1559
|
-
const types2 = (0, util_1$
|
|
1553
|
+
const types2 = (0, util_1$q.toHash)(dataTypes);
|
|
1560
1554
|
if (types2.array && types2.object) {
|
|
1561
|
-
const notObj = (0, codegen_1$
|
|
1562
|
-
cond = types2.null ? notObj : (0, codegen_1$
|
|
1555
|
+
const notObj = (0, codegen_1$s._)`typeof ${data2} != "object"`;
|
|
1556
|
+
cond = types2.null ? notObj : (0, codegen_1$s._)`!${data2} || ${notObj}`;
|
|
1563
1557
|
delete types2.null;
|
|
1564
1558
|
delete types2.array;
|
|
1565
1559
|
delete types2.object;
|
|
1566
1560
|
} else {
|
|
1567
|
-
cond = codegen_1$
|
|
1561
|
+
cond = codegen_1$s.nil;
|
|
1568
1562
|
}
|
|
1569
1563
|
if (types2.number)
|
|
1570
1564
|
delete types2.integer;
|
|
1571
1565
|
for (const t in types2)
|
|
1572
|
-
cond = (0, codegen_1$
|
|
1566
|
+
cond = (0, codegen_1$s.and)(cond, checkDataType$1(t, data2, strictNums, correct));
|
|
1573
1567
|
return cond;
|
|
1574
1568
|
}
|
|
1575
1569
|
dataType.checkDataTypes = checkDataTypes$1;
|
|
1576
1570
|
const typeError = {
|
|
1577
1571
|
message: ({ schema }) => `must be ${schema}`,
|
|
1578
|
-
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$
|
|
1572
|
+
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$s._)`{type: ${schema}}` : (0, codegen_1$s._)`{type: ${schemaValue}}`
|
|
1579
1573
|
};
|
|
1580
1574
|
function reportTypeError(it) {
|
|
1581
1575
|
const cxt = getTypeErrorContext(it);
|
|
1582
|
-
(0, errors_1.reportError)(cxt, typeError);
|
|
1576
|
+
(0, errors_1$2.reportError)(cxt, typeError);
|
|
1583
1577
|
}
|
|
1584
1578
|
dataType.reportTypeError = reportTypeError;
|
|
1585
1579
|
function getTypeErrorContext(it) {
|
|
1586
1580
|
const { gen, data: data2, schema } = it;
|
|
1587
|
-
const schemaCode = (0, util_1$
|
|
1581
|
+
const schemaCode = (0, util_1$q.schemaRefOrVal)(it, schema, "type");
|
|
1588
1582
|
return {
|
|
1589
1583
|
gen,
|
|
1590
1584
|
keyword: "type",
|
|
@@ -1598,60 +1592,54 @@ function getTypeErrorContext(it) {
|
|
|
1598
1592
|
};
|
|
1599
1593
|
}
|
|
1600
1594
|
var defaults = {};
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1595
|
+
Object.defineProperty(defaults, "__esModule", { value: true });
|
|
1596
|
+
defaults.assignDefaults = void 0;
|
|
1597
|
+
const codegen_1$r = codegen;
|
|
1598
|
+
const util_1$p = util$7;
|
|
1599
|
+
function assignDefaults(it, ty) {
|
|
1600
|
+
const { properties: properties2, items: items2 } = it.schema;
|
|
1601
|
+
if (ty === "object" && properties2) {
|
|
1602
|
+
for (const key in properties2) {
|
|
1603
|
+
assignDefault(it, key, properties2[key].default);
|
|
1604
|
+
}
|
|
1605
|
+
} else if (ty === "array" && Array.isArray(items2)) {
|
|
1606
|
+
items2.forEach((sch, i) => assignDefault(it, i, sch.default));
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
defaults.assignDefaults = assignDefaults;
|
|
1610
|
+
function assignDefault(it, prop, defaultValue) {
|
|
1611
|
+
const { gen, compositeRule, data: data2, opts } = it;
|
|
1612
|
+
if (defaultValue === void 0)
|
|
1613
|
+
return;
|
|
1614
|
+
const childData = (0, codegen_1$r._)`${data2}${(0, codegen_1$r.getProperty)(prop)}`;
|
|
1615
|
+
if (compositeRule) {
|
|
1616
|
+
(0, util_1$p.checkStrictMode)(it, `default is ignored for: ${childData}`);
|
|
1617
|
+
return;
|
|
1618
1618
|
}
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
if (defaultValue === void 0)
|
|
1623
|
-
return;
|
|
1624
|
-
const childData = (0, codegen_12._)`${data2}${(0, codegen_12.getProperty)(prop)}`;
|
|
1625
|
-
if (compositeRule) {
|
|
1626
|
-
(0, util_12.checkStrictMode)(it, `default is ignored for: ${childData}`);
|
|
1627
|
-
return;
|
|
1628
|
-
}
|
|
1629
|
-
let condition = (0, codegen_12._)`${childData} === undefined`;
|
|
1630
|
-
if (opts.useDefaults === "empty") {
|
|
1631
|
-
condition = (0, codegen_12._)`${condition} || ${childData} === null || ${childData} === ""`;
|
|
1632
|
-
}
|
|
1633
|
-
gen.if(condition, (0, codegen_12._)`${childData} = ${(0, codegen_12.stringify)(defaultValue)}`);
|
|
1619
|
+
let condition = (0, codegen_1$r._)`${childData} === undefined`;
|
|
1620
|
+
if (opts.useDefaults === "empty") {
|
|
1621
|
+
condition = (0, codegen_1$r._)`${condition} || ${childData} === null || ${childData} === ""`;
|
|
1634
1622
|
}
|
|
1635
|
-
|
|
1623
|
+
gen.if(condition, (0, codegen_1$r._)`${childData} = ${(0, codegen_1$r.stringify)(defaultValue)}`);
|
|
1636
1624
|
}
|
|
1637
1625
|
var keyword$1 = {};
|
|
1638
1626
|
var code = {};
|
|
1639
1627
|
Object.defineProperty(code, "__esModule", { value: true });
|
|
1640
1628
|
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;
|
|
1641
|
-
const codegen_1$
|
|
1642
|
-
const util_1$
|
|
1643
|
-
const names_1$
|
|
1629
|
+
const codegen_1$q = codegen;
|
|
1630
|
+
const util_1$o = util$7;
|
|
1631
|
+
const names_1$5 = names$1;
|
|
1644
1632
|
const util_2$1 = util$7;
|
|
1645
1633
|
function checkReportMissingProp(cxt, prop) {
|
|
1646
1634
|
const { gen, data: data2, it } = cxt;
|
|
1647
1635
|
gen.if(noPropertyInData(gen, data2, prop, it.opts.ownProperties), () => {
|
|
1648
|
-
cxt.setParams({ missingProperty: (0, codegen_1$
|
|
1636
|
+
cxt.setParams({ missingProperty: (0, codegen_1$q._)`${prop}` }, true);
|
|
1649
1637
|
cxt.error();
|
|
1650
1638
|
});
|
|
1651
1639
|
}
|
|
1652
1640
|
code.checkReportMissingProp = checkReportMissingProp;
|
|
1653
1641
|
function checkMissingProp({ gen, data: data2, it: { opts } }, properties2, missing) {
|
|
1654
|
-
return (0, codegen_1$
|
|
1642
|
+
return (0, codegen_1$q.or)(...properties2.map((prop) => (0, codegen_1$q.and)(noPropertyInData(gen, data2, prop, opts.ownProperties), (0, codegen_1$q._)`${missing} = ${prop}`)));
|
|
1655
1643
|
}
|
|
1656
1644
|
code.checkMissingProp = checkMissingProp;
|
|
1657
1645
|
function reportMissingProp(cxt, missing) {
|
|
@@ -1663,22 +1651,22 @@ function hasPropFunc(gen) {
|
|
|
1663
1651
|
return gen.scopeValue("func", {
|
|
1664
1652
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
1665
1653
|
ref: Object.prototype.hasOwnProperty,
|
|
1666
|
-
code: (0, codegen_1$
|
|
1654
|
+
code: (0, codegen_1$q._)`Object.prototype.hasOwnProperty`
|
|
1667
1655
|
});
|
|
1668
1656
|
}
|
|
1669
1657
|
code.hasPropFunc = hasPropFunc;
|
|
1670
1658
|
function isOwnProperty(gen, data2, property) {
|
|
1671
|
-
return (0, codegen_1$
|
|
1659
|
+
return (0, codegen_1$q._)`${hasPropFunc(gen)}.call(${data2}, ${property})`;
|
|
1672
1660
|
}
|
|
1673
1661
|
code.isOwnProperty = isOwnProperty;
|
|
1674
1662
|
function propertyInData(gen, data2, property, ownProperties) {
|
|
1675
|
-
const cond = (0, codegen_1$
|
|
1676
|
-
return ownProperties ? (0, codegen_1$
|
|
1663
|
+
const cond = (0, codegen_1$q._)`${data2}${(0, codegen_1$q.getProperty)(property)} !== undefined`;
|
|
1664
|
+
return ownProperties ? (0, codegen_1$q._)`${cond} && ${isOwnProperty(gen, data2, property)}` : cond;
|
|
1677
1665
|
}
|
|
1678
1666
|
code.propertyInData = propertyInData;
|
|
1679
1667
|
function noPropertyInData(gen, data2, property, ownProperties) {
|
|
1680
|
-
const cond = (0, codegen_1$
|
|
1681
|
-
return ownProperties ? (0, codegen_1$
|
|
1668
|
+
const cond = (0, codegen_1$q._)`${data2}${(0, codegen_1$q.getProperty)(property)} === undefined`;
|
|
1669
|
+
return ownProperties ? (0, codegen_1$q.or)(cond, (0, codegen_1$q.not)(isOwnProperty(gen, data2, property))) : cond;
|
|
1682
1670
|
}
|
|
1683
1671
|
code.noPropertyInData = noPropertyInData;
|
|
1684
1672
|
function allSchemaProperties(schemaMap) {
|
|
@@ -1686,24 +1674,24 @@ function allSchemaProperties(schemaMap) {
|
|
|
1686
1674
|
}
|
|
1687
1675
|
code.allSchemaProperties = allSchemaProperties;
|
|
1688
1676
|
function schemaProperties(it, schemaMap) {
|
|
1689
|
-
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$
|
|
1677
|
+
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$o.alwaysValidSchema)(it, schemaMap[p]));
|
|
1690
1678
|
}
|
|
1691
1679
|
code.schemaProperties = schemaProperties;
|
|
1692
1680
|
function callValidateCode({ schemaCode, data: data2, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context, passSchema) {
|
|
1693
|
-
const dataAndSchema = passSchema ? (0, codegen_1$
|
|
1681
|
+
const dataAndSchema = passSchema ? (0, codegen_1$q._)`${schemaCode}, ${data2}, ${topSchemaRef}${schemaPath}` : data2;
|
|
1694
1682
|
const valCxt = [
|
|
1695
|
-
[names_1$
|
|
1696
|
-
[names_1$
|
|
1697
|
-
[names_1$
|
|
1698
|
-
[names_1$
|
|
1683
|
+
[names_1$5.default.instancePath, (0, codegen_1$q.strConcat)(names_1$5.default.instancePath, errorPath)],
|
|
1684
|
+
[names_1$5.default.parentData, it.parentData],
|
|
1685
|
+
[names_1$5.default.parentDataProperty, it.parentDataProperty],
|
|
1686
|
+
[names_1$5.default.rootData, names_1$5.default.rootData]
|
|
1699
1687
|
];
|
|
1700
1688
|
if (it.opts.dynamicRef)
|
|
1701
|
-
valCxt.push([names_1$
|
|
1702
|
-
const args = (0, codegen_1$
|
|
1703
|
-
return context !== codegen_1$
|
|
1689
|
+
valCxt.push([names_1$5.default.dynamicAnchors, names_1$5.default.dynamicAnchors]);
|
|
1690
|
+
const args = (0, codegen_1$q._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
|
|
1691
|
+
return context !== codegen_1$q.nil ? (0, codegen_1$q._)`${func}.call(${context}, ${args})` : (0, codegen_1$q._)`${func}(${args})`;
|
|
1704
1692
|
}
|
|
1705
1693
|
code.callValidateCode = callValidateCode;
|
|
1706
|
-
const newRegExp = (0, codegen_1$
|
|
1694
|
+
const newRegExp = (0, codegen_1$q._)`new RegExp`;
|
|
1707
1695
|
function usePattern({ gen, it: { opts } }, pattern2) {
|
|
1708
1696
|
const u = opts.unicodeRegExp ? "u" : "";
|
|
1709
1697
|
const { regExp } = opts.code;
|
|
@@ -1711,7 +1699,7 @@ function usePattern({ gen, it: { opts } }, pattern2) {
|
|
|
1711
1699
|
return gen.scopeValue("pattern", {
|
|
1712
1700
|
key: rx.toString(),
|
|
1713
1701
|
ref: rx,
|
|
1714
|
-
code: (0, codegen_1$
|
|
1702
|
+
code: (0, codegen_1$q._)`${regExp.code === "new RegExp" ? newRegExp : (0, util_2$1.useFunc)(gen, regExp)}(${pattern2}, ${u})`
|
|
1715
1703
|
});
|
|
1716
1704
|
}
|
|
1717
1705
|
code.usePattern = usePattern;
|
|
@@ -1727,14 +1715,14 @@ function validateArray(cxt) {
|
|
|
1727
1715
|
validateItems(() => gen.break());
|
|
1728
1716
|
return valid;
|
|
1729
1717
|
function validateItems(notValid) {
|
|
1730
|
-
const len = gen.const("len", (0, codegen_1$
|
|
1718
|
+
const len = gen.const("len", (0, codegen_1$q._)`${data2}.length`);
|
|
1731
1719
|
gen.forRange("i", 0, len, (i) => {
|
|
1732
1720
|
cxt.subschema({
|
|
1733
1721
|
keyword: keyword2,
|
|
1734
1722
|
dataProp: i,
|
|
1735
|
-
dataPropType: util_1$
|
|
1723
|
+
dataPropType: util_1$o.Type.Num
|
|
1736
1724
|
}, valid);
|
|
1737
|
-
gen.if((0, codegen_1$
|
|
1725
|
+
gen.if((0, codegen_1$q.not)(valid), notValid);
|
|
1738
1726
|
});
|
|
1739
1727
|
}
|
|
1740
1728
|
}
|
|
@@ -1743,7 +1731,7 @@ function validateUnion(cxt) {
|
|
|
1743
1731
|
const { gen, schema, keyword: keyword2, it } = cxt;
|
|
1744
1732
|
if (!Array.isArray(schema))
|
|
1745
1733
|
throw new Error("ajv implementation error");
|
|
1746
|
-
const alwaysValid = schema.some((sch) => (0, util_1$
|
|
1734
|
+
const alwaysValid = schema.some((sch) => (0, util_1$o.alwaysValidSchema)(it, sch));
|
|
1747
1735
|
if (alwaysValid && !it.opts.unevaluated)
|
|
1748
1736
|
return;
|
|
1749
1737
|
const valid = gen.let("valid", false);
|
|
@@ -1754,214 +1742,202 @@ function validateUnion(cxt) {
|
|
|
1754
1742
|
schemaProp: i,
|
|
1755
1743
|
compositeRule: true
|
|
1756
1744
|
}, schValid);
|
|
1757
|
-
gen.assign(valid, (0, codegen_1$
|
|
1745
|
+
gen.assign(valid, (0, codegen_1$q._)`${valid} || ${schValid}`);
|
|
1758
1746
|
const merged = cxt.mergeValidEvaluated(schCxt, schValid);
|
|
1759
1747
|
if (!merged)
|
|
1760
|
-
gen.if((0, codegen_1$
|
|
1748
|
+
gen.if((0, codegen_1$q.not)(valid));
|
|
1761
1749
|
}));
|
|
1762
1750
|
cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
|
|
1763
1751
|
}
|
|
1764
1752
|
code.validateUnion = validateUnion;
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
const
|
|
1773
|
-
const
|
|
1774
|
-
const
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
}
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
1809
|
-
if (def2.modifying)
|
|
1810
|
-
modifyData(cxt);
|
|
1811
|
-
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
function validateAsync() {
|
|
1815
|
-
const ruleErrs = gen.let("ruleErrs", null);
|
|
1816
|
-
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)));
|
|
1817
|
-
return ruleErrs;
|
|
1818
|
-
}
|
|
1819
|
-
function validateSync() {
|
|
1820
|
-
const validateErrs = (0, codegen_12._)`${validateRef}.errors`;
|
|
1821
|
-
gen.assign(validateErrs, null);
|
|
1822
|
-
assignValid(codegen_12.nil);
|
|
1823
|
-
return validateErrs;
|
|
1824
|
-
}
|
|
1825
|
-
function assignValid(_await = def2.async ? (0, codegen_12._)`await ` : codegen_12.nil) {
|
|
1826
|
-
const passCxt = it.opts.passContext ? names_12.default.this : names_12.default.self;
|
|
1827
|
-
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
1828
|
-
gen.assign(valid, (0, codegen_12._)`${_await}${(0, code_12.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
1829
|
-
}
|
|
1830
|
-
function reportErrs(errors2) {
|
|
1831
|
-
var _a17;
|
|
1832
|
-
gen.if((0, codegen_12.not)((_a17 = def2.valid) !== null && _a17 !== void 0 ? _a17 : valid), errors2);
|
|
1753
|
+
Object.defineProperty(keyword$1, "__esModule", { value: true });
|
|
1754
|
+
keyword$1.validateKeywordUsage = keyword$1.validSchemaType = keyword$1.funcKeywordCode = keyword$1.macroKeywordCode = void 0;
|
|
1755
|
+
const codegen_1$p = codegen;
|
|
1756
|
+
const names_1$4 = names$1;
|
|
1757
|
+
const code_1$9 = code;
|
|
1758
|
+
const errors_1$1 = errors;
|
|
1759
|
+
function macroKeywordCode(cxt, def2) {
|
|
1760
|
+
const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
|
|
1761
|
+
const macroSchema = def2.macro.call(it.self, schema, parentSchema, it);
|
|
1762
|
+
const schemaRef = useKeyword(gen, keyword2, macroSchema);
|
|
1763
|
+
if (it.opts.validateSchema !== false)
|
|
1764
|
+
it.self.validateSchema(macroSchema, true);
|
|
1765
|
+
const valid = gen.name("valid");
|
|
1766
|
+
cxt.subschema({
|
|
1767
|
+
schema: macroSchema,
|
|
1768
|
+
schemaPath: codegen_1$p.nil,
|
|
1769
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`,
|
|
1770
|
+
topSchemaRef: schemaRef,
|
|
1771
|
+
compositeRule: true
|
|
1772
|
+
}, valid);
|
|
1773
|
+
cxt.pass(valid, () => cxt.error(true));
|
|
1774
|
+
}
|
|
1775
|
+
keyword$1.macroKeywordCode = macroKeywordCode;
|
|
1776
|
+
function funcKeywordCode(cxt, def2) {
|
|
1777
|
+
var _a16;
|
|
1778
|
+
const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
|
|
1779
|
+
checkAsyncKeyword(it, def2);
|
|
1780
|
+
const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
|
|
1781
|
+
const validateRef = useKeyword(gen, keyword2, validate2);
|
|
1782
|
+
const valid = gen.let("valid");
|
|
1783
|
+
cxt.block$data(valid, validateKeyword2);
|
|
1784
|
+
cxt.ok((_a16 = def2.valid) !== null && _a16 !== void 0 ? _a16 : valid);
|
|
1785
|
+
function validateKeyword2() {
|
|
1786
|
+
if (def2.errors === false) {
|
|
1787
|
+
assignValid();
|
|
1788
|
+
if (def2.modifying)
|
|
1789
|
+
modifyData(cxt);
|
|
1790
|
+
reportErrs(() => cxt.error());
|
|
1791
|
+
} else {
|
|
1792
|
+
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
1793
|
+
if (def2.modifying)
|
|
1794
|
+
modifyData(cxt);
|
|
1795
|
+
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
1833
1796
|
}
|
|
1834
1797
|
}
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
}
|
|
1840
|
-
function
|
|
1841
|
-
const
|
|
1842
|
-
gen.
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
}
|
|
1851
|
-
function
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
}
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1798
|
+
function validateAsync() {
|
|
1799
|
+
const ruleErrs = gen.let("ruleErrs", null);
|
|
1800
|
+
gen.try(() => assignValid((0, codegen_1$p._)`await `), (e) => gen.assign(valid, false).if((0, codegen_1$p._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1$p._)`${e}.errors`), () => gen.throw(e)));
|
|
1801
|
+
return ruleErrs;
|
|
1802
|
+
}
|
|
1803
|
+
function validateSync() {
|
|
1804
|
+
const validateErrs = (0, codegen_1$p._)`${validateRef}.errors`;
|
|
1805
|
+
gen.assign(validateErrs, null);
|
|
1806
|
+
assignValid(codegen_1$p.nil);
|
|
1807
|
+
return validateErrs;
|
|
1808
|
+
}
|
|
1809
|
+
function assignValid(_await = def2.async ? (0, codegen_1$p._)`await ` : codegen_1$p.nil) {
|
|
1810
|
+
const passCxt = it.opts.passContext ? names_1$4.default.this : names_1$4.default.self;
|
|
1811
|
+
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
1812
|
+
gen.assign(valid, (0, codegen_1$p._)`${_await}${(0, code_1$9.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
1813
|
+
}
|
|
1814
|
+
function reportErrs(errors2) {
|
|
1815
|
+
var _a17;
|
|
1816
|
+
gen.if((0, codegen_1$p.not)((_a17 = def2.valid) !== null && _a17 !== void 0 ? _a17 : valid), errors2);
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
keyword$1.funcKeywordCode = funcKeywordCode;
|
|
1820
|
+
function modifyData(cxt) {
|
|
1821
|
+
const { gen, data: data2, it } = cxt;
|
|
1822
|
+
gen.if(it.parentData, () => gen.assign(data2, (0, codegen_1$p._)`${it.parentData}[${it.parentDataProperty}]`));
|
|
1823
|
+
}
|
|
1824
|
+
function addErrs(cxt, errs) {
|
|
1825
|
+
const { gen } = cxt;
|
|
1826
|
+
gen.if((0, codegen_1$p._)`Array.isArray(${errs})`, () => {
|
|
1827
|
+
gen.assign(names_1$4.default.vErrors, (0, codegen_1$p._)`${names_1$4.default.vErrors} === null ? ${errs} : ${names_1$4.default.vErrors}.concat(${errs})`).assign(names_1$4.default.errors, (0, codegen_1$p._)`${names_1$4.default.vErrors}.length`);
|
|
1828
|
+
(0, errors_1$1.extendErrors)(cxt);
|
|
1829
|
+
}, () => cxt.error());
|
|
1830
|
+
}
|
|
1831
|
+
function checkAsyncKeyword({ schemaEnv }, def2) {
|
|
1832
|
+
if (def2.async && !schemaEnv.$async)
|
|
1833
|
+
throw new Error("async keyword in sync schema");
|
|
1834
|
+
}
|
|
1835
|
+
function useKeyword(gen, keyword2, result) {
|
|
1836
|
+
if (result === void 0)
|
|
1837
|
+
throw new Error(`keyword "${keyword2}" failed to compile`);
|
|
1838
|
+
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_1$p.stringify)(result) });
|
|
1839
|
+
}
|
|
1840
|
+
function validSchemaType(schema, schemaType, allowUndefined = false) {
|
|
1841
|
+
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");
|
|
1842
|
+
}
|
|
1843
|
+
keyword$1.validSchemaType = validSchemaType;
|
|
1844
|
+
function validateKeywordUsage({ schema, opts, self: self2, errSchemaPath }, def2, keyword2) {
|
|
1845
|
+
if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
|
|
1846
|
+
throw new Error("ajv implementation error");
|
|
1847
|
+
}
|
|
1848
|
+
const deps = def2.dependencies;
|
|
1849
|
+
if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
|
|
1850
|
+
throw new Error(`parent schema must have dependencies of ${keyword2}: ${deps.join(",")}`);
|
|
1851
|
+
}
|
|
1852
|
+
if (def2.validateSchema) {
|
|
1853
|
+
const valid = def2.validateSchema(schema[keyword2]);
|
|
1854
|
+
if (!valid) {
|
|
1855
|
+
const msg = `keyword "${keyword2}" value is invalid at path "${errSchemaPath}": ` + self2.errorsText(def2.validateSchema.errors);
|
|
1856
|
+
if (opts.validateSchema === "log")
|
|
1857
|
+
self2.logger.error(msg);
|
|
1858
|
+
else
|
|
1859
|
+
throw new Error(msg);
|
|
1877
1860
|
}
|
|
1878
1861
|
}
|
|
1879
|
-
keyword$1.validateKeywordUsage = validateKeywordUsage;
|
|
1880
|
-
return keyword$1;
|
|
1881
1862
|
}
|
|
1863
|
+
keyword$1.validateKeywordUsage = validateKeywordUsage;
|
|
1882
1864
|
var subschema = {};
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
}
|
|
1907
|
-
if (schema !== void 0) {
|
|
1908
|
-
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
1909
|
-
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
1910
|
-
}
|
|
1911
|
-
return {
|
|
1912
|
-
schema,
|
|
1913
|
-
schemaPath,
|
|
1914
|
-
topSchemaRef,
|
|
1915
|
-
errSchemaPath
|
|
1916
|
-
};
|
|
1865
|
+
Object.defineProperty(subschema, "__esModule", { value: true });
|
|
1866
|
+
subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
|
|
1867
|
+
const codegen_1$o = codegen;
|
|
1868
|
+
const util_1$n = util$7;
|
|
1869
|
+
function getSubschema(it, { keyword: keyword2, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
|
|
1870
|
+
if (keyword2 !== void 0 && schema !== void 0) {
|
|
1871
|
+
throw new Error('both "keyword" and "schema" passed, only one allowed');
|
|
1872
|
+
}
|
|
1873
|
+
if (keyword2 !== void 0) {
|
|
1874
|
+
const sch = it.schema[keyword2];
|
|
1875
|
+
return schemaProp === void 0 ? {
|
|
1876
|
+
schema: sch,
|
|
1877
|
+
schemaPath: (0, codegen_1$o._)`${it.schemaPath}${(0, codegen_1$o.getProperty)(keyword2)}`,
|
|
1878
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`
|
|
1879
|
+
} : {
|
|
1880
|
+
schema: sch[schemaProp],
|
|
1881
|
+
schemaPath: (0, codegen_1$o._)`${it.schemaPath}${(0, codegen_1$o.getProperty)(keyword2)}${(0, codegen_1$o.getProperty)(schemaProp)}`,
|
|
1882
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_1$n.escapeFragment)(schemaProp)}`
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
if (schema !== void 0) {
|
|
1886
|
+
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
1887
|
+
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
1917
1888
|
}
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
subschema2.
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1889
|
+
return {
|
|
1890
|
+
schema,
|
|
1891
|
+
schemaPath,
|
|
1892
|
+
topSchemaRef,
|
|
1893
|
+
errSchemaPath
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1896
|
+
throw new Error('either "keyword" or "schema" must be passed');
|
|
1897
|
+
}
|
|
1898
|
+
subschema.getSubschema = getSubschema;
|
|
1899
|
+
function extendSubschemaData(subschema2, it, { dataProp, dataPropType: dpType, data: data2, dataTypes, propertyName }) {
|
|
1900
|
+
if (data2 !== void 0 && dataProp !== void 0) {
|
|
1901
|
+
throw new Error('both "data" and "dataProp" passed, only one allowed');
|
|
1902
|
+
}
|
|
1903
|
+
const { gen } = it;
|
|
1904
|
+
if (dataProp !== void 0) {
|
|
1905
|
+
const { errorPath, dataPathArr, opts } = it;
|
|
1906
|
+
const nextData = gen.let("data", (0, codegen_1$o._)`${it.data}${(0, codegen_1$o.getProperty)(dataProp)}`, true);
|
|
1907
|
+
dataContextProps(nextData);
|
|
1908
|
+
subschema2.errorPath = (0, codegen_1$o.str)`${errorPath}${(0, util_1$n.getErrorPath)(dataProp, dpType, opts.jsPropertySyntax)}`;
|
|
1909
|
+
subschema2.parentDataProperty = (0, codegen_1$o._)`${dataProp}`;
|
|
1910
|
+
subschema2.dataPathArr = [...dataPathArr, subschema2.parentDataProperty];
|
|
1911
|
+
}
|
|
1912
|
+
if (data2 !== void 0) {
|
|
1913
|
+
const nextData = data2 instanceof codegen_1$o.Name ? data2 : gen.let("data", data2, true);
|
|
1914
|
+
dataContextProps(nextData);
|
|
1915
|
+
if (propertyName !== void 0)
|
|
1916
|
+
subschema2.propertyName = propertyName;
|
|
1917
|
+
}
|
|
1918
|
+
if (dataTypes)
|
|
1919
|
+
subschema2.dataTypes = dataTypes;
|
|
1920
|
+
function dataContextProps(_nextData) {
|
|
1921
|
+
subschema2.data = _nextData;
|
|
1922
|
+
subschema2.dataLevel = it.dataLevel + 1;
|
|
1923
|
+
subschema2.dataTypes = [];
|
|
1924
|
+
it.definedProperties = /* @__PURE__ */ new Set();
|
|
1925
|
+
subschema2.parentData = it.data;
|
|
1926
|
+
subschema2.dataNames = [...it.dataNames, _nextData];
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
subschema.extendSubschemaData = extendSubschemaData;
|
|
1930
|
+
function extendSubschemaMode(subschema2, { jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors }) {
|
|
1931
|
+
if (compositeRule !== void 0)
|
|
1932
|
+
subschema2.compositeRule = compositeRule;
|
|
1933
|
+
if (createErrors !== void 0)
|
|
1934
|
+
subschema2.createErrors = createErrors;
|
|
1935
|
+
if (allErrors !== void 0)
|
|
1936
|
+
subschema2.allErrors = allErrors;
|
|
1937
|
+
subschema2.jtdDiscriminator = jtdDiscriminator;
|
|
1938
|
+
subschema2.jtdMetadata = jtdMetadata;
|
|
1939
|
+
}
|
|
1940
|
+
subschema.extendSubschemaMode = extendSubschemaMode;
|
|
1965
1941
|
var resolve$7 = {};
|
|
1966
1942
|
var fastDeepEqual = function equal(a, b) {
|
|
1967
1943
|
if (a === b) return true;
|
|
@@ -2076,7 +2052,7 @@ function escapeJsonPtr$1(str) {
|
|
|
2076
2052
|
var jsonSchemaTraverseExports$1 = jsonSchemaTraverse$1.exports;
|
|
2077
2053
|
Object.defineProperty(resolve$7, "__esModule", { value: true });
|
|
2078
2054
|
resolve$7.getSchemaRefs = resolve$7.resolveUrl = resolve$7.normalizeId = resolve$7._getFullPath = resolve$7.getFullPath = resolve$7.inlineRef = void 0;
|
|
2079
|
-
const util_1$
|
|
2055
|
+
const util_1$m = util$7;
|
|
2080
2056
|
const equal$5 = fastDeepEqual;
|
|
2081
2057
|
const traverse$2 = jsonSchemaTraverseExports$1;
|
|
2082
2058
|
const SIMPLE_INLINED$1 = /* @__PURE__ */ new Set([
|
|
@@ -2135,7 +2111,7 @@ function countKeys$1(schema) {
|
|
|
2135
2111
|
if (SIMPLE_INLINED$1.has(key))
|
|
2136
2112
|
continue;
|
|
2137
2113
|
if (typeof schema[key] == "object") {
|
|
2138
|
-
(0, util_1$
|
|
2114
|
+
(0, util_1$m.eachItem)(schema[key], (sch) => count += countKeys$1(sch));
|
|
2139
2115
|
}
|
|
2140
2116
|
if (count === Infinity)
|
|
2141
2117
|
return Infinity;
|
|
@@ -2223,528 +2199,516 @@ function getSchemaRefs(schema, baseId) {
|
|
|
2223
2199
|
}
|
|
2224
2200
|
}
|
|
2225
2201
|
resolve$7.getSchemaRefs = getSchemaRefs;
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
checkKeywords(it);
|
|
2247
|
-
if (schemaCxtHasRules(it)) {
|
|
2248
|
-
topSchemaObjCode(it);
|
|
2249
|
-
return;
|
|
2250
|
-
}
|
|
2202
|
+
Object.defineProperty(validate$2, "__esModule", { value: true });
|
|
2203
|
+
validate$2.getData = validate$2.KeywordCxt = validate$2.validateFunctionCode = void 0;
|
|
2204
|
+
const boolSchema_1 = boolSchema;
|
|
2205
|
+
const dataType_1$1 = dataType;
|
|
2206
|
+
const applicability_1 = applicability;
|
|
2207
|
+
const dataType_2 = dataType;
|
|
2208
|
+
const defaults_1 = defaults;
|
|
2209
|
+
const keyword_1 = keyword$1;
|
|
2210
|
+
const subschema_1 = subschema;
|
|
2211
|
+
const codegen_1$n = codegen;
|
|
2212
|
+
const names_1$3 = names$1;
|
|
2213
|
+
const resolve_1$3 = resolve$7;
|
|
2214
|
+
const util_1$l = util$7;
|
|
2215
|
+
const errors_1 = errors;
|
|
2216
|
+
function validateFunctionCode(it) {
|
|
2217
|
+
if (isSchemaObj(it)) {
|
|
2218
|
+
checkKeywords(it);
|
|
2219
|
+
if (schemaCxtHasRules(it)) {
|
|
2220
|
+
topSchemaObjCode(it);
|
|
2221
|
+
return;
|
|
2251
2222
|
}
|
|
2252
|
-
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
2253
2223
|
}
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
2264
|
-
}
|
|
2265
|
-
}
|
|
2266
|
-
function destructureValCxt(opts) {
|
|
2267
|
-
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}}={}`;
|
|
2268
|
-
}
|
|
2269
|
-
function destructureValCxtES5(gen, opts) {
|
|
2270
|
-
gen.if(names_12.default.valCxt, () => {
|
|
2271
|
-
gen.var(names_12.default.instancePath, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.instancePath}`);
|
|
2272
|
-
gen.var(names_12.default.parentData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentData}`);
|
|
2273
|
-
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentDataProperty}`);
|
|
2274
|
-
gen.var(names_12.default.rootData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.rootData}`);
|
|
2275
|
-
if (opts.dynamicRef)
|
|
2276
|
-
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.dynamicAnchors}`);
|
|
2277
|
-
}, () => {
|
|
2278
|
-
gen.var(names_12.default.instancePath, (0, codegen_12._)`""`);
|
|
2279
|
-
gen.var(names_12.default.parentData, (0, codegen_12._)`undefined`);
|
|
2280
|
-
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`undefined`);
|
|
2281
|
-
gen.var(names_12.default.rootData, names_12.default.data);
|
|
2282
|
-
if (opts.dynamicRef)
|
|
2283
|
-
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`{}`);
|
|
2284
|
-
});
|
|
2285
|
-
}
|
|
2286
|
-
function topSchemaObjCode(it) {
|
|
2287
|
-
const { schema, opts, gen } = it;
|
|
2288
|
-
validateFunction(it, () => {
|
|
2289
|
-
if (opts.$comment && schema.$comment)
|
|
2290
|
-
commentKeyword(it);
|
|
2291
|
-
checkNoDefault(it);
|
|
2292
|
-
gen.let(names_12.default.vErrors, null);
|
|
2293
|
-
gen.let(names_12.default.errors, 0);
|
|
2294
|
-
if (opts.unevaluated)
|
|
2295
|
-
resetEvaluated(it);
|
|
2296
|
-
typeAndKeywords(it);
|
|
2297
|
-
returnResults(it);
|
|
2224
|
+
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
2225
|
+
}
|
|
2226
|
+
validate$2.validateFunctionCode = validateFunctionCode;
|
|
2227
|
+
function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
|
|
2228
|
+
if (opts.code.es5) {
|
|
2229
|
+
gen.func(validateName, (0, codegen_1$n._)`${names_1$3.default.data}, ${names_1$3.default.valCxt}`, schemaEnv.$async, () => {
|
|
2230
|
+
gen.code((0, codegen_1$n._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
|
|
2231
|
+
destructureValCxtES5(gen, opts);
|
|
2232
|
+
gen.code(body);
|
|
2298
2233
|
});
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
if (
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
(
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
return true;
|
|
2327
|
-
return false;
|
|
2328
|
-
}
|
|
2329
|
-
function isSchemaObj(it) {
|
|
2330
|
-
return typeof it.schema != "boolean";
|
|
2331
|
-
}
|
|
2332
|
-
function subSchemaObjCode(it, valid) {
|
|
2333
|
-
const { schema, gen, opts } = it;
|
|
2234
|
+
} else {
|
|
2235
|
+
gen.func(validateName, (0, codegen_1$n._)`${names_1$3.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
function destructureValCxt(opts) {
|
|
2239
|
+
return (0, codegen_1$n._)`{${names_1$3.default.instancePath}="", ${names_1$3.default.parentData}, ${names_1$3.default.parentDataProperty}, ${names_1$3.default.rootData}=${names_1$3.default.data}${opts.dynamicRef ? (0, codegen_1$n._)`, ${names_1$3.default.dynamicAnchors}={}` : codegen_1$n.nil}}={}`;
|
|
2240
|
+
}
|
|
2241
|
+
function destructureValCxtES5(gen, opts) {
|
|
2242
|
+
gen.if(names_1$3.default.valCxt, () => {
|
|
2243
|
+
gen.var(names_1$3.default.instancePath, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.instancePath}`);
|
|
2244
|
+
gen.var(names_1$3.default.parentData, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.parentData}`);
|
|
2245
|
+
gen.var(names_1$3.default.parentDataProperty, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.parentDataProperty}`);
|
|
2246
|
+
gen.var(names_1$3.default.rootData, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.rootData}`);
|
|
2247
|
+
if (opts.dynamicRef)
|
|
2248
|
+
gen.var(names_1$3.default.dynamicAnchors, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.dynamicAnchors}`);
|
|
2249
|
+
}, () => {
|
|
2250
|
+
gen.var(names_1$3.default.instancePath, (0, codegen_1$n._)`""`);
|
|
2251
|
+
gen.var(names_1$3.default.parentData, (0, codegen_1$n._)`undefined`);
|
|
2252
|
+
gen.var(names_1$3.default.parentDataProperty, (0, codegen_1$n._)`undefined`);
|
|
2253
|
+
gen.var(names_1$3.default.rootData, names_1$3.default.data);
|
|
2254
|
+
if (opts.dynamicRef)
|
|
2255
|
+
gen.var(names_1$3.default.dynamicAnchors, (0, codegen_1$n._)`{}`);
|
|
2256
|
+
});
|
|
2257
|
+
}
|
|
2258
|
+
function topSchemaObjCode(it) {
|
|
2259
|
+
const { schema, opts, gen } = it;
|
|
2260
|
+
validateFunction(it, () => {
|
|
2334
2261
|
if (opts.$comment && schema.$comment)
|
|
2335
2262
|
commentKeyword(it);
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
(0, util_12.checkStrictMode)(it, "default is ignored in the schema root");
|
|
2263
|
+
checkNoDefault(it);
|
|
2264
|
+
gen.let(names_1$3.default.vErrors, null);
|
|
2265
|
+
gen.let(names_1$3.default.errors, 0);
|
|
2266
|
+
if (opts.unevaluated)
|
|
2267
|
+
resetEvaluated(it);
|
|
2268
|
+
typeAndKeywords(it);
|
|
2269
|
+
returnResults(it);
|
|
2270
|
+
});
|
|
2271
|
+
return;
|
|
2272
|
+
}
|
|
2273
|
+
function resetEvaluated(it) {
|
|
2274
|
+
const { gen, validateName } = it;
|
|
2275
|
+
it.evaluated = gen.const("evaluated", (0, codegen_1$n._)`${validateName}.evaluated`);
|
|
2276
|
+
gen.if((0, codegen_1$n._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_1$n._)`${it.evaluated}.props`, (0, codegen_1$n._)`undefined`));
|
|
2277
|
+
gen.if((0, codegen_1$n._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_1$n._)`${it.evaluated}.items`, (0, codegen_1$n._)`undefined`));
|
|
2278
|
+
}
|
|
2279
|
+
function funcSourceUrl(schema, opts) {
|
|
2280
|
+
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
2281
|
+
return schId && (opts.code.source || opts.code.process) ? (0, codegen_1$n._)`/*# sourceURL=${schId} */` : codegen_1$n.nil;
|
|
2282
|
+
}
|
|
2283
|
+
function subschemaCode(it, valid) {
|
|
2284
|
+
if (isSchemaObj(it)) {
|
|
2285
|
+
checkKeywords(it);
|
|
2286
|
+
if (schemaCxtHasRules(it)) {
|
|
2287
|
+
subSchemaObjCode(it, valid);
|
|
2288
|
+
return;
|
|
2363
2289
|
}
|
|
2364
2290
|
}
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
if (
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2291
|
+
(0, boolSchema_1.boolOrEmptySchema)(it, valid);
|
|
2292
|
+
}
|
|
2293
|
+
function schemaCxtHasRules({ schema, self: self2 }) {
|
|
2294
|
+
if (typeof schema == "boolean")
|
|
2295
|
+
return !schema;
|
|
2296
|
+
for (const key in schema)
|
|
2297
|
+
if (self2.RULES.all[key])
|
|
2298
|
+
return true;
|
|
2299
|
+
return false;
|
|
2300
|
+
}
|
|
2301
|
+
function isSchemaObj(it) {
|
|
2302
|
+
return typeof it.schema != "boolean";
|
|
2303
|
+
}
|
|
2304
|
+
function subSchemaObjCode(it, valid) {
|
|
2305
|
+
const { schema, gen, opts } = it;
|
|
2306
|
+
if (opts.$comment && schema.$comment)
|
|
2307
|
+
commentKeyword(it);
|
|
2308
|
+
updateContext(it);
|
|
2309
|
+
checkAsyncSchema(it);
|
|
2310
|
+
const errsCount = gen.const("_errs", names_1$3.default.errors);
|
|
2311
|
+
typeAndKeywords(it, errsCount);
|
|
2312
|
+
gen.var(valid, (0, codegen_1$n._)`${errsCount} === ${names_1$3.default.errors}`);
|
|
2313
|
+
}
|
|
2314
|
+
function checkKeywords(it) {
|
|
2315
|
+
(0, util_1$l.checkUnknownRules)(it);
|
|
2316
|
+
checkRefsAndKeywords(it);
|
|
2317
|
+
}
|
|
2318
|
+
function typeAndKeywords(it, errsCount) {
|
|
2319
|
+
if (it.opts.jtd)
|
|
2320
|
+
return schemaKeywords(it, [], false, errsCount);
|
|
2321
|
+
const types2 = (0, dataType_1$1.getSchemaTypes)(it.schema);
|
|
2322
|
+
const checkedTypes = (0, dataType_1$1.coerceAndCheckDataType)(it, types2);
|
|
2323
|
+
schemaKeywords(it, types2, !checkedTypes, errsCount);
|
|
2324
|
+
}
|
|
2325
|
+
function checkRefsAndKeywords(it) {
|
|
2326
|
+
const { schema, errSchemaPath, opts, self: self2 } = it;
|
|
2327
|
+
if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_1$l.schemaHasRulesButRef)(schema, self2.RULES)) {
|
|
2328
|
+
self2.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
function checkNoDefault(it) {
|
|
2332
|
+
const { schema, opts } = it;
|
|
2333
|
+
if (schema.default !== void 0 && opts.useDefaults && opts.strictSchema) {
|
|
2334
|
+
(0, util_1$l.checkStrictMode)(it, "default is ignored in the schema root");
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
function updateContext(it) {
|
|
2338
|
+
const schId = it.schema[it.opts.schemaId];
|
|
2339
|
+
if (schId)
|
|
2340
|
+
it.baseId = (0, resolve_1$3.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
|
|
2341
|
+
}
|
|
2342
|
+
function checkAsyncSchema(it) {
|
|
2343
|
+
if (it.schema.$async && !it.schemaEnv.$async)
|
|
2344
|
+
throw new Error("async schema in sync schema");
|
|
2345
|
+
}
|
|
2346
|
+
function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
|
|
2347
|
+
const msg = schema.$comment;
|
|
2348
|
+
if (opts.$comment === true) {
|
|
2349
|
+
gen.code((0, codegen_1$n._)`${names_1$3.default.self}.logger.log(${msg})`);
|
|
2350
|
+
} else if (typeof opts.$comment == "function") {
|
|
2351
|
+
const schemaPath = (0, codegen_1$n.str)`${errSchemaPath}/$comment`;
|
|
2352
|
+
const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
|
|
2353
|
+
gen.code((0, codegen_1$n._)`${names_1$3.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
function returnResults(it) {
|
|
2357
|
+
const { gen, schemaEnv, validateName, ValidationError: ValidationError3, opts } = it;
|
|
2358
|
+
if (schemaEnv.$async) {
|
|
2359
|
+
gen.if((0, codegen_1$n._)`${names_1$3.default.errors} === 0`, () => gen.return(names_1$3.default.data), () => gen.throw((0, codegen_1$n._)`new ${ValidationError3}(${names_1$3.default.vErrors})`));
|
|
2360
|
+
} else {
|
|
2361
|
+
gen.assign((0, codegen_1$n._)`${validateName}.errors`, names_1$3.default.vErrors);
|
|
2362
|
+
if (opts.unevaluated)
|
|
2363
|
+
assignEvaluated(it);
|
|
2364
|
+
gen.return((0, codegen_1$n._)`${names_1$3.default.errors} === 0`);
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
function assignEvaluated({ gen, evaluated, props, items: items2 }) {
|
|
2368
|
+
if (props instanceof codegen_1$n.Name)
|
|
2369
|
+
gen.assign((0, codegen_1$n._)`${evaluated}.props`, props);
|
|
2370
|
+
if (items2 instanceof codegen_1$n.Name)
|
|
2371
|
+
gen.assign((0, codegen_1$n._)`${evaluated}.items`, items2);
|
|
2372
|
+
}
|
|
2373
|
+
function schemaKeywords(it, types2, typeErrors, errsCount) {
|
|
2374
|
+
const { gen, schema, data: data2, allErrors, opts, self: self2 } = it;
|
|
2375
|
+
const { RULES } = self2;
|
|
2376
|
+
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_1$l.schemaHasRulesButRef)(schema, RULES))) {
|
|
2377
|
+
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
2378
|
+
return;
|
|
2383
2379
|
}
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
}
|
|
2394
|
-
}
|
|
2395
|
-
function assignEvaluated({ gen, evaluated, props, items: items2 }) {
|
|
2396
|
-
if (props instanceof codegen_12.Name)
|
|
2397
|
-
gen.assign((0, codegen_12._)`${evaluated}.props`, props);
|
|
2398
|
-
if (items2 instanceof codegen_12.Name)
|
|
2399
|
-
gen.assign((0, codegen_12._)`${evaluated}.items`, items2);
|
|
2400
|
-
}
|
|
2401
|
-
function schemaKeywords(it, types2, typeErrors, errsCount) {
|
|
2402
|
-
const { gen, schema, data: data2, allErrors, opts, self: self2 } = it;
|
|
2403
|
-
const { RULES } = self2;
|
|
2404
|
-
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_12.schemaHasRulesButRef)(schema, RULES))) {
|
|
2405
|
-
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
2380
|
+
if (!opts.jtd)
|
|
2381
|
+
checkStrictTypes(it, types2);
|
|
2382
|
+
gen.block(() => {
|
|
2383
|
+
for (const group of RULES.rules)
|
|
2384
|
+
groupKeywords(group);
|
|
2385
|
+
groupKeywords(RULES.post);
|
|
2386
|
+
});
|
|
2387
|
+
function groupKeywords(group) {
|
|
2388
|
+
if (!(0, applicability_1.shouldUseGroup)(schema, group))
|
|
2406
2389
|
return;
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
groupKeywords(RULES.post);
|
|
2414
|
-
});
|
|
2415
|
-
function groupKeywords(group) {
|
|
2416
|
-
if (!(0, applicability_12.shouldUseGroup)(schema, group))
|
|
2417
|
-
return;
|
|
2418
|
-
if (group.type) {
|
|
2419
|
-
gen.if((0, dataType_2.checkDataType)(group.type, data2, opts.strictNumbers));
|
|
2420
|
-
iterateKeywords(it, group);
|
|
2421
|
-
if (types2.length === 1 && types2[0] === group.type && typeErrors) {
|
|
2422
|
-
gen.else();
|
|
2423
|
-
(0, dataType_2.reportTypeError)(it);
|
|
2424
|
-
}
|
|
2425
|
-
gen.endIf();
|
|
2426
|
-
} else {
|
|
2427
|
-
iterateKeywords(it, group);
|
|
2390
|
+
if (group.type) {
|
|
2391
|
+
gen.if((0, dataType_2.checkDataType)(group.type, data2, opts.strictNumbers));
|
|
2392
|
+
iterateKeywords(it, group);
|
|
2393
|
+
if (types2.length === 1 && types2[0] === group.type && typeErrors) {
|
|
2394
|
+
gen.else();
|
|
2395
|
+
(0, dataType_2.reportTypeError)(it);
|
|
2428
2396
|
}
|
|
2429
|
-
|
|
2430
|
-
|
|
2397
|
+
gen.endIf();
|
|
2398
|
+
} else {
|
|
2399
|
+
iterateKeywords(it, group);
|
|
2431
2400
|
}
|
|
2401
|
+
if (!allErrors)
|
|
2402
|
+
gen.if((0, codegen_1$n._)`${names_1$3.default.errors} === ${errsCount || 0}`);
|
|
2432
2403
|
}
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2404
|
+
}
|
|
2405
|
+
function iterateKeywords(it, group) {
|
|
2406
|
+
const { gen, schema, opts: { useDefaults } } = it;
|
|
2407
|
+
if (useDefaults)
|
|
2408
|
+
(0, defaults_1.assignDefaults)(it, group.type);
|
|
2409
|
+
gen.block(() => {
|
|
2410
|
+
for (const rule of group.rules) {
|
|
2411
|
+
if ((0, applicability_1.shouldUseRule)(schema, rule)) {
|
|
2412
|
+
keywordCode(it, rule.keyword, rule.definition, group.type);
|
|
2442
2413
|
}
|
|
2443
|
-
});
|
|
2444
|
-
}
|
|
2445
|
-
function checkStrictTypes(it, types2) {
|
|
2446
|
-
if (it.schemaEnv.meta || !it.opts.strictTypes)
|
|
2447
|
-
return;
|
|
2448
|
-
checkContextTypes(it, types2);
|
|
2449
|
-
if (!it.opts.allowUnionTypes)
|
|
2450
|
-
checkMultipleTypes(it, types2);
|
|
2451
|
-
checkKeywordTypes(it, it.dataTypes);
|
|
2452
|
-
}
|
|
2453
|
-
function checkContextTypes(it, types2) {
|
|
2454
|
-
if (!types2.length)
|
|
2455
|
-
return;
|
|
2456
|
-
if (!it.dataTypes.length) {
|
|
2457
|
-
it.dataTypes = types2;
|
|
2458
|
-
return;
|
|
2459
2414
|
}
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2415
|
+
});
|
|
2416
|
+
}
|
|
2417
|
+
function checkStrictTypes(it, types2) {
|
|
2418
|
+
if (it.schemaEnv.meta || !it.opts.strictTypes)
|
|
2419
|
+
return;
|
|
2420
|
+
checkContextTypes(it, types2);
|
|
2421
|
+
if (!it.opts.allowUnionTypes)
|
|
2422
|
+
checkMultipleTypes(it, types2);
|
|
2423
|
+
checkKeywordTypes(it, it.dataTypes);
|
|
2424
|
+
}
|
|
2425
|
+
function checkContextTypes(it, types2) {
|
|
2426
|
+
if (!types2.length)
|
|
2427
|
+
return;
|
|
2428
|
+
if (!it.dataTypes.length) {
|
|
2429
|
+
it.dataTypes = types2;
|
|
2430
|
+
return;
|
|
2466
2431
|
}
|
|
2467
|
-
|
|
2468
|
-
if (
|
|
2469
|
-
strictTypesError(it, "
|
|
2432
|
+
types2.forEach((t) => {
|
|
2433
|
+
if (!includesType(it.dataTypes, t)) {
|
|
2434
|
+
strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
|
|
2470
2435
|
}
|
|
2471
|
-
}
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2436
|
+
});
|
|
2437
|
+
narrowSchemaTypes(it, types2);
|
|
2438
|
+
}
|
|
2439
|
+
function checkMultipleTypes(it, ts) {
|
|
2440
|
+
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
|
|
2441
|
+
strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
function checkKeywordTypes(it, ts) {
|
|
2445
|
+
const rules3 = it.self.RULES.all;
|
|
2446
|
+
for (const keyword2 in rules3) {
|
|
2447
|
+
const rule = rules3[keyword2];
|
|
2448
|
+
if (typeof rule == "object" && (0, applicability_1.shouldUseRule)(it.schema, rule)) {
|
|
2449
|
+
const { type: type2 } = rule.definition;
|
|
2450
|
+
if (type2.length && !type2.some((t) => hasApplicableType(ts, t))) {
|
|
2451
|
+
strictTypesError(it, `missing type "${type2.join(",")}" for keyword "${keyword2}"`);
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
function hasApplicableType(schTs, kwdT) {
|
|
2457
|
+
return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
|
|
2458
|
+
}
|
|
2459
|
+
function includesType(ts, t) {
|
|
2460
|
+
return ts.includes(t) || t === "integer" && ts.includes("number");
|
|
2461
|
+
}
|
|
2462
|
+
function narrowSchemaTypes(it, withTypes) {
|
|
2463
|
+
const ts = [];
|
|
2464
|
+
for (const t of it.dataTypes) {
|
|
2465
|
+
if (includesType(withTypes, t))
|
|
2466
|
+
ts.push(t);
|
|
2467
|
+
else if (withTypes.includes("integer") && t === "number")
|
|
2468
|
+
ts.push("integer");
|
|
2469
|
+
}
|
|
2470
|
+
it.dataTypes = ts;
|
|
2471
|
+
}
|
|
2472
|
+
function strictTypesError(it, msg) {
|
|
2473
|
+
const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
|
|
2474
|
+
msg += ` at "${schemaPath}" (strictTypes)`;
|
|
2475
|
+
(0, util_1$l.checkStrictMode)(it, msg, it.opts.strictTypes);
|
|
2476
|
+
}
|
|
2477
|
+
class KeywordCxt {
|
|
2478
|
+
constructor(it, def2, keyword2) {
|
|
2479
|
+
(0, keyword_1.validateKeywordUsage)(it, def2, keyword2);
|
|
2480
|
+
this.gen = it.gen;
|
|
2481
|
+
this.allErrors = it.allErrors;
|
|
2482
|
+
this.keyword = keyword2;
|
|
2483
|
+
this.data = it.data;
|
|
2484
|
+
this.schema = it.schema[keyword2];
|
|
2485
|
+
this.$data = def2.$data && it.opts.$data && this.schema && this.schema.$data;
|
|
2486
|
+
this.schemaValue = (0, util_1$l.schemaRefOrVal)(it, this.schema, keyword2, this.$data);
|
|
2487
|
+
this.schemaType = def2.schemaType;
|
|
2488
|
+
this.parentSchema = it.schema;
|
|
2489
|
+
this.params = {};
|
|
2490
|
+
this.it = it;
|
|
2491
|
+
this.def = def2;
|
|
2492
|
+
if (this.$data) {
|
|
2493
|
+
this.schemaCode = it.gen.const("vSchema", getData$1(this.$data, it));
|
|
2494
|
+
} else {
|
|
2495
|
+
this.schemaCode = this.schemaValue;
|
|
2496
|
+
if (!(0, keyword_1.validSchemaType)(this.schema, def2.schemaType, def2.allowUndefined)) {
|
|
2497
|
+
throw new Error(`${keyword2} value must be ${JSON.stringify(def2.schemaType)}`);
|
|
2481
2498
|
}
|
|
2482
2499
|
}
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
|
|
2486
|
-
}
|
|
2487
|
-
function includesType(ts, t) {
|
|
2488
|
-
return ts.includes(t) || t === "integer" && ts.includes("number");
|
|
2489
|
-
}
|
|
2490
|
-
function narrowSchemaTypes(it, withTypes) {
|
|
2491
|
-
const ts = [];
|
|
2492
|
-
for (const t of it.dataTypes) {
|
|
2493
|
-
if (includesType(withTypes, t))
|
|
2494
|
-
ts.push(t);
|
|
2495
|
-
else if (withTypes.includes("integer") && t === "number")
|
|
2496
|
-
ts.push("integer");
|
|
2500
|
+
if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
|
|
2501
|
+
this.errsCount = it.gen.const("_errs", names_1$3.default.errors);
|
|
2497
2502
|
}
|
|
2498
|
-
it.dataTypes = ts;
|
|
2499
2503
|
}
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
msg += ` at "${schemaPath}" (strictTypes)`;
|
|
2503
|
-
(0, util_12.checkStrictMode)(it, msg, it.opts.strictTypes);
|
|
2504
|
+
result(condition, successAction, failAction) {
|
|
2505
|
+
this.failResult((0, codegen_1$n.not)(condition), successAction, failAction);
|
|
2504
2506
|
}
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
this.keyword = keyword2;
|
|
2511
|
-
this.data = it.data;
|
|
2512
|
-
this.schema = it.schema[keyword2];
|
|
2513
|
-
this.$data = def2.$data && it.opts.$data && this.schema && this.schema.$data;
|
|
2514
|
-
this.schemaValue = (0, util_12.schemaRefOrVal)(it, this.schema, keyword2, this.$data);
|
|
2515
|
-
this.schemaType = def2.schemaType;
|
|
2516
|
-
this.parentSchema = it.schema;
|
|
2517
|
-
this.params = {};
|
|
2518
|
-
this.it = it;
|
|
2519
|
-
this.def = def2;
|
|
2520
|
-
if (this.$data) {
|
|
2521
|
-
this.schemaCode = it.gen.const("vSchema", getData2(this.$data, it));
|
|
2522
|
-
} else {
|
|
2523
|
-
this.schemaCode = this.schemaValue;
|
|
2524
|
-
if (!(0, keyword_1.validSchemaType)(this.schema, def2.schemaType, def2.allowUndefined)) {
|
|
2525
|
-
throw new Error(`${keyword2} value must be ${JSON.stringify(def2.schemaType)}`);
|
|
2526
|
-
}
|
|
2527
|
-
}
|
|
2528
|
-
if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
|
|
2529
|
-
this.errsCount = it.gen.const("_errs", names_12.default.errors);
|
|
2530
|
-
}
|
|
2531
|
-
}
|
|
2532
|
-
result(condition, successAction, failAction) {
|
|
2533
|
-
this.failResult((0, codegen_12.not)(condition), successAction, failAction);
|
|
2534
|
-
}
|
|
2535
|
-
failResult(condition, successAction, failAction) {
|
|
2536
|
-
this.gen.if(condition);
|
|
2537
|
-
if (failAction)
|
|
2538
|
-
failAction();
|
|
2539
|
-
else
|
|
2540
|
-
this.error();
|
|
2541
|
-
if (successAction) {
|
|
2542
|
-
this.gen.else();
|
|
2543
|
-
successAction();
|
|
2544
|
-
if (this.allErrors)
|
|
2545
|
-
this.gen.endIf();
|
|
2546
|
-
} else {
|
|
2547
|
-
if (this.allErrors)
|
|
2548
|
-
this.gen.endIf();
|
|
2549
|
-
else
|
|
2550
|
-
this.gen.else();
|
|
2551
|
-
}
|
|
2552
|
-
}
|
|
2553
|
-
pass(condition, failAction) {
|
|
2554
|
-
this.failResult((0, codegen_12.not)(condition), void 0, failAction);
|
|
2555
|
-
}
|
|
2556
|
-
fail(condition) {
|
|
2557
|
-
if (condition === void 0) {
|
|
2558
|
-
this.error();
|
|
2559
|
-
if (!this.allErrors)
|
|
2560
|
-
this.gen.if(false);
|
|
2561
|
-
return;
|
|
2562
|
-
}
|
|
2563
|
-
this.gen.if(condition);
|
|
2507
|
+
failResult(condition, successAction, failAction) {
|
|
2508
|
+
this.gen.if(condition);
|
|
2509
|
+
if (failAction)
|
|
2510
|
+
failAction();
|
|
2511
|
+
else
|
|
2564
2512
|
this.error();
|
|
2513
|
+
if (successAction) {
|
|
2514
|
+
this.gen.else();
|
|
2515
|
+
successAction();
|
|
2516
|
+
if (this.allErrors)
|
|
2517
|
+
this.gen.endIf();
|
|
2518
|
+
} else {
|
|
2565
2519
|
if (this.allErrors)
|
|
2566
2520
|
this.gen.endIf();
|
|
2567
2521
|
else
|
|
2568
2522
|
this.gen.else();
|
|
2569
2523
|
}
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
if (errorParams) {
|
|
2578
|
-
this.setParams(errorParams);
|
|
2579
|
-
this._error(append, errorPaths);
|
|
2580
|
-
this.setParams({});
|
|
2581
|
-
return;
|
|
2582
|
-
}
|
|
2583
|
-
this._error(append, errorPaths);
|
|
2584
|
-
}
|
|
2585
|
-
_error(append, errorPaths) {
|
|
2586
|
-
(append ? errors_12.reportExtraError : errors_12.reportError)(this, this.def.error, errorPaths);
|
|
2587
|
-
}
|
|
2588
|
-
$dataError() {
|
|
2589
|
-
(0, errors_12.reportError)(this, this.def.$dataError || errors_12.keyword$DataError);
|
|
2590
|
-
}
|
|
2591
|
-
reset() {
|
|
2592
|
-
if (this.errsCount === void 0)
|
|
2593
|
-
throw new Error('add "trackErrors" to keyword definition');
|
|
2594
|
-
(0, errors_12.resetErrorsCount)(this.gen, this.errsCount);
|
|
2595
|
-
}
|
|
2596
|
-
ok(cond) {
|
|
2524
|
+
}
|
|
2525
|
+
pass(condition, failAction) {
|
|
2526
|
+
this.failResult((0, codegen_1$n.not)(condition), void 0, failAction);
|
|
2527
|
+
}
|
|
2528
|
+
fail(condition) {
|
|
2529
|
+
if (condition === void 0) {
|
|
2530
|
+
this.error();
|
|
2597
2531
|
if (!this.allErrors)
|
|
2598
|
-
this.gen.if(
|
|
2532
|
+
this.gen.if(false);
|
|
2533
|
+
return;
|
|
2599
2534
|
}
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2535
|
+
this.gen.if(condition);
|
|
2536
|
+
this.error();
|
|
2537
|
+
if (this.allErrors)
|
|
2538
|
+
this.gen.endIf();
|
|
2539
|
+
else
|
|
2540
|
+
this.gen.else();
|
|
2541
|
+
}
|
|
2542
|
+
fail$data(condition) {
|
|
2543
|
+
if (!this.$data)
|
|
2544
|
+
return this.fail(condition);
|
|
2545
|
+
const { schemaCode } = this;
|
|
2546
|
+
this.fail((0, codegen_1$n._)`${schemaCode} !== undefined && (${(0, codegen_1$n.or)(this.invalid$data(), condition)})`);
|
|
2547
|
+
}
|
|
2548
|
+
error(append, errorParams, errorPaths) {
|
|
2549
|
+
if (errorParams) {
|
|
2550
|
+
this.setParams(errorParams);
|
|
2551
|
+
this._error(append, errorPaths);
|
|
2552
|
+
this.setParams({});
|
|
2553
|
+
return;
|
|
2605
2554
|
}
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2555
|
+
this._error(append, errorPaths);
|
|
2556
|
+
}
|
|
2557
|
+
_error(append, errorPaths) {
|
|
2558
|
+
(append ? errors_1.reportExtraError : errors_1.reportError)(this, this.def.error, errorPaths);
|
|
2559
|
+
}
|
|
2560
|
+
$dataError() {
|
|
2561
|
+
(0, errors_1.reportError)(this, this.def.$dataError || errors_1.keyword$DataError);
|
|
2562
|
+
}
|
|
2563
|
+
reset() {
|
|
2564
|
+
if (this.errsCount === void 0)
|
|
2565
|
+
throw new Error('add "trackErrors" to keyword definition');
|
|
2566
|
+
(0, errors_1.resetErrorsCount)(this.gen, this.errsCount);
|
|
2567
|
+
}
|
|
2568
|
+
ok(cond) {
|
|
2569
|
+
if (!this.allErrors)
|
|
2570
|
+
this.gen.if(cond);
|
|
2571
|
+
}
|
|
2572
|
+
setParams(obj, assign) {
|
|
2573
|
+
if (assign)
|
|
2574
|
+
Object.assign(this.params, obj);
|
|
2575
|
+
else
|
|
2576
|
+
this.params = obj;
|
|
2577
|
+
}
|
|
2578
|
+
block$data(valid, codeBlock, $dataValid = codegen_1$n.nil) {
|
|
2579
|
+
this.gen.block(() => {
|
|
2580
|
+
this.check$data(valid, $dataValid);
|
|
2581
|
+
codeBlock();
|
|
2582
|
+
});
|
|
2583
|
+
}
|
|
2584
|
+
check$data(valid = codegen_1$n.nil, $dataValid = codegen_1$n.nil) {
|
|
2585
|
+
if (!this.$data)
|
|
2586
|
+
return;
|
|
2587
|
+
const { gen, schemaCode, schemaType, def: def2 } = this;
|
|
2588
|
+
gen.if((0, codegen_1$n.or)((0, codegen_1$n._)`${schemaCode} === undefined`, $dataValid));
|
|
2589
|
+
if (valid !== codegen_1$n.nil)
|
|
2590
|
+
gen.assign(valid, true);
|
|
2591
|
+
if (schemaType.length || def2.validateSchema) {
|
|
2592
|
+
gen.elseIf(this.invalid$data());
|
|
2593
|
+
this.$dataError();
|
|
2594
|
+
if (valid !== codegen_1$n.nil)
|
|
2595
|
+
gen.assign(valid, false);
|
|
2611
2596
|
}
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
gen.assign(valid, false);
|
|
2597
|
+
gen.else();
|
|
2598
|
+
}
|
|
2599
|
+
invalid$data() {
|
|
2600
|
+
const { gen, schemaCode, schemaType, def: def2, it } = this;
|
|
2601
|
+
return (0, codegen_1$n.or)(wrong$DataType(), invalid$DataSchema());
|
|
2602
|
+
function wrong$DataType() {
|
|
2603
|
+
if (schemaType.length) {
|
|
2604
|
+
if (!(schemaCode instanceof codegen_1$n.Name))
|
|
2605
|
+
throw new Error("ajv implementation error");
|
|
2606
|
+
const st = Array.isArray(schemaType) ? schemaType : [schemaType];
|
|
2607
|
+
return (0, codegen_1$n._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
|
|
2624
2608
|
}
|
|
2625
|
-
|
|
2609
|
+
return codegen_1$n.nil;
|
|
2626
2610
|
}
|
|
2627
|
-
invalid$
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
if (schemaType.length) {
|
|
2632
|
-
if (!(schemaCode instanceof codegen_12.Name))
|
|
2633
|
-
throw new Error("ajv implementation error");
|
|
2634
|
-
const st = Array.isArray(schemaType) ? schemaType : [schemaType];
|
|
2635
|
-
return (0, codegen_12._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
|
|
2636
|
-
}
|
|
2637
|
-
return codegen_12.nil;
|
|
2638
|
-
}
|
|
2639
|
-
function invalid$DataSchema() {
|
|
2640
|
-
if (def2.validateSchema) {
|
|
2641
|
-
const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
|
|
2642
|
-
return (0, codegen_12._)`!${validateSchemaRef}(${schemaCode})`;
|
|
2643
|
-
}
|
|
2644
|
-
return codegen_12.nil;
|
|
2645
|
-
}
|
|
2646
|
-
}
|
|
2647
|
-
subschema(appl, valid) {
|
|
2648
|
-
const subschema2 = (0, subschema_1.getSubschema)(this.it, appl);
|
|
2649
|
-
(0, subschema_1.extendSubschemaData)(subschema2, this.it, appl);
|
|
2650
|
-
(0, subschema_1.extendSubschemaMode)(subschema2, appl);
|
|
2651
|
-
const nextContext = { ...this.it, ...subschema2, items: void 0, props: void 0 };
|
|
2652
|
-
subschemaCode(nextContext, valid);
|
|
2653
|
-
return nextContext;
|
|
2654
|
-
}
|
|
2655
|
-
mergeEvaluated(schemaCxt, toName) {
|
|
2656
|
-
const { it, gen } = this;
|
|
2657
|
-
if (!it.opts.unevaluated)
|
|
2658
|
-
return;
|
|
2659
|
-
if (it.props !== true && schemaCxt.props !== void 0) {
|
|
2660
|
-
it.props = util_12.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
|
|
2661
|
-
}
|
|
2662
|
-
if (it.items !== true && schemaCxt.items !== void 0) {
|
|
2663
|
-
it.items = util_12.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
|
|
2611
|
+
function invalid$DataSchema() {
|
|
2612
|
+
if (def2.validateSchema) {
|
|
2613
|
+
const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
|
|
2614
|
+
return (0, codegen_1$n._)`!${validateSchemaRef}(${schemaCode})`;
|
|
2664
2615
|
}
|
|
2616
|
+
return codegen_1$n.nil;
|
|
2665
2617
|
}
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2618
|
+
}
|
|
2619
|
+
subschema(appl, valid) {
|
|
2620
|
+
const subschema2 = (0, subschema_1.getSubschema)(this.it, appl);
|
|
2621
|
+
(0, subschema_1.extendSubschemaData)(subschema2, this.it, appl);
|
|
2622
|
+
(0, subschema_1.extendSubschemaMode)(subschema2, appl);
|
|
2623
|
+
const nextContext = { ...this.it, ...subschema2, items: void 0, props: void 0 };
|
|
2624
|
+
subschemaCode(nextContext, valid);
|
|
2625
|
+
return nextContext;
|
|
2626
|
+
}
|
|
2627
|
+
mergeEvaluated(schemaCxt, toName) {
|
|
2628
|
+
const { it, gen } = this;
|
|
2629
|
+
if (!it.opts.unevaluated)
|
|
2630
|
+
return;
|
|
2631
|
+
if (it.props !== true && schemaCxt.props !== void 0) {
|
|
2632
|
+
it.props = util_1$l.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
|
|
2633
|
+
}
|
|
2634
|
+
if (it.items !== true && schemaCxt.items !== void 0) {
|
|
2635
|
+
it.items = util_1$l.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
mergeValidEvaluated(schemaCxt, valid) {
|
|
2639
|
+
const { it, gen } = this;
|
|
2640
|
+
if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
|
|
2641
|
+
gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_1$n.Name));
|
|
2642
|
+
return true;
|
|
2672
2643
|
}
|
|
2673
2644
|
}
|
|
2674
|
-
validate$2.KeywordCxt = KeywordCxt;
|
|
2675
|
-
function keywordCode(it, keyword2, def2, ruleType) {
|
|
2676
|
-
const cxt = new KeywordCxt(it, def2, keyword2);
|
|
2677
|
-
if ("code" in def2) {
|
|
2678
|
-
def2.code(cxt, ruleType);
|
|
2679
|
-
} else if (cxt.$data && def2.validate) {
|
|
2680
|
-
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2681
|
-
} else if ("macro" in def2) {
|
|
2682
|
-
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
2683
|
-
} else if (def2.compile || def2.validate) {
|
|
2684
|
-
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
|
-
const JSON_POINTER2 = /^\/(?:[^~]|~0|~1)*$/;
|
|
2688
|
-
const RELATIVE_JSON_POINTER2 = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
2689
|
-
function getData2($data, { dataLevel, dataNames, dataPathArr }) {
|
|
2690
|
-
let jsonPointer;
|
|
2691
|
-
let data2;
|
|
2692
|
-
if ($data === "")
|
|
2693
|
-
return names_12.default.rootData;
|
|
2694
|
-
if ($data[0] === "/") {
|
|
2695
|
-
if (!JSON_POINTER2.test($data))
|
|
2696
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2697
|
-
jsonPointer = $data;
|
|
2698
|
-
data2 = names_12.default.rootData;
|
|
2699
|
-
} else {
|
|
2700
|
-
const matches = RELATIVE_JSON_POINTER2.exec($data);
|
|
2701
|
-
if (!matches)
|
|
2702
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2703
|
-
const up = +matches[1];
|
|
2704
|
-
jsonPointer = matches[2];
|
|
2705
|
-
if (jsonPointer === "#") {
|
|
2706
|
-
if (up >= dataLevel)
|
|
2707
|
-
throw new Error(errorMsg("property/index", up));
|
|
2708
|
-
return dataPathArr[dataLevel - up];
|
|
2709
|
-
}
|
|
2710
|
-
if (up > dataLevel)
|
|
2711
|
-
throw new Error(errorMsg("data", up));
|
|
2712
|
-
data2 = dataNames[dataLevel - up];
|
|
2713
|
-
if (!jsonPointer)
|
|
2714
|
-
return data2;
|
|
2715
|
-
}
|
|
2716
|
-
let expr = data2;
|
|
2717
|
-
const segments = jsonPointer.split("/");
|
|
2718
|
-
for (const segment of segments) {
|
|
2719
|
-
if (segment) {
|
|
2720
|
-
data2 = (0, codegen_12._)`${data2}${(0, codegen_12.getProperty)((0, util_12.unescapeJsonPointer)(segment))}`;
|
|
2721
|
-
expr = (0, codegen_12._)`${expr} && ${data2}`;
|
|
2722
|
-
}
|
|
2723
|
-
}
|
|
2724
|
-
return expr;
|
|
2725
|
-
function errorMsg(pointerType, up) {
|
|
2726
|
-
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
2727
|
-
}
|
|
2728
|
-
}
|
|
2729
|
-
validate$2.getData = getData2;
|
|
2730
|
-
return validate$2;
|
|
2731
2645
|
}
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
if (
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2646
|
+
validate$2.KeywordCxt = KeywordCxt;
|
|
2647
|
+
function keywordCode(it, keyword2, def2, ruleType) {
|
|
2648
|
+
const cxt = new KeywordCxt(it, def2, keyword2);
|
|
2649
|
+
if ("code" in def2) {
|
|
2650
|
+
def2.code(cxt, ruleType);
|
|
2651
|
+
} else if (cxt.$data && def2.validate) {
|
|
2652
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2653
|
+
} else if ("macro" in def2) {
|
|
2654
|
+
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
2655
|
+
} else if (def2.compile || def2.validate) {
|
|
2656
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
const JSON_POINTER$2 = /^\/(?:[^~]|~0|~1)*$/;
|
|
2660
|
+
const RELATIVE_JSON_POINTER$2 = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
2661
|
+
function getData$1($data, { dataLevel, dataNames, dataPathArr }) {
|
|
2662
|
+
let jsonPointer;
|
|
2663
|
+
let data2;
|
|
2664
|
+
if ($data === "")
|
|
2665
|
+
return names_1$3.default.rootData;
|
|
2666
|
+
if ($data[0] === "/") {
|
|
2667
|
+
if (!JSON_POINTER$2.test($data))
|
|
2668
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2669
|
+
jsonPointer = $data;
|
|
2670
|
+
data2 = names_1$3.default.rootData;
|
|
2671
|
+
} else {
|
|
2672
|
+
const matches = RELATIVE_JSON_POINTER$2.exec($data);
|
|
2673
|
+
if (!matches)
|
|
2674
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2675
|
+
const up = +matches[1];
|
|
2676
|
+
jsonPointer = matches[2];
|
|
2677
|
+
if (jsonPointer === "#") {
|
|
2678
|
+
if (up >= dataLevel)
|
|
2679
|
+
throw new Error(errorMsg("property/index", up));
|
|
2680
|
+
return dataPathArr[dataLevel - up];
|
|
2681
|
+
}
|
|
2682
|
+
if (up > dataLevel)
|
|
2683
|
+
throw new Error(errorMsg("data", up));
|
|
2684
|
+
data2 = dataNames[dataLevel - up];
|
|
2685
|
+
if (!jsonPointer)
|
|
2686
|
+
return data2;
|
|
2687
|
+
}
|
|
2688
|
+
let expr = data2;
|
|
2689
|
+
const segments = jsonPointer.split("/");
|
|
2690
|
+
for (const segment of segments) {
|
|
2691
|
+
if (segment) {
|
|
2692
|
+
data2 = (0, codegen_1$n._)`${data2}${(0, codegen_1$n.getProperty)((0, util_1$l.unescapeJsonPointer)(segment))}`;
|
|
2693
|
+
expr = (0, codegen_1$n._)`${expr} && ${data2}`;
|
|
2743
2694
|
}
|
|
2744
2695
|
}
|
|
2745
|
-
|
|
2746
|
-
|
|
2696
|
+
return expr;
|
|
2697
|
+
function errorMsg(pointerType, up) {
|
|
2698
|
+
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
2699
|
+
}
|
|
2747
2700
|
}
|
|
2701
|
+
validate$2.getData = getData$1;
|
|
2702
|
+
var validation_error = {};
|
|
2703
|
+
Object.defineProperty(validation_error, "__esModule", { value: true });
|
|
2704
|
+
let ValidationError$2 = class ValidationError extends Error {
|
|
2705
|
+
constructor(errors2) {
|
|
2706
|
+
super("validation failed");
|
|
2707
|
+
this.errors = errors2;
|
|
2708
|
+
this.ajv = this.validation = true;
|
|
2709
|
+
}
|
|
2710
|
+
};
|
|
2711
|
+
validation_error.default = ValidationError$2;
|
|
2748
2712
|
var ref_error = {};
|
|
2749
2713
|
Object.defineProperty(ref_error, "__esModule", { value: true });
|
|
2750
2714
|
const resolve_1$2 = resolve$7;
|
|
@@ -2760,11 +2724,11 @@ var compile$2 = {};
|
|
|
2760
2724
|
Object.defineProperty(compile$2, "__esModule", { value: true });
|
|
2761
2725
|
compile$2.resolveSchema = compile$2.getCompilingSchema = compile$2.resolveRef = compile$2.compileSchema = compile$2.SchemaEnv = void 0;
|
|
2762
2726
|
const codegen_1$m = codegen;
|
|
2763
|
-
const validation_error_1 =
|
|
2727
|
+
const validation_error_1 = validation_error;
|
|
2764
2728
|
const names_1$2 = names$1;
|
|
2765
2729
|
const resolve_1$1 = resolve$7;
|
|
2766
2730
|
const util_1$k = util$7;
|
|
2767
|
-
const validate_1$1 =
|
|
2731
|
+
const validate_1$1 = validate$2;
|
|
2768
2732
|
class SchemaEnv {
|
|
2769
2733
|
constructor(env) {
|
|
2770
2734
|
var _a16;
|
|
@@ -3651,7 +3615,7 @@ uri$2.default = uri$1;
|
|
|
3651
3615
|
(function(exports2) {
|
|
3652
3616
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3653
3617
|
exports2.CodeGen = exports2.Name = exports2.nil = exports2.stringify = exports2.str = exports2._ = exports2.KeywordCxt = void 0;
|
|
3654
|
-
var validate_12 =
|
|
3618
|
+
var validate_12 = validate$2;
|
|
3655
3619
|
Object.defineProperty(exports2, "KeywordCxt", { enumerable: true, get: function() {
|
|
3656
3620
|
return validate_12.KeywordCxt;
|
|
3657
3621
|
} });
|
|
@@ -3674,7 +3638,7 @@ uri$2.default = uri$1;
|
|
|
3674
3638
|
Object.defineProperty(exports2, "CodeGen", { enumerable: true, get: function() {
|
|
3675
3639
|
return codegen_12.CodeGen;
|
|
3676
3640
|
} });
|
|
3677
|
-
const validation_error_12 =
|
|
3641
|
+
const validation_error_12 = validation_error;
|
|
3678
3642
|
const ref_error_12 = ref_error;
|
|
3679
3643
|
const rules_12 = rules$2;
|
|
3680
3644
|
const compile_12 = compile$2;
|
|
@@ -5253,7 +5217,7 @@ const def$a = {
|
|
|
5253
5217
|
additionalProperties$1.default = def$a;
|
|
5254
5218
|
var properties$4 = {};
|
|
5255
5219
|
Object.defineProperty(properties$4, "__esModule", { value: true });
|
|
5256
|
-
const validate_1 =
|
|
5220
|
+
const validate_1 = validate$2;
|
|
5257
5221
|
const code_1$2 = code;
|
|
5258
5222
|
const util_1$7 = util$7;
|
|
5259
5223
|
const additionalProperties_1$1 = additionalProperties$1;
|
|
@@ -6104,7 +6068,7 @@ const require$$3 = {
|
|
|
6104
6068
|
module2.exports.Ajv = Ajv2;
|
|
6105
6069
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
6106
6070
|
exports2.default = Ajv2;
|
|
6107
|
-
var validate_12 =
|
|
6071
|
+
var validate_12 = validate$2;
|
|
6108
6072
|
Object.defineProperty(exports2, "KeywordCxt", { enumerable: true, get: function() {
|
|
6109
6073
|
return validate_12.KeywordCxt;
|
|
6110
6074
|
} });
|
|
@@ -6127,7 +6091,7 @@ const require$$3 = {
|
|
|
6127
6091
|
Object.defineProperty(exports2, "CodeGen", { enumerable: true, get: function() {
|
|
6128
6092
|
return codegen_12.CodeGen;
|
|
6129
6093
|
} });
|
|
6130
|
-
var validation_error_12 =
|
|
6094
|
+
var validation_error_12 = validation_error;
|
|
6131
6095
|
Object.defineProperty(exports2, "ValidationError", { enumerable: true, get: function() {
|
|
6132
6096
|
return validation_error_12.default;
|
|
6133
6097
|
} });
|
|
@@ -13527,7 +13491,7 @@ var resolve$2 = resolve_1, util$2 = util$5, errorClasses$1 = error_classes, stab
|
|
|
13527
13491
|
var validateGenerator = validate$1;
|
|
13528
13492
|
var ucs2length2 = util$2.ucs2length;
|
|
13529
13493
|
var equal2 = fastDeepEqual;
|
|
13530
|
-
var
|
|
13494
|
+
var ValidationError2 = errorClasses$1.Validation;
|
|
13531
13495
|
var compile_1 = compile$1;
|
|
13532
13496
|
function compile$1(schema, root, localRefs, baseId) {
|
|
13533
13497
|
var self2 = this, opts = this._opts, refVal = [void 0], refs = {}, patterns = [], patternsHash = {}, defaults2 = [], defaultsHash = {}, customRules = [];
|
|
@@ -13615,7 +13579,7 @@ function compile$1(schema, root, localRefs, baseId) {
|
|
|
13615
13579
|
customRules,
|
|
13616
13580
|
equal2,
|
|
13617
13581
|
ucs2length2,
|
|
13618
|
-
|
|
13582
|
+
ValidationError2
|
|
13619
13583
|
);
|
|
13620
13584
|
refVal[0] = validate2;
|
|
13621
13585
|
} catch (e) {
|