@illuma/core 0.1.0 → 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.
- package/CHANGELOG.md +2 -0
- package/dist/index.cjs +101 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +120 -76
- package/dist/index.d.ts +120 -76
- package/dist/index.js +99 -20
- package/dist/index.js.map +1 -1
- package/dist/{injection-Y_bVmBSk.d.ts → injection-CJGqGWJ6.d.cts} +1 -1
- package/dist/{injection-CSxu56ds.d.cts → injection-D22uAh1O.d.ts} +1 -1
- package/dist/{plugin-container-CwkVlVS4.d.ts → plugin-container-CUw26ZhP.d.ts} +21 -18
- package/dist/{plugin-container-D8Zwpigq.d.cts → plugin-container-n0FIqLbh.d.cts} +21 -18
- package/dist/plugins.d.cts +3 -3
- package/dist/plugins.d.ts +3 -3
- package/dist/testkit.cjs +62 -20
- 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 +62 -20
- package/dist/testkit.js.map +1 -1
- package/dist/{providers-D9YA8L_g.d.cts → token-BvQrvm-Q.d.cts} +73 -73
- package/dist/{providers-D9YA8L_g.d.ts → token-BvQrvm-Q.d.ts} +73 -73
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,78 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { e as extractToken, g as iNodeAliasProvider, f as iNodeClassProvider, d as iNodeFactoryProvider, h as iNodeProvider, b as iNodeTokenBaseOptions, c as iNodeValueProvider, i as isNodeBase } from './
|
|
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, a as NodeBase, P as Provider, T as Token, M as MultiNodeToken } from './token-BvQrvm-Q.cjs';
|
|
2
|
+
export { e as extractToken, g as iNodeAliasProvider, f as iNodeClassProvider, d as iNodeFactoryProvider, h as iNodeProvider, b as iNodeTokenBaseOptions, c as iNodeValueProvider, i as isNodeBase } from './token-BvQrvm-Q.cjs';
|
|
3
|
+
import { i as iNodeInjectorOptions, E as ExtractInjectedType } from './injection-CJGqGWJ6.cjs';
|
|
4
|
+
export { N as NodeInjectFn, n as nodeInject } from './injection-CJGqGWJ6.cjs';
|
|
5
|
+
import { i as iInjectionNode, T as TreeNode, I as Illuma } from './plugin-container-n0FIqLbh.cjs';
|
|
76
6
|
|
|
77
7
|
/**
|
|
78
8
|
* Symbol used to mark classes as injectable and store their associated token.
|
|
@@ -132,6 +62,47 @@ declare function getInjectableToken<T>(ctor: Ctor<T> & {
|
|
|
132
62
|
}): NodeToken<T>;
|
|
133
63
|
declare function isConstructor(fn: unknown): fn is Ctor<any>;
|
|
134
64
|
|
|
65
|
+
/** @internal */
|
|
66
|
+
type InjectorFn = (token: NodeBase<any>, optional?: boolean) => any;
|
|
67
|
+
/**
|
|
68
|
+
* Internal context manager for tracking dependency injections during factory execution.
|
|
69
|
+
* This class manages the injection context lifecycle and tracks all injection calls.
|
|
70
|
+
*
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
declare abstract class InjectionContext {
|
|
74
|
+
static contextOpen: boolean;
|
|
75
|
+
static readonly _calls: Set<iInjectionNode<any>>;
|
|
76
|
+
static injector: InjectorFn | null;
|
|
77
|
+
private static readonly _scanners;
|
|
78
|
+
/**
|
|
79
|
+
* Adds a dependency to the current injection context.
|
|
80
|
+
* Called by `nodeInject` when a dependency is requested.
|
|
81
|
+
*
|
|
82
|
+
* @param node - The injection node representing the dependency
|
|
83
|
+
* @throws {InjectionError} If called outside of an active injection context
|
|
84
|
+
*/
|
|
85
|
+
static addDep(node: iInjectionNode<any>): void;
|
|
86
|
+
/**
|
|
87
|
+
* Opens a new injection context.
|
|
88
|
+
* Resets the calls set and sets the injector if provided.
|
|
89
|
+
*
|
|
90
|
+
* @param injector - Optional injector function to use for resolving dependencies
|
|
91
|
+
*/
|
|
92
|
+
/**
|
|
93
|
+
* Scans a factory function for dependencies.
|
|
94
|
+
* Executes the factory in a dry-run mode to capture `nodeInject` calls.
|
|
95
|
+
* Also runs registered context scanners.
|
|
96
|
+
*
|
|
97
|
+
* @param factory - The factory function to scan
|
|
98
|
+
* @returns A set of detected injection nodes
|
|
99
|
+
*/
|
|
100
|
+
static open(injector?: InjectorFn): void;
|
|
101
|
+
static scan(factory: any): Set<iInjectionNode<any>>;
|
|
102
|
+
static instantiate<T>(factory: () => T, injector: InjectorFn): T;
|
|
103
|
+
static closeAndReport(): Set<iInjectionNode<any>>;
|
|
104
|
+
}
|
|
105
|
+
|
|
135
106
|
/**
|
|
136
107
|
* Configuration options for the NodeContainer.
|
|
137
108
|
*/
|
|
@@ -142,9 +113,57 @@ interface iContainerOptions {
|
|
|
142
113
|
* @default false
|
|
143
114
|
*/
|
|
144
115
|
measurePerformance?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* When true, enables diagnostics reporting after bootstrap.
|
|
118
|
+
* @default false
|
|
119
|
+
*/
|
|
145
120
|
diagnostics?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* @internal
|
|
123
|
+
* The parent container for hierarchical dependency resolution.
|
|
124
|
+
*/
|
|
146
125
|
parent?: iDIContainer;
|
|
126
|
+
/**
|
|
127
|
+
* @experimental
|
|
128
|
+
* Whether to instantiate dependencies immediately.
|
|
129
|
+
* If disabled, providers instantiation will happen when first requested.
|
|
130
|
+
* This helps improve startup performance for large containers.
|
|
131
|
+
* Enabled by default until stable.
|
|
132
|
+
*
|
|
133
|
+
* @default true
|
|
134
|
+
*/
|
|
135
|
+
instant?: boolean;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Interface for dependency injection containers.
|
|
139
|
+
* Defines the core methods that all DI containers must implement.
|
|
140
|
+
*/
|
|
141
|
+
interface iDIContainer {
|
|
142
|
+
/**
|
|
143
|
+
* Registers a provider in the container.
|
|
144
|
+
* @template T - The type of value being provided
|
|
145
|
+
* @param provider - The provider configuration
|
|
146
|
+
*/
|
|
147
|
+
provide<T>(provider: Provider<T>): void;
|
|
148
|
+
/**
|
|
149
|
+
* @internal Finds the tree node associated with the given token.
|
|
150
|
+
* @template T - The type of value being searched
|
|
151
|
+
* @param token - The token or constructor to find
|
|
152
|
+
* @returns The associated tree node, or null if not found
|
|
153
|
+
*/
|
|
154
|
+
findNode<T>(token: Token<T>): TreeNode<T> | null;
|
|
155
|
+
/**
|
|
156
|
+
* Retrieves an instance for the given token.
|
|
157
|
+
* @template T - The type of value being retrieved
|
|
158
|
+
* @param token - The token or constructor to retrieve
|
|
159
|
+
* @returns The resolved instance
|
|
160
|
+
*/
|
|
161
|
+
get<T>(token: MultiNodeToken<T>): T[];
|
|
162
|
+
get<T>(token: NodeToken<T>): T;
|
|
163
|
+
get<T>(token: Ctor<T>): T;
|
|
164
|
+
produce<T>(fn: Ctor<T> | (() => T)): T;
|
|
147
165
|
}
|
|
166
|
+
|
|
148
167
|
declare class NodeContainer extends Illuma implements iDIContainer {
|
|
149
168
|
private readonly _opts?;
|
|
150
169
|
private _bootstrapped;
|
|
@@ -238,6 +257,24 @@ declare class NodeContainer extends Illuma implements iDIContainer {
|
|
|
238
257
|
produce<T>(fn: Ctor<T> | (() => T)): T;
|
|
239
258
|
}
|
|
240
259
|
|
|
260
|
+
declare const ERR_CODES: {
|
|
261
|
+
readonly DUPLICATE_PROVIDER: 100;
|
|
262
|
+
readonly DUPLICATE_FACTORY: 101;
|
|
263
|
+
readonly INVALID_CTOR: 102;
|
|
264
|
+
readonly INVALID_PROVIDER: 103;
|
|
265
|
+
readonly INVALID_ALIAS: 200;
|
|
266
|
+
readonly LOOP_ALIAS: 201;
|
|
267
|
+
readonly NOT_BOOTSTRAPPED: 300;
|
|
268
|
+
readonly BOOTSTRAPPED: 301;
|
|
269
|
+
readonly DOUBLE_BOOTSTRAP: 302;
|
|
270
|
+
readonly NOT_FOUND: 400;
|
|
271
|
+
readonly CIRCULAR_DEPENDENCY: 401;
|
|
272
|
+
readonly UNTRACKED: 500;
|
|
273
|
+
readonly OUTSIDE_CONTEXT: 501;
|
|
274
|
+
readonly CALLED_UTILS_OUTSIDE_CONTEXT: 502;
|
|
275
|
+
readonly INSTANCE_ACCESS_FAILED: 503;
|
|
276
|
+
readonly ACCESS_FAILED: 504;
|
|
277
|
+
};
|
|
241
278
|
declare class InjectionError extends Error {
|
|
242
279
|
readonly code: number;
|
|
243
280
|
constructor(code: number, message: string);
|
|
@@ -259,6 +296,12 @@ declare class InjectionError extends Error {
|
|
|
259
296
|
static accessFailed(): InjectionError;
|
|
260
297
|
}
|
|
261
298
|
|
|
299
|
+
declare function injectDefer<N>(token: N, options: iNodeInjectorOptions & {
|
|
300
|
+
optional: true;
|
|
301
|
+
}): () => N extends MultiNodeToken<infer V> ? V[] : N extends NodeToken<infer U> ? U | null : N extends new (...args: any[]) => infer T ? T | null : never;
|
|
302
|
+
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;
|
|
303
|
+
declare function injectDefer<N extends NodeToken<unknown> | MultiNodeToken<unknown>>(token: N, options?: iNodeInjectorOptions): () => ExtractInjectedType<N>;
|
|
304
|
+
|
|
262
305
|
interface iInjector {
|
|
263
306
|
/** The DI container associated with this injector */
|
|
264
307
|
readonly container: iDIContainer;
|
|
@@ -300,6 +343,7 @@ declare class InjectorImpl implements iInjector {
|
|
|
300
343
|
* @example
|
|
301
344
|
* ```typescript
|
|
302
345
|
* import { Injector, nodeInject, NodeInjectable, NodeContainer } from "@illuma/core";
|
|
346
|
+
import { iDIContainer } from '../container/types';
|
|
303
347
|
*
|
|
304
348
|
* @NodeInjectable()
|
|
305
349
|
* class MyService {
|
|
@@ -375,4 +419,4 @@ declare function injectEntryAsync<T>(fn: MaybeAsyncFactory<iEntrypointConfig<Nod
|
|
|
375
419
|
declare function injectEntryAsync<T>(fn: MaybeAsyncFactory<iEntrypointConfig<Ctor<T>>>, opts?: iInjectionOptions): () => Promise<T>;
|
|
376
420
|
declare function injectEntryAsync<T>(fn: MaybeAsyncFactory<iEntrypointConfig<MultiNodeToken<T>>>, opts?: iInjectionOptions): () => Promise<T>;
|
|
377
421
|
|
|
378
|
-
export { Ctor, INJECTION_SYMBOL, InjectionContext, InjectionError, Injector, type InjectorFn, InjectorImpl, MultiNodeToken, NodeBase, NodeContainer, NodeInjectable, NodeToken, Provider, Token, getInjectableToken, type
|
|
422
|
+
export { Ctor, ExtractInjectedType, ERR_CODES as ILLUMA_ERR_CODES, INJECTION_SYMBOL, InjectionContext, InjectionError, Injector, type InjectorFn, InjectorImpl, MultiNodeToken, NodeBase, NodeContainer, NodeInjectable, NodeToken, Provider, Token, getInjectableToken, type iEntrypointConfig, iInjectionNode, type iInjector, iNodeInjectorOptions, injectAsync, injectDefer, injectEntryAsync, injectGroupAsync, isConstructor, isInjectable, makeInjectable };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,78 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { e as extractToken, g as iNodeAliasProvider, f as iNodeClassProvider, d as iNodeFactoryProvider, h as iNodeProvider, b as iNodeTokenBaseOptions, c as iNodeValueProvider, i as isNodeBase } from './
|
|
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, a as NodeBase, P as Provider, T as Token, M as MultiNodeToken } from './token-BvQrvm-Q.js';
|
|
2
|
+
export { e as extractToken, g as iNodeAliasProvider, f as iNodeClassProvider, d as iNodeFactoryProvider, h as iNodeProvider, b as iNodeTokenBaseOptions, c as iNodeValueProvider, i as isNodeBase } from './token-BvQrvm-Q.js';
|
|
3
|
+
import { i as iNodeInjectorOptions, E as ExtractInjectedType } from './injection-D22uAh1O.js';
|
|
4
|
+
export { N as NodeInjectFn, n as nodeInject } from './injection-D22uAh1O.js';
|
|
5
|
+
import { i as iInjectionNode, T as TreeNode, I as Illuma } from './plugin-container-CUw26ZhP.js';
|
|
76
6
|
|
|
77
7
|
/**
|
|
78
8
|
* Symbol used to mark classes as injectable and store their associated token.
|
|
@@ -132,6 +62,47 @@ declare function getInjectableToken<T>(ctor: Ctor<T> & {
|
|
|
132
62
|
}): NodeToken<T>;
|
|
133
63
|
declare function isConstructor(fn: unknown): fn is Ctor<any>;
|
|
134
64
|
|
|
65
|
+
/** @internal */
|
|
66
|
+
type InjectorFn = (token: NodeBase<any>, optional?: boolean) => any;
|
|
67
|
+
/**
|
|
68
|
+
* Internal context manager for tracking dependency injections during factory execution.
|
|
69
|
+
* This class manages the injection context lifecycle and tracks all injection calls.
|
|
70
|
+
*
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
declare abstract class InjectionContext {
|
|
74
|
+
static contextOpen: boolean;
|
|
75
|
+
static readonly _calls: Set<iInjectionNode<any>>;
|
|
76
|
+
static injector: InjectorFn | null;
|
|
77
|
+
private static readonly _scanners;
|
|
78
|
+
/**
|
|
79
|
+
* Adds a dependency to the current injection context.
|
|
80
|
+
* Called by `nodeInject` when a dependency is requested.
|
|
81
|
+
*
|
|
82
|
+
* @param node - The injection node representing the dependency
|
|
83
|
+
* @throws {InjectionError} If called outside of an active injection context
|
|
84
|
+
*/
|
|
85
|
+
static addDep(node: iInjectionNode<any>): void;
|
|
86
|
+
/**
|
|
87
|
+
* Opens a new injection context.
|
|
88
|
+
* Resets the calls set and sets the injector if provided.
|
|
89
|
+
*
|
|
90
|
+
* @param injector - Optional injector function to use for resolving dependencies
|
|
91
|
+
*/
|
|
92
|
+
/**
|
|
93
|
+
* Scans a factory function for dependencies.
|
|
94
|
+
* Executes the factory in a dry-run mode to capture `nodeInject` calls.
|
|
95
|
+
* Also runs registered context scanners.
|
|
96
|
+
*
|
|
97
|
+
* @param factory - The factory function to scan
|
|
98
|
+
* @returns A set of detected injection nodes
|
|
99
|
+
*/
|
|
100
|
+
static open(injector?: InjectorFn): void;
|
|
101
|
+
static scan(factory: any): Set<iInjectionNode<any>>;
|
|
102
|
+
static instantiate<T>(factory: () => T, injector: InjectorFn): T;
|
|
103
|
+
static closeAndReport(): Set<iInjectionNode<any>>;
|
|
104
|
+
}
|
|
105
|
+
|
|
135
106
|
/**
|
|
136
107
|
* Configuration options for the NodeContainer.
|
|
137
108
|
*/
|
|
@@ -142,9 +113,57 @@ interface iContainerOptions {
|
|
|
142
113
|
* @default false
|
|
143
114
|
*/
|
|
144
115
|
measurePerformance?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* When true, enables diagnostics reporting after bootstrap.
|
|
118
|
+
* @default false
|
|
119
|
+
*/
|
|
145
120
|
diagnostics?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* @internal
|
|
123
|
+
* The parent container for hierarchical dependency resolution.
|
|
124
|
+
*/
|
|
146
125
|
parent?: iDIContainer;
|
|
126
|
+
/**
|
|
127
|
+
* @experimental
|
|
128
|
+
* Whether to instantiate dependencies immediately.
|
|
129
|
+
* If disabled, providers instantiation will happen when first requested.
|
|
130
|
+
* This helps improve startup performance for large containers.
|
|
131
|
+
* Enabled by default until stable.
|
|
132
|
+
*
|
|
133
|
+
* @default true
|
|
134
|
+
*/
|
|
135
|
+
instant?: boolean;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Interface for dependency injection containers.
|
|
139
|
+
* Defines the core methods that all DI containers must implement.
|
|
140
|
+
*/
|
|
141
|
+
interface iDIContainer {
|
|
142
|
+
/**
|
|
143
|
+
* Registers a provider in the container.
|
|
144
|
+
* @template T - The type of value being provided
|
|
145
|
+
* @param provider - The provider configuration
|
|
146
|
+
*/
|
|
147
|
+
provide<T>(provider: Provider<T>): void;
|
|
148
|
+
/**
|
|
149
|
+
* @internal Finds the tree node associated with the given token.
|
|
150
|
+
* @template T - The type of value being searched
|
|
151
|
+
* @param token - The token or constructor to find
|
|
152
|
+
* @returns The associated tree node, or null if not found
|
|
153
|
+
*/
|
|
154
|
+
findNode<T>(token: Token<T>): TreeNode<T> | null;
|
|
155
|
+
/**
|
|
156
|
+
* Retrieves an instance for the given token.
|
|
157
|
+
* @template T - The type of value being retrieved
|
|
158
|
+
* @param token - The token or constructor to retrieve
|
|
159
|
+
* @returns The resolved instance
|
|
160
|
+
*/
|
|
161
|
+
get<T>(token: MultiNodeToken<T>): T[];
|
|
162
|
+
get<T>(token: NodeToken<T>): T;
|
|
163
|
+
get<T>(token: Ctor<T>): T;
|
|
164
|
+
produce<T>(fn: Ctor<T> | (() => T)): T;
|
|
147
165
|
}
|
|
166
|
+
|
|
148
167
|
declare class NodeContainer extends Illuma implements iDIContainer {
|
|
149
168
|
private readonly _opts?;
|
|
150
169
|
private _bootstrapped;
|
|
@@ -238,6 +257,24 @@ declare class NodeContainer extends Illuma implements iDIContainer {
|
|
|
238
257
|
produce<T>(fn: Ctor<T> | (() => T)): T;
|
|
239
258
|
}
|
|
240
259
|
|
|
260
|
+
declare const ERR_CODES: {
|
|
261
|
+
readonly DUPLICATE_PROVIDER: 100;
|
|
262
|
+
readonly DUPLICATE_FACTORY: 101;
|
|
263
|
+
readonly INVALID_CTOR: 102;
|
|
264
|
+
readonly INVALID_PROVIDER: 103;
|
|
265
|
+
readonly INVALID_ALIAS: 200;
|
|
266
|
+
readonly LOOP_ALIAS: 201;
|
|
267
|
+
readonly NOT_BOOTSTRAPPED: 300;
|
|
268
|
+
readonly BOOTSTRAPPED: 301;
|
|
269
|
+
readonly DOUBLE_BOOTSTRAP: 302;
|
|
270
|
+
readonly NOT_FOUND: 400;
|
|
271
|
+
readonly CIRCULAR_DEPENDENCY: 401;
|
|
272
|
+
readonly UNTRACKED: 500;
|
|
273
|
+
readonly OUTSIDE_CONTEXT: 501;
|
|
274
|
+
readonly CALLED_UTILS_OUTSIDE_CONTEXT: 502;
|
|
275
|
+
readonly INSTANCE_ACCESS_FAILED: 503;
|
|
276
|
+
readonly ACCESS_FAILED: 504;
|
|
277
|
+
};
|
|
241
278
|
declare class InjectionError extends Error {
|
|
242
279
|
readonly code: number;
|
|
243
280
|
constructor(code: number, message: string);
|
|
@@ -259,6 +296,12 @@ declare class InjectionError extends Error {
|
|
|
259
296
|
static accessFailed(): InjectionError;
|
|
260
297
|
}
|
|
261
298
|
|
|
299
|
+
declare function injectDefer<N>(token: N, options: iNodeInjectorOptions & {
|
|
300
|
+
optional: true;
|
|
301
|
+
}): () => N extends MultiNodeToken<infer V> ? V[] : N extends NodeToken<infer U> ? U | null : N extends new (...args: any[]) => infer T ? T | null : never;
|
|
302
|
+
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;
|
|
303
|
+
declare function injectDefer<N extends NodeToken<unknown> | MultiNodeToken<unknown>>(token: N, options?: iNodeInjectorOptions): () => ExtractInjectedType<N>;
|
|
304
|
+
|
|
262
305
|
interface iInjector {
|
|
263
306
|
/** The DI container associated with this injector */
|
|
264
307
|
readonly container: iDIContainer;
|
|
@@ -300,6 +343,7 @@ declare class InjectorImpl implements iInjector {
|
|
|
300
343
|
* @example
|
|
301
344
|
* ```typescript
|
|
302
345
|
* import { Injector, nodeInject, NodeInjectable, NodeContainer } from "@illuma/core";
|
|
346
|
+
import { iDIContainer } from '../container/types';
|
|
303
347
|
*
|
|
304
348
|
* @NodeInjectable()
|
|
305
349
|
* class MyService {
|
|
@@ -375,4 +419,4 @@ declare function injectEntryAsync<T>(fn: MaybeAsyncFactory<iEntrypointConfig<Nod
|
|
|
375
419
|
declare function injectEntryAsync<T>(fn: MaybeAsyncFactory<iEntrypointConfig<Ctor<T>>>, opts?: iInjectionOptions): () => Promise<T>;
|
|
376
420
|
declare function injectEntryAsync<T>(fn: MaybeAsyncFactory<iEntrypointConfig<MultiNodeToken<T>>>, opts?: iInjectionOptions): () => Promise<T>;
|
|
377
421
|
|
|
378
|
-
export { Ctor, INJECTION_SYMBOL, InjectionContext, InjectionError, Injector, type InjectorFn, InjectorImpl, MultiNodeToken, NodeBase, NodeContainer, NodeInjectable, NodeToken, Provider, Token, getInjectableToken, type
|
|
422
|
+
export { Ctor, ExtractInjectedType, ERR_CODES as ILLUMA_ERR_CODES, INJECTION_SYMBOL, InjectionContext, InjectionError, Injector, type InjectorFn, InjectorImpl, MultiNodeToken, NodeBase, NodeContainer, NodeInjectable, NodeToken, Provider, Token, getInjectableToken, type iEntrypointConfig, iInjectionNode, type iInjector, iNodeInjectorOptions, injectAsync, injectDefer, injectEntryAsync, injectGroupAsync, isConstructor, isInjectable, makeInjectable };
|