@hot-updater/aws 1.1.21 → 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 +718 -449
  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.21";
4669
+ const HOT_UPDATER_SERVER_VERSION = "1.1.22";
4670
4670
  //#endregion
4671
4671
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
4672
4672
  /**
@@ -11588,48 +11588,72 @@ const remoteConfig = () => {
11588
11588
  return markOfficial(plugin);
11589
11589
  };
11590
11590
  //#endregion
11591
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/compose.js
11592
- var compose = (middleware, onError, onNotFound) => {
11593
- return (context, next) => {
11594
- let index = -1;
11595
- return dispatch(0);
11596
- async function dispatch(i) {
11597
- if (i <= index) throw new Error("next() called multiple times");
11598
- index = i;
11599
- let res;
11600
- let isError = false;
11601
- let handler;
11602
- if (middleware[i]) {
11603
- handler = middleware[i][0][0];
11604
- context.req.routeIndex = i;
11605
- } else handler = i === middleware.length && next || void 0;
11606
- if (handler) try {
11607
- res = await handler(context, () => dispatch(i + 1));
11608
- } catch (err) {
11609
- if (err instanceof Error && onError) {
11610
- context.error = err;
11611
- res = await onError(err, context);
11612
- isError = true;
11613
- } else throw err;
11614
- }
11615
- else if (context.finalized === false && onNotFound) res = await onNotFound(context);
11616
- if (res && (context.finalized === false || isError)) context.res = res;
11617
- return context;
11618
- }
11619
- };
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
+ }
11620
11643
  };
11621
11644
  //#endregion
11622
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/request/constants.js
11623
- 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();
11624
11647
  //#endregion
11625
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/buffer.js
11626
- 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) => {
11627
11650
  return new Response(arrayBuffer, { headers: { "Content-Type": contentType.replace(/^[^;]+/, (mediaType) => mediaType.toLowerCase()) } }).formData();
11628
11651
  };
11629
11652
  //#endregion
11630
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/body.js
11631
- var isRawRequest = (request) => "headers" in request;
11632
- 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)) => {
11633
11657
  const { all = false, dot = false } = options;
11634
11658
  const mediaType = (isRawRequest(request) ? request.headers : request.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();
11635
11659
  if (mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded") return parseFormData(request, {
@@ -11638,60 +11662,101 @@ var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) =
11638
11662
  });
11639
11663
  return {};
11640
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
+ */
11641
11673
  async function parseFormData(request, options) {
11642
11674
  if (!isRawRequest(request) && request.bodyCache.formData) return convertFormDataToBodyData(await request.bodyCache.formData, options);
11643
11675
  const headers = isRawRequest(request) ? request.headers : request.raw.headers;
11644
- 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") || "");
11645
11678
  if (!isRawRequest(request)) request.bodyCache.formData = formDataPromise;
11646
11679
  const formData = await formDataPromise;
11647
11680
  if (formData) return convertFormDataToBodyData(formData, options);
11648
11681
  return {};
11649
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
+ */
11650
11691
  function convertFormDataToBodyData(formData, options) {
11651
- const form = /* @__PURE__ */ Object.create(null);
11692
+ const form = Object.create(null);
11693
+ const nestingState = { count: 0 };
11652
11694
  formData.forEach((value, key) => {
11653
11695
  if (!(options.all || key.endsWith("[]"))) form[key] = value;
11654
11696
  else handleParsingAllValues(form, key, value);
11655
11697
  });
11656
11698
  if (options.dot) Object.entries(form).forEach(([key, value]) => {
11657
11699
  if (key.includes(".")) {
11658
- handleParsingNestedValues(form, key, value);
11700
+ handleParsingNestedValues(form, key, value, nestingState);
11659
11701
  delete form[key];
11660
11702
  }
11661
11703
  });
11662
11704
  return form;
11663
11705
  }
11664
- 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) => {
11665
11714
  if (form[key] !== void 0) {
11666
11715
  if (Array.isArray(form[key])) form[key].push(value);
11667
11716
  else form[key] = [form[key], value];
11668
11717
  } else if (!key.endsWith("[]")) form[key] = value;
11669
11718
  else form[key] = [value];
11670
11719
  };
11671
- 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) => {
11672
11729
  if (/(?:^|\.)__proto__\./.test(key)) return;
11673
11730
  let nestedForm = form;
11674
- const keys = key.split(".");
11675
- keys.forEach((key2, index) => {
11676
- 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;
11677
11735
  else {
11678
- if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) nestedForm[key2] = /* @__PURE__ */ Object.create(null);
11679
- 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];
11680
11741
  }
11681
11742
  });
11682
11743
  };
11744
+ const throwNestingLimitExceeded = () => {
11745
+ throw new Error("Nesting limit exceeded");
11746
+ };
11683
11747
  //#endregion
