@tsed/di 7.0.0-alpha.1 → 7.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/lib/cjs/constants/index.js +7 -0
  2. package/lib/cjs/constants/index.js.map +1 -0
  3. package/lib/cjs/decorators/configuration.js +24 -0
  4. package/lib/cjs/decorators/configuration.js.map +1 -0
  5. package/lib/cjs/decorators/constant.js +55 -0
  6. package/lib/cjs/decorators/constant.js.map +1 -0
  7. package/lib/cjs/decorators/controller.js +53 -0
  8. package/lib/cjs/decorators/controller.js.map +1 -0
  9. package/lib/cjs/decorators/index.js +19 -0
  10. package/lib/cjs/decorators/index.js.map +1 -0
  11. package/lib/cjs/decorators/inject.js +79 -0
  12. package/lib/cjs/decorators/inject.js.map +1 -0
  13. package/lib/cjs/decorators/injectable.js +34 -0
  14. package/lib/cjs/decorators/injectable.js.map +1 -0
  15. package/lib/cjs/decorators/intercept.js +28 -0
  16. package/lib/cjs/decorators/intercept.js.map +1 -0
  17. package/lib/cjs/decorators/interceptor.js +21 -0
  18. package/lib/cjs/decorators/interceptor.js.map +1 -0
  19. package/lib/cjs/decorators/lazyInject.js +71 -0
  20. package/lib/cjs/decorators/lazyInject.js.map +1 -0
  21. package/lib/cjs/decorators/module.js +31 -0
  22. package/lib/cjs/decorators/module.js.map +1 -0
  23. package/lib/cjs/decorators/opts.js +54 -0
  24. package/lib/cjs/decorators/opts.js.map +1 -0
  25. package/lib/cjs/decorators/overrideProvider.js +17 -0
  26. package/lib/cjs/decorators/overrideProvider.js.map +1 -0
  27. package/lib/cjs/decorators/scope.js +16 -0
  28. package/lib/cjs/decorators/scope.js.map +1 -0
  29. package/lib/cjs/decorators/service.js +18 -0
  30. package/lib/cjs/decorators/service.js.map +1 -0
  31. package/lib/cjs/decorators/useOpts.js +65 -0
  32. package/lib/cjs/decorators/useOpts.js.map +1 -0
  33. package/lib/cjs/decorators/value.js +55 -0
  34. package/lib/cjs/decorators/value.js.map +1 -0
  35. package/lib/cjs/domain/Container.js +72 -0
  36. package/lib/cjs/domain/Container.js.map +1 -0
  37. package/lib/cjs/domain/ContextLogger.js +85 -0
  38. package/lib/cjs/domain/ContextLogger.js.map +1 -0
  39. package/lib/cjs/domain/DIContext.js +45 -0
  40. package/lib/cjs/domain/DIContext.js.map +1 -0
  41. package/lib/cjs/domain/InjectablePropertyType.js +12 -0
  42. package/lib/cjs/domain/InjectablePropertyType.js.map +1 -0
  43. package/lib/cjs/domain/LocalsContainer.js +55 -0
  44. package/lib/cjs/domain/LocalsContainer.js.map +1 -0
  45. package/lib/cjs/domain/Provider.js +122 -0
  46. package/lib/cjs/domain/Provider.js.map +1 -0
  47. package/lib/cjs/domain/ProviderScope.js +10 -0
  48. package/lib/cjs/domain/ProviderScope.js.map +1 -0
  49. package/lib/cjs/domain/ProviderType.js +15 -0
  50. package/lib/cjs/domain/ProviderType.js.map +1 -0
  51. package/lib/cjs/domain/index.js +12 -0
  52. package/lib/cjs/domain/index.js.map +1 -0
  53. package/lib/cjs/errors/InjectionError.js +58 -0
  54. package/lib/cjs/errors/InjectionError.js.map +1 -0
  55. package/lib/cjs/errors/UndefinedTokenError.js +11 -0
  56. package/lib/cjs/errors/UndefinedTokenError.js.map +1 -0
  57. package/lib/cjs/index.js +21 -0
  58. package/lib/cjs/index.js.map +1 -0
  59. package/lib/cjs/interfaces/DIConfigurationOptions.js +3 -0
  60. package/lib/cjs/interfaces/DIConfigurationOptions.js.map +1 -0
  61. package/lib/cjs/interfaces/DILogger.js +3 -0
  62. package/lib/cjs/interfaces/DILogger.js.map +1 -0
  63. package/lib/cjs/interfaces/DIResolver.js +3 -0
  64. package/lib/cjs/interfaces/DIResolver.js.map +1 -0
  65. package/lib/cjs/interfaces/IProvider.js +3 -0
  66. package/lib/cjs/interfaces/IProvider.js.map +1 -0
  67. package/lib/cjs/interfaces/InjectableProperties.js +3 -0
  68. package/lib/cjs/interfaces/InjectableProperties.js.map +1 -0
  69. package/lib/cjs/interfaces/InterceptorContext.js +3 -0
  70. package/lib/cjs/interfaces/InterceptorContext.js.map +1 -0
  71. package/lib/cjs/interfaces/InterceptorMethods.js +3 -0
  72. package/lib/cjs/interfaces/InterceptorMethods.js.map +1 -0
  73. package/lib/cjs/interfaces/InvokeOptions.js +3 -0
  74. package/lib/cjs/interfaces/InvokeOptions.js.map +1 -0
  75. package/lib/cjs/interfaces/OnDestroy.js +3 -0
  76. package/lib/cjs/interfaces/OnDestroy.js.map +1 -0
  77. package/lib/cjs/interfaces/OnInit.js +3 -0
  78. package/lib/cjs/interfaces/OnInit.js.map +1 -0
  79. package/lib/cjs/interfaces/RegistrySettings.js +3 -0
  80. package/lib/cjs/interfaces/RegistrySettings.js.map +1 -0
  81. package/lib/cjs/interfaces/ResolvedInvokeOptions.js +3 -0
  82. package/lib/cjs/interfaces/ResolvedInvokeOptions.js.map +1 -0
  83. package/lib/cjs/interfaces/TokenProvider.js +3 -0
  84. package/lib/cjs/interfaces/TokenProvider.js.map +1 -0
  85. package/lib/cjs/interfaces/index.js +18 -0
  86. package/lib/cjs/interfaces/index.js.map +1 -0
  87. package/lib/cjs/registries/GlobalProviders.js +124 -0
  88. package/lib/cjs/registries/GlobalProviders.js.map +1 -0
  89. package/lib/cjs/registries/ProviderRegistry.js +85 -0
  90. package/lib/cjs/registries/ProviderRegistry.js.map +1 -0
  91. package/lib/cjs/services/DIConfiguration.js +129 -0
  92. package/lib/cjs/services/DIConfiguration.js.map +1 -0
  93. package/lib/cjs/services/DILogger.js +13 -0
  94. package/lib/cjs/services/DILogger.js.map +1 -0
  95. package/lib/cjs/services/DITest.js +108 -0
  96. package/lib/cjs/services/DITest.js.map +1 -0
  97. package/lib/cjs/services/InjectorService.js +566 -0
  98. package/lib/cjs/services/InjectorService.js.map +1 -0
  99. package/lib/cjs/utils/colors.js +10 -0
  100. package/lib/cjs/utils/colors.js.map +1 -0
  101. package/lib/cjs/utils/createContainer.js +14 -0
  102. package/lib/cjs/utils/createContainer.js.map +1 -0
  103. package/lib/cjs/utils/data/Test1.js +8 -0
  104. package/lib/cjs/utils/data/Test1.js.map +1 -0
  105. package/lib/cjs/utils/data/Test2.js +8 -0
  106. package/lib/cjs/utils/data/Test2.js.map +1 -0
  107. package/lib/cjs/utils/getConfiguration.js +20 -0
  108. package/lib/cjs/utils/getConfiguration.js.map +1 -0
  109. package/lib/cjs/utils/setLoggerLevel.js +16 -0
  110. package/lib/cjs/utils/setLoggerLevel.js.map +1 -0
  111. package/lib/esm/constants/index.js +4 -0
  112. package/lib/esm/constants/index.js.map +1 -0
  113. package/lib/esm/decorators/configuration.js +20 -0
  114. package/lib/esm/decorators/configuration.js.map +1 -0
  115. package/lib/esm/decorators/constant.js +51 -0
  116. package/lib/esm/decorators/constant.js.map +1 -0
  117. package/lib/esm/decorators/controller.js +49 -0
  118. package/lib/esm/decorators/controller.js.map +1 -0
  119. package/lib/esm/decorators/index.js +16 -0
  120. package/lib/esm/decorators/index.js.map +1 -0
  121. package/lib/esm/decorators/inject.js +74 -0
  122. package/lib/esm/decorators/inject.js.map +1 -0
  123. package/lib/esm/decorators/injectable.js +30 -0
  124. package/lib/esm/decorators/injectable.js.map +1 -0
  125. package/lib/esm/decorators/intercept.js +24 -0
  126. package/lib/esm/decorators/intercept.js.map +1 -0
  127. package/lib/esm/decorators/interceptor.js +17 -0
  128. package/lib/esm/decorators/interceptor.js.map +1 -0
  129. package/lib/esm/decorators/lazyInject.js +66 -0
  130. package/lib/esm/decorators/lazyInject.js.map +1 -0
  131. package/lib/esm/decorators/module.js +27 -0
  132. package/lib/esm/decorators/module.js.map +1 -0
  133. package/lib/esm/decorators/opts.js +50 -0
  134. package/lib/esm/decorators/opts.js.map +1 -0
  135. package/lib/esm/decorators/overrideProvider.js +13 -0
  136. package/lib/esm/decorators/overrideProvider.js.map +1 -0
  137. package/lib/esm/decorators/scope.js +12 -0
  138. package/lib/esm/decorators/scope.js.map +1 -0
  139. package/lib/esm/decorators/service.js +14 -0
  140. package/lib/esm/decorators/service.js.map +1 -0
  141. package/lib/esm/decorators/useOpts.js +61 -0
  142. package/lib/esm/decorators/useOpts.js.map +1 -0
  143. package/lib/esm/decorators/value.js +51 -0
  144. package/lib/esm/decorators/value.js.map +1 -0
  145. package/lib/esm/domain/Container.js +68 -0
  146. package/lib/esm/domain/Container.js.map +1 -0
  147. package/lib/esm/domain/ContextLogger.js +81 -0
  148. package/lib/esm/domain/ContextLogger.js.map +1 -0
  149. package/lib/esm/domain/DIContext.js +41 -0
  150. package/lib/esm/domain/DIContext.js.map +1 -0
  151. package/lib/esm/domain/InjectablePropertyType.js +9 -0
  152. package/lib/esm/domain/InjectablePropertyType.js.map +1 -0
  153. package/lib/esm/domain/LocalsContainer.js +51 -0
  154. package/lib/esm/domain/LocalsContainer.js.map +1 -0
  155. package/lib/esm/domain/Provider.js +118 -0
  156. package/lib/esm/domain/Provider.js.map +1 -0
  157. package/lib/esm/domain/ProviderScope.js +7 -0
  158. package/lib/esm/domain/ProviderScope.js.map +1 -0
  159. package/lib/esm/domain/ProviderType.js +12 -0
  160. package/lib/esm/domain/ProviderType.js.map +1 -0
  161. package/lib/esm/domain/index.js +9 -0
  162. package/lib/esm/domain/index.js.map +1 -0
  163. package/lib/esm/errors/InjectionError.js +54 -0
  164. package/lib/esm/errors/InjectionError.js.map +1 -0
  165. package/lib/esm/errors/UndefinedTokenError.js +7 -0
  166. package/lib/esm/errors/UndefinedTokenError.js.map +1 -0
  167. package/lib/esm/index.js +18 -0
  168. package/lib/esm/index.js.map +1 -0
  169. package/lib/esm/interfaces/DIConfigurationOptions.js +2 -0
  170. package/lib/esm/interfaces/DIConfigurationOptions.js.map +1 -0
  171. package/lib/esm/interfaces/DILogger.js +2 -0
  172. package/lib/esm/interfaces/DILogger.js.map +1 -0
  173. package/lib/esm/interfaces/DIResolver.js +2 -0
  174. package/lib/esm/interfaces/DIResolver.js.map +1 -0
  175. package/lib/esm/interfaces/IProvider.js +2 -0
  176. package/lib/esm/interfaces/IProvider.js.map +1 -0
  177. package/lib/esm/interfaces/InjectableProperties.js +2 -0
  178. package/lib/esm/interfaces/InjectableProperties.js.map +1 -0
  179. package/lib/esm/interfaces/InterceptorContext.js +2 -0
  180. package/lib/esm/interfaces/InterceptorContext.js.map +1 -0
  181. package/lib/esm/interfaces/InterceptorMethods.js +2 -0
  182. package/lib/esm/interfaces/InterceptorMethods.js.map +1 -0
  183. package/lib/esm/interfaces/InvokeOptions.js +2 -0
  184. package/lib/esm/interfaces/InvokeOptions.js.map +1 -0
  185. package/lib/esm/interfaces/OnDestroy.js +2 -0
  186. package/lib/esm/interfaces/OnDestroy.js.map +1 -0
  187. package/lib/esm/interfaces/OnInit.js +2 -0
  188. package/lib/esm/interfaces/OnInit.js.map +1 -0
  189. package/lib/esm/interfaces/RegistrySettings.js +2 -0
  190. package/lib/esm/interfaces/RegistrySettings.js.map +1 -0
  191. package/lib/esm/interfaces/ResolvedInvokeOptions.js +2 -0
  192. package/lib/esm/interfaces/ResolvedInvokeOptions.js.map +1 -0
  193. package/lib/esm/interfaces/TokenProvider.js +2 -0
  194. package/lib/esm/interfaces/TokenProvider.js.map +1 -0
  195. package/lib/esm/interfaces/index.js +15 -0
  196. package/lib/esm/interfaces/index.js.map +1 -0
  197. package/lib/esm/registries/GlobalProviders.js +120 -0
  198. package/lib/esm/registries/GlobalProviders.js.map +1 -0
  199. package/lib/esm/registries/ProviderRegistry.js +80 -0
  200. package/lib/esm/registries/ProviderRegistry.js.map +1 -0
  201. package/lib/esm/services/DIConfiguration.js +125 -0
  202. package/lib/esm/services/DIConfiguration.js.map +1 -0
  203. package/lib/esm/services/DILogger.js +11 -0
  204. package/lib/esm/services/DILogger.js.map +1 -0
  205. package/lib/esm/services/DITest.js +104 -0
  206. package/lib/esm/services/DITest.js.map +1 -0
  207. package/lib/esm/services/InjectorService.js +563 -0
  208. package/lib/esm/services/InjectorService.js.map +1 -0
  209. package/lib/esm/utils/colors.js +7 -0
  210. package/lib/esm/utils/colors.js.map +1 -0
  211. package/lib/esm/utils/createContainer.js +10 -0
  212. package/lib/esm/utils/createContainer.js.map +1 -0
  213. package/lib/esm/utils/data/Test1.js +4 -0
  214. package/lib/esm/utils/data/Test1.js.map +1 -0
  215. package/lib/esm/utils/data/Test2.js +4 -0
  216. package/lib/esm/utils/data/Test2.js.map +1 -0
  217. package/lib/esm/utils/getConfiguration.js +16 -0
  218. package/lib/esm/utils/getConfiguration.js.map +1 -0
  219. package/lib/esm/utils/setLoggerLevel.js +12 -0
  220. package/lib/esm/utils/setLoggerLevel.js.map +1 -0
  221. package/lib/{constants → types/constants}/index.d.ts +0 -0
  222. package/lib/{decorators → types/decorators}/configuration.d.ts +0 -0
  223. package/lib/{decorators → types/decorators}/constant.d.ts +0 -0
  224. package/lib/types/decorators/controller.d.ts +43 -0
  225. package/lib/{decorators → types/decorators}/index.d.ts +2 -0
  226. package/lib/{decorators → types/decorators}/inject.d.ts +2 -0
  227. package/lib/{decorators → types/decorators}/injectable.d.ts +2 -1
  228. package/lib/{decorators → types/decorators}/intercept.d.ts +0 -0
  229. package/lib/{decorators → types/decorators}/interceptor.d.ts +0 -0
  230. package/lib/types/decorators/lazyInject.d.ts +43 -0
  231. package/lib/{decorators → types/decorators}/module.d.ts +0 -0
  232. package/lib/{decorators → types/decorators}/opts.d.ts +0 -0
  233. package/lib/{decorators → types/decorators}/overrideProvider.d.ts +0 -0
  234. package/lib/{decorators → types/decorators}/scope.d.ts +0 -0
  235. package/lib/{decorators → types/decorators}/service.d.ts +0 -0
  236. package/lib/{decorators → types/decorators}/useOpts.d.ts +0 -0
  237. package/lib/{decorators → types/decorators}/value.d.ts +0 -0
  238. package/lib/{domain → types/domain}/Container.d.ts +2 -3
  239. package/lib/{domain → types/domain}/ContextLogger.d.ts +5 -1
  240. package/lib/{domain → types/domain}/DIContext.d.ts +6 -7
  241. package/lib/{domain → types/domain}/InjectablePropertyType.d.ts +0 -0
  242. package/lib/{domain → types/domain}/LocalsContainer.d.ts +0 -0
  243. package/lib/{domain → types/domain}/Provider.d.ts +17 -3
  244. package/lib/{domain → types/domain}/ProviderScope.d.ts +0 -0
  245. package/lib/{domain → types/domain}/ProviderType.d.ts +0 -0
  246. package/lib/{domain → types/domain}/index.d.ts +0 -0
  247. package/lib/{errors → types/errors}/InjectionError.d.ts +0 -0
  248. package/lib/{errors → types/errors}/UndefinedTokenError.d.ts +0 -0
  249. package/lib/{index.d.ts → types/index.d.ts} +1 -0
  250. package/lib/{interfaces → types/interfaces}/DIConfigurationOptions.d.ts +0 -0
  251. package/lib/{interfaces → types/interfaces}/DILogger.d.ts +0 -0
  252. package/lib/{interfaces → types/interfaces}/DIResolver.d.ts +0 -0
  253. package/lib/{interfaces → types/interfaces}/IProvider.d.ts +0 -0
  254. package/lib/{interfaces → types/interfaces}/InjectableProperties.d.ts +8 -4
  255. package/lib/{interfaces → types/interfaces}/InterceptorContext.d.ts +0 -0
  256. package/lib/{interfaces → types/interfaces}/InterceptorMethods.d.ts +0 -0
  257. package/lib/{interfaces → types/interfaces}/InvokeOptions.d.ts +0 -0
  258. package/lib/{interfaces → types/interfaces}/OnDestroy.d.ts +0 -0
  259. package/lib/{interfaces → types/interfaces}/OnInit.d.ts +0 -0
  260. package/lib/{interfaces → types/interfaces}/RegistrySettings.d.ts +6 -2
  261. package/lib/types/interfaces/ResolvedInvokeOptions.d.ts +12 -0
  262. package/lib/{interfaces → types/interfaces}/TokenProvider.d.ts +0 -0
  263. package/lib/{interfaces → types/interfaces}/index.d.ts +1 -0
  264. package/lib/{registries → types/registries}/GlobalProviders.d.ts +5 -1
  265. package/lib/{registries → types/registries}/ProviderRegistry.d.ts +0 -0
  266. package/lib/{services → types/services}/DIConfiguration.d.ts +0 -0
  267. package/lib/{services → types/services}/DILogger.d.ts +0 -0
  268. package/lib/{services → types/services}/DITest.d.ts +5 -1
  269. package/lib/{services → types/services}/InjectorService.d.ts +31 -14
  270. package/lib/types/utils/colors.d.ts +5 -0
  271. package/lib/{utils → types/utils}/createContainer.d.ts +0 -0
  272. package/lib/types/utils/data/Test1.d.ts +3 -0
  273. package/lib/types/utils/data/Test2.d.ts +3 -0
  274. package/lib/{utils → types/utils}/getConfiguration.d.ts +0 -0
  275. package/lib/{utils → types/utils}/setLoggerLevel.d.ts +0 -0
  276. package/package.json +15 -11
  277. package/readme.md +1 -1
  278. package/tsconfig.compile.esm.json +24 -0
  279. package/lib/index.js +0 -2271
  280. package/lib/index.js.map +0 -1
  281. package/lib/index.modern.js +0 -2235
  282. package/lib/index.modern.js.map +0 -1
