@codefast/di 0.8.0 → 0.9.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 +40 -0
- package/LICENSE +1 -1
- package/README.md +256 -164
- package/dist/ambient/active-container.d.ts +1 -2
- package/dist/ambient/active-container.js +1 -2
- package/dist/container/binding-builders.d.ts +12 -13
- package/dist/container/binding-builders.js +1 -2
- package/dist/container/container.d.ts +11 -12
- package/dist/container/container.js +23 -9
- package/dist/core/binding-scope.d.ts +1 -2
- package/dist/core/binding-scope.js +1 -2
- package/dist/core/binding.d.ts +20 -16
- package/dist/core/binding.js +1 -2
- package/dist/core/constraint-requirement.d.ts +20 -6
- package/dist/core/constraint-requirement.js +20 -11
- package/dist/core/constructor-type.d.ts +1 -2
- package/dist/core/constructor-type.js +1 -2
- package/dist/core/map-upsert.d.ts +1 -2
- package/dist/core/map-upsert.js +1 -2
- package/dist/core/module.d.ts +1 -2
- package/dist/core/module.js +1 -2
- package/dist/core/registry.d.ts +1 -2
- package/dist/core/registry.js +1 -2
- package/dist/core/tag.d.ts +3 -4
- package/dist/core/tag.js +3 -4
- package/dist/core/token.d.ts +25 -6
- package/dist/core/token.js +2 -3
- package/dist/core/types.d.ts +9 -4
- package/dist/core/types.js +1 -2
- package/dist/decorators/inject.d.ts +2 -3
- package/dist/decorators/inject.js +7 -6
- package/dist/decorators/injectable.d.ts +1 -2
- package/dist/decorators/injectable.js +1 -2
- package/dist/decorators/lifecycle-decorators.d.ts +1 -2
- package/dist/decorators/lifecycle-decorators.js +1 -2
- package/dist/errors/diagnostics.d.ts +1 -2
- package/dist/errors/diagnostics.js +1 -2
- package/dist/errors/errors.d.ts +5 -3
- package/dist/errors/errors.js +10 -5
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -2
- package/dist/injection/descriptor.d.ts +12 -7
- package/dist/injection/descriptor.js +1 -2
- package/dist/injection/resolve-options.d.ts +1 -2
- package/dist/injection/resolve-options.js +1 -2
- package/dist/introspection/dependency-graph.d.ts +1 -2
- package/dist/introspection/dependency-graph.js +1 -2
- package/dist/introspection/graph-adapters/cytoscape.d.ts +1 -2
- package/dist/introspection/graph-adapters/cytoscape.js +1 -2
- package/dist/introspection/graph-adapters/dot.d.ts +1 -2
- package/dist/introspection/graph-adapters/dot.js +1 -2
- package/dist/introspection/graph-adapters/mermaid.d.ts +1 -2
- package/dist/introspection/graph-adapters/mermaid.js +1 -2
- package/dist/introspection/graph-adapters/reactflow.d.ts +1 -2
- package/dist/introspection/graph-adapters/reactflow.js +1 -2
- package/dist/introspection/inspector.d.ts +1 -2
- package/dist/introspection/inspector.js +1 -2
- package/dist/lifecycle/lifecycle-manager.d.ts +1 -2
- package/dist/lifecycle/lifecycle-manager.js +1 -2
- package/dist/lifecycle/scope-manager.d.ts +1 -2
- package/dist/lifecycle/scope-manager.js +1 -2
- package/dist/metadata/metadata-keys.d.ts +1 -2
- package/dist/metadata/metadata-keys.js +1 -2
- package/dist/metadata/metadata-reader-token.d.ts +1 -2
- package/dist/metadata/metadata-reader-token.js +1 -2
- package/dist/metadata/metadata-types.d.ts +1 -2
- package/dist/metadata/metadata-types.js +1 -2
- package/dist/metadata/symbol-metadata-reader.d.ts +1 -2
- package/dist/metadata/symbol-metadata-reader.js +1 -2
- package/dist/metadata/verifying-metadata-reader.d.ts +1 -2
- package/dist/metadata/verifying-metadata-reader.js +1 -2
- package/dist/resolution/cache/activation-need.d.ts +1 -2
- package/dist/resolution/cache/activation-need.js +1 -2
- package/dist/resolution/cache/binding-lookup-cache.d.ts +1 -2
- package/dist/resolution/cache/binding-lookup-cache.js +1 -2
- package/dist/resolution/cache/class-introspector.d.ts +1 -2
- package/dist/resolution/cache/class-introspector.js +1 -2
- package/dist/resolution/context.d.ts +1 -2
- package/dist/resolution/context.js +1 -2
- package/dist/resolution/path/resolution-path.d.ts +1 -2
- package/dist/resolution/path/resolution-path.js +1 -2
- package/dist/resolution/plan/instantiation-plan.d.ts +1 -2
- package/dist/resolution/plan/instantiation-plan.js +1 -2
- package/dist/resolution/resolver.d.ts +1 -2
- package/dist/resolution/resolver.js +1 -2
- package/dist/resolution/select/binding-select.d.ts +1 -2
- package/dist/resolution/select/binding-select.js +1 -2
- package/dist/resolution/select/constraints.d.ts +8 -6
- package/dist/resolution/select/constraints.js +35 -15
- package/package.json +6 -92
- package/dist/ambient/active-container.d.ts.map +0 -1
- package/dist/ambient/active-container.js.map +0 -1
- package/dist/container/binding-builders.d.ts.map +0 -1
- package/dist/container/binding-builders.js.map +0 -1
- package/dist/container/container.d.ts.map +0 -1
- package/dist/container/container.js.map +0 -1
- package/dist/core/binding-scope.d.ts.map +0 -1
- package/dist/core/binding-scope.js.map +0 -1
- package/dist/core/binding.d.ts.map +0 -1
- package/dist/core/binding.js.map +0 -1
- package/dist/core/constraint-requirement.d.ts.map +0 -1
- package/dist/core/constraint-requirement.js.map +0 -1
- package/dist/core/constructor-type.d.ts.map +0 -1
- package/dist/core/constructor-type.js.map +0 -1
- package/dist/core/map-upsert.d.ts.map +0 -1
- package/dist/core/map-upsert.js.map +0 -1
- package/dist/core/module.d.ts.map +0 -1
- package/dist/core/module.js.map +0 -1
- package/dist/core/registry.d.ts.map +0 -1
- package/dist/core/registry.js.map +0 -1
- package/dist/core/tag.d.ts.map +0 -1
- package/dist/core/tag.js.map +0 -1
- package/dist/core/token.d.ts.map +0 -1
- package/dist/core/token.js.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js.map +0 -1
- package/dist/decorators/inject.d.ts.map +0 -1
- package/dist/decorators/inject.js.map +0 -1
- package/dist/decorators/injectable.d.ts.map +0 -1
- package/dist/decorators/injectable.js.map +0 -1
- package/dist/decorators/lifecycle-decorators.d.ts.map +0 -1
- package/dist/decorators/lifecycle-decorators.js.map +0 -1
- package/dist/errors/diagnostics.d.ts.map +0 -1
- package/dist/errors/diagnostics.js.map +0 -1
- package/dist/errors/errors.d.ts.map +0 -1
- package/dist/errors/errors.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/injection/descriptor.d.ts.map +0 -1
- package/dist/injection/descriptor.js.map +0 -1
- package/dist/injection/resolve-options.d.ts.map +0 -1
- package/dist/injection/resolve-options.js.map +0 -1
- package/dist/introspection/dependency-graph.d.ts.map +0 -1
- package/dist/introspection/dependency-graph.js.map +0 -1
- package/dist/introspection/graph-adapters/cytoscape.d.ts.map +0 -1
- package/dist/introspection/graph-adapters/cytoscape.js.map +0 -1
- package/dist/introspection/graph-adapters/dot.d.ts.map +0 -1
- package/dist/introspection/graph-adapters/dot.js.map +0 -1
- package/dist/introspection/graph-adapters/mermaid.d.ts.map +0 -1
- package/dist/introspection/graph-adapters/mermaid.js.map +0 -1
- package/dist/introspection/graph-adapters/reactflow.d.ts.map +0 -1
- package/dist/introspection/graph-adapters/reactflow.js.map +0 -1
- package/dist/introspection/inspector.d.ts.map +0 -1
- package/dist/introspection/inspector.js.map +0 -1
- package/dist/lifecycle/lifecycle-manager.d.ts.map +0 -1
- package/dist/lifecycle/lifecycle-manager.js.map +0 -1
- package/dist/lifecycle/scope-manager.d.ts.map +0 -1
- package/dist/lifecycle/scope-manager.js.map +0 -1
- package/dist/metadata/metadata-keys.d.ts.map +0 -1
- package/dist/metadata/metadata-keys.js.map +0 -1
- package/dist/metadata/metadata-reader-token.d.ts.map +0 -1
- package/dist/metadata/metadata-reader-token.js.map +0 -1
- package/dist/metadata/metadata-types.d.ts.map +0 -1
- package/dist/metadata/metadata-types.js.map +0 -1
- package/dist/metadata/symbol-metadata-reader.d.ts.map +0 -1
- package/dist/metadata/symbol-metadata-reader.js.map +0 -1
- package/dist/metadata/verifying-metadata-reader.d.ts.map +0 -1
- package/dist/metadata/verifying-metadata-reader.js.map +0 -1
- package/dist/resolution/cache/activation-need.d.ts.map +0 -1
- package/dist/resolution/cache/activation-need.js.map +0 -1
- package/dist/resolution/cache/binding-lookup-cache.d.ts.map +0 -1
- package/dist/resolution/cache/binding-lookup-cache.js.map +0 -1
- package/dist/resolution/cache/class-introspector.d.ts.map +0 -1
- package/dist/resolution/cache/class-introspector.js.map +0 -1
- package/dist/resolution/context.d.ts.map +0 -1
- package/dist/resolution/context.js.map +0 -1
- package/dist/resolution/path/resolution-path.d.ts.map +0 -1
- package/dist/resolution/path/resolution-path.js.map +0 -1
- package/dist/resolution/plan/instantiation-plan.d.ts.map +0 -1
- package/dist/resolution/plan/instantiation-plan.js.map +0 -1
- package/dist/resolution/resolver.d.ts.map +0 -1
- package/dist/resolution/resolver.js.map +0 -1
- package/dist/resolution/select/binding-select.d.ts.map +0 -1
- package/dist/resolution/select/binding-select.js.map +0 -1
- package/dist/resolution/select/constraints.d.ts.map +0 -1
- package/dist/resolution/select/constraints.js.map +0 -1
- package/src/ambient/active-container.ts +0 -69
- package/src/container/binding-builders.ts +0 -337
- package/src/container/container.ts +0 -972
- package/src/core/binding-scope.ts +0 -15
- package/src/core/binding.ts +0 -505
- package/src/core/constraint-requirement.ts +0 -94
- package/src/core/constructor-type.ts +0 -18
- package/src/core/map-upsert.ts +0 -53
- package/src/core/module.ts +0 -117
- package/src/core/registry.ts +0 -319
- package/src/core/tag.ts +0 -212
- package/src/core/token.ts +0 -31
- package/src/core/types.ts +0 -149
- package/src/decorators/inject.ts +0 -101
- package/src/decorators/injectable.ts +0 -134
- package/src/decorators/lifecycle-decorators.ts +0 -43
- package/src/errors/diagnostics.ts +0 -45
- package/src/errors/errors.ts +0 -499
- package/src/index.ts +0 -139
- package/src/injection/descriptor.ts +0 -218
- package/src/injection/resolve-options.ts +0 -201
- package/src/introspection/dependency-graph.ts +0 -296
- package/src/introspection/graph-adapters/cytoscape.ts +0 -78
- package/src/introspection/graph-adapters/dot.ts +0 -32
- package/src/introspection/graph-adapters/mermaid.ts +0 -61
- package/src/introspection/graph-adapters/reactflow.ts +0 -84
- package/src/introspection/inspector.ts +0 -134
- package/src/lifecycle/lifecycle-manager.ts +0 -272
- package/src/lifecycle/scope-manager.ts +0 -158
- package/src/metadata/metadata-keys.ts +0 -28
- package/src/metadata/metadata-reader-token.ts +0 -10
- package/src/metadata/metadata-types.ts +0 -57
- package/src/metadata/symbol-metadata-reader.ts +0 -126
- package/src/metadata/verifying-metadata-reader.ts +0 -41
- package/src/resolution/cache/activation-need.ts +0 -87
- package/src/resolution/cache/binding-lookup-cache.ts +0 -169
- package/src/resolution/cache/class-introspector.ts +0 -256
- package/src/resolution/context.ts +0 -331
- package/src/resolution/path/resolution-path.ts +0 -167
- package/src/resolution/plan/instantiation-plan.ts +0 -592
- package/src/resolution/resolver.ts +0 -1654
- package/src/resolution/select/binding-select.ts +0 -207
- package/src/resolution/select/constraints.ts +0 -146
|
@@ -31,23 +31,23 @@ export interface BindingRegistration {
|
|
|
31
31
|
*
|
|
32
32
|
* @since 0.5.0-canary.8
|
|
33
33
|
*/
|
|
34
|
-
export declare class BindingChain<Value> implements AliasBindingBuilder
|
|
34
|
+
export declare class BindingChain<Value, Names extends string = string> implements AliasBindingBuilder<Names>, BindingBuilder<Value, Names>, BindToBuilder<Value, Names>, ConstantBindingBuilder<Value, Names>, ScopedBindingBuilder<Value>, SingletonBindingBuilder<Value>, SingletonLifecycleBuilder<Value>, TransientBindingBuilder<Value> {
|
|
35
35
|
#private;
|
|
36
|
-
constructor(token: Token<Value> | Constructor<Value>, registration: BindingRegistration);
|
|
37
|
-
to(type: Constructor<Value>): BindingBuilder<Value>;
|
|
38
|
-
toSelf(): BindingBuilder<Value>;
|
|
39
|
-
toConstantValue(value: Value): ConstantBindingBuilder<Value>;
|
|
40
|
-
toDynamic(factory: (ctx: ResolutionContext) => Value): BindingBuilder<Value>;
|
|
41
|
-
toDynamicAsync(factory: (ctx: ResolutionContext) => Promise<Value>): BindingBuilder<Value>;
|
|
36
|
+
constructor(token: Token<Value, Names> | Constructor<Value>, registration: BindingRegistration);
|
|
37
|
+
to(type: Constructor<Value>): BindingBuilder<Value, Names>;
|
|
38
|
+
toSelf(): BindingBuilder<Value, Names>;
|
|
39
|
+
toConstantValue(value: Value): ConstantBindingBuilder<Value, Names>;
|
|
40
|
+
toDynamic(factory: (ctx: ResolutionContext) => Value): BindingBuilder<Value, Names>;
|
|
41
|
+
toDynamicAsync(factory: (ctx: ResolutionContext) => Promise<Value>): BindingBuilder<Value, Names>;
|
|
42
42
|
toResolved<const Deps extends ReadonlyArray<InjectableDependency>>(factory: (...args: {
|
|
43
43
|
[K in keyof Deps]: ResolvedDependencyValue<NoInfer<Deps>[K]>;
|
|
44
|
-
}) => Value, deps: Deps): BindingBuilder<Value>;
|
|
44
|
+
}) => Value, deps: Deps): BindingBuilder<Value, Names>;
|
|
45
45
|
toResolvedAsync<const Deps extends ReadonlyArray<InjectableDependency>>(factory: (...args: {
|
|
46
46
|
[K in keyof Deps]: ResolvedDependencyValue<NoInfer<Deps>[K]>;
|
|
47
|
-
}) => Promise<Value>, deps: Deps): BindingBuilder<Value>;
|
|
48
|
-
toAlias(target: Token<Value> | Constructor<Value>): AliasBindingBuilder
|
|
47
|
+
}) => Promise<Value>, deps: Deps): BindingBuilder<Value, Names>;
|
|
48
|
+
toAlias(target: Token<Value> | Constructor<Value>): AliasBindingBuilder<Names>;
|
|
49
49
|
when(predicate: BindingConstraint): this;
|
|
50
|
-
whenNamed(name:
|
|
50
|
+
whenNamed(name: Names): this;
|
|
51
51
|
whenTagged(criterion: BindingTag): this;
|
|
52
52
|
whenDefault(): this;
|
|
53
53
|
singleton(): SingletonBindingBuilder<Value>;
|
|
@@ -56,5 +56,4 @@ export declare class BindingChain<Value> implements AliasBindingBuilder, Binding
|
|
|
56
56
|
onActivation(fn: ActivationHandler<Value>): this;
|
|
57
57
|
onDeactivation(fn: DeactivationHandler<Value>): this;
|
|
58
58
|
id(): BindingIdentifier;
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=binding-builders.d.ts.map
|
|
59
|
+
}
|
|
@@ -13,12 +13,12 @@ import type { MetadataReader } from "#/metadata/metadata-types";
|
|
|
13
13
|
*/
|
|
14
14
|
export interface Container {
|
|
15
15
|
readonly isDisposed: boolean;
|
|
16
|
-
bind<Value>(token: Token<Value> | Constructor<Value>): BindToBuilder<Value>;
|
|
16
|
+
bind<Value, Names extends string = string>(token: Token<Value, Names> | Constructor<Value>): BindToBuilder<Value, Names>;
|
|
17
17
|
unbind(tokenOrId: Token<unknown> | Constructor | BindingIdentifier): void;
|
|
18
18
|
unbindAsync(tokenOrId: Token<unknown> | Constructor | BindingIdentifier): Promise<void>;
|
|
19
19
|
unbindAll(): void;
|
|
20
20
|
unbindAllAsync(): Promise<void>;
|
|
21
|
-
rebind<Value>(token: Token<Value> | Constructor<Value>): BindToBuilder<Value>;
|
|
21
|
+
rebind<Value, Names extends string = string>(token: Token<Value, Names> | Constructor<Value>): BindToBuilder<Value, Names>;
|
|
22
22
|
load(...modules: Array<SyncModule>): void;
|
|
23
23
|
loadAsync(...modules: Array<SyncModule | AsyncModule>): Promise<void>;
|
|
24
24
|
unload(...modules: Array<SyncModule>): void;
|
|
@@ -26,20 +26,20 @@ export interface Container {
|
|
|
26
26
|
loadAutoRegistered(registry: AutoRegisterRegistry): number;
|
|
27
27
|
onActivation<Value>(token: Token<Value> | Constructor<Value>, handler: ActivationHandler<Value>): void;
|
|
28
28
|
onDeactivation<Value>(token: Token<Value> | Constructor<Value>, handler: DeactivationHandler<Value>): void;
|
|
29
|
-
resolve<Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Value;
|
|
30
|
-
resolveAsync<Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Promise<Value>;
|
|
31
|
-
resolveOptional<Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Value | undefined;
|
|
32
|
-
resolveOptionalAsync<Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Promise<Value | undefined>;
|
|
33
|
-
resolveAll<Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Array<Value>;
|
|
34
|
-
resolveAllAsync<Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Promise<Array<Value>>;
|
|
29
|
+
resolve<Value, Names extends string = string>(token: Token<Value, Names> | Constructor<Value>, options?: NoInfer<ResolveOptions<Names>>): Value;
|
|
30
|
+
resolveAsync<Value, Names extends string = string>(token: Token<Value, Names> | Constructor<Value>, options?: NoInfer<ResolveOptions<Names>>): Promise<Value>;
|
|
31
|
+
resolveOptional<Value, Names extends string = string>(token: Token<Value, Names> | Constructor<Value>, options?: NoInfer<ResolveOptions<Names>>): Value | undefined;
|
|
32
|
+
resolveOptionalAsync<Value, Names extends string = string>(token: Token<Value, Names> | Constructor<Value>, options?: NoInfer<ResolveOptions<Names>>): Promise<Value | undefined>;
|
|
33
|
+
resolveAll<Value, Names extends string = string>(token: Token<Value, Names> | Constructor<Value>, options?: NoInfer<ResolveOptions<Names>>): Array<Value>;
|
|
34
|
+
resolveAllAsync<Value, Names extends string = string>(token: Token<Value, Names> | Constructor<Value>, options?: NoInfer<ResolveOptions<Names>>): Promise<Array<Value>>;
|
|
35
35
|
createChild(): Container;
|
|
36
36
|
dispose(): Promise<void>;
|
|
37
37
|
[Symbol.asyncDispose](): Promise<void>;
|
|
38
38
|
[Symbol.dispose](): never;
|
|
39
39
|
initializeAsync(): Promise<void>;
|
|
40
40
|
validate(): void;
|
|
41
|
-
has(token: Token<unknown> | Constructor, options?: ResolveOptions): boolean;
|
|
42
|
-
hasOwn(token: Token<unknown> | Constructor, options?: ResolveOptions): boolean;
|
|
41
|
+
has<Names extends string = string>(token: Token<unknown, Names> | Constructor, options?: NoInfer<ResolveOptions<Names>>): boolean;
|
|
42
|
+
hasOwn<Names extends string = string>(token: Token<unknown, Names> | Constructor, options?: NoInfer<ResolveOptions<Names>>): boolean;
|
|
43
43
|
lookupBindings<Value>(token: Token<Value> | Constructor<Value>): ReadonlyArray<BindingSnapshot>;
|
|
44
44
|
inspect(): ContainerSnapshot;
|
|
45
45
|
generateDependencyGraph(options?: GraphOptions): ContainerGraphJson;
|
|
@@ -74,5 +74,4 @@ export interface ContainerStatic {
|
|
|
74
74
|
*
|
|
75
75
|
* @since 0.3.16-canary.0
|
|
76
76
|
*/
|
|
77
|
-
export declare const Container: ContainerStatic;
|
|
78
|
-
//# sourceMappingURL=container.d.ts.map
|
|
77
|
+
export declare const Container: ContainerStatic;
|
|
@@ -2,7 +2,7 @@ import { BindingChain } from "#/container/binding-builders";
|
|
|
2
2
|
import { NO_INSTANCE } from "#/core/binding";
|
|
3
3
|
import { effectiveBindingScope } from "#/core/binding-scope";
|
|
4
4
|
import { constraintRequirementsOf } from "#/core/constraint-requirement";
|
|
5
|
-
import { getOrInsert } from "#/core/map-upsert";
|
|
5
|
+
import { getOrInsert, getOrInsertComputed } from "#/core/map-upsert";
|
|
6
6
|
import { isSyncModule, MODULE_SETUP } from "#/core/module";
|
|
7
7
|
import { BindingRegistry } from "#/core/registry";
|
|
8
8
|
import { tokenName } from "#/core/token";
|
|
@@ -18,6 +18,20 @@ import { defaultMetadataReader } from "#/metadata/symbol-metadata-reader";
|
|
|
18
18
|
import { verifyingMetadataReader } from "#/metadata/verifying-metadata-reader";
|
|
19
19
|
import { ROOT_BRANCH } from "#/resolution/path/resolution-path";
|
|
20
20
|
import { DependencyResolver } from "#/resolution/resolver";
|
|
21
|
+
/** Whether a requirement's name is declared — on its token when it names one, on any token otherwise. */
|
|
22
|
+
function isSlotNameDeclared(declared, requirement) {
|
|
23
|
+
if (requirement.tokenName !== undefined) {
|
|
24
|
+
return declared.get(requirement.tokenName)?.has(requirement.name) ?? false;
|
|
25
|
+
}
|
|
26
|
+
for (const names of declared.values()) {
|
|
27
|
+
if (names.has(requirement.name)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/** Hoisted so the slot-name index's `getOrInsertComputed` allocates only on a miss, no closure per call. */
|
|
34
|
+
const newSlotNameSet = () => new Set();
|
|
21
35
|
// A Record rather than an if-chain, so a new `BindingScope` is a compile error here instead of
|
|
22
36
|
// silently landing in whichever branch happened to be last.
|
|
23
37
|
const APPLY_BINDING_SCOPE = {
|
|
@@ -552,18 +566,19 @@ class DefaultContainer {
|
|
|
552
566
|
}
|
|
553
567
|
declaredSlotNames ??= this.#slotNamesInChain();
|
|
554
568
|
for (const requirement of requirements) {
|
|
555
|
-
if (!declaredSlotNames
|
|
556
|
-
throw new UnreachableConstraintError(tokenName(binding.token), requirement
|
|
569
|
+
if (!isSlotNameDeclared(declaredSlotNames, requirement)) {
|
|
570
|
+
throw new UnreachableConstraintError(tokenName(binding.token), requirement);
|
|
557
571
|
}
|
|
558
572
|
}
|
|
559
573
|
}
|
|
560
574
|
}
|
|
561
|
-
/** Every slot name declared anywhere a resolve through this container could reach. */
|
|
575
|
+
/** Every slot name declared anywhere a resolve through this container could reach, by declaring token. */
|
|
562
576
|
#slotNamesInChain() {
|
|
563
|
-
const names = this.#parent === undefined ? new
|
|
577
|
+
const names = this.#parent === undefined ? new Map() : this.#parent.#slotNamesInChain();
|
|
564
578
|
for (const binding of this.#registry.allBindings()) {
|
|
565
|
-
|
|
566
|
-
|
|
579
|
+
const name = binding.slot.name;
|
|
580
|
+
if (name !== undefined) {
|
|
581
|
+
getOrInsertComputed(names, tokenName(binding.token), newSlotNameSet).add(name);
|
|
567
582
|
}
|
|
568
583
|
}
|
|
569
584
|
return names;
|
|
@@ -743,5 +758,4 @@ export const Container = {
|
|
|
743
758
|
await container.loadAsync(...modules);
|
|
744
759
|
return container;
|
|
745
760
|
},
|
|
746
|
-
};
|
|
747
|
-
//# sourceMappingURL=container.js.map
|
|
761
|
+
};
|
|
@@ -9,5 +9,4 @@ import type { BindingScope } from "#/core/types";
|
|
|
9
9
|
*
|
|
10
10
|
* @since 0.3.16-canary.0
|
|
11
11
|
*/
|
|
12
|
-
export declare function effectiveBindingScope(binding: Binding): BindingScope;
|
|
13
|
-
//# sourceMappingURL=binding-scope.d.ts.map
|
|
12
|
+
export declare function effectiveBindingScope(binding: Binding): BindingScope;
|
package/dist/core/binding.d.ts
CHANGED
|
@@ -248,11 +248,16 @@ export declare function clearBindingFrame<Value>(binding: Binding<Value>): void;
|
|
|
248
248
|
*
|
|
249
249
|
* @since 0.3.16-canary.0
|
|
250
250
|
*/
|
|
251
|
-
export interface SlotConstrainedBuilder {
|
|
251
|
+
export interface SlotConstrainedBuilder<Names extends string = string> {
|
|
252
|
+
/** Narrows the binding to requests the predicate accepts, evaluated on every resolve. */
|
|
252
253
|
when(predicate: BindingConstraint): this;
|
|
253
|
-
|
|
254
|
+
/** Declares the binding's slot name, one of the names the token declares. */
|
|
255
|
+
whenNamed(name: Names): this;
|
|
256
|
+
/** Declares one criterion of the binding's slot, replacing any earlier criterion of the same key. */
|
|
254
257
|
whenTagged(criterion: BindingTag): this;
|
|
258
|
+
/** Keeps the binding on the default slot, the one an unconstrained request selects. */
|
|
255
259
|
whenDefault(): this;
|
|
260
|
+
/** The identifier this binding is registered under. */
|
|
256
261
|
id(): BindingIdentifier;
|
|
257
262
|
}
|
|
258
263
|
/**
|
|
@@ -260,26 +265,26 @@ export interface SlotConstrainedBuilder {
|
|
|
260
265
|
*
|
|
261
266
|
* @since 0.3.16-canary.0
|
|
262
267
|
*/
|
|
263
|
-
export interface BindToBuilder<Value> {
|
|
264
|
-
to(type: Constructor<Value>): BindingBuilder<Value>;
|
|
265
|
-
toSelf(): BindingBuilder<Value>;
|
|
266
|
-
toConstantValue(value: Value): ConstantBindingBuilder<Value>;
|
|
267
|
-
toDynamic(factory: (ctx: ResolutionContext) => Value): BindingBuilder<Value>;
|
|
268
|
-
toDynamicAsync(factory: (ctx: ResolutionContext) => Promise<Value>): BindingBuilder<Value>;
|
|
268
|
+
export interface BindToBuilder<Value, Names extends string = string> {
|
|
269
|
+
to(type: Constructor<Value>): BindingBuilder<Value, Names>;
|
|
270
|
+
toSelf(): BindingBuilder<Value, Names>;
|
|
271
|
+
toConstantValue(value: Value): ConstantBindingBuilder<Value, Names>;
|
|
272
|
+
toDynamic(factory: (ctx: ResolutionContext) => Value): BindingBuilder<Value, Names>;
|
|
273
|
+
toDynamicAsync(factory: (ctx: ResolutionContext) => Promise<Value>): BindingBuilder<Value, Names>;
|
|
269
274
|
toResolved<const Deps extends ReadonlyArray<InjectableDependency>>(factory: (...args: {
|
|
270
275
|
[K in keyof Deps]: ResolvedDependencyValue<NoInfer<Deps>[K]>;
|
|
271
|
-
}) => Value, deps: Deps): BindingBuilder<Value>;
|
|
276
|
+
}) => Value, deps: Deps): BindingBuilder<Value, Names>;
|
|
272
277
|
toResolvedAsync<const Deps extends ReadonlyArray<InjectableDependency>>(factory: (...args: {
|
|
273
278
|
[K in keyof Deps]: ResolvedDependencyValue<NoInfer<Deps>[K]>;
|
|
274
|
-
}) => Promise<Value>, deps: Deps): BindingBuilder<Value>;
|
|
275
|
-
toAlias(target: Token<Value> | Constructor<Value>): AliasBindingBuilder
|
|
279
|
+
}) => Promise<Value>, deps: Deps): BindingBuilder<Value, Names>;
|
|
280
|
+
toAlias(target: Token<Value> | Constructor<Value>): AliasBindingBuilder<Names>;
|
|
276
281
|
}
|
|
277
282
|
/**
|
|
278
283
|
* The scope-selection step of the fluent chain.
|
|
279
284
|
*
|
|
280
285
|
* @since 0.3.16-canary.0
|
|
281
286
|
*/
|
|
282
|
-
export interface BindingBuilder<Value> extends SlotConstrainedBuilder {
|
|
287
|
+
export interface BindingBuilder<Value, Names extends string = string> extends SlotConstrainedBuilder<Names> {
|
|
283
288
|
singleton(): SingletonBindingBuilder<Value>;
|
|
284
289
|
transient(): TransientBindingBuilder<Value>;
|
|
285
290
|
scoped(): ScopedBindingBuilder<Value>;
|
|
@@ -289,7 +294,7 @@ export interface BindingBuilder<Value> extends SlotConstrainedBuilder {
|
|
|
289
294
|
*
|
|
290
295
|
* @since 0.3.16-canary.0
|
|
291
296
|
*/
|
|
292
|
-
export interface ConstantBindingBuilder<Value> extends SlotConstrainedBuilder {
|
|
297
|
+
export interface ConstantBindingBuilder<Value, Names extends string = string> extends SlotConstrainedBuilder<Names> {
|
|
293
298
|
onActivation(fn: ActivationHandler<Value>): SingletonLifecycleBuilder<Value>;
|
|
294
299
|
onDeactivation(fn: DeactivationHandler<Value>): SingletonLifecycleBuilder<Value>;
|
|
295
300
|
}
|
|
@@ -298,7 +303,7 @@ export interface ConstantBindingBuilder<Value> extends SlotConstrainedBuilder {
|
|
|
298
303
|
*
|
|
299
304
|
* @since 0.3.16-canary.0
|
|
300
305
|
*/
|
|
301
|
-
export interface AliasBindingBuilder extends SlotConstrainedBuilder {
|
|
306
|
+
export interface AliasBindingBuilder<Names extends string = string> extends SlotConstrainedBuilder<Names> {
|
|
302
307
|
}
|
|
303
308
|
/**
|
|
304
309
|
* The fluent chain after `singleton()`, where both lifecycle hooks stay available.
|
|
@@ -336,5 +341,4 @@ export interface SingletonLifecycleBuilder<Value> {
|
|
|
336
341
|
onDeactivation(fn: DeactivationHandler<Value>): this;
|
|
337
342
|
id(): BindingIdentifier;
|
|
338
343
|
}
|
|
339
|
-
export {};
|
|
340
|
-
//# sourceMappingURL=binding.d.ts.map
|
|
344
|
+
export {};
|
package/dist/core/binding.js
CHANGED
|
@@ -12,23 +12,38 @@ export declare const CONSTRAINT_REQUIREMENT: unique symbol;
|
|
|
12
12
|
/**
|
|
13
13
|
* The slot name a constraint waits for on an ancestor.
|
|
14
14
|
*
|
|
15
|
-
* @remarks Only names are described
|
|
16
|
-
* looks valid, while a name is a bare string that
|
|
15
|
+
* @remarks Only names are described, however spelled: a tag criterion of any other key is minted from
|
|
16
|
+
* a typed key, so a typo cannot produce one that looks valid, while a name is a bare string that
|
|
17
|
+
* nothing checks — through `whenNamed`'s reserved key included.
|
|
17
18
|
*
|
|
18
19
|
* @since 0.6.0
|
|
19
20
|
*/
|
|
20
21
|
export interface ConstraintRequirement {
|
|
21
22
|
readonly requires: "ancestorSlotName";
|
|
23
|
+
/** The token whose slot must carry the name, or `undefined` when the spelling named no token. */
|
|
24
|
+
readonly tokenName: string | undefined;
|
|
22
25
|
readonly name: string;
|
|
23
26
|
/** The helper that built the predicate, so a report can name what the caller wrote. */
|
|
24
27
|
readonly helperName: string;
|
|
25
28
|
}
|
|
26
29
|
/**
|
|
27
|
-
*
|
|
30
|
+
* What a helper records about one waited-for slot name, before the discriminant is stamped on.
|
|
31
|
+
*
|
|
32
|
+
* @since 0.9.0
|
|
33
|
+
*/
|
|
34
|
+
export type SlotNameRequirement = Omit<ConstraintRequirement, "requires">;
|
|
35
|
+
/**
|
|
36
|
+
* Records the one slot name a predicate waits for. Called once, where the predicate is built.
|
|
28
37
|
*
|
|
29
38
|
* @since 0.6.0
|
|
30
39
|
*/
|
|
31
|
-
export declare function requiringAncestorSlotName(predicate: BindingConstraint,
|
|
40
|
+
export declare function requiringAncestorSlotName(predicate: BindingConstraint, requirement: SlotNameRequirement): BindingConstraint;
|
|
41
|
+
/**
|
|
42
|
+
* Records every slot name a predicate waits for — one per reserved criterion in a `…TaggedAll` list.
|
|
43
|
+
*
|
|
44
|
+
* @since 0.9.0
|
|
45
|
+
*/
|
|
46
|
+
export declare function requiringAncestorSlotNames(predicate: BindingConstraint, requirements: ReadonlyArray<SlotNameRequirement>): BindingConstraint;
|
|
32
47
|
/**
|
|
33
48
|
* The requirement a predicate carries, if it was built by a helper that records one.
|
|
34
49
|
*
|
|
@@ -49,5 +64,4 @@ export declare function constraintRequirementsOf(predicate: BindingConstraint):
|
|
|
49
64
|
*
|
|
50
65
|
* @since 0.6.1
|
|
51
66
|
*/
|
|
52
|
-
export declare function mergingConstraintRequirements(composite: BindingConstraint, left: BindingConstraint, right: BindingConstraint): BindingConstraint;
|
|
53
|
-
//# sourceMappingURL=constraint-requirement.d.ts.map
|
|
67
|
+
export declare function mergingConstraintRequirements(composite: BindingConstraint, left: BindingConstraint, right: BindingConstraint): BindingConstraint;
|
|
@@ -8,13 +8,27 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export const CONSTRAINT_REQUIREMENT = Symbol("di:constraint-requirement");
|
|
10
10
|
/**
|
|
11
|
-
* Records
|
|
11
|
+
* Records the one slot name a predicate waits for. Called once, where the predicate is built.
|
|
12
12
|
*
|
|
13
13
|
* @since 0.6.0
|
|
14
14
|
*/
|
|
15
|
-
export function requiringAncestorSlotName(predicate,
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
export function requiringAncestorSlotName(predicate, requirement) {
|
|
16
|
+
return requiringAncestorSlotNames(predicate, [requirement]);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Records every slot name a predicate waits for — one per reserved criterion in a `…TaggedAll` list.
|
|
20
|
+
*
|
|
21
|
+
* @since 0.9.0
|
|
22
|
+
*/
|
|
23
|
+
export function requiringAncestorSlotNames(predicate, requirements) {
|
|
24
|
+
return attachRequirements(predicate, requirements.map((requirement) => ({ requires: "ancestorSlotName", ...requirement })));
|
|
25
|
+
}
|
|
26
|
+
/** One non-enumerable write per predicate: a second define on the same key would throw. */
|
|
27
|
+
function attachRequirements(predicate, requirements) {
|
|
28
|
+
Object.defineProperty(predicate, CONSTRAINT_REQUIREMENT, {
|
|
29
|
+
value: requirements.length === 1 ? requirements[0] : requirements,
|
|
30
|
+
enumerable: false,
|
|
31
|
+
});
|
|
18
32
|
return predicate;
|
|
19
33
|
}
|
|
20
34
|
/**
|
|
@@ -53,10 +67,5 @@ export function mergingConstraintRequirements(composite, left, right) {
|
|
|
53
67
|
if (merged.length === 0) {
|
|
54
68
|
return composite;
|
|
55
69
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
enumerable: false,
|
|
59
|
-
});
|
|
60
|
-
return composite;
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=constraint-requirement.js.map
|
|
70
|
+
return attachRequirements(composite, merged);
|
|
71
|
+
}
|
|
@@ -14,5 +14,4 @@ export type Constructor<out Value = unknown> = new (...args: Array<never>) => Va
|
|
|
14
14
|
*
|
|
15
15
|
* @since 0.3.16-canary.0
|
|
16
16
|
*/
|
|
17
|
-
export type ConstructorInvocation = new (...args: Array<unknown>) => unknown;
|
|
18
|
-
//# sourceMappingURL=constructor-type.d.ts.map
|
|
17
|
+
export type ConstructorInvocation = new (...args: Array<unknown>) => unknown;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
//# sourceMappingURL=constructor-type.js.map
|
|
1
|
+
export {};
|
|
@@ -25,5 +25,4 @@ export declare function getOrInsert<Key, Value extends {} | null>(map: Map<Key,
|
|
|
25
25
|
*
|
|
26
26
|
* @since 0.7.0
|
|
27
27
|
*/
|
|
28
|
-
export declare function getOrInsertComputed<Key, Value extends {} | null>(map: Map<Key, Value>, key: NoInfer<Key>, create: (key: NoInfer<Key>) => NoInfer<Value>): Value;
|
|
29
|
-
//# sourceMappingURL=map-upsert.d.ts.map
|
|
28
|
+
export declare function getOrInsertComputed<Key, Value extends {} | null>(map: Map<Key, Value>, key: NoInfer<Key>, create: (key: NoInfer<Key>) => NoInfer<Value>): Value;
|
package/dist/core/map-upsert.js
CHANGED
package/dist/core/module.d.ts
CHANGED
package/dist/core/module.js
CHANGED
package/dist/core/registry.d.ts
CHANGED
|
@@ -60,5 +60,4 @@ export declare class BindingRegistry {
|
|
|
60
60
|
availableSlotStrings(token: Token<unknown> | Constructor): Array<string>;
|
|
61
61
|
/** Whether the deferred tagged-slot index has had to be built. */
|
|
62
62
|
get isTaggedIndexBuilt(): boolean;
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=registry.d.ts.map
|
|
63
|
+
}
|
package/dist/core/registry.js
CHANGED
|
@@ -280,5 +280,4 @@ function isDefaultSlotBinding(binding) {
|
|
|
280
280
|
/** A predicate with no slot constraint: last-wins does not apply to it. */
|
|
281
281
|
function isPurePredicateBinding(binding) {
|
|
282
282
|
return binding.predicate !== undefined && binding.slot.tags.length === 0;
|
|
283
|
-
}
|
|
284
|
-
//# sourceMappingURL=registry.js.map
|
|
283
|
+
}
|
package/dist/core/tag.d.ts
CHANGED
|
@@ -59,12 +59,12 @@ export interface TagKey<Value = unknown> {
|
|
|
59
59
|
/**
|
|
60
60
|
* Declares a tag key, whose `of()` builds the criteria a `whenTagged` and a resolve both take.
|
|
61
61
|
*
|
|
62
|
-
* @remarks The value type is checked at both ends: a key declared `tag<Region>("region")` refuses a
|
|
62
|
+
* @remarks The value type is checked at both ends: a key declared `tag<Region>("di:region")` refuses a
|
|
63
63
|
* value that is not a `Region`, so a bind site and a resolve site cannot drift apart silently.
|
|
64
64
|
*
|
|
65
65
|
* @example
|
|
66
66
|
* ```ts
|
|
67
|
-
* const Region = tag<"eu" | "us">("region");
|
|
67
|
+
* const Region = tag<"eu" | "us">("di:region");
|
|
68
68
|
* container.bind(Storage).to(S3).whenTagged(Region.of("eu"));
|
|
69
69
|
* container.resolve(Storage, { tag: Region.of("eu") });
|
|
70
70
|
* ```
|
|
@@ -102,5 +102,4 @@ export declare function tagKeyMaskOf(tags: ReadonlyArray<BindingTag>): TagKeyMas
|
|
|
102
102
|
* @since 0.6.0
|
|
103
103
|
*/
|
|
104
104
|
export declare function coversTagKeys(requestMask: TagKeyMask, slotMask: TagKeyMask): boolean;
|
|
105
|
-
export {};
|
|
106
|
-
//# sourceMappingURL=tag.d.ts.map
|
|
105
|
+
export {};
|
package/dist/core/tag.js
CHANGED
|
@@ -27,12 +27,12 @@ function internKeyFor(value) {
|
|
|
27
27
|
/**
|
|
28
28
|
* Declares a tag key, whose `of()` builds the criteria a `whenTagged` and a resolve both take.
|
|
29
29
|
*
|
|
30
|
-
* @remarks The value type is checked at both ends: a key declared `tag<Region>("region")` refuses a
|
|
30
|
+
* @remarks The value type is checked at both ends: a key declared `tag<Region>("di:region")` refuses a
|
|
31
31
|
* value that is not a `Region`, so a bind site and a resolve site cannot drift apart silently.
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
34
34
|
* ```ts
|
|
35
|
-
* const Region = tag<"eu" | "us">("region");
|
|
35
|
+
* const Region = tag<"eu" | "us">("di:region");
|
|
36
36
|
* container.bind(Storage).to(S3).whenTagged(Region.of("eu"));
|
|
37
37
|
* container.resolve(Storage, { tag: Region.of("eu") });
|
|
38
38
|
* ```
|
|
@@ -135,5 +135,4 @@ export function tagKeyMaskOf(tags) {
|
|
|
135
135
|
*/
|
|
136
136
|
export function coversTagKeys(requestMask, slotMask) {
|
|
137
137
|
return (requestMask & slotMask) === slotMask;
|
|
138
|
-
}
|
|
139
|
-
//# sourceMappingURL=tag.js.map
|
|
138
|
+
}
|
package/dist/core/token.d.ts
CHANGED
|
@@ -1,25 +1,44 @@
|
|
|
1
1
|
import type { Constructor } from "#/core/constructor-type";
|
|
2
2
|
declare const TOKEN_BRAND: unique symbol;
|
|
3
|
+
declare const TOKEN_NAMES_BRAND: unique symbol;
|
|
3
4
|
/**
|
|
4
|
-
* A branded identifier carrying the value type its bindings resolve to.
|
|
5
|
+
* A branded identifier carrying the value type its bindings resolve to, and the slot names they may declare.
|
|
6
|
+
*
|
|
7
|
+
* @remarks `Names` exists at the type level only: `whenNamed`, and `name` in `ResolveOptions` and
|
|
8
|
+
* `InjectOptions`, narrow to it, so a bind site and a request site cannot drift apart silently. It
|
|
9
|
+
* is covariant, so a token declaring names is still a `Token<unknown>` wherever the engine erases
|
|
10
|
+
* the value type; the default `string` leaves a token that declares none unconstrained.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const Logger = token<Logger, "console" | "file">("di:Logger");
|
|
15
|
+
* container.bind(Logger).to(FileLogger).whenNamed("file");
|
|
16
|
+
* container.resolve(Logger, { name: "file" });
|
|
17
|
+
* ```
|
|
5
18
|
*
|
|
6
19
|
* @since 0.3.16-canary.0
|
|
7
20
|
*/
|
|
8
|
-
export interface Token<out Value> {
|
|
21
|
+
export interface Token<out Value, out Names extends string = string> {
|
|
9
22
|
readonly name: string;
|
|
10
23
|
readonly [TOKEN_BRAND]: Value;
|
|
24
|
+
readonly [TOKEN_NAMES_BRAND]?: Names;
|
|
11
25
|
}
|
|
12
26
|
/**
|
|
13
|
-
*
|
|
27
|
+
* The slot names a dependency key declares — `string` for a class, or a token that declares none.
|
|
28
|
+
*
|
|
29
|
+
* @since 0.9.0
|
|
30
|
+
*/
|
|
31
|
+
export type SlotNamesOf<Key> = Key extends Token<unknown, infer Names extends string> ? Names : string;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a named `Token` for the given value type, optionally declaring the slot names its bindings may use.
|
|
14
34
|
*
|
|
15
35
|
* @since 0.3.16-canary.0
|
|
16
36
|
*/
|
|
17
|
-
export declare function token<Value>(name: string): Token<Value>;
|
|
37
|
+
export declare function token<Value, Names extends string = string>(name: string): Token<Value, Names>;
|
|
18
38
|
/**
|
|
19
39
|
* Returns the display name of a token or class used as a dependency key.
|
|
20
40
|
*
|
|
21
41
|
* @since 0.3.16-canary.0
|
|
22
42
|
*/
|
|
23
43
|
export declare function tokenName(dependency: Token<unknown> | Constructor): string;
|
|
24
|
-
export {};
|
|
25
|
-
//# sourceMappingURL=token.d.ts.map
|
|
44
|
+
export {};
|
package/dist/core/token.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Creates a named `Token` for the given value type.
|
|
2
|
+
* Creates a named `Token` for the given value type, optionally declaring the slot names its bindings may use.
|
|
3
3
|
*
|
|
4
4
|
* @since 0.3.16-canary.0
|
|
5
5
|
*/
|
|
@@ -13,5 +13,4 @@ export function token(name) {
|
|
|
13
13
|
*/
|
|
14
14
|
export function tokenName(dependency) {
|
|
15
15
|
return dependency.name;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=token.js.map
|
|
16
|
+
}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -47,8 +47,14 @@ export type DeactivationHandler<Value> = (instance: Value) => void | Promise<voi
|
|
|
47
47
|
*
|
|
48
48
|
* @since 0.3.16-canary.0
|
|
49
49
|
*/
|
|
50
|
-
export interface ResolveOptions {
|
|
51
|
-
|
|
50
|
+
export interface ResolveOptions<Names extends string = string> {
|
|
51
|
+
/**
|
|
52
|
+
* The slot name a binding declared with `whenNamed`.
|
|
53
|
+
*
|
|
54
|
+
* @remarks Narrowed to the names the token declares, so a request cannot ask for a name no
|
|
55
|
+
* binding could carry; a token declaring none takes any string.
|
|
56
|
+
*/
|
|
57
|
+
name?: Names | undefined;
|
|
52
58
|
/**
|
|
53
59
|
* Single-tag shorthand, equivalent to listing the one pair in `tags`.
|
|
54
60
|
*
|
|
@@ -112,5 +118,4 @@ export interface ResolutionContext {
|
|
|
112
118
|
*
|
|
113
119
|
* @since 0.3.16-canary.0
|
|
114
120
|
*/
|
|
115
|
-
export type TokenValue<Type> = Type extends Token<infer Value> ? Value : Type extends Constructor<infer Value> ? Value : never;
|
|
116
|
-
//# sourceMappingURL=types.d.ts.map
|
|
121
|
+
export type TokenValue<Type> = Type extends Token<infer Value> ? Value : Type extends Constructor<infer Value> ? Value : never;
|
package/dist/core/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
//# sourceMappingURL=types.js.map
|
|
1
|
+
export {};
|
|
@@ -8,6 +8,5 @@ type ClassAccessorDecorator<This, Value> = (target: ClassAccessorDecoratorTarget
|
|
|
8
8
|
*
|
|
9
9
|
* @since 0.3.16-canary.0
|
|
10
10
|
*/
|
|
11
|
-
export declare function inject<Value>(token: Token<Value> | Constructor<Value>, options?: InjectOptions): InjectionDescriptor<Value> & ClassAccessorDecorator<unknown, Value>;
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=inject.d.ts.map
|
|
11
|
+
export declare function inject<Value, Names extends string = string>(token: Token<Value, Names> | Constructor<Value>, options?: NoInfer<InjectOptions<Names>>): InjectionDescriptor<Value> & ClassAccessorDecorator<unknown, Value>;
|
|
12
|
+
export {};
|
|
@@ -30,6 +30,8 @@ export function inject(token, options) {
|
|
|
30
30
|
// Derived from the descriptor, not from `options`: the descriptor is where the tag shorthand has
|
|
31
31
|
// already been folded. Built once here rather than per constructed instance.
|
|
32
32
|
const resolveOptions = injectionSlotToResolveOptions(descriptor);
|
|
33
|
+
// The names are checked above; the container lane only needs the value type.
|
|
34
|
+
const resolveKey = token;
|
|
33
35
|
const decoratorFn = (_target, context) => {
|
|
34
36
|
if (context.static) {
|
|
35
37
|
throw new StaticMemberDecoratorError("inject", String(context.name));
|
|
@@ -50,8 +52,8 @@ export function inject(token, options) {
|
|
|
50
52
|
const ambient = getAmbientResolution();
|
|
51
53
|
if (ambient !== undefined) {
|
|
52
54
|
const value = descriptor.optional
|
|
53
|
-
? ambient.resolveOptional(
|
|
54
|
-
: ambient.resolve(
|
|
55
|
+
? ambient.resolveOptional(resolveKey, resolveOptions)
|
|
56
|
+
: ambient.resolve(resolveKey, resolveOptions);
|
|
55
57
|
context.access.set(this, value);
|
|
56
58
|
return;
|
|
57
59
|
}
|
|
@@ -60,8 +62,8 @@ export function inject(token, options) {
|
|
|
60
62
|
throw new MissingContainerContextError(classNameOf(this), context.name);
|
|
61
63
|
}
|
|
62
64
|
const value = descriptor.optional
|
|
63
|
-
? container.resolveOptional(
|
|
64
|
-
: container.resolve(
|
|
65
|
+
? container.resolveOptional(resolveKey, resolveOptions)
|
|
66
|
+
: container.resolve(resolveKey, resolveOptions);
|
|
65
67
|
context.access.set(this, value);
|
|
66
68
|
});
|
|
67
69
|
return {};
|
|
@@ -73,5 +75,4 @@ export function inject(token, options) {
|
|
|
73
75
|
}
|
|
74
76
|
Object.defineProperties(decoratorFn, props);
|
|
75
77
|
return decoratorFn;
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=inject.js.map
|
|
78
|
+
}
|
|
@@ -54,5 +54,4 @@ export declare function injectable(): (target: unknown, context: ClassDecoratorC
|
|
|
54
54
|
* @since 0.3.16-canary.0
|
|
55
55
|
*/
|
|
56
56
|
export declare function injectable<const Deps extends ReadonlyArray<InjectableDependency>>(deps: Deps, options?: InjectableOptions): <Target extends abstract new (...args: InjectedParameters<Deps>) => unknown>(target: Target & (number extends Deps["length"] ? unknown : Deps["length"] extends ConstructorParameters<Target>["length"] ? unknown : never), context: ClassDecoratorContext) => void;
|
|
57
|
-
export type { InjectableDependency };
|
|
58
|
-
//# sourceMappingURL=injectable.d.ts.map
|
|
57
|
+
export type { InjectableDependency };
|