hono 4.6.0 → 4.6.2

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 (45) hide show
  1. package/dist/adapter/bun/serve-static.js +1 -1
  2. package/dist/cjs/adapter/bun/serve-static.js +1 -1
  3. package/dist/cjs/helper/ssg/middleware.js +1 -1
  4. package/dist/cjs/helper/streaming/sse.js +1 -1
  5. package/dist/cjs/jsx/base.js +3 -3
  6. package/dist/cjs/jsx/dom/hooks/index.js +2 -2
  7. package/dist/cjs/jsx/dom/index.js +1 -1
  8. package/dist/cjs/jsx/dom/intrinsic-element/components.js +2 -2
  9. package/dist/cjs/jsx/dom/render.js +1 -1
  10. package/dist/cjs/jsx/index.js +46 -46
  11. package/dist/cjs/jsx/intrinsic-element/components.js +3 -3
  12. package/dist/cjs/middleware/combine/index.js +2 -2
  13. package/dist/cjs/middleware/compress/index.js +2 -2
  14. package/dist/cjs/middleware/serve-static/index.js +12 -11
  15. package/dist/cjs/router/pattern-router/router.js +1 -1
  16. package/dist/cjs/utils/compress.js +28 -0
  17. package/dist/cjs/utils/cookie.js +1 -1
  18. package/dist/cjs/utils/jwt/jwt.js +1 -1
  19. package/dist/cjs/utils/stream.js +2 -2
  20. package/dist/helper/ssg/middleware.js +1 -1
  21. package/dist/helper/streaming/sse.js +1 -1
  22. package/dist/helper/streaming/text.js +1 -1
  23. package/dist/jsx/base.js +3 -3
  24. package/dist/jsx/dom/hooks/index.js +2 -2
  25. package/dist/jsx/dom/index.js +1 -1
  26. package/dist/jsx/dom/intrinsic-element/components.js +2 -2
  27. package/dist/jsx/dom/render.js +1 -1
  28. package/dist/jsx/dom/server.js +1 -1
  29. package/dist/jsx/index.js +1 -1
  30. package/dist/jsx/intrinsic-element/components.js +3 -3
  31. package/dist/middleware/combine/index.js +2 -2
  32. package/dist/middleware/compress/index.js +2 -2
  33. package/dist/middleware/serve-static/index.js +12 -11
  34. package/dist/router/pattern-router/router.js +1 -1
  35. package/dist/types/context.d.ts +1 -1
  36. package/dist/types/jsx/dom/index.d.ts +1 -1
  37. package/dist/types/jsx/dom/intrinsic-element/components.d.ts +1 -1
  38. package/dist/types/jsx/index.d.ts +1 -1
  39. package/dist/types/jsx/intrinsic-element/components.d.ts +1 -1
  40. package/dist/types/utils/compress.d.ts +8 -0
  41. package/dist/utils/compress.js +5 -0
  42. package/dist/utils/cookie.js +1 -1
  43. package/dist/utils/jwt/jwt.js +1 -1
  44. package/dist/utils/stream.js +2 -2
  45. package/package.json +6 -6
@@ -1,6 +1,6 @@
1
1
  // src/adapter/bun/serve-static.ts
2
- import { serveStatic as baseServeStatic } from "../../middleware/serve-static/index.js";
3
2
  import { stat } from "node:fs/promises";
