@tsed/di 7.0.0-beta.1 → 7.0.0-beta.12

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 (165) hide show
  1. package/lib/cjs/constants/{index.js → constants.js} +1 -1
  2. package/lib/cjs/constants/constants.js.map +1 -0
  3. package/lib/cjs/decorators/constant.js +1 -1
  4. package/lib/cjs/decorators/constant.js.map +1 -1
  5. package/lib/cjs/decorators/controller.js.map +1 -1
  6. package/lib/cjs/decorators/inject.js +27 -2
  7. package/lib/cjs/decorators/inject.js.map +1 -1
  8. package/lib/cjs/decorators/injectable.js +0 -2
  9. package/lib/cjs/decorators/injectable.js.map +1 -1
  10. package/lib/cjs/decorators/intercept.js +20 -12
  11. package/lib/cjs/decorators/intercept.js.map +1 -1
  12. package/lib/cjs/decorators/module.js +4 -3
  13. package/lib/cjs/decorators/module.js.map +1 -1
  14. package/lib/cjs/decorators/opts.js +1 -1
  15. package/lib/cjs/decorators/opts.js.map +1 -1
  16. package/lib/cjs/decorators/useOpts.js +1 -1
  17. package/lib/cjs/decorators/useOpts.js.map +1 -1
  18. package/lib/cjs/decorators/value.js +1 -1
  19. package/lib/cjs/decorators/value.js.map +1 -1
  20. package/lib/cjs/domain/Container.js.map +1 -1
  21. package/lib/cjs/domain/DIContext.js.map +1 -1
  22. package/lib/cjs/domain/Provider.js.map +1 -1
  23. package/lib/cjs/errors/InjectionError.js.map +1 -1
  24. package/lib/cjs/index.js +55 -17
  25. package/lib/cjs/index.js.map +1 -1
  26. package/lib/cjs/interfaces/DIConfigurationOptions.js.map +1 -1
  27. package/lib/cjs/interfaces/ProviderOpts.js +3 -0
  28. package/lib/cjs/interfaces/ProviderOpts.js.map +1 -0
  29. package/lib/cjs/interfaces/RegistrySettings.js.map +1 -1
  30. package/lib/cjs/interfaces/{IProvider.js → TokenRoute.js} +1 -1
  31. package/lib/cjs/interfaces/TokenRoute.js.map +1 -0
  32. package/lib/cjs/package.json +3 -0
  33. package/lib/cjs/registries/GlobalProviders.js +4 -4
  34. package/lib/cjs/registries/GlobalProviders.js.map +1 -1
  35. package/lib/cjs/registries/ProviderRegistry.js +7 -6
  36. package/lib/cjs/registries/ProviderRegistry.js.map +1 -1
  37. package/lib/cjs/services/DIConfiguration.js +7 -0
  38. package/lib/cjs/services/DIConfiguration.js.map +1 -1
  39. package/lib/cjs/services/DITest.js +8 -0
  40. package/lib/cjs/services/DITest.js.map +1 -1
  41. package/lib/cjs/services/InjectorService.js +65 -57
  42. package/lib/cjs/services/InjectorService.js.map +1 -1
  43. package/lib/cjs/utils/getConfiguration.js +11 -2
  44. package/lib/cjs/utils/getConfiguration.js.map +1 -1
  45. package/lib/cjs/utils/resolveControllers.js +47 -0
  46. package/lib/cjs/utils/resolveControllers.js.map +1 -0
  47. package/lib/cjs/utils/runInContext.js +19 -0
  48. package/lib/cjs/utils/runInContext.js.map +1 -0
  49. package/lib/esm/constants/{index.js → constants.js} +1 -1
  50. package/lib/esm/constants/constants.js.map +1 -0
  51. package/lib/esm/decorators/configuration.js +1 -1
  52. package/lib/esm/decorators/constant.js +2 -2
  53. package/lib/esm/decorators/constant.js.map +1 -1
  54. package/lib/esm/decorators/controller.js +1 -1
  55. package/lib/esm/decorators/controller.js.map +1 -1
  56. package/lib/esm/decorators/inject.js +25 -1
  57. package/lib/esm/decorators/inject.js.map +1 -1
  58. package/lib/esm/decorators/injectable.js +1 -3
  59. package/lib/esm/decorators/injectable.js.map +1 -1
  60. package/lib/esm/decorators/intercept.js +21 -13
  61. package/lib/esm/decorators/intercept.js.map +1 -1
  62. package/lib/esm/decorators/interceptor.js +2 -2
  63. package/lib/esm/decorators/lazyInject.js +1 -1
  64. package/lib/esm/decorators/module.js +4 -3
  65. package/lib/esm/decorators/module.js.map +1 -1
  66. package/lib/esm/decorators/opts.js +4 -4
  67. package/lib/esm/decorators/opts.js.map +1 -1
  68. package/lib/esm/decorators/overrideProvider.js +1 -1
  69. package/lib/esm/decorators/scope.js +1 -1
  70. package/lib/esm/decorators/service.js +1 -1
  71. package/lib/esm/decorators/useOpts.js +1 -1
  72. package/lib/esm/decorators/useOpts.js.map +1 -1
  73. package/lib/esm/decorators/value.js +2 -2
  74. package/lib/esm/decorators/value.js.map +1 -1
  75. package/lib/esm/domain/Container.js +2 -2
  76. package/lib/esm/domain/Container.js.map +1 -1
  77. package/lib/esm/domain/DIContext.js +2 -2
  78. package/lib/esm/domain/DIContext.js.map +1 -1
  79. package/lib/esm/domain/Provider.js +2 -2
  80. package/lib/esm/domain/Provider.js.map +1 -1
  81. package/lib/esm/errors/InjectionError.js +1 -1
  82. package/lib/esm/errors/InjectionError.js.map +1 -1
  83. package/lib/esm/index.js +55 -17
  84. package/lib/esm/index.js.map +1 -1
  85. package/lib/esm/interfaces/DIConfigurationOptions.js.map +1 -1
  86. package/lib/esm/interfaces/ProviderOpts.js +2 -0
  87. package/lib/esm/interfaces/ProviderOpts.js.map +1 -0
  88. package/lib/esm/interfaces/RegistrySettings.js.map +1 -1
  89. package/lib/esm/interfaces/TokenRoute.js +2 -0
  90. package/lib/esm/interfaces/TokenRoute.js.map +1 -0
  91. package/lib/esm/package.json +3 -0
  92. package/lib/esm/registries/GlobalProviders.js +2 -2
  93. package/lib/esm/registries/GlobalProviders.js.map +1 -1
  94. package/lib/esm/registries/ProviderRegistry.js +5 -4
  95. package/lib/esm/registries/ProviderRegistry.js.map +1 -1
  96. package/lib/esm/services/DIConfiguration.js +7 -0
  97. package/lib/esm/services/DIConfiguration.js.map +1 -1
  98. package/lib/esm/services/DILogger.js +2 -2
  99. package/lib/esm/services/DITest.js +12 -4
  100. package/lib/esm/services/DITest.js.map +1 -1
  101. package/lib/esm/services/InjectorService.js +47 -39
  102. package/lib/esm/services/InjectorService.js.map +1 -1
  103. package/lib/esm/utils/createContainer.js +2 -2
  104. package/lib/esm/utils/getConfiguration.js +10 -2
  105. package/lib/esm/utils/getConfiguration.js.map +1 -1
  106. package/lib/esm/utils/resolveControllers.js +42 -0
  107. package/lib/esm/utils/resolveControllers.js.map +1 -0
  108. package/lib/esm/utils/runInContext.js +13 -0
  109. package/lib/esm/utils/runInContext.js.map +1 -0
  110. package/lib/types/constants/{index.d.ts → constants.d.ts} +0 -0
  111. package/lib/types/decorators/controller.d.ts +2 -2
  112. package/lib/types/decorators/inject.d.ts +15 -0
  113. package/lib/types/decorators/injectable.d.ts +2 -4
  114. package/lib/types/decorators/intercept.d.ts +2 -2
  115. package/lib/types/decorators/module.d.ts +3 -2
  116. package/lib/types/domain/Container.d.ts +3 -3
  117. package/lib/types/domain/DIContext.d.ts +0 -6
  118. package/lib/types/domain/Provider.d.ts +4 -6
  119. package/lib/types/errors/InjectionError.d.ts +1 -1
  120. package/lib/types/index.d.ts +49 -11
  121. package/lib/types/interfaces/DIConfigurationOptions.d.ts +4 -0
  122. package/lib/types/interfaces/{IProvider.d.ts → ProviderOpts.d.ts} +5 -4
  123. package/lib/types/interfaces/RegistrySettings.d.ts +1 -1
  124. package/lib/types/interfaces/TokenRoute.d.ts +5 -0
  125. package/lib/types/registries/GlobalProviders.d.ts +6 -4
  126. package/lib/types/registries/ProviderRegistry.d.ts +4 -4
  127. package/lib/types/services/DIConfiguration.d.ts +6 -2
  128. package/lib/types/services/DITest.d.ts +2 -0
  129. package/lib/types/services/InjectorService.d.ts +17 -18
  130. package/lib/types/utils/getConfiguration.d.ts +1 -0
  131. package/lib/types/utils/resolveControllers.d.ts +12 -0
  132. package/lib/types/utils/runInContext.d.ts +6 -0
  133. package/package.json +28 -10
  134. package/readme.md +39 -42
  135. package/tsconfig.compile.esm.json +1 -0
  136. package/lib/cjs/constants/index.js.map +0 -1
  137. package/lib/cjs/decorators/index.js +0 -19
  138. package/lib/cjs/decorators/index.js.map +0 -1
  139. package/lib/cjs/domain/index.js +0 -12
  140. package/lib/cjs/domain/index.js.map +0 -1
  141. package/lib/cjs/interfaces/IProvider.js.map +0 -1
  142. package/lib/cjs/interfaces/index.js +0 -18
  143. package/lib/cjs/interfaces/index.js.map +0 -1
  144. package/lib/cjs/utils/data/Test1.js +0 -8
  145. package/lib/cjs/utils/data/Test1.js.map +0 -1
  146. package/lib/cjs/utils/data/Test2.js +0 -8
  147. package/lib/cjs/utils/data/Test2.js.map +0 -1
  148. package/lib/esm/constants/index.js.map +0 -1
  149. package/lib/esm/decorators/index.js +0 -16
  150. package/lib/esm/decorators/index.js.map +0 -1
  151. package/lib/esm/domain/index.js +0 -9
  152. package/lib/esm/domain/index.js.map +0 -1
  153. package/lib/esm/interfaces/IProvider.js +0 -2
  154. package/lib/esm/interfaces/IProvider.js.map +0 -1
  155. package/lib/esm/interfaces/index.js +0 -15
  156. package/lib/esm/interfaces/index.js.map +0 -1
  157. package/lib/esm/utils/data/Test1.js +0 -4
  158. package/lib/esm/utils/data/Test1.js.map +0 -1
  159. package/lib/esm/utils/data/Test2.js +0 -4
  160. package/lib/esm/utils/data/Test2.js.map +0 -1
  161. package/lib/types/decorators/index.d.ts +0 -15
  162. package/lib/types/domain/index.d.ts +0 -8
  163. package/lib/types/interfaces/index.d.ts +0 -14
  164. package/lib/types/utils/data/Test1.d.ts +0 -3
  165. package/lib/types/utils/data/Test2.d.ts +0 -3
