@alis-kit/routers 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/README.md +302 -0
- package/dist/adapters/BaseAdapter.d.ts +63 -0
- package/dist/adapters/BaseAdapter.d.ts.map +1 -0
- package/dist/adapters/BaseAdapter.js +17 -0
- package/dist/adapters/BaseAdapter.js.map +1 -0
- package/dist/adapters/ExpressAdapter.d.ts +44 -0
- package/dist/adapters/ExpressAdapter.d.ts.map +1 -0
- package/dist/adapters/ExpressAdapter.js +73 -0
- package/dist/adapters/ExpressAdapter.js.map +1 -0
- package/dist/adapters/FastifyAdapter.d.ts +61 -0
- package/dist/adapters/FastifyAdapter.d.ts.map +1 -0
- package/dist/adapters/FastifyAdapter.js +132 -0
- package/dist/adapters/FastifyAdapter.js.map +1 -0
- package/dist/cookie/CookieSetter.d.ts +74 -0
- package/dist/cookie/CookieSetter.d.ts.map +1 -0
- package/dist/cookie/CookieSetter.js +89 -0
- package/dist/cookie/CookieSetter.js.map +1 -0
- package/dist/core/Logger.d.ts +36 -0
- package/dist/core/Logger.d.ts.map +1 -0
- package/dist/core/Logger.js +53 -0
- package/dist/core/Logger.js.map +1 -0
- package/dist/core/RouteResolver.d.ts +91 -0
- package/dist/core/RouteResolver.d.ts.map +1 -0
- package/dist/core/RouteResolver.js +279 -0
- package/dist/core/RouteResolver.js.map +1 -0
- package/dist/core/RouterKit.d.ts +116 -0
- package/dist/core/RouterKit.d.ts.map +1 -0
- package/dist/core/RouterKit.js +175 -0
- package/dist/core/RouterKit.js.map +1 -0
- package/dist/decorators/controller/ReqController.d.ts +29 -0
- package/dist/decorators/controller/ReqController.d.ts.map +1 -0
- package/dist/decorators/controller/ReqController.js +62 -0
- package/dist/decorators/controller/ReqController.js.map +1 -0
- package/dist/decorators/mapping/index.d.ts +93 -0
- package/dist/decorators/mapping/index.d.ts.map +1 -0
- package/dist/decorators/mapping/index.js +128 -0
- package/dist/decorators/mapping/index.js.map +1 -0
- package/dist/decorators/method/index.d.ts +67 -0
- package/dist/decorators/method/index.d.ts.map +1 -0
- package/dist/decorators/method/index.js +83 -0
- package/dist/decorators/method/index.js.map +1 -0
- package/dist/decorators/parameter/index.d.ts +155 -0
- package/dist/decorators/parameter/index.d.ts.map +1 -0
- package/dist/decorators/parameter/index.js +196 -0
- package/dist/decorators/parameter/index.js.map +1 -0
- package/dist/exceptions/BadRequestException.d.ts +37 -0
- package/dist/exceptions/BadRequestException.d.ts.map +1 -0
- package/dist/exceptions/BadRequestException.js +37 -0
- package/dist/exceptions/BadRequestException.js.map +1 -0
- package/dist/exceptions/BaseException.d.ts +29 -0
- package/dist/exceptions/BaseException.d.ts.map +1 -0
- package/dist/exceptions/BaseException.js +29 -0
- package/dist/exceptions/BaseException.js.map +1 -0
- package/dist/exceptions/ConflictException.d.ts +28 -0
- package/dist/exceptions/ConflictException.d.ts.map +1 -0
- package/dist/exceptions/ConflictException.js +28 -0
- package/dist/exceptions/ConflictException.js.map +1 -0
- package/dist/exceptions/ForbiddenException.d.ts +26 -0
- package/dist/exceptions/ForbiddenException.d.ts.map +1 -0
- package/dist/exceptions/ForbiddenException.js +26 -0
- package/dist/exceptions/ForbiddenException.js.map +1 -0
- package/dist/exceptions/NotFoundException.d.ts +28 -0
- package/dist/exceptions/NotFoundException.d.ts.map +1 -0
- package/dist/exceptions/NotFoundException.js +28 -0
- package/dist/exceptions/NotFoundException.js.map +1 -0
- package/dist/exceptions/ServerErrorException.d.ts +33 -0
- package/dist/exceptions/ServerErrorException.d.ts.map +1 -0
- package/dist/exceptions/ServerErrorException.js +33 -0
- package/dist/exceptions/ServerErrorException.js.map +1 -0
- package/dist/exceptions/UnauthorizedException.d.ts +28 -0
- package/dist/exceptions/UnauthorizedException.d.ts.map +1 -0
- package/dist/exceptions/UnauthorizedException.js +28 -0
- package/dist/exceptions/UnauthorizedException.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/swagger/SwaggerGenerator.d.ts +63 -0
- package/dist/swagger/SwaggerGenerator.d.ts.map +1 -0
- package/dist/swagger/SwaggerGenerator.js +266 -0
- package/dist/swagger/SwaggerGenerator.js.map +1 -0
- package/dist/swagger/SwaggerUI.d.ts +30 -0
- package/dist/swagger/SwaggerUI.d.ts.map +1 -0
- package/dist/swagger/SwaggerUI.js +52 -0
- package/dist/swagger/SwaggerUI.js.map +1 -0
- package/dist/types/index.d.ts +255 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +31 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { META } from "../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Marks a class as a route controller with a base path and optional configuration.
|
|
4
|
+
*
|
|
5
|
+
* Menyimpan metadata controller ke `context.metadata` via TC39 native decorator.
|
|
6
|
+
* Semua route dalam class ini akan mewarisi `authentication` dan `tag` dari sini.
|
|
7
|
+
*
|
|
8
|
+
* @param basePath - Base URL path untuk semua route di controller ini.
|
|
9
|
+
* Akan otomatis diprefiks dengan "/" jika tidak ada.
|
|
10
|
+
* @param options - Opsi tambahan untuk controller.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* @ReqController("/users", { authentication: "auth", tag: "User Management" })
|
|
15
|
+
* class UserController {
|
|
16
|
+
* // semua route inheritance authentication: "auth"
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* @ReqController("/public")
|
|
23
|
+
* class PublicController {
|
|
24
|
+
* // authentication: false (default)
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function ReqController(basePath, options) {
|
|
29
|
+
return function (_value, context) {
|
|
30
|
+
const tag = options?.tag ?? deriveTagFromClassName(_value.name);
|
|
31
|
+
const metadata = {
|
|
32
|
+
basePath: normalizePath(basePath),
|
|
33
|
+
authentication: options?.authentication ?? false,
|
|
34
|
+
tag,
|
|
35
|
+
swagger: options?.swagger !== false,
|
|
36
|
+
};
|
|
37
|
+
if (!context.metadata)
|
|
38
|
+
return;
|
|
39
|
+
context.metadata[META.CONTROLLER] = metadata;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Derives a human-readable Swagger tag from a PascalCase class name.
|
|
44
|
+
* Contoh: "UserController" → "User", "AuthTokenController" → "Auth Token"
|
|
45
|
+
*/
|
|
46
|
+
function deriveTagFromClassName(name) {
|
|
47
|
+
const withoutSuffix = name.replace(/Controller$/i, "");
|
|
48
|
+
return withoutSuffix.replace(/([a-z])([A-Z])/g, "$1 $2").trim() || name;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Normalizes a path: ensures leading "/" and removes trailing "/".
|
|
52
|
+
*/
|
|
53
|
+
function normalizePath(path) {
|
|
54
|
+
if (!path.startsWith("/")) {
|
|
55
|
+
path = "/" + path;
|
|
56
|
+
}
|
|
57
|
+
if (path.length > 1 && path.endsWith("/")) {
|
|
58
|
+
path = path.slice(0, -1);
|
|
59
|
+
}
|
|
60
|
+
return path;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=ReqController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReqController.js","sourceRoot":"","sources":["../../../decorators/controller/ReqController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,OAA2B;IACzE,OAAO,UAAU,MAAgB,EAAE,OAA8B;QAC/D,MAAM,GAAG,GAAG,OAAO,EAAE,GAAG,IAAI,sBAAsB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEhE,MAAM,QAAQ,GAAuB;YACnC,QAAQ,EAAE,aAAa,CAAC,QAAQ,CAAC;YACjC,cAAc,EAAE,OAAO,EAAE,cAAc,IAAI,KAAK;YAChD,GAAG;YACH,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,KAAK;SACpC,CAAC;QAEF,IAAI,CAAC,OAAO,CAAC,QAAQ;YAAE,OAAO;QAC9B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC;IAC/C,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,sBAAsB,CAAC,IAAY;IAC1C,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;IACvD,OAAO,aAAa,CAAC,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC;AAC1E,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;IACpB,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1C,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { MappingOptions } from "../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Maps a controller method to handle HTTP GET requests.
|
|
4
|
+
*
|
|
5
|
+
* @param path - Route path relatif terhadap basePath controller
|
|
6
|
+
* @param options - Opsi mapping (summary, auth override, swagger, dll)
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* @ReqController("/users")
|
|
11
|
+
* class UserController {
|
|
12
|
+
* @GetMapping("/", { summary: "Get all users" })
|
|
13
|
+
* async getAll(@Query(PaginationSchema) query: IPagination) {
|
|
14
|
+
* // ...
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const GetMapping: (path: string, options?: MappingOptions) => (_value: Function, context: ClassMethodDecoratorContext) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Maps a controller method to handle HTTP POST requests.
|
|
22
|
+
*
|
|
23
|
+
* @param path - Route path relatif terhadap basePath controller
|
|
24
|
+
* @param options - Opsi mapping
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* @ReqController("/users")
|
|
29
|
+
* class UserController {
|
|
30
|
+
* @PostMapping("/", { summary: "Create a user" })
|
|
31
|
+
* @HttpStatus(201)
|
|
32
|
+
* async create(@Body(CreateUserSchema) body: ICreateUser) {
|
|
33
|
+
* // ...
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const PostMapping: (path: string, options?: MappingOptions) => (_value: Function, context: ClassMethodDecoratorContext) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Maps a controller method to handle HTTP PUT requests.
|
|
41
|
+
*
|
|
42
|
+
* @param path - Route path relatif terhadap basePath controller
|
|
43
|
+
* @param options - Opsi mapping
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* @ReqController("/users")
|
|
48
|
+
* class UserController {
|
|
49
|
+
* @PutMapping("/:id", { summary: "Update a user" })
|
|
50
|
+
* async update(@Param("id") id: string, @Body(UpdateSchema) body: IUpdate) {
|
|
51
|
+
* // ...
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare const PutMapping: (path: string, options?: MappingOptions) => (_value: Function, context: ClassMethodDecoratorContext) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Maps a controller method to handle HTTP PATCH requests.
|
|
59
|
+
*
|
|
60
|
+
* @param path - Route path relatif terhadap basePath controller
|
|
61
|
+
* @param options - Opsi mapping
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* @ReqController("/users")
|
|
66
|
+
* class UserController {
|
|
67
|
+
* @PatchMapping("/:id/status", { summary: "Update user status" })
|
|
68
|
+
* async updateStatus(@Param("id") id: string, @Body(StatusSchema) body: { status: string }) {
|
|
69
|
+
* // ...
|
|
70
|
+
* }
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare const PatchMapping: (path: string, options?: MappingOptions) => (_value: Function, context: ClassMethodDecoratorContext) => void;
|
|
75
|
+
/**
|
|
76
|
+
* Maps a controller method to handle HTTP DELETE requests.
|
|
77
|
+
*
|
|
78
|
+
* @param path - Route path relatif terhadap basePath controller
|
|
79
|
+
* @param options - Opsi mapping
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* @ReqController("/users")
|
|
84
|
+
* class UserController {
|
|
85
|
+
* @DeleteMapping("/:id", { summary: "Delete a user" })
|
|
86
|
+
* async delete(@Param("id") id: string) {
|
|
87
|
+
* // ...
|
|
88
|
+
* }
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare const DeleteMapping: (path: string, options?: MappingOptions) => (_value: Function, context: ClassMethodDecoratorContext) => void;
|
|
93
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../decorators/mapping/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAA6B,MAAM,sBAAsB,CAAC;AAyCtF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,UAAU,SA9CE,MAAM,YAAY,cAAc,MACpC,QAAQ,QAAQ,EAAE,SAAS,2BAA2B,SA6CpB,CAAC;AAExD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,WAAW,SAlEC,MAAM,YAAY,cAAc,MACpC,QAAQ,QAAQ,EAAE,SAAS,2BAA2B,SAiElB,CAAC;AAE1D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,UAAU,SArFE,MAAM,YAAY,cAAc,MACpC,QAAQ,QAAQ,EAAE,SAAS,2BAA2B,SAoFpB,CAAC;AAExD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,YAAY,SAxGA,MAAM,YAAY,cAAc,MACpC,QAAQ,QAAQ,EAAE,SAAS,2BAA2B,SAuGhB,CAAC;AAE5D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa,SA3HD,MAAM,YAAY,cAAc,MACpC,QAAQ,QAAQ,EAAE,SAAS,2BAA2B,SA0Hd,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { META } from "../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Factory untuk membuat method mapping decorator (GetMapping, PostMapping, dll).
|
|
4
|
+
*
|
|
5
|
+
* Setiap decorator yang dihasilkan menyimpan metadata route ke `context.metadata`
|
|
6
|
+
* via TC39 native decorator, yang nantinya dibaca oleh RouteResolver.
|
|
7
|
+
*
|
|
8
|
+
* @param method - HTTP method yang akan di-map
|
|
9
|
+
*/
|
|
10
|
+
function createMappingDecorator(method) {
|
|
11
|
+
return function (path, options) {
|
|
12
|
+
return function (_value, context) {
|
|
13
|
+
const normalizedPath = normalizePath(path);
|
|
14
|
+
if (!context.metadata)
|
|
15
|
+
return;
|
|
16
|
+
const route = {
|
|
17
|
+
method,
|
|
18
|
+
path: normalizedPath,
|
|
19
|
+
propertyKey: String(context.name),
|
|
20
|
+
options: options ?? {},
|
|
21
|
+
};
|
|
22
|
+
const existingRoutes = context.metadata[META.ROUTES] ?? [];
|
|
23
|
+
existingRoutes.push(route);
|
|
24
|
+
context.metadata[META.ROUTES] = existingRoutes;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Normalizes a path: ensures leading "/".
|
|
30
|
+
*/
|
|
31
|
+
function normalizePath(path) {
|
|
32
|
+
if (!path.startsWith("/")) {
|
|
33
|
+
path = "/" + path;
|
|
34
|
+
}
|
|
35
|
+
return path;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Maps a controller method to handle HTTP GET requests.
|
|
39
|
+
*
|
|
40
|
+
* @param path - Route path relatif terhadap basePath controller
|
|
41
|
+
* @param options - Opsi mapping (summary, auth override, swagger, dll)
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* @ReqController("/users")
|
|
46
|
+
* class UserController {
|
|
47
|
+
* @GetMapping("/", { summary: "Get all users" })
|
|
48
|
+
* async getAll(@Query(PaginationSchema) query: IPagination) {
|
|
49
|
+
* // ...
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export const GetMapping = createMappingDecorator("get");
|
|
55
|
+
/**
|
|
56
|
+
* Maps a controller method to handle HTTP POST requests.
|
|
57
|
+
*
|
|
58
|
+
* @param path - Route path relatif terhadap basePath controller
|
|
59
|
+
* @param options - Opsi mapping
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* @ReqController("/users")
|
|
64
|
+
* class UserController {
|
|
65
|
+
* @PostMapping("/", { summary: "Create a user" })
|
|
66
|
+
* @HttpStatus(201)
|
|
67
|
+
* async create(@Body(CreateUserSchema) body: ICreateUser) {
|
|
68
|
+
* // ...
|
|
69
|
+
* }
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export const PostMapping = createMappingDecorator("post");
|
|
74
|
+
/**
|
|
75
|
+
* Maps a controller method to handle HTTP PUT requests.
|
|
76
|
+
*
|
|
77
|
+
* @param path - Route path relatif terhadap basePath controller
|
|
78
|
+
* @param options - Opsi mapping
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* @ReqController("/users")
|
|
83
|
+
* class UserController {
|
|
84
|
+
* @PutMapping("/:id", { summary: "Update a user" })
|
|
85
|
+
* async update(@Param("id") id: string, @Body(UpdateSchema) body: IUpdate) {
|
|
86
|
+
* // ...
|
|
87
|
+
* }
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export const PutMapping = createMappingDecorator("put");
|
|
92
|
+
/**
|
|
93
|
+
* Maps a controller method to handle HTTP PATCH requests.
|
|
94
|
+
*
|
|
95
|
+
* @param path - Route path relatif terhadap basePath controller
|
|
96
|
+
* @param options - Opsi mapping
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* @ReqController("/users")
|
|
101
|
+
* class UserController {
|
|
102
|
+
* @PatchMapping("/:id/status", { summary: "Update user status" })
|
|
103
|
+
* async updateStatus(@Param("id") id: string, @Body(StatusSchema) body: { status: string }) {
|
|
104
|
+
* // ...
|
|
105
|
+
* }
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export const PatchMapping = createMappingDecorator("patch");
|
|
110
|
+
/**
|
|
111
|
+
* Maps a controller method to handle HTTP DELETE requests.
|
|
112
|
+
*
|
|
113
|
+
* @param path - Route path relatif terhadap basePath controller
|
|
114
|
+
* @param options - Opsi mapping
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* @ReqController("/users")
|
|
119
|
+
* class UserController {
|
|
120
|
+
* @DeleteMapping("/:id", { summary: "Delete a user" })
|
|
121
|
+
* async delete(@Param("id") id: string) {
|
|
122
|
+
* // ...
|
|
123
|
+
* }
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export const DeleteMapping = createMappingDecorator("delete");
|
|
128
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../decorators/mapping/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C;;;;;;;GAOG;AACH,SAAS,sBAAsB,CAAC,MAAkB;IAChD,OAAO,UAAU,IAAY,EAAE,OAAwB;QACrD,OAAO,UAAU,MAAgB,EAAE,OAAoC;YACrE,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,CAAC,OAAO,CAAC,QAAQ;gBAAE,OAAO;YAE9B,MAAM,KAAK,GAAkB;gBAC3B,MAAM;gBACN,IAAI,EAAE,cAAc;gBACpB,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;gBACjC,OAAO,EAAE,OAAO,IAAI,EAAE;aACvB,CAAC;YAEF,MAAM,cAAc,GAAqB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAqB,IAAI,EAAE,CAAC;YACjG,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC;QACjD,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;IACpB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;AAExD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;AAE1D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;AAExD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;AAE5D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { MiddlewareFn } from "../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Applies one or more middleware functions to a specific route method.
|
|
4
|
+
*
|
|
5
|
+
* Middleware dijalankan secara berurutan sebelum route handler.
|
|
6
|
+
* Bisa digunakan untuk logging, file upload, rate limiting, dll.
|
|
7
|
+
*
|
|
8
|
+
* @param middlewares - Middleware functions to apply (Express/fastify-compatible)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import multer from "multer";
|
|
13
|
+
* const upload = multer({ dest: "uploads/" });
|
|
14
|
+
*
|
|
15
|
+
* @ReqController("/files")
|
|
16
|
+
* class FileController {
|
|
17
|
+
* @PostMapping("/upload")
|
|
18
|
+
* @UseMiddleware(upload.single("avatar"))
|
|
19
|
+
* async uploadAvatar(@Req() req: express.Request) {
|
|
20
|
+
* return { file: req.file };
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // Multiple middlewares
|
|
28
|
+
* @Get("/admin")
|
|
29
|
+
* @UseMiddleware(authMiddleware, adminOnlyMiddleware)
|
|
30
|
+
* async adminPanel() {
|
|
31
|
+
* // ...
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function UseMiddleware(...middlewares: MiddlewareFn[]): (_value: Function, context: ClassMethodDecoratorContext) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Overrides the default HTTP response status code for a specific route.
|
|
38
|
+
*
|
|
39
|
+
* Default status code adalah 200. Gunakan decorator ini untuk
|
|
40
|
+
* kasus seperti 201 Created, 204 No Content, atau kode lain.
|
|
41
|
+
*
|
|
42
|
+
* @param code - HTTP status code (contoh: 201, 204, 202)
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* @ReqController("/users")
|
|
47
|
+
* class UserController {
|
|
48
|
+
* @PostMapping("/")
|
|
49
|
+
* @HttpStatus(201)
|
|
50
|
+
* async create(@Body(CreateUserSchema) body: ICreateUser) {
|
|
51
|
+
* return await UserService.create(body);
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* @DeleteMapping("/:id")
|
|
59
|
+
* @HttpStatus(204)
|
|
60
|
+
* async delete(@Param("id") id: string) {
|
|
61
|
+
* await UserService.delete(id);
|
|
62
|
+
* return null; // response 204 tanpa body
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function HttpStatus(code: number): (_value: Function, context: ClassMethodDecoratorContext) => void;
|
|
67
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../decorators/method/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,aAAa,CAAC,GAAG,WAAW,EAAE,YAAY,EAAE,IACzC,QAAQ,QAAQ,EAAE,SAAS,2BAA2B,UAOxE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,IACpB,QAAQ,QAAQ,EAAE,SAAS,2BAA2B,UAKxE"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { META } from "../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Applies one or more middleware functions to a specific route method.
|
|
4
|
+
*
|
|
5
|
+
* Middleware dijalankan secara berurutan sebelum route handler.
|
|
6
|
+
* Bisa digunakan untuk logging, file upload, rate limiting, dll.
|
|
7
|
+
*
|
|
8
|
+
* @param middlewares - Middleware functions to apply (Express/fastify-compatible)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import multer from "multer";
|
|
13
|
+
* const upload = multer({ dest: "uploads/" });
|
|
14
|
+
*
|
|
15
|
+
* @ReqController("/files")
|
|
16
|
+
* class FileController {
|
|
17
|
+
* @PostMapping("/upload")
|
|
18
|
+
* @UseMiddleware(upload.single("avatar"))
|
|
19
|
+
* async uploadAvatar(@Req() req: express.Request) {
|
|
20
|
+
* return { file: req.file };
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // Multiple middlewares
|
|
28
|
+
* @Get("/admin")
|
|
29
|
+
* @UseMiddleware(authMiddleware, adminOnlyMiddleware)
|
|
30
|
+
* async adminPanel() {
|
|
31
|
+
* // ...
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function UseMiddleware(...middlewares) {
|
|
36
|
+
return function (_value, context) {
|
|
37
|
+
if (!context.metadata)
|
|
38
|
+
return;
|
|
39
|
+
const key = META.MIDDLEWARES_PREFIX + String(context.name);
|
|
40
|
+
const existing = context.metadata[key] ?? [];
|
|
41
|
+
existing.push(...middlewares);
|
|
42
|
+
context.metadata[key] = existing;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Overrides the default HTTP response status code for a specific route.
|
|
47
|
+
*
|
|
48
|
+
* Default status code adalah 200. Gunakan decorator ini untuk
|
|
49
|
+
* kasus seperti 201 Created, 204 No Content, atau kode lain.
|
|
50
|
+
*
|
|
51
|
+
* @param code - HTTP status code (contoh: 201, 204, 202)
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* @ReqController("/users")
|
|
56
|
+
* class UserController {
|
|
57
|
+
* @PostMapping("/")
|
|
58
|
+
* @HttpStatus(201)
|
|
59
|
+
* async create(@Body(CreateUserSchema) body: ICreateUser) {
|
|
60
|
+
* return await UserService.create(body);
|
|
61
|
+
* }
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* @DeleteMapping("/:id")
|
|
68
|
+
* @HttpStatus(204)
|
|
69
|
+
* async delete(@Param("id") id: string) {
|
|
70
|
+
* await UserService.delete(id);
|
|
71
|
+
* return null; // response 204 tanpa body
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export function HttpStatus(code) {
|
|
76
|
+
return function (_value, context) {
|
|
77
|
+
if (!context.metadata)
|
|
78
|
+
return;
|
|
79
|
+
const key = META.HTTP_STATUS_PREFIX + String(context.name);
|
|
80
|
+
context.metadata[key] = code;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../decorators/method/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,aAAa,CAAC,GAAG,WAA2B;IAC1D,OAAO,UAAU,MAAgB,EAAE,OAAoC;QACrE,IAAI,CAAC,OAAO,CAAC,QAAQ;YAAE,OAAO;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC3D,MAAM,QAAQ,GAAoB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAoB,IAAI,EAAE,CAAC;QACjF,QAAQ,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC;QAC9B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,UAAU,MAAgB,EAAE,OAAoC;QACrE,IAAI,CAAC,OAAO,CAAC,QAAQ;YAAE,OAAO;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC3D,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { ZodSchema } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Injects and optionally validates `req.body` using a Zod schema.
|
|
4
|
+
*
|
|
5
|
+
* @param schema - Optional Zod schema for validation. Jika diberikan,
|
|
6
|
+
* request body akan di-parse dan divalidasi otomatis.
|
|
7
|
+
* Throw `BadRequestException` jika validasi gagal.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const CreateUserSchema = z.object({
|
|
12
|
+
* name: z.string().min(1),
|
|
13
|
+
* email: z.string().email(),
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* @ReqController("/users")
|
|
17
|
+
* class UserController {
|
|
18
|
+
* @PostMapping("/")
|
|
19
|
+
* async create(@Body(CreateUserSchema) body: { name: string; email: string }) {
|
|
20
|
+
* // body sudah tervalidasi dan typed
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // Tanpa schema — body dikirim raw
|
|
28
|
+
* @PostMapping("/webhook")
|
|
29
|
+
* async handleWebhook(@Body() body: unknown) {
|
|
30
|
+
* // validasi manual
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function Body(schema?: ZodSchema): (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Injects and optionally validates `req.query` using a Zod schema.
|
|
37
|
+
*
|
|
38
|
+
* Gunakan `z.coerce` untuk type conversion (string → number, dll).
|
|
39
|
+
*
|
|
40
|
+
* @param schema - Optional Zod schema for validation
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const PaginationSchema = z.object({
|
|
45
|
+
* page: z.coerce.number().default(1),
|
|
46
|
+
* size: z.coerce.number().default(10),
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* @ReqController("/users")
|
|
50
|
+
* class UserController {
|
|
51
|
+
* @GetMapping("/")
|
|
52
|
+
* async getAll(@Query(PaginationSchema) query: { page: number; size: number }) {
|
|
53
|
+
* // query.page dan query.size otomatis di-coerce ke number
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function Query(schema?: ZodSchema): (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Injects a single route parameter by key.
|
|
61
|
+
*
|
|
62
|
+
* @param key - Nama route parameter (contoh: "id" untuk route `/:id`)
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* @ReqController("/users")
|
|
67
|
+
* class UserController {
|
|
68
|
+
* @GetMapping("/:id")
|
|
69
|
+
* async getById(@Param("id") id: string) {
|
|
70
|
+
* // id = "123" untuk request GET /users/123
|
|
71
|
+
* }
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function Param(key: string): (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
76
|
+
/**
|
|
77
|
+
* Injects the raw framework request object.
|
|
78
|
+
*
|
|
79
|
+
* Berguna saat perlu akses ke properti native request
|
|
80
|
+
* seperti headers, raw body stream, atau IP address.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* @ReqController("/auth")
|
|
85
|
+
* class AuthController {
|
|
86
|
+
* @PostMapping("/refresh")
|
|
87
|
+
* async refresh(@Req() req: express.Request) {
|
|
88
|
+
* const token = req.headers["authorization"];
|
|
89
|
+
* }
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // Dengan Fastify
|
|
96
|
+
* @PostMapping("/webhook")
|
|
97
|
+
* async handle(@Req() req: FastifyRequest) {
|
|
98
|
+
* const sourceIp = req.ip;
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function Req(): (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
103
|
+
/**
|
|
104
|
+
* Injects a CookieSetter instance for reading, setting, and deleting cookies.
|
|
105
|
+
*
|
|
106
|
+
* CookieSetter adalah helper yang mengabstraksi operasi cookie
|
|
107
|
+
* di Express dan Fastify melalui adapter pattern.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* @ReqController("/auth")
|
|
112
|
+
* class AuthController {
|
|
113
|
+
* @PostMapping("/login")
|
|
114
|
+
* async login(@Body(LoginSchema) body: ILogin, @Cookie() cookie: CookieSetter) {
|
|
115
|
+
* cookie.set("refresh_token", token, { httpOnly: true, secure: true });
|
|
116
|
+
* const existing = cookie.get("refresh_token");
|
|
117
|
+
* cookie.delete("old_token");
|
|
118
|
+
* }
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare function Cookie(): (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
123
|
+
/**
|
|
124
|
+
* Injects the raw framework reply object (FastifyReply / express.Response).
|
|
125
|
+
*
|
|
126
|
+
* Digunakan saat handler perlu kontrol penuh terhadap response:
|
|
127
|
+
* - Set content-type selain JSON (HTML, file stream)
|
|
128
|
+
* - Set custom headers
|
|
129
|
+
* - Return non-JSON response (misal: redirect, HTML page)
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* @ReqController("/oauth")
|
|
134
|
+
* class OAuthController {
|
|
135
|
+
* @GetMapping("/callback")
|
|
136
|
+
* async callback(@Reply() reply: FastifyReply) {
|
|
137
|
+
* reply.type("text/html").send("<h1>Login berhasil</h1>");
|
|
138
|
+
* return reply; // Wajib return reply agar framework tidak auto-send
|
|
139
|
+
* }
|
|
140
|
+
* }
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // Express Response — set cookie domain
|
|
146
|
+
* @Get("/download")
|
|
147
|
+
* async download(@Reply() res: express.Response) {
|
|
148
|
+
* res.setHeader("Content-Type", "application/octet-stream");
|
|
149
|
+
* res.status(200).send(Buffer.from("..."));
|
|
150
|
+
* return res;
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export declare function Reply(): (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
155
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../decorators/parameter/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AA2BrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,IACpB,QAAQ,MAAM,EAAE,aAAa,MAAM,GAAG,MAAM,EAAE,gBAAgB,MAAM,KAAG,IAAI,CAG7F;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,IACrB,QAAQ,MAAM,EAAE,aAAa,MAAM,GAAG,MAAM,EAAE,gBAAgB,MAAM,KAAG,IAAI,CAG7F;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,IACd,QAAQ,MAAM,EAAE,aAAa,MAAM,GAAG,MAAM,EAAE,gBAAgB,MAAM,KAAG,IAAI,CAG7F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,GAAG,KACA,QAAQ,MAAM,EAAE,aAAa,MAAM,GAAG,MAAM,EAAE,gBAAgB,MAAM,KAAG,IAAI,CAG7F;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,KACH,QAAQ,MAAM,EAAE,aAAa,MAAM,GAAG,MAAM,EAAE,gBAAgB,MAAM,KAAG,IAAI,CAG7F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,KAAK,KACF,QAAQ,MAAM,EAAE,aAAa,MAAM,GAAG,MAAM,EAAE,gBAAgB,MAAM,KAAG,IAAI,CAG7F"}
|