hono 4.0.10 → 4.1.0

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 (109) hide show
  1. package/dist/adapter/aws-lambda/handler.js +1 -1
  2. package/dist/adapter/bun/index.js +2 -0
  3. package/dist/adapter/bun/websocket.js +77 -0
  4. package/dist/adapter/cloudflare-workers/index.js +3 -1
  5. package/dist/adapter/cloudflare-workers/websocket.js +57 -0
  6. package/dist/adapter/deno/index.js +3 -1
  7. package/dist/adapter/deno/websocket.js +29 -0
  8. package/dist/adapter/lambda-edge/handler.js +1 -1
  9. package/dist/cjs/adapter/aws-lambda/handler.js +1 -1
  10. package/dist/cjs/adapter/bun/index.js +3 -0
  11. package/dist/cjs/adapter/bun/websocket.js +98 -0
  12. package/dist/cjs/adapter/cloudflare-workers/index.js +5 -2
  13. package/dist/cjs/adapter/cloudflare-workers/websocket.js +80 -0
  14. package/dist/cjs/adapter/deno/index.js +5 -2
  15. package/dist/cjs/adapter/deno/websocket.js +52 -0
  16. package/dist/cjs/adapter/lambda-edge/handler.js +1 -1
  17. package/dist/cjs/client/client.js +68 -61
  18. package/dist/cjs/context.js +164 -188
  19. package/dist/cjs/helper/adapter/index.js +1 -1
  20. package/dist/cjs/helper/cookie/index.js +48 -8
  21. package/dist/cjs/helper/dev/index.js +3 -4
  22. package/dist/cjs/helper/factory/index.js +1 -3
  23. package/dist/cjs/helper/ssg/index.js +9 -159
  24. package/dist/cjs/helper/ssg/middleware.js +57 -0
  25. package/dist/cjs/helper/ssg/ssg.js +212 -0
  26. package/dist/cjs/helper/websocket/index.js +32 -0
  27. package/dist/cjs/helper.js +1 -0
  28. package/dist/cjs/hono-base.js +46 -65
  29. package/dist/cjs/http-exception.js +3 -1
  30. package/dist/cjs/jsx/base.js +7 -2
  31. package/dist/cjs/jsx/components.js +1 -1
  32. package/dist/cjs/jsx/dom/index.js +45 -3
  33. package/dist/cjs/jsx/dom/render.js +6 -6
  34. package/dist/cjs/jsx/hooks/index.js +25 -16
  35. package/dist/cjs/jsx/index.js +34 -2
  36. package/dist/cjs/middleware/body-limit/index.js +80 -0
  37. package/dist/cjs/middleware/logger/index.js +9 -7
  38. package/dist/cjs/request.js +29 -48
  39. package/dist/cjs/router/linear-router/router.js +3 -5
  40. package/dist/cjs/router/pattern-router/router.js +2 -4
  41. package/dist/cjs/router/reg-exp-router/node.js +3 -3
  42. package/dist/cjs/router/reg-exp-router/router.js +11 -12
  43. package/dist/cjs/router/reg-exp-router/trie.js +2 -4
  44. package/dist/cjs/router/smart-router/router.js +3 -3
  45. package/dist/cjs/router/trie-router/node.js +6 -2
  46. package/dist/cjs/router/trie-router/router.js +2 -1
  47. package/dist/cjs/test-utils/setup-vitest.js +2 -0
  48. package/dist/cjs/utils/color.js +32 -0
  49. package/dist/cjs/utils/concurrent.js +62 -0
  50. package/dist/cjs/utils/cookie.js +28 -1
  51. package/dist/cjs/utils/stream.js +5 -1
  52. package/dist/cjs/utils/url.js +2 -2
  53. package/dist/client/client.js +68 -61
  54. package/dist/context.js +164 -189
  55. package/dist/helper/adapter/index.js +1 -1
  56. package/dist/helper/cookie/index.js +48 -8
  57. package/dist/helper/dev/index.js +3 -4
  58. package/dist/helper/factory/index.js +1 -3
  59. package/dist/helper/ssg/index.js +3 -151
  60. package/dist/helper/ssg/middleware.js +29 -0
  61. package/dist/helper/ssg/ssg.js +187 -0
  62. package/dist/helper/websocket/index.js +9 -0
  63. package/dist/helper.js +1 -0
  64. package/dist/hono-base.js +45 -65
  65. package/dist/http-exception.js +3 -1
  66. package/dist/jsx/base.js +7 -2
  67. package/dist/jsx/components.js +1 -1
  68. package/dist/jsx/dom/index.js +44 -4
  69. package/dist/jsx/dom/render.js +6 -6
  70. package/dist/jsx/hooks/index.js +23 -16
  71. package/dist/jsx/index.js +34 -3
  72. package/dist/middleware/body-limit/index.js +57 -0
  73. package/dist/middleware/logger/index.js +9 -7
  74. package/dist/request.js +29 -49
  75. package/dist/router/linear-router/router.js +3 -5
  76. package/dist/router/pattern-router/router.js +2 -4
  77. package/dist/router/reg-exp-router/node.js +3 -3
  78. package/dist/router/reg-exp-router/router.js +11 -12
  79. package/dist/router/reg-exp-router/trie.js +2 -4
  80. package/dist/router/smart-router/router.js +3 -3
  81. package/dist/router/trie-router/node.js +6 -2
  82. package/dist/router/trie-router/router.js +2 -1
  83. package/dist/test-utils/setup-vitest.js +2 -0
  84. package/dist/types/adapter/bun/index.d.ts +1 -0
  85. package/dist/types/adapter/bun/websocket.d.ts +26 -0
  86. package/dist/types/adapter/cloudflare-workers/index.d.ts +1 -0
  87. package/dist/types/adapter/cloudflare-workers/websocket.d.ts +2 -0
  88. package/dist/types/adapter/deno/index.d.ts +1 -0
  89. package/dist/types/adapter/deno/websocket.d.ts +2 -0
  90. package/dist/types/client/types.d.ts +9 -0
  91. package/dist/types/helper/cookie/index.d.ts +3 -1
  92. package/dist/types/helper/ssg/index.d.ts +2 -105
  93. package/dist/types/helper/ssg/middleware.d.ts +38 -0
  94. package/dist/types/helper/ssg/ssg.d.ts +70 -0
  95. package/dist/types/helper/websocket/index.d.ts +34 -0
  96. package/dist/types/http-exception.d.ts +1 -0
  97. package/dist/types/jsx/dom/index.d.ts +40 -7
  98. package/dist/types/jsx/hooks/index.d.ts +2 -0
  99. package/dist/types/jsx/index.d.ts +41 -5
  100. package/dist/types/middleware/body-limit/index.d.ts +28 -0
  101. package/dist/types/utils/color.d.ts +1 -0
  102. package/dist/types/utils/concurrent.d.ts +7 -0
  103. package/dist/types/utils/cookie.d.ts +2 -0
  104. package/dist/utils/color.js +9 -0
  105. package/dist/utils/concurrent.js +39 -0
  106. package/dist/utils/cookie.js +28 -1
  107. package/dist/utils/stream.js +5 -1
  108. package/dist/utils/url.js +2 -2
  109. package/package.json +18 -2
