@codefast/di 0.3.16-canary.0 → 0.3.16-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +8 -5
- package/dist/binding-select.d.mts +2 -2
- package/dist/binding-select.mjs +5 -5
- package/dist/binding.d.mts +12 -12
- package/dist/binding.mjs +8 -8
- 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 +202 -121
- package/dist/decorators/inject.d.mts +4 -4
- package/dist/decorators/inject.mjs +21 -19
- 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/dependency-graph.mjs +13 -13
- package/dist/environment.d.mts +17 -17
- package/dist/environment.mjs +21 -21
- 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 +6 -5
- package/dist/index.mjs +5 -4
- package/dist/inspector.d.mts +2 -3
- package/dist/inspector.mjs +18 -16
- 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 +2 -2
- package/dist/module.mjs +2 -2
- package/dist/registry.d.mts +6 -6
- package/dist/registry.mjs +55 -62
- package/dist/resolve-options.d.mts +5 -5
- package/dist/resolve-options.mjs +8 -8
- package/dist/resolver.d.mts +22 -10
- package/dist/resolver.mjs +206 -185
- package/dist/token.d.mts +1 -1
- package/dist/token.mjs +4 -4
- package/dist/types.d.mts +12 -8
- package/package.json +15 -8
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,24 +17,22 @@ 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()
|
|
23
25
|
};
|
|
24
26
|
}
|
|
25
27
|
lookupBindings(token) {
|
|
26
|
-
return this._registry.getAll(token).map((
|
|
28
|
+
return this._registry.getAll(token).map((binding) => this._toSnapshot(binding));
|
|
27
29
|
}
|
|
28
30
|
has(token, hint, parentHas) {
|
|
29
31
|
const bindings = this._registry.getAll(token);
|
|
30
32
|
if (bindings.length > 0) if (hint !== void 0) {
|
|
31
33
|
if (selectBinding(bindings, hint, {
|
|
32
34
|
resolutionPath: [],
|
|
33
|
-
|
|
35
|
+
resolutionStack: [],
|
|
34
36
|
parent: void 0,
|
|
35
37
|
ancestors: [],
|
|
36
38
|
currentResolveHint: hint
|
|
@@ -43,7 +45,7 @@ var Inspector = class {
|
|
|
43
45
|
if (bindings.length === 0) return false;
|
|
44
46
|
if (hint !== void 0) return selectBinding(bindings, hint, {
|
|
45
47
|
resolutionPath: [],
|
|
46
|
-
|
|
48
|
+
resolutionStack: [],
|
|
47
49
|
parent: void 0,
|
|
48
50
|
ancestors: [],
|
|
49
51
|
currentResolveHint: hint
|
|
@@ -51,20 +53,20 @@ var Inspector = class {
|
|
|
51
53
|
return true;
|
|
52
54
|
}
|
|
53
55
|
allBindingSnapshots() {
|
|
54
|
-
return this._registry.allBindings().map((
|
|
56
|
+
return this._registry.allBindings().map((binding) => this._toSnapshot(binding));
|
|
55
57
|
}
|
|
56
|
-
_toSnapshot(
|
|
57
|
-
const scope = effectiveBindingScope(
|
|
58
|
-
const slot =
|
|
59
|
-
name:
|
|
60
|
-
tags:
|
|
61
|
-
} : { tags:
|
|
58
|
+
_toSnapshot(binding) {
|
|
59
|
+
const scope = effectiveBindingScope(binding);
|
|
60
|
+
const slot = binding.slot.name !== void 0 ? {
|
|
61
|
+
name: binding.slot.name,
|
|
62
|
+
tags: binding.slot.tags
|
|
63
|
+
} : { tags: binding.slot.tags };
|
|
62
64
|
return {
|
|
63
|
-
tokenName: tokenName(
|
|
64
|
-
kind:
|
|
65
|
+
tokenName: tokenName(binding.token),
|
|
66
|
+
kind: binding.kind,
|
|
65
67
|
scope,
|
|
66
68
|
slot,
|
|
67
|
-
id:
|
|
69
|
+
id: binding.id
|
|
68
70
|
};
|
|
69
71
|
}
|
|
70
72
|
};
|
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 };
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { ConstructorMetadata, MutableLifecycleMetadata } from "./metadata-types.mjs";
|
|
2
2
|
|
|
3
3
|
//#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
|
+
}>;
|
|
4
14
|
/**
|
|
5
15
|
* @since 0.3.16-canary.0
|
|
6
16
|
*/
|
|
@@ -25,5 +35,18 @@ declare const lifecycleMetadataMap: WeakMap<object, MutableLifecycleMetadata>;
|
|
|
25
35
|
* @since 0.3.16-canary.0
|
|
26
36
|
*/
|
|
27
37
|
declare const lifecycleByConstructorMetadataMap: WeakMap<object, MutableLifecycleMetadata>;
|
|
38
|
+
/**
|
|
39
|
+
* Fallback keyed by the class metadata object (`context.metadata` / `ctor[Symbol.metadata]`).
|
|
40
|
+
*
|
|
41
|
+
* @since 0.3.16-canary.0
|
|
42
|
+
*/
|
|
43
|
+
declare const accessorMetadataByMetadataObjectMap: WeakMap<object, AccessorInjectionEntryList>;
|
|
44
|
+
/**
|
|
45
|
+
* Populated from `@injectable()` after field decorators have written `INJECT_ACCESSOR_KEY`
|
|
46
|
+
* onto `context.metadata` — same timing as {@link constructorMetadataMap}.
|
|
47
|
+
*
|
|
48
|
+
* @since 0.3.16-canary.0
|
|
49
|
+
*/
|
|
50
|
+
declare const accessorMetadataByConstructorMap: WeakMap<object, AccessorInjectionEntryList>;
|
|
28
51
|
//#endregion
|
|
29
|
-
export { INJECTABLE_KEY, INJECT_ACCESSOR_KEY, LIFECYCLE_KEY, constructorMetadataMap, lifecycleByConstructorMetadataMap, lifecycleMetadataMap };
|
|
52
|
+
export { AccessorInjectionEntryList, INJECTABLE_KEY, INJECT_ACCESSOR_KEY, LIFECYCLE_KEY, accessorMetadataByConstructorMap, accessorMetadataByMetadataObjectMap, constructorMetadataMap, lifecycleByConstructorMetadataMap, lifecycleMetadataMap };
|
|
@@ -23,5 +23,18 @@ const lifecycleMetadataMap = /* @__PURE__ */ new WeakMap();
|
|
|
23
23
|
* @since 0.3.16-canary.0
|
|
24
24
|
*/
|
|
25
25
|
const lifecycleByConstructorMetadataMap = /* @__PURE__ */ new WeakMap();
|
|
26
|
+
/**
|
|
27
|
+
* Fallback keyed by the class metadata object (`context.metadata` / `ctor[Symbol.metadata]`).
|
|
28
|
+
*
|
|
29
|
+
* @since 0.3.16-canary.0
|
|
30
|
+
*/
|
|
31
|
+
const accessorMetadataByMetadataObjectMap = /* @__PURE__ */ new WeakMap();
|
|
32
|
+
/**
|
|
33
|
+
* Populated from `@injectable()` after field decorators have written `INJECT_ACCESSOR_KEY`
|
|
34
|
+
* onto `context.metadata` — same timing as {@link constructorMetadataMap}.
|
|
35
|
+
*
|
|
36
|
+
* @since 0.3.16-canary.0
|
|
37
|
+
*/
|
|
38
|
+
const accessorMetadataByConstructorMap = /* @__PURE__ */ new WeakMap();
|
|
26
39
|
//#endregion
|
|
27
|
-
export { INJECTABLE_KEY, INJECT_ACCESSOR_KEY, LIFECYCLE_KEY, constructorMetadataMap, lifecycleByConstructorMetadataMap, lifecycleMetadataMap };
|
|
40
|
+
export { INJECTABLE_KEY, INJECT_ACCESSOR_KEY, LIFECYCLE_KEY, accessorMetadataByConstructorMap, accessorMetadataByMetadataObjectMap, constructorMetadataMap, lifecycleByConstructorMetadataMap, lifecycleMetadataMap };
|
|
@@ -17,14 +17,14 @@ interface ParamMetadata {
|
|
|
17
17
|
* @since 0.3.16-canary.0
|
|
18
18
|
*/
|
|
19
19
|
interface ConstructorMetadata {
|
|
20
|
-
readonly params:
|
|
20
|
+
readonly params: ReadonlyArray<ParamMetadata>;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* @since 0.3.16-canary.0
|
|
24
24
|
*/
|
|
25
25
|
interface LifecycleMetadata {
|
|
26
|
-
readonly postConstruct:
|
|
27
|
-
readonly preDestroy:
|
|
26
|
+
readonly postConstruct: ReadonlyArray<string>;
|
|
27
|
+
readonly preDestroy: ReadonlyArray<string>;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Mutable buckets used while aggregating decorator metadata (same keys as {@link LifecycleMetadata}).
|
|
@@ -32,8 +32,8 @@ interface LifecycleMetadata {
|
|
|
32
32
|
* @since 0.3.16-canary.0
|
|
33
33
|
*/
|
|
34
34
|
interface MutableLifecycleMetadata {
|
|
35
|
-
postConstruct: string
|
|
36
|
-
preDestroy: string
|
|
35
|
+
postConstruct: Array<string>;
|
|
36
|
+
preDestroy: Array<string>;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* @since 0.3.16-canary.0
|
|
@@ -1,39 +1,46 @@
|
|
|
1
|
-
import { INJECTABLE_KEY, INJECT_ACCESSOR_KEY, LIFECYCLE_KEY, constructorMetadataMap, lifecycleByConstructorMetadataMap, lifecycleMetadataMap } from "./metadata-keys.mjs";
|
|
1
|
+
import { INJECTABLE_KEY, INJECT_ACCESSOR_KEY, LIFECYCLE_KEY, accessorMetadataByConstructorMap, accessorMetadataByMetadataObjectMap, constructorMetadataMap, lifecycleByConstructorMetadataMap, lifecycleMetadataMap } 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
7
|
getConstructorMetadata(target) {
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
12
|
-
const
|
|
13
|
-
if (!
|
|
14
|
-
return
|
|
8
|
+
const weakMapMetadata = constructorMetadataMap.get(target);
|
|
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
15
|
}
|
|
16
16
|
getLifecycleMetadata(target) {
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
17
|
+
const lifecycleMetadataByConstructor = lifecycleByConstructorMetadataMap.get(target);
|
|
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
23
|
}
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
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
28
|
}
|
|
29
29
|
}
|
|
30
30
|
getAccessorMetadata(target) {
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
const byConstructor = accessorMetadataByConstructorMap.get(target);
|
|
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];
|
|
37
44
|
}
|
|
38
45
|
};
|
|
39
46
|
/**
|
package/dist/module.d.mts
CHANGED
|
@@ -26,7 +26,7 @@ interface AsyncModule {
|
|
|
26
26
|
*/
|
|
27
27
|
interface ModuleBuilder {
|
|
28
28
|
bind<const Value>(token: Token<Value> | Constructor<Value>): BindToBuilder<Value>;
|
|
29
|
-
import(...modules: SyncModule
|
|
29
|
+
import(...modules: Array<SyncModule>): void;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* @since 0.3.16-canary.0
|
|
@@ -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,24 +16,24 @@ 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
|
-
allBindings():
|
|
29
|
+
allBindings(): ReadonlyArray<Binding>;
|
|
30
30
|
/** Remove all bindings. Returns all removed. */
|
|
31
|
-
clear():
|
|
31
|
+
clear(): ReadonlyArray<Binding>;
|
|
32
32
|
getSimpleNamed(token: Token<unknown> | Constructor, name: string): Binding | undefined;
|
|
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;
|