tezx 1.0.2 → 1.0.4

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