@tsed/di 6.88.1 → 6.89.0

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