@hot-updater/cloudflare 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.
@@ -1877,8 +1877,8 @@ var verifyRows = /* @__PURE__ */ __name((table, request, rows) => {
1877
1877
  if (!matchesQuery(table, index, request, row)) fail(`${table.name}.${index.name} returned a row outside the request.`);
1878
1878
  const tuple = indexOrderTuple(table, index, row);
1879
1879
  if (previous !== void 0) {
1880
- const order = compareTuples(previous, tuple);
1881
- if (request.order === "asc" ? order >= 0 : order <= 0) fail(`${table.name}.${index.name} returned rows out of order.`);
1880
+ const order2 = compareTuples(previous, tuple);
1881
+ if (request.order === "asc" ? order2 >= 0 : order2 <= 0) fail(`${table.name}.${index.name} returned rows out of order.`);
1882
1882
  }
1883
1883
  previous = tuple;
1884
1884
  }
@@ -2221,8 +2221,8 @@ var pruneStatements = /* @__PURE__ */ __name((dialect, table, tablePrefix, limit
2221
2221
  const quote = /* @__PURE__ */ __name((name2) => quoteSql(dialect, name2), "quote");
2222
2222
  const name = quote(`${tablePrefix}${table.name}`);
2223
2223
  const at = quote(table.retention.column);
2224
- const order = retentionOrder(table).columns.map(quote);
2225
- const list = /* @__PURE__ */ __name((alias, direction = "") => order.map((column) => `${alias}.${column}${direction}`).join(", "), "list");
2224
+ const order2 = retentionOrder(table).columns.map(quote);
2225
+ const list = /* @__PURE__ */ __name((alias, direction = "") => order2.map((column) => `${alias}.${column}${direction}`).join(", "), "list");
2226
2226
  const oldest = /* @__PURE__ */ __name((before) => `SELECT ${list("i")} FROM ${name} i WHERE i.${at} <= ${before()} ORDER BY ${list("i", " ASC")} LIMIT ${limit}`, "oldest");
2227
2227
  const doomed = /* @__PURE__ */ __name((alias, before) => `(${list(alias)}) <= (SELECT ${list("b")} FROM (${oldest(before)}) b ORDER BY ${list("b", " DESC")} LIMIT 1) AND ${alias}.${at} <= ${before()}`, "doomed");
2228
2228
  const entries = table.indexes.filter((index) => isMultiIndex(table, index)).map((index) => quote(`${tablePrefix}${table.name}__${index.name}`));
@@ -2235,7 +2235,7 @@ var pruneStatements = /* @__PURE__ */ __name((dialect, table, tablePrefix, limit
2235
2235
  const into = quote(`${tablePrefix}${table.name}__${index.name}`);
2236
2236
  return (before) => `DELETE FROM ${into} WHERE (${columns.map(quote).join(", ")}) IN (SELECT ${values.join(", ")} FROM ${name} b${each.join("")} WHERE ${doomed("b", before)})`;
2237
2237
  }), (before) => `DELETE FROM ${name} WHERE ${doomed(name, before)}`];
2238
- if (dialect === "mysql") return [...entries.map((index) => (before) => `DELETE e FROM ${index} e JOIN (${oldest(before)}) d ON ${keyOf("e", "d")}`), (before) => `DELETE FROM ${name} WHERE ${at} <= ${before()} ORDER BY ${order.join(", ")} LIMIT ${limit}`];
2238
+ if (dialect === "mysql") return [...entries.map((index) => (before) => `DELETE e FROM ${index} e JOIN (${oldest(before)}) d ON ${keyOf("e", "d")}`), (before) => `DELETE FROM ${name} WHERE ${at} <= ${before()} ORDER BY ${order2.join(", ")} LIMIT ${limit}`];
2239
2239
  return [...entries.map((index) => (before) => `DELETE FROM ${index} WHERE EXISTS (SELECT * FROM ${name} b WHERE ${keyOf("b", index)} AND ${doomed("b", before)})`), (before) => `DELETE FROM ${name} WHERE ${doomed(name, before)}`];
2240
2240
  }, "pruneStatements");
2241
2241
 
