@dhaneshpurohit/mockstar 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7180,130 +7180,117 @@ function preflight(bunVersion = detectBunVersion()) {
7180
7180
  };
7181
7181
  }
7182
7182
 
7183
- // node_modules/hono/dist/compose.js
7184
- var compose = (middleware, onError, onNotFound) => {
7185
- return (context, next) => {
7186
- let index2 = -1;
7187
- return dispatch(0);
7188
- async function dispatch(i) {
7189
- if (i <= index2) {
7190
- throw new Error("next() called multiple times");
7191
- }
7192
- index2 = i;
7193
- let res;
7194
- let isError = false;
7195
- let handler;
7196
- if (middleware[i]) {
7197
- handler = middleware[i][0][0];
7198
- context.req.routeIndex = i;
7199
- } else {
7200
- handler = i === middleware.length && next || undefined;
7201
- }
7202
- if (handler) {
7203
- try {
7204
- res = await handler(context, () => dispatch(i + 1));
7205
- } catch (err) {
7206
- if (err instanceof Error && onError) {
7207
- context.error = err;
7208
- res = await onError(err, context);
7209
- isError = true;
7210
- } else {
7211
- throw err;
7212
- }
7213
- }
7214
- } else {
7215
- if (context.finalized === false && onNotFound) {
7216
- res = await onNotFound(context);
7217
- }
7218
- }
7219
- if (res && (context.finalized === false || isError)) {
7220
- context.res = res;
7221
- }
7222
- return context;
7223
- }
7224
- };
7183
+ // node_modules/hono/dist/http-exception.js
7184
+ var HTTPException = class extends Error {
7185
+ res;
7186
+ status;
7187
+ constructor(status = 500, options) {
7188
+ super(options?.message, { cause: options?.cause });
7189
+ this.res = options?.res;
7190
+ this.status = status;
7191
+ }
7192
+ getResponse() {
7193
+ if (this.res)
7194
+ return new Response(this.res.body, {
7195
+ status: this.status,
7196
+ headers: this.res.headers
7197
+ });
7198
+ return new Response(this.message, { status: this.status });
7199
+ }
7225
7200
  };
7226
7201
 
7227
7202
  // node_modules/hono/dist/request/constants.js
7228
- var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
7203
+ var GET_MATCH_RESULT = Symbol();
7204
+
7205
+ // node_modules/hono/dist/utils/buffer.js
7206
+ var bufferToFormData = (arrayBuffer, contentType) => {
7207
+ return new Response(arrayBuffer, { headers: { "Content-Type": contentType.replace(/^[^;]+/, (mediaType) => mediaType.toLowerCase()) } }).formData();
7208
+ };
7229
7209
 
7230
7210
  // node_modules/hono/dist/utils/body.js
7231
- var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
7211
+ var MAX_NESTED_OBJECTS = 1e4;
7212
+ var isRawRequest = (request) => ("headers" in request);
7213
+ var parseBody = async (request, options = Object.create(null)) => {
7232
7214
  const { all = false, dot = false } = options;
7233
- const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
7234
- const contentType = headers.get("Content-Type");
7235
- if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
7236
- return parseFormData(request, { all, dot });
7237
- }
7215
+ const mediaType = (isRawRequest(request) ? request.headers : request.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();
7216
+ if (mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded")
7217
+ return parseFormData(request, {
7218
+ all,
7219
+ dot
7220
+ });
7238
7221
  return {};
7239
7222
  };
7240
7223
  async function parseFormData(request, options) {
7241
- const formData = await request.formData();
7242
- if (formData) {
7224
+ if (!isRawRequest(request) && request.bodyCache.formData)
7225
+ return convertFormDataToBodyData(await request.bodyCache.formData, options);
7226
+ const headers = isRawRequest(request) ? request.headers : request.raw.headers;
7227
+ const arrayBuffer = await request.arrayBuffer();
7228
+ const formDataPromise = bufferToFormData(arrayBuffer, headers.get("Content-Type") || "");
7229
+ if (!isRawRequest(request))
7230
+ request.bodyCache.formData = formDataPromise;
7231
+ const formData = await formDataPromise;
7232
+ if (formData)
7243
7233
  return convertFormDataToBodyData(formData, options);
7244
- }
7245
7234
  return {};
7246
7235
  }
7247
7236
  function convertFormDataToBodyData(formData, options) {
7248
- const form = /* @__PURE__ */ Object.create(null);
7237
+ const form = Object.create(null);
7238
+ const nestingState = { count: 0 };
7249
7239
  formData.forEach((value, key) => {
7250
- const shouldParseAllValues = options.all || key.endsWith("[]");
7251
- if (!shouldParseAllValues) {
7240
+ if (!(options.all || key.endsWith("[]")))
7252
7241
  form[key] = value;
7253
- } else {
7242
+ else
7254
7243
  handleParsingAllValues(form, key, value);
7255
- }
7256
7244
  });
7257
- if (options.dot) {
7245
+ if (options.dot)
7258
7246
  Object.entries(form).forEach(([key, value]) => {
7259
- const shouldParseDotValues = key.includes(".");
7260
- if (shouldParseDotValues) {
7261
- handleParsingNestedValues(form, key, value);
7247
+ if (key.includes(".")) {
7248
+ handleParsingNestedValues(form, key, value, nestingState);
7262
7249
  delete form[key];
7263
7250
  }
7264
7251
  });
7265
- }
7266
7252
  return form;
7267
7253
  }
7268
7254
  var handleParsingAllValues = (form, key, value) => {
7269
7255
  if (form[key] !== undefined) {
7270
- if (Array.isArray(form[key])) {
7256
+ if (Array.isArray(form[key]))
7271
7257
  form[key].push(value);
7272
- } else {
7258
+ else
7273
7259
  form[key] = [form[key], value];
7274
- }
7275
- } else {
7276
- if (!key.endsWith("[]")) {
7277
- form[key] = value;
7278
- } else {
7279
- form[key] = [value];
7280
- }
7281
- }
7260
+ } else if (!key.endsWith("[]"))
7261
+ form[key] = value;
7262
+ else
7263
+ form[key] = [value];
7282
7264
  };
7283
- var handleParsingNestedValues = (form, key, value) => {
7284
- if (/(?:^|\.)__proto__\./.test(key)) {
7265
+ var handleParsingNestedValues = (form, key, value, state) => {
7266
+ if (/(?:^|\.)__proto__\./.test(key))
7285
7267
  return;
7286
- }
7287
7268
  let nestedForm = form;
7288
- const keys = key.split(".");
7269
+ const keys = key.split(".", 34);
7270
+ if (keys.length > 33)
7271
+ throwNestingLimitExceeded();
7289
7272
  keys.forEach((key2, index2) => {
7290
- if (index2 === keys.length - 1) {
7273
+ if (index2 === keys.length - 1)
7291
7274
  nestedForm[key2] = value;
7292
- } else {
7275
+ else {
7293
7276
  if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
7294
- nestedForm[key2] = /* @__PURE__ */ Object.create(null);
7277
+ if (state.count++ >= MAX_NESTED_OBJECTS)
7278
+ throwNestingLimitExceeded();
7279
+ nestedForm[key2] = Object.create(null);
7295
7280
  }
7296
7281
  nestedForm = nestedForm[key2];
7297
7282
  }
7298
7283
  });
7299
7284
  };
7285
+ var throwNestingLimitExceeded = () => {
7286
+ throw new Error("Nesting limit exceeded");
7287
+ };
7300
7288
 
7301
7289
  // node_modules/hono/dist/utils/url.js
7302
7290
  var splitPath2 = (path) => {
7303
7291
  const paths = path.split("/");
7304
- if (paths[0] === "") {
7292
+ if (paths[0] === "")
7305
7293
  paths.shift();
7306
- }
7307
7294
  return paths;
7308
7295
  };
7309
7296
  var splitRoutingPath = (routePath) => {
@@ -7318,34 +7305,46 @@ var extractGroupsFromPath = (path) => {
7318
7305
  groups.push([mark, match]);
7319
7306
  return mark;
7320
7307
  });
7321
- return { groups, path };
7308
+ return {
7309
+ groups,
7310
+ path
7311
+ };
7322
7312
  };
7323
7313
  var replaceGroupMarks = (paths, groups) => {
7324
7314
  for (let i = groups.length - 1;i >= 0; i--) {
7325
7315
  const [mark] = groups[i];
7326
- for (let j = paths.length - 1;j >= 0; j--) {
7316
+ for (let j = paths.length - 1;j >= 0; j--)
7327
7317
  if (paths[j].includes(mark)) {
7328
7318
  paths[j] = paths[j].replace(mark, groups[i][1]);
7329
7319
  break;
7330
7320
  }
7331
- }
7332
7321
  }
7333
7322
  return paths;
7334
7323
  };
7335
7324
  var patternCache = {};
7336
7325
  var getPattern = (label, next) => {
7337
- if (label === "*") {
7326
+ if (label === "*")
7338
7327
  return "*";
7339
- }
7340
7328
  const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
7341
7329
  if (match) {
7342
7330
  const cacheKey = `${label}#${next}`;
7343
7331
  if (!patternCache[cacheKey]) {
7344
- if (match[2]) {
7345
- patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match[1], new RegExp(`^${match[2]}(?=/${next})`)] : [label, match[1], new RegExp(`^${match[2]}$`)];
7346
- } else {
7347
- patternCache[cacheKey] = [label, match[1], true];
7348
- }
7332
+ if (match[2])
7333
+ patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [
7334
+ cacheKey,
7335
+ match[1],
7336
+ new RegExp(`^${match[2]}(?=/${next})`)
7337
+ ] : [
7338
+ label,
7339
+ match[1],
7340
+ new RegExp(`^${match[2]}$`)
7341
+ ];
7342
+ else
7343
+ patternCache[cacheKey] = [
7344
+ label,
7345
+ match[1],
7346
+ true
7347
+ ];
7349
7348
  }
7350
7349
  return patternCache[cacheKey];
7351
7350
  }
@@ -7364,7 +7363,7 @@ var tryDecode = (str, decoder) => {
7364
7363
  });
7365
7364
  }
7366
7365
  };
