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