@depup/nestjs__core 11.1.17-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (371) hide show
  1. package/LICENSE +22 -0
  2. package/PACKAGE.md +1 -0
  3. package/README.md +25 -0
  4. package/Readme.md +146 -0
  5. package/adapters/http-adapter.d.ts +80 -0
  6. package/adapters/http-adapter.js +90 -0
  7. package/adapters/index.d.ts +1 -0
  8. package/adapters/index.js +4 -0
  9. package/application-config.d.ts +47 -0
  10. package/application-config.js +107 -0
  11. package/changes.json +5 -0
  12. package/constants.d.ts +14 -0
  13. package/constants.js +21 -0
  14. package/discovery/discoverable-meta-host-collection.d.ts +46 -0
  15. package/discovery/discoverable-meta-host-collection.js +98 -0
  16. package/discovery/discovery-module.d.ts +5 -0
  17. package/discovery/discovery-module.js +19 -0
  18. package/discovery/discovery-service.d.ts +76 -0
  19. package/discovery/discovery-service.js +98 -0
  20. package/discovery/index.d.ts +2 -0
  21. package/discovery/index.js +5 -0
  22. package/errors/exception-handler.d.ts +4 -0
  23. package/errors/exception-handler.js +11 -0
  24. package/errors/exceptions/circular-dependency.exception.d.ts +4 -0
  25. package/errors/exceptions/circular-dependency.exception.js +11 -0
  26. package/errors/exceptions/index.d.ts +8 -0
  27. package/errors/exceptions/index.js +11 -0
  28. package/errors/exceptions/invalid-class-module.exception.d.ts +4 -0
  29. package/errors/exceptions/invalid-class-module.exception.js +11 -0
  30. package/errors/exceptions/invalid-class-scope.exception.d.ts +5 -0
  31. package/errors/exceptions/invalid-class-scope.exception.js +16 -0
  32. package/errors/exceptions/invalid-class.exception.d.ts +4 -0
  33. package/errors/exceptions/invalid-class.exception.js +11 -0
  34. package/errors/exceptions/invalid-exception-filter.exception.d.ts +4 -0
  35. package/errors/exceptions/invalid-exception-filter.exception.js +11 -0
  36. package/errors/exceptions/invalid-middleware-configuration.exception.d.ts +4 -0
  37. package/errors/exceptions/invalid-middleware-configuration.exception.js +11 -0
  38. package/errors/exceptions/invalid-middleware.exception.d.ts +4 -0
  39. package/errors/exceptions/invalid-middleware.exception.js +11 -0
  40. package/errors/exceptions/invalid-module.exception.d.ts +4 -0
  41. package/errors/exceptions/invalid-module.exception.js +11 -0
  42. package/errors/exceptions/runtime.exception.d.ts +4 -0
  43. package/errors/exceptions/runtime.exception.js +12 -0
  44. package/errors/exceptions/undefined-dependency.exception.d.ts +6 -0
  45. package/errors/exceptions/undefined-dependency.exception.js +11 -0
  46. package/errors/exceptions/undefined-forwardref.exception.d.ts +5 -0
  47. package/errors/exceptions/undefined-forwardref.exception.js +11 -0
  48. package/errors/exceptions/undefined-module.exception.d.ts +4 -0
  49. package/errors/exceptions/undefined-module.exception.js +11 -0
  50. package/errors/exceptions/unknown-dependencies.exception.d.ts +16 -0
  51. package/errors/exceptions/unknown-dependencies.exception.js +15 -0
  52. package/errors/exceptions/unknown-element.exception.d.ts +4 -0
  53. package/errors/exceptions/unknown-element.exception.js +11 -0
  54. package/errors/exceptions/unknown-export.exception.d.ts +4 -0
  55. package/errors/exceptions/unknown-export.exception.js +11 -0
  56. package/errors/exceptions/unknown-module.exception.d.ts +4 -0
  57. package/errors/exceptions/unknown-module.exception.js +10 -0
  58. package/errors/exceptions/unknown-request-mapping.exception.d.ts +5 -0
  59. package/errors/exceptions/unknown-request-mapping.exception.js +11 -0
  60. package/errors/exceptions-zone.d.ts +5 -0
  61. package/errors/exceptions-zone.js +34 -0
  62. package/errors/messages.d.ts +17 -0
  63. package/errors/messages.js +174 -0
  64. package/exceptions/base-exception-filter-context.d.ts +14 -0
  65. package/exceptions/base-exception-filter-context.js +56 -0
  66. package/exceptions/base-exception-filter.d.ts +20 -0
  67. package/exceptions/base-exception-filter.js +72 -0
  68. package/exceptions/exceptions-handler.d.ts +10 -0
  69. package/exceptions/exceptions-handler.js +34 -0
  70. package/exceptions/external-exception-filter-context.d.ts +12 -0
  71. package/exceptions/external-exception-filter-context.js +42 -0
  72. package/exceptions/external-exception-filter.d.ts +5 -0
  73. package/exceptions/external-exception-filter.js +15 -0
  74. package/exceptions/external-exceptions-handler.d.ts +9 -0
  75. package/exceptions/external-exceptions-handler.js +34 -0
  76. package/exceptions/index.d.ts +1 -0
  77. package/exceptions/index.js +4 -0
  78. package/guards/constants.d.ts +1 -0
  79. package/guards/constants.js +4 -0
  80. package/guards/guards-consumer.d.ts +9 -0
  81. package/guards/guards-consumer.js +39 -0
  82. package/guards/guards-context-creator.d.ts +17 -0
  83. package/guards/guards-context-creator.js +70 -0
  84. package/guards/index.d.ts +3 -0
  85. package/guards/index.js +6 -0
  86. package/helpers/barrier.d.ts +30 -0
  87. package/helpers/barrier.js +46 -0
  88. package/helpers/context-creator.d.ts +10 -0
  89. package/helpers/context-creator.js +33 -0
  90. package/helpers/context-id-factory.d.ts +41 -0
  91. package/helpers/context-id-factory.js +67 -0
  92. package/helpers/context-utils.d.ts +23 -0
  93. package/helpers/context-utils.js +55 -0
  94. package/helpers/execution-context-host.d.ts +19 -0
  95. package/helpers/execution-context-host.js +50 -0
  96. package/helpers/external-context-creator.d.ts +51 -0
  97. package/helpers/external-context-creator.js +166 -0
  98. package/helpers/external-proxy.d.ts +5 -0
  99. package/helpers/external-proxy.js +19 -0
  100. package/helpers/get-class-scope.d.ts +3 -0
  101. package/helpers/get-class-scope.js +8 -0
  102. package/helpers/handler-metadata-storage.d.ts +27 -0
  103. package/helpers/handler-metadata-storage.js +26 -0
  104. package/helpers/http-adapter-host.d.ts +51 -0
  105. package/helpers/http-adapter-host.js +73 -0
  106. package/helpers/index.d.ts +3 -0
  107. package/helpers/index.js +6 -0
  108. package/helpers/interfaces/external-handler-metadata.interface.d.ts +11 -0
  109. package/helpers/interfaces/external-handler-metadata.interface.js +2 -0
  110. package/helpers/interfaces/index.d.ts +2 -0
  111. package/helpers/interfaces/index.js +5 -0
  112. package/helpers/interfaces/params-metadata.interface.d.ts +6 -0
  113. package/helpers/interfaces/params-metadata.interface.js +2 -0
  114. package/helpers/is-durable.d.ts +2 -0
  115. package/helpers/is-durable.js +8 -0
  116. package/helpers/load-adapter.d.ts +1 -0
  117. package/helpers/load-adapter.js +15 -0
  118. package/helpers/messages.d.ts +7 -0
  119. package/helpers/messages.js +29 -0
  120. package/helpers/optional-require.d.ts +1 -0
  121. package/helpers/optional-require.js +11 -0
  122. package/helpers/rethrow.d.ts +1 -0
  123. package/helpers/rethrow.js +7 -0
  124. package/helpers/router-method-factory.d.ts +23 -0
  125. package/helpers/router-method-factory.js +33 -0
  126. package/hooks/before-app-shutdown.hook.d.ts +9 -0
  127. package/hooks/before-app-shutdown.hook.js +51 -0
  128. package/hooks/index.d.ts +5 -0
  129. package/hooks/index.js +8 -0
  130. package/hooks/on-app-bootstrap.hook.d.ts +8 -0
  131. package/hooks/on-app-bootstrap.hook.js +53 -0
  132. package/hooks/on-app-shutdown.hook.d.ts +9 -0
  133. package/hooks/on-app-shutdown.hook.js +54 -0
  134. package/hooks/on-module-destroy.hook.d.ts +8 -0
  135. package/hooks/on-module-destroy.hook.js +53 -0
  136. package/hooks/on-module-init.hook.d.ts +8 -0
  137. package/hooks/on-module-init.hook.js +53 -0
  138. package/hooks/utils/get-instances-grouped-by-hierarchy-level.d.ts +3 -0
  139. package/hooks/utils/get-instances-grouped-by-hierarchy-level.js +27 -0
  140. package/hooks/utils/get-sorted-hierarchy-levels.d.ts +1 -0
  141. package/hooks/utils/get-sorted-hierarchy-levels.js +7 -0
  142. package/index.d.ts +17 -0
  143. package/index.js +32 -0
  144. package/injector/abstract-instance-resolver.d.ts +16 -0
  145. package/injector/abstract-instance-resolver.js +49 -0
  146. package/injector/compiler.d.ts +18 -0
  147. package/injector/compiler.js +35 -0
  148. package/injector/constants.d.ts +3 -0
  149. package/injector/constants.js +8 -0
  150. package/injector/container.d.ts +67 -0
  151. package/injector/container.js +233 -0
  152. package/injector/helpers/provider-classifier.d.ts +4 -0
  153. package/injector/helpers/provider-classifier.js +16 -0
  154. package/injector/helpers/silent-logger.d.ts +10 -0
  155. package/injector/helpers/silent-logger.js +18 -0
  156. package/injector/helpers/transient-instances.d.ts +12 -0
  157. package/injector/helpers/transient-instances.js +28 -0
  158. package/injector/index.d.ts +6 -0
  159. package/injector/index.js +8 -0
  160. package/injector/injector.d.ts +104 -0
  161. package/injector/injector.js +554 -0
  162. package/injector/inquirer/index.d.ts +1 -0
  163. package/injector/inquirer/index.js +4 -0
  164. package/injector/inquirer/inquirer-constants.d.ts +1 -0
  165. package/injector/inquirer/inquirer-constants.js +4 -0
  166. package/injector/inquirer/inquirer-providers.d.ts +2 -0
  167. package/injector/inquirer/inquirer-providers.js +11 -0
  168. package/injector/instance-links-host.d.ts +22 -0
  169. package/injector/instance-links-host.js +56 -0
  170. package/injector/instance-loader.d.ts +23 -0
  171. package/injector/instance-loader.js +88 -0
  172. package/injector/instance-wrapper.d.ts +99 -0
  173. package/injector/instance-wrapper.js +350 -0
  174. package/injector/internal-core-module/index.d.ts +1 -0
  175. package/injector/internal-core-module/index.js +4 -0
  176. package/injector/internal-core-module/internal-core-module-factory.d.ts +9 -0
  177. package/injector/internal-core-module/internal-core-module-factory.js +52 -0
  178. package/injector/internal-core-module/internal-core-module.d.ts +5 -0
  179. package/injector/internal-core-module/internal-core-module.js +40 -0
  180. package/injector/internal-providers-storage.d.ts +9 -0
  181. package/injector/internal-providers-storage.js +19 -0
  182. package/injector/lazy-module-loader/lazy-module-loader-options.interface.d.ts +6 -0
  183. package/injector/lazy-module-loader/lazy-module-loader-options.interface.js +2 -0
  184. package/injector/lazy-module-loader/lazy-module-loader.d.ts +20 -0
  185. package/injector/lazy-module-loader/lazy-module-loader.js +49 -0
  186. package/injector/module-ref.d.ts +106 -0
  187. package/injector/module-ref.js +66 -0
  188. package/injector/module.d.ts +82 -0
  189. package/injector/module.js +432 -0
  190. package/injector/modules-container.d.ts +27 -0
  191. package/injector/modules-container.js +42 -0
  192. package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.d.ts +15 -0
  193. package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.js +41 -0
  194. package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.d.ts +15 -0
  195. package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.js +83 -0
  196. package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.d.ts +18 -0
  197. package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.js +2 -0
  198. package/injector/settlement-signal.d.ts +37 -0
  199. package/injector/settlement-signal.js +55 -0
  200. package/injector/topology-tree/topology-tree.d.ts +8 -0
  201. package/injector/topology-tree/topology-tree.js +51 -0
  202. package/injector/topology-tree/tree-node.d.ts +14 -0
  203. package/injector/topology-tree/tree-node.js +54 -0
  204. package/inspector/deterministic-uuid-registry.d.ts +6 -0
  205. package/inspector/deterministic-uuid-registry.js +24 -0
  206. package/inspector/graph-inspector.d.ts +26 -0
  207. package/inspector/graph-inspector.js +166 -0
  208. package/inspector/index.d.ts +4 -0
  209. package/inspector/index.js +7 -0
  210. package/inspector/initialize-on-preview.allowlist.d.ts +6 -0
  211. package/inspector/initialize-on-preview.allowlist.js +13 -0
  212. package/inspector/interfaces/edge.interface.d.ts +28 -0
  213. package/inspector/interfaces/edge.interface.js +2 -0
  214. package/inspector/interfaces/enhancer-metadata-cache-entry.interface.d.ts +12 -0
  215. package/inspector/interfaces/enhancer-metadata-cache-entry.interface.js +2 -0
  216. package/inspector/interfaces/entrypoint.interface.d.ts +23 -0
  217. package/inspector/interfaces/entrypoint.interface.js +2 -0
  218. package/inspector/interfaces/extras.interface.d.ts +18 -0
  219. package/inspector/interfaces/extras.interface.js +2 -0
  220. package/inspector/interfaces/node.interface.d.ts +48 -0
  221. package/inspector/interfaces/node.interface.js +2 -0
  222. package/inspector/interfaces/serialized-graph-json.interface.d.ts +14 -0
  223. package/inspector/interfaces/serialized-graph-json.interface.js +2 -0
  224. package/inspector/interfaces/serialized-graph-metadata.interface.d.ts +10 -0
  225. package/inspector/interfaces/serialized-graph-metadata.interface.js +2 -0
  226. package/inspector/noop-graph-inspector.d.ts +2 -0
  227. package/inspector/noop-graph-inspector.js +8 -0
  228. package/inspector/partial-graph.host.d.ts +7 -0
  229. package/inspector/partial-graph.host.js +15 -0
  230. package/inspector/serialized-graph.d.ts +52 -0
  231. package/inspector/serialized-graph.js +124 -0
  232. package/inspector/uuid-factory.d.ts +9 -0
  233. package/inspector/uuid-factory.js +22 -0
  234. package/interceptors/index.d.ts +2 -0
  235. package/interceptors/index.js +5 -0
  236. package/interceptors/interceptors-consumer.d.ts +9 -0
  237. package/interceptors/interceptors-consumer.js +37 -0
  238. package/interceptors/interceptors-context-creator.d.ts +16 -0
  239. package/interceptors/interceptors-context-creator.js +69 -0
  240. package/interfaces/index.d.ts +2 -0
  241. package/interfaces/index.js +2 -0
  242. package/interfaces/module-definition.interface.d.ts +3 -0
  243. package/interfaces/module-definition.interface.js +2 -0
  244. package/interfaces/module-override.interface.d.ts +5 -0
  245. package/interfaces/module-override.interface.js +2 -0
  246. package/internal.d.ts +38 -0
  247. package/internal.js +46 -0
  248. package/metadata-scanner.d.ts +17 -0
  249. package/metadata-scanner.js +83 -0
  250. package/middleware/builder.d.ts +15 -0
  251. package/middleware/builder.js +91 -0
  252. package/middleware/container.d.ts +14 -0
  253. package/middleware/container.js +49 -0
  254. package/middleware/index.d.ts +1 -0
  255. package/middleware/index.js +4 -0
  256. package/middleware/middleware-module.d.ts +33 -0
  257. package/middleware/middleware-module.js +208 -0
  258. package/middleware/resolver.d.ts +10 -0
  259. package/middleware/resolver.js +18 -0
  260. package/middleware/route-info-path-extractor.d.ts +15 -0
  261. package/middleware/route-info-path-extractor.js +81 -0
  262. package/middleware/routes-mapper.d.ts +19 -0
  263. package/middleware/routes-mapper.js +117 -0
  264. package/middleware/utils.d.ts +8 -0
  265. package/middleware/utils.js +106 -0
  266. package/nest-application-context.d.ts +173 -0
  267. package/nest-application-context.js +327 -0
  268. package/nest-application.d.ts +64 -0
  269. package/nest-application.js +328 -0
  270. package/nest-factory.d.ts +83 -0
  271. package/nest-factory.js +232 -0
  272. package/package.json +73 -0
  273. package/pipes/index.d.ts +3 -0
  274. package/pipes/index.js +6 -0
  275. package/pipes/params-token-factory.d.ts +5 -0
  276. package/pipes/params-token-factory.js +19 -0
  277. package/pipes/pipes-consumer.d.ts +10 -0
  278. package/pipes/pipes-consumer.js +21 -0
  279. package/pipes/pipes-context-creator.d.ts +17 -0
  280. package/pipes/pipes-context-creator.js +72 -0
  281. package/repl/assign-to-object.util.d.ts +5 -0
  282. package/repl/assign-to-object.util.js +14 -0
  283. package/repl/constants.d.ts +1 -0
  284. package/repl/constants.js +4 -0
  285. package/repl/index.d.ts +1 -0
  286. package/repl/index.js +4 -0
  287. package/repl/native-functions/debug-repl-fn.d.ts +9 -0
  288. package/repl/native-functions/debug-repl-fn.js +46 -0
  289. package/repl/native-functions/get-repl-fn.d.ts +7 -0
  290. package/repl/native-functions/get-repl-fn.js +19 -0
  291. package/repl/native-functions/help-repl-fn.d.ts +7 -0
  292. package/repl/native-functions/help-repl-fn.js +29 -0
  293. package/repl/native-functions/index.d.ts +6 -0
  294. package/repl/native-functions/index.js +9 -0
  295. package/repl/native-functions/methods-repl-fn.d.ts +8 -0
  296. package/repl/native-functions/methods-repl-fn.js +28 -0
  297. package/repl/native-functions/resolve-repl-fn.d.ts +7 -0
  298. package/repl/native-functions/resolve-repl-fn.js +18 -0
  299. package/repl/native-functions/select-relp-fn.d.ts +7 -0
  300. package/repl/native-functions/select-relp-fn.js +18 -0
  301. package/repl/repl-context.d.ts +26 -0
  302. package/repl/repl-context.js +126 -0
  303. package/repl/repl-function.d.ts +18 -0
  304. package/repl/repl-function.js +19 -0
  305. package/repl/repl-logger.d.ts +5 -0
  306. package/repl/repl-logger.js +22 -0
  307. package/repl/repl-native-commands.d.ts +2 -0
  308. package/repl/repl-native-commands.js +46 -0
  309. package/repl/repl.d.ts +3 -0
  310. package/repl/repl.interfaces.d.ts +16 -0
  311. package/repl/repl.interfaces.js +2 -0
  312. package/repl/repl.js +32 -0
  313. package/router/index.d.ts +3 -0
  314. package/router/index.js +8 -0
  315. package/router/interfaces/exceptions-filter.interface.d.ts +6 -0
  316. package/router/interfaces/exceptions-filter.interface.js +2 -0
  317. package/router/interfaces/exclude-route-metadata.interface.d.ts +15 -0
  318. package/router/interfaces/exclude-route-metadata.interface.js +2 -0
  319. package/router/interfaces/index.d.ts +1 -0
  320. package/router/interfaces/index.js +4 -0
  321. package/router/interfaces/resolver.interface.d.ts +5 -0
  322. package/router/interfaces/resolver.interface.js +2 -0
  323. package/router/interfaces/route-params-factory.interface.d.ts +8 -0
  324. package/router/interfaces/route-params-factory.interface.js +2 -0
  325. package/router/interfaces/route-path-metadata.interface.d.ts +32 -0
  326. package/router/interfaces/route-path-metadata.interface.js +2 -0
  327. package/router/interfaces/routes.interface.d.ts +7 -0
  328. package/router/interfaces/routes.interface.js +2 -0
  329. package/router/legacy-route-converter.d.ts +16 -0
  330. package/router/legacy-route-converter.js +61 -0
  331. package/router/paths-explorer.d.ts +18 -0
  332. package/router/paths-explorer.js +45 -0
  333. package/router/request/index.d.ts +1 -0
  334. package/router/request/index.js +5 -0
  335. package/router/request/request-constants.d.ts +2 -0
  336. package/router/request/request-constants.js +5 -0
  337. package/router/request/request-providers.d.ts +2 -0
  338. package/router/request/request-providers.js +11 -0
  339. package/router/route-params-factory.d.ts +9 -0
  340. package/router/route-params-factory.js +41 -0
  341. package/router/route-path-factory.d.ts +14 -0
  342. package/router/route-path-factory.js +101 -0
  343. package/router/router-exception-filters.d.ts +14 -0
  344. package/router/router-exception-filters.js +40 -0
  345. package/router/router-execution-context.d.ts +54 -0
  346. package/router/router-execution-context.js +186 -0
  347. package/router/router-explorer.d.ts +47 -0
  348. package/router/router-explorer.js +234 -0
  349. package/router/router-module.d.ts +19 -0
  350. package/router/router-module.js +80 -0
  351. package/router/router-proxy.d.ts +6 -0
  352. package/router/router-proxy.js +31 -0
  353. package/router/router-response-controller.d.ts +28 -0
  354. package/router/router-response-controller.js +98 -0
  355. package/router/routes-resolver.d.ts +27 -0
  356. package/router/routes-resolver.js +129 -0
  357. package/router/sse-stream.d.ts +43 -0
  358. package/router/sse-stream.js +83 -0
  359. package/router/utils/exclude-route.util.d.ts +4 -0
  360. package/router/utils/exclude-route.util.js +19 -0
  361. package/router/utils/flatten-route-paths.util.d.ts +6 -0
  362. package/router/utils/flatten-route-paths.util.js +25 -0
  363. package/router/utils/index.d.ts +2 -0
  364. package/router/utils/index.js +5 -0
  365. package/scanner.d.ts +89 -0
  366. package/scanner.js +416 -0
  367. package/services/index.d.ts +1 -0
  368. package/services/index.js +4 -0
  369. package/services/reflector.service.d.ts +111 -0
  370. package/services/reflector.service.js +100 -0
  371. package/tsconfig.build.json +21 -0
