tezx 1.0.0 → 1.0.2
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 +225 -165
- package/dist/index.js +2503 -5
- package/dist/index.mjs +2492 -5
- package/package.json +34 -34
package/dist/index.d.ts
CHANGED
|
@@ -63,9 +63,9 @@ declare class HeadersParser {
|
|
|
63
63
|
*/
|
|
64
64
|
forEach(callback: (value: string[], key: string) => void): void;
|
|
65
65
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
* Converts headers into a plain object.
|
|
67
|
+
* @returns A record of headers where single-value headers are returned as a string.
|
|
68
|
+
*/
|
|
69
69
|
toObject(): Record<string, string | string[]>;
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -88,6 +88,7 @@ type FormDataOptions = {
|
|
|
88
88
|
maxSize?: number;
|
|
89
89
|
allowedTypes?: string[];
|
|
90
90
|
sanitized?: boolean;
|
|
91
|
+
maxFiles?: number;
|
|
91
92
|
};
|
|
92
93
|
type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "OPTIONS" | "PATCH" | "HEAD" | "ALL" | "TRACE" | "CONNECT" | string;
|
|
93
94
|
declare class Request$1 {
|
|
@@ -115,46 +116,46 @@ declare class Request$1 {
|
|
|
115
116
|
readonly params: Record<string, any>;
|
|
116
117
|
constructor(req: any, params: Record<string, any>);
|
|
117
118
|
/**
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
* Parses the request body as plain text.
|
|
120
|
+
* @returns {Promise<string>} The text content of the request body.
|
|
121
|
+
*/
|
|
121
122
|
text(): Promise<string>;
|
|
122
123
|
/**
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
+
*/
|
|
127
128
|
json(): Promise<Record<string, any>>;
|
|
128
129
|
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
+
*/
|
|
137
138
|
formData(options?: FormDataOptions): Promise<Record<string, any>>;
|
|
138
139
|
}
|
|
139
140
|
|
|
140
|
-
declare class
|
|
141
|
-
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
141
|
+
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
|
+
*/
|
|
148
149
|
static json(body: any, status?: number, headers?: ResponseHeaders): Response;
|
|
149
150
|
static json(body: any, headers?: ResponseHeaders): Response;
|
|
150
151
|
static json(body: any, status?: number): Response;
|
|
151
152
|
/**
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
+
*/
|
|
158
159
|
static html(data: string, status?: number, headers?: ResponseHeaders): Response;
|
|
159
160
|
static html(data: string, headers?: ResponseHeaders): Response;
|
|
160
161
|
static html(data: string, status?: number): Response;
|
|
@@ -190,19 +191,19 @@ declare class JetResponse {
|
|
|
190
191
|
static send(body: any, headers?: ResponseHeaders): Response;
|
|
191
192
|
static send(body: any, status?: number): Response;
|
|
192
193
|
/**
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
+
*/
|
|
199
200
|
static redirect(url: string, status?: number, headers?: ResponseHeaders): Response;
|
|
200
201
|
/**
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
+
*/
|
|
206
207
|
static download(filePath: string, fileName: string): Promise<Response>;
|
|
207
208
|
/**
|
|
208
209
|
* Serves a file to the client.
|
|
@@ -274,7 +275,7 @@ interface CookieOptions {
|
|
|
274
275
|
domain?: string;
|
|
275
276
|
secure?: boolean;
|
|
276
277
|
httpOnly?: boolean;
|
|
277
|
-
sameSite?:
|
|
278
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
278
279
|
}
|
|
279
280
|
type ResponseHeaders = Record<string, string>;
|
|
280
281
|
declare class Context<T extends Record<string, any> = {}> {
|
|
@@ -291,19 +292,14 @@ declare class Context<T extends Record<string, any> = {}> {
|
|
|
291
292
|
*/
|
|
292
293
|
headers: HeadersParser;
|
|
293
294
|
/**
|
|
294
|
-
*
|
|
295
|
-
* @type {
|
|
295
|
+
* Request path without query parameters
|
|
296
|
+
* @type {string}
|
|
296
297
|
*/
|
|
297
|
-
res: Response;
|
|
298
|
-
/**
|
|
299
|
-
* Request path without query parameters
|
|
300
|
-
* @type {string}
|
|
301
|
-
*/
|
|
302
298
|
readonly pathname: string;
|
|
303
299
|
/**
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
300
|
+
* Full request URL including protocol and query string
|
|
301
|
+
* @type {string}
|
|
302
|
+
*/
|
|
307
303
|
readonly url: string;
|
|
308
304
|
/**
|
|
309
305
|
* HTTP request method (GET, POST, PUT, DELETE, etc.)
|
|
@@ -323,14 +319,14 @@ declare class Context<T extends Record<string, any> = {}> {
|
|
|
323
319
|
finalized: boolean;
|
|
324
320
|
constructor(req: any);
|
|
325
321
|
/**
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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
|
+
*/
|
|
334
330
|
get cookies(): {
|
|
335
331
|
/**
|
|
336
332
|
* Get a specific cookie by name.
|
|
@@ -339,62 +335,62 @@ declare class Context<T extends Record<string, any> = {}> {
|
|
|
339
335
|
*/
|
|
340
336
|
get: (cookie: string) => string;
|
|
341
337
|
/**
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
338
|
+
* Get all cookies as an object.
|
|
339
|
+
* @returns {Record<string, string>} - An object containing all cookies.
|
|
340
|
+
*/
|
|
345
341
|
all: () => Record<string, string>;
|
|
346
342
|
/**
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
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
|
+
*/
|
|
351
347
|
delete: (name: string, options?: CookieOptions) => void;
|
|
352
348
|
/**
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
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
|
+
*/
|
|
358
354
|
set: (name: string, value: string, options?: CookieOptions) => void;
|
|
359
355
|
};
|
|
360
356
|
/**
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
json(body: any, status?: number, headers?: ResponseHeaders):
|
|
368
|
-
json(body: any, headers?: ResponseHeaders):
|
|
369
|
-
json(body: any, status?: number):
|
|
370
|
-
/**
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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
|
+
*/
|
|
378
374
|
send(body: any, status?: number, headers?: ResponseHeaders): any;
|
|
379
375
|
send(body: any, headers?: ResponseHeaders): any;
|
|
380
376
|
send(body: any, status?: number): any;
|
|
381
377
|
/**
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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
|
+
*/
|
|
388
384
|
html(data: string, status?: number, headers?: ResponseHeaders): any;
|
|
389
385
|
html(data: string, headers?: ResponseHeaders): any;
|
|
390
386
|
html(data: string, status?: number): any;
|
|
391
387
|
/**
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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
|
+
*/
|
|
398
394
|
text(data: string, status?: number, headers?: ResponseHeaders): any;
|
|
399
395
|
text(data: string, headers?: ResponseHeaders): any;
|
|
400
396
|
text(data: string, status?: number): any;
|
|
@@ -409,10 +405,10 @@ declare class Context<T extends Record<string, any> = {}> {
|
|
|
409
405
|
xml(data: string, headers?: ResponseHeaders): any;
|
|
410
406
|
xml(data: string, status?: number): any;
|
|
411
407
|
/**
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
408
|
+
* HTTP status code..
|
|
409
|
+
* @param status - number.
|
|
410
|
+
* @returns Response object with context all method.
|
|
411
|
+
*/
|
|
416
412
|
status: (status: number) => this;
|
|
417
413
|
/**
|
|
418
414
|
* Redirects to a given URL.
|
|
@@ -423,19 +419,19 @@ declare class Context<T extends Record<string, any> = {}> {
|
|
|
423
419
|
*/
|
|
424
420
|
redirect(url: string, status?: number, headers?: ResponseHeaders): Response;
|
|
425
421
|
/**
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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
|
+
*/
|
|
431
427
|
download(filePath: string, fileName: string): Promise<Response>;
|
|
432
428
|
/**
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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
|
+
*/
|
|
439
435
|
sendFile(filePath: string, fileName?: string, headers?: ResponseHeaders): Promise<Response>;
|
|
440
436
|
sendFile(filePath: string, headers?: ResponseHeaders): Promise<Response>;
|
|
441
437
|
sendFile(filePath: string, fileName?: string): Promise<Response>;
|
|
@@ -473,10 +469,11 @@ declare class CommonHandler {
|
|
|
473
469
|
onError(callback: <T extends Record<string, any> = {}>(err: string, ctx: ctx<T>) => any): this;
|
|
474
470
|
}
|
|
475
471
|
|
|
472
|
+
type DuplicateMiddlewares = Middleware<any>[];
|
|
473
|
+
type UniqueMiddlewares = Set<Middleware<any>>;
|
|
476
474
|
declare class TriMiddleware {
|
|
477
475
|
children: Map<string, TriMiddleware>;
|
|
478
|
-
middlewares:
|
|
479
|
-
groupMiddlewares: Map<string, Middleware<any>[]>;
|
|
476
|
+
middlewares: DuplicateMiddlewares | UniqueMiddlewares;
|
|
480
477
|
isOptional: boolean;
|
|
481
478
|
pathname: string;
|
|
482
479
|
constructor(pathname?: string);
|
|
@@ -490,33 +487,61 @@ declare class MiddlewareConfigure<T extends Record<string, any> = {}> extends Co
|
|
|
490
487
|
|
|
491
488
|
type NextCallback = () => Promise<any>;
|
|
492
489
|
type ctx<T extends Record<string, any> = {}> = Context<T> & T;
|
|
493
|
-
type Callback<T extends Record<string, any> = {}> = (ctx: ctx<T>) =>
|
|
494
|
-
type Middleware<T extends Record<string, any> = {}> = (ctx: ctx<T>, next: NextCallback) =>
|
|
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;
|
|
495
492
|
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
|
+
*/
|
|
496
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
|
+
*/
|
|
497
503
|
basePath?: string;
|
|
498
504
|
};
|
|
499
505
|
declare class TrieRouter {
|
|
500
506
|
children: Map<string, TrieRouter>;
|
|
501
507
|
handlers: Map<HTTPMethod, {
|
|
502
|
-
handlerID?: string;
|
|
503
508
|
callback: Callback<any>;
|
|
504
|
-
middlewares:
|
|
509
|
+
middlewares: UniqueMiddlewares | DuplicateMiddlewares;
|
|
505
510
|
}>;
|
|
506
511
|
pathname: string;
|
|
507
512
|
paramName: any;
|
|
508
513
|
isParam: boolean;
|
|
509
514
|
constructor(pathname?: string);
|
|
510
515
|
}
|
|
516
|
+
type StaticServeOption = {
|
|
517
|
+
cacheControl?: string;
|
|
518
|
+
headers?: ResponseHeaders;
|
|
519
|
+
};
|
|
511
520
|
declare class Router<T extends Record<string, any> = {}> extends MiddlewareConfigure<T> {
|
|
512
521
|
#private;
|
|
513
522
|
protected routers: Map<string, Map<HTTPMethod, {
|
|
514
523
|
callback: Callback<T>;
|
|
515
|
-
|
|
516
|
-
middlewares: Middleware<T>[];
|
|
524
|
+
middlewares: UniqueMiddlewares | DuplicateMiddlewares;
|
|
517
525
|
}>>;
|
|
518
|
-
protected
|
|
526
|
+
protected env: Record<string, string | number>;
|
|
527
|
+
protected triRouter: TrieRouter;
|
|
519
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;
|
|
520
545
|
/**
|
|
521
546
|
* Registers a GET route with optional middleware(s)
|
|
522
547
|
* @param path - URL path pattern (supports route parameters)
|
|
@@ -537,10 +562,10 @@ declare class Router<T extends Record<string, any> = {}> extends MiddlewareConfi
|
|
|
537
562
|
get(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
538
563
|
get(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
539
564
|
/**
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
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
|
+
*/
|
|
544
569
|
post(path: string, callback: Callback<T>): this;
|
|
545
570
|
post(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
546
571
|
post(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
@@ -593,29 +618,29 @@ declare class Router<T extends Record<string, any> = {}> extends MiddlewareConfi
|
|
|
593
618
|
all(path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
594
619
|
all(path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
595
620
|
/**
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
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
|
+
*/
|
|
605
630
|
addRoute(method: HTTPMethod, path: string, callback: Callback<T>): this;
|
|
606
631
|
addRoute(method: HTTPMethod, path: string, middlewares: Middleware<T>[], callback: Callback<T>): this;
|
|
607
632
|
addRoute(method: HTTPMethod, path: string, middlewares: Middleware<T>, callback: Callback<T>): this;
|
|
608
633
|
/**
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
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
|
+
*/
|
|
619
644
|
addRouter(path: string, router: Router<T>): void;
|
|
620
645
|
/**
|
|
621
646
|
* Create route group with shared path prefix
|
|
@@ -630,12 +655,12 @@ declare class Router<T extends Record<string, any> = {}> extends MiddlewareConfi
|
|
|
630
655
|
*/
|
|
631
656
|
group(prefix: string, callback: (group: Router<T>) => void): this;
|
|
632
657
|
/**
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
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
|
+
*/
|
|
639
664
|
use(path: string, middlewares: Middleware<T>[], callback: Callback<T> | Router<T | any>): this;
|
|
640
665
|
use(path: string, middleware: Middleware<T>, callback: Callback<T> | Router<T | any>): this;
|
|
641
666
|
use(path: string, middlewares: Middleware<T>[]): this;
|
|
@@ -665,32 +690,67 @@ type LoggerFnType = () => {
|
|
|
665
690
|
debug?: (msg: string, ...args: unknown[]) => void;
|
|
666
691
|
success?: (msg: string, ...args: unknown[]) => void;
|
|
667
692
|
};
|
|
668
|
-
type
|
|
693
|
+
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
|
+
*/
|
|
669
723
|
logger?: LoggerFnType;
|
|
670
|
-
middlewareRule?: "follow" | "ignore";
|
|
671
724
|
} & RouterConfig;
|
|
672
|
-
declare class
|
|
725
|
+
declare class TezX<T extends Record<string, any> = {}> extends Router<T> {
|
|
673
726
|
#private;
|
|
674
|
-
constructor({ basePath,
|
|
727
|
+
constructor({ basePath, env, logger, allowDuplicateMw, overwriteMethod, }?: TezXConfig);
|
|
675
728
|
protected findRoute(method: HTTPMethod, pathname: string): {
|
|
676
729
|
callback: any;
|
|
677
730
|
middlewares: Middleware<T>[];
|
|
678
731
|
params: Record<string, string>;
|
|
679
|
-
handlerID?: string;
|
|
680
732
|
} | null;
|
|
681
733
|
serve(req: Request): Promise<ServeResponse | any>;
|
|
682
734
|
}
|
|
683
735
|
|
|
684
|
-
declare function denoAdapter<T extends Record<string, any> = {}>(
|
|
736
|
+
declare function denoAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>): {
|
|
685
737
|
listen: (port: number, callback?: (message: string) => void) => any;
|
|
686
738
|
};
|
|
687
|
-
declare function bunAdapter<T extends Record<string, any> = {}>(
|
|
739
|
+
declare function bunAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>): {
|
|
688
740
|
listen: (port: number, callback?: (message: string) => void) => any;
|
|
689
741
|
};
|
|
690
|
-
declare function nodeAdapter<T extends Record<string, any> = {}>(
|
|
742
|
+
declare function nodeAdapter<T extends Record<string, any> = {}>(TezX: TezX<T>): {
|
|
691
743
|
listen: (port: number, callback?: (message: string) => void) => void;
|
|
692
744
|
};
|
|
693
745
|
|
|
746
|
+
declare function useParams({ path, urlPattern, }: {
|
|
747
|
+
path: string;
|
|
748
|
+
urlPattern: string;
|
|
749
|
+
}): {
|
|
750
|
+
success: boolean;
|
|
751
|
+
params: Record<string, any>;
|
|
752
|
+
};
|
|
753
|
+
|
|
694
754
|
/**
|
|
695
755
|
* Loads environment variables from .env files.
|
|
696
756
|
* @param basePath - The base directory where .env files are located.
|
|
@@ -723,4 +783,4 @@ type CorsOptions = {
|
|
|
723
783
|
};
|
|
724
784
|
declare function cors(option?: CorsOptions): (ctx: ctx, next: () => Promise<any>) => Promise<any>;
|
|
725
785
|
|
|
726
|
-
export {
|
|
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 };
|