@tsed/di 7.0.0-beta.8 → 7.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/coverage.json +6 -0
  2. package/jest.config.js +9 -0
  3. package/lib/cjs/decorators/controller.js.map +1 -1
  4. package/lib/cjs/decorators/inject.js +7 -3
  5. package/lib/cjs/decorators/inject.js.map +1 -1
  6. package/lib/cjs/domain/Container.js +1 -2
  7. package/lib/cjs/domain/Container.js.map +1 -1
  8. package/lib/cjs/domain/ContextLogger.js +41 -30
  9. package/lib/cjs/domain/ContextLogger.js.map +1 -1
  10. package/lib/cjs/domain/ControllerProvider.js +37 -0
  11. package/lib/cjs/domain/ControllerProvider.js.map +1 -0
  12. package/lib/cjs/domain/DIContext.js +86 -30
  13. package/lib/cjs/domain/DIContext.js.map +1 -1
  14. package/lib/cjs/domain/LocalsContainer.js +3 -46
  15. package/lib/cjs/domain/LocalsContainer.js.map +1 -1
  16. package/lib/cjs/domain/Provider.js +20 -1
  17. package/lib/cjs/domain/Provider.js.map +1 -1
  18. package/lib/cjs/errors/InjectionError.js +3 -2
  19. package/lib/cjs/errors/InjectionError.js.map +1 -1
  20. package/lib/cjs/errors/InvalidPropertyTokenError.js +12 -0
  21. package/lib/cjs/errors/InvalidPropertyTokenError.js.map +1 -0
  22. package/lib/cjs/errors/UndefinedTokenError.js +1 -1
  23. package/lib/cjs/errors/UndefinedTokenError.js.map +1 -1
  24. package/lib/cjs/index.js +9 -1
  25. package/lib/cjs/index.js.map +1 -1
  26. package/lib/cjs/interfaces/AlterRunInContext.js +3 -0
  27. package/lib/cjs/interfaces/AlterRunInContext.js.map +1 -0
  28. package/lib/cjs/interfaces/DIConfigurationOptions.js.map +1 -1
  29. package/lib/cjs/interfaces/DILoggerOptions.js +3 -0
  30. package/lib/cjs/interfaces/DILoggerOptions.js.map +1 -0
  31. package/lib/cjs/interfaces/InjectableProperties.js.map +1 -1
  32. package/lib/cjs/interfaces/InterceptorMethods.js.map +1 -1
  33. package/lib/cjs/interfaces/TokenProvider.js.map +1 -1
  34. package/lib/cjs/interfaces/TokenRoute.js +3 -0
  35. package/lib/cjs/interfaces/TokenRoute.js.map +1 -0
  36. package/lib/cjs/registries/GlobalProviders.js +7 -12
  37. package/lib/cjs/registries/GlobalProviders.js.map +1 -1
  38. package/lib/cjs/registries/ProviderRegistry.js +1 -1
  39. package/lib/cjs/registries/ProviderRegistry.js.map +1 -1
  40. package/lib/cjs/services/DIConfiguration.js +56 -43
  41. package/lib/cjs/services/DIConfiguration.js.map +1 -1
  42. package/lib/cjs/services/DITest.js +5 -6
  43. package/lib/cjs/services/DITest.js.map +1 -1
  44. package/lib/cjs/services/InjectorService.js +94 -92
  45. package/lib/cjs/services/InjectorService.js.map +1 -1
  46. package/lib/cjs/utils/asyncHookContext.js +42 -0
  47. package/lib/cjs/utils/asyncHookContext.js.map +1 -0
  48. package/lib/cjs/utils/getConfiguration.js +13 -10
  49. package/lib/cjs/utils/getConfiguration.js.map +1 -1
  50. package/lib/cjs/utils/resolveControllers.js +47 -0
  51. package/lib/cjs/utils/resolveControllers.js.map +1 -0
  52. package/lib/cjs/utils/setLoggerConfiguration.js +11 -0
  53. package/lib/cjs/utils/setLoggerConfiguration.js.map +1 -0
  54. package/lib/cjs/utils/setLoggerFormat.js +33 -0
  55. package/lib/cjs/utils/setLoggerFormat.js.map +1 -0
  56. package/lib/cjs/utils/setLoggerLevel.js +1 -2
  57. package/lib/cjs/utils/setLoggerLevel.js.map +1 -1
  58. package/lib/esm/decorators/controller.js.map +1 -1
  59. package/lib/esm/decorators/inject.js +6 -2
  60. package/lib/esm/decorators/inject.js.map +1 -1
  61. package/lib/esm/domain/Container.js +1 -2
  62. package/lib/esm/domain/Container.js.map +1 -1
  63. package/lib/esm/domain/ContextLogger.js +41 -30
  64. package/lib/esm/domain/ContextLogger.js.map +1 -1
  65. package/lib/esm/domain/ControllerProvider.js +33 -0
  66. package/lib/esm/domain/ControllerProvider.js.map +1 -0
  67. package/lib/esm/domain/DIContext.js +86 -30
  68. package/lib/esm/domain/DIContext.js.map +1 -1
  69. package/lib/esm/domain/LocalsContainer.js +3 -46
  70. package/lib/esm/domain/LocalsContainer.js.map +1 -1
  71. package/lib/esm/domain/Provider.js +21 -2
  72. package/lib/esm/domain/Provider.js.map +1 -1
  73. package/lib/esm/errors/InjectionError.js +3 -2
  74. package/lib/esm/errors/InjectionError.js.map +1 -1
  75. package/lib/esm/errors/InvalidPropertyTokenError.js +8 -0
  76. package/lib/esm/errors/InvalidPropertyTokenError.js.map +1 -0
  77. package/lib/esm/errors/UndefinedTokenError.js +1 -1
  78. package/lib/esm/errors/UndefinedTokenError.js.map +1 -1
  79. package/lib/esm/index.js +9 -1
  80. package/lib/esm/index.js.map +1 -1
  81. package/lib/esm/interfaces/AlterRunInContext.js +2 -0
  82. package/lib/esm/interfaces/AlterRunInContext.js.map +1 -0
  83. package/lib/esm/interfaces/DIConfigurationOptions.js.map +1 -1
  84. package/lib/esm/interfaces/DILoggerOptions.js +2 -0
  85. package/lib/esm/interfaces/DILoggerOptions.js.map +1 -0
  86. package/lib/esm/interfaces/InjectableProperties.js.map +1 -1
  87. package/lib/esm/interfaces/InterceptorMethods.js.map +1 -1
  88. package/lib/esm/interfaces/TokenProvider.js.map +1 -1
  89. package/lib/esm/interfaces/TokenRoute.js +2 -0
  90. package/lib/esm/interfaces/TokenRoute.js.map +1 -0
  91. package/lib/esm/registries/GlobalProviders.js +7 -12
  92. package/lib/esm/registries/GlobalProviders.js.map +1 -1
  93. package/lib/esm/registries/ProviderRegistry.js +1 -1
  94. package/lib/esm/registries/ProviderRegistry.js.map +1 -1
  95. package/lib/esm/services/DIConfiguration.js +57 -44
  96. package/lib/esm/services/DIConfiguration.js.map +1 -1
  97. package/lib/esm/services/DITest.js +5 -6
  98. package/lib/esm/services/DITest.js.map +1 -1
  99. package/lib/esm/services/InjectorService.js +96 -94
  100. package/lib/esm/services/InjectorService.js.map +1 -1
  101. package/lib/esm/utils/asyncHookContext.js +33 -0
  102. package/lib/esm/utils/asyncHookContext.js.map +1 -0
  103. package/lib/esm/utils/getConfiguration.js +12 -10
  104. package/lib/esm/utils/getConfiguration.js.map +1 -1
  105. package/lib/esm/utils/resolveControllers.js +42 -0
  106. package/lib/esm/utils/resolveControllers.js.map +1 -0
  107. package/lib/esm/utils/setLoggerConfiguration.js +7 -0
  108. package/lib/esm/utils/setLoggerConfiguration.js.map +1 -0
  109. package/lib/esm/utils/setLoggerFormat.js +29 -0
  110. package/lib/esm/utils/setLoggerFormat.js.map +1 -0
  111. package/lib/esm/utils/setLoggerLevel.js +1 -2
  112. package/lib/esm/utils/setLoggerLevel.js.map +1 -1
  113. package/lib/types/decorators/controller.d.ts +0 -1
  114. package/lib/types/domain/ContextLogger.d.ts +13 -18
  115. package/lib/types/domain/ControllerProvider.d.ts +17 -0
  116. package/lib/types/domain/DIContext.d.ts +23 -29
  117. package/lib/types/domain/LocalsContainer.d.ts +3 -22
  118. package/lib/types/domain/Provider.d.ts +2 -1
  119. package/lib/types/errors/InvalidPropertyTokenError.d.ts +4 -0
  120. package/lib/types/index.d.ts +9 -1
  121. package/lib/types/interfaces/AlterRunInContext.d.ts +3 -0
  122. package/lib/types/interfaces/DIConfigurationOptions.d.ts +5 -2
  123. package/lib/types/interfaces/DILoggerOptions.d.ts +44 -0
  124. package/lib/types/interfaces/InjectableProperties.d.ts +2 -1
  125. package/lib/types/interfaces/InterceptorMethods.d.ts +1 -1
  126. package/lib/types/interfaces/TokenProvider.d.ts +1 -1
  127. package/lib/types/interfaces/TokenRoute.d.ts +5 -0
  128. package/lib/types/registries/GlobalProviders.d.ts +6 -5
  129. package/lib/types/registries/ProviderRegistry.d.ts +2 -1
  130. package/lib/types/services/DIConfiguration.d.ts +19 -11
  131. package/lib/types/services/InjectorService.d.ts +20 -28
  132. package/lib/types/utils/asyncHookContext.d.ts +14 -0
  133. package/lib/types/utils/getConfiguration.d.ts +1 -0
  134. package/lib/types/utils/resolveControllers.d.ts +12 -0
  135. package/lib/types/utils/setLoggerConfiguration.d.ts +2 -0
  136. package/lib/types/utils/setLoggerFormat.d.ts +6 -0
  137. package/lib/types/utils/setLoggerLevel.d.ts +1 -1
  138. package/package.json +15 -11
  139. package/readme.md +3 -2
  140. package/lib/cjs/utils/runInContext.js +0 -20
  141. package/lib/cjs/utils/runInContext.js.map +0 -1
  142. package/lib/esm/utils/runInContext.js +0 -14
  143. package/lib/esm/utils/runInContext.js.map +0 -1
  144. package/lib/types/utils/runInContext.d.ts +0 -6
