@zenofolio/hyper-decor 1.0.7 → 1.0.8

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 (192) hide show
  1. package/.agent/rules/philosophy.md +103 -0
  2. package/.agent/rules/writing.md +32 -0
  3. package/README.md +103 -201
  4. package/dist/__internals/constants.d.ts +1 -62
  5. package/dist/__internals/constants.js +3 -69
  6. package/dist/__internals/helpers/merge-metadata.d.ts +2 -3
  7. package/dist/__internals/helpers/merge-metadata.js +31 -7
  8. package/dist/__internals/helpers/prepare.helper.d.ts +4 -10
  9. package/dist/__internals/helpers/prepare.helper.js +325 -281
  10. package/dist/__internals/stores/hyper.store.d.ts +5 -0
  11. package/dist/__internals/stores/hyper.store.js +5 -0
  12. package/dist/__internals/stores/index.d.ts +4 -0
  13. package/dist/{lib/openapi/helpers → __internals/stores}/index.js +4 -7
  14. package/dist/__internals/stores/meta.store.d.ts +34 -0
  15. package/dist/__internals/stores/meta.store.js +107 -0
  16. package/dist/{stores → __internals/stores}/scope.store.d.ts +1 -1
  17. package/dist/__internals/transform/middleware.transform.d.ts +1 -1
  18. package/dist/__internals/transform/middleware.transform.js +1 -1
  19. package/dist/__internals/transform/role.transform.d.ts +1 -1
  20. package/dist/__internals/transform/role.transform.js +4 -4
  21. package/dist/__internals/transform/scope.transfrom.d.ts +1 -1
  22. package/dist/__internals/transform/scope.transfrom.js +2 -2
  23. package/dist/__internals/types.d.ts +53 -4
  24. package/dist/common/bootstrap.d.ts +6 -2
  25. package/dist/common/bootstrap.js +49 -10
  26. package/dist/common/testing.d.ts +56 -0
  27. package/dist/common/testing.js +193 -0
  28. package/dist/common/transport.d.ts +1 -0
  29. package/dist/common/transport.js +27 -14
  30. package/dist/constants.d.ts +1 -0
  31. package/dist/constants.js +2 -1
  32. package/dist/decorators.d.ts +1 -0
  33. package/dist/{stores/index.js → decorators.js} +1 -1
  34. package/dist/index.d.ts +7 -5
  35. package/dist/index.js +7 -5
  36. package/dist/lib/event/meta.store.d.ts +4 -0
  37. package/dist/lib/event/meta.store.js +5 -0
  38. package/dist/lib/openapi/collectors/class.collector.d.ts +5 -9
  39. package/dist/lib/openapi/collectors/class.collector.js +6 -63
  40. package/dist/lib/openapi/collectors/index.d.ts +3 -4
  41. package/dist/lib/openapi/collectors/index.js +0 -1
  42. package/dist/lib/openapi/collectors/method.collector.d.ts +6 -1
  43. package/dist/lib/openapi/collectors/method.collector.js +92 -59
  44. package/dist/lib/openapi/collectors/schema.collector.d.ts +3 -8
  45. package/dist/lib/openapi/collectors/schema.collector.js +17 -25
  46. package/dist/lib/openapi/constants.d.ts +1 -0
  47. package/dist/lib/openapi/constants.js +2 -2
  48. package/dist/lib/openapi/decorators.d.ts +16 -0
  49. package/dist/lib/openapi/decorators.js +93 -0
  50. package/dist/lib/openapi/index.d.ts +29 -5
  51. package/dist/lib/openapi/index.js +119 -5
  52. package/dist/lib/openapi/metadata.d.ts +7 -0
  53. package/dist/lib/openapi/metadata.js +8 -0
  54. package/dist/lib/openapi/metadata.registry.d.ts +1 -1
  55. package/dist/lib/server/decorators/File.d.ts +37 -0
  56. package/dist/{decorators → lib/server/decorators}/File.js +62 -75
  57. package/dist/lib/server/decorators/Http.d.ts +12 -0
  58. package/dist/lib/server/decorators/Http.js +56 -0
  59. package/dist/lib/server/decorators/HyperApp.d.ts +7 -0
  60. package/dist/lib/server/decorators/HyperApp.js +14 -0
  61. package/dist/lib/server/decorators/HyperController.d.ts +6 -0
  62. package/dist/lib/server/decorators/HyperController.js +15 -0
  63. package/dist/lib/server/decorators/HyperModule.d.ts +6 -0
  64. package/dist/lib/server/decorators/HyperModule.js +13 -0
  65. package/dist/lib/server/decorators/HyperService.d.ts +12 -0
  66. package/dist/lib/server/decorators/HyperService.js +30 -0
  67. package/dist/lib/server/decorators/Messaging.d.ts +8 -0
  68. package/dist/lib/server/decorators/Messaging.js +19 -0
  69. package/dist/{decorators → lib/server/decorators}/Middleware.d.ts +5 -12
  70. package/dist/lib/server/decorators/Middleware.js +52 -0
  71. package/dist/lib/server/decorators/Output.d.ts +6 -0
  72. package/dist/lib/server/decorators/Output.js +14 -0
  73. package/dist/lib/server/decorators/Pass.d.ts +10 -0
  74. package/dist/lib/server/decorators/Pass.js +13 -0
  75. package/dist/lib/server/decorators/Role.d.ts +7 -0
  76. package/dist/lib/server/decorators/Role.js +14 -0
  77. package/dist/lib/server/decorators/Routes.d.ts +14 -0
  78. package/dist/lib/server/decorators/Routes.js +39 -0
  79. package/dist/lib/server/decorators/Scope.d.ts +7 -0
  80. package/dist/lib/server/decorators/Scope.js +14 -0
  81. package/dist/{decorators → lib/server/decorators}/index.d.ts +6 -4
  82. package/dist/{decorators → lib/server/decorators}/index.js +6 -4
  83. package/dist/lib/server/decorators/metadata.d.ts +1 -0
  84. package/dist/lib/server/decorators/metadata.js +5 -0
  85. package/dist/{decorators → lib/server/decorators}/types.d.ts +16 -15
  86. package/dist/{exeptions → lib/server/exeptions}/HyperException.d.ts +2 -1
  87. package/dist/{exeptions → lib/server/exeptions}/HyperException.js +2 -1
  88. package/dist/{exeptions → lib/server/exeptions}/HyperFileException.js +1 -1
  89. package/dist/{exeptions → lib/server/exeptions}/NotRoleException.js +1 -1
  90. package/dist/{exeptions → lib/server/exeptions}/NotScopeException.js +1 -1
  91. package/dist/{__internals/helpers/tree.helper.d.ts → lib/tree/tree.d.ts} +12 -12
  92. package/dist/lib/tree/tree.js +106 -0
  93. package/package.json +10 -2
  94. package/scripts/clean.js +54 -54
  95. package/scripts/test-server.ts +85 -85
  96. package/vitest.config.mjs +1 -1
  97. package/debug.txt +0 -1
  98. package/dist/__internals/creators/request.creator.d.ts +0 -11
  99. package/dist/__internals/creators/request.creator.js +0 -55
  100. package/dist/__internals/creators/routes.creator.d.ts +0 -9
  101. package/dist/__internals/creators/routes.creator.js +0 -39
  102. package/dist/__internals/decorator-base.d.ts +0 -30
  103. package/dist/__internals/decorator-base.js +0 -122
  104. package/dist/__internals/helpers/imports.helper.d.ts +0 -8
  105. package/dist/__internals/helpers/imports.helper.js +0 -92
  106. package/dist/__internals/helpers/tree.helper.js +0 -81
  107. package/dist/__internals/stores/metadata.store.d.ts +0 -15
  108. package/dist/__internals/stores/metadata.store.js +0 -37
  109. package/dist/decorators/File.d.ts +0 -65
  110. package/dist/decorators/Http.d.ts +0 -62
  111. package/dist/decorators/Http.js +0 -139
  112. package/dist/decorators/HyperApp.d.ts +0 -3
  113. package/dist/decorators/HyperApp.js +0 -96
  114. package/dist/decorators/HyperController.d.ts +0 -2
  115. package/dist/decorators/HyperController.js +0 -20
  116. package/dist/decorators/HyperModule.d.ts +0 -5
  117. package/dist/decorators/HyperModule.js +0 -14
  118. package/dist/decorators/HyperService.d.ts +0 -15
  119. package/dist/decorators/HyperService.js +0 -29
  120. package/dist/decorators/Messaging.d.ts +0 -10
  121. package/dist/decorators/Messaging.js +0 -22
  122. package/dist/decorators/Middleware.js +0 -65
  123. package/dist/decorators/Output.d.ts +0 -9
  124. package/dist/decorators/Output.js +0 -18
  125. package/dist/decorators/Pass.d.ts +0 -15
  126. package/dist/decorators/Pass.js +0 -32
  127. package/dist/decorators/Role.d.ts +0 -6
  128. package/dist/decorators/Role.js +0 -34
  129. package/dist/decorators/Routes.d.ts +0 -15
  130. package/dist/decorators/Routes.js +0 -21
  131. package/dist/decorators/Scope.d.ts +0 -6
  132. package/dist/decorators/Scope.js +0 -25
  133. package/dist/decorators/Transform.d.ts +0 -14
  134. package/dist/decorators/Transform.js +0 -18
  135. package/dist/lib/openapi/collectors/param.collector.d.ts +0 -2
  136. package/dist/lib/openapi/collectors/param.collector.js +0 -64
  137. package/dist/lib/openapi/decorators/api-bearer-auth.decorator.d.ts +0 -2
  138. package/dist/lib/openapi/decorators/api-bearer-auth.decorator.js +0 -10
  139. package/dist/lib/openapi/decorators/api-method.decorator.d.ts +0 -3
  140. package/dist/lib/openapi/decorators/api-method.decorator.js +0 -11
  141. package/dist/lib/openapi/decorators/api-parameter.decorator.d.ts +0 -3
  142. package/dist/lib/openapi/decorators/api-parameter.decorator.js +0 -10
  143. package/dist/lib/openapi/decorators/api-request-body.decorator.d.ts +0 -3
  144. package/dist/lib/openapi/decorators/api-request-body.decorator.js +0 -10
  145. package/dist/lib/openapi/decorators/api-response.decorator.d.ts +0 -3
  146. package/dist/lib/openapi/decorators/api-response.decorator.js +0 -10
  147. package/dist/lib/openapi/decorators/api-security.decorator.d.ts +0 -3
  148. package/dist/lib/openapi/decorators/api-security.decorator.js +0 -10
  149. package/dist/lib/openapi/decorators/api-tag.decorator.d.ts +0 -3
  150. package/dist/lib/openapi/decorators/api-tag.decorator.js +0 -13
  151. package/dist/lib/openapi/decorators/index.d.ts +0 -7
  152. package/dist/lib/openapi/decorators/index.js +0 -23
  153. package/dist/lib/openapi/helpers/index.d.ts +0 -7
  154. package/dist/lib/openapi/helpers/method.helper.d.ts +0 -3
  155. package/dist/lib/openapi/helpers/method.helper.js +0 -20
  156. package/dist/lib/openapi/helpers/openapi.helper.d.ts +0 -7
  157. package/dist/lib/openapi/helpers/openapi.helper.js +0 -51
  158. package/dist/lib/openapi/helpers/parameter.helper.d.ts +0 -3
  159. package/dist/lib/openapi/helpers/parameter.helper.js +0 -16
  160. package/dist/lib/openapi/helpers/request-body.helper.d.ts +0 -3
  161. package/dist/lib/openapi/helpers/request-body.helper.js +0 -9
  162. package/dist/lib/openapi/helpers/response.helper.d.ts +0 -3
  163. package/dist/lib/openapi/helpers/response.helper.js +0 -18
  164. package/dist/lib/openapi/helpers/security.helper.d.ts +0 -3
  165. package/dist/lib/openapi/helpers/security.helper.js +0 -17
  166. package/dist/lib/openapi/helpers/tag.helper.d.ts +0 -3
  167. package/dist/lib/openapi/helpers/tag.helper.js +0 -10
  168. package/dist/stores/index.d.ts +0 -1
  169. package/vitest.json +0 -0
  170. /package/dist/{stores → __internals/stores}/scope.store.js +0 -0
  171. /package/dist/__internals/stores/{service.store.d.ts → serivces.store.d.ts} +0 -0
  172. /package/dist/__internals/stores/{service.store.js → serivces.store.js} +0 -0
  173. /package/dist/{decorators → lib/server/decorators}/types.js +0 -0
  174. /package/dist/{exeptions → lib/server/exeptions}/DuplicateControllerPathException.d.ts +0 -0
  175. /package/dist/{exeptions → lib/server/exeptions}/DuplicateControllerPathException.js +0 -0
  176. /package/dist/{exeptions → lib/server/exeptions}/DuplicatedException.d.ts +0 -0
  177. /package/dist/{exeptions → lib/server/exeptions}/DuplicatedException.js +0 -0
  178. /package/dist/{exeptions → lib/server/exeptions}/DuplicatedHandlerException.d.ts +0 -0
  179. /package/dist/{exeptions → lib/server/exeptions}/DuplicatedHandlerException.js +0 -0
  180. /package/dist/{exeptions → lib/server/exeptions}/HyperFileException.d.ts +0 -0
  181. /package/dist/{exeptions → lib/server/exeptions}/MethodNotFountException.d.ts +0 -0
  182. /package/dist/{exeptions → lib/server/exeptions}/MethodNotFountException.js +0 -0
  183. /package/dist/{exeptions → lib/server/exeptions}/NotPropertyException.d.ts +0 -0
  184. /package/dist/{exeptions → lib/server/exeptions}/NotPropertyException.js +0 -0
  185. /package/dist/{exeptions → lib/server/exeptions}/NotRoleException.d.ts +0 -0
  186. /package/dist/{exeptions → lib/server/exeptions}/NotScopeException.d.ts +0 -0
  187. /package/dist/{exeptions → lib/server/exeptions}/WrongPlaceException.d.ts +0 -0
  188. /package/dist/{exeptions → lib/server/exeptions}/WrongPlaceException.js +0 -0
  189. /package/dist/{exeptions → lib/server/exeptions}/index.d.ts +0 -0
  190. /package/dist/{exeptions → lib/server/exeptions}/index.js +0 -0
  191. /package/dist/{exeptions → lib/server/exeptions}/types.d.ts +0 -0
  192. /package/dist/{exeptions → lib/server/exeptions}/types.js +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,156 @@
