@tsed/di 8.18.2 → 8.19.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.
Files changed (89) hide show
  1. package/lib/esm/common/decorators/autoInjectable.js +28 -9
  2. package/lib/esm/common/decorators/constant.js +26 -22
  3. package/lib/esm/common/decorators/controller.js +40 -20
  4. package/lib/esm/common/decorators/injectable.js +30 -10
  5. package/lib/esm/common/decorators/intercept.js +41 -3
  6. package/lib/esm/common/decorators/interceptor.js +31 -4
  7. package/lib/esm/common/decorators/module.js +36 -5
  8. package/lib/esm/common/decorators/opts.js +20 -12
  9. package/lib/esm/common/decorators/overrideProvider.js +38 -4
  10. package/lib/esm/common/decorators/scope.js +32 -3
  11. package/lib/esm/common/decorators/service.js +24 -4
  12. package/lib/esm/common/decorators/useOpts.js +21 -13
  13. package/lib/esm/common/decorators/value.js +28 -22
  14. package/lib/esm/common/domain/Container.js +20 -0
  15. package/lib/esm/common/domain/ContextLogger.js +21 -0
  16. package/lib/esm/common/domain/ControllerProvider.js +22 -0
  17. package/lib/esm/common/domain/DIContext.js +22 -0
  18. package/lib/esm/common/domain/InjectablePropertyType.js +16 -0
  19. package/lib/esm/common/domain/LocalsContainer.js +21 -0
  20. package/lib/esm/common/domain/Provider.js +19 -0
  21. package/lib/esm/common/domain/ProviderScope.js +25 -0
  22. package/lib/esm/common/domain/ProviderType.js +25 -0
  23. package/lib/esm/common/errors/InjectionError.js +24 -0
  24. package/lib/esm/common/errors/InvalidPropertyTokenError.js +15 -0
  25. package/lib/esm/common/fn/inject.js +19 -6
  26. package/lib/esm/common/fn/injectMany.js +24 -6
  27. package/lib/esm/common/fn/injectable.js +57 -0
  28. package/lib/esm/common/fn/injector.js +21 -2
  29. package/lib/esm/common/fn/lazyInject.js +48 -1
  30. package/lib/esm/common/fn/localsContainer.js +31 -2
  31. package/lib/esm/common/fn/logger.js +15 -1
  32. package/lib/esm/common/services/DIConfiguration.js +24 -0
  33. package/lib/esm/common/services/DILogger.js +23 -0
  34. package/lib/esm/common/services/InjectorService.js +89 -43
  35. package/lib/types/common/decorators/autoInjectable.d.ts +31 -10
  36. package/lib/types/common/decorators/configuration.d.ts +32 -2
  37. package/lib/types/common/decorators/constant.d.ts +26 -22
  38. package/lib/types/common/decorators/controller.d.ts +40 -20
  39. package/lib/types/common/decorators/inject.d.ts +29 -7
  40. package/lib/types/common/decorators/injectable.d.ts +30 -10
  41. package/lib/types/common/decorators/intercept.d.ts +41 -3
  42. package/lib/types/common/decorators/interceptor.d.ts +31 -4
  43. package/lib/types/common/decorators/lazyInject.d.ts +43 -9
  44. package/lib/types/common/decorators/module.d.ts +36 -5
  45. package/lib/types/common/decorators/opts.d.ts +20 -12
  46. package/lib/types/common/decorators/overrideProvider.d.ts +38 -4
  47. package/lib/types/common/decorators/scope.d.ts +32 -3
  48. package/lib/types/common/decorators/service.d.ts +24 -4
  49. package/lib/types/common/decorators/useOpts.d.ts +21 -13
  50. package/lib/types/common/decorators/value.d.ts +28 -22
  51. package/lib/types/common/domain/Container.d.ts +20 -0
  52. package/lib/types/common/domain/ContextLogger.d.ts +26 -0
  53. package/lib/types/common/domain/ControllerProvider.d.ts +29 -0
  54. package/lib/types/common/domain/DIContext.d.ts +27 -0
  55. package/lib/types/common/domain/InjectablePropertyType.d.ts +16 -0
  56. package/lib/types/common/domain/LocalsContainer.d.ts +21 -0
  57. package/lib/types/common/domain/Provider.d.ts +25 -0
  58. package/lib/types/common/domain/ProviderScope.d.ts +25 -0
  59. package/lib/types/common/domain/ProviderType.d.ts +25 -0
  60. package/lib/types/common/errors/InjectionError.d.ts +24 -0
  61. package/lib/types/common/errors/InvalidPropertyTokenError.d.ts +15 -0
  62. package/lib/types/common/fn/configuration.d.ts +31 -0
  63. package/lib/types/common/fn/constant.d.ts +22 -0
  64. package/lib/types/common/fn/inject.d.ts +19 -6
  65. package/lib/types/common/fn/injectMany.d.ts +24 -6
  66. package/lib/types/common/fn/injectable.d.ts +57 -0
  67. package/lib/types/common/fn/injector.d.ts +21 -2
  68. package/lib/types/common/fn/lazyInject.d.ts +48 -1
  69. package/lib/types/common/fn/localsContainer.d.ts +31 -2
  70. package/lib/types/common/fn/logger.d.ts +15 -1
  71. package/lib/types/common/fn/refValue.d.ts +15 -6
  72. package/lib/types/common/interfaces/AlterRunInContext.d.ts +26 -0
  73. package/lib/types/common/interfaces/DILogger.d.ts +36 -0
  74. package/lib/types/common/interfaces/DILoggerOptions.d.ts +23 -0
  75. package/lib/types/common/interfaces/ImportTokenProviderOpts.d.ts +43 -0
  76. package/lib/types/common/interfaces/InterceptorContext.d.ts +35 -0
  77. package/lib/types/common/interfaces/InterceptorMethods.d.ts +27 -0
  78. package/lib/types/common/interfaces/InvokeOptions.d.ts +8 -0
  79. package/lib/types/common/interfaces/OnDestroy.d.ts +22 -0
  80. package/lib/types/common/interfaces/OnInit.d.ts +22 -0
  81. package/lib/types/common/interfaces/ProviderOpts.d.ts +31 -0
  82. package/lib/types/common/interfaces/ResolvedInvokeOptions.d.ts +9 -0
  83. package/lib/types/common/interfaces/TokenProvider.d.ts +32 -2
  84. package/lib/types/common/interfaces/TokenRoute.d.ts +16 -0
  85. package/lib/types/common/services/DIConfiguration.d.ts +24 -0
  86. package/lib/types/common/services/DILogger.d.ts +28 -0
  87. package/lib/types/common/services/InjectorService.d.ts +89 -43
  88. package/lib/types/node/utils/asyncHookContext.d.ts +0 -1
  89. package/package.json +6 -6
