@tsed/di 7.0.0-alpha.2 → 7.0.0-beta.11

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 (279) hide show
  1. package/lib/cjs/constants/constants.js +7 -0
  2. package/lib/cjs/constants/constants.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/inject.js +104 -0
  10. package/lib/cjs/decorators/inject.js.map +1 -0
  11. package/lib/cjs/decorators/injectable.js +32 -0
  12. package/lib/cjs/decorators/injectable.js.map +1 -0
  13. package/lib/cjs/decorators/intercept.js +36 -0
  14. package/lib/cjs/decorators/intercept.js.map +1 -0
  15. package/lib/cjs/decorators/interceptor.js +21 -0
  16. package/lib/cjs/decorators/interceptor.js.map +1 -0
  17. package/lib/cjs/decorators/lazyInject.js +71 -0
  18. package/lib/cjs/decorators/lazyInject.js.map +1 -0
  19. package/lib/cjs/decorators/module.js +32 -0
  20. package/lib/cjs/decorators/module.js.map +1 -0
  21. package/lib/cjs/decorators/opts.js +54 -0
  22. package/lib/cjs/decorators/opts.js.map +1 -0
  23. package/lib/cjs/decorators/overrideProvider.js +17 -0
  24. package/lib/cjs/decorators/overrideProvider.js.map +1 -0
  25. package/lib/cjs/decorators/scope.js +16 -0
  26. package/lib/cjs/decorators/scope.js.map +1 -0
  27. package/lib/cjs/decorators/service.js +18 -0
  28. package/lib/cjs/decorators/service.js.map +1 -0
  29. package/lib/cjs/decorators/useOpts.js +65 -0
  30. package/lib/cjs/decorators/useOpts.js.map +1 -0
  31. package/lib/cjs/decorators/value.js +55 -0
  32. package/lib/cjs/decorators/value.js.map +1 -0
  33. package/lib/cjs/domain/Container.js +72 -0
  34. package/lib/cjs/domain/Container.js.map +1 -0
  35. package/lib/cjs/domain/ContextLogger.js +85 -0
  36. package/lib/cjs/domain/ContextLogger.js.map +1 -0
  37. package/lib/cjs/domain/DIContext.js +45 -0
  38. package/lib/cjs/domain/DIContext.js.map +1 -0
  39. package/lib/cjs/domain/InjectablePropertyType.js +12 -0
  40. package/lib/cjs/domain/InjectablePropertyType.js.map +1 -0
  41. package/lib/cjs/domain/LocalsContainer.js +55 -0
  42. package/lib/cjs/domain/LocalsContainer.js.map +1 -0
  43. package/lib/cjs/domain/Provider.js +122 -0
  44. package/lib/cjs/domain/Provider.js.map +1 -0
  45. package/lib/cjs/domain/ProviderScope.js +10 -0
  46. package/lib/cjs/domain/ProviderScope.js.map +1 -0
  47. package/lib/cjs/domain/ProviderType.js +15 -0
  48. package/lib/cjs/domain/ProviderType.js.map +1 -0
  49. package/lib/cjs/errors/InjectionError.js +58 -0
  50. package/lib/cjs/errors/InjectionError.js.map +1 -0
  51. package/lib/cjs/errors/UndefinedTokenError.js +11 -0
  52. package/lib/cjs/errors/UndefinedTokenError.js.map +1 -0
  53. package/lib/cjs/index.js +59 -0
  54. package/lib/cjs/index.js.map +1 -0
  55. package/lib/cjs/interfaces/DIConfigurationOptions.js +3 -0
  56. package/lib/cjs/interfaces/DIConfigurationOptions.js.map +1 -0
  57. package/lib/cjs/interfaces/DILogger.js +3 -0
  58. package/lib/cjs/interfaces/DILogger.js.map +1 -0
  59. package/lib/cjs/interfaces/DIResolver.js +3 -0
  60. package/lib/cjs/interfaces/DIResolver.js.map +1 -0
  61. package/lib/cjs/interfaces/InjectableProperties.js +3 -0
  62. package/lib/cjs/interfaces/InjectableProperties.js.map +1 -0
  63. package/lib/cjs/interfaces/InterceptorContext.js +3 -0
  64. package/lib/cjs/interfaces/InterceptorContext.js.map +1 -0
  65. package/lib/cjs/interfaces/InterceptorMethods.js +3 -0
  66. package/lib/cjs/interfaces/InterceptorMethods.js.map +1 -0
  67. package/lib/cjs/interfaces/InvokeOptions.js +3 -0
  68. package/lib/cjs/interfaces/InvokeOptions.js.map +1 -0
  69. package/lib/cjs/interfaces/OnDestroy.js +3 -0
  70. package/lib/cjs/interfaces/OnDestroy.js.map +1 -0
  71. package/lib/cjs/interfaces/OnInit.js +3 -0
  72. package/lib/cjs/interfaces/OnInit.js.map +1 -0
  73. package/lib/cjs/interfaces/ProviderOpts.js +3 -0
  74. package/lib/cjs/interfaces/ProviderOpts.js.map +1 -0
  75. package/lib/cjs/interfaces/RegistrySettings.js +3 -0
  76. package/lib/cjs/interfaces/RegistrySettings.js.map +1 -0
  77. package/lib/cjs/interfaces/ResolvedInvokeOptions.js +3 -0
  78. package/lib/cjs/interfaces/ResolvedInvokeOptions.js.map +1 -0
  79. package/lib/cjs/interfaces/TokenProvider.js +3 -0
  80. package/lib/cjs/interfaces/TokenProvider.js.map +1 -0
  81. package/lib/cjs/interfaces/TokenRoute.js +3 -0
  82. package/lib/cjs/interfaces/TokenRoute.js.map +1 -0
  83. package/lib/cjs/package.json +3 -0
  84. package/lib/cjs/registries/GlobalProviders.js +124 -0
  85. package/lib/cjs/registries/GlobalProviders.js.map +1 -0
  86. package/lib/cjs/registries/ProviderRegistry.js +86 -0
  87. package/lib/cjs/registries/ProviderRegistry.js.map +1 -0
  88. package/lib/cjs/services/DIConfiguration.js +136 -0
  89. package/lib/cjs/services/DIConfiguration.js.map +1 -0
  90. package/lib/cjs/services/DILogger.js +13 -0
  91. package/lib/cjs/services/DILogger.js.map +1 -0
  92. package/lib/cjs/services/DITest.js +116 -0
  93. package/lib/cjs/services/DITest.js.map +1 -0
  94. package/lib/cjs/services/InjectorService.js +589 -0
  95. package/lib/cjs/services/InjectorService.js.map +1 -0
  96. package/lib/cjs/utils/colors.js +10 -0
  97. package/lib/cjs/utils/colors.js.map +1 -0
  98. package/lib/cjs/utils/createContainer.js +14 -0
  99. package/lib/cjs/utils/createContainer.js.map +1 -0
  100. package/lib/cjs/utils/getConfiguration.js +29 -0
  101. package/lib/cjs/utils/getConfiguration.js.map +1 -0
  102. package/lib/cjs/utils/resolveControllers.js +47 -0
  103. package/lib/cjs/utils/resolveControllers.js.map +1 -0
  104. package/lib/cjs/utils/runInContext.js +19 -0
  105. package/lib/cjs/utils/runInContext.js.map +1 -0
  106. package/lib/cjs/utils/setLoggerLevel.js +16 -0
  107. package/lib/cjs/utils/setLoggerLevel.js.map +1 -0
  108. package/lib/esm/constants/constants.js +4 -0
  109. package/lib/esm/constants/constants.js.map +1 -0
  110. package/lib/esm/decorators/configuration.js +20 -0
  111. package/lib/esm/decorators/configuration.js.map +1 -0
  112. package/lib/esm/decorators/constant.js +51 -0
  113. package/lib/esm/decorators/constant.js.map +1 -0
  114. package/lib/esm/decorators/controller.js +49 -0
  115. package/lib/esm/decorators/controller.js.map +1 -0
  116. package/lib/esm/decorators/inject.js +98 -0
  117. package/lib/esm/decorators/inject.js.map +1 -0
  118. package/lib/esm/decorators/injectable.js +28 -0
  119. package/lib/esm/decorators/injectable.js.map +1 -0
  120. package/lib/esm/decorators/intercept.js +32 -0
  121. package/lib/esm/decorators/intercept.js.map +1 -0
  122. package/lib/esm/decorators/interceptor.js +17 -0
  123. package/lib/esm/decorators/interceptor.js.map +1 -0
  124. package/lib/esm/decorators/lazyInject.js +66 -0
  125. package/lib/esm/decorators/lazyInject.js.map +1 -0
  126. package/lib/esm/decorators/module.js +28 -0
  127. package/lib/esm/decorators/module.js.map +1 -0
  128. package/lib/esm/decorators/opts.js +50 -0
  129. package/lib/esm/decorators/opts.js.map +1 -0
  130. package/lib/esm/decorators/overrideProvider.js +13 -0
  131. package/lib/esm/decorators/overrideProvider.js.map +1 -0
  132. package/lib/esm/decorators/scope.js +12 -0
  133. package/lib/esm/decorators/scope.js.map +1 -0
  134. package/lib/esm/decorators/service.js +14 -0
  135. package/lib/esm/decorators/service.js.map +1 -0
  136. package/lib/esm/decorators/useOpts.js +61 -0
  137. package/lib/esm/decorators/useOpts.js.map +1 -0
  138. package/lib/esm/decorators/value.js +51 -0
  139. package/lib/esm/decorators/value.js.map +1 -0
  140. package/lib/esm/domain/Container.js +68 -0
  141. package/lib/esm/domain/Container.js.map +1 -0
  142. package/lib/esm/domain/ContextLogger.js +81 -0
  143. package/lib/esm/domain/ContextLogger.js.map +1 -0
  144. package/lib/esm/domain/DIContext.js +41 -0
  145. package/lib/esm/domain/DIContext.js.map +1 -0
  146. package/lib/esm/domain/InjectablePropertyType.js +9 -0
  147. package/lib/esm/domain/InjectablePropertyType.js.map +1 -0
  148. package/lib/esm/domain/LocalsContainer.js +51 -0
  149. package/lib/esm/domain/LocalsContainer.js.map +1 -0
  150. package/lib/esm/domain/Provider.js +118 -0
  151. package/lib/esm/domain/Provider.js.map +1 -0
  152. package/lib/esm/domain/ProviderScope.js +7 -0
  153. package/lib/esm/domain/ProviderScope.js.map +1 -0
  154. package/lib/esm/domain/ProviderType.js +12 -0
  155. package/lib/esm/domain/ProviderType.js.map +1 -0
  156. package/lib/esm/errors/InjectionError.js +54 -0
  157. package/lib/esm/errors/InjectionError.js.map +1 -0
  158. package/lib/esm/errors/UndefinedTokenError.js +7 -0
  159. package/lib/esm/errors/UndefinedTokenError.js.map +1 -0
  160. package/lib/esm/index.js +56 -0
  161. package/lib/esm/index.js.map +1 -0
  162. package/lib/esm/interfaces/DIConfigurationOptions.js +2 -0
  163. package/lib/esm/interfaces/DIConfigurationOptions.js.map +1 -0
  164. package/lib/esm/interfaces/DILogger.js +2 -0
  165. package/lib/esm/interfaces/DILogger.js.map +1 -0
  166. package/lib/esm/interfaces/DIResolver.js +2 -0
  167. package/lib/esm/interfaces/DIResolver.js.map +1 -0
  168. package/lib/esm/interfaces/InjectableProperties.js +2 -0
  169. package/lib/esm/interfaces/InjectableProperties.js.map +1 -0
  170. package/lib/esm/interfaces/InterceptorContext.js +2 -0
  171. package/lib/esm/interfaces/InterceptorContext.js.map +1 -0
  172. package/lib/esm/interfaces/InterceptorMethods.js +2 -0
  173. package/lib/esm/interfaces/InterceptorMethods.js.map +1 -0
  174. package/lib/esm/interfaces/InvokeOptions.js +2 -0
  175. package/lib/esm/interfaces/InvokeOptions.js.map +1 -0
  176. package/lib/esm/interfaces/OnDestroy.js +2 -0
  177. package/lib/esm/interfaces/OnDestroy.js.map +1 -0
  178. package/lib/esm/interfaces/OnInit.js +2 -0
  179. package/lib/esm/interfaces/OnInit.js.map +1 -0
  180. package/lib/esm/interfaces/ProviderOpts.js +2 -0
  181. package/lib/esm/interfaces/ProviderOpts.js.map +1 -0
  182. package/lib/esm/interfaces/RegistrySettings.js +2 -0
  183. package/lib/esm/interfaces/RegistrySettings.js.map +1 -0
  184. package/lib/esm/interfaces/ResolvedInvokeOptions.js +2 -0
  185. package/lib/esm/interfaces/ResolvedInvokeOptions.js.map +1 -0
  186. package/lib/esm/interfaces/TokenProvider.js +2 -0
  187. package/lib/esm/interfaces/TokenProvider.js.map +1 -0
  188. package/lib/esm/interfaces/TokenRoute.js +2 -0
  189. package/lib/esm/interfaces/TokenRoute.js.map +1 -0
  190. package/lib/esm/package.json +3 -0
  191. package/lib/esm/registries/GlobalProviders.js +120 -0
  192. package/lib/esm/registries/GlobalProviders.js.map +1 -0
  193. package/lib/esm/registries/ProviderRegistry.js +81 -0
  194. package/lib/esm/registries/ProviderRegistry.js.map +1 -0
  195. package/lib/esm/services/DIConfiguration.js +132 -0
  196. package/lib/esm/services/DIConfiguration.js.map +1 -0
  197. package/lib/esm/services/DILogger.js +11 -0
  198. package/lib/esm/services/DILogger.js.map +1 -0
  199. package/lib/esm/services/DITest.js +112 -0
  200. package/lib/esm/services/DITest.js.map +1 -0
  201. package/lib/esm/services/InjectorService.js +586 -0
  202. package/lib/esm/services/InjectorService.js.map +1 -0
  203. package/lib/esm/utils/colors.js +7 -0
  204. package/lib/esm/utils/colors.js.map +1 -0
  205. package/lib/esm/utils/createContainer.js +10 -0
  206. package/lib/esm/utils/createContainer.js.map +1 -0
  207. package/lib/esm/utils/getConfiguration.js +24 -0
  208. package/lib/esm/utils/getConfiguration.js.map +1 -0
  209. package/lib/esm/utils/resolveControllers.js +42 -0
  210. package/lib/esm/utils/resolveControllers.js.map +1 -0
  211. package/lib/esm/utils/runInContext.js +13 -0
  212. package/lib/esm/utils/runInContext.js.map +1 -0
  213. package/lib/esm/utils/setLoggerLevel.js +12 -0
  214. package/lib/esm/utils/setLoggerLevel.js.map +1 -0
  215. package/lib/{constants/index.d.ts → types/constants/constants.d.ts} +0 -0
  216. package/lib/{decorators → types/decorators}/configuration.d.ts +0 -0
  217. package/lib/{decorators → types/decorators}/constant.d.ts +0 -0
  218. package/lib/{decorators → types/decorators}/controller.d.ts +2 -2
  219. package/lib/types/decorators/inject.d.ts +36 -0
  220. package/lib/{decorators → types/decorators}/injectable.d.ts +4 -5
  221. package/lib/{decorators → types/decorators}/intercept.d.ts +2 -2
  222. package/lib/{decorators → types/decorators}/interceptor.d.ts +0 -0
  223. package/lib/types/decorators/lazyInject.d.ts +43 -0
  224. package/lib/{decorators → types/decorators}/module.d.ts +3 -2
  225. package/lib/{decorators → types/decorators}/opts.d.ts +0 -0
  226. package/lib/{decorators → types/decorators}/overrideProvider.d.ts +0 -0
  227. package/lib/{decorators → types/decorators}/scope.d.ts +0 -0
  228. package/lib/{decorators → types/decorators}/service.d.ts +0 -0
  229. package/lib/{decorators → types/decorators}/useOpts.d.ts +0 -0
  230. package/lib/{decorators → types/decorators}/value.d.ts +0 -0
  231. package/lib/{domain → types/domain}/Container.d.ts +5 -6
  232. package/lib/{domain → types/domain}/ContextLogger.d.ts +0 -0
  233. package/lib/{domain → types/domain}/DIContext.d.ts +0 -6
  234. package/lib/{domain → types/domain}/InjectablePropertyType.d.ts +0 -0
  235. package/lib/{domain → types/domain}/LocalsContainer.d.ts +0 -0
  236. package/lib/{domain → types/domain}/Provider.d.ts +17 -3
  237. package/lib/{domain → types/domain}/ProviderScope.d.ts +0 -0
  238. package/lib/{domain → types/domain}/ProviderType.d.ts +0 -0
  239. package/lib/{errors → types/errors}/InjectionError.d.ts +1 -1
  240. package/lib/{errors → types/errors}/UndefinedTokenError.d.ts +0 -0
  241. package/lib/types/index.d.ts +55 -0
  242. package/lib/{interfaces → types/interfaces}/DIConfigurationOptions.d.ts +4 -0
  243. package/lib/{interfaces → types/interfaces}/DILogger.d.ts +0 -0
  244. package/lib/{interfaces → types/interfaces}/DIResolver.d.ts +0 -0
  245. package/lib/{interfaces → types/interfaces}/InjectableProperties.d.ts +8 -4
  246. package/lib/{interfaces → types/interfaces}/InterceptorContext.d.ts +0 -0
  247. package/lib/{interfaces → types/interfaces}/InterceptorMethods.d.ts +0 -0
  248. package/lib/{interfaces → types/interfaces}/InvokeOptions.d.ts +0 -0
  249. package/lib/{interfaces → types/interfaces}/OnDestroy.d.ts +0 -0
  250. package/lib/{interfaces → types/interfaces}/OnInit.d.ts +0 -0
  251. package/lib/{interfaces/IProvider.d.ts → types/interfaces/ProviderOpts.d.ts} +5 -4
  252. package/lib/{interfaces → types/interfaces}/RegistrySettings.d.ts +7 -3
  253. package/lib/types/interfaces/ResolvedInvokeOptions.d.ts +12 -0
  254. package/lib/{interfaces → types/interfaces}/TokenProvider.d.ts +0 -0
  255. package/lib/types/interfaces/TokenRoute.d.ts +5 -0
  256. package/lib/{registries → types/registries}/GlobalProviders.d.ts +11 -5
  257. package/lib/{registries → types/registries}/ProviderRegistry.d.ts +4 -4
  258. package/lib/{services → types/services}/DIConfiguration.d.ts +6 -2
  259. package/lib/{services → types/services}/DILogger.d.ts +0 -0
  260. package/lib/{services → types/services}/DITest.d.ts +7 -1
  261. package/lib/{services → types/services}/InjectorService.d.ts +45 -22
  262. package/lib/types/utils/colors.d.ts +5 -0
  263. package/lib/{utils → types/utils}/createContainer.d.ts +0 -0
  264. package/lib/{utils → types/utils}/getConfiguration.d.ts +1 -0
  265. package/lib/types/utils/resolveControllers.d.ts +12 -0
  266. package/lib/types/utils/runInContext.d.ts +6 -0
  267. package/lib/{utils → types/utils}/setLoggerLevel.d.ts +0 -0
  268. package/package.json +32 -16
  269. package/readme.md +37 -41
  270. package/tsconfig.compile.esm.json +25 -0
  271. package/lib/decorators/index.d.ts +0 -14
  272. package/lib/decorators/inject.d.ts +0 -19
  273. package/lib/domain/index.d.ts +0 -8
  274. package/lib/index.d.ts +0 -16
  275. package/lib/index.js +0 -2269
  276. package/lib/index.js.map +0 -1
  277. package/lib/index.modern.js +0 -2232
  278. package/lib/index.modern.js.map +0 -1
  279. package/lib/interfaces/index.d.ts +0 -13
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../../src/decorators/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,aAAa,EAAC,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AA2BpD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,MAAM,CAAC,UAAkC,EAAE;IACzD,MAAM,EAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,aAAa,EAAC,GAAG,OAAO,CAAC;IAE5E,OAAO,aAAa,CAClB,aAAa,CAAC,aAAa,CAAC,EAC5B,UAAU,CAAC;QACT,IAAI,EAAE,YAAY,CAAC,MAAM;QACzB,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,OAAO;QACP,IAAI;QACJ,UAAU,EAAE,KAAK;QACjB,SAAS;KACV,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import {useDecorators} from \"@tsed/core\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {Configuration} from \"./configuration\";\nimport {Injectable} from \"./injectable\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport {DIResolver} from \"../interfaces/DIResolver\";\n\nexport interface ModuleOptions extends Omit<TsED.Configuration, \"scopes\"> {\n /**\n * Provider scope\n */\n scope?: ProviderScope;\n /**\n * Providers must be initialized before building this module\n */\n imports?: TokenProvider[];\n /**\n * Explicit token must be injected in the constructor\n */\n deps?: TokenProvider[];\n /**\n * A list of resolvers to inject provider from external DI.\n */\n resolvers?: DIResolver[];\n\n /**\n * Additional properties are stored as provider configuration.\n */\n [key: string]: any;\n}\n\n/**\n * Declare a new Ts.ED module\n *\n * ## Options\n * - imports: List of Provider which must be built by injector before invoking the module\n * - resolvers: List of external DI must be used to resolve unknown provider\n * - deps: List of provider must be injected to the module constructor (explicit declaration)\n *\n * @param options\n * @decorator\n */\nexport function Module(options: Partial<ModuleOptions> = {}) {\n const {scopes, imports, resolvers, deps, scope, ...configuration} = options;\n\n return useDecorators(\n Configuration(configuration),\n Injectable({\n type: ProviderType.MODULE,\n scope: ProviderScope.SINGLETON,\n imports,\n deps,\n injectable: false,\n resolvers\n })\n );\n}\n"]}
@@ -0,0 +1,50 @@
1
+ import { classOf } from "@tsed/core";
2
+ import { DI_PARAM_OPTIONS } from "../constants/constants.js";
3
+ import { ProviderScope } from "../domain/ProviderScope.js";
4
+ import { Inject } from "./inject.js";
5
+ import { Scope } from "./scope.js";
6
+ /**
7
+ * Get instance options. This options depending on his invocation context.
8
+ *
9
+ * ```typescript
10
+ * import {Injectable, Opts, UseOpts} from "@tsed/di";
11
+ *
12
+ * @Injectable()
13
+ * class MyConfigurableService {
14
+ * source: string;
15
+ * constructor(@Opts options: any = {}) {
16
+ * console.log("Hello ", options.source); // log: Hello Service1 then Hello Service2
17
+ *
18
+ * this.source = options.source;
19
+ * }
20
+ * }
21
+ *
22
+ * @Injectable()
23
+ * class MyService1 {
24
+ * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {
25
+ * console.log(service.source) // log: Service1
26
+ * }
27
+ * }
28
+ *
29
+ * @Injectable()
30
+ * class MyService2 {
31
+ * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {
32
+ * console.log(service.source) // log: Service2
33
+ * }
34
+ * }
35
+ * ```
36
+ *
37
+ * ::: warning
38
+ * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.
39
+ * :::
40
+ *
41
+ * @param target
42
+ * @param propertyKey
43
+ * @param index
44
+ * @decorator
45
+ */
46
+ export function Opts(target, propertyKey, index) {
47
+ Scope(ProviderScope.INSTANCE)(classOf(target));
48
+ Inject(DI_PARAM_OPTIONS)(target, propertyKey, index);
49
+ }
50
+ //# sourceMappingURL=opts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opts.js","sourceRoot":"","sources":["../../../src/decorators/opts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AACnC,OAAO,EAAC,gBAAgB,EAAC,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAC,aAAa,EAAC,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,IAAI,CAAC,MAAW,EAAE,WAA4B,EAAE,KAAa;IAC3E,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/C,MAAM,CAAC,gBAAgB,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import {classOf} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS} from \"../constants/constants\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\nimport {Inject} from \"./inject\";\nimport {Scope} from \"./scope\";\n\n/**\n * Get instance options. This options depending on his invocation context.\n *\n * ```typescript\n * import {Injectable, Opts, UseOpts} from \"@tsed/di\";\n *\n * @Injectable()\n * class MyConfigurableService {\n * source: string;\n * constructor(@Opts options: any = {}) {\n * console.log(\"Hello \", options.source); // log: Hello Service1 then Hello Service2\n *\n * this.source = options.source;\n * }\n * }\n *\n * @Injectable()\n * class MyService1 {\n * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service1\n * }\n * }\n *\n * @Injectable()\n * class MyService2 {\n * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service2\n * }\n * }\n * ```\n *\n * ::: warning\n * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.\n * :::\n *\n * @param target\n * @param propertyKey\n * @param index\n * @decorator\n */\nexport function Opts(target: any, propertyKey: string | symbol, index: number) {\n Scope(ProviderScope.INSTANCE)(classOf(target));\n Inject(DI_PARAM_OPTIONS)(target, propertyKey, index);\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { GlobalProviders } from "../registries/GlobalProviders.js";
2
+ /**
3
+ * Override a provider which is already registered in ProviderRegistry.
4
+ * @returns {Function}
5
+ * @decorators
6
+ * @param originalProvider
7
+ */
8
+ export function OverrideProvider(originalProvider) {
9
+ return (target) => {
10
+ GlobalProviders.get(originalProvider).useClass = target;
11
+ };
12
+ }
13
+ //# sourceMappingURL=overrideProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overrideProvider.js","sourceRoot":"","sources":["../../../src/decorators/overrideProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,gBAA2B;IAC1D,OAAO,CAAC,MAAiB,EAAQ,EAAE;QACjC,eAAe,CAAC,GAAG,CAAC,gBAAgB,CAAE,CAAC,QAAQ,GAAG,MAAM,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\n\n/**\n * Override a provider which is already registered in ProviderRegistry.\n * @returns {Function}\n * @decorators\n * @param originalProvider\n */\nexport function OverrideProvider(originalProvider: Type<any>): Function {\n return (target: Type<any>): void => {\n GlobalProviders.get(originalProvider)!.useClass = target;\n };\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import { StoreSet } from "@tsed/core";
2
+ import { ProviderScope } from "../domain/ProviderScope.js";
3
+ /**
4
+ *
5
+ * @param {"request" | "singleton" | ProviderScope} scope
6
+ * @returns {Function}
7
+ * @constructor
8
+ */
9
+ export function Scope(scope = ProviderScope.REQUEST) {
10
+ return StoreSet("scope", scope);
11
+ }
12
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../src/decorators/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,aAAa,EAAC,MAAM,yBAAyB,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,QAAiD,aAAa,CAAC,OAAO;IAC1F,OAAO,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAClC,CAAC","sourcesContent":["import {StoreSet} from \"@tsed/core\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\n\n/**\n *\n * @param {\"request\" | \"singleton\" | ProviderScope} scope\n * @returns {Function}\n * @constructor\n */\nexport function Scope(scope: \"request\" | \"singleton\" | ProviderScope = ProviderScope.REQUEST) {\n return StoreSet(\"scope\", scope);\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import { Injectable } from "./injectable.js";
2
+ /**
3
+ * The decorators `@Service()` declare a new service can be injected in other service or controller on there `constructor`.
4
+ * All services annotated with `@Service()` are constructed one time.
5
+ *
6
+ * > `@Service()` use the `reflect-metadata` to collect and inject service on controllers or other services.
7
+ *
8
+ * @returns {Function}
9
+ * @decorator
10
+ */
11
+ export function Service() {
12
+ return Injectable();
13
+ }
14
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/decorators/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAExC;;;;;;;;GAQG;AACH,MAAM,UAAU,OAAO;IACrB,OAAO,UAAU,EAAE,CAAC;AACtB,CAAC","sourcesContent":["import {Injectable} from \"./injectable\";\n\n/**\n * The decorators `@Service()` declare a new service can be injected in other service or controller on there `constructor`.\n * All services annotated with `@Service()` are constructed one time.\n *\n * > `@Service()` use the `reflect-metadata` to collect and inject service on controllers or other services.\n *\n * @returns {Function}\n * @decorator\n */\nexport function Service(): Function {\n return Injectable();\n}\n"]}
@@ -0,0 +1,61 @@
1
+ import { decoratorTypeOf, DecoratorTypes, Store, UnsupportedDecoratorType } from "@tsed/core";
2
+ import { DI_PARAM_OPTIONS, INJECTABLE_PROP } from "../constants/constants.js";
3
+ /**
4
+ * Add options to invoke the Service.
5
+ *
6
+ * ```typescript
7
+ * import {Injectable, Opts, UseOpts} from "@tsed/di";
8
+ *
9
+ * @Injectable()
10
+ * class MyConfigurableService {
11
+ * source: string;
12
+ * constructor(@Opts options: any = {}) {
13
+ * console.log("Hello ", options.source); // log: Hello Service1 then Hello Service2
14
+ *
15
+ * this.source = options.source;
16
+ * }
17
+ * }
18
+ *
19
+ * @Injectable()
20
+ * class MyService1 {
21
+ * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {
22
+ * console.log(service.source) // log: Service1
23
+ * }
24
+ * }
25
+ *
26
+ * @Injectable()
27
+ * class MyService2 {
28
+ * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {
29
+ * console.log(service.source) // log: Service2
30
+ * }
31
+ * }
32
+ * ```
33
+ *
34
+ * ::: warning
35
+ * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.
36
+ * :::
37
+ *
38
+ * @returns {Function}
39
+ * @decorator
40
+ * @param options
41
+ */
42
+ export function UseOpts(options) {
43
+ return (target, propertyKey, index) => {
44
+ const bindingType = decoratorTypeOf([target, propertyKey, index]);
45
+ switch (bindingType) {
46
+ case DecoratorTypes.PARAM_CTOR:
47
+ Store.from(target).merge(`${DI_PARAM_OPTIONS}:${index}`, options);
48
+ break;
49
+ case DecoratorTypes.PROP:
50
+ Store.from(target).merge(INJECTABLE_PROP, {
51
+ [propertyKey]: {
52
+ options
53
+ }
54
+ });
55
+ break;
56
+ default:
57
+ throw new UnsupportedDecoratorType(UseOpts, [target, propertyKey, index]);
58
+ }
59
+ };
60
+ }
61
+ //# sourceMappingURL=useOpts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOpts.js","sourceRoot":"","sources":["../../../src/decorators/useOpts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAE,KAAK,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAC,gBAAgB,EAAE,eAAe,EAAC,MAAM,wBAAwB,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,UAAU,OAAO,CAAC,OAA6B;IACnD,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,KAAc,EAAO,EAAE;QAC3E,MAAM,WAAW,GAAG,eAAe,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;QAElE,QAAQ,WAAW,EAAE;YACnB,KAAK,cAAc,CAAC,UAAU;gBAC5B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,gBAAgB,IAAI,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;gBAClE,MAAM;YAER,KAAK,cAAc,CAAC,IAAI;gBACtB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,eAAe,EAAE;oBACxC,CAAC,WAAqB,CAAC,EAAE;wBACvB,OAAO;qBACR;iBACF,CAAC,CAAC;gBACH,MAAM;YAER;gBACE,MAAM,IAAI,wBAAwB,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;SAC7E;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants/constants\";\n\n/**\n * Add options to invoke the Service.\n *\n * ```typescript\n * import {Injectable, Opts, UseOpts} from \"@tsed/di\";\n *\n * @Injectable()\n * class MyConfigurableService {\n * source: string;\n * constructor(@Opts options: any = {}) {\n * console.log(\"Hello \", options.source); // log: Hello Service1 then Hello Service2\n *\n * this.source = options.source;\n * }\n * }\n *\n * @Injectable()\n * class MyService1 {\n * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service1\n * }\n * }\n *\n * @Injectable()\n * class MyService2 {\n * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service2\n * }\n * }\n * ```\n *\n * ::: warning\n * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.\n * :::\n *\n * @returns {Function}\n * @decorator\n * @param options\n */\nexport function UseOpts(options: {[key: string]: any}): Function {\n return (target: Object, propertyKey: string | symbol, index?: number): any => {\n const bindingType = decoratorTypeOf([target, propertyKey, index]);\n\n switch (bindingType) {\n case DecoratorTypes.PARAM_CTOR:\n Store.from(target).merge(`${DI_PARAM_OPTIONS}:${index}`, options);\n break;\n\n case DecoratorTypes.PROP:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey as string]: {\n options\n }\n });\n break;\n\n default:\n throw new UnsupportedDecoratorType(UseOpts, [target, propertyKey, index]);\n }\n };\n}\n"]}
@@ -0,0 +1,51 @@
1
+ import { Store } from "@tsed/core";
2
+ import { INJECTABLE_PROP } from "../constants/constants.js";
3
+ import { InjectablePropertyType } from "../domain/InjectablePropertyType.js";
4
+ /**
5
+ * Return value from Configuration.
6
+ *
7
+ * ## Example
8
+ *
9
+ * ```typescript
10
+ * import {Env} from "@tsed/core";
11
+ * import {Constant, Value} from "@tsed/di";
12
+ *
13
+ * export class MyClass {
14
+ *
15
+ * @Constant("env")
16
+ * env: Env;
17
+ *
18
+ * @Value("swagger.path")
19
+ * swaggerPath: string;
20
+ *
21
+ * @Value("swagger.path", "defaultValue")
22
+ * swaggerPath: string;
23
+ *
24
+ * constructor() {
25
+ * console.log(this.swaggerPath) // undefined. Not available on constructor
26
+ * }
27
+ *
28
+ * $onInit() {
29
+ * console.log(this.swaggerPath) // something
30
+ * }
31
+ * }
32
+ * ```
33
+ *
34
+ * @param expression
35
+ * @param defaultValue
36
+ * @returns {(targetClass: any, attributeName: string) => any}
37
+ * @decorator
38
+ */
39
+ export function Value(expression, defaultValue) {
40
+ return (target, propertyKey) => {
41
+ Store.from(target).merge(INJECTABLE_PROP, {
42
+ [propertyKey]: {
43
+ bindingType: InjectablePropertyType.VALUE,
44
+ propertyKey,
45
+ expression,
46
+ defaultValue
47
+ }
48
+ });
49
+ };
50
+ }
51
+ //# sourceMappingURL=value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value.js","sourceRoot":"","sources":["../../../src/decorators/value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AACjC,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAC,sBAAsB,EAAC,MAAM,kCAAkC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,KAAK,CAAC,UAAe,EAAE,YAAkB;IACvD,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,eAAe,EAAE;YACxC,CAAC,WAAW,CAAC,EAAE;gBACb,WAAW,EAAE,sBAAsB,CAAC,KAAK;gBACzC,WAAW;gBACX,UAAU;gBACV,YAAY;aACb;SACsB,CAAC,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants/constants\";\nimport type {InjectableProperties} from \"../interfaces/InjectableProperties\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\n\n/**\n * Return value from Configuration.\n *\n * ## Example\n *\n * ```typescript\n * import {Env} from \"@tsed/core\";\n * import {Constant, Value} from \"@tsed/di\";\n *\n * export class MyClass {\n *\n * @Constant(\"env\")\n * env: Env;\n *\n * @Value(\"swagger.path\")\n * swaggerPath: string;\n *\n * @Value(\"swagger.path\", \"defaultValue\")\n * swaggerPath: string;\n *\n * constructor() {\n * console.log(this.swaggerPath) // undefined. Not available on constructor\n * }\n *\n * $onInit() {\n * console.log(this.swaggerPath) // something\n * }\n * }\n * ```\n *\n * @param expression\n * @param defaultValue\n * @returns {(targetClass: any, attributeName: string) => any}\n * @decorator\n */\nexport function Value(expression: any, defaultValue?: any) {\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: InjectablePropertyType.VALUE,\n propertyKey,\n expression,\n defaultValue\n }\n } as InjectableProperties);\n };\n}\n"]}
@@ -0,0 +1,68 @@
1
+ import { GlobalProviders } from "../registries/GlobalProviders.js";
2
+ import { Provider } from "./Provider.js";
3
+ export class Container extends Map {
4
+ /**
5
+ *
6
+ * @param token
7
+ * @param settings
8
+ */
9
+ add(token, settings = {}) {
10
+ var _a;
11
+ const provider = ((_a = GlobalProviders.get(token)) === null || _a === void 0 ? void 0 : _a.clone()) || new Provider(token);
12
+ Object.assign(provider, settings);
13
+ return super.set(token, provider);
14
+ }
15
+ /**
16
+ * Add a provider to the
17
+ * @param token
18
+ * @param settings
19
+ */
20
+ addProvider(token, settings = {}) {
21
+ return this.add(token, settings);
22
+ }
23
+ /**
24
+ *
25
+ * @param token
26
+ */
27
+ hasProvider(token) {
28
+ return super.has(token);
29
+ }
30
+ /**
31
+ * Add a provider to the
32
+ * @param token
33
+ * @param provider
34
+ */
35
+ setProvider(token, provider) {
36
+ return super.set(token, provider);
37
+ }
38
+ /**
39
+ * The getProvider() method returns a specified element from a Map object.
40
+ * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.
41
+ * @param token
42
+ */
43
+ getProvider(token) {
44
+ return super.get(token);
45
+ }
46
+ /**
47
+ * Get all providers registered in the injector container.
48
+ *
49
+ * @param {ProviderType} type Filter the list by the given ProviderType.
50
+ * @returns {[TokenProvider , Provider<any>][]}
51
+ */
52
+ getProviders(type) {
53
+ return [...this].reduce((providers, [_, provider]) => {
54
+ if (provider.type === type || !type) {
55
+ return [...providers, provider];
56
+ }
57
+ return providers;
58
+ }, []);
59
+ }
60
+ addProviders(container) {
61
+ container.forEach((provider) => {
62
+ if (!this.hasProvider(provider.provide)) {
63
+ this.setProvider(provider.provide, provider.clone());
64
+ }
65
+ });
66
+ }
67
+ }
68
+ //# sourceMappingURL=Container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Container.js","sourceRoot":"","sources":["../../../src/domain/Container.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,MAAM,OAAO,SAAU,SAAQ,GAA4B;IACzD;;;;OAIG;IACI,GAAG,CAAC,KAAoB,EAAE,WAAkC,EAAE;;QACnE,MAAM,QAAQ,GAAG,CAAA,MAAA,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,0CAAE,KAAK,EAAE,KAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC;QAE5E,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CA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Opts} from \"../interfaces/ProviderOpts\";\nimport type {ProviderType} from \"./ProviderType\";\nimport type {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {Provider} from \"./Provider\";\n\nexport class Container extends Map<TokenProvider, Provider> {\n /**\n *\n * @param token\n * @param settings\n */\n public add(token: TokenProvider, settings: Partial<ProviderOpts> = {}): this {\n const provider = GlobalProviders.get(token)?.clone() || new Provider(token);\n\n Object.assign(provider, settings);\n\n return super.set(token, provider);\n }\n\n /**\n * Add a provider to the\n * @param token\n * @param settings\n */\n public addProvider(token: TokenProvider, settings: Partial<ProviderOpts> = {}): this {\n return this.add(token, settings);\n }\n\n /**\n *\n * @param token\n */\n public hasProvider(token: TokenProvider) {\n return super.has(token);\n }\n\n /**\n * Add a provider to the\n * @param token\n * @param provider\n */\n public setProvider(token: TokenProvider, provider: Provider) {\n return super.set(token, provider);\n }\n\n /**\n * The getProvider() method returns a specified element from a Map object.\n * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.\n * @param token\n */\n public getProvider<T extends Provider = Provider>(token: TokenProvider): T | undefined {\n return super.get(token) as T;\n }\n\n /**\n * Get all providers registered in the injector container.\n *\n * @param {ProviderType} type Filter the list by the given ProviderType.\n * @returns {[TokenProvider , Provider<any>][]}\n */\n public getProviders(type?: ProviderType | string): Provider[] {\n return [...this].reduce((providers, [_, provider]) => {\n if (provider.type === type || !type) {\n return [...providers, provider];\n }\n return providers;\n }, []);\n }\n\n public addProviders(container: Map<TokenProvider, Provider>) {\n container.forEach((provider) => {\n if (!this.hasProvider(provider.provide)) {\n this.setProvider(provider.provide, provider.clone());\n }\n });\n }\n}\n"]}
@@ -0,0 +1,81 @@
1
+ import { levels } from "@tsed/logger";
2
+ export class ContextLogger {
3
+ constructor(logger, { id, url = "", dateStart = new Date(), ignoreUrlPatterns = [], minimalRequestPicker, completeRequestPicker, level = "all", maxStackSize = 30, ignoreLog, additionalProps }) {
4
+ this.logger = logger;
5
+ this.stack = [];
6
+ this.id = id;
7
+ this.url = url;
8
+ this.additionalProps = additionalProps || {};
9
+ this.dateStart = dateStart;
10
+ this.ignoreLog = ignoreLog || (() => false);
11
+ this.minimalRequestPicker = minimalRequestPicker || ((l) => l);
12
+ this.completeRequestPicker = completeRequestPicker || ((l) => l);
13
+ // @ts-ignore
14
+ this.level = levels()[level.toUpperCase()] || levels().ALL;
15
+ this.maxStackSize = maxStackSize;
16
+ }
17
+ info(obj) {
18
+ this.run(levels().INFO, obj, (obj) => this.minimalRequestPicker(this.getData(obj)));
19
+ return this;
20
+ }
21
+ debug(obj, withRequest = true) {
22
+ this.run(levels().DEBUG, obj, (obj) => {
23
+ obj = this.getData(obj);
24
+ return withRequest ? this.completeRequestPicker(obj) : obj;
25
+ });
26
+ return this;
27
+ }
28
+ warn(obj) {
29
+ this.run(levels().WARN, obj, (obj) => this.completeRequestPicker(this.getData(obj)));
30
+ return this;
31
+ }
32
+ error(obj) {
33
+ this.run(levels().ERROR, obj, (obj) => this.completeRequestPicker(this.getData(obj)));
34
+ return this;
35
+ }
36
+ trace(obj) {
37
+ this.run(levels().TRACE, obj, (obj) => this.completeRequestPicker(this.getData(obj)));
38
+ return this;
39
+ }
40
+ flush() {
41
+ if (this.stack.length) {
42
+ this.stack.forEach(({ level, data }) => {
43
+ this.logger[level](data);
44
+ });
45
+ this.stack = [];
46
+ }
47
+ }
48
+ isLevelEnabled(otherLevel) {
49
+ return this.level.isLessThanOrEqualTo(otherLevel);
50
+ }
51
+ destroy() {
52
+ this.flush();
53
+ this.logger = undefined;
54
+ this.stack = undefined;
55
+ }
56
+ /**
57
+ * Return the duration between the time when LogIncomingRequest has handle the request and now.
58
+ * @returns {number}
59
+ */
60
+ getDuration() {
61
+ return new Date().getTime() - this.dateStart.getTime();
62
+ }
63
+ getData(obj) {
64
+ if (typeof obj === "string") {
65
+ obj = { message: obj };
66
+ }
67
+ return { ...this.additionalProps, reqId: this.id, time: new Date(), duration: this.getDuration(), ...obj };
68
+ }
69
+ run(level, obj, mapper) {
70
+ if (!this.isLevelEnabled(level)) {
71
+ return;
72
+ }
73
+ if (!this.ignoreLog(obj)) {
74
+ this.stack.push({ level: level.levelStr.toLowerCase(), data: mapper(obj) });
75
+ }
76
+ if (this.maxStackSize < this.stack.length) {
77
+ this.flush();
78
+ }
79
+ }
80
+ }
81
+ //# sourceMappingURL=ContextLogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextLogger.js","sourceRoot":"","sources":["../../../src/domain/ContextLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAW,MAAM,cAAc,CAAC;AAc9C,MAAM,OAAO,aAAa;IAYxB,YACU,MAAW,EACnB,EACE,EAAE,EACF,GAAG,GAAG,EAAE,EACR,SAAS,GAAG,IAAI,IAAI,EAAE,EACtB,iBAAiB,GAAG,EAAE,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,GAAG,KAAK,EACb,YAAY,GAAG,EAAE,EACjB,SAAS,EACT,eAAe,EACM;QAZf,WAAM,GAAN,MAAM,CAAK;QAJb,UAAK,GAAQ,EAAE,CAAC;QAkBtB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,eAAe,GAAG,eAAe,IAAI,EAAE,CAAC;QAC7C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QACpE,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QACtE,aAAa;QACb,IAAI,CAAC,KAAK,GAAG,MAAM,EAAE,C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IAES,GAAG,CAAC,KAAe,EAAE,GAAQ,EAAE,MAA0B;QACjE,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;YAC/B,OAAO;SACR;QAED,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;YACxB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,EAAC,CAAC,CAAC;SAC3E;QAED,IAAI,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YACzC,IAAI,CAAC,KAAK,EAAE,CAAC;SACd;IACH,CAAC;CACF","sourcesContent":["import {levels, LogLevel} from \"@tsed/logger\";\n\nexport interface ContextLoggerOptions extends Record<string, any> {\n id: string;\n url?: string;\n dateStart?: Date;\n level?: \"debug\" | \"info\" | \"warn\" | \"error\" | \"off\" | \"all\";\n maxStackSize?: number;\n minimalRequestPicker?: (o: any) => any;\n completeRequestPicker?: (o: any) => any;\n ignoreLog?: (data: any) => boolean;\n additionalProps?: Record<any, any>;\n}\n\nexport class ContextLogger {\n id: string;\n url: string;\n minimalRequestPicker: Function;\n completeRequestPicker: Function;\n maxStackSize: number;\n private readonly additionalProps: Record<string, unknown>;\n private readonly dateStart: Date;\n private readonly ignoreLog: (data: any) => boolean;\n private stack: any = [];\n private level: LogLevel;\n\n constructor(\n private logger: any,\n {\n id,\n url = \"\",\n dateStart = new Date(),\n ignoreUrlPatterns = [],\n minimalRequestPicker,\n completeRequestPicker,\n level = \"all\",\n maxStackSize = 30,\n ignoreLog,\n additionalProps\n }: ContextLoggerOptions\n ) {\n this.id = id;\n this.url = url;\n this.additionalProps = additionalProps || {};\n this.dateStart = dateStart;\n this.ignoreLog = ignoreLog || (() => false);\n this.minimalRequestPicker = minimalRequestPicker || ((l: any) => l);\n this.completeRequestPicker = completeRequestPicker || ((l: any) => l);\n // @ts-ignore\n this.level = levels()[level.toUpperCase()] || levels().ALL;\n this.maxStackSize = maxStackSize;\n }\n\n info(obj: any) {\n this.run(levels().INFO, obj, (obj) => this.minimalRequestPicker(this.getData(obj)));\n return this;\n }\n\n debug(obj: any, withRequest: boolean = true) {\n this.run(levels().DEBUG, obj, (obj) => {\n obj = this.getData(obj);\n return withRequest ? this.completeRequestPicker(obj) : obj;\n });\n return this;\n }\n\n warn(obj: any) {\n this.run(levels().WARN, obj, (obj) => this.completeRequestPicker(this.getData(obj)));\n return this;\n }\n\n error(obj: any) {\n this.run(levels().ERROR, obj, (obj) => this.completeRequestPicker(this.getData(obj)));\n return this;\n }\n\n trace(obj: any) {\n this.run(levels().TRACE, obj, (obj) => this.completeRequestPicker(this.getData(obj)));\n return this;\n }\n\n public flush() {\n if (this.stack.length) {\n this.stack.forEach(({level, data}: any) => {\n this.logger[level](data);\n });\n\n this.stack = [];\n }\n }\n\n public isLevelEnabled(otherLevel: string | LogLevel) {\n return this.level.isLessThanOrEqualTo(otherLevel);\n }\n\n destroy() {\n this.flush();\n\n this.logger = undefined;\n this.stack = undefined;\n }\n\n /**\n * Return the duration between the time when LogIncomingRequest has handle the request and now.\n * @returns {number}\n */\n protected getDuration(): number {\n return new Date().getTime() - this.dateStart.getTime();\n }\n\n protected getData(obj: any) {\n if (typeof obj === \"string\") {\n obj = {message: obj};\n }\n\n return {...this.additionalProps, reqId: this.id, time: new Date(), duration: this.getDuration(), ...obj};\n }\n\n protected run(level: LogLevel, obj: any, mapper: (data: any) => any) {\n if (!this.isLevelEnabled(level)) {\n return;\n }\n\n if (!this.ignoreLog(obj)) {\n this.stack.push({level: level.levelStr.toLowerCase(), data: mapper(obj)});\n }\n\n if (this.maxStackSize < this.stack.length) {\n this.flush();\n }\n }\n}\n"]}
@@ -0,0 +1,41 @@
1
+ import { ContextLogger } from "./ContextLogger.js";
2
+ import { LocalsContainer } from "./LocalsContainer.js";
3
+ export class DIContext extends Map {
4
+ constructor({ id, injector, logger, ignoreLog, ...options }) {
5
+ super();
6
+ /**
7
+ * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.
8
+ */
9
+ this.dateStart = new Date();
10
+ /**
11
+ * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`
12
+ */
13
+ this.container = new LocalsContainer();
14
+ this.id = id;
15
+ injector && (this.injector = injector);
16
+ this.logger = new ContextLogger(logger, {
17
+ ...options,
18
+ dateStart: this.dateStart,
19
+ id,
20
+ ignoreLog
21
+ });
22
+ }
23
+ get env() {
24
+ return this.injector.settings.env;
25
+ }
26
+ async destroy() {
27
+ await this.container.destroy();
28
+ this.logger.destroy();
29
+ // @ts-ignore
30
+ delete this.container;
31
+ // @ts-ignore
32
+ delete this.logger;
33
+ // @ts-ignore
34
+ delete this.injector;
35
+ }
36
+ async emit(eventName, ...args) {
37
+ var _a;
38
+ return (_a = this.injector) === null || _a === void 0 ? void 0 : _a.emit(eventName, ...args);
39
+ }
40
+ }
41
+ //# sourceMappingURL=DIContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAkBlD,MAAM,OAAO,SAAU,SAAQ,GAAa;IA4C1C,YAAY,EAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,EAAmB;QACzE,KAAK,EAAE,CAAC;QAlBV;;WAEG;QACM,cAAS,GAAS,IAAI,IAAI,EAAE,CAAC;QACtC;;WAEG;QACI,cAAS,GAAG,IAAI,eAAe,EAAO,CAAC;QAY5C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QAEb,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,aAAa,CAAC,MAAM,EAAE;YACtC,GAAG,OAAO;YACV,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,EAAE;YACF,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACtB,aAAa;QACb,OAAO,IAAI,CAAC,SAAS,CAAC;QACtB,aAAa;QACb,OAAO,IAAI,CAAC,MAAM,CAAC;QACnB,aAAa;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,GAAG,IAAW;;QAC1C,OAAO,MAAA,IAAI,CAAC,QAAQ,0CAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;CACF","sourcesContent":["import type {Env} from \"@tsed/core\";\nimport {InjectorService} from \"../services/InjectorService\";\nimport {ContextLogger, ContextLoggerOptions} from \"./ContextLogger\";\nimport {LocalsContainer} from \"./LocalsContainer\";\n\nexport interface ContextMethods extends Map<any, any> {\n readonly id: string;\n readonly logger: ContextLogger;\n readonly injector: InjectorService;\n readonly container: LocalsContainer;\n readonly env: Env;\n\n destroy(): any;\n}\n\nexport interface DIContextOptions extends Omit<ContextLoggerOptions, \"dateStart\"> {\n id: string;\n logger: any;\n injector?: InjectorService;\n}\n\nexport class DIContext extends Map<any, any> implements ContextMethods {\n [x: string]: any;\n /**\n * Request id generated by @@contextMiddleware@@.\n *\n * ::: tip\n * By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, \"\"))`.\n * Dash are removed to simplify tracking logs in Kibana\n * :::\n *\n * ::: tip\n * Request id can by customized by changing the server configuration.\n *\n * ```typescript\n * @Configuration({\n * logger: {\n * reqIdBuilder: createUniqId // give your own id generator function\n * }\n * })\n * class Server {\n *\n * }\n * ```\n * :::\n *\n */\n readonly id: string;\n /**\n * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.\n */\n readonly dateStart: Date = new Date();\n /**\n * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`\n */\n public container = new LocalsContainer<any>();\n /**\n * Logger attached to the context request.\n */\n public logger: ContextLogger;\n /**\n *\n */\n public injector: InjectorService;\n\n constructor({id, injector, logger, ignoreLog, ...options}: DIContextOptions) {\n super();\n this.id = id;\n\n injector && (this.injector = injector);\n\n this.logger = new ContextLogger(logger, {\n ...options,\n dateStart: this.dateStart,\n id,\n ignoreLog\n });\n }\n\n get env() {\n return this.injector.settings.env;\n }\n\n async destroy() {\n await this.container.destroy();\n this.logger.destroy();\n // @ts-ignore\n delete this.container;\n // @ts-ignore\n delete this.logger;\n // @ts-ignore\n delete this.injector;\n }\n\n async emit(eventName: string, ...args: any[]) {\n return this.injector?.emit(eventName, ...args);\n }\n}\n\nexport type BaseContext = DIContext & TsED.Context;\n"]}
@@ -0,0 +1,9 @@
1
+ export var InjectablePropertyType;
2
+ (function (InjectablePropertyType) {
3
+ InjectablePropertyType["METHOD"] = "method";
4
+ InjectablePropertyType["PROPERTY"] = "property";
5
+ InjectablePropertyType["CONSTANT"] = "constant";
6
+ InjectablePropertyType["VALUE"] = "value";
7
+ InjectablePropertyType["INTERCEPTOR"] = "interceptor";
8
+ })(InjectablePropertyType || (InjectablePropertyType = {}));
9
+ //# sourceMappingURL=InjectablePropertyType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InjectablePropertyType.js","sourceRoot":"","sources":["../../../src/domain/InjectablePropertyType.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,sBAMX;AAND,WAAY,sBAAsB;IAChC,2CAAiB,CAAA;IACjB,+CAAqB,CAAA;IACrB,+CAAqB,CAAA;IACrB,yCAAe,CAAA;IACf,qDAA2B,CAAA;AAC7B,CAAC,EANW,sBAAsB,KAAtB,sBAAsB,QAMjC","sourcesContent":["export enum InjectablePropertyType {\n METHOD = \"method\",\n PROPERTY = \"property\",\n CONSTANT = \"constant\",\n VALUE = \"value\",\n INTERCEPTOR = \"interceptor\"\n}\n"]}
@@ -0,0 +1,51 @@
1
+ export class LocalsContainer extends Map {
2
+ /**
3
+ * Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
4
+ * @param eventName The event name to emit at all services.
5
+ * @param args List of the parameters to give to each services.
6
+ * @returns {Promise<any[]>} A list of promises.
7
+ */
8
+ async emit(eventName, ...args) {
9
+ for (const handler of this.getListeners(eventName)) {
10
+ await handler(...args);
11
+ }
12
+ }
13
+ /**
14
+ * @param eventName
15
+ * @param value
16
+ * @param args
17
+ */
18
+ alter(eventName, value, ...args) {
19
+ for (const handler of this.getListeners(eventName)) {
20
+ value = handler(value, ...args);
21
+ }
22
+ return value;
23
+ }
24
+ /**
25
+ * @param eventName
26
+ * @param value
27
+ * @param args
28
+ */
29
+ async alterAsync(eventName, value, ...args) {
30
+ for (const handler of this.getListeners(eventName)) {
31
+ value = handler(value, ...args);
32
+ }
33
+ return value;
34
+ }
35
+ toArray() {
36
+ return [...this.values()];
37
+ }
38
+ async destroy() {
39
+ await this.emit("$onDestroy");
40
+ this.clear();
41
+ }
42
+ getListeners(event) {
43
+ return this.toArray().reduce((listeners, instance) => {
44
+ if (typeof instance === "object" && instance && event in instance) {
45
+ return listeners.concat(instance[event].bind(instance));
46
+ }
47
+ return listeners;
48
+ }, []);
49
+ }
50
+ }
51
+ //# sourceMappingURL=LocalsContainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocalsContainer.js","sourceRoot":"","sources":["../../../src/domain/LocalsContainer.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,eAAyB,SAAQ,GAAqB;IACjE;;;;;OAKG;I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AC;QACnB,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF","sourcesContent":["import type {TokenProvider} from \"../interfaces/TokenProvider\";\n\nexport class LocalsContainer<V = any> extends Map<TokenProvider, V> {\n /**\n * Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).\n * @param eventName The event name to emit at all services.\n * @param args List of the parameters to give to each services.\n * @returns {Promise<any[]>} A list of promises.\n */\n public async emit(eventName: string, ...args: any[]) {\n for (const handler of this.getListeners(eventName)) {\n await handler(...args);\n }\n }\n\n /**\n * @param eventName\n * @param value\n * @param args\n */\n public alter<T = any>(eventName: string, value: any, ...args: any[]): T {\n for (const handler of this.getListeners(eventName)) {\n value = handler(value, ...args);\n }\n\n return value;\n }\n\n /**\n * @param eventName\n * @param value\n * @param args\n */\n public async alterAsync<T = any>(eventName: string, value: any, ...args: any[]): Promise<T> {\n for (const handler of this.getListeners(eventName)) {\n value = handler(value, ...args);\n }\n\n return value;\n }\n\n toArray() {\n return [...this.values()];\n }\n\n async destroy() {\n await this.emit(\"$onDestroy\");\n this.clear();\n }\n\n protected getListeners(event: string): any[] {\n return this.toArray().reduce((listeners, instance) => {\n if (typeof instance === \"object\" && instance && event in instance) {\n return listeners.concat((instance as any)[event].bind(instance));\n }\n\n return listeners;\n }, []);\n }\n}\n"]}