@@ -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;IAenB,YAAY,KAAoB,EAAE,UAA6B,EAAE;QAd1D,SAAI,GAAuB,2BAAY,CAAC,QAAQ,CAAC;QAetD,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;QAC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AE,CAAC,CAAC;IACnD,CAAC;IAED,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,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;AArJD,4BAqJC","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 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"]}
1
+ {"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../src/domain/Provider.ts"],"names":[],"mappings":";;;AAAA,qCAA8F;AAG9F,mDAA8C;AAC9C,iDAA4C;AAI5C,MAAa,QAAQ;IACZ,IAAI,GAAuB,2BAAY,CAAC,QAAQ,CAAC;IACjD,IAAI,CAAkB;IACtB,OAAO,CAAQ;IACf,UAAU,CAAW;IACrB,eAAe,CAAW;IAC1B,QAAQ,CAAM;IACd,KAAK,CAA2C;IAC/C,SAAS,CAAU;IACnB,QAAQ,CAAgB;IACxB,MAAM,CAAQ;IACd,WAAW,CAAQ;IAI3B,YAAY,KAAoB,EAAE,UAA6B,EAAE;QAC/D,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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AM,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;AA/JD,4BA+JC","sourcesContent":["import {classOf, getClassOrSymbol, isClass, methodsOf, 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 type ProviderHookCallback<T = any> = (instance: T, ...args: any[]) => Promise<void> | void;\n\nexport class Provider<T = any> implements ProviderOpts<T> {\n public type: ProviderType | any = ProviderType.PROVIDER;\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, ProviderHookCallback<T>>;\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 this.hooks = methodsOf(this._useClass).reduce((hooks, {propertyKey}) => {\n if (String(propertyKey).startsWith(\"$\")) {\n return {\n ...hooks,\n [propertyKey]: (instance: any, ...args: any[]) => instance[propertyKey](...args)\n };\n }\n return hooks;\n }, {} as any);\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"]}
@@ -4,10 +4,11 @@ exports.InjectionError = void 0;
4
4
  const core_1 = require("@tsed/core");
5
5
  const colors_1 = require("../utils/colors");