@@ -1,17 +1,55 @@
1
- export * from "./constants/index";
2
- export * from "./domain";
3
- export * from "./interfaces";
4
- export * from "./decorators";
5
- export * from "./registries/ProviderRegistry";
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
4
+ export * from "./constants/constants";
5
+ export * from "./decorators/configuration";
6
+ export * from "./decorators/constant";
7
+ export * from "./decorators/controller";
8
+ export * from "./decorators/inject";
9
+ export * from "./decorators/injectable";
10
+ export * from "./decorators/intercept";
11
+ export * from "./decorators/interceptor";
12
+ export * from "./decorators/lazyInject";
13
+ export * from "./decorators/module";
14
+ export * from "./decorators/opts";
15
+ export * from "./decorators/overrideProvider";
16
+ export * from "./decorators/scope";
17
+ export * from "./decorators/service";
18
+ export * from "./decorators/useOpts";
19
+ export * from "./decorators/value";
20
+ export * from "./domain/Container";
21
+ export * from "./domain/ContextLogger";
22
+ export * from "./domain/DIContext";
23
+ export * from "./domain/InjectablePropertyType";
24
+ export * from "./domain/LocalsContainer";
25
+ export * from "./domain/Provider";
26
+ export * from "./domain/ProviderScope";
27
+ export * from "./domain/ProviderType";
28
+ export * from "./errors/InjectionError";
29
+ export * from "./errors/UndefinedTokenError";
30
+ export * from "./interfaces/DIConfigurationOptions";
31
+ export * from "./interfaces/DILogger";
32
+ export * from "./interfaces/DIResolver";
33
+ export * from "./interfaces/InjectableProperties";
34
+ export * from "./interfaces/InterceptorContext";
35
+ export * from "./interfaces/InterceptorMethods";
36
+ export * from "./interfaces/InvokeOptions";
37
+ export * from "./interfaces/OnDestroy";
38
+ export * from "./interfaces/OnInit";
39
+ export * from "./interfaces/ProviderOpts";
40
+ export * from "./interfaces/RegistrySettings";
41
+ export * from "./interfaces/ResolvedInvokeOptions";
42
+ export * from "./interfaces/TokenProvider";
43
+ export * from "./interfaces/TokenRoute";
6
44
  export * from "./registries/GlobalProviders";