@@ -97,7 +97,6 @@ var setShadow = (node) => {
97
97
  node.s?.forEach(setShadow);
98
98
  };
99
99
  var useState = (initialState) => {
100
- var _a;
101
100
  const resolveInitialState = () => typeof initialState === "function" ? initialState() : initialState;
102
101
  const buildData = buildDataStack.at(-1);
103
102
  if (!buildData) {
@@ -105,9 +104,9 @@ var useState = (initialState) => {
105
104
  }];
106
105
  }
107
106
  const [, node] = buildData;
108
- const stateArray = (_a = node[DOM_STASH][1])[STASH_SATE] || (_a[STASH_SATE] = []);
107
+ const stateArray = node[DOM_STASH][1][STASH_SATE] ||= [];
109
108
  const hookIndex = node[DOM_STASH][0]++;
110
- return stateArray[hookIndex] || (stateArray[hookIndex] = [
109
+ return stateArray[hookIndex] ||= [
111
110
  resolveInitialState(),
112
111
  (newState) => {
113
112
  const localUpdateHook = updateHook;
@@ -148,18 +147,26 @@ var useState = (initialState) => {
148
147
  }
149
148
  }
150
149
  }
151
- ]);
150
+ ];
151
+ };
152
+ var useReducer = (reducer, initialArg, init) => {
153
+ const [state, setState] = useState(() => init ? init(initialArg) : initialArg);
154
+ return [
155
+ state,
156
+ (action) => {
157
+ setState((state2) => reducer(state2, action));
158
+ }
159
+ ];
152
160
  };
