hono 4.6.9 → 4.6.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.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/dist/adapter/deno/serve-static.js +3 -0
  3. package/dist/cjs/adapter/deno/serve-static.js +3 -0
  4. package/dist/cjs/hono-base.js +16 -16
  5. package/dist/cjs/middleware/combine/index.js +15 -9
  6. package/dist/cjs/router/linear-router/router.js +4 -4
  7. package/dist/cjs/router/reg-exp-router/node.js +18 -18
  8. package/dist/cjs/router/reg-exp-router/router.js +9 -8
  9. package/dist/cjs/router/reg-exp-router/trie.js +4 -4
  10. package/dist/cjs/router/smart-router/router.js +12 -11
  11. package/dist/cjs/router/trie-router/node.js +53 -49
  12. package/dist/cjs/router/trie-router/router.js +5 -5
  13. package/dist/hono-base.js +16 -16
  14. package/dist/middleware/combine/index.js +15 -9
  15. package/dist/router/linear-router/router.js +4 -4
  16. package/dist/router/reg-exp-router/node.js +18 -18
  17. package/dist/router/reg-exp-router/router.js +9 -8
  18. package/dist/router/reg-exp-router/trie.js +4 -4
  19. package/dist/router/smart-router/router.js +12 -11
  20. package/dist/router/trie-router/node.js +53 -49
  21. package/dist/router/trie-router/router.js +5 -5
  22. package/dist/types/adapter/service-worker/index.d.ts +1 -1
  23. package/dist/types/compose.d.ts +5 -2
  24. package/dist/types/helper/factory/index.d.ts +129 -66
  25. package/dist/types/router/linear-router/router.d.ts +0 -5
  26. package/dist/types/router/reg-exp-router/node.d.ts +0 -3
  27. package/dist/types/router/reg-exp-router/router.d.ts +0 -7
  28. package/dist/types/router/reg-exp-router/trie.d.ts +1 -4
  29. package/dist/types/router/smart-router/router.d.ts +3 -7
  30. package/dist/types/router/trie-router/node.d.ts +0 -12
  31. package/dist/types/router/trie-router/router.d.ts +0 -2
  32. package/dist/types/types.d.ts +1 -1
  33. package/package.json +24 -16
  34. package/perf-measures/bundle-check/generated/.gitkeep +0 -0
package/README.md CHANGED
@@ -47,7 +47,7 @@ npm create hono@latest
47
47
  ## Features
48
48
 
49
49
  - **Ultrafast** 🚀 - The router `RegExpRouter` is really fast. Not using linear loops. Fast.
50
- - **Lightweight** ðŸŠķ - The `hono/tiny` preset is under 13kB. Hono has zero dependencies and uses only the Web Standard API.
50
+ - **Lightweight** ðŸŠķ - The `hono/tiny` preset is under 12kB. Hono has zero dependencies and uses only the Web Standard API.
51
51
  - **Multi-runtime** 🌍 - Works on Cloudflare Workers, Fastly Compute, Deno, Bun, AWS Lambda, Lambda@Edge, or Node.js. The same code runs on all platforms.
52
52
  - **Batteries Included** 🔋 - Hono has built-in middleware, custom middleware, and third-party middleware. Batteries included.
53
53
  - **Delightful DX** 😃 - Super clean APIs. First-class TypeScript support. Now, we've got "Types".
