@asenajs/ioc 0.0.0-stage → 0.2.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 (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +219 -2
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +2 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/CircularDependencyDetector.d.ts +49 -0
  7. package/dist/lib/CircularDependencyDetector.js +69 -0
  8. package/dist/lib/CircularDependencyDetector.js.map +1 -0
  9. package/dist/lib/Container.d.ts +259 -0
  10. package/dist/lib/Container.js +577 -0
  11. package/dist/lib/Container.js.map +1 -0
  12. package/dist/lib/IocApplication.d.ts +88 -0
  13. package/dist/lib/IocApplication.js +110 -0
  14. package/dist/lib/IocApplication.js.map +1 -0
  15. package/dist/lib/IocEngine.d.ts +173 -0
  16. package/dist/lib/IocEngine.js +723 -0
  17. package/dist/lib/IocEngine.js.map +1 -0
  18. package/dist/lib/component/Scope.d.ts +4 -0
  19. package/dist/lib/component/Scope.js +6 -0
  20. package/dist/lib/component/Scope.js.map +1 -0
  21. package/dist/lib/component/componentRegistry.d.ts +34 -0
  22. package/dist/lib/component/componentRegistry.js +134 -0
  23. package/dist/lib/component/componentRegistry.js.map +1 -0
  24. package/dist/lib/component/componentUtils.d.ts +16 -0
  25. package/dist/lib/component/componentUtils.js +44 -0
  26. package/dist/lib/component/componentUtils.js.map +1 -0
  27. package/dist/lib/component/decorators/Component.d.ts +8 -0
  28. package/dist/lib/component/decorators/Component.js +12 -0
  29. package/dist/lib/component/decorators/Component.js.map +1 -0
  30. package/dist/lib/component/decorators/Implements.d.ts +7 -0
  31. package/dist/lib/component/decorators/Implements.js +14 -0
  32. package/dist/lib/component/decorators/Implements.js.map +1 -0
  33. package/dist/lib/component/decorators/Inject.d.ts +29 -0
  34. package/dist/lib/component/decorators/Inject.js +82 -0
  35. package/dist/lib/component/decorators/Inject.js.map +1 -0
  36. package/dist/lib/component/decorators/OnStart.d.ts +20 -0
  37. package/dist/lib/component/decorators/OnStart.js +33 -0
  38. package/dist/lib/component/decorators/OnStart.js.map +1 -0
  39. package/dist/lib/component/decorators/OnStop.d.ts +15 -0
  40. package/dist/lib/component/decorators/OnStop.js +28 -0
  41. package/dist/lib/component/decorators/OnStop.js.map +1 -0
  42. package/dist/lib/component/decorators/PostConstruct.d.ts +14 -0
  43. package/dist/lib/component/decorators/PostConstruct.js +16 -0
  44. package/dist/lib/component/decorators/PostConstruct.js.map +1 -0
  45. package/dist/lib/component/decorators/PostProcessor.d.ts +25 -0
  46. package/dist/lib/component/decorators/PostProcessor.js +29 -0
  47. package/dist/lib/component/decorators/PostProcessor.js.map +1 -0
  48. package/dist/lib/component/decorators/Service.d.ts +8 -0
  49. package/dist/lib/component/decorators/Service.js +12 -0
  50. package/dist/lib/component/decorators/Service.js.map +1 -0
  51. package/dist/lib/component/decorators/Strategy.d.ts +9 -0
  52. package/dist/lib/component/decorators/Strategy.js +29 -0
  53. package/dist/lib/component/decorators/Strategy.js.map +1 -0
  54. package/dist/lib/component/decorators/Value.d.ts +29 -0
  55. package/dist/lib/component/decorators/Value.js +41 -0
  56. package/dist/lib/component/decorators/Value.js.map +1 -0
  57. package/dist/lib/component/decorators/index.d.ts +11 -0
  58. package/dist/lib/component/decorators/index.js +12 -0
  59. package/dist/lib/component/decorators/index.js.map +1 -0
  60. package/dist/lib/component/decorators/legacyDecorator.d.ts +15 -0
  61. package/dist/lib/component/decorators/legacyDecorator.js +24 -0
  62. package/dist/lib/component/decorators/legacyDecorator.js.map +1 -0
  63. package/dist/lib/component/index.d.ts +3 -0
  64. package/dist/lib/component/index.js +4 -0
  65. package/dist/lib/component/index.js.map +1 -0
  66. package/dist/lib/constants/ComponentConstants.d.ts +21 -0
  67. package/dist/lib/constants/ComponentConstants.js +25 -0
  68. package/dist/lib/constants/ComponentConstants.js.map +1 -0
  69. package/dist/lib/constants/index.d.ts +1 -0
  70. package/dist/lib/constants/index.js +2 -0
  71. package/dist/lib/constants/index.js.map +1 -0
  72. package/dist/lib/decorators/CoreService.d.ts +11 -0
  73. package/dist/lib/decorators/CoreService.js +30 -0
  74. package/dist/lib/decorators/CoreService.js.map +1 -0
  75. package/dist/lib/decorators/index.d.ts +1 -0
  76. package/dist/lib/decorators/index.js +2 -0
  77. package/dist/lib/decorators/index.js.map +1 -0
  78. package/dist/lib/helper/fileHelper.d.ts +1 -0
  79. package/dist/lib/helper/fileHelper.js +29 -0
  80. package/dist/lib/helper/fileHelper.js.map +1 -0
  81. package/dist/lib/helper/iocHelper.d.ts +2 -0
  82. package/dist/lib/helper/iocHelper.js +12 -0
  83. package/dist/lib/helper/iocHelper.js.map +1 -0
  84. package/dist/lib/helper/valueResolver.d.ts +24 -0
  85. package/dist/lib/helper/valueResolver.js +37 -0
  86. package/dist/lib/helper/valueResolver.js.map +1 -0
  87. package/dist/lib/index.d.ts +12 -0
  88. package/dist/lib/index.js +13 -0
  89. package/dist/lib/index.js.map +1 -0
  90. package/dist/lib/lifecycle/LifecycleService.d.ts +78 -0
  91. package/dist/lib/lifecycle/LifecycleService.js +181 -0
  92. package/dist/lib/lifecycle/LifecycleService.js.map +1 -0
  93. package/dist/lib/lifecycle/LifecycleState.d.ts +20 -0
  94. package/dist/lib/lifecycle/LifecycleState.js +22 -0
  95. package/dist/lib/lifecycle/LifecycleState.js.map +1 -0
  96. package/dist/lib/lifecycle/index.d.ts +2 -0
  97. package/dist/lib/lifecycle/index.js +3 -0
  98. package/dist/lib/lifecycle/index.js.map +1 -0
  99. package/dist/lib/logger/IocLogger.d.ts +35 -0
  100. package/dist/lib/logger/IocLogger.js +2 -0
  101. package/dist/lib/logger/IocLogger.js.map +1 -0
  102. package/dist/lib/logger/index.d.ts +1 -0
  103. package/dist/lib/logger/index.js +2 -0
  104. package/dist/lib/logger/index.js.map +1 -0
  105. package/dist/lib/types/Class.d.ts +1 -0
  106. package/dist/lib/types/Class.js +2 -0
  107. package/dist/lib/types/Class.js.map +1 -0
  108. package/dist/lib/types/ComponentPostProcessor.d.ts +30 -0
  109. package/dist/lib/types/ComponentPostProcessor.js +2 -0
  110. package/dist/lib/types/ComponentPostProcessor.js.map +1 -0
  111. package/dist/lib/types/ContainerService.d.ts +6 -0
  112. package/dist/lib/types/ContainerService.js +2 -0
  113. package/dist/lib/types/ContainerService.js.map +1 -0
  114. package/dist/lib/types/ICoreService.d.ts +9 -0
  115. package/dist/lib/types/ICoreService.js +2 -0
  116. package/dist/lib/types/ICoreService.js.map +1 -0
  117. package/dist/lib/types/ICoreServiceNames.d.ts +10 -0
  118. package/dist/lib/types/ICoreServiceNames.js +12 -0
  119. package/dist/lib/types/ICoreServiceNames.js.map +1 -0
  120. package/dist/lib/types/InjectableComponent.d.ts +42 -0
  121. package/dist/lib/types/InjectableComponent.js +2 -0
  122. package/dist/lib/types/InjectableComponent.js.map +1 -0
  123. package/dist/lib/types/IocConfig.d.ts +11 -0
  124. package/dist/lib/types/IocConfig.js +2 -0
  125. package/dist/lib/types/IocConfig.js.map +1 -0
  126. package/dist/lib/types/LifecycleComponent.d.ts +29 -0
  127. package/dist/lib/types/LifecycleComponent.js +2 -0
  128. package/dist/lib/types/LifecycleComponent.js.map +1 -0
  129. package/dist/lib/types/decorators/ComponentParams.d.ts +5 -0
  130. package/dist/lib/types/decorators/ComponentParams.js +2 -0
  131. package/dist/lib/types/decorators/ComponentParams.js.map +1 -0
  132. package/dist/lib/types/decorators/ComponentType.d.ts +14 -0
  133. package/dist/lib/types/decorators/ComponentType.js +10 -0
  134. package/dist/lib/types/decorators/ComponentType.js.map +1 -0
  135. package/dist/lib/types/decorators/ServiceParams.d.ts +2 -0
  136. package/dist/lib/types/decorators/ServiceParams.js +2 -0
  137. package/dist/lib/types/decorators/ServiceParams.js.map +1 -0
  138. package/dist/lib/types/index.d.ts +11 -0
  139. package/dist/lib/types/index.js +12 -0
  140. package/dist/lib/types/index.js.map +1 -0
  141. package/dist/lib/utils/errorChain.d.ts +4 -0
  142. package/dist/lib/utils/errorChain.js +29 -0
  143. package/dist/lib/utils/errorChain.js.map +1 -0
  144. package/dist/lib/utils/typedMetadata.d.ts +54 -0
  145. package/dist/lib/utils/typedMetadata.js +97 -0
  146. package/dist/lib/utils/typedMetadata.js.map +1 -0
  147. package/package.json +73 -4
@@ -0,0 +1,577 @@
1
+ import { ComponentConstants } from './constants';
2
+ import { getOwnTypedMetadata, getTypedMetadata } from './utils/typedMetadata';
3
+ import { CircularDependencyDetector } from './CircularDependencyDetector';
4
+ import { CORE_SERVICE } from './decorators';
5
+ import { collectValueFields, readValue } from './helper/valueResolver';
6
+ /**
7
+ * Thrown by {@link Container.resolve} when the requested key has no registration.
8
+ *
9
+ * Carries no information about who needed the key - `resolve` cannot know that - so
10
+ * `injectDependencies` catches it and rethrows with the dependent class and field attached.
11
+ * The subclass identity is what tells an unwrapped miss (wrap it) from any other failure
12
+ * (rethrow untouched), including an already-wrapped nested miss.
13
+ */
14
+ export class UnregisteredDependencyError extends Error {
15
+ constructor(message) {
16
+ super(message);
17
+ this.name = 'UnregisteredDependencyError';
18
+ }
19
+ }
20
+ /**
21
+ * Thrown when an `@OnStart` (or `@PostConstruct`) hook throws or rejects.
22
+ *
23
+ * The original error is the `cause`; `component` and `hook` name the method that failed, so an
24
+ * application can tell a failed start hook apart from any other error without reading the message.
25
+ */
26
+ export class StartHookError extends Error {
27
+ component;
28
+ hook;
29
+ constructor(component, hook, cause) {
30
+ super(`@OnStart hook '${component}.${hook}()' failed`, { cause });
31
+ this.component = component;
32
+ this.hook = hook;
33
+ this.name = 'StartHookError';
34
+ }
35
+ }
36
+ export class Container {
37
+ _services = {};
38
+ circularDetector = new CircularDependencyDetector();
39
+ postProcessors = [];
40
+ overriddenKeys = new Set();
41
+ /** Key -> entries that live there only as an alias of their own key (see `registerAlias`). */
42
+ aliases = new Map();
43
+ /**
44
+ * How the error for an assignment to a wired field ends: what to do instead. Whatever wraps
45
+ * the container names its own way of seeding a test double here.
46
+ */
47
+ injectedFieldHint = "To swap a dependency in a test, seed a double with overrideInstance(), or the 'overrides' option of " +
48
+ 'IocApplication.create(), before the components are registered.';
49
+ /**
50
+ * Whether construction runs start hooks itself.
51
+ *
52
+ * `immediate` is the original behaviour and stays that way for core services, for the
53
+ * post-processor closure the IoC engine registers ahead of everything else, and for every
54
+ * transient. `deferred` holds the hooks back so `LifecycleService` can run them from
55
+ * `start()`, once the whole graph exists.
56
+ */
57
+ startHookMode = 'immediate';
58
+ /**
59
+ * Every singleton built by `register()`, in registration order - which the IoC engine has
60
+ * already topologically sorted, so dependencies come before dependents. Start hooks walk it
61
+ * forwards, stop hooks backwards.
62
+ *
63
+ * Instances handed in through `registerInstance()` are deliberately absent: nothing ever ran
64
+ * a start hook on them, so there is no started/stopped pair to keep symmetric.
65
+ */
66
+ lifecycleComponents = [];
67
+ constructor(services) {
68
+ this._services = services || {};
69
+ }
70
+ /**
71
+ * @returns {Promise<ContainerService>} The new entry, or the test double's entry when `key` is overridden
72
+ */
73
+ async register(key, Class, singleton) {
74
+ // An overridden key keeps its test double. Returning early means the real class is
75
+ // never instantiated (no @PostConstruct side effects) and the entry never turns
76
+ // into an array, which is what resolve() would otherwise hand back.
77
+ if (this.overriddenKeys.has(key)) {
78
+ return this._services[key];
79
+ }
80
+ const instance = singleton ? await this.prepareInstance(Class) : null;
81
+ if (singleton) {
82
+ this.trackLifecycle(key, instance, Class);
83
+ }
84
+ const entry = { Class, instance, singleton };
85
+ this.store(key, entry);
86
+ return entry;
87
+ }
88
+ /**
89
+ * @description Make an entry registered under one key reachable under another as well.
90
+ *
91
+ * The entry object itself is shared, so a singleton keeps one instance and one lifecycle no
92
+ * matter how many keys reach it - `@Implements` registers a component under its name and its
93
+ * interface key this way. Component scans (`resolveAll`) skip alias positions, so the
94
+ * component is still found exactly once.
95
+ *
96
+ * @param {string} key - The additional key, e.g. an `@Implements` interface name
97
+ * @param {ContainerService} entry - An entry returned by `register()`
98
+ * @returns {void}
99
+ */
100
+ registerAlias(key, entry) {
101
+ if (this.overriddenKeys.has(key)) {
102
+ return;
103
+ }
104
+ this.store(key, entry);
105
+ let aliased = this.aliases.get(key);
106
+ if (!aliased) {
107
+ aliased = new Set();
108
+ this.aliases.set(key, aliased);
109
+ }
110
+ aliased.add(entry);
111
+ }
112
+ store(key, entry) {
113
+ const existing = this._services[key];
114
+ if (!existing) {
115
+ this._services[key] = entry;
116
+ }
117
+ else if (Array.isArray(existing)) {
118
+ existing.push(entry);
119
+ }
120
+ else {
121
+ this._services[key] = [existing, entry];
122
+ }
123
+ }
124
+ /**
125
+ * @description Record a singleton for the start/stop lifecycle.
126
+ *
127
+ * `started` reflects what already happened rather than what is planned: a component built in
128
+ * immediate mode has run its start hooks by the time it gets here, so it is stoppable at once.
129
+ * A deferred one is not started until `LifecycleService` says so - and a component that never
130
+ * started must never be stopped.
131
+ *
132
+ * @param {string} key - Service identifier
133
+ * @param {unknown} instance - The post-processed instance
134
+ * @param {Class} Class - The class it was built from
135
+ * @returns {void}
136
+ */
137
+ trackLifecycle(key, instance, Class) {
138
+ this.lifecycleComponents.push({
139
+ key,
140
+ instance,
141
+ Class,
142
+ started: this.startHookMode === 'immediate',
143
+ });
144
+ }
145
+ /**
146
+ * @description Register an already-created instance directly
147
+ * Useful for dependencies created outside the container, like the logger. Any value except
148
+ * `null` and `undefined` can be registered, including `0`, `''`, `false` and an empty array.
149
+ * @param {string} key - Service identifier
150
+ * @param {T} instance - Pre-created instance
151
+ * @returns {Promise<void>}
152
+ */
153
+ async registerInstance(key, instance) {
154
+ if (this._services[key]) {
155
+ throw new Error(`Service '${key}' is already registered`);
156
+ }
157
+ if (instance === null || instance === undefined) {
158
+ throw new Error(`Cannot register '${key}' as ${instance === null ? 'null' : 'undefined'} - ` +
159
+ 'an instance has to be a value. Leave the name out instead of registering nothing under it.');
160
+ }
161
+ this._services[key] = {
162
+ Class: (instance.constructor ?? Object),
163
+ instance: instance,
164
+ singleton: true,
165
+ };
166
+ }
167
+ /**
168
+ * @description Replace a service with a pre-created test double (Spring's @MockBean).
169
+ *
170
+ * Seeds the container before user components are registered: any later `register()`
171
+ * call for the same key becomes a no-op, so the real class is never constructed and
172
+ * dependents capture the override in their injection closures.
173
+ *
174
+ * @param {string} key - Service identifier to override
175
+ * @param {T} instance - Replacement instance
176
+ * @returns {void}
177
+ */
178
+ overrideInstance(key, instance) {
179
+ if (instance === null || instance === undefined) {
180
+ throw new Error(`Cannot override service '${key}' with ${instance === null ? 'null' : 'undefined'} - ` +
181
+ 'an override must be an object instance. ' +
182
+ 'A null override would fail later with an opaque "instance cannot be null" error at resolve time.');
183
+ }
184
+ this.overriddenKeys.add(key);
185
+ this._services[key] = {
186
+ Class: (instance.constructor ?? Object),
187
+ instance,
188
+ singleton: true,
189
+ };
190
+ }
191
+ /**
192
+ * @description Check whether a key has been replaced by an override
193
+ * @param {string} key - Service key
194
+ * @returns {boolean}
195
+ */
196
+ isOverridden(key) {
197
+ return this.overriddenKeys.has(key);
198
+ }
199
+ async resolve(key) {
200
+ // Check circular dependency
201
+ this.circularDetector.checkCircular(key);
202
+ this.circularDetector.push(key);
203
+ try {
204
+ const service = this._services[key];
205
+ if (!service) {
206
+ throw new UnregisteredDependencyError(key + ' is not registered');
207
+ }
208
+ if (Array.isArray(service)) {
209
+ return await this.resolveMultipleContainerService(service);
210
+ }
211
+ return await this.resolveContainerService(service);
212
+ }
213
+ finally {
214
+ this.circularDetector.pop(key);
215
+ }
216
+ }
217
+ /**
218
+ * @description Check if a service is registered without resolving it
219
+ * @param {string} key - Service key
220
+ * @returns {boolean}
221
+ */
222
+ has(key) {
223
+ return this._services[key] !== undefined;
224
+ }
225
+ /**
226
+ * @description Resolve every implementation registered under a strategy key.
227
+ *
228
+ * Cardinality is normalized here rather than borrowed from resolve(). `_services[key]` has
229
+ * three shapes - absent, a bare ContainerService, an array - and resolve() maps them to
230
+ * throw / T / T[]. That is right for @Inject, whose dependency is single-valued: it is
231
+ * either there or the component is broken. @Strategy is multi-valued by construction, so
232
+ * zero is a cardinality it has to be able to take (a plugin point before its first plugin)
233
+ * and one has to arrive as a one-element array like any other count.
234
+ *
235
+ * This used to be a cast over resolve(), which made it correct at exactly one cardinality:
236
+ * an empty key aborted the boot, and a single implementation was injected as a bare
237
+ * instance whose first `.length` / `for...of` / `.map()` failed at runtime.
238
+ *
239
+ * @param {string} key - Strategy (interface) key
240
+ * @returns {Promise<T[]>} Every implementation, empty when the key has none
241
+ */
242
+ async resolveStrategy(key) {
243
+ // Kept from resolve(): a cycle running through a strategy key must still be reported
244
+ // rather than recursing until the stack overflows
245
+ this.circularDetector.checkCircular(key);
246
+ this.circularDetector.push(key);
247
+ try {
248
+ const service = this._services[key];
249
+ if (!service) {
250
+ return [];
251
+ }
252
+ return Array.isArray(service)
253
+ ? await this.resolveMultipleContainerService(service)
254
+ : [await this.resolveContainerService(service)];
255
+ }
256
+ finally {
257
+ this.circularDetector.pop(key);
258
+ }
259
+ }
260
+ /**
261
+ * @description Resolve every component of a kind.
262
+ * @param {ComponentKind} typeOfComponent - The kind the components were declared with
263
+ * @returns {Promise<(T | T[])[]>} One entry per key, empty when no component has the kind
264
+ */
265
+ async resolveAll(typeOfComponent) {
266
+ const matchingServices = this.filterServices(typeOfComponent);
267
+ const instances = [];
268
+ for (const containerService of matchingServices) {
269
+ if (Array.isArray(containerService)) {
270
+ instances.push(await this.resolveMultipleContainerService(containerService));
271
+ }
272
+ else {
273
+ instances.push(await this.resolveContainerService(containerService));
274
+ }
275
+ }
276
+ return instances;
277
+ }
278
+ filterServices(typeOfComponent) {
279
+ const matches = [];
280
+ for (const [key, value] of Object.entries(this._services)) {
281
+ const aliased = this.aliases.get(key);
282
+ const entries = (Array.isArray(value) ? value : [value]).filter((entry) => !aliased?.has(entry));
283
+ // Own-only, like component identity itself. Walking the chain here meant a @Service
284
+ // extending a component of another kind answered true for that kind, so it was
285
+ // resolved as one - without any of the own-only metadata that kind relies on.
286
+ if (!entries.length || !entries.every((entry) => getOwnTypedMetadata(typeOfComponent, entry.Class))) {
287
+ continue;
288
+ }
289
+ matches.push(entries.length > 1 ? entries : entries[0]);
290
+ }
291
+ return matches;
292
+ }
293
+ async resolveContainerService(containerService) {
294
+ if (!containerService.singleton) {
295
+ return await this.prepareInstance(containerService.Class);
296
+ }
297
+ if (containerService.instance === null || containerService.instance === undefined) {
298
+ throw new Error('instance cannot be null');
299
+ }
300
+ return containerService.instance;
301
+ }
302
+ async resolveMultipleContainerService(containerService) {
303
+ return Promise.all(containerService.map(async (_service) => this.resolveContainerService(_service)));
304
+ }
305
+ /**
306
+ * @description Register a ComponentPostProcessor for post-processing newly created instances.
307
+ * PostProcessors are called in FIFO order after DI + PostConstruct.
308
+ * @param {ComponentPostProcessor} processor - The post-processor to register
309
+ */
310
+ registerPostProcessor(processor) {
311
+ this.postProcessors.push(processor);
312
+ }
313
+ /**
314
+ * @description Choose whether construction runs start hooks or hands them to LifecycleService.
315
+ *
316
+ * The IoC engine switches to `deferred` around user components only. Post-processors keep
317
+ * running theirs at construction because `postProcess()` reads state a start hook sets - defer
318
+ * that and every component the processor wraps is built against an uninitialised processor.
319
+ *
320
+ * @param {StartHookMode} mode - immediate (default) or deferred
321
+ * @returns {void}
322
+ */
323
+ setStartHookMode(mode) {
324
+ this.startHookMode = mode;
325
+ }
326
+ /**
327
+ * @description Singletons in registration order, for the start/stop lifecycle.
328
+ * @returns {LifecycleComponent[]} The live list - LifecycleService flips `started` on it
329
+ */
330
+ get lifecycle() {
331
+ return this.lifecycleComponents;
332
+ }
333
+ async prepareInstance(Class) {
334
+ const newInstance = new Class();
335
+ this.injectValues(newInstance, Class); // configuration injection
336
+ await this.injectDependencies(newInstance, Class); // dependency injection
337
+ await this.injectStrategies(newInstance, Class); // strategy injection
338
+ // Post-processing (skipped when postProcessors is empty - zero overhead)
339
+ let processed = newInstance;
340
+ for (const processor of this.postProcessors) {
341
+ processed = (await processor.postProcess(processed, Class)) ?? processed;
342
+ }
343
+ // Deferred mode leaves the start hooks to LifecycleService. The hook runs against the
344
+ // *processed* instance either way - a post-processor may have returned a proxy, and the
345
+ // hook has to see the same object every other component was injected with.
346
+ if (this.startHookMode === 'immediate') {
347
+ await this.executeStartHooks(processed, Class);
348
+ }
349
+ return processed;
350
+ }
351
+ /**
352
+ * @description Run every @OnStart (and its @PostConstruct alias) method on an instance.
353
+ *
354
+ * Walks the prototype chain ancestors-first and runs each method name once, so a hook
355
+ * inherited by three classes still fires once.
356
+ *
357
+ * A failing hook is rethrown as a {@link StartHookError} naming the class and the method, with
358
+ * the original error as `cause` - the boot fails, the process decides what to do about it.
359
+ *
360
+ * @param {any} instance - The instance to run hooks on
361
+ * @param {Class} Class - The class of the instance
362
+ * @returns {Promise<void>}
363
+ * @throws {StartHookError} When a hook throws or rejects
364
+ */
365
+ async executeStartHooks(instance, Class) {
366
+ for (const hook of this.collectHookMethods(Class, ComponentConstants.PostConstructKey)) {
367
+ try {
368
+ await instance[hook]();
369
+ }
370
+ catch (error) {
371
+ throw new StartHookError(Class.name, hook, error);
372
+ }
373
+ }
374
+ }
375
+ /**
376
+ * @description The @OnStop method names for a class, in the order they should run.
377
+ *
378
+ * Reversed relative to the start hooks so a component tears down in the opposite order it
379
+ * was brought up, matching how LifecycleService walks the components themselves.
380
+ *
381
+ * @param {Class} Class - The class to inspect
382
+ * @returns {string[]} Method names, empty when the class declares none
383
+ */
384
+ getStopHooks(Class) {
385
+ return this.collectHookMethods(Class, ComponentConstants.OnStopKey).reverse();
386
+ }
387
+ /**
388
+ * @description The @OnStart method names for a class, in the order they run.
389
+ * @param {Class} Class - The class to inspect
390
+ * @returns {string[]} Method names, empty when the class declares none
391
+ */
392
+ getStartHooks(Class) {
393
+ return this.collectHookMethods(Class, ComponentConstants.PostConstructKey);
394
+ }
395
+ /**
396
+ * @description Collect decorated method names across the prototype chain, de-duplicated.
397
+ * @param {Class} Class - The class to inspect
398
+ * @param {symbol} metadataKey - Which hook list to read
399
+ * @returns {string[]} Method names, ancestors first
400
+ */
401
+ collectHookMethods(Class, metadataKey) {
402
+ const prototypeChain = this.getPrototypeChain(Class);
403
+ const methods = [];
404
+ const seen = new Set();
405
+ for (const classInChain of prototypeChain.reverse()) {
406
+ const hooks = getOwnTypedMetadata(metadataKey, classInChain);
407
+ if (!hooks) {
408
+ continue;
409
+ }
410
+ for (const hook of hooks) {
411
+ // Skip if already collected (prevents duplicate execution in inheritance chain)
412
+ if (seen.has(hook)) {
413
+ continue;
414
+ }
415
+ seen.add(hook);
416
+ methods.push(hook);
417
+ }
418
+ }
419
+ return methods;
420
+ }
421
+ async injectStrategies(newInstance, Class) {
422
+ const prototypeChain = this.getPrototypeChain(Class);
423
+ for (const classInChain of prototypeChain.reverse()) {
424
+ const strategyList = getOwnTypedMetadata(ComponentConstants.StrategyKey, classInChain);
425
+ if (!strategyList)
426
+ continue;
427
+ for (const [propertyKey, interfaceName] of Object.entries(strategyList)) {
428
+ if (!interfaceName) {
429
+ continue;
430
+ }
431
+ if (typeof interfaceName !== 'string') {
432
+ throw new Error('interfaceName must be a string');
433
+ }
434
+ // Same guard shape as injectDependencies, deliberately. Testing for the *descriptor*
435
+ // broke two ways: the chain runs ancestors-first, so a base class's accessor made the
436
+ // subclass's @Strategy override look "already set" and it was skipped; and under
437
+ // `useDefineForClassFields` (the default at ES2022+) an initializer-less field is an
438
+ // own property `= undefined` at construction, so the strategy was never injected at
439
+ // all. Bun's transpiler uses Set semantics, which is why running from source hides it.
440
+ const strategyProperty = Object.getOwnPropertyDescriptor(newInstance, propertyKey);
441
+ if (strategyProperty?.value !== undefined)
442
+ continue;
443
+ const strategy = await this.resolveStrategy(interfaceName);
444
+ const expression = getOwnTypedMetadata(ComponentConstants.ExpressionKey, classInChain);
445
+ Object.defineProperty(newInstance, propertyKey, {
446
+ get() {
447
+ return expression?.[propertyKey] ? strategy.map((s) => expression[propertyKey](s)) : strategy;
448
+ },
449
+ set: () => {
450
+ throw new TypeError(this.injectedFieldMessage(Class, propertyKey, '@Strategy'));
451
+ },
452
+ enumerable: true,
453
+ configurable: true,
454
+ });
455
+ }
456
+ }
457
+ }
458
+ /**
459
+ * @description Assigns every @Value field of the instance from process.env.
460
+ *
461
+ * Values land as plain writable properties - unlike @Inject fields they hold no
462
+ * resolved service to protect, and tests overwrite them freely. The own-property
463
+ * guard mirrors injectDependencies: a field initializer wins over the environment.
464
+ *
465
+ * @param {any} newInstance - The freshly constructed instance
466
+ * @param {Class} Class - The class of the instance
467
+ * @returns {void}
468
+ */
469
+ injectValues(newInstance, Class) {
470
+ for (const [field, spec] of Object.entries(collectValueFields(Class))) {
471
+ if (Object.getOwnPropertyDescriptor(newInstance, field)?.value !== undefined)
472
+ continue;
473
+ newInstance[field] = readValue(spec, Class, field);
474
+ }
475
+ }
476
+ async injectDependencies(newInstance, Class) {
477
+ const prototypeChain = this.getPrototypeChain(Class);
478
+ for (const classInChain of prototypeChain.reverse()) {
479
+ const deps = getOwnTypedMetadata(ComponentConstants.DependencyKey, classInChain);
480
+ if (!deps)
481
+ continue;
482
+ let property;
483
+ for (const [k, name] of Object.entries(deps)) {
484
+ property = Object.getOwnPropertyDescriptor(newInstance, k);
485
+ if (property?.value !== undefined)
486
+ continue;
487
+ let instance;
488
+ try {
489
+ instance = await this.resolve(name);
490
+ }
491
+ catch (error) {
492
+ // Only the container's own miss, and only once: a nested miss arrives already
493
+ // wrapped in a plain Error, and anything else - CircularDependencyError, a failed
494
+ // hook - must reach the caller unchanged.
495
+ if (error instanceof UnregisteredDependencyError) {
496
+ throw new Error(`'${name}' is not registered (injected into ${Class.name}.${k})`, { cause: error });
497
+ }
498
+ throw error;
499
+ }
500
+ if (instance === null) {
501
+ throw new Error('Instance cant be null ' + name);
502
+ }
503
+ const expression = getOwnTypedMetadata(ComponentConstants.ExpressionKey, classInChain);
504
+ Object.defineProperty(newInstance, k, {
505
+ get: () => {
506
+ return expression?.[k] ? expression[k](instance) : instance;
507
+ },
508
+ set: () => {
509
+ throw new TypeError(this.injectedFieldMessage(Class, k, '@Inject'));
510
+ },
511
+ enumerable: true,
512
+ configurable: true,
513
+ });
514
+ }
515
+ }
516
+ }
517
+ /**
518
+ * The message behind an assignment to a wired field.
519
+ *
520
+ * Injected fields are installed as accessors with no setter, so assigning to one throws the
521
+ * engine's own `TypeError: Attempted to assign to readonly property.` - no field name, no class,
522
+ * no hint at what to do instead. Everybody reaches for `Object.assign(instance, {dep: fake})`
523
+ * once; this turns that minute into a sentence.
524
+ */
525
+ injectedFieldMessage(Class, field, decorator) {
526
+ return (`Cannot assign to '${field}' on ${Class.name}: fields wired by ${decorator} are read-only. ` +
527
+ this.injectedFieldHint);
528
+ }
529
+ /**
530
+ * @description Checks if a class is a framework class (CoreService)
531
+ * Framework classes can traverse the prototype chain even if they contain native code patterns
532
+ * @param {any} cls - The class to check
533
+ * @returns {boolean} True if the class is a framework class
534
+ */
535
+ isFrameworkClass(cls) {
536
+ if (!cls || cls === Object.prototype) {
537
+ return false;
538
+ }
539
+ // Check if class is marked as a CoreService
540
+ const isCoreService = getTypedMetadata(CORE_SERVICE, cls);
541
+ return Boolean(isCoreService);
542
+ }
543
+ /**
544
+ * Deliberately NOT `getPrototypeChainOf` from utils, even though the two overlap.
545
+ *
546
+ * This walk carries two rules the generic helper does not: it bails out at a class whose
547
+ * source reads `[native code]` (so injection never tries to walk into a built-in or a bound
548
+ * constructor), with an escape hatch for `@CoreService` classes, and it returns leaf-first
549
+ * because every caller here reverses it themselves.
550
+ *
551
+ * The generic helper is the right reader for decorator metadata; this one guards instance
552
+ * construction. Merging them would mean picking one set of stop conditions for both.
553
+ */
554
+ getPrototypeChain(Class) {
555
+ const chain = [];
556
+ let currentClass = Class;
557
+ while (currentClass && currentClass !== Object.prototype) {
558
+ const classSource = currentClass.toString();
559
+ const isNativeCode = classSource.includes('[native code]');
560
+ // Stop at native code unless it's a framework class
561
+ if (isNativeCode && !this.isFrameworkClass(currentClass)) {
562
+ break;
563
+ }
564
+ chain.push(currentClass);
565
+ currentClass = Object.getPrototypeOf(currentClass);
566
+ }
567
+ return chain;
568
+ }
569
+ get services() {
570
+ return this._services;
571
+ }
572
+ set services(value) {
573
+ this._services = value;
574
+ this.aliases.clear();
575
+ }
576
+ }
577
+ //# sourceMappingURL=Container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Container.js","sourceRoot":"","sources":["../../lib/Container.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEvE;;;;;;;GAOG;AACH,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IACpD,YAAmB,OAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAErB;IACA;IAFlB,YACkB,SAAiB,EACjB,IAAY,EAC5B,KAAc;QAEd,KAAK,CAAC,kBAAkB,SAAS,IAAI,IAAI,YAAY,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAJlD,cAAS,GAAT,SAAS,CAAQ;QACjB,SAAI,GAAJ,IAAI,CAAQ;QAI5B,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,OAAO,SAAS;IACZ,SAAS,GAA6D,EAAE,CAAC;IAEzE,gBAAgB,GAAG,IAAI,0BAA0B,EAAE,CAAC;IAEpD,cAAc,GAA6B,EAAE,CAAC;IAE9C,cAAc,GAAG,IAAI,GAAG,EAAU,CAAC;IAE3C,8FAA8F;IACtF,OAAO,GAAG,IAAI,GAAG,EAAiC,CAAC;IAE3D;;;OA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