hono 5.0.0-rc.0 → 5.0.0-rc.1

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 (98) hide show
  1. package/dist/client/fetch-result-please.js +0 -22
  2. package/dist/client/utils.js +0 -7
  3. package/dist/compose.d.ts +4 -3
  4. package/dist/compose.js +12 -30
  5. package/dist/context/constants.d.ts +3 -0
  6. package/dist/context/constants.js +4 -0
  7. package/dist/context.d.ts +41 -0
  8. package/dist/context.js +4 -230
  9. package/dist/helper/accepts/accepts.js +0 -13
  10. package/dist/helper/css/common.js +0 -10
  11. package/dist/helper/css/index.js +0 -38
  12. package/dist/helper/dev/index.d.ts +5 -2
  13. package/dist/helper/dev/index.js +3 -3
  14. package/dist/helper/factory/define-handler.js +0 -48
  15. package/dist/helper/factory/index.js +0 -28
  16. package/dist/helper/html/index.js +0 -4
  17. package/dist/helper/proxy/index.js +0 -49
  18. package/dist/helper/route/index.js +0 -90
  19. package/dist/helper/ssg/middleware.js +0 -18
  20. package/dist/helper/ssg/plugins.js +0 -24
  21. package/dist/helper/ssg/ssg.js +0 -15
  22. package/dist/helper/ssg/utils.js +0 -5
  23. package/dist/helper/testing/index.js +0 -4
  24. package/dist/helper/websocket/index.js +0 -6
  25. package/dist/hono-base.d.ts +46 -37
  26. package/dist/hono-base.js +62 -136
  27. package/dist/hono.js +0 -13
  28. package/dist/http-exception.js +0 -36
  29. package/dist/index.js +0 -15
  30. package/dist/jsx/components.js +0 -5
  31. package/dist/jsx/context.js +0 -34
  32. package/dist/jsx/dom/client.js +0 -14
  33. package/dist/jsx/dom/css.js +0 -34
  34. package/dist/jsx/dom/hooks/index.js +0 -21
  35. package/dist/jsx/dom/index.js +0 -4
  36. package/dist/jsx/dom/server.js +0 -12
  37. package/dist/jsx/index.js +0 -4
  38. package/dist/jsx/streaming.js +0 -26
  39. package/dist/middleware/basic-auth/index.js +0 -49
  40. package/dist/middleware/bearer-auth/index.js +0 -36
  41. package/dist/middleware/body-limit/index.js +0 -32
  42. package/dist/middleware/cache/index.js +0 -31
  43. package/dist/middleware/combine/index.js +0 -80
  44. package/dist/middleware/compress/index.js +0 -24
  45. package/dist/middleware/context-storage/index.js +0 -35
  46. package/dist/middleware/cors/index.js +0 -39
  47. package/dist/middleware/csrf/index.js +0 -62
  48. package/dist/middleware/etag/index.js +0 -29
  49. package/dist/middleware/ip-restriction/index.js +0 -41
  50. package/dist/middleware/jsx-renderer/index.js +0 -58
  51. package/dist/middleware/jwk/jwk.js +0 -31
  52. package/dist/middleware/jwt/jwt.js +0 -32
  53. package/dist/middleware/language/language.js +1 -61
  54. package/dist/middleware/logger/index.js +0 -16
  55. package/dist/middleware/method-not-allowed/index.js +1 -36
  56. package/dist/middleware/method-override/index.js +0 -25
  57. package/dist/middleware/mount/index.js +0 -32
  58. package/dist/middleware/powered-by/index.js +0 -15
  59. package/dist/middleware/pretty-json/index.js +0 -18
  60. package/dist/middleware/request-id/request-id.js +0 -22
  61. package/dist/middleware/secure-headers/secure-headers.js +0 -32
  62. package/dist/middleware/serve-static/index.js +0 -3
  63. package/dist/middleware/serve-static/path.js +0 -4
  64. package/dist/middleware/timeout/index.js +0 -22
  65. package/dist/middleware/timing/timing.js +0 -95
  66. package/dist/middleware/trailing-slash/index.js +0 -50
  67. package/dist/preset/quick.js +0 -4
  68. package/dist/preset/tiny.js +0 -4
  69. package/dist/request.js +0 -156
  70. package/dist/router/linear-router/router.js +16 -8
  71. package/dist/router/pattern-router/router.js +1 -1
  72. package/dist/router/reg-exp-router/node.js +8 -10
  73. package/dist/router/reg-exp-router/trie.js +0 -5
  74. package/dist/router/trie-router/node.js +2 -2
  75. package/dist/router.js +0 -19
  76. package/dist/types.d.ts +32 -1
  77. package/dist/utils/body.js +0 -30
  78. package/dist/utils/buffer.js +0 -4
  79. package/dist/utils/color.js +0 -13
  80. package/dist/utils/compress.js +0 -7
  81. package/dist/utils/concurrent.js +0 -4
  82. package/dist/utils/constants.js +0 -3
  83. package/dist/utils/cookie.js +0 -4
  84. package/dist/utils/encode.js +0 -4
  85. package/dist/utils/handler.js +0 -4
  86. package/dist/utils/html.js +0 -4
  87. package/dist/utils/ipaddr.js +0 -39
  88. package/dist/utils/jwt/index.js +0 -4
  89. package/dist/utils/jwt/jwa.js +0 -5
  90. package/dist/utils/jwt/jws.js +0 -5
  91. package/dist/utils/jwt/jwt.js +0 -5
  92. package/dist/utils/jwt/types.js +0 -4
  93. package/dist/utils/jwt/utf8.js +0 -4
  94. package/dist/utils/mime.js +0 -4
  95. package/dist/utils/stream.js +0 -14
  96. package/dist/utils/url.js +0 -19
  97. package/dist/validator/validator.js +0 -4
  98. package/package.json +1 -206
