hono 4.0.0 → 4.0.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.
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  <p align="center">
10
10
  <a href="https://hono.dev"><b>Documentation :point_right: hono.dev</b></a><br />
11
- <i>v3 has been released!</i> <a href="docs/MIGRATION.md">Migration guide</b>
11
+ <i>v4 has been released!</i> <a href="docs/MIGRATION.md">Migration guide</b>
12
12
  </p>
13
13
 
14
14
  <hr />
@@ -42,13 +42,13 @@ export default app
42
42
  ## Quick Start
43
43
 
44
44
  ```
45
- npm create hono@latest my-app
45
+ npm create hono@latest
46
46
  ```
47
47
 
48
48
  ## Features
49
49
 
50
50
  - **Ultrafast** 🚀 - The router `RegExpRouter` is really fast. Not using linear loops. Fast.
51
- - **Lightweight** ðŸŠķ - The `hono/tiny` preset is under 14kB. Hono has zero dependencies and uses only the Web Standard API.
51
+ - **Lightweight** ðŸŠķ - The `hono/tiny` preset is under 13kB. Hono has zero dependencies and uses only the Web Standard API.
52
52
  - **Multi-runtime** 🌍 - Works on Cloudflare Workers, Fastly Compute, Deno, Bun, AWS Lambda, Lambda@Edge, or Node.js. The same code runs on all platforms.
53
53
  - **Batteries Included** 🔋 - Hono has built-in middleware, custom middleware, and third-party middleware. Batteries included.
54
54
  - **Delightful DX** 😃 - Super clean APIs. First-class TypeScript support. Now, we've got "Types".
@@ -32,7 +32,7 @@ const mergePath = (base, path) => {
32
32
  };
