tezx 1.0.4 → 1.0.5

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