@tsed/di 6.107.5 → 6.110.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/lib/cjs/decorators/controller.js.map +1 -1
  2. package/lib/cjs/decorators/injectable.js.map +1 -1
  3. package/lib/cjs/domain/Container.js.map +1 -1
  4. package/lib/cjs/domain/Provider.js.map +1 -1
  5. package/lib/cjs/index.js +49 -49
  6. package/lib/cjs/index.js.map +1 -1
  7. package/lib/cjs/interfaces/{IProvider.js → ProviderOpts.js} +1 -1
  8. package/lib/cjs/interfaces/ProviderOpts.js.map +1 -0
  9. package/lib/cjs/registries/GlobalProviders.js +4 -4
  10. package/lib/cjs/registries/GlobalProviders.js.map +1 -1
  11. package/lib/cjs/registries/ProviderRegistry.js +1 -1
  12. package/lib/cjs/registries/ProviderRegistry.js.map +1 -1
  13. package/lib/cjs/services/InjectorService.js +31 -17
  14. package/lib/cjs/services/InjectorService.js.map +1 -1
  15. package/lib/esm/decorators/controller.js.map +1 -1
  16. package/lib/esm/decorators/injectable.js.map +1 -1
  17. package/lib/esm/domain/Container.js.map +1 -1
  18. package/lib/esm/domain/Provider.js.map +1 -1
  19. package/lib/esm/index.js +1 -1
  20. package/lib/esm/index.js.map +1 -1
  21. package/lib/esm/interfaces/ProviderOpts.js +2 -0
  22. package/lib/esm/interfaces/ProviderOpts.js.map +1 -0
  23. package/lib/esm/registries/GlobalProviders.js.map +1 -1
  24. package/lib/esm/registries/ProviderRegistry.js +1 -1
  25. package/lib/esm/registries/ProviderRegistry.js.map +1 -1
  26. package/lib/esm/services/InjectorService.js +14 -0
  27. package/lib/esm/services/InjectorService.js.map +1 -1
  28. package/lib/types/decorators/controller.d.ts +2 -2
  29. package/lib/types/decorators/injectable.d.ts +2 -2
  30. package/lib/types/domain/Container.d.ts +3 -3
  31. package/lib/types/domain/Provider.d.ts +3 -2
  32. package/lib/types/index.d.ts +1 -1
  33. package/lib/types/interfaces/{IProvider.d.ts → ProviderOpts.d.ts} +10 -4
  34. package/lib/types/registries/GlobalProviders.d.ts +4 -4
  35. package/lib/types/registries/ProviderRegistry.d.ts +4 -4
  36. package/lib/types/services/InjectorService.d.ts +7 -2
  37. package/package.json +19 -8
  38. package/lib/cjs/interfaces/IProvider.js.map +0 -1
  39. package/lib/esm/interfaces/IProvider.js +0 -2
  40. package/lib/esm/interfaces/IProvider.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../src/decorators/controller.ts"],"names":[],"mappings":";;;AAAA,qCAAoE;AACpE,yCAA4C;AAE5C,qEAAkE;AAiBlE,SAAS,UAAU,CAAC,OAAY;IAC9B,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,YAAY,MAAM,IAAI,IAAA,0BAAmB,EAAC,OAAO,CAAC,EAAE;QAC5F,OAAO;YACL,IAAI,EAAE,OAAO;SACd,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,UAAU,CAAC,OAAqC;IAC9D,MAAM,EAAC,QAAQ,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,IAAI,EAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAE3D,OAAO,IAAA,oBAAa,EAClB,CAAC,MAAY,EAAE,EAAE;QACf,IAAA,qCAAkB,EAAC;YACjB,OAAO,EAAE,MAAM;YACf,GAAG,IAAI;SACR,CAAC,CAAC;IACL,CAAC,EACD,IAAI,IAAI,IAAA,aAAI,EAAC,IAAW,CAAC,EACzB,IAAA,iBAAQ,EAAC,GAAG,QAAQ,CAAC,CACtB,CAAC;AACJ,CAAC;AAbD,gCAaC","sourcesContent":["import {isArrayOrArrayClass, Type, useDecorators} from \"@tsed/core\";\nimport {Children, Path} from \"@tsed/schema\";\nimport {IProvider} from \"../interfaces/IProvider\";\nimport {registerController} from \"../registries/ProviderRegistry\";\n\nexport type PathType = string | RegExp | (string | RegExp)[];\n\nexport interface ControllerMiddlewares {\n useBefore: any[];\n use: any[];\n useAfter: any[];\n}\n\nexport interface ControllerOptions extends Partial<IProvider<any>> {\n path?: PathType;\n children?: Type<any>[];\n routerOptions?: any;\n middlewares?: Partial<ControllerMiddlewares>;\n}\n\nfunction mapOptions(options: any): ControllerOptions {\n if (typeof options === \"string\" || options instanceof RegExp || isArrayOrArrayClass(options)) {\n return {\n path: options\n };\n }\n\n return options;\n}\n\n/**\n * Declare a new controller with his Rest path. His methods annotated will be collected to build the routing list.\n * This routing listing will be built with the `express.Router` object.\n *\n * ::: tip\n * See [Controllers](/docs/controllers.md) section for more details\n * :::\n *\n * ```typescript\n * @Controller(\"/calendars\")\n * export provide CalendarCtrl {\n *\n * @Get(\"/:id\")\n * public get(\n * @Req() request: Req,\n * @Res() response: Res,\n * @Next() next: Next\n * ): void {\n *\n * }\n * }\n * ```\n *\n * @param options\n * @controller\n * @decorator\n * @classDecorator\n */\nexport function Controller(options: PathType | ControllerOptions): ClassDecorator {\n const {children = [], path, ...opts} = mapOptions(options);\n\n return useDecorators(\n (target: Type) => {\n registerController({\n provide: target,\n ...opts\n });\n },\n path && Path(path as any),\n Children(...children)\n );\n}\n"]}
