wynkjs 1.0.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.
- package/LICENSE +21 -0
- package/README.md +522 -0
- package/dist/database.d.ts +36 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +162 -0
- package/dist/decorators/database.decorators.d.ts +55 -0
- package/dist/decorators/database.decorators.d.ts.map +1 -0
- package/dist/decorators/database.decorators.js +131 -0
- package/dist/decorators/exception.advanced.d.ts +160 -0
- package/dist/decorators/exception.advanced.d.ts.map +1 -0
- package/dist/decorators/exception.advanced.js +232 -0
- package/dist/decorators/exception.decorators.d.ts +121 -0
- package/dist/decorators/exception.decorators.d.ts.map +1 -0
- package/dist/decorators/exception.decorators.js +242 -0
- package/dist/decorators/guard.decorators.d.ts +43 -0
- package/dist/decorators/guard.decorators.d.ts.map +1 -0
- package/dist/decorators/guard.decorators.js +67 -0
- package/dist/decorators/http.decorators.d.ts +130 -0
- package/dist/decorators/http.decorators.d.ts.map +1 -0
- package/dist/decorators/http.decorators.js +209 -0
- package/dist/decorators/interceptor.advanced.d.ts +93 -0
- package/dist/decorators/interceptor.advanced.d.ts.map +1 -0
- package/dist/decorators/interceptor.advanced.js +228 -0
- package/dist/decorators/interceptor.decorators.d.ts +91 -0
- package/dist/decorators/interceptor.decorators.d.ts.map +1 -0
- package/dist/decorators/interceptor.decorators.js +163 -0
- package/dist/decorators/param.decorators.d.ts +144 -0
- package/dist/decorators/param.decorators.d.ts.map +1 -0
- package/dist/decorators/param.decorators.js +205 -0
- package/dist/decorators/pipe.advanced.d.ts +125 -0
- package/dist/decorators/pipe.advanced.d.ts.map +1 -0
- package/dist/decorators/pipe.advanced.js +263 -0
- package/dist/decorators/pipe.decorators.d.ts +226 -0
- package/dist/decorators/pipe.decorators.d.ts.map +1 -0
- package/dist/decorators/pipe.decorators.js +420 -0
- package/dist/dto.d.ts +83 -0
- package/dist/dto.d.ts.map +1 -0
- package/dist/dto.js +88 -0
- package/dist/factory.d.ts +76 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +410 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/pipes/validation.pipe.d.ts +91 -0
- package/dist/pipes/validation.pipe.d.ts.map +1 -0
- package/dist/pipes/validation.pipe.js +163 -0
- package/package.json +68 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
/**
|
|
3
|
+
* @UseGuards decorator - Apply guards to routes or controllers
|
|
4
|
+
* @param guards Guard classes to apply
|
|
5
|
+
* @example
|
|
6
|
+
* @Controller('/admin')
|
|
7
|
+
* @UseGuards(AuthGuard, RolesGuard)
|
|
8
|
+
* export class AdminController {}
|
|
9
|
+
*
|
|
10
|
+
* @Get('/profile')
|
|
11
|
+
* @UseGuards(AuthGuard)
|
|
12
|
+
* getProfile() {}
|
|
13
|
+
*/
|
|
14
|
+
export function UseGuards(...guards) {
|
|
15
|
+
return (target, propertyKey, descriptor) => {
|
|
16
|
+
if (propertyKey && descriptor) {
|
|
17
|
+
// Method decorator
|
|
18
|
+
const existingGuards = Reflect.getMetadata("guards", target, propertyKey) || [];
|
|
19
|
+
Reflect.defineMetadata("guards", [...existingGuards, ...guards], target, propertyKey);
|
|
20
|
+
return descriptor;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// Class decorator
|
|
24
|
+
const existingGuards = Reflect.getMetadata("guards", target) || [];
|
|
25
|
+
Reflect.defineMetadata("guards", [...existingGuards, ...guards], target);
|
|
26
|
+
return target;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Helper function to create execution context
|
|
32
|
+
*/
|
|
33
|
+
export function createExecutionContext(ctx, handler, controllerClass) {
|
|
34
|
+
return {
|
|
35
|
+
getRequest: () => ctx.request || ctx,
|
|
36
|
+
getResponse: () => ctx.response || ctx.set,
|
|
37
|
+
getContext: () => ctx,
|
|
38
|
+
getHandler: () => handler,
|
|
39
|
+
getClass: () => controllerClass,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Helper function to execute guards
|
|
44
|
+
*/
|
|
45
|
+
export async function executeGuards(guards, context) {
|
|
46
|
+
for (const guard of guards) {
|
|
47
|
+
let result;
|
|
48
|
+
if (typeof guard === "function") {
|
|
49
|
+
// Guard is a class, instantiate it
|
|
50
|
+
const guardInstance = new guard();
|
|
51
|
+
if (guardInstance.canActivate) {
|
|
52
|
+
result = await guardInstance.canActivate(context);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
throw new Error(`Guard ${guard.name} must implement CanActivate interface`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// Guard is already an instance
|
|
60
|
+
result = await guard.canActivate(context);
|
|
61
|
+
}
|
|
62
|
+
if (!result) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
/**
|
|
3
|
+
* HTTP Method Decorators for ElysiaJS Framework
|
|
4
|
+
* Inspired by NestJS but optimized for Elysia's performance
|
|
5
|
+
*/
|
|
6
|
+
export interface RouteOptions {
|
|
7
|
+
path?: string;
|
|
8
|
+
body?: any;
|
|
9
|
+
params?: any;
|
|
10
|
+
query?: any;
|
|
11
|
+
headers?: any;
|
|
12
|
+
response?: any;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Controller decorator - Defines a controller with a base path
|
|
16
|
+
* @param path Base path for all routes in this controller
|
|
17
|
+
* @example
|
|
18
|
+
* @Controller('/users')
|
|
19
|
+
* export class UserController {}
|
|
20
|
+
*/
|
|
21
|
+
export declare function Controller(path?: string): ClassDecorator;
|
|
22
|
+
/**
|
|
23
|
+
* HTTP GET decorator
|
|
24
|
+
* @param path Route path
|
|
25
|
+
* @param options Route configuration options
|
|
26
|
+
* @example
|
|
27
|
+
* @Get('/profile')
|
|
28
|
+
* async getProfile() {}
|
|
29
|
+
*/
|
|
30
|
+
export declare function Get(path?: string, options?: RouteOptions): MethodDecorator;
|
|
31
|
+
/**
|
|
32
|
+
* @Post decorator - Define a POST route
|
|
33
|
+
* @param pathOrOptions Optional route path or options with DTO
|
|
34
|
+
* @example
|
|
35
|
+
* @Post()
|
|
36
|
+
* create(@Body() data: any) {}
|
|
37
|
+
*
|
|
38
|
+
* @Post('/new')
|
|
39
|
+
* createNew(@Body() data: any) {}
|
|
40
|
+
*
|
|
41
|
+
* @Post({ path: '/users', body: UserDTO })
|
|
42
|
+
* createUser(@Body() data: any) {}
|
|
43
|
+
*/
|
|
44
|
+
export declare function Post(pathOrOptions?: string | RouteOptions): MethodDecorator;
|
|
45
|
+
/**
|
|
46
|
+
* HTTP PUT decorator
|
|
47
|
+
* @param pathOrOptions Route path or options with DTO
|
|
48
|
+
* @example
|
|
49
|
+
* @Put('/:id')
|
|
50
|
+
* async update(@Param('id') id: string, @Body() dto: UpdateDto) {}
|
|
51
|
+
*
|
|
52
|
+
* @Put({ path: '/:id', body: UpdateUserDTO })
|
|
53
|
+
* async update(@Param('id') id: string, @Body() dto: any) {}
|
|
54
|
+
*/
|
|
55
|
+
export declare function Put(pathOrOptions?: string | RouteOptions): MethodDecorator;
|
|
56
|
+
/**
|
|
57
|
+
* HTTP PATCH decorator
|
|
58
|
+
* @param pathOrOptions Route path or options with DTO
|
|
59
|
+
* @example
|
|
60
|
+
* @Patch('/:id')
|
|
61
|
+
* async partialUpdate(@Param('id') id: string, @Body() dto: PartialDto) {}
|
|
62
|
+
*
|
|
63
|
+
* @Patch({ path: '/:id', body: PatchUserDTO })
|
|
64
|
+
* async patch(@Param('id') id: string, @Body() dto: any) {}
|
|
65
|
+
*/
|
|
66
|
+
export declare function Patch(pathOrOptions?: string | RouteOptions): MethodDecorator;
|
|
67
|
+
/**
|
|
68
|
+
* HTTP DELETE decorator
|
|
69
|
+
* @param path Route path
|
|
70
|
+
* @param options Route configuration options
|
|
71
|
+
* @example
|
|
72
|
+
* @Delete('/:id')
|
|
73
|
+
* async remove(@Param('id') id: string) {}
|
|
74
|
+
*/
|
|
75
|
+
export declare function Delete(path?: string, options?: RouteOptions): MethodDecorator;
|
|
76
|
+
/**
|
|
77
|
+
* HTTP OPTIONS decorator
|
|
78
|
+
* @param path Route path
|
|
79
|
+
* @param options Route configuration options
|
|
80
|
+
*/
|
|
81
|
+
export declare function Options(path?: string, options?: RouteOptions): MethodDecorator;
|
|
82
|
+
/**
|
|
83
|
+
* HTTP HEAD decorator
|
|
84
|
+
* @param path Route path
|
|
85
|
+
* @param options Route configuration options
|
|
86
|
+
*/
|
|
87
|
+
export declare function Head(path?: string, options?: RouteOptions): MethodDecorator;
|
|
88
|
+
/**
|
|
89
|
+
* Set custom HTTP status code for a route
|
|
90
|
+
* @param code HTTP status code
|
|
91
|
+
* @example
|
|
92
|
+
* @Post()
|
|
93
|
+
* @HttpCode(201)
|
|
94
|
+
* async create() {}
|
|
95
|
+
*/
|
|
96
|
+
export declare function HttpCode(code: number): MethodDecorator;
|
|
97
|
+
/**
|
|
98
|
+
* Set custom headers for a route response
|
|
99
|
+
* @param headers Headers object
|
|
100
|
+
* @example
|
|
101
|
+
* @Get()
|
|
102
|
+
* @Header('Cache-Control', 'max-age=3600')
|
|
103
|
+
* async getData() {}
|
|
104
|
+
*/
|
|
105
|
+
export declare function Header(name: string, value: string): MethodDecorator;
|
|
106
|
+
/**
|
|
107
|
+
* Redirect to a URL
|
|
108
|
+
* @param url URL to redirect to
|
|
109
|
+
* @param statusCode Redirect status code (default: 302)
|
|
110
|
+
* @example
|
|
111
|
+
* @Get('/old-url')
|
|
112
|
+
* @Redirect('/new-url', 301)
|
|
113
|
+
* redirect() {}
|
|
114
|
+
*/
|
|
115
|
+
export declare function Redirect(url: string, statusCode?: number): MethodDecorator;
|
|
116
|
+
/**
|
|
117
|
+
* Use decorator - Apply middleware to controller or method
|
|
118
|
+
* Simple middleware pattern like your working code
|
|
119
|
+
* @param middlewares Middleware functions to apply
|
|
120
|
+
* @example
|
|
121
|
+
* @Controller('/users')
|
|
122
|
+
* @Use(authMiddleware, loggingMiddleware)
|
|
123
|
+
* export class UserController {}
|
|
124
|
+
*
|
|
125
|
+
* @Get('/')
|
|
126
|
+
* @Use(cacheMiddleware)
|
|
127
|
+
* async findAll() {}
|
|
128
|
+
*/
|
|
129
|
+
export declare function Use(...middlewares: any[]): ClassDecorator & MethodDecorator;
|
|
130
|
+
//# sourceMappingURL=http.decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.decorators.d.ts","sourceRoot":"","sources":["../../core/decorators/http.decorators.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B;;;GAGG;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,GAAE,MAAW,GAAG,cAAc,CAK5D;AAED;;;;;;;GAOG;AACH,wBAAgB,GAAG,CACjB,IAAI,GAAE,MAAW,EACjB,OAAO,CAAC,EAAE,YAAY,GACrB,eAAe,CAEjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,IAAI,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,eAAe,CAM3E;AAED;;;;;;;;;GASG;AACH,wBAAgB,GAAG,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,eAAe,CAM1E;AAED;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,eAAe,CAM5E;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CACpB,IAAI,GAAE,MAAW,EACjB,OAAO,CAAC,EAAE,YAAY,GACrB,eAAe,CAEjB;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CACrB,IAAI,GAAE,MAAW,EACjB,OAAO,CAAC,EAAE,YAAY,GACrB,eAAe,CAEjB;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAClB,IAAI,GAAE,MAAW,EACjB,OAAO,CAAC,EAAE,YAAY,GACrB,eAAe,CAEjB;AAiDD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAStD;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,eAAe,CAYnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CACtB,GAAG,EAAE,MAAM,EACX,UAAU,GAAE,MAAY,GACvB,eAAe,CAcjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CAAC,GAAG,WAAW,EAAE,GAAG,EAAE,GAAG,cAAc,GAAG,eAAe,CAuB3E"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
/**
|
|
3
|
+
* Controller decorator - Defines a controller with a base path
|
|
4
|
+
* @param path Base path for all routes in this controller
|
|
5
|
+
* @example
|
|
6
|
+
* @Controller('/users')
|
|
7
|
+
* export class UserController {}
|
|
8
|
+
*/
|
|
9
|
+
export function Controller(path = "") {
|
|
10
|
+
return (target) => {
|
|
11
|
+
Reflect.defineMetadata("basePath", path, target);
|
|
12
|
+
Reflect.defineMetadata("routes", [], target);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* HTTP GET decorator
|
|
17
|
+
* @param path Route path
|
|
18
|
+
* @param options Route configuration options
|
|
19
|
+
* @example
|
|
20
|
+
* @Get('/profile')
|
|
21
|
+
* async getProfile() {}
|
|
22
|
+
*/
|
|
23
|
+
export function Get(path = "", options) {
|
|
24
|
+
return createRouteDecorator("GET", path, options);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @Post decorator - Define a POST route
|
|
28
|
+
* @param pathOrOptions Optional route path or options with DTO
|
|
29
|
+
* @example
|
|
30
|
+
* @Post()
|
|
31
|
+
* create(@Body() data: any) {}
|
|
32
|
+
*
|
|
33
|
+
* @Post('/new')
|
|
34
|
+
* createNew(@Body() data: any) {}
|
|
35
|
+
*
|
|
36
|
+
* @Post({ path: '/users', body: UserDTO })
|
|
37
|
+
* createUser(@Body() data: any) {}
|
|
38
|
+
*/
|
|
39
|
+
export function Post(pathOrOptions) {
|
|
40
|
+
if (typeof pathOrOptions === "string") {
|
|
41
|
+
return createRouteDecorator("POST", pathOrOptions);
|
|
42
|
+
}
|
|
43
|
+
const options = pathOrOptions || {};
|
|
44
|
+
return createRouteDecorator("POST", options.path || "", options);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* HTTP PUT decorator
|
|
48
|
+
* @param pathOrOptions Route path or options with DTO
|
|
49
|
+
* @example
|
|
50
|
+
* @Put('/:id')
|
|
51
|
+
* async update(@Param('id') id: string, @Body() dto: UpdateDto) {}
|
|
52
|
+
*
|
|
53
|
+
* @Put({ path: '/:id', body: UpdateUserDTO })
|
|
54
|
+
* async update(@Param('id') id: string, @Body() dto: any) {}
|
|
55
|
+
*/
|
|
56
|
+
export function Put(pathOrOptions) {
|
|
57
|
+
if (typeof pathOrOptions === "string") {
|
|
58
|
+
return createRouteDecorator("PUT", pathOrOptions);
|
|
59
|
+
}
|
|
60
|
+
const options = pathOrOptions || {};
|
|
61
|
+
return createRouteDecorator("PUT", options.path || "", options);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* HTTP PATCH decorator
|
|
65
|
+
* @param pathOrOptions Route path or options with DTO
|
|
66
|
+
* @example
|
|
67
|
+
* @Patch('/:id')
|
|
68
|
+
* async partialUpdate(@Param('id') id: string, @Body() dto: PartialDto) {}
|
|
69
|
+
*
|
|
70
|
+
* @Patch({ path: '/:id', body: PatchUserDTO })
|
|
71
|
+
* async patch(@Param('id') id: string, @Body() dto: any) {}
|
|
72
|
+
*/
|
|
73
|
+
export function Patch(pathOrOptions) {
|
|
74
|
+
if (typeof pathOrOptions === "string") {
|
|
75
|
+
return createRouteDecorator("PATCH", pathOrOptions);
|
|
76
|
+
}
|
|
77
|
+
const options = pathOrOptions || {};
|
|
78
|
+
return createRouteDecorator("PATCH", options.path || "", options);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* HTTP DELETE decorator
|
|
82
|
+
* @param path Route path
|
|
83
|
+
* @param options Route configuration options
|
|
84
|
+
* @example
|
|
85
|
+
* @Delete('/:id')
|
|
86
|
+
* async remove(@Param('id') id: string) {}
|
|
87
|
+
*/
|
|
88
|
+
export function Delete(path = "", options) {
|
|
89
|
+
return createRouteDecorator("DELETE", path, options);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* HTTP OPTIONS decorator
|
|
93
|
+
* @param path Route path
|
|
94
|
+
* @param options Route configuration options
|
|
95
|
+
*/
|
|
96
|
+
export function Options(path = "", options) {
|
|
97
|
+
return createRouteDecorator("OPTIONS", path, options);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* HTTP HEAD decorator
|
|
101
|
+
* @param path Route path
|
|
102
|
+
* @param options Route configuration options
|
|
103
|
+
*/
|
|
104
|
+
export function Head(path = "", options) {
|
|
105
|
+
return createRouteDecorator("HEAD", path, options);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Helper function to create route decorators
|
|
109
|
+
*/
|
|
110
|
+
function createRouteDecorator(method, path, options) {
|
|
111
|
+
return (target, propertyKey, descriptor) => {
|
|
112
|
+
// Store route metadata on the prototype
|
|
113
|
+
const constructor = target.constructor;
|
|
114
|
+
const routes = Reflect.getMetadata("routes", constructor.prototype) || [];
|
|
115
|
+
routes.push({
|
|
116
|
+
method,
|
|
117
|
+
path,
|
|
118
|
+
methodName: propertyKey,
|
|
119
|
+
options,
|
|
120
|
+
});
|
|
121
|
+
console.log(`🔹 Storing route: ${method} ${path} on ${constructor.name}.${String(propertyKey)} (routes: ${routes.length})`);
|
|
122
|
+
Reflect.defineMetadata("routes", routes, constructor.prototype);
|
|
123
|
+
// Also store on constructor for compatibility
|
|
124
|
+
Reflect.defineMetadata("routes", routes, constructor);
|
|
125
|
+
// Verify it was stored
|
|
126
|
+
const verify = Reflect.getMetadata("routes", constructor.prototype) || [];
|
|
127
|
+
console.log(`✅ Verified ${verify.length} routes stored on ${constructor.name}.prototype`);
|
|
128
|
+
// Store method-specific metadata
|
|
129
|
+
Reflect.defineMetadata("route:method", method, target, propertyKey);
|
|
130
|
+
Reflect.defineMetadata("route:path", path, target, propertyKey);
|
|
131
|
+
if (options) {
|
|
132
|
+
Reflect.defineMetadata("route:options", options, target, propertyKey);
|
|
133
|
+
}
|
|
134
|
+
return descriptor;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Set custom HTTP status code for a route
|
|
139
|
+
* @param code HTTP status code
|
|
140
|
+
* @example
|
|
141
|
+
* @Post()
|
|
142
|
+
* @HttpCode(201)
|
|
143
|
+
* async create() {}
|
|
144
|
+
*/
|
|
145
|
+
export function HttpCode(code) {
|
|
146
|
+
return (target, propertyKey, descriptor) => {
|
|
147
|
+
Reflect.defineMetadata("route:httpCode", code, target, propertyKey);
|
|
148
|
+
return descriptor;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Set custom headers for a route response
|
|
153
|
+
* @param headers Headers object
|
|
154
|
+
* @example
|
|
155
|
+
* @Get()
|
|
156
|
+
* @Header('Cache-Control', 'max-age=3600')
|
|
157
|
+
* async getData() {}
|
|
158
|
+
*/
|
|
159
|
+
export function Header(name, value) {
|
|
160
|
+
return (target, propertyKey, descriptor) => {
|
|
161
|
+
const headers = Reflect.getMetadata("route:headers", target, propertyKey) || {};
|
|
162
|
+
headers[name] = value;
|
|
163
|
+
Reflect.defineMetadata("route:headers", headers, target, propertyKey);
|
|
164
|
+
return descriptor;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Redirect to a URL
|
|
169
|
+
* @param url URL to redirect to
|
|
170
|
+
* @param statusCode Redirect status code (default: 302)
|
|
171
|
+
* @example
|
|
172
|
+
* @Get('/old-url')
|
|
173
|
+
* @Redirect('/new-url', 301)
|
|
174
|
+
* redirect() {}
|
|
175
|
+
*/
|
|
176
|
+
export function Redirect(url, statusCode = 302) {
|
|
177
|
+
return (target, propertyKey, descriptor) => {
|
|
178
|
+
Reflect.defineMetadata("route:redirect", { url, statusCode }, target, propertyKey);
|
|
179
|
+
return descriptor;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Use decorator - Apply middleware to controller or method
|
|
184
|
+
* Simple middleware pattern like your working code
|
|
185
|
+
* @param middlewares Middleware functions to apply
|
|
186
|
+
* @example
|
|
187
|
+
* @Controller('/users')
|
|
188
|
+
* @Use(authMiddleware, loggingMiddleware)
|
|
189
|
+
* export class UserController {}
|
|
190
|
+
*
|
|
191
|
+
* @Get('/')
|
|
192
|
+
* @Use(cacheMiddleware)
|
|
193
|
+
* async findAll() {}
|
|
194
|
+
*/
|
|
195
|
+
export function Use(...middlewares) {
|
|
196
|
+
return (target, propertyKey, descriptor) => {
|
|
197
|
+
if (propertyKey) {
|
|
198
|
+
// Method decorator
|
|
199
|
+
const existingUses = Reflect.getMetadata("uses", target, propertyKey) || [];
|
|
200
|
+
Reflect.defineMetadata("uses", [...existingUses, ...middlewares], target, propertyKey);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
// Class decorator
|
|
204
|
+
const existingUses = Reflect.getMetadata("uses", target) || [];
|
|
205
|
+
Reflect.defineMetadata("uses", [...existingUses, ...middlewares], target);
|
|
206
|
+
}
|
|
207
|
+
return descriptor;
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { WynkInterceptor, CallHandler } from "./interceptor.decorators";
|
|
3
|
+
import { ExecutionContext } from "./guard.decorators";
|
|
4
|
+
/**
|
|
5
|
+
* Advanced Interceptors for WynkJS Framework
|
|
6
|
+
* Additional interceptors for common use cases
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Response Interceptor - Wraps all responses in a standard format
|
|
10
|
+
* @example
|
|
11
|
+
* @UseInterceptors(ResponseInterceptor)
|
|
12
|
+
* @Controller('/api')
|
|
13
|
+
* export class ApiController {}
|
|
14
|
+
*/
|
|
15
|
+
export declare class ResponseInterceptor implements WynkInterceptor {
|
|
16
|
+
intercept(context: ExecutionContext, next: CallHandler): Promise<any>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Error Handling Interceptor - Catches and transforms errors
|
|
20
|
+
* @example
|
|
21
|
+
* @UseInterceptors(ErrorHandlingInterceptor)
|
|
22
|
+
* @Get()
|
|
23
|
+
* async getData() {}
|
|
24
|
+
*/
|
|
25
|
+
export declare class ErrorHandlingInterceptor implements WynkInterceptor {
|
|
26
|
+
intercept(context: ExecutionContext, next: CallHandler): Promise<any>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Compression Interceptor - Simulates response compression metadata
|
|
30
|
+
* @example
|
|
31
|
+
* @UseInterceptors(CompressionInterceptor)
|
|
32
|
+
* @Get()
|
|
33
|
+
* async getLargeData() {}
|
|
34
|
+
*/
|
|
35
|
+
export declare class CompressionInterceptor implements WynkInterceptor {
|
|
36
|
+
private threshold;
|
|
37
|
+
constructor(threshold?: number);
|
|
38
|
+
intercept(context: ExecutionContext, next: CallHandler): Promise<any>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Rate Limit Interceptor - Basic rate limiting
|
|
42
|
+
* @example
|
|
43
|
+
* @UseInterceptors(new RateLimitInterceptor(100, 60000))
|
|
44
|
+
* @Post()
|
|
45
|
+
* async create() {}
|
|
46
|
+
*/
|
|
47
|
+
export declare class RateLimitInterceptor implements WynkInterceptor {
|
|
48
|
+
private maxRequests;
|
|
49
|
+
private windowMs;
|
|
50
|
+
private requests;
|
|
51
|
+
constructor(maxRequests?: number, windowMs?: number);
|
|
52
|
+
intercept(context: ExecutionContext, next: CallHandler): Promise<any>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* CORS Interceptor - Add CORS headers to responses
|
|
56
|
+
* @example
|
|
57
|
+
* @UseInterceptors(CorsInterceptor)
|
|
58
|
+
* @Controller('/api')
|
|
59
|
+
* export class ApiController {}
|
|
60
|
+
*/
|
|
61
|
+
export declare class CorsInterceptor implements WynkInterceptor {
|
|
62
|
+
private options;
|
|
63
|
+
constructor(options?: {
|
|
64
|
+
origin?: string | string[];
|
|
65
|
+
methods?: string[];
|
|
66
|
+
credentials?: boolean;
|
|
67
|
+
});
|
|
68
|
+
intercept(context: ExecutionContext, next: CallHandler): Promise<any>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Sanitize Interceptor - Sanitizes response data
|
|
72
|
+
* @example
|
|
73
|
+
* @UseInterceptors(SanitizeInterceptor)
|
|
74
|
+
* @Get('/users')
|
|
75
|
+
* async getUsers() {}
|
|
76
|
+
*/
|
|
77
|
+
export declare class SanitizeInterceptor implements WynkInterceptor {
|
|
78
|
+
private fieldsToRemove;
|
|
79
|
+
constructor(fieldsToRemove?: string[]);
|
|
80
|
+
intercept(context: ExecutionContext, next: CallHandler): Promise<any>;
|
|
81
|
+
private sanitize;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Pagination Interceptor - Adds pagination metadata
|
|
85
|
+
* @example
|
|
86
|
+
* @UseInterceptors(PaginationInterceptor)
|
|
87
|
+
* @Get('/users')
|
|
88
|
+
* async getUsers(@Query('page') page: number, @Query('limit') limit: number) {}
|
|
89
|
+
*/
|
|
90
|
+
export declare class PaginationInterceptor implements WynkInterceptor {
|
|
91
|
+
intercept(context: ExecutionContext, next: CallHandler): Promise<any>;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=interceptor.advanced.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptor.advanced.d.ts","sourceRoot":"","sources":["../../core/decorators/interceptor.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;;GAGG;AAEH;;;;;;GAMG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IACnD,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;CAsC5E;AAED;;;;;;GAMG;AACH,qBAAa,wBAAyB,YAAW,eAAe;IACxD,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;CAkB5E;AAED;;;;;;GAMG;AACH,qBAAa,sBAAuB,YAAW,eAAe;IAChD,OAAO,CAAC,SAAS;gBAAT,SAAS,GAAE,MAAa;IAEtC,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;CAa5E;AAED;;;;;;GAMG;AACH,qBAAa,oBAAqB,YAAW,eAAe;IAIxD,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,QAAQ;IAJlB,OAAO,CAAC,QAAQ,CAAoC;gBAG1C,WAAW,GAAE,MAAY,EACzB,QAAQ,GAAE,MAAc;IAG5B,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;CA0B5E;AAED;;;;;;GAMG;AACH,qBAAa,eAAgB,YAAW,eAAe;IAEnD,OAAO,CAAC,OAAO;gBAAP,OAAO,GAAE;QACf,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAC3B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,WAAW,CAAC,EAAE,OAAO,CAAC;KAClB;IAGF,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;CA8B5E;AAED;;;;;;GAMG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IACzD,OAAO,CAAC,cAAc,CAAW;gBAErB,cAAc,GAAE,MAAM,EAAoC;IAIhE,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAK3E,OAAO,CAAC,QAAQ;CAmBjB;AAED;;;;;;GAMG;AACH,qBAAa,qBAAsB,YAAW,eAAe;IACrD,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;CA2B5E"}
|