create-ones-app 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +848 -897
- package/dist/index.js +848 -897
- package/dist/types/common/package/types.d.ts +1 -1
- package/dist/types/common/package/types.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1056,8 +1056,8 @@ var scope = {};
|
|
|
1056
1056
|
var util = {};
|
|
1057
1057
|
Object.defineProperty(util, "__esModule", { value: true });
|
|
1058
1058
|
util.checkStrictMode = util.getErrorPath = util.Type = util.useFunc = util.setEvaluated = util.evaluatedPropsToName = util.mergeEvaluated = util.eachItem = util.unescapeJsonPointer = util.escapeJsonPointer = util.escapeFragment = util.unescapeFragment = util.schemaRefOrVal = util.schemaHasRulesButRef = util.schemaHasRules = util.checkUnknownRules = util.alwaysValidSchema = util.toHash = void 0;
|
|
1059
|
-
const codegen_1$
|
|
1060
|
-
const code_1$
|
|
1059
|
+
const codegen_1$z = codegen;
|
|
1060
|
+
const code_1$a = code$1;
|
|
1061
1061
|
function toHash(arr) {
|
|
1062
1062
|
const hash = {};
|
|
1063
1063
|
for (const item of arr)
|
|
@@ -1110,9 +1110,9 @@ function schemaRefOrVal({ topSchemaRef, schemaPath }, schema, keyword2, $data) {
|
|
|
1110
1110
|
if (typeof schema == "number" || typeof schema == "boolean")
|
|
1111
1111
|
return schema;
|
|
1112
1112
|
if (typeof schema == "string")
|
|
1113
|
-
return (0, codegen_1$
|
|
1113
|
+
return (0, codegen_1$z._)`${schema}`;
|
|
1114
1114
|
}
|
|
1115
|
-
return (0, codegen_1$
|
|
1115
|
+
return (0, codegen_1$z._)`${topSchemaRef}${schemaPath}${(0, codegen_1$z.getProperty)(keyword2)}`;
|
|
1116
1116
|
}
|
|
1117
1117
|
util.schemaRefOrVal = schemaRefOrVal;
|
|
1118
1118
|
function unescapeFragment(str) {
|
|
@@ -1144,20 +1144,20 @@ function eachItem(xs, f) {
|
|
|
1144
1144
|
util.eachItem = eachItem;
|
|
1145
1145
|
function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues, resultToName }) {
|
|
1146
1146
|
return (gen, from, to, toName) => {
|
|
1147
|
-
const res = to === void 0 ? from : to instanceof codegen_1$
|
|
1148
|
-
return toName === codegen_1$
|
|
1147
|
+
const res = to === void 0 ? from : to instanceof codegen_1$z.Name ? (from instanceof codegen_1$z.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1$z.Name ? (mergeToName(gen, to, from), from) : mergeValues(from, to);
|
|
1148
|
+
return toName === codegen_1$z.Name && !(res instanceof codegen_1$z.Name) ? resultToName(gen, res) : res;
|
|
1149
1149
|
};
|
|
1150
1150
|
}
|
|
1151
1151
|
util.mergeEvaluated = {
|
|
1152
1152
|
props: makeMergeEvaluated({
|
|
1153
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
1154
|
-
gen.if((0, codegen_1$
|
|
1153
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$z._)`${to} !== true && ${from} !== undefined`, () => {
|
|
1154
|
+
gen.if((0, codegen_1$z._)`${from} === true`, () => gen.assign(to, true), () => gen.assign(to, (0, codegen_1$z._)`${to} || {}`).code((0, codegen_1$z._)`Object.assign(${to}, ${from})`));
|
|
1155
1155
|
}),
|
|
1156
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
1156
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$z._)`${to} !== true`, () => {
|
|
1157
1157
|
if (from === true) {
|
|
1158
1158
|
gen.assign(to, true);
|
|
1159
1159
|
} else {
|
|
1160
|
-
gen.assign(to, (0, codegen_1$
|
|
1160
|
+
gen.assign(to, (0, codegen_1$z._)`${to} || {}`);
|
|
1161
1161
|
setEvaluated(gen, to, from);
|
|
1162
1162
|
}
|
|
1163
1163
|
}),
|
|
@@ -1165,8 +1165,8 @@ util.mergeEvaluated = {
|
|
|
1165
1165
|
resultToName: evaluatedPropsToName
|
|
1166
1166
|
}),
|
|
1167
1167
|
items: makeMergeEvaluated({
|
|
1168
|
-
mergeNames: (gen, from, to) => gen.if((0, codegen_1$
|
|
1169
|
-
mergeToName: (gen, from, to) => gen.if((0, codegen_1$
|
|
1168
|
+
mergeNames: (gen, from, to) => gen.if((0, codegen_1$z._)`${to} !== true && ${from} !== undefined`, () => gen.assign(to, (0, codegen_1$z._)`${from} === true ? true : ${to} > ${from} ? ${to} : ${from}`)),
|
|
1169
|
+
mergeToName: (gen, from, to) => gen.if((0, codegen_1$z._)`${to} !== true`, () => gen.assign(to, from === true ? true : (0, codegen_1$z._)`${to} > ${from} ? ${to} : ${from}`)),
|
|
1170
1170
|
mergeValues: (from, to) => from === true ? true : Math.max(from, to),
|
|
1171
1171
|
resultToName: (gen, items2) => gen.var("items", items2)
|
|
1172
1172
|
})
|
|
@@ -1174,21 +1174,21 @@ util.mergeEvaluated = {
|
|
|
1174
1174
|
function evaluatedPropsToName(gen, ps) {
|
|
1175
1175
|
if (ps === true)
|
|
1176
1176
|
return gen.var("props", true);
|
|
1177
|
-
const props = gen.var("props", (0, codegen_1$
|
|
1177
|
+
const props = gen.var("props", (0, codegen_1$z._)`{}`);
|
|
1178
1178
|
if (ps !== void 0)
|
|
1179
1179
|
setEvaluated(gen, props, ps);
|
|
1180
1180
|
return props;
|
|
1181
1181
|
}
|
|
1182
1182
|
util.evaluatedPropsToName = evaluatedPropsToName;
|
|
1183
1183
|
function setEvaluated(gen, props, ps) {
|
|
1184
|
-
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$
|
|
1184
|
+
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$z._)`${props}${(0, codegen_1$z.getProperty)(p)}`, true));
|
|
1185
1185
|
}
|
|
1186
1186
|
util.setEvaluated = setEvaluated;
|
|
1187
1187
|
const snippets = {};
|
|
1188
1188
|
function useFunc(gen, f) {
|
|
1189
1189
|
return gen.scopeValue("func", {
|
|
1190
1190
|
ref: f,
|
|
1191
|
-
code: snippets[f.code] || (snippets[f.code] = new code_1$
|
|
1191
|
+
code: snippets[f.code] || (snippets[f.code] = new code_1$a._Code(f.code))
|
|
1192
1192
|
});
|
|
1193
1193
|
}
|
|
1194
1194
|
util.useFunc = useFunc;
|
|
@@ -1198,11 +1198,11 @@ var Type;
|
|
|
1198
1198
|
Type2[Type2["Str"] = 1] = "Str";
|
|
1199
1199
|
})(Type || (util.Type = Type = {}));
|
|
1200
1200
|
function getErrorPath(dataProp, dataPropType, jsPropertySyntax) {
|
|
1201
|
-
if (dataProp instanceof codegen_1$
|
|
1201
|
+
if (dataProp instanceof codegen_1$z.Name) {
|
|
1202
1202
|
const isNumber = dataPropType === Type.Num;
|
|
1203
|
-
return jsPropertySyntax ? isNumber ? (0, codegen_1$
|
|
1203
|
+
return jsPropertySyntax ? isNumber ? (0, codegen_1$z._)`"[" + ${dataProp} + "]"` : (0, codegen_1$z._)`"['" + ${dataProp} + "']"` : isNumber ? (0, codegen_1$z._)`"/" + ${dataProp}` : (0, codegen_1$z._)`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")`;
|
|
1204
1204
|
}
|
|
1205
|
-
return jsPropertySyntax ? (0, codegen_1$
|
|
1205
|
+
return jsPropertySyntax ? (0, codegen_1$z.getProperty)(dataProp).toString() : "/" + escapeJsonPointer(dataProp);
|
|
1206
1206
|
}
|
|
1207
1207
|
util.getErrorPath = getErrorPath;
|
|
1208
1208
|
function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
@@ -1214,52 +1214,45 @@ function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
|
|
|
1214
1214
|
it.self.logger.warn(msg);
|
|
1215
1215
|
}
|
|
1216
1216
|
util.checkStrictMode = checkStrictMode;
|
|
1217
|
-
var names = {};
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
jsonPos: new codegen_12.Name("jsonPos"),
|
|
1251
|
-
jsonLen: new codegen_12.Name("jsonLen"),
|
|
1252
|
-
jsonPart: new codegen_12.Name("jsonPart")
|
|
1253
|
-
};
|
|
1254
|
-
names.default = names$1;
|
|
1255
|
-
return names;
|
|
1256
|
-
}
|
|
1217
|
+
var names$1 = {};
|
|
1218
|
+
Object.defineProperty(names$1, "__esModule", { value: true });
|
|
1219
|
+
const codegen_1$y = codegen;
|
|
1220
|
+
const names = {
|
|
1221
|
+
// validation function arguments
|
|
1222
|
+
data: new codegen_1$y.Name("data"),
|
|
1223
|
+
// data passed to validation function
|
|
1224
|
+
// args passed from referencing schema
|
|
1225
|
+
valCxt: new codegen_1$y.Name("valCxt"),
|
|
1226
|
+
// validation/data context - should not be used directly, it is destructured to the names below
|
|
1227
|
+
instancePath: new codegen_1$y.Name("instancePath"),
|
|
1228
|
+
parentData: new codegen_1$y.Name("parentData"),
|
|
1229
|
+
parentDataProperty: new codegen_1$y.Name("parentDataProperty"),
|
|
1230
|
+
rootData: new codegen_1$y.Name("rootData"),
|
|
1231
|
+
// root data - same as the data passed to the first/top validation function
|
|
1232
|
+
dynamicAnchors: new codegen_1$y.Name("dynamicAnchors"),
|
|
1233
|
+
// used to support recursiveRef and dynamicRef
|
|
1234
|
+
// function scoped variables
|
|
1235
|
+
vErrors: new codegen_1$y.Name("vErrors"),
|
|
1236
|
+
// null or array of validation errors
|
|
1237
|
+
errors: new codegen_1$y.Name("errors"),
|
|
1238
|
+
// counter of validation errors
|
|
1239
|
+
this: new codegen_1$y.Name("this"),
|
|
1240
|
+
// "globals"
|
|
1241
|
+
self: new codegen_1$y.Name("self"),
|
|
1242
|
+
scope: new codegen_1$y.Name("scope"),
|
|
1243
|
+
// JTD serialize/parse name for JSON string and position
|
|
1244
|
+
json: new codegen_1$y.Name("json"),
|
|
1245
|
+
jsonPos: new codegen_1$y.Name("jsonPos"),
|
|
1246
|
+
jsonLen: new codegen_1$y.Name("jsonLen"),
|
|
1247
|
+
jsonPart: new codegen_1$y.Name("jsonPart")
|
|
1248
|
+
};
|
|
1249
|
+
names$1.default = names;
|
|
1257
1250
|
(function(exports2) {
|
|
1258
1251
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1259
1252
|
exports2.extendErrors = exports2.resetErrorsCount = exports2.reportExtraError = exports2.reportError = exports2.keyword$DataError = exports2.keywordError = void 0;
|
|
1260
1253
|
const codegen_12 = codegen;
|
|
1261
1254
|
const util_12 = util;
|
|
1262
|
-
const names_12 =
|
|
1255
|
+
const names_12 = names$1;
|
|
1263
1256
|
exports2.keywordError = {
|
|
1264
1257
|
message: ({ keyword: keyword2 }) => (0, codegen_12.str)`must pass "${keyword2}" keyword validation`
|
|
1265
1258
|
};
|
|
@@ -1371,56 +1364,49 @@ function requireNames() {
|
|
|
1371
1364
|
keyValues.push([E.propertyName, propertyName]);
|
|
1372
1365
|
}
|
|
1373
1366
|
})(errors);
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
const
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
} else if (typeof schema == "object" && schema.$async === true) {
|
|
1392
|
-
gen.return(names_12.default.data);
|
|
1393
|
-
} else {
|
|
1394
|
-
gen.assign((0, codegen_12._)`${validateName}.errors`, null);
|
|
1395
|
-
gen.return(true);
|
|
1396
|
-
}
|
|
1367
|
+
Object.defineProperty(boolSchema, "__esModule", { value: true });
|
|
1368
|
+
boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
|
|
1369
|
+
const errors_1$3 = errors;
|
|
1370
|
+
const codegen_1$x = codegen;
|
|
1371
|
+
const names_1$9 = names$1;
|
|
1372
|
+
const boolError = {
|
|
1373
|
+
message: "boolean schema is false"
|
|
1374
|
+
};
|
|
1375
|
+
function topBoolOrEmptySchema(it) {
|
|
1376
|
+
const { gen, schema, validateName } = it;
|
|
1377
|
+
if (schema === false) {
|
|
1378
|
+
falseSchemaError(it, false);
|
|
1379
|
+
} else if (typeof schema == "object" && schema.$async === true) {
|
|
1380
|
+
gen.return(names_1$9.default.data);
|
|
1381
|
+
} else {
|
|
1382
|
+
gen.assign((0, codegen_1$x._)`${validateName}.errors`, null);
|
|
1383
|
+
gen.return(true);
|
|
1397
1384
|
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
}
|
|
1408
|
-
boolSchema.boolOrEmptySchema = boolOrEmptySchema;
|
|
1409
|
-
function falseSchemaError(it, overrideAllErrors) {
|
|
1410
|
-
const { gen, data } = it;
|
|
1411
|
-
const cxt = {
|
|
1412
|
-
gen,
|
|
1413
|
-
keyword: "false schema",
|
|
1414
|
-
data,
|
|
1415
|
-
schema: false,
|
|
1416
|
-
schemaCode: false,
|
|
1417
|
-
schemaValue: false,
|
|
1418
|
-
params: {},
|
|
1419
|
-
it
|
|
1420
|
-
};
|
|
1421
|
-
(0, errors_12.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
1385
|
+
}
|
|
1386
|
+
boolSchema.topBoolOrEmptySchema = topBoolOrEmptySchema;
|
|
1387
|
+
function boolOrEmptySchema(it, valid) {
|
|
1388
|
+
const { gen, schema } = it;
|
|
1389
|
+
if (schema === false) {
|
|
1390
|
+
gen.var(valid, false);
|
|
1391
|
+
falseSchemaError(it);
|
|
1392
|
+
} else {
|
|
1393
|
+
gen.var(valid, true);
|
|
1422
1394
|
}
|
|
1423
|
-
|
|
1395
|
+
}
|
|
1396
|
+
boolSchema.boolOrEmptySchema = boolOrEmptySchema;
|
|
1397
|
+
function falseSchemaError(it, overrideAllErrors) {
|
|
1398
|
+
const { gen, data } = it;
|
|
1399
|
+
const cxt = {
|
|
1400
|
+
gen,
|
|
1401
|
+
keyword: "false schema",
|
|
1402
|
+
data,
|
|
1403
|
+
schema: false,
|
|
1404
|
+
schemaCode: false,
|
|
1405
|
+
schemaValue: false,
|
|
1406
|
+
params: {},
|
|
1407
|
+
it
|
|
1408
|
+
};
|
|
1409
|
+
(0, errors_1$3.reportError)(cxt, boolError, void 0, overrideAllErrors);
|
|
1424
1410
|
}
|
|
1425
1411
|
var dataType = {};
|
|
1426
1412
|
var rules = {};
|
|
@@ -1449,36 +1435,29 @@ function getRules() {
|
|
|
1449
1435
|
}
|
|
1450
1436
|
rules.getRules = getRules;
|
|
1451
1437
|
var applicability = {};
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
}
|
|
1467
|
-
applicability.shouldUseGroup = shouldUseGroup;
|
|
1468
|
-
function shouldUseRule(schema, rule) {
|
|
1469
|
-
var _a;
|
|
1470
|
-
return schema[rule.keyword] !== void 0 || ((_a = rule.definition.implements) === null || _a === void 0 ? void 0 : _a.some((kwd) => schema[kwd] !== void 0));
|
|
1471
|
-
}
|
|
1472
|
-
applicability.shouldUseRule = shouldUseRule;
|
|
1473
|
-
return applicability;
|
|
1438
|
+
Object.defineProperty(applicability, "__esModule", { value: true });
|
|
1439
|
+
applicability.shouldUseRule = applicability.shouldUseGroup = applicability.schemaHasRulesForType = void 0;
|
|
1440
|
+
function schemaHasRulesForType({ schema, self }, type2) {
|
|
1441
|
+
const group = self.RULES.types[type2];
|
|
1442
|
+
return group && group !== true && shouldUseGroup(schema, group);
|
|
1443
|
+
}
|
|
1444
|
+
applicability.schemaHasRulesForType = schemaHasRulesForType;
|
|
1445
|
+
function shouldUseGroup(schema, group) {
|
|
1446
|
+
return group.rules.some((rule) => shouldUseRule(schema, rule));
|
|
1447
|
+
}
|
|
1448
|
+
applicability.shouldUseGroup = shouldUseGroup;
|
|
1449
|
+
function shouldUseRule(schema, rule) {
|
|
1450
|
+
var _a;
|
|
1451
|
+
return schema[rule.keyword] !== void 0 || ((_a = rule.definition.implements) === null || _a === void 0 ? void 0 : _a.some((kwd) => schema[kwd] !== void 0));
|
|
1474
1452
|
}
|
|
1453
|
+
applicability.shouldUseRule = shouldUseRule;
|
|
1475
1454
|
Object.defineProperty(dataType, "__esModule", { value: true });
|
|
1476
1455
|
dataType.reportTypeError = dataType.checkDataTypes = dataType.checkDataType = dataType.coerceAndCheckDataType = dataType.getJSONTypes = dataType.getSchemaTypes = dataType.DataType = void 0;
|
|
1477
1456
|
const rules_1 = rules;
|
|
1478
|
-
const applicability_1 =
|
|
1479
|
-
const errors_1 = errors;
|
|
1480
|
-
const codegen_1$
|
|
1481
|
-
const util_1$
|
|
1457
|
+
const applicability_1$1 = applicability;
|
|
1458
|
+
const errors_1$2 = errors;
|
|
1459
|
+
const codegen_1$w = codegen;
|
|
1460
|
+
const util_1$u = util;
|
|
1482
1461
|
var DataType;
|
|
1483
1462
|
(function(DataType2) {
|
|
1484
1463
|
DataType2[DataType2["Correct"] = 0] = "Correct";
|
|
@@ -1510,7 +1489,7 @@ dataType.getJSONTypes = getJSONTypes;
|
|
|
1510
1489
|
function coerceAndCheckDataType(it, types2) {
|
|
1511
1490
|
const { gen, data, opts } = it;
|
|
1512
1491
|
const coerceTo = coerceToTypes(types2, opts.coerceTypes);
|
|
1513
|
-
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1.schemaHasRulesForType)(it, types2[0]));
|
|
1492
|
+
const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1$1.schemaHasRulesForType)(it, types2[0]));
|
|
1514
1493
|
if (checkTypes) {
|
|
1515
1494
|
const wrongType = checkDataTypes(types2, data, opts.strictNumbers, DataType.Wrong);
|
|
1516
1495
|
gen.if(wrongType, () => {
|
|
@@ -1529,12 +1508,12 @@ function coerceToTypes(types2, coerceTypes) {
|
|
|
1529
1508
|
}
|
|
1530
1509
|
function coerceData(it, types2, coerceTo) {
|
|
1531
1510
|
const { gen, data, opts } = it;
|
|
1532
|
-
const dataType2 = gen.let("dataType", (0, codegen_1$
|
|
1533
|
-
const coerced = gen.let("coerced", (0, codegen_1$
|
|
1511
|
+
const dataType2 = gen.let("dataType", (0, codegen_1$w._)`typeof ${data}`);
|
|
1512
|
+
const coerced = gen.let("coerced", (0, codegen_1$w._)`undefined`);
|
|
1534
1513
|
if (opts.coerceTypes === "array") {
|
|
1535
|
-
gen.if((0, codegen_1$
|
|
1514
|
+
gen.if((0, codegen_1$w._)`${dataType2} == 'object' && Array.isArray(${data}) && ${data}.length == 1`, () => gen.assign(data, (0, codegen_1$w._)`${data}[0]`).assign(dataType2, (0, codegen_1$w._)`typeof ${data}`).if(checkDataTypes(types2, data, opts.strictNumbers), () => gen.assign(coerced, data)));
|
|
1536
1515
|
}
|
|
1537
|
-
gen.if((0, codegen_1$
|
|
1516
|
+
gen.if((0, codegen_1$w._)`${coerced} !== undefined`);
|
|
1538
1517
|
for (const t of coerceTo) {
|
|
1539
1518
|
if (COERCIBLE.has(t) || t === "array" && opts.coerceTypes === "array") {
|
|
1540
1519
|
coerceSpecificType(t);
|
|
@@ -1543,63 +1522,63 @@ function coerceData(it, types2, coerceTo) {
|
|
|
1543
1522
|
gen.else();
|
|
1544
1523
|
reportTypeError(it);
|
|
1545
1524
|
gen.endIf();
|
|
1546
|
-
gen.if((0, codegen_1$
|
|
1525
|
+
gen.if((0, codegen_1$w._)`${coerced} !== undefined`, () => {
|
|
1547
1526
|
gen.assign(data, coerced);
|
|
1548
1527
|
assignParentData(it, coerced);
|
|
1549
1528
|
});
|
|
1550
1529
|
function coerceSpecificType(t) {
|
|
1551
1530
|
switch (t) {
|
|
1552
1531
|
case "string":
|
|
1553
|
-
gen.elseIf((0, codegen_1$
|
|
1532
|
+
gen.elseIf((0, codegen_1$w._)`${dataType2} == "number" || ${dataType2} == "boolean"`).assign(coerced, (0, codegen_1$w._)`"" + ${data}`).elseIf((0, codegen_1$w._)`${data} === null`).assign(coerced, (0, codegen_1$w._)`""`);
|
|
1554
1533
|
return;
|
|
1555
1534
|
case "number":
|
|
1556
|
-
gen.elseIf((0, codegen_1$
|
|
1557
|
-
|| (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$
|
|
1535
|
+
gen.elseIf((0, codegen_1$w._)`${dataType2} == "boolean" || ${data} === null
|
|
1536
|
+
|| (${dataType2} == "string" && ${data} && ${data} == +${data})`).assign(coerced, (0, codegen_1$w._)`+${data}`);
|
|
1558
1537
|
return;
|
|
1559
1538
|
case "integer":
|
|
1560
|
-
gen.elseIf((0, codegen_1$
|
|
1561
|
-
|| (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$
|
|
1539
|
+
gen.elseIf((0, codegen_1$w._)`${dataType2} === "boolean" || ${data} === null
|
|
1540
|
+
|| (${dataType2} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`).assign(coerced, (0, codegen_1$w._)`+${data}`);
|
|
1562
1541
|
return;
|
|
1563
1542
|
case "boolean":
|
|
1564
|
-
gen.elseIf((0, codegen_1$
|
|
1543
|
+
gen.elseIf((0, codegen_1$w._)`${data} === "false" || ${data} === 0 || ${data} === null`).assign(coerced, false).elseIf((0, codegen_1$w._)`${data} === "true" || ${data} === 1`).assign(coerced, true);
|
|
1565
1544
|
return;
|
|
1566
1545
|
case "null":
|
|
1567
|
-
gen.elseIf((0, codegen_1$
|
|
1546
|
+
gen.elseIf((0, codegen_1$w._)`${data} === "" || ${data} === 0 || ${data} === false`);
|
|
1568
1547
|
gen.assign(coerced, null);
|
|
1569
1548
|
return;
|
|
1570
1549
|
case "array":
|
|
1571
|
-
gen.elseIf((0, codegen_1$
|
|
1572
|
-
|| ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$
|
|
1550
|
+
gen.elseIf((0, codegen_1$w._)`${dataType2} === "string" || ${dataType2} === "number"
|
|
1551
|
+
|| ${dataType2} === "boolean" || ${data} === null`).assign(coerced, (0, codegen_1$w._)`[${data}]`);
|
|
1573
1552
|
}
|
|
1574
1553
|
}
|
|
1575
1554
|
}
|
|
1576
1555
|
function assignParentData({ gen, parentData, parentDataProperty }, expr) {
|
|
1577
|
-
gen.if((0, codegen_1$
|
|
1556
|
+
gen.if((0, codegen_1$w._)`${parentData} !== undefined`, () => gen.assign((0, codegen_1$w._)`${parentData}[${parentDataProperty}]`, expr));
|
|
1578
1557
|
}
|
|
1579
1558
|
function checkDataType(dataType2, data, strictNums, correct = DataType.Correct) {
|
|
1580
|
-
const EQ = correct === DataType.Correct ? codegen_1$
|
|
1559
|
+
const EQ = correct === DataType.Correct ? codegen_1$w.operators.EQ : codegen_1$w.operators.NEQ;
|
|
1581
1560
|
let cond;
|
|
1582
1561
|
switch (dataType2) {
|
|
1583
1562
|
case "null":
|
|
1584
|
-
return (0, codegen_1$
|
|
1563
|
+
return (0, codegen_1$w._)`${data} ${EQ} null`;
|
|
1585
1564
|
case "array":
|
|
1586
|
-
cond = (0, codegen_1$
|
|
1565
|
+
cond = (0, codegen_1$w._)`Array.isArray(${data})`;
|
|
1587
1566
|
break;
|
|
1588
1567
|
case "object":
|
|
1589
|
-
cond = (0, codegen_1$
|
|
1568
|
+
cond = (0, codegen_1$w._)`${data} && typeof ${data} == "object" && !Array.isArray(${data})`;
|
|
1590
1569
|
break;
|
|
1591
1570
|
case "integer":
|
|
1592
|
-
cond = numCond((0, codegen_1$
|
|
1571
|
+
cond = numCond((0, codegen_1$w._)`!(${data} % 1) && !isNaN(${data})`);
|
|
1593
1572
|
break;
|
|
1594
1573
|
case "number":
|
|
1595
1574
|
cond = numCond();
|
|
1596
1575
|
break;
|
|
1597
1576
|
default:
|
|
1598
|
-
return (0, codegen_1$
|
|
1577
|
+
return (0, codegen_1$w._)`typeof ${data} ${EQ} ${dataType2}`;
|
|
1599
1578
|
}
|
|
1600
|
-
return correct === DataType.Correct ? cond : (0, codegen_1$
|
|
1601
|
-
function numCond(_cond = codegen_1$
|
|
1602
|
-
return (0, codegen_1$
|
|
1579
|
+
return correct === DataType.Correct ? cond : (0, codegen_1$w.not)(cond);
|
|
1580
|
+
function numCond(_cond = codegen_1$w.nil) {
|
|
1581
|
+
return (0, codegen_1$w.and)((0, codegen_1$w._)`typeof ${data} == "number"`, _cond, strictNums ? (0, codegen_1$w._)`isFinite(${data})` : codegen_1$w.nil);
|
|
1603
1582
|
}
|
|
1604
1583
|
}
|
|
1605
1584
|
dataType.checkDataType = checkDataType;
|
|
@@ -1608,35 +1587,35 @@ function checkDataTypes(dataTypes, data, strictNums, correct) {
|
|
|
1608
1587
|
return checkDataType(dataTypes[0], data, strictNums, correct);
|
|
1609
1588
|
}
|
|
1610
1589
|
let cond;
|
|
1611
|
-
const types2 = (0, util_1$
|
|
1590
|
+
const types2 = (0, util_1$u.toHash)(dataTypes);
|
|
1612
1591
|
if (types2.array && types2.object) {
|
|
1613
|
-
const notObj = (0, codegen_1$
|
|
1614
|
-
cond = types2.null ? notObj : (0, codegen_1$
|
|
1592
|
+
const notObj = (0, codegen_1$w._)`typeof ${data} != "object"`;
|
|
1593
|
+
cond = types2.null ? notObj : (0, codegen_1$w._)`!${data} || ${notObj}`;
|
|
1615
1594
|
delete types2.null;
|
|
1616
1595
|
delete types2.array;
|
|
1617
1596
|
delete types2.object;
|
|
1618
1597
|
} else {
|
|
1619
|
-
cond = codegen_1$
|
|
1598
|
+
cond = codegen_1$w.nil;
|
|
1620
1599
|
}
|
|
1621
1600
|
if (types2.number)
|
|
1622
1601
|
delete types2.integer;
|
|
1623
1602
|
for (const t in types2)
|
|
1624
|
-
cond = (0, codegen_1$
|
|
1603
|
+
cond = (0, codegen_1$w.and)(cond, checkDataType(t, data, strictNums, correct));
|
|
1625
1604
|
return cond;
|
|
1626
1605
|
}
|
|
1627
1606
|
dataType.checkDataTypes = checkDataTypes;
|
|
1628
1607
|
const typeError = {
|
|
1629
1608
|
message: ({ schema }) => `must be ${schema}`,
|
|
1630
|
-
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$
|
|
1609
|
+
params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$w._)`{type: ${schema}}` : (0, codegen_1$w._)`{type: ${schemaValue}}`
|
|
1631
1610
|
};
|
|
1632
1611
|
function reportTypeError(it) {
|
|
1633
1612
|
const cxt = getTypeErrorContext(it);
|
|
1634
|
-
(0, errors_1.reportError)(cxt, typeError);
|
|
1613
|
+
(0, errors_1$2.reportError)(cxt, typeError);
|
|
1635
1614
|
}
|
|
1636
1615
|
dataType.reportTypeError = reportTypeError;
|
|
1637
1616
|
function getTypeErrorContext(it) {
|
|
1638
1617
|
const { gen, data, schema } = it;
|
|
1639
|
-
const schemaCode = (0, util_1$
|
|
1618
|
+
const schemaCode = (0, util_1$u.schemaRefOrVal)(it, schema, "type");
|
|
1640
1619
|
return {
|
|
1641
1620
|
gen,
|
|
1642
1621
|
keyword: "type",
|
|
@@ -1650,61 +1629,54 @@ function getTypeErrorContext(it) {
|
|
|
1650
1629
|
};
|
|
1651
1630
|
}
|
|
1652
1631
|
var defaults = {};
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
for (const key in properties2) {
|
|
1666
|
-
assignDefault(it, key, properties2[key].default);
|
|
1667
|
-
}
|
|
1668
|
-
} else if (ty === "array" && Array.isArray(items2)) {
|
|
1669
|
-
items2.forEach((sch, i) => assignDefault(it, i, sch.default));
|
|
1670
|
-
}
|
|
1632
|
+
Object.defineProperty(defaults, "__esModule", { value: true });
|
|
1633
|
+
defaults.assignDefaults = void 0;
|
|
1634
|
+
const codegen_1$v = codegen;
|
|
1635
|
+
const util_1$t = util;
|
|
1636
|
+
function assignDefaults(it, ty) {
|
|
1637
|
+
const { properties: properties2, items: items2 } = it.schema;
|
|
1638
|
+
if (ty === "object" && properties2) {
|
|
1639
|
+
for (const key in properties2) {
|
|
1640
|
+
assignDefault(it, key, properties2[key].default);
|
|
1641
|
+
}
|
|
1642
|
+
} else if (ty === "array" && Array.isArray(items2)) {
|
|
1643
|
+
items2.forEach((sch, i) => assignDefault(it, i, sch.default));
|
|
1671
1644
|
}
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
}
|
|
1686
|
-
gen.if(condition, (0, codegen_12._)`${childData} = ${(0, codegen_12.stringify)(defaultValue)}`);
|
|
1645
|
+
}
|
|
1646
|
+
defaults.assignDefaults = assignDefaults;
|
|
1647
|
+
function assignDefault(it, prop, defaultValue) {
|
|
1648
|
+
const { gen, compositeRule, data, opts } = it;
|
|
1649
|
+
if (defaultValue === void 0)
|
|
1650
|
+
return;
|
|
1651
|
+
const childData = (0, codegen_1$v._)`${data}${(0, codegen_1$v.getProperty)(prop)}`;
|
|
1652
|
+
if (compositeRule) {
|
|
1653
|
+
(0, util_1$t.checkStrictMode)(it, `default is ignored for: ${childData}`);
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1656
|
+
let condition = (0, codegen_1$v._)`${childData} === undefined`;
|
|
1657
|
+
if (opts.useDefaults === "empty") {
|
|
1658
|
+
condition = (0, codegen_1$v._)`${condition} || ${childData} === null || ${childData} === ""`;
|
|
1687
1659
|
}
|
|
1688
|
-
|
|
1660
|
+
gen.if(condition, (0, codegen_1$v._)`${childData} = ${(0, codegen_1$v.stringify)(defaultValue)}`);
|
|
1689
1661
|
}
|
|
1690
1662
|
var keyword = {};
|
|
1691
1663
|
var code = {};
|
|
1692
1664
|
Object.defineProperty(code, "__esModule", { value: true });
|
|
1693
1665
|
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;
|
|
1694
|
-
const codegen_1$
|
|
1695
|
-
const util_1$
|
|
1696
|
-
const names_1$
|
|
1666
|
+
const codegen_1$u = codegen;
|
|
1667
|
+
const util_1$s = util;
|
|
1668
|
+
const names_1$8 = names$1;
|
|
1697
1669
|
const util_2$1 = util;
|
|
1698
1670
|
function checkReportMissingProp(cxt, prop) {
|
|
1699
1671
|
const { gen, data, it } = cxt;
|
|
1700
1672
|
gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
|
|
1701
|
-
cxt.setParams({ missingProperty: (0, codegen_1$
|
|
1673
|
+
cxt.setParams({ missingProperty: (0, codegen_1$u._)`${prop}` }, true);
|
|
1702
1674
|
cxt.error();
|
|
1703
1675
|
});
|
|
1704
1676
|
}
|
|
1705
1677
|
code.checkReportMissingProp = checkReportMissingProp;
|
|
1706
1678
|
function checkMissingProp({ gen, data, it: { opts } }, properties2, missing) {
|
|
1707
|
-
return (0, codegen_1$
|
|
1679
|
+
return (0, codegen_1$u.or)(...properties2.map((prop) => (0, codegen_1$u.and)(noPropertyInData(gen, data, prop, opts.ownProperties), (0, codegen_1$u._)`${missing} = ${prop}`)));
|
|
1708
1680
|
}
|
|
1709
1681
|
code.checkMissingProp = checkMissingProp;
|
|
1710
1682
|
function reportMissingProp(cxt, missing) {
|
|
@@ -1716,22 +1688,22 @@ function hasPropFunc(gen) {
|
|
|
1716
1688
|
return gen.scopeValue("func", {
|
|
1717
1689
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
1718
1690
|
ref: Object.prototype.hasOwnProperty,
|
|
1719
|
-
code: (0, codegen_1$
|
|
1691
|
+
code: (0, codegen_1$u._)`Object.prototype.hasOwnProperty`
|
|
1720
1692
|
});
|
|
1721
1693
|
}
|
|
1722
1694
|
code.hasPropFunc = hasPropFunc;
|
|
1723
1695
|
function isOwnProperty(gen, data, property) {
|
|
1724
|
-
return (0, codegen_1$
|
|
1696
|
+
return (0, codegen_1$u._)`${hasPropFunc(gen)}.call(${data}, ${property})`;
|
|
1725
1697
|
}
|
|
1726
1698
|
code.isOwnProperty = isOwnProperty;
|
|
1727
1699
|
function propertyInData(gen, data, property, ownProperties) {
|
|
1728
|
-
const cond = (0, codegen_1$
|
|
1729
|
-
return ownProperties ? (0, codegen_1$
|
|
1700
|
+
const cond = (0, codegen_1$u._)`${data}${(0, codegen_1$u.getProperty)(property)} !== undefined`;
|
|
1701
|
+
return ownProperties ? (0, codegen_1$u._)`${cond} && ${isOwnProperty(gen, data, property)}` : cond;
|
|
1730
1702
|
}
|
|
1731
1703
|
code.propertyInData = propertyInData;
|
|
1732
1704
|
function noPropertyInData(gen, data, property, ownProperties) {
|
|
1733
|
-
const cond = (0, codegen_1$
|
|
1734
|
-
return ownProperties ? (0, codegen_1$
|
|
1705
|
+
const cond = (0, codegen_1$u._)`${data}${(0, codegen_1$u.getProperty)(property)} === undefined`;
|
|
1706
|
+
return ownProperties ? (0, codegen_1$u.or)(cond, (0, codegen_1$u.not)(isOwnProperty(gen, data, property))) : cond;
|
|
1735
1707
|
}
|
|
1736
1708
|
code.noPropertyInData = noPropertyInData;
|
|
1737
1709
|
function allSchemaProperties(schemaMap) {
|
|
@@ -1739,24 +1711,24 @@ function allSchemaProperties(schemaMap) {
|
|
|
1739
1711
|
}
|
|
1740
1712
|
code.allSchemaProperties = allSchemaProperties;
|
|
1741
1713
|
function schemaProperties(it, schemaMap) {
|
|
1742
|
-
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$
|
|
1714
|
+
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$s.alwaysValidSchema)(it, schemaMap[p]));
|
|
1743
1715
|
}
|
|
1744
1716
|
code.schemaProperties = schemaProperties;
|
|
1745
1717
|
function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context2, passSchema) {
|
|
1746
|
-
const dataAndSchema = passSchema ? (0, codegen_1$
|
|
1718
|
+
const dataAndSchema = passSchema ? (0, codegen_1$u._)`${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
|
|
1747
1719
|
const valCxt = [
|
|
1748
|
-
[names_1$
|
|
1749
|
-
[names_1$
|
|
1750
|
-
[names_1$
|
|
1751
|
-
[names_1$
|
|
1720
|
+
[names_1$8.default.instancePath, (0, codegen_1$u.strConcat)(names_1$8.default.instancePath, errorPath)],
|
|
1721
|
+
[names_1$8.default.parentData, it.parentData],
|
|
1722
|
+
[names_1$8.default.parentDataProperty, it.parentDataProperty],
|
|
1723
|
+
[names_1$8.default.rootData, names_1$8.default.rootData]
|
|
1752
1724
|
];
|
|
1753
1725
|
if (it.opts.dynamicRef)
|
|
1754
|
-
valCxt.push([names_1$
|
|
1755
|
-
const args = (0, codegen_1$
|
|
1756
|
-
return context2 !== codegen_1$
|
|
1726
|
+
valCxt.push([names_1$8.default.dynamicAnchors, names_1$8.default.dynamicAnchors]);
|
|
1727
|
+
const args = (0, codegen_1$u._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
|
|
1728
|
+
return context2 !== codegen_1$u.nil ? (0, codegen_1$u._)`${func}.call(${context2}, ${args})` : (0, codegen_1$u._)`${func}(${args})`;
|
|
1757
1729
|
}
|
|
1758
1730
|
code.callValidateCode = callValidateCode;
|
|
1759
|
-
const newRegExp = (0, codegen_1$
|
|
1731
|
+
const newRegExp = (0, codegen_1$u._)`new RegExp`;
|
|
1760
1732
|
function usePattern({ gen, it: { opts } }, pattern2) {
|
|
1761
1733
|
const u = opts.unicodeRegExp ? "u" : "";
|
|
1762
1734
|
const { regExp } = opts.code;
|
|
@@ -1764,7 +1736,7 @@ function usePattern({ gen, it: { opts } }, pattern2) {
|
|
|
1764
1736
|
return gen.scopeValue("pattern", {
|
|
1765
1737
|
key: rx.toString(),
|
|
1766
1738
|
ref: rx,
|
|
1767
|
-
code: (0, codegen_1$
|
|
1739
|
+
code: (0, codegen_1$u._)`${regExp.code === "new RegExp" ? newRegExp : (0, util_2$1.useFunc)(gen, regExp)}(${pattern2}, ${u})`
|
|
1768
1740
|
});
|
|
1769
1741
|
}
|
|
1770
1742
|
code.usePattern = usePattern;
|
|
@@ -1780,14 +1752,14 @@ function validateArray(cxt) {
|
|
|
1780
1752
|
validateItems(() => gen.break());
|
|
1781
1753
|
return valid;
|
|
1782
1754
|
function validateItems(notValid) {
|
|
1783
|
-
const len = gen.const("len", (0, codegen_1$
|
|
1755
|
+
const len = gen.const("len", (0, codegen_1$u._)`${data}.length`);
|
|
1784
1756
|
gen.forRange("i", 0, len, (i) => {
|
|
1785
1757
|
cxt.subschema({
|
|
1786
1758
|
keyword: keyword2,
|
|
1787
1759
|
dataProp: i,
|
|
1788
|
-
dataPropType: util_1$
|
|
1760
|
+
dataPropType: util_1$s.Type.Num
|
|
1789
1761
|
}, valid);
|
|
1790
|
-
gen.if((0, codegen_1$
|
|
1762
|
+
gen.if((0, codegen_1$u.not)(valid), notValid);
|
|
1791
1763
|
});
|
|
1792
1764
|
}
|
|
1793
1765
|
}
|
|
@@ -1796,7 +1768,7 @@ function validateUnion(cxt) {
|
|
|
1796
1768
|
const { gen, schema, keyword: keyword2, it } = cxt;
|
|
1797
1769
|
if (!Array.isArray(schema))
|
|
1798
1770
|
throw new Error("ajv implementation error");
|
|
1799
|
-
const alwaysValid = schema.some((sch) => (0, util_1$
|
|
1771
|
+
const alwaysValid = schema.some((sch) => (0, util_1$s.alwaysValidSchema)(it, sch));
|
|
1800
1772
|
if (alwaysValid && !it.opts.unevaluated)
|
|
1801
1773
|
return;
|
|
1802
1774
|
const valid = gen.let("valid", false);
|
|
@@ -1807,216 +1779,202 @@ function validateUnion(cxt) {
|
|
|
1807
1779
|
schemaProp: i,
|
|
1808
1780
|
compositeRule: true
|
|
1809
1781
|
}, schValid);
|
|
1810
|
-
gen.assign(valid, (0, codegen_1$
|
|
1782
|
+
gen.assign(valid, (0, codegen_1$u._)`${valid} || ${schValid}`);
|
|
1811
1783
|
const merged = cxt.mergeValidEvaluated(schCxt, schValid);
|
|
1812
1784
|
if (!merged)
|
|
1813
|
-
gen.if((0, codegen_1$
|
|
1785
|
+
gen.if((0, codegen_1$u.not)(valid));
|
|
1814
1786
|
}));
|
|
1815
1787
|
cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
|
|
1816
1788
|
}
|
|
1817
1789
|
code.validateUnion = validateUnion;
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
const
|
|
1826
|
-
const
|
|
1827
|
-
const
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
} else {
|
|
1862
|
-
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
1863
|
-
if (def2.modifying)
|
|
1864
|
-
modifyData(cxt);
|
|
1865
|
-
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
function validateAsync() {
|
|
1869
|
-
const ruleErrs = gen.let("ruleErrs", null);
|
|
1870
|
-
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)));
|
|
1871
|
-
return ruleErrs;
|
|
1872
|
-
}
|
|
1873
|
-
function validateSync() {
|
|
1874
|
-
const validateErrs = (0, codegen_12._)`${validateRef}.errors`;
|
|
1875
|
-
gen.assign(validateErrs, null);
|
|
1876
|
-
assignValid(codegen_12.nil);
|
|
1877
|
-
return validateErrs;
|
|
1878
|
-
}
|
|
1879
|
-
function assignValid(_await = def2.async ? (0, codegen_12._)`await ` : codegen_12.nil) {
|
|
1880
|
-
const passCxt = it.opts.passContext ? names_12.default.this : names_12.default.self;
|
|
1881
|
-
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
1882
|
-
gen.assign(valid, (0, codegen_12._)`${_await}${(0, code_12.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
1883
|
-
}
|
|
1884
|
-
function reportErrs(errors2) {
|
|
1885
|
-
var _a2;
|
|
1886
|
-
gen.if((0, codegen_12.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
|
|
1790
|
+
Object.defineProperty(keyword, "__esModule", { value: true });
|
|
1791
|
+
keyword.validateKeywordUsage = keyword.validSchemaType = keyword.funcKeywordCode = keyword.macroKeywordCode = void 0;
|
|
1792
|
+
const codegen_1$t = codegen;
|
|
1793
|
+
const names_1$7 = names$1;
|
|
1794
|
+
const code_1$9 = code;
|
|
1795
|
+
const errors_1$1 = errors;
|
|
1796
|
+
function macroKeywordCode(cxt, def2) {
|
|
1797
|
+
const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
|
|
1798
|
+
const macroSchema = def2.macro.call(it.self, schema, parentSchema, it);
|
|
1799
|
+
const schemaRef = useKeyword(gen, keyword2, macroSchema);
|
|
1800
|
+
if (it.opts.validateSchema !== false)
|
|
1801
|
+
it.self.validateSchema(macroSchema, true);
|
|
1802
|
+
const valid = gen.name("valid");
|
|
1803
|
+
cxt.subschema({
|
|
1804
|
+
schema: macroSchema,
|
|
1805
|
+
schemaPath: codegen_1$t.nil,
|
|
1806
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`,
|
|
1807
|
+
topSchemaRef: schemaRef,
|
|
1808
|
+
compositeRule: true
|
|
1809
|
+
}, valid);
|
|
1810
|
+
cxt.pass(valid, () => cxt.error(true));
|
|
1811
|
+
}
|
|
1812
|
+
keyword.macroKeywordCode = macroKeywordCode;
|
|
1813
|
+
function funcKeywordCode(cxt, def2) {
|
|
1814
|
+
var _a;
|
|
1815
|
+
const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
|
|
1816
|
+
checkAsyncKeyword(it, def2);
|
|
1817
|
+
const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
|
|
1818
|
+
const validateRef = useKeyword(gen, keyword2, validate2);
|
|
1819
|
+
const valid = gen.let("valid");
|
|
1820
|
+
cxt.block$data(valid, validateKeyword);
|
|
1821
|
+
cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
|
|
1822
|
+
function validateKeyword() {
|
|
1823
|
+
if (def2.errors === false) {
|
|
1824
|
+
assignValid();
|
|
1825
|
+
if (def2.modifying)
|
|
1826
|
+
modifyData(cxt);
|
|
1827
|
+
reportErrs(() => cxt.error());
|
|
1828
|
+
} else {
|
|
1829
|
+
const ruleErrs = def2.async ? validateAsync() : validateSync();
|
|
1830
|
+
if (def2.modifying)
|
|
1831
|
+
modifyData(cxt);
|
|
1832
|
+
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
1887
1833
|
}
|
|
1888
1834
|
}
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
}
|
|
1894
|
-
function
|
|
1895
|
-
const
|
|
1896
|
-
gen.
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
}
|
|
1905
|
-
function
|
|
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
|
-
|
|
1835
|
+
function validateAsync() {
|
|
1836
|
+
const ruleErrs = gen.let("ruleErrs", null);
|
|
1837
|
+
gen.try(() => assignValid((0, codegen_1$t._)`await `), (e) => gen.assign(valid, false).if((0, codegen_1$t._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1$t._)`${e}.errors`), () => gen.throw(e)));
|
|
1838
|
+
return ruleErrs;
|
|
1839
|
+
}
|
|
1840
|
+
function validateSync() {
|
|
1841
|
+
const validateErrs = (0, codegen_1$t._)`${validateRef}.errors`;
|
|
1842
|
+
gen.assign(validateErrs, null);
|
|
1843
|
+
assignValid(codegen_1$t.nil);
|
|
1844
|
+
return validateErrs;
|
|
1845
|
+
}
|
|
1846
|
+
function assignValid(_await = def2.async ? (0, codegen_1$t._)`await ` : codegen_1$t.nil) {
|
|
1847
|
+
const passCxt = it.opts.passContext ? names_1$7.default.this : names_1$7.default.self;
|
|
1848
|
+
const passSchema = !("compile" in def2 && !$data || def2.schema === false);
|
|
1849
|
+
gen.assign(valid, (0, codegen_1$t._)`${_await}${(0, code_1$9.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
|
|
1850
|
+
}
|
|
1851
|
+
function reportErrs(errors2) {
|
|
1852
|
+
var _a2;
|
|
1853
|
+
gen.if((0, codegen_1$t.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
keyword.funcKeywordCode = funcKeywordCode;
|
|
1857
|
+
function modifyData(cxt) {
|
|
1858
|
+
const { gen, data, it } = cxt;
|
|
1859
|
+
gen.if(it.parentData, () => gen.assign(data, (0, codegen_1$t._)`${it.parentData}[${it.parentDataProperty}]`));
|
|
1860
|
+
}
|
|
1861
|
+
function addErrs(cxt, errs) {
|
|
1862
|
+
const { gen } = cxt;
|
|
1863
|
+
gen.if((0, codegen_1$t._)`Array.isArray(${errs})`, () => {
|
|
1864
|
+
gen.assign(names_1$7.default.vErrors, (0, codegen_1$t._)`${names_1$7.default.vErrors} === null ? ${errs} : ${names_1$7.default.vErrors}.concat(${errs})`).assign(names_1$7.default.errors, (0, codegen_1$t._)`${names_1$7.default.vErrors}.length`);
|
|
1865
|
+
(0, errors_1$1.extendErrors)(cxt);
|
|
1866
|
+
}, () => cxt.error());
|
|
1867
|
+
}
|
|
1868
|
+
function checkAsyncKeyword({ schemaEnv }, def2) {
|
|
1869
|
+
if (def2.async && !schemaEnv.$async)
|
|
1870
|
+
throw new Error("async keyword in sync schema");
|
|
1871
|
+
}
|
|
1872
|
+
function useKeyword(gen, keyword2, result) {
|
|
1873
|
+
if (result === void 0)
|
|
1874
|
+
throw new Error(`keyword "${keyword2}" failed to compile`);
|
|
1875
|
+
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_1$t.stringify)(result) });
|
|
1876
|
+
}
|
|
1877
|
+
function validSchemaType(schema, schemaType, allowUndefined = false) {
|
|
1878
|
+
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");
|
|
1879
|
+
}
|
|
1880
|
+
keyword.validSchemaType = validSchemaType;
|
|
1881
|
+
function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def2, keyword2) {
|
|
1882
|
+
if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
|
|
1883
|
+
throw new Error("ajv implementation error");
|
|
1884
|
+
}
|
|
1885
|
+
const deps = def2.dependencies;
|
|
1886
|
+
if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
|
|
1887
|
+
throw new Error(`parent schema must have dependencies of ${keyword2}: ${deps.join(",")}`);
|
|
1888
|
+
}
|
|
1889
|
+
if (def2.validateSchema) {
|
|
1890
|
+
const valid = def2.validateSchema(schema[keyword2]);
|
|
1891
|
+
if (!valid) {
|
|
1892
|
+
const msg = `keyword "${keyword2}" value is invalid at path "${errSchemaPath}": ` + self.errorsText(def2.validateSchema.errors);
|
|
1893
|
+
if (opts.validateSchema === "log")
|
|
1894
|
+
self.logger.error(msg);
|
|
1895
|
+
else
|
|
1896
|
+
throw new Error(msg);
|
|
1931
1897
|
}
|
|
1932
1898
|
}
|
|
1933
|
-
keyword.validateKeywordUsage = validateKeywordUsage;
|
|
1934
|
-
return keyword;
|
|
1935
1899
|
}
|
|
1900
|
+
keyword.validateKeywordUsage = validateKeywordUsage;
|
|
1936
1901
|
var subschema = {};
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
};
|
|
1961
|
-
}
|
|
1962
|
-
if (schema !== void 0) {
|
|
1963
|
-
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
1964
|
-
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
1965
|
-
}
|
|
1966
|
-
return {
|
|
1967
|
-
schema,
|
|
1968
|
-
schemaPath,
|
|
1969
|
-
topSchemaRef,
|
|
1970
|
-
errSchemaPath
|
|
1971
|
-
};
|
|
1902
|
+
Object.defineProperty(subschema, "__esModule", { value: true });
|
|
1903
|
+
subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
|
|
1904
|
+
const codegen_1$s = codegen;
|
|
1905
|
+
const util_1$r = util;
|
|
1906
|
+
function getSubschema(it, { keyword: keyword2, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
|
|
1907
|
+
if (keyword2 !== void 0 && schema !== void 0) {
|
|
1908
|
+
throw new Error('both "keyword" and "schema" passed, only one allowed');
|
|
1909
|
+
}
|
|
1910
|
+
if (keyword2 !== void 0) {
|
|
1911
|
+
const sch = it.schema[keyword2];
|
|
1912
|
+
return schemaProp === void 0 ? {
|
|
1913
|
+
schema: sch,
|
|
1914
|
+
schemaPath: (0, codegen_1$s._)`${it.schemaPath}${(0, codegen_1$s.getProperty)(keyword2)}`,
|
|
1915
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}`
|
|
1916
|
+
} : {
|
|
1917
|
+
schema: sch[schemaProp],
|
|
1918
|
+
schemaPath: (0, codegen_1$s._)`${it.schemaPath}${(0, codegen_1$s.getProperty)(keyword2)}${(0, codegen_1$s.getProperty)(schemaProp)}`,
|
|
1919
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_1$r.escapeFragment)(schemaProp)}`
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
if (schema !== void 0) {
|
|
1923
|
+
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
|
|
1924
|
+
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
|
|
1972
1925
|
}
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
subschema2.
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
1926
|
+
return {
|
|
1927
|
+
schema,
|
|
1928
|
+
schemaPath,
|
|
1929
|
+
topSchemaRef,
|
|
1930
|
+
errSchemaPath
|
|
1931
|
+
};
|
|
1932
|
+
}
|
|
1933
|
+
throw new Error('either "keyword" or "schema" must be passed');
|
|
1934
|
+
}
|
|
1935
|
+
subschema.getSubschema = getSubschema;
|
|
1936
|
+
function extendSubschemaData(subschema2, it, { dataProp, dataPropType: dpType, data, dataTypes, propertyName }) {
|
|
1937
|
+
if (data !== void 0 && dataProp !== void 0) {
|
|
1938
|
+
throw new Error('both "data" and "dataProp" passed, only one allowed');
|
|
1939
|
+
}
|
|
1940
|
+
const { gen } = it;
|
|
1941
|
+
if (dataProp !== void 0) {
|
|
1942
|
+
const { errorPath, dataPathArr, opts } = it;
|
|
1943
|
+
const nextData = gen.let("data", (0, codegen_1$s._)`${it.data}${(0, codegen_1$s.getProperty)(dataProp)}`, true);
|
|
1944
|
+
dataContextProps(nextData);
|
|
1945
|
+
subschema2.errorPath = (0, codegen_1$s.str)`${errorPath}${(0, util_1$r.getErrorPath)(dataProp, dpType, opts.jsPropertySyntax)}`;
|
|
1946
|
+
subschema2.parentDataProperty = (0, codegen_1$s._)`${dataProp}`;
|
|
1947
|
+
subschema2.dataPathArr = [...dataPathArr, subschema2.parentDataProperty];
|
|
1948
|
+
}
|
|
1949
|
+
if (data !== void 0) {
|
|
1950
|
+
const nextData = data instanceof codegen_1$s.Name ? data : gen.let("data", data, true);
|
|
1951
|
+
dataContextProps(nextData);
|
|
1952
|
+
if (propertyName !== void 0)
|
|
1953
|
+
subschema2.propertyName = propertyName;
|
|
1954
|
+
}
|
|
1955
|
+
if (dataTypes)
|
|
1956
|
+
subschema2.dataTypes = dataTypes;
|
|
1957
|
+
function dataContextProps(_nextData) {
|
|
1958
|
+
subschema2.data = _nextData;
|
|
1959
|
+
subschema2.dataLevel = it.dataLevel + 1;
|
|
1960
|
+
subschema2.dataTypes = [];
|
|
1961
|
+
it.definedProperties = /* @__PURE__ */ new Set();
|
|
1962
|
+
subschema2.parentData = it.data;
|
|
1963
|
+
subschema2.dataNames = [...it.dataNames, _nextData];
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
subschema.extendSubschemaData = extendSubschemaData;
|
|
1967
|
+
function extendSubschemaMode(subschema2, { jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors }) {
|
|
1968
|
+
if (compositeRule !== void 0)
|
|
1969
|
+
subschema2.compositeRule = compositeRule;
|
|
1970
|
+
if (createErrors !== void 0)
|
|
1971
|
+
subschema2.createErrors = createErrors;
|
|
1972
|
+
if (allErrors !== void 0)
|
|
1973
|
+
subschema2.allErrors = allErrors;
|
|
1974
|
+
subschema2.jtdDiscriminator = jtdDiscriminator;
|
|
1975
|
+
subschema2.jtdMetadata = jtdMetadata;
|
|
2019
1976
|
}
|
|
1977
|
+
subschema.extendSubschemaMode = extendSubschemaMode;
|
|
2020
1978
|
var resolve$2 = {};
|
|
2021
1979
|
var fastDeepEqual = function equal(a, b) {
|
|
2022
1980
|
if (a === b)
|
|
@@ -2141,7 +2099,7 @@ function escapeJsonPtr(str) {
|
|
|
2141
2099
|
var jsonSchemaTraverseExports = jsonSchemaTraverse.exports;
|
|
2142
2100
|
Object.defineProperty(resolve$2, "__esModule", { value: true });
|
|
2143
2101
|
resolve$2.getSchemaRefs = resolve$2.resolveUrl = resolve$2.normalizeId = resolve$2._getFullPath = resolve$2.getFullPath = resolve$2.inlineRef = void 0;
|
|
2144
|
-
const util_1$
|
|
2102
|
+
const util_1$q = util;
|
|
2145
2103
|
const equal$3 = fastDeepEqual;
|
|
2146
2104
|
const traverse = jsonSchemaTraverseExports;
|
|
2147
2105
|
const SIMPLE_INLINED = /* @__PURE__ */ new Set([
|
|
@@ -2200,7 +2158,7 @@ function countKeys(schema) {
|
|
|
2200
2158
|
if (SIMPLE_INLINED.has(key))
|
|
2201
2159
|
continue;
|
|
2202
2160
|
if (typeof schema[key] == "object") {
|
|
2203
|
-
(0, util_1$
|
|
2161
|
+
(0, util_1$q.eachItem)(schema[key], (sch) => count += countKeys(sch));
|
|
2204
2162
|
}
|
|
2205
2163
|
if (count === Infinity)
|
|
2206
2164
|
return Infinity;
|
|
@@ -2288,513 +2246,506 @@ function getSchemaRefs(schema, baseId) {
|
|
|
2288
2246
|
}
|
|
2289
2247
|
}
|
|
2290
2248
|
resolve$2.getSchemaRefs = getSchemaRefs;
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
if (isSchemaObj(it)) {
|
|
2312
|
-
checkKeywords(it);
|
|
2313
|
-
if (schemaCxtHasRules(it)) {
|
|
2314
|
-
topSchemaObjCode(it);
|
|
2315
|
-
return;
|
|
2316
|
-
}
|
|
2249
|
+
Object.defineProperty(validate, "__esModule", { value: true });
|
|
2250
|
+
validate.getData = validate.KeywordCxt = validate.validateFunctionCode = void 0;
|
|
2251
|
+
const boolSchema_1 = boolSchema;
|
|
2252
|
+
const dataType_1$1 = dataType;
|
|
2253
|
+
const applicability_1 = applicability;
|
|
2254
|
+
const dataType_2 = dataType;
|
|
2255
|
+
const defaults_1 = defaults;
|
|
2256
|
+
const keyword_1 = keyword;
|
|
2257
|
+
const subschema_1 = subschema;
|
|
2258
|
+
const codegen_1$r = codegen;
|
|
2259
|
+
const names_1$6 = names$1;
|
|
2260
|
+
const resolve_1$2 = resolve$2;
|
|
2261
|
+
const util_1$p = util;
|
|
2262
|
+
const errors_1 = errors;
|
|
2263
|
+
function validateFunctionCode(it) {
|
|
2264
|
+
if (isSchemaObj(it)) {
|
|
2265
|
+
checkKeywords(it);
|
|
2266
|
+
if (schemaCxtHasRules(it)) {
|
|
2267
|
+
topSchemaObjCode(it);
|
|
2268
|
+
return;
|
|
2317
2269
|
}
|
|
2318
|
-
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
2319
2270
|
}
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
function destructureValCxt(opts) {
|
|
2333
|
-
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}}={}`;
|
|
2334
|
-
}
|
|
2335
|
-
function destructureValCxtES5(gen, opts) {
|
|
2336
|
-
gen.if(names_12.default.valCxt, () => {
|
|
2337
|
-
gen.var(names_12.default.instancePath, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.instancePath}`);
|
|
2338
|
-
gen.var(names_12.default.parentData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentData}`);
|
|
2339
|
-
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentDataProperty}`);
|
|
2340
|
-
gen.var(names_12.default.rootData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.rootData}`);
|
|
2341
|
-
if (opts.dynamicRef)
|
|
2342
|
-
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.dynamicAnchors}`);
|
|
2343
|
-
}, () => {
|
|
2344
|
-
gen.var(names_12.default.instancePath, (0, codegen_12._)`""`);
|
|
2345
|
-
gen.var(names_12.default.parentData, (0, codegen_12._)`undefined`);
|
|
2346
|
-
gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`undefined`);
|
|
2347
|
-
gen.var(names_12.default.rootData, names_12.default.data);
|
|
2348
|
-
if (opts.dynamicRef)
|
|
2349
|
-
gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`{}`);
|
|
2350
|
-
});
|
|
2351
|
-
}
|
|
2352
|
-
function topSchemaObjCode(it) {
|
|
2353
|
-
const { schema, opts, gen } = it;
|
|
2354
|
-
validateFunction(it, () => {
|
|
2355
|
-
if (opts.$comment && schema.$comment)
|
|
2356
|
-
commentKeyword(it);
|
|
2357
|
-
checkNoDefault(it);
|
|
2358
|
-
gen.let(names_12.default.vErrors, null);
|
|
2359
|
-
gen.let(names_12.default.errors, 0);
|
|
2360
|
-
if (opts.unevaluated)
|
|
2361
|
-
resetEvaluated(it);
|
|
2362
|
-
typeAndKeywords(it);
|
|
2363
|
-
returnResults(it);
|
|
2271
|
+
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
2272
|
+
}
|
|
2273
|
+
validate.validateFunctionCode = validateFunctionCode;
|
|
2274
|
+
function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
|
|
2275
|
+
if (opts.code.es5) {
|
|
2276
|
+
gen.func(validateName, (0, codegen_1$r._)`${names_1$6.default.data}, ${names_1$6.default.valCxt}`, schemaEnv.$async, () => {
|
|
2277
|
+
gen.code((0, codegen_1$r._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
|
|
2278
|
+
destructureValCxtES5(gen, opts);
|
|
2279
|
+
gen.code(body);
|
|
2364
2280
|
});
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
function resetEvaluated(it) {
|
|
2368
|
-
const { gen, validateName } = it;
|
|
2369
|
-
it.evaluated = gen.const("evaluated", (0, codegen_12._)`${validateName}.evaluated`);
|
|
2370
|
-
gen.if((0, codegen_12._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_12._)`${it.evaluated}.props`, (0, codegen_12._)`undefined`));
|
|
2371
|
-
gen.if((0, codegen_12._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_12._)`${it.evaluated}.items`, (0, codegen_12._)`undefined`));
|
|
2372
|
-
}
|
|
2373
|
-
function funcSourceUrl(schema, opts) {
|
|
2374
|
-
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
2375
|
-
return schId && (opts.code.source || opts.code.process) ? (0, codegen_12._)`/*# sourceURL=${schId} */` : codegen_12.nil;
|
|
2376
|
-
}
|
|
2377
|
-
function subschemaCode(it, valid) {
|
|
2378
|
-
if (isSchemaObj(it)) {
|
|
2379
|
-
checkKeywords(it);
|
|
2380
|
-
if (schemaCxtHasRules(it)) {
|
|
2381
|
-
subSchemaObjCode(it, valid);
|
|
2382
|
-
return;
|
|
2383
|
-
}
|
|
2384
|
-
}
|
|
2385
|
-
(0, boolSchema_1.boolOrEmptySchema)(it, valid);
|
|
2386
|
-
}
|
|
2387
|
-
function schemaCxtHasRules({ schema, self }) {
|
|
2388
|
-
if (typeof schema == "boolean")
|
|
2389
|
-
return !schema;
|
|
2390
|
-
for (const key in schema)
|
|
2391
|
-
if (self.RULES.all[key])
|
|
2392
|
-
return true;
|
|
2393
|
-
return false;
|
|
2394
|
-
}
|
|
2395
|
-
function isSchemaObj(it) {
|
|
2396
|
-
return typeof it.schema != "boolean";
|
|
2281
|
+
} else {
|
|
2282
|
+
gen.func(validateName, (0, codegen_1$r._)`${names_1$6.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
2397
2283
|
}
|
|
2398
|
-
|
|
2399
|
-
|
|
2284
|
+
}
|
|
2285
|
+
function destructureValCxt(opts) {
|
|
2286
|
+
return (0, codegen_1$r._)`{${names_1$6.default.instancePath}="", ${names_1$6.default.parentData}, ${names_1$6.default.parentDataProperty}, ${names_1$6.default.rootData}=${names_1$6.default.data}${opts.dynamicRef ? (0, codegen_1$r._)`, ${names_1$6.default.dynamicAnchors}={}` : codegen_1$r.nil}}={}`;
|
|
2287
|
+
}
|
|
2288
|
+
function destructureValCxtES5(gen, opts) {
|
|
2289
|
+
gen.if(names_1$6.default.valCxt, () => {
|
|
2290
|
+
gen.var(names_1$6.default.instancePath, (0, codegen_1$r._)`${names_1$6.default.valCxt}.${names_1$6.default.instancePath}`);
|
|
2291
|
+
gen.var(names_1$6.default.parentData, (0, codegen_1$r._)`${names_1$6.default.valCxt}.${names_1$6.default.parentData}`);
|
|
2292
|
+
gen.var(names_1$6.default.parentDataProperty, (0, codegen_1$r._)`${names_1$6.default.valCxt}.${names_1$6.default.parentDataProperty}`);
|
|
2293
|
+
gen.var(names_1$6.default.rootData, (0, codegen_1$r._)`${names_1$6.default.valCxt}.${names_1$6.default.rootData}`);
|
|
2294
|
+
if (opts.dynamicRef)
|
|
2295
|
+
gen.var(names_1$6.default.dynamicAnchors, (0, codegen_1$r._)`${names_1$6.default.valCxt}.${names_1$6.default.dynamicAnchors}`);
|
|
2296
|
+
}, () => {
|
|
2297
|
+
gen.var(names_1$6.default.instancePath, (0, codegen_1$r._)`""`);
|
|
2298
|
+
gen.var(names_1$6.default.parentData, (0, codegen_1$r._)`undefined`);
|
|
2299
|
+
gen.var(names_1$6.default.parentDataProperty, (0, codegen_1$r._)`undefined`);
|
|
2300
|
+
gen.var(names_1$6.default.rootData, names_1$6.default.data);
|
|
2301
|
+
if (opts.dynamicRef)
|
|
2302
|
+
gen.var(names_1$6.default.dynamicAnchors, (0, codegen_1$r._)`{}`);
|
|
2303
|
+
});
|
|
2304
|
+
}
|
|
2305
|
+
function topSchemaObjCode(it) {
|
|
2306
|
+
const { schema, opts, gen } = it;
|
|
2307
|
+
validateFunction(it, () => {
|
|
2400
2308
|
if (opts.$comment && schema.$comment)
|
|
2401
2309
|
commentKeyword(it);
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2310
|
+
checkNoDefault(it);
|
|
2311
|
+
gen.let(names_1$6.default.vErrors, null);
|
|
2312
|
+
gen.let(names_1$6.default.errors, 0);
|
|
2313
|
+
if (opts.unevaluated)
|
|
2314
|
+
resetEvaluated(it);
|
|
2315
|
+
typeAndKeywords(it);
|
|
2316
|
+
returnResults(it);
|
|
2317
|
+
});
|
|
2318
|
+
return;
|
|
2319
|
+
}
|
|
2320
|
+
function resetEvaluated(it) {
|
|
2321
|
+
const { gen, validateName } = it;
|
|
2322
|
+
it.evaluated = gen.const("evaluated", (0, codegen_1$r._)`${validateName}.evaluated`);
|
|
2323
|
+
gen.if((0, codegen_1$r._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_1$r._)`${it.evaluated}.props`, (0, codegen_1$r._)`undefined`));
|
|
2324
|
+
gen.if((0, codegen_1$r._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_1$r._)`${it.evaluated}.items`, (0, codegen_1$r._)`undefined`));
|
|
2325
|
+
}
|
|
2326
|
+
function funcSourceUrl(schema, opts) {
|
|
2327
|
+
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
2328
|
+
return schId && (opts.code.source || opts.code.process) ? (0, codegen_1$r._)`/*# sourceURL=${schId} */` : codegen_1$r.nil;
|
|
2329
|
+
}
|
|
2330
|
+
function subschemaCode(it, valid) {
|
|
2331
|
+
if (isSchemaObj(it)) {
|
|
2332
|
+
checkKeywords(it);
|
|
2333
|
+
if (schemaCxtHasRules(it)) {
|
|
2334
|
+
subSchemaObjCode(it, valid);
|
|
2335
|
+
return;
|
|
2423
2336
|
}
|
|
2424
2337
|
}
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2338
|
+
(0, boolSchema_1.boolOrEmptySchema)(it, valid);
|
|
2339
|
+
}
|
|
2340
|
+
function schemaCxtHasRules({ schema, self }) {
|
|
2341
|
+
if (typeof schema == "boolean")
|
|
2342
|
+
return !schema;
|
|
2343
|
+
for (const key in schema)
|
|
2344
|
+
if (self.RULES.all[key])
|
|
2345
|
+
return true;
|
|
2346
|
+
return false;
|
|
2347
|
+
}
|
|
2348
|
+
function isSchemaObj(it) {
|
|
2349
|
+
return typeof it.schema != "boolean";
|
|
2350
|
+
}
|
|
2351
|
+
function subSchemaObjCode(it, valid) {
|
|
2352
|
+
const { schema, gen, opts } = it;
|
|
2353
|
+
if (opts.$comment && schema.$comment)
|
|
2354
|
+
commentKeyword(it);
|
|
2355
|
+
updateContext(it);
|
|
2356
|
+
checkAsyncSchema(it);
|
|
2357
|
+
const errsCount = gen.const("_errs", names_1$6.default.errors);
|
|
2358
|
+
typeAndKeywords(it, errsCount);
|
|
2359
|
+
gen.var(valid, (0, codegen_1$r._)`${errsCount} === ${names_1$6.default.errors}`);
|
|
2360
|
+
}
|
|
2361
|
+
function checkKeywords(it) {
|
|
2362
|
+
(0, util_1$p.checkUnknownRules)(it);
|
|
2363
|
+
checkRefsAndKeywords(it);
|
|
2364
|
+
}
|
|
2365
|
+
function typeAndKeywords(it, errsCount) {
|
|
2366
|
+
if (it.opts.jtd)
|
|
2367
|
+
return schemaKeywords(it, [], false, errsCount);
|
|
2368
|
+
const types2 = (0, dataType_1$1.getSchemaTypes)(it.schema);
|
|
2369
|
+
const checkedTypes = (0, dataType_1$1.coerceAndCheckDataType)(it, types2);
|
|
2370
|
+
schemaKeywords(it, types2, !checkedTypes, errsCount);
|
|
2371
|
+
}
|
|
2372
|
+
function checkRefsAndKeywords(it) {
|
|
2373
|
+
const { schema, errSchemaPath, opts, self } = it;
|
|
2374
|
+
if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_1$p.schemaHasRulesButRef)(schema, self.RULES)) {
|
|
2375
|
+
self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
|
|
2430
2376
|
}
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2377
|
+
}
|
|
2378
|
+
function checkNoDefault(it) {
|
|
2379
|
+
const { schema, opts } = it;
|
|
2380
|
+
if (schema.default !== void 0 && opts.useDefaults && opts.strictSchema) {
|
|
2381
|
+
(0, util_1$p.checkStrictMode)(it, "default is ignored in the schema root");
|
|
2435
2382
|
}
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2383
|
+
}
|
|
2384
|
+
function updateContext(it) {
|
|
2385
|
+
const schId = it.schema[it.opts.schemaId];
|
|
2386
|
+
if (schId)
|
|
2387
|
+
it.baseId = (0, resolve_1$2.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
|
|
2388
|
+
}
|
|
2389
|
+
function checkAsyncSchema(it) {
|
|
2390
|
+
if (it.schema.$async && !it.schemaEnv.$async)
|
|
2391
|
+
throw new Error("async schema in sync schema");
|
|
2392
|
+
}
|
|
2393
|
+
function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
|
|
2394
|
+
const msg = schema.$comment;
|
|
2395
|
+
if (opts.$comment === true) {
|
|
2396
|
+
gen.code((0, codegen_1$r._)`${names_1$6.default.self}.logger.log(${msg})`);
|
|
2397
|
+
} else if (typeof opts.$comment == "function") {
|
|
2398
|
+
const schemaPath = (0, codegen_1$r.str)`${errSchemaPath}/$comment`;
|
|
2399
|
+
const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
|
|
2400
|
+
gen.code((0, codegen_1$r._)`${names_1$6.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
|
|
2439
2401
|
}
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
}
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2402
|
+
}
|
|
2403
|
+
function returnResults(it) {
|
|
2404
|
+
const { gen, schemaEnv, validateName, ValidationError: ValidationError2, opts } = it;
|
|
2405
|
+
if (schemaEnv.$async) {
|
|
2406
|
+
gen.if((0, codegen_1$r._)`${names_1$6.default.errors} === 0`, () => gen.return(names_1$6.default.data), () => gen.throw((0, codegen_1$r._)`new ${ValidationError2}(${names_1$6.default.vErrors})`));
|
|
2407
|
+
} else {
|
|
2408
|
+
gen.assign((0, codegen_1$r._)`${validateName}.errors`, names_1$6.default.vErrors);
|
|
2409
|
+
if (opts.unevaluated)
|
|
2410
|
+
assignEvaluated(it);
|
|
2411
|
+
gen.return((0, codegen_1$r._)`${names_1$6.default.errors} === 0`);
|
|
2449
2412
|
}
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2413
|
+
}
|
|
2414
|
+
function assignEvaluated({ gen, evaluated, props, items: items2 }) {
|
|
2415
|
+
if (props instanceof codegen_1$r.Name)
|
|
2416
|
+
gen.assign((0, codegen_1$r._)`${evaluated}.props`, props);
|
|
2417
|
+
if (items2 instanceof codegen_1$r.Name)
|
|
2418
|
+
gen.assign((0, codegen_1$r._)`${evaluated}.items`, items2);
|
|
2419
|
+
}
|
|
2420
|
+
function schemaKeywords(it, types2, typeErrors, errsCount) {
|
|
2421
|
+
const { gen, schema, data, allErrors, opts, self } = it;
|
|
2422
|
+
const { RULES } = self;
|
|
2423
|
+
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_1$p.schemaHasRulesButRef)(schema, RULES))) {
|
|
2424
|
+
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
2425
|
+
return;
|
|
2426
|
+
}
|
|
2427
|
+
if (!opts.jtd)
|
|
2428
|
+
checkStrictTypes(it, types2);
|
|
2429
|
+
gen.block(() => {
|
|
2430
|
+
for (const group of RULES.rules)
|
|
2431
|
+
groupKeywords(group);
|
|
2432
|
+
groupKeywords(RULES.post);
|
|
2433
|
+
});
|
|
2434
|
+
function groupKeywords(group) {
|
|
2435
|
+
if (!(0, applicability_1.shouldUseGroup)(schema, group))
|
|
2472
2436
|
return;
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
groupKeywords(RULES.post);
|
|
2480
|
-
});
|
|
2481
|
-
function groupKeywords(group) {
|
|
2482
|
-
if (!(0, applicability_12.shouldUseGroup)(schema, group))
|
|
2483
|
-
return;
|
|
2484
|
-
if (group.type) {
|
|
2485
|
-
gen.if((0, dataType_2.checkDataType)(group.type, data, opts.strictNumbers));
|
|
2486
|
-
iterateKeywords(it, group);
|
|
2487
|
-
if (types2.length === 1 && types2[0] === group.type && typeErrors) {
|
|
2488
|
-
gen.else();
|
|
2489
|
-
(0, dataType_2.reportTypeError)(it);
|
|
2490
|
-
}
|
|
2491
|
-
gen.endIf();
|
|
2492
|
-
} else {
|
|
2493
|
-
iterateKeywords(it, group);
|
|
2437
|
+
if (group.type) {
|
|
2438
|
+
gen.if((0, dataType_2.checkDataType)(group.type, data, opts.strictNumbers));
|
|
2439
|
+
iterateKeywords(it, group);
|
|
2440
|
+
if (types2.length === 1 && types2[0] === group.type && typeErrors) {
|
|
2441
|
+
gen.else();
|
|
2442
|
+
(0, dataType_2.reportTypeError)(it);
|
|
2494
2443
|
}
|
|
2495
|
-
|
|
2496
|
-
|
|
2444
|
+
gen.endIf();
|
|
2445
|
+
} else {
|
|
2446
|
+
iterateKeywords(it, group);
|
|
2497
2447
|
}
|
|
2448
|
+
if (!allErrors)
|
|
2449
|
+
gen.if((0, codegen_1$r._)`${names_1$6.default.errors} === ${errsCount || 0}`);
|
|
2498
2450
|
}
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2451
|
+
}
|
|
2452
|
+
function iterateKeywords(it, group) {
|
|
2453
|
+
const { gen, schema, opts: { useDefaults } } = it;
|
|
2454
|
+
if (useDefaults)
|
|
2455
|
+
(0, defaults_1.assignDefaults)(it, group.type);
|
|
2456
|
+
gen.block(() => {
|
|
2457
|
+
for (const rule of group.rules) {
|
|
2458
|
+
if ((0, applicability_1.shouldUseRule)(schema, rule)) {
|
|
2459
|
+
keywordCode(it, rule.keyword, rule.definition, group.type);
|
|
2508
2460
|
}
|
|
2509
|
-
});
|
|
2510
|
-
}
|
|
2511
|
-
function checkStrictTypes(it, types2) {
|
|
2512
|
-
if (it.schemaEnv.meta || !it.opts.strictTypes)
|
|
2513
|
-
return;
|
|
2514
|
-
checkContextTypes(it, types2);
|
|
2515
|
-
if (!it.opts.allowUnionTypes)
|
|
2516
|
-
checkMultipleTypes(it, types2);
|
|
2517
|
-
checkKeywordTypes(it, it.dataTypes);
|
|
2518
|
-
}
|
|
2519
|
-
function checkContextTypes(it, types2) {
|
|
2520
|
-
if (!types2.length)
|
|
2521
|
-
return;
|
|
2522
|
-
if (!it.dataTypes.length) {
|
|
2523
|
-
it.dataTypes = types2;
|
|
2524
|
-
return;
|
|
2525
2461
|
}
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2464
|
+
function checkStrictTypes(it, types2) {
|
|
2465
|
+
if (it.schemaEnv.meta || !it.opts.strictTypes)
|
|
2466
|
+
return;
|
|
2467
|
+
checkContextTypes(it, types2);
|
|
2468
|
+
if (!it.opts.allowUnionTypes)
|
|
2469
|
+
checkMultipleTypes(it, types2);
|
|
2470
|
+
checkKeywordTypes(it, it.dataTypes);
|
|
2471
|
+
}
|
|
2472
|
+
function checkContextTypes(it, types2) {
|
|
2473
|
+
if (!types2.length)
|
|
2474
|
+
return;
|
|
2475
|
+
if (!it.dataTypes.length) {
|
|
2476
|
+
it.dataTypes = types2;
|
|
2477
|
+
return;
|
|
2532
2478
|
}
|
|
2533
|
-
|
|
2534
|
-
if (
|
|
2535
|
-
strictTypesError(it, "
|
|
2479
|
+
types2.forEach((t) => {
|
|
2480
|
+
if (!includesType(it.dataTypes, t)) {
|
|
2481
|
+
strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
|
|
2536
2482
|
}
|
|
2483
|
+
});
|
|
2484
|
+
narrowSchemaTypes(it, types2);
|
|
2485
|
+
}
|
|
2486
|
+
function checkMultipleTypes(it, ts) {
|
|
2487
|
+
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
|
|
2488
|
+
strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
2537
2489
|
}
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
}
|
|
2490
|
+
}
|
|
2491
|
+
function checkKeywordTypes(it, ts) {
|
|
2492
|
+
const rules2 = it.self.RULES.all;
|
|
2493
|
+
for (const keyword2 in rules2) {
|
|
2494
|
+
const rule = rules2[keyword2];
|
|
2495
|
+
if (typeof rule == "object" && (0, applicability_1.shouldUseRule)(it.schema, rule)) {
|
|
2496
|
+
const { type: type2 } = rule.definition;
|
|
2497
|
+
if (type2.length && !type2.some((t) => hasApplicableType(ts, t))) {
|
|
2498
|
+
strictTypesError(it, `missing type "${type2.join(",")}" for keyword "${keyword2}"`);
|
|
2547
2499
|
}
|
|
2548
2500
|
}
|
|
2549
2501
|
}
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
}
|
|
2593
|
-
}
|
|
2594
|
-
if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
|
|
2595
|
-
this.errsCount = it.gen.const("_errs", names_12.default.errors);
|
|
2596
|
-
}
|
|
2597
|
-
}
|
|
2598
|
-
result(condition, successAction, failAction) {
|
|
2599
|
-
this.failResult((0, codegen_12.not)(condition), successAction, failAction);
|
|
2600
|
-
}
|
|
2601
|
-
failResult(condition, successAction, failAction) {
|
|
2602
|
-
this.gen.if(condition);
|
|
2603
|
-
if (failAction)
|
|
2604
|
-
failAction();
|
|
2605
|
-
else
|
|
2606
|
-
this.error();
|
|
2607
|
-
if (successAction) {
|
|
2608
|
-
this.gen.else();
|
|
2609
|
-
successAction();
|
|
2610
|
-
if (this.allErrors)
|
|
2611
|
-
this.gen.endIf();
|
|
2612
|
-
} else {
|
|
2613
|
-
if (this.allErrors)
|
|
2614
|
-
this.gen.endIf();
|
|
2615
|
-
else
|
|
2616
|
-
this.gen.else();
|
|
2502
|
+
}
|
|
2503
|
+
function hasApplicableType(schTs, kwdT) {
|
|
2504
|
+
return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
|
|
2505
|
+
}
|
|
2506
|
+
function includesType(ts, t) {
|
|
2507
|
+
return ts.includes(t) || t === "integer" && ts.includes("number");
|
|
2508
|
+
}
|
|
2509
|
+
function narrowSchemaTypes(it, withTypes) {
|
|
2510
|
+
const ts = [];
|
|
2511
|
+
for (const t of it.dataTypes) {
|
|
2512
|
+
if (includesType(withTypes, t))
|
|
2513
|
+
ts.push(t);
|
|
2514
|
+
else if (withTypes.includes("integer") && t === "number")
|
|
2515
|
+
ts.push("integer");
|
|
2516
|
+
}
|
|
2517
|
+
it.dataTypes = ts;
|
|
2518
|
+
}
|
|
2519
|
+
function strictTypesError(it, msg) {
|
|
2520
|
+
const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
|
|
2521
|
+
msg += ` at "${schemaPath}" (strictTypes)`;
|
|
2522
|
+
(0, util_1$p.checkStrictMode)(it, msg, it.opts.strictTypes);
|
|
2523
|
+
}
|
|
2524
|
+
class KeywordCxt {
|
|
2525
|
+
constructor(it, def2, keyword2) {
|
|
2526
|
+
(0, keyword_1.validateKeywordUsage)(it, def2, keyword2);
|
|
2527
|
+
this.gen = it.gen;
|
|
2528
|
+
this.allErrors = it.allErrors;
|
|
2529
|
+
this.keyword = keyword2;
|
|
2530
|
+
this.data = it.data;
|
|
2531
|
+
this.schema = it.schema[keyword2];
|
|
2532
|
+
this.$data = def2.$data && it.opts.$data && this.schema && this.schema.$data;
|
|
2533
|
+
this.schemaValue = (0, util_1$p.schemaRefOrVal)(it, this.schema, keyword2, this.$data);
|
|
2534
|
+
this.schemaType = def2.schemaType;
|
|
2535
|
+
this.parentSchema = it.schema;
|
|
2536
|
+
this.params = {};
|
|
2537
|
+
this.it = it;
|
|
2538
|
+
this.def = def2;
|
|
2539
|
+
if (this.$data) {
|
|
2540
|
+
this.schemaCode = it.gen.const("vSchema", getData(this.$data, it));
|
|
2541
|
+
} else {
|
|
2542
|
+
this.schemaCode = this.schemaValue;
|
|
2543
|
+
if (!(0, keyword_1.validSchemaType)(this.schema, def2.schemaType, def2.allowUndefined)) {
|
|
2544
|
+
throw new Error(`${keyword2} value must be ${JSON.stringify(def2.schemaType)}`);
|
|
2617
2545
|
}
|
|
2618
2546
|
}
|
|
2619
|
-
|
|
2620
|
-
this.
|
|
2547
|
+
if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
|
|
2548
|
+
this.errsCount = it.gen.const("_errs", names_1$6.default.errors);
|
|
2621
2549
|
}
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2550
|
+
}
|
|
2551
|
+
result(condition, successAction, failAction) {
|
|
2552
|
+
this.failResult((0, codegen_1$r.not)(condition), successAction, failAction);
|
|
2553
|
+
}
|
|
2554
|
+
failResult(condition, successAction, failAction) {
|
|
2555
|
+
this.gen.if(condition);
|
|
2556
|
+
if (failAction)
|
|
2557
|
+
failAction();
|
|
2558
|
+
else
|
|
2630
2559
|
this.error();
|
|
2560
|
+
if (successAction) {
|
|
2561
|
+
this.gen.else();
|
|
2562
|
+
successAction();
|
|
2563
|
+
if (this.allErrors)
|
|
2564
|
+
this.gen.endIf();
|
|
2565
|
+
} else {
|
|
2631
2566
|
if (this.allErrors)
|
|
2632
2567
|
this.gen.endIf();
|
|
2633
2568
|
else
|
|
2634
2569
|
this.gen.else();
|
|
2635
2570
|
}
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
if (errorParams) {
|
|
2644
|
-
this.setParams(errorParams);
|
|
2645
|
-
this._error(append, errorPaths);
|
|
2646
|
-
this.setParams({});
|
|
2647
|
-
return;
|
|
2648
|
-
}
|
|
2649
|
-
this._error(append, errorPaths);
|
|
2650
|
-
}
|
|
2651
|
-
_error(append, errorPaths) {
|
|
2652
|
-
(append ? errors_12.reportExtraError : errors_12.reportError)(this, this.def.error, errorPaths);
|
|
2653
|
-
}
|
|
2654
|
-
$dataError() {
|
|
2655
|
-
(0, errors_12.reportError)(this, this.def.$dataError || errors_12.keyword$DataError);
|
|
2656
|
-
}
|
|
2657
|
-
reset() {
|
|
2658
|
-
if (this.errsCount === void 0)
|
|
2659
|
-
throw new Error('add "trackErrors" to keyword definition');
|
|
2660
|
-
(0, errors_12.resetErrorsCount)(this.gen, this.errsCount);
|
|
2661
|
-
}
|
|
2662
|
-
ok(cond) {
|
|
2571
|
+
}
|
|
2572
|
+
pass(condition, failAction) {
|
|
2573
|
+
this.failResult((0, codegen_1$r.not)(condition), void 0, failAction);
|
|
2574
|
+
}
|
|
2575
|
+
fail(condition) {
|
|
2576
|
+
if (condition === void 0) {
|
|
2577
|
+
this.error();
|
|
2663
2578
|
if (!this.allErrors)
|
|
2664
|
-
this.gen.if(
|
|
2579
|
+
this.gen.if(false);
|
|
2580
|
+
return;
|
|
2665
2581
|
}
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2582
|
+
this.gen.if(condition);
|
|
2583
|
+
this.error();
|
|
2584
|
+
if (this.allErrors)
|
|
2585
|
+
this.gen.endIf();
|
|
2586
|
+
else
|
|
2587
|
+
this.gen.else();
|
|
2588
|
+
}
|
|
2589
|
+
fail$data(condition) {
|
|
2590
|
+
if (!this.$data)
|
|
2591
|
+
return this.fail(condition);
|
|
2592
|
+
const { schemaCode } = this;
|
|
2593
|
+
this.fail((0, codegen_1$r._)`${schemaCode} !== undefined && (${(0, codegen_1$r.or)(this.invalid$data(), condition)})`);
|
|
2594
|
+
}
|
|
2595
|
+
error(append, errorParams, errorPaths) {
|
|
2596
|
+
if (errorParams) {
|
|
2597
|
+
this.setParams(errorParams);
|
|
2598
|
+
this._error(append, errorPaths);
|
|
2599
|
+
this.setParams({});
|
|
2600
|
+
return;
|
|
2671
2601
|
}
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2602
|
+
this._error(append, errorPaths);
|
|
2603
|
+
}
|
|
2604
|
+
_error(append, errorPaths) {
|
|
2605
|
+
(append ? errors_1.reportExtraError : errors_1.reportError)(this, this.def.error, errorPaths);
|
|
2606
|
+
}
|
|
2607
|
+
$dataError() {
|
|
2608
|
+
(0, errors_1.reportError)(this, this.def.$dataError || errors_1.keyword$DataError);
|
|
2609
|
+
}
|
|
2610
|
+
reset() {
|
|
2611
|
+
if (this.errsCount === void 0)
|
|
2612
|
+
throw new Error('add "trackErrors" to keyword definition');
|
|
2613
|
+
(0, errors_1.resetErrorsCount)(this.gen, this.errsCount);
|
|
2614
|
+
}
|
|
2615
|
+
ok(cond) {
|
|
2616
|
+
if (!this.allErrors)
|
|
2617
|
+
this.gen.if(cond);
|
|
2618
|
+
}
|
|
2619
|
+
setParams(obj, assign) {
|
|
2620
|
+
if (assign)
|
|
2621
|
+
Object.assign(this.params, obj);
|
|
2622
|
+
else
|
|
2623
|
+
this.params = obj;
|
|
2624
|
+
}
|
|
2625
|
+
block$data(valid, codeBlock, $dataValid = codegen_1$r.nil) {
|
|
2626
|
+
this.gen.block(() => {
|
|
2627
|
+
this.check$data(valid, $dataValid);
|
|
2628
|
+
codeBlock();
|
|
2629
|
+
});
|
|
2630
|
+
}
|
|
2631
|
+
check$data(valid = codegen_1$r.nil, $dataValid = codegen_1$r.nil) {
|
|
2632
|
+
if (!this.$data)
|
|
2633
|
+
return;
|
|
2634
|
+
const { gen, schemaCode, schemaType, def: def2 } = this;
|
|
2635
|
+
gen.if((0, codegen_1$r.or)((0, codegen_1$r._)`${schemaCode} === undefined`, $dataValid));
|
|
2636
|
+
if (valid !== codegen_1$r.nil)
|
|
2637
|
+
gen.assign(valid, true);
|
|
2638
|
+
if (schemaType.length || def2.validateSchema) {
|
|
2639
|
+
gen.elseIf(this.invalid$data());
|
|
2640
|
+
this.$dataError();
|
|
2641
|
+
if (valid !== codegen_1$r.nil)
|
|
2642
|
+
gen.assign(valid, false);
|
|
2677
2643
|
}
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
gen.assign(valid, false);
|
|
2644
|
+
gen.else();
|
|
2645
|
+
}
|
|
2646
|
+
invalid$data() {
|
|
2647
|
+
const { gen, schemaCode, schemaType, def: def2, it } = this;
|
|
2648
|
+
return (0, codegen_1$r.or)(wrong$DataType(), invalid$DataSchema());
|
|
2649
|
+
function wrong$DataType() {
|
|
2650
|
+
if (schemaType.length) {
|
|
2651
|
+
if (!(schemaCode instanceof codegen_1$r.Name))
|
|
2652
|
+
throw new Error("ajv implementation error");
|
|
2653
|
+
const st = Array.isArray(schemaType) ? schemaType : [schemaType];
|
|
2654
|
+
return (0, codegen_1$r._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
|
|
2690
2655
|
}
|
|
2691
|
-
|
|
2656
|
+
return codegen_1$r.nil;
|
|
2692
2657
|
}
|
|
2693
|
-
invalid$
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
if (schemaType.length) {
|
|
2698
|
-
if (!(schemaCode instanceof codegen_12.Name))
|
|
2699
|
-
throw new Error("ajv implementation error");
|
|
2700
|
-
const st = Array.isArray(schemaType) ? schemaType : [schemaType];
|
|
2701
|
-
return (0, codegen_12._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
|
|
2702
|
-
}
|
|
2703
|
-
return codegen_12.nil;
|
|
2704
|
-
}
|
|
2705
|
-
function invalid$DataSchema() {
|
|
2706
|
-
if (def2.validateSchema) {
|
|
2707
|
-
const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
|
|
2708
|
-
return (0, codegen_12._)`!${validateSchemaRef}(${schemaCode})`;
|
|
2709
|
-
}
|
|
2710
|
-
return codegen_12.nil;
|
|
2658
|
+
function invalid$DataSchema() {
|
|
2659
|
+
if (def2.validateSchema) {
|
|
2660
|
+
const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
|
|
2661
|
+
return (0, codegen_1$r._)`!${validateSchemaRef}(${schemaCode})`;
|
|
2711
2662
|
}
|
|
2663
|
+
return codegen_1$r.nil;
|
|
2712
2664
|
}
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
if (it.items !== true && schemaCxt.items !== void 0) {
|
|
2729
|
-
it.items = util_12.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
|
|
2730
|
-
}
|
|
2665
|
+
}
|
|
2666
|
+
subschema(appl, valid) {
|
|
2667
|
+
const subschema2 = (0, subschema_1.getSubschema)(this.it, appl);
|
|
2668
|
+
(0, subschema_1.extendSubschemaData)(subschema2, this.it, appl);
|
|
2669
|
+
(0, subschema_1.extendSubschemaMode)(subschema2, appl);
|
|
2670
|
+
const nextContext = { ...this.it, ...subschema2, items: void 0, props: void 0 };
|
|
2671
|
+
subschemaCode(nextContext, valid);
|
|
2672
|
+
return nextContext;
|
|
2673
|
+
}
|
|
2674
|
+
mergeEvaluated(schemaCxt, toName) {
|
|
2675
|
+
const { it, gen } = this;
|
|
2676
|
+
if (!it.opts.unevaluated)
|
|
2677
|
+
return;
|
|
2678
|
+
if (it.props !== true && schemaCxt.props !== void 0) {
|
|
2679
|
+
it.props = util_1$p.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
|
|
2731
2680
|
}
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
|
|
2735
|
-
gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_12.Name));
|
|
2736
|
-
return true;
|
|
2737
|
-
}
|
|
2681
|
+
if (it.items !== true && schemaCxt.items !== void 0) {
|
|
2682
|
+
it.items = util_1$p.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
|
|
2738
2683
|
}
|
|
2739
2684
|
}
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
} else if (cxt.$data && def2.validate) {
|
|
2746
|
-
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2747
|
-
} else if ("macro" in def2) {
|
|
2748
|
-
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
2749
|
-
} else if (def2.compile || def2.validate) {
|
|
2750
|
-
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2751
|
-
}
|
|
2752
|
-
}
|
|
2753
|
-
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
2754
|
-
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
2755
|
-
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
2756
|
-
let jsonPointer;
|
|
2757
|
-
let data;
|
|
2758
|
-
if ($data === "")
|
|
2759
|
-
return names_12.default.rootData;
|
|
2760
|
-
if ($data[0] === "/") {
|
|
2761
|
-
if (!JSON_POINTER.test($data))
|
|
2762
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2763
|
-
jsonPointer = $data;
|
|
2764
|
-
data = names_12.default.rootData;
|
|
2765
|
-
} else {
|
|
2766
|
-
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
2767
|
-
if (!matches)
|
|
2768
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2769
|
-
const up = +matches[1];
|
|
2770
|
-
jsonPointer = matches[2];
|
|
2771
|
-
if (jsonPointer === "#") {
|
|
2772
|
-
if (up >= dataLevel)
|
|
2773
|
-
throw new Error(errorMsg("property/index", up));
|
|
2774
|
-
return dataPathArr[dataLevel - up];
|
|
2775
|
-
}
|
|
2776
|
-
if (up > dataLevel)
|
|
2777
|
-
throw new Error(errorMsg("data", up));
|
|
2778
|
-
data = dataNames[dataLevel - up];
|
|
2779
|
-
if (!jsonPointer)
|
|
2780
|
-
return data;
|
|
2781
|
-
}
|
|
2782
|
-
let expr = data;
|
|
2783
|
-
const segments = jsonPointer.split("/");
|
|
2784
|
-
for (const segment of segments) {
|
|
2785
|
-
if (segment) {
|
|
2786
|
-
data = (0, codegen_12._)`${data}${(0, codegen_12.getProperty)((0, util_12.unescapeJsonPointer)(segment))}`;
|
|
2787
|
-
expr = (0, codegen_12._)`${expr} && ${data}`;
|
|
2788
|
-
}
|
|
2789
|
-
}
|
|
2790
|
-
return expr;
|
|
2791
|
-
function errorMsg(pointerType, up) {
|
|
2792
|
-
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
2685
|
+
mergeValidEvaluated(schemaCxt, valid) {
|
|
2686
|
+
const { it, gen } = this;
|
|
2687
|
+
if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
|
|
2688
|
+
gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_1$r.Name));
|
|
2689
|
+
return true;
|
|
2793
2690
|
}
|
|
2794
2691
|
}
|
|
2795
|
-
validate.getData = getData;
|
|
2796
|
-
return validate;
|
|
2797
2692
|
}
|
|
2693
|
+
validate.KeywordCxt = KeywordCxt;
|
|
2694
|
+
function keywordCode(it, keyword2, def2, ruleType) {
|
|
2695
|
+
const cxt = new KeywordCxt(it, def2, keyword2);
|
|
2696
|
+
if ("code" in def2) {
|
|
2697
|
+
def2.code(cxt, ruleType);
|
|
2698
|
+
} else if (cxt.$data && def2.validate) {
|
|
2699
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2700
|
+
} else if ("macro" in def2) {
|
|
2701
|
+
(0, keyword_1.macroKeywordCode)(cxt, def2);
|
|
2702
|
+
} else if (def2.compile || def2.validate) {
|
|
2703
|
+
(0, keyword_1.funcKeywordCode)(cxt, def2);
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
2707
|
+
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
2708
|
+
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
2709
|
+
let jsonPointer;
|
|
2710
|
+
let data;
|
|
2711
|
+
if ($data === "")
|
|
2712
|
+
return names_1$6.default.rootData;
|
|
2713
|
+
if ($data[0] === "/") {
|
|
2714
|
+
if (!JSON_POINTER.test($data))
|
|
2715
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2716
|
+
jsonPointer = $data;
|
|
2717
|
+
data = names_1$6.default.rootData;
|
|
2718
|
+
} else {
|
|
2719
|
+
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
2720
|
+
if (!matches)
|
|
2721
|
+
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
2722
|
+
const up = +matches[1];
|
|
2723
|
+
jsonPointer = matches[2];
|
|
2724
|
+
if (jsonPointer === "#") {
|
|
2725
|
+
if (up >= dataLevel)
|
|
2726
|
+
throw new Error(errorMsg("property/index", up));
|
|
2727
|
+
return dataPathArr[dataLevel - up];
|
|
2728
|
+
}
|
|
2729
|
+
if (up > dataLevel)
|
|
2730
|
+
throw new Error(errorMsg("data", up));
|
|
2731
|
+
data = dataNames[dataLevel - up];
|
|
2732
|
+
if (!jsonPointer)
|
|
2733
|
+
return data;
|
|
2734
|
+
}
|
|
2735
|
+
let expr = data;
|
|
2736
|
+
const segments = jsonPointer.split("/");
|
|
2737
|
+
for (const segment of segments) {
|
|
2738
|
+
if (segment) {
|
|
2739
|
+
data = (0, codegen_1$r._)`${data}${(0, codegen_1$r.getProperty)((0, util_1$p.unescapeJsonPointer)(segment))}`;
|
|
2740
|
+
expr = (0, codegen_1$r._)`${expr} && ${data}`;
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
return expr;
|
|
2744
|
+
function errorMsg(pointerType, up) {
|
|
2745
|
+
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
validate.getData = getData;
|
|
2798
2749
|
var validation_error = {};
|
|
2799
2750
|
Object.defineProperty(validation_error, "__esModule", { value: true });
|
|
2800
2751
|
class ValidationError extends Error {
|
|
@@ -2821,10 +2772,10 @@ Object.defineProperty(compile, "__esModule", { value: true });
|
|
|
2821
2772
|
compile.resolveSchema = compile.getCompilingSchema = compile.resolveRef = compile.compileSchema = compile.SchemaEnv = void 0;
|
|
2822
2773
|
const codegen_1$q = codegen;
|
|
2823
2774
|
const validation_error_1 = validation_error;
|
|
2824
|
-
const names_1$5 =
|
|
2775
|
+
const names_1$5 = names$1;
|
|
2825
2776
|
const resolve_1 = resolve$2;
|
|
2826
2777
|
const util_1$o = util;
|
|
2827
|
-
const validate_1$1 =
|
|
2778
|
+
const validate_1$1 = validate;
|
|
2828
2779
|
class SchemaEnv {
|
|
2829
2780
|
constructor(env) {
|
|
2830
2781
|
var _a;
|
|
@@ -3775,7 +3726,7 @@ uri$1.default = uri;
|
|
|
3775
3726
|
(function(exports2) {
|
|
3776
3727
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3777
3728
|
exports2.CodeGen = exports2.Name = exports2.nil = exports2.stringify = exports2.str = exports2._ = exports2.KeywordCxt = void 0;
|
|
3778
|
-
var validate_12 =
|
|
3729
|
+
var validate_12 = validate;
|
|
3779
3730
|
Object.defineProperty(exports2, "KeywordCxt", { enumerable: true, get: function() {
|
|
3780
3731
|
return validate_12.KeywordCxt;
|
|
3781
3732
|
} });
|
|
@@ -4395,7 +4346,7 @@ ref.callRef = ref.getValidate = void 0;
|
|
|
4395
4346
|
const ref_error_1$1 = ref_error;
|
|
4396
4347
|
const code_1$8 = code;
|
|
4397
4348
|
const codegen_1$p = codegen;
|
|
4398
|
-
const names_1$4 =
|
|
4349
|
+
const names_1$4 = names$1;
|
|
4399
4350
|
const compile_1$2 = compile;
|
|
4400
4351
|
const util_1$n = util;
|
|
4401
4352
|
const def$A = {
|
|
@@ -5279,7 +5230,7 @@ var additionalProperties = {};
|
|
|
5279
5230
|
Object.defineProperty(additionalProperties, "__esModule", { value: true });
|
|
5280
5231
|
const code_1$3 = code;
|
|
5281
5232
|
const codegen_1$9 = codegen;
|
|
5282
|
-
const names_1$3 =
|
|
5233
|
+
const names_1$3 = names$1;
|
|
5283
5234
|
const util_1$c = util;
|
|
5284
5235
|
const error$6 = {
|
|
5285
5236
|
message: "must NOT have additional properties",
|
|
@@ -5377,7 +5328,7 @@ const def$j = {
|
|
|
5377
5328
|
additionalProperties.default = def$j;
|
|
5378
5329
|
var properties$8 = {};
|
|
5379
5330
|
Object.defineProperty(properties$8, "__esModule", { value: true });
|
|
5380
|
-
const validate_1 =
|
|
5331
|
+
const validate_1 = validate;
|
|
5381
5332
|
const code_1$2 = code;
|
|
5382
5333
|
const util_1$b = util;
|
|
5383
5334
|
const additionalProperties_1$1 = additionalProperties;
|
|
@@ -5725,7 +5676,7 @@ var dynamicAnchor$1 = {};
|
|
|
5725
5676
|
Object.defineProperty(dynamicAnchor$1, "__esModule", { value: true });
|
|
5726
5677
|
dynamicAnchor$1.dynamicAnchor = void 0;
|
|
5727
5678
|
const codegen_1$5 = codegen;
|
|
5728
|
-
const names_1$2 =
|
|
5679
|
+
const names_1$2 = names$1;
|
|
5729
5680
|
const compile_1$1 = compile;
|
|
5730
5681
|
const ref_1$1 = ref;
|
|
5731
5682
|
const def$a = {
|
|
@@ -5754,7 +5705,7 @@ var dynamicRef$1 = {};
|
|
|
5754
5705
|
Object.defineProperty(dynamicRef$1, "__esModule", { value: true });
|
|
5755
5706
|
dynamicRef$1.dynamicRef = void 0;
|
|
5756
5707
|
const codegen_1$4 = codegen;
|
|
5757
|
-
const names_1$1 =
|
|
5708
|
+
const names_1$1 = names$1;
|
|
5758
5709
|
const ref_1 = ref;
|
|
5759
5710
|
const def$9 = {
|
|
5760
5711
|
keyword: "$dynamicRef",
|
|
@@ -5868,7 +5819,7 @@ var unevaluatedProperties = {};
|
|
|
5868
5819
|
Object.defineProperty(unevaluatedProperties, "__esModule", { value: true });
|
|
5869
5820
|
const codegen_1$3 = codegen;
|
|
5870
5821
|
const util_1$2 = util;
|
|
5871
|
-
const names_1 =
|
|
5822
|
+
const names_1 = names$1;
|
|
5872
5823
|
const error$3 = {
|
|
5873
5824
|
message: "must NOT have unevaluated properties",
|
|
5874
5825
|
params: ({ params }) => (0, codegen_1$3._)`{unevaluatedProperty: ${params.unevaluatedProperty}}`
|
|
@@ -6784,7 +6735,7 @@ jsonSchema202012.default = addMetaSchema2020;
|
|
|
6784
6735
|
module2.exports.Ajv2020 = Ajv20202;
|
|
6785
6736
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
6786
6737
|
exports2.default = Ajv20202;
|
|
6787
|
-
var validate_12 =
|
|
6738
|
+
var validate_12 = validate;
|
|
6788
6739
|
Object.defineProperty(exports2, "KeywordCxt", { enumerable: true, get: function() {
|
|
6789
6740
|
return validate_12.KeywordCxt;
|
|
6790
6741
|
} });
|
|
@@ -7162,12 +7113,12 @@ const create = async function() {
|
|
|
7162
7113
|
const appPackageJSON = await readJSON(appPackageJSONPath);
|
|
7163
7114
|
if (appPackageJSON.dependencies) {
|
|
7164
7115
|
const packageJSON = getPackageJSON();
|
|
7165
|
-
if (packageJSON.
|
|
7166
|
-
const ONES_OPEN_NODE_SDK_VERSION = packageJSON.
|
|
7116
|
+
if (packageJSON.devDependencies) {
|
|
7117
|
+
const ONES_OPEN_NODE_SDK_VERSION = packageJSON.devDependencies[ONES_OPEN_NODE_SDK];
|
|
7167
7118
|
if (ONES_OPEN_NODE_SDK_VERSION) {
|
|
7168
7119
|
appPackageJSON.dependencies[ONES_OPEN_NODE_SDK] = ONES_OPEN_NODE_SDK_VERSION;
|
|
7169
7120
|
}
|
|
7170
|
-
const ONES_OPEN_WEB_SDK_VERSION = packageJSON.
|
|
7121
|
+
const ONES_OPEN_WEB_SDK_VERSION = packageJSON.devDependencies[ONES_OPEN_WEB_SDK];
|
|
7171
7122
|
if (ONES_OPEN_WEB_SDK_VERSION) {
|
|
7172
7123
|
appPackageJSON.dependencies[ONES_OPEN_WEB_SDK] = ONES_OPEN_WEB_SDK_VERSION;
|
|
7173
7124
|
}
|