@venok/core 1.0.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 (400) hide show
  1. package/application/config.d.ts +35 -0
  2. package/application/config.js +85 -0
  3. package/application/context.d.ts +198 -0
  4. package/application/context.js +325 -0
  5. package/application/factory.d.ts +43 -0
  6. package/application/factory.js +147 -0
  7. package/constants.d.ts +46 -0
  8. package/constants.js +53 -0
  9. package/context/creator.d.ts +9 -0
  10. package/context/creator.js +32 -0
  11. package/context/execution-host.d.ts +16 -0
  12. package/context/execution-host.js +30 -0
  13. package/context/external/creator.d.ts +63 -0
  14. package/context/external/creator.js +159 -0
  15. package/context/external/proxy.d.ts +5 -0
  16. package/context/external/proxy.js +19 -0
  17. package/decorators/apply.decorator.d.ts +10 -0
  18. package/decorators/apply.decorator.js +24 -0
  19. package/decorators/bind.decorator.d.ts +11 -0
  20. package/decorators/bind.decorator.js +20 -0
  21. package/decorators/catch.decorator.d.ts +17 -0
  22. package/decorators/catch.decorator.js +26 -0
  23. package/decorators/create-param.decorator.d.ts +29 -0
  24. package/decorators/create-param.decorator.js +51 -0
  25. package/decorators/dependencies.decorator.d.ts +6 -0
  26. package/decorators/dependencies.decorator.js +17 -0
  27. package/decorators/exception-filters.decorator.d.ts +21 -0
  28. package/decorators/exception-filters.decorator.js +41 -0
  29. package/decorators/global.decorator.d.ts +10 -0
  30. package/decorators/global.decorator.js +19 -0
  31. package/decorators/index.d.ts +15 -0
  32. package/decorators/index.js +31 -0
  33. package/decorators/inject.decorator.d.ts +26 -0
  34. package/decorators/inject.decorator.js +45 -0
  35. package/decorators/injectable.decorator.d.ts +40 -0
  36. package/decorators/injectable.decorator.js +51 -0
  37. package/decorators/module.decorator.d.ts +14 -0
  38. package/decorators/module.decorator.js +38 -0
  39. package/decorators/optional.decorator.d.ts +14 -0
  40. package/decorators/optional.decorator.js +30 -0
  41. package/decorators/set-metadata.decorator.d.ts +18 -0
  42. package/decorators/set-metadata.decorator.js +30 -0
  43. package/decorators/use-guards.decorator.d.ts +21 -0
  44. package/decorators/use-guards.decorator.js +40 -0
  45. package/decorators/use-interceptors.decorator.d.ts +21 -0
  46. package/decorators/use-interceptors.decorator.js +40 -0
  47. package/decorators/use-pipes.decorator.d.ts +21 -0
  48. package/decorators/use-pipes.decorator.js +39 -0
  49. package/discovery/meta-host-collection.d.ts +32 -0
  50. package/discovery/meta-host-collection.js +79 -0
  51. package/discovery/module.d.ts +5 -0
  52. package/discovery/module.js +24 -0
  53. package/discovery/service.d.ts +68 -0
  54. package/discovery/service.js +90 -0
  55. package/errors/exceptions/circular-dependency.exception.d.ts +4 -0
  56. package/errors/exceptions/circular-dependency.exception.js +11 -0
  57. package/errors/exceptions/index.d.ts +8 -0
  58. package/errors/exceptions/index.js +24 -0
  59. package/errors/exceptions/invalid-class-module.exception.d.ts +4 -0
  60. package/errors/exceptions/invalid-class-module.exception.js +11 -0
  61. package/errors/exceptions/invalid-class-scope.exception.d.ts +5 -0
  62. package/errors/exceptions/invalid-class-scope.exception.js +14 -0
  63. package/errors/exceptions/invalid-class.exception.d.ts +4 -0
  64. package/errors/exceptions/invalid-class.exception.js +11 -0
  65. package/errors/exceptions/invalid-exception-filter.exception.d.ts +4 -0
  66. package/errors/exceptions/invalid-exception-filter.exception.js +11 -0
  67. package/errors/exceptions/invalid-module.exception.d.ts +4 -0
  68. package/errors/exceptions/invalid-module.exception.js +11 -0
  69. package/errors/exceptions/runtime.exception.d.ts +4 -0
  70. package/errors/exceptions/runtime.exception.js +12 -0
  71. package/errors/exceptions/undefined-dependency.exception.d.ts +6 -0
  72. package/errors/exceptions/undefined-dependency.exception.js +11 -0
  73. package/errors/exceptions/undefined-forwardref.exception.d.ts +5 -0
  74. package/errors/exceptions/undefined-forwardref.exception.js +11 -0
  75. package/errors/exceptions/undefined-module.exception.d.ts +4 -0
  76. package/errors/exceptions/undefined-module.exception.js +11 -0
  77. package/errors/exceptions/unknown-dependencies.exception.d.ts +16 -0
  78. package/errors/exceptions/unknown-dependencies.exception.js +15 -0
  79. package/errors/exceptions/unknown-element.exception.d.ts +4 -0
  80. package/errors/exceptions/unknown-element.exception.js +12 -0
  81. package/errors/exceptions/unknown-export.exception.d.ts +4 -0
  82. package/errors/exceptions/unknown-export.exception.js +11 -0
  83. package/errors/exceptions/unknown-module.exception.d.ts +4 -0
  84. package/errors/exceptions/unknown-module.exception.js +10 -0
  85. package/errors/messages.d.ts +15 -0
  86. package/errors/messages.js +126 -0
  87. package/exceptions/external/filter-context.d.ts +10 -0
  88. package/exceptions/external/filter-context.js +37 -0
  89. package/exceptions/external/filter.d.ts +5 -0
  90. package/exceptions/external/filter.js +16 -0
  91. package/exceptions/external/handler.d.ts +9 -0
  92. package/exceptions/external/handler.js +31 -0
  93. package/exceptions/filter-context.d.ts +14 -0
  94. package/exceptions/filter-context.js +55 -0
  95. package/exceptions/select-exception-filter-metadata.d.ts +2 -0
  96. package/exceptions/select-exception-filter-metadata.js +6 -0
  97. package/exceptions/zone/handler.d.ts +5 -0
  98. package/exceptions/zone/handler.js +15 -0
  99. package/exceptions/zone/zone.d.ts +5 -0
  100. package/exceptions/zone/zone.js +32 -0
  101. package/guards/consumer.d.ts +9 -0
  102. package/guards/consumer.js +33 -0
  103. package/guards/context-creator.d.ts +17 -0
  104. package/guards/context-creator.js +69 -0
  105. package/guards/index.d.ts +2 -0
  106. package/guards/index.js +18 -0
  107. package/helpers/color.helper.d.ts +9 -0
  108. package/helpers/color.helper.js +14 -0
  109. package/helpers/context-id-factory.helper.d.ts +2 -0
  110. package/helpers/context-id-factory.helper.js +15 -0
  111. package/helpers/context.helper.d.ts +23 -0
  112. package/helpers/context.helper.js +49 -0
  113. package/helpers/extends-metadata.helper.d.ts +1 -0
  114. package/helpers/extends-metadata.helper.js +9 -0
  115. package/helpers/flatten.helper.d.ts +1 -0
  116. package/helpers/flatten.helper.js +9 -0
  117. package/helpers/messages.helper.d.ts +2 -0
  118. package/helpers/messages.helper.js +7 -0
  119. package/helpers/noop.helper.d.ts +1 -0
  120. package/helpers/noop.helper.js +5 -0
  121. package/helpers/random-string-generator.helper.d.ts +1 -0
  122. package/helpers/random-string-generator.helper.js +6 -0
  123. package/helpers/rethrow.helper.d.ts +1 -0
  124. package/helpers/rethrow.helper.js +7 -0
  125. package/helpers/shared.helper.d.ts +10 -0
  126. package/helpers/shared.helper.js +33 -0
  127. package/helpers/silent.helper.d.ts +10 -0
  128. package/helpers/silent.helper.js +18 -0
  129. package/helpers/transient.helper.d.ts +12 -0
  130. package/helpers/transient.helper.js +26 -0
  131. package/helpers/uuid.helper.d.ts +15 -0
  132. package/helpers/uuid.helper.js +54 -0
  133. package/helpers/validate-each.helper.d.ts +8 -0
  134. package/helpers/validate-each.helper.js +25 -0
  135. package/hooks/before-app-shutdown.hook.d.ts +9 -0
  136. package/hooks/before-app-shutdown.hook.js +45 -0
  137. package/hooks/index.d.ts +5 -0
  138. package/hooks/index.js +21 -0
  139. package/hooks/on-app-bootstrap.hook.d.ts +8 -0
  140. package/hooks/on-app-bootstrap.hook.js +45 -0
  141. package/hooks/on-app-shutdown.hook.d.ts +9 -0
  142. package/hooks/on-app-shutdown.hook.js +46 -0
  143. package/hooks/on-module-destroy.hook.d.ts +8 -0
  144. package/hooks/on-module-destroy.hook.js +45 -0
  145. package/hooks/on-module-init.hook.d.ts +8 -0
  146. package/hooks/on-module-init.hook.js +45 -0
  147. package/index.d.ts +10 -0
  148. package/index.js +32 -0
  149. package/injector/constants.d.ts +2 -0
  150. package/injector/constants.js +7 -0
  151. package/injector/container.d.ts +61 -0
  152. package/injector/container.js +194 -0
  153. package/injector/helpers/class-scope.helper.d.ts +2 -0
  154. package/injector/helpers/class-scope.helper.js +9 -0
  155. package/injector/helpers/classifier.helper.d.ts +4 -0
  156. package/injector/helpers/classifier.helper.js +17 -0
  157. package/injector/helpers/is-durable.helper.d.ts +2 -0
  158. package/injector/helpers/is-durable.helper.js +9 -0
  159. package/injector/index.d.ts +5 -0
  160. package/injector/index.js +20 -0
  161. package/injector/injector.d.ts +87 -0
  162. package/injector/injector.js +452 -0
  163. package/injector/instance/links-host.d.ts +22 -0
  164. package/injector/instance/links-host.js +50 -0
  165. package/injector/instance/loader.d.ts +21 -0
  166. package/injector/instance/loader.js +73 -0
  167. package/injector/instance/resolver.d.ts +16 -0
  168. package/injector/instance/resolver.js +43 -0
  169. package/injector/instance/wrapper.d.ts +90 -0
  170. package/injector/instance/wrapper.js +272 -0
  171. package/injector/internal-core-module/core-providers.d.ts +4 -0
  172. package/injector/internal-core-module/core-providers.js +21 -0
  173. package/injector/internal-core-module/internal-core-module-factory.d.ts +8 -0
  174. package/injector/internal-core-module/internal-core-module-factory.js +42 -0
  175. package/injector/internal-core-module/internal-core-module.d.ts +4 -0
  176. package/injector/internal-core-module/internal-core-module.js +31 -0
  177. package/injector/module/compiler.d.ts +19 -0
  178. package/injector/module/compiler.js +27 -0
  179. package/injector/module/container.d.ts +6 -0
  180. package/injector/module/container.js +24 -0
  181. package/injector/module/lazy/loader.d.ts +21 -0
  182. package/injector/module/lazy/loader.js +49 -0
  183. package/injector/module/lazy/options.d.ts +6 -0
  184. package/injector/module/lazy/options.js +2 -0
  185. package/injector/module/module.d.ts +74 -0
  186. package/injector/module/module.js +383 -0
  187. package/injector/module/ref.d.ts +106 -0
  188. package/injector/module/ref.js +62 -0
  189. package/injector/module/token-factory.d.ts +13 -0
  190. package/injector/module/token-factory.js +71 -0
  191. package/injector/settlement-signal.d.ts +37 -0
  192. package/injector/settlement-signal.js +55 -0
  193. package/inspector/graph-inspector.d.ts +26 -0
  194. package/inspector/graph-inspector.js +163 -0
  195. package/inspector/initialize-on-preview.allowlist.d.ts +6 -0
  196. package/inspector/initialize-on-preview.allowlist.js +13 -0
  197. package/inspector/interfaces/edge.interface.d.ts +28 -0
  198. package/inspector/interfaces/edge.interface.js +2 -0
  199. package/inspector/interfaces/enhancer-metadata-cache-entry.interface.d.ts +12 -0
  200. package/inspector/interfaces/enhancer-metadata-cache-entry.interface.js +2 -0
  201. package/inspector/interfaces/entrypoint.interface.d.ts +10 -0
  202. package/inspector/interfaces/entrypoint.interface.js +2 -0
  203. package/inspector/interfaces/extras.interface.d.ts +18 -0
  204. package/inspector/interfaces/extras.interface.js +2 -0
  205. package/inspector/interfaces/node.interface.d.ts +49 -0
  206. package/inspector/interfaces/node.interface.js +2 -0
  207. package/inspector/interfaces/serialized-graph-json.interface.d.ts +14 -0
  208. package/inspector/interfaces/serialized-graph-json.interface.js +2 -0
  209. package/inspector/interfaces/serialized-graph-metadata.interface.d.ts +10 -0
  210. package/inspector/interfaces/serialized-graph-metadata.interface.js +2 -0
  211. package/inspector/noop-graph-inspector.d.ts +2 -0
  212. package/inspector/noop-graph-inspector.js +8 -0
  213. package/inspector/partial-graph.host.d.ts +7 -0
  214. package/inspector/partial-graph.host.js +15 -0
  215. package/inspector/serialized-graph.d.ts +52 -0
  216. package/inspector/serialized-graph.js +121 -0
  217. package/interceptors/consumer.d.ts +9 -0
  218. package/interceptors/consumer.js +37 -0
  219. package/interceptors/context-creator.d.ts +17 -0
  220. package/interceptors/context-creator.js +67 -0
  221. package/interceptors/index.d.ts +2 -0
  222. package/interceptors/index.js +18 -0
  223. package/interfaces/abstract.interface.d.ts +3 -0
  224. package/interfaces/abstract.interface.js +2 -0
  225. package/interfaces/application/context-options.interface.d.ts +41 -0
  226. package/interfaces/application/context-options.interface.js +9 -0
  227. package/interfaces/application/context.interface.d.ts +162 -0
  228. package/interfaces/application/context.interface.js +2 -0
  229. package/interfaces/application/index.d.ts +1 -0
  230. package/interfaces/application/index.js +17 -0
  231. package/interfaces/context/arguments-host.interface.d.ts +22 -0
  232. package/interfaces/context/arguments-host.interface.js +2 -0
  233. package/interfaces/context/execution.interface.d.ts +18 -0
  234. package/interfaces/context/execution.interface.js +2 -0
  235. package/interfaces/features/exception-filter.interface.d.ts +21 -0
  236. package/interfaces/features/exception-filter.interface.js +2 -0
  237. package/interfaces/features/guards.interface.d.ts +20 -0
  238. package/interfaces/features/guards.interface.js +2 -0
  239. package/interfaces/features/interceptor.interface.d.ts +30 -0
  240. package/interfaces/features/interceptor.interface.js +2 -0
  241. package/interfaces/features/pipes.interface.d.ts +37 -0
  242. package/interfaces/features/pipes.interface.js +2 -0
  243. package/interfaces/helper.interface.d.ts +3 -0
  244. package/interfaces/helper.interface.js +2 -0
  245. package/interfaces/hooks/before-application-shutdown.interface.d.ts +3 -0
  246. package/interfaces/hooks/before-application-shutdown.interface.js +2 -0
  247. package/interfaces/hooks/index.d.ts +5 -0
  248. package/interfaces/hooks/index.js +21 -0
  249. package/interfaces/hooks/on-application-bootstrap.interface.d.ts +9 -0
  250. package/interfaces/hooks/on-application-bootstrap.interface.js +2 -0
  251. package/interfaces/hooks/on-application-shutdown.interface.d.ts +9 -0
  252. package/interfaces/hooks/on-application-shutdown.interface.js +2 -0
  253. package/interfaces/hooks/on-destroy.interface.d.ts +10 -0
  254. package/interfaces/hooks/on-destroy.interface.js +2 -0
  255. package/interfaces/hooks/on-init.interface.d.ts +8 -0
  256. package/interfaces/hooks/on-init.interface.js +2 -0
  257. package/interfaces/index.d.ts +6 -0
  258. package/interfaces/index.js +22 -0
  259. package/interfaces/injectable.interface.d.ts +1 -0
  260. package/interfaces/injectable.interface.js +2 -0
  261. package/interfaces/modules/configurable/async-options.interface.d.ts +42 -0
  262. package/interfaces/modules/configurable/async-options.interface.js +2 -0
  263. package/interfaces/modules/configurable/cls.interface.d.ts +13 -0
  264. package/interfaces/modules/configurable/cls.interface.js +2 -0
  265. package/interfaces/modules/configurable/host.interface.d.ts +62 -0
  266. package/interfaces/modules/configurable/host.interface.js +2 -0
  267. package/interfaces/modules/configurable/index.d.ts +3 -0
  268. package/interfaces/modules/configurable/index.js +19 -0
  269. package/interfaces/modules/definition.interface.d.ts +4 -0
  270. package/interfaces/modules/definition.interface.js +2 -0
  271. package/interfaces/modules/dynamic-module.interface.d.ts +23 -0
  272. package/interfaces/modules/dynamic-module.interface.js +2 -0
  273. package/interfaces/modules/forward-reference.interface.d.ts +3 -0
  274. package/interfaces/modules/forward-reference.interface.js +2 -0
  275. package/interfaces/modules/index.d.ts +9 -0
  276. package/interfaces/modules/index.js +25 -0
  277. package/interfaces/modules/injection-token.interface.d.ts +5 -0
  278. package/interfaces/modules/injection-token.interface.js +2 -0
  279. package/interfaces/modules/introspection-result.interface.d.ts +10 -0
  280. package/interfaces/modules/introspection-result.interface.js +2 -0
  281. package/interfaces/modules/module-metadata.interface.d.ts +24 -0
  282. package/interfaces/modules/module-metadata.interface.js +2 -0
  283. package/interfaces/modules/module.interface.d.ts +2 -0
  284. package/interfaces/modules/module.interface.js +2 -0
  285. package/interfaces/modules/optional-factory-dependency.interface.d.ts +8 -0
  286. package/interfaces/modules/optional-factory-dependency.interface.js +2 -0
  287. package/interfaces/modules/override.interface.d.ts +5 -0
  288. package/interfaces/modules/override.interface.js +2 -0
  289. package/interfaces/modules/provider.interface.d.ts +142 -0
  290. package/interfaces/modules/provider.interface.js +2 -0
  291. package/interfaces/scope.interface.d.ts +35 -0
  292. package/interfaces/scope.interface.js +23 -0
  293. package/interfaces/type.interface.d.ts +3 -0
  294. package/interfaces/type.interface.js +2 -0
  295. package/metadata-scanner.d.ts +4 -0
  296. package/metadata-scanner.js +34 -0
  297. package/module/configurable-module.builder.d.ts +93 -0
  298. package/module/configurable-module.builder.js +204 -0
  299. package/module/constants.d.ts +4 -0
  300. package/module/constants.js +7 -0
  301. package/module/helpers/generate-options-injection-token.helper.d.ts +1 -0
  302. package/module/helpers/generate-options-injection-token.helper.js +9 -0
  303. package/module/helpers/get-injection-providers.helper.d.ts +8 -0
  304. package/module/helpers/get-injection-providers.helper.js +36 -0
  305. package/module/helpers/index.d.ts +2 -0
  306. package/module/helpers/index.js +18 -0
  307. package/module/index.d.ts +2 -0
  308. package/module/index.js +18 -0
  309. package/package.json +35 -0
  310. package/pipes/consumer.d.ts +9 -0
  311. package/pipes/consumer.js +15 -0
  312. package/pipes/context-creator.d.ts +18 -0
  313. package/pipes/context-creator.js +70 -0
  314. package/pipes/index.d.ts +2 -0
  315. package/pipes/index.js +18 -0
  316. package/scanner.d.ts +81 -0
  317. package/scanner.js +374 -0
  318. package/services/console.service.d.ts +86 -0
  319. package/services/console.service.js +233 -0
  320. package/services/index.d.ts +1 -0
  321. package/services/index.js +17 -0
  322. package/services/logger.service.d.ts +157 -0
  323. package/services/logger.service.js +269 -0
  324. package/services/reflector.service.d.ts +110 -0
  325. package/services/reflector.service.js +87 -0
  326. package/test/context/execution-host.spec.d.ts +1 -0
  327. package/test/context/execution-host.spec.js +31 -0
  328. package/test/context/external/creator.spec.d.ts +1 -0
  329. package/test/context/external/creator.spec.js +149 -0
  330. package/test/context/external/proxy.spec.d.ts +1 -0
  331. package/test/context/external/proxy.spec.js +45 -0
  332. package/test/exceptions/external/handler.spec.d.ts +1 -0
  333. package/test/exceptions/external/handler.spec.js +89 -0
  334. package/test/exceptions/filter-context.spec.d.ts +2 -0
  335. package/test/exceptions/filter-context.spec.js +91 -0
  336. package/test/exceptions/messages.spec.d.ts +0 -0
  337. package/test/exceptions/messages.spec.js +201 -0
  338. package/test/exceptions/zona/handler.spec.d.ts +1 -0
  339. package/test/exceptions/zona/handler.spec.js +51 -0
  340. package/test/exceptions/zona/zone.spec.d.ts +1 -0
  341. package/test/exceptions/zona/zone.spec.js +66 -0
  342. package/test/guards/consumer.spec.d.ts +1 -0
  343. package/test/guards/consumer.spec.js +47 -0
  344. package/test/guards/context-creator.spec.d.ts +1 -0
  345. package/test/guards/context-creator.spec.js +138 -0
  346. package/test/helpers/context-id-factory.spec.d.ts +1 -0
  347. package/test/helpers/context-id-factory.spec.js +9 -0
  348. package/test/helpers/shared.spec.d.ts +1 -0
  349. package/test/helpers/shared.spec.js +122 -0
  350. package/test/hooks/before-app-shutdown.hook.spec.d.ts +1 -0
  351. package/test/hooks/before-app-shutdown.hook.spec.js +44 -0
  352. package/test/hooks/on-app-bootstrap.hook.spec.d.ts +1 -0
  353. package/test/hooks/on-app-bootstrap.hook.spec.js +43 -0
  354. package/test/hooks/on-app-shutdown.hook.spec.d.ts +1 -0
  355. package/test/hooks/on-app-shutdown.hook.spec.js +43 -0
  356. package/test/hooks/on-module-destroy.hook.spec.d.ts +1 -0
  357. package/test/hooks/on-module-destroy.hook.spec.js +43 -0
  358. package/test/hooks/on-module-init.hook.spec.d.ts +1 -0
  359. package/test/hooks/on-module-init.hook.spec.js +43 -0
  360. package/test/injector/compiler.spec.d.ts +1 -0
  361. package/test/injector/compiler.spec.js +42 -0
  362. package/test/injector/container.spec.d.ts +1 -0
  363. package/test/injector/container.spec.js +203 -0
  364. package/test/injector/helpers/classifier.spec.d.ts +1 -0
  365. package/test/injector/helpers/classifier.spec.js +102 -0
  366. package/test/injector/injector.spec.d.ts +1 -0
  367. package/test/injector/injector.spec.js +678 -0
  368. package/test/injector/instance/loader.spec.d.ts +1 -0
  369. package/test/injector/instance/loader.spec.js +108 -0
  370. package/test/injector/instance/wrapper.spec.d.ts +1 -0
  371. package/test/injector/instance/wrapper.spec.js +772 -0
  372. package/test/injector/internal-core-module/internal-core-module-factory.spec.d.ts +1 -0
  373. package/test/injector/internal-core-module/internal-core-module-factory.spec.js +27 -0
  374. package/test/injector/module/lazy/loader.spec.d.ts +1 -0
  375. package/test/injector/module/lazy/loader.spec.js +71 -0
  376. package/test/injector/module/module.spec.d.ts +1 -0
  377. package/test/injector/module/module.spec.js +410 -0
  378. package/test/injector/module/token-factory.spec.d.ts +1 -0
  379. package/test/injector/module/token-factory.spec.js +84 -0
  380. package/test/interceptors/consumer.spec.d.ts +1 -0
  381. package/test/interceptors/consumer.spec.js +136 -0
  382. package/test/interceptors/context-creator.spec.d.ts +1 -0
  383. package/test/interceptors/context-creator.spec.js +139 -0
  384. package/test/metadata-scanner.spec.d.ts +1 -0
  385. package/test/metadata-scanner.spec.js +41 -0
  386. package/test/module/configurable-module.builder.spec.d.ts +1 -0
  387. package/test/module/configurable-module.builder.spec.js +102 -0
  388. package/test/module/helpers/get-injection-providers.helper.spec.d.ts +1 -0
  389. package/test/module/helpers/get-injection-providers.helper.spec.js +49 -0
  390. package/test/pipes/consumer.spec.d.ts +1 -0
  391. package/test/pipes/consumer.spec.js +42 -0
  392. package/test/pipes/context-creator.spec.d.ts +1 -0
  393. package/test/pipes/context-creator.spec.js +108 -0
  394. package/test/scanner.spec.d.ts +1 -0
  395. package/test/scanner.spec.js +620 -0
  396. package/test/services/logger.service.spec.d.ts +1 -0
  397. package/test/services/logger.service.spec.js +487 -0
  398. package/test/services/reflector.service.spec.d.ts +1 -0
  399. package/test/services/reflector.service.spec.js +105 -0
  400. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,35 @@
