hono 4.9.9 → 4.9.11

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.
@@ -1,5 +1,12 @@
1
1
  // src/adapter/aws-lambda/handler.ts
2
2
  import { decodeBase64, encodeBase64 } from "../../utils/encode.js";
3
+ function sanitizeHeaderValue(value) {
4
+ const hasNonAscii = /[^\x00-\x7F]/.test(value);
5
+ if (!hasNonAscii) {
6
+ return value;
7
+ }
8
+ return encodeURIComponent(value);
9
+ }
3
10
  var getRequestContext = (event) => {
4
11
  return event.requestContext;
5
12
  };
@@ -180,7 +187,7 @@ var EventV1Processor = class extends EventProcessor {
180
187
  if (event.headers) {
181
188
  for (const [k, v] of Object.entries(event.headers)) {
182
189
  if (v) {
183
- headers.set(k, v);
190
+ headers.set(k, sanitizeHeaderValue(v));
184
191
  }
185
192
  }
186
193
  }
@@ -188,7 +195,10 @@ var EventV1Processor = class extends EventProcessor {
188
195
  for (const [k, values] of Object.entries(event.multiValueHeaders)) {
189
196
  if (values) {
190
197
  const foundK = headers.get(k);
191
- values.forEach((v) => (!foundK || !foundK.includes(v)) && headers.append(k, v));
198
+ values.forEach((v) => {
199
+ const sanitizedValue = sanitizeHeaderValue(v);
200
+ return (!foundK || !foundK.includes(sanitizedValue)) && headers.append(k, sanitizedValue);
201
+ });
192
202
  }
193
203
  }
194
204
  }
@@ -207,13 +217,14 @@ var ALBProcessor = class extends EventProcessor {
207
217
  if (event.multiValueHeaders) {
208
218
  for (const [key, values] of Object.entries(event.multiValueHeaders)) {
209
219
  if (values && Array.isArray(values)) {
210
- headers.set(key, values.join("; "));
220
+ const sanitizedValue = sanitizeHeaderValue(values.join("; "));
221
+ headers.set(key, sanitizedValue);
211
222
  }
212
223
  }
213
224
  } else {
214
225
  for (const [key, value] of Object.entries(event.headers ?? {})) {
215
226
  if (value) {
216
- headers.set(key, value);
227
+ headers.set(key, sanitizeHeaderValue(value));
217
228
  }
218
229
  }
219
230
  }
@@ -30,6 +30,13 @@ __export(handler_exports, {
30
30
  });
31
31
  module.exports = __toCommonJS(handler_exports);
32
32
  var import_encode = require("../../utils/encode");
33
+ function sanitizeHeaderValue(value) {
34
+ const hasNonAscii = /[^\x00-\x7F]/.test(value);
35
+ if (!hasNonAscii) {
36
+ return value;
37
+ }
38
+ return encodeURIComponent(value);
39
+ }
33
40
  const getRequestContext = (event) => {
34
41
  return event.requestContext;
35
42
  };
@@ -210,7 +217,7 @@ class EventV1Processor extends EventProcessor {
210
217
  if (event.headers) {
211
218
  for (const [k, v] of Object.entries(event.headers)) {
212
219
  if (v) {
213
- headers.set(k, v);
220
+ headers.set(k, sanitizeHeaderValue(v));
214
221
  }
215
222
  }
216
223
  }
@@ -218,7 +225,10 @@ class EventV1Processor extends EventProcessor {
218
225
  for (const [k, values] of Object.entries(event.multiValueHeaders)) {
219
226
  if (values) {
220
227
  const foundK = headers.get(k);
221
- values.forEach((v) => (!foundK || !foundK.includes(v)) && headers.append(k, v));
228
+ values.forEach((v) => {
229
+ const sanitizedValue = sanitizeHeaderValue(v);
230
+ return (!foundK || !foundK.includes(sanitizedValue)) && headers.append(k, sanitizedValue);
231
+ });
222
232
  }
223
233
  }
224
234
  }
@@ -237,13 +247,14 @@ class ALBProcessor extends EventProcessor {
237
247
  if (event.multiValueHeaders) {
238
248
  for (const [key, values] of Object.entries(event.multiValueHeaders)) {
239
249
  if (values && Array.isArray(values)) {
240
- headers.set(key, values.join("; "));
250
+ const sanitizedValue = sanitizeHeaderValue(values.join("; "));
251
+ headers.set(key, sanitizedValue);
241
252
  }
242
253
  }
243
254
  } else {
244
255
  for (const [key, value] of Object.entries(event.headers ?? {})) {
245
256
  if (value) {
246
- headers.set(key, value);
257
+ headers.set(key, sanitizeHeaderValue(value));
247
258
  }
248
259
  }
249
260
  }
@@ -18,11 +18,18 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var reg_exp_router_exports = {};
20
20
  __export(reg_exp_router_exports, {
21
- RegExpRouter: () => import_router.RegExpRouter
21
+ PreparedRegExpRouter: () => import_prepared_router.PreparedRegExpRouter,
22
+ RegExpRouter: () => import_router.RegExpRouter,
23
+ buildInitParams: () => import_prepared_router.buildInitParams,
24
+ serializeInitParams: () => import_prepared_router.serializeInitParams
22
25
  });
23
26
  module.exports = __toCommonJS(reg_exp_router_exports);
24
27
  var import_router = require("./router");
28
+ var import_prepared_router = require("./prepared-router");
25
29
  // Annotate the CommonJS export names for ESM import in node:
26
30
  0 && (module.exports = {
27
- RegExpRouter
31
+ PreparedRegExpRouter,
32
+ RegExpRouter,
33
+ buildInitParams,
34
+ serializeInitParams
28
35
  });
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var matcher_exports = {};
20
+ __export(matcher_exports, {
21
+ buildAllMatchersKey: () => buildAllMatchersKey,
22
+ emptyParam: () => emptyParam,
23
+ match: () => match
24
+ });
25
+ module.exports = __toCommonJS(matcher_exports);
26
+ var import_router = require("../../router");
27
+ const emptyParam = [];
28
+ const buildAllMatchersKey = Symbol("buildAllMatchers");
29
+ function match(method, path) {
30
+ const matchers = this[buildAllMatchersKey]();
31
+ const match2 = (method2, path2) => {
32
+ const matcher = matchers[method2] || matchers[import_router.METHOD_NAME_ALL];
33
+ const staticMatch = matcher[2][path2];
34
+ if (staticMatch) {
35
+ return staticMatch;
36
+ }
37
+ const match3 = path2.match(matcher[0]);
38
+ if (!match3) {
39
+ return [[], emptyParam];
40
+ }
41
+ const index = match3.indexOf("", 1);
42
+ return [matcher[1][index], match3];
43
+ };
44
+ this.match = match2;
45
+ return match2(method, path);
46
+ }
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ buildAllMatchersKey,
50
+ emptyParam,
51
+ match
52
+ });
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var prepared_router_exports = {};
20
+ __export(prepared_router_exports, {
21
+ PreparedRegExpRouter: () => PreparedRegExpRouter,
22
+ buildInitParams: () => buildInitParams,
23
+ serializeInitParams: () => serializeInitParams
24
+ });
25
+ module.exports = __toCommonJS(prepared_router_exports);
26
+ var import_router = require("../../router");
27
+ var import_matcher = require("./matcher");
28
+ var import_router2 = require("./router");
29
+ class PreparedRegExpRouter {
30
+ name = "PreparedRegExpRouter";
31
+ #matchers;
32
+ #relocateMap;
33
+ constructor(matchers, relocateMap) {
34
+ this.#matchers = matchers;
35
+ this.#relocateMap = relocateMap;
36
+ }
37
+ add(method, path, handler) {
38
+ const all = this.#matchers[import_router.METHOD_NAME_ALL];
39
+ this.#matchers[method] ||= [
40
+ all[0],
41
+ all[1].map((list) => Array.isArray(list) ? list.slice() : 0),
42
+ Object.keys(all[2]).reduce((obj, key) => {
43
+ obj[key] = [all[2][key][0].slice(), import_matcher.emptyParam];
44
+ return obj;
45
+ }, {})
46
+ ];
47
+ if (path === "/*" || path === "*") {
48
+ const defaultHandlerData = [handler, {}];
49
+ (method === import_router.METHOD_NAME_ALL ? Object.keys(this.#matchers) : [method]).forEach((m) => {
50
+ const matcher = this.#matchers[m];
51
+ matcher[1].forEach((list) => list && list.push(defaultHandlerData));
52
+ Object.values(matcher[2]).forEach(
53
+ (list) => list[0].push(defaultHandlerData)
54
+ );
55
+ });
56
+ return;
57
+ }
58
+ const data = this.#relocateMap[path];
59
+ if (!data) {
60
+ throw new Error(`Path ${path} is not registered`);
61
+ }
62
+ for (const [indexes, map] of data) {
63
+ ;
64
+ (method === import_router.METHOD_NAME_ALL ? Object.keys(this.#matchers) : [method]).forEach((m) => {
65
+ const matcher = this.#matchers[m];
66
+ if (!map) {
67
+ matcher[2][path][0].push([handler, {}]);
68
+ } else {
69
+ indexes.forEach((index) => {
70
+ if (typeof index === "number") {
71
+ matcher[1][index].push([handler, map]);
72
+ } else {
73
+ ;
74
+ matcher[2][index || path][0].push([handler, map]);
75
+ }
76
+ });
77
+ }
78
+ });
79
+ }
80
+ }
81
+ [import_matcher.buildAllMatchersKey]() {
82
+ return this.#matchers;
83
+ }
84
+ match = import_matcher.match;
85
+ }
86
+ const buildInitParams = ({ paths }) => {
87
+ const router = new import_router2.RegExpRouter();
88
+ for (const path of paths) {
89
+ router.add(import_router.METHOD_NAME_ALL, path, path);
90
+ }
91
+ const matchers = router[import_matcher.buildAllMatchersKey]();
92
+ const all = matchers[import_router.METHOD_NAME_ALL];
93
+ const relocateMap = {};
94
+ for (const path of paths) {
95
+ all[1].forEach((list, i) => {
96
+ list.forEach(([p, map]) => {
97
+ if (p === path) {
98
+ if (relocateMap[path]) {
99
+ relocateMap[path][0][1] = {
100
+ ...relocateMap[path][0][1],
101
+ ...map
102
+ };
103
+ } else {
104
+ relocateMap[path] = [[[], map]];
105
+ }
106
+ if (relocateMap[path][0][0].findIndex((j) => j === i) === -1) {
107
+ relocateMap[path][0][0].push(i);
108
+ }
109
+ }
110
+ });
111
+ });
112
+ for (const path2 in all[2]) {
113
+ all[2][path2][0].forEach(([p]) => {
114
+ if (p === path) {
115
+ relocateMap[path] ||= [[[], void 0]];
116
+ const value = path2 === path ? "" : path2;
117
+ if (relocateMap[path][0][0].findIndex((v) => v === value) === -1) {
118
+ relocateMap[path][0][0].push(value);
119
+ }
120
+ }
121
+ });
122
+ }
123
+ }
124
+ for (let i = 0, len = all[1].length; i < len; i++) {
125
+ all[1][i] = all[1][i] ? [] : 0;
126
+ }
127
+ for (const path in all[2]) {
128
+ all[2][path][0] = [];
129
+ }
130
+ return [matchers, relocateMap];
131
+ };
132
+ const serializeInitParams = ([matchers, relocateMap]) => {
133
+ for (const method in matchers) {
134
+ const matcher = matchers[method];
135
+ matcher[0].toJSON = function() {
136
+ return `@${this.toString()}@`;
137
+ };
138
+ }
139
+ const matchersStr = JSON.stringify(matchers).replace(
140
+ /"@(.+?)@"/g,
141
+ (_, str) => str.replace(/\\\\/g, "\\")
142
+ );
143
+ const relocateMapStr = JSON.stringify(relocateMap);
144
+ return `[${matchersStr},${relocateMapStr}]`;
145
+ };
146
+ // Annotate the CommonJS export names for ESM import in node:
147
+ 0 && (module.exports = {
148
+ PreparedRegExpRouter,
149
+ buildInitParams,
150
+ serializeInitParams
151
+ });
@@ -23,9 +23,9 @@ __export(router_exports, {
23
23
  module.exports = __toCommonJS(router_exports);
24
24
  var import_router = require("../../router");
25
25
  var import_url = require("../../utils/url");
26
+ var import_matcher = require("./matcher");
26
27
  var import_node = require("./node");
27
28
  var import_trie = require("./trie");
28
- const emptyParam = [];
29
29
  const nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
30
30
  let wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
31
31
  function buildWildcardRegExp(path) {
@@ -54,7 +54,7 @@ function buildMatcherFromPreprocessedRoutes(routes) {
54
54
  for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
55
55
  const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
56
56
  if (pathErrorCheckOnly) {
57
- staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
57
+ staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), import_matcher.emptyParam];
58
58
  } else {
59
59
  j++;
60
60
  }
@@ -172,30 +172,14 @@ class RegExpRouter {
172
172
  });
173
173
  }
174
174
  }
