@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.
Files changed (45) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +8 -5
  3. package/dist/binding-select.d.mts +2 -2
  4. package/dist/binding-select.mjs +5 -5
  5. package/dist/binding.d.mts +12 -12
  6. package/dist/binding.mjs +8 -8
  7. package/dist/constraints.d.mts +25 -9
  8. package/dist/constraints.mjs +47 -19
  9. package/dist/constructor-type.d.mts +2 -2
  10. package/dist/container.d.mts +6 -6
  11. package/dist/container.mjs +202 -121
  12. package/dist/decorators/inject.d.mts +4 -4
  13. package/dist/decorators/inject.mjs +21 -19
  14. package/dist/decorators/injectable.d.mts +1 -1
  15. package/dist/decorators/injectable.mjs +18 -14
  16. package/dist/decorators/lifecycle-decorators.mjs +3 -0
  17. package/dist/dependency-graph.d.mts +2 -2
  18. package/dist/dependency-graph.mjs +13 -13
  19. package/dist/environment.d.mts +17 -17
  20. package/dist/environment.mjs +21 -21
  21. package/dist/errors.d.mts +18 -8
  22. package/dist/errors.mjs +17 -1
  23. package/dist/graph-adapters/reactflow.d.mts +2 -2
  24. package/dist/index.d.mts +6 -5
  25. package/dist/index.mjs +5 -4
  26. package/dist/inspector.d.mts +2 -3
  27. package/dist/inspector.mjs +18 -16
  28. package/dist/lifecycle.d.mts +5 -6
  29. package/dist/lifecycle.mjs +45 -52
  30. package/dist/metadata/metadata-keys.d.mts +24 -1
  31. package/dist/metadata/metadata-keys.mjs +14 -1
  32. package/dist/metadata/metadata-types.d.mts +5 -5
  33. package/dist/metadata/symbol-metadata-reader.mjs +31 -24
  34. package/dist/module.d.mts +2 -2
  35. package/dist/module.mjs +2 -2
  36. package/dist/registry.d.mts +6 -6
  37. package/dist/registry.mjs +55 -62
  38. package/dist/resolve-options.d.mts +5 -5
  39. package/dist/resolve-options.mjs +8 -8
  40. package/dist/resolver.d.mts +22 -10
  41. package/dist/resolver.mjs +206 -185
  42. package/dist/token.d.mts +1 -1
  43. package/dist/token.mjs +4 -4
  44. package/dist/types.d.mts +12 -8
  45. package/package.json +15 -8
@@ -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: snapshots,
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((b) => this._toSnapshot(b));
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
- materializationStack: [],
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
- materializationStack: [],
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((b) => this._toSnapshot(b));
56
+ return this._registry.allBindings().map((binding) => this._toSnapshot(binding));
55
57
  }
56
- _toSnapshot(b) {
57
- const scope = effectiveBindingScope(b);
58
- const slot = b.slot.name !== void 0 ? {
59
- name: b.slot.name,
60
- tags: b.slot.tags
61
- } : { tags: b.slot.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(b.token),
64
- kind: b.kind,
65
+ tokenName: tokenName(binding.token),
66
+ kind: binding.kind,
65
67
  scope,
66
68
  slot,
67
- id: b.id
69
+ id: binding.id
68
70
  };
69
71
  }
70
72
  };
