@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,88 @@
1
+ import { Container } from './Container';
2
+ import type { LifecycleState } from './lifecycle';
3
+ import type { IocLogger } from './logger';
4
+ import { type Class } from './types';
5
+ /**
6
+ * Options for {@link IocApplication.create}.
7
+ *
8
+ * A non-empty `components` list wins and disables the scan, otherwise `sourceFolder` is
9
+ * scanned. `imports` is always added on top of whichever one applied.
10
+ */
11
+ export interface IocApplicationOptions {
12
+ /** Explicit component classes. When non-empty, `sourceFolder` is not scanned. */
13
+ components?: Class[];
14
+ /**
15
+ * Components handed in by packages, in addition to `components` or the scan. Every entry
16
+ * must carry its own component decorator; the list is flattened one level.
17
+ */
18
+ imports?: (Class | readonly Class[])[];
19
+ /**
20
+ * Folder scanned for decorated classes. A relative path is resolved against the working
21
+ * directory, so a program that can be started from anywhere has to pass an absolute one.
22
+ */
23
+ sourceFolder?: string;
24
+ /**
25
+ * Entry file to keep out of the scan. The running module (`Bun.main`) is always excluded,
26
+ * so this is only needed when the declared entry differs from the file being executed.
27
+ */
28
+ rootFile?: string;
29
+ /** Milliseconds a scanned file may take to import before a warning is logged. 0 disables. */
30
+ importTimeout?: number;
31
+ /** Receives the engine's diagnostics. Defaults to the console, without debug output. */
32
+ logger?: IocLogger;
33
+ /**
34
+ * Values built outside the container, keyed by the name components inject them under:
35
+ * `@Inject('Environment')`. Any value except `null` and `undefined`. They are registered
36
+ * before the components, take no part in the start/stop lifecycle, and a component that
37
+ * claims the same name is an error.
38
+ */
39
+ instances?: Record<string, unknown>;
40
+ /**
41
+ * Test doubles keyed by name, seeded before anything else. The component registered under
42
+ * that name is never constructed, and an entry of `instances` under it is ignored.
43
+ */
44
+ overrides?: Record<string, object>;
45
+ }
46
+ /**
47
+ * The IoC container wired up on its own: container, engine and lifecycle.
48
+ *
49
+ * `create()` registers and constructs every component. Start hooks are deferred until
50
+ * {@link IocApplication.start}, so a hook always sees the finished graph; `stop()` runs the
51
+ * stop hooks in reverse order.
52
+ */
53
+ export declare class IocApplication {
54
+ private readonly _container;
55
+ private readonly engine;
56
+ private readonly lifecycle;
57
+ private constructor();
58
+ /**
59
+ * Build the container and register every component.
60
+ *
61
+ * @param {IocApplicationOptions} options - Component sources, logger, instances and overrides
62
+ * @returns {Promise<IocApplication>} The application, constructed but not started
63
+ */
64
+ static create(options?: IocApplicationOptions): Promise<IocApplication>;
65
+ /**
66
+ * Resolve a component by name or by class.
67
+ *
68
+ * @param {string | Class<T>} key - Component name, or the decorated class
69
+ * @returns {Promise<T>} The component
70
+ */
71
+ resolve<T>(key: string | Class<T>): Promise<T>;
72
+ /**
73
+ * Run every pending start hook, dependencies first.
74
+ *
75
+ * @returns {Promise<void>}
76
+ * @throws When a hook fails, after rolling back the components that already started
77
+ */
78
+ start(): Promise<void>;
79
+ /**
80
+ * Run stop hooks for everything that started, in reverse order.
81
+ *
82
+ * @param {number} hookTimeout - Per-hook ceiling in milliseconds
83
+ * @returns {Promise<number>} How many hooks threw, rejected or ran out of time
84
+ */
85
+ stop(hookTimeout?: number): Promise<number>;
86
+ get container(): Container;
87
+ get state(): LifecycleState;
88
+ }
@@ -0,0 +1,110 @@
1
+ import { Container } from './Container';
2
+ import { IocEngine } from './IocEngine';
3
+ import { ComponentConstants } from './constants';
4
+ import { LifecycleService } from './lifecycle';
5
+ import { ICoreServiceNames } from './types';
6
+ import { getTypedMetadata } from './utils/typedMetadata';
7
+ const consoleLogger = {
8
+ info: (message, meta) => (meta === undefined ? console.info(message) : console.info(message, meta)),
9
+ warn: (message, meta) => (meta === undefined ? console.warn(message) : console.warn(message, meta)),
10
+ error: (message, meta) => (meta === undefined ? console.error(message) : console.error(message, meta)),
11
+ };
12
+ /**
13
+ * The IoC container wired up on its own: container, engine and lifecycle.
14
+ *
15
+ * `create()` registers and constructs every component. Start hooks are deferred until
16
+ * {@link IocApplication.start}, so a hook always sees the finished graph; `stop()` runs the
17
+ * stop hooks in reverse order.
18
+ */
19
+ export class IocApplication {
20
+ _container;
21
+ engine;
22
+ lifecycle;
23
+ constructor(_container, engine, lifecycle) {
24
+ this._container = _container;
25
+ this.engine = engine;
26
+ this.lifecycle = lifecycle;
27
+ }
28
+ /**
29
+ * Build the container and register every component.
30
+ *
31
+ * @param {IocApplicationOptions} options - Component sources, logger, instances and overrides
32
+ * @returns {Promise<IocApplication>} The application, constructed but not started
33
+ */
34
+ static async create(options = {}) {
35
+ const { components, imports, sourceFolder, rootFile, importTimeout, instances, overrides } = options;
36
+ const container = new Container();
37
+ await container.registerInstance(ICoreServiceNames.CONTAINER, container);
38
+ await container.registerInstance(ICoreServiceNames.LOGGER, options.logger ?? consoleLogger);
39
+ await container.register(ICoreServiceNames.IOC_ENGINE, IocEngine, true);
40
+ await container.register(ICoreServiceNames.LIFECYCLE_SERVICE, LifecycleService, true);
41
+ const engine = (await container.resolve(ICoreServiceNames.IOC_ENGINE));
42
+ const lifecycle = (await container.resolve(ICoreServiceNames.LIFECYCLE_SERVICE));
43
+ for (const [name, instance] of Object.entries(overrides ?? {})) {
44
+ if (container.has(name)) {
45
+ throw new Error(`Cannot override '${name}' - it is one of the container's own services and has already ` + 'been wired.');
46
+ }
47
+ container.overrideInstance(name, instance);
48
+ }
49
+ for (const [name, instance] of Object.entries(instances ?? {})) {
50
+ if (container.isOverridden(name)) {
51
+ continue;
52
+ }
53
+ if (container.has(name)) {
54
+ throw new Error(`Cannot register instance '${name}' - the name belongs to one of the container's own services.`);
55
+ }
56
+ await container.registerInstance(name, instance);
57
+ }
58
+ if (sourceFolder) {
59
+ engine.setConfig({ sourceFolder, rootFile, importTimeout });
60
+ }
61
+ const importClasses = imports?.flatMap((entry) => (Array.isArray(entry) ? entry : [entry]));
62
+ if (components?.length) {
63
+ const injectables = components.map((component) => ({
64
+ Class: component,
65
+ interface: getTypedMetadata(ComponentConstants.InterfaceKey, component),
66
+ }));
67
+ await engine.searchAndRegister(injectables, importClasses);
68
+ }
69
+ else if (sourceFolder || importClasses?.length) {
70
+ await engine.searchAndRegister(undefined, importClasses);
71
+ }
72
+ return new IocApplication(container, engine, lifecycle);
73
+ }
74
+ /**
75
+ * Resolve a component by name or by class.
76
+ *
77
+ * @param {string | Class<T>} key - Component name, or the decorated class
78
+ * @returns {Promise<T>} The component
79
+ */
80
+ async resolve(key) {
81
+ const name = typeof key === 'string' ? key : getTypedMetadata(ComponentConstants.NameKey, key) || key.name;
82
+ return (await this._container.resolve(name));
83
+ }
84
+ /**
85
+ * Run every pending start hook, dependencies first.
86
+ *
87
+ * @returns {Promise<void>}
88
+ * @throws When a hook fails, after rolling back the components that already started
89
+ */
90
+ async start() {
91
+ this.engine.warnAboutLateEntryComponents();
92
+ await this.lifecycle.start();
93
+ }
94
+ /**
95
+ * Run stop hooks for everything that started, in reverse order.
96
+ *
97
+ * @param {number} hookTimeout - Per-hook ceiling in milliseconds
98
+ * @returns {Promise<number>} How many hooks threw, rejected or ran out of time
99
+ */
100
+ async stop(hookTimeout) {
101
+ return this.lifecycle.stop(hookTimeout);
102
+ }
103
+ get container() {
104
+ return this._container;
105
+ }
106
+ get state() {
107
+ return this.lifecycle.state;
108
+ }
109
+ }
110
+ //# sourceMappingURL=IocApplication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IocApplication.js","sourceRoot":"","sources":["../../lib/IocApplication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,EAAc,iBAAiB,EAA4B,MAAM,SAAS,CAAC;AAClF,OAAO,EAAE,gBAAg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CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,KAAK;QAChB,IAAI,CAAC,MAAM,CAAC,4BAA4B,EAAE,CAAC;QAE3C,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,IAAI,CAAC,WAAoB;QACpC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC1C,CAAC;IAED,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;IAC9B,CAAC;CACF"}
@@ -0,0 +1,173 @@
1
+ import { type Class, type ICoreService, type InjectableComponent, type IocConfig } from './types';
2
+ import type { Container } from './Container';
3
+ export declare class IocEngine implements ICoreService {
4
+ serviceName: string;
5
+ private _container;
6
+ private logger;
7
+ private injectables;
8
+ private config?;
9
+ /** Entry files kept out of the scan, empty unless the scan actually ran */
10
+ private entryFiles;
11
+ /** Entry-declared components that existed by the time the scan ran */
12
+ private entryComponents;
13
+ /**
14
+ * @description Set IoC configuration
15
+ * @param {IocConfig} config - IoC configuration object
16
+ * @returns {void}
17
+ */
18
+ setConfig(config?: IocConfig): void;
19
+ searchAndRegister(components?: InjectableComponent[], imports?: Class[]): Promise<void>;
20
+ private loadComponents;
21
+ private describeClass;
22
+ /**
23
+ * @description Refuse a component whose name is already held by something registered ahead of
24
+ * the components: one of the container's own services, or a pre-built instance.
25
+ *
26
+ * `Container.register` promotes a key that is registered twice to an array, which is how
27
+ * several implementations share an interface key. Under a component's own name it means
28
+ * every dependent is handed `[instance, component]` instead of either one, so the collision
29
+ * is reported here, before anything is constructed. An overridden name is exempt: there the
30
+ * double replaces the component on purpose.
31
+ * @returns {void}
32
+ * @throws When a component name is already registered
33
+ */
34
+ private rejectTakenNames;
35
+ /**
36
+ * @description Report components that were declared in the entry file *after* the
37
+ * bootstrap call. Their decorators had not run yet when the scan read the registry,
38
+ * so they never made it into the container - and without this they would just be
39
+ * quietly missing at runtime.
40
+ * @param {string} bootstrapCall - How the warning names the call that built the container
41
+ * @returns {void}
42
+ */
43
+ warnAboutLateEntryComponents(bootstrapCall?: string): void;
44
+ /**
45
+ * @description Absolute paths of the files that must be kept out of the scan:
46
+ * the entry declared in the config, and the module actually being executed.
47
+ * They are usually the same file, but not always - a project may declare one
48
+ * `rootFile` and start another, or run without a config at all.
49
+ * @returns {Set<string>} Resolved absolute entry paths
50
+ */
51
+ private resolveEntryFiles;
52
+ /**
53
+ * @description Resolve a scanned path against the working directory. `getAllFiles`
54
+ * mirrors the form of the folder it was given, so a `sourceFolder` configured as an
55
+ * absolute path yields absolute entries that must not be joined onto cwd again.
56
+ * @param {string} file - Path as returned by the scan
57
+ * @returns {string} Absolute path
58
+ */
59
+ private toAbsolutePath;
60
+ /**
61
+ * @description Collapse components that arrived from more than one source - a class
62
+ * re-exported through a barrel file, or one found by both the scan and the registry.
63
+ *
64
+ * Deduplication is by class identity, not by name: `Container.register` promotes a
65
+ * key to an array when the same name is registered twice, which would construct the
66
+ * component a second time (running @PostConstruct again) and hand every dependent an
67
+ * array instead of an instance.
68
+ * @param {InjectableComponent[]} components - Components from every source
69
+ * @returns {InjectableComponent[]} Components with duplicates removed
70
+ */
71
+ private dedupeInjectables;
72
+ private validateAndRegisterComponents;
73
+ private register;
74
+ /**
75
+ * @description Warn when a transient declares lifecycle hooks.
76
+ *
77
+ * A transient is constructed per resolve and the container keeps no handle on it, so there is
78
+ * nothing for the lifecycle to start or stop. Its @OnStart still runs at construction, but its
79
+ * @OnStop can never run - and a component that acquires something it never releases is worth
80
+ * saying out loud rather than leaving to be discovered as a leak.
81
+ *
82
+ * @param {string} name - Registered component name
83
+ * @param {Class} injectable - The component class
84
+ * @returns {void}
85
+ */
86
+ private warnAboutTransientLifecycleHooks;
87
+ private getInjectables;
88
+ private importFiles;
89
+ /**
90
+ * @description Import a single component file, pointing at it if it takes suspiciously
91
+ * long. A module whose top-level await never settles would otherwise hang the boot with
92
+ * no output at all; the import itself is left alone, only reported.
93
+ * @param {string} filePath - Absolute path to import
94
+ * @param {string} file - Path as scanned, for the message
95
+ * @param {number} timeout - Milliseconds before warning, 0 disables
96
+ * @returns {Promise<any>} The imported module namespace
97
+ */
98
+ private importFile;
99
+ private processComponents;
100
+ /**
101
+ * Validates and converts the `imports` list. Like an explicitly listed component, and unlike a
102
+ * scanned class, an import that carries no decorator of its own is a hard error: a silently
103
+ * dropped import is exactly the failure the option exists to prevent.
104
+ */
105
+ private processImports;
106
+ /**
107
+ * The error for an `imports` entry that failed the identity check. A class that extends a
108
+ * component but carries no decorator of its own is told so explicitly: whoever can see
109
+ * `@Service` on the base class reads the generic message as a contradiction.
110
+ * @param {any} entry - The rejected entry
111
+ * @returns {string} The message to throw
112
+ */
113
+ private describeInvalidImport;
114
+ private describeInvalidListedComponent;
115
+ /**
116
+ * @description The nearest class up the prototype chain that carries its own component
117
+ * decorator, or undefined when none does.
118
+ * @param {any} component - A class, or anything else (yields undefined)
119
+ * @returns {Class | undefined} The decorated ancestor
120
+ */
121
+ private findDecoratedAncestor;
122
+ /**
123
+ * Reports a scanned class that extends a component but carries no decorator of its own. An
124
+ * explicitly listed one never gets here: `loadComponents` rejects it outright.
125
+ *
126
+ * Component identity is read own-only, so such a class is simply skipped. Registering it
127
+ * under its *base's* name blew up on first inject - ugly, but at least detectable. Skipping
128
+ * it silently is worse: whatever the class was meant to do never happens and nothing
129
+ * anywhere says so.
130
+ *
131
+ * Only fires when an ancestor carries the marker, so an ordinary undecorated helper class in
132
+ * the scan folder stays quiet. A decorator that returns a wrapper subclass and applies
133
+ * `@Service` to the wrapper gives the wrapper its own marker, so it never reaches here.
134
+ */
135
+ private warnAboutUndecoratedSubclass;
136
+ private isValidComponent;
137
+ private createComponentObject;
138
+ private topologicalSort;
139
+ private initializeGraph;
140
+ /**
141
+ * `@Inject('IMailer')` names an `@Implements` interface key, not a component, so it has no node
142
+ * in the graph. Its implementations are the components that must be registered first.
143
+ */
144
+ private expandInterfaceDependency;
145
+ private findCycle;
146
+ /**
147
+ * @description Separates PostProcessor classes and their transitive dependencies from other components.
148
+ * PostProcessors and their deps are registered in Phase A (before post-processing is active).
149
+ * Non-PostProcessor dependencies pulled into Phase A will NOT be post-processed (by design).
150
+ */
151
+ private separatePostProcessors;
152
+ private getDependencies;
153
+ /**
154
+ * Every strategy key a component consumes, keyed by the field that declares it. Walks the
155
+ * prototype chain like getStrategyDependencies does - a @Strategy field on a base class is
156
+ * injected into the subclass too, so it has to be reported against the subclass. Own class
157
+ * first, so a field redeclared in a subclass wins the same way injection resolves it.
158
+ */
159
+ private collectStrategyFields;
160
+ /**
161
+ * Reports strategy keys nothing implements, once per injection site, at boot.
162
+ *
163
+ * An empty key is a legitimate plugin point and is injected as `[]`, which means a *typo'd*
164
+ * interface name no longer fails at boot either - it surfaces much later as a collection
165
+ * that is silently always empty. This line is what keeps the two apart.
166
+ *
167
+ * `debug` with no fallback to `info`, deliberately: a deliberate plugin point should stay
168
+ * quiet unless someone is looking.
169
+ */
170
+ private reportEmptyStrategyKeys;
171
+ private getStrategyDependencies;
172
+ get container(): Container;
173
+ }