175
- match(method, path) {
176
- clearWildcardRegExpCache();
177
- const matchers = this.#buildAllMatchers();
178
- this.match = (method2, path2) => {
179
- const matcher = matchers[method2] || matchers[import_router.METHOD_NAME_ALL];
180
- const staticMatch = matcher[2][path2];
181
- if (staticMatch) {
182
- return staticMatch;
183
- }
184
- const match = path2.match(matcher[0]);
185
- if (!match) {
186
- return [[], emptyParam];
187
- }
188
- const index = match.indexOf("", 1);
189
- return [matcher[1][index], match];
190
- };
191
- return this.match(method, path);
192
- }
193
- #buildAllMatchers() {
175
+ match = import_matcher.match;
176
+ [import_matcher.buildAllMatchersKey]() {
194
177
  const matchers = /* @__PURE__ */ Object.create(null);
195
178
  Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
196
179
  matchers[method] ||= this.#buildMatcher(method);
197
180
  });
198
181
  this.#middleware = this.#routes = void 0;
182
+ clearWildcardRegExpCache();
199
183
  return matchers;
200
184
  }
201
185
  #buildMatcher(method) {
@@ -1,5 +1,9 @@
1
1
  // src/router/reg-exp-router/index.ts
2
2
  import { RegExpRouter } from "./router.js";
