tezx 2.0.11 → 3.0.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 +122 -89
- package/bun/getConnInfo.d.ts +21 -0
- package/bun/getConnInfo.js +9 -0
- package/bun/index.d.ts +10 -4
- package/bun/index.js +8 -4
- package/bun/ws.d.ts +48 -0
- package/bun/ws.js +58 -0
- package/cjs/bun/getConnInfo.js +12 -0
- package/cjs/bun/index.js +35 -7
- package/cjs/bun/ws.js +63 -0
- package/cjs/core/config.js +2 -12
- package/cjs/core/context.js +131 -379
- package/cjs/core/error.js +49 -0
- package/cjs/core/request.js +79 -131
- package/cjs/core/router.js +54 -387
- package/cjs/core/server.js +83 -202
- package/cjs/deno/env.js +4 -4
- package/cjs/deno/getConnInfo.js +18 -0
- package/cjs/deno/index.js +11 -18
- package/cjs/deno/serveStatic.js +53 -0
- package/cjs/deno/ws.js +39 -0
- package/cjs/helper/index.js +46 -10
- package/cjs/index.js +5 -7
- package/cjs/jwt/node.js +94 -0
- package/cjs/jwt/web.js +178 -0
- package/cjs/middleware/basic-auth.js +42 -0
- package/cjs/middleware/bearer-auth.js +34 -0
- package/cjs/middleware/cache-control.js +44 -0
- package/cjs/middleware/cors.js +11 -21
- package/cjs/middleware/detect-bot.js +57 -0
- package/cjs/middleware/i18n.js +73 -60
- package/cjs/middleware/index.js +8 -46
- package/cjs/middleware/logger.js +9 -4
- package/cjs/middleware/pagination.js +3 -2
- package/cjs/middleware/powered-by.js +3 -2
- package/cjs/middleware/rate-limiter.js +38 -0
- package/cjs/middleware/request-id.js +4 -5
- package/cjs/middleware/sanitize-headers.js +22 -0
- package/cjs/middleware/secure-headers copy.js +143 -0
- package/cjs/middleware/secure-headers.js +157 -0
- package/cjs/middleware/{xssProtection.js → xss-protection.js} +5 -8
- package/cjs/node/env.js +7 -7
- package/cjs/node/getConnInfo.js +16 -0
- package/cjs/node/index.js +17 -18
- package/cjs/node/mount-node.js +59 -0
- package/cjs/node/serveStatic.js +56 -0
- package/cjs/node/toWebRequest.js +25 -0
- package/cjs/node/ws.js +82 -0
- package/cjs/registry/RadixRouter.js +148 -0
- package/cjs/registry/index.js +17 -0
- package/cjs/types/headers.js +2 -0
- package/cjs/types/index.js +13 -0
- package/cjs/utils/buffer.js +17 -0
- package/cjs/utils/colors.js +2 -0
- package/cjs/utils/cookie.js +59 -0
- package/cjs/utils/file.js +136 -0
- package/cjs/utils/formData.js +60 -10
- package/cjs/utils/generateID.js +37 -0
- package/cjs/utils/low-level.js +115 -0
- package/cjs/utils/{staticFile.js → mimeTypes.js} +0 -87
- package/cjs/utils/rateLimit.js +41 -0
- package/cjs/utils/response.js +65 -0
- package/cjs/{core/environment.js → utils/runtime.js} +2 -1
- package/cjs/utils/url.js +65 -30
- package/core/config.d.ts +2 -7
- package/core/config.js +2 -12
- package/core/context.d.ts +209 -164
- package/core/context.js +131 -346
- package/core/error.d.ts +96 -0
- package/core/error.js +44 -0
- package/core/request.d.ts +67 -107
- package/core/request.js +78 -130
- package/core/router.d.ts +138 -133
- package/core/router.js +53 -352
- package/core/server.d.ts +99 -38
- package/core/server.js +83 -202
- package/deno/env.js +3 -3
- package/deno/getConnInfo.d.ts +21 -0
- package/deno/getConnInfo.js +15 -0
- package/deno/index.d.ts +9 -4
- package/deno/index.js +7 -4
- package/deno/serveStatic.d.ts +28 -0
- package/deno/serveStatic.js +49 -0
- package/deno/ws.d.ts +42 -0
- package/deno/ws.js +36 -0
- package/helper/index.d.ts +29 -15
- package/helper/index.js +27 -7
- package/index.d.ts +10 -8
- package/index.js +4 -5
- package/jwt/node.d.ts +39 -0
- package/jwt/node.js +87 -0
- package/jwt/web.d.ts +14 -0
- package/jwt/web.js +174 -0
- package/middleware/basic-auth.d.ts +56 -0
- package/middleware/basic-auth.js +38 -0
- package/middleware/bearer-auth.d.ts +53 -0
- package/middleware/bearer-auth.js +30 -0
- package/middleware/cache-control.d.ts +30 -0
- package/middleware/cache-control.js +40 -0
- package/middleware/cors.d.ts +30 -3
- package/middleware/cors.js +12 -22
- package/middleware/detect-bot.d.ts +113 -0
- package/middleware/detect-bot.js +53 -0
- package/middleware/i18n.d.ts +166 -73
- package/middleware/i18n.js +73 -60
- package/middleware/index.d.ts +8 -32
- package/middleware/index.js +8 -44
- package/middleware/logger.d.ts +5 -2
- package/middleware/logger.js +9 -4
- package/middleware/pagination.d.ts +9 -6
- package/middleware/pagination.js +3 -2
- package/middleware/powered-by.d.ts +2 -1
- package/middleware/powered-by.js +3 -2
- package/middleware/{rateLimiter.d.ts → rate-limiter.d.ts} +15 -9
- package/middleware/rate-limiter.js +34 -0
- package/middleware/request-id.d.ts +2 -1
- package/middleware/request-id.js +5 -6
- package/middleware/{sanitizeHeader.d.ts → sanitize-headers.d.ts} +5 -19
- package/middleware/sanitize-headers.js +18 -0
- package/middleware/secure-headers copy.d.ts +15 -0
- package/middleware/secure-headers copy.js +136 -0
- package/middleware/secure-headers.d.ts +132 -0
- package/middleware/secure-headers.js +153 -0
- package/middleware/{xssProtection.d.ts → xss-protection.d.ts} +2 -1
- package/middleware/xss-protection.js +19 -0
- package/node/env.js +4 -4
- package/node/getConnInfo.d.ts +21 -0
- package/node/getConnInfo.js +13 -0
- package/node/index.d.ts +13 -4
- package/node/index.js +11 -4
- package/node/mount-node.d.ts +11 -0
- package/node/mount-node.js +56 -0
- package/node/serveStatic.d.ts +36 -0
- package/node/serveStatic.js +52 -0
- package/node/toWebRequest.js +22 -0
- package/node/ws.d.ts +56 -0
- package/node/ws.js +46 -0
- package/package.json +39 -30
- package/registry/RadixRouter.d.ts +40 -0
- package/registry/RadixRouter.js +144 -0
- package/registry/index.d.ts +2 -0
- package/registry/index.js +1 -0
- package/types/headers.d.ts +2 -0
- package/types/headers.js +1 -0
- package/types/index.d.ts +318 -18
- package/types/index.js +12 -1
- package/utils/buffer.d.ts +1 -0
- package/utils/buffer.js +14 -0
- package/utils/colors.d.ts +24 -0
- package/utils/colors.js +2 -0
- package/utils/cookie.d.ts +55 -0
- package/utils/cookie.js +53 -0
- package/utils/file.d.ts +38 -0
- package/utils/file.js +96 -0
- package/utils/formData.d.ts +41 -1
- package/utils/formData.js +58 -9
- package/utils/generateID.d.ts +42 -0
- package/utils/generateID.js +32 -0
- package/utils/httpStatusMap.d.ts +14 -0
- package/utils/low-level.d.ts +58 -0
- package/utils/low-level.js +108 -0
- package/utils/mimeTypes.d.ts +4 -0
- package/utils/{staticFile.js → mimeTypes.js} +0 -53
- package/utils/rateLimit.d.ts +18 -0
- package/utils/rateLimit.js +37 -0
- package/utils/response.d.ts +18 -0
- package/utils/response.js +58 -0
- package/{core/environment.d.ts → utils/runtime.d.ts} +1 -0
- package/{core/environment.js → utils/runtime.js} +1 -0
- package/utils/url.d.ts +42 -14
- package/utils/url.js +61 -27
- package/bun/adapter.d.ts +0 -127
- package/bun/adapter.js +0 -97
- package/cjs/bun/adapter.js +0 -100
- package/cjs/core/MiddlewareConfigure.js +0 -68
- package/cjs/core/common.js +0 -15
- package/cjs/deno/adpater.js +0 -67
- package/cjs/helper/common.js +0 -17
- package/cjs/middleware/basicAuth.js +0 -71
- package/cjs/middleware/cacheControl.js +0 -90
- package/cjs/middleware/detectBot.js +0 -104
- package/cjs/middleware/detectLocale.js +0 -43
- package/cjs/middleware/lazyLoadModules.js +0 -73
- package/cjs/middleware/rateLimiter.js +0 -24
- package/cjs/middleware/requestTimeout.js +0 -42
- package/cjs/middleware/sanitizeHeader.js +0 -51
- package/cjs/middleware/secureHeaders.js +0 -42
- package/cjs/node/adapter.js +0 -138
- package/cjs/utils/regexRouter.js +0 -58
- package/cjs/utils/state.js +0 -34
- package/cjs/utils/toWebRequest.js +0 -35
- package/cjs/ws/deno.js +0 -20
- package/cjs/ws/index.js +0 -53
- package/cjs/ws/node.js +0 -65
- package/core/MiddlewareConfigure.d.ts +0 -15
- package/core/MiddlewareConfigure.js +0 -63
- package/core/common.d.ts +0 -21
- package/core/common.js +0 -11
- package/deno/adpater.d.ts +0 -38
- package/deno/adpater.js +0 -64
- package/helper/common.d.ts +0 -5
- package/helper/common.js +0 -14
- package/middleware/basicAuth.d.ts +0 -81
- package/middleware/basicAuth.js +0 -67
- package/middleware/cacheControl.d.ts +0 -48
- package/middleware/cacheControl.js +0 -53
- package/middleware/detectBot.d.ts +0 -121
- package/middleware/detectBot.js +0 -98
- package/middleware/detectLocale.d.ts +0 -55
- package/middleware/detectLocale.js +0 -39
- package/middleware/lazyLoadModules.d.ts +0 -72
- package/middleware/lazyLoadModules.js +0 -69
- package/middleware/rateLimiter.js +0 -20
- package/middleware/requestTimeout.d.ts +0 -25
- package/middleware/requestTimeout.js +0 -38
- package/middleware/sanitizeHeader.js +0 -47
- package/middleware/secureHeaders.d.ts +0 -78
- package/middleware/secureHeaders.js +0 -38
- package/middleware/xssProtection.js +0 -22
- package/node/adapter.d.ts +0 -46
- package/node/adapter.js +0 -102
- package/utils/regexRouter.d.ts +0 -66
- package/utils/regexRouter.js +0 -53
- package/utils/state.d.ts +0 -50
- package/utils/state.js +0 -30
- package/utils/staticFile.d.ts +0 -10
- package/utils/toWebRequest.js +0 -32
- package/ws/deno.d.ts +0 -6
- package/ws/deno.js +0 -16
- package/ws/index.d.ts +0 -180
- package/ws/index.js +0 -50
- package/ws/node.d.ts +0 -7
- package/ws/node.js +0 -28
- /package/{utils → node}/toWebRequest.d.ts +0 -0
package/core/context.d.ts
CHANGED
|
@@ -1,215 +1,260 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { TezXServeOptions } from "./server.js";
|
|
5
|
-
export declare class Context<T extends Record<string, any> = {}, Path extends PathType = any> {
|
|
1
|
+
import { HttpBaseResponse, ResHeaderKey, ResponseInit } from "../types/index.js";
|
|
2
|
+
import { TezXRequest } from "./request.js";
|
|
3
|
+
export declare class Context<TEnv extends Record<string, any> = {}, TPath extends string = any> {
|
|
6
4
|
#private;
|
|
7
5
|
[key: string]: any;
|
|
6
|
+
/**
|
|
7
|
+
* The original Request object from the underlying platform (e.g., Node.js, Deno).
|
|
8
|
+
* Contains all headers and body data.
|
|
9
|
+
* @type {Request}
|
|
10
|
+
*/
|
|
8
11
|
rawRequest: Request;
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
13
|
+
* The URL associated with the current context.
|
|
14
|
+
*
|
|
15
|
+
* This is a read-only string representing the resource location or endpoint.
|
|
16
|
+
*/
|
|
17
|
+
readonly url: string;
|
|
18
|
+
/**
|
|
19
|
+
* The native Response object associated with this context, if available.
|
|
20
|
+
*
|
|
21
|
+
* This property is set when a response has been created or is being manipulated directly.
|
|
22
|
+
* It may be undefined if the response has not yet been constructed.
|
|
23
|
+
*
|
|
24
|
+
* @type {Response | undefined}
|
|
25
|
+
* @remarks
|
|
26
|
+
* - When present, headers and status should be set directly on this object.
|
|
27
|
+
* - When undefined, internal header and status management is used.
|
|
12
28
|
*/
|
|
13
|
-
|
|
29
|
+
res?: Response;
|
|
14
30
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @type {
|
|
31
|
+
* Environment variables or shared state accessible in context.
|
|
32
|
+
* @type {Record<string, any> & TEnv}
|
|
17
33
|
*/
|
|
18
|
-
|
|
34
|
+
env: Record<string, any> & TEnv;
|
|
19
35
|
/**
|
|
20
|
-
* Request path without
|
|
36
|
+
* Request pathname (URL path without domain).
|
|
37
|
+
* @readonly
|
|
21
38
|
* @type {string}
|
|
22
39
|
*/
|
|
23
40
|
readonly pathname: string;
|
|
24
41
|
/**
|
|
25
|
-
*
|
|
42
|
+
* HTTP request method (e.g., GET, POST).
|
|
43
|
+
* @readonly
|
|
26
44
|
* @type {string}
|
|
27
45
|
*/
|
|
28
|
-
readonly
|
|
46
|
+
readonly method: string;
|
|
29
47
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
48
|
+
* Creates a new context instance.
|
|
49
|
+
*
|
|
50
|
+
* @param {Request} req - The native Request object.
|
|
51
|
+
* @param {ContextOptions<TEnv>} options - Context options including pathname, method, env, params, and args.
|
|
32
52
|
*/
|
|
33
|
-
|
|
53
|
+
constructor(req: Request, pathname: string, method: string, env: Record<string, any> & TEnv, args: any[]);
|
|
34
54
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @type {State}
|
|
55
|
+
* Gets the current HTTP status code.
|
|
56
|
+
* @returns {number} The HTTP status code.
|
|
38
57
|
*/
|
|
39
|
-
|
|
40
|
-
protected readonly resBody?: BodyInit | null;
|
|
41
|
-
constructor(req: any, options: TezXServeOptions);
|
|
58
|
+
get getStatus(): number;
|
|
42
59
|
/**
|
|
43
|
-
*
|
|
44
|
-
* @param
|
|
45
|
-
* @param value - Value to append.
|
|
46
|
-
* @default {append:false}
|
|
60
|
+
* Sets the HTTP status code.
|
|
61
|
+
* @param {number} code - The HTTP status code.
|
|
47
62
|
*/
|
|
48
|
-
|
|
49
|
-
append?: true;
|
|
50
|
-
}): this;
|
|
51
|
-
header(key: string, value: string | string[], options?: {
|
|
52
|
-
append?: false;
|
|
53
|
-
}): this;
|
|
63
|
+
set setStatus(code: number);
|
|
54
64
|
/**
|
|
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
|
-
* @param {string} name - The name of the cookie.
|
|
84
|
-
* @param {string} value - The value of the cookie.
|
|
85
|
-
* @param {CookieOptions} [options] - Additional options like expiration.
|
|
86
|
-
*/
|
|
87
|
-
set: (name: string, value: string, options?: CookieOptions) => void;
|
|
88
|
-
};
|
|
65
|
+
* Access the response headers.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* This returns the native {@link Headers} object associated with the response.
|
|
69
|
+
* It gives you full control over reading, setting, appending, and deleting headers
|
|
70
|
+
* using the standard Web Headers API.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* // Get a header value
|
|
75
|
+
* const contentType = ctx.headers.get("content-type")
|
|
76
|
+
*
|
|
77
|
+
* // Set or overwrite a header
|
|
78
|
+
* ctx.headers.set("x-powered-by", "tezx")
|
|
79
|
+
*
|
|
80
|
+
* // Append multiple values
|
|
81
|
+
* ctx.headers.append("set-cookie", "id=123")
|
|
82
|
+
* ctx.headers.append("set-cookie", "token=xyz")
|
|
83
|
+
*
|
|
84
|
+
* // Iterate all headers
|
|
85
|
+
* for (const [key, value] of ctx.headers.entries()) {
|
|
86
|
+
* console.log(key, value)
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @returns {Headers} The response headers object.
|
|
91
|
+
*/
|
|
92
|
+
get headers(): Headers;
|
|
89
93
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* @param
|
|
93
|
-
* @param
|
|
94
|
-
* @
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
*
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
*/
|
|
107
|
-
send(body: any, status?: number, headers?: ResponseHeaders): Response;
|
|
108
|
-
send(body: any, headers?: ResponseHeaders): Response;
|
|
109
|
-
send(body: any, status?: number): Response;
|
|
94
|
+
* Sets or appends a header to the response.
|
|
95
|
+
*
|
|
96
|
+
* @param {string} key - Header name (e.g., "Content-Type").
|
|
97
|
+
* @param {string} value - Header value to set or append.
|
|
98
|
+
* @param {Object} [options] - Options to modify behavior.
|
|
99
|
+
* @param {boolean} [options.append=false] - If true, appends instead of overwriting.
|
|
100
|
+
* @returns {this} The context instance for chaining.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ctx.setHeader("X-Custom", "Value");
|
|
104
|
+
* ctx.setHeader("Cache-Control", "no-cache", { append: true });
|
|
105
|
+
*/
|
|
106
|
+
setHeader(key: ResHeaderKey, value: string, options?: {
|
|
107
|
+
append?: boolean;
|
|
108
|
+
}): this;
|
|
109
|
+
protected set params(params: Record<string, any>);
|
|
110
110
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* @returns
|
|
111
|
+
* Gets the wrapped request object (`TezXRequest`).
|
|
112
|
+
*
|
|
113
|
+
* Lazily initializes the wrapped request on first access.
|
|
114
|
+
*
|
|
115
|
+
* @returns {TezXRequest<TPath>} The wrapped request.
|
|
116
116
|
*/
|
|
117
|
-
|
|
118
|
-
html(strings: string, status?: number, headers?: ResponseHeaders): Response;
|
|
119
|
-
html(strings: string, headers?: ResponseHeaders): Response;
|
|
120
|
-
html(strings: string, status?: number): Response;
|
|
117
|
+
get req(): TezXRequest<TPath>;
|
|
121
118
|
/**
|
|
122
|
-
*
|
|
123
|
-
* @
|
|
124
|
-
* @param status - (Optional) HTTP status code (default: 200).
|
|
125
|
-
* @param headers - (Optional) Additional response headers.
|
|
126
|
-
* @returns Response object with plain text data.
|
|
119
|
+
* Gets the response body.
|
|
120
|
+
* @returns {*} The response body.
|
|
127
121
|
*/
|
|
128
|
-
|
|
129
|
-
text(data: string, headers?: ResponseHeaders): Response;
|
|
130
|
-
text(data: string, status?: number): Response;
|
|
122
|
+
get body(): any;
|
|
131
123
|
/**
|
|
132
|
-
*
|
|
133
|
-
* @param
|
|
134
|
-
* @param status - (Optional) HTTP status code (default: 200).
|
|
135
|
-
* @param headers - (Optional) Additional response headers.
|
|
136
|
-
* @returns Response object with XML data.
|
|
124
|
+
* Sets the response body.
|
|
125
|
+
* @param {*} value - The response body.
|
|
137
126
|
*/
|
|
138
|
-
|
|
139
|
-
xml(data: string, headers?: ResponseHeaders): Response;
|
|
140
|
-
xml(data: string, status?: number): Response;
|
|
127
|
+
set body(value: any);
|
|
141
128
|
/**
|
|
142
|
-
* HTTP status code
|
|
143
|
-
*
|
|
144
|
-
* @
|
|
129
|
+
* Sets the HTTP response status code.
|
|
130
|
+
*
|
|
131
|
+
* @param {number} status - HTTP status code to set (e.g., 200, 404).
|
|
132
|
+
* @returns {this} The current context instance for method chaining.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ctx.status(404).text("Not found");
|
|
145
136
|
*/
|
|
146
137
|
status: (status: number) => this;
|
|
147
|
-
set setStatus(status: number);
|
|
148
|
-
get getStatus(): number;
|
|
149
138
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* @
|
|
139
|
+
* Protected helper method to create a Response or PlainResponse
|
|
140
|
+
* based on runtime environment (Node.js or Web).
|
|
141
|
+
*
|
|
142
|
+
* @param {BodyInit | null} body - Response body content.
|
|
143
|
+
* @param {ResponseInit} [init] - Response initialization options.
|
|
144
|
+
* @returns {HttpBaseResponse} Response object suitable for runtime.
|
|
145
|
+
* @protected
|
|
154
146
|
*/
|
|
155
|
-
|
|
147
|
+
newResponse(body: BodyInit | null, init?: ResponseInit): Response;
|
|
156
148
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
149
|
+
* Sends a plain text response.
|
|
150
|
+
*
|
|
151
|
+
* Automatically sets Content-Type to `text/plain; charset=utf-8`.
|
|
152
|
+
*
|
|
153
|
+
* @param {string} content - The plain text content.
|
|
154
|
+
* @param {ResponseInit} [init] - Optional response init.
|
|
155
|
+
* @returns {HttpBaseResponse} The response object.
|
|
161
156
|
*/
|
|
162
|
-
|
|
157
|
+
text(content: string, init?: ResponseInit): HttpBaseResponse;
|
|
163
158
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
159
|
+
* Sends an HTML response.
|
|
160
|
+
*
|
|
161
|
+
* Supports both:
|
|
162
|
+
* - Simple string: `ctx.html("<h1>Hello</h1>")`
|
|
163
|
+
* - Template literal: `ctx.html`<h1>${title}</h1>``
|
|
164
|
+
*
|
|
165
|
+
* Minimizes intermediate string allocations for lower GC overhead.
|
|
166
|
+
*
|
|
167
|
+
* @param {string | readonly string[]} strings - HTML string or template literal array.
|
|
168
|
+
* @param {...any[]} args - Values for template literals or a ResponseInit object if using a string.
|
|
169
|
+
* @returns {HttpBaseResponse} Constructed HTML response.
|
|
169
170
|
*/
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
sendFile(filePath: string, fileName?: string): Promise<Response>;
|
|
171
|
+
html(strings: string, init?: ResponseInit): HttpBaseResponse;
|
|
172
|
+
html(strings: readonly string[], ...values: any[]): HttpBaseResponse;
|
|
173
173
|
/**
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* -
|
|
178
|
-
* -
|
|
174
|
+
* Sends an XML response.
|
|
175
|
+
*
|
|
176
|
+
* Supports both:
|
|
177
|
+
* - Simple string: `ctx.xml("<note><to>User</to></note>")`
|
|
178
|
+
* - Template literal: `ctx.xml`<note><to>${user}</to></note>``
|
|
179
|
+
*
|
|
180
|
+
* Minimizes intermediate string allocations for lower GC overhead.
|
|
181
|
+
*
|
|
182
|
+
* @param {string | readonly string[]} strings - XML string or template literal array.
|
|
183
|
+
* @param {...any[]} args - Values for template literals or a ResponseInit object if using a string.
|
|
184
|
+
* @returns {HttpBaseResponse} Constructed XML response.
|
|
185
|
+
*/
|
|
186
|
+
xml(strings: string, init?: ResponseInit): HttpBaseResponse;
|
|
187
|
+
xml(strings: readonly string[], ...values: any[]): HttpBaseResponse;
|
|
188
|
+
/**
|
|
189
|
+
* Sends a JSON response.
|
|
190
|
+
*
|
|
191
|
+
* Automatically sets Content-Type to `application/json; charset=utf-8`.
|
|
192
|
+
*
|
|
193
|
+
* @param {object} json - JSON-serializable object.
|
|
194
|
+
* @param {ResponseInit} [init] - Optional response init overrides.
|
|
195
|
+
* @returns {HttpBaseResponse} A JSON response object.
|
|
179
196
|
*
|
|
180
197
|
* @example
|
|
181
|
-
*
|
|
182
|
-
* const request = ctx.req;
|
|
183
|
-
* // Access route params
|
|
184
|
-
* const id = request.params.get('id');
|
|
198
|
+
* ctx.json({ success: true });
|
|
185
199
|
*/
|
|
186
|
-
|
|
187
|
-
protected set params(params: Record<string, any>);
|
|
200
|
+
json(json: object, init?: ResponseInit): HttpBaseResponse;
|
|
188
201
|
/**
|
|
189
|
-
*
|
|
202
|
+
* Sends a response with automatic content type detection.
|
|
190
203
|
*
|
|
191
|
-
*
|
|
192
|
-
* - Middleware or route handlers can set this value to share data.
|
|
193
|
-
* - If no explicit Response is returned (e.g., `ctx.json()` or `new Response()`),
|
|
194
|
-
* then this body will be auto-wrapped into a `Response` by the framework.
|
|
204
|
+
* Uses `determineContentTypeBody` utility to infer Content-Type.
|
|
195
205
|
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
206
|
+
* @param {*} body - Response body.
|
|
207
|
+
* @param {ResponseInit} [init] - Optional response init.
|
|
208
|
+
* @returns {HttpBaseResponse} The response object.
|
|
209
|
+
*/
|
|
210
|
+
send(body: any, init?: ResponseInit): HttpBaseResponse;
|
|
211
|
+
/**
|
|
212
|
+
* Sends an HTTP redirect response to the specified URL.
|
|
199
213
|
*
|
|
200
|
-
* @param
|
|
214
|
+
* @param {string} url - Target URL to redirect to.
|
|
215
|
+
* @param {number} [status=302] - Redirect HTTP status code.
|
|
216
|
+
* @returns {Response} A native redirect response.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ctx.redirect("/login", 301);
|
|
201
220
|
*/
|
|
202
|
-
|
|
221
|
+
redirect(url: string, status?: number): Response;
|
|
203
222
|
/**
|
|
204
|
-
*
|
|
223
|
+
* Sends a file as a downloadable response.
|
|
224
|
+
*
|
|
225
|
+
* @param {string} filePath - Absolute file path on the server.
|
|
226
|
+
* @param {string} filename - Filename to present to the client.
|
|
227
|
+
* @returns {Promise<HttpBaseResponse>} Response that triggers download.
|
|
205
228
|
*
|
|
206
|
-
*
|
|
207
|
-
* - Allows middleware or route handler to access any pre-set data
|
|
208
|
-
* from earlier in the middleware chain.
|
|
209
|
-
* - Common for situations where response is deferred or centrally handled.
|
|
229
|
+
* @throws {Error} If file is not found.
|
|
210
230
|
*
|
|
211
|
-
* @
|
|
231
|
+
* @example
|
|
232
|
+
* await ctx.download("/files/report.pdf", "report.pdf");
|
|
212
233
|
*/
|
|
213
|
-
|
|
214
|
-
|
|
234
|
+
download(filePath: string, filename: string): Promise<HttpBaseResponse>;
|
|
235
|
+
/**
|
|
236
|
+
* Sends a file as a stream response.
|
|
237
|
+
*
|
|
238
|
+
* Automatically sets appropriate `Content-Type` and `Content-Length`.
|
|
239
|
+
* Adds `Content-Disposition` if filename is provided.
|
|
240
|
+
*
|
|
241
|
+
* @param {string} filePath - Absolute path to the file.
|
|
242
|
+
* @param {Object} [init] - Response options and optional download filename.
|
|
243
|
+
* @param {string} [init.filename] - Name to suggest for download.
|
|
244
|
+
* @returns {Promise<HttpBaseResponse>} A streamable file response.
|
|
245
|
+
*
|
|
246
|
+
* @throws {Error} If the file does not exist.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* await ctx.sendFile("/path/to/image.png");
|
|
250
|
+
*/
|
|
251
|
+
sendFile(filePath: string, init?: ResponseInit & {
|
|
252
|
+
filename?: string;
|
|
253
|
+
}): Promise<HttpBaseResponse>;
|
|
254
|
+
/**
|
|
255
|
+
*@property bun [server]
|
|
256
|
+
*@property deno [connInfo]
|
|
257
|
+
*@property node [res, server]
|
|
258
|
+
*/
|
|
259
|
+
protected get args(): any;
|
|
215
260
|
}
|