@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.
@@ -1017,8 +1017,8 @@ var scope = {};
1017
1017
  var util$7 = {};
1018
1018
  Object.defineProperty(util$7, "__esModule", { value: true });
1019
1019
  util$7.checkStrictMode = util$7.getErrorPath = util$7.Type = util$7.useFunc = util$7.setEvaluated = util$7.evaluatedPropsToName = util$7.mergeEvaluated = util$7.eachItem = util$7.unescapeJsonPointer = util$7.escapeJsonPointer = util$7.escapeFragment = util$7.unescapeFragment = util$7.schemaRefOrVal = util$7.schemaHasRulesButRef = util$7.schemaHasRules = util$7.checkUnknownRules = util$7.alwaysValidSchema = util$7.toHash = void 0;
1020
- const codegen_1$q = codegen;
1021
- const code_1$9 = code$1;
1020
+ const codegen_1$v = codegen;
1021
+ const code_1$a = code$1;
1022
1022
  function toHash$2(arr) {
1023
1023
  const hash = {};
1024
1024
  for (const item of arr)
@@ -1071,9 +1071,9 @@ function schemaRefOrVal({ topSchemaRef, schemaPath }, schema, keyword2, $data) {
1071
1071
  if (typeof schema == "number" || typeof schema == "boolean")
1072
1072
  return schema;
1073
1073
  if (typeof schema == "string")
1074
- return (0, codegen_1$q._)`${schema}`;
1074
+ return (0, codegen_1$v._)`${schema}`;
1075
1075
  }
1076
- return (0, codegen_1$q._)`${topSchemaRef}${schemaPath}${(0, codegen_1$q.getProperty)(keyword2)}`;
1076
+ return (0, codegen_1$v._)`${topSchemaRef}${schemaPath}${(0, codegen_1$v.getProperty)(keyword2)}`;
1077
1077
  }
1078
1078
  util$7.schemaRefOrVal = schemaRefOrVal;
1079
1079
  function unescapeFragment$1(str) {
@@ -1105,20 +1105,20 @@ function eachItem(xs, f) {
1105
1105
  util$7.eachItem = eachItem;
1106
1106
  function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues: mergeValues2, resultToName }) {
1107
1107
  return (gen, from, to, toName) => {
1108
- const res = to === void 0 ? from : to instanceof codegen_1$q.Name ? (from instanceof codegen_1$q.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1$q.Name ? (mergeToName(gen, to, from), from) : mergeValues2(from, to);
1109
- return toName === codegen_1$q.Name && !(res instanceof codegen_1$q.Name) ? resultToName(gen, res) : res;
1108
+ 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);
1109
+ return toName === codegen_1$v.Name && !(res instanceof codegen_1$v.Name) ? resultToName(gen, res) : res;
1110
1110
  };
1111
1111
  }
1112
1112
  util$7.mergeEvaluated = {
1113
1113
  props: makeMergeEvaluated({
1114
- mergeNames: (gen, from, to) => gen.if((0, codegen_1$q._)`${to} !== true && ${from} !== undefined`, () => {
1115
- gen.if((0, codegen_1$q._)`${from} === true`, () => gen.assign(to, true), () => gen.assign(to, (0, codegen_1$q._)`${to} || {}`).code((0, codegen_1$q._)`Object.assign(${to}, ${from})`));
1114
+ mergeNames: (gen, from, to) => gen.if((0, codegen_1$v._)`${to} !== true && ${from} !== undefined`, () => {
1115
+ 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})`));
1116
1116
  }),
1117
- mergeToName: (gen, from, to) => gen.if((0, codegen_1$q._)`${to} !== true`, () => {
1117
+ mergeToName: (gen, from, to) => gen.if((0, codegen_1$v._)`${to} !== true`, () => {
1118
1118
  if (from === true) {
1119
1119
  gen.assign(to, true);
1120
1120
  } else {
1121
- gen.assign(to, (0, codegen_1$q._)`${to} || {}`);
1121
+ gen.assign(to, (0, codegen_1$v._)`${to} || {}`);
1122
1122
  setEvaluated(gen, to, from);
1123
1123
  }
1124
1124
  }),
@@ -1126,8 +1126,8 @@ util$7.mergeEvaluated = {
1126
1126
  resultToName: evaluatedPropsToName
1127
1127
  }),
1128
1128
  items: makeMergeEvaluated({
1129
- mergeNames: (gen, from, to) => gen.if((0, codegen_1$q._)`${to} !== true && ${from} !== undefined`, () => gen.assign(to, (0, codegen_1$q._)`${from} === true ? true : ${to} > ${from} ? ${to} : ${from}`)),
1130
- mergeToName: (gen, from, to) => gen.if((0, codegen_1$q._)`${to} !== true`, () => gen.assign(to, from === true ? true : (0, codegen_1$q._)`${to} > ${from} ? ${to} : ${from}`)),
1129
+ 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}`)),
1130
+ 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}`)),
1131
1131
  mergeValues: (from, to) => from === true ? true : Math.max(from, to),
1132
1132
  resultToName: (gen, items2) => gen.var("items", items2)
1133
1133
  })
@@ -1135,21 +1135,21 @@ util$7.mergeEvaluated = {
1135
1135
  function evaluatedPropsToName(gen, ps) {
1136
1136
  if (ps === true)
1137
1137
  return gen.var("props", true);
1138
- const props = gen.var("props", (0, codegen_1$q._)`{}`);
1138
+ const props = gen.var("props", (0, codegen_1$v._)`{}`);
1139
1139
  if (ps !== void 0)
1140
1140
  setEvaluated(gen, props, ps);
1141
1141
  return props;
1142
1142
  }
1143
1143
  util$7.evaluatedPropsToName = evaluatedPropsToName;
1144
1144
  function setEvaluated(gen, props, ps) {
1145
- Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$q._)`${props}${(0, codegen_1$q.getProperty)(p)}`, true));
1145
+ Object.keys(ps).forEach((p) => gen.assign((0, codegen_1$v._)`${props}${(0, codegen_1$v.getProperty)(p)}`, true));
1146
1146
  }
1147
1147
  util$7.setEvaluated = setEvaluated;
1148
1148
  const snippets = {};
1149
1149
  function useFunc(gen, f) {
1150
1150
  return gen.scopeValue("func", {
1151
1151
  ref: f,
1152
- code: snippets[f.code] || (snippets[f.code] = new code_1$9._Code(f.code))
1152
+ code: snippets[f.code] || (snippets[f.code] = new code_1$a._Code(f.code))
1153
1153
  });
1154
1154
  }
1155
1155
  util$7.useFunc = useFunc;
@@ -1159,11 +1159,11 @@ var Type;
1159
1159
  Type2[Type2["Str"] = 1] = "Str";
1160
1160
  })(Type || (util$7.Type = Type = {}));
1161
1161
  function getErrorPath(dataProp, dataPropType, jsPropertySyntax) {
1162
- if (dataProp instanceof codegen_1$q.Name) {
1162
+ if (dataProp instanceof codegen_1$v.Name) {
1163
1163
  const isNumber = dataPropType === Type.Num;
1164
- return jsPropertySyntax ? isNumber ? (0, codegen_1$q._)`"[" + ${dataProp} + "]"` : (0, codegen_1$q._)`"['" + ${dataProp} + "']"` : isNumber ? (0, codegen_1$q._)`"/" + ${dataProp}` : (0, codegen_1$q._)`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")`;
1164
+ 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")`;
1165
1165
  }
1166
- return jsPropertySyntax ? (0, codegen_1$q.getProperty)(dataProp).toString() : "/" + escapeJsonPointer$1(dataProp);
1166
+ return jsPropertySyntax ? (0, codegen_1$v.getProperty)(dataProp).toString() : "/" + escapeJsonPointer$1(dataProp);
1167
1167
  }
1168
1168
  util$7.getErrorPath = getErrorPath;
1169
1169
  function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
@@ -1177,35 +1177,35 @@ function checkStrictMode(it, msg, mode = it.opts.strictSchema) {
1177
1177
  util$7.checkStrictMode = checkStrictMode;
1178
1178
  var names$1 = {};
1179
1179
  Object.defineProperty(names$1, "__esModule", { value: true });
1180
- const codegen_1$p = codegen;
1180
+ const codegen_1$u = codegen;
1181
1181
  const names = {
1182
1182
  // validation function arguments
1183
- data: new codegen_1$p.Name("data"),
1183
+ data: new codegen_1$u.Name("data"),
1184
1184
  // data passed to validation function
1185
1185
  // args passed from referencing schema
1186
- valCxt: new codegen_1$p.Name("valCxt"),
1186
+ valCxt: new codegen_1$u.Name("valCxt"),
1187
1187
  // validation/data context - should not be used directly, it is destructured to the names below
1188
- instancePath: new codegen_1$p.Name("instancePath"),
1189
- parentData: new codegen_1$p.Name("parentData"),
1190
- parentDataProperty: new codegen_1$p.Name("parentDataProperty"),
1191
- rootData: new codegen_1$p.Name("rootData"),
1188
+ instancePath: new codegen_1$u.Name("instancePath"),
1189
+ parentData: new codegen_1$u.Name("parentData"),
1190
+ parentDataProperty: new codegen_1$u.Name("parentDataProperty"),
1191
+ rootData: new codegen_1$u.Name("rootData"),
1192
1192
  // root data - same as the data passed to the first/top validation function
1193
- dynamicAnchors: new codegen_1$p.Name("dynamicAnchors"),
1193
+ dynamicAnchors: new codegen_1$u.Name("dynamicAnchors"),
1194
1194
  // used to support recursiveRef and dynamicRef
1195
1195
  // function scoped variables
1196
- vErrors: new codegen_1$p.Name("vErrors"),
1196
+ vErrors: new codegen_1$u.Name("vErrors"),
1197
1197
  // null or array of validation errors
1198
- errors: new codegen_1$p.Name("errors"),
1198
+ errors: new codegen_1$u.Name("errors"),
1199
1199
  // counter of validation errors
1200
- this: new codegen_1$p.Name("this"),
1200
+ this: new codegen_1$u.Name("this"),
1201
1201
  // "globals"
1202
- self: new codegen_1$p.Name("self"),
1203
- scope: new codegen_1$p.Name("scope"),
1202
+ self: new codegen_1$u.Name("self"),
1203
+ scope: new codegen_1$u.Name("scope"),
1204
1204
  // JTD serialize/parse name for JSON string and position
1205
- json: new codegen_1$p.Name("json"),
1206
- jsonPos: new codegen_1$p.Name("jsonPos"),
1207
- jsonLen: new codegen_1$p.Name("jsonLen"),
1208
- jsonPart: new codegen_1$p.Name("jsonPart")
1205
+ json: new codegen_1$u.Name("json"),
1206
+ jsonPos: new codegen_1$u.Name("jsonPos"),
1207
+ jsonLen: new codegen_1$u.Name("jsonLen"),
1208
+ jsonPart: new codegen_1$u.Name("jsonPart")
1209
1209
  };
1210
1210
  names$1.default = names;
1211
1211
  (function(exports) {
@@ -1325,55 +1325,49 @@ names$1.default = names;
1325
1325
  keyValues.push([E.propertyName, propertyName]);
1326
1326
  }
1327
1327
  })(errors);
