tezx 1.0.4 → 1.0.5
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/dist/index.d.ts +711 -849
- package/dist/index.js +193 -218
- package/dist/index.mjs +194 -232
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,870 +1,760 @@
|
|
|
1
1
|
declare class HeadersParser {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
2
|
+
private headers;
|
|
3
|
+
constructor(init?: [string, string][] | Record<string, string>);
|
|
4
|
+
/**
|
|
5
|
+
* Adds multiple headers to the parser.
|
|
6
|
+
* @param headers - Headers as an array of tuples or a record object.
|
|
7
|
+
*/
|
|
8
|
+
add(headers: [string, string][] | Record<string, string>): this;
|
|
9
|
+
/**
|
|
10
|
+
* Sets a header value.
|
|
11
|
+
* @param key - Header name.
|
|
12
|
+
* @param value - Header value(s).
|
|
13
|
+
*/
|
|
14
|
+
set(key: string, value: string | string[]): this;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the first value of a header.
|
|
17
|
+
* @param key - Header name.
|
|
18
|
+
* @returns The first header value or undefined if not found.
|
|
19
|
+
*/
|
|
20
|
+
get(key: string): string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves all values of a header.
|
|
23
|
+
* @param key - Header name.
|
|
24
|
+
* @returns An array of header values.
|
|
25
|
+
*/
|
|
26
|
+
getAll(key: string): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a header exists.
|
|
29
|
+
* @param key - Header name.
|
|
30
|
+
* @returns True if the header exists, false otherwise.
|
|
31
|
+
*/
|
|
32
|
+
has(key: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Deletes a header.
|
|
35
|
+
* @param key - Header name.
|
|
36
|
+
* @returns True if deleted successfully, false otherwise.
|
|
37
|
+
*/
|
|
38
|
+
delete(key: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Appends a value to an existing header or creates a new one.
|
|
41
|
+
* @param key - Header name.
|
|
42
|
+
* @param value - Value to append.
|
|
43
|
+
*/
|
|
44
|
+
append(key: string, value: string): this;
|
|
45
|
+
/**
|
|
46
|
+
* Returns an iterator over header entries.
|
|
47
|
+
* @returns IterableIterator of header key-value pairs.
|
|
48
|
+
*/
|
|
49
|
+
entries(): IterableIterator<[string, string[]]>;
|
|
50
|
+
/**
|
|
51
|
+
* Returns an iterator over header keys.
|
|
52
|
+
* @returns IterableIterator of header names.
|
|
53
|
+
*/
|
|
54
|
+
keys(): IterableIterator<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Returns an iterator over header values.
|
|
57
|
+
* @returns IterableIterator of header values arrays.
|
|
58
|
+
*/
|
|
59
|
+
values(): IterableIterator<string[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Iterates over headers and executes a callback function.
|
|
62
|
+
* @param callback - Function to execute for each header.
|
|
63
|
+
*/
|
|
64
|
+
forEach(callback: (value: string[], key: string) => void): void;
|
|
65
|
+
/**
|
|
66
|
+
* Converts headers into a plain object.
|
|
67
|
+
* @returns A record of headers where single-value headers are returned as a string.
|
|
68
|
+
*/
|
|
69
|
+
toObject(): Record<string, string | string[]>;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
type UrlRef = {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
hash: string | undefined;
|
|
74
|
+
protocol: string | undefined;
|
|
75
|
+
origin: string | undefined;
|
|
76
|
+
username: string | undefined;
|
|
77
|
+
password: string | undefined;
|
|
78
|
+
hostname: string | undefined;
|
|
79
|
+
port: string | undefined;
|
|
80
|
+
href: string | undefined;
|
|
81
|
+
query: {
|
|
82
|
+
[key: string]: string;
|
|
83
|
+
};
|
|
84
|
+
pathname: string | undefined;
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
type FormDataOptions = {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
maxSize?: number;
|
|
89
|
+
allowedTypes?: string[];
|
|
90
|
+
sanitized?: boolean;
|
|
91
|
+
maxFiles?: number;
|
|
92
92
|
};
|
|
93
|
-
type HTTPMethod =
|
|
94
|
-
| "GET"
|
|
95
|
-
| "POST"
|
|
96
|
-
| "PUT"
|
|
97
|
-
| "DELETE"
|
|
98
|
-
| "OPTIONS"
|
|
99
|
-
| "PATCH"
|
|
100
|
-
| "HEAD"
|
|
101
|
-
| "ALL"
|
|
102
|
-
| "TRACE"
|
|
103
|
-
| "CONNECT"
|
|
104
|
-
| string;
|
|
93
|
+
type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "OPTIONS" | "PATCH" | "HEAD" | "ALL" | "TRACE" | "CONNECT" | string;
|
|
105
94
|
declare class Request$1 {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
95
|
+
#private;
|
|
96
|
+
headers: HeadersParser;
|
|
97
|
+
/**
|
|
98
|
+
* Full request URL including protocol and query string
|
|
99
|
+
* @type {string}
|
|
100
|
+
*/
|
|
101
|
+
readonly url: string;
|
|
102
|
+
/**
|
|
103
|
+
* HTTP request method (GET, POST, PUT, DELETE, etc.)
|
|
104
|
+
* @type {HTTPMethod}
|
|
105
|
+
*/
|
|
106
|
+
readonly method: HTTPMethod;
|
|
107
|
+
/** Parsed URL reference containing components like query parameters, pathname, etc. */
|
|
108
|
+
readonly urlRef: UrlRef;
|
|
109
|
+
/** Query parameters extracted from the URL */
|
|
110
|
+
readonly query: Record<string, any>;
|
|
111
|
+
/**
|
|
112
|
+
* Retrieve a parameter by name.
|
|
113
|
+
* @param name - The parameter name.
|
|
114
|
+
* @returns The parameter value if found, or undefined.
|
|
115
|
+
*/
|
|
116
|
+
readonly params: Record<string, any>;
|
|
117
|
+
constructor(req: any, params: Record<string, any>);
|
|
118
|
+
/**
|
|
119
|
+
* Parses the request body as plain text.
|
|
120
|
+
* @returns {Promise<string>} The text content of the request body.
|
|
121
|
+
*/
|
|
122
|
+
text(): Promise<string>;
|
|
123
|
+
/**
|
|
124
|
+
* Parses the request body as JSON.
|
|
125
|
+
* @returns {Promise<Record<string, any>>} The parsed JSON object.
|
|
126
|
+
* If the Content-Type is not 'application/json', it returns an empty object.
|
|
127
|
+
*/
|
|
128
|
+
json(): Promise<Record<string, any>>;
|
|
129
|
+
/**
|
|
130
|
+
* Parses the request body based on Content-Type.
|
|
131
|
+
* Supports:
|
|
132
|
+
* - application/json → JSON parsing
|
|
133
|
+
* - application/x-www-form-urlencoded → URL-encoded form parsing
|
|
134
|
+
* - multipart/form-data → Multipart form-data parsing (for file uploads)
|
|
135
|
+
* @returns {Promise<Record<string, any>>} The parsed form data as an object.
|
|
136
|
+
* @throws {Error} If the Content-Type is missing or invalid.
|
|
137
|
+
*/
|
|
138
|
+
formData(options?: FormDataOptions): Promise<Record<string, any>>;
|
|
150
139
|
}
|
|
151
140
|
|
|
152
141
|
declare class TezResponse {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
data: string,
|
|
172
|
-
status?: number
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
headers?: ResponseHeaders
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
headers?: ResponseHeaders
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
* Handles file downloads.
|
|
230
|
-
* @param filePath - The path to the file.
|
|
231
|
-
* @param fileName - The name of the downloaded file.
|
|
232
|
-
* @returns Response object for file download.
|
|
233
|
-
*/
|
|
234
|
-
static download(filePath: string, fileName: string): Promise<Response>;
|
|
235
|
-
/**
|
|
236
|
-
* Serves a file to the client.
|
|
237
|
-
* @param filePath - Absolute or relative path to the file.
|
|
238
|
-
* @param fileName - (Optional) The name of the send file.
|
|
239
|
-
* @param headers - (Optional) Additional headers.
|
|
240
|
-
* @returns Response object with the file stream.
|
|
241
|
-
*/
|
|
242
|
-
static sendFile(
|
|
243
|
-
filePath: string,
|
|
244
|
-
fileName?: string,
|
|
245
|
-
headers?: ResponseHeaders,
|
|
246
|
-
): Promise<Response>;
|
|
247
|
-
static sendFile(
|
|
248
|
-
filePath: string,
|
|
249
|
-
headers?: ResponseHeaders,
|
|
250
|
-
): Promise<Response>;
|
|
251
|
-
static sendFile(filePath: string, fileName?: string): Promise<Response>;
|
|
142
|
+
/**
|
|
143
|
+
* Sends a JSON response.
|
|
144
|
+
* @param body - The response data.
|
|
145
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
146
|
+
* @param headers - (Optional) Additional response headers.
|
|
147
|
+
* @returns Response object with JSON data.
|
|
148
|
+
*/
|
|
149
|
+
static json(body: any, status?: number, headers?: ResponseHeaders): Response;
|
|
150
|
+
static json(body: any, headers?: ResponseHeaders): Response;
|
|
151
|
+
static json(body: any, status?: number): Response;
|
|
152
|
+
/**
|
|
153
|
+
* Sends an HTML response.
|
|
154
|
+
* @param data - The HTML content as a string.
|
|
155
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
156
|
+
* @param headers - (Optional) Additional response headers.
|
|
157
|
+
* @returns Response object with HTML data.
|
|
158
|
+
*/
|
|
159
|
+
static html(data: string, status?: number, headers?: ResponseHeaders): Response;
|
|
160
|
+
static html(data: string, headers?: ResponseHeaders): Response;
|
|
161
|
+
static html(data: string, status?: number): Response;
|
|
162
|
+
/**
|
|
163
|
+
* Sends a plain text response.
|
|
164
|
+
* @param data - The text content.
|
|
165
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
166
|
+
* @param headers - (Optional) Additional response headers.
|
|
167
|
+
* @returns Response object with plain text data.
|
|
168
|
+
*/
|
|
169
|
+
static text(data: string, status?: number, headers?: ResponseHeaders): Response;
|
|
170
|
+
static text(data: string, headers?: ResponseHeaders): Response;
|
|
171
|
+
static text(data: string, status?: number): Response;
|
|
172
|
+
/**
|
|
173
|
+
* Sends an XML response.
|
|
174
|
+
* @param data - The XML content.
|
|
175
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
176
|
+
* @param headers - (Optional) Additional response headers.
|
|
177
|
+
* @returns Response object with XML data.
|
|
178
|
+
*/
|
|
179
|
+
static xml(data: string, status?: number, headers?: ResponseHeaders): Response;
|
|
180
|
+
static xml(data: string, headers?: ResponseHeaders): Response;
|
|
181
|
+
static xml(data: string, status?: number): Response;
|
|
182
|
+
/**
|
|
183
|
+
* Sends a response with any content type.
|
|
184
|
+
* Automatically determines content type if not provided.
|
|
185
|
+
* @param body - The response body.
|
|
186
|
+
* @param status - (Optional) HTTP status code.
|
|
187
|
+
* @param headers - (Optional) Additional response headers.
|
|
188
|
+
* @returns Response object.
|
|
189
|
+
*/
|
|
190
|
+
static send(body: any, status?: number, headers?: ResponseHeaders): Response;
|
|
191
|
+
static send(body: any, headers?: ResponseHeaders): Response;
|
|
192
|
+
static send(body: any, status?: number): Response;
|
|
193
|
+
/**
|
|
194
|
+
* Redirects to a given URL.
|
|
195
|
+
* @param url - The target URL.
|
|
196
|
+
* @param status - (Optional) HTTP status code (default: 302).
|
|
197
|
+
* @param headers - (Optional) Additional headers.
|
|
198
|
+
* @returns Response object with redirect.
|
|
199
|
+
*/
|
|
200
|
+
static redirect(url: string, status?: number, headers?: ResponseHeaders): Response;
|
|
201
|
+
/**
|
|
202
|
+
* Handles file downloads.
|
|
203
|
+
* @param filePath - The path to the file.
|
|
204
|
+
* @param fileName - The name of the downloaded file.
|
|
205
|
+
* @returns Response object for file download.
|
|
206
|
+
*/
|
|
207
|
+
static download(filePath: string, fileName: string): Promise<Response>;
|
|
208
|
+
/**
|
|
209
|
+
* Serves a file to the client.
|
|
210
|
+
* @param filePath - Absolute or relative path to the file.
|
|
211
|
+
* @param fileName - (Optional) The name of the send file.
|
|
212
|
+
* @param headers - (Optional) Additional headers.
|
|
213
|
+
* @returns Response object with the file stream.
|
|
214
|
+
*/
|
|
215
|
+
static sendFile(filePath: string, fileName?: string, headers?: ResponseHeaders): Promise<Response>;
|
|
216
|
+
static sendFile(filePath: string, headers?: ResponseHeaders): Promise<Response>;
|
|
217
|
+
static sendFile(filePath: string, fileName?: string): Promise<Response>;
|
|
252
218
|
}
|
|
253
219
|
|
|
254
220
|
/**
|
|
255
221
|
* A simple key-value storage class using Map.
|
|
256
222
|
*/
|
|
257
223
|
declare class State {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
224
|
+
private state;
|
|
225
|
+
constructor();
|
|
226
|
+
/**
|
|
227
|
+
* Store a value with a specific key.
|
|
228
|
+
* @param key - The key for the value.
|
|
229
|
+
* @param value - The value to be stored.
|
|
230
|
+
*/
|
|
231
|
+
set(key: string, value: any): void;
|
|
232
|
+
/**
|
|
233
|
+
* Retrieve a value by key.
|
|
234
|
+
* @param key - The key of the value to retrieve.
|
|
235
|
+
* @returns The stored value or undefined if not found.
|
|
236
|
+
*/
|
|
237
|
+
get(key: string): any | undefined;
|
|
238
|
+
/**
|
|
239
|
+
* Delete a key from storage.
|
|
240
|
+
* @param key - The key to remove.
|
|
241
|
+
* @returns True if the key was deleted, false otherwise.
|
|
242
|
+
*/
|
|
243
|
+
delete(key: string): boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Check if a key exists in the storage.
|
|
246
|
+
* @param key - The key to check.
|
|
247
|
+
* @returns True if the key exists, false otherwise.
|
|
248
|
+
*/
|
|
249
|
+
has(key: string): boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Get an array of all stored keys.
|
|
252
|
+
* @returns An array of keys.
|
|
253
|
+
*/
|
|
254
|
+
keys(): string[];
|
|
255
|
+
/**
|
|
256
|
+
* Get an array of all stored values.
|
|
257
|
+
* @returns An array of values.
|
|
258
|
+
*/
|
|
259
|
+
values(): any[];
|
|
260
|
+
/**
|
|
261
|
+
* Get an array of all key-value pairs.
|
|
262
|
+
* @returns An array of [key, value] tuples.
|
|
263
|
+
*/
|
|
264
|
+
entries(): [string, any][];
|
|
265
|
+
/**
|
|
266
|
+
* Remove all entries from storage.
|
|
267
|
+
*/
|
|
268
|
+
clear(): void;
|
|
303
269
|
}
|
|
304
270
|
|
|
305
271
|
interface CookieOptions {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
272
|
+
expires?: Date;
|
|
273
|
+
path?: string;
|
|
274
|
+
maxAge?: number;
|
|
275
|
+
domain?: string;
|
|
276
|
+
secure?: boolean;
|
|
277
|
+
httpOnly?: boolean;
|
|
278
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
313
279
|
}
|
|
314
280
|
type ResponseHeaders = Record<string, string>;
|
|
315
281
|
declare class Context<T extends Record<string, any> = {}> {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
get
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
282
|
+
#private;
|
|
283
|
+
[key: string]: any;
|
|
284
|
+
/**
|
|
285
|
+
* Environment variables and configuration
|
|
286
|
+
* @type {object}
|
|
287
|
+
*/
|
|
288
|
+
env: Record<string, any> & T;
|
|
289
|
+
/**
|
|
290
|
+
* Parser for handling and manipulating HTTP headers
|
|
291
|
+
* @type {HeadersParser}
|
|
292
|
+
*/
|
|
293
|
+
headers: HeadersParser;
|
|
294
|
+
/**
|
|
295
|
+
* Request path without query parameters
|
|
296
|
+
* @type {string}
|
|
297
|
+
*/
|
|
298
|
+
readonly pathname: string;
|
|
299
|
+
/**
|
|
300
|
+
* Full request URL including protocol and query string
|
|
301
|
+
* @type {string}
|
|
302
|
+
*/
|
|
303
|
+
readonly url: string;
|
|
304
|
+
/**
|
|
305
|
+
* HTTP request method (GET, POST, PUT, DELETE, etc.)
|
|
306
|
+
* @type {HTTPMethod}
|
|
307
|
+
*/
|
|
308
|
+
readonly method: HTTPMethod;
|
|
309
|
+
/**
|
|
310
|
+
* Public state container for application data
|
|
311
|
+
* state storage for middleware and plugins
|
|
312
|
+
* @type {State}
|
|
313
|
+
*/
|
|
314
|
+
state: State;
|
|
315
|
+
/**
|
|
316
|
+
* Flag indicating if the request processing is complete
|
|
317
|
+
* @type {boolean}
|
|
318
|
+
*/
|
|
319
|
+
finalized: boolean;
|
|
320
|
+
constructor(req: any);
|
|
321
|
+
/**
|
|
322
|
+
* Cookie handling utility with get/set/delete operations
|
|
323
|
+
* @returns {{
|
|
324
|
+
* get: (name: string) => string | undefined,
|
|
325
|
+
* all: () => Record<string, string>,
|
|
326
|
+
* delete: (name: string, options?: CookieOptions) => void,
|
|
327
|
+
* set: (name: string, value: string, options?: CookieOptions) => void
|
|
328
|
+
* }} Cookie handling interface
|
|
329
|
+
*/
|
|
330
|
+
/**
|
|
331
|
+
* Sets a header value.
|
|
332
|
+
* @param key - Header name.
|
|
333
|
+
* @param value - Header value(s).
|
|
334
|
+
*/
|
|
335
|
+
header(key: string, value: string | string[]): this;
|
|
336
|
+
get cookies(): {
|
|
337
|
+
/**
|
|
338
|
+
* Get a specific cookie by name.
|
|
339
|
+
* @param {string} cookie - The name of the cookie to retrieve.
|
|
340
|
+
* @returns {string | undefined} - The cookie value or undefined if not found.
|
|
341
|
+
*/
|
|
342
|
+
get: (cookie: string) => string;
|
|
343
|
+
/**
|
|
344
|
+
* Get all cookies as an object.
|
|
345
|
+
* @returns {Record<string, string>} - An object containing all cookies.
|
|
346
|
+
*/
|
|
347
|
+
all: () => Record<string, string>;
|
|
348
|
+
/**
|
|
349
|
+
* Delete a cookie by setting its expiration to the past.
|
|
350
|
+
* @param {string} name - The name of the cookie to delete.
|
|
351
|
+
* @param {CookieOptions} [options] - Additional cookie options.
|
|
352
|
+
*/
|
|
353
|
+
delete: (name: string, options?: CookieOptions) => void;
|
|
354
|
+
/**
|
|
355
|
+
* Set a new cookie with the given name, value, and options.
|
|
356
|
+
* @param {string} name - The name of the cookie.
|
|
357
|
+
* @param {string} value - The value of the cookie.
|
|
358
|
+
* @param {CookieOptions} [options] - Additional options like expiration.
|
|
359
|
+
*/
|
|
360
|
+
set: (name: string, value: string, options?: CookieOptions) => void;
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* Sends a JSON response.
|
|
364
|
+
* @param body - The response data.
|
|
365
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
366
|
+
* @param headers - (Optional) Additional response headers.
|
|
367
|
+
* @returns Response object with JSON data.
|
|
368
|
+
*/
|
|
369
|
+
json(body: any, status?: number, headers?: ResponseHeaders): TezResponse;
|
|
370
|
+
json(body: any, headers?: ResponseHeaders): TezResponse;
|
|
371
|
+
json(body: any, status?: number): TezResponse;
|
|
372
|
+
/**
|
|
373
|
+
* Sends a response with any content type.
|
|
374
|
+
* Automatically determines content type if not provided.
|
|
375
|
+
* @param body - The response body.
|
|
376
|
+
* @param status - (Optional) HTTP status code.
|
|
377
|
+
* @param headers - (Optional) Additional response headers.
|
|
378
|
+
* @returns Response object.
|
|
379
|
+
*/
|
|
380
|
+
send(body: any, status?: number, headers?: ResponseHeaders): any;
|
|
381
|
+
send(body: any, headers?: ResponseHeaders): any;
|
|
382
|
+
send(body: any, status?: number): any;
|
|
383
|
+
/**
|
|
384
|
+
* Sends an HTML response.
|
|
385
|
+
* @param data - The HTML content as a string.
|
|
386
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
387
|
+
* @param headers - (Optional) Additional response headers.
|
|
388
|
+
* @returns Response object with HTML data.
|
|
389
|
+
*/
|
|
390
|
+
html(data: string, status?: number, headers?: ResponseHeaders): any;
|
|
391
|
+
html(data: string, headers?: ResponseHeaders): any;
|
|
392
|
+
html(data: string, status?: number): any;
|
|
393
|
+
/**
|
|
394
|
+
* Sends a plain text response.
|
|
395
|
+
* @param data - The text content.
|
|
396
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
397
|
+
* @param headers - (Optional) Additional response headers.
|
|
398
|
+
* @returns Response object with plain text data.
|
|
399
|
+
*/
|
|
400
|
+
text(data: string, status?: number, headers?: ResponseHeaders): any;
|
|
401
|
+
text(data: string, headers?: ResponseHeaders): any;
|
|
402
|
+
text(data: string, status?: number): any;
|
|
403
|
+
/**
|
|
404
|
+
* Sends an XML response.
|
|
405
|
+
* @param data - The XML content.
|
|
406
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
407
|
+
* @param headers - (Optional) Additional response headers.
|
|
408
|
+
* @returns Response object with XML data.
|
|
409
|
+
*/
|
|
410
|
+
xml(data: string, status?: number, headers?: ResponseHeaders): any;
|
|
411
|
+
xml(data: string, headers?: ResponseHeaders): any;
|
|
412
|
+
xml(data: string, status?: number): any;
|
|
413
|
+
/**
|
|
414
|
+
* HTTP status code..
|
|
415
|
+
* @param status - number.
|
|
416
|
+
* @returns Response object with context all method.
|
|
417
|
+
*/
|
|
418
|
+
status: (status: number) => this;
|
|
419
|
+
/**
|
|
420
|
+
* Redirects to a given URL.
|
|
421
|
+
* @param url - The target URL.
|
|
422
|
+
* @param status - (Optional) HTTP status code (default: 302).
|
|
423
|
+
* @param headers - (Optional) Additional headers.
|
|
424
|
+
* @returns Response object with redirect.
|
|
425
|
+
*/
|
|
426
|
+
redirect(url: string, status?: number, headers?: ResponseHeaders): Response;
|
|
427
|
+
/**
|
|
428
|
+
* Handles file downloads.
|
|
429
|
+
* @param filePath - The path to the file.
|
|
430
|
+
* @param fileName - The name of the downloaded file.
|
|
431
|
+
* @returns Response object for file download.
|
|
432
|
+
*/
|
|
433
|
+
download(filePath: string, fileName: string): Promise<Response>;
|
|
434
|
+
/**
|
|
435
|
+
* Serves a file to the client.
|
|
436
|
+
* @param filePath - Absolute or relative path to the file.
|
|
437
|
+
* @param fileName - (Optional) The name of the send file.
|
|
438
|
+
* @param headers - (Optional) Additional headers.
|
|
439
|
+
* @returns Response object with the file stream.
|
|
440
|
+
*/
|
|
441
|
+
sendFile(filePath: string, fileName?: string, headers?: ResponseHeaders): Promise<Response>;
|
|
442
|
+
sendFile(filePath: string, headers?: ResponseHeaders): Promise<Response>;
|
|
443
|
+
sendFile(filePath: string, fileName?: string): Promise<Response>;
|
|
444
|
+
/**
|
|
445
|
+
* Getter that creates a standardized Request object from internal state
|
|
446
|
+
* @returns {Request} - Normalized request object combining:
|
|
447
|
+
* - Raw platform-specific request
|
|
448
|
+
* - Parsed headers
|
|
449
|
+
* - Route parameters
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* // Get standardized request
|
|
453
|
+
* const request = ctx.req;
|
|
454
|
+
* // Access route params
|
|
455
|
+
* const id = request.params.get('id');
|
|
456
|
+
*/
|
|
457
|
+
get req(): Request$1;
|
|
458
|
+
protected set params(params: Record<string, any>);
|
|
459
|
+
protected get params(): Record<string, any>;
|
|
492
460
|
}
|
|
493
461
|
|
|
494
462
|
declare class CommonHandler {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
callback: <T extends Record<string, any> = {}>(
|
|
509
|
-
err: string,
|
|
510
|
-
ctx: ctx<T>,
|
|
511
|
-
) => any,
|
|
512
|
-
): this;
|
|
463
|
+
/**
|
|
464
|
+
* Register a custom 404 handler for missing routes
|
|
465
|
+
* @param {Callback} callback - Handler function to execute when no route matches
|
|
466
|
+
* @returns {this} - Returns current instance for chaining
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* // Register a custom not-found handler
|
|
470
|
+
* app.notFound((ctx) => {
|
|
471
|
+
* ctx.status(404).text('Custom not found message');
|
|
472
|
+
* });
|
|
473
|
+
*/
|
|
474
|
+
notFound(callback: Callback): this;
|
|
475
|
+
onError(callback: <T extends Record<string, any> = {}>(err: string, ctx: ctx<T>) => any): this;
|
|
513
476
|
}
|
|
514
477
|
|
|
515
478
|
type DuplicateMiddlewares = Middleware<any>[];
|
|
516
479
|
type UniqueMiddlewares = Set<Middleware<any>>;
|
|
517
480
|
declare class TriMiddleware {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
481
|
+
children: Map<string, TriMiddleware>;
|
|
482
|
+
middlewares: DuplicateMiddlewares | UniqueMiddlewares;
|
|
483
|
+
isOptional: boolean;
|
|
484
|
+
pathname: string;
|
|
485
|
+
constructor(pathname?: string);
|
|
523
486
|
}
|
|
524
|
-
declare class MiddlewareConfigure<
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
constructor(basePath?: string);
|
|
530
|
-
protected addMiddleware(pathname: string, middlewares: Middleware<T>[]): void;
|
|
487
|
+
declare class MiddlewareConfigure<T extends Record<string, any> = {}> extends CommonHandler {
|
|
488
|
+
triMiddlewares: TriMiddleware;
|
|
489
|
+
protected basePath: string;
|
|
490
|
+
constructor(basePath?: string);
|
|
491
|
+
protected addMiddleware(pathname: string, middlewares: Middleware<T>[]): void;
|
|
531
492
|
}
|
|
532
493
|
|
|
533
494
|
type NextCallback = () => Promise<any>;
|
|
534
495
|
type ctx<T extends Record<string, any> = {}> = Context<T> & T;
|
|
535
|
-
type Callback<T extends Record<string, any> = {}> = (
|
|
536
|
-
|
|
537
|
-
) => Promise<TezResponse> | TezResponse;
|
|
538
|
-
type Middleware<T extends Record<string, any> = {}> = (
|
|
539
|
-
ctx: ctx<T>,
|
|
540
|
-
next: NextCallback,
|
|
541
|
-
) => NextCallback | Promise<TezResponse> | TezResponse;
|
|
496
|
+
type Callback<T extends Record<string, any> = {}> = (ctx: ctx<T>) => Promise<TezResponse> | TezResponse;
|
|
497
|
+
type Middleware<T extends Record<string, any> = {}> = (ctx: ctx<T>, next: NextCallback) => NextCallback | Promise<TezResponse> | TezResponse;
|
|
542
498
|
type RouterConfig = {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
499
|
+
/**
|
|
500
|
+
* `env` allows you to define environment variables for the router.
|
|
501
|
+
* It is a record of key-value pairs where the key is the variable name
|
|
502
|
+
* and the value can be either a string or a number.
|
|
503
|
+
*/
|
|
504
|
+
env?: Record<string, string | number>;
|
|
505
|
+
/**
|
|
506
|
+
* `basePath` sets the base path for the router. This is useful for grouping
|
|
507
|
+
* routes under a specific path prefix.
|
|
508
|
+
*/
|
|
509
|
+
basePath?: string;
|
|
554
510
|
};
|
|
555
511
|
declare class TrieRouter {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
paramName: any;
|
|
566
|
-
isParam: boolean;
|
|
567
|
-
constructor(pathname?: string);
|
|
512
|
+
children: Map<string, TrieRouter>;
|
|
513
|
+
handlers: Map<HTTPMethod, {
|
|
514
|
+
callback: Callback<any>;
|
|
515
|
+
middlewares: UniqueMiddlewares | DuplicateMiddlewares;
|
|
516
|
+
}>;
|
|
517
|
+
pathname: string;
|
|
518
|
+
paramName: any;
|
|
519
|
+
isParam: boolean;
|
|
520
|
+
constructor(pathname?: string);
|
|
568
521
|
}
|
|
569
522
|
type StaticServeOption = {
|
|
570
|
-
|
|
571
|
-
|
|
523
|
+
cacheControl?: string;
|
|
524
|
+
headers?: ResponseHeaders;
|
|
572
525
|
};
|
|
573
|
-
declare class Router<
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
#private;
|
|
577
|
-
protected routers: Map<
|
|
578
|
-
string,
|
|
579
|
-
Map<
|
|
580
|
-
HTTPMethod,
|
|
581
|
-
{
|
|
526
|
+
declare class Router<T extends Record<string, any> = {}> extends MiddlewareConfigure<T> {
|
|
527
|
+
#private;
|
|
528
|
+
protected routers: Map<string, Map<HTTPMethod, {
|
|
582
529
|
callback: Callback<T>;
|
|
583
530
|
middlewares: UniqueMiddlewares | DuplicateMiddlewares;
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
path: string,
|
|
661
|
-
middlewares: Middleware<T>[],
|
|
662
|
-
callback: Callback<T
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
path: string,
|
|
678
|
-
middlewares: Middleware<T>,
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
* Create route group with shared path prefix
|
|
734
|
-
* @param prefix - Path prefix for the group
|
|
735
|
-
* @param callback - Function that receives group-specific router
|
|
736
|
-
* @returns Current router instance for chaining
|
|
737
|
-
*
|
|
738
|
-
* @example
|
|
739
|
-
* app.group('/v1', (group) => {
|
|
740
|
-
* group.get('/users', v1UserHandler);
|
|
741
|
-
* });
|
|
742
|
-
*/
|
|
743
|
-
group(prefix: string, callback: (group: Router<T>) => void): this;
|
|
744
|
-
/**
|
|
745
|
-
* Register middleware with flexible signature
|
|
746
|
-
* @overload
|
|
747
|
-
* @param path - Optional path to scope middleware
|
|
748
|
-
* @param middlewares - Middleware(s) to register
|
|
749
|
-
* @param [callback] - Optional sub-router or handler
|
|
750
|
-
*/
|
|
751
|
-
use(
|
|
752
|
-
path: string,
|
|
753
|
-
middlewares: Middleware<T>[],
|
|
754
|
-
callback: Callback<T> | Router<T | any>,
|
|
755
|
-
): this;
|
|
756
|
-
use(
|
|
757
|
-
path: string,
|
|
758
|
-
middleware: Middleware<T>,
|
|
759
|
-
callback: Callback<T> | Router<T | any>,
|
|
760
|
-
): this;
|
|
761
|
-
use(path: string, middlewares: Middleware<T>[]): this;
|
|
762
|
-
use(path: string, middleware: Middleware<T>): this;
|
|
763
|
-
use(path: string, callback: Callback<T> | Router<T | any>): this;
|
|
764
|
-
use(
|
|
765
|
-
middlewares: Middleware<T>[],
|
|
766
|
-
callback: Callback<T> | Router<T | any>,
|
|
767
|
-
): this;
|
|
768
|
-
use(middleware: Middleware<T>, callback: Callback<T> | Router<T | any>): this;
|
|
769
|
-
use(middlewares: Middleware<T>[]): this;
|
|
770
|
-
use(middleware: Middleware<T>): this;
|
|
771
|
-
use(callback: Callback<T> | Router<T | any>): this;
|
|
531
|
+
}>>;
|
|
532
|
+
protected env: Record<string, string | number>;
|
|
533
|
+
protected triRouter: TrieRouter;
|
|
534
|
+
constructor({ basePath, env }?: RouterConfig);
|
|
535
|
+
/**
|
|
536
|
+
* Serves static files from a specified directory.
|
|
537
|
+
*
|
|
538
|
+
* This method provides two overloads:
|
|
539
|
+
* 1. `static(route: string, folder: string, option?: StaticServeOption): this;`
|
|
540
|
+
* - Serves static files from `folder` at the specified `route`.
|
|
541
|
+
* 2. `static(folder: string, option?: StaticServeOption): this;`
|
|
542
|
+
* - Serves static files from `folder` at the root (`/`).
|
|
543
|
+
*
|
|
544
|
+
* @param {string} route - The base route to serve static files from (optional in overload).
|
|
545
|
+
* @param {string} folder - The folder containing the static files.
|
|
546
|
+
* @param {StaticServeOption} [option] - Optional settings for static file serving.
|
|
547
|
+
* @returns {this} Returns the current instance to allow method chaining.
|
|
548
|
+
*/
|
|
549
|
+
static(route: string, folder: string, option?: StaticServeOption): this;
|
|
550
|
+
static(folder: string, Option?: StaticServeOption): this;
|
|
551
|
+
/**
|
|
552
|
+
* Registers a GET route with optional middleware(s)
|
|
553
|
+
* @param path - URL path pattern (supports route parameters)
|
|
554
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
555
|
+
* @returns Current instance for chaining
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* // Simple GET route
|
|
559
|
+
* app.get('/users', (ctx) => { ... });
|
|
560
|
+
*
|
|
561
|
+
* // With middleware
|
|
562
|
+
* app.get('/secure', authMiddleware, (ctx) => { ... });
|
|
563
|
+
*
|
|
564
|
+
* // With multiple middlewares
|
|
565
|
+
* app.get('/admin', [authMiddleware, adminMiddleware], (ctx) => { ... });
|
|
566
|
+
*/
|
|
567
|
+
get(path: string, callback: Callback<T>): this;
|
|
568
|
+
get(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
569
|
+
get(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
570
|
+
/**
|
|
571
|
+
* Registers a POST route with optional middleware(s)
|
|
572
|
+
* @param path - URL path pattern
|
|
573
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
574
|
+
*/
|
|
575
|
+
post(path: string, callback: Callback<T>): this;
|
|
576
|
+
post(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
577
|
+
post(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
578
|
+
/**
|
|
579
|
+
* Registers a PUT route with optional middleware(s)
|
|
580
|
+
* @param path - URL path pattern
|
|
581
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
582
|
+
*/
|
|
583
|
+
put(path: string, callback: Callback<T>): this;
|
|
584
|
+
put(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
585
|
+
put(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
586
|
+
/**
|
|
587
|
+
* Registers a PATCH route with optional middleware(s)
|
|
588
|
+
* @param path - URL path pattern
|
|
589
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
590
|
+
*/
|
|
591
|
+
patch(path: string, callback: Callback<T>): this;
|
|
592
|
+
patch(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
593
|
+
patch(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
594
|
+
/**
|
|
595
|
+
* Registers a DELETE route with optional middleware(s)
|
|
596
|
+
* @param path - URL path pattern
|
|
597
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
598
|
+
*/
|
|
599
|
+
delete(path: string, callback: Callback<T>): this;
|
|
600
|
+
delete(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
601
|
+
delete(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
602
|
+
/**
|
|
603
|
+
* Registers an OPTIONS route (primarily for CORS preflight requests)
|
|
604
|
+
* @param path - URL path pattern
|
|
605
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
606
|
+
*/
|
|
607
|
+
options(path: string, callback: Callback<T>): this;
|
|
608
|
+
options(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
609
|
+
options(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
610
|
+
/**
|
|
611
|
+
* Registers a HEAD route (returns headers only)
|
|
612
|
+
* @param path - URL path pattern
|
|
613
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
614
|
+
*/
|
|
615
|
+
head(path: string, callback: Callback<T>): this;
|
|
616
|
+
head(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
617
|
+
head(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
618
|
+
/**
|
|
619
|
+
* Registers a route that responds to all HTTP methods
|
|
620
|
+
* @param path - URL path pattern
|
|
621
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
622
|
+
*/
|
|
623
|
+
all(path: string, callback: Callback<T>): this;
|
|
624
|
+
all(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
625
|
+
all(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
626
|
+
/**
|
|
627
|
+
* Generic method registration for custom HTTP methods
|
|
628
|
+
* @param method - HTTP method name (e.g., 'PURGE')
|
|
629
|
+
* @param path - URL path pattern
|
|
630
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* // Register custom method
|
|
634
|
+
* server.addRoute('PURGE', '/cache', purgeHandler);
|
|
635
|
+
*/
|
|
636
|
+
addRoute(method: HTTPMethod, path: string, callback: Callback<T>): this;
|
|
637
|
+
addRoute(method: HTTPMethod, path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
638
|
+
addRoute(method: HTTPMethod, path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
639
|
+
/**
|
|
640
|
+
* Mount a sub-router at specific path prefix
|
|
641
|
+
* @param path - Base path for the sub-router
|
|
642
|
+
* @param router - Router instance to mount
|
|
643
|
+
* @returns Current instance for chaining
|
|
644
|
+
*
|
|
645
|
+
* @example
|
|
646
|
+
* const apiRouter = new Router();
|
|
647
|
+
* apiRouter.get('/users', () => { ... });
|
|
648
|
+
* server.addRouter('/api', apiRouter);
|
|
649
|
+
*/
|
|
650
|
+
addRouter(path: string, router: Router<T | any>): void;
|
|
651
|
+
/**
|
|
652
|
+
* Create route group with shared path prefix
|
|
653
|
+
* @param prefix - Path prefix for the group
|
|
654
|
+
* @param callback - Function that receives group-specific router
|
|
655
|
+
* @returns Current router instance for chaining
|
|
656
|
+
*
|
|
657
|
+
* @example
|
|
658
|
+
* app.group('/v1', (group) => {
|
|
659
|
+
* group.get('/users', v1UserHandler);
|
|
660
|
+
* });
|
|
661
|
+
*/
|
|
662
|
+
group(prefix: string, callback: (group: Router<T>) => void): this;
|
|
663
|
+
/**
|
|
664
|
+
* Register middleware with flexible signature
|
|
665
|
+
* @overload
|
|
666
|
+
* @param path - Optional path to scope middleware
|
|
667
|
+
* @param middlewares - Middleware(s) to register
|
|
668
|
+
* @param [callback] - Optional sub-router or handler
|
|
669
|
+
*/
|
|
670
|
+
use(path: string, middlewares: Middleware<T>[], callback: Callback<T> | Router<T | any>): this;
|
|
671
|
+
use(path: string, middleware: Middleware<T>, callback: Callback<T> | Router<T | any>): this;
|
|
672
|
+
use(path: string, middlewares: Middleware<T>[]): this;
|
|
673
|
+
use(path: string, middleware: Middleware<T>): this;
|
|
674
|
+
use(path: string, callback: Callback<T> | Router<T | any>): this;
|
|
675
|
+
use(middlewares: Middleware<T>[], callback: Callback<T> | Router<T | any>): this;
|
|
676
|
+
use(middleware: Middleware<T>, callback: Callback<T> | Router<T | any>): this;
|
|
677
|
+
use(middlewares: Middleware<T>[]): this;
|
|
678
|
+
use(middleware: Middleware<T>): this;
|
|
679
|
+
use(callback: Callback<T> | Router<T | any>): this;
|
|
772
680
|
}
|
|
773
681
|
|
|
774
682
|
interface ServeResponse {
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
683
|
+
status: number;
|
|
684
|
+
headers: {
|
|
685
|
+
[key: string]: string;
|
|
686
|
+
};
|
|
687
|
+
body: string;
|
|
688
|
+
statusText: string;
|
|
781
689
|
}
|
|
782
690
|
type LoggerFnType = () => {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
691
|
+
request?: (method: HTTPMethod, pathname: string) => void;
|
|
692
|
+
response?: (method: HTTPMethod, pathname: string, status?: number) => void;
|
|
693
|
+
info?: (msg: string, ...args: unknown[]) => void;
|
|
694
|
+
warn?: (msg: string, ...args: unknown[]) => void;
|
|
695
|
+
error?: (msg: string, ...args: unknown[]) => void;
|
|
696
|
+
debug?: (msg: string, ...args: unknown[]) => void;
|
|
697
|
+
success?: (msg: string, ...args: unknown[]) => void;
|
|
790
698
|
};
|
|
791
699
|
type TezXConfig = {
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
700
|
+
/**
|
|
701
|
+
* `allowDuplicateMw` determines whether duplicate middleware functions
|
|
702
|
+
* are allowed in the router.
|
|
703
|
+
*
|
|
704
|
+
* - When `true`: The same middleware can be added multiple times.
|
|
705
|
+
* - When `false`: Ensures each middleware is registered only once
|
|
706
|
+
* per route or application context.
|
|
707
|
+
*
|
|
708
|
+
* @default false
|
|
709
|
+
*/
|
|
710
|
+
allowDuplicateMw?: boolean;
|
|
711
|
+
/**
|
|
712
|
+
* `overwriteMethod` controls whether existing route handlers
|
|
713
|
+
* should be overwritten when a new handler for the same
|
|
714
|
+
* HTTP method and path is added.
|
|
715
|
+
*
|
|
716
|
+
* - When `true`: The new handler replaces the existing one.
|
|
717
|
+
* - When `false`: Prevents overwriting, ensuring that the
|
|
718
|
+
* first registered handler remains active.
|
|
719
|
+
*
|
|
720
|
+
* @default true
|
|
721
|
+
*/
|
|
722
|
+
overwriteMethod?: boolean;
|
|
723
|
+
/**
|
|
724
|
+
* `logger` is an optional function that handles logging within the application.
|
|
725
|
+
* It should conform to the `LoggerFnType`, which defines the expected signature for the logging function.
|
|
726
|
+
*
|
|
727
|
+
* If provided, this function will be called for logging purposes throughout the application.
|
|
728
|
+
*/
|
|
729
|
+
logger?: LoggerFnType;
|
|
822
730
|
} & RouterConfig;
|
|
823
731
|
declare class TezX<T extends Record<string, any> = {}> extends Router<T> {
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
protected findRoute(
|
|
833
|
-
method: HTTPMethod,
|
|
834
|
-
pathname: string,
|
|
835
|
-
): {
|
|
836
|
-
callback: any;
|
|
837
|
-
middlewares: Middleware<T>[];
|
|
838
|
-
params: Record<string, string>;
|
|
839
|
-
} | null;
|
|
840
|
-
serve(req: Request): Promise<ServeResponse | any>;
|
|
732
|
+
#private;
|
|
733
|
+
constructor({ basePath, env, logger, allowDuplicateMw, overwriteMethod, }?: TezXConfig);
|
|
734
|
+
protected findRoute(method: HTTPMethod, pathname: string): {
|
|
735
|
+
callback: any;
|
|
736
|
+
middlewares: Middleware<T>[];
|
|
737
|
+
params: Record<string, string>;
|
|
738
|
+
} | null;
|
|
739
|
+
serve(req: Request): Promise<ServeResponse | any>;
|
|
841
740
|
}
|
|
842
741
|
|
|
843
|
-
declare function denoAdapter<T extends Record<string, any> = {}>(
|
|
844
|
-
|
|
845
|
-
): {
|
|
846
|
-
listen: (port: number, callback?: (message: string) => void) => any;
|
|
742
|
+
declare function denoAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>): {
|
|
743
|
+
listen: (port: number, callback?: (message: string) => void) => any;
|
|
847
744
|
};
|
|
848
|
-
declare function bunAdapter<T extends Record<string, any> = {}>(
|
|
849
|
-
|
|
850
|
-
): {
|
|
851
|
-
listen: (port: number, callback?: (message: string) => void) => any;
|
|
745
|
+
declare function bunAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>): {
|
|
746
|
+
listen: (port: number, callback?: (message: string) => void) => any;
|
|
852
747
|
};
|
|
853
|
-
declare function nodeAdapter<T extends Record<string, any> = {}>(
|
|
854
|
-
|
|
855
|
-
): {
|
|
856
|
-
listen: (port: number, callback?: (message: string) => void) => void;
|
|
748
|
+
declare function nodeAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>): {
|
|
749
|
+
listen: (port: number, callback?: (message: string) => void) => void;
|
|
857
750
|
};
|
|
858
751
|
|
|
859
|
-
declare function useParams({
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
}: {
|
|
863
|
-
path: string;
|
|
864
|
-
urlPattern: string;
|
|
752
|
+
declare function useParams({ path, urlPattern, }: {
|
|
753
|
+
path: string;
|
|
754
|
+
urlPattern: string;
|
|
865
755
|
}): {
|
|
866
|
-
|
|
867
|
-
|
|
756
|
+
success: boolean;
|
|
757
|
+
params: Record<string, any>;
|
|
868
758
|
};
|
|
869
759
|
|
|
870
760
|
/**
|
|
@@ -880,51 +770,23 @@ type LogLevel = "info" | "warn" | "error" | "debug" | "success";
|
|
|
880
770
|
* @param callback - The operation to measure and execute.
|
|
881
771
|
*/
|
|
882
772
|
declare function logger(): {
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
773
|
+
request: (method: HTTPMethod, pathname: string) => void;
|
|
774
|
+
response: (method: HTTPMethod, pathname: string, status?: number) => void;
|
|
775
|
+
info: (msg: string, ...args: unknown[]) => void;
|
|
776
|
+
warn: (msg: string, ...args: unknown[]) => void;
|
|
777
|
+
error: (msg: string, ...args: unknown[]) => void;
|
|
778
|
+
debug: (msg: string, ...args: unknown[]) => void;
|
|
779
|
+
success: (msg: string, ...args: unknown[]) => void;
|
|
890
780
|
};
|
|
891
781
|
|
|
892
782
|
type CorsOptions = {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
allowedHeaders?: string[];
|
|
900
|
-
exposedHeaders?: string[];
|
|
901
|
-
credentials?: boolean;
|
|
902
|
-
maxAge?: number;
|
|
783
|
+
origin?: string | RegExp | (string | RegExp)[] | ((reqOrigin: string) => boolean);
|
|
784
|
+
methods?: string[];
|
|
785
|
+
allowedHeaders?: string[];
|
|
786
|
+
exposedHeaders?: string[];
|
|
787
|
+
credentials?: boolean;
|
|
788
|
+
maxAge?: number;
|
|
903
789
|
};
|
|
904
|
-
declare function cors(
|
|
905
|
-
option?: CorsOptions,
|
|
906
|
-
): (ctx: ctx, next: () => Promise<any>) => Promise<any>;
|
|
790
|
+
declare function cors(option?: CorsOptions): (ctx: ctx, next: () => Promise<any>) => Promise<any>;
|
|
907
791
|
|
|
908
|
-
export {
|
|
909
|
-
type Callback,
|
|
910
|
-
type ctx as Context,
|
|
911
|
-
type CorsOptions,
|
|
912
|
-
type LogLevel,
|
|
913
|
-
type LoggerFnType,
|
|
914
|
-
type Middleware,
|
|
915
|
-
type NextCallback,
|
|
916
|
-
Router,
|
|
917
|
-
type RouterConfig,
|
|
918
|
-
type StaticServeOption,
|
|
919
|
-
TezResponse,
|
|
920
|
-
TezX,
|
|
921
|
-
type TezXConfig,
|
|
922
|
-
type UrlRef,
|
|
923
|
-
bunAdapter,
|
|
924
|
-
cors,
|
|
925
|
-
denoAdapter,
|
|
926
|
-
loadEnv,
|
|
927
|
-
logger,
|
|
928
|
-
nodeAdapter,
|
|
929
|
-
useParams,
|
|
930
|
-
};
|
|
792
|
+
export { type Callback, type ctx as Context, type CorsOptions, type LogLevel, type LoggerFnType, type Middleware, type NextCallback, Router, type RouterConfig, type StaticServeOption, TezResponse, TezX, type TezXConfig, type UrlRef, bunAdapter, cors, denoAdapter, loadEnv, logger, nodeAdapter, useParams };
|