@navios/core 1.0.0 → 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/CHANGELOG.md +97 -11
  2. package/README.md +67 -220
  3. package/lib/async-context-6pdlnNLA.d.mts +237 -0
  4. package/lib/async-context-6pdlnNLA.d.mts.map +1 -0
  5. package/lib/async-context-Dqk7pE-D.d.cts +237 -0
  6. package/lib/async-context-Dqk7pE-D.d.cts.map +1 -0
  7. package/lib/attribute-factory-B3VuYnp7.d.cts +70 -0
  8. package/lib/attribute-factory-B3VuYnp7.d.cts.map +1 -0
  9. package/lib/attribute-factory-mKOXoVnV.d.mts +70 -0
  10. package/lib/attribute-factory-mKOXoVnV.d.mts.map +1 -0
  11. package/lib/attribute-value-CjX9ZkLq.cjs +172 -0
  12. package/lib/attribute-value-CjX9ZkLq.cjs.map +1 -0
  13. package/lib/attribute-value-DMEA255r.mjs +119 -0
  14. package/lib/attribute-value-DMEA255r.mjs.map +1 -0
  15. package/lib/basic-execution-context-CeGuhMOz.mjs +246 -0
  16. package/lib/basic-execution-context-CeGuhMOz.mjs.map +1 -0
  17. package/lib/basic-execution-context-DSk5MNtc.cjs +281 -0
  18. package/lib/basic-execution-context-DSk5MNtc.cjs.map +1 -0
  19. package/lib/execution-context-BPD3FeFb.d.mts +71 -0
  20. package/lib/execution-context-BPD3FeFb.d.mts.map +1 -0
  21. package/lib/execution-context-BTJdHhbf.d.cts +71 -0
  22. package/lib/execution-context-BTJdHhbf.d.cts.map +1 -0
  23. package/lib/execution-context-token-BXUKB2hf.cjs +112 -0
  24. package/lib/execution-context-token-BXUKB2hf.cjs.map +1 -0
  25. package/lib/execution-context-token-CrXmTvk2.mjs +77 -0
  26. package/lib/execution-context-token-CrXmTvk2.mjs.map +1 -0
  27. package/lib/index.cjs +1687 -4409
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +838 -3
  30. package/lib/index.d.cts.map +1 -0
  31. package/lib/index.d.mts +838 -3
  32. package/lib/index.d.mts.map +1 -0
  33. package/lib/index.mjs +1573 -4219
  34. package/lib/index.mjs.map +1 -1
  35. package/lib/legacy-compat/index.cjs +72 -371
  36. package/lib/legacy-compat/index.cjs.map +1 -1
  37. package/lib/legacy-compat/index.d.cts +42 -382
  38. package/lib/legacy-compat/index.d.cts.map +1 -1
  39. package/lib/legacy-compat/index.d.mts +41 -382
  40. package/lib/legacy-compat/index.d.mts.map +1 -1
  41. package/lib/legacy-compat/index.mjs +51 -345
  42. package/lib/legacy-compat/index.mjs.map +1 -1
  43. package/lib/module-Bha7GER_.mjs +135 -0
  44. package/lib/module-Bha7GER_.mjs.map +1 -0
  45. package/lib/module-DZewk_2r.cjs +164 -0
  46. package/lib/module-DZewk_2r.cjs.map +1 -0
  47. package/lib/module-graph-DCP9MHG0.cjs +147 -0
  48. package/lib/module-graph-DCP9MHG0.cjs.map +1 -0
  49. package/lib/module-graph-xvVEykFM.mjs +142 -0
  50. package/lib/module-graph-xvVEykFM.mjs.map +1 -0
  51. package/lib/module-metadata-C8S92seK.cjs +95 -0
  52. package/lib/module-metadata-C8S92seK.cjs.map +1 -0
  53. package/lib/module-metadata-k3RTt20x.mjs +66 -0
  54. package/lib/module-metadata-k3RTt20x.mjs.map +1 -0
  55. package/lib/module-options-Dmse0gii.d.mts +51 -0
  56. package/lib/module-options-Dmse0gii.d.mts.map +1 -0
  57. package/lib/module-options-IuDO-p8u.d.cts +51 -0
  58. package/lib/module-options-IuDO-p8u.d.cts.map +1 -0
  59. package/lib/testing/index.cjs +96 -414
  60. package/lib/testing/index.cjs.map +1 -1
  61. package/lib/testing/index.d.cts +25 -385
  62. package/lib/testing/index.d.cts.map +1 -1
  63. package/lib/testing/index.d.mts +24 -385
  64. package/lib/testing/index.d.mts.map +1 -1
  65. package/lib/testing/index.mjs +94 -408
  66. package/lib/testing/index.mjs.map +1 -1
  67. package/lib/transport.cjs +25 -0
  68. package/lib/transport.d.cts +190 -0
  69. package/lib/transport.d.cts.map +1 -0
  70. package/lib/transport.d.mts +190 -0
  71. package/lib/transport.d.mts.map +1 -0
  72. package/lib/transport.mjs +7 -0
  73. package/package.json +37 -17
  74. package/docs/README.md +0 -316
  75. package/docs/adapters.md +0 -308
  76. package/docs/application-setup.md +0 -524
  77. package/docs/attributes.md +0 -689
  78. package/docs/controllers.md +0 -373
  79. package/docs/endpoints.md +0 -444
  80. package/docs/exceptions.md +0 -352
  81. package/docs/guards.md +0 -550
  82. package/docs/legacy-compat.md +0 -356
  83. package/docs/modules.md +0 -377
  84. package/docs/quick-start.md +0 -290
  85. package/docs/services.md +0 -427
  86. package/docs/testing.md +0 -827
  87. package/lib/index-C0Sg16Eb.d.cts +0 -3365
  88. package/lib/index-C0Sg16Eb.d.cts.map +0 -1
  89. package/lib/index-DySQ6Dpd.d.mts +0 -3365
  90. package/lib/index-DySQ6Dpd.d.mts.map +0 -1
  91. package/lib/navios.factory-CO5MB_OK.cjs +0 -4125
  92. package/lib/navios.factory-CO5MB_OK.cjs.map +0 -1
  93. package/lib/navios.factory-D6Y94P9B.mjs +0 -3828
  94. package/lib/navios.factory-D6Y94P9B.mjs.map +0 -1
  95. package/lib/tokens-4J9sredA.mjs +0 -100
  96. package/lib/tokens-4J9sredA.mjs.map +0 -1
  97. package/lib/tokens-CWw9kyeD.cjs +0 -196
  98. package/lib/tokens-CWw9kyeD.cjs.map +0 -1
  99. package/lib/use-guards.decorator-BecoQSmE.mjs +0 -339
  100. package/lib/use-guards.decorator-BecoQSmE.mjs.map +0 -1
  101. package/lib/use-guards.decorator-C4ml9XaT.cjs +0 -447
  102. package/lib/use-guards.decorator-C4ml9XaT.cjs.map +0 -1
  103. package/project.json +0 -66
  104. package/src/__tests__/attribute.factory.spec.mts +0 -300
  105. package/src/__tests__/config.service.spec.mts +0 -43
  106. package/src/__tests__/console-logger.service.spec.mts +0 -312
  107. package/src/__tests__/controller-resolver.spec.mts +0 -229
  108. package/src/__tests__/controller.spec.mts +0 -58
  109. package/src/__tests__/guard-runner.service.spec.mts +0 -399
  110. package/src/__tests__/logger.service.spec.mts +0 -147
  111. package/src/__tests__/responders.spec.mts +0 -340
  112. package/src/__tests__/testing-module.spec.mts +0 -459
  113. package/src/__tests__/unit-testing-module.spec.mts +0 -424
  114. package/src/attribute.factory.mts +0 -325
  115. package/src/config/config-service.interface.mts +0 -47
  116. package/src/config/config.provider.mts +0 -69
  117. package/src/config/config.service.mts +0 -176
  118. package/src/config/index.mts +0 -5
  119. package/src/config/types.mts +0 -58
  120. package/src/config/utils/helpers.mts +0 -23
  121. package/src/config/utils/index.mts +0 -1
  122. package/src/decorators/controller.decorator.mts +0 -81
  123. package/src/decorators/endpoint.decorator.mts +0 -181
  124. package/src/decorators/header.decorator.mts +0 -38
  125. package/src/decorators/http-code.decorator.mts +0 -38
  126. package/src/decorators/index.mts +0 -8
  127. package/src/decorators/module.decorator.mts +0 -106
  128. package/src/decorators/multipart.decorator.mts +0 -169
  129. package/src/decorators/stream.decorator.mts +0 -155
  130. package/src/decorators/use-guards.decorator.mts +0 -73
  131. package/src/exceptions/bad-request.exception.mts +0 -28
  132. package/src/exceptions/conflict.exception.mts +0 -31
  133. package/src/exceptions/forbidden.exception.mts +0 -30
  134. package/src/exceptions/http.exception.mts +0 -33
  135. package/src/exceptions/index.mts +0 -7
  136. package/src/exceptions/internal-server-error.exception.mts +0 -33
  137. package/src/exceptions/not-found.exception.mts +0 -33
  138. package/src/exceptions/unauthorized.exception.mts +0 -30
  139. package/src/factories/adapter.factory.mts +0 -20
  140. package/src/factories/endpoint-adapter.factory.mts +0 -21
  141. package/src/factories/http-adapter.factory.mts +0 -20
  142. package/src/factories/index.mts +0 -8
  143. package/src/factories/multipart-adapter.factory.mts +0 -21
  144. package/src/factories/reply.factory.mts +0 -21
  145. package/src/factories/request.factory.mts +0 -21
  146. package/src/factories/stream-adapter.factory.mts +0 -20
  147. package/src/factories/xml-stream-adapter.factory.mts +0 -20
  148. package/src/index.mts +0 -16
  149. package/src/interfaces/abstract-adapter.interface.mts +0 -32
  150. package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
  151. package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
  152. package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
  153. package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
  154. package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
  155. package/src/interfaces/adapter-environment.interface.mts +0 -74
  156. package/src/interfaces/can-activate.mts +0 -38
  157. package/src/interfaces/http-header.mts +0 -18
  158. package/src/interfaces/index.mts +0 -11
  159. package/src/interfaces/navios-module.mts +0 -28
  160. package/src/interfaces/plugin.interface.mts +0 -139
  161. package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
  162. package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
  163. package/src/legacy-compat/attribute.factory.mts +0 -351
  164. package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
  165. package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
  166. package/src/legacy-compat/decorators/header.decorator.mts +0 -43
  167. package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
  168. package/src/legacy-compat/decorators/index.mts +0 -11
  169. package/src/legacy-compat/decorators/module.decorator.mts +0 -37
  170. package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
  171. package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
  172. package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
  173. package/src/legacy-compat/index.mts +0 -57
  174. package/src/logger/README.md +0 -3
  175. package/src/logger/console-logger.service.mts +0 -714
  176. package/src/logger/index.mts +0 -6
  177. package/src/logger/log-levels.mts +0 -21
  178. package/src/logger/logger-service.interface.mts +0 -42
  179. package/src/logger/logger.service.mts +0 -113
  180. package/src/logger/logger.tokens.mts +0 -44
  181. package/src/logger/utils/cli-colors.util.mts +0 -17
  182. package/src/logger/utils/filter-log-levelts.util.mts +0 -29
  183. package/src/logger/utils/index.mts +0 -5
  184. package/src/logger/utils/is-log-level-enabled.mts +0 -33
  185. package/src/logger/utils/is-log-level.util.mts +0 -10
  186. package/src/logger/utils/shared.utils.mts +0 -51
  187. package/src/metadata/controller.metadata.mts +0 -72
  188. package/src/metadata/handler.metadata.mts +0 -80
  189. package/src/metadata/index.mts +0 -4
  190. package/src/metadata/module.metadata.mts +0 -108
  191. package/src/metadata/navios-managed.metadata.mts +0 -42
  192. package/src/navios.application.mts +0 -484
  193. package/src/navios.environment.mts +0 -42
  194. package/src/navios.factory.mts +0 -158
  195. package/src/responders/enums/framework-error.enum.mts +0 -38
  196. package/src/responders/enums/index.mts +0 -1
  197. package/src/responders/index.mts +0 -4
  198. package/src/responders/interfaces/error-responder.interface.mts +0 -42
  199. package/src/responders/interfaces/error-response.interface.mts +0 -22
  200. package/src/responders/interfaces/index.mts +0 -3
  201. package/src/responders/interfaces/problem-details.interface.mts +0 -34
  202. package/src/responders/services/error-response-producer.service.mts +0 -143
  203. package/src/responders/services/forbidden-responder.service.mts +0 -77
  204. package/src/responders/services/index.mts +0 -5
  205. package/src/responders/services/internal-server-error-responder.service.mts +0 -57
  206. package/src/responders/services/not-found-responder.service.mts +0 -76
  207. package/src/responders/services/validation-error-responder.service.mts +0 -78
  208. package/src/responders/tokens/index.mts +0 -1
  209. package/src/responders/tokens/responder.tokens.mts +0 -84
  210. package/src/services/abstract-handler-adapter.service.mts +0 -366
  211. package/src/services/guard-runner.service.mts +0 -152
  212. package/src/services/index.mts +0 -4
  213. package/src/services/instance-resolver.service.mts +0 -177
  214. package/src/services/module-loader.service.mts +0 -252
  215. package/src/stores/index.mts +0 -1
  216. package/src/stores/request-id.store.mts +0 -85
  217. package/src/testing/index.mts +0 -3
  218. package/src/testing/testing-module.mts +0 -393
  219. package/src/testing/unit-testing-module.mts +0 -298
  220. package/src/tokens/adapter.token.mts +0 -6
  221. package/src/tokens/endpoint-adapter.token.mts +0 -8
  222. package/src/tokens/execution-context.token.mts +0 -9
  223. package/src/tokens/http-adapter.token.mts +0 -8
  224. package/src/tokens/index.mts +0 -10
  225. package/src/tokens/multipart-adapter.token.mts +0 -8
  226. package/src/tokens/navios-options.token.mts +0 -6
  227. package/src/tokens/reply.token.mts +0 -3
  228. package/src/tokens/request.token.mts +0 -3
  229. package/src/tokens/stream-adapter.token.mts +0 -8
  230. package/src/tokens/xml-stream-adapter.token.mts +0 -8
  231. package/src/utils/adapter-supports.util.mts +0 -47
  232. package/src/utils/index.mts +0 -1
  233. package/tsconfig.json +0 -21
  234. package/tsconfig.lib.json +0 -8
  235. package/tsconfig.spec.json +0 -15
  236. package/tsdown.config.mts +0 -35
  237. package/vitest.config.mts +0 -15
