skyguard-js 1.2.1 → 1.2.2

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 (39) hide show
  1. package/README.md +9 -683
  2. package/dist/app.d.ts +14 -9
  3. package/dist/app.js +27 -24
  4. package/dist/http/context.d.ts +115 -0
  5. package/dist/http/context.js +147 -0
  6. package/dist/http/httpAdapter.d.ts +4 -4
  7. package/dist/http/index.d.ts +1 -0
  8. package/dist/http/index.js +3 -1
  9. package/dist/http/nodeNativeHttp.d.ts +4 -4
  10. package/dist/http/nodeNativeHttp.js +11 -4
  11. package/dist/http/request.d.ts +4 -0
  12. package/dist/http/request.js +8 -0
  13. package/dist/http/response.d.ts +21 -2
  14. package/dist/http/response.js +30 -2
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.js +2 -2
  17. package/dist/middlewares/cors.d.ts +10 -4
  18. package/dist/middlewares/cors.js +35 -18
  19. package/dist/middlewares/csrf.js +33 -33
  20. package/dist/middlewares/index.d.ts +1 -1
  21. package/dist/middlewares/rateLimiter.d.ts +58 -6
  22. package/dist/middlewares/rateLimiter.js +149 -40
  23. package/dist/middlewares/session.js +4 -4
  24. package/dist/routing/routeResolveFunc.d.ts +10 -0
  25. package/dist/routing/routeResolveFunc.js +21 -0
  26. package/dist/routing/router.d.ts +16 -10
  27. package/dist/routing/router.js +32 -25
  28. package/dist/routing/routerGroup.d.ts +10 -5
  29. package/dist/routing/routerGroup.js +11 -10
  30. package/dist/storage/storage.d.ts +3 -3
  31. package/dist/storage/storage.js +7 -7
  32. package/dist/storage/types.d.ts +5 -5
  33. package/dist/storage/uploader.d.ts +9 -9
  34. package/dist/storage/uploader.js +62 -62
  35. package/dist/types/index.d.ts +11 -10
  36. package/dist/validators/validationSchema.js +8 -8
  37. package/package.json +2 -2
  38. package/dist/helpers/http.d.ts +0 -95
  39. package/dist/helpers/http.js +0 -112
