@opentiny/next-sdk 0.1.12 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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;
@@ -3006,58 +2970,81 @@
3006
2970
  };
3007
2971
  var uri$2 = {};
3008
2972
  var fastUri$1 = { exports: {} };
3009
- const isUUID$1 = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu);
3010
- const isIPv4$1 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
3011
- function stringArrayToHexStripped(input) {
3012
- let acc = "";
3013
- let code2 = 0;
3014
- let i = 0;
3015
- for (i = 0; i < input.length; i++) {
3016
- code2 = input[i].charCodeAt(0);
3017
- if (code2 === 48) {
3018
- continue;
3019
- }
3020
- if (!(code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 70 || code2 >= 97 && code2 <= 102)) {
3021
- return "";
3022
- }
3023
- acc += input[i];
3024
- break;
3025
- }
3026
- for (i += 1; i < input.length; i++) {
3027
- code2 = input[i].charCodeAt(0);
3028
- if (!(code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 70 || code2 >= 97 && code2 <= 102)) {
3029
- return "";
3030
- }
3031
- acc += input[i];
2973
+ const HEX$1 = {
2974
+ 0: 0,
2975
+ 1: 1,
2976
+ 2: 2,
2977
+ 3: 3,
2978
+ 4: 4,
2979
+ 5: 5,
2980
+ 6: 6,
2981
+ 7: 7,
2982
+ 8: 8,
2983
+ 9: 9,
2984
+ a: 10,
2985
+ A: 10,
2986
+ b: 11,
2987
+ B: 11,
2988
+ c: 12,
2989
+ C: 12,
2990
+ d: 13,
2991
+ D: 13,
2992
+ e: 14,
2993
+ E: 14,
2994
+ f: 15,
2995
+ F: 15
2996
+ };
2997
+ var scopedChars = {
2998
+ HEX: HEX$1
2999
+ };
3000
+ const { HEX } = scopedChars;
3001
+ const IPV4_REG = /^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u;
3002
+ function normalizeIPv4$1(host) {
3003
+ if (findToken(host, ".") < 3) {
3004
+ return { host, isIPV4: false };
3005
+ }
3006
+ const matches = host.match(IPV4_REG) || [];
3007
+ const [address] = matches;
3008
+ if (address) {
3009
+ return { host: stripLeadingZeros(address, "."), isIPV4: true };
3010
+ } else {
3011
+ return { host, isIPV4: false };
3032
3012
  }
3033
- return acc;
3034
3013
  }
3035
- const nonSimpleDomain$1 = RegExp.prototype.test.bind(/[^!"$&'()*+,\-.;=_`a-z{}~]/u);
3036
- function consumeIsZone(buffer) {
3037
- buffer.length = 0;
3038
- return true;
3039
- }
3040
- function consumeHextets(buffer, address, output) {
3041
- if (buffer.length) {
3042
- const hex = stringArrayToHexStripped(buffer);
3043
- if (hex !== "") {
3044
- address.push(hex);
3045
- } else {
3046
- output.error = true;
3047
- return false;
3048
- }
3049
- buffer.length = 0;
3014
+ function stringArrayToHexStripped(input, keepZero = false) {
3015
+ let acc = "";
3016
+ let strip = true;
3017
+ for (const c of input) {
3018
+ if (HEX[c] === void 0) return void 0;
3019
+ if (c !== "0" && strip === true) strip = false;
3020
+ if (!strip) acc += c;
3050
3021
  }
3051
- return true;
3022
+ if (keepZero && acc.length === 0) acc = "0";
3023
+ return acc;
3052
3024
  }
3053
3025
  function getIPV6(input) {
3054
3026
  let tokenCount = 0;
3055
3027
  const output = { error: false, address: "", zone: "" };
3056
3028
  const address = [];
3057
3029
  const buffer = [];
3030
+ let isZone = false;
3058
3031
  let endipv6Encountered = false;
3059
3032
  let endIpv6 = false;
3060
- let consume = consumeHextets;
3033
+ function consume() {
3034
+ if (buffer.length) {
3035
+ if (isZone === false) {
3036
+ const hex = stringArrayToHexStripped(buffer);
3037
+ if (hex !== void 0) {
3038
+ address.push(hex);
3039
+ } else {
3040
+ output.error = true;
3041
+ return false;
3042
+ }
3043
+ }
3044
+ buffer.length = 0;
3045
+ }
3046
+ return true;
3047
+ }
3061
3048
  for (let i = 0; i < input.length; i++) {
3062
3049
  const cursor = input[i];
3063
3050
  if (cursor === "[" || cursor === "]") {
@@ -3067,30 +3054,31 @@
3067
3054
  if (endipv6Encountered === true) {
3068
3055
  endIpv6 = true;
3069
3056
  }
3070
- if (!consume(buffer, address, output)) {
3057
+ if (!consume()) {
3071
3058
  break;
3072
3059
  }
3073
- if (++tokenCount > 7) {
3060
+ tokenCount++;
3061
+ address.push(":");
3062
+ if (tokenCount > 7) {
3074
3063
  output.error = true;
3075
3064
  break;
3076
3065
  }
3077
- if (i > 0 && input[i - 1] === ":") {
3066
+ if (i - 1 >= 0 && input[i - 1] === ":") {
3078
3067
  endipv6Encountered = true;
3079
3068
  }
3080
- address.push(":");
3081
3069
  continue;
3082
3070
  } else if (cursor === "%") {
3083
- if (!consume(buffer, address, output)) {
3071
+ if (!consume()) {
3084
3072
  break;
3085
3073
  }
3086
- consume = consumeIsZone;
3074
+ isZone = true;
3087
3075
  } else {
3088
3076
  buffer.push(cursor);
3089
3077
  continue;
3090
3078
  }
3091
3079
  }
3092
3080
  if (buffer.length) {
3093
- if (consume === consumeIsZone) {
3081
+ if (isZone) {
3094
3082
  output.zone = buffer.join("");
3095
3083
  } else if (endIpv6) {
3096
3084
  address.push(buffer.join(""));
@@ -3113,11 +3101,33 @@
3113
3101
  newHost += "%" + ipv6.zone;
3114
3102
  escapedHost += "%25" + ipv6.zone;
3115
3103
  }
3116
- return { host: newHost, isIPV6: true, escapedHost };
3104
+ return { host: newHost, escapedHost, isIPV6: true };
3117
3105
  } else {
3118
3106
  return { host, isIPV6: false };
3119
3107
  }
3120
3108
  }
3109
+ function stripLeadingZeros(str, token) {
3110
+ let out = "";
3111
+ let skip = true;
3112
+ const l = str.length;
3113
+ for (let i = 0; i < l; i++) {
3114
+ const c = str[i];
3115
+ if (c === "0" && skip) {
3116
+ if (i + 1 <= l && str[i + 1] === token || i + 1 === l) {
3117
+ out += c;
3118
+ skip = false;
3119
+ }
3120
+ } else {
3121
+ if (c === token) {
3122
+ skip = true;
3123
+ } else {
3124
+ skip = false;
3125
+ }
3126
+ out += c;
3127
+ }
3128
+ }
3129
+ return out;
3130
+ }
3121
3131
  function findToken(str, token) {
3122
3132
  let ind = 0;
3123
3133
  for (let i = 0; i < str.length; i++) {
@@ -3125,339 +3135,246 @@
3125
3135
  }
3126
3136
  return ind;
3127
3137
  }
3128
- function removeDotSegments$1(path) {
3129
- let input = path;
3138
+ const RDS1 = /^\.\.?\//u;
3139
+ const RDS2 = /^\/\.(?:\/|$)/u;
3140
+ const RDS3 = /^\/\.\.(?:\/|$)/u;
3141
+ const RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/u;
3142
+ function removeDotSegments$1(input) {
3130
3143
  const output = [];
3131
- let nextSlash = -1;
3132
- let len = 0;
3133
- while (len = input.length) {
3134
- if (len === 1) {
3135
- if (input === ".") {
3136
- break;
3137
- } else if (input === "/") {
3138
- output.push("/");
3139
- break;
3144
+ while (input.length) {
3145
+ if (input.match(RDS1)) {
3146
+ input = input.replace(RDS1, "");
3147
+ } else if (input.match(RDS2)) {
3148
+ input = input.replace(RDS2, "/");
3149
+ } else if (input.match(RDS3)) {
3150
+ input = input.replace(RDS3, "/");
3151
+ output.pop();
3152
+ } else if (input === "." || input === "..") {
3153
+ input = "";
3154
+ } else {
3155
+ const im = input.match(RDS5);
3156
+ if (im) {
3157
+ const s = im[0];
3158
+ input = input.slice(s.length);
3159
+ output.push(s);
3140
3160
  } else {
3141
- output.push(input);
3142
- break;
3143
- }
3144
- } else if (len === 2) {
3145
- if (input[0] === ".") {
3146
- if (input[1] === ".") {
3147
- break;
3148
- } else if (input[1] === "/") {
3149
- input = input.slice(2);
3150
- continue;
3151
- }
3152
- } else if (input[0] === "/") {
3153
- if (input[1] === "." || input[1] === "/") {
3154
- output.push("/");
3155
- break;
3156
- }
3157
- }
3158
- } else if (len === 3) {
3159
- if (input === "/..") {
3160
- if (output.length !== 0) {
3161
- output.pop();
3162
- }
3163
- output.push("/");
3164
- break;
3165
- }
3166
- }
3167
- if (input[0] === ".") {
3168
- if (input[1] === ".") {
3169
- if (input[2] === "/") {
3170
- input = input.slice(3);
3171
- continue;
3172
- }
3173
- } else if (input[1] === "/") {
3174
- input = input.slice(2);
3175
- continue;
3176
- }
3177
- } else if (input[0] === "/") {
3178
- if (input[1] === ".") {
3179
- if (input[2] === "/") {
3180
- input = input.slice(2);
3181
- continue;
3182
- } else if (input[2] === ".") {
3183
- if (input[3] === "/") {
3184
- input = input.slice(3);
3185
- if (output.length !== 0) {
3186
- output.pop();
3187
- }
3188
- continue;
3189
- }
3190
- }
3161
+ throw new Error("Unexpected dot segment condition");
3191
3162
  }
3192
3163
  }
3193
- if ((nextSlash = input.indexOf("/", 1)) === -1) {
3194
- output.push(input);
3195
- break;
3196
- } else {
3197
- output.push(input.slice(0, nextSlash));
3198
- input = input.slice(nextSlash);
3199
- }
3200
3164
  }
3201
3165
  return output.join("");
3202
3166
  }
3203
- function normalizeComponentEncoding$1(component, esc) {
3167
+ function normalizeComponentEncoding$1(components, esc) {
3204
3168
  const func = esc !== true ? escape : unescape;
3205
- if (component.scheme !== void 0) {
3206
- component.scheme = func(component.scheme);
3169
+ if (components.scheme !== void 0) {
3170
+ components.scheme = func(components.scheme);
3207
3171
  }
3208
- if (component.userinfo !== void 0) {
3209
- component.userinfo = func(component.userinfo);
3172
+ if (components.userinfo !== void 0) {
3173
+ components.userinfo = func(components.userinfo);
3210
3174
  }
3211
- if (component.host !== void 0) {
3212
- component.host = func(component.host);
3175
+ if (components.host !== void 0) {
3176
+ components.host = func(components.host);
3213
3177
  }
3214
- if (component.path !== void 0) {
3215
- component.path = func(component.path);
3178
+ if (components.path !== void 0) {
3179
+ components.path = func(components.path);
3216
3180
  }
3217
- if (component.query !== void 0) {
3218
- component.query = func(component.query);
3181
+ if (components.query !== void 0) {
3182
+ components.query = func(components.query);
3219
3183
  }
3220
- if (component.fragment !== void 0) {
3221
- component.fragment = func(component.fragment);
3184
+ if (components.fragment !== void 0) {
3185
+ components.fragment = func(components.fragment);
3222
3186
  }
3223
- return component;
3187
+ return components;
3224
3188
  }
3225
- function recomposeAuthority$1(component) {
3189
+ function recomposeAuthority$1(components) {
3226
3190
  const uriTokens = [];
3227
- if (component.userinfo !== void 0) {
3228
- uriTokens.push(component.userinfo);
3191
+ if (components.userinfo !== void 0) {
3192
+ uriTokens.push(components.userinfo);
3229
3193
  uriTokens.push("@");
3230
3194
  }
3231
- if (component.host !== void 0) {
3232
- let host = unescape(component.host);
3233
- if (!isIPv4$1(host)) {
3234
- const ipV6res = normalizeIPv6$1(host);
3195
+ if (components.host !== void 0) {
3196
+ let host = unescape(components.host);
3197
+ const ipV4res = normalizeIPv4$1(host);
3198
+ if (ipV4res.isIPV4) {
3199
+ host = ipV4res.host;
3200
+ } else {
3201
+ const ipV6res = normalizeIPv6$1(ipV4res.host);
3235
3202
  if (ipV6res.isIPV6 === true) {
3236
3203
  host = `[${ipV6res.escapedHost}]`;
3237
3204
  } else {
3238
- host = component.host;
3205
+ host = components.host;
3239
3206
  }
3240
3207
  }
3241
3208
  uriTokens.push(host);
3242
3209
  }
3243
- if (typeof component.port === "number" || typeof component.port === "string") {
3210
+ if (typeof components.port === "number" || typeof components.port === "string") {
3244
3211
  uriTokens.push(":");
3245
- uriTokens.push(String(component.port));
3212
+ uriTokens.push(String(components.port));
3246
3213
  }
3247
3214
  return uriTokens.length ? uriTokens.join("") : void 0;
3248
3215
  }
3249
3216
  var utils = {
3250
- nonSimpleDomain: nonSimpleDomain$1,
3251
3217
  recomposeAuthority: recomposeAuthority$1,
3252
3218
  normalizeComponentEncoding: normalizeComponentEncoding$1,
3253
3219
  removeDotSegments: removeDotSegments$1,
3254
- isIPv4: isIPv4$1,
3255
- isUUID: isUUID$1,
3220
+ normalizeIPv4: normalizeIPv4$1,
3256
3221
  normalizeIPv6: normalizeIPv6$1
3257
3222
  };
3258
- const { isUUID } = utils;
3223
+ const UUID_REG = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu;
3259
3224
  const URN_REG = /([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu;
3260
- function wsIsSecure(wsComponent) {
3261
- if (wsComponent.secure === true) {
3262
- return true;
3263
- } else if (wsComponent.secure === false) {
3264
- return false;
3265
- } else if (wsComponent.scheme) {
3266
- return wsComponent.scheme.length === 3 && (wsComponent.scheme[0] === "w" || wsComponent.scheme[0] === "W") && (wsComponent.scheme[1] === "s" || wsComponent.scheme[1] === "S") && (wsComponent.scheme[2] === "s" || wsComponent.scheme[2] === "S");
3267
- } else {
3268
- return false;
3269
- }
3225
+ function isSecure(wsComponents) {
3226
+ return typeof wsComponents.secure === "boolean" ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss";
3270
3227
  }
3271
- function httpParse(component) {
3272
- if (!component.host) {
3273
- component.error = component.error || "HTTP URIs must have a host.";
3228
+ function httpParse(components) {
3229
+ if (!components.host) {
3230
+ components.error = components.error || "HTTP URIs must have a host.";
3274
3231
  }
3275
- return component;
3232
+ return components;
3276
3233
  }
3277
- function httpSerialize(component) {
3278
- const secure = String(component.scheme).toLowerCase() === "https";
3279
- if (component.port === (secure ? 443 : 80) || component.port === "") {
3280
- component.port = void 0;
3234
+ function httpSerialize(components) {
3235
+ const secure = String(components.scheme).toLowerCase() === "https";
3236
+ if (components.port === (secure ? 443 : 80) || components.port === "") {
3237
+ components.port = void 0;
3281
3238
  }
3282
- if (!component.path) {
3283
- component.path = "/";
3239
+ if (!components.path) {
3240
+ components.path = "/";
3284
3241
  }
3285
- return component;
3242
+ return components;
3286
3243
  }
3287
- function wsParse(wsComponent) {
3288
- wsComponent.secure = wsIsSecure(wsComponent);
3289
- wsComponent.resourceName = (wsComponent.path || "/") + (wsComponent.query ? "?" + wsComponent.query : "");
3290
- wsComponent.path = void 0;
3291
- wsComponent.query = void 0;
3292
- return wsComponent;
3244
+ function wsParse(wsComponents) {
3245
+ wsComponents.secure = isSecure(wsComponents);
3246
+ wsComponents.resourceName = (wsComponents.path || "/") + (wsComponents.query ? "?" + wsComponents.query : "");
3247
+ wsComponents.path = void 0;
3248
+ wsComponents.query = void 0;
3249
+ return wsComponents;
3293
3250
  }
3294
- function wsSerialize(wsComponent) {
3295
- if (wsComponent.port === (wsIsSecure(wsComponent) ? 443 : 80) || wsComponent.port === "") {
3296
- wsComponent.port = void 0;
3251
+ function wsSerialize(wsComponents) {
3252
+ if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") {
3253
+ wsComponents.port = void 0;
3297
3254
  }
3298
- if (typeof wsComponent.secure === "boolean") {
3299
- wsComponent.scheme = wsComponent.secure ? "wss" : "ws";
3300
- wsComponent.secure = void 0;
3255
+ if (typeof wsComponents.secure === "boolean") {
3256
+ wsComponents.scheme = wsComponents.secure ? "wss" : "ws";
3257
+ wsComponents.secure = void 0;
3301
3258
  }
3302
- if (wsComponent.resourceName) {
3303
- const [path, query] = wsComponent.resourceName.split("?");
3304
- wsComponent.path = path && path !== "/" ? path : void 0;
3305
- wsComponent.query = query;
3306
- wsComponent.resourceName = void 0;
3259
+ if (wsComponents.resourceName) {
3260
+ const [path, query] = wsComponents.resourceName.split("?");
3261
+ wsComponents.path = path && path !== "/" ? path : void 0;
3262
+ wsComponents.query = query;
3263
+ wsComponents.resourceName = void 0;
3307
3264
  }
3308
- wsComponent.fragment = void 0;
3309
- return wsComponent;
3265
+ wsComponents.fragment = void 0;
3266
+ return wsComponents;
3310
3267
  }
3311
- function urnParse(urnComponent, options) {
3312
- if (!urnComponent.path) {
3313
- urnComponent.error = "URN can not be parsed";
3314
- return urnComponent;
3268
+ function urnParse(urnComponents, options) {
3269
+ if (!urnComponents.path) {
3270
+ urnComponents.error = "URN can not be parsed";
3271
+ return urnComponents;
3315
3272
  }
3316
- const matches = urnComponent.path.match(URN_REG);
3273
+ const matches = urnComponents.path.match(URN_REG);
3317
3274
  if (matches) {
3318
- const scheme = options.scheme || urnComponent.scheme || "urn";
3319
- urnComponent.nid = matches[1].toLowerCase();
3320
- urnComponent.nss = matches[2];
3321
- const urnScheme = `${scheme}:${options.nid || urnComponent.nid}`;
3322
- const schemeHandler = getSchemeHandler$1(urnScheme);
3323
- urnComponent.path = void 0;
3275
+ const scheme = options.scheme || urnComponents.scheme || "urn";
3276
+ urnComponents.nid = matches[1].toLowerCase();
3277
+ urnComponents.nss = matches[2];
3278
+ const urnScheme = `${scheme}:${options.nid || urnComponents.nid}`;
3279
+ const schemeHandler = SCHEMES$1[urnScheme];
3280
+ urnComponents.path = void 0;
3324
3281
  if (schemeHandler) {
3325
- urnComponent = schemeHandler.parse(urnComponent, options);
3282
+ urnComponents = schemeHandler.parse(urnComponents, options);
3326
3283
  }
3327
3284
  } else {
3328
- urnComponent.error = urnComponent.error || "URN can not be parsed.";
3285
+ urnComponents.error = urnComponents.error || "URN can not be parsed.";
3329
3286
  }
3330
- return urnComponent;
3287
+ return urnComponents;
3331
3288
  }
3332
- function urnSerialize(urnComponent, options) {
3333
- if (urnComponent.nid === void 0) {
3334
- throw new Error("URN without nid cannot be serialized");
3335
- }
3336
- const scheme = options.scheme || urnComponent.scheme || "urn";
3337
- const nid = urnComponent.nid.toLowerCase();
3289
+ function urnSerialize(urnComponents, options) {
3290
+ const scheme = options.scheme || urnComponents.scheme || "urn";
3291
+ const nid = urnComponents.nid.toLowerCase();
3338
3292
  const urnScheme = `${scheme}:${options.nid || nid}`;
3339
- const schemeHandler = getSchemeHandler$1(urnScheme);
3293
+ const schemeHandler = SCHEMES$1[urnScheme];
3340
3294
  if (schemeHandler) {
3341
- urnComponent = schemeHandler.serialize(urnComponent, options);
3295
+ urnComponents = schemeHandler.serialize(urnComponents, options);
3342
3296
  }
3343
- const uriComponent = urnComponent;
3344
- const nss = urnComponent.nss;
3345
- uriComponent.path = `${nid || options.nid}:${nss}`;
3297
+ const uriComponents = urnComponents;
3298
+ const nss = urnComponents.nss;
3299
+ uriComponents.path = `${nid || options.nid}:${nss}`;
3346
3300
  options.skipEscape = true;
3347
- return uriComponent;
3348
- }
3349
- function urnuuidParse(urnComponent, options) {
3350
- const uuidComponent = urnComponent;
3351
- uuidComponent.uuid = uuidComponent.nss;
3352
- uuidComponent.nss = void 0;
3353
- if (!options.tolerant && (!uuidComponent.uuid || !isUUID(uuidComponent.uuid))) {
3354
- uuidComponent.error = uuidComponent.error || "UUID is not valid.";
3355
- }
3356
- return uuidComponent;
3357
- }
3358
- function urnuuidSerialize(uuidComponent) {
3359
- const urnComponent = uuidComponent;
3360
- urnComponent.nss = (uuidComponent.uuid || "").toLowerCase();
3361
- return urnComponent;
3362
- }
3363
- const http = (
3364
- /** @type {SchemeHandler} */
3365
- {
3366
- scheme: "http",
3367
- domainHost: true,
3368
- parse: httpParse,
3369
- serialize: httpSerialize
3370
- }
3371
- );
3372
- const https = (
3373
- /** @type {SchemeHandler} */
3374
- {
3375
- scheme: "https",
3376
- domainHost: http.domainHost,
3377
- parse: httpParse,
3378
- serialize: httpSerialize
3379
- }
3380
- );
3381
- const ws = (
3382
- /** @type {SchemeHandler} */
3383
- {
3384
- scheme: "ws",
3385
- domainHost: true,
3386
- parse: wsParse,
3387
- serialize: wsSerialize
3388
- }
3389
- );
3390
- const wss = (
3391
- /** @type {SchemeHandler} */
3392
- {
3393
- scheme: "wss",
3394
- domainHost: ws.domainHost,
3395
- parse: ws.parse,
3396
- serialize: ws.serialize
3397
- }
3398
- );
3399
- const urn = (
3400
- /** @type {SchemeHandler} */
3401
- {
3402
- scheme: "urn",
3403
- parse: urnParse,
3404
- serialize: urnSerialize,
3405
- skipNormalize: true
3406
- }
3407
- );
3408
- const urnuuid = (
3409
- /** @type {SchemeHandler} */
3410
- {
3411
- scheme: "urn:uuid",
3412
- parse: urnuuidParse,
3413
- serialize: urnuuidSerialize,
3414
- skipNormalize: true
3415
- }
3416
- );
3417
- const SCHEMES$1 = (
3418
- /** @type {Record<SchemeName, SchemeHandler>} */
3419
- {
3420
- http,
3421
- https,
3422
- ws,
3423
- wss,
3424
- urn,
3425
- "urn:uuid": urnuuid
3426
- }
3427
- );
3428
- Object.setPrototypeOf(SCHEMES$1, null);
3429
- function getSchemeHandler$1(scheme) {
3430
- return scheme && (SCHEMES$1[
3431
- /** @type {SchemeName} */
3432
- scheme
3433
- ] || SCHEMES$1[
3434
- /** @type {SchemeName} */
3435
- scheme.toLowerCase()
3436
- ]) || void 0;
3437
- }
3438
- var schemes = {
3439
- SCHEMES: SCHEMES$1,
3440
- getSchemeHandler: getSchemeHandler$1
3301
+ return uriComponents;
3302
+ }
3303
+ function urnuuidParse(urnComponents, options) {
3304
+ const uuidComponents = urnComponents;
3305
+ uuidComponents.uuid = uuidComponents.nss;
3306
+ uuidComponents.nss = void 0;
3307
+ if (!options.tolerant && (!uuidComponents.uuid || !UUID_REG.test(uuidComponents.uuid))) {
3308
+ uuidComponents.error = uuidComponents.error || "UUID is not valid.";
3309
+ }
3310
+ return uuidComponents;
3311
+ }
3312
+ function urnuuidSerialize(uuidComponents) {
3313
+ const urnComponents = uuidComponents;
3314
+ urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
3315
+ return urnComponents;
3316
+ }
3317
+ const http = {
3318
+ scheme: "http",
3319
+ domainHost: true,
3320
+ parse: httpParse,
3321
+ serialize: httpSerialize
3322
+ };
3323
+ const https = {
3324
+ scheme: "https",
3325
+ domainHost: http.domainHost,
3326
+ parse: httpParse,
3327
+ serialize: httpSerialize
3328
+ };
3329
+ const ws = {
3330
+ scheme: "ws",
3331
+ domainHost: true,
3332
+ parse: wsParse,
3333
+ serialize: wsSerialize
3334
+ };
3335
+ const wss = {
3336
+ scheme: "wss",
3337
+ domainHost: ws.domainHost,
3338
+ parse: ws.parse,
3339
+ serialize: ws.serialize
3441
3340
  };
3442
- const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = utils;
3443
- const { SCHEMES, getSchemeHandler } = schemes;
3341
+ const urn = {
3342
+ scheme: "urn",
3343
+ parse: urnParse,
3344
+ serialize: urnSerialize,
3345
+ skipNormalize: true
3346
+ };
3347
+ const urnuuid = {
3348
+ scheme: "urn:uuid",
3349
+ parse: urnuuidParse,
3350
+ serialize: urnuuidSerialize,
3351
+ skipNormalize: true
3352
+ };
3353
+ const SCHEMES$1 = {
3354
+ http,
3355
+ https,
3356
+ ws,
3357
+ wss,
3358
+ urn,
3359
+ "urn:uuid": urnuuid
3360
+ };
3361
+ var schemes = SCHEMES$1;
3362
+ const { normalizeIPv6, normalizeIPv4, removeDotSegments, recomposeAuthority, normalizeComponentEncoding } = utils;
3363
+ const SCHEMES = schemes;
3444
3364
  function normalize(uri2, options) {
3445
3365
  if (typeof uri2 === "string") {
3446
- uri2 = /** @type {T} */
3447
- serialize(parse(uri2, options), options);
3366
+ uri2 = serialize(parse(uri2, options), options);
3448
3367
  } else if (typeof uri2 === "object") {
3449
- uri2 = /** @type {T} */
3450
- parse(serialize(uri2, options), options);
3368
+ uri2 = parse(serialize(uri2, options), options);
3451
3369
  }
3452
3370
  return uri2;
3453
3371
  }
3454
3372
  function resolve$4(baseURI, relativeURI, options) {
3455
- const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
3456
- const resolved = resolveComponent(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true);
3457
- schemelessOptions.skipEscape = true;
3458
- return serialize(resolved, schemelessOptions);
3373
+ const schemelessOptions = Object.assign({ scheme: "null" }, options);
3374
+ const resolved = resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true);
3375
+ return serialize(resolved, { ...schemelessOptions, skipEscape: true });
3459
3376
  }
3460
- function resolveComponent(base, relative, options, skipNormalization) {
3377
+ function resolveComponents(base, relative, options, skipNormalization) {
3461
3378
  const target = {};
3462
3379
  if (!skipNormalization) {
3463
3380
  base = parse(serialize(base, options), options);
@@ -3487,7 +3404,7 @@
3487
3404
  target.query = base.query;
3488
3405
  }
3489
3406
  } else {
3490
- if (relative.path[0] === "/") {
3407
+ if (relative.path.charAt(0) === "/") {
3491
3408
  target.path = removeDotSegments(relative.path);
3492
3409
  } else {
3493
3410
  if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) {
@@ -3526,7 +3443,7 @@
3526
3443
  return uriA.toLowerCase() === uriB.toLowerCase();
3527
3444
  }
3528
3445
  function serialize(cmpts, opts) {
3529
- const component = {
3446
+ const components = {
3530
3447
  host: cmpts.host,
3531
3448
  scheme: cmpts.scheme,
3532
3449
  userinfo: cmpts.userinfo,
@@ -3544,49 +3461,60 @@
3544
3461
  };
3545
3462
  const options = Object.assign({}, opts);
3546
3463
  const uriTokens = [];
3547
- const schemeHandler = getSchemeHandler(options.scheme || component.scheme);
3548
- if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options);
3549
- if (component.path !== void 0) {
3464
+ const schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
3465
+ if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options);
3466
+ if (components.path !== void 0) {
3550
3467
  if (!options.skipEscape) {
3551
- component.path = escape(component.path);
3552
- if (component.scheme !== void 0) {
3553
- component.path = component.path.split("%3A").join(":");
3468
+ components.path = escape(components.path);
3469
+ if (components.scheme !== void 0) {
3470
+ components.path = components.path.split("%3A").join(":");
3554
3471
  }
3555
3472
  } else {
3556
- component.path = unescape(component.path);
3473
+ components.path = unescape(components.path);
3557
3474
  }
3558
3475
  }
3559
- if (options.reference !== "suffix" && component.scheme) {
3560
- uriTokens.push(component.scheme, ":");
3476
+ if (options.reference !== "suffix" && components.scheme) {
3477
+ uriTokens.push(components.scheme, ":");
3561
3478
  }
3562
- const authority = recomposeAuthority(component);
3479
+ const authority = recomposeAuthority(components);
3563
3480
  if (authority !== void 0) {
3564
3481
  if (options.reference !== "suffix") {
3565
3482
  uriTokens.push("//");
3566
3483
  }
3567
3484
  uriTokens.push(authority);
3568
- if (component.path && component.path[0] !== "/") {
3485
+ if (components.path && components.path.charAt(0) !== "/") {
3569
3486
  uriTokens.push("/");
3570
3487
  }
3571
3488
  }
3572
- if (component.path !== void 0) {
3573
- let s = component.path;
3489
+ if (components.path !== void 0) {
3490
+ let s = components.path;
3574
3491
  if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
3575
3492
  s = removeDotSegments(s);
3576
3493
  }
3577
- if (authority === void 0 && s[0] === "/" && s[1] === "/") {
3578
- s = "/%2F" + s.slice(2);
3494
+ if (authority === void 0) {
3495
+ s = s.replace(/^\/\//u, "/%2F");
3579
3496
  }
3580
3497
  uriTokens.push(s);
3581
3498
  }
3582
- if (component.query !== void 0) {
3583
- uriTokens.push("?", component.query);
3499
+ if (components.query !== void 0) {
3500
+ uriTokens.push("?", components.query);
3584
3501
  }
3585
- if (component.fragment !== void 0) {
3586
- uriTokens.push("#", component.fragment);
3502
+ if (components.fragment !== void 0) {
3503
+ uriTokens.push("#", components.fragment);
3587
3504
  }
3588
3505
  return uriTokens.join("");
3589
3506
  }
3507
+ const hexLookUp = Array.from({ length: 127 }, (_v, k) => /[^!"$&'()*+,\-.;=_`a-z{}~]/u.test(String.fromCharCode(k)));
3508
+ function nonSimpleDomain(value) {
3509
+ let code2 = 0;
3510
+ for (let i = 0, len = value.length; i < len; ++i) {
3511
+ code2 = value.charCodeAt(i);
3512
+ if (code2 > 126 || hexLookUp[code2]) {
3513
+ return true;
3514
+ }
3515
+ }
3516
+ return false;
3517
+ }
3590
3518
  const URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;
3591
3519
  function parse(uri2, opts) {
3592
3520
  const options = Object.assign({}, opts);
@@ -3599,14 +3527,9 @@
3599
3527
  query: void 0,
3600
3528
  fragment: void 0
3601
3529
  };
3530
+ const gotEncoding = uri2.indexOf("%") !== -1;
3602
3531
  let isIP = false;
3603
- if (options.reference === "suffix") {
3604
- if (options.scheme) {
3605
- uri2 = options.scheme + ":" + uri2;
3606
- } else {
3607
- uri2 = "//" + uri2;
3608
- }
3609
- }
3532
+ if (options.reference === "suffix") uri2 = (options.scheme ? options.scheme + ":" : "") + "//" + uri2;
3610
3533
  const matches = uri2.match(URI_PARSE);
3611
3534
  if (matches) {
3612
3535
  parsed.scheme = matches[1];
@@ -3620,12 +3543,13 @@
3620
3543
  parsed.port = matches[5];
3621
3544
  }
3622
3545
  if (parsed.host) {
3623
- const ipv4result = isIPv4(parsed.host);
3624
- if (ipv4result === false) {
3625
- const ipv6result = normalizeIPv6(parsed.host);
3546
+ const ipv4result = normalizeIPv4(parsed.host);
3547
+ if (ipv4result.isIPV4 === false) {
3548
+ const ipv6result = normalizeIPv6(ipv4result.host);
3626
3549
  parsed.host = ipv6result.host.toLowerCase();
3627
3550
  isIP = ipv6result.isIPV6;
3628
3551
  } else {
3552
+ parsed.host = ipv4result.host;
3629
3553
  isIP = true;
3630
3554
  }
3631
3555
  }
@@ -3641,7 +3565,7 @@
3641
3565
  if (options.reference && options.reference !== "suffix" && options.reference !== parsed.reference) {
3642
3566
  parsed.error = parsed.error || "URI is not a " + options.reference + " reference.";
3643
3567
  }
3644
- const schemeHandler = getSchemeHandler(options.scheme || parsed.scheme);
3568
+ const schemeHandler = SCHEMES[(options.scheme || parsed.scheme || "").toLowerCase()];
3645
3569
  if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
3646
3570
  if (parsed.host && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP === false && nonSimpleDomain(parsed.host)) {
3647
3571
  try {
@@ -3652,13 +3576,11 @@
3652
3576
  }
3653
3577
  }
3654
3578
  if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
3655
- if (uri2.indexOf("%") !== -1) {
3656
- if (parsed.scheme !== void 0) {
3657
- parsed.scheme = unescape(parsed.scheme);
3658
- }
3659
- if (parsed.host !== void 0) {
3660
- parsed.host = unescape(parsed.host);
3661
- }
3579
+ if (gotEncoding && parsed.scheme !== void 0) {
3580
+ parsed.scheme = unescape(parsed.scheme);
3581
+ }
3582
+ if (gotEncoding && parsed.host !== void 0) {
3583
+ parsed.host = unescape(parsed.host);
3662
3584
  }
3663
3585
  if (parsed.path) {
3664
3586
  parsed.path = escape(unescape(parsed.path));
@@ -3679,7 +3601,7 @@
3679
3601
  SCHEMES,
3680
3602
  normalize,
3681
3603
  resolve: resolve$4,
3682
- resolveComponent,
3604
+ resolveComponents,
3683
3605
  equal: equal$4,
3684
3606
  serialize,
3685
3607
  parse
@@ -3695,7 +3617,7 @@
3695
3617
  (function(exports3) {
3696
3618
  Object.defineProperty(exports3, "__esModule", { value: true });
3697
3619
  exports3.CodeGen = exports3.Name = exports3.nil = exports3.stringify = exports3.str = exports3._ = exports3.KeywordCxt = void 0;
3698
- var validate_12 = requireValidate();
3620
+ var validate_12 = validate$2;
3699
3621
  Object.defineProperty(exports3, "KeywordCxt", { enumerable: true, get: function() {
3700
3622
  return validate_12.KeywordCxt;
3701
3623
  } });
@@ -3718,7 +3640,7 @@
3718
3640
  Object.defineProperty(exports3, "CodeGen", { enumerable: true, get: function() {
3719
3641
  return codegen_12.CodeGen;
3720
3642
  } });
3721
- const validation_error_12 = requireValidation_error();
3643
+ const validation_error_12 = validation_error;
3722
3644
  const ref_error_12 = ref_error;
3723
3645
  const rules_12 = rules$2;
3724
3646
  const compile_12 = compile$2;
@@ -5297,7 +5219,7 @@
5297
5219
  additionalProperties$1.default = def$a;
5298
5220
  var properties$4 = {};
5299
5221
  Object.defineProperty(properties$4, "__esModule", { value: true });
5300
- const validate_1 = requireValidate();
5222
+ const validate_1 = validate$2;
5301
5223
  const code_1$2 = code;
5302
5224
  const util_1$7 = util$7;
5303
5225
  const additionalProperties_1$1 = additionalProperties$1;
@@ -6148,7 +6070,7 @@
6148
6070
  module2.exports.Ajv = Ajv2;
6149
6071
  Object.defineProperty(exports3, "__esModule", { value: true });
6150
6072
  exports3.default = Ajv2;
6151
- var validate_12 = requireValidate();
6073
+ var validate_12 = validate$2;
6152
6074
  Object.defineProperty(exports3, "KeywordCxt", { enumerable: true, get: function() {
6153
6075
  return validate_12.KeywordCxt;
6154
6076
  } });
@@ -6171,7 +6093,7 @@
6171
6093
  Object.defineProperty(exports3, "CodeGen", { enumerable: true, get: function() {
6172
6094
  return codegen_12.CodeGen;
6173
6095
  } });
6174
- var validation_error_12 = requireValidation_error();
6096
+ var validation_error_12 = validation_error;
6175
6097
  Object.defineProperty(exports3, "ValidationError", { enumerable: true, get: function() {
6176
6098
  return validation_error_12.default;
6177
6099
  } });
@@ -9921,10 +9843,14 @@
9921
9843
  ZodPromise.create;
9922
9844
  const optionalType = ZodOptional.create;
9923
9845
  ZodNullable.create;
9924
- const NEVER = INVALID;
9925
9846
  const LATEST_PROTOCOL_VERSION = "2025-06-18";
9926
9847
  const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26";
9927
- const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-03-26", "2024-11-05", "2024-10-07"];
9848
+ const SUPPORTED_PROTOCOL_VERSIONS = [
9849
+ LATEST_PROTOCOL_VERSION,
9850
+ "2025-03-26",
9851
+ "2024-11-05",
9852
+ "2024-10-07"
9853
+ ];
9928
9854
  const JSONRPC_VERSION = "2.0";
9929
9855
  const ProgressTokenSchema = unionType([stringType(), numberType().int()]);
9930
9856
  const CursorSchema = stringType();
@@ -10004,7 +9930,12 @@
10004
9930
  })
10005
9931
  }).strict();
10006
9932
  const isJSONRPCError = (value) => JSONRPCErrorSchema.safeParse(value).success;
10007
- const JSONRPCMessageSchema = unionType([JSONRPCRequestSchema, JSONRPCNotificationSchema, JSONRPCResponseSchema, JSONRPCErrorSchema]);
9933
+ const JSONRPCMessageSchema = unionType([
9934
+ JSONRPCRequestSchema,
9935
+ JSONRPCNotificationSchema,
9936
+ JSONRPCResponseSchema,
9937
+ JSONRPCErrorSchema
9938
+ ]);
10008
9939
  const EmptyResultSchema = ResultSchema.strict();
10009
9940
  const CancelledNotificationSchema = NotificationSchema.extend({
10010
9941
  method: literalType("notifications/cancelled"),
@@ -10021,57 +9952,22 @@
10021
9952
  reason: stringType().optional()
10022
9953
  })
10023
9954
  });
10024
- const IconSchema = objectType({
10025
- /**
10026
- * URL or data URI for the icon.
10027
- */
10028
- src: stringType(),
10029
- /**
10030
- * Optional MIME type for the icon.
10031
- */
10032
- mimeType: optionalType(stringType()),
10033
- /**
10034
- * Optional array of strings that specify sizes at which the icon can be used.
10035
- * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
10036
- *
10037
- * If not provided, the client should assume that the icon can be used at any size.
10038
- */
10039
- sizes: optionalType(arrayType(stringType()))
10040
- }).passthrough();
10041
- const IconsSchema = objectType({
10042
- /**
10043
- * Optional set of sized icons that the client can display in a user interface.
10044
- *
10045
- * Clients that support rendering icons MUST support at least the following MIME types:
10046
- * - `image/png` - PNG images (safe, universal compatibility)
10047
- * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
10048
- *
10049
- * Clients that support rendering icons SHOULD also support:
10050
- * - `image/svg+xml` - SVG images (scalable but requires security precautions)
10051
- * - `image/webp` - WebP images (modern, efficient format)
10052
- */
10053
- icons: arrayType(IconSchema).optional()
10054
- }).passthrough();
10055
9955
  const BaseMetadataSchema = objectType({
10056
9956
  /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
10057
9957
  name: stringType(),
10058
9958
  /**
10059
- * Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
10060
- * even by those unfamiliar with domain-specific terminology.
10061
- *
10062
- * If not provided, the name should be used for display (except for Tool,
10063
- * where `annotations.title` should be given precedence over using `name`,
10064
- * if present).
10065
- */
9959
+ * Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
9960
+ * even by those unfamiliar with domain-specific terminology.
9961
+ *
9962
+ * If not provided, the name should be used for display (except for Tool,
9963
+ * where `annotations.title` should be given precedence over using `name`,
9964
+ * if present).
9965
+ */
10066
9966
  title: optionalType(stringType())
10067
9967
  }).passthrough();
10068
9968
  const ImplementationSchema = BaseMetadataSchema.extend({
10069
- version: stringType(),
10070
- /**
10071
- * An optional URL of the website for this implementation.
10072
- */
10073
- websiteUrl: optionalType(stringType())
10074
- }).merge(IconsSchema);
9969
+ version: stringType()
9970
+ });
10075
9971
  const ClientCapabilitiesSchema = objectType({
10076
9972
  /**
10077
9973
  * Experimental, non-standard capabilities that the client supports.
@@ -10267,7 +10163,7 @@
10267
10163
  * for notes on _meta usage.
10268
10164
  */
10269
10165
  _meta: optionalType(objectType({}).passthrough())
10270
- }).merge(IconsSchema);
10166
+ });
10271
10167
  const ResourceTemplateSchema = BaseMetadataSchema.extend({
10272
10168
  /**
10273
10169
  * A URI template (according to RFC 6570) that can be used to construct resource URIs.
@@ -10288,7 +10184,7 @@
10288
10184
  * for notes on _meta usage.
10289
10185
  */
10290
10186
  _meta: optionalType(objectType({}).passthrough())
10291
- }).merge(IconsSchema);
10187
+ });
10292
10188
  const ListResourcesRequestSchema = PaginatedRequestSchema.extend({
10293
10189
  method: literalType("resources/list")
10294
10190
  });
@@ -10371,7 +10267,7 @@
10371
10267
  * for notes on _meta usage.
10372
10268
  */
10373
10269
  _meta: optionalType(objectType({}).passthrough())
10374
- }).merge(IconsSchema);
10270
+ });
10375
10271
  const ListPromptsRequestSchema = PaginatedRequestSchema.extend({
10376
10272
  method: literalType("prompts/list")
10377
10273
  });
@@ -10538,7 +10434,7 @@
10538
10434
  * for notes on _meta usage.
10539
10435
  */
10540
10436
  _meta: optionalType(objectType({}).passthrough())
10541
- }).merge(IconsSchema);
10437
+ });
10542
10438
  const ListToolsRequestSchema = PaginatedRequestSchema.extend({
10543
10439
  method: literalType("tools/list")
10544
10440
  });
@@ -10588,7 +10484,16 @@
10588
10484
  const ToolListChangedNotificationSchema = NotificationSchema.extend({
10589
10485
  method: literalType("notifications/tools/list_changed")
10590
10486
  });
10591
- const LoggingLevelSchema = enumType(["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]);
10487
+ const LoggingLevelSchema = enumType([
10488
+ "debug",
10489
+ "info",
10490
+ "notice",
10491
+ "warning",
10492
+ "error",
10493
+ "critical",
10494
+ "alert",
10495
+ "emergency"
10496
+ ]);
10592
10497
  const SetLevelRequestSchema = RequestSchema.extend({
10593
10498
  method: literalType("logging/setLevel"),
10594
10499
  params: BaseRequestParamsSchema.extend({
@@ -10681,7 +10586,11 @@
10681
10586
  */
10682
10587
  stopReason: optionalType(enumType(["endTurn", "stopSequence", "maxTokens"]).or(stringType())),
10683
10588
  role: enumType(["user", "assistant"]),
10684
- content: discriminatedUnionType("type", [TextContentSchema, ImageContentSchema, AudioContentSchema])
10589
+ content: discriminatedUnionType("type", [
10590
+ TextContentSchema,
10591
+ ImageContentSchema,
10592
+ AudioContentSchema
10593
+ ])
10685
10594
  });
10686
10595
  const BooleanSchemaSchema = objectType({
10687
10596
  type: literalType("boolean"),
@@ -10711,7 +10620,12 @@
10711
10620
  enum: arrayType(stringType()),
10712
10621
  enumNames: optionalType(arrayType(stringType()))
10713
10622
  }).passthrough();
10714
- const PrimitiveSchemaDefinitionSchema = unionType([BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema, EnumSchemaSchema]);
10623
+ const PrimitiveSchemaDefinitionSchema = unionType([
10624
+ BooleanSchemaSchema,
10625
+ StringSchemaSchema,
10626
+ NumberSchemaSchema,
10627
+ EnumSchemaSchema
10628
+ ]);
10715
10629
  const ElicitRequestSchema = RequestSchema.extend({
10716
10630
  method: literalType("elicitation/create"),
10717
10631
  params: BaseRequestParamsSchema.extend({
@@ -10840,8 +10754,18 @@
10840
10754
  InitializedNotificationSchema,
10841
10755
  RootsListChangedNotificationSchema
10842
10756
  ]);
10843
- const ClientResultSchema = unionType([EmptyResultSchema, CreateMessageResultSchema, ElicitResultSchema, ListRootsResultSchema]);
10844
- const ServerRequestSchema = unionType([PingRequestSchema, CreateMessageRequestSchema, ElicitRequestSchema, ListRootsRequestSchema]);
10757
+ const ClientResultSchema = unionType([
10758
+ EmptyResultSchema,
10759
+ CreateMessageResultSchema,
10760
+ ElicitResultSchema,
10761
+ ListRootsResultSchema
10762
+ ]);
10763
+ const ServerRequestSchema = unionType([
10764
+ PingRequestSchema,
10765
+ CreateMessageRequestSchema,
10766
+ ElicitRequestSchema,
10767
+ ListRootsRequestSchema
10768
+ ]);
10845
10769
  const ServerNotificationSchema = unionType([
10846
10770
  CancelledNotificationSchema,
10847
10771
  ProgressNotificationSchema,
@@ -11199,10 +11123,7 @@
11199
11123
  const totalElapsed = Date.now() - info.startTime;
11200
11124
  if (info.maxTotalTimeout && totalElapsed >= info.maxTotalTimeout) {
11201
11125
  this._timeoutInfo.delete(messageId);
11202
- throw new McpError(exports2.ErrorCode.RequestTimeout, "Maximum total timeout exceeded", {
11203
- maxTotalTimeout: info.maxTotalTimeout,
11204
- totalElapsed
11205
- });
11126
+ throw new McpError(exports2.ErrorCode.RequestTimeout, "Maximum total timeout exceeded", { maxTotalTimeout: info.maxTotalTimeout, totalElapsed });
11206
11127
  }
11207
11128
  clearTimeout(info.timeoutId);
11208
11129
  info.timeoutId = setTimeout(info.onTimeout, info.timeout);
@@ -11274,11 +11195,10 @@
11274
11195
  Promise.resolve().then(() => handler(notification)).catch((error2) => this._onerror(new Error(`Uncaught error in notification handler: ${error2}`)));
11275
11196
  }
11276
11197
  _onrequest(request, extra) {
11277
- var _a, _b;
11198
+ var _a, _b, _c, _d;
11278
11199
  const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== void 0 ? _a : this.fallbackRequestHandler;
11279
- const capturedTransport = this._transport;
11280
11200
  if (handler === void 0) {
11281
- capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
11201
+ (_b = this._transport) === null || _b === void 0 ? void 0 : _b.send({
11282
11202
  jsonrpc: "2.0",
11283
11203
  id: request.id,
11284
11204
  error: {
@@ -11292,8 +11212,8 @@
11292
11212
  this._requestHandlerAbortControllers.set(request.id, abortController);
11293
11213
  const fullExtra = {
11294
11214
  signal: abortController.signal,
11295
- sessionId: capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId,
11296
- _meta: (_b = request.params) === null || _b === void 0 ? void 0 : _b._meta,
11215
+ sessionId: (_c = this._transport) === null || _c === void 0 ? void 0 : _c.sessionId,
11216
+ _meta: (_d = request.params) === null || _d === void 0 ? void 0 : _d._meta,
11297
11217
  sendNotification: (notification) => this.notification(notification, { relatedRequestId: request.id }),
11298
11218
  sendRequest: (r, resultSchema, options) => this.request(r, resultSchema, { ...options, relatedRequestId: request.id }),
11299
11219
  authInfo: extra === null || extra === void 0 ? void 0 : extra.authInfo,
@@ -11301,25 +11221,26 @@
11301
11221
  requestInfo: extra === null || extra === void 0 ? void 0 : extra.requestInfo
11302
11222
  };
11303
11223
  Promise.resolve().then(() => handler(request, fullExtra)).then((result) => {
11224
+ var _a2;
11304
11225
  if (abortController.signal.aborted) {
11305
11226
  return;
11306
11227
  }
11307
- return capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
11228
+ return (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
11308
11229
  result,
11309
11230
  jsonrpc: "2.0",
11310
11231
  id: request.id
11311
11232
  });
11312
11233
  }, (error2) => {
11313
- var _a2;
11234
+ var _a2, _b2;
11314
11235
  if (abortController.signal.aborted) {
11315
11236
  return;
11316
11237
  }
11317
- return capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
11238
+ return (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
11318
11239
  jsonrpc: "2.0",
11319
11240
  id: request.id,
11320
11241
  error: {
11321
11242
  code: Number.isSafeInteger(error2["code"]) ? error2["code"] : exports2.ErrorCode.InternalError,
11322
- message: (_a2 = error2.message) !== null && _a2 !== void 0 ? _a2 : "Internal error"
11243
+ message: (_b2 = error2.message) !== null && _b2 !== void 0 ? _b2 : "Internal error"
11323
11244
  }
11324
11245
  });
11325
11246
  }).catch((error2) => this._onerror(new Error(`Failed to send response: ${error2}`))).finally(() => {
@@ -12150,24 +12071,24 @@
12150
12071
  }
12151
12072
  return uriTokens.length ? uriTokens.join("") : void 0;
12152
12073
  }
12153
- var RDS1 = /^\.\.?\//;
12154
- var RDS2 = /^\/\.(\/|$)/;
12155
- var RDS3 = /^\/\.\.(\/|$)/;
12156
- var RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/;
12074
+ var RDS12 = /^\.\.?\//;
12075
+ var RDS22 = /^\/\.(\/|$)/;
12076
+ var RDS32 = /^\/\.\.(\/|$)/;
12077
+ var RDS52 = /^\/?(?:.|\n)*?(?=\/|$)/;
12157
12078
  function removeDotSegments2(input) {
12158
12079
  var output = [];
12159
12080
  while (input.length) {
12160
- if (input.match(RDS1)) {
12161
- input = input.replace(RDS1, "");
12162
- } else if (input.match(RDS2)) {
12163
- input = input.replace(RDS2, "/");
12164
- } else if (input.match(RDS3)) {
12165
- input = input.replace(RDS3, "/");
12081
+ if (input.match(RDS12)) {
12082
+ input = input.replace(RDS12, "");
12083
+ } else if (input.match(RDS22)) {
12084
+ input = input.replace(RDS22, "/");
12085
+ } else if (input.match(RDS32)) {
12086
+ input = input.replace(RDS32, "/");
12166
12087
  output.pop();
12167
12088
  } else if (input === "." || input === "..") {
12168
12089
  input = "";
12169
12090
  } else {
12170
- var im = input.match(RDS5);
12091
+ var im = input.match(RDS52);
12171
12092
  if (im) {
12172
12093
  var s = im[0];
12173
12094
  input = input.slice(s.length);
@@ -12230,7 +12151,7 @@
12230
12151
  }
12231
12152
  return uriTokens.join("");
12232
12153
  }
12233
- function resolveComponents(base2, relative) {
12154
+ function resolveComponents2(base2, relative) {
12234
12155
  var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
12235
12156
  var skipNormalization = arguments[3];
12236
12157
  var target = {};
@@ -12287,7 +12208,7 @@
12287
12208
  }
12288
12209
  function resolve2(baseURI, relativeURI, options) {
12289
12210
  var schemelessOptions = assign({ scheme: "null" }, options);
12290
- return serialize2(resolveComponents(parse2(baseURI, schemelessOptions), parse2(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
12211
+ return serialize2(resolveComponents2(parse2(baseURI, schemelessOptions), parse2(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
12291
12212
  }
12292
12213
  function normalize2(uri2, options) {
12293
12214
  if (typeof uri2 === "string") {
@@ -12342,7 +12263,7 @@
12342
12263
  parse: handler.parse,
12343
12264
  serialize: handler.serialize
12344
12265
  };
12345
- function isSecure(wsComponents) {
12266
+ function isSecure2(wsComponents) {
12346
12267
  return typeof wsComponents.secure === "boolean" ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss";
12347
12268
  }
12348
12269
  var handler$2 = {
@@ -12350,14 +12271,14 @@
12350
12271
  domainHost: true,
12351
12272
  parse: function parse3(components, options) {
12352
12273
  var wsComponents = components;
12353
- wsComponents.secure = isSecure(wsComponents);
12274
+ wsComponents.secure = isSecure2(wsComponents);
12354
12275
  wsComponents.resourceName = (wsComponents.path || "/") + (wsComponents.query ? "?" + wsComponents.query : "");
12355
12276
  wsComponents.path = void 0;
12356
12277
  wsComponents.query = void 0;
12357
12278
  return wsComponents;
12358
12279
  },
12359
12280
  serialize: function serialize3(wsComponents, options) {
12360
- if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") {
12281
+ if (wsComponents.port === (isSecure2(wsComponents) ? 443 : 80) || wsComponents.port === "") {
12361
12282
  wsComponents.port = void 0;
12362
12283
  }
12363
12284
  if (typeof wsComponents.secure === "boolean") {
@@ -12548,7 +12469,7 @@
12548
12469
  exports4.parse = parse2;
12549
12470
  exports4.removeDotSegments = removeDotSegments2;
12550
12471
  exports4.serialize = serialize2;
12551
- exports4.resolveComponents = resolveComponents;
12472
+ exports4.resolveComponents = resolveComponents2;
12552
12473
  exports4.resolve = resolve2;
12553
12474
  exports4.normalize = normalize2;
12554
12475
  exports4.equal = equal2;
@@ -17749,22 +17670,9 @@
17749
17670
  code_challenge: challenge
17750
17671
  };
17751
17672
  }
17752
- const SafeUrlSchema = stringType().url().superRefine((val, ctx) => {
17753
- if (!URL.canParse(val)) {
17754
- ctx.addIssue({
17755
- code: ZodIssueCode.custom,
17756
- message: "URL must be parseable",
17757
- fatal: true
17758
- });
17759
- return NEVER;
17760
- }
17761
- }).refine((url) => {
17762
- const u = new URL(url);
17763
- return u.protocol !== "javascript:" && u.protocol !== "data:" && u.protocol !== "vbscript:";
17764
- }, { message: "URL cannot use javascript:, data:, or vbscript: scheme" });
17765
17673
  const OAuthProtectedResourceMetadataSchema = objectType({
17766
17674
  resource: stringType().url(),
17767
- authorization_servers: arrayType(SafeUrlSchema).optional(),
17675
+ authorization_servers: arrayType(stringType().url()).optional(),
17768
17676
  jwks_uri: stringType().url().optional(),
17769
17677
  scopes_supported: arrayType(stringType()).optional(),
17770
17678
  bearer_methods_supported: arrayType(stringType()).optional(),
@@ -17780,17 +17688,17 @@
17780
17688
  }).passthrough();
17781
17689
  const OAuthMetadataSchema = objectType({
17782
17690
  issuer: stringType(),
17783
- authorization_endpoint: SafeUrlSchema,
17784
- token_endpoint: SafeUrlSchema,
17785
- registration_endpoint: SafeUrlSchema.optional(),
17691
+ authorization_endpoint: stringType(),
17692
+ token_endpoint: stringType(),
17693
+ registration_endpoint: stringType().optional(),
17786
17694
  scopes_supported: arrayType(stringType()).optional(),
17787
17695
  response_types_supported: arrayType(stringType()),
17788
17696
  response_modes_supported: arrayType(stringType()).optional(),
17789
17697
  grant_types_supported: arrayType(stringType()).optional(),
17790
17698
  token_endpoint_auth_methods_supported: arrayType(stringType()).optional(),
17791
17699
  token_endpoint_auth_signing_alg_values_supported: arrayType(stringType()).optional(),
17792
- service_documentation: SafeUrlSchema.optional(),
17793
- revocation_endpoint: SafeUrlSchema.optional(),
17700
+ service_documentation: stringType().optional(),
17701
+ revocation_endpoint: stringType().optional(),
17794
17702
  revocation_endpoint_auth_methods_supported: arrayType(stringType()).optional(),
17795
17703
  revocation_endpoint_auth_signing_alg_values_supported: arrayType(stringType()).optional(),
17796
17704
  introspection_endpoint: stringType().optional(),
@@ -17800,11 +17708,11 @@
17800
17708
  }).passthrough();
17801
17709
  const OpenIdProviderMetadataSchema = objectType({
17802
17710
  issuer: stringType(),
17803
- authorization_endpoint: SafeUrlSchema,
17804
- token_endpoint: SafeUrlSchema,
17805
- userinfo_endpoint: SafeUrlSchema.optional(),
17806
- jwks_uri: SafeUrlSchema,
17807
- registration_endpoint: SafeUrlSchema.optional(),
17711
+ authorization_endpoint: stringType(),
17712
+ token_endpoint: stringType(),
17713
+ userinfo_endpoint: stringType().optional(),
17714
+ jwks_uri: stringType(),
17715
+ registration_endpoint: stringType().optional(),
17808
17716
  scopes_supported: arrayType(stringType()).optional(),
17809
17717
  response_types_supported: arrayType(stringType()),
17810
17718
  response_modes_supported: arrayType(stringType()).optional(),
@@ -17832,8 +17740,8 @@
17832
17740
  request_parameter_supported: booleanType().optional(),
17833
17741
  request_uri_parameter_supported: booleanType().optional(),
17834
17742
  require_request_uri_registration: booleanType().optional(),
17835
- op_policy_uri: SafeUrlSchema.optional(),
17836
- op_tos_uri: SafeUrlSchema.optional()
17743
+ op_policy_uri: stringType().optional(),
17744
+ op_tos_uri: stringType().optional()
17837
17745
  }).passthrough();
17838
17746
  const OpenIdProviderDiscoveryMetadataSchema = OpenIdProviderMetadataSchema.merge(OAuthMetadataSchema.pick({
17839
17747
  code_challenge_methods_supported: true
@@ -17852,20 +17760,19 @@
17852
17760
  error_description: stringType().optional(),
17853
17761
  error_uri: stringType().optional()
17854
17762
  });
17855
- const OptionalSafeUrlSchema = SafeUrlSchema.optional().or(literalType("").transform(() => void 0));
17856
17763
  const OAuthClientMetadataSchema = objectType({
17857
- redirect_uris: arrayType(SafeUrlSchema),
17764
+ redirect_uris: arrayType(stringType()).refine((uris) => uris.every((uri2) => URL.canParse(uri2)), { message: "redirect_uris must contain valid URLs" }),
17858
17765
  token_endpoint_auth_method: stringType().optional(),
17859
17766
  grant_types: arrayType(stringType()).optional(),
17860
17767
  response_types: arrayType(stringType()).optional(),
17861
17768
  client_name: stringType().optional(),
17862
- client_uri: SafeUrlSchema.optional(),
17863
- logo_uri: OptionalSafeUrlSchema,
17769
+ client_uri: stringType().optional(),
17770
+ logo_uri: stringType().optional(),
17864
17771
  scope: stringType().optional(),
17865
17772
  contacts: arrayType(stringType()).optional(),
17866
- tos_uri: OptionalSafeUrlSchema,
17773
+ tos_uri: stringType().optional(),
17867
17774
  policy_uri: stringType().optional(),
17868
- jwks_uri: SafeUrlSchema.optional(),
17775
+ jwks_uri: stringType().optional(),
17869
17776
  jwks: anyType().optional(),
17870
17777
  software_id: stringType().optional(),
17871
17778
  software_version: stringType().optional(),
@@ -17998,8 +17905,6 @@
17998
17905
  super(message !== null && message !== void 0 ? message : "Unauthorized");
17999
17906
  }
18000
17907
  }
18001
- const AUTHORIZATION_CODE_RESPONSE_TYPE = "code";
18002
- const AUTHORIZATION_CODE_CHALLENGE_METHOD = "S256";
18003
17908
  function selectClientAuthMethod(clientInformation, supportedMethods) {
18004
17909
  const hasClientSecret = clientInformation.client_secret !== void 0;
18005
17910
  if (supportedMethods.length === 0) {
@@ -18103,8 +18008,7 @@
18103
18008
  }
18104
18009
  const fullInformation = await registerClient(authorizationServerUrl, {
18105
18010
  metadata: metadata2,
18106
- clientMetadata: provider.clientMetadata,
18107
- fetchFn
18011
+ clientMetadata: provider.clientMetadata
18108
18012
  });
18109
18013
  await provider.saveClientInformation(fullInformation);
18110
18014
  clientInformation = fullInformation;
@@ -18132,8 +18036,7 @@
18132
18036
  clientInformation,
18133
18037
  refreshToken: tokens.refresh_token,
18134
18038
  resource,
18135
- addClientAuthentication: provider.addClientAuthentication,
18136
- fetchFn
18039
+ addClientAuthentication: provider.addClientAuthentication
18137
18040
  });
18138
18041
  await provider.saveTokens(newTokens);
18139
18042
  return "AUTHORIZED";
@@ -18230,7 +18133,7 @@
18230
18133
  return await fetchWithCorsRetry(url, headers, fetchFn);
18231
18134
  }
18232
18135
  function shouldAttemptFallback(response, pathname) {
18233
- return !response || response.status >= 400 && response.status < 500 && pathname !== "/";
18136
+ return !response || response.status === 404 && pathname !== "/";
18234
18137
  }
18235
18138
  async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) {
18236
18139
  var _a, _b;
@@ -18312,15 +18215,13 @@
18312
18215
  return urlsToTry;
18313
18216
  }
18314
18217
  async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn = fetch, protocolVersion = LATEST_PROTOCOL_VERSION } = {}) {
18315
- const headers = {
18316
- "MCP-Protocol-Version": protocolVersion,
18317
- Accept: "application/json"
18318
- };
18218
+ var _a;
18219
+ const headers = { "MCP-Protocol-Version": protocolVersion };
18319
18220
  const urlsToTry = buildDiscoveryUrls(authorizationServerUrl);
18320
18221
  for (const { url: endpointUrl, type: type2 } of urlsToTry) {
18321
18222
  const response = await fetchWithCorsRetry(endpointUrl, headers, fetchFn);
18322
18223
  if (!response) {
18323
- continue;
18224
+ throw new Error(`CORS error trying to load ${type2 === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${endpointUrl}`);
18324
18225
  }
18325
18226
  if (!response.ok) {
18326
18227
  if (response.status >= 400 && response.status < 500) {
@@ -18331,20 +18232,26 @@
18331
18232
  if (type2 === "oauth") {
18332
18233
  return OAuthMetadataSchema.parse(await response.json());
18333
18234
  } else {
18334
- return OpenIdProviderDiscoveryMetadataSchema.parse(await response.json());
18235
+ const metadata2 = OpenIdProviderDiscoveryMetadataSchema.parse(await response.json());
18236
+ if (!((_a = metadata2.code_challenge_methods_supported) === null || _a === void 0 ? void 0 : _a.includes("S256"))) {
18237
+ throw new Error(`Incompatible OIDC provider at ${endpointUrl}: does not support S256 code challenge method required by MCP specification`);
18238
+ }
18239
+ return metadata2;
18335
18240
  }
18336
18241
  }
18337
18242
  return void 0;
18338
18243
  }
18339
18244
  async function startAuthorization(authorizationServerUrl, { metadata: metadata2, clientInformation, redirectUrl, scope: scope2, state, resource }) {
18245
+ const responseType = "code";
18246
+ const codeChallengeMethod = "S256";
18340
18247
  let authorizationUrl;
18341
18248
  if (metadata2) {
18342
18249
  authorizationUrl = new URL(metadata2.authorization_endpoint);
18343
- if (!metadata2.response_types_supported.includes(AUTHORIZATION_CODE_RESPONSE_TYPE)) {
18344
- throw new Error(`Incompatible auth server: does not support response type ${AUTHORIZATION_CODE_RESPONSE_TYPE}`);
18250
+ if (!metadata2.response_types_supported.includes(responseType)) {
18251
+ throw new Error(`Incompatible auth server: does not support response type ${responseType}`);
18345
18252
  }
18346
- if (metadata2.code_challenge_methods_supported && !metadata2.code_challenge_methods_supported.includes(AUTHORIZATION_CODE_CHALLENGE_METHOD)) {
18347
- throw new Error(`Incompatible auth server: does not support code challenge method ${AUTHORIZATION_CODE_CHALLENGE_METHOD}`);
18253
+ if (!metadata2.code_challenge_methods_supported || !metadata2.code_challenge_methods_supported.includes(codeChallengeMethod)) {
18254
+ throw new Error(`Incompatible auth server: does not support code challenge method ${codeChallengeMethod}`);
18348
18255
  }
18349
18256
  } else {
18350
18257
  authorizationUrl = new URL("/authorize", authorizationServerUrl);
@@ -18352,10 +18259,10 @@
18352
18259
  const challenge = await pkceChallenge();
18353
18260
  const codeVerifier = challenge.code_verifier;
18354
18261
  const codeChallenge = challenge.code_challenge;
18355
- authorizationUrl.searchParams.set("response_type", AUTHORIZATION_CODE_RESPONSE_TYPE);
18262
+ authorizationUrl.searchParams.set("response_type", responseType);
18356
18263
  authorizationUrl.searchParams.set("client_id", clientInformation.client_id);
18357
18264
  authorizationUrl.searchParams.set("code_challenge", codeChallenge);
18358
- authorizationUrl.searchParams.set("code_challenge_method", AUTHORIZATION_CODE_CHALLENGE_METHOD);
18265
+ authorizationUrl.searchParams.set("code_challenge_method", codeChallengeMethod);
18359
18266
  authorizationUrl.searchParams.set("redirect_uri", String(redirectUrl));
18360
18267
  if (state) {
18361
18268
  authorizationUrl.searchParams.set("state", state);
@@ -18380,7 +18287,7 @@
18380
18287
  }
18381
18288
  const headers = new Headers({
18382
18289
  "Content-Type": "application/x-www-form-urlencoded",
18383
- Accept: "application/json"
18290
+ "Accept": "application/json"
18384
18291
  });
18385
18292
  const params = new URLSearchParams({
18386
18293
  grant_type: grantType,
@@ -18559,7 +18466,7 @@
18559
18466
  const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
18560
18467
  `, searchIndex);
18561
18468
  let lineEnd = -1;
18562
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
18469
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
18563
18470
  incompleteLine = chunk.slice(searchIndex);
18564
18471
  break;
18565
18472
  } else {
@@ -18860,11 +18767,7 @@
18860
18767
  }
18861
18768
  let result;
18862
18769
  try {
18863
- result = await auth(this._authProvider, {
18864
- serverUrl: this._url,
18865
- resourceMetadataUrl: this._resourceMetadataUrl,
18866
- fetchFn: this._fetch
18867
- });
18770
+ result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
18868
18771
  } catch (error2) {
18869
18772
  (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error2);
18870
18773
  throw error2;
@@ -18963,12 +18866,7 @@
18963
18866
  if (!this._authProvider) {
18964
18867
  throw new UnauthorizedError("No auth provider");
18965
18868
  }
18966
- const result = await auth(this._authProvider, {
18967
- serverUrl: this._url,
18968
- authorizationCode,
18969
- resourceMetadataUrl: this._resourceMetadataUrl,
18970
- fetchFn: this._fetch
18971
- });
18869
+ const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
18972
18870
  if (result !== "AUTHORIZED") {
18973
18871
  throw new UnauthorizedError("Failed to authorize");
18974
18872
  }
@@ -18998,11 +18896,7 @@
18998
18896
  if (!response.ok) {
18999
18897
  if (response.status === 401 && this._authProvider) {
19000
18898
  this._resourceMetadataUrl = extractResourceMetadataUrl(response);
19001
- const result = await auth(this._authProvider, {
19002
- serverUrl: this._url,
19003
- resourceMetadataUrl: this._resourceMetadataUrl,
19004
- fetchFn: this._fetch
19005
- });
18899
+ const result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
19006
18900
  if (result !== "AUTHORIZED") {
19007
18901
  throw new UnauthorizedError();
19008
18902
  }
@@ -19057,7 +18951,6 @@
19057
18951
  class StreamableHTTPClientTransport {
19058
18952
  constructor(url, opts) {
19059
18953
  var _a;
19060
- this._hasCompletedAuthFlow = false;
19061
18954
  this._url = url;
19062
18955
  this._resourceMetadataUrl = void 0;
19063
18956
  this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit;
@@ -19073,11 +18966,7 @@
19073
18966
  }
19074
18967
  let result;
19075
18968
  try {
19076
- result = await auth(this._authProvider, {
19077
- serverUrl: this._url,
19078
- resourceMetadataUrl: this._resourceMetadataUrl,
19079
- fetchFn: this._fetch
19080
- });
18969
+ result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
19081
18970
  } catch (error2) {
19082
18971
  (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error2);
19083
18972
  throw error2;
@@ -19243,12 +19132,7 @@
19243
19132
  if (!this._authProvider) {
19244
19133
  throw new UnauthorizedError("No auth provider");
19245
19134
  }
19246
- const result = await auth(this._authProvider, {
19247
- serverUrl: this._url,
19248
- authorizationCode,
19249
- resourceMetadataUrl: this._resourceMetadataUrl,
19250
- fetchFn: this._fetch
19251
- });
19135
+ const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
19252
19136
  if (result !== "AUTHORIZED") {
19253
19137
  throw new UnauthorizedError("Failed to authorize");
19254
19138
  }
@@ -19286,25 +19170,16 @@
19286
19170
  }
19287
19171
  if (!response.ok) {
19288
19172
  if (response.status === 401 && this._authProvider) {
19289
- if (this._hasCompletedAuthFlow) {
19290
- throw new StreamableHTTPError(401, "Server returned 401 after successful authentication");
19291
- }
19292
19173
  this._resourceMetadataUrl = extractResourceMetadataUrl(response);
19293
- const result = await auth(this._authProvider, {
19294
- serverUrl: this._url,
19295
- resourceMetadataUrl: this._resourceMetadataUrl,
19296
- fetchFn: this._fetch
19297
- });
19174
+ const result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
19298
19175
  if (result !== "AUTHORIZED") {
19299
19176
  throw new UnauthorizedError();
19300
19177
  }
19301
- this._hasCompletedAuthFlow = true;
19302
19178
  return this.send(message);
19303
19179
  }
19304
19180
  const text = await response.text().catch(() => null);
19305
19181
  throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
19306
19182
  }
19307
- this._hasCompletedAuthFlow = false;
19308
19183
  if (response.status === 202) {
19309
19184
  if (isInitializedNotification(message)) {
19310
19185
  this._startOrAuthSse({ resumptionToken: void 0 }).catch((err) => {
@@ -19387,12 +19262,6 @@
19387
19262
  var _a;
19388
19263
  super(options);
19389
19264
  this._serverInfo = _serverInfo;
19390
- this._loggingLevels = /* @__PURE__ */ new Map();
19391
- this.LOG_LEVEL_SEVERITY = new Map(LoggingLevelSchema.options.map((level, index) => [level, index]));
19392
- this.isMessageIgnored = (level, sessionId) => {
19393
- const currentLevel = this._loggingLevels.get(sessionId);
19394
- return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false;
19395
- };
19396
19265
  this._capabilities = (_a = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a !== void 0 ? _a : {};
19397
19266
  this._instructions = options === null || options === void 0 ? void 0 : options.instructions;
19398
19267
  this.setRequestHandler(InitializeRequestSchema, (request) => this._oninitialize(request));
@@ -19400,18 +19269,6 @@
19400
19269
  var _a2;
19401
19270
  return (_a2 = this.oninitialized) === null || _a2 === void 0 ? void 0 : _a2.call(this);
19402
19271
  });
19403
- if (this._capabilities.logging) {
19404
- this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => {
19405
- var _a2;
19406
- const transportSessionId = extra.sessionId || ((_a2 = extra.requestInfo) === null || _a2 === void 0 ? void 0 : _a2.headers["mcp-session-id"]) || void 0;
19407
- const { level } = request.params;
19408
- const parseResult = LoggingLevelSchema.safeParse(level);
19409
- if (parseResult.success) {
19410
- this._loggingLevels.set(transportSessionId, parseResult.data);
19411
- }
19412
- return {};
19413
- });
19414
- }
19415
19272
  }
19416
19273
  /**
19417
19274
  * Registers new capabilities. This can only be called before connecting to a transport.
@@ -19557,19 +19414,8 @@
19557
19414
  async listRoots(params, options) {
19558
19415
  return this.request({ method: "roots/list", params }, ListRootsResultSchema, options);
19559
19416
  }
19560
- /**
19561
- * Sends a logging message to the client, if connected.
19562
- * Note: You only need to send the parameters object, not the entire JSON RPC message
19563
- * @see LoggingMessageNotification
19564
- * @param params
19565
- * @param sessionId optional for stateless and backward compatibility
19566
- */
19567
- async sendLoggingMessage(params, sessionId) {
19568
- if (this._capabilities.logging) {
19569
- if (!this.isMessageIgnored(params.level, sessionId)) {
19570
- return this.notification({ method: "notifications/message", params });
19571
- }
19572
- }
19417
+ async sendLoggingMessage(params) {
19418
+ return this.notification({ method: "notifications/message", params });
19573
19419
  }
19574
19420
  async sendResourceUpdated(params) {
19575
19421
  return this.notification({
@@ -20845,13 +20691,10 @@
20845
20691
  inputSchema: tool.inputSchema ? zodToJsonSchema(tool.inputSchema, {
20846
20692
  strictUnions: true
20847
20693
  }) : EMPTY_OBJECT_JSON_SCHEMA,
20848
- annotations: tool.annotations,
20849
- _meta: tool._meta
20694
+ annotations: tool.annotations
20850
20695
  };
20851
20696
  if (tool.outputSchema) {
20852
- toolDefinition.outputSchema = zodToJsonSchema(tool.outputSchema, {
20853
- strictUnions: true
20854
- });
20697
+ toolDefinition.outputSchema = zodToJsonSchema(tool.outputSchema, { strictUnions: true });
20855
20698
  }
20856
20699
  return toolDefinition;
20857
20700
  })
@@ -21214,14 +21057,13 @@
21214
21057
  this._registeredPrompts[name] = registeredPrompt;
21215
21058
  return registeredPrompt;
21216
21059
  }
21217
- _createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, _meta, callback) {
21060
+ _createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, callback) {
21218
21061
  const registeredTool = {
21219
21062
  title: title2,
21220
21063
  description: description2,
21221
21064
  inputSchema: inputSchema === void 0 ? void 0 : objectType(inputSchema),
21222
21065
  outputSchema: outputSchema === void 0 ? void 0 : objectType(outputSchema),
21223
21066
  annotations,
21224
- _meta,
21225
21067
  callback,
21226
21068
  enabled: true,
21227
21069
  disable: () => registeredTool.update({ enabled: false }),
@@ -21243,8 +21085,6 @@
21243
21085
  registeredTool.callback = updates.callback;
21244
21086
  if (typeof updates.annotations !== "undefined")
21245
21087
  registeredTool.annotations = updates.annotations;
21246
- if (typeof updates._meta !== "undefined")
21247
- registeredTool._meta = updates._meta;
21248
21088
  if (typeof updates.enabled !== "undefined")
21249
21089
  registeredTool.enabled = updates.enabled;
21250
21090
  this.sendToolListChanged();
@@ -21281,7 +21121,7 @@
21281
21121
  }
21282
21122
  }
21283
21123
  const callback = rest[0];
21284
- return this._createRegisteredTool(name, void 0, description2, inputSchema, outputSchema, annotations, void 0, callback);
21124
+ return this._createRegisteredTool(name, void 0, description2, inputSchema, outputSchema, annotations, callback);
21285
21125
  }
21286
21126
  /**
21287
21127
  * Registers a tool with a config object and callback.
@@ -21290,8 +21130,8 @@
21290
21130
  if (this._registeredTools[name]) {
21291
21131
  throw new Error(`Tool ${name} is already registered`);
21292
21132
  }
21293
- const { title: title2, description: description2, inputSchema, outputSchema, annotations, _meta } = config;
21294
- return this._createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, _meta, cb);
21133
+ const { title: title2, description: description2, inputSchema, outputSchema, annotations } = config;
21134
+ return this._createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, cb);
21295
21135
  }
21296
21136
  prompt(name, ...rest) {
21297
21137
  if (this._registeredPrompts[name]) {
@@ -21331,16 +21171,6 @@
21331
21171
  isConnected() {
21332
21172
  return this.server.transport !== void 0;
21333
21173
  }
21334
- /**
21335
- * Sends a logging message to the client, if connected.
21336
- * Note: You only need to send the parameters object, not the entire JSON RPC message
21337
- * @see LoggingMessageNotification
21338
- * @param params
21339
- * @param sessionId optional for stateless and backward compatibility
21340
- */
21341
- async sendLoggingMessage(params, sessionId) {
21342
- return this.server.sendLoggingMessage(params, sessionId);
21343
- }
21344
21174
  /**
21345
21175
  * Sends a resource list changed event to the client, if connected.
21346
21176
  */
@@ -21456,8 +21286,6 @@
21456
21286
  exports2.EnumSchemaSchema = EnumSchemaSchema;
21457
21287
  exports2.GetPromptRequestSchema = GetPromptRequestSchema;
21458
21288
  exports2.GetPromptResultSchema = GetPromptResultSchema;
21459
- exports2.IconSchema = IconSchema;
21460
- exports2.IconsSchema = IconsSchema;
21461
21289
  exports2.ImageContentSchema = ImageContentSchema;
21462
21290
  exports2.ImplementationSchema = ImplementationSchema;
21463
21291
  exports2.InitializeRequestSchema = InitializeRequestSchema;