@tsed/di 6.68.1 → 6.69.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/lib/index.js +2537 -23
  2. package/lib/index.js.map +1 -1
  3. package/lib/index.modern.js +2474 -0
  4. package/lib/index.modern.js.map +1 -0
  5. package/lib/registries/GlobalProviders.d.ts +1 -1
  6. package/package.json +11 -8
  7. package/lib/constants/index.js +0 -7
  8. package/lib/constants/index.js.map +0 -1
  9. package/lib/decorators/configuration.js +0 -24
  10. package/lib/decorators/configuration.js.map +0 -1
  11. package/lib/decorators/constant.js +0 -55
  12. package/lib/decorators/constant.js.map +0 -1
  13. package/lib/decorators/index.js +0 -17
  14. package/lib/decorators/index.js.map +0 -1
  15. package/lib/decorators/inject.js +0 -60
  16. package/lib/decorators/inject.js.map +0 -1
  17. package/lib/decorators/injectable.js +0 -33
  18. package/lib/decorators/injectable.js.map +0 -1
  19. package/lib/decorators/intercept.js +0 -28
  20. package/lib/decorators/intercept.js.map +0 -1
  21. package/lib/decorators/interceptor.js +0 -21
  22. package/lib/decorators/interceptor.js.map +0 -1
  23. package/lib/decorators/module.js +0 -31
  24. package/lib/decorators/module.js.map +0 -1
  25. package/lib/decorators/opts.js +0 -54
  26. package/lib/decorators/opts.js.map +0 -1
  27. package/lib/decorators/overrideProvider.js +0 -17
  28. package/lib/decorators/overrideProvider.js.map +0 -1
  29. package/lib/decorators/scope.js +0 -16
  30. package/lib/decorators/scope.js.map +0 -1
  31. package/lib/decorators/service.js +0 -18
  32. package/lib/decorators/service.js.map +0 -1
  33. package/lib/decorators/useOpts.js +0 -65
  34. package/lib/decorators/useOpts.js.map +0 -1
  35. package/lib/decorators/value.js +0 -55
  36. package/lib/decorators/value.js.map +0 -1
  37. package/lib/domain/Container.js +0 -69
  38. package/lib/domain/Container.js.map +0 -1
  39. package/lib/domain/ContextLogger.js +0 -92
  40. package/lib/domain/ContextLogger.js.map +0 -1
  41. package/lib/domain/DIContext.js +0 -45
  42. package/lib/domain/DIContext.js.map +0 -1
  43. package/lib/domain/InjectablePropertyType.js +0 -12
  44. package/lib/domain/InjectablePropertyType.js.map +0 -1
  45. package/lib/domain/LocalsContainer.js +0 -55
  46. package/lib/domain/LocalsContainer.js.map +0 -1
  47. package/lib/domain/Provider.js +0 -173
  48. package/lib/domain/Provider.js.map +0 -1
  49. package/lib/domain/ProviderScope.js +0 -10
  50. package/lib/domain/ProviderScope.js.map +0 -1
  51. package/lib/domain/ProviderType.js +0 -15
  52. package/lib/domain/ProviderType.js.map +0 -1
  53. package/lib/domain/index.js +0 -12
  54. package/lib/domain/index.js.map +0 -1
  55. package/lib/errors/InjectionError.js +0 -59
  56. package/lib/errors/InjectionError.js.map +0 -1
  57. package/lib/errors/UndefinedTokenError.js +0 -11
  58. package/lib/errors/UndefinedTokenError.js.map +0 -1
  59. package/lib/interfaces/DIConfigurationOptions.js +0 -3
  60. package/lib/interfaces/DIConfigurationOptions.js.map +0 -1
  61. package/lib/interfaces/DILogger.js +0 -3
  62. package/lib/interfaces/DILogger.js.map +0 -1
  63. package/lib/interfaces/DIResolver.js +0 -3
  64. package/lib/interfaces/DIResolver.js.map +0 -1
  65. package/lib/interfaces/IProvider.js +0 -3
  66. package/lib/interfaces/IProvider.js.map +0 -1
  67. package/lib/interfaces/InjectableProperties.js +0 -3
  68. package/lib/interfaces/InjectableProperties.js.map +0 -1
  69. package/lib/interfaces/InterceptorContext.js +0 -3
  70. package/lib/interfaces/InterceptorContext.js.map +0 -1
  71. package/lib/interfaces/InterceptorMethods.js +0 -3
  72. package/lib/interfaces/InterceptorMethods.js.map +0 -1
  73. package/lib/interfaces/InvokeOptions.js +0 -3
  74. package/lib/interfaces/InvokeOptions.js.map +0 -1
  75. package/lib/interfaces/OnDestroy.js +0 -3
  76. package/lib/interfaces/OnDestroy.js.map +0 -1
  77. package/lib/interfaces/OnInit.js +0 -3
  78. package/lib/interfaces/OnInit.js.map +0 -1
  79. package/lib/interfaces/RegistrySettings.js +0 -3
  80. package/lib/interfaces/RegistrySettings.js.map +0 -1
  81. package/lib/interfaces/TokenProvider.js +0 -3
  82. package/lib/interfaces/TokenProvider.js.map +0 -1
  83. package/lib/interfaces/index.js +0 -17
  84. package/lib/interfaces/index.js.map +0 -1
  85. package/lib/registries/GlobalProviders.js +0 -124
  86. package/lib/registries/GlobalProviders.js.map +0 -1
  87. package/lib/registries/ProviderRegistry.js +0 -181
  88. package/lib/registries/ProviderRegistry.js.map +0 -1
  89. package/lib/services/DIConfiguration.js +0 -129
  90. package/lib/services/DIConfiguration.js.map +0 -1
  91. package/lib/services/DILogger.js +0 -13
  92. package/lib/services/DILogger.js.map +0 -1
  93. package/lib/services/DITest.js +0 -100
  94. package/lib/services/DITest.js.map +0 -1
  95. package/lib/services/InjectorService.js +0 -543
  96. package/lib/services/InjectorService.js.map +0 -1
  97. package/lib/utils/cleanGlobPatterns.js +0 -30
  98. package/lib/utils/cleanGlobPatterns.js.map +0 -1
  99. package/lib/utils/createContainer.js +0 -14
  100. package/lib/utils/createContainer.js.map +0 -1
  101. package/lib/utils/data/Test1.d.ts +0 -3
  102. package/lib/utils/data/Test1.js +0 -8
  103. package/lib/utils/data/Test1.js.map +0 -1
  104. package/lib/utils/data/Test2.d.ts +0 -3
  105. package/lib/utils/data/Test2.js +0 -8
  106. package/lib/utils/data/Test2.js.map +0 -1
  107. package/lib/utils/getConfiguration.js +0 -20
  108. package/lib/utils/getConfiguration.js.map +0 -1
  109. package/lib/utils/importComponents.js +0 -50
  110. package/lib/utils/importComponents.js.map +0 -1
  111. package/lib/utils/importFiles.js +0 -28
  112. package/lib/utils/importFiles.js.map +0 -1
  113. package/lib/utils/importProviders.js +0 -29
  114. package/lib/utils/importProviders.js.map +0 -1
  115. package/lib/utils/setLoggerLevel.js +0 -16
  116. package/lib/utils/setLoggerLevel.js.map +0 -1
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC;AAClC,mDAAyB;AACzB,uDAA6B;AAC7B,uDAA6B;AAC7B,wEAA8C;AAC9C,uEAA6C;AAE7C,qEAA2C;AAC3C,8DAAoC;AACpC,qEAA2C;AAC3C,4DAAkC;AAElC,kEAAwC;AACxC,uEAA6C;AAE7C,kEAAwC;AACxC,8DAAoC;AACpC,mEAAyC;AACzC,mEAAyC;AACzC,mEAAyC;AACzC,kEAAwC;AACxC,iEAAuC","sourcesContent":["export * from \"./constants/index\";\nexport * from \"./domain\";\nexport * from \"./interfaces\";\nexport * from \"./decorators\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./registries/GlobalProviders\";\n\nexport * from \"./services/InjectorService\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DITest\";\n\nexport * from \"./errors/InjectionError\";\nexport * from \"./errors/UndefinedTokenError\";\n\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/importFiles\";\nexport * from \"./utils/importComponents\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/importProviders\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
1
+ {"version":3,"file":"index.js","sources":["../src/constants/index.ts","../src/domain/ProviderScope.ts","../src/domain/ProviderType.ts","../src/domain/Provider.ts","../src/registries/GlobalProviders.ts","../src/domain/LocalsContainer.ts","../src/domain/Container.ts","../src/domain/InjectablePropertyType.ts","../src/domain/ContextLogger.ts","../src/domain/DIContext.ts","../src/decorators/scope.ts","../src/registries/ProviderRegistry.ts","../src/decorators/injectable.ts","../src/decorators/service.ts","../src/decorators/overrideProvider.ts","../src/decorators/inject.ts","../src/decorators/constant.ts","../src/decorators/value.ts","../src/decorators/intercept.ts","../src/decorators/interceptor.ts","../src/decorators/configuration.ts","../src/decorators/module.ts","../src/decorators/opts.ts","../src/decorators/useOpts.ts","../src/errors/InjectionError.ts","../src/errors/UndefinedTokenError.ts","../src/utils/createContainer.ts","../src/services/DIConfiguration.ts","../src/services/InjectorService.ts","../src/services/DILogger.ts","../src/utils/setLoggerLevel.ts","../src/services/DITest.ts","../src/utils/cleanGlobPatterns.ts","../src/utils/importFiles.ts","../src/utils/importComponents.ts","../src/utils/getConfiguration.ts","../src/utils/importProviders.ts"],"sourcesContent":["export const INJECTABLE_PROP = \"DI:INJECTABLE_PROP\";\nexport const DI_PARAMS = \"DI:PARAMS\";\nexport const DI_PARAM_OPTIONS = \"DI:PARAM:OPTIONS\";\n","export enum ProviderScope {\n SINGLETON = \"singleton\",\n REQUEST = \"request\",\n INSTANCE = \"instance\"\n}\n","export enum ProviderType {\n VALUE = \"value\",\n FACTORY = \"factory\",\n SERVICE = \"service\",\n PROVIDER = \"provider\",\n MODULE = \"module\",\n CONTROLLER = \"controller\",\n INTERCEPTOR = \"interceptor\",\n MIDDLEWARE = \"middleware\"\n}\n","import {classOf, Enumerable, getEnumerableKeys, isClass, nameOf, NotEnumerable, Store, Type} from \"@tsed/core\";\nimport {IProvider, TokenProvider} from \"../interfaces\";\nimport {ProviderScope} from \"./ProviderScope\";\nimport {ProviderType} from \"./ProviderType\";\n\nexport class Provider<T = any> implements IProvider<T> {\n @Enumerable()\n public type: ProviderType | any = ProviderType.PROVIDER;\n\n @Enumerable()\n public injectable: boolean = true;\n\n @Enumerable()\n public instance: T;\n\n @Enumerable()\n public deps: TokenProvider[];\n\n @Enumerable()\n public imports: any[];\n\n @Enumerable()\n public useFactory: Function;\n\n @Enumerable()\n public useAsyncFactory: Function;\n\n @Enumerable()\n public useValue: any;\n\n @NotEnumerable()\n protected _provide: TokenProvider;\n\n @NotEnumerable()\n protected _useClass: Type<T>;\n\n @NotEnumerable()\n protected _instance: T;\n\n @NotEnumerable()\n private _store: Store;\n\n @NotEnumerable()\n private _tokenStore: Store;\n\n [key: string]: any;\n\n constructor(token: TokenProvider) {\n this.provide = token;\n this.useClass = token;\n }\n\n get token() {\n return this._provide;\n }\n\n get provide(): TokenProvider {\n return this._provide;\n }\n\n set provide(value: TokenProvider) {\n if (value) {\n this._provide = isClass(value) ? classOf(value) : value;\n this._tokenStore = this._store = Store.from(value);\n }\n }\n\n get useClass(): Type<T> {\n return this._useClass;\n }\n\n /**\n * Create a new store if the given value is a class. Otherwise the value is ignored.\n * @param value\n */\n @Enumerable()\n set useClass(value: Type<T>) {\n if (isClass(value)) {\n this._useClass = classOf(value);\n this._store = Store.from(value);\n }\n }\n\n get className() {\n return this.name;\n }\n\n get name() {\n return nameOf(this.provide);\n }\n\n public get store(): Store {\n return this._store;\n }\n\n /**\n * Get the scope of the provider.\n *\n * ::: tip Note\n * Async provider is always a SINGLETON\n * :::\n *\n * @returns {boolean}\n */\n get scope(): ProviderScope {\n if (this.isAsync()) {\n return ProviderScope.SINGLETON;\n }\n\n return this.get(\"scope\");\n }\n\n /**\n * Change the scope value of the provider.\n * @param scope\n */\n @Enumerable()\n set scope(scope: ProviderScope) {\n this.store.set(\"scope\", scope);\n }\n\n get configuration(): Partial<TsED.Configuration> {\n return this.get(\"configuration\");\n }\n\n @Enumerable()\n set configuration(configuration: Partial<TsED.Configuration>) {\n this.store.set(\"configuration\", configuration);\n }\n\n get(key: string) {\n return this.store.get(key) || this._tokenStore.get(key);\n }\n\n isAsync(): boolean {\n return !!this.useAsyncFactory;\n }\n\n clone(): Provider<any> {\n const provider = new (classOf(this))(this.token);\n\n getEnumerableKeys(this).forEach((key) => {\n if (this[key] !== undefined) {\n provider[key] = this[key];\n }\n });\n\n return provider;\n }\n\n toString() {\n return [\n \"Token\",\n this.name,\n this.useClass && nameOf(this.useClass),\n this.useFactory && \"Factory\",\n this.useValue && \"Value\",\n this.useAsyncFactory && \"AsyncFactory\"\n ]\n .filter(Boolean)\n .join(\":\");\n }\n}\n","import {getClassOrSymbol, Type} from \"@tsed/core\";\nimport type {IProvider, RegistrySettings, TokenProvider} from \"../interfaces\";\nimport {Provider} from \"../domain/Provider\";\nimport {ProviderType} from \"../domain/ProviderType\";\n\nexport class GlobalProviderRegistry extends Map<TokenProvider, Provider> {\n #settings: Map<string, RegistrySettings> = new Map();\n\n /**\n * The get() method returns a specified element from a Map object.\n * @param key Required. The key of the element to return from the Map object.\n * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.\n */\n get(key: TokenProvider): Provider | undefined {\n return super.get(getClassOrSymbol(key));\n }\n\n /**\n * The has() method returns a boolean indicating whether an element with the specified key exists or not.\n * @param key\n * @returns {boolean}\n */\n has(key: TokenProvider): boolean {\n return super.has(getClassOrSymbol(key));\n }\n\n /**\n * The set() method adds or updates an element with a specified key and value to a Map object.\n * @param key Required. The key of the element to add to the Map object.\n * @param metadata Required. The value of the element to add to the Map object.\n */\n set(key: TokenProvider, metadata: Provider): this {\n super.set(getClassOrSymbol(key), metadata);\n\n return this;\n }\n\n /**\n *\n * @param target\n * @param options\n */\n merge(target: TokenProvider, options: Partial<IProvider>): void {\n const meta = this.createIfNotExists(target, options);\n\n Object.keys(options).forEach((key) => {\n meta[key] = (options as any)[key];\n });\n\n this.set(target, meta);\n }\n\n /**\n * The delete() method removes the specified element from a Map object.\n * @param key Required. The key of the element to remove from the Map object.\n * @returns {boolean} Returns true if an element in the Map object existed and has been removed, or false if the element does not exist.\n */\n delete(key: TokenProvider): boolean {\n return super.delete(getClassOrSymbol(key));\n }\n\n createRegistry(type: string, model: Type<Provider>, options: Partial<RegistrySettings> = {injectable: true}) {\n const defaultOptions = this.getRegistrySettings(type);\n\n options = Object.assign(defaultOptions, {\n ...options,\n model\n });\n\n this.#settings.set(type, options);\n\n return this;\n }\n\n getRegistrySettings(target: string | TokenProvider): RegistrySettings {\n let type: string = \"provider\";\n\n if (typeof target === \"string\") {\n type = target;\n } else {\n const provider = this.get(target);\n if (provider) {\n type = provider.type;\n }\n }\n\n return (\n this.#settings.get(type) || {\n model: Provider,\n injectable: true\n }\n );\n }\n\n createRegisterFn(type: string) {\n return (provider: any | IProvider, instance?: any): void => {\n if (!provider.provide) {\n provider = {\n provide: provider\n };\n }\n\n provider = Object.assign({instance}, provider, {type});\n this.merge(provider.provide, provider);\n };\n }\n\n /**\n * @deprecated\n */\n // istanbul ignore next\n getRegistry(target: string | TokenProvider) {\n return this;\n }\n\n /**\n *\n * @param key\n * @param options\n */\n protected createIfNotExists(key: TokenProvider, options: Partial<IProvider>): Provider {\n const type = options.type || ProviderType.PROVIDER;\n\n if (!this.has(key)) {\n const {model = Provider} = this.#settings.get(type) || {};\n\n const item = new model(key);\n\n this.set(key, item);\n }\n\n return this.get(key)!;\n }\n}\n\n/**\n *\n * @type {GlobalProviders}\n */\n// tslint:disable-next-line: variable-name\nexport const GlobalProviders = new GlobalProviderRegistry();\n","import {TokenProvider} from \"../interfaces/TokenProvider\";\n\nexport class LocalsContainer<V = any> extends Map<TokenProvider, V> {\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 for (const handler of this.getListeners(eventName)) {\n await handler(...args);\n }\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 for (const handler of this.getListeners(eventName)) {\n value = handler(value, ...args);\n }\n\n return value;\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 for (const handler of this.getListeners(eventName)) {\n value = handler(value, ...args);\n }\n\n return value;\n }\n\n toArray() {\n return [...this.values()];\n }\n\n async destroy() {\n await this.emit(\"$onDestroy\");\n this.clear();\n }\n\n protected getListeners(event: string): any[] {\n return this.toArray().reduce((listeners, instance) => {\n if (typeof instance === \"object\" && instance && event in instance) {\n return listeners.concat((instance as any)[event].bind(instance));\n }\n\n return listeners;\n }, []);\n }\n}\n","import {IProvider} from \"../interfaces/IProvider\";\nimport {ProviderType} from \"./ProviderType\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {LocalsContainer} from \"./LocalsContainer\";\nimport {Provider} from \"./Provider\";\n\nexport class Container extends LocalsContainer<Provider> {\n /**\n *\n * @param token\n * @param settings\n */\n public add(token: TokenProvider, settings: Partial<IProvider> = {}): this {\n const provider = GlobalProviders.has(token) ? GlobalProviders.get(token)!.clone() : new Provider(token);\n\n Object.assign(provider, settings);\n\n return super.set(token, provider);\n }\n\n /**\n * Add a provider to the\n * @param token\n * @param settings\n */\n public addProvider(token: TokenProvider, settings: Partial<IProvider> = {}): this {\n return this.add(token, settings);\n }\n\n /**\n *\n * @param token\n */\n public hasProvider(token: TokenProvider) {\n return super.has(token);\n }\n\n /**\n * Add a provider to the\n * @param token\n * @param provider\n */\n public setProvider(token: TokenProvider, provider: Provider) {\n return super.set(token, provider);\n }\n\n /**\n * The getProvider() method returns a specified element from a Map object.\n * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.\n * @param token\n */\n public getProvider(token: TokenProvider): Provider | undefined {\n return super.get(token);\n }\n\n /**\n * Get all providers registered in the injector container.\n *\n * @param {ProviderType} type Filter the list by the given ProviderType.\n * @returns {[TokenProvider , Provider<any>][]}\n */\n public getProviders(type?: ProviderType | string): Provider[] {\n return Array.from(this)\n .filter(([_, provider]) => (type ? provider.type === type : true))\n .map(([_, provider]) => provider);\n }\n\n public addProviders(container: Map<TokenProvider, Provider>) {\n container.forEach((provider) => {\n if (!this.hasProvider(provider.provide)) {\n this.setProvider(provider.provide, provider.clone());\n }\n });\n }\n}\n","export enum InjectablePropertyType {\n METHOD = \"method\",\n PROPERTY = \"property\",\n CONSTANT = \"constant\",\n VALUE = \"value\",\n INTERCEPTOR = \"interceptor\"\n}\n","import {levels, LogLevel} from \"@tsed/logger\";\n\nexport interface ContextLoggerOptions extends Record<string, any> {\n id: string;\n url?: string;\n dateStart?: Date;\n level?: \"debug\" | \"info\" | \"warn\" | \"error\" | \"off\" | \"all\";\n maxStackSize?: number;\n minimalRequestPicker?: (o: any) => any;\n completeRequestPicker?: (o: any) => any;\n ignoreLog?: (data: any) => boolean;\n additionalProps?: Record<any, any>;\n}\n\nexport class ContextLogger {\n id: string;\n url: string;\n minimalRequestPicker: Function;\n completeRequestPicker: Function;\n maxStackSize: number;\n readonly #additionalProps: Record<string, unknown>;\n readonly #dateStart: Date;\n readonly #ignoreLog: (data: any) => boolean;\n #stack: any = [];\n #level: LogLevel;\n\n constructor(\n private logger: any,\n {\n id,\n url = \"\",\n dateStart = new Date(),\n ignoreUrlPatterns = [],\n minimalRequestPicker,\n completeRequestPicker,\n level = \"all\",\n maxStackSize = 30,\n ignoreLog,\n additionalProps\n }: ContextLoggerOptions\n ) {\n this.id = id;\n this.url = url;\n this.#additionalProps = additionalProps || {};\n this.#dateStart = dateStart;\n this.#ignoreLog = ignoreLog || (() => false);\n this.minimalRequestPicker = minimalRequestPicker || ((l: any) => l);\n this.completeRequestPicker = completeRequestPicker || ((l: any) => l);\n // @ts-ignore\n this.#level = levels()[level.toUpperCase()] || levels().ALL;\n this.maxStackSize = maxStackSize;\n }\n\n info(obj: any) {\n this.run(levels().INFO, obj, (obj) => this.minimalRequestPicker(this.getData(obj)));\n return this;\n }\n\n debug(obj: any, withRequest: boolean = true) {\n this.run(levels().DEBUG, obj, (obj) => {\n obj = this.getData(obj);\n return withRequest ? this.completeRequestPicker(obj) : obj;\n });\n return this;\n }\n\n warn(obj: any) {\n this.run(levels().WARN, obj, (obj) => this.completeRequestPicker(this.getData(obj)));\n return this;\n }\n\n error(obj: any) {\n this.run(levels().ERROR, obj, (obj) => this.completeRequestPicker(this.getData(obj)));\n return this;\n }\n\n trace(obj: any) {\n this.run(levels().TRACE, obj, (obj) => this.completeRequestPicker(this.getData(obj)));\n return this;\n }\n\n public flush() {\n if (this.#stack.length) {\n this.#stack.forEach(({level, data}: any) => {\n this.logger[level](data);\n });\n\n this.#stack = [];\n }\n }\n\n public isLevelEnabled(otherLevel: string | LogLevel) {\n return this.#level.isLessThanOrEqualTo(otherLevel);\n }\n\n destroy() {\n this.flush();\n\n this.logger = undefined;\n this.#stack = undefined;\n }\n\n /**\n * Return the duration between the time when LogIncomingRequest has handle the request and now.\n * @returns {number}\n */\n protected getDuration(): number {\n return new Date().getTime() - this.#dateStart.getTime();\n }\n\n protected getData(obj: any) {\n if (typeof obj === \"string\") {\n obj = {message: obj};\n }\n\n return {...this.#additionalProps, reqId: this.id, time: new Date(), duration: this.getDuration(), ...obj};\n }\n\n protected run(level: LogLevel, obj: any, mapper: (data: any) => any) {\n if (!this.isLevelEnabled(level)) {\n return;\n }\n\n if (!this.#ignoreLog(obj)) {\n this.#stack.push({level: level.levelStr.toLowerCase(), data: mapper(obj)});\n }\n\n if (this.maxStackSize < this.#stack.length) {\n this.flush();\n }\n }\n}\n","import {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\ndeclare global {\n namespace TsED {\n interface Context {}\n }\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 public logger: ContextLogger;\n /**\n *\n */\n public 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.env;\n }\n\n async destroy() {\n await this.container.destroy();\n this.logger.destroy();\n // @ts-ignore\n delete this.container;\n // @ts-ignore\n delete this.logger;\n // @ts-ignore\n delete this.injector;\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","import {StoreSet} from \"@tsed/core\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\n\n/**\n *\n * @param {\"request\" | \"singleton\" | ProviderScope} scope\n * @returns {Function}\n * @constructor\n */\nexport function Scope(scope: \"request\" | \"singleton\" | ProviderScope = ProviderScope.REQUEST) {\n return StoreSet(\"scope\", scope);\n}\n","import {Provider} from \"../domain/Provider\";\nimport type {IProvider} from \"../interfaces\";\nimport {ProviderScope, ProviderType} from \"../domain\";\nimport {GlobalProviders} from \"./GlobalProviders\";\n\n/**\n *\n */\nGlobalProviders.createRegistry(ProviderType.CONTROLLER, Provider, {\n injectable: false\n});\n\n/**\n * Register a provider configuration.\n * @param {IProvider<any>} provider\n */\nexport function registerProvider(provider: Partial<IProvider<any>>): void {\n if (!provider.provide) {\n throw new Error(\"Provider.provide is required\");\n }\n\n GlobalProviders.merge(provider.provide, provider);\n}\n\n/**\n * Add a new factory in the `ProviderRegistry`.\n *\n * #### Example with symbol definition\n *\n *\n * ```typescript\n * import {registerFactory, InjectorService} from \"@tsed/di\";\n *\n * export interface IMyFooFactory {\n * getFoo(): string;\n * }\n *\n * export type MyFooFactory = IMyFooFactory;\n * export const MyFooFactory = Symbol(\"MyFooFactory\");\n *\n * registerFactory(MyFooFactory, {\n * getFoo: () => \"test\"\n * });\n *\n * // or\n *\n * registerFactory({provide: MyFooFactory, instance: {\n * getFoo: () => \"test\"\n * }});\n *\n * @Service()\n * export class OtherService {\n * constructor(@Inject(MyFooFactory) myFooFactory: MyFooFactory){\n * console.log(myFooFactory.getFoo()); /// \"test\"\n * }\n * }\n * ```\n *\n * > Note: When you use the factory method with Symbol definition, you must use the `@Inject()`\n * decorator to retrieve your factory in another Service. Advice: By convention all factory class name will be prefixed by\n * `Factory`.\n *\n * #### Example with class\n *\n * ```typescript\n * import {InjectorService, registerFactory} from \"@tsed/di\";\n *\n * export class MyFooService {\n * constructor(){}\n * getFoo() {\n * return \"test\";\n * }\n * }\n *\n * registerFactory(MyFooService, new MyFooService());\n * // or\n * registerFactory({provider: MyFooService, instance: new MyFooService()});\n *\n * @Service()\n * export class OtherService {\n * constructor(myFooService: MyFooService){\n * console.log(myFooFactory.getFoo()); /// \"test\"\n * }\n * }\n * ```\n * @deprecated Since 2021-05-15. Use registerProvider instead.\n */\nexport const registerFactory = registerProvider;\n\n/**\n * Add a new value in the `ProviderRegistry`.\n *\n * #### Example with symbol definition\n *\n *\n * ```typescript\n * import {registerValue, InjectorService} from \"@tsed/di\";\n *\n * const MyValue = Symbol.from(\"MyValue\")\n *\n * registerValue({token: MyValue, useValue: \"myValue\"});\n *\n * @Service()\n * export class OtherService {\n * constructor(@Inject(MyValue) myValue: string){\n * console.log(myValue); /// \"myValue\"\n * }\n * }\n * ```\n */\nexport const registerValue = (provider: any | IProvider<any>, value?: any): void => {\n if (!provider.provide) {\n provider = {\n provide: provider\n };\n }\n\n provider = Object.assign(\n {\n scope: ProviderScope.SINGLETON,\n useValue: value\n },\n provider,\n {type: ProviderType.VALUE}\n );\n GlobalProviders.merge(provider.provide, provider);\n};\n\n/**\n * Add a new service in the `ProviderRegistry`. This service will be built when `InjectorService` will be loaded.\n *\n * #### Example\n *\n * ```typescript\n * import {registerService, InjectorService} from \"@tsed/di\";\n *\n * export default class MyFooService {\n * constructor(){}\n * getFoo() {\n * return \"test\";\n * }\n * }\n *\n * registerService({provide: MyFooService});\n * // or\n * registerService(MyFooService);\n *\n * const injector = new InjectorService();\n * injector.load();\n *\n * const myFooService = injector.get<MyFooService>(MyFooService);\n * myFooService.getFoo(); // test\n * ```\n *\n * @param provider Provider configuration.\n * @deprecated Since 2021-05-15. Use registerProvider instead.\n */\nexport const registerService = GlobalProviders.createRegisterFn(ProviderType.SERVICE);\n/**\n * Add a new controller in the `ProviderRegistry`. This controller will be built when `InjectorService` will be loaded.\n *\n * #### Example\n *\n * ```typescript\n * import {registerController, InjectorService} from \"@tsed/di\";\n *\n * export default class MyController {\n * constructor(){}\n * transform() {\n * return \"test\";\n * }\n * }\n *\n * registerController({provide: MyController});\n * // or\n * registerController(MyController);\n *\n * const injector = new InjectorService();\n * injector.load();\n *\n * const myController = injector.get<MyController>(MyController);\n * myController.getFoo(); // test\n * ```\n *\n * @param provider Provider configuration.\n */\nexport const registerController = GlobalProviders.createRegisterFn(ProviderType.CONTROLLER);\n","import type {IProvider} from \"../interfaces\";\nimport {registerProvider} from \"../registries/ProviderRegistry\";\n\n/**\n * The decorators `@Injectable()` declare a new service can be injected in other service, controller, interceptor, etc.. on there `constructor`.\n * All classes annotated with `@Injectable()` are built one time, excepted if you change the default provider configuration.\n *\n * <<< @/docs/snippets/providers/getting-started-injectable.ts\n *\n * ::: tip\n * `@Injectable()` use the `reflect-metadata` to collect and inject the built provided to other services.\n * :::\n *\n * ### Options\n *\n * - type (@@ProviderType@@ or `string`): Kind of provider. (Default: `ProviderType.PROVIDER`)\n * - scope (@@ProviderScope@): Kind of provider. (Default: `ProviderScope.SINGLETON`)\n * - deps (`Type<any>`): List of class or provider which will be injected to the constructor (Note: This options override default metadata generated by Typescript).\n *\n * @returns {Function}\n * @decorator\n */\nexport function Injectable(options: Partial<IProvider<any>> = {}): ClassDecorator {\n return (provide: any) => {\n registerProvider({\n ...options,\n provide\n });\n };\n}\n","import {Injectable} from \"./injectable\";\n\n/**\n * The decorators `@Service()` declare a new service can be injected in other service or controller on there `constructor`.\n * All services annotated with `@Service()` are constructed one time.\n *\n * > `@Service()` use the `reflect-metadata` to collect and inject service on controllers or other services.\n *\n * @returns {Function}\n * @decorator\n */\nexport function Service(): Function {\n return Injectable();\n}\n","import {Type} from \"@tsed/core\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\n\n/**\n * Override a provider which is already registered in ProviderRegistry.\n * @returns {Function}\n * @decorators\n * @param originalProvider\n */\nexport function OverrideProvider(originalProvider: Type<any>): Function {\n return (target: Type<any>): void => {\n GlobalProviders.get(originalProvider)!.useClass = target;\n };\n}\n","import {decoratorTypeOf, DecoratorTypes, Metadata, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants\";\n\n/**\n * Inject a provider to another provider.\n *\n * Use this decorator to inject a custom provider on constructor parameter or property.\n *\n * ```typescript\n * @Injectable()\n * export class MyService {\n * @Inject(CONNECTION)\n * connection: CONNECTION;\n * }\n * ```\n *\n * @param symbol\n * @param onGet Use the given name method to inject\n * @returns {Function}\n * @decorator\n */\nexport function Inject(symbol?: any, onGet?: (bean: any) => any): Function {\n return (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<Function> | number): any | void => {\n const bindingType = decoratorTypeOf([target, propertyKey, descriptor]);\n\n switch (bindingType) {\n case DecoratorTypes.PARAM:\n case DecoratorTypes.PARAM_CTOR:\n if (symbol) {\n const paramTypes = Metadata.getParamTypes(target, propertyKey);\n\n paramTypes[descriptor as number] = symbol;\n Metadata.setParamTypes(target, propertyKey, paramTypes);\n }\n break;\n\n case DecoratorTypes.PROP:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType,\n propertyKey,\n onGet,\n useType: symbol || Metadata.getType(target, propertyKey)\n }\n });\n break;\n\n case DecoratorTypes.METHOD:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType,\n propertyKey\n }\n });\n\n return descriptor;\n\n default:\n throw new UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);\n }\n };\n}\n","import {Store} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants\";\nimport type {InjectableProperties} from \"../interfaces\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\n\n/**\n * Return value from Configuration.\n *\n * ## Example\n *\n * ```typescript\n * import {Env} from \"@tsed/core\";\n * import {Constant, Value} from \"@tsed/di\";\n *\n * export class MyClass {\n *\n * @Constant(\"env\")\n * env: Env;\n *\n * @Value(\"swagger.path\")\n * swaggerPath: string;\n *\n * @Value(\"swagger.path\", \"defaultValue\")\n * swaggerPath: string;\n *\n * constructor() {\n * console.log(this.swaggerPath) // undefined. Not available on constructor\n * }\n *\n * $onInit() {\n * console.log(this.swaggerPath) // something\n * }\n * }\n * ```\n *\n * @param {string} expression\n * @param defaultValue\n * @returns {(targetClass: any, attributeName: string) => any}\n * @decorator\n */\nexport function Constant(expression: string, defaultValue?: any): any {\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: InjectablePropertyType.CONSTANT,\n propertyKey,\n expression,\n defaultValue\n }\n } as InjectableProperties);\n };\n}\n","import {Store} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants\";\nimport type {InjectableProperties} from \"../interfaces/InjectableProperties\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\n\n/**\n * Return value from Configuration.\n *\n * ## Example\n *\n * ```typescript\n * import {Env} from \"@tsed/core\";\n * import {Constant, Value} from \"@tsed/di\";\n *\n * export class MyClass {\n *\n * @Constant(\"env\")\n * env: Env;\n *\n * @Value(\"swagger.path\")\n * swaggerPath: string;\n *\n * @Value(\"swagger.path\", \"defaultValue\")\n * swaggerPath: string;\n *\n * constructor() {\n * console.log(this.swaggerPath) // undefined. Not available on constructor\n * }\n *\n * $onInit() {\n * console.log(this.swaggerPath) // something\n * }\n * }\n * ```\n *\n * @param expression\n * @param defaultValue\n * @returns {(targetClass: any, attributeName: string) => any}\n * @decorator\n */\nexport function Value(expression: any, defaultValue?: any) {\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: InjectablePropertyType.VALUE,\n propertyKey,\n expression,\n defaultValue\n }\n } as InjectableProperties);\n };\n}\n","import {Store, Type} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants\";\nimport type {InjectableProperties, InterceptorMethods} from \"../interfaces\";\nimport {InjectablePropertyType} from \"../domain\";\n\n/**\n * Attaches interceptor to method call and executes the before and after methods\n *\n * @param interceptor\n * @param options\n * @decorator\n */\nexport function Intercept<T extends InterceptorMethods>(interceptor: Type<T>, options?: any): MethodDecorator {\n return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: InjectablePropertyType.INTERCEPTOR,\n propertyKey,\n useType: interceptor,\n options\n }\n } as InjectableProperties);\n\n return descriptor;\n };\n}\n","import {ProviderType} from \"../domain/ProviderType\";\nimport {Injectable} from \"./injectable\";\n\n/**\n * The decorators `@Service()` declare a new service can be injected in other service or controller on there `constructor`.\n * All services annotated with `@Service()` are constructed one time.\n *\n * > `@Service()` use the `reflect-metadata` to collect and inject service on controllers or other services.\n *\n * @returns {Function}\n * @decorator\n */\nexport function Interceptor(): Function {\n return Injectable({\n type: ProviderType.INTERCEPTOR\n });\n}\n","import {DecoratorParameters, decoratorTypeOf, DecoratorTypes, StoreSet} from \"@tsed/core\";\nimport {Inject} from \"../decorators/inject\";\nimport {DIConfiguration} from \"../services/DIConfiguration\";\n\n/**\n * Get or set Configuration on a class.\n *\n * @decorator\n */\nexport function Configuration(configuration: Partial<TsED.Configuration> = {}): Function {\n return (...args: DecoratorParameters) => {\n switch (decoratorTypeOf(args)) {\n case DecoratorTypes.CLASS:\n StoreSet(\"configuration\", configuration)(args[0]);\n\n break;\n default:\n case DecoratorTypes.PARAM_CTOR:\n return Inject(Configuration)(args[0], args[1], args[2] as number);\n }\n };\n}\n\nexport type Configuration = TsED.Configuration & DIConfiguration;\n","import {useDecorators} from \"@tsed/core\";\nimport {ProviderScope, ProviderType} from \"../domain\";\nimport type {DIResolver, TokenProvider} from \"../interfaces\";\nimport {Configuration} from \"./configuration\";\nimport {Injectable} from \"./injectable\";\n\nexport interface ModuleOptions extends Omit<TsED.Configuration, \"scopes\"> {\n /**\n * Provider scope\n */\n scope?: ProviderScope;\n /**\n * Providers must be initialized before building this module\n */\n imports?: TokenProvider[];\n /**\n * Explicit token must be injected in the constructor\n */\n deps?: TokenProvider[];\n /**\n * A list of resolvers to inject provider from external DI.\n */\n resolvers?: DIResolver[];\n\n /**\n * Additional properties are stored as provider configuration.\n */\n [key: string]: any;\n}\n\n/**\n * Declare a new Ts.ED module\n *\n * ## Options\n * - imports: List of Provider which must be built by injector before invoking the module\n * - resolvers: List of external DI must be used to resolve unknown provider\n * - deps: List of provider must be injected to the module constructor (explicit declaration)\n *\n * @param options\n * @decorator\n */\nexport function Module(options: Partial<ModuleOptions> = {}) {\n const {scopes, imports, resolvers, deps, scope, ...configuration} = options;\n\n return useDecorators(\n Configuration(configuration),\n Injectable({\n type: ProviderType.MODULE,\n scope: ProviderScope.SINGLETON,\n imports,\n deps,\n injectable: false,\n resolvers\n })\n );\n}\n","import {classOf} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS} from \"../constants\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\nimport {Inject} from \"./inject\";\nimport {Scope} from \"./scope\";\n\n/**\n * Get instance options. This options depending on his invocation context.\n *\n * ```typescript\n * import {Injectable, Opts, UseOpts} from \"@tsed/di\";\n *\n * @Injectable()\n * class MyConfigurableService {\n * source: string;\n * constructor(@Opts options: any = {}) {\n * console.log(\"Hello \", options.source); // log: Hello Service1 then Hello Service2\n *\n * this.source = options.source;\n * }\n * }\n *\n * @Injectable()\n * class MyService1 {\n * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service1\n * }\n * }\n *\n * @Injectable()\n * class MyService2 {\n * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service2\n * }\n * }\n * ```\n *\n * ::: warning\n * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.\n * :::\n *\n * @param target\n * @param propertyKey\n * @param index\n * @decorator\n */\nexport function Opts(target: any, propertyKey: string | symbol, index: number) {\n Scope(ProviderScope.INSTANCE)(classOf(target));\n Inject(DI_PARAM_OPTIONS)(target, propertyKey, index);\n}\n","import {decoratorTypeOf, DecoratorTypes, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants\";\n\n/**\n * Add options to invoke the Service.\n *\n * ```typescript\n * import {Injectable, Opts, UseOpts} from \"@tsed/di\";\n *\n * @Injectable()\n * class MyConfigurableService {\n * source: string;\n * constructor(@Opts options: any = {}) {\n * console.log(\"Hello \", options.source); // log: Hello Service1 then Hello Service2\n *\n * this.source = options.source;\n * }\n * }\n *\n * @Injectable()\n * class MyService1 {\n * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service1\n * }\n * }\n *\n * @Injectable()\n * class MyService2 {\n * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service2\n * }\n * }\n * ```\n *\n * ::: warning\n * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.\n * :::\n *\n * @returns {Function}\n * @decorator\n * @param options\n */\nexport function UseOpts(options: {[key: string]: any}): Function {\n return (target: Object, propertyKey: string | symbol, index?: number): any => {\n const bindingType = decoratorTypeOf([target, propertyKey, index]);\n\n switch (bindingType) {\n case DecoratorTypes.PARAM_CTOR:\n Store.from(target).merge(`${DI_PARAM_OPTIONS}:${index}`, options);\n break;\n\n case DecoratorTypes.PROP:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey as string]: {\n options\n }\n });\n break;\n\n default:\n throw new UnsupportedDecoratorType(UseOpts, [target, propertyKey, index]);\n }\n };\n}\n","import {getConstructorArgNames, isClass, isString, nameOf} from \"@tsed/core\";\nimport chalk from \"chalk\";\nimport {TokenProvider} from \"../interfaces\";\n\nexport class InjectionError extends Error {\n name = \"INJECTION_ERROR\";\n\n public tokens: TokenProvider[] = [];\n public origin: any;\n\n constructor(token: TokenProvider, origin?: any) {\n super(isString(origin) ? origin : \"\");\n\n this.tokens = [token];\n\n if (origin) {\n if (isString(origin)) {\n this.origin = {\n message: origin,\n stack: this.stack\n };\n } else {\n if (origin.tokens) {\n this.tokens = this.tokens.concat(origin.tokens);\n this.origin = origin.origin;\n } else {\n this.origin = origin;\n this.stack = origin.stack;\n }\n }\n }\n\n const originMessage = this.origin ? \"\\nOrigin: \" + this.origin.message : \"\";\n const tokensMessage = this.tokens.map((token) => nameOf(token)).join(\" > \");\n\n this.message = `Injection failed on ${tokensMessage}${originMessage}`;\n }\n\n static throwInjectorError(token: any, currentDependency: any, error: any) {\n if (currentDependency && isClass(token)) {\n error.message = printDependencyInjectionError(token, {...currentDependency, message: error.message});\n }\n\n throw new InjectionError(token, error);\n }\n}\n\nfunction printDependencyInjectionError(token: any, options: {token: any; index: number; deps: any[]; message: string}) {\n let erroredArg = \"\";\n\n const args = getConstructorArgNames(token)\n .map((arg, index) => {\n if (options.index === index) {\n erroredArg = arg;\n arg = chalk.red(arg);\n }\n\n return `${arg}: ${nameOf(options.deps[index])}`;\n })\n .join(\", \");\n\n const signature = nameOf(token) + \"->constructor(\" + args + \")\";\n const indexOf = signature.indexOf(erroredArg) - 5;\n const drawline = (indexOf: number) => \" \".repeat(indexOf) + chalk.red(\"^\" + \"‾\".repeat(erroredArg.length - 1));\n\n return \"Unable to inject dependency. \" + options.message + \"\\n\\n\" + signature + \"\\n\" + (indexOf > -1 ? drawline(indexOf) : \"\");\n}\n","export class UndefinedTokenError extends Error {\n name = \"UNDEFINED_TOKEN_ERROR\";\n\n constructor() {\n super(\n \"Given token is undefined. Have you enabled emitDecoratorMetadata in your tsconfig.json or decorated your class with @Injectable, @Service, ... decorator ?\"\n );\n }\n}\n","import {Type} from \"@tsed/core\";\nimport {Container} from \"../domain/Container\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\n\nexport function createContainer(rootModule?: Type<any>) {\n const container = new Container(GlobalProviders.entries());\n\n if (rootModule) {\n container.delete(rootModule);\n }\n\n return container;\n}\n","import {classOf, deepMerge, getValue, proxyDelegation, setValue} from \"@tsed/core\";\nimport {ProviderScope} from \"../domain\";\nimport type {DIResolver, TokenProvider} from \"../interfaces\";\n\nexport class DIConfiguration {\n readonly default: Map<string, any> = new Map();\n protected map: Map<string, any> = new Map();\n\n [key: string]: any;\n\n constructor(initialProps = {}) {\n Object.entries({\n scopes: {},\n resolvers: [],\n imports: [],\n ...initialProps\n }).forEach(([key, value]) => {\n this.default.set(key, value);\n });\n\n return proxyDelegation<DIConfiguration>(this, {\n ownKeys(target) {\n return [...target.default.keys(), ...target.map.keys()];\n }\n });\n }\n\n get scopes(): {[key: string]: ProviderScope} {\n return this.getRaw(\"scopes\");\n }\n\n set scopes(value: {[key: string]: ProviderScope}) {\n this.setRaw(\"scopes\", value);\n }\n\n get resolvers(): DIResolver[] {\n return this.getRaw(\"resolvers\");\n }\n\n set resolvers(resolvers: DIResolver[]) {\n this.setRaw(\"resolvers\", resolvers);\n }\n\n get imports(): TokenProvider[] {\n return this.getRaw(\"imports\");\n }\n\n set imports(imports: TokenProvider[]) {\n this.setRaw(\"imports\", imports);\n }\n\n /**\n *\n * @param callbackfn\n * @param thisArg\n */\n forEach(callbackfn: (value: any, index: string, map: Map<string, any>) => void, thisArg?: any) {\n return new Set([...Array.from(this.default.keys()), ...Array.from(this.map.keys())]).forEach((key) => {\n callbackfn(this.getRaw(key), key, this.map);\n }, thisArg);\n }\n\n /**\n *\n * @param propertyKey\n * @param value\n */\n set(propertyKey: string | Partial<TsED.Configuration>, value?: any): this {\n if (typeof propertyKey === \"string\") {\n this.setRaw(propertyKey, value);\n } else {\n Object.entries(propertyKey).forEach(([key, value]) => {\n this[key] = value;\n });\n }\n\n return this;\n }\n\n setRaw(propertyKey: string, value: any) {\n setValue(this.map, propertyKey, value);\n\n return this;\n }\n\n /**\n *\n * @param propertyKey\n * @param defaultValue\n * @returns {undefined|any}\n */\n get<T = any>(propertyKey: string, defaultValue?: T): T {\n return this.resolve(this.getRaw(propertyKey, defaultValue));\n }\n\n getRaw(propertyKey: string, defaultValue?: any): any {\n const value = getValue(this.map, propertyKey);\n\n if (value !== undefined) {\n return value;\n }\n\n return getValue(this.default, propertyKey, defaultValue);\n }\n\n merge(obj: Partial<TsED.Configuration>) {\n Object.entries(obj).forEach(([key, value]) => {\n const descriptor = Object.getOwnPropertyDescriptor(DIConfiguration.prototype, key);\n const originalValue = this.get(key);\n value = deepMerge(value, originalValue);\n\n if (descriptor && ![\"default\", \"set\", \"map\", \"get\"].includes(key)) {\n this[key] = value;\n }\n });\n }\n\n /**\n *\n * @param value\n * @returns {any}\n */\n resolve(value: any) {\n if (typeof value === \"object\" && value !== null) {\n if (![Array, Object].includes(classOf(value))) {\n return value;\n }\n\n return Object.entries(value).reduce(\n (o, [k, v]) => {\n // @ts-ignore\n o[k] = this.resolve(v);\n\n return o;\n },\n Array.isArray(value) ? [] : {}\n );\n }\n\n if (typeof value === \"string\") {\n const replacer = (match: string, key: string) => getValue(this.map, key);\n return value\n .replace(/\\${([\\w.]+)}/gi, replacer)\n .replace(/<([\\w.]+)>/gi, replacer)\n .replace(/{{([\\w.]+)}}/gi, replacer);\n }\n\n return value;\n }\n\n build() {\n this.forEach((value, key) => this.map.set(key, this.resolve(value)));\n\n this.set = this.setRaw;\n this.get = this.getRaw = (propertyKey: string, defaultValue?: any) => getValue(this.map, propertyKey, defaultValue);\n }\n}\n","import {\n ancestorsOf,\n classOf,\n deepClone,\n deepMerge,\n getClassOrSymbol,\n isFunction,\n isInheritedFrom,\n isPromise,\n Metadata,\n nameOf,\n prototypeOf,\n Store\n} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants\";\nimport {Configuration} from \"../decorators/configuration\";\nimport {Injectable} from \"../decorators/injectable\";\nimport {DIContext, InjectablePropertyType, ProviderScope} from \"../domain\";\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 {\n DILogger,\n InjectableProperties,\n InjectablePropertyService,\n InjectablePropertyValue,\n InterceptorContext,\n InterceptorMethods,\n InvokeOptions,\n IProvider,\n TokenProvider\n} from \"../interfaces\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {createContainer} from \"../utils/createContainer\";\nimport {DIConfiguration} from \"./DIConfiguration\";\n\ninterface InvokeSettings {\n token: TokenProvider;\n parent?: TokenProvider;\n scope: ProviderScope;\n isBindable: boolean;\n deps: TokenProvider[];\n imports: TokenProvider[];\n provider: Provider<any>;\n\n construct(deps: TokenProvider[]): any;\n}\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: TsED.Configuration & DIConfiguration = new DIConfiguration() as any;\n public logger: DILogger = console;\n private resolvedConfiguration: boolean = false;\n\n constructor() {\n super();\n const provider = this.addProvider(InjectorService).getProvider(InjectorService)!;\n provider.instance = 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 */\n public forkProvider(token: TokenProvider, settings: Partial<IProvider<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 provider.instance = 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 super.toArray().map((provider) => provider.instance);\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 = super.get(getClassOrSymbol(token))?.instance;\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 * 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 super.has(getClassOrSymbol(token)) && this.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 this.hasProvider(token) && (this.getProvider(token)!.instance = instance);\n\n return instance;\n }\n\n switch (this.scopeOf(provider)) {\n case ProviderScope.SINGLETON:\n if (!this.has(token)) {\n provider.instance = this.resolve(token, locals, options);\n\n if (provider.isAsync()) {\n provider.instance.then((instance: any) => {\n provider.instance = 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<any> = 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 if (provider.instance) {\n locals.set(provider.token, provider.instance);\n }\n }\n }\n\n return locals;\n }\n\n loadSync(locals: LocalsContainer<any> = 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 if (provider.instance !== undefined) {\n locals.set(provider.token, provider.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 * 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(\"$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) {\n Object.entries(provider.configuration).forEach(([key, value]) => {\n value = mergedConfiguration.has(key) ? deepMerge(mergedConfiguration.get(key), value) : deepClone(value);\n mergedConfiguration.set(key, value);\n });\n }\n if (provider.resolvers) {\n this.resolvers.push(...provider.resolvers);\n }\n });\n\n mergedConfiguration.forEach((value, key) => {\n this.settings[key] = deepMerge(value, this.settings[key]);\n });\n\n this.settings.build();\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}: InjectablePropertyService) {\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 onGet\n * @param options\n * @param locals\n * @param invokeOptions\n */\n public bindProperty(\n instance: any,\n {propertyKey, useType, onGet = (f: any) => f, options}: InjectablePropertyService,\n locals: Map<TokenProvider, any>,\n invokeOptions: Partial<InvokeOptions>\n ) {\n invokeOptions = {...invokeOptions};\n locals.set(DI_PARAM_OPTIONS, {...options});\n\n let bean: any = this.invoke(useType, locals, invokeOptions);\n\n locals.delete(DI_PARAM_OPTIONS);\n\n if (isPromise(bean)) {\n bean.then((result: any) => {\n bean = result;\n });\n }\n\n Object.defineProperty(instance, propertyKey, {\n get: () => onGet(bean)\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 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): PropertyDescriptor {\n const clone = (o: any) => {\n if (o) {\n return Object.freeze(deepClone(o));\n }\n\n return defaultValue;\n };\n\n const descriptor = {\n get: () => clone(this.settings.get(expression)),\n\n enumerable: true,\n configurable: true\n };\n Object.defineProperty(instance, propertyKey, descriptor);\n\n return 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}: InjectablePropertyService) {\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 /**\n * Allow handler hack for AsyncHookContext plugin.\n * @param ctx\n * @param cb\n * @protected\n */\n runInContext(ctx: DIContext, cb: any) {\n return cb();\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 /**\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 {token, deps, construct, isBindable, imports, provider} = this.mapInvokeOptions(target, locals, options);\n\n if (provider) {\n if (!provider.injectable && options.parent) {\n throw new InjectionError(token, `${nameOf(token)} ${provider.type} is not injectable to another provider`);\n }\n\n const {onInvoke} = GlobalProviders.getRegistrySettings(target);\n if (onInvoke) {\n onInvoke(provider, locals, deps);\n }\n }\n\n let instance: any;\n let currentDependency: any = false;\n\n try {\n const invokeDependency = (parent?: any) => (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 && isBindable) {\n this.bindInjectableProperties(instance, locals, options);\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<any>>): InvokeSettings {\n let imports: TokenProvider[] | undefined = options.imports;\n let deps: TokenProvider[] | undefined = options.deps;\n let scope = options.scope;\n let construct;\n let isBindable = false;\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 = (deps: TokenProvider[]) => provider.useAsyncFactory(...deps);\n } else {\n // useClass\n isBindable = true;\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 isBindable,\n construct,\n provider\n };\n }\n}\n","import {Logger} from \"@tsed/logger\";\nimport {registerProvider} from \"../registries/ProviderRegistry\";\nimport {InjectorService} from \"./InjectorService\";\n\nregisterProvider({\n provide: Logger,\n deps: [InjectorService],\n useFactory(injector: InjectorService) {\n return injector.logger;\n }\n});\n","import {InjectorService} from \"../services/InjectorService\";\n\n/**\n * @ignore\n * @param injector\n */\nexport function setLoggerLevel(injector: InjectorService) {\n const level = injector.settings.logger?.level;\n\n if (level) {\n injector.logger.level = level;\n }\n}\n","import {Env, getValue} from \"@tsed/core\";\nimport {$log} from \"@tsed/logger\";\nimport {Container} from \"../domain/Container\";\nimport {LocalsContainer} from \"../domain/LocalsContainer\";\nimport {OnInit} from \"../interfaces/OnInit\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {setLoggerLevel} from \"../utils/setLoggerLevel\";\nimport {InjectorService} from \"./InjectorService\";\n\nexport interface DITestInvokeOptions {\n token?: TokenProvider;\n use: any;\n}\n\n/**\n * Tool to run test with lightweight DI sandbox.\n */\nexport class DITest {\n protected static _injector: InjectorService | null = null;\n\n static get injector(): InjectorService {\n if (DITest._injector) {\n return DITest._injector!;\n }\n\n /* istanbul ignore next */\n throw new Error(\n \"PlatformTest.injector is not initialized. Use PlatformTest.create(): Promise before PlatformTest.invoke() or PlatformTest.injector.\\n\" +\n \"Example:\\n\" +\n \"before(async () => {\\n\" +\n \" await PlatformTest.create()\\n\" +\n \" await PlatformTest.invoke(MyService, [])\\n\" +\n \"})\"\n );\n }\n\n static set injector(injector: InjectorService) {\n DITest._injector = injector;\n }\n\n static hasInjector() {\n return !!DITest._injector;\n }\n\n static async create(settings: Partial<TsED.Configuration> = {}) {\n DITest.injector = DITest.createInjector(settings);\n\n const container = new Container();\n DITest.injector.bootstrap(container);\n\n await DITest.injector.load(container);\n }\n\n /**\n * Create a new injector with the right default services\n */\n static createInjector(settings: any = {}): InjectorService {\n const injector = new InjectorService();\n injector.logger = $log;\n\n // @ts-ignore\n injector.settings.set(DITest.configure(settings));\n\n setLoggerLevel(injector);\n\n return injector;\n }\n\n /**\n * Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.\n */\n static async reset() {\n if (DITest.hasInjector()) {\n await DITest.injector.destroy();\n DITest._injector = null;\n }\n }\n\n /**\n * Invoke a provider and return a fresh instance\n * @param target\n * @param providers\n */\n static invoke<T = any>(target: TokenProvider, providers: DITestInvokeOptions[] = []): T | Promise<T> {\n const locals = new LocalsContainer();\n providers.forEach((p) => {\n locals.set(p.token, p.use);\n });\n\n locals.set(InjectorService, DITest.injector);\n\n const instance: OnInit = DITest.injector.invoke(target, locals, {rebuild: true});\n\n if (instance && instance.$onInit) {\n // await instance.$onInit();\n const result = instance.$onInit();\n if (result instanceof Promise) {\n return result.then(() => instance as any);\n }\n }\n\n return instance as any;\n }\n\n /**\n * Return the instance from injector registry\n * @param target\n * @param options\n */\n static get<T = any>(target: TokenProvider, options: any = {}): T {\n return DITest.injector.get<T>(target, options)!;\n }\n\n protected static configure(settings: Partial<TsED.Configuration> = {}): Partial<TsED.Configuration> {\n return {\n ...settings,\n env: getValue(settings, \"env\", Env.TEST),\n logger: {\n ...getValue(settings, \"logger\", {}),\n level: getValue(settings, \"logger.level\", \"off\")\n }\n };\n }\n}\n","import {normalizePath} from \"@tsed/core\";\nimport {resolve} from \"path\";\n\nfunction isTsEnv() {\n return (\n (require && require.extensions && require.extensions[\".ts\"]) ||\n process.env[\"TS_TEST\"] ||\n process.env.JEST_WORKER_ID !== undefined ||\n process.env.NODE_ENV === \"test\"\n );\n}\n\nfunction mapExcludes(excludes: string[]) {\n return excludes.map((s: string) => `!${s.replace(/!/gi, \"\")}`);\n}\n\nfunction mapExtensions(file: string): string {\n if (!isTsEnv()) {\n file = file.replace(/\\.ts$/i, \".js\").replace(/{\\.ts,\\.js}$/i, \".js\");\n }\n\n return file;\n}\n\nexport function cleanGlobPatterns(files: string | string[], excludes: string[]): string[] {\n return []\n .concat(files as never)\n .map((s: string) => resolve(s))\n .concat(mapExcludes(excludes) as never)\n .map(mapExtensions)\n .map((s: string) => normalizePath(s));\n}\n","import globby from \"globby\";\nimport {cleanGlobPatterns} from \"./cleanGlobPatterns\";\n\nexport async function importFiles(patterns: string | string[], exclude: string[]): Promise<any[]> {\n const files = await globby(cleanGlobPatterns(patterns, exclude));\n const symbols: any[] = [];\n\n for (const file of files) {\n if (!file.endsWith(\".d.ts\")) {\n // prevent .d.ts import if the global pattern isn't correctly configured\n try {\n const exports = await import(file);\n Object.keys(exports).forEach((key) => symbols.push(exports[key]));\n } catch (er) {\n // istanbul ignore next\n console.error(er);\n // istanbul ignore next\n process.exit(1);\n }\n }\n }\n\n return symbols;\n}\n","import {isArray, isClass} from \"@tsed/core\";\nimport {importFiles} from \"./importFiles\";\n\nasync function resolveSymbols(item: any, excludes: string[]) {\n if (isClass(item)) {\n return [item];\n }\n /* istanbul ignore else */\n if (!process.env.WEBPACK) {\n return importFiles(item, excludes);\n }\n\n /* istanbul ignore next */\n return [];\n}\n\nexport function mapConfiguration(config: any): {endpoint?: string; values: any[]}[] {\n if (isArray(config)) {\n return config.map((value: any) => {\n return {\n values: [].concat(value)\n };\n });\n }\n\n return Object.keys(config).reduce((list: any[], key: string) => {\n list.push({\n endpoint: key,\n values: [].concat(config[key])\n });\n\n return list;\n }, []);\n}\n\nexport async function importComponents(config: any, excludes: string[]): Promise<{token: string; route?: string}[]> {\n if (!config) {\n return [];\n }\n\n config = mapConfiguration(config);\n\n const promises: any = [];\n\n for (const option of config) {\n promises.push(\n ...option.values.map(async (value: any) => {\n const symbols = await resolveSymbols(value, excludes);\n\n return symbols.filter(isClass).map((symbol) => ({token: symbol, route: option.endpoint}));\n })\n );\n }\n\n const result: {token: string; route?: string}[][] = await Promise.all(promises);\n\n return result.flat();\n}\n","import {deepMerge, Store, Type} from \"@tsed/core\";\n\nexport function getConfiguration(module: Type<any>, configuration: any = {}) {\n const store = Store.from(module).get(\"configuration\") || {};\n\n const config = {\n ...store,\n ...configuration\n };\n\n if (store.mount && configuration.mount) {\n config.mount = deepMerge(store.mount, configuration.mount);\n }\n\n if (store.componentsScan && configuration.componentsScan) {\n config.componentsScan = [...store.componentsScan, ...configuration.componentsScan];\n }\n\n return config;\n}\n","import {Provider} from \"../domain/Provider\";\nimport {IProvider} from \"../interfaces/IProvider\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {importComponents} from \"./importComponents\";\n\nasync function recursiveImports(providers: {token: string; route?: string}[], settings: Partial<TsED.Configuration>, properties: string[]) {\n const {exclude = []} = settings;\n\n const promises = providers\n .map(({token}) => GlobalProviders.get(token))\n .filter((provider) => provider?.type === ProviderType.MODULE && provider.configuration)\n .map((provider: Provider) => importProviders({exclude, ...provider.configuration}, properties));\n\n return (await Promise.all(promises)).flat();\n}\n\n/**\n * Import providers from given patterns.\n *\n * @param settings\n * @param properties\n */\nexport async function importProviders(\n settings: Partial<TsED.Configuration>,\n properties: string[] = [\"imports\"]\n): Promise<{token: string; route?: string}[]> {\n const {exclude = []} = settings;\n\n const promises = properties.map((key) => importComponents(settings[key], exclude));\n const providers = (await Promise.all(promises)).flat();\n const children = await recursiveImports(providers, settings, properties);\n\n return [...children, ...providers];\n}\n"],"names":["INJECTABLE_PROP","DI_PARAMS","DI_PARAM_OPTIONS","ProviderScope","ProviderType","Provider","constructor","token","PROVIDER","provide","useClass","_provide","value","isClass","classOf","_tokenStore","_store","Store","from","_useClass","className","name","nameOf","store","scope","isAsync","SINGLETON","get","set","configuration","key","useAsyncFactory","clone","provider","getEnumerableKeys","forEach","undefined","toString","useFactory","useValue","filter","Boolean","join","__decorate","Enumerable","Function","NotEnumerable","Type","GlobalProviderRegistry","Map","getClassOrSymbol","has","metadata","merge","target","options","meta","createIfNotExists","Object","keys","delete","createRegistry","type","model","injectable","defaultOptions","getRegistrySettings","assign","createRegisterFn","instance","getRegistry","item","GlobalProviders","LocalsContainer","emit","eventName","args","handler","getListeners","alter","alterAsync","toArray","values","destroy","clear","event","reduce","listeners","concat","bind","Container","add","settings","addProvider","hasProvider","setProvider","getProvider","getProviders","Array","_","map","addProviders","container","InjectablePropertyType","ContextLogger","logger","id","url","dateStart","Date","ignoreUrlPatterns","minimalRequestPicker","completeRequestPicker","level","maxStackSize","ignoreLog","additionalProps","l","levels","toUpperCase","ALL","info","obj","run","INFO","getData","debug","withRequest","DEBUG","warn","WARN","error","ERROR","trace","TRACE","flush","length","data","isLevelEnabled","otherLevel","isLessThanOrEqualTo","getDuration","getTime","message","reqId","time","duration","mapper","push","levelStr","toLowerCase","DIContext","injector","env","Scope","REQUEST","StoreSet","CONTROLLER","registerProvider","Error","registerFactory","registerValue","VALUE","registerService","SERVICE","registerController","Injectable","Service","OverrideProvider","originalProvider","Inject","symbol","onGet","propertyKey","descriptor","bindingType","decoratorTypeOf","DecoratorTypes","PARAM","PARAM_CTOR","paramTypes","Metadata","getParamTypes","setParamTypes","PROP","useType","getType","METHOD","UnsupportedDecoratorType","Constant","expression","defaultValue","CONSTANT","Value","Intercept","interceptor","INTERCEPTOR","Interceptor","Configuration","CLASS","Module","imports","resolvers","deps","useDecorators","MODULE","Opts","index","INSTANCE","UseOpts","InjectionError","origin","isString","tokens","stack","originMessage","tokensMessage","throwInjectorError","currentDependency","printDependencyInjectionError","erroredArg","getConstructorArgNames","arg","chalk","red","signature","indexOf","drawline","repeat","UndefinedTokenError","createContainer","rootModule","entries","DIConfiguration","initialProps","scopes","default","proxyDelegation","ownKeys","getRaw","setRaw","callbackfn","thisArg","Set","setValue","resolve","getValue","getOwnPropertyDescriptor","prototype","originalValue","deepMerge","includes","o","k","v","isArray","replacer","match","replace","build","InjectorService","console","InjectorService_1","scopeOf","forkProvider","invoke","resolver","result","locals","ensureProvider","rebuild","then","loadAsync","loadSync","bootstrap","resolveConfiguration","load","resolvedConfiguration","mergedConfiguration","deepClone","bindInjectableProperties","properties","ancestorsOf","definition","bindMethod","PROPERTY","bindProperty","bindConstant","bindValue","bindInterceptor","originalMethod","prototypeOf","services","dependency","call","f","invokeOptions","bean","isPromise","defineProperty","enumerable","configurable","freeze","next","err","apply","context","intercept","runInContext","ctx","cb","construct","isBindable","mapInvokeOptions","parent","onInvoke","invokeDependency","isInheritedFrom","isFunction","global","Logger","setLoggerLevel","DITest","_injector","hasInjector","create","createInjector","$log","configure","reset","providers","p","use","$onInit","Promise","Env","TEST","isTsEnv","require","extensions","process","JEST_WORKER_ID","NODE_ENV","mapExcludes","excludes","s","mapExtensions","file","cleanGlobPatterns","files","normalizePath","importFiles","patterns","exclude","globby","symbols","endsWith","exports","er","exit","resolveSymbols","WEBPACK","mapConfiguration","config","list","endpoint","importComponents","promises","option","route","all","flat","getConfiguration","module","mount","componentsScan","recursiveImports","importProviders","children"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAaA,eAAe,GAAG;MAClBC,SAAS,GAAG;MACZC,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACFpBC;;AAAZ,WAAYA;AACVA,EAAAA,0BAAA,cAAA;AACAA,EAAAA,wBAAA,YAAA;AACAA,EAAAA,yBAAA,aAAA;AACD,CAJD,EAAYA,qBAAa,KAAbA,qBAAa,KAAA,CAAzB;;ACAYC;;AAAZ,WAAYA;AACVA,EAAAA,qBAAA,UAAA;AACAA,EAAAA,uBAAA,YAAA;AACAA,EAAAA,uBAAA,YAAA;AACAA,EAAAA,wBAAA,aAAA;AACAA,EAAAA,sBAAA,WAAA;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,2474 @@
1
+ import { isClass, classOf, Store, nameOf, getEnumerableKeys, Enumerable, NotEnumerable, Type, getClassOrSymbol, StoreSet, decoratorTypeOf, UnsupportedDecoratorType, DecoratorTypes, Metadata, useDecorators, isString, getConstructorArgNames, proxyDelegation, setValue, getValue, deepMerge, deepClone, ancestorsOf, prototypeOf, isPromise, isInheritedFrom, isFunction, Env, normalizePath, isArray } from '@tsed/core';
2
+ import { __decorate, __metadata } from 'tslib';
3
+ import { levels, Logger, $log } from '@tsed/logger';
4
+ import chalk from 'chalk';
5
+ import globby from 'globby';
6
+ import { resolve } from 'path';
7
+
8
+ const INJECTABLE_PROP = "DI:INJECTABLE_PROP";
9
+ const DI_PARAMS = "DI:PARAMS";
10
+ const DI_PARAM_OPTIONS = "DI:PARAM:OPTIONS";
11
+
12
+ function _extends() {
13
+ _extends = Object.assign || function (target) {
14
+ for (var i = 1; i < arguments.length; i++) {
15
+ var source = arguments[i];
16
+
17
+ for (var key in source) {
18
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
19
+ target[key] = source[key];
20
+ }
21
+ }
22
+ }
23
+
24
+ return target;
25
+ };
26
+
27
+ return _extends.apply(this, arguments);
28
+ }
29
+
30
+ function _objectWithoutPropertiesLoose(source, excluded) {
31
+ if (source == null) return {};
32
+ var target = {};
33
+ var sourceKeys = Object.keys(source);
34
+ var key, i;
35
+
36
+ for (i = 0; i < sourceKeys.length; i++) {
37
+ key = sourceKeys[i];
38
+ if (excluded.indexOf(key) >= 0) continue;
39
+ target[key] = source[key];
40
+ }
41
+
42
+ return target;
43
+ }
44
+
45
+ var id = 0;
46
+
47
+ function _classPrivateFieldLooseKey(name) {
48
+ return "__private_" + id++ + "_" + name;
49
+ }
50
+
51
+ function _classPrivateFieldLooseBase(receiver, privateKey) {
52
+ if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
53
+ throw new TypeError("attempted to use private field on non-instance");
54
+ }
55
+
56
+ return receiver;
57
+ }
58
+
59
+ var ProviderScope;
60
+
61
+ (function (ProviderScope) {
62
+ ProviderScope["SINGLETON"] = "singleton";
63
+ ProviderScope["REQUEST"] = "request";
64
+ ProviderScope["INSTANCE"] = "instance";
65
+ })(ProviderScope || (ProviderScope = {}));
66
+
67
+ var ProviderType;
68
+
69
+ (function (ProviderType) {
70
+ ProviderType["VALUE"] = "value";
71
+ ProviderType["FACTORY"] = "factory";
72
+ ProviderType["SERVICE"] = "service";
73
+ ProviderType["PROVIDER"] = "provider";
74
+ ProviderType["MODULE"] = "module";
75
+ ProviderType["CONTROLLER"] = "controller";
76
+ ProviderType["INTERCEPTOR"] = "interceptor";
77
+ ProviderType["MIDDLEWARE"] = "middleware";
78
+ })(ProviderType || (ProviderType = {}));
79
+
80
+ class Provider {
81
+ constructor(token) {
82
+ this.type = ProviderType.PROVIDER;
83
+ this.injectable = true;
84
+ this.provide = token;
85
+ this.useClass = token;
86
+ }
87
+
88
+ get token() {
89
+ return this._provide;
90
+ }
91
+
92
+ get provide() {
93
+ return this._provide;
94
+ }
95
+
96
+ set provide(value) {
97
+ if (value) {
98
+ this._provide = isClass(value) ? classOf(value) : value;
99
+ this._tokenStore = this._store = Store.from(value);
100
+ }
101
+ }
102
+
103
+ get useClass() {
104
+ return this._useClass;
105
+ }
106
+ /**
107
+ * Create a new store if the given value is a class. Otherwise the value is ignored.
108
+ * @param value
109
+ */
110
+
111
+
112
+ set useClass(value) {
113
+ if (isClass(value)) {
114
+ this._useClass = classOf(value);
115
+ this._store = Store.from(value);
116
+ }
117
+ }
118
+
119
+ get className() {
120
+ return this.name;
121
+ }
122
+
123
+ get name() {
124
+ return nameOf(this.provide);
125
+ }
126
+
127
+ get store() {
128
+ return this._store;
129
+ }
130
+ /**
131
+ * Get the scope of the provider.
132
+ *
133
+ * ::: tip Note
134
+ * Async provider is always a SINGLETON
135
+ * :::
136
+ *
137
+ * @returns {boolean}
138
+ */
139
+
140
+
141
+ get scope() {
142
+ if (this.isAsync()) {
143
+ return ProviderScope.SINGLETON;
144
+ }
145
+
146
+ return this.get("scope");
147
+ }
148
+ /**
149
+ * Change the scope value of the provider.
150
+ * @param scope
151
+ */
152
+
153
+
154
+ set scope(scope) {
155
+ this.store.set("scope", scope);
156
+ }
157
+
158
+ get configuration() {
159
+ return this.get("configuration");
160
+ }
161
+
162
+ set configuration(configuration) {
163
+ this.store.set("configuration", configuration);
164
+ }
165
+
166
+ get(key) {
167
+ return this.store.get(key) || this._tokenStore.get(key);
168
+ }
169
+
170
+ isAsync() {
171
+ return !!this.useAsyncFactory;
172
+ }
173
+
174
+ clone() {
175
+ const provider = new (classOf(this))(this.token);
176
+ getEnumerableKeys(this).forEach(key => {
177
+ if (this[key] !== undefined) {
178
+ provider[key] = this[key];
179
+ }
180
+ });
181
+ return provider;
182
+ }
183
+
184
+ toString() {
185
+ return ["Token", this.name, this.useClass && nameOf(this.useClass), this.useFactory && "Factory", this.useValue && "Value", this.useAsyncFactory && "AsyncFactory"].filter(Boolean).join(":");
186
+ }
187
+
188
+ }
189
+
190
+ __decorate([Enumerable(), __metadata("design:type", Object)], Provider.prototype, "type", void 0);
191
+
192
+ __decorate([Enumerable(), __metadata("design:type", Boolean)], Provider.prototype, "injectable", void 0);
193
+
194
+ __decorate([Enumerable(), __metadata("design:type", Object)], Provider.prototype, "instance", void 0);
195
+
196
+ __decorate([Enumerable(), __metadata("design:type", Array)], Provider.prototype, "deps", void 0);
197
+
198
+ __decorate([Enumerable(), __metadata("design:type", Array)], Provider.prototype, "imports", void 0);
199
+
200
+ __decorate([Enumerable(), __metadata("design:type", Function)], Provider.prototype, "useFactory", void 0);
201
+
202
+ __decorate([Enumerable(), __metadata("design:type", Function)], Provider.prototype, "useAsyncFactory", void 0);
203
+
204
+ __decorate([Enumerable(), __metadata("design:type", Object)], Provider.prototype, "useValue", void 0);
205
+
206
+ __decorate([NotEnumerable(), __metadata("design:type", Object)], Provider.prototype, "_provide", void 0);
207
+
208
+ __decorate([NotEnumerable(), __metadata("design:type", Type)], Provider.prototype, "_useClass", void 0);
209
+
210
+ __decorate([NotEnumerable(), __metadata("design:type", Object)], Provider.prototype, "_instance", void 0);
211
+
212
+ __decorate([NotEnumerable(), __metadata("design:type", Store)], Provider.prototype, "_store", void 0);
213
+
214
+ __decorate([NotEnumerable(), __metadata("design:type", Store)], Provider.prototype, "_tokenStore", void 0);
215
+
216
+ __decorate([Enumerable(), __metadata("design:type", Type), __metadata("design:paramtypes", [Type])], Provider.prototype, "useClass", null);
217
+
218
+ __decorate([Enumerable(), __metadata("design:type", String), __metadata("design:paramtypes", [String])], Provider.prototype, "scope", null);
219
+
220
+ __decorate([Enumerable(), __metadata("design:type", Object), __metadata("design:paramtypes", [Object])], Provider.prototype, "configuration", null);
221
+
222
+ var _settings = /*#__PURE__*/_classPrivateFieldLooseKey("settings");
223
+
224
+ class GlobalProviderRegistry extends Map {
225
+ constructor() {
226
+ super(...arguments);
227
+ Object.defineProperty(this, _settings, {
228
+ writable: true,
229
+ value: void 0
230
+ });
231
+ _classPrivateFieldLooseBase(this, _settings)[_settings] = new Map();
232
+ }
233
+
234
+ /**
235
+ * The get() method returns a specified element from a Map object.
236
+ * @param key Required. The key of the element to return from the Map object.
237
+ * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.
238
+ */
239
+ get(key) {
240
+ return super.get(getClassOrSymbol(key));
241
+ }
242
+ /**
243
+ * The has() method returns a boolean indicating whether an element with the specified key exists or not.
244
+ * @param key
245
+ * @returns {boolean}
246
+ */
247
+
248
+
249
+ has(key) {
250
+ return super.has(getClassOrSymbol(key));
251
+ }
252
+ /**
253
+ * The set() method adds or updates an element with a specified key and value to a Map object.
254
+ * @param key Required. The key of the element to add to the Map object.
255
+ * @param metadata Required. The value of the element to add to the Map object.
256
+ */
257
+
258
+
259
+ set(key, metadata) {
260
+ super.set(getClassOrSymbol(key), metadata);
261
+ return this;
262
+ }
263
+ /**
264
+ *
265
+ * @param target
266
+ * @param options
267
+ */
268
+
269
+
270
+ merge(target, options) {
271
+ const meta = this.createIfNotExists(target, options);
272
+ Object.keys(options).forEach(key => {
273
+ meta[key] = options[key];
274
+ });
275
+ this.set(target, meta);
276
+ }
277
+ /**
278
+ * The delete() method removes the specified element from a Map object.
279
+ * @param key Required. The key of the element to remove from the Map object.
280
+ * @returns {boolean} Returns true if an element in the Map object existed and has been removed, or false if the element does not exist.
281
+ */
282
+
283
+
284
+ delete(key) {
285
+ return super.delete(getClassOrSymbol(key));
286
+ }
287
+
288
+ createRegistry(type, model, options = {
289
+ injectable: true
290
+ }) {
291
+ const defaultOptions = this.getRegistrySettings(type);
292
+ options = Object.assign(defaultOptions, _extends({}, options, {
293
+ model
294
+ }));
295
+
296
+ _classPrivateFieldLooseBase(this, _settings)[_settings].set(type, options);
297
+
298
+ return this;
299
+ }
300
+
301
+ getRegistrySettings(target) {
302
+ let type = "provider";
303
+
304
+ if (typeof target === "string") {
305
+ type = target;
306
+ } else {
307
+ const provider = this.get(target);
308
+
309
+ if (provider) {
310
+ type = provider.type;
311
+ }
312
+ }
313
+
314
+ return _classPrivateFieldLooseBase(this, _settings)[_settings].get(type) || {
315
+ model: Provider,
316
+ injectable: true
317
+ };
318
+ }
319
+
320
+ createRegisterFn(type) {
321
+ return (provider, instance) => {
322
+ if (!provider.provide) {
323
+ provider = {
324
+ provide: provider
325
+ };
326
+ }
327
+
328
+ provider = Object.assign({
329
+ instance
330
+ }, provider, {
331
+ type
332
+ });
333
+ this.merge(provider.provide, provider);
334
+ };
335
+ }
336
+ /**
337
+ * @deprecated
338
+ */
339
+ // istanbul ignore next
340
+
341
+
342
+ getRegistry(target) {
343
+ return this;
344
+ }
345
+ /**
346
+ *
347
+ * @param key
348
+ * @param options
349
+ */
350
+
351
+
352
+ createIfNotExists(key, options) {
353
+ const type = options.type || ProviderType.PROVIDER;
354
+
355
+ if (!this.has(key)) {
356
+ const {
357
+ model = Provider
358
+ } = _classPrivateFieldLooseBase(this, _settings)[_settings].get(type) || {};
359
+ const item = new model(key);
360
+ this.set(key, item);
361
+ }
362
+
363
+ return this.get(key);
364
+ }
365
+
366
+ }
367
+ /**
368
+ *
369
+ * @type {GlobalProviders}
370
+ */
371
+ // tslint:disable-next-line: variable-name
372
+
373
+ const GlobalProviders = new GlobalProviderRegistry();
374
+
375
+ class LocalsContainer extends Map {
376
+ /**
377
+ * Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
378
+ * @param eventName The event name to emit at all services.
379
+ * @param args List of the parameters to give to each services.
380
+ * @returns {Promise<any[]>} A list of promises.
381
+ */
382
+ async emit(eventName, ...args) {
383
+ for (const handler of this.getListeners(eventName)) {
384
+ await handler(...args);
385
+ }
386
+ }
387
+ /**
388
+ * @param eventName
389
+ * @param value
390
+ * @param args
391
+ */
392
+
393
+
394
+ alter(eventName, value, ...args) {
395
+ for (const handler of this.getListeners(eventName)) {
396
+ value = handler(value, ...args);
397
+ }
398
+
399
+ return value;
400
+ }
401
+ /**
402
+ * @param eventName
403
+ * @param value
404
+ * @param args
405
+ */
406
+
407
+
408
+ async alterAsync(eventName, value, ...args) {
409
+ for (const handler of this.getListeners(eventName)) {
410
+ value = handler(value, ...args);
411
+ }
412
+
413
+ return value;
414
+ }
415
+
416
+ toArray() {
417
+ return [...this.values()];
418
+ }
419
+
420
+ async destroy() {
421
+ await this.emit("$onDestroy");
422
+ this.clear();
423
+ }
424
+
425
+ getListeners(event) {
426
+ return this.toArray().reduce((listeners, instance) => {
427
+ if (typeof instance === "object" && instance && event in instance) {
428
+ return listeners.concat(instance[event].bind(instance));
429
+ }
430
+
431
+ return listeners;
432
+ }, []);
433
+ }
434
+
435
+ }
436
+
437
+ class Container extends LocalsContainer {
438
+ /**
439
+ *
440
+ * @param token
441
+ * @param settings
442
+ */
443
+ add(token, settings = {}) {
444
+ const provider = GlobalProviders.has(token) ? GlobalProviders.get(token).clone() : new Provider(token);
445
+ Object.assign(provider, settings);
446
+ return super.set(token, provider);
447
+ }
448
+ /**
449
+ * Add a provider to the
450
+ * @param token
451
+ * @param settings
452
+ */
453
+
454
+
455
+ addProvider(token, settings = {}) {
456
+ return this.add(token, settings);
457
+ }
458
+ /**
459
+ *
460
+ * @param token
461
+ */
462
+
463
+
464
+ hasProvider(token) {
465
+ return super.has(token);
466
+ }
467
+ /**
468
+ * Add a provider to the
469
+ * @param token
470
+ * @param provider
471
+ */
472
+
473
+
474
+ setProvider(token, provider) {
475
+ return super.set(token, provider);
476
+ }
477
+ /**
478
+ * The getProvider() method returns a specified element from a Map object.
479
+ * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.
480
+ * @param token
481
+ */
482
+
483
+
484
+ getProvider(token) {
485
+ return super.get(token);
486
+ }
487
+ /**
488
+ * Get all providers registered in the injector container.
489
+ *
490
+ * @param {ProviderType} type Filter the list by the given ProviderType.
491
+ * @returns {[TokenProvider , Provider<any>][]}
492
+ */
493
+
494
+
495
+ getProviders(type) {
496
+ return Array.from(this).filter(([_, provider]) => type ? provider.type === type : true).map(([_, provider]) => provider);
497
+ }
498
+
499
+ addProviders(container) {
500
+ container.forEach(provider => {
501
+ if (!this.hasProvider(provider.provide)) {
502
+ this.setProvider(provider.provide, provider.clone());
503
+ }
504
+ });
505
+ }
506
+
507
+ }
508
+
509
+ var InjectablePropertyType;
510
+
511
+ (function (InjectablePropertyType) {
512
+ InjectablePropertyType["METHOD"] = "method";
513
+ InjectablePropertyType["PROPERTY"] = "property";
514
+ InjectablePropertyType["CONSTANT"] = "constant";
515
+ InjectablePropertyType["VALUE"] = "value";
516
+ InjectablePropertyType["INTERCEPTOR"] = "interceptor";
517
+ })(InjectablePropertyType || (InjectablePropertyType = {}));
518
+
519
+ var _additionalProps = /*#__PURE__*/_classPrivateFieldLooseKey("additionalProps");
520
+
521
+ var _dateStart = /*#__PURE__*/_classPrivateFieldLooseKey("dateStart");
522
+
523
+ var _ignoreLog = /*#__PURE__*/_classPrivateFieldLooseKey("ignoreLog");
524
+
525
+ var _stack = /*#__PURE__*/_classPrivateFieldLooseKey("stack");
526
+
527
+ var _level = /*#__PURE__*/_classPrivateFieldLooseKey("level");
528
+
529
+ class ContextLogger {
530
+ constructor(logger, {
531
+ id,
532
+ url = "",
533
+ dateStart = new Date(),
534
+ ignoreUrlPatterns = [],
535
+ minimalRequestPicker,
536
+ completeRequestPicker,
537
+ level = "all",
538
+ maxStackSize = 30,
539
+ ignoreLog,
540
+ additionalProps
541
+ }) {
542
+ Object.defineProperty(this, _additionalProps, {
543
+ writable: true,
544
+ value: void 0
545
+ });
546
+ Object.defineProperty(this, _dateStart, {
547
+ writable: true,
548
+ value: void 0
549
+ });
550
+ Object.defineProperty(this, _ignoreLog, {
551
+ writable: true,
552
+ value: void 0
553
+ });
554
+ Object.defineProperty(this, _stack, {
555
+ writable: true,
556
+ value: void 0
557
+ });
558
+ Object.defineProperty(this, _level, {
559
+ writable: true,
560
+ value: void 0
561
+ });
562
+ this.logger = logger;
563
+ _classPrivateFieldLooseBase(this, _stack)[_stack] = [];
564
+ this.id = id;
565
+ this.url = url;
566
+ _classPrivateFieldLooseBase(this, _additionalProps)[_additionalProps] = additionalProps || {};
567
+ _classPrivateFieldLooseBase(this, _dateStart)[_dateStart] = dateStart;
568
+
569
+ _classPrivateFieldLooseBase(this, _ignoreLog)[_ignoreLog] = ignoreLog || (() => false);
570
+
571
+ this.minimalRequestPicker = minimalRequestPicker || (l => l);
572
+
573
+ this.completeRequestPicker = completeRequestPicker || (l => l); // @ts-ignore
574
+
575
+
576
+ _classPrivateFieldLooseBase(this, _level)[_level] = levels()[level.toUpperCase()] || levels().ALL;
577
+ this.maxStackSize = maxStackSize;
578
+ }
579
+
580
+ info(obj) {
581
+ this.run(levels().INFO, obj, obj => this.minimalRequestPicker(this.getData(obj)));
582
+ return this;
583
+ }
584
+
585
+ debug(obj, withRequest = true) {
586
+ this.run(levels().DEBUG, obj, obj => {
587
+ obj = this.getData(obj);
588
+ return withRequest ? this.completeRequestPicker(obj) : obj;
589
+ });
590
+ return this;
591
+ }
592
+
593
+ warn(obj) {
594
+ this.run(levels().WARN, obj, obj => this.completeRequestPicker(this.getData(obj)));
595
+ return this;
596
+ }
597
+
598
+ error(obj) {
599
+ this.run(levels().ERROR, obj, obj => this.completeRequestPicker(this.getData(obj)));
600
+ return this;
601
+ }
602
+
603
+ trace(obj) {
604
+ this.run(levels().TRACE, obj, obj => this.completeRequestPicker(this.getData(obj)));
605
+ return this;
606
+ }
607
+
608
+ flush() {
609
+ if (_classPrivateFieldLooseBase(this, _stack)[_stack].length) {
610
+ _classPrivateFieldLooseBase(this, _stack)[_stack].forEach(({
611
+ level,
612
+ data
613
+ }) => {
614
+ this.logger[level](data);
615
+ });
616
+
617
+ _classPrivateFieldLooseBase(this, _stack)[_stack] = [];
618
+ }
619
+ }
620
+
621
+ isLevelEnabled(otherLevel) {
622
+ return _classPrivateFieldLooseBase(this, _level)[_level].isLessThanOrEqualTo(otherLevel);
623
+ }
624
+
625
+ destroy() {
626
+ this.flush();
627
+ this.logger = undefined;
628
+ _classPrivateFieldLooseBase(this, _stack)[_stack] = undefined;
629
+ }
630
+ /**
631
+ * Return the duration between the time when LogIncomingRequest has handle the request and now.
632
+ * @returns {number}
633
+ */
634
+
635
+
636
+ getDuration() {
637
+ return new Date().getTime() - _classPrivateFieldLooseBase(this, _dateStart)[_dateStart].getTime();
638
+ }
639
+
640
+ getData(obj) {
641
+ if (typeof obj === "string") {
642
+ obj = {
643
+ message: obj
644
+ };
645
+ }
646
+
647
+ return _extends({}, _classPrivateFieldLooseBase(this, _additionalProps)[_additionalProps], {
648
+ reqId: this.id,
649
+ time: new Date(),
650
+ duration: this.getDuration()
651
+ }, obj);
652
+ }
653
+
654
+ run(level, obj, mapper) {
655
+ if (!this.isLevelEnabled(level)) {
656
+ return;
657
+ }
658
+
659
+ if (!_classPrivateFieldLooseBase(this, _ignoreLog)[_ignoreLog](obj)) {
660
+ _classPrivateFieldLooseBase(this, _stack)[_stack].push({
661
+ level: level.levelStr.toLowerCase(),
662
+ data: mapper(obj)
663
+ });
664
+ }
665
+
666
+ if (this.maxStackSize < _classPrivateFieldLooseBase(this, _stack)[_stack].length) {
667
+ this.flush();
668
+ }
669
+ }
670
+
671
+ }
672
+
673
+ const _excluded$1 = ["id", "injector", "logger", "ignoreLog"];
674
+ class DIContext extends Map {
675
+ constructor(_ref) {
676
+ let {
677
+ id,
678
+ injector,
679
+ logger,
680
+ ignoreLog
681
+ } = _ref,
682
+ options = _objectWithoutPropertiesLoose(_ref, _excluded$1);
683
+
684
+ super();
685
+ /**
686
+ * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.
687
+ */
688
+
689
+ this.dateStart = new Date();
690
+ /**
691
+ * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`
692
+ */
693
+
694
+ this.container = new LocalsContainer();
695
+ this.id = id;
696
+ injector && (this.injector = injector);
697
+ this.logger = new ContextLogger(logger, _extends({}, options, {
698
+ dateStart: this.dateStart,
699
+ id,
700
+ ignoreLog
701
+ }));
702
+ }
703
+
704
+ get env() {
705
+ return this.injector.settings.env;
706
+ }
707
+
708
+ async destroy() {
709
+ await this.container.destroy();
710
+ this.logger.destroy(); // @ts-ignore
711
+
712
+ delete this.container; // @ts-ignore
713
+
714
+ delete this.logger; // @ts-ignore
715
+
716
+ delete this.injector;
717
+ }
718
+
719
+ async emit(eventName, ...args) {
720
+ var _this$injector;
721
+
722
+ return (_this$injector = this.injector) == null ? void 0 : _this$injector.emit(eventName, ...args);
723
+ }
724
+
725
+ }
726
+
727
+ /**
728
+ *
729
+ * @param {"request" | "singleton" | ProviderScope} scope
730
+ * @returns {Function}
731
+ * @constructor
732
+ */
733
+
734
+ function Scope(scope = ProviderScope.REQUEST) {
735
+ return StoreSet("scope", scope);
736
+ }
737
+
738
+ /**
739
+ *
740
+ */
741
+
742
+ GlobalProviders.createRegistry(ProviderType.CONTROLLER, Provider, {
743
+ injectable: false
744
+ });
745
+ /**
746
+ * Register a provider configuration.
747
+ * @param {IProvider<any>} provider
748
+ */
749
+
750
+ function registerProvider(provider) {
751
+ if (!provider.provide) {
752
+ throw new Error("Provider.provide is required");
753
+ }
754
+
755
+ GlobalProviders.merge(provider.provide, provider);
756
+ }
757
+ /**
758
+ * Add a new factory in the `ProviderRegistry`.
759
+ *
760
+ * #### Example with symbol definition
761
+ *
762
+ *
763
+ * ```typescript
764
+ * import {registerFactory, InjectorService} from "@tsed/di";
765
+ *
766
+ * export interface IMyFooFactory {
767
+ * getFoo(): string;
768
+ * }
769
+ *
770
+ * export type MyFooFactory = IMyFooFactory;
771
+ * export const MyFooFactory = Symbol("MyFooFactory");
772
+ *
773
+ * registerFactory(MyFooFactory, {
774
+ * getFoo: () => "test"
775
+ * });
776
+ *
777
+ * // or
778
+ *
779
+ * registerFactory({provide: MyFooFactory, instance: {
780
+ * getFoo: () => "test"
781
+ * }});
782
+ *
783
+ * @Service()
784
+ * export class OtherService {
785
+ * constructor(@Inject(MyFooFactory) myFooFactory: MyFooFactory){
786
+ * console.log(myFooFactory.getFoo()); /// "test"
787
+ * }
788
+ * }
789
+ * ```
790
+ *
791
+ * > Note: When you use the factory method with Symbol definition, you must use the `@Inject()`
792
+ * decorator to retrieve your factory in another Service. Advice: By convention all factory class name will be prefixed by
793
+ * `Factory`.
794
+ *
795
+ * #### Example with class
796
+ *
797
+ * ```typescript
798
+ * import {InjectorService, registerFactory} from "@tsed/di";
799
+ *
800
+ * export class MyFooService {
801
+ * constructor(){}
802
+ * getFoo() {
803
+ * return "test";
804
+ * }
805
+ * }
806
+ *
807
+ * registerFactory(MyFooService, new MyFooService());
808
+ * // or
809
+ * registerFactory({provider: MyFooService, instance: new MyFooService()});
810
+ *
811
+ * @Service()
812
+ * export class OtherService {
813
+ * constructor(myFooService: MyFooService){
814
+ * console.log(myFooFactory.getFoo()); /// "test"
815
+ * }
816
+ * }
817
+ * ```
818
+ * @deprecated Since 2021-05-15. Use registerProvider instead.
819
+ */
820
+
821
+ const registerFactory = registerProvider;
822
+ /**
823
+ * Add a new value in the `ProviderRegistry`.
824
+ *
825
+ * #### Example with symbol definition
826
+ *
827
+ *
828
+ * ```typescript
829
+ * import {registerValue, InjectorService} from "@tsed/di";
830
+ *
831
+ * const MyValue = Symbol.from("MyValue")
832
+ *
833
+ * registerValue({token: MyValue, useValue: "myValue"});
834
+ *
835
+ * @Service()
836
+ * export class OtherService {
837
+ * constructor(@Inject(MyValue) myValue: string){
838
+ * console.log(myValue); /// "myValue"
839
+ * }
840
+ * }
841
+ * ```
842
+ */
843
+
844
+ const registerValue = (provider, value) => {
845
+ if (!provider.provide) {
846
+ provider = {
847
+ provide: provider
848
+ };
849
+ }
850
+
851
+ provider = Object.assign({
852
+ scope: ProviderScope.SINGLETON,
853
+ useValue: value
854
+ }, provider, {
855
+ type: ProviderType.VALUE
856
+ });
857
+ GlobalProviders.merge(provider.provide, provider);
858
+ };
859
+ /**
860
+ * Add a new service in the `ProviderRegistry`. This service will be built when `InjectorService` will be loaded.
861
+ *
862
+ * #### Example
863
+ *
864
+ * ```typescript
865
+ * import {registerService, InjectorService} from "@tsed/di";
866
+ *
867
+ * export default class MyFooService {
868
+ * constructor(){}
869
+ * getFoo() {
870
+ * return "test";
871
+ * }
872
+ * }
873
+ *
874
+ * registerService({provide: MyFooService});
875
+ * // or
876
+ * registerService(MyFooService);
877
+ *
878
+ * const injector = new InjectorService();
879
+ * injector.load();
880
+ *
881
+ * const myFooService = injector.get<MyFooService>(MyFooService);
882
+ * myFooService.getFoo(); // test
883
+ * ```
884
+ *
885
+ * @param provider Provider configuration.
886
+ * @deprecated Since 2021-05-15. Use registerProvider instead.
887
+ */
888
+
889
+ const registerService = GlobalProviders.createRegisterFn(ProviderType.SERVICE);
890
+ /**
891
+ * Add a new controller in the `ProviderRegistry`. This controller will be built when `InjectorService` will be loaded.
892
+ *
893
+ * #### Example
894
+ *
895
+ * ```typescript
896
+ * import {registerController, InjectorService} from "@tsed/di";
897
+ *
898
+ * export default class MyController {
899
+ * constructor(){}
900
+ * transform() {
901
+ * return "test";
902
+ * }
903
+ * }
904
+ *
905
+ * registerController({provide: MyController});
906
+ * // or
907
+ * registerController(MyController);
908
+ *
909
+ * const injector = new InjectorService();
910
+ * injector.load();
911
+ *
912
+ * const myController = injector.get<MyController>(MyController);
913
+ * myController.getFoo(); // test
914
+ * ```
915
+ *
916
+ * @param provider Provider configuration.
917
+ */
918
+
919
+ const registerController = GlobalProviders.createRegisterFn(ProviderType.CONTROLLER);
920
+
921
+ /**
922
+ * The decorators `@Injectable()` declare a new service can be injected in other service, controller, interceptor, etc.. on there `constructor`.
923
+ * All classes annotated with `@Injectable()` are built one time, excepted if you change the default provider configuration.
924
+ *
925
+ * <<< @/docs/snippets/providers/getting-started-injectable.ts
926
+ *
927
+ * ::: tip
928
+ * `@Injectable()` use the `reflect-metadata` to collect and inject the built provided to other services.
929
+ * :::
930
+ *
931
+ * ### Options
932
+ *
933
+ * - type (@@ProviderType@@ or `string`): Kind of provider. (Default: `ProviderType.PROVIDER`)
934
+ * - scope (@@ProviderScope@): Kind of provider. (Default: `ProviderScope.SINGLETON`)
935
+ * - deps (`Type<any>`): List of class or provider which will be injected to the constructor (Note: This options override default metadata generated by Typescript).
936
+ *
937
+ * @returns {Function}
938
+ * @decorator
939
+ */
940
+
941
+ function Injectable(options = {}) {
942
+ return provide => {
943
+ registerProvider(_extends({}, options, {
944
+ provide
945
+ }));
946
+ };
947
+ }
948
+
949
+ /**
950
+ * The decorators `@Service()` declare a new service can be injected in other service or controller on there `constructor`.
951
+ * All services annotated with `@Service()` are constructed one time.
952
+ *
953
+ * > `@Service()` use the `reflect-metadata` to collect and inject service on controllers or other services.
954
+ *
955
+ * @returns {Function}
956
+ * @decorator
957
+ */
958
+
959
+ function Service() {
960
+ return Injectable();
961
+ }
962
+
963
+ /**
964
+ * Override a provider which is already registered in ProviderRegistry.
965
+ * @returns {Function}
966
+ * @decorators
967
+ * @param originalProvider
968
+ */
969
+
970
+ function OverrideProvider(originalProvider) {
971
+ return target => {
972
+ GlobalProviders.get(originalProvider).useClass = target;
973
+ };
974
+ }
975
+
976
+ /**
977
+ * Inject a provider to another provider.
978
+ *
979
+ * Use this decorator to inject a custom provider on constructor parameter or property.
980
+ *
981
+ * ```typescript
982
+ * @Injectable()
983
+ * export class MyService {
984
+ * @Inject(CONNECTION)
985
+ * connection: CONNECTION;
986
+ * }
987
+ * ```
988
+ *
989
+ * @param symbol
990
+ * @param onGet Use the given name method to inject
991
+ * @returns {Function}
992
+ * @decorator
993
+ */
994
+
995
+ function Inject(symbol, onGet) {
996
+ return (target, propertyKey, descriptor) => {
997
+ const bindingType = decoratorTypeOf([target, propertyKey, descriptor]);
998
+
999
+ switch (bindingType) {
1000
+ case DecoratorTypes.PARAM:
1001
+ case DecoratorTypes.PARAM_CTOR:
1002
+ if (symbol) {
1003
+ const paramTypes = Metadata.getParamTypes(target, propertyKey);
1004
+ paramTypes[descriptor] = symbol;
1005
+ Metadata.setParamTypes(target, propertyKey, paramTypes);
1006
+ }
1007
+
1008
+ break;
1009
+
1010
+ case DecoratorTypes.PROP:
1011
+ Store.from(target).merge(INJECTABLE_PROP, {
1012
+ [propertyKey]: {
1013
+ bindingType,
1014
+ propertyKey,
1015
+ onGet,
1016
+ useType: symbol || Metadata.getType(target, propertyKey)
1017
+ }
1018
+ });
1019
+ break;
1020
+
1021
+ case DecoratorTypes.METHOD:
1022
+ Store.from(target).merge(INJECTABLE_PROP, {
1023
+ [propertyKey]: {
1024
+ bindingType,
1025
+ propertyKey
1026
+ }
1027
+ });
1028
+ return descriptor;
1029
+
1030
+ default:
1031
+ throw new UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);
1032
+ }
1033
+ };
1034
+ }
1035
+
1036
+ /**
1037
+ * Return value from Configuration.
1038
+ *
1039
+ * ## Example
1040
+ *
1041
+ * ```typescript
1042
+ * import {Env} from "@tsed/core";
1043
+ * import {Constant, Value} from "@tsed/di";
1044
+ *
1045
+ * export class MyClass {
1046
+ *
1047
+ * @Constant("env")
1048
+ * env: Env;
1049
+ *
1050
+ * @Value("swagger.path")
1051
+ * swaggerPath: string;
1052
+ *
1053
+ * @Value("swagger.path", "defaultValue")
1054
+ * swaggerPath: string;
1055
+ *
1056
+ * constructor() {
1057
+ * console.log(this.swaggerPath) // undefined. Not available on constructor
1058
+ * }
1059
+ *
1060
+ * $onInit() {
1061
+ * console.log(this.swaggerPath) // something
1062
+ * }
1063
+ * }
1064
+ * ```
1065
+ *
1066
+ * @param {string} expression
1067
+ * @param defaultValue
1068
+ * @returns {(targetClass: any, attributeName: string) => any}
1069
+ * @decorator
1070
+ */
1071
+
1072
+ function Constant(expression, defaultValue) {
1073
+ return (target, propertyKey) => {
1074
+ Store.from(target).merge(INJECTABLE_PROP, {
1075
+ [propertyKey]: {
1076
+ bindingType: InjectablePropertyType.CONSTANT,
1077
+ propertyKey,
1078
+ expression,
1079
+ defaultValue
1080
+ }
1081
+ });
1082
+ };
1083
+ }
1084
+
1085
+ /**
1086
+ * Return value from Configuration.
1087
+ *
1088
+ * ## Example
1089
+ *
1090
+ * ```typescript
1091
+ * import {Env} from "@tsed/core";
1092
+ * import {Constant, Value} from "@tsed/di";
1093
+ *
1094
+ * export class MyClass {
1095
+ *
1096
+ * @Constant("env")
1097
+ * env: Env;
1098
+ *
1099
+ * @Value("swagger.path")
1100
+ * swaggerPath: string;
1101
+ *
1102
+ * @Value("swagger.path", "defaultValue")
1103
+ * swaggerPath: string;
1104
+ *
1105
+ * constructor() {
1106
+ * console.log(this.swaggerPath) // undefined. Not available on constructor
1107
+ * }
1108
+ *
1109
+ * $onInit() {
1110
+ * console.log(this.swaggerPath) // something
1111
+ * }
1112
+ * }
1113
+ * ```
1114
+ *
1115
+ * @param expression
1116
+ * @param defaultValue
1117
+ * @returns {(targetClass: any, attributeName: string) => any}
1118
+ * @decorator
1119
+ */
1120
+
1121
+ function Value(expression, defaultValue) {
1122
+ return (target, propertyKey) => {
1123
+ Store.from(target).merge(INJECTABLE_PROP, {
1124
+ [propertyKey]: {
1125
+ bindingType: InjectablePropertyType.VALUE,
1126
+ propertyKey,
1127
+ expression,
1128
+ defaultValue
1129
+ }
1130
+ });
1131
+ };
1132
+ }
1133
+
1134
+ /**
1135
+ * Attaches interceptor to method call and executes the before and after methods
1136
+ *
1137
+ * @param interceptor
1138
+ * @param options
1139
+ * @decorator
1140
+ */
1141
+
1142
+ function Intercept(interceptor, options) {
1143
+ return (target, propertyKey, descriptor) => {
1144
+ Store.from(target).merge(INJECTABLE_PROP, {
1145
+ [propertyKey]: {
1146
+ bindingType: InjectablePropertyType.INTERCEPTOR,
1147
+ propertyKey,
1148
+ useType: interceptor,
1149
+ options
1150
+ }
1151
+ });
1152
+ return descriptor;
1153
+ };
1154
+ }
1155
+
1156
+ /**
1157
+ * The decorators `@Service()` declare a new service can be injected in other service or controller on there `constructor`.
1158
+ * All services annotated with `@Service()` are constructed one time.
1159
+ *
1160
+ * > `@Service()` use the `reflect-metadata` to collect and inject service on controllers or other services.
1161
+ *
1162
+ * @returns {Function}
1163
+ * @decorator
1164
+ */
1165
+
1166
+ function Interceptor() {
1167
+ return Injectable({
1168
+ type: ProviderType.INTERCEPTOR
1169
+ });
1170
+ }
1171
+
1172
+ /**
1173
+ * Get or set Configuration on a class.
1174
+ *
1175
+ * @decorator
1176
+ */
1177
+
1178
+ function Configuration(configuration = {}) {
1179
+ return (...args) => {
1180
+ switch (decoratorTypeOf(args)) {
1181
+ case DecoratorTypes.CLASS:
1182
+ StoreSet("configuration", configuration)(args[0]);
1183
+ break;
1184
+
1185
+ default:
1186
+ case DecoratorTypes.PARAM_CTOR:
1187
+ return Inject(Configuration)(args[0], args[1], args[2]);
1188
+ }
1189
+ };
1190
+ }
1191
+
1192
+ const _excluded = ["scopes", "imports", "resolvers", "deps", "scope"];
1193
+ /**
1194
+ * Declare a new Ts.ED module
1195
+ *
1196
+ * ## Options
1197
+ * - imports: List of Provider which must be built by injector before invoking the module
1198
+ * - resolvers: List of external DI must be used to resolve unknown provider
1199
+ * - deps: List of provider must be injected to the module constructor (explicit declaration)
1200
+ *
1201
+ * @param options
1202
+ * @decorator
1203
+ */
1204
+
1205
+ function Module(options = {}) {
1206
+ const {
1207
+ imports,
1208
+ resolvers,
1209
+ deps
1210
+ } = options,
1211
+ configuration = _objectWithoutPropertiesLoose(options, _excluded);
1212
+
1213
+ return useDecorators(Configuration(configuration), Injectable({
1214
+ type: ProviderType.MODULE,
1215
+ scope: ProviderScope.SINGLETON,
1216
+ imports,
1217
+ deps,
1218
+ injectable: false,
1219
+ resolvers
1220
+ }));
1221
+ }
1222
+
1223
+ /**
1224
+ * Get instance options. This options depending on his invocation context.
1225
+ *
1226
+ * ```typescript
1227
+ * import {Injectable, Opts, UseOpts} from "@tsed/di";
1228
+ *
1229
+ * @Injectable()
1230
+ * class MyConfigurableService {
1231
+ * source: string;
1232
+ * constructor(@Opts options: any = {}) {
1233
+ * console.log("Hello ", options.source); // log: Hello Service1 then Hello Service2
1234
+ *
1235
+ * this.source = options.source;
1236
+ * }
1237
+ * }
1238
+ *
1239
+ * @Injectable()
1240
+ * class MyService1 {
1241
+ * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {
1242
+ * console.log(service.source) // log: Service1
1243
+ * }
1244
+ * }
1245
+ *
1246
+ * @Injectable()
1247
+ * class MyService2 {
1248
+ * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {
1249
+ * console.log(service.source) // log: Service2
1250
+ * }
1251
+ * }
1252
+ * ```
1253
+ *
1254
+ * ::: warning
1255
+ * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.
1256
+ * :::
1257
+ *
1258
+ * @param target
1259
+ * @param propertyKey
1260
+ * @param index
1261
+ * @decorator
1262
+ */
1263
+
1264
+ function Opts(target, propertyKey, index) {
1265
+ Scope(ProviderScope.INSTANCE)(classOf(target));
1266
+ Inject(DI_PARAM_OPTIONS)(target, propertyKey, index);
1267
+ }
1268
+
1269
+ /**
1270
+ * Add options to invoke the Service.
1271
+ *
1272
+ * ```typescript
1273
+ * import {Injectable, Opts, UseOpts} from "@tsed/di";
1274
+ *
1275
+ * @Injectable()
1276
+ * class MyConfigurableService {
1277
+ * source: string;
1278
+ * constructor(@Opts options: any = {}) {
1279
+ * console.log("Hello ", options.source); // log: Hello Service1 then Hello Service2
1280
+ *
1281
+ * this.source = options.source;
1282
+ * }
1283
+ * }
1284
+ *
1285
+ * @Injectable()
1286
+ * class MyService1 {
1287
+ * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {
1288
+ * console.log(service.source) // log: Service1
1289
+ * }
1290
+ * }
1291
+ *
1292
+ * @Injectable()
1293
+ * class MyService2 {
1294
+ * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {
1295
+ * console.log(service.source) // log: Service2
1296
+ * }
1297
+ * }
1298
+ * ```
1299
+ *
1300
+ * ::: warning
1301
+ * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.
1302
+ * :::
1303
+ *
1304
+ * @returns {Function}
1305
+ * @decorator
1306
+ * @param options
1307
+ */
1308
+
1309
+ function UseOpts(options) {
1310
+ return (target, propertyKey, index) => {
1311
+ const bindingType = decoratorTypeOf([target, propertyKey, index]);
1312
+
1313
+ switch (bindingType) {
1314
+ case DecoratorTypes.PARAM_CTOR:
1315
+ Store.from(target).merge(`${DI_PARAM_OPTIONS}:${index}`, options);
1316
+ break;
1317
+
1318
+ case DecoratorTypes.PROP:
1319
+ Store.from(target).merge(INJECTABLE_PROP, {
1320
+ [propertyKey]: {
1321
+ options
1322
+ }
1323
+ });
1324
+ break;
1325
+
1326
+ default:
1327
+ throw new UnsupportedDecoratorType(UseOpts, [target, propertyKey, index]);
1328
+ }
1329
+ };
1330
+ }
1331
+
1332
+ class InjectionError extends Error {
1333
+ constructor(token, origin) {
1334
+ super(isString(origin) ? origin : "");
1335
+ this.name = "INJECTION_ERROR";
1336
+ this.tokens = [];
1337
+ this.tokens = [token];
1338
+
1339
+ if (origin) {
1340
+ if (isString(origin)) {
1341
+ this.origin = {
1342
+ message: origin,
1343
+ stack: this.stack
1344
+ };
1345
+ } else {
1346
+ if (origin.tokens) {
1347
+ this.tokens = this.tokens.concat(origin.tokens);
1348
+ this.origin = origin.origin;
1349
+ } else {
1350
+ this.origin = origin;
1351
+ this.stack = origin.stack;
1352
+ }
1353
+ }
1354
+ }
1355
+
1356
+ const originMessage = this.origin ? "\nOrigin: " + this.origin.message : "";
1357
+ const tokensMessage = this.tokens.map(token => nameOf(token)).join(" > ");
1358
+ this.message = `Injection failed on ${tokensMessage}${originMessage}`;
1359
+ }
1360
+
1361
+ static throwInjectorError(token, currentDependency, error) {
1362
+ if (currentDependency && isClass(token)) {
1363
+ error.message = printDependencyInjectionError(token, _extends({}, currentDependency, {
1364
+ message: error.message
1365
+ }));
1366
+ }
1367
+
1368
+ throw new InjectionError(token, error);
1369
+ }
1370
+
1371
+ }
1372
+
1373
+ function printDependencyInjectionError(token, options) {
1374
+ let erroredArg = "";
1375
+ const args = getConstructorArgNames(token).map((arg, index) => {
1376
+ if (options.index === index) {
1377
+ erroredArg = arg;
1378
+ arg = chalk.red(arg);
1379
+ }
1380
+
1381
+ return `${arg}: ${nameOf(options.deps[index])}`;
1382
+ }).join(", ");
1383
+ const signature = nameOf(token) + "->constructor(" + args + ")";
1384
+ const indexOf = signature.indexOf(erroredArg) - 5;
1385
+
1386
+ const drawline = indexOf => " ".repeat(indexOf) + chalk.red("^" + "‾".repeat(erroredArg.length - 1));
1387
+
1388
+ return "Unable to inject dependency. " + options.message + "\n\n" + signature + "\n" + (indexOf > -1 ? drawline(indexOf) : "");
1389
+ }
1390
+
1391
+ class UndefinedTokenError extends Error {
1392
+ constructor() {
1393
+ super("Given token is undefined. Have you enabled emitDecoratorMetadata in your tsconfig.json or decorated your class with @Injectable, @Service, ... decorator ?");
1394
+ this.name = "UNDEFINED_TOKEN_ERROR";
1395
+ }
1396
+
1397
+ }
1398
+
1399
+ function createContainer(rootModule) {
1400
+ const container = new Container(GlobalProviders.entries());
1401
+
1402
+ if (rootModule) {
1403
+ container.delete(rootModule);
1404
+ }
1405
+
1406
+ return container;
1407
+ }
1408
+
1409
+ class DIConfiguration {
1410
+ constructor(initialProps = {}) {
1411
+ this.default = new Map();
1412
+ this.map = new Map();
1413
+ Object.entries(_extends({
1414
+ scopes: {},
1415
+ resolvers: [],
1416
+ imports: []
1417
+ }, initialProps)).forEach(([key, value]) => {
1418
+ this.default.set(key, value);
1419
+ });
1420
+ return proxyDelegation(this, {
1421
+ ownKeys(target) {
1422
+ return [...target.default.keys(), ...target.map.keys()];
1423
+ }
1424
+
1425
+ });
1426
+ }
1427
+
1428
+ get scopes() {
1429
+ return this.getRaw("scopes");
1430
+ }
1431
+
1432
+ set scopes(value) {
1433
+ this.setRaw("scopes", value);
1434
+ }
1435
+
1436
+ get resolvers() {
1437
+ return this.getRaw("resolvers");
1438
+ }
1439
+
1440
+ set resolvers(resolvers) {
1441
+ this.setRaw("resolvers", resolvers);
1442
+ }
1443
+
1444
+ get imports() {
1445
+ return this.getRaw("imports");
1446
+ }
1447
+
1448
+ set imports(imports) {
1449
+ this.setRaw("imports", imports);
1450
+ }
1451
+ /**
1452
+ *
1453
+ * @param callbackfn
1454
+ * @param thisArg
1455
+ */
1456
+
1457
+
1458
+ forEach(callbackfn, thisArg) {
1459
+ return new Set([...Array.from(this.default.keys()), ...Array.from(this.map.keys())]).forEach(key => {
1460
+ callbackfn(this.getRaw(key), key, this.map);
1461
+ }, thisArg);
1462
+ }
1463
+ /**
1464
+ *
1465
+ * @param propertyKey
1466
+ * @param value
1467
+ */
1468
+
1469
+
1470
+ set(propertyKey, value) {
1471
+ if (typeof propertyKey === "string") {
1472
+ this.setRaw(propertyKey, value);
1473
+ } else {
1474
+ Object.entries(propertyKey).forEach(([key, value]) => {
1475
+ this[key] = value;
1476
+ });
1477
+ }
1478
+
1479
+ return this;
1480
+ }
1481
+
1482
+ setRaw(propertyKey, value) {
1483
+ setValue(this.map, propertyKey, value);
1484
+ return this;
1485
+ }
1486
+ /**
1487
+ *
1488
+ * @param propertyKey
1489
+ * @param defaultValue
1490
+ * @returns {undefined|any}
1491
+ */
1492
+
1493
+
1494
+ get(propertyKey, defaultValue) {
1495
+ return this.resolve(this.getRaw(propertyKey, defaultValue));
1496
+ }
1497
+
1498
+ getRaw(propertyKey, defaultValue) {
1499
+ const value = getValue(this.map, propertyKey);
1500
+
1501
+ if (value !== undefined) {
1502
+ return value;
1503
+ }
1504
+
1505
+ return getValue(this.default, propertyKey, defaultValue);
1506
+ }
1507
+
1508
+ merge(obj) {
1509
+ Object.entries(obj).forEach(([key, value]) => {
1510
+ const descriptor = Object.getOwnPropertyDescriptor(DIConfiguration.prototype, key);
1511
+ const originalValue = this.get(key);
1512
+ value = deepMerge(value, originalValue);
1513
+
1514
+ if (descriptor && !["default", "set", "map", "get"].includes(key)) {
1515
+ this[key] = value;
1516
+ }
1517
+ });
1518
+ }
1519
+ /**
1520
+ *
1521
+ * @param value
1522
+ * @returns {any}
1523
+ */
1524
+
1525
+
1526
+ resolve(value) {
1527
+ if (typeof value === "object" && value !== null) {
1528
+ if (![Array, Object].includes(classOf(value))) {
1529
+ return value;
1530
+ }
1531
+
1532
+ return Object.entries(value).reduce((o, [k, v]) => {
1533
+ // @ts-ignore
1534
+ o[k] = this.resolve(v);
1535
+ return o;
1536
+ }, Array.isArray(value) ? [] : {});
1537
+ }
1538
+
1539
+ if (typeof value === "string") {
1540
+ const replacer = (match, key) => getValue(this.map, key);
1541
+
1542
+ return value.replace(/\${([\w.]+)}/gi, replacer).replace(/<([\w.]+)>/gi, replacer).replace(/{{([\w.]+)}}/gi, replacer);
1543
+ }
1544
+
1545
+ return value;
1546
+ }
1547
+
1548
+ build() {
1549
+ this.forEach((value, key) => this.map.set(key, this.resolve(value)));
1550
+ this.set = this.setRaw;
1551
+
1552
+ this.get = this.getRaw = (propertyKey, defaultValue) => getValue(this.map, propertyKey, defaultValue);
1553
+ }
1554
+
1555
+ }
1556
+
1557
+ var InjectorService_1;
1558
+ /**
1559
+ * This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.
1560
+ *
1561
+ * ### Example:
1562
+ *
1563
+ * ```typescript
1564
+ * import {InjectorService} from "@tsed/di";
1565
+ *
1566
+ * // Import the services (all services are decorated with @Service()";
1567
+ * import MyService1 from "./services/service1";
1568
+ * import MyService2 from "./services/service2";
1569
+ * import MyService3 from "./services/service3";
1570
+ *
1571
+ * // When all services is imported you can load InjectorService.
1572
+ * const injector = new InjectorService()
1573
+ *
1574
+ * await injector.load();
1575
+ *
1576
+ * const myService1 = injector.get<MyService1>(MyServcice1);
1577
+ * ```
1578
+ */
1579
+
1580
+ let InjectorService = InjectorService_1 = class InjectorService extends Container {
1581
+ constructor() {
1582
+ super();
1583
+ this.settings = new DIConfiguration();
1584
+ this.logger = console;
1585
+ this.resolvedConfiguration = false;
1586
+ const provider = this.addProvider(InjectorService_1).getProvider(InjectorService_1);
1587
+ provider.instance = this;
1588
+ }
1589
+
1590
+ get resolvers() {
1591
+ return this.settings.resolvers;
1592
+ }
1593
+
1594
+ get scopes() {
1595
+ return this.settings.scopes || {};
1596
+ }
1597
+ /**
1598
+ * Retrieve default scope for a given provider.
1599
+ * @param provider
1600
+ */
1601
+
1602
+
1603
+ scopeOf(provider) {
1604
+ return provider.scope || this.scopes[provider.type] || ProviderScope.SINGLETON;
1605
+ }
1606
+ /**
1607
+ * Clone a provider from GlobalProviders and the given token. forkProvider method build automatically the provider if the instance parameter ins't given.
1608
+ * @param token
1609
+ * @param settings
1610
+ */
1611
+
1612
+
1613
+ forkProvider(token, settings = {}) {
1614
+ if (!this.hasProvider(token)) {
1615
+ this.addProvider(token);
1616
+ }
1617
+
1618
+ const provider = this.getProvider(token);
1619
+ Object.assign(provider, settings);
1620
+ provider.instance = this.invoke(token);
1621
+ return provider;
1622
+ }
1623
+ /**
1624
+ * Return a list of instance build by the injector.
1625
+ */
1626
+
1627
+
1628
+ toArray() {
1629
+ return super.toArray().map(provider => provider.instance);
1630
+ }
1631
+ /**
1632
+ * Get a service or factory already constructed from his symbol or class.
1633
+ *
1634
+ * #### Example
1635
+ *
1636
+ * ```typescript
1637
+ * import {InjectorService} from "@tsed/di";
1638
+ * import MyService from "./services";
1639
+ *
1640
+ * class OtherService {
1641
+ * constructor(injectorService: InjectorService) {
1642
+ * const myService = injectorService.get<MyService>(MyService);
1643
+ * }
1644
+ * }
1645
+ * ```
1646
+ *
1647
+ * @param token The class or symbol registered in InjectorService.
1648
+ * @param options
1649
+ * @returns {boolean}
1650
+ */
1651
+
1652
+
1653
+ get(token, options = {}) {
1654
+ var _super$get;
1655
+
1656
+ const instance = (_super$get = super.get(getClassOrSymbol(token))) == null ? void 0 : _super$get.instance;
1657
+
1658
+ if (instance !== undefined) {
1659
+ return instance;
1660
+ }
1661
+
1662
+ if (!this.hasProvider(token)) {
1663
+ for (const resolver of this.resolvers) {
1664
+ const result = resolver.get(token, options);
1665
+
1666
+ if (result !== undefined) {
1667
+ return result;
1668
+ }
1669
+ }
1670
+ }
1671
+ }
1672
+ /**
1673
+ * The has() method returns a boolean indicating whether an element with the specified key exists or not.
1674
+ * @returns {boolean}
1675
+ * @param token
1676
+ */
1677
+
1678
+
1679
+ has(token) {
1680
+ return super.has(getClassOrSymbol(token)) && this.get(token) !== undefined;
1681
+ }
1682
+ /**
1683
+ * Invoke the class and inject all services that required by the class constructor.
1684
+ *
1685
+ * #### Example
1686
+ *
1687
+ * ```typescript
1688
+ * import {InjectorService} from "@tsed/di";
1689
+ * import MyService from "./services";
1690
+ *
1691
+ * class OtherService {
1692
+ * constructor(injectorService: InjectorService) {
1693
+ * const myService = injectorService.invoke<MyService>(MyService);
1694
+ * }
1695
+ * }
1696
+ * ```
1697
+ *
1698
+ * @param token The injectable class to invoke. Class parameters are injected according constructor signature.
1699
+ * @param locals Optional object. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.
1700
+ * @param options
1701
+ * @returns {T} The class constructed.
1702
+ */
1703
+
1704
+
1705
+ invoke(token, locals = new LocalsContainer(), options = {}) {
1706
+ const provider = this.ensureProvider(token);
1707
+ let instance;
1708
+ !locals.has(Configuration) && locals.set(Configuration, this.settings);
1709
+
1710
+ if (locals.has(token)) {
1711
+ return locals.get(token);
1712
+ }
1713
+
1714
+ if (token === DI_PARAM_OPTIONS) {
1715
+ return {};
1716
+ }
1717
+
1718
+ if (!provider || options.rebuild) {
1719
+ instance = this.resolve(token, locals, options);
1720
+ this.hasProvider(token) && (this.getProvider(token).instance = instance);
1721
+ return instance;
1722
+ }
1723
+
1724
+ switch (this.scopeOf(provider)) {
1725
+ case ProviderScope.SINGLETON:
1726
+ if (!this.has(token)) {
1727
+ provider.instance = this.resolve(token, locals, options);
1728
+
1729
+ if (provider.isAsync()) {
1730
+ provider.instance.then(instance => {
1731
+ provider.instance = instance;
1732
+ });
1733
+ }
1734
+ }
1735
+
1736
+ instance = this.get(token);
1737
+ break;
1738
+
1739
+ case ProviderScope.REQUEST:
1740
+ instance = this.resolve(token, locals, options);
1741
+ locals.set(token, instance);
1742
+ break;
1743
+
1744
+ case ProviderScope.INSTANCE:
1745
+ instance = this.resolve(provider.provide, locals, options);
1746
+ break;
1747
+ }
1748
+
1749
+ return instance;
1750
+ }
1751
+ /**
1752
+ * Build only providers which are asynchronous.
1753
+ */
1754
+
1755
+
1756
+ async loadAsync(locals = new LocalsContainer()) {
1757
+ for (const [, provider] of this) {
1758
+ if (!locals.has(provider.token)) {
1759
+ if (provider.isAsync()) {
1760
+ await this.invoke(provider.token, locals);
1761
+ }
1762
+
1763
+ if (provider.instance) {
1764
+ locals.set(provider.token, provider.instance);
1765
+ }
1766
+ }
1767
+ }
1768
+
1769
+ return locals;
1770
+ }
1771
+
1772
+ loadSync(locals = new LocalsContainer()) {
1773
+ for (const [, provider] of this) {
1774
+ if (!locals.has(provider.token) && this.scopeOf(provider) === ProviderScope.SINGLETON) {
1775
+ this.invoke(provider.token, locals);
1776
+ }
1777
+
1778
+ if (provider.instance !== undefined) {
1779
+ locals.set(provider.token, provider.instance);
1780
+ }
1781
+ }
1782
+
1783
+ return locals;
1784
+ }
1785
+ /**
1786
+ * Boostrap injector from container and resolve configuration.
1787
+ *
1788
+ * @param container
1789
+ */
1790
+
1791
+
1792
+ bootstrap(container = createContainer()) {
1793
+ // Clone all providers in the container
1794
+ this.addProviders(container); // Resolve all configuration
1795
+
1796
+ this.resolveConfiguration();
1797
+ return this;
1798
+ }
1799
+ /**
1800
+ * Build all providers from given container (or GlobalProviders) and emit `$onInit` event.
1801
+ *
1802
+ * @param container
1803
+ * @param rootModule
1804
+ */
1805
+
1806
+
1807
+ async load(container = createContainer(), rootModule) {
1808
+ this.bootstrap(container); // build async and sync provider
1809
+
1810
+ let locals = await this.loadAsync();
1811
+
1812
+ if (rootModule) {
1813
+ await this.invoke(rootModule);
1814
+ } // load sync provider
1815
+
1816
+
1817
+ locals = this.loadSync(locals);
1818
+ await locals.emit("$onInit");
1819
+ return locals;
1820
+ }
1821
+ /**
1822
+ * Load all configurations registered on providers
1823
+ */
1824
+
1825
+
1826
+ resolveConfiguration() {
1827
+ if (this.resolvedConfiguration) {
1828
+ return;
1829
+ }
1830
+
1831
+ const mergedConfiguration = new Map();
1832
+ super.forEach(provider => {
1833
+ if (provider.configuration) {
1834
+ Object.entries(provider.configuration).forEach(([key, value]) => {
1835
+ value = mergedConfiguration.has(key) ? deepMerge(mergedConfiguration.get(key), value) : deepClone(value);
1836
+ mergedConfiguration.set(key, value);
1837
+ });
1838
+ }
1839
+
1840
+ if (provider.resolvers) {
1841
+ this.resolvers.push(...provider.resolvers);
1842
+ }
1843
+ });
1844
+ mergedConfiguration.forEach((value, key) => {
1845
+ this.settings[key] = deepMerge(value, this.settings[key]);
1846
+ });
1847
+ this.settings.build();
1848
+ this.resolvedConfiguration = true;
1849
+ }
1850
+ /**
1851
+ *
1852
+ * @param instance
1853
+ * @param locals
1854
+ * @param options
1855
+ */
1856
+
1857
+
1858
+ bindInjectableProperties(instance, locals, options) {
1859
+ const properties = ancestorsOf(classOf(instance)).reduce((properties, target) => {
1860
+ const store = Store.from(target);
1861
+ return _extends({}, properties, store.get(INJECTABLE_PROP) || {});
1862
+ }, {});
1863
+ Object.values(properties).forEach(definition => {
1864
+ switch (definition.bindingType) {
1865
+ case InjectablePropertyType.METHOD:
1866
+ this.bindMethod(instance, definition);
1867
+ break;
1868
+
1869
+ case InjectablePropertyType.PROPERTY:
1870
+ this.bindProperty(instance, definition, locals, options);
1871
+ break;
1872
+
1873
+ case InjectablePropertyType.CONSTANT:
1874
+ this.bindConstant(instance, definition);
1875
+ break;
1876
+
1877
+ case InjectablePropertyType.VALUE:
1878
+ this.bindValue(instance, definition);
1879
+ break;
1880
+
1881
+ case InjectablePropertyType.INTERCEPTOR:
1882
+ this.bindInterceptor(instance, definition);
1883
+ break;
1884
+ }
1885
+ });
1886
+ }
1887
+ /**
1888
+ *
1889
+ * @param instance
1890
+ * @param {string} propertyKey
1891
+ */
1892
+
1893
+
1894
+ bindMethod(instance, {
1895
+ propertyKey
1896
+ }) {
1897
+ const target = classOf(instance);
1898
+ const originalMethod = instance[propertyKey];
1899
+ const deps = Metadata.getParamTypes(prototypeOf(target), propertyKey);
1900
+
1901
+ instance[propertyKey] = () => {
1902
+ const services = deps.map(dependency => this.get(dependency));
1903
+ return originalMethod.call(instance, ...services);
1904
+ };
1905
+ }
1906
+ /**
1907
+ * Create an injectable property.
1908
+ *
1909
+ * @param instance
1910
+ * @param {string} propertyKey
1911
+ * @param {any} useType
1912
+ * @param onGet
1913
+ * @param options
1914
+ * @param locals
1915
+ * @param invokeOptions
1916
+ */
1917
+
1918
+
1919
+ bindProperty(instance, {
1920
+ propertyKey,
1921
+ useType,
1922
+ onGet = f => f,
1923
+ options
1924
+ }, locals, invokeOptions) {
1925
+ invokeOptions = _extends({}, invokeOptions);
1926
+ locals.set(DI_PARAM_OPTIONS, _extends({}, options));
1927
+ let bean = this.invoke(useType, locals, invokeOptions);
1928
+ locals.delete(DI_PARAM_OPTIONS);
1929
+
1930
+ if (isPromise(bean)) {
1931
+ bean.then(result => {
1932
+ bean = result;
1933
+ });
1934
+ }
1935
+
1936
+ Object.defineProperty(instance, propertyKey, {
1937
+ get: () => onGet(bean)
1938
+ });
1939
+ }
1940
+ /**
1941
+ *
1942
+ * @param instance
1943
+ * @param {string} propertyKey
1944
+ * @param {any} useType
1945
+ */
1946
+
1947
+
1948
+ bindValue(instance, {
1949
+ propertyKey,
1950
+ expression,
1951
+ defaultValue
1952
+ }) {
1953
+ const descriptor = {
1954
+ get: () => this.settings.get(expression) || defaultValue,
1955
+ set: value => this.settings.set(expression, value),
1956
+ enumerable: true,
1957
+ configurable: true
1958
+ };
1959
+ Object.defineProperty(instance, propertyKey, descriptor);
1960
+ }
1961
+ /**
1962
+ *
1963
+ * @param instance
1964
+ * @param {string} propertyKey
1965
+ * @param {any} useType
1966
+ */
1967
+
1968
+
1969
+ bindConstant(instance, {
1970
+ propertyKey,
1971
+ expression,
1972
+ defaultValue
1973
+ }) {
1974
+ const clone = o => {
1975
+ if (o) {
1976
+ return Object.freeze(deepClone(o));
1977
+ }
1978
+
1979
+ return defaultValue;
1980
+ };
1981
+
1982
+ const descriptor = {
1983
+ get: () => clone(this.settings.get(expression)),
1984
+ enumerable: true,
1985
+ configurable: true
1986
+ };
1987
+ Object.defineProperty(instance, propertyKey, descriptor);
1988
+ return descriptor;
1989
+ }
1990
+ /**
1991
+ *
1992
+ * @param instance
1993
+ * @param propertyKey
1994
+ * @param useType
1995
+ * @param options
1996
+ */
1997
+
1998
+
1999
+ bindInterceptor(instance, {
2000
+ propertyKey,
2001
+ useType,
2002
+ options
2003
+ }) {
2004
+ const target = classOf(instance);
2005
+ const originalMethod = instance[propertyKey];
2006
+
2007
+ instance[propertyKey] = (...args) => {
2008
+ const next = err => {
2009
+ if (!err) {
2010
+ return originalMethod.apply(instance, args);
2011
+ }
2012
+
2013
+ throw err;
2014
+ };
2015
+
2016
+ const context = {
2017
+ target,
2018
+ propertyKey,
2019
+ args,
2020
+ options,
2021
+ next
2022
+ };
2023
+ const interceptor = this.get(useType);
2024
+ return interceptor.intercept(_extends({}, context, {
2025
+ options
2026
+ }), next);
2027
+ };
2028
+ }
2029
+ /**
2030
+ * Allow handler hack for AsyncHookContext plugin.
2031
+ * @param ctx
2032
+ * @param cb
2033
+ * @protected
2034
+ */
2035
+
2036
+
2037
+ runInContext(ctx, cb) {
2038
+ return cb();
2039
+ }
2040
+
2041
+ ensureProvider(token) {
2042
+ if (!this.hasProvider(token) && GlobalProviders.has(token)) {
2043
+ this.addProvider(token);
2044
+ }
2045
+
2046
+ return this.getProvider(token);
2047
+ }
2048
+ /**
2049
+ * Invoke a class method and inject service.
2050
+ *
2051
+ * #### IInjectableMethod options
2052
+ *
2053
+ * * **target**: Optional. The class instance.
2054
+ * * **methodName**: `string` Optional. The method name.
2055
+ * * **designParamTypes**: `any[]` Optional. List of injectable types.
2056
+ * * **locals**: `Map<Function, any>` Optional. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.
2057
+ *
2058
+ * #### Example
2059
+ *
2060
+ * @param target
2061
+ * @param locals
2062
+ * @param options
2063
+ * @private
2064
+ */
2065
+
2066
+
2067
+ resolve(target, locals, options = {}) {
2068
+ const {
2069
+ token,
2070
+ deps,
2071
+ construct,
2072
+ isBindable,
2073
+ imports,
2074
+ provider
2075
+ } = this.mapInvokeOptions(target, locals, options);
2076
+
2077
+ if (provider) {
2078
+ if (!provider.injectable && options.parent) {
2079
+ throw new InjectionError(token, `${nameOf(token)} ${provider.type} is not injectable to another provider`);
2080
+ }
2081
+
2082
+ const {
2083
+ onInvoke
2084
+ } = GlobalProviders.getRegistrySettings(target);
2085
+
2086
+ if (onInvoke) {
2087
+ onInvoke(provider, locals, deps);
2088
+ }
2089
+ }
2090
+
2091
+ let instance;
2092
+ let currentDependency = false;
2093
+
2094
+ try {
2095
+ const invokeDependency = parent => (token, index) => {
2096
+ currentDependency = {
2097
+ token,
2098
+ index,
2099
+ deps
2100
+ };
2101
+
2102
+ if (token !== DI_PARAM_OPTIONS) {
2103
+ var _provider$store;
2104
+
2105
+ const options = provider == null ? void 0 : (_provider$store = provider.store) == null ? void 0 : _provider$store.get(`${DI_PARAM_OPTIONS}:${index}`);
2106
+ locals.set(DI_PARAM_OPTIONS, options || {});
2107
+ }
2108
+
2109
+ return isInheritedFrom(token, Provider, 1) ? provider : this.invoke(token, locals, {
2110
+ parent
2111
+ });
2112
+ }; // Invoke manually imported providers
2113
+
2114
+
2115
+ imports.forEach(invokeDependency()); // Inject dependencies
2116
+
2117
+ const services = deps.map(invokeDependency(token));
2118
+ currentDependency = false;
2119
+ instance = construct(services);
2120
+ } catch (error) {
2121
+ InjectionError.throwInjectorError(token, currentDependency, error);
2122
+ }
2123
+
2124
+ if (instance === undefined) {
2125
+ throw new InjectionError(token, `Unable to create new instance from undefined value. Check your provider declaration for ${nameOf(token)}`);
2126
+ }
2127
+
2128
+ if (instance && isBindable) {
2129
+ this.bindInjectableProperties(instance, locals, options);
2130
+ }
2131
+
2132
+ return instance;
2133
+ }
2134
+ /**
2135
+ * Create options to invoke a provider or class.
2136
+ * @param token
2137
+ * @param locals
2138
+ * @param options
2139
+ */
2140
+
2141
+
2142
+ mapInvokeOptions(token, locals, options) {
2143
+ let imports = options.imports;
2144
+ let deps = options.deps;
2145
+ let scope = options.scope;
2146
+ let construct;
2147
+ let isBindable = false;
2148
+
2149
+ if (!token) {
2150
+ throw new UndefinedTokenError();
2151
+ }
2152
+
2153
+ let provider;
2154
+
2155
+ if (!this.hasProvider(token)) {
2156
+ provider = new Provider(token);
2157
+ this.resolvers.forEach(resolver => {
2158
+ const result = resolver.get(token, locals.get(DI_PARAM_OPTIONS));
2159
+
2160
+ if (result !== undefined) {
2161
+ provider.useFactory = () => result;
2162
+ }
2163
+ });
2164
+ } else {
2165
+ provider = this.getProvider(token);
2166
+ }
2167
+
2168
+ scope = scope || this.scopeOf(provider);
2169
+ deps = deps || provider.deps;
2170
+ imports = imports || provider.imports;
2171
+
2172
+ if (provider.useValue !== undefined) {
2173
+ construct = () => isFunction(provider.useValue) ? provider.useValue() : provider.useValue;
2174
+ } else if (provider.useFactory) {
2175
+ construct = deps => provider.useFactory(...deps);
2176
+ } else if (provider.useAsyncFactory) {
2177
+ construct = deps => provider.useAsyncFactory(...deps);
2178
+ } else {
2179
+ // useClass
2180
+ isBindable = true;
2181
+ deps = deps || Metadata.getParamTypes(provider.useClass);
2182
+
2183
+ construct = deps => new provider.useClass(...deps);
2184
+ }
2185
+
2186
+ return {
2187
+ token,
2188
+ scope: scope || Store.from(token).get("scope") || ProviderScope.SINGLETON,
2189
+ deps: deps || [],
2190
+ imports: imports || [],
2191
+ isBindable,
2192
+ construct,
2193
+ provider
2194
+ };
2195
+ }
2196
+
2197
+ };
2198
+ InjectorService = InjectorService_1 = __decorate([Injectable({
2199
+ scope: ProviderScope.SINGLETON,
2200
+ global: true
2201
+ }), __metadata("design:paramtypes", [])], InjectorService);
2202
+
2203
+ registerProvider({
2204
+ provide: Logger,
2205
+ deps: [InjectorService],
2206
+
2207
+ useFactory(injector) {
2208
+ return injector.logger;
2209
+ }
2210
+
2211
+ });
2212
+
2213
+ /**
2214
+ * @ignore
2215
+ * @param injector
2216
+ */
2217
+ function setLoggerLevel(injector) {
2218
+ var _injector$settings$lo;
2219
+
2220
+ const level = (_injector$settings$lo = injector.settings.logger) == null ? void 0 : _injector$settings$lo.level;
2221
+
2222
+ if (level) {
2223
+ injector.logger.level = level;
2224
+ }
2225
+ }
2226
+
2227
+ /**
2228
+ * Tool to run test with lightweight DI sandbox.
2229
+ */
2230
+
2231
+ class DITest {
2232
+ static get injector() {
2233
+ if (DITest._injector) {
2234
+ return DITest._injector;
2235
+ }
2236
+ /* istanbul ignore next */
2237
+
2238
+
2239
+ throw new Error("PlatformTest.injector is not initialized. Use PlatformTest.create(): Promise before PlatformTest.invoke() or PlatformTest.injector.\n" + "Example:\n" + "before(async () => {\n" + " await PlatformTest.create()\n" + " await PlatformTest.invoke(MyService, [])\n" + "})");
2240
+ }
2241
+
2242
+ static set injector(injector) {
2243
+ DITest._injector = injector;
2244
+ }
2245
+
2246
+ static hasInjector() {
2247
+ return !!DITest._injector;
2248
+ }
2249
+
2250
+ static async create(settings = {}) {
2251
+ DITest.injector = DITest.createInjector(settings);
2252
+ const container = new Container();
2253
+ DITest.injector.bootstrap(container);
2254
+ await DITest.injector.load(container);
2255
+ }
2256
+ /**
2257
+ * Create a new injector with the right default services
2258
+ */
2259
+
2260
+
2261
+ static createInjector(settings = {}) {
2262
+ const injector = new InjectorService();
2263
+ injector.logger = $log; // @ts-ignore
2264
+
2265
+ injector.settings.set(DITest.configure(settings));
2266
+ setLoggerLevel(injector);
2267
+ return injector;
2268
+ }
2269
+ /**
2270
+ * Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.
2271
+ */
2272
+
2273
+
2274
+ static async reset() {
2275
+ if (DITest.hasInjector()) {
2276
+ await DITest.injector.destroy();
2277
+ DITest._injector = null;
2278
+ }
2279
+ }
2280
+ /**
2281
+ * Invoke a provider and return a fresh instance
2282
+ * @param target
2283
+ * @param providers
2284
+ */
2285
+
2286
+
2287
+ static invoke(target, providers = []) {
2288
+ const locals = new LocalsContainer();
2289
+ providers.forEach(p => {
2290
+ locals.set(p.token, p.use);
2291
+ });
2292
+ locals.set(InjectorService, DITest.injector);
2293
+ const instance = DITest.injector.invoke(target, locals, {
2294
+ rebuild: true
2295
+ });
2296
+
2297
+ if (instance && instance.$onInit) {
2298
+ // await instance.$onInit();
2299
+ const result = instance.$onInit();
2300
+
2301
+ if (result instanceof Promise) {
2302
+ return result.then(() => instance);
2303
+ }
2304
+ }
2305
+
2306
+ return instance;
2307
+ }
2308
+ /**
2309
+ * Return the instance from injector registry
2310
+ * @param target
2311
+ * @param options
2312
+ */
2313
+
2314
+
2315
+ static get(target, options = {}) {
2316
+ return DITest.injector.get(target, options);
2317
+ }
2318
+
2319
+ static configure(settings = {}) {
2320
+ return _extends({}, settings, {
2321
+ env: getValue(settings, "env", Env.TEST),
2322
+ logger: _extends({}, getValue(settings, "logger", {}), {
2323
+ level: getValue(settings, "logger.level", "off")
2324
+ })
2325
+ });
2326
+ }
2327
+
2328
+ }
2329
+ DITest._injector = null;
2330
+
2331
+ function isTsEnv() {
2332
+ return require && require.extensions && require.extensions[".ts"] || process.env["TS_TEST"] || process.env.JEST_WORKER_ID !== undefined || process.env.NODE_ENV === "test";
2333
+ }
2334
+
2335
+ function mapExcludes(excludes) {
2336
+ return excludes.map(s => `!${s.replace(/!/gi, "")}`);
2337
+ }
2338
+
2339
+ function mapExtensions(file) {
2340
+ if (!isTsEnv()) {
2341
+ file = file.replace(/\.ts$/i, ".js").replace(/{\.ts,\.js}$/i, ".js");
2342
+ }
2343
+
2344
+ return file;
2345
+ }
2346
+
2347
+ function cleanGlobPatterns(files, excludes) {
2348
+ return [].concat(files).map(s => resolve(s)).concat(mapExcludes(excludes)).map(mapExtensions).map(s => normalizePath(s));
2349
+ }
2350
+
2351
+ async function importFiles(patterns, exclude) {
2352
+ const files = await globby(cleanGlobPatterns(patterns, exclude));
2353
+ const symbols = [];
2354
+
2355
+ for (const file of files) {
2356
+ if (!file.endsWith(".d.ts")) {
2357
+ // prevent .d.ts import if the global pattern isn't correctly configured
2358
+ try {
2359
+ const exports = await import(file);
2360
+ Object.keys(exports).forEach(key => symbols.push(exports[key]));
2361
+ } catch (er) {
2362
+ // istanbul ignore next
2363
+ console.error(er); // istanbul ignore next
2364
+
2365
+ process.exit(1);
2366
+ }
2367
+ }
2368
+ }
2369
+
2370
+ return symbols;
2371
+ }
2372
+
2373
+ async function resolveSymbols(item, excludes) {
2374
+ if (isClass(item)) {
2375
+ return [item];
2376
+ }
2377
+ /* istanbul ignore else */
2378
+
2379
+
2380
+ if (!process.env.WEBPACK) {
2381
+ return importFiles(item, excludes);
2382
+ }
2383
+ /* istanbul ignore next */
2384
+
2385
+
2386
+ return [];
2387
+ }
2388
+
2389
+ function mapConfiguration(config) {
2390
+ if (isArray(config)) {
2391
+ return config.map(value => {
2392
+ return {
2393
+ values: [].concat(value)
2394
+ };
2395
+ });
2396
+ }
2397
+
2398
+ return Object.keys(config).reduce((list, key) => {
2399
+ list.push({
2400
+ endpoint: key,
2401
+ values: [].concat(config[key])
2402
+ });
2403
+ return list;
2404
+ }, []);
2405
+ }
2406
+ async function importComponents(config, excludes) {
2407
+ if (!config) {
2408
+ return [];
2409
+ }
2410
+
2411
+ config = mapConfiguration(config);
2412
+ const promises = [];
2413
+
2414
+ for (const option of config) {
2415
+ promises.push(...option.values.map(async value => {
2416
+ const symbols = await resolveSymbols(value, excludes);
2417
+ return symbols.filter(isClass).map(symbol => ({
2418
+ token: symbol,
2419
+ route: option.endpoint
2420
+ }));
2421
+ }));
2422
+ }
2423
+
2424
+ const result = await Promise.all(promises);
2425
+ return result.flat();
2426
+ }
2427
+
2428
+ function getConfiguration(module, configuration = {}) {
2429
+ const store = Store.from(module).get("configuration") || {};
2430
+
2431
+ const config = _extends({}, store, configuration);
2432
+
2433
+ if (store.mount && configuration.mount) {
2434
+ config.mount = deepMerge(store.mount, configuration.mount);
2435
+ }
2436
+
2437
+ if (store.componentsScan && configuration.componentsScan) {
2438
+ config.componentsScan = [...store.componentsScan, ...configuration.componentsScan];
2439
+ }
2440
+
2441
+ return config;
2442
+ }
2443
+
2444
+ async function recursiveImports(providers, settings, properties) {
2445
+ const {
2446
+ exclude = []
2447
+ } = settings;
2448
+ const promises = providers.map(({
2449
+ token
2450
+ }) => GlobalProviders.get(token)).filter(provider => (provider == null ? void 0 : provider.type) === ProviderType.MODULE && provider.configuration).map(provider => importProviders(_extends({
2451
+ exclude
2452
+ }, provider.configuration), properties));
2453
+ return (await Promise.all(promises)).flat();
2454
+ }
2455
+ /**
2456
+ * Import providers from given patterns.
2457
+ *
2458
+ * @param settings
2459
+ * @param properties
2460
+ */
2461
+
2462
+
2463
+ async function importProviders(settings, properties = ["imports"]) {
2464
+ const {
2465
+ exclude = []
2466
+ } = settings;
2467
+ const promises = properties.map(key => importComponents(settings[key], exclude));
2468
+ const providers = (await Promise.all(promises)).flat();
2469
+ const children = await recursiveImports(providers, settings, properties);
2470
+ return [...children, ...providers];
2471
+ }
2472
+
2473
+ export { Configuration, Constant, Container, ContextLogger, DIConfiguration, DIContext, DITest, DI_PARAMS, DI_PARAM_OPTIONS, GlobalProviderRegistry, GlobalProviders, INJECTABLE_PROP, Inject, Injectable, InjectablePropertyType, InjectionError, InjectorService, Intercept, Interceptor, LocalsContainer, Module, Opts, OverrideProvider, Provider, ProviderScope, ProviderType, Scope, Service, UndefinedTokenError, UseOpts, Value, createContainer, getConfiguration, importComponents, importFiles, importProviders, mapConfiguration, registerController, registerFactory, registerProvider, registerService, registerValue, setLoggerLevel };
2474
+ //# sourceMappingURL=index.modern.js.map