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.
Files changed (234) hide show
  1. package/README.md +122 -89
  2. package/bun/getConnInfo.d.ts +21 -0
  3. package/bun/getConnInfo.js +9 -0
  4. package/bun/index.d.ts +10 -4
  5. package/bun/index.js +8 -4
  6. package/bun/ws.d.ts +48 -0
  7. package/bun/ws.js +58 -0
  8. package/cjs/bun/getConnInfo.js +12 -0
  9. package/cjs/bun/index.js +35 -7
  10. package/cjs/bun/ws.js +63 -0
  11. package/cjs/core/config.js +2 -12
  12. package/cjs/core/context.js +131 -379
  13. package/cjs/core/error.js +49 -0
  14. package/cjs/core/request.js +79 -131
  15. package/cjs/core/router.js +54 -387
  16. package/cjs/core/server.js +83 -202
  17. package/cjs/deno/env.js +4 -4
  18. package/cjs/deno/getConnInfo.js +18 -0
  19. package/cjs/deno/index.js +11 -18
  20. package/cjs/deno/serveStatic.js +53 -0
  21. package/cjs/deno/ws.js +39 -0
  22. package/cjs/helper/index.js +46 -10
  23. package/cjs/index.js +5 -7
  24. package/cjs/jwt/node.js +94 -0
  25. package/cjs/jwt/web.js +178 -0
  26. package/cjs/middleware/basic-auth.js +42 -0
  27. package/cjs/middleware/bearer-auth.js +34 -0
  28. package/cjs/middleware/cache-control.js +44 -0
  29. package/cjs/middleware/cors.js +11 -21
  30. package/cjs/middleware/detect-bot.js +57 -0
  31. package/cjs/middleware/i18n.js +73 -60
  32. package/cjs/middleware/index.js +8 -46
  33. package/cjs/middleware/logger.js +9 -4
  34. package/cjs/middleware/pagination.js +3 -2
  35. package/cjs/middleware/powered-by.js +3 -2
  36. package/cjs/middleware/rate-limiter.js +38 -0
  37. package/cjs/middleware/request-id.js +4 -5
  38. package/cjs/middleware/sanitize-headers.js +22 -0
  39. package/cjs/middleware/secure-headers copy.js +143 -0
  40. package/cjs/middleware/secure-headers.js +157 -0
  41. package/cjs/middleware/{xssProtection.js → xss-protection.js} +5 -8
  42. package/cjs/node/env.js +7 -7
  43. package/cjs/node/getConnInfo.js +16 -0
  44. package/cjs/node/index.js +17 -18
  45. package/cjs/node/mount-node.js +59 -0
  46. package/cjs/node/serveStatic.js +56 -0
  47. package/cjs/node/toWebRequest.js +25 -0
  48. package/cjs/node/ws.js +82 -0
  49. package/cjs/registry/RadixRouter.js +148 -0
  50. package/cjs/registry/index.js +17 -0
  51. package/cjs/types/headers.js +2 -0
  52. package/cjs/types/index.js +13 -0
  53. package/cjs/utils/buffer.js +17 -0
  54. package/cjs/utils/colors.js +2 -0
  55. package/cjs/utils/cookie.js +59 -0
  56. package/cjs/utils/file.js +136 -0
  57. package/cjs/utils/formData.js +60 -10
  58. package/cjs/utils/generateID.js +37 -0
  59. package/cjs/utils/low-level.js +115 -0
  60. package/cjs/utils/{staticFile.js → mimeTypes.js} +0 -87
  61. package/cjs/utils/rateLimit.js +41 -0
  62. package/cjs/utils/response.js +65 -0
  63. package/cjs/{core/environment.js → utils/runtime.js} +2 -1
  64. package/cjs/utils/url.js +65 -30
  65. package/core/config.d.ts +2 -7
  66. package/core/config.js +2 -12
  67. package/core/context.d.ts +209 -164
  68. package/core/context.js +131 -346
  69. package/core/error.d.ts +96 -0
  70. package/core/error.js +44 -0
  71. package/core/request.d.ts +67 -107
  72. package/core/request.js +78 -130
  73. package/core/router.d.ts +138 -133
  74. package/core/router.js +53 -352
  75. package/core/server.d.ts +99 -38
  76. package/core/server.js +83 -202
  77. package/deno/env.js +3 -3
  78. package/deno/getConnInfo.d.ts +21 -0
  79. package/deno/getConnInfo.js +15 -0
  80. package/deno/index.d.ts +9 -4
  81. package/deno/index.js +7 -4
  82. package/deno/serveStatic.d.ts +28 -0
  83. package/deno/serveStatic.js +49 -0
  84. package/deno/ws.d.ts +42 -0
  85. package/deno/ws.js +36 -0
  86. package/helper/index.d.ts +29 -15
  87. package/helper/index.js +27 -7
  88. package/index.d.ts +10 -8
  89. package/index.js +4 -5
  90. package/jwt/node.d.ts +39 -0
  91. package/jwt/node.js +87 -0
  92. package/jwt/web.d.ts +14 -0
  93. package/jwt/web.js +174 -0
  94. package/middleware/basic-auth.d.ts +56 -0
  95. package/middleware/basic-auth.js +38 -0
  96. package/middleware/bearer-auth.d.ts +53 -0
  97. package/middleware/bearer-auth.js +30 -0
  98. package/middleware/cache-control.d.ts +30 -0
  99. package/middleware/cache-control.js +40 -0
  100. package/middleware/cors.d.ts +30 -3
  101. package/middleware/cors.js +12 -22
  102. package/middleware/detect-bot.d.ts +113 -0
  103. package/middleware/detect-bot.js +53 -0
  104. package/middleware/i18n.d.ts +166 -73
  105. package/middleware/i18n.js +73 -60
  106. package/middleware/index.d.ts +8 -32
  107. package/middleware/index.js +8 -44
  108. package/middleware/logger.d.ts +5 -2
  109. package/middleware/logger.js +9 -4
  110. package/middleware/pagination.d.ts +9 -6
  111. package/middleware/pagination.js +3 -2
  112. package/middleware/powered-by.d.ts +2 -1
  113. package/middleware/powered-by.js +3 -2
  114. package/middleware/{rateLimiter.d.ts → rate-limiter.d.ts} +15 -9
  115. package/middleware/rate-limiter.js +34 -0
  116. package/middleware/request-id.d.ts +2 -1
  117. package/middleware/request-id.js +5 -6
  118. package/middleware/{sanitizeHeader.d.ts → sanitize-headers.d.ts} +5 -19
  119. package/middleware/sanitize-headers.js +18 -0
  120. package/middleware/secure-headers copy.d.ts +15 -0
  121. package/middleware/secure-headers copy.js +136 -0
  122. package/middleware/secure-headers.d.ts +132 -0
  123. package/middleware/secure-headers.js +153 -0
  124. package/middleware/{xssProtection.d.ts → xss-protection.d.ts} +2 -1
  125. package/middleware/xss-protection.js +19 -0
  126. package/node/env.js +4 -4
  127. package/node/getConnInfo.d.ts +21 -0
  128. package/node/getConnInfo.js +13 -0
  129. package/node/index.d.ts +13 -4
  130. package/node/index.js +11 -4
  131. package/node/mount-node.d.ts +11 -0
  132. package/node/mount-node.js +56 -0
  133. package/node/serveStatic.d.ts +36 -0
  134. package/node/serveStatic.js +52 -0
  135. package/node/toWebRequest.js +22 -0
  136. package/node/ws.d.ts +56 -0
  137. package/node/ws.js +46 -0
  138. package/package.json +39 -30
  139. package/registry/RadixRouter.d.ts +40 -0
  140. package/registry/RadixRouter.js +144 -0
  141. package/registry/index.d.ts +2 -0
  142. package/registry/index.js +1 -0
  143. package/types/headers.d.ts +2 -0
  144. package/types/headers.js +1 -0
  145. package/types/index.d.ts +318 -18
  146. package/types/index.js +12 -1
  147. package/utils/buffer.d.ts +1 -0
  148. package/utils/buffer.js +14 -0
  149. package/utils/colors.d.ts +24 -0
  150. package/utils/colors.js +2 -0
  151. package/utils/cookie.d.ts +55 -0
  152. package/utils/cookie.js +53 -0
  153. package/utils/file.d.ts +38 -0
  154. package/utils/file.js +96 -0
  155. package/utils/formData.d.ts +41 -1
  156. package/utils/formData.js +58 -9
  157. package/utils/generateID.d.ts +42 -0
  158. package/utils/generateID.js +32 -0
  159. package/utils/httpStatusMap.d.ts +14 -0
  160. package/utils/low-level.d.ts +58 -0
  161. package/utils/low-level.js +108 -0
  162. package/utils/mimeTypes.d.ts +4 -0
  163. package/utils/{staticFile.js → mimeTypes.js} +0 -53
  164. package/utils/rateLimit.d.ts +18 -0
  165. package/utils/rateLimit.js +37 -0
  166. package/utils/response.d.ts +18 -0
  167. package/utils/response.js +58 -0
  168. package/{core/environment.d.ts → utils/runtime.d.ts} +1 -0
  169. package/{core/environment.js → utils/runtime.js} +1 -0
  170. package/utils/url.d.ts +42 -14
  171. package/utils/url.js +61 -27
  172. package/bun/adapter.d.ts +0 -127
  173. package/bun/adapter.js +0 -97
  174. package/cjs/bun/adapter.js +0 -100
  175. package/cjs/core/MiddlewareConfigure.js +0 -68
  176. package/cjs/core/common.js +0 -15
  177. package/cjs/deno/adpater.js +0 -67
  178. package/cjs/helper/common.js +0 -17
  179. package/cjs/middleware/basicAuth.js +0 -71
  180. package/cjs/middleware/cacheControl.js +0 -90
  181. package/cjs/middleware/detectBot.js +0 -104
  182. package/cjs/middleware/detectLocale.js +0 -43
  183. package/cjs/middleware/lazyLoadModules.js +0 -73
  184. package/cjs/middleware/rateLimiter.js +0 -24
  185. package/cjs/middleware/requestTimeout.js +0 -42
  186. package/cjs/middleware/sanitizeHeader.js +0 -51
  187. package/cjs/middleware/secureHeaders.js +0 -42
  188. package/cjs/node/adapter.js +0 -138
  189. package/cjs/utils/regexRouter.js +0 -58
  190. package/cjs/utils/state.js +0 -34
  191. package/cjs/utils/toWebRequest.js +0 -35
  192. package/cjs/ws/deno.js +0 -20
  193. package/cjs/ws/index.js +0 -53
  194. package/cjs/ws/node.js +0 -65
  195. package/core/MiddlewareConfigure.d.ts +0 -15
  196. package/core/MiddlewareConfigure.js +0 -63
  197. package/core/common.d.ts +0 -21
  198. package/core/common.js +0 -11
  199. package/deno/adpater.d.ts +0 -38
  200. package/deno/adpater.js +0 -64
  201. package/helper/common.d.ts +0 -5
  202. package/helper/common.js +0 -14
  203. package/middleware/basicAuth.d.ts +0 -81
  204. package/middleware/basicAuth.js +0 -67
  205. package/middleware/cacheControl.d.ts +0 -48
  206. package/middleware/cacheControl.js +0 -53
  207. package/middleware/detectBot.d.ts +0 -121
  208. package/middleware/detectBot.js +0 -98
  209. package/middleware/detectLocale.d.ts +0 -55
  210. package/middleware/detectLocale.js +0 -39
  211. package/middleware/lazyLoadModules.d.ts +0 -72
  212. package/middleware/lazyLoadModules.js +0 -69
  213. package/middleware/rateLimiter.js +0 -20
  214. package/middleware/requestTimeout.d.ts +0 -25
  215. package/middleware/requestTimeout.js +0 -38
  216. package/middleware/sanitizeHeader.js +0 -47
  217. package/middleware/secureHeaders.d.ts +0 -78
  218. package/middleware/secureHeaders.js +0 -38
  219. package/middleware/xssProtection.js +0 -22
  220. package/node/adapter.d.ts +0 -46
  221. package/node/adapter.js +0 -102
  222. package/utils/regexRouter.d.ts +0 -66
  223. package/utils/regexRouter.js +0 -53
  224. package/utils/state.d.ts +0 -50
  225. package/utils/state.js +0 -30
  226. package/utils/staticFile.d.ts +0 -10
  227. package/utils/toWebRequest.js +0 -32
  228. package/ws/deno.d.ts +0 -6
  229. package/ws/deno.js +0 -16
  230. package/ws/index.d.ts +0 -180
  231. package/ws/index.js +0 -50
  232. package/ws/node.d.ts +0 -7
  233. package/ws/node.js +0 -28
  234. /package/{utils → node}/toWebRequest.d.ts +0 -0
