@hot-updater/aws 1.1.20 → 1.1.22

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 +720 -450
  2. package/package.json +9 -9
@@ -4666,7 +4666,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
4666
4666
  };
4667
4667
  //#endregion
4668
4668
  //#region ../../packages/server/dist/version.mjs
4669
- const HOT_UPDATER_SERVER_VERSION = "1.1.20";
4669
+ const HOT_UPDATER_SERVER_VERSION = "1.1.22";
4670
4670
  //#endregion
4671
4671
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
4672
4672
  /**
@@ -7217,7 +7217,8 @@ const createRequestHandler = ({ api, clientPolicy, privateResponses = false, rou
7217
7217
  let authenticated;
7218
7218
  try {
7219
7219
  authenticated = await clientPolicy.authenticate(request);
7220
- } catch {
7220
+ } catch (error) {
7221
+ console.error("Hot Updater client authentication error:", error);
7221
7222
  return errorResponse("Service unavailable", 503);
7222
7223
  }
7223
7224
  if (!authenticated) return errorResponse("Unauthorized", 401);
@@ -11587,48 +11588,72 @@ const remoteConfig = () => {
11587
11588
  return markOfficial(plugin);
11588
11589
  };
11589
11590
  //#endregion
11590
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/compose.js
11591
- var compose = (middleware, onError, onNotFound) => {
11592
- return (context, next) => {
11593
- let index = -1;
11594
- return dispatch(0);
11595
- async function dispatch(i) {
11596
- if (i <= index) throw new Error("next() called multiple times");
11597
- index = i;
11598
- let res;
11599
- let isError = false;
11600
- let handler;
11601
- if (middleware[i]) {
11602
- handler = middleware[i][0][0];
11603
- context.req.routeIndex = i;
11604
- } else handler = i === middleware.length && next || void 0;
11605
- if (handler) try {
11606
- res = await handler(context, () => dispatch(i + 1));
11607
- } catch (err) {
11608
- if (err instanceof Error && onError) {
11609
- context.error = err;
11610
- res = await onError(err, context);
11611
- isError = true;
11612
- } else throw err;
11613
- }
11614
- else if (context.finalized === false && onNotFound) res = await onNotFound(context);
11615
- if (res && (context.finalized === false || isError)) context.res = res;
11616
- return context;
11617
- }
11618
- };
11591
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/http-exception.js
11592
+ /**
11593
+ * `HTTPException` must be used when a fatal error such as authentication failure occurs.
11594
+ *
11595
+ * @see {@link https://hono.dev/docs/api/exception}
11596
+ *
11597
+ * @param {StatusCode} status - status code of HTTPException
11598
+ * @param {HTTPExceptionOptions} options - options of HTTPException
11599
+ * @param {HTTPExceptionOptions["res"]} options.res - response of options of HTTPException
11600
+ * @param {HTTPExceptionOptions["message"]} options.message - message of options of HTTPException
11601
+ * @param {HTTPExceptionOptions["cause"]} options.cause - cause of options of HTTPException
11602
+ *
11603
+ * @example
11604
+ * ```ts
11605
+ * import { HTTPException } from 'hono/http-exception'
11606
+ *
11607
+ * // ...
11608
+ *
11609
+ * app.post('/auth', async (c, next) => {
11610
+ * // authentication
11611
+ * if (authorized === false) {
11612
+ * throw new HTTPException(401, { message: 'Custom error message' })
11613
+ * }
11614
+ * await next()
11615
+ * })
11616
+ * ```
11617
+ */
11618
+ var HTTPException = class extends Error {
11619
+ res;
11620
+ status;
11621
+ /**
11622
+ * Creates an instance of `HTTPException`.
11623
+ * @param status - HTTP status code for the exception. Defaults to 500.
11624
+ * @param options - Additional options for the exception.
11625
+ */
11626
+ constructor(status = 500, options) {
11627
+ super(options?.message, { cause: options?.cause });
11628
+ this.res = options?.res;
11629
+ this.status = status;
11630
+ }
11631
+ /**
11632
+ * Returns the response object associated with the exception.
11633
+ * If a response object is not provided, a new response is created with the error message and status code.
11634
+ * @returns The response object.
11635
+ */
11636
+ getResponse() {
11637
+ if (this.res) return new Response(this.res.body, {
11638
+ status: this.status,
11639
+ headers: this.res.headers
11640
+ });
11641
+ return new Response(this.message, { status: this.status });
11642
+ }
11619
11643
  };
11620
11644
  //#endregion
11621
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/request/constants.js
11622
- var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
11645
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/request/constants.js
11646
+ const GET_MATCH_RESULT = Symbol();
11623
11647
  //#endregion
11624
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/buffer.js
11625
- var bufferToFormData = (arrayBuffer, contentType) => {
11648
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/buffer.js
11649
+ const bufferToFormData = (arrayBuffer, contentType) => {
11626
11650
  return new Response(arrayBuffer, { headers: { "Content-Type": contentType.replace(/^[^;]+/, (mediaType) => mediaType.toLowerCase()) } }).formData();
11627
11651
  };
11628
11652
  //#endregion
11629
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/body.js
11630
- var isRawRequest = (request) => "headers" in request;
11631
- var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
11653
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/body.js
11654
+ const MAX_NESTED_OBJECTS = 1e4;
11655
+ const isRawRequest = (request) => "headers" in request;
11656
+ const parseBody = async (request, options = Object.create(null)) => {
11632
11657
  const { all = false, dot = false } = options;
11633
11658
  const mediaType = (isRawRequest(request) ? request.headers : request.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();
11634
11659
  if (mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded") return parseFormData(request, {
@@ -11637,60 +11662,101 @@ var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) =
11637
11662
  });
11638
11663
  return {};
11639
11664
  };
11665
+ /**
11666
+ * Parses form data from a request.
11667
+ *
11668
+ * @template T - The type of the parsed body data.
11669
+ * @param {HonoRequest | Request} request - The request object containing form data.
11670
+ * @param {ParseBodyOptions} options - Options for parsing the form data.
11671
+ * @returns {Promise<T>} The parsed body data.
11672
+ */
11640
11673
  async function parseFormData(request, options) {
11641
11674
  if (!isRawRequest(request) && request.bodyCache.formData) return convertFormDataToBodyData(await request.bodyCache.formData, options);
11642
11675
  const headers = isRawRequest(request) ? request.headers : request.raw.headers;
11643
- const formDataPromise = bufferToFormData(await request.arrayBuffer(), headers.get("Content-Type") || "");
11676
+ const arrayBuffer = await request.arrayBuffer();
11677
+ const formDataPromise = bufferToFormData(arrayBuffer, headers.get("Content-Type") || "");
11644
11678
  if (!isRawRequest(request)) request.bodyCache.formData = formDataPromise;
11645
11679
  const formData = await formDataPromise;
11646
11680
  if (formData) return convertFormDataToBodyData(formData, options);
11647
11681
  return {};
11648
11682
  }
11683
+ /**
11684
+ * Converts form data to body data based on the provided options.
11685
+ *
11686
+ * @template T - The type of the parsed body data.
11687
+ * @param {FormData} formData - The form data to convert.
11688
+ * @param {ParseBodyOptions} options - Options for parsing the form data.
11689
+ * @returns {T} The converted body data.
11690
+ */
11649
11691
  function convertFormDataToBodyData(formData, options) {
11650
- const form = /* @__PURE__ */ Object.create(null);
11692
+ const form = Object.create(null);
11693
+ const nestingState = { count: 0 };
11651
11694
  formData.forEach((value, key) => {
11652
11695
  if (!(options.all || key.endsWith("[]"))) form[key] = value;
11653
11696
  else handleParsingAllValues(form, key, value);
11654
11697
  });
11655
11698
  if (options.dot) Object.entries(form).forEach(([key, value]) => {
11656
11699
  if (key.includes(".")) {
11657
- handleParsingNestedValues(form, key, value);
11700
+ handleParsingNestedValues(form, key, value, nestingState);
11658
11701
  delete form[key];
11659
11702
  }
11660
11703
  });
11661
11704
  return form;
11662
11705
  }
