@codefast/di 0.3.14-canary.0 → 0.3.14-canary.2
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 +28 -0
- package/README.md +54 -29
- package/dist/binding-scope.d.mts +11 -0
- package/dist/binding-scope.mjs +19 -0
- package/dist/binding-select.d.mts +8 -26
- package/dist/binding-select.mjs +56 -49
- package/dist/binding.d.mts +107 -327
- package/dist/binding.mjs +19 -324
- package/dist/constraints.d.mts +11 -29
- package/dist/constraints.mjs +32 -36
- package/dist/constructor-type.d.mts +17 -0
- package/dist/constructor-type.mjs +1 -0
- package/dist/container.d.mts +44 -128
- package/dist/container.mjs +664 -433
- package/dist/decorators/inject.d.mts +19 -50
- package/dist/decorators/inject.mjs +131 -93
- package/dist/decorators/injectable.d.mts +16 -37
- package/dist/decorators/injectable.mjs +47 -66
- package/dist/decorators/lifecycle-decorators.d.mts +2 -22
- package/dist/decorators/lifecycle-decorators.mjs +81 -37
- package/dist/dependency-graph.d.mts +24 -54
- package/dist/dependency-graph.mjs +51 -153
- package/dist/environment.d.mts +38 -12
- package/dist/environment.mjs +82 -16
- package/dist/errors.d.mts +69 -188
- package/dist/errors.mjs +92 -219
- package/dist/graph-adapters/cytoscape.d.mts +24 -0
- package/dist/graph-adapters/cytoscape.mjs +23 -0
- package/dist/graph-adapters/dot.d.mts +6 -0
- package/dist/graph-adapters/dot.mjs +17 -0
- package/dist/graph-adapters/reactflow.d.mts +29 -0
- package/dist/graph-adapters/reactflow.mjs +29 -0
- package/dist/graph-adapters/types.d.mts +2 -0
- package/dist/graph-adapters/types.mjs +1 -0
- package/dist/index.d.mts +16 -9
- package/dist/index.mjs +8 -5
- package/dist/inspector.d.mts +34 -95
- package/dist/inspector.mjs +57 -256
- package/dist/lifecycle.d.mts +20 -53
- package/dist/lifecycle.mjs +129 -99
- package/dist/metadata/metadata-keys.d.mts +9 -26
- package/dist/metadata/metadata-keys.mjs +7 -28
- package/dist/metadata/metadata-reader-token.d.mts +7 -0
- package/dist/metadata/metadata-reader-token.mjs +5 -0
- package/dist/metadata/metadata-types.d.mts +22 -71
- package/dist/metadata/symbol-metadata-reader.d.mts +10 -26
- package/dist/metadata/symbol-metadata-reader.mjs +32 -45
- package/dist/module.d.mts +30 -84
- package/dist/module.mjs +26 -72
- package/dist/registry.d.mts +32 -63
- package/dist/registry.mjs +131 -82
- package/dist/resolve-options.d.mts +18 -0
- package/dist/resolve-options.mjs +22 -0
- package/dist/resolver.d.mts +67 -190
- package/dist/resolver.mjs +715 -424
- package/dist/scope.d.mts +19 -102
- package/dist/scope.mjs +37 -192
- package/dist/token.d.mts +8 -22
- package/dist/token.mjs +9 -11
- package/dist/types.d.mts +48 -0
- package/dist/types.mjs +1 -0
- package/package.json +52 -14
- package/dist/metadata/param-registry.d.mts +0 -16
- package/dist/metadata/param-registry.mjs +0 -31
- package/dist/scope-validation.d.mts +0 -21
- package/dist/scope-validation.mjs +0 -35
package/dist/binding.d.mts
CHANGED
|
@@ -1,344 +1,124 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Constructor } from "./constructor-type.mjs";
|
|
2
|
+
import { Token } from "./token.mjs";
|
|
3
|
+
import { ActivationHandler, BindingIdentifier, BindingScope, ConstraintContext, DeactivationHandler, DependencyKey, ResolutionContext, TokenValue } from "./types.mjs";
|
|
4
|
+
import { InjectionDescriptor } from "./decorators/inject.mjs";
|
|
3
5
|
|
|
4
6
|
//#region src/binding.d.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* Allocates a new opaque binding identifier (used when `.id(...)` is not supplied).
|
|
14
|
-
*/
|
|
15
|
-
declare function createBindingIdentifier(): BindingIdentifier;
|
|
16
|
-
/**
|
|
17
|
-
* Runtime constructor token used as a registry key (no reflection metadata).
|
|
18
|
-
*/
|
|
19
|
-
type Constructor<Value> = abstract new (...args: never[]) => Value;
|
|
20
|
-
/**
|
|
21
|
-
* Lifetime strategy for a resolved instance.
|
|
22
|
-
*/
|
|
23
|
-
type BindingScope = "singleton" | "transient" | "scoped";
|
|
24
|
-
/**
|
|
25
|
-
* Hint for disambiguating multi-bindings registered against the same token or constructor.
|
|
26
|
-
*/
|
|
27
|
-
type ResolveHint = {
|
|
28
|
-
readonly name?: string;
|
|
29
|
-
readonly tag?: readonly [tag: string, value: unknown];
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Public alias for {@link ResolveHint} — the `hint` parameter accepted by
|
|
33
|
-
* `Container.resolve`, `Container.resolveAsync`, and related methods.
|
|
34
|
-
* Passes `name` and/or `tag` to select among multi-bindings.
|
|
35
|
-
*/
|
|
36
|
-
type ResolveOptions = ResolveHint;
|
|
37
|
-
/**
|
|
38
|
-
* Snapshot of a binding on the materialization stack (for {@link ConstraintContext}).
|
|
39
|
-
*/
|
|
40
|
-
type ConstraintBindingKind = "constant" | "class" | "dynamic" | "async-dynamic" | "resolved" | "alias";
|
|
41
|
-
/**
|
|
42
|
-
* Snapshot of a single binding on the materialization stack during resolution.
|
|
43
|
-
* Each frame captures enough identity to implement contextual constraints
|
|
44
|
-
* ({@link whenParentIs}, {@link whenAnyAncestorIs}) and captive-dependency detection.
|
|
45
|
-
*/
|
|
46
|
-
type ConstraintParentFrame = {
|
|
47
|
-
readonly registryKey: RegistryKey;
|
|
48
|
-
readonly bindingId: BindingIdentifier;
|
|
49
|
-
readonly bindingKind: ConstraintBindingKind;
|
|
50
|
-
readonly tags: ReadonlyMap<string, unknown>;
|
|
51
|
-
readonly scope: BindingScope;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* @alias {@link ConstraintParentFrame} — frame on the materialization stack during resolution.
|
|
55
|
-
*/
|
|
56
|
-
type MaterializationFrame = ConstraintParentFrame;
|
|
57
|
-
/**
|
|
58
|
-
* Context for {@link BindingBuilder.when} predicates: path, ancestor metadata, and the current resolve hint.
|
|
59
|
-
*/
|
|
60
|
-
type ConstraintContext = {
|
|
61
|
-
readonly resolutionPath: readonly string[];
|
|
62
|
-
readonly materializationStack: readonly ConstraintParentFrame[];
|
|
63
|
-
readonly parent: ConstraintParentFrame | undefined;
|
|
64
|
-
readonly ancestors: readonly ConstraintParentFrame[];
|
|
65
|
-
readonly currentResolveHint: ResolveHint | undefined;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Context passed to factories and lifecycle hooks so nested dependencies resolve with the same path rules.
|
|
69
|
-
*
|
|
70
|
-
* `graph` exposes the current position in the dependency graph (resolution path, materialization
|
|
71
|
-
* stack, parent/ancestor frames) — used by {@link BindingBuilder.when} predicates to implement
|
|
72
|
-
* context-sensitive bindings such as `whenParentIs` or `whenAnyAncestorIs`.
|
|
73
|
-
*/
|
|
74
|
-
type ResolutionContext = {
|
|
75
|
-
readonly resolve: <Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions) => Value;
|
|
76
|
-
readonly resolveAsync: <Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions) => Promise<Value>;
|
|
77
|
-
readonly resolveOptional: <Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions) => Value | undefined; /** Resolves every binding registered for `token` (multi-binding). */
|
|
78
|
-
readonly resolveAll: <Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions) => Value[]; /** Async variant of {@link ResolutionContext.resolveAll}. */
|
|
79
|
-
readonly resolveAllAsync: <Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions) => Promise<Value[]>;
|
|
80
|
-
/**
|
|
81
|
-
* Dependency-graph navigation context — path, materialization stack, parent/ancestor frames.
|
|
82
|
-
*/
|
|
83
|
-
readonly graph: ConstraintContext;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Lifecycle and constraint fields shared by every concrete {@link Binding} variant.
|
|
87
|
-
* Separated from {@link BindingBase} so the builder can accumulate them independently of `id` / `scope`.
|
|
88
|
-
*/
|
|
89
|
-
type BindingLifecycle = {
|
|
90
|
-
readonly bindingName?: string;
|
|
91
|
-
readonly tags: ReadonlyMap<string, unknown>;
|
|
92
|
-
readonly onActivation?: ActivationHandler<unknown>;
|
|
93
|
-
readonly onDeactivation?: DeactivationHandler<unknown>;
|
|
94
|
-
readonly constraint?: (ctx: ConstraintContext) => boolean;
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* Called after an instance is constructed (and after `@postConstruct`).
|
|
98
|
-
* The return value replaces the instance in the scope cache — use this to wrap with a proxy or
|
|
99
|
-
* apply post-processing. May be async; async handlers require `resolveAsync`.
|
|
100
|
-
*/
|
|
101
|
-
type ActivationHandler<Value> = (ctx: ResolutionContext, instance: Value) => Value | Promise<Value>;
|
|
102
|
-
/**
|
|
103
|
-
* Called before a singleton/scoped instance is evicted from the scope cache.
|
|
104
|
-
* Runs after `@preDestroy`. May be async; async deactivation requires `disposeAsync` / `unloadAsync`.
|
|
105
|
-
*/
|
|
106
|
-
type DeactivationHandler<Value> = (instance: Value) => void | Promise<void>;
|
|
107
|
-
type BindingBase = BindingLifecycle & {
|
|
7
|
+
interface SlotKey {
|
|
8
|
+
readonly name: string | undefined;
|
|
9
|
+
readonly tags: ReadonlyArray<readonly [tag: string, value: unknown]>;
|
|
10
|
+
}
|
|
11
|
+
declare function slotKeyEquals(a: SlotKey, b: SlotKey): boolean;
|
|
12
|
+
declare const DEFAULT_SLOT: SlotKey;
|
|
13
|
+
declare function slotKeyToString(slot: SlotKey): string;
|
|
14
|
+
interface BindingBase<Value> {
|
|
108
15
|
readonly id: BindingIdentifier;
|
|
109
|
-
readonly
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* Binding backed by a pre-existing constant value; always singleton, no construction cost.
|
|
117
|
-
*/
|
|
118
|
-
type ConstantBinding<Value> = BindingBase & {
|
|
119
|
-
readonly kind: "constant";
|
|
120
|
-
readonly value: Value;
|
|
121
|
-
};
|
|
122
|
-
/**
|
|
123
|
-
* Binding that constructs `implementationClass` via the container's metadata-driven instantiation.
|
|
124
|
-
*/
|
|
125
|
-
type ClassBinding<Value> = BindingBase & {
|
|
16
|
+
readonly token: Token<Value> | Constructor<Value>;
|
|
17
|
+
readonly slot: SlotKey;
|
|
18
|
+
readonly predicate?: (ctx: ConstraintContext) => boolean;
|
|
19
|
+
}
|
|
20
|
+
interface ClassBinding<Value> extends BindingBase<Value> {
|
|
126
21
|
readonly kind: "class";
|
|
127
|
-
readonly
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
22
|
+
readonly target: Constructor<Value>;
|
|
23
|
+
readonly scope: BindingScope;
|
|
24
|
+
readonly onActivation?: ActivationHandler<Value>;
|
|
25
|
+
readonly onDeactivation?: DeactivationHandler<Value>;
|
|
26
|
+
}
|
|
27
|
+
interface DynamicBinding<Value> extends BindingBase<Value> {
|
|
133
28
|
readonly kind: "dynamic";
|
|
134
29
|
readonly factory: (ctx: ResolutionContext) => Value;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
readonly kind: "async
|
|
30
|
+
readonly scope: BindingScope;
|
|
31
|
+
readonly onActivation?: ActivationHandler<Value>;
|
|
32
|
+
readonly onDeactivation?: DeactivationHandler<Value>;
|
|
33
|
+
}
|
|
34
|
+
interface DynamicAsyncBinding<Value> extends BindingBase<Value> {
|
|
35
|
+
readonly kind: "dynamic-async";
|
|
141
36
|
readonly factory: (ctx: ResolutionContext) => Promise<Value>;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
37
|
+
readonly scope: BindingScope;
|
|
38
|
+
readonly onActivation?: ActivationHandler<Value>;
|
|
39
|
+
readonly onDeactivation?: DeactivationHandler<Value>;
|
|
40
|
+
}
|
|
41
|
+
interface ResolvedBinding<Value> extends BindingBase<Value> {
|
|
147
42
|
readonly kind: "resolved";
|
|
148
|
-
readonly dependencyTokens: readonly (Token<unknown> | Constructor<unknown>)[];
|
|
149
43
|
readonly factory: (...args: unknown[]) => Value;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
44
|
+
readonly deps: readonly InjectionDescriptor[];
|
|
45
|
+
readonly scope: BindingScope;
|
|
46
|
+
readonly onActivation?: ActivationHandler<Value>;
|
|
47
|
+
readonly onDeactivation?: DeactivationHandler<Value>;
|
|
48
|
+
}
|
|
49
|
+
interface ResolvedAsyncBinding<Value> extends BindingBase<Value> {
|
|
50
|
+
readonly kind: "resolved-async";
|
|
51
|
+
readonly factory: (...args: unknown[]) => Promise<Value>;
|
|
52
|
+
readonly deps: readonly InjectionDescriptor[];
|
|
53
|
+
readonly scope: BindingScope;
|
|
54
|
+
readonly onActivation?: ActivationHandler<Value>;
|
|
55
|
+
readonly onDeactivation?: DeactivationHandler<Value>;
|
|
56
|
+
}
|
|
57
|
+
interface ConstantBinding<Value> extends BindingBase<Value> {
|
|
58
|
+
readonly kind: "constant";
|
|
59
|
+
readonly value: Value;
|
|
60
|
+
readonly scope: "singleton";
|
|
61
|
+
readonly onActivation?: ActivationHandler<Value>;
|
|
62
|
+
readonly onDeactivation?: DeactivationHandler<Value>;
|
|
63
|
+
}
|
|
64
|
+
interface AliasBinding<Value> extends BindingBase<Value> {
|
|
155
65
|
readonly kind: "alias";
|
|
156
|
-
readonly
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
readonly
|
|
169
|
-
readonly
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
* 2. **Refinement chain** — optional calls to `singleton()`, `transient()`, `scoped()`,
|
|
178
|
-
* `onActivation()`, `onDeactivation()`, `whenNamed()`, `whenTagged()`, `when()`, and `id()`.
|
|
179
|
-
*
|
|
180
|
-
* Calling a second `to*()` method throws {@link InternalError}.
|
|
181
|
-
*
|
|
182
|
-
* The builder is created by {@link Container.bind} or by `bind` on {@link ModuleBuilder}.
|
|
183
|
-
* The container injects {@link RegistryCallbacks} so that every strategy selection and
|
|
184
|
-
* refinement is immediately reflected in the live registry.
|
|
185
|
-
*/
|
|
186
|
-
declare class BindingBuilder<Value> {
|
|
187
|
-
protected readonly bindingKey: Token<Value> | Constructor<Value>;
|
|
188
|
-
/**
|
|
189
|
-
* Current resolution strategy; starts as `"unset"` until a `to*()` method is called.
|
|
190
|
-
*/
|
|
191
|
-
private strategy;
|
|
192
|
-
/**
|
|
193
|
-
* Lifetime scope applied to the next binding snapshot; defaults to `"transient"`.
|
|
194
|
-
*/
|
|
195
|
-
private scope;
|
|
196
|
-
/**
|
|
197
|
-
* True after an explicit `.singleton()` / `.transient()` / `.scoped()` call (prevents constant scope change).
|
|
198
|
-
*/
|
|
199
|
-
private isScopeExplicit;
|
|
200
|
-
/**
|
|
201
|
-
* Pre-allocated binding ID set via `id(identifier)` before the first `to*()` call.
|
|
202
|
-
*/
|
|
203
|
-
private explicitId;
|
|
204
|
-
/**
|
|
205
|
-
* Resolve-hint name filter set by `.whenNamed()`.
|
|
206
|
-
*/
|
|
207
|
-
private bindingName;
|
|
208
|
-
/**
|
|
209
|
-
* Tag filters accumulated by successive `.whenTagged()` calls.
|
|
210
|
-
*/
|
|
211
|
-
private readonly tags;
|
|
212
|
-
/**
|
|
213
|
-
* Custom constraint predicates accumulated by `.when()`; all must pass for this binding to be selected.
|
|
214
|
-
*/
|
|
215
|
-
private readonly constraintPredicates;
|
|
216
|
-
private onActivationHandler;
|
|
217
|
-
private onDeactivationHandler;
|
|
218
|
-
/**
|
|
219
|
-
* Set when this binding was created inside a {@link Module} / {@link AsyncModule} setup callback.
|
|
220
|
-
*/
|
|
221
|
-
private readonly moduleId;
|
|
222
|
-
/**
|
|
223
|
-
* The most recently emitted {@link Binding} snapshot; `undefined` before the first `to*()` call.
|
|
224
|
-
*/
|
|
225
|
-
private currentBinding;
|
|
226
|
-
/**
|
|
227
|
-
* Container-injected hooks that sync builder mutations into the live registry.
|
|
228
|
-
*/
|
|
229
|
-
private readonly callbacks;
|
|
230
|
-
constructor(bindingKey: Token<Value> | Constructor<Value>, moduleId?: string, callbacks?: RegistryCallbacks<Value>);
|
|
231
|
-
/**
|
|
232
|
-
* Binds the token to a concrete implementation class; the container constructs it on demand.
|
|
233
|
-
*/
|
|
234
|
-
to<C extends Constructor<Value>>(implementationClass: C): TransientBindingBuilder<Value>;
|
|
235
|
-
/**
|
|
236
|
-
* Binds the class key to itself — only valid when the key is a constructor.
|
|
237
|
-
*/
|
|
238
|
-
toSelf(): TransientBindingBuilder<Value>;
|
|
239
|
-
/**
|
|
240
|
-
* Binds the token to a pre-existing value; always resolved as singleton, no construction.
|
|
241
|
-
*/
|
|
242
|
-
toConstantValue<const ConcreteValue extends Value>(value: ConcreteValue): ConstantBindingBuilder<Value>;
|
|
243
|
-
/**
|
|
244
|
-
* Binds to a synchronous factory; `ctx` provides nested resolution within the same path.
|
|
245
|
-
*/
|
|
246
|
-
toDynamic(factory: (ctx: ResolutionContext) => Value): TransientBindingBuilder<Value>;
|
|
247
|
-
/**
|
|
248
|
-
* Binds to an async factory; must be resolved via `resolveAsync` / `resolveAllAsync`.
|
|
249
|
-
*/
|
|
250
|
-
toDynamicAsync(factory: (ctx: ResolutionContext) => Promise<Value>): TransientBindingBuilder<Value>;
|
|
251
|
-
/**
|
|
252
|
-
* Binds to a factory whose dependencies are declared explicitly in `deps` and pre-resolved by
|
|
253
|
-
* the container before the factory is called — no `ResolutionContext` needed inside the factory.
|
|
254
|
-
*/
|
|
255
|
-
toResolved<Deps extends readonly (Token<unknown> | Constructor<unknown>)[]>(factory: (...args: { [Index in keyof Deps]: TokenValue<Deps[Index]> }) => Value, deps: Deps): TransientBindingBuilder<Value>;
|
|
256
|
-
/**
|
|
257
|
-
* Redirects resolution to `targetToken`; the container resolves whatever is bound there.
|
|
258
|
-
*/
|
|
259
|
-
toAlias(targetToken: Token<Value>): TransientBindingBuilder<Value>;
|
|
260
|
-
/**
|
|
261
|
-
* One instance per container; supports `onDeactivation`.
|
|
262
|
-
*/
|
|
66
|
+
readonly target: Token<Value> | Constructor<Value>;
|
|
67
|
+
}
|
|
68
|
+
type Binding<Value = unknown> = ClassBinding<Value> | DynamicBinding<Value> | DynamicAsyncBinding<Value> | ResolvedBinding<Value> | ResolvedAsyncBinding<Value> | ConstantBinding<Value> | AliasBinding<Value>;
|
|
69
|
+
/** Builder-only payload before `id`, `token`, `slot`, and `predicate` are applied. */
|
|
70
|
+
type PartialBinding<Value> = Omit<ClassBinding<Value>, "id" | "token" | "slot" | "predicate"> | Omit<DynamicBinding<Value>, "id" | "token" | "slot" | "predicate"> | Omit<DynamicAsyncBinding<Value>, "id" | "token" | "slot" | "predicate"> | Omit<ResolvedBinding<Value>, "id" | "token" | "slot" | "predicate"> | Omit<ResolvedAsyncBinding<Value>, "id" | "token" | "slot" | "predicate"> | Omit<ConstantBinding<Value>, "id" | "token" | "slot" | "predicate"> | Omit<AliasBinding<Value>, "id" | "token" | "slot" | "predicate">;
|
|
71
|
+
declare function generateBindingId(): BindingIdentifier;
|
|
72
|
+
interface BindToBuilder<Value> {
|
|
73
|
+
to(type: Constructor<Value>): BindingBuilder<Value>;
|
|
74
|
+
toSelf(): BindingBuilder<Value>;
|
|
75
|
+
toConstantValue(value: Value): ConstantBindingBuilder<Value>;
|
|
76
|
+
toDynamic(factory: (ctx: ResolutionContext) => Value): BindingBuilder<Value>;
|
|
77
|
+
toDynamicAsync(factory: (ctx: ResolutionContext) => Promise<Value>): BindingBuilder<Value>;
|
|
78
|
+
toResolved<const Deps extends readonly DependencyKey[]>(factory: (...args: { [K in keyof Deps]: TokenValue<NoInfer<Deps>[K]> }) => Value, deps: Deps): BindingBuilder<Value>;
|
|
79
|
+
toResolvedAsync<const Deps extends readonly DependencyKey[]>(factory: (...args: { [K in keyof Deps]: TokenValue<NoInfer<Deps>[K]> }) => Promise<Value>, deps: Deps): BindingBuilder<Value>;
|
|
80
|
+
toAlias(target: Token<Value> | Constructor<Value>): AliasBindingBuilder;
|
|
81
|
+
}
|
|
82
|
+
interface BindingBuilder<Value> {
|
|
83
|
+
when(predicate: (ctx: ConstraintContext) => boolean): this;
|
|
84
|
+
whenNamed(name: string): this;
|
|
85
|
+
whenTagged(tag: string, value: unknown): this;
|
|
86
|
+
whenDefault(): this;
|
|
263
87
|
singleton(): SingletonBindingBuilder<Value>;
|
|
264
|
-
/**
|
|
265
|
-
* New instance on every resolution (default scope).
|
|
266
|
-
*/
|
|
267
88
|
transient(): TransientBindingBuilder<Value>;
|
|
268
|
-
/**
|
|
269
|
-
* One instance per child container scope.
|
|
270
|
-
*/
|
|
271
89
|
scoped(): ScopedBindingBuilder<Value>;
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
90
|
+
id(): BindingIdentifier;
|
|
91
|
+
}
|
|
92
|
+
interface ConstantBindingBuilder<Value> {
|
|
93
|
+
when(predicate: (ctx: ConstraintContext) => boolean): this;
|
|
94
|
+
whenNamed(name: string): this;
|
|
95
|
+
whenTagged(tag: string, value: unknown): this;
|
|
96
|
+
whenDefault(): this;
|
|
97
|
+
onActivation(fn: ActivationHandler<Value>): SingletonLifecycleBuilder<Value>;
|
|
98
|
+
onDeactivation(fn: DeactivationHandler<Value>): SingletonLifecycleBuilder<Value>;
|
|
99
|
+
id(): BindingIdentifier;
|
|
100
|
+
}
|
|
101
|
+
interface AliasBindingBuilder {
|
|
102
|
+
when(predicate: (ctx: ConstraintContext) => boolean): this;
|
|
283
103
|
whenNamed(name: string): this;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
104
|
+
whenTagged(tag: string, value: unknown): this;
|
|
105
|
+
whenDefault(): this;
|
|
106
|
+
id(): BindingIdentifier;
|
|
107
|
+
}
|
|
108
|
+
interface SingletonBindingBuilder<Value> {
|
|
109
|
+
onActivation(fn: ActivationHandler<Value>): this;
|
|
110
|
+
onDeactivation(fn: DeactivationHandler<Value>): this;
|
|
111
|
+
id(): BindingIdentifier;
|
|
112
|
+
}
|
|
113
|
+
interface TransientBindingBuilder<Value> {
|
|
114
|
+
onActivation(fn: ActivationHandler<Value>): this;
|
|
115
|
+
id(): BindingIdentifier;
|
|
116
|
+
}
|
|
117
|
+
interface ScopedBindingBuilder<Value> extends TransientBindingBuilder<Value> {}
|
|
118
|
+
interface SingletonLifecycleBuilder<Value> {
|
|
119
|
+
onActivation(fn: ActivationHandler<Value>): this;
|
|
120
|
+
onDeactivation(fn: DeactivationHandler<Value>): this;
|
|
297
121
|
id(): BindingIdentifier;
|
|
298
|
-
id(identifier: BindingIdentifier): BindingIdentifier;
|
|
299
|
-
/**
|
|
300
|
-
* Records the chosen strategy and emits the first {@link Binding} snapshot.
|
|
301
|
-
* Throws {@link InternalError} if a strategy was already selected (double `to*()` call).
|
|
302
|
-
*/
|
|
303
|
-
private registerWithStrategy;
|
|
304
|
-
/**
|
|
305
|
-
* Re-creates the {@link Binding} snapshot from the current builder state and pushes
|
|
306
|
-
* the update to the registry. No-op if no strategy has been set yet.
|
|
307
|
-
*/
|
|
308
|
-
private refreshRegisteredBinding;
|
|
309
|
-
/**
|
|
310
|
-
* Guards against calling `.singleton()` / `.transient()` / `.scoped()` on a constant binding,
|
|
311
|
-
* which is locked to `"singleton"` scope by invariant.
|
|
312
|
-
*/
|
|
313
|
-
private assertScopeMutable;
|
|
314
|
-
/**
|
|
315
|
-
* Produces an immutable {@link Binding} snapshot from the current builder fields.
|
|
316
|
-
* Called by both {@link registerWithStrategy} and {@link refreshRegisteredBinding}.
|
|
317
|
-
*/
|
|
318
|
-
private createBinding;
|
|
319
122
|
}
|
|
320
|
-
/**
|
|
321
|
-
* Builder returned after calling `.singleton()` — exposes `onDeactivation`.
|
|
322
|
-
*/
|
|
323
|
-
type SingletonBindingBuilder<Value> = BindingBuilder<Value>;
|
|
324
|
-
/**
|
|
325
|
-
* Builder returned after calling `.transient()`, or any strategy method before a scope is set.
|
|
326
|
-
* Does NOT expose `onDeactivation` at the type level.
|
|
327
|
-
*/
|
|
328
|
-
type TransientBindingBuilder<Value> = Omit<BindingBuilder<Value>, "onDeactivation">;
|
|
329
|
-
/**
|
|
330
|
-
* Builder returned after calling `.scoped()`.
|
|
331
|
-
* Does NOT expose `onDeactivation` at the type level.
|
|
332
|
-
*/
|
|
333
|
-
type ScopedBindingBuilder<Value> = Omit<BindingBuilder<Value>, "onDeactivation">;
|
|
334
|
-
/**
|
|
335
|
-
* Builder returned after calling `.toConstantValue()`.
|
|
336
|
-
*/
|
|
337
|
-
type ConstantBindingBuilder<Value> = Omit<SingletonBindingBuilder<Value>, "singleton" | "transient" | "scoped">;
|
|
338
|
-
/**
|
|
339
|
-
* Starts a fluent binding for the given token or constructor key.
|
|
340
|
-
*/
|
|
341
|
-
declare function bind<Value>(key: Token<Value>): BindingBuilder<Value>;
|
|
342
|
-
declare function bind<Value>(key: Constructor<Value>): BindingBuilder<Value>;
|
|
343
123
|
//#endregion
|
|
344
|
-
export {
|
|
124
|
+
export { AliasBinding, AliasBindingBuilder, BindToBuilder, Binding, BindingBuilder, ClassBinding, ConstantBinding, ConstantBindingBuilder, DEFAULT_SLOT, DynamicAsyncBinding, DynamicBinding, PartialBinding, ResolvedAsyncBinding, ResolvedBinding, ScopedBindingBuilder, SingletonBindingBuilder, SingletonLifecycleBuilder, SlotKey, TransientBindingBuilder, generateBindingId, slotKeyEquals, slotKeyToString };
|