3
+ import { PreparedRegExpRouter, buildInitParams, serializeInitParams } from "./prepared-router.js";
3
4
  export {
4
- RegExpRouter
5
+ PreparedRegExpRouter,
6
+ RegExpRouter,
7
+ buildInitParams,
8
+ serializeInitParams
5
9
  };
@@ -0,0 +1,27 @@
1
+ // src/router/reg-exp-router/matcher.ts
2
+ import { METHOD_NAME_ALL } from "../../router.js";
3
+ var emptyParam = [];
4
+ var buildAllMatchersKey = Symbol("buildAllMatchers");
5
+ function match(method, path) {
6
+ const matchers = this[buildAllMatchersKey]();
7
+ const match2 = (method2, path2) => {
8
+ const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
9
+ const staticMatch = matcher[2][path2];
10
+ if (staticMatch) {
11
+ return staticMatch;
12
+ }
13
+ const match3 = path2.match(matcher[0]);
14
+ if (!match3) {
15
+ return [[], emptyParam];
16
+ }
17
+ const index = match3.indexOf("", 1);
18
+ return [matcher[1][index], match3];
19
+ };
20
+ this.match = match2;
21
+ return match2(method, path);
22
+ }
23
+ export {
24
+ buildAllMatchersKey,
25
+ emptyParam,
26
+ match
27
+ };
@@ -0,0 +1,126 @@
1
+ // src/router/reg-exp-router/prepared-router.ts
2
+ import { METHOD_NAME_ALL } from "../../router.js";
3
+ import { match, buildAllMatchersKey, emptyParam } from "./matcher.js";
4
+ import { RegExpRouter } from "./router.js";
5
+ var PreparedRegExpRouter = class {
6
+ name = "PreparedRegExpRouter";
7
+ #matchers;
8
+ #relocateMap;
9
+ constructor(matchers, relocateMap) {
10
+ this.#matchers = matchers;
11
+ this.#relocateMap = relocateMap;
12
+ }
13
+ add(method, path, handler) {
14
+ const all = this.#matchers[METHOD_NAME_ALL];
15
+ this.#matchers[method] ||= [
16
+ all[0],
17
+ all[1].map((list) => Array.isArray(list) ? list.slice() : 0),
18
+ Object.keys(all[2]).reduce((obj, key) => {
19
+ obj[key] = [all[2][key][0].slice(), emptyParam];
20
+ return obj;
21
+ }, {})
22
+ ];
23
+ if (path === "/*" || path === "*") {
24
+ const defaultHandlerData = [handler, {}];
25
+ (method === METHOD_NAME_ALL ? Object.keys(this.#matchers) : [method]).forEach((m) => {
26
+ const matcher = this.#matchers[m];
27
+ matcher[1].forEach((list) => list && list.push(defaultHandlerData));
28
+ Object.values(matcher[2]).forEach(
29
+ (list) => list[0].push(defaultHandlerData)
30
+ );
31
+ });
32
+ return;
33
+ }
34
+ const data = this.#relocateMap[path];
35
+ if (!data) {
36
+ throw new Error(`Path ${path} is not registered`);
37
+ }
38
+ for (const [indexes, map] of data) {
39
+ ;
40
+ (method === METHOD_NAME_ALL ? Object.keys(this.#matchers) : [method]).forEach((m) => {
41
+ const matcher = this.#matchers[m];
42
+ if (!map) {
43
+ matcher[2][path][0].push([handler, {}]);
44
+ } else {
45
+ indexes.forEach((index) => {
46
+ if (typeof index === "number") {
47
+ matcher[1][index].push([handler, map]);
48
+ } else {
49
+ ;
50
+ matcher[2][index || path][0].push([handler, map]);
51
+ }
52
+ });
53
+ }
54
+ });
55
+ }
56
+ }
57
+ [buildAllMatchersKey]() {
58
+ return this.#matchers;
59
+ }
60
+ match = match;
61
+ };
62
+ var buildInitParams = ({ paths }) => {
63
+ const router = new RegExpRouter();
64
+ for (const path of paths) {
65
+ router.add(METHOD_NAME_ALL, path, path);
66
+ }
67
+ const matchers = router[buildAllMatchersKey]();
68
+ const all = matchers[METHOD_NAME_ALL];
69
+ const relocateMap = {};
70
+ for (const path of paths) {
71
+ all[1].forEach((list, i) => {
72
+ list.forEach(([p, map]) => {
73
+ if (p === path) {
74
+ if (relocateMap[path]) {
75
+ relocateMap[path][0][1] = {
76
+ ...relocateMap[path][0][1],
77
+ ...map
78
+ };
79
+ } else {
80
+ relocateMap[path] = [[[], map]];
81
+ }
82
+ if (relocateMap[path][0][0].findIndex((j) => j === i) === -1) {
83
+ relocateMap[path][0][0].push(i);
84
+ }
85
+ }
86
+ });
87
+ });
88
+ for (const path2 in all[2]) {
89
+ all[2][path2][0].forEach(([p]) => {
90
+ if (p === path) {
91
+ relocateMap[path] ||= [[[], void 0]];
92
+ const value = path2 === path ? "" : path2;
93
+ if (relocateMap[path][0][0].findIndex((v) => v === value) === -1) {
94
+ relocateMap[path][0][0].push(value);
95
+ }
96
+ }
97
+ });
98
+ }
99
+ }
100
+ for (let i = 0, len = all[1].length; i < len; i++) {
101
+ all[1][i] = all[1][i] ? [] : 0;
102
+ }
103
+ for (const path in all[2]) {
104
+ all[2][path][0] = [];
105
+ }
106
+ return [matchers, relocateMap];
107
+ };
108
+ var serializeInitParams = ([matchers, relocateMap]) => {
109
+ for (const method in matchers) {
110
+ const matcher = matchers[method];
111
+ matcher[0].toJSON = function() {
112
+ return `@${this.toString()}@`;
113
+ };
114
+ }
115
+ const matchersStr = JSON.stringify(matchers).replace(
116
+ /"@(.+?)@"/g,
117
+ (_, str) => str.replace(/\\\\/g, "\\")
118
+ );
119
+ const relocateMapStr = JSON.stringify(relocateMap);
120
+ return `[${matchersStr},${relocateMapStr}]`;
121
+ };
122
+ export {
123
+ PreparedRegExpRouter,
124
+ buildInitParams,
125
+ serializeInitParams
126
+ };
@@ -5,9 +5,9 @@ import {
5
5
  UnsupportedPathError
6
6
  } from "../../router.js";
