@frontmcp/di 0.0.1 → 0.7.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/decorators/async-with.decorator.d.ts +43 -0
- package/decorators/index.d.ts +4 -0
- package/esm/index.mjs +1173 -0
- package/esm/package.json +59 -0
- package/index.d.ts +18 -0
- package/index.js +1225 -0
- package/interfaces/base.interface.d.ts +119 -0
- package/interfaces/index.d.ts +6 -0
- package/interfaces/provider.interface.d.ts +57 -0
- package/interfaces/registry.interface.d.ts +66 -0
- package/metadata/index.d.ts +5 -0
- package/metadata/provider.metadata.d.ts +47 -0
- package/metadata/provider.schema.d.ts +32 -0
- package/package.json +1 -1
- package/records/index.d.ts +4 -0
- package/records/provider.record.d.ts +73 -0
- package/registry/container.d.ts +155 -0
- package/registry/index.d.ts +8 -0
- package/registry/indexed.registry.d.ts +140 -0
- package/registry/indexed.types.d.ts +87 -0
- package/registry/registry.base.d.ts +85 -0
- package/registry/simple.registry.d.ts +28 -0
- package/tokens/di.constants.d.ts +22 -0
- package/tokens/index.d.ts +9 -0
- package/tokens/token.factory.d.ts +55 -0
- package/utils/index.d.ts +6 -0
- package/utils/metadata.utils.d.ts +37 -0
- package/utils/provider.utils.d.ts +79 -0
- package/utils/token.utils.d.ts +74 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @AsyncWith decorator for async dependency resolution.
|
|
3
|
+
*
|
|
4
|
+
* Use this decorator when a class needs async initialization or when
|
|
5
|
+
* you want to avoid TDZ (Temporal Dead Zone) issues with circular imports.
|
|
6
|
+
*/
|
|
7
|
+
import 'reflect-metadata';
|
|
8
|
+
import type { Token } from '../interfaces/base.interface.js';
|
|
9
|
+
/**
|
|
10
|
+
* Decorator that marks a class for async initialization.
|
|
11
|
+
*
|
|
12
|
+
* When a class is decorated with @AsyncWith, the DI container will:
|
|
13
|
+
* 1. Resolve the specified dependency tokens
|
|
14
|
+
* 2. Call the static `with(...deps)` method instead of the constructor
|
|
15
|
+
* 3. Await the result if it's a Promise
|
|
16
|
+
*
|
|
17
|
+
* This is useful for:
|
|
18
|
+
* - Async initialization that requires resolved dependencies
|
|
19
|
+
* - Avoiding TDZ issues with ESM circular imports
|
|
20
|
+
* - Lazy dependency declaration
|
|
21
|
+
*
|
|
22
|
+
* @param tokensFactory - Function returning array of dependency tokens
|
|
23
|
+
* @returns Class decorator
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* @AsyncWith(() => [DatabaseConnection, Logger])
|
|
28
|
+
* class UserRepository {
|
|
29
|
+
* private constructor(private db: DatabaseConnection, private logger: Logger) {}
|
|
30
|
+
*
|
|
31
|
+
* static async with(db: DatabaseConnection, logger: Logger): Promise<UserRepository> {
|
|
32
|
+
* const repo = new UserRepository(db, logger);
|
|
33
|
+
* await repo.initialize();
|
|
34
|
+
* return repo;
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* private async initialize() {
|
|
38
|
+
* // Async setup
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function AsyncWith<T extends readonly Token[]>(tokensFactory: () => T): ClassDecorator;
|