@hot-updater/aws 1.2.0-rc.59 → 1.2.0-rc.60

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.
Files changed (2) hide show
  1. package/dist/lambda/index.cjs +718 -449
  2. package/package.json +9 -9
@@ -5230,7 +5230,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
5230
5230
  };
5231
5231
  //#endregion
5232
5232
  //#region ../../packages/server/dist/version.mjs
5233
- const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.59";
5233
+ const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.60";
5234
5234
  //#endregion
5235
5235
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
5236
5236
  /**
@@ -9504,7 +9504,7 @@ const createRequestHandler = ({ api, clientPolicy, privateResponses = false, rou
9504
9504
  try {
9505
9505
  authenticated = await clientPolicy.authenticate(request);
9506
9506
  } catch (error) {
9507
- console.error("Hot Updater client authentication failed:", error);
9507
+ console.error("Hot Updater client authentication error:", error);
9508
9508
  return errorResponse("Service unavailable", 503);
9509
9509
  }
9510
9510
  if (!authenticated) return errorResponse("Unauthorized", 401);
@@ -14051,48 +14051,72 @@ const remoteConfig = () => {
14051
14051
  return markOfficial(plugin);
14052
14052
  };
14053
14053
  //#endregion
14054
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/compose.js
14055
- var compose = (middleware, onError, onNotFound) => {
14056
- return (context, next) => {
14057
- let index = -1;
14058
- return dispatch(0);
14059
- async function dispatch(i) {
14060
- if (i <= index) throw new Error("next() called multiple times");
14061
- index = i;
14062
- let res;
14063
- let isError = false;
14064
- let handler;
14065
- if (middleware[i]) {
14066
- handler = middleware[i][0][0];
14067
- context.req.routeIndex = i;
14068
- } else handler = i === middleware.length && next || void 0;
14069
- if (handler) try {
14070
- res = await handler(context, () => dispatch(i + 1));
14071
- } catch (err) {
14072
- if (err instanceof Error && onError) {
14073
- context.error = err;
14074
- res = await onError(err, context);
14075
- isError = true;
14076
- } else throw err;
14077
- }
14078
- else if (context.finalized === false && onNotFound) res = await onNotFound(context);
14079
- if (res && (context.finalized === false || isError)) context.res = res;
14080
- return context;
14081
- }
14082
- };
14054
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/http-exception.js
14055
+ /**
14056
+ * `HTTPException` must be used when a fatal error such as authentication failure occurs.
14057
+ *
14058
+ * @see {@link https://hono.dev/docs/api/exception}
14059
+ *
14060
+ * @param {StatusCode} status - status code of HTTPException
14061
+ * @param {HTTPExceptionOptions} options - options of HTTPException
14062
+ * @param {HTTPExceptionOptions["res"]} options.res - response of options of HTTPException
14063
+ * @param {HTTPExceptionOptions["message"]} options.message - message of options of HTTPException
14064
+ * @param {HTTPExceptionOptions["cause"]} options.cause - cause of options of HTTPException
14065
+ *
14066
+ * @example
14067
+ * ```ts
14068
+ * import { HTTPException } from 'hono/http-exception'
14069
+ *
14070
+ * // ...
14071
+ *
14072
+ * app.post('/auth', async (c, next) => {
14073
+ * // authentication
14074
+ * if (authorized === false) {
14075
+ * throw new HTTPException(401, { message: 'Custom error message' })
14076
+ * }
14077
+ * await next()
14078
+ * })
14079
+ * ```
14080
+ */
14081
+ var HTTPException = class extends Error {
14082
+ res;
14083
+ status;
14084
+ /**
14085
+ * Creates an instance of `HTTPException`.
14086
+ * @param status - HTTP status code for the exception. Defaults to 500.
14087
+ * @param options - Additional options for the exception.
14088
+ */
14089
+ constructor(status = 500, options) {
14090
+ super(options?.message, { cause: options?.cause });
14091
+ this.res = options?.res;
14092
+ this.status = status;
14093
+ }
14094
+ /**
14095
+ * Returns the response object associated with the exception.
14096
+ * If a response object is not provided, a new response is created with the error message and status code.
14097
+ * @returns The response object.
14098
+ */
14099
+ getResponse() {
14100
+ if (this.res) return new Response(this.res.body, {
14101
+ status: this.status,
14102
+ headers: this.res.headers
14103
+ });
14104
+ return new Response(this.message, { status: this.status });
14105
+ }
14083
14106
  };
14084
14107
  //#endregion
14085
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/request/constants.js
14086
- var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
14108
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/request/constants.js
14109
+ const GET_MATCH_RESULT = Symbol();
14087
14110
  //#endregion
14088
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/buffer.js
14089
- var bufferToFormData = (arrayBuffer, contentType) => {
14111
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/buffer.js
14112
+ const bufferToFormData = (arrayBuffer, contentType) => {
14090
14113
  return new Response(arrayBuffer, { headers: { "Content-Type": contentType.replace(/^[^;]+/, (mediaType) => mediaType.toLowerCase()) } }).formData();
14091
14114
  };
14092
14115
  //#endregion
14093
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/body.js
14094
- var isRawRequest = (request) => "headers" in request;
14095
- var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
14116
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/body.js
14117
+ const MAX_NESTED_OBJECTS = 1e4;
14118
+ const isRawRequest = (request) => "headers" in request;
14119
+ const parseBody = async (request, options = Object.create(null)) => {
14096
14120
  const { all = false, dot = false } = options;
14097
14121
  const mediaType = (isRawRequest(request) ? request.headers : request.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();
14098
14122
  if (mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded") return parseFormData(request, {
@@ -14101,60 +14125,101 @@ var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) =
14101
14125
  });
14102
14126
  return {};
14103
14127
  };
14128
+ /**
14129
+ * Parses form data from a request.
14130
+ *
14131
+ * @template T - The type of the parsed body data.
14132
+ * @param {HonoRequest | Request} request - The request object containing form data.
14133
+ * @param {ParseBodyOptions} options - Options for parsing the form data.
14134
+ * @returns {Promise<T>} The parsed body data.
14135
+ */
14104
14136
  async function parseFormData(request, options) {
14105
14137
  if (!isRawRequest(request) && request.bodyCache.formData) return convertFormDataToBodyData(await request.bodyCache.formData, options);
14106
14138
  const headers = isRawRequest(request) ? request.headers : request.raw.headers;
14107
- const formDataPromise = bufferToFormData(await request.arrayBuffer(), headers.get("Content-Type") || "");
14139
+ const arrayBuffer = await request.arrayBuffer();
14140
+ const formDataPromise = bufferToFormData(arrayBuffer, headers.get("Content-Type") || "");
14108
14141
  if (!isRawRequest(request)) request.bodyCache.formData = formDataPromise;
14109
14142
  const formData = await formDataPromise;
14110
14143
  if (formData) return convertFormDataToBodyData(formData, options);
14111
14144
  return {};
14112
14145
  }
14146
+ /**
14147
+ * Converts form data to body data based on the provided options.
14148
+ *
14149
+ * @template T - The type of the parsed body data.
14150
+ * @param {FormData} formData - The form data to convert.
14151
+ * @param {ParseBodyOptions} options - Options for parsing the form data.
14152
+ * @returns {T} The converted body data.
14153
+ */
14113
14154
  function convertFormDataToBodyData(formData, options) {
14114
- const form = /* @__PURE__ */ Object.create(null);
14155
+ const form = Object.create(null);
14156
+ const nestingState = { count: 0 };
14115
14157
  formData.forEach((value, key) => {
14116
14158
  if (!(options.all || key.endsWith("[]"))) form[key] = value;
14117
14159
  else handleParsingAllValues(form, key, value);
14118
14160
  });
14119
14161
  if (options.dot) Object.entries(form).forEach(([key, value]) => {
14120
14162
  if (key.includes(".")) {
14121
- handleParsingNestedValues(form, key, value);
14163
+ handleParsingNestedValues(form, key, value, nestingState);
14122
14164
  delete form[key];
14123
14165
  }
14124
14166
  });
14125
14167
  return form;
14126
14168
  }
