@catbee/utils 2.0.0-next.0 → 2.0.0-next.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.
- package/README.md +52 -16
- package/array/index.cjs +180 -71
- package/array/index.d.ts +293 -1
- package/array/index.mjs +171 -72
- package/async/index.cjs +92 -36
- package/async/index.d.ts +275 -1
- package/async/index.mjs +92 -36
- package/cache/index.cjs +1 -1
- package/cache/index.d.ts +155 -1
- package/cache/index.mjs +2 -2
- package/config/index.cjs +78 -64
- package/config/index.d.ts +64 -2
- package/config/index.mjs +76 -64
- package/context-store/index.d.ts +192 -1
- package/crypto/index.d.ts +163 -1
- package/date/index.cjs +46 -1
- package/date/index.d.ts +190 -1
- package/date/index.mjs +45 -2
- package/decorators/index.cjs +1156 -18
- package/decorators/index.d.ts +684 -1
- package/decorators/index.mjs +1156 -18
- package/dir/index.cjs +4 -3
- package/dir/index.d.ts +195 -1
- package/dir/index.mjs +4 -3
- package/env/index.cjs +10 -26
- package/env/index.d.ts +379 -1
- package/env/index.mjs +10 -26
- package/exception/index.d.ts +232 -1
- package/fs/index.cjs +70 -36
- package/fs/index.d.ts +205 -1
- package/fs/index.mjs +64 -34
- package/http-status-codes/index.d.ts +267 -1
- package/id/index.d.ts +37 -1
- package/index.cjs +3 -3
- package/index.d.ts +1 -1
- package/index.mjs +1 -1
- package/logger/index.cjs +11 -11
- package/logger/index.d.ts +189 -1
- package/logger/index.mjs +12 -12
- package/middleware/index.d.ts +103 -1
- package/obj/index.cjs +150 -162
- package/obj/index.d.ts +136 -1
- package/obj/index.mjs +150 -162
- package/package.json +11 -11
- package/performance/index.cjs +2 -2
- package/performance/index.d.ts +138 -1
- package/performance/index.mjs +2 -2
- package/request/index.cjs +1 -1
- package/request/index.d.ts +241 -2
- package/request/index.mjs +1 -1
- package/response/index.d.ts +318 -2
- package/server/index.cjs +27 -23
- package/server/index.d.ts +785 -4
- package/server/index.mjs +28 -23
- package/stream/index.d.ts +90 -1
- package/string/index.d.ts +102 -1
- package/type/index.cjs +1 -1
- package/type/index.d.ts +107 -1
- package/type/index.mjs +1 -1
- package/types/index.d.ts +774 -4
- package/url/index.cjs +2 -4
- package/url/index.d.ts +142 -1
- package/url/index.mjs +2 -4
- package/{validate → validation}/index.cjs +89 -42
- package/{validate/validate.utils.d.ts → validation/index.d.ts} +32 -23
- package/{validate → validation}/index.mjs +85 -42
- package/array/array.utils.d.ts +0 -191
- package/async/async.utils.d.ts +0 -296
- package/cache/cache.utils.d.ts +0 -176
- package/config/config.d.ts +0 -57
- package/context-store/context-store.utils.d.ts +0 -212
- package/crypto/crypto.utils.d.ts +0 -183
- package/date/date.utils.d.ts +0 -190
- package/decorators/decorators.utils.d.ts +0 -705
- package/dir/dir.utils.d.ts +0 -216
- package/env/env.utils.d.ts +0 -400
- package/exception/exception.utils.d.ts +0 -253
- package/fs/fs.utils.d.ts +0 -196
- package/http-status-codes/http-status-codes.d.ts +0 -289
- package/id/id.utils.d.ts +0 -59
- package/logger/logger.utils.d.ts +0 -210
- package/middleware/middleware.utils.d.ts +0 -123
- package/obj/obj.utils.d.ts +0 -156
- package/performance/performance.utils.d.ts +0 -159
- package/request/request.utils.d.ts +0 -109
- package/response/response.utils.d.ts +0 -186
- package/server/server.builder.d.ts +0 -531
- package/server/server.d.ts +0 -303
- package/stream/stream.utils.d.ts +0 -111
- package/string/string.utils.d.ts +0 -124
- package/type/type.utils.d.ts +0 -129
- package/types/api-response.d.ts +0 -175
- package/types/common.d.ts +0 -148
- package/types/config.d.ts +0 -88
- package/types/server.d.ts +0 -291
- package/url/url.utils.d.ts +0 -164
- package/validate/index.d.ts +0 -25
|
@@ -1,705 +0,0 @@
|
|
|
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 {};
|