@tsed/di 6.114.18 → 6.116.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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DIContext = void 0;
4
4
  const ContextLogger_1 = require("./ContextLogger");
5
5
  const LocalsContainer_1 = require("./LocalsContainer");
6
+ const runInContext_1 = require("../utils/runInContext");
6
7
  class DIContext extends Map {
7
8
  /**
8
9
  * Request id generated by @@contextMiddleware@@.
@@ -68,6 +69,12 @@ class DIContext extends Map {
68
69
  async emit(eventName, ...args) {
69
70
  return this.injector?.emit(eventName, ...args);
70
71
  }
72
+ async runInContext(next) {
73
+ return (0, runInContext_1.runInContext)(this, async () => {
74
+ next = (await this.injector?.alterAsync("$alterRunInContext", next, this)) || next;
75
+ return next();
76
+ });
77
+ }
71
78
  }
72
79
  exports.DIContext = DIContext;
73
80
  //# sourceMappingURL=DIContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":";;;AAEA,mDAAoE;AACpE,uDAAkD;AAkBlD,MAAa,SAAU,SAAQ,GAAa;IAE1C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACM,EAAE,CAAS;IACpB;;OAEG;IACM,SAAS,GAAS,IAAI,IAAI,EAAE,CAAC;IACtC;;OAEG;IACI,SAAS,GAAG,IAAI,iCAAe,EAAO,CAAC;IAC9C;;OAEG;IACM,MAAM,CAAgB;IAC/B;;OAEG;IACM,QAAQ,CAAkB;IAEnC,YAAY,EAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,EAAmB;QACzE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QAEb,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAa,CAAC,MAAM,EAAE;YACtC,GAAG,OAAO;YACV,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,EAAE;YACF,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAEtB,aAAa;QACb,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,GAAG,IAAW;QAC1C,OAAO,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;CACF;AAzED,8BAyEC","sourcesContent":["import type {Env} from \"@tsed/core\";\nimport {InjectorService} from \"../services/InjectorService\";\nimport {ContextLogger, ContextLoggerOptions} from \"./ContextLogger\";\nimport {LocalsContainer} from \"./LocalsContainer\";\n\nexport interface ContextMethods extends Map<any, any> {\n readonly id: string;\n readonly logger: ContextLogger;\n readonly injector: InjectorService;\n readonly container: LocalsContainer;\n readonly env: Env;\n\n destroy(): any;\n}\n\nexport interface DIContextOptions extends Omit<ContextLoggerOptions, \"dateStart\"> {\n id: string;\n logger: any;\n injector?: InjectorService;\n}\n\nexport class DIContext extends Map<any, any> implements ContextMethods {\n [x: string]: any;\n /**\n * Request id generated by @@contextMiddleware@@.\n *\n * ::: tip\n * By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, \"\"))`.\n * Dash are removed to simplify tracking logs in Kibana\n * :::\n *\n * ::: tip\n * Request id can by customized by changing the server configuration.\n *\n * ```typescript\n * @Configuration({\n * logger: {\n * reqIdBuilder: createUniqId // give your own id generator function\n * }\n * })\n * class Server {\n *\n * }\n * ```\n * :::\n *\n */\n readonly id: string;\n /**\n * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.\n */\n readonly dateStart: Date = new Date();\n /**\n * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`\n */\n public container = new LocalsContainer<any>();\n /**\n * Logger attached to the context request.\n */\n readonly logger: ContextLogger;\n /**\n *\n */\n readonly injector: InjectorService;\n\n constructor({id, injector, logger, ignoreLog, ...options}: DIContextOptions) {\n super();\n this.id = id;\n\n injector && (this.injector = injector);\n\n this.logger = new ContextLogger(logger, {\n ...options,\n dateStart: this.dateStart,\n id,\n ignoreLog\n });\n }\n\n get env() {\n return this.injector.settings.get(\"env\");\n }\n\n async destroy() {\n await this.container.destroy();\n this.logger.destroy();\n\n // @ts-ignore\n delete this.container;\n }\n\n async emit(eventName: string, ...args: any[]) {\n return this.injector?.emit(eventName, ...args);\n }\n}\n\nexport type BaseContext = DIContext & TsED.Context;\n"]}
1
+ {"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":";;;AAEA,mDAAoE;AACpE,uDAAkD;AAClD,wDAAmD;AAkBnD,MAAa,SAAU,SAAQ,GAAa;IAE1C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACM,EAAE,CAAS;IACpB;;OAEG;IACM,SAAS,GAAS,IAAI,IAAI,EAAE,CAAC;IACtC;;OAEG;IACI,SAAS,GAAG,IAAI,iCAAe,EAAO,CAAC;IAC9C;;OAEG;IACM,MAAM,CAAgB;IAC/B;;OAEG;IACM,QAAQ,CAAkB;IAEnC,YAAY,EAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,EAAmB;QACzE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QAEb,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAa,CAAC,MAAM,EAAE;YACtC,GAAG,OAAO;YACV,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,EAAE;YACF,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAEtB,aAAa;QACb,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,GAAG,IAAW;QAC1C,OAAO,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,IAAc;QAC/B,OAAO,IAAA,2BAAY,EAAC,IAAI,EAAE,KAAK,IAAI,EAAE;YACnC,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,oBAAoB,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC;YACnF,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAhFD,8BAgFC","sourcesContent":["import type {Env} from \"@tsed/core\";\nimport {InjectorService} from \"../services/InjectorService\";\nimport {ContextLogger, ContextLoggerOptions} from \"./ContextLogger\";\nimport {LocalsContainer} from \"./LocalsContainer\";\nimport {runInContext} from \"../utils/runInContext\";\n\nexport interface ContextMethods extends Map<any, any> {\n readonly id: string;\n readonly logger: ContextLogger;\n readonly injector: InjectorService;\n readonly container: LocalsContainer;\n readonly env: Env;\n\n destroy(): any;\n}\n\nexport interface DIContextOptions extends Omit<ContextLoggerOptions, \"dateStart\"> {\n id: string;\n logger: any;\n injector?: InjectorService;\n}\n\nexport class DIContext extends Map<any, any> implements ContextMethods {\n [x: string]: any;\n /**\n * Request id generated by @@contextMiddleware@@.\n *\n * ::: tip\n * By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, \"\"))`.\n * Dash are removed to simplify tracking logs in Kibana\n * :::\n *\n * ::: tip\n * Request id can by customized by changing the server configuration.\n *\n * ```typescript\n * @Configuration({\n * logger: {\n * reqIdBuilder: createUniqId // give your own id generator function\n * }\n * })\n * class Server {\n *\n * }\n * ```\n * :::\n *\n */\n readonly id: string;\n /**\n * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.\n */\n readonly dateStart: Date = new Date();\n /**\n * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`\n */\n public container = new LocalsContainer<any>();\n /**\n * Logger attached to the context request.\n */\n readonly logger: ContextLogger;\n /**\n *\n */\n readonly injector: InjectorService;\n\n constructor({id, injector, logger, ignoreLog, ...options}: DIContextOptions) {\n super();\n this.id = id;\n\n injector && (this.injector = injector);\n\n this.logger = new ContextLogger(logger, {\n ...options,\n dateStart: this.dateStart,\n id,\n ignoreLog\n });\n }\n\n get env() {\n return this.injector.settings.get(\"env\");\n }\n\n async destroy() {\n await this.container.destroy();\n this.logger.destroy();\n\n // @ts-ignore\n delete this.container;\n }\n\n async emit(eventName: string, ...args: any[]) {\n return this.injector?.emit(eventName, ...args);\n }\n\n async runInContext(next: Function) {\n return runInContext(this, async () => {\n next = (await this.injector?.alterAsync(\"$alterRunInContext\", next, this)) || next;\n return next();\n });\n }\n}\n\nexport type BaseContext = DIContext & TsED.Context;\n"]}
package/lib/cjs/index.js CHANGED
@@ -30,6 +30,7 @@ tslib_1.__exportStar(require("./domain/ProviderScope"), exports);
30
30
  tslib_1.__exportStar(require("./domain/ProviderType"), exports);
31
31
  tslib_1.__exportStar(require("./errors/InjectionError"), exports);
32
32
  tslib_1.__exportStar(require("./errors/UndefinedTokenError"), exports);
33
+ tslib_1.__exportStar(require("./interfaces/AlterRunInContext"), exports);
33
34
  tslib_1.__exportStar(require("./interfaces/DIConfigurationOptions"), exports);
34
35
  tslib_1.__exportStar(require("./interfaces/DILogger"), exports);
35
36
  tslib_1.__exportStar(require("./interfaces/DILoggerOptions"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gEAAsC;AACtC,qEAA2C;AAC3C,gEAAsC;AACtC,kEAAwC;AACxC,8DAAoC;AACpC,kEAAwC;AACxC,iEAAuC;AACvC,mEAAyC;AACzC,kEAAwC;AACxC,8DAAoC;AACpC,4DAAkC;AAClC,wEAA8C;AAC9C,6DAAmC;AACnC,+DAAqC;AACrC,+DAAqC;AACrC,6DAAmC;AACnC,6DAAmC;AACnC,iEAAuC;AACvC,6DAAmC;AACnC,0EAAgD;AAChD,mEAAyC;AACzC,4DAAkC;AAClC,iEAAuC;AACvC,gEAAsC;AACtC,kEAAwC;AACxC,uEAA6C;AAC7C,8EAAoD;AACpD,gEAAsC;AACtC,uEAA6C;AAC7C,kEAAwC;AACxC,4EAAkD;AAClD,0EAAgD;AAChD,0EAAgD;AAChD,qEAA2C;AAC3C,iEAAuC;AACvC,8DAAoC;AACpC,oEAA0C;AAC1C,wEAA8C;AAC9C,6EAAmD;AACnD,qEAA2C;AAC3C,kEAAwC;AACxC,uEAA6C;AAC7C,wEAA8C;AAC9C,qEAA2C;AAC3C,8DAAoC;AACpC,4DAAkC;AAClC,qEAA2C;AAC3C,yDAA+B;AAC/B,kEAAwC;AACxC,mEAAyC;AACzC,qEAA2C;AAC3C,+DAAqC;AACrC,yEAA+C;AAC/C,kEAAwC;AACxC,iEAAuC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/configuration\";\nexport * from \"./decorators/constant\";\nexport * from \"./decorators/controller\";\nexport * from \"./decorators/inject\";\nexport * from \"./decorators/injectable\";\nexport * from \"./decorators/intercept\";\nexport * from \"./decorators/interceptor\";\nexport * from \"./decorators/lazyInject\";\nexport * from \"./decorators/module\";\nexport * from \"./decorators/opts\";\nexport * from \"./decorators/overrideProvider\";\nexport * from \"./decorators/scope\";\nexport * from \"./decorators/service\";\nexport * from \"./decorators/useOpts\";\nexport * from \"./decorators/value\";\nexport * from \"./domain/Container\";\nexport * from \"./domain/ContextLogger\";\nexport * from \"./domain/DIContext\";\nexport * from \"./domain/InjectablePropertyType\";\nexport * from \"./domain/LocalsContainer\";\nexport * from \"./domain/Provider\";\nexport * from \"./domain/ProviderScope\";\nexport * from \"./domain/ProviderType\";\nexport * from \"./errors/InjectionError\";\nexport * from \"./errors/UndefinedTokenError\";\nexport * from \"./interfaces/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\nexport * from \"./interfaces/DILoggerOptions\";\nexport * from \"./interfaces/DIResolver\";\nexport * from \"./interfaces/InjectableProperties\";\nexport * from \"./interfaces/InterceptorContext\";\nexport * from \"./interfaces/InterceptorMethods\";\nexport * from \"./interfaces/InvokeOptions\";\nexport * from \"./interfaces/OnDestroy\";\nexport * from \"./interfaces/OnInit\";\nexport * from \"./interfaces/ProviderOpts\";\nexport * from \"./interfaces/RegistrySettings\";\nexport * from \"./interfaces/ResolvedInvokeOptions\";\nexport * from \"./interfaces/TokenProvider\";\nexport * from \"./interfaces/TokenRoute\";\nexport * from \"./registries/GlobalProviders\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DITest\";\nexport * from \"./services/InjectorService\";\nexport * from \"./utils/colors\";\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/resolveControllers\";\nexport * from \"./utils/runInContext\";\nexport * from \"./utils/setLoggerConfiguration\";\nexport * from \"./utils/setLoggerFormat\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gEAAsC;AACtC,qEAA2C;AAC3C,gEAAsC;AACtC,kEAAwC;AACxC,8DAAoC;AACpC,kEAAwC;AACxC,iEAAuC;AACvC,mEAAyC;AACzC,kEAAwC;AACxC,8DAAoC;AACpC,4DAAkC;AAClC,wEAA8C;AAC9C,6DAAmC;AACnC,+DAAqC;AACrC,+DAAqC;AACrC,6DAAmC;AACnC,6DAAmC;AACnC,iEAAuC;AACvC,6DAAmC;AACnC,0EAAgD;AAChD,mEAAyC;AACzC,4DAAkC;AAClC,iEAAuC;AACvC,gEAAsC;AACtC,kEAAwC;AACxC,uEAA6C;AAC7C,yEAA+C;AAC/C,8EAAoD;AACpD,gEAAsC;AACtC,uEAA6C;AAC7C,kEAAwC;AACxC,4EAAkD;AAClD,0EAAgD;AAChD,0EAAgD;AAChD,qEAA2C;AAC3C,iEAAuC;AACvC,8DAAoC;AACpC,oEAA0C;AAC1C,wEAA8C;AAC9C,6EAAmD;AACnD,qEAA2C;AAC3C,kEAAwC;AACxC,uEAA6C;AAC7C,wEAA8C;AAC9C,qEAA2C;AAC3C,8DAAoC;AACpC,4DAAkC;AAClC,qEAA2C;AAC3C,yDAA+B;AAC/B,kEAAwC;AACxC,mEAAyC;AACzC,qEAA2C;AAC3C,+DAAqC;AACrC,yEAA+C;AAC/C,kEAAwC;AACxC,iEAAuC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/configuration\";\nexport * from \"./decorators/constant\";\nexport * from \"./decorators/controller\";\nexport * from \"./decorators/inject\";\nexport * from \"./decorators/injectable\";\nexport * from \"./decorators/intercept\";\nexport * from \"./decorators/interceptor\";\nexport * from \"./decorators/lazyInject\";\nexport * from \"./decorators/module\";\nexport * from \"./decorators/opts\";\nexport * from \"./decorators/overrideProvider\";\nexport * from \"./decorators/scope\";\nexport * from \"./decorators/service\";\nexport * from \"./decorators/useOpts\";\nexport * from \"./decorators/value\";\nexport * from \"./domain/Container\";\nexport * from \"./domain/ContextLogger\";\nexport * from \"./domain/DIContext\";\nexport * from \"./domain/InjectablePropertyType\";\nexport * from \"./domain/LocalsContainer\";\nexport * from \"./domain/Provider\";\nexport * from \"./domain/ProviderScope\";\nexport * from \"./domain/ProviderType\";\nexport * from \"./errors/InjectionError\";\nexport * from \"./errors/UndefinedTokenError\";\nexport * from \"./interfaces/AlterRunInContext\";\nexport * from \"./interfaces/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\nexport * from \"./interfaces/DILoggerOptions\";\nexport * from \"./interfaces/DIResolver\";\nexport * from \"./interfaces/InjectableProperties\";\nexport * from \"./interfaces/InterceptorContext\";\nexport * from \"./interfaces/InterceptorMethods\";\nexport * from \"./interfaces/InvokeOptions\";\nexport * from \"./interfaces/OnDestroy\";\nexport * from \"./interfaces/OnInit\";\nexport * from \"./interfaces/ProviderOpts\";\nexport * from \"./interfaces/RegistrySettings\";\nexport * from \"./interfaces/ResolvedInvokeOptions\";\nexport * from \"./interfaces/TokenProvider\";\nexport * from \"./interfaces/TokenRoute\";\nexport * from \"./registries/GlobalProviders\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DITest\";\nexport * from \"./services/InjectorService\";\nexport * from \"./utils/colors\";\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/resolveControllers\";\nexport * from \"./utils/runInContext\";\nexport * from \"./utils/setLoggerConfiguration\";\nexport * from \"./utils/setLoggerFormat\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=AlterRunInContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlterRunInContext.js","sourceRoot":"","sources":["../../../src/interfaces/AlterRunInContext.ts"],"names":[],"mappings":"","sourcesContent":["import {DIContext} from \"../domain/DIContext\";\n\nexport interface AlterRunInContext {\n $alterRunInContext(next: (...args: unknown[]) => unknown, ctx: DIContext): () => unknown | Promise<() => unknown>;\n}\n"]}
@@ -8,17 +8,17 @@ const constants_1 = require("../constants/constants");
8
8
  const configuration_1 = require("../decorators/configuration");
9
9
  const injectable_1 = require("../decorators/injectable");
10
10
  const Container_1 = require("../domain/Container");
11
+ const InjectablePropertyType_1 = require("../domain/InjectablePropertyType");
11
12
  const LocalsContainer_1 = require("../domain/LocalsContainer");
12
13
  const Provider_1 = require("../domain/Provider");
14
+ const ProviderScope_1 = require("../domain/ProviderScope");
13
15
  const InjectionError_1 = require("../errors/InjectionError");
14
16
  const UndefinedTokenError_1 = require("../errors/UndefinedTokenError");
15
17
  const GlobalProviders_1 = require("../registries/GlobalProviders");
16
18
  const createContainer_1 = require("../utils/createContainer");
17
- const DIConfiguration_1 = require("./DIConfiguration");
18
- const ProviderScope_1 = require("../domain/ProviderScope");
19
- const InjectablePropertyType_1 = require("../domain/InjectablePropertyType");
20
- const runInContext_1 = require("../utils/runInContext");
21
19
  const resolveControllers_1 = require("../utils/resolveControllers");
20
+ const runInContext_1 = require("../utils/runInContext");
21
+ const DIConfiguration_1 = require("./DIConfiguration");
22
22
  /**
23
23
  * This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.
24
24
  *
@@ -158,7 +158,7 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
158
158
  */
159
159
  invoke(token, locals = new LocalsContainer_1.LocalsContainer(), options = {}) {
160
160
  const provider = this.ensureProvider(token);
161
- let instance;
161
+ let instance = undefined;
162
162
  !locals.has(configuration_1.Configuration) && locals.set(configuration_1.Configuration, this.settings);
163
163
  if (locals.has(token)) {
164
164
  return locals.get(token);
@@ -175,54 +175,46 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
175
175
  }
176
176
  switch (this.scopeOf(provider)) {
177
177
  case ProviderScope_1.ProviderScope.SINGLETON:
178
- if (!this.has(token)) {
179
- this.#cache.set(token, this.resolve(token, locals, options));
180
- if (provider.isAsync()) {
181
- this.#cache.get(token).then((instance) => {
182
- this.#cache.set(token, instance);
183
- });
184
- }
178
+ if (this.has(token)) {
179
+ return this.get(token);
180
+ }
181
+ instance = this.resolve(token, locals, options);
182
+ if (!provider.isAsync()) {
183
+ this.#cache.set(token, instance);
184
+ return instance;
185
185
  }
186
- instance = this.get(token);
187
- break;
186
+ // store promise to lock token in cache
187
+ this.#cache.set(token, instance);
188
+ instance = instance.then((instance) => {
189
+ this.#cache.set(token, instance);
190
+ return instance;
191
+ });
192
+ return instance;
188
193
  case ProviderScope_1.ProviderScope.REQUEST:
189
194
  instance = this.resolve(token, locals, options);
190
195
  locals.set(token, instance);
191
- break;
196
+ return instance;
192
197
  case ProviderScope_1.ProviderScope.INSTANCE:
193
- instance = this.resolve(provider.provide, locals, options);
194
- break;
198
+ return this.resolve(provider.provide, locals, options);
195
199
  }
196
200
  return instance;
197
201
  }
198
202
  /**
199
203
  * Build only providers which are asynchronous.
200
204
  */
201
- async loadAsync(locals = new LocalsContainer_1.LocalsContainer()) {
205
+ async loadAsync() {
202
206
  for (const [, provider] of this) {
203
- if (!locals.has(provider.token)) {
204
- if (provider.isAsync()) {
205
- await this.invoke(provider.token, locals);
206
- }
207
- const instance = this.#cache.get(provider.token);
208
- if (instance !== undefined) {
209
- locals.set(provider.token, instance);
210
- }
207
+ if (!this.has(provider.token) && provider.isAsync()) {
208
+ await this.invoke(provider.token);
211
209
  }
212
210
  }
213
- return locals;
214
211
  }
215
- loadSync(locals = new LocalsContainer_1.LocalsContainer()) {
212
+ loadSync() {
216
213
  for (const [, provider] of this) {
217
- if (!locals.has(provider.token) && this.scopeOf(provider) === ProviderScope_1.ProviderScope.SINGLETON) {
218
- this.invoke(provider.token, locals);
219
- }
220
- const instance = this.#cache.get(provider.token);
221
- if (instance !== undefined) {
222
- locals.set(provider.token, instance);
214
+ if (!this.has(provider.token) && this.scopeOf(provider) === ProviderScope_1.ProviderScope.SINGLETON) {
215
+ this.invoke(provider.token);
223
216
  }
224
217
  }
225
- return locals;
226
218
  }
227
219
  /**
228
220
  * Boostrap injector from container and resolve configuration.
@@ -259,15 +251,14 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
259
251
  async load(container = (0, createContainer_1.createContainer)(), rootModule) {
260
252
  this.bootstrap(container);
261
253
  // build async and sync provider
262
- let locals = await this.loadAsync();
254
+ await this.loadAsync();
263
255
  if (rootModule) {
264
256
  await this.invoke(rootModule);
265
257
  }
266
258
  // load sync provider
267
- locals = this.loadSync(locals);
268
- await locals.emit("$beforeInit");
269
- await locals.emit("$onInit");
270
- return locals;
259
+ this.loadSync();
260
+ await this.emit("$beforeInit");
261
+ await this.emit("$onInit");
271
262
  }
272
263
  /**
273
264
  * Load all configurations registered on providers
@@ -1 +1 @@
1
- {"version":3,"file":"InjectorService.js","sourceRoot":"","sources":["../../../src/services/InjectorService.ts"],"names":[],"mappings":";;;;;AAAA,qCAaoB;AACpB,sDAAyE;AACzE,+DAA0D;AAC1D,yDAAoD;AACpD,mDAA8C;AAC9C,+DAA0D;AAC1D,iDAA4C;AAC5C,6DAAwD;AACxD,uEAAkE;AAClE,mEAA8D;AAC9D,8DAAyD;AACzD,uDAAkD;AAElD,2DAAsD;AAMtD,6EAAwE;AAGxE,wDAAmD;AACnD,oEAA+D;AAE/D;;;;;;;;;;;;;;;;;;;;GAoBG;AAKH,IAAa,eAAe,uBAA5B,MAAa,eAAgB,SAAQ,qBAAS;IACrC,QAAQ,GAAoB,IAAI,iCAAe,EAAE,CAAC;IAClD,MAAM,GAAa,OAAO,CAAC;IAC3B,YAAY,GAAG,2BAAY,CAAC;IAC3B,qBAAqB,GAAY,KAAK,CAAC;IAC/C,MAAM,GAAG,IAAI,iCAAe,EAAE,CAAC;IAE/B;QACE,KAAK,EAAE,CAAC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\n Metadata,\n nameOf,\n prototypeOf,\n Store\n} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants/constants\";\nimport {Configuration} from \"../decorators/configuration\";\nimport {Injectable} from \"../decorators/injectable\";\nimport {Container} from \"../domain/Container\";\nimport {LocalsContainer} from \"../domain/LocalsContainer\";\nimport {Provider} from \"../domain/Provider\";\nimport {InjectionError} from \"../errors/InjectionError\";\nimport {UndefinedTokenError} from \"../errors/UndefinedTokenError\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {createContainer} from \"../utils/createContainer\";\nimport {DIConfiguration} from \"./DIConfiguration\";\nimport {ResolvedInvokeOptions} from \"../interfaces/ResolvedInvokeOptions\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\nimport {DILogger} from \"../interfaces/DILogger\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {InvokeOptions} from \"../interfaces/InvokeOptions\";\nimport {InjectableProperties, InjectablePropertyOptions, InjectablePropertyValue} from \"../interfaces/InjectableProperties\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\nimport {InterceptorContext} from \"../interfaces/InterceptorContext\";\nimport {InterceptorMethods} from \"../interfaces/InterceptorMethods\";\nimport {runInContext} from \"../utils/runInContext\";\nimport {resolveControllers} from \"../utils/resolveControllers\";\n\n/**\n * This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.\n *\n * ### Example:\n *\n * ```typescript\n * import {InjectorService} from \"@tsed/di\";\n *\n * // Import the services (all services are decorated with @Service()\";\n * import MyService1 from \"./services/service1\";\n * import MyService2 from \"./services/service2\";\n * import MyService3 from \"./services/service3\";\n *\n * // When all services is imported you can load InjectorService.\n * const injector = new InjectorService()\n *\n * await injector.load();\n *\n * const myService1 = injector.get<MyService1>(MyServcice1);\n * ```\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n global: true\n})\nexport class InjectorService extends Container {\n public settings: DIConfiguration = new DIConfiguration();\n public logger: DILogger = console;\n public runInContext = runInContext;\n private resolvedConfiguration: boolean = false;\n #cache = new LocalsContainer();\n\n constructor() {\n super();\n this.#cache.set(InjectorService, this);\n }\n\n get resolvers() {\n return this.settings.resolvers!;\n }\n\n get scopes() {\n return this.settings.scopes || {};\n }\n\n /**\n * Retrieve default scope for a given provider.\n * @param provider\n */\n public scopeOf(provider: Provider) {\n return provider.scope || this.scopes[provider.type] || ProviderScope.SINGLETON;\n }\n\n /**\n * Clone a provider from GlobalProviders and the given token. forkProvider method build automatically the provider if the instance parameter ins't given.\n * @param token\n * @param settings\n * @deprecated\n */\n public forkProvider(token: TokenProvider, settings: Partial<ProviderOpts<any>> = {}): Provider {\n if (!this.hasProvider(token)) {\n this.addProvider(token);\n }\n\n const provider = this.getProvider(token)!;\n\n Object.assign(provider, settings);\n\n this.#cache.set(token, this.invoke(token));\n\n return provider;\n }\n\n /**\n * Return a list of instance build by the injector.\n */\n public toArray(): any[] {\n return this.#cache.toArray();\n }\n\n /**\n * Get a service or factory already constructed from his symbol or class.\n *\n * #### Example\n *\n * ```typescript\n * import {InjectorService} from \"@tsed/di\";\n * import MyService from \"./services\";\n *\n * class OtherService {\n * constructor(injectorService: InjectorService) {\n * const myService = injectorService.get<MyService>(MyService);\n * }\n * }\n * ```\n *\n * @param token The class or symbol registered in InjectorService.\n * @param options\n * @returns {boolean}\n */\n get<T = any>(token: TokenProvider, options: any = {}): T | undefined {\n const instance = this.getInstance(token);\n\n if (instance !== undefined) {\n return instance;\n }\n\n if (!this.hasProvider(token)) {\n for (const resolver of this.resolvers) {\n const result = resolver.get(token, options);\n\n if (result !== undefined) {\n return result;\n }\n }\n }\n }\n\n /**\n * Return all instance of the same provider type\n * @param type\n */\n getAll(type: string) {\n return this.getProviders(type).map((provider) => {\n return this.get(provider.token);\n });\n }\n\n /**\n * The has() method returns a boolean indicating whether an element with the specified key exists or not.\n * @returns {boolean}\n * @param token\n */\n has(token: TokenProvider): boolean {\n return this.#cache.get(token) !== undefined;\n }\n\n /**\n * Invoke the class and inject all services that required by the class constructor.\n *\n * #### Example\n *\n * ```typescript\n * import {InjectorService} from \"@tsed/di\";\n * import MyService from \"./services\";\n *\n * class OtherService {\n * constructor(injectorService: InjectorService) {\n * const myService = injectorService.invoke<MyService>(MyService);\n * }\n * }\n * ```\n *\n * @param token The injectable class to invoke. Class parameters are injected according constructor signature.\n * @param locals Optional object. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.\n * @param options\n * @returns {T} The class constructed.\n */\n public invoke<T>(\n token: TokenProvider,\n locals: Map<TokenProvider, any> = new LocalsContainer(),\n options: Partial<InvokeOptions<T>> = {}\n ): T {\n const provider = this.ensureProvider(token);\n let instance: any;\n\n !locals.has(Configuration) && locals.set(Configuration, this.settings);\n\n if (locals.has(token)) {\n return locals.get(token);\n }\n\n if (token === DI_PARAM_OPTIONS) {\n return {} as T;\n }\n\n if (!provider || options.rebuild) {\n instance = this.resolve(token, locals, options);\n\n if (this.hasProvider(token)) {\n this.#cache.set(token, instance);\n }\n\n return instance;\n }\n\n switch (this.scopeOf(provider)) {\n case ProviderScope.SINGLETON:\n if (!this.has(token)) {\n this.#cache.set(token, this.resolve(token, locals, options));\n\n if (provider.isAsync()) {\n this.#cache.get(token).then((instance: any) => {\n this.#cache.set(token, instance);\n });\n }\n }\n\n instance = this.get<T>(token)!;\n break;\n\n case ProviderScope.REQUEST:\n instance = this.resolve(token, locals, options);\n locals.set(token, instance);\n break;\n\n case ProviderScope.INSTANCE:\n instance = this.resolve(provider.provide, locals, options);\n break;\n }\n\n return instance;\n }\n\n /**\n * Build only providers which are asynchronous.\n */\n async loadAsync(locals: LocalsContainer = new LocalsContainer()) {\n for (const [, provider] of this) {\n if (!locals.has(provider.token)) {\n if (provider.isAsync()) {\n await this.invoke(provider.token, locals);\n }\n\n const instance = this.#cache.get(provider.token);\n if (instance !== undefined) {\n locals.set(provider.token, instance);\n }\n }\n }\n\n return locals;\n }\n\n loadSync(locals: LocalsContainer = new LocalsContainer()) {\n for (const [, provider] of this) {\n if (!locals.has(provider.token) && this.scopeOf(provider) === ProviderScope.SINGLETON) {\n this.invoke(provider.token, locals);\n }\n\n const instance = this.#cache.get(provider.token);\n if (instance !== undefined) {\n locals.set(provider.token, instance);\n }\n }\n\n return locals;\n }\n\n /**\n * Boostrap injector from container and resolve configuration.\n *\n * @param container\n */\n bootstrap(container: Container = createContainer()) {\n // Clone all providers in the container\n this.addProviders(container);\n\n // Resolve all configuration\n this.resolveConfiguration();\n\n return this;\n }\n\n /**\n * Load injector from a given module\n * @param rootModule\n */\n loadModule(rootModule: TokenProvider) {\n this.settings.routes = this.settings.routes.concat(resolveControllers(this.settings));\n\n const container = createContainer();\n container.delete(rootModule);\n\n container.addProvider(rootModule, {\n type: \"server:module\",\n scope: ProviderScope.SINGLETON\n });\n\n return this.load(container);\n }\n\n /**\n * Build all providers from given container (or GlobalProviders) and emit `$onInit` event.\n *\n * @param container\n * @param rootModule\n */\n async load(container: Container = createContainer(), rootModule?: TokenProvider): Promise<LocalsContainer<any>> {\n this.bootstrap(container);\n\n // build async and sync provider\n let locals = await this.loadAsync();\n\n if (rootModule) {\n await this.invoke(rootModule);\n }\n\n // load sync provider\n locals = this.loadSync(locals);\n\n await locals.emit(\"$beforeInit\");\n await locals.emit(\"$onInit\");\n\n return locals;\n }\n\n /**\n * Load all configurations registered on providers\n */\n resolveConfiguration() {\n if (this.resolvedConfiguration) {\n return;\n }\n const mergedConfiguration = new Map();\n\n super.forEach((provider) => {\n if (provider.configuration && provider.type !== \"server:module\") {\n Object.entries(provider.configuration).forEach(([key, value]) => {\n if (![\"resolvers\", \"mount\", \"imports\"].includes(key)) {\n value = mergedConfiguration.has(key) ? deepMerge(mergedConfiguration.get(key), value) : deepClone(value);\n mergedConfiguration.set(key, value);\n }\n });\n }\n\n if (provider.resolvers) {\n this.settings.resolvers = this.settings.resolvers.concat(provider.resolvers);\n }\n });\n\n mergedConfiguration.forEach((value, key) => {\n this.settings.set(key, deepMerge(value, this.settings.get(key)));\n });\n\n this.resolvedConfiguration = true;\n }\n\n /**\n *\n * @param instance\n * @param locals\n * @param options\n */\n public bindInjectableProperties(instance: any, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions>) {\n const properties: InjectableProperties = ancestorsOf(classOf(instance)).reduce((properties: any, target: any) => {\n const store = Store.from(target);\n\n return {\n ...properties,\n ...(store.get(INJECTABLE_PROP) || {})\n };\n }, {});\n\n Object.values(properties).forEach((definition) => {\n switch (definition.bindingType) {\n case InjectablePropertyType.METHOD:\n this.bindMethod(instance, definition);\n break;\n case InjectablePropertyType.PROPERTY:\n this.bindProperty(instance, definition, locals, options);\n break;\n case InjectablePropertyType.CONSTANT:\n this.bindConstant(instance, definition);\n break;\n case InjectablePropertyType.VALUE:\n this.bindValue(instance, definition);\n break;\n case InjectablePropertyType.INTERCEPTOR:\n this.bindInterceptor(instance, definition);\n break;\n }\n });\n }\n\n /**\n *\n * @param instance\n * @param {string} propertyKey\n */\n public bindMethod(instance: any, {propertyKey}: InjectablePropertyOptions) {\n const target = classOf(instance);\n const originalMethod = instance[propertyKey];\n const deps = Metadata.getParamTypes(prototypeOf(target), propertyKey);\n\n instance[propertyKey] = () => {\n const services = deps.map((dependency: any) => this.get(dependency));\n\n return originalMethod.call(instance, ...services);\n };\n }\n\n /**\n * Create an injectable property.\n *\n * @param instance\n * @param {string} propertyKey\n * @param {any} useType\n * @param resolver\n * @param options\n * @param locals\n * @param invokeOptions\n */\n public bindProperty(\n instance: any,\n {propertyKey, resolver, options = {}}: InjectablePropertyOptions,\n locals: Map<TokenProvider, any>,\n invokeOptions: Partial<InvokeOptions>\n ) {\n let get: () => any;\n\n get = resolver(this, locals, {...invokeOptions, options});\n\n catchError(() =>\n Object.defineProperty(instance, propertyKey, {\n get\n })\n );\n }\n\n /**\n *\n * @param instance\n * @param {string} propertyKey\n * @param {any} useType\n */\n public bindValue(instance: any, {propertyKey, expression, defaultValue}: InjectablePropertyValue) {\n const descriptor = {\n get: () => this.settings.get(expression) || defaultValue,\n set: (value: any) => this.settings.set(expression, value),\n enumerable: true,\n configurable: true\n };\n\n catchError(() => Object.defineProperty(instance, propertyKey, descriptor));\n }\n\n /**\n *\n * @param instance\n * @param {string} propertyKey\n * @param {any} useType\n */\n public bindConstant(instance: any, {propertyKey, expression, defaultValue}: InjectablePropertyValue) {\n let bean: any;\n\n const get = () => {\n if (bean !== undefined) {\n return bean;\n }\n\n const value = this.settings.get(expression, defaultValue);\n bean = Object.freeze(deepClone(value));\n\n return bean;\n };\n\n const descriptor = {\n get,\n enumerable: true,\n configurable: true\n };\n\n catchError(() => Object.defineProperty(instance, propertyKey, descriptor));\n }\n\n /**\n *\n * @param instance\n * @param propertyKey\n * @param useType\n * @param options\n */\n public bindInterceptor(instance: any, {propertyKey, useType, options}: InjectablePropertyOptions) {\n const target = classOf(instance);\n const originalMethod = instance[propertyKey];\n\n instance[propertyKey] = (...args: any[]) => {\n const next = (err?: Error) => {\n if (!err) {\n return originalMethod.apply(instance, args);\n }\n\n throw err;\n };\n\n const context: InterceptorContext<any> = {\n target,\n propertyKey,\n args,\n options,\n next\n };\n\n const interceptor = this.get<InterceptorMethods>(useType)!;\n\n return interceptor.intercept!(\n {\n ...context,\n options\n },\n next\n );\n };\n }\n\n async lazyInvoke<T = any>(token: TokenProvider) {\n let instance = this.getInstance(token);\n\n if (!instance) {\n instance = await this.invoke<T>(token);\n\n if (isFunction(instance?.$onInit)) {\n await instance.$onInit();\n }\n }\n\n return instance;\n }\n\n /**\n * Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).\n * @param eventName The event name to emit at all services.\n * @param args List of the parameters to give to each services.\n * @returns {Promise<any[]>} A list of promises.\n */\n public async emit(eventName: string, ...args: any[]) {\n return this.#cache.emit(eventName, ...args);\n }\n\n /**\n * @param eventName\n * @param value\n * @param args\n */\n public alter<T = any>(eventName: string, value: any, ...args: any[]): T {\n return this.#cache.alter(eventName, value, ...args);\n }\n\n /**\n * @param eventName\n * @param value\n * @param args\n */\n public async alterAsync<T = any>(eventName: string, value: any, ...args: any[]): Promise<T> {\n return this.#cache.alterAsync(eventName, value, ...args);\n }\n\n async destroy() {\n await this.#cache.destroy();\n }\n\n protected ensureProvider(token: TokenProvider): Provider | undefined {\n if (!this.hasProvider(token) && GlobalProviders.has(token)) {\n this.addProvider(token);\n }\n\n return this.getProvider(token)!;\n }\n\n protected getInstance(token: any) {\n return this.#cache.get(token);\n }\n\n /**\n * Invoke a class method and inject service.\n *\n * #### IInjectableMethod options\n *\n * * **target**: Optional. The class instance.\n * * **methodName**: `string` Optional. The method name.\n * * **designParamTypes**: `any[]` Optional. List of injectable types.\n * * **locals**: `Map<Function, any>` Optional. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.\n *\n * #### Example\n *\n * @param target\n * @param locals\n * @param options\n * @private\n */\n private resolve<T>(target: TokenProvider, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions<T>> = {}): Promise<T> {\n const resolvedOpts = this.mapInvokeOptions(target, locals, options);\n const {token, deps, construct, imports, provider} = resolvedOpts;\n\n if (provider) {\n GlobalProviders.onInvoke(provider, locals, {...resolvedOpts, injector: this});\n }\n\n let instance: any;\n let currentDependency: any = false;\n\n try {\n const invokeDependency =\n (parent?: any) =>\n (token: any, index: number): any => {\n currentDependency = {token, index, deps};\n\n if (token !== DI_PARAM_OPTIONS) {\n const options = provider?.store?.get(`${DI_PARAM_OPTIONS}:${index}`);\n\n locals.set(DI_PARAM_OPTIONS, options || {});\n }\n\n return isInheritedFrom(token, Provider, 1) ? provider : this.invoke(token, locals, {parent});\n };\n\n // Invoke manually imported providers\n imports.forEach(invokeDependency());\n\n // Inject dependencies\n const services = deps.map(invokeDependency(token));\n\n currentDependency = false;\n\n instance = construct(services);\n } catch (error) {\n InjectionError.throwInjectorError(token, currentDependency, error);\n }\n\n if (instance === undefined) {\n throw new InjectionError(\n token,\n `Unable to create new instance from undefined value. Check your provider declaration for ${nameOf(token)}`\n );\n }\n\n if (instance && isClass(classOf(instance))) {\n this.bindInjectableProperties(instance, locals, options);\n }\n\n if (instance && provider.hooks) {\n Object.entries(provider.hooks).forEach(([key, cb]) => {\n instance[key] = (...args: any[]) => cb(instance, ...args);\n });\n }\n\n return instance;\n }\n\n /**\n * Create options to invoke a provider or class.\n * @param token\n * @param locals\n * @param options\n */\n private mapInvokeOptions(token: TokenProvider, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions>): ResolvedInvokeOptions {\n let imports: TokenProvider[] | undefined = options.imports;\n let deps: TokenProvider[] | undefined = options.deps;\n let scope = options.scope;\n let construct;\n\n if (!token) {\n throw new UndefinedTokenError();\n }\n\n let provider: Provider;\n\n if (!this.hasProvider(token)) {\n provider = new Provider(token);\n\n this.resolvers.forEach((resolver) => {\n const result = resolver.get(token, locals.get(DI_PARAM_OPTIONS));\n\n if (result !== undefined) {\n provider.useFactory = () => result;\n }\n });\n } else {\n provider = this.getProvider(token)!;\n }\n\n scope = scope || this.scopeOf(provider);\n deps = deps || provider.deps;\n imports = imports || provider.imports;\n\n if (provider.useValue !== undefined) {\n construct = () => (isFunction(provider.useValue) ? provider.useValue() : provider.useValue);\n } else if (provider.useFactory) {\n construct = (deps: TokenProvider[]) => provider.useFactory(...deps);\n } else if (provider.useAsyncFactory) {\n construct = async (deps: TokenProvider[]) => {\n deps = await Promise.all(deps);\n return provider.useAsyncFactory(...deps);\n };\n } else {\n // useClass\n deps = deps || Metadata.getParamTypes(provider.useClass);\n construct = (deps: TokenProvider[]) => new provider.useClass(...deps);\n }\n\n return {\n token,\n scope: scope || Store.from(token).get(\"scope\") || ProviderScope.SINGLETON,\n deps: deps! || [],\n imports: imports || [],\n construct,\n provider\n };\n }\n}\n"]}
1
+ {"version":3,"file":"InjectorService.js","sourceRoot":"","sources":["../../../src/services/InjectorService.ts"],"names":[],"mappings":";;;;;AAAA,qCAaoB;AACpB,sDAAyE;AACzE,+DAA0D;AAC1D,yD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From,\n Metadata,\n nameOf,\n prototypeOf,\n Store\n} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants/constants\";\nimport {Configuration} from \"../decorators/configuration\";\nimport {Injectable} from \"../decorators/injectable\";\nimport {Container} from \"../domain/Container\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\nimport {LocalsContainer} from \"../domain/LocalsContainer\";\nimport {Provider} from \"../domain/Provider\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\nimport {InjectionError} from \"../errors/InjectionError\";\nimport {UndefinedTokenError} from \"../errors/UndefinedTokenError\";\nimport {DILogger} from \"../interfaces/DILogger\";\nimport {InjectableProperties, InjectablePropertyOptions, InjectablePropertyValue} from \"../interfaces/InjectableProperties\";\nimport {InterceptorContext} from \"../interfaces/InterceptorContext\";\nimport {InterceptorMethods} from \"../interfaces/InterceptorMethods\";\nimport {InvokeOptions} from \"../interfaces/InvokeOptions\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {ResolvedInvokeOptions} from \"../interfaces/ResolvedInvokeOptions\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {createContainer} from \"../utils/createContainer\";\nimport {resolveControllers} from \"../utils/resolveControllers\";\nimport {runInContext} from \"../utils/runInContext\";\nimport {DIConfiguration} from \"./DIConfiguration\";\n\n/**\n * This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.\n *\n * ### Example:\n *\n * ```typescript\n * import {InjectorService} from \"@tsed/di\";\n *\n * // Import the services (all services are decorated with @Service()\";\n * import MyService1 from \"./services/service1\";\n * import MyService2 from \"./services/service2\";\n * import MyService3 from \"./services/service3\";\n *\n * // When all services is imported you can load InjectorService.\n * const injector = new InjectorService()\n *\n * await injector.load();\n *\n * const myService1 = injector.get<MyService1>(MyServcice1);\n * ```\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n global: true\n})\nexport class InjectorService extends Container {\n public settings: DIConfiguration = new DIConfiguration();\n public logger: DILogger = console;\n public runInContext = runInContext;\n private resolvedConfiguration: boolean = false;\n #cache = new LocalsContainer();\n\n constructor() {\n super();\n this.#cache.set(InjectorService, this);\n }\n\n get resolvers() {\n return this.settings.resolvers!;\n }\n\n get scopes() {\n return this.settings.scopes || {};\n }\n\n /**\n * Retrieve default scope for a given provider.\n * @param provider\n */\n public scopeOf(provider: Provider) {\n return provider.scope || this.scopes[provider.type] || ProviderScope.SINGLETON;\n }\n\n /**\n * Clone a provider from GlobalProviders and the given token. forkProvider method build automatically the provider if the instance parameter ins't given.\n * @param token\n * @param settings\n * @deprecated\n */\n public forkProvider(token: TokenProvider, settings: Partial<ProviderOpts<any>> = {}): Provider {\n if (!this.hasProvider(token)) {\n this.addProvider(token);\n }\n\n const provider = this.getProvider(token)!;\n\n Object.assign(provider, settings);\n\n this.#cache.set(token, this.invoke(token));\n\n return provider;\n }\n\n /**\n * Return a list of instance build by the injector.\n */\n public toArray(): any[] {\n return this.#cache.toArray();\n }\n\n /**\n * Get a service or factory already constructed from his symbol or class.\n *\n * #### Example\n *\n * ```typescript\n * import {InjectorService} from \"@tsed/di\";\n * import MyService from \"./services\";\n *\n * class OtherService {\n * constructor(injectorService: InjectorService) {\n * const myService = injectorService.get<MyService>(MyService);\n * }\n * }\n * ```\n *\n * @param token The class or symbol registered in InjectorService.\n * @param options\n * @returns {boolean}\n */\n get<T = any>(token: TokenProvider, options: any = {}): T | undefined {\n const instance = this.getInstance(token);\n\n if (instance !== undefined) {\n return instance;\n }\n\n if (!this.hasProvider(token)) {\n for (const resolver of this.resolvers) {\n const result = resolver.get(token, options);\n\n if (result !== undefined) {\n return result;\n }\n }\n }\n }\n\n /**\n * Return all instance of the same provider type\n * @param type\n */\n getAll(type: string) {\n return this.getProviders(type).map((provider) => {\n return this.get(provider.token);\n });\n }\n\n /**\n * The has() method returns a boolean indicating whether an element with the specified key exists or not.\n * @returns {boolean}\n * @param token\n */\n has(token: TokenProvider): boolean {\n return this.#cache.get(token) !== undefined;\n }\n\n /**\n * Invoke the class and inject all services that required by the class constructor.\n *\n * #### Example\n *\n * ```typescript\n * import {InjectorService} from \"@tsed/di\";\n * import MyService from \"./services\";\n *\n * class OtherService {\n * constructor(injectorService: InjectorService) {\n * const myService = injectorService.invoke<MyService>(MyService);\n * }\n * }\n * ```\n *\n * @param token The injectable class to invoke. Class parameters are injected according constructor signature.\n * @param locals Optional object. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.\n * @param options\n * @returns {T} The class constructed.\n */\n public invoke<T>(\n token: TokenProvider,\n locals: Map<TokenProvider, any> = new LocalsContainer(),\n options: Partial<InvokeOptions<T>> = {}\n ): T {\n const provider = this.ensureProvider(token);\n let instance: any = undefined;\n\n !locals.has(Configuration) && locals.set(Configuration, this.settings);\n\n if (locals.has(token)) {\n return locals.get(token);\n }\n\n if (token === DI_PARAM_OPTIONS) {\n return {} as T;\n }\n\n if (!provider || options.rebuild) {\n instance = this.resolve(token, locals, options);\n\n if (this.hasProvider(token)) {\n this.#cache.set(token, instance);\n }\n\n return instance;\n }\n\n switch (this.scopeOf(provider)) {\n case ProviderScope.SINGLETON:\n if (this.has(token)) {\n return this.get<T>(token)!;\n }\n\n instance = this.resolve(token, locals, options);\n\n if (!provider.isAsync()) {\n this.#cache.set(token, instance);\n return instance;\n }\n\n // store promise to lock token in cache\n this.#cache.set(token, instance);\n\n instance = instance.then((instance: any) => {\n this.#cache.set(token, instance);\n\n return instance;\n });\n\n return instance;\n\n case ProviderScope.REQUEST:\n instance = this.resolve(token, locals, options);\n locals.set(token, instance);\n return instance;\n\n case ProviderScope.INSTANCE:\n return this.resolve(provider.provide, locals, options) as any;\n }\n\n return instance;\n }\n\n /**\n * Build only providers which are asynchronous.\n */\n async loadAsync() {\n for (const [, provider] of this) {\n if (!this.has(provider.token) && provider.isAsync()) {\n await this.invoke(provider.token);\n }\n }\n }\n\n loadSync() {\n for (const [, provider] of this) {\n if (!this.has(provider.token) && this.scopeOf(provider) === ProviderScope.SINGLETON) {\n this.invoke(provider.token);\n }\n }\n }\n\n /**\n * Boostrap injector from container and resolve configuration.\n *\n * @param container\n */\n bootstrap(container: Container = createContainer()) {\n // Clone all providers in the container\n this.addProviders(container);\n\n // Resolve all configuration\n this.resolveConfiguration();\n\n return this;\n }\n\n /**\n * Load injector from a given module\n * @param rootModule\n */\n loadModule(rootModule: TokenProvider) {\n this.settings.routes = this.settings.routes.concat(resolveControllers(this.settings));\n\n const container = createContainer();\n container.delete(rootModule);\n\n container.addProvider(rootModule, {\n type: \"server:module\",\n scope: ProviderScope.SINGLETON\n });\n\n return this.load(container);\n }\n\n /**\n * Build all providers from given container (or GlobalProviders) and emit `$onInit` event.\n *\n * @param container\n * @param rootModule\n */\n async load(container: Container = createContainer(), rootModule?: TokenProvider) {\n this.bootstrap(container);\n\n // build async and sync provider\n await this.loadAsync();\n\n if (rootModule) {\n await this.invoke(rootModule);\n }\n\n // load sync provider\n this.loadSync();\n\n await this.emit(\"$beforeInit\");\n await this.emit(\"$onInit\");\n }\n\n /**\n * Load all configurations registered on providers\n */\n resolveConfiguration() {\n if (this.resolvedConfiguration) {\n return;\n }\n const mergedConfiguration = new Map();\n\n super.forEach((provider) => {\n if (provider.configuration && provider.type !== \"server:module\") {\n Object.entries(provider.configuration).forEach(([key, value]) => {\n if (![\"resolvers\", \"mount\", \"imports\"].includes(key)) {\n value = mergedConfiguration.has(key) ? deepMerge(mergedConfiguration.get(key), value) : deepClone(value);\n mergedConfiguration.set(key, value);\n }\n });\n }\n\n if (provider.resolvers) {\n this.settings.resolvers = this.settings.resolvers.concat(provider.resolvers);\n }\n });\n\n mergedConfiguration.forEach((value, key) => {\n this.settings.set(key, deepMerge(value, this.settings.get(key)));\n });\n\n this.resolvedConfiguration = true;\n }\n\n /**\n *\n * @param instance\n * @param locals\n * @param options\n */\n public bindInjectableProperties(instance: any, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions>) {\n const properties: InjectableProperties = ancestorsOf(classOf(instance)).reduce((properties: any, target: any) => {\n const store = Store.from(target);\n\n return {\n ...properties,\n ...(store.get(INJECTABLE_PROP) || {})\n };\n }, {});\n\n Object.values(properties).forEach((definition) => {\n switch (definition.bindingType) {\n case InjectablePropertyType.METHOD:\n this.bindMethod(instance, definition);\n break;\n case InjectablePropertyType.PROPERTY:\n this.bindProperty(instance, definition, locals, options);\n break;\n case InjectablePropertyType.CONSTANT:\n this.bindConstant(instance, definition);\n break;\n case InjectablePropertyType.VALUE:\n this.bindValue(instance, definition);\n break;\n case InjectablePropertyType.INTERCEPTOR:\n this.bindInterceptor(instance, definition);\n break;\n }\n });\n }\n\n /**\n *\n * @param instance\n * @param {string} propertyKey\n */\n public bindMethod(instance: any, {propertyKey}: InjectablePropertyOptions) {\n const target = classOf(instance);\n const originalMethod = instance[propertyKey];\n const deps = Metadata.getParamTypes(prototypeOf(target), propertyKey);\n\n instance[propertyKey] = () => {\n const services = deps.map((dependency: any) => this.get(dependency));\n\n return originalMethod.call(instance, ...services);\n };\n }\n\n /**\n * Create an injectable property.\n *\n * @param instance\n * @param {string} propertyKey\n * @param {any} useType\n * @param resolver\n * @param options\n * @param locals\n * @param invokeOptions\n */\n public bindProperty(\n instance: any,\n {propertyKey, resolver, options = {}}: InjectablePropertyOptions,\n locals: Map<TokenProvider, any>,\n invokeOptions: Partial<InvokeOptions>\n ) {\n let get: () => any;\n\n get = resolver(this, locals, {...invokeOptions, options});\n\n catchError(() =>\n Object.defineProperty(instance, propertyKey, {\n get\n })\n );\n }\n\n /**\n *\n * @param instance\n * @param {string} propertyKey\n * @param {any} useType\n */\n public bindValue(instance: any, {propertyKey, expression, defaultValue}: InjectablePropertyValue) {\n const descriptor = {\n get: () => this.settings.get(expression) || defaultValue,\n set: (value: any) => this.settings.set(expression, value),\n enumerable: true,\n configurable: true\n };\n\n catchError(() => Object.defineProperty(instance, propertyKey, descriptor));\n }\n\n /**\n *\n * @param instance\n * @param {string} propertyKey\n * @param {any} useType\n */\n public bindConstant(instance: any, {propertyKey, expression, defaultValue}: InjectablePropertyValue) {\n let bean: any;\n\n const get = () => {\n if (bean !== undefined) {\n return bean;\n }\n\n const value = this.settings.get(expression, defaultValue);\n bean = Object.freeze(deepClone(value));\n\n return bean;\n };\n\n const descriptor = {\n get,\n enumerable: true,\n configurable: true\n };\n\n catchError(() => Object.defineProperty(instance, propertyKey, descriptor));\n }\n\n /**\n *\n * @param instance\n * @param propertyKey\n * @param useType\n * @param options\n */\n public bindInterceptor(instance: any, {propertyKey, useType, options}: InjectablePropertyOptions) {\n const target = classOf(instance);\n const originalMethod = instance[propertyKey];\n\n instance[propertyKey] = (...args: any[]) => {\n const next = (err?: Error) => {\n if (!err) {\n return originalMethod.apply(instance, args);\n }\n\n throw err;\n };\n\n const context: InterceptorContext<any> = {\n target,\n propertyKey,\n args,\n options,\n next\n };\n\n const interceptor = this.get<InterceptorMethods>(useType)!;\n\n return interceptor.intercept!(\n {\n ...context,\n options\n },\n next\n );\n };\n }\n\n async lazyInvoke<T = any>(token: TokenProvider) {\n let instance = this.getInstance(token);\n\n if (!instance) {\n instance = await this.invoke<T>(token);\n\n if (isFunction(instance?.$onInit)) {\n await instance.$onInit();\n }\n }\n\n return instance;\n }\n\n /**\n * Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).\n * @param eventName The event name to emit at all services.\n * @param args List of the parameters to give to each services.\n * @returns {Promise<any[]>} A list of promises.\n */\n public async emit(eventName: string, ...args: any[]) {\n return this.#cache.emit(eventName, ...args);\n }\n\n /**\n * @param eventName\n * @param value\n * @param args\n */\n public alter<T = any>(eventName: string, value: any, ...args: any[]): T {\n return this.#cache.alter(eventName, value, ...args);\n }\n\n /**\n * @param eventName\n * @param value\n * @param args\n */\n public async alterAsync<T = any>(eventName: string, value: any, ...args: any[]): Promise<T> {\n return this.#cache.alterAsync(eventName, value, ...args);\n }\n\n async destroy() {\n await this.#cache.destroy();\n }\n\n protected ensureProvider(token: TokenProvider): Provider | undefined {\n if (!this.hasProvider(token) && GlobalProviders.has(token)) {\n this.addProvider(token);\n }\n\n return this.getProvider(token)!;\n }\n\n protected getInstance(token: any) {\n return this.#cache.get(token);\n }\n\n /**\n * Invoke a class method and inject service.\n *\n * #### IInjectableMethod options\n *\n * * **target**: Optional. The class instance.\n * * **methodName**: `string` Optional. The method name.\n * * **designParamTypes**: `any[]` Optional. List of injectable types.\n * * **locals**: `Map<Function, any>` Optional. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.\n *\n * #### Example\n *\n * @param target\n * @param locals\n * @param options\n * @private\n */\n private resolve<T>(target: TokenProvider, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions<T>> = {}): T | Promise<T> {\n const resolvedOpts = this.mapInvokeOptions(target, locals, options);\n const {token, deps, construct, imports, provider} = resolvedOpts;\n\n if (provider) {\n GlobalProviders.onInvoke(provider, locals, {...resolvedOpts, injector: this});\n }\n\n let instance: any;\n let currentDependency: any = false;\n\n try {\n const invokeDependency =\n (parent?: any) =>\n (token: any, index: number): any => {\n currentDependency = {token, index, deps};\n\n if (token !== DI_PARAM_OPTIONS) {\n const options = provider?.store?.get(`${DI_PARAM_OPTIONS}:${index}`);\n\n locals.set(DI_PARAM_OPTIONS, options || {});\n }\n\n return isInheritedFrom(token, Provider, 1) ? provider : this.invoke(token, locals, {parent});\n };\n\n // Invoke manually imported providers\n imports.forEach(invokeDependency());\n\n // Inject dependencies\n const services = deps.map(invokeDependency(token));\n\n currentDependency = false;\n\n instance = construct(services);\n } catch (error) {\n InjectionError.throwInjectorError(token, currentDependency, error);\n }\n\n if (instance === undefined) {\n throw new InjectionError(\n token,\n `Unable to create new instance from undefined value. Check your provider declaration for ${nameOf(token)}`\n );\n }\n\n if (instance && isClass(classOf(instance))) {\n this.bindInjectableProperties(instance, locals, options);\n }\n\n if (instance && provider.hooks) {\n Object.entries(provider.hooks).forEach(([key, cb]) => {\n instance[key] = (...args: any[]) => cb(instance, ...args);\n });\n }\n\n return instance;\n }\n\n /**\n * Create options to invoke a provider or class.\n * @param token\n * @param locals\n * @param options\n */\n private mapInvokeOptions(token: TokenProvider, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions>): ResolvedInvokeOptions {\n let imports: TokenProvider[] | undefined = options.imports;\n let deps: TokenProvider[] | undefined = options.deps;\n let scope = options.scope;\n let construct;\n\n if (!token) {\n throw new UndefinedTokenError();\n }\n\n let provider: Provider;\n\n if (!this.hasProvider(token)) {\n provider = new Provider(token);\n\n this.resolvers.forEach((resolver) => {\n const result = resolver.get(token, locals.get(DI_PARAM_OPTIONS));\n\n if (result !== undefined) {\n provider.useFactory = () => result;\n }\n });\n } else {\n provider = this.getProvider(token)!;\n }\n\n scope = scope || this.scopeOf(provider);\n deps = deps || provider.deps;\n imports = imports || provider.imports;\n\n if (provider.useValue !== undefined) {\n construct = () => (isFunction(provider.useValue) ? provider.useValue() : provider.useValue);\n } else if (provider.useFactory) {\n construct = (deps: TokenProvider[]) => provider.useFactory(...deps);\n } else if (provider.useAsyncFactory) {\n construct = async (deps: TokenProvider[]) => {\n deps = await Promise.all(deps);\n return provider.useAsyncFactory(...deps);\n };\n } else {\n // useClass\n deps = deps || Metadata.getParamTypes(provider.useClass);\n construct = (deps: TokenProvider[]) => new provider.useClass(...deps);\n }\n\n return {\n token,\n scope: scope || Store.from(token).get(\"scope\") || ProviderScope.SINGLETON,\n deps: deps! || [],\n imports: imports || [],\n construct,\n provider\n };\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { ContextLogger } from "./ContextLogger.js";
2
2
  import { LocalsContainer } from "./LocalsContainer.js";
3
+ import { runInContext } from "../utils/runInContext.js";
3
4
  export class DIContext extends Map {
4
5
  /**
5
6
  * Request id generated by @@contextMiddleware@@.
@@ -65,5 +66,11 @@ export class DIContext extends Map {
65
66
  async emit(eventName, ...args) {
66
67
  return this.injector?.emit(eventName, ...args);
67
68
  }
69
+ async runInContext(next) {
70
+ return runInContext(this, async () => {
71
+ next = (await this.injector?.alterAsync("$alterRunInContext", next, this)) || next;
72
+ return next();
73
+ });
74
+ }
68
75
  }
69
76
  //# sourceMappingURL=DIContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAkBlD,MAAM,OAAO,SAAU,SAAQ,GAAa;IAE1C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACM,EAAE,CAAS;IACpB;;OAEG;IACM,SAAS,GAAS,IAAI,IAAI,EAAE,CAAC;IACtC;;OAEG;IACI,SAAS,GAAG,IAAI,eAAe,EAAO,CAAC;IAC9C;;OAEG;IACM,MAAM,CAAgB;IAC/B;;OAEG;IACM,QAAQ,CAAkB;IAEnC,YAAY,EAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,EAAmB;QACzE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QAEb,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,aAAa,CAAC,MAAM,EAAE;YACtC,GAAG,OAAO;YACV,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,EAAE;YACF,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAEtB,aAAa;QACb,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,GAAG,IAAW;QAC1C,OAAO,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;CACF","sourcesContent":["import type {Env} from \"@tsed/core\";\nimport {InjectorService} from \"../services/InjectorService\";\nimport {ContextLogger, ContextLoggerOptions} from \"./ContextLogger\";\nimport {LocalsContainer} from \"./LocalsContainer\";\n\nexport interface ContextMethods extends Map<any, any> {\n readonly id: string;\n readonly logger: ContextLogger;\n readonly injector: InjectorService;\n readonly container: LocalsContainer;\n readonly env: Env;\n\n destroy(): any;\n}\n\nexport interface DIContextOptions extends Omit<ContextLoggerOptions, \"dateStart\"> {\n id: string;\n logger: any;\n injector?: InjectorService;\n}\n\nexport class DIContext extends Map<any, any> implements ContextMethods {\n [x: string]: any;\n /**\n * Request id generated by @@contextMiddleware@@.\n *\n * ::: tip\n * By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, \"\"))`.\n * Dash are removed to simplify tracking logs in Kibana\n * :::\n *\n * ::: tip\n * Request id can by customized by changing the server configuration.\n *\n * ```typescript\n * @Configuration({\n * logger: {\n * reqIdBuilder: createUniqId // give your own id generator function\n * }\n * })\n * class Server {\n *\n * }\n * ```\n * :::\n *\n */\n readonly id: string;\n /**\n * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.\n */\n readonly dateStart: Date = new Date();\n /**\n * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`\n */\n public container = new LocalsContainer<any>();\n /**\n * Logger attached to the context request.\n */\n readonly logger: ContextLogger;\n /**\n *\n */\n readonly injector: InjectorService;\n\n constructor({id, injector, logger, ignoreLog, ...options}: DIContextOptions) {\n super();\n this.id = id;\n\n injector && (this.injector = injector);\n\n this.logger = new ContextLogger(logger, {\n ...options,\n dateStart: this.dateStart,\n id,\n ignoreLog\n });\n }\n\n get env() {\n return this.injector.settings.get(\"env\");\n }\n\n async destroy() {\n await this.container.destroy();\n this.logger.destroy();\n\n // @ts-ignore\n delete this.container;\n }\n\n async emit(eventName: string, ...args: any[]) {\n return this.injector?.emit(eventName, ...args);\n }\n}\n\nexport type BaseContext = DIContext & TsED.Context;\n"]}
1
+ {"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAkBnD,MAAM,OAAO,SAAU,SAAQ,GAAa;IAE1C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACM,EAAE,CAAS;IACpB;;OAEG;IACM,SAAS,GAAS,IAAI,IAAI,EAAE,CAAC;IACtC;;OAEG;IACI,SAAS,GAAG,IAAI,eAAe,EAAO,CAAC;IAC9C;;OAEG;IACM,MAAM,CAAgB;IAC/B;;OAEG;IACM,QAAQ,CAAkB;IAEnC,YAAY,EAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,EAAmB;QACzE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QAEb,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,aAAa,CAAC,MAAM,EAAE;YACtC,GAAG,OAAO;YACV,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,EAAE;YACF,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAEtB,aAAa;QACb,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,GAAG,IAAW;QAC1C,OAAO,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,IAAc;QAC/B,OAAO,YAAY,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;YACnC,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,oBAAoB,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC;YACnF,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {Env} from \"@tsed/core\";\nimport {InjectorService} from \"../services/InjectorService\";\nimport {ContextLogger, ContextLoggerOptions} from \"./ContextLogger\";\nimport {LocalsContainer} from \"./LocalsContainer\";\nimport {runInContext} from \"../utils/runInContext\";\n\nexport interface ContextMethods extends Map<any, any> {\n readonly id: string;\n readonly logger: ContextLogger;\n readonly injector: InjectorService;\n readonly container: LocalsContainer;\n readonly env: Env;\n\n destroy(): any;\n}\n\nexport interface DIContextOptions extends Omit<ContextLoggerOptions, \"dateStart\"> {\n id: string;\n logger: any;\n injector?: InjectorService;\n}\n\nexport class DIContext extends Map<any, any> implements ContextMethods {\n [x: string]: any;\n /**\n * Request id generated by @@contextMiddleware@@.\n *\n * ::: tip\n * By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, \"\"))`.\n * Dash are removed to simplify tracking logs in Kibana\n * :::\n *\n * ::: tip\n * Request id can by customized by changing the server configuration.\n *\n * ```typescript\n * @Configuration({\n * logger: {\n * reqIdBuilder: createUniqId // give your own id generator function\n * }\n * })\n * class Server {\n *\n * }\n * ```\n * :::\n *\n */\n readonly id: string;\n /**\n * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.\n */\n readonly dateStart: Date = new Date();\n /**\n * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`\n */\n public container = new LocalsContainer<any>();\n /**\n * Logger attached to the context request.\n */\n readonly logger: ContextLogger;\n /**\n *\n */\n readonly injector: InjectorService;\n\n constructor({id, injector, logger, ignoreLog, ...options}: DIContextOptions) {\n super();\n this.id = id;\n\n injector && (this.injector = injector);\n\n this.logger = new ContextLogger(logger, {\n ...options,\n dateStart: this.dateStart,\n id,\n ignoreLog\n });\n }\n\n get env() {\n return this.injector.settings.get(\"env\");\n }\n\n async destroy() {\n await this.container.destroy();\n this.logger.destroy();\n\n // @ts-ignore\n delete this.container;\n }\n\n async emit(eventName: string, ...args: any[]) {\n return this.injector?.emit(eventName, ...args);\n }\n\n async runInContext(next: Function) {\n return runInContext(this, async () => {\n next = (await this.injector?.alterAsync(\"$alterRunInContext\", next, this)) || next;\n return next();\n });\n }\n}\n\nexport type BaseContext = DIContext & TsED.Context;\n"]}
package/lib/esm/index.js CHANGED
@@ -27,6 +27,7 @@ export * from "./domain/ProviderScope.js";
27
27
  export * from "./domain/ProviderType.js";
28
28
  export * from "./errors/InjectionError.js";
29
29
  export * from "./errors/UndefinedTokenError.js";
30
+ export * from "./interfaces/AlterRunInContext.js";
30
31
  export * from "./interfaces/DIConfigurationOptions.js";
31
32
  export * from "./interfaces/DILogger.js";
32
33
  export * from "./interfaces/DILoggerOptions.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAA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Ac,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/configuration\";\nexport * from \"./decorators/constant\";\nexport * from \"./decorators/controller\";\nexport * from \"./decorators/inject\";\nexport * from \"./decorators/injectable\";\nexport * from \"./decorators/intercept\";\nexport * from \"./decorators/interceptor\";\nexport * from \"./decorators/lazyInject\";\nexport * from \"./decorators/module\";\nexport * from \"./decorators/opts\";\nexport * from \"./decorators/overrideProvider\";\nexport * from \"./decorators/scope\";\nexport * from \"./decorators/service\";\nexport * from \"./decorators/useOpts\";\nexport * from \"./decorators/value\";\nexport * from \"./domain/Container\";\nexport * from \"./domain/ContextLogger\";\nexport * from \"./domain/DIContext\";\nexport * from \"./domain/InjectablePropertyType\";\nexport * from \"./domain/LocalsContainer\";\nexport * from \"./domain/Provider\";\nexport * from \"./domain/ProviderScope\";\nexport * from \"./domain/ProviderType\";\nexport * from \"./errors/InjectionError\";\nexport * from \"./errors/UndefinedTokenError\";\nexport * from \"./interfaces/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\nexport * from \"./interfaces/DILoggerOptions\";\nexport * from \"./interfaces/DIResolver\";\nexport * from \"./interfaces/InjectableProperties\";\nexport * from \"./interfaces/InterceptorContext\";\nexport * from \"./interfaces/InterceptorMethods\";\nexport * from \"./interfaces/InvokeOptions\";\nexport * from \"./interfaces/OnDestroy\";\nexport * from \"./interfaces/OnInit\";\nexport * from \"./interfaces/ProviderOpts\";\nexport * from \"./interfaces/RegistrySettings\";\nexport * from \"./interfaces/ResolvedInvokeOptions\";\nexport * from \"./interfaces/TokenProvider\";\nexport * from \"./interfaces/TokenRoute\";\nexport * from \"./registries/GlobalProviders\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DITest\";\nexport * from \"./services/InjectorService\";\nexport * from \"./utils/colors\";\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/resolveControllers\";\nexport * from \"./utils/runInContext\";\nexport * from \"./utils/setLoggerConfiguration\";\nexport * from \"./utils/setLoggerFormat\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oCAAoC,CAAC;AACnD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/configuration\";\nexport * from \"./decorators/constant\";\nexport * from \"./decorators/controller\";\nexport * from \"./decorators/inject\";\nexport * from \"./decorators/injectable\";\nexport * from \"./decorators/intercept\";\nexport * from \"./decorators/interceptor\";\nexport * from \"./decorators/lazyInject\";\nexport * from \"./decorators/module\";\nexport * from \"./decorators/opts\";\nexport * from \"./decorators/overrideProvider\";\nexport * from \"./decorators/scope\";\nexport * from \"./decorators/service\";\nexport * from \"./decorators/useOpts\";\nexport * from \"./decorators/value\";\nexport * from \"./domain/Container\";\nexport * from \"./domain/ContextLogger\";\nexport * from \"./domain/DIContext\";\nexport * from \"./domain/InjectablePropertyType\";\nexport * from \"./domain/LocalsContainer\";\nexport * from \"./domain/Provider\";\nexport * from \"./domain/ProviderScope\";\nexport * from \"./domain/ProviderType\";\nexport * from \"./errors/InjectionError\";\nexport * from \"./errors/UndefinedTokenError\";\nexport * from \"./interfaces/AlterRunInContext\";\nexport * from \"./interfaces/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\nexport * from \"./interfaces/DILoggerOptions\";\nexport * from \"./interfaces/DIResolver\";\nexport * from \"./interfaces/InjectableProperties\";\nexport * from \"./interfaces/InterceptorContext\";\nexport * from \"./interfaces/InterceptorMethods\";\nexport * from \"./interfaces/InvokeOptions\";\nexport * from \"./interfaces/OnDestroy\";\nexport * from \"./interfaces/OnInit\";\nexport * from \"./interfaces/ProviderOpts\";\nexport * from \"./interfaces/RegistrySettings\";\nexport * from \"./interfaces/ResolvedInvokeOptions\";\nexport * from \"./interfaces/TokenProvider\";\nexport * from \"./interfaces/TokenRoute\";\nexport * from \"./registries/GlobalProviders\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DITest\";\nexport * from \"./services/InjectorService\";\nexport * from \"./utils/colors\";\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/resolveControllers\";\nexport * from \"./utils/runInContext\";\nexport * from \"./utils/setLoggerConfiguration\";\nexport * from \"./utils/setLoggerFormat\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=AlterRunInContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlterRunInContext.js","sourceRoot":"","sources":["../../../src/interfaces/AlterRunInContext.ts"],"names":[],"mappings":"","sourcesContent":["import {DIContext} from \"../domain/DIContext\";\n\nexport interface AlterRunInContext {\n $alterRunInContext(next: (...args: unknown[]) => unknown, ctx: DIContext): () => unknown | Promise<() => unknown>;\n}\n"]}
@@ -5,17 +5,17 @@ import { DI_PARAM_OPTIONS, INJECTABLE_PROP } from "../constants/constants.js";
5
5
  import { Configuration } from "../decorators/configuration.js";
6
6
  import { Injectable } from "../decorators/injectable.js";
7
7
  import { Container } from "../domain/Container.js";
8
+ import { InjectablePropertyType } from "../domain/InjectablePropertyType.js";
8
9
  import { LocalsContainer } from "../domain/LocalsContainer.js";
9
10
  import { Provider } from "../domain/Provider.js";
11
+ import { ProviderScope } from "../domain/ProviderScope.js";
10
12
  import { InjectionError } from "../errors/InjectionError.js";
11
13
  import { UndefinedTokenError } from "../errors/UndefinedTokenError.js";
12
14
  import { GlobalProviders } from "../registries/GlobalProviders.js";
13
15
  import { createContainer } from "../utils/createContainer.js";
14
- import { DIConfiguration } from "./DIConfiguration.js";
15
- import { ProviderScope } from "../domain/ProviderScope.js";
16
- import { InjectablePropertyType } from "../domain/InjectablePropertyType.js";
17
- import { runInContext } from "../utils/runInContext.js";
18
16
  import { resolveControllers } from "../utils/resolveControllers.js";
17
+ import { runInContext } from "../utils/runInContext.js";
18
+ import { DIConfiguration } from "./DIConfiguration.js";
19
19
  /**
20
20
  * This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.
21
21
  *
@@ -155,7 +155,7 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
155
155
  */
156
156
  invoke(token, locals = new LocalsContainer(), options = {}) {
157
157
  const provider = this.ensureProvider(token);
158
- let instance;
158
+ let instance = undefined;
159
159
  !locals.has(Configuration) && locals.set(Configuration, this.settings);
160
160
  if (locals.has(token)) {
161
161
  return locals.get(token);
@@ -172,54 +172,46 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
172
172
  }
173
173
  switch (this.scopeOf(provider)) {
174
174
  case ProviderScope.SINGLETON:
175
- if (!this.has(token)) {
176
- this.#cache.set(token, this.resolve(token, locals, options));
177
- if (provider.isAsync()) {
178
- this.#cache.get(token).then((instance) => {
179
- this.#cache.set(token, instance);
180
- });
181
- }
175
+ if (this.has(token)) {
176
+ return this.get(token);
177
+ }
178
+ instance = this.resolve(token, locals, options);
179
+ if (!provider.isAsync()) {
180
+ this.#cache.set(token, instance);
181
+ return instance;
182
182
  }
183
- instance = this.get(token);
184
- break;
183
+ // store promise to lock token in cache
184
+ this.#cache.set(token, instance);
185
+ instance = instance.then((instance) => {
186
+ this.#cache.set(token, instance);
187
+ return instance;
188
+ });
189
+ return instance;
185
190
  case ProviderScope.REQUEST:
186
191
  instance = this.resolve(token, locals, options);
187
192
  locals.set(token, instance);
188
- break;
193
+ return instance;
189
194
  case ProviderScope.INSTANCE:
190
- instance = this.resolve(provider.provide, locals, options);
191
- break;
195
+ return this.resolve(provider.provide, locals, options);
192
196
  }
193
197
  return instance;
194
198
  }
195
199
  /**
196
200
  * Build only providers which are asynchronous.
197
201
  */
198
- async loadAsync(locals = new LocalsContainer()) {
202
+ async loadAsync() {
199
203
  for (const [, provider] of this) {
200
- if (!locals.has(provider.token)) {
201
- if (provider.isAsync()) {
202
- await this.invoke(provider.token, locals);
203
- }
204
- const instance = this.#cache.get(provider.token);
205
- if (instance !== undefined) {
206
- locals.set(provider.token, instance);
207
- }
204
+ if (!this.has(provider.token) && provider.isAsync()) {
205
+ await this.invoke(provider.token);
208
206
  }
209
207
  }
210
- return locals;
211
208
  }
212
- loadSync(locals = new LocalsContainer()) {
209
+ loadSync() {
213
210
  for (const [, provider] of this) {
214
- if (!locals.has(provider.token) && this.scopeOf(provider) === ProviderScope.SINGLETON) {
215
- this.invoke(provider.token, locals);
216
- }
217
- const instance = this.#cache.get(provider.token);
218
- if (instance !== undefined) {
219
- locals.set(provider.token, instance);
211
+ if (!this.has(provider.token) && this.scopeOf(provider) === ProviderScope.SINGLETON) {
212
+ this.invoke(provider.token);
220
213
  }
221
214
  }
222
- return locals;
223
215
  }
224
216
  /**
225
217
  * Boostrap injector from container and resolve configuration.
@@ -256,15 +248,14 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
256
248
  async load(container = createContainer(), rootModule) {
257
249
  this.bootstrap(container);
258
250
  // build async and sync provider
259
- let locals = await this.loadAsync();
251
+ await this.loadAsync();
260
252
  if (rootModule) {
261
253
  await this.invoke(rootModule);
262
254
  }
263
255
  // load sync provider
264
- locals = this.loadSync(locals);
265
- await locals.emit("$beforeInit");
266
- await locals.emit("$onInit");
267
- return locals;
256
+ this.loadSync();
257
+ await this.emit("$beforeInit");
258
+ await this.emit("$onInit");
268
259
  }
269
260
  /**
270
261
  * Load all configurations registered on providers
@@ -1 +1 @@
1
- {"version":3,"file":"InjectorService.js","sourceRoot":"","sources":["../../../src/services/InjectorService.ts"],"names":[],"mappings":";;AAAA,OAAO,EACL,WAAW,EACX,UAAU,EACV,OAAO,EACP,SAAS,EACT,SAAS,EACT,OAAO,EACP,UAAU,EACV,eAAe,EACf,QAAQ,EACR,MAAM,EACN,WAAW,EACX,KAAK,EACN,MAAM,YAAY,CAAC;AACpB,OAAO,EAAC,gBAAgB,EAAE,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAC,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAC,cAAc,EAAC,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAC,mBAAmB,EAAC,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAC,eAAe,EAAC,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAC,aAAa,EAAC,MAAM,yBAAyB,CAAC;AAMtD,OAAO,EAAC,sBAAsB,EAAC,MAAM,kCAAkC,CAAC;AAGxE,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;GAoBG;AAKH,IAAa,eAAe,uBAA5B,MAAa,eAAgB,SAAQ,SAAS;IACrC,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,\n isFunction,\n isInheritedFrom,\n Metadata,\n nameOf,\n prototypeOf,\n Store\n} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants/constants\";\nimport {Configuration} from \"../decorators/configuration\";\nimport {Injectable} from \"../decorators/injectable\";\nimport {Container} from \"../domain/Container\";\nimport {LocalsContainer} from \"../domain/LocalsContainer\";\nimport {Provider} from \"../domain/Provider\";\nimport {InjectionError} from \"../errors/InjectionError\";\nimport {UndefinedTokenError} from \"../errors/UndefinedTokenError\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {createContainer} from \"../utils/createContainer\";\nimport {DIConfiguration} from \"./DIConfiguration\";\nimport {ResolvedInvokeOptions} from \"../interfaces/ResolvedInvokeOptions\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\nimport {DILogger} from \"../interfaces/DILogger\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {InvokeOptions} from \"../interfaces/InvokeOptions\";\nimport {InjectableProperties, InjectablePropertyOptions, InjectablePropertyValue} from \"../interfaces/InjectableProperties\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\nimport {InterceptorContext} from \"../interfaces/InterceptorContext\";\nimport {InterceptorMethods} from \"../interfaces/InterceptorMethods\";\nimport {runInContext} from \"../utils/runInContext\";\nimport {resolveControllers} from \"../utils/resolveControllers\";\n\n/**\n * This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.\n *\n * ### Example:\n *\n * ```typescript\n * import {InjectorService} from \"@tsed/di\";\n *\n * // Import the services (all services are decorated with @Service()\";\n * import MyService1 from \"./services/service1\";\n * import MyService2 from \"./services/service2\";\n * import MyService3 from \"./services/service3\";\n *\n * // When all services is imported you can load InjectorService.\n * const injector = new InjectorService()\n *\n * await injector.load();\n *\n * const myService1 = injector.get<MyService1>(MyServcice1);\n * ```\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n global: true\n})\nexport class InjectorService extends Container {\n public settings: DIConfiguration = new DIConfiguration();\n public logger: DILogger = console;\n public runInContext = runInContext;\n private resolvedConfiguration: boolean = false;\n #cache = new LocalsContainer();\n\n constructor() {\n super();\n this.#cache.set(InjectorService, this);\n }\n\n get resolvers() {\n return this.settings.resolvers!;\n }\n\n get scopes() {\n return this.settings.scopes || {};\n }\n\n /**\n * Retrieve default scope for a given provider.\n * @param provider\n */\n public scopeOf(provider: Provider) {\n return provider.scope || this.scopes[provider.type] || ProviderScope.SINGLETON;\n }\n\n /**\n * Clone a provider from GlobalProviders and the given token. forkProvider method build automatically the provider if the instance parameter ins't given.\n * @param token\n * @param settings\n * @deprecated\n */\n public forkProvider(token: TokenProvider, settings: Partial<ProviderOpts<any>> = {}): Provider {\n if (!this.hasProvider(token)) {\n this.addProvider(token);\n }\n\n const provider = this.getProvider(token)!;\n\n Object.assign(provider, settings);\n\n this.#cache.set(token, this.invoke(token));\n\n return provider;\n }\n\n /**\n * Return a list of instance build by the injector.\n */\n public toArray(): any[] {\n return this.#cache.toArray();\n }\n\n /**\n * Get a service or factory already constructed from his symbol or class.\n *\n * #### Example\n *\n * ```typescript\n * import {InjectorService} from \"@tsed/di\";\n * import MyService from \"./services\";\n *\n * class OtherService {\n * constructor(injectorService: InjectorService) {\n * const myService = injectorService.get<MyService>(MyService);\n * }\n * }\n * ```\n *\n * @param token The class or symbol registered in InjectorService.\n * @param options\n * @returns {boolean}\n */\n get<T = any>(token: TokenProvider, options: any = {}): T | undefined {\n const instance = this.getInstance(token);\n\n if (instance !== undefined) {\n return instance;\n }\n\n if (!this.hasProvider(token)) {\n for (const resolver of this.resolvers) {\n const result = resolver.get(token, options);\n\n if (result !== undefined) {\n return result;\n }\n }\n }\n }\n\n /**\n * Return all instance of the same provider type\n * @param type\n */\n getAll(type: string) {\n return this.getProviders(type).map((provider) => {\n return this.get(provider.token);\n });\n }\n\n /**\n * The has() method returns a boolean indicating whether an element with the specified key exists or not.\n * @returns {boolean}\n * @param token\n */\n has(token: TokenProvider): boolean {\n return this.#cache.get(token) !== undefined;\n }\n\n /**\n * Invoke the class and inject all services that required by the class constructor.\n *\n * #### Example\n *\n * ```typescript\n * import {InjectorService} from \"@tsed/di\";\n * import MyService from \"./services\";\n *\n * class OtherService {\n * constructor(injectorService: InjectorService) {\n * const myService = injectorService.invoke<MyService>(MyService);\n * }\n * }\n * ```\n *\n * @param token The injectable class to invoke. Class parameters are injected according constructor signature.\n * @param locals Optional object. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.\n * @param options\n * @returns {T} The class constructed.\n */\n public invoke<T>(\n token: TokenProvider,\n locals: Map<TokenProvider, any> = new LocalsContainer(),\n options: Partial<InvokeOptions<T>> = {}\n ): T {\n const provider = this.ensureProvider(token);\n let instance: any;\n\n !locals.has(Configuration) && locals.set(Configuration, this.settings);\n\n if (locals.has(token)) {\n return locals.get(token);\n }\n\n if (token === DI_PARAM_OPTIONS) {\n return {} as T;\n }\n\n if (!provider || options.rebuild) {\n instance = this.resolve(token, locals, options);\n\n if (this.hasProvider(token)) {\n this.#cache.set(token, instance);\n }\n\n return instance;\n }\n\n switch (this.scopeOf(provider)) {\n case ProviderScope.SINGLETON:\n if (!this.has(token)) {\n this.#cache.set(token, this.resolve(token, locals, options));\n\n if (provider.isAsync()) {\n this.#cache.get(token).then((instance: any) => {\n this.#cache.set(token, instance);\n });\n }\n }\n\n instance = this.get<T>(token)!;\n break;\n\n case ProviderScope.REQUEST:\n instance = this.resolve(token, locals, options);\n locals.set(token, instance);\n break;\n\n case ProviderScope.INSTANCE:\n instance = this.resolve(provider.provide, locals, options);\n break;\n }\n\n return instance;\n }\n\n /**\n * Build only providers which are asynchronous.\n */\n async loadAsync(locals: LocalsContainer = new LocalsContainer()) {\n for (const [, provider] of this) {\n if (!locals.has(provider.token)) {\n if (provider.isAsync()) {\n await this.invoke(provider.token, locals);\n }\n\n const instance = this.#cache.get(provider.token);\n if (instance !== undefined) {\n locals.set(provider.token, instance);\n }\n }\n }\n\n return locals;\n }\n\n loadSync(locals: LocalsContainer = new LocalsContainer()) {\n for (const [, provider] of this) {\n if (!locals.has(provider.token) && this.scopeOf(provider) === ProviderScope.SINGLETON) {\n this.invoke(provider.token, locals);\n }\n\n const instance = this.#cache.get(provider.token);\n if (instance !== undefined) {\n locals.set(provider.token, instance);\n }\n }\n\n return locals;\n }\n\n /**\n * Boostrap injector from container and resolve configuration.\n *\n * @param container\n */\n bootstrap(container: Container = createContainer()) {\n // Clone all providers in the container\n this.addProviders(container);\n\n // Resolve all configuration\n this.resolveConfiguration();\n\n return this;\n }\n\n /**\n * Load injector from a given module\n * @param rootModule\n */\n loadModule(rootModule: TokenProvider) {\n this.settings.routes = this.settings.routes.concat(resolveControllers(this.settings));\n\n const container = createContainer();\n container.delete(rootModule);\n\n container.addProvider(rootModule, {\n type: \"server:module\",\n scope: ProviderScope.SINGLETON\n });\n\n return this.load(container);\n }\n\n /**\n * Build all providers from given container (or GlobalProviders) and emit `$onInit` event.\n *\n * @param container\n * @param rootModule\n */\n async load(container: Container = createContainer(), rootModule?: TokenProvider): Promise<LocalsContainer<any>> {\n this.bootstrap(container);\n\n // build async and sync provider\n let locals = await this.loadAsync();\n\n if (rootModule) {\n await this.invoke(rootModule);\n }\n\n // load sync provider\n locals = this.loadSync(locals);\n\n await locals.emit(\"$beforeInit\");\n await locals.emit(\"$onInit\");\n\n return locals;\n }\n\n /**\n * Load all configurations registered on providers\n */\n resolveConfiguration() {\n if (this.resolvedConfiguration) {\n return;\n }\n const mergedConfiguration = new Map();\n\n super.forEach((provider) => {\n if (provider.configuration && provider.type !== \"server:module\") {\n Object.entries(provider.configuration).forEach(([key, value]) => {\n if (![\"resolvers\", \"mount\", \"imports\"].includes(key)) {\n value = mergedConfiguration.has(key) ? deepMerge(mergedConfiguration.get(key), value) : deepClone(value);\n mergedConfiguration.set(key, value);\n }\n });\n }\n\n if (provider.resolvers) {\n this.settings.resolvers = this.settings.resolvers.concat(provider.resolvers);\n }\n });\n\n mergedConfiguration.forEach((value, key) => {\n this.settings.set(key, deepMerge(value, this.settings.get(key)));\n });\n\n this.resolvedConfiguration = true;\n }\n\n /**\n *\n * @param instance\n * @param locals\n * @param options\n */\n public bindInjectableProperties(instance: any, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions>) {\n const properties: InjectableProperties = ancestorsOf(classOf(instance)).reduce((properties: any, target: any) => {\n const store = Store.from(target);\n\n return {\n ...properties,\n ...(store.get(INJECTABLE_PROP) || {})\n };\n }, {});\n\n Object.values(properties).forEach((definition) => {\n switch (definition.bindingType) {\n case InjectablePropertyType.METHOD:\n this.bindMethod(instance, definition);\n break;\n case InjectablePropertyType.PROPERTY:\n this.bindProperty(instance, definition, locals, options);\n break;\n case InjectablePropertyType.CONSTANT:\n this.bindConstant(instance, definition);\n break;\n case InjectablePropertyType.VALUE:\n this.bindValue(instance, definition);\n break;\n case InjectablePropertyType.INTERCEPTOR:\n this.bindInterceptor(instance, definition);\n break;\n }\n });\n }\n\n /**\n *\n * @param instance\n * @param {string} propertyKey\n */\n public bindMethod(instance: any, {propertyKey}: InjectablePropertyOptions) {\n const target = classOf(instance);\n const originalMethod = instance[propertyKey];\n const deps = Metadata.getParamTypes(prototypeOf(target), propertyKey);\n\n instance[propertyKey] = () => {\n const services = deps.map((dependency: any) => this.get(dependency));\n\n return originalMethod.call(instance, ...services);\n };\n }\n\n /**\n * Create an injectable property.\n *\n * @param instance\n * @param {string} propertyKey\n * @param {any} useType\n * @param resolver\n * @param options\n * @param locals\n * @param invokeOptions\n */\n public bindProperty(\n instance: any,\n {propertyKey, resolver, options = {}}: InjectablePropertyOptions,\n locals: Map<TokenProvider, any>,\n invokeOptions: Partial<InvokeOptions>\n ) {\n let get: () => any;\n\n get = resolver(this, locals, {...invokeOptions, options});\n\n catchError(() =>\n Object.defineProperty(instance, propertyKey, {\n get\n })\n );\n }\n\n /**\n *\n * @param instance\n * @param {string} propertyKey\n * @param {any} useType\n */\n public bindValue(instance: any, {propertyKey, expression, defaultValue}: InjectablePropertyValue) {\n const descriptor = {\n get: () => this.settings.get(expression) || defaultValue,\n set: (value: any) => this.settings.set(expression, value),\n enumerable: true,\n configurable: true\n };\n\n catchError(() => Object.defineProperty(instance, propertyKey, descriptor));\n }\n\n /**\n *\n * @param instance\n * @param {string} propertyKey\n * @param {any} useType\n */\n public bindConstant(instance: any, {propertyKey, expression, defaultValue}: InjectablePropertyValue) {\n let bean: any;\n\n const get = () => {\n if (bean !== undefined) {\n return bean;\n }\n\n const value = this.settings.get(expression, defaultValue);\n bean = Object.freeze(deepClone(value));\n\n return bean;\n };\n\n const descriptor = {\n get,\n enumerable: true,\n configurable: true\n };\n\n catchError(() => Object.defineProperty(instance, propertyKey, descriptor));\n }\n\n /**\n *\n * @param instance\n * @param propertyKey\n * @param useType\n * @param options\n */\n public bindInterceptor(instance: any, {propertyKey, useType, options}: InjectablePropertyOptions) {\n const target = classOf(instance);\n const originalMethod = instance[propertyKey];\n\n instance[propertyKey] = (...args: any[]) => {\n const next = (err?: Error) => {\n if (!err) {\n return originalMethod.apply(instance, args);\n }\n\n throw err;\n };\n\n const context: InterceptorContext<any> = {\n target,\n propertyKey,\n args,\n options,\n next\n };\n\n const interceptor = this.get<InterceptorMethods>(useType)!;\n\n return interceptor.intercept!(\n {\n ...context,\n options\n },\n next\n );\n };\n }\n\n async lazyInvoke<T = any>(token: TokenProvider) {\n let instance = this.getInstance(token);\n\n if (!instance) {\n instance = await this.invoke<T>(token);\n\n if (isFunction(instance?.$onInit)) {\n await instance.$onInit();\n }\n }\n\n return instance;\n }\n\n /**\n * Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).\n * @param eventName The event name to emit at all services.\n * @param args List of the parameters to give to each services.\n * @returns {Promise<any[]>} A list of promises.\n */\n public async emit(eventName: string, ...args: any[]) {\n return this.#cache.emit(eventName, ...args);\n }\n\n /**\n * @param eventName\n * @param value\n * @param args\n */\n public alter<T = any>(eventName: string, value: any, ...args: any[]): T {\n return this.#cache.alter(eventName, value, ...args);\n }\n\n /**\n * @param eventName\n * @param value\n * @param args\n */\n public async alterAsync<T = any>(eventName: string, value: any, ...args: any[]): Promise<T> {\n return this.#cache.alterAsync(eventName, value, ...args);\n }\n\n async destroy() {\n await this.#cache.destroy();\n }\n\n protected ensureProvider(token: TokenProvider): Provider | undefined {\n if (!this.hasProvider(token) && GlobalProviders.has(token)) {\n this.addProvider(token);\n }\n\n return this.getProvider(token)!;\n }\n\n protected getInstance(token: any) {\n return this.#cache.get(token);\n }\n\n /**\n * Invoke a class method and inject service.\n *\n * #### IInjectableMethod options\n *\n * * **target**: Optional. The class instance.\n * * **methodName**: `string` Optional. The method name.\n * * **designParamTypes**: `any[]` Optional. List of injectable types.\n * * **locals**: `Map<Function, any>` Optional. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.\n *\n * #### Example\n *\n * @param target\n * @param locals\n * @param options\n * @private\n */\n private resolve<T>(target: TokenProvider, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions<T>> = {}): Promise<T> {\n const resolvedOpts = this.mapInvokeOptions(target, locals, options);\n const {token, deps, construct, imports, provider} = resolvedOpts;\n\n if (provider) {\n GlobalProviders.onInvoke(provider, locals, {...resolvedOpts, injector: this});\n }\n\n let instance: any;\n let currentDependency: any = false;\n\n try {\n const invokeDependency =\n (parent?: any) =>\n (token: any, index: number): any => {\n currentDependency = {token, index, deps};\n\n if (token !== DI_PARAM_OPTIONS) {\n const options = provider?.store?.get(`${DI_PARAM_OPTIONS}:${index}`);\n\n locals.set(DI_PARAM_OPTIONS, options || {});\n }\n\n return isInheritedFrom(token, Provider, 1) ? provider : this.invoke(token, locals, {parent});\n };\n\n // Invoke manually imported providers\n imports.forEach(invokeDependency());\n\n // Inject dependencies\n const services = deps.map(invokeDependency(token));\n\n currentDependency = false;\n\n instance = construct(services);\n } catch (error) {\n InjectionError.throwInjectorError(token, currentDependency, error);\n }\n\n if (instance === undefined) {\n throw new InjectionError(\n token,\n `Unable to create new instance from undefined value. Check your provider declaration for ${nameOf(token)}`\n );\n }\n\n if (instance && isClass(classOf(instance))) {\n this.bindInjectableProperties(instance, locals, options);\n }\n\n if (instance && provider.hooks) {\n Object.entries(provider.hooks).forEach(([key, cb]) => {\n instance[key] = (...args: any[]) => cb(instance, ...args);\n });\n }\n\n return instance;\n }\n\n /**\n * Create options to invoke a provider or class.\n * @param token\n * @param locals\n * @param options\n */\n private mapInvokeOptions(token: TokenProvider, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions>): ResolvedInvokeOptions {\n let imports: TokenProvider[] | undefined = options.imports;\n let deps: TokenProvider[] | undefined = options.deps;\n let scope = options.scope;\n let construct;\n\n if (!token) {\n throw new UndefinedTokenError();\n }\n\n let provider: Provider;\n\n if (!this.hasProvider(token)) {\n provider = new Provider(token);\n\n this.resolvers.forEach((resolver) => {\n const result = resolver.get(token, locals.get(DI_PARAM_OPTIONS));\n\n if (result !== undefined) {\n provider.useFactory = () => result;\n }\n });\n } else {\n provider = this.getProvider(token)!;\n }\n\n scope = scope || this.scopeOf(provider);\n deps = deps || provider.deps;\n imports = imports || provider.imports;\n\n if (provider.useValue !== undefined) {\n construct = () => (isFunction(provider.useValue) ? provider.useValue() : provider.useValue);\n } else if (provider.useFactory) {\n construct = (deps: TokenProvider[]) => provider.useFactory(...deps);\n } else if (provider.useAsyncFactory) {\n construct = async (deps: TokenProvider[]) => {\n deps = await Promise.all(deps);\n return provider.useAsyncFactory(...deps);\n };\n } else {\n // useClass\n deps = deps || Metadata.getParamTypes(provider.useClass);\n construct = (deps: TokenProvider[]) => new provider.useClass(...deps);\n }\n\n return {\n token,\n scope: scope || Store.from(token).get(\"scope\") || ProviderScope.SINGLETON,\n deps: deps! || [],\n imports: imports || [],\n construct,\n provider\n };\n }\n}\n"]}
1
+ {"version":3,"file":"InjectorService.js","sourceRoot":"","sources":["../../../src/services/InjectorService.ts"],"names":[],"mappings":";;AAAA,OAAO,EACL,WAAW,EACX,UAAU,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,QAAQ,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;SACvE;QAED,OAAO;YACL,KAAK;YACL,KAAK,EAAE,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,aAAa,CAAC,SAAS;YACzE,IAAI,EAAE,IAAK,IAAI,EAAE;YACjB,OAAO,EAAE,OAAO,IAAI,EAAE;YACtB,SAAS;YACT,QAAQ;SACT,CAAC;IACJ,CAAC;CACF,CAAA;AAzpBY,eAAe;IAJ3B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,MAAM,EAAE,IAAI;KACb,CAAC;;GACW,eAAe,CAypB3B;SAzpBY,eAAe","sourcesContent":["import {\n ancestorsOf,\n catchError,\n classOf,\n deepClone,\n deepMerge,\n isClass,\n isFunction,\n isInheritedFrom,\n Metadata,\n nameOf,\n prototypeOf,\n Store\n} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants/constants\";\nimport {Configuration} from \"../decorators/configuration\";\nimport {Injectable} from \"../decorators/injectable\";\nimport {Container} from \"../domain/Container\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\nimport {LocalsContainer} from \"../domain/LocalsContainer\";\nimport {Provider} from \"../domain/Provider\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\nimport {InjectionError} from \"../errors/InjectionError\";\nimport {UndefinedTokenError} from \"../errors/UndefinedTokenError\";\nimport {DILogger} from \"../interfaces/DILogger\";\nimport {InjectableProperties, InjectablePropertyOptions, InjectablePropertyValue} from \"../interfaces/InjectableProperties\";\nimport {InterceptorContext} from \"../interfaces/InterceptorContext\";\nimport {InterceptorMethods} from \"../interfaces/InterceptorMethods\";\nimport {InvokeOptions} from \"../interfaces/InvokeOptions\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {ResolvedInvokeOptions} from \"../interfaces/ResolvedInvokeOptions\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {createContainer} from \"../utils/createContainer\";\nimport {resolveControllers} from \"../utils/resolveControllers\";\nimport {runInContext} from \"../utils/runInContext\";\nimport {DIConfiguration} from \"./DIConfiguration\";\n\n/**\n * This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.\n *\n * ### Example:\n *\n * ```typescript\n * import {InjectorService} from \"@tsed/di\";\n *\n * // Import the services (all services are decorated with @Service()\";\n * import MyService1 from \"./services/service1\";\n * import MyService2 from \"./services/service2\";\n * import MyService3 from \"./services/service3\";\n *\n * // When all services is imported you can load InjectorService.\n * const injector = new InjectorService()\n *\n * await injector.load();\n *\n * const myService1 = injector.get<MyService1>(MyServcice1);\n * ```\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n global: true\n})\nexport class InjectorService extends Container {\n public settings: DIConfiguration = new DIConfiguration();\n public logger: DILogger = console;\n public runInContext = runInContext;\n private resolvedConfiguration: boolean = false;\n #cache = new LocalsContainer();\n\n constructor() {\n super();\n this.#cache.set(InjectorService, this);\n }\n\n get resolvers() {\n return this.settings.resolvers!;\n }\n\n get scopes() {\n return this.settings.scopes || {};\n }\n\n /**\n * Retrieve default scope for a given provider.\n * @param provider\n */\n public scopeOf(provider: Provider) {\n return provider.scope || this.scopes[provider.type] || ProviderScope.SINGLETON;\n }\n\n /**\n * Clone a provider from GlobalProviders and the given token. forkProvider method build automatically the provider if the instance parameter ins't given.\n * @param token\n * @param settings\n * @deprecated\n */\n public forkProvider(token: TokenProvider, settings: Partial<ProviderOpts<any>> = {}): Provider {\n if (!this.hasProvider(token)) {\n this.addProvider(token);\n }\n\n const provider = this.getProvider(token)!;\n\n Object.assign(provider, settings);\n\n this.#cache.set(token, this.invoke(token));\n\n return provider;\n }\n\n /**\n * Return a list of instance build by the injector.\n */\n public toArray(): any[] {\n return this.#cache.toArray();\n }\n\n /**\n * Get a service or factory already constructed from his symbol or class.\n *\n * #### Example\n *\n * ```typescript\n * import {InjectorService} from \"@tsed/di\";\n * import MyService from \"./services\";\n *\n * class OtherService {\n * constructor(injectorService: InjectorService) {\n * const myService = injectorService.get<MyService>(MyService);\n * }\n * }\n * ```\n *\n * @param token The class or symbol registered in InjectorService.\n * @param options\n * @returns {boolean}\n */\n get<T = any>(token: TokenProvider, options: any = {}): T | undefined {\n const instance = this.getInstance(token);\n\n if (instance !== undefined) {\n return instance;\n }\n\n if (!this.hasProvider(token)) {\n for (const resolver of this.resolvers) {\n const result = resolver.get(token, options);\n\n if (result !== undefined) {\n return result;\n }\n }\n }\n }\n\n /**\n * Return all instance of the same provider type\n * @param type\n */\n getAll(type: string) {\n return this.getProviders(type).map((provider) => {\n return this.get(provider.token);\n });\n }\n\n /**\n * The has() method returns a boolean indicating whether an element with the specified key exists or not.\n * @returns {boolean}\n * @param token\n */\n has(token: TokenProvider): boolean {\n return this.#cache.get(token) !== undefined;\n }\n\n /**\n * Invoke the class and inject all services that required by the class constructor.\n *\n * #### Example\n *\n * ```typescript\n * import {InjectorService} from \"@tsed/di\";\n * import MyService from \"./services\";\n *\n * class OtherService {\n * constructor(injectorService: InjectorService) {\n * const myService = injectorService.invoke<MyService>(MyService);\n * }\n * }\n * ```\n *\n * @param token The injectable class to invoke. Class parameters are injected according constructor signature.\n * @param locals Optional object. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.\n * @param options\n * @returns {T} The class constructed.\n */\n public invoke<T>(\n token: TokenProvider,\n locals: Map<TokenProvider, any> = new LocalsContainer(),\n options: Partial<InvokeOptions<T>> = {}\n ): T {\n const provider = this.ensureProvider(token);\n let instance: any = undefined;\n\n !locals.has(Configuration) && locals.set(Configuration, this.settings);\n\n if (locals.has(token)) {\n return locals.get(token);\n }\n\n if (token === DI_PARAM_OPTIONS) {\n return {} as T;\n }\n\n if (!provider || options.rebuild) {\n instance = this.resolve(token, locals, options);\n\n if (this.hasProvider(token)) {\n this.#cache.set(token, instance);\n }\n\n return instance;\n }\n\n switch (this.scopeOf(provider)) {\n case ProviderScope.SINGLETON:\n if (this.has(token)) {\n return this.get<T>(token)!;\n }\n\n instance = this.resolve(token, locals, options);\n\n if (!provider.isAsync()) {\n this.#cache.set(token, instance);\n return instance;\n }\n\n // store promise to lock token in cache\n this.#cache.set(token, instance);\n\n instance = instance.then((instance: any) => {\n this.#cache.set(token, instance);\n\n return instance;\n });\n\n return instance;\n\n case ProviderScope.REQUEST:\n instance = this.resolve(token, locals, options);\n locals.set(token, instance);\n return instance;\n\n case ProviderScope.INSTANCE:\n return this.resolve(provider.provide, locals, options) as any;\n }\n\n return instance;\n }\n\n /**\n * Build only providers which are asynchronous.\n */\n async loadAsync() {\n for (const [, provider] of this) {\n if (!this.has(provider.token) && provider.isAsync()) {\n await this.invoke(provider.token);\n }\n }\n }\n\n loadSync() {\n for (const [, provider] of this) {\n if (!this.has(provider.token) && this.scopeOf(provider) === ProviderScope.SINGLETON) {\n this.invoke(provider.token);\n }\n }\n }\n\n /**\n * Boostrap injector from container and resolve configuration.\n *\n * @param container\n */\n bootstrap(container: Container = createContainer()) {\n // Clone all providers in the container\n this.addProviders(container);\n\n // Resolve all configuration\n this.resolveConfiguration();\n\n return this;\n }\n\n /**\n * Load injector from a given module\n * @param rootModule\n */\n loadModule(rootModule: TokenProvider) {\n this.settings.routes = this.settings.routes.concat(resolveControllers(this.settings));\n\n const container = createContainer();\n container.delete(rootModule);\n\n container.addProvider(rootModule, {\n type: \"server:module\",\n scope: ProviderScope.SINGLETON\n });\n\n return this.load(container);\n }\n\n /**\n * Build all providers from given container (or GlobalProviders) and emit `$onInit` event.\n *\n * @param container\n * @param rootModule\n */\n async load(container: Container = createContainer(), rootModule?: TokenProvider) {\n this.bootstrap(container);\n\n // build async and sync provider\n await this.loadAsync();\n\n if (rootModule) {\n await this.invoke(rootModule);\n }\n\n // load sync provider\n this.loadSync();\n\n await this.emit(\"$beforeInit\");\n await this.emit(\"$onInit\");\n }\n\n /**\n * Load all configurations registered on providers\n */\n resolveConfiguration() {\n if (this.resolvedConfiguration) {\n return;\n }\n const mergedConfiguration = new Map();\n\n super.forEach((provider) => {\n if (provider.configuration && provider.type !== \"server:module\") {\n Object.entries(provider.configuration).forEach(([key, value]) => {\n if (![\"resolvers\", \"mount\", \"imports\"].includes(key)) {\n value = mergedConfiguration.has(key) ? deepMerge(mergedConfiguration.get(key), value) : deepClone(value);\n mergedConfiguration.set(key, value);\n }\n });\n }\n\n if (provider.resolvers) {\n this.settings.resolvers = this.settings.resolvers.concat(provider.resolvers);\n }\n });\n\n mergedConfiguration.forEach((value, key) => {\n this.settings.set(key, deepMerge(value, this.settings.get(key)));\n });\n\n this.resolvedConfiguration = true;\n }\n\n /**\n *\n * @param instance\n * @param locals\n * @param options\n */\n public bindInjectableProperties(instance: any, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions>) {\n const properties: InjectableProperties = ancestorsOf(classOf(instance)).reduce((properties: any, target: any) => {\n const store = Store.from(target);\n\n return {\n ...properties,\n ...(store.get(INJECTABLE_PROP) || {})\n };\n }, {});\n\n Object.values(properties).forEach((definition) => {\n switch (definition.bindingType) {\n case InjectablePropertyType.METHOD:\n this.bindMethod(instance, definition);\n break;\n case InjectablePropertyType.PROPERTY:\n this.bindProperty(instance, definition, locals, options);\n break;\n case InjectablePropertyType.CONSTANT:\n this.bindConstant(instance, definition);\n break;\n case InjectablePropertyType.VALUE:\n this.bindValue(instance, definition);\n break;\n case InjectablePropertyType.INTERCEPTOR:\n this.bindInterceptor(instance, definition);\n break;\n }\n });\n }\n\n /**\n *\n * @param instance\n * @param {string} propertyKey\n */\n public bindMethod(instance: any, {propertyKey}: InjectablePropertyOptions) {\n const target = classOf(instance);\n const originalMethod = instance[propertyKey];\n const deps = Metadata.getParamTypes(prototypeOf(target), propertyKey);\n\n instance[propertyKey] = () => {\n const services = deps.map((dependency: any) => this.get(dependency));\n\n return originalMethod.call(instance, ...services);\n };\n }\n\n /**\n * Create an injectable property.\n *\n * @param instance\n * @param {string} propertyKey\n * @param {any} useType\n * @param resolver\n * @param options\n * @param locals\n * @param invokeOptions\n */\n public bindProperty(\n instance: any,\n {propertyKey, resolver, options = {}}: InjectablePropertyOptions,\n locals: Map<TokenProvider, any>,\n invokeOptions: Partial<InvokeOptions>\n ) {\n let get: () => any;\n\n get = resolver(this, locals, {...invokeOptions, options});\n\n catchError(() =>\n Object.defineProperty(instance, propertyKey, {\n get\n })\n );\n }\n\n /**\n *\n * @param instance\n * @param {string} propertyKey\n * @param {any} useType\n */\n public bindValue(instance: any, {propertyKey, expression, defaultValue}: InjectablePropertyValue) {\n const descriptor = {\n get: () => this.settings.get(expression) || defaultValue,\n set: (value: any) => this.settings.set(expression, value),\n enumerable: true,\n configurable: true\n };\n\n catchError(() => Object.defineProperty(instance, propertyKey, descriptor));\n }\n\n /**\n *\n * @param instance\n * @param {string} propertyKey\n * @param {any} useType\n */\n public bindConstant(instance: any, {propertyKey, expression, defaultValue}: InjectablePropertyValue) {\n let bean: any;\n\n const get = () => {\n if (bean !== undefined) {\n return bean;\n }\n\n const value = this.settings.get(expression, defaultValue);\n bean = Object.freeze(deepClone(value));\n\n return bean;\n };\n\n const descriptor = {\n get,\n enumerable: true,\n configurable: true\n };\n\n catchError(() => Object.defineProperty(instance, propertyKey, descriptor));\n }\n\n /**\n *\n * @param instance\n * @param propertyKey\n * @param useType\n * @param options\n */\n public bindInterceptor(instance: any, {propertyKey, useType, options}: InjectablePropertyOptions) {\n const target = classOf(instance);\n const originalMethod = instance[propertyKey];\n\n instance[propertyKey] = (...args: any[]) => {\n const next = (err?: Error) => {\n if (!err) {\n return originalMethod.apply(instance, args);\n }\n\n throw err;\n };\n\n const context: InterceptorContext<any> = {\n target,\n propertyKey,\n args,\n options,\n next\n };\n\n const interceptor = this.get<InterceptorMethods>(useType)!;\n\n return interceptor.intercept!(\n {\n ...context,\n options\n },\n next\n );\n };\n }\n\n async lazyInvoke<T = any>(token: TokenProvider) {\n let instance = this.getInstance(token);\n\n if (!instance) {\n instance = await this.invoke<T>(token);\n\n if (isFunction(instance?.$onInit)) {\n await instance.$onInit();\n }\n }\n\n return instance;\n }\n\n /**\n * Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).\n * @param eventName The event name to emit at all services.\n * @param args List of the parameters to give to each services.\n * @returns {Promise<any[]>} A list of promises.\n */\n public async emit(eventName: string, ...args: any[]) {\n return this.#cache.emit(eventName, ...args);\n }\n\n /**\n * @param eventName\n * @param value\n * @param args\n */\n public alter<T = any>(eventName: string, value: any, ...args: any[]): T {\n return this.#cache.alter(eventName, value, ...args);\n }\n\n /**\n * @param eventName\n * @param value\n * @param args\n */\n public async alterAsync<T = any>(eventName: string, value: any, ...args: any[]): Promise<T> {\n return this.#cache.alterAsync(eventName, value, ...args);\n }\n\n async destroy() {\n await this.#cache.destroy();\n }\n\n protected ensureProvider(token: TokenProvider): Provider | undefined {\n if (!this.hasProvider(token) && GlobalProviders.has(token)) {\n this.addProvider(token);\n }\n\n return this.getProvider(token)!;\n }\n\n protected getInstance(token: any) {\n return this.#cache.get(token);\n }\n\n /**\n * Invoke a class method and inject service.\n *\n * #### IInjectableMethod options\n *\n * * **target**: Optional. The class instance.\n * * **methodName**: `string` Optional. The method name.\n * * **designParamTypes**: `any[]` Optional. List of injectable types.\n * * **locals**: `Map<Function, any>` Optional. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.\n *\n * #### Example\n *\n * @param target\n * @param locals\n * @param options\n * @private\n */\n private resolve<T>(target: TokenProvider, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions<T>> = {}): T | Promise<T> {\n const resolvedOpts = this.mapInvokeOptions(target, locals, options);\n const {token, deps, construct, imports, provider} = resolvedOpts;\n\n if (provider) {\n GlobalProviders.onInvoke(provider, locals, {...resolvedOpts, injector: this});\n }\n\n let instance: any;\n let currentDependency: any = false;\n\n try {\n const invokeDependency =\n (parent?: any) =>\n (token: any, index: number): any => {\n currentDependency = {token, index, deps};\n\n if (token !== DI_PARAM_OPTIONS) {\n const options = provider?.store?.get(`${DI_PARAM_OPTIONS}:${index}`);\n\n locals.set(DI_PARAM_OPTIONS, options || {});\n }\n\n return isInheritedFrom(token, Provider, 1) ? provider : this.invoke(token, locals, {parent});\n };\n\n // Invoke manually imported providers\n imports.forEach(invokeDependency());\n\n // Inject dependencies\n const services = deps.map(invokeDependency(token));\n\n currentDependency = false;\n\n instance = construct(services);\n } catch (error) {\n InjectionError.throwInjectorError(token, currentDependency, error);\n }\n\n if (instance === undefined) {\n throw new InjectionError(\n token,\n `Unable to create new instance from undefined value. Check your provider declaration for ${nameOf(token)}`\n );\n }\n\n if (instance && isClass(classOf(instance))) {\n this.bindInjectableProperties(instance, locals, options);\n }\n\n if (instance && provider.hooks) {\n Object.entries(provider.hooks).forEach(([key, cb]) => {\n instance[key] = (...args: any[]) => cb(instance, ...args);\n });\n }\n\n return instance;\n }\n\n /**\n * Create options to invoke a provider or class.\n * @param token\n * @param locals\n * @param options\n */\n private mapInvokeOptions(token: TokenProvider, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions>): ResolvedInvokeOptions {\n let imports: TokenProvider[] | undefined = options.imports;\n let deps: TokenProvider[] | undefined = options.deps;\n let scope = options.scope;\n let construct;\n\n if (!token) {\n throw new UndefinedTokenError();\n }\n\n let provider: Provider;\n\n if (!this.hasProvider(token)) {\n provider = new Provider(token);\n\n this.resolvers.forEach((resolver) => {\n const result = resolver.get(token, locals.get(DI_PARAM_OPTIONS));\n\n if (result !== undefined) {\n provider.useFactory = () => result;\n }\n });\n } else {\n provider = this.getProvider(token)!;\n }\n\n scope = scope || this.scopeOf(provider);\n deps = deps || provider.deps;\n imports = imports || provider.imports;\n\n if (provider.useValue !== undefined) {\n construct = () => (isFunction(provider.useValue) ? provider.useValue() : provider.useValue);\n } else if (provider.useFactory) {\n construct = (deps: TokenProvider[]) => provider.useFactory(...deps);\n } else if (provider.useAsyncFactory) {\n construct = async (deps: TokenProvider[]) => {\n deps = await Promise.all(deps);\n return provider.useAsyncFactory(...deps);\n };\n } else {\n // useClass\n deps = deps || Metadata.getParamTypes(provider.useClass);\n construct = (deps: TokenProvider[]) => new provider.useClass(...deps);\n }\n\n return {\n token,\n scope: scope || Store.from(token).get(\"scope\") || ProviderScope.SINGLETON,\n deps: deps! || [],\n imports: imports || [],\n construct,\n provider\n };\n }\n}\n"]}
@@ -62,5 +62,6 @@ export declare class DIContext extends Map<any, any> implements ContextMethods {
62
62
  get env(): any;
63
63
  destroy(): Promise<void>;
64
64
  emit(eventName: string, ...args: any[]): Promise<void>;
65
+ runInContext(next: Function): Promise<any>;
65
66
  }
66
67
  export declare type BaseContext = DIContext & TsED.Context;
@@ -27,6 +27,7 @@ export * from "./domain/ProviderScope";
27
27
  export * from "./domain/ProviderType";
28
28
  export * from "./errors/InjectionError";
29
29
  export * from "./errors/UndefinedTokenError";
30
+ export * from "./interfaces/AlterRunInContext";
30
31
  export * from "./interfaces/DIConfigurationOptions";
31
32
  export * from "./interfaces/DILogger";
32
33
  export * from "./interfaces/DILoggerOptions";
@@ -0,0 +1,4 @@
1
+ import { DIContext } from "../domain/DIContext";
2
+ export interface AlterRunInContext {
3
+ $alterRunInContext(next: (...args: unknown[]) => unknown, ctx: DIContext): () => unknown | Promise<() => unknown>;
4
+ }
@@ -1,14 +1,13 @@
1
1
  import { Container } from "../domain/Container";
2
- import { LocalsContainer } from "../domain/LocalsContainer";
3
2
  import { Provider } from "../domain/Provider";
4
- import { DIConfiguration } from "./DIConfiguration";
5
3
  import { ProviderScope } from "../domain/ProviderScope";
6
4
  import { DILogger } from "../interfaces/DILogger";
7
- import { TokenProvider } from "../interfaces/TokenProvider";
8
- import { ProviderOpts } from "../interfaces/ProviderOpts";
9
- import { InvokeOptions } from "../interfaces/InvokeOptions";
10
5
  import { InjectablePropertyOptions, InjectablePropertyValue } from "../interfaces/InjectableProperties";
6
+ import { InvokeOptions } from "../interfaces/InvokeOptions";
7
+ import { ProviderOpts } from "../interfaces/ProviderOpts";
8
+ import { TokenProvider } from "../interfaces/TokenProvider";
11
9
  import { runInContext } from "../utils/runInContext";
10
+ import { DIConfiguration } from "./DIConfiguration";
12
11
  /**
13
12
  * This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.
14
13
  *
@@ -112,8 +111,8 @@ export declare class InjectorService extends Container {
112
111
  /**
113
112
  * Build only providers which are asynchronous.
114
113
  */
115
- loadAsync(locals?: LocalsContainer): Promise<LocalsContainer<any>>;
116
- loadSync(locals?: LocalsContainer): LocalsContainer<any>;
114
+ loadAsync(): Promise<void>;
115
+ loadSync(): void;
117
116
  /**
118
117
  * Boostrap injector from container and resolve configuration.
119
118
  *
@@ -124,14 +123,14 @@ export declare class InjectorService extends Container {
124
123
  * Load injector from a given module
125
124
  * @param rootModule
126
125
  */
127
- loadModule(rootModule: TokenProvider): Promise<LocalsContainer<any>>;
126
+ loadModule(rootModule: TokenProvider): Promise<void>;
128
127
  /**
129
128
  * Build all providers from given container (or GlobalProviders) and emit `$onInit` event.
130
129
  *
131
130
  * @param container
132
131
  * @param rootModule
133
132
  */
134
- load(container?: Container, rootModule?: TokenProvider): Promise<LocalsContainer<any>>;
133
+ load(container?: Container, rootModule?: TokenProvider): Promise<void>;
135
134
  /**
136
135
  * Load all configurations registered on providers
137
136
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/di",
3
- "version": "6.114.18",
3
+ "version": "6.116.0",
4
4
  "description": "DI module for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -24,14 +24,14 @@
24
24
  "tslib": "2.4.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@tsed/core": "6.114.18",
27
+ "@tsed/core": "6.116.0",
28
28
  "@tsed/logger": ">=6.1.4",
29
- "@tsed/schema": "6.114.18"
29
+ "@tsed/schema": "6.116.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "@tsed/core": "^6.114.18",
32
+ "@tsed/core": "^6.116.0",
33
33
  "@tsed/logger": ">=6.1.4",
34
- "@tsed/schema": "^6.114.18"
34
+ "@tsed/schema": "^6.116.0"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@tsed/core": {