hono 4.3.11 → 4.4.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 (188) hide show
  1. package/README.md +2 -3
  2. package/dist/adapter/aws-lambda/handler.js +12 -9
  3. package/dist/adapter/bun/conninfo.js +21 -0
  4. package/dist/adapter/bun/index.js +2 -0
  5. package/dist/adapter/bun/websocket.js +1 -3
  6. package/dist/adapter/cloudflare-workers/conninfo.js +10 -0
  7. package/dist/adapter/cloudflare-workers/websocket.js +2 -6
  8. package/dist/adapter/deno/conninfo.js +15 -0
  9. package/dist/adapter/deno/index.js +2 -0
  10. package/dist/adapter/lambda-edge/handler.js +3 -3
  11. package/dist/cjs/adapter/aws-lambda/handler.js +12 -9
  12. package/dist/cjs/adapter/bun/conninfo.js +44 -0
  13. package/dist/cjs/adapter/bun/index.js +3 -0
  14. package/dist/cjs/adapter/cloudflare-workers/conninfo.js +33 -0
  15. package/dist/cjs/adapter/cloudflare-workers/websocket.js +2 -6
  16. package/dist/cjs/adapter/deno/conninfo.js +38 -0
  17. package/dist/cjs/adapter/deno/index.js +3 -0
  18. package/dist/cjs/adapter/lambda-edge/handler.js +3 -3
  19. package/dist/cjs/helper/conninfo/index.js +16 -0
  20. package/dist/cjs/helper/ssg/ssg.js +64 -3
  21. package/dist/cjs/helper/streaming/text.js +1 -1
  22. package/dist/cjs/hono-base.js +10 -6
  23. package/dist/cjs/jsx/base.js +5 -2
  24. package/dist/cjs/jsx/dom/client.js +68 -0
  25. package/dist/cjs/jsx/dom/index.js +8 -4
  26. package/dist/cjs/jsx/dom/jsx-dev-runtime.js +6 -20
  27. package/dist/cjs/jsx/dom/render.js +41 -25
  28. package/dist/cjs/jsx/dom/utils.js +15 -0
  29. package/dist/cjs/jsx/hooks/index.js +4 -1
  30. package/dist/cjs/jsx/index.js +8 -4
  31. package/dist/cjs/middleware/jwt/index.js +5 -82
  32. package/dist/cjs/middleware/jwt/jwt.js +111 -0
  33. package/dist/cjs/middleware/secure-headers/index.js +3 -123
  34. package/dist/cjs/middleware/secure-headers/secure-headers.js +150 -0
  35. package/dist/cjs/middleware/timeout/index.js +48 -0
  36. package/dist/cjs/middleware/timing/index.js +5 -89
  37. package/dist/cjs/middleware/timing/timing.js +118 -0
  38. package/dist/cjs/utils/body.js +34 -9
  39. package/dist/cjs/utils/jwt/jws.js +4 -5
  40. package/dist/cjs/utils/jwt/jwt.js +6 -7
  41. package/dist/cjs/utils/url.js +26 -2
  42. package/dist/helper/css/index.js +4 -4
  43. package/dist/helper/html/index.js +1 -1
  44. package/dist/helper/ssg/ssg.js +63 -5
  45. package/dist/helper/streaming/text.js +1 -1
  46. package/dist/hono-base.js +11 -7
  47. package/dist/jsx/base.js +3 -1
  48. package/dist/jsx/dom/client.js +44 -0
  49. package/dist/jsx/dom/css.js +4 -4
  50. package/dist/jsx/dom/index.js +25 -21
  51. package/dist/jsx/dom/jsx-dev-runtime.js +6 -20
  52. package/dist/jsx/dom/render.js +40 -26
  53. package/dist/jsx/dom/utils.js +14 -0
  54. package/dist/jsx/hooks/index.js +4 -2
  55. package/dist/jsx/index.js +22 -18
  56. package/dist/jsx/jsx-runtime.js +1 -1
  57. package/dist/middleware/jsx-renderer/index.js +1 -1
  58. package/dist/middleware/jwt/index.js +1 -78
  59. package/dist/middleware/jwt/jwt.js +85 -0
  60. package/dist/middleware/secure-headers/index.js +1 -121
  61. package/dist/middleware/secure-headers/secure-headers.js +126 -0
  62. package/dist/middleware/timeout/index.js +25 -0
  63. package/dist/middleware/timing/index.js +1 -85
  64. package/dist/middleware/timing/timing.js +92 -0
  65. package/dist/request.js +1 -1
  66. package/dist/router/reg-exp-router/router.js +2 -2
  67. package/dist/router/smart-router/router.js +1 -1
  68. package/dist/router/trie-router/node.js +1 -1
  69. package/dist/types/adapter/aws-lambda/handler.d.ts +3 -3
  70. package/dist/types/adapter/aws-lambda/index.d.ts +4 -0
  71. package/dist/types/adapter/bun/conninfo.d.ts +7 -0
  72. package/dist/types/adapter/bun/index.d.ts +5 -0
  73. package/dist/types/adapter/bun/websocket.d.ts +2 -3
  74. package/dist/types/adapter/cloudflare-pages/index.d.ts +4 -0
  75. package/dist/types/adapter/cloudflare-workers/conninfo.d.ts +2 -0
  76. package/dist/types/adapter/cloudflare-workers/index.d.ts +4 -0
  77. package/dist/types/adapter/cloudflare-workers/serve-static-module.d.ts +2 -2
  78. package/dist/types/adapter/cloudflare-workers/serve-static.d.ts +1 -2
  79. package/dist/types/adapter/cloudflare-workers/utils.d.ts +1 -2
  80. package/dist/types/adapter/deno/conninfo.d.ts +7 -0
  81. package/dist/types/adapter/deno/index.d.ts +5 -0
  82. package/dist/types/adapter/lambda-edge/handler.d.ts +1 -2
  83. package/dist/types/adapter/lambda-edge/index.d.ts +4 -0
  84. package/dist/types/adapter/netlify/handler.d.ts +1 -7
  85. package/dist/types/adapter/netlify/index.d.ts +4 -0
  86. package/dist/types/adapter/netlify/mod.d.ts +0 -1
  87. package/dist/types/adapter/vercel/index.d.ts +4 -0
  88. package/dist/types/client/index.d.ts +4 -0
  89. package/dist/types/compose.d.ts +1 -1
  90. package/dist/types/helper/accepts/index.d.ts +4 -0
  91. package/dist/types/helper/adapter/index.d.ts +4 -0
  92. package/dist/types/helper/conninfo/index.d.ts +40 -0
  93. package/dist/types/helper/cookie/index.d.ts +5 -1
  94. package/dist/types/helper/css/index.d.ts +4 -0
  95. package/dist/types/helper/dev/index.d.ts +4 -0
  96. package/dist/types/helper/factory/index.d.ts +4 -0
  97. package/dist/types/helper/html/index.d.ts +4 -0
  98. package/dist/types/helper/ssg/index.d.ts +4 -0
  99. package/dist/types/helper/ssg/ssg.d.ts +6 -3
  100. package/dist/types/helper/streaming/index.d.ts +4 -0
  101. package/dist/types/helper/testing/index.d.ts +4 -0
  102. package/dist/types/helper/websocket/index.d.ts +4 -0
  103. package/dist/types/hono-base.d.ts +15 -15
  104. package/dist/types/http-exception.d.ts +4 -0
  105. package/dist/types/index.d.ts +15 -0
  106. package/dist/types/jsx/base.d.ts +10 -11
  107. package/dist/types/jsx/components.d.ts +1 -1
  108. package/dist/types/jsx/context.d.ts +1 -1
  109. package/dist/types/jsx/dom/client.d.ts +26 -0
  110. package/dist/types/jsx/dom/components.d.ts +2 -2
  111. package/dist/types/jsx/dom/css.d.ts +31 -20
  112. package/dist/types/jsx/dom/index.d.ts +13 -7
  113. package/dist/types/jsx/dom/jsx-dev-runtime.d.ts +5 -1
  114. package/dist/types/jsx/dom/jsx-runtime.d.ts +4 -0
  115. package/dist/types/jsx/dom/render.d.ts +4 -3
  116. package/dist/types/jsx/dom/utils.d.ts +6 -0
  117. package/dist/types/jsx/hooks/index.d.ts +4 -0
  118. package/dist/types/jsx/index.d.ts +13 -7
  119. package/dist/types/jsx/intrinsic-elements.d.ts +629 -630
  120. package/dist/types/jsx/jsx-dev-runtime.d.ts +5 -0
  121. package/dist/types/jsx/jsx-runtime.d.ts +5 -0
  122. package/dist/types/jsx/streaming.d.ts +5 -1
  123. package/dist/types/jsx/types.d.ts +1 -0
  124. package/dist/types/middleware/basic-auth/index.d.ts +35 -0
  125. package/dist/types/middleware/bearer-auth/index.d.ts +33 -0
  126. package/dist/types/middleware/body-limit/index.d.ts +28 -11
  127. package/dist/types/middleware/cache/index.d.ts +29 -0
  128. package/dist/types/middleware/compress/index.d.ts +20 -0
  129. package/dist/types/middleware/cors/index.d.ts +43 -0
  130. package/dist/types/middleware/csrf/index.d.ts +41 -0
  131. package/dist/types/middleware/etag/index.d.ts +24 -0
  132. package/dist/types/middleware/jsx-renderer/index.d.ts +63 -2
  133. package/dist/types/middleware/jwt/index.d.ts +5 -17
  134. package/dist/types/middleware/jwt/jwt.d.ts +48 -0
  135. package/dist/types/middleware/logger/index.d.ts +20 -0
  136. package/dist/types/middleware/method-override/index.d.ts +22 -10
  137. package/dist/types/middleware/powered-by/index.d.ts +4 -0
  138. package/dist/types/middleware/pretty-json/index.d.ts +23 -0
  139. package/dist/types/middleware/secure-headers/index.d.ts +6 -64
  140. package/dist/types/middleware/secure-headers/secure-headers.d.ts +97 -0
  141. package/dist/types/middleware/serve-static/index.d.ts +4 -0
  142. package/dist/types/middleware/timeout/index.d.ts +31 -0
  143. package/dist/types/middleware/timing/index.d.ts +5 -29
  144. package/dist/types/middleware/timing/timing.d.ts +111 -0
  145. package/dist/types/middleware/trailing-slash/index.d.ts +29 -5
  146. package/dist/types/preset/quick.d.ts +4 -0
  147. package/dist/types/preset/tiny.d.ts +4 -0
  148. package/dist/types/request.d.ts +5 -4
  149. package/dist/types/router/linear-router/index.d.ts +4 -0
  150. package/dist/types/router/linear-router/router.d.ts +1 -1
  151. package/dist/types/router/pattern-router/index.d.ts +4 -0
  152. package/dist/types/router/reg-exp-router/index.d.ts +4 -0
  153. package/dist/types/router/reg-exp-router/router.d.ts +1 -1
  154. package/dist/types/router/reg-exp-router/trie.d.ts +1 -1
  155. package/dist/types/router/smart-router/index.d.ts +4 -0
  156. package/dist/types/router/smart-router/router.d.ts +1 -1
  157. package/dist/types/router/trie-router/index.d.ts +4 -0
  158. package/dist/types/router.d.ts +4 -0
  159. package/dist/types/types.d.ts +4 -0
  160. package/dist/types/utils/body.d.ts +61 -3
  161. package/dist/types/utils/buffer.d.ts +4 -0
  162. package/dist/types/utils/color.d.ts +4 -0
  163. package/dist/types/utils/concurrent.d.ts +4 -0
  164. package/dist/types/utils/cookie.d.ts +4 -0
  165. package/dist/types/utils/crypto.d.ts +4 -0
  166. package/dist/types/utils/encode.d.ts +4 -0
  167. package/dist/types/utils/filepath.d.ts +4 -0
  168. package/dist/types/utils/handler.d.ts +4 -0
  169. package/dist/types/utils/html.d.ts +4 -0
  170. package/dist/types/utils/http-status.d.ts +4 -0
  171. package/dist/types/utils/jwt/index.d.ts +4 -0
  172. package/dist/types/utils/jwt/jwt.d.ts +3 -3
  173. package/dist/types/utils/mime.d.ts +4 -0
  174. package/dist/types/utils/stream.d.ts +4 -0
  175. package/dist/types/utils/types.d.ts +4 -0
  176. package/dist/types/utils/url.d.ts +4 -0
  177. package/dist/types/validator/index.d.ts +4 -0
  178. package/dist/types/validator/validator.d.ts +1 -1
  179. package/dist/utils/body.js +34 -9
  180. package/dist/utils/jwt/index.js +1 -1
  181. package/dist/utils/jwt/jws.js +1 -2
  182. package/dist/utils/jwt/jwt.js +5 -5
  183. package/dist/utils/url.js +26 -2
  184. package/package.json +27 -6
  185. package/dist/cjs/adapter/aws-lambda/awslambda.d.js +0 -1
  186. package/dist/cjs/helper.js +0 -44
  187. package/dist/helper.js +0 -18
  188. /package/dist/{adapter/aws-lambda/awslambda.d.js → helper/conninfo/index.js} +0 -0
