@lppedd/di-wise-neo 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es/index.mjs CHANGED
@@ -80,7 +80,7 @@ class KeyedStack {
80
80
  };
81
81
  }
82
82
  constructor(){
83
- this.myEntries = new Array();
83
+ this.myEntries = [];
84
84
  this.myKeys = new WeakSet();
85
85
  }
86
86
  }
@@ -113,6 +113,7 @@ class WeakRefMap {
113
113
  // @internal
114
114
  function createResolution() {
115
115
  return {
116
+ tokenStack: [],
116
117
  stack: new KeyedStack(),
117
118
  values: new WeakRefMap(),
118
119
  dependents: new WeakRefMap()
@@ -548,7 +549,7 @@ function isDisposable(value) {
548
549
  }
549
550
  // Eager-instantiate only if the class is container-scoped
550
551
  if (metadata.eagerInstantiate && registration.options?.scope === Scope.Container) {
551
- this.resolveProviderValue(registration, registration.provider);
552
+ this.resolveProviderValue(Class, registration);
552
553
  }
553
554
  } else {
554
555
  const [token, provider, options] = args;
@@ -571,7 +572,7 @@ function isDisposable(value) {
571
572
  this.myTokenRegistry.set(token, registration);
572
573
  // Eager-instantiate only if the provided class is container-scoped
573
574
  if (metadata.eagerInstantiate && registration.options?.scope === Scope.Container) {
574
- this.resolveProviderValue(registration, registration.provider);
575
+ this.resolveProviderValue(token, registration);
575
576
  }
576
577
  } else {
577
578
  if (existingProvider) {
@@ -661,17 +662,15 @@ function isDisposable(value) {
661
662
  }
662
663
  resolveRegistration(token, registration, name) {
663
664
  let currRegistration = registration;
664
- let currProvider = currRegistration.provider;
665
- while(isExistingProvider(currProvider)){
666
- const targetToken = currProvider.useExisting;
665
+ while(isExistingProvider(currRegistration.provider)){
666
+ const targetToken = currRegistration.provider.useExisting;
667
667
  currRegistration = this.myTokenRegistry.get(targetToken, name);
668
668
  if (!currRegistration) {
669
669
  throwExistingUnregisteredError(token, targetToken);
670
670
  }
671
- currProvider = currRegistration.provider;
672
671
  }
673
672
  try {
674
- return this.resolveProviderValue(currRegistration, currProvider);
673
+ return this.resolveProviderValue(token, currRegistration);
675
674
  } catch (e) {
676
675
  // If we were trying to resolve a token registered via ExistingProvider,
677
676
  // we must add the cause of the error to the message
@@ -698,16 +697,16 @@ function isDisposable(value) {
698
697
  }
699
698
  return undefined;
700
699
  }
701
- resolveProviderValue(registration, provider) {
702
- check(registration.provider === provider, "internal error: mismatching provider");
700
+ resolveProviderValue(token, registration) {
701
+ const provider = registration.provider;
703
702
  if (isClassProvider(provider)) {
704
703
  const Class = provider.useClass;
705
704
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
706
- return this.resolveScopedValue(registration, (args)=>new Class(...args));
705
+ return this.resolveScopedValue(token, registration, (args)=>new Class(...args));
707
706
  }
708
707
  if (isFactoryProvider(provider)) {
709
708
  const factory = provider.useFactory;
710
- return this.resolveScopedValue(registration, factory);
709
+ return this.resolveScopedValue(token, registration, factory);
711
710
  }
712
711
  if (isValueProvider(provider)) {
713
712
  return provider.useValue;
@@ -715,7 +714,7 @@ function isDisposable(value) {
715
714
  check(!isExistingProvider(provider), "internal error: unexpected ExistingProvider");
716
715
  expectNever(provider);
717
716
  }
718
- resolveScopedValue(registration, factory) {
717
+ resolveScopedValue(token, registration, factory) {
719
718
  let context = useInjectionContext();
720
719
  if (!context || context.container !== this) {
721
720
  context = {
@@ -728,12 +727,16 @@ function isDisposable(value) {
728
727
  const options = registration.options;
729
728
  if (resolution.stack.has(provider)) {
730
729
  const dependentRef = resolution.dependents.get(provider);
731
- check(dependentRef, "circular dependency detected");
730
+ check(dependentRef, ()=>{
731
+ const tokenStack = resolution.tokenStack.map((t)=>t.name).concat(token.name).join(" → ");
732
+ return `circular dependency detected while resolving ${tokenStack}`;
733
+ });
732
734
  return dependentRef.current;
733
735
  }
734
736
  const scope = this.resolveScope(options?.scope, context);
735
737
  const cleanups = [
736
738
  provideInjectionContext(context),
739
+ resolution.tokenStack.push(token) && (()=>resolution.tokenStack.pop()),
737
740
  !isBuilder(provider) && resolution.stack.push(provider, {
738
741
  provider,
739
742
  scope