hono 4.6.8 → 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 (96) hide show
  1. package/dist/adapter/cloudflare-workers/websocket.js +34 -39
  2. package/dist/adapter/deno/serve-static.js +5 -1
  3. package/dist/adapter/lambda-edge/handler.js +1 -1
  4. package/dist/cjs/adapter/cloudflare-workers/websocket.js +34 -39
  5. package/dist/cjs/adapter/deno/serve-static.js +5 -1
  6. package/dist/cjs/adapter/lambda-edge/handler.js +1 -1
  7. package/dist/cjs/client/client.js +3 -3
  8. package/dist/cjs/compose.js +4 -3
  9. package/dist/cjs/context.js +12 -9
  10. package/dist/cjs/helper/html/index.js +1 -1
  11. package/dist/cjs/helper/ssg/ssg.js +2 -2
  12. package/dist/cjs/helper/ssg/utils.js +2 -2
  13. package/dist/cjs/hono-base.js +38 -41
  14. package/dist/cjs/jsx/base.js +8 -3
  15. package/dist/cjs/jsx/constants.js +3 -0
  16. package/dist/cjs/jsx/dom/index.js +8 -2
  17. package/dist/cjs/jsx/dom/render.js +15 -12
  18. package/dist/cjs/middleware/combine/index.js +15 -9
  19. package/dist/cjs/middleware/etag/digest.js +59 -0
  20. package/dist/cjs/middleware/etag/index.js +5 -2
  21. package/dist/cjs/middleware/ip-restriction/index.js +3 -3
  22. package/dist/cjs/middleware/jsx-renderer/index.js +2 -1
  23. package/dist/cjs/middleware/logger/index.js +13 -11
  24. package/dist/cjs/middleware/timing/timing.js +5 -7
  25. package/dist/cjs/request.js +15 -14
  26. package/dist/cjs/router/linear-router/router.js +4 -4
  27. package/dist/cjs/router/pattern-router/router.js +4 -4
  28. package/dist/cjs/router/reg-exp-router/node.js +18 -18
  29. package/dist/cjs/router/reg-exp-router/router.js +13 -12
  30. package/dist/cjs/router/reg-exp-router/trie.js +6 -6
  31. package/dist/cjs/router/smart-router/router.js +12 -11
  32. package/dist/cjs/router/trie-router/node.js +53 -47
  33. package/dist/cjs/router/trie-router/router.js +5 -5
  34. package/dist/cjs/utils/color.js +1 -1
  35. package/dist/cjs/utils/cookie.js +13 -6
  36. package/dist/cjs/utils/crypto.js +0 -9
  37. package/dist/cjs/utils/jwt/jwt.js +1 -1
  38. package/dist/cjs/utils/mime.js +2 -1
  39. package/dist/cjs/utils/url.js +9 -6
  40. package/dist/client/client.js +3 -3
  41. package/dist/compose.js +4 -3
  42. package/dist/context.js +12 -9
  43. package/dist/helper/html/index.js +1 -1
  44. package/dist/helper/ssg/ssg.js +2 -2
  45. package/dist/helper/ssg/utils.js +2 -2
  46. package/dist/hono-base.js +38 -41
  47. package/dist/jsx/base.js +7 -3
  48. package/dist/jsx/constants.js +2 -0
  49. package/dist/jsx/dom/index.js +7 -1
  50. package/dist/jsx/dom/render.js +22 -13
  51. package/dist/middleware/combine/index.js +15 -9
  52. package/dist/middleware/etag/digest.js +36 -0
  53. package/dist/middleware/etag/index.js +5 -2
  54. package/dist/middleware/ip-restriction/index.js +3 -3
  55. package/dist/middleware/jsx-renderer/index.js +2 -1
  56. package/dist/middleware/logger/index.js +13 -11
  57. package/dist/middleware/timing/timing.js +5 -7
  58. package/dist/request.js +16 -15
  59. package/dist/router/linear-router/router.js +4 -4
  60. package/dist/router/pattern-router/router.js +4 -4
  61. package/dist/router/reg-exp-router/node.js +18 -18
  62. package/dist/router/reg-exp-router/router.js +13 -12
  63. package/dist/router/reg-exp-router/trie.js +6 -6
  64. package/dist/router/smart-router/router.js +12 -11
  65. package/dist/router/trie-router/node.js +53 -47
  66. package/dist/router/trie-router/router.js +5 -5
  67. package/dist/types/adapter/cloudflare-workers/websocket.d.ts +2 -2
  68. package/dist/types/adapter/deno/websocket.d.ts +1 -20
  69. package/dist/types/adapter/service-worker/index.d.ts +1 -1
  70. package/dist/types/compose.d.ts +5 -2
  71. package/dist/types/context.d.ts +1 -1
  72. package/dist/types/helper/websocket/index.d.ts +1 -1
  73. package/dist/types/hono-base.d.ts +1 -1
  74. package/dist/types/jsx/base.d.ts +5 -0
  75. package/dist/types/jsx/constants.d.ts +1 -0
  76. package/dist/types/jsx/dom/index.d.ts +6 -5
  77. package/dist/types/jsx/dom/render.d.ts +1 -0
  78. package/dist/types/middleware/etag/digest.d.ts +1 -0
  79. package/dist/types/router/linear-router/router.d.ts +0 -5
  80. package/dist/types/router/reg-exp-router/node.d.ts +0 -3
  81. package/dist/types/router/reg-exp-router/router.d.ts +0 -7
  82. package/dist/types/router/reg-exp-router/trie.d.ts +1 -4
  83. package/dist/types/router/smart-router/router.d.ts +3 -7
  84. package/dist/types/router/trie-router/node.d.ts +0 -12
  85. package/dist/types/router/trie-router/router.d.ts +0 -2
  86. package/dist/types/utils/body.d.ts +2 -2
  87. package/dist/types/utils/crypto.d.ts +2 -1
  88. package/dist/types/utils/mime.d.ts +58 -1
  89. package/dist/types/utils/url.d.ts +3 -0
  90. package/dist/utils/color.js +1 -1
  91. package/dist/utils/cookie.js +13 -6
  92. package/dist/utils/crypto.js +0 -9
  93. package/dist/utils/jwt/jwt.js +1 -1
  94. package/dist/utils/mime.js +2 -1
  95. package/dist/utils/url.js +7 -5
  96. package/package.json +20 -12