14127
- var handleParsingAllValues = (form, key, value) => {
14169
+ /**
14170
+ * Handles parsing all values for a given key, supporting multiple values as arrays.
14171
+ *
14172
+ * @param {BodyData} form - The form data object.
14173
+ * @param {string} key - The key to parse.
14174
+ * @param {FormDataEntryValue} value - The value to assign.
14175
+ */
14176
+ const handleParsingAllValues = (form, key, value) => {
14128
14177
  if (form[key] !== void 0) {
14129
14178
  if (Array.isArray(form[key])) form[key].push(value);
14130
14179
  else form[key] = [form[key], value];
14131
14180
  } else if (!key.endsWith("[]")) form[key] = value;
14132
14181
  else form[key] = [value];
14133
14182
  };
14134
- var handleParsingNestedValues = (form, key, value) => {
14183
+ /**
14184
+ * Handles parsing nested values using dot notation keys.
14185
+ *
14186
+ * @param {BodyData} form - The form data object.
14187
+ * @param {string} key - The dot notation key.
14188
+ * @param {BodyDataValue} value - The value to assign.
14189
+ * @param {{ count: number }} state - The state object tracking nesting depth.
14190
+ */
14191
+ const handleParsingNestedValues = (form, key, value, state) => {
14135
14192
  if (/(?:^|\.)__proto__\./.test(key)) return;
14136
14193
  let nestedForm = form;
14137
- const keys = key.split(".");
14138
- keys.forEach((key2, index) => {
14139
- if (index === keys.length - 1) nestedForm[key2] = value;
14194
+ const keys = key.split(".", 34);
14195
+ if (keys.length > 33) throwNestingLimitExceeded();
14196
+ keys.forEach((key, index) => {
14197
+ if (index === keys.length - 1) nestedForm[key] = value;
14140
14198
  else {
14141
- if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) nestedForm[key2] = /* @__PURE__ */ Object.create(null);
14142
- nestedForm = nestedForm[key2];
14199
+ if (!nestedForm[key] || typeof nestedForm[key] !== "object" || Array.isArray(nestedForm[key]) || nestedForm[key] instanceof File) {
14200
+ if (state.count++ >= MAX_NESTED_OBJECTS) throwNestingLimitExceeded();
14201
+ nestedForm[key] = Object.create(null);
14202
+ }
14203
+ nestedForm = nestedForm[key];
14143
14204
  }
14144
14205
  });
14145
14206
  };
14207
+ const throwNestingLimitExceeded = () => {
14208
+ throw new Error("Nesting limit exceeded");
14209
+ };
14146
14210
  //#endregion
14147
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/url.js
14148
- var splitPath = (path) => {
14211
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/url.js
14212
+ const splitPath = (path) => {
14149
14213
  const paths = path.split("/");
14150
14214
  if (paths[0] === "") paths.shift();
14151
14215
  return paths;
14152
14216
  };
14153
- var splitRoutingPath = (routePath) => {
14217
+ const splitRoutingPath = (routePath) => {
14154
14218
  const { groups, path } = extractGroupsFromPath(routePath);
14155
- return replaceGroupMarks(splitPath(path), groups);
14219
+ const paths = splitPath(path);
14220
+ return replaceGroupMarks(paths, groups);
14156
14221
  };
14157
- var extractGroupsFromPath = (path) => {
14222
+ const extractGroupsFromPath = (path) => {
14158
14223
  const groups = [];
14159
14224
  path = path.replace(/\{[^}]+\}/g, (match, index) => {
14160
14225
  const mark = `@${index}`;
@@ -14166,7 +14231,7 @@ var extractGroupsFromPath = (path) => {
14166
14231
  path
14167
14232
  };
14168
14233
  };
14169
- var replaceGroupMarks = (paths, groups) => {
14234
+ const replaceGroupMarks = (paths, groups) => {
14170
14235
  for (let i = groups.length - 1; i >= 0; i--) {
14171
14236
  const [mark] = groups[i];
14172
14237
  for (let j = paths.length - 1; j >= 0; j--) if (paths[j].includes(mark)) {
@@ -14176,8 +14241,8 @@ var replaceGroupMarks = (paths, groups) => {
14176
14241
  }
14177
14242
  return paths;
14178
14243
  };
14179
- var patternCache = {};
14180
- var getPattern = (label, next) => {
14244
+ const patternCache = {};
14245
+ const getPattern = (label, next) => {
14181
14246
  if (label === "*") return "*";
14182
14247
  const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
14183
14248
  if (match) {
@@ -14202,7 +14267,7 @@ var getPattern = (label, next) => {
14202
14267
  }
14203
14268
  return null;
14204
14269
  };
14205
- var tryDecode = (str, decoder) => {
14270
+ const tryDecode = (str, decoder) => {
14206
14271
  try {
14207
14272
  return decoder(str);
14208
14273
  } catch {
@@ -14215,8 +14280,8 @@ var tryDecode = (str, decoder) => {
14215
14280
  });
14216
14281
  }
14217
14282
  };
14218
- var tryDecodeURI = (str) => tryDecode(str, decodeURI);
14219
- var getPath = (request) => {
14283
+ const decodeURIWithPreservedPercent = (value) => decodeURI(value.includes("%25") ? value.replace(/%25/g, "%2525") : value);
14284
+ const getPath = (request) => {
14220
14285
  const url = request.url;
14221
14286
  const start = url.indexOf("/", url.indexOf(":") + 4);
14222
14287
  let i = start;
@@ -14227,20 +14292,36 @@ var getPath = (request) => {
14227
14292
  const hashIndex = url.indexOf("#", i);
14228
14293
  const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
14229
14294
  const path = url.slice(start, end);
14230
- return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
14295
+ const decoded = tryDecode(path, decodeURIWithPreservedPercent);
14296
+ if (/%(?![0-9A-Fa-f]{2})/.test(path)) {
14297
+ const rewritten = new URL("http://localhost");
14298
+ rewritten.pathname = decoded.replace(/[\\\t\n\r]/g, encodeURIComponent);
14299
+ if (tryDecode(rewritten.pathname, decodeURIWithPreservedPercent) !== decoded) return tryDecode(path.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"), decodeURIWithPreservedPercent);
14300
+ }
14301
+ return decoded;
14231
14302
  } else if (charCode === 63 || charCode === 35) break;
14232
14303
  }
14233
14304
  return url.slice(start, i);
14234
14305
  };
14235
- var getPathNoStrict = (request) => {
14306
+ const getPathNoStrict = (request) => {
14236
14307
  const result = getPath(request);
14237
14308
  return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
14238
14309
  };
14239
- var mergePath = (base, sub, ...rest) => {
14310
+ /**
14311
+ * Merge paths.
14312
+ * @param {string[]} ...paths - The paths to merge.
14313
+ * @returns {string} The merged path.
14314
+ * @example
14315
+ * mergePath('/api', '/users') // '/api/users'
14316
+ * mergePath('/api/', '/users') // '/api/users'
14317
+ * mergePath('/api', '/') // '/api'
14318
+ * mergePath('/api/', '/') // '/api/'
14319
+ */
14320
+ const mergePath = (base, sub, ...rest) => {
14240
14321
  if (rest.length) sub = mergePath(sub, ...rest);
14241
14322
  return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
14242
14323
  };
14243
- var checkOptionalParameter = (path) => {
14324
+ const checkOptionalParameter = (path) => {
14244
14325
  if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) return null;
14245
14326
  const segments = path.split("/");
14246
14327
  const results = [];
@@ -14248,10 +14329,10 @@ var checkOptionalParameter = (path) => {
14248
14329
  segments.forEach((segment) => {
14249
14330
  if (segment !== "" && !/\:/.test(segment)) basePath += "/" + segment;
14250
14331
  else if (/\:/.test(segment)) {
14251
- if (/\?/.test(segment)) {
14332
+ if (segment.charCodeAt(segment.length - 1) === 63) {
14252
14333
  if (results.length === 0 && basePath === "") results.push("/");
14253
14334
  else results.push(basePath);
14254
- const optionalSegment = segment.replace("?", "");
14335
+ const optionalSegment = segment.slice(0, -1);
14255
14336
  basePath += "/" + optionalSegment;
14256
14337
  results.push(basePath);
14257
14338
  } else basePath += "/" + segment;
@@ -14259,30 +14340,37 @@ var checkOptionalParameter = (path) => {
14259
14340
  });
14260
14341
  return results.filter((v, i, a) => a.indexOf(v) === i);
14261
14342
  };
14262
- var _decodeURI = (value) => {
14263
- if (!/[%+]/.test(value)) return value;
14343
+ const tryDecodeURIComponent = (str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str;
14344
+ const _decodeURI = (value) => {
14264
14345
  if (value.indexOf("+") !== -1) value = value.replace(/\+/g, " ");
14265
- return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
14346
+ return tryDecodeURIComponent(value);
14266
14347
  };
14267
- var _getQueryParam = (url, key, multiple) => {
14348
+ const _getQueryParam = (url, key, multiple) => {
14349
+ const hashIndex = url.indexOf("#", 8);
14350
+ if (hashIndex !== -1) url = url.slice(0, hashIndex);
14268
14351
  let encoded;
14269
- if (!multiple && key && !/[%+]/.test(key)) {
14270
- let keyIndex2 = url.indexOf("?", 8);
14271
- if (keyIndex2 === -1) return;
14272
- if (!url.startsWith(key, keyIndex2 + 1)) keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
14273
- while (keyIndex2 !== -1) {
14274
- const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
14275
- if (trailingKeyCode === 61) {
14276
- const valueIndex = keyIndex2 + key.length + 2;
14277
- const endIndex = url.indexOf("&", valueIndex);
14278
- return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
14279
- } else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) return "";
14280
- keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
14352
+ if (!multiple && key && !/[%+&=]/.test(key)) {
14353
+ const queryIndex = url.indexOf("?", 8);
14354
+ let keyIndex = queryIndex;
14355
+ if (keyIndex === -1) return;
14356
+ if (!url.startsWith(key, keyIndex + 1)) keyIndex = url.indexOf(`&${key}`, keyIndex + 1);
14357
+ while (keyIndex !== -1) {
14358
+ const trailingKeyCode = url.charCodeAt(keyIndex + key.length + 1);
14359
+ if (trailingKeyCode === 61 || trailingKeyCode === 38 || isNaN(trailingKeyCode)) {
14360
+ if (keyIndex > queryIndex && /(?:^|&)[^=&]*[%+]/.test(url.slice(queryIndex + 1, keyIndex))) break;
14361
+ if (trailingKeyCode === 61) {
14362
+ const valueIndex = keyIndex + key.length + 2;
14363
+ const endIndex = url.indexOf("&", valueIndex);
14364
+ return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
14365
+ }
14366
+ return "";
14367
+ }
14368
+ keyIndex = url.indexOf(`&${key}`, keyIndex + 1);
14281
14369
  }
14282
14370
  encoded = /[%+]/.test(url);
14283
14371
  if (!encoded) return;
14284
14372
  }
14285
- const results = /* @__PURE__ */ Object.create(null);
14373
+ const results = Object.create(null);
14286
14374
  encoded ??= /[%+]/.test(url);
14287
14375
  let keyIndex = url.indexOf("?", 8);
14288
14376
  while (keyIndex !== -1) {
@@ -14306,14 +14394,13 @@ var _getQueryParam = (url, key, multiple) => {
14306
14394
  }
14307
14395
  return key ? results[key] : results;
14308
14396
  };
14309
- var getQueryParam = _getQueryParam;
14310
- var getQueryParams = (url, key) => {
14397
+ const getQueryParam = _getQueryParam;
14398
+ const getQueryParams = (url, key) => {
14311
14399
  return _getQueryParam(url, key, true);
14312
14400
  };
14313
- var decodeURIComponent_ = decodeURIComponent;
14401
+ const decodeURIComponent_ = decodeURIComponent;
14314
14402
  //#endregion
14315
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/request.js
14316
- var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
14403
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/request.js
14317
14404
  var HonoRequest = class {
14318
14405
  /**
14319
14406
  * `.raw` can get the raw Request object.
@@ -14351,22 +14438,21 @@ var HonoRequest = class {
14351
14438
  this.raw = request;
14352
14439
  this.path = path;
14353
14440
  this.#matchResult = matchResult;
14354
- this.#validatedData = {};
14355
14441
  }
14356
14442
  param(key) {
14357
14443
  return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
14358
14444
  }
14359
14445
  #getDecodedParam(key) {
14360
- const paramKey = this.#matchResult[0][this.routeIndex][1][key];
14446
+ const paramKey = this.#matchResult[0][this.routeIndex]?.[1][key];
14361
14447
  const param = this.#getParamValue(paramKey);
14362
- return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
14448
+ return param && tryDecodeURIComponent(param);
14363
14449
  }
14364
14450
  #getAllDecodedParams() {
14365
14451
  const decoded = {};
14366
- const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
14452
+ const keys = Object.keys(this.#matchResult[0][this.routeIndex]?.[1] ?? {});
14367
14453
  for (const key of keys) {
14368
14454
  const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
14369
- if (value !== void 0) decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
14455
+ if (value !== void 0) decoded[key] = tryDecodeURIComponent(value);
14370
14456
  }
14371
14457
  return decoded;
14372
14458
  }
@@ -14381,7 +14467,7 @@ var HonoRequest = class {
14381
14467
  }
14382
14468
  header(name) {
14383
14469
  if (name) return this.raw.headers.get(name) ?? void 0;
14384
- const headerData = /* @__PURE__ */ Object.create(null);
14470
+ const headerData = Object.create(null);
14385
14471
  this.raw.headers.forEach((value, key) => {
14386
14472
  headerData[key] = value;
14387
14473
  });
@@ -14394,10 +14480,10 @@ var HonoRequest = class {
14394
14480
  const { bodyCache, raw } = this;
14395
14481
  const cachedBody = bodyCache[key];
14396
14482
  if (cachedBody) return cachedBody;
14397
- const anyCachedKey = Object.keys(bodyCache)[0];
14398
- if (anyCachedKey) return bodyCache[anyCachedKey].then((body) => {
14483
+ for (const anyCachedKey in bodyCache) return bodyCache[anyCachedKey].then((body) => {
14399
14484
  if (anyCachedKey === "json") body = JSON.stringify(body);
14400
- return new Response(body)[key]();
14485
+ const contentType = anyCachedKey === "formData" ? void 0 : raw.headers.get("content-type");
14486
+ return new Response(body, { headers: contentType ? { "Content-Type": contentType } : void 0 })[key]();
14401
14487
  });
14402
14488
  return bodyCache[key] = raw[key]();
14403
14489
  };
@@ -14494,13 +14580,13 @@ var HonoRequest = class {
14494
14580
  * @param data - The validated data to add.
14495
14581
  */
14496
14582
  addValidatedData(target, data) {
14497
- this.#validatedData[target] = data;
14583
+ (this.#validatedData ??= {})[target] = data;
14498
14584
  }
14499
14585
  valid(target) {
14500
- return this.#validatedData[target];
14586
+ return this.#validatedData?.[target];
14501
14587
  }
14502
14588
  /**
14503
- * `.url()` can get the request url strings.
14589
+ * `.url` can get the request url strings.
14504
14590
  *
14505
14591
  * @see {@link https://hono.dev/docs/api/request#url}
14506
14592
  *
@@ -14516,7 +14602,7 @@ var HonoRequest = class {
14516
14602
  return this.raw.url;
14517
14603
  }
14518
14604
  /**
14519
- * `.method()` can get the method name of the request.
14605
+ * `.method` can get the method name of the request.
14520
14606
  *
14521
14607
  * @see {@link https://hono.dev/docs/api/request#method}
14522
14608
  *
@@ -14534,7 +14620,7 @@ var HonoRequest = class {
14534
14620
  return this.#matchResult;
14535
14621
  }
14536
14622
  /**
14537
- * `.matchedRoutes()` can return a matched route in the handler
14623
+ * `.matchedRoutes` can return a matched route in the handler
14538
14624
  *
14539
14625
  * @deprecated
14540
14626
  *
@@ -14564,7 +14650,7 @@ var HonoRequest = class {
14564
14650
  return this.#matchResult[0].map(([[, route]]) => route);
14565
14651
  }
14566
14652
  /**
14567
- * `routePath()` can retrieve the path registered within the handler
14653
+ * `.routePath` can retrieve the path registered within the handler
14568
14654
  *
14569
14655
  * @deprecated
14570
14656
  *
@@ -14584,19 +14670,23 @@ var HonoRequest = class {
14584
14670
  }
14585
14671
  };
14586
14672
  //#endregion
14587
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/html.js
14588
- var HtmlEscapedCallbackPhase = {
14673
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/html.js
14674
+ /**
14675
+ * @module
14676
+ * HTML utility.
14677
+ */
14678
+ const HtmlEscapedCallbackPhase = {
14589
14679
  Stringify: 1,
14590
14680
  BeforeStream: 2,
14591
14681
  Stream: 3
14592
14682
  };
14593
- var raw = (value, callbacks) => {
14683
+ const raw = (value, callbacks) => {
14594
14684
  const escapedString = new String(value);
14595
14685
  escapedString.isEscaped = true;
14596
14686
  escapedString.callbacks = callbacks;
14597
14687
  return escapedString;
14598
14688
  };
14599
- var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
14689
+ const resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
14600
14690
  if (typeof str === "object" && !(str instanceof String)) {
14601
14691
  if (!(str instanceof Promise)) str = str.toString();
14602
14692
  if (str instanceof Promise) str = await str;
@@ -14609,20 +14699,20 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
14609
14699
  phase,
14610
14700
  buffer,
14611
14701
  context
14612
- }))).then((res) => Promise.all(res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))).then(() => buffer[0]));
14702
+ }))).then((res) => Promise.all(res.filter(Boolean).map((str) => resolveCallback(str, phase, false, context, buffer))).then(() => buffer[0]));
14613
14703
  if (preserveCallbacks) return raw(await resStr, callbacks);
14614
14704
  else return resStr;
14615
14705
  };
14616
14706
  //#endregion
14617
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/context.js
14618
- var TEXT_PLAIN = "text/plain; charset=UTF-8";
14619
- var setDefaultContentType = (contentType, headers) => {
14707
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/context.js
14708
+ const TEXT_PLAIN = "text/plain; charset=UTF-8";
14709
+ const setDefaultContentType = (contentType, headers) => {
14620
14710
  return {
14621
14711
  "Content-Type": contentType,
14622
14712
  ...headers
14623
14713
  };
14624
14714
  };
14625
- var createResponseInstance = (body, init) => new Response(body, init);
14715
+ const createResponseInstance = (body, init) => new Response(body, init);
14626
14716
  var Context = class {
14627
14717
  #rawRequest;
14628
14718
  #req;
@@ -14802,12 +14892,16 @@ var Context = class {
14802
14892
  * c.header('X-Message', 'Hello!')
14803
14893
  * c.header('Content-Type', 'text/plain')
14804
14894
  *
14895
+ * // Append multiple headers using the append option (e.g. Vary)
14896
+ * c.header('Vary', 'Accept-Encoding', { append: true })
14897
+ * c.header('Vary', 'User-Agent', { append: true })
14898
+ *
14805
14899
  * return c.body('Thank you for coming')
14806
14900
  * })
14807
14901
  * ```
14808
14902
  */
14809
14903
  header = (name, value, options) => {
14810
- if (this.finalized) this.#res = createResponseInstance(this.#res.body, this.#res);
14904
+ if (this.finalized && !this.#res.bodyUsed) this.#res = createResponseInstance(this.#res.body, this.#res);
14811
14905
  const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
14812
14906
  if (value === void 0) headers.delete(name);
14813
14907
  else if (options?.append) headers.append(name, value);
@@ -14864,20 +14958,33 @@ var Context = class {
14864
14958
  return Object.fromEntries(this.#var);
14865
14959
  }
14866
14960
  #newResponse(data, arg, headers) {
14867
- const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
14868
- if (typeof arg === "object" && "headers" in arg) {
14869
- const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
14870
- for (const [key, value] of argHeaders) if (key.toLowerCase() === "set-cookie") responseHeaders.append(key, value);
14961
+ let responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders;
14962
+ if (typeof arg === "object" && arg.headers) {
14963
+ responseHeaders ??= new Headers();
14964
+ for (const [key, value] of new Headers(arg.headers)) if (key === "set-cookie") responseHeaders.append(key, value);
14871
14965
  else responseHeaders.set(key, value);
14872
14966
  }
14873
- if (headers) for (const [k, v] of Object.entries(headers)) if (typeof v === "string") responseHeaders.set(k, v);
14874
- else {
14875
- responseHeaders.delete(k);
14876
- for (const v2 of v) responseHeaders.append(k, v2);
14967
+ if (headers) {
14968
+ if (!responseHeaders) {
14969
+ let count = 0;
14970
+ for (const k in headers) if (++count > 1 || typeof headers[k] !== "string") {
14971
+ responseHeaders = new Headers();
14972
+ break;
14973
+ }
14974
+ }
14975
+ if (responseHeaders) for (const k in headers) {
14976
+ const v = headers[k];
14977
+ if (typeof v === "string") responseHeaders.set(k, v);
14978
+ else {
14979
+ responseHeaders.delete(k);
14980
+ for (const v2 of v) responseHeaders.append(k, v2);
14981
+ }
14982
+ }
14877
14983
  }
14984
+ const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
14878
14985
  return createResponseInstance(data, {
14879
- status: typeof arg === "number" ? arg : arg?.status ?? this.#status,
14880
- headers: responseHeaders
14986
+ status,
14987
+ headers: responseHeaders ?? headers
14881
14988
  });
14882
14989
  }
14883
14990
  newResponse = (...args) => this.#newResponse(...args);
@@ -14934,7 +15041,7 @@ var Context = class {
14934
15041
  return this.#newResponse(JSON.stringify(object), arg, setDefaultContentType("application/json", headers));
14935
15042
  };
14936
15043
  html = (html, arg, headers) => {
14937
- const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
15044
+ const res = (html) => this.#newResponse(html, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
14938
15045
  return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
14939
15046
  };
14940
15047
  /**
@@ -14975,26 +15082,190 @@ var Context = class {
14975
15082
  };
14976
15083
  };
14977
15084
  //#endregion
14978
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router.js
14979
- var METHODS = [
15085
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/compose.js
15086
+ /**
15087
+ * Compose middleware functions into a single function based on `koa-compose` package.
15088
+ *
15089
+ * @template E - The environment type.
15090
+ *
15091
+ * @param {[[Function, unknown], unknown][] | [[Function]][]} middleware - An array of middleware functions and their corresponding parameters.
15092
+ * @param {ErrorHandler<E>} [onError] - An optional error handler function.
15093
+ * @param {NotFoundHandler<E>} [onNotFound] - An optional not-found handler function.
15094
+ *
15095
+ * @returns {(context: Context, next?: Next) => Promise<Context>} - A composed middleware function.
15096
+ */
15097
+ const compose = (middleware, onError, onNotFound) => {
15098
+ return (context, next) => {
15099
+ let index = -1;
15100
+ return dispatch(0);
15101
+ /**
15102
+ * Dispatch the middleware functions.
15103
+ *
15104
+ * @param {number} i - The current index in the middleware array.
15105
+ *
15106
+ * @returns {Promise<Context>} - A promise that resolves to the context.
15107
+ */
15108
+ async function dispatch(i) {
15109
+ if (i <= index) throw new Error("next() called multiple times");
15110
+ index = i;
15111
+ let res;
15112
+ let isError = false;
15113
+ let handler;
15114
+ if (middleware[i]) {
15115
+ handler = middleware[i][0][0];
15116
+ context.req.routeIndex = i;
15117
+ } else handler = i === middleware.length && next || void 0;
15118
+ if (handler) try {
15119
+ res = await handler(context, () => dispatch(i + 1));
15120
+ } catch (err) {
15121
+ if (err instanceof Error && onError) {
15122
+ context.error = err;
15123
+ res = await onError(err, context);
15124
+ isError = true;
15125
+ } else throw err;
15126
+ }
15127
+ else if (context.finalized === false && onNotFound) res = await onNotFound(context);
15128
+ if (res && (context.finalized === false || isError)) context.res = res;
15129
+ return context;
15130
+ }
15131
+ };
15132
+ };
15133
+ //#endregion
15134
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/helper/route/index.js
15135
+ /**
15136
+ * Get matched routes in the handler
15137
+ *
15138
+ * @param {Context} c - The context object
15139
+ * @returns An array of matched routes
15140
+ *
15141
+ * @example
15142
+ * ```ts
15143
+ * import { matchedRoutes } from 'hono/route'
15144
+ *
15145
+ * app.use('*', async function logger(c, next) {
15146
+ * await next()
15147
+ * matchedRoutes(c).forEach(({ handler, method, path }, i) => {
15148
+ * const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
15149
+ * console.log(
15150
+ * method,
15151
+ * ' ',
15152
+ * path,
15153
+ * ' '.repeat(Math.max(10 - path.length, 0)),
15154
+ * name,
15155
+ * i === c.req.routeIndex ? '<- respond from here' : ''
15156
+ * )
15157
+ * })
15158
+ * })
15159
+ * ```
15160
+ */
15161
+ const matchedRoutes = (c) => c.req[GET_MATCH_RESULT][0].map(([[, route]]) => route);
15162
+ /**
15163
+ * Get the route path registered within the handler
15164
+ *
15165
+ * @param {Context} c - The context object
15166
+ * @param {number} index - The index of the route from which to retrieve the path, similar to Array.prototype.at(), where a negative number is the index counted from the end of the matching route. Defaults to the current route index.
15167
+ * @returns The route path registered within the handler
15168
+ *
15169
+ * @example
15170
+ * ```ts
15171
+ * import { routePath } from 'hono/route'
15172
+ *
15173
+ * app.use('*', (c, next) => {
15174
+ * console.log(routePath(c)) // '*'
15175
+ * console.log(routePath(c, -1)) // '/posts/:id'
15176
+ * return next()
15177
+ * })
15178
+ *
15179
+ * app.get('/posts/:id', (c) => {
15180
+ * return c.text(routePath(c)) // '/posts/:id'
15181
+ * })
15182
+ * ```
15183
+ */
15184
+ const routePath = (c, index) => matchedRoutes(c).at(index ?? c.req.routeIndex)?.path ?? "";
15185
+ //#endregion
15186
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router.js
15187
+ /**
15188
+ * Array of supported HTTP methods.
15189
+ */
15190
+ const METHODS = [
14980
15191
  "get",
14981
15192
  "post",
14982
15193
  "put",
14983
15194
  "delete",
14984
15195
  "options",
14985
- "patch"
15196
+ "patch",
15197
+ "query"
14986
15198
  ];
14987
- var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
15199
+ /**
15200
+ * Error message indicating that a route cannot be added because the matcher is already built.
15201
+ */
15202
+ const MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
15203
+ /**
15204
+ * Error class representing an unsupported path error.
15205
+ */
14988
15206
  var UnsupportedPathError = class extends Error {};
14989
15207
  //#endregion
14990
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/constants.js
14991
- var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
15208
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/constants.js
15209
+ /**
15210
+ * Constant used to mark a composed handler.
15211
+ */
15212
+ const COMPOSED_HANDLER = "__COMPOSED_HANDLER";
15213
+ //#endregion
15214
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/mount.js
15215
+ const countTrailingSlashes = (path) => {
15216
+ let index = path.length;
15217
+ while (index > 0 && path.charCodeAt(index - 1) === 47) index--;
15218
+ return path.length - index;
15219
+ };
15220
+ const getPathPrefixLength = (c, pathPrefix, routePath) => {
15221
+ if (!/[:*]/.test(pathPrefix)) return pathPrefix.length;
15222
+ const path = c.req.path;
15223
+ const matchResult = c.req[GET_MATCH_RESULT];
15224
+ const paramNames = /* @__PURE__ */ new Set();
15225
+ let length = 0;
15226
+ for (const part of splitRoutingPath(pathPrefix)) {
15227
+ if (part[0] === ":" && part.endsWith("}?")) throw new Error(`mount(): Optional regular expression parameters are not supported in "${routePath}".`);
15228
+ const pattern = getPattern(part);
15229
+ if (pattern && pattern !== "*") {
15230
+ const name = pattern[1];
15231
+ if (paramNames.has(name)) throw new Error(`mount(): Duplicate path parameter "${name}" in "${routePath}".`);
15232
+ paramNames.add(name);
15233
+ }
15234
+ if (pattern && pattern !== "*" && pattern[2] !== true) {
15235
+ const value = matchResult.length === 2 ? matchResult[1][matchResult[0][c.req.routeIndex][1][pattern[1]]] : matchResult[0][c.req.routeIndex][1][pattern[1]];
15236
+ length += value.length + 1;
15237
+ } else if (pattern || part.endsWith("*")) {
15238
+ const end = path.indexOf("/", length + 1);
15239
+ length = end === -1 ? path.length : end;
15240
+ } else length += part.length + 1;
15241
+ }
15242
+ return length;
15243
+ };
15244
+ const createMountedRequest = (c, pathPrefix, routePath) => {
15245
+ if (/[^/]\*$/.test(routePath)) throw new Error(`mount(): Wildcard must follow "/" in "${routePath}".`);
15246
+ const prefixLength = getPathPrefixLength(c, pathPrefix, routePath);
15247
+ const path = c.req.path.slice(prefixLength) || "/";
15248
+ if (prefixLength > c.req.path.length || path[0] !== "/" || /\/(?:\.|%2e){1,2}(?:\/|$)/i.test(path)) throw new HTTPException(400, { message: "Invalid mounted path" });
15249
+ const rawUrl = c.req.raw.url;
15250
+ if (/^[^/?#]*\/\/[^/?#\\]*[?#\\]/.test(rawUrl)) throw new HTTPException(400, { message: "Invalid mounted path" });
15251
+ const rawPathEnd = rawUrl.search(/[?#]/);
15252
+ const rawTrailingSlashes = countTrailingSlashes(rawPathEnd === -1 ? rawUrl : rawUrl.slice(0, rawPathEnd));
15253
+ if (rawTrailingSlashes > 1 && countTrailingSlashes(c.req.path) === rawTrailingSlashes - 1) throw new HTTPException(400, { message: "Invalid mounted path" });
15254
+ const url = new URL(rawUrl);
15255
+ url.pathname = path.replace(/[\\\t\n\r]/g, encodeURIComponent);
15256
+ if (path.includes("%")) {}
15257
+ return new Request(url, c.req.raw);
15258
+ };
14992
15259
  //#endregion
14993
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/hono-base.js
14994
- var notFoundHandler = (c) => {
15260
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/hono-base.js
15261
+ /**
15262
+ * @module
15263
+ * This module is the base module for the Hono object.
15264
+ */
15265
+ const notFoundHandler = (c) => {
14995
15266
  return c.text("404 Not Found", 404);
14996
15267
  };
14997
- var errorHandler = (err, c) => {
15268
+ const errorHandler = (err, c) => {
14998
15269
  if ("getResponse" in err) {
14999
15270
  const res = err.getResponse();
15000
15271
  return c.newResponse(res.body, res);
@@ -15002,13 +15273,14 @@ var errorHandler = (err, c) => {
15002
15273
  console.error(err);
15003
15274
  return c.text("Internal Server Error", 500);
15004
15275
  };
15005
- var Hono$1 = class _Hono {
15276
+ var Hono$1 = class Hono {
15006
15277
  get;
15007
15278
  post;
15008
15279
  put;
15009
15280
  delete;
15010
15281
  options;
15011
15282
  patch;
15283
+ query;
15012
15284
  all;
15013
15285
  on;
15014
15286
  use;
@@ -15020,10 +15292,11 @@ var Hono$1 = class _Hono {
15020
15292
  constructor(options = {}) {
15021
15293
  [...METHODS, "all"].forEach((method) => {
15022
15294
  this[method] = (args1, ...args) => {
15295
+ const methodName = method.toUpperCase();
15023
15296
  if (typeof args1 === "string") this.#path = args1;
15024
- else this.#addRoute(method, this.#path, args1);
15297
+ else this.#addRoute(methodName, this.#path, args1);
15025
15298
  args.forEach((handler) => {
15026
- this.#addRoute(method, this.#path, handler);
15299
+ this.#addRoute(methodName, this.#path, handler);
15027
15300
  });
15028
15301
  return this;
15029
15302
  };
@@ -15031,9 +15304,10 @@ var Hono$1 = class _Hono {
15031
15304
  this.on = (method, path, ...handlers) => {
15032
15305
  for (const p of [path].flat()) {
15033
15306
  this.#path = p;
15034
- for (const m of [method].flat()) handlers.map((handler) => {
15035
- this.#addRoute(m.toUpperCase(), this.#path, handler);
15036
- });
15307
+ for (const m of [method].flat()) {
15308
+ const methodName = m.toUpperCase();
15309
+ for (const handler of handlers) this.#addRoute(methodName, this.#path, handler);
15310
+ }
15037
15311
  }
15038
15312
  return this;
15039
15313
  };
@@ -15053,7 +15327,7 @@ var Hono$1 = class _Hono {
15053
15327
  this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
15054
15328
  }
15055
15329
  #clone() {
15056
- const clone = new _Hono({
15330
+ const clone = new Hono({
15057
15331
  router: this.router,
15058
15332
  getPath: this.getPath
15059
15333
  });
@@ -15155,12 +15429,16 @@ var Hono$1 = class _Hono {
15155
15429
  /**
15156
15430
  * `.mount()` allows you to mount applications built with other frameworks into your Hono application.
15157
15431
  *
15432
+ * @deprecated Use `mount()` from `hono/mount` instead. `.mount()` will be removed in v5.
15433
+ *
15158
15434
  * @see {@link https://hono.dev/docs/api/hono#mount}
15159
15435
  *
15160
15436
  * @param {string} path - base Path
15161
15437
  * @param {Function} applicationHandler - other Request Handler
15162
15438
  * @param {MountOptions} [options] - options of `.mount()`
15163
15439
  * @returns {Hono} mounted Hono instance
15440
+ * @throws {Error} If automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
15441
+ * @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
15164
15442
  *
15165
15443
  * @example
15166
15444
  * ```ts
@@ -15196,8 +15474,8 @@ var Hono$1 = class _Hono {
15196
15474
  }
15197
15475
  }
15198
15476
  const getOptions = optionHandler ? (c) => {
15199
- const options2 = optionHandler(c);
15200
- return Array.isArray(options2) ? options2 : [options2];
15477
+ const options = optionHandler(c);
15478
+ return Array.isArray(options) ? options : [options];
15201
15479
  } : (c) => {
15202
15480
  let executionContext = void 0;
15203
15481
  try {
@@ -15205,17 +15483,12 @@ var Hono$1 = class _Hono {
15205
15483
  } catch {}
15206
15484
  return [c.env, executionContext];
15207
15485
  };
15208
- replaceRequest ||= (() => {
15209
- const mergedPath = mergePath(this._basePath, path);
15210
- const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
15211
- return (request) => {
15212
- const url = new URL(request.url);
15213
- url.pathname = this.getPath(request).slice(pathPrefixLength) || "/";
15214
- return new Request(url, request);
15215
- };
15216
- })();
15486
+ const defaultReplaceRequest = (c) => {
15487
+ const mountedRoutePath = routePath(c);
15488
+ return createMountedRequest(c, mountedRoutePath.replace(/\/?\*$/, ""), mountedRoutePath);
15489
+ };
15217
15490
  const handler = async (c, next) => {
15218
- const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
15491
+ const res = await applicationHandler(replaceRequest ? replaceRequest(c.req.raw) : defaultReplaceRequest(c), ...getOptions(c));
15219
15492
  if (res) return res;
15220
15493
  await next();
15221
15494
  };
@@ -15223,7 +15496,6 @@ var Hono$1 = class _Hono {
15223
15496
  return this;
15224
15497
  }
15225
15498
  #addRoute(method, path, handler, baseRoutePath) {
15226
- method = method.toUpperCase();
15227
15499
  path = mergePath(this._basePath, path);
15228
15500
  const r = {
15229
15501
  basePath: baseRoutePath !== void 0 ? mergePath(this._basePath, baseRoutePath) : this._basePath,
@@ -15277,8 +15549,8 @@ var Hono$1 = class _Hono {
15277
15549
  * @see {@link https://hono.dev/docs/api/hono#fetch}
15278
15550
  *
15279
15551
  * @param {Request} request - request Object of request
15280
- * @param {Env} Env - env Object
15281
- * @param {ExecutionContext} - context of execution
15552
+ * @param {Env} env - env Object
15553
+ * @param {ExecutionContext} executionCtx - context of execution
15282
15554
  * @returns {Response | Promise<Response>} response of request
15283
15555
  *
15284
15556
  */
@@ -15326,112 +15598,140 @@ var Hono$1 = class _Hono {
15326
15598
  };
15327
15599
  };
15328
15600
  //#endregion
15329
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/matcher.js
15330
- var emptyParam = [];
15601
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/utils.js
15602
+ const createNullObject = () => Object.create(null);
15603
+ //#endregion
15604
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/reg-exp-router/matcher.js
15605
+ const emptyParam = [];
15331
15606
  function match(method, path) {
15332
15607
  const matchers = this.buildAllMatchers();
15333
- const match2 = ((method2, path2) => {
15334
- const matcher = matchers[method2] || matchers["ALL"];
15335
- const staticMatch = matcher[2][path2];
15608
+ const match = ((method, path) => {
15609
+ const matcher = matchers[method] || matchers["ALL"];
15610
+ const staticMatch = matcher[2][path];
15336
15611
  if (staticMatch) return staticMatch;
15337
- const match3 = path2.match(matcher[0]);
15338
- if (!match3) return [[], emptyParam];
15339
- const index = match3.indexOf("", 1);
15340
- return [matcher[1][index], match3];
15612
+ const match = path.match(matcher[0]);
15613
+ if (!match) return [[], emptyParam];
15614
+ const index = match.indexOf("", 1);
15615
+ return [matcher[1][index], match];
15341
15616
  });
15342
- this.match = match2;
15343
- return match2(method, path);
15617
+ this.match = match;
15618
+ return match(method, path);
15344
15619
  }
15345
15620
  //#endregion
15346
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/node.js
15347
- var LABEL_REG_EXP_STR = "[^/]+";
15348
- var ONLY_WILDCARD_REG_EXP_STR = ".*";
15349
- var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
15350
- var PATH_ERROR = /* @__PURE__ */ Symbol();
15351
- var regExpMetaChars = /* @__PURE__ */ new Set(".\\+*[^]$()");
15621
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/reg-exp-router/node.js
15622
+ const LABEL_REG_EXP_STR = "[^/]+";
15623
+ const ONLY_WILDCARD_REG_EXP_STR = "[^]*";
15624
+ const TAIL_WILDCARD_REG_EXP_STR = "(?:|/[^]*)";
15625
+ const PATH_ERROR = Symbol();
15626
+ const regExpMetaChars = /* @__PURE__ */ new Set(".\\+*[^]$()");
15627
+ /**
15628
+ * Sort order:
15629
+ * 1. literal
15630
+ * 2. special pattern (e.g. :label{[0-9]+})
15631
+ * 3. common label pattern (e.g. :label)
15632
+ * 4. wildcard
15633
+ */
15352
15634
  function compareKey(a, b) {
15353
15635
  if (a.length === 1) return b.length === 1 ? a < b ? -1 : 1 : -1;
15354
15636
  if (b.length === 1) return 1;
15355
- if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) return 1;
15356
- else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) return -1;
15357
- if (a === LABEL_REG_EXP_STR) return 1;
15358
- else if (b === LABEL_REG_EXP_STR) return -1;
15637
+ if (a === "[^]*" || a === "(?:|/[^]*)") return b === "[^]*" ? -1 : 1;
15638
+ else if (b === "[^]*" || b === "(?:|/[^]*)") return -1;
15639
+ if (a === "[^/]+") return 1;
15640
+ else if (b === "[^/]+") return -1;
15359
15641
  return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
15360
15642
  }
15361
- var Node$1 = class _Node {
15643
+ var Node$1 = class Node {
15362
15644
  #index;
15363
15645
  #varIndex;
15364
- #children = /* @__PURE__ */ Object.create(null);
15365
- insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
15366
- if (tokens.length === 0) {
15367
- if (this.#index !== void 0) throw PATH_ERROR;
15368
- if (pathErrorCheckOnly) return;
15369
- this.#index = index;
15370
- return;
15371
- }
15372
- const [token, ...restTokens] = tokens;
15373
- const pattern = token === "*" ? restTokens.length === 0 ? [
15374
- "",
15375
- "",
15376
- ONLY_WILDCARD_REG_EXP_STR
15377
- ] : [
15378
- "",
15379
- "",
15380
- LABEL_REG_EXP_STR
15381
- ] : token === "/*" ? [
15382
- "",
15383
- "",
15384
- TAIL_WILDCARD_REG_EXP_STR
15385
- ] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
15386
- let node;
15387
- if (pattern) {
15388
- const name = pattern[1];
15389
- let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
15390
- if (name && pattern[2]) {
15391
- if (regexpStr === ".*") throw PATH_ERROR;
15392
- regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
15393
- if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
15394
- }
15395
- node = this.#children[regexpStr];
15396
- if (!node) {
15397
- if (Object.keys(this.#children).some((k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) throw PATH_ERROR;
15398
- if (pathErrorCheckOnly) return;
15399
- node = this.#children[regexpStr] = new _Node();
15400
- if (name !== "") node.#varIndex = context.varIndex++;
15401
- }
15402
- if (!pathErrorCheckOnly && name !== "") paramMap.push([name, node.#varIndex]);
15403
- } else {
15404
- node = this.#children[token];
15405
- if (!node) {
15406
- if (Object.keys(this.#children).some((k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) throw PATH_ERROR;
15407
- if (pathErrorCheckOnly) return;
15408
- node = this.#children[token] = new _Node();
15646
+ #children = createNullObject();
15647
+ insert(tokens, index, paramMap, context, keys) {
15648
+ let node = this;
15649
+ for (let i = 0, len = tokens.length; i < len; i++) {
15650
+ const token = tokens[i];
15651
+ const pattern = token.length === 1 ? token === "*" ? i === len - 1 ? [
15652
+ "",
15653
+ "",
15654
+ ONLY_WILDCARD_REG_EXP_STR
15655
+ ] : [
15656
+ "",
15657
+ "",
15658
+ LABEL_REG_EXP_STR
15659
+ ] : null : token === "/*" ? [
15660
+ "",
15661
+ "",
15662
+ TAIL_WILDCARD_REG_EXP_STR
15663
+ ] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
15664
+ let nextNode;
15665
+ if (pattern) {
15666
+ const name = pattern[1];
15667
+ let regexpStr = pattern[2] || "[^/]+";
15668
+ if (name && pattern[2]) {
15669
+ if (new RegExp(regexpStr).test("")) throw PATH_ERROR;
15670
+ regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
15671
+ if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
15672
+ if (regexpStr.length === 1 && regExpMetaChars.has(regexpStr)) throw PATH_ERROR;
15673
+ }
15674
+ keys.push(regexpStr);
15675
+ nextNode = node.#children[regexpStr];
15676
+ if (!nextNode) {
15677
+ if (regexpStr !== "[^]*" && regexpStr !== "(?:|/[^]*)") {
15678
+ for (const k in node.#children) if ((regexpStr.length > 1 || k.length > 1) && k !== "[^]*" && k !== "(?:|/[^]*)") throw PATH_ERROR;
15679
+ }
15680
+ nextNode = node.#children[regexpStr] = new Node();
15681
+ }
15682
+ if (name !== "") {
15683
+ nextNode.#varIndex ??= context.varIndex++;
15684
+ paramMap.push([name, nextNode.#varIndex]);
15685
+ }
15686
+ } else {
15687
+ keys.push(token);
15688
+ nextNode = node.#children[token];
15689
+ if (!nextNode) {
15690
+ for (const k in node.#children) if (k.length > 1 && k !== "[^]*" && k !== "(?:|/[^]*)") throw PATH_ERROR;
15691
+ nextNode = node.#children[token] = new Node();
15692
+ }
15409
15693
  }
15694
+ node = nextNode;
15410
15695
  }
15411
- node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
15696
+ if (node.#index !== void 0) throw PATH_ERROR;
15697
+ node.#index = index;
15412
15698
  }
15413
15699
  buildRegExpStr() {
15414
15700
  const strList = Object.keys(this.#children).sort(compareKey).map((k) => {
15415
15701
  const c = this.#children[k];
15416
- return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
15417
- });
15418
- if (typeof this.#index === "number") strList.unshift(`#${this.#index}`);
15702
+ const childStr = c.buildRegExpStr();
15703
+ return childStr === "" ? "" : (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + childStr;
15704
+ }).filter(Boolean);
15705
+ if (typeof this.#index === "number" && this.#index !== -1) strList.unshift(`#${this.#index}`);
15419
15706
  if (strList.length === 0) return "";
15420
15707
  if (strList.length === 1) return strList[0];
15421
15708
  return "(?:" + strList.join("|") + ")";
15422
15709
  }
15423
15710
  };
15424
15711
  //#endregion
15425
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/trie.js
15712
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/reg-exp-router/trie.js
15426
15713
  var Trie = class {
15427
15714
  #context = { varIndex: 0 };
15428
15715
  #root = new Node$1();
15429
- insert(path, index, pathErrorCheckOnly) {
15716
+ #index = 0;
15717
+ paths = createNullObject();
15718
+ insert(path, isStatic) {
15719
+ const keys = [];
15720
+ if (isStatic) {
15721
+ this.#root.insert(path.split(""), -1, [], this.#context, keys);
15722
+ this.paths[path] = [
15723
+ -1,
15724
+ [],
15725
+ keys
15726
+ ];
15727
+ return;
15728
+ }
15430
15729
  const paramAssoc = [];
15431
15730
  const groups = [];
15731
+ let markedPath = path;
15432
15732
  for (let i = 0;;) {
15433
15733
  let replaced = false;
15434
- path = path.replace(/\{[^}]+\}/g, (m) => {
15734
+ markedPath = markedPath.replace(/\{(?:\{[\d,]+\}|[^}])+\}/g, (m) => {
15435
15735
  const mark = `@\\${i}`;
15436
15736
  groups[i] = [mark, m];
15437
15737
  i++;
@@ -15440,7 +15740,12 @@ var Trie = class {
15440
15740
  });
15441
15741
  if (!replaced) break;
15442
15742
  }
15443
- const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
15743
+ /**
15744
+ * - pattern (:label, :label{0-9]+}, ...)
15745
+ * - /* wildcard
15746
+ * - character
15747
+ */
15748
+ const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./gs) || [];
15444
15749
  for (let i = groups.length - 1; i >= 0; i--) {
15445
15750
  const [mark] = groups[i];
15446
15751
  for (let j = tokens.length - 1; j >= 0; j--) if (tokens[j].indexOf(mark) !== -1) {
@@ -15448,8 +15753,12 @@ var Trie = class {
15448
15753
  break;
15449
15754
  }
15450
15755
  }
15451
- this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
15452
- return paramAssoc;
15756
+ this.#root.insert(tokens, this.#index, paramAssoc, this.#context, keys);
15757
+ this.paths[path] = [
15758
+ this.#index++,
15759
+ paramAssoc,
15760
+ keys
15761
+ ];
15453
15762
  }
15454
15763
  buildRegExp() {
15455
15764
  let regexp = this.#root.buildRegExpStr();
@@ -15480,138 +15789,89 @@ var Trie = class {
15480
15789
  }
15481
15790
  };
15482
15791
  //#endregion
15483
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/router.js
15484
- var nullMatcher = [
15485
- /^$/,
15486
- [],
15487
- /* @__PURE__ */ Object.create(null)
15488
- ];
15489
- var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
15490
- function buildWildcardRegExp(path) {
15491
- return wildcardRegExpCache[path] ??= new RegExp(path === "*" ? "" : `^${path.replace(/\/\*$|([.\\+*[^\]$()])/g, (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)")}$`);
15792
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/reg-exp-router/router.js
15793
+ function endsWithWildcard(keys) {
15794
+ const tail = keys[keys.length - 1];
15795
+ return tail === "[^]*" || tail === "(?:|/[^]*)";
15492
15796
  }
15493
- function clearWildcardRegExpCache() {
15494
- wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
15797
+ function covers(wildcard, target) {
15798
+ const last = wildcard.length - 1;
15799
+ for (let i = 0; i < last; i++) if (wildcard[i] !== target[i]) return false;
15800
+ return wildcard[last] === "[^]*" || target.length === last || target[last] === "/";
15495
15801
  }
15496
- function buildMatcherFromPreprocessedRoutes(routes) {
15497
- const trie = new Trie();
15498
- const handlerData = [];
15499
- if (routes.length === 0) return nullMatcher;
15500
- const routesWithStaticPathFlag = routes.map((route) => [!/\*|\/:/.test(route[0]), ...route]).sort(([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length);
15501
- const staticMap = /* @__PURE__ */ Object.create(null);
15502
- for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
15503
- const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
15504
- if (pathErrorCheckOnly) staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
15505
- else j++;
15506
- let paramAssoc;
15802
+ var RegExpRouter = class {
15803
+ name = "RegExpRouter";
15804
+ #handlers;
15805
+ #tries;
15806
+ constructor() {
15807
+ this.#handlers = { ["ALL"]: [] };
15808
+ this.#tries = { ["ALL"]: new Trie() };
15809
+ }
15810
+ #insertPath(method, path) {
15507
15811
  try {
15508
- paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
15812
+ this.#tries[method].insert(path, !/\*|\/:/.test(path));
15509
15813
  } catch (e) {
15510
15814
  throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
15511
15815
  }
15512
- if (pathErrorCheckOnly) continue;
15513
- handlerData[j] = handlers.map(([h, paramCount]) => {
15514
- const paramIndexMap = /* @__PURE__ */ Object.create(null);
15515
- paramCount -= 1;
15516
- for (; paramCount >= 0; paramCount--) {
15517
- const [key, value] = paramAssoc[paramCount];
15518
- paramIndexMap[key] = value;
15519
- }
15520
- return [h, paramIndexMap];
15521
- });
15522
- }
15523
- const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
15524
- for (let i = 0, len = handlerData.length; i < len; i++) for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
15525
- const map = handlerData[i][j]?.[1];
15526
- if (!map) continue;
15527
- const keys = Object.keys(map);
15528
- for (let k = 0, len3 = keys.length; k < len3; k++) map[keys[k]] = paramReplacementMap[map[keys[k]]];
15529
- }
15530
- const handlerMap = [];
15531
- for (const i in indexReplacementMap) handlerMap[i] = handlerData[indexReplacementMap[i]];
15532
- return [
15533
- regexp,
15534
- handlerMap,
15535
- staticMap
15536
- ];
15537
- }
15538
- function findMiddleware(middleware, path) {
15539
- if (!middleware) return;
15540
- for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) if (buildWildcardRegExp(k).test(path)) return [...middleware[k]];
15541
- }
15542
- var RegExpRouter = class {
15543
- name = "RegExpRouter";
15544
- #middleware;
15545
- #routes;
15546
- constructor() {
15547
- this.#middleware = { ["ALL"]: /* @__PURE__ */ Object.create(null) };
15548
- this.#routes = { ["ALL"]: /* @__PURE__ */ Object.create(null) };
15549
15816
  }
15550
15817
  add(method, path, handler) {
15551
- const middleware = this.#middleware;
15552
- const routes = this.#routes;
15553
- if (!middleware || !routes) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
15554
- if (!middleware[method]) [middleware, routes].forEach((handlerMap) => {
15555
- handlerMap[method] = /* @__PURE__ */ Object.create(null);
15556
- Object.keys(handlerMap["ALL"]).forEach((p) => {
15557
- handlerMap[method][p] = [...handlerMap["ALL"][p]];
15558
- });
15559
- });
15560
- if (path === "/*") path = "*";
15561
- const paramCount = (path.match(/\/:/g) || []).length;
15562
- if (/\*$/.test(path)) {
15563
- const re = buildWildcardRegExp(path);
15564
- if (method === "ALL") Object.keys(middleware).forEach((m) => {
15565
- middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware["ALL"], path) || [];
15566
- });
15567
- else middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware["ALL"], path) || [];
15568
- Object.keys(middleware).forEach((m) => {
15569
- if (method === "ALL" || method === m) Object.keys(middleware[m]).forEach((p) => {
15570
- re.test(p) && middleware[m][p].push([handler, paramCount]);
15571
- });
15572
- });
15573
- Object.keys(routes).forEach((m) => {
15574
- if (method === "ALL" || method === m) Object.keys(routes[m]).forEach((p) => re.test(p) && routes[m][p].push([handler, paramCount]));
15575
- });
15576
- return;
15818
+ const handlers = this.#handlers;
15819
+ if (!handlers) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
15820
+ const tries = this.#tries;
15821
+ if (!handlers[method]) {
15822
+ tries[method] = new Trie();
15823
+ handlers[method] = [...handlers["ALL"]];
15824
+ for (const p in tries["ALL"].paths) this.#insertPath(method, p);
15577
15825
  }
15826
+ if (path === "/*") path = "*";
15827
+ const methods = method === "ALL" ? Object.keys(handlers) : [method];
15578
15828
  const paths = checkOptionalParameter(path) || [path];
15579
- for (let i = 0, len = paths.length; i < len; i++) {
15580
- const path2 = paths[i];
15581
- Object.keys(routes).forEach((m) => {
15582
- if (method === "ALL" || method === m) {
15583
- routes[m][path2] ||= [...findMiddleware(middleware[m], path2) || findMiddleware(middleware["ALL"], path2) || []];
15584
- routes[m][path2].push([handler, paramCount - len + i + 1]);
15585
- }
15586
- });
15829
+ for (const path of paths) for (const m of methods) {
15830
+ if (!tries[m].paths[path]) this.#insertPath(m, path);
15831
+ handlers[m].push([handler, path]);
15587
15832
  }
15588
15833
  }
15589
15834
  match = match;
15590
15835
  buildAllMatchers() {
15591
- const matchers = /* @__PURE__ */ Object.create(null);
15592
- Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
15593
- matchers[method] ||= this.#buildMatcher(method);
15594
- });
15595
- this.#middleware = this.#routes = void 0;
15596
- clearWildcardRegExpCache();
15836
+ const matchers = createNullObject();
15837
+ for (const method of Object.keys(this.#handlers)) matchers[method] = this.#buildMatcher(method);
15838
+ this.#handlers = this.#tries = void 0;
15597
15839
  return matchers;
15598
15840
  }
15599
15841
  #buildMatcher(method) {
15600
- const routes = [];
15601
- let hasOwnRoute = method === "ALL";
15602
- [this.#middleware, this.#routes].forEach((r) => {
15603
- const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
15604
- if (ownRoute.length !== 0) {
15605
- hasOwnRoute ||= true;
15606
- routes.push(...ownRoute);
15607
- } else if (method !== "ALL") routes.push(...Object.keys(r["ALL"]).map((path) => [path, r["ALL"][path]]));
15842
+ const handlers = this.#handlers[method];
15843
+ const trie = this.#tries[method];
15844
+ const staticMap = createNullObject();
15845
+ const handlerData = [];
15846
+ const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
15847
+ const own = createNullObject();
15848
+ const entries = handlers.map(([h, p], i) => {
15849
+ (own[p] ??= []).push(i);
15850
+ return [h, trie.paths[p][1].reduceRight((map, [key, varIndex]) => {
15851
+ map[key] = paramReplacementMap[varIndex];
15852
+ return map;
15853
+ }, createNullObject())];
15608
15854
  });
15609
- if (!hasOwnRoute) return null;
15610
- else return buildMatcherFromPreprocessedRoutes(routes);
15855
+ const wildcards = Object.keys(own).filter((p) => endsWithWildcard(trie.paths[p][2]));
15856
+ for (const path in trie.paths) {
15857
+ const [index, , keys] = trie.paths[path];
15858
+ const indexes = [...own[path]];
15859
+ for (const p of wildcards) if (p !== path && covers(trie.paths[p][2], keys)) indexes.push(...own[p]);
15860
+ const data = indexes.sort((a, b) => a - b).map((i) => entries[i]);
15861
+ if (index === -1) {
15862
+ const last = Math.max(-1, ...data.flatMap(([, map]) => Object.values(map)));
15863
+ staticMap[path] = [data, last === -1 ? emptyParam : path.match(regexp).slice(0, last + 1)];
15864
+ } else handlerData[index] = data;
15865
+ }
15866
+ return [
15867
+ regexp,
15868
+ indexReplacementMap.map((i) => handlerData[i]),
15869
+ staticMap
15870
+ ];
15611
15871
  }
15612
15872
  };
15613
15873
  //#endregion
15614
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/smart-router/router.js
15874
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/smart-router/router.js
15615
15875
  var SmartRouter = class {
15616
15876
  name = "SmartRouter";
15617
15877
  #routers = [];
@@ -15637,7 +15897,7 @@ var SmartRouter = class {
15637
15897
  for (; i < len; i++) {
15638
15898
  const router = routers[i];
15639
15899
  try {
15640
- for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) router.add(...routes[i2]);
15900
+ for (let i = 0, len = routes.length; i < len; i++) router.add(...routes[i]);
15641
15901
  res = router.match(method, path);
15642
15902
  } catch (e) {
15643
15903
  if (e instanceof UnsupportedPathError) continue;
@@ -15658,74 +15918,49 @@ var SmartRouter = class {
15658
15918
  }
15659
15919
  };
15660
15920
  //#endregion
15661
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/trie-router/node.js
15662
- var emptyParams = /* @__PURE__ */ Object.create(null);
15663
- var hasChildren = (children) => {
15664
- for (const _ in children) return true;
15665
- return false;
15666
- };
15667
- var Node = class _Node {
15668
- #methods;
15669
- #children;
15670
- #patterns;
15671
- #order = 0;
15921
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/trie-router/node.js
15922
+ const emptyParams = createNullObject();
15923
+ let order = 0;
15924
+ var Node = class Node {
15925
+ #methods = [];
15926
+ #children = createNullObject();
15927
+ #patterns = [];
15928
+ #pattern;
15672
15929
  #params = emptyParams;
15673
- constructor(method, handler, children) {
15674
- this.#children = children || /* @__PURE__ */ Object.create(null);
15675
- this.#methods = [];
15676
- if (method && handler) {
15677
- const m = /* @__PURE__ */ Object.create(null);
15678
- m[method] = {
15679
- handler,
15680
- possibleKeys: [],
15681
- score: 0
15682
- };
15683
- this.#methods = [m];
15684
- }
15685
- this.#patterns = [];
15686
- }
15687
15930
  insert(method, path, handler) {
15688
- this.#order = ++this.#order;
15689
15931
  let curNode = this;
15690
15932
  const parts = splitRoutingPath(path);
15691
- const possibleKeys = [];
15692
- for (let i = 0, len = parts.length; i < len; i++) {
15693
- const p = parts[i];
15694
- const nextP = parts[i + 1];
15695
- const pattern = getPattern(p, nextP);
15696
- const key = Array.isArray(pattern) ? pattern[0] : p;
15697
- if (key in curNode.#children) {
15698
- curNode = curNode.#children[key];
15699
- if (pattern) possibleKeys.push(pattern[1]);
15700
- continue;
15701
- }
15702
- curNode.#children[key] = new _Node();
15703
- if (pattern) {
15704
- curNode.#patterns.push(pattern);
15705
- possibleKeys.push(pattern[1]);
15933
+ const possibleKeys = /* @__PURE__ */ new Set();
15934
+ let i = 0;
15935
+ for (const p of parts) {
15936
+ const nextP = parts[++i];
15937
+ const pattern = getPattern(p, nextP) || (nextP === void 0 && p && p.indexOf("*") === p.length - 1 ? p : null);
15938
+ const isParam = Array.isArray(pattern);
15939
+ const key = isParam ? pattern[0] : pattern || p;
15940
+ const child = curNode.#children[key] ||= new Node();
15941
+ if (pattern && !child.#pattern) {
15942
+ child.#pattern = pattern;
15943
+ curNode.#patterns.push(child);
15706
15944
  }
15707
- curNode = curNode.#children[key];
15945
+ curNode = child;
15946
+ if (isParam) possibleKeys.add(pattern[1]);
15708
15947
  }
15709
15948
  curNode.#methods.push({ [method]: {
15710
15949
  handler,
15711
- possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
15712
- score: this.#order
15950
+ possibleKeys: [...possibleKeys],
15951
+ score: ++order
15713
15952
  } });
15714
- return curNode;
15715
15953
  }
15716
15954
  #pushHandlerSets(handlerSets, node, method, nodeParams, params) {
15717
15955
  for (let i = 0, len = node.#methods.length; i < len; i++) {
15718
15956
  const m = node.#methods[i];
15719
15957
  const handlerSet = m[method] || m["ALL"];
15720
- const processedSet = {};
15721
- if (handlerSet !== void 0) {
15722
- handlerSet.params = /* @__PURE__ */ Object.create(null);
15958
+ if (handlerSet) {
15959
+ handlerSet.params = createNullObject();
15723
15960
  handlerSets.push(handlerSet);
15724
- if (nodeParams !== emptyParams || params && params !== emptyParams) for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
15725
- const key = handlerSet.possibleKeys[i2];
15726
- const processed = processedSet[handlerSet.score];
15727
- handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
15728
- processedSet[handlerSet.score] = true;
15961
+ for (let i = 0, len = handlerSet.possibleKeys.length; i < len; i++) {
15962
+ const key = handlerSet.possibleKeys[i];
15963
+ handlerSet.params[key] = params?.[key] && !i ? params[key] : nodeParams[key] ?? params?.[key];
15729
15964
  }
15730
15965
  }
15731
15966
  }
@@ -15752,46 +15987,47 @@ var Node = class _Node {
15752
15987
  this.#pushHandlerSets(handlerSets, nextNode, method, node.#params);
15753
15988
  } else tempNodes.push(nextNode);
15754
15989
  }
15755
- for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
15756
- const pattern = node.#patterns[k];
15990
+ for (const child of node.#patterns) {
15991
+ const pattern = child.#pattern;
15757
15992
  const params = node.#params === emptyParams ? {} : { ...node.#params };
15758
- if (pattern === "*") {
15759
- const astNode = node.#children["*"];
15760
- if (astNode) {
15761
- this.#pushHandlerSets(handlerSets, astNode, method, node.#params);
15762
- astNode.#params = params;
15763
- tempNodes.push(astNode);
15993
+ if (typeof pattern === "string") {
15994
+ if (pattern === "*" || part.startsWith(pattern.slice(0, -1))) {
15995
+ this.#pushHandlerSets(handlerSets, child, method, node.#params);
15996
+ if (pattern === "*") {
15997
+ child.#params = params;
15998
+ tempNodes.push(child);
15999
+ }
15764
16000
  }
15765
16001
  continue;
15766
16002
  }
15767
- const [key, name, matcher] = pattern;
15768
- if (!part && !(matcher instanceof RegExp)) continue;
15769
- const child = node.#children[key];
15770
- if (matcher instanceof RegExp) {
15771
- if (partOffsets === null) {
15772
- partOffsets = new Array(len);
16003
+ const [, name, matcher] = pattern;
16004
+ if (!part && matcher === true) continue;
16005
+ if (matcher !== true) {
16006
+ if (!partOffsets) {
16007
+ partOffsets = [];
15773
16008
  let offset = path[0] === "/" ? 1 : 0;
15774
16009
  for (let p = 0; p < len; p++) {
15775
16010
  partOffsets[p] = offset;
15776
16011
  offset += parts[p].length + 1;
15777
16012
  }
15778
16013
  }
15779
- const restPathString = path.substring(partOffsets[i]);
16014
+ const restPathString = path.slice(partOffsets[i]);
15780
16015
  const m = matcher.exec(restPathString);
15781
16016
  if (m) {
15782
- params[name] = m[0];
16017
+ if (!Object.hasOwn(params, name)) params[name] = m[0];
15783
16018
  this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
15784
16019
  if (m[0].length === restPathString.length && child.#children["*"]) this.#pushHandlerSets(handlerSets, child.#children["*"], method, node.#params, params);
15785
- if (hasChildren(child.#children)) {
16020
+ for (const _ in child.#children) {
15786
16021
  child.#params = params;
15787
- const componentCount = m[0].match(/\//)?.length ?? 0;
16022
+ const componentCount = m[0].match(/\//g)?.length ?? 0;
15788
16023
  (curNodesQueue[componentCount] ||= []).push(child);
16024
+ break;
15789
16025
  }
15790
16026
  continue;
15791
16027
  }
15792
16028
  }
15793
16029
  if (matcher === true || matcher.test(part)) {
15794
- params[name] = part;
16030
+ if (!Object.hasOwn(params, name)) params[name] = part;
15795
16031
  if (isLast) {
15796
16032
  this.#pushHandlerSets(handlerSets, child, method, params, node.#params);
15797
16033
  if (child.#children["*"]) this.#pushHandlerSets(handlerSets, child.#children["*"], method, params, node.#params);
@@ -15805,34 +16041,34 @@ var Node = class _Node {
15805
16041
  const shifted = curNodesQueue.shift();
15806
16042
  curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
15807
16043
  }
15808
- if (handlerSets.length > 1) handlerSets.sort((a, b) => {
16044
+ if (handlerSets[1]) handlerSets.sort((a, b) => {
15809
16045
  return a.score - b.score;
15810
16046
  });
15811
16047
  return [handlerSets.map(({ handler, params }) => [handler, params])];
15812
16048
  }
15813
16049
  };
15814
16050
  //#endregion
15815
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/trie-router/router.js
16051
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/trie-router/router.js
15816
16052
  var TrieRouter = class {
15817
16053
  name = "TrieRouter";
15818
- #node;
15819
- constructor() {
15820
- this.#node = new Node();
15821
- }
16054
+ #node = new Node();
15822
16055
  add(method, path, handler) {
15823
- const results = checkOptionalParameter(path);
15824
- if (results) {
15825
- for (let i = 0, len = results.length; i < len; i++) this.#node.insert(method, results[i], handler);
15826
- return;
15827
- }
15828
- this.#node.insert(method, path, handler);
16056
+ for (const result of checkOptionalParameter(path) || [path]) this.#node.insert(method, result, handler);
15829
16057
  }
15830
16058
  match(method, path) {
15831
16059
  return this.#node.search(method, path);
15832
16060
  }
15833
16061
  };
15834
16062
  //#endregion
15835
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/hono.js
16063
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/hono.js
16064
+ /**
16065
+ * The Hono class extends the functionality of the HonoBase class.
16066
+ * It sets up routing and allows for custom options to be passed.
16067
+ *
16068
+ * @template E - The environment type.
16069
+ * @template S - The schema type.
16070
+ * @template BasePath - The base path type.
16071
+ */
15836
16072
  var Hono = class extends Hono$1 {
15837
16073
  /**
15838
16074
  * Creates an instance of the Hono class.
@@ -15845,14 +16081,14 @@ var Hono = class extends Hono$1 {
15845
16081
  }
15846
16082
  };
15847
16083
  //#endregion
15848
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/encode.js
15849
- var encodeBase64 = (buf) => {
16084
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/encode.js
16085
+ const encodeBase64 = (buf) => {
15850
16086
  let binary = "";
15851
16087
  const bytes = new Uint8Array(buf);
15852
16088
  for (let i = 0, len = bytes.length; i < len; i++) binary += String.fromCharCode(bytes[i]);
15853
16089
  return btoa(binary);
15854
16090
  };
15855
- var decodeBase64 = (str) => {
16091
+ const decodeBase64 = (str) => {
15856
16092
  const binary = atob(str);
15857
16093
  const bytes = new Uint8Array(new ArrayBuffer(binary.length));
15858
16094
  const half = binary.length / 2;
@@ -15863,9 +16099,13 @@ var decodeBase64 = (str) => {
15863
16099
  return bytes;
15864
16100
  };
15865
16101
  //#endregion
15866
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/adapter/lambda-edge/handler.js
16102
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/adapter/lambda-edge/handler.js
15867
16103
  globalThis.crypto ??= node_crypto.default;
15868
- var convertHeaders = (headers) => {
16104
+ /**
16105
+ * Accepts events from 'Lambda@Edge' event
16106
+ * https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html
16107
+ */
16108
+ const convertHeaders = (headers) => {
15869
16109
  const cfHeaders = {};
15870
16110
  headers.forEach((value, key) => {
15871
16111
  cfHeaders[key.toLowerCase()] = [...cfHeaders[key.toLowerCase()] || [], {
@@ -15875,12 +16115,16 @@ var convertHeaders = (headers) => {
15875
16115
  });
15876
16116
  return cfHeaders;
15877
16117
  };
15878
- var handle = (app) => {
16118
+ /**
16119
+ * @deprecated `hono/lambda-edge` will be removed in v5. Install `@hono/lambda-edge` and import from there instead.
16120
+ */
16121
+ const handle = (app) => {
15879
16122
  return async (event, ...args) => {
15880
16123
  const [context, callback] = args;
15881
16124
  let callbackError = null;
15882
16125
  let callbackResult;
15883
- const res = await app.fetch(createRequest(event), {
16126
+ const cf = getCloudFrontRecord(event);
16127
+ const res = await app.fetch(createRequest(cf), {
15884
16128
  event,
15885
16129
  context,
15886
16130
  callback: (err, result) => {
@@ -15890,18 +16134,22 @@ var handle = (app) => {
15890
16134
  }
15891
16135
  callback?.(err, result);
15892
16136
  },
15893
- config: event.Records[0].cf.config,
15894
- request: event.Records[0].cf.request,
15895
- response: event.Records[0].cf.response
16137
+ config: cf.config,
16138
+ request: cf.request,
16139
+ response: cf.response
15896
16140
  });
15897
16141
  if (callbackError) throw callbackError;
15898
16142
  return callbackResult ?? createResult(res);
15899
16143
  };
15900
16144
  };
15901
- var createResult = async (res) => {
16145
+ const createResult = async (res) => {
16146
+ if (res.status === 204) return {
16147
+ status: "204",
16148
+ headers: convertHeaders(res.headers)
16149
+ };
15902
16150
  const contentEncoding = res.headers.get("content-encoding");
15903
16151
  const isBase64Encoded = isContentTypeBinary(res.headers.get("content-type") || "") || !!contentEncoding && !/^identity$/i.test(contentEncoding);
15904
- const body = isBase64Encoded ? encodeBase64(await res.arrayBuffer()) : await res.text();
16152
+ const body = isBase64Encoded ? encodeBase64(await res.arrayBuffer()) : new TextDecoder("utf-8", { ignoreBOM: true }).decode(await res.arrayBuffer());
15905
16153
  return {
15906
16154
  status: res.status.toString(),
15907
16155
  headers: convertHeaders(res.headers),
@@ -15909,16 +16157,30 @@ var createResult = async (res) => {
15909
16157
  ...isBase64Encoded && { bodyEncoding: "base64" }
15910
16158
  };
15911
16159
  };
15912
- var createRequest = (event) => {
15913
- const queryString = event.Records[0].cf.request.querystring;
15914
- const urlPath = `https://${event.Records[0].cf.request.headers?.host?.[0]?.value || event.Records[0].cf.config.distributionDomainName}${event.Records[0].cf.request.uri}`;
16160
+ /**
16161
+ * Reads the CloudFront record out of a Lambda@Edge event.
16162
+ *
16163
+ * The event is supplied by the runtime, so a malformed one means the function
16164
+ * was invoked with something other than a Lambda@Edge event. Fail with a
16165
+ * message naming the adapter and the missing field, rather than letting an
16166
+ * unattributable property access error escape.
16167
+ */
16168
+ const getCloudFrontRecord = (event) => {
16169
+ const cf = event?.Records?.[0]?.cf;
16170
+ if (!cf?.request) throw new TypeError("Unable to map the CloudFront event to a Request: expected `Records[0].cf.request` in the Lambda@Edge event.");
16171
+ return cf;
16172
+ };
16173
+ const createRequest = (cf) => {
16174
+ const request = cf.request;
16175
+ const queryString = request.querystring;
16176
+ const urlPath = `https://${request.headers?.host?.[0]?.value || cf.config?.distributionDomainName}${request.uri}`;
15915
16177
  const url = queryString ? `${urlPath}?${queryString}` : urlPath;
15916
16178
  const headers = new Headers();
15917
- Object.entries(event.Records[0].cf.request.headers).forEach(([k, v]) => {
16179
+ Object.entries(request.headers ?? {}).forEach(([k, v]) => {
15918
16180
  v.forEach((header) => headers.append(k, header.value));
15919
16181
  });
15920
- const requestBody = event.Records[0].cf.request.body;
15921
- const method = event.Records[0].cf.request.method;
16182
+ const requestBody = request.body;
16183
+ const method = request.method;
15922
16184
  const rawBody = createBody(method, requestBody);
15923
16185
  let body = rawBody;
15924
16186
  if (rawBody !== void 0) {
@@ -15932,14 +16194,21 @@ var createRequest = (event) => {
15932
16194
  body
15933
16195
  });
15934
16196
  };
15935
- var createBody = (method, requestBody) => {
16197
+ /**
16198
+ * @deprecated `hono/lambda-edge` will be removed in v5. Install `@hono/lambda-edge` and import from there instead.
16199
+ */
16200
+ const createBody = (method, requestBody) => {
15936
16201
  if (!requestBody || !requestBody.data) return;
15937
16202
  if (method === "GET" || method === "HEAD") return;
15938
16203
  if (requestBody.encoding === "base64") return decodeBase64(requestBody.data);
15939
16204
  return requestBody.data;
15940
16205
  };
15941
- var isContentTypeBinary = (contentType) => {
15942
- return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml.*)$/.test(contentType);
16206
+ /**
16207
+ * @deprecated `hono/lambda-edge` will be removed in v5. Install `@hono/lambda-edge` and import from there instead.
16208
+ */
16209
+ const isContentTypeBinary = (contentType) => {
16210
+ if (/^application\/vnd\.(?:apple\.installer|mozilla\.xul)\+xml\s*(?:;|$)/i.test(contentType)) return true;
16211
+ return !/^text\/(?:plain|html|css|javascript|csv)|(?:\/|\+)(?:json|xml)\s*(?:;|$)/i.test(contentType);
15943
16212
  };
15944
16213
  //#endregion
15945
16214
  //#region src/runtimeAwsConfig.ts