@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,300 +0,0 @@
1
- import type { ControllerMetadata, HandlerMetadata, ModuleMetadata } from '../metadata/index.mjs'
2
-
3
- import { describe, expect, it } from 'vitest'
4
- import { z } from 'zod/v4'
5
-
6
- import { AttributeFactory } from '../attribute.factory.mjs'
7
-
8
- // Helper to create mock metadata objects
9
- const createMockMetadata = (
10
- attributes: Map<symbol, any> = new Map(),
11
- ): ModuleMetadata | ControllerMetadata | HandlerMetadata<any> => ({
12
- customAttributes: attributes,
13
- } as any)
14
-
15
- describe('AttributeFactory', () => {
16
- describe('createAttribute', () => {
17
- it('should create a simple attribute without schema', () => {
18
- const token = Symbol.for('TestAttribute')
19
- const attribute = AttributeFactory.createAttribute(token)
20
-
21
- expect(attribute.token).toBe(token)
22
- expect(typeof attribute).toBe('function')
23
- })
24
-
25
- it('should create an attribute with schema', () => {
26
- const token = Symbol.for('SchemaAttribute')
27
- const schema = z.object({ value: z.number() })
28
- const attribute = AttributeFactory.createAttribute(token, schema)
29
-
30
- expect(attribute.token).toBe(token)
31
- expect(attribute.schema).toBe(schema)
32
- expect(typeof attribute).toBe('function')
33
- })
34
- })
35
-
36
- describe('get', () => {
37
- it('should return true for simple attribute when present', () => {
38
- const token = Symbol.for('SimpleAttribute')
39
- const attribute = AttributeFactory.createAttribute(token)
40
-
41
- const metadata = createMockMetadata(new Map([[token, true]]))
42
-
43
- const result = AttributeFactory.get(attribute, metadata)
44
-
45
- expect(result).toBe(true)
46
- })
47
-
48
- it('should return null when attribute is not present', () => {
49
- const token = Symbol.for('MissingAttribute')
50
- const attribute = AttributeFactory.createAttribute(token)
51
-
52
- const metadata = createMockMetadata()
53
-
54
- const result = AttributeFactory.get(attribute, metadata)
55
-
56
- expect(result).toBeNull()
57
- })
58
-
59
- it('should return validated value for schema attribute', () => {
60
- const token = Symbol.for('RateLimitAttribute')
61
- const schema = z.object({ requests: z.number(), window: z.number() })
62
- const attribute = AttributeFactory.createAttribute(token, schema)
63
-
64
- const value = { requests: 100, window: 60000 }
65
- const metadata = createMockMetadata(new Map([[token, value]]))
66
-
67
- const result = AttributeFactory.get(attribute, metadata)
68
-
69
- expect(result).toEqual(value)
70
- })
71
-
72
- it('should work with different metadata types (module)', () => {
73
- const token = Symbol.for('ModuleAttribute')
74
- const attribute = AttributeFactory.createAttribute(token)
75
-
76
- const moduleMetadata = {
77
- customAttributes: new Map([[token, true]]),
78
- providers: [],
79
- controllers: new Set(),
80
- } as unknown as ModuleMetadata
81
-
82
- const result = AttributeFactory.get(attribute, moduleMetadata)
83
-
84
- expect(result).toBe(true)
85
- })
86
-
87
- it('should work with different metadata types (controller)', () => {
88
- const token = Symbol.for('ControllerAttribute')
89
- const attribute = AttributeFactory.createAttribute(token)
90
-
91
- const controllerMetadata = {
92
- customAttributes: new Map([[token, true]]),
93
- guards: new Set(),
94
- } as unknown as ControllerMetadata
95
-
96
- const result = AttributeFactory.get(attribute, controllerMetadata)
97
-
98
- expect(result).toBe(true)
99
- })
100
-
101
- it('should work with different metadata types (handler)', () => {
102
- const token = Symbol.for('HandlerAttribute')
103
- const attribute = AttributeFactory.createAttribute(token)
104
-
105
- const handlerMetadata = {
106
- customAttributes: new Map([[token, true]]),
107
- config: {},
108
- } as unknown as HandlerMetadata<any>
109
-
110
- const result = AttributeFactory.get(attribute, handlerMetadata)
111
-
112
- expect(result).toBe(true)
113
- })
114
- })
115
-
116
- describe('getAll', () => {
117
- it('should return array of values when attribute is present', () => {
118
- const token = Symbol.for('TagAttribute')
119
- const attribute = AttributeFactory.createAttribute(token)
120
-
121
- // Note: Map only stores unique keys, so getAll with Map will only return one value
122
- const metadata = createMockMetadata(new Map([[token, true]]))
123
-
124
- const result = AttributeFactory.getAll(attribute, metadata)
125
-
126
- expect(result).toEqual([true])
127
- })
128
-
129
- it('should return null when attribute is not present', () => {
130
- const token = Symbol.for('MissingAllAttribute')
131
- const attribute = AttributeFactory.createAttribute(token)
132
-
133
- const metadata = createMockMetadata()
134
-
135
- const result = AttributeFactory.getAll(attribute, metadata)
136
-
137
- expect(result).toBeNull()
138
- })
139
-
140
- it('should return array of schema values', () => {
141
- const token = Symbol.for('MultiValueAttribute')
142
- const schema = z.string()
143
- const attribute = AttributeFactory.createAttribute(token, schema)
144
-
145
- const metadata = createMockMetadata(new Map([[token, 'value1']]))
146
-
147
- const result = AttributeFactory.getAll(attribute, metadata)
148
-
149
- expect(result).toEqual(['value1'])
150
- })
151
- })
152
-
153
- describe('getLast', () => {
154
- it('should return last value from array of metadata objects', () => {
155
- const token = Symbol.for('HierarchyAttribute')
156
- const schema = z.number()
157
- const attribute = AttributeFactory.createAttribute(token, schema)
158
-
159
- const moduleMetadata = createMockMetadata(new Map([[token, 100]]))
160
- const controllerMetadata = createMockMetadata(new Map([[token, 200]]))
161
- const handlerMetadata = createMockMetadata(new Map([[token, 300]]))
162
-
163
- const result = AttributeFactory.getLast(attribute, [
164
- moduleMetadata,
165
- controllerMetadata,
166
- handlerMetadata,
167
- ])
168
-
169
- // Last one (most specific) should be returned
170
- expect(result).toBe(300)
171
- })
172
-
173
- it('should find value from earlier metadata if later ones are missing', () => {
174
- const token = Symbol.for('FallbackAttribute')
175
- const schema = z.number()
176
- const attribute = AttributeFactory.createAttribute(token, schema)
177
-
178
- const moduleMetadata = createMockMetadata(new Map([[token, 100]]))
179
- const controllerMetadata = createMockMetadata() // No attribute
180
- const handlerMetadata = createMockMetadata() // No attribute
181
-
182
- const result = AttributeFactory.getLast(attribute, [
183
- moduleMetadata,
184
- controllerMetadata,
185
- handlerMetadata,
186
- ])
187
-
188
- expect(result).toBe(100)
189
- })
190
-
191
- it('should return null when attribute is not present in any metadata', () => {
192
- const token = Symbol.for('NowhereAttribute')
193
- const attribute = AttributeFactory.createAttribute(token)
194
-
195
- const result = AttributeFactory.getLast(attribute, [
196
- createMockMetadata(),
197
- createMockMetadata(),
198
- createMockMetadata(),
199
- ])
200
-
201
- expect(result).toBeNull()
202
- })
203
-
204
- it('should return null for empty array', () => {
205
- const token = Symbol.for('EmptyArrayAttribute')
206
- const attribute = AttributeFactory.createAttribute(token)
207
-
208
- const result = AttributeFactory.getLast(attribute, [])
209
-
210
- expect(result).toBeNull()
211
- })
212
-
213
- it('should work with simple (boolean) attributes', () => {
214
- const token = Symbol.for('PublicAttribute')
215
- const attribute = AttributeFactory.createAttribute(token)
216
-
217
- const moduleMetadata = createMockMetadata()
218
- const controllerMetadata = createMockMetadata(new Map([[token, true]]))
219
- const handlerMetadata = createMockMetadata()
220
-
221
- const result = AttributeFactory.getLast(attribute, [
222
- moduleMetadata,
223
- controllerMetadata,
224
- handlerMetadata,
225
- ])
226
-
227
- expect(result).toBe(true)
228
- })
229
- })
230
-
231
- describe('has', () => {
232
- it('should return true when attribute is present', () => {
233
- const token = Symbol.for('ExistsAttribute')
234
- const attribute = AttributeFactory.createAttribute(token)
235
-
236
- const metadata = createMockMetadata(new Map([[token, true]]))
237
-
238
- const result = AttributeFactory.has(attribute, metadata)
239
-
240
- expect(result).toBe(true)
241
- })
242
-
243
- it('should return false when attribute is not present', () => {
244
- const token = Symbol.for('NotExistsAttribute')
245
- const attribute = AttributeFactory.createAttribute(token)
246
-
247
- const metadata = createMockMetadata()
248
-
249
- const result = AttributeFactory.has(attribute, metadata)
250
-
251
- expect(result).toBe(false)
252
- })
253
-
254
- it('should return true for schema attribute when present', () => {
255
- const token = Symbol.for('SchemaExistsAttribute')
256
- const schema = z.object({ key: z.string() })
257
- const attribute = AttributeFactory.createAttribute(token, schema)
258
-
259
- const metadata = createMockMetadata(new Map([[token, { key: 'value' }]]))
260
-
261
- const result = AttributeFactory.has(attribute, metadata)
262
-
263
- expect(result).toBe(true)
264
- })
265
-
266
- it('should return false for schema attribute when not present', () => {
267
- const token = Symbol.for('SchemaNotExistsAttribute')
268
- const schema = z.object({ key: z.string() })
269
- const attribute = AttributeFactory.createAttribute(token, schema)
270
-
271
- const metadata = createMockMetadata()
272
-
273
- const result = AttributeFactory.has(attribute, metadata)
274
-
275
- expect(result).toBe(false)
276
- })
277
- })
278
-
279
- describe('type safety', () => {
280
- it('should return correctly typed value for schema attributes', () => {
281
- const token = Symbol.for('TypedAttribute')
282
- const schema = z.object({
283
- requests: z.number(),
284
- window: z.number(),
285
- })
286
- const attribute = AttributeFactory.createAttribute(token, schema)
287
-
288
- const value = { requests: 100, window: 60000 }
289
- const metadata = createMockMetadata(new Map([[token, value]]))
290
-
291
- const result = AttributeFactory.get(attribute, metadata)
292
-
293
- // TypeScript should infer: { requests: number, window: number } | null
294
- if (result) {
295
- expect(typeof result.requests).toBe('number')
296
- expect(typeof result.window).toBe('number')
297
- }
298
- })
299
- })
300
- })
@@ -1,43 +0,0 @@
1
- import { env } from 'node:process'
2
-
3
- import { beforeEach, describe, expect, it } from 'vitest'
4
-
5
- import {
6
- ConfigServiceToken,
7
- Container,
8
- EnvConfigProvider,
9
- inject,
10
- Injectable,
11
- Logger,
12
- } from '../index.mjs'
13
-
14
- describe('ConfigService', () => {
15
- let container: Container
16
- beforeEach(() => {
17
- container = new Container()
18
- })
19
- it('should be able to get a config value', async () => {
20
- const service = await container.get(ConfigServiceToken, { ...env })
21
- expect(service).toBeDefined()
22
- expect(service.get('NODE_ENV')).toBe(env.NODE_ENV)
23
- })
24
-
25
- it('should be possible to use bound config service', async () => {
26
- const service = await container.get(EnvConfigProvider)
27
- expect(service).toBeDefined()
28
- expect(service.get('NODE_ENV')).toBe(env.NODE_ENV)
29
- })
30
-
31
- it('should be possible to use inside service as a inject', async () => {
32
- @Injectable()
33
- class TestService {
34
- public readonly configService = inject(EnvConfigProvider)
35
- public readonly logger = inject(Logger)
36
- }
37
-
38
- const service = await container.get(TestService)
39
-
40
- expect(service.configService).toBeDefined()
41
- expect(service.configService.get('NODE_ENV')).toBe(env.NODE_ENV)
42
- })
43
- })
@@ -1,312 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
-
3
- import { ConsoleLogger } from '../logger/console-logger.service.mjs'
4
-
5
- describe('ConsoleLogger', () => {
6
- let stdoutSpy: ReturnType<typeof vi.spyOn>
7
- let stderrSpy: ReturnType<typeof vi.spyOn>
8
-
9
- beforeEach(() => {
10
- stdoutSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true)
11
- stderrSpy = vi.spyOn(process.stderr, 'write').mockImplementation(() => true)
12
- })
13
-
14
- afterEach(() => {
15
- stdoutSpy.mockRestore()
16
- stderrSpy.mockRestore()
17
- })
18
-
19
- describe('static create()', () => {
20
- it('should create a logger instance with default options', () => {
21
- const logger = ConsoleLogger.create()
22
-
23
- expect(logger).toBeInstanceOf(ConsoleLogger)
24
- })
25
-
26
- it('should create a logger instance with context', () => {
27
- const logger = ConsoleLogger.create('TestContext')
28
-
29
- logger.log('test message')
30
-
31
- expect(stdoutSpy).toHaveBeenCalled()
32
- const output = stdoutSpy.mock.calls[0]?.[0] as string
33
- expect(output).toContain('[TestContext]')
34
- })
35
-
36
- it('should create a logger instance with options', () => {
37
- const logger = ConsoleLogger.create({
38
- showPid: false,
39
- showPrefix: false,
40
- })
41
-
42
- logger.log('test message')
43
-
44
- expect(stdoutSpy).toHaveBeenCalled()
45
- const output = stdoutSpy.mock.calls[0]?.[0] as string
46
- expect(output).not.toContain('[Navios]')
47
- expect(output).not.toContain(process.pid.toString())
48
- })
49
-
50
- it('should create a logger instance with context and options', () => {
51
- const logger = ConsoleLogger.create('TestContext', {
52
- showPid: false,
53
- })
54
-
55
- logger.log('test message')
56
-
57
- expect(stdoutSpy).toHaveBeenCalled()
58
- const output = stdoutSpy.mock.calls[0]?.[0] as string
59
- expect(output).toContain('[TestContext]')
60
- expect(output).not.toContain(process.pid.toString())
61
- })
62
- })
63
-
64
- describe('display options', () => {
65
- describe('showPid', () => {
66
- it('should show PID by default', () => {
67
- const logger = ConsoleLogger.create()
68
-
69
- logger.log('test message')
70
-
71
- const output = stdoutSpy.mock.calls[0]?.[0] as string
72
- expect(output).toContain(process.pid.toString())
73
- })
74
-
75
- it('should hide PID when showPid is false', () => {
76
- const logger = ConsoleLogger.create({ showPid: false })
77
-
78
- logger.log('test message')
79
-
80
- const output = stdoutSpy.mock.calls[0]?.[0] as string
81
- expect(output).not.toContain(` ${process.pid} `)
82
- })
83
- })
84
-
85
- describe('showPrefix', () => {
86
- it('should show prefix by default', () => {
87
- const logger = ConsoleLogger.create()
88
-
89
- logger.log('test message')
90
-
91
- const output = stdoutSpy.mock.calls[0]?.[0] as string
92
- expect(output).toContain('[Navios]')
93
- })
94
-
95
- it('should hide prefix when showPrefix is false', () => {
96
- const logger = ConsoleLogger.create({ showPrefix: false })
97
-
98
- logger.log('test message')
99
-
100
- const output = stdoutSpy.mock.calls[0]?.[0] as string
101
- expect(output).not.toContain('[Navios]')
102
- })
103
-
104
- it('should use custom prefix when provided', () => {
105
- const logger = ConsoleLogger.create({ prefix: 'MyApp' })
106
-
107
- logger.log('test message')
108
-
109
- const output = stdoutSpy.mock.calls[0]?.[0] as string
110
- expect(output).toContain('[MyApp]')
111
- })
112
- })
113
-
114
- describe('showLogLevel', () => {
115
- it('should show log level by default', () => {
116
- const logger = ConsoleLogger.create()
117
-
118
- logger.log('test message')
119
-
120
- const output = stdoutSpy.mock.calls[0]?.[0] as string
121
- expect(output).toContain('LOG')
122
- })
123
-
124
- it('should hide log level when showLogLevel is false', () => {
125
- const logger = ConsoleLogger.create({ showLogLevel: false })
126
-
127
- logger.log('test message')
128
-
129
- const output = stdoutSpy.mock.calls[0]?.[0] as string
130
- expect(output).not.toContain('LOG')
131
- })
132
- })
133
-
134
- describe('showContext', () => {
135
- it('should show context by default', () => {
136
- const logger = ConsoleLogger.create('TestContext')
137
-
138
- logger.log('test message')
139
-
140
- const output = stdoutSpy.mock.calls[0]?.[0] as string
141
- expect(output).toContain('[TestContext]')
142
- })
143
-
144
- it('should hide context when showContext is false', () => {
145
- const logger = ConsoleLogger.create('TestContext', { showContext: false })
146
-
147
- logger.log('test message')
148
-
149
- const output = stdoutSpy.mock.calls[0]?.[0] as string
150
- expect(output).not.toContain('[TestContext]')
151
- })
152
- })
153
-
154
- describe('showTimestamp', () => {
155
- it('should show timestamp by default', () => {
156
- const logger = ConsoleLogger.create()
157
-
158
- logger.log('test message')
159
-
160
- const output = stdoutSpy.mock.calls[0]?.[0] as string
161
- // Timestamp format includes date separators
162
- expect(output).toMatch(/\d{2}\/\d{2}\/\d{4}/)
163
- })
164
-
165
- it('should hide timestamp when showTimestamp is false', () => {
166
- const logger = ConsoleLogger.create({ showTimestamp: false })
167
-
168
- logger.log('test message')
169
-
170
- const output = stdoutSpy.mock.calls[0]?.[0] as string
171
- expect(output).not.toMatch(/\d{2}\/\d{2}\/\d{4}/)
172
- })
173
- })
174
-
175
- describe('showTimeDiff', () => {
176
- it('should not show time diff by default', () => {
177
- const logger = ConsoleLogger.create()
178
-
179
- logger.log('first message')
180
- logger.log('second message')
181
-
182
- const output = stdoutSpy.mock.calls[1]?.[0] as string
183
- expect(output).not.toMatch(/\+\d+ms/)
184
- })
185
-
186
- it('should show time diff when showTimeDiff is true', () => {
187
- const logger = ConsoleLogger.create({ showTimeDiff: true })
188
-
189
- logger.log('first message')
190
- logger.log('second message')
191
-
192
- const output = stdoutSpy.mock.calls[1]?.[0] as string
193
- expect(output).toMatch(/\+\d+ms/)
194
- })
195
-
196
- it('should not show time diff on first message even when enabled', () => {
197
- const logger = ConsoleLogger.create({ showTimeDiff: true })
198
-
199
- logger.log('first message')
200
-
201
- const output = stdoutSpy.mock.calls[0]?.[0] as string
202
- expect(output).not.toMatch(/\+\d+ms/)
203
- })
204
- })
205
-
206
- describe('minimal output for CLI', () => {
207
- it('should output only message when all display options are disabled', () => {
208
- const logger = ConsoleLogger.create({
209
- showPid: false,
210
- showPrefix: false,
211
- showLogLevel: false,
212
- showContext: false,
213
- showTimestamp: false,
214
- colors: false,
215
- })
216
-
217
- logger.log('hello world')
218
-
219
- const output = stdoutSpy.mock.calls[0]?.[0] as string
220
- expect(output).toBe('hello world\n')
221
- })
222
- })
223
- })
224
-
225
- describe('log levels', () => {
226
- it('should write to stdout for log level', () => {
227
- const logger = ConsoleLogger.create()
228
- logger.log('test')
229
- expect(stdoutSpy).toHaveBeenCalled()
230
- })
231
-
232
- it('should write to stderr for error level', () => {
233
- const logger = ConsoleLogger.create()
234
- logger.error('test')
235
- expect(stderrSpy).toHaveBeenCalled()
236
- })
237
-
238
- it('should write to stdout for warn level', () => {
239
- const logger = ConsoleLogger.create()
240
- logger.warn('test')
241
- expect(stdoutSpy).toHaveBeenCalled()
242
- })
243
-
244
- it('should write to stdout for debug level', () => {
245
- const logger = ConsoleLogger.create()
246
- logger.debug('test')
247
- expect(stdoutSpy).toHaveBeenCalled()
248
- })
249
-
250
- it('should write to stdout for verbose level', () => {
251
- const logger = ConsoleLogger.create()
252
- logger.verbose('test')
253
- expect(stdoutSpy).toHaveBeenCalled()
254
- })
255
-
256
- it('should write to stdout for fatal level', () => {
257
- const logger = ConsoleLogger.create()
258
- logger.fatal('test')
259
- expect(stdoutSpy).toHaveBeenCalled()
260
- })
261
- })
262
-
263
- describe('setContext', () => {
264
- it('should update context', () => {
265
- const logger = ConsoleLogger.create('InitialContext')
266
- logger.setContext('NewContext')
267
-
268
- logger.log('test message')
269
-
270
- const output = stdoutSpy.mock.calls[0]?.[0] as string
271
- expect(output).toContain('[NewContext]')
272
- expect(output).not.toContain('[InitialContext]')
273
- })
274
- })
275
-
276
- describe('resetContext', () => {
277
- it('should reset to original context', () => {
278
- const logger = ConsoleLogger.create('OriginalContext')
279
- logger.setContext('TempContext')
280
- logger.resetContext()
281
-
282
- logger.log('test message')
283
-
284
- const output = stdoutSpy.mock.calls[0]?.[0] as string
285
- expect(output).toContain('[OriginalContext]')
286
- })
287
- })
288
-
289
- describe('setLogLevels', () => {
290
- it('should filter messages based on log levels', () => {
291
- const logger = ConsoleLogger.create()
292
- logger.setLogLevels(['error'])
293
-
294
- logger.log('should not appear')
295
- logger.error('should appear')
296
-
297
- expect(stdoutSpy).not.toHaveBeenCalled()
298
- expect(stderrSpy).toHaveBeenCalled()
299
- })
300
- })
301
-
302
- describe('isLevelEnabled', () => {
303
- it('should return true for enabled levels', () => {
304
- const logger = ConsoleLogger.create()
305
- logger.setLogLevels(['log', 'error'])
306
-
307
- expect(logger.isLevelEnabled('log')).toBe(true)
308
- expect(logger.isLevelEnabled('error')).toBe(true)
309
- expect(logger.isLevelEnabled('debug')).toBe(false)
310
- })
311
- })
312
- })