@illuma/core 1.1.0 → 1.3.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.
- package/CHANGELOG.md +16 -0
- package/README.md +170 -170
- package/dist/index.cjs +176 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +133 -82
- package/dist/index.d.ts +133 -82
- package/dist/index.js +172 -83
- package/dist/index.js.map +1 -1
- package/dist/{injection-CSxu56ds.d.cts → injection-C2z7Ycba.d.ts} +4 -2
- package/dist/{injection-Y_bVmBSk.d.ts → injection-QKbSn2Jk.d.cts} +4 -2
- package/dist/{plugin-container-D8Zwpigq.d.cts → plugin-container-DkECHcvu.d.cts} +25 -22
- package/dist/{plugin-container-CwkVlVS4.d.ts → plugin-container-GF2OqmiJ.d.ts} +25 -22
- package/dist/plugins.d.cts +3 -3
- package/dist/plugins.d.ts +3 -3
- package/dist/testkit.cjs +127 -80
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.d.cts +2 -2
- package/dist/testkit.d.ts +2 -2
- package/dist/testkit.js +127 -80
- package/dist/testkit.js.map +1 -1
- package/dist/{providers-D9YA8L_g.d.cts → types-5mX9F_24.d.cts} +1 -1
- package/dist/{providers-D9YA8L_g.d.ts → types-5mX9F_24.d.ts} +1 -1
- package/package.json +74 -74
package/dist/index.d.cts
CHANGED
|
@@ -1,82 +1,13 @@
|
|
|
1
|
-
import { N as
|
|
2
|
-
export { e as extractToken,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/** @internal */
|
|
7
|
-
type InjectorFn = (token: NodeBase<any>, optional?: boolean) => any;
|
|
8
|
-
/**
|
|
9
|
-
* Internal context manager for tracking dependency injections during factory execution.
|
|
10
|
-
* This class manages the injection context lifecycle and tracks all injection calls.
|
|
11
|
-
*
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
declare abstract class InjectionContext {
|
|
15
|
-
static contextOpen: boolean;
|
|
16
|
-
static readonly _calls: Set<iInjectionNode<any>>;
|
|
17
|
-
static injector: InjectorFn | null;
|
|
18
|
-
private static readonly _scanners;
|
|
19
|
-
/**
|
|
20
|
-
* Adds a dependency to the current injection context.
|
|
21
|
-
* Called by `nodeInject` when a dependency is requested.
|
|
22
|
-
*
|
|
23
|
-
* @param node - The injection node representing the dependency
|
|
24
|
-
* @throws {InjectionError} If called outside of an active injection context
|
|
25
|
-
*/
|
|
26
|
-
static addDep(node: iInjectionNode<any>): void;
|
|
27
|
-
/**
|
|
28
|
-
* Opens a new injection context.
|
|
29
|
-
* Resets the calls set and sets the injector if provided.
|
|
30
|
-
*
|
|
31
|
-
* @param injector - Optional injector function to use for resolving dependencies
|
|
32
|
-
*/
|
|
33
|
-
/**
|
|
34
|
-
* Scans a factory function for dependencies.
|
|
35
|
-
* Executes the factory in a dry-run mode to capture `nodeInject` calls.
|
|
36
|
-
* Also runs registered context scanners.
|
|
37
|
-
*
|
|
38
|
-
* @param factory - The factory function to scan
|
|
39
|
-
* @returns A set of detected injection nodes
|
|
40
|
-
*/
|
|
41
|
-
static open(injector?: InjectorFn): void;
|
|
42
|
-
static scan(factory: any): Set<iInjectionNode<any>>;
|
|
43
|
-
static instantiate<T>(factory: () => T, injector: InjectorFn): T;
|
|
44
|
-
static closeAndReport(): Set<iInjectionNode<any>>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Interface for dependency injection containers.
|
|
49
|
-
* Defines the core methods that all DI containers must implement.
|
|
50
|
-
*/
|
|
51
|
-
interface iDIContainer {
|
|
52
|
-
/**
|
|
53
|
-
* Registers a provider in the container.
|
|
54
|
-
* @template T - The type of value being provided
|
|
55
|
-
* @param provider - The provider configuration
|
|
56
|
-
*/
|
|
57
|
-
provide<T>(provider: Provider<T>): void;
|
|
58
|
-
/**
|
|
59
|
-
* @internal Finds the tree node associated with the given token.
|
|
60
|
-
* @template T - The type of value being searched
|
|
61
|
-
* @param token - The token or constructor to find
|
|
62
|
-
* @returns The associated tree node, or null if not found
|
|
63
|
-
*/
|
|
64
|
-
findNode<T>(token: Token<T>): TreeNode<T> | null;
|
|
65
|
-
/**
|
|
66
|
-
* Retrieves an instance for the given token.
|
|
67
|
-
* @template T - The type of value being retrieved
|
|
68
|
-
* @param token - The token or constructor to retrieve
|
|
69
|
-
* @returns The resolved instance
|
|
70
|
-
*/
|
|
71
|
-
get<T>(token: MultiNodeToken<T>): T[];
|
|
72
|
-
get<T>(token: NodeToken<T>): T;
|
|
73
|
-
get<T>(token: Ctor<T>): T;
|
|
74
|
-
produce<T>(fn: Ctor<T> | (() => T)): T;
|
|
75
|
-
}
|
|
1
|
+
import { C as Ctor, N as NodeToken, P as Provider, T as Token, M as MultiNodeToken, a as NodeBase } from './types-5mX9F_24.cjs';
|
|
2
|
+
export { e as extractToken, i as isNodeBase } from './types-5mX9F_24.cjs';
|
|
3
|
+
import { I as InjectorFn, i as iNodeInjectorOptions, E as ExtractInjectedType } from './injection-QKbSn2Jk.cjs';
|
|
4
|
+
export { N as NodeInjectFn, n as nodeInject } from './injection-QKbSn2Jk.cjs';
|
|
5
|
+
import { T as TreeNode, I as Illuma, i as iInjectionNode } from './plugin-container-DkECHcvu.cjs';
|
|
76
6
|
|
|
77
7
|
/**
|
|
78
8
|
* Symbol used to mark classes as injectable and store their associated token.
|
|
79
9
|
* @internal
|
|
10
|
+
* @deprecated Use internal registry instead
|
|
80
11
|
*/
|
|
81
12
|
declare const INJECTION_SYMBOL: unique symbol;
|
|
82
13
|
/**
|
|
@@ -110,6 +41,7 @@ declare function NodeInjectable<T>(): (ctor: Ctor<T>) => Ctor<T>;
|
|
|
110
41
|
* @example
|
|
111
42
|
* ```typescript
|
|
112
43
|
* import { makeInjectable } from '@illuma/core';
|
|
44
|
+
import { InjectionError } from '../errors';
|
|
113
45
|
*
|
|
114
46
|
* class _UserService {
|
|
115
47
|
* public getUser() {
|
|
@@ -123,14 +55,21 @@ declare function NodeInjectable<T>(): (ctor: Ctor<T>) => Ctor<T>;
|
|
|
123
55
|
*/
|
|
124
56
|
declare function makeInjectable<T>(ctor: Ctor<T>): Ctor<T>;
|
|
125
57
|
/** @internal */
|
|
126
|
-
declare function isInjectable<T>(ctor: unknown): ctor is Ctor<T
|
|
127
|
-
[INJECTION_SYMBOL]: NodeToken<T>;
|
|
128
|
-
};
|
|
58
|
+
declare function isInjectable<T>(ctor: unknown): ctor is Ctor<T>;
|
|
129
59
|
/** @internal */
|
|
130
|
-
declare function getInjectableToken<T>(ctor: Ctor<T>
|
|
131
|
-
[INJECTION_SYMBOL]: NodeToken<T>;
|
|
132
|
-
}): NodeToken<T>;
|
|
60
|
+
declare function getInjectableToken<T>(ctor: Ctor<T>): NodeToken<T>;
|
|
133
61
|
declare function isConstructor(fn: unknown): fn is Ctor<any>;
|
|
62
|
+
/**
|
|
63
|
+
* Registers a class as injectable with a specific token.
|
|
64
|
+
* Use this function to manually associate a class with a token.
|
|
65
|
+
*
|
|
66
|
+
* Normally, the {@link NodeInjectable} and {@link makeInjectable} decorator is used to mark classes as injectable,
|
|
67
|
+
* but if developing a plugin that requires manual registration, this function can be used.
|
|
68
|
+
*
|
|
69
|
+
* @param ctor - The class constructor to register
|
|
70
|
+
* @param token - The token to associate with the class
|
|
71
|
+
*/
|
|
72
|
+
declare function registerClassAsInjectable<T>(ctor: Ctor<T>, token: NodeToken<T>): void;
|
|
134
73
|
|
|
135
74
|
/**
|
|
136
75
|
* Configuration options for the NodeContainer.
|
|
@@ -142,9 +81,57 @@ interface iContainerOptions {
|
|
|
142
81
|
* @default false
|
|
143
82
|
*/
|
|
144
83
|
measurePerformance?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* When true, enables diagnostics reporting after bootstrap.
|
|
86
|
+
* @default false
|
|
87
|
+
*/
|
|
145
88
|
diagnostics?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* @internal
|
|
91
|
+
* The parent container for hierarchical dependency resolution.
|
|
92
|
+
*/
|
|
146
93
|
parent?: iDIContainer;
|
|
94
|
+
/**
|
|
95
|
+
* @experimental
|
|
96
|
+
* Whether to instantiate dependencies immediately.
|
|
97
|
+
* If disabled, providers instantiation will happen when first requested.
|
|
98
|
+
* This helps improve startup performance for large containers.
|
|
99
|
+
* Enabled by default until stable.
|
|
100
|
+
*
|
|
101
|
+
* @default true
|
|
102
|
+
*/
|
|
103
|
+
instant?: boolean;
|
|
147
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Interface for dependency injection containers.
|
|
107
|
+
* Defines the core methods that all DI containers must implement.
|
|
108
|
+
*/
|
|
109
|
+
interface iDIContainer {
|
|
110
|
+
/**
|
|
111
|
+
* Registers a provider in the container.
|
|
112
|
+
* @template T - The type of value being provided
|
|
113
|
+
* @param provider - The provider configuration
|
|
114
|
+
*/
|
|
115
|
+
provide<T>(provider: Provider<T>): void;
|
|
116
|
+
/**
|
|
117
|
+
* @internal Finds the tree node associated with the given token.
|
|
118
|
+
* @template T - The type of value being searched
|
|
119
|
+
* @param token - The token or constructor to find
|
|
120
|
+
* @returns The associated tree node, or null if not found
|
|
121
|
+
*/
|
|
122
|
+
findNode<T>(token: Token<T>): TreeNode<T> | null;
|
|
123
|
+
/**
|
|
124
|
+
* Retrieves an instance for the given token.
|
|
125
|
+
* @template T - The type of value being retrieved
|
|
126
|
+
* @param token - The token or constructor to retrieve
|
|
127
|
+
* @returns The resolved instance
|
|
128
|
+
*/
|
|
129
|
+
get<T>(token: MultiNodeToken<T>): T[];
|
|
130
|
+
get<T>(token: NodeToken<T>): T;
|
|
131
|
+
get<T>(token: Ctor<T>): T;
|
|
132
|
+
produce<T>(fn: Ctor<T> | (() => T)): T;
|
|
133
|
+
}
|
|
134
|
+
|
|
148
135
|
declare class NodeContainer extends Illuma implements iDIContainer {
|
|
149
136
|
private readonly _opts?;
|
|
150
137
|
private _bootstrapped;
|
|
@@ -238,6 +225,63 @@ declare class NodeContainer extends Illuma implements iDIContainer {
|
|
|
238
225
|
produce<T>(fn: Ctor<T> | (() => T)): T;
|
|
239
226
|
}
|
|
240
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Internal context manager for tracking dependency injections during factory execution.
|
|
230
|
+
* This class manages the injection context lifecycle and tracks all injection calls.
|
|
231
|
+
*
|
|
232
|
+
* @internal
|
|
233
|
+
*/
|
|
234
|
+
declare abstract class InjectionContext {
|
|
235
|
+
static contextOpen: boolean;
|
|
236
|
+
static readonly _calls: Set<iInjectionNode<any>>;
|
|
237
|
+
static injector: InjectorFn | null;
|
|
238
|
+
private static readonly _scanners;
|
|
239
|
+
/**
|
|
240
|
+
* Adds a dependency to the current injection context.
|
|
241
|
+
* Called by `nodeInject` when a dependency is requested.
|
|
242
|
+
*
|
|
243
|
+
* @param node - The injection node representing the dependency
|
|
244
|
+
* @throws {InjectionError} If called outside of an active injection context
|
|
245
|
+
*/
|
|
246
|
+
static addDep(node: iInjectionNode<any>): void;
|
|
247
|
+
/**
|
|
248
|
+
* Opens a new injection context.
|
|
249
|
+
* Resets the calls set and sets the injector if provided.
|
|
250
|
+
*
|
|
251
|
+
* @param injector - Optional injector function to use for resolving dependencies
|
|
252
|
+
*/
|
|
253
|
+
/**
|
|
254
|
+
* Scans a factory function for dependencies.
|
|
255
|
+
* Executes the factory in a dry-run mode to capture `nodeInject` calls.
|
|
256
|
+
* Also runs registered context scanners.
|
|
257
|
+
*
|
|
258
|
+
* @param factory - The factory function to scan
|
|
259
|
+
* @returns A set of detected injection nodes
|
|
260
|
+
*/
|
|
261
|
+
static open(injector?: InjectorFn): void;
|
|
262
|
+
static scan(factory: any): Set<iInjectionNode<any>>;
|
|
263
|
+
static instantiate<T>(factory: () => T, injector: InjectorFn): T;
|
|
264
|
+
static closeAndReport(): Set<iInjectionNode<any>>;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
declare const ERR_CODES: {
|
|
268
|
+
readonly DUPLICATE_PROVIDER: 100;
|
|
269
|
+
readonly DUPLICATE_FACTORY: 101;
|
|
270
|
+
readonly INVALID_CTOR: 102;
|
|
271
|
+
readonly INVALID_PROVIDER: 103;
|
|
272
|
+
readonly INVALID_ALIAS: 200;
|
|
273
|
+
readonly LOOP_ALIAS: 201;
|
|
274
|
+
readonly NOT_BOOTSTRAPPED: 300;
|
|
275
|
+
readonly BOOTSTRAPPED: 301;
|
|
276
|
+
readonly DOUBLE_BOOTSTRAP: 302;
|
|
277
|
+
readonly NOT_FOUND: 400;
|
|
278
|
+
readonly CIRCULAR_DEPENDENCY: 401;
|
|
279
|
+
readonly UNTRACKED: 500;
|
|
280
|
+
readonly OUTSIDE_CONTEXT: 501;
|
|
281
|
+
readonly CALLED_UTILS_OUTSIDE_CONTEXT: 502;
|
|
282
|
+
readonly INSTANCE_ACCESS_FAILED: 503;
|
|
283
|
+
readonly ACCESS_FAILED: 504;
|
|
284
|
+
};
|
|
241
285
|
declare class InjectionError extends Error {
|
|
242
286
|
readonly code: number;
|
|
243
287
|
constructor(code: number, message: string);
|
|
@@ -259,6 +303,12 @@ declare class InjectionError extends Error {
|
|
|
259
303
|
static accessFailed(): InjectionError;
|
|
260
304
|
}
|
|
261
305
|
|
|
306
|
+
declare function injectDefer<N>(token: N, options: iNodeInjectorOptions & {
|
|
307
|
+
optional: true;
|
|
308
|
+
}): () => N extends MultiNodeToken<infer V> ? V[] : N extends NodeToken<infer U> ? U | null : N extends new (...args: any[]) => infer T ? T | null : never;
|
|
309
|
+
declare function injectDefer<N>(token: N, options?: iNodeInjectorOptions): () => N extends MultiNodeToken<infer V> ? V[] : N extends NodeToken<infer U> ? U : N extends new (...args: any) => infer T ? T : never;
|
|
310
|
+
declare function injectDefer<N extends NodeToken<unknown> | MultiNodeToken<unknown>>(token: N, options?: iNodeInjectorOptions): () => ExtractInjectedType<N>;
|
|
311
|
+
|
|
262
312
|
interface iInjector {
|
|
263
313
|
/** The DI container associated with this injector */
|
|
264
314
|
readonly container: iDIContainer;
|
|
@@ -300,6 +350,7 @@ declare class InjectorImpl implements iInjector {
|
|
|
300
350
|
* @example
|
|
301
351
|
* ```typescript
|
|
302
352
|
* import { Injector, nodeInject, NodeInjectable, NodeContainer } from "@illuma/core";
|
|
353
|
+
import { iDIContainer } from '../container/types';
|
|
303
354
|
*
|
|
304
355
|
* @NodeInjectable()
|
|
305
356
|
* class MyService {
|
|
@@ -375,4 +426,4 @@ declare function injectEntryAsync<T>(fn: MaybeAsyncFactory<iEntrypointConfig<Nod
|
|
|
375
426
|
declare function injectEntryAsync<T>(fn: MaybeAsyncFactory<iEntrypointConfig<Ctor<T>>>, opts?: iInjectionOptions): () => Promise<T>;
|
|
376
427
|
declare function injectEntryAsync<T>(fn: MaybeAsyncFactory<iEntrypointConfig<MultiNodeToken<T>>>, opts?: iInjectionOptions): () => Promise<T>;
|
|
377
428
|
|
|
378
|
-
export {
|
|
429
|
+
export { ExtractInjectedType, ERR_CODES as ILLUMA_ERR_CODES, INJECTION_SYMBOL, InjectionContext, InjectionError, Injector, InjectorFn, InjectorImpl, MultiNodeToken, NodeBase, NodeContainer, NodeInjectable, NodeToken, getInjectableToken, type iContainerOptions, type iDIContainer, type iEntrypointConfig, iInjectionNode, type iInjector, iNodeInjectorOptions, injectAsync, injectDefer, injectEntryAsync, injectGroupAsync, isConstructor, isInjectable, makeInjectable, registerClassAsInjectable };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,82 +1,13 @@
|
|
|
1
|
-
import { N as
|
|
2
|
-
export { e as extractToken,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/** @internal */
|
|
7
|
-
type InjectorFn = (token: NodeBase<any>, optional?: boolean) => any;
|
|
8
|
-
/**
|
|
9
|
-
* Internal context manager for tracking dependency injections during factory execution.
|
|
10
|
-
* This class manages the injection context lifecycle and tracks all injection calls.
|
|
11
|
-
*
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
declare abstract class InjectionContext {
|
|
15
|
-
static contextOpen: boolean;
|
|
16
|
-
static readonly _calls: Set<iInjectionNode<any>>;
|
|
17
|
-
static injector: InjectorFn | null;
|
|
18
|
-
private static readonly _scanners;
|
|
19
|
-
/**
|
|
20
|
-
* Adds a dependency to the current injection context.
|
|
21
|
-
* Called by `nodeInject` when a dependency is requested.
|
|
22
|
-
*
|
|
23
|
-
* @param node - The injection node representing the dependency
|
|
24
|
-
* @throws {InjectionError} If called outside of an active injection context
|
|
25
|
-
*/
|
|
26
|
-
static addDep(node: iInjectionNode<any>): void;
|
|
27
|
-
/**
|
|
28
|
-
* Opens a new injection context.
|
|
29
|
-
* Resets the calls set and sets the injector if provided.
|
|
30
|
-
*
|
|
31
|
-
* @param injector - Optional injector function to use for resolving dependencies
|
|
32
|
-
*/
|
|
33
|
-
/**
|
|
34
|
-
* Scans a factory function for dependencies.
|
|
35
|
-
* Executes the factory in a dry-run mode to capture `nodeInject` calls.
|
|
36
|
-
* Also runs registered context scanners.
|
|
37
|
-
*
|
|
38
|
-
* @param factory - The factory function to scan
|
|
39
|
-
* @returns A set of detected injection nodes
|
|
40
|
-
*/
|
|
41
|
-
static open(injector?: InjectorFn): void;
|
|
42
|
-
static scan(factory: any): Set<iInjectionNode<any>>;
|
|
43
|
-
static instantiate<T>(factory: () => T, injector: InjectorFn): T;
|
|
44
|
-
static closeAndReport(): Set<iInjectionNode<any>>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Interface for dependency injection containers.
|
|
49
|
-
* Defines the core methods that all DI containers must implement.
|
|
50
|
-
*/
|
|
51
|
-
interface iDIContainer {
|
|
52
|
-
/**
|
|
53
|
-
* Registers a provider in the container.
|
|
54
|
-
* @template T - The type of value being provided
|
|
55
|
-
* @param provider - The provider configuration
|
|
56
|
-
*/
|
|
57
|
-
provide<T>(provider: Provider<T>): void;
|
|
58
|
-
/**
|
|
59
|
-
* @internal Finds the tree node associated with the given token.
|
|
60
|
-
* @template T - The type of value being searched
|
|
61
|
-
* @param token - The token or constructor to find
|
|
62
|
-
* @returns The associated tree node, or null if not found
|
|
63
|
-
*/
|
|
64
|
-
findNode<T>(token: Token<T>): TreeNode<T> | null;
|
|
65
|
-
/**
|
|
66
|
-
* Retrieves an instance for the given token.
|
|
67
|
-
* @template T - The type of value being retrieved
|
|
68
|
-
* @param token - The token or constructor to retrieve
|
|
69
|
-
* @returns The resolved instance
|
|
70
|
-
*/
|
|
71
|
-
get<T>(token: MultiNodeToken<T>): T[];
|
|
72
|
-
get<T>(token: NodeToken<T>): T;
|
|
73
|
-
get<T>(token: Ctor<T>): T;
|
|
74
|
-
produce<T>(fn: Ctor<T> | (() => T)): T;
|
|
75
|
-
}
|
|
1
|
+
import { C as Ctor, N as NodeToken, P as Provider, T as Token, M as MultiNodeToken, a as NodeBase } from './types-5mX9F_24.js';
|
|
2
|
+
export { e as extractToken, i as isNodeBase } from './types-5mX9F_24.js';
|
|
3
|
+
import { I as InjectorFn, i as iNodeInjectorOptions, E as ExtractInjectedType } from './injection-C2z7Ycba.js';
|
|
4
|
+
export { N as NodeInjectFn, n as nodeInject } from './injection-C2z7Ycba.js';
|
|
5
|
+
import { T as TreeNode, I as Illuma, i as iInjectionNode } from './plugin-container-GF2OqmiJ.js';
|
|
76
6
|
|
|
77
7
|
/**
|
|
78
8
|
* Symbol used to mark classes as injectable and store their associated token.
|
|
79
9
|
* @internal
|
|
10
|
+
* @deprecated Use internal registry instead
|
|
80
11
|
*/
|
|
81
12
|
declare const INJECTION_SYMBOL: unique symbol;
|
|
82
13
|
/**
|
|
@@ -110,6 +41,7 @@ declare function NodeInjectable<T>(): (ctor: Ctor<T>) => Ctor<T>;
|
|
|
110
41
|
* @example
|
|
111
42
|
* ```typescript
|
|
112
43
|
* import { makeInjectable } from '@illuma/core';
|
|
44
|
+
import { InjectionError } from '../errors';
|
|
113
45
|
*
|
|
114
46
|
* class _UserService {
|
|
115
47
|
* public getUser() {
|
|
@@ -123,14 +55,21 @@ declare function NodeInjectable<T>(): (ctor: Ctor<T>) => Ctor<T>;
|
|
|
123
55
|
*/
|
|
124
56
|
declare function makeInjectable<T>(ctor: Ctor<T>): Ctor<T>;
|
|
125
57
|
/** @internal */
|
|
126
|
-
declare function isInjectable<T>(ctor: unknown): ctor is Ctor<T
|
|
127
|
-
[INJECTION_SYMBOL]: NodeToken<T>;
|
|
128
|
-
};
|
|
58
|
+
declare function isInjectable<T>(ctor: unknown): ctor is Ctor<T>;
|
|
129
59
|
/** @internal */
|
|
130
|
-
declare function getInjectableToken<T>(ctor: Ctor<T>
|
|
131
|
-
[INJECTION_SYMBOL]: NodeToken<T>;
|
|
132
|
-
}): NodeToken<T>;
|
|
60
|
+
declare function getInjectableToken<T>(ctor: Ctor<T>): NodeToken<T>;
|
|
133
61
|
declare function isConstructor(fn: unknown): fn is Ctor<any>;
|
|
62
|
+
/**
|
|
63
|
+
* Registers a class as injectable with a specific token.
|
|
64
|
+
* Use this function to manually associate a class with a token.
|
|
65
|
+
*
|
|
66
|
+
* Normally, the {@link NodeInjectable} and {@link makeInjectable} decorator is used to mark classes as injectable,
|
|
67
|
+
* but if developing a plugin that requires manual registration, this function can be used.
|
|
68
|
+
*
|
|
69
|
+
* @param ctor - The class constructor to register
|
|
70
|
+
* @param token - The token to associate with the class
|
|
71
|
+
*/
|
|
72
|
+
declare function registerClassAsInjectable<T>(ctor: Ctor<T>, token: NodeToken<T>): void;
|
|
134
73
|
|
|
135
74
|
/**
|
|
136
75
|
* Configuration options for the NodeContainer.
|
|
@@ -142,9 +81,57 @@ interface iContainerOptions {
|
|
|
142
81
|
* @default false
|
|
143
82
|
*/
|
|
144
83
|
measurePerformance?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* When true, enables diagnostics reporting after bootstrap.
|
|
86
|
+
* @default false
|
|
87
|
+
*/
|
|
145
88
|
diagnostics?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* @internal
|
|
91
|
+
* The parent container for hierarchical dependency resolution.
|
|
92
|
+
*/
|
|
146
93
|
parent?: iDIContainer;
|
|
94
|
+
/**
|
|
95
|
+
* @experimental
|
|
96
|
+
* Whether to instantiate dependencies immediately.
|
|
97
|
+
* If disabled, providers instantiation will happen when first requested.
|
|
98
|
+
* This helps improve startup performance for large containers.
|
|
99
|
+
* Enabled by default until stable.
|
|
100
|
+
*
|
|
101
|
+
* @default true
|
|
102
|
+
*/
|
|
103
|
+
instant?: boolean;
|
|
147
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Interface for dependency injection containers.
|
|
107
|
+
* Defines the core methods that all DI containers must implement.
|
|
108
|
+
*/
|
|
109
|
+
interface iDIContainer {
|
|
110
|
+
/**
|
|
111
|
+
* Registers a provider in the container.
|
|
112
|
+
* @template T - The type of value being provided
|
|
113
|
+
* @param provider - The provider configuration
|
|
114
|
+
*/
|
|
115
|
+
provide<T>(provider: Provider<T>): void;
|
|
116
|
+
/**
|
|
117
|
+
* @internal Finds the tree node associated with the given token.
|
|
118
|
+
* @template T - The type of value being searched
|
|
119
|
+
* @param token - The token or constructor to find
|
|
120
|
+
* @returns The associated tree node, or null if not found
|
|
121
|
+
*/
|
|
122
|
+
findNode<T>(token: Token<T>): TreeNode<T> | null;
|
|
123
|
+
/**
|
|
124
|
+
* Retrieves an instance for the given token.
|
|
125
|
+
* @template T - The type of value being retrieved
|
|
126
|
+
* @param token - The token or constructor to retrieve
|
|
127
|
+
* @returns The resolved instance
|
|
128
|
+
*/
|
|
129
|
+
get<T>(token: MultiNodeToken<T>): T[];
|
|
130
|
+
get<T>(token: NodeToken<T>): T;
|
|
131
|
+
get<T>(token: Ctor<T>): T;
|
|
132
|
+
produce<T>(fn: Ctor<T> | (() => T)): T;
|
|
133
|
+
}
|
|
134
|
+
|
|
148
135
|
declare class NodeContainer extends Illuma implements iDIContainer {
|
|
149
136
|
private readonly _opts?;
|
|
150
137
|
private _bootstrapped;
|
|
@@ -238,6 +225,63 @@ declare class NodeContainer extends Illuma implements iDIContainer {
|
|
|
238
225
|
produce<T>(fn: Ctor<T> | (() => T)): T;
|
|
239
226
|
}
|
|
240
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Internal context manager for tracking dependency injections during factory execution.
|
|
230
|
+
* This class manages the injection context lifecycle and tracks all injection calls.
|
|
231
|
+
*
|
|
232
|
+
* @internal
|
|
233
|
+
*/
|
|
234
|
+
declare abstract class InjectionContext {
|
|
235
|
+
static contextOpen: boolean;
|
|
236
|
+
static readonly _calls: Set<iInjectionNode<any>>;
|
|
237
|
+
static injector: InjectorFn | null;
|
|
238
|
+
private static readonly _scanners;
|
|
239
|
+
/**
|
|
240
|
+
* Adds a dependency to the current injection context.
|
|
241
|
+
* Called by `nodeInject` when a dependency is requested.
|
|
242
|
+
*
|
|
243
|
+
* @param node - The injection node representing the dependency
|
|
244
|
+
* @throws {InjectionError} If called outside of an active injection context
|
|
245
|
+
*/
|
|
246
|
+
static addDep(node: iInjectionNode<any>): void;
|
|
247
|
+
/**
|
|
248
|
+
* Opens a new injection context.
|
|
249
|
+
* Resets the calls set and sets the injector if provided.
|
|
250
|
+
*
|
|
251
|
+
* @param injector - Optional injector function to use for resolving dependencies
|
|
252
|
+
*/
|
|
253
|
+
/**
|
|
254
|
+
* Scans a factory function for dependencies.
|
|
255
|
+
* Executes the factory in a dry-run mode to capture `nodeInject` calls.
|
|
256
|
+
* Also runs registered context scanners.
|
|
257
|
+
*
|
|
258
|
+
* @param factory - The factory function to scan
|
|
259
|
+
* @returns A set of detected injection nodes
|
|
260
|
+
*/
|
|
261
|
+
static open(injector?: InjectorFn): void;
|
|
262
|
+
static scan(factory: any): Set<iInjectionNode<any>>;
|
|
263
|
+
static instantiate<T>(factory: () => T, injector: InjectorFn): T;
|
|
264
|
+
static closeAndReport(): Set<iInjectionNode<any>>;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
declare const ERR_CODES: {
|
|
268
|
+
readonly DUPLICATE_PROVIDER: 100;
|
|
269
|
+
readonly DUPLICATE_FACTORY: 101;
|
|
270
|
+
readonly INVALID_CTOR: 102;
|
|
271
|
+
readonly INVALID_PROVIDER: 103;
|
|
272
|
+
readonly INVALID_ALIAS: 200;
|
|
273
|
+
readonly LOOP_ALIAS: 201;
|
|
274
|
+
readonly NOT_BOOTSTRAPPED: 300;
|
|
275
|
+
readonly BOOTSTRAPPED: 301;
|
|
276
|
+
readonly DOUBLE_BOOTSTRAP: 302;
|
|
277
|
+
readonly NOT_FOUND: 400;
|
|
278
|
+
readonly CIRCULAR_DEPENDENCY: 401;
|
|
279
|
+
readonly UNTRACKED: 500;
|
|
280
|
+
readonly OUTSIDE_CONTEXT: 501;
|
|
281
|
+
readonly CALLED_UTILS_OUTSIDE_CONTEXT: 502;
|
|
282
|
+
readonly INSTANCE_ACCESS_FAILED: 503;
|
|
283
|
+
readonly ACCESS_FAILED: 504;
|
|
284
|
+
};
|
|
241
285
|
declare class InjectionError extends Error {
|
|
242
286
|
readonly code: number;
|
|
243
287
|
constructor(code: number, message: string);
|
|
@@ -259,6 +303,12 @@ declare class InjectionError extends Error {
|
|
|
259
303
|
static accessFailed(): InjectionError;
|
|
260
304
|
}
|
|
261
305
|
|
|
306
|
+
declare function injectDefer<N>(token: N, options: iNodeInjectorOptions & {
|
|
307
|
+
optional: true;
|
|
308
|
+
}): () => N extends MultiNodeToken<infer V> ? V[] : N extends NodeToken<infer U> ? U | null : N extends new (...args: any[]) => infer T ? T | null : never;
|
|
309
|
+
declare function injectDefer<N>(token: N, options?: iNodeInjectorOptions): () => N extends MultiNodeToken<infer V> ? V[] : N extends NodeToken<infer U> ? U : N extends new (...args: any) => infer T ? T : never;
|
|
310
|
+
declare function injectDefer<N extends NodeToken<unknown> | MultiNodeToken<unknown>>(token: N, options?: iNodeInjectorOptions): () => ExtractInjectedType<N>;
|
|
311
|
+
|
|
262
312
|
interface iInjector {
|
|
263
313
|
/** The DI container associated with this injector */
|
|
264
314
|
readonly container: iDIContainer;
|
|
@@ -300,6 +350,7 @@ declare class InjectorImpl implements iInjector {
|
|
|
300
350
|
* @example
|
|
301
351
|
* ```typescript
|
|
302
352
|
* import { Injector, nodeInject, NodeInjectable, NodeContainer } from "@illuma/core";
|
|
353
|
+
import { iDIContainer } from '../container/types';
|
|
303
354
|
*
|
|
304
355
|
* @NodeInjectable()
|
|
305
356
|
* class MyService {
|
|
@@ -375,4 +426,4 @@ declare function injectEntryAsync<T>(fn: MaybeAsyncFactory<iEntrypointConfig<Nod
|
|
|
375
426
|
declare function injectEntryAsync<T>(fn: MaybeAsyncFactory<iEntrypointConfig<Ctor<T>>>, opts?: iInjectionOptions): () => Promise<T>;
|
|
376
427
|
declare function injectEntryAsync<T>(fn: MaybeAsyncFactory<iEntrypointConfig<MultiNodeToken<T>>>, opts?: iInjectionOptions): () => Promise<T>;
|
|
377
428
|
|
|
378
|
-
export {
|
|
429
|
+
export { ExtractInjectedType, ERR_CODES as ILLUMA_ERR_CODES, INJECTION_SYMBOL, InjectionContext, InjectionError, Injector, InjectorFn, InjectorImpl, MultiNodeToken, NodeBase, NodeContainer, NodeInjectable, NodeToken, getInjectableToken, type iContainerOptions, type iDIContainer, type iEntrypointConfig, iInjectionNode, type iInjector, iNodeInjectorOptions, injectAsync, injectDefer, injectEntryAsync, injectGroupAsync, isConstructor, isInjectable, makeInjectable, registerClassAsInjectable };
|