1
+ {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../src/decorators/controller.ts"],"names":[],"mappings":";;;AAAA,qCAAoE;AACpE,yCAA4C;AAE5C,qEAAkE;AAiBlE,SAAS,UAAU,CAAC,OAAY;IAC9B,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,YAAY,MAAM,IAAI,IAAA,0BAAmB,EAAC,OAAO,CAAC,EAAE;QAC5F,OAAO;YACL,IAAI,EAAE,OAAO;SACd,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,UAAU,CAAC,OAAqC;IAC9D,MAAM,EAAC,QAAQ,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,IAAI,EAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAE3D,OAAO,IAAA,oBAAa,EAClB,CAAC,MAAY,EAAE,EAAE;QACf,IAAA,qCAAkB,EAAC;YACjB,OAAO,EAAE,MAAM;YACf,GAAG,IAAI;SACR,CAAC,CAAC;IACL,CAAC,EACD,IAAI,IAAI,IAAA,aAAI,EAAC,IAAW,CAAC,EACzB,IAAA,iBAAQ,EAAC,GAAG,QAAQ,CAAC,CACtB,CAAC;AACJ,CAAC;AAbD,gCAaC","sourcesContent":["import {isArrayOrArrayClass, Type, useDecorators} from \"@tsed/core\";\nimport {Children, Path} from \"@tsed/schema\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {registerController} from \"../registries/ProviderRegistry\";\n\nexport type PathType = string | RegExp | (string | RegExp)[];\n\nexport interface ControllerMiddlewares {\n useBefore: any[];\n use: any[];\n useAfter: any[];\n}\n\nexport interface ControllerOptions extends Partial<ProviderOpts<any>> {\n path?: PathType;\n children?: Type<any>[];\n routerOptions?: any;\n middlewares?: Partial<ControllerMiddlewares>;\n}\n\nfunction mapOptions(options: any): ControllerOptions {\n if (typeof options === \"string\" || options instanceof RegExp || isArrayOrArrayClass(options)) {\n return {\n path: options\n };\n }\n\n return options;\n}\n\n/**\n * Declare a new controller with his Rest path. His methods annotated will be collected to build the routing list.\n * This routing listing will be built with the `express.Router` object.\n *\n * ::: tip\n * See [Controllers](/docs/controllers.md) section for more details\n * :::\n *\n * ```typescript\n * @Controller(\"/calendars\")\n * export provide CalendarCtrl {\n *\n * @Get(\"/:id\")\n * public get(\n * @Req() request: Req,\n * @Res() response: Res,\n * @Next() next: Next\n * ): void {\n *\n * }\n * }\n * ```\n *\n * @param options\n * @controller\n * @decorator\n * @classDecorator\n */\nexport function Controller(options: PathType | ControllerOptions): ClassDecorator {\n const {children = [], path, ...opts} = mapOptions(options);\n\n return useDecorators(\n (target: Type) => {\n registerController({\n provide: target,\n ...opts\n });\n },\n path && Path(path as any),\n Children(...children)\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"injectable.js","sourceRoot":"","sources":["../../../src/decorators/injectable.ts"],"names":[],"mappings":";;;AACA,qEAAgE;AAEhE;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,UAAU,CAAC,UAA8B,EAAE;IACzD,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,IAAA,mCAAgB,EAAC;YACf,GAAG,OAAO;YACV,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC,CAAC,EAAC,OAAO,EAAE,MAAM,EAAC,CAAC;SAC9D,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAPD,gCAOC","sourcesContent":["import type {IProvider} from \"../interfaces/IProvider\";\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 * ::: 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 * - provide (@@TokenProvider@@): An injection token (Note: This option override default metadata generated by Typescript).\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> = {}): ClassDecorator {\n return (target: any) => {\n registerProvider({\n ...options,\n ...(options.provide ? {useClass: target} : {provide: target})\n });\n };\n}\n"]}
1
+ {"version":3,"file":"injectable.js","sourceRoot":"","sources":["../../../src/decorators/injectable.ts"],"names":[],"mappings":";;;AACA,qEAAgE;AAEhE;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,UAAU,CAAC,UAAiC,EAAE;IAC5D,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,IAAA,mCAAgB,EAAC;YACf,GAAG,OAAO;YACV,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC,CAAC,EAAC,OAAO,EAAE,MAAM,EAAC,CAAC;SAC9D,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAPD,gCAOC","sourcesContent":["import type {ProviderOpts} from \"../interfaces/ProviderOpts\";\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 * ::: 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 * - provide (@@TokenProvider@@): An injection token (Note: This option override default metadata generated by Typescript).\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<ProviderOpts> = {}): ClassDecorator {\n return (target: any) => {\n registerProvider({\n ...options,\n ...(options.provide ? {useClass: target} : {provide: target})\n });\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Container.js","sourceRoot":"","sources":["../../../src/domain/Container.ts"],"names":[],"mappings":";;;AAGA,mEAA8D;AAC9D,yCAAoC;AAEpC,MAAa,SAAU,SAAQ,GAA4B;IACzD;;;;OAIG;IACI,GAAG,CAAC,KAAoB,EAAE,WAA+B,EAAE;;QAChE,MAAM,QAAQ,GAAG,CAAA,MAAA,iCAAe,CAAC,GAAG,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AC,WAAW,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;aACtD;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAvED,8BAuEC","sourcesContent":["import type {IProvider} from \"../interfaces/IProvider\";\nimport type {ProviderType} from \"./ProviderType\";\nimport type {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {Provider} from \"./Provider\";\n\nexport class Container extends Map<TokenProvider, Provider> {\n /**\n *\n * @param token\n * @param settings\n */\n public add(token: TokenProvider, settings: Partial<IProvider> = {}): this {\n const provider = 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<T extends Provider = Provider>(token: TokenProvider): T | undefined {\n return super.get(token) as T;\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 [...this].reduce((providers, [_, provider]) => {\n if (provider.type === type || !type) {\n return [...providers, provider];\n }\n return providers;\n }, []);\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"]}
1
+ {"version":3,"file":"Container.js","sourceRoot":"","sources":["../../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,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;IAEM,YAAY,CAAC,SAAuC;QACzD,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC7B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;gBACvC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;aACtD;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAvED,8BAuEC","sourcesContent":["import type {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport type {ProviderType} from \"./ProviderType\";\nimport type {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {Provider} from \"./Provider\";\n\nexport class Container extends Map<TokenProvider, Provider> {\n /**\n *\n * @param token\n * @param settings\n */\n public add(token: TokenProvider, settings: Partial<ProviderOpts> = {}): this {\n const provider = 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<ProviderOpts> = {}): 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<T extends Provider = Provider>(token: TokenProvider): T | undefined {\n return super.get(token) as T;\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 [...this].reduce((providers, [_, provider]) => {\n if (provider.type === type || !type) {\n return [...providers, provider];\n }\n return providers;\n }, []);\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../src/domain/Provider.ts"],"names":[],"mappings":";;;AAAA,qCAAmF;AAGnF,mDAA8C;AAC9C,iDAA4C;AAE5C,MAAa,QAAQ;IAkBnB,YAAY,KAAoB,EAAE,UAA6B,EAAE;QAjB1D,SAAI,GAAuB,2BAAY,CAAC,QAAQ,CAAC;QAkBtD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QAEtB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,OAAO,CAAC,KAAoB;QAC9B,IAAI,KAAK,EAAE;YACT,IAAI,CAAC,QAAQ,GAAG,IAAA,uBAAgB,EAAC,KAAK,CAAC,CAAC;YACxC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,MAAM,GAAG,YAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACpD;IACH,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,IAAI,QAAQ,CAAC,KAAc;QACzB,IAAI,IAAA,cAAO,EAAC,KAAK,CAAC,EAAE;YAClB,IAAI,CAAC,SAAS,GAAG,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC;YAChC,IAAI,CAAC,MAAM,GAAG,YAAK,CAAC,IAAI,CA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,CAAC;IAC1D,CAAC;IAED,OAAO;QACL,OAAO,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IAED;;;OAGG;IACI,WAAW;QAChB,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAChC,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC9C,CAAC;IAED,QAAQ;QACN,OAAO;YACL,OAAO;YACP,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,QAAQ,IAAI,IAAA,aAAM,EAAC,IAAI,CAAC,QAAQ,CAAC;YACtC,IAAI,CAAC,UAAU,IAAI,SAAS;YAC5B,IAAI,CAAC,QAAQ,IAAI,OAAO;YACxB,IAAI,CAAC,eAAe,IAAI,cAAc;SACvC;aACE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;CACF;AAxJD,4BAwJC","sourcesContent":["import {classOf, getClassOrSymbol, isClass, nameOf, Store, Type} from \"@tsed/core\";\nimport {IProvider} from \"../interfaces/IProvider\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {ProviderScope} from \"./ProviderScope\";\nimport {ProviderType} from \"./ProviderType\";\n\nexport class Provider<T = any> implements IProvider<T> {\n public type: ProviderType | any = ProviderType.PROVIDER;\n /**\n * @deprecated Use injector.get(provider.token) instead.\n */\n public instance: T;\n public deps: TokenProvider[];\n public imports: any[];\n public useFactory: Function;\n public useAsyncFactory: Function;\n public useValue: any;\n private _useClass: Type<T>;\n private _provide: TokenProvider;\n private _store: Store;\n private _tokenStore: Store;\n\n [key: string]: any;\n\n constructor(token: TokenProvider, options: Partial<Provider> = {}) {\n this.provide = token;\n this.useClass = token;\n\n Object.assign(this, options);\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 = getClassOrSymbol(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 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 get store(): Store {\n return this._store;\n }\n\n get path() {\n return this.store.get(\"path\", \"/\");\n }\n\n set path(path: string) {\n this.store.set(\"path\", path);\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 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 set configuration(configuration: Partial<TsED.Configuration>) {\n this.store.set(\"configuration\", configuration);\n }\n\n get children(): TokenProvider[] {\n return this.store.get(\"childrenControllers\", []);\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 {\n return new (classOf(this))(this._provide, this);\n }\n\n /**\n *\n * @returns {boolean}\n */\n public hasChildren(): boolean {\n return !!this.children.length;\n }\n\n /**\n *\n * @returns {boolean}\n */\n public hasParent(): boolean {\n return !!this.store.get(\"parentController\");\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"]}
1
+ {"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../src/domain/Provider.ts"],"names":[],"mappings":";;;AAAA,qCAAmF;AAGnF,mDAA8C;AAC9C,iDAA4C;AAE5C,MAAa,QAAQ;IAmBnB,YAAY,KAAoB,EAAE,UAA6B,EAAE;QAlB1D,SAAI,GAAuB,2BAAY,CAAC,QAAQ,CAAC;QAmBtD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QAEtB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,OAAO,CAAC,KAAoB;QAC9B,IAAI,KAAK,EAAE;YACT,IAAI,CAAC,QAAQ,GAAG,IAAA,uBAAgB,EAAC,KAAK,CAAC,CAAC;YACxC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,MAAM,GAAG,YAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACpD;IACH,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,IAAI,QAAQ,CAAC,KAAc;QACzB,IAAI,IAAA,cAAO,EAAC,KAAK,CAAC,EAAE;YAClB,IAAI,CAAC,SAAS,GAAG,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC;YAChC,IAAI,CAAC,MAAM,GAAG,YAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjC;IACH,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IA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,OAAO,IAAI,CAAC,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IAED;;;OAGG;IACI,WAAW;QAChB,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAChC,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC9C,CAAC;IAED,QAAQ;QACN,OAAO;YACL,OAAO;YACP,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,QAAQ,IAAI,IAAA,aAAM,EAAC,IAAI,CAAC,QAAQ,CAAC;YACtC,IAAI,CAAC,UAAU,IAAI,SAAS;YAC5B,IAAI,CAAC,QAAQ,IAAI,OAAO;YACxB,IAAI,CAAC,eAAe,IAAI,cAAc;SACvC;aACE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;CACF;AAzJD,4BAyJC","sourcesContent":["import {classOf, getClassOrSymbol, isClass, nameOf, Store, Type} from \"@tsed/core\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {ProviderScope} from \"./ProviderScope\";\nimport {ProviderType} from \"./ProviderType\";\n\nexport class Provider<T = any> implements ProviderOpts<T> {\n public type: ProviderType | any = ProviderType.PROVIDER;\n /**\n * @deprecated Use injector.get(provider.token) instead.\n */\n public instance: T;\n public deps: TokenProvider[];\n public imports: any[];\n public useFactory: Function;\n public useAsyncFactory: Function;\n public useValue: any;\n public hooks?: Record<string, (instance: T, ...args: any[]) => Promise<void> | void>;\n private _useClass: Type<T>;\n private _provide: TokenProvider;\n private _store: Store;\n private _tokenStore: Store;\n\n [key: string]: any;\n\n constructor(token: TokenProvider, options: Partial<Provider> = {}) {\n this.provide = token;\n this.useClass = token;\n\n Object.assign(this, options);\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 = getClassOrSymbol(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 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 get store(): Store {\n return this._store;\n }\n\n get path() {\n return this.store.get(\"path\", \"/\");\n }\n\n set path(path: string) {\n this.store.set(\"path\", path);\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 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 set configuration(configuration: Partial<TsED.Configuration>) {\n this.store.set(\"configuration\", configuration);\n }\n\n get children(): TokenProvider[] {\n return this.store.get(\"childrenControllers\", []);\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 {\n return new (classOf(this))(this._provide, this);\n }\n\n /**\n *\n * @returns {boolean}\n */\n public hasChildren(): boolean {\n return !!this.children.length;\n }\n\n /**\n *\n * @returns {boolean}\n */\n public hasParent(): boolean {\n return !!this.store.get(\"parentController\");\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"]}
package/lib/cjs/index.js CHANGED
@@ -4,53 +4,53 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const tslib_1 = require("tslib");
7
- (0, tslib_1.__exportStar)(require("./constants/constants"), exports);
8
- (0, tslib_1.__exportStar)(require("./decorators/configuration"), exports);
9
- (0, tslib_1.__exportStar)(require("./decorators/constant"), exports);
10
- (0, tslib_1.__exportStar)(require("./decorators/controller"), exports);
11
- (0, tslib_1.__exportStar)(require("./decorators/inject"), exports);
12
- (0, tslib_1.__exportStar)(require("./decorators/injectable"), exports);
13
- (0, tslib_1.__exportStar)(require("./decorators/intercept"), exports);
14
- (0, tslib_1.__exportStar)(require("./decorators/interceptor"), exports);
15
- (0, tslib_1.__exportStar)(require("./decorators/lazyInject"), exports);
16
- (0, tslib_1.__exportStar)(require("./decorators/module"), exports);
17
- (0, tslib_1.__exportStar)(require("./decorators/opts"), exports);
18
- (0, tslib_1.__exportStar)(require("./decorators/overrideProvider"), exports);
19
- (0, tslib_1.__exportStar)(require("./decorators/scope"), exports);
20
- (0, tslib_1.__exportStar)(require("./decorators/service"), exports);
21
- (0, tslib_1.__exportStar)(require("./decorators/useOpts"), exports);
22
- (0, tslib_1.__exportStar)(require("./decorators/value"), exports);
23
- (0, tslib_1.__exportStar)(require("./domain/Container"), exports);
24
- (0, tslib_1.__exportStar)(require("./domain/ContextLogger"), exports);
25
- (0, tslib_1.__exportStar)(require("./domain/DIContext"), exports);
26
- (0, tslib_1.__exportStar)(require("./domain/InjectablePropertyType"), exports);
27
- (0, tslib_1.__exportStar)(require("./domain/LocalsContainer"), exports);
28
- (0, tslib_1.__exportStar)(require("./domain/Provider"), exports);
29
- (0, tslib_1.__exportStar)(require("./domain/ProviderScope"), exports);
30
- (0, tslib_1.__exportStar)(require("./domain/ProviderType"), exports);
31
- (0, tslib_1.__exportStar)(require("./errors/InjectionError"), exports);
32
- (0, tslib_1.__exportStar)(require("./errors/UndefinedTokenError"), exports);
33
- (0, tslib_1.__exportStar)(require("./interfaces/DIConfigurationOptions"), exports);
34
- (0, tslib_1.__exportStar)(require("./interfaces/DILogger"), exports);
35
- (0, tslib_1.__exportStar)(require("./interfaces/DIResolver"), exports);
36
- (0, tslib_1.__exportStar)(require("./interfaces/IProvider"), exports);
37
- (0, tslib_1.__exportStar)(require("./interfaces/InjectableProperties"), exports);
38
- (0, tslib_1.__exportStar)(require("./interfaces/InterceptorContext"), exports);
39
- (0, tslib_1.__exportStar)(require("./interfaces/InterceptorMethods"), exports);
40
- (0, tslib_1.__exportStar)(require("./interfaces/InvokeOptions"), exports);
41
- (0, tslib_1.__exportStar)(require("./interfaces/OnDestroy"), exports);
42
- (0, tslib_1.__exportStar)(require("./interfaces/OnInit"), exports);
43
- (0, tslib_1.__exportStar)(require("./interfaces/RegistrySettings"), exports);
44
- (0, tslib_1.__exportStar)(require("./interfaces/ResolvedInvokeOptions"), exports);
45
- (0, tslib_1.__exportStar)(require("./interfaces/TokenProvider"), exports);
46
- (0, tslib_1.__exportStar)(require("./registries/GlobalProviders"), exports);
47
- (0, tslib_1.__exportStar)(require("./registries/ProviderRegistry"), exports);
48
- (0, tslib_1.__exportStar)(require("./services/DIConfiguration"), exports);
49
- (0, tslib_1.__exportStar)(require("./services/DILogger"), exports);
50
- (0, tslib_1.__exportStar)(require("./services/DITest"), exports);
51
- (0, tslib_1.__exportStar)(require("./services/InjectorService"), exports);
52
- (0, tslib_1.__exportStar)(require("./utils/colors"), exports);
53
- (0, tslib_1.__exportStar)(require("./utils/createContainer"), exports);
54
- (0, tslib_1.__exportStar)(require("./utils/getConfiguration"), exports);
55
- (0, tslib_1.__exportStar)(require("./utils/setLoggerLevel"), exports);
7
+ tslib_1.__exportStar(require("./constants/constants"), exports);
8
+ tslib_1.__exportStar(require("./decorators/configuration"), exports);
9
+ tslib_1.__exportStar(require("./decorators/constant"), exports);
10
+ tslib_1.__exportStar(require("./decorators/controller"), exports);
11
+ tslib_1.__exportStar(require("./decorators/inject"), exports);
12
+ tslib_1.__exportStar(require("./decorators/injectable"), exports);
13
+ tslib_1.__exportStar(require("./decorators/intercept"), exports);
14
+ tslib_1.__exportStar(require("./decorators/interceptor"), exports);
15
+ tslib_1.__exportStar(require("./decorators/lazyInject"), exports);
16
+ tslib_1.__exportStar(require("./decorators/module"), exports);
17
+ tslib_1.__exportStar(require("./decorators/opts"), exports);
18
+ tslib_1.__exportStar(require("./decorators/overrideProvider"), exports);
19
+ tslib_1.__exportStar(require("./decorators/scope"), exports);
20
+ tslib_1.__exportStar(require("./decorators/service"), exports);
21
+ tslib_1.__exportStar(require("./decorators/useOpts"), exports);
22
+ tslib_1.__exportStar(require("./decorators/value"), exports);
23
+ tslib_1.__exportStar(require("./domain/Container"), exports);
24
+ tslib_1.__exportStar(require("./domain/ContextLogger"), exports);
25
+ tslib_1.__exportStar(require("./domain/DIContext"), exports);
26
+ tslib_1.__exportStar(require("./domain/InjectablePropertyType"), exports);
27
+ tslib_1.__exportStar(require("./domain/LocalsContainer"), exports);
28
+ tslib_1.__exportStar(require("./domain/Provider"), exports);
29
+ tslib_1.__exportStar(require("./domain/ProviderScope"), exports);
30
+ tslib_1.__exportStar(require("./domain/ProviderType"), exports);
31
+ tslib_1.__exportStar(require("./errors/InjectionError"), exports);
32
+ tslib_1.__exportStar(require("./errors/UndefinedTokenError"), exports);
33
+ tslib_1.__exportStar(require("./interfaces/DIConfigurationOptions"), exports);
34
+ tslib_1.__exportStar(require("./interfaces/DILogger"), exports);
35
+ tslib_1.__exportStar(require("./interfaces/DIResolver"), exports);
36
+ tslib_1.__exportStar(require("./interfaces/InjectableProperties"), exports);
37
+ tslib_1.__exportStar(require("./interfaces/InterceptorContext"), exports);
38
+ tslib_1.__exportStar(require("./interfaces/InterceptorMethods"), exports);
39
+ tslib_1.__exportStar(require("./interfaces/InvokeOptions"), exports);
40
+ tslib_1.__exportStar(require("./interfaces/OnDestroy"), exports);
41
+ tslib_1.__exportStar(require("./interfaces/OnInit"), exports);
42
+ tslib_1.__exportStar(require("./interfaces/ProviderOpts"), exports);
43
+ tslib_1.__exportStar(require("./interfaces/RegistrySettings"), exports);
44
+ tslib_1.__exportStar(require("./interfaces/ResolvedInvokeOptions"), exports);
45
+ tslib_1.__exportStar(require("./interfaces/TokenProvider"), exports);
46
+ tslib_1.__exportStar(require("./registries/GlobalProviders"), exports);
47
+ tslib_1.__exportStar(require("./registries/ProviderRegistry"), exports);
48
+ tslib_1.__exportStar(require("./services/DIConfiguration"), exports);
49
+ tslib_1.__exportStar(require("./services/DILogger"), exports);
50
+ tslib_1.__exportStar(require("./services/DITest"), exports);
51
+ tslib_1.__exportStar(require("./services/InjectorService"), exports);
52
+ tslib_1.__exportStar(require("./utils/colors"), exports);
53
+ tslib_1.__exportStar(require("./utils/createContainer"), exports);
54
+ tslib_1.__exportStar(require("./utils/getConfiguration"), exports);
55
+ tslib_1.__exportStar(require("./utils/setLoggerLevel"), exports);
56
56
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,qEAAsC;AACtC,0EAA2C;AAC3C,qEAAsC;AACtC,uEAAwC;AACxC,mEAAoC;AACpC,uEAAwC;AACxC,sEAAuC;AACvC,wEAAyC;AACzC,uEAAwC;AACxC,mEAAoC;AACpC,iEAAkC;AAClC,6EAA8C;AAC9C,kEAAmC;AACnC,oEAAqC;AACrC,oEAAqC;AACrC,kEAAmC;AACnC,kEAAmC;AACnC,sEAAuC;AACvC,kEAAmC;AACnC,+EAAgD;AAChD,wEAAyC;AACzC,iEAAkC;AAClC,sEAAuC;AACvC,qEAAsC;AACtC,uEAAwC;AACxC,4EAA6C;AAC7C,mFAAoD;AACpD,qEAAsC;AACtC,uEAAwC;AACxC,sEAAuC;AACvC,iFAAkD;AAClD,+EAAgD;AAChD,+EAAgD;AAChD,0EAA2C;AAC3C,sEAAuC;AACvC,mEAAoC;AACpC,6EAA8C;AAC9C,kFAAmD;AACnD,0EAA2C;AAC3C,4EAA6C;AAC7C,6EAA8C;AAC9C,0EAA2C;AAC3C,mEAAoC;AACpC,iEAAkC;AAClC,0EAA2C;AAC3C,8DAA+B;AAC/B,uEAAwC;AACxC,wEAAyC;AACzC,sEAAuC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/configuration\";\nexport * from \"./decorators/constant\";\nexport * from \"./decorators/controller\";\nexport * from \"./decorators/inject\";\nexport * from \"./decorators/injectable\";\nexport * from \"./decorators/intercept\";\nexport * from \"./decorators/interceptor\";\nexport * from \"./decorators/lazyInject\";\nexport * from \"./decorators/module\";\nexport * from \"./decorators/opts\";\nexport * from \"./decorators/overrideProvider\";\nexport * from \"./decorators/scope\";\nexport * from \"./decorators/service\";\nexport * from \"./decorators/useOpts\";\nexport * from \"./decorators/value\";\nexport * from \"./domain/Container\";\nexport * from \"./domain/ContextLogger\";\nexport * from \"./domain/DIContext\";\nexport * from \"./domain/InjectablePropertyType\";\nexport * from \"./domain/LocalsContainer\";\nexport * from \"./domain/Provider\";\nexport * from \"./domain/ProviderScope\";\nexport * from \"./domain/ProviderType\";\nexport * from \"./errors/InjectionError\";\nexport * from \"./errors/UndefinedTokenError\";\nexport * from \"./interfaces/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\nexport * from \"./interfaces/DIResolver\";\nexport * from \"./interfaces/IProvider\";\nexport * from \"./interfaces/InjectableProperties\";\nexport * from \"./interfaces/InterceptorContext\";\nexport * from \"./interfaces/InterceptorMethods\";\nexport * from \"./interfaces/InvokeOptions\";\nexport * from \"./interfaces/OnDestroy\";\nexport * from \"./interfaces/OnInit\";\nexport * from \"./interfaces/RegistrySettings\";\nexport * from \"./interfaces/ResolvedInvokeOptions\";\nexport * from \"./interfaces/TokenProvider\";\nexport * from \"./registries/GlobalProviders\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DITest\";\nexport * from \"./services/InjectorService\";\nexport * from \"./utils/colors\";\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gEAAsC;AACtC,qEAA2C;AAC3C,gEAAsC;AACtC,kEAAwC;AACxC,8DAAoC;AACpC,kEAAwC;AACxC,iEAAuC;AACvC,mEAAyC;AACzC,kEAAwC;AACxC,8DAAoC;AACpC,4DAAkC;AAClC,wEAA8C;AAC9C,6DAAmC;AACnC,+DAAqC;AACrC,+DAAqC;AACrC,6DAAmC;AACnC,6DAAmC;AACnC,iEAAuC;AACvC,6DAAmC;AACnC,0EAAgD;AAChD,mEAAyC;AACzC,4DAAkC;AAClC,iEAAuC;AACvC,gEAAsC;AACtC,kEAAwC;AACxC,uEAA6C;AAC7C,8EAAoD;AACpD,gEAAsC;AACtC,kEAAwC;AACxC,4EAAkD;AAClD,0EAAgD;AAChD,0EAAgD;AAChD,qEAA2C;AAC3C,iEAAuC;AACvC,8DAAoC;AACpC,oEAA0C;AAC1C,wEAA8C;AAC9C,6EAAmD;AACnD,qEAA2C;AAC3C,uEAA6C;AAC7C,wEAA8C;AAC9C,qEAA2C;AAC3C,8DAAoC;AACpC,4DAAkC;AAClC,qEAA2C;AAC3C,yDAA+B;AAC/B,kEAAwC;AACxC,mEAAyC;AACzC,iEAAuC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/configuration\";\nexport * from \"./decorators/constant\";\nexport * from \"./decorators/controller\";\nexport * from \"./decorators/inject\";\nexport * from \"./decorators/injectable\";\nexport * from \"./decorators/intercept\";\nexport * from \"./decorators/interceptor\";\nexport * from \"./decorators/lazyInject\";\nexport * from \"./decorators/module\";\nexport * from \"./decorators/opts\";\nexport * from \"./decorators/overrideProvider\";\nexport * from \"./decorators/scope\";\nexport * from \"./decorators/service\";\nexport * from \"./decorators/useOpts\";\nexport * from \"./decorators/value\";\nexport * from \"./domain/Container\";\nexport * from \"./domain/ContextLogger\";\nexport * from \"./domain/DIContext\";\nexport * from \"./domain/InjectablePropertyType\";\nexport * from \"./domain/LocalsContainer\";\nexport * from \"./domain/Provider\";\nexport * from \"./domain/ProviderScope\";\nexport * from \"./domain/ProviderType\";\nexport * from \"./errors/InjectionError\";\nexport * from \"./errors/UndefinedTokenError\";\nexport * from \"./interfaces/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\nexport * from \"./interfaces/DIResolver\";\nexport * from \"./interfaces/InjectableProperties\";\nexport * from \"./interfaces/InterceptorContext\";\nexport * from \"./interfaces/InterceptorMethods\";\nexport * from \"./interfaces/InvokeOptions\";\nexport * from \"./interfaces/OnDestroy\";\nexport * from \"./interfaces/OnInit\";\nexport * from \"./interfaces/ProviderOpts\";\nexport * from \"./interfaces/RegistrySettings\";\nexport * from \"./interfaces/ResolvedInvokeOptions\";\nexport * from \"./interfaces/TokenProvider\";\nexport * from \"./registries/GlobalProviders\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DITest\";\nexport * from \"./services/InjectorService\";\nexport * from \"./utils/colors\";\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IProvider.js.map
3
+ //# sourceMappingURL=ProviderOpts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProviderOpts.js","sourceRoot":"","sources":["../../../src/interfaces/ProviderOpts.ts"],"names":[],"mappings":"","sourcesContent":["import type {Type} from \"@tsed/core\";\nimport type {DIResolver} from \"./DIResolver\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {ProviderType} from \"../domain/ProviderType\";\nimport type {TokenProvider} from \"./TokenProvider\";\n\nexport interface ProviderOpts<T = any> {\n /**\n * An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).\n */\n provide: TokenProvider;\n /**\n * Provider type\n */\n type?: ProviderType | string;\n /**\n * Instance build by the injector\n */\n instance?: T;\n /**\n * Define dependencies to build the provider\n */\n deps?: TokenProvider[];\n /**\n * Class to instantiate for the `token`.\n */\n useClass?: Type<T>;\n /**\n * Provide a function to build the provider\n */\n useFactory?: Function;\n /**\n * Provide an async function to build the provider\n */\n useAsyncFactory?: Function;\n /**\n * Provide predefined value\n */\n useValue?: any;\n /**\n * Scope used by the injector to build the provider.\n */\n scope?: ProviderScope;\n /**\n * A list of resolvers which will be used to resolve missing Symbol/Class when injector invoke a Class. This property allow external DI usage.\n */\n resolvers?: DIResolver[];\n\n /**\n * hooks to intercept custom events\n */\n hooks?: Record<string, (instance: T, ...args: any[]) => Promise<any> | any>;\n /**\n *\n */\n [key: string]: any;\n}\n\n/**\n * @deprecated\n */\nexport interface IProvider<T = any> extends ProviderOpts<T> {}\n"]}
@@ -62,11 +62,11 @@ class GlobalProviderRegistry extends Map {
62
62
  ...options,
63
63
  model
64
64
  });
