hono 4.11.5 → 4.11.7

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.
@@ -3,9 +3,11 @@ import { serveStatic } from "./serve-static.js";
3
3
  import { bunFileSystemModule, toSSG } from "./ssg.js";
4
4
  import { createBunWebSocket, upgradeWebSocket, websocket } from "./websocket.js";
5
5
  import { getConnInfo } from "./conninfo.js";
6
+ import { getBunServer } from "./server.js";
6
7
  export {
7
8
  bunFileSystemModule,
8
9
  createBunWebSocket,
10
+ getBunServer,
9
11
  getConnInfo,
10
12
  serveStatic,
11
13
  toSSG,
@@ -20,7 +20,7 @@ var getContentFromKVAsset = async (path, options) => {
20
20
  } else {
21
21
  ASSET_NAMESPACE = __STATIC_CONTENT;
22
22
  }
23
- const key = ASSET_MANIFEST[path] || path;
23
+ const key = ASSET_MANIFEST[path];
24
24
  if (!key) {
25
25
  return null;
26
26
  }
@@ -20,6 +20,7 @@ var bun_exports = {};
20
20
  __export(bun_exports, {
21
21
  bunFileSystemModule: () => import_ssg.bunFileSystemModule,
22
22
  createBunWebSocket: () => import_websocket.createBunWebSocket,
23
+ getBunServer: () => import_server.getBunServer,
23
24
  getConnInfo: () => import_conninfo.getConnInfo,
24
25
  serveStatic: () => import_serve_static.serveStatic,
25
26
  toSSG: () => import_ssg.toSSG,
@@ -31,10 +32,12 @@ var import_serve_static = require("./serve-static");
31
32
  var import_ssg = require("./ssg");
32
33
  var import_websocket = require("./websocket");
33
34
  var import_conninfo = require("./conninfo");
35
+ var import_server = require("./server");
34
36
  // Annotate the CommonJS export names for ESM import in node:
35
37
  0 && (module.exports = {
36
38
  bunFileSystemModule,
37
39
  createBunWebSocket,
40
+ getBunServer,
38
41
  getConnInfo,
39
42
  serveStatic,
40
43
  toSSG,
@@ -42,7 +42,7 @@ const getContentFromKVAsset = async (path, options) => {
42
42
  } else {
43
43
  ASSET_NAMESPACE = __STATIC_CONTENT;
44
44
  }
45
- const key = ASSET_MANIFEST[path] || path;
45
+ const key = ASSET_MANIFEST[path];
46
46
  if (!key) {
47
47
  return null;
48
48
  }
@@ -31,7 +31,7 @@ class SSEStreamingApi extends import_stream.StreamingApi {
31
31
  }
32
32
  async writeSSE(message) {
33
33
  const data = await (0, import_html.resolveCallback)(message.data, import_html.HtmlEscapedCallbackPhase.Stringify, false, {});
34
- const dataLines = data.split("\n").map((line) => {
34
+ const dataLines = data.split(/\r\n|\r|\n/).map((line) => {
35
35
  return `data: ${line}`;
36
36
  }).join("\n");
37
37
  const sseData = [
@@ -24,6 +24,7 @@ __export(components_exports, {
24
24
  module.exports = __toCommonJS(components_exports);
25
25
  var import_html = require("../helper/html");
26
26
  var import_html2 = require("../utils/html");
27
+ var import_base = require("./base");
27
28
  var import_constants = require("./constants");
28
29
  var import_context = require("./context");
29
30
  var import_components = require("./dom/components");
@@ -41,6 +42,20 @@ const childrenToString = async (children) => {
41
42
  }
42
43
  }
43
44
  };
45
+ const resolveChildEarly = (c) => {
46
+ if (c == null || typeof c === "boolean") {
47
+ return "";
48
+ } else if (typeof c === "string") {
49
+ return c;
50
+ } else {
51
+ const str = c.toString();
52
+ if (!(str instanceof Promise)) {
53
+ return (0, import_html.raw)(str);
54
+ } else {
55
+ return str;
56
+ }
57
+ }
58
+ };
44
59
  const ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) => {
45
60
  if (!children) {
46
61
  return (0, import_html.raw)("");
@@ -50,17 +65,26 @@ const ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) =>
50
65
  }
51
66
  const nonce = (0, import_context.useContext)(import_streaming.StreamingContext)?.scriptNonce;
52
67
  let fallbackStr;
68
+ const resolveFallbackStr = async () => {
69
+ const awaitedFallback = await fallback;
70
+ if (typeof awaitedFallback === "string") {
71
+ fallbackStr = awaitedFallback;
72
+ } else {
73
+ fallbackStr = await awaitedFallback?.toString();
74
+ if (typeof fallbackStr === "string") {
75
+ fallbackStr = (0, import_html.raw)(fallbackStr);
76
+ }
77
+ }
78
+ };
53
79
  const fallbackRes = (error) => {
54
80
  onError?.(error);
55
- return (fallbackStr || fallbackRender?.(error) || "").toString();
81
+ return fallbackStr || fallbackRender && (0, import_base.jsx)(import_base.Fragment, {}, fallbackRender(error)) || "";
56
82
  };
57
83
  let resArray = [];
58
84
  try {
59
- resArray = children.map(
60
- (c) => c == null || typeof c === "boolean" ? "" : c.toString()
61
- );
85
+ resArray = children.map(resolveChildEarly);
62
86
  } catch (e) {
63
- fallbackStr = await fallback?.toString();
87
+ await resolveFallbackStr();
64
88
  if (e instanceof Promise) {
65
89
  resArray = [
66
90
  e.then(() => childrenToString(children)).catch((e2) => fallbackRes(e2))
@@ -70,15 +94,17 @@ const ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) =>
70
94
  }
71
95
  }
72
96
  if (resArray.some((res) => res instanceof Promise)) {
73
- fallbackStr ||= await fallback?.toString();
97
+ await resolveFallbackStr();
74
98
  const index = errorBoundaryCounter++;
75
99
  const replaceRe = RegExp(`(<template id="E:${index}"></template>.*?)(.*?)(<!--E:${index}-->)`);
76
100
  const caught = false;
77
- const catchCallback = ({ error: error2, buffer }) => {
101
+ const catchCallback = async ({ error: error2, buffer }) => {
78
102
  if (caught) {
79
103
  return "";
80
104
  }
81
- const fallbackResString = fallbackRes(error2);
105
+ const fallbackResString = await (0, import_base.Fragment)({
106
+ children: fallbackRes(error2)
107
+ }).toString();
82
108
  if (buffer) {
83
109
  buffer[0] = buffer[0].replace(replaceRe, fallbackResString);
84
110
  }
@@ -165,7 +191,7 @@ d.remove()
165
191
  }
166
192
  ]);
167
193
  } else {
168
- return (0, import_html.raw)(resArray.join(""));
194
+ return (0, import_base.Fragment)({ children: resArray });
169
195
  }
170
196
  };
171
197
  ErrorBoundary[import_constants.DOM_RENDERER] = import_components.ErrorBoundary;
@@ -24,7 +24,17 @@ module.exports = __toCommonJS(cache_exports);
24
24
  const defaultCacheableStatusCodes = [200];
25
25
  const shouldSkipCache = (res) => {
26
26
  const vary = res.headers.get("Vary");
27
- return vary && vary.includes("*");
27
+ if (vary && vary.includes("*")) {
28
+ return true;
29
+ }
30
+ const cacheControl = res.headers.get("Cache-Control");
31
+ if (cacheControl && /(?:^|,\s*)(?:private|no-(?:store|cache))(?:\s*(?:=|,|$))/i.test(cacheControl)) {
32
+ return true;
33
+ }
34
+ if (res.headers.has("Set-Cookie")) {
35
+ return true;
36
+ }
37
+ return false;
28
38
  };
29
39
  const cache = (options) => {
30
40
  if (!globalThis.caches) {
@@ -47,7 +47,8 @@ const expandIPv6 = (ipV6) => {
47
47
  }
48
48
  return sections.join(":");
49
49
  };
50
- const IPV4_REGEX = /^[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}$/;
50
+ const IPV4_OCTET_PART = "(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])";
51
+ const IPV4_REGEX = new RegExp(`^(?:${IPV4_OCTET_PART}\\.){3}${IPV4_OCTET_PART}$`);
51
52
  const distinctRemoteAddr = (remoteAddr) => {
52
53
  if (IPV4_REGEX.test(remoteAddr)) {
53
54
  return "IPv4";
@@ -8,7 +8,7 @@ var SSEStreamingApi = class extends StreamingApi {
8
8
  }
9
9
  async writeSSE(message) {
10
10
  const data = await resolveCallback(message.data, HtmlEscapedCallbackPhase.Stringify, false, {});
11
- const dataLines = data.split("\n").map((line) => {
11
+ const dataLines = data.split(/\r\n|\r|\n/).map((line) => {
12
12
  return `data: ${line}`;
13
13
  }).join("\n");
14
14
  const sseData = [
@@ -1,6 +1,7 @@
1
1
  // src/jsx/components.ts
2
2
  import { raw } from "../helper/html/index.js";
3
3
  import { HtmlEscapedCallbackPhase, resolveCallback } from "../utils/html.js";
4
+ import { jsx, Fragment } from "./base.js";
4
5
  import { DOM_RENDERER } from "./constants.js";
5
6
  import { useContext } from "./context.js";
6
7
  import { ErrorBoundary as ErrorBoundaryDomRenderer } from "./dom/components.js";
@@ -18,6 +19,20 @@ var childrenToString = async (children) => {
18
19
  }
19
20
  }
20
21
  };
22
+ var resolveChildEarly = (c) => {
23
+ if (c == null || typeof c === "boolean") {
24
+ return "";
25
+ } else if (typeof c === "string") {
26
+ return c;
27
+ } else {
28
+ const str = c.toString();
29
+ if (!(str instanceof Promise)) {
30
+ return raw(str);
31
+ } else {
32
+ return str;
33
+ }
34
+ }
35
+ };
21
36
  var ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) => {
22
37
  if (!children) {
23
38
  return raw("");
@@ -27,17 +42,26 @@ var ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) => {
27
42
  }
28
43
  const nonce = useContext(StreamingContext)?.scriptNonce;
29
44
  let fallbackStr;
45
+ const resolveFallbackStr = async () => {
46
+ const awaitedFallback = await fallback;
47
+ if (typeof awaitedFallback === "string") {
48
+ fallbackStr = awaitedFallback;
49
+ } else {
50
+ fallbackStr = await awaitedFallback?.toString();
51
+ if (typeof fallbackStr === "string") {
52
+ fallbackStr = raw(fallbackStr);
53
+ }
54
+ }
55
+ };
30
56
  const fallbackRes = (error) => {
31
57
  onError?.(error);
32
- return (fallbackStr || fallbackRender?.(error) || "").toString();
58
+ return fallbackStr || fallbackRender && jsx(Fragment, {}, fallbackRender(error)) || "";
33
59
  };
34
60
  let resArray = [];
35
61
  try {
36
- resArray = children.map(
37
- (c) => c == null || typeof c === "boolean" ? "" : c.toString()
38
- );
62
+ resArray = children.map(resolveChildEarly);
39
63
  } catch (e) {
40
- fallbackStr = await fallback?.toString();
64
+ await resolveFallbackStr();
41
65
  if (e instanceof Promise) {
42
66
  resArray = [
43
67
  e.then(() => childrenToString(children)).catch((e2) => fallbackRes(e2))
@@ -47,15 +71,17 @@ var ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) => {
47
71
  }
48
72
  }
49
73
  if (resArray.some((res) => res instanceof Promise)) {
50
- fallbackStr ||= await fallback?.toString();
74
+ await resolveFallbackStr();
51
75
  const index = errorBoundaryCounter++;
52
76
  const replaceRe = RegExp(`(<template id="E:${index}"></template>.*?)(.*?)(<!--E:${index}-->)`);
53
77
  const caught = false;
54
- const catchCallback = ({ error: error2, buffer }) => {
78
+ const catchCallback = async ({ error: error2, buffer }) => {
55
79
  if (caught) {
56
80
  return "";
57
81
  }
58
- const fallbackResString = fallbackRes(error2);
82
+ const fallbackResString = await Fragment({
83
+ children: fallbackRes(error2)
84
+ }).toString();
59
85
  if (buffer) {
60
86
  buffer[0] = buffer[0].replace(replaceRe, fallbackResString);
61
87
  }
@@ -142,7 +168,7 @@ d.remove()
142
168
  }
143
169
  ]);
144
170
  } else {
145
- return raw(resArray.join(""));
171
+ return Fragment({ children: resArray });
146
172
  }
147
173
  };
148
174
  ErrorBoundary[DOM_RENDERER] = ErrorBoundaryDomRenderer;
@@ -2,7 +2,17 @@
2
2
  var defaultCacheableStatusCodes = [200];
3
3
  var shouldSkipCache = (res) => {
4
4
  const vary = res.headers.get("Vary");
5
- return vary && vary.includes("*");
5
+ if (vary && vary.includes("*")) {
6
+ return true;
7
+ }
8
+ const cacheControl = res.headers.get("Cache-Control");
9
+ if (cacheControl && /(?:^|,\s*)(?:private|no-(?:store|cache))(?:\s*(?:=|,|$))/i.test(cacheControl)) {
10
+ return true;
11
+ }
12
+ if (res.headers.has("Set-Cookie")) {
13
+ return true;
14
+ }
15
+ return false;
6
16
  };
7
17
  var cache = (options) => {
8
18
  if (!globalThis.caches) {
@@ -7,3 +7,4 @@ export { bunFileSystemModule, toSSG } from './ssg';
7
7
  export { createBunWebSocket, upgradeWebSocket, websocket } from './websocket';
8
8
  export type { BunWebSocketData, BunWebSocketHandler } from './websocket';
9
9
  export { getConnInfo } from './conninfo';
10
+ export { getBunServer } from './server';
@@ -3,22 +3,10 @@
3
3
  * @module
4
4
  */
5
5
  import type { Context } from '../../context';
6
- /**
7
- * Bun Server Object
8
- */
9
- export interface BunServer {
10
- requestIP?: (req: Request) => {
11
- address: string;
12
- family: string;
13
- port: number;
14
- } | null;
15
- upgrade<T>(req: Request, options?: {
16
- data: T;
17
- }): boolean;
18
- }
19
6
  /**
20
7
  * Get Bun Server Object from Context
8
+ * @template T - The type of Bun Server
21
9
  * @param c Context
22
10
  * @returns Bun Server
23
11
  */
24
- export declare const getBunServer: (c: Context) => BunServer | undefined;
12
+ export declare const getBunServer: <T>(c: Context) => T | undefined;
@@ -1 +1 @@
1
- export declare const GET_MATCH_RESULT: symbol;
1
+ export declare const GET_MATCH_RESULT: unique symbol;
@@ -16,7 +16,6 @@ type BodyCache = Partial<Body & {
16
16
  }>;
17
17
  export declare class HonoRequest<P extends string = '/', I extends Input['out'] = {}> {
18
18
 
19
- [GET_MATCH_RESULT]: Result<[unknown, RouterRoute]>;
20
19
  /**
21
20
  * `.raw` can get the raw Request object.
22
21
  *
@@ -232,6 +231,7 @@ export declare class HonoRequest<P extends string = '/', I extends Input['out']
232
231
  * ```
233
232
  */
234
233
  get method(): string;
234
+ get [GET_MATCH_RESULT](): Result<[unknown, RouterRoute]>;
235
235
  /**
236
236
  * `.matchedRoutes()` can return a matched route in the handler
237
237
  *
@@ -20,7 +20,8 @@ var expandIPv6 = (ipV6) => {
20
20
  }
21
21
  return sections.join(":");
22
22
  };
23
- var IPV4_REGEX = /^[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}$/;
23
+ var IPV4_OCTET_PART = "(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])";
24
+ var IPV4_REGEX = new RegExp(`^(?:${IPV4_OCTET_PART}\\.){3}${IPV4_OCTET_PART}$`);
24
25
  var distinctRemoteAddr = (remoteAddr) => {
25
26
  if (IPV4_REGEX.test(remoteAddr)) {
26
27
  return "IPv4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.11.5",
3
+ "version": "4.11.7",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",