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

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 (269) 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 +57 -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/package.json +3 -0
  82. package/lib/cjs/registries/GlobalProviders.js +124 -0
  83. package/lib/cjs/registries/GlobalProviders.js.map +1 -0
  84. package/lib/cjs/registries/ProviderRegistry.js +86 -0
  85. package/lib/cjs/registries/ProviderRegistry.js.map +1 -0
  86. package/lib/cjs/services/DIConfiguration.js +129 -0
  87. package/lib/cjs/services/DIConfiguration.js.map +1 -0
  88. package/lib/cjs/services/DILogger.js +13 -0
  89. package/lib/cjs/services/DILogger.js.map +1 -0
  90. package/lib/cjs/services/DITest.js +116 -0
  91. package/lib/cjs/services/DITest.js.map +1 -0
  92. package/lib/cjs/services/InjectorService.js +572 -0
  93. package/lib/cjs/services/InjectorService.js.map +1 -0
  94. package/lib/cjs/utils/colors.js +10 -0
  95. package/lib/cjs/utils/colors.js.map +1 -0
  96. package/lib/cjs/utils/createContainer.js +14 -0
  97. package/lib/cjs/utils/createContainer.js.map +1 -0
  98. package/lib/cjs/utils/getConfiguration.js +20 -0
  99. package/lib/cjs/utils/getConfiguration.js.map +1 -0
  100. package/lib/cjs/utils/runInContext.js +19 -0
  101. package/lib/cjs/utils/runInContext.js.map +1 -0
  102. package/lib/cjs/utils/setLoggerLevel.js +16 -0
  103. package/lib/cjs/utils/setLoggerLevel.js.map +1 -0
  104. package/lib/esm/constants/constants.js +4 -0
  105. package/lib/esm/constants/constants.js.map +1 -0
  106. package/lib/esm/decorators/configuration.js +20 -0
  107. package/lib/esm/decorators/configuration.js.map +1 -0
  108. package/lib/esm/decorators/constant.js +51 -0
  109. package/lib/esm/decorators/constant.js.map +1 -0
  110. package/lib/esm/decorators/controller.js +49 -0
  111. package/lib/esm/decorators/controller.js.map +1 -0
  112. package/lib/esm/decorators/inject.js +98 -0
  113. package/lib/esm/decorators/inject.js.map +1 -0
  114. package/lib/esm/decorators/injectable.js +28 -0
  115. package/lib/esm/decorators/injectable.js.map +1 -0
  116. package/lib/esm/decorators/intercept.js +32 -0
  117. package/lib/esm/decorators/intercept.js.map +1 -0
  118. package/lib/esm/decorators/interceptor.js +17 -0
  119. package/lib/esm/decorators/interceptor.js.map +1 -0
  120. package/lib/esm/decorators/lazyInject.js +66 -0
  121. package/lib/esm/decorators/lazyInject.js.map +1 -0
  122. package/lib/esm/decorators/module.js +28 -0
  123. package/lib/esm/decorators/module.js.map +1 -0
  124. package/lib/esm/decorators/opts.js +50 -0
  125. package/lib/esm/decorators/opts.js.map +1 -0
  126. package/lib/esm/decorators/overrideProvider.js +13 -0
  127. package/lib/esm/decorators/overrideProvider.js.map +1 -0
  128. package/lib/esm/decorators/scope.js +12 -0
  129. package/lib/esm/decorators/scope.js.map +1 -0
  130. package/lib/esm/decorators/service.js +14 -0
  131. package/lib/esm/decorators/service.js.map +1 -0
  132. package/lib/esm/decorators/useOpts.js +61 -0
  133. package/lib/esm/decorators/useOpts.js.map +1 -0
  134. package/lib/esm/decorators/value.js +51 -0
  135. package/lib/esm/decorators/value.js.map +1 -0
  136. package/lib/esm/domain/Container.js +68 -0
  137. package/lib/esm/domain/Container.js.map +1 -0
  138. package/lib/esm/domain/ContextLogger.js +81 -0
  139. package/lib/esm/domain/ContextLogger.js.map +1 -0
  140. package/lib/esm/domain/DIContext.js +41 -0
  141. package/lib/esm/domain/DIContext.js.map +1 -0
  142. package/lib/esm/domain/InjectablePropertyType.js +9 -0
  143. package/lib/esm/domain/InjectablePropertyType.js.map +1 -0
  144. package/lib/esm/domain/LocalsContainer.js +51 -0
  145. package/lib/esm/domain/LocalsContainer.js.map +1 -0
  146. package/lib/esm/domain/Provider.js +118 -0
  147. package/lib/esm/domain/Provider.js.map +1 -0
  148. package/lib/esm/domain/ProviderScope.js +7 -0
  149. package/lib/esm/domain/ProviderScope.js.map +1 -0
  150. package/lib/esm/domain/ProviderType.js +12 -0
  151. package/lib/esm/domain/ProviderType.js.map +1 -0
  152. package/lib/esm/errors/InjectionError.js +54 -0
  153. package/lib/esm/errors/InjectionError.js.map +1 -0
  154. package/lib/esm/errors/UndefinedTokenError.js +7 -0
  155. package/lib/esm/errors/UndefinedTokenError.js.map +1 -0
  156. package/lib/esm/index.js +54 -0
  157. package/lib/esm/index.js.map +1 -0
  158. package/lib/esm/interfaces/DIConfigurationOptions.js +2 -0
  159. package/lib/esm/interfaces/DIConfigurationOptions.js.map +1 -0
  160. package/lib/esm/interfaces/DILogger.js +2 -0
  161. package/lib/esm/interfaces/DILogger.js.map +1 -0
  162. package/lib/esm/interfaces/DIResolver.js +2 -0
  163. package/lib/esm/interfaces/DIResolver.js.map +1 -0
  164. package/lib/esm/interfaces/InjectableProperties.js +2 -0
  165. package/lib/esm/interfaces/InjectableProperties.js.map +1 -0
  166. package/lib/esm/interfaces/InterceptorContext.js +2 -0
  167. package/lib/esm/interfaces/InterceptorContext.js.map +1 -0
  168. package/lib/esm/interfaces/InterceptorMethods.js +2 -0
  169. package/lib/esm/interfaces/InterceptorMethods.js.map +1 -0
  170. package/lib/esm/interfaces/InvokeOptions.js +2 -0
  171. package/lib/esm/interfaces/InvokeOptions.js.map +1 -0
  172. package/lib/esm/interfaces/OnDestroy.js +2 -0
  173. package/lib/esm/interfaces/OnDestroy.js.map +1 -0
  174. package/lib/esm/interfaces/OnInit.js +2 -0
  175. package/lib/esm/interfaces/OnInit.js.map +1 -0
  176. package/lib/esm/interfaces/ProviderOpts.js +2 -0
  177. package/lib/esm/interfaces/ProviderOpts.js.map +1 -0
  178. package/lib/esm/interfaces/RegistrySettings.js +2 -0
  179. package/lib/esm/interfaces/RegistrySettings.js.map +1 -0
  180. package/lib/esm/interfaces/ResolvedInvokeOptions.js +2 -0
  181. package/lib/esm/interfaces/ResolvedInvokeOptions.js.map +1 -0
  182. package/lib/esm/interfaces/TokenProvider.js +2 -0
  183. package/lib/esm/interfaces/TokenProvider.js.map +1 -0
  184. package/lib/esm/package.json +3 -0
  185. package/lib/esm/registries/GlobalProviders.js +120 -0
  186. package/lib/esm/registries/GlobalProviders.js.map +1 -0
  187. package/lib/esm/registries/ProviderRegistry.js +81 -0
  188. package/lib/esm/registries/ProviderRegistry.js.map +1 -0
  189. package/lib/esm/services/DIConfiguration.js +125 -0
  190. package/lib/esm/services/DIConfiguration.js.map +1 -0
  191. package/lib/esm/services/DILogger.js +11 -0
  192. package/lib/esm/services/DILogger.js.map +1 -0
  193. package/lib/esm/services/DITest.js +112 -0
  194. package/lib/esm/services/DITest.js.map +1 -0
  195. package/lib/esm/services/InjectorService.js +569 -0
  196. package/lib/esm/services/InjectorService.js.map +1 -0
  197. package/lib/esm/utils/colors.js +7 -0
  198. package/lib/esm/utils/colors.js.map +1 -0
  199. package/lib/esm/utils/createContainer.js +10 -0
  200. package/lib/esm/utils/createContainer.js.map +1 -0
  201. package/lib/esm/utils/getConfiguration.js +16 -0
  202. package/lib/esm/utils/getConfiguration.js.map +1 -0
  203. package/lib/esm/utils/runInContext.js +13 -0
  204. package/lib/esm/utils/runInContext.js.map +1 -0
  205. package/lib/esm/utils/setLoggerLevel.js +12 -0
  206. package/lib/esm/utils/setLoggerLevel.js.map +1 -0
  207. package/lib/{constants/index.d.ts → types/constants/constants.d.ts} +0 -0
  208. package/lib/{decorators → types/decorators}/configuration.d.ts +0 -0
  209. package/lib/{decorators → types/decorators}/constant.d.ts +0 -0
  210. package/lib/types/decorators/controller.d.ts +43 -0
  211. package/lib/types/decorators/inject.d.ts +36 -0
  212. package/lib/{decorators → types/decorators}/injectable.d.ts +4 -5
  213. package/lib/{decorators → types/decorators}/intercept.d.ts +2 -2
  214. package/lib/{decorators → types/decorators}/interceptor.d.ts +0 -0
  215. package/lib/types/decorators/lazyInject.d.ts +43 -0
  216. package/lib/{decorators → types/decorators}/module.d.ts +3 -2
  217. package/lib/{decorators → types/decorators}/opts.d.ts +0 -0
  218. package/lib/{decorators → types/decorators}/overrideProvider.d.ts +0 -0
  219. package/lib/{decorators → types/decorators}/scope.d.ts +0 -0
  220. package/lib/{decorators → types/decorators}/service.d.ts +0 -0
  221. package/lib/{decorators → types/decorators}/useOpts.d.ts +0 -0
  222. package/lib/{decorators → types/decorators}/value.d.ts +0 -0
  223. package/lib/{domain → types/domain}/Container.d.ts +5 -6
  224. package/lib/{domain → types/domain}/ContextLogger.d.ts +5 -1
  225. package/lib/{domain → types/domain}/DIContext.d.ts +6 -13
  226. package/lib/{domain → types/domain}/InjectablePropertyType.d.ts +0 -0
  227. package/lib/{domain → types/domain}/LocalsContainer.d.ts +0 -0
  228. package/lib/{domain → types/domain}/Provider.d.ts +21 -5
  229. package/lib/{domain → types/domain}/ProviderScope.d.ts +0 -0
  230. package/lib/{domain → types/domain}/ProviderType.d.ts +0 -0
  231. package/lib/{errors → types/errors}/InjectionError.d.ts +1 -1
  232. package/lib/{errors → types/errors}/UndefinedTokenError.d.ts +0 -0
  233. package/lib/types/index.d.ts +53 -0
  234. package/lib/{interfaces → types/interfaces}/DIConfigurationOptions.d.ts +0 -0
  235. package/lib/{interfaces → types/interfaces}/DILogger.d.ts +0 -0
  236. package/lib/{interfaces → types/interfaces}/DIResolver.d.ts +0 -0
  237. package/lib/{interfaces → types/interfaces}/InjectableProperties.d.ts +8 -4
  238. package/lib/{interfaces → types/interfaces}/InterceptorContext.d.ts +0 -0
  239. package/lib/{interfaces → types/interfaces}/InterceptorMethods.d.ts +0 -0
  240. package/lib/{interfaces → types/interfaces}/InvokeOptions.d.ts +0 -0
  241. package/lib/{interfaces → types/interfaces}/OnDestroy.d.ts +0 -0
  242. package/lib/{interfaces → types/interfaces}/OnInit.d.ts +0 -0
  243. package/lib/{interfaces/IProvider.d.ts → types/interfaces/ProviderOpts.d.ts} +5 -4
  244. package/lib/{interfaces → types/interfaces}/RegistrySettings.d.ts +7 -3
  245. package/lib/types/interfaces/ResolvedInvokeOptions.d.ts +12 -0
  246. package/lib/{interfaces → types/interfaces}/TokenProvider.d.ts +0 -0
  247. package/lib/{registries → types/registries}/GlobalProviders.d.ts +11 -5
  248. package/lib/{registries → types/registries}/ProviderRegistry.d.ts +4 -4
  249. package/lib/{services → types/services}/DIConfiguration.d.ts +3 -2
  250. package/lib/{services → types/services}/DILogger.d.ts +0 -0
  251. package/lib/{services → types/services}/DITest.d.ts +7 -1
  252. package/lib/{services → types/services}/InjectorService.d.ts +39 -21
  253. package/lib/types/utils/colors.d.ts +5 -0
  254. package/lib/{utils → types/utils}/createContainer.d.ts +0 -0
  255. package/lib/{utils → types/utils}/getConfiguration.d.ts +0 -0
  256. package/lib/types/utils/runInContext.d.ts +6 -0
  257. package/lib/{utils → types/utils}/setLoggerLevel.d.ts +0 -0
  258. package/package.json +31 -12
  259. package/readme.md +38 -42
  260. package/tsconfig.compile.esm.json +25 -0
  261. package/lib/decorators/index.d.ts +0 -13
  262. package/lib/decorators/inject.d.ts +0 -19
  263. package/lib/domain/index.d.ts +0 -8
  264. package/lib/index.d.ts +0 -16
  265. package/lib/index.js +0 -2271
  266. package/lib/index.js.map +0 -1
  267. package/lib/index.modern.js +0 -2235
  268. package/lib/index.modern.js.map +0 -1
  269. package/lib/interfaces/index.d.ts +0 -13
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createContainer.js","sourceRoot":"","sources":["../../../src/utils/createContainer.ts"],"names":[],"mappings":";;;AACA,mDAA8C;AAC9C,mEAA8D;AAE9D,SAAgB,eAAe,CAAC,UAAsB;IACpD,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,iCAAe,CAAC,OAAO,EAAE,CAAC,CAAC;IAE3D,IAAI,UAAU,EAAE;QACd,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;KAC9B;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AARD,0CAQC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {Container} from \"../domain/Container\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\n\nexport function createContainer(rootModule?: Type<any>) {\n const container = new Container(GlobalProviders.entries());\n\n if (rootModule) {\n container.delete(rootModule);\n }\n\n return container;\n}\n"]}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConfiguration = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ function getConfiguration(module, configuration = {}) {
6
+ const store = core_1.Store.from(module).get("configuration") || {};
7
+ const config = {
8
+ ...store,
9
+ ...configuration
10
+ };
11
+ if (store.mount && configuration.mount) {
12
+ config.mount = (0, core_1.deepMerge)(store.mount, configuration.mount);
13
+ }
14
+ if (store.componentsScan && configuration.componentsScan) {
15
+ config.componentsScan = [...store.componentsScan, ...configuration.componentsScan];
16
+ }
17
+ return config;
18
+ }
19
+ exports.getConfiguration = getConfiguration;
20
+ //# sourceMappingURL=getConfiguration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getConfiguration.js","sourceRoot":"","sources":["../../../src/utils/getConfiguration.ts"],"names":[],"mappings":";;;AAAA,qCAAkD;AAElD,SAAgB,gBAAgB,CAAC,MAAiB,EAAE,gBAAqB,EAAE;IACzE,MAAM,KAAK,GAAG,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;IAE5D,MAAM,MAAM,GAAG;QACb,GAAG,KAAK;QACR,GAAG,aAAa;KACjB,CAAC;IAEF,IAAI,KAAK,CAAC,KAAK,IAAI,aAAa,CAAC,KAAK,EAAE;QACtC,MAAM,CAAC,KAAK,GAAG,IAAA,gBAAS,EAAC,KAAK,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;KAC5D;IAED,IAAI,KAAK,CAAC,cAAc,IAAI,aAAa,CAAC,cAAc,EAAE;QACxD,MAAM,CAAC,cAAc,GAAG,CAAC,GAAG,KAAK,CAAC,cAAc,EAAE,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;KACpF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAjBD,4CAiBC","sourcesContent":["import {deepMerge, Store, Type} from \"@tsed/core\";\n\nexport function getConfiguration(module: Type<any>, configuration: any = {}) {\n const store = Store.from(module).get(\"configuration\") || {};\n\n const config = {\n ...store,\n ...configuration\n };\n\n if (store.mount && configuration.mount) {\n config.mount = deepMerge(store.mount, configuration.mount);\n }\n\n if (store.componentsScan && configuration.componentsScan) {\n config.componentsScan = [...store.componentsScan, ...configuration.componentsScan];\n }\n\n return config;\n}\n"]}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runInContext = exports.getContext = exports.getAsyncStore = void 0;
4
+ const async_hooks_1 = require("async_hooks");
5
+ let store;
6
+ function getAsyncStore() {
7
+ store = store || new async_hooks_1.AsyncLocalStorage();
8
+ return store;
9
+ }
10
+ exports.getAsyncStore = getAsyncStore;
11
+ function getContext() {
12
+ return store === null || store === void 0 ? void 0 : store.getStore();
13
+ }
14
+ exports.getContext = getContext;
15
+ function runInContext(ctx, cb) {
16
+ return getAsyncStore().run(ctx, cb);
17
+ }
18
+ exports.runInContext = runInContext;
19
+ //# sourceMappingURL=runInContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runInContext.js","sourceRoot":"","sources":["../../../src/utils/runInContext.ts"],"names":[],"mappings":";;;AAAA,6CAA8C;AAG9C,IAAI,KAAmC,CAAC;AAExC,SAAgB,aAAa;IAC3B,KAAK,GAAG,KAAK,IAAI,IAAI,+BAAiB,EAAE,CAAC;IACzC,OAAO,KAAK,CAAC;AACf,CAAC;AAHD,sCAGC;AAED,SAAgB,UAAU;IACxB,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,EAAE,CAAC;AAC3B,CAAC;AAFD,gCAEC;AAED,SAAgB,YAAY,CAAC,GAAc,EAAE,EAAO;IAClD,OAAO,aAAa,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC;AAFD,oCAEC","sourcesContent":["import {AsyncLocalStorage} from \"async_hooks\";\nimport {DIContext} from \"../domain/DIContext\";\n\nlet store: AsyncLocalStorage<DIContext>;\n\nexport function getAsyncStore() {\n store = store || new AsyncLocalStorage();\n return store;\n}\n\nexport function getContext() {\n return store?.getStore();\n}\n\nexport function runInContext(ctx: DIContext, cb: any) {\n return getAsyncStore().run(ctx, cb);\n}\n"]}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setLoggerLevel = void 0;
4
+ /**
5
+ * @ignore
6
+ * @param injector
7
+ */
8
+ function setLoggerLevel(injector) {
9
+ var _a;
10
+ const level = (_a = injector.settings.logger) === null || _a === void 0 ? void 0 : _a.level;
11
+ if (level) {
12
+ injector.logger.level = level;
13
+ }
14
+ }
15
+ exports.setLoggerLevel = setLoggerLevel;
16
+ //# sourceMappingURL=setLoggerLevel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setLoggerLevel.js","sourceRoot":"","sources":["../../../src/utils/setLoggerLevel.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,SAAgB,cAAc,CAAC,QAAyB;;IACtD,MAAM,KAAK,GAAG,MAAA,QAAQ,CAAC,QAAQ,CAAC,MAAM,0CAAE,KAAK,CAAC;IAE9C,IAAI,KAAK,EAAE;QACT,QAAQ,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;KAC/B;AACH,CAAC;AAND,wCAMC","sourcesContent":["import {InjectorService} from \"../services/InjectorService\";\n\n/**\n * @ignore\n * @param injector\n */\nexport function setLoggerLevel(injector: InjectorService) {\n const level = injector.settings.logger?.level;\n\n if (level) {\n injector.logger.level = level;\n }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export const INJECTABLE_PROP = "DI:INJECTABLE_PROP";
2
+ export const DI_PARAMS = "DI:PARAMS";
3
+ export const DI_PARAM_OPTIONS = "DI:PARAM:OPTIONS";
4
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,oBAAoB,CAAC;AACpD,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC;AACrC,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC","sourcesContent":["export const INJECTABLE_PROP = \"DI:INJECTABLE_PROP\";\nexport const DI_PARAMS = \"DI:PARAMS\";\nexport const DI_PARAM_OPTIONS = \"DI:PARAM:OPTIONS\";\n"]}
@@ -0,0 +1,20 @@
1
+ import { decoratorTypeOf, DecoratorTypes, StoreSet } from "@tsed/core";
2
+ import { Inject } from "../decorators/inject.js";
3
+ /**
4
+ * Get or set Configuration on a class.
5
+ *
6
+ * @decorator
7
+ */
8
+ export function Configuration(configuration = {}) {
9
+ return (...args) => {
10
+ switch (decoratorTypeOf(args)) {
11
+ case DecoratorTypes.CLASS:
12
+ StoreSet("configuration", configuration)(args[0]);
13
+ break;
14
+ default:
15
+ case DecoratorTypes.PARAM_CTOR:
16
+ return Inject(Configuration)(args[0], args[1], args[2]);
17
+ }
18
+ };
19
+ }
20
+ //# sourceMappingURL=configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../../src/decorators/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,eAAe,EAAE,cAAc,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AAC1F,OAAO,EAAC,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAG5C;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,gBAA6C,EAAE;IAC3E,OAAO,CAAC,GAAG,IAAyB,EAAE,EAAE;QACtC,QAAQ,eAAe,CAAC,IAAI,CAAC,EAAE;YAC7B,KAAK,cAAc,CAAC,KAAK;gBACvB,QAAQ,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBAElD,MAAM;YACR,QAAQ;YACR,KAAK,cAAc,CAAC,UAAU;gBAC5B,OAAO,MAAM,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAW,CAAC,CAAC;SACrE;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {DecoratorParameters, decoratorTypeOf, DecoratorTypes, StoreSet} from \"@tsed/core\";\nimport {Inject} from \"../decorators/inject\";\nimport {DIConfiguration} from \"../services/DIConfiguration\";\n\n/**\n * Get or set Configuration on a class.\n *\n * @decorator\n */\nexport function Configuration(configuration: Partial<TsED.Configuration> = {}): Function {\n return (...args: DecoratorParameters) => {\n switch (decoratorTypeOf(args)) {\n case DecoratorTypes.CLASS:\n StoreSet(\"configuration\", configuration)(args[0]);\n\n break;\n default:\n case DecoratorTypes.PARAM_CTOR:\n return Inject(Configuration)(args[0], args[1], args[2] as number);\n }\n };\n}\n\nexport type Configuration = TsED.Configuration & DIConfiguration;\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 {string} expression
35
+ * @param defaultValue
36
+ * @returns {(targetClass: any, attributeName: string) => any}
37
+ * @decorator
38
+ */
39
+ export function Constant(expression, defaultValue) {
40
+ return (target, propertyKey) => {
41
+ Store.from(target).merge(INJECTABLE_PROP, {
42
+ [propertyKey]: {
43
+ bindingType: InjectablePropertyType.CONSTANT,
44
+ propertyKey,
45
+ expression,
46
+ defaultValue
47
+ }
48
+ });
49
+ };
50
+ }
51
+ //# sourceMappingURL=constant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constant.js","sourceRoot":"","sources":["../../../src/decorators/constant.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,QAAQ,CAAC,UAAkB,EAAE,YAAkB;IAC7D,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,QAAQ;gBAC5C,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 {string} expression\n * @param defaultValue\n * @returns {(targetClass: any, attributeName: string) => any}\n * @decorator\n */\nexport function Constant(expression: string, defaultValue?: any): any {\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: InjectablePropertyType.CONSTANT,\n propertyKey,\n expression,\n defaultValue\n }\n } as InjectableProperties);\n };\n}\n"]}
@@ -0,0 +1,49 @@
1
+ import { isArrayOrArrayClass, useDecorators } from "@tsed/core";
2
+ import { Children, Path } from "@tsed/schema";
3
+ import { registerController } from "../registries/ProviderRegistry.js";
4
+ function mapOptions(options) {
5
+ if (typeof options === "string" || options instanceof RegExp || isArrayOrArrayClass(options)) {
6
+ return {
7
+ path: options
8
+ };
9
+ }
10
+ return options;
11
+ }
12
+ /**
13
+ * Declare a new controller with his Rest path. His methods annotated will be collected to build the routing list.
14
+ * This routing listing will be built with the `express.Router` object.
15
+ *
16
+ * ::: tip
17
+ * See [Controllers](/docs/controllers.md) section for more details
18
+ * :::
19
+ *
20
+ * ```typescript
21
+ * @Controller("/calendars")
22
+ * export provide CalendarCtrl {
23
+ *
24
+ * @Get("/:id")
25
+ * public get(
26
+ * @Req() request: Req,
27
+ * @Res() response: Res,
28
+ * @Next() next: Next
29
+ * ): void {
30
+ *
31
+ * }
32
+ * }
33
+ * ```
34
+ *
35
+ * @param options
36
+ * @controller
37
+ * @decorator
38
+ * @classDecorator
39
+ */
40
+ export function Controller(options) {
41
+ const { children = [], path, ...opts } = mapOptions(options);
42
+ return useDecorators((target) => {
43
+ registerController({
44
+ provide: target,
45
+ ...opts
46
+ });
47
+ }, path && Path(path), Children(...children));
48
+ }
49
+ //# sourceMappingURL=controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../src/decorators/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAQ,aAAa,EAAC,MAAM,YAAY,CAAC;AACpE,OAAO,EAAC,QAAQ,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAiBlE,SAAS,UAAU,CAAC,OAAY;IAC9B,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,YAAY,MAAM,IAAI,mBAAmB,CAAC,OAAO,CAAC,EAAE;QAC5F,OAAO;YACL,IAAI,EAAE,OAAO;SACd,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,UAAU,CAAC,OAAqC;IAC9D,MAAM,EAAC,QAAQ,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,IAAI,EAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAE3D,OAAO,aAAa,CAClB,CAAC,MAAY,EAAE,EAAE;QACf,kBAAkB,CAAC;YACjB,OAAO,EAAE,MAAM;YACf,GAAG,IAAI;SACR,CAAC,CAAC;IACL,CAAC,EACD,IAAI,IAAI,IAAI,CAAC,IAAW,CAAC,EACzB,QAAQ,CAAC,GAAG,QAAQ,CAAC,CACtB,CAAC;AACJ,CAAC","sourcesContent":["import {isArrayOrArrayClass, Type, useDecorators} from \"@tsed/core\";\nimport {Children, Path} from \"@tsed/schema\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {registerController} from \"../registries/ProviderRegistry\";\n\nexport type PathType = string | RegExp | (string | RegExp)[];\n\nexport interface ControllerMiddlewares {\n useBefore: any[];\n use: any[];\n useAfter: any[];\n}\n\nexport interface ControllerOptions extends Partial<ProviderOpts<any>> {\n path?: PathType;\n children?: Type<any>[];\n routerOptions?: any;\n middlewares?: Partial<ControllerMiddlewares>;\n}\n\nfunction mapOptions(options: any): ControllerOptions {\n if (typeof options === \"string\" || options instanceof RegExp || isArrayOrArrayClass(options)) {\n return {\n path: options\n };\n }\n\n return options;\n}\n\n/**\n * Declare a new controller with his Rest path. His methods annotated will be collected to build the routing list.\n * This routing listing will be built with the `express.Router` object.\n *\n * ::: tip\n * See [Controllers](/docs/controllers.md) section for more details\n * :::\n *\n * ```typescript\n * @Controller(\"/calendars\")\n * export provide CalendarCtrl {\n *\n * @Get(\"/:id\")\n * public get(\n * @Req() request: Req,\n * @Res() response: Res,\n * @Next() next: Next\n * ): void {\n *\n * }\n * }\n * ```\n *\n * @param options\n * @controller\n * @decorator\n * @classDecorator\n */\nexport function Controller(options: PathType | ControllerOptions): ClassDecorator {\n const {children = [], path, ...opts} = mapOptions(options);\n\n return useDecorators(\n (target: Type) => {\n registerController({\n provide: target,\n ...opts\n });\n },\n path && Path(path as any),\n Children(...children)\n );\n}\n"]}
@@ -0,0 +1,98 @@
1
+ import { decoratorTypeOf, DecoratorTypes, isPromise, Metadata, Store, UnsupportedDecoratorType } from "@tsed/core";
2
+ import { DI_PARAM_OPTIONS, INJECTABLE_PROP } from "../constants/constants.js";
3
+ import { getContext } from "../utils/runInContext.js";
4
+ export function injectProperty(target, propertyKey, options) {
5
+ Store.from(target).merge(INJECTABLE_PROP, {
6
+ [propertyKey]: {
7
+ bindingType: DecoratorTypes.PROP,
8
+ propertyKey,
9
+ ...options
10
+ }
11
+ });
12
+ }
13
+ /**
14
+ * Inject a provider to another provider.
15
+ *
16
+ * Use this decorator to inject a custom provider on constructor parameter or property.
17
+ *
18
+ * ```typescript
19
+ * @Injectable()
20
+ * export class MyService {
21
+ * @Inject(CONNECTION)
22
+ * connection: CONNECTION;
23
+ * }
24
+ * ```
25
+ *
26
+ * @param symbol
27
+ * @param onGet Use the given name method to inject
28
+ * @returns {Function}
29
+ * @decorator
30
+ */
31
+ export function Inject(symbol, onGet = (bean) => bean) {
32
+ return (target, propertyKey, descriptor) => {
33
+ const bindingType = decoratorTypeOf([target, propertyKey, descriptor]);
34
+ switch (bindingType) {
35
+ case DecoratorTypes.PARAM:
36
+ case DecoratorTypes.PARAM_CTOR:
37
+ if (symbol) {
38
+ const paramTypes = Metadata.getParamTypes(target, propertyKey);
39
+ paramTypes[descriptor] = symbol;
40
+ Metadata.setParamTypes(target, propertyKey, paramTypes);
41
+ }
42
+ break;
43
+ case DecoratorTypes.PROP:
44
+ injectProperty(target, propertyKey, {
45
+ resolver(injector, locals, { options, ...invokeOptions }) {
46
+ locals.set(DI_PARAM_OPTIONS, { ...options });
47
+ let bean;
48
+ if (!bean) {
49
+ const useType = symbol || Metadata.getType(target, propertyKey);
50
+ bean = injector.invoke(useType, locals, invokeOptions);
51
+ locals.delete(DI_PARAM_OPTIONS);
52
+ }
53
+ if (isPromise(bean)) {
54
+ bean.then((result) => {
55
+ bean = result;
56
+ });
57
+ }
58
+ return () => onGet(bean);
59
+ }
60
+ });
61
+ break;
62
+ case DecoratorTypes.METHOD:
63
+ Store.from(target).merge(INJECTABLE_PROP, {
64
+ [propertyKey]: {
65
+ bindingType,
66
+ propertyKey
67
+ }
68
+ });
69
+ return descriptor;
70
+ default:
71
+ throw new UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);
72
+ }
73
+ };
74
+ }
75
+ /**
76
+ * Inject a context like PlatformContext or any BaseContext.
77
+ *
78
+ * ```typescript
79
+ * @Injectable()
80
+ * export class MyService {
81
+ * @InjectContext()
82
+ * ctx?: Context;
83
+ * }
84
+ * ```
85
+ *
86
+ * @returns {Function}
87
+ * @decorator
88
+ */
89
+ export function InjectContext() {
90
+ return (target, propertyKey) => {
91
+ injectProperty(target, propertyKey, {
92
+ resolver() {
93
+ return () => getContext();
94
+ }
95
+ });
96
+ };
97
+ }
98
+ //# sourceMappingURL=inject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/decorators/inject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAC;AACjH,OAAO,EAAC,gBAAgB,EAAE,eAAe,EAAC,MAAM,wBAAwB,CAAC;AAEzE,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAEjD,MAAM,UAAU,cAAc,CAAC,MAAW,EAAE,WAAmB,EAAE,OAA2C;IAC1G,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,eAAe,EAAE;QACxC,CAAC,WAAW,CAAC,EAAE;YACb,WAAW,EAAE,cAAc,CAAC,IAAI;YAChC,WAAW;YACX,GAAG,OAAO;SACX;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM,CAAC,MAAY,EAAE,QAAQ,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI;IAC9D,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,UAAsD,EAAc,EAAE;QAC9G,MAAM,WAAW,GAAG,eAAe,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;QAEvE,QAAQ,WAAW,EAAE;YACnB,KAAK,cAAc,CAAC,KAAK,CAAC;YAC1B,KAAK,cAAc,CAAC,UAAU;gBAC5B,IAAI,MAAM,EAAE;oBACV,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;oBAE/D,UAAU,CAAC,UAAoB,CAAC,GAAG,MAAM,CAAC;oBAC1C,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;iBACzD;gBACD,MAAM;YAER,KAAK,cAAc,CAAC,IAAI;gBACtB,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;oBAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAC,OAAO,EAAE,GAAG,aAAa,EAAC;wBACpD,MAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,EAAC,GAAG,OAAO,EAAC,CAAC,CAAC;wBAE3C,IAAI,IAAS,CAAC;wBAEd,IAAI,CAAC,IAAI,EAAE;4BACT,MAAM,OAAO,GAAG,MAAM,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;4BAChE,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;4BACvD,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;yBACjC;wBAED,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE;4BACnB,IAAI,CAAC,IAAI,CAAC,CAAC,MAAW,EAAE,EAAE;gCACxB,IAAI,GAAG,MAAM,CAAC;4BAChB,CAAC,CAAC,CAAC;yBACJ;wBAED,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBAC3B,CAAC;iBACF,CAAC,CAAC;gBACH,MAAM;YAER,KAAK,cAAc,CAAC,MAAM;gBACxB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,eAAe,EAAE;oBACxC,CAAC,WAAW,CAAC,EAAE;wBACb,WAAW;wBACX,WAAW;qBACZ;iBACF,CAAC,CAAC;gBAEH,OAAO,UAAU,CAAC;YAEpB;gBACE,MAAM,IAAI,wBAAwB,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;SACjF;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAc,EAAE;QACtD,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;YAClC,QAAQ;gBACN,OAAO,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC;YAC5B,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, isPromise, Metadata, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants/constants\";\nimport type {InjectablePropertyOptions} from \"../interfaces/InjectableProperties\";\nimport {getContext} from \"../utils/runInContext\";\n\nexport function injectProperty(target: any, propertyKey: string, options: Partial<InjectablePropertyOptions>) {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: DecoratorTypes.PROP,\n propertyKey,\n ...options\n }\n });\n}\n\n/**\n * Inject a provider to another provider.\n *\n * Use this decorator to inject a custom provider on constructor parameter or property.\n *\n * ```typescript\n * @Injectable()\n * export class MyService {\n * @Inject(CONNECTION)\n * connection: CONNECTION;\n * }\n * ```\n *\n * @param symbol\n * @param onGet Use the given name method to inject\n * @returns {Function}\n * @decorator\n */\nexport function Inject(symbol?: any, onGet = (bean: any) => bean): Function {\n return (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<Function> | number): any | void => {\n const bindingType = decoratorTypeOf([target, propertyKey, descriptor]);\n\n switch (bindingType) {\n case DecoratorTypes.PARAM:\n case DecoratorTypes.PARAM_CTOR:\n if (symbol) {\n const paramTypes = Metadata.getParamTypes(target, propertyKey);\n\n paramTypes[descriptor as number] = symbol;\n Metadata.setParamTypes(target, propertyKey, paramTypes);\n }\n break;\n\n case DecoratorTypes.PROP:\n injectProperty(target, propertyKey, {\n resolver(injector, locals, {options, ...invokeOptions}) {\n locals.set(DI_PARAM_OPTIONS, {...options});\n\n let bean: any;\n\n if (!bean) {\n const useType = symbol || Metadata.getType(target, propertyKey);\n bean = injector.invoke(useType, locals, invokeOptions);\n locals.delete(DI_PARAM_OPTIONS);\n }\n\n if (isPromise(bean)) {\n bean.then((result: any) => {\n bean = result;\n });\n }\n\n return () => onGet(bean);\n }\n });\n break;\n\n case DecoratorTypes.METHOD:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType,\n propertyKey\n }\n });\n\n return descriptor;\n\n default:\n throw new UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);\n }\n };\n}\n\n/**\n * Inject a context like PlatformContext or any BaseContext.\n *\n * ```typescript\n * @Injectable()\n * export class MyService {\n * @InjectContext()\n * ctx?: Context;\n * }\n * ```\n *\n * @returns {Function}\n * @decorator\n */\nexport function InjectContext(): PropertyDecorator {\n return (target: any, propertyKey: string): any | void => {\n injectProperty(target, propertyKey, {\n resolver() {\n return () => getContext();\n }\n });\n };\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import { registerProvider } from "../registries/ProviderRegistry.js";
2
+ /**
3
+ * The decorators `@Injectable()` declare a new service can be injected in other service, controller, interceptor, etc.. on there `constructor`.
4
+ * All classes annotated with `@Injectable()` are built one time, excepted if you change the default provider configuration.
5
+ *
6
+ * ::: tip
7
+ * `@Injectable()` use the `reflect-metadata` to collect and inject the built provided to other services.
8
+ * :::
9
+ *
10
+ * ### Options
11
+ *
12
+ * - type (@@ProviderType@@ or `string`): Kind of provider. (Default: `ProviderType.PROVIDER`)
13
+ * - scope (@@ProviderScope@@): Kind of provider. (Default: `ProviderScope.SINGLETON`)
14
+ * - provide (@@TokenProvider@@): An injection token (Note: This option override default metadata generated by Typescript).
15
+ * - deps (`Type<any>`): List of class or provider which will be injected to the constructor (Note: This options override default metadata generated by Typescript).
16
+ *
17
+ * @returns {Function}
18
+ * @decorator
19
+ */
20
+ export function Injectable(options = {}) {
21
+ return (target) => {
22
+ registerProvider({
23
+ ...options,
24
+ ...(options.provide ? { useClass: target } : { provide: target })
25
+ });
26
+ };
27
+ }
28
+ //# sourceMappingURL=injectable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectable.js","sourceRoot":"","sources":["../../../src/decorators/injectable.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,gCAAgC,CAAC;AAEhE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,UAAU,CAAC,UAAiC,EAAE;IAC5D,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,gBAAgB,CAAC;YACf,GAAG,OAAO;YACV,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC,CAAC,EAAC,OAAO,EAAE,MAAM,EAAC,CAAC;SAC9D,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {registerProvider} from \"../registries/ProviderRegistry\";\n\n/**\n * The decorators `@Injectable()` declare a new service can be injected in other service, controller, interceptor, etc.. on there `constructor`.\n * All classes annotated with `@Injectable()` are built one time, excepted if you change the default provider configuration.\n *\n * ::: tip\n * `@Injectable()` use the `reflect-metadata` to collect and inject the built provided to other services.\n * :::\n *\n * ### Options\n *\n * - type (@@ProviderType@@ or `string`): Kind of provider. (Default: `ProviderType.PROVIDER`)\n * - scope (@@ProviderScope@@): Kind of provider. (Default: `ProviderScope.SINGLETON`)\n * - provide (@@TokenProvider@@): An injection token (Note: This option override default metadata generated by Typescript).\n * - deps (`Type<any>`): List of class or provider which will be injected to the constructor (Note: This options override default metadata generated by Typescript).\n *\n * @returns {Function}\n * @decorator\n */\nexport function Injectable(options: Partial<ProviderOpts> = {}): ClassDecorator {\n return (target: any) => {\n registerProvider({\n ...options,\n ...(options.provide ? {useClass: target} : {provide: target})\n });\n };\n}\n"]}
@@ -0,0 +1,32 @@
1
+ import { decorateMethodsOf, decoratorTypeOf, DecoratorTypes, Store } from "@tsed/core";
2
+ import { INJECTABLE_PROP } from "../constants/constants.js";
3
+ import { InjectablePropertyType } from "../domain/InjectablePropertyType.js";
4
+ /**
5
+ * Attaches interceptor to method call and executes the before and after methods
6
+ *
7
+ * @param interceptor
8
+ * @param options
9
+ * @decorator
10
+ */
11
+ export function Intercept(interceptor, options) {
12
+ return (...args) => {
13
+ const [target, propertyKey, descriptor] = args;
14
+ const type = decoratorTypeOf(args);
15
+ switch (type) {
16
+ case DecoratorTypes.CLASS:
17
+ decorateMethodsOf(target, Intercept(interceptor, options));
18
+ break;
19
+ case DecoratorTypes.METHOD:
20
+ Store.from(target).merge(INJECTABLE_PROP, {
21
+ [propertyKey]: {
22
+ options,
23
+ propertyKey,
24
+ useType: interceptor,
25
+ bindingType: InjectablePropertyType.INTERCEPTOR
26
+ }
27
+ });
28
+ return descriptor;
29
+ }
30
+ };
31
+ }
32
+ //# sourceMappingURL=intercept.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intercept.js","sourceRoot":"","sources":["../../../src/decorators/intercept.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAuB,eAAe,EAAE,cAAc,EAAE,KAAK,EAAO,MAAM,YAAY,CAAC;AAChH,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAC,sBAAsB,EAAC,MAAM,kCAAkC,CAAC;AAIxE;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAA+B,WAAoB,EAAE,OAAa;IACzF,OAAO,CAAC,GAAG,IAAyB,EAAE,EAAE;QACtC,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,IAAI,CAAC;QAC/C,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QACnC,QAAQ,IAAI,EAAE;YACZ,KAAK,cAAc,CAAC,KAAK;gBACvB,iBAAiB,CAAC,MAAM,EAAE,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;gBAC3D,MAAM;YACR,KAAK,cAAc,CAAC,MAAM;gBACxB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,eAAe,EAAE;oBACxC,CAAC,WAAW,CAAC,EAAE;wBACb,OAAO;wBACP,WAAW;wBACX,OAAO,EAAE,WAAW;wBACpB,WAAW,EAAE,sBAAsB,CAAC,WAAW;qBAChD;iBACsB,CAAC,CAAC;gBAE3B,OAAO,UAAU,CAAC;SACrB;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {decorateMethodsOf, DecoratorParameters, decoratorTypeOf, DecoratorTypes, Store, Type} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants/constants\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\nimport type {InterceptorMethods} from \"../interfaces/InterceptorMethods\";\nimport type {InjectableProperties} from \"../interfaces/InjectableProperties\";\n\n/**\n * Attaches interceptor to method call and executes the before and after methods\n *\n * @param interceptor\n * @param options\n * @decorator\n */\nexport function Intercept<T extends InterceptorMethods>(interceptor: Type<T>, options?: any): any {\n return (...args: DecoratorParameters) => {\n const [target, propertyKey, descriptor] = args;\n const type = decoratorTypeOf(args);\n switch (type) {\n case DecoratorTypes.CLASS:\n decorateMethodsOf(target, Intercept(interceptor, options));\n break;\n case DecoratorTypes.METHOD:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n options,\n propertyKey,\n useType: interceptor,\n bindingType: InjectablePropertyType.INTERCEPTOR\n }\n } as InjectableProperties);\n\n return descriptor;\n }\n };\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import { ProviderType } from "../domain/ProviderType.js";
2
+ import { Injectable } from "./injectable.js";
3
+ /**
4
+ * The decorators `@Service()` declare a new service can be injected in other service or controller on there `constructor`.
5
+ * All services annotated with `@Service()` are constructed one time.
6
+ *
7
+ * > `@Service()` use the `reflect-metadata` to collect and inject service on controllers or other services.
8
+ *
9
+ * @returns {Function}
10
+ * @decorator
11
+ */
12
+ export function Interceptor() {
13
+ return Injectable({
14
+ type: ProviderType.INTERCEPTOR
15
+ });
16
+ }
17
+ //# sourceMappingURL=interceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interceptor.js","sourceRoot":"","sources":["../../../src/decorators/interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAExC;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,UAAU,CAAC;QAChB,IAAI,EAAE,YAAY,CAAC,WAAW;KAC/B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {ProviderType} from \"../domain/ProviderType\";\nimport {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 Interceptor(): Function {\n return Injectable({\n type: ProviderType.INTERCEPTOR\n });\n}\n"]}
@@ -0,0 +1,66 @@
1
+ import { importPackage } from "@tsed/core";
2
+ import { injectProperty } from "./inject.js";
3
+ /**
4
+ * Lazy load a provider from his package and invoke only when the provider is used
5
+ *
6
+ * ```typescript
7
+ * import type {PlatformException} from "@tsed/platform-exceptions";
8
+ *
9
+ * @Injectable()
10
+ * export class MyService {
11
+ * @LazyInject("PlatformException", () => import("@tsed/platform-exceptions"))
12
+ * exceptions: Promise<PlatformException>;
13
+ * }
14
+ * ```
15
+ *
16
+ * @param key
17
+ * @param packageName
18
+ * @param resolver
19
+ * @param optional
20
+ * @returns {Function}
21
+ * @decorator
22
+ */
23
+ export function LazyInject(key, resolver, { optional = false, packageName = resolver.toString() } = {}) {
24
+ return (target, propertyKey) => {
25
+ let bean, token;
26
+ injectProperty(target, propertyKey, {
27
+ resolver(injector) {
28
+ return async () => {
29
+ if (!token) {
30
+ const exports = await importPackage(packageName, resolver, optional);
31
+ token = exports[key];
32
+ if (!token) {
33
+ if (!optional) {
34
+ throw new Error(`Unable to lazy load the "${key}". The token isn\'t a valid token provider.`);
35
+ }
36
+ }
37
+ bean = token ? await injector.lazyInvoke(token) : {};
38
+ }
39
+ return bean;
40
+ };
41
+ }
42
+ });
43
+ };
44
+ }
45
+ /**
46
+ * Optionally Lazy load a provider from his package and invoke only when the provider is used
47
+ *
48
+ * ```typescript
49
+ * import type {PlatformException} from "@tsed/platform-exceptions";
50
+ *
51
+ * @Injectable()
52
+ * export class MyService {
53
+ * @OptionalLazyInject("@tsed/platform-exceptions")
54
+ * exceptions: Promise<PlatformException>;
55
+ * }
56
+ * ```
57
+ *
58
+ * @param key
59
+ * @param resolver
60
+ * @returns {Function}
61
+ * @decorator
62
+ */
63
+ export function OptionalLazyInject(key, resolver) {
64
+ return LazyInject(key, resolver, { optional: true });
65
+ }
66
+ //# sourceMappingURL=lazyInject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazyInject.js","sourceRoot":"","sources":["../../../src/decorators/lazyInject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,UAAU,CACxB,GAAW,EACX,QAAmB,EACnB,EAAC,QAAQ,GAAG,KAAK,EAAE,WAAW,GAAG,QAAQ,CAAC,QAAQ,EAAE,KAAgD,EAAE;IAEtG,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAc,EAAE;QACtD,IAAI,IAAS,EAAE,KAAU,CAAC;QAC1B,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;YAClC,QAAQ,CAAC,QAAQ;gBACf,OAAO,KAAK,IAAI,EAAE;oBAChB,IAAI,CAAC,KAAK,EAAE;wBACV,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;wBACrE,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;wBAErB,IAAI,CAAC,KAAK,EAAE;4BACV,IAAI,CAAC,QAAQ,EAAE;gCACb,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,6CAA6C,CAAC,CAAC;6BAC/F;yBACF;wBAED,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;qBACtD;oBAED,OAAO,IAAI,CAAC;gBACd,CAAC,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW,EAAE,QAAmB;IACjE,OAAQ,UAAkB,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import {importPackage} from \"@tsed/core\";\nimport {injectProperty} from \"./inject\";\n\n/**\n * Lazy load a provider from his package and invoke only when the provider is used\n *\n * ```typescript\n * import type {PlatformException} from \"@tsed/platform-exceptions\";\n *\n * @Injectable()\n * export class MyService {\n * @LazyInject(\"PlatformException\", () => import(\"@tsed/platform-exceptions\"))\n * exceptions: Promise<PlatformException>;\n * }\n * ```\n *\n * @param key\n * @param packageName\n * @param resolver\n * @param optional\n * @returns {Function}\n * @decorator\n */\nexport function LazyInject(\n key: string,\n resolver: () => any,\n {optional = false, packageName = resolver.toString()}: {optional?: boolean; packageName?: string} = {}\n): PropertyDecorator {\n return (target: any, propertyKey: string): any | void => {\n let bean: any, token: any;\n injectProperty(target, propertyKey, {\n resolver(injector) {\n return async () => {\n if (!token) {\n const exports = await importPackage(packageName, resolver, optional);\n token = exports[key];\n\n if (!token) {\n if (!optional) {\n throw new Error(`Unable to lazy load the \"${key}\". The token isn\\'t a valid token provider.`);\n }\n }\n\n bean = token ? await injector.lazyInvoke(token) : {};\n }\n\n return bean;\n };\n }\n });\n };\n}\n\n/**\n * Optionally Lazy load a provider from his package and invoke only when the provider is used\n *\n * ```typescript\n * import type {PlatformException} from \"@tsed/platform-exceptions\";\n *\n * @Injectable()\n * export class MyService {\n * @OptionalLazyInject(\"@tsed/platform-exceptions\")\n * exceptions: Promise<PlatformException>;\n * }\n * ```\n *\n * @param key\n * @param resolver\n * @returns {Function}\n * @decorator\n */\nexport function OptionalLazyInject(key: string, resolver: () => any): PropertyDecorator {\n return (LazyInject as any)(key, resolver, {optional: true});\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import { useDecorators } from "@tsed/core";
2
+ import { ProviderScope } from "../domain/ProviderScope.js";
3
+ import { Configuration } from "./configuration.js";
4
+ import { Injectable } from "./injectable.js";
5
+ import { ProviderType } from "../domain/ProviderType.js";
6
+ /**
7
+ * Declare a new Ts.ED module
8
+ *
9
+ * ## Options
10
+ * - imports: List of Provider which must be built by injector before invoking the module
11
+ * - resolvers: List of external DI must be used to resolve unknown provider
12
+ * - deps: List of provider must be injected to the module constructor (explicit declaration)
13
+ *
14
+ * @param options
15
+ * @decorator
16
+ */
17
+ export function Module(options = {}) {
18
+ const { scopes, imports, resolvers, deps, scope, ...configuration } = options;
19
+ return useDecorators(Configuration(configuration), Injectable({
20
+ type: ProviderType.MODULE,
21
+ scope: ProviderScope.SINGLETON,
22
+ imports,
23
+ deps,
24
+ injectable: false,
25
+ resolvers
26
+ }));
27
+ }
28
+ //# sourceMappingURL=module.js.map
@@ -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"]}