@codefast/di 0.3.15 → 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 +4 -0
- package/README.md +4 -1
- package/dist/binding-scope.d.mts +2 -0
- package/dist/binding-scope.mjs +2 -0
- package/dist/binding-select.d.mts +6 -2
- package/dist/binding-select.mjs +4 -0
- package/dist/binding.d.mts +74 -7
- package/dist/binding.mjs +12 -0
- package/dist/constraints.d.mts +49 -9
- package/dist/constraints.mjs +71 -19
- package/dist/constructor-type.d.mts +6 -2
- package/dist/container.d.mts +15 -6
- package/dist/container.mjs +139 -55
- package/dist/decorators/inject.d.mts +27 -3
- package/dist/decorators/inject.mjs +28 -11
- package/dist/decorators/injectable.d.mts +13 -1
- package/dist/decorators/injectable.mjs +24 -14
- package/dist/decorators/lifecycle-decorators.d.mts +6 -0
- package/dist/decorators/lifecycle-decorators.mjs +9 -0
- package/dist/dependency-graph.d.mts +17 -2
- package/dist/dependency-graph.mjs +3 -0
- package/dist/environment.d.mts +27 -12
- package/dist/environment.mjs +12 -0
- package/dist/errors.d.mts +69 -8
- package/dist/errors.mjs +65 -1
- package/dist/graph-adapters/cytoscape.d.mts +12 -0
- package/dist/graph-adapters/cytoscape.mjs +3 -0
- package/dist/graph-adapters/dot.d.mts +3 -0
- package/dist/graph-adapters/dot.mjs +3 -0
- package/dist/graph-adapters/reactflow.d.mts +14 -2
- package/dist/graph-adapters/reactflow.mjs +3 -0
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +4 -3
- package/dist/inspector.d.mts +11 -3
- package/dist/inspector.mjs +8 -3
- package/dist/lifecycle.d.mts +8 -6
- package/dist/lifecycle.mjs +48 -52
- package/dist/metadata/metadata-keys.d.mts +42 -1
- package/dist/metadata/metadata-keys.mjs +32 -1
- package/dist/metadata/metadata-reader-token.d.mts +3 -0
- package/dist/metadata/metadata-reader-token.mjs +3 -0
- package/dist/metadata/metadata-types.d.mts +22 -6
- package/dist/metadata/symbol-metadata-reader.d.mts +6 -0
- package/dist/metadata/symbol-metadata-reader.mjs +37 -24
- package/dist/module.d.mts +25 -1
- package/dist/module.mjs +12 -0
- package/dist/registry.d.mts +8 -5
- package/dist/registry.mjs +38 -42
- package/dist/resolve-options.d.mts +4 -0
- package/dist/resolve-options.mjs +4 -0
- package/dist/resolver.d.mts +23 -8
- package/dist/resolver.mjs +67 -43
- package/dist/scope.d.mts +3 -0
- package/dist/scope.mjs +3 -0
- package/dist/token.d.mts +12 -0
- package/dist/token.mjs +9 -0
- package/dist/types.d.mts +44 -6
- package/package.json +11 -5
package/dist/lifecycle.d.mts
CHANGED
|
@@ -5,19 +5,21 @@ import { Binding } from "./binding.mjs";
|
|
|
5
5
|
import { MetadataReader } from "./metadata/metadata-types.mjs";
|
|
6
6
|
|
|
7
7
|
//#region src/lifecycle.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* @since 0.3.16-canary.0
|
|
10
|
+
*/
|
|
8
11
|
declare class LifecycleManager {
|
|
9
12
|
private readonly _activationHooks;
|
|
10
13
|
private readonly _deactivationHooks;
|
|
11
14
|
private _activationVersion;
|
|
12
|
-
registerActivation<const Value>(
|
|
13
|
-
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;
|
|
14
17
|
get activationVersion(): number;
|
|
15
|
-
registerDeactivation<const Value>(
|
|
16
|
-
runActivation<const Value>(
|
|
17
|
-
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;
|
|
18
21
|
runDeactivation<const Value>(binding: Binding<Value>, instance: Value, metadataReader: MetadataReader): Promise<void>;
|
|
19
22
|
runDeactivationSync<const Value>(binding: Binding<Value>, instance: Value, metadataReader: MetadataReader): void;
|
|
20
|
-
hasAsyncDeactivation<const Value>(binding: Binding<Value>, instance: Value, _metadataReader: MetadataReader): boolean;
|
|
21
23
|
}
|
|
22
24
|
//#endregion
|
|
23
25
|
export { LifecycleManager };
|
package/dist/lifecycle.mjs
CHANGED
|
@@ -1,132 +1,128 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* @since 0.3.16-canary.0
|
|
6
|
+
*/
|
|
4
7
|
var LifecycleManager = class {
|
|
5
8
|
_activationHooks = /* @__PURE__ */ new Map();
|
|
6
9
|
_deactivationHooks = /* @__PURE__ */ new Map();
|
|
7
10
|
_activationVersion = 0;
|
|
8
|
-
registerActivation(
|
|
11
|
+
registerActivation(token, handler) {
|
|
9
12
|
this._activationVersion += 1;
|
|
10
|
-
let list = this._activationHooks.get(
|
|
13
|
+
let list = this._activationHooks.get(token);
|
|
11
14
|
if (list === void 0) {
|
|
12
15
|
list = [];
|
|
13
|
-
this._activationHooks.set(
|
|
16
|
+
this._activationHooks.set(token, list);
|
|
14
17
|
}
|
|
15
18
|
list.push(handler);
|
|
16
19
|
}
|
|
17
|
-
hasActivationHandlers(
|
|
20
|
+
hasActivationHandlers(token) {
|
|
18
21
|
if (this._activationHooks.size === 0) return false;
|
|
19
|
-
const list = this._activationHooks.get(
|
|
22
|
+
const list = this._activationHooks.get(token);
|
|
20
23
|
return list !== void 0 && list.length > 0;
|
|
21
24
|
}
|
|
22
25
|
get activationVersion() {
|
|
23
26
|
return this._activationVersion;
|
|
24
27
|
}
|
|
25
|
-
registerDeactivation(
|
|
26
|
-
let list = this._deactivationHooks.get(
|
|
28
|
+
registerDeactivation(token, handler) {
|
|
29
|
+
let list = this._deactivationHooks.get(token);
|
|
27
30
|
if (list === void 0) {
|
|
28
31
|
list = [];
|
|
29
|
-
this._deactivationHooks.set(
|
|
32
|
+
this._deactivationHooks.set(token, list);
|
|
30
33
|
}
|
|
31
34
|
list.push(handler);
|
|
32
35
|
}
|
|
33
|
-
async runActivation(
|
|
34
|
-
let
|
|
36
|
+
async runActivation(resolutionContext, binding, instance, metadataReader) {
|
|
37
|
+
let activatedInstance = instance;
|
|
35
38
|
if (binding.kind === "class") {
|
|
36
39
|
const lifecycle = metadataReader.getLifecycleMetadata(binding.target);
|
|
37
40
|
if (lifecycle?.postConstruct && lifecycle.postConstruct.length > 0) for (const methodName of lifecycle.postConstruct) {
|
|
38
|
-
const method =
|
|
41
|
+
const method = activatedInstance[methodName];
|
|
39
42
|
if (typeof method === "function") {
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
43
|
+
const hookResult = method.call(activatedInstance);
|
|
44
|
+
if (hookResult instanceof Promise) await hookResult;
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
if (binding.kind !== "alias" && binding.onActivation !== void 0) {
|
|
46
|
-
const
|
|
47
|
-
|
|
49
|
+
const activationResult = binding.onActivation(resolutionContext, activatedInstance);
|
|
50
|
+
activatedInstance = activationResult instanceof Promise ? await activationResult : activationResult;
|
|
48
51
|
}
|
|
49
52
|
const containerHooks = this._activationHooks.get(binding.token);
|
|
50
53
|
if (containerHooks !== void 0) for (const hook of containerHooks) {
|
|
51
|
-
const
|
|
52
|
-
|
|
54
|
+
const activationResult = hook(resolutionContext, activatedInstance);
|
|
55
|
+
activatedInstance = activationResult instanceof Promise ? await activationResult : activationResult;
|
|
53
56
|
}
|
|
54
|
-
return
|
|
57
|
+
return activatedInstance;
|
|
55
58
|
}
|
|
56
|
-
runActivationSync(
|
|
57
|
-
let
|
|
59
|
+
runActivationSync(resolutionContext, binding, instance, metadataReader) {
|
|
60
|
+
let activatedInstance = instance;
|
|
58
61
|
if (binding.kind === "class") {
|
|
59
62
|
const lifecycle = metadataReader.getLifecycleMetadata(binding.target);
|
|
60
63
|
if (lifecycle?.postConstruct && lifecycle.postConstruct.length > 0) for (const methodName of lifecycle.postConstruct) {
|
|
61
|
-
const method =
|
|
64
|
+
const method = activatedInstance[methodName];
|
|
62
65
|
if (typeof method === "function") {
|
|
63
|
-
if (method.call(
|
|
66
|
+
if (method.call(activatedInstance) instanceof Promise) throw new AsyncActivationError(tokenName(binding.token), "postConstruct", methodName);
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
69
|
}
|
|
67
70
|
if (binding.kind !== "alias" && binding.onActivation !== void 0) {
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
+
const activationResult = binding.onActivation(resolutionContext, activatedInstance);
|
|
72
|
+
if (activationResult instanceof Promise) throw new AsyncActivationError(tokenName(binding.token), "onActivation");
|
|
73
|
+
activatedInstance = activationResult;
|
|
71
74
|
}
|
|
72
|
-
const
|
|
75
|
+
const tokenDisplayName = tokenName(binding.token);
|
|
73
76
|
const containerHooks = this._activationHooks.get(binding.token);
|
|
74
77
|
if (containerHooks !== void 0) for (const hook of containerHooks) {
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
+
const activationResult = hook(resolutionContext, activatedInstance);
|
|
79
|
+
if (activationResult instanceof Promise) throw new AsyncActivationError(tokenDisplayName, "onActivation");
|
|
80
|
+
activatedInstance = activationResult;
|
|
78
81
|
}
|
|
79
|
-
return
|
|
82
|
+
return activatedInstance;
|
|
80
83
|
}
|
|
81
84
|
async runDeactivation(binding, instance, metadataReader) {
|
|
82
|
-
const
|
|
83
|
-
const containerHooks = this._deactivationHooks.get(
|
|
85
|
+
const tokenKey = binding.token;
|
|
86
|
+
const containerHooks = this._deactivationHooks.get(tokenKey);
|
|
84
87
|
if (containerHooks !== void 0) for (const hook of containerHooks) {
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
88
|
+
const hookResult = hook(instance);
|
|
89
|
+
if (hookResult instanceof Promise) await hookResult;
|
|
87
90
|
}
|
|
88
91
|
if (binding.kind !== "alias" && binding.onDeactivation !== void 0) {
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
92
|
+
const hookResult = binding.onDeactivation(instance);
|
|
93
|
+
if (hookResult instanceof Promise) await hookResult;
|
|
91
94
|
}
|
|
92
95
|
if (binding.kind === "class") {
|
|
93
96
|
const lifecycle = metadataReader.getLifecycleMetadata(binding.target);
|
|
94
97
|
if (lifecycle?.preDestroy && lifecycle.preDestroy.length > 0) for (const methodName of lifecycle.preDestroy) {
|
|
95
98
|
const method = instance[methodName];
|
|
96
99
|
if (typeof method === "function") {
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
100
|
+
const hookResult = method.call(instance);
|
|
101
|
+
if (hookResult instanceof Promise) await hookResult;
|
|
99
102
|
}
|
|
100
103
|
}
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
106
|
runDeactivationSync(binding, instance, metadataReader) {
|
|
104
|
-
const
|
|
105
|
-
const
|
|
106
|
-
const containerHooks = this._deactivationHooks.get(
|
|
107
|
+
const tokenDisplayName = tokenName(binding.token);
|
|
108
|
+
const tokenKey = binding.token;
|
|
109
|
+
const containerHooks = this._deactivationHooks.get(tokenKey);
|
|
107
110
|
if (containerHooks !== void 0) {
|
|
108
|
-
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);
|
|
109
112
|
}
|
|
110
113
|
if (binding.kind !== "alias" && binding.onDeactivation !== void 0) {
|
|
111
|
-
if (binding.onDeactivation(instance) instanceof Promise) throw new AsyncDeactivationError(
|
|
114
|
+
if (binding.onDeactivation(instance) instanceof Promise) throw new AsyncDeactivationError(tokenDisplayName);
|
|
112
115
|
}
|
|
113
116
|
if (binding.kind === "class") {
|
|
114
117
|
const lifecycle = metadataReader.getLifecycleMetadata(binding.target);
|
|
115
118
|
if (lifecycle?.preDestroy && lifecycle.preDestroy.length > 0) for (const methodName of lifecycle.preDestroy) {
|
|
116
119
|
const method = instance[methodName];
|
|
117
120
|
if (typeof method === "function") {
|
|
118
|
-
if (method.call(instance) instanceof Promise) throw new AsyncDeactivationError(
|
|
121
|
+
if (method.call(instance) instanceof Promise) throw new AsyncDeactivationError(tokenDisplayName);
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
}
|
|
122
125
|
}
|
|
123
|
-
hasAsyncDeactivation(binding, instance, _metadataReader) {
|
|
124
|
-
if (binding.kind === "alias") return false;
|
|
125
|
-
if (binding.onDeactivation !== void 0) {
|
|
126
|
-
if (binding.onDeactivation(instance) instanceof Promise) return true;
|
|
127
|
-
}
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
126
|
};
|
|
131
127
|
//#endregion
|
|
132
128
|
export { LifecycleManager };
|
|
@@ -1,11 +1,52 @@
|
|
|
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
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* @since 0.3.16-canary.0
|
|
16
|
+
*/
|
|
4
17
|
declare const INJECTABLE_KEY: unique symbol;
|
|
18
|
+
/**
|
|
19
|
+
* @since 0.3.16-canary.0
|
|
20
|
+
*/
|
|
5
21
|
declare const LIFECYCLE_KEY: unique symbol;
|
|
22
|
+
/**
|
|
23
|
+
* @since 0.3.16-canary.0
|
|
24
|
+
*/
|
|
6
25
|
declare const INJECT_ACCESSOR_KEY: unique symbol;
|
|
26
|
+
/**
|
|
27
|
+
* @since 0.3.16-canary.0
|
|
28
|
+
*/
|
|
7
29
|
declare const constructorMetadataMap: WeakMap<object, ConstructorMetadata>;
|
|
30
|
+
/**
|
|
31
|
+
* @since 0.3.16-canary.0
|
|
32
|
+
*/
|
|
8
33
|
declare const lifecycleMetadataMap: WeakMap<object, MutableLifecycleMetadata>;
|
|
34
|
+
/**
|
|
35
|
+
* @since 0.3.16-canary.0
|
|
36
|
+
*/
|
|
9
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>;
|
|
10
51
|
//#endregion
|
|
11
|
-
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 };
|
|
@@ -1,9 +1,40 @@
|
|
|
1
1
|
//#region src/metadata/metadata-keys.ts
|
|
2
|
+
/**
|
|
3
|
+
* @since 0.3.16-canary.0
|
|
4
|
+
*/
|
|
2
5
|
const INJECTABLE_KEY = Symbol("di:injectable");
|
|
6
|
+
/**
|
|
7
|
+
* @since 0.3.16-canary.0
|
|
8
|
+
*/
|
|
3
9
|
const LIFECYCLE_KEY = Symbol("di:lifecycle");
|
|
10
|
+
/**
|
|
11
|
+
* @since 0.3.16-canary.0
|
|
12
|
+
*/
|
|
4
13
|
const INJECT_ACCESSOR_KEY = Symbol("di:inject-accessor");
|
|
14
|
+
/**
|
|
15
|
+
* @since 0.3.16-canary.0
|
|
16
|
+
*/
|
|
5
17
|
const constructorMetadataMap = /* @__PURE__ */ new WeakMap();
|
|
18
|
+
/**
|
|
19
|
+
* @since 0.3.16-canary.0
|
|
20
|
+
*/
|
|
6
21
|
const lifecycleMetadataMap = /* @__PURE__ */ new WeakMap();
|
|
22
|
+
/**
|
|
23
|
+
* @since 0.3.16-canary.0
|
|
24
|
+
*/
|
|
7
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();
|
|
8
39
|
//#endregion
|
|
9
|
-
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 };
|
|
@@ -2,6 +2,9 @@ import { Token } from "../token.mjs";
|
|
|
2
2
|
import { MetadataReader } from "./metadata-types.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/metadata/metadata-reader-token.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* @since 0.3.16-canary.0
|
|
7
|
+
*/
|
|
5
8
|
declare const MetadataReaderToken: Token<MetadataReader>;
|
|
6
9
|
//#endregion
|
|
7
10
|
export { MetadataReaderToken };
|
|
@@ -2,6 +2,9 @@ import { Constructor } from "../constructor-type.mjs";
|
|
|
2
2
|
import { Token } from "../token.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/metadata/metadata-types.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* @since 0.3.16-canary.0
|
|
7
|
+
*/
|
|
5
8
|
interface ParamMetadata {
|
|
6
9
|
readonly index: number;
|
|
7
10
|
readonly token: Token<unknown> | Constructor;
|
|
@@ -10,18 +13,31 @@ interface ParamMetadata {
|
|
|
10
13
|
readonly name?: string;
|
|
11
14
|
readonly tags?: ReadonlyArray<readonly [string, unknown]>;
|
|
12
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* @since 0.3.16-canary.0
|
|
18
|
+
*/
|
|
13
19
|
interface ConstructorMetadata {
|
|
14
|
-
readonly params:
|
|
20
|
+
readonly params: ReadonlyArray<ParamMetadata>;
|
|
15
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* @since 0.3.16-canary.0
|
|
24
|
+
*/
|
|
16
25
|
interface LifecycleMetadata {
|
|
17
|
-
readonly postConstruct:
|
|
18
|
-
readonly preDestroy:
|
|
26
|
+
readonly postConstruct: ReadonlyArray<string>;
|
|
27
|
+
readonly preDestroy: ReadonlyArray<string>;
|
|
19
28
|
}
|
|
20
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Mutable buckets used while aggregating decorator metadata (same keys as {@link LifecycleMetadata}).
|
|
31
|
+
*
|
|
32
|
+
* @since 0.3.16-canary.0
|
|
33
|
+
*/
|
|
21
34
|
interface MutableLifecycleMetadata {
|
|
22
|
-
postConstruct: string
|
|
23
|
-
preDestroy: string
|
|
35
|
+
postConstruct: Array<string>;
|
|
36
|
+
preDestroy: Array<string>;
|
|
24
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* @since 0.3.16-canary.0
|
|
40
|
+
*/
|
|
25
41
|
interface MetadataReader {
|
|
26
42
|
getConstructorMetadata(target: Constructor): ConstructorMetadata | undefined;
|
|
27
43
|
getLifecycleMetadata(target: Constructor): LifecycleMetadata | undefined;
|
|
@@ -3,6 +3,9 @@ import { InjectionDescriptor } from "../decorators/inject.mjs";
|
|
|
3
3
|
import { ConstructorMetadata, LifecycleMetadata, MetadataReader } from "./metadata-types.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/metadata/symbol-metadata-reader.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* @since 0.3.16-canary.0
|
|
8
|
+
*/
|
|
6
9
|
declare class SymbolMetadataReader implements MetadataReader {
|
|
7
10
|
getConstructorMetadata(target: Constructor): ConstructorMetadata | undefined;
|
|
8
11
|
getLifecycleMetadata(target: Constructor): LifecycleMetadata | undefined;
|
|
@@ -11,6 +14,9 @@ declare class SymbolMetadataReader implements MetadataReader {
|
|
|
11
14
|
descriptor: InjectionDescriptor;
|
|
12
15
|
}> | undefined;
|
|
13
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* @since 0.3.16-canary.0
|
|
19
|
+
*/
|
|
14
20
|
declare const defaultMetadataReader: SymbolMetadataReader;
|
|
15
21
|
//#endregion
|
|
16
22
|
export { SymbolMetadataReader, defaultMetadataReader };
|
|
@@ -1,38 +1,51 @@
|
|
|
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
|
+
/**
|
|
4
|
+
* @since 0.3.16-canary.0
|
|
5
|
+
*/
|
|
3
6
|
var SymbolMetadataReader = class {
|
|
4
7
|
getConstructorMetadata(target) {
|
|
5
|
-
const
|
|
6
|
-
if (
|
|
7
|
-
const
|
|
8
|
-
if (
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
11
|
-
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];
|
|
12
15
|
}
|
|
13
16
|
getLifecycleMetadata(target) {
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
const
|
|
19
|
-
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];
|
|
20
23
|
}
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
23
|
-
const
|
|
24
|
-
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;
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
30
|
getAccessorMetadata(target) {
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
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];
|
|
34
44
|
}
|
|
35
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* @since 0.3.16-canary.0
|
|
48
|
+
*/
|
|
36
49
|
const defaultMetadataReader = new SymbolMetadataReader();
|
|
37
50
|
//#endregion
|
|
38
51
|
export { SymbolMetadataReader, defaultMetadataReader };
|
package/dist/module.d.mts
CHANGED
|
@@ -5,34 +5,58 @@ import { BindToBuilder } from "./binding.mjs";
|
|
|
5
5
|
//#region src/module.d.ts
|
|
6
6
|
declare const SYNC_MODULE_BRAND: unique symbol;
|
|
7
7
|
declare const ASYNC_MODULE_BRAND: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* @since 0.3.16-canary.0
|
|
10
|
+
*/
|
|
8
11
|
interface SyncModule {
|
|
9
12
|
readonly name: string;
|
|
10
13
|
readonly [SYNC_MODULE_BRAND]: true;
|
|
11
14
|
readonly _setup: (builder: ModuleBuilder) => void;
|
|
12
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* @since 0.3.16-canary.0
|
|
18
|
+
*/
|
|
13
19
|
interface AsyncModule {
|
|
14
20
|
readonly name: string;
|
|
15
21
|
readonly [ASYNC_MODULE_BRAND]: true;
|
|
16
22
|
readonly _setup: (builder: AsyncModuleBuilder) => Promise<void>;
|
|
17
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* @since 0.3.16-canary.0
|
|
26
|
+
*/
|
|
18
27
|
interface ModuleBuilder {
|
|
19
28
|
bind<const Value>(token: Token<Value> | Constructor<Value>): BindToBuilder<Value>;
|
|
20
|
-
import(...modules: SyncModule
|
|
29
|
+
import(...modules: Array<SyncModule>): void;
|
|
21
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* @since 0.3.16-canary.0
|
|
33
|
+
*/
|
|
22
34
|
interface AsyncModuleBuilder {
|
|
23
35
|
bind<const Value>(token: Token<Value> | Constructor<Value>): BindToBuilder<Value>;
|
|
24
36
|
import(...modules: Array<SyncModule | AsyncModule>): void;
|
|
25
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* @since 0.3.16-canary.0
|
|
40
|
+
*/
|
|
26
41
|
declare const SyncModule: {
|
|
27
42
|
create(name: string, setup: (builder: ModuleBuilder) => void): SyncModule;
|
|
28
43
|
};
|
|
44
|
+
/**
|
|
45
|
+
* @since 0.3.16-canary.0
|
|
46
|
+
*/
|
|
29
47
|
declare const AsyncModule: {
|
|
30
48
|
create(name: string, setup: (builder: AsyncModuleBuilder) => Promise<void>): AsyncModule;
|
|
31
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* @since 0.3.16-canary.0
|
|
52
|
+
*/
|
|
32
53
|
declare const Module: {
|
|
33
54
|
create(name: string, setup: (builder: ModuleBuilder) => void): SyncModule;
|
|
34
55
|
createAsync(name: string, setup: (builder: AsyncModuleBuilder) => Promise<void>): AsyncModule;
|
|
35
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* @since 0.3.16-canary.0
|
|
59
|
+
*/
|
|
36
60
|
declare function isSyncModule(m: SyncModule | AsyncModule): m is SyncModule;
|
|
37
61
|
//#endregion
|
|
38
62
|
export { AsyncModule, AsyncModuleBuilder, Module, ModuleBuilder, SyncModule, isSyncModule };
|
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
//#region src/module.ts
|
|
2
2
|
const SYNC_MODULE_BRAND = Symbol("di:sync-module");
|
|
3
3
|
const ASYNC_MODULE_BRAND = Symbol("di:async-module");
|
|
4
|
+
/**
|
|
5
|
+
* @since 0.3.16-canary.0
|
|
6
|
+
*/
|
|
4
7
|
const SyncModule = { create(name, setup) {
|
|
5
8
|
return {
|
|
6
9
|
name,
|
|
@@ -8,6 +11,9 @@ const SyncModule = { create(name, setup) {
|
|
|
8
11
|
_setup: setup
|
|
9
12
|
};
|
|
10
13
|
} };
|
|
14
|
+
/**
|
|
15
|
+
* @since 0.3.16-canary.0
|
|
16
|
+
*/
|
|
11
17
|
const AsyncModule = { create(name, setup) {
|
|
12
18
|
return {
|
|
13
19
|
name,
|
|
@@ -15,6 +21,9 @@ const AsyncModule = { create(name, setup) {
|
|
|
15
21
|
_setup: setup
|
|
16
22
|
};
|
|
17
23
|
} };
|
|
24
|
+
/**
|
|
25
|
+
* @since 0.3.16-canary.0
|
|
26
|
+
*/
|
|
18
27
|
const Module = {
|
|
19
28
|
create(name, setup) {
|
|
20
29
|
return SyncModule.create(name, setup);
|
|
@@ -23,6 +32,9 @@ const Module = {
|
|
|
23
32
|
return AsyncModule.create(name, setup);
|
|
24
33
|
}
|
|
25
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* @since 0.3.16-canary.0
|
|
37
|
+
*/
|
|
26
38
|
function isSyncModule(m) {
|
|
27
39
|
return m[SYNC_MODULE_BRAND] === true;
|
|
28
40
|
}
|
package/dist/registry.d.mts
CHANGED
|
@@ -4,6 +4,9 @@ import { BindingIdentifier } from "./types.mjs";
|
|
|
4
4
|
import { Binding } from "./binding.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/registry.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* @since 0.3.16-canary.0
|
|
9
|
+
*/
|
|
7
10
|
declare class BindingRegistry {
|
|
8
11
|
private readonly _bindings;
|
|
9
12
|
private readonly _byId;
|
|
@@ -13,24 +16,24 @@ declare class BindingRegistry {
|
|
|
13
16
|
/** Add or replace binding using slot-aware last-wins. */
|
|
14
17
|
add(binding: Binding): void;
|
|
15
18
|
/** Remove all bindings for a token. Returns removed bindings. */
|
|
16
|
-
removeByToken(t: Token<unknown> | Constructor): Binding
|
|
19
|
+
removeByToken(t: Token<unknown> | Constructor): Array<Binding>;
|
|
17
20
|
/** Remove a specific binding by ID. Returns the removed binding or undefined. */
|
|
18
21
|
removeById(id: BindingIdentifier): Binding | undefined;
|
|
19
22
|
/** Get all bindings for a token. */
|
|
20
|
-
getAll(t: Token<unknown> | Constructor):
|
|
23
|
+
getAll(t: Token<unknown> | Constructor): ReadonlyArray<Binding>;
|
|
21
24
|
/** Get binding by ID. */
|
|
22
25
|
getById(id: BindingIdentifier): Binding | undefined;
|
|
23
26
|
/** Check if any binding exists for token. */
|
|
24
27
|
has(t: Token<unknown> | Constructor): boolean;
|
|
25
28
|
/** All bindings in the registry. */
|
|
26
|
-
allBindings():
|
|
29
|
+
allBindings(): ReadonlyArray<Binding>;
|
|
27
30
|
/** Remove all bindings. Returns all removed. */
|
|
28
|
-
clear():
|
|
31
|
+
clear(): ReadonlyArray<Binding>;
|
|
29
32
|
getSimpleNamed(token: Token<unknown> | Constructor, name: string): Binding | undefined;
|
|
30
33
|
getSimpleTagged(token: Token<unknown> | Constructor, tagKey: string, tagValue: unknown): Binding | undefined;
|
|
31
34
|
getFastDefault(token: Token<unknown> | Constructor): Binding | undefined;
|
|
32
35
|
/** Summarize available slot strings for a token (for error messages). */
|
|
33
|
-
availableSlotStrings(t: Token<unknown> | Constructor): string
|
|
36
|
+
availableSlotStrings(t: Token<unknown> | Constructor): Array<string>;
|
|
34
37
|
private _indexSimpleTaggedBinding;
|
|
35
38
|
private _deindexSimpleTaggedBinding;
|
|
36
39
|
private _isPurePredicateBinding;
|