@codefast/di 0.5.0-canary.3 → 0.5.0-canary.4

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/dist/resolver.mjs CHANGED
@@ -13,7 +13,7 @@ const ROOT_CONSTRAINT_CONTEXT = {
13
13
  resolutionStack: EMPTY_FRAME_LIST,
14
14
  parent: void 0,
15
15
  ancestors: EMPTY_FRAME_LIST,
16
- currentResolveHint: void 0
16
+ currentResolveOptions: void 0
17
17
  };
18
18
  /**
19
19
  * @since 0.3.16-canary.0
@@ -48,23 +48,23 @@ var DependencyResolver = class {
48
48
  this._container = _container;
49
49
  this._parent = _parent;
50
50
  }
51
- _findBinding(token, hint, resolutionPath, resolutionStack) {
52
- if (hint === void 0) {
51
+ _findBinding(token, options, resolutionPath, resolutionStack) {
52
+ if (options === void 0) {
53
53
  const fastDefaultBinding = this._registry.getFastDefault(token);
54
54
  if (fastDefaultBinding !== void 0) return {
55
55
  binding: fastDefaultBinding,
56
56
  owner: this
57
57
  };
58
58
  }
59
- if (hint?.name !== void 0 && hint.tag === void 0 && (hint.tags?.length ?? 0) === 0) {
60
- const namedBinding = this._registry.getSimpleNamed(token, hint.name);
61
- if (namedBinding !== void 0 && this._matchesBindingFast(namedBinding, hint, resolutionPath, resolutionStack)) return {
59
+ if (options?.name !== void 0 && options.tag === void 0 && (options.tags?.length ?? 0) === 0) {
60
+ const namedBinding = this._registry.getSimpleNamed(token, options.name);
61
+ if (namedBinding !== void 0 && this._matchesBindingFast(namedBinding, options, resolutionPath, resolutionStack)) return {
62
62
  binding: namedBinding,
63
63
  owner: this
64
64
  };
65
65
  }
66
- if (hint !== void 0 && hint.name === void 0 && hint.tag === void 0 && (hint.tags?.length ?? 0) === 1) {
67
- const [tagKey, tagValue] = hint.tags[0];
66
+ if (options !== void 0 && options.name === void 0 && options.tag === void 0 && (options.tags?.length ?? 0) === 1) {
67
+ const [tagKey, tagValue] = options.tags[0];
68
68
  const tagged = this._registry.getSimpleTagged(token, tagKey, tagValue);
69
69
  if (tagged !== void 0) return {
70
70
  binding: tagged,
@@ -76,37 +76,37 @@ var DependencyResolver = class {
76
76
  if (bindings.length === 1) {
77
77
  const onlyBinding = bindings[0];
78
78
  const isDefaultSlot = onlyBinding.slot.name === void 0 && onlyBinding.slot.tags.length === 0;
79
- if (hint === void 0 && isDefaultSlot && onlyBinding.predicate === void 0) return {
79
+ if (options === void 0 && isDefaultSlot && onlyBinding.predicate === void 0) return {
80
80
  binding: onlyBinding,
81
81
  owner: this
82
82
  };
83
- if (this._matchesBindingFast(onlyBinding, hint, resolutionPath, resolutionStack)) return {
83
+ if (this._matchesBindingFast(onlyBinding, options, resolutionPath, resolutionStack)) return {
84
84
  binding: onlyBinding,
85
85
  owner: this
86
86
  };
87
87
  }
88
- const binding = selectBinding(bindings, hint, this._makeConstraintContext(resolutionPath, resolutionStack, hint), this._getTokenName(token));
88
+ const binding = selectBinding(bindings, options, this._makeConstraintContext(resolutionPath, resolutionStack, options), this._getTokenName(token));
89
89
  if (binding !== void 0) return {
90
90
  binding,
91
91
  owner: this
92
92
  };
93
93
  }
94
- if (this._parent !== void 0) return this._parent._findBinding(token, hint, resolutionPath, resolutionStack);
94
+ if (this._parent !== void 0) return this._parent._findBinding(token, options, resolutionPath, resolutionStack);
95
95
  }
96
96
  /**
97
97
  * Binding lookup aligned with `resolve` — used by `Container.validate` without instantiating.
98
98
  */
