@catbee/utils 1.0.5 → 2.0.0-next.0

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.
Files changed (121) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +27 -27
  3. package/array/array.utils.d.ts +191 -0
  4. package/array/index.cjs +246 -0
  5. package/array/index.d.ts +25 -0
  6. package/array/index.mjs +228 -0
  7. package/async/async.utils.d.ts +296 -0
  8. package/async/index.cjs +428 -0
  9. package/async/index.d.ts +25 -0
  10. package/async/index.mjs +407 -0
  11. package/cache/cache.utils.d.ts +176 -0
  12. package/cache/index.cjs +292 -0
  13. package/cache/index.d.ts +25 -0
  14. package/cache/index.mjs +290 -0
  15. package/config/config.d.ts +57 -0
  16. package/config/index.cjs +136 -0
  17. package/config/index.d.ts +26 -0
  18. package/config/index.mjs +131 -0
  19. package/context-store/context-store.utils.d.ts +212 -0
  20. package/context-store/index.cjs +267 -0
  21. package/context-store/index.d.ts +25 -0
  22. package/context-store/index.mjs +261 -0
  23. package/crypto/crypto.utils.d.ts +183 -0
  24. package/crypto/index.cjs +182 -0
  25. package/crypto/index.d.ts +25 -0
  26. package/crypto/index.mjs +166 -0
  27. package/date/date.utils.d.ts +190 -0
  28. package/date/index.cjs +295 -0
  29. package/date/index.d.ts +25 -0
  30. package/date/index.mjs +283 -0
  31. package/decorators/decorators.utils.d.ts +705 -0
  32. package/decorators/index.cjs +913 -0
  33. package/decorators/index.d.ts +25 -0
  34. package/decorators/index.mjs +872 -0
  35. package/dir/dir.utils.d.ts +216 -0
  36. package/dir/index.cjs +416 -0
  37. package/dir/index.d.ts +25 -0
  38. package/dir/index.mjs +389 -0
  39. package/env/env.utils.d.ts +400 -0
  40. package/env/index.cjs +761 -0
  41. package/env/index.d.ts +25 -0
  42. package/env/index.mjs +758 -0
  43. package/exception/exception.utils.d.ts +253 -0
  44. package/exception/index.cjs +362 -0
  45. package/exception/index.d.ts +25 -0
  46. package/exception/index.mjs +338 -0
  47. package/fs/fs.utils.d.ts +196 -0
  48. package/fs/index.cjs +253 -0
  49. package/fs/index.d.ts +25 -0
  50. package/fs/index.mjs +228 -0
  51. package/http-status-codes/http-status-codes.d.ts +289 -0
  52. package/http-status-codes/index.cjs +96 -0
  53. package/http-status-codes/index.d.ts +25 -0
  54. package/http-status-codes/index.mjs +94 -0
  55. package/id/id.utils.d.ts +59 -0
  56. package/id/index.cjs +62 -0
  57. package/id/index.d.ts +25 -0
  58. package/id/index.mjs +56 -0
  59. package/index.cjs +218 -0
  60. package/index.d.ts +51 -0
  61. package/index.mjs +51 -0
  62. package/logger/index.cjs +334 -0
  63. package/logger/index.d.ts +25 -0
  64. package/logger/index.mjs +313 -0
  65. package/logger/logger.utils.d.ts +210 -0
  66. package/middleware/index.cjs +177 -0
  67. package/middleware/index.d.ts +25 -0
  68. package/middleware/index.mjs +170 -0
  69. package/middleware/middleware.utils.d.ts +123 -0
  70. package/obj/index.cjs +317 -0
  71. package/obj/index.d.ts +25 -0
  72. package/obj/index.mjs +301 -0
  73. package/obj/obj.utils.d.ts +156 -0
  74. package/package.json +172 -20
  75. package/performance/index.cjs +231 -0
  76. package/performance/index.d.ts +25 -0
  77. package/performance/index.mjs +225 -0
  78. package/performance/performance.utils.d.ts +159 -0
  79. package/request/index.cjs +202 -0
  80. package/request/index.d.ts +26 -0
  81. package/request/index.mjs +194 -0
  82. package/request/request.utils.d.ts +109 -0
  83. package/response/index.cjs +234 -0
  84. package/response/index.d.ts +26 -0
  85. package/response/index.mjs +222 -0
  86. package/response/response.utils.d.ts +186 -0
  87. package/server/index.cjs +1627 -0
  88. package/server/index.d.ts +28 -0
  89. package/server/index.mjs +1617 -0
  90. package/server/server.builder.d.ts +531 -0
  91. package/server/server.d.ts +303 -0
  92. package/stream/index.cjs +151 -0
  93. package/stream/index.d.ts +25 -0
  94. package/stream/index.mjs +144 -0
  95. package/stream/stream.utils.d.ts +111 -0
  96. package/string/index.cjs +109 -0
  97. package/string/index.d.ts +25 -0
  98. package/string/index.mjs +95 -0
  99. package/string/string.utils.d.ts +124 -0
  100. package/type/index.cjs +129 -0
  101. package/type/index.d.ts +25 -0
  102. package/type/index.mjs +119 -0
  103. package/type/type.utils.d.ts +129 -0
  104. package/types/api-response.d.ts +175 -0
  105. package/types/common.d.ts +148 -0
  106. package/types/config.d.ts +88 -0
  107. package/types/index.cjs +34 -0
  108. package/types/index.d.ts +28 -0
  109. package/types/index.mjs +32 -0
  110. package/types/server.d.ts +291 -0
  111. package/url/index.cjs +201 -0
  112. package/url/index.d.ts +25 -0
  113. package/url/index.mjs +189 -0
  114. package/url/url.utils.d.ts +164 -0
  115. package/validate/index.cjs +212 -0
  116. package/validate/index.d.ts +25 -0
  117. package/validate/index.mjs +188 -0
  118. package/validate/validate.utils.d.ts +200 -0
  119. package/build/index.cjs +0 -7579
  120. package/build/index.d.ts +0 -5774
  121. package/build/index.mjs +0 -7274