@@ -4055,7 +4055,7 @@ var createEngineReads = /* @__PURE__ */ __name(({ adapter, schema, maxPageSize:
4055
4055
  if (index === void 0) throw new DatabaseQueryError(`${table.name} has no index ${input.index}.`);
4056
4056
  const where = input.where ?? {};
4057
4057
  if (!sameFields(Object.keys(where), index.eq)) throw new DatabaseQueryError(`${table.name}.${index.name} reads need where on exactly: ${index.eq.join(", ") || "(none)"}.`);
4058
- const { limit, order = "asc", range } = input;
4058
+ const { limit, order: order2 = "asc", range } = input;
4059
4059
  if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxPageSize) throw new DatabaseQueryError(`limit must be 1\u2013${maxPageSize}.`);
4060
4060
  const columns = indexOrderColumns(table, index);
4061
4061
  const eq = index.eq.map((field) => keyValue(where[field], `${table.name}.${field}`));
@@ -4063,14 +4063,14 @@ var createEngineReads = /* @__PURE__ */ __name(({ adapter, schema, maxPageSize:
4063
4063
  table.name,
4064
4064
  index.name,
4065
4065
  eq,
4066
- order,
4066
+ order2,
4067
4067
  range
4068
4068
  ]);
4069
4069
  let lower = bound(range?.gt, range?.gte, columns);
4070
4070
  let upper = bound(range?.lt, range?.lte, columns);
4071
4071
  if (input.cursor !== void 0) {
4072
4072
  const values = decodeCursor(scope, input.cursor);
4073
- if (order === "asc") lower = {
4073
+ if (order2 === "asc") lower = {
4074
4074
  values,
4075
4075
  inclusive: false
4076
4076
  };
@@ -4083,7 +4083,7 @@ var createEngineReads = /* @__PURE__ */ __name(({ adapter, schema, maxPageSize:
4083
4083
  request: {
4084
4084
  index: index.name,
4085
4085
  eq,
4086
- order,
4086
+ order: order2,
4087
4087
  limit,
4088
4088
  ...lower === void 0 ? {} : { lower },
4089
4089
  ...upper === void 0 ? {} : { upper }
@@ -4420,9 +4420,9 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4420
4420
  if (!isMultiIndex(table, index) || changed && !columns.some((column) => changed.includes(column))) return [];
4421
4421
  const into = tableOf(table, index);
4422
4422
  const found = row ? indexEntries(table, index, row) : [];
4423
- const order = found.length > 0 ? indexOrderTuple(table, index, row) : [];
4423
+ const order2 = found.length > 0 ? indexOrderTuple(table, index, row) : [];
4424
4424
  return [...stale ? [sql((bind) => `DELETE FROM ${into} WHERE ${where(bind, key)}`)] : [], ...found.map((eq) => sql((bind) => {
4425
- const values = [...eq, ...order].map((value) => bind(value));
4425
+ const values = [...eq, ...order2].map((value) => bind(value));
4426
4426
  return insert(bind, into, columns, values);
4427
4427
  }))];
4428
4428
  }), "entries");
@@ -4511,17 +4511,17 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4511
4511
  async query(table, request) {
4512
4512
  const index = findPhysicalIndex(table, request.index);
4513
4513
  if (!Number.isSafeInteger(request.limit) || request.limit < 1) throw new RangeError("query limit must be a positive integer.");
4514
- const order = indexOrderColumns(table, index);
4514
+ const order2 = indexOrderColumns(table, index);
4515
4515
  const multi = isMultiIndex(table, index);
4516
4516
  const source = multi ? `${tableOf(table, index)} i JOIN ${tableOf(table)} b ON ${table.key.map((column) => `b.${quote(column)} = i.${quote(column)}`).join(" AND ")}` : `${tableOf(table)} i`;
4517
4517
  const direction = request.order === "asc" ? "ASC" : "DESC";
4518
4518
  const statement = sql((bind) => {
4519
4519
  const conditions = [
4520
4520
  ...index.eq.map((column, position) => `i.${quote(column)} = ${bind(request.eq[position])}`),
4521
- ...request.lower ? [compare2(bind, order, request.lower, ">")] : [],
4522
- ...request.upper ? [compare2(bind, order, request.upper, "<")] : []
4521
+ ...request.lower ? [compare2(bind, order2, request.lower, ">")] : [],
4522
+ ...request.upper ? [compare2(bind, order2, request.upper, "<")] : []
4523
4523
  ];
4524
- return `SELECT ${multi ? "b" : "i"}.* FROM ${source}${conditions.length > 0 ? ` WHERE ${conditions.join(" AND ")}` : ""} ORDER BY ${order.map((column) => `i.${quote(column)} ${direction}`).join(", ")} LIMIT ${request.limit}`;
4524
+ return `SELECT ${multi ? "b" : "i"}.* FROM ${source}${conditions.length > 0 ? ` WHERE ${conditions.join(" AND ")}` : ""} ORDER BY ${order2.map((column) => `i.${quote(column)} ${direction}`).join(", ")} LIMIT ${request.limit}`;
4525
4525
  });
4526
4526
  return read(table, statement);
4527
4527
  },
@@ -4587,7 +4587,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4587
4587
  }, "createSqlAdapter");
4588
4588
 
4589
4589
  // ../../packages/server/dist/package.mjs
4590
- var version = "1.1.20";
4590
+ var version = "1.1.22";
4591
4591
 
4592
4592
  // ../../packages/server/dist/version.mjs
4593
4593
  var HOT_UPDATER_SERVER_VERSION = version;
@@ -6466,14 +6466,14 @@ var LIMITS = {
6466
6466
  maxValue: 500
6467
6467
  };
6468
6468
  var keyset = /* @__PURE__ */ __name((url, maxValue = LIMITS.maxValue) => {
6469
- const order = url.searchParams.get("order") ?? "desc";
6470
- if (order !== "asc" && order !== "desc") throw new HandlerBadRequestError("order must be 'asc' or 'desc'.");
6469
+ const order2 = url.searchParams.get("order") ?? "desc";
6470
+ if (order2 !== "asc" && order2 !== "desc") throw new HandlerBadRequestError("order must be 'asc' or 'desc'.");
6471
6471
  const limitParam = url.searchParams.get("limit");
6472
6472
  const limit = limitParam === null ? Math.min(LIMITS.defaultValue, maxValue) : Number(limitParam);
6473
6473
  if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxValue) throw new HandlerBadRequestError(`limit must be between 1 and ${maxValue}.`);
6474
6474
  const cursor = url.searchParams.get("cursor");
6475
6475
  return {
6476
- order,
6476
+ order: order2,
6477
6477
  limit,
6478
6478
  ...cursor === null ? {} : { after: cursor }
6479
6479
  };
@@ -7048,7 +7048,8 @@ var createRequestHandler = /* @__PURE__ */ __name(({ api, clientPolicy, privateR
7048
7048
  let authenticated;
7049
7049
  try {
7050
7050
  authenticated = await clientPolicy.authenticate(request);
7051
- } catch {
7051
+ } catch (error) {
7052
+ console.error("Hot Updater client authentication error:", error);
7052
7053
  return errorResponse("Service unavailable", 503);
7053
7054
  }
7054
7055
  if (!authenticated) return errorResponse("Unauthorized", 401);
@@ -11030,163 +11031,119 @@ var remoteConfig = /* @__PURE__ */ __name(() => {
11030
11031
  // worker/src/index.ts
11031
11032
  import { env } from "cloudflare:workers";
11032
11033
 
11033
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/compose.js
11034
- var compose = /* @__PURE__ */ __name((middleware, onError, onNotFound) => {
11035
- return (context, next) => {
11036
- let index = -1;
11037
- return dispatch(0);
11038
- async function dispatch(i) {
11039
- if (i <= index) {
11040
- throw new Error("next() called multiple times");
11041
- }
11042
- index = i;
11043
- let res;
11044
- let isError = false;
11045
- let handler;
11046
- if (middleware[i]) {
11047
- handler = middleware[i][0][0];
11048
- context.req.routeIndex = i;
11049
- } else {
11050
- handler = i === middleware.length && next || void 0;
11051
- }
11052
- if (handler) {
11053
- try {
11054
- res = await handler(context, () => dispatch(i + 1));
11055
- } catch (err) {
11056
- if (err instanceof Error && onError) {
11057
- context.error = err;
11058
- res = await onError(err, context);
11059
- isError = true;
11060
- } else {
11061
- throw err;
11062
- }
11063
- }
11064
- } else {
11065
- if (context.finalized === false && onNotFound) {
11066
- res = await onNotFound(context);
11067
- }
11068
- }
11069
- if (res && (context.finalized === false || isError)) {
11070
- context.res = res;
11071
- }
11072
- return context;
11073
- }
11074
- __name(dispatch, "dispatch");
11075
- };
11076
- }, "compose");
11034
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/http-exception.js
11035
+ var HTTPException = class extends Error {
11036
+ static {
11037
+ __name(this, "HTTPException");
11038
+ }
11039
+ res;
11040
+ status;
11041
+ /**
11042
+ * Creates an instance of `HTTPException`.
11043
+ * @param status - HTTP status code for the exception. Defaults to 500.
11044
+ * @param options - Additional options for the exception.
11045
+ */
11046
+ constructor(status = 500, options) {
11047
+ super(options?.message, { cause: options?.cause });
11048
+ this.res = options?.res;
11049
+ this.status = status;
11050
+ }
11051
+ /**
11052
+ * Returns the response object associated with the exception.
11053
+ * If a response object is not provided, a new response is created with the error message and status code.
11054
+ * @returns The response object.
11055
+ */
11056
+ getResponse() {
11057
+ if (this.res) return new Response(this.res.body, {
11058
+ status: this.status,
11059
+ headers: this.res.headers
11060
+ });
11061
+ return new Response(this.message, { status: this.status });
11062
+ }
11063
+ };
11077
11064
 
11078
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/request/constants.js
11065
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/request/constants.js
11079
11066
  var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
11080
11067
 
11081
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/buffer.js
11068
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/buffer.js
11082
11069
  var bufferToFormData = /* @__PURE__ */ __name((arrayBuffer, contentType) => {
11083
- const response = new Response(arrayBuffer, {
11084
- headers: {
11085
- // Normalize the media type (case-insensitive) while keeping parameters like the boundary
11086
- "Content-Type": contentType.replace(/^[^;]+/, (mediaType) => mediaType.toLowerCase())
11087
- }
11088
- });
11089
- return response.formData();
11070
+ return new Response(arrayBuffer, { headers: { "Content-Type": contentType.replace(/^[^;]+/, (mediaType) => mediaType.toLowerCase()) } }).formData();
11090
11071
  }, "bufferToFormData");
11091
11072
 
11092
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/body.js
11073
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/body.js
11074
+ var MAX_NESTED_OBJECTS = 1e4;
11093
11075
  var isRawRequest = /* @__PURE__ */ __name((request) => "headers" in request, "isRawRequest");
11094
11076
  var parseBody = /* @__PURE__ */ __name(async (request, options = /* @__PURE__ */ Object.create(null)) => {
11095
11077
  const { all = false, dot = false } = options;
11096
- const headers = isRawRequest(request) ? request.headers : request.raw.headers;
11097
- const contentType = headers.get("Content-Type");
11098
- const mediaType = contentType?.split(";")[0].trim().toLowerCase();
11099
- if (mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded") {
11100
- return parseFormData(request, { all, dot });
11101
- }
11078
+ const mediaType = (isRawRequest(request) ? request.headers : request.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();
11079
+ if (mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded") return parseFormData(request, {
11080
+ all,
11081
+ dot
11082
+ });
11102
11083
  return {};
11103
11084
  }, "parseBody");
11104
11085
  async function parseFormData(request, options) {
11105
- if (!isRawRequest(request) && request.bodyCache.formData) {
11106
- return convertFormDataToBodyData(
11107
- await request.bodyCache.formData,
11108
- options
11109
- );
11110
- }
11086
+ if (!isRawRequest(request) && request.bodyCache.formData) return convertFormDataToBodyData(await request.bodyCache.formData, options);
11111
11087
  const headers = isRawRequest(request) ? request.headers : request.raw.headers;
11112
11088
  const arrayBuffer = await request.arrayBuffer();
11113
11089
  const formDataPromise = bufferToFormData(arrayBuffer, headers.get("Content-Type") || "");
11114
- if (!isRawRequest(request)) {
11115
- request.bodyCache.formData = formDataPromise;
11116
- }
11090
+ if (!isRawRequest(request)) request.bodyCache.formData = formDataPromise;
11117
11091
  const formData = await formDataPromise;
11118
- if (formData) {
11119
- return convertFormDataToBodyData(formData, options);
11120
- }
11092
+ if (formData) return convertFormDataToBodyData(formData, options);
11121
11093
  return {};
11122
11094
  }
11123
11095
  __name(parseFormData, "parseFormData");
11124
11096
  function convertFormDataToBodyData(formData, options) {
11125
11097
  const form = /* @__PURE__ */ Object.create(null);
11098
+ const nestingState = { count: 0 };
11126
11099
  formData.forEach((value, key) => {
11127
- const shouldParseAllValues = options.all || key.endsWith("[]");
11128
- if (!shouldParseAllValues) {
11129
- form[key] = value;
11130
- } else {
11131
- handleParsingAllValues(form, key, value);
11100
+ if (!(options.all || key.endsWith("[]"))) form[key] = value;
11101
+ else handleParsingAllValues(form, key, value);
11102
+ });
11103
+ if (options.dot) Object.entries(form).forEach(([key, value]) => {
11104
+ if (key.includes(".")) {
11105
+ handleParsingNestedValues(form, key, value, nestingState);
11106
+ delete form[key];
11132
11107
  }
11133
11108
  });
11134
- if (options.dot) {
11135
- Object.entries(form).forEach(([key, value]) => {
11136
- const shouldParseDotValues = key.includes(".");
11137
- if (shouldParseDotValues) {
11138
- handleParsingNestedValues(form, key, value);
11139
- delete form[key];
11140
- }
11141
- });
11142
- }
11143
11109
  return form;
11144
11110
  }
11145
11111
  __name(convertFormDataToBodyData, "convertFormDataToBodyData");
11146
11112
  var handleParsingAllValues = /* @__PURE__ */ __name((form, key, value) => {
11147
11113
  if (form[key] !== void 0) {
11148
- if (Array.isArray(form[key])) {
11149
- ;
11150
- form[key].push(value);
11151
- } else {
11152
- form[key] = [form[key], value];
11153
- }
11154
- } else {
11155
- if (!key.endsWith("[]")) {
11156
- form[key] = value;
11157
- } else {
11158
- form[key] = [value];
11159
- }
11160
- }
11114
+ if (Array.isArray(form[key])) form[key].push(value);
11115
+ else form[key] = [form[key], value];
11116
+ } else if (!key.endsWith("[]")) form[key] = value;
11117
+ else form[key] = [value];
11161
11118
  }, "handleParsingAllValues");
11162
- var handleParsingNestedValues = /* @__PURE__ */ __name((form, key, value) => {
11163
- if (/(?:^|\.)__proto__\./.test(key)) {
11164
- return;
11165
- }
11119
+ var handleParsingNestedValues = /* @__PURE__ */ __name((form, key, value, state) => {
11120
+ if (/(?:^|\.)__proto__\./.test(key)) return;
11166
11121
  let nestedForm = form;
11167
- const keys = key.split(".");
11122
+ const keys = key.split(".", 34);
11123
+ if (keys.length > 33) throwNestingLimitExceeded();
11168
11124
  keys.forEach((key2, index) => {
11169
- if (index === keys.length - 1) {
11170
- nestedForm[key2] = value;
11171
- } else {
11125
+ if (index === keys.length - 1) nestedForm[key2] = value;
11126
+ else {
11172
11127
  if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
11128
+ if (state.count++ >= MAX_NESTED_OBJECTS) throwNestingLimitExceeded();
11173
11129
  nestedForm[key2] = /* @__PURE__ */ Object.create(null);
11174
11130
  }
11175
11131
  nestedForm = nestedForm[key2];
11176
11132
  }
11177
11133
  });
11178
11134
  }, "handleParsingNestedValues");
11135
+ var throwNestingLimitExceeded = /* @__PURE__ */ __name(() => {
11136
+ throw new Error("Nesting limit exceeded");
11137
+ }, "throwNestingLimitExceeded");
11179
11138
 
11180
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/url.js
11139
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/url.js
11181
11140
  var splitPath = /* @__PURE__ */ __name((path) => {
11182
11141
  const paths = path.split("/");
11183
- if (paths[0] === "") {
11184
- paths.shift();
11185
- }
11142
+ if (paths[0] === "") paths.shift();
11186
11143
  return paths;
11187
11144
  }, "splitPath");
11188
- var splitRoutingPath = /* @__PURE__ */ __name((routePath) => {
11189
- const { groups, path } = extractGroupsFromPath(routePath);
11145
+ var splitRoutingPath = /* @__PURE__ */ __name((routePath2) => {
11146
+ const { groups, path } = extractGroupsFromPath(routePath2);
11190
11147
  const paths = splitPath(path);
11191
11148
  return replaceGroupMarks(paths, groups);
11192
11149
  }, "splitRoutingPath");
@@ -11197,34 +11154,42 @@ var extractGroupsFromPath = /* @__PURE__ */ __name((path) => {
11197
11154
  groups.push([mark, match2]);
11198
11155
  return mark;
11199
11156
  });
11200
- return { groups, path };
11157
+ return {
11158
+ groups,
11159
+ path
11160
+ };
11201
11161
  }, "extractGroupsFromPath");
11202
11162
  var replaceGroupMarks = /* @__PURE__ */ __name((paths, groups) => {
11203
11163
  for (let i = groups.length - 1; i >= 0; i--) {
11204
11164
  const [mark] = groups[i];
11205
- for (let j = paths.length - 1; j >= 0; j--) {
11206
- if (paths[j].includes(mark)) {
11207
- paths[j] = paths[j].replace(mark, groups[i][1]);
11208
- break;
11209
- }
11165
+ for (let j = paths.length - 1; j >= 0; j--) if (paths[j].includes(mark)) {
11166
+ paths[j] = paths[j].replace(mark, groups[i][1]);
11167
+ break;
11210
11168
  }
11211
11169
  }
11212
11170
  return paths;
11213
11171
  }, "replaceGroupMarks");
11214
11172
  var patternCache = {};
11215
11173
  var getPattern = /* @__PURE__ */ __name((label, next) => {
11216
- if (label === "*") {
11217
- return "*";
11218
- }
11174
+ if (label === "*") return "*";
11219
11175
  const match2 = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
11220
11176
  if (match2) {
11221
11177
  const cacheKey = `${label}#${next}`;
11222
11178
  if (!patternCache[cacheKey]) {
11223
- if (match2[2]) {
11224
- patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match2[1], new RegExp(`^${match2[2]}(?=/${next})`)] : [label, match2[1], new RegExp(`^${match2[2]}$`)];
11225
- } else {
11226
- patternCache[cacheKey] = [label, match2[1], true];
11227
- }
11179
+ if (match2[2]) patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [
11180
+ cacheKey,
11181
+ match2[1],
11182
+ new RegExp(`^${match2[2]}(?=/${next})`)
11183
+ ] : [
11184
+ label,
11185
+ match2[1],
11186
+ new RegExp(`^${match2[2]}$`)
11187
+ ];
11188
+ else patternCache[cacheKey] = [
11189
+ label,
11190
+ match2[1],
11191
+ true
11192
+ ];
11228
11193
  }
11229
11194
  return patternCache[cacheKey];
11230
11195
  }
@@ -11243,7 +11208,7 @@ var tryDecode = /* @__PURE__ */ __name((str, decoder2) => {
11243
11208
  });
11244
11209
  }
11245
11210
  }, "tryDecode");
11246
- var tryDecodeURI = /* @__PURE__ */ __name((str) => tryDecode(str, decodeURI), "tryDecodeURI");
11211
+ var decodeURIWithPreservedPercent = /* @__PURE__ */ __name((value) => decodeURI(value.includes("%25") ? value.replace(/%25/g, "%2525") : value), "decodeURIWithPreservedPercent");
11247
11212
  var getPath = /* @__PURE__ */ __name((request) => {
11248
11213
  const url = request.url;
11249
11214
  const start = url.indexOf("/", url.indexOf(":") + 4);
@@ -11255,10 +11220,14 @@ var getPath = /* @__PURE__ */ __name((request) => {
11255
11220
  const hashIndex = url.indexOf("#", i);
11256
11221
  const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
11257
11222
  const path = url.slice(start, end);
11258
- return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
11259
- } else if (charCode === 63 || charCode === 35) {
11260
- break;
11261
- }
11223
+ const decoded = tryDecode(path, decodeURIWithPreservedPercent);
11224
+ if (/%(?![0-9A-Fa-f]{2})/.test(path)) {
11225
+ const rewritten = new URL("http://localhost");
11226
+ rewritten.pathname = decoded.replace(/[\\\t\n\r]/g, encodeURIComponent);
11227
+ if (tryDecode(rewritten.pathname, decodeURIWithPreservedPercent) !== decoded) return tryDecode(path.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"), decodeURIWithPreservedPercent);
11228
+ }
11229
+ return decoded;
11230
+ } else if (charCode === 63 || charCode === 35) break;
11262
11231
  }
11263
11232
  return url.slice(start, i);
11264
11233
  }, "getPath");
@@ -11267,72 +11236,57 @@ var getPathNoStrict = /* @__PURE__ */ __name((request) => {
11267
11236
  return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
11268
11237
  }, "getPathNoStrict");
11269
11238
  var mergePath = /* @__PURE__ */ __name((base, sub, ...rest) => {
11270
- if (rest.length) {
11271
- sub = mergePath(sub, ...rest);
11272
- }
11239
+ if (rest.length) sub = mergePath(sub, ...rest);
11273
11240
  return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
11274
11241
  }, "mergePath");
11275
11242
  var checkOptionalParameter = /* @__PURE__ */ __name((path) => {
11276
- if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) {
11277
- return null;
11278
- }
11243
+ if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) return null;
11279
11244
  const segments = path.split("/");
11280
11245
  const results = [];
11281
11246
  let basePath = "";
11282
11247
  segments.forEach((segment) => {
11283
- if (segment !== "" && !/\:/.test(segment)) {
11284
- basePath += "/" + segment;
11285
- } else if (/\:/.test(segment)) {
11286
- if (/\?/.test(segment)) {
11287
- if (results.length === 0 && basePath === "") {
11288
- results.push("/");
11289
- } else {
11290
- results.push(basePath);
11291
- }
11292
- const optionalSegment = segment.replace("?", "");
11248
+ if (segment !== "" && !/\:/.test(segment)) basePath += "/" + segment;
11249
+ else if (/\:/.test(segment)) {
11250
+ if (segment.charCodeAt(segment.length - 1) === 63) {
11251
+ if (results.length === 0 && basePath === "") results.push("/");
11252
+ else results.push(basePath);
11253
+ const optionalSegment = segment.slice(0, -1);
11293
11254
  basePath += "/" + optionalSegment;
11294
11255
  results.push(basePath);
11295
- } else {
11296
- basePath += "/" + segment;
11297
- }
11256
+ } else basePath += "/" + segment;
11298
11257
  }
11299
11258
  });
11300
11259
  return results.filter((v, i, a) => a.indexOf(v) === i);
11301
11260
  }, "checkOptionalParameter");
11261
+ var tryDecodeURIComponent = /* @__PURE__ */ __name((str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str, "tryDecodeURIComponent");
11302
11262
  var _decodeURI = /* @__PURE__ */ __name((value) => {
11303
- if (!/[%+]/.test(value)) {
11304
- return value;
11305
- }
11306
- if (value.indexOf("+") !== -1) {
11307
- value = value.replace(/\+/g, " ");
11308
- }
11309
- return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
11263
+ if (value.indexOf("+") !== -1) value = value.replace(/\+/g, " ");
11264
+ return tryDecodeURIComponent(value);
11310
11265
  }, "_decodeURI");
11311
11266
  var _getQueryParam = /* @__PURE__ */ __name((url, key, multiple) => {
11267
+ const hashIndex = url.indexOf("#", 8);
11268
+ if (hashIndex !== -1) url = url.slice(0, hashIndex);
11312
11269
  let encoded;
11313
- if (!multiple && key && !/[%+]/.test(key)) {
11314
- let keyIndex2 = url.indexOf("?", 8);
11315
- if (keyIndex2 === -1) {
11316
- return void 0;
11317
- }
11318
- if (!url.startsWith(key, keyIndex2 + 1)) {
11319
- keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
11320
- }
11270
+ if (!multiple && key && !/[%+&=]/.test(key)) {
11271
+ const queryIndex = url.indexOf("?", 8);
11272
+ let keyIndex2 = queryIndex;
11273
+ if (keyIndex2 === -1) return;
11274
+ if (!url.startsWith(key, keyIndex2 + 1)) keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
11321
11275
  while (keyIndex2 !== -1) {
11322
11276
  const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
11323
- if (trailingKeyCode === 61) {
11324
- const valueIndex = keyIndex2 + key.length + 2;
11325
- const endIndex = url.indexOf("&", valueIndex);
11326
- return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
11327
- } else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
11277
+ if (trailingKeyCode === 61 || trailingKeyCode === 38 || isNaN(trailingKeyCode)) {
11278
+ if (keyIndex2 > queryIndex && /(?:^|&)[^=&]*[%+]/.test(url.slice(queryIndex + 1, keyIndex2))) break;
11279
+ if (trailingKeyCode === 61) {
11280
+ const valueIndex = keyIndex2 + key.length + 2;
11281
+ const endIndex = url.indexOf("&", valueIndex);
11282
+ return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
11283
+ }
11328
11284
  return "";
11329
11285
  }
11330
11286
  keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
11331
11287
  }
11332
11288
  encoded = /[%+]/.test(url);
11333
- if (!encoded) {
11334
- return void 0;
11335
- }
11289
+ if (!encoded) return;
11336
11290
  }
11337
11291
  const results = /* @__PURE__ */ Object.create(null);
11338
11292
  encoded ??= /[%+]/.test(url);
@@ -11340,38 +11294,21 @@ var _getQueryParam = /* @__PURE__ */ __name((url, key, multiple) => {
11340
11294
  while (keyIndex !== -1) {
11341
11295
  const nextKeyIndex = url.indexOf("&", keyIndex + 1);
11342
11296
  let valueIndex = url.indexOf("=", keyIndex);
11343
- if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
11344
- valueIndex = -1;
11345
- }
11346
- let name = url.slice(
11347
- keyIndex + 1,
11348
- valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex
11349
- );
11350
- if (encoded) {
11351
- name = _decodeURI(name);
11352
- }
11297
+ if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) valueIndex = -1;
11298
+ let name = url.slice(keyIndex + 1, valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex);
11299
+ if (encoded) name = _decodeURI(name);
11353
11300
  keyIndex = nextKeyIndex;
11354
- if (name === "") {
11355
- continue;
11356
- }
11301
+ if (name === "") continue;
11357
11302
  let value;
11358
- if (valueIndex === -1) {
11359
- value = "";
11360
- } else {
11303
+ if (valueIndex === -1) value = "";
11304
+ else {
11361
11305
  value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
11362
- if (encoded) {
11363
- value = _decodeURI(value);
11364
- }
11306
+ if (encoded) value = _decodeURI(value);
11365
11307
  }
11366
11308
  if (multiple) {
11367
- if (!(results[name] && Array.isArray(results[name]))) {
11368
- results[name] = [];
11369
- }
11370
- ;
11309
+ if (!(results[name] && Array.isArray(results[name]))) results[name] = [];
11371
11310
  results[name].push(value);
11372
- } else {
11373
- results[name] ??= value;
11374
- }
11311
+ } else results[name] ??= value;
11375
11312
  }
11376
11313
  return key ? results[key] : results;
11377
11314
  }, "_getQueryParam");
@@ -11381,67 +11318,62 @@ var getQueryParams = /* @__PURE__ */ __name((url, key) => {
11381
11318
  }, "getQueryParams");
11382
11319
  var decodeURIComponent_ = decodeURIComponent;
11383
11320
 
11384
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/request.js
11385
- var tryDecodeURIComponent = /* @__PURE__ */ __name((str) => tryDecode(str, decodeURIComponent_), "tryDecodeURIComponent");
11321
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/request.js
11386
11322
  var HonoRequest = class {
11387
11323
  static {
11388
11324
  __name(this, "HonoRequest");
11389
11325
  }
11390
11326
  /**
11391
- * `.raw` can get the raw Request object.
11392
- *
11393
- * @see {@link https://hono.dev/docs/api/request#raw}
11394
- *
11395
- * @example
11396
- * ```ts
11397
- * // For Cloudflare Workers
11398
- * app.post('/', async (c) => {
11399
- * const metadata = c.req.raw.cf?.hostMetadata?
11400
- * ...
11401
- * })
11402
- * ```
11403
- */
11327
+ * `.raw` can get the raw Request object.
11328
+ *
11329
+ * @see {@link https://hono.dev/docs/api/request#raw}
11330
+ *
11331
+ * @example
11332
+ * ```ts
11333
+ * // For Cloudflare Workers
11334
+ * app.post('/', async (c) => {
11335
+ * const metadata = c.req.raw.cf?.hostMetadata?
11336
+ * ...
11337
+ * })
11338
+ * ```
11339
+ */
11404
11340
  raw;
11405
11341
  #validatedData;
11406
- // Short name of validatedData
11407
11342
  #matchResult;
11408
11343
  routeIndex = 0;
11409
11344
  /**
11410
- * `.path` can get the pathname of the request.
11411
- *
11412
- * @see {@link https://hono.dev/docs/api/request#path}
11413
- *
11414
- * @example
11415
- * ```ts
11416
- * app.get('/about/me', (c) => {
11417
- * const pathname = c.req.path // `/about/me`
11418
- * })
11419
- * ```
11420
- */
11345
+ * `.path` can get the pathname of the request.
11346
+ *
11347
+ * @see {@link https://hono.dev/docs/api/request#path}
11348
+ *
11349
+ * @example
11350
+ * ```ts
11351
+ * app.get('/about/me', (c) => {
11352
+ * const pathname = c.req.path // `/about/me`
11353
+ * })
11354
+ * ```
11355
+ */
11421
11356
  path;
11422
11357
  bodyCache = {};
11423
11358
  constructor(request, path = "/", matchResult = [[]]) {
11424
11359
  this.raw = request;
11425
11360
  this.path = path;
11426
11361
  this.#matchResult = matchResult;
11427
- this.#validatedData = {};
11428
11362
  }
11429
11363
  param(key) {
11430
11364
  return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
11431
11365
  }
11432
11366
  #getDecodedParam(key) {
11433
- const paramKey = this.#matchResult[0][this.routeIndex][1][key];
11367
+ const paramKey = this.#matchResult[0][this.routeIndex]?.[1][key];
11434
11368
  const param = this.#getParamValue(paramKey);
11435
- return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
11369
+ return param && tryDecodeURIComponent(param);
11436
11370
  }
11437
11371
  #getAllDecodedParams() {
11438
11372
  const decoded = {};
11439
- const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
11373
+ const keys = Object.keys(this.#matchResult[0][this.routeIndex]?.[1] ?? {});
11440
11374
  for (const key of keys) {
11441
11375
  const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
11442
- if (value !== void 0) {
11443
- decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
11444
- }
11376
+ if (value !== void 0) decoded[key] = tryDecodeURIComponent(value);
11445
11377
  }
11446
11378
  return decoded;
11447
11379
  }
@@ -11455,9 +11387,7 @@ var HonoRequest = class {
11455
11387
  return getQueryParams(this.url, key);
11456
11388
  }
11457
11389
  header(name) {
11458
- if (name) {
11459
- return this.raw.headers.get(name) ?? void 0;
11460
- }
11390
+ if (name) return this.raw.headers.get(name) ?? void 0;
11461
11391
  const headerData = /* @__PURE__ */ Object.create(null);
11462
11392
  this.raw.headers.forEach((value, key) => {
11463
11393
  headerData[key] = value;
@@ -11470,146 +11400,140 @@ var HonoRequest = class {
11470
11400
  #cachedBody = /* @__PURE__ */ __name((key) => {
11471
11401
  const { bodyCache, raw: raw2 } = this;
11472
11402
  const cachedBody = bodyCache[key];
11473
- if (cachedBody) {
11474
- return cachedBody;
11475
- }
11476
- const anyCachedKey = Object.keys(bodyCache)[0];
11477
- if (anyCachedKey) {
11478
- return bodyCache[anyCachedKey].then((body2) => {
11479
- if (anyCachedKey === "json") {
11480
- body2 = JSON.stringify(body2);
11481
- }
11482
- return new Response(body2)[key]();
11483
- });
11484
- }
11403
+ if (cachedBody) return cachedBody;
11404
+ for (const anyCachedKey in bodyCache) return bodyCache[anyCachedKey].then((body2) => {
11405
+ if (anyCachedKey === "json") body2 = JSON.stringify(body2);
11406
+ const contentType = anyCachedKey === "formData" ? void 0 : raw2.headers.get("content-type");
11407
+ return new Response(body2, { headers: contentType ? { "Content-Type": contentType } : void 0 })[key]();
11408
+ });
11485
11409
  return bodyCache[key] = raw2[key]();
11486
11410
  }, "#cachedBody");
11487
11411
  /**
11488
- * `.json()` can parse Request body of type `application/json`
11489
- *
11490
- * @see {@link https://hono.dev/docs/api/request#json}
11491
- *
11492
- * @example
11493
- * ```ts
11494
- * app.post('/entry', async (c) => {
11495
- * const body = await c.req.json()
11496
- * })
11497
- * ```
11498
- */
11412
+ * `.json()` can parse Request body of type `application/json`
11413
+ *
11414
+ * @see {@link https://hono.dev/docs/api/request#json}
11415
+ *
11416
+ * @example
11417
+ * ```ts
11418
+ * app.post('/entry', async (c) => {
11419
+ * const body = await c.req.json()
11420
+ * })
11421
+ * ```
11422
+ */
11499
11423
  json() {
11500
11424
  return this.#cachedBody("text").then((text) => JSON.parse(text));
11501
11425
  }
11502
11426
  /**
11503
- * `.text()` can parse Request body of type `text/plain`
11504
- *
11505
- * @see {@link https://hono.dev/docs/api/request#text}
11506
- *
11507
- * @example
11508
- * ```ts
11509
- * app.post('/entry', async (c) => {
11510
- * const body = await c.req.text()
11511
- * })
11512
- * ```
11513
- */
11427
+ * `.text()` can parse Request body of type `text/plain`
11428
+ *
11429
+ * @see {@link https://hono.dev/docs/api/request#text}
11430
+ *
11431
+ * @example
11432
+ * ```ts
11433
+ * app.post('/entry', async (c) => {
11434
+ * const body = await c.req.text()
11435
+ * })
11436
+ * ```
11437
+ */
11514
11438
  text() {
11515
11439
  return this.#cachedBody("text");
11516
11440
  }
11517
11441
  /**
11518
- * `.arrayBuffer()` parse Request body as an `ArrayBuffer`
11519
- *
11520
- * @see {@link https://hono.dev/docs/api/request#arraybuffer}
11521
- *
11522
- * @example
11523
- * ```ts
11524
- * app.post('/entry', async (c) => {
11525
- * const body = await c.req.arrayBuffer()
11526
- * })
11527
- * ```
11528
- */
11442
+ * `.arrayBuffer()` parse Request body as an `ArrayBuffer`
11443
+ *
11444
+ * @see {@link https://hono.dev/docs/api/request#arraybuffer}
11445
+ *
11446
+ * @example
11447
+ * ```ts
11448
+ * app.post('/entry', async (c) => {
11449
+ * const body = await c.req.arrayBuffer()
11450
+ * })
11451
+ * ```
11452
+ */
11529
11453
  arrayBuffer() {
11530
11454
  return this.#cachedBody("arrayBuffer");
11531
11455
  }
11532
11456
  /**
11533
- * `.bytes()` parses the request body as a `Uint8Array`.
11534
- *
11535
- * @see {@link https://hono.dev/docs/api/request#bytes}
11536
- *
11537
- * @example
11538
- * ```ts
11539
- * app.post('/entry', async (c) => {
11540
- * const body = await c.req.bytes()
11541
- * })
11542
- * ```
11543
- */
11457
+ * `.bytes()` parses the request body as a `Uint8Array`.
11458
+ *
11459
+ * @see {@link https://hono.dev/docs/api/request#bytes}
11460
+ *
11461
+ * @example
11462
+ * ```ts
11463
+ * app.post('/entry', async (c) => {
11464
+ * const body = await c.req.bytes()
11465
+ * })
11466
+ * ```
11467
+ */
11544
11468
  bytes() {
11545
11469
  return this.#cachedBody("arrayBuffer").then((buffer) => new Uint8Array(buffer));
11546
11470
  }
11547
11471
  /**
11548
- * Parses the request body as a `Blob`.
11549
- * @example
11550
- * ```ts
11551
- * app.post('/entry', async (c) => {
11552
- * const body = await c.req.blob();
11553
- * });
11554
- * ```
11555
- * @see https://hono.dev/docs/api/request#blob
11556
- */
11472
+ * Parses the request body as a `Blob`.
11473
+ * @example
11474
+ * ```ts
11475
+ * app.post('/entry', async (c) => {
11476
+ * const body = await c.req.blob();
11477
+ * });
11478
+ * ```
11479
+ * @see https://hono.dev/docs/api/request#blob
11480
+ */
11557
11481
  blob() {
11558
11482
  return this.#cachedBody("blob");
11559
11483
  }
11560
11484
  /**
11561
- * Parses the request body as `FormData`.
11562
- * @example
11563
- * ```ts
11564
- * app.post('/entry', async (c) => {
11565
- * const body = await c.req.formData();
11566
- * });
11567
- * ```
11568
- * @see https://hono.dev/docs/api/request#formdata
11569
- */
11485
+ * Parses the request body as `FormData`.
11486
+ * @example
11487
+ * ```ts
11488
+ * app.post('/entry', async (c) => {
11489
+ * const body = await c.req.formData();
11490
+ * });
11491
+ * ```
11492
+ * @see https://hono.dev/docs/api/request#formdata
11493
+ */
11570
11494
  formData() {
11571
11495
  return this.#cachedBody("formData");
11572
11496
  }
11573
11497
  /**
11574
- * Adds validated data to the request.
11575
- *
11576
- * @param target - The target of the validation.
11577
- * @param data - The validated data to add.
11578
- */
11498
+ * Adds validated data to the request.
11499
+ *
11500
+ * @param target - The target of the validation.
11501
+ * @param data - The validated data to add.
11502
+ */
11579
11503
  addValidatedData(target, data) {
11580
- this.#validatedData[target] = data;
11504
+ (this.#validatedData ??= {})[target] = data;
11581
11505
  }
11582
11506
  valid(target) {
11583
- return this.#validatedData[target];
11507
+ return this.#validatedData?.[target];
11584
11508
  }
11585
11509
  /**
11586
- * `.url()` can get the request url strings.
11587
- *
11588
- * @see {@link https://hono.dev/docs/api/request#url}
11589
- *
11590
- * @example
11591
- * ```ts
11592
- * app.get('/about/me', (c) => {
11593
- * const url = c.req.url // `http://localhost:8787/about/me`
11594
- * ...
11595
- * })
11596
- * ```
11597
- */
11510
+ * `.url` can get the request url strings.
11511
+ *
11512
+ * @see {@link https://hono.dev/docs/api/request#url}
11513
+ *
11514
+ * @example
11515
+ * ```ts
11516
+ * app.get('/about/me', (c) => {
11517
+ * const url = c.req.url // `http://localhost:8787/about/me`
11518
+ * ...
11519
+ * })
11520
+ * ```
11521
+ */
11598
11522
  get url() {
11599
11523
  return this.raw.url;
11600
11524
  }
11601
11525
  /**
11602
- * `.method()` can get the method name of the request.
11603
- *
11604
- * @see {@link https://hono.dev/docs/api/request#method}
11605
- *
11606
- * @example
11607
- * ```ts
11608
- * app.get('/about/me', (c) => {
11609
- * const method = c.req.method // `GET`
11610
- * })
11611
- * ```
11612
- */
11526
+ * `.method` can get the method name of the request.
11527
+ *
11528
+ * @see {@link https://hono.dev/docs/api/request#method}
11529
+ *
11530
+ * @example
11531
+ * ```ts
11532
+ * app.get('/about/me', (c) => {
11533
+ * const method = c.req.method // `GET`
11534
+ * })
11535
+ * ```
11536
+ */
11613
11537
  get method() {
11614
11538
  return this.raw.method;
11615
11539
  }
@@ -11617,57 +11541,57 @@ var HonoRequest = class {
11617
11541
  return this.#matchResult;
11618
11542
  }
11619
11543
  /**
11620
- * `.matchedRoutes()` can return a matched route in the handler
11621
- *
11622
- * @deprecated
11623
- *
11624
- * Use matchedRoutes helper defined in "hono/route" instead.
11625
- *
11626
- * @see {@link https://hono.dev/docs/api/request#matchedroutes}
11627
- *
11628
- * @example
11629
- * ```ts
11630
- * app.use('*', async function logger(c, next) {
11631
- * await next()
11632
- * c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
11633
- * const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
11634
- * console.log(
11635
- * method,
11636
- * ' ',
11637
- * path,
11638
- * ' '.repeat(Math.max(10 - path.length, 0)),
11639
- * name,
11640
- * i === c.req.routeIndex ? '<- respond from here' : ''
11641
- * )
11642
- * })
11643
- * })
11644
- * ```
11645
- */
11544
+ * `.matchedRoutes` can return a matched route in the handler
11545
+ *
11546
+ * @deprecated
11547
+ *
11548
+ * Use matchedRoutes helper defined in "hono/route" instead.
11549
+ *
11550
+ * @see {@link https://hono.dev/docs/api/request#matchedroutes}
11551
+ *
11552
+ * @example
11553
+ * ```ts
11554
+ * app.use('*', async function logger(c, next) {
11555
+ * await next()
11556
+ * c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
11557
+ * const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
11558
+ * console.log(
11559
+ * method,
11560
+ * ' ',
11561
+ * path,
11562
+ * ' '.repeat(Math.max(10 - path.length, 0)),
11563
+ * name,
11564
+ * i === c.req.routeIndex ? '<- respond from here' : ''
11565
+ * )
11566
+ * })
11567
+ * })
11568
+ * ```
11569
+ */
11646
11570
  get matchedRoutes() {
11647
11571
  return this.#matchResult[0].map(([[, route]]) => route);
11648
11572
  }
11649
11573
  /**
11650
- * `routePath()` can retrieve the path registered within the handler
11651
- *
11652
- * @deprecated
11653
- *
11654
- * Use routePath helper defined in "hono/route" instead.
11655
- *
11656
- * @see {@link https://hono.dev/docs/api/request#routepath}
11657
- *
11658
- * @example
11659
- * ```ts
11660
- * app.get('/posts/:id', (c) => {
11661
- * return c.json({ path: c.req.routePath })
11662
- * })
11663
- * ```
11664
- */
11574
+ * `.routePath` can retrieve the path registered within the handler
11575
+ *
11576
+ * @deprecated
11577
+ *
11578
+ * Use routePath helper defined in "hono/route" instead.
11579
+ *
11580
+ * @see {@link https://hono.dev/docs/api/request#routepath}
11581
+ *
11582
+ * @example
11583
+ * ```ts
11584
+ * app.get('/posts/:id', (c) => {
11585
+ * return c.json({ path: c.req.routePath })
11586
+ * })
11587
+ * ```
11588
+ */
11665
11589
  get routePath() {
11666
11590
  return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
11667
11591
  }
11668
11592
  };
11669
11593
 
11670
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/html.js
11594
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/html.js
11671
11595
  var HtmlEscapedCallbackPhase = {
11672
11596
  Stringify: 1,
11673
11597
  BeforeStream: 2,
@@ -11681,35 +11605,23 @@ var raw = /* @__PURE__ */ __name((value, callbacks) => {
11681
11605
  }, "raw");
11682
11606
  var resolveCallback = /* @__PURE__ */ __name(async (str, phase, preserveCallbacks, context, buffer) => {
11683
11607
  if (typeof str === "object" && !(str instanceof String)) {
11684
- if (!(str instanceof Promise)) {
11685
- str = str.toString();
11686
- }
11687
- if (str instanceof Promise) {
11688
- str = await str;
11689
- }
11608
+ if (!(str instanceof Promise)) str = str.toString();
11609
+ if (str instanceof Promise) str = await str;
11690
11610
  }
11691
11611
  const callbacks = str.callbacks;
11692
- if (!callbacks?.length) {
11693
- return Promise.resolve(str);
11694
- }
11695
- if (buffer) {
11696
- buffer[0] += str;
11697
- } else {
11698
- buffer = [str];
11699
- }
11700
- const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then(
11701
- (res) => Promise.all(
11702
- res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))
11703
- ).then(() => buffer[0])
11704
- );
11705
- if (preserveCallbacks) {
11706
- return raw(await resStr, callbacks);
11707
- } else {
11708
- return resStr;
11709
- }
11612
+ if (!callbacks?.length) return Promise.resolve(str);
11613
+ if (buffer) buffer[0] += str;
11614
+ else buffer = [str];
11615
+ const resStr = Promise.all(callbacks.map((c) => c({
11616
+ phase,
11617
+ buffer,
11618
+ context
11619
+ }))).then((res) => Promise.all(res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))).then(() => buffer[0]));
11620
+ if (preserveCallbacks) return raw(await resStr, callbacks);
11621
+ else return resStr;
11710
11622
  }, "resolveCallback");
11711
11623
 
11712
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/context.js
11624
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/context.js
11713
11625
  var TEXT_PLAIN = "text/plain; charset=UTF-8";
11714
11626
  var setDefaultContentType = /* @__PURE__ */ __name((contentType, headers) => {
11715
11627
  return {
@@ -11725,36 +11637,36 @@ var Context = class {
11725
11637
  #rawRequest;
11726
11638
  #req;
11727
11639
  /**
11728
- * `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
11729
- *
11730
- * @see {@link https://hono.dev/docs/api/context#env}
11731
- *
11732
- * @example
11733
- * ```ts
11734
- * // Environment object for Cloudflare Workers
11735
- * app.get('*', async c => {
11736
- * const counter = c.env.COUNTER
11737
- * })
11738
- * ```
11739
- */
11640
+ * `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
11641
+ *
11642
+ * @see {@link https://hono.dev/docs/api/context#env}
11643
+ *
11644
+ * @example
11645
+ * ```ts
11646
+ * // Environment object for Cloudflare Workers
11647
+ * app.get('*', async c => {
11648
+ * const counter = c.env.COUNTER
11649
+ * })
11650
+ * ```
11651
+ */
11740
11652
  env = {};
11741
11653
  #var;
11742
11654
  finalized = false;
11743
11655
  /**
11744
- * `.error` can get the error object from the middleware if the Handler throws an error.
11745
- *
11746
- * @see {@link https://hono.dev/docs/api/context#error}
11747
- *
11748
- * @example
11749
- * ```ts
11750
- * app.use('*', async (c, next) => {
11751
- * await next()
11752
- * if (c.error) {
11753
- * // do something...
11754
- * }
11755
- * })
11756
- * ```
11757
- */
11656
+ * `.error` can get the error object from the middleware if the Handler throws an error.
11657
+ *
11658
+ * @see {@link https://hono.dev/docs/api/context#error}
11659
+ *
11660
+ * @example
11661
+ * ```ts
11662
+ * app.use('*', async (c, next) => {
11663
+ * await next()
11664
+ * if (c.error) {
11665
+ * // do something...
11666
+ * }
11667
+ * })
11668
+ * ```
11669
+ */
11758
11670
  error;
11759
11671
  #status;
11760
11672
  #executionCtx;
@@ -11766,11 +11678,11 @@ var Context = class {
11766
11678
  #matchResult;
11767
11679
  #path;
11768
11680
  /**
11769
- * Creates an instance of the Context class.
11770
- *
11771
- * @param req - The Request object.
11772
- * @param options - Optional configuration options for the context.
11773
- */
11681
+ * Creates an instance of the Context class.
11682
+ *
11683
+ * @param req - The Request object.
11684
+ * @param options - Optional configuration options for the context.
11685
+ */
11774
11686
  constructor(req, options) {
11775
11687
  this.#rawRequest = req;
11776
11688
  if (options) {
@@ -11782,347 +11694,360 @@ var Context = class {
11782
11694
  }
11783
11695
  }
11784
11696
  /**
11785
- * `.req` is the instance of {@link HonoRequest}.
11786
- */
11697
+ * `.req` is the instance of {@link HonoRequest}.
11698
+ */
11787
11699
  get req() {
11788
11700
  this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
11789
11701
  return this.#req;
11790
11702
  }
11791
11703
  /**
11792
- * @see {@link https://hono.dev/docs/api/context#event}
11793
- * The FetchEvent associated with the current request.
11794
- *
11795
- * @throws Will throw an error if the context does not have a FetchEvent.
11796
- */
11704
+ * @see {@link https://hono.dev/docs/api/context#event}
11705
+ * The FetchEvent associated with the current request.
11706
+ *
11707
+ * @throws Will throw an error if the context does not have a FetchEvent.
11708
+ */
11797
11709
  get event() {
11798
- if (this.#executionCtx && "respondWith" in this.#executionCtx) {
11799
- return this.#executionCtx;
11800
- } else {
11801
- throw Error("This context has no FetchEvent");
11802
- }
11710
+ if (this.#executionCtx && "respondWith" in this.#executionCtx) return this.#executionCtx;
11711
+ else throw Error("This context has no FetchEvent");
11803
11712
  }
11804
11713
  /**
11805
- * @see {@link https://hono.dev/docs/api/context#executionctx}
11806
- * The ExecutionContext associated with the current request.
11807
- *
11808
- * @throws Will throw an error if the context does not have an ExecutionContext.
11809
- */
11714
+ * @see {@link https://hono.dev/docs/api/context#executionctx}
11715
+ * The ExecutionContext associated with the current request.
11716
+ *
11717
+ * @throws Will throw an error if the context does not have an ExecutionContext.
11718
+ */
11810
11719
  get executionCtx() {
11811
- if (this.#executionCtx) {
11812
- return this.#executionCtx;
11813
- } else {
11814
- throw Error("This context has no ExecutionContext");
11815
- }
11720
+ if (this.#executionCtx) return this.#executionCtx;
11721
+ else throw Error("This context has no ExecutionContext");
11816
11722
  }
11817
11723
  /**
11818
- * @see {@link https://hono.dev/docs/api/context#res}
11819
- * The Response object for the current request.
11820
- */
11724
+ * @see {@link https://hono.dev/docs/api/context#res}
11725
+ * The Response object for the current request.
11726
+ */
11821
11727
  get res() {
11822
- return this.#res ||= createResponseInstance(null, {
11823
- headers: this.#preparedHeaders ??= new Headers()
11824
- });
11728
+ return this.#res ||= createResponseInstance(null, { headers: this.#preparedHeaders ??= new Headers() });
11825
11729
  }
11826
11730
  /**
11827
- * Sets the Response object for the current request.
11828
- *
11829
- * @param _res - The Response object to set.
11830
- */
11731
+ * Sets the Response object for the current request.
11732
+ *
11733
+ * @param _res - The Response object to set.
11734
+ */
11831
11735
  set res(_res) {
11832
11736
  if (this.#res && _res) {
11833
11737
  _res = createResponseInstance(_res.body, _res);
11834
11738
  for (const [k, v] of this.#res.headers.entries()) {
11835
- if (k === "content-type") {
11836
- continue;
11837
- }
11739
+ if (k === "content-type") continue;
11838
11740
  if (k === "set-cookie") {
11839
11741
  const cookies = this.#res.headers.getSetCookie();
11840
11742
  _res.headers.delete("set-cookie");
11841
- for (const cookie of cookies) {
11842
- _res.headers.append("set-cookie", cookie);
11843
- }
11844
- } else {
11845
- _res.headers.set(k, v);
11846
- }
11743
+ for (const cookie of cookies) _res.headers.append("set-cookie", cookie);
11744
+ } else _res.headers.set(k, v);
11847
11745
  }
11848
11746
  }
11849
11747
  this.#res = _res;
11850
11748
  this.finalized = true;
11851
11749
  }
11852
11750
  /**
11853
- * `.render()` can create a response within a layout.
11854
- *
11855
- * @see {@link https://hono.dev/docs/api/context#render-setrenderer}
11856
- *
11857
- * @example
11858
- * ```ts
11859
- * app.get('/', (c) => {
11860
- * return c.render('Hello!')
11861
- * })
11862
- * ```
11863
- */
11751
+ * `.render()` can create a response within a layout.
11752
+ *
11753
+ * @see {@link https://hono.dev/docs/api/context#render-setrenderer}
11754
+ *
11755
+ * @example
11756
+ * ```ts
11757
+ * app.get('/', (c) => {
11758
+ * return c.render('Hello!')
11759
+ * })
11760
+ * ```
11761
+ */
11864
11762
  render = /* @__PURE__ */ __name((...args) => {
11865
11763
  this.#renderer ??= (content) => this.html(content);
11866
11764
  return this.#renderer(...args);
11867
11765
  }, "render");
11868
11766
  /**
11869
- * Sets the layout for the response.
11870
- *
11871
- * @param layout - The layout to set.
11872
- * @returns The layout function.
11873
- */
11767
+ * Sets the layout for the response.
11768
+ *
11769
+ * @param layout - The layout to set.
11770
+ * @returns The layout function.
11771
+ */
11874
11772
  setLayout = /* @__PURE__ */ __name((layout) => this.#layout = layout, "setLayout");
11875
11773
  /**
11876
- * Gets the current layout for the response.
11877
- *
11878
- * @returns The current layout function.
11879
- */
11774
+ * Gets the current layout for the response.
11775
+ *
11776
+ * @returns The current layout function.
11777
+ */
11880
11778
  getLayout = /* @__PURE__ */ __name(() => this.#layout, "getLayout");
11881
11779
  /**
11882
- * `.setRenderer()` can set the layout in the custom middleware.
11883
- *
11884
- * @see {@link https://hono.dev/docs/api/context#render-setrenderer}
11885
- *
11886
- * @example
11887
- * ```tsx
11888
- * app.use('*', async (c, next) => {
11889
- * c.setRenderer((content) => {
11890
- * return c.html(
11891
- * <html>
11892
- * <body>
11893
- * <p>{content}</p>
11894
- * </body>
11895
- * </html>
11896
- * )
11897
- * })
11898
- * await next()
11899
- * })
11900
- * ```
11901
- */
11780
+ * `.setRenderer()` can set the layout in the custom middleware.
11781
+ *
11782
+ * @see {@link https://hono.dev/docs/api/context#render-setrenderer}
11783
+ *
11784
+ * @example
11785
+ * ```tsx
11786
+ * app.use('*', async (c, next) => {
11787
+ * c.setRenderer((content) => {
11788
+ * return c.html(
11789
+ * <html>
11790
+ * <body>
11791
+ * <p>{content}</p>
11792
+ * </body>
11793
+ * </html>
11794
+ * )
11795
+ * })
11796
+ * await next()
11797
+ * })
11798
+ * ```
11799
+ */
11902
11800
  setRenderer = /* @__PURE__ */ __name((renderer) => {
11903
11801
  this.#renderer = renderer;
11904
11802
  }, "setRenderer");
11905
11803
  /**
11906
- * `.header()` can set headers.
11907
- *
11908
- * @see {@link https://hono.dev/docs/api/context#header}
11909
- *
11910
- * @example
11911
- * ```ts
11912
- * app.get('/welcome', (c) => {
11913
- * // Set headers
11914
- * c.header('X-Message', 'Hello!')
11915
- * c.header('Content-Type', 'text/plain')
11916
- *
11917
- * return c.body('Thank you for coming')
11918
- * })
11919
- * ```
11920
- */
11804
+ * `.header()` can set headers.
11805
+ *
11806
+ * @see {@link https://hono.dev/docs/api/context#header}
11807
+ *
11808
+ * @example
11809
+ * ```ts
11810
+ * app.get('/welcome', (c) => {
11811
+ * // Set headers
11812
+ * c.header('X-Message', 'Hello!')
11813
+ * c.header('Content-Type', 'text/plain')
11814
+ *
11815
+ * // Append multiple headers using the append option (e.g. Vary)
11816
+ * c.header('Vary', 'Accept-Encoding', { append: true })
11817
+ * c.header('Vary', 'User-Agent', { append: true })
11818
+ *
11819
+ * return c.body('Thank you for coming')
11820
+ * })
11821
+ * ```
11822
+ */
11921
11823
  header = /* @__PURE__ */ __name((name, value, options) => {
11922
- if (this.finalized) {
11923
- this.#res = createResponseInstance(this.#res.body, this.#res);
11924
- }
11824
+ if (this.finalized && !this.#res.bodyUsed) this.#res = createResponseInstance(this.#res.body, this.#res);
11925
11825
  const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
11926
- if (value === void 0) {
11927
- headers.delete(name);
11928
- } else if (options?.append) {
11929
- headers.append(name, value);
11930
- } else {
11931
- headers.set(name, value);
11932
- }
11826
+ if (value === void 0) headers.delete(name);
11827
+ else if (options?.append) headers.append(name, value);
11828
+ else headers.set(name, value);
11933
11829
  }, "header");
11934
11830
  status = /* @__PURE__ */ __name((status) => {
11935
11831
  this.#status = status;
11936
11832
  }, "status");
11937
11833
  /**
11938
- * `.set()` can set the value specified by the key.
11939
- *
11940
- * @see {@link https://hono.dev/docs/api/context#set-get}
11941
- *
11942
- * @example
11943
- * ```ts
11944
- * app.use('*', async (c, next) => {
11945
- * c.set('message', 'Hono is hot!!')
11946
- * await next()
11947
- * })
11948
- * ```
11949
- */
11834
+ * `.set()` can set the value specified by the key.
11835
+ *
11836
+ * @see {@link https://hono.dev/docs/api/context#set-get}
11837
+ *
11838
+ * @example
11839
+ * ```ts
11840
+ * app.use('*', async (c, next) => {
11841
+ * c.set('message', 'Hono is hot!!')
11842
+ * await next()
11843
+ * })
11844
+ * ```
11845
+ */
11950
11846
  set = /* @__PURE__ */ __name((key, value) => {
11951
11847
  this.#var ??= /* @__PURE__ */ new Map();
11952
11848
  this.#var.set(key, value);
11953
11849
  }, "set");
11954
11850
  /**
11955
- * `.get()` can use the value specified by the key.
11956
- *
11957
- * @see {@link https://hono.dev/docs/api/context#set-get}
11958
- *
11959
- * @example
11960
- * ```ts
11961
- * app.get('/', (c) => {
11962
- * const message = c.get('message')
11963
- * return c.text(`The message is "${message}"`)
11964
- * })
11965
- * ```
11966
- */
11851
+ * `.get()` can use the value specified by the key.
11852
+ *
11853
+ * @see {@link https://hono.dev/docs/api/context#set-get}
11854
+ *
11855
+ * @example
11856
+ * ```ts
11857
+ * app.get('/', (c) => {
11858
+ * const message = c.get('message')
11859
+ * return c.text(`The message is "${message}"`)
11860
+ * })
11861
+ * ```
11862
+ */
11967
11863
  get = /* @__PURE__ */ __name((key) => {
11968
11864
  return this.#var ? this.#var.get(key) : void 0;
11969
11865
  }, "get");
11970
11866
  /**
11971
- * `.var` can access the value of a variable.
11972
- *
11973
- * @see {@link https://hono.dev/docs/api/context#var}
11974
- *
11975
- * @example
11976
- * ```ts
11977
- * const result = c.var.client.oneMethod()
11978
- * ```
11979
- */
11980
- // c.var.propName is a read-only
11867
+ * `.var` can access the value of a variable.
11868
+ *
11869
+ * @see {@link https://hono.dev/docs/api/context#var}
11870
+ *
11871
+ * @example
11872
+ * ```ts
11873
+ * const result = c.var.client.oneMethod()
11874
+ * ```
11875
+ */
11981
11876
  get var() {
11982
- if (!this.#var) {
11983
- return {};
11984
- }
11877
+ if (!this.#var) return {};
11985
11878
  return Object.fromEntries(this.#var);
11986
11879
  }
11987
11880
  #newResponse(data, arg, headers) {
11988
- const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
11989
- if (typeof arg === "object" && "headers" in arg) {
11990
- const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
11991
- for (const [key, value] of argHeaders) {
11992
- if (key.toLowerCase() === "set-cookie") {
11993
- responseHeaders.append(key, value);
11994
- } else {
11995
- responseHeaders.set(key, value);
11996
- }
11997
- }
11881
+ let responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders;
11882
+ if (typeof arg === "object" && arg.headers) {
11883
+ responseHeaders ??= new Headers();
11884
+ for (const [key, value] of new Headers(arg.headers)) if (key === "set-cookie") responseHeaders.append(key, value);
11885
+ else responseHeaders.set(key, value);
11998
11886
  }
11999
11887
  if (headers) {
12000
- for (const [k, v] of Object.entries(headers)) {
12001
- if (typeof v === "string") {
12002
- responseHeaders.set(k, v);
12003
- } else {
11888
+ if (!responseHeaders) {
11889
+ let count = 0;
11890
+ for (const k in headers) if (++count > 1 || typeof headers[k] !== "string") {
11891
+ responseHeaders = new Headers();
11892
+ break;
11893
+ }
11894
+ }
11895
+ if (responseHeaders) for (const k in headers) {
11896
+ const v = headers[k];
11897
+ if (typeof v === "string") responseHeaders.set(k, v);
11898
+ else {
12004
11899
  responseHeaders.delete(k);
12005
- for (const v2 of v) {
12006
- responseHeaders.append(k, v2);
12007
- }
11900
+ for (const v2 of v) responseHeaders.append(k, v2);
12008
11901
  }
12009
11902
  }
12010
11903
  }
12011
11904
  const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
12012
- return createResponseInstance(data, { status, headers: responseHeaders });
11905
+ return createResponseInstance(data, {
11906
+ status,
11907
+ headers: responseHeaders ?? headers
11908
+ });
12013
11909
  }
12014
11910
  newResponse = /* @__PURE__ */ __name((...args) => this.#newResponse(...args), "newResponse");
12015
11911
  /**
12016
- * `.body()` can return the HTTP response.
12017
- * You can set headers with `.header()` and set HTTP status code with `.status`.
12018
- * This can also be set in `.text()`, `.json()` and so on.
12019
- *
12020
- * @see {@link https://hono.dev/docs/api/context#body}
12021
- *
12022
- * @example
12023
- * ```ts
12024
- * app.get('/welcome', (c) => {
12025
- * // Set headers
12026
- * c.header('X-Message', 'Hello!')
12027
- * c.header('Content-Type', 'text/plain')
12028
- * // Set HTTP status code
12029
- * c.status(201)
12030
- *
12031
- * // Return the response body
12032
- * return c.body('Thank you for coming')
12033
- * })
12034
- * ```
12035
- */
11912
+ * `.body()` can return the HTTP response.
11913
+ * You can set headers with `.header()` and set HTTP status code with `.status`.
11914
+ * This can also be set in `.text()`, `.json()` and so on.
11915
+ *
11916
+ * @see {@link https://hono.dev/docs/api/context#body}
11917
+ *
11918
+ * @example
11919
+ * ```ts
11920
+ * app.get('/welcome', (c) => {
11921
+ * // Set headers
11922
+ * c.header('X-Message', 'Hello!')
11923
+ * c.header('Content-Type', 'text/plain')
11924
+ * // Set HTTP status code
11925
+ * c.status(201)
11926
+ *
11927
+ * // Return the response body
11928
+ * return c.body('Thank you for coming')
11929
+ * })
11930
+ * ```
11931
+ */
12036
11932
  body = /* @__PURE__ */ __name((data, arg, headers) => this.#newResponse(data, arg, headers), "body");
12037
11933
  /**
12038
- * `.text()` can render text as `Content-Type:text/plain`.
12039
- *
12040
- * @see {@link https://hono.dev/docs/api/context#text}
12041
- *
12042
- * @example
12043
- * ```ts
12044
- * app.get('/say', (c) => {
12045
- * return c.text('Hello!')
12046
- * })
12047
- * ```
12048
- */
11934
+ * `.text()` can render text as `Content-Type:text/plain`.
11935
+ *
11936
+ * @see {@link https://hono.dev/docs/api/context#text}
11937
+ *
11938
+ * @example
11939
+ * ```ts
11940
+ * app.get('/say', (c) => {
11941
+ * return c.text('Hello!')
11942
+ * })
11943
+ * ```
11944
+ */
12049
11945
  text = /* @__PURE__ */ __name((text, arg, headers) => {
12050
- return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(
12051
- text,
12052
- arg,
12053
- setDefaultContentType(TEXT_PLAIN, headers)
12054
- );
11946
+ return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(text, arg, setDefaultContentType(TEXT_PLAIN, headers));
12055
11947
  }, "text");
12056
11948
  /**
12057
- * `.json()` can render JSON as `Content-Type:application/json`.
12058
- *
12059
- * @see {@link https://hono.dev/docs/api/context#json}
12060
- *
12061
- * @example
12062
- * ```ts
12063
- * app.get('/api', (c) => {
12064
- * return c.json({ message: 'Hello!' })
12065
- * })
12066
- * ```
12067
- */
11949
+ * `.json()` can render JSON as `Content-Type:application/json`.
11950
+ *
11951
+ * @see {@link https://hono.dev/docs/api/context#json}
11952
+ *
11953
+ * @example
11954
+ * ```ts
11955
+ * app.get('/api', (c) => {
11956
+ * return c.json({ message: 'Hello!' })
11957
+ * })
11958
+ * ```
11959
+ */
12068
11960
  json = /* @__PURE__ */ __name((object, arg, headers) => {
12069
- return this.#newResponse(
12070
- JSON.stringify(object),
12071
- arg,
12072
- setDefaultContentType("application/json", headers)
12073
- );
11961
+ return this.#newResponse(JSON.stringify(object), arg, setDefaultContentType("application/json", headers));
12074
11962
  }, "json");
12075
11963
  html = /* @__PURE__ */ __name((html, arg, headers) => {
12076
11964
  const res = /* @__PURE__ */ __name((html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers)), "res");
12077
11965
  return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
12078
11966
  }, "html");
12079
11967
  /**
12080
- * `.redirect()` can Redirect, default status code is 302.
12081
- *
12082
- * @see {@link https://hono.dev/docs/api/context#redirect}
12083
- *
12084
- * @example
12085
- * ```ts
12086
- * app.get('/redirect', (c) => {
12087
- * return c.redirect('/')
12088
- * })
12089
- * app.get('/redirect-permanently', (c) => {
12090
- * return c.redirect('/', 301)
12091
- * })
12092
- * ```
12093
- */
11968
+ * `.redirect()` can Redirect, default status code is 302.
11969
+ *
11970
+ * @see {@link https://hono.dev/docs/api/context#redirect}
11971
+ *
11972
+ * @example
11973
+ * ```ts
11974
+ * app.get('/redirect', (c) => {
11975
+ * return c.redirect('/')
11976
+ * })
11977
+ * app.get('/redirect-permanently', (c) => {
11978
+ * return c.redirect('/', 301)
11979
+ * })
11980
+ * ```
11981
+ */
12094
11982
  redirect = /* @__PURE__ */ __name((location, status) => {
12095
11983
  const locationString = String(location);
12096
- this.header(
12097
- "Location",
12098
- // Multibyes should be encoded
12099
- // eslint-disable-next-line no-control-regex
12100
- !/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString)
12101
- );
11984
+ this.header("Location", !/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString));
12102
11985
  return this.newResponse(null, status ?? 302);
12103
11986
  }, "redirect");
12104
11987
  /**
12105
- * `.notFound()` can return the Not Found Response.
12106
- *
12107
- * @see {@link https://hono.dev/docs/api/context#notfound}
12108
- *
12109
- * @example
12110
- * ```ts
12111
- * app.get('/notfound', (c) => {
12112
- * return c.notFound()
12113
- * })
12114
- * ```
12115
- */
11988
+ * `.notFound()` can return the Not Found Response.
11989
+ *
11990
+ * @see {@link https://hono.dev/docs/api/context#notfound}
11991
+ *
11992
+ * @example
11993
+ * ```ts
11994
+ * app.get('/notfound', (c) => {
11995
+ * return c.notFound()
11996
+ * })
11997
+ * ```
11998
+ */
12116
11999
  notFound = /* @__PURE__ */ __name(() => {
12117
12000
  this.#notFoundHandler ??= () => createResponseInstance();
12118
12001
  return this.#notFoundHandler(this);
12119
12002
  }, "notFound");
12120
12003
  };
12121
12004
 
12122
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router.js
12123
- var METHOD_NAME_ALL = "ALL";
12124
- var METHOD_NAME_ALL_LOWERCASE = "all";
12125
- var METHODS2 = ["get", "post", "put", "delete", "options", "patch"];
12005
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/compose.js
12006
+ var compose = /* @__PURE__ */ __name((middleware, onError, onNotFound) => {
12007
+ return (context, next) => {
12008
+ let index = -1;
12009
+ return dispatch(0);
12010
+ async function dispatch(i) {
12011
+ if (i <= index) throw new Error("next() called multiple times");
12012
+ index = i;
12013
+ let res;
12014
+ let isError = false;
12015
+ let handler;
12016
+ if (middleware[i]) {
12017
+ handler = middleware[i][0][0];
12018
+ context.req.routeIndex = i;
12019
+ } else handler = i === middleware.length && next || void 0;
12020
+ if (handler) try {
12021
+ res = await handler(context, () => dispatch(i + 1));
12022
+ } catch (err) {
12023
+ if (err instanceof Error && onError) {
12024
+ context.error = err;
12025
+ res = await onError(err, context);
12026
+ isError = true;
12027
+ } else throw err;
12028
+ }
12029
+ else if (context.finalized === false && onNotFound) res = await onNotFound(context);
12030
+ if (res && (context.finalized === false || isError)) context.res = res;
12031
+ return context;
12032
+ }
12033
+ __name(dispatch, "dispatch");
12034
+ };
12035
+ }, "compose");
12036
+
12037
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/helper/route/index.js
12038
+ var matchedRoutes = /* @__PURE__ */ __name((c) => c.req[GET_MATCH_RESULT][0].map(([[, route]]) => route), "matchedRoutes");
12039
+ var routePath = /* @__PURE__ */ __name((c, index) => matchedRoutes(c).at(index ?? c.req.routeIndex)?.path ?? "", "routePath");
12040
+
12041
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router.js
12042
+ var METHODS2 = [
12043
+ "get",
12044
+ "post",
12045
+ "put",
12046
+ "delete",
12047
+ "options",
12048
+ "patch",
12049
+ "query"
12050
+ ];
12126
12051
  var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
12127
12052
  var UnsupportedPathError = class extends Error {
12128
12053
  static {
@@ -12130,10 +12055,57 @@ var UnsupportedPathError = class extends Error {
12130
12055
  }
12131
12056
  };
12132
12057
 
12133
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/utils/constants.js
12058
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/constants.js
12134
12059
  var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
12135
12060
 
12136
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/hono-base.js
12061
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/utils/mount.js
12062
+ var countTrailingSlashes = /* @__PURE__ */ __name((path) => {
12063
+ let index = path.length;
12064
+ while (index > 0 && path.charCodeAt(index - 1) === 47) index--;
12065
+ return path.length - index;
12066
+ }, "countTrailingSlashes");
12067
+ var getPathPrefixLength = /* @__PURE__ */ __name((c, pathPrefix, routePath2) => {
12068
+ if (!/[:*]/.test(pathPrefix)) return pathPrefix.length;
12069
+ const path = c.req.path;
12070
+ const matchResult = c.req[GET_MATCH_RESULT];
12071
+ const paramNames = /* @__PURE__ */ new Set();
12072
+ let length = 0;
12073
+ for (const part of splitRoutingPath(pathPrefix)) {
12074
+ if (part[0] === ":" && part.endsWith("}?")) throw new Error(`mount(): Optional regular expression parameters are not supported in "${routePath2}".`);
12075
+ const pattern = getPattern(part);
12076
+ if (pattern && pattern !== "*") {
12077
+ const name = pattern[1];
12078
+ if (paramNames.has(name)) throw new Error(`mount(): Duplicate path parameter "${name}" in "${routePath2}".`);
12079
+ paramNames.add(name);
12080
+ }
12081
+ if (pattern && pattern !== "*" && pattern[2] !== true) {
12082
+ const value = matchResult.length === 2 ? matchResult[1][matchResult[0][c.req.routeIndex][1][pattern[1]]] : matchResult[0][c.req.routeIndex][1][pattern[1]];
12083
+ length += value.length + 1;
12084
+ } else if (pattern || part.endsWith("*")) {
12085
+ const end = path.indexOf("/", length + 1);
12086
+ length = end === -1 ? path.length : end;
12087
+ } else length += part.length + 1;
12088
+ }
12089
+ return length;
12090
+ }, "getPathPrefixLength");
12091
+ var createMountedRequest = /* @__PURE__ */ __name((c, pathPrefix, routePath2) => {
12092
+ if (/[^/]\*$/.test(routePath2)) throw new Error(`mount(): Wildcard must follow "/" in "${routePath2}".`);
12093
+ const prefixLength = getPathPrefixLength(c, pathPrefix, routePath2);
12094
+ const path = c.req.path.slice(prefixLength) || "/";
12095
+ if (prefixLength > c.req.path.length || path[0] !== "/" || /\/(?:\.|%2e){1,2}(?:\/|$)/i.test(path)) throw new HTTPException(400, { message: "Invalid mounted path" });
12096
+ const rawUrl = c.req.raw.url;
12097
+ if (/^[^/?#]*\/\/[^/?#\\]*[?#\\]/.test(rawUrl)) throw new HTTPException(400, { message: "Invalid mounted path" });
12098
+ const rawPathEnd = rawUrl.search(/[?#]/);
12099
+ const rawTrailingSlashes = countTrailingSlashes(rawPathEnd === -1 ? rawUrl : rawUrl.slice(0, rawPathEnd));
12100
+ if (rawTrailingSlashes > 1 && countTrailingSlashes(c.req.path) === rawTrailingSlashes - 1) throw new HTTPException(400, { message: "Invalid mounted path" });
12101
+ const url = new URL(rawUrl);
12102
+ url.pathname = path.replace(/[\\\t\n\r]/g, encodeURIComponent);
12103
+ if (path.includes("%")) {
12104
+ }
12105
+ return new Request(url, c.req.raw);
12106
+ }, "createMountedRequest");
12107
+
12108
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/hono-base.js
12137
12109
  var notFoundHandler = /* @__PURE__ */ __name((c) => {
12138
12110
  return c.text("404 Not Found", 404);
12139
12111
  }, "notFoundHandler");
@@ -12145,9 +12117,9 @@ var errorHandler = /* @__PURE__ */ __name((err, c) => {
12145
12117
  console.error(err);
12146
12118
  return c.text("Internal Server Error", 500);
12147
12119
  }, "errorHandler");
12148
- var Hono = class _Hono {
12120
+ var Hono = class Hono2 {
12149
12121
  static {
12150
- __name(this, "_Hono");
12122
+ __name(this, "Hono");
12151
12123
  }
12152
12124
  get;
12153
12125
  post;
@@ -12155,30 +12127,23 @@ var Hono = class _Hono {
12155
12127
  delete;
12156
12128
  options;
12157
12129
  patch;
12130
+ query;
12158
12131
  all;
12159
12132
  on;
12160
12133
  use;
12161
- /*
12162
- This class is like an abstract class and does not have a router.
12163
- To use it, inherit the class and implement router in the constructor.
12164
- */
12165
12134
  router;
12166
12135
  getPath;
12167
- // Cannot use `#` because it requires visibility at JavaScript runtime.
12168
12136
  _basePath = "/";
12169
12137
  #path = "/";
12170
12138
  routes = [];
12171
12139
  constructor(options = {}) {
12172
- const allMethods = [...METHODS2, METHOD_NAME_ALL_LOWERCASE];
12173
- allMethods.forEach((method) => {
12140
+ [...METHODS2, "all"].forEach((method) => {
12174
12141
  this[method] = (args1, ...args) => {
12175
- if (typeof args1 === "string") {
12176
- this.#path = args1;
12177
- } else {
12178
- this.#addRoute(method, this.#path, args1);
12179
- }
12142
+ const methodName = method.toUpperCase();
12143
+ if (typeof args1 === "string") this.#path = args1;
12144
+ else this.#addRoute(methodName, this.#path, args1);
12180
12145
  args.forEach((handler) => {
12181
- this.#addRoute(method, this.#path, handler);
12146
+ this.#addRoute(methodName, this.#path, handler);
12182
12147
  });
12183
12148
  return this;
12184
12149
  };
@@ -12187,22 +12152,20 @@ var Hono = class _Hono {
12187
12152
  for (const p of [path].flat()) {
12188
12153
  this.#path = p;
12189
12154
  for (const m of [method].flat()) {
12190
- handlers.map((handler) => {
12191
- this.#addRoute(m.toUpperCase(), this.#path, handler);
12192
- });
12155
+ const methodName = m.toUpperCase();
12156
+ for (const handler of handlers) this.#addRoute(methodName, this.#path, handler);
12193
12157
  }
12194
12158
  }
12195
12159
  return this;
12196
12160
  };
12197
12161
  this.use = (arg1, ...handlers) => {
12198
- if (typeof arg1 === "string") {
12199
- this.#path = arg1;
12200
- } else {
12162
+ if (typeof arg1 === "string") this.#path = arg1;
12163
+ else {
12201
12164
  this.#path = "*";
12202
12165
  handlers.unshift(arg1);
12203
12166
  }
12204
12167
  handlers.forEach((handler) => {
12205
- this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
12168
+ this.#addRoute("ALL", this.#path, handler);
12206
12169
  });
12207
12170
  return this;
12208
12171
  };
@@ -12211,7 +12174,7 @@ var Hono = class _Hono {
12211
12174
  this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
12212
12175
  }
12213
12176
  #clone() {
12214
- const clone = new _Hono({
12177
+ const clone = new Hono2({
12215
12178
  router: this.router,
12216
12179
  getPath: this.getPath
12217
12180
  });
@@ -12221,33 +12184,31 @@ var Hono = class _Hono {
12221
12184
  return clone;
12222
12185
  }
12223
12186
  #notFoundHandler = notFoundHandler;
12224
- // Cannot use `#` because it requires visibility at JavaScript runtime.
12225
12187
  errorHandler = errorHandler;
12226
12188
  /**
12227
- * `.route()` allows grouping other Hono instance in routes.
12228
- *
12229
- * @see {@link https://hono.dev/docs/api/routing#grouping}
12230
- *
12231
- * @param {string} path - base Path
12232
- * @param {Hono} app - other Hono instance
12233
- * @returns {Hono} routed Hono instance
12234
- *
12235
- * @example
12236
- * ```ts
12237
- * const app = new Hono()
12238
- * const app2 = new Hono()
12239
- *
12240
- * app2.get("/user", (c) => c.text("user"))
12241
- * app.route("/api", app2) // GET /api/user
12242
- * ```
12243
- */
12189
+ * `.route()` allows grouping other Hono instance in routes.
12190
+ *
12191
+ * @see {@link https://hono.dev/docs/api/routing#grouping}
12192
+ *
12193
+ * @param {string} path - base Path
12194
+ * @param {Hono} app - other Hono instance
12195
+ * @returns {Hono} routed Hono instance
12196
+ *
12197
+ * @example
12198
+ * ```ts
12199
+ * const app = new Hono()
12200
+ * const app2 = new Hono()
12201
+ *
12202
+ * app2.get("/user", (c) => c.text("user"))
12203
+ * app.route("/api", app2) // GET /api/user
12204
+ * ```
12205
+ */
12244
12206
  route(path, app2) {
12245
12207
  const subApp = this.basePath(path);
12246
12208
  app2.routes.map((r) => {
12247
12209
  let handler;
12248
- if (app2.errorHandler === errorHandler) {
12249
- handler = r.handler;
12250
- } else {
12210
+ if (app2.errorHandler === errorHandler) handler = r.handler;
12211
+ else {
12251
12212
  handler = /* @__PURE__ */ __name(async (c, next) => (await compose([], app2.errorHandler)(c, () => r.handler(c, next))).res, "handler");
12252
12213
  handler[COMPOSED_HANDLER] = r.handler;
12253
12214
  }
@@ -12256,107 +12217,107 @@ var Hono = class _Hono {
12256
12217
  return this;
12257
12218
  }
12258
12219
  /**
12259
- * `.basePath()` allows base paths to be specified.
12260
- *
12261
- * @see {@link https://hono.dev/docs/api/routing#base-path}
12262
- *
12263
- * @param {string} path - base Path
12264
- * @returns {Hono} changed Hono instance
12265
- *
12266
- * @example
12267
- * ```ts
12268
- * const api = new Hono().basePath('/api')
12269
- * ```
12270
- */
12220
+ * `.basePath()` allows base paths to be specified.
12221
+ *
12222
+ * @see {@link https://hono.dev/docs/api/routing#base-path}
12223
+ *
12224
+ * @param {string} path - base Path
12225
+ * @returns {Hono} changed Hono instance
12226
+ *
12227
+ * @example
12228
+ * ```ts
12229
+ * const api = new Hono().basePath('/api')
12230
+ * ```
12231
+ */
12271
12232
  basePath(path) {
12272
12233
  const subApp = this.#clone();
12273
12234
  subApp._basePath = mergePath(this._basePath, path);
12274
12235
  return subApp;
12275
12236
  }
12276
12237
  /**
12277
- * `.onError()` handles an error and returns a customized Response.
12278
- *
12279
- * @see {@link https://hono.dev/docs/api/hono#error-handling}
12280
- *
12281
- * @param {ErrorHandler} handler - request Handler for error
12282
- * @returns {Hono} changed Hono instance
12283
- *
12284
- * @example
12285
- * ```ts
12286
- * app.onError((err, c) => {
12287
- * console.error(`${err}`)
12288
- * return c.text('Custom Error Message', 500)
12289
- * })
12290
- * ```
12291
- */
12238
+ * `.onError()` handles an error and returns a customized Response.
12239
+ *
12240
+ * @see {@link https://hono.dev/docs/api/hono#error-handling}
12241
+ *
12242
+ * @param {ErrorHandler} handler - request Handler for error
12243
+ * @returns {Hono} changed Hono instance
12244
+ *
12245
+ * @example
12246
+ * ```ts
12247
+ * app.onError((err, c) => {
12248
+ * console.error(`${err}`)
12249
+ * return c.text('Custom Error Message', 500)
12250
+ * })
12251
+ * ```
12252
+ */
12292
12253
  onError = /* @__PURE__ */ __name((handler) => {
12293
12254
  this.errorHandler = handler;
12294
12255
  return this;
12295
12256
  }, "onError");
12296
12257
  /**
12297
- * `.notFound()` allows you to customize a Not Found Response.
12298
- *
12299
- * @see {@link https://hono.dev/docs/api/hono#not-found}
12300
- *
12301
- * @param {NotFoundHandler} handler - request handler for not-found
12302
- * @returns {Hono} changed Hono instance
12303
- *
12304
- * @example
12305
- * ```ts
12306
- * app.notFound((c) => {
12307
- * return c.text('Custom 404 Message', 404)
12308
- * })
12309
- * ```
12310
- */
12258
+ * `.notFound()` allows you to customize a Not Found Response.
12259
+ *
12260
+ * @see {@link https://hono.dev/docs/api/hono#not-found}
12261
+ *
12262
+ * @param {NotFoundHandler} handler - request handler for not-found
12263
+ * @returns {Hono} changed Hono instance
12264
+ *
12265
+ * @example
12266
+ * ```ts
12267
+ * app.notFound((c) => {
12268
+ * return c.text('Custom 404 Message', 404)
12269
+ * })
12270
+ * ```
12271
+ */
12311
12272
  notFound = /* @__PURE__ */ __name((handler) => {
12312
12273
  this.#notFoundHandler = handler;
12313
12274
  return this;
12314
12275
  }, "notFound");
12315
12276
  /**
12316
- * `.mount()` allows you to mount applications built with other frameworks into your Hono application.
12317
- *
12318
- * @see {@link https://hono.dev/docs/api/hono#mount}
12319
- *
12320
- * @param {string} path - base Path
12321
- * @param {Function} applicationHandler - other Request Handler
12322
- * @param {MountOptions} [options] - options of `.mount()`
12323
- * @returns {Hono} mounted Hono instance
12324
- *
12325
- * @example
12326
- * ```ts
12327
- * import { Router as IttyRouter } from 'itty-router'
12328
- * import { Hono } from 'hono'
12329
- * // Create itty-router application
12330
- * const ittyRouter = IttyRouter()
12331
- * // GET /itty-router/hello
12332
- * ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
12333
- *
12334
- * const app = new Hono()
12335
- * app.mount('/itty-router', ittyRouter.handle)
12336
- * ```
12337
- *
12338
- * @example
12339
- * ```ts
12340
- * const app = new Hono()
12341
- * // Send the request to another application without modification.
12342
- * app.mount('/app', anotherApp, {
12343
- * replaceRequest: (req) => req,
12344
- * })
12345
- * ```
12346
- */
12277
+ * `.mount()` allows you to mount applications built with other frameworks into your Hono application.
12278
+ *
12279
+ * @deprecated Use `mount()` from `hono/mount` instead. `.mount()` will be removed in v5.
12280
+ *
12281
+ * @see {@link https://hono.dev/docs/api/hono#mount}
12282
+ *
12283
+ * @param {string} path - base Path
12284
+ * @param {Function} applicationHandler - other Request Handler
12285
+ * @param {MountOptions} [options] - options of `.mount()`
12286
+ * @returns {Hono} mounted Hono instance
12287
+ * @throws {Error} If automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
12288
+ * @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
12289
+ *
12290
+ * @example
12291
+ * ```ts
12292
+ * import { Router as IttyRouter } from 'itty-router'
12293
+ * import { Hono } from 'hono'
12294
+ * // Create itty-router application
12295
+ * const ittyRouter = IttyRouter()
12296
+ * // GET /itty-router/hello
12297
+ * ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
12298
+ *
12299
+ * const app = new Hono()
12300
+ * app.mount('/itty-router', ittyRouter.handle)
12301
+ * ```
12302
+ *
12303
+ * @example
12304
+ * ```ts
12305
+ * const app = new Hono()
12306
+ * // Send the request to another application without modification.
12307
+ * app.mount('/app', anotherApp, {
12308
+ * replaceRequest: (req) => req,
12309
+ * })
12310
+ * ```
12311
+ */
12347
12312
  mount(path, applicationHandler, options) {
12348
12313
  let replaceRequest;
12349
12314
  let optionHandler;
12350
12315
  if (options) {
12351
- if (typeof options === "function") {
12352
- optionHandler = options;
12353
- } else {
12316
+ if (typeof options === "function") optionHandler = options;
12317
+ else {
12354
12318
  optionHandler = options.optionHandler;
12355
- if (options.replaceRequest === false) {
12356
- replaceRequest = /* @__PURE__ */ __name((request) => request, "replaceRequest");
12357
- } else {
12358
- replaceRequest = options.replaceRequest;
12359
- }
12319
+ if (options.replaceRequest === false) replaceRequest = /* @__PURE__ */ __name((request) => request, "replaceRequest");
12320
+ else replaceRequest = options.replaceRequest;
12360
12321
  }
12361
12322
  }
12362
12323
  const getOptions = optionHandler ? (c) => {
@@ -12370,27 +12331,19 @@ var Hono = class _Hono {
12370
12331
  }
12371
12332
  return [c.env, executionContext];
12372
12333
  };
12373
- replaceRequest ||= (() => {
12374
- const mergedPath = mergePath(this._basePath, path);
12375
- const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
12376
- return (request) => {
12377
- const url = new URL(request.url);
12378
- url.pathname = this.getPath(request).slice(pathPrefixLength) || "/";
12379
- return new Request(url, request);
12380
- };
12381
- })();
12334
+ const defaultReplaceRequest = /* @__PURE__ */ __name((c) => {
12335
+ const mountedRoutePath = routePath(c);
12336
+ return createMountedRequest(c, mountedRoutePath.replace(/\/?\*$/, ""), mountedRoutePath);
12337
+ }, "defaultReplaceRequest");
12382
12338
  const handler = /* @__PURE__ */ __name(async (c, next) => {
12383
- const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
12384
- if (res) {
12385
- return res;
12386
- }
12339
+ const res = await applicationHandler(replaceRequest ? replaceRequest(c.req.raw) : defaultReplaceRequest(c), ...getOptions(c));
12340
+ if (res) return res;
12387
12341
  await next();
12388
12342
  }, "handler");
12389
- this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
12343
+ this.#addRoute("ALL", mergePath(path, "*"), handler);
12390
12344
  return this;
12391
12345
  }
12392
12346
  #addRoute(method, path, handler, baseRoutePath) {
12393
- method = method.toUpperCase();
12394
12347
  path = mergePath(this._basePath, path);
12395
12348
  const r = {
12396
12349
  basePath: baseRoutePath !== void 0 ? mergePath(this._basePath, baseRoutePath) : this._basePath,
@@ -12402,15 +12355,11 @@ var Hono = class _Hono {
12402
12355
  this.routes.push(r);
12403
12356
  }
12404
12357
  #handleError(err, c) {
12405
- if (err instanceof Error) {
12406
- return this.errorHandler(err, c);
12407
- }
12358
+ if (err instanceof Error) return this.errorHandler(err, c);
12408
12359
  throw err;
12409
12360
  }
12410
12361
  #dispatch(request, executionCtx, env2, method) {
12411
- if (method === "HEAD") {
12412
- return (async () => new Response(null, await this.#dispatch(request, executionCtx, env2, "GET")))();
12413
- }
12362
+ if (method === "HEAD") return (async () => new Response(null, await this.#dispatch(request, executionCtx, env2, "GET")))();
12414
12363
  const path = this.getPath(request, { env: env2 });
12415
12364
  const matchResult = this.router.match(method, path);
12416
12365
  const c = new Context(request, {
@@ -12429,19 +12378,13 @@ var Hono = class _Hono {
12429
12378
  } catch (err) {
12430
12379
  return this.#handleError(err, c);
12431
12380
  }
12432
- return res instanceof Promise ? res.then(
12433
- (resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))
12434
- ).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
12381
+ return res instanceof Promise ? res.then((resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
12435
12382
  }
12436
12383
  const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
12437
12384
  return (async () => {
12438
12385
  try {
12439
12386
  const context = await composed(c);
12440
- if (!context.finalized) {
12441
- throw new Error(
12442
- "Context is not finalized. Did you forget to return a Response object or `await next()`?"
12443
- );
12444
- }
12387
+ if (!context.finalized) throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
12445
12388
  return context.res;
12446
12389
  } catch (err) {
12447
12390
  return this.#handleError(err, c);
@@ -12449,62 +12392,53 @@ var Hono = class _Hono {
12449
12392
  })();
12450
12393
  }
12451
12394
  /**
12452
- * `.fetch()` will be entry point of your app.
12453
- *
12454
- * @see {@link https://hono.dev/docs/api/hono#fetch}
12455
- *
12456
- * @param {Request} request - request Object of request
12457
- * @param {Env} Env - env Object
12458
- * @param {ExecutionContext} - context of execution
12459
- * @returns {Response | Promise<Response>} response of request
12460
- *
12461
- */
12395
+ * `.fetch()` will be entry point of your app.
12396
+ *
12397
+ * @see {@link https://hono.dev/docs/api/hono#fetch}
12398
+ *
12399
+ * @param {Request} request - request Object of request
12400
+ * @param {Env} env - env Object
12401
+ * @param {ExecutionContext} executionCtx - context of execution
12402
+ * @returns {Response | Promise<Response>} response of request
12403
+ *
12404
+ */
12462
12405
  fetch = /* @__PURE__ */ __name((request, ...rest) => {
12463
12406
  return this.#dispatch(request, rest[1], rest[0], request.method);
12464
12407
  }, "fetch");
12465
12408
  /**
12466
- * `.request()` is a useful method for testing.
12467
- * You can pass a URL or pathname to send a GET request.
12468
- * app will return a Response object.
12469
- * ```ts
12470
- * test('GET /hello is ok', async () => {
12471
- * const res = await app.request('/hello')
12472
- * expect(res.status).toBe(200)
12473
- * })
12474
- * ```
12475
- * @see https://hono.dev/docs/api/hono#request
12476
- */
12409
+ * `.request()` is a useful method for testing.
12410
+ * You can pass a URL or pathname to send a GET request.
12411
+ * app will return a Response object.
12412
+ * ```ts
12413
+ * test('GET /hello is ok', async () => {
12414
+ * const res = await app.request('/hello')
12415
+ * expect(res.status).toBe(200)
12416
+ * })
12417
+ * ```
12418
+ * @see https://hono.dev/docs/api/hono#request
12419
+ */
12477
12420
  request = /* @__PURE__ */ __name((input, requestInit, Env, executionCtx) => {
12478
- if (input instanceof Request) {
12479
- return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
12480
- }
12421
+ if (input instanceof Request) return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
12481
12422
  input = input.toString();
12482
- return this.fetch(
12483
- new Request(
12484
- /^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`,
12485
- requestInit
12486
- ),
12487
- Env,
12488
- executionCtx
12489
- );
12423
+ return this.fetch(new Request(/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`, requestInit), Env, executionCtx);
12490
12424
  }, "request");
12491
12425
  /**
12492
- * `.fire()` automatically adds a global fetch event listener.
12493
- * This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
12494
- * @deprecated
12495
- * Use `fire` from `hono/service-worker` instead.
12496
- * ```ts
12497
- * import { Hono } from 'hono'
12498
- * import { fire } from 'hono/service-worker'
12499
- *
12500
- * const app = new Hono()
12501
- * // ...
12502
- * fire(app)
12503
- * ```
12504
- * @see https://hono.dev/docs/api/hono#fire
12505
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
12506
- * @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
12507
- */
12426
+ * `.fire()` automatically adds a global fetch event listener.
12427
+ * This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
12428
+ * @deprecated
12429
+ * Use `fire` from `hono/service-worker` instead.
12430
+ * ```ts
12431
+ * import { Hono } from 'hono'
12432
+ * import { fire } from 'hono/service-worker'
12433
+ *
12434
+ * const app = new Hono()
12435
+ * // ...
12436
+ * fire(app)
12437
+ * ```
12438
+ * @see https://hono.dev/docs/api/hono#fire
12439
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
12440
+ * @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
12441
+ */
12508
12442
  fire = /* @__PURE__ */ __name(() => {
12509
12443
  addEventListener("fetch", (event) => {
12510
12444
  event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
@@ -12512,181 +12446,171 @@ var Hono = class _Hono {
12512
12446
  }, "fire");
12513
12447
  };
12514
12448
 
12515
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/matcher.js
12449
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/utils.js
12450
+ var createNullObject = /* @__PURE__ */ __name(() => /* @__PURE__ */ Object.create(null), "createNullObject");
12451
+
12452
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/reg-exp-router/matcher.js
12516
12453
  var emptyParam = [];
12517
12454
  function match(method, path) {
12518
12455
  const matchers = this.buildAllMatchers();
12519
12456
  const match2 = /* @__PURE__ */ __name(((method2, path2) => {
12520
- const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
12457
+ const matcher = matchers[method2] || matchers["ALL"];
12521
12458
  const staticMatch = matcher[2][path2];
12522
- if (staticMatch) {
12523
- return staticMatch;
12524
- }
12459
+ if (staticMatch) return staticMatch;
12525
12460
  const match3 = path2.match(matcher[0]);
12526
- if (!match3) {
12527
- return [[], emptyParam];
12528
- }
12461
+ if (!match3) return [[], emptyParam];
12529
12462
  const index = match3.indexOf("", 1);
12530
12463
  return [matcher[1][index], match3];
12531
- }), "match2");
12464
+ }), "match");
12532
12465
  this.match = match2;
12533
12466
  return match2(method, path);
12534
12467
  }
12535
12468
  __name(match, "match");
12536
12469
 
12537
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/node.js
12470
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/reg-exp-router/node.js
12538
12471
  var LABEL_REG_EXP_STR = "[^/]+";
12539
- var ONLY_WILDCARD_REG_EXP_STR = ".*";
12540
- var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
12472
+ var ONLY_WILDCARD_REG_EXP_STR = "[^]*";
12473
+ var TAIL_WILDCARD_REG_EXP_STR = "(?:|/[^]*)";
12541
12474
  var PATH_ERROR = /* @__PURE__ */ Symbol();
12542
- var regExpMetaChars = new Set(".\\+*[^]$()");
12475
+ var regExpMetaChars = /* @__PURE__ */ new Set(".\\+*[^]$()");
12543
12476
  function compareKey(a, b) {
12544
- if (a.length === 1) {
12545
- return b.length === 1 ? a < b ? -1 : 1 : -1;
12546
- }
12547
- if (b.length === 1) {
12548
- return 1;
12549
- }
12550
- if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
12551
- return 1;
12552
- } else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
12553
- return -1;
12554
- }
12555
- if (a === LABEL_REG_EXP_STR) {
12556
- return 1;
12557
- } else if (b === LABEL_REG_EXP_STR) {
12558
- return -1;
12559
- }
12477
+ if (a.length === 1) return b.length === 1 ? a < b ? -1 : 1 : -1;
12478
+ if (b.length === 1) return 1;
12479
+ if (a === "[^]*" || a === "(?:|/[^]*)") return b === "[^]*" ? -1 : 1;
12480
+ else if (b === "[^]*" || b === "(?:|/[^]*)") return -1;
12481
+ if (a === "[^/]+") return 1;
12482
+ else if (b === "[^/]+") return -1;
12560
12483
  return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
12561
12484
  }
12562
12485
  __name(compareKey, "compareKey");
12563
- var Node = class _Node {
12486
+ var Node = class Node2 {
12564
12487
  static {
12565
- __name(this, "_Node");
12488
+ __name(this, "Node");
12566
12489
  }
12567
12490
  #index;
12568
12491
  #varIndex;
12569
- #children = /* @__PURE__ */ Object.create(null);
12570
- insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
12571
- if (tokens.length === 0) {
12572
- if (this.#index !== void 0) {
12573
- throw PATH_ERROR;
12574
- }
12575
- if (pathErrorCheckOnly) {
12576
- return;
12577
- }
12578
- this.#index = index;
12579
- return;
12580
- }
12581
- const [token, ...restTokens] = tokens;
12582
- const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
12583
- let node;
12584
- if (pattern) {
12585
- const name = pattern[1];
12586
- let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
12587
- if (name && pattern[2]) {
12588
- if (regexpStr === ".*") {
12589
- throw PATH_ERROR;
12590
- }
12591
- regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
12592
- if (/\((?!\?:)/.test(regexpStr)) {
12593
- throw PATH_ERROR;
12594
- }
12595
- }
12596
- node = this.#children[regexpStr];
12597
- if (!node) {
12598
- if (Object.keys(this.#children).some(
12599
- (k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
12600
- )) {
12601
- throw PATH_ERROR;
12492
+ #children = createNullObject();
12493
+ insert(tokens, index, paramMap, context, keys) {
12494
+ let node = this;
12495
+ for (let i = 0, len = tokens.length; i < len; i++) {
12496
+ const token = tokens[i];
12497
+ const pattern = token.length === 1 ? token === "*" ? i === len - 1 ? [
12498
+ "",
12499
+ "",
12500
+ ONLY_WILDCARD_REG_EXP_STR
12501
+ ] : [
12502
+ "",
12503
+ "",
12504
+ LABEL_REG_EXP_STR
12505
+ ] : null : token === "/*" ? [
12506
+ "",
12507
+ "",
12508
+ TAIL_WILDCARD_REG_EXP_STR
12509
+ ] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
12510
+ let nextNode;
12511
+ if (pattern) {
12512
+ const name = pattern[1];
12513
+ let regexpStr = pattern[2] || "[^/]+";
12514
+ if (name && pattern[2]) {
12515
+ if (new RegExp(regexpStr).test("")) throw PATH_ERROR;
12516
+ regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
12517
+ if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
12518
+ if (regexpStr.length === 1 && regExpMetaChars.has(regexpStr)) throw PATH_ERROR;
12602
12519
  }
12603
- if (pathErrorCheckOnly) {
12604
- return;
12520
+ keys.push(regexpStr);
12521
+ nextNode = node.#children[regexpStr];
12522
+ if (!nextNode) {
12523
+ if (regexpStr !== "[^]*" && regexpStr !== "(?:|/[^]*)") {
12524
+ for (const k in node.#children) if ((regexpStr.length > 1 || k.length > 1) && k !== "[^]*" && k !== "(?:|/[^]*)") throw PATH_ERROR;
12525
+ }
12526
+ nextNode = node.#children[regexpStr] = new Node2();
12605
12527
  }
12606
- node = this.#children[regexpStr] = new _Node();
12607
12528
  if (name !== "") {
12608
- node.#varIndex = context.varIndex++;
12609
- }
12610
- }
12611
- if (!pathErrorCheckOnly && name !== "") {
12612
- paramMap.push([name, node.#varIndex]);
12613
- }
12614
- } else {
12615
- node = this.#children[token];
12616
- if (!node) {
12617
- if (Object.keys(this.#children).some(
12618
- (k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
12619
- )) {
12620
- throw PATH_ERROR;
12529
+ nextNode.#varIndex ??= context.varIndex++;
12530
+ paramMap.push([name, nextNode.#varIndex]);
12621
12531
  }
12622
- if (pathErrorCheckOnly) {
12623
- return;
12532
+ } else {
12533
+ keys.push(token);
12534
+ nextNode = node.#children[token];
12535
+ if (!nextNode) {
12536
+ for (const k in node.#children) if (k.length > 1 && k !== "[^]*" && k !== "(?:|/[^]*)") throw PATH_ERROR;
12537
+ nextNode = node.#children[token] = new Node2();
12624
12538
  }
12625
- node = this.#children[token] = new _Node();
12626
12539
  }
12540
+ node = nextNode;
12627
12541
  }
12628
- node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
12542
+ if (node.#index !== void 0) throw PATH_ERROR;
12543
+ node.#index = index;
12629
12544
  }
12630
12545
  buildRegExpStr() {
12631
- const childKeys = Object.keys(this.#children).sort(compareKey);
12632
- const strList = childKeys.map((k) => {
12546
+ const strList = Object.keys(this.#children).sort(compareKey).map((k) => {
12633
12547
  const c = this.#children[k];
12634
- return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
12635
- });
12636
- if (typeof this.#index === "number") {
12637
- strList.unshift(`#${this.#index}`);
12638
- }
12639
- if (strList.length === 0) {
12640
- return "";
12641
- }
12642
- if (strList.length === 1) {
12643
- return strList[0];
12644
- }
12548
+ const childStr = c.buildRegExpStr();
12549
+ return childStr === "" ? "" : (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + childStr;
12550
+ }).filter(Boolean);
12551
+ if (typeof this.#index === "number" && this.#index !== -1) strList.unshift(`#${this.#index}`);
12552
+ if (strList.length === 0) return "";
12553
+ if (strList.length === 1) return strList[0];
12645
12554
  return "(?:" + strList.join("|") + ")";
12646
12555
  }
12647
12556
  };
12648
12557
 
12649
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/trie.js
12558
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/reg-exp-router/trie.js
12650
12559
  var Trie = class {
12651
12560
  static {
12652
12561
  __name(this, "Trie");
12653
12562
  }
12654
12563
  #context = { varIndex: 0 };
12655
12564
  #root = new Node();
12656
- insert(path, index, pathErrorCheckOnly) {
12565
+ #index = 0;
12566
+ paths = createNullObject();
12567
+ insert(path, isStatic) {
12568
+ const keys = [];
12569
+ if (isStatic) {
12570
+ this.#root.insert(path.split(""), -1, [], this.#context, keys);
12571
+ this.paths[path] = [
12572
+ -1,
12573
+ [],
12574
+ keys
12575
+ ];
12576
+ return;
12577
+ }
12657
12578
  const paramAssoc = [];
12658
12579
  const groups = [];
12580
+ let markedPath = path;
12659
12581
  for (let i = 0; ; ) {
12660
12582
  let replaced = false;
12661
- path = path.replace(/\{[^}]+\}/g, (m) => {
12583
+ markedPath = markedPath.replace(/\{(?:\{[\d,]+\}|[^}])+\}/g, (m) => {
12662
12584
  const mark = `@\\${i}`;
12663
12585
  groups[i] = [mark, m];
12664
12586
  i++;
12665
12587
  replaced = true;
12666
12588
  return mark;
12667
12589
  });
12668
- if (!replaced) {
12669
- break;
12670
- }
12590
+ if (!replaced) break;
12671
12591
  }
12672
- const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
12592
+ const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./gs) || [];
12673
12593
  for (let i = groups.length - 1; i >= 0; i--) {
12674
12594
  const [mark] = groups[i];
12675
- for (let j = tokens.length - 1; j >= 0; j--) {
12676
- if (tokens[j].indexOf(mark) !== -1) {
12677
- tokens[j] = tokens[j].replace(mark, groups[i][1]);
12678
- break;
12679
- }
12595
+ for (let j = tokens.length - 1; j >= 0; j--) if (tokens[j].indexOf(mark) !== -1) {
12596
+ tokens[j] = tokens[j].replace(mark, groups[i][1]);
12597
+ break;
12680
12598
  }
12681
12599
  }
12682
- this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
12683
- return paramAssoc;
12600
+ this.#root.insert(tokens, this.#index, paramAssoc, this.#context, keys);
12601
+ this.paths[path] = [
12602
+ this.#index++,
12603
+ paramAssoc,
12604
+ keys
12605
+ ];
12684
12606
  }
12685
12607
  buildRegExp() {
12686
12608
  let regexp = this.#root.buildRegExpStr();
12687
- if (regexp === "") {
12688
- return [/^$/, [], []];
12689
- }
12609
+ if (regexp === "") return [
12610
+ /^$/,
12611
+ [],
12612
+ []
12613
+ ];
12690
12614
  let captureIndex = 0;
12691
12615
  const indexReplacementMap = [];
12692
12616
  const paramReplacementMap = [];
@@ -12701,197 +12625,102 @@ var Trie = class {
12701
12625
  }
12702
12626
  return "";
12703
12627
  });
12704
- return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap];
12628
+ return [
12629
+ new RegExp(`^${regexp}`),
12630
+ indexReplacementMap,
12631
+ paramReplacementMap
12632
+ ];
12705
12633
  }
12706
12634
  };
12707
12635
 
12708
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/reg-exp-router/router.js
12709
- var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
12710
- var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
12711
- function buildWildcardRegExp(path) {
12712
- return wildcardRegExpCache[path] ??= new RegExp(
12713
- path === "*" ? "" : `^${path.replace(
12714
- /\/\*$|([.\\+*[^\]$()])/g,
12715
- (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
12716
- )}$`
12717
- );
12718
- }
12719
- __name(buildWildcardRegExp, "buildWildcardRegExp");
12720
- function clearWildcardRegExpCache() {
12721
- wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
12722
- }
12723
- __name(clearWildcardRegExpCache, "clearWildcardRegExpCache");
12724
- function buildMatcherFromPreprocessedRoutes(routes) {
12725
- const trie = new Trie();
12726
- const handlerData = [];
12727
- if (routes.length === 0) {
12728
- return nullMatcher;
12729
- }
12730
- const routesWithStaticPathFlag = routes.map(
12731
- (route) => [!/\*|\/:/.test(route[0]), ...route]
12732
- ).sort(
12733
- ([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
12734
- );
12735
- const staticMap = /* @__PURE__ */ Object.create(null);
12736
- for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
12737
- const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
12738
- if (pathErrorCheckOnly) {
12739
- staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
12740
- } else {
12741
- j++;
12742
- }
12743
- let paramAssoc;
12744
- try {
12745
- paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
12746
- } catch (e) {
12747
- throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
12748
- }
12749
- if (pathErrorCheckOnly) {
12750
- continue;
12751
- }
12752
- handlerData[j] = handlers.map(([h, paramCount]) => {
12753
- const paramIndexMap = /* @__PURE__ */ Object.create(null);
12754
- paramCount -= 1;
12755
- for (; paramCount >= 0; paramCount--) {
12756
- const [key, value] = paramAssoc[paramCount];
12757
- paramIndexMap[key] = value;
12758
- }
12759
- return [h, paramIndexMap];
12760
- });
12761
- }
12762
- const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
12763
- for (let i = 0, len = handlerData.length; i < len; i++) {
12764
- for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
12765
- const map = handlerData[i][j]?.[1];
12766
- if (!map) {
12767
- continue;
12768
- }
12769
- const keys = Object.keys(map);
12770
- for (let k = 0, len3 = keys.length; k < len3; k++) {
12771
- map[keys[k]] = paramReplacementMap[map[keys[k]]];
12772
- }
12773
- }
12774
- }
12775
- const handlerMap = [];
12776
- for (const i in indexReplacementMap) {
12777
- handlerMap[i] = handlerData[indexReplacementMap[i]];
12778
- }
12779
- return [regexp, handlerMap, staticMap];
12636
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/reg-exp-router/router.js
12637
+ function endsWithWildcard(keys) {
12638
+ const tail = keys[keys.length - 1];
12639
+ return tail === "[^]*" || tail === "(?:|/[^]*)";
12780
12640
  }
12781
- __name(buildMatcherFromPreprocessedRoutes, "buildMatcherFromPreprocessedRoutes");
12782
- function findMiddleware(middleware, path) {
12783
- if (!middleware) {
12784
- return void 0;
12785
- }
12786
- for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
12787
- if (buildWildcardRegExp(k).test(path)) {
12788
- return [...middleware[k]];
12789
- }
12790
- }
12791
- return void 0;
12641
+ __name(endsWithWildcard, "endsWithWildcard");
12642
+ function covers(wildcard, target) {
12643
+ const last = wildcard.length - 1;
12644
+ for (let i = 0; i < last; i++) if (wildcard[i] !== target[i]) return false;
12645
+ return wildcard[last] === "[^]*" || target.length === last || target[last] === "/";
12792
12646
  }
12793
- __name(findMiddleware, "findMiddleware");
12647
+ __name(covers, "covers");
12794
12648
  var RegExpRouter = class {
12795
12649
  static {
12796
12650
  __name(this, "RegExpRouter");
12797
12651
  }
12798
12652
  name = "RegExpRouter";
12799
- #middleware;
12800
- #routes;
12653
+ #handlers;
12654
+ #tries;
12801
12655
  constructor() {
12802
- this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
12803
- this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
12656
+ this.#handlers = { ["ALL"]: [] };
12657
+ this.#tries = { ["ALL"]: new Trie() };
12804
12658
  }
12805
- add(method, path, handler) {
12806
- const middleware = this.#middleware;
12807
- const routes = this.#routes;
12808
- if (!middleware || !routes) {
12809
- throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
12810
- }
12811
- if (!middleware[method]) {
12812
- ;
12813
- [middleware, routes].forEach((handlerMap) => {
12814
- handlerMap[method] = /* @__PURE__ */ Object.create(null);
12815
- Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
12816
- handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
12817
- });
12818
- });
12819
- }
12820
- if (path === "/*") {
12821
- path = "*";
12822
- }
12823
- const paramCount = (path.match(/\/:/g) || []).length;
12824
- if (/\*$/.test(path)) {
12825
- const re = buildWildcardRegExp(path);
12826
- if (method === METHOD_NAME_ALL) {
12827
- Object.keys(middleware).forEach((m) => {
12828
- middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
12829
- });
12830
- } else {
12831
- middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
12832
- }
12833
- Object.keys(middleware).forEach((m) => {
12834
- if (method === METHOD_NAME_ALL || method === m) {
12835
- Object.keys(middleware[m]).forEach((p) => {
12836
- re.test(p) && middleware[m][p].push([handler, paramCount]);
12837
- });
12838
- }
12839
- });
12840
- Object.keys(routes).forEach((m) => {
12841
- if (method === METHOD_NAME_ALL || method === m) {
12842
- Object.keys(routes[m]).forEach(
12843
- (p) => re.test(p) && routes[m][p].push([handler, paramCount])
12844
- );
12845
- }
12846
- });
12847
- return;
12659
+ #insertPath(method, path) {
12660
+ try {
12661
+ this.#tries[method].insert(path, !/\*|\/:/.test(path));
12662
+ } catch (e) {
12663
+ throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
12848
12664
  }
12665
+ }
12666
+ add(method, path, handler) {
12667
+ const handlers = this.#handlers;
12668
+ if (!handlers) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
12669
+ const tries = this.#tries;
12670
+ if (!handlers[method]) {
12671
+ tries[method] = new Trie();
12672
+ handlers[method] = [...handlers["ALL"]];
12673
+ for (const p in tries["ALL"].paths) this.#insertPath(method, p);
12674
+ }
12675
+ if (path === "/*") path = "*";
12676
+ const methods = method === "ALL" ? Object.keys(handlers) : [method];
12849
12677
  const paths = checkOptionalParameter(path) || [path];
12850
- for (let i = 0, len = paths.length; i < len; i++) {
12851
- const path2 = paths[i];
12852
- Object.keys(routes).forEach((m) => {
12853
- if (method === METHOD_NAME_ALL || method === m) {
12854
- routes[m][path2] ||= [
12855
- ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
12856
- ];
12857
- routes[m][path2].push([handler, paramCount - len + i + 1]);
12858
- }
12859
- });
12678
+ for (const path2 of paths) for (const m of methods) {
12679
+ if (!tries[m].paths[path2]) this.#insertPath(m, path2);
12680
+ handlers[m].push([handler, path2]);
12860
12681
  }
12861
12682
  }
12862
12683
  match = match;
12863
12684
  buildAllMatchers() {
12864
- const matchers = /* @__PURE__ */ Object.create(null);
12865
- Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
12866
- matchers[method] ||= this.#buildMatcher(method);
12867
- });
12868
- this.#middleware = this.#routes = void 0;
12869
- clearWildcardRegExpCache();
12685
+ const matchers = createNullObject();
12686
+ for (const method of Object.keys(this.#handlers)) matchers[method] = this.#buildMatcher(method);
12687
+ this.#handlers = this.#tries = void 0;
12870
12688
  return matchers;
12871
12689
  }
12872
12690
  #buildMatcher(method) {
12873
- const routes = [];
12874
- let hasOwnRoute = method === METHOD_NAME_ALL;
12875
- [this.#middleware, this.#routes].forEach((r) => {
12876
- const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
12877
- if (ownRoute.length !== 0) {
12878
- hasOwnRoute ||= true;
12879
- routes.push(...ownRoute);
12880
- } else if (method !== METHOD_NAME_ALL) {
12881
- routes.push(
12882
- ...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]])
12883
- );
12884
- }
12691
+ const handlers = this.#handlers[method];
12692
+ const trie = this.#tries[method];
12693
+ const staticMap = createNullObject();
12694
+ const handlerData = [];
12695
+ const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
12696
+ const own = createNullObject();
12697
+ const entries = handlers.map(([h, p], i) => {
12698
+ (own[p] ??= []).push(i);
12699
+ return [h, trie.paths[p][1].reduceRight((map, [key, varIndex]) => {
12700
+ map[key] = paramReplacementMap[varIndex];
12701
+ return map;
12702
+ }, createNullObject())];
12885
12703
  });
12886
- if (!hasOwnRoute) {
12887
- return null;
12888
- } else {
12889
- return buildMatcherFromPreprocessedRoutes(routes);
12704
+ const wildcards = Object.keys(own).filter((p) => endsWithWildcard(trie.paths[p][2]));
12705
+ for (const path in trie.paths) {
12706
+ const [index, , keys] = trie.paths[path];
12707
+ const indexes = [...own[path]];
12708
+ for (const p of wildcards) if (p !== path && covers(trie.paths[p][2], keys)) indexes.push(...own[p]);
12709
+ const data = indexes.sort((a, b) => a - b).map((i) => entries[i]);
12710
+ if (index === -1) {
12711
+ const last = Math.max(-1, ...data.flatMap(([, map]) => Object.values(map)));
12712
+ staticMap[path] = [data, last === -1 ? emptyParam : path.match(regexp).slice(0, last + 1)];
12713
+ } else handlerData[index] = data;
12890
12714
  }
12715
+ return [
12716
+ regexp,
12717
+ indexReplacementMap.map((i) => handlerData[i]),
12718
+ staticMap
12719
+ ];
12891
12720
  }
12892
12721
  };
12893
12722
 
12894
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/smart-router/router.js
12723
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/smart-router/router.js
12895
12724
  var SmartRouter = class {
12896
12725
  static {
12897
12726
  __name(this, "SmartRouter");
@@ -12903,15 +12732,15 @@ var SmartRouter = class {
12903
12732
  this.#routers = init.routers;
12904
12733
  }
12905
12734
  add(method, path, handler) {
12906
- if (!this.#routes) {
12907
- throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
12908
- }
12909
- this.#routes.push([method, path, handler]);
12735
+ if (!this.#routes) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
12736
+ this.#routes.push([
12737
+ method,
12738
+ path,
12739
+ handler
12740
+ ]);
12910
12741
  }
12911
12742
  match(method, path) {
12912
- if (!this.#routes) {
12913
- throw new Error("Fatal error");
12914
- }
12743
+ if (!this.#routes) throw new Error("Fatal error");
12915
12744
  const routers = this.#routers;
12916
12745
  const routes = this.#routes;
12917
12746
  const len = routers.length;
@@ -12920,14 +12749,10 @@ var SmartRouter = class {
12920
12749
  for (; i < len; i++) {
12921
12750
  const router = routers[i];
12922
12751
  try {
12923
- for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) {
12924
- router.add(...routes[i2]);
12925
- }
12752
+ for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) router.add(...routes[i2]);
12926
12753
  res = router.match(method, path);
12927
12754
  } catch (e) {
12928
- if (e instanceof UnsupportedPathError) {
12929
- continue;
12930
- }
12755
+ if (e instanceof UnsupportedPathError) continue;
12931
12756
  throw e;
12932
12757
  }
12933
12758
  this.match = router.match.bind(router);
@@ -12935,95 +12760,62 @@ var SmartRouter = class {
12935
12760
  this.#routes = void 0;
12936
12761
  break;
12937
12762
  }
12938
- if (i === len) {
12939
- throw new Error("Fatal error");
12940
- }
12763
+ if (i === len) throw new Error("Fatal error");
12941
12764
  this.name = `SmartRouter + ${this.activeRouter.name}`;
12942
12765
  return res;
12943
12766
  }
12944
12767
  get activeRouter() {
12945
- if (this.#routes || this.#routers.length !== 1) {
12946
- throw new Error("No active router has been determined yet.");
12947
- }
12768
+ if (this.#routes || this.#routers.length !== 1) throw new Error("No active router has been determined yet.");
12948
12769
  return this.#routers[0];
12949
12770
  }
12950
12771
  };
12951
12772
 
12952
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/trie-router/node.js
12953
- var emptyParams = /* @__PURE__ */ Object.create(null);
12954
- var hasChildren = /* @__PURE__ */ __name((children) => {
12955
- for (const _ in children) {
12956
- return true;
12957
- }
12958
- return false;
12959
- }, "hasChildren");
12960
- var Node2 = class _Node2 {
12773
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/trie-router/node.js
12774
+ var emptyParams = createNullObject();
12775
+ var order = 0;
12776
+ var Node3 = class Node4 {
12961
12777
  static {
12962
- __name(this, "_Node");
12778
+ __name(this, "Node");
12963
12779
  }
12964
- #methods;
12965
- #children;
12966
- #patterns;
12967
- #order = 0;
12780
+ #methods = [];
12781
+ #children = createNullObject();
12782
+ #patterns = [];
12783
+ #pattern;
12968
12784
  #params = emptyParams;
12969
- constructor(method, handler, children) {
12970
- this.#children = children || /* @__PURE__ */ Object.create(null);
12971
- this.#methods = [];
12972
- if (method && handler) {
12973
- const m = /* @__PURE__ */ Object.create(null);
12974
- m[method] = { handler, possibleKeys: [], score: 0 };
12975
- this.#methods = [m];
12976
- }
12977
- this.#patterns = [];
12978
- }
12979
12785
  insert(method, path, handler) {
12980
- this.#order = ++this.#order;
12981
12786
  let curNode = this;
12982
12787
  const parts = splitRoutingPath(path);
12983
- const possibleKeys = [];
12984
- for (let i = 0, len = parts.length; i < len; i++) {
12985
- const p = parts[i];
12986
- const nextP = parts[i + 1];
12987
- const pattern = getPattern(p, nextP);
12988
- const key = Array.isArray(pattern) ? pattern[0] : p;
12989
- if (key in curNode.#children) {
12990
- curNode = curNode.#children[key];
12991
- if (pattern) {
12992
- possibleKeys.push(pattern[1]);
12993
- }
12994
- continue;
12995
- }
12996
- curNode.#children[key] = new _Node2();
12997
- if (pattern) {
12998
- curNode.#patterns.push(pattern);
12999
- possibleKeys.push(pattern[1]);
12788
+ const possibleKeys = /* @__PURE__ */ new Set();
12789
+ let i = 0;
12790
+ for (const p of parts) {
12791
+ const nextP = parts[++i];
12792
+ const pattern = getPattern(p, nextP) || (nextP === void 0 && p && p.indexOf("*") === p.length - 1 ? p : null);
12793
+ const isParam = Array.isArray(pattern);
12794
+ const key = isParam ? pattern[0] : pattern || p;
12795
+ const child = curNode.#children[key] ||= new Node4();
12796
+ if (pattern && !child.#pattern) {
12797
+ child.#pattern = pattern;
12798
+ curNode.#patterns.push(child);
13000
12799
  }
13001
- curNode = curNode.#children[key];
12800
+ curNode = child;
12801
+ if (isParam) possibleKeys.add(pattern[1]);
13002
12802
  }
13003
- curNode.#methods.push({
13004
- [method]: {
13005
- handler,
13006
- possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
13007
- score: this.#order
13008
- }
13009
- });
13010
- return curNode;
12803
+ curNode.#methods.push({ [method]: {
12804
+ handler,
12805
+ possibleKeys: [...possibleKeys],
12806
+ score: ++order
12807
+ } });
13011
12808
  }
13012
12809
  #pushHandlerSets(handlerSets, node, method, nodeParams, params) {
13013
12810
  for (let i = 0, len = node.#methods.length; i < len; i++) {
13014
12811
  const m = node.#methods[i];
13015
- const handlerSet = m[method] || m[METHOD_NAME_ALL];
13016
- const processedSet = {};
13017
- if (handlerSet !== void 0) {
13018
- handlerSet.params = /* @__PURE__ */ Object.create(null);
12812
+ const handlerSet = m[method] || m["ALL"];
12813
+ if (handlerSet) {
12814
+ handlerSet.params = createNullObject();
13019
12815
  handlerSets.push(handlerSet);
13020
- if (nodeParams !== emptyParams || params && params !== emptyParams) {
13021
- for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
13022
- const key = handlerSet.possibleKeys[i2];
13023
- const processed = processedSet[handlerSet.score];
13024
- handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
13025
- processedSet[handlerSet.score] = true;
13026
- }
12816
+ for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
12817
+ const key = handlerSet.possibleKeys[i2];
12818
+ handlerSet.params[key] = params?.[key] && !i2 ? params[key] : nodeParams[key] ?? params?.[key];
13027
12819
  }
13028
12820
  }
13029
12821
  }
@@ -13031,8 +12823,7 @@ var Node2 = class _Node2 {
13031
12823
  search(method, path) {
13032
12824
  const handlerSets = [];
13033
12825
  this.#params = emptyParams;
13034
- const curNode = this;
13035
- let curNodes = [curNode];
12826
+ let curNodes = [this];
13036
12827
  const parts = splitPath(path);
13037
12828
  const curNodesQueue = [];
13038
12829
  const len = parts.length;
@@ -13047,76 +12838,54 @@ var Node2 = class _Node2 {
13047
12838
  if (nextNode) {
13048
12839
  nextNode.#params = node.#params;
13049
12840
  if (isLast) {
13050
- if (nextNode.#children["*"]) {
13051
- this.#pushHandlerSets(handlerSets, nextNode.#children["*"], method, node.#params);
13052
- }
12841
+ if (nextNode.#children["*"]) this.#pushHandlerSets(handlerSets, nextNode.#children["*"], method, node.#params);
13053
12842
  this.#pushHandlerSets(handlerSets, nextNode, method, node.#params);
13054
- } else {
13055
- tempNodes.push(nextNode);
13056
- }
12843
+ } else tempNodes.push(nextNode);
13057
12844
  }
13058
- for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
13059
- const pattern = node.#patterns[k];
12845
+ for (const child of node.#patterns) {
12846
+ const pattern = child.#pattern;
13060
12847
  const params = node.#params === emptyParams ? {} : { ...node.#params };
13061
- if (pattern === "*") {
13062
- const astNode = node.#children["*"];
13063
- if (astNode) {
13064
- this.#pushHandlerSets(handlerSets, astNode, method, node.#params);
13065
- astNode.#params = params;
13066
- tempNodes.push(astNode);
12848
+ if (typeof pattern === "string") {
12849
+ if (pattern === "*" || part.startsWith(pattern.slice(0, -1))) {
12850
+ this.#pushHandlerSets(handlerSets, child, method, node.#params);
12851
+ if (pattern === "*") {
12852
+ child.#params = params;
12853
+ tempNodes.push(child);
12854
+ }
13067
12855
  }
13068
12856
  continue;
13069
12857
  }
13070
- const [key, name, matcher] = pattern;
13071
- if (!part && !(matcher instanceof RegExp)) {
13072
- continue;
13073
- }
13074
- const child = node.#children[key];
13075
- if (matcher instanceof RegExp) {
13076
- if (partOffsets === null) {
13077
- partOffsets = new Array(len);
12858
+ const [, name, matcher] = pattern;
12859
+ if (!part && matcher === true) continue;
12860
+ if (matcher !== true) {
12861
+ if (!partOffsets) {
12862
+ partOffsets = [];
13078
12863
  let offset = path[0] === "/" ? 1 : 0;
13079
12864
  for (let p = 0; p < len; p++) {
13080
12865
  partOffsets[p] = offset;
13081
12866
  offset += parts[p].length + 1;
13082
12867
  }
13083
12868
  }
13084
- const restPathString = path.substring(partOffsets[i]);
12869
+ const restPathString = path.slice(partOffsets[i]);
13085
12870
  const m = matcher.exec(restPathString);
13086
12871
  if (m) {
13087
- params[name] = m[0];
12872
+ if (!Object.hasOwn(params, name)) params[name] = m[0];
13088
12873
  this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
13089
- if (m[0].length === restPathString.length && child.#children["*"]) {
13090
- this.#pushHandlerSets(
13091
- handlerSets,
13092
- child.#children["*"],
13093
- method,
13094
- node.#params,
13095
- params
13096
- );
13097
- }
13098
- if (hasChildren(child.#children)) {
12874
+ if (m[0].length === restPathString.length && child.#children["*"]) this.#pushHandlerSets(handlerSets, child.#children["*"], method, node.#params, params);
12875
+ for (const _ in child.#children) {
13099
12876
  child.#params = params;
13100
- const componentCount = m[0].match(/\//)?.length ?? 0;
13101
- const targetCurNodes = curNodesQueue[componentCount] ||= [];
13102
- targetCurNodes.push(child);
12877
+ const componentCount = m[0].match(/\//g)?.length ?? 0;
12878
+ (curNodesQueue[componentCount] ||= []).push(child);
12879
+ break;
13103
12880
  }
13104
12881
  continue;
13105
12882
  }
13106
12883
  }
13107
12884
  if (matcher === true || matcher.test(part)) {
13108
- params[name] = part;
12885
+ if (!Object.hasOwn(params, name)) params[name] = part;
13109
12886
  if (isLast) {
13110
12887
  this.#pushHandlerSets(handlerSets, child, method, params, node.#params);
13111
- if (child.#children["*"]) {
13112
- this.#pushHandlerSets(
13113
- handlerSets,
13114
- child.#children["*"],
13115
- method,
13116
- params,
13117
- node.#params
13118
- );
13119
- }
12888
+ if (child.#children["*"]) this.#pushHandlerSets(handlerSets, child.#children["*"], method, params, node.#params);
13120
12889
  } else {
13121
12890
  child.#params = params;
13122
12891
  tempNodes.push(child);
@@ -13127,55 +12896,41 @@ var Node2 = class _Node2 {
13127
12896
  const shifted = curNodesQueue.shift();
13128
12897
  curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
13129
12898
  }
13130
- if (handlerSets.length > 1) {
13131
- handlerSets.sort((a, b) => {
13132
- return a.score - b.score;
13133
- });
13134
- }
12899
+ if (handlerSets[1]) handlerSets.sort((a, b) => {
12900
+ return a.score - b.score;
12901
+ });
13135
12902
  return [handlerSets.map(({ handler, params }) => [handler, params])];
13136
12903
  }
13137
12904
  };
13138
12905
 
13139
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/router/trie-router/router.js
12906
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/router/trie-router/router.js
13140
12907
  var TrieRouter = class {
13141
12908
  static {
13142
12909
  __name(this, "TrieRouter");
13143
12910
  }
13144
12911
  name = "TrieRouter";
13145
- #node;
13146
- constructor() {
13147
- this.#node = new Node2();
13148
- }
12912
+ #node = new Node3();
13149
12913
  add(method, path, handler) {
13150
- const results = checkOptionalParameter(path);
13151
- if (results) {
13152
- for (let i = 0, len = results.length; i < len; i++) {
13153
- this.#node.insert(method, results[i], handler);
13154
- }
13155
- return;
13156
- }
13157
- this.#node.insert(method, path, handler);
12914
+ for (const result of checkOptionalParameter(path) || [path]) this.#node.insert(method, result, handler);
13158
12915
  }
13159
12916
  match(method, path) {
13160
12917
  return this.#node.search(method, path);
13161
12918
  }
13162
12919
  };
13163
12920
 
13164
- // ../../node_modules/.pnpm/hono@4.12.34/node_modules/hono/dist/hono.js
13165
- var Hono2 = class extends Hono {
12921
+ // ../../node_modules/.pnpm/hono@4.13.21/node_modules/hono/dist/hono.js
12922
+ var Hono3 = class extends Hono {
13166
12923
  static {
13167
12924
  __name(this, "Hono");
13168
12925
  }
13169
12926
  /**
13170
- * Creates an instance of the Hono class.
13171
- *
13172
- * @param options - Optional configuration options for the Hono instance.
13173
- */
12927
+ * Creates an instance of the Hono class.
12928
+ *
12929
+ * @param options - Optional configuration options for the Hono instance.
12930
+ */
13174
12931
  constructor(options = {}) {
13175
12932
  super(options);
13176
- this.router = options.router ?? new SmartRouter({
13177
- routers: [new RegExpRouter(), new TrieRouter()]
13178
- });
12933
+ this.router = options.router ?? new SmartRouter({ routers: [new RegExpRouter(), new TrieRouter()] });
13179
12934
  }
13180
12935
  };
13181
12936
 
@@ -13459,7 +13214,7 @@ var hotUpdater = createHotUpdater({
13459
13214
  }
13460
13215
  })
13461
13216
  });
13462
- var app = new Hono2();
13217
+ var app = new Hono3();
13463
13218
  app.mount(
13464
13219
  HOT_UPDATER_BASE_PATH,
13465
13220
  (request) => hotUpdater.handlers.client(request)