99
- peekBindingForValidate(token, hint) {
100
- return this._findBinding(token, hint, [], []);
99
+ peekBindingForValidate(token, options) {
100
+ return this._findBinding(token, options, [], []);
101
101
  }
102
102
  /**
103
103
  * Mirrors {@link DependencyResolver.resolveAll} candidate selection only (no instantiation).
104
104
  */
105
- peekCandidateBindingsForValidate(token, hint) {
106
- if (hint?.name !== void 0 && hint.tag === void 0 && (hint.tags?.length ?? 0) === 0) return this._getSimpleNamedBindingsFromChain(token, hint.name);
105
+ peekCandidateBindingsForValidate(token, options) {
106
+ if (options?.name !== void 0 && options.tag === void 0 && (options.tags?.length ?? 0) === 0) return this._getSimpleNamedBindingsFromChain(token, options.name);
107
107
  const allBindings = this._getAllBindingsFromChain(token);
108
108
  if (allBindings.length === 0) return [];
109
- return selectAllBindings(allBindings, hint, this._makeConstraintContext([], [], hint));
109
+ return selectAllBindings(allBindings, options, this._makeConstraintContext([], [], options));
110
110
  }
111
111
  resolveFromContext(token, resolutionPath, resolutionStack) {
112
112
  const fastBinding = this._registry.getFastDefault(token);
@@ -123,18 +123,18 @@ var DependencyResolver = class {
123
123
  }
124
124
  return this.resolve(token, void 0, resolutionPath, resolutionStack);
125
125
  }
126
- resolve(token, hint, resolutionPath, resolutionStack) {
127
- const found = this._findBinding(token, hint, resolutionPath, resolutionStack);
126
+ resolve(token, options, resolutionPath, resolutionStack) {
127
+ const found = this._findBinding(token, options, resolutionPath, resolutionStack);
128
128
  if (found === void 0) {
129
- if (this._registry.getAll(token).length > 0) throw new NoMatchingBindingError(this._getTokenName(token), hint ?? {}, this._getAvailableSlots(token));
129
+ if (this._registry.getAll(token).length > 0) throw new NoMatchingBindingError(this._getTokenName(token), options ?? {}, this._getAvailableSlots(token));
130
130
  throw new TokenNotBoundError(this._getTokenName(token));
131
131
  }
132
132
  const { binding, owner } = found;
133
- if (binding.kind === "alias") return this.resolve(binding.target, hint, resolutionPath, resolutionStack);
134
- if ((binding.scope ?? "transient") === "singleton" && owner !== this) return owner._resolveBinding(binding, hint, resolutionPath, resolutionStack);
135
- return this._resolveBinding(binding, hint, resolutionPath, resolutionStack);
133
+ if (binding.kind === "alias") return this.resolve(binding.target, options, resolutionPath, resolutionStack);
134
+ if ((binding.scope ?? "transient") === "singleton" && owner !== this) return owner._resolveBinding(binding, options, resolutionPath, resolutionStack);
135
+ return this._resolveBinding(binding, options, resolutionPath, resolutionStack);
136
136
  }
137
- _resolveBinding(binding, hint, resolutionPath, resolutionStack) {
137
+ _resolveBinding(binding, options, resolutionPath, resolutionStack) {
138
138
  if (binding.kind === "constant" && binding.onActivation === void 0 && !this._lifecycle.hasActivationHandlers(binding.token)) return binding.value;
139
139
  const scope = binding.scope ?? "transient";
140
140
  if (scope === "singleton") {
@@ -158,7 +158,7 @@ var DependencyResolver = class {
158
158
  resolutionStack.push(frame);
159
159
  const needsActivation = this._needsActivation(binding);
160
160
  if (!needsActivation && scope === "transient" && binding.kind === "dynamic") {
161
- const resolutionCtx = this._acquireSyncResolutionContext(resolutionPath, resolutionStack, hint);
161
+ const resolutionCtx = this._acquireSyncResolutionContext(resolutionPath, resolutionStack, options);
162
162
  try {
163
163
  const dynamicResult = binding.factory(resolutionCtx);
164
164
  if (dynamicResult instanceof Promise) throw new AsyncResolutionError(tokenName(binding.token), tokenName(binding.token));
@@ -174,7 +174,7 @@ var DependencyResolver = class {
174
174
  }
175
175
  }
176
176
  try {
177
- const resolutionCtx = needsActivation || this._requiresResolutionContext(binding) ? this._acquireSyncResolutionContext(resolutionPath, resolutionStack, hint) : void 0;
177
+ const resolutionCtx = needsActivation || this._requiresResolutionContext(binding) ? this._acquireSyncResolutionContext(resolutionPath, resolutionStack, options) : void 0;
178
178
  const instance = this._instantiateSync(binding, resolutionCtx, resolutionPath, resolutionStack);
179
179
  const activated = this._refreshActivationCacheIfNeeded(binding, needsActivation) ? this._lifecycle.runActivationSync(resolutionCtx, binding, instance, this._metadataReader) : instance;
180
180
  if (scope === "singleton") this._scope.setSingleton(binding.id, activated);
@@ -219,25 +219,25 @@ var DependencyResolver = class {
219
219
  if (meta.params.length === 0) return [];
220
220
  if (meta.params.length === 1) {
221
221
  const param = meta.params[0];
222
- const paramHint = injectionSlotToResolveOptions(param);
223
- if (param.multi) return [this.resolveAll(param.token, paramHint, resolutionPath, resolutionStack)];
224
- if (param.optional) return [this.resolveOptional(param.token, paramHint, resolutionPath, resolutionStack)];
225
- if (paramHint === void 0) return [this.resolveFromContext(param.token, resolutionPath, resolutionStack)];
226
- return [this.resolve(param.token, paramHint, resolutionPath, resolutionStack)];
222
+ const paramOptions = injectionSlotToResolveOptions(param);
223
+ if (param.multi) return [this.resolveAll(param.token, paramOptions, resolutionPath, resolutionStack)];
224
+ if (param.optional) return [this.resolveOptional(param.token, paramOptions, resolutionPath, resolutionStack)];
225
+ if (paramOptions === void 0) return [this.resolveFromContext(param.token, resolutionPath, resolutionStack)];
226
+ return [this.resolve(param.token, paramOptions, resolutionPath, resolutionStack)];
227
227
  }
228
228
  const deps = new Array(meta.params.length);
229
229
  for (let index = 0; index < meta.params.length; index += 1) {
230
230
  const param = meta.params[index];
231
- const paramHint = injectionSlotToResolveOptions(param);
231
+ const paramOptions = injectionSlotToResolveOptions(param);
232
232
  if (param.multi) {
233
- deps[index] = this.resolveAll(param.token, paramHint, resolutionPath, resolutionStack);
233
+ deps[index] = this.resolveAll(param.token, paramOptions, resolutionPath, resolutionStack);
234
234
  continue;
235
235
  }
236
236
  if (param.optional) {
237
- deps[index] = this.resolveOptional(param.token, paramHint, resolutionPath, resolutionStack);
237
+ deps[index] = this.resolveOptional(param.token, paramOptions, resolutionPath, resolutionStack);
238
238
  continue;
239
239
  }
240
- deps[index] = paramHint === void 0 ? this.resolveFromContext(param.token, resolutionPath, resolutionStack) : this.resolve(param.token, paramHint, resolutionPath, resolutionStack);
240
+ deps[index] = paramOptions === void 0 ? this.resolveFromContext(param.token, resolutionPath, resolutionStack) : this.resolve(param.token, paramOptions, resolutionPath, resolutionStack);
241
241
  }
242
242
  return deps;
243
243
  }
@@ -245,36 +245,36 @@ var DependencyResolver = class {
245
245
  const resolved = new Array(deps.length);
246
246
  for (let index = 0; index < deps.length; index += 1) {
247
247
  const dep = deps[index];
248
- const depHint = injectionSlotToResolveOptions(dep);
248
+ const depOptions = injectionSlotToResolveOptions(dep);
249
249
  if (dep.multi) {
250
- resolved[index] = this.resolveAll(dep.token, depHint, resolutionPath, resolutionStack);
250
+ resolved[index] = this.resolveAll(dep.token, depOptions, resolutionPath, resolutionStack);
251
251
  continue;
252
252
  }
253
253
  if (dep.optional) {
254
- resolved[index] = this.resolveOptional(dep.token, depHint, resolutionPath, resolutionStack);
254
+ resolved[index] = this.resolveOptional(dep.token, depOptions, resolutionPath, resolutionStack);
255
255
  continue;
256
256
  }
257
- resolved[index] = depHint === void 0 ? this.resolveFromContext(dep.token, resolutionPath, resolutionStack) : this.resolve(dep.token, depHint, resolutionPath, resolutionStack);
257
+ resolved[index] = depOptions === void 0 ? this.resolveFromContext(dep.token, resolutionPath, resolutionStack) : this.resolve(dep.token, depOptions, resolutionPath, resolutionStack);
258
258
  }
259
259
  return resolved;
260
260
  }
261
- resolveOptional(token, hint, resolutionPath, resolutionStack) {
262
- if (this._findBinding(token, hint, resolutionPath, resolutionStack) === void 0) return;
263
- return this.resolve(token, hint, resolutionPath, resolutionStack);
261
+ resolveOptional(token, options, resolutionPath, resolutionStack) {
262
+ if (this._findBinding(token, options, resolutionPath, resolutionStack) === void 0) return;
263
+ return this.resolve(token, options, resolutionPath, resolutionStack);
264
264
  }
265
- resolveAll(token, hint, resolutionPath, resolutionStack) {
266
- if (hint?.name !== void 0 && hint.tag === void 0 && (hint.tags?.length ?? 0) === 0) {
267
- const namedCandidates = this._getSimpleNamedBindingsFromChain(token, hint.name);
265
+ resolveAll(token, options, resolutionPath, resolutionStack) {
266
+ if (options?.name !== void 0 && options.tag === void 0 && (options.tags?.length ?? 0) === 0) {
267
+ const namedCandidates = this._getSimpleNamedBindingsFromChain(token, options.name);
268
268
  if (namedCandidates.length === 0) return [];
269
269
  const resolved = new Array(namedCandidates.length);
270
- for (let index = 0; index < namedCandidates.length; index += 1) resolved[index] = this._resolveCandidateSync(namedCandidates[index], hint, resolutionPath, resolutionStack);
270
+ for (let index = 0; index < namedCandidates.length; index += 1) resolved[index] = this._resolveCandidateSync(namedCandidates[index], options, resolutionPath, resolutionStack);
271
271
  return resolved;
272
272
  }
273
273
  const allBindings = this._getAllBindingsFromChain(token);
274
274
  if (allBindings.length === 0) return [];
275
- const candidates = selectAllBindings(allBindings, hint, this._makeConstraintContext(resolutionPath, resolutionStack, hint));
275
+ const candidates = selectAllBindings(allBindings, options, this._makeConstraintContext(resolutionPath, resolutionStack, options));
276
276
  const resolved = new Array(candidates.length);
277
- for (let index = 0; index < candidates.length; index += 1) resolved[index] = this._resolveCandidateSync(candidates[index], hint, resolutionPath, resolutionStack);
277
+ for (let index = 0; index < candidates.length; index += 1) resolved[index] = this._resolveCandidateSync(candidates[index], options, resolutionPath, resolutionStack);
278
278
  return resolved;
279
279
  }
280
280
  resolveAsyncFromContext(token, resolutionPath, resolutionStack) {
@@ -292,18 +292,18 @@ var DependencyResolver = class {
292
292
  }
293
293
  return this.resolveAsync(token, void 0, resolutionPath, resolutionStack);
294
294
  }
295
- async resolveAsync(token, hint, resolutionPath, resolutionStack) {
296
- const found = this._findBinding(token, hint, resolutionPath, resolutionStack);
295
+ async resolveAsync(token, options, resolutionPath, resolutionStack) {
296
+ const found = this._findBinding(token, options, resolutionPath, resolutionStack);
297
297
  if (found === void 0) {
298
- if (this._registry.getAll(token).length > 0) throw new NoMatchingBindingError(this._getTokenName(token), hint ?? {}, this._getAvailableSlots(token));
298
+ if (this._registry.getAll(token).length > 0) throw new NoMatchingBindingError(this._getTokenName(token), options ?? {}, this._getAvailableSlots(token));
299
299
  throw new TokenNotBoundError(this._getTokenName(token));
300
300
  }
301
301
  const { binding, owner } = found;
302
- if (binding.kind === "alias") return this.resolveAsync(binding.target, hint, resolutionPath, resolutionStack);
303
- if ((binding.scope ?? "transient") === "singleton" && owner !== this) return owner._resolveBindingAsync(binding, hint, resolutionPath, resolutionStack);
304
- return this._resolveBindingAsync(binding, hint, resolutionPath, resolutionStack);
302
+ if (binding.kind === "alias") return this.resolveAsync(binding.target, options, resolutionPath, resolutionStack);
303
+ if ((binding.scope ?? "transient") === "singleton" && owner !== this) return owner._resolveBindingAsync(binding, options, resolutionPath, resolutionStack);
304
+ return this._resolveBindingAsync(binding, options, resolutionPath, resolutionStack);
305
305
  }
306
- async _resolveBindingAsync(binding, hint, resolutionPath, resolutionStack) {
306
+ async _resolveBindingAsync(binding, options, resolutionPath, resolutionStack) {
307
307
  if (binding.kind === "constant" && binding.onActivation === void 0 && !this._lifecycle.hasActivationHandlers(binding.token)) return binding.value;
308
308
  const scope = binding.scope ?? "transient";
309
309
  if (scope === "singleton") {
@@ -329,7 +329,7 @@ var DependencyResolver = class {
329
329
  resolutionStack.push(frame);
330
330
  const needsActivation = this._needsActivation(binding);
331
331
  if (!needsActivation && scope === "transient" && (binding.kind === "dynamic" || binding.kind === "dynamic-async")) {
332
- const resolutionCtx = new DefaultResolutionContext(this, resolutionPath, resolutionStack, hint);
332
+ const resolutionCtx = new DefaultResolutionContext(this, resolutionPath, resolutionStack, options);
333
333
  try {
334
334
  if (binding.kind === "dynamic-async") return await binding.factory(resolutionCtx);
335
335
  const dynamicResult = binding.factory(resolutionCtx);
@@ -340,7 +340,7 @@ var DependencyResolver = class {
340
340
  resolutionSet?.delete(frameName);
341
341
  }
342
342
  }
343
- const resolutionCtx = needsActivation || this._requiresResolutionContext(binding) ? new DefaultResolutionContext(this, resolutionPath, resolutionStack, hint) : void 0;
343
+ const resolutionCtx = needsActivation || this._requiresResolutionContext(binding) ? new DefaultResolutionContext(this, resolutionPath, resolutionStack, options) : void 0;
344
344
  try {
345
345
  if (scope === "singleton") {
346
346
  const createSingletonPromise = async () => {
@@ -404,20 +404,20 @@ var DependencyResolver = class {
404
404
  if (meta.params.length === 0) return [];
405
405
  if (meta.params.length === 1) {
406
406
  const param = meta.params[0];
407
- const paramHint = injectionSlotToResolveOptions(param);
408
- if (param.multi) return [await this.resolveAllAsync(param.token, paramHint, resolutionPath, resolutionStack)];
409
- if (param.optional) return [await this.resolveOptionalAsync(param.token, paramHint, resolutionPath, resolutionStack)];
410
- if (paramHint === void 0) return [await this.resolveAsyncFromContext(param.token, resolutionPath, resolutionStack)];
411
- return [await this.resolveAsync(param.token, paramHint, resolutionPath, resolutionStack)];
407
+ const paramOptions = injectionSlotToResolveOptions(param);
408
+ if (param.multi) return [await this.resolveAllAsync(param.token, paramOptions, resolutionPath, resolutionStack)];
409
+ if (param.optional) return [await this.resolveOptionalAsync(param.token, paramOptions, resolutionPath, resolutionStack)];
410
+ if (paramOptions === void 0) return [await this.resolveAsyncFromContext(param.token, resolutionPath, resolutionStack)];
411
+ return [await this.resolveAsync(param.token, paramOptions, resolutionPath, resolutionStack)];
412
412
  }
413
413
  const pending = new Array(meta.params.length);
414
414
  const shouldCloneContext = meta.params.length > 1;
415
415
  for (let index = 0; index < meta.params.length; index += 1) {
416
416
  const param = meta.params[index];
417
- const paramHint = injectionSlotToResolveOptions(param);
418
- if (param.multi) pending[index] = this.resolveAllAsync(param.token, paramHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
419
- else if (param.optional) pending[index] = this.resolveOptionalAsync(param.token, paramHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
420
- else pending[index] = paramHint === void 0 ? this.resolveAsyncFromContext(param.token, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack) : this.resolveAsync(param.token, paramHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
417
+ const paramOptions = injectionSlotToResolveOptions(param);
418
+ if (param.multi) pending[index] = this.resolveAllAsync(param.token, paramOptions, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
419
+ else if (param.optional) pending[index] = this.resolveOptionalAsync(param.token, paramOptions, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
420
+ else pending[index] = paramOptions === void 0 ? this.resolveAsyncFromContext(param.token, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack) : this.resolveAsync(param.token, paramOptions, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
421
421
  }
422
422
  return Promise.all(pending);
423
423
  }
@@ -426,30 +426,30 @@ var DependencyResolver = class {
426
426
  const shouldCloneContext = deps.length > 1;
427
427
  for (let index = 0; index < deps.length; index += 1) {
428
428
  const dep = deps[index];
429
- const depHint = injectionSlotToResolveOptions(dep);
430
- if (dep.multi) pending[index] = this.resolveAllAsync(dep.token, depHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
431
- else if (dep.optional) pending[index] = this.resolveOptionalAsync(dep.token, depHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
432
- else pending[index] = depHint === void 0 ? this.resolveAsyncFromContext(dep.token, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack) : this.resolveAsync(dep.token, depHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
429
+ const depOptions = injectionSlotToResolveOptions(dep);
430
+ if (dep.multi) pending[index] = this.resolveAllAsync(dep.token, depOptions, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
431
+ else if (dep.optional) pending[index] = this.resolveOptionalAsync(dep.token, depOptions, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
432
+ else pending[index] = depOptions === void 0 ? this.resolveAsyncFromContext(dep.token, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack) : this.resolveAsync(dep.token, depOptions, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
433
433
  }
434
434
  return Promise.all(pending);
435
435
  }
436
- async resolveOptionalAsync(token, hint, resolutionPath, resolutionStack) {
437
- if (this._findBinding(token, hint, resolutionPath, resolutionStack) === void 0) return;
438
- return this.resolveAsync(token, hint, resolutionPath, resolutionStack);
436
+ async resolveOptionalAsync(token, options, resolutionPath, resolutionStack) {
437
+ if (this._findBinding(token, options, resolutionPath, resolutionStack) === void 0) return;
438
+ return this.resolveAsync(token, options, resolutionPath, resolutionStack);
439
439
  }
440
- async resolveAllAsync(token, hint, resolutionPath, resolutionStack) {
441
- if (hint?.name !== void 0 && hint.tag === void 0 && (hint.tags?.length ?? 0) === 0) {
442
- const namedCandidates = this._getSimpleNamedBindingsFromChain(token, hint.name);
440
+ async resolveAllAsync(token, options, resolutionPath, resolutionStack) {
441
+ if (options?.name !== void 0 && options.tag === void 0 && (options.tags?.length ?? 0) === 0) {
442
+ const namedCandidates = this._getSimpleNamedBindingsFromChain(token, options.name);
443
443
  if (namedCandidates.length === 0) return [];
444
444
  const pending = new Array(namedCandidates.length);
445
- for (let index = 0; index < namedCandidates.length; index += 1) pending[index] = this._resolveCandidateAsync(namedCandidates[index], hint, resolutionPath, resolutionStack);
445
+ for (let index = 0; index < namedCandidates.length; index += 1) pending[index] = this._resolveCandidateAsync(namedCandidates[index], options, resolutionPath, resolutionStack);
446
446
  return Promise.all(pending);
447
447
  }
448
448
  const allBindings = this._getAllBindingsFromChain(token);
449
449
  if (allBindings.length === 0) return [];
450
- const candidates = selectAllBindings(allBindings, hint, this._makeConstraintContext(resolutionPath, resolutionStack, hint));
450
+ const candidates = selectAllBindings(allBindings, options, this._makeConstraintContext(resolutionPath, resolutionStack, options));
451
451
  const pending = new Array(candidates.length);
452
- for (let index = 0; index < candidates.length; index += 1) pending[index] = this._resolveCandidateAsync(candidates[index], hint, resolutionPath, resolutionStack);
452
+ for (let index = 0; index < candidates.length; index += 1) pending[index] = this._resolveCandidateAsync(candidates[index], options, resolutionPath, resolutionStack);
453
453
  return Promise.all(pending);
454
454
  }
455
455
  _getAllBindingsFromChain(token) {
@@ -480,34 +480,34 @@ var DependencyResolver = class {
480
480
  _getAvailableSlots(token) {
481
481
  return this._registry.availableSlotStrings(token);
482
482
  }
483
- _makeConstraintContext(resolutionPath, resolutionStack, hint) {
484
- if (hint === void 0 && resolutionPath.length === 0 && resolutionStack.length === 0) return ROOT_CONSTRAINT_CONTEXT;
483
+ _makeConstraintContext(resolutionPath, resolutionStack, options) {
484
+ if (options === void 0 && resolutionPath.length === 0 && resolutionStack.length === 0) return ROOT_CONSTRAINT_CONTEXT;
485
485
  return {
486
486
  resolutionPath,
487
487
  resolutionStack,
488
488
  parent: resolutionStack.at(-1),
489
489
  ancestors: resolutionStack.length > 1 ? resolutionStack.slice(0, -1) : [],
490
- currentResolveHint: hint
490
+ currentResolveOptions: options
491
491
  };
492
492
  }
493
- _matchesBindingFast(binding, hint, resolutionPath, resolutionStack) {
494
- if (!this._matchesSlotFast(binding.slot, hint)) return false;
493
+ _matchesBindingFast(binding, options, resolutionPath, resolutionStack) {
494
+ if (!this._matchesSlotFast(binding.slot, options)) return false;
495
495
  if (binding.predicate === void 0) return true;
496
- const ctx = this._makeConstraintContext(resolutionPath, resolutionStack, hint);
496
+ const ctx = this._makeConstraintContext(resolutionPath, resolutionStack, options);
497
497
  return binding.predicate(ctx);
498
498
  }
499
- _matchesSlotFast(slot, hint) {
500
- const hintName = hint?.name;
501
- const hintTags = hint?.tags;
502
- const singleHintTag = hint?.tag;
503
- const hasHintTags = (hintTags?.length ?? 0) > 0 || singleHintTag !== void 0;
499
+ _matchesSlotFast(slot, options) {
500
+ const requestedName = options?.name;
501
+ const requestedTags = options?.tags;
502
+ const singleRequestedTag = options?.tag;
503
+ const hasRequestedTags = (requestedTags?.length ?? 0) > 0 || singleRequestedTag !== void 0;
504
504
  if (slot.name !== void 0) {
505
- if (hintName === void 0 || slot.name !== hintName) return false;
506
- } else if (hintName !== void 0) return false;
505
+ if (requestedName === void 0 || slot.name !== requestedName) return false;
506
+ } else if (requestedName !== void 0) return false;
507
507
  if (slot.tags.length > 0) {
508
- if (!hasHintTags) return false;
509
- for (const [tagKey, tagValue] of slot.tags) if (!this._matchesHintTag(tagKey, tagValue, hintTags, singleHintTag)) return false;
510
- } else if (hasHintTags) return false;
508
+ if (!hasRequestedTags) return false;
509
+ for (const [tagKey, tagValue] of slot.tags) if (!this._matchesRequestedTag(tagKey, tagValue, requestedTags, singleRequestedTag)) return false;
510
+ } else if (hasRequestedTags) return false;
511
511
  return true;
512
512
  }
513
513
  _getTokenName(token) {
@@ -530,12 +530,12 @@ var DependencyResolver = class {
530
530
  if (!needsActiveContainer) return new invokable(...deps);
531
531
  return runWithContainer(this._container, () => new invokable(...deps));
532
532
  }
533
- _matchesHintTag(tagKey, tagValue, hintTags, singleHintTag) {
534
- if (singleHintTag !== void 0 && singleHintTag[0] === tagKey && Object.is(singleHintTag[1], tagValue)) return true;
535
- if (hintTags === void 0 || hintTags.length === 0) return false;
536
- for (let index = 0; index < hintTags.length; index += 1) {
537
- const hintTag = hintTags[index];
538
- if (hintTag[0] === tagKey && Object.is(hintTag[1], tagValue)) return true;
533
+ _matchesRequestedTag(tagKey, tagValue, requestedTags, singleRequestedTag) {
534
+ if (singleRequestedTag !== void 0 && singleRequestedTag[0] === tagKey && Object.is(singleRequestedTag[1], tagValue)) return true;
535
+ if (requestedTags === void 0 || requestedTags.length === 0) return false;
536
+ for (let index = 0; index < requestedTags.length; index += 1) {
537
+ const requestedTag = requestedTags[index];
538
+ if (requestedTag[0] === tagKey && Object.is(requestedTag[1], tagValue)) return true;
539
539
  }
540
540
  return false;
541
541
  }
@@ -676,29 +676,29 @@ var DependencyResolver = class {
676
676
  resolutionSet.delete(tokenDisplayName);
677
677
  }
678
678
  }
679
- _resolveCandidateSync(binding, hint, resolutionPath, resolutionStack) {
679
+ _resolveCandidateSync(binding, options, resolutionPath, resolutionStack) {
680
680
  if (binding.kind === "constant" && binding.onActivation === void 0 && !this._lifecycle.hasActivationHandlers(binding.token)) return binding.value;
681
- if (binding.kind === "alias") return this.resolve(binding.target, hint, resolutionPath, resolutionStack);
681
+ if (binding.kind === "alias") return this.resolve(binding.target, options, resolutionPath, resolutionStack);
682
682
  const scope = binding.scope ?? "transient";
683
683
  if (scope === "singleton" && this._scope.hasSingleton(binding.id)) return this._scope.getSingleton(binding.id);
684
684
  if (scope === "scoped") {
685
685
  if (!this._scope.isChild) throw new MissingScopeContextError(this._getTokenName(binding.token));
686
686
  if (this._scope.hasScoped(binding.id)) return this._scope.getScoped(binding.id);
687
687
  }
688
- return this._resolveBinding(binding, hint, resolutionPath, resolutionStack);
688
+ return this._resolveBinding(binding, options, resolutionPath, resolutionStack);
689
689
  }
690
- _resolveCandidateAsync(binding, hint, resolutionPath, resolutionStack) {
690
+ _resolveCandidateAsync(binding, options, resolutionPath, resolutionStack) {
691
691
  if (binding.kind === "constant" && binding.onActivation === void 0 && !this._lifecycle.hasActivationHandlers(binding.token)) return Promise.resolve(binding.value);
692
692
  const isolatedPath = [...resolutionPath];
693
693
  const isolatedStack = [...resolutionStack];
694
- if (binding.kind === "alias") return this.resolveAsync(binding.target, hint, isolatedPath, isolatedStack);
694
+ if (binding.kind === "alias") return this.resolveAsync(binding.target, options, isolatedPath, isolatedStack);
695
695
  const scope = binding.scope ?? "transient";
696
696
  if (scope === "singleton" && this._scope.hasSingleton(binding.id)) return Promise.resolve(this._scope.getSingleton(binding.id));
697
697
  if (scope === "scoped") {
698
698
  if (!this._scope.isChild) return Promise.reject(new MissingScopeContextError(this._getTokenName(binding.token)));
699
699
  if (this._scope.hasScoped(binding.id)) return Promise.resolve(this._scope.getScoped(binding.id));
700
700
  }
701
- return this._resolveBindingAsync(binding, hint, isolatedPath, isolatedStack);
701
+ return this._resolveBindingAsync(binding, options, isolatedPath, isolatedStack);
702
702
  }
703
703
  _getResolutionFrame(binding) {
704
704
  const existing = this._frameByBindingId.get(binding.id);
@@ -751,14 +751,14 @@ var DependencyResolver = class {
751
751
  _requiresResolutionContext(binding) {
752
752
  return binding.kind === "dynamic" || binding.kind === "dynamic-async";
753
753
  }
754
- _acquireSyncResolutionContext(resolutionPath, resolutionStack, hint) {
754
+ _acquireSyncResolutionContext(resolutionPath, resolutionStack, options) {
755
755
  const depth = resolutionStack.length;
756
756
  const existing = this._syncResolutionContextPool[depth];
757
757
  if (existing !== void 0) {
758
- existing.reset(this, resolutionPath, resolutionStack, hint);
758
+ existing.reset(this, resolutionPath, resolutionStack, options);
759
759
  return existing;
760
760
  }
761
- const created = new DefaultResolutionContext(this, resolutionPath, resolutionStack, hint);
761
+ const created = new DefaultResolutionContext(this, resolutionPath, resolutionStack, options);
762
762
  this._syncResolutionContextPool[depth] = created;
763
763
  return created;
764
764
  }
package/dist/types.d.mts CHANGED
@@ -3,7 +3,7 @@ import { Token } from "./token.mjs";
3
3
 
4
4
  //#region src/types.d.ts
5
5
  /**
6
- * A single [tag, value] pair used in slot constraints and resolve hints.
6
+ * A single [tag, value] pair used in slot constraints and resolve options.
7
7
  *
8
8
  * @since 0.3.16-canary.0
9
9
  */
@@ -70,18 +70,18 @@ interface ConstraintContext {
70
70
  readonly resolutionStack: ReadonlyArray<ResolutionFrame>;
71
71
  readonly parent: ResolutionFrame | undefined;
72
72
  readonly ancestors: ReadonlyArray<ResolutionFrame>;
73
- readonly currentResolveHint: ResolveOptions | undefined;
73
+ readonly currentResolveOptions: ResolveOptions | undefined;
74
74
  }
75
75
  /**
76
76
  * @since 0.3.16-canary.0
77
77
  */
78
78
  interface ResolutionContext {
79
- resolve<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Value;
80
- resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Promise<Value>;
81
- resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Value | undefined;
82
- resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Promise<Value | undefined>;
83
- resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Array<Value>;
84
- resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Promise<Array<Value>>;
79
+ resolve<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Value;
80
+ resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Promise<Value>;
81
+ resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Value | undefined;
82
+ resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Promise<Value | undefined>;
83
+ resolveAll<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Array<Value>;
84
+ resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Promise<Array<Value>>;
85
85
  readonly graph: ConstraintContext;
86
86
  }
87
87
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codefast/di",
3
- "version": "0.5.0-canary.3",
3
+ "version": "0.5.0-canary.4",
4
4
  "description": "Lightweight dependency injection primitives for Codefast",
5
5
  "keywords": [
6
6
  "codefast",
@@ -200,14 +200,14 @@
200
200
  "@babel/plugin-proposal-decorators": "8.0.2",
201
201
  "@rolldown/plugin-babel": "^0.2.3",
202
202
  "@types/node": "^26.1.0",
203
- "@typescript/native-preview": "7.0.0-dev.20260703.1",
203
+ "@typescript/native-preview": "7.0.0-dev.20260704.1",
204
204
  "@vitest/coverage-v8": "^4.1.9",
205
205
  "expect-type": "^1.4.0",
206
206
  "tsdown": "^0.22.3",
207
207
  "tsx": "^4.23.0",
208
208
  "typescript": "^6.0.3",
209
209
  "vitest": "^4.1.9",
210
- "@codefast/typescript-config": "0.5.0-canary.3"
210
+ "@codefast/typescript-config": "0.5.0-canary.4"
211
211
  },
212
212
  "engines": {
213
213
  "node": ">=26.0.0"