33
33
  const replaceUrlParam = (urlString, params) => {
34
34
  for (const [k, v] of Object.entries(params)) {
35
- const reg = new RegExp("/:" + k + "({[^}]*})?");
35
+ const reg = new RegExp("/:" + k + "(?:{[^/]+})?");
36
36
  urlString = urlString.replace(reg, `/${v}`);
37
37
  }
38
38
  return urlString;
@@ -63,7 +63,6 @@ class Context {
63
63
  this.renderer = (content) => this.html(content);
64
64
  this.notFoundHandler = () => new Response();
65
65
  this.render = (...args) => this.renderer(...args);
66
- this.render = (...args) => this.renderer(...args);
67
66
  this.setLayout = (layout) => this.layout = layout;
68
67
  this.getLayout = () => this.layout;
69
68
  this.setRenderer = (renderer) => {
@@ -23,22 +23,18 @@ __export(dev_exports, {
23
23
  showRoutes: () => showRoutes
24
24
  });
25
25
  module.exports = __toCommonJS(dev_exports);
26
- var import_hono_base = require("../../hono-base");
27
- const isMiddleware = (handler) => handler.length > 1;
26
+ var import_handler = require("../../utils/handler");
28
27
  const handlerName = (handler) => {
29
- return handler.name || (isMiddleware(handler) ? "[middleware]" : "[handler]");
30
- };
31
- const findTargetHandler = (handler) => {
32
- return handler[import_hono_base.COMPOSED_HANDLER] ? findTargetHandler(handler[import_hono_base.COMPOSED_HANDLER]) : handler;
28
+ return handler.name || ((0, import_handler.isMiddleware)(handler) ? "[middleware]" : "[handler]");
33
29
  };
34
30
  const inspectRoutes = (hono) => {
35
31
  return hono.routes.map(({ path, method, handler }) => {
36
- const targetHandler = findTargetHandler(handler);
32
+ const targetHandler = (0, import_handler.findTargetHandler)(handler);
37
33
  return {
38
34
  path,
39
35
  method,
40
36
  name: handlerName(targetHandler),
41
- isMiddleware: isMiddleware(targetHandler)
37
+ isMiddleware: (0, import_handler.isMiddleware)(targetHandler)
42
38
  };
43
39
  });
44
40
  };
@@ -18,10 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var ssg_exports = {};
20
20
  __export(ssg_exports, {
21
- X_HONO_DISABLE_SSG_HEADER_KEY: () => X_HONO_DISABLE_SSG_HEADER_KEY,
22
- X_HONO_SSG_HEADER_KEY: () => X_HONO_SSG_HEADER_KEY,
21
+ SSG_DISABLED_RESPONSE: () => SSG_DISABLED_RESPONSE,
23
22
  disableSSG: () => disableSSG,
24
23
  fetchRoutesContent: () => fetchRoutesContent,
24
+ isSSGContext: () => isSSGContext,
25
25
  onlySSG: () => onlySSG,
26
26
  saveContentToFiles: () => saveContentToFiles,
27
27
  ssgParams: () => ssgParams,
@@ -29,12 +29,11 @@ __export(ssg_exports, {
29
29
  });
30
30
  module.exports = __toCommonJS(ssg_exports);
31
31
  var import_utils = require("../../client/utils");
32
- var import_dev = require("../../helper/dev");
33
32
  var import_buffer = require("../../utils/buffer");
34
33
  var import_mime = require("../../utils/mime");
35
34
  var import_utils2 = require("./utils");
36
- const X_HONO_SSG_HEADER_KEY = "x-hono-ssg";
37
- const X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
35
+ const SSG_CONTEXT = "HONO_SSG_CONTEXT";
36
+ const SSG_DISABLED_RESPONSE = new Response("SSG is disabled", { status: 404 });
38
37
  const generateFilePath = (routePath, outDir, mimeType) => {
39
38
  const extension = determineExtension(mimeType);
40
39
  if (routePath === "/") {
@@ -79,13 +78,9 @@ const ssgParams = (params) => async (c, next) => {
79
78
  const fetchRoutesContent = async (app, beforeRequestHook, afterResponseHook) => {
80
79
  const htmlMap = /* @__PURE__ */ new Map();
81
80
  const baseURL = "http://localhost";
82
- for (const route of (0, import_dev.inspectRoutes)(app)) {
83
- if (route.isMiddleware) {
84
- continue;
85
- }
81
+ for (const route of (0, import_utils2.filterStaticGenerateRoutes)(app)) {
86
82
  const thisRouteBaseURL = new URL(route.path, baseURL).toString();
87
83
  let forGetInfoURLRequest = new Request(thisRouteBaseURL);
88
- forGetInfoURLRequest.headers.set(X_HONO_SSG_HEADER_KEY, "true");
89
84
  if (beforeRequestHook) {
90
85
  const maybeRequest = beforeRequestHook(forGetInfoURLRequest);
91
86
  if (!maybeRequest) {
@@ -100,10 +95,16 @@ const fetchRoutesContent = async (app, beforeRequestHook, afterResponseHook) =>
100
95
  }
101
96
  forGetInfoURLRequest.ssgParams = [{}];
102
97
  }
98
+ const requestInit = {
99
+ method: forGetInfoURLRequest.method,
100
+ headers: forGetInfoURLRequest.headers
101
+ };
103
102
  for (const param of forGetInfoURLRequest.ssgParams) {
104
103
  const replacedUrlParam = (0, import_utils.replaceUrlParam)(route.path, param);
105
- let response = await app.request(replacedUrlParam, forGetInfoURLRequest);
106
- if (response.headers.get(X_HONO_DISABLE_SSG_HEADER_KEY)) {
104
+ let response = await app.request(replacedUrlParam, requestInit, {
105
+ [SSG_CONTEXT]: true
106
+ });
107
+ if (response === SSG_DISABLED_RESPONSE) {
107
108
  continue;
108
109
  }
109
110
  if (afterResponseHook) {
@@ -159,23 +160,25 @@ const toSSG = async (app, fs, options) => {
159
160
  await options?.afterGenerateHook?.(result);
160
161
  return result;
161
162
  };
163
+ const isSSGContext = (c) => !!c.env?.[SSG_CONTEXT];
162
164
  const disableSSG = () => async function disableSSG2(c, next) {
165
+ if (isSSGContext(c)) {
166
+ return SSG_DISABLED_RESPONSE;
167
+ }
163
168
  await next();
164
- c.header(X_HONO_DISABLE_SSG_HEADER_KEY, "true");
165
169
  };
166
170
  const onlySSG = () => async function onlySSG2(c, next) {
167
- const headerValue = c.req.raw.headers.get(X_HONO_SSG_HEADER_KEY);
168
- if (headerValue) {
169
- await next();
171
+ if (!isSSGContext(c)) {
172
+ return c.notFound();
170
173
  }
171
- return c.notFound();
174
+ await next();
172
175
  };
173
176
  // Annotate the CommonJS export names for ESM import in node:
174
177
  0 && (module.exports = {
175
- X_HONO_DISABLE_SSG_HEADER_KEY,
176
- X_HONO_SSG_HEADER_KEY,
178
+ SSG_DISABLED_RESPONSE,
177
179
  disableSSG,
178
180
  fetchRoutesContent,
181
+ isSSGContext,
179
182
  onlySSG,
180
183
  saveContentToFiles,
181
184
  ssgParams,
@@ -19,9 +19,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var utils_exports = {};
20
20
  __export(utils_exports, {
21
21
  dirname: () => dirname,
22
+ filterStaticGenerateRoutes: () => filterStaticGenerateRoutes,
22
23
  joinPaths: () => joinPaths
23
24
  });
24
25
  module.exports = __toCommonJS(utils_exports);
26
+ var import_router = require("../../router");
27
+ var import_handler = require("../../utils/handler");
25
28
  const dirname = (path) => {
26
29
  const splitedPath = path.split(/[\/\\]/);
27
30
  return splitedPath.slice(0, -1).join("/");
@@ -57,8 +60,18 @@ const joinPaths = (...paths) => {
57
60
  handleSegments(paths.join("/").split("/"), resultPaths);
58
61
  return (paths[0][0] === "/" ? "/" : "") + resultPaths.join("/");
59
62
  };
63
+ const filterStaticGenerateRoutes = (hono) => {
64
+ return hono.routes.reduce((acc, { method, handler, path }) => {
65
+ const targetHandler = (0, import_handler.findTargetHandler)(handler);
66
+ if (["GET", import_router.METHOD_NAME_ALL].includes(method) && !(0, import_handler.isMiddleware)(targetHandler)) {
67
+ acc.push({ path });
68
+ }
69
+ return acc;
70
+ }, []);
71
+ };
60
72
  // Annotate the CommonJS export names for ESM import in node:
61
73
  0 && (module.exports = {
62
74
  dirname,
75
+ filterStaticGenerateRoutes,
63
76
  joinPaths
64
77
  });
@@ -31,7 +31,12 @@ class SSEStreamingApi extends import_stream.StreamingApi {
31
31
  const data = message.data.split("\n").map((line) => {
32
32
  return `data: ${line}`;
33
33
  }).join("\n");
34
- const sseData = [message.event && `event: ${message.event}`, data, message.id && `id: ${message.id}`].filter(Boolean).join("\n") + "\n\n";
34
+ const sseData = [
35
+ message.event && `event: ${message.event}`,
36
+ data,
37
+ message.id && `id: ${message.id}`,
38
+ message.retry && `retry: ${message.retry}`
39
+ ].filter(Boolean).join("\n") + "\n\n";
35
40
  await this.write(sseData);
36
41
  }
37
42
  }
@@ -193,6 +193,7 @@ const applyNodeObject = (node, container) => {
193
193
  }
194
194
  }
195
195
  }
196
+ const childNodes = container.childNodes;
196
197
  for (let i = 0, len = next.length; i < len; i++, offset++) {
197
198
  const child = next[i];
198
199
  let el;
@@ -206,8 +207,8 @@ const applyNodeObject = (node, container) => {
206
207
  applyProps(el, child.props, child.pP);
207
208
  applyNode(child, el);
208
209
  }
209
- if (container.childNodes[offset] !== el) {
210
- container.insertBefore(el, container.childNodes[offset] || null);
210
+ if (childNodes[offset] !== el && childNodes[offset - 1] !== child.e) {
211
+ container.insertBefore(el, childNodes[offset] || null);
211
212
  }
212
213
  }
213
214
  remove.forEach(removeNode);
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(router_exports);
24
24
  var import_router = require("../../router");
25
25
  var import_url = require("../../utils/url");
26
26
  const emptyParams = {};
27
- const splitPathRe = /\/(:\w+(?:{[^}]+})?)|\/[^\/\?]+|(\?)/g;
27
+ const splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
28
28
  const splitByStarRe = /\*/;
29
29
  class LinearRouter {
30
30
  constructor() {
@@ -32,7 +32,7 @@ class PatternRouter {
32
32
  if (endsWithWildcard) {
33
33
  path = path.slice(0, -2);
34
34
  }
35
- const parts = path.match(/\/?(:\w+(?:{[^}]+})?)|\/?[^\/\?]+|(\?)/g) || [];
35
+ const parts = path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+|(\?)/g) || [];
36
36
  if (parts[parts.length - 1] === "?") {
37
37
  this.add(method, parts.slice(0, parts.length - 2).join(""), handler);
38
38
  parts.pop();
@@ -0,0 +1,34 @@
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 handler_exports = {};
20
+ __export(handler_exports, {
21
+ findTargetHandler: () => findTargetHandler,
22
+ isMiddleware: () => isMiddleware
23
+ });
24
+ module.exports = __toCommonJS(handler_exports);
25
+ var import_hono_base = require("../hono-base");
26
+ const isMiddleware = (handler) => handler.length > 1;
27
+ const findTargetHandler = (handler) => {
28
+ return handler[import_hono_base.COMPOSED_HANDLER] ? findTargetHandler(handler[import_hono_base.COMPOSED_HANDLER]) : handler;
29
+ };
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ findTargetHandler,
33
+ isMiddleware
34
+ });
@@ -7,7 +7,7 @@ var mergePath = (base, path) => {
7
7
  };
8
8
  var replaceUrlParam = (urlString, params) => {
9
9
  for (const [k, v] of Object.entries(params)) {
10
- const reg = new RegExp("/:" + k + "({[^}]*})?");
10
+ const reg = new RegExp("/:" + k + "(?:{[^/]+})?");
11
11
  urlString = urlString.replace(reg, `/${v}`);
12
12
  }
13
13
  return urlString;
package/dist/context.js CHANGED
@@ -41,7 +41,6 @@ var Context = class {
41
41
  this.renderer = (content) => this.html(content);
42
42
  this.notFoundHandler = () => new Response();
43
43
  this.render = (...args) => this.renderer(...args);
44
- this.render = (...args) => this.renderer(...args);
45
44
  this.setLayout = (layout) => this.layout = layout;
46
45
  this.getLayout = () => this.layout;
47
46
  this.setRenderer = (renderer) => {
@@ -1,12 +1,8 @@
1
1
  // src/helper/dev/index.ts
2
- import { COMPOSED_HANDLER } from "../../hono-base.js";
3
- var isMiddleware = (handler) => handler.length > 1;
2
+ import { findTargetHandler, isMiddleware } from "../../utils/handler.js";
4
3
  var handlerName = (handler) => {
5
4
  return handler.name || (isMiddleware(handler) ? "[middleware]" : "[handler]");
6
5
  };
7
- var findTargetHandler = (handler) => {
8
- return handler[COMPOSED_HANDLER] ? findTargetHandler(handler[COMPOSED_HANDLER]) : handler;
9
- };
10
6
  var inspectRoutes = (hono) => {
11
7
  return hono.routes.map(({ path, method, handler }) => {
12
8
  const targetHandler = findTargetHandler(handler);
@@ -1,11 +1,10 @@
1
1
  // src/helper/ssg/index.ts
2
2
  import { replaceUrlParam } from "../../client/utils.js";
3
- import { inspectRoutes } from "../../helper/dev/index.js";
4
3
  import { bufferToString } from "../../utils/buffer.js";
5
4
  import { getExtension } from "../../utils/mime.js";
6
- import { joinPaths, dirname } from "./utils.js";
7
- var X_HONO_SSG_HEADER_KEY = "x-hono-ssg";
8
- var X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
5
+ import { joinPaths, dirname, filterStaticGenerateRoutes } from "./utils.js";
6
+ var SSG_CONTEXT = "HONO_SSG_CONTEXT";
7
+ var SSG_DISABLED_RESPONSE = new Response("SSG is disabled", { status: 404 });
9
8
  var generateFilePath = (routePath, outDir, mimeType) => {
10
9
  const extension = determineExtension(mimeType);
11
10
  if (routePath === "/") {
@@ -50,13 +49,9 @@ var ssgParams = (params) => async (c, next) => {
50
49
  var fetchRoutesContent = async (app, beforeRequestHook, afterResponseHook) => {
51
50
  const htmlMap = /* @__PURE__ */ new Map();
52
51
  const baseURL = "http://localhost";
53
- for (const route of inspectRoutes(app)) {
54
- if (route.isMiddleware) {
55
- continue;
56
- }
52
+ for (const route of filterStaticGenerateRoutes(app)) {
57
53
  const thisRouteBaseURL = new URL(route.path, baseURL).toString();
58
54
  let forGetInfoURLRequest = new Request(thisRouteBaseURL);
59
- forGetInfoURLRequest.headers.set(X_HONO_SSG_HEADER_KEY, "true");
60
55
  if (beforeRequestHook) {
61
56
  const maybeRequest = beforeRequestHook(forGetInfoURLRequest);
62
57
  if (!maybeRequest) {
@@ -71,10 +66,16 @@ var fetchRoutesContent = async (app, beforeRequestHook, afterResponseHook) => {
71
66
  }
72
67
  forGetInfoURLRequest.ssgParams = [{}];
73
68
  }
69
+ const requestInit = {
70
+ method: forGetInfoURLRequest.method,
71
+ headers: forGetInfoURLRequest.headers
72
+ };
74
73
  for (const param of forGetInfoURLRequest.ssgParams) {
75
74
  const replacedUrlParam = replaceUrlParam(route.path, param);
76
- let response = await app.request(replacedUrlParam, forGetInfoURLRequest);
77
- if (response.headers.get(X_HONO_DISABLE_SSG_HEADER_KEY)) {
75
+ let response = await app.request(replacedUrlParam, requestInit, {
76
+ [SSG_CONTEXT]: true
77
+ });
78
+ if (response === SSG_DISABLED_RESPONSE) {
78
79
  continue;
79
80
  }
80
81
  if (afterResponseHook) {
@@ -130,22 +131,24 @@ var toSSG = async (app, fs, options) => {
130
131
  await options?.afterGenerateHook?.(result);
131
132
  return result;
132
133
  };
134
+ var isSSGContext = (c) => !!c.env?.[SSG_CONTEXT];
133
135
  var disableSSG = () => async function disableSSG2(c, next) {
136
+ if (isSSGContext(c)) {
137
+ return SSG_DISABLED_RESPONSE;
138
+ }
134
139
  await next();
135
- c.header(X_HONO_DISABLE_SSG_HEADER_KEY, "true");
136
140
  };
137
141
  var onlySSG = () => async function onlySSG2(c, next) {
138
- const headerValue = c.req.raw.headers.get(X_HONO_SSG_HEADER_KEY);
139
- if (headerValue) {
140
- await next();
142
+ if (!isSSGContext(c)) {
143
+ return c.notFound();
141
144
  }
142
- return c.notFound();
145
+ await next();
143
146
  };
144
147
  export {
145
- X_HONO_DISABLE_SSG_HEADER_KEY,
146
- X_HONO_SSG_HEADER_KEY,
148
+ SSG_DISABLED_RESPONSE,
147
149
  disableSSG,
148
150
  fetchRoutesContent,
151
+ isSSGContext,
149
152
  onlySSG,
150
153
  saveContentToFiles,
151
154
  ssgParams,
@@ -1,4 +1,6 @@
1
1
  // src/helper/ssg/utils.ts
2
+ import { METHOD_NAME_ALL } from "../../router.js";
3
+ import { findTargetHandler, isMiddleware } from "../../utils/handler.js";
2
4
  var dirname = (path) => {
3
5
  const splitedPath = path.split(/[\/\\]/);
4
6
  return splitedPath.slice(0, -1).join("/");
@@ -34,7 +36,17 @@ var joinPaths = (...paths) => {
34
36
  handleSegments(paths.join("/").split("/"), resultPaths);
35
37
  return (paths[0][0] === "/" ? "/" : "") + resultPaths.join("/");
36
38
  };
39
+ var filterStaticGenerateRoutes = (hono) => {
40
+ return hono.routes.reduce((acc, { method, handler, path }) => {
41
+ const targetHandler = findTargetHandler(handler);
42
+ if (["GET", METHOD_NAME_ALL].includes(method) && !isMiddleware(targetHandler)) {
43
+ acc.push({ path });
44
+ }
45
+ return acc;
46
+ }, []);
47
+ };
37
48
  export {
38
49
  dirname,
50
+ filterStaticGenerateRoutes,
39
51
  joinPaths
40
52
  };
@@ -8,7 +8,12 @@ var SSEStreamingApi = class extends StreamingApi {
8
8
  const data = message.data.split("\n").map((line) => {
9
9
  return `data: ${line}`;
10
10
  }).join("\n");
11
- const sseData = [message.event && `event: ${message.event}`, data, message.id && `id: ${message.id}`].filter(Boolean).join("\n") + "\n\n";
11
+ const sseData = [
12
+ message.event && `event: ${message.event}`,
13
+ data,
14
+ message.id && `id: ${message.id}`,
15
+ message.retry && `retry: ${message.retry}`
16
+ ].filter(Boolean).join("\n") + "\n\n";
12
17
  await this.write(sseData);
13
18
  }
14
19
  };
@@ -168,6 +168,7 @@ var applyNodeObject = (node, container) => {
168
168
  }
169
169
  }
170
170
  }
171
+ const childNodes = container.childNodes;
171
172
  for (let i = 0, len = next.length; i < len; i++, offset++) {
172
173
  const child = next[i];
173
174
  let el;
@@ -181,8 +182,8 @@ var applyNodeObject = (node, container) => {
181
182
  applyProps(el, child.props, child.pP);
182
183
  applyNode(child, el);
183
184
  }
184
- if (container.childNodes[offset] !== el) {
185
- container.insertBefore(el, container.childNodes[offset] || null);
185
+ if (childNodes[offset] !== el && childNodes[offset - 1] !== child.e) {
186
+ container.insertBefore(el, childNodes[offset] || null);
186
187
  }
187
188
  }
188
189
  remove.forEach(removeNode);
@@ -2,7 +2,7 @@
2
2
  import { METHOD_NAME_ALL, UnsupportedPathError } from "../../router.js";
3
3
  import { checkOptionalParameter } from "../../utils/url.js";
4
4
  var emptyParams = {};
5
- var splitPathRe = /\/(:\w+(?:{[^}]+})?)|\/[^\/\?]+|(\?)/g;
5
+ var splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
6
6
  var splitByStarRe = /\*/;
7
7
  var LinearRouter = class {
8
8
  constructor() {
@@ -10,7 +10,7 @@ var PatternRouter = class {
10
10
  if (endsWithWildcard) {
11
11
  path = path.slice(0, -2);
12
12
  }
13
- const parts = path.match(/\/?(:\w+(?:{[^}]+})?)|\/?[^\/\?]+|(\?)/g) || [];
13
+ const parts = path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+|(\?)/g) || [];
14
14
  if (parts[parts.length - 1] === "?") {
15
15
  this.add(method, parts.slice(0, parts.length - 2).join(""), handler);
16
16
  parts.pop();
@@ -112,6 +112,14 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
112
112
  * @see https://hono.dev/api/context#render-setrenderer
113
113
  */
114
114
  render: Renderer;
115
+ setLayout: (layout: FC<PropsForRenderer & {
116
+ Layout: FC;
117
+ }>) => FC<{
118
+ Layout: FC;
119
+ }>;
120
+ getLayout: () => FC<{
121
+ Layout: FC;
122
+ }> | undefined;
115
123
  /**
116
124
  * `.setRenderer()` can set the layout in the custom middleware.
117
125
  * @example
@@ -131,15 +139,6 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
131
139
  * ```
132
140
  * @see https://hono.dev/api/context#render-setrenderer
133
141
  */
134
- render: Renderer;
135
- setLayout: (layout: FC<PropsForRenderer & {
136
- Layout: FC;
137
- }>) => FC<{
138
- Layout: FC;
139
- }>;
140
- getLayout: () => FC<{
141
- Layout: FC;
142
- }> | undefined;
143
142
  setRenderer: (renderer: Renderer) => void;
144
143
  /**
145
144
  * `.header()` can set headers.
@@ -1,7 +1,7 @@
1
- import type { Env, Input, MiddlewareHandler, H, HandlerResponse } from '../../types';
1
+ import type { Env, H, HandlerResponse, Input, MiddlewareHandler } from '../../types';
2
2
  export declare class Factory<E extends Env = any, P extends string = any> {
3
3
  createMiddleware: <I extends Input = {}>(middleware: MiddlewareHandler<E, P, I>) => MiddlewareHandler<E, P, I>;
4
- createHandlers<I extends Input = {}>(handler1: H<E, P, I>): [H<E, P, I>];
4
+ createHandlers<I extends Input = {}, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>): [H<E, P, I, R>];
5
5
  createHandlers<I extends Input = {}, I2 extends Input = I, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>, handler2: H<E, P, I2, R>): [H<E, P, I, R>, H<E, P, I2, R>];
6
6
  createHandlers<I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>, handler2: H<E, P, I2, R>, handler3: H<E, P, I3, R>): [H<E, P, I, R>, H<E, P, I2, R>, H<E, P, I3, R>];
7
7
  createHandlers<I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>, handler2: H<E, P, I2, R>, handler3: H<E, P, I3, R>, handler4: H<E, P, I4, R>): [H<E, P, I, R>, H<E, P, I2, R>, H<E, P, I3, R>, H<E, P, I4, R>];
@@ -1,8 +1,7 @@
1
1
  import type { Context } from '../../context';
2
2
  import type { Hono } from '../../hono';
3
3
  import type { Env, MiddlewareHandler, Schema } from '../../types';
4
- export declare const X_HONO_SSG_HEADER_KEY = "x-hono-ssg";
5
- export declare const X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
4
+ export declare const SSG_DISABLED_RESPONSE: Response;
6
5
  /**
7
6
  * @experimental
8
7
  * `FileSystemModule` is an experimental feature.
@@ -85,6 +84,12 @@ export interface ToSSGAdaptorInterface<E extends Env = Env, S extends Schema = {
85
84
  * The API might be changed.
86
85
  */
87
86
  export declare const toSSG: ToSSGInterface;
87
+ /**
88
+ * @experimental
89
+ * `isSSGContext` is an experimental feature.
90
+ * The API might be changed.
91
+ */
92
+ export declare const isSSGContext: (c: Context) => boolean;
88
93
  /**
89
94
  * @experimental
90
95
  * `disableSSG` is an experimental feature.
@@ -1,3 +1,5 @@
1
+ import type { Hono } from '../../hono';
2
+ import type { Env } from '../../types';
1
3
  /**
2
4
  * Get dirname
3
5
  * @param path File Path
@@ -5,3 +7,8 @@
5
7
  */
6
8
  export declare const dirname: (path: string) => string;
7
9
  export declare const joinPaths: (...paths: string[]) => string;
10
+ interface FilterStaticGenerateRouteData {
11
+ path: string;
12
+ }
13
+ export declare const filterStaticGenerateRoutes: <E extends Env>(hono: Hono<E, import("../../types").BlankSchema, "/">) => FilterStaticGenerateRouteData[];
14
+ export {};
@@ -4,6 +4,7 @@ export interface SSEMessage {
4
4
  data: string;
5
5
  event?: string;
6
6
  id?: string;
7
+ retry?: number;
7
8
  }
8
9
  export declare class SSEStreamingApi extends StreamingApi {
9
10
  constructor(writable: WritableStream, readable: ReadableStream);
@@ -0,0 +1,2 @@
1
+ export declare const isMiddleware: (handler: Function) => boolean;
2
+ export declare const findTargetHandler: (handler: Function) => Function;
@@ -0,0 +1,10 @@
1
+ // src/utils/handler.ts
2
+ import { COMPOSED_HANDLER } from "../hono-base.js";
3
+ var isMiddleware = (handler) => handler.length > 1;
4
+ var findTargetHandler = (handler) => {
5
+ return handler[COMPOSED_HANDLER] ? findTargetHandler(handler[COMPOSED_HANDLER]) : handler;
6
+ };
7
+ export {
8
+ findTargetHandler,
9
+ isMiddleware
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",