@codefast/di 0.3.16-canary.0 → 0.3.16-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +4 -1
- package/dist/binding-select.d.mts +2 -2
- package/dist/binding.d.mts +6 -6
- package/dist/constraints.d.mts +25 -9
- package/dist/constraints.mjs +47 -19
- package/dist/constructor-type.d.mts +2 -2
- package/dist/container.d.mts +6 -6
- package/dist/container.mjs +136 -55
- package/dist/decorators/inject.d.mts +3 -3
- package/dist/decorators/inject.mjs +13 -11
- package/dist/decorators/injectable.d.mts +1 -1
- package/dist/decorators/injectable.mjs +18 -14
- package/dist/decorators/lifecycle-decorators.mjs +3 -0
- package/dist/dependency-graph.d.mts +2 -2
- package/dist/environment.d.mts +12 -12
- package/dist/errors.d.mts +18 -8
- package/dist/errors.mjs +17 -1
- package/dist/graph-adapters/reactflow.d.mts +2 -2
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +4 -3
- package/dist/inspector.d.mts +2 -3
- package/dist/inspector.mjs +5 -3
- package/dist/lifecycle.d.mts +5 -6
- package/dist/lifecycle.mjs +45 -52
- package/dist/metadata/metadata-keys.d.mts +24 -1
- package/dist/metadata/metadata-keys.mjs +14 -1
- package/dist/metadata/metadata-types.d.mts +5 -5
- package/dist/metadata/symbol-metadata-reader.mjs +31 -24
- package/dist/module.d.mts +1 -1
- package/dist/registry.d.mts +5 -5
- package/dist/registry.mjs +35 -42
- package/dist/resolver.d.mts +20 -8
- package/dist/resolver.mjs +64 -43
- package/dist/types.d.mts +9 -5
- package/package.json +11 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MissingContainerContextError } from "../errors.mjs";
|
|
1
|
+
import { InternalError, MissingContainerContextError } from "../errors.mjs";
|
|
2
2
|
import { getActiveContainer } from "../environment.mjs";
|
|
3
3
|
import { injectableSlotToResolveOptions } from "../resolve-options.mjs";
|
|
4
|
-
import { INJECT_ACCESSOR_KEY } from "../metadata/metadata-keys.mjs";
|
|
4
|
+
import { INJECT_ACCESSOR_KEY, accessorMetadataByMetadataObjectMap } from "../metadata/metadata-keys.mjs";
|
|
5
5
|
//#region src/decorators/inject.ts
|
|
6
6
|
/**
|
|
7
7
|
* @since 0.3.16-canary.0
|
|
@@ -54,9 +54,9 @@ function materializeInjectionDescriptor(dep) {
|
|
|
54
54
|
};
|
|
55
55
|
return base;
|
|
56
56
|
}
|
|
57
|
-
function buildInjectionDescriptor(
|
|
57
|
+
function buildInjectionDescriptor(token, options) {
|
|
58
58
|
const base = {
|
|
59
|
-
token
|
|
59
|
+
token,
|
|
60
60
|
optional: false,
|
|
61
61
|
multi: false
|
|
62
62
|
};
|
|
@@ -78,15 +78,17 @@ function buildInjectionDescriptor(t, options) {
|
|
|
78
78
|
/**
|
|
79
79
|
* @since 0.3.16-canary.0
|
|
80
80
|
*/
|
|
81
|
-
function inject(
|
|
82
|
-
const descriptor = buildInjectionDescriptor(
|
|
81
|
+
function inject(token, options) {
|
|
82
|
+
const descriptor = buildInjectionDescriptor(token, options);
|
|
83
83
|
const decoratorFn = (_target, context) => {
|
|
84
|
+
if (context.static === true) throw new InternalError("@inject() on static accessors is not supported; only instance accessors participate in runWithContainer-based property injection.");
|
|
84
85
|
const meta = context.metadata;
|
|
85
86
|
if (!Array.isArray(meta[INJECT_ACCESSOR_KEY])) meta[INJECT_ACCESSOR_KEY] = [];
|
|
86
87
|
meta[INJECT_ACCESSOR_KEY].push({
|
|
87
88
|
key: context.name,
|
|
88
89
|
descriptor
|
|
89
90
|
});
|
|
91
|
+
accessorMetadataByMetadataObjectMap.set(context.metadata, meta[INJECT_ACCESSOR_KEY]);
|
|
90
92
|
context.addInitializer(function() {
|
|
91
93
|
const container = getActiveContainer();
|
|
92
94
|
if (container === void 0) throw new MissingContainerContextError(String(context.name));
|
|
@@ -94,7 +96,7 @@ function inject(t, options) {
|
|
|
94
96
|
...options.name !== void 0 ? { name: options.name } : {},
|
|
95
97
|
...options.tags !== void 0 ? { tags: options.tags } : {}
|
|
96
98
|
});
|
|
97
|
-
const value = descriptor.optional ? container.resolveOptional(
|
|
99
|
+
const value = descriptor.optional ? container.resolveOptional(token, hint) : container.resolve(token, hint);
|
|
98
100
|
context.access.set(this, value);
|
|
99
101
|
});
|
|
100
102
|
return {};
|
|
@@ -112,9 +114,9 @@ function inject(t, options) {
|
|
|
112
114
|
/**
|
|
113
115
|
* @since 0.3.16-canary.0
|
|
114
116
|
*/
|
|
115
|
-
function optional(
|
|
117
|
+
function optional(token, options) {
|
|
116
118
|
const base = {
|
|
117
|
-
token
|
|
119
|
+
token,
|
|
118
120
|
optional: true,
|
|
119
121
|
multi: false
|
|
120
122
|
};
|
|
@@ -136,9 +138,9 @@ function optional(t, options) {
|
|
|
136
138
|
/**
|
|
137
139
|
* @since 0.3.16-canary.0
|
|
138
140
|
*/
|
|
139
|
-
function injectAll(
|
|
141
|
+
function injectAll(token, options) {
|
|
140
142
|
const base = {
|
|
141
|
-
token
|
|
143
|
+
token,
|
|
142
144
|
optional: false,
|
|
143
145
|
multi: true
|
|
144
146
|
};
|
|
@@ -27,6 +27,6 @@ interface InjectableOptions {
|
|
|
27
27
|
/**
|
|
28
28
|
* @since 0.3.16-canary.0
|
|
29
29
|
*/
|
|
30
|
-
declare function injectable(deps?:
|
|
30
|
+
declare function injectable(deps?: ReadonlyArray<InjectableDependency>, options?: InjectableOptions): (target: unknown, context: ClassDecoratorContext) => void;
|
|
31
31
|
//#endregion
|
|
32
32
|
export { AutoRegisterRegistry, type InjectableDependency, InjectableOptions, createAutoRegisterRegistry, injectable };
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { INJECTABLE_KEY, constructorMetadataMap } from "../metadata/metadata-keys.mjs";
|
|
1
|
+
import { INJECTABLE_KEY, INJECT_ACCESSOR_KEY, accessorMetadataByConstructorMap, constructorMetadataMap } from "../metadata/metadata-keys.mjs";
|
|
2
2
|
import { normalizeToDescriptor } from "./inject.mjs";
|
|
3
3
|
//#region src/decorators/injectable.ts
|
|
4
4
|
/**
|
|
5
5
|
* @since 0.3.16-canary.0
|
|
6
6
|
*/
|
|
7
7
|
function createAutoRegisterRegistry() {
|
|
8
|
-
const
|
|
8
|
+
const _registeredEntries = [];
|
|
9
9
|
return {
|
|
10
10
|
register(target, scope) {
|
|
11
|
-
|
|
11
|
+
_registeredEntries.push({
|
|
12
12
|
target,
|
|
13
13
|
scope
|
|
14
14
|
});
|
|
15
15
|
},
|
|
16
16
|
entries() {
|
|
17
|
-
return
|
|
17
|
+
return _registeredEntries;
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
}
|
|
@@ -23,33 +23,37 @@ function createAutoRegisterRegistry() {
|
|
|
23
23
|
*/
|
|
24
24
|
function injectable(deps, options) {
|
|
25
25
|
return function(target, context) {
|
|
26
|
-
const
|
|
27
|
-
const descriptor = normalizeToDescriptor(
|
|
28
|
-
const
|
|
26
|
+
const constructorMetadata = { params: (deps ?? []).map((dependency, index) => {
|
|
27
|
+
const descriptor = normalizeToDescriptor(dependency);
|
|
28
|
+
const baseParameterMetadata = {
|
|
29
29
|
index,
|
|
30
30
|
token: descriptor.token,
|
|
31
31
|
optional: descriptor.optional,
|
|
32
32
|
multi: descriptor.multi
|
|
33
33
|
};
|
|
34
34
|
if (descriptor.name !== void 0 && descriptor.tags !== void 0) return {
|
|
35
|
-
...
|
|
35
|
+
...baseParameterMetadata,
|
|
36
36
|
name: descriptor.name,
|
|
37
37
|
tags: descriptor.tags
|
|
38
38
|
};
|
|
39
39
|
if (descriptor.name !== void 0) return {
|
|
40
|
-
...
|
|
40
|
+
...baseParameterMetadata,
|
|
41
41
|
name: descriptor.name
|
|
42
42
|
};
|
|
43
43
|
if (descriptor.tags !== void 0) return {
|
|
44
|
-
...
|
|
44
|
+
...baseParameterMetadata,
|
|
45
45
|
tags: descriptor.tags
|
|
46
46
|
};
|
|
47
|
-
return
|
|
47
|
+
return baseParameterMetadata;
|
|
48
48
|
}) };
|
|
49
|
-
constructorMetadataMap.set(target,
|
|
49
|
+
constructorMetadataMap.set(target, constructorMetadata);
|
|
50
50
|
try {
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
51
|
+
const metadata = context.metadata;
|
|
52
|
+
if (metadata !== null && typeof metadata === "object") {
|
|
53
|
+
const accessorList = metadata[INJECT_ACCESSOR_KEY];
|
|
54
|
+
if (Array.isArray(accessorList) && accessorList.length > 0) accessorMetadataByConstructorMap.set(target, accessorList);
|
|
55
|
+
metadata[INJECTABLE_KEY] = constructorMetadata;
|
|
56
|
+
}
|
|
53
57
|
} catch {}
|
|
54
58
|
if (options?.autoRegister !== void 0) {
|
|
55
59
|
const scope = options.scope ?? "transient";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InternalError } from "../errors.mjs";
|
|
1
2
|
import { LIFECYCLE_KEY, lifecycleByConstructorMetadataMap, lifecycleMetadataMap } from "../metadata/metadata-keys.mjs";
|
|
2
3
|
//#region src/decorators/lifecycle-decorators.ts
|
|
3
4
|
function appendUniqueMethod(metadata, phase, methodName) {
|
|
@@ -25,6 +26,7 @@ function registerByConstructor(target, phase, methodName) {
|
|
|
25
26
|
*/
|
|
26
27
|
function postConstruct() {
|
|
27
28
|
return function(target, context) {
|
|
29
|
+
if (context.static === true) throw new InternalError("@postConstruct() applies to instance methods only; static methods are not invoked during instance lifecycle.");
|
|
28
30
|
const methodName = String(context.name);
|
|
29
31
|
registerByConstructor(target, "postConstruct", methodName);
|
|
30
32
|
const existing = lifecycleMetadataMap.get(context.metadata);
|
|
@@ -61,6 +63,7 @@ function postConstruct() {
|
|
|
61
63
|
*/
|
|
62
64
|
function preDestroy() {
|
|
63
65
|
return function(target, context) {
|
|
66
|
+
if (context.static === true) throw new InternalError("@preDestroy() applies to instance methods only; static methods are not invoked during instance teardown.");
|
|
64
67
|
const methodName = String(context.name);
|
|
65
68
|
registerByConstructor(target, "preDestroy", methodName);
|
|
66
69
|
const existing = lifecycleMetadataMap.get(context.metadata);
|
|
@@ -25,8 +25,8 @@ interface GraphEdge {
|
|
|
25
25
|
* @since 0.3.16-canary.0
|
|
26
26
|
*/
|
|
27
27
|
interface ContainerGraphJson {
|
|
28
|
-
readonly nodes:
|
|
29
|
-
readonly edges:
|
|
28
|
+
readonly nodes: ReadonlyArray<GraphNode>;
|
|
29
|
+
readonly edges: ReadonlyArray<GraphEdge>;
|
|
30
30
|
readonly includesParent: boolean;
|
|
31
31
|
}
|
|
32
32
|
/**
|
package/dist/environment.d.mts
CHANGED
|
@@ -16,14 +16,14 @@ declare function getActiveContainer(): Container | undefined;
|
|
|
16
16
|
* @since 0.3.16-canary.0
|
|
17
17
|
*/
|
|
18
18
|
interface ResolverCallbacks {
|
|
19
|
-
resolveFromContext<const Value>(token: Token<Value> | Constructor<Value>, path: string
|
|
20
|
-
resolve<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: string
|
|
21
|
-
resolveAsyncFromContext<const Value>(token: Token<Value> | Constructor<Value>, path: string
|
|
22
|
-
resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: string
|
|
23
|
-
resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: string
|
|
24
|
-
resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: string
|
|
25
|
-
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: string
|
|
26
|
-
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: string
|
|
19
|
+
resolveFromContext<const Value>(token: Token<Value> | Constructor<Value>, path: Array<string>, stack: Array<MaterializationFrame>): Value;
|
|
20
|
+
resolve<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: Array<string>, stack: Array<MaterializationFrame>): Value;
|
|
21
|
+
resolveAsyncFromContext<const Value>(token: Token<Value> | Constructor<Value>, path: Array<string>, stack: Array<MaterializationFrame>): Promise<Value>;
|
|
22
|
+
resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: Array<string>, stack: Array<MaterializationFrame>): Promise<Value>;
|
|
23
|
+
resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: Array<string>, stack: Array<MaterializationFrame>): Value | undefined;
|
|
24
|
+
resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: Array<string>, stack: Array<MaterializationFrame>): Promise<Value | undefined>;
|
|
25
|
+
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: Array<string>, stack: Array<MaterializationFrame>): Array<Value>;
|
|
26
|
+
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: Array<string>, stack: Array<MaterializationFrame>): Promise<Array<Value>>;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* @since 0.3.16-canary.0
|
|
@@ -33,16 +33,16 @@ declare class DefaultResolutionContext implements ResolutionContext {
|
|
|
33
33
|
private _resolutionPath;
|
|
34
34
|
private _materializationStack;
|
|
35
35
|
private _currentHint;
|
|
36
|
-
constructor(resolver: ResolverCallbacks, resolutionPath: string
|
|
36
|
+
constructor(resolver: ResolverCallbacks, resolutionPath: Array<string>, materializationStack: Array<MaterializationFrame>, currentHint: ResolveOptions | undefined);
|
|
37
37
|
private _graph;
|
|
38
38
|
get graph(): ConstraintContext;
|
|
39
|
-
reset(resolver: ResolverCallbacks, resolutionPath: string
|
|
39
|
+
reset(resolver: ResolverCallbacks, resolutionPath: Array<string>, materializationStack: Array<MaterializationFrame>, currentHint: ResolveOptions | undefined): void;
|
|
40
40
|
resolve<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Value;
|
|
41
41
|
resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Promise<Value>;
|
|
42
42
|
resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Value | undefined;
|
|
43
43
|
resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Promise<Value | undefined>;
|
|
44
|
-
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Value
|
|
45
|
-
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Promise<Value
|
|
44
|
+
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Array<Value>;
|
|
45
|
+
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Promise<Array<Value>>;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* @since 0.3.16-canary.0
|
package/dist/errors.d.mts
CHANGED
|
@@ -30,8 +30,8 @@ declare class NoMatchingBindingError extends DiError {
|
|
|
30
30
|
readonly code = "NO_MATCHING_BINDING";
|
|
31
31
|
readonly tokenName: string;
|
|
32
32
|
readonly hint: ResolveOptions;
|
|
33
|
-
readonly availableSlots: string
|
|
34
|
-
constructor(tokenName: string, hint: ResolveOptions, availableSlots: string
|
|
33
|
+
readonly availableSlots: Array<string>;
|
|
34
|
+
constructor(tokenName: string, hint: ResolveOptions, availableSlots: Array<string>);
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* @since 0.3.16-canary.0
|
|
@@ -39,16 +39,16 @@ declare class NoMatchingBindingError extends DiError {
|
|
|
39
39
|
declare class AmbiguousBindingError extends DiError {
|
|
40
40
|
readonly code = "AMBIGUOUS_BINDING";
|
|
41
41
|
readonly tokenName: string;
|
|
42
|
-
readonly candidateIds:
|
|
43
|
-
constructor(tokenName: string, candidateIds:
|
|
42
|
+
readonly candidateIds: ReadonlyArray<BindingIdentifier>;
|
|
43
|
+
constructor(tokenName: string, candidateIds: ReadonlyArray<BindingIdentifier>);
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* @since 0.3.16-canary.0
|
|
47
47
|
*/
|
|
48
48
|
declare class CircularDependencyError extends DiError {
|
|
49
49
|
readonly code = "CIRCULAR_DEPENDENCY";
|
|
50
|
-
readonly cycle: string
|
|
51
|
-
constructor(cycle: string
|
|
50
|
+
readonly cycle: Array<string>;
|
|
51
|
+
constructor(cycle: Array<string>);
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* @since 0.3.16-canary.0
|
|
@@ -75,7 +75,7 @@ interface ScopeViolationDetails {
|
|
|
75
75
|
readonly consumerScope: BindingScope;
|
|
76
76
|
readonly dependencyToken: string;
|
|
77
77
|
readonly dependencyScope: BindingScope;
|
|
78
|
-
readonly path: string
|
|
78
|
+
readonly path: Array<string>;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* @since 0.3.16-canary.0
|
|
@@ -139,5 +139,15 @@ declare class DisposedContainerError extends DiError {
|
|
|
139
139
|
readonly code = "DISPOSED_CONTAINER";
|
|
140
140
|
constructor();
|
|
141
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* @since 0.3.16-canary.0
|
|
144
|
+
*/
|
|
145
|
+
declare class AsyncActivationError extends DiError {
|
|
146
|
+
readonly code = "ASYNC_ACTIVATION";
|
|
147
|
+
readonly tokenName: string;
|
|
148
|
+
readonly hookKind: "postConstruct" | "onActivation";
|
|
149
|
+
readonly methodName: string | undefined;
|
|
150
|
+
constructor(tokenName: string, hookKind: "postConstruct" | "onActivation", methodName?: string);
|
|
151
|
+
}
|
|
142
152
|
//#endregion
|
|
143
|
-
export { AmbiguousBindingError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationDetails, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError };
|
|
153
|
+
export { AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationDetails, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError };
|
package/dist/errors.mjs
CHANGED
|
@@ -177,5 +177,21 @@ var DisposedContainerError = class extends DiError {
|
|
|
177
177
|
super("Cannot perform operations on a disposed container.");
|
|
178
178
|
}
|
|
179
179
|
};
|
|
180
|
+
/**
|
|
181
|
+
* @since 0.3.16-canary.0
|
|
182
|
+
*/
|
|
183
|
+
var AsyncActivationError = class extends DiError {
|
|
184
|
+
code = "ASYNC_ACTIVATION";
|
|
185
|
+
tokenName;
|
|
186
|
+
hookKind;
|
|
187
|
+
methodName;
|
|
188
|
+
constructor(tokenName, hookKind, methodName) {
|
|
189
|
+
const detail = hookKind === "postConstruct" ? `@postConstruct method '${methodName ?? ""}' returned a Promise` : `onActivation for '${tokenName}' returned a Promise`;
|
|
190
|
+
super(`${detail}. Use resolveAsync() instead.`);
|
|
191
|
+
this.tokenName = tokenName;
|
|
192
|
+
this.hookKind = hookKind;
|
|
193
|
+
this.methodName = methodName;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
180
196
|
//#endregion
|
|
181
|
-
export { AmbiguousBindingError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError };
|
|
197
|
+
export { AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError };
|
package/dist/index.d.mts
CHANGED
|
@@ -4,14 +4,15 @@ import { ActivationHandler, BindingIdentifier, BindingKind, BindingScope, Constr
|
|
|
4
4
|
import { InjectOptions, InjectableDependency, InjectionDescriptor, inject, injectAll, isInjectionDescriptor, optional } from "./decorators/inject.mjs";
|
|
5
5
|
import { AliasBindingBuilder, BindToBuilder, BindingBuilder, ConstantBindingBuilder, ScopedBindingBuilder, SingletonBindingBuilder, SingletonLifecycleBuilder, TransientBindingBuilder } from "./binding.mjs";
|
|
6
6
|
import { effectiveBindingScope } from "./binding-scope.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import { whenAnyAncestorIs, whenAnyAncestorNamed, whenAnyAncestorTagged, whenAnyAncestorTaggedAll, whenNoAncestorIs, whenNoParentIs, whenParentIs, whenParentNamed, whenParentTagged, whenParentTaggedAll } from "./constraints.mjs";
|
|
8
|
+
import { AsyncModule, AsyncModuleBuilder, Module, ModuleBuilder, SyncModule, isSyncModule } from "./module.mjs";
|
|
8
9
|
import { BindingSnapshot, ContainerSnapshot } from "./inspector.mjs";
|
|
9
10
|
import { MetadataReader, MutableLifecycleMetadata } from "./metadata/metadata-types.mjs";
|
|
10
11
|
import { ContainerGraphJson, GraphEdge, GraphNode, GraphOptions } from "./dependency-graph.mjs";
|
|
11
12
|
import { AutoRegisterRegistry, InjectableOptions, createAutoRegisterRegistry, injectable } from "./decorators/injectable.mjs";
|
|
12
13
|
import { Container, ContainerStatic } from "./container.mjs";
|
|
13
14
|
import { postConstruct, preDestroy } from "./decorators/lifecycle-decorators.mjs";
|
|
14
|
-
import { AmbiguousBindingError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationDetails, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError } from "./errors.mjs";
|
|
15
|
+
import { AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationDetails, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError } from "./errors.mjs";
|
|
15
16
|
import { injectableSlotToResolveOptions, slotKeyToResolveOptions } from "./resolve-options.mjs";
|
|
16
17
|
import { MetadataReaderToken } from "./metadata/metadata-reader-token.mjs";
|
|
17
|
-
export { type ActivationHandler, type AliasBindingBuilder, AmbiguousBindingError, AsyncDeactivationError, AsyncModule, type AsyncModuleBuilder, AsyncModuleLoadError, AsyncResolutionError, type AutoRegisterRegistry, type BindToBuilder, type BindingBuilder, type BindingIdentifier, type BindingKind, type BindingScope, type BindingSnapshot, CircularDependencyError, type ConstantBindingBuilder, type ConstraintContext, type Constructor, Container, type ContainerGraphJson, type Container as ContainerInterface, type ContainerSnapshot, type ContainerStatic, type DeactivationHandler, type DependencyKey, DiError, DisposedContainerError, type GraphEdge, type GraphNode, type GraphOptions, type InjectOptions, type InjectableDependency, type InjectableOptions, type InjectionDescriptor, InternalError, type MaterializationFrame, type MetadataReader, MetadataReaderToken, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, Module, type ModuleBuilder, type MutableLifecycleMetadata, NoMatchingBindingError, RebindUnboundTokenError, type ResolutionContext, type ResolveOptions, type ScopeViolationDetails, ScopeViolationError, type ScopedBindingBuilder, type SingletonBindingBuilder, type SingletonLifecycleBuilder, SyncDisposalNotSupportedError, SyncModule, type Token, TokenNotBoundError, type TokenValue, type TransientBindingBuilder, createAutoRegisterRegistry, effectiveBindingScope, inject, injectAll, injectable, injectableSlotToResolveOptions, isInjectionDescriptor, isToken, optional, postConstruct, preDestroy, slotKeyToResolveOptions, token, tokenName };
|
|
18
|
+
export { type ActivationHandler, type AliasBindingBuilder, AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModule, type AsyncModuleBuilder, AsyncModuleLoadError, AsyncResolutionError, type AutoRegisterRegistry, type BindToBuilder, type BindingBuilder, type BindingIdentifier, type BindingKind, type BindingScope, type BindingSnapshot, CircularDependencyError, type ConstantBindingBuilder, type ConstraintContext, type Constructor, Container, type ContainerGraphJson, type Container as ContainerInterface, type ContainerSnapshot, type ContainerStatic, type DeactivationHandler, type DependencyKey, DiError, DisposedContainerError, type GraphEdge, type GraphNode, type GraphOptions, type InjectOptions, type InjectableDependency, type InjectableOptions, type InjectionDescriptor, InternalError, type MaterializationFrame, type MetadataReader, MetadataReaderToken, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, Module, type ModuleBuilder, type MutableLifecycleMetadata, NoMatchingBindingError, RebindUnboundTokenError, type ResolutionContext, type ResolveOptions, type ScopeViolationDetails, ScopeViolationError, type ScopedBindingBuilder, type SingletonBindingBuilder, type SingletonLifecycleBuilder, SyncDisposalNotSupportedError, SyncModule, type Token, TokenNotBoundError, type TokenValue, type TransientBindingBuilder, createAutoRegisterRegistry, effectiveBindingScope, inject, injectAll, injectable, injectableSlotToResolveOptions, isInjectionDescriptor, isSyncModule, isToken, optional, postConstruct, preDestroy, slotKeyToResolveOptions, token, tokenName, whenAnyAncestorIs, whenAnyAncestorNamed, whenAnyAncestorTagged, whenAnyAncestorTaggedAll, whenNoAncestorIs, whenNoParentIs, whenParentIs, whenParentNamed, whenParentTagged, whenParentTaggedAll };
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { effectiveBindingScope } from "./binding-scope.mjs";
|
|
2
|
-
import { AmbiguousBindingError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError } from "./errors.mjs";
|
|
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
|
+
import { whenAnyAncestorIs, whenAnyAncestorNamed, whenAnyAncestorTagged, whenAnyAncestorTaggedAll, whenNoAncestorIs, whenNoParentIs, whenParentIs, whenParentNamed, whenParentTagged, whenParentTaggedAll } from "./constraints.mjs";
|
|
4
5
|
import { injectableSlotToResolveOptions, slotKeyToResolveOptions } from "./resolve-options.mjs";
|
|
5
6
|
import { MetadataReaderToken } from "./metadata/metadata-reader-token.mjs";
|
|
6
7
|
import { inject, injectAll, isInjectionDescriptor, optional } from "./decorators/inject.mjs";
|
|
7
|
-
import { AsyncModule, Module, SyncModule } from "./module.mjs";
|
|
8
|
+
import { AsyncModule, Module, SyncModule, isSyncModule } from "./module.mjs";
|
|
8
9
|
import { Container } from "./container.mjs";
|
|
9
10
|
import { createAutoRegisterRegistry, injectable } from "./decorators/injectable.mjs";
|
|
10
11
|
import { postConstruct, preDestroy } from "./decorators/lifecycle-decorators.mjs";
|
|
11
|
-
export { AmbiguousBindingError, 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, injectableSlotToResolveOptions, isInjectionDescriptor, isToken, optional, postConstruct, preDestroy, slotKeyToResolveOptions, token, tokenName };
|
|
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, injectableSlotToResolveOptions, isInjectionDescriptor, isSyncModule, isToken, optional, postConstruct, preDestroy, slotKeyToResolveOptions, token, tokenName, whenAnyAncestorIs, whenAnyAncestorNamed, whenAnyAncestorTagged, whenAnyAncestorTaggedAll, whenNoAncestorIs, whenNoParentIs, whenParentIs, whenParentNamed, whenParentTagged, whenParentTaggedAll };
|
package/dist/inspector.d.mts
CHANGED
|
@@ -22,8 +22,7 @@ interface BindingSnapshot {
|
|
|
22
22
|
* @since 0.3.16-canary.0
|
|
23
23
|
*/
|
|
24
24
|
interface ContainerSnapshot {
|
|
25
|
-
readonly ownBindings:
|
|
26
|
-
readonly bindings: readonly BindingSnapshot[];
|
|
25
|
+
readonly ownBindings: ReadonlyArray<BindingSnapshot>;
|
|
27
26
|
readonly cachedSingletonCount: number;
|
|
28
27
|
readonly hasParent: boolean;
|
|
29
28
|
readonly isDisposed: boolean;
|
|
@@ -38,7 +37,7 @@ declare class Inspector {
|
|
|
38
37
|
private readonly _isDisposed;
|
|
39
38
|
constructor(_registry: BindingRegistry, _scope: ScopeManager, _hasParent: boolean, _isDisposed: () => boolean);
|
|
40
39
|
inspect(): ContainerSnapshot;
|
|
41
|
-
lookupBindings<Value>(token: Token<Value> | Constructor<Value>):
|
|
40
|
+
lookupBindings<Value>(token: Token<Value> | Constructor<Value>): ReadonlyArray<BindingSnapshot>;
|
|
42
41
|
has(token: Token<unknown> | Constructor, hint?: ResolveOptions, parentHas?: () => boolean): boolean;
|
|
43
42
|
hasOwn(token: Token<unknown> | Constructor, hint?: ResolveOptions): boolean;
|
|
44
43
|
private allBindingSnapshots;
|
package/dist/inspector.mjs
CHANGED
|
@@ -6,6 +6,10 @@ import { tokenName } from "./token.mjs";
|
|
|
6
6
|
* @since 0.3.16-canary.0
|
|
7
7
|
*/
|
|
8
8
|
var Inspector = class {
|
|
9
|
+
_registry;
|
|
10
|
+
_scope;
|
|
11
|
+
_hasParent;
|
|
12
|
+
_isDisposed;
|
|
9
13
|
constructor(_registry, _scope, _hasParent, _isDisposed) {
|
|
10
14
|
this._registry = _registry;
|
|
11
15
|
this._scope = _scope;
|
|
@@ -13,10 +17,8 @@ var Inspector = class {
|
|
|
13
17
|
this._isDisposed = _isDisposed;
|
|
14
18
|
}
|
|
15
19
|
inspect() {
|
|
16
|
-
const snapshots = this.allBindingSnapshots();
|
|
17
20
|
return {
|
|
18
|
-
ownBindings:
|
|
19
|
-
bindings: snapshots,
|
|
21
|
+
ownBindings: this.allBindingSnapshots(),
|
|
20
22
|
cachedSingletonCount: this._scope.getAllSingletons().size,
|
|
21
23
|
hasParent: this._hasParent,
|
|
22
24
|
isDisposed: this._isDisposed()
|
package/dist/lifecycle.d.mts
CHANGED
|
@@ -12,15 +12,14 @@ declare class LifecycleManager {
|
|
|
12
12
|
private readonly _activationHooks;
|
|
13
13
|
private readonly _deactivationHooks;
|
|
14
14
|
private _activationVersion;
|
|
15
|
-
registerActivation<const Value>(
|
|
16
|
-
hasActivationHandlers<const Value>(
|
|
15
|
+
registerActivation<const Value>(token: Token<Value> | Constructor<Value>, handler: ActivationHandler<Value>): void;
|
|
16
|
+
hasActivationHandlers<const Value>(token: Token<Value> | Constructor<Value>): boolean;
|
|
17
17
|
get activationVersion(): number;
|
|
18
|
-
registerDeactivation<const Value>(
|
|
19
|
-
runActivation<const Value>(
|
|
20
|
-
runActivationSync<const Value>(
|
|
18
|
+
registerDeactivation<const Value>(token: Token<Value> | Constructor<Value>, handler: DeactivationHandler<Value>): void;
|
|
19
|
+
runActivation<const Value>(resolutionContext: ResolutionContext, binding: Binding<Value>, instance: Value, metadataReader: MetadataReader): Promise<Value>;
|
|
20
|
+
runActivationSync<const Value>(resolutionContext: ResolutionContext, binding: Binding<Value>, instance: Value, metadataReader: MetadataReader): Value;
|
|
21
21
|
runDeactivation<const Value>(binding: Binding<Value>, instance: Value, metadataReader: MetadataReader): Promise<void>;
|
|
22
22
|
runDeactivationSync<const Value>(binding: Binding<Value>, instance: Value, metadataReader: MetadataReader): void;
|
|
23
|
-
hasAsyncDeactivation<const Value>(binding: Binding<Value>, instance: Value, _metadataReader: MetadataReader): boolean;
|
|
24
23
|
}
|
|
25
24
|
//#endregion
|
|
26
25
|
export { LifecycleManager };
|
package/dist/lifecycle.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AsyncDeactivationError } from "./errors.mjs";
|
|
1
|
+
import { AsyncActivationError, AsyncDeactivationError } from "./errors.mjs";
|
|
2
2
|
import { tokenName } from "./token.mjs";
|
|
3
3
|
//#region src/lifecycle.ts
|
|
4
4
|
/**
|
|
@@ -8,128 +8,121 @@ var LifecycleManager = class {
|
|
|
8
8
|
_activationHooks = /* @__PURE__ */ new Map();
|
|
9
9
|
_deactivationHooks = /* @__PURE__ */ new Map();
|
|
10
10
|
_activationVersion = 0;
|
|
11
|
-
registerActivation(
|
|
11
|
+
registerActivation(token, handler) {
|
|
12
12
|
this._activationVersion += 1;
|
|
13
|
-
let list = this._activationHooks.get(
|
|
13
|
+
let list = this._activationHooks.get(token);
|
|
14
14
|
if (list === void 0) {
|
|
15
15
|
list = [];
|
|
16
|
-
this._activationHooks.set(
|
|
16
|
+
this._activationHooks.set(token, list);
|
|
17
17
|
}
|
|
18
18
|
list.push(handler);
|
|
19
19
|
}
|
|
20
|
-
hasActivationHandlers(
|
|
20
|
+
hasActivationHandlers(token) {
|
|
21
21
|
if (this._activationHooks.size === 0) return false;
|
|
22
|
-
const list = this._activationHooks.get(
|
|
22
|
+
const list = this._activationHooks.get(token);
|
|
23
23
|
return list !== void 0 && list.length > 0;
|
|
24
24
|
}
|
|
25
25
|
get activationVersion() {
|
|
26
26
|
return this._activationVersion;
|
|
27
27
|
}
|
|
28
|
-
registerDeactivation(
|
|
29
|
-
let list = this._deactivationHooks.get(
|
|
28
|
+
registerDeactivation(token, handler) {
|
|
29
|
+
let list = this._deactivationHooks.get(token);
|
|
30
30
|
if (list === void 0) {
|
|
31
31
|
list = [];
|
|
32
|
-
this._deactivationHooks.set(
|
|
32
|
+
this._deactivationHooks.set(token, list);
|
|
33
33
|
}
|
|
34
34
|
list.push(handler);
|
|
35
35
|
}
|
|
36
|
-
async runActivation(
|
|
37
|
-
let
|
|
36
|
+
async runActivation(resolutionContext, binding, instance, metadataReader) {
|
|
37
|
+
let activatedInstance = instance;
|
|
38
38
|
if (binding.kind === "class") {
|
|
39
39
|
const lifecycle = metadataReader.getLifecycleMetadata(binding.target);
|
|
40
40
|
if (lifecycle?.postConstruct && lifecycle.postConstruct.length > 0) for (const methodName of lifecycle.postConstruct) {
|
|
41
|
-
const method =
|
|
41
|
+
const method = activatedInstance[methodName];
|
|
42
42
|
if (typeof method === "function") {
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
43
|
+
const hookResult = method.call(activatedInstance);
|
|
44
|
+
if (hookResult instanceof Promise) await hookResult;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
if (binding.kind !== "alias" && binding.onActivation !== void 0) {
|
|
49
|
-
const
|
|
50
|
-
|
|
49
|
+
const activationResult = binding.onActivation(resolutionContext, activatedInstance);
|
|
50
|
+
activatedInstance = activationResult instanceof Promise ? await activationResult : activationResult;
|
|
51
51
|
}
|
|
52
52
|
const containerHooks = this._activationHooks.get(binding.token);
|
|
53
53
|
if (containerHooks !== void 0) for (const hook of containerHooks) {
|
|
54
|
-
const
|
|
55
|
-
|
|
54
|
+
const activationResult = hook(resolutionContext, activatedInstance);
|
|
55
|
+
activatedInstance = activationResult instanceof Promise ? await activationResult : activationResult;
|
|
56
56
|
}
|
|
57
|
-
return
|
|
57
|
+
return activatedInstance;
|
|
58
58
|
}
|
|
59
|
-
runActivationSync(
|
|
60
|
-
let
|
|
59
|
+
runActivationSync(resolutionContext, binding, instance, metadataReader) {
|
|
60
|
+
let activatedInstance = instance;
|
|
61
61
|
if (binding.kind === "class") {
|
|
62
62
|
const lifecycle = metadataReader.getLifecycleMetadata(binding.target);
|
|
63
63
|
if (lifecycle?.postConstruct && lifecycle.postConstruct.length > 0) for (const methodName of lifecycle.postConstruct) {
|
|
64
|
-
const method =
|
|
64
|
+
const method = activatedInstance[methodName];
|
|
65
65
|
if (typeof method === "function") {
|
|
66
|
-
if (method.call(
|
|
66
|
+
if (method.call(activatedInstance) instanceof Promise) throw new AsyncActivationError(tokenName(binding.token), "postConstruct", methodName);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
if (binding.kind !== "alias" && binding.onActivation !== void 0) {
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
|
|
71
|
+
const activationResult = binding.onActivation(resolutionContext, activatedInstance);
|
|
72
|
+
if (activationResult instanceof Promise) throw new AsyncActivationError(tokenName(binding.token), "onActivation");
|
|
73
|
+
activatedInstance = activationResult;
|
|
74
74
|
}
|
|
75
|
-
const
|
|
75
|
+
const tokenDisplayName = tokenName(binding.token);
|
|
76
76
|
const containerHooks = this._activationHooks.get(binding.token);
|
|
77
77
|
if (containerHooks !== void 0) for (const hook of containerHooks) {
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
|
|
78
|
+
const activationResult = hook(resolutionContext, activatedInstance);
|
|
79
|
+
if (activationResult instanceof Promise) throw new AsyncActivationError(tokenDisplayName, "onActivation");
|
|
80
|
+
activatedInstance = activationResult;
|
|
81
81
|
}
|
|
82
|
-
return
|
|
82
|
+
return activatedInstance;
|
|
83
83
|
}
|
|
84
84
|
async runDeactivation(binding, instance, metadataReader) {
|
|
85
|
-
const
|
|
86
|
-
const containerHooks = this._deactivationHooks.get(
|
|
85
|
+
const tokenKey = binding.token;
|
|
86
|
+
const containerHooks = this._deactivationHooks.get(tokenKey);
|
|
87
87
|
if (containerHooks !== void 0) for (const hook of containerHooks) {
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
88
|
+
const hookResult = hook(instance);
|
|
89
|
+
if (hookResult instanceof Promise) await hookResult;
|
|
90
90
|
}
|
|
91
91
|
if (binding.kind !== "alias" && binding.onDeactivation !== void 0) {
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
92
|
+
const hookResult = binding.onDeactivation(instance);
|
|
93
|
+
if (hookResult instanceof Promise) await hookResult;
|
|
94
94
|
}
|
|
95
95
|
if (binding.kind === "class") {
|
|
96
96
|
const lifecycle = metadataReader.getLifecycleMetadata(binding.target);
|
|
97
97
|
if (lifecycle?.preDestroy && lifecycle.preDestroy.length > 0) for (const methodName of lifecycle.preDestroy) {
|
|
98
98
|
const method = instance[methodName];
|
|
99
99
|
if (typeof method === "function") {
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
100
|
+
const hookResult = method.call(instance);
|
|
101
|
+
if (hookResult instanceof Promise) await hookResult;
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
runDeactivationSync(binding, instance, metadataReader) {
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
const containerHooks = this._deactivationHooks.get(
|
|
107
|
+
const tokenDisplayName = tokenName(binding.token);
|
|
108
|
+
const tokenKey = binding.token;
|
|
109
|
+
const containerHooks = this._deactivationHooks.get(tokenKey);
|
|
110
110
|
if (containerHooks !== void 0) {
|
|
111
|
-
for (const hook of containerHooks) if (hook(instance) instanceof Promise) throw new AsyncDeactivationError(
|
|
111
|
+
for (const hook of containerHooks) if (hook(instance) instanceof Promise) throw new AsyncDeactivationError(tokenDisplayName);
|
|
112
112
|
}
|
|
113
113
|
if (binding.kind !== "alias" && binding.onDeactivation !== void 0) {
|
|
114
|
-
if (binding.onDeactivation(instance) instanceof Promise) throw new AsyncDeactivationError(
|
|
114
|
+
if (binding.onDeactivation(instance) instanceof Promise) throw new AsyncDeactivationError(tokenDisplayName);
|
|
115
115
|
}
|
|
116
116
|
if (binding.kind === "class") {
|
|
117
117
|
const lifecycle = metadataReader.getLifecycleMetadata(binding.target);
|
|
118
118
|
if (lifecycle?.preDestroy && lifecycle.preDestroy.length > 0) for (const methodName of lifecycle.preDestroy) {
|
|
119
119
|
const method = instance[methodName];
|
|
120
120
|
if (typeof method === "function") {
|
|
121
|
-
if (method.call(instance) instanceof Promise) throw new AsyncDeactivationError(
|
|
121
|
+
if (method.call(instance) instanceof Promise) throw new AsyncDeactivationError(tokenDisplayName);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
hasAsyncDeactivation(binding, instance, _metadataReader) {
|
|
127
|
-
if (binding.kind === "alias") return false;
|
|
128
|
-
if (binding.onDeactivation !== void 0) {
|
|
129
|
-
if (binding.onDeactivation(instance) instanceof Promise) return true;
|
|
130
|
-
}
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
126
|
};
|
|
134
127
|
//#endregion
|
|
135
128
|
export { LifecycleManager };
|