@opentiny/next-sdk 0.1.4 → 0.1.5

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