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