11684
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/url.js
11685
- var splitPath = (path) => {
11748
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/url.js
11749
+ const splitPath = (path) => {
11686
11750
  const paths = path.split("/");
11687
11751
  if (paths[0] === "") paths.shift();
11688
11752
  return paths;
11689
11753
  };
11690
- var splitRoutingPath = (routePath) => {
11754
+ const splitRoutingPath = (routePath) => {
11691
11755
  const { groups, path } = extractGroupsFromPath(routePath);
11692
- return replaceGroupMarks(splitPath(path), groups);
11756
+ const paths = splitPath(path);
11757
+ return replaceGroupMarks(paths, groups);
11693
11758
  };
11694
- var extractGroupsFromPath = (path) => {
11759
+ const extractGroupsFromPath = (path) => {
11695
11760
  const groups = [];
11696
11761
  path = path.replace(/\{[^}]+\}/g, (match, index) => {
11697
11762
  const mark = `@${index}`;
@@ -11703,7 +11768,7 @@ var extractGroupsFromPath = (path) => {
11703
11768
  path
11704
11769
  };
11705
11770
  };
11706
- var replaceGroupMarks = (paths, groups) => {
11771
+ const replaceGroupMarks = (paths, groups) => {
11707
11772
  for (let i = groups.length - 1; i >= 0; i--) {
11708
11773
  const [mark] = groups[i];
11709
11774
  for (let j = paths.length - 1; j >= 0; j--) if (paths[j].includes(mark)) {
@@ -11713,8 +11778,8 @@ var replaceGroupMarks = (paths, groups) => {
11713
11778
  }
11714
11779
  return paths;
11715
11780
  };
11716
- var patternCache = {};
11717
- var getPattern = (label, next) => {
11781
+ const patternCache = {};
11782
+ const getPattern = (label, next) => {
11718
11783
  if (label === "*") return "*";
11719
11784
  const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
11720
11785
  if (match) {
@@ -11739,7 +11804,7 @@ var getPattern = (label, next) => {
11739
11804
  }
11740
11805
  return null;
11741
11806
  };
11742
- var tryDecode = (str, decoder) => {
11807
+ const tryDecode = (str, decoder) => {
11743
11808
  try {
11744
11809
  return decoder(str);
11745
11810
  } catch {
@@ -11752,8 +11817,8 @@ var tryDecode = (str, decoder) => {
11752
11817
  });
11753
11818
  }
11754
11819
  };
11755
- var tryDecodeURI = (str) => tryDecode(str, decodeURI);
11756
- var getPath = (request) => {
11820
+ const decodeURIWithPreservedPercent = (value) => decodeURI(value.includes("%25") ? value.replace(/%25/g, "%2525") : value);
11821
+ const getPath = (request) => {
11757
11822
  const url = request.url;
11758
11823
  const start = url.indexOf("/", url.indexOf(":") + 4);
11759
11824
  let i = start;
@@ -11764,20 +11829,36 @@ var getPath = (request) => {
11764
11829
  const hashIndex = url.indexOf("#", i);
11765
11830
  const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
11766
11831
  const path = url.slice(start, end);
11767
- 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;
11768
11839
  } else if (charCode === 63 || charCode === 35) break;
11769
11840
  }
11770
11841
  return url.slice(start, i);
11771
11842
  };
11772
- var getPathNoStrict = (request) => {
11843
+ const getPathNoStrict = (request) => {
11773
11844
  const result = getPath(request);
11774
11845
  return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
11775
11846
  };
11776
- 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) => {
11777
11858
  if (rest.length) sub = mergePath(sub, ...rest);
11778
11859
  return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
11779
11860
  };
11780
- var checkOptionalParameter = (path) => {
11861
+ const checkOptionalParameter = (path) => {
11781
11862
  if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) return null;
11782
11863
  const segments = path.split("/");
11783
11864
  const results = [];
@@ -11785,10 +11866,10 @@ var checkOptionalParameter = (path) => {
11785
11866
  segments.forEach((segment) => {
11786
11867
  if (segment !== "" && !/\:/.test(segment)) basePath += "/" + segment;
11787
11868
  else if (/\:/.test(segment)) {
11788
- if (/\?/.test(segment)) {
11869
+ if (segment.charCodeAt(segment.length - 1) === 63) {
11789
11870
  if (results.length === 0 && basePath === "") results.push("/");
11790
11871
  else results.push(basePath);
11791
- const optionalSegment = segment.replace("?", "");
11872
+ const optionalSegment = segment.slice(0, -1);
11792
11873
  basePath += "/" + optionalSegment;
11793
11874
  results.push(basePath);
11794
11875
  } else basePath += "/" + segment;
@@ -11796,30 +11877,37 @@ var checkOptionalParameter = (path) => {
11796
11877
  });
11797
11878
  return results.filter((v, i, a) => a.indexOf(v) === i);
11798
11879
  };
11799
- var _decodeURI = (value) => {
11800
- if (!/[%+]/.test(value)) return value;
11880
+ const tryDecodeURIComponent = (str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str;
11881
+ const _decodeURI = (value) => {
11801
11882
  if (value.indexOf("+") !== -1) value = value.replace(/\+/g, " ");
11802
- return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
11883
+ return tryDecodeURIComponent(value);
11803
11884
  };
11804
- 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);
11805
11888
  let encoded;
11806
- if (!multiple && key && !/[%+]/.test(key)) {
11807
- let keyIndex2 = url.indexOf("?", 8);
11808
- if (keyIndex2 === -1) return;
11809
- if (!url.startsWith(key, keyIndex2 + 1)) keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
11810
- while (keyIndex2 !== -1) {
11811
- const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
11812
- if (trailingKeyCode === 61) {
11813
- const valueIndex = keyIndex2 + key.length + 2;
11814
- const endIndex = url.indexOf("&", valueIndex);
11815
- return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
11816
- } else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) return "";
11817
- 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);
11818
11906
  }
11819
11907
  encoded = /[%+]/.test(url);
11820
11908
  if (!encoded) return;
11821
11909
  }
11822
- const results = /* @__PURE__ */ Object.create(null);
11910
+ const results = Object.create(null);
11823
11911
  encoded ??= /[%+]/.test(url);
11824
11912
  let keyIndex = url.indexOf("?", 8);
11825
11913
  while (keyIndex !== -1) {
@@ -11843,14 +11931,13 @@ var _getQueryParam = (url, key, multiple) => {
11843
11931
  }
11844
11932
  return key ? results[key] : results;
11845
11933
  };
11846
- var getQueryParam = _getQueryParam;
11847
- var getQueryParams = (url, key) => {
11934
+ const getQueryParam = _getQueryParam;
11935
+ const getQueryParams = (url, key) => {
11848
11936
  return _getQueryParam(url, key, true);
11849
11937
  };
11850
- var decodeURIComponent_ = decodeURIComponent;
11938
+ const decodeURIComponent_ = decodeURIComponent;
11851
11939
  //#endregion
11852
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/request.js
11853
- var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
11940
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/request.js
11854
11941
  var HonoRequest = class {
11855
11942
  /**
11856
11943
  * `.raw` can get the raw Request object.
@@ -11888,22 +11975,21 @@ var HonoRequest = class {
11888
11975
  this.raw = request;
11889
11976
  this.path = path;
11890
11977
  this.#matchResult = matchResult;
11891
- this.#validatedData = {};
11892
11978
  }
11893
11979
  param(key) {
11894
11980
  return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
11895
11981
  }
11896
11982
  #getDecodedParam(key) {
11897
- const paramKey = this.#matchResult[0][this.routeIndex][1][key];
11983
+ const paramKey = this.#matchResult[0][this.routeIndex]?.[1][key];
11898
11984
  const param = this.#getParamValue(paramKey);
11899
- return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
11985
+ return param && tryDecodeURIComponent(param);
11900
11986
  }
11901
11987
  #getAllDecodedParams() {
11902
11988
  const decoded = {};
11903
- const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
11989
+ const keys = Object.keys(this.#matchResult[0][this.routeIndex]?.[1] ?? {});
11904
11990
  for (const key of keys) {
11905
11991
  const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
11906
- if (value !== void 0) decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
11992
+ if (value !== void 0) decoded[key] = tryDecodeURIComponent(value);
11907
11993
  }
11908
11994
  return decoded;
11909
11995
  }
@@ -11918,7 +12004,7 @@ var HonoRequest = class {
11918
12004
  }
11919
12005
  header(name) {
11920
12006
  if (name) return this.raw.headers.get(name) ?? void 0;
11921
- const headerData = /* @__PURE__ */ Object.create(null);
12007
+ const headerData = Object.create(null);
11922
12008
  this.raw.headers.forEach((value, key) => {
11923
12009
  headerData[key] = value;
11924
12010
  });
@@ -11931,10 +12017,10 @@ var HonoRequest = class {
11931
12017
  const { bodyCache, raw } = this;
11932
12018
  const cachedBody = bodyCache[key];
11933
12019
  if (cachedBody) return cachedBody;
11934
- const anyCachedKey = Object.keys(bodyCache)[0];
11935
- if (anyCachedKey) return bodyCache[anyCachedKey].then((body) => {
12020
+ for (const anyCachedKey in bodyCache) return bodyCache[anyCachedKey].then((body) => {
11936
12021
  if (anyCachedKey === "json") body = JSON.stringify(body);
11937
- 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]();
11938
12024
  });
11939
12025
  return bodyCache[key] = raw[key]();
11940
12026
  };
@@ -12031,13 +12117,13 @@ var HonoRequest = class {
12031
12117
  * @param data - The validated data to add.
12032
12118
  */
12033
12119
  addValidatedData(target, data) {
12034
- this.#validatedData[target] = data;
12120
+ (this.#validatedData ??= {})[target] = data;
12035
12121
  }
12036
12122
  valid(target) {
12037
- return this.#validatedData[target];
12123
+ return this.#validatedData?.[target];
12038
12124
  }
12039
12125
  /**
12040
- * `.url()` can get the request url strings.
12126
+ * `.url` can get the request url strings.
12041
12127
  *
12042
12128
  * @see {@link https://hono.dev/docs/api/request#url}
12043
12129
  *
@@ -12053,7 +12139,7 @@ var HonoRequest = class {
12053
12139
  return this.raw.url;
12054
12140
  }
12055
12141
  /**
12056
- * `.method()` can get the method name of the request.
12142
+ * `.method` can get the method name of the request.
12057
12143
  *
12058
12144
  * @see {@link https://hono.dev/docs/api/request#method}
12059
12145
  *
@@ -12071,7 +12157,7 @@ var HonoRequest = class {
12071
12157
  return this.#matchResult;
12072
12158
  }
12073
12159
  /**
12074
- * `.matchedRoutes()` can return a matched route in the handler
12160
+ * `.matchedRoutes` can return a matched route in the handler
12075
12161
  *
12076
12162
  * @deprecated
12077
12163
  *
@@ -12101,7 +12187,7 @@ var HonoRequest = class {
12101
12187
  return this.#matchResult[0].map(([[, route]]) => route);
12102
12188
  }
12103
12189
  /**
12104
- * `routePath()` can retrieve the path registered within the handler
12190
+ * `.routePath` can retrieve the path registered within the handler
12105
12191
  *
12106
12192
  * @deprecated
12107
12193
  *
@@ -12121,19 +12207,23 @@ var HonoRequest = class {
12121
12207
  }
12122
12208
  };
12123
12209
  //#endregion
12124
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/html.js
12125
- 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 = {
12126
12216
  Stringify: 1,
12127
12217
  BeforeStream: 2,
12128
12218
  Stream: 3
12129
12219
  };
12130
- var raw = (value, callbacks) => {
12220
+ const raw = (value, callbacks) => {
12131
12221
  const escapedString = new String(value);
12132
12222
  escapedString.isEscaped = true;
12133
12223
  escapedString.callbacks = callbacks;
12134
12224
  return escapedString;
12135
12225
  };
12136
- var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
12226
+ const resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
12137
12227
  if (typeof str === "object" && !(str instanceof String)) {
12138
12228
  if (!(str instanceof Promise)) str = str.toString();
12139
12229
  if (str instanceof Promise) str = await str;
@@ -12146,20 +12236,20 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
12146
12236
  phase,
12147
12237
  buffer,
12148
12238
  context
12149
- }))).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]));
12150
12240
  if (preserveCallbacks) return raw(await resStr, callbacks);
12151
12241
  else return resStr;
12152
12242
  };
12153
12243
  //#endregion
12154
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/context.js
12155
- var TEXT_PLAIN = "text/plain; charset=UTF-8";
12156
- 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) => {
12157
12247
  return {
12158
12248
  "Content-Type": contentType,
12159
12249
  ...headers
12160
12250
  };
12161
12251
  };
12162
- var createResponseInstance = (body, init) => new Response(body, init);
12252
+ const createResponseInstance = (body, init) => new Response(body, init);
12163
12253
  var Context = class {
12164
12254
  #rawRequest;
12165
12255
  #req;
@@ -12339,12 +12429,16 @@ var Context = class {
12339
12429
  * c.header('X-Message', 'Hello!')
12340
12430
  * c.header('Content-Type', 'text/plain')
12341
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
+ *
12342
12436
  * return c.body('Thank you for coming')
12343
12437
  * })
12344
12438
  * ```
12345
12439
  */
12346
12440
  header = (name, value, options) => {
12347
- 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);
12348
12442
  const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
12349
12443
  if (value === void 0) headers.delete(name);
12350
12444
  else if (options?.append) headers.append(name, value);
@@ -12401,20 +12495,33 @@ var Context = class {
12401
12495
  return Object.fromEntries(this.#var);
12402
12496
  }
12403
12497
  #newResponse(data, arg, headers) {
12404
- const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
12405
- if (typeof arg === "object" && "headers" in arg) {
12406
- const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
12407
- 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);
12408
12502
  else responseHeaders.set(key, value);
12409
12503
  }
12410
- if (headers) for (const [k, v] of Object.entries(headers)) if (typeof v === "string") responseHeaders.set(k, v);
12411
- else {
12412
- responseHeaders.delete(k);
12413
- 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
+ }
12414
12520
  }
12521
+ const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
12415
12522
  return createResponseInstance(data, {
12416
- status: typeof arg === "number" ? arg : arg?.status ?? this.#status,
12417
- headers: responseHeaders
12523
+ status,
12524
+ headers: responseHeaders ?? headers
12418
12525
  });
12419
12526
  }
12420
12527
  newResponse = (...args) => this.#newResponse(...args);
@@ -12471,7 +12578,7 @@ var Context = class {
12471
12578
  return this.#newResponse(JSON.stringify(object), arg, setDefaultContentType("application/json", headers));
12472
12579
  };
12473
12580
  html = (html, arg, headers) => {
12474
- 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));
12475
12582
  return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
12476
12583
  };
12477
12584
  /**
@@ -12512,26 +12619,190 @@ var Context = class {
12512
12619
  };
12513
12620
  };
12514
12621
  //#endregion
12515
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router.js
12516
- 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 = [
12517
12728
  "get",
12518
12729
  "post",
12519
12730
  "put",
12520
12731
  "delete",
12521
12732
  "options",
12522
- "patch"
12733
+ "patch",
12734
+ "query"
12523
12735
  ];
12524
- 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
+ */
12525
12743
  var UnsupportedPathError = class extends Error {};
12526
12744
  //#endregion
12527
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/constants.js
12528
- 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";
12529
12750
  //#endregion
12530
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/hono-base.js
12531
- 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) => {
12532
12803
  return c.text("404 Not Found", 404);
12533
12804
  };
12534
- var errorHandler = (err, c) => {
12805
+ const errorHandler = (err, c) => {
12535
12806
  if ("getResponse" in err) {
12536
12807
  const res = err.getResponse();
12537
12808
  return c.newResponse(res.body, res);
@@ -12539,13 +12810,14 @@ var errorHandler = (err, c) => {
12539
12810
  console.error(err);
12540
12811
  return c.text("Internal Server Error", 500);
12541
12812
  };
12542
- var Hono$1 = class _Hono {
12813
+ var Hono$1 = class Hono {
12543
12814
  get;
12544
12815
  post;
12545
12816
  put;
12546
12817
  delete;
12547
12818
  options;
12548
12819
  patch;
12820
+ query;
12549
12821
  all;
12550
12822
  on;
12551
12823
  use;
@@ -12557,10 +12829,11 @@ var Hono$1 = class _Hono {
12557
12829
  constructor(options = {}) {
12558
12830
  [...METHODS, "all"].forEach((method) => {
12559
12831
  this[method] = (args1, ...args) => {
12832
+ const methodName = method.toUpperCase();
12560
12833
  if (typeof args1 === "string") this.#path = args1;
12561
- else this.#addRoute(method, this.#path, args1);
12834
+ else this.#addRoute(methodName, this.#path, args1);
12562
12835
  args.forEach((handler) => {
12563
- this.#addRoute(method, this.#path, handler);
12836
+ this.#addRoute(methodName, this.#path, handler);
12564
12837
  });
12565
12838
  return this;
12566
12839
  };
@@ -12568,9 +12841,10 @@ var Hono$1 = class _Hono {
12568
12841
  this.on = (method, path, ...handlers) => {
12569
12842
  for (const p of [path].flat()) {
12570
12843
  this.#path = p;
12571
- for (const m of [method].flat()) handlers.map((handler) => {
12572
- this.#addRoute(m.toUpperCase(), this.#path, handler);
12573
- });
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
+ }
12574
12848
  }
12575
12849
  return this;
12576
12850
  };
@@ -12590,7 +12864,7 @@ var Hono$1 = class _Hono {
12590
12864
  this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
12591
12865
  }
12592
12866
  #clone() {
12593
- const clone = new _Hono({
12867
+ const clone = new Hono({
12594
12868
  router: this.router,
12595
12869
  getPath: this.getPath
12596
12870
  });
@@ -12692,12 +12966,16 @@ var Hono$1 = class _Hono {
12692
12966
  /**
12693
12967
  * `.mount()` allows you to mount applications built with other frameworks into your Hono application.
12694
12968
  *
12969
+ * @deprecated Use `mount()` from `hono/mount` instead. `.mount()` will be removed in v5.
12970
+ *
12695
12971
  * @see {@link https://hono.dev/docs/api/hono#mount}
12696
12972
  *
12697
12973
  * @param {string} path - base Path
12698
12974
  * @param {Function} applicationHandler - other Request Handler
12699
12975
  * @param {MountOptions} [options] - options of `.mount()`
12700
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.
12701
12979
  *
12702
12980
  * @example
12703
12981
  * ```ts
@@ -12733,8 +13011,8 @@ var Hono$1 = class _Hono {
12733
13011
  }
12734
13012
  }
12735
13013
  const getOptions = optionHandler ? (c) => {
12736
- const options2 = optionHandler(c);
12737
- return Array.isArray(options2) ? options2 : [options2];
13014
+ const options = optionHandler(c);
13015
+ return Array.isArray(options) ? options : [options];
12738
13016
  } : (c) => {
12739
13017
  let executionContext = void 0;
12740
13018
  try {
@@ -12742,17 +13020,12 @@ var Hono$1 = class _Hono {
12742
13020
  } catch {}
12743
13021
  return [c.env, executionContext];
12744
13022
  };
12745
- replaceRequest ||= (() => {
12746
- const mergedPath = mergePath(this._basePath, path);
12747
- const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
12748
- return (request) => {
12749
- const url = new URL(request.url);
12750
- url.pathname = this.getPath(request).slice(pathPrefixLength) || "/";
12751
- return new Request(url, request);
12752
- };
12753
- })();
13023
+ const defaultReplaceRequest = (c) => {
13024
+ const mountedRoutePath = routePath(c);
13025
+ return createMountedRequest(c, mountedRoutePath.replace(/\/?\*$/, ""), mountedRoutePath);
13026
+ };
12754
13027
  const handler = async (c, next) => {
12755
- const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
13028
+ const res = await applicationHandler(replaceRequest ? replaceRequest(c.req.raw) : defaultReplaceRequest(c), ...getOptions(c));
12756
13029
  if (res) return res;
12757
13030
  await next();
12758
13031
  };
@@ -12760,7 +13033,6 @@ var Hono$1 = class _Hono {
12760
13033
  return this;
12761
13034
  }
12762
13035
  #addRoute(method, path, handler, baseRoutePath) {
12763
- method = method.toUpperCase();
12764
13036
  path = mergePath(this._basePath, path);
12765
13037
  const r = {
12766
13038
  basePath: baseRoutePath !== void 0 ? mergePath(this._basePath, baseRoutePath) : this._basePath,
@@ -12814,8 +13086,8 @@ var Hono$1 = class _Hono {
12814
13086
  * @see {@link https://hono.dev/docs/api/hono#fetch}
12815
13087
  *
12816
13088
  * @param {Request} request - request Object of request
12817
- * @param {Env} Env - env Object
12818
- * @param {ExecutionContext} - context of execution
13089
+ * @param {Env} env - env Object
13090
+ * @param {ExecutionContext} executionCtx - context of execution
12819
13091
  * @returns {Response | Promise<Response>} response of request
12820
13092
  *
12821
13093
  */
@@ -12863,112 +13135,140 @@ var Hono$1 = class _Hono {
12863
13135
  };
12864
13136
  };
12865
13137
  //#endregion
12866
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/matcher.js
12867
- 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 = [];
12868
13143
  function match(method, path) {
12869
13144
  const matchers = this.buildAllMatchers();
12870
- const match2 = ((method2, path2) => {
12871
- const matcher = matchers[method2] || matchers["ALL"];
12872
- const staticMatch = matcher[2][path2];
13145
+ const match = ((method, path) => {
13146
+ const matcher = matchers[method] || matchers["ALL"];
13147
+ const staticMatch = matcher[2][path];
12873
13148
  if (staticMatch) return staticMatch;
12874
- const match3 = path2.match(matcher[0]);
12875
- if (!match3) return [[], emptyParam];
12876
- const index = match3.indexOf("", 1);
12877
- 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];
12878
13153
  });
12879
- this.match = match2;
12880
- return match2(method, path);
13154
+ this.match = match;
13155
+ return match(method, path);
12881
13156
  }
12882
13157
  //#endregion
12883
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/node.js
12884
- var LABEL_REG_EXP_STR = "[^/]+";
12885
- var ONLY_WILDCARD_REG_EXP_STR = ".*";
12886
- var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
12887
- var PATH_ERROR = /* @__PURE__ */ Symbol();
12888
- 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
+ */
12889
13171
  function compareKey(a, b) {
12890
13172
  if (a.length === 1) return b.length === 1 ? a < b ? -1 : 1 : -1;
12891
13173
  if (b.length === 1) return 1;
12892
- if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) return 1;
12893
- else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) return -1;
12894
- if (a === LABEL_REG_EXP_STR) return 1;
12895
- 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;
12896
13178
  return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
12897
13179
  }
12898
- var Node$1 = class _Node {
13180
+ var Node$1 = class Node {
12899
13181
  #index;
12900
13182
  #varIndex;
12901
- #children = /* @__PURE__ */ Object.create(null);
12902
- insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
12903
- if (tokens.length === 0) {
12904
- if (this.#index !== void 0) throw PATH_ERROR;
12905
- if (pathErrorCheckOnly) return;
12906
- this.#index = index;
12907
- return;
12908
- }
12909
- const [token, ...restTokens] = tokens;
12910
- const pattern = token === "*" ? restTokens.length === 0 ? [
12911
- "",
12912
- "",
12913
- ONLY_WILDCARD_REG_EXP_STR
12914
- ] : [
12915
- "",
12916
- "",
12917
- LABEL_REG_EXP_STR
12918
- ] : token === "/*" ? [
12919
- "",
12920
- "",
12921
- TAIL_WILDCARD_REG_EXP_STR
12922
- ] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
12923
- let node;
12924
- if (pattern) {
12925
- const name = pattern[1];
12926
- let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
12927
- if (name && pattern[2]) {
12928
- if (regexpStr === ".*") throw PATH_ERROR;
12929
- regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
12930
- if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
12931
- }
12932
- node = this.#children[regexpStr];
12933
- if (!node) {
12934
- if (Object.keys(this.#children).some((k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) throw PATH_ERROR;
12935
- if (pathErrorCheckOnly) return;
12936
- node = this.#children[regexpStr] = new _Node();
12937
- if (name !== "") node.#varIndex = context.varIndex++;
12938
- }
12939
- if (!pathErrorCheckOnly && name !== "") paramMap.push([name, node.#varIndex]);
12940
- } else {
12941
- node = this.#children[token];
12942
- if (!node) {
12943
- 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;
12944
- if (pathErrorCheckOnly) return;
12945
- 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
+ }
12946
13230
  }
13231
+ node = nextNode;
12947
13232
  }
12948
- node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
13233
+ if (node.#index !== void 0) throw PATH_ERROR;
13234
+ node.#index = index;
12949
13235
  }
12950
13236
  buildRegExpStr() {
12951
13237
  const strList = Object.keys(this.#children).sort(compareKey).map((k) => {
12952
13238
  const c = this.#children[k];
12953
- return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
12954
- });
12955
- 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}`);
12956
13243
  if (strList.length === 0) return "";
12957
13244
  if (strList.length === 1) return strList[0];
12958
13245
  return "(?:" + strList.join("|") + ")";
12959
13246
  }
12960
13247
  };
12961
13248
  //#endregion
12962
- //#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
12963
13250
  var Trie = class {
12964
13251
  #context = { varIndex: 0 };
12965
13252
  #root = new Node$1();
12966
- 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
+ }
12967
13266
  const paramAssoc = [];
12968
13267
  const groups = [];
13268
+ let markedPath = path;
12969
13269
  for (let i = 0;;) {
12970
13270
  let replaced = false;
12971
- path = path.replace(/\{[^}]+\}/g, (m) => {
13271
+ markedPath = markedPath.replace(/\{(?:\{[\d,]+\}|[^}])+\}/g, (m) => {
12972
13272
  const mark = `@\\${i}`;
12973
13273
  groups[i] = [mark, m];
12974
13274
  i++;
@@ -12977,7 +13277,12 @@ var Trie = class {
12977
13277
  });
12978
13278
  if (!replaced) break;
12979
13279
  }
12980
- const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
13280
+ /**
13281
+ * - pattern (:label, :label{0-9]+}, ...)
13282
+ * - /* wildcard
13283
+ * - character
13284
+ */
13285
+ const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./gs) || [];
12981
13286
  for (let i = groups.length - 1; i >= 0; i--) {
12982
13287
  const [mark] = groups[i];
12983
13288
  for (let j = tokens.length - 1; j >= 0; j--) if (tokens[j].indexOf(mark) !== -1) {
@@ -12985,8 +13290,12 @@ var Trie = class {
12985
13290
  break;
12986
13291
  }
12987
13292
  }
12988
- this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
12989
- 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
+ ];
12990
13299
  }
12991
13300
  buildRegExp() {
12992
13301
  let regexp = this.#root.buildRegExpStr();
@@ -13017,138 +13326,89 @@ var Trie = class {
13017
13326
  }
13018
13327
  };
13019
13328
  //#endregion
13020
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/router.js
13021
- var nullMatcher = [
13022
- /^$/,
13023
- [],
13024
- /* @__PURE__ */ Object.create(null)
13025
- ];
13026
- var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
13027
- function buildWildcardRegExp(path) {
13028
- return wildcardRegExpCache[path] ??= new RegExp(path === "*" ? "" : `^${path.replace(/\/\*$|([.\\+*[^\]$()])/g, (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)")}$`);
13029
- }
13030
- function clearWildcardRegExpCache() {
13031
- wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
13032
- }
13033
- function buildMatcherFromPreprocessedRoutes(routes) {
13034
- const trie = new Trie();
13035
- const handlerData = [];
13036
- if (routes.length === 0) return nullMatcher;
13037
- const routesWithStaticPathFlag = routes.map((route) => [!/\*|\/:/.test(route[0]), ...route]).sort(([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length);
13038
- const staticMap = /* @__PURE__ */ Object.create(null);
13039
- for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
13040
- const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
13041
- if (pathErrorCheckOnly) staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
13042
- else j++;
13043
- let paramAssoc;
13044
- try {
13045
- paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
13046
- } catch (e) {
13047
- throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
13048
- }
13049
- if (pathErrorCheckOnly) continue;
13050
- handlerData[j] = handlers.map(([h, paramCount]) => {
13051
- const paramIndexMap = /* @__PURE__ */ Object.create(null);
13052
- paramCount -= 1;
13053
- for (; paramCount >= 0; paramCount--) {
13054
- const [key, value] = paramAssoc[paramCount];
13055
- paramIndexMap[key] = value;
13056
- }
13057
- return [h, paramIndexMap];
13058
- });
13059
- }
13060
- const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
13061
- for (let i = 0, len = handlerData.length; i < len; i++) for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
13062
- const map = handlerData[i][j]?.[1];
13063
- if (!map) continue;
13064
- const keys = Object.keys(map);
13065
- for (let k = 0, len3 = keys.length; k < len3; k++) map[keys[k]] = paramReplacementMap[map[keys[k]]];
13066
- }
13067
- const handlerMap = [];
13068
- for (const i in indexReplacementMap) handlerMap[i] = handlerData[indexReplacementMap[i]];
13069
- return [
13070
- regexp,
13071
- handlerMap,
13072
- staticMap
13073
- ];
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 === "(?:|/[^]*)";
13074
13333
  }
13075
- function findMiddleware(middleware, path) {
13076
- if (!middleware) return;
13077
- 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] === "/";
13078
13338
  }
13079
13339
  var RegExpRouter = class {
13080
13340
  name = "RegExpRouter";
13081
- #middleware;
13082
- #routes;
13341
+ #handlers;
13342
+ #tries;
13083
13343
  constructor() {
13084
- this.#middleware = { ["ALL"]: /* @__PURE__ */ Object.create(null) };
13085
- 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
+ }
13086
13353
  }
13087
13354
  add(method, path, handler) {
13088
- const middleware = this.#middleware;
13089
- const routes = this.#routes;
13090
- if (!middleware || !routes) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
13091
- if (!middleware[method]) [middleware, routes].forEach((handlerMap) => {
13092
- handlerMap[method] = /* @__PURE__ */ Object.create(null);
13093
- Object.keys(handlerMap["ALL"]).forEach((p) => {
13094
- handlerMap[method][p] = [...handlerMap["ALL"][p]];
13095
- });
13096
- });
13097
- if (path === "/*") path = "*";
13098
- const paramCount = (path.match(/\/:/g) || []).length;
13099
- if (/\*$/.test(path)) {
13100
- const re = buildWildcardRegExp(path);
13101
- if (method === "ALL") Object.keys(middleware).forEach((m) => {
13102
- middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware["ALL"], path) || [];
13103
- });
13104
- else middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware["ALL"], path) || [];
13105
- Object.keys(middleware).forEach((m) => {
13106
- if (method === "ALL" || method === m) Object.keys(middleware[m]).forEach((p) => {
13107
- re.test(p) && middleware[m][p].push([handler, paramCount]);
13108
- });
13109
- });
13110
- Object.keys(routes).forEach((m) => {
13111
- if (method === "ALL" || method === m) Object.keys(routes[m]).forEach((p) => re.test(p) && routes[m][p].push([handler, paramCount]));
13112
- });
13113
- 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);
13114
13362
  }
13363
+ if (path === "/*") path = "*";
13364
+ const methods = method === "ALL" ? Object.keys(handlers) : [method];
13115
13365
  const paths = checkOptionalParameter(path) || [path];
13116
- for (let i = 0, len = paths.length; i < len; i++) {
13117
- const path2 = paths[i];
13118
- Object.keys(routes).forEach((m) => {
13119
- if (method === "ALL" || method === m) {
13120
- routes[m][path2] ||= [...findMiddleware(middleware[m], path2) || findMiddleware(middleware["ALL"], path2) || []];
13121
- routes[m][path2].push([handler, paramCount - len + i + 1]);
13122
- }
13123
- });
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]);
13124
13369
  }
13125
13370
  }
13126
13371
  match = match;
13127
13372
  buildAllMatchers() {
13128
- const matchers = /* @__PURE__ */ Object.create(null);
13129
- Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
13130
- matchers[method] ||= this.#buildMatcher(method);
13131
- });
13132
- this.#middleware = this.#routes = void 0;
13133
- 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;
13134
13376
  return matchers;
13135
13377
  }
13136
13378
  #buildMatcher(method) {
13137
- const routes = [];
13138
- let hasOwnRoute = method === "ALL";
13139
- [this.#middleware, this.#routes].forEach((r) => {
13140
- const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
13141
- if (ownRoute.length !== 0) {
13142
- hasOwnRoute ||= true;
13143
- routes.push(...ownRoute);
13144
- } 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())];
13145
13391
  });
13146
- if (!hasOwnRoute) return null;
13147
- 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
+ ];
13148
13408
  }
13149
13409
  };
13150
13410
  //#endregion
13151
- //#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
13152
13412
  var SmartRouter = class {
13153
13413
  name = "SmartRouter";
13154
13414
  #routers = [];
@@ -13174,7 +13434,7 @@ var SmartRouter = class {
13174
13434
  for (; i < len; i++) {
13175
13435
  const router = routers[i];
13176
13436
  try {
13177
- 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]);
13178
13438
  res = router.match(method, path);
13179
13439
  } catch (e) {
13180
13440
  if (e instanceof UnsupportedPathError) continue;
@@ -13195,74 +13455,49 @@ var SmartRouter = class {
13195
13455
  }
13196
13456
  };
13197
13457
  //#endregion
13198
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/trie-router/node.js
13199
- var emptyParams = /* @__PURE__ */ Object.create(null);
13200
- var hasChildren = (children) => {
13201
- for (const _ in children) return true;
13202
- return false;
13203
- };
13204
- var Node = class _Node {
13205
- #methods;
13206
- #children;
13207
- #patterns;
13208
- #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;
13209
13466
  #params = emptyParams;
13210
- constructor(method, handler, children) {
13211
- this.#children = children || /* @__PURE__ */ Object.create(null);
13212
- this.#methods = [];
13213
- if (method && handler) {
13214
- const m = /* @__PURE__ */ Object.create(null);
13215
- m[method] = {
13216
- handler,
13217
- possibleKeys: [],
13218
- score: 0
13219
- };
13220
- this.#methods = [m];
13221
- }
13222
- this.#patterns = [];
13223
- }
13224
13467
  insert(method, path, handler) {
13225
- this.#order = ++this.#order;
13226
13468
  let curNode = this;
13227
13469
  const parts = splitRoutingPath(path);
13228
- const possibleKeys = [];
13229
- for (let i = 0, len = parts.length; i < len; i++) {
13230
- const p = parts[i];
13231
- const nextP = parts[i + 1];
13232
- const pattern = getPattern(p, nextP);
13233
- const key = Array.isArray(pattern) ? pattern[0] : p;
13234
- if (key in curNode.#children) {
13235
- curNode = curNode.#children[key];
13236
- if (pattern) possibleKeys.push(pattern[1]);
13237
- continue;
13238
- }
13239
- curNode.#children[key] = new _Node();
13240
- if (pattern) {
13241
- curNode.#patterns.push(pattern);
13242
- 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);
13243
13481
  }
13244
- curNode = curNode.#children[key];
13482
+ curNode = child;
13483
+ if (isParam) possibleKeys.add(pattern[1]);
13245
13484
  }
13246
13485
  curNode.#methods.push({ [method]: {
13247
13486
  handler,
13248
- possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
13249
- score: this.#order
13487
+ possibleKeys: [...possibleKeys],
13488
+ score: ++order
13250
13489
  } });
13251
- return curNode;
13252
13490
  }
13253
13491
  #pushHandlerSets(handlerSets, node, method, nodeParams, params) {
13254
13492
  for (let i = 0, len = node.#methods.length; i < len; i++) {
13255
13493
  const m = node.#methods[i];
13256
13494
  const handlerSet = m[method] || m["ALL"];
13257
- const processedSet = {};
13258
- if (handlerSet !== void 0) {
13259
- handlerSet.params = /* @__PURE__ */ Object.create(null);
13495
+ if (handlerSet) {
13496
+ handlerSet.params = createNullObject();
13260
13497
  handlerSets.push(handlerSet);
13261
- if (nodeParams !== emptyParams || params && params !== emptyParams) for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
13262
- const key = handlerSet.possibleKeys[i2];
13263
- const processed = processedSet[handlerSet.score];
13264
- handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
13265
- 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];
13266
13501
  }
13267
13502
  }
13268
13503
  }
@@ -13289,46 +13524,47 @@ var Node = class _Node {
13289
13524
  this.#pushHandlerSets(handlerSets, nextNode, method, node.#params);
13290
13525
  } else tempNodes.push(nextNode);
13291
13526
  }
13292
- for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
13293
- const pattern = node.#patterns[k];
13527
+ for (const child of node.#patterns) {
13528
+ const pattern = child.#pattern;
13294
13529
  const params = node.#params === emptyParams ? {} : { ...node.#params };
13295
- if (pattern === "*") {
13296
- const astNode = node.#children["*"];
13297
- if (astNode) {
13298
- this.#pushHandlerSets(handlerSets, astNode, method, node.#params);
13299
- astNode.#params = params;
13300
- 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
+ }
13301
13537
  }
13302
13538
  continue;
13303
13539
  }
13304
- const [key, name, matcher] = pattern;
13305
- if (!part && !(matcher instanceof RegExp)) continue;
13306
- const child = node.#children[key];
13307
- if (matcher instanceof RegExp) {
13308
- if (partOffsets === null) {
13309
- partOffsets = new Array(len);
13540
+ const [, name, matcher] = pattern;
13541
+ if (!part && matcher === true) continue;
13542
+ if (matcher !== true) {
13543
+ if (!partOffsets) {
13544
+ partOffsets = [];
13310
13545
  let offset = path[0] === "/" ? 1 : 0;
13311
13546
  for (let p = 0; p < len; p++) {
13312
13547
  partOffsets[p] = offset;
13313
13548
  offset += parts[p].length + 1;
13314
13549
  }
13315
13550
  }
13316
- const restPathString = path.substring(partOffsets[i]);
13551
+ const restPathString = path.slice(partOffsets[i]);
13317
13552
  const m = matcher.exec(restPathString);
13318
13553
  if (m) {
13319
- params[name] = m[0];
13554
+ if (!Object.hasOwn(params, name)) params[name] = m[0];
13320
13555
  this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
13321
13556
  if (m[0].length === restPathString.length && child.#children["*"]) this.#pushHandlerSets(handlerSets, child.#children["*"], method, node.#params, params);
13322
- if (hasChildren(child.#children)) {
13557
+ for (const _ in child.#children) {
13323
13558
  child.#params = params;
13324
- const componentCount = m[0].match(/\//)?.length ?? 0;
13559
+ const componentCount = m[0].match(/\//g)?.length ?? 0;
13325
13560
  (curNodesQueue[componentCount] ||= []).push(child);
13561
+ break;
13326
13562
  }
13327
13563
  continue;
13328
13564
  }
13329
13565
  }
13330
13566
  if (matcher === true || matcher.test(part)) {
13331
- params[name] = part;
13567
+ if (!Object.hasOwn(params, name)) params[name] = part;
13332
13568
  if (isLast) {
13333
13569
  this.#pushHandlerSets(handlerSets, child, method, params, node.#params);
13334
13570
  if (child.#children["*"]) this.#pushHandlerSets(handlerSets, child.#children["*"], method, params, node.#params);
@@ -13342,34 +13578,34 @@ var Node = class _Node {
13342
13578
  const shifted = curNodesQueue.shift();
13343
13579
  curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
13344
13580
  }
13345
- if (handlerSets.length > 1) handlerSets.sort((a, b) => {
13581
+ if (handlerSets[1]) handlerSets.sort((a, b) => {
13346
13582
  return a.score - b.score;
13347
13583
  });
13348
13584
  return [handlerSets.map(({ handler, params }) => [handler, params])];
13349
13585
  }
13350
13586
  };
13351
13587
  //#endregion
13352
- //#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
13353
13589
  var TrieRouter = class {
13354
13590
  name = "TrieRouter";
13355
- #node;
13356
- constructor() {
13357
- this.#node = new Node();
13358
- }
13591
+ #node = new Node();
13359
13592
  add(method, path, handler) {
13360
- const results = checkOptionalParameter(path);
13361
- if (results) {
13362
- for (let i = 0, len = results.length; i < len; i++) this.#node.insert(method, results[i], handler);
13363
- return;
13364
- }
13365
- this.#node.insert(method, path, handler);
13593
+ for (const result of checkOptionalParameter(path) || [path]) this.#node.insert(method, result, handler);
13366
13594
  }
13367
13595
  match(method, path) {
13368
13596
  return this.#node.search(method, path);
13369
13597
  }
13370
13598
  };
13371
13599
  //#endregion
13372
- //#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
+ */
13373
13609
  var Hono = class extends Hono$1 {
13374
13610
  /**
13375
13611
  * Creates an instance of the Hono class.
@@ -13382,14 +13618,14 @@ var Hono = class extends Hono$1 {
13382
13618
  }
13383
13619
  };
13384
13620
  //#endregion
13385
- //#region ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/encode.js
13386
- var encodeBase64 = (buf) => {
13621
+ //#region ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/encode.js
13622
+ const encodeBase64 = (buf) => {
13387
13623
  let binary = "";
13388
13624
  const bytes = new Uint8Array(buf);
13389
13625
  for (let i = 0, len = bytes.length; i < len; i++) binary += String.fromCharCode(bytes[i]);
13390
13626
  return btoa(binary);
13391
13627
  };
13392
- var decodeBase64 = (str) => {
13628
+ const decodeBase64 = (str) => {
13393
13629
  const binary = atob(str);
13394
13630
  const bytes = new Uint8Array(new ArrayBuffer(binary.length));
13395
13631
  const half = binary.length / 2;
@@ -13400,9 +13636,13 @@ var decodeBase64 = (str) => {
13400
13636
  return bytes;
13401
13637
  };
13402
13638
  //#endregion
13403
- //#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
13404
13640
  globalThis.crypto ??= node_crypto.default;
13405
- 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) => {
13406
13646
  const cfHeaders = {};
13407
13647
  headers.forEach((value, key) => {
13408
13648
  cfHeaders[key.toLowerCase()] = [...cfHeaders[key.toLowerCase()] || [], {
@@ -13412,12 +13652,16 @@ var convertHeaders = (headers) => {
13412
13652
  });
13413
13653
  return cfHeaders;
13414
13654
  };
13415
- 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) => {
13416
13659
  return async (event, ...args) => {
13417
13660
  const [context, callback] = args;
13418
13661
  let callbackError = null;
13419
13662
  let callbackResult;
13420
- const res = await app.fetch(createRequest(event), {
13663
+ const cf = getCloudFrontRecord(event);
13664
+ const res = await app.fetch(createRequest(cf), {
13421
13665
  event,
13422
13666
  context,
13423
13667
  callback: (err, result) => {
@@ -13427,18 +13671,22 @@ var handle = (app) => {
13427
13671
  }
13428
13672
  callback?.(err, result);
13429
13673
  },
13430
- config: event.Records[0].cf.config,
13431
- request: event.Records[0].cf.request,
13432
- response: event.Records[0].cf.response
13674
+ config: cf.config,
13675
+ request: cf.request,
13676
+ response: cf.response
13433
13677
  });
13434
13678
  if (callbackError) throw callbackError;
13435
13679
  return callbackResult ?? createResult(res);
13436
13680
  };
13437
13681
  };
13438
- var createResult = async (res) => {
13682
+ const createResult = async (res) => {
13683
+ if (res.status === 204) return {
13684
+ status: "204",
13685
+ headers: convertHeaders(res.headers)
13686
+ };
13439
13687
  const contentEncoding = res.headers.get("content-encoding");
13440
13688
  const isBase64Encoded = isContentTypeBinary(res.headers.get("content-type") || "") || !!contentEncoding && !/^identity$/i.test(contentEncoding);
13441
- 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());
13442
13690
  return {
13443
13691
  status: res.status.toString(),
13444
13692
  headers: convertHeaders(res.headers),
@@ -13446,16 +13694,30 @@ var createResult = async (res) => {
13446
13694
  ...isBase64Encoded && { bodyEncoding: "base64" }
13447
13695
  };
13448
13696
  };
13449
- var createRequest = (event) => {
13450
- const queryString = event.Records[0].cf.request.querystring;
13451
- 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}`;
13452
13714
  const url = queryString ? `${urlPath}?${queryString}` : urlPath;
13453
13715
  const headers = new Headers();
13454
- Object.entries(event.Records[0].cf.request.headers).forEach(([k, v]) => {
13716
+ Object.entries(request.headers ?? {}).forEach(([k, v]) => {
13455
13717
  v.forEach((header) => headers.append(k, header.value));
13456
13718
  });
13457
- const requestBody = event.Records[0].cf.request.body;
13458
- const method = event.Records[0].cf.request.method;
13719
+ const requestBody = request.body;
13720
+ const method = request.method;
13459
13721
  const rawBody = createBody(method, requestBody);
13460
13722
  let body = rawBody;
13461
13723
  if (rawBody !== void 0) {
@@ -13469,14 +13731,21 @@ var createRequest = (event) => {
13469
13731
  body
13470
13732
  });
13471
13733
  };
13472
- 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) => {
13473
13738
  if (!requestBody || !requestBody.data) return;
13474
13739
  if (method === "GET" || method === "HEAD") return;
13475
13740
  if (requestBody.encoding === "base64") return decodeBase64(requestBody.data);
13476
13741
  return requestBody.data;
13477
13742
  };
13478
- var isContentTypeBinary = (contentType) => {
13479
- 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);
13480
13749
  };
13481
13750
  //#endregion
13482
13751
  //#region src/runtimeAwsConfig.ts