@tsed/di 7.83.0 → 8.0.0-alpha.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.
Files changed (118) hide show
  1. package/lib/browser/di.umd.min.js +1 -1
  2. package/lib/browser/di.umd.min.js.map +1 -1
  3. package/lib/cjs/common/constants/constants.js +6 -4
  4. package/lib/cjs/common/constants/constants.js.map +1 -1
  5. package/lib/cjs/common/decorators/autoInjectable.js +23 -3
  6. package/lib/cjs/common/decorators/autoInjectable.js.map +1 -1
  7. package/lib/cjs/common/decorators/constant.js +30 -11
  8. package/lib/cjs/common/decorators/constant.js.map +1 -1
  9. package/lib/cjs/common/decorators/inject.js +64 -73
  10. package/lib/cjs/common/decorators/inject.js.map +1 -1
  11. package/lib/cjs/common/decorators/intercept.js +41 -12
  12. package/lib/cjs/common/decorators/intercept.js.map +1 -1
  13. package/lib/cjs/common/decorators/lazyInject.js +13 -13
  14. package/lib/cjs/common/decorators/lazyInject.js.map +1 -1
  15. package/lib/cjs/common/decorators/opts.js +1 -1
  16. package/lib/cjs/common/decorators/opts.js.map +1 -1
  17. package/lib/cjs/common/decorators/useOpts.js +2 -6
  18. package/lib/cjs/common/decorators/useOpts.js.map +1 -1
  19. package/lib/cjs/common/decorators/value.js +18 -11
  20. package/lib/cjs/common/decorators/value.js.map +1 -1
  21. package/lib/cjs/common/domain/Container.js +3 -3
  22. package/lib/cjs/common/domain/Container.js.map +1 -1
  23. package/lib/cjs/common/domain/Provider.js +1 -1
  24. package/lib/cjs/common/domain/Provider.js.map +1 -1
  25. package/lib/cjs/common/index.js +0 -2
  26. package/lib/cjs/common/index.js.map +1 -1
  27. package/lib/cjs/common/registries/GlobalProviders.js +6 -2
  28. package/lib/cjs/common/registries/GlobalProviders.js.map +1 -1
  29. package/lib/cjs/common/services/DIConfiguration.js.map +1 -1
  30. package/lib/cjs/common/services/InjectorService.js +48 -165
  31. package/lib/cjs/common/services/InjectorService.js.map +1 -1
  32. package/lib/cjs/node/decorators/injectContext.js +12 -3
  33. package/lib/cjs/node/decorators/injectContext.js.map +1 -1
  34. package/lib/cjs/node/services/DITest.js +8 -3
  35. package/lib/cjs/node/services/DITest.js.map +1 -1
  36. package/lib/esm/common/constants/constants.js +5 -3
  37. package/lib/esm/common/constants/constants.js.map +1 -1
  38. package/lib/esm/common/decorators/autoInjectable.js +23 -3
  39. package/lib/esm/common/decorators/autoInjectable.js.map +1 -1
  40. package/lib/esm/common/decorators/constant.js +28 -11
  41. package/lib/esm/common/decorators/constant.js.map +1 -1
  42. package/lib/esm/common/decorators/inject.js +63 -73
  43. package/lib/esm/common/decorators/inject.js.map +1 -1
  44. package/lib/esm/common/decorators/intercept.js +40 -13
  45. package/lib/esm/common/decorators/intercept.js.map +1 -1
  46. package/lib/esm/common/decorators/lazyInject.js +14 -14
  47. package/lib/esm/common/decorators/lazyInject.js.map +1 -1
  48. package/lib/esm/common/decorators/opts.js +2 -2
  49. package/lib/esm/common/decorators/opts.js.map +1 -1
  50. package/lib/esm/common/decorators/useOpts.js +3 -7
  51. package/lib/esm/common/decorators/useOpts.js.map +1 -1
  52. package/lib/esm/common/decorators/value.js +17 -11
  53. package/lib/esm/common/decorators/value.js.map +1 -1
  54. package/lib/esm/common/domain/Container.js +3 -3
  55. package/lib/esm/common/domain/Container.js.map +1 -1
  56. package/lib/esm/common/domain/Provider.js +1 -1
  57. package/lib/esm/common/domain/Provider.js.map +1 -1
  58. package/lib/esm/common/index.js +0 -2
  59. package/lib/esm/common/index.js.map +1 -1
  60. package/lib/esm/common/registries/GlobalProviders.js +6 -2
  61. package/lib/esm/common/registries/GlobalProviders.js.map +1 -1
  62. package/lib/esm/common/services/DIConfiguration.js.map +1 -1
  63. package/lib/esm/common/services/InjectorService.js +50 -167
  64. package/lib/esm/common/services/InjectorService.js.map +1 -1
  65. package/lib/esm/node/decorators/injectContext.js +13 -4
  66. package/lib/esm/node/decorators/injectContext.js.map +1 -1
  67. package/lib/esm/node/services/DITest.js +10 -5
  68. package/lib/esm/node/services/DITest.js.map +1 -1
  69. package/lib/types/common/constants/constants.d.ts +5 -3
  70. package/lib/types/common/decorators/constant.d.ts +4 -1
  71. package/lib/types/common/decorators/inject.d.ts +17 -4
  72. package/lib/types/common/decorators/intercept.d.ts +3 -0
  73. package/lib/types/common/decorators/value.d.ts +2 -1
  74. package/lib/types/common/domain/Container.d.ts +3 -3
  75. package/lib/types/common/domain/Provider.d.ts +6 -6
  76. package/lib/types/common/index.d.ts +0 -2
  77. package/lib/types/common/interfaces/ImportTokenProviderOpts.d.ts +2 -2
  78. package/lib/types/common/interfaces/InterceptorContext.d.ts +1 -1
  79. package/lib/types/common/interfaces/InvokeOptions.d.ts +8 -2
  80. package/lib/types/common/interfaces/ProviderOpts.d.ts +1 -1
  81. package/lib/types/common/interfaces/RegistrySettings.d.ts +2 -1
  82. package/lib/types/common/interfaces/ResolvedInvokeOptions.d.ts +1 -1
  83. package/lib/types/common/interfaces/TokenProvider.d.ts +2 -6
  84. package/lib/types/common/registries/GlobalProviders.d.ts +2 -2
  85. package/lib/types/common/services/InjectorService.d.ts +30 -54
  86. package/lib/types/node/services/DITest.d.ts +1 -1
  87. package/lib/types-esm/common/constants/constants.d.ts +5 -3
  88. package/lib/types-esm/common/decorators/constant.d.ts +4 -1
  89. package/lib/types-esm/common/decorators/inject.d.ts +17 -4
  90. package/lib/types-esm/common/decorators/intercept.d.ts +3 -0
  91. package/lib/types-esm/common/decorators/value.d.ts +2 -1
  92. package/lib/types-esm/common/domain/Container.d.ts +3 -3
  93. package/lib/types-esm/common/domain/Provider.d.ts +6 -6
  94. package/lib/types-esm/common/index.d.ts +0 -2
  95. package/lib/types-esm/common/interfaces/ImportTokenProviderOpts.d.ts +2 -2
  96. package/lib/types-esm/common/interfaces/InterceptorContext.d.ts +1 -1
  97. package/lib/types-esm/common/interfaces/InvokeOptions.d.ts +8 -2
  98. package/lib/types-esm/common/interfaces/ProviderOpts.d.ts +1 -1
  99. package/lib/types-esm/common/interfaces/RegistrySettings.d.ts +2 -1
  100. package/lib/types-esm/common/interfaces/ResolvedInvokeOptions.d.ts +1 -1
  101. package/lib/types-esm/common/interfaces/TokenProvider.d.ts +2 -6
  102. package/lib/types-esm/common/registries/GlobalProviders.d.ts +2 -2
  103. package/lib/types-esm/common/services/InjectorService.d.ts +30 -54
  104. package/lib/types-esm/node/services/DITest.d.ts +1 -1
  105. package/package.json +13 -9
  106. package/vitest.config.mts +5 -5
  107. package/lib/cjs/common/errors/UndefinedTokenError.js +0 -11
  108. package/lib/cjs/common/errors/UndefinedTokenError.js.map +0 -1
  109. package/lib/cjs/common/interfaces/InjectableProperties.js +0 -3
  110. package/lib/cjs/common/interfaces/InjectableProperties.js.map +0 -1
  111. package/lib/esm/common/errors/UndefinedTokenError.js +0 -7
  112. package/lib/esm/common/errors/UndefinedTokenError.js.map +0 -1
  113. package/lib/esm/common/interfaces/InjectableProperties.js +0 -2
  114. package/lib/esm/common/interfaces/InjectableProperties.js.map +0 -1
  115. package/lib/types/common/errors/UndefinedTokenError.d.ts +0 -4
  116. package/lib/types/common/interfaces/InjectableProperties.d.ts +0 -25
  117. package/lib/types-esm/common/errors/UndefinedTokenError.d.ts +0 -4
  118. package/lib/types-esm/common/interfaces/InjectableProperties.d.ts +0 -25
