@catbee/utils 0.0.8-rc.3 → 1.0.1

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 (129) hide show
  1. package/README.md +3 -2
  2. package/build/index.cjs +6912 -0
  3. package/build/index.d.ts +5284 -0
  4. package/build/index.mjs +6635 -0
  5. package/package.json +13 -292
  6. package/build/cjs/config.d.ts +0 -121
  7. package/build/cjs/config.js +0 -137
  8. package/build/cjs/index.d.ts +0 -26
  9. package/build/cjs/index.js +0 -68
  10. package/build/cjs/servers/server.builder.d.ts +0 -507
  11. package/build/cjs/servers/server.builder.js +0 -658
  12. package/build/cjs/servers/server.d.ts +0 -255
  13. package/build/cjs/servers/server.js +0 -970
  14. package/build/cjs/types/api-response.d.ts +0 -151
  15. package/build/cjs/types/api-response.js +0 -36
  16. package/build/cjs/types/index.d.ts +0 -124
  17. package/build/cjs/types/index.js +0 -25
  18. package/build/cjs/types/server.d.ts +0 -267
  19. package/build/cjs/types/server.js +0 -25
  20. package/build/cjs/utils/array.utils.d.ts +0 -167
  21. package/build/cjs/utils/array.utils.js +0 -363
  22. package/build/cjs/utils/async.utils.d.ts +0 -264
  23. package/build/cjs/utils/async.utils.js +0 -640
  24. package/build/cjs/utils/cache.utils.d.ts +0 -152
  25. package/build/cjs/utils/cache.utils.js +0 -298
  26. package/build/cjs/utils/context-store.utils.d.ts +0 -188
  27. package/build/cjs/utils/context-store.utils.js +0 -297
  28. package/build/cjs/utils/crypto.utils.d.ts +0 -159
  29. package/build/cjs/utils/crypto.utils.js +0 -295
  30. package/build/cjs/utils/date.utils.d.ts +0 -158
  31. package/build/cjs/utils/date.utils.js +0 -395
  32. package/build/cjs/utils/decorators.utils.d.ts +0 -511
  33. package/build/cjs/utils/decorators.utils.js +0 -1035
  34. package/build/cjs/utils/dir.utils.d.ts +0 -195
  35. package/build/cjs/utils/dir.utils.js +0 -500
  36. package/build/cjs/utils/env.utils.d.ts +0 -376
  37. package/build/cjs/utils/env.utils.js +0 -786
  38. package/build/cjs/utils/exception.utils.d.ts +0 -229
  39. package/build/cjs/utils/exception.utils.js +0 -408
  40. package/build/cjs/utils/fs.utils.d.ts +0 -163
  41. package/build/cjs/utils/fs.utils.js +0 -371
  42. package/build/cjs/utils/http-status-codes.d.ts +0 -265
  43. package/build/cjs/utils/http-status-codes.js +0 -297
  44. package/build/cjs/utils/id.utils.d.ts +0 -35
  45. package/build/cjs/utils/id.utils.js +0 -90
  46. package/build/cjs/utils/logger.utils.d.ts +0 -159
  47. package/build/cjs/utils/logger.utils.js +0 -350
  48. package/build/cjs/utils/middleware.utils.d.ts +0 -99
  49. package/build/cjs/utils/middleware.utils.js +0 -243
  50. package/build/cjs/utils/obj.utils.d.ts +0 -123
  51. package/build/cjs/utils/obj.utils.js +0 -428
  52. package/build/cjs/utils/performance.utils.d.ts +0 -135
  53. package/build/cjs/utils/performance.utils.js +0 -280
  54. package/build/cjs/utils/request.utils.d.ts +0 -85
  55. package/build/cjs/utils/request.utils.js +0 -199
  56. package/build/cjs/utils/response.utils.d.ts +0 -162
  57. package/build/cjs/utils/response.utils.js +0 -274
  58. package/build/cjs/utils/stream.utils.d.ts +0 -87
  59. package/build/cjs/utils/stream.utils.js +0 -217
  60. package/build/cjs/utils/string.utils.d.ts +0 -92
  61. package/build/cjs/utils/string.utils.js +0 -178
  62. package/build/cjs/utils/type.utils.d.ts +0 -89
  63. package/build/cjs/utils/type.utils.js +0 -195
  64. package/build/cjs/utils/url.utils.d.ts +0 -140
  65. package/build/cjs/utils/url.utils.js +0 -316
  66. package/build/cjs/utils/validate.utils.d.ts +0 -176
  67. package/build/cjs/utils/validate.utils.js +0 -344
  68. package/build/esm/config.d.ts +0 -121
  69. package/build/esm/config.js +0 -132
  70. package/build/esm/index.d.ts +0 -26
  71. package/build/esm/index.js +0 -49
  72. package/build/esm/servers/server.builder.d.ts +0 -507
  73. package/build/esm/servers/server.builder.js +0 -654
  74. package/build/esm/servers/server.d.ts +0 -255
  75. package/build/esm/servers/server.js +0 -963
  76. package/build/esm/types/api-response.d.ts +0 -151
  77. package/build/esm/types/api-response.js +0 -33
  78. package/build/esm/types/index.d.ts +0 -124
  79. package/build/esm/types/index.js +0 -24
  80. package/build/esm/types/server.d.ts +0 -267
  81. package/build/esm/types/server.js +0 -24
  82. package/build/esm/utils/array.utils.d.ts +0 -167
  83. package/build/esm/utils/array.utils.js +0 -344
  84. package/build/esm/utils/async.utils.d.ts +0 -264
  85. package/build/esm/utils/async.utils.js +0 -619
  86. package/build/esm/utils/cache.utils.d.ts +0 -152
  87. package/build/esm/utils/cache.utils.js +0 -294
  88. package/build/esm/utils/context-store.utils.d.ts +0 -188
  89. package/build/esm/utils/context-store.utils.js +0 -290
  90. package/build/esm/utils/crypto.utils.d.ts +0 -159
  91. package/build/esm/utils/crypto.utils.js +0 -278
  92. package/build/esm/utils/date.utils.d.ts +0 -158
  93. package/build/esm/utils/date.utils.js +0 -383
  94. package/build/esm/utils/decorators.utils.d.ts +0 -511
  95. package/build/esm/utils/decorators.utils.js +0 -1013
  96. package/build/esm/utils/dir.utils.d.ts +0 -195
  97. package/build/esm/utils/dir.utils.js +0 -476
  98. package/build/esm/utils/env.utils.d.ts +0 -376
  99. package/build/esm/utils/env.utils.js +0 -782
  100. package/build/esm/utils/exception.utils.d.ts +0 -229
  101. package/build/esm/utils/exception.utils.js +0 -382
  102. package/build/esm/utils/fs.utils.d.ts +0 -163
  103. package/build/esm/utils/fs.utils.js +0 -348
  104. package/build/esm/utils/http-status-codes.d.ts +0 -265
  105. package/build/esm/utils/http-status-codes.js +0 -294
  106. package/build/esm/utils/id.utils.d.ts +0 -35
  107. package/build/esm/utils/id.utils.js +0 -83
  108. package/build/esm/utils/logger.utils.d.ts +0 -159
  109. package/build/esm/utils/logger.utils.js +0 -304
  110. package/build/esm/utils/middleware.utils.d.ts +0 -99
  111. package/build/esm/utils/middleware.utils.js +0 -235
  112. package/build/esm/utils/obj.utils.d.ts +0 -123
  113. package/build/esm/utils/obj.utils.js +0 -412
  114. package/build/esm/utils/performance.utils.d.ts +0 -135
  115. package/build/esm/utils/performance.utils.js +0 -273
  116. package/build/esm/utils/request.utils.d.ts +0 -85
  117. package/build/esm/utils/request.utils.js +0 -190
  118. package/build/esm/utils/response.utils.d.ts +0 -162
  119. package/build/esm/utils/response.utils.js +0 -261
  120. package/build/esm/utils/stream.utils.d.ts +0 -87
  121. package/build/esm/utils/stream.utils.js +0 -209
  122. package/build/esm/utils/string.utils.d.ts +0 -92
  123. package/build/esm/utils/string.utils.js +0 -164
  124. package/build/esm/utils/type.utils.d.ts +0 -89
  125. package/build/esm/utils/type.utils.js +0 -186
  126. package/build/esm/utils/url.utils.d.ts +0 -140
  127. package/build/esm/utils/url.utils.js +0 -303
  128. package/build/esm/utils/validate.utils.d.ts +0 -176
  129. package/build/esm/utils/validate.utils.js +0 -319
