tezx 1.0.4 → 1.0.6
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 +636 -852
- package/dist/index.js +490 -634
- package/dist/index.mjs +491 -647
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,870 +1,682 @@
|
|
|
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
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
declare class TezResponse {
|
|
153
|
-
/**
|
|
154
|
-
* Sends a JSON response.
|
|
155
|
-
* @param body - The response data.
|
|
156
|
-
* @param status - (Optional) HTTP status code (default: 200).
|
|
157
|
-
* @param headers - (Optional) Additional response headers.
|
|
158
|
-
* @returns Response object with JSON data.
|
|
159
|
-
*/
|
|
160
|
-
static json(body: any, status?: number, headers?: ResponseHeaders): Response;
|
|
161
|
-
static json(body: any, headers?: ResponseHeaders): Response;
|
|
162
|
-
static json(body: any, status?: number): Response;
|
|
163
|
-
/**
|
|
164
|
-
* Sends an HTML response.
|
|
165
|
-
* @param data - The HTML content as a string.
|
|
166
|
-
* @param status - (Optional) HTTP status code (default: 200).
|
|
167
|
-
* @param headers - (Optional) Additional response headers.
|
|
168
|
-
* @returns Response object with HTML data.
|
|
169
|
-
*/
|
|
170
|
-
static html(
|
|
171
|
-
data: string,
|
|
172
|
-
status?: number,
|
|
173
|
-
headers?: ResponseHeaders,
|
|
174
|
-
): Response;
|
|
175
|
-
static html(data: string, headers?: ResponseHeaders): Response;
|
|
176
|
-
static html(data: string, status?: number): Response;
|
|
177
|
-
/**
|
|
178
|
-
* Sends a plain text response.
|
|
179
|
-
* @param data - The text content.
|
|
180
|
-
* @param status - (Optional) HTTP status code (default: 200).
|
|
181
|
-
* @param headers - (Optional) Additional response headers.
|
|
182
|
-
* @returns Response object with plain text data.
|
|
183
|
-
*/
|
|
184
|
-
static text(
|
|
185
|
-
data: string,
|
|
186
|
-
status?: number,
|
|
187
|
-
headers?: ResponseHeaders,
|
|
188
|
-
): Response;
|
|
189
|
-
static text(data: string, headers?: ResponseHeaders): Response;
|
|
190
|
-
static text(data: string, status?: number): Response;
|
|
191
|
-
/**
|
|
192
|
-
* Sends an XML response.
|
|
193
|
-
* @param data - The XML content.
|
|
194
|
-
* @param status - (Optional) HTTP status code (default: 200).
|
|
195
|
-
* @param headers - (Optional) Additional response headers.
|
|
196
|
-
* @returns Response object with XML data.
|
|
197
|
-
*/
|
|
198
|
-
static xml(
|
|
199
|
-
data: string,
|
|
200
|
-
status?: number,
|
|
201
|
-
headers?: ResponseHeaders,
|
|
202
|
-
): Response;
|
|
203
|
-
static xml(data: string, headers?: ResponseHeaders): Response;
|
|
204
|
-
static xml(data: string, status?: number): Response;
|
|
205
|
-
/**
|
|
206
|
-
* Sends a response with any content type.
|
|
207
|
-
* Automatically determines content type if not provided.
|
|
208
|
-
* @param body - The response body.
|
|
209
|
-
* @param status - (Optional) HTTP status code.
|
|
210
|
-
* @param headers - (Optional) Additional response headers.
|
|
211
|
-
* @returns Response object.
|
|
212
|
-
*/
|
|
213
|
-
static send(body: any, status?: number, headers?: ResponseHeaders): Response;
|
|
214
|
-
static send(body: any, headers?: ResponseHeaders): Response;
|
|
215
|
-
static send(body: any, status?: number): Response;
|
|
216
|
-
/**
|
|
217
|
-
* Redirects to a given URL.
|
|
218
|
-
* @param url - The target URL.
|
|
219
|
-
* @param status - (Optional) HTTP status code (default: 302).
|
|
220
|
-
* @param headers - (Optional) Additional headers.
|
|
221
|
-
* @returns Response object with redirect.
|
|
222
|
-
*/
|
|
223
|
-
static redirect(
|
|
224
|
-
url: string,
|
|
225
|
-
status?: number,
|
|
226
|
-
headers?: ResponseHeaders,
|
|
227
|
-
): Response;
|
|
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>;
|
|
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>>;
|
|
252
139
|
}
|
|
253
140
|
|
|
254
141
|
/**
|
|
255
142
|
* A simple key-value storage class using Map.
|
|
256
143
|
*/
|
|
257
144
|
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
|
-
|
|
145
|
+
private state;
|
|
146
|
+
constructor();
|
|
147
|
+
/**
|
|
148
|
+
* Store a value with a specific key.
|
|
149
|
+
* @param key - The key for the value.
|
|
150
|
+
* @param value - The value to be stored.
|
|
151
|
+
*/
|
|
152
|
+
set(key: string, value: any): void;
|
|
153
|
+
/**
|
|
154
|
+
* Retrieve a value by key.
|
|
155
|
+
* @param key - The key of the value to retrieve.
|
|
156
|
+
* @returns The stored value or undefined if not found.
|
|
157
|
+
*/
|
|
158
|
+
get(key: string): any | undefined;
|
|
159
|
+
/**
|
|
160
|
+
* Delete a key from storage.
|
|
161
|
+
* @param key - The key to remove.
|
|
162
|
+
* @returns True if the key was deleted, false otherwise.
|
|
163
|
+
*/
|
|
164
|
+
delete(key: string): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Check if a key exists in the storage.
|
|
167
|
+
* @param key - The key to check.
|
|
168
|
+
* @returns True if the key exists, false otherwise.
|
|
169
|
+
*/
|
|
170
|
+
has(key: string): boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Get an array of all stored keys.
|
|
173
|
+
* @returns An array of keys.
|
|
174
|
+
*/
|
|
175
|
+
keys(): string[];
|
|
176
|
+
/**
|
|
177
|
+
* Get an array of all stored values.
|
|
178
|
+
* @returns An array of values.
|
|
179
|
+
*/
|
|
180
|
+
values(): any[];
|
|
181
|
+
/**
|
|
182
|
+
* Get an array of all key-value pairs.
|
|
183
|
+
* @returns An array of [key, value] tuples.
|
|
184
|
+
*/
|
|
185
|
+
entries(): [string, any][];
|
|
186
|
+
/**
|
|
187
|
+
* Remove all entries from storage.
|
|
188
|
+
*/
|
|
189
|
+
clear(): void;
|
|
303
190
|
}
|
|
304
191
|
|
|
305
192
|
interface CookieOptions {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
193
|
+
expires?: Date;
|
|
194
|
+
path?: string;
|
|
195
|
+
maxAge?: number;
|
|
196
|
+
domain?: string;
|
|
197
|
+
secure?: boolean;
|
|
198
|
+
httpOnly?: boolean;
|
|
199
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
313
200
|
}
|
|
314
201
|
type ResponseHeaders = Record<string, string>;
|
|
315
202
|
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
|
-
|
|
203
|
+
#private;
|
|
204
|
+
[key: string]: any;
|
|
205
|
+
/**
|
|
206
|
+
* Environment variables and configuration
|
|
207
|
+
* @type {object}
|
|
208
|
+
*/
|
|
209
|
+
env: Record<string, any> & T;
|
|
210
|
+
/**
|
|
211
|
+
* Parser for handling and manipulating HTTP headers
|
|
212
|
+
* @type {HeadersParser}
|
|
213
|
+
*/
|
|
214
|
+
headers: HeadersParser;
|
|
215
|
+
/**
|
|
216
|
+
* Request path without query parameters
|
|
217
|
+
* @type {string}
|
|
218
|
+
*/
|
|
219
|
+
readonly pathname: string;
|
|
220
|
+
/**
|
|
221
|
+
* Full request URL including protocol and query string
|
|
222
|
+
* @type {string}
|
|
223
|
+
*/
|
|
224
|
+
readonly url: string;
|
|
225
|
+
/**
|
|
226
|
+
* HTTP request method (GET, POST, PUT, DELETE, etc.)
|
|
227
|
+
* @type {HTTPMethod}
|
|
228
|
+
*/
|
|
229
|
+
readonly method: HTTPMethod;
|
|
230
|
+
/**
|
|
231
|
+
* Public state container for application data
|
|
232
|
+
* state storage for middleware and plugins
|
|
233
|
+
* @type {State}
|
|
234
|
+
*/
|
|
235
|
+
state: State;
|
|
236
|
+
/**
|
|
237
|
+
* Flag indicating if the request processing is complete
|
|
238
|
+
* @type {boolean}
|
|
239
|
+
*/
|
|
240
|
+
finalized: boolean;
|
|
241
|
+
constructor(req: any);
|
|
242
|
+
/**
|
|
243
|
+
* Cookie handling utility with get/set/delete operations
|
|
244
|
+
* @returns {{
|
|
245
|
+
* get: (name: string) => string | undefined,
|
|
246
|
+
* all: () => Record<string, string>,
|
|
247
|
+
* delete: (name: string, options?: CookieOptions) => void,
|
|
248
|
+
* set: (name: string, value: string, options?: CookieOptions) => void
|
|
249
|
+
* }} Cookie handling interface
|
|
250
|
+
*/
|
|
251
|
+
/**
|
|
252
|
+
* Sets a header value.
|
|
253
|
+
* @param key - Header name.
|
|
254
|
+
* @param value - Header value(s).
|
|
255
|
+
*/
|
|
256
|
+
header(key: string, value: string | string[]): this;
|
|
257
|
+
get cookies(): {
|
|
258
|
+
/**
|
|
259
|
+
* Get a specific cookie by name.
|
|
260
|
+
* @param {string} cookie - The name of the cookie to retrieve.
|
|
261
|
+
* @returns {string | undefined} - The cookie value or undefined if not found.
|
|
262
|
+
*/
|
|
263
|
+
get: (cookie: string) => string;
|
|
264
|
+
/**
|
|
265
|
+
* Get all cookies as an object.
|
|
266
|
+
* @returns {Record<string, string>} - An object containing all cookies.
|
|
267
|
+
*/
|
|
268
|
+
all: () => Record<string, string>;
|
|
269
|
+
/**
|
|
270
|
+
* Delete a cookie by setting its expiration to the past.
|
|
271
|
+
* @param {string} name - The name of the cookie to delete.
|
|
272
|
+
* @param {CookieOptions} [options] - Additional cookie options.
|
|
273
|
+
*/
|
|
274
|
+
delete: (name: string, options?: CookieOptions) => void;
|
|
275
|
+
/**
|
|
276
|
+
* Set a new cookie with the given name, value, and options.
|
|
277
|
+
* @param {string} name - The name of the cookie.
|
|
278
|
+
* @param {string} value - The value of the cookie.
|
|
279
|
+
* @param {CookieOptions} [options] - Additional options like expiration.
|
|
280
|
+
*/
|
|
281
|
+
set: (name: string, value: string, options?: CookieOptions) => void;
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* Sends a JSON response.
|
|
285
|
+
* @param body - The response data.
|
|
286
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
287
|
+
* @param headers - (Optional) Additional response headers.
|
|
288
|
+
* @returns Response object with JSON data.
|
|
289
|
+
*/
|
|
290
|
+
json(body: any, status?: number, headers?: ResponseHeaders): Response;
|
|
291
|
+
json(body: any, headers?: ResponseHeaders): Response;
|
|
292
|
+
json(body: any, status?: number): Response;
|
|
293
|
+
/**
|
|
294
|
+
* Sends a response with any content type.
|
|
295
|
+
* Automatically determines content type if not provided.
|
|
296
|
+
* @param body - The response body.
|
|
297
|
+
* @param status - (Optional) HTTP status code.
|
|
298
|
+
* @param headers - (Optional) Additional response headers.
|
|
299
|
+
* @returns Response object.
|
|
300
|
+
*/
|
|
301
|
+
send(body: any, status?: number, headers?: ResponseHeaders): any;
|
|
302
|
+
send(body: any, headers?: ResponseHeaders): any;
|
|
303
|
+
send(body: any, status?: number): any;
|
|
304
|
+
/**
|
|
305
|
+
* Sends an HTML response.
|
|
306
|
+
* @param data - The HTML content as a string.
|
|
307
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
308
|
+
* @param headers - (Optional) Additional response headers.
|
|
309
|
+
* @returns Response object with HTML data.
|
|
310
|
+
*/
|
|
311
|
+
html(data: string, status?: number, headers?: ResponseHeaders): any;
|
|
312
|
+
html(data: string, headers?: ResponseHeaders): any;
|
|
313
|
+
html(data: string, status?: number): any;
|
|
314
|
+
/**
|
|
315
|
+
* Sends a plain text response.
|
|
316
|
+
* @param data - The text content.
|
|
317
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
318
|
+
* @param headers - (Optional) Additional response headers.
|
|
319
|
+
* @returns Response object with plain text data.
|
|
320
|
+
*/
|
|
321
|
+
text(data: string, status?: number, headers?: ResponseHeaders): any;
|
|
322
|
+
text(data: string, headers?: ResponseHeaders): any;
|
|
323
|
+
text(data: string, status?: number): any;
|
|
324
|
+
/**
|
|
325
|
+
* Sends an XML response.
|
|
326
|
+
* @param data - The XML content.
|
|
327
|
+
* @param status - (Optional) HTTP status code (default: 200).
|
|
328
|
+
* @param headers - (Optional) Additional response headers.
|
|
329
|
+
* @returns Response object with XML data.
|
|
330
|
+
*/
|
|
331
|
+
xml(data: string, status?: number, headers?: ResponseHeaders): any;
|
|
332
|
+
xml(data: string, headers?: ResponseHeaders): any;
|
|
333
|
+
xml(data: string, status?: number): any;
|
|
334
|
+
/**
|
|
335
|
+
* HTTP status code..
|
|
336
|
+
* @param status - number.
|
|
337
|
+
* @returns Response object with context all method.
|
|
338
|
+
*/
|
|
339
|
+
status: (status: number) => this;
|
|
340
|
+
set setStatus(status: number);
|
|
341
|
+
get getStatus(): number;
|
|
342
|
+
/**
|
|
343
|
+
* Redirects to a given URL.
|
|
344
|
+
* @param url - The target URL.
|
|
345
|
+
* @param status - (Optional) HTTP status code (default: 302).
|
|
346
|
+
* @returns Response object with redirect.
|
|
347
|
+
*/
|
|
348
|
+
redirect(url: string, status?: number): Response;
|
|
349
|
+
/**
|
|
350
|
+
* Handles file downloads.
|
|
351
|
+
* @param filePath - The path to the file.
|
|
352
|
+
* @param fileName - The name of the downloaded file.
|
|
353
|
+
* @returns Response object for file download.
|
|
354
|
+
*/
|
|
355
|
+
download(filePath: string, fileName: string): Promise<Response>;
|
|
356
|
+
/**
|
|
357
|
+
* Serves a file to the client.
|
|
358
|
+
* @param filePath - Absolute or relative path to the file.
|
|
359
|
+
* @param fileName - (Optional) The name of the send file.
|
|
360
|
+
* @param headers - (Optional) Additional headers.
|
|
361
|
+
* @returns Response object with the file stream.
|
|
362
|
+
*/
|
|
363
|
+
sendFile(filePath: string, fileName?: string, headers?: ResponseHeaders): Promise<Response>;
|
|
364
|
+
sendFile(filePath: string, headers?: ResponseHeaders): Promise<Response>;
|
|
365
|
+
sendFile(filePath: string, fileName?: string): Promise<Response>;
|
|
366
|
+
/**
|
|
367
|
+
* Getter that creates a standardized Request object from internal state
|
|
368
|
+
* @returns {Request} - Normalized request object combining:
|
|
369
|
+
* - Raw platform-specific request
|
|
370
|
+
* - Parsed headers
|
|
371
|
+
* - Route parameters
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* // Get standardized request
|
|
375
|
+
* const request = ctx.req;
|
|
376
|
+
* // Access route params
|
|
377
|
+
* const id = request.params.get('id');
|
|
378
|
+
*/
|
|
379
|
+
get req(): Request$1;
|
|
380
|
+
protected set params(params: Record<string, any>);
|
|
381
|
+
protected get params(): Record<string, any>;
|
|
492
382
|
}
|
|
493
383
|
|
|
494
384
|
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;
|
|
385
|
+
/**
|
|
386
|
+
* Register a custom 404 handler for missing routes
|
|
387
|
+
* @param {Callback} callback - Handler function to execute when no route matches
|
|
388
|
+
* @returns {this} - Returns current instance for chaining
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* // Register a custom not-found handler
|
|
392
|
+
* app.notFound((ctx) => {
|
|
393
|
+
* ctx.status(404).text('Custom not found message');
|
|
394
|
+
* });
|
|
395
|
+
*/
|
|
396
|
+
notFound(callback: Callback): this;
|
|
397
|
+
onError(callback: <T extends Record<string, any> = {}>(err: string, ctx: ctx<T>) => any): this;
|
|
513
398
|
}
|
|
514
399
|
|
|
515
400
|
type DuplicateMiddlewares = Middleware<any>[];
|
|
516
401
|
type UniqueMiddlewares = Set<Middleware<any>>;
|
|
517
402
|
declare class TriMiddleware {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
403
|
+
children: Map<string, TriMiddleware>;
|
|
404
|
+
middlewares: DuplicateMiddlewares | UniqueMiddlewares;
|
|
405
|
+
isOptional: boolean;
|
|
406
|
+
pathname: string;
|
|
407
|
+
constructor(pathname?: string);
|
|
523
408
|
}
|
|
524
|
-
declare class MiddlewareConfigure<
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
constructor(basePath?: string);
|
|
530
|
-
protected addMiddleware(pathname: string, middlewares: Middleware<T>[]): void;
|
|
409
|
+
declare class MiddlewareConfigure<T extends Record<string, any> = {}> extends CommonHandler {
|
|
410
|
+
triMiddlewares: TriMiddleware;
|
|
411
|
+
protected basePath: string;
|
|
412
|
+
constructor(basePath?: string);
|
|
413
|
+
protected addMiddleware(pathname: string, middlewares: Middleware<T>[]): void;
|
|
531
414
|
}
|
|
532
415
|
|
|
533
416
|
type NextCallback = () => Promise<any>;
|
|
534
417
|
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;
|
|
418
|
+
type Callback<T extends Record<string, any> = {}> = (ctx: ctx<T>) => Promise<Response> | Response;
|
|
419
|
+
type Middleware<T extends Record<string, any> = {}> = (ctx: ctx<T>, next: NextCallback) => NextCallback | Promise<Response> | Response;
|
|
542
420
|
type RouterConfig = {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
421
|
+
/**
|
|
422
|
+
* `env` allows you to define environment variables for the router.
|
|
423
|
+
* It is a record of key-value pairs where the key is the variable name
|
|
424
|
+
* and the value can be either a string or a number.
|
|
425
|
+
*/
|
|
426
|
+
env?: Record<string, string | number>;
|
|
427
|
+
/**
|
|
428
|
+
* `basePath` sets the base path for the router. This is useful for grouping
|
|
429
|
+
* routes under a specific path prefix.
|
|
430
|
+
*/
|
|
431
|
+
basePath?: string;
|
|
554
432
|
};
|
|
555
433
|
declare class TrieRouter {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
paramName: any;
|
|
566
|
-
isParam: boolean;
|
|
567
|
-
constructor(pathname?: string);
|
|
434
|
+
children: Map<string, TrieRouter>;
|
|
435
|
+
handlers: Map<HTTPMethod, {
|
|
436
|
+
callback: Callback<any>;
|
|
437
|
+
middlewares: UniqueMiddlewares | DuplicateMiddlewares;
|
|
438
|
+
}>;
|
|
439
|
+
pathname: string;
|
|
440
|
+
paramName: any;
|
|
441
|
+
isParam: boolean;
|
|
442
|
+
constructor(pathname?: string);
|
|
568
443
|
}
|
|
569
444
|
type StaticServeOption = {
|
|
570
|
-
|
|
571
|
-
|
|
445
|
+
cacheControl?: string;
|
|
446
|
+
headers?: ResponseHeaders;
|
|
572
447
|
};
|
|
573
|
-
declare class Router<
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
#private;
|
|
577
|
-
protected routers: Map<
|
|
578
|
-
string,
|
|
579
|
-
Map<
|
|
580
|
-
HTTPMethod,
|
|
581
|
-
{
|
|
448
|
+
declare class Router<T extends Record<string, any> = {}> extends MiddlewareConfigure<T> {
|
|
449
|
+
#private;
|
|
450
|
+
protected routers: Map<string, Map<HTTPMethod, {
|
|
582
451
|
callback: Callback<T>;
|
|
583
452
|
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;
|
|
453
|
+
}>>;
|
|
454
|
+
protected env: Record<string, string | number>;
|
|
455
|
+
protected triRouter: TrieRouter;
|
|
456
|
+
constructor({ basePath, env }?: RouterConfig);
|
|
457
|
+
/**
|
|
458
|
+
* Serves static files from a specified directory.
|
|
459
|
+
*
|
|
460
|
+
* This method provides two overloads:
|
|
461
|
+
* 1. `static(route: string, folder: string, option?: StaticServeOption): this;`
|
|
462
|
+
* - Serves static files from `folder` at the specified `route`.
|
|
463
|
+
* 2. `static(folder: string, option?: StaticServeOption): this;`
|
|
464
|
+
* - Serves static files from `folder` at the root (`/`).
|
|
465
|
+
*
|
|
466
|
+
* @param {string} route - The base route to serve static files from (optional in overload).
|
|
467
|
+
* @param {string} folder - The folder containing the static files.
|
|
468
|
+
* @param {StaticServeOption} [option] - Optional settings for static file serving.
|
|
469
|
+
* @returns {this} Returns the current instance to allow method chaining.
|
|
470
|
+
*/
|
|
471
|
+
static(route: string, folder: string, option?: StaticServeOption): this;
|
|
472
|
+
static(folder: string, Option?: StaticServeOption): this;
|
|
473
|
+
/**
|
|
474
|
+
* Registers a GET route with optional middleware(s)
|
|
475
|
+
* @param path - URL path pattern (supports route parameters)
|
|
476
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
477
|
+
* @returns Current instance for chaining
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* // Simple GET route
|
|
481
|
+
* app.get('/users', (ctx) => { ... });
|
|
482
|
+
*
|
|
483
|
+
* // With middleware
|
|
484
|
+
* app.get('/secure', authMiddleware, (ctx) => { ... });
|
|
485
|
+
*
|
|
486
|
+
* // With multiple middlewares
|
|
487
|
+
* app.get('/admin', [authMiddleware, adminMiddleware], (ctx) => { ... });
|
|
488
|
+
*/
|
|
489
|
+
get(path: string, callback: Callback<T>): this;
|
|
490
|
+
get(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
491
|
+
get(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
492
|
+
/**
|
|
493
|
+
* Registers a POST route with optional middleware(s)
|
|
494
|
+
* @param path - URL path pattern
|
|
495
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
496
|
+
*/
|
|
497
|
+
post(path: string, callback: Callback<T>): this;
|
|
498
|
+
post(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
499
|
+
post(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
500
|
+
/**
|
|
501
|
+
* Registers a PUT route with optional middleware(s)
|
|
502
|
+
* @param path - URL path pattern
|
|
503
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
504
|
+
*/
|
|
505
|
+
put(path: string, callback: Callback<T>): this;
|
|
506
|
+
put(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
507
|
+
put(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
508
|
+
/**
|
|
509
|
+
* Registers a PATCH route with optional middleware(s)
|
|
510
|
+
* @param path - URL path pattern
|
|
511
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
512
|
+
*/
|
|
513
|
+
patch(path: string, callback: Callback<T>): this;
|
|
514
|
+
patch(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
515
|
+
patch(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
516
|
+
/**
|
|
517
|
+
* Registers a DELETE route with optional middleware(s)
|
|
518
|
+
* @param path - URL path pattern
|
|
519
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
520
|
+
*/
|
|
521
|
+
delete(path: string, callback: Callback<T>): this;
|
|
522
|
+
delete(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
523
|
+
delete(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
524
|
+
/**
|
|
525
|
+
* Registers an OPTIONS route (primarily for CORS preflight requests)
|
|
526
|
+
* @param path - URL path pattern
|
|
527
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
528
|
+
*/
|
|
529
|
+
options(path: string, callback: Callback<T>): this;
|
|
530
|
+
options(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
531
|
+
options(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
532
|
+
/**
|
|
533
|
+
* Registers a HEAD route (returns headers only)
|
|
534
|
+
* @param path - URL path pattern
|
|
535
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
536
|
+
*/
|
|
537
|
+
head(path: string, callback: Callback<T>): this;
|
|
538
|
+
head(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
539
|
+
head(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
540
|
+
/**
|
|
541
|
+
* Registers a route that responds to all HTTP methods
|
|
542
|
+
* @param path - URL path pattern
|
|
543
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
544
|
+
*/
|
|
545
|
+
all(path: string, callback: Callback<T>): this;
|
|
546
|
+
all(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
547
|
+
all(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
548
|
+
/**
|
|
549
|
+
* Generic method registration for custom HTTP methods
|
|
550
|
+
* @param method - HTTP method name (e.g., 'PURGE')
|
|
551
|
+
* @param path - URL path pattern
|
|
552
|
+
* @param args - Handler callback or middleware(s) + handler
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* // Register custom method
|
|
556
|
+
* server.addRoute('PURGE', '/cache', purgeHandler);
|
|
557
|
+
*/
|
|
558
|
+
addRoute(method: HTTPMethod, path: string, callback: Callback<T>): this;
|
|
559
|
+
addRoute(method: HTTPMethod, path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
560
|
+
addRoute(method: HTTPMethod, path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
561
|
+
/**
|
|
562
|
+
* Mount a sub-router at specific path prefix
|
|
563
|
+
* @param path - Base path for the sub-router
|
|
564
|
+
* @param router - Router instance to mount
|
|
565
|
+
* @returns Current instance for chaining
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* const apiRouter = new Router();
|
|
569
|
+
* apiRouter.get('/users', () => { ... });
|
|
570
|
+
* server.addRouter('/api', apiRouter);
|
|
571
|
+
*/
|
|
572
|
+
addRouter(path: string, router: Router<T | any>): void;
|
|
573
|
+
/**
|
|
574
|
+
* Create route group with shared path prefix
|
|
575
|
+
* @param prefix - Path prefix for the group
|
|
576
|
+
* @param callback - Function that receives group-specific router
|
|
577
|
+
* @returns Current router instance for chaining
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* app.group('/v1', (group) => {
|
|
581
|
+
* group.get('/users', v1UserHandler);
|
|
582
|
+
* });
|
|
583
|
+
*/
|
|
584
|
+
group(prefix: string, callback: (group: Router<T>) => void): this;
|
|
585
|
+
/**
|
|
586
|
+
* Register middleware with flexible signature
|
|
587
|
+
* @overload
|
|
588
|
+
* @param path - Optional path to scope middleware
|
|
589
|
+
* @param middlewares - Middleware(s) to register
|
|
590
|
+
* @param [callback] - Optional sub-router or handler
|
|
591
|
+
*/
|
|
592
|
+
use(path: string, middlewares: Middleware<T>[], callback: Callback<T> | Router<T | any>): this;
|
|
593
|
+
use(path: string, middleware: Middleware<T>, callback: Callback<T> | Router<T | any>): this;
|
|
594
|
+
use(path: string, middlewares: Middleware<T>[]): this;
|
|
595
|
+
use(path: string, middleware: Middleware<T>): this;
|
|
596
|
+
use(path: string, callback: Callback<T> | Router<T | any>): this;
|
|
597
|
+
use(middlewares: Middleware<T>[], callback: Callback<T> | Router<T | any>): this;
|
|
598
|
+
use(middleware: Middleware<T>, callback: Callback<T> | Router<T | any>): this;
|
|
599
|
+
use(middlewares: Middleware<T>[]): this;
|
|
600
|
+
use(middleware: Middleware<T>): this;
|
|
601
|
+
use(callback: Callback<T> | Router<T | any>): this;
|
|
772
602
|
}
|
|
773
603
|
|
|
774
604
|
interface ServeResponse {
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
605
|
+
status: number;
|
|
606
|
+
headers: {
|
|
607
|
+
[key: string]: string;
|
|
608
|
+
};
|
|
609
|
+
body: string;
|
|
610
|
+
statusText: string;
|
|
781
611
|
}
|
|
782
612
|
type LoggerFnType = () => {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
613
|
+
request?: (method: HTTPMethod, pathname: string) => void;
|
|
614
|
+
response?: (method: HTTPMethod, pathname: string, status?: number) => void;
|
|
615
|
+
info?: (msg: string, ...args: unknown[]) => void;
|
|
616
|
+
warn?: (msg: string, ...args: unknown[]) => void;
|
|
617
|
+
error?: (msg: string, ...args: unknown[]) => void;
|
|
618
|
+
debug?: (msg: string, ...args: unknown[]) => void;
|
|
619
|
+
success?: (msg: string, ...args: unknown[]) => void;
|
|
790
620
|
};
|
|
791
621
|
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
|
-
|
|
622
|
+
/**
|
|
623
|
+
* `allowDuplicateMw` determines whether duplicate middleware functions
|
|
624
|
+
* are allowed in the router.
|
|
625
|
+
*
|
|
626
|
+
* - When `true`: The same middleware can be added multiple times.
|
|
627
|
+
* - When `false`: Ensures each middleware is registered only once
|
|
628
|
+
* per route or application context.
|
|
629
|
+
*
|
|
630
|
+
* @default false
|
|
631
|
+
*/
|
|
632
|
+
allowDuplicateMw?: boolean;
|
|
633
|
+
/**
|
|
634
|
+
* `overwriteMethod` controls whether existing route handlers
|
|
635
|
+
* should be overwritten when a new handler for the same
|
|
636
|
+
* HTTP method and path is added.
|
|
637
|
+
*
|
|
638
|
+
* - When `true`: The new handler replaces the existing one.
|
|
639
|
+
* - When `false`: Prevents overwriting, ensuring that the
|
|
640
|
+
* first registered handler remains active.
|
|
641
|
+
*
|
|
642
|
+
* @default true
|
|
643
|
+
*/
|
|
644
|
+
overwriteMethod?: boolean;
|
|
645
|
+
/**
|
|
646
|
+
* `logger` is an optional function that handles logging within the application.
|
|
647
|
+
* It should conform to the `LoggerFnType`, which defines the expected signature for the logging function.
|
|
648
|
+
*
|
|
649
|
+
* If provided, this function will be called for logging purposes throughout the application.
|
|
650
|
+
*/
|
|
651
|
+
logger?: LoggerFnType;
|
|
822
652
|
} & RouterConfig;
|
|
823
653
|
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>;
|
|
654
|
+
#private;
|
|
655
|
+
constructor({ basePath, env, logger, allowDuplicateMw, overwriteMethod, }?: TezXConfig);
|
|
656
|
+
protected findRoute(method: HTTPMethod, pathname: string): {
|
|
657
|
+
callback: any;
|
|
658
|
+
middlewares: Middleware<T>[];
|
|
659
|
+
params: Record<string, string>;
|
|
660
|
+
} | null;
|
|
661
|
+
serve(req: Request): Promise<ServeResponse | any>;
|
|
841
662
|
}
|
|
842
663
|
|
|
843
|
-
declare function denoAdapter<T extends Record<string, any> = {}>(
|
|
844
|
-
|
|
845
|
-
): {
|
|
846
|
-
listen: (port: number, callback?: (message: string) => void) => any;
|
|
664
|
+
declare function denoAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>): {
|
|
665
|
+
listen: (port: number, callback?: (message: string) => void) => any;
|
|
847
666
|
};
|
|
848
|
-
declare function bunAdapter<T extends Record<string, any> = {}>(
|
|
849
|
-
|
|
850
|
-
): {
|
|
851
|
-
listen: (port: number, callback?: (message: string) => void) => any;
|
|
667
|
+
declare function bunAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>): {
|
|
668
|
+
listen: (port: number, callback?: (message: string) => void) => any;
|
|
852
669
|
};
|
|
853
|
-
declare function nodeAdapter<T extends Record<string, any> = {}>(
|
|
854
|
-
|
|
855
|
-
): {
|
|
856
|
-
listen: (port: number, callback?: (message: string) => void) => void;
|
|
670
|
+
declare function nodeAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>): {
|
|
671
|
+
listen: (port: number, callback?: (message: string) => void) => void;
|
|
857
672
|
};
|
|
858
673
|
|
|
859
|
-
declare function useParams({
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
}: {
|
|
863
|
-
path: string;
|
|
864
|
-
urlPattern: string;
|
|
674
|
+
declare function useParams({ path, urlPattern, }: {
|
|
675
|
+
path: string;
|
|
676
|
+
urlPattern: string;
|
|
865
677
|
}): {
|
|
866
|
-
|
|
867
|
-
|
|
678
|
+
success: boolean;
|
|
679
|
+
params: Record<string, any>;
|
|
868
680
|
};
|
|
869
681
|
|
|
870
682
|
/**
|
|
@@ -880,51 +692,23 @@ type LogLevel = "info" | "warn" | "error" | "debug" | "success";
|
|
|
880
692
|
* @param callback - The operation to measure and execute.
|
|
881
693
|
*/
|
|
882
694
|
declare function logger(): {
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
695
|
+
request: (method: HTTPMethod, pathname: string) => void;
|
|
696
|
+
response: (method: HTTPMethod, pathname: string, status?: number) => void;
|
|
697
|
+
info: (msg: string, ...args: unknown[]) => void;
|
|
698
|
+
warn: (msg: string, ...args: unknown[]) => void;
|
|
699
|
+
error: (msg: string, ...args: unknown[]) => void;
|
|
700
|
+
debug: (msg: string, ...args: unknown[]) => void;
|
|
701
|
+
success: (msg: string, ...args: unknown[]) => void;
|
|
890
702
|
};
|
|
891
703
|
|
|
892
704
|
type CorsOptions = {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
allowedHeaders?: string[];
|
|
900
|
-
exposedHeaders?: string[];
|
|
901
|
-
credentials?: boolean;
|
|
902
|
-
maxAge?: number;
|
|
705
|
+
origin?: string | RegExp | (string | RegExp)[] | ((reqOrigin: string) => boolean);
|
|
706
|
+
methods?: string[];
|
|
707
|
+
allowedHeaders?: string[];
|
|
708
|
+
exposedHeaders?: string[];
|
|
709
|
+
credentials?: boolean;
|
|
710
|
+
maxAge?: number;
|
|
903
711
|
};
|
|
904
|
-
declare function cors(
|
|
905
|
-
option?: CorsOptions,
|
|
906
|
-
): (ctx: ctx, next: () => Promise<any>) => Promise<any>;
|
|
712
|
+
declare function cors(option?: CorsOptions): (ctx: ctx, next: () => Promise<any>) => Promise<any>;
|
|
907
713
|
|
|
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
|
-
};
|
|
714
|
+
export { type Callback, type ctx as Context, type CorsOptions, type LogLevel, type LoggerFnType, type Middleware, type NextCallback, Router, type RouterConfig, type StaticServeOption, TezX, type TezXConfig, type UrlRef, bunAdapter, cors, denoAdapter, loadEnv, logger, nodeAdapter, useParams };
|