@tsed/di 7.0.0-beta.7 → 7.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.
Files changed (136) hide show
  1. package/coverage.json +6 -0
  2. package/jest.config.js +9 -0
  3. package/lib/cjs/decorators/controller.js.map +1 -1
  4. package/lib/cjs/decorators/inject.js +26 -1
  5. package/lib/cjs/decorators/inject.js.map +1 -1
  6. package/lib/cjs/domain/Container.js +1 -2
  7. package/lib/cjs/domain/Container.js.map +1 -1
  8. package/lib/cjs/domain/ContextLogger.js +41 -30
  9. package/lib/cjs/domain/ContextLogger.js.map +1 -1
  10. package/lib/cjs/domain/ControllerProvider.js +37 -0
  11. package/lib/cjs/domain/ControllerProvider.js.map +1 -0
  12. package/lib/cjs/domain/DIContext.js +86 -30
  13. package/lib/cjs/domain/DIContext.js.map +1 -1
  14. package/lib/cjs/domain/LocalsContainer.js +3 -46
  15. package/lib/cjs/domain/LocalsContainer.js.map +1 -1
  16. package/lib/cjs/domain/Provider.js +20 -1
  17. package/lib/cjs/domain/Provider.js.map +1 -1
  18. package/lib/cjs/errors/InjectionError.js +3 -2
  19. package/lib/cjs/errors/InjectionError.js.map +1 -1
  20. package/lib/cjs/errors/UndefinedTokenError.js +1 -1
  21. package/lib/cjs/errors/UndefinedTokenError.js.map +1 -1
  22. package/lib/cjs/index.js +8 -0
  23. package/lib/cjs/index.js.map +1 -1
  24. package/lib/cjs/interfaces/AlterRunInContext.js +3 -0
  25. package/lib/cjs/interfaces/AlterRunInContext.js.map +1 -0
  26. package/lib/cjs/interfaces/DIConfigurationOptions.js.map +1 -1
  27. package/lib/cjs/interfaces/DILoggerOptions.js +3 -0
  28. package/lib/cjs/interfaces/DILoggerOptions.js.map +1 -0
  29. package/lib/cjs/interfaces/InjectableProperties.js.map +1 -1
  30. package/lib/cjs/interfaces/InterceptorMethods.js.map +1 -1
  31. package/lib/cjs/interfaces/TokenProvider.js.map +1 -1
  32. package/lib/cjs/interfaces/TokenRoute.js +3 -0
  33. package/lib/cjs/interfaces/TokenRoute.js.map +1 -0
  34. package/lib/cjs/registries/GlobalProviders.js +7 -12
  35. package/lib/cjs/registries/GlobalProviders.js.map +1 -1
  36. package/lib/cjs/registries/ProviderRegistry.js +1 -1
  37. package/lib/cjs/registries/ProviderRegistry.js.map +1 -1
  38. package/lib/cjs/services/DIConfiguration.js +56 -43
  39. package/lib/cjs/services/DIConfiguration.js.map +1 -1
  40. package/lib/cjs/services/DITest.js +13 -6
  41. package/lib/cjs/services/DITest.js.map +1 -1
  42. package/lib/cjs/services/InjectorService.js +94 -92
  43. package/lib/cjs/services/InjectorService.js.map +1 -1
  44. package/lib/cjs/utils/asyncHookContext.js +42 -0
  45. package/lib/cjs/utils/asyncHookContext.js.map +1 -0
  46. package/lib/cjs/utils/getConfiguration.js +13 -10
  47. package/lib/cjs/utils/getConfiguration.js.map +1 -1
  48. package/lib/cjs/utils/resolveControllers.js +47 -0
  49. package/lib/cjs/utils/resolveControllers.js.map +1 -0
  50. package/lib/cjs/utils/setLoggerConfiguration.js +11 -0
  51. package/lib/cjs/utils/setLoggerConfiguration.js.map +1 -0
  52. package/lib/cjs/utils/setLoggerFormat.js +33 -0
  53. package/lib/cjs/utils/setLoggerFormat.js.map +1 -0
  54. package/lib/cjs/utils/setLoggerLevel.js +1 -2
  55. package/lib/cjs/utils/setLoggerLevel.js.map +1 -1
  56. package/lib/esm/decorators/controller.js.map +1 -1
  57. package/lib/esm/decorators/inject.js +24 -0
  58. package/lib/esm/decorators/inject.js.map +1 -1
  59. package/lib/esm/domain/Container.js +1 -2
  60. package/lib/esm/domain/Container.js.map +1 -1
  61. package/lib/esm/domain/ContextLogger.js +41 -30
  62. package/lib/esm/domain/ContextLogger.js.map +1 -1
  63. package/lib/esm/domain/ControllerProvider.js +33 -0
  64. package/lib/esm/domain/ControllerProvider.js.map +1 -0
  65. package/lib/esm/domain/DIContext.js +86 -30
  66. package/lib/esm/domain/DIContext.js.map +1 -1
  67. package/lib/esm/domain/LocalsContainer.js +3 -46
  68. package/lib/esm/domain/LocalsContainer.js.map +1 -1
  69. package/lib/esm/domain/Provider.js +21 -2
  70. package/lib/esm/domain/Provider.js.map +1 -1
  71. package/lib/esm/errors/InjectionError.js +3 -2
  72. package/lib/esm/errors/InjectionError.js.map +1 -1
  73. package/lib/esm/errors/UndefinedTokenError.js +1 -1
  74. package/lib/esm/errors/UndefinedTokenError.js.map +1 -1
  75. package/lib/esm/index.js +8 -0
  76. package/lib/esm/index.js.map +1 -1
  77. package/lib/esm/interfaces/AlterRunInContext.js +2 -0
  78. package/lib/esm/interfaces/AlterRunInContext.js.map +1 -0
  79. package/lib/esm/interfaces/DIConfigurationOptions.js.map +1 -1
  80. package/lib/esm/interfaces/DILoggerOptions.js +2 -0
  81. package/lib/esm/interfaces/DILoggerOptions.js.map +1 -0
  82. package/lib/esm/interfaces/InjectableProperties.js.map +1 -1
  83. package/lib/esm/interfaces/InterceptorMethods.js.map +1 -1
  84. package/lib/esm/interfaces/TokenProvider.js.map +1 -1
  85. package/lib/esm/interfaces/TokenRoute.js +2 -0
  86. package/lib/esm/interfaces/TokenRoute.js.map +1 -0
  87. package/lib/esm/registries/GlobalProviders.js +7 -12
  88. package/lib/esm/registries/GlobalProviders.js.map +1 -1
  89. package/lib/esm/registries/ProviderRegistry.js +1 -1
  90. package/lib/esm/registries/ProviderRegistry.js.map +1 -1
  91. package/lib/esm/services/DIConfiguration.js +57 -44
  92. package/lib/esm/services/DIConfiguration.js.map +1 -1
  93. package/lib/esm/services/DITest.js +13 -6
  94. package/lib/esm/services/DITest.js.map +1 -1
  95. package/lib/esm/services/InjectorService.js +96 -94
  96. package/lib/esm/services/InjectorService.js.map +1 -1
  97. package/lib/esm/utils/asyncHookContext.js +33 -0
  98. package/lib/esm/utils/asyncHookContext.js.map +1 -0
  99. package/lib/esm/utils/getConfiguration.js +12 -10
  100. package/lib/esm/utils/getConfiguration.js.map +1 -1
  101. package/lib/esm/utils/resolveControllers.js +42 -0
  102. package/lib/esm/utils/resolveControllers.js.map +1 -0
  103. package/lib/esm/utils/setLoggerConfiguration.js +7 -0
  104. package/lib/esm/utils/setLoggerConfiguration.js.map +1 -0
  105. package/lib/esm/utils/setLoggerFormat.js +29 -0
  106. package/lib/esm/utils/setLoggerFormat.js.map +1 -0
  107. package/lib/esm/utils/setLoggerLevel.js +1 -2
  108. package/lib/esm/utils/setLoggerLevel.js.map +1 -1
  109. package/lib/types/decorators/controller.d.ts +0 -1
  110. package/lib/types/decorators/inject.d.ts +15 -0
  111. package/lib/types/domain/ContextLogger.d.ts +13 -18
  112. package/lib/types/domain/ControllerProvider.d.ts +17 -0
  113. package/lib/types/domain/DIContext.d.ts +23 -29
  114. package/lib/types/domain/LocalsContainer.d.ts +3 -22
  115. package/lib/types/domain/Provider.d.ts +2 -1
  116. package/lib/types/index.d.ts +8 -0
  117. package/lib/types/interfaces/AlterRunInContext.d.ts +3 -0
  118. package/lib/types/interfaces/DIConfigurationOptions.d.ts +5 -2
  119. package/lib/types/interfaces/DILoggerOptions.d.ts +44 -0
  120. package/lib/types/interfaces/InjectableProperties.d.ts +2 -1
  121. package/lib/types/interfaces/InterceptorMethods.d.ts +1 -1
  122. package/lib/types/interfaces/TokenProvider.d.ts +1 -1
  123. package/lib/types/interfaces/TokenRoute.d.ts +5 -0
  124. package/lib/types/registries/GlobalProviders.d.ts +6 -5
  125. package/lib/types/registries/ProviderRegistry.d.ts +2 -1
  126. package/lib/types/services/DIConfiguration.d.ts +19 -11
  127. package/lib/types/services/DITest.d.ts +2 -0
  128. package/lib/types/services/InjectorService.d.ts +20 -28
  129. package/lib/types/utils/asyncHookContext.d.ts +14 -0
  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/setLoggerConfiguration.d.ts +2 -0
  133. package/lib/types/utils/setLoggerFormat.d.ts +6 -0
  134. package/lib/types/utils/setLoggerLevel.d.ts +1 -1
  135. package/package.json +15 -11
  136. package/readme.md +3 -2