@@ -1,10 +1,8 @@
1
- import { type Type } from "@tsed/core";
2
1
  import { Container } from "../domain/Container.js";
3
2
  import { LocalsContainer } from "../domain/LocalsContainer.js";
4
3
  import { Provider } from "../domain/Provider.js";
5
4
  import { ProviderScope } from "../domain/ProviderScope.js";
6
5
  import type { DILogger } from "../interfaces/DILogger.js";
7
- import { InjectablePropertyOptions, InjectablePropertyValue } from "../interfaces/InjectableProperties.js";
8
6
  import type { InvokeOptions } from "../interfaces/InvokeOptions.js";
9
7
  import type { TokenProvider } from "../interfaces/TokenProvider.js";
10
8
  import { DIConfiguration } from "./DIConfiguration.js";
@@ -37,8 +35,18 @@ export declare class InjectorService extends Container {
37
35
  constructor();
38
36
  get resolvers(): import("../index.js").DIResolver[];
39
37
  get scopes(): Record<string, ProviderScope>;
40
- static resolveAutoInjectableArgs(token: Type, locals: LocalsContainer, args: unknown[]): any[];
41
- static bind(instance: any, locals: LocalsContainer): void;
38
+ /**
39
+ * Return the current injector service.
40
+ */
41
+ static getInstance(): InjectorService;
42
+ /**
43
+ * Get the locals container initiated by DITest or .bootstrap() method.
44
+ */
45
+ static getLocals(): LocalsContainer;
46
+ /**
47
+ * Reset the locals container.
48
+ */
49
+ static unsetLocals(): void;
42
50
  /**
43
51
  * Retrieve default scope for a given provider.
44
52
  * @param provider
@@ -66,22 +74,19 @@ export declare class InjectorService extends Container {
66
74
  *
67
75
  * @param token The class or symbol registered in InjectorService.
68
76
  * @param options
69
- * @returns {boolean}
70
77
  */
71
- get<T = any>(token: TokenProvider<T>, options?: any): T | undefined;
78
+ get<T = any>(token: TokenProvider<T>, options?: Record<string, unknown>): T | undefined;
72
79
  /**
73
80
  * Return all instance of the same provider type
74
- * @param type
75
- * @param locals
76
- * @param options
77
81
  */
78
82
  getMany<Type = any>(type: any, locals?: LocalsContainer, options?: Partial<InvokeOptions>): Type[];
79
83
  /**
80
84
  * The has() method returns a boolean indicating whether an element with the specified key exists or not.
81
- * @returns {boolean}
82
- * @param token
83
85
  */
84
86
  has(token: TokenProvider): boolean;
87
+ /**
88
+ * Declare an alias for a given token.
89
+ */
85
90
  alias(token: TokenProvider, alias: TokenProvider): this;
86
91
  /**
87
92
  * Invoke the class and inject all services that required by the class constructor.
@@ -104,11 +109,14 @@ export declare class InjectorService extends Container {
104
109
  * @param options
105
110
  * @returns {Type} The class constructed.
106
111
  */
107
- invoke<Type = any>(token: TokenProvider, locals?: LocalsContainer, options?: Partial<InvokeOptions>): Type;
112
+ invoke<Type = any>(token: TokenProvider<Type>, locals?: LocalsContainer, options?: Partial<InvokeOptions>): Type;
108
113
  /**
109
114
  * Build only providers which are asynchronous.
110
115
  */
111
116
  loadAsync(): Promise<void>;
117
+ /**
118
+ * Build only providers which are synchronous.
119
+ */
112
120
  loadSync(): void;
113
121
  /**
114
122
  * Boostrap injector from container and resolve configuration.
@@ -131,68 +139,36 @@ export declare class InjectorService extends Container {
131
139
  * Load all configurations registered on providers
132
140
  */
133
141
  resolveConfiguration(): void;
134
- /**
135
- *
136
- * @param instance
137
- * @param locals
138
- * @param options
139
- */
140
- bindInjectableProperties(instance: any, locals: LocalsContainer, options: Partial<InvokeOptions>): void;
141
- /**
142
- * Create an injectable property.
143
- *
144
- * @param instance
145
- * @param {string} propertyKey
146
- * @param {any} useType
147
- * @param resolver
148
- * @param options
149
- * @param locals
150
- * @param invokeOptions
151
- */
152
- bindProperty(instance: any, { propertyKey, resolver, options }: InjectablePropertyOptions, locals: LocalsContainer, invokeOptions: Partial<InvokeOptions>): void;
153
- /**
154
- *
155
- * @param instance
156
- * @param {string} propertyKey
157
- * @param {any} useType
158
- */
159
- bindValue(instance: any, { propertyKey, expression, defaultValue }: InjectablePropertyValue): void;
160
- /**
161
- *
162
- * @param instance
163
- * @param {string} propertyKey
164
- * @param {any} useType
165
- */
166
- bindConstant(instance: any, { propertyKey, expression, defaultValue }: InjectablePropertyValue): void;
167
- /**
168
- *
169
- * @param instance
170
- * @param propertyKey
171
- * @param useType
172
- * @param options
173
- */
174
- bindInterceptor(instance: any, { propertyKey, useType, options }: InjectablePropertyOptions): void;
175
142
  lazyInvoke<T = any>(token: TokenProvider): Promise<any>;
176
143
  /**
177
144
  * Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
178
145
  * @param eventName The event name to emit at all services.
179
146
  * @param args List of the parameters to give to each service.
180
- * @returns {Promise<any[]>} A list of promises.
147
+ * @returns A list of promises.
181
148
  */
182
149
  emit(eventName: string, ...args: any[]): Promise<void>;
183
150
  /**
151
+ * Alter value attached to an event.
184
152
  * @param eventName
185
153
  * @param value
186
154
  * @param args
187
155
  */
188
156
  alter<T = any>(eventName: string, value: any, ...args: any[]): T;
189
157
  /**
158
+ * Alter value attached to an event asynchronously.
190
159
  * @param eventName
191
160
  * @param value
192
161
  * @param args
193
162
  */
194
163
  alterAsync<T = any>(eventName: string, value: any, ...args: any[]): Promise<T>;
164
+ /**
165
+ * Destroy the injector and all services.
166
+ */
195
167
  destroy(): Promise<void>;
168
+ /**
169
+ * Ensure that a provider is added to the container.
170
+ * @protected
171
+ */
196
172
  protected ensureProvider(token: TokenProvider, force: true): Provider;
197
173
  protected ensureProvider(token: TokenProvider, force: false): Provider | undefined;
198
174
  protected ensureProvider(token: TokenProvider): Provider | undefined;
@@ -25,7 +25,7 @@ export declare class DITest {
25
25
  * @param target
26
26
  * @param providers
27
27
  */
28
- static invoke<T = any>(target: TokenProvider, providers?: UseImportTokenProviderOpts[]): Promise<T>;
28
+ static invoke<T = any>(target: TokenProvider<T>, providers?: UseImportTokenProviderOpts[]): Promise<T>;
29
29
  /**
30
30
  * Return the instance from injector registry
31
31
  * @param target
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsed/di",
3
3
  "description": "DI module for Ts.ED Framework",
4
4
  "type": "commonjs",
5
- "version": "7.83.0",
5
+ "version": "8.0.0-alpha.2",
6
6
  "source": "./src/index.ts",
7
7
  "main": "lib/esm/index.js",
8
8
  "module": "lib/esm/index.js",
@@ -26,14 +26,15 @@
26
26
  "test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
27
27
  },
28
28
  "dependencies": {
29
- "tslib": "2.6.2"
29
+ "tslib": "2.6.2",
30
+ "uuid": "9.0.1"
30
31
  },
31
32
  "devDependencies": {
32
- "@tsed/barrels": "7.83.0",
33
- "@tsed/core": "7.83.0",
33
+ "@tsed/barrels": "8.0.0-alpha.2",
34
+ "@tsed/core": "8.0.0-alpha.2",
34
35
  "@tsed/logger": ">=6.7.5",
35
- "@tsed/schema": "7.83.0",
36
- "@tsed/typescript": "7.83.0",
36
+ "@tsed/schema": "8.0.0-alpha.2",
37
+ "@tsed/typescript": "8.0.0-alpha.2",
37
38
  "cross-env": "7.0.3",
38
39
  "eslint": "^8.57.0",
39
40
  "typescript": "4.9.5",
@@ -41,9 +42,9 @@
41
42
  "webpack": "^5.75.0"
42
43
  },
43
44
  "peerDependencies": {
44
- "@tsed/core": "7.83.0",
45
+ "@tsed/core": "8.0.0-alpha.2",
45
46
  "@tsed/logger": ">=6.7.5",
46
- "@tsed/schema": "7.83.0"
47
+ "@tsed/schema": "8.0.0-alpha.2"
47
48
  },
48
49
  "peerDependenciesMeta": {
49
50
  "@tsed/core": {
@@ -62,5 +63,8 @@
62
63
  },
63
64
  "homepage": "https://github.com/tsedio/tsed/tree/production/packages/di",
64
65
  "author": "Romain Lenzotti",
65
- "license": "MIT"
66
+ "license": "MIT",
67
+ "publishConfig": {
68
+ "tag": "alpha"
69
+ }
66
70
  }
package/vitest.config.mts CHANGED
@@ -10,12 +10,12 @@ export default defineConfig(
10
10
  coverage: {
11
11
  ...presets.test.coverage,
12
12
  thresholds: {
13
- statements: 98.92,
14
- branches: 97.36,
15
- functions: 99.08,
16
- lines: 98.92
13
+ statements: 98.75,
14
+ branches: 97.2,
15
+ functions: 98.67,
16
+ lines: 98.75
17
17
  }
18
18
  }
19
19
  }
20
20
  }
21
- );
21
+ );
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UndefinedTokenError = void 0;
4
- class UndefinedTokenError extends Error {
5
- constructor() {
6
- super("Given token is undefined. Have you enabled emitDecoratorMetadata in your tsconfig.json or decorated your class with @Injectable, @Service, ... decorator ?");
7
- this.name = "UNDEFINED_TOKEN_ERROR";
8
- }
9
- }
10
- exports.UndefinedTokenError = UndefinedTokenError;
11
- //# sourceMappingURL=UndefinedTokenError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UndefinedTokenError.js","sourceRoot":"","sources":["../../../../src/common/errors/UndefinedTokenError.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAoB,SAAQ,KAAK;IAG5C;QACE,KAAK,CACH,4JAA4J,CAC7J,CAAC;QALJ,SAAI,GAAG,uBAAuB,CAAC;IAM/B,CAAC;CACF;AARD,kDAQC"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=InjectableProperties.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InjectableProperties.js","sourceRoot":"","sources":["../../../../src/common/interfaces/InjectableProperties.ts"],"names":[],"mappings":""}
@@ -1,7 +0,0 @@
1
- export class UndefinedTokenError extends Error {
2
- constructor() {
3
- super("Given token is undefined. Have you enabled emitDecoratorMetadata in your tsconfig.json or decorated your class with @Injectable, @Service, ... decorator ?");
4
- this.name = "UNDEFINED_TOKEN_ERROR";
5
- }
6
- }
7
- //# sourceMappingURL=UndefinedTokenError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UndefinedTokenError.js","sourceRoot":"","sources":["../../../../src/common/errors/UndefinedTokenError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAG5C;QACE,KAAK,CACH,4JAA4J,CAC7J,CAAC;QALJ,SAAI,GAAG,uBAAuB,CAAC;IAM/B,CAAC;CACF"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=InjectableProperties.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InjectableProperties.js","sourceRoot":"","sources":["../../../../src/common/interfaces/InjectableProperties.ts"],"names":[],"mappings":""}
@@ -1,4 +0,0 @@
1
- export declare class UndefinedTokenError extends Error {
2
- name: string;
3
- constructor();
4
- }
@@ -1,25 +0,0 @@
1
- import type { InjectablePropertyType } from "../domain/InjectablePropertyType.js";
2
- import type { LocalsContainer } from "../domain/LocalsContainer.js";
3
- import type { TokenProvider } from "./TokenProvider.js";
4
- import type { InjectorService } from "../services/InjectorService.js";
5
- import type { InvokeOptions } from "./InvokeOptions.js";
6
- export interface InjectableProperty {
7
- propertyKey: string;
8
- }
9
- export interface InjectablePropertyOptions extends InjectableProperty {
10
- bindingType: InjectablePropertyType.METHOD | InjectablePropertyType.PROPERTY | InjectablePropertyType.INTERCEPTOR;
11
- propertyType: string;
12
- useType?: TokenProvider;
13
- resolver: (injector: InjectorService, locals: LocalsContainer, options: Partial<InvokeOptions> & {
14
- options: any;
15
- }) => () => any;
16
- options?: any;
17
- }
18
- export interface InjectablePropertyValue extends InjectableProperty {
19
- bindingType: InjectablePropertyType.CONSTANT | InjectablePropertyType.VALUE;
20
- expression: string;
21
- defaultValue?: any;
22
- }
23
- export interface InjectableProperties {
24
- [key: string]: InjectablePropertyOptions | InjectablePropertyValue;
25
- }
@@ -1,4 +0,0 @@
1
- export declare class UndefinedTokenError extends Error {
2
- name: string;
3
- constructor();
4
- }
@@ -1,25 +0,0 @@
1
- import type { InjectablePropertyType } from "../domain/InjectablePropertyType.js";
2
- import type { LocalsContainer } from "../domain/LocalsContainer.js";
3
- import type { TokenProvider } from "./TokenProvider.js";
4
- import type { InjectorService } from "../services/InjectorService.js";
5
- import type { InvokeOptions } from "./InvokeOptions.js";
6
- export interface InjectableProperty {
7
- propertyKey: string;
8
- }
9
- export interface InjectablePropertyOptions extends InjectableProperty {
10
- bindingType: InjectablePropertyType.METHOD | InjectablePropertyType.PROPERTY | InjectablePropertyType.INTERCEPTOR;
11
- propertyType: string;
12
- useType?: TokenProvider;
13
- resolver: (injector: InjectorService, locals: LocalsContainer, options: Partial<InvokeOptions> & {
14
- options: any;
15
- }) => () => any;
16
- options?: any;
17
- }
18
- export interface InjectablePropertyValue extends InjectableProperty {
19
- bindingType: InjectablePropertyType.CONSTANT | InjectablePropertyType.VALUE;
20
- expression: string;
21
- defaultValue?: any;
22
- }
23
- export interface InjectableProperties {
24
- [key: string]: InjectablePropertyOptions | InjectablePropertyValue;
25
- }