@@ -1,423 +1,105 @@
1
- const require_navios_factory = require('../navios.factory-CO5MB_OK.cjs');
2
- require('../tokens-CWw9kyeD.cjs');
3
- let _navios_di_testing = require("@navios/di/testing");
4
-
5
- //#region src/testing/testing-module.mts
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../attribute-value-CjX9ZkLq.cjs");
3
+ const require_execution_context_token = require("../execution-context-token-BXUKB2hf.cjs");
4
+ let _navios_di_legacy_compat = require("@navios/di/legacy-compat");
5
+ const require_basic_execution_context = require("../basic-execution-context-DSk5MNtc.cjs");
6
+ // src/testing/fake-transport.mts
7
+ let runs = 0;
6
8
  /**
7
- * A testing-optimized wrapper around NaviosApplication.
8
- * Provides utilities for setting up test environments with mock dependencies.
9
- *
10
- * When `init()` is called, a request scope is automatically started.
11
- * This means `get()` calls will resolve request-scoped services correctly,
12
- * simulating a real HTTP request context.
13
- *
14
- * @example
15
- * ```typescript
16
- * const module = await TestingModule.create(AppModule)
17
- * .overrideProvider(DatabaseService)
18
- * .useValue(mockDatabase)
19
- * .init()
20
- *
21
- * const userService = await module.get(UserService)
22
- * // ... run tests ...
23
- *
24
- * await module.close()
25
- * ```
26
- */ var TestingModule = class TestingModule {
27
- appModule;
28
- container;
29
- options;
30
- app = null;
31
- scopedContainer = null;
32
- requestId = `test-request-${Date.now()}-${Math.random().toString(36).slice(2)}`;
33
- constructor(appModule, container, options) {
34
- this.appModule = appModule;
35
- this.container = container;
36
- this.options = options;
37
- }
38
- /**
39
- * Creates a new TestingModule for the given app module.
40
- * This is the main entry point for setting up integration tests.
41
- *
42
- * @example
43
- * ```typescript
44
- * const module = await TestingModule.create(AppModule)
45
- * .overrideProvider(DatabaseService)
46
- * .useValue(mockDatabase)
47
- * .init()
48
- * ```
49
- */ static create(appModule, options = { adapter: [] }) {
50
- const container = options.container ?? new _navios_di_testing.TestContainer({ parentRegistry: options.registry });
51
- if (options.overrides) {
52
- for (const override of options.overrides) if (override.useValue !== void 0) container.bind(override.token).toValue(override.useValue);
53
- else if (override.useClass) container.bind(override.token).toClass(override.useClass);
54
- }
55
- return new TestingModule(appModule, container, options);
56
- }
57
- /**
58
- * Compiles the testing module without initializing it.
59
- * Call this if you need to access the app before initialization.
60
- *
61
- * @returns this for chaining
62
- */ async compile() {
63
- if (!this.app) this.app = await require_navios_factory.NaviosFactory.create(this.appModule, {
64
- ...this.options,
65
- container: this.container
66
- });
67
- return this;
68
- }
69
- /**
70
- * Initializes the application and starts a request scope.
71
- *
72
- * This is equivalent to calling `compile()` followed by `app.init()`,
73
- * plus starting a request context for proper request-scoped service resolution.
74
- *
75
- * @returns this for chaining
76
- */ async init() {
77
- if (!this.app) await this.compile();
78
- await this.app.init();
79
- this.scopedContainer = this.container.beginRequest(this.requestId, { testingModule: true });
80
- return this;
81
- }
82
- /**
83
- * Gets the compiled application.
84
- *
85
- * @throws Error if the module has not been compiled yet
86
- */ getApp() {
87
- if (!this.app) throw new Error("TestingModule not compiled. Call compile() or init() first.");
88
- return this.app;
89
- }
90
- /**
91
- * Gets the underlying TestContainer for direct manipulation.
92
- */ getContainer() {
93
- return this.container;
94
- }
95
- /**
96
- * Gets the scoped container for the current test request.
97
- * Only available after calling `init()`.
98
- *
99
- * @throws Error if init() has not been called
100
- */ getScopedContainer() {
101
- if (!this.scopedContainer) throw new Error("No scoped container available. Call init() first.");
102
- return this.scopedContainer;
103
- }
104
- /**
105
- * Override a provider with a mock value or class.
106
- * Must be called before `compile()` or `init()`.
107
- */ overrideProvider(token) {
9
+ * What decorators attached to a class, of either kind, without a decorator of
10
+ * the transport's own having asked for it.
11
+ */
12
+ function attachedTo(target) {
13
+ const symbol = Symbol.metadata;
14
+ const standard = symbol && target[symbol];
15
+ const { metadata } = (0, _navios_di_legacy_compat.createClassContext)(target);
16
+ const [first, second] = [standard, metadata].map((from) => require_basic_execution_context.describeHandlerClass({ metadata: Object.create(from ?? null) }));
17
+ return {
18
+ guards: [...first.guards, ...second.guards],
19
+ interceptors: [...first.interceptors, ...second.interceptors],
20
+ attributes: new Map([...first.attributes, ...second.attributes])
21
+ };
22
+ }
23
+ /**
24
+ * A transport for tests: it records its lifecycle and can run the guards and
25
+ * interceptors of a handler class with a context of its own kind.
26
+ */
27
+ const fakeTransport = require_basic_execution_context.defineTransport({
28
+ name: "fake",
29
+ create(host, options) {
30
+ const { kind, entry, log } = options;
31
+ const found = /* @__PURE__ */ new Map();
32
+ log.push(`${kind}:create`);
108
33
  return {
109
- useValue: (value) => {
110
- this.container.bind(token).toValue(value);
111
- return this;
34
+ get handlers() {
35
+ return [...found.keys()];
36
+ },
37
+ setup(graph) {
38
+ log.push(`${kind}:setup`);
39
+ if (options.failSetup) throw new Error(`${kind} setup failed`);
40
+ for (const node of graph) for (const handler of node.entries.get(entry) ?? []) {
41
+ const owner = attachedTo(handler);
42
+ const chain = require_basic_execution_context.handlerChain({
43
+ application: host.interceptors,
44
+ node,
45
+ owner,
46
+ member: {
47
+ guards: [],
48
+ interceptors: [],
49
+ attributes: /* @__PURE__ */ new Map()
50
+ }
51
+ });
52
+ found.set(handler, {
53
+ node,
54
+ owner,
55
+ chain
56
+ });
57
+ }
112
58
  },
113
- useClass: (target) => {
114
- this.container.bind(token).toClass(target);
115
- return this;
59
+ start() {
60
+ log.push(`${kind}:start`);
61
+ if (options.failStart) throw new Error(`${kind} start failed`);
62
+ },
63
+ async stop() {
64
+ log.push(`${kind}:stop`);
65
+ if (options.failStop) throw new Error(`${kind} stop failed`);
66
+ },
67
+ async run(handler) {
68
+ const known = found.get(handler);
69
+ if (!known) throw new Error(`${handler.name} is not a handler of the ${kind} transport`);
70
+ const { node, owner, chain } = known;
71
+ const resolved = await require_basic_execution_context.resolveChain(host.container, chain);
72
+ const ctx = new require_basic_execution_context.BasicExecutionContext({
73
+ kind,
74
+ id: `${kind}-${++runs}`,
75
+ host: host.contextHost,
76
+ handler: {
77
+ module: node.module,
78
+ controller: handler,
79
+ handlerName: "run",
80
+ guards: chain.guards,
81
+ interceptors: chain.interceptors,
82
+ attributes: {
83
+ handler: /* @__PURE__ */ new Map(),
84
+ controller: owner.attributes,
85
+ module: node.attributes
86
+ }
87
+ }
88
+ });
89
+ const execute = async () => {
90
+ try {
91
+ return await require_basic_execution_context.runChain(ctx, resolved, () => true, () => false);
92
+ } finally {
93
+ await ctx.finish();
94
+ }
95
+ };
96
+ return host.asyncContext ? require_execution_context_token.runInContext(ctx, execute) : execute();
116
97
  }
117
98
  };
118
99
  }
119
- /**
120
- * Gets an instance from the container.
121
- *
122
- * If `init()` has been called, this uses the scoped container
123
- * which properly resolves request-scoped services.
124
- *
125
- * If only `compile()` was called, this uses the root container
126
- * and request-scoped services will throw.
127
- */ async get(token) {
128
- if (this.scopedContainer) return this.scopedContainer.get(token);
129
- return this.container.get(token);
130
- }
131
- /**
132
- * Disposes the testing module and cleans up all resources.
133
- *
134
- * This will:
135
- * 1. End the request scope (if started)
136
- * 2. Close the application (if initialized)
137
- * 3. Dispose the container
138
- */ async close() {
139
- if (this.scopedContainer) {
140
- await this.scopedContainer.endRequest();
141
- this.scopedContainer = null;
142
- }
143
- if (this.app) {
144
- await this.app.close();
145
- this.app = null;
146
- }
147
- await this.container.dispose();
148
- }
149
- /**
150
- * Asserts that a service has been resolved at least once.
151
- */ expectResolved(token) {
152
- this.container.expectResolved(token);
153
- }
154
- /**
155
- * Asserts that a service has NOT been resolved.
156
- */ expectNotResolved(token) {
157
- this.container.expectNotResolved(token);
158
- }
159
- /**
160
- * Asserts that a service is registered as singleton scope.
161
- */ expectSingleton(token) {
162
- this.container.expectSingleton(token);
163
- }
164
- /**
165
- * Asserts that a service is registered as transient scope.
166
- */ expectTransient(token) {
167
- this.container.expectTransient(token);
168
- }
169
- /**
170
- * Asserts that a service is registered as request scope.
171
- */ expectRequestScoped(token) {
172
- this.container.expectRequestScoped(token);
173
- }
174
- /**
175
- * Asserts that a method was called on a service.
176
- * Note: You must use `recordMethodCall()` in your mocks for this to work.
177
- */ expectCalled(token, method) {
178
- this.container.expectCalled(token, method);
179
- }
180
- /**
181
- * Asserts that a method was called with specific arguments.
182
- * Note: You must use `recordMethodCall()` in your mocks for this to work.
183
- */ expectCalledWith(token, method, expectedArgs) {
184
- this.container.expectCalledWith(token, method, expectedArgs);
185
- }
186
- /**
187
- * Asserts that a method was called a specific number of times.
188
- * Note: You must use `recordMethodCall()` in your mocks for this to work.
189
- */ expectCallCount(token, method, count) {
190
- this.container.expectCallCount(token, method, count);
191
- }
192
- /**
193
- * Records a method call for tracking.
194
- * Call this from your mock implementations to enable call assertions.
195
- */ recordMethodCall(token, method, args, result, error) {
196
- this.container.recordMethodCall(token, method, args, result, error);
197
- }
198
- /**
199
- * Gets all recorded method calls for a service.
200
- */ getMethodCalls(token) {
201
- return this.container.getMethodCalls(token);
202
- }
203
- /**
204
- * Gets the dependency graph for debugging or snapshot testing.
205
- */ getDependencyGraph() {
206
- return this.container.getDependencyGraph();
207
- }
208
- /**
209
- * Gets a simplified dependency graph showing only token relationships.
210
- */ getSimplifiedDependencyGraph() {
211
- return this.container.getSimplifiedDependencyGraph();
212
- }
213
- };
214
- /**
215
- * Creates a testing module for the given app module.
216
- *
217
- * @deprecated Use `TestingModule.create()` instead.
218
- *
219
- * @example
220
- * ```typescript
221
- * // Old way (deprecated)
222
- * const module = createTestingModule(AppModule)
223
- *
224
- * // New way
225
- * const module = TestingModule.create(AppModule)
226
- * ```
227
- */ function createTestingModule(appModule, options = { adapter: [] }) {
228
- return TestingModule.create(appModule, options);
229
- }
230
-
231
- //#endregion
232
- //#region src/testing/unit-testing-module.mts
233
- /**
234
- * A lightweight testing module for isolated unit tests.
235
- *
236
- * Unlike `TestingModule`, this does NOT load Navios modules or create an application.
237
- * It uses `UnitTestContainer` which:
238
- * - Only allows explicitly provided services
239
- * - Automatically tracks all method calls via proxies
240
- * - Can auto-mock unregistered dependencies
241
- *
242
- * This is ideal for testing services in isolation without the overhead
243
- * of full module loading.
244
- *
245
- * @example
246
- * ```typescript
247
- * const module = UnitTestingModule.create({
248
- * providers: [
249
- * { token: UserService, useClass: UserService },
250
- * { token: DatabaseService, useValue: mockDatabase },
251
- * ],
252
- * })
253
- *
254
- * const userService = await module.get(UserService)
255
- * await userService.findUser('123')
256
- *
257
- * // Method calls are automatically tracked
258
- * module.expectCalled(UserService, 'findUser')
259
- * module.expectCalledWith(UserService, 'findUser', ['123'])
260
- *
261
- * await module.close()
262
- * ```
263
- */ var UnitTestingModule = class UnitTestingModule {
264
- container;
265
- constructor(container) {
266
- this.container = container;
267
- }
268
- /**
269
- * Creates a new UnitTestingModule with the given providers.
270
- *
271
- * @example
272
- * ```typescript
273
- * const module = UnitTestingModule.create({
274
- * providers: [
275
- * { token: UserService, useClass: UserService },
276
- * { token: ConfigToken, useValue: { apiUrl: 'test' } },
277
- * ],
278
- * })
279
- * ```
280
- */ static create(options) {
281
- return new UnitTestingModule(options.container ?? new _navios_di_testing.UnitTestContainer({
282
- providers: options.providers,
283
- allowUnregistered: options.allowUnregistered,
284
- logger: options.logger
285
- }));
286
- }
287
- /**
288
- * Gets the underlying UnitTestContainer for direct manipulation.
289
- */ getContainer() {
290
- return this.container;
291
- }
292
- /**
293
- * Gets an instance from the container.
294
- *
295
- * All resolved instances are wrapped in tracking proxies,
296
- * so method calls are automatically recorded.
297
- *
298
- * @throws Error if the token is not in the providers list
299
- * and `allowUnregistered` is false
300
- */ async get(token) {
301
- return this.container.get(token);
302
- }
303
- /**
304
- * Disposes the module and cleans up all resources.
305
- */ async close() {
306
- await this.container.clear();
307
- }
308
- /**
309
- * Enables auto-mocking for unregistered dependencies.
310
- * Unregistered services will return a proxy that throws on method access.
311
- */ enableAutoMocking() {
312
- this.container.enableAutoMocking();
313
- return this;
314
- }
315
- /**
316
- * Disables auto-mocking (strict mode).
317
- * Unregistered dependencies will throw immediately on resolution.
318
- */ disableAutoMocking() {
319
- this.container.disableAutoMocking();
320
- return this;
321
- }
322
- /**
323
- * Asserts that a service has been resolved at least once.
324
- */ expectResolved(token) {
325
- this.container.expectResolved(token);
326
- }
327
- /**
328
- * Asserts that a service has NOT been resolved.
329
- */ expectNotResolved(token) {
330
- this.container.expectNotResolved(token);
331
- }
332
- /**
333
- * Asserts that a service was auto-mocked (not in providers list).
334
- */ expectAutoMocked(token) {
335
- this.container.expectAutoMocked(token);
336
- }
337
- /**
338
- * Asserts that a service was NOT auto-mocked (is in providers list).
339
- */ expectNotAutoMocked(token) {
340
- this.container.expectNotAutoMocked(token);
341
- }
342
- /**
343
- * Asserts that a method was called on a service.
344
- * Method calls are automatically tracked via proxy.
345
- */ expectCalled(token, method) {
346
- this.container.expectCalled(token, method);
347
- }
348
- /**
349
- * Asserts that a method was NOT called on a service.
350
- */ expectNotCalled(token, method) {
351
- this.container.expectNotCalled(token, method);
352
- }
353
- /**
354
- * Asserts that a method was called with specific arguments.
355
- */ expectCalledWith(token, method, expectedArgs) {
356
- this.container.expectCalledWith(token, method, expectedArgs);
357
- }
358
- /**
359
- * Asserts that a method was called a specific number of times.
360
- */ expectCallCount(token, method, count) {
361
- this.container.expectCallCount(token, method, count);
362
- }
363
- /**
364
- * Gets all recorded method calls for a service.
365
- */ getMethodCalls(token) {
366
- return this.container.getMethodCalls(token);
367
- }
368
- /**
369
- * Gets statistics about a service (instance count, method calls, lifecycle events).
370
- */ getServiceStats(token) {
371
- return this.container.getServiceStats(token);
372
- }
373
- /**
374
- * Clears all recorded method calls.
375
- * Useful for resetting state between test assertions.
376
- */ clearMethodCalls() {
377
- this.container.clearMethodCalls();
378
- }
379
- /**
380
- * Gets list of all registered provider token IDs.
381
- */ getRegisteredTokenIds() {
382
- return this.container.getRegisteredTokenIds();
383
- }
384
- /**
385
- * Gets list of all auto-mocked token IDs.
386
- */ getAutoMockedTokenIds() {
387
- return this.container.getAutoMockedTokenIds();
388
- }
389
- /**
390
- * Asserts that a service's onServiceInit was called.
391
- */ expectInitialized(token) {
392
- this.container.expectInitialized(token);
393
- }
394
- /**
395
- * Asserts that a service's onServiceDestroy was called.
396
- */ expectDestroyed(token) {
397
- this.container.expectDestroyed(token);
398
- }
399
- /**
400
- * Asserts that a service has NOT been destroyed.
401
- */ expectNotDestroyed(token) {
402
- this.container.expectNotDestroyed(token);
403
- }
404
- /**
405
- * Records a lifecycle event for tracking.
406
- * Call this from your mock implementations if needed.
407
- */ recordLifecycleEvent(token, event, instanceName) {
408
- this.container.recordLifecycleEvent(token, event, instanceName);
409
- }
410
- };
411
-
412
- //#endregion
413
- exports.TestingModule = TestingModule;
414
- exports.UnitTestingModule = UnitTestingModule;
415
- exports.createTestingModule = createTestingModule;
416
- Object.keys(_navios_di_testing).forEach(function (k) {
417
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
418
- enumerable: true,
419
- get: function () { return _navios_di_testing[k]; }
420
- });
421
100
  });
101
+ exports.createContextHost = require_execution_context_token.createContextHost;
102
+ exports.enableAsyncContext = require_execution_context_token.enableAsyncContext;
103
+ exports.fakeTransport = fakeTransport;
422
104
 
423
105
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["TestContainer","NaviosFactory","TestingModule","app","scopedContainer","requestId","Date","now","Math","random","toString","slice","appModule","container","options","create","adapter","parentRegistry","registry","overrides","override","useValue","undefined","bind","token","toValue","useClass","toClass","compile","init","beginRequest","testingModule","getApp","Error","getContainer","getScopedContainer","overrideProvider","value","target","get","close","endRequest","dispose","expectResolved","expectNotResolved","expectSingleton","expectTransient","expectRequestScoped","expectCalled","method","expectCalledWith","expectedArgs","expectCallCount","count","recordMethodCall","args","result","error","getMethodCalls","getDependencyGraph","getSimplifiedDependencyGraph","createTestingModule","UnitTestContainer","UnitTestingModule","container","create","options","providers","allowUnregistered","logger","getContainer","get","token","close","clear","enableAutoMocking","disableAutoMocking","expectResolved","expectNotResolved","expectAutoMocked","expectNotAutoMocked","expectCalled","method","expectNotCalled","expectCalledWith","expectedArgs","expectCallCount","count","getMethodCalls","getServiceStats","clearMethodCalls","getRegisteredTokenIds","getAutoMockedTokenIds","expectInitialized","expectDestroyed","expectNotDestroyed","recordLifecycleEvent","event","instanceName"],"sources":["../../src/testing/testing-module.mts","../../src/testing/unit-testing-module.mts"],"sourcesContent":["import type {\n ClassType,\n ClassTypeWithInstance,\n InjectionToken,\n ScopedContainer,\n} from '@navios/di'\n\nimport { TestContainer } from '@navios/di/testing'\n\nimport type { NaviosModule } from '../interfaces/index.mjs'\nimport type { NaviosApplicationOptions } from '../navios.application.mjs'\n\nimport { NaviosApplication } from '../navios.application.mjs'\nimport { NaviosFactory } from '../navios.factory.mjs'\n\n/**\n * Configuration for overriding a provider in the testing module.\n *\n * @typeParam T - The type of the provider being overridden\n */\nexport interface TestingModuleOverride<T = any> {\n /**\n * The injection token or class to override.\n */\n token: ClassType | InjectionToken<T, any>\n /**\n * Value to use instead of the original provider.\n */\n useValue?: T\n /**\n * Class to use instead of the original provider.\n */\n useClass?: ClassType\n}\n\n/**\n * Options for creating a testing module.\n *\n * Extends NaviosApplicationOptions but excludes the container option,\n * as TestingModule manages its own TestContainer.\n */\nexport interface TestingModuleOptions extends Omit<\n NaviosApplicationOptions,\n 'container'\n> {\n /**\n * Initial provider overrides to apply when creating the testing module.\n *\n * You can also use `overrideProvider()` method for a fluent API.\n */\n overrides?: TestingModuleOverride[]\n /**\n * Container to use for the testing module.\n * If not provided, a new TestContainer will be created.\n */\n container?: TestContainer\n}\n\n/**\n * A testing-optimized wrapper around NaviosApplication.\n * Provides utilities for setting up test environments with mock dependencies.\n *\n * When `init()` is called, a request scope is automatically started.\n * This means `get()` calls will resolve request-scoped services correctly,\n * simulating a real HTTP request context.\n *\n * @example\n * ```typescript\n * const module = await TestingModule.create(AppModule)\n * .overrideProvider(DatabaseService)\n * .useValue(mockDatabase)\n * .init()\n *\n * const userService = await module.get(UserService)\n * // ... run tests ...\n *\n * await module.close()\n * ```\n */\nexport class TestingModule {\n private app: NaviosApplication | null = null\n private scopedContainer: ScopedContainer | null = null\n private requestId = `test-request-${Date.now()}-${Math.random().toString(36).slice(2)}`\n\n private constructor(\n private readonly appModule: ClassTypeWithInstance<NaviosModule>,\n private readonly container: TestContainer,\n private readonly options: TestingModuleOptions,\n ) {}\n\n /**\n * Creates a new TestingModule for the given app module.\n * This is the main entry point for setting up integration tests.\n *\n * @example\n * ```typescript\n * const module = await TestingModule.create(AppModule)\n * .overrideProvider(DatabaseService)\n * .useValue(mockDatabase)\n * .init()\n * ```\n */\n static create(\n appModule: ClassTypeWithInstance<NaviosModule>,\n options: TestingModuleOptions = { adapter: [] },\n ): TestingModule {\n const container =\n options.container ??\n new TestContainer({\n parentRegistry: options.registry,\n })\n\n // Apply initial overrides if provided\n if (options.overrides) {\n for (const override of options.overrides) {\n if (override.useValue !== undefined) {\n container.bind(override.token as any).toValue(override.useValue)\n } else if (override.useClass) {\n container.bind(override.token as any).toClass(override.useClass)\n }\n }\n }\n\n return new TestingModule(appModule, container, options)\n }\n\n /**\n * Compiles the testing module without initializing it.\n * Call this if you need to access the app before initialization.\n *\n * @returns this for chaining\n */\n async compile(): Promise<this> {\n if (!this.app) {\n this.app = await NaviosFactory.create(this.appModule, {\n ...this.options,\n container: this.container,\n })\n }\n return this\n }\n\n /**\n * Initializes the application and starts a request scope.\n *\n * This is equivalent to calling `compile()` followed by `app.init()`,\n * plus starting a request context for proper request-scoped service resolution.\n *\n * @returns this for chaining\n */\n async init(): Promise<this> {\n if (!this.app) {\n await this.compile()\n }\n await this.app!.init()\n\n // Begin a request scope so get() can resolve request-scoped services\n this.scopedContainer = this.container.beginRequest(this.requestId, {\n testingModule: true,\n })\n\n return this\n }\n\n /**\n * Gets the compiled application.\n *\n * @throws Error if the module has not been compiled yet\n */\n getApp(): NaviosApplication {\n if (!this.app) {\n throw new Error(\n 'TestingModule not compiled. Call compile() or init() first.',\n )\n }\n return this.app\n }\n\n /**\n * Gets the underlying TestContainer for direct manipulation.\n */\n getContainer(): TestContainer {\n return this.container\n }\n\n /**\n * Gets the scoped container for the current test request.\n * Only available after calling `init()`.\n *\n * @throws Error if init() has not been called\n */\n getScopedContainer(): ScopedContainer {\n if (!this.scopedContainer) {\n throw new Error('No scoped container available. Call init() first.')\n }\n return this.scopedContainer\n }\n\n /**\n * Override a provider with a mock value or class.\n * Must be called before `compile()` or `init()`.\n */\n overrideProvider<T>(token: ClassType | InjectionToken<T, any>): {\n useValue: (value: T) => TestingModule\n useClass: (target: ClassType) => TestingModule\n } {\n return {\n useValue: (value: T) => {\n this.container.bind(token as any).toValue(value)\n return this\n },\n useClass: (target: ClassType) => {\n this.container.bind(token as any).toClass(target)\n return this\n },\n }\n }\n\n /**\n * Gets an instance from the container.\n *\n * If `init()` has been called, this uses the scoped container\n * which properly resolves request-scoped services.\n *\n * If only `compile()` was called, this uses the root container\n * and request-scoped services will throw.\n */\n async get<T>(\n token: ClassTypeWithInstance<T> | InjectionToken<T, any>,\n ): Promise<T> {\n // Use scoped container if available (after init)\n if (this.scopedContainer) {\n return this.scopedContainer.get(token as any)\n }\n // Fall back to root container (after compile only)\n return this.container.get(token as any)\n }\n\n /**\n * Disposes the testing module and cleans up all resources.\n *\n * This will:\n * 1. End the request scope (if started)\n * 2. Close the application (if initialized)\n * 3. Dispose the container\n */\n async close(): Promise<void> {\n // End the request scope first\n if (this.scopedContainer) {\n await this.scopedContainer.endRequest()\n this.scopedContainer = null\n }\n\n // Close the app\n if (this.app) {\n await this.app.close()\n this.app = null\n }\n\n // Dispose the container\n await this.container.dispose()\n }\n\n // ===========================================================================\n // ASSERTION HELPERS (delegated to TestContainer)\n // ===========================================================================\n\n /**\n * Asserts that a service has been resolved at least once.\n */\n expectResolved(token: ClassType | InjectionToken<any, any>): void {\n this.container.expectResolved(token)\n }\n\n /**\n * Asserts that a service has NOT been resolved.\n */\n expectNotResolved(token: ClassType | InjectionToken<any, any>): void {\n this.container.expectNotResolved(token)\n }\n\n /**\n * Asserts that a service is registered as singleton scope.\n */\n expectSingleton(token: ClassType | InjectionToken<any, any>): void {\n this.container.expectSingleton(token)\n }\n\n /**\n * Asserts that a service is registered as transient scope.\n */\n expectTransient(token: ClassType | InjectionToken<any, any>): void {\n this.container.expectTransient(token)\n }\n\n /**\n * Asserts that a service is registered as request scope.\n */\n expectRequestScoped(token: ClassType | InjectionToken<any, any>): void {\n this.container.expectRequestScoped(token)\n }\n\n /**\n * Asserts that a method was called on a service.\n * Note: You must use `recordMethodCall()` in your mocks for this to work.\n */\n expectCalled(\n token: ClassType | InjectionToken<any, any>,\n method: string,\n ): void {\n this.container.expectCalled(token, method)\n }\n\n /**\n * Asserts that a method was called with specific arguments.\n * Note: You must use `recordMethodCall()` in your mocks for this to work.\n */\n expectCalledWith(\n token: ClassType | InjectionToken<any, any>,\n method: string,\n expectedArgs: unknown[],\n ): void {\n this.container.expectCalledWith(token, method, expectedArgs)\n }\n\n /**\n * Asserts that a method was called a specific number of times.\n * Note: You must use `recordMethodCall()` in your mocks for this to work.\n */\n expectCallCount(\n token: ClassType | InjectionToken<any, any>,\n method: string,\n count: number,\n ): void {\n this.container.expectCallCount(token, method, count)\n }\n\n /**\n * Records a method call for tracking.\n * Call this from your mock implementations to enable call assertions.\n */\n recordMethodCall(\n token: ClassType | InjectionToken<any, any>,\n method: string,\n args: unknown[],\n result?: unknown,\n error?: Error,\n ): void {\n this.container.recordMethodCall(token, method, args, result, error)\n }\n\n /**\n * Gets all recorded method calls for a service.\n */\n getMethodCalls(token: ClassType | InjectionToken<any, any>) {\n return this.container.getMethodCalls(token)\n }\n\n /**\n * Gets the dependency graph for debugging or snapshot testing.\n */\n getDependencyGraph() {\n return this.container.getDependencyGraph()\n }\n\n /**\n * Gets a simplified dependency graph showing only token relationships.\n */\n getSimplifiedDependencyGraph() {\n return this.container.getSimplifiedDependencyGraph()\n }\n}\n\n/**\n * Creates a testing module for the given app module.\n *\n * @deprecated Use `TestingModule.create()` instead.\n *\n * @example\n * ```typescript\n * // Old way (deprecated)\n * const module = createTestingModule(AppModule)\n *\n * // New way\n * const module = TestingModule.create(AppModule)\n * ```\n */\nexport function createTestingModule(\n appModule: ClassTypeWithInstance<NaviosModule>,\n options: TestingModuleOptions = { adapter: [] },\n): TestingModule {\n return TestingModule.create(appModule, options)\n}\n","import type {\n ClassType,\n ClassTypeWithInstance,\n InjectionToken,\n} from '@navios/di'\nimport type {\n MethodCallRecord,\n MockServiceStats,\n ProviderConfig,\n} from '@navios/di/testing'\n\nimport { UnitTestContainer } from '@navios/di/testing'\n\n/**\n * Options for creating a UnitTestingModule.\n */\nexport interface UnitTestingModuleOptions {\n /**\n * List of providers to register. Only these services can be resolved.\n */\n providers: ProviderConfig[]\n\n /**\n * If true, unregistered dependencies will be auto-mocked instead of throwing.\n * Default: false (throws on unregistered dependencies)\n */\n allowUnregistered?: boolean\n\n /**\n * Logger for debugging.\n */\n logger?: Console | null\n\n /**\n * Container to use for the testing module.\n * If not provided, a new UnitTestContainer will be created.\n */\n container?: UnitTestContainer\n}\n\n/**\n * A lightweight testing module for isolated unit tests.\n *\n * Unlike `TestingModule`, this does NOT load Navios modules or create an application.\n * It uses `UnitTestContainer` which:\n * - Only allows explicitly provided services\n * - Automatically tracks all method calls via proxies\n * - Can auto-mock unregistered dependencies\n *\n * This is ideal for testing services in isolation without the overhead\n * of full module loading.\n *\n * @example\n * ```typescript\n * const module = UnitTestingModule.create({\n * providers: [\n * { token: UserService, useClass: UserService },\n * { token: DatabaseService, useValue: mockDatabase },\n * ],\n * })\n *\n * const userService = await module.get(UserService)\n * await userService.findUser('123')\n *\n * // Method calls are automatically tracked\n * module.expectCalled(UserService, 'findUser')\n * module.expectCalledWith(UserService, 'findUser', ['123'])\n *\n * await module.close()\n * ```\n */\nexport class UnitTestingModule {\n private constructor(private readonly container: UnitTestContainer) {}\n\n /**\n * Creates a new UnitTestingModule with the given providers.\n *\n * @example\n * ```typescript\n * const module = UnitTestingModule.create({\n * providers: [\n * { token: UserService, useClass: UserService },\n * { token: ConfigToken, useValue: { apiUrl: 'test' } },\n * ],\n * })\n * ```\n */\n static create(options: UnitTestingModuleOptions): UnitTestingModule {\n const container =\n options.container ??\n new UnitTestContainer({\n providers: options.providers,\n allowUnregistered: options.allowUnregistered,\n logger: options.logger,\n })\n\n return new UnitTestingModule(container)\n }\n\n /**\n * Gets the underlying UnitTestContainer for direct manipulation.\n */\n getContainer(): UnitTestContainer {\n return this.container\n }\n\n /**\n * Gets an instance from the container.\n *\n * All resolved instances are wrapped in tracking proxies,\n * so method calls are automatically recorded.\n *\n * @throws Error if the token is not in the providers list\n * and `allowUnregistered` is false\n */\n async get<T>(\n token: ClassTypeWithInstance<T> | InjectionToken<T, any>,\n ): Promise<T> {\n return this.container.get(token as any)\n }\n\n /**\n * Disposes the module and cleans up all resources.\n */\n async close(): Promise<void> {\n await this.container.clear()\n }\n\n /**\n * Enables auto-mocking for unregistered dependencies.\n * Unregistered services will return a proxy that throws on method access.\n */\n enableAutoMocking(): this {\n this.container.enableAutoMocking()\n return this\n }\n\n /**\n * Disables auto-mocking (strict mode).\n * Unregistered dependencies will throw immediately on resolution.\n */\n disableAutoMocking(): this {\n this.container.disableAutoMocking()\n return this\n }\n\n // ===========================================================================\n // ASSERTION HELPERS (delegated to UnitTestContainer)\n // ===========================================================================\n\n /**\n * Asserts that a service has been resolved at least once.\n */\n expectResolved(token: ClassType | InjectionToken<any, any>): void {\n this.container.expectResolved(token)\n }\n\n /**\n * Asserts that a service has NOT been resolved.\n */\n expectNotResolved(token: ClassType | InjectionToken<any, any>): void {\n this.container.expectNotResolved(token)\n }\n\n /**\n * Asserts that a service was auto-mocked (not in providers list).\n */\n expectAutoMocked(token: ClassType | InjectionToken<any, any>): void {\n this.container.expectAutoMocked(token)\n }\n\n /**\n * Asserts that a service was NOT auto-mocked (is in providers list).\n */\n expectNotAutoMocked(token: ClassType | InjectionToken<any, any>): void {\n this.container.expectNotAutoMocked(token)\n }\n\n /**\n * Asserts that a method was called on a service.\n * Method calls are automatically tracked via proxy.\n */\n expectCalled(\n token: ClassType | InjectionToken<any, any>,\n method: string,\n ): void {\n this.container.expectCalled(token, method)\n }\n\n /**\n * Asserts that a method was NOT called on a service.\n */\n expectNotCalled(\n token: ClassType | InjectionToken<any, any>,\n method: string,\n ): void {\n this.container.expectNotCalled(token, method)\n }\n\n /**\n * Asserts that a method was called with specific arguments.\n */\n expectCalledWith(\n token: ClassType | InjectionToken<any, any>,\n method: string,\n expectedArgs: unknown[],\n ): void {\n this.container.expectCalledWith(token, method, expectedArgs)\n }\n\n /**\n * Asserts that a method was called a specific number of times.\n */\n expectCallCount(\n token: ClassType | InjectionToken<any, any>,\n method: string,\n count: number,\n ): void {\n this.container.expectCallCount(token, method, count)\n }\n\n /**\n * Gets all recorded method calls for a service.\n */\n getMethodCalls(\n token: ClassType | InjectionToken<any, any>,\n ): MethodCallRecord[] {\n return this.container.getMethodCalls(token)\n }\n\n /**\n * Gets statistics about a service (instance count, method calls, lifecycle events).\n */\n getServiceStats(\n token: ClassType | InjectionToken<any, any>,\n ): MockServiceStats {\n return this.container.getServiceStats(token)\n }\n\n /**\n * Clears all recorded method calls.\n * Useful for resetting state between test assertions.\n */\n clearMethodCalls(): void {\n this.container.clearMethodCalls()\n }\n\n /**\n * Gets list of all registered provider token IDs.\n */\n getRegisteredTokenIds(): ReadonlySet<string> {\n return this.container.getRegisteredTokenIds()\n }\n\n /**\n * Gets list of all auto-mocked token IDs.\n */\n getAutoMockedTokenIds(): ReadonlySet<string> {\n return this.container.getAutoMockedTokenIds()\n }\n\n // ===========================================================================\n // LIFECYCLE ASSERTIONS\n // ===========================================================================\n\n /**\n * Asserts that a service's onServiceInit was called.\n */\n expectInitialized(token: ClassType | InjectionToken<any, any>): void {\n this.container.expectInitialized(token)\n }\n\n /**\n * Asserts that a service's onServiceDestroy was called.\n */\n expectDestroyed(token: ClassType | InjectionToken<any, any>): void {\n this.container.expectDestroyed(token)\n }\n\n /**\n * Asserts that a service has NOT been destroyed.\n */\n expectNotDestroyed(token: ClassType | InjectionToken<any, any>): void {\n this.container.expectNotDestroyed(token)\n }\n\n /**\n * Records a lifecycle event for tracking.\n * Call this from your mock implementations if needed.\n */\n recordLifecycleEvent(\n token: ClassType | InjectionToken<any, any>,\n event: 'created' | 'initialized' | 'destroyed',\n instanceName: string,\n ): void {\n this.container.recordLifecycleEvent(token, event, instanceName)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;GA+EA,IAAaE,gBAAb,MAAaA,cAAAA;;;;CACHC,MAAgC;CAChCC,kBAA0C;CAC1CC,YAAY,gBAAgBC,KAAKC,KAAG,CAAG,GAAGC,KAAKC,QAAM,CAAGC,SAAS,GAAA,CAAIC,MAAM,EAAA;CAEnF,YACE,WACA,WACA,SACA;OAHiBC,YAAAA;OACAC,YAAAA;OACAC,UAAAA;;;;;;;;;;;;;IAenB,OAAOC,OACLH,WACAE,UAAgC,EAAEE,SAAS,EAAE,EAAE,EAChC;EACf,MAAMH,YACJC,QAAQD,aACR,IAAIb,iCAAc,EAChBiB,gBAAgBH,QAAQI,UAC1B,CAAA;AAGF,MAAIJ,QAAQK,WACV;QAAK,MAAMC,YAAYN,QAAQK,UAC7B,KAAIC,SAASC,aAAaC,OACxBT,WAAUU,KAAKH,SAASI,MAAK,CAASC,QAAQL,SAASC,SAAQ;YACtDD,SAASM,SAClBb,WAAUU,KAAKH,SAASI,MAAK,CAASG,QAAQP,SAASM,SAAQ;;AAKrE,SAAO,IA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vB,OAAK1B,UAAU0B,kBAAgB;;;;IAMjCC,wBAA6C;AAC3C,SAAO,KAAK3B,UAAU2B,uBAAqB;;;;IAM7CC,wBAA6C;AAC3C,SAAO,KAAK5B,UAAU4B,uBAAqB;;;;IAU7CC,kBAAkBrB,OAAmD;AACnE,OAAKR,UAAU6B,kBAAkBrB,MAAAA;;;;IAMnCsB,gBAAgBtB,OAAmD;AACjE,OAAKR,UAAU8B,gBAAgBtB,MAAAA;;;;IAMjCuB,mBAAmBvB,OAAmD;AACpE,OAAKR,UAAU+B,mBAAmBvB,MAAAA;;;;;IAOpCwB,qBACExB,OACAyB,OACAC,cACM;AACN,OAAKlC,UAAUgC,qBAAqBxB,OAAOyB,OAAOC,aAAAA"}
1
+ {"version":3,"file":"index.cjs","names":["createClassContext","describeHandlerClass","defineTransport","handlerChain","resolveChain","BasicExecutionContext","runChain","runInContext"],"sources":["../../src/testing/fake-transport.mts"],"sourcesContent":["import { createClassContext } from '@navios/di/legacy-compat'\n\nimport type { ClassType } from '@navios/di'\n\nimport { runInContext } from '../execution/async-context.mjs'\nimport { BasicExecutionContext } from '../execution/basic-execution-context.mjs'\nimport { handlerChain } from '../metadata/handler-chain.mjs'\nimport { describeHandlerClass } from '../metadata/handler-class.mjs'\nimport { resolveChain, runChain } from '../metadata/run-chain.mjs'\nimport { defineTransport } from '../transports/transport.mjs'\n\nimport type { HandlerChain } from '../metadata/handler-chain.mjs'\nimport type { HandlerExtras } from '../metadata/member-metadata.mjs'\nimport type { ModuleNode } from '../modules/module-graph.mjs'\nimport type { Transport, TransportHost } from '../transports/transport.mjs'\n\nexport interface FakeTransportOptions {\n /** The `kind` of the contexts this transport creates. */\n kind: string\n /** The `@Module` option this transport reads its handler classes from. */\n entry: string\n /** Receives `<kind>:create`, `:setup`, `:start` and `:stop`. */\n log: string[]\n failSetup?: boolean\n failStart?: boolean\n failStop?: boolean\n}\n\nexport interface FakeTransport extends Transport {\n /** The handler classes found in the graph, in graph order. */\n readonly handlers: ClassType[]\n /**\n * Runs what applies to a handler class, as a transport runs it for a handler\n * that does nothing: the application's interceptors, the guards, the\n * interceptors of the module and the class. Resolves to whether every guard\n * allowed it.\n */\n run(handler: ClassType): Promise<boolean>\n}\n\ninterface FoundHandler {\n node: ModuleNode\n owner: HandlerExtras\n chain: HandlerChain\n}\n\nlet runs = 0\n\n/**\n * What decorators attached to a class, of either kind, without a decorator of\n * the transport's own having asked for it.\n */\nfunction attachedTo(target: ClassType): HandlerExtras {\n const symbol = (Symbol as { metadata?: symbol }).metadata\n const standard = symbol && (target as unknown as Record<symbol, object | undefined>)[symbol]\n const { metadata } = createClassContext(target)\n const [first, second] = [standard, metadata].map((from) =>\n // Read through an object of its own: reading adds what is missing.\n describeHandlerClass({ metadata: Object.create(from ?? null) }),\n )\n return {\n guards: [...first.guards, ...second.guards],\n interceptors: [...first.interceptors, ...second.interceptors],\n attributes: new Map([...first.attributes, ...second.attributes]),\n }\n}\n\n/**\n * A transport for tests: it records its lifecycle and can run the guards and\n * interceptors of a handler class with a context of its own kind.\n */\nexport const fakeTransport = defineTransport<FakeTransportOptions, FakeTransport>({\n name: 'fake',\n create(host: TransportHost, options) {\n const { kind, entry, log } = options\n const found = new Map<ClassType, FoundHandler>()\n log.push(`${kind}:create`)\n return {\n get handlers() {\n return [...found.keys()]\n },\n setup(graph) {\n log.push(`${kind}:setup`)\n if (options.failSetup) {\n throw new Error(`${kind} setup failed`)\n }\n for (const node of graph) {\n for (const handler of (node.entries.get(entry) as ClassType[] | undefined) ?? []) {\n const owner = attachedTo(handler)\n const chain = handlerChain({\n application: host.interceptors,\n node,\n owner,\n member: { guards: [], interceptors: [], attributes: new Map() },\n })\n found.set(handler, { node, owner, chain })\n }\n }\n },\n start() {\n log.push(`${kind}:start`)\n if (options.failStart) {\n throw new Error(`${kind} start failed`)\n }\n },\n async stop() {\n log.push(`${kind}:stop`)\n if (options.failStop) {\n throw new Error(`${kind} stop failed`)\n }\n },\n async run(handler) {\n const known = found.get(handler)\n if (!known) {\n throw new Error(`${handler.name} is not a handler of the ${kind} transport`)\n }\n const { node, owner, chain } = known\n const resolved = await resolveChain<BasicExecutionContext, boolean>(host.container, chain)\n const ctx = new BasicExecutionContext({\n kind,\n id: `${kind}-${++runs}`,\n host: host.contextHost,\n handler: {\n module: node.module,\n controller: handler,\n handlerName: 'run',\n guards: chain.guards,\n interceptors: chain.interceptors,\n attributes: {\n handler: new Map(),\n controller: owner.attributes,\n module: node.attributes,\n },\n },\n })\n const execute = async () => {\n try {\n return await runChain(\n ctx,\n resolved,\n () => true,\n () => false,\n )\n } finally {\n await ctx.finish()\n }\n }\n return host.asyncContext ? runInContext(ctx, execute) : execute()\n },\n }\n },\n})\n"],"mappings":";;;;;;AA8CA,IAAI,OAAO;;;;;AAMX,SAAS,WAAW,QAAkC;CACpD,MAAM,SAAU,OAAiC;CACjD,MAAM,WAAW,UAAW,OAAyD;CACrF,MAAM,EAAE,cAAA,GAAaA,yBAAAA,mBAAAA,CAAmB,MAAM;CAC9C,MAAM,CAAC,OAAO,UAAU,CAAC,UAAU,QAAQ,CAAC,CAAC,KAAK,SAEhDC,gCAAAA,qBAAqB,EAAE,UAAU,OAAO,OAAO,QAAQ,IAAI,EAAE,CAAC,CAChE;CACA,OAAO;EACL,QAAQ,CAAC,GAAG,MAAM,QAAQ,GAAG,OAAO,MAAM;EAC1C,cAAc,CAAC,GAAG,MAAM,cAAc,GAAG,OAAO,YAAY;EAC5D,YAAY,IAAI,IAAI,CAAC,GAAG,MAAM,YAAY,GAAG,OAAO,UAAU,CAAC;CACjE;AACF;;;;;AAMA,MAAa,gBAAgBC,gCAAAA,gBAAqD;CAChF,MAAM;CACN,OAAO,MAAqB,SAAS;EACnC,MAAM,EAAE,MAAM,OAAO,QAAQ;EAC7B,MAAM,wBAAQ,IAAI,IAA6B;EAC/C,IAAI,KAAK,GAAG,KAAK,QAAQ;EACzB,OAAO;GACL,IAAI,WAAW;IACb,OAAO,CAAC,GAAG,MAAM,KAAK,CAAC;G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