@@ -5,6 +5,9 @@ var serveStatic = (options) => {
5
5
  return async function serveStatic2(c, next) {
6
6
  const getContent = async (path) => {
7
7
  try {
8
+ if (isDir(path)) {
9
+ return null;
10
+ }
8
11
  const file = await open(path);
9
12
  return file.readable;
10
13
  } catch (e) {
@@ -27,6 +27,9 @@ const serveStatic = (options) => {
27
27
  return async function serveStatic2(c, next) {
28
28
  const getContent = async (path) => {
29
29
  try {
30
+ if (isDir(path)) {
31
+ return null;
32
+ }
30
33
  const file = await open(path);
31
34
  return file.readable;
32
35
  } catch (e) {
@@ -62,9 +62,7 @@ class Hono {
62
62
  this.#addRoute(method, this.#path, args1);
63
63
  }
64
64
  args.forEach((handler) => {
65
- if (typeof handler !== "string") {
66
- this.#addRoute(method, this.#path, handler);
67
- }
65
+ this.#addRoute(method, this.#path, handler);
68
66
  });
69
67
  return this;
70
68
  };
@@ -106,15 +104,15 @@ class Hono {
106
104
  return clone;
107
105
  }
108
106
  #notFoundHandler = notFoundHandler;
109
- #errorHandler = errorHandler;
107
+ errorHandler = errorHandler;
110
108
  route(path, app) {
111
109
  const subApp = this.basePath(path);
112
110
  app.routes.map((r) => {
113
111
  let handler;
114
- if (app.#errorHandler === errorHandler) {
112
+ if (app.errorHandler === errorHandler) {
115
113
  handler = r.handler;
116
114
  } else {
117
- handler = async (c, next) => (await (0, import_compose.compose)([], app.#errorHandler)(c, () => r.handler(c, next))).res;
115
+ handler = async (c, next) => (await (0, import_compose.compose)([], app.errorHandler)(c, () => r.handler(c, next))).res;
118
116
  handler[COMPOSED_HANDLER] = r.handler;
119
117
  }
120
118
  subApp.#addRoute(r.method, r.path, handler);
@@ -127,7 +125,7 @@ class Hono {
127
125
  return subApp;
128
126
  }
129
127
  onError = (handler) => {
130
- this.#errorHandler = handler;
128
+ this.errorHandler = handler;
131
129
  return this;
132
130
  };
133
131
  notFound = (handler) => {
@@ -184,7 +182,7 @@ class Hono {
184
182
  }
185
183
  #handleError(err, c) {
186
184
  if (err instanceof Error) {
187
- return this.#errorHandler(err, c);
185
+ return this.errorHandler(err, c);
188
186
  }
189
187
  throw err;
190
188
  }
@@ -214,7 +212,7 @@ class Hono {
214
212
  (resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))
215
213
  ).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
216
214
  }
217
- const composed = (0, import_compose.compose)(matchResult[0], this.#errorHandler, this.#notFoundHandler);
215
+ const composed = (0, import_compose.compose)(matchResult[0], this.errorHandler, this.#notFoundHandler);
218
216
  return (async () => {
219
217
  try {
220
218
  const context = await composed(c);
@@ -234,15 +232,17 @@ class Hono {
234
232
  };
235
233
  request = (input, requestInit, Env, executionCtx) => {
236
234
  if (input instanceof Request) {
237
- if (requestInit !== void 0) {
238
- input = new Request(input, requestInit);
239
- }
240
- return this.fetch(input, Env, executionCtx);
235
+ return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
241
236
  }
242
237
  input = input.toString();
243
- const path = /^https?:\/\//.test(input) ? input : `http://localhost${(0, import_url.mergePath)("/", input)}`;
244
- const req = new Request(path, requestInit);
245
- return this.fetch(req, Env, executionCtx);
238
+ return this.fetch(
239
+ new Request(
240
+ /^https?:\/\//.test(input) ? input : `http://localhost${(0, import_url.mergePath)("/", input)}`,
241
+ requestInit
242
+ ),
243
+ Env,
244
+ executionCtx
245
+ );
246
246
  };
247
247
  fire = () => {
248
248
  addEventListener("fetch", (event) => {
@@ -51,16 +51,22 @@ const some = (...middleware) => {
51
51
  };
52
52
  };
53
53
  const every = (...middleware) => {
54
- const wrappedMiddleware = middleware.map((m) => async (c, next) => {
55
- const res = await m(c, next);
56
- if (res === false) {
57
- throw new Error("Unmet condition");
58
- }
59
- return res;
60
- });
61
- const handler = async (c, next) => (0, import_compose.compose)(wrappedMiddleware.map((m) => [[m, void 0], c.req.param()]))(c, next);
62
54
  return async function every2(c, next) {
63
- await handler(c, next);
55
+ const currentRouteIndex = c.req.routeIndex;
56
+ await (0, import_compose.compose)(
57
+ middleware.map((m) => [
58
+ [
59
+ async (c2, next2) => {
60
+ c2.req.routeIndex = currentRouteIndex;
61
+ const res = await m(c2, next2);
62
+ if (res === false) {
63
+ throw new Error("Unmet condition");
64
+ }
65
+ return res;
66
+ }
67
+ ]
68
+ ])
69
+ )(c, next);
64
70
  };
65
71
  };
66
72
  const except = (condition, ...middleware) => {
@@ -28,17 +28,17 @@ const splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
28
28
  const splitByStarRe = /\*/;
29
29
  class LinearRouter {
30
30
  name = "LinearRouter";
31
- routes = [];
31
+ #routes = [];
32
32
  add(method, path, handler) {
33
33
  for (let i = 0, paths = (0, import_url.checkOptionalParameter)(path) || [path], len = paths.length; i < len; i++) {
34
- this.routes.push([method, paths[i], handler]);
34
+ this.#routes.push([method, paths[i], handler]);
35
35
  }
36
36
  }
37
37
  match(method, path) {
38
38
  const handlers = [];
39
39
  ROUTES_LOOP:
40
- for (let i = 0, len = this.routes.length; i < len; i++) {
41
- const [routeMethod, routePath, handler] = this.routes[i];
40
+ for (let i = 0, len = this.#routes.length; i < len; i++) {
41
+ const [routeMethod, routePath, handler] = this.#routes[i];
42
42
  if (routeMethod === method || routeMethod === import_router.METHOD_NAME_ALL) {
43
43
  if (routePath === "*" || routePath === "/*") {
44
44
  handlers.push([handler, emptyParams]);
@@ -47,18 +47,18 @@ function compareKey(a, b) {
47
47
  return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
48
48
  }
49
49
  class Node {
50
- index;
51
- varIndex;
52
- children = /* @__PURE__ */ Object.create(null);
50
+ #index;
51
+ #varIndex;
52
+ #children = /* @__PURE__ */ Object.create(null);
53
53
  insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
54
54
  if (tokens.length === 0) {
55
- if (this.index !== void 0) {
55
+ if (this.#index !== void 0) {
56
56
  throw PATH_ERROR;
57
57
  }
58
58
  if (pathErrorCheckOnly) {
59
59
  return;
60
60
  }
61
- this.index = index;
61
+ this.#index = index;
62
62
  return;
63
63
  }
64
64
  const [token, ...restTokens] = tokens;
@@ -73,9 +73,9 @@ class Node {
73
73
  throw PATH_ERROR;
74
74
  }
75
75
  }
76
- node = this.children[regexpStr];
76
+ node = this.#children[regexpStr];
77
77
  if (!node) {
78
- if (Object.keys(this.children).some(
78
+ if (Object.keys(this.#children).some(
79
79
  (k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
80
80
  )) {
81
81
  throw PATH_ERROR;
@@ -83,18 +83,18 @@ class Node {
83
83
  if (pathErrorCheckOnly) {
84
84
  return;
85
85
  }
86
- node = this.children[regexpStr] = new Node();
86
+ node = this.#children[regexpStr] = new Node();
87
87
  if (name !== "") {
88
- node.varIndex = context.varIndex++;
88
+ node.#varIndex = context.varIndex++;
89
89
  }
90
90
  }
91
91
  if (!pathErrorCheckOnly && name !== "") {
92
- paramMap.push([name, node.varIndex]);
92
+ paramMap.push([name, node.#varIndex]);
93
93
  }
94
94
  } else {
95
- node = this.children[token];
95
+ node = this.#children[token];
96
96
  if (!node) {
97
- if (Object.keys(this.children).some(
97
+ if (Object.keys(this.#children).some(
98
98
  (k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
99
99
  )) {
100
100
  throw PATH_ERROR;
@@ -102,19 +102,19 @@ class Node {
102
102
  if (pathErrorCheckOnly) {
103
103
  return;
104
104
  }
105
- node = this.children[token] = new Node();
105
+ node = this.#children[token] = new Node();
106
106
  }
107
107
  }
108
108
  node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
109
109
  }
110
110
  buildRegExpStr() {
111
- const childKeys = Object.keys(this.children).sort(compareKey);
111
+ const childKeys = Object.keys(this.#children).sort(compareKey);
112
112
  const strList = childKeys.map((k) => {
113
- const c = this.children[k];
114
- return (typeof c.varIndex === "number" ? `(${k})@${c.varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
113
+ const c = this.#children[k];
114
+ return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
115
115
  });
116
- if (typeof this.index === "number") {
117
- strList.unshift(`#${this.index}`);
116
+ if (typeof this.#index === "number") {
117
+ strList.unshift(`#${this.#index}`);
118
118
  }
119
119
  if (strList.length === 0) {
120
120
  return "";
@@ -109,14 +109,15 @@ function findMiddleware(middleware, path) {
109
109
  }
110
110
  class RegExpRouter {
111
111
  name = "RegExpRouter";
112
- middleware;
113
- routes;
112
+ #middleware;
113
+ #routes;
114
114
  constructor() {
115
- this.middleware = { [import_router.METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
116
- this.routes = { [import_router.METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
115
+ this.#middleware = { [import_router.METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
116
+ this.#routes = { [import_router.METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
117
117
  }
118
118
  add(method, path, handler) {
119
- const { middleware, routes } = this;
119
+ const middleware = this.#middleware;
120
+ const routes = this.#routes;
120
121
  if (!middleware || !routes) {
121
122
  throw new Error(import_router.MESSAGE_MATCHER_IS_ALREADY_BUILT);
122
123
  }
@@ -191,16 +192,16 @@ class RegExpRouter {
191
192
  }
192
193
  #buildAllMatchers() {
193
194
  const matchers = /* @__PURE__ */ Object.create(null);
194
- Object.keys(this.routes).concat(Object.keys(this.middleware)).forEach((method) => {
195
+ Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
195
196
  matchers[method] ||= this.#buildMatcher(method);
196
197
  });
197
- this.middleware = this.routes = void 0;
198
+ this.#middleware = this.#routes = void 0;
198
199
  return matchers;
199
200
  }
200
201
  #buildMatcher(method) {
201
202
  const routes = [];
202
203
  let hasOwnRoute = method === import_router.METHOD_NAME_ALL;
203
- [this.middleware, this.routes].forEach((r) => {
204
+ [this.#middleware, this.#routes].forEach((r) => {
204
205
  const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
205
206
  if (ownRoute.length !== 0) {
206
207
  hasOwnRoute ||= true;
@@ -23,8 +23,8 @@ __export(trie_exports, {
23
23
  module.exports = __toCommonJS(trie_exports);
24
24
  var import_node = require("./node");
25
25
  class Trie {
26
- context = { varIndex: 0 };
27
- root = new import_node.Node();
26
+ #context = { varIndex: 0 };
27
+ #root = new import_node.Node();
28
28
  insert(path, index, pathErrorCheckOnly) {
29
29
  const paramAssoc = [];
30
30
  const groups = [];
@@ -51,11 +51,11 @@ class Trie {
51
51
  }
52
52
  }
53
53
  }
54
- this.root.insert(tokens, index, paramAssoc, this.context, pathErrorCheckOnly);
54
+ this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
55
55
  return paramAssoc;
56
56
  }
57
57
  buildRegExp() {
58
- let regexp = this.root.buildRegExpStr();
58
+ let regexp = this.#root.buildRegExpStr();
59
59
  if (regexp === "") {
60
60
  return [/^$/, [], []];
61
61
  }
@@ -24,22 +24,23 @@ module.exports = __toCommonJS(router_exports);
24
24
  var import_router = require("../../router");
25
25
  class SmartRouter {
26
26
  name = "SmartRouter";
27
- routers = [];
28
- routes = [];
27
+ #routers = [];
28
+ #routes = [];
29
29
  constructor(init) {
30
- Object.assign(this, init);
30
+ this.#routers = init.routers;
31
31
  }
32
32
  add(method, path, handler) {
33
- if (!this.routes) {
33
+ if (!this.#routes) {
34
34
  throw new Error(import_router.MESSAGE_MATCHER_IS_ALREADY_BUILT);
35
35
  }
36
- this.routes.push([method, path, handler]);
36
+ this.#routes.push([method, path, handler]);
37
37
  }
38
38
  match(method, path) {
39
- if (!this.routes) {
39
+ if (!this.#routes) {
40
40
  throw new Error("Fatal error");
41
41
  }
42
- const { routers, routes } = this;
42
+ const routers = this.#routers;
43
+ const routes = this.#routes;
43
44
  const len = routers.length;
44
45
  let i = 0;
45
46
  let res;
@@ -57,8 +58,8 @@ class SmartRouter {
57
58
  throw e;
58
59
  }
59
60
  this.match = router.match.bind(router);
60
- this.routers = [router];
61
- this.routes = void 0;
61
+ this.#routers = [router];
62
+ this.#routes = void 0;
62
63
  break;
63
64
  }
64
65
  if (i === len) {
@@ -68,10 +69,10 @@ class SmartRouter {
68
69
  return res;
69
70
  }
70
71
  get activeRouter() {
71
- if (this.routes || this.routers.length !== 1) {
72
+ if (this.#routes || this.#routers.length !== 1) {
72
73
  throw new Error("No active router has been determined yet.");
73
74
  }
74
- return this.routers[0];
75
+ return this.#routers[0];
75
76
  }
76
77
  }
77
78
  // Annotate the CommonJS export names for ESM import in node:
@@ -24,63 +24,60 @@ module.exports = __toCommonJS(node_exports);
24
24
  var import_router = require("../../router");
25
25
  var import_url = require("../../utils/url");
26
26
  class Node {
27
- methods;
28
- children;
29
- patterns;
30
- order = 0;
31
- params = /* @__PURE__ */ Object.create(null);
27
+ #methods;
28
+ #children;
29
+ #patterns;
30
+ #order = 0;
31
+ #params = /* @__PURE__ */ Object.create(null);
32
32
  constructor(method, handler, children) {
33
- this.children = children || /* @__PURE__ */ Object.create(null);
34
- this.methods = [];
33
+ this.#children = children || /* @__PURE__ */ Object.create(null);
34
+ this.#methods = [];
35
35
  if (method && handler) {
36
36
  const m = /* @__PURE__ */ Object.create(null);
37
37
  m[method] = { handler, possibleKeys: [], score: 0 };
38
- this.methods = [m];
38
+ this.#methods = [m];
39
39
  }
40
- this.patterns = [];
40
+ this.#patterns = [];
41
41
  }
42
42
  insert(method, path, handler) {
43
- this.order = ++this.order;
43
+ this.#order = ++this.#order;
44
44
  let curNode = this;
45
45
  const parts = (0, import_url.splitRoutingPath)(path);
46
46
  const possibleKeys = [];
47
47
  for (let i = 0, len = parts.length; i < len; i++) {
48
48
  const p = parts[i];
49
- if (Object.keys(curNode.children).includes(p)) {
50
- curNode = curNode.children[p];
49
+ if (Object.keys(curNode.#children).includes(p)) {
50
+ curNode = curNode.#children[p];
51
51
  const pattern2 = (0, import_url.getPattern)(p);
52
52
  if (pattern2) {
53
53
  possibleKeys.push(pattern2[1]);
54
54
  }
55
55
  continue;
56
56
  }
57
- curNode.children[p] = new Node();
57
+ curNode.#children[p] = new Node();
58
58
  const pattern = (0, import_url.getPattern)(p);
59
59
  if (pattern) {
60
- curNode.patterns.push(pattern);
60
+ curNode.#patterns.push(pattern);
61
61
  possibleKeys.push(pattern[1]);
62
62
  }
63
- curNode = curNode.children[p];
64
- }
65
- if (!curNode.methods.length) {
66
- curNode.methods = [];
63
+ curNode = curNode.#children[p];
67
64
  }
68
65
  const m = /* @__PURE__ */ Object.create(null);
69
66
  const handlerSet = {
70
67
  handler,
71
68
  possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
72
- score: this.order
69
+ score: this.#order
73
70
  };
74
71
  m[method] = handlerSet;
75
- curNode.methods.push(m);
72
+ curNode.#methods.push(m);
76
73
  return curNode;
77
74
  }
78
- #gHSets(node, method, nodeParams, params) {
75
+ #getHandlerSets(node, method, nodeParams, params) {
79
76
  const handlerSets = [];
80
- for (let i = 0, len = node.methods.length; i < len; i++) {
81
- const m = node.methods[i];
77
+ for (let i = 0, len = node.#methods.length; i < len; i++) {
78
+ const m = node.#methods[i];
82
79
  const handlerSet = m[method] || m[import_router.METHOD_NAME_ALL];
83
- const processedSet = /* @__PURE__ */ Object.create(null);
80
+ const processedSet = {};
84
81
  if (handlerSet !== void 0) {
85
82
  handlerSet.params = /* @__PURE__ */ Object.create(null);
86
83
  for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
@@ -96,7 +93,7 @@ class Node {
96
93
  }
97
94
  search(method, path) {
98
95
  const handlerSets = [];
99
- this.params = /* @__PURE__ */ Object.create(null);
96
+ this.#params = /* @__PURE__ */ Object.create(null);
100
97
  const curNode = this;
101
98
  let curNodes = [curNode];
102
99
  const parts = (0, import_url.splitPath)(path);
@@ -106,27 +103,36 @@ class Node {
106
103
  const tempNodes = [];
107
104
  for (let j = 0, len2 = curNodes.length; j < len2; j++) {
108
105
  const node = curNodes[j];
109
- const nextNode = node.children[part];
106
+ const nextNode = node.#children[part];
110
107
  if (nextNode) {
111
- nextNode.params = node.params;
108
+ nextNode.#params = node.#params;
112
109
  if (isLast) {
113
- if (nextNode.children["*"]) {
110
+ if (nextNode.#children["*"]) {
114
111
  handlerSets.push(
115
- ...this.#gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null))
112
+ ...this.#getHandlerSets(
113
+ nextNode.#children["*"],
114
+ method,
115
+ node.#params,
116
+ /* @__PURE__ */ Object.create(null)
117
+ )
116
118
  );
117
119
  }
118
- handlerSets.push(...this.#gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null)));
120
+ handlerSets.push(
121
+ ...this.#getHandlerSets(nextNode, method, node.#params, /* @__PURE__ */ Object.create(null))
122
+ );
119
123
  } else {
120
124
  tempNodes.push(nextNode);
121
125
  }
122
126
  }
123
- for (let k = 0, len3 = node.patterns.length; k < len3; k++) {
124
- const pattern = node.patterns[k];
125
- const params = { ...node.params };
127
+ for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
128
+ const pattern = node.#patterns[k];
129
+ const params = { ...node.#params };
126
130
  if (pattern === "*") {
127
- const astNode = node.children["*"];
131
+ const astNode = node.#children["*"];
128
132
  if (astNode) {
129
- handlerSets.push(...this.#gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null)));
133
+ handlerSets.push(
134
+ ...this.#getHandlerSets(astNode, method, node.#params, /* @__PURE__ */ Object.create(null))
135
+ );
130
136
  tempNodes.push(astNode);
131
137
  }
132
138
  continue;
@@ -135,27 +141,25 @@ class Node {
135
141
  continue;
136
142
  }
137
143
  const [key, name, matcher] = pattern;
138
- const child = node.children[key];
144
+ const child = node.#children[key];
139
145
  const restPathString = parts.slice(i).join("/");
140
146
  if (matcher instanceof RegExp && matcher.test(restPathString)) {
141
147
  params[name] = restPathString;
142
- handlerSets.push(...this.#gHSets(child, method, node.params, params));
148
+ handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params));
143
149
  continue;
144
150
  }
145
151
  if (matcher === true || matcher.test(part)) {
146
- if (typeof key === "string") {
147
- params[name] = part;
148
- if (isLast) {
149
- handlerSets.push(...this.#gHSets(child, method, params, node.params));
150
- if (child.children["*"]) {
151
- handlerSets.push(
152
- ...this.#gHSets(child.children["*"], method, params, node.params)
153
- );
154
- }
155
- } else {
156
- child.params = params;
157
- tempNodes.push(child);
152
+ params[name] = part;
153
+ if (isLast) {
154
+ handlerSets.push(...this.#getHandlerSets(child, method, params, node.#params));
155
+ if (child.#children["*"]) {
156
+ handlerSets.push(
157
+ ...this.#getHandlerSets(child.#children["*"], method, params, node.#params)
158
+ );
158
159
  }
160
+ } else {
161
+ child.#params = params;
162
+ tempNodes.push(child);
159
163
  }
160
164
  }
161
165
  }
@@ -25,22 +25,22 @@ var import_url = require("../../utils/url");
25
25
  var import_node = require("./node");
26
26
  class TrieRouter {
27
27
  name = "TrieRouter";
28
- node;
28
+ #node;
29
29
  constructor() {
30
- this.node = new import_node.Node();
30
+ this.#node = new import_node.Node();
31
31
  }
32
32
  add(method, path, handler) {
33
33
  const results = (0, import_url.checkOptionalParameter)(path);
34
34
  if (results) {
35
35
  for (let i = 0, len = results.length; i < len; i++) {
36
- this.node.insert(method, results[i], handler);
36
+ this.#node.insert(method, results[i], handler);
37
37
  }
38
38
  return;
39
39
  }
40
- this.node.insert(method, path, handler);
40
+ this.#node.insert(method, path, handler);
41
41
  }
42
42
  match(method, path) {
43
- return this.node.search(method, path);
43
+ return this.#node.search(method, path);
44
44
  }
45
45
  }
46
46
  // Annotate the CommonJS export names for ESM import in node:
package/dist/hono-base.js CHANGED
@@ -39,9 +39,7 @@ var Hono = class {
39
39
  this.#addRoute(method, this.#path, args1);
40
40
  }
41
41
  args.forEach((handler) => {
42
- if (typeof handler !== "string") {
43
- this.#addRoute(method, this.#path, handler);
44
- }
42
+ this.#addRoute(method, this.#path, handler);
45
43
  });
46
44
  return this;
47
45
  };
@@ -83,15 +81,15 @@ var Hono = class {
83
81
  return clone;
84
82
  }
85
83
  #notFoundHandler = notFoundHandler;
86
- #errorHandler = errorHandler;
84
+ errorHandler = errorHandler;
87
85
  route(path, app) {
88
86
  const subApp = this.basePath(path);
89
87
  app.routes.map((r) => {
90
88
  let handler;
91
- if (app.#errorHandler === errorHandler) {
89
+ if (app.errorHandler === errorHandler) {
92
90
  handler = r.handler;
93
91
  } else {
94
- handler = async (c, next) => (await compose([], app.#errorHandler)(c, () => r.handler(c, next))).res;
92
+ handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
95
93
  handler[COMPOSED_HANDLER] = r.handler;
96
94
  }
97
95
  subApp.#addRoute(r.method, r.path, handler);
@@ -104,7 +102,7 @@ var Hono = class {
104
102
  return subApp;
105
103
  }
106
104
  onError = (handler) => {
107
- this.#errorHandler = handler;
105
+ this.errorHandler = handler;
108
106
  return this;
109
107
  };
110
108
  notFound = (handler) => {
@@ -161,7 +159,7 @@ var Hono = class {
161
159
  }
162
160
  #handleError(err, c) {
163
161
  if (err instanceof Error) {
164
- return this.#errorHandler(err, c);
162
+ return this.errorHandler(err, c);
165
163
  }
166
164
  throw err;
167
165
  }
@@ -191,7 +189,7 @@ var Hono = class {
191
189
  (resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))
192
190
  ).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
193
191
  }
194
- const composed = compose(matchResult[0], this.#errorHandler, this.#notFoundHandler);
192
+ const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
195
193
  return (async () => {
196
194
  try {
197
195
  const context = await composed(c);
@@ -211,15 +209,17 @@ var Hono = class {
211
209
  };
212
210
  request = (input, requestInit, Env, executionCtx) => {
213
211
  if (input instanceof Request) {
214
- if (requestInit !== void 0) {
215
- input = new Request(input, requestInit);
216
- }
217
- return this.fetch(input, Env, executionCtx);
212
+ return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
218
213
  }
219
214
  input = input.toString();
220
- const path = /^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`;
221
- const req = new Request(path, requestInit);
222
- return this.fetch(req, Env, executionCtx);
215
+ return this.fetch(
216
+ new Request(
217
+ /^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`,
218
+ requestInit
219
+ ),
220
+ Env,
221
+ executionCtx
222
+ );
223
223
  };
224
224
  fire = () => {
225
225
  addEventListener("fetch", (event) => {