@@ -0,0 +1,54 @@
1
+ import { getConstructorArgNames, isClass, isString, nameOf } from "@tsed/core";
2
+ import { colors } from "../utils/colors";
3
+ export class InjectionError extends Error {
4
+ constructor(token, origin) {
5
+ super(isString(origin) ? origin : "");
6
+ this.name = "INJECTION_ERROR";
7
+ this.tokens = [];
8
+ this.tokens = [token];
9
+ if (origin) {
10
+ if (isString(origin)) {
11
+ this.origin = {
12
+ message: origin,
13
+ stack: this.stack
14
+ };
15
+ }
16
+ else {
17
+ if (origin.tokens) {
18
+ this.tokens = this.tokens.concat(origin.tokens);
19
+ this.origin = origin.origin;
20
+ }
21
+ else {
22
+ this.origin = origin;
23
+ this.stack = origin.stack;
24
+ }
25
+ }
26
+ }
27
+ const originMessage = this.origin ? "\nOrigin: " + this.origin.message : "";
28
+ const tokensMessage = this.tokens.map((token) => nameOf(token)).join(" > ");
29
+ this.message = `Injection failed on ${tokensMessage}${originMessage}`;
30
+ }
31
+ static throwInjectorError(token, currentDependency, error) {
32
+ if (currentDependency && isClass(token)) {
33
+ error.message = printDependencyInjectionError(token, { ...currentDependency, message: error.message });
34
+ }
35
+ throw new InjectionError(token, error);
36
+ }
37
+ }
38
+ function printDependencyInjectionError(token, options) {
39
+ let erroredArg = "";
40
+ const args = getConstructorArgNames(token)
41
+ .map((arg, index) => {
42
+ if (options.index === index) {
43
+ erroredArg = arg;
44
+ arg = colors.red(arg);
45
+ }
46
+ return `${arg}: ${nameOf(options.deps[index])}`;
47
+ })
48
+ .join(", ");
49
+ const signature = nameOf(token) + "->constructor(" + args + ")";
50
+ const indexOf = signature.indexOf(erroredArg) - 5;
51
+ const drawline = (indexOf) => " ".repeat(indexOf) + colors.red("^" + "‾".repeat(erroredArg.length - 1));
52
+ return "Unable to inject dependency. " + options.message + "\n\n" + signature + "\n" + (indexOf > -1 ? drawline(indexOf) : "");
53
+ }
54
+ //# sourceMappingURL=InjectionError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InjectionError.js","sourceRoot":"","sources":["../../../src/errors/InjectionError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAC,MAAM,YAAY,CAAC;AAE7E,OAAO,EAAC,MAAM,EAAC,MAAM,iBAAiB,CAAC;AAEvC,MAAM,OAAO,cAAe,SAAQ,KAAK;IAMvC,YAAY,KAAoB,EAAE,MAAY;QAC5C,KAAK,CAAC,QAAQ,CAAC,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,QAAQ,CAAC,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,C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IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,SAAS,GAAG,MAAM,CAAC,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,MAAM,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\";\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,7 @@
1
+ export class UndefinedTokenError extends Error {
2
+ constructor() {
3
+ super("Given token is undefined. Have you enabled emitDecoratorMetadata in your tsconfig.json or decorated your class with @Injectable, @Service, ... decorator ?");
4
+ this.name = "UNDEFINED_TOKEN_ERROR";
5
+ }
6
+ }
7
+ //# sourceMappingURL=UndefinedTokenError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UndefinedTokenError.js","sourceRoot":"","sources":["../../../src/errors/UndefinedTokenError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAG5C;QACE,KAAK,CACH,4JAA4J,CAC7J,CAAC;QALJ,SAAI,GAAG,uBAAuB,CAAC;IAM/B,CAAC;CACF","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"]}
@@ -0,0 +1,18 @@
1
+ export * from "./constants/index";
2
+ export * from "./domain";
3
+ export * from "./interfaces";
4
+ export * from "./decorators";
5
+ export * from "./registries/ProviderRegistry";
6
+ export * from "./registries/GlobalProviders";
7
+ export * from "./services/InjectorService";
8
+ export * from "./services/DILogger";
9
+ export * from "./services/DIConfiguration";
10
+ export * from "./services/DITest";
11
+ export * from "./errors/InjectionError";
12
+ export * from "./errors/UndefinedTokenError";
13
+ export * from "./utils/createContainer";
14
+ export * from "./utils/getConfiguration";
15
+ export * from "./utils/getConfiguration";
16
+ export * from "./utils/setLoggerLevel";
17
+ export * from "./utils/colors";
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAE7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAElC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAE7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC","sourcesContent":["export * from \"./constants/index\";\nexport * from \"./domain\";\nexport * from \"./interfaces\";\nexport * from \"./decorators\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./registries/GlobalProviders\";\n\nexport * from \"./services/InjectorService\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DITest\";\n\nexport * from \"./errors/InjectionError\";\nexport * from \"./errors/UndefinedTokenError\";\n\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/setLoggerLevel\";\nexport * from \"./utils/colors\";\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=DIConfigurationOptions.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=DILogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DILogger.js","sourceRoot":"","sources":["../../../src/interfaces/DILogger.ts"],"names":[],"mappings":"","sourcesContent":["export interface DILogger {\n info(...args: any[]): void | any;\n\n warn(...args: any[]): void | any;\n\n debug(...args: any[]): void | any;\n\n error(...args: any[]): void | any;\n\n trace(...args: any[]): void | any;\n\n [key: string]: any;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=DIResolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DIResolver.js","sourceRoot":"","sources":["../../../src/interfaces/DIResolver.ts"],"names":[],"mappings":"","sourcesContent":["import type {TokenProvider} from \"./TokenProvider\";\n\nexport interface DIResolver {\n deps?: TokenProvider[];\n get<T = any>(type: TokenProvider, options: any): T | undefined;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../../src/interfaces/IProvider.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/**\n *\n */\nexport interface IProvider<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 *\n */\n [key: string]: any;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=InjectableProperties.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=InterceptorContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InterceptorContext.js","sourceRoot":"","sources":["../../../src/interfaces/InterceptorContext.ts"],"names":[],"mappings":"","sourcesContent":["import type {Type} from \"@tsed/core\";\n\nexport interface InterceptorNext {\n <T>(err?: Error): T;\n}\n\nexport interface InterceptorContext<Klass = Type, Opts = any> {\n target: Klass;\n propertyKey: string;\n args: any[];\n next: InterceptorNext;\n options?: Opts;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=InterceptorMethods.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=InvokeOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InvokeOptions.js","sourceRoot":"","sources":["../../../src/interfaces/InvokeOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {ProviderScope} from \"../domain/ProviderScope\";\nimport {TokenProvider} from \"./TokenProvider\";\n\nexport interface InvokeOptions<T = any> {\n deps: any[];\n imports: any[];\n parent?: TokenProvider;\n scope: ProviderScope;\n useScope: boolean;\n rebuild?: boolean;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=OnDestroy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OnDestroy.js","sourceRoot":"","sources":["../../../src/interfaces/OnDestroy.ts"],"names":[],"mappings":"","sourcesContent":["export interface OnDestroy {\n $onDestroy(): Promise<any> | void;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=OnInit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OnInit.js","sourceRoot":"","sources":["../../../src/interfaces/OnInit.ts"],"names":[],"mappings":"","sourcesContent":["export interface OnInit {\n $onInit(): Promise<any> | void;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=RegistrySettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegistrySettings.js","sourceRoot":"","sources":["../../../src/interfaces/RegistrySettings.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\nimport type {Provider} from \"../domain\";\nimport type {InjectorService} from \"../services/InjectorService\";\nimport type {ResolvedInvokeOptions} from \"./ResolvedInvokeOptions\";\n\n/**\n * @ignore\n */\nexport interface RegistrySettings {\n injectable?: boolean;\n model?: Type<Provider>;\n\n /**\n *\n * @param provider\n * @param {Map<string | Function, any>} locals\n * @param options\n */\n onInvoke?(provider: Provider, locals: Map<string | Function, any>, options: ResolvedInvokeOptions & {injector: InjectorService}): void;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ResolvedInvokeOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResolvedInvokeOptions.js","sourceRoot":"","sources":["../../../src/interfaces/ResolvedInvokeOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type {Provider} from \"../domain/Provider\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {TokenProvider} from \"./TokenProvider\";\n\nexport interface ResolvedInvokeOptions {\n token: TokenProvider;\n parent?: TokenProvider;\n scope: ProviderScope;\n deps: TokenProvider[];\n imports: TokenProvider[];\n provider: Provider;\n\n construct(deps: TokenProvider[]): any;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=TokenProvider.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,15 @@
1
+ export * from "./DILogger";
2
+ export * from "./DIConfigurationOptions";
3
+ export * from "./DIResolver";
4
+ export * from "./InjectableProperties";
5
+ export * from "./InterceptorMethods";
6
+ export * from "./InterceptorContext";
7
+ export * from "./InvokeOptions";
8
+ export * from "./IProvider";
9
+ export * from "./OnInit";
10
+ export * from "./OnDestroy";
11
+ export * from "./OnInit";
12
+ export * from "./RegistrySettings";
13
+ export * from "./TokenProvider";
14
+ export * from "./ResolvedInvokeOptions";
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC","sourcesContent":["export * from \"./DILogger\";\nexport * from \"./DIConfigurationOptions\";\nexport * from \"./DIResolver\";\nexport * from \"./InjectableProperties\";\nexport * from \"./InterceptorMethods\";\nexport * from \"./InterceptorContext\";\nexport * from \"./InvokeOptions\";\nexport * from \"./IProvider\";\nexport * from \"./OnInit\";\nexport * from \"./OnDestroy\";\nexport * from \"./OnInit\";\nexport * from \"./RegistrySettings\";\nexport * from \"./TokenProvider\";\nexport * from \"./ResolvedInvokeOptions\";\n"]}
@@ -0,0 +1,120 @@
1
+ var _GlobalProviderRegistry_settings;
2
+ import { __classPrivateFieldGet } from "tslib";
3
+ import { getClassOrSymbol } from "@tsed/core";
4
+ import { Provider } from "../domain/Provider";
5
+ import { ProviderType } from "../domain/ProviderType";
6
+ export class GlobalProviderRegistry extends Map {
7
+ constructor() {
8
+ super(...arguments);
9
+ _GlobalProviderRegistry_settings.set(this, new Map());
10
+ }
11
+ /**
12
+ * The get() method returns a specified element from a Map object.
13
+ * @param key Required. The key of the element to return from the Map object.
14
+ * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.
15
+ */
16
+ get(key) {
17
+ return super.get(getClassOrSymbol(key));
18
+ }
19
+ /**
20
+ * The has() method returns a boolean indicating whether an element with the specified key exists or not.
21
+ * @param key
22
+ * @returns {boolean}
23
+ */
24
+ has(key) {
25
+ return super.has(getClassOrSymbol(key));
26
+ }
27
+ /**
28
+ * The set() method adds or updates an element with a specified key and value to a Map object.
29
+ * @param key Required. The key of the element to add to the Map object.
30
+ * @param metadata Required. The value of the element to add to the Map object.
31
+ */
32
+ set(key, metadata) {
33
+ super.set(getClassOrSymbol(key), metadata);
34
+ return this;
35
+ }
36
+ /**
37
+ *
38
+ * @param target
39
+ * @param options
40
+ */
41
+ merge(target, options) {
42
+ const meta = this.createIfNotExists(target, options);
43
+ Object.keys(options).forEach((key) => {
44
+ meta[key] = options[key];
45
+ });
46
+ this.set(target, meta);
47
+ }
48
+ /**
49
+ * The delete() method removes the specified element from a Map object.
50
+ * @param key Required. The key of the element to remove from the Map object.
51
+ * @returns {boolean} Returns true if an element in the Map object existed and has been removed, or false if the element does not exist.
52
+ */
53
+ delete(key) {
54
+ return super.delete(getClassOrSymbol(key));
55
+ }
56
+ createRegistry(type, model, options = {}) {
57
+ const defaultOptions = this.getRegistrySettings(type);
58
+ options = Object.assign(defaultOptions, {
59
+ ...options,
60
+ model
61
+ });
62
+ __classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").set(type, options);
63
+ return this;
64
+ }
65
+ onInvoke(provider, locals, options) {
66
+ const settings = __classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").get(provider.type);
67
+ if (settings === null || settings === void 0 ? void 0 : settings.onInvoke) {
68
+ settings.onInvoke(provider, locals, options);
69
+ }
70
+ }
71
+ getRegistrySettings(target) {
72
+ let type = "provider";
73
+ if (typeof target === "string") {
74
+ type = target;
75
+ }
76
+ else {
77
+ const provider = this.get(target);
78
+ if (provider) {
79
+ type = provider.type;
80
+ }
81
+ }
82
+ return (__classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").get(type) || {
83
+ model: Provider
84
+ });
85
+ }
86
+ createRegisterFn(type) {
87
+ return (provider, instance) => {
88
+ // istanbul ignore next
89
+ if (!provider.provide) {
90
+ provider = {
91
+ provide: provider
92
+ };
93
+ }
94
+ provider = Object.assign({ instance }, provider, { type });
95
+ this.merge(provider.provide, provider);
96
+ };
97
+ }
98
+ /**
99
+ *
100
+ * @param key
101
+ * @param options
102
+ */
103
+ createIfNotExists(key, options) {
104
+ const type = options.type || ProviderType.PROVIDER;
105
+ if (!this.has(key)) {
106
+ const { model = Provider } = __classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").get(type) || {};
107
+ const item = new model(key, options);
108
+ this.set(key, item);
109
+ }
110
+ return this.get(key);
111
+ }
112
+ }
113
+ _GlobalProviderRegistry_settings = new WeakMap();
114
+ /**
115
+ *
116
+ * @type {GlobalProviders}
117
+ */
118
+ // tslint:disable-next-line: variable-name
119
+ export const GlobalProviders = new GlobalProviderRegistry();
120
+ //# sourceMappingURL=GlobalProviders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GlobalProviders.js","sourceRoot":"","sources":["../../../src/registries/GlobalProviders.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,gBAAgB,EAAO,MAAM,YA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,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,OAA2B;QACzE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,YAAY,CAAC,QAAQ,CAAC;QAEnD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAClB,MAAM,EAAC,KAAK,GAAG,QAAQ,EAAC,GAAG,uBAAA,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;;AAED;;;GAGG;AACH,0CAA0C;AAC1C,MAAM,CAAC,MAAM,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 {IProvider, RegistrySettings, TokenProvider} from \"../interfaces\";\nimport type {InjectorService} from \"../services/InjectorService\";\nimport {ResolvedInvokeOptions} from \"../interfaces/ResolvedInvokeOptions\";\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"]}
@@ -0,0 +1,80 @@
1
+ import { Provider } from "../domain/Provider";
2
+ import { ProviderScope, ProviderType } from "../domain";
3
+ import { GlobalProviders } from "./GlobalProviders";
4
+ /**
5
+ *
6
+ */
7
+ GlobalProviders.createRegistry(ProviderType.CONTROLLER, Provider);
8
+ /**
9
+ * Register a provider configuration.
10
+ * @param {IProvider<any>} provider
11
+ */
12
+ export function registerProvider(provider) {
13
+ if (!provider.provide) {
14
+ throw new Error("Provider.provide is required");
15
+ }
16
+ GlobalProviders.merge(provider.provide, provider);
17
+ }
18
+ /**
19
+ * Add a new value in the `ProviderRegistry`.
20
+ *
21
+ * #### Example with symbol definition
22
+ *
23
+ *
24
+ * ```typescript
25
+ * import {registerValue, InjectorService} from "@tsed/di";
26
+ *
27
+ * const MyValue = Symbol.from("MyValue")
28
+ *
29
+ * registerValue({token: MyValue, useValue: "myValue"});
30
+ *
31
+ * @Service()
32
+ * export class OtherService {
33
+ * constructor(@Inject(MyValue) myValue: string){
34
+ * console.log(myValue); /// "myValue"
35
+ * }
36
+ * }
37
+ * ```
38
+ */
39
+ export const registerValue = (provider, value) => {
40
+ if (!provider.provide) {
41
+ provider = {
42
+ provide: provider
43
+ };
44
+ }
45
+ provider = Object.assign({
46
+ scope: ProviderScope.SINGLETON,
47
+ useValue: value
48
+ }, provider, { type: ProviderType.VALUE });
49
+ GlobalProviders.merge(provider.provide, provider);
50
+ };
51
+ /**
52
+ * Add a new controller in the `ProviderRegistry`. This controller will be built when `InjectorService` will be loaded.
53
+ *
54
+ * #### Example
55
+ *
56
+ * ```typescript
57
+ * import {registerController, InjectorService} from "@tsed/di";
58
+ *
59
+ * export default class MyController {
60
+ * constructor(){}
61
+ * transform() {
62
+ * return "test";
63
+ * }
64
+ * }
65
+ *
66
+ * registerController({provide: MyController});
67
+ * // or
68
+ * registerController(MyController);
69
+ *
70
+ * const injector = new InjectorService();
71
+ * injector.load();
72
+ *
73
+ * const myController = injector.get<MyController>(MyController);
74
+ * myController.getFoo(); // test
75
+ * ```
76
+ *
77
+ * @param provider Provider configuration.
78
+ */
79
+ export const registerController = GlobalProviders.createRegisterFn(ProviderType.CONTROLLER);
80
+ //# sourceMappingURL=ProviderRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProviderRegistry.js","sourceRoot":"","sources":["../../../src/registries/ProviderRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAC,aAAa,EAAE,YAAY,EAAC,MAAM,WAAW,CAAC;AACtD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD;;GAEG;AACH,eAAe,CAAC,cAAc,CAAC,YAAY,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAElE;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAA4B;IAC3D,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IAED,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACpD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,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,aAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,KAAK;KAChB,EACD,QAAQ,EACR,EAAC,IAAI,EAAE,YAAY,CAAC,KAAK,EAAC,CAC3B,CAAC;IACF,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAC,gBAAgB,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC","sourcesContent":["import {Provider} from \"../domain/Provider\";\nimport type {IProvider} from \"../interfaces\";\nimport {ProviderScope, ProviderType} from \"../domain\";\nimport {GlobalProviders} from \"./GlobalProviders\";\n\n/**\n *\n */\nGlobalProviders.createRegistry(ProviderType.CONTROLLER, Provider);\n\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 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"]}
@@ -0,0 +1,125 @@
1
+ import { classOf, deepMerge, getValue, proxyDelegation, setValue } from "@tsed/core";
2
+ export class DIConfiguration {
3
+ constructor(initialProps = {}) {
4
+ this.default = new Map();
5
+ this.map = new Map();
6
+ Object.entries({
7
+ scopes: {},
8
+ resolvers: [],
9
+ imports: [],
10
+ ...initialProps
11
+ }).forEach(([key, value]) => {
12
+ this.default.set(key, value);
13
+ });
14
+ return proxyDelegation(this, {
15
+ ownKeys(target) {
16
+ return [...target.default.keys(), ...target.map.keys()];
17
+ }
18
+ });
19
+ }
20
+ get scopes() {
21
+ return this.getRaw("scopes");
22
+ }
23
+ set scopes(value) {
24
+ this.setRaw("scopes", value);
25
+ }
26
+ get resolvers() {
27
+ return this.getRaw("resolvers");
28
+ }
29
+ set resolvers(resolvers) {
30
+ this.setRaw("resolvers", resolvers);
31
+ }
32
+ get imports() {
33
+ return this.getRaw("imports");
34
+ }
35
+ set imports(imports) {
36
+ this.setRaw("imports", imports);
37
+ }
38
+ /**
39
+ *
40
+ * @param callbackfn
41
+ * @param thisArg
42
+ */
43
+ forEach(callbackfn, thisArg) {
44
+ return new Set([...Array.from(this.default.keys()), ...Array.from(this.map.keys())]).forEach((key) => {
45
+ callbackfn(this.getRaw(key), key, this.map);
46
+ }, thisArg);
47
+ }
48
+ /**
49
+ *
50
+ * @param propertyKey
51
+ * @param value
52
+ */
53
+ set(propertyKey, value) {
54
+ if (typeof propertyKey === "string") {
55
+ this.setRaw(propertyKey, value);
56
+ }
57
+ else {
58
+ Object.entries(propertyKey).forEach(([key, value]) => {
59
+ this[key] = value;
60
+ });
61
+ }
62
+ return this;
63
+ }
64
+ setRaw(propertyKey, value) {
65
+ setValue(this.map, propertyKey, value);
66
+ return this;
67
+ }
68
+ /**
69
+ *
70
+ * @param propertyKey
71
+ * @param defaultValue
72
+ * @returns {undefined|any}
73
+ */
74
+ get(propertyKey, defaultValue) {
75
+ return this.resolve(this.getRaw(propertyKey, defaultValue));
76
+ }
77
+ getRaw(propertyKey, defaultValue) {
78
+ const value = getValue(this.map, propertyKey);
79
+ if (value !== undefined) {
80
+ return value;
81
+ }
82
+ return getValue(this.default, propertyKey, defaultValue);
83
+ }
84
+ merge(obj) {
85
+ Object.entries(obj).forEach(([key, value]) => {
86
+ const descriptor = Object.getOwnPropertyDescriptor(DIConfiguration.prototype, key);
87
+ const originalValue = this.get(key);
88
+ value = deepMerge(value, originalValue);
89
+ if (descriptor && !["default", "set", "map", "get"].includes(key)) {
90
+ this[key] = value;
91
+ }
92
+ });
93
+ }
94
+ /**
95
+ *
96
+ * @param value
97
+ * @returns {any}
98
+ */
99
+ resolve(value) {
100
+ if (typeof value === "object" && value !== null) {
101
+ if (![Array, Object].includes(classOf(value))) {
102
+ return value;
103
+ }
104
+ return Object.entries(value).reduce((o, [k, v]) => {
105
+ // @ts-ignore
106
+ o[k] = this.resolve(v);
107
+ return o;
108
+ }, Array.isArray(value) ? [] : {});
109
+ }
110
+ if (typeof value === "string") {
111
+ const replacer = (match, key) => getValue(this.map, key);
112
+ return value
113
+ .replace(/\${([\w.]+)}/gi, replacer)
114
+ .replace(/<([\w.]+)>/gi, replacer)
115
+ .replace(/{{([\w.]+)}}/gi, replacer);
116
+ }
117
+ return value;
118
+ }
119
+ build() {
120
+ this.forEach((value, key) => this.map.set(key, this.resolve(value)));
121
+ this.set = this.setRaw;
122
+ this.get = this.getRaw = (propertyKey, defaultValue) => getValue(this.map, propertyKey, defaultValue);
123
+ }
124
+ }
125
+ //# sourceMappingURL=DIConfiguration.js.map
@@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C,CAAC,EAAE,CAAC,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,QAAQ,CAAC,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,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IACtH,CAAC;CACF","sourcesContent":["import {classOf, deepMerge, getValue, proxyDelegation, setValue} from \"@tsed/core\";\nimport {ProviderScope} from \"../domain\";\nimport type {DIResolver, TokenProvider} from \"../interfaces\";\n\nexport class DIConfiguration {\n readonly default: Map<string, any> = new Map();\n protected map: Map<string, any> = new Map();\n\n [key: string]: any;\n\n constructor(initialProps = {}) {\n Object.entries({\n scopes: {},\n resolvers: [],\n imports: [],\n ...initialProps\n }).forEach(([key, value]) => {\n this.default.set(key, value);\n });\n\n return proxyDelegation<DIConfiguration>(this, {\n ownKeys(target) {\n return [...target.default.keys(), ...target.map.keys()];\n }\n });\n }\n\n get scopes(): {[key: string]: ProviderScope} {\n return this.getRaw(\"scopes\");\n }\n\n set scopes(value: {[key: string]: ProviderScope}) {\n this.setRaw(\"scopes\", value);\n }\n\n get resolvers(): DIResolver[] {\n return this.getRaw(\"resolvers\");\n }\n\n set resolvers(resolvers: DIResolver[]) {\n this.setRaw(\"resolvers\", resolvers);\n }\n\n get imports(): TokenProvider[] {\n return this.getRaw(\"imports\");\n }\n\n set imports(imports: TokenProvider[]) {\n this.setRaw(\"imports\", imports);\n }\n\n /**\n *\n * @param callbackfn\n * @param thisArg\n */\n forEach(callbackfn: (value: any, index: string, map: Map<string, any>) => void, thisArg?: any) {\n return new Set([...Array.from(this.default.keys()), ...Array.from(this.map.keys())]).forEach((key) => {\n callbackfn(this.getRaw(key), key, this.map);\n }, thisArg);\n }\n\n /**\n *\n * @param propertyKey\n * @param value\n */\n set(propertyKey: string | Partial<TsED.Configuration>, value?: any): this {\n if (typeof propertyKey === \"string\") {\n this.setRaw(propertyKey, value);\n } else {\n Object.entries(propertyKey).forEach(([key, value]) => {\n this[key] = value;\n });\n }\n\n return this;\n }\n\n setRaw(propertyKey: string, value: any) {\n setValue(this.map, propertyKey, value);\n\n return this;\n }\n\n /**\n *\n * @param propertyKey\n * @param defaultValue\n * @returns {undefined|any}\n */\n get<T = any>(propertyKey: string, defaultValue?: T): T {\n return this.resolve(this.getRaw(propertyKey, defaultValue));\n }\n\n getRaw(propertyKey: string, defaultValue?: any): any {\n const value = getValue(this.map, propertyKey);\n\n if (value !== undefined) {\n return value;\n }\n\n return getValue(this.default, propertyKey, defaultValue);\n }\n\n merge(obj: Partial<TsED.Configuration>) {\n Object.entries(obj).forEach(([key, value]) => {\n const descriptor = Object.getOwnPropertyDescriptor(DIConfiguration.prototype, key);\n const originalValue = this.get(key);\n value = deepMerge(value, originalValue);\n\n if (descriptor && ![\"default\", \"set\", \"map\", \"get\"].includes(key)) {\n this[key] = value;\n }\n });\n }\n\n /**\n *\n * @param value\n * @returns {any}\n */\n resolve(value: any) {\n if (typeof value === \"object\" && value !== null) {\n if (![Array, Object].includes(classOf(value))) {\n return value;\n }\n\n return Object.entries(value).reduce(\n (o, [k, v]) => {\n // @ts-ignore\n o[k] = this.resolve(v);\n\n return o;\n },\n Array.isArray(value) ? [] : {}\n );\n }\n\n if (typeof value === \"string\") {\n const replacer = (match: string, key: string) => getValue(this.map, key);\n return value\n .replace(/\\${([\\w.]+)}/gi, replacer)\n .replace(/<([\\w.]+)>/gi, replacer)\n .replace(/{{([\\w.]+)}}/gi, replacer);\n }\n\n return value;\n }\n\n build() {\n this.forEach((value, key) => this.map.set(key, this.resolve(value)));\n\n this.set = this.setRaw;\n this.get = this.getRaw = (propertyKey: string, defaultValue?: any) => getValue(this.map, propertyKey, defaultValue);\n }\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { Logger } from "@tsed/logger";
2
+ import { registerProvider } from "../registries/ProviderRegistry";
3
+ import { InjectorService } from "./InjectorService";
4
+ registerProvider({
5
+ provide: Logger,
6
+ deps: [InjectorService],
7
+ useFactory(injector) {
8
+ return injector.logger;
9
+ }
10
+ });
11
+ //# sourceMappingURL=DILogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DILogger.js","sourceRoot":"","sources":["../../../src/services/DILogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,EAAC,gBAAgB,EAAC,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD,gBAAgB,CAAC;IACf,OAAO,EAAE,MAAM;IACf,IAAI,EAAE,CAAC,eAAe,CAAC;IACvB,UAAU,CAAC,QAAyB;QAClC,OAAO,QAAQ,CAAC,MAAM,CAAC;IACzB,CAAC;CACF,CAAC,CAAC","sourcesContent":["import {Logger} from \"@tsed/logger\";\nimport {registerProvider} from \"../registries/ProviderRegistry\";\nimport {InjectorService} from \"./InjectorService\";\n\nregisterProvider({\n provide: Logger,\n deps: [InjectorService],\n useFactory(injector: InjectorService) {\n return injector.logger;\n }\n});\n"]}