@@ -1,20 +1,40 @@
1
1
  import type { ProviderOpts } from "../interfaces/ProviderOpts.js";
2
2
  /**
3
- * The decorators `@Injectable()` declare a new service can be injected in other service, controller, interceptor, etc.. on there `constructor`.
4
- * All classes annotated with `@Injectable()` are built one time, excepted if you change the default provider configuration.
3
+ * Declare a class as an injectable provider in the DI system.
5
4
  *
6
- * ::: tip
7
- * `@Injectable()` use the `reflect-metadata` to collect and inject the built provided to other services.
8
- * :::
5
+ * Registers a class as a provider that can be injected into other services, controllers, or interceptors.
6
+ * By default, providers are singleton-scoped and built once during application initialization.
7
+ *
8
+ * ### Usage
9
+ *
10
+ * ```typescript
11
+ * import {Injectable} from "@tsed/di";
12
+ *
13
+ * @Injectable()
14
+ * export class MyService {
15
+ * getData() {
16
+ * return "data";
17
+ * }
18
+ * }
19
+ *
20
+ * // With options
21
+ * @Injectable({
22
+ * scope: ProviderScope.REQUEST,
23
+ * type: ProviderType.PROVIDER
24
+ * })
25
+ * export class RequestScopedService {}
26
+ * ```
9
27
  *
10
28
  * ### Options
11
29
  *
12
- * - type (@@ProviderType@@ or `string`): Kind of provider. (Default: `ProviderType.PROVIDER`)
13
- * - scope (@@ProviderScope@@): Kind of provider. (Default: `ProviderScope.SINGLETON`)
14
- * - token (@@TokenProvider@@): An injection token (Note: This option override default metadata generated by Typescript).
15
- * - deps (`Type<any>`): List of class or provider which will be injected to the constructor (Note: This options override default metadata generated by Typescript).
30
+ * - `type`: Provider category (default: `ProviderType.PROVIDER`)
31
+ * - `scope`: Instance lifecycle scope (default: `ProviderScope.SINGLETON`)
32
+ * - `token`: Custom injection token (overrides class reference)
33
+ * - `deps`: Explicit constructor dependencies (overrides TypeScript metadata)
16
34
  *
17
- * @returns {Function}
35
+ * @param options Provider configuration options
36
+ * @returns Class decorator function
37
+ * @public
18
38
  * @decorator
19
39
  */