7367
- var tryDecodeURI = (str) => tryDecode(str, decodeURI);
7366
+ var decodeURIWithPreservedPercent = (value) => decodeURI(value.includes("%25") ? value.replace(/%25/g, "%2525") : value);
7368
7367
  var getPath = (request) => {
7369
7368
  const url = request.url;
7370
7369
  const start = url.indexOf("/", url.indexOf(":") + 4);
@@ -7376,10 +7375,16 @@ var getPath = (request) => {
7376
7375
  const hashIndex = url.indexOf("#", i);
7377
7376
  const end = queryIndex === -1 ? hashIndex === -1 ? undefined : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
7378
7377
  const path = url.slice(start, end);
7379
- return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
7380
- } else if (charCode === 63 || charCode === 35) {
7378
+ const decoded = tryDecode(path, decodeURIWithPreservedPercent);
7379
+ if (/%(?![0-9A-Fa-f]{2})/.test(path)) {
7380
+ const rewritten = new URL("http://localhost");
7381
+ rewritten.pathname = decoded.replace(/[\\\t\n\r]/g, encodeURIComponent);
7382
+ if (tryDecode(rewritten.pathname, decodeURIWithPreservedPercent) !== decoded)
7383
+ return tryDecode(path.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"), decodeURIWithPreservedPercent);
7384
+ }
7385
+ return decoded;
7386
+ } else if (charCode === 63 || charCode === 35)
7381
7387
  break;
7382
- }
7383
7388
  }
7384
7389
  return url.slice(start, i);
7385
7390
  };
@@ -7388,107 +7393,98 @@ var getPathNoStrict = (request) => {
7388
7393
  return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
7389
7394
  };
7390
7395
  var mergePath = (base, sub, ...rest) => {
7391
- if (rest.length) {
7396
+ if (rest.length)
7392
7397
  sub = mergePath(sub, ...rest);
7393
- }
7394
7398
  return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
7395
7399
  };
7396
7400
  var checkOptionalParameter = (path) => {
7397
- if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) {
7401
+ if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":"))
7398
7402
  return null;
7399
- }
7400
7403
  const segments = path.split("/");
7401
7404
  const results = [];
7402
7405
  let basePath = "";
7403
7406
  segments.forEach((segment) => {
7404
- if (segment !== "" && !/\:/.test(segment)) {
7407
+ if (segment !== "" && !/\:/.test(segment))
7405
7408
  basePath += "/" + segment;
7406
- } else if (/\:/.test(segment)) {
7407
- if (/\?/.test(segment)) {
7408
- if (results.length === 0 && basePath === "") {
7409
+ else if (/\:/.test(segment)) {
7410
+ if (segment.charCodeAt(segment.length - 1) === 63) {
7411
+ if (results.length === 0 && basePath === "")
7409
7412
  results.push("/");
7410
- } else {
7413
+ else
7411
7414
  results.push(basePath);
7412
- }
7413
- const optionalSegment = segment.replace("?", "");
7415
+ const optionalSegment = segment.slice(0, -1);
7414
7416
  basePath += "/" + optionalSegment;
7415
7417
  results.push(basePath);
7416
- } else {
7418
+ } else
7417
7419
  basePath += "/" + segment;
7418
- }
7419
7420
  }
7420
7421
  });
7421
7422
  return results.filter((v, i, a) => a.indexOf(v) === i);
7422
7423
  };
7424
+ var tryDecodeURIComponent = (str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str;
7423
7425
  var _decodeURI = (value) => {
7424
- if (!/[%+]/.test(value)) {
7425
- return value;
7426
- }
7427
- if (value.indexOf("+") !== -1) {
7426
+ if (value.indexOf("+") !== -1)
7428
7427
  value = value.replace(/\+/g, " ");
7429
- }
7430
- return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
7428
+ return tryDecodeURIComponent(value);
7431
7429
  };
7432
7430
  var _getQueryParam = (url, key, multiple) => {
7431
+ const hashIndex = url.indexOf("#", 8);
7432
+ if (hashIndex !== -1)
7433
+ url = url.slice(0, hashIndex);
7433
7434
  let encoded;
7434
- if (!multiple && key && !/[%+]/.test(key)) {
7435
- let keyIndex2 = url.indexOf("?", 8);
7436
- if (keyIndex2 === -1) {
7435
+ if (!multiple && key && !/[%+&=]/.test(key)) {
7436
+ const queryIndex = url.indexOf("?", 8);
7437
+ let keyIndex2 = queryIndex;
7438
+ if (keyIndex2 === -1)
7437
7439
  return;
7438
- }
7439
- if (!url.startsWith(key, keyIndex2 + 1)) {
7440
+ if (!url.startsWith(key, keyIndex2 + 1))
7440
7441
  keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
7441
- }
7442
7442
  while (keyIndex2 !== -1) {
7443
7443
  const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
7444
- if (trailingKeyCode === 61) {
7445
- const valueIndex = keyIndex2 + key.length + 2;
7446
- const endIndex = url.indexOf("&", valueIndex);
7447
- return _decodeURI(url.slice(valueIndex, endIndex === -1 ? undefined : endIndex));
7448
- } else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
7444
+ if (trailingKeyCode === 61 || trailingKeyCode === 38 || isNaN(trailingKeyCode)) {
7445
+ if (keyIndex2 > queryIndex && /(?:^|&)[^=&]*[%+]/.test(url.slice(queryIndex + 1, keyIndex2)))
7446
+ break;
7447
+ if (trailingKeyCode === 61) {
7448
+ const valueIndex = keyIndex2 + key.length + 2;
7449
+ const endIndex = url.indexOf("&", valueIndex);
7450
+ return _decodeURI(url.slice(valueIndex, endIndex === -1 ? undefined : endIndex));
7451
+ }
7449
7452
  return "";
7450
7453
  }
7451
7454
  keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
7452
7455
  }
7453
7456
  encoded = /[%+]/.test(url);
7454
- if (!encoded) {
7457
+ if (!encoded)
7455
7458
  return;
7456
- }
7457
7459
  }
7458
- const results = {};
7460
+ const results = Object.create(null);
7459
7461
  encoded ??= /[%+]/.test(url);
7460
7462
  let keyIndex = url.indexOf("?", 8);
7461
7463
  while (keyIndex !== -1) {
7462
7464
  const nextKeyIndex = url.indexOf("&", keyIndex + 1);
7463
7465
  let valueIndex = url.indexOf("=", keyIndex);
7464
- if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
7466
+ if (valueIndex > nextKeyIndex && nextKeyIndex !== -1)
7465
7467
  valueIndex = -1;
7466
- }
7467
7468
  let name = url.slice(keyIndex + 1, valueIndex === -1 ? nextKeyIndex === -1 ? undefined : nextKeyIndex : valueIndex);
7468
- if (encoded) {
7469
+ if (encoded)
7469
7470
  name = _decodeURI(name);
7470
- }
7471
7471
  keyIndex = nextKeyIndex;
7472
- if (name === "") {
7472
+ if (name === "")
7473
7473
  continue;
7474
- }
7475
7474
  let value;
7476
- if (valueIndex === -1) {
7475
+ if (valueIndex === -1)
7477
7476
  value = "";
7478
- } else {
7477
+ else {
7479
7478
  value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? undefined : nextKeyIndex);
7480
- if (encoded) {
7479
+ if (encoded)
7481
7480
  value = _decodeURI(value);
7482
- }
7483
7481
  }
7484
7482
  if (multiple) {
7485
- if (!(results[name] && Array.isArray(results[name]))) {
7483
+ if (!(results[name] && Array.isArray(results[name])))
7486
7484
  results[name] = [];
7487
- }
7488
7485
  results[name].push(value);
7489
- } else {
7486
+ } else
7490
7487
  results[name] ??= value;
7491
- }
7492
7488
  }
7493
7489
  return key ? results[key] : results;
7494
7490
  };