1
- # Hyper Express Decorators
2
- A simple decorators library for Hyper Express
1
+ # @zenofolio/hyper-decor
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
82
-
83
- This package extends the `hyper-express/Request` class by adding methods that help manage roles and scopes for requests.
24
+ ---
84
25
 
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
+ }
134
54
 
135
- @Get("/list")
136
- async index(@Query() query: any, @Res() res: Response) {
137
- res.send("hello");
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 };
138
59
  }
139
60
 
61
+ // 3. Extracción de propiedad anidada con DTO
62
+ @Post("/settings")
63
+ async updateSettings(@Body("settings", SettingsDto) data: SettingsDto) {
64
+ return data;
65
+ }
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
+ ## OpenAPI y DTOs
178
97
 
179
- - `/api/users/v1/list`
98
+ Es posible utilizar clases para definir los esquemas de datos que se reflejarán en la documentación OpenAPI generada.
180
99
 
100
+ ```typescript
101
+ class CreateUserDto {
102
+ age: number;
103
+ name: string;
104
+ }
181
105
 
182
- # Examples
106
+ @Post("/")
107
+ async create(@Body(CreateUserDto) data: CreateUserDto) { ... }
108
+ ```
183
109
 
184
- - [Add Roles and scopes](./examples/add-roles-and-scopes.ts)
185
- - [Middleware](./examples/middleware.ts)
186
- - [File](./examples//upload-file.ts)
110
+ ---
187
111
 
188
- ## Services & Dependency Injection
189
- You can use `@HyperService()` with `tsyringe` to inject dependencies into controllers or other services.
112
+ ## Testing
190
113
 
191
- ```typescript
192
- import { injectable } from "tsyringe";
114
+ `@zenofolio/hyper-decor` incluye una utilidad potente y fácil de usar inspirada en NestJS para facilitar el testing de servicios, módulos y controladores.
193
115
 
194
- @injectable()
195
- @HyperService()
196
- class UserService {
197
- getUsers() { return ["User1", "User2"]; }
198
- }
116
+ ### HyperTest
117
+ La clase `HyperTest` permite crear entornos de prueba aislados con soporte completo para el ciclo de vida `onInit` de forma recursiva.
199
118
 
200
- @HyperController("/users")
201
- class UserController {
202
- constructor(private userService: UserService) {}
119
+ #### 1. Bootstrap de una línea (Simplicidad total)
120
+ Ideal para pruebas rápidas de integración de una aplicación, módulo o servicio.
121
+ ```typescript
122
+ import { HyperTest } from "@zenofolio/hyper-decor";
203
123
 
204
- @Get("/")
205
- getUsers(@Res() res: Response) {
206
- res.json(this.userService.getUsers());
207
- }
208
- }
124
+ const module = await HyperTest.create(AppModule);
125
+ const service = await module.get(MyService);
209
126
  ```
210
127
 
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
-
128
+ #### 2. Sobrescritura de Proveedores (Mocks)
129
+ Puedes reemplazar dependencias fácilmente usando el API de construcción (builder).
214
130
  ```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