11663
- var handleParsingAllValues = (form, key, value) => {
11706
+ /**
11707
+ * Handles parsing all values for a given key, supporting multiple values as arrays.
11708
+ *
11709
+ * @param {BodyData} form - The form data object.
11710
+ * @param {string} key - The key to parse.
11711
+ * @param {FormDataEntryValue} value - The value to assign.
11712
+ */
11713
+ const handleParsingAllValues = (form, key, value) => {
11664
11714
  if (form[key] !== void 0) {
11665
11715
  if (Array.isArray(form[key])) form[key].push(value);
11666
11716
  else form[key] = [form[key], value];
11667
11717
  } else if (!key.endsWith("[]")) form[key] = value;
11668
11718
  else form[key] = [value];
11669
11719
  };
11670
- var handleParsingNestedValues = (form, key, value) => {
11720
+ /**
11721
+ * Handles parsing nested values using dot notation keys.
11722
+ *
11723
+ * @param {BodyData} form - The form data object.
11724
+ * @param {string} key - The dot notation key.
11725
+ * @param {BodyDataValue} value - The value to assign.
11726
+ * @param {{ count: number }} state - The state object tracking nesting depth.
11727
+ */
11728
+ const handleParsingNestedValues = (form, key, value, state) => {
11671
11729
  if (/(?:^|\.)__proto__\./.test(key)) return;
11672
11730
  let nestedForm = form;
11673
- const keys = key.split(".");
11674
- keys.forEach((key2, index) => {
11675
- if (index === keys.length - 1) nestedForm[key2] = value;
11731
+ const keys = key.split(".", 34);
11732
+ if (keys.length > 33) throwNestingLimitExceeded();
11733
+ keys.forEach((key, index) => {
11734
+ if (index === keys.length - 1) nestedForm[key] = value;
11676
11735
  else {
11677
- if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) nestedForm[key2] = /* @__PURE__ */ Object.create(null);
11678
- nestedForm = nestedForm[key2];
11736
+ if (!nestedForm[key] || typeof nestedForm[key] !== "object" || Array.isArray(nestedForm[key]) || nestedForm[key] instanceof File) {
11737
+ if (state.count++ >= MAX_NESTED_OBJECTS) throwNestingLimitExceeded();
11738
+ nestedForm[key] = Object.create(null);
11739
+ }
11740
+ nestedForm = nestedForm[key];
11679
11741
  }
11680
11742
  });
11681
11743
  };
11744
+ const throwNestingLimitExceeded = () => {
11745
+ throw new Error("Nesting limit exceeded");
11746
+ };
11682
11747
  //#endregion
11683
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/url.js
11684
- var splitPath = (path) => {
11748
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/url.js
11749
+ const splitPath = (path) => {
11685
11750
  const paths = path.split("/");
11686
11751
  if (paths[0] === "") paths.shift();
11687
11752
  return paths;
11688
11753
  };
11689
- var splitRoutingPath = (routePath) => {
11754
+ const splitRoutingPath = (routePath) => {
11690
11755
  const { groups, path } = extractGroupsFromPath(routePath);
11691
- return replaceGroupMarks(splitPath(path), groups);
11756
+ const paths = splitPath(path);
11757
+ return replaceGroupMarks(paths, groups);
11692
11758
  };
11693
- var extractGroupsFromPath = (path) => {
11759
+ const extractGroupsFromPath = (path) => {
11694
11760
  const groups = [];
11695
11761
  path = path.replace(/\{[^}]+\}/g, (match, index) => {
11696
11762
  const mark = `@${index}`;
@@ -11702,7 +11768,7 @@ var extractGroupsFromPath = (path) => {
11702
11768
  path
11703
11769
  };
11704
11770
  };
11705
- var replaceGroupMarks = (paths, groups) => {
11771
+ const replaceGroupMarks = (paths, groups) => {
11706
11772
  for (let i = groups.length - 1; i >= 0; i--) {
11707
11773
  const [mark] = groups[i];
11708
11774
  for (let j = paths.length - 1; j >= 0; j--) if (paths[j].includes(mark)) {
@@ -11712,8 +11778,8 @@ var replaceGroupMarks = (paths, groups) => {
11712
11778
  }
11713
11779
  return paths;
11714
11780
  };
11715
- var patternCache = {};
11716
- var getPattern = (label, next) => {
11781
+ const patternCache = {};
11782
+ const getPattern = (label, next) => {
11717
11783
  if (label === "*") return "*";
11718
11784
  const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
11719
11785
  if (match) {
@@ -11738,7 +11804,7 @@ var getPattern = (label, next) => {
11738
11804
  }
11739
11805
  return null;
11740
11806
  };
11741
- var tryDecode = (str, decoder) => {
11807
+ const tryDecode = (str, decoder) => {
11742
11808
  try {
11743
11809
  return decoder(str);
11744
11810
  } catch {
@@ -11751,8 +11817,8 @@ var tryDecode = (str, decoder) => {
11751
11817
  });
11752
11818
  }
11753
11819
  };
11754
- var tryDecodeURI = (str) => tryDecode(str, decodeURI);
11755
- var getPath = (request) => {
11820
+ const decodeURIWithPreservedPercent = (value) => decodeURI(value.includes("%25") ? value.replace(/%25/g, "%2525") : value);
11821
+ const getPath = (request) => {
11756
11822
  const url = request.url;
11757
11823
  const start = url.indexOf("/", url.indexOf(":") + 4);
11758
11824
  let i = start;
@@ -11763,20 +11829,36 @@ var getPath = (request) => {
11763
11829
  const hashIndex = url.indexOf("#", i);
11764
11830
  const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
11765
11831
  const path = url.slice(start, end);
11766
- return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
11832
+ const decoded = tryDecode(path, decodeURIWithPreservedPercent);
11833
+ if (/%(?![0-9A-Fa-f]{2})/.test(path)) {
11834
+ const rewritten = new URL("http://localhost");
11835
+ rewritten.pathname = decoded.replace(/[\\\t\n\r]/g, encodeURIComponent);
11836
+ if (tryDecode(rewritten.pathname, decodeURIWithPreservedPercent) !== decoded) return tryDecode(path.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"), decodeURIWithPreservedPercent);
11837
+ }
11838
+ return decoded;
11767
11839
  } else if (charCode === 63 || charCode === 35) break;
11768
11840
  }
11769
11841
  return url.slice(start, i);
11770
11842
  };
11771
- var getPathNoStrict = (request) => {
11843
+ const getPathNoStrict = (request) => {
11772
11844
  const result = getPath(request);
11773
11845
  return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
11774
11846
  };
11775
- var mergePath = (base, sub, ...rest) => {
11847
+ /**
11848
+ * Merge paths.
11849
+ * @param {string[]} ...paths - The paths to merge.
11850
+ * @returns {string} The merged path.
11851
+ * @example
11852
+ * mergePath('/api', '/users') // '/api/users'
11853
+ * mergePath('/api/', '/users') // '/api/users'
11854
+ * mergePath('/api', '/') // '/api'
11855
+ * mergePath('/api/', '/') // '/api/'
11856
+ */
11857
+ const mergePath = (base, sub, ...rest) => {
11776
11858
  if (rest.length) sub = mergePath(sub, ...rest);
11777
11859
  return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
11778
11860
  };
11779
- var checkOptionalParameter = (path) => {
11861
+ const checkOptionalParameter = (path) => {
11780
11862
  if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) return null;
11781
11863
  const segments = path.split("/");
11782
11864
  const results = [];
@@ -11784,10 +11866,10 @@ var checkOptionalParameter = (path) => {
11784
11866
  segments.forEach((segment) => {
11785
11867
  if (segment !== "" && !/\:/.test(segment)) basePath += "/" + segment;
11786
11868
  else if (/\:/.test(segment)) {
11787
- if (/\?/.test(segment)) {
11869
+ if (segment.charCodeAt(segment.length - 1) === 63) {
11788
11870
  if (results.length === 0 && basePath === "") results.push("/");
11789
11871
  else results.push(basePath);
11790
- const optionalSegment = segment.replace("?", "");
11872
+ const optionalSegment = segment.slice(0, -1);
11791
11873
  basePath += "/" + optionalSegment;
11792
11874
  results.push(basePath);
11793
11875
  } else basePath += "/" + segment;
@@ -11795,30 +11877,37 @@ var checkOptionalParameter = (path) => {
11795
11877
  });
11796
11878
  return results.filter((v, i, a) => a.indexOf(v) === i);
11797
11879
  };
11798
- var _decodeURI = (value) => {
11799
- if (!/[%+]/.test(value)) return value;
11880
+ const tryDecodeURIComponent = (str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str;
11881
+ const _decodeURI = (value) => {
11800
11882
  if (value.indexOf("+") !== -1) value = value.replace(/\+/g, " ");
11801
- return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
11883
+ return tryDecodeURIComponent(value);
11802
11884
  };
11803
- var _getQueryParam = (url, key, multiple) => {
11885
+ const _getQueryParam = (url, key, multiple) => {
11886
+ const hashIndex = url.indexOf("#", 8);
11887
+ if (hashIndex !== -1) url = url.slice(0, hashIndex);
11804
11888
  let encoded;
11805
- if (!multiple && key && !/[%+]/.test(key)) {
11806
- let keyIndex2 = url.indexOf("?", 8);
11807
- if (keyIndex2 === -1) return;
11808
- if (!url.startsWith(key, keyIndex2 + 1)) keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
11809
- while (keyIndex2 !== -1) {
11810
- const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
11811
- if (trailingKeyCode === 61) {
11812
- const valueIndex = keyIndex2 + key.length + 2;
11813
- const endIndex = url.indexOf("&", valueIndex);
11814
- return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
11815
- } else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) return "";
11816
- keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
11889
+ if (!multiple && key && !/[%+&=]/.test(key)) {
11890
+ const queryIndex = url.indexOf("?", 8);
11891
+ let keyIndex = queryIndex;
11892
+ if (keyIndex === -1) return;
11893
+ if (!url.startsWith(key, keyIndex + 1)) keyIndex = url.indexOf(`&${key}`, keyIndex + 1);
11894
+ while (keyIndex !== -1) {
11895
+ const trailingKeyCode = url.charCodeAt(keyIndex + key.length + 1);
11896
+ if (trailingKeyCode === 61 || trailingKeyCode === 38 || isNaN(trailingKeyCode)) {
11897
+ if (keyIndex > queryIndex && /(?:^|&)[^=&]*[%+]/.test(url.slice(queryIndex + 1, keyIndex))) break;
11898
+ if (trailingKeyCode === 61) {
11899
+ const valueIndex = keyIndex + key.length + 2;
11900
+ const endIndex = url.indexOf("&", valueIndex);
11901
+ return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
11902
+ }
11903
+ return "";
11904
+ }
11905
+ keyIndex = url.indexOf(`&${key}`, keyIndex + 1);
11817
11906
  }
11818
11907
  encoded = /[%+]/.test(url);
11819
11908
  if (!encoded) return;
11820
11909
  }
11821
- const results = /* @__PURE__ */ Object.create(null);
11910
+ const results = Object.create(null);
11822
11911
  encoded ??= /[%+]/.test(url);
11823
11912
  let keyIndex = url.indexOf("?", 8);
11824
11913
  while (keyIndex !== -1) {
@@ -11842,14 +11931,13 @@ var _getQueryParam = (url, key, multiple) => {
11842
11931
  }
11843
11932
  return key ? results[key] : results;
11844
11933
  };
11845
- var getQueryParam = _getQueryParam;
11846
- var getQueryParams = (url, key) => {
11934
+ const getQueryParam = _getQueryParam;
11935
+ const getQueryParams = (url, key) => {
11847
11936
  return _getQueryParam(url, key, true);
11848
11937
  };
11849
- var decodeURIComponent_ = decodeURIComponent;
11938
+ const decodeURIComponent_ = decodeURIComponent;
11850
11939
  //#endregion
11851
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/request.js
11852
- var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
11940
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/request.js
11853
11941
  var HonoRequest = class {
11854
11942
  /**
11855
11943
  * `.raw` can get the raw Request object.
@@ -11887,22 +11975,21 @@ var HonoRequest = class {
11887
11975
  this.raw = request;
11888
11976
  this.path = path;
11889
11977
  this.#matchResult = matchResult;
11890
- this.#validatedData = {};
11891
11978
  }
11892
11979
  param(key) {
11893
11980
  return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
11894
11981
  }
11895
11982
  #getDecodedParam(key) {
11896
- const paramKey = this.#matchResult[0][this.routeIndex][1][key];
11983
+ const paramKey = this.#matchResult[0][this.routeIndex]?.[1][key];
11897
11984
  const param = this.#getParamValue(paramKey);
11898
- return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
11985
+ return param && tryDecodeURIComponent(param);
11899
11986
  }
11900
11987
  #getAllDecodedParams() {
11901
11988
  const decoded = {};
11902
- const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
11989
+ const keys = Object.keys(this.#matchResult[0][this.routeIndex]?.[1] ?? {});
11903
11990
  for (const key of keys) {
11904
11991
  const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
11905
- if (value !== void 0) decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
11992
+ if (value !== void 0) decoded[key] = tryDecodeURIComponent(value);
11906
11993
  }
11907
11994
  return decoded;
11908
11995
  }
@@ -11917,7 +12004,7 @@ var HonoRequest = class {
11917
12004
  }
11918
12005
  header(name) {
11919
12006
  if (name) return this.raw.headers.get(name) ?? void 0;
11920
- const headerData = /* @__PURE__ */ Object.create(null);
12007
+ const headerData = Object.create(null);
11921
12008
  this.raw.headers.forEach((value, key) => {
11922
12009
  headerData[key] = value;
11923
12010
  });
@@ -11930,10 +12017,10 @@ var HonoRequest = class {
11930
12017
  const { bodyCache, raw } = this;
11931
12018
  const cachedBody = bodyCache[key];
11932
12019
  if (cachedBody) return cachedBody;
11933
- const anyCachedKey = Object.keys(bodyCache)[0];
11934
- if (anyCachedKey) return bodyCache[anyCachedKey].then((body) => {
12020
+ for (const anyCachedKey in bodyCache) return bodyCache[anyCachedKey].then((body) => {
11935
12021
  if (anyCachedKey === "json") body = JSON.stringify(body);
11936
- return new Response(body)[key]();
12022
+ const contentType = anyCachedKey === "formData" ? void 0 : raw.headers.get("content-type");
12023
+ return new Response(body, { headers: contentType ? { "Content-Type": contentType } : void 0 })[key]();
11937
12024
  });
11938
12025
  return bodyCache[key] = raw[key]();
11939
12026
  };
@@ -12030,13 +12117,13 @@ var HonoRequest = class {
12030
12117
  * @param data - The validated data to add.
12031
12118
  */
12032
12119
  addValidatedData(target, data) {
12033
- this.#validatedData[target] = data;
12120
+ (this.#validatedData ??= {})[target] = data;
12034
12121
  }
12035
12122
  valid(target) {
12036
- return this.#validatedData[target];
12123
+ return this.#validatedData?.[target];
12037
12124
  }
12038
12125
  /**
12039
- * `.url()` can get the request url strings.
12126
+ * `.url` can get the request url strings.
12040
12127
  *
12041
12128
  * @see {@link https://hono.dev/docs/api/request#url}
12042
12129
  *
@@ -12052,7 +12139,7 @@ var HonoRequest = class {
12052
12139
  return this.raw.url;
12053
12140
  }
12054
12141
  /**
12055
- * `.method()` can get the method name of the request.
12142
+ * `.method` can get the method name of the request.
12056
12143
  *
12057
12144
  * @see {@link https://hono.dev/docs/api/request#method}
12058
12145
  *
@@ -12070,7 +12157,7 @@ var HonoRequest = class {
12070
12157
  return this.#matchResult;
12071
12158
  }
12072
12159
  /**
12073
- * `.matchedRoutes()` can return a matched route in the handler
12160
+ * `.matchedRoutes` can return a matched route in the handler
12074
12161
  *
12075
12162
  * @deprecated
12076
12163
  *
@@ -12100,7 +12187,7 @@ var HonoRequest = class {
12100
12187
  return this.#matchResult[0].map(([[, route]]) => route);
12101
12188
  }
12102
12189
  /**
12103
- * `routePath()` can retrieve the path registered within the handler
12190
+ * `.routePath` can retrieve the path registered within the handler
12104
12191
  *
12105
12192
  * @deprecated
12106
12193
  *
@@ -12120,19 +12207,23 @@ var HonoRequest = class {
12120
12207
  }
12121
12208
  };
12122
12209
  //#endregion
12123
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/html.js
12124
- var HtmlEscapedCallbackPhase = {
12210
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/html.js
12211
+ /**
12212
+ * @module
12213
+ * HTML utility.
12214
+ */
12215
+ const HtmlEscapedCallbackPhase = {
12125
12216
  Stringify: 1,
12126
12217
  BeforeStream: 2,
12127
12218
  Stream: 3
12128
12219
  };
12129
- var raw = (value, callbacks) => {
12220
+ const raw = (value, callbacks) => {
12130
12221
  const escapedString = new String(value);
12131
12222
  escapedString.isEscaped = true;
12132
12223
  escapedString.callbacks = callbacks;
12133
12224
  return escapedString;
12134
12225
  };
12135
- var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
12226
+ const resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
12136
12227
  if (typeof str === "object" && !(str instanceof String)) {
12137
12228
  if (!(str instanceof Promise)) str = str.toString();
12138
12229
  if (str instanceof Promise) str = await str;
@@ -12145,20 +12236,20 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
12145
12236
  phase,
12146
12237
  buffer,
12147
12238
  context
12148
- }))).then((res) => Promise.all(res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))).then(() => buffer[0]));
12239
+ }))).then((res) => Promise.all(res.filter(Boolean).map((str) => resolveCallback(str, phase, false, context, buffer))).then(() => buffer[0]));
12149
12240
  if (preserveCallbacks) return raw(await resStr, callbacks);
12150
12241
  else return resStr;
12151
12242
  };
12152
12243
  //#endregion
12153
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/context.js
12154
- var TEXT_PLAIN = "text/plain; charset=UTF-8";
12155
- var setDefaultContentType = (contentType, headers) => {
12244
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/context.js
12245
+ const TEXT_PLAIN = "text/plain; charset=UTF-8";
12246
+ const setDefaultContentType = (contentType, headers) => {
12156
12247
  return {
12157
12248
  "Content-Type": contentType,
12158
12249
  ...headers
12159
12250
  };
12160
12251
  };
12161
- var createResponseInstance = (body, init) => new Response(body, init);
12252
+ const createResponseInstance = (body, init) => new Response(body, init);
12162
12253
  var Context = class {
12163
12254
  #rawRequest;
12164
12255
  #req;
@@ -12338,12 +12429,16 @@ var Context = class {
12338
12429
  * c.header('X-Message', 'Hello!')
12339
12430
  * c.header('Content-Type', 'text/plain')
12340
12431
  *
12432
+ * // Append multiple headers using the append option (e.g. Vary)
12433
+ * c.header('Vary', 'Accept-Encoding', { append: true })
12434
+ * c.header('Vary', 'User-Agent', { append: true })
12435
+ *
12341
12436
  * return c.body('Thank you for coming')
12342
12437
  * })
12343
12438
  * ```
12344
12439
  */
12345
12440
  header = (name, value, options) => {
12346
- if (this.finalized) this.#res = createResponseInstance(this.#res.body, this.#res);
12441
+ if (this.finalized && !this.#res.bodyUsed) this.#res = createResponseInstance(this.#res.body, this.#res);
12347
12442
  const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
12348
12443
  if (value === void 0) headers.delete(name);
12349
12444
  else if (options?.append) headers.append(name, value);
@@ -12400,20 +12495,33 @@ var Context = class {
12400
12495
  return Object.fromEntries(this.#var);
12401
12496
  }
12402
12497
  #newResponse(data, arg, headers) {
12403
- const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
12404
- if (typeof arg === "object" && "headers" in arg) {
12405
- const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
12406
- for (const [key, value] of argHeaders) if (key.toLowerCase() === "set-cookie") responseHeaders.append(key, value);
12498
+ let responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders;
12499
+ if (typeof arg === "object" && arg.headers) {
12500
+ responseHeaders ??= new Headers();
12501
+ for (const [key, value] of new Headers(arg.headers)) if (key === "set-cookie") responseHeaders.append(key, value);
12407
12502
  else responseHeaders.set(key, value);
12408
12503
  }
12409
- if (headers) for (const [k, v] of Object.entries(headers)) if (typeof v === "string") responseHeaders.set(k, v);
12410
- else {
12411
- responseHeaders.delete(k);
12412
- for (const v2 of v) responseHeaders.append(k, v2);
12504
+ if (headers) {
12505
+ if (!responseHeaders) {
12506
+ let count = 0;
12507
+ for (const k in headers) if (++count > 1 || typeof headers[k] !== "string") {
12508
+ responseHeaders = new Headers();
12509
+ break;
12510
+ }
12511
+ }
12512
+ if (responseHeaders) for (const k in headers) {
12513
+ const v = headers[k];
12514
+ if (typeof v === "string") responseHeaders.set(k, v);
12515
+ else {
12516
+ responseHeaders.delete(k);
12517
+ for (const v2 of v) responseHeaders.append(k, v2);
12518
+ }
12519
+ }
12413
12520
  }
12521
+ const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
12414
12522
  return createResponseInstance(data, {
12415
- status: typeof arg === "number" ? arg : arg?.status ?? this.#status,
12416
- headers: responseHeaders
12523
+ status,
12524
+ headers: responseHeaders ?? headers
12417
12525
  });
12418
12526
  }
12419
12527
  newResponse = (...args) => this.#newResponse(...args);
@@ -12470,7 +12578,7 @@ var Context = class {
12470
12578
  return this.#newResponse(JSON.stringify(object), arg, setDefaultContentType("application/json", headers));
12471
12579
  };
12472
12580
  html = (html, arg, headers) => {
12473
- const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
12581
+ const res = (html) => this.#newResponse(html, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
12474
12582
  return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
12475
12583
  };
12476
12584
  /**
@@ -12511,26 +12619,190 @@ var Context = class {
12511
12619
  };
12512
12620
  };
12513
12621
  //#endregion
12514
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router.js
12515
- var METHODS = [
12622
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/compose.js
12623
+ /**
12624
+ * Compose middleware functions into a single function based on `koa-compose` package.
12625
+ *
12626
+ * @template E - The environment type.
12627
+ *
12628
+ * @param {[[Function, unknown], unknown][] | [[Function]][]} middleware - An array of middleware functions and their corresponding parameters.
12629
+ * @param {ErrorHandler<E>} [onError] - An optional error handler function.
12630
+ * @param {NotFoundHandler<E>} [onNotFound] - An optional not-found handler function.
12631
+ *
12632
+ * @returns {(context: Context, next?: Next) => Promise<Context>} - A composed middleware function.
12633
+ */
12634
+ const compose = (middleware, onError, onNotFound) => {
12635
+ return (context, next) => {
12636
+ let index = -1;
12637
+ return dispatch(0);
12638
+ /**
12639
+ * Dispatch the middleware functions.
12640
+ *
12641
+ * @param {number} i - The current index in the middleware array.
12642
+ *
12643
+ * @returns {Promise<Context>} - A promise that resolves to the context.
12644
+ */
12645
+ async function dispatch(i) {
12646
+ if (i <= index) throw new Error("next() called multiple times");
12647
+ index = i;
12648
+ let res;
12649
+ let isError = false;
12650
+ let handler;
12651
+ if (middleware[i]) {
12652
+ handler = middleware[i][0][0];
12653
+ context.req.routeIndex = i;
12654
+ } else handler = i === middleware.length && next || void 0;
12655
+ if (handler) try {
12656
+ res = await handler(context, () => dispatch(i + 1));
12657
+ } catch (err) {
12658
+ if (err instanceof Error && onError) {
12659
+ context.error = err;
12660
+ res = await onError(err, context);
12661
+ isError = true;
12662
+ } else throw err;
12663
+ }
12664
+ else if (context.finalized === false && onNotFound) res = await onNotFound(context);
12665
+ if (res && (context.finalized === false || isError)) context.res = res;
12666
+ return context;
12667
+ }
12668
+ };
12669
+ };
12670
+ //#endregion
12671
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/helper/route/index.js
12672
+ /**
12673
+ * Get matched routes in the handler
12674
+ *
12675
+ * @param {Context} c - The context object
12676
+ * @returns An array of matched routes
12677
+ *
12678
+ * @example
12679
+ * ```ts
12680
+ * import { matchedRoutes } from 'hono/route'
12681
+ *
12682
+ * app.use('*', async function logger(c, next) {
12683
+ * await next()
12684
+ * matchedRoutes(c).forEach(({ handler, method, path }, i) => {
12685
+ * const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
12686
+ * console.log(
12687
+ * method,
12688
+ * ' ',
12689
+ * path,
12690
+ * ' '.repeat(Math.max(10 - path.length, 0)),
12691
+ * name,
12692
+ * i === c.req.routeIndex ? '<- respond from here' : ''
12693
+ * )
12694
+ * })
12695
+ * })
12696
+ * ```
12697
+ */
12698
+ const matchedRoutes = (c) => c.req[GET_MATCH_RESULT][0].map(([[, route]]) => route);
12699
+ /**
12700
+ * Get the route path registered within the handler
12701
+ *
12702
+ * @param {Context} c - The context object
12703
+ * @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.
12704
+ * @returns The route path registered within the handler
12705
+ *
12706
+ * @example
12707
+ * ```ts
12708
+ * import { routePath } from 'hono/route'
12709
+ *
12710
+ * app.use('*', (c, next) => {
12711
+ * console.log(routePath(c)) // '*'
12712
+ * console.log(routePath(c, -1)) // '/posts/:id'
12713
+ * return next()
12714
+ * })
12715
+ *
12716
+ * app.get('/posts/:id', (c) => {
12717
+ * return c.text(routePath(c)) // '/posts/:id'
12718
+ * })
12719
+ * ```
12720
+ */
12721
+ const routePath = (c, index) => matchedRoutes(c).at(index ?? c.req.routeIndex)?.path ?? "";
12722
+ //#endregion
12723
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router.js
12724
+ /**
12725
+ * Array of supported HTTP methods.
12726
+ */
12727
+ const METHODS = [
12516
12728
  "get",
12517
12729
  "post",
12518
12730
  "put",
12519
12731
  "delete",
12520
12732
  "options",
12521
- "patch"
12733
+ "patch",
12734
+ "query"
12522
12735
  ];
12523
- var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
12736
+ /**
12737
+ * Error message indicating that a route cannot be added because the matcher is already built.
12738
+ */
12739
+ const MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
12740
+ /**
12741
+ * Error class representing an unsupported path error.
12742
+ */
12524
12743
  var UnsupportedPathError = class extends Error {};
12525
12744
  //#endregion
12526
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/constants.js
12527
- var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
12745
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/constants.js
12746
+ /**
12747
+ * Constant used to mark a composed handler.
12748
+ */
12749
+ const COMPOSED_HANDLER = "__COMPOSED_HANDLER";
12528
12750
  //#endregion
12529
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/hono-base.js
12530
- var notFoundHandler = (c) => {
12751
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/mount.js
12752
+ const countTrailingSlashes = (path) => {
12753
+ let index = path.length;
12754
+ while (index > 0 && path.charCodeAt(index - 1) === 47) index--;
12755
+ return path.length - index;
12756
+ };
12757
+ const getPathPrefixLength = (c, pathPrefix, routePath) => {
12758
+ if (!/[:*]/.test(pathPrefix)) return pathPrefix.length;
12759
+ const path = c.req.path;
12760
+ const matchResult = c.req[GET_MATCH_RESULT];
12761
+ const paramNames = /* @__PURE__ */ new Set();
12762
+ let length = 0;
12763
+ for (const part of splitRoutingPath(pathPrefix)) {
12764
+ if (part[0] === ":" && part.endsWith("}?")) throw new Error(`mount(): Optional regular expression parameters are not supported in "${routePath}".`);
12765
+ const pattern = getPattern(part);
12766
+ if (pattern && pattern !== "*") {
12767
+ const name = pattern[1];
12768
+ if (paramNames.has(name)) throw new Error(`mount(): Duplicate path parameter "${name}" in "${routePath}".`);
12769
+ paramNames.add(name);
12770
+ }
12771
+ if (pattern && pattern !== "*" && pattern[2] !== true) {
12772
+ const value = matchResult.length === 2 ? matchResult[1][matchResult[0][c.req.routeIndex][1][pattern[1]]] : matchResult[0][c.req.routeIndex][1][pattern[1]];
12773
+ length += value.length + 1;
12774
+ } else if (pattern || part.endsWith("*")) {
12775
+ const end = path.indexOf("/", length + 1);
12776
+ length = end === -1 ? path.length : end;
12777
+ } else length += part.length + 1;
12778
+ }
12779
+ return length;
12780
+ };
12781
+ const createMountedRequest = (c, pathPrefix, routePath) => {
12782
+ if (/[^/]\*$/.test(routePath)) throw new Error(`mount(): Wildcard must follow "/" in "${routePath}".`);
12783
+ const prefixLength = getPathPrefixLength(c, pathPrefix, routePath);
12784
+ const path = c.req.path.slice(prefixLength) || "/";
12785
+ if (prefixLength > c.req.path.length || path[0] !== "/" || /\/(?:\.|%2e){1,2}(?:\/|$)/i.test(path)) throw new HTTPException(400, { message: "Invalid mounted path" });
12786
+ const rawUrl = c.req.raw.url;
12787
+ if (/^[^/?#]*\/\/[^/?#\\]*[?#\\]/.test(rawUrl)) throw new HTTPException(400, { message: "Invalid mounted path" });
12788
+ const rawPathEnd = rawUrl.search(/[?#]/);
12789
+ const rawTrailingSlashes = countTrailingSlashes(rawPathEnd === -1 ? rawUrl : rawUrl.slice(0, rawPathEnd));
12790
+ if (rawTrailingSlashes > 1 && countTrailingSlashes(c.req.path) === rawTrailingSlashes - 1) throw new HTTPException(400, { message: "Invalid mounted path" });
12791
+ const url = new URL(rawUrl);
12792
+ url.pathname = path.replace(/[\\\t\n\r]/g, encodeURIComponent);
12793
+ if (path.includes("%")) {}
12794
+ return new Request(url, c.req.raw);
12795
+ };
12796
+ //#endregion
12797
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/hono-base.js
12798
+ /**
12799
+ * @module
12800
+ * This module is the base module for the Hono object.
12801
+ */
12802
+ const notFoundHandler = (c) => {
12531
12803
  return c.text("404 Not Found", 404);
12532
12804
  };
12533
- var errorHandler = (err, c) => {
12805
+ const errorHandler = (err, c) => {
12534
12806
  if ("getResponse" in err) {
12535
12807
  const res = err.getResponse();
12536
12808
  return c.newResponse(res.body, res);
@@ -12538,13 +12810,14 @@ var errorHandler = (err, c) => {
12538
12810
  console.error(err);
12539
12811
  return c.text("Internal Server Error", 500);
12540
12812
  };
12541
- var Hono$1 = class _Hono {
12813
+ var Hono$1 = class Hono {
12542
12814
  get;
12543
12815
  post;
12544
12816
  put;
12545
12817
  delete;
12546
12818
  options;
12547
12819
  patch;
12820
+ query;
12548
12821
  all;
12549
12822
  on;
12550
12823
  use;
@@ -12556,10 +12829,11 @@ var Hono$1 = class _Hono {
12556
12829
  constructor(options = {}) {
12557
12830
  [...METHODS, "all"].forEach((method) => {
12558
12831
  this[method] = (args1, ...args) => {
12832
+ const methodName = method.toUpperCase();
12559
12833
  if (typeof args1 === "string") this.#path = args1;
12560
- else this.#addRoute(method, this.#path, args1);
12834
+ else this.#addRoute(methodName, this.#path, args1);
12561
12835
  args.forEach((handler) => {
12562
- this.#addRoute(method, this.#path, handler);
12836
+ this.#addRoute(methodName, this.#path, handler);
12563
12837
  });
12564
12838
  return this;
12565
12839
  };
@@ -12567,9 +12841,10 @@ var Hono$1 = class _Hono {
12567
12841
  this.on = (method, path, ...handlers) => {
12568
12842
  for (const p of [path].flat()) {
12569
12843
  this.#path = p;
12570
- for (const m of [method].flat()) handlers.map((handler) => {
12571
- this.#addRoute(m.toUpperCase(), this.#path, handler);
12572
- });
12844
+ for (const m of [method].flat()) {
12845
+ const methodName = m.toUpperCase();
12846
+ for (const handler of handlers) this.#addRoute(methodName, this.#path, handler);
12847
+ }
12573
12848
  }
12574
12849
  return this;
12575
12850
  };
@@ -12589,7 +12864,7 @@ var Hono$1 = class _Hono {
12589
12864
  this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
12590
12865
  }
12591
12866
  #clone() {
12592
- const clone = new _Hono({
12867
+ const clone = new Hono({
12593
12868
  router: this.router,
12594
12869
  getPath: this.getPath
12595
12870
  });
@@ -12691,12 +12966,16 @@ var Hono$1 = class _Hono {
12691
12966
  /**
12692
12967
  * `.mount()` allows you to mount applications built with other frameworks into your Hono application.
12693
12968
  *
12969
+ * @deprecated Use `mount()` from `hono/mount` instead. `.mount()` will be removed in v5.
12970
+ *
12694
12971
  * @see {@link https://hono.dev/docs/api/hono#mount}
12695
12972
  *
12696
12973
  * @param {string} path - base Path
12697
12974
  * @param {Function} applicationHandler - other Request Handler
12698
12975
  * @param {MountOptions} [options] - options of `.mount()`
12699
12976
  * @returns {Hono} mounted Hono instance
12977
+ * @throws {Error} If automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
12978
+ * @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
12700
12979
  *
12701
12980
  * @example
12702
12981
  * ```ts
@@ -12732,8 +13011,8 @@ var Hono$1 = class _Hono {
12732
13011
  }
12733
13012
  }
12734
13013
  const getOptions = optionHandler ? (c) => {
12735
- const options2 = optionHandler(c);
12736
- return Array.isArray(options2) ? options2 : [options2];
13014
+ const options = optionHandler(c);
13015
+ return Array.isArray(options) ? options : [options];
12737
13016
  } : (c) => {
12738
13017
  let executionContext = void 0;
12739
13018
  try {
@@ -12741,17 +13020,12 @@ var Hono$1 = class _Hono {
12741
13020
  } catch {}
12742
13021
  return [c.env, executionContext];
12743
13022
  };
12744
- replaceRequest ||= (() => {
12745
- const mergedPath = mergePath(this._basePath, path);
12746
- const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
12747
- return (request) => {
12748
- const url = new URL(request.url);
12749
- url.pathname = this.getPath(request).slice(pathPrefixLength) || "/";
12750
- return new Request(url, request);
12751
- };
12752
- })();
13023
+ const defaultReplaceRequest = (c) => {
13024
+ const mountedRoutePath = routePath(c);
13025
+ return createMountedRequest(c, mountedRoutePath.replace(/\/?\*$/, ""), mountedRoutePath);
13026
+ };
12753
13027
  const handler = async (c, next) => {
12754
- const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
13028
+ const res = await applicationHandler(replaceRequest ? replaceRequest(c.req.raw) : defaultReplaceRequest(c), ...getOptions(c));
12755
13029
  if (res) return res;
12756
13030
  await next();
12757
13031
  };
@@ -12759,7 +13033,6 @@ var Hono$1 = class _Hono {
12759
13033
  return this;
12760
13034
  }
12761
13035
  #addRoute(method, path, handler, baseRoutePath) {
12762
- method = method.toUpperCase();
12763
13036
  path = mergePath(this._basePath, path);
12764
13037
  const r = {
12765
13038
  basePath: baseRoutePath !== void 0 ? mergePath(this._basePath, baseRoutePath) : this._basePath,
@@ -12813,8 +13086,8 @@ var Hono$1 = class _Hono {
12813
13086
  * @see {@link https://hono.dev/docs/api/hono#fetch}
12814
13087
  *
12815
13088
  * @param {Request} request - request Object of request
12816
- * @param {Env} Env - env Object
12817
- * @param {ExecutionContext} - context of execution
13089
+ * @param {Env} env - env Object
13090
+ * @param {ExecutionContext} executionCtx - context of execution
12818
13091
  * @returns {Response | Promise<Response>} response of request
12819
13092
  *
12820
13093
  */
@@ -12862,112 +13135,140 @@ var Hono$1 = class _Hono {
12862
13135
  };
12863
13136
  };
12864
13137
  //#endregion
12865
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/matcher.js
12866
- var emptyParam = [];
13138
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/utils.js
13139
+ const createNullObject = () => Object.create(null);
13140
+ //#endregion
13141
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/reg-exp-router/matcher.js
13142
+ const emptyParam = [];
12867
13143
  function match(method, path) {
12868
13144
  const matchers = this.buildAllMatchers();
12869
- const match2 = ((method2, path2) => {
12870
- const matcher = matchers[method2] || matchers["ALL"];
12871
- const staticMatch = matcher[2][path2];
13145
+ const match = ((method, path) => {
13146
+ const matcher = matchers[method] || matchers["ALL"];
13147
+ const staticMatch = matcher[2][path];
12872
13148
  if (staticMatch) return staticMatch;
12873
- const match3 = path2.match(matcher[0]);
12874
- if (!match3) return [[], emptyParam];
12875
- const index = match3.indexOf("", 1);
12876
- return [matcher[1][index], match3];
13149
+ const match = path.match(matcher[0]);
13150
+ if (!match) return [[], emptyParam];
13151
+ const index = match.indexOf("", 1);
13152
+ return [matcher[1][index], match];
12877
13153
  });
12878
- this.match = match2;
12879
- return match2(method, path);
13154
+ this.match = match;
13155
+ return match(method, path);
12880
13156
  }
12881
13157
  //#endregion
12882
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/node.js
12883
- var LABEL_REG_EXP_STR = "[^/]+";
12884
- var ONLY_WILDCARD_REG_EXP_STR = ".*";
12885
- var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
12886
- var PATH_ERROR = /* @__PURE__ */ Symbol();
12887
- var regExpMetaChars = /* @__PURE__ */ new Set(".\\+*[^]$()");
13158
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/reg-exp-router/node.js
13159
+ const LABEL_REG_EXP_STR = "[^/]+";
13160
+ const ONLY_WILDCARD_REG_EXP_STR = "[^]*";
13161
+ const TAIL_WILDCARD_REG_EXP_STR = "(?:|/[^]*)";
13162
+ const PATH_ERROR = Symbol();
13163
+ const regExpMetaChars = /* @__PURE__ */ new Set(".\\+*[^]$()");
13164
+ /**
13165
+ * Sort order:
13166
+ * 1. literal
13167
+ * 2. special pattern (e.g. :label{[0-9]+})
13168
+ * 3. common label pattern (e.g. :label)
13169
+ * 4. wildcard
13170
+ */
12888
13171
  function compareKey(a, b) {
12889
13172
  if (a.length === 1) return b.length === 1 ? a < b ? -1 : 1 : -1;
12890
13173
  if (b.length === 1) return 1;
12891
- if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) return 1;
12892
- else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) return -1;
12893
- if (a === LABEL_REG_EXP_STR) return 1;
12894
- else if (b === LABEL_REG_EXP_STR) return -1;
13174
+ if (a === "[^]*" || a === "(?:|/[^]*)") return b === "[^]*" ? -1 : 1;
13175
+ else if (b === "[^]*" || b === "(?:|/[^]*)") return -1;
13176
+ if (a === "[^/]+") return 1;
13177
+ else if (b === "[^/]+") return -1;
12895
13178
  return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
12896
13179
  }
12897
- var Node$1 = class _Node {
13180
+ var Node$1 = class Node {
12898
13181
  #index;
12899
13182
  #varIndex;
12900
- #children = /* @__PURE__ */ Object.create(null);
12901
- insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
12902
- if (tokens.length === 0) {
12903
- if (this.#index !== void 0) throw PATH_ERROR;
12904
- if (pathErrorCheckOnly) return;
12905
- this.#index = index;
12906
- return;
12907
- }
12908
- const [token, ...restTokens] = tokens;
12909
- const pattern = token === "*" ? restTokens.length === 0 ? [
12910
- "",
12911
- "",
12912
- ONLY_WILDCARD_REG_EXP_STR
12913
- ] : [
12914
- "",
12915
- "",
12916
- LABEL_REG_EXP_STR
12917
- ] : token === "/*" ? [
12918
- "",
12919
- "",
12920
- TAIL_WILDCARD_REG_EXP_STR
12921
- ] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
12922
- let node;
12923
- if (pattern) {
12924
- const name = pattern[1];
12925
- let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
12926
- if (name && pattern[2]) {
12927
- if (regexpStr === ".*") throw PATH_ERROR;
12928
- regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
12929
- if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
12930
- }
12931
- node = this.#children[regexpStr];
12932
- if (!node) {
12933
- if (Object.keys(this.#children).some((k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) throw PATH_ERROR;
12934
- if (pathErrorCheckOnly) return;
12935
- node = this.#children[regexpStr] = new _Node();
12936
- if (name !== "") node.#varIndex = context.varIndex++;
12937
- }
12938
- if (!pathErrorCheckOnly && name !== "") paramMap.push([name, node.#varIndex]);
12939
- } else {
12940
- node = this.#children[token];
12941
- if (!node) {
12942
- 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;
12943
- if (pathErrorCheckOnly) return;
12944
- node = this.#children[token] = new _Node();
13183
+ #children = createNullObject();
13184
+ insert(tokens, index, paramMap, context, keys) {
13185
+ let node = this;
13186
+ for (let i = 0, len = tokens.length; i < len; i++) {
13187
+ const token = tokens[i];
13188
+ const pattern = token.length === 1 ? token === "*" ? i === len - 1 ? [
13189
+ "",
13190
+ "",
13191
+ ONLY_WILDCARD_REG_EXP_STR
13192
+ ] : [
13193
+ "",
13194
+ "",
13195
+ LABEL_REG_EXP_STR
13196
+ ] : null : token === "/*" ? [
13197
+ "",
13198
+ "",
13199
+ TAIL_WILDCARD_REG_EXP_STR
13200
+ ] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
13201
+ let nextNode;
13202
+ if (pattern) {
13203
+ const name = pattern[1];
13204
+ let regexpStr = pattern[2] || "[^/]+";
13205
+ if (name && pattern[2]) {
13206
+ if (new RegExp(regexpStr).test("")) throw PATH_ERROR;
13207
+ regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
13208
+ if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
13209
+ if (regexpStr.length === 1 && regExpMetaChars.has(regexpStr)) throw PATH_ERROR;
13210
+ }
13211
+ keys.push(regexpStr);
13212
+ nextNode = node.#children[regexpStr];
13213
+ if (!nextNode) {
13214
+ if (regexpStr !== "[^]*" && regexpStr !== "(?:|/[^]*)") {
13215
+ for (const k in node.#children) if ((regexpStr.length > 1 || k.length > 1) && k !== "[^]*" && k !== "(?:|/[^]*)") throw PATH_ERROR;
13216
+ }
13217
+ nextNode = node.#children[regexpStr] = new Node();
13218
+ }
13219
+ if (name !== "") {
13220
+ nextNode.#varIndex ??= context.varIndex++;
13221
+ paramMap.push([name, nextNode.#varIndex]);
13222
+ }
13223
+ } else {
13224
+ keys.push(token);
13225
+ nextNode = node.#children[token];
13226
+ if (!nextNode) {
13227
+ for (const k in node.#children) if (k.length > 1 && k !== "[^]*" && k !== "(?:|/[^]*)") throw PATH_ERROR;
13228
+ nextNode = node.#children[token] = new Node();
13229
+ }
12945
13230
  }
13231
+ node = nextNode;
12946
13232
  }
12947
- node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
13233
+ if (node.#index !== void 0) throw PATH_ERROR;
13234
+ node.#index = index;
12948
13235
  }
12949
13236
  buildRegExpStr() {
12950
13237
  const strList = Object.keys(this.#children).sort(compareKey).map((k) => {
12951
13238
  const c = this.#children[k];
12952
- return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
12953
- });
12954
- if (typeof this.#index === "number") strList.unshift(`#${this.#index}`);
13239
+ const childStr = c.buildRegExpStr();
13240
+ return childStr === "" ? "" : (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + childStr;
13241
+ }).filter(Boolean);
13242
+ if (typeof this.#index === "number" && this.#index !== -1) strList.unshift(`#${this.#index}`);
12955
13243
  if (strList.length === 0) return "";
12956
13244
  if (strList.length === 1) return strList[0];
12957
13245
  return "(?:" + strList.join("|") + ")";
12958
13246
  }
12959
13247
  };
12960
13248
  //#endregion
12961
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/trie.js
13249
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/reg-exp-router/trie.js
12962
13250
  var Trie = class {
12963
13251
  #context = { varIndex: 0 };
12964
13252
  #root = new Node$1();
12965
- insert(path, index, pathErrorCheckOnly) {
13253
+ #index = 0;
13254
+ paths = createNullObject();
13255
+ insert(path, isStatic) {
13256
+ const keys = [];
13257
+ if (isStatic) {
13258
+ this.#root.insert(path.split(""), -1, [], this.#context, keys);
13259
+ this.paths[path] = [
13260
+ -1,
13261
+ [],
13262
+ keys
13263
+ ];
13264
+ return;
13265
+ }
12966
13266
  const paramAssoc = [];
12967
13267
  const groups = [];
13268
+ let markedPath = path;
12968
13269
  for (let i = 0;;) {
12969
13270
  let replaced = false;
12970
- path = path.replace(/\{[^}]+\}/g, (m) => {
13271
+ markedPath = markedPath.replace(/\{(?:\{[\d,]+\}|[^}])+\}/g, (m) => {
12971
13272
  const mark = `@\\${i}`;
12972
13273
  groups[i] = [mark, m];
12973
13274
  i++;
@@ -12976,7 +13277,12 @@ var Trie = class {
12976
13277
  });
12977
13278
  if (!replaced) break;
12978
13279
  }
12979
- const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
13280
+ /**
13281
+ * - pattern (:label, :label{0-9]+}, ...)
13282
+ * - /* wildcard
13283
+ * - character
13284
+ */
13285
+ const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./gs) || [];
12980
13286
  for (let i = groups.length - 1; i >= 0; i--) {
12981
13287
  const [mark] = groups[i];
12982
13288
  for (let j = tokens.length - 1; j >= 0; j--) if (tokens[j].indexOf(mark) !== -1) {
@@ -12984,8 +13290,12 @@ var Trie = class {
12984
13290
  break;
12985
13291
  }
12986
13292
  }
12987
- this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
12988
- return paramAssoc;
13293
+ this.#root.insert(tokens, this.#index, paramAssoc, this.#context, keys);
13294
+ this.paths[path] = [
13295
+ this.#index++,
13296
+ paramAssoc,
13297
+ keys
13298
+ ];
12989
13299
  }
12990
13300
  buildRegExp() {
12991
13301
  let regexp = this.#root.buildRegExpStr();
@@ -13016,138 +13326,89 @@ var Trie = class {
13016
13326
  }
13017
13327
  };
13018
13328
  //#endregion
13019
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/router.js
13020
- var nullMatcher = [
13021
- /^$/,
13022
- [],
13023
- /* @__PURE__ */ Object.create(null)
13024
- ];
13025
- var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
13026
- function buildWildcardRegExp(path) {
13027
- return wildcardRegExpCache[path] ??= new RegExp(path === "*" ? "" : `^${path.replace(/\/\*$|([.\\+*[^\]$()])/g, (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)")}$`);
13028
- }
13029
- function clearWildcardRegExpCache() {
13030
- wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
13031
- }
13032
- function buildMatcherFromPreprocessedRoutes(routes) {
13033
- const trie = new Trie();
13034
- const handlerData = [];
13035
- if (routes.length === 0) return nullMatcher;
13036
- const routesWithStaticPathFlag = routes.map((route) => [!/\*|\/:/.test(route[0]), ...route]).sort(([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length);
13037
- const staticMap = /* @__PURE__ */ Object.create(null);
13038
- for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
13039
- const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
13040
- if (pathErrorCheckOnly) staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
13041
- else j++;
13042
- let paramAssoc;
13043
- try {
13044
- paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
13045
- } catch (e) {
13046
- throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
13047
- }
13048
- if (pathErrorCheckOnly) continue;
13049
- handlerData[j] = handlers.map(([h, paramCount]) => {
13050
- const paramIndexMap = /* @__PURE__ */ Object.create(null);
13051
- paramCount -= 1;
13052
- for (; paramCount >= 0; paramCount--) {
13053
- const [key, value] = paramAssoc[paramCount];
13054
- paramIndexMap[key] = value;
13055
- }
13056
- return [h, paramIndexMap];
13057
- });
13058
- }
13059
- const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
13060
- for (let i = 0, len = handlerData.length; i < len; i++) for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
13061
- const map = handlerData[i][j]?.[1];
13062
- if (!map) continue;
13063
- const keys = Object.keys(map);
13064
- for (let k = 0, len3 = keys.length; k < len3; k++) map[keys[k]] = paramReplacementMap[map[keys[k]]];
13065
- }
13066
- const handlerMap = [];
13067
- for (const i in indexReplacementMap) handlerMap[i] = handlerData[indexReplacementMap[i]];
13068
- return [
13069
- regexp,
13070
- handlerMap,
13071
- staticMap
13072
- ];
13329
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/reg-exp-router/router.js
13330
+ function endsWithWildcard(keys) {
13331
+ const tail = keys[keys.length - 1];
13332
+ return tail === "[^]*" || tail === "(?:|/[^]*)";
13073
13333
  }
13074
- function findMiddleware(middleware, path) {
13075
- if (!middleware) return;
13076
- for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) if (buildWildcardRegExp(k).test(path)) return [...middleware[k]];
13334
+ function covers(wildcard, target) {
13335
+ const last = wildcard.length - 1;
13336
+ for (let i = 0; i < last; i++) if (wildcard[i] !== target[i]) return false;
13337
+ return wildcard[last] === "[^]*" || target.length === last || target[last] === "/";
13077
13338
  }
13078
13339
  var RegExpRouter = class {
13079
13340
  name = "RegExpRouter";
13080
- #middleware;
13081
- #routes;
13341
+ #handlers;
13342
+ #tries;
13082
13343
  constructor() {
13083
- this.#middleware = { ["ALL"]: /* @__PURE__ */ Object.create(null) };
13084
- this.#routes = { ["ALL"]: /* @__PURE__ */ Object.create(null) };
13344
+ this.#handlers = { ["ALL"]: [] };
13345
+ this.#tries = { ["ALL"]: new Trie() };
13346
+ }
13347
+ #insertPath(method, path) {
13348
+ try {
13349
+ this.#tries[method].insert(path, !/\*|\/:/.test(path));
13350
+ } catch (e) {
13351
+ throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
13352
+ }
13085
13353
  }
13086
13354
  add(method, path, handler) {
13087
- const middleware = this.#middleware;
13088
- const routes = this.#routes;
13089
- if (!middleware || !routes) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
13090
- if (!middleware[method]) [middleware, routes].forEach((handlerMap) => {
13091
- handlerMap[method] = /* @__PURE__ */ Object.create(null);
13092
- Object.keys(handlerMap["ALL"]).forEach((p) => {
13093
- handlerMap[method][p] = [...handlerMap["ALL"][p]];
13094
- });
13095
- });
13096
- if (path === "/*") path = "*";
13097
- const paramCount = (path.match(/\/:/g) || []).length;
13098
- if (/\*$/.test(path)) {
13099
- const re = buildWildcardRegExp(path);
13100
- if (method === "ALL") Object.keys(middleware).forEach((m) => {
13101
- middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware["ALL"], path) || [];
13102
- });
13103
- else middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware["ALL"], path) || [];
13104
- Object.keys(middleware).forEach((m) => {
13105
- if (method === "ALL" || method === m) Object.keys(middleware[m]).forEach((p) => {
13106
- re.test(p) && middleware[m][p].push([handler, paramCount]);
13107
- });
13108
- });
13109
- Object.keys(routes).forEach((m) => {
13110
- if (method === "ALL" || method === m) Object.keys(routes[m]).forEach((p) => re.test(p) && routes[m][p].push([handler, paramCount]));
13111
- });
13112
- return;
13355
+ const handlers = this.#handlers;
13356
+ if (!handlers) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
13357
+ const tries = this.#tries;
13358
+ if (!handlers[method]) {
13359
+ tries[method] = new Trie();
13360
+ handlers[method] = [...handlers["ALL"]];
13361
+ for (const p in tries["ALL"].paths) this.#insertPath(method, p);
13113
13362
  }
13363
+ if (path === "/*") path = "*";
13364
+ const methods = method === "ALL" ? Object.keys(handlers) : [method];
13114
13365
  const paths = checkOptionalParameter(path) || [path];
13115
- for (let i = 0, len = paths.length; i < len; i++) {
13116
- const path2 = paths[i];
13117
- Object.keys(routes).forEach((m) => {
13118
- if (method === "ALL" || method === m) {
13119
- routes[m][path2] ||= [...findMiddleware(middleware[m], path2) || findMiddleware(middleware["ALL"], path2) || []];
13120
- routes[m][path2].push([handler, paramCount - len + i + 1]);
13121
- }
13122
- });
13366
+ for (const path of paths) for (const m of methods) {
13367
+ if (!tries[m].paths[path]) this.#insertPath(m, path);
13368
+ handlers[m].push([handler, path]);
13123
13369
  }
13124
13370
  }
13125
13371
  match = match;
13126
13372
  buildAllMatchers() {
13127
- const matchers = /* @__PURE__ */ Object.create(null);
13128
- Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
13129
- matchers[method] ||= this.#buildMatcher(method);
13130
- });
13131
- this.#middleware = this.#routes = void 0;
13132
- clearWildcardRegExpCache();
13373
+ const matchers = createNullObject();
13374
+ for (const method of Object.keys(this.#handlers)) matchers[method] = this.#buildMatcher(method);
13375
+ this.#handlers = this.#tries = void 0;
13133
13376
  return matchers;
13134
13377
  }
13135
13378
  #buildMatcher(method) {
13136
- const routes = [];
13137
- let hasOwnRoute = method === "ALL";
13138
- [this.#middleware, this.#routes].forEach((r) => {
13139
- const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
13140
- if (ownRoute.length !== 0) {
13141
- hasOwnRoute ||= true;
13142
- routes.push(...ownRoute);
13143
- } else if (method !== "ALL") routes.push(...Object.keys(r["ALL"]).map((path) => [path, r["ALL"][path]]));
13379
+ const handlers = this.#handlers[method];
13380
+ const trie = this.#tries[method];
13381
+ const staticMap = createNullObject();
13382
+ const handlerData = [];
13383
+ const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
13384
+ const own = createNullObject();
13385
+ const entries = handlers.map(([h, p], i) => {
13386
+ (own[p] ??= []).push(i);
13387
+ return [h, trie.paths[p][1].reduceRight((map, [key, varIndex]) => {
13388
+ map[key] = paramReplacementMap[varIndex];
13389
+ return map;
13390
+ }, createNullObject())];
13144
13391
  });
13145
- if (!hasOwnRoute) return null;
13146
- else return buildMatcherFromPreprocessedRoutes(routes);
13392
+ const wildcards = Object.keys(own).filter((p) => endsWithWildcard(trie.paths[p][2]));
13393
+ for (const path in trie.paths) {
13394
+ const [index, , keys] = trie.paths[path];
13395
+ const indexes = [...own[path]];
13396
+ for (const p of wildcards) if (p !== path && covers(trie.paths[p][2], keys)) indexes.push(...own[p]);
13397
+ const data = indexes.sort((a, b) => a - b).map((i) => entries[i]);
13398
+ if (index === -1) {
13399
+ const last = Math.max(-1, ...data.flatMap(([, map]) => Object.values(map)));
13400
+ staticMap[path] = [data, last === -1 ? emptyParam : path.match(regexp).slice(0, last + 1)];
13401
+ } else handlerData[index] = data;
13402
+ }
13403
+ return [
13404
+ regexp,
13405
+ indexReplacementMap.map((i) => handlerData[i]),
13406
+ staticMap
13407
+ ];
13147
13408
  }
13148
13409
  };
13149
13410
  //#endregion
13150
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/smart-router/router.js
13411
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/smart-router/router.js
13151
13412
  var SmartRouter = class {
13152
13413
  name = "SmartRouter";
13153
13414
  #routers = [];
@@ -13173,7 +13434,7 @@ var SmartRouter = class {
13173
13434
  for (; i < len; i++) {
13174
13435
  const router = routers[i];
13175
13436
  try {
13176
- for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) router.add(...routes[i2]);
13437
+ for (let i = 0, len = routes.length; i < len; i++) router.add(...routes[i]);
13177
13438
  res = router.match(method, path);
13178
13439
  } catch (e) {
13179
13440
  if (e instanceof UnsupportedPathError) continue;
@@ -13194,74 +13455,49 @@ var SmartRouter = class {
13194
13455
  }
13195
13456
  };
13196
13457
  //#endregion
13197
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/trie-router/node.js
13198
- var emptyParams = /* @__PURE__ */ Object.create(null);
13199
- var hasChildren = (children) => {
13200
- for (const _ in children) return true;
13201
- return false;
13202
- };
13203
- var Node = class _Node {
13204
- #methods;
13205
- #children;
13206
- #patterns;
13207
- #order = 0;
13458
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/trie-router/node.js
13459
+ const emptyParams = createNullObject();
13460
+ let order = 0;
13461
+ var Node = class Node {
13462
+ #methods = [];
13463
+ #children = createNullObject();
13464
+ #patterns = [];
13465
+ #pattern;
13208
13466
  #params = emptyParams;
13209
- constructor(method, handler, children) {
13210
- this.#children = children || /* @__PURE__ */ Object.create(null);
13211
- this.#methods = [];
13212
- if (method && handler) {
13213
- const m = /* @__PURE__ */ Object.create(null);
13214
- m[method] = {
13215
- handler,
13216
- possibleKeys: [],
13217
- score: 0
13218
- };
13219
- this.#methods = [m];
13220
- }
13221
- this.#patterns = [];
13222
- }
13223
13467
  insert(method, path, handler) {
13224
- this.#order = ++this.#order;
13225
13468
  let curNode = this;
13226
13469
  const parts = splitRoutingPath(path);
13227
- const possibleKeys = [];
13228
- for (let i = 0, len = parts.length; i < len; i++) {
13229
- const p = parts[i];
13230
- const nextP = parts[i + 1];
13231
- const pattern = getPattern(p, nextP);
13232
- const key = Array.isArray(pattern) ? pattern[0] : p;
13233
- if (key in curNode.#children) {
13234
- curNode = curNode.#children[key];
13235
- if (pattern) possibleKeys.push(pattern[1]);
13236
- continue;
13237
- }
13238
- curNode.#children[key] = new _Node();
13239
- if (pattern) {
13240
- curNode.#patterns.push(pattern);
13241
- possibleKeys.push(pattern[1]);
13470
+ const possibleKeys = /* @__PURE__ */ new Set();
13471
+ let i = 0;
13472
+ for (const p of parts) {
13473
+ const nextP = parts[++i];
13474
+ const pattern = getPattern(p, nextP) || (nextP === void 0 && p && p.indexOf("*") === p.length - 1 ? p : null);
13475
+ const isParam = Array.isArray(pattern);
13476
+ const key = isParam ? pattern[0] : pattern || p;
13477
+ const child = curNode.#children[key] ||= new Node();
13478
+ if (pattern && !child.#pattern) {
13479
+ child.#pattern = pattern;
13480
+ curNode.#patterns.push(child);
13242
13481
  }
13243
- curNode = curNode.#children[key];
13482
+ curNode = child;
13483
+ if (isParam) possibleKeys.add(pattern[1]);
13244
13484
  }
13245
13485
  curNode.#methods.push({ [method]: {
13246
13486
  handler,
13247
- possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
13248
- score: this.#order
13487
+ possibleKeys: [...possibleKeys],
13488
+ score: ++order
13249
13489
  } });
13250
- return curNode;
13251
13490
  }
13252
13491
  #pushHandlerSets(handlerSets, node, method, nodeParams, params) {
13253
13492
  for (let i = 0, len = node.#methods.length; i < len; i++) {
13254
13493
  const m = node.#methods[i];
13255
13494
  const handlerSet = m[method] || m["ALL"];
13256
- const processedSet = {};
13257
- if (handlerSet !== void 0) {
13258
- handlerSet.params = /* @__PURE__ */ Object.create(null);
13495
+ if (handlerSet) {
13496
+ handlerSet.params = createNullObject();
13259
13497
  handlerSets.push(handlerSet);
13260
- if (nodeParams !== emptyParams || params && params !== emptyParams) for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
13261
- const key = handlerSet.possibleKeys[i2];
13262
- const processed = processedSet[handlerSet.score];
13263
- handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
13264
- processedSet[handlerSet.score] = true;
13498
+ for (let i = 0, len = handlerSet.possibleKeys.length; i < len; i++) {
13499
+ const key = handlerSet.possibleKeys[i];
13500
+ handlerSet.params[key] = params?.[key] && !i ? params[key] : nodeParams[key] ?? params?.[key];
13265
13501
  }
13266
13502
  }
13267
13503
  }
@@ -13288,46 +13524,47 @@ var Node = class _Node {
13288
13524
  this.#pushHandlerSets(handlerSets, nextNode, method, node.#params);
13289
13525
  } else tempNodes.push(nextNode);
13290
13526
  }
13291
- for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
13292
- const pattern = node.#patterns[k];
13527
+ for (const child of node.#patterns) {
13528
+ const pattern = child.#pattern;
13293
13529
  const params = node.#params === emptyParams ? {} : { ...node.#params };
13294
- if (pattern === "*") {
13295
- const astNode = node.#children["*"];
13296
- if (astNode) {
13297
- this.#pushHandlerSets(handlerSets, astNode, method, node.#params);
13298
- astNode.#params = params;
13299
- tempNodes.push(astNode);
13530
+ if (typeof pattern === "string") {
13531
+ if (pattern === "*" || part.startsWith(pattern.slice(0, -1))) {
13532
+ this.#pushHandlerSets(handlerSets, child, method, node.#params);
13533
+ if (pattern === "*") {
13534
+ child.#params = params;
13535
+ tempNodes.push(child);
13536
+ }
13300
13537
  }
13301
13538
  continue;
13302
13539
  }
13303
- const [key, name, matcher] = pattern;
13304
- if (!part && !(matcher instanceof RegExp)) continue;
13305
- const child = node.#children[key];
13306
- if (matcher instanceof RegExp) {
13307
- if (partOffsets === null) {
13308
- partOffsets = new Array(len);
13540
+ const [, name, matcher] = pattern;
13541
+ if (!part && matcher === true) continue;
13542
+ if (matcher !== true) {
13543
+ if (!partOffsets) {
13544
+ partOffsets = [];
13309
13545
  let offset = path[0] === "/" ? 1 : 0;
13310
13546
  for (let p = 0; p < len; p++) {
13311
13547
  partOffsets[p] = offset;
13312
13548
  offset += parts[p].length + 1;
13313
13549
  }
13314
13550
  }
13315
- const restPathString = path.substring(partOffsets[i]);
13551
+ const restPathString = path.slice(partOffsets[i]);
13316
13552
  const m = matcher.exec(restPathString);
13317
13553
  if (m) {
13318
- params[name] = m[0];
13554
+ if (!Object.hasOwn(params, name)) params[name] = m[0];
13319
13555
  this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
13320
13556
  if (m[0].length === restPathString.length && child.#children["*"]) this.#pushHandlerSets(handlerSets, child.#children["*"], method, node.#params, params);
13321
- if (hasChildren(child.#children)) {
13557
+ for (const _ in child.#children) {
13322
13558
  child.#params = params;
13323
- const componentCount = m[0].match(/\//)?.length ?? 0;
13559
+ const componentCount = m[0].match(/\//g)?.length ?? 0;
13324
13560
  (curNodesQueue[componentCount] ||= []).push(child);
13561
+ break;
13325
13562
  }
13326
13563
  continue;
13327
13564
  }
13328
13565
  }
13329
13566
  if (matcher === true || matcher.test(part)) {
13330
- params[name] = part;
13567
+ if (!Object.hasOwn(params, name)) params[name] = part;
13331
13568
  if (isLast) {
13332
13569
  this.#pushHandlerSets(handlerSets, child, method, params, node.#params);
13333
13570
  if (child.#children["*"]) this.#pushHandlerSets(handlerSets, child.#children["*"], method, params, node.#params);
@@ -13341,34 +13578,34 @@ var Node = class _Node {
13341
13578
  const shifted = curNodesQueue.shift();
13342
13579
  curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
13343
13580
  }
13344
- if (handlerSets.length > 1) handlerSets.sort((a, b) => {
13581
+ if (handlerSets[1]) handlerSets.sort((a, b) => {
13345
13582
  return a.score - b.score;
13346
13583
  });
13347
13584
  return [handlerSets.map(({ handler, params }) => [handler, params])];
13348
13585
  }
13349
13586
  };
13350
13587
  //#endregion
13351
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/trie-router/router.js
13588
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/trie-router/router.js
13352
13589
  var TrieRouter = class {
13353
13590
  name = "TrieRouter";
13354
- #node;
13355
- constructor() {
13356
- this.#node = new Node();
13357
- }
13591
+ #node = new Node();
13358
13592
  add(method, path, handler) {
13359
- const results = checkOptionalParameter(path);
13360
- if (results) {
13361
- for (let i = 0, len = results.length; i < len; i++) this.#node.insert(method, results[i], handler);
13362
- return;
13363
- }
13364
- this.#node.insert(method, path, handler);
13593
+ for (const result of checkOptionalParameter(path) || [path]) this.#node.insert(method, result, handler);
13365
13594
  }
13366
13595
  match(method, path) {
13367
13596
  return this.#node.search(method, path);
13368
13597
  }
13369
13598
  };
13370
13599
  //#endregion
13371
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/hono.js
13600
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/hono.js
13601
+ /**
13602
+ * The Hono class extends the functionality of the HonoBase class.
13603
+ * It sets up routing and allows for custom options to be passed.
13604
+ *
13605
+ * @template E - The environment type.
13606
+ * @template S - The schema type.
13607
+ * @template BasePath - The base path type.
13608
+ */
13372
13609
  var Hono = class extends Hono$1 {
13373
13610
  /**
13374
13611
  * Creates an instance of the Hono class.
@@ -13381,14 +13618,14 @@ var Hono = class extends Hono$1 {
13381
13618
  }
13382
13619
  };
13383
13620
  //#endregion
13384
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/encode.js
13385
- var encodeBase64 = (buf) => {
13621
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/encode.js
13622
+ const encodeBase64 = (buf) => {
13386
13623
  let binary = "";
13387
13624
  const bytes = new Uint8Array(buf);
13388
13625
  for (let i = 0, len = bytes.length; i < len; i++) binary += String.fromCharCode(bytes[i]);
13389
13626
  return btoa(binary);
13390
13627
  };
13391
- var decodeBase64 = (str) => {
13628
+ const decodeBase64 = (str) => {
13392
13629
  const binary = atob(str);
13393
13630
  const bytes = new Uint8Array(new ArrayBuffer(binary.length));
13394
13631
  const half = binary.length / 2;
@@ -13399,9 +13636,13 @@ var decodeBase64 = (str) => {
13399
13636
  return bytes;
13400
13637
  };
13401
13638
  //#endregion
13402
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/adapter/lambda-edge/handler.js
13639
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/adapter/lambda-edge/handler.js
13403
13640
  globalThis.crypto ??= node_crypto.default;
13404
- var convertHeaders = (headers) => {
13641
+ /**
13642
+ * Accepts events from 'Lambda@Edge' event
13643
+ * https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html
13644
+ */
13645
+ const convertHeaders = (headers) => {
13405
13646
  const cfHeaders = {};
13406
13647
  headers.forEach((value, key) => {
13407
13648
  cfHeaders[key.toLowerCase()] = [...cfHeaders[key.toLowerCase()] || [], {
@@ -13411,12 +13652,16 @@ var convertHeaders = (headers) => {
13411
13652
  });
13412
13653
  return cfHeaders;
13413
13654
  };
13414
- var handle = (app) => {
13655
+ /**
13656
+ * @deprecated `hono/lambda-edge` will be removed in v5. Install `@hono/lambda-edge` and import from there instead.
13657
+ */
13658
+ const handle = (app) => {
13415
13659
  return async (event, ...args) => {
13416
13660
  const [context, callback] = args;
13417
13661
  let callbackError = null;
13418
13662
  let callbackResult;
13419
- const res = await app.fetch(createRequest(event), {
13663
+ const cf = getCloudFrontRecord(event);
13664
+ const res = await app.fetch(createRequest(cf), {
13420
13665
  event,
13421
13666
  context,
13422
13667
  callback: (err, result) => {
@@ -13426,18 +13671,22 @@ var handle = (app) => {
13426
13671
  }
13427
13672
  callback?.(err, result);
13428
13673
  },
13429
- config: event.Records[0].cf.config,
13430
- request: event.Records[0].cf.request,
13431
- response: event.Records[0].cf.response
13674
+ config: cf.config,
13675
+ request: cf.request,
13676
+ response: cf.response
13432
13677
  });
13433
13678
  if (callbackError) throw callbackError;
13434
13679
  return callbackResult ?? createResult(res);
13435
13680
  };
13436
13681
  };
13437
- var createResult = async (res) => {
13682
+ const createResult = async (res) => {
13683
+ if (res.status === 204) return {
13684
+ status: "204",
13685
+ headers: convertHeaders(res.headers)
13686
+ };
13438
13687
  const contentEncoding = res.headers.get("content-encoding");
13439
13688
  const isBase64Encoded = isContentTypeBinary(res.headers.get("content-type") || "") || !!contentEncoding && !/^identity$/i.test(contentEncoding);
13440
- const body = isBase64Encoded ? encodeBase64(await res.arrayBuffer()) : await res.text();
13689
+ const body = isBase64Encoded ? encodeBase64(await res.arrayBuffer()) : new TextDecoder("utf-8", { ignoreBOM: true }).decode(await res.arrayBuffer());
13441
13690
  return {
13442
13691
  status: res.status.toString(),
13443
13692
  headers: convertHeaders(res.headers),
@@ -13445,16 +13694,30 @@ var createResult = async (res) => {
13445
13694
  ...isBase64Encoded && { bodyEncoding: "base64" }
13446
13695
  };
13447
13696
  };
13448
- var createRequest = (event) => {
13449
- const queryString = event.Records[0].cf.request.querystring;
13450
- const urlPath = `https://${event.Records[0].cf.request.headers?.host?.[0]?.value || event.Records[0].cf.config.distributionDomainName}${event.Records[0].cf.request.uri}`;
13697
+ /**
13698
+ * Reads the CloudFront record out of a Lambda@Edge event.
13699
+ *
13700
+ * The event is supplied by the runtime, so a malformed one means the function
13701
+ * was invoked with something other than a Lambda@Edge event. Fail with a
13702
+ * message naming the adapter and the missing field, rather than letting an
13703
+ * unattributable property access error escape.
13704
+ */
13705
+ const getCloudFrontRecord = (event) => {
13706
+ const cf = event?.Records?.[0]?.cf;
13707
+ 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.");
13708
+ return cf;
13709
+ };
13710
+ const createRequest = (cf) => {
13711
+ const request = cf.request;
13712
+ const queryString = request.querystring;
13713
+ const urlPath = `https://${request.headers?.host?.[0]?.value || cf.config?.distributionDomainName}${request.uri}`;
13451
13714
  const url = queryString ? `${urlPath}?${queryString}` : urlPath;
13452
13715
  const headers = new Headers();
13453
- Object.entries(event.Records[0].cf.request.headers).forEach(([k, v]) => {
13716
+ Object.entries(request.headers ?? {}).forEach(([k, v]) => {
13454
13717
  v.forEach((header) => headers.append(k, header.value));
13455
13718
  });
13456
- const requestBody = event.Records[0].cf.request.body;
13457
- const method = event.Records[0].cf.request.method;
13719
+ const requestBody = request.body;
13720
+ const method = request.method;
13458
13721
  const rawBody = createBody(method, requestBody);
13459
13722
  let body = rawBody;
13460
13723
  if (rawBody !== void 0) {
@@ -13468,14 +13731,21 @@ var createRequest = (event) => {
13468
13731
  body
13469
13732
  });
13470
13733
  };
13471
- var createBody = (method, requestBody) => {
13734
+ /**
13735
+ * @deprecated `hono/lambda-edge` will be removed in v5. Install `@hono/lambda-edge` and import from there instead.
13736
+ */
13737
+ const createBody = (method, requestBody) => {
13472
13738
  if (!requestBody || !requestBody.data) return;
13473
13739
  if (method === "GET" || method === "HEAD") return;
13474
13740
  if (requestBody.encoding === "base64") return decodeBase64(requestBody.data);
13475
13741
  return requestBody.data;
13476
13742
  };
13477
- var isContentTypeBinary = (contentType) => {
13478
- return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml.*)$/.test(contentType);
13743
+ /**
13744
+ * @deprecated `hono/lambda-edge` will be removed in v5. Install `@hono/lambda-edge` and import from there instead.
13745
+ */
13746
+ const isContentTypeBinary = (contentType) => {
13747
+ if (/^application\/vnd\.(?:apple\.installer|mozilla\.xul)\+xml\s*(?:;|$)/i.test(contentType)) return true;
13748
+ return !/^text\/(?:plain|html|css|javascript|csv)|(?:\/|\+)(?:json|xml)\s*(?:;|$)/i.test(contentType);
13479
13749
  };
13480
13750
  //#endregion
13481
13751
  //#region src/runtimeAwsConfig.ts