package/dist/app.d.ts CHANGED
@@ -109,7 +109,7 @@ declare class App {
109
109
  *
110
110
  * @param port - TCP port to listen on
111
111
  */
112
- run(port: number, callback: VoidFunction, hostname?: string): void;
112
+ run(port?: number, callback?: VoidFunction, hostname?: string): void;
113
113
  /**
114
114
  * Configures HTTP request logger output format and optional file output.
115
115
  *
@@ -136,24 +136,29 @@ declare class App {
136
136
  */
137
137
  setPrefix(prefix: string): void;
138
138
  /** Registers a GET route */
139
- get(path: string, action: RouteHandler, middlewares?: Middleware[]): void;
139
+ get(path: string, action: RouteHandler): void;
140
+ get(path: string, middlewares: Middleware[], action: RouteHandler): void;
140
141
  /** Registers a POST route */
141
- post(path: string, action: RouteHandler, middlewares?: Middleware[]): void;
142
+ post(path: string, action: RouteHandler): void;
143
+ post(path: string, middlewares: Middleware[], action: RouteHandler): void;
142
144
  /** Registers a PUT route */
143
- put(path: string, action: RouteHandler, middlewares?: Middleware[]): void;
145
+ put(path: string, action: RouteHandler): void;
146
+ put(path: string, middlewares: Middleware[], action: RouteHandler): void;
144
147
  /** Registers a PATCH route */
145
- patch(path: string, action: RouteHandler, middlewares?: Middleware[]): void;
148
+ patch(path: string, action: RouteHandler): void;
149
+ patch(path: string, middlewares: Middleware[], action: RouteHandler): void;
146
150
  /** Registers a DELETE route */
147
- delete(path: string, action: RouteHandler, middlewares?: Middleware[]): void;
151
+ delete(path: string, action: RouteHandler): void;
152
+ delete(path: string, middlewares: Middleware[], action: RouteHandler): void;
148
153
  /**
149
154
  * Registers global middlewares.
150
155
  *
151
156
  * These are executed for every route.
152
157
  *
153
158
  * @example
154
- * const auth = async (request, next) => {
155
- * console.log(request.header);
156
- * return await next(request);
159
+ * const auth = async (context, next) => {
160
+ * console.log(context.headers);
161
+ * return await next(context);
157
162
  * }
158
163
  *
159
164
  * app.middlewares(auth);
package/dist/app.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createApp = void 0;
4
4
  const routing_1 = require("./routing");
5
+ const routeResolveFunc_1 = require("./routing/routeResolveFunc");
5
6
  const http_1 = require("./http");
6
7
  const validationException_1 = require("./exceptions/validationException");
7
8
  const node_path_1 = require("node:path");
@@ -71,15 +72,15 @@ class App {
71
72
  */
72
73
  async handle(adapter) {
73
74
  try {
74
- const request = await adapter.getRequest();
75
- if (this.staticFileHandler && request.method === http_1.HttpMethods.get) {
76
- const staticResponse = await this.staticFileHandler.tryServeFile(request.url);
75
+ const context = await adapter.getContext();
76
+ if (this.staticFileHandler && context.req.method === http_1.HttpMethods.get) {
77
+ const staticResponse = await this.staticFileHandler.tryServeFile(context.req.url);
77
78
  if (staticResponse) {
78
79
  adapter.sendResponse(staticResponse);
79
80
  return;
80
81
  }
81
82
  }
82
- const response = await this.router.resolve(request);
83
+ const response = await this.router.resolve(context);
83
84
  adapter.sendResponse(response);
84
85
  }
85
86
  catch (error) {
@@ -147,12 +148,13 @@ class App {
147
148
  *
148
149
  * @param port - TCP port to listen on
149
150
  */
150
- run(port, callback, hostname = "127.0.0.1") {
151
+ run(port = 3000, callback, hostname = "localhost") {
151
152
  (0, node_http_1.createServer)((req, res) => {
152
153
  const adapter = new http_1.NodeHttpAdapter(req, res, this.loggerOptions);
153
154
  void this.handle(adapter);
154
155
  }).listen(port, hostname, () => {
155
- callback();
156
+ if (callback)
157
+ callback();
156
158
  });
157
159
  }
158
160
  /**
@@ -192,25 +194,25 @@ class App {
192
194
  setPrefix(prefix) {
193
195
  this.router.setPrefix(prefix);
194
196
  }
195
- /** Registers a GET route */
196
- get(path, action, middlewares) {
197
- this.router.get(path, action, middlewares);
197
+ get(path, handlerOrMiddlewares, handler) {
198
+ const { action, middlewares } = (0, routeResolveFunc_1.normalizeRouteArgs)(handlerOrMiddlewares, handler);
199
+ this.router.get(path, middlewares, action);
198
200
  }
199
- /** Registers a POST route */
200
- post(path, action, middlewares) {
201
- this.router.post(path, action, middlewares);
201
+ post(path, handlerOrMiddlewares, handler) {
202
+ const { action, middlewares } = (0, routeResolveFunc_1.normalizeRouteArgs)(handlerOrMiddlewares, handler);
203
+ this.router.post(path, middlewares, action);
202
204
  }
203
- /** Registers a PUT route */
204
- put(path, action, middlewares) {
205
- this.router.put(path, action, middlewares);
205
+ put(path, handlerOrMiddlewares, handler) {
206
+ const { action, middlewares } = (0, routeResolveFunc_1.normalizeRouteArgs)(handlerOrMiddlewares, handler);
207
+ this.router.put(path, middlewares, action);
206
208
  }
207
- /** Registers a PATCH route */
208
- patch(path, action, middlewares) {
209
- this.router.patch(path, action, middlewares);
209
+ patch(path, handlerOrMiddlewares, handler) {
210
+ const { action, middlewares } = (0, routeResolveFunc_1.normalizeRouteArgs)(handlerOrMiddlewares, handler);
211
+ this.router.patch(path, middlewares, action);
210
212
  }
211
- /** Registers a DELETE route */
212
- delete(path, action, middlewares) {
213
- this.router.delete(path, action, middlewares);
213
+ delete(path, handlerOrMiddlewares, handler) {
214
+ const { action, middlewares } = (0, routeResolveFunc_1.normalizeRouteArgs)(handlerOrMiddlewares, handler);
215
+ this.router.delete(path, middlewares, action);
214
216
  }
215
217
  /**
216
218
  * Registers global middlewares.
@@ -218,9 +220,9 @@ class App {
218
220
  * These are executed for every route.
219
221
  *
220
222
  * @example
221
- * const auth = async (request, next) => {
222
- * console.log(request.header);
223
- * return await next(request);
223
+ * const auth = async (context, next) => {
224
+ * console.log(context.headers);
225
+ * return await next(context);
224
226
  * }
225
227
  *
226
228
  * app.middlewares(auth);
@@ -252,6 +254,7 @@ class App {
252
254
  }
253
255
  if (error instanceof validationException_1.ValidationException) {
254
256
  adapter.sendResponse(http_1.Response.json({
257
+ message: "Validation Error",
255
258
  errors: error.getErrorsByField(),
256
259
  }).setStatusCode(400));
257
260
  return;
@@ -0,0 +1,115 @@
1
+ import { IncomingHttpHeaders } from "node:http";
2
+ import { Request } from "./request";
3
+ import { Response } from "./response";
4
+ import { Readable } from "node:stream";
5
+ import { Session } from "../sessions";
6
+ /**
7
+ * Unified HTTP context shared by middleware and route handlers.
8
+ *
9
+ * This object wraps the current {@link Request} and exposes convenient
10
+ * read-only accessors (`headers`, `body`, `params`, etc.) plus response
11
+ * builder helpers (`json`, `text`, `redirect`, `stream`, `download`).
12
+ *
13
+ * @example
14
+ * app.get("/users/{id}", context => {
15
+ * return context.json({
16
+ * id: context.params.id,
17
+ * ip: context.remoteAddress,
18
+ * });
19
+ * });
20
+ */
21
+ export declare class Context {
22
+ private readonly _req;
23
+ /**
24
+ * @param _req - Current request wrapper instance.
25
+ */
26
+ constructor(_req: Request);
27
+ /**
28
+ * Returns a new empty response instance.
29
+ *
30
+ * Useful when constructing a response manually.
31
+ */
32
+ get res(): Response;
33
+ /**
34
+ * Returns the underlying request object.
35
+ */
36
+ get req(): Request;
37
+ /**
38
+ * Returns incoming request headers.
39
+ */
40
+ get headers(): IncomingHttpHeaders;
41
+ /**
42
+ * Returns the socket peer IP address when available.
43
+ */
44
+ get remoteAddress(): string | undefined;
45
+ /**
46
+ * Returns parsed request body.
47
+ */
48
+ get body(): Record<string, any>;
49
+ /**
50
+ * Returns route path parameters.
51
+ */
52
+ get params(): Record<string, any>;
53
+ /**
54
+ * Returns parsed query string values.
55
+ */
56
+ get query(): Record<string, any>;
57
+ /**
58
+ * Returns parsed request cookies.
59
+ */
60
+ get cookies(): Record<string, string>;
61
+ /**
62
+ * Returns request session wrapper.
63
+ */
64
+ get session(): Session;
65
+ /**
66
+ * Creates a JSON response.
67
+ *
68
+ * @param data - Serializable payload.
69
+ */
70
+ json(data: unknown): Response;
71
+ /**
72
+ * Creates a plain-text response.
73
+ *
74
+ * @param data - Text payload.
75
+ */
76
+ text(data: string): Response;
77
+ /**
78
+ * Creates an HTTP redirect response (302 by default).
79
+ *
80
+ * @param url - Redirect target URL.
81
+ */
82
+ redirect(url: string): Response;
83
+ /**
84
+ * Creates a streaming response.
85
+ *
86
+ * @param stream - Readable stream body.
87
+ * @param headers - Optional extra headers.
88
+ */
89
+ stream(stream: Readable, headers?: Record<string, string>): Response;
90
+ /**
91
+ * Creates a download response from a filesystem path.
92
+ *
93
+ * @param path - File path.
94
+ * @param filename - Optional download filename.
95
+ * @param headers - Optional additional headers.
96
+ */
97
+ download(path: string, filename?: string, headers?: Record<string, string>): Promise<Response>;
98
+ /**
99
+ * Renders a configured template with optional params.
100
+ *
101
+ * @param data - Template source or identifier depending on view engine setup.
102
+ * @param params - Template context values.
103
+ */
104
+ render(data: string, params?: Record<string, unknown>): Promise<Response>;
105
+ /**
106
+ * Sends a file for inline display.
107
+ *
108
+ * @param filePath - File path to send.
109
+ * @param options - Optional root and headers.
110
+ */
111
+ sendFile(filePath: string, options: {
112
+ headers?: Record<string, string>;
113
+ root?: string;
114
+ }): Promise<Response>;
115
+ }
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Context = void 0;
4
+ const response_1 = require("./response");
5
+ /**
6
+ * Unified HTTP context shared by middleware and route handlers.
7
+ *
8
+ * This object wraps the current {@link Request} and exposes convenient
9
+ * read-only accessors (`headers`, `body`, `params`, etc.) plus response
10
+ * builder helpers (`json`, `text`, `redirect`, `stream`, `download`).
11
+ *
12
+ * @example
13
+ * app.get("/users/{id}", context => {
14
+ * return context.json({
15
+ * id: context.params.id,
16
+ * ip: context.remoteAddress,
17
+ * });
18
+ * });
19
+ */
20
+ class Context {
21
+ _req;
22
+ /**
23
+ * @param _req - Current request wrapper instance.
24
+ */
25
+ constructor(_req) {
26
+ this._req = _req;
27
+ this._req = _req;
28
+ }
29
+ /**
30
+ * Returns a new empty response instance.
31
+ *
32
+ * Useful when constructing a response manually.
33
+ */
34
+ get res() {
35
+ return new response_1.Response();
36
+ }
37
+ /**
38
+ * Returns the underlying request object.
39
+ */
40
+ get req() {
41
+ return this._req;
42
+ }
43
+ /**
44
+ * Returns incoming request headers.
45
+ */
46
+ get headers() {
47
+ return this._req.headers;
48
+ }
49
+ /**
50
+ * Returns the socket peer IP address when available.
51
+ */
52
+ get remoteAddress() {
53
+ return this._req.remoteAddress;
54
+ }
55
+ /**
56
+ * Returns parsed request body.
57
+ */
58
+ get body() {
59
+ return this._req.body;
60
+ }
61
+ /**
62
+ * Returns route path parameters.
63
+ */
64
+ get params() {
65
+ return this._req.params;
66
+ }
67
+ /**
68
+ * Returns parsed query string values.
69
+ */
70
+ get query() {
71
+ return this._req.query;
72
+ }
73
+ /**
74
+ * Returns parsed request cookies.
75
+ */
76
+ get cookies() {
77
+ return this._req.cookies;
78
+ }
79
+ /**
80
+ * Returns request session wrapper.
81
+ */
82
+ get session() {
83
+ return this._req.session;
84
+ }
85
+ /**
86
+ * Creates a JSON response.
87
+ *
88
+ * @param data - Serializable payload.
89
+ */
90
+ json(data) {
91
+ return response_1.Response.json(data);
92
+ }
93
+ /**
94
+ * Creates a plain-text response.
95
+ *
96
+ * @param data - Text payload.
97
+ */
98
+ text(data) {
99
+ return response_1.Response.text(data);
100
+ }
101
+ /**
102
+ * Creates an HTTP redirect response (302 by default).
103
+ *
104
+ * @param url - Redirect target URL.
105
+ */
106
+ redirect(url) {
107
+ return response_1.Response.redirect(url);
108
+ }
109
+ /**
110
+ * Creates a streaming response.
111
+ *
112
+ * @param stream - Readable stream body.
113
+ * @param headers - Optional extra headers.
114
+ */
115
+ stream(stream, headers) {
116
+ return response_1.Response.stream(stream, headers);
117
+ }
118
+ /**
119
+ * Creates a download response from a filesystem path.
120
+ *
121
+ * @param path - File path.
122
+ * @param filename - Optional download filename.
123
+ * @param headers - Optional additional headers.
124
+ */
125
+ async download(path, filename, headers) {
126
+ return await response_1.Response.download(path, filename, headers);
127
+ }
128
+ /**
129
+ * Renders a configured template with optional params.
130
+ *
131
+ * @param data - Template source or identifier depending on view engine setup.
132
+ * @param params - Template context values.
133
+ */
134
+ async render(data, params) {
135
+ return await response_1.Response.render(data, params);
136
+ }
137
+ /**
138
+ * Sends a file for inline display.
139
+ *
140
+ * @param filePath - File path to send.
141
+ * @param options - Optional root and headers.
142
+ */
143
+ async sendFile(filePath, options) {
144
+ return await response_1.Response.sendFile(filePath, options);
145
+ }
146
+ }
147
+ exports.Context = Context;
@@ -1,4 +1,4 @@
1
- import { Request } from "./request";
1
+ import { Context } from "./context";
2
2
  import { Response } from "./response";
3
3
  /**
4
4
  * High-level contract that defines the framework entry port
@@ -9,12 +9,12 @@ import { Response } from "./response";
9
9
  */
10
10
  export interface HttpAdapter {
11
11
  /**
12
- * Builds and returns a {@link Request} instance from
12
+ * Builds and returns a {@link Context} instance from
13
13
  * the current connection context.
14
14
  *
15
- * @returns A promise that resolves to a {@link Request} object
15
+ * @returns A promise that resolves to a {@link Context} object
16
16
  */
17
- getRequest(): Promise<Request>;
17
+ getContext(): Promise<Context>;
18
18
  /**
19
19
  * Sends a {@link Response} to the client, mapping its status,
20
20
  * headers, and body to the underlying runtime protocol.
@@ -1,5 +1,6 @@
1
1
  export { Response } from "./response";
2
2
  export { Request } from "./request";
3
+ export { Context } from "./context";
3
4
  export { NodeHttpAdapter } from "./nodeNativeHttp";
4
5
  export { HttpMethods } from "./httpMethods";
5
6
  export { HttpAdapter } from "./httpAdapter";
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Logger = exports.HttpMethods = exports.NodeHttpAdapter = exports.Request = exports.Response = void 0;
3
+ exports.Logger = exports.HttpMethods = exports.NodeHttpAdapter = exports.Context = exports.Request = exports.Response = void 0;
4
4
  var response_1 = require("./response");
5
5
  Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return response_1.Response; } });
6
6
  var request_1 = require("./request");
7
7
  Object.defineProperty(exports, "Request", { enumerable: true, get: function () { return request_1.Request; } });
8
+ var context_1 = require("./context");
9
+ Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.Context; } });
8
10
  var nodeNativeHttp_1 = require("./nodeNativeHttp");
9
11
  Object.defineProperty(exports, "NodeHttpAdapter", { enumerable: true, get: function () { return nodeNativeHttp_1.NodeHttpAdapter; } });
10
12
  var httpMethods_1 = require("./httpMethods");
@@ -1,7 +1,7 @@
1
1
  import { IncomingMessage, ServerResponse } from "node:http";
2
2
  import type { HttpAdapter } from "./httpAdapter";
3
3
  import { Response } from "./response";
4
- import { Request } from "./request";
4
+ import { Context } from "./context";
5
5
  import { type LoggerOptions } from "./logger";
6
6
  /**
7
7
  * Node.js HTTP adapter.
@@ -26,12 +26,12 @@ export declare class NodeHttpAdapter implements HttpAdapter {
26
26
  */
27
27
  constructor(req: IncomingMessage, res: ServerResponse, loggerOptions?: LoggerOptions);
28
28
  /**
29
- * Builds and returns a {@link Request} instance from
29
+ * Builds and returns a {@link Context} instance from
30
30
  * the incoming Node.js request.
31
31
  *
32
- * @returns A fully constructed {@link Request} instance
32
+ * @returns A fully constructed {@link Context} instance
33
33
  */
34
- getRequest(): Promise<Request>;
34
+ getContext(): Promise<Context>;
35
35
  /**
36
36
  * Sends a framework {@link Response} to the client by mapping it
37
37
  * to the native Node.js {@link ServerResponse}.
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NodeHttpAdapter = void 0;
4
4
  const httpMethods_1 = require("./httpMethods");
5
5
  const request_1 = require("./request");
6
+ const context_1 = require("./context");
6
7
  const contentParserManager_1 = require("../parsers/contentParserManager");
7
8
  const logger_1 = require("./logger");
9
+ const node_stream_1 = require("node:stream");
8
10
  /**
9
11
  * Node.js HTTP adapter.
10
12
  *
@@ -34,24 +36,25 @@ class NodeHttpAdapter {
34
36
  this.contentParser = new contentParserManager_1.ContentParserManager();
35
37
  }
36
38
  /**
37
- * Builds and returns a {@link Request} instance from
39
+ * Builds and returns a {@link Context} instance from
38
40
  * the incoming Node.js request.
39
41
  *
40
- * @returns A fully constructed {@link Request} instance
42
+ * @returns A fully constructed {@link Context} instance
41
43
  */
42
- async getRequest() {
44
+ async getContext() {
43
45
  const url = new URL(this.req.url || "", `http://${this.req.headers.host}`);
44
46
  const request = new request_1.Request(url.pathname);
45
47
  request.setMethod(this.req.method || httpMethods_1.HttpMethods.get);
46
48
  request.setQuery(Object.fromEntries(url.searchParams.entries()));
47
49
  request.setHeaders(this.req.headers);
50
+ request.setRemoteAddress(this.req.socket?.remoteAddress);
48
51
  if (request.method === httpMethods_1.HttpMethods.post ||
49
52
  request.method === httpMethods_1.HttpMethods.put ||
50
53
  request.method === httpMethods_1.HttpMethods.patch) {
51
54
  const parsedData = await this.contentParser.parse(this.req);
52
55
  request.setBody(parsedData);
53
56
  }
54
- return request;
57
+ return new context_1.Context(request);
55
58
  }
56
59
  /**
57
60
  * Sends a framework {@link Response} to the client by mapping it
@@ -72,6 +75,10 @@ class NodeHttpAdapter {
72
75
  if (!response.content)
73
76
  this.res.removeHeader("Content-Type");
74
77
  this.logger.log(this.req, this.res, this.startTime);
78
+ if (response.content instanceof node_stream_1.Readable) {
79
+ response.content.pipe(this.res);
80
+ return;
81
+ }
75
82
  this.res.end(response.content);
76
83
  }
77
84
  }
@@ -29,6 +29,8 @@ export declare class Request {
29
29
  private _params;
30
30
  /** Session associated with the request */
31
31
  private _session;
32
+ /** Network peer address (adapter-provided). */
33
+ private _remoteAddress?;
32
34
  /**
33
35
  * Per-request shared state container.
34
36
  *
@@ -52,6 +54,8 @@ export declare class Request {
52
54
  setBody(body: Record<string, any>): void;
53
55
  get session(): Session;
54
56
  setSession(session: Session): void;
57
+ get remoteAddress(): string | undefined;
58
+ setRemoteAddress(remoteAddress: string): void;
55
59
  /**
56
60
  * Returns all request cookies as a key-value object.
57
61
  */
@@ -29,6 +29,8 @@ class Request {
29
29
  _params = Object.create(null);
30
30
  /** Session associated with the request */
31
31
  _session;
32
+ /** Network peer address (adapter-provided). */
33
+ _remoteAddress;
32
34
  /**
33
35
  * Per-request shared state container.
34
36
  *
@@ -80,6 +82,12 @@ class Request {
80
82
  setSession(session) {
81
83
  this._session = session;
82
84
  }
85
+ get remoteAddress() {
86
+ return this._remoteAddress;
87
+ }
88
+ setRemoteAddress(remoteAddress) {
89
+ this._remoteAddress = remoteAddress;
90
+ }
83
91
  /**
84
92
  * Returns all request cookies as a key-value object.
85
93
  */
@@ -1,5 +1,6 @@
1
1
  import { type CookieOptions } from "../sessions/cookies";
2
2
  import { IncomingHttpHeaders } from "node:http";
3
+ import { Readable } from "node:stream";
3
4
  /**
4
5
  * Represents an outgoing response sent to the client.
5
6
  *
@@ -56,8 +57,18 @@ export declare class Response {
56
57
  * .setContent("<h1>Hello</h1>");
57
58
  */
58
59
  setContentType(value: string): this;
59
- get content(): string | Buffer | null;
60
- setContent(content: string | Buffer): this;
60
+ get content(): string | Buffer | Readable | null;
61
+ setContent(content: string | Buffer | Readable): this;
62
+ /**
63
+ * Sets a readable stream as the response body.
64
+ *
65
+ * Use this when you need to send large payloads in chunks without
66
+ * buffering the full content in memory first.
67
+ *
68
+ * @param stream - Node.js readable stream
69
+ * @returns The current {@link Response} instance
70
+ */
71
+ stream(stream: Readable): this;
61
72
  /**
62
73
  * Prepares the response before being sent to the client.
63
74
  *
@@ -97,6 +108,14 @@ export declare class Response {
97
108
  * });
98
109
  */
99
110
  static text(data: string): Response;
111
+ /**
112
+ * Creates a response whose body is streamed.
113
+ *
114
+ * @param stream - Node.js readable stream
115
+ * @param headers - Optional headers to include in the response
116
+ * @returns A {@link Response} configured for streaming
117
+ */
118
+ static stream(stream: Readable, headers?: Record<string, string>): Response;
100
119
  /**
101
120
  * Creates an HTTP redirect response.
102
121
  *