@@ -0,0 +1,126 @@
1
+ // src/middleware/secure-headers/secure-headers.ts
2
+ import { encodeBase64 } from "../../utils/encode.js";
3
+ var HEADERS_MAP = {
4
+ crossOriginEmbedderPolicy: ["Cross-Origin-Embedder-Policy", "require-corp"],
5
+ crossOriginResourcePolicy: ["Cross-Origin-Resource-Policy", "same-origin"],
6
+ crossOriginOpenerPolicy: ["Cross-Origin-Opener-Policy", "same-origin"],
7
+ originAgentCluster: ["Origin-Agent-Cluster", "?1"],
8
+ referrerPolicy: ["Referrer-Policy", "no-referrer"],
9
+ strictTransportSecurity: ["Strict-Transport-Security", "max-age=15552000; includeSubDomains"],
10
+ xContentTypeOptions: ["X-Content-Type-Options", "nosniff"],
11
+ xDnsPrefetchControl: ["X-DNS-Prefetch-Control", "off"],
12
+ xDownloadOptions: ["X-Download-Options", "noopen"],
13
+ xFrameOptions: ["X-Frame-Options", "SAMEORIGIN"],
14
+ xPermittedCrossDomainPolicies: ["X-Permitted-Cross-Domain-Policies", "none"],
15
+ xXssProtection: ["X-XSS-Protection", "0"]
16
+ };
17
+ var DEFAULT_OPTIONS = {
18
+ crossOriginEmbedderPolicy: false,
19
+ crossOriginResourcePolicy: true,
20
+ crossOriginOpenerPolicy: true,
21
+ originAgentCluster: true,
22
+ referrerPolicy: true,
23
+ strictTransportSecurity: true,
24
+ xContentTypeOptions: true,
25
+ xDnsPrefetchControl: true,
26
+ xDownloadOptions: true,
27
+ xFrameOptions: true,
28
+ xPermittedCrossDomainPolicies: true,
29
+ xXssProtection: true
30
+ };
31
+ var generateNonce = () => {
32
+ const buffer = new Uint8Array(16);
33
+ crypto.getRandomValues(buffer);
34
+ return encodeBase64(buffer);
35
+ };
36
+ var NONCE = (ctx) => {
37
+ const nonce = ctx.get("secureHeadersNonce") || (() => {
38
+ const newNonce = generateNonce();
39
+ ctx.set("secureHeadersNonce", newNonce);
40
+ return newNonce;
41
+ })();
42
+ return `'nonce-${nonce}'`;
43
+ };
44
+ var secureHeaders = (customOptions) => {
45
+ const options = { ...DEFAULT_OPTIONS, ...customOptions };
46
+ const headersToSet = getFilteredHeaders(options);
47
+ const callbacks = [];
48
+ if (options.contentSecurityPolicy) {
49
+ const [callback, value] = getCSPDirectives(options.contentSecurityPolicy);
50
+ if (callback) {
51
+ callbacks.push(callback);
52
+ }
53
+ headersToSet.push(["Content-Security-Policy", value]);
54
+ }
55
+ if (options.reportingEndpoints) {
56
+ headersToSet.push(["Reporting-Endpoints", getReportingEndpoints(options.reportingEndpoints)]);
57
+ }
58
+ if (options.reportTo) {
59
+ headersToSet.push(["Report-To", getReportToOptions(options.reportTo)]);
60
+ }
61
+ return async function secureHeaders2(ctx, next) {
62
+ const headersToSetForReq = callbacks.length === 0 ? headersToSet : callbacks.reduce((acc, cb) => cb(ctx, acc), headersToSet);
63
+ await next();
64
+ setHeaders(ctx, headersToSetForReq);
65
+ ctx.res.headers.delete("X-Powered-By");
66
+ };
67
+ };
68
+ function getFilteredHeaders(options) {
69
+ return Object.entries(HEADERS_MAP).filter(([key]) => options[key]).map(([key, defaultValue]) => {
70
+ const overrideValue = options[key];
71
+ return typeof overrideValue === "string" ? [defaultValue[0], overrideValue] : defaultValue;
72
+ });
73
+ }
74
+ function getCSPDirectives(contentSecurityPolicy) {
75
+ const callbacks = [];
76
+ const resultValues = [];
77
+ for (const [directive, value] of Object.entries(contentSecurityPolicy)) {
78
+ const valueArray = Array.isArray(value) ? value : [value];
79
+ valueArray.forEach((value2, i) => {
80
+ if (typeof value2 === "function") {
81
+ const index = i * 2 + 2 + resultValues.length;
82
+ callbacks.push((ctx, values) => {
83
+ values[index] = value2(ctx, directive);
84
+ });
85
+ }
86
+ });
87
+ resultValues.push(
88
+ directive.replace(
89
+ /[A-Z]+(?![a-z])|[A-Z]/g,
90
+ (match, offset) => offset ? "-" + match.toLowerCase() : match.toLowerCase()
91
+ ),
92
+ ...valueArray.flatMap((value2) => [" ", value2]),
93
+ "; "
94
+ );
95
+ }
96
+ resultValues.pop();
97
+ return callbacks.length === 0 ? [void 0, resultValues.join("")] : [
98
+ (ctx, headersToSet) => headersToSet.map((values) => {
99
+ if (values[0] === "Content-Security-Policy") {
100
+ const clone = values[1].slice();
101
+ callbacks.forEach((cb) => {
102
+ cb(ctx, clone);
103
+ });
104
+ return [values[0], clone.join("")];
105
+ } else {
106
+ return values;
107
+ }
108
+ }),
109
+ resultValues
110
+ ];
111
+ }
112
+ function getReportingEndpoints(reportingEndpoints = []) {
113
+ return reportingEndpoints.map((endpoint) => `${endpoint.name}="${endpoint.url}"`).join(", ");
114
+ }
115
+ function getReportToOptions(reportTo = []) {
116
+ return reportTo.map((option) => JSON.stringify(option)).join(", ");
117
+ }
118
+ function setHeaders(ctx, headersToSet) {
119
+ headersToSet.forEach(([header, value]) => {
120
+ ctx.res.headers.set(header, value);
121
+ });
122
+ }
123
+ export {
124
+ NONCE,
125
+ secureHeaders
126
+ };
@@ -0,0 +1,25 @@
1
+ // src/middleware/timeout/index.ts
2
+ import { HTTPException } from "../../http-exception.js";
3
+ var defaultTimeoutException = new HTTPException(504, {
4
+ message: "Gateway Timeout"
5
+ });
6
+ var timeout = (duration, exception = defaultTimeoutException) => {
7
+ return async function timeout2(context, next) {
8
+ let timer;
9
+ const timeoutPromise = new Promise((_, reject) => {
10
+ timer = setTimeout(() => {
11
+ reject(typeof exception === "function" ? exception(context) : exception);
12
+ }, duration);
13
+ });
14
+ try {
15
+ await Promise.race([next(), timeoutPromise]);
16
+ } finally {
17
+ if (timer !== void 0) {
18
+ clearTimeout(timer);
19
+ }
20
+ }
21
+ };
22
+ };
23
+ export {
24
+ timeout
25
+ };
@@ -1,89 +1,5 @@
1
1
  // src/middleware/timing/index.ts
