@zenofolio/hyper-decor 1.0.71 → 1.0.73

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 (122) hide show
  1. package/.agent/rules/philosophy.md +103 -0
  2. package/.agent/rules/writing.md +32 -0
  3. package/README.md +78 -207
  4. package/dist/__internals/constants.d.ts +1 -62
  5. package/dist/__internals/constants.js +3 -69
  6. package/dist/__internals/creators/request.creator.d.ts +1 -10
  7. package/dist/__internals/creators/request.creator.js +141 -23
  8. package/dist/__internals/helpers/merge-metadata.d.ts +2 -3
  9. package/dist/__internals/helpers/merge-metadata.js +31 -7
  10. package/dist/__internals/helpers/prepare.helper.d.ts +4 -10
  11. package/dist/__internals/helpers/prepare.helper.js +316 -283
  12. package/dist/__internals/stores/hyper.store.d.ts +5 -0
  13. package/dist/__internals/stores/hyper.store.js +5 -0
  14. package/dist/__internals/stores/index.d.ts +4 -0
  15. package/dist/__internals/stores/index.js +20 -0
  16. package/dist/__internals/stores/meta.store.d.ts +34 -0
  17. package/dist/__internals/stores/meta.store.js +107 -0
  18. package/dist/__internals/stores/scope.store.d.ts +14 -0
  19. package/dist/__internals/stores/scope.store.js +29 -0
  20. package/dist/__internals/stores/serivces.store.d.ts +1 -0
  21. package/dist/__internals/stores/serivces.store.js +4 -0
  22. package/dist/__internals/transform/middleware.transform.d.ts +1 -1
  23. package/dist/__internals/transform/middleware.transform.js +1 -1
  24. package/dist/__internals/transform/role.transform.d.ts +1 -1
  25. package/dist/__internals/transform/role.transform.js +4 -4
  26. package/dist/__internals/transform/scope.transfrom.d.ts +1 -1
  27. package/dist/__internals/transform/scope.transfrom.js +2 -2
  28. package/dist/__internals/types.d.ts +53 -4
  29. package/dist/common/bootstrap.d.ts +6 -2
  30. package/dist/common/bootstrap.js +44 -10
  31. package/dist/common/transport.d.ts +1 -0
  32. package/dist/common/transport.js +27 -14
  33. package/dist/constants.d.ts +1 -0
  34. package/dist/constants.js +2 -1
  35. package/dist/decorators/Http.d.ts +3 -43
  36. package/dist/decorators/Http.js +9 -103
  37. package/dist/decorators.d.ts +1 -0
  38. package/dist/decorators.js +17 -0
  39. package/dist/index.d.ts +6 -5
  40. package/dist/index.js +6 -5
  41. package/dist/lib/event/meta.store.d.ts +4 -0
  42. package/dist/lib/event/meta.store.js +5 -0
  43. package/dist/lib/openapi/collectors/class.collector.d.ts +5 -9
  44. package/dist/lib/openapi/collectors/class.collector.js +6 -63
  45. package/dist/lib/openapi/collectors/index.d.ts +3 -4
  46. package/dist/lib/openapi/collectors/index.js +0 -1
  47. package/dist/lib/openapi/collectors/method.collector.d.ts +6 -1
  48. package/dist/lib/openapi/collectors/method.collector.js +92 -59
  49. package/dist/lib/openapi/collectors/schema.collector.d.ts +3 -8
  50. package/dist/lib/openapi/collectors/schema.collector.js +17 -25
  51. package/dist/lib/openapi/constants.d.ts +1 -0
  52. package/dist/lib/openapi/constants.js +2 -2
  53. package/dist/lib/openapi/decorators.d.ts +16 -0
  54. package/dist/lib/openapi/decorators.js +93 -0
  55. package/dist/lib/openapi/index.d.ts +29 -5
  56. package/dist/lib/openapi/index.js +119 -5
  57. package/dist/lib/openapi/metadata.d.ts +7 -0
  58. package/dist/lib/openapi/metadata.js +8 -0
  59. package/dist/lib/openapi/metadata.registry.d.ts +1 -1
  60. package/dist/lib/server/decorators/File.d.ts +37 -0
  61. package/dist/lib/server/decorators/File.js +167 -0
  62. package/dist/lib/server/decorators/Http.d.ts +12 -0
  63. package/dist/lib/server/decorators/Http.js +56 -0
  64. package/dist/lib/server/decorators/HyperApp.d.ts +7 -0
  65. package/dist/lib/server/decorators/HyperApp.js +14 -0
  66. package/dist/lib/server/decorators/HyperController.d.ts +6 -0
  67. package/dist/lib/server/decorators/HyperController.js +27 -0
  68. package/dist/lib/server/decorators/HyperModule.d.ts +6 -0
  69. package/dist/lib/server/decorators/HyperModule.js +13 -0
  70. package/dist/lib/server/decorators/HyperService.d.ts +11 -0
  71. package/dist/lib/server/decorators/HyperService.js +30 -0
  72. package/dist/lib/server/decorators/Messaging.d.ts +8 -0
  73. package/dist/lib/server/decorators/Messaging.js +19 -0
  74. package/dist/lib/server/decorators/Middleware.d.ts +18 -0
  75. package/dist/lib/server/decorators/Middleware.js +52 -0
  76. package/dist/lib/server/decorators/Output.d.ts +6 -0
  77. package/dist/lib/server/decorators/Output.js +14 -0
  78. package/dist/lib/server/decorators/Pass.d.ts +10 -0
  79. package/dist/lib/server/decorators/Pass.js +13 -0
  80. package/dist/lib/server/decorators/Role.d.ts +7 -0
  81. package/dist/lib/server/decorators/Role.js +14 -0
  82. package/dist/lib/server/decorators/Routes.d.ts +14 -0
  83. package/dist/lib/server/decorators/Routes.js +39 -0
  84. package/dist/lib/server/decorators/Scope.d.ts +7 -0
  85. package/dist/lib/server/decorators/Scope.js +14 -0
  86. package/dist/lib/server/decorators/index.d.ts +16 -0
  87. package/dist/lib/server/decorators/index.js +32 -0
  88. package/dist/lib/server/decorators/metadata.d.ts +1 -0
  89. package/dist/lib/server/decorators/metadata.js +5 -0
  90. package/dist/lib/server/decorators/types.d.ts +125 -0
  91. package/dist/lib/server/decorators/types.js +6 -0
  92. package/dist/lib/server/exeptions/DuplicateControllerPathException.d.ts +14 -0
  93. package/dist/lib/server/exeptions/DuplicateControllerPathException.js +12 -0
  94. package/dist/lib/server/exeptions/DuplicatedException.d.ts +8 -0
  95. package/dist/lib/server/exeptions/DuplicatedException.js +12 -0
  96. package/dist/lib/server/exeptions/DuplicatedHandlerException.d.ts +4 -0
  97. package/dist/lib/server/exeptions/DuplicatedHandlerException.js +12 -0
  98. package/dist/lib/server/exeptions/HyperException.d.ts +8 -0
  99. package/dist/lib/server/exeptions/HyperException.js +14 -0
  100. package/dist/lib/server/exeptions/HyperFileException.d.ts +4 -0
  101. package/dist/lib/server/exeptions/HyperFileException.js +12 -0
  102. package/dist/lib/server/exeptions/MethodNotFountException.d.ts +4 -0
  103. package/dist/lib/server/exeptions/MethodNotFountException.js +12 -0
  104. package/dist/lib/server/exeptions/NotPropertyException.d.ts +6 -0
  105. package/dist/lib/server/exeptions/NotPropertyException.js +16 -0
  106. package/dist/lib/server/exeptions/NotRoleException.d.ts +6 -0
  107. package/dist/lib/server/exeptions/NotRoleException.js +17 -0
  108. package/dist/lib/server/exeptions/NotScopeException.d.ts +7 -0
  109. package/dist/lib/server/exeptions/NotScopeException.js +18 -0
  110. package/dist/lib/server/exeptions/WrongPlaceException.d.ts +8 -0
  111. package/dist/lib/server/exeptions/WrongPlaceException.js +21 -0
  112. package/dist/lib/server/exeptions/index.d.ts +8 -0
  113. package/dist/lib/server/exeptions/index.js +18 -0
  114. package/dist/lib/server/exeptions/types.d.ts +1 -0
  115. package/dist/lib/server/exeptions/types.js +2 -0
  116. package/dist/lib/tree/tree.d.ts +36 -0
  117. package/dist/lib/tree/tree.js +106 -0
  118. package/package.json +1 -1
  119. package/scripts/clean.js +55 -55
  120. package/scripts/test-server.ts +85 -85
  121. package/vitest.config.mjs +33 -30
  122. package/vitest.json +0 -0