20
40
  export declare function Injectable(options?: Partial<ProviderOpts>): ClassDecorator;
@@ -4,10 +4,48 @@ import type { TokenProvider } from "../interfaces/TokenProvider.js";
4
4
  export declare function getInterceptorOptions<T>(target: Type<any>, propertyKey: string | symbol): T;
5
5
  export declare function bindIntercept(target: any, propertyKey: string | symbol, token: TokenProvider, options: Record<string, unknown>): TypedPropertyDescriptor<any> | undefined;
6
6
  /**
7
- * Attaches interceptor to method call and executes the before and after methods
7
+ * Apply an interceptor to a method or all methods of a class.
8
8
  *
9
- * @param interceptor
10
- * @param options
9
+ * Wraps method execution with interceptor logic for cross-cutting concerns like logging,
10
+ * validation, caching, or error handling. Can be applied to individual methods or entire classes.
11
+ *
12
+ * ### Usage
13
+ *
14
+ * ```typescript
15
+ * import {Injectable, Intercept, Interceptor, InterceptorContext, InterceptorMethods} from "@tsed/di";
16
+ *
17
+ * @Interceptor()
18
+ * class LogInterceptor implements InterceptorMethods {
19
+ * intercept(context: InterceptorContext) {
20
+ * console.log("Before:", context.propertyKey);
21
+ * const result = context.next();
22
+ * console.log("After:", result);
23
+ * return result;
24
+ * }
25
+ * }
26
+ *
27
+ * @Injectable()
28
+ * class UserService {
29
+ * @Intercept(LogInterceptor)
30
+ * async findById(id: string) {
31
+ * return {id, name: "User"};
32
+ * }
33
+ * }
34
+ *
35
+ * // Apply to all methods
36
+ * @Injectable()
37
+ * @Intercept(LogInterceptor)
38
+ * class ProductService {
39
+ * getAll() {}
40
+ * getById(id: string) {}
41
+ * }
42
+ * ```
43
+ *
44
+ * @typeParam T The interceptor class type
45
+ * @param interceptor The interceptor class token
46
+ * @param options Optional configuration passed to the interceptor
47
+ * @returns Method or class decorator function
48
+ * @public
11
49
  * @decorator
12
50
  */
13
51
  export declare function Intercept<T extends InterceptorMethods>(interceptor: Type<T>, options?: any): any;