@@ -1,13 +1,12 @@
1
1
  import { Container } from "../domain/Container";
2
2
  import { LocalsContainer } from "../domain/LocalsContainer";
3
3
  import { Provider } from "../domain/Provider";
4
- import { DIConfiguration } from "./DIConfiguration";
5
4
  import { ProviderScope } from "../domain/ProviderScope";
6
5
  import { DILogger } from "../interfaces/DILogger";
7
- import { TokenProvider } from "../interfaces/TokenProvider";
8
- import { InvokeOptions } from "../interfaces/InvokeOptions";
9
6
  import { InjectablePropertyOptions, InjectablePropertyValue } from "../interfaces/InjectableProperties";
10
- import { DIContext } from "../domain/DIContext";
7
+ import { InvokeOptions } from "../interfaces/InvokeOptions";
8
+ import { TokenProvider } from "../interfaces/TokenProvider";
9
+ import { DIConfiguration } from "./DIConfiguration";
11
10
  /**
12
11
  * This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.
13
12
  *
@@ -21,7 +20,7 @@ import { DIContext } from "../domain/DIContext";
21
20
  * import MyService2 from "./services/service2";
22
21
  * import MyService3 from "./services/service3";
23
22
  *
24
- * // When all services is imported you can load InjectorService.
23
+ * // When all services are imported, you can load InjectorService.
25
24
  * const injector = new InjectorService()
26
25
  *
27
26
  * await injector.load();
@@ -31,16 +30,12 @@ import { DIContext } from "../domain/DIContext";
31
30
  */