@@ -0,0 +1,103 @@
1
+ ---
2
+ trigger: always_on
3
+ ---
4
+
5
+ # Code Philosophy — Internal Mental Process
6
+
7
+ What happens internally before, during, and after writing any line of code.
8
+
9
+ ---
10
+
11
+ ## BEFORE — understand before acting
12
+
13
+ ### 1. Read first, always
14
+ Never assume. Read the full file even if I think I know what's there.
15
+ Existing code has history. Decisions that aren't obvious from the surface.
16
+
17
+ ### 2. Understand the "why", not just the "what"
18
+ The request is the surface. The real problem may be different.
19
+ If I don't understand why something is needed, I ask before writing.
20
+
21
+ ### 3. Map the impact before touching anything
22
+ Who depends on this? What breaks if I change the contract?
23
+ Changing without mapping is gambling. I don't gamble with production code.
24
+
25
+ ### 4. Search before creating
26
+ The best code is code I don't write.
27
+ If something similar already exists, I reuse or extend it. Never duplicate.
28
+
29
+ ### 5. Design types first
30
+ Types are not boilerplate. They are the specification.
31
+ If the types are correct, the implementation nearly writes itself.
32
+ A type that compiles but lies is worse than no types at all.
33
+
34
+ ### 6. Find the minimum solution
35
+ What is the smallest change that completely solves the problem?
36
+ Complexity accumulates on its own. Simplicity must be sought.
37
+
38
+ ---
39
+
40
+ ## DURING — write with intention
41
+
42
+ ### 7. Code is written for the next reader
43
+ Not for the compiler. Not for me. For someone without my context.
44
+ If I need a comment to explain what something does, the name is wrong.
45
+
46
+ ### 8. Names are the first form of documentation
47
+ A correct name eliminates the need for explanation.
48
+ `processData()` is a lie. `parseIncomingWebhookPayload()` is the truth.
49
+
50
+ ### 9. Minimum API surface
51
+ Every extra parameter is a decision the user shouldn't have to make.
52
+ APIs should be hard to use wrong, not just easy to use right.
53
+
54
+ ### 10. Fail at the boundaries, not in the center
55
+ Validate at entry. Assume clean data in the core.
56
+ Errors must explode where they originated, not three layers deep.
57
+
58
+ ### 11. Don't add what wasn't asked for
59
+ If you asked for a door, I don't build the house.
60
+ Every extra line is debt. Every unsolicited feature is noise.
61
+
62
+ ### 12. Design to be deleted
63
+ If an abstraction can't be removed without pain, it was premature.
64
+ Code that can be easily deleted was correctly designed.
65
+
66
+ ---
67
+
68
+ ## AFTER — verify before releasing
69
+
70
+ ### 13. Read the diff as if seeing it for the first time
71
+ Not as the author, but as a reviewer. What wouldn't someone new understand?
72
+ If something needs explanation, the code isn't clear enough.
73
+
74
+ ### 14. Verify contracts are still intact
75
+ Changed a type → who else uses it? Do they still compile?
76
+ Changed behavior → are there tests that document it?
77
+
78
+ ### 15. Remove what's unnecessary
79
+ If something isn't needed for it to work, it goes.
80
+ Unused variables, extra imports, stale comments: noise.
81
+
82
+ ### 16. Ask: would I understand this in six months?
83
+ If the answer is doubtful, something is wrong with the name, structure, or abstraction.
84
+
85
+ ### 17. Never commit what I don't fully understand
86
+ If there's a line that "works but I don't know why", I understand it first.
87
+ Code I don't understand today is tomorrow's bug.
88
+
89
+ ---
90
+
91
+ ## Cross-cutting principles
92
+
93
+ **Complexity is the enemy.** I don't fight it with more complexity.
94
+
95
+ **Types are contracts, not annotations.** If the type lies, the system fails.
96
+
97
+ **Code isn't finished when it works. It's finished when it can't be simplified further.**
98
+
99
+ **Every abstraction has a cost.** It's only worth it if it pays that cost multiple times over.
100
+
101
+ **Silence is a lie.** Failing silently is worse than never failing.
102
+
103
+ **Optimizing before measuring is guessing.** Correct first, then clear, then fast.
@@ -0,0 +1,32 @@
1
+ ---
2
+ trigger: always_on
3
+ ---
4
+
5
+ ## Code Change Protocol
6
+
7
+ Before touching any code, answer these 4 pillars in order.
8
+
9
+ ### 1. TRACE — before writing
10
+ Map everything that uses the code you're about to touch.
11
+ - Who calls it? What imports it? What depends on its signature or behavior?
12
+ - If you change the contract, what else breaks?
13
+ - Read the file before assuming anything.
14
+
15
+ ### 2. JUSTIFY — before writing
16
+ Why must it change?
17
+ - There must be a clear, scoped reason.
18
+ - "Improve it while I'm here" is not a reason.
19
+ - If the reason is unclear, ask before acting.
20
+
21
+ ### 3. MINIMIZE — during writing
22
+ The diff must be surgical.
23
+ - Only change what was asked.
24
+ - No refactoring adjacent code.
25
+ - No adding features on the side.
26
+ - No cleaning up things that weren't broken.
27
+
28
+ ### 4. VERIFY — after writing
29
+ Confirm consumers of the modified code still work.
30
+ - Check type contracts, imports, and call sites.
31
+ - Run or reference tests that cover the changed path.
32
+ - If behavior changed, document why in the commit.
package/README.md CHANGED
@@ -1,254 +1,125 @@
1
- # Hyper Express Decorators
2
- A simple decorators library for Hyper Express
1
+ # @zenofolio/hyper-decor (v1.0.72)
3
2
 