7
7
  import { checkOptionalParameter } from "../../utils/url.js";
8
+ import { match, emptyParam, buildAllMatchersKey } from "./matcher.js";
8
9
  import { PATH_ERROR } from "./node.js";
9
10
  import { Trie } from "./trie.js";
10
- var emptyParam = [];
11
11
  var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
12
12
  var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
13
13
  function buildWildcardRegExp(path) {
@@ -154,30 +154,14 @@ var RegExpRouter = class {
154
154
  });
155
155
  }
156
156
  }
157
- match(method, path) {
158
- clearWildcardRegExpCache();
159
- const matchers = this.#buildAllMatchers();
160
- this.match = (method2, path2) => {
161
- const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
162
- const staticMatch = matcher[2][path2];
163
- if (staticMatch) {
164
- return staticMatch;
165
- }
166
- const match = path2.match(matcher[0]);
167
- if (!match) {
168
- return [[], emptyParam];
169
- }
170
- const index = match.indexOf("", 1);
171
- return [matcher[1][index], match];
172
- };
173
- return this.match(method, path);
174
- }
175
- #buildAllMatchers() {
157
+ match = match;
158
+ [buildAllMatchersKey]() {
176
159
  const matchers = /* @__PURE__ */ Object.create(null);
177
160
  Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
178
161
  matchers[method] ||= this.#buildMatcher(method);
179
162
  });