@@ -7499,7 +7495,6 @@ var getQueryParams = (url, key) => {
7499
7495
  var decodeURIComponent_ = decodeURIComponent;
7500
7496
 
7501
7497
  // node_modules/hono/dist/request.js
7502
- var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
7503
7498
  var HonoRequest = class {
7504
7499
  raw;
7505
7500
  #validatedData;
@@ -7511,24 +7506,22 @@ var HonoRequest = class {
7511
7506
  this.raw = request;
7512
7507
  this.path = path;
7513
7508
  this.#matchResult = matchResult;
7514
- this.#validatedData = {};
7515
7509
  }
7516
7510
  param(key) {
7517
7511
  return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
7518
7512
  }
7519
7513
  #getDecodedParam(key) {
7520
- const paramKey = this.#matchResult[0][this.routeIndex][1][key];
7514
+ const paramKey = this.#matchResult[0][this.routeIndex]?.[1][key];
7521
7515
  const param = this.#getParamValue(paramKey);
7522
- return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
7516
+ return param && tryDecodeURIComponent(param);
7523
7517
  }
7524
7518
  #getAllDecodedParams() {
7525
7519
  const decoded = {};
7526
- const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
7520
+ const keys = Object.keys(this.#matchResult[0][this.routeIndex]?.[1] ?? {});
7527
7521
  for (const key of keys) {
7528
7522
  const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
7529
- if (value !== undefined) {
7530
- decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
7531
- }
7523
+ if (value !== undefined)
7524
+ decoded[key] = tryDecodeURIComponent(value);
7532
7525
  }
7533
7526
  return decoded;
7534
7527
  }
@@ -7542,10 +7535,9 @@ var HonoRequest = class {
7542
7535
  return getQueryParams(this.url, key);
7543
7536
  }
7544
7537
  header(name) {
7545
- if (name) {
7538
+ if (name)
7546
7539
  return this.raw.headers.get(name) ?? undefined;
7547
- }
7548
- const headerData = {};
7540
+ const headerData = Object.create(null);
7549
7541
  this.raw.headers.forEach((value, key) => {
7550
7542
  headerData[key] = value;
7551
7543
  });
@@ -7557,18 +7549,15 @@ var HonoRequest = class {
7557
7549
  #cachedBody = (key) => {
7558
7550
  const { bodyCache, raw } = this;
7559
7551
  const cachedBody = bodyCache[key];
7560
- if (cachedBody) {
7552
+ if (cachedBody)
7561
7553
  return cachedBody;
7562
- }
7563
- const anyCachedKey = Object.keys(bodyCache)[0];
7564
- if (anyCachedKey) {
7554
+ for (const anyCachedKey in bodyCache)
7565
7555
  return bodyCache[anyCachedKey].then((body) => {
7566
- if (anyCachedKey === "json") {
7556
+ if (anyCachedKey === "json")
7567
7557
  body = JSON.stringify(body);
7568
- }
7569
- return new Response(body)[key]();
7558
+ const contentType = anyCachedKey === "formData" ? undefined : raw.headers.get("content-type");
7559
+ return new Response(body, { headers: contentType ? { "Content-Type": contentType } : undefined })[key]();
7570
7560
  });
7571
- }
7572
7561
  return bodyCache[key] = raw[key]();
7573
7562
  };
7574
7563
  json() {
@@ -7580,6 +7569,9 @@ var HonoRequest = class {
7580
7569
  arrayBuffer() {
7581
7570
  return this.#cachedBody("arrayBuffer");
7582
7571
  }
7572
+ bytes() {
7573
+ return this.#cachedBody("arrayBuffer").then((buffer) => new Uint8Array(buffer));
7574
+ }
7583
7575
  blob() {
7584
7576
  return this.#cachedBody("blob");
7585
7577
  }
@@ -7587,10 +7579,10 @@ var HonoRequest = class {
7587
7579
  return this.#cachedBody("formData");
7588
7580
  }
7589
7581
  addValidatedData(target, data) {
7590
- this.#validatedData[target] = data;
7582
+ (this.#validatedData ??= {})[target] = data;
7591
7583
  }
7592
7584
  valid(target) {
7593
- return this.#validatedData[target];
7585
+ return this.#validatedData?.[target];
7594
7586
  }
7595
7587
  get url() {
7596
7588
  return this.raw.url;
@@ -7623,28 +7615,27 @@ var raw = (value, callbacks) => {
7623
7615
  };
7624
7616
  var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
7625
7617
  if (typeof str === "object" && !(str instanceof String)) {
7626
- if (!(str instanceof Promise)) {
7618
+ if (!(str instanceof Promise))
7627
7619
  str = str.toString();
7628
- }
7629
- if (str instanceof Promise) {
7620
+ if (str instanceof Promise)
7630
7621
  str = await str;
7631
- }
7632
7622
  }
7633
7623
  const callbacks = str.callbacks;
7634
- if (!callbacks?.length) {
7624
+ if (!callbacks?.length)
7635
7625
  return Promise.resolve(str);
7636
- }
7637
- if (buffer) {
7626
+ if (buffer)
7638
7627
  buffer[0] += str;
7639
- } else {
7628
+ else
7640
7629
  buffer = [str];
7641
- }
7642
- const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then((res) => Promise.all(res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))).then(() => buffer[0]));
7643
- if (preserveCallbacks) {
7630
+ const resStr = Promise.all(callbacks.map((c) => c({
7631
+ phase,
7632
+ buffer,
7633
+ context
7634
+ }))).then((res) => Promise.all(res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))).then(() => buffer[0]));
7635
+ if (preserveCallbacks)
7644
7636
  return raw(await resStr, callbacks);
7645
- } else {
7637
+ else
7646
7638
  return resStr;
7647
- }
7648
7639
  };
7649
7640
 
7650
7641
  // node_modules/hono/dist/context.js
@@ -7687,40 +7678,33 @@ var Context = class {
7687
7678
  return this.#req;
7688
7679
  }
7689
7680
  get event() {
7690
- if (this.#executionCtx && "respondWith" in this.#executionCtx) {
7681
+ if (this.#executionCtx && "respondWith" in this.#executionCtx)
7691
7682
  return this.#executionCtx;
7692
- } else {
7683
+ else
7693
7684
  throw Error("This context has no FetchEvent");
7694
- }
7695
7685
  }
7696
7686
  get executionCtx() {
7697
- if (this.#executionCtx) {
7687
+ if (this.#executionCtx)
7698
7688
  return this.#executionCtx;
7699
- } else {
7689
+ else
7700
7690
  throw Error("This context has no ExecutionContext");
7701
- }
7702
7691
  }
7703
7692
  get res() {
7704
- return this.#res ||= createResponseInstance(null, {
7705
- headers: this.#preparedHeaders ??= new Headers
7706
- });
7693
+ return this.#res ||= createResponseInstance(null, { headers: this.#preparedHeaders ??= new Headers });
7707
7694
  }
7708
7695
  set res(_res) {
7709
7696
  if (this.#res && _res) {
7710
7697
  _res = createResponseInstance(_res.body, _res);
7711
7698
  for (const [k, v] of this.#res.headers.entries()) {
7712
- if (k === "content-type") {
7699
+ if (k === "content-type")
7713
7700
  continue;
7714
- }
7715
7701
  if (k === "set-cookie") {
7716
7702
  const cookies = this.#res.headers.getSetCookie();
7717
7703
  _res.headers.delete("set-cookie");
7718
- for (const cookie of cookies) {
7704
+ for (const cookie of cookies)
7719
7705
  _res.headers.append("set-cookie", cookie);
7720
- }
7721
- } else {
7706
+ } else
7722
7707
  _res.headers.set(k, v);
7723
- }
7724
7708
  }
7725
7709
  }
7726
7710
  this.#res = _res;
@@ -7736,17 +7720,15 @@ var Context = class {
7736
7720
  this.#renderer = renderer;
7737
7721
  };
7738
7722
  header = (name, value, options) => {
7739
- if (this.finalized) {
7723
+ if (this.finalized && !this.#res.bodyUsed)
7740
7724
  this.#res = createResponseInstance(this.#res.body, this.#res);
7741
- }
7742
7725
  const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers;
7743
- if (value === undefined) {
7726
+ if (value === undefined)
7744
7727
  headers.delete(name);
7745
- } else if (options?.append) {
7728
+ else if (options?.append)
7746
7729
  headers.append(name, value);
7747
- } else {
7730
+ else
7748
7731
  headers.set(name, value);
7749
- }
7750
7732
  };
7751
7733
  status = (status) => {
7752
7734
  this.#status = status;
@@ -7759,37 +7741,46 @@ var Context = class {
7759
7741
  return this.#var ? this.#var.get(key) : undefined;
7760
7742
  };
7761
7743
  get var() {
7762
- if (!this.#var) {
7744
+ if (!this.#var)
7763
7745
  return {};
7764
- }
7765
7746
  return Object.fromEntries(this.#var);
7766
7747
  }
7767
7748
  #newResponse(data, arg, headers) {
7768
- const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers;
7769
- if (typeof arg === "object" && "headers" in arg) {
7770
- const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
7771
- for (const [key, value] of argHeaders) {
7772
- if (key.toLowerCase() === "set-cookie") {
7749
+ let responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders;
7750
+ if (typeof arg === "object" && arg.headers) {
7751
+ responseHeaders ??= new Headers;
7752
+ for (const [key, value] of new Headers(arg.headers))
7753
+ if (key === "set-cookie")
7773
7754
  responseHeaders.append(key, value);
7774
- } else {
7755
+ else
7775
7756
  responseHeaders.set(key, value);
7776
- }
7777
- }
7778
7757
  }
7779
7758
  if (headers) {
7780
- for (const [k, v] of Object.entries(headers)) {
7781
- if (typeof v === "string") {
7782
- responseHeaders.set(k, v);
7783
- } else {
7784
- responseHeaders.delete(k);
7785
- for (const v2 of v) {
7786
- responseHeaders.append(k, v2);
7759
+ if (!responseHeaders) {
7760
+ let count = 0;
7761
+ for (const k in headers)
7762
+ if (++count > 1 || typeof headers[k] !== "string") {
7763
+ responseHeaders = new Headers;
7764
+ break;
7787
7765
  }
7788
- }
7789
7766
  }
7767
+ if (responseHeaders)
7768
+ for (const k in headers) {
7769
+ const v = headers[k];
7770
+ if (typeof v === "string")
7771
+ responseHeaders.set(k, v);
7772
+ else {
7773
+ responseHeaders.delete(k);
7774
+ for (const v2 of v)
7775
+ responseHeaders.append(k, v2);
7776
+ }
7777
+ }
7790
7778
  }
7791
7779
  const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
7792
- return createResponseInstance(data, { status, headers: responseHeaders });
7780
+ return createResponseInstance(data, {
7781
+ status,
7782
+ headers: responseHeaders ?? headers
7783
+ });
7793
7784
  }
7794
7785
  newResponse = (...args) => this.#newResponse(...args);
7795
7786
  body = (data, arg, headers) => this.#newResponse(data, arg, headers);
@@ -7814,10 +7805,57 @@ var Context = class {
7814
7805
  };
7815
7806
  };
7816
7807
 
7808
+ // node_modules/hono/dist/compose.js
7809
+ var compose = (middleware, onError, onNotFound) => {
7810
+ return (context, next) => {
7811
+ let index2 = -1;
7812
+ return dispatch(0);
7813
+ async function dispatch(i) {
7814
+ if (i <= index2)
7815
+ throw new Error("next() called multiple times");
7816
+ index2 = i;
7817
+ let res;
7818
+ let isError = false;
7819
+ let handler;
7820
+ if (middleware[i]) {
7821
+ handler = middleware[i][0][0];
7822
+ context.req.routeIndex = i;
7823
+ } else
7824
+ handler = i === middleware.length && next || undefined;
7825
+ if (handler)
7826
+ try {
7827
+ res = await handler(context, () => dispatch(i + 1));
7828
+ } catch (err) {
7829
+ if (err instanceof Error && onError) {
7830
+ context.error = err;
7831
+ res = await onError(err, context);
7832
+ isError = true;
7833
+ } else
7834
+ throw err;
7835
+ }
7836
+ else if (context.finalized === false && onNotFound)
7837
+ res = await onNotFound(context);
7838
+ if (res && (context.finalized === false || isError))
7839
+ context.res = res;
7840
+ return context;
7841
+ }
7842
+ };
7843
+ };
7844
+
7845
+ // node_modules/hono/dist/helper/route/index.js
7846
+ var matchedRoutes = (c) => c.req[GET_MATCH_RESULT][0].map(([[, route]]) => route);
7847
+ var routePath = (c, index2) => matchedRoutes(c).at(index2 ?? c.req.routeIndex)?.path ?? "";
7848
+
7817
7849
  // node_modules/hono/dist/router.js
7818
- var METHOD_NAME_ALL = "ALL";
7819
- var METHOD_NAME_ALL_LOWERCASE = "all";
7820
- var METHODS = ["get", "post", "put", "delete", "options", "patch"];
7850
+ var METHODS = [
7851
+ "get",
7852
+ "post",
7853
+ "put",
7854
+ "delete",
7855
+ "options",
7856
+ "patch",
7857
+ "query"
7858
+ ];
7821
7859
  var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
7822
7860
  var UnsupportedPathError = class extends Error {
7823
7861
  };
@@ -7825,6 +7863,61 @@ var UnsupportedPathError = class extends Error {
7825
7863
  // node_modules/hono/dist/utils/constants.js
7826
7864
  var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
7827
7865
 
7866
+ // node_modules/hono/dist/utils/mount.js
7867
+ var countTrailingSlashes = (path) => {
7868
+ let index2 = path.length;
7869
+ while (index2 > 0 && path.charCodeAt(index2 - 1) === 47)
7870
+ index2--;
7871
+ return path.length - index2;
7872
+ };
7873
+ var getPathPrefixLength = (c, pathPrefix, routePath2) => {
7874
+ if (!/[:*]/.test(pathPrefix))
7875
+ return pathPrefix.length;
7876
+ const path = c.req.path;
7877
+ const matchResult = c.req[GET_MATCH_RESULT];
7878
+ const paramNames = /* @__PURE__ */ new Set;
7879
+ let length = 0;
7880
+ for (const part of splitRoutingPath(pathPrefix)) {
7881
+ if (part[0] === ":" && part.endsWith("}?"))
7882
+ throw new Error(`mount(): Optional regular expression parameters are not supported in "${routePath2}".`);
7883
+ const pattern = getPattern(part);
7884
+ if (pattern && pattern !== "*") {
7885
+ const name = pattern[1];
7886
+ if (paramNames.has(name))
7887
+ throw new Error(`mount(): Duplicate path parameter "${name}" in "${routePath2}".`);
7888
+ paramNames.add(name);
7889
+ }
7890
+ if (pattern && pattern !== "*" && pattern[2] !== true) {
7891
+ const value = matchResult.length === 2 ? matchResult[1][matchResult[0][c.req.routeIndex][1][pattern[1]]] : matchResult[0][c.req.routeIndex][1][pattern[1]];
7892
+ length += value.length + 1;
7893
+ } else if (pattern || part.endsWith("*")) {
7894
+ const end = path.indexOf("/", length + 1);
7895
+ length = end === -1 ? path.length : end;
7896
+ } else
7897
+ length += part.length + 1;
7898
+ }
7899
+ return length;
7900
+ };
7901
+ var createMountedRequest = (c, pathPrefix, routePath2) => {
7902
+ if (/[^/]\*$/.test(routePath2))
7903
+ throw new Error(`mount(): Wildcard must follow "/" in "${routePath2}".`);
7904
+ const prefixLength = getPathPrefixLength(c, pathPrefix, routePath2);
7905
+ const path = c.req.path.slice(prefixLength) || "/";
7906
+ if (prefixLength > c.req.path.length || path[0] !== "/" || /\/(?:\.|%2e){1,2}(?:\/|$)/i.test(path))
7907
+ throw new HTTPException(400, { message: "Invalid mounted path" });
7908
+ const rawUrl = c.req.raw.url;
7909
+ if (/^[^/?#]*\/\/[^/?#\\]*[?#\\]/.test(rawUrl))
7910
+ throw new HTTPException(400, { message: "Invalid mounted path" });
7911
+ const rawPathEnd = rawUrl.search(/[?#]/);
7912
+ const rawTrailingSlashes = countTrailingSlashes(rawPathEnd === -1 ? rawUrl : rawUrl.slice(0, rawPathEnd));
7913
+ if (rawTrailingSlashes > 1 && countTrailingSlashes(c.req.path) === rawTrailingSlashes - 1)
7914
+ throw new HTTPException(400, { message: "Invalid mounted path" });
7915
+ const url = new URL(rawUrl);
7916
+ url.pathname = path.replace(/[\\\t\n\r]/g, encodeURIComponent);
7917
+ if (path.includes("%")) {}
7918
+ return new Request(url, c.req.raw);
7919
+ };
7920
+
7828
7921
  // node_modules/hono/dist/hono-base.js
7829
7922
  var notFoundHandler = (c) => {
7830
7923
  return c.text("404 Not Found", 404);
@@ -7837,13 +7930,14 @@ var errorHandler = (err, c) => {
7837
7930
  console.error(err);
7838
7931
  return c.text("Internal Server Error", 500);
7839
7932
  };
7840
- var Hono = class _Hono {
7933
+ var Hono = class Hono2 {
7841
7934
  get;
7842
7935
  post;
7843
7936
  put;
7844
7937
  delete;
7845
7938
  options;
7846
7939
  patch;
7940
+ query;
7847
7941
  all;
7848
7942
  on;
7849
7943
  use;
@@ -7853,16 +7947,15 @@ var Hono = class _Hono {
7853
7947
  #path = "/";
7854
7948
  routes = [];
7855
7949
  constructor(options = {}) {
7856
- const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
7857
- allMethods.forEach((method) => {
7950
+ [...METHODS, "all"].forEach((method) => {
7858
7951
  this[method] = (args1, ...args) => {
7859
- if (typeof args1 === "string") {
7952
+ const methodName = method.toUpperCase();
7953
+ if (typeof args1 === "string")
7860
7954
  this.#path = args1;
7861
- } else {
7862
- this.#addRoute(method, this.#path, args1);
7863
- }
7955
+ else
7956
+ this.#addRoute(methodName, this.#path, args1);
7864
7957
  args.forEach((handler) => {
7865
- this.#addRoute(method, this.#path, handler);
7958
+ this.#addRoute(methodName, this.#path, handler);
7866
7959
  });
7867
7960
  return this;
7868
7961
  };
@@ -7871,22 +7964,22 @@ var Hono = class _Hono {
7871
7964
  for (const p of [path].flat()) {
7872
7965
  this.#path = p;
7873
7966
  for (const m of [method].flat()) {
7874
- handlers.map((handler) => {
7875
- this.#addRoute(m.toUpperCase(), this.#path, handler);
7876
- });
7967
+ const methodName = m.toUpperCase();
7968
+ for (const handler of handlers)
7969
+ this.#addRoute(methodName, this.#path, handler);
7877
7970
  }
7878
7971
  }
7879
7972
  return this;
7880
7973
  };
7881
7974
  this.use = (arg1, ...handlers) => {
7882
- if (typeof arg1 === "string") {
7975
+ if (typeof arg1 === "string")
7883
7976
  this.#path = arg1;
7884
- } else {
7977
+ else {
7885
7978
  this.#path = "*";
7886
7979
  handlers.unshift(arg1);
7887
7980
  }
7888
7981
  handlers.forEach((handler) => {
7889
- this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
7982
+ this.#addRoute("ALL", this.#path, handler);
7890
7983
  });
7891
7984
  return this;
7892
7985
  };
@@ -7895,7 +7988,7 @@ var Hono = class _Hono {
7895
7988
  this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
7896
7989
  }
7897
7990
  #clone() {
7898
- const clone = new _Hono({
7991
+ const clone = new Hono2({
7899
7992
  router: this.router,
7900
7993
  getPath: this.getPath
7901
7994
  });
@@ -7910,13 +8003,13 @@ var Hono = class _Hono {
7910
8003
  const subApp = this.basePath(path);
7911
8004
  app.routes.map((r) => {
7912
8005
  let handler;
7913
- if (app.errorHandler === errorHandler) {
8006
+ if (app.errorHandler === errorHandler)
7914
8007
  handler = r.handler;
7915
- } else {
8008
+ else {
7916
8009
  handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
7917
8010
  handler[COMPOSED_HANDLER] = r.handler;
7918
8011
  }
7919
- subApp.#addRoute(r.method, r.path, handler);
8012
+ subApp.#addRoute(r.method, r.path, handler, r.basePath);
7920
8013
  });
7921
8014
  return this;
7922
8015
  }
@@ -7937,15 +8030,14 @@ var Hono = class _Hono {
7937
8030
  let replaceRequest;
7938
8031
  let optionHandler;
7939
8032
  if (options) {
7940
- if (typeof options === "function") {
8033
+ if (typeof options === "function")
7941
8034
  optionHandler = options;
7942
- } else {
8035
+ else {
7943
8036
  optionHandler = options.optionHandler;
7944
- if (options.replaceRequest === false) {
8037
+ if (options.replaceRequest === false)
7945
8038
  replaceRequest = (request) => request;
7946
- } else {
8039
+ else
7947
8040
  replaceRequest = options.replaceRequest;
7948
- }
7949
8041
  }
7950
8042
  }
7951
8043
  const getOptions = optionHandler ? (c) => {
@@ -7958,42 +8050,38 @@ var Hono = class _Hono {
7958
8050
  } catch {}
7959
8051
  return [c.env, executionContext];
7960
8052
  };
7961
- replaceRequest ||= (() => {
7962
- const mergedPath = mergePath(this._basePath, path);
7963
- const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
7964
- return (request) => {
7965
- const url = new URL(request.url);
7966
- url.pathname = url.pathname.slice(pathPrefixLength) || "/";
7967
- return new Request(url, request);
7968
- };
7969
- })();
8053
+ const defaultReplaceRequest = (c) => {
8054
+ const mountedRoutePath = routePath(c);
8055
+ return createMountedRequest(c, mountedRoutePath.replace(/\/?\*$/, ""), mountedRoutePath);
8056
+ };
7970
8057
  const handler = async (c, next) => {
7971
- const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
7972
- if (res) {
8058
+ const res = await applicationHandler(replaceRequest ? replaceRequest(c.req.raw) : defaultReplaceRequest(c), ...getOptions(c));
8059
+ if (res)
7973
8060
  return res;
7974
- }
7975
8061
  await next();
7976
8062
  };
7977
- this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
8063
+ this.#addRoute("ALL", mergePath(path, "*"), handler);
7978
8064
  return this;
7979
8065
  }
7980
- #addRoute(method, path, handler) {
7981
- method = method.toUpperCase();
8066
+ #addRoute(method, path, handler, baseRoutePath) {
7982
8067
  path = mergePath(this._basePath, path);
7983
- const r = { basePath: this._basePath, path, method, handler };
8068
+ const r = {
8069
+ basePath: baseRoutePath !== undefined ? mergePath(this._basePath, baseRoutePath) : this._basePath,
8070
+ path,
8071
+ method,
8072
+ handler
8073
+ };
7984
8074
  this.router.add(method, path, [handler, r]);
7985
8075
  this.routes.push(r);
7986
8076
  }
7987
8077
  #handleError(err, c) {
7988
- if (err instanceof Error) {
8078
+ if (err instanceof Error)
7989
8079
  return this.errorHandler(err, c);
7990
- }
7991
8080
  throw err;
7992
8081
  }
7993
8082
  #dispatch(request, executionCtx, env, method) {
7994
- if (method === "HEAD") {
8083
+ if (method === "HEAD")
7995
8084
  return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
7996
- }
7997
8085
  const path = this.getPath(request, { env });
7998
8086
  const matchResult = this.router.match(method, path);
7999
8087
  const c = new Context(request, {
@@ -8018,9 +8106,8 @@ var Hono = class _Hono {
8018
8106
  return (async () => {
8019
8107
  try {
8020
8108
  const context = await composed(c);
8021
- if (!context.finalized) {
8109
+ if (!context.finalized)
8022
8110
  throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
8023
- }
8024
8111
  return context.res;
8025
8112
  } catch (err) {
8026
8113
  return this.#handleError(err, c);
@@ -8031,9 +8118,8 @@ var Hono = class _Hono {
8031
8118
  return this.#dispatch(request, rest[1], rest[0], request.method);
8032
8119
  };
8033
8120
  request = (input, requestInit, Env, executionCtx) => {
8034
- if (input instanceof Request) {
8121
+ if (input instanceof Request)
8035
8122
  return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
8036
- }
8037
8123
  input = input.toString();
8038
8124
  return this.fetch(new Request(/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`, requestInit), Env, executionCtx);
8039
8125
  };
@@ -8044,20 +8130,21 @@ var Hono = class _Hono {
8044
8130
  };
8045
8131
  };
8046
8132
 
8133
+ // node_modules/hono/dist/router/utils.js
8134
+ var createNullObject = () => Object.create(null);
8135
+
8047
8136
  // node_modules/hono/dist/router/reg-exp-router/matcher.js
8048
8137
  var emptyParam = [];
8049
8138
  function match(method, path) {
8050
8139
  const matchers = this.buildAllMatchers();
8051
8140
  const match2 = (method2, path2) => {
8052
- const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
8141
+ const matcher = matchers[method2] || matchers["ALL"];
8053
8142
  const staticMatch = matcher[2][path2];
8054
- if (staticMatch) {
8143
+ if (staticMatch)
8055
8144
  return staticMatch;
8056
- }
8057
8145
  const match3 = path2.match(matcher[0]);
8058
- if (!match3) {
8146
+ if (!match3)
8059
8147
  return [[], emptyParam];
8060
- }
8061
8148
  const index2 = match3.indexOf("", 1);
8062
8149
  return [matcher[1][index2], match3];
8063
8150
  };
@@ -8067,104 +8154,101 @@ function match(method, path) {
8067
8154
 
8068
8155
  // node_modules/hono/dist/router/reg-exp-router/node.js
8069
8156
  var LABEL_REG_EXP_STR = "[^/]+";
8070
- var ONLY_WILDCARD_REG_EXP_STR = ".*";
8071
- var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
8072
- var PATH_ERROR = /* @__PURE__ */ Symbol();
8073
- var regExpMetaChars = new Set(".\\+*[^]$()");
8157
+ var ONLY_WILDCARD_REG_EXP_STR = "[^]*";
8158
+ var TAIL_WILDCARD_REG_EXP_STR = "(?:|/[^]*)";
8159
+ var PATH_ERROR = Symbol();
8160
+ var regExpMetaChars = /* @__PURE__ */ new Set(".\\+*[^]$()");
8074
8161
  function compareKey(a, b) {
8075
- if (a.length === 1) {
8162
+ if (a.length === 1)
8076
8163
  return b.length === 1 ? a < b ? -1 : 1 : -1;
8077
- }
8078
- if (b.length === 1) {
8164
+ if (b.length === 1)
8079
8165
  return 1;
8080
- }
8081
- if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
8082
- return 1;
8083
- } else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
8166
+ if (a === "[^]*" || a === "(?:|/[^]*)")
8167
+ return b === "[^]*" ? -1 : 1;
8168
+ else if (b === "[^]*" || b === "(?:|/[^]*)")
8084
8169
  return -1;
8085
- }
8086
- if (a === LABEL_REG_EXP_STR) {
8170
+ if (a === "[^/]+")
8087
8171
  return 1;
8088
- } else if (b === LABEL_REG_EXP_STR) {
8172
+ else if (b === "[^/]+")
8089
8173
  return -1;
8090
- }
8091
8174
  return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
8092
8175
  }
8093
- var Node = class _Node {
8176
+ var Node = class Node2 {
8094
8177
  #index;
8095
8178
  #varIndex;
8096
- #children = /* @__PURE__ */ Object.create(null);
8097
- insert(tokens, index2, paramMap, context, pathErrorCheckOnly) {
8098
- if (tokens.length === 0) {
8099
- if (this.#index !== undefined) {
8100
- throw PATH_ERROR;
8101
- }
8102
- if (pathErrorCheckOnly) {
8103
- return;
8104
- }
8105
- this.#index = index2;
8106
- return;
8107
- }
8108
- const [token, ...restTokens] = tokens;
8109
- const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
8110
- let node;
8111
- if (pattern) {
8112
- const name = pattern[1];
8113
- let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
8114
- if (name && pattern[2]) {
8115
- if (regexpStr === ".*") {
8116
- throw PATH_ERROR;
8117
- }
8118
- regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
8119
- if (/\((?!\?:)/.test(regexpStr)) {
8120
- throw PATH_ERROR;
8121
- }
8122
- }
8123
- node = this.#children[regexpStr];
8124
- if (!node) {
8125
- if (Object.keys(this.#children).some((k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) {
8126
- throw PATH_ERROR;
8127
- }
8128
- if (pathErrorCheckOnly) {
8129
- return;
8179
+ #children = createNullObject();
8180
+ insert(tokens, index2, paramMap, context, keys) {
8181
+ let node = this;
8182
+ for (let i = 0, len = tokens.length;i < len; i++) {
8183
+ const token = tokens[i];
8184
+ const pattern = token.length === 1 ? token === "*" ? i === len - 1 ? [
8185
+ "",
8186
+ "",
8187
+ ONLY_WILDCARD_REG_EXP_STR
8188
+ ] : [
8189
+ "",
8190
+ "",
8191
+ LABEL_REG_EXP_STR
8192
+ ] : null : token === "/*" ? [
8193
+ "",
8194
+ "",
8195
+ TAIL_WILDCARD_REG_EXP_STR
8196
+ ] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
8197
+ let nextNode;
8198
+ if (pattern) {
8199
+ const name = pattern[1];
8200
+ let regexpStr = pattern[2] || "[^/]+";
8201
+ if (name && pattern[2]) {
8202
+ if (new RegExp(regexpStr).test(""))
8203
+ throw PATH_ERROR;
8204
+ regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
8205
+ if (/\((?!\?:)/.test(regexpStr))
8206
+ throw PATH_ERROR;
8207
+ if (regexpStr.length === 1 && regExpMetaChars.has(regexpStr))
8208
+ throw PATH_ERROR;
8209
+ }
8210
+ keys.push(regexpStr);
8211
+ nextNode = node.#children[regexpStr];
8212
+ if (!nextNode) {
8213
+ if (regexpStr !== "[^]*" && regexpStr !== "(?:|/[^]*)") {
8214
+ for (const k in node.#children)
8215
+ if ((regexpStr.length > 1 || k.length > 1) && k !== "[^]*" && k !== "(?:|/[^]*)")
8216
+ throw PATH_ERROR;
8217
+ }
8218
+ nextNode = node.#children[regexpStr] = new Node2;
8130
8219
  }
8131
- node = this.#children[regexpStr] = new _Node;
8132
8220
  if (name !== "") {
8133
- node.#varIndex = context.varIndex++;
8221
+ nextNode.#varIndex ??= context.varIndex++;
8222
+ paramMap.push([name, nextNode.#varIndex]);
8134
8223
  }
8135
- }
8136
- if (!pathErrorCheckOnly && name !== "") {
8137
- paramMap.push([name, node.#varIndex]);
8138
- }
8139
- } else {
8140
- node = this.#children[token];
8141
- if (!node) {
8142
- if (Object.keys(this.#children).some((k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) {
8143
- throw PATH_ERROR;
8144
- }
8145
- if (pathErrorCheckOnly) {
8146
- return;
8224
+ } else {
8225
+ keys.push(token);
8226
+ nextNode = node.#children[token];
8227
+ if (!nextNode) {
8228
+ for (const k in node.#children)
8229
+ if (k.length > 1 && k !== "[^]*" && k !== "(?:|/[^]*)")
8230
+ throw PATH_ERROR;
8231
+ nextNode = node.#children[token] = new Node2;
8147
8232
  }
8148
- node = this.#children[token] = new _Node;
8149
8233
  }
8234
+ node = nextNode;
8150
8235
  }
8151
- node.insert(restTokens, index2, paramMap, context, pathErrorCheckOnly);
8236
+ if (node.#index !== undefined)
8237
+ throw PATH_ERROR;
8238
+ node.#index = index2;
8152
8239
  }
8153
8240
  buildRegExpStr() {
8154
- const childKeys = Object.keys(this.#children).sort(compareKey);
8155
- const strList = childKeys.map((k) => {
8241
+ const strList = Object.keys(this.#children).sort(compareKey).map((k) => {
8156
8242
  const c = this.#children[k];
8157
- return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
8158
- });
8159
- if (typeof this.#index === "number") {
8243
+ const childStr = c.buildRegExpStr();
8244
+ return childStr === "" ? "" : (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + childStr;
8245
+ }).filter(Boolean);
8246
+ if (typeof this.#index === "number" && this.#index !== -1)
8160
8247
  strList.unshift(`#${this.#index}`);
8161
- }
8162
- if (strList.length === 0) {
8248
+ if (strList.length === 0)
8163
8249
  return "";
8164
- }
8165
- if (strList.length === 1) {
8250
+ if (strList.length === 1)
8166
8251
  return strList[0];
8167
- }
8168
8252
  return "(?:" + strList.join("|") + ")";
8169
8253
  }
8170
8254
  };
@@ -8173,40 +8257,58 @@ var Node = class _Node {
8173
8257
  var Trie = class {
8174
8258
  #context = { varIndex: 0 };
8175
8259
  #root = new Node;
8176
- insert(path, index2, pathErrorCheckOnly) {
8260
+ #index = 0;
8261
+ paths = createNullObject();
8262
+ insert(path, isStatic) {
8263
+ const keys = [];
8264
+ if (isStatic) {
8265
+ this.#root.insert(path.split(""), -1, [], this.#context, keys);
8266
+ this.paths[path] = [
8267
+ -1,
8268
+ [],
8269
+ keys
8270
+ ];
8271
+ return;
8272
+ }
8177
8273
  const paramAssoc = [];
8178
8274
  const groups = [];
8275
+ let markedPath = path;
8179
8276
  for (let i = 0;; ) {
8180
8277
  let replaced = false;
8181
- path = path.replace(/\{[^}]+\}/g, (m) => {
8278
+ markedPath = markedPath.replace(/\{(?:\{[\d,]+\}|[^}])+\}/g, (m) => {
8182
8279
  const mark = `@\\${i}`;
8183
8280
  groups[i] = [mark, m];
8184
8281
  i++;
8185
8282
  replaced = true;
8186
8283
  return mark;
8187
8284
  });
8188
- if (!replaced) {
8285
+ if (!replaced)
8189
8286
  break;
8190
- }
8191
8287
  }
8192
- const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
8288
+ const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./gs) || [];
8193
8289
  for (let i = groups.length - 1;i >= 0; i--) {
8194
8290
  const [mark] = groups[i];
8195
- for (let j = tokens.length - 1;j >= 0; j--) {
8291
+ for (let j = tokens.length - 1;j >= 0; j--)
8196
8292
  if (tokens[j].indexOf(mark) !== -1) {
8197
8293
  tokens[j] = tokens[j].replace(mark, groups[i][1]);
8198
8294
  break;
8199
8295
  }
8200
- }
8201
8296
  }
8202
- this.#root.insert(tokens, index2, paramAssoc, this.#context, pathErrorCheckOnly);
8203
- return paramAssoc;
8297
+ this.#root.insert(tokens, this.#index, paramAssoc, this.#context, keys);
8298
+ this.paths[path] = [
8299
+ this.#index++,
8300
+ paramAssoc,
8301
+ keys
8302
+ ];
8204
8303
  }
8205
8304
  buildRegExp() {
8206
8305
  let regexp = this.#root.buildRegExpStr();
8207
- if (regexp === "") {
8208
- return [/^$/, [], []];
8209
- }
8306
+ if (regexp === "")
8307
+ return [
8308
+ /^$/,
8309
+ [],
8310
+ []
8311
+ ];
8210
8312
  let captureIndex = 0;
8211
8313
  const indexReplacementMap = [];
8212
8314
  const paramReplacementMap = [];
@@ -8221,245 +8323,105 @@ var Trie = class {
8221
8323
  }
8222
8324
  return "";
8223
8325
  });
8224
- return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap];
8326
+ return [
8327
+ new RegExp(`^${regexp}`),
8328
+ indexReplacementMap,
8329
+ paramReplacementMap
8330
+ ];
8225
8331
  }
8226
8332
  };
8227
8333
 
8228
8334
  // node_modules/hono/dist/router/reg-exp-router/router.js
8229
- var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
8230
- var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
8231
- function buildWildcardRegExp(path) {
8232
- return wildcardRegExpCache[path] ??= new RegExp(path === "*" ? "" : `^${path.replace(/\/\*$|([.\\+*[^\]$()])/g, (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)")}$`);
8233
- }
8234
- function clearWildcardRegExpCache() {
8235
- wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
8236
- }
8237
- function buildMatcherFromPreprocessedRoutes(routes) {
8238
- const trie = new Trie;
8239
- const handlerData = [];
8240
- if (routes.length === 0) {
8241
- return nullMatcher;
8242
- }
8243
- const routesWithStaticPathFlag = routes.map((route) => [!/\*|\/:/.test(route[0]), ...route]).sort(([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length);
8244
- const staticMap = /* @__PURE__ */ Object.create(null);
8245
- for (let i = 0, j = -1, len = routesWithStaticPathFlag.length;i < len; i++) {
8246
- const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
8247
- if (pathErrorCheckOnly) {
8248
- staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
8249
- } else {
8250
- j++;
8251
- }
8252
- let paramAssoc;
8253
- try {
8254
- paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
8255
- } catch (e) {
8256
- throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
8257
- }
8258
- if (pathErrorCheckOnly) {
8259
- continue;
8260
- }
8261
- handlerData[j] = handlers.map(([h, paramCount]) => {
8262
- const paramIndexMap = /* @__PURE__ */ Object.create(null);
8263
- paramCount -= 1;
8264
- for (;paramCount >= 0; paramCount--) {
8265
- const [key, value] = paramAssoc[paramCount];
8266
- paramIndexMap[key] = value;
8267
- }
8268
- return [h, paramIndexMap];
8269
- });
8270
- }
8271
- const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
8272
- for (let i = 0, len = handlerData.length;i < len; i++) {
8273
- for (let j = 0, len2 = handlerData[i].length;j < len2; j++) {
8274
- const map = handlerData[i][j]?.[1];
8275
- if (!map) {
8276
- continue;
8277
- }
8278
- const keys = Object.keys(map);
8279
- for (let k = 0, len3 = keys.length;k < len3; k++) {
8280
- map[keys[k]] = paramReplacementMap[map[keys[k]]];
8281
- }
8282
- }
8283
- }
8284
- const handlerMap = [];
8285
- for (const i in indexReplacementMap) {
8286
- handlerMap[i] = handlerData[indexReplacementMap[i]];
8287
- }
8288
- return [regexp, handlerMap, staticMap];
8289
- }
8290
- function findMiddleware(middleware, path) {
8291
- if (!middleware) {
8292
- return;
8293
- }
8294
- for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
8295
- if (buildWildcardRegExp(k).test(path)) {
8296
- return [...middleware[k]];
8297
- }
8298
- }
8299
- return;
8335
+ function endsWithWildcard(keys) {
8336
+ const tail = keys[keys.length - 1];
8337
+ return tail === "[^]*" || tail === "(?:|/[^]*)";
8338
+ }
8339
+ function covers(wildcard, target) {
8340
+ const last = wildcard.length - 1;
8341
+ for (let i = 0;i < last; i++)
8342
+ if (wildcard[i] !== target[i])
8343
+ return false;
8344
+ return wildcard[last] === "[^]*" || target.length === last || target[last] === "/";
8300
8345
  }
8301
8346
  var RegExpRouter = class {
8302
8347
  name = "RegExpRouter";
8303
- #middleware;
8304
- #routes;
8348
+ #handlers;
8349
+ #tries;
8305
8350
  constructor() {
8306
- this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
8307
- this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
8351
+ this.#handlers = { ["ALL"]: [] };
8352
+ this.#tries = { ["ALL"]: new Trie };
8353
+ }
8354
+ #insertPath(method, path) {
8355
+ try {
8356
+ this.#tries[method].insert(path, !/\*|\/:/.test(path));
8357
+ } catch (e) {
8358
+ throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
8359
+ }
8308
8360
  }
8309
8361
  add(method, path, handler) {
8310
- const middleware = this.#middleware;
8311
- const routes = this.#routes;
8312
- if (!middleware || !routes) {
8362
+ const handlers = this.#handlers;
8363
+ if (!handlers)
8313
8364
  throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
8314
- }
8315
- if (!middleware[method]) {
8316
- [middleware, routes].forEach((handlerMap) => {
8317
- handlerMap[method] = /* @__PURE__ */ Object.create(null);
8318
- Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
8319
- handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
8320
- });
8321
- });
8322
- }
8323
- if (path === "/*") {
8365
+ const tries = this.#tries;
8366
+ if (!handlers[method]) {
8367
+ tries[method] = new Trie;
8368
+ handlers[method] = [...handlers["ALL"]];
8369
+ for (const p in tries["ALL"].paths)
8370
+ this.#insertPath(method, p);
8371
+ }
8372
+ if (path === "/*")
8324
8373
  path = "*";
8325
- }
8326
- const paramCount = (path.match(/\/:/g) || []).length;
8327
- if (/\*$/.test(path)) {
8328
- const re = buildWildcardRegExp(path);
8329
- if (method === METHOD_NAME_ALL) {
8330
- Object.keys(middleware).forEach((m) => {
8331
- middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
8332
- });
8333
- } else {
8334
- middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
8335
- }
8336
- Object.keys(middleware).forEach((m) => {
8337
- if (method === METHOD_NAME_ALL || method === m) {
8338
- Object.keys(middleware[m]).forEach((p) => {
8339
- re.test(p) && middleware[m][p].push([handler, paramCount]);
8340
- });
8341
- }
8342
- });
8343
- Object.keys(routes).forEach((m) => {
8344
- if (method === METHOD_NAME_ALL || method === m) {
8345
- Object.keys(routes[m]).forEach((p) => re.test(p) && routes[m][p].push([handler, paramCount]));
8346
- }
8347
- });
8348
- return;
8349
- }
8374
+ const methods = method === "ALL" ? Object.keys(handlers) : [method];
8350
8375
  const paths = checkOptionalParameter(path) || [path];
8351
- for (let i = 0, len = paths.length;i < len; i++) {
8352
- const path2 = paths[i];
8353
- Object.keys(routes).forEach((m) => {
8354
- if (method === METHOD_NAME_ALL || method === m) {
8355
- routes[m][path2] ||= [
8356
- ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
8357
- ];
8358
- routes[m][path2].push([handler, paramCount - len + i + 1]);
8359
- }
8360
- });
8361
- }
8376
+ for (const path2 of paths)
8377
+ for (const m of methods) {
8378
+ if (!tries[m].paths[path2])
8379
+ this.#insertPath(m, path2);
8380
+ handlers[m].push([handler, path2]);
8381
+ }
8362
8382
  }
8363
8383
  match = match;
8364
8384
  buildAllMatchers() {
8365
- const matchers = /* @__PURE__ */ Object.create(null);
8366
- Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
8367
- matchers[method] ||= this.#buildMatcher(method);
8368
- });
8369
- this.#middleware = this.#routes = undefined;
8370
- clearWildcardRegExpCache();
8385
+ const matchers = createNullObject();
8386
+ for (const method of Object.keys(this.#handlers))
8387
+ matchers[method] = this.#buildMatcher(method);
8388
+ this.#handlers = this.#tries = undefined;
8371
8389
  return matchers;
8372
8390
  }
8373
8391
  #buildMatcher(method) {
8374
- const routes = [];
8375
- let hasOwnRoute = method === METHOD_NAME_ALL;
8376
- [this.#middleware, this.#routes].forEach((r) => {
8377
- const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
8378
- if (ownRoute.length !== 0) {
8379
- hasOwnRoute ||= true;
8380
- routes.push(...ownRoute);
8381
- } else if (method !== METHOD_NAME_ALL) {
8382
- routes.push(...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]]));
8383
- }
8384
- });
8385
- if (!hasOwnRoute) {
8386
- return null;
8387
- } else {
8388
- return buildMatcherFromPreprocessedRoutes(routes);
8389
- }
8390
- }
8391
- };
8392
-
8393
- // node_modules/hono/dist/router/reg-exp-router/prepared-router.js
8394
- var PreparedRegExpRouter = class {
8395
- name = "PreparedRegExpRouter";
8396
- #matchers;
8397
- #relocateMap;
8398
- constructor(matchers, relocateMap) {
8399
- this.#matchers = matchers;
8400
- this.#relocateMap = relocateMap;
8401
- }
8402
- #addWildcard(method, handlerData) {
8403
- const matcher = this.#matchers[method];
8404
- matcher[1].forEach((list) => list && list.push(handlerData));
8405
- Object.values(matcher[2]).forEach((list) => list[0].push(handlerData));
8406
- }
8407
- #addPath(method, path, handler, indexes, map) {
8408
- const matcher = this.#matchers[method];
8409
- if (!map) {
8410
- matcher[2][path][0].push([handler, {}]);
8411
- } else {
8412
- indexes.forEach((index2) => {
8413
- if (typeof index2 === "number") {
8414
- matcher[1][index2].push([handler, map]);
8415
- } else {
8416
- matcher[2][index2 || path][0].push([handler, map]);
8417
- }
8418
- });
8419
- }
8420
- }
8421
- add(method, path, handler) {
8422
- if (!this.#matchers[method]) {
8423
- const all = this.#matchers[METHOD_NAME_ALL];
8424
- const staticMap = {};
8425
- for (const key in all[2]) {
8426
- staticMap[key] = [all[2][key][0].slice(), emptyParam];
8427
- }
8428
- this.#matchers[method] = [
8429
- all[0],
8430
- all[1].map((list) => Array.isArray(list) ? list.slice() : 0),
8431
- staticMap
8432
- ];
8433
- }
8434
- if (path === "/*" || path === "*") {
8435
- const handlerData = [handler, {}];
8436
- if (method === METHOD_NAME_ALL) {
8437
- for (const m in this.#matchers) {
8438
- this.#addWildcard(m, handlerData);
8439
- }
8440
- } else {
8441
- this.#addWildcard(method, handlerData);
8442
- }
8443
- return;
8444
- }
8445
- const data = this.#relocateMap[path];
8446
- if (!data) {
8447
- throw new Error(`Path ${path} is not registered`);
8448
- }
8449
- for (const [indexes, map] of data) {
8450
- if (method === METHOD_NAME_ALL) {
8451
- for (const m in this.#matchers) {
8452
- this.#addPath(m, path, handler, indexes, map);
8453
- }
8454
- } else {
8455
- this.#addPath(method, path, handler, indexes, map);
8456
- }
8457
- }
8458
- }
8459
- buildAllMatchers() {
8460
- return this.#matchers;
8392
+ const handlers = this.#handlers[method];
8393
+ const trie = this.#tries[method];
8394
+ const staticMap = createNullObject();
8395
+ const handlerData = [];
8396
+ const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
8397
+ const own = createNullObject();
8398
+ const entries = handlers.map(([h, p], i) => {
8399
+ (own[p] ??= []).push(i);
8400
+ return [h, trie.paths[p][1].reduceRight((map, [key, varIndex]) => {
8401
+ map[key] = paramReplacementMap[varIndex];
8402
+ return map;
8403
+ }, createNullObject())];
8404
+ });
8405
+ const wildcards = Object.keys(own).filter((p) => endsWithWildcard(trie.paths[p][2]));
8406
+ for (const path in trie.paths) {
8407
+ const [index2, , keys] = trie.paths[path];
8408
+ const indexes = [...own[path]];
8409
+ for (const p of wildcards)
8410
+ if (p !== path && covers(trie.paths[p][2], keys))
8411
+ indexes.push(...own[p]);
8412
+ const data = indexes.sort((a, b) => a - b).map((i) => entries[i]);
8413
+ if (index2 === -1) {
8414
+ const last = Math.max(-1, ...data.flatMap(([, map]) => Object.values(map)));
8415
+ staticMap[path] = [data, last === -1 ? emptyParam : path.match(regexp).slice(0, last + 1)];
8416
+ } else
8417
+ handlerData[index2] = data;
8418
+ }
8419
+ return [
8420
+ regexp,
8421
+ indexReplacementMap.map((i) => handlerData[i]),
8422
+ staticMap
8423
+ ];
8461
8424
  }
8462
- match = match;
8463
8425
  };
8464
8426
 
8465
8427
  // node_modules/hono/dist/router/smart-router/router.js
@@ -8471,15 +8433,17 @@ var SmartRouter = class {
8471
8433
  this.#routers = init.routers;
8472
8434
  }
8473
8435
  add(method, path, handler) {
8474
- if (!this.#routes) {
8436
+ if (!this.#routes)
8475
8437
  throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
8476
- }
8477
- this.#routes.push([method, path, handler]);
8438
+ this.#routes.push([
8439
+ method,
8440
+ path,
8441
+ handler
8442
+ ]);
8478
8443
  }
8479
8444
  match(method, path) {
8480
- if (!this.#routes) {
8445
+ if (!this.#routes)
8481
8446
  throw new Error("Fatal error");
8482
- }
8483
8447
  const routers = this.#routers;
8484
8448
  const routes = this.#routes;
8485
8449
  const len = routers.length;
@@ -8488,14 +8452,12 @@ var SmartRouter = class {
8488
8452
  for (;i < len; i++) {
8489
8453
  const router = routers[i];
8490
8454
  try {
8491
- for (let i2 = 0, len2 = routes.length;i2 < len2; i2++) {
8455
+ for (let i2 = 0, len2 = routes.length;i2 < len2; i2++)
8492
8456
  router.add(...routes[i2]);
8493
- }
8494
8457
  res = router.match(method, path);
8495
8458
  } catch (e) {
8496
- if (e instanceof UnsupportedPathError) {
8459
+ if (e instanceof UnsupportedPathError)
8497
8460
  continue;
8498
- }
8499
8461
  throw e;
8500
8462
  }
8501
8463
  this.match = router.match.bind(router);
@@ -8503,92 +8465,62 @@ var SmartRouter = class {
8503
8465
  this.#routes = undefined;
8504
8466
  break;
8505
8467
  }
8506
- if (i === len) {
8468
+ if (i === len)
8507
8469
  throw new Error("Fatal error");
8508
- }
8509
8470
  this.name = `SmartRouter + ${this.activeRouter.name}`;
8510
8471
  return res;
8511
8472
  }
8512
8473
  get activeRouter() {
8513
- if (this.#routes || this.#routers.length !== 1) {
8474
+ if (this.#routes || this.#routers.length !== 1)
8514
8475
  throw new Error("No active router has been determined yet.");
8515
- }
8516
8476
  return this.#routers[0];
8517
8477
  }
8518
8478
  };
8519
8479
 
8520
8480
  // node_modules/hono/dist/router/trie-router/node.js
8521
- var emptyParams = /* @__PURE__ */ Object.create(null);
8522
- var hasChildren = (children) => {
8523
- for (const _ in children) {
8524
- return true;
8525
- }
8526
- return false;
8527
- };
8528
- var Node2 = class _Node2 {
8529
- #methods;
8530
- #children;
8531
- #patterns;
8532
- #order = 0;
8481
+ var emptyParams = createNullObject();
8482
+ var order = 0;
8483
+ var Node3 = class Node4 {
8484
+ #methods = [];
8485
+ #children = createNullObject();
8486
+ #patterns = [];
8487
+ #pattern;
8533
8488
  #params = emptyParams;
8534
- constructor(method, handler, children) {
8535
- this.#children = children || /* @__PURE__ */ Object.create(null);
8536
- this.#methods = [];
8537
- if (method && handler) {
8538
- const m = /* @__PURE__ */ Object.create(null);
8539
- m[method] = { handler, possibleKeys: [], score: 0 };
8540
- this.#methods = [m];
8541
- }
8542
- this.#patterns = [];
8543
- }
8544
8489
  insert(method, path, handler) {
8545
- this.#order = ++this.#order;
8546
8490
  let curNode = this;
8547
8491
  const parts = splitRoutingPath(path);
8548
- const possibleKeys = [];
8549
- for (let i = 0, len = parts.length;i < len; i++) {
8550
- const p = parts[i];
8551
- const nextP = parts[i + 1];
8552
- const pattern = getPattern(p, nextP);
8553
- const key = Array.isArray(pattern) ? pattern[0] : p;
8554
- if (key in curNode.#children) {
8555
- curNode = curNode.#children[key];
8556
- if (pattern) {
8557
- possibleKeys.push(pattern[1]);
8558
- }
8559
- continue;
8560
- }
8561
- curNode.#children[key] = new _Node2;
8562
- if (pattern) {
8563
- curNode.#patterns.push(pattern);
8564
- possibleKeys.push(pattern[1]);
8565
- }
8566
- curNode = curNode.#children[key];
8567
- }
8568
- curNode.#methods.push({
8569
- [method]: {
8570
- handler,
8571
- possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
8572
- score: this.#order
8573
- }
8574
- });
8575
- return curNode;
8492
+ const possibleKeys = /* @__PURE__ */ new Set;
8493
+ let i = 0;
8494
+ for (const p of parts) {
8495
+ const nextP = parts[++i];
8496
+ const pattern = getPattern(p, nextP) || (nextP === undefined && p && p.indexOf("*") === p.length - 1 ? p : null);
8497
+ const isParam = Array.isArray(pattern);
8498
+ const key = isParam ? pattern[0] : pattern || p;
8499
+ const child = curNode.#children[key] ||= new Node4;
8500
+ if (pattern && !child.#pattern) {
8501
+ child.#pattern = pattern;
8502
+ curNode.#patterns.push(child);
8503
+ }
8504
+ curNode = child;
8505
+ if (isParam)
8506
+ possibleKeys.add(pattern[1]);
8507
+ }
8508
+ curNode.#methods.push({ [method]: {
8509
+ handler,
8510
+ possibleKeys: [...possibleKeys],
8511
+ score: ++order
8512
+ } });
8576
8513
  }
8577
8514
  #pushHandlerSets(handlerSets, node, method, nodeParams, params) {
8578
8515
  for (let i = 0, len = node.#methods.length;i < len; i++) {
8579
8516
  const m = node.#methods[i];
8580
- const handlerSet = m[method] || m[METHOD_NAME_ALL];
8581
- const processedSet = {};
8582
- if (handlerSet !== undefined) {
8583
- handlerSet.params = /* @__PURE__ */ Object.create(null);
8517
+ const handlerSet = m[method] || m["ALL"];
8518
+ if (handlerSet) {
8519
+ handlerSet.params = createNullObject();
8584
8520
  handlerSets.push(handlerSet);
8585
- if (nodeParams !== emptyParams || params && params !== emptyParams) {
8586
- for (let i2 = 0, len2 = handlerSet.possibleKeys.length;i2 < len2; i2++) {
8587
- const key = handlerSet.possibleKeys[i2];
8588
- const processed = processedSet[handlerSet.score];
8589
- handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
8590
- processedSet[handlerSet.score] = true;
8591
- }
8521
+ for (let i2 = 0, len2 = handlerSet.possibleKeys.length;i2 < len2; i2++) {
8522
+ const key = handlerSet.possibleKeys[i2];
8523
+ handlerSet.params[key] = params?.[key] && !i2 ? params[key] : nodeParams[key] ?? params?.[key];
8592
8524
  }
8593
8525
  }
8594
8526
  }
@@ -8596,8 +8528,7 @@ var Node2 = class _Node2 {
8596
8528
  search(method, path) {
8597
8529
  const handlerSets = [];
8598
8530
  this.#params = emptyParams;
8599
- const curNode = this;
8600
- let curNodes = [curNode];
8531
+ let curNodes = [this];
8601
8532
  const parts = splitPath2(path);
8602
8533
  const curNodesQueue = [];
8603
8534
  const len = parts.length;
@@ -8612,61 +8543,61 @@ var Node2 = class _Node2 {
8612
8543
  if (nextNode) {
8613
8544
  nextNode.#params = node.#params;
8614
8545
  if (isLast) {
8615
- if (nextNode.#children["*"]) {
8546
+ if (nextNode.#children["*"])
8616
8547
  this.#pushHandlerSets(handlerSets, nextNode.#children["*"], method, node.#params);
8617
- }
8618
8548
  this.#pushHandlerSets(handlerSets, nextNode, method, node.#params);
8619
- } else {
8549
+ } else
8620
8550
  tempNodes.push(nextNode);
8621
- }
8622
8551
  }
8623
- for (let k = 0, len3 = node.#patterns.length;k < len3; k++) {
8624
- const pattern = node.#patterns[k];
8552
+ for (const child of node.#patterns) {
8553
+ const pattern = child.#pattern;
8625
8554
  const params = node.#params === emptyParams ? {} : { ...node.#params };
8626
- if (pattern === "*") {
8627
- const astNode = node.#children["*"];
8628
- if (astNode) {
8629
- this.#pushHandlerSets(handlerSets, astNode, method, node.#params);
8630
- astNode.#params = params;
8631
- tempNodes.push(astNode);
8555
+ if (typeof pattern === "string") {
8556
+ if (pattern === "*" || part.startsWith(pattern.slice(0, -1))) {
8557
+ this.#pushHandlerSets(handlerSets, child, method, node.#params);
8558
+ if (pattern === "*") {
8559
+ child.#params = params;
8560
+ tempNodes.push(child);
8561
+ }
8632
8562
  }
8633
8563
  continue;
8634
8564
  }
8635
- const [key, name, matcher] = pattern;
8636
- if (!part && !(matcher instanceof RegExp)) {
8565
+ const [, name, matcher] = pattern;
8566
+ if (!part && matcher === true)
8637
8567
  continue;
8638
- }
8639
- const child = node.#children[key];
8640
- if (matcher instanceof RegExp) {
8641
- if (partOffsets === null) {
8642
- partOffsets = new Array(len);
8568
+ if (matcher !== true) {
8569
+ if (!partOffsets) {
8570
+ partOffsets = [];
8643
8571
  let offset = path[0] === "/" ? 1 : 0;
8644
8572
  for (let p = 0;p < len; p++) {
8645
8573
  partOffsets[p] = offset;
8646
8574
  offset += parts[p].length + 1;
8647
8575
  }
8648
8576
  }
8649
- const restPathString = path.substring(partOffsets[i]);
8577
+ const restPathString = path.slice(partOffsets[i]);
8650
8578
  const m = matcher.exec(restPathString);
8651
8579
  if (m) {
8652
- params[name] = m[0];
8580
+ if (!Object.hasOwn(params, name))
8581
+ params[name] = m[0];
8653
8582
  this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
8654
- if (hasChildren(child.#children)) {
8583
+ if (m[0].length === restPathString.length && child.#children["*"])
8584
+ this.#pushHandlerSets(handlerSets, child.#children["*"], method, node.#params, params);
8585
+ for (const _ in child.#children) {
8655
8586
  child.#params = params;
8656
- const componentCount = m[0].match(/\//)?.length ?? 0;
8657
- const targetCurNodes = curNodesQueue[componentCount] ||= [];
8658
- targetCurNodes.push(child);
8587
+ const componentCount = m[0].match(/\//g)?.length ?? 0;
8588
+ (curNodesQueue[componentCount] ||= []).push(child);
8589
+ break;
8659
8590
  }
8660
8591
  continue;
8661
8592
  }
8662
8593
  }
8663
8594
  if (matcher === true || matcher.test(part)) {
8664
- params[name] = part;
8595
+ if (!Object.hasOwn(params, name))
8596
+ params[name] = part;
8665
8597
  if (isLast) {
8666
8598
  this.#pushHandlerSets(handlerSets, child, method, params, node.#params);
8667
- if (child.#children["*"]) {
8599
+ if (child.#children["*"])
8668
8600
  this.#pushHandlerSets(handlerSets, child.#children["*"], method, params, node.#params);
8669
- }
8670
8601
  } else {
8671
8602
  child.#params = params;
8672
8603
  tempNodes.push(child);
@@ -8677,11 +8608,10 @@ var Node2 = class _Node2 {
8677
8608
  const shifted = curNodesQueue.shift();
8678
8609
  curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
8679
8610
  }
8680
- if (handlerSets.length > 1) {
8611
+ if (handlerSets[1])
8681
8612
  handlerSets.sort((a, b) => {
8682
8613
  return a.score - b.score;
8683
8614
  });
8684
- }
8685
8615
  return [handlerSets.map(({ handler, params }) => [handler, params])];
8686
8616
  }
8687
8617
  };
@@ -8689,19 +8619,10 @@ var Node2 = class _Node2 {
8689
8619
  // node_modules/hono/dist/router/trie-router/router.js
8690
8620
  var TrieRouter = class {
8691
8621
  name = "TrieRouter";
8692
- #node;
8693
- constructor() {
8694
- this.#node = new Node2;
8695
- }
8622
+ #node = new Node3;
8696
8623
  add(method, path, handler) {
8697
- const results = checkOptionalParameter(path);
8698
- if (results) {
8699
- for (let i = 0, len = results.length;i < len; i++) {
8700
- this.#node.insert(method, results[i], handler);
8701
- }
8702
- return;
8703
- }
8704
- this.#node.insert(method, path, handler);
8624
+ for (const result of checkOptionalParameter(path) || [path])
8625
+ this.#node.insert(method, result, handler);
8705
8626
  }
8706
8627
  match(method, path) {
8707
8628
  return this.#node.search(method, path);
@@ -8709,12 +8630,10 @@ var TrieRouter = class {
8709
8630
  };
8710
8631
 
8711
8632
  // node_modules/hono/dist/hono.js
8712
- var Hono2 = class extends Hono {
8633
+ var Hono3 = class extends Hono {
8713
8634
  constructor(options = {}) {
8714
8635
  super(options);
8715
- this.router = options.router ?? new SmartRouter({
8716
- routers: [new RegExpRouter, new TrieRouter]
8717
- });
8636
+ this.router = options.router ?? new SmartRouter({ routers: [new RegExpRouter, new TrieRouter] });
8718
8637
  }
8719
8638
  };
8720
8639
 
@@ -11266,7 +11185,7 @@ function constantTimeEquals(a2, b2) {
11266
11185
 
11267
11186
  // src/features/admin/endpoints.ts
11268
11187
  function adminRouter(deps) {
11269
- const app = new Hono2;
11188
+ const app = new Hono3;
11270
11189
  app.get("/health", (ctx) => ctx.json({ status: "ok" }));
11271
11190
  app.get("/ready", (ctx) => {
11272
11191
  const ready = deps.ready.current();
@@ -12869,7 +12788,7 @@ function createServer(opts) {
12869
12788
  const clock = createClock({ deterministic: opts.deterministic ?? false });
12870
12789
  const handlerTimeoutMs = opts.handlerTimeoutMs ?? 5000;
12871
12790
  const genRequestId = createRequestIdGenerator(opts.deterministic ?? false);
12872
- const app = new Hono2;
12791
+ const app = new Hono3;
12873
12792
  const replayWebhook = (tenant, deliveryId) => {
12874
12793
  const snap = opts.holder.get();
12875
12794
  const tenantSnap = snap.tenants.get(tenant);