32
31
  export declare class InjectorService extends Container {
33
32
  #private;
34
- settings: TsED.Configuration & DIConfiguration;
33
+ settings: DIConfiguration;
35
34
  logger: DILogger;
36
35
  private resolvedConfiguration;
37
36
  constructor();
38
37
  get resolvers(): import("..").DIResolver[];
39
- get scopes(): {
40
- [key: string]: ProviderScope;
41
- } & {
42
- [key: string]: ProviderScope;
43
- };
38
+ get scopes(): Record<string, ProviderScope>;
44
39
  /**
45
40
  * Retrieve default scope for a given provider.
46
41
  * @param provider
@@ -70,7 +65,7 @@ export declare class InjectorService extends Container {
70
65
  * @param options
71
66
  * @returns {boolean}
72
67
  */
73
- get<T = any>(token: TokenProvider, options?: any): T | undefined;
68
+ get<T = any>(token: TokenProvider<T>, options?: any): T | undefined;
74
69
  /**
75
70
  * Return all instance of the same provider type
76
71
  * @param type
@@ -103,25 +98,29 @@ export declare class InjectorService extends Container {
103
98
  * @param options
104
99
  * @returns {T} The class constructed.
105
100
  */
106
- invoke<T>(token: TokenProvider, locals?: Map<TokenProvider, any>, options?: Partial<InvokeOptions<T>>): T;
101
+ invoke<T = any>(token: TokenProvider, locals?: LocalsContainer, options?: Partial<InvokeOptions<T>>): T;
107
102
  /**
108
103
  * Build only providers which are asynchronous.
109
104
  */
110
- loadAsync(locals?: LocalsContainer): Promise<LocalsContainer<any>>;
111
- loadSync(locals?: LocalsContainer): LocalsContainer<any>;
105
+ loadAsync(): Promise<void>;
106
+ loadSync(): void;
112
107
  /**
113
108
  * Boostrap injector from container and resolve configuration.
114
109
  *
115
110
  * @param container
116
111
  */
117
112
  bootstrap(container?: Container): this;
113
+ /**
114
+ * Load injector from a given module
115
+ * @param rootModule
116
+ */
117
+ loadModule(rootModule: TokenProvider): Promise<void>;
118
118
  /**
119
119
  * Build all providers from given container (or GlobalProviders) and emit `$onInit` event.
120
120
  *
121
121
  * @param container
122
- * @param rootModule
123
122
  */
124
- load(container?: Container, rootModule?: TokenProvider): Promise<LocalsContainer<any>>;
123
+ load(container?: Container): Promise<void>;
125
124
  /**
126
125
  * Load all configurations registered on providers
127
126
  */
@@ -132,9 +131,8 @@ export declare class InjectorService extends Container {
132
131
  * @param locals
133
132
  * @param options
134
133
  */
135
- bindInjectableProperties(instance: any, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions>): void;
134
+ bindInjectableProperties(instance: any, locals: LocalsContainer, options: Partial<InvokeOptions>): void;
136
135
  /**
137
- *
138
136
  * @param instance
139
137
  * @param {string} propertyKey
140
138
  */
@@ -150,7 +148,7 @@ export declare class InjectorService extends Container {
150
148
  * @param locals
151
149
  * @param invokeOptions
152
150
  */
153
- bindProperty(instance: any, { propertyKey, resolver, options }: InjectablePropertyOptions, locals: Map<TokenProvider, any>, invokeOptions: Partial<InvokeOptions>): void;
151
+ bindProperty(instance: any, { propertyKey, resolver, options }: InjectablePropertyOptions, locals: LocalsContainer, invokeOptions: Partial<InvokeOptions>): void;
154
152
  /**
155
153
  *
156
154
  * @param instance
@@ -173,18 +171,11 @@ export declare class InjectorService extends Container {
173
171
  * @param options
174
172
  */
175
173
  bindInterceptor(instance: any, { propertyKey, useType, options }: InjectablePropertyOptions): void;
176
- /**
177
- * Allow handler hack for AsyncHookContext plugin.
178
- * @param ctx
179
- * @param cb
180
- * @protected
181
- */
182
- runInContext(ctx: DIContext, cb: any): any;
183
174
  lazyInvoke<T = any>(token: TokenProvider): Promise<any>;
184
175
  /**
185
176
  * Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
186
177
  * @param eventName The event name to emit at all services.
187
- * @param args List of the parameters to give to each services.
178
+ * @param args List of the parameters to give to each service.
188
179
  * @returns {Promise<any[]>} A list of promises.
189
180
  */
190
181
  emit(eventName: string, ...args: any[]): Promise<void>;
@@ -228,4 +219,5 @@ export declare class InjectorService extends Container {
228
219
  * @param options
229
220
  */
230
221
  private mapInvokeOptions;
222
+ private registerHooks;
231
223
  }
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ import { AsyncLocalStorage } from "async_hooks";
3
+ import type { DIContext } from "../domain/DIContext";
4
+ import type { InjectorService } from "../services/InjectorService";
5
+ export declare function getAsyncStore(): AsyncLocalStorage<{
6
+ current: DIContext | undefined;
7
+ }>;
8
+ export declare function useContextRef(): {
9
+ current: DIContext | undefined;
10
+ } | undefined;
11
+ export declare function getContext<Context = DIContext>(): Context | undefined;
12
+ export declare function runInContext(ctx: DIContext | undefined, cb: any, injector?: InjectorService): Promise<any>;
13
+ export declare function setContext(ctx: DIContext): void;
14
+ export declare function bindContext(cb: any): any;
@@ -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,2 @@
1
+ import type { InjectorService } from "../services/InjectorService";
2
+ export declare function setLoggerConfiguration(injector: InjectorService): void;
@@ -0,0 +1,6 @@
1
+ import type { InjectorService } from "../services/InjectorService";
2
+ /**
3
+ * @ignore
4
+ * @param injector
5
+ */
6
+ export declare function setLoggerFormat(injector: InjectorService): void;
@@ -1,4 +1,4 @@
1
- import { InjectorService } from "../services/InjectorService";
1
+ import type { InjectorService } from "../services/InjectorService";
2
2
  /**
3
3
  * @ignore
4
4
  * @param injector
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/di",
3
- "version": "7.0.0-beta.7",
3
+ "version": "7.0.0-rc.1",
4
4
  "description": "DI module for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -17,20 +17,21 @@
17
17
  "build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
18
18
  "build:cjs": "tsc --build tsconfig.compile.json",
19
19
  "build:esm": "tsc --build tsconfig.compile.esm.json",
20
- "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\""
20
+ "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\"",
21
+ "test": "cross-env NODE_ENV=test yarn jest --max-workers=2"
21
22
  },
22
23
  "dependencies": {
23
- "tslib": "2.3.1"
24
+ "tslib": "2.4.0"
24
25
  },
25
26
  "devDependencies": {
26
- "@tsed/core": "7.0.0-beta.7",
27
- "@tsed/logger": ">=6.1.1",
28
- "@tsed/schema": "7.0.0-beta.7"
27
+ "@tsed/core": "7.0.0-rc.1",
28
+ "@tsed/logger": ">=6.2.0",
29
+ "@tsed/schema": "7.0.0-rc.1"
29
30
  },
30
31
  "peerDependencies": {
31
- "@tsed/core": "^7.0.0-beta.7",
32
- "@tsed/logger": ">=6.1.1",
33
- "@tsed/schema": "^7.0.0-beta.7"
32
+ "@tsed/core": "^7.0.0-rc.1",
33
+ "@tsed/logger": ">=6.2.0",
34
+ "@tsed/schema": "^7.0.0-rc.1"
34
35
  },
35
36
  "peerDependenciesMeta": {
36
37
  "@tsed/core": {
@@ -47,7 +48,10 @@
47
48
  "bugs": {
48
49
  "url": "https://github.com/tsedio/tsed/issues"
49
50
  },
50
- "homepage": "https://github.com/tsedio/tsed/tree/production/packages/di",
51
+ "homepage": "https://github.com/tsedio/tsed/tree/rc/packages/di",
51
52
  "author": "Romain Lenzotti",
52
- "license": "MIT"
53
+ "license": "MIT",
54
+ "publishConfig": {
55
+ "tag": "rc"
56
+ }
53
57
  }
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
 
@@ -168,7 +169,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
168
169
 
169
170
  The MIT License (MIT)
170
171
 
171
- Copyright (c) 2016 - 2018 Romain Lenzotti
172
+ Copyright (c) 2016 - 2022 Romain Lenzotti
172
173
 
173
174
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
174
175