@navios/core 1.1.0 → 2.0.0-alpha.1

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