@travetto/di 5.0.16 → 6.0.0-rc.0
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/README.md +6 -1
- package/package.json +3 -3
- package/src/registry.ts +13 -13
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -157,7 +157,12 @@ import { DependentService } from './dep';
|
|
|
157
157
|
|
|
158
158
|
@Injectable()
|
|
159
159
|
class CustomService {
|
|
160
|
-
|
|
160
|
+
|
|
161
|
+
dependentService: DependentService;
|
|
162
|
+
|
|
163
|
+
constructor(svc: DependentService) {
|
|
164
|
+
this.dependentService = svc;
|
|
165
|
+
}
|
|
161
166
|
|
|
162
167
|
async coolOperation() {
|
|
163
168
|
await this.dependentService.doWork();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/di",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-rc.0",
|
|
4
4
|
"description": "Dependency registration/management and injection support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast-transformations",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"directory": "module/di"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/registry": "^
|
|
30
|
+
"@travetto/registry": "^6.0.0-rc.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@travetto/transformer": "^
|
|
33
|
+
"@travetto/transformer": "^6.0.0-rc.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependenciesMeta": {
|
|
36
36
|
"@travetto/transformer": {
|
package/src/registry.ts
CHANGED
|
@@ -23,17 +23,17 @@ const hasPreDestroy = hasFunction<{ preDestroy: () => Promise<unknown> }>('preDe
|
|
|
23
23
|
* Dependency registry
|
|
24
24
|
*/
|
|
25
25
|
class $DependencyRegistry extends MetadataRegistry<InjectableConfig> {
|
|
26
|
-
|
|
26
|
+
pendingFinalize: Class[] = [];
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
defaultSymbols = new Set<symbol>();
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
instances = new Map<TargetId, Map<symbol, unknown>>();
|
|
31
|
+
instancePromises = new Map<TargetId, Map<symbol, Promise<unknown>>>();
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
factories = new Map<TargetId, Map<Class, InjectableConfig>>();
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
targetToClass = new Map<TargetId, Map<symbol, string>>();
|
|
36
|
+
classToTarget = new Map<ClassId, Map<symbol, TargetId>>();
|
|
37
37
|
|
|
38
38
|
constructor() {
|
|
39
39
|
super(RootRegistry);
|
|
@@ -44,7 +44,7 @@ class $DependencyRegistry extends MetadataRegistry<InjectableConfig> {
|
|
|
44
44
|
* @param target
|
|
45
45
|
* @param qualifier
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
resolveTarget<T>(target: ClassTarget<T>, qualifier?: symbol, resolution?: ResolutionType): Resolved<T> {
|
|
48
48
|
const qualifiers = this.targetToClass.get(target.Ⲑid) ?? new Map<symbol, string>();
|
|
49
49
|
|
|
50
50
|
let cls: string | undefined;
|
|
@@ -104,7 +104,7 @@ class $DependencyRegistry extends MetadataRegistry<InjectableConfig> {
|
|
|
104
104
|
/**
|
|
105
105
|
* Retrieve all dependencies
|
|
106
106
|
*/
|
|
107
|
-
|
|
107
|
+
async fetchDependencies(managed: InjectableConfig, deps?: Dependency[]): Promise<unknown[]> {
|
|
108
108
|
if (!deps || !deps.length) {
|
|
109
109
|
return [];
|
|
110
110
|
}
|
|
@@ -130,7 +130,7 @@ class $DependencyRegistry extends MetadataRegistry<InjectableConfig> {
|
|
|
130
130
|
/**
|
|
131
131
|
* Resolve all field dependencies
|
|
132
132
|
*/
|
|
133
|
-
|
|
133
|
+
async resolveFieldDependencies<T>(config: InjectableConfig<T>, instance: T): Promise<void> {
|
|
134
134
|
const keys = Object.keys(config.dependencies.fields ?? {})
|
|
135
135
|
.filter(k => instance[castKey<T>(k)] === undefined); // Filter out already set ones
|
|
136
136
|
|
|
@@ -146,7 +146,7 @@ class $DependencyRegistry extends MetadataRegistry<InjectableConfig> {
|
|
|
146
146
|
/**
|
|
147
147
|
* Actually construct an instance while resolving the dependencies
|
|
148
148
|
*/
|
|
149
|
-
|
|
149
|
+
async construct<T>(target: ClassTarget<T>, qualifier: symbol): Promise<T> {
|
|
150
150
|
const managed = this.resolveTarget(target, qualifier).config;
|
|
151
151
|
|
|
152
152
|
// Only fetch constructor values
|
|
@@ -180,7 +180,7 @@ class $DependencyRegistry extends MetadataRegistry<InjectableConfig> {
|
|
|
180
180
|
/**
|
|
181
181
|
* Create the instance
|
|
182
182
|
*/
|
|
183
|
-
|
|
183
|
+
async createInstance<T>(target: ClassTarget<T>, qualifier: symbol): Promise<T> {
|
|
184
184
|
const classId = this.resolveTarget(target, qualifier).id;
|
|
185
185
|
|
|
186
186
|
if (!this.instances.has(classId)) {
|
|
@@ -208,7 +208,7 @@ class $DependencyRegistry extends MetadataRegistry<InjectableConfig> {
|
|
|
208
208
|
/**
|
|
209
209
|
* Destroy an instance
|
|
210
210
|
*/
|
|
211
|
-
|
|
211
|
+
destroyInstance(cls: Class, qualifier: symbol): void {
|
|
212
212
|
const classId = cls.Ⲑid;
|
|
213
213
|
|
|
214
214
|
const activeInstance = this.instances.get(classId)!.get(qualifier);
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 ArcSine Technologies
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|