3
+ import { serveStatic as baseServeStatic } from "../../middleware/serve-static/index.js";
4
4
  var serveStatic = (options) => {
5
5
  return async function serveStatic2(c, next) {
6
6
  const getContent = async (path) => {
@@ -21,8 +21,8 @@ __export(serve_static_exports, {
21
21
  serveStatic: () => serveStatic
22
22
  });
23
23
  module.exports = __toCommonJS(serve_static_exports);
24
- var import_serve_static = require("../../middleware/serve-static");
25
24
  var import_promises = require("node:fs/promises");
25
+ var import_serve_static = require("../../middleware/serve-static");
26
26
  const serveStatic = (options) => {
27
27
  return async function serveStatic2(c, next) {
28
28
  const getContent = async (path) => {
@@ -35,7 +35,7 @@ const SSG_DISABLED_RESPONSE = (() => {
35
35
  status: 404,
36
36
  headers: { [X_HONO_DISABLE_SSG_HEADER_KEY]: "true" }
37
37
  });
38
- } catch (e) {
38
+ } catch {
39
39
  return null;
40
40
  }
41
41
  })();
@@ -22,8 +22,8 @@ __export(sse_exports, {
22
22
  streamSSE: () => streamSSE
23
23
  });
24
24
  module.exports = __toCommonJS(sse_exports);
25
- var import_stream = require("../../utils/stream");
26
25
  var import_html = require("../../utils/html");
26
+ var import_stream = require("../../utils/stream");
27
27
  class SSEStreamingApi extends import_stream.StreamingApi {
28
28
  constructor(writable, readable) {
29
29
  super(writable, readable);
@@ -38,11 +38,11 @@ __export(base_exports, {
38
38
  module.exports = __toCommonJS(base_exports);
39
39
  var import_html = require("../helper/html");
40
40
  var import_html2 = require("../utils/html");
41
- var import_context = require("./context");
42
41
  var import_constants = require("./constants");
43
- var import_utils = require("./utils");
44
- var intrinsicElementTags = __toESM(require("./intrinsic-element/components"), 1);
42
+ var import_context = require("./context");
45
43
  var import_common = require("./intrinsic-element/common");
44
+ var intrinsicElementTags = __toESM(require("./intrinsic-element/components"), 1);
45
+ var import_utils = require("./utils");
46
46
  let nameSpaceContext = void 0;
47
47
  const getNameSpaceContext = () => nameSpaceContext;
48
48
  const toSVGAttributeName = (key) => /[A-Z]/.test(key) && key.match(
@@ -25,10 +25,10 @@ __export(hooks_exports, {
25
25
  useOptimistic: () => useOptimistic
26
26
  });
27
27
  module.exports = __toCommonJS(hooks_exports);
28
+ var import_constants = require("../../constants");
28
29
  var import_context = require("../../context");
29
- var import_context2 = require("../context");
30
30
  var import_hooks = require("../../hooks");
31
- var import_constants = require("../../constants");
31
+ var import_context2 = require("../context");
32
32
  const FormContext = (0, import_context2.createContext)({
33
33
  pending: false,
34
34
  data: null,
@@ -64,9 +64,9 @@ var import_base = require("../base");
64
64
  var import_children = require("../children");
65
65
  var import_context = require("../context");
66
66
  var import_hooks = require("../hooks");
67
- var import_hooks2 = require("./hooks");
68
67
  var import_components = require("./components");
69
68
  var import_context2 = require("./context");
69
+ var import_hooks2 = require("./hooks");
70
70
  var import_jsx_runtime = require("./jsx-runtime");
71
71
  var import_render = require("./render");
72
72
  var import_render2 = require("./render");
@@ -30,11 +30,11 @@ __export(components_exports, {
30
30
  title: () => title
31
31
  });
32
32
  module.exports = __toCommonJS(components_exports);
33
- var import_render = require("../render");
34
33
  var import_context = require("../../context");
35
34
  var import_hooks = require("../../hooks");
36
- var import_hooks2 = require("../hooks");
37
35
  var import_common = require("../../intrinsic-element/common");
36
+ var import_hooks2 = require("../hooks");
37
+ var import_render = require("../render");
38
38
  const clearCache = () => {
39
39
  blockingPromiseMap = /* @__PURE__ */ Object.create(null);
40
40
  createdElements = /* @__PURE__ */ Object.create(null);
@@ -509,7 +509,7 @@ const updateSync = (context, node) => {
509
509
  });
510
510
  try {
511
511
  build(context, node, void 0);
512
- } catch (e) {
512
+ } catch {
513
513
  return;
514
514
  }
515
515
  if (node.a) {
@@ -26,33 +26,33 @@ __export(jsx_exports, {
26
26
  cloneElement: () => import_base.cloneElement,
27
27
  createContext: () => import_context.createContext,
28
28
  createElement: () => import_base.jsx,
29
- createRef: () => import_hooks.createRef,
29
+ createRef: () => import_hooks2.createRef,
30
30
  default: () => jsx_default,
31
- forwardRef: () => import_hooks.forwardRef,
31
+ forwardRef: () => import_hooks2.forwardRef,
32
32
  isValidElement: () => import_base.isValidElement,
33
33
  jsx: () => import_base.jsx,
34
34
  memo: () => import_base.memo,
35
- startTransition: () => import_hooks.startTransition,
36
- startViewTransition: () => import_hooks.startViewTransition,
37
- use: () => import_hooks.use,
38
- useActionState: () => import_hooks2.useActionState,
39
- useCallback: () => import_hooks.useCallback,
35
+ startTransition: () => import_hooks2.startTransition,
36
+ startViewTransition: () => import_hooks2.startViewTransition,
37
+ use: () => import_hooks2.use,
38
+ useActionState: () => import_hooks.useActionState,
39
+ useCallback: () => import_hooks2.useCallback,
40
40
  useContext: () => import_context.useContext,
41
- useDebugValue: () => import_hooks.useDebugValue,
42
- useDeferredValue: () => import_hooks.useDeferredValue,
43
- useEffect: () => import_hooks.useEffect,
44
- useId: () => import_hooks.useId,
45
- useImperativeHandle: () => import_hooks.useImperativeHandle,
46
- useInsertionEffect: () => import_hooks.useInsertionEffect,
47
- useLayoutEffect: () => import_hooks.useLayoutEffect,
48
- useMemo: () => import_hooks.useMemo,
49
- useOptimistic: () => import_hooks2.useOptimistic,
50
- useReducer: () => import_hooks.useReducer,
51
- useRef: () => import_hooks.useRef,
52
- useState: () => import_hooks.useState,
53
- useSyncExternalStore: () => import_hooks.useSyncExternalStore,
54
- useTransition: () => import_hooks.useTransition,
55
- useViewTransition: () => import_hooks.useViewTransition,
41
+ useDebugValue: () => import_hooks2.useDebugValue,
42
+ useDeferredValue: () => import_hooks2.useDeferredValue,
43
+ useEffect: () => import_hooks2.useEffect,
44
+ useId: () => import_hooks2.useId,
45
+ useImperativeHandle: () => import_hooks2.useImperativeHandle,
46
+ useInsertionEffect: () => import_hooks2.useInsertionEffect,
47
+ useLayoutEffect: () => import_hooks2.useLayoutEffect,
48
+ useMemo: () => import_hooks2.useMemo,
49
+ useOptimistic: () => import_hooks.useOptimistic,
50
+ useReducer: () => import_hooks2.useReducer,
51
+ useRef: () => import_hooks2.useRef,
52
+ useState: () => import_hooks2.useState,
53
+ useSyncExternalStore: () => import_hooks2.useSyncExternalStore,
54
+ useTransition: () => import_hooks2.useTransition,
55
+ useViewTransition: () => import_hooks2.useViewTransition,
56
56
  version: () => import_base.reactAPICompatVersion
57
57
  });
58
58
  module.exports = __toCommonJS(jsx_exports);
@@ -60,8 +60,8 @@ var import_base = require("./base");
60
60
  var import_children = require("./children");
61
61
  var import_components = require("./components");
62
62
  var import_context = require("./context");
63
- var import_hooks = require("./hooks");
64
- var import_hooks2 = require("./dom/hooks");
63
+ var import_hooks = require("./dom/hooks");
64
+ var import_hooks2 = require("./hooks");
65
65
  var import_streaming = require("./streaming");
66
66
  var jsx_default = {
67
67
  version: import_base.reactAPICompatVersion,
@@ -74,28 +74,28 @@ var jsx_default = {
74
74
  ErrorBoundary: import_components.ErrorBoundary,
75
75
  createContext: import_context.createContext,
76
76
  useContext: import_context.useContext,
77
- useState: import_hooks.useState,
78
- useEffect: import_hooks.useEffect,
79
- useRef: import_hooks.useRef,
80
- useCallback: import_hooks.useCallback,
81
- useReducer: import_hooks.useReducer,
82
- useId: import_hooks.useId,
83
- useDebugValue: import_hooks.useDebugValue,
84
- use: import_hooks.use,
85
- startTransition: import_hooks.startTransition,
86
- useTransition: import_hooks.useTransition,
87
- useDeferredValue: import_hooks.useDeferredValue,
88
- startViewTransition: import_hooks.startViewTransition,
89
- useViewTransition: import_hooks.useViewTransition,
90
- useMemo: import_hooks.useMemo,
91
- useLayoutEffect: import_hooks.useLayoutEffect,
92
- useInsertionEffect: import_hooks.useInsertionEffect,
93
- createRef: import_hooks.createRef,
94
- forwardRef: import_hooks.forwardRef,
95
- useImperativeHandle: import_hooks.useImperativeHandle,
96
- useSyncExternalStore: import_hooks.useSyncExternalStore,
97
- useActionState: import_hooks2.useActionState,
98
- useOptimistic: import_hooks2.useOptimistic,
77
+ useState: import_hooks2.useState,
78
+ useEffect: import_hooks2.useEffect,
79
+ useRef: import_hooks2.useRef,
80
+ useCallback: import_hooks2.useCallback,
81
+ useReducer: import_hooks2.useReducer,
82
+ useId: import_hooks2.useId,
83
+ useDebugValue: import_hooks2.useDebugValue,
84
+ use: import_hooks2.use,
85
+ startTransition: import_hooks2.startTransition,
86
+ useTransition: import_hooks2.useTransition,
87
+ useDeferredValue: import_hooks2.useDeferredValue,
88
+ startViewTransition: import_hooks2.startViewTransition,
89
+ useViewTransition: import_hooks2.useViewTransition,
90
+ useMemo: import_hooks2.useMemo,
91
+ useLayoutEffect: import_hooks2.useLayoutEffect,
92
+ useInsertionEffect: import_hooks2.useInsertionEffect,
93
+ createRef: import_hooks2.createRef,
94
+ forwardRef: import_hooks2.forwardRef,
95
+ useImperativeHandle: import_hooks2.useImperativeHandle,
96
+ useSyncExternalStore: import_hooks2.useSyncExternalStore,
97
+ useActionState: import_hooks.useActionState,
98
+ useOptimistic: import_hooks.useOptimistic,
99
99
  Suspense: import_streaming.Suspense,
100
100
  Children: import_children.Children
101
101
  };
@@ -28,12 +28,12 @@ __export(components_exports, {
28
28
  title: () => title
29
29
  });
30
30
  module.exports = __toCommonJS(components_exports);
31
+ var import_html = require("../../helper/html");
31
32
  var import_base = require("../base");
33
+ var import_children = require("../children");
34
+ var import_constants = require("../constants");
32
35
  var import_context = require("../context");
33
- var import_html = require("../../helper/html");
34
36
  var import_common = require("./common");
35
- var import_constants = require("../constants");
36
- var import_children = require("../children");
37
37
  const metaTagMap = /* @__PURE__ */ new WeakMap();
38
38
  const insertIntoHead = (tagName, tag, props, precedence) => ({ buffer, context }) => {
39
39
  if (!buffer) {
@@ -23,9 +23,9 @@ __export(combine_exports, {
23
23
  some: () => some
24
24
  });
25
25
  module.exports = __toCommonJS(combine_exports);
26
- var import_trie_router = require("../../router/trie-router");
27
- var import_router = require("../../router");
28
26
  var import_compose = require("../../compose");
27
+ var import_router = require("../../router");
28
+ var import_trie_router = require("../../router/trie-router");
29
29
  const some = (...middleware) => {
30
30
  return async function some2(c, next) {
31
31
  let lastError;
@@ -21,9 +21,9 @@ __export(compress_exports, {
21
21
  compress: () => compress
22
22
  });
23
23
  module.exports = __toCommonJS(compress_exports);
24
+ var import_compress = require("../../utils/compress");
24
25
  const ENCODING_TYPES = ["gzip", "deflate"];
25
26
  const cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/i;
26
- const compressibleContentTypeRegExp = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
27
27
  const compress = (options) => {
28
28
  const threshold = options?.threshold ?? 1024;
29
29
  return async function compress2(ctx, next) {
@@ -45,7 +45,7 @@ const compress = (options) => {
45
45
  };
46
46
  const shouldCompress = (res) => {
47
47
  const type = res.headers.get("Content-Type");
48
- return type && compressibleContentTypeRegExp.test(type);
48
+ return type && import_compress.COMPRESSIBLE_CONTENT_TYPE_REGEX.test(type);
49
49
  };
50
50
  const shouldTransform = (res) => {
51
51
  const cacheControl = res.headers.get("Cache-Control");
@@ -21,6 +21,7 @@ __export(serve_static_exports, {
21
21
  serveStatic: () => serveStatic
22
22
  });
23
23
  module.exports = __toCommonJS(serve_static_exports);
24
+ var import_compress = require("../../utils/compress");
24
25
  var import_filepath = require("../../utils/filepath");
25
26
  var import_mime = require("../../utils/mime");
26
27
  const ENCODINGS = {
@@ -28,6 +29,7 @@ const ENCODINGS = {
28
29
  zstd: ".zst",
29
30
  gzip: ".gz"
30
31
  };
32
+ const ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
31
33
  const DEFAULT_DOCUMENT = "index.html";
32
34
  const defaultPathResolve = (path) => path;
33
35
  const serveStatic = (options) => {
@@ -79,18 +81,17 @@ const serveStatic = (options) => {
79
81
  if (content instanceof Response) {
80
82
  return c.newResponse(content.body, content);
81
83
  }
82
- const mimeType = options.mimes ? (0, import_mime.getMimeType)(path, options.mimes) ?? (0, import_mime.getMimeType)(path) : (0, import_mime.getMimeType)(path);
83
- if (mimeType) {
84
- c.header("Content-Type", mimeType);
85
- }
86
84
  if (content) {
87
- if (options.precompressed) {
88
- const acceptEncodings = c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim()).filter(
89
- (encoding) => Object.hasOwn(ENCODINGS, encoding)
90
- ).sort(
91
- (a, b) => Object.keys(ENCODINGS).indexOf(a) - Object.keys(ENCODINGS).indexOf(b)
92
- ) ?? [];
93
- for (const encoding of acceptEncodings) {
85
+ const mimeType = options.mimes && (0, import_mime.getMimeType)(path, options.mimes) || (0, import_mime.getMimeType)(path);
86
+ c.header("Content-Type", mimeType || "application/octet-stream");
87
+ if (options.precompressed && (!mimeType || import_compress.COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
88
+ const acceptEncodingSet = new Set(
89
+ c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim())
90
+ );
91
+ for (const encoding of ENCODINGS_ORDERED_KEYS) {
92
+ if (!acceptEncodingSet.has(encoding)) {
93
+ continue;
94
+ }
94
95
  const compressedContent = await getContent(path + ENCODINGS[encoding], c);
95
96
  if (compressedContent) {
96
97
  content = compressedContent;
@@ -43,7 +43,7 @@ class PatternRouter {
43
43
  let re;
44
44
  try {
45
45
  re = new RegExp(`^${parts.join("")}${endsWithWildcard ? "" : "/?$"}`);
46
- } catch (e) {
46
+ } catch {
47
47
  throw new import_router.UnsupportedPathError();
48
48
  }
49
49
  this.routes.push([re, method, handler]);
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var compress_exports = {};
20
+ __export(compress_exports, {
21
+ COMPRESSIBLE_CONTENT_TYPE_REGEX: () => COMPRESSIBLE_CONTENT_TYPE_REGEX
22
+ });
23
+ module.exports = __toCommonJS(compress_exports);
24
+ const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
25
+ // Annotate the CommonJS export names for ESM import in node:
26
+ 0 && (module.exports = {
27
+ COMPRESSIBLE_CONTENT_TYPE_REGEX
28
+ });
@@ -43,7 +43,7 @@ const verifySignature = async (base64Signature, value, secret) => {
43
43
  signature[i] = signatureBinStr.charCodeAt(i);
44
44
  }
45
45
  return await crypto.subtle.verify(algorithm, secret, signature, new TextEncoder().encode(value));
46
- } catch (e) {
46
+ } catch {
47
47
  return false;
48
48
  }
49
49
  };
@@ -87,7 +87,7 @@ const decode = (token) => {
87
87
  header,
88
88
  payload
89
89
  };
90
- } catch (e) {
90
+ } catch {
91
91
  throw new import_types.JwtTokenInvalid(token);
92
92
  }
93
93
  };
@@ -53,7 +53,7 @@ class StreamingApi {
53
53
  input = this.encoder.encode(input);
54
54
  }
55
55
  await this.writer.write(input);
56
- } catch (e) {
56
+ } catch {
57
57
  }
58
58
  return this;
59
59
  }
@@ -67,7 +67,7 @@ class StreamingApi {
67
67
  async close() {
68
68
  try {
69
69
  await this.writer.close();
70
- } catch (e) {
70
+ } catch {
71
71
  }
72
72
  this.closed = true;
73
73
  }
@@ -7,7 +7,7 @@ var SSG_DISABLED_RESPONSE = (() => {
7
7
  status: 404,
8
8
  headers: { [X_HONO_DISABLE_SSG_HEADER_KEY]: "true" }
9
9
  });
10
- } catch (e) {
10
+ } catch {
11
11
  return null;
12
12
  }
13
13
  })();
@@ -1,6 +1,6 @@
1
1
  // src/helper/streaming/sse.ts
2
- import { StreamingApi } from "../../utils/stream.js";
3
2
  import { HtmlEscapedCallbackPhase, resolveCallback } from "../../utils/html.js";
3
+ import { StreamingApi } from "../../utils/stream.js";
4
4
  var SSEStreamingApi = class extends StreamingApi {
5
5
  constructor(writable, readable) {
6
6
  super(writable, readable);
@@ -1,6 +1,6 @@
1
1
  // src/helper/streaming/text.ts
2
2
  import { TEXT_PLAIN } from "../../context.js";
3
- import { stream } from ".//index.js";
3
+ import { stream } from "./index.js";
4
4
  var streamText = (c, cb, onError) => {
5
5
  c.header("Content-Type", TEXT_PLAIN);
6
6
  c.header("X-Content-Type-Options", "nosniff");
package/dist/jsx/base.js CHANGED
@@ -1,11 +1,11 @@
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 { createContext, globalContexts, useContext } from "./context.js";
5
4
  import { DOM_RENDERER } from "./constants.js";
6
- import { normalizeIntrinsicElementKey, styleObjectForEach } from "./utils.js";
7
- import * as intrinsicElementTags from "./intrinsic-element/components.js";
5
+ import { createContext, globalContexts, useContext } from "./context.js";
8
6
  import { domRenderers } from "./intrinsic-element/common.js";
7
+ import * as intrinsicElementTags from "./intrinsic-element/components.js";
8
+ import { normalizeIntrinsicElementKey, styleObjectForEach } from "./utils.js";
9
9
  var nameSpaceContext = void 0;
10
10
  var getNameSpaceContext = () => nameSpaceContext;
11
11
  var toSVGAttributeName = (key) => /[A-Z]/.test(key) && key.match(
@@ -1,8 +1,8 @@
1
1
  // src/jsx/dom/hooks/index.ts
2
+ import { PERMALINK } from "../../constants.js";
2
3
  import { useContext } from "../../context.js";
3
- import { createContext } from "../context.js";
4
4
  import { useCallback, useState } from "../../hooks/index.js";
5
- import { PERMALINK } from "../../constants.js";
5
+ import { createContext } from "../context.js";
6
6
  var FormContext = createContext({
7
7
  pending: false,
8
8
  data: null,
@@ -24,9 +24,9 @@ import {
24
24
  useTransition,
25
25
  useViewTransition
26
26
  } from "../hooks/index.js";
27
- import { useActionState, useFormStatus, useOptimistic } from "./hooks/index.js";
28
27
  import { ErrorBoundary, Suspense } from "./components.js";
29
28
  import { createContext } from "./context.js";
29
+ import { useActionState, useFormStatus, useOptimistic } from "./hooks/index.js";
30
30
  import { Fragment, jsx } from "./jsx-runtime.js";
31
31
  import { createPortal, flushSync } from "./render.js";
32
32
  import { render } from "./render.js";
@@ -1,9 +1,9 @@
1
1
  // src/jsx/dom/intrinsic-element/components.ts
2
- import { createPortal, getNameSpaceContext } from "../render.js";
3
2
  import { useContext } from "../../context.js";
4
3
  import { use, useCallback, useMemo, useState } from "../../hooks/index.js";
5
- import { FormContext, registerAction } from "../hooks/index.js";
6
4
  import { dataPrecedenceAttr, deDupeKeyMap, domRenderers } from "../../intrinsic-element/common.js";
5
+ import { FormContext, registerAction } from "../hooks/index.js";
6
+ import { createPortal, getNameSpaceContext } from "../render.js";
7
7
  var clearCache = () => {
8
8
  blockingPromiseMap = /* @__PURE__ */ Object.create(null);
9
9
  createdElements = /* @__PURE__ */ Object.create(null);
@@ -479,7 +479,7 @@ var updateSync = (context, node) => {
479
479
  });
480
480
  try {
481
481
  build(context, node, void 0);
482
- } catch (e) {
482
+ } catch {
483
483
  return;
484
484
  }
485
485
  if (node.a) {
@@ -1,6 +1,6 @@
1
1
  // src/jsx/dom/server.ts
2
2
  import { renderToReadableStream as renderToReadableStreamHono } from "../streaming.js";
3
- import version from ".//index.js";
3
+ import version from "./index.js";
4
4
  var renderToString = (element, options = {}) => {
5
5
  if (Object.keys(options).length > 0) {
6
6
  console.warn("options are not supported yet");
package/dist/jsx/index.js CHANGED
@@ -3,6 +3,7 @@ import { Fragment, cloneElement, isValidElement, jsx, memo, reactAPICompatVersio
3
3
  import { Children } from "./children.js";
4
4
  import { ErrorBoundary } from "./components.js";
5
5
  import { createContext, useContext } from "./context.js";
6
+ import { useActionState, useOptimistic } from "./dom/hooks/index.js";
6
7
  import {
7
8
  createRef,
8
9
  forwardRef,
@@ -25,7 +26,6 @@ import {
25
26
  useTransition,
26
27
  useViewTransition
27
28
  } from "./hooks/index.js";
28
- import { useActionState, useOptimistic } from "./dom/hooks/index.js";
29
29
  import { Suspense } from "./streaming.js";
30
30
  var jsx_default = {
31
31
  version: reactAPICompatVersion,
@@ -1,10 +1,10 @@
1
1
  // src/jsx/intrinsic-element/components.ts
2
+ import { raw } from "../../helper/html/index.js";
2
3
  import { JSXNode, getNameSpaceContext } from "../base.js";
4
+ import { toArray } from "../children.js";
5
+ import { PERMALINK } from "../constants.js";
3
6
  import { useContext } from "../context.js";
4
- import { raw } from "../../helper/html/index.js";
5
7
  import { dataPrecedenceAttr, deDupeKeyMap } from "./common.js";
6
- import { PERMALINK } from "../constants.js";
7
- import { toArray } from "../children.js";
8
8
  var metaTagMap = /* @__PURE__ */ new WeakMap();
9
9
  var insertIntoHead = (tagName, tag, props, precedence) => ({ buffer, context }) => {
10
10
  if (!buffer) {
@@ -1,7 +1,7 @@
1
1
  // src/middleware/combine/index.ts
2
- import { TrieRouter } from "../../router/trie-router/index.js";
3
- import { METHOD_NAME_ALL } from "../../router.js";
4
2
  import { compose } from "../../compose.js";
3
+ import { METHOD_NAME_ALL } from "../../router.js";
4
+ import { TrieRouter } from "../../router/trie-router/index.js";
5
5
  var some = (...middleware) => {
6
6
  return async function some2(c, next) {
7
7
  let lastError;
@@ -1,7 +1,7 @@
1
1
  // src/middleware/compress/index.ts
2
+ import { COMPRESSIBLE_CONTENT_TYPE_REGEX } from "../../utils/compress.js";
2
3
  var ENCODING_TYPES = ["gzip", "deflate"];
3
4
  var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/i;
4
- var compressibleContentTypeRegExp = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
5
5
  var compress = (options) => {
6
6
  const threshold = options?.threshold ?? 1024;
7
7
  return async function compress2(ctx, next) {
@@ -23,7 +23,7 @@ var compress = (options) => {
23
23
  };
24
24
  var shouldCompress = (res) => {
25
25
  const type = res.headers.get("Content-Type");
26
- return type && compressibleContentTypeRegExp.test(type);
26
+ return type && COMPRESSIBLE_CONTENT_TYPE_REGEX.test(type);
27
27
  };
28
28
  var shouldTransform = (res) => {
29
29
  const cacheControl = res.headers.get("Cache-Control");
@@ -1,4 +1,5 @@
1
1
  // src/middleware/serve-static/index.ts
2
+ import { COMPRESSIBLE_CONTENT_TYPE_REGEX } from "../../utils/compress.js";
2
3
  import { getFilePath, getFilePathWithoutDefaultDocument } from "../../utils/filepath.js";
3
4
  import { getMimeType } from "../../utils/mime.js";
4
5
  var ENCODINGS = {
@@ -6,6 +7,7 @@ var ENCODINGS = {
6
7
  zstd: ".zst",
7
8
  gzip: ".gz"
8
9
  };
10
+ var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
9
11
  var DEFAULT_DOCUMENT = "index.html";
10
12
  var defaultPathResolve = (path) => path;
11
13
  var serveStatic = (options) => {
@@ -57,18 +59,17 @@ var serveStatic = (options) => {
57
59
  if (content instanceof Response) {
58
60
  return c.newResponse(content.body, content);
59
61
  }
60
- const mimeType = options.mimes ? getMimeType(path, options.mimes) ?? getMimeType(path) : getMimeType(path);
61
- if (mimeType) {
62
- c.header("Content-Type", mimeType);
63
- }
64
62
  if (content) {
65
- if (options.precompressed) {
66
- const acceptEncodings = c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim()).filter(
67
- (encoding) => Object.hasOwn(ENCODINGS, encoding)
68
- ).sort(
69
- (a, b) => Object.keys(ENCODINGS).indexOf(a) - Object.keys(ENCODINGS).indexOf(b)
70
- ) ?? [];
71
- for (const encoding of acceptEncodings) {
63
+ const mimeType = options.mimes && getMimeType(path, options.mimes) || getMimeType(path);
64
+ c.header("Content-Type", mimeType || "application/octet-stream");
65
+ if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
66
+ const acceptEncodingSet = new Set(
67
+ c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim())
68
+ );
69
+ for (const encoding of ENCODINGS_ORDERED_KEYS) {
70
+ if (!acceptEncodingSet.has(encoding)) {
71
+ continue;
72
+ }
72
73
  const compressedContent = await getContent(path + ENCODINGS[encoding], c);
73
74
  if (compressedContent) {
74
75
  content = compressedContent;
@@ -21,7 +21,7 @@ var PatternRouter = class {
21
21
  let re;
22
22
  try {
23
23
  re = new RegExp(`^${parts.join("")}${endsWithWildcard ? "" : "/?$"}`);
24
- } catch (e) {
24
+ } catch {
25
25
  throw new UnsupportedPathError();
26
26
  }
27
27
  this.routes.push([re, method, handler]);
@@ -2,8 +2,8 @@ import { HonoRequest } from './request';
2
2
  import type { Result } from './router';
3
3
  import type { Env, FetchEventLike, H, Input, NotFoundHandler, RouterRoute, TypedResponse } from './types';
4
4
  import type { RedirectStatusCode, StatusCode } from './utils/http-status';
5
- import type { InvalidJSONValue, IsAny, JSONParsed, JSONValue, SimplifyDeepArray } from './utils/types';
6
5
  import type { BaseMime } from './utils/mime';
6
+ import type { InvalidJSONValue, IsAny, JSONParsed, JSONValue, SimplifyDeepArray } from './utils/types';
7
7
  type HeaderRecord = Record<'Content-Type', BaseMime> | Record<ResponseHeader, string | string[]> | Record<string, string | string[]>;
8
8
  /**
9
9
  * Data type can be a string, ArrayBuffer, or ReadableStream.
@@ -7,9 +7,9 @@ import type { Child, DOMAttributes, JSX, JSXNode, Props } from '../base';
7
7
  import { Children } from '../children';
8
8
  import { useContext } from '../context';
9
9
  import { createRef, forwardRef, startTransition, startViewTransition, use, useCallback, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore, useTransition, useViewTransition } from '../hooks';
10
- import { useActionState, useFormStatus, useOptimistic } from './hooks';
11
10
  import { ErrorBoundary, Suspense } from './components';
12
11
  import { createContext } from './context';
12
+ import { useActionState, useFormStatus, useOptimistic } from './hooks';
13
13
  import { Fragment } from './jsx-runtime';
14
14
  import { createPortal, flushSync } from './render';
15
15
  export { render } from './render';
@@ -1,5 +1,5 @@
1
- import type { FC, PropsWithChildren, RefObject } from '../../types';
2
1
  import type { IntrinsicElements } from '../../intrinsic-elements';
2
+ import type { FC, PropsWithChildren, RefObject } from '../../types';
3
3
  export declare const clearCache: () => void;
4
4
  export declare const composeRef: <T>(ref: Function | RefObject<T> | undefined, cb: (e: T) => void | (() => void)) => (e: T) => () => void;
5
5
  export declare const title: FC<PropsWithChildren>;
@@ -7,8 +7,8 @@ import type { DOMAttributes } from './base';
7
7
  import { Children } from './children';
8
8
  import { ErrorBoundary } from './components';
9
9
  import { createContext, useContext } from './context';
10
- import { createRef, forwardRef, startTransition, startViewTransition, use, useCallback, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore, useTransition, useViewTransition } from './hooks';
11
10
  import { useActionState, useOptimistic } from './dom/hooks';
11
+ import { createRef, forwardRef, startTransition, startViewTransition, use, useCallback, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore, useTransition, useViewTransition } from './hooks';
12
12
  import { Suspense } from './streaming';
13
13
  export { reactAPICompatVersion as version, jsx, memo, Fragment, Fragment as StrictMode, isValidElement, jsx as createElement, cloneElement, ErrorBoundary, createContext, useContext, useState, useEffect, useRef, useCallback, useReducer, useId, useDebugValue, use, startTransition, useTransition, useDeferredValue, startViewTransition, useViewTransition, useMemo, useLayoutEffect, useInsertionEffect, createRef, forwardRef, useImperativeHandle, useSyncExternalStore, useActionState, useOptimistic, Suspense, Children, DOMAttributes, };
14
14
  declare const _default: {
@@ -1,5 +1,5 @@
1
- import type { FC, PropsWithChildren } from '../types';
2
1
  import type { IntrinsicElements } from '../intrinsic-elements';
2
+ import type { FC, PropsWithChildren } from '../types';
3
3
  export declare const title: FC<PropsWithChildren>;
4
4
  export declare const script: FC<PropsWithChildren<IntrinsicElements['script']>>;
5
5
  export declare const style: FC<PropsWithChildren<IntrinsicElements['style']>>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @module
3
+ * Constants for compression.
4
+ */
5
+ /**
6
+ * Match for compressible content type.
7
+ */
8
+ export declare const COMPRESSIBLE_CONTENT_TYPE_REGEX: RegExp;
@@ -0,0 +1,5 @@
1
+ // src/utils/compress.ts
2
+ var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
3
+ export {
4
+ COMPRESSIBLE_CONTENT_TYPE_REGEX
5
+ };
@@ -18,7 +18,7 @@ var verifySignature = async (base64Signature, value, secret) => {
18
18
  signature[i] = signatureBinStr.charCodeAt(i);
19
19
  }
20
20
  return await crypto.subtle.verify(algorithm, secret, signature, new TextEncoder().encode(value));
21
- } catch (e) {
21
+ } catch {
22
22
  return false;
23
23
  }
24
24
  };
@@ -69,7 +69,7 @@ var decode = (token) => {
69
69
  header,
70
70
  payload
71
71
  };
72
- } catch (e) {
72
+ } catch {
73
73
  throw new JwtTokenInvalid(token);
74
74
  }
75
75
  };
@@ -31,7 +31,7 @@ var StreamingApi = class {
31
31
  input = this.encoder.encode(input);
32
32
  }
33
33
  await this.writer.write(input);
34
- } catch (e) {
34
+ } catch {
35
35
  }
36
36
  return this;
37
37
  }
@@ -45,7 +45,7 @@ var StreamingApi = class {
45
45
  async close() {
46
46
  try {
47
47
  await this.writer.close();
48
- } catch (e) {
48
+ } catch {
49
49
  }
50
50
  this.closed = true;
51
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.6.0",
3
+ "version": "4.6.2",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",
@@ -20,8 +20,8 @@
20
20
  "test:lambda": "vitest --run --config ./runtime_tests/lambda/vitest.config.ts",
21
21
  "test:lambda-edge": "vitest --run --config ./runtime_tests/lambda-edge/vitest.config.ts",
22
22
  "test:all": "bun run test && bun test:deno && bun test:bun && bun test:fastly && bun test:node && bun test:workerd && bun test:lambda && bun test:lambda-edge",
23
- "lint": "eslint --ext js,ts,tsx src runtime_tests",
24
- "lint:fix": "eslint --ext js,ts,tsx src runtime_tests --fix",
23
+ "lint": "eslint src runtime_tests",
24
+ "lint:fix": "eslint src runtime_tests --fix",
25
25
  "format": "prettier --check --cache \"src/**/*.{js,ts,tsx}\" \"runtime_tests/**/*.{js,ts,tsx}\"",
26
26
  "format:fix": "prettier --write --cache --cache-strategy metadata \"src/**/*.{js,ts,tsx}\" \"runtime_tests/**/*.{js,ts,tsx}\"",
27
27
  "copy:package.cjs.json": "cp ./package.cjs.json ./dist/cjs/package.json && cp ./package.cjs.json ./dist/types/package.json ",
@@ -618,7 +618,7 @@
618
618
  "nodejs"
619
619
  ],
620
620
  "devDependencies": {
621
- "@hono/eslint-config": "^0.0.6",
621
+ "@hono/eslint-config": "^1.0.1",
622
622
  "@hono/node-server": "^1.8.2",
623
623
  "@types/crypto-js": "^4.1.1",
624
624
  "@types/glob": "^8.0.0",
@@ -629,7 +629,7 @@
629
629
  "arg": "^5.0.2",
630
630
  "crypto-js": "^4.1.1",
631
631
  "esbuild": "^0.15.12",
632
- "eslint": "^8.55.0",
632
+ "eslint": "^9.10.0",
633
633
  "glob": "7.2.3",
634
634
  "jsdom": "^22.1.0",
635
635
  "msw": "^2.3.0",
@@ -645,6 +645,6 @@
645
645
  "zod": "^3.20.2"
646
646
  },
647
647
  "engines": {
648
- "node": ">=16.0.0"
648
+ "node": ">=16.9.0"
649
649
  }
650
650
  }