@navios/core 1.1.0 → 2.0.0-alpha.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.
Files changed (241) hide show
  1. package/CHANGELOG.md +53 -11
  2. package/README.md +67 -220
  3. package/lib/async-context-6pdlnNLA.d.mts +237 -0
  4. package/lib/async-context-6pdlnNLA.d.mts.map +1 -0
  5. package/lib/async-context-Dqk7pE-D.d.cts +237 -0
  6. package/lib/async-context-Dqk7pE-D.d.cts.map +1 -0
  7. package/lib/attribute-factory-B3VuYnp7.d.cts +70 -0
  8. package/lib/attribute-factory-B3VuYnp7.d.cts.map +1 -0
  9. package/lib/attribute-factory-mKOXoVnV.d.mts +70 -0
  10. package/lib/attribute-factory-mKOXoVnV.d.mts.map +1 -0
  11. package/lib/attribute-value-CjX9ZkLq.cjs +172 -0
  12. package/lib/attribute-value-CjX9ZkLq.cjs.map +1 -0
  13. package/lib/attribute-value-DMEA255r.mjs +119 -0
  14. package/lib/attribute-value-DMEA255r.mjs.map +1 -0
  15. package/lib/basic-execution-context-CeGuhMOz.mjs +246 -0
  16. package/lib/basic-execution-context-CeGuhMOz.mjs.map +1 -0
  17. package/lib/basic-execution-context-DSk5MNtc.cjs +281 -0
  18. package/lib/basic-execution-context-DSk5MNtc.cjs.map +1 -0
  19. package/lib/execution-context-BPD3FeFb.d.mts +71 -0
  20. package/lib/execution-context-BPD3FeFb.d.mts.map +1 -0
  21. package/lib/execution-context-BTJdHhbf.d.cts +71 -0
  22. package/lib/execution-context-BTJdHhbf.d.cts.map +1 -0
  23. package/lib/execution-context-token-BXUKB2hf.cjs +112 -0
  24. package/lib/execution-context-token-BXUKB2hf.cjs.map +1 -0
  25. package/lib/execution-context-token-CrXmTvk2.mjs +77 -0
  26. package/lib/execution-context-token-CrXmTvk2.mjs.map +1 -0
  27. package/lib/index.cjs +1687 -4424
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +838 -3
  30. package/lib/index.d.cts.map +1 -0
  31. package/lib/index.d.mts +838 -3
  32. package/lib/index.d.mts.map +1 -0
  33. package/lib/index.mjs +1573 -4219
  34. package/lib/index.mjs.map +1 -1
  35. package/lib/legacy-compat/index.cjs +72 -371
  36. package/lib/legacy-compat/index.cjs.map +1 -1
  37. package/lib/legacy-compat/index.d.cts +42 -382
  38. package/lib/legacy-compat/index.d.cts.map +1 -1
  39. package/lib/legacy-compat/index.d.mts +41 -382
  40. package/lib/legacy-compat/index.d.mts.map +1 -1
  41. package/lib/legacy-compat/index.mjs +51 -345
  42. package/lib/legacy-compat/index.mjs.map +1 -1
  43. package/lib/module-Bha7GER_.mjs +135 -0
  44. package/lib/module-Bha7GER_.mjs.map +1 -0
  45. package/lib/module-DZewk_2r.cjs +164 -0
  46. package/lib/module-DZewk_2r.cjs.map +1 -0
  47. package/lib/module-graph-DCP9MHG0.cjs +147 -0
  48. package/lib/module-graph-DCP9MHG0.cjs.map +1 -0
  49. package/lib/module-graph-xvVEykFM.mjs +142 -0
  50. package/lib/module-graph-xvVEykFM.mjs.map +1 -0
  51. package/lib/module-metadata-C8S92seK.cjs +95 -0
  52. package/lib/module-metadata-C8S92seK.cjs.map +1 -0
  53. package/lib/module-metadata-k3RTt20x.mjs +66 -0
  54. package/lib/module-metadata-k3RTt20x.mjs.map +1 -0
  55. package/lib/module-options-Dmse0gii.d.mts +51 -0
  56. package/lib/module-options-Dmse0gii.d.mts.map +1 -0
  57. package/lib/module-options-IuDO-p8u.d.cts +51 -0
  58. package/lib/module-options-IuDO-p8u.d.cts.map +1 -0
  59. package/lib/testing/index.cjs +96 -414
  60. package/lib/testing/index.cjs.map +1 -1
  61. package/lib/testing/index.d.cts +25 -385
  62. package/lib/testing/index.d.cts.map +1 -1
  63. package/lib/testing/index.d.mts +24 -385
  64. package/lib/testing/index.d.mts.map +1 -1
  65. package/lib/testing/index.mjs +94 -408
  66. package/lib/testing/index.mjs.map +1 -1
  67. package/lib/transport.cjs +25 -0
  68. package/lib/transport.d.cts +190 -0
  69. package/lib/transport.d.cts.map +1 -0
  70. package/lib/transport.d.mts +190 -0
  71. package/lib/transport.d.mts.map +1 -0
  72. package/lib/transport.mjs +7 -0
  73. package/package.json +37 -17
  74. package/docs/README.md +0 -316
  75. package/docs/adapters.md +0 -308
  76. package/docs/application-setup.md +0 -524
  77. package/docs/attributes.md +0 -689
  78. package/docs/controllers.md +0 -373
  79. package/docs/endpoints.md +0 -444
  80. package/docs/exceptions.md +0 -352
  81. package/docs/guards.md +0 -550
  82. package/docs/legacy-compat.md +0 -356
  83. package/docs/modules.md +0 -377
  84. package/docs/quick-start.md +0 -290
  85. package/docs/services.md +0 -427
  86. package/docs/testing.md +0 -827
  87. package/lib/index-3LcTrbxz.d.mts +0 -3804
  88. package/lib/index-3LcTrbxz.d.mts.map +0 -1
  89. package/lib/index-B14SekVb.d.cts +0 -3804
  90. package/lib/index-B14SekVb.d.cts.map +0 -1
  91. package/lib/navios.factory-CUrO_p6K.cjs +0 -4538
  92. package/lib/navios.factory-CUrO_p6K.cjs.map +0 -1
  93. package/lib/navios.factory-DjUOOVVL.mjs +0 -4151
  94. package/lib/navios.factory-DjUOOVVL.mjs.map +0 -1
  95. package/lib/tokens-BEuBMGGX.cjs +0 -193
  96. package/lib/tokens-BEuBMGGX.cjs.map +0 -1
  97. package/lib/tokens-COyNGV1I.mjs +0 -97
  98. package/lib/tokens-COyNGV1I.mjs.map +0 -1
  99. package/lib/use-guards.decorator-DLmRl2CV.mjs +0 -336
  100. package/lib/use-guards.decorator-DLmRl2CV.mjs.map +0 -1
  101. package/lib/use-guards.decorator-DhumFTk3.cjs +0 -444
  102. package/lib/use-guards.decorator-DhumFTk3.cjs.map +0 -1
  103. package/project.json +0 -66
  104. package/src/__tests__/attribute.factory.spec.mts +0 -300
  105. package/src/__tests__/config.service.spec.mts +0 -43
  106. package/src/__tests__/console-logger.service.spec.mts +0 -312
  107. package/src/__tests__/controller-resolver.spec.mts +0 -229
  108. package/src/__tests__/controller.spec.mts +0 -58
  109. package/src/__tests__/guard-runner.service.spec.mts +0 -399
  110. package/src/__tests__/logger.service.spec.mts +0 -147
  111. package/src/__tests__/responders.spec.mts +0 -340
  112. package/src/__tests__/testing-module.spec.mts +0 -459
  113. package/src/__tests__/unit-testing-module.spec.mts +0 -424
  114. package/src/attribute.factory.mts +0 -325
  115. package/src/config/config-service.interface.mts +0 -47
  116. package/src/config/config.provider.mts +0 -69
  117. package/src/config/config.service.mts +0 -176
  118. package/src/config/index.mts +0 -5
  119. package/src/config/types.mts +0 -58
  120. package/src/config/utils/helpers.mts +0 -23
  121. package/src/config/utils/index.mts +0 -1
  122. package/src/decorators/controller.decorator.mts +0 -81
  123. package/src/decorators/endpoint.decorator.mts +0 -181
  124. package/src/decorators/header.decorator.mts +0 -38
  125. package/src/decorators/http-code.decorator.mts +0 -38
  126. package/src/decorators/index.mts +0 -8
  127. package/src/decorators/module.decorator.mts +0 -106
  128. package/src/decorators/multipart.decorator.mts +0 -169
  129. package/src/decorators/stream.decorator.mts +0 -155
  130. package/src/decorators/use-guards.decorator.mts +0 -73
  131. package/src/exceptions/bad-request.exception.mts +0 -28
  132. package/src/exceptions/conflict.exception.mts +0 -31
  133. package/src/exceptions/forbidden.exception.mts +0 -30
  134. package/src/exceptions/http.exception.mts +0 -33
  135. package/src/exceptions/index.mts +0 -7
  136. package/src/exceptions/internal-server-error.exception.mts +0 -33
  137. package/src/exceptions/not-found.exception.mts +0 -33
  138. package/src/exceptions/unauthorized.exception.mts +0 -30
  139. package/src/factories/adapter.factory.mts +0 -20
  140. package/src/factories/endpoint-adapter.factory.mts +0 -21
  141. package/src/factories/http-adapter.factory.mts +0 -20
  142. package/src/factories/index.mts +0 -8
  143. package/src/factories/multipart-adapter.factory.mts +0 -21
  144. package/src/factories/reply.factory.mts +0 -21
  145. package/src/factories/request.factory.mts +0 -21
  146. package/src/factories/stream-adapter.factory.mts +0 -20
  147. package/src/factories/xml-stream-adapter.factory.mts +0 -20
  148. package/src/index.mts +0 -16
  149. package/src/interfaces/abstract-adapter.interface.mts +0 -32
  150. package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
  151. package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
  152. package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
  153. package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
  154. package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
  155. package/src/interfaces/adapter-environment.interface.mts +0 -74
  156. package/src/interfaces/can-activate.mts +0 -38
  157. package/src/interfaces/http-header.mts +0 -18
  158. package/src/interfaces/index.mts +0 -14
  159. package/src/interfaces/navios-module.mts +0 -28
  160. package/src/interfaces/plugin-context.mts +0 -104
  161. package/src/interfaces/plugin-stage.mts +0 -62
  162. package/src/interfaces/plugin.interface.mts +0 -119
  163. package/src/interfaces/staged-plugin.interface.mts +0 -209
  164. package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
  165. package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
  166. package/src/legacy-compat/attribute.factory.mts +0 -351
  167. package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
  168. package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
  169. package/src/legacy-compat/decorators/header.decorator.mts +0 -43
  170. package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
  171. package/src/legacy-compat/decorators/index.mts +0 -11
  172. package/src/legacy-compat/decorators/module.decorator.mts +0 -37
  173. package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
  174. package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
  175. package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
  176. package/src/legacy-compat/index.mts +0 -57
  177. package/src/logger/README.md +0 -3
  178. package/src/logger/console-logger.service.mts +0 -714
  179. package/src/logger/index.mts +0 -6
  180. package/src/logger/log-levels.mts +0 -21
  181. package/src/logger/logger-service.interface.mts +0 -42
  182. package/src/logger/logger.service.mts +0 -113
  183. package/src/logger/logger.tokens.mts +0 -44
  184. package/src/logger/utils/cli-colors.util.mts +0 -17
  185. package/src/logger/utils/filter-log-levelts.util.mts +0 -29
  186. package/src/logger/utils/index.mts +0 -5
  187. package/src/logger/utils/is-log-level-enabled.mts +0 -33
  188. package/src/logger/utils/is-log-level.util.mts +0 -10
  189. package/src/logger/utils/shared.utils.mts +0 -51
  190. package/src/metadata/controller.metadata.mts +0 -79
  191. package/src/metadata/handler.metadata.mts +0 -80
  192. package/src/metadata/index.mts +0 -4
  193. package/src/metadata/module.metadata.mts +0 -116
  194. package/src/metadata/navios-managed.metadata.mts +0 -42
  195. package/src/navios.application.mts +0 -678
  196. package/src/navios.environment.mts +0 -42
  197. package/src/navios.factory.mts +0 -158
  198. package/src/responders/enums/framework-error.enum.mts +0 -38
  199. package/src/responders/enums/index.mts +0 -1
  200. package/src/responders/index.mts +0 -4
  201. package/src/responders/interfaces/error-responder.interface.mts +0 -42
  202. package/src/responders/interfaces/error-response.interface.mts +0 -22
  203. package/src/responders/interfaces/index.mts +0 -3
  204. package/src/responders/interfaces/problem-details.interface.mts +0 -34
  205. package/src/responders/services/error-response-producer.service.mts +0 -143
  206. package/src/responders/services/forbidden-responder.service.mts +0 -77
  207. package/src/responders/services/index.mts +0 -5
  208. package/src/responders/services/internal-server-error-responder.service.mts +0 -57
  209. package/src/responders/services/not-found-responder.service.mts +0 -76
  210. package/src/responders/services/validation-error-responder.service.mts +0 -78
  211. package/src/responders/tokens/index.mts +0 -1
  212. package/src/responders/tokens/responder.tokens.mts +0 -84
  213. package/src/services/abstract-handler-adapter.service.mts +0 -366
  214. package/src/services/guard-runner.service.mts +0 -152
  215. package/src/services/index.mts +0 -4
  216. package/src/services/instance-resolver.service.mts +0 -177
  217. package/src/services/module-loader.service.mts +0 -255
  218. package/src/stores/index.mts +0 -1
  219. package/src/stores/request-id.store.mts +0 -85
  220. package/src/testing/index.mts +0 -3
  221. package/src/testing/testing-module.mts +0 -393
  222. package/src/testing/unit-testing-module.mts +0 -298
  223. package/src/tokens/adapter.token.mts +0 -6
  224. package/src/tokens/endpoint-adapter.token.mts +0 -8
  225. package/src/tokens/execution-context.token.mts +0 -9
  226. package/src/tokens/http-adapter.token.mts +0 -8
  227. package/src/tokens/index.mts +0 -10
  228. package/src/tokens/multipart-adapter.token.mts +0 -8
  229. package/src/tokens/navios-options.token.mts +0 -6
  230. package/src/tokens/reply.token.mts +0 -3
  231. package/src/tokens/request.token.mts +0 -3
  232. package/src/tokens/stream-adapter.token.mts +0 -8
  233. package/src/tokens/xml-stream-adapter.token.mts +0 -8
  234. package/src/utils/adapter-supports.util.mts +0 -47
  235. package/src/utils/define-plugin.mts +0 -251
  236. package/src/utils/index.mts +0 -2
  237. package/tsconfig.json +0 -21
  238. package/tsconfig.lib.json +0 -8
  239. package/tsconfig.spec.json +0 -15
  240. package/tsdown.config.mts +0 -35
  241. package/vitest.config.mts +0 -15