6
6
  class InjectionError extends Error {
7
+ name = "INJECTION_ERROR";
8
+ tokens = [];
9
+ origin;
7
10
  constructor(token, origin) {
8
11
  super((0, core_1.isString)(origin) ? origin : "");
9
- this.name = "INJECTION_ERROR";
10
- this.tokens = [];
11
12
  this.tokens = [token];
12
13
  if (origin) {
13
14
  if ((0, core_1.isString)(origin)) {
@@ -1 +1 @@
1
- {"version":3,"file":"InjectionError.js","sourceRoot":"","sources":["../../../src/errors/InjectionError.ts"],"names":[],"mappings":";;;AAAA,qCAA6E;AAE7E,4CAAuC;AAEvC,MAAa,cAAe,SAAQ,KAAK;IAMvC,YAAY,KAAoB,EAAE,MAAY;QAC5C,KAAK,CAAC,IAAA,eAAQ,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QANxC,SAAI,GAAG,iBAAiB,CAAC;QAElB,WAAM,GAAoB,EAAE,CAAC;QAMlC,IAAI,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC;QAEtB,IAAI,MAAM,EAAE;YACV,IAAI,IAAA,eAAQ,EAAC,MAAM,CAAC,EAAE;gBACpB,IAAI,CAAC,MAAM,GAAG;oBACZ,OAAO,EAAE,MAAM;oBACf,KAAK,EAAE,IAAI,CAAC,KAAK;iBAClB,CAAC;aACH;iBAAM;gBACL,IAAI,MAAM,CAAC,MAAM,EAAE;oBACjB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;iBAC7B;qBAAM;oBACL,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;oBACrB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;iBAC3B;aACF;SACF;QAED,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE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E,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,eAAM,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAEhH,OAAO,+BAA+B,GAAG,OAAO,CAAC,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACjI,CAAC","sourcesContent":["import {getConstructorArgNames, isClass, isString, nameOf} from \"@tsed/core\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {colors} from \"../utils/colors\";\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 = colors.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) + colors.red(\"^\" + \"‾\".repeat(erroredArg.length - 1));\n\n return \"Unable to inject dependency. \" + options.message + \"\\n\\n\" + signature + \"\\n\" + (indexOf > -1 ? drawline(indexOf) : \"\");\n}\n"]}
1
+ {"version":3,"file":"InjectionError.js","sourceRoot":"","sources":["../../../src/errors/InjectionError.ts"],"names":[],"mappings":";;;AAAA,qCAA6E;AAE7E,4CAAuC;AAEvC,MAAa,cAAe,SAAQ,KAAK;IACvC,IAAI,GAAG,iBAAiB,CAAC;IAElB,MAAM,GAAoB,EAAE,CAAC;IAC7B,MAAM,CAAM;IAEnB,YAAY,KAAoB,EAAE,MAAY;QAC5C,KAAK,CAAC,IAAA,eAAQ,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAEtC,IAAI,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC;QAEtB,IAAI,MAAM,EAAE;YACV,IAAI,IAAA,eAAQ,EAAC,MAAM,CAAC,EAAE;gBACpB,IAAI,CAAC,MAAM,GAAG;oBACZ,OAAO,EAAE,MAAM;oBACf,KAAK,EAAE,IAAI,CAAC,KAAK;iBAClB,CAAC;aACH;iBAAM;gBACL,IAAI,MAAM,CAAC,MAAM,EAAE;oBACjB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;iBAC7B;qBAAM;oBACL,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;oBACrB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;iBAC3B;aACF;SACF;QAED,MAAM,aAAa,GAAG,IAAI,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AAC,KAAK,CAAC,GAAG,gBAAgB,GAAG,IAAI,GAAG,GAAG,CAAC;IAChE,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,eAAM,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAEhH,OAAO,+BAA+B,GAAG,OAAO,CAAC,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACjI,CAAC","sourcesContent":["import {getConstructorArgNames, isClass, isString, nameOf} from \"@tsed/core\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {colors} from \"../utils/colors\";\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 = colors.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) + colors.red(\"^\" + \"‾\".repeat(erroredArg.length - 1));\n\n return \"Unable to inject dependency. \" + options.message + \"\\n\\n\" + signature + \"\\n\" + (indexOf > -1 ? drawline(indexOf) : \"\");\n}\n"]}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidPropertyTokenError = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ class InvalidPropertyTokenError extends Error {
6
+ name = "INVALID_TOKEN_ERROR";
7
+ constructor(target, propertyKey) {
8
+ super(`Object isn't a valid token. Please check the token set on ${(0, core_1.nameOf)((0, core_1.classOf)(target))}.${propertyKey}.\n- Check that it is not a circular reference.\n- Check that the token (class or symbol) exists`);
9
+ }
10
+ }
11
+ exports.InvalidPropertyTokenError = InvalidPropertyTokenError;
12
+ //# sourceMappingURL=InvalidPropertyTokenError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InvalidPropertyTokenError.js","sourceRoot":"","sources":["../../../src/errors/InvalidPropertyTokenError.ts"],"names":[],"mappings":";;;AAAA,qCAA2C;AAE3C,MAAa,yBAA0B,SAAQ,KAAK;IAClD,IAAI,GAAG,qBAAqB,CAAC;IAE7B,YAAY,MAAW,EAAE,WAAmB;QAC1C,KAAK,CACH,6DAA6D,IAAA,aAAM,EACjE,IAAA,cAAO,EAAC,MAAM,CAAC,CAChB,IAAI,WAAW,kGAAkG,CACnH,CAAC;IACJ,CAAC;CACF;AAVD,8DAUC","sourcesContent":["import {classOf, nameOf} from \"@tsed/core\";\n\nexport class InvalidPropertyTokenError extends Error {\n name = \"INVALID_TOKEN_ERROR\";\n\n constructor(target: any, propertyKey: string) {\n super(\n `Object isn't a valid token. Please check the token set on ${nameOf(\n classOf(target)\n )}.${propertyKey}.\\n- Check that it is not a circular reference.\\n- Check that the token (class or symbol) exists`\n );\n }\n}\n"]}
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UndefinedTokenError = void 0;
4
4
  class UndefinedTokenError extends Error {
5
+ name = "UNDEFINED_TOKEN_ERROR";
5
6
  constructor() {
6
7
  super("Given token is undefined. Have you enabled emitDecoratorMetadata in your tsconfig.json or decorated your class with @Injectable, @Service, ... decorator ?");
7
- this.name = "UNDEFINED_TOKEN_ERROR";
8
8
  }
9
9
  }
10
10
  exports.UndefinedTokenError = UndefinedTokenError;
@@ -1 +1 @@
1
- {"version":3,"file":"UndefinedTokenError.js","sourceRoot":"","sources":["../../../src/errors/UndefinedTokenError.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAoB,SAAQ,KAAK;IAG5C;QACE,KAAK,CACH,4JAA4J,CAC7J,CAAC;QALJ,SAAI,GAAG,uBAAuB,CAAC;IAM/B,CAAC;CACF;AARD,kDAQC","sourcesContent":["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"]}
1
+ {"version":3,"file":"UndefinedTokenError.js","sourceRoot":"","sources":["../../../src/errors/UndefinedTokenError.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAoB,SAAQ,KAAK;IAC5C,IAAI,GAAG,uBAAuB,CAAC;IAE/B;QACE,KAAK,CACH,4JAA4J,CAC7J,CAAC;IACJ,CAAC;CACF;AARD,kDAQC","sourcesContent":["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"]}
package/lib/cjs/index.js CHANGED
@@ -22,6 +22,7 @@ tslib_1.__exportStar(require("./decorators/useOpts"), exports);
22
22
  tslib_1.__exportStar(require("./decorators/value"), exports);
23
23
  tslib_1.__exportStar(require("./domain/Container"), exports);
24
24
  tslib_1.__exportStar(require("./domain/ContextLogger"), exports);
25
+ tslib_1.__exportStar(require("./domain/ControllerProvider"), exports);
25
26
  tslib_1.__exportStar(require("./domain/DIContext"), exports);
26
27
  tslib_1.__exportStar(require("./domain/InjectablePropertyType"), exports);
27
28
  tslib_1.__exportStar(require("./domain/LocalsContainer"), exports);
@@ -29,9 +30,12 @@ tslib_1.__exportStar(require("./domain/Provider"), exports);
29
30
  tslib_1.__exportStar(require("./domain/ProviderScope"), exports);
30
31
  tslib_1.__exportStar(require("./domain/ProviderType"), exports);
31
32
  tslib_1.__exportStar(require("./errors/InjectionError"), exports);
33
+ tslib_1.__exportStar(require("./errors/InvalidPropertyTokenError"), exports);
32
34
  tslib_1.__exportStar(require("./errors/UndefinedTokenError"), exports);
35
+ tslib_1.__exportStar(require("./interfaces/AlterRunInContext"), exports);
33
36
  tslib_1.__exportStar(require("./interfaces/DIConfigurationOptions"), exports);
34
37
  tslib_1.__exportStar(require("./interfaces/DILogger"), exports);
38
+ tslib_1.__exportStar(require("./interfaces/DILoggerOptions"), exports);
35
39
  tslib_1.__exportStar(require("./interfaces/DIResolver"), exports);
36
40
  tslib_1.__exportStar(require("./interfaces/InjectableProperties"), exports);
37
41
  tslib_1.__exportStar(require("./interfaces/InterceptorContext"), exports);
@@ -43,15 +47,19 @@ tslib_1.__exportStar(require("./interfaces/ProviderOpts"), exports);
43
47
  tslib_1.__exportStar(require("./interfaces/RegistrySettings"), exports);
44
48
  tslib_1.__exportStar(require("./interfaces/ResolvedInvokeOptions"), exports);
45
49
  tslib_1.__exportStar(require("./interfaces/TokenProvider"), exports);
50
+ tslib_1.__exportStar(require("./interfaces/TokenRoute"), exports);
46
51
  tslib_1.__exportStar(require("./registries/GlobalProviders"), exports);
47
52
  tslib_1.__exportStar(require("./registries/ProviderRegistry"), exports);
48
53
  tslib_1.__exportStar(require("./services/DIConfiguration"), exports);
49
54
  tslib_1.__exportStar(require("./services/DILogger"), exports);
50
55
  tslib_1.__exportStar(require("./services/DITest"), exports);
51
56
  tslib_1.__exportStar(require("./services/InjectorService"), exports);
57
+ tslib_1.__exportStar(require("./utils/asyncHookContext"), exports);
52
58
  tslib_1.__exportStar(require("./utils/colors"), exports);
53
59
  tslib_1.__exportStar(require("./utils/createContainer"), exports);
54
60
  tslib_1.__exportStar(require("./utils/getConfiguration"), exports);
55
- tslib_1.__exportStar(require("./utils/runInContext"), exports);
61
+ tslib_1.__exportStar(require("./utils/resolveControllers"), exports);
62
+ tslib_1.__exportStar(require("./utils/setLoggerConfiguration"), exports);
63
+ tslib_1.__exportStar(require("./utils/setLoggerFormat"), exports);
56
64
  tslib_1.__exportStar(require("./utils/setLoggerLevel"), exports);
57
65
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gEAAsC;AACtC,qEAA2C;AAC3C,gEAAsC;AACtC,kEAAwC;AACxC,8DAAoC;AACpC,kEAAwC;AACxC,iEAAuC;AACvC,mEAAyC;AACzC,kEAAwC;AACxC,8DAAoC;AACpC,4DAAkC;AAClC,wEAA8C;AAC9C,6DAAmC;AACnC,+DAAqC;AACrC,+DAAqC;AACrC,6DAAmC;AACnC,6DAAmC;AACnC,iEAAuC;AACvC,6DAAmC;AACnC,0EAAgD;AAChD,mEAAyC;AACzC,4DAAkC;AAClC,iEAAuC;AACvC,gEAAsC;AACtC,kEAAwC;AACxC,uEAA6C;AAC7C,8EAAoD;AACpD,gEAAsC;AACtC,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,+DAAqC;AACrC,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/runInContext\";\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,sEAA4C;AAC5C,6DAAmC;AACnC,0EAAgD;AAChD,mEAAyC;AACzC,4DAAkC;AAClC,iEAAuC;AACvC,gEAAsC;AACtC,kEAAwC;AACxC,6EAAmD;AACnD,uEAA6C;AAC7C,yEAA+C;AAC/C,8EAAoD;AACpD,gEAAsC;AACtC,uEAA6C;AAC7C,kEAAwC;AACxC,4EAAkD;AAClD,0EAAgD;AAChD,0EAAgD;AAChD,qEAA2C;AAC3C,iEAAuC;AACvC,8DAAoC;AACpC,oEAA0C;AAC1C,wEAA8C;AAC9C,6EAAmD;AACnD,qEAA2C;AAC3C,kEAAwC;AACxC,uEAA6C;AAC7C,wEAA8C;AAC9C,qEAA2C;AAC3C,8DAAoC;AACpC,4DAAkC;AAClC,qEAA2C;AAC3C,mEAAyC;AACzC,yDAA+B;AAC/B,kEAAwC;AACxC,mEAAyC;AACzC,qEAA2C;AAC3C,yEAA+C;AAC/C,kEAAwC;AACxC,iEAAuC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/configuration\";\nexport * from \"./decorators/constant\";\nexport * from \"./decorators/controller\";\nexport * from \"./decorators/inject\";\nexport * from \"./decorators/injectable\";\nexport * from \"./decorators/intercept\";\nexport * from \"./decorators/interceptor\";\nexport * from \"./decorators/lazyInject\";\nexport * from \"./decorators/module\";\nexport * from \"./decorators/opts\";\nexport * from \"./decorators/overrideProvider\";\nexport * from \"./decorators/scope\";\nexport * from \"./decorators/service\";\nexport * from \"./decorators/useOpts\";\nexport * from \"./decorators/value\";\nexport * from \"./domain/Container\";\nexport * from \"./domain/ContextLogger\";\nexport * from \"./domain/ControllerProvider\";\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/InvalidPropertyTokenError\";\nexport * from \"./errors/UndefinedTokenError\";\nexport * from \"./interfaces/AlterRunInContext\";\nexport * from \"./interfaces/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\nexport * from \"./interfaces/DILoggerOptions\";\nexport * from \"./interfaces/DIResolver\";\nexport * from \"./interfaces/InjectableProperties\";\nexport * from \"./interfaces/InterceptorContext\";\nexport * from \"./interfaces/InterceptorMethods\";\nexport * from \"./interfaces/InvokeOptions\";\nexport * from \"./interfaces/OnDestroy\";\nexport * from \"./interfaces/OnInit\";\nexport * from \"./interfaces/ProviderOpts\";\nexport * from \"./interfaces/RegistrySettings\";\nexport * from \"./interfaces/ResolvedInvokeOptions\";\nexport * from \"./interfaces/TokenProvider\";\nexport * from \"./interfaces/TokenRoute\";\nexport * from \"./registries/GlobalProviders\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DITest\";\nexport * from \"./services/InjectorService\";\nexport * from \"./utils/asyncHookContext\";\nexport * from \"./utils/colors\";\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/resolveControllers\";\nexport * from \"./utils/setLoggerConfiguration\";\nexport * from \"./utils/setLoggerFormat\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=AlterRunInContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlterRunInContext.js","sourceRoot":"","sources":["../../../src/interfaces/AlterRunInContext.ts"],"names":[],"mappings":"","sourcesContent":["export interface AlterRunInContext {\n $alterRunInContext(next: (...args: unknown[]) => unknown): () => unknown | Promise<() => unknown>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"DIConfigurationOptions.js","sourceRoot":"","sources":["../../../src/interfaces/DIConfigurationOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type {DIResolver} from \"./DIResolver\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {TokenProvider} from \"./TokenProvider\";\n\ndeclare global {\n namespace TsED {\n interface Context {}\n interface Configuration {\n scopes: {[key: string]: ProviderScope};\n /**\n * Define a list of resolvers (it can be an external DI).\n */\n resolvers: DIResolver[];\n /**\n * Define dependencies to build the provider\n */\n imports: TokenProvider[];\n\n [key: string]: any;\n }\n }\n}\n\nexport interface DIConfigurationOptions extends TsED.Configuration {}\n"]}
1
+ {"version":3,"file":"DIConfigurationOptions.js","sourceRoot":"","sources":["../../../src/interfaces/DIConfigurationOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type {DIResolver} from \"./DIResolver\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {TokenProvider} from \"./TokenProvider\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n interface Context {}\n interface Configuration extends Record<string, any> {\n scopes: {[key: string]: ProviderScope};\n /**\n * Define a list of resolvers (it can be an external DI).\n */\n resolvers: DIResolver[];\n /**\n * Define dependencies to build the provider\n */\n imports: TokenProvider[];\n /**\n * Mount controllers\n */\n mount: Record<string, TokenProvider[]>;\n }\n }\n}\n\nexport interface DIConfigurationOptions extends TsED.Configuration {}\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=DILoggerOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DILoggerOptions.js","sourceRoot":"","sources":["../../../src/interfaces/DILoggerOptions.ts"],"names":[],"mappings":"","sourcesContent":["export interface DILoggerOptions {\n /**\n * Enable debug mode. By default debug is false.\n */\n debug?: boolean;\n /**\n * Enable info mode. By default debug is false.\n */\n level?: \"debug\" | \"info\" | \"warn\" | \"error\" | \"off\";\n /**\n * Enable log performance tracker and disable log server.\n */\n perf?: boolean;\n /**\n * List of regexp to ignore log.\n */\n ignoreUrlPatterns?: (string | RegExp)[];\n /**\n * The number of space characters to use as white space in JSON output. Default is 2 (0 in production).\n */\n jsonIndentation?: number;\n /**\n * A function called for each incoming request to create a request id.\n * @returns {number}\n */\n reqIdBuilder?: (req: any) => string;\n /**\n * Disable routes table displayed in the logger. By default debug is `false`.\n */\n disableRoutesSummary?: boolean;\n /**\n * Disable bootstrap log displayed in the logger. By default debug is `false`.\n */\n disableBootstrapLog?: boolean;\n /**\n * Specify log format. Example: `%[%d{[yyyy-MM-dd hh:mm:ss,SSS}] %p%] %m`. See [@tsed/logger configuration](https://tsedio.github.io/logger/).\n */\n format?: string;\n /**\n * Specify the log stack size for the context.logger. When the stack.length is reach, the logger is flushed during the request.\n * Default size is set to 30.\n */\n maxStackSize?: number;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"InjectableProperties.js","sourceRoot":"","sources":["../../../src/interfaces/InjectableProperties.ts"],"names":[],"mappings":"","sourcesContent":["import type {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\nimport type {TokenProvider} from \"./TokenProvider\";\nimport type {InjectorService} from \"../services/InjectorService\";\nimport type {InvokeOptions} from \"./InvokeOptions\";\n\nexport interface InjectableProperty {\n propertyKey: string;\n}\n\nexport interface InjectablePropertyOptions extends InjectableProperty {\n bindingType: InjectablePropertyType.METHOD | InjectablePropertyType.PROPERTY | InjectablePropertyType.INTERCEPTOR;\n propertyType: string;\n useType?: TokenProvider;\n resolver: (injector: InjectorService, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions> & {options: any}) => () => any;\n options?: any;\n}\n\nexport interface InjectablePropertyValue extends InjectableProperty {\n bindingType: InjectablePropertyType.CONSTANT | InjectablePropertyType.VALUE;\n expression: string;\n defaultValue?: any;\n}\n\nexport interface InjectableProperties {\n [key: string]: InjectablePropertyOptions | InjectablePropertyValue;\n}\n"]}
1
+ {"version":3,"file":"InjectableProperties.js","sourceRoot":"","sources":["../../../src/interfaces/InjectableProperties.ts"],"names":[],"mappings":"","sourcesContent":["import type {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\nimport type {LocalsContainer} from \"../domain/LocalsContainer\";\nimport type {TokenProvider} from \"./TokenProvider\";\nimport type {InjectorService} from \"../services/InjectorService\";\nimport type {InvokeOptions} from \"./InvokeOptions\";\n\nexport interface InjectableProperty {\n propertyKey: string;\n}\n\nexport interface InjectablePropertyOptions extends InjectableProperty {\n bindingType: InjectablePropertyType.METHOD | InjectablePropertyType.PROPERTY | InjectablePropertyType.INTERCEPTOR;\n propertyType: string;\n useType?: TokenProvider;\n resolver: (injector: InjectorService, locals: LocalsContainer, options: Partial<InvokeOptions> & {options: any}) => () => any;\n options?: any;\n}\n\nexport interface InjectablePropertyValue extends InjectableProperty {\n bindingType: InjectablePropertyType.CONSTANT | InjectablePropertyType.VALUE;\n expression: string;\n defaultValue?: any;\n}\n\nexport interface InjectableProperties {\n [key: string]: InjectablePropertyOptions | InjectablePropertyValue;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"InterceptorMethods.js","sourceRoot":"","sources":["../../../src/interfaces/InterceptorMethods.ts"],"names":[],"mappings":"","sourcesContent":["import type {InterceptorContext, InterceptorNext} from \"./InterceptorContext\";\n\nexport interface InterceptorMethods {\n intercept?(context: InterceptorContext, next?: InterceptorNext): any;\n}\n"]}
1
+ {"version":3,"file":"InterceptorMethods.js","sourceRoot":"","sources":["../../../src/interfaces/InterceptorMethods.ts"],"names":[],"mappings":"","sourcesContent":["import type {InterceptorContext, InterceptorNext} from \"./InterceptorContext\";\n\nexport interface InterceptorMethods {\n intercept(context: InterceptorContext, next?: InterceptorNext): any;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"TokenProvider.js","sourceRoot":"","sources":["../../../src/interfaces/TokenProvider.ts"],"names":[],"mappings":"","sourcesContent":["import type {Type} from \"@tsed/core\";\n\nexport type TokenProvider = string | symbol | Type | Function | any;\n"]}
1
+ {"version":3,"file":"TokenProvider.js","sourceRoot":"","sources":["../../../src/interfaces/TokenProvider.ts"],"names":[],"mappings":"","sourcesContent":["import type {Type} from \"@tsed/core\";\n\nexport type TokenProvider<T = any> = string | symbol | Type<T> | Function | any;\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=TokenRoute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TokenRoute.js","sourceRoot":"","sources":["../../../src/interfaces/TokenRoute.ts"],"names":[],"mappings":"","sourcesContent":["import {TokenProvider} from \"./TokenProvider\";\n\nexport interface TokenRoute {\n token: TokenProvider;\n route: string;\n}\n"]}
@@ -1,16 +1,11 @@
1
1
  "use strict";
2
- var _GlobalProviderRegistry_settings;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.GlobalProviders = exports.GlobalProviderRegistry = void 0;
5
- const tslib_1 = require("tslib");
6
4
  const core_1 = require("@tsed/core");
7
5
  const Provider_1 = require("../domain/Provider");
8
6
  const ProviderType_1 = require("../domain/ProviderType");
9
7
  class GlobalProviderRegistry extends Map {
10
- constructor() {
11
- super(...arguments);
12
- _GlobalProviderRegistry_settings.set(this, new Map());
13
- }
8
+ #settings = new Map();
14
9
  /**
15
10
  * The get() method returns a specified element from a Map object.
16
11
  * @param key Required. The key of the element to return from the Map object.
@@ -47,6 +42,7 @@ class GlobalProviderRegistry extends Map {
47
42
  meta[key] = options[key];
48
43
  });
49
44
  this.set(target, meta);
45
+ return meta;
50
46
  }
51
47
  /**
52
48
  * The delete() method removes the specified element from a Map object.
@@ -62,12 +58,12 @@ class GlobalProviderRegistry extends Map {
62
58
  ...options,
63
59
  model
64
60
  });
65
- tslib_1.__classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").set(type, options);
61
+ this.#settings.set(type, options);
66
62
  return this;
67
63
  }
68
64
  onInvoke(provider, locals, options) {
69
- const settings = tslib_1.__classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").get(provider.type);
70
- if (settings === null || settings === void 0 ? void 0 : settings.onInvoke) {
65
+ const settings = this.#settings.get(provider.type);
66
+ if (settings?.onInvoke) {
71
67
  settings.onInvoke(provider, locals, options);
72
68
  }
73
69
  }
@@ -82,7 +78,7 @@ class GlobalProviderRegistry extends Map {
82
78
  type = provider.type;
83
79
  }
84
80
  }
85
- return (tslib_1.__classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").get(type) || {
81
+ return (this.#settings.get(type) || {
86
82
  model: Provider_1.Provider
87
83
  });
88
84
  }
@@ -106,7 +102,7 @@ class GlobalProviderRegistry extends Map {
106
102
  createIfNotExists(key, options) {
107
103
  const type = options.type || ProviderType_1.ProviderType.PROVIDER;
108
104
  if (!this.has(key)) {
109
- const { model = Provider_1.Provider } = tslib_1.__classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").get(type) || {};
105
+ const { model = Provider_1.Provider } = this.#settings.get(type) || {};
110
106
  const item = new model(key, options);
111
107
  this.set(key, item);
112
108
  }
@@ -114,7 +110,6 @@ class GlobalProviderRegistry extends Map {
114
110
  }
115
111
  }
116
112
  exports.GlobalProviderRegistry = GlobalProviderRegistry;
117
- _GlobalProviderRegistry_settings = new WeakMap();
118
113
  /**
119
114
  *
120
115
  * @type {GlobalProviders}
@@ -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,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAqB,EAAE,OAA8B;QACzD,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAErD,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnC,IAAI,CAAC,GAAG,CAAC,GAAI,OAAe,CAAC,GAAG,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACzB,C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C3B,OAAO,CAAC,QAA4B,EAAE,QAAc,EAAQ,EAAE;YAC5D,uBAAuB;YACvB,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;gBACrB,QAAQ,GAAG;oBACT,OAAO,EAAE,QAAQ;iBAClB,CAAC;aACH;YAED,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAC,QAAQ,EAAC,EAAE,QAAQ,EAAE,EAAC,IAAI,EAAC,CAAC,CAAC;YACvD,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACzC,CAAC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACO,iBAAiB,CAAC,GAAkB,EAAE,OAA8B;QAC5E,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,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"]}
1
+ {"version":3,"file":"GlobalProviders.js","sourceRoot":"","sources":["../../../src/registries/GlobalProviders.ts"],"names":[],"mappings":";;;AAAA,qCAAkD;AAElD,iDAA4C;AAC5C,yDAAoD;AAOpD,MAAa,sBAAuB,SAAQ,GAA4B;IACtE,SAAS,GAAkC,IAAI,GAAG,EAAE,CAAC;IAErD;;;;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,CAAC;IAED;;;;OA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E,CAAC;IACxB,CAAC;CACF;AAlID,wDAkIC;AAED;;;GAGG;AACH,0CAA0C;AAC7B,QAAA,eAAe,GAAG,IAAI,sBAAsB,EAAE,CAAC","sourcesContent":["import {getClassOrSymbol, Type} from \"@tsed/core\";\nimport type {LocalsContainer} from \"../domain/LocalsContainer\";\nimport {Provider} from \"../domain/Provider\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {RegistrySettings} from \"../interfaces/RegistrySettings\";\nimport {ResolvedInvokeOptions} from \"../interfaces/ResolvedInvokeOptions\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport type {InjectorService} from \"../services/InjectorService\";\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>) {\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 return 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: LocalsContainer, 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"]}
@@ -17,7 +17,7 @@ function registerProvider(provider) {
17
17
  if (!provider.provide) {
18
18
  throw new Error("Provider.provide is required");
19
19
  }
20
- GlobalProviders_1.GlobalProviders.merge(provider.provide, provider);
20
+ return GlobalProviders_1.GlobalProviders.merge(provider.provide, provider);
21
21
  }
22
22
  exports.registerProvider = registerProvider;
23
23
  /**
@@ -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,CAAa,QAAqC;IAChF,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;;;;;;;;;;;;;;;;;;;;GAoBG;AACI,MAAM,aAAa,GAAG,CAAC,QAAiC,EAAE,KAAW,EAAQ,EAAE;IACpF,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 {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 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"]}
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,CAAa,QAAqC;IAChF,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IAED,OAAO,iCAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAC3D,CAAC;AAND,4CAMC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACI,MAAM,aAAa,GAAG,CAAC,QAAiC,EAAE,KAAW,EAAQ,EAAE;IACpF,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 {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>>) {\n if (!provider.provide) {\n throw new Error(\"Provider.provide is required\");\n }\n\n return GlobalProviders.merge(provider.provide, provider);\n}\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"]}
@@ -3,13 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DIConfiguration = void 0;
4
4
  const core_1 = require("@tsed/core");
5
5
  class DIConfiguration {
6
+ default = new Map();
7
+ map = new Map();
6
8
  constructor(initialProps = {}) {
7
- this.default = new Map();
8
- this.map = new Map();
9
9
  Object.entries({
10
10
  scopes: {},
11
11
  resolvers: [],
12
12
  imports: [],
13
+ routes: [],
14
+ logger: {},
13
15
  ...initialProps
14
16
  }).forEach(([key, value]) => {
15
17
  this.default.set(key, value);
@@ -20,23 +22,60 @@ class DIConfiguration {
20
22
  }
21
23
  });
22
24
  }
25
+ get version() {
26
+ return this.get("version");
27
+ }
28
+ set version(v) {
29
+ this.map.set("version", v);
30
+ }
31
+ get rootDir() {
32
+ return this.get("rootDir");
33
+ }
34
+ set rootDir(value) {
35
+ this.map.set("rootDir", value);
36
+ }
37
+ get env() {
38
+ return this.map.get("env");
39
+ }
40
+ set env(value) {
41
+ this.map.set("env", value);
42
+ }
23
43
  get scopes() {
24
- return this.getRaw("scopes");
44
+ return this.map.get("scopes");
25
45
  }
26
46
  set scopes(value) {
27
- this.setRaw("scopes", value);
47
+ this.map.set("scopes", value);
28
48
  }
29
49
  get resolvers() {
30
50
  return this.getRaw("resolvers");
31
51
  }
32
52
  set resolvers(resolvers) {
33
- this.setRaw("resolvers", resolvers);
53
+ this.map.set("resolvers", resolvers);
34
54
  }
35
55
  get imports() {
36
- return this.getRaw("imports");
56
+ return this.get("imports");
37
57
  }
38
58
  set imports(imports) {
39
- this.setRaw("imports", imports);
59
+ this.map.set("imports", imports);
60
+ }
61
+ get routes() {
62
+ return this.get("routes");
63
+ }
64
+ set routes(routes) {
65
+ this.map.set("routes", routes);
66
+ }
67
+ get logger() {
68
+ return this.get("logger");
69
+ }
70
+ set logger(value) {
71
+ const logger = { ...this.logger, ...value };
72
+ this.map.set("logger", logger);
73
+ }
74
+ get debug() {
75
+ return this.logger.level === "debug";
76
+ }
77
+ set debug(debug) {
78
+ this.logger = { ...this.logger, level: debug ? "debug" : "info" };
40
79
  }
41
80
  /**
42
81
  *
@@ -55,11 +94,17 @@ class DIConfiguration {
55
94
  */
56
95
  set(propertyKey, value) {
57
96
  if (typeof propertyKey === "string") {
58
- this.setRaw(propertyKey, value);
97
+ if (propertyKey in this) {
98
+ // @ts-ignore
99
+ this[propertyKey] = value;
100
+ }
101
+ else {
102
+ this.setRaw(propertyKey, value);
103
+ }
59
104
  }
60
105
  else {
61
106
  Object.entries(propertyKey).forEach(([key, value]) => {
62
- this[key] = value;
107
+ this.set(key, value);
63
108
  });
64
109
  }
65
110
  return this;
@@ -75,7 +120,7 @@ class DIConfiguration {
75
120
  * @returns {undefined|any}
76
121
  */
77
122
  get(propertyKey, defaultValue) {
78
- return this.resolve(this.getRaw(propertyKey, defaultValue));
123
+ return this.getRaw(propertyKey, defaultValue);
79
124
  }
80
125
  getRaw(propertyKey, defaultValue) {
81
126
  const value = (0, core_1.getValue)(this.map, propertyKey);
@@ -84,45 +129,13 @@ class DIConfiguration {
84
129
  }
85
130
  return (0, core_1.getValue)(this.default, propertyKey, defaultValue);
86
131
  }
87
- merge(obj) {
88
- Object.entries(obj).forEach(([key, value]) => {
89
- const descriptor = Object.getOwnPropertyDescriptor(DIConfiguration.prototype, key);
90
- const originalValue = this.get(key);
91
- value = (0, core_1.deepMerge)(value, originalValue);
92
- if (descriptor && !["default", "set", "map", "get"].includes(key)) {
93
- this[key] = value;
94
- }
95
- });
96
- }
97
132
  /**
98
133
  *
99
134
  * @param value
100
135
  * @returns {any}
101
136
  */
102
137
  resolve(value) {
103
- if (typeof value === "object" && value !== null) {
104
- if (![Array, Object].includes((0, core_1.classOf)(value))) {
105
- return value;
106
- }
107
- return Object.entries(value).reduce((o, [k, v]) => {
108
- // @ts-ignore
109
- o[k] = this.resolve(v);
110
- return o;
111
- }, Array.isArray(value) ? [] : {});
112
- }
113
- if (typeof value === "string") {
114
- const replacer = (match, key) => (0, core_1.getValue)(this.map, key);
115
- return value
116
- .replace(/\${([\w.]+)}/gi, replacer)
117
- .replace(/<([\w.]+)>/gi, replacer)
118
- .replace(/{{([\w.]+)}}/gi, replacer);
119
- }
120
- return value;
121
- }
122
- build() {
123
- this.forEach((value, key) => this.map.set(key, this.resolve(value)));
124
- this.set = this.setRaw;
125
- this.get = this.getRaw = (propertyKey, defaultValue) => (0, core_1.getValue)(this.map, propertyKey, defaultValue);
138
+ return value.replace("${rootDir}", this.rootDir);
126
139
  }
127
140
  }
128
141
  exports.DIConfiguration = DIConfiguration;
@@ -1 +1 @@
1
- {"version":3,"file":"DIConfiguration.js","sourceRoot":"","sources":["../../../src/services/DIConfiguration.ts"],"names":[],"mappings":";;;AAAA,qCAAmF;AAKnF,MAAa,eAAe;IAM1B,YAAY,YAAY,GAAG,EAAE;QALpB,YAAO,GAAqB,IAAI,GAAG,EAAE,CAAC;QACrC,QAAG,GAAqB,IAAI,GAAG,EAAE,CAAC;QAK1C,MAAM,CAAC,OAAO,CAAC;YACb,MAAM,EAAE,EAAE;YACV,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,EAAE;YACX,GAAG,YAAY;SAChB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC1B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,OAAO,IAAA,sBAAe,EAAkB,IAAI,EAAE;YAC5C,OAAO,CAAC,MAAM;gBACZ,OAAO,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;YAC1D,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED,IAAI,MAAM,CAAC,KAAqC;QAC9C,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,SAAS,CAAC,SAAuB;QACnC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,SA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C,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;gBACZ,aAAa;gBACb,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBAEvB,OAAO,CAAC,CAAC;YACX,CAAC,EACD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAC/B,CAAC;SACH;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAE,GAAW,EAAE,EAAE,CAAC,IAAA,eAAQ,EAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YACzE,OAAO,KAAK;iBACT,OAAO,CAAC,gBAAgB,EAAE,QAAQ,CAAC;iBACnC,OAAO,CAAC,cAAc,EAAE,QAAQ,CAAC;iBACjC,OAAO,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;SACxC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAErE,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC;QACvB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,WAAmB,EAAE,YAAkB,EAAE,EAAE,CAAC,IAAA,eAAQ,EAAC,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IACtH,CAAC;CACF;AAxJD,0CAwJC","sourcesContent":["import {classOf, deepMerge, getValue, proxyDelegation, setValue} from \"@tsed/core\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\nimport type {DIResolver} from \"../interfaces/DIResolver\";\nimport type {TokenProvider} from \"../interfaces/TokenProvider\";\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"]}
1
+ {"version":3,"file":"DIConfiguration.js","sourceRoot":"","sources":["../../../src/services/DIConfiguration.ts"],"names":[],"mappings":";;;AAAA,qCAA6E;AAO7E,MAAa,eAAe;IACjB,OAAO,GAAqB,IAAI,GAAG,EAAE,CAAC;IACrC,GAAG,GAAqB,IAAI,GAAG,EAAE,CAAC;IAE5C,YAAY,YAAY,GAAG,EAAE;QAC3B,MAAM,CAAC,OAAO,CAAC;YACb,MAAM,EAAE,EAAE;YACV,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,EAAE;YACX,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,EAAE;YACV,GAAG,YAAY;SAChB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC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AK,SAAS,EAAE;YACvB,OAAO,KAAK,CAAC;SACd;QAED,OAAO,IAAA,eAAQ,EAAC,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IAC3D,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,KAAU;QAChB,OAAO,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;CACF;AAnKD,0CAmKC","sourcesContent":["import {classOf, Env, getValue, proxyDelegation, setValue} from \"@tsed/core\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {DILoggerOptions} from \"../interfaces/DILoggerOptions\";\nimport type {DIResolver} from \"../interfaces/DIResolver\";\nimport type {TokenProvider} from \"../interfaces/TokenProvider\";\nimport type {TokenRoute} from \"../interfaces/TokenRoute\";\n\nexport class DIConfiguration {\n readonly default: Map<string, any> = new Map();\n protected map: Map<string, any> = new Map();\n\n constructor(initialProps = {}) {\n Object.entries({\n scopes: {},\n resolvers: [],\n imports: [],\n routes: [],\n logger: {},\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 version() {\n return this.get(\"version\");\n }\n\n set version(v: string) {\n this.map.set(\"version\", v);\n }\n\n get rootDir() {\n return this.get(\"rootDir\");\n }\n\n set rootDir(value: string) {\n this.map.set(\"rootDir\", value);\n }\n\n get env(): Env {\n return this.map.get(\"env\");\n }\n\n set env(value: Env) {\n this.map.set(\"env\", value);\n }\n\n get scopes(): Record<string, ProviderScope> {\n return this.map.get(\"scopes\");\n }\n\n set scopes(value: Record<string, ProviderScope>) {\n this.map.set(\"scopes\", value);\n }\n\n get resolvers(): DIResolver[] {\n return this.getRaw(\"resolvers\");\n }\n\n set resolvers(resolvers: DIResolver[]) {\n this.map.set(\"resolvers\", resolvers);\n }\n\n get imports(): TokenProvider[] {\n return this.get(\"imports\");\n }\n\n set imports(imports: TokenProvider[]) {\n this.map.set(\"imports\", imports);\n }\n\n get routes(): TokenRoute[] {\n return this.get(\"routes\");\n }\n\n set routes(routes: TokenRoute[]) {\n this.map.set(\"routes\", routes);\n }\n\n get logger(): Partial<DILoggerOptions> {\n return this.get(\"logger\");\n }\n\n set logger(value: Partial<DILoggerOptions>) {\n const logger = {...this.logger, ...value};\n this.map.set(\"logger\", logger);\n }\n\n get debug(): boolean {\n return this.logger.level === \"debug\";\n }\n\n set debug(debug: boolean) {\n this.logger = {...this.logger, level: debug ? \"debug\" : \"info\"};\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 if (propertyKey in this) {\n // @ts-ignore\n this[propertyKey] = value;\n } else {\n this.setRaw(propertyKey, value);\n }\n } else {\n Object.entries(propertyKey).forEach(([key, value]) => {\n this.set(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.getRaw(propertyKey, defaultValue);\n }\n\n protected 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 /**\n *\n * @param value\n * @returns {any}\n */\n resolve(value: any) {\n return value.replace(\"${rootDir}\", this.rootDir);\n }\n}\n"]}