package/dist/hono-base.js CHANGED
@@ -36,12 +36,10 @@ var Hono = class {
36
36
  if (typeof args1 === "string") {
37
37
  this.#path = args1;
38
38
  } else {
39
- this.addRoute(method, this.#path, args1);
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
  };
@@ -51,7 +49,7 @@ var Hono = class {
51
49
  this.#path = p;
52
50
  for (const m of [method].flat()) {
53
51
  handlers.map((handler) => {
54
- this.addRoute(m.toUpperCase(), this.#path, handler);
52
+ this.#addRoute(m.toUpperCase(), this.#path, handler);
55
53
  });
56
54
  }
57
55
  }
@@ -65,7 +63,7 @@ var Hono = class {
65
63
  handlers.unshift(arg1);
66
64
  }
67
65
  handlers.forEach((handler) => {
68
- this.addRoute(METHOD_NAME_ALL, this.#path, handler);
66
+ this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
69
67
  });
70
68
  return this;
71
69
  };
@@ -74,7 +72,7 @@ var Hono = class {
74
72
  Object.assign(this, options);
75
73
  this.getPath = strict ? options.getPath ?? getPath : getPathNoStrict;
76
74
  }
77
- clone() {
75
+ #clone() {
78
76
  const clone = new Hono({
79
77
  router: this.router,
80
78
  getPath: this.getPath
@@ -82,33 +80,33 @@ var Hono = class {
82
80
  clone.routes = this.routes;
83
81
  return clone;
84
82
  }
85
- notFoundHandler = notFoundHandler;
86
- errorHandler = errorHandler;
83
+ #notFoundHandler = notFoundHandler;
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
- subApp.addRoute(r.method, r.path, handler);
95
+ subApp.#addRoute(r.method, r.path, handler);
98
96
  });
99
97
  return this;
100
98
  }
101
99
  basePath(path) {
102
- const subApp = this.clone();
100
+ const subApp = this.#clone();
103
101
  subApp._basePath = mergePath(this._basePath, path);
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) => {
111
- this.notFoundHandler = handler;
109
+ this.#notFoundHandler = handler;
112
110
  return this;
113
111
  };
114
112
  mount(path, applicationHandler, options) {
@@ -149,52 +147,49 @@ var Hono = class {
149
147
  }
150
148
  await next();
151
149
  };
152
- this.addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
150
+ this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
153
151
  return this;
154
152
  }
155
- addRoute(method, path, handler) {
153
+ #addRoute(method, path, handler) {
156
154
  method = method.toUpperCase();
157
155
  path = mergePath(this._basePath, path);
158
156
  const r = { path, method, handler };
159
157
  this.router.add(method, path, [handler, r]);
160
158
  this.routes.push(r);
161
159
  }
162
- matchRoute(method, path) {
163
- return this.router.match(method, path);
164
- }
165
- handleError(err, c) {
160
+ #handleError(err, c) {
166
161
  if (err instanceof Error) {
167
- return this.errorHandler(err, c);
162
+ return this.#errorHandler(err, c);
168
163
  }
169
164
  throw err;
170
165
  }
171
- dispatch(request, executionCtx, env, method) {
166
+ #dispatch(request, executionCtx, env, method) {
172
167
  if (method === "HEAD") {
173
- return (async () => new Response(null, await this.dispatch(request, executionCtx, env, "GET")))();
168
+ return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
174
169
  }
175
170
  const path = this.getPath(request, { env });
176
- const matchResult = this.matchRoute(method, path);
171
+ const matchResult = this.router.match(method, path);
177
172
  const c = new Context(request, {
178
173
  path,
179
174
  matchResult,
180
175
  env,
181
176
  executionCtx,
182
- notFoundHandler: this.notFoundHandler
177
+ notFoundHandler: this.#notFoundHandler
183
178
  });
184
179
  if (matchResult[0].length === 1) {
185
180
  let res;
186
181
  try {
187
182
  res = matchResult[0][0][0][0](c, async () => {
188
- c.res = await this.notFoundHandler(c);
183
+ c.res = await this.#notFoundHandler(c);
189
184
  });
190
185
  } catch (err) {
191
- return this.handleError(err, c);
186
+ return this.#handleError(err, c);
192
187
  }
193
188
  return res instanceof Promise ? res.then(
194
- (resolved) => resolved || (c.finalized ? c.res : this.notFoundHandler(c))
195
- ).catch((err) => this.handleError(err, c)) : res ?? this.notFoundHandler(c);
189
+ (resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))
190
+ ).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
196
191
  }
197
- const composed = compose(matchResult[0], this.errorHandler, this.notFoundHandler);
192
+ const composed = compose(matchResult[0], this.#errorHandler, this.#notFoundHandler);
198
193
  return (async () => {
199
194
  try {
200
195
  const context = await composed(c);
@@ -205,28 +200,30 @@ var Hono = class {
205
200
  }
206
201
  return context.res;
207
202
  } catch (err) {
208
- return this.handleError(err, c);
203
+ return this.#handleError(err, c);
209
204
  }
210
205
  })();
211
206
  }
212
207
  fetch = (request, ...rest) => {
213
- return this.dispatch(request, rest[1], rest[0], request.method);
208
+ return this.#dispatch(request, rest[1], rest[0], request.method);
214
209
  };
215
210
  request = (input, requestInit, Env, executionCtx) => {
216
211
  if (input instanceof Request) {
217
- if (requestInit !== void 0) {
218
- input = new Request(input, requestInit);
219
- }
220
- return this.fetch(input, Env, executionCtx);
212
+ return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
221
213
  }
222
214
  input = input.toString();
223
- const path = /^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`;
224
- const req = new Request(path, requestInit);
225
- 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
+ );
226
223
  };
227
224
  fire = () => {
228
225
  addEventListener("fetch", (event) => {
229
- event.respondWith(this.dispatch(event.request, event, void 0, event.request.method));
226
+ event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
230
227
  });
231
228
  };
232
229
  };
package/dist/jsx/base.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/jsx/base.ts
2
2
  import { raw } from "../helper/html/index.js";
3
3
  import { escapeToBuffer, resolveCallbackSync, stringBufferToString } from "../utils/html.js";
4
- import { DOM_RENDERER } from "./constants.js";
4
+ import { DOM_RENDERER, DOM_MEMO } from "./constants.js";
5
5
  import { createContext, globalContexts, useContext } from "./context.js";
6
6
  import { domRenderers } from "./intrinsic-element/common.js";
7
7
  import * as intrinsicElementTags from "./intrinsic-element/components.js";
@@ -270,13 +270,16 @@ var shallowEqual = (a, b) => {
270
270
  var memo = (component, propsAreEqual = shallowEqual) => {
271
271
  let computed = null;
272
272
  let prevProps = void 0;
273
- return (props) => {
273
+ const wrapper = (props) => {
274
274
  if (prevProps && !propsAreEqual(prevProps, props)) {
275
275
  computed = null;
276
276
  }
277
277
  prevProps = props;
278
278
  return computed ||= component(props);
279
279
  };
280
+ wrapper[DOM_MEMO] = propsAreEqual;
281
+ wrapper[DOM_RENDERER] = component;
282
+ return wrapper;
280
283
  };
281
284
  var Fragment = ({
282
285
  children
@@ -311,5 +314,6 @@ export {
311
314
  jsx,
312
315
  jsxFn,
313
316
  memo,
314
- reactAPICompatVersion
317
+ reactAPICompatVersion,
318
+ shallowEqual
315
319
  };
@@ -3,10 +3,12 @@ var DOM_RENDERER = Symbol("RENDERER");
3
3
  var DOM_ERROR_HANDLER = Symbol("ERROR_HANDLER");
4
4
  var DOM_STASH = Symbol("STASH");
5
5
  var DOM_INTERNAL_TAG = Symbol("INTERNAL");
6
+ var DOM_MEMO = Symbol("MEMO");
6
7
  var PERMALINK = Symbol("PERMALINK");
7
8
  export {
8
9
  DOM_ERROR_HANDLER,
9
10
  DOM_INTERNAL_TAG,
11
+ DOM_MEMO,
10
12
  DOM_RENDERER,
11
13
  DOM_STASH,
12
14
  PERMALINK
@@ -1,6 +1,7 @@
1
1
  // src/jsx/dom/index.ts
2
- import { isValidElement, memo, reactAPICompatVersion } from "../base.js";
2
+ import { isValidElement, reactAPICompatVersion, shallowEqual } from "../base.js";
3
3
  import { Children } from "../children.js";
4
+ import { DOM_MEMO } from "../constants.js";
4
5
  import { useContext } from "../context.js";
5
6
  import {
6
7
  createRef,
@@ -53,6 +54,11 @@ var cloneElement = (element, props, ...children) => {
53
54
  element.key
54
55
  );
55
56
  };
57
+ var memo = (component, propsAreEqual = shallowEqual) => {
58
+ const wrapper = (props) => component(props);
59
+ wrapper[DOM_MEMO] = propsAreEqual;
60
+ return wrapper;
61
+ };
56
62
  var dom_default = {
57
63
  version: reactAPICompatVersion,
58
64
  useState,
@@ -1,6 +1,12 @@
1
1
  // src/jsx/dom/render.ts
2
2
  import { toArray } from "../children.js";
3
- import { DOM_ERROR_HANDLER, DOM_INTERNAL_TAG, DOM_RENDERER, DOM_STASH } from "../constants.js";
3
+ import {
4
+ DOM_ERROR_HANDLER,
5
+ DOM_INTERNAL_TAG,
6
+ DOM_MEMO,
7
+ DOM_RENDERER,
8
+ DOM_STASH
9
+ } from "../constants.js";
4
10
  import { globalContexts as globalJSXContexts, useContext } from "../context.js";
5
11
  import { STASH_EFFECT } from "../hooks/index.js";
6
12
  import { normalizeIntrinsicElementKey, styleObjectForEach } from "../utils.js";
@@ -228,13 +234,19 @@ var applyNodeObject = (node, container, isNew) => {
228
234
  remove.forEach(removeNode);
229
235
  const childNodes = isNew ? void 0 : container.childNodes;
230
236
  let offset;
237
+ let insertBeforeNode = null;
231
238
  if (isNew) {
232
239
  offset = -1;
240
+ } else if (!childNodes.length) {
241
+ offset = 0;
233
242
  } else {
234
- offset = (childNodes.length && (findChildNodeIndex(childNodes, findInsertBefore(node.nN)) ?? findChildNodeIndex(
235
- childNodes,
236
- next.find((n) => n.tag !== HONO_PORTAL_ELEMENT && n.e)?.e
237
- ))) ?? -1;
243
+ const offsetByNextNode = findChildNodeIndex(childNodes, findInsertBefore(node.nN));
244
+ if (offsetByNextNode !== void 0) {
245
+ insertBeforeNode = childNodes[offsetByNextNode];
246
+ offset = offsetByNextNode;
247
+ } else {
248
+ offset = findChildNodeIndex(childNodes, next.find((n) => n.tag !== HONO_PORTAL_ELEMENT && n.e)?.e) ?? -1;
249
+ }
238
250
  if (offset === -1) {
239
251
  isNew = true;
240
252
  }
@@ -269,7 +281,7 @@ var applyNodeObject = (node, container, isNew) => {
269
281
  if (childNodes[offset + 1] === el) {
270
282
  container.appendChild(childNodes[offset]);
271
283
  } else {
272
- container.insertBefore(el, childNodes[offset] || null);
284
+ container.insertBefore(el, insertBeforeNode || childNodes[offset] || null);
273
285
  }
274
286
  }
275
287
  }
@@ -351,12 +363,8 @@ var build = (context, node, children) => {
351
363
  if (typeof child.tag === "function") {
352
364
  oldChild[DOM_STASH][2] = child[DOM_STASH][2] || [];
353
365
  oldChild[DOM_STASH][3] = child[DOM_STASH][3];
354
- if (!oldChild.f) {
355
- const prevPropsKeys = Object.keys(pP);
356
- const currentProps = oldChild.props;
357
- if (prevPropsKeys.length === Object.keys(currentProps).length && prevPropsKeys.every((k) => k in currentProps && currentProps[k] === pP[k])) {
358
- oldChild.s = true;
359
- }
366
+ if (!oldChild.f && ((oldChild.o || oldChild) === child.o || oldChild.tag[DOM_MEMO]?.(pP, oldChild.props))) {
367
+ oldChild.s = true;
360
368
  }
361
369
  }
362
370
  child = oldChild;
@@ -443,7 +451,8 @@ var buildNode = (node) => {
443
451
  key: node.key,
444
452
  f: node.f,
445
453
  type: node.tag,
446
- ref: node.props.ref
454
+ ref: node.props.ref,
455
+ o: node.o || node
447
456
  };
448
457
  }
449
458
  if (typeof node.tag === "function") {
@@ -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) => {
@@ -0,0 +1,36 @@
1
+ // src/middleware/etag/digest.ts
2
+ var mergeBuffers = (buffer1, buffer2) => {
3
+ if (!buffer1) {
4
+ return buffer2;
5
+ }
6
+ const merged = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
7
+ merged.set(new Uint8Array(buffer1), 0);
8
+ merged.set(buffer2, buffer1.byteLength);
9
+ return merged;
10
+ };
11
+ var generateDigest = async (stream) => {
12
+ if (!stream || !crypto || !crypto.subtle) {
13
+ return null;
14
+ }
15
+ let result = void 0;
16
+ const reader = stream.getReader();
17
+ for (; ; ) {
18
+ const { value, done } = await reader.read();
19
+ if (done) {
20
+ break;
21
+ }
22
+ result = await crypto.subtle.digest(
23
+ {
24
+ name: "SHA-1"
25
+ },
26
+ mergeBuffers(result, value)
27
+ );
28
+ }
29
+ if (!result) {
30
+ return null;
31
+ }
32
+ return Array.prototype.map.call(new Uint8Array(result), (x) => x.toString(16).padStart(2, "0")).join("");
33
+ };
34
+ export {
35
+ generateDigest
36
+ };
@@ -1,5 +1,5 @@
1
1
  // src/middleware/etag/index.ts
2
- import { sha1 } from "../../utils/crypto.js";
2
+ import { generateDigest } from "./digest.js";
3
3
  var RETAINED_304_HEADERS = [
4
4
  "cache-control",
5
5
  "content-location",
@@ -20,7 +20,10 @@ var etag = (options) => {
20
20
  const res = c.res;
21
21
  let etag3 = res.headers.get("ETag");
22
22
  if (!etag3) {
23
- const hash = await sha1(res.clone().body || "");
23
+ const hash = await generateDigest(res.clone().body);
24
+ if (hash === null) {
25
+ return;
26
+ }
24
27
  etag3 = weak ? `W/"${hash}"` : `"${hash}"`;
25
28
  }
26
29
  if (etagMatches(etag3, ifNoneMatch)) {
@@ -18,14 +18,14 @@ var buildMatcher = (rules) => {
18
18
  functionRules.push(rule);
19
19
  } else {
20
20
  if (IS_CIDR_NOTATION_REGEX.test(rule)) {
21
- const splittedRule = rule.split("/");
22
- const addrStr = splittedRule[0];
21
+ const separatedRule = rule.split("/");
22
+ const addrStr = separatedRule[0];
23
23
  const type2 = distinctRemoteAddr(addrStr);
24
24
  if (type2 === void 0) {
25
25
  throw new TypeError(`Invalid rule: ${rule}`);
26
26
  }
27
27
  const isIPv4 = type2 === "IPv4";
28
- const prefix = parseInt(splittedRule[1]);
28
+ const prefix = parseInt(separatedRule[1]);
29
29
  if (isIPv4 ? prefix === 32 : prefix === 128) {
30
30
  rule = addrStr;
31
31
  } else {
@@ -8,7 +8,8 @@ var createRenderer = (c, Layout, component, options) => (children, props) => {
8
8
  const currentLayout = component ? jsx(
9
9
  (props2) => component(props2, c),
10
10
  {
11
- ...{ Layout, ...props }
11
+ Layout,
12
+ ...props
12
13
  },
13
14
  children
14
15
  ) : children;
@@ -12,17 +12,19 @@ var time = (start) => {
12
12
  };
13
13
  var colorStatus = (status) => {
14
14
  const colorEnabled = getColorEnabled();
15
- const out = {
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}`
23
- };
24
- const calculateStatus = status / 100 | 0;
25
- return out[calculateStatus];
15
+ if (colorEnabled) {
16
+ switch (status / 100 | 0) {
17
+ case 5:
18
+ return `\x1B[31m${status}\x1B[0m`;
19
+ case 4:
20
+ return `\x1B[33m${status}\x1B[0m`;
21
+ case 3:
22
+ return `\x1B[36m${status}\x1B[0m`;
23
+ case 2:
24
+ return `\x1B[32m${status}\x1B[0m`;
25
+ }
26
+ }
27
+ return `${status}`;
26
28
  };