@@ -1,10 +1,37 @@
1
1
  /**
2
- * The decorators `@Interceptor()` declare a new service can be injected in other service or controller on there `constructor`.
3
- * All services annotated with `@Interceptor()` are constructed one time.
2
+ * Declare an interceptor class for cross-cutting concerns.
4
3
  *
5
- * > `@Service()` use the `reflect-metadata` to collect and inject service on controllers or other services.
4
+ * Registers a class as an interceptor provider that can modify method execution behavior.
5
+ * Interceptors must implement the `InterceptorMethods` interface.
6
+ * All interceptors are singleton-scoped and constructed once.
6
7
  *
7
- * @returns {Function}
8
+ * ### Usage
9
+ *
10
+ * ```typescript
11
+ * import {Interceptor, InterceptorContext, InterceptorMethods} from "@tsed/di";
12
+ *
13
+ * @Interceptor()
14
+ * export class LogInterceptor implements InterceptorMethods {
15
+ * intercept(context: InterceptorContext) {
16
+ * console.log("Before:", context.propertyKey);
17
+ * const result = context.next();
18
+ * console.log("After:", result);
19
+ * return result;
20
+ * }
21
+ * }
22
+ *
23
+ * // Use with @Intercept decorator
24
+ * @Injectable()
25
+ * class MyService {
26
+ * @Intercept(LogInterceptor)
27
+ * async fetchData() {
28
+ * return "data";
29
+ * }
30
+ * }
31
+ * ```
32
+ *
33
+ * @returns Class decorator function
34
+ * @public
8
35
  * @decorator
9
36
  */
10
37
  export declare function Interceptor(): ClassDecorator;
@@ -1,19 +1,36 @@
1
1
  /**
2
- * Lazy load a provider from his package and invoke only when the provider is used
2
+ * Lazily inject a provider from a dynamic import.
3
+ *
4
+ * Defers loading and injection of a provider until the property is first accessed.
5
+ * Useful for code splitting, optional dependencies, or reducing initial bundle size.
6
+ *
7
+ * ### Usage
3
8
  *
4
9
  * ```typescript
5
10
  * import type {PlatformException} from "@tsed/platform-exceptions";
11
+ * import {Injectable, LazyInject} from "@tsed/di";
6
12
  *
7
13
  * @Injectable()
8
14
  * export class MyService {
15
+ * // Import default export
9
16
  * @LazyInject(() => import("@tsed/platform-exceptions"))
10
17
  * exceptions: Promise<PlatformException>;
18
+ *
19
+ * // Import named export
20
+ * @LazyInject("MyPlugin", () => import("./plugins"))
21
+ * plugin: Promise<MyPlugin>;
22
+ *
23
+ * async handleError(error: Error) {
24
+ * const handler = await this.exceptions;
25
+ * handler.handle(error);
26
+ * }
11
27
  * }
12
28
  * ```
13
29
  *
14
- * @param key - The named export to import from the module.
15
- * @param resolver - A function that returns a promise resolving to the module.
16
- * @returns {Function}
30
+ * @param key Optional named export to extract from the module
31
+ * @param resolver Function returning a promise resolving to the module
32
+ * @returns Property decorator function
33
+ * @public
17
34
  * @decorator
18
35
  */
