hono 4.6.9 → 4.6.10

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 (30) hide show
  1. package/dist/adapter/deno/serve-static.js +3 -0
  2. package/dist/cjs/adapter/deno/serve-static.js +3 -0
  3. package/dist/cjs/hono-base.js +10 -10
  4. package/dist/cjs/middleware/combine/index.js +15 -9
  5. package/dist/cjs/router/linear-router/router.js +4 -4
  6. package/dist/cjs/router/reg-exp-router/node.js +18 -18
  7. package/dist/cjs/router/reg-exp-router/router.js +9 -8
  8. package/dist/cjs/router/reg-exp-router/trie.js +4 -4
  9. package/dist/cjs/router/smart-router/router.js +12 -11
  10. package/dist/cjs/router/trie-router/node.js +53 -49
  11. package/dist/cjs/router/trie-router/router.js +5 -5
  12. package/dist/hono-base.js +10 -10
  13. package/dist/middleware/combine/index.js +15 -9
  14. package/dist/router/linear-router/router.js +4 -4
  15. package/dist/router/reg-exp-router/node.js +18 -18
  16. package/dist/router/reg-exp-router/router.js +9 -8
  17. package/dist/router/reg-exp-router/trie.js +4 -4
  18. package/dist/router/smart-router/router.js +12 -11
  19. package/dist/router/trie-router/node.js +53 -49
  20. package/dist/router/trie-router/router.js +5 -5
  21. package/dist/types/adapter/service-worker/index.d.ts +1 -1
  22. package/dist/types/compose.d.ts +5 -2
  23. package/dist/types/router/linear-router/router.d.ts +0 -5
  24. package/dist/types/router/reg-exp-router/node.d.ts +0 -3
  25. package/dist/types/router/reg-exp-router/router.d.ts +0 -7
  26. package/dist/types/router/reg-exp-router/trie.d.ts +1 -4
  27. package/dist/types/router/smart-router/router.d.ts +3 -7
  28. package/dist/types/router/trie-router/node.d.ts +0 -12
  29. package/dist/types/router/trie-router/router.d.ts +0 -2
  30. package/package.json +20 -12
@@ -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
  };
@@ -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
  };
@@ -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) => {
@@ -27,16 +27,22 @@ var some = (...middleware) => {
27
27
  };
28
28
  };
29
29
  var every = (...middleware) => {
30
- const wrappedMiddleware = middleware.map((m) => async (c, next) => {
31
- const res = await m(c, next);
32
- if (res === false) {
33
- throw new Error("Unmet condition");
34
- }
35
- return res;
36
- });
37
- const handler = async (c, next) => compose(wrappedMiddleware.map((m) => [[m, void 0], c.req.param()]))(c, next);
38
30
  return async function every2(c, next) {
39
- await handler(c, next);
31
+ const currentRouteIndex = c.req.routeIndex;
32
+ await compose(
33
+ middleware.map((m) => [
34
+ [
35
+ async (c2, next2) => {
36
+ c2.req.routeIndex = currentRouteIndex;
37
+ const res = await m(c2, next2);
38
+ if (res === false) {
39
+ throw new Error("Unmet condition");
40
+ }
41
+ return res;
42
+ }
43
+ ]
44
+ ])
45
+ )(c, next);
40
46
  };
41
47
  };
