@jderstd/hono 0.7.1 → 0.8.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.
- 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/not-found.js.map +1 -1
- package/dist/not-found.mjs.map +1 -1
- package/dist/on-error.d.ts +56 -56
- package/dist/on-error.js.map +1 -1
- package/dist/on-error.mjs.map +1 -1
- 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/http.d.ts +3 -0
- package/dist/response/error/http.js +7 -0
- package/dist/response/error/http.js.map +1 -1
- package/dist/response/error/http.mjs +7 -0
- package/dist/response/error/http.mjs.map +1 -1
- package/dist/response/error/index.d.ts +36 -32
- package/dist/response/error/index.js +4 -0
- package/dist/response/error/index.js.map +1 -1
- package/dist/response/error/index.mjs +4 -0
- package/dist/response/error/index.mjs.map +1 -1
- 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
|
@@ -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,5 +1,12 @@
|
|
|
1
1
|
let hono_http_exception = require("hono/http-exception");
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* HTTP response error module
|
|
5
|
+
* @module response/error/http
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Jder HTTP exception class extended from `HTTPException`.
|
|
9
|
+
*/
|
|
3
10
|
var JderHttpException = class extends hono_http_exception.HTTPException {};
|
|
4
11
|
|
|
5
12
|
exports.JderHttpException = JderHttpException;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","names":["HTTPException"],"sources":["../../../src/response/error/http.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"http.js","names":["HTTPException"],"sources":["../../../src/response/error/http.ts"],"sourcesContent":["/**\n * HTTP response error module\n * @module response/error/http\n */\n\nimport { HTTPException } from \"hono/http-exception\";\n\n/**\n * Jder HTTP exception class extended from `HTTPException`.\n */\nclass JderHttpException extends HTTPException {}\n\nexport { JderHttpException };\n"],"mappings":";;;;;;;;;AAUA,IAAM,oBAAN,cAAgCA,kCAAc"}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { HTTPException } from "hono/http-exception";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* HTTP response error module
|
|
5
|
+
* @module response/error/http
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Jder HTTP exception class extended from `HTTPException`.
|
|
9
|
+
*/
|
|
3
10
|
var JderHttpException = class extends HTTPException {};
|
|
4
11
|
|
|
5
12
|
export { JderHttpException };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.mjs","names":[],"sources":["../../../src/response/error/http.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"http.mjs","names":[],"sources":["../../../src/response/error/http.ts"],"sourcesContent":["/**\n * HTTP response error module\n * @module response/error/http\n */\n\nimport { HTTPException } from \"hono/http-exception\";\n\n/**\n * Jder HTTP exception class extended from `HTTPException`.\n */\nclass JderHttpException extends HTTPException {}\n\nexport { JderHttpException };\n"],"mappings":";;;;;;;;;AAUA,IAAM,oBAAN,cAAgC,cAAc"}
|
|
@@ -1,53 +1,57 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
* Response error module
|
|
3
|
+
* @module response/error
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Response error code.
|
|
7
|
+
*/
|
|
4
8
|
declare enum ResponseErrorCode {
|
|
5
9
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
* Request body is too large.
|
|
11
|
+
*
|
|
12
|
+
* For `bodyLimit` middleware.
|
|
13
|
+
*/
|
|
10
14
|
TooLarge = "too_large",
|
|
11
15
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
* Forbidden access.
|
|
17
|
+
*
|
|
18
|
+
* For `ipLimit` middleware.
|
|
19
|
+
*/
|
|
16
20
|
Forbidden = "forbidden",
|
|
17
21
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
* Request timeout.
|
|
23
|
+
*
|
|
24
|
+
* For `timeLimit` middleware.
|
|
25
|
+
*/
|
|
22
26
|
Timeout = "timeout",
|
|
23
27
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
* Content not found.
|
|
29
|
+
*
|
|
30
|
+
* For `notFoundHandler` function.
|
|
31
|
+
*/
|
|
28
32
|
NotFound = "not_found",
|
|
29
33
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
* Bad request.
|
|
35
|
+
*
|
|
36
|
+
* For `onErrorHandler` function.
|
|
37
|
+
*/
|
|
34
38
|
BadRequest = "bad_request",
|
|
35
39
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
* Internal server error.
|
|
41
|
+
*
|
|
42
|
+
* For `onErrorHandler` function.
|
|
43
|
+
*/
|
|
40
44
|
Server = "server",
|
|
41
45
|
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
* Validation error.
|
|
47
|
+
*
|
|
48
|
+
* For validator package.
|
|
49
|
+
*/
|
|
46
50
|
Parse = "parse",
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
* Get response error message by code.
|
|
54
|
+
*/
|
|
51
55
|
declare const getResponseErrorMessage: (code: ResponseErrorCode) => string;
|
|
52
56
|
export { ResponseErrorCode, getResponseErrorMessage };
|
|
53
57
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/response/error/index.ts"],"sourcesContent":["/**\n * Response error code.\n */\nenum ResponseErrorCode {\n /**\n * Request body is too large.\n *\n * For `bodyLimit` middleware.\n */\n TooLarge = \"too_large\",\n /**\n * Forbidden access.\n *\n * For `ipLimit` middleware.\n */\n Forbidden = \"forbidden\",\n /**\n * Request timeout.\n *\n * For `timeLimit` middleware.\n */\n Timeout = \"timeout\",\n /**\n * Content not found.\n *\n * For `notFoundHandler` function.\n */\n NotFound = \"not_found\",\n /**\n * Bad request.\n *\n * For `onErrorHandler` function.\n */\n BadRequest = \"bad_request\",\n /**\n * Internal server error.\n *\n * For `onErrorHandler` function.\n */\n Server = \"server\",\n /**\n * Validation error.\n *\n * For validator package.\n */\n Parse = \"parse\",\n}\n\n/**\n * Get response error message by code.\n */\nconst getResponseErrorMessage = (code: ResponseErrorCode): string => {\n switch (code) {\n case ResponseErrorCode.TooLarge: {\n return \"Request body is too large\";\n }\n case ResponseErrorCode.Forbidden: {\n return \"Forbidden IP address\";\n }\n case ResponseErrorCode.Timeout: {\n return \"Gateway timeout\";\n }\n case ResponseErrorCode.NotFound: {\n return \"Content not found\";\n }\n case ResponseErrorCode.BadRequest: {\n return \"Bad request\";\n }\n case ResponseErrorCode.Server: {\n return \"Internal server error\";\n }\n case ResponseErrorCode.Parse: {\n return \"Failed to parse the request\";\n }\n }\n};\n\nexport { ResponseErrorCode, getResponseErrorMessage };\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/response/error/index.ts"],"sourcesContent":["/**\n * Response error module\n * @module response/error\n */\n\n/**\n * Response error code.\n */\nenum ResponseErrorCode {\n /**\n * Request body is too large.\n *\n * For `bodyLimit` middleware.\n */\n TooLarge = \"too_large\",\n /**\n * Forbidden access.\n *\n * For `ipLimit` middleware.\n */\n Forbidden = \"forbidden\",\n /**\n * Request timeout.\n *\n * For `timeLimit` middleware.\n */\n Timeout = \"timeout\",\n /**\n * Content not found.\n *\n * For `notFoundHandler` function.\n */\n NotFound = \"not_found\",\n /**\n * Bad request.\n *\n * For `onErrorHandler` function.\n */\n BadRequest = \"bad_request\",\n /**\n * Internal server error.\n *\n * For `onErrorHandler` function.\n */\n Server = \"server\",\n /**\n * Validation error.\n *\n * For validator package.\n */\n Parse = \"parse\",\n}\n\n/**\n * Get response error message by code.\n */\nconst getResponseErrorMessage = (code: ResponseErrorCode): string => {\n switch (code) {\n case ResponseErrorCode.TooLarge: {\n return \"Request body is too large\";\n }\n case ResponseErrorCode.Forbidden: {\n return \"Forbidden IP address\";\n }\n case ResponseErrorCode.Timeout: {\n return \"Gateway timeout\";\n }\n case ResponseErrorCode.NotFound: {\n return \"Content not found\";\n }\n case ResponseErrorCode.BadRequest: {\n return \"Bad request\";\n }\n case ResponseErrorCode.Server: {\n return \"Internal server error\";\n }\n case ResponseErrorCode.Parse: {\n return \"Failed to parse the request\";\n }\n }\n};\n\nexport { ResponseErrorCode, getResponseErrorMessage };\n"],"mappings":";;;;;;;;AAQA,IAAK,kEAAL;;;;;;AAMI;;;;;;AAMA;;;;;;AAMA;;;;;;AAMA;;;;;;AAMA;;;;;;AAMA;;;;;;AAMA;;EA1CC;;;;AAgDL,MAAM,2BAA2B,SAAoC;AACjE,SAAQ,MAAR;EACI,KAAK,kBAAkB,SACnB,QAAO;EAEX,KAAK,kBAAkB,UACnB,QAAO;EAEX,KAAK,kBAAkB,QACnB,QAAO;EAEX,KAAK,kBAAkB,SACnB,QAAO;EAEX,KAAK,kBAAkB,WACnB,QAAO;EAEX,KAAK,kBAAkB,OACnB,QAAO;EAEX,KAAK,kBAAkB,MACnB,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/response/error/index.ts"],"sourcesContent":["/**\n * Response error code.\n */\nenum ResponseErrorCode {\n /**\n * Request body is too large.\n *\n * For `bodyLimit` middleware.\n */\n TooLarge = \"too_large\",\n /**\n * Forbidden access.\n *\n * For `ipLimit` middleware.\n */\n Forbidden = \"forbidden\",\n /**\n * Request timeout.\n *\n * For `timeLimit` middleware.\n */\n Timeout = \"timeout\",\n /**\n * Content not found.\n *\n * For `notFoundHandler` function.\n */\n NotFound = \"not_found\",\n /**\n * Bad request.\n *\n * For `onErrorHandler` function.\n */\n BadRequest = \"bad_request\",\n /**\n * Internal server error.\n *\n * For `onErrorHandler` function.\n */\n Server = \"server\",\n /**\n * Validation error.\n *\n * For validator package.\n */\n Parse = \"parse\",\n}\n\n/**\n * Get response error message by code.\n */\nconst getResponseErrorMessage = (code: ResponseErrorCode): string => {\n switch (code) {\n case ResponseErrorCode.TooLarge: {\n return \"Request body is too large\";\n }\n case ResponseErrorCode.Forbidden: {\n return \"Forbidden IP address\";\n }\n case ResponseErrorCode.Timeout: {\n return \"Gateway timeout\";\n }\n case ResponseErrorCode.NotFound: {\n return \"Content not found\";\n }\n case ResponseErrorCode.BadRequest: {\n return \"Bad request\";\n }\n case ResponseErrorCode.Server: {\n return \"Internal server error\";\n }\n case ResponseErrorCode.Parse: {\n return \"Failed to parse the request\";\n }\n }\n};\n\nexport { ResponseErrorCode, getResponseErrorMessage };\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/response/error/index.ts"],"sourcesContent":["/**\n * Response error module\n * @module response/error\n */\n\n/**\n * Response error code.\n */\nenum ResponseErrorCode {\n /**\n * Request body is too large.\n *\n * For `bodyLimit` middleware.\n */\n TooLarge = \"too_large\",\n /**\n * Forbidden access.\n *\n * For `ipLimit` middleware.\n */\n Forbidden = \"forbidden\",\n /**\n * Request timeout.\n *\n * For `timeLimit` middleware.\n */\n Timeout = \"timeout\",\n /**\n * Content not found.\n *\n * For `notFoundHandler` function.\n */\n NotFound = \"not_found\",\n /**\n * Bad request.\n *\n * For `onErrorHandler` function.\n */\n BadRequest = \"bad_request\",\n /**\n * Internal server error.\n *\n * For `onErrorHandler` function.\n */\n Server = \"server\",\n /**\n * Validation error.\n *\n * For validator package.\n */\n Parse = \"parse\",\n}\n\n/**\n * Get response error message by code.\n */\nconst getResponseErrorMessage = (code: ResponseErrorCode): string => {\n switch (code) {\n case ResponseErrorCode.TooLarge: {\n return \"Request body is too large\";\n }\n case ResponseErrorCode.Forbidden: {\n return \"Forbidden IP address\";\n }\n case ResponseErrorCode.Timeout: {\n return \"Gateway timeout\";\n }\n case ResponseErrorCode.NotFound: {\n return \"Content not found\";\n }\n case ResponseErrorCode.BadRequest: {\n return \"Bad request\";\n }\n case ResponseErrorCode.Server: {\n return \"Internal server error\";\n }\n case ResponseErrorCode.Parse: {\n return \"Failed to parse the request\";\n }\n }\n};\n\nexport { ResponseErrorCode, getResponseErrorMessage };\n"],"mappings":";;;;;;;AAQA,IAAK,kEAAL;;;;;;AAMI;;;;;;AAMA;;;;;;AAMA;;;;;;AAMA;;;;;;AAMA;;;;;;AAMA;;;;;;AAMA;;EA1CC;;;;AAgDL,MAAM,2BAA2B,SAAoC;AACjE,SAAQ,MAAR;EACI,KAAK,kBAAkB,SACnB,QAAO;EAEX,KAAK,kBAAkB,UACnB,QAAO;EAEX,KAAK,kBAAkB,QACnB,QAAO;EAEX,KAAK,kBAAkB,SACnB,QAAO;EAEX,KAAK,kBAAkB,WACnB,QAAO;EAEX,KAAK,kBAAkB,OACnB,QAAO;EAEX,KAAK,kBAAkB,MACnB,QAAO"}
|
|
@@ -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 };
|