@@ -1,511 +0,0 @@
1
- import type { RequestHandler, Router } from 'express';
2
- import 'reflect-metadata';
3
- type Constructor<T = any> = new (...args: any[]) => T;
4
- export declare class DIContainer {
5
- private instances;
6
- private constructing;
7
- register<T>(target: Constructor<T>): void;
8
- get<T>(target: Constructor<T>): T;
9
- clear(): void;
10
- }
11
- /**
12
- * Injectable decorator for marking classes as injectable.
13
- *
14
- * @returns Class decorator that marks a class as injectable and registers it with the DI container.
15
- */
16
- export declare function Injectable(): ClassDecorator;
17
- /**
18
- * Inject decorator for injecting dependencies into class properties.
19
- *
20
- * @param targetClass - The class to inject
21
- * @returns Property decorator that injects the specified class into the property
22
- */
23
- export declare function Inject<T>(targetClass: new (...args: any[]) => T): PropertyDecorator;
24
- /**
25
- * Decorator for GET HTTP method routes.
26
- *
27
- * @param path - URL path for the route
28
- * @returns Method decorator
29
- *
30
- * @example
31
- * ```ts
32
- * @Get('/users')
33
- * getUsers() {
34
- * return this.userService.findAll();
35
- * }
36
- * ```
37
- */
38
- export declare const Get: (path: string) => MethodDecorator;
39
- /**
40
- * Decorator for POST HTTP method routes.
41
- *
42
- * @param path - URL path for the route
43
- * @returns Method decorator
44
- *
45
- * @example
46
- * ```ts
47
- * @Post('/users')
48
- * createUser(@Body() userData: any) {
49
- * return this.userService.create(userData);
50
- * }
51
- * ```
52
- */
53
- export declare const Post: (path: string) => MethodDecorator;
54
- /**
55
- * Decorator for PUT HTTP method routes.
56
- *
57
- * @param path - URL path for the route
58
- * @returns Method decorator
59
- */
60
- export declare const Put: (path: string) => MethodDecorator;
61
- /**
62
- * Decorator for PATCH HTTP method routes.
63
- *
64
- * @param path - URL path for the route
65
- * @returns Method decorator
66
- */
67
- export declare const Patch: (path: string) => MethodDecorator;
68
- /**
69
- * Decorator for DELETE HTTP method routes.
70
- *
71
- * @param path - URL path for the route
72
- * @returns Method decorator
73
- */
74
- export declare const Delete: (path: string) => MethodDecorator;
75
- /**
76
- * Decorator for OPTIONS HTTP method routes.
77
- *
78
- * @param path - URL path for the route
79
- * @returns Method decorator
80
- */
81
- export declare const Options: (path: string) => MethodDecorator;
82
- /**
83
- * Decorator for HEAD HTTP method routes.
84
- *
85
- * @param path - URL path for the route
86
- * @returns Method decorator
87
- */
88
- export declare const Head: (path: string) => MethodDecorator;
89
- /**
90
- * Decorator for TRACE HTTP method routes.
91
- *
92
- * @param path - URL path for the route
93
- * @returns Method decorator
94
- */
95
- export declare const Trace: (path: string) => MethodDecorator;
96
- /**
97
- * Decorator for CONNECT HTTP method routes.
98
- *
99
- * @param path - URL path for the route
100
- * @returns Method decorator
101
- */
102
- export declare const Connect: (path: string) => MethodDecorator;
103
- /**
104
- * Decorator that marks a class as a controller with a base path.
105
- * Used as the entry point for routing configuration.
106
- *
107
- * @param basePath - Base URL path for all routes in this controller
108
- * @returns Class decorator
109
- *
110
- * @example
111
- * ```ts
112
- * @Controller('/api/users')
113
- * class UserController {
114
- * // Controller methods...
115
- * }
116
- * ```
117
- */
118
- export declare function Controller(basePath: string): ClassDecorator;
119
- /**
120
- * Decorator that applies middleware to a controller method.
121
- * Multiple middlewares can be applied and will execute in order.
122
- *
123
- * @param middlewares - Express middleware functions to apply
124
- * @returns Method decorator
125
- *
126
- * @example
127
- * ```ts
128
- * @Get('/protected')
129
- * @Use(authMiddleware, loggingMiddleware)
130
- * getProtectedResource() {
131
- * // This route is protected by auth middleware
132
- * }
133
- * ```
134
- */
135
- export declare function Use(...middlewares: RequestHandler[]): MethodDecorator;
136
- /**
137
- * Decorator that extracts query parameters from request.
138
- *
139
- * @param paramKey - Optional key to extract specific query parameter
140
- * @returns Parameter decorator
141
- *
142
- * @example
143
- * ```ts
144
- * @Get('/search')
145
- * search(@Query('term') searchTerm: string) {
146
- * // searchTerm will contain the value of req.query.term
147
- * }
148
- * ```
149
- */
150
- export declare const Query: (paramKey?: string) => ParameterDecorator;
151
- /**
152
- * Decorator that extracts route parameters from request.
153
- *
154
- * @param paramKey - Optional key to extract specific route parameter
155
- * @returns Parameter decorator
156
- *
157
- * @example
158
- * ```ts
159
- * @Get('/users/:id')
160
- * getUser(@Param('id') userId: string) {
161
- * // userId will contain the value of req.params.id
162
- * }
163
- * ```
164
- */
165
- export declare const Param: (paramKey?: string) => ParameterDecorator;
166
- /**
167
- * Decorator that extracts body or body property from request.
168
- *
169
- * @param paramKey - Optional key to extract specific body property
170
- * @returns Parameter decorator
171
- *
172
- * @example
173
- * ```ts
174
- * @Post('/users')
175
- * createUser(@Body() userData: any) {
176
- * // userData will contain the entire req.body
177
- * }
178
- *
179
- * @Post('/update')
180
- * updateName(@Body('name') name: string) {
181
- * // name will contain the value of req.body.name
182
- * }
183
- * ```
184
- */
185
- export declare const Body: (paramKey?: string) => ParameterDecorator;
186
- /**
187
- * Decorator that injects the entire request object.
188
- *
189
- * @returns Parameter decorator
190
- *
191
- * @example
192
- * ```ts
193
- * @Get('/complex')
194
- * complex(@Req() req: Request) {
195
- * // Access the full request object
196
- * console.log(req.headers);
197
- * }
198
- * ```
199
- */
200
- export declare const Req: (paramKey?: string) => ParameterDecorator;
201
- /**
202
- * Decorator that injects the response object.
203
- *
204
- * @returns Parameter decorator
205
- *
206
- * @example
207
- * ```ts
208
- * @Get('/custom')
209
- * custom(@Res() res: Response) {
210
- * // Direct access to response object
211
- * return res.status(201).send('Created');
212
- * }
213
- * ```
214
- */
215
- export declare const Res: (paramKey?: string) => ParameterDecorator;
216
- /**
217
- * Decorator that sets a custom HTTP status code for a response.
218
- *
219
- * @param status - HTTP status code to use
220
- * @returns Method decorator
221
- *
222
- * @example
223
- * ```ts
224
- * @Post('/users')
225
- * @HttpCode(201)
226
- * createUser(@Body() userData: any) {
227
- * // Response will have 201 Created status code
228
- * return { id: '123', ...userData };
229
- * }
230
- * ```
231
- */
232
- export declare function HttpCode(status: number): MethodDecorator;
233
- /**
234
- * Decorator that adds a custom HTTP header to the response.
235
- *
236
- * @param header - Header name-value pairs or a single header name and value
237
- * @param value - Header value if a single header name is provided
238
- * @returns Method decorator
239
- *
240
- * @example
241
- * ```ts
242
- * @Get('/data')
243
- * @Header('Cache-Control', 'max-age=60')
244
- * getData() {
245
- * // Response will include the Cache-Control header
246
- * return { data: '...' };
247
- * }
248
- */
249
- export declare function Header(name: string, value: string): MethodDecorator & ClassDecorator;
250
- /**
251
- * Decorator that adds a custom HTTP headers to the response.
252
- *
253
- * @param headers - Header name-value pairs or a single header name and value
254
- * @param value - Header value if a single header name is provided
255
- * @returns Method decorator
256
- *
257
- * @example
258
- * ```ts
259
- * @Get('/data')
260
- * @Headers('Cache-Control', 'max-age=60')
261
- * getData() {
262
- * // Response will include the Cache-Control header
263
- * return { data: '...' };
264
- * }
265
- *
266
- * @Get('/data/:id')
267
- * @Headers({
268
- * 'Cache-Control': 'max-age=60',
269
- * 'X-Custom-Header': 'custom-value',
270
- * 'Content-Security-Policy': "default-src 'self'"
271
- * })
272
- * getData() {
273
- * // Response will include all specified headers
274
- * return { data: '...' };
275
- * }
276
- *
277
- * ```
278
- */
279
- export declare function Headers(headers: Record<string, string> | string, value?: string): MethodDecorator & ClassDecorator;
280
- /**
281
- * Decorator that registers a function to run before route handler execution.
282
- * Useful for pre-processing or logging.
283
- *
284
- * @param fn - Function to execute before the handler
285
- * @returns Method decorator
286
- *
287
- * @example
288
- * ```ts
289
- * @Get('/users/:id')
290
- * @Before((req, res) => console.log(`Accessing user ${req.params.id}`))
291
- * getUser(@Param('id') id: string) {
292
- * // Function will log before this handler runs
293
- * }
294
- * ```
295
- */
296
- export declare function Before(fn: Function): MethodDecorator;
297
- /**
298
- * Decorator that registers a function to run after route handler execution.
299
- * Can access the handler's result.
300
- *
301
- * @param fn - Function to execute after the handler
302
- * @returns Method decorator
303
- *
304
- * @example
305
- * ```ts
306
- * @Get('/users/:id')
307
- * @After((req, res, result) => console.log(`User data sent: ${JSON.stringify(result)}`))
308
- * getUser(@Param('id') id: string) {
309
- * // After this handler, the function will log the returned data
310
- * return { id, name: 'Example' };
311
- * }
312
- * ```
313
- */
314
- export declare function After(fn: Function): MethodDecorator;
315
- /**
316
- * Decorator that requires specific roles for accessing a route.
317
- * Must be used with authentication middleware.
318
- *
319
- * Check req.user.roles for user roles[].
320
- *
321
- * @param roles - List of roles that can access this route
322
- * @returns Method decorator
323
- *
324
- * @example
325
- * ```ts
326
- * @Get('/admin/settings')
327
- * @Roles('admin', 'superuser')
328
- * getSettings() {
329
- * // Only admins and superusers can access
330
- * return { settings: [...] };
331
- * }
332
- * ```
333
- */
334
- export declare function Roles(...roles: string[]): MethodDecorator & ClassDecorator;
335
- /**
336
- * Decorator that redirects to another URL.
337
- *
338
- * @param url - URL to redirect to (can be absolute or relative)
339
- * @param statusCode - HTTP status code for redirect (default: 302)
340
- * @returns Method decorator
341
- *
342
- * @example
343
- * ```ts
344
- * @Get('/old-path')
345
- * @Redirect('/new-path', 301)
346
- * redirectToNewPath() {
347
- * // This method won't be executed; automatic redirect happens
348
- * }
349
- *
350
- * @Get('/dynamic-redirect')
351
- * @Redirect()
352
- * getDynamicRedirect() {
353
- * // Return an object with url and optionally statusCode
354
- * return { url: '/calculated-path', statusCode: 307 };
355
- * }
356
- * ```
357
- */
358
- export declare function Redirect(url?: string, statusCode?: number): MethodDecorator;
359
- /**
360
- * Decorator that adds caching to a route response.
361
- *
362
- * @param ttlSeconds - Time to live in seconds for the cache
363
- * @returns Method decorator
364
- *
365
- * @example
366
- * ```ts
367
- * @Get('/data')
368
- * @Cache(300) // Cache for 5 minutes
369
- * getData() {
370
- * return { data: 'expensive operation result' };
371
- * }
372
- * ```
373
- */
374
- export declare function Cache(ttlSeconds: number): MethodDecorator & ClassDecorator;
375
- /**
376
- * Decorator that applies rate limiting to a route.
377
- * Note: Requires 'express-rate-limit' package to be installed.
378
- *
379
- * @param limit - Maximum number of requests allowed in the window
380
- * @param windowMs - Time window in milliseconds
381
- * @returns Method decorator
382
- *
383
- * Default Options:
384
- * - standardHeaders: true
385
- * - legacyHeaders: false
386
- *
387
- * @example
388
- * ```ts
389
- * @Post('/login')
390
- * @RateLimit({ max: 5, windowMs: 60000, standardHeaders: true, legacyHeaders: false }) // 5 requests per minute
391
- * login(@Body() credentials: LoginDto) {
392
- * return this.authService.login(credentials);
393
- * }
394
- * ```
395
- */
396
- export declare function RateLimit(options: {
397
- max: number;
398
- windowMs: number;
399
- standardHeaders?: boolean;
400
- legacyHeaders?: boolean;
401
- }): MethodDecorator & ClassDecorator;
402
- /**
403
- * Decorator that sets the content type for the response.
404
- *
405
- * @param type - MIME type for the response
406
- * @returns Method decorator
407
- *
408
- * @example
409
- * ```ts
410
- * @Get('/download')
411
- * @ContentType('application/pdf')
412
- * downloadPdf() {
413
- * return this.fileService.generatePdf();
414
- * }
415
- * ```
416
- */
417
- export declare function ContentType(type: string): MethodDecorator;
418
- /**
419
- * Decorator that adds API versioning to a route.
420
- *
421
- * @param version - Version string for the API endpoint
422
- * @param options - Versioning options
423
- * @returns Method decorator
424
- *
425
- * Default Options:
426
- * - addPrefix: true
427
- * - addHeader: true
428
- * - headerName: 'X-API-Version'
429
- *
430
- * @example
431
- * ```ts
432
- *
433
- * @Get('/users')
434
- * @Version('v2')
435
- * getUsersV2() {
436
- * return this.userService.findAllV2();
437
- * }
438
- *
439
- * @Get('/users')
440
- * @Version('v2', { addPrefix: true, addHeader: true, headerName: 'X-API-Version' })
441
- * getUsersV2() {
442
- * // Route becomes /v2/users
443
- * return this.userService.findAllV2();
444
- * }
445
- * ```
446
- */
447
- export declare function Version(version: string, options?: {
448
- addPrefix?: boolean;
449
- addHeader?: boolean;
450
- headerName?: string;
451
- }): MethodDecorator & ClassDecorator;
452
- /**
453
- * Decorator that sets a timeout for route execution.
454
- *
455
- * @param ms - Timeout in milliseconds
456
- * @returns Method decorator
457
- *
458
- * @example
459
- * ```ts
460
- * @Get('/slow-operation')
461
- * @Timeout(30000) // 30 second timeout
462
- * slowOperation() {
463
- * return this.heavyService.processData();
464
- * }
465
- * ```
466
- */
467
- export declare function Timeout(ms: number): MethodDecorator & ClassDecorator;
468
- /**
469
- * Decorator that adds comprehensive logging to a route.
470
- *
471
- * @param options - Logging configuration options
472
- * @returns Method decorator
473
- *
474
- * Default Options:
475
- * - logEntry: true
476
- * - logExit: true
477
- * - logBody: false
478
- * - logParams: false
479
- * - logResponse: false
480
- *
481
- * @example
482
- * ```ts
483
- * @Post('/users')
484
- * @Log({
485
- * logEntry: true,
486
- * logExit: true,
487
- * logBody: true,
488
- * logParams: true,
489
- * logResponse: false
490
- * })
491
- * createUser(@Body() userData: any) {
492
- * return this.userService.create(userData);
493
- * }
494
- * ```
495
- */
496
- export declare function Log(options?: {
497
- logEntry?: boolean;
498
- logExit?: boolean;
499
- logBody?: boolean;
500
- logParams?: boolean;
501
- logResponse?: boolean;
502
- }): MethodDecorator & ClassDecorator;
503
- /**
504
- * Registers all controller classes with the provided router.
505
- * This function processes all decorators and sets up the Express routes.
506
- *
507
- * @param router - Express router instance
508
- * @param controllers - Array of controller classes
509
- */
510
- export declare function registerControllers(router: Router, controllers: any[]): void;
511
- export {};