@navios/core 1.0.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 (237) hide show
  1. package/CHANGELOG.md +97 -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 -4409
  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-C0Sg16Eb.d.cts +0 -3365
  88. package/lib/index-C0Sg16Eb.d.cts.map +0 -1
  89. package/lib/index-DySQ6Dpd.d.mts +0 -3365
  90. package/lib/index-DySQ6Dpd.d.mts.map +0 -1
  91. package/lib/navios.factory-CO5MB_OK.cjs +0 -4125
  92. package/lib/navios.factory-CO5MB_OK.cjs.map +0 -1
  93. package/lib/navios.factory-D6Y94P9B.mjs +0 -3828
  94. package/lib/navios.factory-D6Y94P9B.mjs.map +0 -1
  95. package/lib/tokens-4J9sredA.mjs +0 -100
  96. package/lib/tokens-4J9sredA.mjs.map +0 -1
  97. package/lib/tokens-CWw9kyeD.cjs +0 -196
  98. package/lib/tokens-CWw9kyeD.cjs.map +0 -1
  99. package/lib/use-guards.decorator-BecoQSmE.mjs +0 -339
  100. package/lib/use-guards.decorator-BecoQSmE.mjs.map +0 -1
  101. package/lib/use-guards.decorator-C4ml9XaT.cjs +0 -447
  102. package/lib/use-guards.decorator-C4ml9XaT.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 -11
  159. package/src/interfaces/navios-module.mts +0 -28
  160. package/src/interfaces/plugin.interface.mts +0 -139
  161. package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
  162. package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
  163. package/src/legacy-compat/attribute.factory.mts +0 -351
  164. package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
  165. package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
  166. package/src/legacy-compat/decorators/header.decorator.mts +0 -43
  167. package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
  168. package/src/legacy-compat/decorators/index.mts +0 -11
  169. package/src/legacy-compat/decorators/module.decorator.mts +0 -37
  170. package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
  171. package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
  172. package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
  173. package/src/legacy-compat/index.mts +0 -57
  174. package/src/logger/README.md +0 -3
  175. package/src/logger/console-logger.service.mts +0 -714
  176. package/src/logger/index.mts +0 -6
  177. package/src/logger/log-levels.mts +0 -21
  178. package/src/logger/logger-service.interface.mts +0 -42
  179. package/src/logger/logger.service.mts +0 -113
  180. package/src/logger/logger.tokens.mts +0 -44
  181. package/src/logger/utils/cli-colors.util.mts +0 -17
  182. package/src/logger/utils/filter-log-levelts.util.mts +0 -29
  183. package/src/logger/utils/index.mts +0 -5
  184. package/src/logger/utils/is-log-level-enabled.mts +0 -33
  185. package/src/logger/utils/is-log-level.util.mts +0 -10
  186. package/src/logger/utils/shared.utils.mts +0 -51
  187. package/src/metadata/controller.metadata.mts +0 -72
  188. package/src/metadata/handler.metadata.mts +0 -80
  189. package/src/metadata/index.mts +0 -4
  190. package/src/metadata/module.metadata.mts +0 -108
  191. package/src/metadata/navios-managed.metadata.mts +0 -42
  192. package/src/navios.application.mts +0 -484
  193. package/src/navios.environment.mts +0 -42
  194. package/src/navios.factory.mts +0 -158
  195. package/src/responders/enums/framework-error.enum.mts +0 -38
  196. package/src/responders/enums/index.mts +0 -1
  197. package/src/responders/index.mts +0 -4
  198. package/src/responders/interfaces/error-responder.interface.mts +0 -42
  199. package/src/responders/interfaces/error-response.interface.mts +0 -22
  200. package/src/responders/interfaces/index.mts +0 -3
  201. package/src/responders/interfaces/problem-details.interface.mts +0 -34
  202. package/src/responders/services/error-response-producer.service.mts +0 -143
  203. package/src/responders/services/forbidden-responder.service.mts +0 -77
  204. package/src/responders/services/index.mts +0 -5
  205. package/src/responders/services/internal-server-error-responder.service.mts +0 -57
  206. package/src/responders/services/not-found-responder.service.mts +0 -76
  207. package/src/responders/services/validation-error-responder.service.mts +0 -78
  208. package/src/responders/tokens/index.mts +0 -1
  209. package/src/responders/tokens/responder.tokens.mts +0 -84
  210. package/src/services/abstract-handler-adapter.service.mts +0 -366
  211. package/src/services/guard-runner.service.mts +0 -152
  212. package/src/services/index.mts +0 -4
  213. package/src/services/instance-resolver.service.mts +0 -177
  214. package/src/services/module-loader.service.mts +0 -252
  215. package/src/stores/index.mts +0 -1
  216. package/src/stores/request-id.store.mts +0 -85
  217. package/src/testing/index.mts +0 -3
  218. package/src/testing/testing-module.mts +0 -393
  219. package/src/testing/unit-testing-module.mts +0 -298
  220. package/src/tokens/adapter.token.mts +0 -6
  221. package/src/tokens/endpoint-adapter.token.mts +0 -8
  222. package/src/tokens/execution-context.token.mts +0 -9
  223. package/src/tokens/http-adapter.token.mts +0 -8
  224. package/src/tokens/index.mts +0 -10
  225. package/src/tokens/multipart-adapter.token.mts +0 -8
  226. package/src/tokens/navios-options.token.mts +0 -6
  227. package/src/tokens/reply.token.mts +0 -3
  228. package/src/tokens/request.token.mts +0 -3
  229. package/src/tokens/stream-adapter.token.mts +0 -8
  230. package/src/tokens/xml-stream-adapter.token.mts +0 -8
  231. package/src/utils/adapter-supports.util.mts +0 -47
  232. package/src/utils/index.mts +0 -1
  233. package/tsconfig.json +0 -21
  234. package/tsconfig.lib.json +0 -8
  235. package/tsconfig.spec.json +0 -15
  236. package/tsdown.config.mts +0 -35
  237. package/vitest.config.mts +0 -15
