@lppedd/di-wise-neo 0.14.0 → 0.14.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 +3 -7
- package/dist/cjs/index.js +56 -56
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.mts +3 -7
- package/dist/es/index.mjs +56 -56
- package/dist/es/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -55,18 +55,14 @@ interface Type<T> {
|
|
|
55
55
|
* The name of the type.
|
|
56
56
|
*/
|
|
57
57
|
readonly name: string;
|
|
58
|
-
/**
|
|
59
|
-
* Returns the stringified representation of the type.
|
|
60
|
-
*/
|
|
61
|
-
readonly toString: () => string;
|
|
62
58
|
/**
|
|
63
59
|
* Ensures that different `Type<T>` types are not structurally compatible.
|
|
64
60
|
*
|
|
65
|
-
* This property is never used at runtime.
|
|
61
|
+
* This property is always `undefined` and is never used at runtime.
|
|
66
62
|
*
|
|
67
63
|
* @private
|
|
68
64
|
*/
|
|
69
|
-
readonly __type
|
|
65
|
+
readonly __type: T | undefined;
|
|
70
66
|
}
|
|
71
67
|
/**
|
|
72
68
|
* An injectable type `T` with a default {@link Provider} and optional default registration options.
|
|
@@ -91,7 +87,7 @@ interface Constructor<Instance extends object> {
|
|
|
91
87
|
/**
|
|
92
88
|
* Token type.
|
|
93
89
|
*/
|
|
94
|
-
type Token<Value = any> = [Value] extends [object] ? Type<Value> | Constructor<Value> : Type<Value>;
|
|
90
|
+
type Token<Value = any> = [Value] extends [object] ? Type<Value> | Constructor<Value & object> : Type<Value>;
|
|
95
91
|
/**
|
|
96
92
|
* Describes a {@link Token} array with at least one element.
|
|
97
93
|
*/
|
package/dist/cjs/index.js
CHANGED
|
@@ -575,13 +575,66 @@ function isDisposable(value) {
|
|
|
575
575
|
if (isConstructor(token)) {
|
|
576
576
|
this.registerClass(token);
|
|
577
577
|
} else {
|
|
578
|
-
this.
|
|
578
|
+
this.registerToken(token, token.provider, token.options);
|
|
579
579
|
}
|
|
580
580
|
} else {
|
|
581
|
-
this.
|
|
581
|
+
this.registerToken(...args);
|
|
582
582
|
}
|
|
583
583
|
return this;
|
|
584
584
|
}
|
|
585
|
+
unregister(token, name) {
|
|
586
|
+
this.checkDisposed();
|
|
587
|
+
const registrations = this.myTokenRegistry.delete(token, name);
|
|
588
|
+
const values = new Set();
|
|
589
|
+
for (const registration of registrations){
|
|
590
|
+
const value = registration.value;
|
|
591
|
+
if (value) {
|
|
592
|
+
values.add(value.current);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return Array.from(values);
|
|
596
|
+
}
|
|
597
|
+
resolve(token, name) {
|
|
598
|
+
this.checkDisposed();
|
|
599
|
+
return this.resolveToken(token, name, false);
|
|
600
|
+
}
|
|
601
|
+
tryResolve(token, name) {
|
|
602
|
+
this.checkDisposed();
|
|
603
|
+
return this.resolveToken(token, name, true);
|
|
604
|
+
}
|
|
605
|
+
resolveAll(token) {
|
|
606
|
+
this.checkDisposed();
|
|
607
|
+
return this.resolveAllToken(token, false);
|
|
608
|
+
}
|
|
609
|
+
tryResolveAll(token) {
|
|
610
|
+
this.checkDisposed();
|
|
611
|
+
return this.resolveAllToken(token, true);
|
|
612
|
+
}
|
|
613
|
+
dispose() {
|
|
614
|
+
if (this.myDisposed) {
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
// Dispose children containers first
|
|
618
|
+
for (const child of this.myChildren){
|
|
619
|
+
child.dispose();
|
|
620
|
+
}
|
|
621
|
+
this.myChildren.clear();
|
|
622
|
+
// Remove ourselves from our parent container
|
|
623
|
+
this.myParent?.myChildren?.delete(this);
|
|
624
|
+
this.myDisposed = true;
|
|
625
|
+
const [, registrations] = this.myTokenRegistry.deleteAll();
|
|
626
|
+
const disposedRefs = new Set();
|
|
627
|
+
// Dispose all resolved (aka instantiated) tokens that implement the Disposable interface
|
|
628
|
+
for (const registration of registrations){
|
|
629
|
+
const value = registration.value?.current;
|
|
630
|
+
if (isDisposable(value) && !disposedRefs.has(value)) {
|
|
631
|
+
disposedRefs.add(value);
|
|
632
|
+
value.dispose();
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
// Allow values to be GCed
|
|
636
|
+
disposedRefs.clear();
|
|
637
|
+
}
|
|
585
638
|
registerClass(Class) {
|
|
586
639
|
const metadata = getMetadata(Class);
|
|
587
640
|
const name = metadata.name;
|
|
@@ -614,7 +667,7 @@ function isDisposable(value) {
|
|
|
614
667
|
this.resolveProviderValue(Class, registration);
|
|
615
668
|
}
|
|
616
669
|
}
|
|
617
|
-
|
|
670
|
+
registerToken(token, provider, options) {
|
|
618
671
|
const name = provider.name;
|
|
619
672
|
check(name === undefined || name.trim(), `name qualifier for token ${getTokenName(token)} must not be empty`);
|
|
620
673
|
if (isClassProvider(provider)) {
|
|
@@ -647,59 +700,6 @@ function isDisposable(value) {
|
|
|
647
700
|
});
|
|
648
701
|
}
|
|
649
702
|
}
|
|
650
|
-
unregister(token, name) {
|
|
651
|
-
this.checkDisposed();
|
|
652
|
-
const registrations = this.myTokenRegistry.delete(token, name);
|
|
653
|
-
const values = new Set();
|
|
654
|
-
for (const registration of registrations){
|
|
655
|
-
const value = registration.value;
|
|
656
|
-
if (value) {
|
|
657
|
-
values.add(value.current);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
return Array.from(values);
|
|
661
|
-
}
|
|
662
|
-
resolve(token, name) {
|
|
663
|
-
this.checkDisposed();
|
|
664
|
-
return this.resolveToken(token, name, false);
|
|
665
|
-
}
|
|
666
|
-
tryResolve(token, name) {
|
|
667
|
-
this.checkDisposed();
|
|
668
|
-
return this.resolveToken(token, name, true);
|
|
669
|
-
}
|
|
670
|
-
resolveAll(token) {
|
|
671
|
-
this.checkDisposed();
|
|
672
|
-
return this.resolveAllToken(token, false);
|
|
673
|
-
}
|
|
674
|
-
tryResolveAll(token) {
|
|
675
|
-
this.checkDisposed();
|
|
676
|
-
return this.resolveAllToken(token, true);
|
|
677
|
-
}
|
|
678
|
-
dispose() {
|
|
679
|
-
if (this.myDisposed) {
|
|
680
|
-
return;
|
|
681
|
-
}
|
|
682
|
-
// Dispose children containers first
|
|
683
|
-
for (const child of this.myChildren){
|
|
684
|
-
child.dispose();
|
|
685
|
-
}
|
|
686
|
-
this.myChildren.clear();
|
|
687
|
-
// Remove ourselves from our parent container
|
|
688
|
-
this.myParent?.myChildren?.delete(this);
|
|
689
|
-
this.myDisposed = true;
|
|
690
|
-
const [, registrations] = this.myTokenRegistry.deleteAll();
|
|
691
|
-
const disposedRefs = new Set();
|
|
692
|
-
// Dispose all resolved (aka instantiated) tokens that implement the Disposable interface
|
|
693
|
-
for (const registration of registrations){
|
|
694
|
-
const value = registration.value?.current;
|
|
695
|
-
if (isDisposable(value) && !disposedRefs.has(value)) {
|
|
696
|
-
disposedRefs.add(value);
|
|
697
|
-
value.dispose();
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
// Allow values to be GCed
|
|
701
|
-
disposedRefs.clear();
|
|
702
|
-
}
|
|
703
703
|
resolveToken(token, name, optional) {
|
|
704
704
|
let registration = this.myTokenRegistry.get(token, name);
|
|
705
705
|
if (!registration && isConstructor(token)) {
|