@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,155 +0,0 @@
1
- import type {
2
- BaseEndpointOptions,
3
- RequestArgs,
4
- StreamHandler,
5
- } from '@navios/builder'
6
- import type { ZodObject, ZodType } from 'zod/v4'
7
-
8
- import { getEndpointMetadata } from '../metadata/index.mjs'
9
- import { StreamAdapterToken } from '../tokens/index.mjs'
10
-
11
- /**
12
- * Extracts the typed parameters for a stream endpoint handler function.
13
- *
14
- * Similar to `EndpointParams`, but specifically for streaming endpoints.
15
- *
16
- * @typeParam EndpointDeclaration - The stream endpoint declaration from @navios/builder
17
- */
18
- export type StreamParams<
19
- EndpointDeclaration extends StreamHandler<Config, false>,
20
- Config extends BaseEndpointOptions = EndpointDeclaration['config'],
21
- Url extends string = EndpointDeclaration['config']['url'],
22
- QuerySchema = EndpointDeclaration['config']['querySchema'],
23
- > = QuerySchema extends ZodObject
24
- ? EndpointDeclaration['config']['requestSchema'] extends ZodType
25
- ? RequestArgs<
26
- Url,
27
- QuerySchema,
28
- EndpointDeclaration['config']['requestSchema'],
29
- EndpointDeclaration['config']['urlParamsSchema'],
30
- true
31
- >
32
- : RequestArgs<
33
- Url,
34
- QuerySchema,
35
- undefined,
36
- EndpointDeclaration['config']['urlParamsSchema'],
37
- true
38
- >
39
- : EndpointDeclaration['config']['requestSchema'] extends ZodType
40
- ? RequestArgs<
41
- Url,
42
- undefined,
43
- EndpointDeclaration['config']['requestSchema'],
44
- EndpointDeclaration['config']['urlParamsSchema'],
45
- true
46
- >
47
- : RequestArgs<
48
- Url,
49
- undefined,
50
- undefined,
51
- EndpointDeclaration['config']['urlParamsSchema'],
52
- true
53
- >
54
-
55
- /**
56
- * Decorator that marks a method as a streaming endpoint.
57
- *
58
- * Use this decorator for endpoints that stream data (e.g., file downloads, SSE).
59
- * The endpoint must be defined using @navios/builder's `declareStream` method.
60
- *
61
- * @param endpoint - The stream endpoint declaration from @navios/builder
62
- * @returns A method decorator
63
- *
64
- * @example
65
- * ```typescript
66
- * const downloadFileEndpoint = api.declareStream({
67
- * method: 'get',
68
- * url: '/files/$fileId',
69
- * })
70
- *
71
- * @Controller()
72
- * export class FileController {
73
- * @Stream(downloadFileEndpoint)
74
- * async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any) {
75
- * const { fileId } = request.urlParams
76
- * // Stream file data to reply
77
- * }
78
- * }
79
- * ```
80
- */
81
- export function Stream<Config extends BaseEndpointOptions>(endpoint: {
82
- config: Config
83
- }): (
84
- target: (
85
- params: RequestArgs<
86
- Config['url'],
87
- Config['querySchema'],
88
- Config['requestSchema'],
89
- Config['urlParamsSchema'],
90
- true
91
- >,
92
- reply: any,
93
- ) => any,
94
- context: ClassMethodDecoratorContext,
95
- ) => void
96
- // Bun doesn't support reply parameter
97
- export function Stream<Config extends BaseEndpointOptions>(endpoint: {
98
- config: Config
99
- }): (
100
- target: (
101
- params: RequestArgs<
102
- Config['url'],
103
- Config['querySchema'],
104
- Config['requestSchema'],
105
- Config['urlParamsSchema'],
106
- true
107
- >,
108
- ) => any,
109
- context: ClassMethodDecoratorContext,
110
- ) => void
111
- export function Stream<Config extends BaseEndpointOptions>(endpoint: {
112
- config: Config
113
- }): (target: () => any, context: ClassMethodDecoratorContext) => void
114
- export function Stream<Config extends BaseEndpointOptions>(endpoint: {
115
- config: Config
116
- }) {
117
- type Params = RequestArgs<
118
- Config['url'],
119
- Config['querySchema'],
120
- Config['requestSchema'],
121
- Config['urlParamsSchema'],
122
- true
123
- >
124
-
125
- type Handler =
126
- | ((params: Params, reply: any) => any)
127
- | ((params: Params) => any)
128
- | (() => any)
129
-
130
- return (target: Handler, context: ClassMethodDecoratorContext) => {
131
- if (context.kind !== 'method') {
132
- throw new Error(
133
- '[Navios] Endpoint decorator can only be used on methods.',
134
- )
135
- }
136
- const config = endpoint.config
137
- if (context.metadata) {
138
- let endpointMetadata = getEndpointMetadata<BaseEndpointOptions>(
139
- target,
140
- context,
141
- )
142
- if (endpointMetadata.config && endpointMetadata.config.url) {
143
- throw new Error(
144
- `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,
145
- )
146
- }
147
- endpointMetadata.config = config
148
- endpointMetadata.adapterToken = StreamAdapterToken
149
- endpointMetadata.classMethod = target.name
150
- endpointMetadata.httpMethod = config.method
151
- endpointMetadata.url = config.url
152
- }
153
- return target
154
- }
155
- }
@@ -1,73 +0,0 @@
1
- import type {
2
- ClassType,
3
- ClassTypeWithInstance,
4
- InjectionToken,
5
- } from '@navios/di'
6
-
7
- import type { CanActivate } from '../interfaces/index.mjs'
8
-
9
- import {
10
- getControllerMetadata,
11
- getEndpointMetadata,
12
- } from '../metadata/index.mjs'
13
-
14
- /**
15
- * Decorator that applies guards to a controller or endpoint.
16
- *
17
- * Guards are used for authentication, authorization, and request validation.
18
- * They implement the `CanActivate` interface and are executed before the endpoint handler.
19
- * Guards can be applied at the module, controller, or endpoint level.
20
- *
21
- * @param guards - Guard classes or injection tokens to apply
22
- * @returns A class or method decorator
23
- *
24
- * @example
25
- * ```typescript
26
- * // Apply to a controller
27
- * @Controller()
28
- * @UseGuards(AuthGuard, RoleGuard)
29
- * export class UserController {
30
- * @Endpoint(getUserEndpoint)
31
- * async getUser() { }
32
- * }
33
- *
34
- * // Apply to a specific endpoint
35
- * @Controller()
36
- * export class UserController {
37
- * @Endpoint(getUserEndpoint)
38
- * @UseGuards(AuthGuard)
39
- * async getUser() { }
40
- * }
41
- * ```
42
- */
43
- export function UseGuards(
44
- ...guards: (
45
- | ClassTypeWithInstance<CanActivate>
46
- | InjectionToken<CanActivate, undefined>
47
- )[]
48
- ) {
49
- return function <T extends Function>(
50
- target: T,
51
- context: ClassMethodDecoratorContext | ClassDecoratorContext,
52
- ): T {
53
- if (context.kind === 'class') {
54
- const controllerMetadata = getControllerMetadata(
55
- target as unknown as ClassType,
56
- context,
57
- )
58
- for (const guard of guards.reverse()) {
59
- controllerMetadata.guards.add(guard)
60
- }
61
- } else if (context.kind === 'method') {
62
- const endpointMetadata = getEndpointMetadata(target, context)
63
- for (const guard of guards.reverse()) {
64
- endpointMetadata.guards.add(guard)
65
- }
66
- } else {
67
- throw new Error(
68
- '[Navios] @UseGuards decorator can only be used on classes or methods.',
69
- )
70
- }
71
- return target
72
- }
73
- }
@@ -1,28 +0,0 @@
1
- import { HttpException } from './http.exception.mjs'
2
-
3
- /**
4
- * Exception that represents a 400 Bad Request HTTP error.
5
- *
6
- * Use this exception when the client's request is malformed or invalid.
7
- *
8
- * @example
9
- * ```typescript
10
- * @Endpoint(createUserEndpoint)
11
- * async createUser(request: EndpointParams<typeof createUserEndpoint>) {
12
- * if (!request.data.email) {
13
- * throw new BadRequestException('Email is required')
14
- * }
15
- * // ...
16
- * }
17
- * ```
18
- */
19
- export class BadRequestException extends HttpException {
20
- /**
21
- * Creates a new BadRequestException.
22
- *
23
- * @param message - Error message or response object
24
- */
25
- constructor(message: string | object) {
26
- super(400, message)
27
- }
28
- }
@@ -1,31 +0,0 @@
1
- import { HttpException } from './http.exception.mjs'
2
-
3
- /**
4
- * Exception that represents a 409 Conflict HTTP error.
5
- *
6
- * Use this exception when the request conflicts with the current state of the resource
7
- * (e.g., trying to create a resource that already exists).
8
- *
9
- * @example
10
- * ```typescript
11
- * @Endpoint(createUserEndpoint)
12
- * async createUser(request: EndpointParams<typeof createUserEndpoint>) {
13
- * const existing = await this.userService.findByEmail(request.data.email)
14
- * if (existing) {
15
- * throw new ConflictException('User with this email already exists')
16
- * }
17
- * // ...
18
- * }
19
- * ```
20
- */
21
- export class ConflictException extends HttpException {
22
- /**
23
- * Creates a new ConflictException.
24
- *
25
- * @param message - Error message or response object
26
- * @param error - Optional underlying error for logging
27
- */
28
- constructor(message: string | object, error?: Error) {
29
- super(409, message, error)
30
- }
31
- }
@@ -1,30 +0,0 @@
1
- import { HttpException } from './http.exception.mjs'
2
-
3
- /**
4
- * Exception that represents a 403 Forbidden HTTP error.
5
- *
6
- * Use this exception when the client is authenticated but does not have
7
- * permission to access the requested resource.
8
- *
9
- * @example
10
- * ```typescript
11
- * @Endpoint(deleteUserEndpoint)
12
- * @UseGuards(AuthGuard, RoleGuard)
13
- * async deleteUser(request: EndpointParams<typeof deleteUserEndpoint>) {
14
- * if (!this.userService.hasPermission(request.user, 'delete')) {
15
- * throw new ForbiddenException('Insufficient permissions')
16
- * }
17
- * // ...
18
- * }
19
- * ```
20
- */
21
- export class ForbiddenException extends HttpException {
22
- /**
23
- * Creates a new ForbiddenException.
24
- *
25
- * @param message - Error message
26
- */
27
- constructor(message: string) {
28
- super(403, message)
29
- }
30
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * Base exception class for all HTTP exceptions in Navios.
3
- *
4
- * All HTTP exception classes extend this base class. When thrown from an endpoint handler,
5
- * Navios will automatically convert it to an appropriate HTTP response with the specified
6
- * status code and response body.
7
- *
8
- * @example
9
- * ```typescript
10
- * @Endpoint(getUserEndpoint)
11
- * async getUser(request: EndpointParams<typeof getUserEndpoint>) {
12
- * const user = await this.userService.findById(request.urlParams.userId)
13
- * if (!user) {
14
- * throw new HttpException(404, 'User not found')
15
- * }
16
- * return user
17
- * }
18
- * ```
19
- */
20
- export class HttpException {
21
- /**
22
- * Creates a new HttpException instance.
23
- *
24
- * @param statusCode - HTTP status code (e.g., 400, 404, 500)
25
- * @param response - Response body (string or object)
26
- * @param error - Optional underlying error for logging/debugging
27
- */
28
- constructor(
29
- public readonly statusCode: number,
30
- public readonly response: string | object,
31
- public readonly error?: Error,
32
- ) {}
33
- }
@@ -1,7 +0,0 @@
1
- export * from './http.exception.mjs'
2
- export * from './bad-request.exception.mjs'
3
- export * from './forbidden.exception.mjs'
4
- export * from './internal-server-error.exception.mjs'
5
- export * from './not-found.exception.mjs'
6
- export * from './unauthorized.exception.mjs'
7
- export * from './conflict.exception.mjs'
@@ -1,33 +0,0 @@
1
- import { HttpException } from './http.exception.mjs'
2
-
3
- /**
4
- * Exception that represents a 500 Internal Server Error HTTP error.
5
- *
6
- * Use this exception when an unexpected error occurs on the server.
7
- * Generally, you should let unhandled errors bubble up rather than catching
8
- * and rethrowing as InternalServerErrorException, as Navios will handle them appropriately.
9
- *
10
- * @example
11
- * ```typescript
12
- * @Endpoint(processPaymentEndpoint)
13
- * async processPayment(request: EndpointParams<typeof processPaymentEndpoint>) {
14
- * try {
15
- * return await this.paymentService.process(request.data)
16
- * } catch (error) {
17
- * this.logger.error('Payment processing failed', error)
18
- * throw new InternalServerErrorException('Payment processing failed', error)
19
- * }
20
- * }
21
- * ```
22
- */
23
- export class InternalServerErrorException extends HttpException {
24
- /**
25
- * Creates a new InternalServerErrorException.
26
- *
27
- * @param message - Error message or response object
28
- * @param error - Optional underlying error for logging
29
- */
30
- constructor(message: string | object, error?: Error) {
31
- super(500, message, error)
32
- }
33
- }
@@ -1,33 +0,0 @@
1
- import { HttpException } from './http.exception.mjs'
2
-
3
- /**
4
- * Exception that represents a 404 Not Found HTTP error.
5
- *
6
- * Use this exception when the requested resource does not exist.
7
- *
8
- * @example
9
- * ```typescript
10
- * @Endpoint(getUserEndpoint)
11
- * async getUser(request: EndpointParams<typeof getUserEndpoint>) {
12
- * const user = await this.userService.findById(request.urlParams.userId)
13
- * if (!user) {
14
- * throw new NotFoundException('User not found')
15
- * }
16
- * return user
17
- * }
18
- * ```
19
- */
20
- export class NotFoundException extends HttpException {
21
- /**
22
- * Creates a new NotFoundException.
23
- *
24
- * @param response - Error message or response object
25
- * @param error - Optional underlying error for logging
26
- */
27
- constructor(
28
- public readonly response: string | object,
29
- public readonly error?: Error,
30
- ) {
31
- super(404, response, error)
32
- }
33
- }
@@ -1,30 +0,0 @@
1
- import { HttpException } from './http.exception.mjs'
2
-
3
- /**
4
- * Exception that represents a 401 Unauthorized HTTP error.
5
- *
6
- * Use this exception when the client is not authenticated or authentication failed.
7
- *
8
- * @example
9
- * ```typescript
10
- * @Endpoint(getUserEndpoint)
11
- * @UseGuards(AuthGuard)
12
- * async getUser(request: EndpointParams<typeof getUserEndpoint>) {
13
- * if (!request.headers.authorization) {
14
- * throw new UnauthorizedException('Authentication required')
15
- * }
16
- * // ...
17
- * }
18
- * ```
19
- */
20
- export class UnauthorizedException extends HttpException {
21
- /**
22
- * Creates a new UnauthorizedException.
23
- *
24
- * @param message - Error message or response object
25
- * @param error - Optional underlying error for logging
26
- */
27
- constructor(message: string | object, error?: Error) {
28
- super(401, message, error)
29
- }
30
- }
@@ -1,20 +0,0 @@
1
- import type { FactoryContext } from '@navios/di'
2
-
3
- import { Factory, inject, InjectionToken } from '@navios/di'
4
-
5
- import { NaviosEnvironment } from '../navios.environment.mjs'
6
- import { AdapterToken } from '../tokens/index.mjs'
7
-
8
- @Factory({
9
- token: AdapterToken,
10
- })
11
- export class AdapterFactory {
12
- private readonly environment = inject(NaviosEnvironment)
13
- create(ctx: FactoryContext) {
14
- const service = this.environment.getToken(AdapterToken)
15
- if (!service) {
16
- throw new Error('AdapterToken service not found in environment')
17
- }
18
- return ctx.inject(service as InjectionToken<any, undefined>)
19
- }
20
- }
@@ -1,21 +0,0 @@
1
- import type { FactoryContext, InjectionToken } from '@navios/di'
2
-
3
- import { Factory, inject } from '@navios/di'
4
-
5
- import { NaviosEnvironment } from '../navios.environment.mjs'
6
- import { EndpointAdapterToken } from '../tokens/index.mjs'
7
-
8
- @Factory({
9
- token: EndpointAdapterToken,
10
- })
11
- export class EndpointAdapterFactory {
12
- private readonly environment = inject(NaviosEnvironment)
13
-
14
- create(ctx: FactoryContext) {
15
- const service = this.environment.getToken(EndpointAdapterToken)
16
- if (!service) {
17
- throw new Error('EndpointAdapterToken service not found in environment')
18
- }
19
- return ctx.inject(service as InjectionToken<any, undefined>)
20
- }
21
- }
@@ -1,20 +0,0 @@
1
- import type { FactoryContext } from '@navios/di'
2
-
3
- import { Factory, inject, InjectionToken } from '@navios/di'
4
-
5
- import { NaviosEnvironment } from '../navios.environment.mjs'
6
- import { HttpAdapterToken } from '../tokens/index.mjs'
7
-
8
- @Factory({
9
- token: HttpAdapterToken,
10
- })
11
- export class HttpAdapterFactory {
12
- private readonly environment = inject(NaviosEnvironment)
13
- create(ctx: FactoryContext) {
14
- const service = this.environment.getToken(HttpAdapterToken)
15
- if (!service) {
16
- throw new Error('HttpAdapterToken service not found in environment')
17
- }
18
- return ctx.inject(service as InjectionToken<any, undefined>)
19
- }
20
- }
@@ -1,8 +0,0 @@
1
- export * from './adapter.factory.mjs'
2
- export * from './endpoint-adapter.factory.mjs'
3
- export * from './http-adapter.factory.mjs'
4
- export * from './multipart-adapter.factory.mjs'
5
- export * from './request.factory.mjs'
6
- export * from './reply.factory.mjs'
7
- export * from './stream-adapter.factory.mjs'
8
- export * from './xml-stream-adapter.factory.mjs'
@@ -1,21 +0,0 @@
1
- import type { FactoryContext, InjectionToken } from '@navios/di'
2
-
3
- import { Factory, inject } from '@navios/di'
4
-
5
- import { NaviosEnvironment } from '../navios.environment.mjs'
6
- import { MultipartAdapterToken } from '../tokens/index.mjs'
7
-
8
- @Factory({
9
- token: MultipartAdapterToken,
10
- })
11
- export class MultipartAdapterFactory {
12
- private readonly environment = inject(NaviosEnvironment)
13
-
14
- create(ctx: FactoryContext) {
15
- const service = this.environment.getToken(MultipartAdapterToken)
16
- if (!service) {
17
- throw new Error('MultipartAdapterToken service not found in environment')
18
- }
19
- return ctx.inject(service as InjectionToken<any, undefined>)
20
- }
21
- }
@@ -1,21 +0,0 @@
1
- import type { FactoryContext, InjectionToken } from '@navios/di'
2
-
3
- import { Factory, inject, InjectableScope } from '@navios/di'
4
-
5
- import { NaviosEnvironment } from '../navios.environment.mjs'
6
- import { Reply } from '../tokens/index.mjs'
7
-
8
- @Factory({
9
- token: Reply,
10
- scope: InjectableScope.Request,
11
- })
12
- export class ReplyFactory {
13
- private readonly environment = inject(NaviosEnvironment)
14
- create(ctx: FactoryContext) {
15
- const service = this.environment.getToken(Reply)
16
- if (!service) {
17
- throw new Error('ReplyToken service not found in environment')
18
- }
19
- return ctx.inject(service as InjectionToken<any, undefined>)
20
- }
21
- }
@@ -1,21 +0,0 @@
1
- import type { FactoryContext, InjectionToken } from '@navios/di'
2
-
3
- import { Factory, inject, InjectableScope } from '@navios/di'
4
-
5
- import { NaviosEnvironment } from '../navios.environment.mjs'
6
- import { Request } from '../tokens/index.mjs'
7
-
8
- @Factory({
9
- token: Request,
10
- scope: InjectableScope.Request,
11
- })
12
- export class RequestFactory {
13
- private readonly environment = inject(NaviosEnvironment)
14
- create(ctx: FactoryContext) {
15
- const service = this.environment.getToken(Request)
16
- if (!service) {
17
- throw new Error('RequestToken service not found in environment')
18
- }
19
- return ctx.inject(service as InjectionToken<any, undefined>)
20
- }
21
- }
@@ -1,20 +0,0 @@
1
- import type { FactoryContext, InjectionToken } from '@navios/di'
2
-
3
- import { Factory, inject } from '@navios/di'
4
-
5
- import { NaviosEnvironment } from '../navios.environment.mjs'
6
- import { StreamAdapterToken } from '../tokens/index.mjs'
7
-
8
- @Factory({
9
- token: StreamAdapterToken,
10
- })
11
- export class StreamAdapterFactory {
12
- private readonly environment = inject(NaviosEnvironment)
13
- create(ctx: FactoryContext) {
14
- const service = this.environment.getToken(StreamAdapterToken)
15
- if (!service) {
16
- throw new Error('StreamAdapterToken service not found in environment')
17
- }
18
- return ctx.inject(service as InjectionToken<any, undefined>)
19
- }
20
- }
@@ -1,20 +0,0 @@
1
- import type { FactoryContext, InjectionToken } from '@navios/di'
2
-
3
- import { Factory, inject } from '@navios/di'
4
-
5
- import { NaviosEnvironment } from '../navios.environment.mjs'
6
- import { XmlStreamAdapterToken } from '../tokens/index.mjs'
7
-
8
- @Factory({
9
- token: XmlStreamAdapterToken,
10
- })
11
- export class XmlStreamAdapterFactory {
12
- private readonly environment = inject(NaviosEnvironment)
13
- create(ctx: FactoryContext) {
14
- const service = this.environment.getToken(XmlStreamAdapterToken)
15
- if (!service) {
16
- throw new Error('XmlStreamAdapterToken service not found in environment')
17
- }
18
- return ctx.inject(service as InjectionToken<any, undefined>)
19
- }
20
- }
package/src/index.mts DELETED
@@ -1,16 +0,0 @@
1
- export * from '@navios/di'
2
- export * from './config/index.mjs'
3
- export * from './decorators/index.mjs'
4
- export * from './exceptions/index.mjs'
5
- export * from './interfaces/index.mjs'
6
- export * from './logger/index.mjs'
7
- export * from './metadata/index.mjs'
8
- export * from './responders/index.mjs'
9
- export * from './services/index.mjs'
10
- export * from './stores/index.mjs'
11
- export * from './tokens/index.mjs'
12
- export * from './utils/index.mjs'
13
- export * from './attribute.factory.mjs'
14
- export * from './factories/index.mjs'
15
- export * from './navios.application.mjs'
16
- export * from './navios.factory.mjs'