@codefast/di 0.3.16-canary.1 → 0.3.16-canary.3
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 +18 -0
- package/README.md +4 -4
- package/dist/binding-select.d.mts +1 -1
- package/dist/binding-select.mjs +5 -5
- package/dist/binding.d.mts +28 -28
- package/dist/binding.mjs +8 -8
- package/dist/constraints.d.mts +3 -3
- package/dist/constraints.mjs +2 -2
- package/dist/container.mjs +146 -214
- package/dist/decorators/inject.d.mts +4 -3
- package/dist/decorators/inject.mjs +21 -48
- package/dist/decorators/injectable.mjs +4 -12
- package/dist/decorators/lifecycle-decorators.mjs +11 -72
- package/dist/dependency-graph.mjs +17 -15
- package/dist/environment.d.mts +15 -15
- package/dist/environment.mjs +21 -21
- package/dist/graph-adapters/cytoscape.d.mts +12 -12
- package/dist/graph-adapters/cytoscape.mjs +7 -7
- package/dist/graph-adapters/reactflow.d.mts +15 -15
- package/dist/graph-adapters/reactflow.mjs +6 -9
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +2 -2
- package/dist/inspector.d.mts +3 -2
- package/dist/inspector.mjs +19 -22
- package/dist/lifecycle.mjs +2 -12
- package/dist/metadata/metadata-keys.d.mts +8 -33
- package/dist/metadata/metadata-keys.mjs +8 -21
- package/dist/metadata/metadata-types.d.mts +5 -0
- package/dist/metadata/symbol-metadata-reader.d.mts +1 -0
- package/dist/metadata/symbol-metadata-reader.mjs +11 -33
- package/dist/module.d.mts +1 -1
- package/dist/module.mjs +2 -2
- package/dist/registry.d.mts +4 -4
- package/dist/registry.mjs +26 -45
- package/dist/resolve-options.d.mts +7 -7
- package/dist/resolve-options.mjs +14 -12
- package/dist/resolver.d.mts +15 -10
- package/dist/resolver.mjs +167 -173
- package/dist/token.d.mts +1 -1
- package/dist/token.mjs +4 -4
- package/dist/types.d.mts +14 -8
- package/package.json +40 -13
- package/src/binding-scope.ts +26 -0
- package/src/binding-select.ts +167 -0
- package/src/binding.ts +281 -0
- package/src/constraints.ts +149 -0
- package/src/constructor-type.ts +19 -0
- package/src/container.ts +1213 -0
- package/src/decorators/inject.ts +233 -0
- package/src/decorators/injectable.ts +85 -0
- package/src/decorators/lifecycle-decorators.ts +55 -0
- package/src/dependency-graph.ts +116 -0
- package/src/environment.ts +232 -0
- package/src/errors.ts +262 -0
- package/src/graph-adapters/cytoscape.ts +64 -0
- package/src/graph-adapters/dot.ts +22 -0
- package/src/graph-adapters/reactflow.ts +58 -0
- package/src/index.ts +101 -0
- package/src/inspector.ts +133 -0
- package/src/lifecycle.ts +238 -0
- package/src/metadata/metadata-keys.ts +25 -0
- package/src/metadata/metadata-reader-token.ts +8 -0
- package/src/metadata/metadata-types.ts +53 -0
- package/src/metadata/symbol-metadata-reader.ts +57 -0
- package/src/module.ts +93 -0
- package/src/registry.ts +241 -0
- package/src/resolve-options.ts +42 -0
- package/src/resolver.ts +1837 -0
- package/src/scope.ts +77 -0
- package/src/token.ts +40 -0
- package/src/types.ts +145 -0
- package/dist/graph-adapters/types.d.mts +0 -2
- package/dist/graph-adapters/types.mjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -2,11 +2,11 @@ import { effectiveBindingScope } from "./binding-scope.mjs";
|
|
|
2
2
|
import { AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError } from "./errors.mjs";
|
|
3
3
|
import { isToken, token, tokenName } from "./token.mjs";
|
|
4
4
|
import { whenAnyAncestorIs, whenAnyAncestorNamed, whenAnyAncestorTagged, whenAnyAncestorTaggedAll, whenNoAncestorIs, whenNoParentIs, whenParentIs, whenParentNamed, whenParentTagged, whenParentTaggedAll } from "./constraints.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { bindingSlotToResolveOptions, injectionSlotToResolveOptions } from "./resolve-options.mjs";
|
|
6
6
|
import { MetadataReaderToken } from "./metadata/metadata-reader-token.mjs";
|
|
7
7
|
import { inject, injectAll, isInjectionDescriptor, optional } from "./decorators/inject.mjs";
|
|
8
8
|
import { AsyncModule, Module, SyncModule, isSyncModule } from "./module.mjs";
|
|
9
9
|
import { Container } from "./container.mjs";
|
|
10
10
|
import { createAutoRegisterRegistry, injectable } from "./decorators/injectable.mjs";
|
|
11
11
|
import { postConstruct, preDestroy } from "./decorators/lifecycle-decorators.mjs";
|
|
12
|
-
export { AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModule, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, Container, DiError, DisposedContainerError, InternalError, MetadataReaderToken, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, Module, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError, SyncModule, TokenNotBoundError, createAutoRegisterRegistry, effectiveBindingScope, inject, injectAll, injectable,
|
|
12
|
+
export { AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModule, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, Container, DiError, DisposedContainerError, InternalError, MetadataReaderToken, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, Module, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError, SyncModule, TokenNotBoundError, bindingSlotToResolveOptions, createAutoRegisterRegistry, effectiveBindingScope, inject, injectAll, injectable, injectionSlotToResolveOptions, isInjectionDescriptor, isSyncModule, isToken, optional, postConstruct, preDestroy, token, tokenName, whenAnyAncestorIs, whenAnyAncestorNamed, whenAnyAncestorTagged, whenAnyAncestorTaggedAll, whenNoAncestorIs, whenNoParentIs, whenParentIs, whenParentNamed, whenParentTagged, whenParentTaggedAll };
|
package/dist/inspector.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Constructor } from "./constructor-type.mjs";
|
|
2
2
|
import { Token } from "./token.mjs";
|
|
3
|
-
import { BindingIdentifier, BindingKind, BindingScope, ResolveOptions } from "./types.mjs";
|
|
3
|
+
import { BindingIdentifier, BindingKind, BindingScope, BindingTag, ResolveOptions } from "./types.mjs";
|
|
4
4
|
import { BindingRegistry } from "./registry.mjs";
|
|
5
5
|
import { ScopeManager } from "./scope.mjs";
|
|
6
6
|
|
|
@@ -14,7 +14,7 @@ interface BindingSnapshot {
|
|
|
14
14
|
readonly scope: BindingScope;
|
|
15
15
|
readonly slot: {
|
|
16
16
|
readonly name?: string;
|
|
17
|
-
readonly tags: ReadonlyArray<
|
|
17
|
+
readonly tags: ReadonlyArray<BindingTag>;
|
|
18
18
|
};
|
|
19
19
|
readonly id: BindingIdentifier;
|
|
20
20
|
}
|
|
@@ -40,6 +40,7 @@ declare class Inspector {
|
|
|
40
40
|
lookupBindings<Value>(token: Token<Value> | Constructor<Value>): ReadonlyArray<BindingSnapshot>;
|
|
41
41
|
has(token: Token<unknown> | Constructor, hint?: ResolveOptions, parentHas?: () => boolean): boolean;
|
|
42
42
|
hasOwn(token: Token<unknown> | Constructor, hint?: ResolveOptions): boolean;
|
|
43
|
+
private _makeHintContext;
|
|
43
44
|
private allBindingSnapshots;
|
|
44
45
|
private _toSnapshot;
|
|
45
46
|
}
|
package/dist/inspector.mjs
CHANGED
|
@@ -25,48 +25,45 @@ var Inspector = class {
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
lookupBindings(token) {
|
|
28
|
-
return this._registry.getAll(token).map((
|
|
28
|
+
return this._registry.getAll(token).map((binding) => this._toSnapshot(binding));
|
|
29
29
|
}
|
|
30
30
|
has(token, hint, parentHas) {
|
|
31
31
|
const bindings = this._registry.getAll(token);
|
|
32
32
|
if (bindings.length > 0) if (hint !== void 0) {
|
|
33
|
-
if (selectBinding(bindings, hint,
|
|
34
|
-
resolutionPath: [],
|
|
35
|
-
materializationStack: [],
|
|
36
|
-
parent: void 0,
|
|
37
|
-
ancestors: [],
|
|
38
|
-
currentResolveHint: hint
|
|
39
|
-
}, tokenName(token)) !== void 0) return true;
|
|
33
|
+
if (selectBinding(bindings, hint, this._makeHintContext(hint), tokenName(token)) !== void 0) return true;
|
|
40
34
|
} else return true;
|
|
41
35
|
return parentHas?.() ?? false;
|
|
42
36
|
}
|
|
43
37
|
hasOwn(token, hint) {
|
|
44
38
|
const bindings = this._registry.getAll(token);
|
|
45
39
|
if (bindings.length === 0) return false;
|
|
46
|
-
if (hint !== void 0) return selectBinding(bindings, hint,
|
|
40
|
+
if (hint !== void 0) return selectBinding(bindings, hint, this._makeHintContext(hint), tokenName(token)) !== void 0;
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
_makeHintContext(hint) {
|
|
44
|
+
return {
|
|
47
45
|
resolutionPath: [],
|
|
48
|
-
|
|
46
|
+
resolutionStack: [],
|
|
49
47
|
parent: void 0,
|
|
50
48
|
ancestors: [],
|
|
51
49
|
currentResolveHint: hint
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
50
|
+
};
|
|
54
51
|
}
|
|
55
52
|
allBindingSnapshots() {
|
|
56
|
-
return this._registry.allBindings().map((
|
|
53
|
+
return this._registry.allBindings().map((binding) => this._toSnapshot(binding));
|
|
57
54
|
}
|
|
58
|
-
_toSnapshot(
|
|
59
|
-
const scope = effectiveBindingScope(
|
|
60
|
-
const slot =
|
|
61
|
-
name:
|
|
62
|
-
tags:
|
|
63
|
-
} : { tags:
|
|
55
|
+
_toSnapshot(binding) {
|
|
56
|
+
const scope = effectiveBindingScope(binding);
|
|
57
|
+
const slot = binding.slot.name !== void 0 ? {
|
|
58
|
+
name: binding.slot.name,
|
|
59
|
+
tags: binding.slot.tags
|
|
60
|
+
} : { tags: binding.slot.tags };
|
|
64
61
|
return {
|
|
65
|
-
tokenName: tokenName(
|
|
66
|
-
kind:
|
|
62
|
+
tokenName: tokenName(binding.token),
|
|
63
|
+
kind: binding.kind,
|
|
67
64
|
scope,
|
|
68
65
|
slot,
|
|
69
|
-
id:
|
|
66
|
+
id: binding.id
|
|
70
67
|
};
|
|
71
68
|
}
|
|
72
69
|
};
|
package/dist/lifecycle.mjs
CHANGED
|
@@ -10,12 +10,7 @@ var LifecycleManager = class {
|
|
|
10
10
|
_activationVersion = 0;
|
|
11
11
|
registerActivation(token, handler) {
|
|
12
12
|
this._activationVersion += 1;
|
|
13
|
-
|
|
14
|
-
if (list === void 0) {
|
|
15
|
-
list = [];
|
|
16
|
-
this._activationHooks.set(token, list);
|
|
17
|
-
}
|
|
18
|
-
list.push(handler);
|
|
13
|
+
this._activationHooks.getOrInsert(token, []).push(handler);
|
|
19
14
|
}
|
|
20
15
|
hasActivationHandlers(token) {
|
|
21
16
|
if (this._activationHooks.size === 0) return false;
|
|
@@ -26,12 +21,7 @@ var LifecycleManager = class {
|
|
|
26
21
|
return this._activationVersion;
|
|
27
22
|
}
|
|
28
23
|
registerDeactivation(token, handler) {
|
|
29
|
-
|
|
30
|
-
if (list === void 0) {
|
|
31
|
-
list = [];
|
|
32
|
-
this._deactivationHooks.set(token, list);
|
|
33
|
-
}
|
|
34
|
-
list.push(handler);
|
|
24
|
+
this._deactivationHooks.getOrInsert(token, []).push(handler);
|
|
35
25
|
}
|
|
36
26
|
async runActivation(resolutionContext, binding, instance, metadataReader) {
|
|
37
27
|
let activatedInstance = instance;
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
import { ConstructorMetadata, MutableLifecycleMetadata } from "./metadata-types.mjs";
|
|
2
|
-
|
|
3
1
|
//#region src/metadata/metadata-keys.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Accessor injection entries mirrored from `Symbol.metadata` for toolchains where
|
|
6
|
-
* resolver reads stable metadata via the same object identity as `context.metadata`.
|
|
7
|
-
*
|
|
8
|
-
* @since 0.3.16-canary.0
|
|
9
|
-
*/
|
|
10
|
-
type AccessorInjectionEntryList = Array<{
|
|
11
|
-
key: string | symbol;
|
|
12
|
-
descriptor: unknown;
|
|
13
|
-
}>;
|
|
14
2
|
/**
|
|
15
3
|
* @since 0.3.16-canary.0
|
|
16
4
|
*/
|
|
@@ -24,29 +12,16 @@ declare const LIFECYCLE_KEY: unique symbol;
|
|
|
24
12
|
*/
|
|
25
13
|
declare const INJECT_ACCESSOR_KEY: unique symbol;
|
|
26
14
|
/**
|
|
27
|
-
*
|
|
28
|
-
*/
|
|
29
|
-
declare const constructorMetadataMap: WeakMap<object, ConstructorMetadata>;
|
|
30
|
-
/**
|
|
31
|
-
* @since 0.3.16-canary.0
|
|
32
|
-
*/
|
|
33
|
-
declare const lifecycleMetadataMap: WeakMap<object, MutableLifecycleMetadata>;
|
|
34
|
-
/**
|
|
35
|
-
* @since 0.3.16-canary.0
|
|
36
|
-
*/
|
|
37
|
-
declare const lifecycleByConstructorMetadataMap: WeakMap<object, MutableLifecycleMetadata>;
|
|
38
|
-
/**
|
|
39
|
-
* Fallback keyed by the class metadata object (`context.metadata` / `ctor[Symbol.metadata]`).
|
|
15
|
+
* The well-known symbol used by TC39 Stage 3 decorator transforms to store class metadata.
|
|
40
16
|
*
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
46
|
-
* onto `context.metadata` — same timing as {@link constructorMetadataMap}.
|
|
17
|
+
* `Symbol.metadata` is defined natively once the runtime ships the full TC39 decorator
|
|
18
|
+
* proposal. Until then (current Node.js / browsers), Babel and esbuild both fall back to
|
|
19
|
+
* `Symbol.for("Symbol.metadata")` — a global-registry symbol with the same string key.
|
|
20
|
+
* Resolving it here once keeps the reader and the decorator transforms in sync regardless
|
|
21
|
+
* of which path is taken.
|
|
47
22
|
*
|
|
48
23
|
* @since 0.3.16-canary.0
|
|
49
24
|
*/
|
|
50
|
-
declare const
|
|
25
|
+
declare const METADATA_SYMBOL: symbol;
|
|
51
26
|
//#endregion
|
|
52
|
-
export {
|
|
27
|
+
export { INJECTABLE_KEY, INJECT_ACCESSOR_KEY, LIFECYCLE_KEY, METADATA_SYMBOL };
|
|
@@ -12,29 +12,16 @@ const LIFECYCLE_KEY = Symbol("di:lifecycle");
|
|
|
12
12
|
*/
|
|
13
13
|
const INJECT_ACCESSOR_KEY = Symbol("di:inject-accessor");
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
const constructorMetadataMap = /* @__PURE__ */ new WeakMap();
|
|
18
|
-
/**
|
|
19
|
-
* @since 0.3.16-canary.0
|
|
20
|
-
*/
|
|
21
|
-
const lifecycleMetadataMap = /* @__PURE__ */ new WeakMap();
|
|
22
|
-
/**
|
|
23
|
-
* @since 0.3.16-canary.0
|
|
24
|
-
*/
|
|
25
|
-
const lifecycleByConstructorMetadataMap = /* @__PURE__ */ new WeakMap();
|
|
26
|
-
/**
|
|
27
|
-
* Fallback keyed by the class metadata object (`context.metadata` / `ctor[Symbol.metadata]`).
|
|
15
|
+
* The well-known symbol used by TC39 Stage 3 decorator transforms to store class metadata.
|
|
28
16
|
*
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
* onto `context.metadata` — same timing as {@link constructorMetadataMap}.
|
|
17
|
+
* `Symbol.metadata` is defined natively once the runtime ships the full TC39 decorator
|
|
18
|
+
* proposal. Until then (current Node.js / browsers), Babel and esbuild both fall back to
|
|
19
|
+
* `Symbol.for("Symbol.metadata")` — a global-registry symbol with the same string key.
|
|
20
|
+
* Resolving it here once keeps the reader and the decorator transforms in sync regardless
|
|
21
|
+
* of which path is taken.
|
|
35
22
|
*
|
|
36
23
|
* @since 0.3.16-canary.0
|
|
37
24
|
*/
|
|
38
|
-
const
|
|
25
|
+
const METADATA_SYMBOL = Symbol.metadata ?? Symbol.for("Symbol.metadata");
|
|
39
26
|
//#endregion
|
|
40
|
-
export { INJECTABLE_KEY, INJECT_ACCESSOR_KEY, LIFECYCLE_KEY,
|
|
27
|
+
export { INJECTABLE_KEY, INJECT_ACCESSOR_KEY, LIFECYCLE_KEY, METADATA_SYMBOL };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Constructor } from "../constructor-type.mjs";
|
|
2
2
|
import { Token } from "../token.mjs";
|
|
3
|
+
import { InjectionDescriptor } from "../decorators/inject.mjs";
|
|
3
4
|
|
|
4
5
|
//#region src/metadata/metadata-types.d.ts
|
|
5
6
|
/**
|
|
@@ -41,6 +42,10 @@ interface MutableLifecycleMetadata {
|
|
|
41
42
|
interface MetadataReader {
|
|
42
43
|
getConstructorMetadata(target: Constructor): ConstructorMetadata | undefined;
|
|
43
44
|
getLifecycleMetadata(target: Constructor): LifecycleMetadata | undefined;
|
|
45
|
+
getAccessorMetadata?(target: Constructor): ReadonlyArray<{
|
|
46
|
+
readonly key: string | symbol;
|
|
47
|
+
readonly descriptor: InjectionDescriptor;
|
|
48
|
+
}> | undefined;
|
|
44
49
|
}
|
|
45
50
|
//#endregion
|
|
46
51
|
export { ConstructorMetadata, LifecycleMetadata, MetadataReader, MutableLifecycleMetadata, ParamMetadata };
|
|
@@ -7,6 +7,7 @@ import { ConstructorMetadata, LifecycleMetadata, MetadataReader } from "./metada
|
|
|
7
7
|
* @since 0.3.16-canary.0
|
|
8
8
|
*/
|
|
9
9
|
declare class SymbolMetadataReader implements MetadataReader {
|
|
10
|
+
private _getMetadataRecord;
|
|
10
11
|
getConstructorMetadata(target: Constructor): ConstructorMetadata | undefined;
|
|
11
12
|
getLifecycleMetadata(target: Constructor): LifecycleMetadata | undefined;
|
|
12
13
|
getAccessorMetadata(target: Constructor): Array<{
|
|
@@ -1,46 +1,24 @@
|
|
|
1
|
-
import { INJECTABLE_KEY, INJECT_ACCESSOR_KEY, LIFECYCLE_KEY,
|
|
1
|
+
import { INJECTABLE_KEY, INJECT_ACCESSOR_KEY, LIFECYCLE_KEY, METADATA_SYMBOL } from "./metadata-keys.mjs";
|
|
2
2
|
//#region src/metadata/symbol-metadata-reader.ts
|
|
3
3
|
/**
|
|
4
4
|
* @since 0.3.16-canary.0
|
|
5
5
|
*/
|
|
6
6
|
var SymbolMetadataReader = class {
|
|
7
|
+
_getMetadataRecord(target, key) {
|
|
8
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, METADATA_SYMBOL);
|
|
9
|
+
if (descriptor === void 0) return;
|
|
10
|
+
const record = descriptor.value;
|
|
11
|
+
if (!record || typeof record !== "object" || !Object.hasOwn(record, key)) return;
|
|
12
|
+
return record;
|
|
13
|
+
}
|
|
7
14
|
getConstructorMetadata(target) {
|
|
8
|
-
|
|
9
|
-
if (weakMapMetadata !== void 0) return weakMapMetadata;
|
|
10
|
-
const metadataDescriptor = Object.getOwnPropertyDescriptor(target, Symbol.metadata);
|
|
11
|
-
if (metadataDescriptor === void 0) return;
|
|
12
|
-
const metadataRecord = metadataDescriptor.value;
|
|
13
|
-
if (!metadataRecord || typeof metadataRecord !== "object" || !Object.hasOwn(metadataRecord, INJECTABLE_KEY)) return;
|
|
14
|
-
return metadataRecord[INJECTABLE_KEY];
|
|
15
|
+
return this._getMetadataRecord(target, INJECTABLE_KEY)?.[INJECTABLE_KEY];
|
|
15
16
|
}
|
|
16
17
|
getLifecycleMetadata(target) {
|
|
17
|
-
|
|
18
|
-
if (lifecycleMetadataByConstructor !== void 0) return lifecycleMetadataByConstructor;
|
|
19
|
-
const metadataDescriptor = Object.getOwnPropertyDescriptor(target, Symbol.metadata);
|
|
20
|
-
if (metadataDescriptor !== void 0) {
|
|
21
|
-
const metadataRecord = metadataDescriptor.value;
|
|
22
|
-
if (metadataRecord && typeof metadataRecord === "object" && Object.hasOwn(metadataRecord, LIFECYCLE_KEY)) return metadataRecord[LIFECYCLE_KEY];
|
|
23
|
-
}
|
|
24
|
-
const classMetadataObject = target[Symbol.metadata];
|
|
25
|
-
if (classMetadataObject !== void 0) {
|
|
26
|
-
const weakMapMetadata = lifecycleMetadataMap.get(classMetadataObject);
|
|
27
|
-
if (weakMapMetadata !== void 0) return weakMapMetadata;
|
|
28
|
-
}
|
|
18
|
+
return this._getMetadataRecord(target, LIFECYCLE_KEY)?.[LIFECYCLE_KEY];
|
|
29
19
|
}
|
|
30
20
|
getAccessorMetadata(target) {
|
|
31
|
-
|
|
32
|
-
if (byConstructor !== void 0) return byConstructor;
|
|
33
|
-
const metadataObject = target[Symbol.metadata];
|
|
34
|
-
if (metadataObject !== void 0) {
|
|
35
|
-
const fromWeakMap = accessorMetadataByMetadataObjectMap.get(metadataObject);
|
|
36
|
-
if (fromWeakMap !== void 0) return fromWeakMap;
|
|
37
|
-
}
|
|
38
|
-
const metadataDescriptor = Object.getOwnPropertyDescriptor(target, Symbol.metadata);
|
|
39
|
-
if (metadataDescriptor === void 0) return;
|
|
40
|
-
const metadataRecord = metadataDescriptor.value;
|
|
41
|
-
if (!metadataRecord || typeof metadataRecord !== "object") return;
|
|
42
|
-
if (!Object.hasOwn(metadataRecord, INJECT_ACCESSOR_KEY)) return;
|
|
43
|
-
return metadataRecord[INJECT_ACCESSOR_KEY];
|
|
21
|
+
return this._getMetadataRecord(target, INJECT_ACCESSOR_KEY)?.[INJECT_ACCESSOR_KEY];
|
|
44
22
|
}
|
|
45
23
|
};
|
|
46
24
|
/**
|
package/dist/module.d.mts
CHANGED
|
@@ -57,6 +57,6 @@ declare const Module: {
|
|
|
57
57
|
/**
|
|
58
58
|
* @since 0.3.16-canary.0
|
|
59
59
|
*/
|
|
60
|
-
declare function isSyncModule(
|
|
60
|
+
declare function isSyncModule(module: SyncModule | AsyncModule): module is SyncModule;
|
|
61
61
|
//#endregion
|
|
62
62
|
export { AsyncModule, AsyncModuleBuilder, Module, ModuleBuilder, SyncModule, isSyncModule };
|
package/dist/module.mjs
CHANGED
|
@@ -35,8 +35,8 @@ const Module = {
|
|
|
35
35
|
/**
|
|
36
36
|
* @since 0.3.16-canary.0
|
|
37
37
|
*/
|
|
38
|
-
function isSyncModule(
|
|
39
|
-
return
|
|
38
|
+
function isSyncModule(module) {
|
|
39
|
+
return module[SYNC_MODULE_BRAND] === true;
|
|
40
40
|
}
|
|
41
41
|
//#endregion
|
|
42
42
|
export { AsyncModule, Module, SyncModule, isSyncModule };
|
package/dist/registry.d.mts
CHANGED
|
@@ -16,15 +16,15 @@ declare class BindingRegistry {
|
|
|
16
16
|
/** Add or replace binding using slot-aware last-wins. */
|
|
17
17
|
add(binding: Binding): void;
|
|
18
18
|
/** Remove all bindings for a token. Returns removed bindings. */
|
|
19
|
-
removeByToken(
|
|
19
|
+
removeByToken(token: Token<unknown> | Constructor): Array<Binding>;
|
|
20
20
|
/** Remove a specific binding by ID. Returns the removed binding or undefined. */
|
|
21
21
|
removeById(id: BindingIdentifier): Binding | undefined;
|
|
22
22
|
/** Get all bindings for a token. */
|
|
23
|
-
getAll(
|
|
23
|
+
getAll(token: Token<unknown> | Constructor): ReadonlyArray<Binding>;
|
|
24
24
|
/** Get binding by ID. */
|
|
25
25
|
getById(id: BindingIdentifier): Binding | undefined;
|
|
26
26
|
/** Check if any binding exists for token. */
|
|
27
|
-
has(
|
|
27
|
+
has(token: Token<unknown> | Constructor): boolean;
|
|
28
28
|
/** All bindings in the registry. */
|
|
29
29
|
allBindings(): ReadonlyArray<Binding>;
|
|
30
30
|
/** Remove all bindings. Returns all removed. */
|
|
@@ -33,7 +33,7 @@ declare class BindingRegistry {
|
|
|
33
33
|
getSimpleTagged(token: Token<unknown> | Constructor, tagKey: string, tagValue: unknown): Binding | undefined;
|
|
34
34
|
getFastDefault(token: Token<unknown> | Constructor): Binding | undefined;
|
|
35
35
|
/** Summarize available slot strings for a token (for error messages). */
|
|
36
|
-
availableSlotStrings(
|
|
36
|
+
availableSlotStrings(token: Token<unknown> | Constructor): Array<string>;
|
|
37
37
|
private _indexSimpleTaggedBinding;
|
|
38
38
|
private _deindexSimpleTaggedBinding;
|
|
39
39
|
private _isPurePredicateBinding;
|
package/dist/registry.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bindingSlotEquals, bindingSlotToString } from "./binding.mjs";
|
|
2
2
|
//#region src/registry.ts
|
|
3
3
|
/**
|
|
4
4
|
* @since 0.3.16-canary.0
|
|
@@ -12,13 +12,9 @@ var BindingRegistry = class {
|
|
|
12
12
|
/** Add or replace binding using slot-aware last-wins. */
|
|
13
13
|
add(binding) {
|
|
14
14
|
const key = binding.token;
|
|
15
|
-
|
|
16
|
-
if (bindingsForToken === void 0) {
|
|
17
|
-
bindingsForToken = [];
|
|
18
|
-
this._bindings.set(key, bindingsForToken);
|
|
19
|
-
}
|
|
15
|
+
const bindingsForToken = this._bindings.getOrInsert(key, []);
|
|
20
16
|
if (!this._isPurePredicateBinding(binding)) {
|
|
21
|
-
const existingIndex = bindingsForToken.findIndex((
|
|
17
|
+
const existingIndex = bindingsForToken.findIndex((candidate) => !this._isPurePredicateBinding(candidate) && bindingSlotEquals(candidate.slot, binding.slot));
|
|
22
18
|
if (existingIndex !== -1) {
|
|
23
19
|
const replacedBinding = bindingsForToken[existingIndex];
|
|
24
20
|
this._byId.delete(replacedBinding.id);
|
|
@@ -32,8 +28,8 @@ var BindingRegistry = class {
|
|
|
32
28
|
this._refreshFastDefaultForToken(key);
|
|
33
29
|
}
|
|
34
30
|
/** Remove all bindings for a token. Returns removed bindings. */
|
|
35
|
-
removeByToken(
|
|
36
|
-
const key =
|
|
31
|
+
removeByToken(token) {
|
|
32
|
+
const key = token;
|
|
37
33
|
const bindingsForToken = this._bindings.get(key) ?? [];
|
|
38
34
|
this._bindings.delete(key);
|
|
39
35
|
this._simpleNamed.delete(key);
|
|
@@ -64,16 +60,16 @@ var BindingRegistry = class {
|
|
|
64
60
|
return binding;
|
|
65
61
|
}
|
|
66
62
|
/** Get all bindings for a token. */
|
|
67
|
-
getAll(
|
|
68
|
-
return this._bindings.get(
|
|
63
|
+
getAll(token) {
|
|
64
|
+
return this._bindings.get(token) ?? [];
|
|
69
65
|
}
|
|
70
66
|
/** Get binding by ID. */
|
|
71
67
|
getById(id) {
|
|
72
68
|
return this._byId.get(id);
|
|
73
69
|
}
|
|
74
70
|
/** Check if any binding exists for token. */
|
|
75
|
-
has(
|
|
76
|
-
const key =
|
|
71
|
+
has(token) {
|
|
72
|
+
const key = token;
|
|
77
73
|
const list = this._bindings.get(key);
|
|
78
74
|
return list !== void 0 && list.length > 0;
|
|
79
75
|
}
|
|
@@ -103,30 +99,20 @@ var BindingRegistry = class {
|
|
|
103
99
|
return this._fastDefault.get(token);
|
|
104
100
|
}
|
|
105
101
|
/** Summarize available slot strings for a token (for error messages). */
|
|
106
|
-
availableSlotStrings(
|
|
107
|
-
return (this._bindings.get(
|
|
102
|
+
availableSlotStrings(token) {
|
|
103
|
+
return (this._bindings.get(token) ?? []).map((binding) => bindingSlotToString(binding.slot));
|
|
108
104
|
}
|
|
109
|
-
_indexSimpleTaggedBinding(
|
|
105
|
+
_indexSimpleTaggedBinding(tokenKey, binding) {
|
|
110
106
|
const slot = binding.slot;
|
|
111
107
|
if (slot.name !== void 0 || slot.tags.length !== 1 || binding.predicate !== void 0) return;
|
|
112
108
|
const [tagKey, tagValue] = slot.tags[0];
|
|
113
|
-
|
|
114
|
-
if (byTagKey === void 0) {
|
|
115
|
-
byTagKey = /* @__PURE__ */ new Map();
|
|
116
|
-
this._simpleTagged.set(tokenKeyValue, byTagKey);
|
|
117
|
-
}
|
|
118
|
-
let byTagValue = byTagKey.get(tagKey);
|
|
119
|
-
if (byTagValue === void 0) {
|
|
120
|
-
byTagValue = /* @__PURE__ */ new Map();
|
|
121
|
-
byTagKey.set(tagKey, byTagValue);
|
|
122
|
-
}
|
|
123
|
-
byTagValue.set(tagValue, binding);
|
|
109
|
+
this._simpleTagged.getOrInsert(tokenKey, /* @__PURE__ */ new Map()).getOrInsert(tagKey, /* @__PURE__ */ new Map()).set(tagValue, binding);
|
|
124
110
|
}
|
|
125
|
-
_deindexSimpleTaggedBinding(
|
|
111
|
+
_deindexSimpleTaggedBinding(tokenKey, binding) {
|
|
126
112
|
const slot = binding.slot;
|
|
127
113
|
if (slot.name !== void 0 || slot.tags.length !== 1 || binding.predicate !== void 0) return;
|
|
128
114
|
const [tagKey, tagValue] = slot.tags[0];
|
|
129
|
-
const byTagKey = this._simpleTagged.get(
|
|
115
|
+
const byTagKey = this._simpleTagged.get(tokenKey);
|
|
130
116
|
if (byTagKey === void 0) return;
|
|
131
117
|
const byTagValue = byTagKey.get(tagKey);
|
|
132
118
|
if (byTagValue === void 0) return;
|
|
@@ -134,7 +120,7 @@ var BindingRegistry = class {
|
|
|
134
120
|
byTagValue.delete(tagValue);
|
|
135
121
|
if (byTagValue.size === 0) {
|
|
136
122
|
byTagKey.delete(tagKey);
|
|
137
|
-
if (byTagKey.size === 0) this._simpleTagged.delete(
|
|
123
|
+
if (byTagKey.size === 0) this._simpleTagged.delete(tokenKey);
|
|
138
124
|
}
|
|
139
125
|
}
|
|
140
126
|
}
|
|
@@ -144,38 +130,33 @@ var BindingRegistry = class {
|
|
|
144
130
|
const hasConstraint = slot.name !== void 0 || slot.tags.length > 0;
|
|
145
131
|
return hasPredicate && !hasConstraint;
|
|
146
132
|
}
|
|
147
|
-
_indexSimpleNamedBinding(
|
|
133
|
+
_indexSimpleNamedBinding(tokenKey, binding) {
|
|
148
134
|
const slot = binding.slot;
|
|
149
135
|
if (slot.name === void 0 || slot.tags.length > 0) return;
|
|
150
|
-
|
|
151
|
-
if (bindingsByName === void 0) {
|
|
152
|
-
bindingsByName = /* @__PURE__ */ new Map();
|
|
153
|
-
this._simpleNamed.set(tokenKeyValue, bindingsByName);
|
|
154
|
-
}
|
|
155
|
-
bindingsByName.set(slot.name, binding);
|
|
136
|
+
this._simpleNamed.getOrInsert(tokenKey, /* @__PURE__ */ new Map()).set(slot.name, binding);
|
|
156
137
|
}
|
|
157
|
-
_deindexSimpleNamedBinding(
|
|
138
|
+
_deindexSimpleNamedBinding(tokenKey, binding) {
|
|
158
139
|
const slot = binding.slot;
|
|
159
140
|
if (slot.name === void 0 || slot.tags.length > 0) return;
|
|
160
|
-
const bindingsByName = this._simpleNamed.get(
|
|
141
|
+
const bindingsByName = this._simpleNamed.get(tokenKey);
|
|
161
142
|
if (bindingsByName === void 0) return;
|
|
162
143
|
if (bindingsByName.get(slot.name)?.id === binding.id) {
|
|
163
144
|
bindingsByName.delete(slot.name);
|
|
164
|
-
if (bindingsByName.size === 0) this._simpleNamed.delete(
|
|
145
|
+
if (bindingsByName.size === 0) this._simpleNamed.delete(tokenKey);
|
|
165
146
|
}
|
|
166
147
|
}
|
|
167
|
-
_refreshFastDefaultForToken(
|
|
168
|
-
const bindingsForToken = this._bindings.get(
|
|
148
|
+
_refreshFastDefaultForToken(tokenKey) {
|
|
149
|
+
const bindingsForToken = this._bindings.get(tokenKey);
|
|
169
150
|
if (bindingsForToken === void 0 || bindingsForToken.length !== 1) {
|
|
170
|
-
this._fastDefault.delete(
|
|
151
|
+
this._fastDefault.delete(tokenKey);
|
|
171
152
|
return;
|
|
172
153
|
}
|
|
173
154
|
const onlyBinding = bindingsForToken[0];
|
|
174
155
|
if (!(onlyBinding.slot.name === void 0 && onlyBinding.slot.tags.length === 0) || onlyBinding.predicate !== void 0) {
|
|
175
|
-
this._fastDefault.delete(
|
|
156
|
+
this._fastDefault.delete(tokenKey);
|
|
176
157
|
return;
|
|
177
158
|
}
|
|
178
|
-
this._fastDefault.set(
|
|
159
|
+
this._fastDefault.set(tokenKey, onlyBinding);
|
|
179
160
|
}
|
|
180
161
|
};
|
|
181
162
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ResolveOptions } from "./types.mjs";
|
|
2
|
-
import {
|
|
1
|
+
import { BindingTag, ResolveOptions } from "./types.mjs";
|
|
2
|
+
import { BindingSlot } from "./binding.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/resolve-options.d.ts
|
|
5
5
|
/**
|
|
@@ -8,15 +8,15 @@ import { SlotKey } from "./binding.mjs";
|
|
|
8
8
|
*
|
|
9
9
|
* @since 0.3.16-canary.0
|
|
10
10
|
*/
|
|
11
|
-
declare function
|
|
11
|
+
declare function injectionSlotToResolveOptions(injectionSlot: {
|
|
12
12
|
readonly name?: string;
|
|
13
|
-
readonly tags?: ReadonlyArray<
|
|
13
|
+
readonly tags?: ReadonlyArray<BindingTag>;
|
|
14
14
|
}): ResolveOptions | undefined;
|
|
15
15
|
/**
|
|
16
|
-
* Hint from a binding {@link
|
|
16
|
+
* Hint from a binding {@link BindingSlot} (tags may be empty; omits when nothing to match).
|
|
17
17
|
*
|
|
18
18
|
* @since 0.3.16-canary.0
|
|
19
19
|
*/
|
|
20
|
-
declare function
|
|
20
|
+
declare function bindingSlotToResolveOptions(bindingSlot: BindingSlot): ResolveOptions | undefined;
|
|
21
21
|
//#endregion
|
|
22
|
-
export {
|
|
22
|
+
export { bindingSlotToResolveOptions, injectionSlotToResolveOptions };
|
package/dist/resolve-options.mjs
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
//#region src/resolve-options.ts
|
|
2
|
+
/** Shared core: build a ResolveOptions from already-normalised name + tags. */
|
|
3
|
+
function buildOptions(name, tags) {
|
|
4
|
+
if (name === void 0 && tags === void 0) return;
|
|
5
|
+
const options = {};
|
|
6
|
+
if (name !== void 0) options.name = name;
|
|
7
|
+
if (tags !== void 0) options.tags = tags;
|
|
8
|
+
return options;
|
|
9
|
+
}
|
|
2
10
|
/**
|
|
3
11
|
* Builds a {@link ResolveOptions} safe for `exactOptionalPropertyTypes`:
|
|
4
12
|
* omits keys instead of assigning `undefined`.
|
|
5
13
|
*
|
|
6
14
|
* @since 0.3.16-canary.0
|
|
7
15
|
*/
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
if (slot.name !== void 0) options.name = slot.name;
|
|
11
|
-
if (slot.tags !== void 0) options.tags = slot.tags;
|
|
12
|
-
return options.name !== void 0 || options.tags !== void 0 ? options : void 0;
|
|
16
|
+
function injectionSlotToResolveOptions(injectionSlot) {
|
|
17
|
+
return buildOptions(injectionSlot.name, injectionSlot.tags);
|
|
13
18
|
}
|
|
14
19
|
/**
|
|
15
|
-
* Hint from a binding {@link
|
|
20
|
+
* Hint from a binding {@link BindingSlot} (tags may be empty; omits when nothing to match).
|
|
16
21
|
*
|
|
17
22
|
* @since 0.3.16-canary.0
|
|
18
23
|
*/
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
if (slot.name !== void 0) options.name = slot.name;
|
|
22
|
-
if (slot.tags.length > 0) options.tags = slot.tags;
|
|
23
|
-
return options.name !== void 0 || options.tags !== void 0 ? options : void 0;
|
|
24
|
+
function bindingSlotToResolveOptions(bindingSlot) {
|
|
25
|
+
return buildOptions(bindingSlot.name, bindingSlot.tags.length > 0 ? bindingSlot.tags : void 0);
|
|
24
26
|
}
|
|
25
27
|
//#endregion
|
|
26
|
-
export {
|
|
28
|
+
export { bindingSlotToResolveOptions, injectionSlotToResolveOptions };
|
package/dist/resolver.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Constructor } from "./constructor-type.mjs";
|
|
2
2
|
import { Token } from "./token.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { ResolutionFrame, ResolveOptions } from "./types.mjs";
|
|
4
4
|
import { Binding } from "./binding.mjs";
|
|
5
5
|
import { BindingRegistry } from "./registry.mjs";
|
|
6
6
|
import { ScopeManager } from "./scope.mjs";
|
|
@@ -47,22 +47,22 @@ declare class DependencyResolver {
|
|
|
47
47
|
* Mirrors {@link DependencyResolver.resolveAll} candidate selection only (no instantiation).
|
|
48
48
|
*/
|
|
49
49
|
peekCandidateBindingsForValidate(token: Token<unknown> | Constructor, hint: ResolveOptions | undefined): Array<Binding>;
|
|
50
|
-
resolveFromContext<const Value>(token: Token<Value> | Constructor<Value>, resolutionPath: Array<string>,
|
|
51
|
-
resolve<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>,
|
|
50
|
+
resolveFromContext<const Value>(token: Token<Value> | Constructor<Value>, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Value;
|
|
51
|
+
resolve<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Value;
|
|
52
52
|
private _resolveBinding;
|
|
53
53
|
private _instantiateSync;
|
|
54
54
|
private _resolveClassDeps;
|
|
55
55
|
private _resolveDescriptorDeps;
|
|
56
|
-
resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>,
|
|
57
|
-
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>,
|
|
58
|
-
resolveAsyncFromContext<const Value>(token: Token<Value> | Constructor<Value>, resolutionPath: Array<string>,
|
|
59
|
-
resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>,
|
|
56
|
+
resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Value | undefined;
|
|
57
|
+
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Array<Value>;
|
|
58
|
+
resolveAsyncFromContext<const Value>(token: Token<Value> | Constructor<Value>, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Value>;
|
|
59
|
+
resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Value>;
|
|
60
60
|
private _resolveBindingAsync;
|
|
61
61
|
private _instantiateAsync;
|
|
62
62
|
private _resolveClassDepsAsync;
|
|
63
63
|
private _resolveDescriptorDepsAsync;
|
|
64
|
-
resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>,
|
|
65
|
-
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>,
|
|
64
|
+
resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Value | undefined>;
|
|
65
|
+
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Array<Value>>;
|
|
66
66
|
private _getAllBindingsFromChain;
|
|
67
67
|
private _getSimpleNamedBindingsFromChain;
|
|
68
68
|
private _getAvailableSlots;
|
|
@@ -79,9 +79,14 @@ declare class DependencyResolver {
|
|
|
79
79
|
private _resolveTransientDynamicAsyncSlow;
|
|
80
80
|
private _resolveCandidateSync;
|
|
81
81
|
private _resolveCandidateAsync;
|
|
82
|
-
private
|
|
82
|
+
private _getResolutionFrame;
|
|
83
83
|
private _needsActivation;
|
|
84
84
|
private _refreshClassPostConstructCache;
|
|
85
|
+
/**
|
|
86
|
+
* Refreshes the post-construct cache for class bindings on first instantiation and
|
|
87
|
+
* returns the (possibly updated) shouldActivate flag.
|
|
88
|
+
*/
|
|
89
|
+
private _refreshActivationCacheIfNeeded;
|
|
85
90
|
private _requiresResolutionContext;
|
|
86
91
|
private _acquireSyncResolutionContext;
|
|
87
92
|
}
|