tezx 1.0.4 → 1.0.6

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