@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,32 +0,0 @@
1
- import type { ModuleMetadata } from '../metadata/index.mjs'
2
-
3
- /**
4
- * Base interface for all Navios adapters (HTTP, CLI, etc.).
5
- *
6
- * Adapters implement this interface to provide runtime-specific functionality.
7
- * This interface defines the common lifecycle methods shared across all adapter types.
8
- */
9
- export interface AbstractAdapterInterface {
10
- /**
11
- * Sets up the adapter with the provided options.
12
- * Called during application initialization before modules are initialized.
13
- */
14
- setupAdapter(options: unknown): Promise<void>
15
-
16
- /**
17
- * Called after all modules are loaded.
18
- * Adapters use this to register routes, commands, or other module-based functionality.
19
- */
20
- onModulesInit(modules: Map<string, ModuleMetadata>): Promise<void>
21
-
22
- /**
23
- * Signals that the adapter is ready to handle requests/commands.
24
- * Called after onModulesInit completes.
25
- */
26
- ready(): Promise<void>
27
-
28
- /**
29
- * Disposes of the adapter and cleans up resources.
30
- */
31
- dispose(): Promise<void>
32
- }
@@ -1,48 +0,0 @@
1
- import type {
2
- ControllerMetadata,
3
- HandlerMetadata,
4
- ModuleMetadata,
5
- } from '../metadata/index.mjs'
6
-
7
- /**
8
- * Interface providing access to the execution context during request handling.
9
- *
10
- * The execution context provides access to metadata and request/reply objects
11
- * for the current request. It is available in guards and can be injected into
12
- * services if needed.
13
- *
14
- * @example
15
- * ```typescript
16
- * @Injectable()
17
- * export class AuthGuard implements CanActivate {
18
- * async canActivate(context: AbstractExecutionContext): Promise<boolean> {
19
- * const request = context.getRequest()
20
- * const handler = context.getHandler()
21
- * // Access request and handler metadata
22
- * return true
23
- * }
24
- * }
25
- * ```
26
- */
27
- export interface AbstractExecutionContext {
28
- /**
29
- * Gets the metadata for the module containing the current endpoint.
30
- */
31
- getModule(): ModuleMetadata
32
- /**
33
- * Gets the metadata for the controller containing the current endpoint.
34
- */
35
- getController(): ControllerMetadata
36
- /**
37
- * Gets the metadata for the current endpoint handler.
38
- */
39
- getHandler(): HandlerMetadata
40
- /**
41
- * Gets the HTTP request object (adapter-specific).
42
- */
43
- getRequest(): any
44
- /**
45
- * Gets the HTTP reply object (adapter-specific).
46
- */
47
- getReply(): any
48
- }
@@ -1,79 +0,0 @@
1
- import type { ModuleMetadata } from '../metadata/index.mjs'
2
- import type { AbstractAdapterInterface } from './abstract-adapter.interface.mjs'
3
- import type { HttpAdapterEnvironment } from './adapter-environment.interface.mjs'
4
-
5
- /**
6
- * Interface for HTTP adapters extending the base adapter interface.
7
- *
8
- * Adapters implement this interface to provide runtime-specific HTTP server
9
- * functionality (Fastify, Bun, etc.).
10
- *
11
- * @typeParam Environment - The adapter environment providing type-safe access to
12
- * server instance, CORS options, listen options, etc.
13
- */
14
- export interface AbstractHttpAdapterInterface<
15
- Environment extends HttpAdapterEnvironment = HttpAdapterEnvironment,
16
- > extends AbstractAdapterInterface {
17
- /**
18
- * Sets up the adapter with the provided options.
19
- * Called during application initialization before modules are initialized.
20
- */
21
- setupAdapter(options: Environment['options']): Promise<void>
22
-
23
- /**
24
- * Called after all modules are loaded to register routes.
25
- */
26
- onModulesInit(modules: Map<string, ModuleMetadata>): Promise<void>
27
-
28
- /**
29
- * Signals that the server is ready to accept requests.
30
- */
31
- ready(): Promise<void>
32
-
33
- /**
34
- * Disposes of the server and cleans up resources.
35
- */
36
- dispose(): Promise<void>
37
-
38
- /**
39
- * Returns the underlying HTTP server instance.
40
- */
41
- getServer(): Environment['server']
42
-
43
- /**
44
- * Sets a global prefix for all routes.
45
- */
46
- setGlobalPrefix(prefix: string): void
47
-
48
- /**
49
- * Gets the current global prefix.
50
- * Returns empty string if no prefix is set.
51
- */
52
- getGlobalPrefix(): string
53
-
54
- /**
55
- * Enables CORS with the specified options.
56
- */
57
- enableCors(options: Environment['corsOptions']): void
58
-
59
- /**
60
- * Enables multipart form data handling.
61
- */
62
- enableMultipart(options: Environment['multipartOptions']): void
63
-
64
- /**
65
- * Starts the server and listens for incoming requests.
66
- */
67
- listen(options: Environment['listenOptions']): Promise<string>
68
-
69
- /**
70
- * Configures the adapter with additional options before init.
71
- *
72
- * This method allows setting adapter-specific configuration options
73
- * before the server is initialized. Options set via configure() are
74
- * merged with options passed to setupAdapter().
75
- *
76
- * Must be called before setupAdapter().
77
- */
78
- configure(options: Partial<Environment['options']>): void
79
- }
@@ -1,59 +0,0 @@
1
- import type { LogLevel } from '../logger/index.mjs'
2
-
3
- interface ArrayOfValueOrArray<T> extends Array<ValueOrArray<T>> {}
4
-
5
- type OriginType = string | boolean | RegExp
6
- type ValueOrArray<T> = T | ArrayOfValueOrArray<T>
7
-
8
- export interface AbstractHttpCorsOptions {
9
- /**
10
- * Configures the Access-Control-Allow-Origin CORS header.
11
- */
12
- origin?: ValueOrArray<OriginType>
13
- /**
14
- * Configures the Access-Control-Allow-Credentials CORS header.
15
- * Set to true to pass the header, otherwise it is omitted.
16
- */
17
- credentials?: boolean
18
- /**
19
- * Configures the Access-Control-Expose-Headers CORS header.
20
- * Expects a comma-delimited string (ex: 'Content-Range,X-Content-Range')
21
- * or an array (ex: ['Content-Range', 'X-Content-Range']).
22
- * If not specified, no custom headers are exposed.
23
- */
24
- exposedHeaders?: string | string[]
25
- /**
26
- * Configures the Access-Control-Allow-Headers CORS header.
27
- * Expects a comma-delimited string (ex: 'Content-Type,Authorization')
28
- * or an array (ex: ['Content-Type', 'Authorization']). If not
29
- * specified, defaults to reflecting the headers specified in the
30
- * request's Access-Control-Request-Headers header.
31
- */
32
- allowedHeaders?: string | string[]
33
- /**
34
- * Configures the Access-Control-Allow-Methods CORS header.
35
- * Expects a comma-delimited string (ex: 'GET,PUT,POST') or an array (ex: ['GET', 'PUT', 'POST']).
36
- */
37
- methods?: string | string[]
38
- /**
39
- * Configures the Access-Control-Max-Age CORS header.
40
- * Set to an integer to pass the header, otherwise it is omitted.
41
- */
42
- maxAge?: number
43
- /**
44
- * Configures the Cache-Control header for CORS preflight responses.
45
- * Set to an integer to pass the header as `Cache-Control: max-age=${cacheControl}`,
46
- * or set to a string to pass the header as `Cache-Control: ${cacheControl}` (fully define
47
- * the header value), otherwise the header is omitted.
48
- */
49
- cacheControl?: number | string
50
-
51
- /**
52
- * Sets the Fastify log level specifically for the internal OPTIONS route
53
- * used to handle CORS preflight requests. For example, setting this to `'silent'`
54
- * will prevent these requests from being logged.
55
- * Useful for reducing noise in application logs.
56
- * Default: inherits Fastify's global log level.
57
- */
58
- logLevel?: LogLevel
59
- }
@@ -1,127 +0,0 @@
1
- import type { ClassType, ScopedContainer } from '@navios/di'
2
-
3
- import type { HandlerMetadata } from '../metadata/index.mjs'
4
-
5
- /**
6
- * Static handler result - handler can be called without a scoped container.
7
- * Used when the controller and all its dependencies are singletons.
8
- */
9
- export type StaticHandler<TRequest = any, TReply = any> = {
10
- isStatic: true
11
- handler: (request: TRequest, reply: TReply) => Promise<any>
12
- }
13
-
14
- /**
15
- * Dynamic handler result - handler requires a scoped container for resolution.
16
- * Used when the controller or its dependencies need per-request resolution.
17
- */
18
- export type DynamicHandler<TRequest = any, TReply = any> = {
19
- isStatic: false
20
- handler: (
21
- scoped: ScopedContainer,
22
- request: TRequest,
23
- reply: TReply,
24
- ) => Promise<any>
25
- }
26
-
27
- /**
28
- * Handler result returned by provideHandler.
29
- * Can be either static (pre-resolved) or dynamic (needs scoped container).
30
- */
31
- export type HandlerResult<TRequest = any, TReply = any> =
32
- | StaticHandler<TRequest, TReply>
33
- | DynamicHandler<TRequest, TReply>
34
-
35
- /**
36
- * Function type for argument getters that extract data from requests.
37
- * Each getter populates a target object with data from the request.
38
- */
39
- export type ArgumentGetterFn<TRequest = any> = (
40
- target: Record<string, any>,
41
- request: TRequest,
42
- ) => void | Promise<void>
43
-
44
- /**
45
- * Function type for formatting arguments from a request.
46
- * Built from argument getters, optimized for sync/async handling.
47
- */
48
- export type FormatArgumentsFn<TRequest = any> = (
49
- request: TRequest,
50
- ) => Record<string, any> | Promise<Record<string, any>>
51
-
52
- /**
53
- * Interface for HTTP handler adapter services.
54
- *
55
- * Adapters handle different types of HTTP requests (REST, streaming, multipart)
56
- * and are responsible for:
57
- * - Parsing and validating request data
58
- * - Creating handler functions
59
- * - Formatting responses
60
- * - Providing schema information (for frameworks like Fastify)
61
- */
62
- export interface AbstractHttpHandlerAdapterInterface<TRequest = any> {
63
- /**
64
- * Prepares argument getters for parsing request data.
65
- *
66
- * Creates functions that extract and validate data from the request,
67
- * populating a target object with validated arguments.
68
- *
69
- * @param handlerMetadata - The handler metadata with schemas and configuration.
70
- * @returns An array of getter functions that populate request arguments.
71
- */
72
- prepareArguments?: (
73
- handlerMetadata: HandlerMetadata<any>,
74
- ) => ArgumentGetterFn<TRequest>[]
75
-
76
- /**
77
- * Builds a formatArguments function from argument getters.
78
- *
79
- * Automatically detects sync vs async getters and optimizes accordingly:
80
- * - If all getters are sync: returns sync function (no Promise overhead)
81
- * - If any getter is async: returns async function with Promise.all
82
- * - If no getters: returns frozen empty object (zero allocation)
83
- *
84
- * This method is useful for composition-based adapters that need to
85
- * build formatArguments without duplicating the optimization logic.
86
- *
87
- * @param getters - Array of argument getter functions
88
- * @returns Function to format arguments from request
89
- */
90
- buildFormatArguments?: (
91
- getters: ArgumentGetterFn<TRequest>[],
92
- ) => FormatArgumentsFn<TRequest>
93
-
94
- /**
95
- * Checks if the handler has any validation schemas defined.
96
- *
97
- * @param handlerMetadata - The handler metadata containing configuration.
98
- * @returns `true` if the handler has any schemas (request, query, response).
99
- */
100
- hasSchema?: (handlerMetadata: HandlerMetadata<any>) => boolean
101
-
102
- /**
103
- * Provides schema information for the framework's validation system.
104
- *
105
- * For frameworks like Fastify, this returns route schema objects.
106
- * For frameworks like Bun, this typically returns an empty object.
107
- *
108
- * @param handlerMetadata - The handler metadata containing configuration.
109
- * @returns Schema information for framework registration.
110
- */
111
- provideSchema?: (handlerMetadata: HandlerMetadata<any>) => Record<string, any>
112
-
113
- /**
114
- * Creates a request handler function for the endpoint.
115
- *
116
- * This is the core method that generates the actual handler function
117
- * that will be called when a request matches the endpoint.
118
- *
119
- * @param controller - The controller class containing the handler method.
120
- * @param handlerMetadata - The handler metadata with configuration and schemas.
121
- * @returns A handler result that is either static or dynamic.
122
- */
123
- provideHandler: (
124
- controller: ClassType,
125
- handlerMetadata: HandlerMetadata<any>,
126
- ) => Promise<HandlerResult>
127
- }
@@ -1,4 +0,0 @@
1
- export interface AbstractHttpListenOptions {
2
- port: number
3
- host?: string
4
- }
@@ -1,74 +0,0 @@
1
- import type { AbstractAdapterInterface } from './abstract-adapter.interface.mjs'
2
-
3
- /**
4
- * Base interface for adapter environments.
5
- *
6
- * All adapter environments extend this interface to provide
7
- * type-safe access to adapter-specific configuration options.
8
- */
9
- export interface AdapterEnvironment {
10
- /**
11
- * Adapter setup/configuration options type
12
- */
13
- options: unknown
14
- /**
15
- * Adapter type
16
- */
17
- adapter: AbstractAdapterInterface
18
- }
19
-
20
- /**
21
- * Environment interface for HTTP adapters.
22
- *
23
- * Each HTTP adapter (Fastify, Bun, etc.) implements this interface to provide
24
- * type-safe access to HTTP-specific types throughout the application.
25
- *
26
- * @example
27
- * ```typescript
28
- * // Using with a specific adapter
29
- * import { FastifyEnvironment } from '@navios/adapter-fastify'
30
- *
31
- * const app = await NaviosFactory.create<FastifyEnvironment>(AppModule, {
32
- * adapter: defineFastifyEnvironment(),
33
- * })
34
- *
35
- * // All methods are now type-safe for Fastify
36
- * app.configure({ trustProxy: true })
37
- * app.enableCors({ origin: true }) // FastifyCorsOptions
38
- * const server = app.getServer() // FastifyInstance
39
- * await app.listen({ port: 3000 }) // FastifyListenOptions
40
- * ```
41
- */
42
- export interface HttpAdapterEnvironment extends AdapterEnvironment {
43
- /**
44
- * The underlying HTTP server instance type (e.g., FastifyInstance, Bun.Server)
45
- */
46
- server: unknown
47
-
48
- /**
49
- * CORS configuration options type
50
- */
51
- corsOptions: unknown
52
-
53
- /**
54
- * Multipart form data configuration options type
55
- */
56
- multipartOptions: unknown
57
-
58
- /**
59
- * Server listen options type (port, host, etc.)
60
- */
61
- listenOptions: unknown
62
- }
63
-
64
- /**
65
- * Default environment with unknown types.
66
- *
67
- * Forces users to specify an Environment generic for type-safe adapter access.
68
- * When no generic is provided to `NaviosApplication` or `NaviosFactory.create()`,
69
- * this default is used, resulting in `unknown` types for all adapter-specific
70
- * methods.
71
- */
72
- export interface DefaultAdapterEnvironment extends AdapterEnvironment {
73
- options: unknown
74
- }
@@ -1,38 +0,0 @@
1
- import type { AbstractExecutionContext } from '../interfaces/index.mjs'
2
-
3
- /**
4
- * Interface that guards must implement to control access to endpoints.
5
- *
6
- * Guards are used for authentication, authorization, and request validation.
7
- * They are executed before the endpoint handler and can prevent the request
8
- * from proceeding by returning `false` or throwing an exception.
9
- *
10
- * @example
11
- * ```typescript
12
- * @Injectable()
13
- * export class AuthGuard implements CanActivate {
14
- * async canActivate(context: AbstractExecutionContext): Promise<boolean> {
15
- * const request = context.getRequest()
16
- * const token = request.headers.authorization
17
- *
18
- * if (!token) {
19
- * throw new UnauthorizedException('Authentication required')
20
- * }
21
- *
22
- * // Validate token
23
- * return true
24
- * }
25
- * }
26
- * ```
27
- */
28
- export interface CanActivate {
29
- /**
30
- * Determines if the current request can proceed to the endpoint handler.
31
- *
32
- * @param executionContext - The execution context containing request, reply, and metadata
33
- * @returns `true` if the request can proceed, `false` otherwise. Can also throw an exception.
34
- */
35
- canActivate(
36
- executionContext: AbstractExecutionContext,
37
- ): Promise<boolean> | boolean
38
- }
@@ -1,18 +0,0 @@
1
- import type { OutgoingHttpHeaders } from 'http'
2
-
3
- export type OmitIndexSignature<T> = {
4
- [K in keyof T as string extends K
5
- ? never
6
- : number extends K
7
- ? never
8
- : K]: T[K]
9
- }
10
-
11
- /**
12
- * HTTP header strings
13
- * Use this type only for input values, not for output values.
14
- */
15
-
16
- export type HttpHeader =
17
- | keyof OmitIndexSignature<OutgoingHttpHeaders>
18
- | (string & Record<never, never>)
@@ -1,11 +0,0 @@
1
- export * from './abstract-adapter.interface.mjs'
2
- export * from './abstract-execution-context.inteface.mjs'
3
- export * from './adapter-environment.interface.mjs'
4
- export * from './abstract-http-adapter.interface.mjs'
5
- export * from './abstract-http-cors-options.interface.mjs'
6
- export * from './abstract-http-handler-adapter.interface.mjs'
7
- export * from './abstract-http-listen-options.interface.mjs'
8
- export * from './can-activate.mjs'
9
- export * from './http-header.mjs'
10
- export * from './navios-module.mjs'
11
- export * from './plugin.interface.mjs'
@@ -1,28 +0,0 @@
1
- /**
2
- * Interface that all Navios modules must implement.
3
- *
4
- * Modules decorated with @Module() should implement this interface to receive
5
- * lifecycle hooks.
6
- *
7
- * @example
8
- * ```typescript
9
- * @Module({
10
- * controllers: [UserController],
11
- * })
12
- * export class AppModule implements NaviosModule {
13
- * async onModuleInit() {
14
- * console.log('AppModule initialized')
15
- * // Perform initialization logic
16
- * }
17
- * }
18
- * ```
19
- */
20
- export interface NaviosModule {
21
- /**
22
- * Optional lifecycle hook called after the module is initialized.
23
- *
24
- * This is called after all modules are loaded and the HTTP server is set up
25
- * (if an adapter is configured), but before the server starts listening.
26
- */
27
- onModuleInit?: () => Promise<void> | void
28
- }
@@ -1,139 +0,0 @@
1
- import type { Container } from '@navios/di'
2
-
3
- import type { ModuleMetadata } from '../metadata/index.mjs'
4
- import type { ModuleLoaderService } from '../services/module-loader.service.mjs'
5
- import type { AbstractAdapterInterface } from './abstract-adapter.interface.mjs'
6
-
7
- /**
8
- * Context provided to plugins during registration.
9
- *
10
- * This context gives plugins access to the application's modules,
11
- * adapter instance, DI container, and module loader.
12
- *
13
- * @typeParam TAdapter - The adapter type, defaults to AbstractAdapterInterface
14
- *
15
- * @example
16
- * ```typescript
17
- * // Generic plugin that works with any adapter
18
- * async register(context: PluginContext) {
19
- * const modules = context.modules
20
- * // ...
21
- * }
22
- *
23
- * // Adapter-specific plugin with typed adapter
24
- * async register(context: PluginContext<BunApplicationService>) {
25
- * const server = context.adapter.getServer() // Typed as Bun.Server
26
- * // ...
27
- * }
28
- * ```
29
- */
30
- export interface PluginContext<
31
- TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
32
- > {
33
- /**
34
- * All loaded modules with their metadata.
35
- * Keys are module class names, values are their metadata.
36
- */
37
- modules: Map<string, ModuleMetadata>
38
-
39
- /**
40
- * The current adapter instance.
41
- * Use type guards or cast to adapter-specific types for HTTP methods.
42
- */
43
- adapter: TAdapter
44
-
45
- /**
46
- * The dependency injection container.
47
- */
48
- container: Container
49
-
50
- /**
51
- * Module loader service for extending the module tree.
52
- * Use `moduleLoader.extendModules()` to add controllers dynamically.
53
- */
54
- moduleLoader: ModuleLoaderService
55
- }
56
-
57
- /**
58
- * Base interface for Navios plugins.
59
- *
60
- * Plugins are registered using `app.usePlugin()` and are initialized
61
- * after all modules are loaded but before the server starts listening.
62
- *
63
- * @typeParam TOptions - The type of options the plugin accepts
64
- * @typeParam TAdapter - The adapter type the plugin requires
65
- *
66
- * @example
67
- * ```typescript
68
- * // Generic plugin
69
- * const myPlugin: NaviosPlugin<{ enabled: boolean }> = {
70
- * name: 'my-plugin',
71
- * register: async (context, options) => {
72
- * if (options.enabled) {
73
- * // Register routes, services, etc.
74
- * }
75
- * },
76
- * }
77
- *
78
- * // Adapter-specific plugin
79
- * const fastifyPlugin: NaviosPlugin<Options, FastifyApplicationService> = {
80
- * name: 'fastify-plugin',
81
- * register: async (context, options) => {
82
- * const fastify = context.adapter.getServer() // Typed!
83
- * },
84
- * }
85
- * ```
86
- */
87
- export interface NaviosPlugin<
88
- TOptions = unknown,
89
- TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
90
- > {
91
- /**
92
- * Plugin name for identification and logging.
93
- */
94
- name: string
95
-
96
- /**
97
- * Called after modules are loaded but before the server starts listening.
98
- *
99
- * @param context - The plugin context with access to modules and adapter
100
- * @param options - Plugin-specific configuration options
101
- */
102
- register(
103
- context: PluginContext<TAdapter>,
104
- options: TOptions,
105
- ): Promise<void> | void
106
- }
107
-
108
- /**
109
- * Plugin definition combining a plugin with its options.
110
- *
111
- * This is the type returned by plugin factory functions like `defineOpenApiPlugin()`.
112
- *
113
- * @typeParam TOptions - The type of options the plugin accepts
114
- * @typeParam TAdapter - The adapter type the plugin requires
115
- *
116
- * @example
117
- * ```typescript
118
- * function defineMyPlugin(options: MyPluginOptions): PluginDefinition<MyPluginOptions> {
119
- * return {
120
- * plugin: myPlugin,
121
- * options,
122
- * }
123
- * }
124
- * ```
125
- */
126
- export interface PluginDefinition<
127
- TOptions = unknown,
128
- TAdapter extends AbstractAdapterInterface = AbstractAdapterInterface,
129
- > {
130
- /**
131
- * The plugin instance.
132
- */
133
- plugin: NaviosPlugin<TOptions, TAdapter>
134
-
135
- /**
136
- * Options to pass to the plugin's register function.
137
- */
138
- options: TOptions
139
- }