@@ -1,351 +0,0 @@
1
- import type { ClassType } from '@navios/di'
2
- import { createClassContext, createMethodContext } from '@navios/di/legacy-compat'
3
- import type { z, ZodType } from 'zod/v4'
4
-
5
- import type {
6
- ControllerMetadata,
7
- HandlerMetadata,
8
- ModuleMetadata,
9
- } from '../metadata/index.mjs'
10
-
11
- import {
12
- getControllerMetadata,
13
- getEndpointMetadata,
14
- getModuleMetadata,
15
- hasControllerMetadata,
16
- hasModuleMetadata,
17
- } from '../metadata/index.mjs'
18
- import {
19
- getManagedMetadata,
20
- hasManagedMetadata,
21
- } from '../metadata/navios-managed.metadata.mjs'
22
-
23
- /**
24
- * Type for a legacy class/method attribute decorator without a value.
25
- *
26
- * Attributes are custom metadata decorators that can be applied to modules,
27
- * controllers, and endpoints.
28
- */
29
- export type LegacyClassAttribute = {
30
- (): ClassDecorator & MethodDecorator
31
- token: symbol
32
- }
33
-
34
- /**
35
- * Type for a legacy class/method attribute decorator with a validated value.
36
- *
37
- * @typeParam S - The Zod schema type for validation
38
- */
39
- export type LegacyClassSchemaAttribute<S extends ZodType> = {
40
- (value: z.input<S>): ClassDecorator & MethodDecorator
41
- token: symbol
42
- schema: ZodType
43
- }
44
-
45
- /**
46
- * Legacy-compatible factory for creating custom attribute decorators.
47
- *
48
- * Works with TypeScript experimental decorators (legacy API).
49
- *
50
- * Attributes allow you to add custom metadata to modules, controllers, and endpoints.
51
- * This is useful for cross-cutting concerns like rate limiting, caching, API versioning, etc.
52
- *
53
- * @example
54
- * ```typescript
55
- * // Create a simple boolean attribute
56
- * const Public = LegacyAttributeFactory.createAttribute(Symbol.for('Public'))
57
- *
58
- * // Use it as a decorator
59
- * @Controller()
60
- * @Public()
61
- * export class PublicController { }
62
- *
63
- * // Check if attribute exists
64
- * if (LegacyAttributeFactory.has(Public, controllerMetadata)) {
65
- * // Skip authentication
66
- * }
67
- * ```
68
- *
69
- * @example
70
- * ```typescript
71
- * // Create an attribute with a validated value
72
- * const RateLimit = LegacyAttributeFactory.createAttribute(
73
- * Symbol.for('RateLimit'),
74
- * z.object({ requests: z.number(), window: z.number() })
75
- * )
76
- *
77
- * // Use it with a value
78
- * @Endpoint(apiEndpoint)
79
- * @RateLimit({ requests: 100, window: 60000 })
80
- * async handler() { }
81
- *
82
- * // Get the value
83
- * const limit = LegacyAttributeFactory.get(RateLimit, endpointMetadata)
84
- * // limit is typed as { requests: number, window: number } | null
85
- * ```
86
- */
87
- export class LegacyAttributeFactory {
88
- /**
89
- * Creates a simple attribute decorator without a value.
90
- *
91
- * @param token - A unique symbol to identify this attribute
92
- * @returns A decorator function that can be applied to classes or methods
93
- *
94
- * @example
95
- * ```typescript
96
- * const Public = LegacyAttributeFactory.createAttribute(Symbol.for('Public'))
97
- *
98
- * @Public()
99
- * @Controller()
100
- * export class PublicController { }
101
- * ```
102
- */
103
- static createAttribute(token: symbol): LegacyClassAttribute
104
- /**
105
- * Creates an attribute decorator with a validated value.
106
- *
107
- * @param token - A unique symbol to identify this attribute
108
- * @param schema - A Zod schema to validate the attribute value
109
- * @returns A decorator function that accepts a value and can be applied to classes or methods
110
- *
111
- * @example
112
- * ```typescript
113
- * const RateLimit = LegacyAttributeFactory.createAttribute(
114
- * Symbol.for('RateLimit'),
115
- * z.object({ requests: z.number(), window: z.number() })
116
- * )
117
- *
118
- * @RateLimit({ requests: 100, window: 60000 })
119
- * @Endpoint(apiEndpoint)
120
- * async handler() { }
121
- * ```
122
- */
123
- static createAttribute<T extends ZodType>(
124
- token: symbol,
125
- schema: T,
126
- ): LegacyClassSchemaAttribute<T>
127
-
128
- static createAttribute(token: symbol, schema?: ZodType) {
129
- const res = (value?: unknown) => {
130
- // Return a decorator that can handle both class and method targets
131
- function decorator(target: any): any
132
- function decorator(
133
- target: any,
134
- propertyKey: string | symbol,
135
- descriptor: PropertyDescriptor,
136
- ): PropertyDescriptor
137
- function decorator(
138
- target: any,
139
- propertyKey?: string | symbol,
140
- descriptor?: PropertyDescriptor,
141
- ): any {
142
- const isMethodDecorator =
143
- propertyKey !== undefined && descriptor !== undefined
144
-
145
- if (isMethodDecorator) {
146
- // Method decorator - apply to endpoint
147
- const context = createMethodContext(target, propertyKey, descriptor)
148
- const metadata = getEndpointMetadata(descriptor.value, context)
149
-
150
- if (schema) {
151
- const validatedValue = schema.safeParse(value)
152
- if (!validatedValue.success) {
153
- throw new Error(
154
- `[Navios] Invalid value for attribute ${token.toString()}: ${validatedValue.error}`,
155
- )
156
- }
157
- metadata.customAttributes.set(token, validatedValue.data)
158
- } else {
159
- metadata.customAttributes.set(token, true)
160
- }
161
- return descriptor
162
- } else {
163
- // Class decorator
164
- const isController = hasControllerMetadata(target as ClassType)
165
- const isModule = hasModuleMetadata(target as ClassType)
166
- const isManaged = hasManagedMetadata(target as ClassType)
167
-
168
- if (!isController && !isModule && !isManaged) {
169
- throw new Error(
170
- '[Navios] Attribute can only be applied to classes with @Controller, @Module, or other Navios-managed decorators',
171
- )
172
- }
173
-
174
- const context = createClassContext(target)
175
- const metadata = isController
176
- ? getControllerMetadata(target, context)
177
- : isModule
178
- ? getModuleMetadata(target, context)
179
- : isManaged
180
- ? getManagedMetadata(target)!
181
- : null
182
-
183
- if (!metadata) {
184
- throw new Error(
185
- '[Navios] Could not determine metadata for attribute target',
186
- )
187
- }
188
-
189
- if (schema) {
190
- const validatedValue = schema.safeParse(value)
191
- if (!validatedValue.success) {
192
- throw new Error(
193
- `[Navios] Invalid value for attribute ${token.toString()}: ${validatedValue.error}`,
194
- )
195
- }
196
- metadata.customAttributes.set(token, validatedValue.data)
197
- } else {
198
- metadata.customAttributes.set(token, true)
199
- }
200
- return target
201
- }
202
- }
203
- return decorator
204
- }
205
- res.token = token
206
- if (schema) {
207
- res.schema = schema
208
- }
209
- return res
210
- }
211
-
212
- /**
213
- * Gets the value of an attribute from metadata.
214
- *
215
- * Returns `null` if the attribute is not present.
216
- * For simple attributes (without values), returns `true` if present.
217
- *
218
- * @param attribute - The attribute decorator
219
- * @param target - The metadata object (module, controller, or handler)
220
- * @returns The attribute value, `true` for simple attributes, or `null` if not found
221
- *
222
- * @example
223
- * ```typescript
224
- * const isPublic = LegacyAttributeFactory.get(Public, controllerMetadata)
225
- * // isPublic is true | null
226
- *
227
- * const rateLimit = LegacyAttributeFactory.get(RateLimit, endpointMetadata)
228
- * // rateLimit is { requests: number, window: number } | null
229
- * ```
230
- */
231
- static get(
232
- attribute: LegacyClassAttribute,
233
- target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
234
- ): true | null
235
- static get<T extends ZodType>(
236
- attribute: LegacyClassSchemaAttribute<T>,
237
- target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
238
- ): z.output<T> | null
239
- static get(
240
- attribute: LegacyClassAttribute | LegacyClassSchemaAttribute<any>,
241
- target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
242
- ) {
243
- return target.customAttributes.get(attribute.token) ?? null
244
- }
245
-
246
- /**
247
- * Gets all values of an attribute from metadata (useful when an attribute can appear multiple times).
248
- *
249
- * Returns `null` if the attribute is not present.
250
- *
251
- * @param attribute - The attribute decorator
252
- * @param target - The metadata object (module, controller, or handler)
253
- * @returns An array of attribute values, or `null` if not found
254
- *
255
- * @example
256
- * ```typescript
257
- * const tags = LegacyAttributeFactory.getAll(Tag, endpointMetadata)
258
- * // tags is string[] | null
259
- * ```
260
- */
261
- static getAll(
262
- attribute: LegacyClassAttribute,
263
- target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
264
- ): Array<true> | null
265
- static getAll<T extends ZodType>(
266
- attribute: LegacyClassSchemaAttribute<T>,
267
- target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
268
- ): Array<z.output<T>> | null
269
- static getAll(
270
- attribute: LegacyClassAttribute | LegacyClassSchemaAttribute<any>,
271
- target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
272
- ) {
273
- const values = Array.from(target.customAttributes.entries())
274
- .filter(([key]) => key === attribute.token)
275
- .map(([, value]) => value)
276
- return values.length > 0 ? values : null
277
- }
278
-
279
- /**
280
- * Gets the last value of an attribute from an array of metadata objects.
281
- *
282
- * Searches from the end of the array backwards, useful for finding the most
283
- * specific attribute value (e.g., endpoint-level overrides module-level).
284
- *
285
- * @param attribute - The attribute decorator
286
- * @param target - An array of metadata objects (typically [module, controller, handler])
287
- * @returns The last attribute value found, or `null` if not found
288
- *
289
- * @example
290
- * ```typescript
291
- * // Check attribute hierarchy: endpoint -> controller -> module
292
- * const rateLimit = LegacyAttributeFactory.getLast(RateLimit, [
293
- * moduleMetadata,
294
- * controllerMetadata,
295
- * endpointMetadata
296
- * ])
297
- * ```
298
- */
299
- static getLast(
300
- attribute: LegacyClassAttribute,
301
- target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[],
302
- ): true | null
303
- static getLast<T extends ZodType>(
304
- attribute: LegacyClassSchemaAttribute<T>,
305
- target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[],
306
- ): z.output<T> | null
307
- static getLast(
308
- attribute: LegacyClassAttribute | LegacyClassSchemaAttribute<any>,
309
- target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[],
310
- ) {
311
- for (let i = target.length - 1; i >= 0; i--) {
312
- const value = target[i].customAttributes.get(attribute.token)
313
- if (value) {
314
- return value
315
- }
316
- }
317
- return null
318
- }
319
-
320
- /**
321
- * Checks if an attribute is present on the metadata object.
322
- *
323
- * @param attribute - The attribute decorator
324
- * @param target - The metadata object (module, controller, or handler)
325
- * @returns `true` if the attribute is present, `false` otherwise
326
- *
327
- * @example
328
- * ```typescript
329
- * if (LegacyAttributeFactory.has(Public, controllerMetadata)) {
330
- * // Skip authentication
331
- * }
332
- * ```
333
- */
334
- static has(
335
- attribute: LegacyClassAttribute,
336
- target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
337
- ): boolean
338
- static has<T extends ZodType>(
339
- attribute: LegacyClassSchemaAttribute<T>,
340
- target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
341
- ): boolean
342
- static has(
343
- attribute: LegacyClassAttribute | LegacyClassSchemaAttribute<any>,
344
- target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>,
345
- ) {
346
- return target.customAttributes.has(attribute.token)
347
- }
348
- }
349
-
350
- // Re-export as AttributeFactory for convenience
351
- export { LegacyAttributeFactory as AttributeFactory }
@@ -1,31 +0,0 @@
1
- import type { ClassType } from '@navios/di'
2
- import { createClassContext } from '@navios/di/legacy-compat'
3
-
4
- import type { ControllerOptions } from '../../decorators/controller.decorator.mjs'
5
-
6
- import { Controller as OriginalController } from '../../decorators/controller.decorator.mjs'
7
-
8
- /**
9
- * Legacy-compatible Controller decorator.
10
- *
11
- * Works with TypeScript experimental decorators (legacy API).
12
- *
13
- * @param options - Controller configuration options
14
- * @returns A class decorator compatible with legacy decorator API
15
- *
16
- * @example
17
- * ```typescript
18
- * @Controller({ guards: [AuthGuard] })
19
- * export class UserController {
20
- * @Endpoint(getUserEndpoint)
21
- * async getUser() { }
22
- * }
23
- * ```
24
- */
25
- export function Controller(options: ControllerOptions = {}) {
26
- return function (target: ClassType) {
27
- const context = createClassContext(target)
28
- const originalDecorator = OriginalController(options)
29
- return originalDecorator(target, context)
30
- }
31
- }
@@ -1,73 +0,0 @@
1
- import type {
2
- EndpointHandler,
3
- EndpointOptions,
4
- RequestArgs,
5
- } from '@navios/builder'
6
- import { createMethodContext } from '@navios/di/legacy-compat'
7
- import type { z } from 'zod/v4'
8
-
9
- import { Endpoint as OriginalEndpoint } from '../../decorators/endpoint.decorator.mjs'
10
-
11
- /**
12
- * Type helper to constrain a PropertyDescriptor's value to match an endpoint signature.
13
- * Note: In legacy decorators, type constraints are checked when the decorator is applied,
14
- * but may not be preserved perfectly when decorators are stacked.
15
- */
16
- type EndpointMethodDescriptor<Config extends EndpointOptions> =
17
- TypedPropertyDescriptor<
18
- (
19
- params: RequestArgs<
20
- Config['url'],
21
- Config['querySchema'],
22
- Config['requestSchema'],
23
- Config['urlParamsSchema'],
24
- true
25
- >,
26
- ) => Promise<z.input<Config['responseSchema']>>
27
- >
28
-
29
- /**
30
- * Legacy-compatible Endpoint decorator.
31
- *
32
- * Works with TypeScript experimental decorators (legacy API).
33
- * Provides type safety by ensuring method signatures match the endpoint configuration.
34
- *
35
- * @param endpoint - The endpoint declaration from @navios/builder
36
- * @returns A method decorator compatible with legacy decorator API
37
- *
38
- * @example
39
- * ```typescript
40
- * @Controller()
41
- * export class UserController {
42
- * @Endpoint(getUserEndpoint)
43
- * async getUser(request: EndpointParams<typeof getUserEndpoint>): EndpointResult<typeof getUserEndpoint> {
44
- * return { id: '1', name: 'John' }
45
- * }
46
- * }
47
- * ```
48
- */
49
- export function Endpoint<const Config extends EndpointOptions>(
50
- endpoint: EndpointHandler<Config, false>,
51
- ) {
52
- return function (
53
- target: any,
54
- propertyKey: string | symbol,
55
- descriptor: EndpointMethodDescriptor<Config>,
56
- ): PropertyDescriptor | void {
57
- if (!descriptor) {
58
- throw new Error(
59
- '[Navios] @Endpoint decorator requires a method descriptor. Make sure experimentalDecorators is enabled.',
60
- )
61
- }
62
- // Type check the descriptor value matches expected signature
63
- const typedDescriptor = descriptor as EndpointMethodDescriptor<Config>
64
- const context = createMethodContext(target, propertyKey, typedDescriptor)
65
- const originalDecorator = OriginalEndpoint(endpoint)
66
- // @ts-expect-error - we don't need to type the value
67
- const result = originalDecorator(typedDescriptor.value, context)
68
- if (result !== typedDescriptor.value) {
69
- typedDescriptor.value = result as any
70
- }
71
- return typedDescriptor
72
- }
73
- }
@@ -1,43 +0,0 @@
1
- import { createMethodContext } from '@navios/di/legacy-compat'
2
-
3
- import type { HttpHeader } from '../../interfaces/index.mjs'
4
-
5
- import { Header as OriginalHeader } from '../../decorators/header.decorator.mjs'
6
-
7
- /**
8
- * Legacy-compatible Header decorator.
9
- *
10
- * Works with TypeScript experimental decorators (legacy API).
11
- *
12
- * @param name - The header name (e.g., 'Content-Type', 'Cache-Control')
13
- * @param value - The header value (string, number, or array of strings)
14
- * @returns A method decorator compatible with legacy decorator API
15
- *
16
- * @example
17
- * ```typescript
18
- * @Controller()
19
- * export class UserController {
20
- * @Endpoint(getUserEndpoint)
21
- * @Header('Cache-Control', 'max-age=3600')
22
- * async getUser() {
23
- * return { id: '1', name: 'John' }
24
- * }
25
- * }
26
- * ```
27
- */
28
- export function Header(name: HttpHeader, value: string | number | string[]) {
29
- return function <T extends object>(
30
- target: T,
31
- propertyKey: string | symbol,
32
- descriptor: PropertyDescriptor,
33
- ) {
34
- const context = createMethodContext(target, propertyKey, descriptor)
35
- const originalDecorator = OriginalHeader(name, value)
36
- const result = originalDecorator(descriptor.value, context)
37
- if (result !== descriptor.value) {
38
- descriptor.value = result
39
- }
40
- return descriptor
41
- }
42
- }
43
-
@@ -1,39 +0,0 @@
1
- import { createMethodContext } from '@navios/di/legacy-compat'
2
-
3
- import { HttpCode as OriginalHttpCode } from '../../decorators/http-code.decorator.mjs'
4
-
5
- /**
6
- * Legacy-compatible HttpCode decorator.
7
- *
8
- * Works with TypeScript experimental decorators (legacy API).
9
- *
10
- * @param code - The HTTP status code to return (e.g., 201, 204, 202)
11
- * @returns A method decorator compatible with legacy decorator API
12
- *
13
- * @example
14
- * ```typescript
15
- * @Controller()
16
- * export class UserController {
17
- * @Endpoint(createUserEndpoint)
18
- * @HttpCode(201)
19
- * async createUser() {
20
- * return { id: '1', name: 'John' }
21
- * }
22
- * }
23
- * ```
24
- */
25
- export function HttpCode(code: number) {
26
- return function <T extends object>(
27
- target: T,
28
- propertyKey: string | symbol,
29
- descriptor: PropertyDescriptor,
30
- ) {
31
- const context = createMethodContext(target, propertyKey, descriptor)
32
- const originalDecorator = OriginalHttpCode(code)
33
- const result = originalDecorator(descriptor.value, context)
34
- if (result !== descriptor.value) {
35
- descriptor.value = result
36
- }
37
- return descriptor
38
- }
39
- }
@@ -1,11 +0,0 @@
1
- export * from './module.decorator.mjs'
2
- export * from './controller.decorator.mjs'
3
- export * from './endpoint.decorator.mjs'
4
- export * from './use-guards.decorator.mjs'
5
- export * from './header.decorator.mjs'
6
- export * from './http-code.decorator.mjs'
7
- export * from './multipart.decorator.mjs'
8
- export * from './stream.decorator.mjs'
9
-
10
- // Re-export DI decorators from @navios/di/legacy-compat
11
- export { Injectable, Factory, type InjectableOptions, type FactoryOptions } from '@navios/di/legacy-compat'
@@ -1,37 +0,0 @@
1
- import type { ClassType } from '@navios/di'
2
- import { createClassContext } from '@navios/di/legacy-compat'
3
-
4
- import { Module as OriginalModule, type ModuleOptions } from '../../decorators/module.decorator.mjs'
5
-
6
- /**
7
- * Legacy-compatible Module decorator.
8
- *
9
- * Works with TypeScript experimental decorators (legacy API).
10
- *
11
- * @param options - Module configuration options
12
- * @returns A class decorator compatible with legacy decorator API
13
- *
14
- * @example
15
- * ```typescript
16
- * @Module({
17
- * controllers: [UserController, AuthController],
18
- * imports: [DatabaseModule],
19
- * guards: [AuthGuard],
20
- * })
21
- * export class AppModule {}
22
- * ```
23
- */
24
- export function Module(
25
- options: ModuleOptions = {
26
- controllers: [],
27
- imports: [],
28
- guards: [],
29
- },
30
- ) {
31
- return function (target: ClassType) {
32
- const context = createClassContext(target)
33
- const originalDecorator = OriginalModule(options)
34
- return originalDecorator(target, context)
35
- }
36
- }
37
-
@@ -1,72 +0,0 @@
1
- import type {
2
- EndpointHandler,
3
- EndpointOptions,
4
- RequestArgs,
5
- } from '@navios/builder'
6
- import { createMethodContext } from '@navios/di/legacy-compat'
7
- import type { z } from 'zod/v4'
8
-
9
- import { Multipart as OriginalMultipart } from '../../decorators/multipart.decorator.mjs'
10
-
11
- /**
12
- * Type helper to constrain a PropertyDescriptor's value to match a multipart endpoint signature.
13
- * Note: In legacy decorators, type constraints are checked when the decorator is applied,
14
- * but may not be preserved perfectly when decorators are stacked.
15
- */
16
- type MultipartMethodDescriptor<Config extends EndpointOptions> =
17
- TypedPropertyDescriptor<
18
- (
19
- params: RequestArgs<
20
- Config['url'],
21
- Config['querySchema'],
22
- Config['requestSchema'],
23
- Config['urlParamsSchema'],
24
- true
25
- >,
26
- ) => Promise<z.input<Config['responseSchema']>>
27
- >
28
-
29
- /**
30
- * Legacy-compatible Multipart decorator.
31
- *
32
- * Works with TypeScript experimental decorators (legacy API).
33
- * Provides type safety by ensuring method signatures match the endpoint configuration.
34
- *
35
- * @param endpoint - The multipart endpoint declaration from @navios/builder
36
- * @returns A method decorator compatible with legacy decorator API
37
- *
38
- * @example
39
- * ```typescript
40
- * @Controller()
41
- * export class FileController {
42
- * @Multipart(uploadFileEndpoint)
43
- * async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>): MultipartResult<typeof uploadFileEndpoint> {
44
- * const { file } = request.data
45
- * return { url: 'https://example.com/file.jpg' }
46
- * }
47
- * }
48
- * ```
49
- */
50
- export function Multipart<const Config extends EndpointOptions>(
51
- endpoint: EndpointHandler<Config, false>,
52
- ) {
53
- return function <T extends object>(
54
- target: T,
55
- propertyKey: string | symbol,
56
- descriptor: MultipartMethodDescriptor<Config>,
57
- ): PropertyDescriptor | void {
58
- if (!descriptor) {
59
- throw new Error(
60
- '[Navios] @Multipart decorator requires a method descriptor. Make sure experimentalDecorators is enabled.',
61
- )
62
- }
63
- const context = createMethodContext(target, propertyKey, descriptor)
64
- const originalDecorator = OriginalMultipart(endpoint)
65
- // @ts-expect-error - we don't need to type the value
66
- const result = originalDecorator(descriptor.value, context)
67
- if (result !== descriptor.value) {
68
- descriptor.value = result as any
69
- }
70
- return descriptor
71
- }
72
- }