@navios/core 1.1.0 → 2.0.0-alpha.1

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 +85 -13
  2. package/README.md +69 -220
  3. package/lib/async-context-BAdt7bno.d.mts +239 -0
  4. package/lib/async-context-BAdt7bno.d.mts.map +1 -0
  5. package/lib/async-context-RsWmy2Hi.d.cts +239 -0
  6. package/lib/async-context-RsWmy2Hi.d.cts.map +1 -0
  7. package/lib/attribute-factory-BW1kgBqf.d.mts +70 -0
  8. package/lib/attribute-factory-BW1kgBqf.d.mts.map +1 -0
  9. package/lib/attribute-factory-DqN4x5XM.d.cts +70 -0
  10. package/lib/attribute-factory-DqN4x5XM.d.cts.map +1 -0
  11. package/lib/attribute-value-BNiJjxl1.mjs +225 -0
  12. package/lib/attribute-value-BNiJjxl1.mjs.map +1 -0
  13. package/lib/attribute-value-Cux5HhOL.cjs +314 -0
  14. package/lib/attribute-value-Cux5HhOL.cjs.map +1 -0
  15. package/lib/basic-execution-context-5uq2DvEA.cjs +318 -0
  16. package/lib/basic-execution-context-5uq2DvEA.cjs.map +1 -0
  17. package/lib/basic-execution-context-u1VktGoM.mjs +277 -0
  18. package/lib/basic-execution-context-u1VktGoM.mjs.map +1 -0
  19. package/lib/execution-context-BVSmLkYp.d.cts +71 -0
  20. package/lib/execution-context-BVSmLkYp.d.cts.map +1 -0
  21. package/lib/execution-context-C5F9rojO.d.mts +71 -0
  22. package/lib/execution-context-C5F9rojO.d.mts.map +1 -0
  23. package/lib/execution-context-token--cKS4cJv.cjs +270 -0
  24. package/lib/execution-context-token--cKS4cJv.cjs.map +1 -0
  25. package/lib/execution-context-token-Cb3M3Ao0.mjs +223 -0
  26. package/lib/execution-context-token-Cb3M3Ao0.mjs.map +1 -0
  27. package/lib/index.cjs +1672 -4426
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +842 -3
  30. package/lib/index.d.cts.map +1 -0
  31. package/lib/index.d.mts +842 -3
  32. package/lib/index.d.mts.map +1 -0
  33. package/lib/index.mjs +1559 -4221
  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-Bz83ZnJ5.cjs +173 -0
  44. package/lib/module-Bz83ZnJ5.cjs.map +1 -0
  45. package/lib/module-options-CSqQUSTm.d.mts +51 -0
  46. package/lib/module-options-CSqQUSTm.d.mts.map +1 -0
  47. package/lib/module-options-DSRBri4J.d.cts +51 -0
  48. package/lib/module-options-DSRBri4J.d.cts.map +1 -0
  49. package/lib/module-zPXwR2qp.mjs +138 -0
  50. package/lib/module-zPXwR2qp.mjs.map +1 -0
  51. package/lib/settled-within-B6gpu2XW.cjs +32 -0
  52. package/lib/settled-within-B6gpu2XW.cjs.map +1 -0
  53. package/lib/settled-within-Bc2pj8WB.mjs +21 -0
  54. package/lib/settled-within-Bc2pj8WB.mjs.map +1 -0
  55. package/lib/testing/index.cjs +74 -414
  56. package/lib/testing/index.cjs.map +1 -1
  57. package/lib/testing/index.d.cts +25 -385
  58. package/lib/testing/index.d.cts.map +1 -1
  59. package/lib/testing/index.d.mts +24 -385
  60. package/lib/testing/index.d.mts.map +1 -1
  61. package/lib/testing/index.mjs +72 -408
  62. package/lib/testing/index.mjs.map +1 -1
  63. package/lib/transport.cjs +36 -0
  64. package/lib/transport.d.cts +254 -0
  65. package/lib/transport.d.cts.map +1 -0
  66. package/lib/transport.d.mts +254 -0
  67. package/lib/transport.d.mts.map +1 -0
  68. package/lib/transport.mjs +6 -0
  69. package/package.json +37 -17
  70. package/docs/README.md +0 -316
  71. package/docs/adapters.md +0 -308
  72. package/docs/application-setup.md +0 -524
  73. package/docs/attributes.md +0 -689
  74. package/docs/controllers.md +0 -373
  75. package/docs/endpoints.md +0 -444
  76. package/docs/exceptions.md +0 -352
  77. package/docs/guards.md +0 -550
  78. package/docs/legacy-compat.md +0 -356
  79. package/docs/modules.md +0 -377
  80. package/docs/quick-start.md +0 -290
  81. package/docs/services.md +0 -427
  82. package/docs/testing.md +0 -827
  83. package/lib/index-3LcTrbxz.d.mts +0 -3804
  84. package/lib/index-3LcTrbxz.d.mts.map +0 -1
  85. package/lib/index-B14SekVb.d.cts +0 -3804
  86. package/lib/index-B14SekVb.d.cts.map +0 -1
  87. package/lib/navios.factory-CUrO_p6K.cjs +0 -4538
  88. package/lib/navios.factory-CUrO_p6K.cjs.map +0 -1
  89. package/lib/navios.factory-DjUOOVVL.mjs +0 -4151
  90. package/lib/navios.factory-DjUOOVVL.mjs.map +0 -1
  91. package/lib/tokens-BEuBMGGX.cjs +0 -193
  92. package/lib/tokens-BEuBMGGX.cjs.map +0 -1
  93. package/lib/tokens-COyNGV1I.mjs +0 -97
  94. package/lib/tokens-COyNGV1I.mjs.map +0 -1
  95. package/lib/use-guards.decorator-DLmRl2CV.mjs +0 -336
  96. package/lib/use-guards.decorator-DLmRl2CV.mjs.map +0 -1
  97. package/lib/use-guards.decorator-DhumFTk3.cjs +0 -444
  98. package/lib/use-guards.decorator-DhumFTk3.cjs.map +0 -1
  99. package/project.json +0 -66
  100. package/src/__tests__/attribute.factory.spec.mts +0 -300
  101. package/src/__tests__/config.service.spec.mts +0 -43
  102. package/src/__tests__/console-logger.service.spec.mts +0 -312
  103. package/src/__tests__/controller-resolver.spec.mts +0 -229
  104. package/src/__tests__/controller.spec.mts +0 -58
  105. package/src/__tests__/guard-runner.service.spec.mts +0 -399
  106. package/src/__tests__/logger.service.spec.mts +0 -147
  107. package/src/__tests__/responders.spec.mts +0 -340
  108. package/src/__tests__/testing-module.spec.mts +0 -459
  109. package/src/__tests__/unit-testing-module.spec.mts +0 -424
  110. package/src/attribute.factory.mts +0 -325
  111. package/src/config/config-service.interface.mts +0 -47
  112. package/src/config/config.provider.mts +0 -69
  113. package/src/config/config.service.mts +0 -176
  114. package/src/config/index.mts +0 -5
  115. package/src/config/types.mts +0 -58
  116. package/src/config/utils/helpers.mts +0 -23
  117. package/src/config/utils/index.mts +0 -1
  118. package/src/decorators/controller.decorator.mts +0 -81
  119. package/src/decorators/endpoint.decorator.mts +0 -181
  120. package/src/decorators/header.decorator.mts +0 -38
  121. package/src/decorators/http-code.decorator.mts +0 -38
  122. package/src/decorators/index.mts +0 -8
  123. package/src/decorators/module.decorator.mts +0 -106
  124. package/src/decorators/multipart.decorator.mts +0 -169
  125. package/src/decorators/stream.decorator.mts +0 -155
  126. package/src/decorators/use-guards.decorator.mts +0 -73
  127. package/src/exceptions/bad-request.exception.mts +0 -28
  128. package/src/exceptions/conflict.exception.mts +0 -31
  129. package/src/exceptions/forbidden.exception.mts +0 -30
  130. package/src/exceptions/http.exception.mts +0 -33
  131. package/src/exceptions/index.mts +0 -7
  132. package/src/exceptions/internal-server-error.exception.mts +0 -33
  133. package/src/exceptions/not-found.exception.mts +0 -33
  134. package/src/exceptions/unauthorized.exception.mts +0 -30
  135. package/src/factories/adapter.factory.mts +0 -20
  136. package/src/factories/endpoint-adapter.factory.mts +0 -21
  137. package/src/factories/http-adapter.factory.mts +0 -20
  138. package/src/factories/index.mts +0 -8
  139. package/src/factories/multipart-adapter.factory.mts +0 -21
  140. package/src/factories/reply.factory.mts +0 -21
  141. package/src/factories/request.factory.mts +0 -21
  142. package/src/factories/stream-adapter.factory.mts +0 -20
  143. package/src/factories/xml-stream-adapter.factory.mts +0 -20
  144. package/src/index.mts +0 -16
  145. package/src/interfaces/abstract-adapter.interface.mts +0 -32
  146. package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
  147. package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
  148. package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
  149. package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
  150. package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
  151. package/src/interfaces/adapter-environment.interface.mts +0 -74
  152. package/src/interfaces/can-activate.mts +0 -38
  153. package/src/interfaces/http-header.mts +0 -18
  154. package/src/interfaces/index.mts +0 -14
  155. package/src/interfaces/navios-module.mts +0 -28
  156. package/src/interfaces/plugin-context.mts +0 -104
  157. package/src/interfaces/plugin-stage.mts +0 -62
  158. package/src/interfaces/plugin.interface.mts +0 -119
  159. package/src/interfaces/staged-plugin.interface.mts +0 -209
  160. package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
  161. package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
  162. package/src/legacy-compat/attribute.factory.mts +0 -351
  163. package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
  164. package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
  165. package/src/legacy-compat/decorators/header.decorator.mts +0 -43
  166. package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
  167. package/src/legacy-compat/decorators/index.mts +0 -11
  168. package/src/legacy-compat/decorators/module.decorator.mts +0 -37
  169. package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
  170. package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
  171. package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
  172. package/src/legacy-compat/index.mts +0 -57
  173. package/src/logger/README.md +0 -3
  174. package/src/logger/console-logger.service.mts +0 -714
  175. package/src/logger/index.mts +0 -6
  176. package/src/logger/log-levels.mts +0 -21
  177. package/src/logger/logger-service.interface.mts +0 -42
  178. package/src/logger/logger.service.mts +0 -113
  179. package/src/logger/logger.tokens.mts +0 -44
  180. package/src/logger/utils/cli-colors.util.mts +0 -17
  181. package/src/logger/utils/filter-log-levelts.util.mts +0 -29
  182. package/src/logger/utils/index.mts +0 -5
  183. package/src/logger/utils/is-log-level-enabled.mts +0 -33
  184. package/src/logger/utils/is-log-level.util.mts +0 -10
  185. package/src/logger/utils/shared.utils.mts +0 -51
  186. package/src/metadata/controller.metadata.mts +0 -79
  187. package/src/metadata/handler.metadata.mts +0 -80
  188. package/src/metadata/index.mts +0 -4
  189. package/src/metadata/module.metadata.mts +0 -116
  190. package/src/metadata/navios-managed.metadata.mts +0 -42
  191. package/src/navios.application.mts +0 -678
  192. package/src/navios.environment.mts +0 -42
  193. package/src/navios.factory.mts +0 -158
  194. package/src/responders/enums/framework-error.enum.mts +0 -38
  195. package/src/responders/enums/index.mts +0 -1
  196. package/src/responders/index.mts +0 -4
  197. package/src/responders/interfaces/error-responder.interface.mts +0 -42
  198. package/src/responders/interfaces/error-response.interface.mts +0 -22
  199. package/src/responders/interfaces/index.mts +0 -3
  200. package/src/responders/interfaces/problem-details.interface.mts +0 -34
  201. package/src/responders/services/error-response-producer.service.mts +0 -143
  202. package/src/responders/services/forbidden-responder.service.mts +0 -77
  203. package/src/responders/services/index.mts +0 -5
  204. package/src/responders/services/internal-server-error-responder.service.mts +0 -57
  205. package/src/responders/services/not-found-responder.service.mts +0 -76
  206. package/src/responders/services/validation-error-responder.service.mts +0 -78
  207. package/src/responders/tokens/index.mts +0 -1
  208. package/src/responders/tokens/responder.tokens.mts +0 -84
  209. package/src/services/abstract-handler-adapter.service.mts +0 -366
  210. package/src/services/guard-runner.service.mts +0 -152
  211. package/src/services/index.mts +0 -4
  212. package/src/services/instance-resolver.service.mts +0 -177
  213. package/src/services/module-loader.service.mts +0 -255
  214. package/src/stores/index.mts +0 -1
  215. package/src/stores/request-id.store.mts +0 -85
  216. package/src/testing/index.mts +0 -3
  217. package/src/testing/testing-module.mts +0 -393
  218. package/src/testing/unit-testing-module.mts +0 -298
  219. package/src/tokens/adapter.token.mts +0 -6
  220. package/src/tokens/endpoint-adapter.token.mts +0 -8
  221. package/src/tokens/execution-context.token.mts +0 -9
  222. package/src/tokens/http-adapter.token.mts +0 -8
  223. package/src/tokens/index.mts +0 -10
  224. package/src/tokens/multipart-adapter.token.mts +0 -8
  225. package/src/tokens/navios-options.token.mts +0 -6
  226. package/src/tokens/reply.token.mts +0 -3
  227. package/src/tokens/request.token.mts +0 -3
  228. package/src/tokens/stream-adapter.token.mts +0 -8
  229. package/src/tokens/xml-stream-adapter.token.mts +0 -8
  230. package/src/utils/adapter-supports.util.mts +0 -47
  231. package/src/utils/define-plugin.mts +0 -251
  232. package/src/utils/index.mts +0 -2
  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
- }