153
161
  var useEffectCommon = (index, effect, deps) => {
154
- var _a;
155
162
  const buildData = buildDataStack.at(-1);
156
163
  if (!buildData) {
157
164
  return;
158
165
  }
159
166
  const [, node] = buildData;
160
- const effectDepsArray = (_a = node[DOM_STASH][1])[STASH_EFFECT] || (_a[STASH_EFFECT] = []);
167
+ const effectDepsArray = node[DOM_STASH][1][STASH_EFFECT] ||= [];
161
168
  const hookIndex = node[DOM_STASH][0]++;
162
- const [prevDeps, , prevCleanup] = effectDepsArray[hookIndex] || (effectDepsArray[hookIndex] = []);
169
+ const [prevDeps, , prevCleanup] = effectDepsArray[hookIndex] ||= [];
163
170
  if (isDepsChanged(prevDeps, deps)) {
164
171
  if (prevCleanup) {
165
172
  prevCleanup();
@@ -176,13 +183,12 @@ var useEffectCommon = (index, effect, deps) => {
176
183
  var useEffect = (effect, deps) => useEffectCommon(3, effect, deps);
177
184
  var useLayoutEffect = (effect, deps) => useEffectCommon(1, effect, deps);
178
185
  var useCallback = (callback, deps) => {
179
- var _a;
180
186
  const buildData = buildDataStack.at(-1);
181
187
  if (!buildData) {
182
188
  return callback;
183
189
  }
184
190
  const [, node] = buildData;
185
- const callbackArray = (_a = node[DOM_STASH][1])[STASH_CALLBACK] || (_a[STASH_CALLBACK] = []);
191
+ const callbackArray = node[DOM_STASH][1][STASH_CALLBACK] ||= [];
186
192
  const hookIndex = node[DOM_STASH][0]++;
187
193
  const prevDeps = callbackArray[hookIndex];
188
194
  if (isDepsChanged(prevDeps?.[1], deps)) {
@@ -193,18 +199,16 @@ var useCallback = (callback, deps) => {
193
199
  return callback;
194
200
  };
195
201
  var useRef = (initialValue) => {
196
- var _a;
197
202
  const buildData = buildDataStack.at(-1);
198
203
  if (!buildData) {
199
204
  return { current: initialValue };
200
205
  }
201
206
  const [, node] = buildData;
202
- const refArray = (_a = node[DOM_STASH][1])[STASH_REF] || (_a[STASH_REF] = []);
207
+ const refArray = node[DOM_STASH][1][STASH_REF] ||= [];
203
208
  const hookIndex = node[DOM_STASH][0]++;
204
- return refArray[hookIndex] || (refArray[hookIndex] = { current: initialValue });
209
+ return refArray[hookIndex] ||= { current: initialValue };
205
210
  };
206
211
  var use = (promise) => {
207
- var _a;
208
212
  const cachedRes = resolvedPromiseValueMap.get(promise);
209
213
  if (cachedRes) {
210
214
  if (cachedRes.length === 2) {
@@ -221,7 +225,7 @@ var use = (promise) => {
221
225
  throw promise;
222
226
  }
223
227
  const [, node] = buildData;
224
- const promiseArray = (_a = node[DOM_STASH][1])[STASH_USE] || (_a[STASH_USE] = []);
228
+ const promiseArray = node[DOM_STASH][1][STASH_USE] ||= [];
225
229
  const hookIndex = node[DOM_STASH][0]++;
226
230
  promise.then(
227
231
  (res2) => {
@@ -241,13 +245,12 @@ var use = (promise) => {
241
245
  throw promise;
242
246
  };
243
247
  var useMemo = (factory, deps) => {
244
- var _a;
245
248
  const buildData = buildDataStack.at(-1);
246
249
  if (!buildData) {
247
250
  return factory();
248
251
  }
249
252
  const [, node] = buildData;
250
- const memoArray = (_a = node[DOM_STASH][1])[STASH_MEMO] || (_a[STASH_MEMO] = []);
253
+ const memoArray = node[DOM_STASH][1][STASH_MEMO] ||= [];
251
254
  const hookIndex = node[DOM_STASH][0]++;
252
255
  const prevDeps = memoArray[hookIndex];
253
256
  if (isDepsChanged(prevDeps?.[1], deps)) {
@@ -255,16 +258,20 @@ var useMemo = (factory, deps) => {
255
258
  }
256
259
  return memoArray[hookIndex][0];
257
260
  };
261
+ var useDebugValue = (value, formatter) => {
262
+ };
258
263
  export {
259
264
  STASH_EFFECT,
260
265
  startTransition,
261
266
  startViewTransition,
262
267
  use,
263
268
  useCallback,
269
+ useDebugValue,
264
270
  useDeferredValue,
265
271
  useEffect,
266
272
  useLayoutEffect,
267
273
  useMemo,
274
+ useReducer,
268
275
  useRef,
269
276
  useState,
270
277
  useTransition,
package/dist/jsx/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/jsx/index.ts
2
2
  import { jsx, memo, Fragment, isValidElement, cloneElement } from "./base.js";
3
3
  import { ErrorBoundary } from "./components.js";
4
- import { Suspense } from "./streaming.js";
4
+ import { createContext, useContext } from "./context.js";
5
5
  import {
6
6
  useState,
7
7
  useEffect,
@@ -14,16 +14,45 @@ import {
14
14
  startViewTransition,
15
15
  useViewTransition,
16
16
  useMemo,
17
- useLayoutEffect
17
+ useLayoutEffect,
18
+ useReducer,
19
+ useDebugValue
18
20
  } from "./hooks/index.js";
19
- import { createContext, useContext } from "./context.js";
21
+ import { Suspense } from "./streaming.js";
20
22
  export * from "./types.js";
23
+ var jsx_default = {
24
+ memo,
25
+ Fragment,
26
+ isValidElement,
27
+ createElement: jsx,
28
+ cloneElement,
29
+ ErrorBoundary,
30
+ createContext,
31
+ useContext,
32
+ useState,
33
+ useEffect,
34
+ useRef,
35
+ useCallback,
36
+ useReducer,
37
+ useDebugValue,
38
+ use,
39
+ startTransition,
40
+ useTransition,
41
+ useDeferredValue,
42
+ startViewTransition,
43
+ useViewTransition,
44
+ useMemo,
45
+ useLayoutEffect,
46
+ Suspense
47
+ };
21
48
  export {
22
49
  ErrorBoundary,
23
50
  Fragment,
24
51
  Suspense,
25
52
  cloneElement,
26
53
  createContext,
54
+ jsx as createElement,
55
+ jsx_default as default,
27
56
  isValidElement,
28
57
  jsx,
29
58
  memo,
@@ -32,10 +61,12 @@ export {
32
61
  use,
33
62
  useCallback,
34
63
  useContext,
64
+ useDebugValue,
35
65
  useDeferredValue,
36
66
  useEffect,
37
67
  useLayoutEffect,
38
68
  useMemo,
69
+ useReducer,
39
70
  useRef,
40
71
  useState,
41
72
  useTransition,
@@ -0,0 +1,57 @@
1
+ // src/middleware/body-limit/index.ts
2
+ import { HTTPException } from "../../http-exception.js";
3
+ var ERROR_MESSAGE = "Payload Too Large";
4
+ var BodyLimitError = class extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = "BodyLimitError";
8
+ }
9
+ };
10
+ var bodyLimit = (options) => {
11
+ const onError = options.onError || (() => {
12
+ const res = new Response(ERROR_MESSAGE, {
13
+ status: 413
14
+ });
15
+ throw new HTTPException(413, { res });
16
+ });
17
+ const maxSize = options.maxSize;
18
+ return async function bodyLimit2(c, next) {
19
+ if (!c.req.raw.body) {
20
+ return next();
21
+ }
22
+ if (c.req.raw.headers.has("content-length")) {
23
+ const contentLength = parseInt(c.req.raw.headers.get("content-length") || "0", 10);
24
+ return contentLength > maxSize ? onError(c) : next();
25
+ }
26
+ let size = 0;
27
+ const rawReader = c.req.raw.body.getReader();
28
+ const reader = new ReadableStream({
29
+ async start(controller) {
30
+ try {
31
+ for (; ; ) {
32
+ const { done, value } = await rawReader.read();
33
+ if (done) {
34
+ break;
35
+ }
36
+ size += value.length;
37
+ if (size > maxSize) {
38
+ controller.error(new BodyLimitError(ERROR_MESSAGE));
39
+ break;
40
+ }
41
+ controller.enqueue(value);
42
+ }
43
+ } finally {
44
+ controller.close();
45
+ }
46
+ }
47
+ });
48
+ c.req.raw = new Request(c.req.raw, { body: reader });
49
+ await next();
50
+ if (c.error instanceof BodyLimitError) {
51
+ c.res = await onError(c);
52
+ }
53
+ };
54
+ };
55
+ export {
56
+ bodyLimit
57
+ };
@@ -1,4 +1,5 @@
1
1
  // src/middleware/logger/index.ts
2
+ import { getColorEnabled } from "../../utils/color.js";
2
3
  import { getPath } from "../../utils/url.js";
3
4
  var humanize = (times) => {
4
5
  const [delimiter, separator] = [",", "."];
@@ -10,14 +11,15 @@ var time = (start) => {
10
11
  return humanize([delta < 1e3 ? delta + "ms" : Math.round(delta / 1e3) + "s"]);
11
12
  };
12
13
  var colorStatus = (status) => {
14
+ const colorEnabled = getColorEnabled();
13
15
  const out = {
14
- 7: `\x1B[35m${status}\x1B[0m`,
15
- 5: `\x1B[31m${status}\x1B[0m`,
16
- 4: `\x1B[33m${status}\x1B[0m`,
17
- 3: `\x1B[36m${status}\x1B[0m`,
18
- 2: `\x1B[32m${status}\x1B[0m`,
19
- 1: `\x1B[32m${status}\x1B[0m`,
20
- 0: `\x1B[33m${status}\x1B[0m`
16
+ 7: colorEnabled ? `\x1B[35m${status}\x1B[0m` : `${status}`,
17
+ 5: colorEnabled ? `\x1B[31m${status}\x1B[0m` : `${status}`,
18
+ 4: colorEnabled ? `\x1B[33m${status}\x1B[0m` : `${status}`,
19
+ 3: colorEnabled ? `\x1B[36m${status}\x1B[0m` : `${status}`,
20
+ 2: colorEnabled ? `\x1B[32m${status}\x1B[0m` : `${status}`,
21
+ 1: colorEnabled ? `\x1B[32m${status}\x1B[0m` : `${status}`,
22
+ 0: colorEnabled ? `\x1B[33m${status}\x1B[0m` : `${status}`
21
23
  };
22
24
  const calculateStatus = status / 100 | 0;
23
25
  return out[calculateStatus];
package/dist/request.js CHANGED
@@ -1,63 +1,32 @@
1
- var __accessCheck = (obj, member, msg) => {
2
- if (!member.has(obj))
3
- throw TypeError("Cannot " + msg);
4
- };
5
- var __privateGet = (obj, member, getter) => {
6
- __accessCheck(obj, member, "read from private field");
7
- return getter ? getter.call(obj) : member.get(obj);
8
- };
9
- var __privateAdd = (obj, member, value) => {
10
- if (member.has(obj))
11
- throw TypeError("Cannot add the same private member more than once");
12
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- };
14
- var __privateSet = (obj, member, value, setter) => {
15
- __accessCheck(obj, member, "write to private field");
16
- setter ? setter.call(obj, value) : member.set(obj, value);
17
- return value;
18
- };
19
-
20
1
  // src/request.ts
21
2
  import { parseBody } from "./utils/body.js";
22
3
  import { getQueryParam, getQueryParams, decodeURIComponent_ } from "./utils/url.js";
23
- var _validatedData, _matchResult;
24
4
  var HonoRequest = class {
5
+ raw;
6
+ #validatedData;
7
+ #matchResult;
8
+ routeIndex = 0;
9
+ path;
10
+ bodyCache = {};
25
11
  constructor(request, path = "/", matchResult = [[]]) {
26
- __privateAdd(this, _validatedData, void 0);
27
- __privateAdd(this, _matchResult, void 0);
28
- this.routeIndex = 0;
29
- this.bodyCache = {};
30
- this.cachedBody = (key) => {
31
- const { bodyCache, raw } = this;
32
- const cachedBody = bodyCache[key];
33
- if (cachedBody) {
34
- return cachedBody;
35
- }
36
- if (bodyCache.arrayBuffer) {
37
- return (async () => {
38
- return await new Response(bodyCache.arrayBuffer)[key]();
39
- })();
40
- }
41
- return bodyCache[key] = raw[key]();
42
- };
43
12
  this.raw = request;
44
13
  this.path = path;
45
- __privateSet(this, _matchResult, matchResult);
46
- __privateSet(this, _validatedData, {});
14
+ this.#matchResult = matchResult;
15
+ this.#validatedData = {};
47
16
  }
48
17
  param(key) {
49
18
  return key ? this.getDecodedParam(key) : this.getAllDecodedParams();
50
19
  }
51
20
  getDecodedParam(key) {
52
- const paramKey = __privateGet(this, _matchResult)[0][this.routeIndex][1][key];
21
+ const paramKey = this.#matchResult[0][this.routeIndex][1][key];
53
22
  const param = this.getParamValue(paramKey);
54
23
  return param ? /\%/.test(param) ? decodeURIComponent_(param) : param : void 0;
55
24
  }
56
25
  getAllDecodedParams() {
57
26
  const decoded = {};
58
- const keys = Object.keys(__privateGet(this, _matchResult)[0][this.routeIndex][1]);
27
+ const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
59
28
  for (const key of keys) {
60
- const value = this.getParamValue(__privateGet(this, _matchResult)[0][this.routeIndex][1][key]);
29
+ const value = this.getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
61
30
  if (value && typeof value === "string") {
62
31
  decoded[key] = /\%/.test(value) ? decodeURIComponent_(value) : value;
63
32
  }
@@ -65,7 +34,7 @@ var HonoRequest = class {
65
34
  return decoded;
66
35
  }
67
36
  getParamValue(paramKey) {
68
- return __privateGet(this, _matchResult)[1] ? __privateGet(this, _matchResult)[1][paramKey] : paramKey;
37
+ return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
69
38
  }
70
39
  query(key) {
71
40
  return getQueryParam(this.url, key);
@@ -91,6 +60,19 @@ var HonoRequest = class {
91
60
  this.bodyCache.parsedBody = parsedBody;
92
61
  return parsedBody;
93
62
  }
63
+ cachedBody = (key) => {
64
+ const { bodyCache, raw } = this;
65
+ const cachedBody = bodyCache[key];
66
+ if (cachedBody) {
67
+ return cachedBody;
68
+ }
69
+ if (bodyCache.arrayBuffer) {
70
+ return (async () => {
71
+ return await new Response(bodyCache.arrayBuffer)[key]();
72
+ })();
73
+ }
74
+ return bodyCache[key] = raw[key]();
75
+ };
94
76
  json() {
95
77
  return this.cachedBody("json");
96
78
  }
@@ -107,10 +89,10 @@ var HonoRequest = class {
107
89
  return this.cachedBody("formData");
108
90
  }
109
91
  addValidatedData(target, data) {
110
- __privateGet(this, _validatedData)[target] = data;
92
+ this.#validatedData[target] = data;
111
93
  }
112
94
  valid(target) {
113
- return __privateGet(this, _validatedData)[target];
95
+ return this.#validatedData[target];
114
96
  }
115
97
  get url() {
116
98
  return this.raw.url;
@@ -119,14 +101,12 @@ var HonoRequest = class {
119
101
  return this.raw.method;
120
102
  }
121
103
  get matchedRoutes() {
122
- return __privateGet(this, _matchResult)[0].map(([[, route]]) => route);
104
+ return this.#matchResult[0].map(([[, route]]) => route);
123
105
  }
124
106
  get routePath() {
125
- return __privateGet(this, _matchResult)[0].map(([[, route]]) => route)[this.routeIndex].path;
107
+ return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
126
108
  }
127
109
  };
128
- _validatedData = new WeakMap();
129
- _matchResult = new WeakMap();
130
110
  export {
131
111
  HonoRequest
132
112
  };
@@ -5,10 +5,8 @@ var emptyParams = {};
5
5
  var splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
6
6
  var splitByStarRe = /\*/;
7
7
  var LinearRouter = class {
8
- constructor() {
9
- this.name = "LinearRouter";
10
- this.routes = [];
11
- }
8
+ name = "LinearRouter";
9
+ routes = [];
12
10
  add(method, path, handler) {
13
11
  ;
14
12
  (checkOptionalParameter(path) || [path]).forEach((p) => {
@@ -91,7 +89,7 @@ var LinearRouter = class {
91
89
  value = path.slice(pos + 1, endValuePos);
92
90
  pos = endValuePos;
93
91
  }
94
- params[name] || (params[name] = value);
92
+ params[name] ||= value;
95
93
  } else {
96
94
  const index = path.indexOf(part, pos);
97
95
  if (index !== pos) {
@@ -1,10 +1,8 @@
1
1
  // src/router/pattern-router/router.ts
2
2
  import { METHOD_NAME_ALL, UnsupportedPathError } from "../../router.js";
3
3
  var PatternRouter = class {
4
- constructor() {
5
- this.name = "PatternRouter";
6
- this.routes = [];
7
- }
4
+ name = "PatternRouter";
5
+ routes = [];
8
6
  add(method, path, handler) {
9
7
  const endsWithWildcard = path[path.length - 1] === "*";
10
8
  if (endsWithWildcard) {
@@ -23,9 +23,9 @@ function compareKey(a, b) {
23
23
  return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
24
24
  }
25
25
  var Node = class {
26
- constructor() {
27
- this.children = {};
28
- }
26
+ index;
27
+ varIndex;
28
+ children = {};
29
29
  insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
30
30
  if (tokens.length === 0) {
31
31
  if (this.index !== void 0) {
@@ -11,9 +11,9 @@ var emptyParam = [];
11
11
  var nullMatcher = [/^$/, [], {}];
12
12
  var wildcardRegExpCache = {};
13
13
  function buildWildcardRegExp(path) {
14
- return wildcardRegExpCache[path] ?? (wildcardRegExpCache[path] = new RegExp(
14
+ return wildcardRegExpCache[path] ??= new RegExp(
15
15
  path === "*" ? "" : `^${path.replace(/\/\*/, "(?:|/.*)")}$`
16
- ));
16
+ );
17
17
  }
18
18
  function clearWildcardRegExpCache() {
19
19
  wildcardRegExpCache = {};
@@ -87,13 +87,14 @@ function findMiddleware(middleware, path) {
87
87
  return void 0;
88
88
  }
89
89
  var RegExpRouter = class {
90
+ name = "RegExpRouter";
91
+ middleware;
92
+ routes;
90
93
  constructor() {
91
- this.name = "RegExpRouter";
92
94
  this.middleware = { [METHOD_NAME_ALL]: {} };
93
95
  this.routes = { [METHOD_NAME_ALL]: {} };
94
96
  }
95
97
  add(method, path, handler) {
96
- var _a;
97
98
  const { middleware, routes } = this;
98
99
  if (!middleware || !routes) {
99
100
  throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
@@ -115,11 +116,10 @@ var RegExpRouter = class {
115
116
  const re = buildWildcardRegExp(path);
116
117
  if (method === METHOD_NAME_ALL) {
117
118
  Object.keys(middleware).forEach((m) => {
118
- var _a2;
119
- (_a2 = middleware[m])[path] || (_a2[path] = findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || []);
119
+ middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
120
120
  });
121
121
  } else {
122
- (_a = middleware[method])[path] || (_a[path] = findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || []);
122
+ middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
123
123
  }
124
124
  Object.keys(middleware).forEach((m) => {
125
125
  if (method === METHOD_NAME_ALL || method === m) {
@@ -141,11 +141,10 @@ var RegExpRouter = class {
141
141
  for (let i = 0, len = paths.length; i < len; i++) {
142
142
  const path2 = paths[i];
143
143
  Object.keys(routes).forEach((m) => {
144
- var _a2;
145
144
  if (method === METHOD_NAME_ALL || method === m) {
146
- (_a2 = routes[m])[path2] || (_a2[path2] = [
145
+ routes[m][path2] ||= [
147
146
  ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
148
- ]);
147
+ ];
149
148
  routes[m][path2].push([handler, paramCount - len + i + 1]);
150
149
  }
151
150
  });
@@ -172,7 +171,7 @@ var RegExpRouter = class {
172
171
  buildAllMatchers() {
173
172
  const matchers = {};
174
173
  [...Object.keys(this.routes), ...Object.keys(this.middleware)].forEach((method) => {
175
- matchers[method] || (matchers[method] = this.buildMatcher(method));
174
+ matchers[method] ||= this.buildMatcher(method);
176
175
  });
177
176
  this.middleware = this.routes = void 0;
178
177
  return matchers;
@@ -183,7 +182,7 @@ var RegExpRouter = class {
183
182
  [this.middleware, this.routes].forEach((r) => {
184
183
  const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
185
184
  if (ownRoute.length !== 0) {
186
- hasOwnRoute || (hasOwnRoute = true);
185
+ hasOwnRoute ||= true;
187
186
  routes.push(...ownRoute);
188
187
  } else if (method !== METHOD_NAME_ALL) {
189
188
  routes.push(
@@ -1,10 +1,8 @@
1
1
  // src/router/reg-exp-router/trie.ts
2
2
  import { Node } from "./node.js";
3
3
  var Trie = class {
4
- constructor() {
5
- this.context = { varIndex: 0 };
6
- this.root = new Node();
7
- }
4
+ context = { varIndex: 0 };
5
+ root = new Node();
8
6
  insert(path, index, pathErrorCheckOnly) {
9
7
  const paramAssoc = [];
10
8
  const groups = [];
@@ -1,10 +1,10 @@
1
1
  // src/router/smart-router/router.ts
2
2
  import { UnsupportedPathError, MESSAGE_MATCHER_IS_ALREADY_BUILT } from "../../router.js";
3
3
  var SmartRouter = class {
4
+ name = "SmartRouter";
5
+ routers = [];
6
+ routes = [];
4
7
  constructor(init) {
5
- this.name = "SmartRouter";
6
- this.routers = [];
7
- this.routes = [];
8
8
  Object.assign(this, init);
9
9
  }
10
10
  add(method, path, handler) {
@@ -2,9 +2,13 @@
2
2
  import { METHOD_NAME_ALL } from "../../router.js";
3
3
  import { splitPath, splitRoutingPath, getPattern } from "../../utils/url.js";
4
4
  var Node = class {
5
+ methods;
6
+ children;
7
+ patterns;
8
+ order = 0;
9
+ name;
10
+ params = {};
5
11
  constructor(method, handler, children) {
6
- this.order = 0;
7
- this.params = {};
8
12
  this.children = children || {};
9
13
  this.methods = [];
10
14
  this.name = "";
@@ -2,8 +2,9 @@
2
2
  import { checkOptionalParameter } from "../../utils/url.js";
3
3
  import { Node } from "./node.js";
4
4
  var TrieRouter = class {
5
+ name = "TrieRouter";
6
+ node;
5
7
  constructor() {
6
- this.name = "TrieRouter";
7
8
  this.node = new Node();
8
9
  }
9
10
  add(method, path, handler) {
@@ -3,6 +3,8 @@ import crypto from "node:crypto";
3
3
  import { vi } from "vitest";
4
4
  vi.stubGlobal("crypto", crypto);
5
5
  var MockCache = class {
6
+ name;
7
+ store;
6
8
  constructor(name, store) {
7
9
  this.name = name;
8
10
  this.store = store;
@@ -1,2 +1,3 @@
1
1
  export { serveStatic } from './serve-static';
2
2
  export { bunFileSystemModule, toSSG } from './ssg';
3
+ export { createBunWebSocket } from './websocket';
@@ -0,0 +1,26 @@
1
+ /// <reference types="node" />
2
+ import { type UpgradeWebSocket } from '../../helper/websocket';
3
+ interface BunServerWebSocket<T> {
4
+ send(data: string | ArrayBufferLike, compress?: boolean): void;
5
+ close(code?: number, reason?: string): void;
6
+ data: T;
7
+ readyState: 0 | 1 | 2 | 3;
8
+ }
9
+ interface BunWebSocketHandler<T> {
10
+ open(ws: BunServerWebSocket<T>): void;
11
+ close(ws: BunServerWebSocket<T>, code?: number, reason?: string): void;
12
+ message(ws: BunServerWebSocket<T>, message: string | Buffer): void;
13
+ }
14
+ interface CreateWebSocket {
15
+ (): {
16
+ upgradeWebSocket: UpgradeWebSocket;
17
+ websocket: BunWebSocketHandler<BunWebSocketData>;
18
+ };
19
+ }
20
+ export interface BunWebSocketData {
21
+ connId: number;
22
+ url: URL;
23
+ protocol: string;
24
+ }
25
+ export declare const createBunWebSocket: CreateWebSocket;
26
+ export {};
@@ -1 +1,2 @@
1
1
  export { serveStatic } from './serve-static-module';
2
+ export { upgradeWebSocket } from './websocket';
@@ -0,0 +1,2 @@
1
+ import type { UpgradeWebSocket } from '../../helper/websocket';
2
+ export declare const upgradeWebSocket: UpgradeWebSocket;
@@ -1,2 +1,3 @@
1
1
  export { serveStatic } from './serve-static';
2
2
  export { toSSG, denoFileSystemModule } from './ssg';
3
+ export { upgradeWebSocket } from './websocket';
@@ -0,0 +1,2 @@
1
+ import type { UpgradeWebSocket } from '../../helper/websocket';
2
+ export declare const upgradeWebSocket: UpgradeWebSocket;