@@ -0,0 +1,705 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import 'reflect-metadata';
26
+ import type { RequestHandler, Router } from 'express';
27
+ /**
28
+ * Supported HTTP methods for route decorators
29
+ */
30
+ export type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'head' | 'trace' | 'connect';
31
+ /**
32
+ * Represents a route definition for controller methods
33
+ */
34
+ export interface RouteDefinition {
35
+ /** The URL path for this route */
36
+ path: string;
37
+ /** HTTP method for this route */
38
+ method: HttpMethod;
39
+ /** Name of the handler method in the controller class */
40
+ handlerName: string;
41
+ }
42
+ /**
43
+ * Parameter decoration definition for method parameters
44
+ */
45
+ export interface ParamDefinition {
46
+ /** Parameter position in method signature */
47
+ index: number;
48
+ /** Type of parameter (query, body, etc.) */
49
+ type: 'query' | 'param' | 'body' | 'req' | 'res' | 'logger' | 'reqHeader' | 'reqId' | 'cookie';
50
+ /** Optional key for extracting specific property */
51
+ key?: string;
52
+ /** Optional ParamOptions for advanced extraction */
53
+ options?: ParamOptions;
54
+ }
55
+ export type CachedRateLimiter = {
56
+ limiter: ReturnType<typeof import('express-rate-limit').rateLimit>;
57
+ config: string;
58
+ };
59
+ type Constructor<T = any> = new (...args: any[]) => T;
60
+ export declare class DIContainer {
61
+ private instances;
62
+ private constructing;
63
+ private propertyInjections;
64
+ register<T>(target: Constructor<T>): void;
65
+ /**
66
+ * Register a property injection to be resolved when the target class is instantiated
67
+ */
68
+ registerPropertyInjection(target: object, propertyKey: string | symbol, injectClass: Constructor): void;
69
+ get<T>(target: Constructor<T>): T;
70
+ private applyPropertyInjections;
71
+ clear(): void;
72
+ }
73
+ /**
74
+ * Injectable decorator for marking classes as injectable.
75
+ *
76
+ * @returns Class decorator that marks a class as injectable and registers it with the DI container.
77
+ */
78
+ export declare function Injectable(): ClassDecorator;
79
+ /**
80
+ * Inject decorator for injecting dependencies into class properties.
81
+ *
82
+ * @param targetClass - The class to inject
83
+ * @returns Property decorator that injects the specified class into the property
84
+ */
85
+ export declare function Inject<T>(targetClass: new (...args: any[]) => T): PropertyDecorator;
86
+ /**
87
+ * Inject function for retrieving instances from the DI container.
88
+ * @param targetClass - The class to inject
89
+ *
90
+ * @returns The instance of the requested class
91
+ *
92
+ * @example
93
+ * const a = inject(TestClass);
94
+ */
95
+ export declare function inject<T>(targetClass: new (...args: any[]) => T): T;
96
+ /**
97
+ * Decorator for GET HTTP method routes.
98
+ *
99
+ * @param path - URL path for the route
100
+ * @returns Method decorator
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * @Get('/users')
105
+ * getUsers() {
106
+ * return this.userService.findAll();
107
+ * }
108
+ * ```
109
+ */
110
+ export declare const Get: (path: string) => MethodDecorator;
111
+ /**
112
+ * Decorator for POST HTTP method routes.
113
+ *
114
+ * @param path - URL path for the route
115
+ * @returns Method decorator
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * @Post('/users')
120
+ * createUser(@Body() userData: any) {
121
+ * return this.userService.create(userData);
122
+ * }
123
+ * ```
124
+ */
125
+ export declare const Post: (path: string) => MethodDecorator;
126
+ /**
127
+ * Decorator for PUT HTTP method routes.
128
+ *
129
+ * @param path - URL path for the route
130
+ * @returns Method decorator
131
+ */
132
+ export declare const Put: (path: string) => MethodDecorator;
133
+ /**
134
+ * Decorator for PATCH HTTP method routes.
135
+ *
136
+ * @param path - URL path for the route
137
+ * @returns Method decorator
138
+ */
139
+ export declare const Patch: (path: string) => MethodDecorator;
140
+ /**
141
+ * Decorator for DELETE HTTP method routes.
142
+ *
143
+ * @param path - URL path for the route
144
+ * @returns Method decorator
145
+ */
146
+ export declare const Delete: (path: string) => MethodDecorator;
147
+ /**
148
+ * Decorator for OPTIONS HTTP method routes.
149
+ *
150
+ * @param path - URL path for the route
151
+ * @returns Method decorator
152
+ */
153
+ export declare const Options: (path: string) => MethodDecorator;
154
+ /**
155
+ * Decorator for HEAD HTTP method routes.
156
+ *
157
+ * @param path - URL path for the route
158
+ * @returns Method decorator
159
+ */
160
+ export declare const Head: (path: string) => MethodDecorator;
161
+ /**
162
+ * Decorator for TRACE HTTP method routes.
163
+ *
164
+ * @param path - URL path for the route
165
+ * @returns Method decorator
166
+ */
167
+ export declare const Trace: (path: string) => MethodDecorator;
168
+ /**
169
+ * Decorator for CONNECT HTTP method routes.
170
+ *
171
+ * @param path - URL path for the route
172
+ * @returns Method decorator
173
+ */
174
+ export declare const Connect: (path: string) => MethodDecorator;
175
+ /**
176
+ * Decorator that marks a class as a controller with a base path.
177
+ * Used as the entry point for routing configuration.
178
+ *
179
+ * @param basePath - Base URL path for all routes in this controller
180
+ * @returns Class decorator
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * @Controller('/api/users')
185
+ * class UserController {
186
+ * // Controller methods...
187
+ * }
188
+ * ```
189
+ */
190
+ export declare function Controller(basePath: string): ClassDecorator;
191
+ /**
192
+ * Decorator that applies middleware to a controller method or an entire controller.
193
+ * Multiple middlewares can be applied and will execute in order.
194
+ *
195
+ * @param middlewares - Express middleware functions to apply
196
+ * @returns Method decorator or Class decorator
197
+ *
198
+ * @example
199
+ * ```ts
200
+ * @Get('/protected')
201
+ * @Use(authMiddleware, loggingMiddleware)
202
+ * getProtectedResource() {
203
+ * // This route is protected by auth middleware
204
+ * }
205
+ *
206
+ * @Controller('/api')
207
+ * @Use(commonMiddleware)
208
+ * class ApiController {
209
+ * // All routes in this controller use the middleware
210
+ * }
211
+ * ```
212
+ */
213
+ export declare function Use(...middlewares: RequestHandler[]): MethodDecorator & ClassDecorator;
214
+ /**
215
+ * Options for parameter decorators
216
+ * @template T - Type of the parameter value after transformation
217
+ *
218
+ * @property type - Base type of the parameter (default: 'string')'
219
+ * @property dataType - Data structure type (single, array, object)
220
+ * @property delimiter - Delimiter for array types
221
+ * @property default - Default value if parameter is missing
222
+ * @property required - Whether the parameter is required
223
+ * @property throwError - Throw error on validation failure
224
+ * @property validate - Custom validation function
225
+ * @property transform - Custom transformation function
226
+ */
227
+ export interface ParamOptions<T = any> {
228
+ /** Base type of the parameter (default: 'string') */
229
+ type?: 'string' | 'number' | 'boolean';
230
+ /** Data structure type (default: 'single') */
231
+ dataType?: 'single' | 'array' | 'object';
232
+ /** Delimiter for array types (default: ',') */
233
+ delimiter?: string;
234
+ /** Default value if parameter is missing */
235
+ default?: T;
236
+ /** Whether the parameter is required (default: false) */
237
+ required?: boolean;
238
+ /** Throw error on validation failure (default: true) */
239
+ throwError?: boolean;
240
+ /** Minimum value for number type */
241
+ min?: number;
242
+ /** Maximum value for number type */
243
+ max?: number;
244
+ /** Regex pattern the value must match */
245
+ pattern?: RegExp;
246
+ /** Name of the pattern for error messages */
247
+ patternName?: string;
248
+ /** Custom validation function */
249
+ validate?: (value: any) => boolean;
250
+ /** Custom transformation function */
251
+ transform?: (value: any) => any;
252
+ }
253
+ export declare function createParamDecorator(type: ParamDefinition['type'], key?: string): (paramKey?: string) => ParameterDecorator;
254
+ export declare function createParamDecoratorWithoutParam(type: ParamDefinition['type']): () => ParameterDecorator;
255
+ /**
256
+ * Decorator that extracts query parameters from request.
257
+ *
258
+ * @param paramKey - Optional key to extract specific query parameter
259
+ * @param options - Optional ParamOptions
260
+ * @returns Parameter decorator
261
+ *
262
+ * @example
263
+ * ```ts
264
+ * @Get('/search')
265
+ * search(@Query('term') term: string, @Query('page', { type: 'number', default: 1 }) page: number) {
266
+ * // term will contain the value of req.query.term
267
+ * // page will contain the numeric value of req.query.page or default to 1
268
+ * }
269
+ * ```
270
+ */
271
+ export declare const Query: (paramKey?: string, options?: ParamOptions) => ParameterDecorator;
272
+ /**
273
+ * Decorator that extracts route parameters from request.
274
+ *
275
+ * @param paramKey - Optional key to extract specific route parameter
276
+ * @param options - Optional ParamOptions
277
+ * @returns Parameter decorator
278
+ *
279
+ * @example
280
+ * ```ts
281
+ * @Get('/users/:id')
282
+ * getUser(@Param('id') id: string) {
283
+ * // id will contain the value of req.params.id
284
+ * }
285
+ * ```
286
+ */
287
+ export declare const Param: (paramKey?: string, options?: ParamOptions) => ParameterDecorator;
288
+ /**
289
+ * Decorator that extracts body or body property from request.
290
+ *
291
+ * @param paramKey - Optional key to extract specific body property
292
+ * @returns Parameter decorator
293
+ *
294
+ * @example
295
+ * ```ts
296
+ * @Post('/users')
297
+ * createUser(@Body() userData: any) {
298
+ * // userData will contain the entire req.body
299
+ * }
300
+ *
301
+ * @Post('/update')
302
+ * updateName(@Body('name') name: string) {
303
+ * // name will contain the value of req.body.name
304
+ * }
305
+ * ```
306
+ */
307
+ export declare const Body: (paramKey?: string) => ParameterDecorator;
308
+ /**
309
+ * Decorator that injects a logger instance.
310
+ * @returns Parameter decorator
311
+ *
312
+ * @example
313
+ * ```ts
314
+ * @Get('/log')
315
+ * log(@ReqLogger() logger: Logger) {
316
+ * logger.info('Logging request...');
317
+ * }
318
+ * ```
319
+ */
320
+ export declare const ReqLogger: () => ParameterDecorator;
321
+ /**
322
+ * Decorator that extracts request ID from headers.
323
+ * @returns Parameter decorator
324
+ *
325
+ * @example
326
+ * ```ts
327
+ * @Get('/data')
328
+ * getData(@ReqId() reqId: string) {
329
+ * // reqId will contain the value of req.headers['x-request-id'] or req.id
330
+ * }
331
+ * ```
332
+ */
333
+ export declare const ReqId: () => ParameterDecorator;
334
+ /**
335
+ * Decorator that extracts request headers.
336
+ * @param key - Optional key to extract specific header
337
+ * @returns Parameter decorator
338
+ *
339
+ * @example
340
+ * ```ts
341
+ * @Get('/data')
342
+ * getData(@ReqHeader('Authorization') authHeader: string) {
343
+ * // authHeader will contain the value of req.headers['authorization']
344
+ * }
345
+ * ```
346
+ */
347
+ export declare const ReqHeader: (paramKey?: string) => ParameterDecorator;
348
+ /**
349
+ * Decorator that extracts cookies from request.
350
+ * @param key - Optional key to extract specific cookie
351
+ * @returns Parameter decorator
352
+ *
353
+ * @example
354
+ * ```ts
355
+ * @Get('/data')
356
+ * getData(@ReqCookie('session_id') sessionId: string) {
357
+ * // sessionId will contain the value of req.cookies['session_id']
358
+ * }
359
+ * ```
360
+ */
361
+ export declare const ReqCookie: (paramKey?: string) => ParameterDecorator;
362
+ /**
363
+ * Decorator that injects the entire request object.
364
+ *
365
+ * @returns Parameter decorator
366
+ *
367
+ * @example
368
+ * ```ts
369
+ * @Get('/complex')
370
+ * complex(@Req() req: Request) {
371
+ * // Access the full request object
372
+ * console.log(req.headers);
373
+ * }
374
+ * ```
375
+ */
376
+ export declare const Req: () => ParameterDecorator;
377
+ /**
378
+ * Decorator that injects the response object.
379
+ *
380
+ * @returns Parameter decorator
381
+ *
382
+ * @example
383
+ * ```ts
384
+ * @Get('/custom')
385
+ * custom(@Res() res: Response) {
386
+ * // Direct access to response object
387
+ * return res.status(201).send('Created');
388
+ * }
389
+ * ```
390
+ */
391
+ export declare const Res: () => ParameterDecorator;
392
+ /**
393
+ * Decorator that sets a custom HTTP status code for a response.
394
+ *
395
+ * @param status - HTTP status code to use
396
+ * @returns Method decorator
397
+ *
398
+ * @example
399
+ * ```ts
400
+ * @Post('/users')
401
+ * @HttpCode(201)
402
+ * createUser(@Body() userData: any) {
403
+ * // Response will have 201 Created status code
404
+ * return { id: '123', ...userData };
405
+ * }
406
+ * ```
407
+ */
408
+ export declare function HttpCode(status: number): MethodDecorator;
409
+ /**
410
+ * Decorator that adds a custom HTTP header to the response.
411
+ *
412
+ * @param header - Header name-value pairs or a single header name and value
413
+ * @param value - Header value if a single header name is provided
414
+ * @returns Method decorator
415
+ *
416
+ * @example
417
+ * ```ts
418
+ * @Get('/data')
419
+ * @Header('Cache-Control', 'max-age=60')
420
+ * getData() {
421
+ * // Response will include the Cache-Control header
422
+ * return { data: '...' };
423
+ * }
424
+ */
425
+ export declare function Header(name: string, value: string): MethodDecorator & ClassDecorator;
426
+ /**
427
+ * Decorator that adds a custom HTTP headers to the response.
428
+ *
429
+ * @param headers - Header name-value pairs or a single header name and value
430
+ * @param value - Header value if a single header name is provided
431
+ * @returns Method decorator
432
+ *
433
+ * @example
434
+ * ```ts
435
+ * @Get('/data')
436
+ * @Headers('Cache-Control', 'max-age=60')
437
+ * getData() {
438
+ * // Response will include the Cache-Control header
439
+ * return { data: '...' };
440
+ * }
441
+ *
442
+ * @Get('/data/:id')
443
+ * @Headers({
444
+ * 'Cache-Control': 'max-age=60',
445
+ * 'X-Custom-Header': 'custom-value',
446
+ * 'Content-Security-Policy': "default-src 'self'"
447
+ * })
448
+ * getData() {
449
+ * // Response will include all specified headers
450
+ * return { data: '...' };
451
+ * }
452
+ *
453
+ * ```
454
+ */
455
+ export declare function Headers(headers: Record<string, string> | string, value?: string): MethodDecorator & ClassDecorator;
456
+ /**
457
+ * Decorator that registers a function to run before route handler execution.
458
+ * Useful for pre-processing or logging.
459
+ *
460
+ * @param fn - Function to execute before the handler
461
+ * @returns Method decorator or Class decorator
462
+ *
463
+ * @example
464
+ * ```ts
465
+ * @Get('/users/:id')
466
+ * @Before((req, res) => console.log(`Accessing user ${req.params.id}`))
467
+ * getUser(@Param('id') id: string) {
468
+ * // Function will log before this handler runs
469
+ * }
470
+ *
471
+ * @Controller('/api')
472
+ * @Before((req, res) => console.log(`API access: ${req.path}`))
473
+ * class ApiController {
474
+ * // Hook runs before all routes in this controller
475
+ * }
476
+ * ```
477
+ */
478
+ export declare function Before(fn: Function): MethodDecorator & ClassDecorator;
479
+ /**
480
+ * Decorator that registers a function to run after route handler execution.
481
+ * Can access the handler's result.
482
+ *
483
+ * @param fn - Function to execute after the handler
484
+ * @returns Method decorator or Class decorator
485
+ *
486
+ * @example
487
+ * ```ts
488
+ * @Get('/users/:id')
489
+ * @After((req, res, result) => console.log(`User data sent: ${JSON.stringify(result)}`))
490
+ * getUser(@Param('id') id: string) {
491
+ * // After this handler, the function will log the returned data
492
+ * return { id, name: 'Example' };
493
+ * }
494
+ *
495
+ * @Controller('/api')
496
+ * @After((req, res, result) => console.log(`API response: ${JSON.stringify(result)}`))
497
+ * class ApiController {
498
+ * // Hook runs after all routes in this controller
499
+ * }
500
+ * ```
501
+ */
502
+ export declare function After(fn: Function): MethodDecorator & ClassDecorator;
503
+ /**
504
+ * Decorator that requires specific roles for accessing a route.
505
+ * Must be used with authentication middleware.
506
+ *
507
+ * Check req.user.roles for user roles[].
508
+ *
509
+ * @param roles - List of roles that can access this route
510
+ * @returns Method decorator
511
+ *
512
+ * @example
513
+ * ```ts
514
+ * @Get('/admin/settings')
515
+ * @Roles('admin', 'superuser')
516
+ * getSettings() {
517
+ * // Only admins and superusers can access
518
+ * return { settings: [...] };
519
+ * }
520
+ * ```
521
+ */
522
+ export declare function Roles(...roles: string[]): MethodDecorator & ClassDecorator;
523
+ /**
524
+ * Decorator that redirects to another URL.
525
+ *
526
+ * @param url - URL to redirect to (can be absolute or relative)
527
+ * @param statusCode - HTTP status code for redirect (default: 302)
528
+ * @returns Method decorator
529
+ *
530
+ * @example
531
+ * ```ts
532
+ * @Get('/old-path')
533
+ * @Redirect('/new-path', 301)
534
+ * redirectToNewPath() {
535
+ * // This method won't be executed; automatic redirect happens
536
+ * }
537
+ *
538
+ * @Get('/dynamic-redirect')
539
+ * @Redirect()
540
+ * getDynamicRedirect() {
541
+ * // Return an object with url and optionally statusCode
542
+ * return { url: '/calculated-path', statusCode: 307 };
543
+ * }
544
+ * ```
545
+ */
546
+ export declare function Redirect(url?: string, statusCode?: number): MethodDecorator;
547
+ /**
548
+ * Decorator that adds caching to a route response.
549
+ *
550
+ * @param ttlSeconds - Time to live in seconds for the cache
551
+ * @returns Method decorator
552
+ *
553
+ * @example
554
+ * ```ts
555
+ * @Get('/data')
556
+ * @Cache(300) // Cache for 5 minutes
557
+ * getData() {
558
+ * return { data: 'expensive operation result' };
559
+ * }
560
+ * ```
561
+ */
562
+ export declare function Cache(ttlSeconds: number): MethodDecorator & ClassDecorator;
563
+ /**
564
+ * Decorator that applies rate limiting to a route.
565
+ * Note: Requires 'express-rate-limit' package to be installed.
566
+ *
567
+ * @param limit - Maximum number of requests allowed in the window
568
+ * @param windowMs - Time window in milliseconds
569
+ * @returns Method decorator
570
+ *
571
+ * Default Options:
572
+ * - standardHeaders: true
573
+ * - legacyHeaders: false
574
+ *
575
+ * @example
576
+ * ```ts
577
+ * @Post('/login')
578
+ * @RateLimit({ max: 5, windowMs: 60000, standardHeaders: true, legacyHeaders: false }) // 5 requests per minute
579
+ * login(@Body() credentials: LoginDto) {
580
+ * return this.authService.login(credentials);
581
+ * }
582
+ * ```
583
+ */
584
+ export declare function RateLimit(options: {
585
+ max: number;
586
+ windowMs: number;
587
+ standardHeaders?: boolean;
588
+ legacyHeaders?: boolean;
589
+ }): MethodDecorator & ClassDecorator;
590
+ /**
591
+ * Decorator that sets the content type for the response.
592
+ *
593
+ * @param type - MIME type for the response
594
+ * @returns Method decorator or Class decorator
595
+ *
596
+ * @example
597
+ * ```ts
598
+ * @Get('/download')
599
+ * @ContentType('application/pdf')
600
+ * downloadPdf() {
601
+ * return this.fileService.generatePdf();
602
+ * }
603
+ *
604
+ * @Controller('/api/json')
605
+ * @ContentType('application/json')
606
+ * class JsonApiController {
607
+ * // All routes in this controller use this content type
608
+ * }
609
+ * ```
610
+ */
611
+ export declare function ContentType(type: string): MethodDecorator & ClassDecorator;
612
+ /**
613
+ * Decorator that adds API versioning to a route.
614
+ *
615
+ * @param version - Version string for the API endpoint
616
+ * @param options - Versioning options
617
+ * @returns Method decorator
618
+ *
619
+ * Default Options:
620
+ * - addPrefix: true
621
+ * - addHeader: true
622
+ * - headerName: 'X-API-Version'
623
+ *
624
+ * @example
625
+ * ```ts
626
+ *
627
+ * @Get('/users')
628
+ * @Version('v2')
629
+ * getUsersV2() {
630
+ * return this.userService.findAllV2();
631
+ * }
632
+ *
633
+ * @Get('/users')
634
+ * @Version('v2', { addPrefix: true, addHeader: true, headerName: 'X-API-Version' })
635
+ * getUsersV2() {
636
+ * // Route becomes /v2/users
637
+ * return this.userService.findAllV2();
638
+ * }
639
+ * ```
640
+ */
641
+ export declare function Version(version: string, options?: {
642
+ addPrefix?: boolean;
643
+ addHeader?: boolean;
644
+ headerName?: string;
645
+ }): MethodDecorator & ClassDecorator;
646
+ /**
647
+ * Decorator that sets a timeout for route execution.
648
+ *
649
+ * @param ms - Timeout in milliseconds
650
+ * @returns Method decorator
651
+ *
652
+ * @example
653
+ * ```ts
654
+ * @Get('/slow-operation')
655
+ * @Timeout(30000) // 30 second timeout
656
+ * slowOperation() {
657
+ * return this.heavyService.processData();
658
+ * }
659
+ * ```
660
+ */
661
+ export declare function Timeout(ms: number): MethodDecorator & ClassDecorator;
662
+ /**
663
+ * Decorator that adds comprehensive logging to a route.
664
+ *
665
+ * @param options - Logging configuration options
666
+ * @returns Method decorator
667
+ *
668
+ * Default Options:
669
+ * - logEntry: true
670
+ * - logExit: true
671
+ * - logBody: false
672
+ * - logParams: false
673
+ * - logResponse: false
674
+ *
675
+ * @example
676
+ * ```ts
677
+ * @Post('/users')
678
+ * @Log({
679
+ * logEntry: true,
680
+ * logExit: true,
681
+ * logBody: true,
682
+ * logParams: true,
683
+ * logResponse: false
684
+ * })
685
+ * createUser(@Body() userData: any) {
686
+ * return this.userService.create(userData);
687
+ * }
688
+ * ```
689
+ */
690
+ export declare function Log(options?: {
691
+ logEntry?: boolean;
692
+ logExit?: boolean;
693
+ logBody?: boolean;
694
+ logParams?: boolean;
695
+ logResponse?: boolean;
696
+ }): MethodDecorator & ClassDecorator;
697
+ /**
698
+ * Registers all controller classes with the provided router.
699
+ * This function processes all decorators and sets up the Express routes.
700
+ *
701
+ * @param router - Express router instance
702
+ * @param controllers - Array of controller classes
703
+ */
704
+ export declare function registerControllers(router: Router, controllers: any[]): void;
705
+ export {};