1328
- var hasRequiredBoolSchema;
1329
- function requireBoolSchema() {
1330
- if (hasRequiredBoolSchema) return boolSchema;
1331
- hasRequiredBoolSchema = 1;
1332
- Object.defineProperty(boolSchema, "__esModule", { value: true });
1333
- boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
1334
- const errors_12 = errors;
1335
- const codegen_12 = codegen;
1336
- const names_12 = names$1;
1337
- const boolError = {
1338
- message: "boolean schema is false"
1339
- };
1340
- function topBoolOrEmptySchema(it) {
1341
- const { gen, schema, validateName } = it;
1342
- if (schema === false) {
1343
- falseSchemaError(it, false);
1344
- } else if (typeof schema == "object" && schema.$async === true) {
1345
- gen.return(names_12.default.data);
1346
- } else {
1347
- gen.assign((0, codegen_12._)`${validateName}.errors`, null);
1348
- gen.return(true);
1349
- }
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);
1359
- }
1328
+ Object.defineProperty(boolSchema, "__esModule", { value: true });
1329
+ boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
1330
+ const errors_1$3 = errors;
1331
+ const codegen_1$t = codegen;
1332
+ const names_1$6 = names$1;
1333
+ const boolError = {
1334
+ message: "boolean schema is false"
1335
+ };
1336
+ function topBoolOrEmptySchema(it) {
1337
+ const { gen, schema, validateName } = it;
1338
+ if (schema === false) {
1339
+ falseSchemaError(it, false);
1340
+ } else if (typeof schema == "object" && schema.$async === true) {
1341
+ gen.return(names_1$6.default.data);
1342
+ } else {
1343
+ gen.assign((0, codegen_1$t._)`${validateName}.errors`, null);
1344
+ gen.return(true);
1360
1345
  }
1361
- boolSchema.boolOrEmptySchema = boolOrEmptySchema;
1362
- function falseSchemaError(it, overrideAllErrors) {
1363
- const { gen, data: data2 } = it;
1364
- const cxt = {
1365
- gen,
1366
- keyword: "false schema",
1367
- data: data2,
1368
- schema: false,
1369
- schemaCode: false,
1370
- schemaValue: false,
1371
- params: {},
1372
- it
1373
- };
1374
- (0, errors_12.reportError)(cxt, boolError, void 0, overrideAllErrors);
1346
+ }
1347
+ boolSchema.topBoolOrEmptySchema = topBoolOrEmptySchema;
1348
+ function boolOrEmptySchema(it, valid) {
1349
+ const { gen, schema } = it;
1350
+ if (schema === false) {
1351
+ gen.var(valid, false);
1352
+ falseSchemaError(it);
1353
+ } else {
1354
+ gen.var(valid, true);
1375
1355
  }
1376
- return boolSchema;
1356
+ }
1357
+ boolSchema.boolOrEmptySchema = boolOrEmptySchema;
1358
+ function falseSchemaError(it, overrideAllErrors) {
1359
+ const { gen, data: data2 } = it;
1360
+ const cxt = {
1361
+ gen,
1362
+ keyword: "false schema",
1363
+ data: data2,
1364
+ schema: false,
1365
+ schemaCode: false,
1366
+ schemaValue: false,
1367
+ params: {},
1368
+ it
1369
+ };
1370
+ (0, errors_1$3.reportError)(cxt, boolError, void 0, overrideAllErrors);
1377
1371
  }
1378
1372
  var dataType = {};
1379
1373
  var rules$2 = {};
@@ -1421,10 +1415,10 @@ applicability.shouldUseRule = shouldUseRule;
1421
1415
  Object.defineProperty(dataType, "__esModule", { value: true });
1422
1416
  dataType.reportTypeError = dataType.checkDataTypes = dataType.checkDataType = dataType.coerceAndCheckDataType = dataType.getJSONTypes = dataType.getSchemaTypes = dataType.DataType = void 0;
1423
1417
  const rules_1 = rules$2;
1424
- const applicability_1 = applicability;
1425
- const errors_1 = errors;
1426
- const codegen_1$o = codegen;
1427
- const util_1$n = util$7;
1418
+ const applicability_1$1 = applicability;
1419
+ const errors_1$2 = errors;
1420
+ const codegen_1$s = codegen;
1421
+ const util_1$q = util$7;
1428
1422
  var DataType;
1429
1423
  (function(DataType2) {
1430
1424
  DataType2[DataType2["Correct"] = 0] = "Correct";
@@ -1456,7 +1450,7 @@ dataType.getJSONTypes = getJSONTypes;
1456
1450
  function coerceAndCheckDataType(it, types2) {
1457
1451
  const { gen, data: data2, opts } = it;
1458
1452
  const coerceTo = coerceToTypes$1(types2, opts.coerceTypes);
1459
- const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1.schemaHasRulesForType)(it, types2[0]));
1453
+ const checkTypes = types2.length > 0 && !(coerceTo.length === 0 && types2.length === 1 && (0, applicability_1$1.schemaHasRulesForType)(it, types2[0]));
1460
1454
  if (checkTypes) {
1461
1455
  const wrongType = checkDataTypes$1(types2, data2, opts.strictNumbers, DataType.Wrong);
1462
1456
  gen.if(wrongType, () => {
@@ -1475,12 +1469,12 @@ function coerceToTypes$1(types2, coerceTypes) {
1475
1469
  }
1476
1470
  function coerceData(it, types2, coerceTo) {
1477
1471
  const { gen, data: data2, opts } = it;
1478
- const dataType2 = gen.let("dataType", (0, codegen_1$o._)`typeof ${data2}`);
1479
- const coerced = gen.let("coerced", (0, codegen_1$o._)`undefined`);
1472
+ const dataType2 = gen.let("dataType", (0, codegen_1$s._)`typeof ${data2}`);
1473
+ const coerced = gen.let("coerced", (0, codegen_1$s._)`undefined`);
1480
1474
  if (opts.coerceTypes === "array") {
1481
- gen.if((0, codegen_1$o._)`${dataType2} == 'object' && Array.isArray(${data2}) && ${data2}.length == 1`, () => gen.assign(data2, (0, codegen_1$o._)`${data2}[0]`).assign(dataType2, (0, codegen_1$o._)`typeof ${data2}`).if(checkDataTypes$1(types2, data2, opts.strictNumbers), () => gen.assign(coerced, data2)));
1475
+ 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)));
1482
1476
  }
1483
- gen.if((0, codegen_1$o._)`${coerced} !== undefined`);
1477
+ gen.if((0, codegen_1$s._)`${coerced} !== undefined`);
1484
1478
  for (const t of coerceTo) {
1485
1479
  if (COERCIBLE.has(t) || t === "array" && opts.coerceTypes === "array") {
1486
1480
  coerceSpecificType(t);
@@ -1489,63 +1483,63 @@ function coerceData(it, types2, coerceTo) {
1489
1483
  gen.else();
1490
1484
  reportTypeError(it);
1491
1485
  gen.endIf();
1492
- gen.if((0, codegen_1$o._)`${coerced} !== undefined`, () => {
1486
+ gen.if((0, codegen_1$s._)`${coerced} !== undefined`, () => {
1493
1487
  gen.assign(data2, coerced);
1494
1488
  assignParentData(it, coerced);
1495
1489
  });
1496
1490
  function coerceSpecificType(t) {
1497
1491
  switch (t) {
1498
1492
  case "string":
1499
- gen.elseIf((0, codegen_1$o._)`${dataType2} == "number" || ${dataType2} == "boolean"`).assign(coerced, (0, codegen_1$o._)`"" + ${data2}`).elseIf((0, codegen_1$o._)`${data2} === null`).assign(coerced, (0, codegen_1$o._)`""`);
1493
+ 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._)`""`);
1500
1494
  return;
1501
1495
  case "number":
1502
- gen.elseIf((0, codegen_1$o._)`${dataType2} == "boolean" || ${data2} === null
1503
- || (${dataType2} == "string" && ${data2} && ${data2} == +${data2})`).assign(coerced, (0, codegen_1$o._)`+${data2}`);
1496
+ gen.elseIf((0, codegen_1$s._)`${dataType2} == "boolean" || ${data2} === null
1497
+ || (${dataType2} == "string" && ${data2} && ${data2} == +${data2})`).assign(coerced, (0, codegen_1$s._)`+${data2}`);
1504
1498
  return;
1505
1499
  case "integer":
1506
- gen.elseIf((0, codegen_1$o._)`${dataType2} === "boolean" || ${data2} === null
1507
- || (${dataType2} === "string" && ${data2} && ${data2} == +${data2} && !(${data2} % 1))`).assign(coerced, (0, codegen_1$o._)`+${data2}`);
1500
+ gen.elseIf((0, codegen_1$s._)`${dataType2} === "boolean" || ${data2} === null
1501
+ || (${dataType2} === "string" && ${data2} && ${data2} == +${data2} && !(${data2} % 1))`).assign(coerced, (0, codegen_1$s._)`+${data2}`);
1508
1502
  return;
1509
1503
  case "boolean":
1510
- gen.elseIf((0, codegen_1$o._)`${data2} === "false" || ${data2} === 0 || ${data2} === null`).assign(coerced, false).elseIf((0, codegen_1$o._)`${data2} === "true" || ${data2} === 1`).assign(coerced, true);
1504
+ 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);
1511
1505
  return;
1512
1506
  case "null":
1513
- gen.elseIf((0, codegen_1$o._)`${data2} === "" || ${data2} === 0 || ${data2} === false`);
1507
+ gen.elseIf((0, codegen_1$s._)`${data2} === "" || ${data2} === 0 || ${data2} === false`);
1514
1508
  gen.assign(coerced, null);
1515
1509
  return;
1516
1510
  case "array":
1517
- gen.elseIf((0, codegen_1$o._)`${dataType2} === "string" || ${dataType2} === "number"
1518
- || ${dataType2} === "boolean" || ${data2} === null`).assign(coerced, (0, codegen_1$o._)`[${data2}]`);
1511
+ gen.elseIf((0, codegen_1$s._)`${dataType2} === "string" || ${dataType2} === "number"
1512
+ || ${dataType2} === "boolean" || ${data2} === null`).assign(coerced, (0, codegen_1$s._)`[${data2}]`);
1519
1513
  }
1520
1514
  }
1521
1515
  }
1522
1516
  function assignParentData({ gen, parentData, parentDataProperty }, expr) {
1523
- gen.if((0, codegen_1$o._)`${parentData} !== undefined`, () => gen.assign((0, codegen_1$o._)`${parentData}[${parentDataProperty}]`, expr));
1517
+ gen.if((0, codegen_1$s._)`${parentData} !== undefined`, () => gen.assign((0, codegen_1$s._)`${parentData}[${parentDataProperty}]`, expr));
1524
1518
  }
1525
1519
  function checkDataType$1(dataType2, data2, strictNums, correct = DataType.Correct) {
1526
- const EQ = correct === DataType.Correct ? codegen_1$o.operators.EQ : codegen_1$o.operators.NEQ;
1520
+ const EQ = correct === DataType.Correct ? codegen_1$s.operators.EQ : codegen_1$s.operators.NEQ;
1527
1521
  let cond;
1528
1522
  switch (dataType2) {
1529
1523
  case "null":
1530
- return (0, codegen_1$o._)`${data2} ${EQ} null`;
1524
+ return (0, codegen_1$s._)`${data2} ${EQ} null`;
1531
1525
  case "array":
1532
- cond = (0, codegen_1$o._)`Array.isArray(${data2})`;
1526
+ cond = (0, codegen_1$s._)`Array.isArray(${data2})`;
1533
1527
  break;
1534
1528
  case "object":
1535
- cond = (0, codegen_1$o._)`${data2} && typeof ${data2} == "object" && !Array.isArray(${data2})`;
1529
+ cond = (0, codegen_1$s._)`${data2} && typeof ${data2} == "object" && !Array.isArray(${data2})`;
1536
1530
  break;
1537
1531
  case "integer":
1538
- cond = numCond((0, codegen_1$o._)`!(${data2} % 1) && !isNaN(${data2})`);
1532
+ cond = numCond((0, codegen_1$s._)`!(${data2} % 1) && !isNaN(${data2})`);
1539
1533
  break;
1540
1534
  case "number":
1541
1535
  cond = numCond();
1542
1536
  break;
1543
1537
  default:
1544
- return (0, codegen_1$o._)`typeof ${data2} ${EQ} ${dataType2}`;
1538
+ return (0, codegen_1$s._)`typeof ${data2} ${EQ} ${dataType2}`;
1545
1539
  }
1546
- return correct === DataType.Correct ? cond : (0, codegen_1$o.not)(cond);
1547
- function numCond(_cond = codegen_1$o.nil) {
1548
- return (0, codegen_1$o.and)((0, codegen_1$o._)`typeof ${data2} == "number"`, _cond, strictNums ? (0, codegen_1$o._)`isFinite(${data2})` : codegen_1$o.nil);
1540
+ return correct === DataType.Correct ? cond : (0, codegen_1$s.not)(cond);
1541
+ function numCond(_cond = codegen_1$s.nil) {
1542
+ 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);
1549
1543
  }
1550
1544
  }
1551
1545
  dataType.checkDataType = checkDataType$1;
@@ -1554,35 +1548,35 @@ function checkDataTypes$1(dataTypes, data2, strictNums, correct) {
1554
1548
  return checkDataType$1(dataTypes[0], data2, strictNums, correct);
1555
1549
  }
1556
1550
  let cond;
1557
- const types2 = (0, util_1$n.toHash)(dataTypes);
1551
+ const types2 = (0, util_1$q.toHash)(dataTypes);
1558
1552
  if (types2.array && types2.object) {
1559
- const notObj = (0, codegen_1$o._)`typeof ${data2} != "object"`;
1560
- cond = types2.null ? notObj : (0, codegen_1$o._)`!${data2} || ${notObj}`;
1553
+ const notObj = (0, codegen_1$s._)`typeof ${data2} != "object"`;
1554
+ cond = types2.null ? notObj : (0, codegen_1$s._)`!${data2} || ${notObj}`;
1561
1555
  delete types2.null;
1562
1556
  delete types2.array;
1563
1557
  delete types2.object;
1564
1558
  } else {
1565
- cond = codegen_1$o.nil;
1559
+ cond = codegen_1$s.nil;
1566
1560
  }
1567
1561
  if (types2.number)
1568
1562
  delete types2.integer;
1569
1563
  for (const t in types2)
1570
- cond = (0, codegen_1$o.and)(cond, checkDataType$1(t, data2, strictNums, correct));
1564
+ cond = (0, codegen_1$s.and)(cond, checkDataType$1(t, data2, strictNums, correct));
1571
1565
  return cond;
1572
1566
  }
1573
1567
  dataType.checkDataTypes = checkDataTypes$1;
1574
1568
  const typeError = {
1575
1569
  message: ({ schema }) => `must be ${schema}`,
1576
- params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$o._)`{type: ${schema}}` : (0, codegen_1$o._)`{type: ${schemaValue}}`
1570
+ params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1$s._)`{type: ${schema}}` : (0, codegen_1$s._)`{type: ${schemaValue}}`
1577
1571
  };
1578
1572
  function reportTypeError(it) {
1579
1573
  const cxt = getTypeErrorContext(it);
1580
- (0, errors_1.reportError)(cxt, typeError);
1574
+ (0, errors_1$2.reportError)(cxt, typeError);
1581
1575
  }
1582
1576
  dataType.reportTypeError = reportTypeError;
1583
1577
  function getTypeErrorContext(it) {
1584
1578
  const { gen, data: data2, schema } = it;
1585
- const schemaCode = (0, util_1$n.schemaRefOrVal)(it, schema, "type");
1579
+ const schemaCode = (0, util_1$q.schemaRefOrVal)(it, schema, "type");
1586
1580
  return {
1587
1581
  gen,
1588
1582
  keyword: "type",
@@ -1596,60 +1590,54 @@ function getTypeErrorContext(it) {
1596
1590
  };
1597
1591
  }
1598
1592
  var defaults = {};
1599
- var hasRequiredDefaults;
1600
- function requireDefaults() {
1601
- if (hasRequiredDefaults) return defaults;
1602
- hasRequiredDefaults = 1;
1603
- Object.defineProperty(defaults, "__esModule", { value: true });
1604
- defaults.assignDefaults = void 0;
1605
- const codegen_12 = codegen;
1606
- const util_12 = util$7;
1607
- function assignDefaults(it, ty) {
1608
- const { properties: properties2, items: items2 } = it.schema;
1609
- if (ty === "object" && properties2) {
1610
- for (const key in properties2) {
1611
- assignDefault(it, key, properties2[key].default);
1612
- }
1613
- } else if (ty === "array" && Array.isArray(items2)) {
1614
- items2.forEach((sch, i) => assignDefault(it, i, sch.default));
1615
- }
1593
+ Object.defineProperty(defaults, "__esModule", { value: true });
1594
+ defaults.assignDefaults = void 0;
1595
+ const codegen_1$r = codegen;
1596
+ const util_1$p = util$7;
1597
+ function assignDefaults(it, ty) {
1598
+ const { properties: properties2, items: items2 } = it.schema;
1599
+ if (ty === "object" && properties2) {
1600
+ for (const key in properties2) {
1601
+ assignDefault(it, key, properties2[key].default);
1602
+ }
1603
+ } else if (ty === "array" && Array.isArray(items2)) {
1604
+ items2.forEach((sch, i) => assignDefault(it, i, sch.default));
1605
+ }
1606
+ }
1607
+ defaults.assignDefaults = assignDefaults;
1608
+ function assignDefault(it, prop, defaultValue) {
1609
+ const { gen, compositeRule, data: data2, opts } = it;
1610
+ if (defaultValue === void 0)
1611
+ return;
1612
+ const childData = (0, codegen_1$r._)`${data2}${(0, codegen_1$r.getProperty)(prop)}`;
1613
+ if (compositeRule) {
1614
+ (0, util_1$p.checkStrictMode)(it, `default is ignored for: ${childData}`);
1615
+ return;
1616
1616
  }
1617
- defaults.assignDefaults = assignDefaults;
1618
- function assignDefault(it, prop, defaultValue) {
1619
- const { gen, compositeRule, data: data2, opts } = it;
1620
- if (defaultValue === void 0)
1621
- return;
1622
- const childData = (0, codegen_12._)`${data2}${(0, codegen_12.getProperty)(prop)}`;
1623
- if (compositeRule) {
1624
- (0, util_12.checkStrictMode)(it, `default is ignored for: ${childData}`);
1625
- return;
1626
- }
1627
- let condition = (0, codegen_12._)`${childData} === undefined`;
1628
- if (opts.useDefaults === "empty") {
1629
- condition = (0, codegen_12._)`${condition} || ${childData} === null || ${childData} === ""`;
1630
- }
1631
- gen.if(condition, (0, codegen_12._)`${childData} = ${(0, codegen_12.stringify)(defaultValue)}`);
1617
+ let condition = (0, codegen_1$r._)`${childData} === undefined`;
1618
+ if (opts.useDefaults === "empty") {
1619
+ condition = (0, codegen_1$r._)`${condition} || ${childData} === null || ${childData} === ""`;
1632
1620
  }
1633
- return defaults;
1621
+ gen.if(condition, (0, codegen_1$r._)`${childData} = ${(0, codegen_1$r.stringify)(defaultValue)}`);
1634
1622
  }
1635
1623
  var keyword$1 = {};
1636
1624
  var code = {};
1637
1625
  Object.defineProperty(code, "__esModule", { value: true });
1638
1626
  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;
1639
- const codegen_1$n = codegen;
1640
- const util_1$m = util$7;
1641
- const names_1$3 = names$1;
1627
+ const codegen_1$q = codegen;
1628
+ const util_1$o = util$7;
1629
+ const names_1$5 = names$1;
1642
1630
  const util_2$1 = util$7;
1643
1631
  function checkReportMissingProp(cxt, prop) {
1644
1632
  const { gen, data: data2, it } = cxt;
1645
1633
  gen.if(noPropertyInData(gen, data2, prop, it.opts.ownProperties), () => {
1646
- cxt.setParams({ missingProperty: (0, codegen_1$n._)`${prop}` }, true);
1634
+ cxt.setParams({ missingProperty: (0, codegen_1$q._)`${prop}` }, true);
1647
1635
  cxt.error();
1648
1636
  });
1649
1637
  }
1650
1638
  code.checkReportMissingProp = checkReportMissingProp;
1651
1639
  function checkMissingProp({ gen, data: data2, it: { opts } }, properties2, missing) {
1652
- return (0, codegen_1$n.or)(...properties2.map((prop) => (0, codegen_1$n.and)(noPropertyInData(gen, data2, prop, opts.ownProperties), (0, codegen_1$n._)`${missing} = ${prop}`)));
1640
+ 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}`)));
1653
1641
  }
1654
1642
  code.checkMissingProp = checkMissingProp;
1655
1643
  function reportMissingProp(cxt, missing) {
@@ -1661,22 +1649,22 @@ function hasPropFunc(gen) {
1661
1649
  return gen.scopeValue("func", {
1662
1650
  // eslint-disable-next-line @typescript-eslint/unbound-method
1663
1651
  ref: Object.prototype.hasOwnProperty,
1664
- code: (0, codegen_1$n._)`Object.prototype.hasOwnProperty`
1652
+ code: (0, codegen_1$q._)`Object.prototype.hasOwnProperty`
1665
1653
  });
1666
1654
  }
1667
1655
  code.hasPropFunc = hasPropFunc;
1668
1656
  function isOwnProperty(gen, data2, property) {
1669
- return (0, codegen_1$n._)`${hasPropFunc(gen)}.call(${data2}, ${property})`;
1657
+ return (0, codegen_1$q._)`${hasPropFunc(gen)}.call(${data2}, ${property})`;
1670
1658
  }
1671
1659
  code.isOwnProperty = isOwnProperty;
1672
1660
  function propertyInData(gen, data2, property, ownProperties) {
1673
- const cond = (0, codegen_1$n._)`${data2}${(0, codegen_1$n.getProperty)(property)} !== undefined`;
1674
- return ownProperties ? (0, codegen_1$n._)`${cond} && ${isOwnProperty(gen, data2, property)}` : cond;
1661
+ const cond = (0, codegen_1$q._)`${data2}${(0, codegen_1$q.getProperty)(property)} !== undefined`;
1662
+ return ownProperties ? (0, codegen_1$q._)`${cond} && ${isOwnProperty(gen, data2, property)}` : cond;
1675
1663
  }
1676
1664
  code.propertyInData = propertyInData;
1677
1665
  function noPropertyInData(gen, data2, property, ownProperties) {
1678
- const cond = (0, codegen_1$n._)`${data2}${(0, codegen_1$n.getProperty)(property)} === undefined`;
1679
- return ownProperties ? (0, codegen_1$n.or)(cond, (0, codegen_1$n.not)(isOwnProperty(gen, data2, property))) : cond;
1666
+ const cond = (0, codegen_1$q._)`${data2}${(0, codegen_1$q.getProperty)(property)} === undefined`;
1667
+ return ownProperties ? (0, codegen_1$q.or)(cond, (0, codegen_1$q.not)(isOwnProperty(gen, data2, property))) : cond;
1680
1668
  }
1681
1669
  code.noPropertyInData = noPropertyInData;
1682
1670
  function allSchemaProperties(schemaMap) {
@@ -1684,24 +1672,24 @@ function allSchemaProperties(schemaMap) {
1684
1672
  }
1685
1673
  code.allSchemaProperties = allSchemaProperties;
1686
1674
  function schemaProperties(it, schemaMap) {
1687
- return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$m.alwaysValidSchema)(it, schemaMap[p]));
1675
+ return allSchemaProperties(schemaMap).filter((p) => !(0, util_1$o.alwaysValidSchema)(it, schemaMap[p]));
1688
1676
  }
1689
1677
  code.schemaProperties = schemaProperties;
1690
1678
  function callValidateCode({ schemaCode, data: data2, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context, passSchema) {
1691
- const dataAndSchema = passSchema ? (0, codegen_1$n._)`${schemaCode}, ${data2}, ${topSchemaRef}${schemaPath}` : data2;
1679
+ const dataAndSchema = passSchema ? (0, codegen_1$q._)`${schemaCode}, ${data2}, ${topSchemaRef}${schemaPath}` : data2;
1692
1680
  const valCxt = [
1693
- [names_1$3.default.instancePath, (0, codegen_1$n.strConcat)(names_1$3.default.instancePath, errorPath)],
1694
- [names_1$3.default.parentData, it.parentData],
1695
- [names_1$3.default.parentDataProperty, it.parentDataProperty],
1696
- [names_1$3.default.rootData, names_1$3.default.rootData]
1681
+ [names_1$5.default.instancePath, (0, codegen_1$q.strConcat)(names_1$5.default.instancePath, errorPath)],
1682
+ [names_1$5.default.parentData, it.parentData],
1683
+ [names_1$5.default.parentDataProperty, it.parentDataProperty],
1684
+ [names_1$5.default.rootData, names_1$5.default.rootData]
1697
1685
  ];
1698
1686
  if (it.opts.dynamicRef)
1699
- valCxt.push([names_1$3.default.dynamicAnchors, names_1$3.default.dynamicAnchors]);
1700
- const args = (0, codegen_1$n._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
1701
- return context !== codegen_1$n.nil ? (0, codegen_1$n._)`${func}.call(${context}, ${args})` : (0, codegen_1$n._)`${func}(${args})`;
1687
+ valCxt.push([names_1$5.default.dynamicAnchors, names_1$5.default.dynamicAnchors]);
1688
+ const args = (0, codegen_1$q._)`${dataAndSchema}, ${gen.object(...valCxt)}`;
1689
+ return context !== codegen_1$q.nil ? (0, codegen_1$q._)`${func}.call(${context}, ${args})` : (0, codegen_1$q._)`${func}(${args})`;
1702
1690
  }
1703
1691
  code.callValidateCode = callValidateCode;
1704
- const newRegExp = (0, codegen_1$n._)`new RegExp`;
1692
+ const newRegExp = (0, codegen_1$q._)`new RegExp`;
1705
1693
  function usePattern({ gen, it: { opts } }, pattern2) {
1706
1694
  const u = opts.unicodeRegExp ? "u" : "";
1707
1695
  const { regExp } = opts.code;
@@ -1709,7 +1697,7 @@ function usePattern({ gen, it: { opts } }, pattern2) {
1709
1697
  return gen.scopeValue("pattern", {
1710
1698
  key: rx.toString(),
1711
1699
  ref: rx,
1712
- code: (0, codegen_1$n._)`${regExp.code === "new RegExp" ? newRegExp : (0, util_2$1.useFunc)(gen, regExp)}(${pattern2}, ${u})`
1700
+ code: (0, codegen_1$q._)`${regExp.code === "new RegExp" ? newRegExp : (0, util_2$1.useFunc)(gen, regExp)}(${pattern2}, ${u})`
1713
1701
  });
1714
1702
  }
1715
1703
  code.usePattern = usePattern;
@@ -1725,14 +1713,14 @@ function validateArray(cxt) {
1725
1713
  validateItems(() => gen.break());
1726
1714
  return valid;
1727
1715
  function validateItems(notValid) {
1728
- const len = gen.const("len", (0, codegen_1$n._)`${data2}.length`);
1716
+ const len = gen.const("len", (0, codegen_1$q._)`${data2}.length`);
1729
1717
  gen.forRange("i", 0, len, (i) => {
1730
1718
  cxt.subschema({
1731
1719
  keyword: keyword2,
1732
1720
  dataProp: i,
1733
- dataPropType: util_1$m.Type.Num
1721
+ dataPropType: util_1$o.Type.Num
1734
1722
  }, valid);
1735
- gen.if((0, codegen_1$n.not)(valid), notValid);
1723
+ gen.if((0, codegen_1$q.not)(valid), notValid);
1736
1724
  });
1737
1725
  }
1738
1726
  }
@@ -1741,7 +1729,7 @@ function validateUnion(cxt) {
1741
1729
  const { gen, schema, keyword: keyword2, it } = cxt;
1742
1730
  if (!Array.isArray(schema))
1743
1731
  throw new Error("ajv implementation error");
1744
- const alwaysValid = schema.some((sch) => (0, util_1$m.alwaysValidSchema)(it, sch));
1732
+ const alwaysValid = schema.some((sch) => (0, util_1$o.alwaysValidSchema)(it, sch));
1745
1733
  if (alwaysValid && !it.opts.unevaluated)
1746
1734
  return;
1747
1735
  const valid = gen.let("valid", false);
@@ -1752,214 +1740,202 @@ function validateUnion(cxt) {
1752
1740
  schemaProp: i,
1753
1741
  compositeRule: true
1754
1742
  }, schValid);
1755
- gen.assign(valid, (0, codegen_1$n._)`${valid} || ${schValid}`);
1743
+ gen.assign(valid, (0, codegen_1$q._)`${valid} || ${schValid}`);
1756
1744
  const merged = cxt.mergeValidEvaluated(schCxt, schValid);
1757
1745
  if (!merged)
1758
- gen.if((0, codegen_1$n.not)(valid));
1746
+ gen.if((0, codegen_1$q.not)(valid));
1759
1747
  }));
1760
1748
  cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
1761
1749
  }
1762
1750
  code.validateUnion = validateUnion;
1763
- var hasRequiredKeyword;
1764
- function requireKeyword() {
1765
- if (hasRequiredKeyword) return keyword$1;
1766
- hasRequiredKeyword = 1;
1767
- Object.defineProperty(keyword$1, "__esModule", { value: true });
1768
- keyword$1.validateKeywordUsage = keyword$1.validSchemaType = keyword$1.funcKeywordCode = keyword$1.macroKeywordCode = void 0;
1769
- const codegen_12 = codegen;
1770
- const names_12 = names$1;
1771
- const code_12 = code;
1772
- const errors_12 = errors;
1773
- function macroKeywordCode(cxt, def2) {
1774
- const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
1775
- const macroSchema = def2.macro.call(it.self, schema, parentSchema, it);
1776
- const schemaRef = useKeyword(gen, keyword2, macroSchema);
1777
- if (it.opts.validateSchema !== false)
1778
- it.self.validateSchema(macroSchema, true);
1779
- const valid = gen.name("valid");
1780
- cxt.subschema({
1781
- schema: macroSchema,
1782
- schemaPath: codegen_12.nil,
1783
- errSchemaPath: `${it.errSchemaPath}/${keyword2}`,
1784
- topSchemaRef: schemaRef,
1785
- compositeRule: true
1786
- }, valid);
1787
- cxt.pass(valid, () => cxt.error(true));
1788
- }
1789
- keyword$1.macroKeywordCode = macroKeywordCode;
1790
- function funcKeywordCode(cxt, def2) {
1791
- var _a;
1792
- const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
1793
- checkAsyncKeyword(it, def2);
1794
- const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
1795
- const validateRef = useKeyword(gen, keyword2, validate2);
1796
- const valid = gen.let("valid");
1797
- cxt.block$data(valid, validateKeyword2);
1798
- cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
1799
- function validateKeyword2() {
1800
- if (def2.errors === false) {
1801
- assignValid();
1802
- if (def2.modifying)
1803
- modifyData(cxt);
1804
- reportErrs(() => cxt.error());
1805
- } else {
1806
- const ruleErrs = def2.async ? validateAsync() : validateSync();
1807
- if (def2.modifying)
1808
- modifyData(cxt);
1809
- reportErrs(() => addErrs(cxt, ruleErrs));
1810
- }
1811
- }
1812
- function validateAsync() {
1813
- const ruleErrs = gen.let("ruleErrs", null);
1814
- gen.try(() => assignValid((0, codegen_12._)`await `), (e) => gen.assign(valid, false).if((0, codegen_12._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_12._)`${e}.errors`), () => gen.throw(e)));
1815
- return ruleErrs;
1816
- }
1817
- function validateSync() {
1818
- const validateErrs = (0, codegen_12._)`${validateRef}.errors`;
1819
- gen.assign(validateErrs, null);
1820
- assignValid(codegen_12.nil);
1821
- return validateErrs;
1822
- }
1823
- function assignValid(_await = def2.async ? (0, codegen_12._)`await ` : codegen_12.nil) {
1824
- const passCxt = it.opts.passContext ? names_12.default.this : names_12.default.self;
1825
- const passSchema = !("compile" in def2 && !$data || def2.schema === false);
1826
- gen.assign(valid, (0, codegen_12._)`${_await}${(0, code_12.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
1827
- }
1828
- function reportErrs(errors2) {
1829
- var _a2;
1830
- gen.if((0, codegen_12.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
1751
+ Object.defineProperty(keyword$1, "__esModule", { value: true });
1752
+ keyword$1.validateKeywordUsage = keyword$1.validSchemaType = keyword$1.funcKeywordCode = keyword$1.macroKeywordCode = void 0;
1753
+ const codegen_1$p = codegen;
1754
+ const names_1$4 = names$1;
1755
+ const code_1$9 = code;
1756
+ const errors_1$1 = errors;
1757
+ function macroKeywordCode(cxt, def2) {
1758
+ const { gen, keyword: keyword2, schema, parentSchema, it } = cxt;
1759
+ const macroSchema = def2.macro.call(it.self, schema, parentSchema, it);
1760
+ const schemaRef = useKeyword(gen, keyword2, macroSchema);
1761
+ if (it.opts.validateSchema !== false)
1762
+ it.self.validateSchema(macroSchema, true);
1763
+ const valid = gen.name("valid");
1764
+ cxt.subschema({
1765
+ schema: macroSchema,
1766
+ schemaPath: codegen_1$p.nil,
1767
+ errSchemaPath: `${it.errSchemaPath}/${keyword2}`,
1768
+ topSchemaRef: schemaRef,
1769
+ compositeRule: true
1770
+ }, valid);
1771
+ cxt.pass(valid, () => cxt.error(true));
1772
+ }
1773
+ keyword$1.macroKeywordCode = macroKeywordCode;
1774
+ function funcKeywordCode(cxt, def2) {
1775
+ var _a;
1776
+ const { gen, keyword: keyword2, schema, parentSchema, $data, it } = cxt;
1777
+ checkAsyncKeyword(it, def2);
1778
+ const validate2 = !$data && def2.compile ? def2.compile.call(it.self, schema, parentSchema, it) : def2.validate;
1779
+ const validateRef = useKeyword(gen, keyword2, validate2);
1780
+ const valid = gen.let("valid");
1781
+ cxt.block$data(valid, validateKeyword2);
1782
+ cxt.ok((_a = def2.valid) !== null && _a !== void 0 ? _a : valid);
1783
+ function validateKeyword2() {
1784
+ if (def2.errors === false) {
1785
+ assignValid();
1786
+ if (def2.modifying)
1787
+ modifyData(cxt);
1788
+ reportErrs(() => cxt.error());
1789
+ } else {
1790
+ const ruleErrs = def2.async ? validateAsync() : validateSync();
1791
+ if (def2.modifying)
1792
+ modifyData(cxt);
1793
+ reportErrs(() => addErrs(cxt, ruleErrs));
1831
1794
  }
1832
1795
  }
1833
- keyword$1.funcKeywordCode = funcKeywordCode;
1834
- function modifyData(cxt) {
1835
- const { gen, data: data2, it } = cxt;
1836
- gen.if(it.parentData, () => gen.assign(data2, (0, codegen_12._)`${it.parentData}[${it.parentDataProperty}]`));
1837
- }
1838
- function addErrs(cxt, errs) {
1839
- const { gen } = cxt;
1840
- gen.if((0, codegen_12._)`Array.isArray(${errs})`, () => {
1841
- gen.assign(names_12.default.vErrors, (0, codegen_12._)`${names_12.default.vErrors} === null ? ${errs} : ${names_12.default.vErrors}.concat(${errs})`).assign(names_12.default.errors, (0, codegen_12._)`${names_12.default.vErrors}.length`);
1842
- (0, errors_12.extendErrors)(cxt);
1843
- }, () => cxt.error());
1844
- }
1845
- function checkAsyncKeyword({ schemaEnv }, def2) {
1846
- if (def2.async && !schemaEnv.$async)
1847
- throw new Error("async keyword in sync schema");
1848
- }
1849
- function useKeyword(gen, keyword2, result) {
1850
- if (result === void 0)
1851
- throw new Error(`keyword "${keyword2}" failed to compile`);
1852
- return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_12.stringify)(result) });
1853
- }
1854
- function validSchemaType(schema, schemaType, allowUndefined = false) {
1855
- return !schemaType.length || schemaType.some((st) => st === "array" ? Array.isArray(schema) : st === "object" ? schema && typeof schema == "object" && !Array.isArray(schema) : typeof schema == st || allowUndefined && typeof schema == "undefined");
1856
- }
1857
- keyword$1.validSchemaType = validSchemaType;
1858
- function validateKeywordUsage({ schema, opts, self: self2, errSchemaPath }, def2, keyword2) {
1859
- if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
1860
- throw new Error("ajv implementation error");
1861
- }
1862
- const deps = def2.dependencies;
1863
- if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
1864
- throw new Error(`parent schema must have dependencies of ${keyword2}: ${deps.join(",")}`);
1865
- }
1866
- if (def2.validateSchema) {
1867
- const valid = def2.validateSchema(schema[keyword2]);
1868
- if (!valid) {
1869
- const msg = `keyword "${keyword2}" value is invalid at path "${errSchemaPath}": ` + self2.errorsText(def2.validateSchema.errors);
1870
- if (opts.validateSchema === "log")
1871
- self2.logger.error(msg);
1872
- else
1873
- throw new Error(msg);
1874
- }
1796
+ function validateAsync() {
1797
+ const ruleErrs = gen.let("ruleErrs", null);
1798
+ gen.try(() => assignValid((0, codegen_1$p._)`await `), (e) => gen.assign(valid, false).if((0, codegen_1$p._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1$p._)`${e}.errors`), () => gen.throw(e)));
1799
+ return ruleErrs;
1800
+ }
1801
+ function validateSync() {
1802
+ const validateErrs = (0, codegen_1$p._)`${validateRef}.errors`;
1803
+ gen.assign(validateErrs, null);
1804
+ assignValid(codegen_1$p.nil);
1805
+ return validateErrs;
1806
+ }
1807
+ function assignValid(_await = def2.async ? (0, codegen_1$p._)`await ` : codegen_1$p.nil) {
1808
+ const passCxt = it.opts.passContext ? names_1$4.default.this : names_1$4.default.self;
1809
+ const passSchema = !("compile" in def2 && !$data || def2.schema === false);
1810
+ gen.assign(valid, (0, codegen_1$p._)`${_await}${(0, code_1$9.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def2.modifying);
1811
+ }
1812
+ function reportErrs(errors2) {
1813
+ var _a2;
1814
+ gen.if((0, codegen_1$p.not)((_a2 = def2.valid) !== null && _a2 !== void 0 ? _a2 : valid), errors2);
1815
+ }
1816
+ }
1817
+ keyword$1.funcKeywordCode = funcKeywordCode;
1818
+ function modifyData(cxt) {
1819
+ const { gen, data: data2, it } = cxt;
1820
+ gen.if(it.parentData, () => gen.assign(data2, (0, codegen_1$p._)`${it.parentData}[${it.parentDataProperty}]`));
1821
+ }
1822
+ function addErrs(cxt, errs) {
1823
+ const { gen } = cxt;
1824
+ gen.if((0, codegen_1$p._)`Array.isArray(${errs})`, () => {
1825
+ gen.assign(names_1$4.default.vErrors, (0, codegen_1$p._)`${names_1$4.default.vErrors} === null ? ${errs} : ${names_1$4.default.vErrors}.concat(${errs})`).assign(names_1$4.default.errors, (0, codegen_1$p._)`${names_1$4.default.vErrors}.length`);
1826
+ (0, errors_1$1.extendErrors)(cxt);
1827
+ }, () => cxt.error());
1828
+ }
1829
+ function checkAsyncKeyword({ schemaEnv }, def2) {
1830
+ if (def2.async && !schemaEnv.$async)
1831
+ throw new Error("async keyword in sync schema");
1832
+ }
1833
+ function useKeyword(gen, keyword2, result) {
1834
+ if (result === void 0)
1835
+ throw new Error(`keyword "${keyword2}" failed to compile`);
1836
+ return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_1$p.stringify)(result) });
1837
+ }
1838
+ function validSchemaType(schema, schemaType, allowUndefined = false) {
1839
+ return !schemaType.length || schemaType.some((st) => st === "array" ? Array.isArray(schema) : st === "object" ? schema && typeof schema == "object" && !Array.isArray(schema) : typeof schema == st || allowUndefined && typeof schema == "undefined");
1840
+ }
1841
+ keyword$1.validSchemaType = validSchemaType;
1842
+ function validateKeywordUsage({ schema, opts, self: self2, errSchemaPath }, def2, keyword2) {
1843
+ if (Array.isArray(def2.keyword) ? !def2.keyword.includes(keyword2) : def2.keyword !== keyword2) {
1844
+ throw new Error("ajv implementation error");
1845
+ }
1846
+ const deps = def2.dependencies;
1847
+ if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
1848
+ throw new Error(`parent schema must have dependencies of ${keyword2}: ${deps.join(",")}`);
1849
+ }
1850
+ if (def2.validateSchema) {
1851
+ const valid = def2.validateSchema(schema[keyword2]);
1852
+ if (!valid) {
1853
+ const msg = `keyword "${keyword2}" value is invalid at path "${errSchemaPath}": ` + self2.errorsText(def2.validateSchema.errors);
1854
+ if (opts.validateSchema === "log")
1855
+ self2.logger.error(msg);
1856
+ else
1857
+ throw new Error(msg);
1875
1858
  }
1876
1859
  }
1877
- keyword$1.validateKeywordUsage = validateKeywordUsage;
1878
- return keyword$1;
1879
1860
  }
1861
+ keyword$1.validateKeywordUsage = validateKeywordUsage;
1880
1862
  var subschema = {};
1881
- var hasRequiredSubschema;
1882
- function requireSubschema() {
1883
- if (hasRequiredSubschema) return subschema;
1884
- hasRequiredSubschema = 1;
1885
- Object.defineProperty(subschema, "__esModule", { value: true });
1886
- subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
1887
- const codegen_12 = codegen;
1888
- const util_12 = util$7;
1889
- function getSubschema(it, { keyword: keyword2, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
1890
- if (keyword2 !== void 0 && schema !== void 0) {
1891
- throw new Error('both "keyword" and "schema" passed, only one allowed');
1892
- }
1893
- if (keyword2 !== void 0) {
1894
- const sch = it.schema[keyword2];
1895
- return schemaProp === void 0 ? {
1896
- schema: sch,
1897
- schemaPath: (0, codegen_12._)`${it.schemaPath}${(0, codegen_12.getProperty)(keyword2)}`,
1898
- errSchemaPath: `${it.errSchemaPath}/${keyword2}`
1899
- } : {
1900
- schema: sch[schemaProp],
1901
- schemaPath: (0, codegen_12._)`${it.schemaPath}${(0, codegen_12.getProperty)(keyword2)}${(0, codegen_12.getProperty)(schemaProp)}`,
1902
- errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_12.escapeFragment)(schemaProp)}`
1903
- };
1904
- }
1905
- if (schema !== void 0) {
1906
- if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
1907
- throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
1908
- }
1909
- return {
1910
- schema,
1911
- schemaPath,
1912
- topSchemaRef,
1913
- errSchemaPath
1914
- };
1863
+ Object.defineProperty(subschema, "__esModule", { value: true });
1864
+ subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
1865
+ const codegen_1$o = codegen;
1866
+ const util_1$n = util$7;
1867
+ function getSubschema(it, { keyword: keyword2, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
1868
+ if (keyword2 !== void 0 && schema !== void 0) {
1869
+ throw new Error('both "keyword" and "schema" passed, only one allowed');
1870
+ }
1871
+ if (keyword2 !== void 0) {
1872
+ const sch = it.schema[keyword2];
1873
+ return schemaProp === void 0 ? {
1874
+ schema: sch,
1875
+ schemaPath: (0, codegen_1$o._)`${it.schemaPath}${(0, codegen_1$o.getProperty)(keyword2)}`,
1876
+ errSchemaPath: `${it.errSchemaPath}/${keyword2}`
1877
+ } : {
1878
+ schema: sch[schemaProp],
1879
+ schemaPath: (0, codegen_1$o._)`${it.schemaPath}${(0, codegen_1$o.getProperty)(keyword2)}${(0, codegen_1$o.getProperty)(schemaProp)}`,
1880
+ errSchemaPath: `${it.errSchemaPath}/${keyword2}/${(0, util_1$n.escapeFragment)(schemaProp)}`
1881
+ };
1882
+ }
1883
+ if (schema !== void 0) {
1884
+ if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) {
1885
+ throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
1915
1886
  }
1916
- throw new Error('either "keyword" or "schema" must be passed');
1917
- }
1918
- subschema.getSubschema = getSubschema;
1919
- function extendSubschemaData(subschema2, it, { dataProp, dataPropType: dpType, data: data2, dataTypes, propertyName }) {
1920
- if (data2 !== void 0 && dataProp !== void 0) {
1921
- throw new Error('both "data" and "dataProp" passed, only one allowed');
1922
- }
1923
- const { gen } = it;
1924
- if (dataProp !== void 0) {
1925
- const { errorPath, dataPathArr, opts } = it;
1926
- const nextData = gen.let("data", (0, codegen_12._)`${it.data}${(0, codegen_12.getProperty)(dataProp)}`, true);
1927
- dataContextProps(nextData);
1928
- subschema2.errorPath = (0, codegen_12.str)`${errorPath}${(0, util_12.getErrorPath)(dataProp, dpType, opts.jsPropertySyntax)}`;
1929
- subschema2.parentDataProperty = (0, codegen_12._)`${dataProp}`;
1930
- subschema2.dataPathArr = [...dataPathArr, subschema2.parentDataProperty];
1931
- }
1932
- if (data2 !== void 0) {
1933
- const nextData = data2 instanceof codegen_12.Name ? data2 : gen.let("data", data2, true);
1934
- dataContextProps(nextData);
1935
- if (propertyName !== void 0)
1936
- subschema2.propertyName = propertyName;
1937
- }
1938
- if (dataTypes)
1939
- subschema2.dataTypes = dataTypes;
1940
- function dataContextProps(_nextData) {
1941
- subschema2.data = _nextData;
1942
- subschema2.dataLevel = it.dataLevel + 1;
1943
- subschema2.dataTypes = [];
1944
- it.definedProperties = /* @__PURE__ */ new Set();
1945
- subschema2.parentData = it.data;
1946
- subschema2.dataNames = [...it.dataNames, _nextData];
1947
- }
1948
- }
1949
- subschema.extendSubschemaData = extendSubschemaData;
1950
- function extendSubschemaMode(subschema2, { jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors }) {
1951
- if (compositeRule !== void 0)
1952
- subschema2.compositeRule = compositeRule;
1953
- if (createErrors !== void 0)
1954
- subschema2.createErrors = createErrors;
1955
- if (allErrors !== void 0)
1956
- subschema2.allErrors = allErrors;
1957
- subschema2.jtdDiscriminator = jtdDiscriminator;
1958
- subschema2.jtdMetadata = jtdMetadata;
1959
- }
1960
- subschema.extendSubschemaMode = extendSubschemaMode;
1961
- return subschema;
1962
- }
1887
+ return {
1888
+ schema,
1889
+ schemaPath,
1890
+ topSchemaRef,
1891
+ errSchemaPath
1892
+ };
1893
+ }
1894
+ throw new Error('either "keyword" or "schema" must be passed');
1895
+ }
1896
+ subschema.getSubschema = getSubschema;
1897
+ function extendSubschemaData(subschema2, it, { dataProp, dataPropType: dpType, data: data2, dataTypes, propertyName }) {
1898
+ if (data2 !== void 0 && dataProp !== void 0) {
1899
+ throw new Error('both "data" and "dataProp" passed, only one allowed');
1900
+ }
1901
+ const { gen } = it;
1902
+ if (dataProp !== void 0) {
1903
+ const { errorPath, dataPathArr, opts } = it;
1904
+ const nextData = gen.let("data", (0, codegen_1$o._)`${it.data}${(0, codegen_1$o.getProperty)(dataProp)}`, true);
1905
+ dataContextProps(nextData);
1906
+ subschema2.errorPath = (0, codegen_1$o.str)`${errorPath}${(0, util_1$n.getErrorPath)(dataProp, dpType, opts.jsPropertySyntax)}`;
1907
+ subschema2.parentDataProperty = (0, codegen_1$o._)`${dataProp}`;
1908
+ subschema2.dataPathArr = [...dataPathArr, subschema2.parentDataProperty];
1909
+ }
1910
+ if (data2 !== void 0) {
1911
+ const nextData = data2 instanceof codegen_1$o.Name ? data2 : gen.let("data", data2, true);
1912
+ dataContextProps(nextData);
1913
+ if (propertyName !== void 0)
1914
+ subschema2.propertyName = propertyName;
1915
+ }
1916
+ if (dataTypes)
1917
+ subschema2.dataTypes = dataTypes;
1918
+ function dataContextProps(_nextData) {
1919
+ subschema2.data = _nextData;
1920
+ subschema2.dataLevel = it.dataLevel + 1;
1921
+ subschema2.dataTypes = [];
1922
+ it.definedProperties = /* @__PURE__ */ new Set();
1923
+ subschema2.parentData = it.data;
1924
+ subschema2.dataNames = [...it.dataNames, _nextData];
1925
+ }
1926
+ }
1927
+ subschema.extendSubschemaData = extendSubschemaData;
1928
+ function extendSubschemaMode(subschema2, { jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors }) {
1929
+ if (compositeRule !== void 0)
1930
+ subschema2.compositeRule = compositeRule;
1931
+ if (createErrors !== void 0)
1932
+ subschema2.createErrors = createErrors;
1933
+ if (allErrors !== void 0)
1934
+ subschema2.allErrors = allErrors;
1935
+ subschema2.jtdDiscriminator = jtdDiscriminator;
1936
+ subschema2.jtdMetadata = jtdMetadata;
1937
+ }
1938
+ subschema.extendSubschemaMode = extendSubschemaMode;
1963
1939
  var resolve$6 = {};
1964
1940
  var fastDeepEqual = function equal(a, b) {
1965
1941
  if (a === b) return true;
@@ -2074,7 +2050,7 @@ function escapeJsonPtr$1(str) {
2074
2050
  var jsonSchemaTraverseExports$1 = jsonSchemaTraverse$1.exports;
2075
2051
  Object.defineProperty(resolve$6, "__esModule", { value: true });
2076
2052
  resolve$6.getSchemaRefs = resolve$6.resolveUrl = resolve$6.normalizeId = resolve$6._getFullPath = resolve$6.getFullPath = resolve$6.inlineRef = void 0;
2077
- const util_1$l = util$7;
2053
+ const util_1$m = util$7;
2078
2054
  const equal$5 = fastDeepEqual;
2079
2055
  const traverse$2 = jsonSchemaTraverseExports$1;
2080
2056
  const SIMPLE_INLINED$1 = /* @__PURE__ */ new Set([
@@ -2133,7 +2109,7 @@ function countKeys$1(schema) {
2133
2109
  if (SIMPLE_INLINED$1.has(key))
2134
2110
  continue;
2135
2111
  if (typeof schema[key] == "object") {
2136
- (0, util_1$l.eachItem)(schema[key], (sch) => count += countKeys$1(sch));
2112
+ (0, util_1$m.eachItem)(schema[key], (sch) => count += countKeys$1(sch));
2137
2113
  }
2138
2114
  if (count === Infinity)
2139
2115
  return Infinity;
@@ -2221,528 +2197,516 @@ function getSchemaRefs(schema, baseId) {
2221
2197
  }
2222
2198
  }
2223
2199
  resolve$6.getSchemaRefs = getSchemaRefs;
2224
- var hasRequiredValidate;
2225
- function requireValidate() {
2226
- if (hasRequiredValidate) return validate$2;
2227
- hasRequiredValidate = 1;
2228
- Object.defineProperty(validate$2, "__esModule", { value: true });
2229
- validate$2.getData = validate$2.KeywordCxt = validate$2.validateFunctionCode = void 0;
2230
- const boolSchema_1 = requireBoolSchema();
2231
- const dataType_12 = dataType;
2232
- const applicability_12 = applicability;
2233
- const dataType_2 = dataType;
2234
- const defaults_1 = requireDefaults();
2235
- const keyword_1 = requireKeyword();
2236
- const subschema_1 = requireSubschema();
2237
- const codegen_12 = codegen;
2238
- const names_12 = names$1;
2239
- const resolve_12 = resolve$6;
2240
- const util_12 = util$7;
2241
- const errors_12 = errors;
2242
- function validateFunctionCode(it) {
2243
- if (isSchemaObj(it)) {
2244
- checkKeywords(it);
2245
- if (schemaCxtHasRules(it)) {
2246
- topSchemaObjCode(it);
2247
- return;
2248
- }
2200
+ Object.defineProperty(validate$2, "__esModule", { value: true });
2201
+ validate$2.getData = validate$2.KeywordCxt = validate$2.validateFunctionCode = void 0;
2202
+ const boolSchema_1 = boolSchema;
2203
+ const dataType_1$1 = dataType;
2204
+ const applicability_1 = applicability;
2205
+ const dataType_2 = dataType;
2206
+ const defaults_1 = defaults;
2207
+ const keyword_1 = keyword$1;
2208
+ const subschema_1 = subschema;
2209
+ const codegen_1$n = codegen;
2210
+ const names_1$3 = names$1;
2211
+ const resolve_1$3 = resolve$6;
2212
+ const util_1$l = util$7;
2213
+ const errors_1 = errors;
2214
+ function validateFunctionCode(it) {
2215
+ if (isSchemaObj(it)) {
2216
+ checkKeywords(it);
2217
+ if (schemaCxtHasRules(it)) {
2218
+ topSchemaObjCode(it);
2219
+ return;
2249
2220
  }
2250
- validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
2251
2221
  }
2252
- validate$2.validateFunctionCode = validateFunctionCode;
2253
- function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
2254
- if (opts.code.es5) {
2255
- gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${names_12.default.valCxt}`, schemaEnv.$async, () => {
2256
- gen.code((0, codegen_12._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
2257
- destructureValCxtES5(gen, opts);
2258
- gen.code(body);
2259
- });
2260
- } else {
2261
- gen.func(validateName, (0, codegen_12._)`${names_12.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
2262
- }
2263
- }
2264
- function destructureValCxt(opts) {
2265
- return (0, codegen_12._)`{${names_12.default.instancePath}="", ${names_12.default.parentData}, ${names_12.default.parentDataProperty}, ${names_12.default.rootData}=${names_12.default.data}${opts.dynamicRef ? (0, codegen_12._)`, ${names_12.default.dynamicAnchors}={}` : codegen_12.nil}}={}`;
2266
- }
2267
- function destructureValCxtES5(gen, opts) {
2268
- gen.if(names_12.default.valCxt, () => {
2269
- gen.var(names_12.default.instancePath, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.instancePath}`);
2270
- gen.var(names_12.default.parentData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentData}`);
2271
- gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.parentDataProperty}`);
2272
- gen.var(names_12.default.rootData, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.rootData}`);
2273
- if (opts.dynamicRef)
2274
- gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`${names_12.default.valCxt}.${names_12.default.dynamicAnchors}`);
2275
- }, () => {
2276
- gen.var(names_12.default.instancePath, (0, codegen_12._)`""`);
2277
- gen.var(names_12.default.parentData, (0, codegen_12._)`undefined`);
2278
- gen.var(names_12.default.parentDataProperty, (0, codegen_12._)`undefined`);
2279
- gen.var(names_12.default.rootData, names_12.default.data);
2280
- if (opts.dynamicRef)
2281
- gen.var(names_12.default.dynamicAnchors, (0, codegen_12._)`{}`);
2282
- });
2283
- }
2284
- function topSchemaObjCode(it) {
2285
- const { schema, opts, gen } = it;
2286
- validateFunction(it, () => {
2287
- if (opts.$comment && schema.$comment)
2288
- commentKeyword(it);
2289
- checkNoDefault(it);
2290
- gen.let(names_12.default.vErrors, null);
2291
- gen.let(names_12.default.errors, 0);
2292
- if (opts.unevaluated)
2293
- resetEvaluated(it);
2294
- typeAndKeywords(it);
2295
- returnResults(it);
2222
+ validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
2223
+ }
2224
+ validate$2.validateFunctionCode = validateFunctionCode;
2225
+ function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
2226
+ if (opts.code.es5) {
2227
+ gen.func(validateName, (0, codegen_1$n._)`${names_1$3.default.data}, ${names_1$3.default.valCxt}`, schemaEnv.$async, () => {
2228
+ gen.code((0, codegen_1$n._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
2229
+ destructureValCxtES5(gen, opts);
2230
+ gen.code(body);
2296
2231
  });
2297
- return;
2298
- }
2299
- function resetEvaluated(it) {
2300
- const { gen, validateName } = it;
2301
- it.evaluated = gen.const("evaluated", (0, codegen_12._)`${validateName}.evaluated`);
2302
- gen.if((0, codegen_12._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_12._)`${it.evaluated}.props`, (0, codegen_12._)`undefined`));
2303
- gen.if((0, codegen_12._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_12._)`${it.evaluated}.items`, (0, codegen_12._)`undefined`));
2304
- }
2305
- function funcSourceUrl(schema, opts) {
2306
- const schId = typeof schema == "object" && schema[opts.schemaId];
2307
- return schId && (opts.code.source || opts.code.process) ? (0, codegen_12._)`/*# sourceURL=${schId} */` : codegen_12.nil;
2308
- }
2309
- function subschemaCode(it, valid) {
2310
- if (isSchemaObj(it)) {
2311
- checkKeywords(it);
2312
- if (schemaCxtHasRules(it)) {
2313
- subSchemaObjCode(it, valid);
2314
- return;
2315
- }
2316
- }
2317
- (0, boolSchema_1.boolOrEmptySchema)(it, valid);
2318
- }
2319
- function schemaCxtHasRules({ schema, self: self2 }) {
2320
- if (typeof schema == "boolean")
2321
- return !schema;
2322
- for (const key in schema)
2323
- if (self2.RULES.all[key])
2324
- return true;
2325
- return false;
2326
- }
2327
- function isSchemaObj(it) {
2328
- return typeof it.schema != "boolean";
2329
- }
2330
- function subSchemaObjCode(it, valid) {
2331
- const { schema, gen, opts } = it;
2232
+ } else {
2233
+ gen.func(validateName, (0, codegen_1$n._)`${names_1$3.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
2234
+ }
2235
+ }
2236
+ function destructureValCxt(opts) {
2237
+ return (0, codegen_1$n._)`{${names_1$3.default.instancePath}="", ${names_1$3.default.parentData}, ${names_1$3.default.parentDataProperty}, ${names_1$3.default.rootData}=${names_1$3.default.data}${opts.dynamicRef ? (0, codegen_1$n._)`, ${names_1$3.default.dynamicAnchors}={}` : codegen_1$n.nil}}={}`;
2238
+ }
2239
+ function destructureValCxtES5(gen, opts) {
2240
+ gen.if(names_1$3.default.valCxt, () => {
2241
+ gen.var(names_1$3.default.instancePath, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.instancePath}`);
2242
+ gen.var(names_1$3.default.parentData, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.parentData}`);
2243
+ gen.var(names_1$3.default.parentDataProperty, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.parentDataProperty}`);
2244
+ gen.var(names_1$3.default.rootData, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.rootData}`);
2245
+ if (opts.dynamicRef)
2246
+ gen.var(names_1$3.default.dynamicAnchors, (0, codegen_1$n._)`${names_1$3.default.valCxt}.${names_1$3.default.dynamicAnchors}`);
2247
+ }, () => {
2248
+ gen.var(names_1$3.default.instancePath, (0, codegen_1$n._)`""`);
2249
+ gen.var(names_1$3.default.parentData, (0, codegen_1$n._)`undefined`);
2250
+ gen.var(names_1$3.default.parentDataProperty, (0, codegen_1$n._)`undefined`);
2251
+ gen.var(names_1$3.default.rootData, names_1$3.default.data);
2252
+ if (opts.dynamicRef)
2253
+ gen.var(names_1$3.default.dynamicAnchors, (0, codegen_1$n._)`{}`);
2254
+ });
2255
+ }
2256
+ function topSchemaObjCode(it) {
2257
+ const { schema, opts, gen } = it;
2258
+ validateFunction(it, () => {
2332
2259
  if (opts.$comment && schema.$comment)
2333
2260
  commentKeyword(it);
2334
- updateContext(it);
2335
- checkAsyncSchema(it);
2336
- const errsCount = gen.const("_errs", names_12.default.errors);
2337
- typeAndKeywords(it, errsCount);
2338
- gen.var(valid, (0, codegen_12._)`${errsCount} === ${names_12.default.errors}`);
2339
- }
2340
- function checkKeywords(it) {
2341
- (0, util_12.checkUnknownRules)(it);
2342
- checkRefsAndKeywords(it);
2343
- }
2344
- function typeAndKeywords(it, errsCount) {
2345
- if (it.opts.jtd)
2346
- return schemaKeywords(it, [], false, errsCount);
2347
- const types2 = (0, dataType_12.getSchemaTypes)(it.schema);
2348
- const checkedTypes = (0, dataType_12.coerceAndCheckDataType)(it, types2);
2349
- schemaKeywords(it, types2, !checkedTypes, errsCount);
2350
- }
2351
- function checkRefsAndKeywords(it) {
2352
- const { schema, errSchemaPath, opts, self: self2 } = it;
2353
- if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_12.schemaHasRulesButRef)(schema, self2.RULES)) {
2354
- self2.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
2355
- }
2356
- }
2357
- function checkNoDefault(it) {
2358
- const { schema, opts } = it;
2359
- if (schema.default !== void 0 && opts.useDefaults && opts.strictSchema) {
2360
- (0, util_12.checkStrictMode)(it, "default is ignored in the schema root");
2261
+ checkNoDefault(it);
2262
+ gen.let(names_1$3.default.vErrors, null);
2263
+ gen.let(names_1$3.default.errors, 0);
2264
+ if (opts.unevaluated)
2265
+ resetEvaluated(it);
2266
+ typeAndKeywords(it);
2267
+ returnResults(it);
2268
+ });
2269
+ return;
2270
+ }
2271
+ function resetEvaluated(it) {
2272
+ const { gen, validateName } = it;
2273
+ it.evaluated = gen.const("evaluated", (0, codegen_1$n._)`${validateName}.evaluated`);
2274
+ gen.if((0, codegen_1$n._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_1$n._)`${it.evaluated}.props`, (0, codegen_1$n._)`undefined`));
2275
+ gen.if((0, codegen_1$n._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_1$n._)`${it.evaluated}.items`, (0, codegen_1$n._)`undefined`));
2276
+ }
2277
+ function funcSourceUrl(schema, opts) {
2278
+ const schId = typeof schema == "object" && schema[opts.schemaId];
2279
+ return schId && (opts.code.source || opts.code.process) ? (0, codegen_1$n._)`/*# sourceURL=${schId} */` : codegen_1$n.nil;
2280
+ }
2281
+ function subschemaCode(it, valid) {
2282
+ if (isSchemaObj(it)) {
2283
+ checkKeywords(it);
2284
+ if (schemaCxtHasRules(it)) {
2285
+ subSchemaObjCode(it, valid);
2286
+ return;
2361
2287
  }
2362
2288
  }
2363
- function updateContext(it) {
2364
- const schId = it.schema[it.opts.schemaId];
2365
- if (schId)
2366
- it.baseId = (0, resolve_12.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
2367
- }
2368
- function checkAsyncSchema(it) {
2369
- if (it.schema.$async && !it.schemaEnv.$async)
2370
- throw new Error("async schema in sync schema");
2371
- }
2372
- function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
2373
- const msg = schema.$comment;
2374
- if (opts.$comment === true) {
2375
- gen.code((0, codegen_12._)`${names_12.default.self}.logger.log(${msg})`);
2376
- } else if (typeof opts.$comment == "function") {
2377
- const schemaPath = (0, codegen_12.str)`${errSchemaPath}/$comment`;
2378
- const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
2379
- gen.code((0, codegen_12._)`${names_12.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
2380
- }
2289
+ (0, boolSchema_1.boolOrEmptySchema)(it, valid);
2290
+ }
2291
+ function schemaCxtHasRules({ schema, self: self2 }) {
2292
+ if (typeof schema == "boolean")
2293
+ return !schema;
2294
+ for (const key in schema)
2295
+ if (self2.RULES.all[key])
2296
+ return true;
2297
+ return false;
2298
+ }
2299
+ function isSchemaObj(it) {
2300
+ return typeof it.schema != "boolean";
2301
+ }
2302
+ function subSchemaObjCode(it, valid) {
2303
+ const { schema, gen, opts } = it;
2304
+ if (opts.$comment && schema.$comment)
2305
+ commentKeyword(it);
2306
+ updateContext(it);
2307
+ checkAsyncSchema(it);
2308
+ const errsCount = gen.const("_errs", names_1$3.default.errors);
2309
+ typeAndKeywords(it, errsCount);
2310
+ gen.var(valid, (0, codegen_1$n._)`${errsCount} === ${names_1$3.default.errors}`);
2311
+ }
2312
+ function checkKeywords(it) {
2313
+ (0, util_1$l.checkUnknownRules)(it);
2314
+ checkRefsAndKeywords(it);
2315
+ }
2316
+ function typeAndKeywords(it, errsCount) {
2317
+ if (it.opts.jtd)
2318
+ return schemaKeywords(it, [], false, errsCount);
2319
+ const types2 = (0, dataType_1$1.getSchemaTypes)(it.schema);
2320
+ const checkedTypes = (0, dataType_1$1.coerceAndCheckDataType)(it, types2);
2321
+ schemaKeywords(it, types2, !checkedTypes, errsCount);
2322
+ }
2323
+ function checkRefsAndKeywords(it) {
2324
+ const { schema, errSchemaPath, opts, self: self2 } = it;
2325
+ if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_1$l.schemaHasRulesButRef)(schema, self2.RULES)) {
2326
+ self2.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
2327
+ }
2328
+ }
2329
+ function checkNoDefault(it) {
2330
+ const { schema, opts } = it;
2331
+ if (schema.default !== void 0 && opts.useDefaults && opts.strictSchema) {
2332
+ (0, util_1$l.checkStrictMode)(it, "default is ignored in the schema root");
2333
+ }
2334
+ }
2335
+ function updateContext(it) {
2336
+ const schId = it.schema[it.opts.schemaId];
2337
+ if (schId)
2338
+ it.baseId = (0, resolve_1$3.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
2339
+ }
2340
+ function checkAsyncSchema(it) {
2341
+ if (it.schema.$async && !it.schemaEnv.$async)
2342
+ throw new Error("async schema in sync schema");
2343
+ }
2344
+ function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
2345
+ const msg = schema.$comment;
2346
+ if (opts.$comment === true) {
2347
+ gen.code((0, codegen_1$n._)`${names_1$3.default.self}.logger.log(${msg})`);
2348
+ } else if (typeof opts.$comment == "function") {
2349
+ const schemaPath = (0, codegen_1$n.str)`${errSchemaPath}/$comment`;
2350
+ const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
2351
+ gen.code((0, codegen_1$n._)`${names_1$3.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
2352
+ }
2353
+ }
2354
+ function returnResults(it) {
2355
+ const { gen, schemaEnv, validateName, ValidationError: ValidationError3, opts } = it;
2356
+ if (schemaEnv.$async) {
2357
+ gen.if((0, codegen_1$n._)`${names_1$3.default.errors} === 0`, () => gen.return(names_1$3.default.data), () => gen.throw((0, codegen_1$n._)`new ${ValidationError3}(${names_1$3.default.vErrors})`));
2358
+ } else {
2359
+ gen.assign((0, codegen_1$n._)`${validateName}.errors`, names_1$3.default.vErrors);
2360
+ if (opts.unevaluated)
2361
+ assignEvaluated(it);
2362
+ gen.return((0, codegen_1$n._)`${names_1$3.default.errors} === 0`);
2363
+ }
2364
+ }
2365
+ function assignEvaluated({ gen, evaluated, props, items: items2 }) {
2366
+ if (props instanceof codegen_1$n.Name)
2367
+ gen.assign((0, codegen_1$n._)`${evaluated}.props`, props);
2368
+ if (items2 instanceof codegen_1$n.Name)
2369
+ gen.assign((0, codegen_1$n._)`${evaluated}.items`, items2);
2370
+ }
2371
+ function schemaKeywords(it, types2, typeErrors, errsCount) {
2372
+ const { gen, schema, data: data2, allErrors, opts, self: self2 } = it;
2373
+ const { RULES } = self2;
2374
+ if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_1$l.schemaHasRulesButRef)(schema, RULES))) {
2375
+ gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
2376
+ return;
2381
2377
  }
2382
- function returnResults(it) {
2383
- const { gen, schemaEnv, validateName, ValidationError: ValidationError2, opts } = it;
2384
- if (schemaEnv.$async) {
2385
- gen.if((0, codegen_12._)`${names_12.default.errors} === 0`, () => gen.return(names_12.default.data), () => gen.throw((0, codegen_12._)`new ${ValidationError2}(${names_12.default.vErrors})`));
2386
- } else {
2387
- gen.assign((0, codegen_12._)`${validateName}.errors`, names_12.default.vErrors);
2388
- if (opts.unevaluated)
2389
- assignEvaluated(it);
2390
- gen.return((0, codegen_12._)`${names_12.default.errors} === 0`);
2391
- }
2392
- }
2393
- function assignEvaluated({ gen, evaluated, props, items: items2 }) {
2394
- if (props instanceof codegen_12.Name)
2395
- gen.assign((0, codegen_12._)`${evaluated}.props`, props);
2396
- if (items2 instanceof codegen_12.Name)
2397
- gen.assign((0, codegen_12._)`${evaluated}.items`, items2);
2398
- }
2399
- function schemaKeywords(it, types2, typeErrors, errsCount) {
2400
- const { gen, schema, data: data2, allErrors, opts, self: self2 } = it;
2401
- const { RULES } = self2;
2402
- if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_12.schemaHasRulesButRef)(schema, RULES))) {
2403
- gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
2378
+ if (!opts.jtd)
2379
+ checkStrictTypes(it, types2);
2380
+ gen.block(() => {
2381
+ for (const group of RULES.rules)
2382
+ groupKeywords(group);
2383
+ groupKeywords(RULES.post);
2384
+ });
2385
+ function groupKeywords(group) {
2386
+ if (!(0, applicability_1.shouldUseGroup)(schema, group))
2404
2387
  return;
2405
- }
2406
- if (!opts.jtd)
2407
- checkStrictTypes(it, types2);
2408
- gen.block(() => {
2409
- for (const group of RULES.rules)
2410
- groupKeywords(group);
2411
- groupKeywords(RULES.post);
2412
- });
2413
- function groupKeywords(group) {
2414
- if (!(0, applicability_12.shouldUseGroup)(schema, group))
2415
- return;
2416
- if (group.type) {
2417
- gen.if((0, dataType_2.checkDataType)(group.type, data2, opts.strictNumbers));
2418
- iterateKeywords(it, group);
2419
- if (types2.length === 1 && types2[0] === group.type && typeErrors) {
2420
- gen.else();
2421
- (0, dataType_2.reportTypeError)(it);
2422
- }
2423
- gen.endIf();
2424
- } else {
2425
- iterateKeywords(it, group);
2388
+ if (group.type) {
2389
+ gen.if((0, dataType_2.checkDataType)(group.type, data2, opts.strictNumbers));
2390
+ iterateKeywords(it, group);
2391
+ if (types2.length === 1 && types2[0] === group.type && typeErrors) {
2392
+ gen.else();
2393
+ (0, dataType_2.reportTypeError)(it);
2426
2394
  }
2427
- if (!allErrors)
2428
- gen.if((0, codegen_12._)`${names_12.default.errors} === ${errsCount || 0}`);
2395
+ gen.endIf();
2396
+ } else {
2397
+ iterateKeywords(it, group);
2429
2398
  }
2399
+ if (!allErrors)
2400
+ gen.if((0, codegen_1$n._)`${names_1$3.default.errors} === ${errsCount || 0}`);
2430
2401
  }
2431
- function iterateKeywords(it, group) {
2432
- const { gen, schema, opts: { useDefaults } } = it;
2433
- if (useDefaults)
2434
- (0, defaults_1.assignDefaults)(it, group.type);
2435
- gen.block(() => {
2436
- for (const rule of group.rules) {
2437
- if ((0, applicability_12.shouldUseRule)(schema, rule)) {
2438
- keywordCode(it, rule.keyword, rule.definition, group.type);
2439
- }
2440
- }
2441
- });
2442
- }
2443
- function checkStrictTypes(it, types2) {
2444
- if (it.schemaEnv.meta || !it.opts.strictTypes)
2445
- return;
2446
- checkContextTypes(it, types2);
2447
- if (!it.opts.allowUnionTypes)
2448
- checkMultipleTypes(it, types2);
2449
- checkKeywordTypes(it, it.dataTypes);
2450
- }
2451
- function checkContextTypes(it, types2) {
2452
- if (!types2.length)
2453
- return;
2454
- if (!it.dataTypes.length) {
2455
- it.dataTypes = types2;
2456
- return;
2457
- }
2458
- types2.forEach((t) => {
2459
- if (!includesType(it.dataTypes, t)) {
2460
- strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
2461
- }
2462
- });
2463
- narrowSchemaTypes(it, types2);
2464
- }
2465
- function checkMultipleTypes(it, ts) {
2466
- if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
2467
- strictTypesError(it, "use allowUnionTypes to allow union type keyword");
2468
- }
2469
- }
2470
- function checkKeywordTypes(it, ts) {
2471
- const rules3 = it.self.RULES.all;
2472
- for (const keyword2 in rules3) {
2473
- const rule = rules3[keyword2];
2474
- if (typeof rule == "object" && (0, applicability_12.shouldUseRule)(it.schema, rule)) {
2475
- const { type: type2 } = rule.definition;
2476
- if (type2.length && !type2.some((t) => hasApplicableType(ts, t))) {
2477
- strictTypesError(it, `missing type "${type2.join(",")}" for keyword "${keyword2}"`);
2478
- }
2479
- }
2480
- }
2481
- }
2482
- function hasApplicableType(schTs, kwdT) {
2483
- return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
2484
- }
2485
- function includesType(ts, t) {
2486
- return ts.includes(t) || t === "integer" && ts.includes("number");
2487
- }
2488
- function narrowSchemaTypes(it, withTypes) {
2489
- const ts = [];
2490
- for (const t of it.dataTypes) {
2491
- if (includesType(withTypes, t))
2492
- ts.push(t);
2493
- else if (withTypes.includes("integer") && t === "number")
2494
- ts.push("integer");
2495
- }
2496
- it.dataTypes = ts;
2497
- }
2498
- function strictTypesError(it, msg) {
2499
- const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
2500
- msg += ` at "${schemaPath}" (strictTypes)`;
2501
- (0, util_12.checkStrictMode)(it, msg, it.opts.strictTypes);
2502
- }
2503
- class KeywordCxt {
2504
- constructor(it, def2, keyword2) {
2505
- (0, keyword_1.validateKeywordUsage)(it, def2, keyword2);
2506
- this.gen = it.gen;
2507
- this.allErrors = it.allErrors;
2508
- this.keyword = keyword2;
2509
- this.data = it.data;
2510
- this.schema = it.schema[keyword2];
2511
- this.$data = def2.$data && it.opts.$data && this.schema && this.schema.$data;
2512
- this.schemaValue = (0, util_12.schemaRefOrVal)(it, this.schema, keyword2, this.$data);
2513
- this.schemaType = def2.schemaType;
2514
- this.parentSchema = it.schema;
2515
- this.params = {};
2516
- this.it = it;
2517
- this.def = def2;
2518
- if (this.$data) {
2519
- this.schemaCode = it.gen.const("vSchema", getData2(this.$data, it));
2520
- } else {
2521
- this.schemaCode = this.schemaValue;
2522
- if (!(0, keyword_1.validSchemaType)(this.schema, def2.schemaType, def2.allowUndefined)) {
2523
- throw new Error(`${keyword2} value must be ${JSON.stringify(def2.schemaType)}`);
2524
- }
2525
- }
2526
- if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
2527
- this.errsCount = it.gen.const("_errs", names_12.default.errors);
2402
+ }
2403
+ function iterateKeywords(it, group) {
2404
+ const { gen, schema, opts: { useDefaults } } = it;
2405
+ if (useDefaults)
2406
+ (0, defaults_1.assignDefaults)(it, group.type);
2407
+ gen.block(() => {
2408
+ for (const rule of group.rules) {
2409
+ if ((0, applicability_1.shouldUseRule)(schema, rule)) {
2410
+ keywordCode(it, rule.keyword, rule.definition, group.type);
2528
2411
  }
2529
2412
  }
2530
- result(condition, successAction, failAction) {
2531
- this.failResult((0, codegen_12.not)(condition), successAction, failAction);
2413
+ });
2414
+ }
2415
+ function checkStrictTypes(it, types2) {
2416
+ if (it.schemaEnv.meta || !it.opts.strictTypes)
2417
+ return;
2418
+ checkContextTypes(it, types2);
2419
+ if (!it.opts.allowUnionTypes)
2420
+ checkMultipleTypes(it, types2);
2421
+ checkKeywordTypes(it, it.dataTypes);
2422
+ }
2423
+ function checkContextTypes(it, types2) {
2424
+ if (!types2.length)
2425
+ return;
2426
+ if (!it.dataTypes.length) {
2427
+ it.dataTypes = types2;
2428
+ return;
2429
+ }
2430
+ types2.forEach((t) => {
2431
+ if (!includesType(it.dataTypes, t)) {
2432
+ strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
2532
2433
  }
2533
- failResult(condition, successAction, failAction) {
2534
- this.gen.if(condition);
2535
- if (failAction)
2536
- failAction();
2537
- else
2538
- this.error();
2539
- if (successAction) {
2540
- this.gen.else();
2541
- successAction();
2542
- if (this.allErrors)
2543
- this.gen.endIf();
2544
- } else {
2545
- if (this.allErrors)
2546
- this.gen.endIf();
2547
- else
2548
- this.gen.else();
2434
+ });
2435
+ narrowSchemaTypes(it, types2);
2436
+ }
2437
+ function checkMultipleTypes(it, ts) {
2438
+ if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
2439
+ strictTypesError(it, "use allowUnionTypes to allow union type keyword");
2440
+ }
2441
+ }
2442
+ function checkKeywordTypes(it, ts) {
2443
+ const rules3 = it.self.RULES.all;
2444
+ for (const keyword2 in rules3) {
2445
+ const rule = rules3[keyword2];
2446
+ if (typeof rule == "object" && (0, applicability_1.shouldUseRule)(it.schema, rule)) {
2447
+ const { type: type2 } = rule.definition;
2448
+ if (type2.length && !type2.some((t) => hasApplicableType(ts, t))) {
2449
+ strictTypesError(it, `missing type "${type2.join(",")}" for keyword "${keyword2}"`);
2450
+ }
2451
+ }
2452
+ }
2453
+ }
2454
+ function hasApplicableType(schTs, kwdT) {
2455
+ return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
2456
+ }
2457
+ function includesType(ts, t) {
2458
+ return ts.includes(t) || t === "integer" && ts.includes("number");
2459
+ }
2460
+ function narrowSchemaTypes(it, withTypes) {
2461
+ const ts = [];
2462
+ for (const t of it.dataTypes) {
2463
+ if (includesType(withTypes, t))
2464
+ ts.push(t);
2465
+ else if (withTypes.includes("integer") && t === "number")
2466
+ ts.push("integer");
2467
+ }
2468
+ it.dataTypes = ts;
2469
+ }
2470
+ function strictTypesError(it, msg) {
2471
+ const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
2472
+ msg += ` at "${schemaPath}" (strictTypes)`;
2473
+ (0, util_1$l.checkStrictMode)(it, msg, it.opts.strictTypes);
2474
+ }
2475
+ class KeywordCxt {
2476
+ constructor(it, def2, keyword2) {
2477
+ (0, keyword_1.validateKeywordUsage)(it, def2, keyword2);
2478
+ this.gen = it.gen;
2479
+ this.allErrors = it.allErrors;
2480
+ this.keyword = keyword2;
2481
+ this.data = it.data;
2482
+ this.schema = it.schema[keyword2];
2483
+ this.$data = def2.$data && it.opts.$data && this.schema && this.schema.$data;
2484
+ this.schemaValue = (0, util_1$l.schemaRefOrVal)(it, this.schema, keyword2, this.$data);
2485
+ this.schemaType = def2.schemaType;
2486
+ this.parentSchema = it.schema;
2487
+ this.params = {};
2488
+ this.it = it;
2489
+ this.def = def2;
2490
+ if (this.$data) {
2491
+ this.schemaCode = it.gen.const("vSchema", getData$1(this.$data, it));
2492
+ } else {
2493
+ this.schemaCode = this.schemaValue;
2494
+ if (!(0, keyword_1.validSchemaType)(this.schema, def2.schemaType, def2.allowUndefined)) {
2495
+ throw new Error(`${keyword2} value must be ${JSON.stringify(def2.schemaType)}`);
2549
2496
  }
2550
2497
  }
2551
- pass(condition, failAction) {
2552
- this.failResult((0, codegen_12.not)(condition), void 0, failAction);
2498
+ if ("code" in def2 ? def2.trackErrors : def2.errors !== false) {
2499
+ this.errsCount = it.gen.const("_errs", names_1$3.default.errors);
2553
2500
  }
2554
- fail(condition) {
2555
- if (condition === void 0) {
2556
- this.error();
2557
- if (!this.allErrors)
2558
- this.gen.if(false);
2559
- return;
2560
- }
2561
- this.gen.if(condition);
2501
+ }
2502
+ result(condition, successAction, failAction) {
2503
+ this.failResult((0, codegen_1$n.not)(condition), successAction, failAction);
2504
+ }
2505
+ failResult(condition, successAction, failAction) {
2506
+ this.gen.if(condition);
2507
+ if (failAction)
2508
+ failAction();
2509
+ else
2562
2510
  this.error();
2511
+ if (successAction) {
2512
+ this.gen.else();
2513
+ successAction();
2514
+ if (this.allErrors)
2515
+ this.gen.endIf();
2516
+ } else {
2563
2517
  if (this.allErrors)
2564
2518
  this.gen.endIf();
2565
2519
  else
2566
2520
  this.gen.else();
2567
2521
  }
2568
- fail$data(condition) {
2569
- if (!this.$data)
2570
- return this.fail(condition);
2571
- const { schemaCode } = this;
2572
- this.fail((0, codegen_12._)`${schemaCode} !== undefined && (${(0, codegen_12.or)(this.invalid$data(), condition)})`);
2573
- }
2574
- error(append, errorParams, errorPaths) {
2575
- if (errorParams) {
2576
- this.setParams(errorParams);
2577
- this._error(append, errorPaths);
2578
- this.setParams({});
2579
- return;
2580
- }
2581
- this._error(append, errorPaths);
2582
- }
2583
- _error(append, errorPaths) {
2584
- (append ? errors_12.reportExtraError : errors_12.reportError)(this, this.def.error, errorPaths);
2585
- }
2586
- $dataError() {
2587
- (0, errors_12.reportError)(this, this.def.$dataError || errors_12.keyword$DataError);
2588
- }
2589
- reset() {
2590
- if (this.errsCount === void 0)
2591
- throw new Error('add "trackErrors" to keyword definition');
2592
- (0, errors_12.resetErrorsCount)(this.gen, this.errsCount);
2593
- }
2594
- ok(cond) {
2522
+ }
2523
+ pass(condition, failAction) {
2524
+ this.failResult((0, codegen_1$n.not)(condition), void 0, failAction);
2525
+ }
2526
+ fail(condition) {
2527
+ if (condition === void 0) {
2528
+ this.error();
2595
2529
  if (!this.allErrors)
2596
- this.gen.if(cond);
2530
+ this.gen.if(false);
2531
+ return;
2597
2532
  }
2598
- setParams(obj, assign) {
2599
- if (assign)
2600
- Object.assign(this.params, obj);
2601
- else
2602
- this.params = obj;
2533
+ this.gen.if(condition);
2534
+ this.error();
2535
+ if (this.allErrors)
2536
+ this.gen.endIf();
2537
+ else
2538
+ this.gen.else();
2539
+ }
2540
+ fail$data(condition) {
2541
+ if (!this.$data)
2542
+ return this.fail(condition);
2543
+ const { schemaCode } = this;
2544
+ this.fail((0, codegen_1$n._)`${schemaCode} !== undefined && (${(0, codegen_1$n.or)(this.invalid$data(), condition)})`);
2545
+ }
2546
+ error(append, errorParams, errorPaths) {
2547
+ if (errorParams) {
2548
+ this.setParams(errorParams);
2549
+ this._error(append, errorPaths);
2550
+ this.setParams({});
2551
+ return;
2603
2552
  }
2604
- block$data(valid, codeBlock, $dataValid = codegen_12.nil) {
2605
- this.gen.block(() => {
2606
- this.check$data(valid, $dataValid);
2607
- codeBlock();
2608
- });
2553
+ this._error(append, errorPaths);
2554
+ }
2555
+ _error(append, errorPaths) {
2556
+ (append ? errors_1.reportExtraError : errors_1.reportError)(this, this.def.error, errorPaths);
2557
+ }
2558
+ $dataError() {
2559
+ (0, errors_1.reportError)(this, this.def.$dataError || errors_1.keyword$DataError);
2560
+ }
2561
+ reset() {
2562
+ if (this.errsCount === void 0)
2563
+ throw new Error('add "trackErrors" to keyword definition');
2564
+ (0, errors_1.resetErrorsCount)(this.gen, this.errsCount);
2565
+ }
2566
+ ok(cond) {
2567
+ if (!this.allErrors)
2568
+ this.gen.if(cond);
2569
+ }
2570
+ setParams(obj, assign) {
2571
+ if (assign)
2572
+ Object.assign(this.params, obj);
2573
+ else
2574
+ this.params = obj;
2575
+ }
2576
+ block$data(valid, codeBlock, $dataValid = codegen_1$n.nil) {
2577
+ this.gen.block(() => {
2578
+ this.check$data(valid, $dataValid);
2579
+ codeBlock();
2580
+ });
2581
+ }
2582
+ check$data(valid = codegen_1$n.nil, $dataValid = codegen_1$n.nil) {
2583
+ if (!this.$data)
2584
+ return;
2585
+ const { gen, schemaCode, schemaType, def: def2 } = this;
2586
+ gen.if((0, codegen_1$n.or)((0, codegen_1$n._)`${schemaCode} === undefined`, $dataValid));
2587
+ if (valid !== codegen_1$n.nil)
2588
+ gen.assign(valid, true);
2589
+ if (schemaType.length || def2.validateSchema) {
2590
+ gen.elseIf(this.invalid$data());
2591
+ this.$dataError();
2592
+ if (valid !== codegen_1$n.nil)
2593
+ gen.assign(valid, false);
2609
2594
  }
2610
- check$data(valid = codegen_12.nil, $dataValid = codegen_12.nil) {
2611
- if (!this.$data)
2612
- return;
2613
- const { gen, schemaCode, schemaType, def: def2 } = this;
2614
- gen.if((0, codegen_12.or)((0, codegen_12._)`${schemaCode} === undefined`, $dataValid));
2615
- if (valid !== codegen_12.nil)
2616
- gen.assign(valid, true);
2617
- if (schemaType.length || def2.validateSchema) {
2618
- gen.elseIf(this.invalid$data());
2619
- this.$dataError();
2620
- if (valid !== codegen_12.nil)
2621
- gen.assign(valid, false);
2595
+ gen.else();
2596
+ }
2597
+ invalid$data() {
2598
+ const { gen, schemaCode, schemaType, def: def2, it } = this;
2599
+ return (0, codegen_1$n.or)(wrong$DataType(), invalid$DataSchema());
2600
+ function wrong$DataType() {
2601
+ if (schemaType.length) {
2602
+ if (!(schemaCode instanceof codegen_1$n.Name))
2603
+ throw new Error("ajv implementation error");
2604
+ const st = Array.isArray(schemaType) ? schemaType : [schemaType];
2605
+ return (0, codegen_1$n._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
2622
2606
  }
2623
- gen.else();
2607
+ return codegen_1$n.nil;
2624
2608
  }
2625
- invalid$data() {
2626
- const { gen, schemaCode, schemaType, def: def2, it } = this;
2627
- return (0, codegen_12.or)(wrong$DataType(), invalid$DataSchema());
2628
- function wrong$DataType() {
2629
- if (schemaType.length) {
2630
- if (!(schemaCode instanceof codegen_12.Name))
2631
- throw new Error("ajv implementation error");
2632
- const st = Array.isArray(schemaType) ? schemaType : [schemaType];
2633
- return (0, codegen_12._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
2634
- }
2635
- return codegen_12.nil;
2636
- }
2637
- function invalid$DataSchema() {
2638
- if (def2.validateSchema) {
2639
- const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
2640
- return (0, codegen_12._)`!${validateSchemaRef}(${schemaCode})`;
2641
- }
2642
- return codegen_12.nil;
2643
- }
2644
- }
2645
- subschema(appl, valid) {
2646
- const subschema2 = (0, subschema_1.getSubschema)(this.it, appl);
2647
- (0, subschema_1.extendSubschemaData)(subschema2, this.it, appl);
2648
- (0, subschema_1.extendSubschemaMode)(subschema2, appl);
2649
- const nextContext = { ...this.it, ...subschema2, items: void 0, props: void 0 };
2650
- subschemaCode(nextContext, valid);
2651
- return nextContext;
2652
- }
2653
- mergeEvaluated(schemaCxt, toName) {
2654
- const { it, gen } = this;
2655
- if (!it.opts.unevaluated)
2656
- return;
2657
- if (it.props !== true && schemaCxt.props !== void 0) {
2658
- it.props = util_12.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
2659
- }
2660
- if (it.items !== true && schemaCxt.items !== void 0) {
2661
- it.items = util_12.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
2609
+ function invalid$DataSchema() {
2610
+ if (def2.validateSchema) {
2611
+ const validateSchemaRef = gen.scopeValue("validate$data", { ref: def2.validateSchema });
2612
+ return (0, codegen_1$n._)`!${validateSchemaRef}(${schemaCode})`;
2662
2613
  }
2614
+ return codegen_1$n.nil;
2663
2615
  }
2664
- mergeValidEvaluated(schemaCxt, valid) {
2665
- const { it, gen } = this;
2666
- if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
2667
- gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_12.Name));
2668
- return true;
2669
- }
2616
+ }
2617
+ subschema(appl, valid) {
2618
+ const subschema2 = (0, subschema_1.getSubschema)(this.it, appl);
2619
+ (0, subschema_1.extendSubschemaData)(subschema2, this.it, appl);
2620
+ (0, subschema_1.extendSubschemaMode)(subschema2, appl);
2621
+ const nextContext = { ...this.it, ...subschema2, items: void 0, props: void 0 };
2622
+ subschemaCode(nextContext, valid);
2623
+ return nextContext;
2624
+ }
2625
+ mergeEvaluated(schemaCxt, toName) {
2626
+ const { it, gen } = this;
2627
+ if (!it.opts.unevaluated)
2628
+ return;
2629
+ if (it.props !== true && schemaCxt.props !== void 0) {
2630
+ it.props = util_1$l.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
2631
+ }
2632
+ if (it.items !== true && schemaCxt.items !== void 0) {
2633
+ it.items = util_1$l.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
2634
+ }
2635
+ }
2636
+ mergeValidEvaluated(schemaCxt, valid) {
2637
+ const { it, gen } = this;
2638
+ if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
2639
+ gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_1$n.Name));
2640
+ return true;
2670
2641
  }
2671
2642
  }
2672
- validate$2.KeywordCxt = KeywordCxt;
2673
- function keywordCode(it, keyword2, def2, ruleType) {
2674
- const cxt = new KeywordCxt(it, def2, keyword2);
2675
- if ("code" in def2) {
2676
- def2.code(cxt, ruleType);
2677
- } else if (cxt.$data && def2.validate) {
2678
- (0, keyword_1.funcKeywordCode)(cxt, def2);
2679
- } else if ("macro" in def2) {
2680
- (0, keyword_1.macroKeywordCode)(cxt, def2);
2681
- } else if (def2.compile || def2.validate) {
2682
- (0, keyword_1.funcKeywordCode)(cxt, def2);
2683
- }
2684
- }
2685
- const JSON_POINTER2 = /^\/(?:[^~]|~0|~1)*$/;
2686
- const RELATIVE_JSON_POINTER2 = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
2687
- function getData2($data, { dataLevel, dataNames, dataPathArr }) {
2688
- let jsonPointer;
2689
- let data2;
2690
- if ($data === "")
2691
- return names_12.default.rootData;
2692
- if ($data[0] === "/") {
2693
- if (!JSON_POINTER2.test($data))
2694
- throw new Error(`Invalid JSON-pointer: ${$data}`);
2695
- jsonPointer = $data;
2696
- data2 = names_12.default.rootData;
2697
- } else {
2698
- const matches = RELATIVE_JSON_POINTER2.exec($data);
2699
- if (!matches)
2700
- throw new Error(`Invalid JSON-pointer: ${$data}`);
2701
- const up = +matches[1];
2702
- jsonPointer = matches[2];
2703
- if (jsonPointer === "#") {
2704
- if (up >= dataLevel)
2705
- throw new Error(errorMsg("property/index", up));
2706
- return dataPathArr[dataLevel - up];
2707
- }
2708
- if (up > dataLevel)
2709
- throw new Error(errorMsg("data", up));
2710
- data2 = dataNames[dataLevel - up];
2711
- if (!jsonPointer)
2712
- return data2;
2713
- }
2714
- let expr = data2;
2715
- const segments = jsonPointer.split("/");
2716
- for (const segment of segments) {
2717
- if (segment) {
2718
- data2 = (0, codegen_12._)`${data2}${(0, codegen_12.getProperty)((0, util_12.unescapeJsonPointer)(segment))}`;
2719
- expr = (0, codegen_12._)`${expr} && ${data2}`;
2720
- }
2721
- }
2722
- return expr;
2723
- function errorMsg(pointerType, up) {
2724
- return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
2725
- }
2726
- }
2727
- validate$2.getData = getData2;
2728
- return validate$2;
2729
2643
  }
2730
- var validation_error = {};
2731
- var hasRequiredValidation_error;
2732
- function requireValidation_error() {
2733
- if (hasRequiredValidation_error) return validation_error;
2734
- hasRequiredValidation_error = 1;
2735
- Object.defineProperty(validation_error, "__esModule", { value: true });
2736
- class ValidationError2 extends Error {
2737
- constructor(errors2) {
2738
- super("validation failed");
2739
- this.errors = errors2;
2740
- this.ajv = this.validation = true;
2644
+ validate$2.KeywordCxt = KeywordCxt;
2645
+ function keywordCode(it, keyword2, def2, ruleType) {
2646
+ const cxt = new KeywordCxt(it, def2, keyword2);
2647
+ if ("code" in def2) {
2648
+ def2.code(cxt, ruleType);
2649
+ } else if (cxt.$data && def2.validate) {
2650
+ (0, keyword_1.funcKeywordCode)(cxt, def2);
2651
+ } else if ("macro" in def2) {
2652
+ (0, keyword_1.macroKeywordCode)(cxt, def2);
2653
+ } else if (def2.compile || def2.validate) {
2654
+ (0, keyword_1.funcKeywordCode)(cxt, def2);
2655
+ }
2656
+ }
2657
+ const JSON_POINTER$2 = /^\/(?:[^~]|~0|~1)*$/;
2658
+ const RELATIVE_JSON_POINTER$2 = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
2659
+ function getData$1($data, { dataLevel, dataNames, dataPathArr }) {
2660
+ let jsonPointer;
2661
+ let data2;
2662
+ if ($data === "")
2663
+ return names_1$3.default.rootData;
2664
+ if ($data[0] === "/") {
2665
+ if (!JSON_POINTER$2.test($data))
2666
+ throw new Error(`Invalid JSON-pointer: ${$data}`);
2667
+ jsonPointer = $data;
2668
+ data2 = names_1$3.default.rootData;
2669
+ } else {
2670
+ const matches = RELATIVE_JSON_POINTER$2.exec($data);
2671
+ if (!matches)
2672
+ throw new Error(`Invalid JSON-pointer: ${$data}`);
2673
+ const up = +matches[1];
2674
+ jsonPointer = matches[2];
2675
+ if (jsonPointer === "#") {
2676
+ if (up >= dataLevel)
2677
+ throw new Error(errorMsg("property/index", up));
2678
+ return dataPathArr[dataLevel - up];
2679
+ }
2680
+ if (up > dataLevel)
2681
+ throw new Error(errorMsg("data", up));
2682
+ data2 = dataNames[dataLevel - up];
2683
+ if (!jsonPointer)
2684
+ return data2;
2685
+ }
2686
+ let expr = data2;
2687
+ const segments = jsonPointer.split("/");
2688
+ for (const segment of segments) {
2689
+ if (segment) {
2690
+ data2 = (0, codegen_1$n._)`${data2}${(0, codegen_1$n.getProperty)((0, util_1$l.unescapeJsonPointer)(segment))}`;
2691
+ expr = (0, codegen_1$n._)`${expr} && ${data2}`;
2741
2692
  }
2742
2693
  }
2743
- validation_error.default = ValidationError2;
2744
- return validation_error;
2694
+ return expr;
2695
+ function errorMsg(pointerType, up) {
2696
+ return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
2697
+ }
2745
2698
  }
2699
+ validate$2.getData = getData$1;
2700
+ var validation_error = {};
2701
+ Object.defineProperty(validation_error, "__esModule", { value: true });
2702
+ let ValidationError$2 = class ValidationError extends Error {
2703
+ constructor(errors2) {
2704
+ super("validation failed");
2705
+ this.errors = errors2;
2706
+ this.ajv = this.validation = true;
2707
+ }
2708
+ };
2709
+ validation_error.default = ValidationError$2;
2746
2710
  var ref_error = {};
2747
2711
  Object.defineProperty(ref_error, "__esModule", { value: true });
2748
2712
  const resolve_1$2 = resolve$6;
@@ -2758,11 +2722,11 @@ var compile$2 = {};
2758
2722
  Object.defineProperty(compile$2, "__esModule", { value: true });
2759
2723
  compile$2.resolveSchema = compile$2.getCompilingSchema = compile$2.resolveRef = compile$2.compileSchema = compile$2.SchemaEnv = void 0;
2760
2724
  const codegen_1$m = codegen;
2761
- const validation_error_1 = requireValidation_error();
2725
+ const validation_error_1 = validation_error;
2762
2726
  const names_1$2 = names$1;
2763
2727
  const resolve_1$1 = resolve$6;
2764
2728
  const util_1$k = util$7;
2765
- const validate_1$1 = requireValidate();
2729
+ const validate_1$1 = validate$2;
2766
2730
  class SchemaEnv {
2767
2731
  constructor(env) {
2768
2732
  var _a;
@@ -3002,58 +2966,81 @@ const require$$9 = {
3002
2966
  };
3003
2967
  var uri$2 = {};
3004
2968
  var fastUri$1 = { exports: {} };
3005
- const isUUID$1 = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu);
3006
- 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);
3007
- function stringArrayToHexStripped(input) {
3008
- let acc = "";
3009
- let code2 = 0;
3010
- let i = 0;
3011
- for (i = 0; i < input.length; i++) {
3012
- code2 = input[i].charCodeAt(0);
3013
- if (code2 === 48) {
3014
- continue;
3015
- }
3016
- if (!(code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 70 || code2 >= 97 && code2 <= 102)) {
3017
- return "";
3018
- }
3019
- acc += input[i];
3020
- break;
3021
- }
3022
- for (i += 1; i < input.length; i++) {
3023
- code2 = input[i].charCodeAt(0);
3024
- if (!(code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 70 || code2 >= 97 && code2 <= 102)) {
3025
- return "";
3026
- }
3027
- acc += input[i];
2969
+ const HEX$1 = {
2970
+ 0: 0,
2971
+ 1: 1,
2972
+ 2: 2,
2973
+ 3: 3,
2974
+ 4: 4,
2975
+ 5: 5,
2976
+ 6: 6,
2977
+ 7: 7,
2978
+ 8: 8,
2979
+ 9: 9,
2980
+ a: 10,
2981
+ A: 10,
2982
+ b: 11,
2983
+ B: 11,
2984
+ c: 12,
2985
+ C: 12,
2986
+ d: 13,
2987
+ D: 13,
2988
+ e: 14,
2989
+ E: 14,
2990
+ f: 15,
2991
+ F: 15
2992
+ };
2993
+ var scopedChars = {
2994
+ HEX: HEX$1
2995
+ };
2996
+ const { HEX } = scopedChars;
2997
+ 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;
2998
+ function normalizeIPv4$1(host) {
2999
+ if (findToken(host, ".") < 3) {
3000
+ return { host, isIPV4: false };
3001
+ }
3002
+ const matches = host.match(IPV4_REG) || [];
3003
+ const [address] = matches;
3004
+ if (address) {
3005
+ return { host: stripLeadingZeros(address, "."), isIPV4: true };
3006
+ } else {
3007
+ return { host, isIPV4: false };
3028
3008
  }
3029
- return acc;
3030
3009
  }
3031
- const nonSimpleDomain$1 = RegExp.prototype.test.bind(/[^!"$&'()*+,\-.;=_`a-z{}~]/u);
3032
- function consumeIsZone(buffer) {
3033
- buffer.length = 0;
3034
- return true;
3035
- }
3036
- function consumeHextets(buffer, address, output) {
3037
- if (buffer.length) {
3038
- const hex = stringArrayToHexStripped(buffer);
3039
- if (hex !== "") {
3040
- address.push(hex);
3041
- } else {
3042
- output.error = true;
3043
- return false;
3044
- }
3045
- buffer.length = 0;
3010
+ function stringArrayToHexStripped(input, keepZero = false) {
3011
+ let acc = "";
3012
+ let strip = true;
3013
+ for (const c of input) {
3014
+ if (HEX[c] === void 0) return void 0;
3015
+ if (c !== "0" && strip === true) strip = false;
3016
+ if (!strip) acc += c;
3046
3017
  }
3047
- return true;
3018
+ if (keepZero && acc.length === 0) acc = "0";
3019
+ return acc;
3048
3020
  }
3049
3021
  function getIPV6(input) {
3050
3022
  let tokenCount = 0;
3051
3023
  const output = { error: false, address: "", zone: "" };
3052
3024
  const address = [];
3053
3025
  const buffer = [];
3026
+ let isZone = false;
3054
3027
  let endipv6Encountered = false;
3055
3028
  let endIpv6 = false;
3056
- let consume = consumeHextets;
3029
+ function consume() {
3030
+ if (buffer.length) {
3031
+ if (isZone === false) {
3032
+ const hex = stringArrayToHexStripped(buffer);
3033
+ if (hex !== void 0) {
3034
+ address.push(hex);
3035
+ } else {
3036
+ output.error = true;
3037
+ return false;
3038
+ }
3039
+ }
3040
+ buffer.length = 0;
3041
+ }
3042
+ return true;
3043
+ }
3057
3044
  for (let i = 0; i < input.length; i++) {
3058
3045
  const cursor = input[i];
3059
3046
  if (cursor === "[" || cursor === "]") {
@@ -3063,30 +3050,31 @@ function getIPV6(input) {
3063
3050
  if (endipv6Encountered === true) {
3064
3051
  endIpv6 = true;
3065
3052
  }
3066
- if (!consume(buffer, address, output)) {
3053
+ if (!consume()) {
3067
3054
  break;
3068
3055
  }
3069
- if (++tokenCount > 7) {
3056
+ tokenCount++;
3057
+ address.push(":");
3058
+ if (tokenCount > 7) {
3070
3059
  output.error = true;
3071
3060
  break;
3072
3061
  }
3073
- if (i > 0 && input[i - 1] === ":") {
3062
+ if (i - 1 >= 0 && input[i - 1] === ":") {
3074
3063
  endipv6Encountered = true;
3075
3064
  }
3076
- address.push(":");
3077
3065
  continue;
3078
3066
  } else if (cursor === "%") {
3079
- if (!consume(buffer, address, output)) {
3067
+ if (!consume()) {
3080
3068
  break;
3081
3069
  }
3082
- consume = consumeIsZone;
3070
+ isZone = true;
3083
3071
  } else {
3084
3072
  buffer.push(cursor);
3085
3073
  continue;
3086
3074
  }
3087
3075
  }
3088
3076
  if (buffer.length) {
3089
- if (consume === consumeIsZone) {
3077
+ if (isZone) {
3090
3078
  output.zone = buffer.join("");
3091
3079
  } else if (endIpv6) {
3092
3080
  address.push(buffer.join(""));
@@ -3109,11 +3097,33 @@ function normalizeIPv6$1(host) {
3109
3097
  newHost += "%" + ipv6.zone;
3110
3098
  escapedHost += "%25" + ipv6.zone;
3111
3099
  }
3112
- return { host: newHost, isIPV6: true, escapedHost };
3100
+ return { host: newHost, escapedHost, isIPV6: true };
3113
3101
  } else {
3114
3102
  return { host, isIPV6: false };
3115
3103
  }
3116
3104
  }
3105
+ function stripLeadingZeros(str, token) {
3106
+ let out = "";
3107
+ let skip = true;
3108
+ const l = str.length;
3109
+ for (let i = 0; i < l; i++) {
3110
+ const c = str[i];
3111
+ if (c === "0" && skip) {
3112
+ if (i + 1 <= l && str[i + 1] === token || i + 1 === l) {
3113
+ out += c;
3114
+ skip = false;
3115
+ }
3116
+ } else {
3117
+ if (c === token) {
3118
+ skip = true;
3119
+ } else {
3120
+ skip = false;
3121
+ }
3122
+ out += c;
3123
+ }
3124
+ }
3125
+ return out;
3126
+ }
3117
3127
  function findToken(str, token) {
3118
3128
  let ind = 0;
3119
3129
  for (let i = 0; i < str.length; i++) {
@@ -3121,339 +3131,246 @@ function findToken(str, token) {
3121
3131
  }
3122
3132
  return ind;
3123
3133
  }
3124
- function removeDotSegments$1(path) {
3125
- let input = path;
3134
+ const RDS1 = /^\.\.?\//u;
3135
+ const RDS2 = /^\/\.(?:\/|$)/u;
3136
+ const RDS3 = /^\/\.\.(?:\/|$)/u;
3137
+ const RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/u;
3138
+ function removeDotSegments$1(input) {
3126
3139
  const output = [];
3127
- let nextSlash = -1;
3128
- let len = 0;
3129
- while (len = input.length) {
3130
- if (len === 1) {
3131
- if (input === ".") {
3132
- break;
3133
- } else if (input === "/") {
3134
- output.push("/");
3135
- break;
3140
+ while (input.length) {
3141
+ if (input.match(RDS1)) {
3142
+ input = input.replace(RDS1, "");
3143
+ } else if (input.match(RDS2)) {
3144
+ input = input.replace(RDS2, "/");
3145
+ } else if (input.match(RDS3)) {
3146
+ input = input.replace(RDS3, "/");
3147
+ output.pop();
3148
+ } else if (input === "." || input === "..") {
3149
+ input = "";
3150
+ } else {
3151
+ const im = input.match(RDS5);
3152
+ if (im) {
3153
+ const s = im[0];
3154
+ input = input.slice(s.length);
3155
+ output.push(s);
3136
3156
  } else {
3137
- output.push(input);
3138
- break;
3139
- }
3140
- } else if (len === 2) {
3141
- if (input[0] === ".") {
3142
- if (input[1] === ".") {
3143
- break;
3144
- } else if (input[1] === "/") {
3145
- input = input.slice(2);
3146
- continue;
3147
- }
3148
- } else if (input[0] === "/") {
3149
- if (input[1] === "." || input[1] === "/") {
3150
- output.push("/");
3151
- break;
3152
- }
3153
- }
3154
- } else if (len === 3) {
3155
- if (input === "/..") {
3156
- if (output.length !== 0) {
3157
- output.pop();
3158
- }
3159
- output.push("/");
3160
- break;
3157
+ throw new Error("Unexpected dot segment condition");
3161
3158
  }
3162
3159
  }
3163
- if (input[0] === ".") {
3164
- if (input[1] === ".") {
3165
- if (input[2] === "/") {
3166
- input = input.slice(3);
3167
- continue;
3168
- }
3169
- } else if (input[1] === "/") {
3170
- input = input.slice(2);
3171
- continue;
3172
- }
3173
- } else if (input[0] === "/") {
3174
- if (input[1] === ".") {
3175
- if (input[2] === "/") {
3176
- input = input.slice(2);
3177
- continue;
3178
- } else if (input[2] === ".") {
3179
- if (input[3] === "/") {
3180
- input = input.slice(3);
3181
- if (output.length !== 0) {
3182
- output.pop();
3183
- }
3184
- continue;
3185
- }
3186
- }
3187
- }
3188
- }
3189
- if ((nextSlash = input.indexOf("/", 1)) === -1) {
3190
- output.push(input);
3191
- break;
3192
- } else {
3193
- output.push(input.slice(0, nextSlash));
3194
- input = input.slice(nextSlash);
3195
- }
3196
3160
  }
3197
3161
  return output.join("");
3198
3162
  }
3199
- function normalizeComponentEncoding$1(component, esc) {
3163
+ function normalizeComponentEncoding$1(components, esc) {
3200
3164
  const func = esc !== true ? escape : unescape;
3201
- if (component.scheme !== void 0) {
3202
- component.scheme = func(component.scheme);
3165
+ if (components.scheme !== void 0) {
3166
+ components.scheme = func(components.scheme);
3203
3167
  }
3204
- if (component.userinfo !== void 0) {
3205
- component.userinfo = func(component.userinfo);
3168
+ if (components.userinfo !== void 0) {
3169
+ components.userinfo = func(components.userinfo);
3206
3170
  }
3207
- if (component.host !== void 0) {
3208
- component.host = func(component.host);
3171
+ if (components.host !== void 0) {
3172
+ components.host = func(components.host);
3209
3173
  }
3210
- if (component.path !== void 0) {
3211
- component.path = func(component.path);
3174
+ if (components.path !== void 0) {
3175
+ components.path = func(components.path);
3212
3176
  }
3213
- if (component.query !== void 0) {
3214
- component.query = func(component.query);
3177
+ if (components.query !== void 0) {
3178
+ components.query = func(components.query);
3215
3179
  }
3216
- if (component.fragment !== void 0) {
3217
- component.fragment = func(component.fragment);
3180
+ if (components.fragment !== void 0) {
3181
+ components.fragment = func(components.fragment);
3218
3182
  }
3219
- return component;
3183
+ return components;
3220
3184
  }
3221
- function recomposeAuthority$1(component) {
3185
+ function recomposeAuthority$1(components) {
3222
3186
  const uriTokens = [];
3223
- if (component.userinfo !== void 0) {
3224
- uriTokens.push(component.userinfo);
3187
+ if (components.userinfo !== void 0) {
3188
+ uriTokens.push(components.userinfo);
3225
3189
  uriTokens.push("@");
3226
3190
  }
3227
- if (component.host !== void 0) {
3228
- let host = unescape(component.host);
3229
- if (!isIPv4$1(host)) {
3230
- const ipV6res = normalizeIPv6$1(host);
3191
+ if (components.host !== void 0) {
3192
+ let host = unescape(components.host);
3193
+ const ipV4res = normalizeIPv4$1(host);
3194
+ if (ipV4res.isIPV4) {
3195
+ host = ipV4res.host;
3196
+ } else {
3197
+ const ipV6res = normalizeIPv6$1(ipV4res.host);
3231
3198
  if (ipV6res.isIPV6 === true) {
3232
3199
  host = `[${ipV6res.escapedHost}]`;
3233
3200
  } else {
3234
- host = component.host;
3201
+ host = components.host;
3235
3202
  }
3236
3203
  }
3237
3204
  uriTokens.push(host);
3238
3205
  }
3239
- if (typeof component.port === "number" || typeof component.port === "string") {
3206
+ if (typeof components.port === "number" || typeof components.port === "string") {
3240
3207
  uriTokens.push(":");
3241
- uriTokens.push(String(component.port));
3208
+ uriTokens.push(String(components.port));
3242
3209
  }
3243
3210
  return uriTokens.length ? uriTokens.join("") : void 0;
3244
3211
  }
3245
3212
  var utils = {
3246
- nonSimpleDomain: nonSimpleDomain$1,
3247
3213
  recomposeAuthority: recomposeAuthority$1,
3248
3214
  normalizeComponentEncoding: normalizeComponentEncoding$1,
3249
3215
  removeDotSegments: removeDotSegments$1,
3250
- isIPv4: isIPv4$1,
3251
- isUUID: isUUID$1,
3216
+ normalizeIPv4: normalizeIPv4$1,
3252
3217
  normalizeIPv6: normalizeIPv6$1
3253
3218
  };
3254
- const { isUUID } = utils;
3219
+ const UUID_REG = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu;
3255
3220
  const URN_REG = /([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu;
3256
- function wsIsSecure(wsComponent) {
3257
- if (wsComponent.secure === true) {
3258
- return true;
3259
- } else if (wsComponent.secure === false) {
3260
- return false;
3261
- } else if (wsComponent.scheme) {
3262
- 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");
3263
- } else {
3264
- return false;
3265
- }
3221
+ function isSecure(wsComponents) {
3222
+ return typeof wsComponents.secure === "boolean" ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss";
3266
3223
  }
3267
- function httpParse(component) {
3268
- if (!component.host) {
3269
- component.error = component.error || "HTTP URIs must have a host.";
3224
+ function httpParse(components) {
3225
+ if (!components.host) {
3226
+ components.error = components.error || "HTTP URIs must have a host.";
3270
3227
  }
3271
- return component;
3228
+ return components;
3272
3229
  }
3273
- function httpSerialize(component) {
3274
- const secure = String(component.scheme).toLowerCase() === "https";
3275
- if (component.port === (secure ? 443 : 80) || component.port === "") {
3276
- component.port = void 0;
3230
+ function httpSerialize(components) {
3231
+ const secure = String(components.scheme).toLowerCase() === "https";
3232
+ if (components.port === (secure ? 443 : 80) || components.port === "") {
3233
+ components.port = void 0;
3277
3234
  }
3278
- if (!component.path) {
3279
- component.path = "/";
3235
+ if (!components.path) {
3236
+ components.path = "/";
3280
3237
  }
3281
- return component;
3238
+ return components;
3282
3239
  }
3283
- function wsParse(wsComponent) {
3284
- wsComponent.secure = wsIsSecure(wsComponent);
3285
- wsComponent.resourceName = (wsComponent.path || "/") + (wsComponent.query ? "?" + wsComponent.query : "");
3286
- wsComponent.path = void 0;
3287
- wsComponent.query = void 0;
3288
- return wsComponent;
3240
+ function wsParse(wsComponents) {
3241
+ wsComponents.secure = isSecure(wsComponents);
3242
+ wsComponents.resourceName = (wsComponents.path || "/") + (wsComponents.query ? "?" + wsComponents.query : "");
3243
+ wsComponents.path = void 0;
3244
+ wsComponents.query = void 0;
3245
+ return wsComponents;
3289
3246
  }
3290
- function wsSerialize(wsComponent) {
3291
- if (wsComponent.port === (wsIsSecure(wsComponent) ? 443 : 80) || wsComponent.port === "") {
3292
- wsComponent.port = void 0;
3247
+ function wsSerialize(wsComponents) {
3248
+ if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") {
3249
+ wsComponents.port = void 0;
3293
3250
  }
3294
- if (typeof wsComponent.secure === "boolean") {
3295
- wsComponent.scheme = wsComponent.secure ? "wss" : "ws";
3296
- wsComponent.secure = void 0;
3251
+ if (typeof wsComponents.secure === "boolean") {
3252
+ wsComponents.scheme = wsComponents.secure ? "wss" : "ws";
3253
+ wsComponents.secure = void 0;
3297
3254
  }
3298
- if (wsComponent.resourceName) {
3299
- const [path, query] = wsComponent.resourceName.split("?");
3300
- wsComponent.path = path && path !== "/" ? path : void 0;
3301
- wsComponent.query = query;
3302
- wsComponent.resourceName = void 0;
3255
+ if (wsComponents.resourceName) {
3256
+ const [path, query] = wsComponents.resourceName.split("?");
3257
+ wsComponents.path = path && path !== "/" ? path : void 0;
3258
+ wsComponents.query = query;
3259
+ wsComponents.resourceName = void 0;
3303
3260
  }
3304
- wsComponent.fragment = void 0;
3305
- return wsComponent;
3261
+ wsComponents.fragment = void 0;
3262
+ return wsComponents;
3306
3263
  }
3307
- function urnParse(urnComponent, options) {
3308
- if (!urnComponent.path) {
3309
- urnComponent.error = "URN can not be parsed";
3310
- return urnComponent;
3264
+ function urnParse(urnComponents, options) {
3265
+ if (!urnComponents.path) {
3266
+ urnComponents.error = "URN can not be parsed";
3267
+ return urnComponents;
3311
3268
  }
3312
- const matches = urnComponent.path.match(URN_REG);
3269
+ const matches = urnComponents.path.match(URN_REG);
3313
3270
  if (matches) {
3314
- const scheme = options.scheme || urnComponent.scheme || "urn";
3315
- urnComponent.nid = matches[1].toLowerCase();
3316
- urnComponent.nss = matches[2];
3317
- const urnScheme = `${scheme}:${options.nid || urnComponent.nid}`;
3318
- const schemeHandler = getSchemeHandler$1(urnScheme);
3319
- urnComponent.path = void 0;
3271
+ const scheme = options.scheme || urnComponents.scheme || "urn";
3272
+ urnComponents.nid = matches[1].toLowerCase();
3273
+ urnComponents.nss = matches[2];
3274
+ const urnScheme = `${scheme}:${options.nid || urnComponents.nid}`;
3275
+ const schemeHandler = SCHEMES$1[urnScheme];
3276
+ urnComponents.path = void 0;
3320
3277
  if (schemeHandler) {
3321
- urnComponent = schemeHandler.parse(urnComponent, options);
3278
+ urnComponents = schemeHandler.parse(urnComponents, options);
3322
3279
  }
3323
3280
  } else {
3324
- urnComponent.error = urnComponent.error || "URN can not be parsed.";
3281
+ urnComponents.error = urnComponents.error || "URN can not be parsed.";
3325
3282
  }
3326
- return urnComponent;
3283
+ return urnComponents;
3327
3284
  }
3328
- function urnSerialize(urnComponent, options) {
3329
- if (urnComponent.nid === void 0) {
3330
- throw new Error("URN without nid cannot be serialized");
3331
- }
3332
- const scheme = options.scheme || urnComponent.scheme || "urn";
3333
- const nid = urnComponent.nid.toLowerCase();
3285
+ function urnSerialize(urnComponents, options) {
3286
+ const scheme = options.scheme || urnComponents.scheme || "urn";
3287
+ const nid = urnComponents.nid.toLowerCase();
3334
3288
  const urnScheme = `${scheme}:${options.nid || nid}`;
3335
- const schemeHandler = getSchemeHandler$1(urnScheme);
3289
+ const schemeHandler = SCHEMES$1[urnScheme];
3336
3290
  if (schemeHandler) {
3337
- urnComponent = schemeHandler.serialize(urnComponent, options);
3291
+ urnComponents = schemeHandler.serialize(urnComponents, options);
3338
3292
  }
3339
- const uriComponent = urnComponent;
3340
- const nss = urnComponent.nss;
3341
- uriComponent.path = `${nid || options.nid}:${nss}`;
3293
+ const uriComponents = urnComponents;
3294
+ const nss = urnComponents.nss;
3295
+ uriComponents.path = `${nid || options.nid}:${nss}`;
3342
3296
  options.skipEscape = true;
3343
- return uriComponent;
3344
- }
3345
- function urnuuidParse(urnComponent, options) {
3346
- const uuidComponent = urnComponent;
3347
- uuidComponent.uuid = uuidComponent.nss;
3348
- uuidComponent.nss = void 0;
3349
- if (!options.tolerant && (!uuidComponent.uuid || !isUUID(uuidComponent.uuid))) {
3350
- uuidComponent.error = uuidComponent.error || "UUID is not valid.";
3351
- }
3352
- return uuidComponent;
3353
- }
3354
- function urnuuidSerialize(uuidComponent) {
3355
- const urnComponent = uuidComponent;
3356
- urnComponent.nss = (uuidComponent.uuid || "").toLowerCase();
3357
- return urnComponent;
3358
- }
3359
- const http = (
3360
- /** @type {SchemeHandler} */
3361
- {
3362
- scheme: "http",
3363
- domainHost: true,
3364
- parse: httpParse,
3365
- serialize: httpSerialize
3366
- }
3367
- );
3368
- const https = (
3369
- /** @type {SchemeHandler} */
3370
- {
3371
- scheme: "https",
3372
- domainHost: http.domainHost,
3373
- parse: httpParse,
3374
- serialize: httpSerialize
3375
- }
3376
- );
3377
- const ws = (
3378
- /** @type {SchemeHandler} */
3379
- {
3380
- scheme: "ws",
3381
- domainHost: true,
3382
- parse: wsParse,
3383
- serialize: wsSerialize
3384
- }
3385
- );
3386
- const wss = (
3387
- /** @type {SchemeHandler} */
3388
- {
3389
- scheme: "wss",
3390
- domainHost: ws.domainHost,
3391
- parse: ws.parse,
3392
- serialize: ws.serialize
3393
- }
3394
- );
3395
- const urn = (
3396
- /** @type {SchemeHandler} */
3397
- {
3398
- scheme: "urn",
3399
- parse: urnParse,
3400
- serialize: urnSerialize,
3401
- skipNormalize: true
3402
- }
3403
- );
3404
- const urnuuid = (
3405
- /** @type {SchemeHandler} */
3406
- {
3407
- scheme: "urn:uuid",
3408
- parse: urnuuidParse,
3409
- serialize: urnuuidSerialize,
3410
- skipNormalize: true
3411
- }
3412
- );
3413
- const SCHEMES$1 = (
3414
- /** @type {Record<SchemeName, SchemeHandler>} */
3415
- {
3416
- http,
3417
- https,
3418
- ws,
3419
- wss,
3420
- urn,
3421
- "urn:uuid": urnuuid
3422
- }
3423
- );
3424
- Object.setPrototypeOf(SCHEMES$1, null);
3425
- function getSchemeHandler$1(scheme) {
3426
- return scheme && (SCHEMES$1[
3427
- /** @type {SchemeName} */
3428
- scheme
3429
- ] || SCHEMES$1[
3430
- /** @type {SchemeName} */
3431
- scheme.toLowerCase()
3432
- ]) || void 0;
3433
- }
3434
- var schemes = {
3435
- SCHEMES: SCHEMES$1,
3436
- getSchemeHandler: getSchemeHandler$1
3297
+ return uriComponents;
3298
+ }
3299
+ function urnuuidParse(urnComponents, options) {
3300
+ const uuidComponents = urnComponents;
3301
+ uuidComponents.uuid = uuidComponents.nss;
3302
+ uuidComponents.nss = void 0;
3303
+ if (!options.tolerant && (!uuidComponents.uuid || !UUID_REG.test(uuidComponents.uuid))) {
3304
+ uuidComponents.error = uuidComponents.error || "UUID is not valid.";
3305
+ }
3306
+ return uuidComponents;
3307
+ }
3308
+ function urnuuidSerialize(uuidComponents) {
3309
+ const urnComponents = uuidComponents;
3310
+ urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
3311
+ return urnComponents;
3312
+ }
3313
+ const http = {
3314
+ scheme: "http",
3315
+ domainHost: true,
3316
+ parse: httpParse,
3317
+ serialize: httpSerialize
3318
+ };
3319
+ const https = {
3320
+ scheme: "https",
3321
+ domainHost: http.domainHost,
3322
+ parse: httpParse,
3323
+ serialize: httpSerialize
3324
+ };
3325
+ const ws = {
3326
+ scheme: "ws",
3327
+ domainHost: true,
3328
+ parse: wsParse,
3329
+ serialize: wsSerialize
3330
+ };
3331
+ const wss = {
3332
+ scheme: "wss",
3333
+ domainHost: ws.domainHost,
3334
+ parse: ws.parse,
3335
+ serialize: ws.serialize
3336
+ };
3337
+ const urn = {
3338
+ scheme: "urn",
3339
+ parse: urnParse,
3340
+ serialize: urnSerialize,
3341
+ skipNormalize: true
3342
+ };
3343
+ const urnuuid = {
3344
+ scheme: "urn:uuid",
3345
+ parse: urnuuidParse,
3346
+ serialize: urnuuidSerialize,
3347
+ skipNormalize: true
3437
3348
  };
3438
- const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = utils;
3439
- const { SCHEMES, getSchemeHandler } = schemes;
3349
+ const SCHEMES$1 = {
3350
+ http,
3351
+ https,
3352
+ ws,
3353
+ wss,
3354
+ urn,
3355
+ "urn:uuid": urnuuid
3356
+ };
3357
+ var schemes = SCHEMES$1;
3358
+ const { normalizeIPv6, normalizeIPv4, removeDotSegments, recomposeAuthority, normalizeComponentEncoding } = utils;
3359
+ const SCHEMES = schemes;
3440
3360
  function normalize(uri2, options) {
3441
3361
  if (typeof uri2 === "string") {
3442
- uri2 = /** @type {T} */
3443
- serialize(parse(uri2, options), options);
3362
+ uri2 = serialize(parse(uri2, options), options);
3444
3363
  } else if (typeof uri2 === "object") {
3445
- uri2 = /** @type {T} */
3446
- parse(serialize(uri2, options), options);
3364
+ uri2 = parse(serialize(uri2, options), options);
3447
3365
  }
3448
3366
  return uri2;
3449
3367
  }
3450
3368
  function resolve$4(baseURI, relativeURI, options) {
3451
- const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
3452
- const resolved = resolveComponent(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true);
3453
- schemelessOptions.skipEscape = true;
3454
- return serialize(resolved, schemelessOptions);
3369
+ const schemelessOptions = Object.assign({ scheme: "null" }, options);
3370
+ const resolved = resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true);
3371
+ return serialize(resolved, { ...schemelessOptions, skipEscape: true });
3455
3372
  }
3456
- function resolveComponent(base, relative, options, skipNormalization) {
3373
+ function resolveComponents(base, relative, options, skipNormalization) {
3457
3374
  const target = {};
3458
3375
  if (!skipNormalization) {
3459
3376
  base = parse(serialize(base, options), options);
@@ -3483,7 +3400,7 @@ function resolveComponent(base, relative, options, skipNormalization) {
3483
3400
  target.query = base.query;
3484
3401
  }
3485
3402
  } else {
3486
- if (relative.path[0] === "/") {
3403
+ if (relative.path.charAt(0) === "/") {
3487
3404
  target.path = removeDotSegments(relative.path);
3488
3405
  } else {
3489
3406
  if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) {
@@ -3522,7 +3439,7 @@ function equal$4(uriA, uriB, options) {
3522
3439
  return uriA.toLowerCase() === uriB.toLowerCase();
3523
3440
  }
3524
3441
  function serialize(cmpts, opts) {
3525
- const component = {
3442
+ const components = {
3526
3443
  host: cmpts.host,
3527
3444
  scheme: cmpts.scheme,
3528
3445
  userinfo: cmpts.userinfo,
@@ -3540,49 +3457,60 @@ function serialize(cmpts, opts) {
3540
3457
  };
3541
3458
  const options = Object.assign({}, opts);
3542
3459
  const uriTokens = [];
3543
- const schemeHandler = getSchemeHandler(options.scheme || component.scheme);
3544
- if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options);
3545
- if (component.path !== void 0) {
3460
+ const schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
3461
+ if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options);
3462
+ if (components.path !== void 0) {
3546
3463
  if (!options.skipEscape) {
3547
- component.path = escape(component.path);
3548
- if (component.scheme !== void 0) {
3549
- component.path = component.path.split("%3A").join(":");
3464
+ components.path = escape(components.path);
3465
+ if (components.scheme !== void 0) {
3466
+ components.path = components.path.split("%3A").join(":");
3550
3467
  }
3551
3468
  } else {
3552
- component.path = unescape(component.path);
3469
+ components.path = unescape(components.path);
3553
3470
  }
3554
3471
  }
3555
- if (options.reference !== "suffix" && component.scheme) {
3556
- uriTokens.push(component.scheme, ":");
3472
+ if (options.reference !== "suffix" && components.scheme) {
3473
+ uriTokens.push(components.scheme, ":");
3557
3474
  }
3558
- const authority = recomposeAuthority(component);
3475
+ const authority = recomposeAuthority(components);
3559
3476
  if (authority !== void 0) {
3560
3477
  if (options.reference !== "suffix") {
3561
3478
  uriTokens.push("//");
3562
3479
  }
3563
3480
  uriTokens.push(authority);
3564
- if (component.path && component.path[0] !== "/") {
3481
+ if (components.path && components.path.charAt(0) !== "/") {
3565
3482
  uriTokens.push("/");
3566
3483
  }
3567
3484
  }
3568
- if (component.path !== void 0) {
3569
- let s = component.path;
3485
+ if (components.path !== void 0) {
3486
+ let s = components.path;
3570
3487
  if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
3571
3488
  s = removeDotSegments(s);
3572
3489
  }
3573
- if (authority === void 0 && s[0] === "/" && s[1] === "/") {
3574
- s = "/%2F" + s.slice(2);
3490
+ if (authority === void 0) {
3491
+ s = s.replace(/^\/\//u, "/%2F");
3575
3492
  }
3576
3493
  uriTokens.push(s);
3577
3494
  }
3578
- if (component.query !== void 0) {
3579
- uriTokens.push("?", component.query);
3495
+ if (components.query !== void 0) {
3496
+ uriTokens.push("?", components.query);
3580
3497
  }
3581
- if (component.fragment !== void 0) {
3582
- uriTokens.push("#", component.fragment);
3498
+ if (components.fragment !== void 0) {
3499
+ uriTokens.push("#", components.fragment);
3583
3500
  }
3584
3501
  return uriTokens.join("");
3585
3502
  }
3503
+ const hexLookUp = Array.from({ length: 127 }, (_v, k) => /[^!"$&'()*+,\-.;=_`a-z{}~]/u.test(String.fromCharCode(k)));
3504
+ function nonSimpleDomain(value) {
3505
+ let code2 = 0;
3506
+ for (let i = 0, len = value.length; i < len; ++i) {
3507
+ code2 = value.charCodeAt(i);
3508
+ if (code2 > 126 || hexLookUp[code2]) {
3509
+ return true;
3510
+ }
3511
+ }
3512
+ return false;
3513
+ }
3586
3514
  const URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;
3587
3515
  function parse(uri2, opts) {
3588
3516
  const options = Object.assign({}, opts);
@@ -3595,14 +3523,9 @@ function parse(uri2, opts) {
3595
3523
  query: void 0,
3596
3524
  fragment: void 0
3597
3525
  };
3526
+ const gotEncoding = uri2.indexOf("%") !== -1;
3598
3527
  let isIP = false;
3599
- if (options.reference === "suffix") {
3600
- if (options.scheme) {
3601
- uri2 = options.scheme + ":" + uri2;
3602
- } else {
3603
- uri2 = "//" + uri2;
3604
- }
3605
- }
3528
+ if (options.reference === "suffix") uri2 = (options.scheme ? options.scheme + ":" : "") + "//" + uri2;
3606
3529
  const matches = uri2.match(URI_PARSE);
3607
3530
  if (matches) {
3608
3531
  parsed.scheme = matches[1];
@@ -3616,12 +3539,13 @@ function parse(uri2, opts) {
3616
3539
  parsed.port = matches[5];
3617
3540
  }
3618
3541
  if (parsed.host) {
3619
- const ipv4result = isIPv4(parsed.host);
3620
- if (ipv4result === false) {
3621
- const ipv6result = normalizeIPv6(parsed.host);
3542
+ const ipv4result = normalizeIPv4(parsed.host);
3543
+ if (ipv4result.isIPV4 === false) {
3544
+ const ipv6result = normalizeIPv6(ipv4result.host);
3622
3545
  parsed.host = ipv6result.host.toLowerCase();
3623
3546
  isIP = ipv6result.isIPV6;
3624
3547
  } else {
3548
+ parsed.host = ipv4result.host;
3625
3549
  isIP = true;
3626
3550
  }
3627
3551
  }
@@ -3637,7 +3561,7 @@ function parse(uri2, opts) {
3637
3561
  if (options.reference && options.reference !== "suffix" && options.reference !== parsed.reference) {
3638
3562
  parsed.error = parsed.error || "URI is not a " + options.reference + " reference.";
3639
3563
  }
3640
- const schemeHandler = getSchemeHandler(options.scheme || parsed.scheme);
3564
+ const schemeHandler = SCHEMES[(options.scheme || parsed.scheme || "").toLowerCase()];
3641
3565
  if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
3642
3566
  if (parsed.host && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP === false && nonSimpleDomain(parsed.host)) {
3643
3567
  try {
@@ -3648,13 +3572,11 @@ function parse(uri2, opts) {
3648
3572
  }
3649
3573
  }
3650
3574
  if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
3651
- if (uri2.indexOf("%") !== -1) {
3652
- if (parsed.scheme !== void 0) {
3653
- parsed.scheme = unescape(parsed.scheme);
3654
- }
3655
- if (parsed.host !== void 0) {
3656
- parsed.host = unescape(parsed.host);
3657
- }
3575
+ if (gotEncoding && parsed.scheme !== void 0) {
3576
+ parsed.scheme = unescape(parsed.scheme);
3577
+ }
3578
+ if (gotEncoding && parsed.host !== void 0) {
3579
+ parsed.host = unescape(parsed.host);
3658
3580
  }
3659
3581
  if (parsed.path) {
3660
3582
  parsed.path = escape(unescape(parsed.path));
@@ -3675,7 +3597,7 @@ const fastUri = {
3675
3597
  SCHEMES,
3676
3598
  normalize,
3677
3599
  resolve: resolve$4,
3678
- resolveComponent,
3600
+ resolveComponents,
3679
3601
  equal: equal$4,
3680
3602
  serialize,
3681
3603
  parse
@@ -3691,7 +3613,7 @@ uri$2.default = uri$1;
3691
3613
  (function(exports) {
3692
3614
  Object.defineProperty(exports, "__esModule", { value: true });
3693
3615
  exports.CodeGen = exports.Name = exports.nil = exports.stringify = exports.str = exports._ = exports.KeywordCxt = void 0;
3694
- var validate_12 = requireValidate();
3616
+ var validate_12 = validate$2;
3695
3617
  Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function() {
3696
3618
  return validate_12.KeywordCxt;
3697
3619
  } });
@@ -3714,7 +3636,7 @@ uri$2.default = uri$1;
3714
3636
  Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function() {
3715
3637
  return codegen_12.CodeGen;
3716
3638
  } });
3717
- const validation_error_12 = requireValidation_error();
3639
+ const validation_error_12 = validation_error;
3718
3640
  const ref_error_12 = ref_error;
3719
3641
  const rules_12 = rules$2;
3720
3642
  const compile_12 = compile$2;
@@ -5293,7 +5215,7 @@ const def$a = {
5293
5215
  additionalProperties$1.default = def$a;
5294
5216
  var properties$4 = {};
5295
5217
  Object.defineProperty(properties$4, "__esModule", { value: true });
5296
- const validate_1 = requireValidate();
5218
+ const validate_1 = validate$2;
5297
5219
  const code_1$2 = code;
5298
5220
  const util_1$7 = util$7;
5299
5221
  const additionalProperties_1$1 = additionalProperties$1;
@@ -6144,7 +6066,7 @@ const require$$3 = {
6144
6066
  module.exports.Ajv = Ajv2;
6145
6067
  Object.defineProperty(exports, "__esModule", { value: true });
6146
6068
  exports.default = Ajv2;
6147
- var validate_12 = requireValidate();
6069
+ var validate_12 = validate$2;
6148
6070
  Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function() {
6149
6071
  return validate_12.KeywordCxt;
6150
6072
  } });
@@ -6167,7 +6089,7 @@ const require$$3 = {
6167
6089
  Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function() {
6168
6090
  return codegen_12.CodeGen;
6169
6091
  } });
6170
- var validation_error_12 = requireValidation_error();
6092
+ var validation_error_12 = validation_error;
6171
6093
  Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function() {
6172
6094
  return validation_error_12.default;
6173
6095
  } });
@@ -9917,10 +9839,14 @@ const enumType = ZodEnum.create;
9917
9839
  ZodPromise.create;
9918
9840
  const optionalType = ZodOptional.create;
9919
9841
  ZodNullable.create;
9920
- const NEVER = INVALID;
9921
9842
  const LATEST_PROTOCOL_VERSION = "2025-06-18";
9922
9843
  const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26";
9923
- const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-03-26", "2024-11-05", "2024-10-07"];
9844
+ const SUPPORTED_PROTOCOL_VERSIONS = [
9845
+ LATEST_PROTOCOL_VERSION,
9846
+ "2025-03-26",
9847
+ "2024-11-05",
9848
+ "2024-10-07"
9849
+ ];
9924
9850
  const JSONRPC_VERSION = "2.0";
9925
9851
  const ProgressTokenSchema = unionType([stringType(), numberType().int()]);
9926
9852
  const CursorSchema = stringType();
@@ -10000,7 +9926,12 @@ const JSONRPCErrorSchema = objectType({
10000
9926
  })
10001
9927
  }).strict();
10002
9928
  const isJSONRPCError = (value) => JSONRPCErrorSchema.safeParse(value).success;
10003
- const JSONRPCMessageSchema = unionType([JSONRPCRequestSchema, JSONRPCNotificationSchema, JSONRPCResponseSchema, JSONRPCErrorSchema]);
9929
+ const JSONRPCMessageSchema = unionType([
9930
+ JSONRPCRequestSchema,
9931
+ JSONRPCNotificationSchema,
9932
+ JSONRPCResponseSchema,
9933
+ JSONRPCErrorSchema
9934
+ ]);
10004
9935
  const EmptyResultSchema = ResultSchema.strict();
10005
9936
  const CancelledNotificationSchema = NotificationSchema.extend({
10006
9937
  method: literalType("notifications/cancelled"),
@@ -10017,57 +9948,22 @@ const CancelledNotificationSchema = NotificationSchema.extend({
10017
9948
  reason: stringType().optional()
10018
9949
  })
10019
9950
  });
10020
- const IconSchema = objectType({
10021
- /**
10022
- * URL or data URI for the icon.
10023
- */
10024
- src: stringType(),
10025
- /**
10026
- * Optional MIME type for the icon.
10027
- */
10028
- mimeType: optionalType(stringType()),
10029
- /**
10030
- * Optional array of strings that specify sizes at which the icon can be used.
10031
- * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
10032
- *
10033
- * If not provided, the client should assume that the icon can be used at any size.
10034
- */
10035
- sizes: optionalType(arrayType(stringType()))
10036
- }).passthrough();
10037
- const IconsSchema = objectType({
10038
- /**
10039
- * Optional set of sized icons that the client can display in a user interface.
10040
- *
10041
- * Clients that support rendering icons MUST support at least the following MIME types:
10042
- * - `image/png` - PNG images (safe, universal compatibility)
10043
- * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
10044
- *
10045
- * Clients that support rendering icons SHOULD also support:
10046
- * - `image/svg+xml` - SVG images (scalable but requires security precautions)
10047
- * - `image/webp` - WebP images (modern, efficient format)
10048
- */
10049
- icons: arrayType(IconSchema).optional()
10050
- }).passthrough();
10051
9951
  const BaseMetadataSchema = objectType({
10052
9952
  /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
10053
9953
  name: stringType(),
10054
9954
  /**
10055
- * Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
10056
- * even by those unfamiliar with domain-specific terminology.
10057
- *
10058
- * If not provided, the name should be used for display (except for Tool,
10059
- * where `annotations.title` should be given precedence over using `name`,
10060
- * if present).
10061
- */
9955
+ * Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
9956
+ * even by those unfamiliar with domain-specific terminology.
9957
+ *
9958
+ * If not provided, the name should be used for display (except for Tool,
9959
+ * where `annotations.title` should be given precedence over using `name`,
9960
+ * if present).
9961
+ */
10062
9962
  title: optionalType(stringType())
10063
9963
  }).passthrough();
10064
9964
  const ImplementationSchema = BaseMetadataSchema.extend({
10065
- version: stringType(),
10066
- /**
10067
- * An optional URL of the website for this implementation.
10068
- */
10069
- websiteUrl: optionalType(stringType())
10070
- }).merge(IconsSchema);
9965
+ version: stringType()
9966
+ });
10071
9967
  const ClientCapabilitiesSchema = objectType({
10072
9968
  /**
10073
9969
  * Experimental, non-standard capabilities that the client supports.
@@ -10263,7 +10159,7 @@ const ResourceSchema = BaseMetadataSchema.extend({
10263
10159
  * for notes on _meta usage.
10264
10160
  */
10265
10161
  _meta: optionalType(objectType({}).passthrough())
10266
- }).merge(IconsSchema);
10162
+ });
10267
10163
  const ResourceTemplateSchema = BaseMetadataSchema.extend({
10268
10164
  /**
10269
10165
  * A URI template (according to RFC 6570) that can be used to construct resource URIs.
@@ -10284,7 +10180,7 @@ const ResourceTemplateSchema = BaseMetadataSchema.extend({
10284
10180
  * for notes on _meta usage.
10285
10181
  */
10286
10182
  _meta: optionalType(objectType({}).passthrough())
10287
- }).merge(IconsSchema);
10183
+ });
10288
10184
  const ListResourcesRequestSchema = PaginatedRequestSchema.extend({
10289
10185
  method: literalType("resources/list")
10290
10186
  });
@@ -10367,7 +10263,7 @@ const PromptSchema = BaseMetadataSchema.extend({
10367
10263
  * for notes on _meta usage.
10368
10264
  */
10369
10265
  _meta: optionalType(objectType({}).passthrough())
10370
- }).merge(IconsSchema);
10266
+ });
10371
10267
  const ListPromptsRequestSchema = PaginatedRequestSchema.extend({
10372
10268
  method: literalType("prompts/list")
10373
10269
  });
@@ -10534,7 +10430,7 @@ const ToolSchema = BaseMetadataSchema.extend({
10534
10430
  * for notes on _meta usage.
10535
10431
  */
10536
10432
  _meta: optionalType(objectType({}).passthrough())
10537
- }).merge(IconsSchema);
10433
+ });
10538
10434
  const ListToolsRequestSchema = PaginatedRequestSchema.extend({
10539
10435
  method: literalType("tools/list")
10540
10436
  });
@@ -10584,7 +10480,16 @@ const CallToolRequestSchema = RequestSchema.extend({
10584
10480
  const ToolListChangedNotificationSchema = NotificationSchema.extend({
10585
10481
  method: literalType("notifications/tools/list_changed")
10586
10482
  });
10587
- const LoggingLevelSchema = enumType(["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]);
10483
+ const LoggingLevelSchema = enumType([
10484
+ "debug",
10485
+ "info",
10486
+ "notice",
10487
+ "warning",
10488
+ "error",
10489
+ "critical",
10490
+ "alert",
10491
+ "emergency"
10492
+ ]);
10588
10493
  const SetLevelRequestSchema = RequestSchema.extend({
10589
10494
  method: literalType("logging/setLevel"),
10590
10495
  params: BaseRequestParamsSchema.extend({
@@ -10677,7 +10582,11 @@ const CreateMessageResultSchema = ResultSchema.extend({
10677
10582
  */
10678
10583
  stopReason: optionalType(enumType(["endTurn", "stopSequence", "maxTokens"]).or(stringType())),
10679
10584
  role: enumType(["user", "assistant"]),
10680
- content: discriminatedUnionType("type", [TextContentSchema, ImageContentSchema, AudioContentSchema])
10585
+ content: discriminatedUnionType("type", [
10586
+ TextContentSchema,
10587
+ ImageContentSchema,
10588
+ AudioContentSchema
10589
+ ])
10681
10590
  });
10682
10591
  const BooleanSchemaSchema = objectType({
10683
10592
  type: literalType("boolean"),
@@ -10707,7 +10616,12 @@ const EnumSchemaSchema = objectType({
10707
10616
  enum: arrayType(stringType()),
10708
10617
  enumNames: optionalType(arrayType(stringType()))
10709
10618
  }).passthrough();
10710
- const PrimitiveSchemaDefinitionSchema = unionType([BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema, EnumSchemaSchema]);
10619
+ const PrimitiveSchemaDefinitionSchema = unionType([
10620
+ BooleanSchemaSchema,
10621
+ StringSchemaSchema,
10622
+ NumberSchemaSchema,
10623
+ EnumSchemaSchema
10624
+ ]);
10711
10625
  const ElicitRequestSchema = RequestSchema.extend({
10712
10626
  method: literalType("elicitation/create"),
10713
10627
  params: BaseRequestParamsSchema.extend({
@@ -10836,8 +10750,18 @@ const ClientNotificationSchema = unionType([
10836
10750
  InitializedNotificationSchema,
10837
10751
  RootsListChangedNotificationSchema
10838
10752
  ]);
10839
- const ClientResultSchema = unionType([EmptyResultSchema, CreateMessageResultSchema, ElicitResultSchema, ListRootsResultSchema]);
10840
- const ServerRequestSchema = unionType([PingRequestSchema, CreateMessageRequestSchema, ElicitRequestSchema, ListRootsRequestSchema]);
10753
+ const ClientResultSchema = unionType([
10754
+ EmptyResultSchema,
10755
+ CreateMessageResultSchema,
10756
+ ElicitResultSchema,
10757
+ ListRootsResultSchema
10758
+ ]);
10759
+ const ServerRequestSchema = unionType([
10760
+ PingRequestSchema,
10761
+ CreateMessageRequestSchema,
10762
+ ElicitRequestSchema,
10763
+ ListRootsRequestSchema
10764
+ ]);
10841
10765
  const ServerNotificationSchema = unionType([
10842
10766
  CancelledNotificationSchema,
10843
10767
  ProgressNotificationSchema,
@@ -11195,10 +11119,7 @@ class Protocol {
11195
11119
  const totalElapsed = Date.now() - info.startTime;
11196
11120
  if (info.maxTotalTimeout && totalElapsed >= info.maxTotalTimeout) {
11197
11121
  this._timeoutInfo.delete(messageId);
11198
- throw new McpError(ErrorCode.RequestTimeout, "Maximum total timeout exceeded", {
11199
- maxTotalTimeout: info.maxTotalTimeout,
11200
- totalElapsed
11201
- });
11122
+ throw new McpError(ErrorCode.RequestTimeout, "Maximum total timeout exceeded", { maxTotalTimeout: info.maxTotalTimeout, totalElapsed });
11202
11123
  }
11203
11124
  clearTimeout(info.timeoutId);
11204
11125
  info.timeoutId = setTimeout(info.onTimeout, info.timeout);
@@ -11270,11 +11191,10 @@ class Protocol {
11270
11191
  Promise.resolve().then(() => handler(notification)).catch((error2) => this._onerror(new Error(`Uncaught error in notification handler: ${error2}`)));
11271
11192
  }
11272
11193
  _onrequest(request, extra) {
11273
- var _a, _b;
11194
+ var _a, _b, _c, _d;
11274
11195
  const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== void 0 ? _a : this.fallbackRequestHandler;
11275
- const capturedTransport = this._transport;
11276
11196
  if (handler === void 0) {
11277
- capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
11197
+ (_b = this._transport) === null || _b === void 0 ? void 0 : _b.send({
11278
11198
  jsonrpc: "2.0",
11279
11199
  id: request.id,
11280
11200
  error: {
@@ -11288,8 +11208,8 @@ class Protocol {
11288
11208
  this._requestHandlerAbortControllers.set(request.id, abortController);
11289
11209
  const fullExtra = {
11290
11210
  signal: abortController.signal,
11291
- sessionId: capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.sessionId,
11292
- _meta: (_b = request.params) === null || _b === void 0 ? void 0 : _b._meta,
11211
+ sessionId: (_c = this._transport) === null || _c === void 0 ? void 0 : _c.sessionId,
11212
+ _meta: (_d = request.params) === null || _d === void 0 ? void 0 : _d._meta,
11293
11213
  sendNotification: (notification) => this.notification(notification, { relatedRequestId: request.id }),
11294
11214
  sendRequest: (r, resultSchema, options) => this.request(r, resultSchema, { ...options, relatedRequestId: request.id }),
11295
11215
  authInfo: extra === null || extra === void 0 ? void 0 : extra.authInfo,
@@ -11297,25 +11217,26 @@ class Protocol {
11297
11217
  requestInfo: extra === null || extra === void 0 ? void 0 : extra.requestInfo
11298
11218
  };
11299
11219
  Promise.resolve().then(() => handler(request, fullExtra)).then((result) => {
11220
+ var _a2;
11300
11221
  if (abortController.signal.aborted) {
11301
11222
  return;
11302
11223
  }
11303
- return capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
11224
+ return (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
11304
11225
  result,
11305
11226
  jsonrpc: "2.0",
11306
11227
  id: request.id
11307
11228
  });
11308
11229
  }, (error2) => {
11309
- var _a2;
11230
+ var _a2, _b2;
11310
11231
  if (abortController.signal.aborted) {
11311
11232
  return;
11312
11233
  }
11313
- return capturedTransport === null || capturedTransport === void 0 ? void 0 : capturedTransport.send({
11234
+ return (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
11314
11235
  jsonrpc: "2.0",
11315
11236
  id: request.id,
11316
11237
  error: {
11317
11238
  code: Number.isSafeInteger(error2["code"]) ? error2["code"] : ErrorCode.InternalError,
11318
- message: (_a2 = error2.message) !== null && _a2 !== void 0 ? _a2 : "Internal error"
11239
+ message: (_b2 = error2.message) !== null && _b2 !== void 0 ? _b2 : "Internal error"
11319
11240
  }
11320
11241
  });
11321
11242
  }).catch((error2) => this._onerror(new Error(`Failed to send response: ${error2}`))).finally(() => {
@@ -12146,24 +12067,24 @@ var uri_all = { exports: {} };
12146
12067
  }
12147
12068
  return uriTokens.length ? uriTokens.join("") : void 0;
12148
12069
  }
12149
- var RDS1 = /^\.\.?\//;
12150
- var RDS2 = /^\/\.(\/|$)/;
12151
- var RDS3 = /^\/\.\.(\/|$)/;
12152
- var RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/;
12070
+ var RDS12 = /^\.\.?\//;
12071
+ var RDS22 = /^\/\.(\/|$)/;
12072
+ var RDS32 = /^\/\.\.(\/|$)/;
12073
+ var RDS52 = /^\/?(?:.|\n)*?(?=\/|$)/;
12153
12074
  function removeDotSegments2(input) {
12154
12075
  var output = [];
12155
12076
  while (input.length) {
12156
- if (input.match(RDS1)) {
12157
- input = input.replace(RDS1, "");
12158
- } else if (input.match(RDS2)) {
12159
- input = input.replace(RDS2, "/");
12160
- } else if (input.match(RDS3)) {
12161
- input = input.replace(RDS3, "/");
12077
+ if (input.match(RDS12)) {
12078
+ input = input.replace(RDS12, "");
12079
+ } else if (input.match(RDS22)) {
12080
+ input = input.replace(RDS22, "/");
12081
+ } else if (input.match(RDS32)) {
12082
+ input = input.replace(RDS32, "/");
12162
12083
  output.pop();
12163
12084
  } else if (input === "." || input === "..") {
12164
12085
  input = "";
12165
12086
  } else {
12166
- var im = input.match(RDS5);
12087
+ var im = input.match(RDS52);
12167
12088
  if (im) {
12168
12089
  var s = im[0];
12169
12090
  input = input.slice(s.length);
@@ -12226,7 +12147,7 @@ var uri_all = { exports: {} };
12226
12147
  }
12227
12148
  return uriTokens.join("");
12228
12149
  }
12229
- function resolveComponents(base2, relative) {
12150
+ function resolveComponents2(base2, relative) {
12230
12151
  var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
12231
12152
  var skipNormalization = arguments[3];
12232
12153
  var target = {};
@@ -12283,7 +12204,7 @@ var uri_all = { exports: {} };
12283
12204
  }
12284
12205
  function resolve2(baseURI, relativeURI, options) {
12285
12206
  var schemelessOptions = assign({ scheme: "null" }, options);
12286
- return serialize2(resolveComponents(parse2(baseURI, schemelessOptions), parse2(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
12207
+ return serialize2(resolveComponents2(parse2(baseURI, schemelessOptions), parse2(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
12287
12208
  }
12288
12209
  function normalize2(uri2, options) {
12289
12210
  if (typeof uri2 === "string") {
@@ -12338,7 +12259,7 @@ var uri_all = { exports: {} };
12338
12259
  parse: handler.parse,
12339
12260
  serialize: handler.serialize
12340
12261
  };
12341
- function isSecure(wsComponents) {
12262
+ function isSecure2(wsComponents) {
12342
12263
  return typeof wsComponents.secure === "boolean" ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss";
12343
12264
  }
12344
12265
  var handler$2 = {
@@ -12346,14 +12267,14 @@ var uri_all = { exports: {} };
12346
12267
  domainHost: true,
12347
12268
  parse: function parse3(components, options) {
12348
12269
  var wsComponents = components;
12349
- wsComponents.secure = isSecure(wsComponents);
12270
+ wsComponents.secure = isSecure2(wsComponents);
12350
12271
  wsComponents.resourceName = (wsComponents.path || "/") + (wsComponents.query ? "?" + wsComponents.query : "");
12351
12272
  wsComponents.path = void 0;
12352
12273
  wsComponents.query = void 0;
12353
12274
  return wsComponents;
12354
12275
  },
12355
12276
  serialize: function serialize3(wsComponents, options) {
12356
- if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") {
12277
+ if (wsComponents.port === (isSecure2(wsComponents) ? 443 : 80) || wsComponents.port === "") {
12357
12278
  wsComponents.port = void 0;
12358
12279
  }
12359
12280
  if (typeof wsComponents.secure === "boolean") {
@@ -12544,7 +12465,7 @@ var uri_all = { exports: {} };
12544
12465
  exports2.parse = parse2;
12545
12466
  exports2.removeDotSegments = removeDotSegments2;
12546
12467
  exports2.serialize = serialize2;
12547
- exports2.resolveComponents = resolveComponents;
12468
+ exports2.resolveComponents = resolveComponents2;
12548
12469
  exports2.resolve = resolve2;
12549
12470
  exports2.normalize = normalize2;
12550
12471
  exports2.equal = equal3;
@@ -13564,7 +13485,7 @@ var resolve$1 = resolve_1, util$2 = util$5, errorClasses$1 = error_classes, stab
13564
13485
  var validateGenerator = validate$1;
13565
13486
  var ucs2length2 = util$2.ucs2length;
13566
13487
  var equal2 = fastDeepEqual;
13567
- var ValidationError = errorClasses$1.Validation;
13488
+ var ValidationError2 = errorClasses$1.Validation;
13568
13489
  var compile_1 = compile$1;
13569
13490
  function compile$1(schema, root, localRefs, baseId) {
13570
13491
  var self2 = this, opts = this._opts, refVal = [void 0], refs = {}, patterns = [], patternsHash = {}, defaults2 = [], defaultsHash = {}, customRules = [];
@@ -13652,7 +13573,7 @@ function compile$1(schema, root, localRefs, baseId) {
13652
13573
  customRules,
13653
13574
  equal2,
13654
13575
  ucs2length2,
13655
- ValidationError
13576
+ ValidationError2
13656
13577
  );
13657
13578
  refVal[0] = validate2;
13658
13579
  } catch (e) {
@@ -17745,22 +17666,9 @@ async function pkceChallenge(length) {
17745
17666
  code_challenge: challenge
17746
17667
  };
17747
17668
  }
17748
- const SafeUrlSchema = stringType().url().superRefine((val, ctx) => {
17749
- if (!URL.canParse(val)) {
17750
- ctx.addIssue({
17751
- code: ZodIssueCode.custom,
17752
- message: "URL must be parseable",
17753
- fatal: true
17754
- });
17755
- return NEVER;
17756
- }
17757
- }).refine((url) => {
17758
- const u = new URL(url);
17759
- return u.protocol !== "javascript:" && u.protocol !== "data:" && u.protocol !== "vbscript:";
17760
- }, { message: "URL cannot use javascript:, data:, or vbscript: scheme" });
17761
17669
  const OAuthProtectedResourceMetadataSchema = objectType({
17762
17670
  resource: stringType().url(),
17763
- authorization_servers: arrayType(SafeUrlSchema).optional(),
17671
+ authorization_servers: arrayType(stringType().url()).optional(),
17764
17672
  jwks_uri: stringType().url().optional(),
17765
17673
  scopes_supported: arrayType(stringType()).optional(),
17766
17674
  bearer_methods_supported: arrayType(stringType()).optional(),
@@ -17776,17 +17684,17 @@ const OAuthProtectedResourceMetadataSchema = objectType({
17776
17684
  }).passthrough();
17777
17685
  const OAuthMetadataSchema = objectType({
17778
17686
  issuer: stringType(),
17779
- authorization_endpoint: SafeUrlSchema,
17780
- token_endpoint: SafeUrlSchema,
17781
- registration_endpoint: SafeUrlSchema.optional(),
17687
+ authorization_endpoint: stringType(),
17688
+ token_endpoint: stringType(),
17689
+ registration_endpoint: stringType().optional(),
17782
17690
  scopes_supported: arrayType(stringType()).optional(),
17783
17691
  response_types_supported: arrayType(stringType()),
17784
17692
  response_modes_supported: arrayType(stringType()).optional(),
17785
17693
  grant_types_supported: arrayType(stringType()).optional(),
17786
17694
  token_endpoint_auth_methods_supported: arrayType(stringType()).optional(),
17787
17695
  token_endpoint_auth_signing_alg_values_supported: arrayType(stringType()).optional(),
17788
- service_documentation: SafeUrlSchema.optional(),
17789
- revocation_endpoint: SafeUrlSchema.optional(),
17696
+ service_documentation: stringType().optional(),
17697
+ revocation_endpoint: stringType().optional(),
17790
17698
  revocation_endpoint_auth_methods_supported: arrayType(stringType()).optional(),
17791
17699
  revocation_endpoint_auth_signing_alg_values_supported: arrayType(stringType()).optional(),
17792
17700
  introspection_endpoint: stringType().optional(),
@@ -17796,11 +17704,11 @@ const OAuthMetadataSchema = objectType({
17796
17704
  }).passthrough();
17797
17705
  const OpenIdProviderMetadataSchema = objectType({
17798
17706
  issuer: stringType(),
17799
- authorization_endpoint: SafeUrlSchema,
17800
- token_endpoint: SafeUrlSchema,
17801
- userinfo_endpoint: SafeUrlSchema.optional(),
17802
- jwks_uri: SafeUrlSchema,
17803
- registration_endpoint: SafeUrlSchema.optional(),
17707
+ authorization_endpoint: stringType(),
17708
+ token_endpoint: stringType(),
17709
+ userinfo_endpoint: stringType().optional(),
17710
+ jwks_uri: stringType(),
17711
+ registration_endpoint: stringType().optional(),
17804
17712
  scopes_supported: arrayType(stringType()).optional(),
17805
17713
  response_types_supported: arrayType(stringType()),
17806
17714
  response_modes_supported: arrayType(stringType()).optional(),
@@ -17828,8 +17736,8 @@ const OpenIdProviderMetadataSchema = objectType({
17828
17736
  request_parameter_supported: booleanType().optional(),
17829
17737
  request_uri_parameter_supported: booleanType().optional(),
17830
17738
  require_request_uri_registration: booleanType().optional(),
17831
- op_policy_uri: SafeUrlSchema.optional(),
17832
- op_tos_uri: SafeUrlSchema.optional()
17739
+ op_policy_uri: stringType().optional(),
17740
+ op_tos_uri: stringType().optional()
17833
17741
  }).passthrough();
17834
17742
  const OpenIdProviderDiscoveryMetadataSchema = OpenIdProviderMetadataSchema.merge(OAuthMetadataSchema.pick({
17835
17743
  code_challenge_methods_supported: true
@@ -17848,20 +17756,19 @@ const OAuthErrorResponseSchema = objectType({
17848
17756
  error_description: stringType().optional(),
17849
17757
  error_uri: stringType().optional()
17850
17758
  });
17851
- const OptionalSafeUrlSchema = SafeUrlSchema.optional().or(literalType("").transform(() => void 0));
17852
17759
  const OAuthClientMetadataSchema = objectType({
17853
- redirect_uris: arrayType(SafeUrlSchema),
17760
+ redirect_uris: arrayType(stringType()).refine((uris) => uris.every((uri2) => URL.canParse(uri2)), { message: "redirect_uris must contain valid URLs" }),
17854
17761
  token_endpoint_auth_method: stringType().optional(),
17855
17762
  grant_types: arrayType(stringType()).optional(),
17856
17763
  response_types: arrayType(stringType()).optional(),
17857
17764
  client_name: stringType().optional(),
17858
- client_uri: SafeUrlSchema.optional(),
17859
- logo_uri: OptionalSafeUrlSchema,
17765
+ client_uri: stringType().optional(),
17766
+ logo_uri: stringType().optional(),
17860
17767
  scope: stringType().optional(),
17861
17768
  contacts: arrayType(stringType()).optional(),
17862
- tos_uri: OptionalSafeUrlSchema,
17769
+ tos_uri: stringType().optional(),
17863
17770
  policy_uri: stringType().optional(),
17864
- jwks_uri: SafeUrlSchema.optional(),
17771
+ jwks_uri: stringType().optional(),
17865
17772
  jwks: anyType().optional(),
17866
17773
  software_id: stringType().optional(),
17867
17774
  software_version: stringType().optional(),
@@ -17994,8 +17901,6 @@ class UnauthorizedError extends Error {
17994
17901
  super(message !== null && message !== void 0 ? message : "Unauthorized");
17995
17902
  }
17996
17903
  }
17997
- const AUTHORIZATION_CODE_RESPONSE_TYPE = "code";
17998
- const AUTHORIZATION_CODE_CHALLENGE_METHOD = "S256";
17999
17904
  function selectClientAuthMethod(clientInformation, supportedMethods) {
18000
17905
  const hasClientSecret = clientInformation.client_secret !== void 0;
18001
17906
  if (supportedMethods.length === 0) {
@@ -18099,8 +18004,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope: sco
18099
18004
  }
18100
18005
  const fullInformation = await registerClient(authorizationServerUrl, {
18101
18006
  metadata: metadata2,
18102
- clientMetadata: provider.clientMetadata,
18103
- fetchFn
18007
+ clientMetadata: provider.clientMetadata
18104
18008
  });
18105
18009
  await provider.saveClientInformation(fullInformation);
18106
18010
  clientInformation = fullInformation;
@@ -18128,8 +18032,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope: sco
18128
18032
  clientInformation,
18129
18033
  refreshToken: tokens.refresh_token,
18130
18034
  resource,
18131
- addClientAuthentication: provider.addClientAuthentication,
18132
- fetchFn
18035
+ addClientAuthentication: provider.addClientAuthentication
18133
18036
  });
18134
18037
  await provider.saveTokens(newTokens);
18135
18038
  return "AUTHORIZED";
@@ -18226,7 +18129,7 @@ async function tryMetadataDiscovery(url, protocolVersion, fetchFn = fetch) {
18226
18129
  return await fetchWithCorsRetry(url, headers, fetchFn);
18227
18130
  }
18228
18131
  function shouldAttemptFallback(response, pathname) {
18229
- return !response || response.status >= 400 && response.status < 500 && pathname !== "/";
18132
+ return !response || response.status === 404 && pathname !== "/";
18230
18133
  }
18231
18134
  async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) {
18232
18135
  var _a, _b;
@@ -18308,15 +18211,13 @@ function buildDiscoveryUrls(authorizationServerUrl) {
18308
18211
  return urlsToTry;
18309
18212
  }
18310
18213
  async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn = fetch, protocolVersion = LATEST_PROTOCOL_VERSION } = {}) {
18311
- const headers = {
18312
- "MCP-Protocol-Version": protocolVersion,
18313
- Accept: "application/json"
18314
- };
18214
+ var _a;
18215
+ const headers = { "MCP-Protocol-Version": protocolVersion };
18315
18216
  const urlsToTry = buildDiscoveryUrls(authorizationServerUrl);
18316
18217
  for (const { url: endpointUrl, type: type2 } of urlsToTry) {
18317
18218
  const response = await fetchWithCorsRetry(endpointUrl, headers, fetchFn);
18318
18219
  if (!response) {
18319
- continue;
18220
+ throw new Error(`CORS error trying to load ${type2 === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${endpointUrl}`);
18320
18221
  }
18321
18222
  if (!response.ok) {
18322
18223
  if (response.status >= 400 && response.status < 500) {
@@ -18327,20 +18228,26 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
18327
18228
  if (type2 === "oauth") {
18328
18229
  return OAuthMetadataSchema.parse(await response.json());
18329
18230
  } else {
18330
- return OpenIdProviderDiscoveryMetadataSchema.parse(await response.json());
18231
+ const metadata2 = OpenIdProviderDiscoveryMetadataSchema.parse(await response.json());
18232
+ if (!((_a = metadata2.code_challenge_methods_supported) === null || _a === void 0 ? void 0 : _a.includes("S256"))) {
18233
+ throw new Error(`Incompatible OIDC provider at ${endpointUrl}: does not support S256 code challenge method required by MCP specification`);
18234
+ }
18235
+ return metadata2;
18331
18236
  }
18332
18237
  }
18333
18238
  return void 0;
18334
18239
  }
18335
18240
  async function startAuthorization(authorizationServerUrl, { metadata: metadata2, clientInformation, redirectUrl, scope: scope2, state, resource }) {
18241
+ const responseType = "code";
18242
+ const codeChallengeMethod = "S256";
18336
18243
  let authorizationUrl;
18337
18244
  if (metadata2) {
18338
18245
  authorizationUrl = new URL(metadata2.authorization_endpoint);
18339
- if (!metadata2.response_types_supported.includes(AUTHORIZATION_CODE_RESPONSE_TYPE)) {
18340
- throw new Error(`Incompatible auth server: does not support response type ${AUTHORIZATION_CODE_RESPONSE_TYPE}`);
18246
+ if (!metadata2.response_types_supported.includes(responseType)) {
18247
+ throw new Error(`Incompatible auth server: does not support response type ${responseType}`);
18341
18248
  }
18342
- if (metadata2.code_challenge_methods_supported && !metadata2.code_challenge_methods_supported.includes(AUTHORIZATION_CODE_CHALLENGE_METHOD)) {
18343
- throw new Error(`Incompatible auth server: does not support code challenge method ${AUTHORIZATION_CODE_CHALLENGE_METHOD}`);
18249
+ if (!metadata2.code_challenge_methods_supported || !metadata2.code_challenge_methods_supported.includes(codeChallengeMethod)) {
18250
+ throw new Error(`Incompatible auth server: does not support code challenge method ${codeChallengeMethod}`);
18344
18251
  }
18345
18252
  } else {
18346
18253
  authorizationUrl = new URL("/authorize", authorizationServerUrl);
@@ -18348,10 +18255,10 @@ async function startAuthorization(authorizationServerUrl, { metadata: metadata2,
18348
18255
  const challenge = await pkceChallenge();
18349
18256
  const codeVerifier = challenge.code_verifier;
18350
18257
  const codeChallenge = challenge.code_challenge;
18351
- authorizationUrl.searchParams.set("response_type", AUTHORIZATION_CODE_RESPONSE_TYPE);
18258
+ authorizationUrl.searchParams.set("response_type", responseType);
18352
18259
  authorizationUrl.searchParams.set("client_id", clientInformation.client_id);
18353
18260
  authorizationUrl.searchParams.set("code_challenge", codeChallenge);
18354
- authorizationUrl.searchParams.set("code_challenge_method", AUTHORIZATION_CODE_CHALLENGE_METHOD);
18261
+ authorizationUrl.searchParams.set("code_challenge_method", codeChallengeMethod);
18355
18262
  authorizationUrl.searchParams.set("redirect_uri", String(redirectUrl));
18356
18263
  if (state) {
18357
18264
  authorizationUrl.searchParams.set("state", state);
@@ -18376,7 +18283,7 @@ async function exchangeAuthorization(authorizationServerUrl, { metadata: metadat
18376
18283
  }
18377
18284
  const headers = new Headers({
18378
18285
  "Content-Type": "application/x-www-form-urlencoded",
18379
- Accept: "application/json"
18286
+ "Accept": "application/json"
18380
18287
  });
18381
18288
  const params = new URLSearchParams({
18382
18289
  grant_type: grantType,
@@ -18555,7 +18462,7 @@ function splitLines(chunk) {
18555
18462
  const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
18556
18463
  `, searchIndex);
18557
18464
  let lineEnd = -1;
18558
- 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) {
18465
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
18559
18466
  incompleteLine = chunk.slice(searchIndex);
18560
18467
  break;
18561
18468
  } else {
@@ -18856,11 +18763,7 @@ class SSEClientTransport {
18856
18763
  }
18857
18764
  let result;
18858
18765
  try {
18859
- result = await auth(this._authProvider, {
18860
- serverUrl: this._url,
18861
- resourceMetadataUrl: this._resourceMetadataUrl,
18862
- fetchFn: this._fetch
18863
- });
18766
+ result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
18864
18767
  } catch (error2) {
18865
18768
  (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error2);
18866
18769
  throw error2;
@@ -18959,12 +18862,7 @@ class SSEClientTransport {
18959
18862
  if (!this._authProvider) {
18960
18863
  throw new UnauthorizedError("No auth provider");
18961
18864
  }
18962
- const result = await auth(this._authProvider, {
18963
- serverUrl: this._url,
18964
- authorizationCode,
18965
- resourceMetadataUrl: this._resourceMetadataUrl,
18966
- fetchFn: this._fetch
18967
- });
18865
+ const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
18968
18866
  if (result !== "AUTHORIZED") {
18969
18867
  throw new UnauthorizedError("Failed to authorize");
18970
18868
  }
@@ -18994,11 +18892,7 @@ class SSEClientTransport {
18994
18892
  if (!response.ok) {
18995
18893
  if (response.status === 401 && this._authProvider) {
18996
18894
  this._resourceMetadataUrl = extractResourceMetadataUrl(response);
18997
- const result = await auth(this._authProvider, {
18998
- serverUrl: this._url,
18999
- resourceMetadataUrl: this._resourceMetadataUrl,
19000
- fetchFn: this._fetch
19001
- });
18895
+ const result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
19002
18896
  if (result !== "AUTHORIZED") {
19003
18897
  throw new UnauthorizedError();
19004
18898
  }
@@ -19053,7 +18947,6 @@ class StreamableHTTPError extends Error {
19053
18947
  class StreamableHTTPClientTransport {
19054
18948
  constructor(url, opts) {
19055
18949
  var _a;
19056
- this._hasCompletedAuthFlow = false;
19057
18950
  this._url = url;
19058
18951
  this._resourceMetadataUrl = void 0;
19059
18952
  this._requestInit = opts === null || opts === void 0 ? void 0 : opts.requestInit;
@@ -19069,11 +18962,7 @@ class StreamableHTTPClientTransport {
19069
18962
  }
19070
18963
  let result;
19071
18964
  try {
19072
- result = await auth(this._authProvider, {
19073
- serverUrl: this._url,
19074
- resourceMetadataUrl: this._resourceMetadataUrl,
19075
- fetchFn: this._fetch
19076
- });
18965
+ result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
19077
18966
  } catch (error2) {
19078
18967
  (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error2);
19079
18968
  throw error2;
@@ -19239,12 +19128,7 @@ class StreamableHTTPClientTransport {
19239
19128
  if (!this._authProvider) {
19240
19129
  throw new UnauthorizedError("No auth provider");
19241
19130
  }
19242
- const result = await auth(this._authProvider, {
19243
- serverUrl: this._url,
19244
- authorizationCode,
19245
- resourceMetadataUrl: this._resourceMetadataUrl,
19246
- fetchFn: this._fetch
19247
- });
19131
+ const result = await auth(this._authProvider, { serverUrl: this._url, authorizationCode, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
19248
19132
  if (result !== "AUTHORIZED") {
19249
19133
  throw new UnauthorizedError("Failed to authorize");
19250
19134
  }
@@ -19282,25 +19166,16 @@ class StreamableHTTPClientTransport {
19282
19166
  }
19283
19167
  if (!response.ok) {
19284
19168
  if (response.status === 401 && this._authProvider) {
19285
- if (this._hasCompletedAuthFlow) {
19286
- throw new StreamableHTTPError(401, "Server returned 401 after successful authentication");
19287
- }
19288
19169
  this._resourceMetadataUrl = extractResourceMetadataUrl(response);
19289
- const result = await auth(this._authProvider, {
19290
- serverUrl: this._url,
19291
- resourceMetadataUrl: this._resourceMetadataUrl,
19292
- fetchFn: this._fetch
19293
- });
19170
+ const result = await auth(this._authProvider, { serverUrl: this._url, resourceMetadataUrl: this._resourceMetadataUrl, fetchFn: this._fetch });
19294
19171
  if (result !== "AUTHORIZED") {
19295
19172
  throw new UnauthorizedError();
19296
19173
  }
19297
- this._hasCompletedAuthFlow = true;
19298
19174
  return this.send(message);
19299
19175
  }
19300
19176
  const text = await response.text().catch(() => null);
19301
19177
  throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
19302
19178
  }
19303
- this._hasCompletedAuthFlow = false;
19304
19179
  if (response.status === 202) {
19305
19180
  if (isInitializedNotification(message)) {
19306
19181
  this._startOrAuthSse({ resumptionToken: void 0 }).catch((err) => {
@@ -19383,12 +19258,6 @@ class Server extends Protocol {
19383
19258
  var _a;
19384
19259
  super(options);
19385
19260
  this._serverInfo = _serverInfo;
19386
- this._loggingLevels = /* @__PURE__ */ new Map();
19387
- this.LOG_LEVEL_SEVERITY = new Map(LoggingLevelSchema.options.map((level, index) => [level, index]));
19388
- this.isMessageIgnored = (level, sessionId) => {
19389
- const currentLevel = this._loggingLevels.get(sessionId);
19390
- return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false;
19391
- };
19392
19261
  this._capabilities = (_a = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a !== void 0 ? _a : {};
19393
19262
  this._instructions = options === null || options === void 0 ? void 0 : options.instructions;
19394
19263
  this.setRequestHandler(InitializeRequestSchema, (request) => this._oninitialize(request));
@@ -19396,18 +19265,6 @@ class Server extends Protocol {
19396
19265
  var _a2;
19397
19266
  return (_a2 = this.oninitialized) === null || _a2 === void 0 ? void 0 : _a2.call(this);
19398
19267
  });
19399
- if (this._capabilities.logging) {
19400
- this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => {
19401
- var _a2;
19402
- const transportSessionId = extra.sessionId || ((_a2 = extra.requestInfo) === null || _a2 === void 0 ? void 0 : _a2.headers["mcp-session-id"]) || void 0;
19403
- const { level } = request.params;
19404
- const parseResult = LoggingLevelSchema.safeParse(level);
19405
- if (parseResult.success) {
19406
- this._loggingLevels.set(transportSessionId, parseResult.data);
19407
- }
19408
- return {};
19409
- });
19410
- }
19411
19268
  }
19412
19269
  /**
19413
19270
  * Registers new capabilities. This can only be called before connecting to a transport.
@@ -19553,19 +19410,8 @@ class Server extends Protocol {
19553
19410
  async listRoots(params, options) {
19554
19411
  return this.request({ method: "roots/list", params }, ListRootsResultSchema, options);
19555
19412
  }
19556
- /**
19557
- * Sends a logging message to the client, if connected.
19558
- * Note: You only need to send the parameters object, not the entire JSON RPC message
19559
- * @see LoggingMessageNotification
19560
- * @param params
19561
- * @param sessionId optional for stateless and backward compatibility
19562
- */
19563
- async sendLoggingMessage(params, sessionId) {
19564
- if (this._capabilities.logging) {
19565
- if (!this.isMessageIgnored(params.level, sessionId)) {
19566
- return this.notification({ method: "notifications/message", params });
19567
- }
19568
- }
19413
+ async sendLoggingMessage(params) {
19414
+ return this.notification({ method: "notifications/message", params });
19569
19415
  }
19570
19416
  async sendResourceUpdated(params) {
19571
19417
  return this.notification({
@@ -20841,13 +20687,10 @@ class McpServer {
20841
20687
  inputSchema: tool.inputSchema ? zodToJsonSchema(tool.inputSchema, {
20842
20688
  strictUnions: true
20843
20689
  }) : EMPTY_OBJECT_JSON_SCHEMA,
20844
- annotations: tool.annotations,
20845
- _meta: tool._meta
20690
+ annotations: tool.annotations
20846
20691
  };
20847
20692
  if (tool.outputSchema) {
20848
- toolDefinition.outputSchema = zodToJsonSchema(tool.outputSchema, {
20849
- strictUnions: true
20850
- });
20693
+ toolDefinition.outputSchema = zodToJsonSchema(tool.outputSchema, { strictUnions: true });
20851
20694
  }
20852
20695
  return toolDefinition;
20853
20696
  })
@@ -21210,14 +21053,13 @@ class McpServer {
21210
21053
  this._registeredPrompts[name] = registeredPrompt;
21211
21054
  return registeredPrompt;
21212
21055
  }
21213
- _createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, _meta, callback) {
21056
+ _createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, callback) {
21214
21057
  const registeredTool = {
21215
21058
  title: title2,
21216
21059
  description: description2,
21217
21060
  inputSchema: inputSchema === void 0 ? void 0 : objectType(inputSchema),
21218
21061
  outputSchema: outputSchema === void 0 ? void 0 : objectType(outputSchema),
21219
21062
  annotations,
21220
- _meta,
21221
21063
  callback,
21222
21064
  enabled: true,
21223
21065
  disable: () => registeredTool.update({ enabled: false }),
@@ -21239,8 +21081,6 @@ class McpServer {
21239
21081
  registeredTool.callback = updates.callback;
21240
21082
  if (typeof updates.annotations !== "undefined")
21241
21083
  registeredTool.annotations = updates.annotations;
21242
- if (typeof updates._meta !== "undefined")
21243
- registeredTool._meta = updates._meta;
21244
21084
  if (typeof updates.enabled !== "undefined")
21245
21085
  registeredTool.enabled = updates.enabled;
21246
21086
  this.sendToolListChanged();
@@ -21277,7 +21117,7 @@ class McpServer {
21277
21117
  }
21278
21118
  }
21279
21119
  const callback = rest[0];
21280
- return this._createRegisteredTool(name, void 0, description2, inputSchema, outputSchema, annotations, void 0, callback);
21120
+ return this._createRegisteredTool(name, void 0, description2, inputSchema, outputSchema, annotations, callback);
21281
21121
  }
21282
21122
  /**
21283
21123
  * Registers a tool with a config object and callback.
@@ -21286,8 +21126,8 @@ class McpServer {
21286
21126
  if (this._registeredTools[name]) {
21287
21127
  throw new Error(`Tool ${name} is already registered`);
21288
21128
  }
21289
- const { title: title2, description: description2, inputSchema, outputSchema, annotations, _meta } = config;
21290
- return this._createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, _meta, cb);
21129
+ const { title: title2, description: description2, inputSchema, outputSchema, annotations } = config;
21130
+ return this._createRegisteredTool(name, title2, description2, inputSchema, outputSchema, annotations, cb);
21291
21131
  }
21292
21132
  prompt(name, ...rest) {
21293
21133
  if (this._registeredPrompts[name]) {
@@ -21327,16 +21167,6 @@ class McpServer {
21327
21167
  isConnected() {
21328
21168
  return this.server.transport !== void 0;
21329
21169
  }
21330
- /**
21331
- * Sends a logging message to the client, if connected.
21332
- * Note: You only need to send the parameters object, not the entire JSON RPC message
21333
- * @see LoggingMessageNotification
21334
- * @param params
21335
- * @param sessionId optional for stateless and backward compatibility
21336
- */
21337
- async sendLoggingMessage(params, sessionId) {
21338
- return this.server.sendLoggingMessage(params, sessionId);
21339
- }
21340
21170
  /**
21341
21171
  * Sends a resource list changed event to the client, if connected.
21342
21172
  */
@@ -21454,8 +21284,6 @@ export {
21454
21284
  ErrorCode,
21455
21285
  GetPromptRequestSchema,
21456
21286
  GetPromptResultSchema,
21457
- IconSchema,
21458
- IconsSchema,
21459
21287
  ImageContentSchema,
21460
21288
  ImplementationSchema,
21461
21289
  InitializeRequestSchema,