@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,21 +0,0 @@
1
- /**
2
- * Available log levels in order of severity (lowest to highest).
3
- */
4
- export const LOG_LEVELS = [
5
- 'verbose',
6
- 'debug',
7
- 'log',
8
- 'warn',
9
- 'error',
10
- 'fatal',
11
- ] as const satisfies string[]
12
-
13
- /**
14
- * Log level type.
15
- *
16
- * Represents the severity level of a log message.
17
- * Levels are: 'verbose', 'debug', 'log', 'warn', 'error', 'fatal'
18
- *
19
- * @publicApi
20
- */
21
- export type LogLevel = (typeof LOG_LEVELS)[number]
@@ -1,42 +0,0 @@
1
- import type { LogLevel } from './log-levels.mjs'
2
-
3
- /**
4
- * @publicApi
5
- */
6
- export interface LoggerService {
7
- /**
8
- * Write a 'log' level log.
9
- */
10
- log(message: any, ...optionalParams: any[]): any
11
-
12
- /**
13
- * Write an 'error' level log.
14
- */
15
- error(message: any, ...optionalParams: any[]): any
16
-
17
- /**
18
- * Write a 'warn' level log.
19
- */
20
- warn(message: any, ...optionalParams: any[]): any
21
-
22
- /**
23
- * Write a 'debug' level log.
24
- */
25
- debug?(message: any, ...optionalParams: any[]): any
26
-
27
- /**
28
- * Write a 'verbose' level log.
29
- */
30
- verbose?(message: any, ...optionalParams: any[]): any
31
-
32
- /**
33
- * Write a 'fatal' level log.
34
- */
35
- fatal?(message: any, ...optionalParams: any[]): any
36
-
37
- /**
38
- * Set log levels.
39
- * @param levels log levels
40
- */
41
- setLogLevels?(levels: LogLevel[]): any
42
- }
@@ -1,113 +0,0 @@
1
- import { inject, Injectable } from '@navios/di'
2
-
3
- import type { LoggerService } from './logger-service.interface.mjs'
4
- import type { LoggerOptions } from './logger.tokens.mjs'
5
-
6
- import { Logger, LoggerOutput } from './logger.tokens.mjs'
7
-
8
- /**
9
- * Logger service instance that can be injected into services and controllers.
10
- *
11
- * Provides contextualized logging with automatic context injection.
12
- * The context is set when the logger is injected using the `inject` function.
13
- *
14
- * @example
15
- * ```typescript
16
- * @Injectable()
17
- * export class UserService {
18
- * private logger = inject(Logger, { context: UserService.name })
19
- *
20
- * async findUser(id: string) {
21
- * this.logger.log(`Finding user ${id}`)
22
- * // Logs with context: [UserService]
23
- * }
24
- * }
25
- * ```
26
- */
27
- @Injectable({
28
- token: Logger,
29
- })
30
- export class LoggerInstance implements LoggerService {
31
- protected localInstance = inject(LoggerOutput)
32
-
33
- protected context?: string
34
-
35
- constructor(config: LoggerOptions = {}) {
36
- this.context = config.context
37
- }
38
-
39
- /**
40
- * Write an 'error' level log.
41
- */
42
- error(message: any, stack?: string, context?: string): void
43
- error(message: any, ...optionalParams: [...any, string?, string?]): void
44
- error(message: any, ...optionalParams: any[]) {
45
- optionalParams = this.context
46
- ? (optionalParams.length ? optionalParams : [undefined]).concat(
47
- this.context,
48
- )
49
- : optionalParams
50
-
51
- this.localInstance?.error(message, ...optionalParams)
52
- }
53
-
54
- /**
55
- * Write a 'log' level log.
56
- */
57
- log(message: any, context?: string): void
58
- log(message: any, ...optionalParams: [...any, string?]): void
59
- log(message: any, ...optionalParams: any[]) {
60
- optionalParams = this.context
61
- ? optionalParams.concat(this.context)
62
- : optionalParams
63
- this.localInstance?.log(message, ...optionalParams)
64
- }
65
-
66
- /**
67
- * Write a 'warn' level log.
68
- */
69
- warn(message: any, context?: string): void
70
- warn(message: any, ...optionalParams: [...any, string?]): void
71
- warn(message: any, ...optionalParams: any[]) {
72
- optionalParams = this.context
73
- ? optionalParams.concat(this.context)
74
- : optionalParams
75
- this.localInstance?.warn(message, ...optionalParams)
76
- }
77
-
78
- /**
79
- * Write a 'debug' level log.
80
- */
81
- debug(message: any, context?: string): void
82
- debug(message: any, ...optionalParams: [...any, string?]): void
83
- debug(message: any, ...optionalParams: any[]) {
84
- optionalParams = this.context
85
- ? optionalParams.concat(this.context)
86
- : optionalParams
87
- this.localInstance?.debug?.(message, ...optionalParams)
88
- }
89
-
90
- /**
91
- * Write a 'verbose' level log.
92
- */
93
- verbose(message: any, context?: string): void
94
- verbose(message: any, ...optionalParams: [...any, string?]): void
95
- verbose(message: any, ...optionalParams: any[]) {
96
- optionalParams = this.context
97
- ? optionalParams.concat(this.context)
98
- : optionalParams
99
- this.localInstance?.verbose?.(message, ...optionalParams)
100
- }
101
-
102
- /**
103
- * Write a 'fatal' level log.
104
- */
105
- fatal(message: any, context?: string): void
106
- fatal(message: any, ...optionalParams: [...any, string?]): void
107
- fatal(message: any, ...optionalParams: any[]) {
108
- optionalParams = this.context
109
- ? optionalParams.concat(this.context)
110
- : optionalParams
111
- this.localInstance?.fatal?.(message, ...optionalParams)
112
- }
113
- }
@@ -1,44 +0,0 @@
1
- import { InjectionToken } from '@navios/di'
2
-
3
- import z from 'zod/v4'
4
-
5
- import type { LoggerService } from './logger-service.interface.mjs'
6
- import type { LoggerInstance } from './logger.service.mjs'
7
-
8
- /**
9
- * Injection token for the logger output service.
10
- *
11
- * This token is used to provide a custom logger implementation.
12
- * By default, it's bound to ConsoleLogger.
13
- */
14
- export const LoggerOutput = InjectionToken.create<LoggerService>('LoggerOutput')
15
-
16
- /**
17
- * Schema for logger options.
18
- */
19
- export const loggerOptionsSchema = z
20
- .object({
21
- context: z.string().optional(),
22
- })
23
- .optional()
24
-
25
- /**
26
- * Options for creating a logger instance.
27
- */
28
- export type LoggerOptions = z.infer<typeof loggerOptionsSchema>
29
-
30
- /**
31
- * Injection token for the Logger service.
32
- *
33
- * Use this token to inject a contextualized logger instance.
34
- *
35
- * @example
36
- * ```typescript
37
- * const logger = inject(Logger, { context: 'MyService' })
38
- * logger.log('Hello world') // Logs with context: [MyService]
39
- * ```
40
- */
41
- export const Logger = InjectionToken.create<
42
- LoggerInstance,
43
- typeof loggerOptionsSchema
44
- >('Logger', loggerOptionsSchema)
@@ -1,17 +0,0 @@
1
- type ColorTextFn = (text: string) => string
2
-
3
- const isColorAllowed = () => !process.env.NO_COLOR
4
- const colorIfAllowed = (colorFn: ColorTextFn) => (text: string) =>
5
- isColorAllowed() ? colorFn(text) : text
6
-
7
- export const clc = {
8
- bold: colorIfAllowed((text: string) => `\x1B[1m${text}\x1B[0m`),
9
- green: colorIfAllowed((text: string) => `\x1B[32m${text}\x1B[39m`),
10
- yellow: colorIfAllowed((text: string) => `\x1B[33m${text}\x1B[39m`),
11
- red: colorIfAllowed((text: string) => `\x1B[31m${text}\x1B[39m`),
12
- magentaBright: colorIfAllowed((text: string) => `\x1B[95m${text}\x1B[39m`),
13
- cyanBright: colorIfAllowed((text: string) => `\x1B[96m${text}\x1B[39m`),
14
- }
15
- export const yellow = colorIfAllowed(
16
- (text: string) => `\x1B[38;5;3m${text}\x1B[39m`,
17
- )
@@ -1,29 +0,0 @@
1
- import type { LogLevel } from '../log-levels.mjs'
2
-
3
- import { LOG_LEVELS } from '../log-levels.mjs'
4
- import { isLogLevel } from './is-log-level.util.mjs'
5
-
6
- /**
7
- * @publicApi
8
- */
9
- export function filterLogLevels(parseableString = ''): LogLevel[] {
10
- const sanitizedString = parseableString.replaceAll(' ', '').toLowerCase()
11
-
12
- if (sanitizedString[0] === '>') {
13
- const orEqual = sanitizedString[1] === '='
14
-
15
- const logLevelIndex = (LOG_LEVELS as string[]).indexOf(
16
- sanitizedString.substring(orEqual ? 2 : 1),
17
- )
18
-
19
- if (logLevelIndex === -1) {
20
- throw new Error(`parse error (unknown log level): ${sanitizedString}`)
21
- }
22
-
23
- return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1)
24
- } else if (sanitizedString.includes(',')) {
25
- return sanitizedString.split(',').filter(isLogLevel)
26
- }
27
-
28
- return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS
29
- }
@@ -1,5 +0,0 @@
1
- export * from './cli-colors.util.mjs'
2
- export * from './filter-log-levelts.util.mjs'
3
- export * from './is-log-level.util.mjs'
4
- export * from './is-log-level-enabled.mjs'
5
- export * from './shared.utils.mjs'
@@ -1,33 +0,0 @@
1
- import type { LogLevel } from '../log-levels.mjs'
2
-
3
- const LOG_LEVEL_VALUES: Record<LogLevel, number> = {
4
- verbose: 0,
5
- debug: 1,
6
- log: 2,
7
- warn: 3,
8
- error: 4,
9
- fatal: 5,
10
- }
11
-
12
- /**
13
- * Checks if target level is enabled.
14
- * @param targetLevel target level
15
- * @param logLevels array of enabled log levels
16
- */
17
- export function isLogLevelEnabled(
18
- targetLevel: LogLevel,
19
- logLevels: LogLevel[] | undefined,
20
- ): boolean {
21
- if (!logLevels || (Array.isArray(logLevels) && logLevels?.length === 0)) {
22
- return false
23
- }
24
- if (logLevels.includes(targetLevel)) {
25
- return true
26
- }
27
- const highestLogLevelValue = logLevels
28
- .map((level) => LOG_LEVEL_VALUES[level])
29
- .sort((a, b) => b - a)?.[0]
30
-
31
- const targetLevelValue = LOG_LEVEL_VALUES[targetLevel]
32
- return targetLevelValue >= highestLogLevelValue
33
- }
@@ -1,10 +0,0 @@
1
- import type { LogLevel } from '../log-levels.mjs'
2
-
3
- import { LOG_LEVELS } from '../log-levels.mjs'
4
-
5
- /**
6
- * @publicApi
7
- */
8
- export function isLogLevel(maybeLogLevel: any): maybeLogLevel is LogLevel {
9
- return LOG_LEVELS.includes(maybeLogLevel)
10
- }
@@ -1,51 +0,0 @@
1
- export const isUndefined = (obj: any): obj is undefined =>
2
- typeof obj === 'undefined'
3
-
4
- export const isObject = (fn: any): fn is object =>
5
- !isNil(fn) && typeof fn === 'object'
6
-
7
- export const isPlainObject = (fn: any): fn is object => {
8
- if (!isObject(fn)) {
9
- return false
10
- }
11
- const proto = Object.getPrototypeOf(fn)
12
- if (proto === null) {
13
- return true
14
- }
15
- const ctor =
16
- Object.prototype.hasOwnProperty.call(proto, 'constructor') &&
17
- proto.constructor
18
- return (
19
- typeof ctor === 'function' &&
20
- ctor instanceof ctor &&
21
- Function.prototype.toString.call(ctor) ===
22
- Function.prototype.toString.call(Object)
23
- )
24
- }
25
-
26
- export const addLeadingSlash = (path?: string): string =>
27
- path && typeof path === 'string'
28
- ? path.charAt(0) !== '/' && path.substring(0, 2) !== '{/'
29
- ? '/' + path
30
- : path
31
- : ''
32
-
33
- export const normalizePath = (path?: string): string =>
34
- path
35
- ? path.startsWith('/')
36
- ? ('/' + path.replace(/\/+$/, '')).replace(/\/+/g, '/')
37
- : '/' + path.replace(/\/+$/, '')
38
- : '/'
39
-
40
- export const stripEndSlash = (path: string) =>
41
- path[path.length - 1] === '/' ? path.slice(0, path.length - 1) : path
42
-
43
- export const isFunction = (val: any): val is Function =>
44
- typeof val === 'function'
45
- export const isString = (val: any): val is string => typeof val === 'string'
46
- export const isNumber = (val: any): val is number => typeof val === 'number'
47
- export const isConstructor = (val: any): boolean => val === 'constructor'
48
- export const isNil = (val: any): val is null | undefined =>
49
- isUndefined(val) || val === null
50
- export const isEmpty = (array: any): boolean => !(array && array.length > 0)
51
- export const isSymbol = (val: any): val is symbol => typeof val === 'symbol'
@@ -1,79 +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
- import type { HandlerMetadata } from './handler.metadata.mjs'
9
-
10
- import { getAllEndpointMetadata } from './handler.metadata.mjs'
11
-
12
- export const ControllerMetadataKey = Symbol('ControllerMetadataKey')
13
-
14
- export interface ControllerMetadata {
15
- /**
16
- * The name of the controller class.
17
- */
18
- name: string
19
- endpoints: Set<HandlerMetadata>
20
- guards: Set<
21
- ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>
22
- >
23
- customAttributes: Map<string | symbol, any>
24
- }
25
-
26
- export function getControllerMetadata(
27
- target: ClassType,
28
- context: ClassDecoratorContext,
29
- ): ControllerMetadata {
30
- if (!context.metadata) {
31
- throw new Error('[Navios] Wrong environment.')
32
- }
33
-
34
- const existingMetadata = context.metadata[ControllerMetadataKey] as
35
- | ControllerMetadata
36
- | undefined
37
-
38
- if (existingMetadata) {
39
- return existingMetadata
40
- }
41
-
42
- const newMetadata: ControllerMetadata = {
43
- name: target.name,
44
- endpoints: getAllEndpointMetadata(context),
45
- guards: new Set<
46
- ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>
47
- >(),
48
- customAttributes: new Map<string | symbol, any>(),
49
- }
50
-
51
- context.metadata[ControllerMetadataKey] = newMetadata
52
- // @ts-expect-error We add a custom metadata key to the target
53
- target[ControllerMetadataKey] = newMetadata
54
-
55
- return newMetadata
56
- }
57
-
58
- export function extractControllerMetadata(
59
- target: ClassType,
60
- ): ControllerMetadata {
61
- // @ts-expect-error We add a custom metadata key to the target
62
- const metadata = target[ControllerMetadataKey] as
63
- | ControllerMetadata
64
- | undefined
65
- if (!metadata) {
66
- throw new Error(
67
- '[Navios] Controller metadata not found. Make sure to use @Controller decorator.',
68
- )
69
- }
70
- return metadata
71
- }
72
-
73
- export function hasControllerMetadata(target: ClassType): boolean {
74
- // @ts-expect-error We add a custom metadata key to the target
75
- const metadata = target[ControllerMetadataKey] as
76
- | ControllerMetadata
77
- | undefined
78
- return !!metadata
79
- }
@@ -1,80 +0,0 @@
1
- import type { HttpMethod } from '@navios/builder'
2
- import type { ClassTypeWithInstance, InjectionToken } from '@navios/di'
3
-
4
- import type {
5
- AbstractHttpHandlerAdapterInterface,
6
- CanActivate,
7
- HttpHeader,
8
- } from '../interfaces/index.mjs'
9
-
10
- export const EndpointMetadataKey = Symbol('EndpointMetadataKey')
11
-
12
- export interface HandlerMetadata<Config = null> {
13
- classMethod: string
14
- url: string
15
- successStatusCode: number
16
- adapterToken:
17
- | InjectionToken<AbstractHttpHandlerAdapterInterface, undefined>
18
- | ClassTypeWithInstance<AbstractHttpHandlerAdapterInterface>
19
- | null
20
- headers: Partial<Record<HttpHeader, number | string | string[] | undefined>>
21
- httpMethod: HttpMethod
22
- config: Config
23
- guards: Set<
24
- ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>
25
- >
26
- customAttributes: Map<string | symbol, any>
27
- }
28
-
29
- export function getAllEndpointMetadata(
30
- context: ClassMethodDecoratorContext | ClassDecoratorContext,
31
- ): Set<HandlerMetadata<any>> {
32
- if (context.metadata) {
33
- const metadata = context.metadata[EndpointMetadataKey] as
34
- | Set<HandlerMetadata>
35
- | undefined
36
- if (metadata) {
37
- return metadata
38
- } else {
39
- context.metadata[EndpointMetadataKey] = new Set<HandlerMetadata<any>>()
40
- return context.metadata[EndpointMetadataKey] as Set<HandlerMetadata<any>>
41
- }
42
- }
43
- throw new Error('[Navios] Wrong environment.')
44
- }
45
-
46
- export function getEndpointMetadata<Config = any>(
47
- target: Function,
48
- context: ClassMethodDecoratorContext,
49
- ): HandlerMetadata<Config> {
50
- if (context.metadata) {
51
- const metadata = getAllEndpointMetadata(context)
52
- if (metadata) {
53
- const endpointMetadata = Array.from(metadata).find(
54
- (item) => item.classMethod === target.name,
55
- )
56
- if (endpointMetadata) {
57
- return endpointMetadata
58
- } else {
59
- const newMetadata: HandlerMetadata<Config> = {
60
- classMethod: target.name,
61
- url: '',
62
- successStatusCode: 200,
63
- adapterToken: null,
64
- headers: {},
65
- httpMethod: 'GET',
66
- // @ts-expect-error We are using a generic type here
67
- config: null,
68
- guards: new Set<
69
- | ClassTypeWithInstance<CanActivate>
70
- | InjectionToken<CanActivate, undefined>
71
- >(),
72
- customAttributes: new Map<string | symbol, any>(),
73
- }
74
- metadata.add(newMetadata)
75
- return newMetadata
76
- }
77
- }
78
- }
79
- throw new Error('[Navios] Wrong environment.')
80
- }
@@ -1,4 +0,0 @@
1
- export * from './controller.metadata.mjs'
2
- export * from './handler.metadata.mjs'
3
- export * from './module.metadata.mjs'
4
- export * from './navios-managed.metadata.mjs'
@@ -1,116 +0,0 @@
1
- import type {
2
- ClassType,
3
- ClassTypeWithInstance,
4
- InjectionToken,
5
- } from '@navios/di'
6
-
7
- import type { CanActivate } from '../index.mjs'
8
-
9
- export const ModuleMetadataKey = Symbol('ModuleMetadataKey')
10
-
11
- export interface ModuleMetadata {
12
- /**
13
- * The name of the module class.
14
- */
15
- name: string
16
- controllers: Set<ClassType>
17
- imports: Set<ClassType>
18
- guards: Set<
19
- ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>
20
- >
21
- overrides: Set<ClassType>
22
- customAttributes: Map<string | symbol, any>
23
- /**
24
- * Extensible entries for adapter-specific data.
25
- * Adapters can store custom metadata using symbol keys.
26
- *
27
- * @example
28
- * ```typescript
29
- * const CommandEntryKey = Symbol('CommandEntryKey')
30
- * metadata.customEntries.set(CommandEntryKey, new Set([Command1, Command2]))
31
- * ```
32
- */
33
- customEntries: Map<symbol, unknown>
34
- }
35
-
36
- export function getModuleMetadata(
37
- target: ClassType,
38
- context: ClassDecoratorContext,
39
- ): ModuleMetadata {
40
- if (!context.metadata) {
41
- throw new Error('[Navios] Wrong environment.')
42
- }
43
-
44
- const existingMetadata = context.metadata[ModuleMetadataKey] as
45
- | ModuleMetadata
46
- | undefined
47
-
48
- if (existingMetadata) {
49
- return existingMetadata
50
- }
51
-
52
- const newMetadata: ModuleMetadata = {
53
- name: target.name,
54
- controllers: new Set<ClassType>(),
55
- imports: new Set<ClassType>(),
56
- guards: new Set<
57
- ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>
58
- >(),
59
- overrides: new Set<ClassType>(),
60
- customAttributes: new Map<string | symbol, any>(),
61
- customEntries: new Map<symbol, unknown>(),
62
- }
63
-
64
- context.metadata[ModuleMetadataKey] = newMetadata
65
- // @ts-expect-error We add a custom metadata key to the target
66
- target[ModuleMetadataKey] = newMetadata
67
-
68
- return newMetadata
69
- }
70
-
71
- export function extractModuleMetadata(target: ClassType): ModuleMetadata {
72
- // @ts-expect-error We add a custom metadata key to the target
73
- const metadata = target[ModuleMetadataKey] as ModuleMetadata | undefined
74
- if (!metadata) {
75
- throw new Error(
76
- `[Navios] Module metadata not found for ${target.name}. Make sure to use @Module decorator.`,
77
- )
78
- }
79
- return metadata
80
- }
81
-
82
- export function hasModuleMetadata(target: ClassType): boolean {
83
- // @ts-expect-error We add a custom metadata key to the target
84
- return !!target[ModuleMetadataKey]
85
- }
86
-
87
- /**
88
- * Type-safe helper to get or create a custom entry in module metadata.
89
- * Adapters use this to store their own metadata in modules.
90
- *
91
- * @param metadata - The module metadata object
92
- * @param key - Symbol key for the custom entry
93
- * @param defaultValue - Factory function to create default value if entry doesn't exist
94
- * @returns The existing or newly created entry value
95
- *
96
- * @example
97
- * ```typescript
98
- * const CommandEntryKey = Symbol('CommandEntryKey')
99
- * const commands = getModuleCustomEntry<Set<ClassType>>(
100
- * metadata,
101
- * CommandEntryKey,
102
- * () => new Set(),
103
- * )
104
- * commands.add(MyCommand)
105
- * ```
106
- */
107
- export function getModuleCustomEntry<T>(
108
- metadata: ModuleMetadata,
109
- key: symbol,
110
- defaultValue: () => T,
111
- ): T {
112
- if (!metadata.customEntries.has(key)) {
113
- metadata.customEntries.set(key, defaultValue())
114
- }
115
- return metadata.customEntries.get(key) as T
116
- }