@lppedd/di-wise-neo 0.20.0 → 0.21.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/dist/cjs/index.d.ts +4 -2
- package/dist/cjs/index.js +46 -21
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.mts +4 -2
- package/dist/es/index.mjs +46 -21
- package/dist/es/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/cjs/index.d.ts
CHANGED
|
@@ -627,11 +627,13 @@ interface Container {
|
|
|
627
627
|
* Disposes this container and all its cached values.
|
|
628
628
|
*
|
|
629
629
|
* Token values implementing a `Disposable` interface (e.g., objects with a `dispose()` function)
|
|
630
|
-
* are
|
|
630
|
+
* are also disposed. All disposals, whether synchronous or asynchronous, are returned as promises
|
|
631
|
+
* in an array. Callers may await these promises (e.g., using `Promise.allSettled()`) if they want
|
|
632
|
+
* to ensure that all async work has completed.
|
|
631
633
|
*
|
|
632
634
|
* Note that children containers are disposed first, in creation order.
|
|
633
635
|
*/
|
|
634
|
-
dispose():
|
|
636
|
+
dispose(): Promise<unknown>[];
|
|
635
637
|
}
|
|
636
638
|
/**
|
|
637
639
|
* Creates a new container.
|
package/dist/cjs/index.js
CHANGED
|
@@ -57,7 +57,7 @@ function getTokenName(token) {
|
|
|
57
57
|
}
|
|
58
58
|
function getFullTokenName([token, name]) {
|
|
59
59
|
const tokenName = token ? token.name || "<unnamed>" : "<undefined token>";
|
|
60
|
-
return name ? `${tokenName}["${name}"]` : tokenName;
|
|
60
|
+
return name !== undefined ? `${tokenName}["${name}"]` : tokenName;
|
|
61
61
|
}
|
|
62
62
|
function getCause(error) {
|
|
63
63
|
if (!error) {
|
|
@@ -104,7 +104,7 @@ class KeyedStack {
|
|
|
104
104
|
return this.myEntries.at(-1)?.value;
|
|
105
105
|
}
|
|
106
106
|
push(key, value) {
|
|
107
|
-
check(!this.has(key), "invariant violation");
|
|
107
|
+
check(!this.has(key), "internal: invariant violation");
|
|
108
108
|
this.myKeys.add(key);
|
|
109
109
|
this.myEntries.push({
|
|
110
110
|
key,
|
|
@@ -135,7 +135,7 @@ class WeakRefMap {
|
|
|
135
135
|
return undefined;
|
|
136
136
|
}
|
|
137
137
|
set(key, value) {
|
|
138
|
-
check(!this.get(key), "invariant violation");
|
|
138
|
+
check(!this.get(key), "internal: invariant violation");
|
|
139
139
|
this.myMap.set(key, new WeakRef(value));
|
|
140
140
|
return ()=>{
|
|
141
141
|
this.myMap.delete(key);
|
|
@@ -230,7 +230,7 @@ function tokenRef(token) {
|
|
|
230
230
|
return {
|
|
231
231
|
getRefToken: ()=>{
|
|
232
232
|
const tokenOrTokens = token();
|
|
233
|
-
check(!Array.isArray(tokenOrTokens), "internal
|
|
233
|
+
check(!Array.isArray(tokenOrTokens), "internal: unexpected array of tokens");
|
|
234
234
|
return tokenOrTokens;
|
|
235
235
|
},
|
|
236
236
|
getRefTokens: ()=>{
|
|
@@ -262,7 +262,7 @@ class Metadata {
|
|
|
262
262
|
this.tokenRef = {
|
|
263
263
|
// prettier-ignore
|
|
264
264
|
getRefToken: ()=>{
|
|
265
|
-
check(false, "internal
|
|
265
|
+
check(false, "internal: unexpected getRefToken call");
|
|
266
266
|
},
|
|
267
267
|
getRefTokens: ()=>new Set()
|
|
268
268
|
};
|
|
@@ -471,6 +471,7 @@ function isConstructor(token) {
|
|
|
471
471
|
|
|
472
472
|
// @internal
|
|
473
473
|
function getTypeName(value) {
|
|
474
|
+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
474
475
|
switch(typeof value){
|
|
475
476
|
case "string":
|
|
476
477
|
return `"${value}"`;
|
|
@@ -511,7 +512,7 @@ class TokenRegistry {
|
|
|
511
512
|
] || this.getAllFromParent(token, name);
|
|
512
513
|
}
|
|
513
514
|
put(token, registration) {
|
|
514
|
-
check(!internals.has(token), `cannot register reserved token ${token.name}`);
|
|
515
|
+
check(!internals.has(token), `internal: cannot register reserved token ${token.name}`);
|
|
515
516
|
let registrations = this.myRegistrations.get(token);
|
|
516
517
|
if (registrations) {
|
|
517
518
|
const name = registration.name;
|
|
@@ -544,8 +545,12 @@ class TokenRegistry {
|
|
|
544
545
|
return registrations;
|
|
545
546
|
}
|
|
546
547
|
deleteAll() {
|
|
547
|
-
const tokens =
|
|
548
|
-
|
|
548
|
+
const tokens = [
|
|
549
|
+
...this.myRegistrations.keys()
|
|
550
|
+
];
|
|
551
|
+
const registrations = [
|
|
552
|
+
...this.myRegistrations.values()
|
|
553
|
+
].flat();
|
|
549
554
|
this.myRegistrations.clear();
|
|
550
555
|
return [
|
|
551
556
|
tokens,
|
|
@@ -563,13 +568,15 @@ class TokenRegistry {
|
|
|
563
568
|
registration.valueRef = undefined;
|
|
564
569
|
}
|
|
565
570
|
}
|
|
566
|
-
return
|
|
571
|
+
return [
|
|
572
|
+
...values
|
|
573
|
+
];
|
|
567
574
|
}
|
|
568
575
|
getAllFromParent(token, name) {
|
|
569
576
|
let registrations = this.myRegistrations.get(token) || this.myParent?.getAllFromParent(token, name);
|
|
570
577
|
if (registrations && name !== undefined) {
|
|
571
578
|
registrations = registrations.filter((r)=>r.name === name);
|
|
572
|
-
check(registrations.length < 2, `internal
|
|
579
|
+
check(registrations.length < 2, `internal: multiple registrations with name '${name}'`);
|
|
573
580
|
}
|
|
574
581
|
return registrations ?? [];
|
|
575
582
|
}
|
|
@@ -661,7 +668,9 @@ function isDisposable(value) {
|
|
|
661
668
|
values.add(valueRef.current);
|
|
662
669
|
}
|
|
663
670
|
}
|
|
664
|
-
return
|
|
671
|
+
return [
|
|
672
|
+
...values
|
|
673
|
+
];
|
|
665
674
|
}
|
|
666
675
|
resetRegistry() {
|
|
667
676
|
this.checkDisposed();
|
|
@@ -672,7 +681,9 @@ function isDisposable(value) {
|
|
|
672
681
|
values.add(valueRef.current);
|
|
673
682
|
}
|
|
674
683
|
}
|
|
675
|
-
return
|
|
684
|
+
return [
|
|
685
|
+
...values
|
|
686
|
+
];
|
|
676
687
|
}
|
|
677
688
|
isRegistered(token, name) {
|
|
678
689
|
this.checkDisposed();
|
|
@@ -701,7 +712,9 @@ function isDisposable(value) {
|
|
|
701
712
|
values.add(valueRef.current);
|
|
702
713
|
}
|
|
703
714
|
}
|
|
704
|
-
return
|
|
715
|
+
return [
|
|
716
|
+
...values
|
|
717
|
+
];
|
|
705
718
|
}
|
|
706
719
|
resolve(token, name) {
|
|
707
720
|
this.checkDisposed();
|
|
@@ -720,20 +733,23 @@ function isDisposable(value) {
|
|
|
720
733
|
return this.resolveAllToken(token, true);
|
|
721
734
|
}
|
|
722
735
|
addHook(hook) {
|
|
736
|
+
this.checkDisposed();
|
|
723
737
|
this.myHookRegistry.add(hook);
|
|
724
738
|
}
|
|
725
739
|
removeHook(hook) {
|
|
740
|
+
this.checkDisposed();
|
|
726
741
|
this.myHookRegistry.delete(hook);
|
|
727
742
|
}
|
|
728
743
|
dispose() {
|
|
729
744
|
if (this.myDisposed) {
|
|
730
|
-
return;
|
|
745
|
+
return [];
|
|
731
746
|
}
|
|
747
|
+
this.myDisposed = true;
|
|
748
|
+
const promises = [];
|
|
732
749
|
// Dispose children containers first
|
|
733
750
|
for (const child of this.myChildren){
|
|
734
|
-
child.dispose();
|
|
751
|
+
promises.push(...child.dispose());
|
|
735
752
|
}
|
|
736
|
-
this.myDisposed = true;
|
|
737
753
|
this.myChildren.clear();
|
|
738
754
|
this.myParent?.myChildren?.delete(this);
|
|
739
755
|
const [, registrations] = this.myTokenRegistry.deleteAll();
|
|
@@ -750,11 +766,18 @@ function isDisposable(value) {
|
|
|
750
766
|
}
|
|
751
767
|
for (const value of allValues){
|
|
752
768
|
if (isDisposable(value)) {
|
|
753
|
-
|
|
769
|
+
try {
|
|
770
|
+
promises.push(Promise.resolve(value.dispose()));
|
|
771
|
+
} catch (e) {
|
|
772
|
+
promises.push(Promise.reject(e));
|
|
773
|
+
}
|
|
754
774
|
}
|
|
755
775
|
}
|
|
756
|
-
this.notifyDisposeHooks(
|
|
776
|
+
this.notifyDisposeHooks([
|
|
777
|
+
...cacheValues
|
|
778
|
+
]);
|
|
757
779
|
this.myHookRegistry.clear();
|
|
780
|
+
return promises;
|
|
758
781
|
}
|
|
759
782
|
registerClass(Class) {
|
|
760
783
|
const metadata = getMetadata(Class);
|
|
@@ -928,7 +951,7 @@ function isDisposable(value) {
|
|
|
928
951
|
if (isValueProvider(provider)) {
|
|
929
952
|
return provider.useValue;
|
|
930
953
|
}
|
|
931
|
-
check(false, "internal
|
|
954
|
+
check(false, "internal: unexpected ExistingProvider");
|
|
932
955
|
}
|
|
933
956
|
resolveScopedValue(token, registration, factory) {
|
|
934
957
|
let context = useInjectionContext();
|
|
@@ -1004,7 +1027,7 @@ function isDisposable(value) {
|
|
|
1004
1027
|
resolveCtorDependencies(registration) {
|
|
1005
1028
|
const dependencies = registration.dependencies;
|
|
1006
1029
|
if (dependencies) {
|
|
1007
|
-
check(isClassProvider(registration.provider), `internal
|
|
1030
|
+
check(isClassProvider(registration.provider), `internal: expected a ClassProvider`);
|
|
1008
1031
|
const ctorDeps = dependencies.ctor.filter((d)=>d.appliedBy);
|
|
1009
1032
|
if (ctorDeps.length > 0) {
|
|
1010
1033
|
// Let's check if all necessary constructor parameters are decorated.
|
|
@@ -1023,7 +1046,7 @@ function isDisposable(value) {
|
|
|
1023
1046
|
injectMethodDependencies(registration, instance) {
|
|
1024
1047
|
const dependencies = registration.dependencies;
|
|
1025
1048
|
if (dependencies) {
|
|
1026
|
-
check(isClassProvider(registration.provider), `internal
|
|
1049
|
+
check(isClassProvider(registration.provider), `internal: expected a ClassProvider`);
|
|
1027
1050
|
const ctor = registration.provider.useClass;
|
|
1028
1051
|
// Perform method injection
|
|
1029
1052
|
for (const entry of dependencies.methods){
|
|
@@ -1070,6 +1093,8 @@ function isDisposable(value) {
|
|
|
1070
1093
|
return instance ? optionalBy(instance, token, name) : this.tryResolve(token, name);
|
|
1071
1094
|
case "OptionalAll":
|
|
1072
1095
|
return instance ? optionalAll(token) : this.tryResolveAll(token);
|
|
1096
|
+
case undefined:
|
|
1097
|
+
check(false, "internal: unexpected undefined appliedBy");
|
|
1073
1098
|
}
|
|
1074
1099
|
}
|
|
1075
1100
|
notifyProvideHooks(value, scope) {
|