package/core/context.d.ts CHANGED
@@ -1,215 +1,260 @@
1
- import { CookieOptions, HTTPMethod, PathType, ResponseHeaders } from "../types/index.js";
2
- import { State } from "../utils/state.js";
3
- import { Request as RequestParser } from "./request.js";
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
- * Environment variables and configuration
11
- * @type {object}
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
- env: Record<string, any> & T;
29
+ res?: Response;
14
30
  /**
15
- * Parser for handling and manipulating HTTP headers
16
- * @type {Headers}
31
+ * Environment variables or shared state accessible in context.
32
+ * @type {Record<string, any> & TEnv}
17
33
  */
18
- headers: Headers;
34
+ env: Record<string, any> & TEnv;
19
35
  /**
20
- * Request path without query parameters
36
+ * Request pathname (URL path without domain).
37
+ * @readonly
21
38
  * @type {string}
22
39
  */
23
40
  readonly pathname: string;
24
41
  /**
25
- * Full request URL including protocol and query string
42
+ * HTTP request method (e.g., GET, POST).
43
+ * @readonly
26
44
  * @type {string}
27
45
  */
28
- readonly url: string;
46
+ readonly method: string;
29
47
  /**
30
- * HTTP request method (GET, POST, PUT, DELETE, etc.)
31
- * @type {HTTPMethod}
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
- readonly method: HTTPMethod;
53
+ constructor(req: Request, pathname: string, method: string, env: Record<string, any> & TEnv, args: any[]);
34
54
  /**
35
- * Public state container for application data
36
- * state storage for middleware and plugins
37
- * @type {State}
55
+ * Gets the current HTTP status code.
56
+ * @returns {number} The HTTP status code.
38
57
  */