7
- export * from "./services/InjectorService";
8
- export * from "./services/DILogger";
45
+ export * from "./registries/ProviderRegistry";
9
46
  export * from "./services/DIConfiguration";
47
+ export * from "./services/DILogger";
10
48
  export * from "./services/DITest";
11
- export * from "./errors/InjectionError";
12
- export * from "./errors/UndefinedTokenError";
49
+ export * from "./services/InjectorService";
50
+ export * from "./utils/colors";
13
51
  export * from "./utils/createContainer";
14
52
  export * from "./utils/getConfiguration";
15
- export * from "./utils/getConfiguration";
53
+ export * from "./utils/resolveControllers";
54
+ export * from "./utils/runInContext";
16
55
  export * from "./utils/setLoggerLevel";
17
- export * from "./utils/colors";
@@ -17,6 +17,10 @@ declare global {
17
17
  * Define dependencies to build the provider
18
18
  */
19
19
  imports: TokenProvider[];
20
+ /**
21
+ * Mount controllers
22
+ */
23
+ mount: Record<string, TokenProvider[]>;
20
24
  [key: string]: any;
21
25
  }
22
26
  }
@@ -3,10 +3,7 @@ import type { DIResolver } from "./DIResolver";
3
3
  import type { ProviderScope } from "../domain/ProviderScope";
4
4
  import type { ProviderType } from "../domain/ProviderType";
5
5
  import type { TokenProvider } from "./TokenProvider";