@@ -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>(t: Token<Value> | Constructor<Value>, handler: ActivationHandler<Value>): void;
16
- hasActivationHandlers<const Value>(t: Token<Value> | Constructor<Value>): boolean;
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>(t: Token<Value> | Constructor<Value>, handler: DeactivationHandler<Value>): void;
19
- runActivation<const Value>(ctx: ResolutionContext, binding: Binding<Value>, instance: Value, metadataReader: MetadataReader): Promise<Value>;
20
- runActivationSync<const Value>(ctx: ResolutionContext, binding: Binding<Value>, instance: Value, metadataReader: MetadataReader): 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 };
@@ -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(t, handler) {
11
+ registerActivation(token, handler) {
12
12
  this._activationVersion += 1;
13
- let list = this._activationHooks.get(t);
13
+ let list = this._activationHooks.get(token);
14
14
  if (list === void 0) {
15
15
  list = [];
16
- this._activationHooks.set(t, list);
16
+ this._activationHooks.set(token, list);
17
17
  }
18
18
  list.push(handler);
19
19
  }
20
- hasActivationHandlers(t) {
20
+ hasActivationHandlers(token) {
21
21
  if (this._activationHooks.size === 0) return false;
22
- const list = this._activationHooks.get(t);
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(t, handler) {
29
- let list = this._deactivationHooks.get(t);
28
+ registerDeactivation(token, handler) {
29
+ let list = this._deactivationHooks.get(token);
30
30
  if (list === void 0) {
31
31
  list = [];
32
- this._deactivationHooks.set(t, list);
32
+ this._deactivationHooks.set(token, list);
33
33
  }
34
34
  list.push(handler);
35
35
  }
36
- async runActivation(ctx, binding, instance, metadataReader) {
37
- let result = instance;
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 = result[methodName];
41
+ const method = activatedInstance[methodName];
42
42
  if (typeof method === "function") {
43
- const r = method.call(result);
44
- if (r instanceof Promise) await r;
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 activated = binding.onActivation(ctx, result);
50
- result = activated instanceof Promise ? await activated : activated;
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 activated = hook(ctx, result);
55
- result = activated instanceof Promise ? await activated : activated;
54
+ const activationResult = hook(resolutionContext, activatedInstance);
55
+ activatedInstance = activationResult instanceof Promise ? await activationResult : activationResult;
56
56
  }
57
- return result;
57
+ return activatedInstance;
58
58
  }
59
- runActivationSync(ctx, binding, instance, metadataReader) {
60
- let result = instance;
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 = result[methodName];
64
+ const method = activatedInstance[methodName];
65
65
  if (typeof method === "function") {
66
- if (method.call(result) instanceof Promise) throw new Error(`@postConstruct method '${methodName}' returned a Promise. Use resolveAsync() instead.`);
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 activated = binding.onActivation(ctx, result);
72
- if (activated instanceof Promise) throw new Error(`onActivation for '${tokenName(binding.token)}' returned a Promise. Use resolveAsync() instead.`);
73
- result = activated;
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 key = tokenName(binding.token);
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 activated = hook(ctx, result);
79
- if (activated instanceof Promise) throw new Error(`Container-level onActivation for '${key}' returned a Promise. Use resolveAsync() instead.`);
80
- result = activated;
78
+ const activationResult = hook(resolutionContext, activatedInstance);
79
+ if (activationResult instanceof Promise) throw new AsyncActivationError(tokenDisplayName, "onActivation");
80
+ activatedInstance = activationResult;
81
81
  }
82
- return result;
82
+ return activatedInstance;
83
83
  }
84
84
  async runDeactivation(binding, instance, metadataReader) {
85
- const key = binding.token;
86
- const containerHooks = this._deactivationHooks.get(key);
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 r = hook(instance);
89
- if (r instanceof Promise) await r;
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 r = binding.onDeactivation(instance);
93
- if (r instanceof Promise) await r;
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 r = method.call(instance);
101
- if (r instanceof Promise) await r;
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 tName = tokenName(binding.token);
108
- const key = binding.token;
109
- const containerHooks = this._deactivationHooks.get(key);
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(tName);
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(tName);
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(tName);
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: readonly ParamMetadata[];
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: readonly string[];
27
- readonly preDestroy: readonly string[];
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 fromWeakMap = constructorMetadataMap.get(target);
9
- if (fromWeakMap !== void 0) return fromWeakMap;
10
- const own = Object.getOwnPropertyDescriptor(target, Symbol.metadata);
11
- if (own === void 0) return;
12
- const meta = own.value;
13
- if (!meta || typeof meta !== "object" || !Object.hasOwn(meta, INJECTABLE_KEY)) return;
14
- return meta[INJECTABLE_KEY];
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 byConstructor = lifecycleByConstructorMetadataMap.get(target);
18
- if (byConstructor !== void 0) return byConstructor;
19
- const own = Object.getOwnPropertyDescriptor(target, Symbol.metadata);
20
- if (own !== void 0) {
21
- const meta = own.value;
22
- if (meta && typeof meta === "object" && Object.hasOwn(meta, LIFECYCLE_KEY)) return meta[LIFECYCLE_KEY];
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 classMeta = target[Symbol.metadata];
25
- if (classMeta !== void 0) {
26
- const fromWeakMap = lifecycleMetadataMap.get(classMeta);
27
- if (fromWeakMap !== void 0) return fromWeakMap;
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 own = Object.getOwnPropertyDescriptor(target, Symbol.metadata);
32
- if (own === void 0) return;
33
- const meta = own.value;
34
- if (!meta || typeof meta !== "object") return;
35
- if (!Object.hasOwn(meta, INJECT_ACCESSOR_KEY)) return;
36
- return meta[INJECT_ACCESSOR_KEY];
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[]): void;
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(m: SyncModule | AsyncModule): m is SyncModule;
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(m) {
39
- return m[SYNC_MODULE_BRAND] === true;
38
+ function isSyncModule(module) {
39
+ return module[SYNC_MODULE_BRAND] === true;
40
40
  }
41
41
  //#endregion
42
42
  export { AsyncModule, Module, SyncModule, isSyncModule };
@@ -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(t: Token<unknown> | Constructor): Binding[];
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(t: Token<unknown> | Constructor): readonly Binding[];
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(t: Token<unknown> | Constructor): boolean;
27
+ has(token: Token<unknown> | Constructor): boolean;
28
28
  /** All bindings in the registry. */
29
- allBindings(): readonly Binding[];
29
+ allBindings(): ReadonlyArray<Binding>;
30
30
  /** Remove all bindings. Returns all removed. */
31
- clear(): readonly Binding[];
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(t: Token<unknown> | Constructor): string[];
36
+ availableSlotStrings(token: Token<unknown> | Constructor): Array<string>;
37
37
  private _indexSimpleTaggedBinding;
38
38
  private _deindexSimpleTaggedBinding;
39
39
  private _isPurePredicateBinding;