@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,81 +0,0 @@
1
- import type { ClassType, InjectableScope } from '@navios/di'
2
-
3
- import { Injectable, InjectionToken, Registry } from '@navios/di'
4
-
5
- import { getControllerMetadata } from '../metadata/index.mjs'
6
-
7
- /**
8
- * Options for configuring a Navios controller.
9
- */
10
- export interface ControllerOptions {
11
- /**
12
- * Guards to apply to all endpoints in this controller.
13
- * Guards are executed in reverse order (last guard first).
14
- */
15
- guards?: ClassType[] | Set<ClassType>
16
- /**
17
- * Registry to use for the controller.
18
- * Registry is used to store the controller and its endpoints.
19
- */
20
- registry?: Registry
21
- /**
22
- * Priority to use for the controller.
23
- * Priority is used to sort the controller in the registry.
24
- */
25
- priority?: number
26
- /**
27
- * Scope to use for the controller.
28
- * Scope is used to determine the scope of the controller.
29
- */
30
- scope?: InjectableScope
31
- }
32
-
33
- /**
34
- * Decorator that marks a class as a Navios controller.
35
- *
36
- * Controllers handle HTTP requests and define endpoints.
37
- * They are request-scoped by default, meaning a new instance is created for each request.
38
- *
39
- * @param options - Controller configuration options
40
- * @returns A class decorator
41
- *
42
- * @example
43
- * ```typescript
44
- * @Controller({ guards: [AuthGuard] })
45
- * export class UserController {
46
- * @Endpoint(getUserEndpoint)
47
- * async getUser(request: EndpointParams<typeof getUserEndpoint>) {
48
- * // Handle request
49
- * }
50
- * }
51
- * ```
52
- */
53
- export function Controller({
54
- guards,
55
- registry,
56
- priority,
57
- scope,
58
- }: ControllerOptions = {}) {
59
- return function (target: ClassType, context: ClassDecoratorContext) {
60
- if (context.kind !== 'class') {
61
- throw new Error(
62
- '[Navios] @Controller decorator can only be used on classes.',
63
- )
64
- }
65
- const token = InjectionToken.create(target)
66
- if (context.metadata) {
67
- const controllerMetadata = getControllerMetadata(target, context)
68
- if (guards) {
69
- for (const guard of Array.from(guards).reverse()) {
70
- controllerMetadata.guards.add(guard)
71
- }
72
- }
73
- }
74
- return Injectable({
75
- token,
76
- registry,
77
- priority,
78
- scope,
79
- })(target, context)
80
- }
81
- }
@@ -1,181 +0,0 @@
1
- import type {
2
- EndpointHandler,
3
- EndpointOptions,
4
- RequestArgs,
5
- } from '@navios/builder'
6
- import type { z } from 'zod/v4'
7
-
8
- import { ZodDiscriminatedUnion } from 'zod/v4'
9
-
10
- import { getEndpointMetadata } from '../metadata/index.mjs'
11
- import { EndpointAdapterToken } from '../tokens/index.mjs'
12
-
13
- /**
14
- * Extracts the typed parameters for an endpoint handler function.
15
- *
16
- * This utility type extracts URL parameters, query parameters, and request body
17
- * from an endpoint declaration and flattens them into a single object.
18
- *
19
- * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
20
- *
21
- * @example
22
- * ```typescript
23
- * const getUserEndpoint = api.declareEndpoint({
24
- * method: 'get',
25
- * url: '/users/$userId',
26
- * querySchema: z.object({ include: z.string().optional() }),
27
- * responseSchema: z.object({ id: z.string(), name: z.string() }),
28
- * })
29
- *
30
- * @Endpoint(getUserEndpoint)
31
- * async getUser(request: EndpointParams<typeof getUserEndpoint>) {
32
- * // request.urlParams.userId is typed as string
33
- * // request.query.include is typed as string | undefined
34
- * }
35
- * ```
36
- */
37
- export type EndpointParams<
38
- EndpointDeclaration extends EndpointHandler<Config, false>,
39
- Config extends EndpointOptions = EndpointDeclaration['config'],
40
- > = RequestArgs<
41
- Config['url'],
42
- Config['querySchema'],
43
- Config['requestSchema'],
44
- Config['urlParamsSchema'],
45
- true
46
- >
47
-
48
- /**
49
- * Extracts the typed return value for an endpoint handler function.
50
- *
51
- * This utility type extracts the response schema from an endpoint declaration
52
- * and returns the appropriate Promise type.
53
- *
54
- * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
55
- *
56
- * @example
57
- * ```typescript
58
- * const getUserEndpoint = api.declareEndpoint({
59
- * method: 'get',
60
- * url: '/users/$userId',
61
- * responseSchema: z.object({ id: z.string(), name: z.string() }),
62
- * })
63
- *
64
- * @Endpoint(getUserEndpoint)
65
- * async getUser(request: EndpointParams<typeof getUserEndpoint>): EndpointResult<typeof getUserEndpoint> {
66
- * return { id: '1', name: 'John' } // Type-checked against responseSchema
67
- * }
68
- * ```
69
- */
70
- export type EndpointResult<
71
- EndpointDeclaration extends {
72
- config: EndpointOptions
73
- },
74
- > =
75
- EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<
76
- infer Options
77
- >
78
- ? Promise<z.input<Options[number]>>
79
- : Promise<z.input<EndpointDeclaration['config']['responseSchema']>>
80
-
81
- /**
82
- * Decorator that marks a method as an HTTP endpoint.
83
- *
84
- * The endpoint must be defined using @navios/builder's `declareEndpoint` method.
85
- * This ensures type safety and consistency between client and server.
86
- *
87
- * @param endpoint - The endpoint declaration from @navios/builder
88
- * @returns A method decorator
89
- *
90
- * @example
91
- * ```typescript
92
- * import { builder } from '@navios/builder'
93
- *
94
- * const api = builder()
95
- * const getUserEndpoint = api.declareEndpoint({
96
- * method: 'get',
97
- * url: '/users/$userId',
98
- * responseSchema: z.object({ id: z.string(), name: z.string() }),
99
- * })
100
- *
101
- * @Controller()
102
- * export class UserController {
103
- * @Endpoint(getUserEndpoint)
104
- * async getUser(request: EndpointParams<typeof getUserEndpoint>) {
105
- * const { userId } = request.urlParams
106
- * return { id: userId, name: 'John' }
107
- * }
108
- * }
109
- * ```
110
- */
111
- export function Endpoint<const Config extends EndpointOptions>(
112
- endpoint: EndpointHandler<Config, false>,
113
- ): (
114
- target: (
115
- params: RequestArgs<
116
- Config['url'],
117
- Config['querySchema'],
118
- Config['requestSchema'],
119
- Config['urlParamsSchema'],
120
- true
121
- >,
122
- ) =>
123
- | Promise<z.input<Config['responseSchema']>>
124
- | z.input<Config['responseSchema']>,
125
- context: ClassMethodDecoratorContext,
126
- ) => void
127
- export function Endpoint<const Config extends EndpointOptions>(
128
- endpoint: EndpointHandler<Config, false>,
129
- ): (
130
- target: () =>
131
- | Promise<z.input<Config['responseSchema']>>
132
- | z.input<Config['responseSchema']>,
133
- context: ClassMethodDecoratorContext,
134
- ) => void
135
- export function Endpoint<const Config extends EndpointOptions>(
136
- endpoint: EndpointHandler<Config, false>,
137
- ) {
138
- type Params = RequestArgs<
139
- Config['url'],
140
- Config['querySchema'],
141
- Config['requestSchema'],
142
- Config['urlParamsSchema'],
143
- true
144
- >
145
-
146
- type Handler =
147
- | ((
148
- params: Params,
149
- ) =>
150
- | Promise<z.input<Config['responseSchema']>>
151
- | z.input<Config['responseSchema']>)
152
- | (() =>
153
- | Promise<z.input<Config['responseSchema']>>
154
- | z.input<Config['responseSchema']>)
155
-
156
- return (target: Handler, context: ClassMethodDecoratorContext) => {
157
- if (context.kind !== 'method') {
158
- throw new Error(
159
- '[Navios] Endpoint decorator can only be used on methods.',
160
- )
161
- }
162
- const config = endpoint.config
163
- if (context.metadata) {
164
- let endpointMetadata = getEndpointMetadata<EndpointOptions>(
165
- target,
166
- context,
167
- )
168
- if (endpointMetadata.config && endpointMetadata.config.url) {
169
- throw new Error(
170
- `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,
171
- )
172
- }
173
- endpointMetadata.config = config
174
- endpointMetadata.adapterToken = EndpointAdapterToken
175
- endpointMetadata.classMethod = target.name
176
- endpointMetadata.httpMethod = config.method
177
- endpointMetadata.url = config.url
178
- }
179
- return target
180
- }
181
- }
@@ -1,38 +0,0 @@
1
- import type { HttpHeader } from '../interfaces/index.mjs'
2
-
3
- import { getEndpointMetadata } from '../metadata/index.mjs'
4
-
5
- /**
6
- * Decorator that sets a custom HTTP response header for an endpoint.
7
- *
8
- * @param name - The header name (e.g., 'Content-Type', 'Cache-Control')
9
- * @param value - The header value (string, number, or array of strings)
10
- * @returns A method decorator
11
- *
12
- * @example
13
- * ```typescript
14
- * @Controller()
15
- * export class UserController {
16
- * @Endpoint(getUserEndpoint)
17
- * @Header('Cache-Control', 'max-age=3600')
18
- * async getUser() {
19
- * return { id: '1', name: 'John' }
20
- * }
21
- * }
22
- * ```
23
- */
24
- export function Header(name: HttpHeader, value: string | number | string[]) {
25
- return <T extends Function>(
26
- target: T,
27
- context: ClassMethodDecoratorContext,
28
- ) => {
29
- if (context.kind !== 'method') {
30
- throw new Error('[Navios] Header decorator can only be used on methods.')
31
- }
32
- const metadata = getEndpointMetadata(target, context)
33
-
34
- metadata.headers[name] = value
35
-
36
- return target
37
- }
38
- }
@@ -1,38 +0,0 @@
1
- import { getEndpointMetadata } from '../metadata/index.mjs'
2
-
3
- /**
4
- * Decorator that sets a custom HTTP status code for successful responses.
5
- *
6
- * By default, endpoints return 200 OK. Use this decorator to return a different status code.
7
- *
8
- * @param code - The HTTP status code to return (e.g., 201, 204, 202)
9
- * @returns A method decorator
10
- *
11
- * @example
12
- * ```typescript
13
- * @Controller()
14
- * export class UserController {
15
- * @Endpoint(createUserEndpoint)
16
- * @HttpCode(201)
17
- * async createUser() {
18
- * return { id: '1', name: 'John' }
19
- * }
20
- * }
21
- * ```
22
- */
23
- export function HttpCode(code: number) {
24
- return <T extends Function>(
25
- target: T,
26
- context: ClassMethodDecoratorContext,
27
- ) => {
28
- if (context.kind !== 'method') {
29
- throw new Error(
30
- '[Navios] HttpCode decorator can only be used on methods.',
31
- )
32
- }
33
- const metadata = getEndpointMetadata(target, context)
34
- metadata.successStatusCode = code
35
-
36
- return target
37
- }
38
- }
@@ -1,8 +0,0 @@
1
- export * from './controller.decorator.mjs'
2
- export * from './endpoint.decorator.mjs'
3
- export * from './header.decorator.mjs'
4
- export * from './http-code.decorator.mjs'
5
- export * from './module.decorator.mjs'
6
- export * from './multipart.decorator.mjs'
7
- export * from './stream.decorator.mjs'
8
- export * from './use-guards.decorator.mjs'
@@ -1,106 +0,0 @@
1
- import type { ClassType, Registry } from '@navios/di'
2
-
3
- import { Injectable, InjectableScope, InjectionToken } from '@navios/di'
4
-
5
- import { getModuleMetadata } from '../metadata/index.mjs'
6
-
7
- /**
8
- * Options for configuring a Navios module.
9
- */
10
- export interface ModuleOptions {
11
- /**
12
- * Controllers to register in this module.
13
- * Controllers handle HTTP requests and define endpoints.
14
- */
15
- controllers?: ClassType[] | Set<ClassType>
16
- /**
17
- * Other modules to import into this module.
18
- * Imported modules' controllers and services become available.
19
- */
20
- imports?: ClassType[] | Set<ClassType>
21
- /**
22
- * Guards to apply to all controllers in this module.
23
- * Guards are executed in reverse order (last guard first).
24
- */
25
- guards?: ClassType[] | Set<ClassType>
26
- /**
27
- * Service override classes to import for side effects.
28
- * These classes are imported to ensure their @Injectable decorators execute,
29
- * allowing them to register with the DI system. Overrides should use the same
30
- * InjectionToken as the original service with a higher priority.
31
- */
32
- overrides?: ClassType[] | Set<ClassType>
33
- /**
34
- * Priority to use for the module.
35
- * Priority is used to sort the module in the registry.
36
- */
37
- priority?: number
38
- /**
39
- * Registry to use for the module.
40
- * Registry is used to store the module and its controllers.
41
- */
42
- registry?: Registry
43
- }
44
-
45
- /**
46
- * Decorator that marks a class as a Navios module.
47
- *
48
- * Modules are the basic building blocks of a Navios application.
49
- * They organize controllers, services, and other modules into logical units.
50
- *
51
- * @param options - Module configuration options
52
- * @returns A class decorator
53
- *
54
- * @example
55
- * ```typescript
56
- * @Module({
57
- * controllers: [UserController, AuthController],
58
- * imports: [DatabaseModule],
59
- * guards: [AuthGuard],
60
- * })
61
- * export class AppModule {}
62
- * ```
63
- */
64
- export function Module(
65
- {
66
- controllers = [],
67
- imports = [],
68
- guards = [],
69
- overrides = [],
70
- priority,
71
- registry,
72
- }: ModuleOptions = {
73
- controllers: [],
74
- imports: [],
75
- guards: [],
76
- overrides: [],
77
- },
78
- ) {
79
- return (target: ClassType, context: ClassDecoratorContext) => {
80
- if (context.kind !== 'class') {
81
- throw new Error('[Navios] @Module decorator can only be used on classes.')
82
- }
83
- // Register the module in the service locator
84
- const token = InjectionToken.create(target)
85
- const moduleMetadata = getModuleMetadata(target, context)
86
- for (const controller of controllers) {
87
- moduleMetadata.controllers.add(controller)
88
- }
89
- for (const importedModule of imports) {
90
- moduleMetadata.imports.add(importedModule)
91
- }
92
- for (const guard of Array.from(guards).reverse()) {
93
- moduleMetadata.guards.add(guard)
94
- }
95
- for (const override of overrides) {
96
- moduleMetadata.overrides.add(override)
97
- }
98
-
99
- return Injectable({
100
- token,
101
- scope: InjectableScope.Singleton,
102
- priority,
103
- registry,
104
- })(target, context)
105
- }
106
- }
@@ -1,169 +0,0 @@
1
- import type { EndpointOptions, RequestArgs } from '@navios/builder'
2
- import type { z, ZodObject, ZodType } from 'zod/v4'
3
-
4
- import { ZodDiscriminatedUnion } from 'zod/v4'
5
-
6
- import { getEndpointMetadata } from '../metadata/index.mjs'
7
- import { MultipartAdapterToken } from '../tokens/index.mjs'
8
-
9
- /**
10
- * Extracts the typed parameters for a multipart endpoint handler function.
11
- *
12
- * Similar to `EndpointParams`, but specifically for multipart/form-data endpoints.
13
- *
14
- * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
15
- */
16
- export type MultipartParams<
17
- EndpointDeclaration extends {
18
- config: EndpointOptions
19
- },
20
- Url extends string = EndpointDeclaration['config']['url'],
21
- QuerySchema = EndpointDeclaration['config']['querySchema'],
22
- > = QuerySchema extends ZodObject
23
- ? EndpointDeclaration['config']['requestSchema'] extends ZodType
24
- ? RequestArgs<
25
- Url,
26
- QuerySchema,
27
- EndpointDeclaration['config']['requestSchema'],
28
- EndpointDeclaration['config']['urlParamsSchema'],
29
- true
30
- >
31
- : RequestArgs<
32
- Url,
33
- QuerySchema,
34
- undefined,
35
- EndpointDeclaration['config']['urlParamsSchema'],
36
- true
37
- >
38
- : EndpointDeclaration['config']['requestSchema'] extends ZodType
39
- ? RequestArgs<
40
- Url,
41
- undefined,
42
- EndpointDeclaration['config']['requestSchema'],
43
- EndpointDeclaration['config']['urlParamsSchema'],
44
- true
45
- >
46
- : RequestArgs<
47
- Url,
48
- undefined,
49
- undefined,
50
- EndpointDeclaration['config']['urlParamsSchema'],
51
- true
52
- >
53
-
54
- /**
55
- * Extracts the typed return value for a multipart endpoint handler function.
56
- *
57
- * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
58
- */
59
- export type MultipartResult<
60
- EndpointDeclaration extends {
61
- config: EndpointOptions
62
- },
63
- > =
64
- EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<
65
- infer Options
66
- >
67
- ? Promise<z.input<Options[number]>>
68
- : Promise<z.input<EndpointDeclaration['config']['responseSchema']>>
69
-
70
- /**
71
- * Decorator that marks a method as a multipart/form-data endpoint.
72
- *
73
- * Use this decorator for endpoints that handle file uploads or form data.
74
- * The endpoint must be defined using @navios/builder's `declareMultipart` method.
75
- *
76
- * @param endpoint - The multipart endpoint declaration from @navios/builder
77
- * @returns A method decorator
78
- *
79
- * @example
80
- * ```typescript
81
- * const uploadFileEndpoint = api.declareMultipart({
82
- * method: 'post',
83
- * url: '/upload',
84
- * requestSchema: z.object({ file: z.instanceof(File) }),
85
- * responseSchema: z.object({ url: z.string() }),
86
- * })
87
- *
88
- * @Controller()
89
- * export class FileController {
90
- * @Multipart(uploadFileEndpoint)
91
- * async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>) {
92
- * const { file } = request.data
93
- * // Handle file upload
94
- * return { url: 'https://example.com/file.jpg' }
95
- * }
96
- * }
97
- * ```
98
- */
99
- export function Multipart<Config extends EndpointOptions>(endpoint: {
100
- config: Config
101
- }): (
102
- target: (
103
- params: RequestArgs<
104
- Config['url'],
105
- Config['querySchema'],
106
- Config['requestSchema'],
107
- Config['urlParamsSchema'],
108
- true
109
- >,
110
- ) =>
111
- | Promise<z.input<Config['responseSchema']>>
112
- | z.input<Config['responseSchema']>,
113
- context: ClassMethodDecoratorContext,
114
- ) => void
115
- export function Multipart<Config extends EndpointOptions>(endpoint: {
116
- config: Config
117
- }): (
118
- target: () =>
119
- | Promise<z.input<Config['responseSchema']>>
120
- | z.input<Config['responseSchema']>,
121
- context: ClassMethodDecoratorContext,
122
- ) => void
123
- export function Multipart<Config extends EndpointOptions>(endpoint: {
124
- config: Config
125
- }) {
126
- type Params = RequestArgs<
127
- Config['url'],
128
- Config['querySchema'],
129
- Config['requestSchema'],
130
- Config['urlParamsSchema'],
131
- true
132
- >
133
-
134
- type Handler =
135
- | ((
136
- params: Params,
137
- ) =>
138
- | Promise<z.input<Config['responseSchema']>>
139
- | z.input<Config['responseSchema']>)
140
- | (() =>
141
- | Promise<z.input<Config['responseSchema']>>
142
- | z.input<Config['responseSchema']>)
143
-
144
- return (target: Handler, context: ClassMethodDecoratorContext) => {
145
- if (context.kind !== 'method') {
146
- throw new Error(
147
- '[Navios] Endpoint decorator can only be used on methods.',
148
- )
149
- }
150
- const config = endpoint.config
151
- if (context.metadata) {
152
- let endpointMetadata = getEndpointMetadata<EndpointOptions>(
153
- target,
154
- context,
155
- )
156
- if (endpointMetadata.config && endpointMetadata.config.url) {
157
- throw new Error(
158
- `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,
159
- )
160
- }
161
- endpointMetadata.config = config
162
- endpointMetadata.adapterToken = MultipartAdapterToken
163
- endpointMetadata.classMethod = target.name
164
- endpointMetadata.httpMethod = config.method
165
- endpointMetadata.url = config.url
166
- }
167
- return target
168
- }
169
- }