tezx 1.0.21 → 1.0.23
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/.gitignore +22 -0
- package/.npmignore +18 -0
- package/MiddlewareConfigure.d.ts +17 -0
- package/MiddlewareConfigure.js +63 -0
- package/adapter.d.ts +10 -0
- package/adapter.js +162 -0
- package/common.d.ts +21 -0
- package/common.js +11 -0
- package/config/config.d.ts +17 -0
- package/config/config.js +31 -0
- package/context.d.ts +195 -0
- package/context.js +424 -0
- package/environment.d.ts +6 -0
- package/environment.js +30 -0
- package/header.d.ts +71 -0
- package/header.js +81 -0
- package/package.json +2 -6
- package/request.d.ts +82 -0
- package/request.js +76 -0
- package/router.d.ts +191 -0
- package/router.js +373 -0
- package/server.d.ts +54 -0
- package/server.js +166 -0
- package/utils/colors.d.ts +21 -0
- package/utils/colors.js +21 -0
- package/utils/debugging.d.ts +7 -0
- package/utils/debugging.js +13 -0
- package/utils/formData.d.ts +5 -0
- package/utils/formData.js +213 -0
- package/utils/params.d.ts +7 -0
- package/utils/params.js +91 -0
- package/utils/state.d.ts +50 -0
- package/utils/state.js +30 -0
- package/utils/staticFile.d.ts +9 -0
- package/utils/staticFile.js +154 -0
- package/utils/url.d.ts +16 -0
- package/utils/url.js +55 -0
package/.gitignore
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
/.pnp
|
|
6
|
+
.pnp.js
|
|
7
|
+
|
|
8
|
+
# testing
|
|
9
|
+
/coverage
|
|
10
|
+
|
|
11
|
+
# production
|
|
12
|
+
/build
|
|
13
|
+
|
|
14
|
+
# debug
|
|
15
|
+
npm-debug.log*
|
|
16
|
+
yarn-debug.log*
|
|
17
|
+
yarn-error.log*
|
|
18
|
+
|
|
19
|
+
# local env files
|
|
20
|
+
.env*.local
|
|
21
|
+
|
|
22
|
+
|
package/.npmignore
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Ignore all .ts files except .d.ts files
|
|
2
|
+
*.ts
|
|
3
|
+
|
|
4
|
+
# Optional: Allow specific .ts files if needed
|
|
5
|
+
# !/specific-directory/*.ts
|
|
6
|
+
/test
|
|
7
|
+
/query
|
|
8
|
+
/utilities
|
|
9
|
+
/docs
|
|
10
|
+
/dist/test
|
|
11
|
+
/src
|
|
12
|
+
/dist/DataTypes
|
|
13
|
+
!/dist/index.d.ts
|
|
14
|
+
*.md
|
|
15
|
+
!README.md
|
|
16
|
+
tsconfig.json
|
|
17
|
+
.npmignore
|
|
18
|
+
.gitignore
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CommonHandler } from "./common";
|
|
2
|
+
import { Middleware } from "./router";
|
|
3
|
+
export type DuplicateMiddlewares = Middleware<any>[];
|
|
4
|
+
export type UniqueMiddlewares = Set<Middleware<any>>;
|
|
5
|
+
export declare class TriMiddleware {
|
|
6
|
+
children: Map<string, TriMiddleware>;
|
|
7
|
+
middlewares: DuplicateMiddlewares | UniqueMiddlewares;
|
|
8
|
+
isOptional: boolean;
|
|
9
|
+
pathname: string;
|
|
10
|
+
constructor(pathname?: string);
|
|
11
|
+
}
|
|
12
|
+
export default class MiddlewareConfigure<T extends Record<string, any> = {}> extends CommonHandler {
|
|
13
|
+
triMiddlewares: TriMiddleware;
|
|
14
|
+
protected basePath: string;
|
|
15
|
+
constructor(basePath?: string);
|
|
16
|
+
protected addMiddleware(pathname: string, middlewares: Middleware<T>[]): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CommonHandler } from "./common";
|
|
2
|
+
import { GlobalConfig } from "./config/config";
|
|
3
|
+
import { sanitizePathSplit } from "./utils/url";
|
|
4
|
+
export class TriMiddleware {
|
|
5
|
+
children = new Map();
|
|
6
|
+
middlewares = new Set();
|
|
7
|
+
isOptional = false;
|
|
8
|
+
pathname;
|
|
9
|
+
constructor(pathname = "/") {
|
|
10
|
+
this.pathname = pathname;
|
|
11
|
+
if (GlobalConfig.allowDuplicateMw) {
|
|
12
|
+
this.middlewares = [];
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
this.middlewares = new Set();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export default class MiddlewareConfigure extends CommonHandler {
|
|
20
|
+
triMiddlewares = new TriMiddleware();
|
|
21
|
+
basePath;
|
|
22
|
+
constructor(basePath = "/") {
|
|
23
|
+
super();
|
|
24
|
+
this.basePath = basePath;
|
|
25
|
+
}
|
|
26
|
+
addMiddleware(pathname, middlewares) {
|
|
27
|
+
const parts = sanitizePathSplit(this.basePath, pathname);
|
|
28
|
+
let node = this.triMiddlewares;
|
|
29
|
+
for (const part of parts) {
|
|
30
|
+
if (part.startsWith("*")) {
|
|
31
|
+
if (!node.children.has("*")) {
|
|
32
|
+
node.children.set("*", new TriMiddleware());
|
|
33
|
+
}
|
|
34
|
+
node = node.children.get("*");
|
|
35
|
+
}
|
|
36
|
+
else if (part.startsWith(":")) {
|
|
37
|
+
const isOptional = part?.endsWith("?");
|
|
38
|
+
if (isOptional) {
|
|
39
|
+
node.isOptional = isOptional;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (!node.children.has(":")) {
|
|
43
|
+
node.children.set(":", new TriMiddleware());
|
|
44
|
+
}
|
|
45
|
+
node = node.children.get(":");
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
if (!node.children.has(part)) {
|
|
49
|
+
node.children.set(part, new TriMiddleware());
|
|
50
|
+
}
|
|
51
|
+
node = node.children.get(part);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (GlobalConfig.allowDuplicateMw) {
|
|
55
|
+
node.middlewares.push(...middlewares);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
for (const middleware of middlewares) {
|
|
59
|
+
node.middlewares.add(middleware);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
package/adapter.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TezX } from "./server";
|
|
2
|
+
export declare function denoAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>): {
|
|
3
|
+
listen: (port: number, callback?: (message: string) => void) => any;
|
|
4
|
+
};
|
|
5
|
+
export declare function bunAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>): {
|
|
6
|
+
listen: (port: number, callback?: (message: string) => void) => any;
|
|
7
|
+
};
|
|
8
|
+
export declare function nodeAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>): {
|
|
9
|
+
listen: (port: number, callback?: (message: string) => void) => void;
|
|
10
|
+
};
|
package/adapter.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { GlobalConfig } from "./config/config";
|
|
2
|
+
export function denoAdapter(TezX) {
|
|
3
|
+
function listen(port, callback) {
|
|
4
|
+
const isDeno = typeof Deno !== "undefined";
|
|
5
|
+
try {
|
|
6
|
+
async function handleRequest(req, connInfo) {
|
|
7
|
+
let remoteAddr = connInfo.remoteAddr;
|
|
8
|
+
let localAddr = { ...server.addr };
|
|
9
|
+
let address = {
|
|
10
|
+
remoteAddr: {
|
|
11
|
+
port: remoteAddr?.port,
|
|
12
|
+
address: remoteAddr?.hostname,
|
|
13
|
+
transport: remoteAddr?.transport,
|
|
14
|
+
family: remoteAddr?.family,
|
|
15
|
+
},
|
|
16
|
+
localAddr: {
|
|
17
|
+
port: localAddr?.port,
|
|
18
|
+
address: localAddr?.hostname,
|
|
19
|
+
transport: localAddr?.transport,
|
|
20
|
+
family: localAddr?.family,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
const response = await TezX.serve(req, address);
|
|
24
|
+
if (response instanceof Response) {
|
|
25
|
+
return response;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return new Response(response.body, {
|
|
29
|
+
status: response.status,
|
|
30
|
+
statusText: response.statusText || "",
|
|
31
|
+
headers: new Headers(response.headers),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const server = isDeno ? Deno.serve({ port }, handleRequest) : null;
|
|
36
|
+
GlobalConfig.serverInfo = server;
|
|
37
|
+
if (!server) {
|
|
38
|
+
throw new Error("Deno is not find");
|
|
39
|
+
}
|
|
40
|
+
const protocol = "\x1b[1;34mhttp\x1b[0m";
|
|
41
|
+
const message = `\x1b[1m🚀 Deno TezX Server running at ${protocol}://localhost:${port}/\x1b[0m`;
|
|
42
|
+
if (typeof callback === "function") {
|
|
43
|
+
callback(message);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
GlobalConfig.debugging.success(message);
|
|
47
|
+
}
|
|
48
|
+
return server;
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
throw new Error(err?.message);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
listen,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function bunAdapter(TezX) {
|
|
59
|
+
function listen(port, callback) {
|
|
60
|
+
const serve = typeof Bun !== "undefined" ? Bun.serve : null;
|
|
61
|
+
try {
|
|
62
|
+
if (!serve) {
|
|
63
|
+
throw new Error("Bun is not find");
|
|
64
|
+
}
|
|
65
|
+
const server = serve({
|
|
66
|
+
port: port,
|
|
67
|
+
async fetch(req) {
|
|
68
|
+
const response = await TezX.serve(req, {
|
|
69
|
+
remoteAddr: server.requestIP(req),
|
|
70
|
+
localAddr: server.address,
|
|
71
|
+
});
|
|
72
|
+
if (response instanceof Response) {
|
|
73
|
+
return response;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
return new Response(response.body, {
|
|
77
|
+
status: response.status,
|
|
78
|
+
statusText: response.statusText || "",
|
|
79
|
+
headers: new Headers(response.headers),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
GlobalConfig.serverInfo = server;
|
|
85
|
+
const protocol = "\x1b[1;34mhttp\x1b[0m";
|
|
86
|
+
const message = `\x1b[1m Bun TezX Server running at ${protocol}://localhost:${port}/\x1b[0m`;
|
|
87
|
+
if (typeof callback == "function") {
|
|
88
|
+
callback(message);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
GlobalConfig.debugging.success(message);
|
|
92
|
+
}
|
|
93
|
+
return server;
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
throw new Error(err?.message);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
listen,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export function nodeAdapter(TezX) {
|
|
104
|
+
function listen(port, callback) {
|
|
105
|
+
import("http")
|
|
106
|
+
.then((r) => {
|
|
107
|
+
let server = r.createServer(async (req, res) => {
|
|
108
|
+
let address = {};
|
|
109
|
+
if (req.socket) {
|
|
110
|
+
address = {
|
|
111
|
+
remoteAddr: {
|
|
112
|
+
family: req.socket.remoteFamily,
|
|
113
|
+
address: req.socket.remoteAddress,
|
|
114
|
+
port: req.socket.remotePort,
|
|
115
|
+
},
|
|
116
|
+
localAddr: {
|
|
117
|
+
address: req.socket.localAddress,
|
|
118
|
+
port: req.socket.localPort,
|
|
119
|
+
family: req.socket.localFamily,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const response = await TezX.serve(req, address);
|
|
124
|
+
const statusText = response?.statusText;
|
|
125
|
+
if (!(response instanceof Response)) {
|
|
126
|
+
throw new Error("Invalid response from TezX.serve");
|
|
127
|
+
}
|
|
128
|
+
const headers = Object.fromEntries(await response.headers.entries());
|
|
129
|
+
if (statusText) {
|
|
130
|
+
res.statusMessage = statusText;
|
|
131
|
+
}
|
|
132
|
+
res.writeHead(response.status, headers);
|
|
133
|
+
const { Readable } = await import("stream");
|
|
134
|
+
if (response.body instanceof Readable) {
|
|
135
|
+
response.body.pipe(res);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
const body = await response.arrayBuffer();
|
|
139
|
+
res.end(Buffer.from(body));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
server.listen(port, () => {
|
|
143
|
+
const protocol = "\x1b[1;34mhttp\x1b[0m";
|
|
144
|
+
const message = `\x1b[1m NodeJS TezX Server running at ${protocol}://localhost:${port}/\x1b[0m`;
|
|
145
|
+
GlobalConfig.serverInfo = server;
|
|
146
|
+
if (typeof callback == "function") {
|
|
147
|
+
callback(message);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
GlobalConfig.debugging.success(message);
|
|
151
|
+
}
|
|
152
|
+
return server;
|
|
153
|
+
});
|
|
154
|
+
})
|
|
155
|
+
.catch((r) => {
|
|
156
|
+
throw Error(r.message);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
listen,
|
|
161
|
+
};
|
|
162
|
+
}
|
package/common.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context } from "./context";
|
|
2
|
+
import { Callback, ctx } from "./router";
|
|
3
|
+
export interface option {
|
|
4
|
+
status?: number;
|
|
5
|
+
}
|
|
6
|
+
export type onError<T> = (error: string, ctx: Context) => void;
|
|
7
|
+
export declare class CommonHandler {
|
|
8
|
+
/**
|
|
9
|
+
* Register a custom 404 handler for missing routes
|
|
10
|
+
* @param {Callback} callback - Handler function to execute when no route matches
|
|
11
|
+
* @returns {this} - Returns current instance for chaining
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Register a custom not-found handler
|
|
15
|
+
* app.notFound((ctx) => {
|
|
16
|
+
* ctx.status(404).text('Custom not found message');
|
|
17
|
+
* });
|
|
18
|
+
*/
|
|
19
|
+
notFound(callback: Callback): this;
|
|
20
|
+
onError(callback: <T extends Record<string, any> = {}>(err: string, ctx: ctx<T>) => any): this;
|
|
21
|
+
}
|
package/common.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Callback, ctx } from "../router";
|
|
2
|
+
export declare let GlobalConfig: {
|
|
3
|
+
new (): {};
|
|
4
|
+
notFound: Callback;
|
|
5
|
+
onError: <T extends Record<string, any> = {}>(err: string, ctx: ctx<T>) => any;
|
|
6
|
+
allowDuplicateMw?: boolean;
|
|
7
|
+
overwriteMethod?: boolean;
|
|
8
|
+
debugMode?: boolean;
|
|
9
|
+
serverInfo: any;
|
|
10
|
+
readonly debugging: {
|
|
11
|
+
info: (msg: string, ...args: unknown[]) => void;
|
|
12
|
+
warn: (msg: string, ...args: unknown[]) => void;
|
|
13
|
+
error: (msg: string, ...args: unknown[]) => void;
|
|
14
|
+
debug: (msg: string, ...args: unknown[]) => void;
|
|
15
|
+
success: (msg: string, ...args: unknown[]) => void;
|
|
16
|
+
};
|
|
17
|
+
};
|
package/config/config.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { loggerOutput } from "../utils/debugging";
|
|
2
|
+
export let GlobalConfig = class {
|
|
3
|
+
static notFound = (ctx) => {
|
|
4
|
+
const { method, urlRef: { pathname }, } = ctx.req;
|
|
5
|
+
return ctx.text(`${method}: '${pathname}' could not find\n`, 404);
|
|
6
|
+
};
|
|
7
|
+
static onError = (err, ctx) => {
|
|
8
|
+
return ctx.text(err, 500);
|
|
9
|
+
};
|
|
10
|
+
static allowDuplicateMw = false;
|
|
11
|
+
static overwriteMethod = true;
|
|
12
|
+
static debugMode = false;
|
|
13
|
+
static serverInfo;
|
|
14
|
+
static get debugging() {
|
|
15
|
+
return this.debugMode
|
|
16
|
+
? {
|
|
17
|
+
info: (msg, ...args) => loggerOutput("info", msg, ...args),
|
|
18
|
+
warn: (msg, ...args) => loggerOutput("warn", msg, ...args),
|
|
19
|
+
error: (msg, ...args) => loggerOutput("error", msg, ...args),
|
|
20
|
+
debug: (msg, ...args) => loggerOutput("debug", msg, ...args),
|
|
21
|
+
success: (msg, ...args) => loggerOutput("success", msg, ...args),
|
|
22
|
+
}
|
|
23
|
+
: {
|
|
24
|
+
info: (msg, ...args) => { },
|
|
25
|
+
warn: (msg, ...args) => { },
|
|
26
|
+
error: (msg, ...args) => { },
|
|
27
|
+
debug: (msg, ...args) => { },
|
|
28
|
+
success: (msg, ...args) => { },
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
};
|
package/context.d.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { HeadersParser } from "./header";
|
|
2
|
+
import { ConnAddress, HTTPMethod, Request } from "./request";
|
|
3
|
+
import { State } from "./utils/state";
|
|
4
|
+
export interface CookieOptions {
|
|
5
|
+
expires?: Date;
|
|
6
|
+
path?: string;
|
|
7
|
+
maxAge?: number;
|
|
8
|
+
domain?: string;
|
|
9
|
+
secure?: boolean;
|
|
10
|
+
httpOnly?: boolean;
|
|
11
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
12
|
+
}
|
|
13
|
+
export declare const httpStatusMap: Record<number, string>;
|
|
14
|
+
export type ResponseHeaders = Record<string, string>;
|
|
15
|
+
export declare class Context<T extends Record<string, any> = {}> {
|
|
16
|
+
#private;
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
/**
|
|
19
|
+
* Environment variables and configuration
|
|
20
|
+
* @type {object}
|
|
21
|
+
*/
|
|
22
|
+
env: Record<string, any> & T;
|
|
23
|
+
/**
|
|
24
|
+
* Parser for handling and manipulating HTTP headers
|
|
25
|
+
* @type {HeadersParser}
|
|
26
|
+
*/
|
|
27
|
+
headers: HeadersParser;
|
|
28
|
+
/**
|
|
29
|
+
* Parser for handling and manipulating HTTP response(Read Only)
|
|
30
|
+
* @type {Response}
|
|
31
|
+
*/
|
|
32
|
+
readonly res: Response | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Request path without query parameters
|
|
35
|
+
* @type {string}
|
|
36
|
+
*/
|
|
37
|
+
readonly pathname: string;
|
|
38
|
+
/**
|
|
39
|
+
* Full request URL including protocol and query string
|
|
40
|
+
* @type {string}
|
|
41
|
+
*/
|
|
42
|
+
readonly url: string;
|
|
43
|
+
/**
|
|
44
|
+
* HTTP request method (GET, POST, PUT, DELETE, etc.)
|
|
45
|
+
* @type {HTTPMethod}
|
|
46
|
+
*/
|
|
47
|
+
readonly method: HTTPMethod;
|
|
48
|
+
/**
|
|
49
|
+
* Public state container for application data
|
|
50
|
+
* state storage for middleware and plugins
|
|
51
|
+
* @type {State}
|
|
52
|
+
*/
|
|
53
|
+
state: State;
|
|
54
|
+
constructor(req: any, connInfo: ConnAddress);
|
|
55
|
+
/**
|
|
56
|
+
* Cookie handling utility with get/set/delete operations
|
|
57
|
+
* @returns {{
|
|
58
|
+
* get: (name: string) => string | undefined,
|
|
59
|
+
* all: () => Record<string, string>,
|
|
60
|
+
* delete: (name: string, options?: CookieOptions) => void,
|
|
61
|
+
* set: (name: string, value: string, options?: CookieOptions) => void
|
|
62
|
+
* }} Cookie handling interface
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* Sets a header value.
|
|
66
|
+
* @param key - Header name.
|
|
67
|
+
* @param value - Header value(s).
|
|
68
|
+
*/
|
|
69
|
+
header(key: string, value: string | string[]): this;
|
|
70
|
+
get cookies(): {
|
|
71
|
+
/**
|
|
72
|
+
* Get a specific cookie by name.
|
|
73
|
+
* @param {string} cookie - The name of the cookie to retrieve.
|
|
74
|
+
* @returns {string | undefined} - The cookie value or undefined if not found.
|
|
75
|
+
*/
|
|
76
|
+
get: (cookie: string) => string;
|
|
77
|
+
/**
|
|
78
|
+
* Get all cookies as an object.
|
|
79
|
+
* @returns {Record<string, string>} - An object containing all cookies.
|
|
80
|
+
*/
|
|
81
|
+
all: () => Record<string, string>;
|
|
82
|
+
/**
|
|
83
|
+
* Delete a cookie by setting its expiration to the past.
|
|
84
|
+
* @param {string} name - The name of the cookie to delete.
|
|
85
|
+
* @param {CookieOptions} [options] - Additional cookie options.
|
|
86
|
+
*/
|
|
87
|
+
delete: (name: string, options?: CookieOptions) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Set a new cookie with the given name, value, and options.
|
|
90
|
+
* @param {string} name - The name of the cookie.
|
|
91
|
+
* @param {string} value - The value of the cookie.
|
|
92
|
+
* @param {CookieOptions} [options] - Additional options like expiration.
|
|
93
|
+
*/
|
|
94
|
+
set: (name: string, value: string, options?: CookieOptions) => void;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Sends a JSON response.
|
|
98
|
+
* @param body - The response data.
|
|
99
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
100
|
+
* @param headers - (Optional) Additional response headers.
|
|
101
|
+
* @returns Response object with JSON data.
|
|
102
|
+
*/
|
|
103
|
+
json(body: any, status?: number, headers?: ResponseHeaders): Response;
|
|
104
|
+
json(body: any, headers?: ResponseHeaders): Response;
|
|
105
|
+
json(body: any, status?: number): Response;
|
|
106
|
+
/**
|
|
107
|
+
* Sends a response with any content type.
|
|
108
|
+
* Automatically determines content type if not provided.
|
|
109
|
+
* @param body - The response body.
|
|
110
|
+
* @param status - (Optional) HTTP status code.
|
|
111
|
+
* @param headers - (Optional) Additional response headers.
|
|
112
|
+
* @returns Response object.
|
|
113
|
+
*/
|
|
114
|
+
send(body: any, status?: number, headers?: ResponseHeaders): any;
|
|
115
|
+
send(body: any, headers?: ResponseHeaders): any;
|
|
116
|
+
send(body: any, status?: number): any;
|
|
117
|
+
/**
|
|
118
|
+
* Sends an HTML response.
|
|
119
|
+
* @param data - The HTML content as a string.
|
|
120
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
121
|
+
* @param headers - (Optional) Additional response headers.
|
|
122
|
+
* @returns Response object with HTML data.
|
|
123
|
+
*/
|
|
124
|
+
html(data: string, status?: number, headers?: ResponseHeaders): any;
|
|
125
|
+
html(data: string, headers?: ResponseHeaders): any;
|
|
126
|
+
html(data: string, status?: number): any;
|
|
127
|
+
/**
|
|
128
|
+
* Sends a plain text response.
|
|
129
|
+
* @param data - The text content.
|
|
130
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
131
|
+
* @param headers - (Optional) Additional response headers.
|
|
132
|
+
* @returns Response object with plain text data.
|
|
133
|
+
*/
|
|
134
|
+
text(data: string, status?: number, headers?: ResponseHeaders): any;
|
|
135
|
+
text(data: string, headers?: ResponseHeaders): any;
|
|
136
|
+
text(data: string, status?: number): any;
|
|
137
|
+
/**
|
|
138
|
+
* Sends an XML response.
|
|
139
|
+
* @param data - The XML content.
|
|
140
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
141
|
+
* @param headers - (Optional) Additional response headers.
|
|
142
|
+
* @returns Response object with XML data.
|
|
143
|
+
*/
|
|
144
|
+
xml(data: string, status?: number, headers?: ResponseHeaders): any;
|
|
145
|
+
xml(data: string, headers?: ResponseHeaders): any;
|
|
146
|
+
xml(data: string, status?: number): any;
|
|
147
|
+
/**
|
|
148
|
+
* HTTP status code..
|
|
149
|
+
* @param status - number.
|
|
150
|
+
* @returns Response object with context all method.
|
|
151
|
+
*/
|
|
152
|
+
status: (status: number) => this;
|
|
153
|
+
set setStatus(status: number);
|
|
154
|
+
get getStatus(): number;
|
|
155
|
+
/**
|
|
156
|
+
* Redirects to a given URL.
|
|
157
|
+
* @param url - The target URL.
|
|
158
|
+
* @param status - (Optional) HTTP status code (default: 302).
|
|
159
|
+
* @returns Response object with redirect.
|
|
160
|
+
*/
|
|
161
|
+
redirect(url: string, status?: number): Response;
|
|
162
|
+
/**
|
|
163
|
+
* Handles file downloads.
|
|
164
|
+
* @param filePath - The path to the file.
|
|
165
|
+
* @param fileName - The name of the downloaded file.
|
|
166
|
+
* @returns Response object for file download.
|
|
167
|
+
*/
|
|
168
|
+
download(filePath: string, fileName: string): Promise<Response>;
|
|
169
|
+
/**
|
|
170
|
+
* Serves a file to the client.
|
|
171
|
+
* @param filePath - Absolute or relative path to the file.
|
|
172
|
+
* @param fileName - (Optional) The name of the send file.
|
|
173
|
+
* @param headers - (Optional) Additional headers.
|
|
174
|
+
* @returns Response object with the file stream.
|
|
175
|
+
*/
|
|
176
|
+
sendFile(filePath: string, fileName?: string, headers?: ResponseHeaders): Promise<Response>;
|
|
177
|
+
sendFile(filePath: string, headers?: ResponseHeaders): Promise<Response>;
|
|
178
|
+
sendFile(filePath: string, fileName?: string): Promise<Response>;
|
|
179
|
+
/**
|
|
180
|
+
* Getter that creates a standardized Request object from internal state
|
|
181
|
+
* @returns {Request} - Normalized request object combining:
|
|
182
|
+
* - Raw platform-specific request
|
|
183
|
+
* - Parsed headers
|
|
184
|
+
* - Route parameters
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* // Get standardized request
|
|
188
|
+
* const request = ctx.req;
|
|
189
|
+
* // Access route params
|
|
190
|
+
* const id = request.params.get('id');
|
|
191
|
+
*/
|
|
192
|
+
get req(): Request;
|
|
193
|
+
protected set params(params: Record<string, any>);
|
|
194
|
+
protected get params(): Record<string, any>;
|
|
195
|
+
}
|