39
- state: State;
40
- protected readonly resBody?: BodyInit | null;
41
- constructor(req: any, options: TezXServeOptions);
58
+ get getStatus(): number;
42
59
  /**
43
- * Appends or set a value to an existing header or creates a new one.
44
- * @param key - Header name.
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
- header(key: string, value: string, options?: {
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
- * Cookie handling utility with get/set/delete operations
56
- * @returns {{
57
- * get: (name: string) => string | undefined,
58
- * all: () => Record<string, string>,
59
- * delete: (name: string, options?: CookieOptions) => void,
60
- * set: (name: string, value: string, options?: CookieOptions) => void
61
- * }} Cookie handling interface
62
- */
63
- get cookies(): {
64
- /**
65
- * Get a specific cookie by name.
66
- * @param {string} cookie - The name of the cookie to retrieve.
67
- * @returns {string | undefined} - The cookie value or undefined if not found.
68
- */
69
- get: (cookie: string) => string;
70
- /**
71
- * Get all cookies as an object.
72
- * @returns {Record<string, string>} - An object containing all cookies.
73
- */
74
- all: () => Record<string, string>;
75
- /**
76
- * Delete a cookie by setting its expiration to the past.
77
- * @param {string} name - The name of the cookie to delete.
78
- * @param {CookieOptions} [options] - Additional cookie options.
79
- */
80
- delete: (name: string, options?: CookieOptions) => void;
81
- /**
82
- * Set a new cookie with the given name, value, and options.
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
- * Sends a JSON response.
91
- * @param body - The response data.
92
- * @param status - (Optional) HTTP status code (default: 200).
93
- * @param headers - (Optional) Additional response headers.
94
- * @returns Response object with JSON data.
95
- */
96
- json(body: object, status?: number, headers?: ResponseHeaders): Response;
97
- json(body: object, headers?: ResponseHeaders): Response;
98
- json(body: object, status?: number): Response;
99
- /**
100
- * Sends a response with any content type.
101
- * Automatically determines content type if not provided.
102
- * @param body - The response body.
103
- * @param status - (Optional) HTTP status code.
104
- * @param headers - (Optional) Additional response headers.
105
- * @returns Response object.
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
- * Sends an HTML response.
112
- * @param strings - The HTML content as a string. Supports `both template literals` and plain string input..
113
- * @param status - (Optional) HTTP status code (default: 200).
114
- * @param headers - (Optional) Additional response headers.
115
- * @returns Response object with HTML data.
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
- html(strings: readonly string[], ...values: any[]): Response;
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
- * Sends a plain text response.
123
- * @param data - The text content.
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
- text(data: string, status?: number, headers?: ResponseHeaders): Response;
129
- text(data: string, headers?: ResponseHeaders): Response;
130
- text(data: string, status?: number): Response;
122
+ get body(): any;
131
123
  /**
132
- * Sends an XML response.
133
- * @param data - The XML content.
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
- xml(data: string, status?: number, headers?: ResponseHeaders): Response;
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
- * @param status - number.
144
- * @returns Response object with context all method.
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
- * Redirects to a given URL.
151
- * @param url - The target URL.
152
- * @param status - (Optional) HTTP status code (default: 302).
153
- * @returns Response object with redirect.
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
- redirect(url: string, status?: number): Response;
147
+ newResponse(body: BodyInit | null, init?: ResponseInit): Response;
156
148
  /**
157
- * Handles file downloads.
158
- * @param filePath - The path to the file.
159
- * @param fileName - The name of the downloaded file.
160
- * @returns Response object for file download.
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
- download(filePath: string, fileName: string): Promise<Response>;
157
+ text(content: string, init?: ResponseInit): HttpBaseResponse;
163
158
  /**
164
- * Serves a file to the client.
165
- * @param filePath - Absolute or relative path to the file.
166
- * @param fileName - (Optional) The name of the send file.
167
- * @param headers - (Optional) Additional headers.
168
- * @returns Response object with the file stream.
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
- sendFile(filePath: string, fileName?: string, headers?: ResponseHeaders): Promise<Response>;
171
- sendFile(filePath: string, headers?: ResponseHeaders): Promise<Response>;
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
- * Getter that creates a standardized Request object from internal state
175
- * @returns {Request} - Normalized request object combining:
176
- * - Raw platform-specific request
177
- * - Parsed headers
178
- * - Route parameters
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
- * // Get standardized request
182
- * const request = ctx.req;
183
- * // Access route params
184
- * const id = request.params.get('id');
198
+ * ctx.json({ success: true });
185
199
  */
186
- get req(): RequestParser<Path>;
187
- protected set params(params: Record<string, any>);
200
+ json(json: object, init?: ResponseInit): HttpBaseResponse;
188
201
  /**
189
- * Set response body to be passed between middlewares or returned as final output.
202
+ * Sends a response with automatic content type detection.
190
203
  *
191
- * 🔄 Use-case:
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
- * ⚠️ Note:
197
- * Always use `return next()` or an explicit return like `return ctx.json(...)`
198
- * to ensure proper flow control and response resolution.
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 body - The response content (string, object, etc).
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
- set body(body: any);
221
+ redirect(url: string, status?: number): Response;
203
222
  /**
204
- * Get the current response body.
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
- * 🧠 Use-case:
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
- * @returns The currently stored response body.
231
+ * @example
232
+ * await ctx.download("/files/report.pdf", "report.pdf");
212
233
  */
213
- get body(): any;
214
- protected get params(): Record<string, any>;
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
  }