2
- import "../../context.js";
3
- var getTime = () => {
4
- try {
5
- return performance.now();
6
- } catch {
7
- }
8
- return Date.now();
9
- };
10
- var timing = (config) => {
11
- const options = {
12
- ...{
13
- total: true,
14
- enabled: true,
15
- totalDescription: "Total Response Time",
16
- autoEnd: true,
17
- crossOrigin: false
18
- },
19
- ...config
20
- };
21
- return async function timing2(c, next) {
22
- const headers = [];
23
- const timers = /* @__PURE__ */ new Map();
24
- c.set("metric", { headers, timers });
25
- if (options.total) {
26
- startTime(c, "total", options.totalDescription);
27
- }
28
- await next();
29
- if (options.total) {
30
- endTime(c, "total");
31
- }
32
- if (options.autoEnd) {
33
- timers.forEach((_, key) => endTime(c, key));
34
- }
35
- const enabled = typeof options.enabled === "function" ? options.enabled(c) : options.enabled;
36
- if (enabled) {
37
- c.res.headers.append("Server-Timing", headers.join(","));
38
- const crossOrigin = typeof options.crossOrigin === "function" ? options.crossOrigin(c) : options.crossOrigin;
39
- if (crossOrigin) {
40
- c.res.headers.append(
41
- "Timing-Allow-Origin",
42
- typeof crossOrigin === "string" ? crossOrigin : "*"
43
- );
44
- }
45
- }
46
- };
47
- };
48
- var setMetric = (c, name, valueDescription, description, precision) => {
49
- const metrics = c.get("metric");
50
- if (!metrics) {
51
- console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
52
- return;
53
- }
54
- if (typeof valueDescription === "number") {
55
- const dur = valueDescription.toFixed(precision || 1);
56
- const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
57
- metrics.headers.push(metric);
58
- } else {
59
- const metric = valueDescription ? `${name};desc="${valueDescription}"` : `${name}`;
60
- metrics.headers.push(metric);
61
- }
62
- };
63
- var startTime = (c, name, description) => {
64
- const metrics = c.get("metric");
65
- if (!metrics) {
66
- console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
67
- return;
68
- }
69
- metrics.timers.set(name, { description, start: getTime() });
70
- };
71
- var endTime = (c, name, precision) => {
72
- const metrics = c.get("metric");
73
- if (!metrics) {
74
- console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
75
- return;
76
- }
77
- const timer = metrics.timers.get(name);
78
- if (!timer) {
79
- console.warn(`Timer "${name}" does not exist!`);
80
- return;
81
- }
82
- const { description, start } = timer;
83
- const duration = getTime() - start;
84
- setMetric(c, name, duration, description, precision);
85
- metrics.timers.delete(name);
86
- };
2
+ import { timing, setMetric, startTime, endTime } from "./timing.js";
87
3
  export {
88
4
  endTime,
89
5
  setMetric,
@@ -0,0 +1,92 @@
1
+ // src/middleware/timing/timing.ts
2
+ import "../../context.js";
3
+ var getTime = () => {
4
+ try {
5
+ return performance.now();
6
+ } catch {
7
+ }
8
+ return Date.now();
9
+ };
10
+ var timing = (config) => {
11
+ const options = {
12
+ ...{
13
+ total: true,
14
+ enabled: true,
15
+ totalDescription: "Total Response Time",
16
+ autoEnd: true,
17
+ crossOrigin: false
18
+ },
19
+ ...config
20
+ };
21
+ return async function timing2(c, next) {
22
+ const headers = [];
23
+ const timers = /* @__PURE__ */ new Map();
24
+ c.set("metric", { headers, timers });
25
+ if (options.total) {
26
+ startTime(c, "total", options.totalDescription);
27
+ }
28
+ await next();
29
+ if (options.total) {
30
+ endTime(c, "total");
31
+ }
32
+ if (options.autoEnd) {
33
+ timers.forEach((_, key) => endTime(c, key));
34
+ }
35
+ const enabled = typeof options.enabled === "function" ? options.enabled(c) : options.enabled;
36
+ if (enabled) {
37
+ c.res.headers.append("Server-Timing", headers.join(","));
38
+ const crossOrigin = typeof options.crossOrigin === "function" ? options.crossOrigin(c) : options.crossOrigin;
39
+ if (crossOrigin) {
40
+ c.res.headers.append(
41
+ "Timing-Allow-Origin",
42
+ typeof crossOrigin === "string" ? crossOrigin : "*"
43
+ );
44
+ }
45
+ }
46
+ };
47
+ };
48
+ var setMetric = (c, name, valueDescription, description, precision) => {
49
+ const metrics = c.get("metric");
50
+ if (!metrics) {
51
+ console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
52
+ return;
53
+ }
54
+ if (typeof valueDescription === "number") {
55
+ const dur = valueDescription.toFixed(precision || 1);
56
+ const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
57
+ metrics.headers.push(metric);
58
+ } else {
59
+ const metric = valueDescription ? `${name};desc="${valueDescription}"` : `${name}`;
60
+ metrics.headers.push(metric);
61
+ }
62
+ };
63
+ var startTime = (c, name, description) => {
64
+ const metrics = c.get("metric");
65
+ if (!metrics) {
66
+ console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
67
+ return;
68
+ }
69
+ metrics.timers.set(name, { description, start: getTime() });
70
+ };
71
+ var endTime = (c, name, precision) => {
72
+ const metrics = c.get("metric");
73
+ if (!metrics) {
74
+ console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
75
+ return;
76
+ }
77
+ const timer = metrics.timers.get(name);
78
+ if (!timer) {
79
+ console.warn(`Timer "${name}" does not exist!`);
80
+ return;
81
+ }
82
+ const { description, start } = timer;
83
+ const duration = getTime() - start;
84
+ setMetric(c, name, duration, description, precision);
85
+ metrics.timers.delete(name);
86
+ };
87
+ export {
88
+ endTime,
89
+ setMetric,
90
+ startTime,
91
+ timing
92
+ };
package/dist/request.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/request.ts
2
2
  import { parseBody } from "./utils/body.js";
3
- import { getQueryParam, getQueryParams, decodeURIComponent_ } from "./utils/url.js";
3
+ import { decodeURIComponent_, getQueryParam, getQueryParams } from "./utils/url.js";
4
4
  var HonoRequest = class {
5
5
  raw;
6
6
  #validatedData;
@@ -1,8 +1,8 @@
1
1
  // src/router/reg-exp-router/router.ts
2
2
  import {
3
+ MESSAGE_MATCHER_IS_ALREADY_BUILT,
3
4
  METHOD_NAME_ALL,
4
- UnsupportedPathError,
5
- MESSAGE_MATCHER_IS_ALREADY_BUILT
5
+ UnsupportedPathError
6
6
  } from "../../router.js";
7
7
  import { checkOptionalParameter } from "../../utils/url.js";
8
8
  import { PATH_ERROR } from "./node.js";
@@ -1,5 +1,5 @@
1
1
  // src/router/smart-router/router.ts
2
- import { UnsupportedPathError, MESSAGE_MATCHER_IS_ALREADY_BUILT } from "../../router.js";
2
+ import { MESSAGE_MATCHER_IS_ALREADY_BUILT, UnsupportedPathError } from "../../router.js";
3
3
  var SmartRouter = class {
4
4
  name = "SmartRouter";
5
5
  routers = [];
@@ -1,6 +1,6 @@
1
1
  // src/router/trie-router/node.ts
2
2
  import { METHOD_NAME_ALL } from "../../router.js";
3
- import { splitPath, splitRoutingPath, getPattern } from "../../utils/url.js";
3
+ import { getPattern, splitPath, splitRoutingPath } from "../../utils/url.js";
4
4
  var Node = class {
5
5
  methods;
6
6
  children;
@@ -1,7 +1,7 @@
1
1
  import type { Hono } from '../../hono';
2
2
  import type { Env, Schema } from '../../types';
3
- import type { ApiGatewayRequestContext, ApiGatewayRequestContextV2, ALBRequestContext } from './custom-context';
4
- import type { LambdaContext } from './types';
3
+ import type { ALBRequestContext, ApiGatewayRequestContext, ApiGatewayRequestContextV2 } from './custom-context';
4
+ import type { Handler, LambdaContext } from './types';
5
5
  export type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2 | ALBProxyEvent;
6
6
  export interface APIGatewayProxyEventV2 {
7
7
  version: string;
@@ -67,7 +67,7 @@ export interface APIGatewayProxyResult {
67
67
  };
68
68
  isBase64Encoded: boolean;
69
69
  }
70
- export declare const streamHandle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => import("./types").Handler;
70
+ export declare const streamHandle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => Handler;
71
71
  /**
72
72
  * Accepts events from API Gateway/ELB(`APIGatewayProxyEvent`) and directly through Function Url(`APIGatewayProxyEventV2`)
73
73
  */
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module
3
+ * AWS Lambda Adapter for Hono.
4
+ */
1
5
  export { handle, streamHandle } from './handler';
2
6
  export type { APIGatewayProxyResult, LambdaEvent } from './handler';
3
7
  export type { ApiGatewayRequestContext, ApiGatewayRequestContextV2, ALBRequestContext, } from './custom-context';
@@ -0,0 +1,7 @@
1
+ import type { GetConnInfo } from '../../helper/conninfo';
2
+ /**
3
+ * Get ConnInfo with Bun
4
+ * @param c Context
5
+ * @returns ConnInfo
6
+ */
7
+ export declare const getConnInfo: GetConnInfo;
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @module
3
+ * Bun Adapter for Hono.
4
+ */
1
5
  export { serveStatic } from './serve-static';
2
6
  export { bunFileSystemModule, toSSG } from './ssg';
3
7
  export { createBunWebSocket } from './websocket';
8
+ export { getConnInfo } from './conninfo';
@@ -1,5 +1,4 @@
1
- /// <reference types="node" />
2
- import { type UpgradeWebSocket } from '../../helper/websocket';
1
+ import type { UpgradeWebSocket } from '../../helper/websocket';
3
2
  interface BunServerWebSocket<T> {
4
3
  send(data: string | ArrayBufferLike, compress?: boolean): void;
5
4
  close(code?: number, reason?: string): void;
@@ -9,7 +8,7 @@ interface BunServerWebSocket<T> {
9
8
  interface BunWebSocketHandler<T> {
10
9
  open(ws: BunServerWebSocket<T>): void;
11
10
  close(ws: BunServerWebSocket<T>, code?: number, reason?: string): void;
12
- message(ws: BunServerWebSocket<T>, message: string | Buffer): void;
11
+ message(ws: BunServerWebSocket<T>, message: string | Uint8Array): void;
13
12
  }
14
13
  interface CreateWebSocket {
15
14
  (): {
@@ -1,2 +1,6 @@
1
+ /**
2
+ * @module
3
+ * Cloudflare Pages Adapter for Hono.
4
+ */
1
5
  export { handle, serveStatic } from './handler';
2
6
  export type { EventContext } from './handler';
@@ -0,0 +1,2 @@
1
+ import type { GetConnInfo } from '../../helper/conninfo';
2
+ export declare const getConnInfo: GetConnInfo;
@@ -1,2 +1,6 @@
1
+ /**
2
+ * @module
3
+ * Cloudflare Workers Adapter for Hono.
4
+ */
1
5
  export { serveStatic } from './serve-static-module';
2
6
  export { upgradeWebSocket } from './websocket';
@@ -1,4 +1,4 @@
1
- import type { Env } from '../../types';
1
+ import type { Env, MiddlewareHandler } from '../../types';
2
2
  import type { ServeStaticOptions } from './serve-static';
3
- declare const module: <E extends Env = Env>(options: Omit<ServeStaticOptions<E>, "namespace">) => import("../../types").MiddlewareHandler;
3
+ declare const module: <E extends Env = Env>(options: Omit<ServeStaticOptions<E>, "namespace">) => MiddlewareHandler;
4
4
  export { module as serveStatic };
@@ -1,8 +1,7 @@
1
- import type { KVNamespace } from '@cloudflare/workers-types';
2
1
  import type { ServeStaticOptions as BaseServeStaticOptions } from '../../middleware/serve-static';
3
2
  import type { Env, MiddlewareHandler } from '../../types';
4
3
  export type ServeStaticOptions<E extends Env = Env> = BaseServeStaticOptions<E> & {
5
- namespace?: KVNamespace;
4
+ namespace?: unknown;
6
5
  manifest: object | string;
7
6
  };
8
7
  /**
@@ -1,6 +1,5 @@
1
- import type { KVNamespace } from '@cloudflare/workers-types';
2
1
  export type KVAssetOptions = {
3
2
  manifest?: object | string;
4
- namespace?: KVNamespace;
3
+ namespace?: unknown;
5
4
  };
6
5
  export declare const getContentFromKVAsset: (path: string, options?: KVAssetOptions) => Promise<ReadableStream | null>;
@@ -0,0 +1,7 @@
1
+ import type { GetConnInfo } from '../../helper/conninfo';
2
+ /**
3
+ * Get conninfo with Deno
4
+ * @param c Context
5
+ * @returns ConnInfo
6
+ */
7
+ export declare const getConnInfo: GetConnInfo;
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @module
3
+ * Deno Adapter for Hono.
4
+ */
1
5
  export { serveStatic } from './serve-static';
2
6
  export { toSSG, denoFileSystemModule } from './ssg';
3
7
  export { upgradeWebSocket } from './websocket';
8
+ export { getConnInfo } from './conninfo';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { Hono } from '../../hono';
3
2
  interface CloudFrontHeader {
4
3
  key: string;
@@ -83,6 +82,6 @@ interface CloudFrontResult {
83
82
  bodyEncoding?: 'text' | 'base64';
84
83
  }
85
84
  export declare const handle: (app: Hono<any>) => (event: CloudFrontEdgeEvent, context?: CloudFrontContext, callback?: Callback) => Promise<CloudFrontResult>;
86
- export declare const createBody: (method: string, requestBody: CloudFrontRequest['body']) => string | Buffer | undefined;
85
+ export declare const createBody: (method: string, requestBody: CloudFrontRequest['body']) => string | Uint8Array | undefined;
87
86
  export declare const isContentTypeBinary: (contentType: string) => boolean;
88
87
  export {};
@@ -1,2 +1,6 @@
1
+ /**
2
+ * @module
3
+ * Lambda@Edge Adapter for Hono.
4
+ */
1
5
  export { handle } from './handler';
2
6
  export type { Callback, CloudFrontConfig, CloudFrontRequest, CloudFrontResponse, CloudFrontEdgeEvent, } from './handler';
@@ -1,8 +1,2 @@
1
- import type { Context } from 'https://edge.netlify.com/';
2
1
  import type { Hono } from '../../hono';
3
- export type Env = {
4
- Bindings: {
5
- context: Context;
6
- };
7
- };
8
- export declare const handle: (app: Hono<any, any>) => (req: Request, context: Context) => Response | Promise<Response>;
2
+ export declare const handle: (app: Hono<any, any>) => (req: Request, context: any) => Response | Promise<Response>;
@@ -1 +1,5 @@
1
+ /**
2
+ * @module
3
+ * Netlify Adapter for Hono.
4
+ */
1
5
  export * from './mod';
@@ -1,2 +1 @@
1
1
  export { handle } from './handler';
2
- export type { Env } from './handler';
@@ -1 +1,5 @@
1
+ /**
2
+ * @module
3
+ * Vercel Adapter for Hono.
4
+ */
1
5
  export { handle } from './handler';
@@ -1,2 +1,6 @@
1
+ /**
2
+ * @module
3
+ * The HTTP Client for Hono.
4
+ */
1
5
  export { hc } from './client';
2
6
  export type { InferResponseType, InferRequestType, Fetch, ClientRequestOptions, ClientRequest, ClientResponse, } from './types';
@@ -1,5 +1,5 @@
1
1
  import type { ParamIndexMap, Params } from './router';
2
- import type { Env, NotFoundHandler, ErrorHandler } from './types';
2
+ import type { Env, ErrorHandler, NotFoundHandler } from './types';
3
3
  interface ComposeContext {
4
4
  finalized: boolean;
5
5
  res: unknown;
@@ -1 +1,5 @@
1
+ /**
2
+ * @module
3
+ * Accepts Helper for Hono.
4
+ */
1
5
  export { accepts } from './accepts';
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module
3
+ * Adapter Helper for Hono.
4
+ */
1
5
  import type { Context } from '../../context';
2
6
  export type Runtime = 'node' | 'deno' | 'bun' | 'workerd' | 'fastly' | 'edge-light' | 'other';
3
7
  export declare const env: <T extends Record<string, unknown>, C extends Context<any, any, {}> = Context<{}, any, {}>>(c: C, runtime?: Runtime) => T & C["env"];
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @module
3
+ * ConnInfo Helper for Hono.
4
+ */
5
+ import type { Context } from '../../context';
6
+ export type AddressType = 'IPv6' | 'IPv4' | 'unknown';
7
+ export type NetAddrInfo = {
8
+ /**
9
+ * Transport protocol type
10
+ */
11
+ transport?: 'tcp' | 'udp';
12
+ /**
13
+ * Transport port number
14
+ */
15
+ port?: number;
16
+ address?: string;
17
+ addressType?: AddressType;
18
+ } & ({
19
+ /**
20
+ * Host name such as IP Addr
21
+ */
22
+ address: string;
23
+ /**
24
+ * Host name type
25
+ */
26
+ addressType: AddressType;
27
+ } | {});
28
+ /**
29
+ * HTTP Connection infomation
30
+ */
31
+ export interface ConnInfo {
32
+ /**
33
+ * Remote infomation
34
+ */
35
+ remote: NetAddrInfo;
36
+ }
37
+ /**
38
+ * Helper type
39
+ */
40
+ export type GetConnInfo = (c: Context) => ConnInfo;
@@ -1,5 +1,9 @@
1
+ /**
2
+ * @module
3
+ * Cookie Helper for Hono.
4
+ */
1
5
  import type { Context } from '../../context';
2
- import type { CookieOptions, Cookie, SignedCookie, CookiePrefixOptions } from '../../utils/cookie';
6
+ import type { Cookie, CookieOptions, CookiePrefixOptions, SignedCookie } from '../../utils/cookie';
3
7
  interface GetCookie {
4
8
  (c: Context, key: string): string | undefined;
5
9
  (c: Context): Cookie;
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module
3
+ * css Helper for Hono.
4
+ */
1
5
  import type { HtmlEscapedString } from '../../utils/html';
2
6
  import type { CssClassName as CssClassNameCommon, CssVariableType } from './common';
3
7
  export { rawCssString } from './common';
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module
3
+ * Dev Helper for Hono.
4
+ */
1
5
  import type { Hono } from '../../hono';
2
6
  import type { Env } from '../../types';
3
7
  interface ShowRoutesOptions {