@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.
@@ -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;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Decorators for dependency injection.
3
+ */
4
+ export { AsyncWith } from './async-with.decorator.js';