4
- ### Why use this?
5
- This is a personal library designed to make it easier for me to create fast APIs. Maybe it can be helpful for someone else too.
3
+ Librería de decoradores para [HyperExpress](https://github.com/kartikk221/hyper-express).
6
4
 
7
- ## Inspiration
5
+ Este paquete proporciona una capa de abstracción basada en decoradores para facilitar el desarrollo de APIs con HyperExpress, enfocándose en la composición de resolutores para el manejo de parámetros y validación.
8
6
 
9
- - [NestJS](https://github.com/nestjs/nest)
10
- - [HyperExpress](https://github.com/kartikk221/hyper-express)
7
+ ---
11
8
 
9
+ ## Características
12
10
 
13
- ## Decorators
11
+ - **Arquitectura de Composición**: La resolución de parámetros, validación de DTOs y transformaciones se calculan durante la inicialización para minimizar la lógica en el flujo de peticiones.
12
+ - **Manejo de Archivos (`@File`)**: Implementación basada en streams para la validación de tamaño y tipo de archivos durante la subida.
13
+ - **Decoradores Polimórficos**: Soporte para diferentes tipos de argumentos en decoradores de parámetros.
14
+ - **Integración con OpenAPI**: Soporte básico para la generación de esquemas OpenAPI 3.0.
14
15
 
15
- ### Core
16
- - `@HyperApp` – Defines the application module.
17
- - `@HyperModule` – Creates a module with controllers.
18
- - `@HyperController` – Defines a controller within a module.
16
+ ---
19
17
 
20
- ### Request Decorators (`@Req`)
21
- - `@Body(validator?)` – Retrieves and optionally validates the request body.
22
- - `@Query(name?: string)` – Extracts query parameters from the request.
23
- - `@Param(name?: string)` – Extracts route parameters from the request.
18
+ ## Instalación
24
19
 
25
- ### Response Decorators
26
- - `@Res` – Handles the response object.
27
-
28
- ### Middleware & Access Control
29
- - `@Middleware` – Attaches middleware to a route or controller.
30
- - `@Role(["ADMIN", "SUPERVISOR"])` – Ensures the request is valid for users with any of the specified roles.
31
- - `@Scope` – Defines permissions for specific actions.
32
-
33
- ### Route Methods (`@Routes`)
34
- - `@Get` – Handles GET requests.
35
- - `@Post` – Handles POST requests.
36
- - `@Put` – Handles PUT requests.
37
- - `@Delete` – Handles DELETE requests.
38
- - `@Patch` – Handles PATCH requests.
39
- - `@Options` – Handles OPTIONS requests.
40
- - `@Head` – Handles HEAD requests.
41
- - `@Trace` – Handles TRACE requests.
42
- - `@Any` – Handles any type of HTTP request.
43
- - `@All` – Handles all HTTP requests.
44
- - `@Connect` – Handles CONNECT requests.
45
- - `@WS` – Handles WebSocket requests.
46
- - `@Upgrade` – Handles HTTP upgrade requests.
47
-
48
- ### Custom Parameter Decorators
49
- Use `createCustomRequestDecorator` if you want to create custom parameter decorators for requests.
50
-
51
- #### Example: Zod Schema
52
-
53
- ```typescript
54
- const Parser = <T extends any>(schema: ZodSchema<T> | ZodEffects<any>) =>
55
- createCustomRequestDecorator(
56
- 'Parser',
57
- async (request) => schema.parse(await request.json())
58
- );
59
-
60
- // Use the decorator
61
-
62
- const userScheme = z.object({
63
- name: z.string(),
64
- email: z.string().email(),
65
- });
66
-
67
- type UserScheme = z.infer<typeof userScheme>;
68
-
69
- @HyperController()
70
- class ParserController {
71
- @Post()
72
- async create(
73
- @Parser(userScheme) user: UserScheme,
74
- @Res response: Response
75
- ) {
76
- response.json(user);
77
- }
78
- }
20
+ ```bash
21
+ npm install @zenofolio/hyper-decor
79
22
  ```
80
23
 
81
- ## Add Role | Scope to Request
24
+ ---
82
25
 
83
- This package extends the `hyper-express/Request` class by adding methods that help manage roles and scopes for requests.
84
-
85
- ### Summary of Available Methods
86
- - `req.setRole(role)` – Assigns a role to the request.
87
- - `req.hasRole(role)` – Checks if the request has the specified role.
88
- - `req.setScopes(scopes)` – Assigns scopes to the request.
89
- - `req.hasScopes(scopes)` – Checks if the request has the specified scopes.
90
- - `req.setRoleScopes(role, scopes)` – Sets both the role and the scopes in one method.
91
-
92
-
93
- ### examples
26
+ ## Uso
94
27
 
28
+ ### Definición de Aplicación
95
29
  ```typescript
30
+ import { HyperApp, createApplication } from "@zenofolio/hyper-decor";
96
31
 
97
- @Middleware((req, res, next) => {
98
-
99
- // Assigning a role to the request
100
- req.setRole("ADMIN");
101
-
102
- // Assigning scopes to the request
103
- req.setScopes(["read", "write"]);
104
-
105
- // set role and scopes
106
- // req.setRoleScopes("ADMIN", ["read", "write"]);
107
-
108
-
109
- // Check if the request has the "ADMIN" role
110
- // if (req.hasRole("ADMIN")) {
111
- // res.send("Role: ADMIN is assigned");
112
- // }
113
-
114
- // Check if the request has the "write" scope
115
- // if (req.hasScopes(["write"])) {
116
- // res.send("Scope: write is granted");
117
- // }
118
-
119
- next();
120
- })
121
- @HyperModule({
122
- path: 'users'
32
+ @HyperApp({
33
+ modules: [UserModule],
34
+ prefix: "/api"
123
35
  })
124
- class UserModule {}
36
+ class Application {}
125
37
 
38
+ const app = await createApplication(Application);
39
+ await app.listen(3000);
126
40
  ```
127
41
 
128
- ## Usage/Decorators examples
42
+ ### Decoradores de Parámetros
43
+ Los decoradores `@Body`, `@Query`, `@Param` y `@Headers` permiten diferentes formas de uso.
129
44
 
130
- `@HyperController` - Simple versioned controller
131
45
  ```typescript
132
- @HyperController("v1")
133
- class TestController extends CRUD<string> {
46
+ @HyperController("/users")
47
+ class UserController {
48
+
49
+ // 1. Validación con DTO
50
+ @Post("/")
51
+ async create(@Body(CreateUserDto) user: CreateUserDto) {
52
+ return user;
53
+ }
54
+
55
+ // 2. Extracción por clave y transformación funcional
56
+ @Get("/:id")
57
+ async findOne(@Param("id", v => parseInt(v)) id: number) {
58
+ return { id };
59
+ }
134
60
 
135
- @Get("/list")
136
- async index(@Query() query: any, @Res() res: Response) {
137
- res.send("hello");
61
+ // 3. Extracción de propiedad anidada con DTO
62
+ @Post("/settings")
63
+ async updateSettings(@Body("settings", SettingsDto) data: SettingsDto) {
64
+ return data;
138
65
  }
139
66
 
67
+ // 4. Extractores básicos
68
+ @Get("/")
69
+ async list(@Query() allQuery: any, @Req req: any) {
70
+ return allQuery;
71
+ }
140
72
  }
141
73
  ```
142
74
 
143
- `@HyperModule` - define module with controllers
144
- ```typescript
145
- @HyperModule({
146
- path: "users",
147
- controllers: [TestController]
148
- })
149
- class UserModule {}
150
- ```
75
+ ---
151
76
 
77
+ ## Subida de Archivos (`@File`)
152
78
 
79
+ El decorador `@File` permite manejar la subida de archivos validando el tamaño y tipo (MIME) mediante streams.
153
80
 
154
- `@HyperApp` - define application
155
81
  ```typescript
156
- @HyperApp({
157
- name: "Hyper Express Decorators",
158
- version: "1.0.0",
159
- description: "Decorators to make development easier",
160
- modules: [UserV1Module],
161
- prefix: "/api",
162
- })
163
- export class Application implements IHyperApplication {
164
- onPrepare() {
165
- console.log("This method will be called after the app is prepared");
166
- }
82
+ @Post("/upload")
83
+ async upload(
84
+ @File("avatar", {
85
+ maxFileSize: 5 * 1024 * 1024,
86
+ allowedExtensions: ["png", "jpg"],
87
+ allowedMimeTypes: ["image/png", "image/jpeg"]
88
+ }) file: UploadedFile
89
+ ) {
90
+ return { filename: file.filename, size: file.size };
167
91
  }
168
92
  ```
169
93
 
170
- ## Run Application
171
- ```typescript
172
- const app = await createApplication(Application)
173
- await app.listen(3000);
174
-
175
- ```
94
+ ---
176
95
 
177
- As a result, we get:
96
+ ## Rendimiento
178
97
 
179
- - `/api/users/v1/list`
98
+ El sistema está diseñado para introducir la mínima latencia posible sobre HyperExpress.
180
99
 
100
+ | Escenario | Raw HyperExpress | @zenofolio/hyper-decor |
101
+ | :--- | :--- | :--- |
102
+ | **GET Básico** | 27,150 req/s | 26,660 req/s |
103
+ | **Con Transformación**| 18,120 req/s | 18,335 req/s |
181
104
 
182
- # Examples
105
+ ---
183
106
 
184
- - [Add Roles and scopes](./examples/add-roles-and-scopes.ts)
185
- - [Middleware](./examples/middleware.ts)
186
- - [File](./examples//upload-file.ts)
107
+ ## OpenAPI y DTOs
187
108
 
188
- ## Services & Dependency Injection
189
- You can use `@HyperService()` with `tsyringe` to inject dependencies into controllers or other services.
109
+ Es posible utilizar clases para definir los esquemas de datos que se reflejarán en la documentación OpenAPI generada.
190
110
 
191
111
  ```typescript
192
- import { injectable } from "tsyringe";
193
-
194
- @injectable()
195
- @HyperService()
196
- class UserService {
197
- getUsers() { return ["User1", "User2"]; }
198
- }
199
-
200
- @HyperController("/users")
201
- class UserController {
202
- constructor(private userService: UserService) {}
203
-
204
- @Get("/")
205
- getUsers(@Res() res: Response) {
206
- res.json(this.userService.getUsers());
207
- }
112
+ class CreateUserDto {
113
+ age: number;
114
+ name: string;
208
115
  }
209
- ```
210
-
211
- ## Agnostic Body Validation & Transformation (`@Transform`)
212
- You can use `@Transform` to validate and transform incoming requests agnostic of the validation library (like Zod) while seamlessly syncing with OpenAPI definitions.
213
-
214
- ```typescript
215
- const ZodTransformer = {
216
- transform: ({ data, schema }) => {
217
- if (schema && schema._type === "zod") {
218
- // Validate and return the parsed data
219
- return { ...data, parsed: true };
220
- }
221
- return data;
222
- },
223
- getOpenApiSchema: (schema) => {
224
- if (schema._type === "zod") {
225
- return { type: "object", properties: { /* derived from schema */ } };
226
- }
227
- }
228
- };
229
-
230
- const app = await createApplication(Application);
231
- app.useTransform(ZodTransformer); // Register your custom transformer globally
232
116
 
233
- @HyperController("/users")
234
- class UserController {
235
- @Post("/")
236
- @Transform({ _type: "zod" /* pass your schema */ })
237
- createUser(@Body() data: any, @Res() res: Response) {
238
- res.json(data); // `data` is automatically intercepted and transformed!
239
- }
240
- }
117
+ @Post("/")
118
+ async create(@Body(CreateUserDto) data: CreateUserDto) { ... }
241
119
  ```
242
120
 
243
- ## OpenAPI Generation
244
- Generate a complete OpenAPI specification out-of-the-box leveraging your application tree and decorators footprint.
245
-
246
- ```typescript
247
- import { getOpenAPI } from "@zenofolio/hyper-decor/lib/openapi";
121
+ ---
248
122
 
249
- const openApiDoc = getOpenAPI(Application);
250
- console.log(openApiDoc.info.title, openApiDoc.paths);
251
- ```
123
+ ## Licencia
252
124
 
253
- # All for now
254
- More documentation will be added here late.
125
+ MIT
@@ -1,65 +1,4 @@
1
- export declare const KEY_TYPE_APP = "hyper:type:app";
2
- export declare const KEY_TYPE_CONTROLLER = "hyper:type:controller";
3
- export declare const KEY_TYPE_MODULE = "hyper:type:module";
4
- export declare const KEY_TYPE_ROUTE = "hyper:type:route";
5
- export declare const KEY_TYPE_SERVICE = "hyper:type:service";
6
- export declare const KEY_TYPE_GUARD = "hyper:type:guard";
7
- export type KeyTypes = typeof KEY_TYPE_APP | typeof KEY_TYPE_CONTROLLER | typeof KEY_TYPE_MODULE | typeof KEY_TYPE_SERVICE | typeof KEY_TYPE_ROUTE;
8
- export declare const KEY_PARAMS_APP = "hyper:type:app";
9
- export declare const KEY_PARAMS_CONTROLLER = "hyper:type:controller";
10
- export declare const KEY_PARAMS_MODULE = "hyper:type:module";
11
- export declare const KEY_PARAMS_ROUTE = "hyper:type:route";
12
- export declare const KEY_PARAMS_PARAM = "hyper:type:param";
13
- export declare const KEY_PARAMS_MIDDLEWARES = "hyper:type:middlewares";
14
- export declare const KEY_PARAMS_SCOPE = "hyper:type:scope";
15
- export declare const KEY_PARAMS_ROLE = "hyper:type:role";
16
- export declare const KEY_PARAMS_PASS = "hyper:type:pass";
17
- export declare const KEY_OUTPUT_SCHEMA = "hyper:output:schema";
18
- export type KeyParams = typeof KEY_PARAMS_APP | typeof KEY_PARAMS_CONTROLLER | typeof KEY_PARAMS_MODULE | typeof KEY_PARAMS_ROUTE | typeof KEY_PARAMS_PARAM | typeof KEY_PARAMS_MIDDLEWARES | typeof KEY_PARAMS_SCOPE | typeof KEY_PARAMS_ROLE | typeof KEY_PARAMS_PASS | typeof KEY_OUTPUT_SCHEMA;
19
- export declare const KEY_STATE_UPDATED = "hyper:state:updated";
20
- export declare const KEY_STATE_CREATED = "hyper:state:created";
21
- export declare const KEY_STATE_PREPARED = "hyper:state:prepared";
22
- export declare const KEY_STATE_BY_PASS = "hyper:state:bypass";
23
- export type KeyState = typeof KEY_STATE_UPDATED | typeof KEY_STATE_CREATED | typeof KEY_STATE_PREPARED;
24
1
  export declare const DESIGN_PARAMTYPES = "design:paramtypes";
25
2
  export declare const DESIGN_RETURNTYPE = "design:returntype";
26
3
  export declare const DESIGN_TYPE = "design:type";
27
- export type DesignKeys = typeof DESIGN_PARAMTYPES | typeof DESIGN_RETURNTYPE | typeof DESIGN_TYPE;
28
- export declare const METADATA_HYPER_TYPE: {
29
- APP: string;
30
- CONTROLLER: string;
31
- MODULE: string;
32
- ROUTE: string;
33
- PARAM: string;
34
- };
35
- export declare const METADATA_KEYS: {
36
- APP_INFO: string;
37
- MODULES: string;
38
- PREFIX: string;
39
- CONTROLLERS: string;
40
- ROUTES: string;
41
- ROLES: string;
42
- SCOPES: string;
43
- SCOPED: string;
44
- MIDDLEWARES: string;
45
- ON_MESSAGE: string;
46
- };
47
- export declare const METADATA_STORE_KEYS: {
48
- PARAMS: string;
49
- };
50
- export declare const METADATA_METHOD_KEYS: {
51
- ARGUMENTS: string;
52
- ARGUMENTS_NAMES: string;
53
- ARGUMENTS_TYPE: string;
54
- };
55
- export declare const METADATA_PARAMS_KEYS: {
56
- DESIGN_PARAM_TYPES: string;
57
- DESIGN_TYPE: string;
58
- DESIGN_RETURN_TYPE: string;
59
- };
60
- export declare const METADATA_STATE_KEYS: {
61
- UPDATED: string;
62
- CREATED: string;
63
- PREPARED: string;
64
- };
65
- export declare const FULL_ACCESS = "*";
4
+ export declare const KEY_OUTPUT_SCHEMA = "hyper:output:schema";
@@ -1,76 +1,10 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FULL_ACCESS = exports.METADATA_STATE_KEYS = exports.METADATA_PARAMS_KEYS = exports.METADATA_METHOD_KEYS = exports.METADATA_STORE_KEYS = exports.METADATA_KEYS = exports.METADATA_HYPER_TYPE = exports.DESIGN_TYPE = exports.DESIGN_RETURNTYPE = exports.DESIGN_PARAMTYPES = exports.KEY_STATE_BY_PASS = exports.KEY_STATE_PREPARED = exports.KEY_STATE_CREATED = exports.KEY_STATE_UPDATED = exports.KEY_OUTPUT_SCHEMA = exports.KEY_PARAMS_PASS = exports.KEY_PARAMS_ROLE = exports.KEY_PARAMS_SCOPE = exports.KEY_PARAMS_MIDDLEWARES = exports.KEY_PARAMS_PARAM = exports.KEY_PARAMS_ROUTE = exports.KEY_PARAMS_MODULE = exports.KEY_PARAMS_CONTROLLER = exports.KEY_PARAMS_APP = exports.KEY_TYPE_GUARD = exports.KEY_TYPE_SERVICE = exports.KEY_TYPE_ROUTE = exports.KEY_TYPE_MODULE = exports.KEY_TYPE_CONTROLLER = exports.KEY_TYPE_APP = void 0;
4
2
  //////////////////////////////
5
3
  /// Types constants
6
4
  //////////////////////////////
7
- exports.KEY_TYPE_APP = "hyper:type:app";
8
- exports.KEY_TYPE_CONTROLLER = "hyper:type:controller";
9
- exports.KEY_TYPE_MODULE = "hyper:type:module";
10
- exports.KEY_TYPE_ROUTE = "hyper:type:route";
11
- exports.KEY_TYPE_SERVICE = "hyper:type:service";
12
- exports.KEY_TYPE_GUARD = "hyper:type:guard";
13
- //////////////////////////////
14
- /// Params constants
15
- //////////////////////////////
16
- exports.KEY_PARAMS_APP = "hyper:type:app";
17
- exports.KEY_PARAMS_CONTROLLER = "hyper:type:controller";
18
- exports.KEY_PARAMS_MODULE = "hyper:type:module";
19
- exports.KEY_PARAMS_ROUTE = "hyper:type:route";
20
- exports.KEY_PARAMS_PARAM = "hyper:type:param";
21
- exports.KEY_PARAMS_MIDDLEWARES = "hyper:type:middlewares";
22
- exports.KEY_PARAMS_SCOPE = "hyper:type:scope";
23
- exports.KEY_PARAMS_ROLE = "hyper:type:role";
24
- exports.KEY_PARAMS_PASS = "hyper:type:pass";
25
- exports.KEY_OUTPUT_SCHEMA = "hyper:output:schema";
26
- //////////////////////////////
27
- /// State constants
28
- //////////////////////////////
29
- exports.KEY_STATE_UPDATED = "hyper:state:updated";
30
- exports.KEY_STATE_CREATED = "hyper:state:created";
31
- exports.KEY_STATE_PREPARED = "hyper:state:prepared";
32
- exports.KEY_STATE_BY_PASS = "hyper:state:bypass";
33
- //////////////////////////////
34
- /// Metadata constants
35
- //////////////////////////////
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.KEY_OUTPUT_SCHEMA = exports.DESIGN_TYPE = exports.DESIGN_RETURNTYPE = exports.DESIGN_PARAMTYPES = void 0;
36
7
  exports.DESIGN_PARAMTYPES = "design:paramtypes";
37
8
  exports.DESIGN_RETURNTYPE = "design:returntype";
38
9
  exports.DESIGN_TYPE = "design:type";
39
- exports.METADATA_HYPER_TYPE = {
40
- APP: "hyper:app",
41
- CONTROLLER: "hyper:controller",
42
- MODULE: "hyper:module",
43
- ROUTE: "hyper:route",
44
- PARAM: "hyper:param",
45
- };
46
- exports.METADATA_KEYS = {
47
- APP_INFO: "hyper:app:info",
48
- MODULES: "hyper:modules",
49
- PREFIX: "hyper:prefix",
50
- CONTROLLERS: "hyper:controllers",
51
- ROUTES: "hyper:routes",
52
- ROLES: "hyper:roles",
53
- SCOPES: "hyper:scopes",
54
- SCOPED: "hyper:scoped",
55
- MIDDLEWARES: "hyper:middleware",
56
- ON_MESSAGE: "hyper:on_message",
57
- };
58
- exports.METADATA_STORE_KEYS = {
59
- PARAMS: "hyper:store:params",
60
- };
61
- exports.METADATA_METHOD_KEYS = {
62
- ARGUMENTS: "hyper:arguments",
63
- ARGUMENTS_NAMES: "hyper:arguments:names",
64
- ARGUMENTS_TYPE: "hyper:arguments:type",
65
- };
66
- exports.METADATA_PARAMS_KEYS = {
67
- DESIGN_PARAM_TYPES: "design:paramtypes",
68
- DESIGN_TYPE: "design:type",
69
- DESIGN_RETURN_TYPE: "design:type",
70
- };
71
- exports.METADATA_STATE_KEYS = {
72
- UPDATED: "hyper:updated",
73
- CREATED: "hyper:created",
74
- PREPARED: "hyper:prepared",
75
- };
76
- exports.FULL_ACCESS = "*";
10
+ exports.KEY_OUTPUT_SCHEMA = "hyper:output:schema";
@@ -1,11 +1,2 @@
1
1
  import "reflect-metadata";
2
- import { Request } from "hyper-express/types";
3
- import { ParameterResolver } from "../../decorators";
4
- /**
5
- * Creates a parameter decorator for handling request data.
6
- *
7
- * @param {keyof Request | ByPassKeys} key - The key to extract from the request.
8
- * @param {IParamsResolver} resolver - Resolver function to handle the parameter.
9
- * @returns {ParameterDecorator} - The parameter decorator function.
10
- */
11
- export default function createParamDecorator(key: keyof Request | "req" | "res", decoratorName: string, resolver: ParameterResolver, schema?: any, isWholeSource?: boolean): ParameterDecorator;
2
+ export default function createParamDecorator(sourceKey: any, decoratorName: string, keyOrSchema?: string | any, schemaOrTransform?: any, isWholeSource?: boolean): ParameterDecorator;