65
- (0, tslib_1.__classPrivateFieldGet)(this, _GlobalProviderRegistry_settings, "f").set(type, options);
65
+ tslib_1.__classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").set(type, options);
66
66
  return this;
67
67
  }
68
68
  onInvoke(provider, locals, options) {
69
- const settings = (0, tslib_1.__classPrivateFieldGet)(this, _GlobalProviderRegistry_settings, "f").get(provider.type);
69
+ const settings = tslib_1.__classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").get(provider.type);
70
70
  if (settings === null || settings === void 0 ? void 0 : settings.onInvoke) {
71
71
  settings.onInvoke(provider, locals, options);
72
72
  }
@@ -82,7 +82,7 @@ class GlobalProviderRegistry extends Map {
82
82
  type = provider.type;
83
83
  }
84
84
  }
85
- return ((0, tslib_1.__classPrivateFieldGet)(this, _GlobalProviderRegistry_settings, "f").get(type) || {
85
+ return (tslib_1.__classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").get(type) || {
86
86
  model: Provider_1.Provider
87
87
  });
88
88
  }
@@ -106,7 +106,7 @@ class GlobalProviderRegistry extends Map {
106
106
  createIfNotExists(key, options) {
107
107
  const type = options.type || ProviderType_1.ProviderType.PROVIDER;
108
108
  if (!this.has(key)) {
109
- const { model = Provider_1.Provider } = (0, tslib_1.__classPrivateFieldGet)(this, _GlobalProviderRegistry_settings, "f").get(type) || {};
109
+ const { model = Provider_1.Provider } = tslib_1.__classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").get(type) || {};
110
110
  const item = new model(key, options);
111
111
  this.set(key, item);
112
112
  }
@@ -1 +1 @@
1
- {"version":3,"file":"GlobalProviders.js","sourceRoot":"","sources":["../../../src/registries/GlobalProviders.ts"],"names":[],"mappings":";;;;;AAAA,qCAAkD;AAClD,iDAA4C;AAC5C,yDAAoD;AAOpD,MAAa,sBAAuB,SAAQ,GAA4B;IAAxE;;QACE,2CAA2C,IAAI,GAAG,EAAE,EAAC;IA+HvD,CAAC;IA7HC;;;;OAIG;IACH,GAAG,CAAC,GAAkB;QACpB,OAAO,KAAK,CAAC,GAAG,CAAC,IAAA,uBAAgB,EAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAkB;QACpB,OAAO,KAAK,CAAC,GAAG,CAAC,IAAA,uBAAgB,EAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAkB,EAAE,QAAkB;QACxC,KAAK,CAAC,GAAG,CAAC,IAAA,uBAAgB,EAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;QAE3C,OAAO,IAAI,CAAC;IACd,CA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AC,GAAG,CAAC,GAAG,CAAE,CAAC;IACxB,CAAC;CACF;AAhID,wDAgIC;;AAED;;;GAGG;AACH,0CAA0C;AAC7B,QAAA,eAAe,GAAG,IAAI,sBAAsB,EAAE,CAAC","sourcesContent":["import {getClassOrSymbol, Type} from \"@tsed/core\";\nimport {Provider} from \"../domain/Provider\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport type {InjectorService} from \"../services/InjectorService\";\nimport {ResolvedInvokeOptions} from \"../interfaces/ResolvedInvokeOptions\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {RegistrySettings} from \"../interfaces/RegistrySettings\";\nimport {IProvider} from \"../interfaces/IProvider\";\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> = {}) {\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 onInvoke(provider: Provider, locals: Map<TokenProvider, any>, options: ResolvedInvokeOptions & {injector: InjectorService}) {\n const settings = this.#settings.get(provider.type);\n\n if (settings?.onInvoke) {\n settings.onInvoke(provider, locals, options);\n }\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 }\n );\n }\n\n createRegisterFn(type: string) {\n return (provider: any | IProvider, instance?: any): void => {\n // istanbul ignore next\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 *\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, options);\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"]}
1
+ {"version":3,"file":"GlobalProviders.js","sourceRoot":"","sources":["../../../src/registries/GlobalProviders.ts"],"names":[],"mappings":";;;;;AAAA,qCAAkD;AAClD,iDAA4C;AAC5C,yDAAoD;AAOpD,MAAa,sBAAuB,SAAQ,GAA4B;IAAxE;;QACE,2CAA2C,IAAI,GAAG,EAAE,EAAC;IA+HvD,CAAC;IA7HC;;;;OAIG;IACH,GAAG,CAAC,GAAkB;QACpB,OAAO,KAAK,CAAC,GAAG,CAAC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2BAAY,CAAC,QAAQ,CAAC;QAEnD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAClB,MAAM,EAAC,KAAK,GAAG,mBAAQ,EAAC,GAAG,+BAAA,IAAI,wCAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAE1D,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YAErC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;SACrB;QAED,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;IACxB,CAAC;CACF;AAhID,wDAgIC;;AAED;;;GAGG;AACH,0CAA0C;AAC7B,QAAA,eAAe,GAAG,IAAI,sBAAsB,EAAE,CAAC","sourcesContent":["import {getClassOrSymbol, Type} from \"@tsed/core\";\nimport {Provider} from \"../domain/Provider\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport type {InjectorService} from \"../services/InjectorService\";\nimport {ResolvedInvokeOptions} from \"../interfaces/ResolvedInvokeOptions\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {RegistrySettings} from \"../interfaces/RegistrySettings\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\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<ProviderOpts>): 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> = {}) {\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 onInvoke(provider: Provider, locals: Map<TokenProvider, any>, options: ResolvedInvokeOptions & {injector: InjectorService}) {\n const settings = this.#settings.get(provider.type);\n\n if (settings?.onInvoke) {\n settings.onInvoke(provider, locals, options);\n }\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 }\n );\n }\n\n createRegisterFn(type: string) {\n return (provider: any | ProviderOpts, instance?: any): void => {\n // istanbul ignore next\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 *\n * @param key\n * @param options\n */\n protected createIfNotExists(key: TokenProvider, options: Partial<ProviderOpts>): 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, options);\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"]}
@@ -11,7 +11,7 @@ const GlobalProviders_1 = require("./GlobalProviders");
11
11
  GlobalProviders_1.GlobalProviders.createRegistry(ProviderType_1.ProviderType.CONTROLLER, Provider_1.Provider);
12
12
  /**
13
13
  * Register a provider configuration.
14
- * @param {IProvider<any>} provider
14
+ * @param {ProviderOpts<any>} provider
15
15
  */
16
16
  function registerProvider(provider) {
17
17
  if (!provider.provide) {
@@ -1 +1 @@
1
- {"version":3,"file":"ProviderRegistry.js","sourceRoot":"","sources":["../../../src/registries/ProviderRegistry.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAC5C,2DAAsD;AACtD,yDAAoD;AAEpD,uDAAkD;AAElD;;GAEG;AACH,iCAAe,CAAC,cAAc,CAAC,2BAAY,CAAC,UAAU,EAAE,mBAAQ,CAAC,CAAC;AAElE;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,QAA4B;IAC3D,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IAED,iCAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACpD,CAAC;AAND,4CAMC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACU,QAAA,eAAe,GAAG,gBAAgB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACI,MAAM,aAAa,GAAG,CAAC,QAA8B,EAAE,KAAW,EAAQ,EAAE;IACjF,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;QACrB,QAAQ,GAAG;YACT,OAAO,EAAE,QAAQ;SAClB,CAAC;KACH;IAED,QAAQ,GAAG,MAAM,CAAC,MAAM,CACtB;QACE,KAAK,EAAE,6BAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,KAAK;KAChB,EACD,QAAQ,EACR,EAAC,IAAI,EAAE,2BAAY,CAAC,KAAK,EAAC,CAC3B,CAAC;IACF,iCAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACpD,CAAC,CAAC;AAhBW,QAAA,aAAa,iBAgBxB;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACU,QAAA,kBAAkB,GAAG,iCAAe,CAAC,gBAAgB,CAAC,2BAAY,CAAC,UAAU,CAAC,CAAC","sourcesContent":["import {Provider} from \"../domain/Provider\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport type {IProvider} from \"../interfaces/IProvider\";\nimport {GlobalProviders} from \"./GlobalProviders\";\n\n/**\n *\n */\nGlobalProviders.createRegistry(ProviderType.CONTROLLER, Provider);\n\n/**\n * Register a provider configuration.\n * @param {IProvider<any>} provider\n */\nexport function registerProvider(provider: Partial<IProvider>): 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 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"]}
1
+ {"version":3,"file":"ProviderRegistry.js","sourceRoot":"","sources":["../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ProviderScope} from \"../domain/ProviderScope\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport type {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {GlobalProviders} from \"./GlobalProviders\";\n\n/**\n *\n */\nGlobalProviders.createRegistry(ProviderType.CONTROLLER, Provider);\n\n/**\n * Register a provider configuration.\n * @param {ProviderOpts<any>} provider\n */\nexport function registerProvider<Type = any>(provider: Partial<ProviderOpts<Type>>): 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 | ProviderOpts<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 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"]}
@@ -46,7 +46,7 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
46
46
  this.logger = console;
47
47
  this.resolvedConfiguration = false;
48
48
  _InjectorService_cache.set(this, new LocalsContainer_1.LocalsContainer());
49
- (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").set(InjectorService_1, this);
49
+ tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").set(InjectorService_1, this);
50
50
  }
51
51
  get resolvers() {
52
52
  return this.settings.resolvers;
@@ -73,14 +73,14 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
73
73
  }
74
74
  const provider = this.getProvider(token);
75
75
  Object.assign(provider, settings);
76
- (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").set(token, this.invoke(token));
76
+ tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").set(token, this.invoke(token));
77
77
  return provider;
78
78
  }
79
79
  /**
80
80
  * Return a list of instance build by the injector.
81
81
  */
82
82
  toArray() {
83
- return (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").toArray();
83
+ return tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").toArray();
84
84
  }
85
85
  /**
86
86
  * Get a service or factory already constructed from his symbol or class.
@@ -116,13 +116,22 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
116
116
  }
117
117
  }
118
118
  }
119
+ /**
120
+ * Return all instance of the same provider type
121
+ * @param type
122
+ */
123
+ getAll(type) {
124
+ return this.getProviders(type).map((provider) => {
125
+ return this.get(provider.token);
126
+ });
127
+ }
119
128
  /**
120
129
  * The has() method returns a boolean indicating whether an element with the specified key exists or not.
121
130
  * @returns {boolean}
122
131
  * @param token
123
132
  */
124
133
  has(token) {
125
- return (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").get(token) !== undefined;
134
+ return tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").get(token) !== undefined;
126
135
  }
127
136
  /**
128
137
  * Invoke the class and inject all services that required by the class constructor.
@@ -158,17 +167,17 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
158
167
  if (!provider || options.rebuild) {
159
168
  instance = this.resolve(token, locals, options);
160
169
  if (this.hasProvider(token)) {
161
- (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").set(token, instance);
170
+ tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").set(token, instance);
162
171
  }
163
172
  return instance;
164
173
  }
165
174
  switch (this.scopeOf(provider)) {
166
175
  case ProviderScope_1.ProviderScope.SINGLETON:
167
176
  if (!this.has(token)) {
168
- (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").set(token, this.resolve(token, locals, options));
177
+ tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").set(token, this.resolve(token, locals, options));
169
178
  if (provider.isAsync()) {
170
- (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").get(token).then((instance) => {
171
- (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").set(token, instance);
179
+ tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").get(token).then((instance) => {
180
+ tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").set(token, instance);
172
181
  });
173
182
  }
174
183
  }
@@ -193,7 +202,7 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
193
202
  if (provider.isAsync()) {
194
203
  await this.invoke(provider.token, locals);
195
204
  }
196
- const instance = (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").get(provider.token);
205
+ const instance = tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").get(provider.token);
197
206
  if (instance !== undefined) {
198
207
  locals.set(provider.token, instance);
199
208
  }
@@ -206,7 +215,7 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
206
215
  if (!locals.has(provider.token) && this.scopeOf(provider) === ProviderScope_1.ProviderScope.SINGLETON) {
207
216
  this.invoke(provider.token, locals);
208
217
  }
209
- const instance = (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").get(provider.token);
218
+ const instance = tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").get(provider.token);
210
219
  if (instance !== undefined) {
211
220
  locals.set(provider.token, instance);
212
221
  }
@@ -430,7 +439,7 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
430
439
  * @returns {Promise<any[]>} A list of promises.
431
440
  */
432
441
  async emit(eventName, ...args) {
433
- return (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").emit(eventName, ...args);
442
+ return tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").emit(eventName, ...args);
434
443
  }
435
444
  /**
436
445
  * @param eventName
@@ -438,7 +447,7 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
438
447
  * @param args
439
448
  */
440
449
  alter(eventName, value, ...args) {
441
- return (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").alter(eventName, value, ...args);
450
+ return tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").alter(eventName, value, ...args);
442
451
  }
443
452
  /**
444
453
  * @param eventName
@@ -446,10 +455,10 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
446
455
  * @param args
447
456
  */
448
457
  async alterAsync(eventName, value, ...args) {
449
- return (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").alterAsync(eventName, value, ...args);
458
+ return tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").alterAsync(eventName, value, ...args);
450
459
  }
451
460
  async destroy() {
452
- await (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").destroy();
461
+ await tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").destroy();
453
462
  }
454
463
  ensureProvider(token) {
455
464
  if (!this.hasProvider(token) && GlobalProviders_1.GlobalProviders.has(token)) {
@@ -458,7 +467,7 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
458
467
  return this.getProvider(token);
459
468
  }
460
469
  getInstance(token) {
461
- return (0, tslib_1.__classPrivateFieldGet)(this, _InjectorService_cache, "f").get(token);
470
+ return tslib_1.__classPrivateFieldGet(this, _InjectorService_cache, "f").get(token);
462
471
  }
463
472
  /**
464
473
  * Invoke a class method and inject service.
@@ -511,6 +520,11 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
511
520
  if (instance && (0, core_1.isClass)((0, core_1.classOf)(instance))) {
512
521
  this.bindInjectableProperties(instance, locals, options);
513
522
  }
523
+ if (instance && provider.hooks) {
524
+ Object.entries(provider.hooks).forEach(([key, cb]) => {
525
+ instance[key] = (...args) => cb(instance, ...args);
526
+ });
527
+ }
514
528
  return instance;
515
529
  }
516
530
  /**
@@ -571,12 +585,12 @@ let InjectorService = InjectorService_1 = class InjectorService extends Containe
571
585
  }
572
586
  };
573
587
  _InjectorService_cache = new WeakMap();
574
- InjectorService = InjectorService_1 = (0, tslib_1.__decorate)([
588
+ InjectorService = InjectorService_1 = tslib_1.__decorate([
575
589
  (0, injectable_1.Injectable)({
576
590
  scope: ProviderScope_1.ProviderScope.SINGLETON,
577
591
  global: true
578
592
  }),
579
- (0, tslib_1.__metadata)("design:paramtypes", [])
593
+ tslib_1.__metadata("design:paramtypes", [])
580
594
  ], InjectorService);
581
595
  exports.InjectorService = InjectorService;
582
596
  //# sourceMappingURL=InjectorService.js.map