1
+ import { CanActivate } from "@venok/core/interfaces/features/guards.interface";
2
+ import { InstanceWrapper } from "@venok/core/injector/instance/wrapper";
3
+ import { PipeTransform } from "@venok/core/interfaces/features/pipes.interface";
4
+ import { ExceptionFilter } from "@venok/core/interfaces/features/exception-filter.interface";
5
+ import { VenokInterceptor } from "@venok/core/interfaces/features/interceptor.interface";
6
+ export declare class ApplicationConfig {
7
+ private globalPipes;
8
+ private globalFilters;
9
+ private globalInterceptors;
10
+ private globalGuards;
11
+ private readonly globalRequestPipes;
12
+ private readonly globalRequestFilters;
13
+ private readonly globalRequestInterceptors;
14
+ private readonly globalRequestGuards;
15
+ addGlobalPipe(pipe: PipeTransform<any>): void;
16
+ useGlobalPipes(...pipes: PipeTransform<any>[]): void;
17
+ getGlobalFilters(): ExceptionFilter[];
18
+ addGlobalFilter(filter: ExceptionFilter): void;
19
+ useGlobalFilters(...filters: ExceptionFilter[]): void;
20
+ getGlobalPipes(): PipeTransform<any>[];
21
+ getGlobalInterceptors(): VenokInterceptor[];
22
+ addGlobalInterceptor(interceptor: VenokInterceptor): void;
23
+ useGlobalInterceptors(...interceptors: VenokInterceptor[]): void;
24
+ getGlobalGuards(): CanActivate[];
25
+ addGlobalGuard(guard: CanActivate): void;
26
+ useGlobalGuards(...guards: CanActivate[]): void;
27
+ addGlobalRequestInterceptor(wrapper: InstanceWrapper<VenokInterceptor>): void;
28
+ getGlobalRequestInterceptors(): InstanceWrapper<VenokInterceptor>[];
29
+ addGlobalRequestPipe(wrapper: InstanceWrapper<PipeTransform>): void;
30
+ getGlobalRequestPipes(): InstanceWrapper<PipeTransform>[];
31
+ addGlobalRequestFilter(wrapper: InstanceWrapper<ExceptionFilter>): void;
32
+ getGlobalRequestFilters(): InstanceWrapper<ExceptionFilter>[];
33
+ addGlobalRequestGuard(wrapper: InstanceWrapper<CanActivate>): void;
34
+ getGlobalRequestGuards(): InstanceWrapper<CanActivate>[];
35
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApplicationConfig = void 0;
4
+ class ApplicationConfig {
5
+ constructor() {
6
+ this.globalPipes = [];
7
+ this.globalFilters = [];
8
+ this.globalInterceptors = [];
9
+ this.globalGuards = [];
10
+ this.globalRequestPipes = [];
11
+ this.globalRequestFilters = [];
12
+ this.globalRequestInterceptors = [];
13
+ this.globalRequestGuards = [];
14
+ }
15
+ // constructor(private ioAdapter: WebSocketAdapter | null = null) {}
16
+ //
17
+ // public setIoAdapter(ioAdapter: WebSocketAdapter) {
18
+ // this.ioAdapter = ioAdapter;
19
+ // }
20
+ //
21
+ // public getIoAdapter(): WebSocketAdapter {
22
+ // return this.ioAdapter;
23
+ // }
24
+ addGlobalPipe(pipe) {
25
+ this.globalPipes.push(pipe);
26
+ }
27
+ useGlobalPipes(...pipes) {
28
+ this.globalPipes = this.globalPipes.concat(pipes);
29
+ }
30
+ getGlobalFilters() {
31
+ return this.globalFilters;
32
+ }
33
+ addGlobalFilter(filter) {
34
+ this.globalFilters.push(filter);
35
+ }
36
+ useGlobalFilters(...filters) {
37
+ this.globalFilters = this.globalFilters.concat(filters);
38
+ }
39
+ getGlobalPipes() {
40
+ return this.globalPipes;
41
+ }
42
+ getGlobalInterceptors() {
43
+ return this.globalInterceptors;
44
+ }
45
+ addGlobalInterceptor(interceptor) {
46
+ this.globalInterceptors.push(interceptor);
47
+ }
48
+ useGlobalInterceptors(...interceptors) {
49
+ this.globalInterceptors = this.globalInterceptors.concat(interceptors);
50
+ }
51
+ getGlobalGuards() {
52
+ return this.globalGuards;
53
+ }
54
+ addGlobalGuard(guard) {
55
+ this.globalGuards.push(guard);
56
+ }
57
+ useGlobalGuards(...guards) {
58
+ this.globalGuards = this.globalGuards.concat(guards);
59
+ }
60
+ addGlobalRequestInterceptor(wrapper) {
61
+ this.globalRequestInterceptors.push(wrapper);
62
+ }
63
+ getGlobalRequestInterceptors() {
64
+ return this.globalRequestInterceptors;
65
+ }
66
+ addGlobalRequestPipe(wrapper) {
67
+ this.globalRequestPipes.push(wrapper);
68
+ }
69
+ getGlobalRequestPipes() {
70
+ return this.globalRequestPipes;
71
+ }
72
+ addGlobalRequestFilter(wrapper) {
73
+ this.globalRequestFilters.push(wrapper);
74
+ }
75
+ getGlobalRequestFilters() {
76
+ return this.globalRequestFilters;
77
+ }
78
+ addGlobalRequestGuard(wrapper) {
79
+ this.globalRequestGuards.push(wrapper);
80
+ }
81
+ getGlobalRequestGuards() {
82
+ return this.globalRequestGuards;
83
+ }
84
+ }
85
+ exports.ApplicationConfig = ApplicationConfig;
@@ -0,0 +1,198 @@
1
+ import { AbstractInstanceResolver } from "@venok/core/injector/instance/resolver";
2
+ import { Injector } from "@venok/core/injector/injector";
3
+ import { Logger, LoggerService, LogLevel } from "@venok/core/services/logger.service";
4
+ import { InstanceLinksHost } from "@venok/core/injector/instance/links-host";
5
+ import { Module } from "@venok/core/injector/module/module";
6
+ import { DynamicModule, Type } from "@venok/core/interfaces";
7
+ import { VenokContainer } from "@venok/core/injector/container";
8
+ import { ContextId } from "@venok/core/injector/instance/wrapper";
9
+ import { ApplicationContextOptions } from "@venok/core/interfaces/application/context-options.interface";
10
+ import { VenokApplicationContext } from "@venok/core/interfaces/application/context.interface";
11
+ import { ApplicationConfig } from "@venok/core/application/config";
12
+ import { VenokInterceptor } from "@venok/core/interfaces/features/interceptor.interface";
13
+ import { CanActivate } from "@venok/core/interfaces/features/guards.interface";
14
+ import { ExceptionFilter } from "@venok/core/interfaces/features/exception-filter.interface";
15
+ import { PipeTransform } from "@venok/core/interfaces/features/pipes.interface";
16
+ /**
17
+ * System signals which shut down a process
18
+ */
19
+ export declare enum ShutdownSignal {
20
+ SIGHUP = "SIGHUP",
21
+ SIGINT = "SIGINT",
22
+ SIGQUIT = "SIGQUIT",
23
+ SIGILL = "SIGILL",
24
+ SIGTRAP = "SIGTRAP",
25
+ SIGABRT = "SIGABRT",
26
+ SIGBUS = "SIGBUS",
27
+ SIGFPE = "SIGFPE",
28
+ SIGSEGV = "SIGSEGV",
29
+ SIGUSR2 = "SIGUSR2",
30
+ SIGTERM = "SIGTERM"
31
+ }
32
+ export type ShutdownSignalKeys = keyof typeof ShutdownSignal;
33
+ /**
34
+ * @publicApi
35
+ */
36
+ export declare class ApplicationContext<TOptions extends ApplicationContextOptions = ApplicationContextOptions> extends AbstractInstanceResolver implements VenokApplicationContext {
37
+ protected readonly container: VenokContainer;
38
+ protected readonly config: ApplicationConfig;
39
+ protected readonly appOptions: TOptions;
40
+ private contextModule;
41
+ private readonly scope;
42
+ protected isInitialized: boolean;
43
+ protected injector: Injector;
44
+ protected readonly logger: Logger;
45
+ private shouldFlushLogsOnOverride;
46
+ private readonly activeShutdownSignals;
47
+ private readonly moduleCompiler;
48
+ private shutdownCleanupRef?;
49
+ private _instanceLinksHost;
50
+ private _moduleRefsForHooksByDistance?;
51
+ protected get instanceLinksHost(): InstanceLinksHost;
52
+ constructor(container: VenokContainer, config: ApplicationConfig, appOptions?: TOptions, contextModule?: Module, scope?: Type<any>[]);
53
+ selectContextModule(): void;
54
+ /**
55
+ * Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module.
56
+ * @returns {VenokApplicationContext}
57
+ */
58
+ select<T>(moduleType: Type<T> | DynamicModule): VenokApplicationContext;
59
+ /**
60
+ * Retrieves an instance of either injectable or controller, otherwise, throws exception.
61
+ * @returns {TResult}
62
+ */
63
+ get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): TResult;
64
+ /**
65
+ * Retrieves an instance of either injectable or controller, otherwise, throws exception.
66
+ * @returns {TResult}
67
+ */
68
+ get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
69
+ strict?: boolean;
70
+ each?: undefined | false;
71
+ }): TResult;
72
+ /**
73
+ * Retrieves a list of instances of either injectables or controllers, otherwise, throws exception.
74
+ * @returns {Array<TResult>}
75
+ */
76
+ get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
77
+ strict?: boolean;
78
+ each: true;
79
+ }): Array<TResult>;
80
+ /**
81
+ * Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
82
+ * @returns {Array<TResult>}
83
+ */
84
+ resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): Promise<TResult>;
85
+ /**
86
+ * Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
87
+ * @returns {Array<TResult>}
88
+ */
89
+ resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
90
+ id: number;
91
+ }): Promise<TResult>;
92
+ /**
93
+ * Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
94
+ * @returns {Array<TResult>}
95
+ */
96
+ resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
97
+ id: number;
98
+ }, options?: {
99
+ strict?: boolean;
100
+ each?: undefined | false;
101
+ }): Promise<TResult>;
102
+ /**
103
+ * Resolves transient or request-scoped instances of either injectables or controllers, otherwise, throws exception.
104
+ * @returns {Array<TResult>}
105
+ */
106
+ resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
107
+ id: number;
108
+ }, options?: {
109
+ strict?: boolean;
110
+ each: true;
111
+ }): Promise<Array<TResult>>;
112
+ /**
113
+ * Registers the request/context object for a given context ID (DI container sub-tree).
114
+ * @returns {void}
115
+ */
116
+ registerRequestByContextId<T = any>(request: T, contextId: ContextId): void;
117
+ /**
118
+ * Initializes the Venok application.
119
+ * Calls the Venok lifecycle events.
120
+ *
121
+ * @returns {Promise<this>} The ApplicationContext instance as Promise
122
+ */
123
+ init(): Promise<this>;
124
+ /**
125
+ * Terminates the application
126
+ * @returns {Promise<void>}
127
+ */
128
+ close(signal?: string): Promise<void>;
129
+ /**
130
+ * Sets custom logger service.
131
+ * Flushes buffered logs if auto flush is on.
132
+ * @returns {void}
133
+ */
134
+ useLogger(logger: LoggerService | LogLevel[] | false): void;
135
+ useGlobalFilters(...filters: ExceptionFilter[]): this;
136
+ useGlobalPipes(...pipes: PipeTransform<any>[]): this;
137
+ useGlobalInterceptors(...interceptors: VenokInterceptor[]): this;
138
+ useGlobalGuards(...guards: CanActivate[]): this;
139
+ /**
140
+ * Prints buffered logs and detaches buffer.
141
+ * @returns {void}
142
+ */
143
+ flushLogs(): void;
144
+ /**
145
+ * Define that it must flush logs right after defining a custom logger.
146
+ */
147
+ flushLogsOnOverride(): void;
148
+ /**
149
+ * Enables the usage of shutdown hooks. Will call the
150
+ * `onApplicationShutdown` function of a provider if the
151
+ * process receives a shutdown signal.
152
+ *
153
+ * @param {ShutdownSignal[]} [signals=[]] The system signals it should listen to
154
+ *
155
+ * @returns {this} The Venok application context instance
156
+ */
157
+ enableShutdownHooks(signals?: (ShutdownSignal | string)[]): this;
158
+ protected dispose(): Promise<void>;
159
+ /**
160
+ * Listens to shutdown signals by listening to
161
+ * process events
162
+ *
163
+ * @param {string[]} signals The system signals it should listen to
164
+ */
165
+ protected listenToShutdownSignals(signals: string[]): void;
166
+ /**
167
+ * Unsubscribes from shutdown signals (process events)
168
+ */
169
+ protected unsubscribeFromProcessSignals(): void;
170
+ /**
171
+ * Calls the `onModuleInit` function on the registered
172
+ * modules and its children.
173
+ */
174
+ protected callInitHook(): Promise<void>;
175
+ /**
176
+ * Calls the `onModuleDestroy` function on the registered
177
+ * modules and its children.
178
+ */
179
+ protected callDestroyHook(): Promise<void>;
180
+ /**
181
+ * Calls the `onApplicationBootstrap` function on the registered
182
+ * modules and its children.
183
+ */
184
+ protected callBootstrapHook(): Promise<void>;
185
+ /**
186
+ * Calls the `onApplicationShutdown` function on the registered
187
+ * modules and children.
188
+ */
189
+ protected callShutdownHook(signal?: string): Promise<void>;
190
+ /**
191
+ * Calls the `beforeApplicationShutdown` function on the registered
192
+ * modules and children.
193
+ */
194
+ protected callBeforeShutdownHook(signal?: string): Promise<void>;
195
+ protected assertNotInPreviewMode(methodName: string): void;
196
+ private getModulesToTriggerHooksOn;
197
+ private printInPreviewModeWarning;
198
+ }
@@ -0,0 +1,325 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApplicationContext = exports.ShutdownSignal = void 0;
4
+ const resolver_1 = require("@venok/core/injector/instance/resolver");
5
+ const injector_1 = require("@venok/core/injector/injector");
6
+ const logger_service_1 = require("@venok/core/services/logger.service");
7
+ const compiler_1 = require("@venok/core/injector/module/compiler");
8
+ const links_host_1 = require("@venok/core/injector/instance/links-host");
9
+ const exceptions_1 = require("@venok/core/errors/exceptions");
10
+ const context_id_factory_helper_1 = require("@venok/core/helpers/context-id-factory.helper");
11
+ const shared_helper_1 = require("@venok/core/helpers/shared.helper");
12
+ const hooks_1 = require("@venok/core/hooks");
13
+ const constants_1 = require("@venok/core/constants");
14
+ /**
15
+ * System signals which shut down a process
16
+ */
17
+ var ShutdownSignal;
18
+ (function (ShutdownSignal) {
19
+ ShutdownSignal["SIGHUP"] = "SIGHUP";
20
+ ShutdownSignal["SIGINT"] = "SIGINT";
21
+ ShutdownSignal["SIGQUIT"] = "SIGQUIT";
22
+ ShutdownSignal["SIGILL"] = "SIGILL";
23
+ ShutdownSignal["SIGTRAP"] = "SIGTRAP";
24
+ ShutdownSignal["SIGABRT"] = "SIGABRT";
25
+ ShutdownSignal["SIGBUS"] = "SIGBUS";
26
+ ShutdownSignal["SIGFPE"] = "SIGFPE";
27
+ ShutdownSignal["SIGSEGV"] = "SIGSEGV";
28
+ ShutdownSignal["SIGUSR2"] = "SIGUSR2";
29
+ ShutdownSignal["SIGTERM"] = "SIGTERM";
30
+ })(ShutdownSignal || (exports.ShutdownSignal = ShutdownSignal = {}));
31
+ /**
32
+ * @publicApi
33
+ */
34
+ class ApplicationContext extends resolver_1.AbstractInstanceResolver {
35
+ get instanceLinksHost() {
36
+ if (!this._instanceLinksHost) {
37
+ this._instanceLinksHost = new links_host_1.InstanceLinksHost(this.container);
38
+ }
39
+ return this._instanceLinksHost;
40
+ }
41
+ constructor(container, config, appOptions = {}, contextModule = null, scope = new Array()) {
42
+ super();
43
+ this.container = container;
44
+ this.config = config;
45
+ this.appOptions = appOptions;
46
+ this.contextModule = contextModule;
47
+ this.scope = scope;
48
+ this.isInitialized = false;
49
+ this.logger = new logger_service_1.Logger(ApplicationContext.name, {
50
+ timestamp: true,
51
+ });
52
+ this.shouldFlushLogsOnOverride = false;
53
+ this.activeShutdownSignals = new Array();
54
+ this.moduleCompiler = new compiler_1.ModuleCompiler();
55
+ this.injector = new injector_1.Injector();
56
+ if (this.appOptions.preview) {
57
+ this.printInPreviewModeWarning();
58
+ }
59
+ }
60
+ selectContextModule() {
61
+ const modules = this.container.getModules().values();
62
+ this.contextModule = modules.next().value;
63
+ }
64
+ /**
65
+ * Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module.
66
+ * @returns {VenokApplicationContext}
67
+ */
68
+ select(moduleType) {
69
+ const modulesContainer = this.container.getModules();
70
+ const contextModuleCtor = this.contextModule.metatype;
71
+ const scope = this.scope.concat(contextModuleCtor);
72
+ const moduleTokenFactory = this.container.getModuleTokenFactory();
73
+ const { type, dynamicMetadata } = this.moduleCompiler.extractMetadata(moduleType);
74
+ const token = moduleTokenFactory.create(type, dynamicMetadata);
75
+ const selectedModule = modulesContainer.get(token);
76
+ if (!selectedModule) {
77
+ throw new exceptions_1.UnknownModuleException();
78
+ }
79
+ return new ApplicationContext(this.container, this.config, this.appOptions, selectedModule, scope);
80
+ }
81
+ /**
82
+ * Retrieves an instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
83
+ * @returns {TResult | Array<TResult>}
84
+ */
85
+ get(typeOrToken, options = { strict: false }) {
86
+ return !(options && options.strict)
87
+ ? this.find(typeOrToken, options)
88
+ : this.find(typeOrToken, {
89
+ moduleId: this.contextModule?.id,
90
+ each: options.each,
91
+ });
92
+ }
93
+ /**
94
+ * Resolves transient or request-scoped instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
95
+ * @returns {Promise<TResult | Array<TResult>>}
96
+ */
97
+ resolve(typeOrToken, contextId = (0, context_id_factory_helper_1.createContextId)(), options = { strict: false }) {
98
+ return this.resolvePerContext(typeOrToken, this.contextModule, contextId, options);
99
+ }
100
+ /**
101
+ * Registers the request/context object for a given context ID (DI container sub-tree).
102
+ * @returns {void}
103
+ */
104
+ registerRequestByContextId(request, contextId) {
105
+ this.container.registerRequestProvider(request, contextId);
106
+ }
107
+ /**
108
+ * Initializes the Venok application.
109
+ * Calls the Venok lifecycle events.
110
+ *
111
+ * @returns {Promise<this>} The ApplicationContext instance as Promise
112
+ */
113
+ async init() {
114
+ if (this.isInitialized) {
115
+ return this;
116
+ }
117
+ await this.callInitHook();
118
+ await this.callBootstrapHook();
119
+ this.isInitialized = true;
120
+ return this;
121
+ }
122
+ /**
123
+ * Terminates the application
124
+ * @returns {Promise<void>}
125
+ */
126
+ async close(signal) {
127
+ await this.callDestroyHook();
128
+ await this.callBeforeShutdownHook(signal);
129
+ await this.dispose();
130
+ await this.callShutdownHook(signal);
131
+ this.unsubscribeFromProcessSignals();
132
+ }
133
+ /**
134
+ * Sets custom logger service.
135
+ * Flushes buffered logs if auto flush is on.
136
+ * @returns {void}
137
+ */
138
+ useLogger(logger) {
139
+ logger_service_1.Logger.overrideLogger(logger);
140
+ if (this.shouldFlushLogsOnOverride) {
141
+ this.flushLogs();
142
+ }
143
+ }
144
+ useGlobalFilters(...filters) {
145
+ this.config.useGlobalFilters(...filters);
146
+ return this;
147
+ }
148
+ useGlobalPipes(...pipes) {
149
+ this.config.useGlobalPipes(...pipes);
150
+ return this;
151
+ }
152
+ useGlobalInterceptors(...interceptors) {
153
+ this.config.useGlobalInterceptors(...interceptors);
154
+ return this;
155
+ }
156
+ useGlobalGuards(...guards) {
157
+ this.config.useGlobalGuards(...guards);
158
+ return this;
159
+ }
160
+ /**
161
+ * Prints buffered logs and detaches buffer.
162
+ * @returns {void}
163
+ */
164
+ flushLogs() {
165
+ logger_service_1.Logger.flush();
166
+ }
167
+ /**
168
+ * Define that it must flush logs right after defining a custom logger.
169
+ */
170
+ flushLogsOnOverride() {
171
+ this.shouldFlushLogsOnOverride = true;
172
+ }
173
+ /**
174
+ * Enables the usage of shutdown hooks. Will call the
175
+ * `onApplicationShutdown` function of a provider if the
176
+ * process receives a shutdown signal.
177
+ *
178
+ * @param {ShutdownSignal[]} [signals=[]] The system signals it should listen to
179
+ *
180
+ * @returns {this} The Venok application context instance
181
+ */
182
+ enableShutdownHooks(signals = []) {
183
+ if ((0, shared_helper_1.isEmpty)(signals)) {
184
+ const keys = Object.keys(ShutdownSignal);
185
+ signals = keys.map((key) => ShutdownSignal[key]);
186
+ }
187
+ else {
188
+ // given signals array should be unique because
189
+ // process shouldn't listen to the same signal more than once.
190
+ signals = Array.from(new Set(signals));
191
+ }
192
+ signals = signals
193
+ .map((signal) => signal.toString().toUpperCase().trim())
194
+ // filter out the signals which is already listening to
195
+ .filter((signal) => !this.activeShutdownSignals.includes(signal));
196
+ this.listenToShutdownSignals(signals);
197
+ return this;
198
+ }
199
+ async dispose() {
200
+ // Venok application context has no server
201
+ // to dispose, therefore just call a noop
202
+ return Promise.resolve();
203
+ }
204
+ /**
205
+ * Listens to shutdown signals by listening to
206
+ * process events
207
+ *
208
+ * @param {string[]} signals The system signals it should listen to
209
+ */
210
+ listenToShutdownSignals(signals) {
211
+ let receivedSignal = false;
212
+ const cleanup = async (signal) => {
213
+ try {
214
+ if (receivedSignal) {
215
+ // If we receive another signal while we're waiting
216
+ // for the server to stop, just ignore it.
217
+ return;
218
+ }
219
+ receivedSignal = true;
220
+ await this.callDestroyHook();
221
+ await this.callBeforeShutdownHook(signal);
222
+ await this.dispose();
223
+ await this.callShutdownHook(signal);
224
+ signals.forEach((sig) => process.removeListener(sig, cleanup));
225
+ process.kill(process.pid, signal);
226
+ }
227
+ catch (err) {
228
+ logger_service_1.Logger.error(constants_1.MESSAGES.ERROR_DURING_SHUTDOWN, err?.stack, ApplicationContext.name);
229
+ process.exit(1);
230
+ }
231
+ };
232
+ this.shutdownCleanupRef = cleanup;
233
+ signals.forEach((signal) => {
234
+ this.activeShutdownSignals.push(signal);
235
+ process.on(signal, cleanup);
236
+ });
237
+ }
238
+ /**
239
+ * Unsubscribes from shutdown signals (process events)
240
+ */
241
+ unsubscribeFromProcessSignals() {
242
+ if (!this.shutdownCleanupRef) {
243
+ return;
244
+ }
245
+ this.activeShutdownSignals.forEach((signal) => {
246
+ process.removeListener(signal, this.shutdownCleanupRef);
247
+ });
248
+ }
249
+ /**
250
+ * Calls the `onModuleInit` function on the registered
251
+ * modules and its children.
252
+ */
253
+ async callInitHook() {
254
+ const modulesSortedByDistance = this.getModulesToTriggerHooksOn();
255
+ for (const module of modulesSortedByDistance) {
256
+ await (0, hooks_1.callModuleInitHook)(module);
257
+ }
258
+ }
259
+ /**
260
+ * Calls the `onModuleDestroy` function on the registered
261
+ * modules and its children.
262
+ */
263
+ async callDestroyHook() {
264
+ const modulesSortedByDistance = this.getModulesToTriggerHooksOn();
265
+ for (const module of modulesSortedByDistance) {
266
+ await (0, hooks_1.callModuleDestroyHook)(module);
267
+ }
268
+ }
269
+ /**
270
+ * Calls the `onApplicationBootstrap` function on the registered
271
+ * modules and its children.
272
+ */
273
+ async callBootstrapHook() {
274
+ const modulesSortedByDistance = this.getModulesToTriggerHooksOn();
275
+ for (const module of modulesSortedByDistance) {
276
+ await (0, hooks_1.callModuleBootstrapHook)(module);
277
+ }
278
+ }
279
+ /**
280
+ * Calls the `onApplicationShutdown` function on the registered
281
+ * modules and children.
282
+ */
283
+ async callShutdownHook(signal) {
284
+ const modulesSortedByDistance = this.getModulesToTriggerHooksOn();
285
+ for (const module of modulesSortedByDistance) {
286
+ await (0, hooks_1.callAppShutdownHook)(module, signal);
287
+ }
288
+ }
289
+ /**
290
+ * Calls the `beforeApplicationShutdown` function on the registered
291
+ * modules and children.
292
+ */
293
+ async callBeforeShutdownHook(signal) {
294
+ const modulesSortedByDistance = this.getModulesToTriggerHooksOn();
295
+ for (const module of modulesSortedByDistance) {
296
+ await (0, hooks_1.callBeforeAppShutdownHook)(module, signal);
297
+ }
298
+ }
299
+ assertNotInPreviewMode(methodName) {
300
+ if (this.appOptions.preview) {
301
+ const error = `Calling the "${methodName}" in the preview mode is not supported.`;
302
+ this.logger.error(error);
303
+ throw new Error(error);
304
+ }
305
+ }
306
+ getModulesToTriggerHooksOn() {
307
+ if (this._moduleRefsForHooksByDistance) {
308
+ return this._moduleRefsForHooksByDistance;
309
+ }
310
+ const modulesContainer = this.container.getModules();
311
+ const compareFn = (a, b) => b.distance - a.distance;
312
+ const modulesSortedByDistance = Array.from(modulesContainer.values()).sort(compareFn);
313
+ this._moduleRefsForHooksByDistance = this.appOptions?.preview
314
+ ? modulesSortedByDistance.filter((moduleRef) => moduleRef.initOnPreview)
315
+ : modulesSortedByDistance;
316
+ return this._moduleRefsForHooksByDistance;
317
+ }
318
+ printInPreviewModeWarning() {
319
+ this.logger.warn("------------------------------------------------");
320
+ this.logger.warn("Application is running in the PREVIEW mode!");
321
+ this.logger.warn("Providers will not be instantiated.");
322
+ this.logger.warn("------------------------------------------------");
323
+ }
324
+ }
325
+ exports.ApplicationContext = ApplicationContext;
@@ -0,0 +1,43 @@
1
+ import { VenokApplicationContext } from "@venok/core/interfaces";
2
+ import { ApplicationContextOptions } from "@venok/core/interfaces/application/context-options.interface";
3
+ /**
4
+ * @publicApi
5
+ */
6
+ export declare class VenokFactoryStatic {
7
+ private readonly logger;
8
+ private abortOnError;
9
+ private autoFlushLogs;
10
+ /**
11
+ * Creates an instance of VenokApplicationContext.
12
+ *
13
+ * @param moduleCls Entry (root) application module class
14
+ * @param options Optional Venok application configuration
15
+ *
16
+ * @returns A promise that, when resolved,
17
+ * contains a reference to the VenokApplicationContext instance.
18
+ */
19
+ createApplicationContext(moduleCls: any, options?: ApplicationContextOptions): Promise<VenokApplicationContext>;
20
+ private createVenokInstance;
21
+ private setAbortOnError;
22
+ private initialize;
23
+ private handleInitializationError;
24
+ private createProxy;
25
+ private createExceptionProxy;
26
+ private createExceptionZone;
27
+ private registerLoggerConfiguration;
28
+ private createGraphInspector;
29
+ }
30
+ /**
31
+ * Use VenokFactory to create an application instance.
32
+ *
33
+ * ### Specifying an entry module
34
+ *
35
+ * Pass the required *root module* for the application via the module parameter.
36
+ * By convention, it is usually called `ApplicationModule`. Starting with this
37
+ * module, Venok assembles the dependency graph and begins the process of
38
+ * Dependency Injection and instantiates the classes needed to launch your
39
+ * application.
40
+ *
41
+ * @publicApi
42
+ */
43
+ export declare const VenokFactory: VenokFactoryStatic;