42
48
  var except = (condition, ...middleware) => {
@@ -6,17 +6,17 @@ var splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
6
6
  var splitByStarRe = /\*/;
7
7
  var LinearRouter = class {
8
8
  name = "LinearRouter";
9
- routes = [];
9
+ #routes = [];
10
10
  add(method, path, handler) {
11
11
  for (let i = 0, paths = checkOptionalParameter(path) || [path], len = paths.length; i < len; i++) {
12
- this.routes.push([method, paths[i], handler]);
12
+ this.#routes.push([method, paths[i], handler]);
13
13
  }
14
14
  }
15
15
  match(method, path) {
16
16
  const handlers = [];
17
17
  ROUTES_LOOP:
18
- for (let i = 0, len = this.routes.length; i < len; i++) {
19
- const [routeMethod, routePath, handler] = this.routes[i];
18
+ for (let i = 0, len = this.#routes.length; i < len; i++) {
19
+ const [routeMethod, routePath, handler] = this.#routes[i];
20
20
  if (routeMethod === method || routeMethod === METHOD_NAME_ALL) {
21
21
  if (routePath === "*" || routePath === "/*") {
22
22
  handlers.push([handler, emptyParams]);
@@ -24,18 +24,18 @@ function compareKey(a, b) {
24
24
  return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
25
25
  }
26
26
  var Node = class {
27
- index;
28
- varIndex;
29
- children = /* @__PURE__ */ Object.create(null);
27
+ #index;
28
+ #varIndex;
29
+ #children = /* @__PURE__ */ Object.create(null);
30
30
  insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
31
31
  if (tokens.length === 0) {
32
- if (this.index !== void 0) {
32
+ if (this.#index !== void 0) {
33
33
  throw PATH_ERROR;
34
34
  }
35
35
  if (pathErrorCheckOnly) {
36
36
  return;
37
37
  }
38
- this.index = index;
38
+ this.#index = index;
39
39
  return;
40
40
  }
41
41
  const [token, ...restTokens] = tokens;
@@ -50,9 +50,9 @@ var Node = class {
50
50
  throw PATH_ERROR;
51
51
  }
52
52
  }
53
- node = this.children[regexpStr];
53
+ node = this.#children[regexpStr];
54
54
  if (!node) {
55
- if (Object.keys(this.children).some(
55
+ if (Object.keys(this.#children).some(
56
56
  (k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
57
57
  )) {
58
58
  throw PATH_ERROR;
@@ -60,18 +60,18 @@ var Node = class {
60
60
  if (pathErrorCheckOnly) {
61
61
  return;
62
62
  }
63
- node = this.children[regexpStr] = new Node();
63
+ node = this.#children[regexpStr] = new Node();
64
64
  if (name !== "") {
65
- node.varIndex = context.varIndex++;
65
+ node.#varIndex = context.varIndex++;
66
66
  }
67
67
  }
68
68
  if (!pathErrorCheckOnly && name !== "") {
69
- paramMap.push([name, node.varIndex]);
69
+ paramMap.push([name, node.#varIndex]);
70
70
  }
71
71
  } else {
72
- node = this.children[token];
72
+ node = this.#children[token];
73
73
  if (!node) {
74
- if (Object.keys(this.children).some(
74
+ if (Object.keys(this.#children).some(
75
75
  (k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
76
76
  )) {
77
77
  throw PATH_ERROR;
@@ -79,19 +79,19 @@ var Node = class {
79
79
  if (pathErrorCheckOnly) {
80
80
  return;
81
81
  }
82
- node = this.children[token] = new Node();
82
+ node = this.#children[token] = new Node();
83
83
  }
84
84
  }
85
85
  node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
86
86
  }
87
87
  buildRegExpStr() {
88
- const childKeys = Object.keys(this.children).sort(compareKey);
88
+ const childKeys = Object.keys(this.#children).sort(compareKey);
89
89
  const strList = childKeys.map((k) => {
90
- const c = this.children[k];
91
- return (typeof c.varIndex === "number" ? `(${k})@${c.varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
90
+ const c = this.#children[k];
91
+ return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
92
92
  });
93
- if (typeof this.index === "number") {
94
- strList.unshift(`#${this.index}`);
93
+ if (typeof this.#index === "number") {
94
+ strList.unshift(`#${this.#index}`);
95
95
  }
96
96
  if (strList.length === 0) {
97
97
  return "";
@@ -91,14 +91,15 @@ function findMiddleware(middleware, path) {
91
91
  }
92
92
  var RegExpRouter = class {
93
93
  name = "RegExpRouter";
94
- middleware;
95
- routes;
94
+ #middleware;
95
+ #routes;
96
96
  constructor() {
97
- this.middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
98
- this.routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
97
+ this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
98
+ this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
99
99
  }
100
100
  add(method, path, handler) {
101
- const { middleware, routes } = this;
101
+ const middleware = this.#middleware;
102
+ const routes = this.#routes;
102
103
  if (!middleware || !routes) {
103
104
  throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
104
105
  }
@@ -173,16 +174,16 @@ var RegExpRouter = class {
173
174
  }
174
175
  #buildAllMatchers() {
175
176
  const matchers = /* @__PURE__ */ Object.create(null);
176
- Object.keys(this.routes).concat(Object.keys(this.middleware)).forEach((method) => {
177
+ Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
177
178
  matchers[method] ||= this.#buildMatcher(method);
178
179
  });
179
- this.middleware = this.routes = void 0;
180
+ this.#middleware = this.#routes = void 0;
180
181
  return matchers;
181
182
  }
182
183
  #buildMatcher(method) {
183
184
  const routes = [];
184
185
  let hasOwnRoute = method === METHOD_NAME_ALL;
185
- [this.middleware, this.routes].forEach((r) => {
186
+ [this.#middleware, this.#routes].forEach((r) => {
186
187
  const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
187
188
  if (ownRoute.length !== 0) {
188
189
  hasOwnRoute ||= true;
@@ -1,8 +1,8 @@
1
1
  // src/router/reg-exp-router/trie.ts
2
2
  import { Node } from "./node.js";
3
3
  var Trie = class {
4
- context = { varIndex: 0 };
5
- root = new Node();
4
+ #context = { varIndex: 0 };
5
+ #root = new Node();
6
6
  insert(path, index, pathErrorCheckOnly) {
7
7
  const paramAssoc = [];
8
8
  const groups = [];
@@ -29,11 +29,11 @@ var Trie = class {
29
29
  }
30
30
  }
31
31
  }
32
- this.root.insert(tokens, index, paramAssoc, this.context, pathErrorCheckOnly);
32
+ this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
33
33
  return paramAssoc;
34
34
  }
35
35
  buildRegExp() {
36
- let regexp = this.root.buildRegExpStr();
36
+ let regexp = this.#root.buildRegExpStr();
37
37
  if (regexp === "") {
38
38
  return [/^$/, [], []];
39
39
  }
@@ -2,22 +2,23 @@
2
2
  import { MESSAGE_MATCHER_IS_ALREADY_BUILT, UnsupportedPathError } from "../../router.js";
3
3
  var SmartRouter = class {
4
4
  name = "SmartRouter";
5
- routers = [];
6
- routes = [];
5
+ #routers = [];
6
+ #routes = [];
7
7
  constructor(init) {
8
- Object.assign(this, init);
8
+ this.#routers = init.routers;
9
9
  }
10
10
  add(method, path, handler) {
11
- if (!this.routes) {
11
+ if (!this.#routes) {
12
12
  throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
13
13
  }
14
- this.routes.push([method, path, handler]);
14
+ this.#routes.push([method, path, handler]);
15
15
  }
16
16
  match(method, path) {
17
- if (!this.routes) {
17
+ if (!this.#routes) {
18
18
  throw new Error("Fatal error");
19
19
  }
20
- const { routers, routes } = this;
20
+ const routers = this.#routers;
21
+ const routes = this.#routes;
21
22
  const len = routers.length;
22
23
  let i = 0;
23
24
  let res;
@@ -35,8 +36,8 @@ var SmartRouter = class {
35
36
  throw e;
36
37
  }
37
38
  this.match = router.match.bind(router);
38
- this.routers = [router];
39
- this.routes = void 0;
39
+ this.#routers = [router];
40
+ this.#routes = void 0;
40
41
  break;
41
42
  }
42
43
  if (i === len) {
@@ -46,10 +47,10 @@ var SmartRouter = class {
46
47
  return res;
47
48
  }
48
49
  get activeRouter() {
49
- if (this.routes || this.routers.length !== 1) {
50
+ if (this.#routes || this.#routers.length !== 1) {
50
51
  throw new Error("No active router has been determined yet.");
51
52
  }
52
- return this.routers[0];
53
+ return this.#routers[0];
53
54
  }
54
55
  };
55
56
  export {
@@ -2,63 +2,60 @@
2
2
  import { METHOD_NAME_ALL } from "../../router.js";
3
3
  import { getPattern, splitPath, splitRoutingPath } from "../../utils/url.js";
4
4
  var Node = class {
5
- methods;
6
- children;
7
- patterns;
8
- order = 0;
9
- params = /* @__PURE__ */ Object.create(null);
5
+ #methods;
6
+ #children;
7
+ #patterns;
8
+ #order = 0;
9
+ #params = /* @__PURE__ */ Object.create(null);
10
10
  constructor(method, handler, children) {
11
- this.children = children || /* @__PURE__ */ Object.create(null);
12
- this.methods = [];
11
+ this.#children = children || /* @__PURE__ */ Object.create(null);
12
+ this.#methods = [];
13
13
  if (method && handler) {
14
14
  const m = /* @__PURE__ */ Object.create(null);
15
15
  m[method] = { handler, possibleKeys: [], score: 0 };
16
- this.methods = [m];
16
+ this.#methods = [m];
17
17
  }
18
- this.patterns = [];
18
+ this.#patterns = [];
19
19
  }
20
20
  insert(method, path, handler) {
21
- this.order = ++this.order;
21
+ this.#order = ++this.#order;
22
22
  let curNode = this;
23
23
  const parts = splitRoutingPath(path);
24
24
  const possibleKeys = [];
25
25
  for (let i = 0, len = parts.length; i < len; i++) {
26
26
  const p = parts[i];
27
- if (Object.keys(curNode.children).includes(p)) {
28
- curNode = curNode.children[p];
27
+ if (Object.keys(curNode.#children).includes(p)) {
28
+ curNode = curNode.#children[p];
29
29
  const pattern2 = getPattern(p);
30
30
  if (pattern2) {
31
31
  possibleKeys.push(pattern2[1]);
32
32
  }
33
33
  continue;
34
34
  }
35
- curNode.children[p] = new Node();
35
+ curNode.#children[p] = new Node();
36
36
  const pattern = getPattern(p);
37
37
  if (pattern) {
38
- curNode.patterns.push(pattern);
38
+ curNode.#patterns.push(pattern);
39
39
  possibleKeys.push(pattern[1]);
40
40
  }
41
- curNode = curNode.children[p];
42
- }
43
- if (!curNode.methods.length) {
44
- curNode.methods = [];
41
+ curNode = curNode.#children[p];
45
42
  }
46
43
  const m = /* @__PURE__ */ Object.create(null);
47
44
  const handlerSet = {
48
45
  handler,
49
46
  possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
50
- score: this.order
47
+ score: this.#order
51
48
  };
52
49
  m[method] = handlerSet;
53
- curNode.methods.push(m);
50
+ curNode.#methods.push(m);
54
51
  return curNode;
55
52
  }
56
- #gHSets(node, method, nodeParams, params) {
53
+ #getHandlerSets(node, method, nodeParams, params) {
57
54
  const handlerSets = [];
58
- for (let i = 0, len = node.methods.length; i < len; i++) {
59
- const m = node.methods[i];
55
+ for (let i = 0, len = node.#methods.length; i < len; i++) {
56
+ const m = node.#methods[i];
60
57
  const handlerSet = m[method] || m[METHOD_NAME_ALL];
61
- const processedSet = /* @__PURE__ */ Object.create(null);
58
+ const processedSet = {};
62
59
  if (handlerSet !== void 0) {
63
60
  handlerSet.params = /* @__PURE__ */ Object.create(null);
64
61
  for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
@@ -74,7 +71,7 @@ var Node = class {
74
71
  }
75
72
  search(method, path) {
76
73
  const handlerSets = [];
77
- this.params = /* @__PURE__ */ Object.create(null);
74
+ this.#params = /* @__PURE__ */ Object.create(null);
78
75
  const curNode = this;
79
76
  let curNodes = [curNode];
80
77
  const parts = splitPath(path);
@@ -84,27 +81,36 @@ var Node = class {
84
81
  const tempNodes = [];
85
82
  for (let j = 0, len2 = curNodes.length; j < len2; j++) {
86
83
  const node = curNodes[j];
87
- const nextNode = node.children[part];
84
+ const nextNode = node.#children[part];
88
85
  if (nextNode) {
89
- nextNode.params = node.params;
86
+ nextNode.#params = node.#params;
90
87
  if (isLast) {
91
- if (nextNode.children["*"]) {
88
+ if (nextNode.#children["*"]) {
92
89
  handlerSets.push(
93
- ...this.#gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null))
90
+ ...this.#getHandlerSets(
91
+ nextNode.#children["*"],
92
+ method,
93
+ node.#params,
94
+ /* @__PURE__ */ Object.create(null)
95
+ )
94
96
  );
95
97
  }
96
- handlerSets.push(...this.#gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null)));
98
+ handlerSets.push(
99
+ ...this.#getHandlerSets(nextNode, method, node.#params, /* @__PURE__ */ Object.create(null))
100
+ );
97
101
  } else {
98
102
  tempNodes.push(nextNode);
99
103
  }
100
104
  }
101
- for (let k = 0, len3 = node.patterns.length; k < len3; k++) {
102
- const pattern = node.patterns[k];
103
- const params = { ...node.params };
105
+ for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
106
+ const pattern = node.#patterns[k];
107
+ const params = { ...node.#params };
104
108
  if (pattern === "*") {
105
- const astNode = node.children["*"];
109
+ const astNode = node.#children["*"];
106
110
  if (astNode) {
107
- handlerSets.push(...this.#gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null)));
111
+ handlerSets.push(
112
+ ...this.#getHandlerSets(astNode, method, node.#params, /* @__PURE__ */ Object.create(null))
113
+ );
108
114
  tempNodes.push(astNode);
109
115
  }
110
116
  continue;
@@ -113,27 +119,25 @@ var Node = class {
113
119
  continue;
114
120
  }
115
121
  const [key, name, matcher] = pattern;
116
- const child = node.children[key];
122
+ const child = node.#children[key];
117
123
  const restPathString = parts.slice(i).join("/");
118
124
  if (matcher instanceof RegExp && matcher.test(restPathString)) {
119
125
  params[name] = restPathString;
120
- handlerSets.push(...this.#gHSets(child, method, node.params, params));
126
+ handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params));
121
127
  continue;
122
128
  }
123
129
  if (matcher === true || matcher.test(part)) {
124
- if (typeof key === "string") {
125
- params[name] = part;
126
- if (isLast) {
127
- handlerSets.push(...this.#gHSets(child, method, params, node.params));
128
- if (child.children["*"]) {
129
- handlerSets.push(
130
- ...this.#gHSets(child.children["*"], method, params, node.params)
131
- );
132
- }
133
- } else {
134
- child.params = params;
135
- tempNodes.push(child);
130
+ params[name] = part;
131
+ if (isLast) {
132
+ handlerSets.push(...this.#getHandlerSets(child, method, params, node.#params));
133
+ if (child.#children["*"]) {
134
+ handlerSets.push(
135
+ ...this.#getHandlerSets(child.#children["*"], method, params, node.#params)
136
+ );
136
137
  }
138
+ } else {
139
+ child.#params = params;
140
+ tempNodes.push(child);
137
141
  }
138
142
  }
139
143
  }
@@ -3,22 +3,22 @@ import { checkOptionalParameter } from "../../utils/url.js";
3
3
  import { Node } from "./node.js";
4
4
  var TrieRouter = class {
5
5
  name = "TrieRouter";
6
- node;
6
+ #node;
7
7
  constructor() {
8
- this.node = new Node();
8
+ this.#node = new Node();
9
9
  }
10
10
  add(method, path, handler) {
11
11
  const results = checkOptionalParameter(path);
12
12
  if (results) {
13
13
  for (let i = 0, len = results.length; i < len; i++) {
14
- this.node.insert(method, results[i], handler);
14
+ this.#node.insert(method, results[i], handler);
15
15
  }
16
16
  return;
17
17
  }
18
- this.node.insert(method, path, handler);
18
+ this.#node.insert(method, path, handler);
19
19
  }
20
20
  match(method, path) {
21
- return this.node.search(method, path);
21
+ return this.#node.search(method, path);
22
22
  }
23
23
  };
24
24
  export {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Cloudflare Workers Adapter for Hono.
2
+ * Service Worker Adapter for Hono.
3
3
  * @module
4
4
  */
5
5
  export { handle } from './handler';
@@ -1,4 +1,3 @@
1
- import type { ParamIndexMap, Params } from './router';
2
1
  import type { Env, ErrorHandler, NotFoundHandler } from './types';
3
2
  /**
4
3
  * Interface representing the context for a composition operation.
@@ -31,6 +30,10 @@ export declare const compose: <C extends ComposeContext, E extends Env = Env>(mi
31
30
  Function,
32
31
  unknown
33
32
  ],
34
- ParamIndexMap | Params
33
+ unknown
34
+ ][] | [
35
+ [
36
+ Function
37
+ ]
35
38
  ][], onError?: ErrorHandler<E>, onNotFound?: NotFoundHandler<E>) => ((context: C, next?: Function) => Promise<C>);
36
39
  export {};
@@ -1,11 +1,6 @@
1
1
  import type { Result, Router } from '../../router';
2
2
  export declare class LinearRouter<T> implements Router<T> {
3
3
  name: string;
4
- routes: [
5
- string,
6
- string,
7
- T
8
- ][];
9
4
  add(method: string, path: string, handler: T): void;
10
5
  match(method: string, path: string): Result<T>;
11
6
  }
@@ -7,9 +7,6 @@ export interface Context {
7
7
  varIndex: number;
8
8
  }
9
9
  export declare class Node {
10
- index?: number;
11
- varIndex?: number;
12
- children: Record<string, Node>;
13
10
  insert(tokens: readonly string[], index: number, paramMap: ParamAssocArray, context: Context, pathErrorCheckOnly: boolean): void;
14
11
  buildRegExpStr(): string;
15
12
  }
@@ -1,14 +1,7 @@
1
1
  import type { Result, Router } from '../../router';
2
- type HandlerWithMetadata<T> = [
3
- T,
4
- number
5
- ];
6
2
  export declare class RegExpRouter<T> implements Router<T> {
7
3
  name: string;
8
- middleware?: Record<string, Record<string, HandlerWithMetadata<T>[]>>;
9
- routes?: Record<string, Record<string, HandlerWithMetadata<T>[]>>;
10
4
  constructor();
11
5
  add(method: string, path: string, handler: T): void;
12
6
  match(method: string, path: string): Result<T>;
13
7
  }
14
- export {};
@@ -1,9 +1,6 @@
1
- import type { Context, ParamAssocArray } from './node';
2
- import { Node } from './node';
1
+ import type { ParamAssocArray } from './node';
3
2
  export type ReplacementMap = number[];
4
3
  export declare class Trie {
5
- context: Context;
6
- root: Node;
7
4
  insert(path: string, index: number, pathErrorCheckOnly: boolean): ParamAssocArray;
8
5
  buildRegExp(): [
9
6
  RegExp,
@@ -1,13 +1,9 @@
1
1
  import type { Result, Router } from '../../router';
2
2
  export declare class SmartRouter<T> implements Router<T> {
3
3
  name: string;
4
- routers: Router<T>[];
5
- routes?: [
6
- string,
7
- string,
8
- T
9
- ][];
10
- constructor(init: Pick<SmartRouter<T>, "routers">);
4
+ constructor(init: {
5
+ routers: Router<T>[];
6
+ });
11
7
  add(method: string, path: string, handler: T): void;
12
8
  match(method: string, path: string): Result<T>;
13
9
  get activeRouter(): Router<T>;
@@ -1,16 +1,5 @@
1
1
  import type { Params } from '../../router';
2
- import type { Pattern } from '../../utils/url';
3
- type HandlerSet<T> = {
4
- handler: T;
5
- possibleKeys: string[];
6
- score: number;
7
- };
8
2
  export declare class Node<T> {
9
- methods: Record<string, HandlerSet<T>>[];
10
- children: Record<string, Node<T>>;
11
- patterns: Pattern[];
12
- order: number;
13
- params: Record<string, string>;
14
3
  constructor(method?: string, handler?: T, children?: Record<string, Node<T>>);
15
4
  insert(method: string, path: string, handler: T): Node<T>;
16
5
  search(method: string, path: string): [
@@ -20,4 +9,3 @@ export declare class Node<T> {
20
9
  ][]
21
10
  ];
22
11
  }
23
- export {};
@@ -1,8 +1,6 @@
1
1
  import type { Result, Router } from '../../router';
2
- import { Node } from './node';
3
2
  export declare class TrieRouter<T> implements Router<T> {
4
3
  name: string;
5
- node: Node<T>;
6
4
  constructor();
7
5
  add(method: string, path: string, handler: T): void;
8
6
  match(method: string, path: string): Result<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.6.9",
3
+ "version": "4.6.10",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",
@@ -39,6 +39,11 @@
39
39
  "import": "./dist/index.js",
40
40
  "require": "./dist/cjs/index.js"
41
41
  },
42
+ "./request": {
43
+ "types": "./dist/types/request.d.ts",
44
+ "import": "./dist/request.js",
45
+ "require": "./dist/cjs/request.js"
46
+ },
42
47
  "./types": {
43
48
  "types": "./dist/types/types.d.ts",
44
49
  "import": "./dist/types.js",
@@ -387,6 +392,9 @@
387
392
  },
388
393
  "typesVersions": {
389
394
  "*": {
395
+ "request": [
396
+ "./dist/types/request"
397
+ ],
390
398
  "types": [
391
399
  "./dist/types/types"
392
400
  ],
@@ -619,29 +627,29 @@
619
627
  ],
620
628
  "devDependencies": {
621
629
  "@hono/eslint-config": "^1.0.2",
622
- "@hono/node-server": "^1.8.2",
623
- "@types/glob": "^8.0.0",
624
- "@types/jsdom": "^21.1.4",
630
+ "@hono/node-server": "^1.13.5",
631
+ "@types/glob": "^8.1.0",
632
+ "@types/jsdom": "^21.1.7",
625
633
  "@types/node": "20.11.4",
626
- "@types/supertest": "^2.0.12",
634
+ "@types/supertest": "^2.0.16",
627
635
  "@vitest/coverage-v8": "^2.0.5",
628
636
  "arg": "^5.0.2",
629
- "bun-types": "^1.1.30",
630
- "esbuild": "^0.15.12",
637
+ "bun-types": "^1.1.34",
638
+ "esbuild": "^0.15.18",
631
639
  "eslint": "^9.10.0",
632
640
  "glob": "^11.0.0",
633
641
  "jsdom": "^22.1.0",
634
- "msw": "^2.3.0",
642
+ "msw": "^2.6.0",
635
643
  "np": "7.7.0",
636
644
  "prettier": "^2.6.2",
637
- "publint": "^0.1.8",
638
- "supertest": "^6.3.3",
645
+ "publint": "^0.1.16",
646
+ "supertest": "^6.3.4",
639
647
  "typescript": "^5.3.3",
640
648
  "vite-plugin-fastly-js-compute": "^0.4.2",
641
649
  "vitest": "^2.0.5",
642
650
  "wrangler": "3.58.0",
643
- "ws": "^8.17.0",
644
- "zod": "^3.20.2"
651
+ "ws": "^8.18.0",
652
+ "zod": "^3.23.8"
645
653
  },
646
654
  "engines": {
647
655
  "node": ">=16.9.0"