6
- /**
7
- *
8
- */
9
- export interface IProvider<T = any> {
6
+ export interface ProviderOpts<T = any> {
10
7
  /**
11
8
  * An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
12
9
  */
@@ -47,6 +44,10 @@ export interface IProvider<T = any> {
47
44
  * A list of resolvers which will be used to resolve missing Symbol/Class when injector invoke a Class. This property allow external DI usage.
48
45
  */
49
46
  resolvers?: DIResolver[];
47
+ /**
48
+ * hooks to intercept custom events
49
+ */
50
+ hooks?: Record<string, (instance: T, ...args: any[]) => Promise<any> | any>;
50
51
  /**
51
52
  *
52
53
  */
@@ -1,5 +1,5 @@
1
1
  import { Type } from "@tsed/core";
2
- import type { Provider } from "../domain";
2
+ import type { Provider } from "../domain/Provider";
3
3
  import type { InjectorService } from "../services/InjectorService";
4
4
  import type { ResolvedInvokeOptions } from "./ResolvedInvokeOptions";
5
5
  /**
@@ -0,0 +1,5 @@
1
+ import { TokenProvider } from "./TokenProvider";
2
+ export interface TokenRoute {
3
+ token: TokenProvider;
4
+ route: string;
5
+ }
@@ -1,8 +1,10 @@
1
1
  import { Type } from "@tsed/core";
2
2
  import { Provider } from "../domain/Provider";
3
- import type { IProvider, RegistrySettings, TokenProvider } from "../interfaces";
4
3
  import type { InjectorService } from "../services/InjectorService";
5
4
  import { ResolvedInvokeOptions } from "../interfaces/ResolvedInvokeOptions";
5
+ import { TokenProvider } from "../interfaces/TokenProvider";
6
+ import { RegistrySettings } from "../interfaces/RegistrySettings";
7
+ import { ProviderOpts } from "../interfaces/ProviderOpts";
6
8
  export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider> {
7
9
  #private;
8
10
  /**
@@ -28,7 +30,7 @@ export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider>
28
30
  * @param target
29
31
  * @param options
30
32
  */
31
- merge(target: TokenProvider, options: Partial<IProvider>): void;
33
+ merge(target: TokenProvider, options: Partial<ProviderOpts>): void;
32
34
  /**
33
35
  * The delete() method removes the specified element from a Map object.
34
36
  * @param key Required. The key of the element to remove from the Map object.
@@ -40,13 +42,13 @@ export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider>
40
42
  injector: InjectorService;
41
43
  }): void;
42
44
  getRegistrySettings(target: string | TokenProvider): RegistrySettings;
43
- createRegisterFn(type: string): (provider: any | IProvider, instance?: any) => void;
45
+ createRegisterFn(type: string): (provider: any | ProviderOpts, instance?: any) => void;
44
46
  /**
45
47
  *
46
48
  * @param key
47
49
  * @param options
48
50
  */
49
- protected createIfNotExists(key: TokenProvider, options: Partial<IProvider>): Provider;
51
+ protected createIfNotExists(key: TokenProvider, options: Partial<ProviderOpts>): Provider;
50
52
  }
51
53
  /**
52
54
  *
@@ -1,9 +1,9 @@
1
- import type { IProvider } from "../interfaces";
1
+ import type { ProviderOpts } from "../interfaces/ProviderOpts";
2
2
  /**
3
3
  * Register a provider configuration.
4
- * @param {IProvider<any>} provider
4
+ * @param {ProviderOpts<any>} provider
5
5
  */
6
- export declare function registerProvider(provider: Partial<IProvider>): void;
6
+ export declare function registerProvider<Type = any>(provider: Partial<ProviderOpts<Type>>): void;
7
7
  /**
8
8
  * Add a new value in the `ProviderRegistry`.
9
9
  *
@@ -25,7 +25,7 @@ export declare function registerProvider(provider: Partial<IProvider>): void;
25
25
  * }
26
26
  * ```
27
27
  */
28
- export declare const registerValue: (provider: any | IProvider<any>, value?: any) => void;
28
+ export declare const registerValue: (provider: any | ProviderOpts<any>, value?: any) => void;
29
29
  /**
30
30
  * Add a new controller in the `ProviderRegistry`. This controller will be built when `InjectorService` will be loaded.
31
31
  *
@@ -1,5 +1,7 @@
1
- import { ProviderScope } from "../domain";
2
- import type { DIResolver, TokenProvider } from "../interfaces";
1
+ import { ProviderScope } from "../domain/ProviderScope";
2
+ import type { DIResolver } from "../interfaces/DIResolver";
3
+ import type { TokenProvider } from "../interfaces/TokenProvider";
4
+ import { TokenRoute } from "../interfaces/TokenRoute";
3
5
  export declare class DIConfiguration {
4
6
  readonly default: Map<string, any>;
5
7
  protected map: Map<string, any>;
@@ -15,6 +17,8 @@ export declare class DIConfiguration {
15
17
  set resolvers(resolvers: DIResolver[]);
16
18
  get imports(): TokenProvider[];
17
19
  set imports(imports: TokenProvider[]);
20
+ get routes(): TokenRoute[];
21
+ set routes(routes: TokenRoute[]);
18
22
  /**
19
23
  *
20
24
  * @param callbackfn
@@ -1,5 +1,6 @@
1
1
  import { TokenProvider } from "../interfaces/TokenProvider";
2
2
  import { InjectorService } from "./InjectorService";
3
+ import { DIContext } from "../domain/DIContext";
3
4
  export interface DITestInvokeOptions {
4
5
  token?: TokenProvider;
5
6
  use: any;
@@ -37,5 +38,6 @@ export declare class DITest {
37
38
  * @param options
38
39
  */
39
40
  static get<T = any>(target: TokenProvider, options?: any): T;
41
+ static createDIContext(): DIContext;
40
42
  protected static configure(settings?: Partial<TsED.Configuration>): Partial<TsED.Configuration>;
41
43
  }
@@ -1,9 +1,12 @@
1
- import { DIContext, ProviderScope } from "../domain";
2
1
  import { Container } from "../domain/Container";
3
2
  import { LocalsContainer } from "../domain/LocalsContainer";
4
3
  import { Provider } from "../domain/Provider";
5
- import { DILogger, InjectablePropertyOptions, InjectablePropertyValue, InvokeOptions, IProvider, TokenProvider } from "../interfaces";
6
4
  import { DIConfiguration } from "./DIConfiguration";
5
+ import { ProviderScope } from "../domain/ProviderScope";
6
+ import { DILogger } from "../interfaces/DILogger";
7
+ import { TokenProvider } from "../interfaces/TokenProvider";
8
+ import { InvokeOptions } from "../interfaces/InvokeOptions";
9
+ import { InjectablePropertyOptions, InjectablePropertyValue } from "../interfaces/InjectableProperties";
7
10
  /**
8
11
  * This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.
9
12
  *
@@ -17,7 +20,7 @@ import { DIConfiguration } from "./DIConfiguration";
17
20
  * import MyService2 from "./services/service2";
18
21
  * import MyService3 from "./services/service3";
19
22
  *
20
- * // When all services is imported you can load InjectorService.
23
+ * // When all services are imported, you can load InjectorService.
21
24
  * const injector = new InjectorService()
22
25
  *
23
26
  * await injector.load();
@@ -31,7 +34,7 @@ export declare class InjectorService extends Container {
31
34
  logger: DILogger;
32
35
  private resolvedConfiguration;
33
36
  constructor();
34
- get resolvers(): import("../interfaces").DIResolver[];
37
+ get resolvers(): import("..").DIResolver[];
35
38
  get scopes(): {
36
39
  [key: string]: ProviderScope;
37
40
  } & {
@@ -42,13 +45,6 @@ export declare class InjectorService extends Container {
42
45
  * @param provider
43
46
  */
44
47
  scopeOf(provider: Provider): ProviderScope;
45
- /**
46
- * Clone a provider from GlobalProviders and the given token. forkProvider method build automatically the provider if the instance parameter ins't given.
47
- * @param token
48
- * @param settings
49
- * @deprecated
50
- */
51
- forkProvider(token: TokenProvider, settings?: Partial<IProvider<any>>): Provider;
52
48
  /**
53
49
  * Return a list of instance build by the injector.
54
50
  */
@@ -74,6 +70,11 @@ export declare class InjectorService extends Container {
74
70
  * @returns {boolean}
75
71
  */
76
72
  get<T = any>(token: TokenProvider, options?: any): T | undefined;
73
+ /**
74
+ * Return all instance of the same provider type
75
+ * @param type
76
+ */
77
+ getAll(type: string): any[];
77
78
  /**
78
79
  * The has() method returns a boolean indicating whether an element with the specified key exists or not.
79
80
  * @returns {boolean}
@@ -113,6 +114,11 @@ export declare class InjectorService extends Container {
113
114
  * @param container
114
115
  */
115
116
  bootstrap(container?: Container): this;
117
+ /**
118
+ * Load injector from a given module
119
+ * @param rootModule
120
+ */
121
+ loadModule(rootModule: TokenProvider): Promise<LocalsContainer<any>>;
116
122
  /**
117
123
  * Build all providers from given container (or GlobalProviders) and emit `$onInit` event.
118
124
  *
@@ -171,13 +177,6 @@ export declare class InjectorService extends Container {
171
177
  * @param options
172
178
  */
173
179
  bindInterceptor(instance: any, { propertyKey, useType, options }: InjectablePropertyOptions): void;
174
- /**
175
- * Allow handler hack for AsyncHookContext plugin.
176
- * @param ctx
177
- * @param cb
178
- * @protected
179
- */
180
- runInContext(ctx: DIContext, cb: any): any;
181
180
  lazyInvoke<T = any>(token: TokenProvider): Promise<any>;
182
181
  /**
183
182
  * Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
@@ -1,2 +1,3 @@
1
1
  import { Type } from "@tsed/core";
2
+ export declare function mergeMount(m1?: any, m2?: any): any;
2
3
  export declare function getConfiguration(module: Type<any>, configuration?: any): any;
@@ -0,0 +1,12 @@
1
+ import { TokenProvider } from "../interfaces/TokenProvider";
2
+ import { TokenRoute } from "../interfaces/TokenRoute";
3
+ export declare function getTokens(config: any): {
4
+ route?: string;
5
+ token: TokenProvider;
6
+ }[];
7
+ /**
8
+ * Return controllers and is base route according to his configuration in module configuration.
9
+ *
10
+ * @param settings
11
+ */
12
+ export declare function resolveControllers(settings: Partial<TsED.Configuration>): TokenRoute[];
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ import { AsyncLocalStorage } from "async_hooks";
3
+ import { DIContext } from "../domain/DIContext";
4
+ export declare function getAsyncStore(): AsyncLocalStorage<DIContext>;
5
+ export declare function getContext(): DIContext | undefined;
6
+ export declare function runInContext(ctx: DIContext, cb: any): unknown;
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@tsed/di",
3
- "version": "7.0.0-beta.1",
3
+ "version": "7.0.0-beta.12",
4
4
  "description": "DI module for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/cjs/index.js",
8
+ "module": "./lib/esm/index.js",
8
9
  "typings": "./lib/types/index.d.ts",
9
10
  "exports": {
10
11
  "types": "./lib/types/index.d.ts",
@@ -13,26 +14,43 @@
13
14
  "default": "./lib/esm/index.js"
14
15
  },
15
16
  "scripts": {
16
- "build": "yarn run build:esm && yarn run build:cjs",
17
+ "build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
17
18
  "build:cjs": "tsc --build tsconfig.compile.json",
18
- "build:esm": "tsc --build tsconfig.compile.esm.json"
19
+ "build:esm": "tsc --build tsconfig.compile.esm.json",
20
+ "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\""
19
21
  },
20
22
  "dependencies": {
21
- "@tsed/core": "7.0.0-beta.1",
22
- "@tsed/schema": "7.0.0-beta.1",
23
- "tslib": "2.2.0"
23
+ "tslib": "2.3.1"
24
24
  },
25
25
  "devDependencies": {
26
- "@tsed/logger": "^6.0.0"
26
+ "@tsed/core": "7.0.0-beta.12",
27
+ "@tsed/logger": ">=6.1.1",
28
+ "@tsed/schema": "7.0.0-beta.12"
27
29
  },
28
30
  "peerDependencies": {
29
- "@tsed/logger": ">=6.0.0"
31
+ "@tsed/core": "^7.0.0-beta.12",
32
+ "@tsed/logger": ">=6.1.1",
33
+ "@tsed/schema": "^7.0.0-beta.12"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "@tsed/core": {
37
+ "optional": false
38
+ },
39
+ "@tsed/logger": {
40
+ "optional": false
41
+ },
42
+ "@tsed/schema": {
43
+ "optional": false
44
+ }
30
45
  },
31
46
  "repository": "https://github.com/tsedio/tsed",
32
47
  "bugs": {
33
48
  "url": "https://github.com/tsedio/tsed/issues"
34
49
  },
35
- "homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/di",
50
+ "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/di",
36
51
  "author": "Romain Lenzotti",
37
- "license": "MIT"
52
+ "license": "MIT",
53
+ "publishConfig": {
54
+ "tag": "beta"
55
+ }
38
56
  }
package/readme.md CHANGED
@@ -11,7 +11,8 @@
11
11
  [![npm version](https://badge.fury.io/js/%40tsed%2Fcommon.svg)](https://badge.fury.io/js/%40tsed%2Fcommon)
12
12
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
13
13
  [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
14
- [![backers](https://opencollective.com/tsed/tiers/badge.svg)](https://opencollective.com/tsed)
14
+ [![github](https://img.shields.io/static/v1?label=Github%20sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/romakita)
15
+ [![opencollective](https://img.shields.io/static/v1?label=OpenCollective%20sponsor&message=%E2%9D%A4&logo=OpenCollective&color=%23fe8e86)](https://opencollective.com/tsed)
15
16
 
16
17
  </div>
17
18
 
@@ -32,39 +33,36 @@ A package of Ts.ED framework. See website: https://tsed.io/
32
33
  # Installation
33
34
 
34
35
  You can get the latest release and the type definitions using npm:
36
+
35
37
  ```bash
36
38
  npm install --save @tsed/di
37
39
  ```
38
40
 
39
- > **Important!** TsExpressDecorators requires Node >= 6, Express >= 4, TypeScript >= 2.0 and
40
- the `experimentalDecorators`, `emitDecoratorMetadata`, `types` and `lib` compilation
41
- options in your `tsconfig.json` file.
41
+ > **Important!** TsExpressDecorators requires Node >= 6, Express >= 4, TypeScript >= 2.0 and
42
+ > the `experimentalDecorators`, `emitDecoratorMetadata`, `types` and `lib` compilation
43
+ > options in your `tsconfig.json` file.
42
44
 
43
45
  ```json
44
46
  {
45
47
  "compilerOptions": {
46
48
  "target": "es2016",
47
49
  "lib": ["es2016"],
48
- "typeRoots": [
49
- "./node_modules/@types"
50
- ],
50
+ "typeRoots": ["./node_modules/@types"],
51
51
  "module": "commonjs",
52
52
  "moduleResolution": "node",
53
- "experimentalDecorators":true,
53
+ "experimentalDecorators": true,
54
54
  "emitDecoratorMetadata": true,
55
55
  "allowSyntheticDefaultImports": true
56
56
  },
57
- "exclude": [
58
- "node_modules"
59
- ]
57
+ "exclude": ["node_modules"]
60
58
  }
61
59
  ```
62
60
 
63
61
  ## Introduction
64
62
 
65
- Basically, almost everything may be considered as a provider – service, factory, intereceptors, and so on.
63
+ Basically, almost everything may be considered as a provider – service, factory, intereceptors, and so on.
66
64
  All of them can inject dependencies, meaning, they can create various relationships with each other.
67
- But in fact, a provider is nothing else than just a simple class annotated with an `@Injectable()` decorator.
65
+ But in fact, a provider is nothing else than just a simple class annotated with an `@Injectable()` decorator.
68
66
 
69
67
  ## Usage
70
68
 
@@ -77,27 +75,28 @@ import {Calendar} from "./models/calendar";
77
75
  @Injectable()
78
76
  export class CalendarsService {
79
77
  private readonly calendars: Calendar[] = [];
80
-
81
- create(calendar: Calendar) {
82
- this.calendars.push(calendar);
83
- }
84
-
85
- findAll(): Calendar[] {
86
- return this.calendars;
87
- }
78
+
79
+ create(calendar: Calendar) {
80
+ this.calendars.push(calendar);
81
+ }
82
+
83
+ findAll(): Calendar[] {
84
+ return this.calendars;
85
+ }
88
86
  }
89
87
  ```
90
88
 
91
89
  Here's a CalendarsService, a basic class with one property and two methods. The only new trait is that it uses the `@Injectable()` decorator.
92
90
  The `@Injectable()` attaches the metadata, thereby Ts.ED knows that this class is a provider.
93
-
91
+
94
92
  Now we have the service class already done, let's use it inside a controller:
93
+
95
94
  ```typescript
96
- import { Controller, Post, Body, Get } from '@tsed/common';
97
- import { CalendarsService } from './CalendarsService';
98
- import { Calendar } from './models/Calendar';
95
+ import {Controller, Post, Body, Get} from "@tsed/common";
96
+ import {CalendarsService} from "./CalendarsService";
97
+ import {Calendar} from "./models/Calendar";
99
98
 
100
- @Controller('/calendars')
99
+ @Controller("/calendars")
101
100
  export class CalendarCtrl {
102
101
  constructor(private readonly calendarsService: CalendarsService) {}
103
102
 
@@ -112,30 +111,31 @@ export class CalendarCtrl {
112
111
  }
113
112
  }
114
113
  ```
115
- > Note: Controller isn't a part of `@tsed/di`. `@Controller` decorator is exposed by `@tsed/common` package because it's a specific provider
116
- used by the Ts.ED framework. Ts.ED DI allow you to define your own Provider and decorator.
117
114
 
115
+ > Note: Controller isn't a part of `@tsed/di`. `@Controller` decorator is exposed by `@tsed/common` package because it's a specific provider
116
+ > used by the Ts.ED framework. Ts.ED DI allow you to define your own Provider and decorator.
118
117
 
119
118
  Finally, we can load the injector and use:
119
+
120
120
  ```typescript
121
121
  import {InjectorService} from "@tsed/di";
122
122
  import {CalendarCtrl} from "./CalendarCtrl";
123
123
 
124
124
  async function bootstrap() {
125
- const injector = new InjectorService()
126
-
125
+ const injector = new InjectorService();
126
+
127
127
  // Load all providers registered via @Injectable decorator
128
- await injector.load()
129
-
130
- const calendarController = injector.get<CalendarCtrl>()
131
-
132
- await calendarController.create(new Calendar())
133
-
128
+ await injector.load();
129
+
130
+ const calendarController = injector.get<CalendarCtrl>();
131
+
132
+ await calendarController.create(new Calendar());
133
+
134
134
  // And finally destroy injector and his instances (see injector hooks)
135
- await injector.destroy()
135
+ await injector.destroy();
136
136
  }
137
137
 
138
- bootstrap()
138
+ bootstrap();
139
139
  ```
140
140
 
141
141
  ## Custom providers
@@ -147,23 +147,20 @@ To organize your code Ts.ED DI provide different kind of providers:
147
147
  - Interceptor can be declared with `@Interceptor`,
148
148
  - Factory and Value can be declared with `registerProvider` and `registerValue`.
149
149
 
150
-
151
150
  See more details on our documentation https://tsed.io/providers.html
152
151
 
153
-
154
152
  ## Contributors
153
+
155
154
  Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
156
155
 
157
156
  <a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
158
157
 
159
-
160
158
  ## Backers
161
159
 
162
160
  Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
163
161
 
164
162
  <a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
165
163
 
166
-
167
164
  ## Sponsors
168
165
 
169
166
  Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
@@ -8,6 +8,7 @@
8
8
  "declaration": true,
9
9
  "declarationDir": "./lib/types"
10
10
  },
11
+ "include": ["src"],
11
12
  "exclude": [
12
13
  "node_modules",
13
14
  "test",
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,oBAAoB,CAAC;AACvC,QAAA,SAAS,GAAG,WAAW,CAAC;AACxB,QAAA,gBAAgB,GAAG,kBAAkB,CAAC","sourcesContent":["export const INJECTABLE_PROP = \"DI:INJECTABLE_PROP\";\nexport const DI_PARAMS = \"DI:PARAMS\";\nexport const DI_PARAM_OPTIONS = \"DI:PARAM:OPTIONS\";\n"]}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./scope"), exports);
5
- (0, tslib_1.__exportStar)(require("./service"), exports);
6
- (0, tslib_1.__exportStar)(require("./overrideProvider"), exports);
7
- (0, tslib_1.__exportStar)(require("./inject"), exports);
8
- (0, tslib_1.__exportStar)(require("./lazyInject"), exports);
9
- (0, tslib_1.__exportStar)(require("./injectable"), exports);
10
- (0, tslib_1.__exportStar)(require("./constant"), exports);
11
- (0, tslib_1.__exportStar)(require("./value"), exports);
12
- (0, tslib_1.__exportStar)(require("./intercept"), exports);
13
- (0, tslib_1.__exportStar)(require("./interceptor"), exports);
14
- (0, tslib_1.__exportStar)(require("./configuration"), exports);
15
- (0, tslib_1.__exportStar)(require("./module"), exports);
16
- (0, tslib_1.__exportStar)(require("./opts"), exports);
17
- (0, tslib_1.__exportStar)(require("./useOpts"), exports);
18
- (0, tslib_1.__exportStar)(require("./controller"), exports);
19
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,uDAAwB;AACxB,yDAA0B;AAC1B,kEAAmC;AACnC,wDAAyB;AACzB,4DAA6B;AAC7B,4DAA6B;AAC7B,0DAA2B;AAC3B,uDAAwB;AACxB,2DAA4B;AAC5B,6DAA8B;AAC9B,+DAAgC;AAChC,wDAAyB;AACzB,sDAAuB;AACvB,yDAA0B;AAC1B,4DAA6B","sourcesContent":["export * from \"./scope\";\nexport * from \"./service\";\nexport * from \"./overrideProvider\";\nexport * from \"./inject\";\nexport * from \"./lazyInject\";\nexport * from \"./injectable\";\nexport * from \"./constant\";\nexport * from \"./value\";\nexport * from \"./intercept\";\nexport * from \"./interceptor\";\nexport * from \"./configuration\";\nexport * from \"./module\";\nexport * from \"./opts\";\nexport * from \"./useOpts\";\nexport * from \"./controller\";\n"]}
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./Container"), exports);
5
- (0, tslib_1.__exportStar)(require("./InjectablePropertyType"), exports);
6
- (0, tslib_1.__exportStar)(require("./LocalsContainer"), exports);
7
- (0, tslib_1.__exportStar)(require("./Provider"), exports);
8
- (0, tslib_1.__exportStar)(require("./ProviderScope"), exports);
9
- (0, tslib_1.__exportStar)(require("./ProviderType"), exports);
10
- (0, tslib_1.__exportStar)(require("./ContextLogger"), exports);
11
- (0, tslib_1.__exportStar)(require("./DIContext"), exports);
12
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/index.ts"],"names":[],"mappings":";;;AAAA,2DAA4B;AAC5B,wEAAyC;AACzC,iEAAkC;AAClC,0DAA2B;AAC3B,+DAAgC;AAChC,8DAA+B;AAC/B,+DAAgC;AAChC,2DAA4B","sourcesContent":["export * from \"./Container\";\nexport * from \"./InjectablePropertyType\";\nexport * from \"./LocalsContainer\";\nexport * from \"./Provider\";\nexport * from \"./ProviderScope\";\nexport * from \"./ProviderType\";\nexport * from \"./ContextLogger\";\nexport * from \"./DIContext\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../../src/interfaces/IProvider.ts"],"names":[],"mappings":"","sourcesContent":["import type {Type} from \"@tsed/core\";\nimport type {DIResolver} from \"./DIResolver\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {ProviderType} from \"../domain/ProviderType\";\nimport type {TokenProvider} from \"./TokenProvider\";\n/**\n *\n */\nexport interface IProvider<T = any> {\n /**\n * An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).\n */\n provide: TokenProvider;\n /**\n * Provider type\n */\n type?: ProviderType | string;\n /**\n * Instance build by the injector\n */\n instance?: T;\n /**\n * Define dependencies to build the provider\n */\n deps?: TokenProvider[];\n /**\n * Class to instantiate for the `token`.\n */\n useClass?: Type<T>;\n /**\n * Provide a function to build the provider\n */\n useFactory?: Function;\n /**\n * Provide an async function to build the provider\n */\n useAsyncFactory?: Function;\n /**\n * Provide predefined value\n */\n useValue?: any;\n /**\n * Scope used by the injector to build the provider.\n */\n scope?: ProviderScope;\n /**\n * A list of resolvers which will be used to resolve missing Symbol/Class when injector invoke a Class. This property allow external DI usage.\n */\n resolvers?: DIResolver[];\n\n /**\n *\n */\n [key: string]: any;\n}\n"]}
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./DILogger"), exports);
5
- (0, tslib_1.__exportStar)(require("./DIConfigurationOptions"), exports);
6
- (0, tslib_1.__exportStar)(require("./DIResolver"), exports);
7
- (0, tslib_1.__exportStar)(require("./InjectableProperties"), exports);
8
- (0, tslib_1.__exportStar)(require("./InterceptorMethods"), exports);
9
- (0, tslib_1.__exportStar)(require("./InterceptorContext"), exports);
10
- (0, tslib_1.__exportStar)(require("./InvokeOptions"), exports);
11
- (0, tslib_1.__exportStar)(require("./IProvider"), exports);
12
- (0, tslib_1.__exportStar)(require("./OnInit"), exports);
13
- (0, tslib_1.__exportStar)(require("./OnDestroy"), exports);
14
- (0, tslib_1.__exportStar)(require("./OnInit"), exports);
15
- (0, tslib_1.__exportStar)(require("./RegistrySettings"), exports);
16
- (0, tslib_1.__exportStar)(require("./TokenProvider"), exports);
17
- (0, tslib_1.__exportStar)(require("./ResolvedInvokeOptions"), exports);
18
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAAA,0DAA2B;AAC3B,wEAAyC;AACzC,4DAA6B;AAC7B,sEAAuC;AACvC,oEAAqC;AACrC,oEAAqC;AACrC,+DAAgC;AAChC,2DAA4B;AAC5B,wDAAyB;AACzB,2DAA4B;AAC5B,wDAAyB;AACzB,kEAAmC;AACnC,+DAAgC;AAChC,uEAAwC","sourcesContent":["export * from \"./DILogger\";\nexport * from \"./DIConfigurationOptions\";\nexport * from \"./DIResolver\";\nexport * from \"./InjectableProperties\";\nexport * from \"./InterceptorMethods\";\nexport * from \"./InterceptorContext\";\nexport * from \"./InvokeOptions\";\nexport * from \"./IProvider\";\nexport * from \"./OnInit\";\nexport * from \"./OnDestroy\";\nexport * from \"./OnInit\";\nexport * from \"./RegistrySettings\";\nexport * from \"./TokenProvider\";\nexport * from \"./ResolvedInvokeOptions\";\n"]}