27
29
  function log(fn, prefix, method, path, status = 0, elapsed) {
28
30
  const out = prefix === "<--" /* Incoming */ ? `${prefix} ${method} ${path}` : `${prefix} ${method} ${path} ${colorStatus(status)} ${elapsed}`;
@@ -9,13 +9,11 @@ var getTime = () => {
9
9
  };
10
10
  var timing = (config) => {
11
11
  const options = {
12
- ...{
13
- total: true,
14
- enabled: true,
15
- totalDescription: "Total Response Time",
16
- autoEnd: true,
17
- crossOrigin: false
18
- },
12
+ total: true,
13
+ enabled: true,
14
+ totalDescription: "Total Response Time",
15
+ autoEnd: true,
16
+ crossOrigin: false,
19
17
  ...config
20
18
  };
21
19
  return async function timing2(c, next) {
package/dist/request.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/request.ts
2
2
  import { parseBody } from "./utils/body.js";
3
- import { decodeURIComponent_, getQueryParam, getQueryParams } from "./utils/url.js";
3
+ import { decodeURIComponent_, getQueryParam, getQueryParams, tryDecode } from "./utils/url.js";
4
+ var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
4
5
  var HonoRequest = class {
5
6
  raw;
6
7
  #validatedData;
@@ -15,25 +16,25 @@ var HonoRequest = class {
15
16
  this.#validatedData = {};
16
17
  }
17
18
  param(key) {
18
- return key ? this.getDecodedParam(key) : this.getAllDecodedParams();
19
+ return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
19
20
  }
20
- getDecodedParam(key) {
21
+ #getDecodedParam(key) {
21
22
  const paramKey = this.#matchResult[0][this.routeIndex][1][key];
22
- const param = this.getParamValue(paramKey);
23
- return param ? /\%/.test(param) ? decodeURIComponent_(param) : param : void 0;
23
+ const param = this.#getParamValue(paramKey);
24
+ return param ? /\%/.test(param) ? tryDecodeURIComponent(param) : param : void 0;
24
25
  }
25
- getAllDecodedParams() {
26
+ #getAllDecodedParams() {
26
27
  const decoded = {};
27
28
  const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
28
29
  for (const key of keys) {
29
- const value = this.getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
30
+ const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
30
31
  if (value && typeof value === "string") {
31
- decoded[key] = /\%/.test(value) ? decodeURIComponent_(value) : value;
32
+ decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
32
33
  }
33
34
  }
34
35
  return decoded;
35
36
  }
36
- getParamValue(paramKey) {
37
+ #getParamValue(paramKey) {
37
38
  return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
38
39
  }
39
40
  query(key) {
@@ -55,7 +56,7 @@ var HonoRequest = class {
55
56
  async parseBody(options) {
56
57
  return this.bodyCache.parsedBody ??= await parseBody(this, options);
57
58
  }
58
- cachedBody = (key) => {
59
+ #cachedBody = (key) => {
59
60
  const { bodyCache, raw } = this;
60
61
  const cachedBody = bodyCache[key];
61
62
  if (cachedBody) {
@@ -73,19 +74,19 @@ var HonoRequest = class {
73
74
  return bodyCache[key] = raw[key]();
74
75
  };
75
76
  json() {
76
- return this.cachedBody("json");
77
+ return this.#cachedBody("json");
77
78
  }
78
79
  text() {
79
- return this.cachedBody("text");
80
+ return this.#cachedBody("text");
80
81
  }
81
82
  arrayBuffer() {
82
- return this.cachedBody("arrayBuffer");
83
+ return this.#cachedBody("arrayBuffer");
83
84
  }
84
85
  blob() {
85
- return this.cachedBody("blob");
86
+ return this.#cachedBody("blob");
86
87
  }
87
88
  formData() {
88
- return this.cachedBody("formData");
89
+ return this.#cachedBody("formData");
89
90
  }
90
91
  addValidatedData(target, data) {
91
92
  this.#validatedData[target] = data;
@@ -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]);
@@ -2,7 +2,7 @@
2
2
  import { METHOD_NAME_ALL, UnsupportedPathError } from "../../router.js";
3
3
  var PatternRouter = class {
4
4
  name = "PatternRouter";
5
- routes = [];
5
+ #routes = [];
6
6
  add(method, path, handler) {
7
7
  const endsWithWildcard = path[path.length - 1] === "*";
8
8
  if (endsWithWildcard) {
@@ -24,12 +24,12 @@ var PatternRouter = class {
24
24
  } catch {
25
25
  throw new UnsupportedPathError();
26
26
  }
27
- this.routes.push([re, method, handler]);
27
+ this.#routes.push([re, method, handler]);
28
28
  }
29
29
  match(method, path) {
30
30
  const handlers = [];
31
- for (let i = 0, len = this.routes.length; i < len; i++) {
32
- const [pattern, routeMethod, handler] = this.routes[i];
31
+ for (let i = 0, len = this.#routes.length; i < len; i++) {
32
+ const [pattern, routeMethod, handler] = this.#routes[i];
33
33
  if (routeMethod === method || routeMethod === METHOD_NAME_ALL) {
34
34
  const match = pattern.exec(path);
35
35
  if (match) {