@travetto/di 3.4.2 → 4.0.0-rc.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/README.md +5 -5
- package/package.json +3 -3
- package/src/registry.ts +6 -6
- package/src/types.ts +2 -2
- package/support/dynamic.injection.ts +4 -3
package/README.md
CHANGED
|
@@ -100,10 +100,10 @@ Given the `static` method `initService`, the function will be provided as a vali
|
|
|
100
100
|
|
|
101
101
|
**Code: Example Conditional Dependency**
|
|
102
102
|
```typescript
|
|
103
|
-
import {
|
|
103
|
+
import { Env } from '@travetto/base';
|
|
104
104
|
import { Inject, Injectable } from '@travetto/di';
|
|
105
105
|
|
|
106
|
-
@Injectable({ enabled:
|
|
106
|
+
@Injectable({ enabled: Env.production })
|
|
107
107
|
class ProductionLogger {
|
|
108
108
|
async log() {
|
|
109
109
|
console.log('This will only run in production');
|
|
@@ -229,8 +229,8 @@ It is also possible to directly reference external types, and they will be conve
|
|
|
229
229
|
|
|
230
230
|
**Code: Example External Dependencies**
|
|
231
231
|
```typescript
|
|
232
|
-
import { EventEmitter } from 'events';
|
|
233
|
-
import { Writable } from 'stream';
|
|
232
|
+
import { EventEmitter } from 'node:events';
|
|
233
|
+
import { Writable } from 'node:stream';
|
|
234
234
|
|
|
235
235
|
import { Inject, Injectable, InjectableFactory } from '@travetto/di';
|
|
236
236
|
|
|
@@ -288,7 +288,7 @@ import { DependencyRegistry, Inject, Injectable, InjectableFactory } from '@trav
|
|
|
288
288
|
class TargetConcrete { }
|
|
289
289
|
|
|
290
290
|
/**
|
|
291
|
-
* @concrete
|
|
291
|
+
* @concrete #TargetConcrete
|
|
292
292
|
*/
|
|
293
293
|
export interface ServiceContract {
|
|
294
294
|
deleteUser(userId: string): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/di",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-rc.1",
|
|
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": "^4.0.0-rc.1"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@travetto/transformer": "^
|
|
33
|
+
"@travetto/transformer": "^4.0.0-rc.1"
|
|
34
34
|
},
|
|
35
35
|
"peerDependenciesMeta": {
|
|
36
36
|
"@travetto/transformer": {
|
package/src/registry.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Class, ClassInstance, ConcreteClass,
|
|
1
|
+
import { Class, ClassInstance, ConcreteClass, Env } from '@travetto/base';
|
|
2
2
|
import { MetadataRegistry, RootRegistry, ChangeEvent } from '@travetto/registry';
|
|
3
|
-
import {
|
|
3
|
+
import { RuntimeIndex } from '@travetto/manifest';
|
|
4
4
|
|
|
5
5
|
import { Dependency, InjectableConfig, ClassTarget, InjectableFactoryConfig } from './types';
|
|
6
6
|
import { InjectionError } from './error';
|
|
@@ -237,7 +237,7 @@ class $DependencyRegistry extends MetadataRegistry<InjectableConfig> {
|
|
|
237
237
|
|
|
238
238
|
override async init(): Promise<void> {
|
|
239
239
|
await super.init();
|
|
240
|
-
if (
|
|
240
|
+
if (Env.dynamic) {
|
|
241
241
|
const { DependencyRegistration } = await import('../support/dynamic.injection.js');
|
|
242
242
|
DependencyRegistration.init(this);
|
|
243
243
|
}
|
|
@@ -435,7 +435,7 @@ class $DependencyRegistry extends MetadataRegistry<InjectableConfig> {
|
|
|
435
435
|
let parentClass = config.factory ? config.target : Object.getPrototypeOf(cls);
|
|
436
436
|
|
|
437
437
|
if (config.factory) {
|
|
438
|
-
while (
|
|
438
|
+
while (RuntimeIndex.getFunctionMetadata(Object.getPrototypeOf(parentClass))?.abstract) {
|
|
439
439
|
parentClass = Object.getPrototypeOf(parentClass);
|
|
440
440
|
}
|
|
441
441
|
if (!this.targetToClass.has(classId)) {
|
|
@@ -465,7 +465,7 @@ class $DependencyRegistry extends MetadataRegistry<InjectableConfig> {
|
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
-
if (
|
|
468
|
+
if (RuntimeIndex.getFunctionMetadata(cls)?.abstract) { // Skip out early, only needed to inherit
|
|
469
469
|
return config;
|
|
470
470
|
}
|
|
471
471
|
|
|
@@ -500,7 +500,7 @@ class $DependencyRegistry extends MetadataRegistry<InjectableConfig> {
|
|
|
500
500
|
}
|
|
501
501
|
|
|
502
502
|
// If targeting self (default @Injectable behavior)
|
|
503
|
-
if ((classId === targetId || config.factory) && (parentConfig ||
|
|
503
|
+
if ((classId === targetId || config.factory) && (parentConfig || RuntimeIndex.getFunctionMetadata(parentClass)?.abstract)) {
|
|
504
504
|
const parentId = parentClass.Ⲑid;
|
|
505
505
|
|
|
506
506
|
if (!this.targetToClass.has(parentId)) {
|
package/src/types.ts
CHANGED
|
@@ -72,7 +72,7 @@ export interface InjectableFactoryConfig<T = unknown> extends Core<T> {
|
|
|
72
72
|
/**
|
|
73
73
|
* Is this injectable enabled
|
|
74
74
|
*/
|
|
75
|
-
enabled
|
|
75
|
+
enabled?: boolean | (() => boolean);
|
|
76
76
|
/**
|
|
77
77
|
* Src of the factory method
|
|
78
78
|
*/
|
|
@@ -88,6 +88,6 @@ export interface InjectableFactoryConfig<T = unknown> extends Core<T> {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
* @concrete ./internal/types
|
|
91
|
+
* @concrete ./internal/types#AutoCreateTarget
|
|
92
92
|
*/
|
|
93
93
|
export interface AutoCreate { }
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Class, ClassInstance } from '@travetto/base';
|
|
2
|
+
import { RuntimeIndex } from '@travetto/manifest';
|
|
3
|
+
import { RetargettingProxy } from '@travetto/registry';
|
|
3
4
|
|
|
4
5
|
import type { DependencyRegistry, ResolutionType, Resolved } from '../src/registry';
|
|
5
6
|
import type { ClassTarget, InjectableConfig } from '../src/types';
|
|
@@ -64,7 +65,7 @@ class $DynamicDependencyRegistry {
|
|
|
64
65
|
const classId = cls.Ⲑid;
|
|
65
66
|
|
|
66
67
|
if (
|
|
67
|
-
!
|
|
68
|
+
!RuntimeIndex.getFunctionMetadata(cls)?.abstract &&
|
|
68
69
|
this.#proxies.has(classId) &&
|
|
69
70
|
this.#proxies.get(classId)!.has(config.qualifier)
|
|
70
71
|
) {
|