131
+ const module = await HyperTest.createTestingModule({
132
+ imports: [AppModule]
133
+ })
134
+ .overrideProvider(AuthService).useValue(mockAuth)
135
+ .compile();
232
136
 
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
- }
137
+ const service = module.get(AuthService);
138
+ const app = await module.createHyperApplication();
241
139
  ```
242
140
 
243
- ## OpenAPI Generation
244
- Generate a complete OpenAPI specification out-of-the-box leveraging your application tree and decorators footprint.
141
+ #### 3. Soporte para Clases Abstractas e Inyección Profunda
142
+ El sistema soporta la resolución de implementaciones a través de clases abstractas como tokens y garantiza que todo el árbol de dependencias ejecute su `onInit` antes de comenzar la prueba.
245
143
 
144
+ ### Reset del Contenedor
145
+ Para evitar la persistencia de instancias entre tests, `HyperTest` proporciona una utilidad de limpieza.
246
146
  ```typescript
247
- import { getOpenAPI } from "@zenofolio/hyper-decor/lib/openapi";
248
-
249
- const openApiDoc = getOpenAPI(Application);
250
- console.log(openApiDoc.info.title, openApiDoc.paths);
147
+ beforeEach(() => {
148
+ HyperTest.reset();
149
+ });
251
150
  ```
252
151
 
253
- # All for now
254
- More documentation will be added here late.
152
+ ---
153
+
154
+ ## Licencia
155
+
156
+ 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,5 +1,4 @@
1
- import "reflect-metadata";
2
- type MetadataKey = string | symbol;
1
+ import { HyperCommonMetadata } from "../types";
3
2
  type MergeOptions = {
4
3
  overwriteArrays?: boolean;
5
4
  };
@@ -10,5 +9,5 @@ type MergeOptions = {
10
9
  * @param keys Metadata keys to merge.
11
10
  * @param options Merge options (e.g., array handling).
12
11
  */
13
- export declare function mergeMetadata(target: any, source: any, keys: MetadataKey[], options?: MergeOptions): void;
12
+ export declare function mergeMetadata(target: object, source: object, keys: (keyof HyperCommonMetadata)[], options?: MergeOptions): void;
14
13
  export {};