@@ -0,0 +1,554 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Injector = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const constants_1 = require("@nestjs/common/constants");
6
+ const cli_colors_util_1 = require("@nestjs/common/utils/cli-colors.util");
7
+ const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
8
+ const iterare_1 = require("iterare");
9
+ const perf_hooks_1 = require("perf_hooks");
10
+ const exceptions_1 = require("../errors/exceptions");
11
+ const runtime_exception_1 = require("../errors/exceptions/runtime.exception");
12
+ const undefined_dependency_exception_1 = require("../errors/exceptions/undefined-dependency.exception");
13
+ const unknown_dependencies_exception_1 = require("../errors/exceptions/unknown-dependencies.exception");
14
+ const barrier_1 = require("../helpers/barrier");
15
+ const constants_2 = require("./constants");
16
+ const inquirer_1 = require("./inquirer");
17
+ const instance_wrapper_1 = require("./instance-wrapper");
18
+ const settlement_signal_1 = require("./settlement-signal");
19
+ class Injector {
20
+ constructor(options) {
21
+ this.options = options;
22
+ this.logger = new common_1.Logger('InjectorLogger');
23
+ this.instanceDecorator = (target) => target;
24
+ if (options?.instanceDecorator) {
25
+ this.instanceDecorator = options.instanceDecorator;
26
+ }
27
+ }
28
+ loadPrototype({ token }, collection, contextId = constants_2.STATIC_CONTEXT) {
29
+ if (!collection) {
30
+ return;
31
+ }
32
+ const target = collection.get(token);
33
+ const instance = target.createPrototype(contextId);
34
+ if (instance) {
35
+ const wrapper = new instance_wrapper_1.InstanceWrapper({
36
+ ...target,
37
+ instance,
38
+ });
39
+ collection.set(token, wrapper);
40
+ }
41
+ }
42
+ async loadInstance(wrapper, collection, moduleRef, contextId = constants_2.STATIC_CONTEXT, inquirer) {
43
+ const inquirerId = this.getInquirerId(inquirer);
44
+ const instanceHost = wrapper.getInstanceByContextId(this.getContextId(contextId, wrapper), inquirerId);
45
+ if (instanceHost.isPending) {
46
+ const settlementSignal = wrapper.settlementSignal;
47
+ if (inquirer && settlementSignal?.isCycle(inquirer.id)) {
48
+ throw new exceptions_1.CircularDependencyException(`"${wrapper.name}"`);
49
+ }
50
+ return instanceHost.donePromise.then((err) => {
51
+ if (err) {
52
+ throw err;
53
+ }
54
+ });
55
+ }
56
+ const settlementSignal = this.applySettlementSignal(instanceHost, wrapper);
57
+ const token = wrapper.token || wrapper.name;
58
+ const { inject } = wrapper;
59
+ const targetWrapper = collection.get(token);
60
+ if ((0, shared_utils_1.isUndefined)(targetWrapper)) {
61
+ throw new runtime_exception_1.RuntimeException();
62
+ }
63
+ if (instanceHost.isResolved) {
64
+ return settlementSignal.complete();
65
+ }
66
+ try {
67
+ const t0 = this.getNowTimestamp();
68
+ const callback = async (instances) => {
69
+ const properties = await this.resolveProperties(wrapper, moduleRef, inject, contextId, wrapper, inquirer);
70
+ const instance = await this.instantiateClass(instances, wrapper, targetWrapper, contextId, inquirer);
71
+ this.applyProperties(instance, properties);
72
+ wrapper.initTime = this.getNowTimestamp() - t0;
73
+ settlementSignal.complete();
74
+ };
75
+ await this.resolveConstructorParams(wrapper, moduleRef, inject, callback, contextId, wrapper, inquirer);
76
+ }
77
+ catch (err) {
78
+ wrapper.removeInstanceByContextId(this.getContextId(contextId, wrapper), inquirerId);
79
+ settlementSignal.error(err);
80
+ throw err;
81
+ }
82
+ }
83
+ async loadMiddleware(wrapper, collection, moduleRef, contextId = constants_2.STATIC_CONTEXT, inquirer) {
84
+ const { metatype, token } = wrapper;
85
+ const targetWrapper = collection.get(token);
86
+ if (!(0, shared_utils_1.isUndefined)(targetWrapper.instance)) {
87
+ return;
88
+ }
89
+ targetWrapper.instance = Object.create(metatype.prototype);
90
+ await this.loadInstance(wrapper, collection, moduleRef, contextId, inquirer || wrapper);
91
+ }
92
+ async loadController(wrapper, moduleRef, contextId = constants_2.STATIC_CONTEXT) {
93
+ const controllers = moduleRef.controllers;
94
+ await this.loadInstance(wrapper, controllers, moduleRef, contextId, wrapper);
95
+ await this.loadEnhancersPerContext(wrapper, contextId, wrapper);
96
+ }
97
+ async loadInjectable(wrapper, moduleRef, contextId = constants_2.STATIC_CONTEXT, inquirer) {
98
+ const injectables = moduleRef.injectables;
99
+ await this.loadInstance(wrapper, injectables, moduleRef, contextId, inquirer);
100
+ }
101
+ async loadProvider(wrapper, moduleRef, contextId = constants_2.STATIC_CONTEXT, inquirer) {
102
+ const providers = moduleRef.providers;
103
+ await this.loadInstance(wrapper, providers, moduleRef, contextId, inquirer);
104
+ await this.loadEnhancersPerContext(wrapper, contextId, wrapper);
105
+ }
106
+ applySettlementSignal(instancePerContext, host) {
107
+ const settlementSignal = new settlement_signal_1.SettlementSignal();
108
+ instancePerContext.donePromise = settlementSignal.asPromise();
109
+ instancePerContext.isPending = true;
110
+ host.settlementSignal = settlementSignal;
111
+ return settlementSignal;
112
+ }
113
+ async resolveConstructorParams(wrapper, moduleRef, inject, callback, contextId = constants_2.STATIC_CONTEXT, inquirer, parentInquirer) {
114
+ const metadata = wrapper.getCtorMetadata();
115
+ if (metadata && contextId !== constants_2.STATIC_CONTEXT) {
116
+ const deps = await this.loadCtorMetadata(metadata, contextId, inquirer, parentInquirer);
117
+ return callback(deps);
118
+ }
119
+ const isFactoryProvider = !(0, shared_utils_1.isNil)(inject);
120
+ const [dependencies, optionalDependenciesIds] = isFactoryProvider
121
+ ? this.getFactoryProviderDependencies(wrapper)
122
+ : this.getClassDependencies(wrapper);
123
+ const paramBarrier = new barrier_1.Barrier(dependencies.length);
124
+ let isResolved = true;
125
+ const resolveParam = async (param, index) => {
126
+ try {
127
+ if (this.isInquirer(param, parentInquirer)) {
128
+ /*
129
+ * Signal the barrier to make sure other dependencies do not get stuck waiting forever.
130
+ */
131
+ paramBarrier.signal();
132
+ return parentInquirer && parentInquirer.instance;
133
+ }
134
+ if (inquirer?.isTransient && parentInquirer) {
135
+ // When `inquirer` is transient too, inherit the parent inquirer
136
+ // This is required to ensure that transient providers are only resolved
137
+ // when requested
138
+ inquirer.attachRootInquirer(parentInquirer);
139
+ }
140
+ const paramWrapper = await this.resolveSingleParam(wrapper, param, { index, dependencies }, moduleRef, contextId, inquirer, index);
141
+ /*
142
+ * Ensure that all instance wrappers are resolved at this point before we continue.
143
+ * Otherwise the staticity of `wrapper`'s dependency tree may be evaluated incorrectly
144
+ * and result in undefined / null injection.
145
+ */
146
+ await paramBarrier.signalAndWait();
147
+ const effectiveInquirer = this.getEffectiveInquirer(paramWrapper, inquirer, parentInquirer, contextId);
148
+ const paramWrapperWithInstance = await this.resolveComponentHost(moduleRef, paramWrapper, contextId, effectiveInquirer);
149
+ const instanceHost = paramWrapperWithInstance.getInstanceByContextId(this.getContextId(contextId, paramWrapperWithInstance), this.getInquirerId(effectiveInquirer));
150
+ if (!instanceHost.isResolved && !paramWrapperWithInstance.forwardRef) {
151
+ isResolved = false;
152
+ }
153
+ return instanceHost?.instance;
154
+ }
155
+ catch (err) {
156
+ /*
157
+ * Signal the barrier to make sure other dependencies do not get stuck waiting forever. We
158
+ * do not care if this occurs after `Barrier.signalAndWait()` is called in the `try` block
159
+ * because the barrier will always have been resolved by then.
160
+ */
161
+ paramBarrier.signal();
162
+ const isOptional = optionalDependenciesIds.includes(index);
163
+ if (!isOptional) {
164
+ throw err;
165
+ }
166
+ return undefined;
167
+ }
168
+ };
169
+ const instances = await Promise.all(dependencies.map(resolveParam));
170
+ isResolved && (await callback(instances));
171
+ }
172
+ getClassDependencies(wrapper) {
173
+ const ctorRef = wrapper.metatype;
174
+ return [
175
+ this.reflectConstructorParams(ctorRef),
176
+ this.reflectOptionalParams(ctorRef),
177
+ ];
178
+ }
179
+ getFactoryProviderDependencies(wrapper) {
180
+ const optionalDependenciesIds = [];
181
+ /**
182
+ * Same as the internal utility function `isOptionalFactoryDependency` from `@nestjs/common`.
183
+ * We are duplicating it here because that one is not supposed to be exported.
184
+ */
185
+ function isOptionalFactoryDependency(value) {
186
+ return (!(0, shared_utils_1.isUndefined)(value.token) &&
187
+ !(0, shared_utils_1.isUndefined)(value.optional) &&
188
+ !value.prototype);
189
+ }
190
+ const mapFactoryProviderInjectArray = (item, index) => {
191
+ if (typeof item !== 'object') {
192
+ return item;
193
+ }
194
+ if (isOptionalFactoryDependency(item)) {
195
+ if (item.optional) {
196
+ optionalDependenciesIds.push(index);
197
+ }
198
+ return item?.token;
199
+ }
200
+ return item;
201
+ };
202
+ return [
203
+ wrapper.inject?.map?.(mapFactoryProviderInjectArray),
204
+ optionalDependenciesIds,
205
+ ];
206
+ }
207
+ reflectConstructorParams(type) {
208
+ const paramtypes = [
209
+ ...(Reflect.getMetadata(constants_1.PARAMTYPES_METADATA, type) || []),
210
+ ];
211
+ const selfParams = this.reflectSelfParams(type);
212
+ selfParams.forEach(({ index, param }) => (paramtypes[index] = param));
213
+ return paramtypes;
214
+ }
215
+ reflectOptionalParams(type) {
216
+ return Reflect.getMetadata(constants_1.OPTIONAL_DEPS_METADATA, type) || [];
217
+ }
218
+ reflectSelfParams(type) {
219
+ return Reflect.getMetadata(constants_1.SELF_DECLARED_DEPS_METADATA, type) || [];
220
+ }
221
+ async resolveSingleParam(wrapper, param, dependencyContext, moduleRef, contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex) {
222
+ if ((0, shared_utils_1.isUndefined)(param)) {
223
+ this.logger.log('Nest encountered an undefined dependency. This may be due to a circular import or a missing dependency declaration.');
224
+ throw new undefined_dependency_exception_1.UndefinedDependencyException(wrapper.name, dependencyContext, moduleRef);
225
+ }
226
+ const token = this.resolveParamToken(wrapper, param);
227
+ return this.resolveComponentWrapper(moduleRef, token, dependencyContext, wrapper, contextId, inquirer, keyOrIndex);
228
+ }
229
+ resolveParamToken(wrapper, param) {
230
+ if (typeof param === 'object' && 'forwardRef' in param) {
231
+ wrapper.forwardRef = true;
232
+ return param.forwardRef();
233
+ }
234
+ return param;
235
+ }
236
+ async resolveComponentWrapper(moduleRef, token, dependencyContext, wrapper, contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex) {
237
+ this.printResolvingDependenciesLog(token, inquirer);
238
+ this.printLookingForProviderLog(token, moduleRef);
239
+ const providers = moduleRef.providers;
240
+ return this.lookupComponent(providers, moduleRef, { ...dependencyContext, name: token }, wrapper, contextId, inquirer, keyOrIndex);
241
+ }
242
+ async resolveComponentHost(moduleRef, instanceWrapper, contextId = constants_2.STATIC_CONTEXT, inquirer) {
243
+ const inquirerId = this.getInquirerId(inquirer);
244
+ const instanceHost = instanceWrapper.getInstanceByContextId(this.getContextId(contextId, instanceWrapper), inquirerId);
245
+ if (!instanceHost.isResolved && !instanceWrapper.forwardRef) {
246
+ inquirer?.settlementSignal?.insertRef(instanceWrapper.id);
247
+ await this.loadProvider(instanceWrapper, instanceWrapper.host ?? moduleRef, contextId, inquirer);
248
+ }
249
+ else if (!instanceHost.isResolved &&
250
+ instanceWrapper.forwardRef &&
251
+ (contextId !== constants_2.STATIC_CONTEXT || !!inquirerId)) {
252
+ /**
253
+ * When circular dependency has been detected between
254
+ * either request/transient providers, we have to asynchronously
255
+ * resolve instance host for a specific contextId or inquirer, to ensure
256
+ * that eventual lazily created instance will be merged with the prototype
257
+ * instantiated beforehand.
258
+ */
259
+ instanceHost.donePromise &&
260
+ void instanceHost.donePromise
261
+ .then(() => this.loadProvider(instanceWrapper, moduleRef, contextId, inquirer))
262
+ .catch(err => {
263
+ instanceWrapper.settlementSignal?.error(err);
264
+ });
265
+ }
266
+ if (instanceWrapper.async) {
267
+ const host = instanceWrapper.getInstanceByContextId(this.getContextId(contextId, instanceWrapper), inquirerId);
268
+ host.instance = await host.instance;
269
+ instanceWrapper.setInstanceByContextId(contextId, host, inquirerId);
270
+ }
271
+ return instanceWrapper;
272
+ }
273
+ async lookupComponent(providers, moduleRef, dependencyContext, wrapper, contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex) {
274
+ const token = wrapper.token || wrapper.name;
275
+ const { name } = dependencyContext;
276
+ if (wrapper && token === name) {
277
+ throw new unknown_dependencies_exception_1.UnknownDependenciesException(wrapper.name, dependencyContext, moduleRef, { id: wrapper.id });
278
+ }
279
+ if (name && providers.has(name)) {
280
+ const instanceWrapper = providers.get(name);
281
+ this.printFoundInModuleLog(name, moduleRef);
282
+ this.addDependencyMetadata(keyOrIndex, wrapper, instanceWrapper);
283
+ return instanceWrapper;
284
+ }
285
+ return this.lookupComponentInParentModules(dependencyContext, moduleRef, wrapper, contextId, inquirer, keyOrIndex);
286
+ }
287
+ async lookupComponentInParentModules(dependencyContext, moduleRef, wrapper, contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex) {
288
+ const instanceWrapper = await this.lookupComponentInImports(moduleRef, dependencyContext.name, wrapper, new Set(), contextId, inquirer, keyOrIndex);
289
+ if ((0, shared_utils_1.isNil)(instanceWrapper)) {
290
+ throw new unknown_dependencies_exception_1.UnknownDependenciesException(wrapper.name, dependencyContext, moduleRef, { id: wrapper.id });
291
+ }
292
+ return instanceWrapper;
293
+ }
294
+ async lookupComponentInImports(moduleRef, name, wrapper, moduleRegistry = new Set(), contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex, isTraversing) {
295
+ let instanceWrapperRef = null;
296
+ const imports = moduleRef.imports || new Set();
297
+ const identity = (item) => item;
298
+ let children = [...imports.values()].filter(identity);
299
+ if (isTraversing) {
300
+ const contextModuleExports = moduleRef.exports;
301
+ children = children.filter(child => contextModuleExports.has(child.metatype));
302
+ }
303
+ for (const relatedModule of children) {
304
+ if (moduleRegistry.has(relatedModule.id)) {
305
+ continue;
306
+ }
307
+ this.printLookingForProviderLog(name, relatedModule);
308
+ moduleRegistry.add(relatedModule.id);
309
+ const { providers, exports } = relatedModule;
310
+ if (!exports.has(name) || !providers.has(name)) {
311
+ const instanceRef = await this.lookupComponentInImports(relatedModule, name, wrapper, moduleRegistry, contextId, inquirer, keyOrIndex, true);
312
+ if (instanceRef) {
313
+ this.addDependencyMetadata(keyOrIndex, wrapper, instanceRef);
314
+ return instanceRef;
315
+ }
316
+ continue;
317
+ }
318
+ this.printFoundInModuleLog(name, relatedModule);
319
+ instanceWrapperRef = providers.get(name);
320
+ this.addDependencyMetadata(keyOrIndex, wrapper, instanceWrapperRef);
321
+ const inquirerId = this.getInquirerId(inquirer);
322
+ const instanceHost = instanceWrapperRef.getInstanceByContextId(this.getContextId(contextId, instanceWrapperRef), inquirerId);
323
+ if (!instanceHost.isResolved && !instanceWrapperRef.forwardRef) {
324
+ /*
325
+ * Provider will be loaded shortly in resolveComponentHost() once we pass the current
326
+ * Barrier. We cannot load it here because doing so could incorrectly evaluate the
327
+ * staticity of the dependency tree and lead to undefined / null injection.
328
+ */
329
+ break;
330
+ }
331
+ }
332
+ return instanceWrapperRef;
333
+ }
334
+ async resolveProperties(wrapper, moduleRef, inject, contextId = constants_2.STATIC_CONTEXT, inquirer, parentInquirer) {
335
+ if (!(0, shared_utils_1.isNil)(inject)) {
336
+ return [];
337
+ }
338
+ const metadata = wrapper.getPropertiesMetadata();
339
+ if (metadata && contextId !== constants_2.STATIC_CONTEXT) {
340
+ return this.loadPropertiesMetadata(metadata, contextId, inquirer);
341
+ }
342
+ const properties = this.reflectProperties(wrapper.metatype);
343
+ const propertyBarrier = new barrier_1.Barrier(properties.length);
344
+ const instances = await Promise.all(properties.map(async (item) => {
345
+ try {
346
+ const dependencyContext = {
347
+ key: item.key,
348
+ name: item.name,
349
+ };
350
+ if (this.isInquirer(item.name, parentInquirer)) {
351
+ /*
352
+ * Signal the barrier to make sure other dependencies do not get stuck waiting forever.
353
+ */
354
+ propertyBarrier.signal();
355
+ return parentInquirer && parentInquirer.instance;
356
+ }
357
+ const paramWrapper = await this.resolveSingleParam(wrapper, item.name, dependencyContext, moduleRef, contextId, inquirer, item.key);
358
+ /*
359
+ * Ensure that all instance wrappers are resolved at this point before we continue.
360
+ * Otherwise the staticity of `wrapper`'s dependency tree may be evaluated incorrectly
361
+ * and result in undefined / null injection.
362
+ */
363
+ await propertyBarrier.signalAndWait();
364
+ const effectivePropertyInquirer = this.getEffectiveInquirer(paramWrapper, inquirer, parentInquirer, contextId);
365
+ const paramWrapperWithInstance = await this.resolveComponentHost(moduleRef, paramWrapper, contextId, effectivePropertyInquirer);
366
+ if (!paramWrapperWithInstance) {
367
+ return undefined;
368
+ }
369
+ const instanceHost = paramWrapperWithInstance.getInstanceByContextId(this.getContextId(contextId, paramWrapperWithInstance), this.getInquirerId(effectivePropertyInquirer));
370
+ return instanceHost.instance;
371
+ }
372
+ catch (err) {
373
+ /*
374
+ * Signal the barrier to make sure other dependencies do not get stuck waiting forever. We
375
+ * do not care if this occurs after `Barrier.signalAndWait()` is called in the `try` block
376
+ * because the barrier will always have been resolved by then.
377
+ */
378
+ propertyBarrier.signal();
379
+ if (!item.isOptional) {
380
+ throw err;
381
+ }
382
+ return undefined;
383
+ }
384
+ }));
385
+ return properties.map((item, index) => ({
386
+ ...item,
387
+ instance: instances[index],
388
+ }));
389
+ }
390
+ reflectProperties(type) {
391
+ const properties = Reflect.getMetadata(constants_1.PROPERTY_DEPS_METADATA, type) || [];
392
+ const optionalKeys = Reflect.getMetadata(constants_1.OPTIONAL_PROPERTY_DEPS_METADATA, type) || [];
393
+ return properties.map((item) => ({
394
+ ...item,
395
+ name: item.type,
396
+ isOptional: optionalKeys.includes(item.key),
397
+ }));
398
+ }
399
+ applyProperties(instance, properties) {
400
+ if (!(0, shared_utils_1.isObject)(instance)) {
401
+ return undefined;
402
+ }
403
+ (0, iterare_1.iterate)(properties)
404
+ .filter(item => !(0, shared_utils_1.isNil)(item.instance))
405
+ .forEach(item => (instance[item.key] = item.instance));
406
+ }
407
+ async instantiateClass(instances, wrapper, targetMetatype, contextId = constants_2.STATIC_CONTEXT, inquirer) {
408
+ const { metatype, inject } = wrapper;
409
+ const inquirerId = this.getInquirerId(inquirer);
410
+ const instanceHost = targetMetatype.getInstanceByContextId(this.getContextId(contextId, targetMetatype), inquirerId);
411
+ const isInContext = wrapper.isStatic(contextId, inquirer) ||
412
+ wrapper.isInRequestScope(contextId, inquirer) ||
413
+ wrapper.isLazyTransient(contextId, inquirer) ||
414
+ wrapper.isExplicitlyRequested(contextId, inquirer);
415
+ if (this.options?.preview && !wrapper.host?.initOnPreview) {
416
+ instanceHost.isResolved = true;
417
+ return instanceHost.instance;
418
+ }
419
+ if ((0, shared_utils_1.isNil)(inject) && isInContext) {
420
+ instanceHost.instance = wrapper.forwardRef
421
+ ? Object.assign(instanceHost.instance, new metatype(...instances))
422
+ : new metatype(...instances);
423
+ instanceHost.instance = this.instanceDecorator(instanceHost.instance);
424
+ instanceHost.isConstructorCalled = true;
425
+ }
426
+ else if (isInContext) {
427
+ const factoryReturnValue = targetMetatype.metatype(...instances);
428
+ instanceHost.instance = await factoryReturnValue;
429
+ instanceHost.instance = this.instanceDecorator(instanceHost.instance);
430
+ instanceHost.isConstructorCalled = true;
431
+ }
432
+ instanceHost.isResolved = true;
433
+ return instanceHost.instance;
434
+ }
435
+ async loadPerContext(instance, moduleRef, collection, ctx, wrapper) {
436
+ if (!wrapper) {
437
+ const injectionToken = instance.constructor;
438
+ wrapper = collection.get(injectionToken);
439
+ }
440
+ await this.loadInstance(wrapper, collection, moduleRef, ctx, wrapper);
441
+ await this.loadEnhancersPerContext(wrapper, ctx, wrapper);
442
+ const host = wrapper.getInstanceByContextId(this.getContextId(ctx, wrapper), wrapper.id);
443
+ return host && host.instance;
444
+ }
445
+ async loadEnhancersPerContext(wrapper, ctx, inquirer) {
446
+ const enhancers = wrapper.getEnhancersMetadata() || [];
447
+ const loadEnhancer = (item) => {
448
+ const hostModule = item.host;
449
+ return this.loadInstance(item, hostModule.injectables, hostModule, ctx, inquirer);
450
+ };
451
+ await Promise.all(enhancers.map(loadEnhancer));
452
+ }
453
+ async loadCtorMetadata(metadata, contextId, inquirer, parentInquirer) {
454
+ const hosts = await Promise.all(metadata.map(async (item) => this.resolveScopedComponentHost(item, contextId, inquirer, parentInquirer)));
455
+ return hosts.map((item, index) => {
456
+ const dependency = metadata[index];
457
+ const effectiveInquirer = this.getEffectiveInquirer(dependency, inquirer, parentInquirer, contextId);
458
+ return item?.getInstanceByContextId(this.getContextId(contextId, item), this.getInquirerId(effectiveInquirer)).instance;
459
+ });
460
+ }
461
+ async loadPropertiesMetadata(metadata, contextId, inquirer) {
462
+ const dependenciesHosts = await Promise.all(metadata.map(async ({ wrapper: item, key }) => ({
463
+ key,
464
+ host: await this.resolveComponentHost(item.host, item, contextId, inquirer),
465
+ })));
466
+ const inquirerId = this.getInquirerId(inquirer);
467
+ return dependenciesHosts.map(({ key, host }) => ({
468
+ key,
469
+ name: key,
470
+ instance: host.getInstanceByContextId(this.getContextId(contextId, host), inquirerId).instance,
471
+ }));
472
+ }
473
+ getInquirerId(inquirer) {
474
+ return inquirer ? inquirer.id : undefined;
475
+ }
476
+ /**
477
+ * For nested TRANSIENT dependencies (TRANSIENT -> TRANSIENT) in non-static contexts,
478
+ * returns parentInquirer to ensure each parent TRANSIENT gets its own instance.
479
+ * This is necessary because in REQUEST/DURABLE scopes, the same TRANSIENT wrapper
480
+ * can be used by multiple parents, causing nested TRANSIENTs to be shared incorrectly.
481
+ * For non-TRANSIENT -> TRANSIENT, returns inquirer (current wrapper being created).
482
+ */
483
+ getEffectiveInquirer(dependency, inquirer, parentInquirer, contextId) {
484
+ return dependency?.isTransient &&
485
+ inquirer?.isTransient &&
486
+ parentInquirer &&
487
+ contextId !== constants_2.STATIC_CONTEXT
488
+ ? parentInquirer
489
+ : inquirer;
490
+ }
491
+ resolveScopedComponentHost(item, contextId, inquirer, parentInquirer) {
492
+ return this.isInquirerRequest(item, parentInquirer)
493
+ ? parentInquirer
494
+ : this.resolveComponentHost(item.host, item, contextId, this.getEffectiveInquirer(item, inquirer, parentInquirer, contextId));
495
+ }
496
+ isInquirerRequest(item, parentInquirer) {
497
+ return item.isTransient && item.name === inquirer_1.INQUIRER && parentInquirer;
498
+ }
499
+ isInquirer(param, parentInquirer) {
500
+ return param === inquirer_1.INQUIRER && parentInquirer;
501
+ }
502
+ addDependencyMetadata(keyOrIndex, hostWrapper, instanceWrapper) {
503
+ if ((0, shared_utils_1.isSymbol)(keyOrIndex) || (0, shared_utils_1.isString)(keyOrIndex)) {
504
+ hostWrapper.addPropertiesMetadata(keyOrIndex, instanceWrapper);
505
+ }
506
+ else {
507
+ hostWrapper.addCtorMetadata(keyOrIndex, instanceWrapper);
508
+ }
509
+ }
510
+ getTokenName(token) {
511
+ return (0, shared_utils_1.isFunction)(token) ? token.name : token.toString();
512
+ }
513
+ printResolvingDependenciesLog(token, inquirer) {
514
+ if (!this.isDebugMode()) {
515
+ return;
516
+ }
517
+ const tokenName = this.getTokenName(token);
518
+ const dependentName = (inquirer?.name && inquirer.name.toString?.()) ?? 'unknown';
519
+ const isAlias = dependentName === tokenName;
520
+ const messageToPrint = `Resolving dependency ${cli_colors_util_1.clc.cyanBright(tokenName)}${cli_colors_util_1.clc.green(' in the ')}${cli_colors_util_1.clc.yellow(dependentName)}${cli_colors_util_1.clc.green(` provider ${isAlias ? '(alias)' : ''}`)}`;
521
+ this.logger.log(messageToPrint);
522
+ }
523
+ printLookingForProviderLog(token, moduleRef) {
524
+ if (!this.isDebugMode()) {
525
+ return;
526
+ }
527
+ const tokenName = this.getTokenName(token);
528
+ const moduleRefName = moduleRef?.metatype?.name ?? 'unknown';
529
+ this.logger.log(`Looking for ${cli_colors_util_1.clc.cyanBright(tokenName)}${cli_colors_util_1.clc.green(' in ')}${cli_colors_util_1.clc.magentaBright(moduleRefName)}`);
530
+ }
531
+ printFoundInModuleLog(token, moduleRef) {
532
+ if (!this.isDebugMode()) {
533
+ return;
534
+ }
535
+ const tokenName = this.getTokenName(token);
536
+ const moduleRefName = moduleRef?.metatype?.name ?? 'unknown';
537
+ this.logger.log(`Found ${cli_colors_util_1.clc.cyanBright(tokenName)}${cli_colors_util_1.clc.green(' in ')}${cli_colors_util_1.clc.magentaBright(moduleRefName)}`);
538
+ }
539
+ isDebugMode() {
540
+ return !!process.env.NEST_DEBUG;
541
+ }
542
+ getContextId(contextId, instanceWrapper) {
543
+ return contextId.getParent
544
+ ? contextId.getParent({
545
+ token: instanceWrapper.token,
546
+ isTreeDurable: instanceWrapper.isDependencyTreeDurable(),
547
+ })
548
+ : contextId;
549
+ }
550
+ getNowTimestamp() {
551
+ return perf_hooks_1.performance.now();
552
+ }
553
+ }
554
+ exports.Injector = Injector;
@@ -0,0 +1 @@
1
+ export * from './inquirer-constants';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./inquirer-constants"), exports);
@@ -0,0 +1 @@
1
+ export declare const INQUIRER = "INQUIRER";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.INQUIRER = void 0;
4
+ exports.INQUIRER = 'INQUIRER';
@@ -0,0 +1,2 @@
1
+ import { Provider } from '@nestjs/common';
2
+ export declare const inquirerProvider: Provider;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inquirerProvider = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const inquirer_constants_1 = require("./inquirer-constants");
6
+ const noop = () => { };
7
+ exports.inquirerProvider = {
8
+ provide: inquirer_constants_1.INQUIRER,
9
+ scope: common_1.Scope.TRANSIENT,
10
+ useFactory: noop,
11
+ };
@@ -0,0 +1,22 @@
1
+ import { InjectionToken } from '@nestjs/common';
2
+ import { NestContainer } from './container';
3
+ import { InstanceWrapper } from './instance-wrapper';
4
+ export interface InstanceLink<T = any> {
5
+ token: InjectionToken;
6
+ wrapperRef: InstanceWrapper<T>;
7
+ collection: Map<any, InstanceWrapper>;
8
+ moduleId: string;
9
+ }
10
+ export declare class InstanceLinksHost {
11
+ private readonly container;
12
+ private readonly instanceLinks;
13
+ constructor(container: NestContainer);
14
+ get<T = any>(token: InjectionToken): InstanceLink<T>;
15
+ get<T = any>(token: InjectionToken, options?: {
16
+ moduleId?: string;
17
+ each?: boolean;
18
+ }): InstanceLink<T> | Array<InstanceLink<T>>;
19
+ private initialize;
20
+ private addLink;
21
+ private getInstanceNameByToken;
22
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InstanceLinksHost = void 0;
4
+ const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
5
+ const unknown_element_exception_1 = require("../errors/exceptions/unknown-element.exception");
6
+ class InstanceLinksHost {
7
+ constructor(container) {
8
+ this.container = container;
9
+ this.instanceLinks = new Map();
10
+ this.initialize();
11
+ }
12
+ get(token, options = {}) {
13
+ const instanceLinksForGivenToken = this.instanceLinks.get(token);
14
+ if (!instanceLinksForGivenToken) {
15
+ throw new unknown_element_exception_1.UnknownElementException(this.getInstanceNameByToken(token));
16
+ }
17
+ if (options.each) {
18
+ return instanceLinksForGivenToken;
19
+ }
20
+ const instanceLink = options.moduleId
21
+ ? instanceLinksForGivenToken.find(item => item.moduleId === options.moduleId)
22
+ : instanceLinksForGivenToken[instanceLinksForGivenToken.length - 1];
23
+ if (!instanceLink) {
24
+ throw new unknown_element_exception_1.UnknownElementException(this.getInstanceNameByToken(token));
25
+ }
26
+ return instanceLink;
27
+ }
28
+ initialize() {
29
+ const modules = this.container.getModules();
30
+ modules.forEach(moduleRef => {
31
+ const { providers, injectables, controllers } = moduleRef;
32
+ providers.forEach((wrapper, token) => this.addLink(wrapper, token, moduleRef, 'providers'));
33
+ injectables.forEach((wrapper, token) => this.addLink(wrapper, token, moduleRef, 'injectables'));
34
+ controllers.forEach((wrapper, token) => this.addLink(wrapper, token, moduleRef, 'controllers'));
35
+ });
36
+ }
37
+ addLink(wrapper, token, moduleRef, collectionName) {
38
+ const instanceLink = {
39
+ moduleId: moduleRef.id,
40
+ wrapperRef: wrapper,
41
+ collection: moduleRef[collectionName],
42
+ token,
43
+ };
44
+ const existingLinks = this.instanceLinks.get(token);
45
+ if (!existingLinks) {
46
+ this.instanceLinks.set(token, [instanceLink]);
47
+ }
48
+ else {
49
+ existingLinks.push(instanceLink);
50
+ }
51
+ }
52
+ getInstanceNameByToken(token) {
53
+ return (0, shared_utils_1.isFunction)(token) ? token?.name : token;
54
+ }
55
+ }
56
+ exports.InstanceLinksHost = InstanceLinksHost;