180
163
  this.#middleware = this.#routes = void 0;
164
+ clearWildcardRegExpCache();
181
165
  return matchers;
182
166
  }
183
167
  #buildMatcher(method) {
@@ -137,7 +137,7 @@ interface JSONRespond {
137
137
  *
138
138
  * @returns {Response & TypedResponse<JSONParsed<T>, U, 'json'>} - The response after rendering the JSON object, typed with the provided object and status code types.
139
139
  */
140
- export type JSONRespondReturn<T extends JSONValue | {} | InvalidJSONValue, U extends ContentfulStatusCode> = Response & TypedResponse<JSONParsed<T>, U, "json">;
140
+ type JSONRespondReturn<T extends JSONValue | {} | InvalidJSONValue, U extends ContentfulStatusCode> = Response & TypedResponse<JSONParsed<T>, U, "json">;
141
141
  /**
142
142
  * Interface representing a function that responds with HTML content.
143
143
  *
@@ -3,3 +3,4 @@
3
3
  * RegExpRouter for Hono.
4
4
  */
5
5
  export { RegExpRouter } from './router';
6
+ export { PreparedRegExpRouter, buildInitParams, serializeInitParams } from './prepared-router';
@@ -0,0 +1,15 @@
1
+ import type { ParamIndexMap, Result, Router } from '../../router';
2
+ export type HandlerData<T> = [
3
+ T,
4
+ ParamIndexMap
5
+ ][];
6
+ export type StaticMap<T> = Record<string, Result<T>>;
7
+ export type Matcher<T> = [
8
+ RegExp,
9
+ HandlerData<T>[],
10
+ StaticMap<T>
11
+ ];
12
+ export type MatcherMap<T> = Record<string, Matcher<T> | null>;
13
+ export declare const emptyParam: string[];
14
+ export declare const buildAllMatchersKey: unique symbol;
15
+ export declare function match<R extends Router<T>, T>(this: R, method: string, path: string): Result<T>;
@@ -0,0 +1,19 @@
1
+ import type { ParamIndexMap, Router } from '../../router';
2
+ import type { MatcherMap } from './matcher';
3
+ import { match, buildAllMatchersKey } from './matcher';
4
+ type RelocateMap = Record<string, [
5
+ (number | string)[],
6
+ ParamIndexMap | undefined
7
+ ][]>;
8
+ export declare class PreparedRegExpRouter<T> implements Router<T> {
9
+ name: string;
10
+ constructor(matchers: MatcherMap<T>, relocateMap: RelocateMap);
11
+ add(method: string, path: string, handler: T): void;
12
+ [buildAllMatchersKey](): MatcherMap<T>;
13
+ match: typeof match<Router<T>, T>;
14
+ }
15
+ export declare const buildInitParams: (params: {
16
+ paths: string[];
17
+ }) => ConstructorParameters<typeof PreparedRegExpRouter>;
18
+ export declare const serializeInitParams: (params: ConstructorParameters<typeof PreparedRegExpRouter>) => string;
19
+ export {};
@@ -1,7 +1,10 @@
1
- import type { Result, Router } from '../../router';
1
+ import type { Router } from '../../router';
2
+ import type { MatcherMap } from './matcher';
3
+ import { match, buildAllMatchersKey } from './matcher';
2
4
  export declare class RegExpRouter<T> implements Router<T> {
3
5
  name: string;
4
6
  constructor();
5
7
  add(method: string, path: string, handler: T): void;
6
- match(method: string, path: string): Result<T>;
8
+ match: typeof match<Router<T>, T>;
9
+ [buildAllMatchersKey](): MatcherMap<T>;
7
10
  }
@@ -36,7 +36,7 @@ export type JSONValue = JSONObject | JSONArray | JSONPrimitive;
36
36
  * which defaults to `bigint | ReadonlyArray<bigint>`.
37
37
  * You can set it to `never` to disable this check.
38
38
  */
39
- export type JSONParsed<T, TError = bigint | ReadonlyArray<bigint>> = T extends TError ? never : T extends {
39
+ export type JSONParsed<T, TError = bigint | ReadonlyArray<bigint>> = T extends {
40
40
  toJSON(): infer J;
41
41
  } ? (() => J) extends () => JSONPrimitive ? J : (() => J) extends () => {
42
42
  toJSON(): unknown;
@@ -44,7 +44,7 @@ export type JSONParsed<T, TError = bigint | ReadonlyArray<bigint>> = T extends T
44
44
  [K in keyof T]: JSONParsed<InvalidToNull<T[K]>, TError>;
45
45
  } : T extends Set<unknown> | Map<unknown, unknown> | Record<string, never> ? {} : T extends object ? T[keyof T] extends TError ? never : {
46
46
  [K in keyof OmitSymbolKeys<T> as IsInvalid<T[K]> extends true ? never : K]: boolean extends IsInvalid<T[K]> ? JSONParsed<T[K], TError> | undefined : JSONParsed<T[K], TError>;
47
- } : T extends unknown ? JSONValue : never;
47
+ } : T extends unknown ? T extends TError ? never : JSONValue : never;
48
48
  /**
49
49
  * Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
50
50
  * @copyright from sindresorhus/type-fest
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.9.9",
3
+ "version": "4.9.11",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",