19
36
  export declare function LazyInject(resolver: () => Promise<{
@@ -23,20 +40,37 @@ export declare function LazyInject(key: string, resolver: () => Promise<{
23
40
  default: unknown;
24
41
  }>): PropertyDecorator;
25
42
  /**
26
- * Optionally Lazy load a provider from his package and invoke only when the provider is used
43
+ * Optionally inject a provider from a dynamic import, returning undefined on failure.
44
+ *
45
+ * Similar to `@LazyInject` but gracefully handles import failures by returning undefined.
46
+ * Useful for truly optional dependencies that may not be available in all environments.
47
+ *
48
+ * ### Usage
27
49
  *
28
50
  * ```typescript
29
51
  * import type {PlatformException} from "@tsed/platform-exceptions";
52
+ * import {Injectable, OptionalLazyInject} from "@tsed/di";
30
53
  *
31
54
  * @Injectable()
32
55
  * export class MyService {
33
56
  * @OptionalLazyInject(() => import("@tsed/platform-exceptions"))
34
- * exceptions: Promise<PlatformException>;
57
+ * exceptions?: Promise<PlatformException>;
58
+ *
59
+ * async handleError(error: Error) {
60
+ * const handler = await this.exceptions;
61
+ * if (handler) {
62
+ * handler.handle(error);
63
+ * } else {
64
+ * console.error("Exception handler not available:", error);
65
+ * }
66
+ * }
35
67
  * }
36
68
  * ```
37
- * @param key - The named export to import from the module.
38
- * @param resolver - A function that returns a promise resolving to the module.
39
- * @decorator
69
+ *
70
+ * @param key Optional named export to extract from the module
71
+ * @param resolver Function returning a promise resolving to the module
72
+ * @returns Property decorator function
73
+ * @public
40
74
  */
41
75
  export declare function OptionalLazyInject(resolver: () => Promise<{
42
76
  default: unknown;
@@ -19,13 +19,44 @@ export interface ModuleOptions extends Omit<TsED.Configuration, "scopes"> {
19
19
  [key: string]: any;
20
20
  }
21
21
  /**
22
- * Declare a new Ts.ED module
22
+ * Declare a Ts.ED module to organize related providers and configuration.
23
23
  *
24
- * ## Options
25
- * - imports: List of Provider which must be built by injector before invoking the module
26
- * - deps: List of provider must be injected to the module constructor (explicit declaration)
24
+ * Modules group related functionality together, manage provider dependencies,
25
+ * and configure application settings. They are singleton-scoped by default.
27
26
  *
28
- * @param options
27
+ * ### Usage
28
+ *
29
+ * ```typescript
30
+ * import {Module} from "@tsed/di";
31
+ *
32
+ * @Module({
33
+ * imports: [DatabaseService, CacheService],
34
+ * mount: {
35
+ * "/api": [UserController, ProductController]
36
+ * }
37
+ * })
38
+ * export class AppModule {
39
+ * constructor(private db: DatabaseService) {
40
+ * // Dependencies injected
41
+ * }
42
+ *
43
+ * $onInit() {
44
+ * this.db.connect();
45
+ * }
46
+ * }
47
+ * ```
48
+ *
49
+ * ### Options
50
+ *
51
+ * - `imports`: Providers to initialize before this module
52
+ * - `deps`: Constructor dependencies (explicit declaration)
53
+ * - `mount`: Route mappings for controllers
54
+ * - `scope`: Provider scope (default: singleton)
55
+ * - Additional properties are stored as module configuration
56
+ *
57
+ * @param options Module configuration options
58
+ * @returns Class decorator function
59
+ * @public
29
60
  * @decorator
30
61
  */
31
62
  export declare function Module(options?: Partial<ModuleOptions>): any;
@@ -1,5 +1,10 @@
1
1
  /**
2
- * Get instance options. This options depending on his invocation context.
2
+ * Inject custom options passed to a provider instance.
3
+ *
4
+ * Used in configurable providers to receive options from the injection context.
5
+ * Automatically changes the provider scope to `INSTANCE` since each invocation may have different options.
6
+ *
7
+ * ### Usage
3
8
  *
4
9
  * ```typescript
5
10
  * import {Injectable, Opts, UseOpts} from "@tsed/di";
@@ -7,35 +12,38 @@
7
12
  * @Injectable()
8
13
  * class MyConfigurableService {
9
14
  * source: string;
10
- * constructor(@Opts options: any = {}) {
11
- * console.log("Hello ", options.source); // log: Hello Service1 then Hello Service2
12
15
  *
13
- * this.source = options.source;
16
+ * constructor(@Opts options: any = {}) {
17
+ * console.log("Hello", options.source);
18
+ * this.source = options.source;
14
19
  * }
15
20
  * }
16
21
  *
17
22
  * @Injectable()
18
23
  * class MyService1 {
19
24
  * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {
20
- * console.log(service.source) // log: Service1
25
+ * console.log(service.source); // "Service1"
21
26
  * }
22
27
  * }
23
28
  *
24
29
  * @Injectable()
25
30
  * class MyService2 {
26
31
  * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {
27
- * console.log(service.source) // log: Service2
32
+ * console.log(service.source); // "Service2"
28
33
  * }
29
34
  * }
30
35
  * ```
31
36
  *
32
- * ::: warning
33
- * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.
34
- * :::
37
+ * ### Warning
38
+ *
39
+ * Using `@Opts` changes the provider scope to `ProviderScope.INSTANCE`,
40
+ * meaning a new instance is created for each injection.
35
41
  *
36
- * @param target
37
- * @param propertyKey
38
- * @param index
42
+ * @param target The target class
43
+ * @param propertyKey The constructor method name
44
+ * @param index The parameter index
45
+ * @returns Parameter decorator
46
+ * @public
39
47
  * @decorator
40
48
  */
41
49
  export declare function Opts(target: any, propertyKey: string | symbol | undefined, index: number): void;
@@ -1,8 +1,42 @@
1
1
  import type { Type } from "@tsed/core/types/Type.js";
2
2
  /**
3
- * Override a provider which is already registered in ProviderRegistry.
4
- * @returns {Function}
5
- * @decorators
6
- * @param originalProvider
3
+ * Override an existing provider registration with a new implementation.
4
+ *
5
+ * Replaces the implementation class of a registered provider while keeping the same token.
6
+ * Useful for testing, plugin systems, or providing alternative implementations.
7
+ *
8
+ * ### Usage
9
+ *
10
+ * ```typescript
11
+ * import {Injectable, OverrideProvider} from "@tsed/di";
12
+ *
13
+ * @Injectable()
14
+ * class OriginalService {
15
+ * getData() {
16
+ * return "original";
17
+ * }
18
+ * }
19
+ *
20
+ * // Override with new implementation
21
+ * @OverrideProvider(OriginalService)
22
+ * class MockService {
23
+ * getData() {
24
+ * return "mocked";
25
+ * }
26
+ * }
27
+ *
28
+ * // Injected instances will now use MockService
29
+ * @Injectable()
30
+ * class UserService {
31
+ * constructor(private service: OriginalService) {
32
+ * console.log(this.service.getData()); // "mocked"
33
+ * }
34
+ * }
35
+ * ```
36
+ *
37
+ * @param originalProvider The provider class to override
38
+ * @returns Class decorator function
39
+ * @public
40
+ * @decorator
7
41
  */
8
42
  export declare function OverrideProvider(originalProvider: Type<any>): Function;
@@ -1,8 +1,37 @@
1
1
  import { ProviderScope } from "../domain/ProviderScope.js";
2
2
  /**
3
+ * Define the lifecycle scope of a provider.
3
4
  *
4
- * @param {"request" | "singleton" | ProviderScope} scope
5
- * @returns {Function}
6
- * @constructor
5
+ * Controls when and how provider instances are created and shared.
6
+ * Can be combined with `@Injectable()`, `@Service()`, or other provider decorators.
7
+ *
8
+ * ### Scopes
9
+ *
10
+ * - `SINGLETON`: One instance shared across the application (default)
11
+ * - `REQUEST`: New instance per request/context
12
+ * - `INSTANCE`: New instance on every injection
13
+ *
14
+ * ### Usage
15
+ *
16
+ * ```typescript
17
+ * import {Injectable, Scope, ProviderScope} from "@tsed/di";
18
+ *
19
+ * @Injectable()
20
+ * @Scope(ProviderScope.REQUEST)
21
+ * export class RequestScopedService {
22
+ * // New instance created for each request
23
+ * }
24
+ *
25
+ * @Injectable()
26
+ * @Scope("singleton")
27
+ * export class SingletonService {
28
+ * // Same instance shared across the app
29
+ * }
30
+ * ```
31
+ *
32
+ * @param scope The provider scope to set (default: REQUEST)
33
+ * @returns Class decorator function
34
+ * @public
35
+ * @decorator
7
36
  */
8
37
  export declare function Scope(scope?: "request" | "singleton" | ProviderScope): Function;
@@ -1,10 +1,30 @@
1
1
  /**
2
- * The decorators `@Service()` declare a new service can be injected in other service or controller on there `constructor`.
3
- * All services annotated with `@Service()` are constructed one time.
2
+ * Declare a service class that can be injected into other components.
4
3
  *
5
- * > `@Service()` use the `reflect-metadata` to collect and inject service on controllers or other services.
4
+ * Alias for `@Injectable()` decorator with default settings.
5
+ * Services are singleton-scoped and instantiated once during application startup.
6
6
  *
7
- * @returns {Function}
7
+ * ### Usage
8
+ *
9
+ * ```typescript
10
+ * import {Service} from "@tsed/di";
11
+ *
12
+ * @Service()
13
+ * export class UserService {
14
+ * async findById(id: string) {
15
+ * // Service logic
16
+ * }
17
+ * }
18
+ *
19
+ * // Use in another service or controller
20
+ * @Service()
21
+ * export class AuthService {
22
+ * constructor(private userService: UserService) {}
23
+ * }
24
+ * ```
25
+ *
26
+ * @returns Class decorator function
27
+ * @public
8
28
  * @decorator
9
29
  */
10
30
  export declare function Service(): Function;
@@ -1,5 +1,10 @@
1
1
  /**
2
- * Add options to invoke the Service.
2
+ * Pass custom options to an injected provider.
3
+ *
4
+ * Supplies configuration options when injecting a provider that accepts `@Opts`.
5
+ * Works with constructor parameters and property injection.
6
+ *
7
+ * ### Usage
3
8
  *
4
9
  * ```typescript
5
10
  * import {Injectable, Opts, UseOpts} from "@tsed/di";
@@ -7,35 +12,38 @@
7
12
  * @Injectable()
8
13
  * class MyConfigurableService {
9
14
  * source: string;
10
- * constructor(@Opts options: any = {}) {
11
- * console.log("Hello ", options.source); // log: Hello Service1 then Hello Service2
12
15
  *
13
- * this.source = options.source;
16
+ * constructor(@Opts options: any = {}) {
17
+ * this.source = options.source;
14
18
  * }
15
19
  * }
16
20
  *
17
21
  * @Injectable()
18
22
  * class MyService1 {
23
+ * // Constructor parameter with options
19
24
  * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {
20
- * console.log(service.source) // log: Service1
25
+ * console.log(service.source); // "Service1"
21
26
  * }
22
27
  * }
23
28
  *
24
29
  * @Injectable()
25
30
  * class MyService2 {
26
- * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {
27
- * console.log(service.source) // log: Service2
28
- * }
31
+ * // Property injection with options
32
+ * @Inject(MyConfigurableService)
33
+ * @UseOpts({source: 'Service2'})
34
+ * service: MyConfigurableService;
29
35
  * }
30
36
  * ```
31
37
  *
32
- * ::: warning
33
- * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.
34
- * :::
38
+ * ### Warning
39
+ *
40
+ * The injected provider must use `@Opts` to receive these options.
41
+ * Using `@Opts` automatically sets the provider scope to `INSTANCE`.
35
42
  *
36
- * @returns {Function}
43
+ * @param options Configuration object to pass to the provider
44
+ * @returns Decorator function (parameter or property)
45
+ * @public
37
46
  * @decorator
38
- * @param options
39
47
  */
40
48
  export declare function UseOpts(options: {
41
49
  [key: string]: any;
@@ -1,37 +1,43 @@
1
1
  export declare function bindValue(target: any, propertyKey: string | symbol, expression: string, defaultValue?: any): void;
2
2
  /**
3
- * Return value from Configuration.
3
+ * Inject a reactive configuration value into a property.
4
4
  *
5
- * ## Example
5
+ * Creates a getter/setter that always reflects the current configuration value.
6
+ * Unlike `@Constant()`, the value is not frozen and can change at runtime.
6
7
  *
7
- * ```typescript
8
- * import {Env} from "@tsed/core/domain/Env.js";
9
- * import {Constant, Value} from "@tsed/di";
10
- *
11
- * export class MyClass {
8
+ * ### Usage
12
9
  *
13
- * @Constant("env")
14
- * env: Env;
10
+ * ```typescript
11
+ * import {Injectable, Value} from "@tsed/di";
15
12
  *
16
- * @Value("swagger.path")
17
- * swaggerPath: string;
13
+ * @Injectable()
14
+ * export class MyService {
15
+ * @Value("swagger.path")
16
+ * swaggerPath: string;
18
17
  *
19
- * @Value("swagger.path", "defaultValue")
20
- * swaggerPath: string;
18
+ * @Value("api.port", 3000)
19
+ * port: number;
21
20
  *
22
- * constructor() {
23
- * console.log(this.swaggerPath) // undefined. Not available on constructor
24
- * }
21
+ * constructor() {
22
+ * // Not available yet - undefined
23
+ * }
25
24
  *
26
- * $onInit() {
27
- * console.log(this.swaggerPath) // something
28
- * }
25
+ * $onInit() {
26
+ * console.log(this.swaggerPath); // Current value
27
+ * this.swaggerPath = "/new-path"; // Can be modified
28
+ * }
29
29
  * }
30
30
  * ```
31
31
  *
32
- * @param expression
33
- * @param defaultValue
34
- * @returns {(targetClass: any, attributeName: string) => any}
32
+ * ### Difference from @Constant
33
+ *
34
+ * - `@Constant`: Frozen immutable value (deep clone)
35
+ * - `@Value`: Reactive value (always reads current config)
36
+ *
37
+ * @param expression Dot-notation path to the configuration value
38
+ * @param defaultValue Optional default value if not found
39
+ * @returns Property decorator function
40
+ * @public
35
41
  * @decorator
36
42
  */
37
43
  export declare function Value(expression: string, defaultValue?: unknown): PropertyDecorator;
@@ -2,6 +2,26 @@ import type { ProviderOpts } from "../interfaces/ProviderOpts.js";
2
2
  import type { TokenProvider } from "../interfaces/TokenProvider.js";
3
3
  import { Provider } from "./Provider.js";
4
4
  import type { ProviderType } from "./ProviderType.js";
5
+ /**
6
+ * Provider container managing registered providers and their metadata.
7
+ *
8
+ * Extends `Map` to provide specialized methods for adding, retrieving, and managing providers
9
+ * within the dependency injection system. Acts as a registry for all injectable classes and values.
10
+ *
11
+ * ### Usage
12
+ *
13
+ * ```typescript
14
+ * import {Container} from "@tsed/di";
15
+ *
16
+ * const container = new Container();
17
+ * container.add(MyService, {scope: ProviderScope.SINGLETON});
18
+ *
19
+ * const provider = container.getProvider(MyService);
20
+ * const controllers = container.getProviders(ProviderType.CONTROLLER);
21
+ * ```
22
+ *
23
+ * @public
24
+ */
5
25
  export declare class Container extends Map<TokenProvider, Provider> {
6
26
  /**
7
27
  *
@@ -1,6 +1,11 @@
1
1
  import { Hooks } from "@tsed/hooks";
2
2
  import { LogLevel } from "@tsed/logger";
3
3
  import { DILogger } from "../../common/index.js";
4
+ /**
5
+ * Options for creating a context logger instance.
6
+ *
7
+ * @public
8
+ */
4
9
  export interface ContextLoggerOptions extends Record<string, any> {
5
10
  id: string;
6
11
  logger?: DILogger;
@@ -8,6 +13,27 @@ export interface ContextLoggerOptions extends Record<string, any> {
8
13
  maxStackSize?: number;
9
14
  additionalProps?: Record<any, any>;
10
15
  }
16
+ /**
17
+ * Context-aware logger for scoped logging within a request or execution context.
18
+ *
19
+ * Buffers log messages and associates them with a specific context (like an HTTP request).
20
+ * Supports log level filtering, buffering, and automatic flushing when the context ends.
21
+ *
22
+ * ### Usage
23
+ *
24
+ * ```typescript
25
+ * import {ContextLogger} from "@tsed/di";
26
+ *
27
+ * const logger = new ContextLogger({id: "req-123"});
28
+ *
29
+ * logger.info("Processing request");
30
+ * logger.debug("Debug info");
31
+ *
32
+ * await logger.flush(); // Write buffered logs
33
+ * ```
34
+ *
35
+ * @public
36
+ */
11
37
  export declare class ContextLogger {
12
38
  #private;
13
39
  readonly dateStart: Date;