@@ -1,356 +0,0 @@
1
- # Legacy-Compatible Decorators
2
-
3
- Navios provides a legacy-compatible decorator API for projects that cannot use Stage 3 decorators (the standard decorator proposal). These decorators use the TypeScript experimental decorator API and convert the arguments to Stage 3 format internally.
4
-
5
- ## Overview
6
-
7
- The legacy-compat decorators are located in `@navios/core/legacy-compat` and provide the same functionality as the standard decorators, but with compatibility for TypeScript's experimental decorator system.
8
-
9
- ## When to Use Legacy-Compatible Decorators
10
-
11
- Use legacy-compatible decorators if:
12
-
13
- - Your project uses TypeScript with `experimentalDecorators` enabled
14
- - You cannot migrate to Stage 3 decorators due to tooling or compatibility constraints
15
- - You need to maintain compatibility with older TypeScript versions or build tools
16
-
17
- ## Installation and Setup
18
-
19
- No additional installation is required. The legacy-compat decorators are included in `@navios/core`.
20
-
21
- To use legacy-compatible decorators, import them from the `legacy-compat` subpath:
22
-
23
- ```typescript
24
- import {
25
- Controller,
26
- Endpoint,
27
- Header,
28
- HttpCode,
29
- Module,
30
- Multipart,
31
- Stream,
32
- UseGuards,
33
- } from '@navios/core/legacy-compat'
34
- ```
35
-
36
- ## Available Decorators
37
-
38
- All standard Navios decorators are available in legacy-compatible form:
39
-
40
- ### Class Decorators
41
-
42
- #### `@Module(options?)`
43
-
44
- Defines an application module. Can be applied to classes.
45
-
46
- ```typescript
47
- import { Module } from '@navios/core/legacy-compat'
48
-
49
- @Module({
50
- controllers: [UserController, AuthController],
51
- imports: [DatabaseModule],
52
- guards: [AuthGuard],
53
- })
54
- export class AppModule {}
55
- ```
56
-
57
- #### `@Controller(options?)`
58
-
59
- Defines a request controller. Can be applied to classes.
60
-
61
- ```typescript
62
- import { Controller } from '@navios/core/legacy-compat'
63
-
64
- @Controller({ guards: [AuthGuard] })
65
- export class UserController {
66
- // ...
67
- }
68
- ```
69
-
70
- ### Method Decorators
71
-
72
- #### `@Endpoint(endpoint)`
73
-
74
- Defines an HTTP endpoint with type-safe request/response schemas. Must be applied to methods.
75
-
76
- ```typescript
77
- import type { EndpointParams, EndpointResult } from '@navios/core/legacy-compat'
78
-
79
- import { Controller, Endpoint } from '@navios/core/legacy-compat'
80
-
81
- @Controller()
82
- export class UserController {
83
- @Endpoint(getUserEndpoint)
84
- async getUser(
85
- request: EndpointParams<typeof getUserEndpoint>,
86
- ): Promise<EndpointResult<typeof getUserEndpoint>> {
87
- const { id } = request
88
- return { id, name: 'John Doe' }
89
- }
90
- }
91
- ```
92
-
93
- #### `@Multipart(endpoint)`
94
-
95
- Defines a multipart/form-data endpoint for file uploads. Must be applied to methods.
96
-
97
- ```typescript
98
- import type {
99
- MultipartParams,
100
- MultipartResult,
101
- } from '@navios/core/legacy-compat'
102
-
103
- import { Controller, Multipart } from '@navios/core/legacy-compat'
104
-
105
- @Controller()
106
- export class FileController {
107
- @Multipart(uploadFileEndpoint)
108
- async uploadFile(
109
- request: MultipartParams<typeof uploadFileEndpoint>,
110
- ): Promise<MultipartResult<typeof uploadFileEndpoint>> {
111
- const { file } = request.data
112
- return { url: 'https://example.com/file.jpg' }
113
- }
114
- }
115
- ```
116
-
117
- #### `@Stream(endpoint)`
118
-
119
- Defines a streaming endpoint. Must be applied to methods.
120
-
121
- ```typescript
122
- import type { StreamParams } from '@navios/core/legacy-compat'
123
-
124
- import { Controller, Stream } from '@navios/core/legacy-compat'
125
-
126
- @Controller()
127
- export class FileController {
128
- @Stream(downloadFileEndpoint)
129
- async downloadFile(
130
- request: StreamParams<typeof downloadFileEndpoint>,
131
- reply: any,
132
- ): Promise<void> {
133
- const { fileId } = request.urlParams
134
- // Stream file data to reply
135
- }
136
- }
137
- ```
138
-
139
- #### `@UseGuards(...guards)`
140
-
141
- Applies guards to controllers or endpoints. Can be applied to classes or methods.
142
-
143
- ```typescript
144
- import { Controller, Endpoint, UseGuards } from '@navios/core/legacy-compat'
145
-
146
- // Apply to a controller
147
- @Controller()
148
- @UseGuards(AuthGuard, RoleGuard)
149
- export class UserController {
150
- // All endpoints in this controller will use AuthGuard and RoleGuard
151
- }
152
-
153
- // Apply to a specific endpoint
154
- @Controller()
155
- export class UserController {
156
- @Endpoint(getUserEndpoint)
157
- @UseGuards(AuthGuard)
158
- async getUser() {
159
- // Only this endpoint uses AuthGuard
160
- }
161
- }
162
- ```
163
-
164
- #### `@Header(name, value)`
165
-
166
- Sets custom response headers. Must be applied to methods.
167
-
168
- ```typescript
169
- import { Controller, Endpoint, Header } from '@navios/core/legacy-compat'
170
-
171
- @Controller()
172
- export class UserController {
173
- @Endpoint(getUserEndpoint)
174
- @Header('Cache-Control', 'max-age=3600')
175
- async getUser() {
176
- return { id: '1', name: 'John' }
177
- }
178
- }
179
- ```
180
-
181
- #### `@HttpCode(code)`
182
-
183
- Sets a custom HTTP status code for the response. Must be applied to methods.
184
-
185
- ```typescript
186
- import { Controller, Endpoint, HttpCode } from '@navios/core/legacy-compat'
187
-
188
- @Controller()
189
- export class UserController {
190
- @Endpoint(createUserEndpoint)
191
- @HttpCode(201)
192
- async createUser() {
193
- return { id: '1', name: 'John' }
194
- }
195
- }
196
- ```
197
-
198
- ## Type Utilities
199
-
200
- The legacy-compat module also exports type utilities for working with endpoints:
201
-
202
- ```typescript
203
- import type {
204
- ControllerOptions,
205
- EndpointParams,
206
- EndpointResult,
207
- ModuleOptions,
208
- MultipartParams,
209
- MultipartResult,
210
- StreamParams,
211
- } from '@navios/core/legacy-compat'
212
- ```
213
-
214
- ## Complete Example
215
-
216
- Here's a complete example using legacy-compatible decorators:
217
-
218
- ```typescript
219
- import type { EndpointParams, EndpointResult } from '@navios/core/legacy-compat'
220
-
221
- import { builder } from '@navios/builder'
222
- import { inject, Injectable } from '@navios/core'
223
- import {
224
- Controller,
225
- Endpoint,
226
- HttpCode,
227
- Module,
228
- UseGuards,
229
- } from '@navios/core/legacy-compat'
230
-
231
- import { z } from 'zod/v4'
232
-
233
- // Define API endpoints
234
- const api = builder()
235
-
236
- const getUserEndpoint = api.declareEndpoint({
237
- method: 'get',
238
- url: '/users/:id',
239
- responseSchema: z.object({
240
- id: z.string(),
241
- name: z.string(),
242
- email: z.string().email(),
243
- }),
244
- })
245
-
246
- const createUserEndpoint = api.declareEndpoint({
247
- method: 'post',
248
- url: '/users',
249
- requestSchema: z.object({
250
- name: z.string(),
251
- email: z.string().email(),
252
- }),
253
- responseSchema: z.object({
254
- id: z.string(),
255
- name: z.string(),
256
- email: z.string().email(),
257
- }),
258
- })
259
-
260
- // Service
261
- @Injectable()
262
- export class UserService {
263
- async findById(id: string) {
264
- // Implementation
265
- }
266
-
267
- async create(data: { name: string; email: string }) {
268
- // Implementation
269
- }
270
- }
271
-
272
- // Controller
273
- @Controller()
274
- @UseGuards(AuthGuard)
275
- export class UserController {
276
- userService = inject(UserService)
277
-
278
- @Endpoint(getUserEndpoint)
279
- async getUser(
280
- request: EndpointParams<typeof getUserEndpoint>,
281
- ): Promise<EndpointResult<typeof getUserEndpoint>> {
282
- const { id } = request.urlParams
283
- return await this.userService.findById(id)
284
- }
285
-
286
- @Endpoint(createUserEndpoint)
287
- @HttpCode(201)
288
- async createUser(
289
- request: EndpointParams<typeof createUserEndpoint>,
290
- ): Promise<EndpointResult<typeof createUserEndpoint>> {
291
- const { name, email } = request.body
292
- return await this.userService.create({ name, email })
293
- }
294
- }
295
-
296
- // Module
297
- @Module({
298
- controllers: [UserController],
299
- })
300
- export class AppModule {}
301
- ```
302
-
303
- ## Migration from Standard Decorators
304
-
305
- If you're migrating from standard decorators to legacy-compatible decorators:
306
-
307
- 1. Update your imports to use the `legacy-compat` subpath:
308
-
309
- ```typescript
310
- // Before
311
- import { Controller, Endpoint, Module } from '@navios/core'
312
- // After
313
- import { Controller, Endpoint, Module } from '@navios/core/legacy-compat'
314
- ```
315
-
316
- 2. Ensure your `tsconfig.json` has `experimentalDecorators` enabled:
317
-
318
- ```json
319
- {
320
- "compilerOptions": {
321
- "experimentalDecorators": true
322
- }
323
- }
324
- ```
325
-
326
- 3. The decorator usage remains the same - no changes to how you apply them.
327
-
328
- ## Differences from Standard Decorators
329
-
330
- The legacy-compatible decorators:
331
-
332
- - Use TypeScript's experimental decorator API instead of Stage 3 decorators
333
- - Convert decorator arguments internally to work with the standard Navios implementation
334
- - Provide the same functionality and type safety as standard decorators
335
- - May have slightly different type inference behavior in some edge cases
336
-
337
- ## TypeScript Configuration
338
-
339
- To use legacy-compatible decorators, ensure your `tsconfig.json` includes:
340
-
341
- ```json
342
- {
343
- "compilerOptions": {
344
- "experimentalDecorators": true,
345
- "emitDecoratorMetadata": true
346
- }
347
- }
348
- ```
349
-
350
- The `emitDecoratorMetadata` option is optional but recommended for better runtime behavior with dependency injection.
351
-
352
- ## Notes
353
-
354
- - Legacy-compatible decorators are fully compatible with all Navios features including guards, attributes, dependency injection, and adapters
355
- - You can mix legacy-compatible decorators with standard decorators in the same project, but it's recommended to use one approach consistently
356
- - The legacy-compat module is maintained alongside the standard decorators and receives the same updates and bug fixes
package/docs/modules.md DELETED
@@ -1,377 +0,0 @@
1
- # Modules
2
-
3
- Modules in Navios are the primary building blocks for organizing your application. They provide a way to group related controllers, services, and other providers into cohesive units that can be easily managed and imported.
4
-
5
- ## What is a Module?
6
-
7
- A module is a TypeScript class decorated with the `@Module()` decorator. It serves as a container for controllers, other modules, and shared guards. Modules help organize your application into logical boundaries and enable dependency injection across the application.
8
-
9
- ## Creating a Module
10
-
11
- ### Basic Module
12
-
13
- ```typescript
14
- import { Module } from '@navios/core'
15
-
16
- @Module()
17
- export class AppModule {}
18
- ```
19
-
20
- ### Module with Controllers
21
-
22
- ```typescript
23
- import { Module } from '@navios/core'
24
-
25
- import { ProductController } from './product.controller'
26
- import { UserController } from './user.controller'
27
-
28
- @Module({
29
- controllers: [UserController, ProductController],
30
- })
31
- export class AppModule {}
32
- ```
33
-
34
- ### Module with Imports
35
-
36
- ```typescript
37
- import { Module } from '@navios/core'
38
-
39
- import { AuthModule } from './auth/auth.module'
40
- import { UserModule } from './user/user.module'
41
-
42
- @Module({
43
- imports: [UserModule, AuthModule],
44
- })
45
- export class AppModule {}
46
- ```
47
-
48
- ### Module with Guards
49
-
50
- ```typescript
51
- import { Module } from '@navios/core'
52
-
53
- import { AuthGuard } from './auth.guard'
54
- import { UserController } from './user.controller'
55
-
56
- @Module({
57
- controllers: [UserController],
58
- guards: [AuthGuard], // Applied to all controllers in this module
59
- })
60
- export class UserModule {}
61
- ```
62
-
63
- ## Module Options
64
-
65
- The `@Module()` decorator accepts the following options:
66
-
67
- ### `controllers`
68
-
69
- - **Type**: `ClassType[] | Set<ClassType>`
70
- - **Description**: Array of controller classes that belong to this module
71
- - **Example**:
72
-
73
- ```typescript
74
- @Module({
75
- controllers: [UserController, PostController],
76
- })
77
- export class UserModule {}
78
- ```
79
-
80
- ### `imports`
81
-
82
- - **Type**: `ClassType[] | Set<ClassType>`
83
- - **Description**: Array of other modules to import into this module
84
- - **Example**:
85
-
86
- ```typescript
87
- @Module({
88
- imports: [DatabaseModule, AuthModule],
89
- })
90
- export class AppModule {}
91
- ```
92
-
93
- ### `guards`
94
-
95
- - **Type**: `ClassType[] | Set<ClassType>`
96
- - **Description**: Array of guard classes that will be applied to all controllers in this module
97
- - **Example**:
98
-
99
- ```typescript
100
- @Module({
101
- guards: [AuthGuard, RoleGuard],
102
- })
103
- export class ProtectedModule {}
104
- ```
105
-
106
- ## Module Lifecycle
107
-
108
- Modules in Navios follow a specific lifecycle:
109
-
110
- 1. **Registration**: Modules are registered with the dependency injection container
111
- 2. **Import Resolution**: Imported modules are loaded recursively
112
- 3. **Controller Registration**: Controllers are registered and their endpoints discovered
113
- 4. **Guard Application**: Module-level guards are applied to all controllers
114
- 5. **Initialization**: Module initialization hooks are called
115
-
116
- ## Module Lifecycle Methods
117
-
118
- ### `onModuleInit`
119
-
120
- The `onModuleInit` lifecycle method is called after the module has been initialized and all its dependencies have been resolved. This is useful for performing setup tasks, initializing connections, or running startup logic.
121
-
122
- #### Interface
123
-
124
- ```typescript
125
- interface NaviosModule {
126
- onModuleInit(): void | Promise<void>
127
- }
128
- ```
129
-
130
- #### Usage
131
-
132
- To use the `onModuleInit` lifecycle method, implement the `NaviosModule` interface in your module class:
133
-
134
- ```typescript
135
- import { Module, NaviosModule } from '@navios/core'
136
-
137
- @Module({
138
- controllers: [UserController],
139
- })
140
- export class UserModule implements NaviosModule {
141
- onModuleInit() {
142
- console.log('UserModule has been initialized')
143
- // Perform initialization logic here
144
- }
145
- }
146
- ```
147
-
148
- #### Async Initialization
149
-
150
- The `onModuleInit` method can be asynchronous, allowing you to perform async setup tasks:
151
-
152
- ```typescript
153
- import { Module, NaviosModule } from '@navios/core'
154
-
155
- @Module({
156
- controllers: [DatabaseController],
157
- })
158
- export class DatabaseModule implements NaviosModule {
159
- async onModuleInit() {
160
- console.log('Initializing database connection...')
161
- await this.connectToDatabase()
162
- console.log('Database connection established')
163
- }
164
-
165
- private async connectToDatabase() {
166
- // Database connection logic
167
- return new Promise((resolve) => setTimeout(resolve, 1000))
168
- }
169
- }
170
- ```
171
-
172
- #### Common Use Cases
173
-
174
- - **Database Connections**: Initialize database connections or verify connectivity
175
- - **Cache Warming**: Pre-populate caches with frequently accessed data
176
- - **External Service Setup**: Initialize connections to external APIs or services
177
- - **Configuration Validation**: Validate required configuration settings
178
- - **Background Tasks**: Start background processes or scheduled tasks
179
-
180
- ```typescript
181
- import { Module, NaviosModule } from '@navios/core'
182
-
183
- @Module({
184
- controllers: [CacheController],
185
- })
186
- export class CacheModule implements NaviosModule {
187
- private cache = new Map<string, any>()
188
-
189
- async onModuleInit() {
190
- // Warm up the cache with initial data
191
- await this.warmUpCache()
192
-
193
- // Validate configuration
194
- this.validateConfiguration()
195
-
196
- console.log('CacheModule initialized successfully')
197
- }
198
-
199
- private async warmUpCache() {
200
- // Pre-populate cache with frequently accessed data
201
- this.cache.set('app:config', await this.loadAppConfig())
202
- this.cache.set('user:defaults', await this.loadUserDefaults())
203
- }
204
-
205
- private validateConfiguration() {
206
- if (!process.env.CACHE_TTL) {
207
- throw new Error('CACHE_TTL environment variable is required')
208
- }
209
- }
210
-
211
- private async loadAppConfig() {
212
- // Load application configuration
213
- return { theme: 'dark', language: 'en' }
214
- }
215
-
216
- private async loadUserDefaults() {
217
- // Load default user settings
218
- return { notifications: true, theme: 'auto' }
219
- }
220
- }
221
- ```
222
-
223
- #### Execution Order
224
-
225
- The `onModuleInit` methods are called in dependency order:
226
-
227
- 1. **Imported modules first**: All imported modules' `onModuleInit` methods are called before the current module
228
- 2. **Current module last**: The current module's `onModuleInit` method is called after all its dependencies
229
-
230
- ```typescript
231
- @Module({
232
- imports: [DatabaseModule, CacheModule], // These initialize first
233
- })
234
- export class AppModule implements NaviosModule {
235
- onModuleInit() {
236
- // This runs after DatabaseModule and CacheModule have been initialized
237
- console.log('AppModule initialized - all dependencies are ready')
238
- }
239
- }
240
- ```
241
-
242
- ## Module Metadata
243
-
244
- Each module decorated with `@Module()` has associated metadata that Navios uses internally:
245
-
246
- ```typescript
247
- export interface ModuleMetadata {
248
- controllers: Set<ClassType>
249
- imports: Set<ClassType>
250
- guards: Set<ClassType>
251
- attributes: Map<symbol, unknown>
252
- }
253
- ```
254
-
255
- ## Best Practices
256
-
257
- ### 1. Feature-Based Organization
258
-
259
- Organize modules around business features rather than technical layers:
260
-
261
- ```typescript
262
- // ✅ Good - Feature-based
263
- @Module({
264
- controllers: [UserController],
265
- imports: [UserDatabaseModule],
266
- })
267
- export class UserModule {}
268
-
269
- // ❌ Avoid - Layer-based
270
- @Module({
271
- controllers: [UserController, ProductController, OrderController],
272
- })
273
- export class ControllersModule {}
274
- ```
275
-
276
- ### 2. Single Responsibility
277
-
278
- Each module should have a single, well-defined responsibility:
279
-
280
- ```typescript
281
- // ✅ Good - Single responsibility
282
- @Module({
283
- controllers: [AuthController],
284
- imports: [JwtModule],
285
- })
286
- export class AuthModule {}
287
-
288
- // ❌ Avoid - Multiple responsibilities
289
- @Module({
290
- controllers: [AuthController, UserController, ProductController],
291
- })
292
- export class EverythingModule {}
293
- ```
294
-
295
- ### 3. Explicit Dependencies
296
-
297
- Always explicitly import the modules you depend on:
298
-
299
- ```typescript
300
- // ✅ Good - Explicit imports
301
- @Module({
302
- imports: [AuthModule, DatabaseModule],
303
- controllers: [UserController],
304
- })
305
- export class UserModule {}
306
- ```
307
-
308
- ### 4. Module Composition
309
-
310
- Build complex applications by composing smaller, focused modules:
311
-
312
- ```typescript
313
- @Module({
314
- imports: [AuthModule, UserModule, ProductModule, OrderModule],
315
- })
316
- export class AppModule {}
317
- ```
318
-
319
- ## Advanced Usage
320
-
321
- ### Conditional Module Loading
322
-
323
- You can conditionally include modules based on environment or configuration:
324
-
325
- ```typescript
326
- import { Module } from '@navios/core'
327
-
328
- const imports = [CoreModule]
329
- if (process.env.NODE_ENV === 'development') {
330
- imports.push(DevToolsModule)
331
- }
332
-
333
- @Module({
334
- imports,
335
- controllers: [AppController],
336
- })
337
- export class AppModule {}
338
- ```
339
-
340
- ### Module with Complex Guard Setup
341
-
342
- ```typescript
343
- import { Module } from '@navios/core'
344
-
345
- import { AuthGuard, RoleGuard, ThrottleGuard } from './guards'
346
-
347
- @Module({
348
- guards: [
349
- AuthGuard, // Applied first
350
- RoleGuard, // Applied second
351
- ThrottleGuard, // Applied last
352
- ],
353
- controllers: [AdminController],
354
- })
355
- export class AdminModule {}
356
- ```
357
-
358
- ## Testing Modules
359
-
360
- When testing modules, you can create test-specific module configurations:
361
-
362
- ```typescript
363
- import { Module } from '@navios/core'
364
-
365
- import { MockUserService } from './mocks/user.service'
366
- import { UserController } from './user.controller'
367
-
368
- @Module({
369
- controllers: [UserController],
370
- // Use mock services for testing
371
- })
372
- export class TestUserModule {}
373
- ```
374
-
375
- ## Module Discovery
376
-
377
- Navios automatically discovers and registers modules through the module tree starting from your root application module.