@@ -1,20 +1,10 @@
1
1
  //#region src/client/fetch-result-please.ts
2
- /**
3
- * @description This file is a modified version of `fetch-result-please` (`ofetch`), minimalized and adapted to Hono's custom needs.
4
- *
5
- * @link https://www.npmjs.com/package/fetch-result-please
6
- */
7
2
  const nullBodyResponses = /* @__PURE__ */ new Set([
8
3
  101,
9
4
  204,
10
5
  205,
11
6
  304
12
7
  ]);
13
- /**
14
- * Smartly parses and return the consumable result from a fetch `Response`.
15
- *
16
- * Throwing a structured error if the response is not `ok`. ({@link DetailedError})
17
- */
18
8
  async function fetchRP(fetchRes) {
19
9
  const _fetchRes = await fetchRes;
20
10
  if ((_fetchRes.body || _fetchRes._bodyInit) && !nullBodyResponses.has(_fetchRes.status)) _fetchRes._data = await _fetchRes[detectResponseType(_fetchRes)]();
@@ -28,21 +18,9 @@ async function fetchRP(fetchRes) {
28
18
  return _fetchRes._data;
29
19
  }
30
20
  var DetailedError = class extends Error {
31
- /**
32
- * Additional `message` that will be logged AND returned to client
33
- */
34
21
  detail;
35
- /**
36
- * Additional `code` that will be logged AND returned to client
37
- */
38
22
  code;
39
- /**
40
- * Additional value that will be logged AND NOT returned to client
41
- */
42
23
  log;
43
- /**
44
- * Optionally set the status code to return, in a web server context
45
- */
46
24
  statusCode;
47
25
  constructor(message, options = {}) {
48
26
  super(message);
@@ -48,13 +48,6 @@ function deepMerge(target, source) {
48
48
  }
49
49
  return merged;
50
50
  }
51
- /**
52
- * Shortcut to get a consumable response from `hc`'s fetch calls (Response), with types inference.
53
- *
54
- * Smartly parse the response data, throwing a structured error if the response is not `ok`. ({@link DetailedError})
55
- *
56
- * @example const result = await parseResponse(client.posts.$get())
57
- */
58
51
  async function parseResponse(fetchRes) {
59
52
  return fetchRP(fetchRes);
60
53
  }
package/dist/compose.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Env, ErrorHandler, Next, NotFoundHandler } from "./types.js";
1
+ import { Env, Next, NotFoundHandler } from "./types.js";
2
2
  import { Context } from "./context.js";
3
3
  //#region src/compose.d.ts
4
4
  export declare const toError: (err: unknown) => Error;
@@ -8,10 +8,11 @@ export declare const toError: (err: unknown) => Error;
8
8
  * @template E - The environment type.
9
9
  *
10
10
  * @param {[[Function, unknown], unknown][] | [[Function]][]} middleware - An array of middleware functions and their corresponding parameters.
11
- * @param {ErrorHandler<E>} [onError] - An optional error handler function.
11
+ * @param {Function} [onError] - An optional callback receiving the error and context.
12
12
  * @param {NotFoundHandler<E>} [onNotFound] - An optional not-found handler function.
13
+ * @param {boolean} [updateRouteIndex] - Whether to update the matched route index.
13
14
  *
14
15
  * @returns {(context: Context, next?: Next) => Promise<Context>} - A composed middleware function.
15
16
  */
16
- export declare const compose: <E extends Env = Env>(middleware: [[Function, unknown], unknown][] | [[Function]][], onError?: ErrorHandler<E>, onNotFound?: NotFoundHandler<E>) => ((context: Context, next?: Next) => Promise<Context>);
17
+ export declare const compose: <E extends Env = Env>(middleware: [[Function, unknown], unknown][] | [[Function]][], onError?: (err: Error, context: Context<E>) => Response | Promise<Response>, onNotFound?: NotFoundHandler<E>, updateRouteIndex?: boolean) => ((context: Context, next?: Next) => Promise<Context>);
17
18
  //#endregion
package/dist/compose.js CHANGED
@@ -1,49 +1,31 @@
1
1
  //#region src/compose.ts
2
2
  const toError = (err) => err instanceof Error ? err : new Error(typeof err === "string" ? err : void 0, { cause: err });
3
- /**
4
- * Compose middleware functions into a single function based on `koa-compose` package.
5
- *
6
- * @template E - The environment type.
7
- *
8
- * @param {[[Function, unknown], unknown][] | [[Function]][]} middleware - An array of middleware functions and their corresponding parameters.
9
- * @param {ErrorHandler<E>} [onError] - An optional error handler function.
10
- * @param {NotFoundHandler<E>} [onNotFound] - An optional not-found handler function.
11
- *
12
- * @returns {(context: Context, next?: Next) => Promise<Context>} - A composed middleware function.
13
- */
14
- const compose = (middleware, onError, onNotFound) => {
3
+ const compose = (middleware, onError, onNotFound, updateRouteIndex = true) => {
15
4
  return (context, next) => {
16
5
  let index = -1;
17
6
  return dispatch(0);
18
- /**
19
- * Dispatch the middleware functions.
20
- *
21
- * @param {number} i - The current index in the middleware array.
22
- *
23
- * @returns {Promise<Context>} - A promise that resolves to the context.
24
- */
25
7
  async function dispatch(i) {
26
8
  if (i <= index) throw new Error("next() called multiple times");
27
9
  index = i;
28
10
  let res;
29
11
  let isError = false;
30
- let handler;
31
- if (middleware[i]) {
32
- handler = middleware[i][0][0];
33
- context.req.routeIndex = i;
34
- } else handler = i === middleware.length && next || void 0;
12
+ const entry = middleware[i];
13
+ const handler = entry ? entry[0][0] : i === middleware.length && next || void 0;
14
+ if (entry) {
15
+ if (updateRouteIndex) context.req.routeIndex = i;
16
+ }
35
17
  if (handler) try {
36
18
  res = await handler(context, () => {
37
19
  const routeIndex = context.req.routeIndex;
38
20
  return dispatch(i + 1).finally(() => context.req.routeIndex = routeIndex);
39
21
  });
40
22
  } catch (err) {
41
- if (onError) {
42
- const error = toError(err);
43
- context.error = error;
44
- res = await onError(error, context);
45
- isError = true;
46
- } else throw err;
23
+ if (updateRouteIndex) context.req.routeIndex = i;
24
+ if (!onError) throw err;
25
+ const error = toError(err);
26
+ context.error = error;
27
+ res = await onError(error, context);
28
+ isError = true;
47
29
  }
48
30
  else if (context.finalized === false && onNotFound) res = await onNotFound(context);
49
31
  if (res && (context.finalized === false || isError)) context.res = res;
@@ -0,0 +1,3 @@
1
+ //#region src/context/constants.d.ts
2
+ export declare const GET_RESPONSE: unique symbol;
3
+ //#endregion
@@ -0,0 +1,4 @@
1
+ //#region src/context/constants.ts
2
+ const GET_RESPONSE = Symbol();
3
+ //#endregion
4
+ export { GET_RESPONSE };
package/dist/context.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { GET_RESPONSE } from "./context/constants.js";
1
2
  import { Result } from "./router.js";
2
3
  import { ResponseHeader } from "./utils/headers.js";
3
4
  import { ContentfulStatusCode, RedirectStatusCode, StatusCode } from "./utils/http-status.js";
@@ -11,6 +12,40 @@ type HeaderRecord = Record<'Content-Type', BaseMime> | Record<ResponseHeader, st
11
12
  * Data type can be a string, ArrayBuffer, Blob, Uint8Array (buffer), or ReadableStream.
12
13
  */
13
14
  export type Data = string | ArrayBuffer | Blob | ReadableStream | Uint8Array<ArrayBuffer>;
15
+ /**
16
+ * Identity information for a user authenticated by Cloudflare Access.
17
+ */
18
+ export interface CloudflareAccessIdentity extends Record<string, unknown> {
19
+ email?: string;
20
+ name?: string;
21
+ user_uuid?: string;
22
+ account_id?: string;
23
+ iat?: number;
24
+ ip?: string;
25
+ amr?: string[];
26
+ idp?: {
27
+ id: string;
28
+ type: string;
29
+ };
30
+ geo?: {
31
+ country: string;
32
+ };
33
+ groups?: Array<{
34
+ id: string;
35
+ name: string;
36
+ email?: string;
37
+ }>;
38
+ devicePosture?: Record<string, unknown>;
39
+ is_warp?: boolean;
40
+ is_gateway?: boolean;
41
+ }
42
+ /**
43
+ * Cloudflare Access authentication information for the current request.
44
+ */
45
+ export interface CloudflareAccessContext {
46
+ readonly aud: string;
47
+ getIdentity(): Promise<CloudflareAccessIdentity | undefined>;
48
+ }
14
49
  /**
15
50
  * Interface for the execution context in a web worker or similar environment.
16
51
  */
@@ -33,6 +68,10 @@ export interface ExecutionContext {
33
68
  * For compatibility with Wrangler 4.x.
34
69
  */
35
70
  exports?: any;
71
+ /**
72
+ * Cloudflare Access authentication information, when available.
73
+ */
74
+ readonly access?: CloudflareAccessContext;
36
75
  }
37
76
  /**
38
77
  * Interface for context variable mapping.
@@ -256,6 +295,8 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
256
295
  * @param _res - The Response object to set.
257
296
  */
258
297
  set res(_res: Response | undefined);
298
+ /** @internal Returns the existing response without creating one. */
299
+ get [GET_RESPONSE](): Response | undefined;
259
300
  /**
260
301
  * `.render()` can create a response within a layout.
261
302
  *
package/dist/context.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { GET_RESPONSE } from "./context/constants.js";
1
2
  import { HonoRequest } from "./request.js";
2
3
  import { HtmlEscapedCallbackPhase, resolveCallback } from "./utils/html.js";
3
4
  //#region src/context.ts
@@ -12,37 +13,9 @@ const createResponseInstance = (body, init) => new Response(body, init);
12
13
  var Context = class {
13
14
  #rawRequest;
14
15
  #req;
15
- /**
16
- * `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
17
- *
18
- * @see {@link https://hono.dev/docs/api/context#env}
19
- *
20
- * @example
21
- * ```ts
22
- * // Environment object for Cloudflare Workers
23
- * app.get('*', async c => {
24
- * const counter = c.env.COUNTER
25
- * })
26
- * ```
27
- */
28
16
  env = {};
29
17
  #var;
30
18
  finalized = false;
31
- /**
32
- * `.error` can get the error object from the middleware if the Handler throws an error.
33
- *
34
- * @see {@link https://hono.dev/docs/api/context#error}
35
- *
36
- * @example
37
- * ```ts
38
- * app.use('*', async (c, next) => {
39
- * await next()
40
- * if (c.error) {
41
- * // do something...
42
- * }
43
- * })
44
- * ```
45
- */
46
19
  error;
47
20
  #status;
48
21
  #executionCtx;
@@ -53,12 +26,6 @@ var Context = class {
53
26
  #preparedHeaders;
54
27
  #matchResult;
55
28
  #path;
56
- /**
57
- * Creates an instance of the Context class.
58
- *
59
- * @param req - The Request object.
60
- * @param options - Optional configuration options for the context.
61
- */
62
29
  constructor(req, options) {
63
30
  this.#rawRequest = req;
64
31
  if (options) {
@@ -69,45 +36,21 @@ var Context = class {
69
36
  this.#matchResult = options.matchResult;
70
37
  }
71
38
  }
72
- /**
73
- * `.req` is the instance of {@link HonoRequest}.
74
- */
75
39
  get req() {
76
40
  this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
77
41
  return this.#req;
78
42
  }
79
- /**
80
- * @see {@link https://hono.dev/docs/api/context#event}
81
- * The FetchEvent associated with the current request.
82
- *
83
- * @throws Will throw an error if the context does not have a FetchEvent.
84
- */
85
43
  get event() {
86
44
  if (this.#executionCtx && "respondWith" in this.#executionCtx) return this.#executionCtx;
87
45
  else throw Error("This context has no FetchEvent");
88
46
  }
89
- /**
90
- * @see {@link https://hono.dev/docs/api/context#executionctx}
91
- * The ExecutionContext associated with the current request.
92
- *
93
- * @throws Will throw an error if the context does not have an ExecutionContext.
94
- */
95
47
  get executionCtx() {
96
48
  if (this.#executionCtx) return this.#executionCtx;
97
49
  else throw Error("This context has no ExecutionContext");
98
50
  }
99
- /**
100
- * @see {@link https://hono.dev/docs/api/context#res}
101
- * The Response object for the current request.
102
- */
103
51
  get res() {
104
52
  return this.#res ||= createResponseInstance(null, { headers: this.#preparedHeaders ??= new Headers() });
105
53
  }
106
- /**
107
- * Sets the Response object for the current request.
108
- *
109
- * @param _res - The Response object to set.
110
- */
111
54
  set res(_res) {
112
55
  if (this.#res && _res) {
113
56
  _res = createResponseInstance(_res.body, _res);
@@ -123,87 +66,26 @@ var Context = class {
123
66
  this.#res = _res;
124
67
  this.finalized = true;
125
68
  }
126
- /**
127
- * `.render()` can create a response within a layout.
128
- *
129
- * @see {@link https://hono.dev/docs/api/context#render-setrenderer}
130
- *
131
- * @example
132
- * ```ts
133
- * app.get('/', (c) => {
134
- * return c.render('Hello!')
135
- * })
136
- * ```
137
- */
69
+ get [GET_RESPONSE]() {
70
+ return this.#res;
71
+ }
138
72
  get render() {
139
73
  return (...args) => {
140
74
  this.#renderer ??= (content) => this.html(content);
141
75
  return this.#renderer(...args);
142
76
  };
143
77
  }
144
- /**
145
- * Sets the layout for the response.
146
- *
147
- * @param layout - The layout to set.
148
- * @returns The layout function.
149
- */
150
78
  get setLayout() {
151
79
  return (layout) => this.#layout = layout;
152
80
  }
153
- /**
154
- * Gets the current layout for the response.
155
- *
156
- * @returns The current layout function.
157
- */
158
81
  get getLayout() {
159
82
  return () => this.#layout;
160
83
  }
161
- /**
162
- * `.setRenderer()` can set the layout in the custom middleware.
163
- *
164
- * @see {@link https://hono.dev/docs/api/context#render-setrenderer}
165
- *
166
- * @example
167
- * ```tsx
168
- * app.use('*', async (c, next) => {
169
- * c.setRenderer((content) => {
170
- * return c.html(
171
- * <html>
172
- * <body>
173
- * <p>{content}</p>
174
- * </body>
175
- * </html>
176
- * )
177
- * })
178
- * await next()
179
- * })
180
- * ```
181
- */
182
84
  get setRenderer() {
183
85
  return (renderer) => {
184
86
  this.#renderer = renderer;
185
87
  };
186
88
  }
187
- /**
188
- * `.header()` can set headers.
189
- *
190
- * @see {@link https://hono.dev/docs/api/context#header}
191
- *
192
- * @example
193
- * ```ts
194
- * app.get('/welcome', (c) => {
195
- * // Set headers
196
- * c.header('X-Message', 'Hello!')
197
- * c.header('Content-Type', 'text/plain')
198
- *
199
- * // Append multiple headers using the append option (e.g. Vary)
200
- * c.header('Vary', 'Accept-Encoding', { append: true })
201
- * c.header('Vary', 'User-Agent', { append: true })
202
- *
203
- * return c.body('Thank you for coming')
204
- * })
205
- * ```
206
- */
207
89
  get header() {
208
90
  return (name, value, options) => {
209
91
  if (this.finalized) this.#res = createResponseInstance(this.#res.body, this.#res);
@@ -218,53 +100,17 @@ var Context = class {
218
100
  this.#status = status;
219
101
  };
220
102
  }
221
- /**
222
- * `.set()` can set the value specified by the key.
223
- *
224
- * @see {@link https://hono.dev/docs/api/context#set-get}
225
- *
226
- * @example
227
- * ```ts
228
- * app.use('*', async (c, next) => {
229
- * c.set('message', 'Hono is hot!!')
230
- * await next()
231
- * })
232
- * ```
233
- */
234
103
  get set() {
235
104
  return (key, value) => {
236
105
  this.#var ??= /* @__PURE__ */ new Map();
237
106
  this.#var.set(key, value);
238
107
  };
239
108
  }
240
- /**
241
- * `.get()` can use the value specified by the key.
242
- *
243
- * @see {@link https://hono.dev/docs/api/context#set-get}
244
- *
245
- * @example
246
- * ```ts
247
- * app.get('/', (c) => {
248
- * const message = c.get('message')
249
- * return c.text(`The message is "${message}"`)
250
- * })
251
- * ```
252
- */
253
109
  get get() {
254
110
  return (key) => {
255
111
  return this.#var ? this.#var.get(key) : void 0;
256
112
  };
257
113
  }
258
- /**
259
- * `.var` can access the value of a variable.
260
- *
261
- * @see {@link https://hono.dev/docs/api/context#var}
262
- *
263
- * @example
264
- * ```ts
265
- * const result = c.var.client.oneMethod()
266
- * ```
267
- */
268
114
  get var() {
269
115
  if (!this.#var) return {};
270
116
  return Object.fromEntries(this.#var);
@@ -302,59 +148,14 @@ var Context = class {
302
148
  get newResponse() {
303
149
  return (...args) => this.#newResponse(...args);
304
150
  }
305
- /**
306
- * `.body()` can return the HTTP response.
307
- * You can set headers with `.header()` and set HTTP status code with `.status`.
308
- * This can also be set in `.text()`, `.json()` and so on.
309
- *
310
- * @see {@link https://hono.dev/docs/api/context#body}
311
- *
312
- * @example
313
- * ```ts
314
- * app.get('/welcome', (c) => {
315
- * // Set headers
316
- * c.header('X-Message', 'Hello!')
317
- * c.header('Content-Type', 'text/plain')
318
- * // Set HTTP status code
319
- * c.status(201)
320
- *
321
- * // Return the response body
322
- * return c.body('Thank you for coming')
323
- * })
324
- * ```
325
- */
326
151
  get body() {
327
152
  return (data, arg, headers) => this.#newResponse(data, arg, headers);
328
153
  }
329
- /**
330
- * `.text()` can render text as `Content-Type:text/plain`.
331
- *
332
- * @see {@link https://hono.dev/docs/api/context#text}
333
- *
334
- * @example
335
- * ```ts
336
- * app.get('/say', (c) => {
337
- * return c.text('Hello!')
338
- * })
339
- * ```
340
- */
341
154
  get text() {
342
155
  return (text, arg, headers) => {
343
156
  return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(text, arg, setDefaultContentType(TEXT_PLAIN, headers));
344
157
  };
345
158
  }
346
- /**
347
- * `.json()` can render JSON as `Content-Type:application/json`.
348
- *
349
- * @see {@link https://hono.dev/docs/api/context#json}
350
- *
351
- * @example
352
- * ```ts
353
- * app.get('/api', (c) => {
354
- * return c.json({ message: 'Hello!' })
355
- * })
356
- * ```
357
- */
358
159
  get json() {
359
160
  return (object, arg, headers) => {
360
161
  const body = JSON.stringify(object);
@@ -368,21 +169,6 @@ var Context = class {
368
169
  return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
369
170
  };
370
171
  }
371
- /**
372
- * `.redirect()` can Redirect, default status code is 302.
373
- *
374
- * @see {@link https://hono.dev/docs/api/context#redirect}
375
- *
376
- * @example
377
- * ```ts
378
- * app.get('/redirect', (c) => {
379
- * return c.redirect('/')
380
- * })
381
- * app.get('/redirect-permanently', (c) => {
382
- * return c.redirect('/', 301)
383
- * })
384
- * ```
385
- */
386
172
  get redirect() {
387
173
  return (location, status) => {
388
174
  const locationString = String(location);
@@ -390,18 +176,6 @@ var Context = class {
390
176
  return this.newResponse(null, status ?? 302);
391
177
  };
392
178
  }
393
- /**
394
- * `.notFound()` can return the Not Found Response.
395
- *
396
- * @see {@link https://hono.dev/docs/api/context#notfound}
397
- *
398
- * @example
399
- * ```ts
400
- * app.get('/notfound', (c) => {
401
- * return c.notFound()
402
- * })
403
- * ```
404
- */
405
179
  get notFound() {
406
180
  return () => {
407
181
  this.#notFoundHandler ??= () => createResponseInstance();
@@ -29,19 +29,6 @@ const defaultMatch = (accepts, config) => {
29
29
  }
30
30
  return defaultSupport;
31
31
  };
32
- /**
33
- * Match the accept header with the given options.
34
- * @example
35
- * ```ts
36
- * app.get('/users', (c) => {
37
- * const lang = accepts(c, {
38
- * header: 'Accept-Language',
39
- * supports: ['en', 'zh'],
40
- * default: 'en',
41
- * })
42
- * })
43
- * ```
44
- */
45
32
  const accepts = (c, options) => {
46
33
  const acceptHeader = c.req.header(options.header);
47
34
  if (!acceptHeader) return options.default;
@@ -9,19 +9,9 @@ const SELECTORS = Symbol();
9
9
  const EXTERNAL_CLASS_NAMES = Symbol();
10
10
  const CSS_ESCAPED = Symbol();
11
11
  const IS_CSS_ESCAPED = Symbol();
12
- /**
13
- * @experimental
14
- * `rawCssString` is an experimental feature.
15
- * The API might be changed.
16
- */
17
12
  const rawCssString = (value) => {
18
13
  return { [CSS_ESCAPED]: value };
19
14
  };
20
- /**
21
- * Used the goober'code as a reference:
22
- * https://github.com/cristianbote/goober/blob/master/src/core/to-hash.js
23
- * MIT License, Copyright (c) 2019 Cristian Bote
24
- */
25
15
  const toHash = (str) => {
26
16
  let i = 0, out = 11;
27
17
  while (i < str.length) out = 101 * out + str.charCodeAt(i++) >>> 0;
@@ -3,19 +3,6 @@ import { DOM_RENDERER } from "../../jsx/constants.js";
3
3
  import { CLASS_NAME, DEFAULT_STYLE_ID, SELECTOR, SELECTORS, STYLE_STRING, cssCommon, cxCommon, keyframesCommon, rawCssString, viewTransitionCommon } from "./common.js";
4
4
  import { createCssJsxDomObjects } from "../../jsx/dom/css.js";
5
5
  //#region src/helper/css/index.ts
6
- /**
7
- * @module
8
- * css Helper for Hono.
9
- */
10
- /**
11
- * @experimental
12
- * `createCssContext` is an experimental feature.
13
- * The API might be changed.
14
- *
15
- * @param options.id - The ID for the style element
16
- * @param options.classNameSlug - Optional function to customize generated CSS class names
17
- * @param options.onInvalidSlug - Optional callback function called when an invalid slug is returned from ClassNameSlug
18
- */
19
6
  const createCssContext = ({ id, classNameSlug, onInvalidSlug }) => {
20
7
  const [cssJsxDomObject, StyleRenderToDom] = createCssJsxDomObjects({ id });
21
8
  const contextMap = /* @__PURE__ */ new WeakMap();
@@ -101,35 +88,10 @@ const createCssContext = ({ id, classNameSlug, onInvalidSlug }) => {
101
88
  };
102
89
  };
103
90
  const defaultContext = createCssContext({ id: DEFAULT_STYLE_ID });
104
- /**
105
- * @experimental
106
- * `css` is an experimental feature.
107
- * The API might be changed.
108
- */
109
91
  const css = defaultContext.css;
110
- /**
111
- * @experimental
112
- * `cx` is an experimental feature.
113
- * The API might be changed.
114
- */
115
92
  const cx = defaultContext.cx;
116
- /**
117
- * @experimental
118
- * `keyframes` is an experimental feature.
119
- * The API might be changed.
120
- */
121
93
  const keyframes = defaultContext.keyframes;
122
- /**
123
- * @experimental
124
- * `viewTransition` is an experimental feature.
125
- * The API might be changed.
126
- */
127
94
  const viewTransition = defaultContext.viewTransition;
128
- /**
129
- * @experimental
130
- * `Style` is an experimental feature.
131
- * The API might be changed.
132
- */
133
95
  const Style = defaultContext.Style;
134
96
  //#endregion
135
97
  export { Style, createCssContext, css, cx, keyframes, rawCssString, viewTransition };
@@ -1,7 +1,10 @@
1
1
  import { Env } from "../../types.js";
2
2
  import { Hono } from "../../hono.js";
3
3
  //#region src/helper/dev/index.d.ts
4
- interface ShowRoutesOptions {
4
+ interface InspectRoutesOptions {
5
+ includeInternal?: boolean;
6
+ }
7
+ interface ShowRoutesOptions extends InspectRoutesOptions {
5
8
  verbose?: boolean;
6
9
  colorize?: boolean;
7
10
  }
@@ -11,7 +14,7 @@ interface RouteData {
11
14
  name: string;
12
15
  isMiddleware: boolean;
13
16
  }
14
- export declare const inspectRoutes: <E extends Env>(hono: Hono<E>) => RouteData[];
17
+ export declare const inspectRoutes: <E extends Env>(hono: Hono<E>, opts?: InspectRoutesOptions) => RouteData[];
15
18
  export declare const showRoutes: <E extends Env>(hono: Hono<E>, opts?: ShowRoutesOptions) => void;
16
19
  export declare const getRouterName: <E extends Env>(app: Hono<E>) => string;
17
20
  //#endregion