hono 4.4.2 → 4.4.4
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 +2 -1
- package/dist/adapter/cloudflare-workers/index.js +2 -0
- package/dist/adapter/cloudflare-workers/websocket.js +1 -0
- package/dist/adapter/deno/serve-static.js +2 -3
- package/dist/adapter/deno/websocket.js +1 -1
- package/dist/cjs/adapter/cloudflare-workers/index.js +3 -0
- package/dist/cjs/adapter/cloudflare-workers/websocket.js +1 -0
- package/dist/cjs/adapter/deno/serve-static.js +2 -3
- package/dist/cjs/adapter/deno/websocket.js +1 -1
- package/dist/cjs/context.js +2 -2
- package/dist/cjs/{adapter/aws-lambda/custom-context.js → helper/conninfo/types.js} +2 -2
- package/dist/cjs/hono-base.js +31 -18
- package/dist/cjs/jsx/utils.js +4 -0
- package/dist/cjs/middleware/serve-static/index.js +5 -3
- package/dist/cjs/utils/filepath.js +1 -1
- package/dist/context.js +2 -2
- package/dist/hono-base.js +32 -19
- package/dist/jsx/utils.js +4 -0
- package/dist/middleware/serve-static/index.js +5 -3
- package/dist/types/adapter/aws-lambda/handler.d.ts +1 -2
- package/dist/types/adapter/aws-lambda/index.d.ts +1 -2
- package/dist/types/adapter/aws-lambda/types.d.ts +82 -0
- package/dist/types/adapter/cloudflare-workers/index.d.ts +1 -0
- package/dist/types/context.d.ts +54 -25
- package/dist/types/helper/conninfo/index.d.ts +1 -36
- package/dist/types/helper/conninfo/types.d.ts +36 -0
- package/dist/types/hono-base.d.ts +86 -15
- package/dist/types/http-exception.d.ts +9 -1
- package/dist/types/jsx/utils.d.ts +6 -0
- package/dist/types/request.d.ts +42 -14
- package/dist/types/types.d.ts +11 -8
- package/dist/types/utils/http-status.d.ts +10 -5
- package/dist/types/utils/types.d.ts +10 -3
- package/dist/utils/filepath.js +1 -1
- package/package.json +5 -4
- package/dist/types/adapter/aws-lambda/custom-context.d.ts +0 -83
- /package/dist/{adapter/aws-lambda/custom-context.js → helper/conninfo/types.js} +0 -0
package/dist/types/context.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HonoRequest } from './request';
|
|
2
2
|
import type { Env, FetchEventLike, Input, NotFoundHandler, TypedResponse } from './types';
|
|
3
3
|
import type { RedirectStatusCode, StatusCode } from './utils/http-status';
|
|
4
|
-
import type { IsAny, JSONParsed, JSONValue,
|
|
4
|
+
import type { IsAny, JSONParsed, JSONValue, SimplifyDeepArray } from './utils/types';
|
|
5
5
|
type HeaderRecord = Record<string, string | string[]>;
|
|
6
6
|
/**
|
|
7
7
|
* Data type can be a string, ArrayBuffer, or ReadableStream.
|
|
@@ -109,12 +109,19 @@ interface TextRespond {
|
|
|
109
109
|
* @param {U} [status] - An optional status code for the response.
|
|
110
110
|
* @param {HeaderRecord} [headers] - An optional record of headers to include in the response.
|
|
111
111
|
*
|
|
112
|
-
* @returns {
|
|
112
|
+
* @returns {JSONRespondReturn<T, U>} - The response after rendering the JSON object, typed with the provided object and status code types.
|
|
113
113
|
*/
|
|
114
114
|
interface JSONRespond {
|
|
115
|
-
<T extends JSONValue |
|
|
116
|
-
<T extends JSONValue |
|
|
115
|
+
<T extends JSONValue | SimplifyDeepArray<unknown>, U extends StatusCode>(object: T, status?: U, headers?: HeaderRecord): JSONRespondReturn<T, U>;
|
|
116
|
+
<T extends JSONValue | SimplifyDeepArray<unknown>, U extends StatusCode>(object: T, init?: ResponseInit): JSONRespondReturn<T, U>;
|
|
117
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* @template T - The type of the JSON value or simplified unknown type.
|
|
120
|
+
* @template U - The type of the status code.
|
|
121
|
+
*
|
|
122
|
+
* @returns {Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? (JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T>) : never, U, 'json'>} - The response after rendering the JSON object, typed with the provided object and status code types.
|
|
123
|
+
*/
|
|
124
|
+
type JSONRespondReturn<T extends JSONValue | SimplifyDeepArray<unknown>, U extends StatusCode> = Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T> : never, U, 'json'>;
|
|
118
125
|
/**
|
|
119
126
|
* Interface representing a function that responds with HTML content.
|
|
120
127
|
*
|
|
@@ -157,6 +164,9 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
157
164
|
req: HonoRequest<P, I['out']>;
|
|
158
165
|
/**
|
|
159
166
|
* `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
|
|
167
|
+
*
|
|
168
|
+
* @see {@link https://hono.dev/api/context#env}
|
|
169
|
+
*
|
|
160
170
|
* @example
|
|
161
171
|
* ```ts
|
|
162
172
|
* // Environment object for Cloudflare Workers
|
|
@@ -164,13 +174,15 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
164
174
|
* const counter = c.env.COUNTER
|
|
165
175
|
* })
|
|
166
176
|
* ```
|
|
167
|
-
* @see https://hono.dev/api/context#env
|
|
168
177
|
*/
|
|
169
178
|
env: E['Bindings'];
|
|
170
179
|
private _var;
|
|
171
180
|
finalized: boolean;
|
|
172
181
|
/**
|
|
173
182
|
* `.error` can get the error object from the middleware if the Handler throws an error.
|
|
183
|
+
*
|
|
184
|
+
* @see {@link https://hono.dev/api/context#error}
|
|
185
|
+
*
|
|
174
186
|
* @example
|
|
175
187
|
* ```ts
|
|
176
188
|
* app.use('*', async (c, next) => {
|
|
@@ -180,7 +192,6 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
180
192
|
* }
|
|
181
193
|
* })
|
|
182
194
|
* ```
|
|
183
|
-
* @see https://hono.dev/api/context#error
|
|
184
195
|
*/
|
|
185
196
|
error: Error | undefined;
|
|
186
197
|
private layout;
|
|
@@ -194,25 +205,22 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
194
205
|
*/
|
|
195
206
|
constructor(req: HonoRequest<P, I['out']>, options?: ContextOptions<E>);
|
|
196
207
|
/**
|
|
208
|
+
* @see {@link https://hono.dev/api/context#event}
|
|
197
209
|
* The FetchEvent associated with the current request.
|
|
198
210
|
*
|
|
199
211
|
* @throws Will throw an error if the context does not have a FetchEvent.
|
|
200
|
-
*
|
|
201
|
-
* @see https://hono.dev/api/context#event
|
|
202
212
|
*/
|
|
203
213
|
get event(): FetchEventLike;
|
|
204
214
|
/**
|
|
215
|
+
* @see {@link https://hono.dev/api/context#executionctx}
|
|
205
216
|
* The ExecutionContext associated with the current request.
|
|
206
217
|
*
|
|
207
218
|
* @throws Will throw an error if the context does not have an ExecutionContext.
|
|
208
|
-
*
|
|
209
|
-
* @see https://hono.dev/api/context#executionctx
|
|
210
219
|
*/
|
|
211
220
|
get executionCtx(): ExecutionContext;
|
|
212
221
|
/**
|
|
222
|
+
* @see {@link https://hono.dev/api/context#res}
|
|
213
223
|
* The Response object for the current request.
|
|
214
|
-
*
|
|
215
|
-
* @see https://hono.dev/api/context#res
|
|
216
224
|
*/
|
|
217
225
|
get res(): Response;
|
|
218
226
|
/**
|
|
@@ -222,7 +230,9 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
222
230
|
*/
|
|
223
231
|
set res(_res: Response | undefined);
|
|
224
232
|
/**
|
|
225
|
-
*
|
|
233
|
+
* `.render()` can create a response within a layout.
|
|
234
|
+
*
|
|
235
|
+
* @see {@link https://hono.dev/api/context#render-setrenderer}
|
|
226
236
|
*
|
|
227
237
|
* @example
|
|
228
238
|
* ```ts
|
|
@@ -230,7 +240,6 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
230
240
|
* return c.render('Hello!')
|
|
231
241
|
* })
|
|
232
242
|
* ```
|
|
233
|
-
* @see https://hono.dev/api/context#render-setrenderer
|
|
234
243
|
*/
|
|
235
244
|
render: Renderer;
|
|
236
245
|
/**
|
|
@@ -254,6 +263,9 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
254
263
|
}> | undefined;
|
|
255
264
|
/**
|
|
256
265
|
* `.setRenderer()` can set the layout in the custom middleware.
|
|
266
|
+
*
|
|
267
|
+
* @see {@link https://hono.dev/api/context#render-setrenderer}
|
|
268
|
+
*
|
|
257
269
|
* @example
|
|
258
270
|
* ```tsx
|
|
259
271
|
* app.use('*', async (c, next) => {
|
|
@@ -269,11 +281,13 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
269
281
|
* await next()
|
|
270
282
|
* })
|
|
271
283
|
* ```
|
|
272
|
-
* @see https://hono.dev/api/context#render-setrenderer
|
|
273
284
|
*/
|
|
274
285
|
setRenderer: (renderer: Renderer) => void;
|
|
275
286
|
/**
|
|
276
287
|
* `.header()` can set headers.
|
|
288
|
+
*
|
|
289
|
+
* @see {@link https://hono.dev/api/context#body}
|
|
290
|
+
*
|
|
277
291
|
* @example
|
|
278
292
|
* ```ts
|
|
279
293
|
* app.get('/welcome', (c) => {
|
|
@@ -284,7 +298,6 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
284
298
|
* return c.body('Thank you for coming')
|
|
285
299
|
* })
|
|
286
300
|
* ```
|
|
287
|
-
* @see https://hono.dev/api/context#body
|
|
288
301
|
*/
|
|
289
302
|
header: (name: string, value: string | undefined, options?: {
|
|
290
303
|
append?: boolean;
|
|
@@ -292,6 +305,9 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
292
305
|
status: (status: StatusCode) => void;
|
|
293
306
|
/**
|
|
294
307
|
* `.set()` can set the value specified by the key.
|
|
308
|
+
*
|
|
309
|
+
* @see {@link https://hono.dev/api/context#set-get}
|
|
310
|
+
*
|
|
295
311
|
* @example
|
|
296
312
|
* ```ts
|
|
297
313
|
* app.use('*', async (c, next) => {
|
|
@@ -299,12 +315,14 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
299
315
|
* await next()
|
|
300
316
|
* })
|
|
301
317
|
* ```
|
|
302
|
-
* @see https://hono.dev/api/context#set-get
|
|
303
318
|
```
|
|
304
319
|
*/
|
|
305
320
|
set: Set<E>;
|
|
306
321
|
/**
|
|
307
322
|
* `.get()` can use the value specified by the key.
|
|
323
|
+
*
|
|
324
|
+
* @see {@link https://hono.dev/api/context#set-get}
|
|
325
|
+
*
|
|
308
326
|
* @example
|
|
309
327
|
* ```ts
|
|
310
328
|
* app.get('/', (c) => {
|
|
@@ -312,16 +330,17 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
312
330
|
* return c.text(`The message is "${message}"`)
|
|
313
331
|
* })
|
|
314
332
|
* ```
|
|
315
|
-
* @see https://hono.dev/api/context#set-get
|
|
316
333
|
*/
|
|
317
334
|
get: Get<E>;
|
|
318
335
|
/**
|
|
319
336
|
* `.var` can access the value of a variable.
|
|
337
|
+
*
|
|
338
|
+
* @see {@link https://hono.dev/api/context#var}
|
|
339
|
+
*
|
|
320
340
|
* @example
|
|
321
341
|
* ```ts
|
|
322
342
|
* const result = c.var.client.oneMethod()
|
|
323
343
|
* ```
|
|
324
|
-
* @see https://hono.dev/api/context#var
|
|
325
344
|
*/
|
|
326
345
|
get var(): Readonly<ContextVariableMap & (IsAny<E['Variables']> extends true ? Record<string, any> : E['Variables'])>;
|
|
327
346
|
newResponse: NewResponse;
|
|
@@ -329,6 +348,9 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
329
348
|
* `.body()` can return the HTTP response.
|
|
330
349
|
* You can set headers with `.header()` and set HTTP status code with `.status`.
|
|
331
350
|
* This can also be set in `.text()`, `.json()` and so on.
|
|
351
|
+
*
|
|
352
|
+
* @see {@link https://hono.dev/api/context#body}
|
|
353
|
+
*
|
|
332
354
|
* @example
|
|
333
355
|
* ```ts
|
|
334
356
|
* app.get('/welcome', (c) => {
|
|
@@ -342,34 +364,40 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
342
364
|
* return c.body('Thank you for coming')
|
|
343
365
|
* })
|
|
344
366
|
* ```
|
|
345
|
-
* @see https://hono.dev/api/context#body
|
|
346
367
|
*/
|
|
347
368
|
body: BodyRespond;
|
|
348
369
|
/**
|
|
349
370
|
* `.text()` can render text as `Content-Type:text/plain`.
|
|
371
|
+
*
|
|
372
|
+
* @see {@link https://hono.dev/api/context#text}
|
|
373
|
+
*
|
|
350
374
|
* @example
|
|
351
375
|
* ```ts
|
|
352
376
|
* app.get('/say', (c) => {
|
|
353
377
|
* return c.text('Hello!')
|
|
354
378
|
* })
|
|
355
379
|
* ```
|
|
356
|
-
* @see https://hono.dev/api/context#text
|
|
357
380
|
*/
|
|
358
381
|
text: TextRespond;
|
|
359
382
|
/**
|
|
360
383
|
* `.json()` can render JSON as `Content-Type:application/json`.
|
|
384
|
+
*
|
|
385
|
+
* @see {@link https://hono.dev/api/context#json}
|
|
386
|
+
*
|
|
361
387
|
* @example
|
|
362
388
|
* ```ts
|
|
363
389
|
* app.get('/api', (c) => {
|
|
364
390
|
* return c.json({ message: 'Hello!' })
|
|
365
391
|
* })
|
|
366
392
|
* ```
|
|
367
|
-
* @see https://hono.dev/api/context#json
|
|
368
393
|
*/
|
|
369
394
|
json: JSONRespond;
|
|
370
395
|
html: HTMLRespond;
|
|
371
396
|
/**
|
|
372
397
|
* `.redirect()` can Redirect, default status code is 302.
|
|
398
|
+
*
|
|
399
|
+
* @see {@link https://hono.dev/api/context#redirect}
|
|
400
|
+
*
|
|
373
401
|
* @example
|
|
374
402
|
* ```ts
|
|
375
403
|
* app.get('/redirect', (c) => {
|
|
@@ -379,18 +407,19 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
379
407
|
* return c.redirect('/', 301)
|
|
380
408
|
* })
|
|
381
409
|
* ```
|
|
382
|
-
* @see https://hono.dev/api/context#redirect
|
|
383
410
|
*/
|
|
384
|
-
redirect: (location: string, status?:
|
|
411
|
+
redirect: <T extends RedirectStatusCode = 302>(location: string, status?: T | undefined) => Response & TypedResponse<undefined, T, "redirect">;
|
|
385
412
|
/**
|
|
386
413
|
* `.notFound()` can return the Not Found Response.
|
|
414
|
+
*
|
|
415
|
+
* @see {@link https://hono.dev/api/context#notfound}
|
|
416
|
+
*
|
|
387
417
|
* @example
|
|
388
418
|
* ```ts
|
|
389
419
|
* app.get('/notfound', (c) => {
|
|
390
420
|
* return c.notFound()
|
|
391
421
|
* })
|
|
392
422
|
* ```
|
|
393
|
-
* @see https://hono.dev/api/context#notfound
|
|
394
423
|
*/
|
|
395
424
|
notFound: () => Response | Promise<Response>;
|
|
396
425
|
}
|
|
@@ -2,39 +2,4 @@
|
|
|
2
2
|
* @module
|
|
3
3
|
* ConnInfo Helper for Hono.
|
|
4
4
|
*/
|
|
5
|
-
|
|
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;
|
|
5
|
+
export type { AddressType, NetAddrInfo, ConnInfo, GetConnInfo } from './types';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Context } from '../../context';
|
|
2
|
+
export type AddressType = 'IPv6' | 'IPv4' | 'unknown';
|
|
3
|
+
export type NetAddrInfo = {
|
|
4
|
+
/**
|
|
5
|
+
* Transport protocol type
|
|
6
|
+
*/
|
|
7
|
+
transport?: 'tcp' | 'udp';
|
|
8
|
+
/**
|
|
9
|
+
* Transport port number
|
|
10
|
+
*/
|
|
11
|
+
port?: number;
|
|
12
|
+
address?: string;
|
|
13
|
+
addressType?: AddressType;
|
|
14
|
+
} & ({
|
|
15
|
+
/**
|
|
16
|
+
* Host name such as IP Addr
|
|
17
|
+
*/
|
|
18
|
+
address: string;
|
|
19
|
+
/**
|
|
20
|
+
* Host name type
|
|
21
|
+
*/
|
|
22
|
+
addressType: AddressType;
|
|
23
|
+
} | {});
|
|
24
|
+
/**
|
|
25
|
+
* HTTP Connection infomation
|
|
26
|
+
*/
|
|
27
|
+
export interface ConnInfo {
|
|
28
|
+
/**
|
|
29
|
+
* Remote infomation
|
|
30
|
+
*/
|
|
31
|
+
remote: NetAddrInfo;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Helper type
|
|
35
|
+
*/
|
|
36
|
+
export type GetConnInfo = (c: Context) => ConnInfo;
|
|
@@ -16,20 +16,28 @@ type GetPath<E extends Env> = (request: Request, options?: {
|
|
|
16
16
|
export type HonoOptions<E extends Env> = {
|
|
17
17
|
/**
|
|
18
18
|
* `strict` option specifies whether to distinguish whether the last path is a directory or not.
|
|
19
|
+
*
|
|
20
|
+
* @see {@link https://hono.dev/api/hono#strict-mode}
|
|
21
|
+
*
|
|
19
22
|
* @default true
|
|
20
|
-
* @see https://hono.dev/api/hono#strict-mode
|
|
21
23
|
*/
|
|
22
24
|
strict?: boolean;
|
|
23
25
|
/**
|
|
24
26
|
* `router` option specifices which router to use.
|
|
27
|
+
*
|
|
28
|
+
* @see {@link https://hono.dev/api/hono#router-option}
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
25
31
|
* ```ts
|
|
26
32
|
* const app = new Hono({ router: new RegExpRouter() })
|
|
27
33
|
* ```
|
|
28
|
-
* @see https://hono.dev/api/hono#router-option
|
|
29
34
|
*/
|
|
30
35
|
router?: Router<[H, RouterRoute]>;
|
|
31
36
|
/**
|
|
32
37
|
* `getPath` can handle the host header value.
|
|
38
|
+
*
|
|
39
|
+
* @see {@link https://hono.dev/api/routing#routing-with-host-header-value}
|
|
40
|
+
*
|
|
33
41
|
* @example
|
|
34
42
|
* ```ts
|
|
35
43
|
* const app = new Hono({
|
|
@@ -44,10 +52,15 @@ export type HonoOptions<E extends Env> = {
|
|
|
44
52
|
* // headers: { host: 'www1.example.com' },
|
|
45
53
|
* // })
|
|
46
54
|
* ```
|
|
47
|
-
* @see https://hono.dev/api/routing#routing-with-host-header-value
|
|
48
55
|
*/
|
|
49
56
|
getPath?: GetPath<E>;
|
|
50
57
|
};
|
|
58
|
+
type MountOptionHandler = (c: Context) => unknown;
|
|
59
|
+
type MountReplaceRequest = (originalRequest: Request) => Request;
|
|
60
|
+
type MountOptions = MountOptionHandler | {
|
|
61
|
+
optionHandler?: MountOptionHandler;
|
|
62
|
+
replaceRequest?: MountReplaceRequest;
|
|
63
|
+
};
|
|
51
64
|
declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'> {
|
|
52
65
|
#private;
|
|
53
66
|
get: HandlerInterface<E, 'get', S, BasePath>;
|
|
@@ -67,18 +80,48 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
|
|
|
67
80
|
private clone;
|
|
68
81
|
private notFoundHandler;
|
|
69
82
|
private errorHandler;
|
|
83
|
+
/**
|
|
84
|
+
* `.route()` allows grouping other Hono instance in routes.
|
|
85
|
+
*
|
|
86
|
+
* @see {@link https://hono.dev/api/routing#grouping}
|
|
87
|
+
*
|
|
88
|
+
* @param {string} path - base Path
|
|
89
|
+
* @param {Hono} app - other Hono instance
|
|
90
|
+
* @returns {Hono} routed Hono instnace
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* const app = new Hono()
|
|
95
|
+
* const app2 = new Hono()
|
|
96
|
+
*
|
|
97
|
+
* app2.get("/user", (c) => c.text("user"))
|
|
98
|
+
* app.route("/api", app2) // GET /api/user
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
70
101
|
route<SubPath extends string, SubEnv extends Env, SubSchema extends Schema, SubBasePath extends string>(path: SubPath, app?: Hono<SubEnv, SubSchema, SubBasePath>): Hono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath>;
|
|
71
102
|
/**
|
|
72
103
|
* `.basePath()` allows base paths to be specified.
|
|
104
|
+
*
|
|
105
|
+
* @see {@link https://hono.dev/api/routing#base-path}
|
|
106
|
+
*
|
|
107
|
+
* @param {string} path - base Path
|
|
108
|
+
* @returns {Hono} changed Hono instance
|
|
109
|
+
*
|
|
73
110
|
* @example
|
|
74
111
|
* ```ts
|
|
75
112
|
* const api = new Hono().basePath('/api')
|
|
76
113
|
* ```
|
|
77
|
-
* @see https://hono.dev/api/routing#base-path
|
|
78
114
|
*/
|
|
79
115
|
basePath<SubPath extends string>(path: SubPath): Hono<E, S, MergePath<BasePath, SubPath>>;
|
|
80
116
|
/**
|
|
81
117
|
* `.onError()` handles an error and returns a customized Response.
|
|
118
|
+
*
|
|
119
|
+
* @see {@link https://hono.dev/api/hono#error-handling}
|
|
120
|
+
*
|
|
121
|
+
* @param {ErrorHandler} handler - request Handler for error
|
|
122
|
+
* @returns {Hono} changed Hono instance
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
82
125
|
* ```ts
|
|
83
126
|
* app.onError((err, c) => {
|
|
84
127
|
* console.error(`${err}`)
|
|
@@ -89,39 +132,67 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
|
|
|
89
132
|
onError: (handler: ErrorHandler<E>) => Hono<E, S, BasePath>;
|
|
90
133
|
/**
|
|
91
134
|
* `.notFound()` allows you to customize a Not Found Response.
|
|
135
|
+
*
|
|
136
|
+
* @see {@link https://hono.dev/api/hono#not-found}
|
|
137
|
+
*
|
|
138
|
+
* @param {NotFoundHandler} handler - request handler for not-found
|
|
139
|
+
* @returns {Hono} changed Hono instance
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
92
142
|
* ```ts
|
|
93
143
|
* app.notFound((c) => {
|
|
94
144
|
* return c.text('Custom 404 Message', 404)
|
|
95
145
|
* })
|
|
96
146
|
* ```
|
|
97
|
-
* @see https://hono.dev/api/hono#not-found
|
|
98
147
|
*/
|
|
99
148
|
notFound: (handler: NotFoundHandler<E>) => Hono<E, S, BasePath>;
|
|
100
149
|
/**
|
|
101
|
-
*
|
|
150
|
+
* `.mount()` allows you to mount applications built with other frameworks into your Hono application.
|
|
102
151
|
*
|
|
103
|
-
* @
|
|
104
|
-
* @param applicationHandler - The external application handler function that processes requests.
|
|
105
|
-
* @param optionHandler - Optional function to handle additional options, such as environment variables and execution context.
|
|
152
|
+
* @see {@link https://hono.dev/api/hono#mount}
|
|
106
153
|
*
|
|
107
|
-
* @
|
|
154
|
+
* @param {string} path - base Path
|
|
155
|
+
* @param {Function} applicationHandler - other Request Handler
|
|
156
|
+
* @param {MountOptions} [options] - options of `.mount()`
|
|
157
|
+
* @returns {Hono} mounted Hono instance
|
|
108
158
|
*
|
|
109
159
|
* @example
|
|
110
160
|
* ```ts
|
|
161
|
+
* import { Router as IttyRouter } from 'itty-router'
|
|
162
|
+
* import { Hono } from 'hono'
|
|
163
|
+
* // Create itty-router application
|
|
164
|
+
* const ittyRouter = IttyRouter()
|
|
165
|
+
* // GET /itty-router/hello
|
|
166
|
+
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
|
167
|
+
*
|
|
111
168
|
* const app = new Hono()
|
|
112
|
-
*
|
|
113
|
-
*
|
|
169
|
+
* app.mount('/itty-router', ittyRouter.handle)
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const app = new Hono()
|
|
175
|
+
* // Send the request to another application without modification.
|
|
176
|
+
* app.mount('/app', anotherApp, {
|
|
177
|
+
* replaceRequest: (req) => req,
|
|
178
|
+
* })
|
|
114
179
|
* ```
|
|
115
|
-
* @see https://hono.dev/api/hono#mount
|
|
116
180
|
*/
|
|
117
|
-
mount(path: string, applicationHandler: (request: Request, ...args: any) => Response | Promise<Response>,
|
|
181
|
+
mount(path: string, applicationHandler: (request: Request, ...args: any) => Response | Promise<Response>, options?: MountOptions): Hono<E, S, BasePath>;
|
|
118
182
|
private addRoute;
|
|
119
183
|
private matchRoute;
|
|
120
184
|
private handleError;
|
|
121
185
|
private dispatch;
|
|
122
186
|
/**
|
|
123
187
|
* `.fetch()` will be entry point of your app.
|
|
124
|
-
*
|
|
188
|
+
*
|
|
189
|
+
* @see {@link https://hono.dev/api/hono#fetch}
|
|
190
|
+
*
|
|
191
|
+
* @param {Request} request - reuqest Object of request
|
|
192
|
+
* @param {Env} Env - env Object
|
|
193
|
+
* @param {ExecutionContext} - context of execution
|
|
194
|
+
* @returns {Response | Promise<Response>} response of request
|
|
195
|
+
*
|
|
125
196
|
*/
|
|
126
197
|
fetch: (request: Request, Env?: E['Bindings'] | {}, executionCtx?: ExecutionContext) => Response | Promise<Response>;
|
|
127
198
|
/**
|
|
@@ -16,6 +16,15 @@ type HTTPExceptionOptions = {
|
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
18
18
|
* `HTTPException` must be used when a fatal error such as authentication failure occurs.
|
|
19
|
+
*
|
|
20
|
+
* @see {@link https://hono.dev/api/exception}
|
|
21
|
+
*
|
|
22
|
+
* @param {StatusCode} status - status code of HTTPException
|
|
23
|
+
* @param {HTTPExceptionOptions} options - options of HTTPException
|
|
24
|
+
* @param {HTTPExceptionOptions["res"]} options.res - response of options of HTTPException
|
|
25
|
+
* @param {HTTPExceptionOptions["message"]} options.message - message of options of HTTPException
|
|
26
|
+
* @param {HTTPExceptionOptions["cause"]} options.cause - cause of options of HTTPException
|
|
27
|
+
*
|
|
19
28
|
* @example
|
|
20
29
|
* ```ts
|
|
21
30
|
* import { HTTPException } from 'hono/http-exception'
|
|
@@ -30,7 +39,6 @@ type HTTPExceptionOptions = {
|
|
|
30
39
|
* await next()
|
|
31
40
|
* })
|
|
32
41
|
* ```
|
|
33
|
-
* @see https://hono.dev/api/exception
|
|
34
42
|
*/
|
|
35
43
|
export declare class HTTPException extends Error {
|
|
36
44
|
readonly res?: Response;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes intrinsic element properties by converting JSX element properties
|
|
3
|
+
* to their corresponding HTML attributes.
|
|
4
|
+
*
|
|
5
|
+
* @param props - JSX element properties.
|
|
6
|
+
*/
|
|
1
7
|
export declare const normalizeIntrinsicElementProps: (props: Record<string, unknown>) => void;
|
|
2
8
|
export declare const styleObjectForEach: (style: Record<string, string | number>, fn: (key: string, value: string | null) => void) => void;
|