@jderstd/hono 0.7.1 → 0.8.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.
- package/README.md +3 -1
- package/dist/body-limit.d.ts +54 -54
- package/dist/ip-limit.d.ts +74 -74
- package/dist/not-found.d.ts +28 -28
- package/dist/on-error.d.ts +55 -55
- package/dist/response/common/index.d.ts +67 -67
- package/dist/response/common/index.js +2 -2
- package/dist/response/common/index.js.map +1 -1
- package/dist/response/error/index.d.ts +32 -32
- package/dist/response/json/index.d.ts +95 -95
- package/dist/response/json/index.js +2 -2
- package/dist/response/json/index.js.map +1 -1
- package/dist/response.d.ts +2 -2
- package/dist/time-limit.d.ts +50 -50
- package/package.json +3 -3
package/README.md
CHANGED
package/dist/body-limit.d.ts
CHANGED
|
@@ -4,63 +4,63 @@ declare const BODY_LIMIT_MAX_DEFAULT: 10485760;
|
|
|
4
4
|
/** Options for `bodyLimit` middleware. */
|
|
5
5
|
type BodyLimitOptions = {
|
|
6
6
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
* Maximum body size in bytes.
|
|
8
|
+
*
|
|
9
|
+
* By default, it is `BODY_LIMIT_MAX_DEFAULT`.
|
|
10
|
+
*/
|
|
11
11
|
max?: number;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
14
|
+
* Body limit middleware.
|
|
15
|
+
*
|
|
16
|
+
* Following error will be returned if the body size is over the limit:
|
|
17
|
+
*
|
|
18
|
+
* ```jsonc
|
|
19
|
+
* // Status: 413
|
|
20
|
+
* {
|
|
21
|
+
* "success": false,
|
|
22
|
+
* "errors": [
|
|
23
|
+
* {
|
|
24
|
+
* "code": "too_large",
|
|
25
|
+
* "path": [
|
|
26
|
+
* "request",
|
|
27
|
+
* "body"
|
|
28
|
+
* ],
|
|
29
|
+
* "message": "Request body is too large"
|
|
30
|
+
* }
|
|
31
|
+
* ]
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* For more information, please refer to
|
|
36
|
+
* [Body Limit](https://hono.dev/docs/middleware/builtin/body-limit).
|
|
37
|
+
*
|
|
38
|
+
* ### Examples
|
|
39
|
+
*
|
|
40
|
+
* A example of using `bodyLimit` middleware:
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { Hono } from "hono";
|
|
44
|
+
* import { bodyLimit } from "@jderstd/hono/body-limit";
|
|
45
|
+
*
|
|
46
|
+
* const app: Hono = new Hono();
|
|
47
|
+
*
|
|
48
|
+
* app.use(bodyLimit());
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* A example of using `bodyLimit` middleware with options:
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { Hono } from "hono";
|
|
55
|
+
* import { bodyLimit } from "@jderstd/hono/body-limit";
|
|
56
|
+
*
|
|
57
|
+
* const app: Hono = new Hono();
|
|
58
|
+
*
|
|
59
|
+
* app.use(bodyLimit({
|
|
60
|
+
* max: 20 * 1024 * 1024, // 20MiB
|
|
61
|
+
* }));
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
64
|
declare const bodyLimit: (options?: BodyLimitOptions) => MiddlewareHandler;
|
|
65
65
|
export { BODY_LIMIT_MAX_DEFAULT, type BodyLimitOptions, bodyLimit };
|
|
66
66
|
//# sourceMappingURL=body-limit.d.ts.map
|
package/dist/ip-limit.d.ts
CHANGED
|
@@ -10,9 +10,9 @@ type IpLimitBaseOptions = {
|
|
|
10
10
|
/** Denied IP addresses. */
|
|
11
11
|
denyList?: IPRestrictionRule[];
|
|
12
12
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
* Whether show more information.
|
|
14
|
+
* By default, it's `false`.
|
|
15
|
+
*/
|
|
16
16
|
verbose?: boolean;
|
|
17
17
|
};
|
|
18
18
|
/** Options for `ipLimit` middleware. */
|
|
@@ -21,79 +21,79 @@ type IpLimitOptions = Format<{
|
|
|
21
21
|
getConnInfo: GetIPAddr;
|
|
22
22
|
} & IpLimitBaseOptions>;
|
|
23
23
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
24
|
+
* IP limit middleware.
|
|
25
|
+
*
|
|
26
|
+
* Following error will be returned if the IP address is not allowed:
|
|
27
|
+
*
|
|
28
|
+
* ```jsonc
|
|
29
|
+
* // Status: 403
|
|
30
|
+
* {
|
|
31
|
+
* "success": false,
|
|
32
|
+
* "errors": [
|
|
33
|
+
* {
|
|
34
|
+
* "code": "forbidden"
|
|
35
|
+
* }
|
|
36
|
+
* ]
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* When `verbose` is `true`, the error will be like:
|
|
41
|
+
*
|
|
42
|
+
* ```jsonc
|
|
43
|
+
* // Status: 403
|
|
44
|
+
* {
|
|
45
|
+
* "success": false,
|
|
46
|
+
* "errors": [
|
|
47
|
+
* {
|
|
48
|
+
* "code": "forbidden",
|
|
49
|
+
* "path": [
|
|
50
|
+
* "request",
|
|
51
|
+
* "ip"
|
|
52
|
+
* ],
|
|
53
|
+
* "message": "Forbidden IP address: x.x.x.x"
|
|
54
|
+
* }
|
|
55
|
+
* ]
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* For more information, please refer to
|
|
60
|
+
* [IP Restriction](https://hono.dev/docs/middleware/builtin/ip-restriction).
|
|
61
|
+
*
|
|
62
|
+
* For `getConnInfo`, please refer to
|
|
63
|
+
* [ConnInfo helper](https://hono.dev/docs/helpers/conninfo).
|
|
64
|
+
*
|
|
65
|
+
* ### Example
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { Hono } from "hono";
|
|
69
|
+
* import { ipLimit } from "@jderstd/hono/ip-limit";
|
|
70
|
+
*
|
|
71
|
+
* // getConnInfo helper for Node.js
|
|
72
|
+
* import { getConnInfo } from "@hono/node-server/conninfo";
|
|
73
|
+
*
|
|
74
|
+
* const app: Hono = new Hono();
|
|
75
|
+
*
|
|
76
|
+
* app.use(
|
|
77
|
+
* ipLimit({
|
|
78
|
+
* getConnInfo,
|
|
79
|
+
* allowList: [],
|
|
80
|
+
* denyList: [],
|
|
81
|
+
* })
|
|
82
|
+
* );
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
85
|
declare function ipLimit(options: IpLimitOptions): MiddlewareHandler;
|
|
86
86
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
* IP limit middleware for compatibility with `hono/ip-restriction`.
|
|
88
|
+
*
|
|
89
|
+
* This is functionally equivalent to:
|
|
90
|
+
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* ipLimit({ getConnInfo, ...options });
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* And it behaves the same as the main `ipLimit` function.
|
|
96
|
+
*/
|
|
97
97
|
declare function ipLimit(getConnInfo: GetIPAddr, options?: IpLimitBaseOptions): MiddlewareHandler;
|
|
98
98
|
export { type AddressType, type ConnInfo, type GetConnInfo, type GetIPAddr, type IPRestrictionRule, type IpLimitBaseOptions, type IpLimitOptions, type NetAddrInfo, ipLimit };
|
|
99
99
|
//# sourceMappingURL=ip-limit.d.ts.map
|
package/dist/not-found.d.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import { Context } from "hono";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
3
|
+
* Not found handler.
|
|
4
|
+
*
|
|
5
|
+
* Following response will be returned on route not found:
|
|
6
|
+
*
|
|
7
|
+
* ```jsonc
|
|
8
|
+
* // Status: 404
|
|
9
|
+
* {
|
|
10
|
+
* "success": false,
|
|
11
|
+
* "errors": [
|
|
12
|
+
* {
|
|
13
|
+
* "code": "not_found",
|
|
14
|
+
* "message": "Content not found"
|
|
15
|
+
* }
|
|
16
|
+
* ]
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* ### Example
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { Hono } from "hono";
|
|
24
|
+
* import { notFoundHandler } from "@jderstd/hono/not-found";
|
|
25
|
+
*
|
|
26
|
+
* const app: Hono = new Hono();
|
|
27
|
+
*
|
|
28
|
+
* app.notFound(notFoundHandler());
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
31
|
declare const notFoundHandler: () => ((c: Context) => Response);
|
|
32
32
|
export { notFoundHandler };
|
|
33
33
|
//# sourceMappingURL=not-found.d.ts.map
|
package/dist/on-error.d.ts
CHANGED
|
@@ -3,64 +3,64 @@ import { HTTPResponseError } from "hono/types";
|
|
|
3
3
|
/** Options for `onErrorHandler` function. */
|
|
4
4
|
type OnErrorHandlerOptions = {
|
|
5
5
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
* Whether show more information.
|
|
7
|
+
* By default, it's `false`.
|
|
8
|
+
*/
|
|
9
9
|
verbose?: boolean;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
12
|
+
* On error handler.
|
|
13
|
+
*
|
|
14
|
+
* Following responses could be returned on error:
|
|
15
|
+
*
|
|
16
|
+
* ```jsonc
|
|
17
|
+
* // Status: 400
|
|
18
|
+
* {
|
|
19
|
+
* "success": false,
|
|
20
|
+
* "errors": [
|
|
21
|
+
* {
|
|
22
|
+
* "code": "bad_request"
|
|
23
|
+
* }
|
|
24
|
+
* ]
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* ```jsonc
|
|
29
|
+
* // Status: 500
|
|
30
|
+
* {
|
|
31
|
+
* "success": false,
|
|
32
|
+
* "errors": [
|
|
33
|
+
* {
|
|
34
|
+
* "code": "server"
|
|
35
|
+
* }
|
|
36
|
+
* ]
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* ### Examples
|
|
41
|
+
*
|
|
42
|
+
* Basic example of using `onErrorHandler` handler:
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { Hono } from "hono";
|
|
46
|
+
* import { onErrorHandler } from "@jderstd/hono/on-error";
|
|
47
|
+
*
|
|
48
|
+
* const app: Hono = new Hono();
|
|
49
|
+
*
|
|
50
|
+
* app.onError(onErrorHandler());
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* Show more information with `verbose` option:
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { Hono } from "hono";
|
|
57
|
+
* import { onErrorHandler } from "@jderstd/hono/on-error";
|
|
58
|
+
*
|
|
59
|
+
* const app: Hono = new Hono();
|
|
60
|
+
*
|
|
61
|
+
* app.onError(onErrorHandler({ verbose: true }));
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
64
|
declare const onErrorHandler: (options?: OnErrorHandlerOptions) => ((err: Error | HTTPResponseError, c: Context) => Response);
|
|
65
65
|
export { onErrorHandler };
|
|
66
66
|
//# sourceMappingURL=on-error.d.ts.map
|
|
@@ -5,78 +5,78 @@ import { StatusCode } from "hono/utils/http-status";
|
|
|
5
5
|
/** Options of `createResponse` function. */
|
|
6
6
|
type CreateResponseOptions<B extends BodyInit = BodyInit> = Format<{
|
|
7
7
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
* Status code of the response.
|
|
9
|
+
* By default, it is `200` for success and `400` for failure.
|
|
10
|
+
*/
|
|
11
11
|
status?: StatusCode;
|
|
12
12
|
} & Omit<CreateResponseStructOptions<B>, "status">>;
|
|
13
13
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
14
|
+
* Create a response.
|
|
15
|
+
*
|
|
16
|
+
* ### Examples
|
|
17
|
+
*
|
|
18
|
+
* Example for creating a basic response:
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { createResponse } from "@jderstd/hono/response";
|
|
22
|
+
*
|
|
23
|
+
* const route = (): Response => {
|
|
24
|
+
* return createResponse();
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Example for creating a response with status, headers, and body:
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { createResponse } from "@jderstd/hono/response";
|
|
32
|
+
*
|
|
33
|
+
* const route = (): Response => {
|
|
34
|
+
* return createResponse({
|
|
35
|
+
* status: 404,
|
|
36
|
+
* headers: [
|
|
37
|
+
* ["Content-Type", "text/plain"],
|
|
38
|
+
* ],
|
|
39
|
+
* body: "Not Found",
|
|
40
|
+
* });
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
44
|
declare function createResponse<B extends BodyInit = BodyInit>(options?: CreateResponseOptions<B>): Response;
|
|
45
45
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
46
|
+
* Create a response with context.
|
|
47
|
+
*
|
|
48
|
+
* ### Examples
|
|
49
|
+
*
|
|
50
|
+
* Example for creating a basic response:
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* import type { Context } from "hono";
|
|
54
|
+
*
|
|
55
|
+
* import { createResponse } from "@jderstd/hono/response";
|
|
56
|
+
*
|
|
57
|
+
* const route = (c: Context): Response => {
|
|
58
|
+
* return createResponse(c);
|
|
59
|
+
* };
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* Example for creating a response with status, headers, and body:
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* import type { Context } from "hono";
|
|
66
|
+
*
|
|
67
|
+
* import { createResponse } from "@jderstd/hono/response";
|
|
68
|
+
*
|
|
69
|
+
* const route = (c: Context): Response => {
|
|
70
|
+
* return createResponse(c, {
|
|
71
|
+
* status: 404,
|
|
72
|
+
* headers: [
|
|
73
|
+
* ["Content-Type", "text/plain"],
|
|
74
|
+
* ],
|
|
75
|
+
* body: "Not Found",
|
|
76
|
+
* });
|
|
77
|
+
* };
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
80
|
declare function createResponse<B extends BodyInit = BodyInit>(context?: Context, options?: CreateResponseOptions<B>): Response;
|
|
81
81
|
export { type CreateResponseOptions, createResponse };
|
|
82
82
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_index = require('../json/index.js');
|
|
2
|
-
let
|
|
2
|
+
let _jderstd_core_response_common_struct = require("@jderstd/core/response/common/struct");
|
|
3
3
|
|
|
4
4
|
function createResponse(contextOrOptions, options) {
|
|
5
|
-
const { status, headers, body } = require_index.isContext(contextOrOptions) ? (0,
|
|
5
|
+
const { status, headers, body } = require_index.isContext(contextOrOptions) ? (0, _jderstd_core_response_common_struct.createResponseStruct)(options) : (0, _jderstd_core_response_common_struct.createResponseStruct)(contextOrOptions);
|
|
6
6
|
if (require_index.isContext(contextOrOptions)) {
|
|
7
7
|
const c = contextOrOptions;
|
|
8
8
|
c.status(status);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["isContext","c: Context"],"sources":["../../../src/response/common/index.ts"],"sourcesContent":["import type { CreateResponseStructOptions } from \"@jderstd/core/response/common/struct\";\nimport type { Context } from \"hono\";\nimport type { StatusCode } from \"hono/utils/http-status\";\nimport type { Format, Omit } from \"ts-vista\";\n\nimport { createResponseStruct } from \"@jderstd/core/response/common/struct\";\n\nimport { isContext } from \"#/response/json\";\n\n/** Options of `createResponse` function. */\ntype CreateResponseOptions<B extends BodyInit = BodyInit> = Format<\n {\n /**\n * Status code of the response.\n * By default, it is `200` for success and `400` for failure.\n */\n status?: StatusCode;\n } & Omit<CreateResponseStructOptions<B>, \"status\">\n>;\n\n/**\n * Create a response.\n *\n * ### Examples\n *\n * Example for creating a basic response:\n *\n * ```ts\n * import { createResponse } from \"@jderstd/hono/response\";\n *\n * const route = (): Response => {\n * return createResponse();\n * };\n * ```\n *\n * Example for creating a response with status, headers, and body:\n *\n * ```ts\n * import { createResponse } from \"@jderstd/hono/response\";\n *\n * const route = (): Response => {\n * return createResponse({\n * status: 404,\n * headers: [\n * [\"Content-Type\", \"text/plain\"],\n * ],\n * body: \"Not Found\",\n * });\n * };\n * ```\n */\nfunction createResponse<B extends BodyInit = BodyInit>(\n options?: CreateResponseOptions<B>,\n): Response;\n\n/**\n * Create a response with context.\n *\n * ### Examples\n *\n * Example for creating a basic response:\n *\n * ```ts\n * import type { Context } from \"hono\";\n *\n * import { createResponse } from \"@jderstd/hono/response\";\n *\n * const route = (c: Context): Response => {\n * return createResponse(c);\n * };\n * ```\n *\n * Example for creating a response with status, headers, and body:\n *\n * ```ts\n * import type { Context } from \"hono\";\n *\n * import { createResponse } from \"@jderstd/hono/response\";\n *\n * const route = (c: Context): Response => {\n * return createResponse(c, {\n * status: 404,\n * headers: [\n * [\"Content-Type\", \"text/plain\"],\n * ],\n * body: \"Not Found\",\n * });\n * };\n * ```\n */\nfunction createResponse<B extends BodyInit = BodyInit>(\n context?: Context,\n options?: CreateResponseOptions<B>,\n): Response;\n\nfunction createResponse<B extends BodyInit = BodyInit>(\n contextOrOptions?: Context | CreateResponseOptions<B>,\n options?: CreateResponseOptions<B>,\n): Response {\n const { status, headers, body } = isContext(contextOrOptions)\n ? createResponseStruct(options)\n : createResponseStruct(contextOrOptions);\n\n if (isContext(contextOrOptions)) {\n const c: Context = contextOrOptions;\n\n c.status(status as StatusCode);\n\n for (const [key, value] of headers) c.header(key, value);\n\n return body\n ? c.body(body as string | ArrayBuffer | ReadableStream)\n : c.body(null);\n }\n\n return new Response(body, {\n status,\n headers,\n });\n}\n\nexport type { CreateResponseOptions };\nexport { createResponse };\n"],"mappings":";;;AA+FA,SAAS,eACL,kBACA,SACQ;CACR,MAAM,EAAE,QAAQ,SAAS,SAASA,wBAAU,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.js","names":["isContext","c: Context"],"sources":["../../../src/response/common/index.ts"],"sourcesContent":["import type { CreateResponseStructOptions } from \"@jderstd/core/response/common/struct\";\nimport type { Context } from \"hono\";\nimport type { StatusCode } from \"hono/utils/http-status\";\nimport type { Format, Omit } from \"ts-vista\";\n\nimport { createResponseStruct } from \"@jderstd/core/response/common/struct\";\n\nimport { isContext } from \"#/response/json\";\n\n/** Options of `createResponse` function. */\ntype CreateResponseOptions<B extends BodyInit = BodyInit> = Format<\n {\n /**\n * Status code of the response.\n * By default, it is `200` for success and `400` for failure.\n */\n status?: StatusCode;\n } & Omit<CreateResponseStructOptions<B>, \"status\">\n>;\n\n/**\n * Create a response.\n *\n * ### Examples\n *\n * Example for creating a basic response:\n *\n * ```ts\n * import { createResponse } from \"@jderstd/hono/response\";\n *\n * const route = (): Response => {\n * return createResponse();\n * };\n * ```\n *\n * Example for creating a response with status, headers, and body:\n *\n * ```ts\n * import { createResponse } from \"@jderstd/hono/response\";\n *\n * const route = (): Response => {\n * return createResponse({\n * status: 404,\n * headers: [\n * [\"Content-Type\", \"text/plain\"],\n * ],\n * body: \"Not Found\",\n * });\n * };\n * ```\n */\nfunction createResponse<B extends BodyInit = BodyInit>(\n options?: CreateResponseOptions<B>,\n): Response;\n\n/**\n * Create a response with context.\n *\n * ### Examples\n *\n * Example for creating a basic response:\n *\n * ```ts\n * import type { Context } from \"hono\";\n *\n * import { createResponse } from \"@jderstd/hono/response\";\n *\n * const route = (c: Context): Response => {\n * return createResponse(c);\n * };\n * ```\n *\n * Example for creating a response with status, headers, and body:\n *\n * ```ts\n * import type { Context } from \"hono\";\n *\n * import { createResponse } from \"@jderstd/hono/response\";\n *\n * const route = (c: Context): Response => {\n * return createResponse(c, {\n * status: 404,\n * headers: [\n * [\"Content-Type\", \"text/plain\"],\n * ],\n * body: \"Not Found\",\n * });\n * };\n * ```\n */\nfunction createResponse<B extends BodyInit = BodyInit>(\n context?: Context,\n options?: CreateResponseOptions<B>,\n): Response;\n\nfunction createResponse<B extends BodyInit = BodyInit>(\n contextOrOptions?: Context | CreateResponseOptions<B>,\n options?: CreateResponseOptions<B>,\n): Response {\n const { status, headers, body } = isContext(contextOrOptions)\n ? createResponseStruct(options)\n : createResponseStruct(contextOrOptions);\n\n if (isContext(contextOrOptions)) {\n const c: Context = contextOrOptions;\n\n c.status(status as StatusCode);\n\n for (const [key, value] of headers) c.header(key, value);\n\n return body\n ? c.body(body as string | ArrayBuffer | ReadableStream)\n : c.body(null);\n }\n\n return new Response(body, {\n status,\n headers,\n });\n}\n\nexport type { CreateResponseOptions };\nexport { createResponse };\n"],"mappings":";;;AA+FA,SAAS,eACL,kBACA,SACQ;CACR,MAAM,EAAE,QAAQ,SAAS,SAASA,wBAAU,iBAAiB,kEAClC,QAAQ,kEACR,iBAAiB;AAE5C,KAAIA,wBAAU,iBAAiB,EAAE;EAC7B,MAAMC,IAAa;AAEnB,IAAE,OAAO,OAAqB;AAE9B,OAAK,MAAM,CAAC,KAAK,UAAU,QAAS,GAAE,OAAO,KAAK,MAAM;AAExD,SAAO,OACD,EAAE,KAAK,KAA8C,GACrD,EAAE,KAAK,KAAK;;AAGtB,QAAO,IAAI,SAAS,MAAM;EACtB;EACA;EACH,CAAC"}
|
|
@@ -1,53 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
* Response error code.
|
|
3
|
+
*/
|
|
4
4
|
declare enum ResponseErrorCode {
|
|
5
5
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
* Request body is too large.
|
|
7
|
+
*
|
|
8
|
+
* For `bodyLimit` middleware.
|
|
9
|
+
*/
|
|
10
10
|
TooLarge = "too_large",
|
|
11
11
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
* Forbidden access.
|
|
13
|
+
*
|
|
14
|
+
* For `ipLimit` middleware.
|
|
15
|
+
*/
|
|
16
16
|
Forbidden = "forbidden",
|
|
17
17
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
* Request timeout.
|
|
19
|
+
*
|
|
20
|
+
* For `timeLimit` middleware.
|
|
21
|
+
*/
|
|
22
22
|
Timeout = "timeout",
|
|
23
23
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
* Content not found.
|
|
25
|
+
*
|
|
26
|
+
* For `notFoundHandler` function.
|
|
27
|
+
*/
|
|
28
28
|
NotFound = "not_found",
|
|
29
29
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
* Bad request.
|
|
31
|
+
*
|
|
32
|
+
* For `onErrorHandler` function.
|
|
33
|
+
*/
|
|
34
34
|
BadRequest = "bad_request",
|
|
35
35
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
* Internal server error.
|
|
37
|
+
*
|
|
38
|
+
* For `onErrorHandler` function.
|
|
39
|
+
*/
|
|
40
40
|
Server = "server",
|
|
41
41
|
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
* Validation error.
|
|
43
|
+
*
|
|
44
|
+
* For validator package.
|
|
45
|
+
*/
|
|
46
46
|
Parse = "parse",
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
* Get response error message by code.
|
|
50
|
+
*/
|
|
51
51
|
declare const getResponseErrorMessage: (code: ResponseErrorCode) => string;
|
|
52
52
|
export { ResponseErrorCode, getResponseErrorMessage };
|
|
53
53
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -5,106 +5,106 @@ import { CreateJsonResponseStructOptions } from "@jderstd/core/response/json/str
|
|
|
5
5
|
/** Options of `createJsonResponse` function. */
|
|
6
6
|
type CreateJsonResponseOptions<D = unknown> = Format<{
|
|
7
7
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
* Status code of the response.
|
|
9
|
+
* By default, it is `200` for success and `400` for failure.
|
|
10
|
+
*/
|
|
11
11
|
status?: StatusCode;
|
|
12
12
|
} & Omit<CreateJsonResponseStructOptions<D>, "status">>;
|
|
13
13
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
14
|
+
* Create a JSON response.
|
|
15
|
+
*
|
|
16
|
+
* ### Examples
|
|
17
|
+
*
|
|
18
|
+
* Example for creating a successful JSON response without data:
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { createJsonResponse } from "@jderstd/hono/response";
|
|
22
|
+
*
|
|
23
|
+
* const route = (): Response => {
|
|
24
|
+
* return createJsonResponse();
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Example for creating a successful JSON response with data:
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { createJsonResponse } from "@jderstd/hono/response";
|
|
32
|
+
*
|
|
33
|
+
* const route = (): Response => {
|
|
34
|
+
* return createJsonResponse({
|
|
35
|
+
* data: "Hello, World!",
|
|
36
|
+
* });
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* Example for creating a failed JSON response:
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { createJsonResponse } from "@jderstd/hono/response";
|
|
44
|
+
*
|
|
45
|
+
* const route = (): Response => {
|
|
46
|
+
* return createJsonResponse({
|
|
47
|
+
* errors: [
|
|
48
|
+
* {
|
|
49
|
+
* code: "server",
|
|
50
|
+
* message: "Internal server error",
|
|
51
|
+
* },
|
|
52
|
+
* ],
|
|
53
|
+
* });
|
|
54
|
+
* };
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
57
|
declare function createJsonResponse<D = unknown>(options?: CreateJsonResponseOptions<D>): Response;
|
|
58
58
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
59
|
+
* Create a JSON response with context.
|
|
60
|
+
*
|
|
61
|
+
* ### Examples
|
|
62
|
+
*
|
|
63
|
+
* Example for creating a successful JSON response without data:
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* import type { Context } from "hono";
|
|
67
|
+
*
|
|
68
|
+
* import { createJsonResponse } from "@jderstd/hono/response";
|
|
69
|
+
*
|
|
70
|
+
* const route = (c: Context): Response => {
|
|
71
|
+
* return createJsonResponse(c);
|
|
72
|
+
* };
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* Example for creating a successful JSON response with data:
|
|
76
|
+
*
|
|
77
|
+
* ```ts
|
|
78
|
+
* import type { Context } from "hono";
|
|
79
|
+
*
|
|
80
|
+
* import { createJsonResponse } from "@jderstd/hono/response";
|
|
81
|
+
*
|
|
82
|
+
* const route = (c: Context): Response => {
|
|
83
|
+
* return createJsonResponse(c, {
|
|
84
|
+
* data: "Hello, World!",
|
|
85
|
+
* });
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* Example for creating a failed JSON response:
|
|
90
|
+
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* import type { Context } from "hono";
|
|
93
|
+
*
|
|
94
|
+
* import { createJsonResponse } from "@jderstd/hono/response";
|
|
95
|
+
*
|
|
96
|
+
* const route = (c: Context): Response => {
|
|
97
|
+
* return createJsonResponse(c, {
|
|
98
|
+
* errors: [
|
|
99
|
+
* {
|
|
100
|
+
* code: "server",
|
|
101
|
+
* message: "Internal server error",
|
|
102
|
+
* },
|
|
103
|
+
* ],
|
|
104
|
+
* });
|
|
105
|
+
* };
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
108
|
declare function createJsonResponse<D = unknown>(context?: Context, options?: CreateJsonResponseOptions<D>): Response;
|
|
109
109
|
export { type CreateJsonResponseOptions, createJsonResponse };
|
|
110
110
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
let
|
|
1
|
+
let _jderstd_core_response_json_struct = require("@jderstd/core/response/json/struct");
|
|
2
2
|
|
|
3
3
|
/** Check if the argument is a Hono context. */
|
|
4
4
|
const isContext = (arg) => arg?.req !== void 0;
|
|
5
5
|
function createJsonResponse(contextOrOptions, options) {
|
|
6
|
-
const { status, headers, json } = isContext(contextOrOptions) ? (0,
|
|
6
|
+
const { status, headers, json } = isContext(contextOrOptions) ? (0, _jderstd_core_response_json_struct.createJsonResponseStruct)(options) : (0, _jderstd_core_response_json_struct.createJsonResponseStruct)(contextOrOptions);
|
|
7
7
|
if (isContext(contextOrOptions)) {
|
|
8
8
|
const c = contextOrOptions;
|
|
9
9
|
c.status(status);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c: Context"],"sources":["../../../src/response/json/index.ts"],"sourcesContent":["import type { CreateJsonResponseStructOptions } from \"@jderstd/core/response/json/struct\";\nimport type { Context } from \"hono\";\nimport type { StatusCode } from \"hono/utils/http-status\";\nimport type { Format, Omit } from \"ts-vista\";\n\nimport { createJsonResponseStruct } from \"@jderstd/core/response/json/struct\";\n\n/** Check if the argument is a Hono context. */\nconst isContext = (arg: any): arg is Context => arg?.req !== undefined;\n\n/** Options of `createJsonResponse` function. */\ntype CreateJsonResponseOptions<D = unknown> = Format<\n {\n /**\n * Status code of the response.\n * By default, it is `200` for success and `400` for failure.\n */\n status?: StatusCode;\n } & Omit<CreateJsonResponseStructOptions<D>, \"status\">\n>;\n\n/**\n * Create a JSON response.\n *\n * ### Examples\n *\n * Example for creating a successful JSON response without data:\n *\n * ```ts\n * import { createJsonResponse } from \"@jderstd/hono/response\";\n *\n * const route = (): Response => {\n * return createJsonResponse();\n * };\n * ```\n *\n * Example for creating a successful JSON response with data:\n *\n * ```ts\n * import { createJsonResponse } from \"@jderstd/hono/response\";\n *\n * const route = (): Response => {\n * return createJsonResponse({\n * data: \"Hello, World!\",\n * });\n * }\n * ```\n *\n * Example for creating a failed JSON response:\n *\n * ```ts\n * import { createJsonResponse } from \"@jderstd/hono/response\";\n *\n * const route = (): Response => {\n * return createJsonResponse({\n * errors: [\n * {\n * code: \"server\",\n * message: \"Internal server error\",\n * },\n * ],\n * });\n * };\n * ```\n */\nfunction createJsonResponse<D = unknown>(\n options?: CreateJsonResponseOptions<D>,\n): Response;\n\n/**\n * Create a JSON response with context.\n *\n * ### Examples\n *\n * Example for creating a successful JSON response without data:\n *\n * ```ts\n * import type { Context } from \"hono\";\n *\n * import { createJsonResponse } from \"@jderstd/hono/response\";\n *\n * const route = (c: Context): Response => {\n * return createJsonResponse(c);\n * };\n * ```\n *\n * Example for creating a successful JSON response with data:\n *\n * ```ts\n * import type { Context } from \"hono\";\n *\n * import { createJsonResponse } from \"@jderstd/hono/response\";\n *\n * const route = (c: Context): Response => {\n * return createJsonResponse(c, {\n * data: \"Hello, World!\",\n * });\n * }\n * ```\n *\n * Example for creating a failed JSON response:\n *\n * ```ts\n * import type { Context } from \"hono\";\n *\n * import { createJsonResponse } from \"@jderstd/hono/response\";\n *\n * const route = (c: Context): Response => {\n * return createJsonResponse(c, {\n * errors: [\n * {\n * code: \"server\",\n * message: \"Internal server error\",\n * },\n * ],\n * });\n * };\n * ```\n */\nfunction createJsonResponse<D = unknown>(\n context?: Context,\n options?: CreateJsonResponseOptions<D>,\n): Response;\n\nfunction createJsonResponse<D = unknown>(\n contextOrOptions?: Context | CreateJsonResponseOptions<D>,\n options?: CreateJsonResponseOptions<D>,\n): Response {\n const { status, headers, json } = isContext(contextOrOptions)\n ? createJsonResponseStruct(options)\n : createJsonResponseStruct(contextOrOptions);\n\n if (isContext(contextOrOptions)) {\n const c: Context = contextOrOptions;\n\n c.status(status as StatusCode);\n\n for (const [key, value] of headers) c.header(key, value);\n\n return c.json(json);\n }\n\n return new Response(JSON.stringify(json), {\n status,\n headers,\n });\n}\n\nexport type { CreateJsonResponseOptions };\nexport { isContext, createJsonResponse };\n"],"mappings":";;;AAQA,MAAM,aAAa,QAA6B,KAAK,QAAQ;AAoH7D,SAAS,mBACL,kBACA,SACQ;CACR,MAAM,EAAE,QAAQ,SAAS,SAAS,UAAU,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.js","names":["c: Context"],"sources":["../../../src/response/json/index.ts"],"sourcesContent":["import type { CreateJsonResponseStructOptions } from \"@jderstd/core/response/json/struct\";\nimport type { Context } from \"hono\";\nimport type { StatusCode } from \"hono/utils/http-status\";\nimport type { Format, Omit } from \"ts-vista\";\n\nimport { createJsonResponseStruct } from \"@jderstd/core/response/json/struct\";\n\n/** Check if the argument is a Hono context. */\nconst isContext = (arg: any): arg is Context => arg?.req !== undefined;\n\n/** Options of `createJsonResponse` function. */\ntype CreateJsonResponseOptions<D = unknown> = Format<\n {\n /**\n * Status code of the response.\n * By default, it is `200` for success and `400` for failure.\n */\n status?: StatusCode;\n } & Omit<CreateJsonResponseStructOptions<D>, \"status\">\n>;\n\n/**\n * Create a JSON response.\n *\n * ### Examples\n *\n * Example for creating a successful JSON response without data:\n *\n * ```ts\n * import { createJsonResponse } from \"@jderstd/hono/response\";\n *\n * const route = (): Response => {\n * return createJsonResponse();\n * };\n * ```\n *\n * Example for creating a successful JSON response with data:\n *\n * ```ts\n * import { createJsonResponse } from \"@jderstd/hono/response\";\n *\n * const route = (): Response => {\n * return createJsonResponse({\n * data: \"Hello, World!\",\n * });\n * }\n * ```\n *\n * Example for creating a failed JSON response:\n *\n * ```ts\n * import { createJsonResponse } from \"@jderstd/hono/response\";\n *\n * const route = (): Response => {\n * return createJsonResponse({\n * errors: [\n * {\n * code: \"server\",\n * message: \"Internal server error\",\n * },\n * ],\n * });\n * };\n * ```\n */\nfunction createJsonResponse<D = unknown>(\n options?: CreateJsonResponseOptions<D>,\n): Response;\n\n/**\n * Create a JSON response with context.\n *\n * ### Examples\n *\n * Example for creating a successful JSON response without data:\n *\n * ```ts\n * import type { Context } from \"hono\";\n *\n * import { createJsonResponse } from \"@jderstd/hono/response\";\n *\n * const route = (c: Context): Response => {\n * return createJsonResponse(c);\n * };\n * ```\n *\n * Example for creating a successful JSON response with data:\n *\n * ```ts\n * import type { Context } from \"hono\";\n *\n * import { createJsonResponse } from \"@jderstd/hono/response\";\n *\n * const route = (c: Context): Response => {\n * return createJsonResponse(c, {\n * data: \"Hello, World!\",\n * });\n * }\n * ```\n *\n * Example for creating a failed JSON response:\n *\n * ```ts\n * import type { Context } from \"hono\";\n *\n * import { createJsonResponse } from \"@jderstd/hono/response\";\n *\n * const route = (c: Context): Response => {\n * return createJsonResponse(c, {\n * errors: [\n * {\n * code: \"server\",\n * message: \"Internal server error\",\n * },\n * ],\n * });\n * };\n * ```\n */\nfunction createJsonResponse<D = unknown>(\n context?: Context,\n options?: CreateJsonResponseOptions<D>,\n): Response;\n\nfunction createJsonResponse<D = unknown>(\n contextOrOptions?: Context | CreateJsonResponseOptions<D>,\n options?: CreateJsonResponseOptions<D>,\n): Response {\n const { status, headers, json } = isContext(contextOrOptions)\n ? createJsonResponseStruct(options)\n : createJsonResponseStruct(contextOrOptions);\n\n if (isContext(contextOrOptions)) {\n const c: Context = contextOrOptions;\n\n c.status(status as StatusCode);\n\n for (const [key, value] of headers) c.header(key, value);\n\n return c.json(json);\n }\n\n return new Response(JSON.stringify(json), {\n status,\n headers,\n });\n}\n\nexport type { CreateJsonResponseOptions };\nexport { isContext, createJsonResponse };\n"],"mappings":";;;AAQA,MAAM,aAAa,QAA6B,KAAK,QAAQ;AAoH7D,SAAS,mBACL,kBACA,SACQ;CACR,MAAM,EAAE,QAAQ,SAAS,SAAS,UAAU,iBAAiB,oEAC9B,QAAQ,oEACR,iBAAiB;AAEhD,KAAI,UAAU,iBAAiB,EAAE;EAC7B,MAAMA,IAAa;AAEnB,IAAE,OAAO,OAAqB;AAE9B,OAAK,MAAM,CAAC,KAAK,UAAU,QAAS,GAAE,OAAO,KAAK,MAAM;AAExD,SAAO,EAAE,KAAK,KAAK;;AAGvB,QAAO,IAAI,SAAS,KAAK,UAAU,KAAK,EAAE;EACtC;EACA;EACH,CAAC"}
|
package/dist/response.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { CreateResponseOptions, createResponse } from "./response/common/index.js";
|
|
2
2
|
import { CreateJsonResponseOptions, createJsonResponse } from "./response/json/index.js";
|
|
3
|
-
import { JsonResponse, JsonResponseError } from "@jderstd/core";
|
|
4
|
-
export { type CreateJsonResponseOptions, type CreateResponseOptions, type JsonResponse, type JsonResponseError, createJsonResponse, createResponse };
|
|
3
|
+
import { JsonResponse, JsonResponseError, JsonResponseErrorInput } from "@jderstd/core";
|
|
4
|
+
export { type CreateJsonResponseOptions, type CreateResponseOptions, type JsonResponse, type JsonResponseError, type JsonResponseErrorInput, createJsonResponse, createResponse };
|
package/dist/time-limit.d.ts
CHANGED
|
@@ -4,59 +4,59 @@ declare const TIME_LIMIT_MAX_DEFAULT: 5000;
|
|
|
4
4
|
/** Options for `timeLimit` middleware. */
|
|
5
5
|
type TimeLimitOptions = {
|
|
6
6
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
* Maximum time in milliseconds.
|
|
8
|
+
*
|
|
9
|
+
* By default, it is `TIME_LIMIT_MAX_DEFAULT`.
|
|
10
|
+
*/
|
|
11
11
|
max?: number;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
14
|
+
* Time limit middleware.
|
|
15
|
+
*
|
|
16
|
+
* Following error will be returned if the request takes longer than the limit:
|
|
17
|
+
*
|
|
18
|
+
* ```jsonc
|
|
19
|
+
* // Status: 504
|
|
20
|
+
* {
|
|
21
|
+
* "success": false,
|
|
22
|
+
* "errors": [
|
|
23
|
+
* {
|
|
24
|
+
* "code": "timeout",
|
|
25
|
+
* "message": "Request timeout"
|
|
26
|
+
* }
|
|
27
|
+
* ]
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* For more information, please refer to
|
|
32
|
+
* [Timeout](https://hono.dev/docs/middleware/builtin/timeout).
|
|
33
|
+
*
|
|
34
|
+
* ### Examples
|
|
35
|
+
*
|
|
36
|
+
* A example of using `timeLimit` middleware:
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { Hono } from "hono";
|
|
40
|
+
* import { timeLimit } from "@jderstd/hono/time-limit";
|
|
41
|
+
*
|
|
42
|
+
* const app: Hono = new Hono();
|
|
43
|
+
*
|
|
44
|
+
* app.use(timeLimit());
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* A example of using `timeLimit` middleware with options:
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { Hono } from "hono";
|
|
51
|
+
* import { timeLimit } from "@jderstd/hono/time-limit";
|
|
52
|
+
*
|
|
53
|
+
* const app: Hono = new Hono();
|
|
54
|
+
*
|
|
55
|
+
* app.use(timeLimit({
|
|
56
|
+
* max: 10 * 1000, // 10s
|
|
57
|
+
* }));
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
60
|
declare const timeLimit: (options?: TimeLimitOptions) => MiddlewareHandler;
|
|
61
61
|
export { TIME_LIMIT_MAX_DEFAULT, type TimeLimitOptions, timeLimit };
|
|
62
62
|
//# sourceMappingURL=time-limit.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jderstd/hono",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A response builder for Hono",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jder",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
"dist"
|
|
74
74
|
],
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@jderstd/core": "
|
|
77
|
-
"ts-vista": "~0.2.
|
|
76
|
+
"@jderstd/core": "0.5.0",
|
|
77
|
+
"ts-vista": "~0.2.3"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"hono": "4.5.0"
|