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