node-cqrs 1.0.0-rc.2 → 1.0.0-rc.20

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 (354) hide show
  1. package/CHANGELOG.md +244 -83
  2. package/dist/AbstractAggregate.js +62 -40
  3. package/dist/AbstractAggregate.js.map +1 -1
  4. package/dist/AbstractProjection.js +64 -47
  5. package/dist/AbstractProjection.js.map +1 -1
  6. package/dist/AbstractSaga.js.map +1 -1
  7. package/dist/AggregateCommandHandler.js +44 -20
  8. package/dist/AggregateCommandHandler.js.map +1 -1
  9. package/dist/CommandBus.js +6 -10
  10. package/dist/CommandBus.js.map +1 -1
  11. package/dist/CqrsContainerBuilder.js +12 -3
  12. package/dist/CqrsContainerBuilder.js.map +1 -1
  13. package/dist/Event.js +0 -24
  14. package/dist/Event.js.map +1 -1
  15. package/dist/EventDispatchPipeline.js +81 -0
  16. package/dist/EventDispatchPipeline.js.map +1 -0
  17. package/dist/EventDispatcher.js +94 -0
  18. package/dist/EventDispatcher.js.map +1 -0
  19. package/dist/EventStore.js +63 -141
  20. package/dist/EventStore.js.map +1 -1
  21. package/dist/SagaEventHandler.js +3 -2
  22. package/dist/SagaEventHandler.js.map +1 -1
  23. package/dist/in-memory/InMemoryEventStorage.js +73 -0
  24. package/dist/in-memory/InMemoryEventStorage.js.map +1 -0
  25. package/dist/in-memory/InMemoryLock.js +40 -0
  26. package/dist/in-memory/InMemoryLock.js.map +1 -0
  27. package/dist/{infrastructure → in-memory}/InMemoryMessageBus.js +28 -27
  28. package/dist/in-memory/InMemoryMessageBus.js.map +1 -0
  29. package/dist/in-memory/InMemorySnapshotStorage.js +70 -0
  30. package/dist/in-memory/InMemorySnapshotStorage.js.map +1 -0
  31. package/dist/{infrastructure → in-memory}/InMemoryView.js +13 -9
  32. package/dist/in-memory/InMemoryView.js.map +1 -0
  33. package/dist/in-memory/index.js +22 -0
  34. package/dist/in-memory/index.js.map +1 -0
  35. package/dist/{infrastructure → in-memory}/utils/index.js +0 -1
  36. package/dist/in-memory/utils/index.js.map +1 -0
  37. package/dist/{infrastructure → in-memory}/utils/nextCycle.js +1 -1
  38. package/dist/in-memory/utils/nextCycle.js.map +1 -0
  39. package/dist/index.js +3 -8
  40. package/dist/index.js.map +1 -1
  41. package/dist/{interfaces.js → interfaces/IAggregate.js} +1 -2
  42. package/dist/interfaces/IAggregate.js.map +1 -0
  43. package/dist/interfaces/IAggregateSnapshotStorage.js +3 -0
  44. package/dist/interfaces/IAggregateSnapshotStorage.js.map +1 -0
  45. package/dist/interfaces/ICommand.js +3 -0
  46. package/dist/interfaces/ICommand.js.map +1 -0
  47. package/dist/interfaces/ICommandBus.js +3 -0
  48. package/dist/interfaces/ICommandBus.js.map +1 -0
  49. package/dist/interfaces/IContainer.js +3 -0
  50. package/dist/interfaces/IContainer.js.map +1 -0
  51. package/dist/interfaces/IDispatchPipelineProcessor.js +9 -0
  52. package/dist/interfaces/IDispatchPipelineProcessor.js.map +1 -0
  53. package/dist/interfaces/IEvent.js +10 -0
  54. package/dist/interfaces/IEvent.js.map +1 -0
  55. package/dist/interfaces/IEventBus.js +9 -0
  56. package/dist/interfaces/IEventBus.js.map +1 -0
  57. package/dist/interfaces/IEventDispatcher.js +3 -0
  58. package/dist/interfaces/IEventDispatcher.js.map +1 -0
  59. package/dist/interfaces/IEventLocker.js +10 -0
  60. package/dist/interfaces/IEventLocker.js.map +1 -0
  61. package/dist/interfaces/IEventReceptor.js +3 -0
  62. package/dist/interfaces/IEventReceptor.js.map +1 -0
  63. package/dist/interfaces/IEventSet.js +8 -0
  64. package/dist/interfaces/IEventSet.js.map +1 -0
  65. package/dist/interfaces/IEventStorageReader.js +13 -0
  66. package/dist/interfaces/IEventStorageReader.js.map +1 -0
  67. package/dist/interfaces/IEventStorageWriter.js +3 -0
  68. package/dist/interfaces/IEventStorageWriter.js.map +1 -0
  69. package/dist/interfaces/IEventStore.js +3 -0
  70. package/dist/interfaces/IEventStore.js.map +1 -0
  71. package/dist/interfaces/IEventStream.js +3 -0
  72. package/dist/interfaces/IEventStream.js.map +1 -0
  73. package/dist/interfaces/IIdentifierProvider.js +9 -0
  74. package/dist/interfaces/IIdentifierProvider.js.map +1 -0
  75. package/dist/interfaces/ILogger.js +3 -0
  76. package/dist/interfaces/ILogger.js.map +1 -0
  77. package/dist/interfaces/IMessage.js +9 -0
  78. package/dist/interfaces/IMessage.js.map +1 -0
  79. package/dist/interfaces/IMessageBus.js +3 -0
  80. package/dist/interfaces/IMessageBus.js.map +1 -0
  81. package/dist/interfaces/IObjectStorage.js +3 -0
  82. package/dist/interfaces/IObjectStorage.js.map +1 -0
  83. package/dist/interfaces/IObservable.js +11 -0
  84. package/dist/interfaces/IObservable.js.map +1 -0
  85. package/dist/interfaces/IObserver.js +3 -0
  86. package/dist/interfaces/IObserver.js.map +1 -0
  87. package/dist/interfaces/IProjection.js +3 -0
  88. package/dist/interfaces/IProjection.js.map +1 -0
  89. package/dist/interfaces/ISaga.js +3 -0
  90. package/dist/interfaces/ISaga.js.map +1 -0
  91. package/dist/interfaces/IViewLocker.js +17 -0
  92. package/dist/interfaces/IViewLocker.js.map +1 -0
  93. package/dist/interfaces/Identifier.js +3 -0
  94. package/dist/interfaces/Identifier.js.map +1 -0
  95. package/dist/interfaces/index.js +44 -0
  96. package/dist/interfaces/index.js.map +1 -0
  97. package/dist/interfaces/isObject.js +9 -0
  98. package/dist/interfaces/isObject.js.map +1 -0
  99. package/dist/rabbitmq/IContainer.js +3 -0
  100. package/dist/rabbitmq/IContainer.js.map +1 -0
  101. package/dist/rabbitmq/RabbitMqEventBus.js +89 -0
  102. package/dist/rabbitmq/RabbitMqEventBus.js.map +1 -0
  103. package/dist/rabbitmq/RabbitMqEventInjector.js +55 -0
  104. package/dist/rabbitmq/RabbitMqEventInjector.js.map +1 -0
  105. package/dist/rabbitmq/RabbitMqGateway.js +349 -0
  106. package/dist/rabbitmq/RabbitMqGateway.js.map +1 -0
  107. package/dist/rabbitmq/TerminationHandler.js +31 -0
  108. package/dist/rabbitmq/TerminationHandler.js.map +1 -0
  109. package/dist/rabbitmq/index.js +20 -0
  110. package/dist/rabbitmq/index.js.map +1 -0
  111. package/dist/sqlite/AbstractSqliteAccessor.js +50 -0
  112. package/dist/sqlite/AbstractSqliteAccessor.js.map +1 -0
  113. package/dist/sqlite/AbstractSqliteObjectProjection.js +26 -0
  114. package/dist/sqlite/AbstractSqliteObjectProjection.js.map +1 -0
  115. package/dist/sqlite/AbstractSqliteView.js +44 -0
  116. package/dist/sqlite/AbstractSqliteView.js.map +1 -0
  117. package/dist/sqlite/IContainer.js +3 -0
  118. package/dist/sqlite/IContainer.js.map +1 -0
  119. package/dist/sqlite/SqliteEventLocker.js +94 -0
  120. package/dist/sqlite/SqliteEventLocker.js.map +1 -0
  121. package/dist/sqlite/SqliteObjectStorage.js +113 -0
  122. package/dist/sqlite/SqliteObjectStorage.js.map +1 -0
  123. package/dist/sqlite/SqliteObjectView.js +46 -0
  124. package/dist/sqlite/SqliteObjectView.js.map +1 -0
  125. package/dist/sqlite/SqliteProjectionDataParams.js +3 -0
  126. package/dist/sqlite/SqliteProjectionDataParams.js.map +1 -0
  127. package/dist/sqlite/SqliteViewLocker.js +121 -0
  128. package/dist/sqlite/SqliteViewLocker.js.map +1 -0
  129. package/dist/sqlite/index.js +25 -0
  130. package/dist/sqlite/index.js.map +1 -0
  131. package/dist/sqlite/queries/eventLockTableInit.js +15 -0
  132. package/dist/sqlite/queries/eventLockTableInit.js.map +1 -0
  133. package/dist/sqlite/queries/index.js +19 -0
  134. package/dist/sqlite/queries/index.js.map +1 -0
  135. package/dist/sqlite/queries/viewLockTableInit.js +14 -0
  136. package/dist/sqlite/queries/viewLockTableInit.js.map +1 -0
  137. package/dist/sqlite/utils/getEventId.js +11 -0
  138. package/dist/sqlite/utils/getEventId.js.map +1 -0
  139. package/dist/sqlite/utils/guid.js +9 -0
  140. package/dist/sqlite/utils/guid.js.map +1 -0
  141. package/dist/sqlite/utils/index.js +19 -0
  142. package/dist/sqlite/utils/index.js.map +1 -0
  143. package/dist/tsconfig.tsbuildinfo +1 -0
  144. package/dist/utils/Deferred.js.map +1 -0
  145. package/dist/utils/Lock.js +86 -0
  146. package/dist/utils/Lock.js.map +1 -0
  147. package/dist/utils/MapAssertable.js +30 -0
  148. package/dist/utils/MapAssertable.js.map +1 -0
  149. package/dist/utils/delay.js +13 -0
  150. package/dist/utils/delay.js.map +1 -0
  151. package/dist/utils/getHandler.js +2 -3
  152. package/dist/utils/getHandler.js.map +1 -1
  153. package/dist/utils/getMessageHandlerNames.js +2 -6
  154. package/dist/utils/getMessageHandlerNames.js.map +1 -1
  155. package/dist/utils/index.js +8 -3
  156. package/dist/utils/index.js.map +1 -1
  157. package/dist/utils/iteratorToArray.js +10 -0
  158. package/dist/utils/iteratorToArray.js.map +1 -0
  159. package/dist/utils/notEmpty.js +6 -0
  160. package/dist/utils/notEmpty.js.map +1 -0
  161. package/dist/utils/setupOneTimeEmitterSubscription.js.map +1 -1
  162. package/dist/utils/subscribe.js +16 -4
  163. package/dist/utils/subscribe.js.map +1 -1
  164. package/dist/utils/validateHandlers.js.map +1 -1
  165. package/eslint.config.mjs +839 -0
  166. package/package.json +68 -30
  167. package/src/AbstractAggregate.ts +83 -56
  168. package/src/AbstractProjection.ts +107 -69
  169. package/src/AbstractSaga.ts +3 -3
  170. package/src/AggregateCommandHandler.ts +69 -46
  171. package/src/CommandBus.ts +14 -13
  172. package/src/CqrsContainerBuilder.ts +28 -29
  173. package/src/Event.ts +1 -26
  174. package/src/EventDispatchPipeline.ts +99 -0
  175. package/src/EventDispatcher.ts +126 -0
  176. package/src/EventStore.ts +93 -181
  177. package/src/SagaEventHandler.ts +7 -8
  178. package/src/in-memory/InMemoryEventStorage.ts +108 -0
  179. package/src/in-memory/InMemoryLock.ts +43 -0
  180. package/src/{infrastructure → in-memory}/InMemoryMessageBus.ts +34 -32
  181. package/src/in-memory/InMemorySnapshotStorage.ts +89 -0
  182. package/src/{infrastructure → in-memory}/InMemoryView.ts +23 -24
  183. package/src/in-memory/index.ts +5 -0
  184. package/src/{infrastructure → in-memory}/utils/index.ts +0 -1
  185. package/src/{infrastructure → in-memory}/utils/nextCycle.ts +1 -1
  186. package/src/index.ts +2 -7
  187. package/src/interfaces/IAggregate.ts +68 -0
  188. package/src/interfaces/IAggregateSnapshotStorage.ts +11 -0
  189. package/src/interfaces/ICommand.ts +3 -0
  190. package/src/interfaces/ICommandBus.ts +16 -0
  191. package/src/interfaces/IContainer.ts +33 -0
  192. package/src/interfaces/IDispatchPipelineProcessor.ts +35 -0
  193. package/src/interfaces/IEvent.ts +14 -0
  194. package/src/interfaces/IEventBus.ts +11 -0
  195. package/src/interfaces/IEventDispatcher.ts +7 -0
  196. package/src/interfaces/IEventLocker.ts +34 -0
  197. package/src/interfaces/IEventReceptor.ts +6 -0
  198. package/src/interfaces/IEventSet.ts +7 -0
  199. package/src/interfaces/IEventStorageReader.ts +44 -0
  200. package/src/interfaces/IEventStorageWriter.ts +10 -0
  201. package/src/interfaces/IEventStore.ts +13 -0
  202. package/src/interfaces/IEventStream.ts +3 -0
  203. package/src/interfaces/IIdentifierProvider.ts +17 -0
  204. package/src/interfaces/ILogger.ts +11 -0
  205. package/src/interfaces/IMessage.ts +22 -0
  206. package/src/interfaces/IMessageBus.ts +8 -0
  207. package/src/interfaces/IObjectStorage.ts +13 -0
  208. package/src/interfaces/IObservable.ts +31 -0
  209. package/src/interfaces/IObserver.ts +5 -0
  210. package/src/interfaces/IProjection.ts +20 -0
  211. package/src/interfaces/ISaga.ts +38 -0
  212. package/src/interfaces/IViewLocker.ts +46 -0
  213. package/src/interfaces/Identifier.ts +1 -0
  214. package/src/interfaces/index.ts +27 -0
  215. package/src/interfaces/isObject.ts +5 -0
  216. package/src/rabbitmq/IContainer.ts +16 -0
  217. package/src/rabbitmq/RabbitMqEventBus.ts +105 -0
  218. package/src/rabbitmq/RabbitMqEventInjector.ts +66 -0
  219. package/src/rabbitmq/RabbitMqGateway.ts +474 -0
  220. package/src/rabbitmq/TerminationHandler.ts +31 -0
  221. package/src/rabbitmq/index.ts +3 -0
  222. package/src/sqlite/AbstractSqliteAccessor.ts +58 -0
  223. package/src/sqlite/AbstractSqliteObjectProjection.ts +31 -0
  224. package/src/sqlite/AbstractSqliteView.ts +53 -0
  225. package/src/sqlite/IContainer.ts +8 -0
  226. package/src/sqlite/SqliteEventLocker.ts +137 -0
  227. package/src/sqlite/SqliteObjectStorage.ts +142 -0
  228. package/src/sqlite/SqliteObjectView.ts +58 -0
  229. package/src/sqlite/SqliteProjectionDataParams.ts +16 -0
  230. package/src/sqlite/SqliteViewLocker.ts +171 -0
  231. package/src/sqlite/index.ts +8 -0
  232. package/src/sqlite/queries/eventLockTableInit.ts +10 -0
  233. package/src/sqlite/queries/index.ts +2 -0
  234. package/src/sqlite/queries/viewLockTableInit.ts +9 -0
  235. package/src/sqlite/utils/getEventId.ts +8 -0
  236. package/src/sqlite/utils/guid.ts +4 -0
  237. package/src/sqlite/utils/index.ts +2 -0
  238. package/src/utils/Lock.ts +99 -0
  239. package/src/utils/MapAssertable.ts +30 -0
  240. package/src/utils/delay.ts +8 -0
  241. package/src/utils/getHandler.ts +4 -4
  242. package/src/utils/getMessageHandlerNames.ts +2 -8
  243. package/src/utils/index.ts +8 -3
  244. package/src/utils/iteratorToArray.ts +6 -0
  245. package/src/utils/notEmpty.ts +1 -0
  246. package/src/utils/setupOneTimeEmitterSubscription.ts +5 -3
  247. package/src/utils/subscribe.ts +20 -6
  248. package/src/utils/validateHandlers.ts +2 -1
  249. package/types/AbstractAggregate.d.ts +61 -0
  250. package/types/AbstractProjection.d.ts +60 -0
  251. package/types/AbstractSaga.d.ts +31 -0
  252. package/types/AggregateCommandHandler.d.ts +20 -0
  253. package/types/CommandBus.d.ts +27 -0
  254. package/types/CqrsContainerBuilder.d.ts +21 -0
  255. package/types/Event.d.ts +9 -0
  256. package/types/EventDispatchPipeline.d.ts +18 -0
  257. package/types/EventDispatcher.d.ts +39 -0
  258. package/types/EventStore.d.ts +34 -0
  259. package/types/SagaEventHandler.d.ts +21 -0
  260. package/types/in-memory/InMemoryEventStorage.d.ts +24 -0
  261. package/types/in-memory/InMemoryLock.d.ts +21 -0
  262. package/types/in-memory/InMemoryMessageBus.d.ts +36 -0
  263. package/types/in-memory/InMemorySnapshotStorage.d.ts +37 -0
  264. package/types/in-memory/InMemoryView.d.ts +53 -0
  265. package/types/in-memory/index.d.ts +5 -0
  266. package/types/in-memory/utils/index.d.ts +1 -0
  267. package/types/in-memory/utils/nextCycle.d.ts +4 -0
  268. package/types/index.d.ts +13 -0
  269. package/types/interfaces/IAggregate.d.ts +51 -0
  270. package/types/interfaces/IAggregateSnapshotStorage.d.ts +7 -0
  271. package/types/interfaces/ICommand.d.ts +2 -0
  272. package/types/interfaces/ICommandBus.d.ts +14 -0
  273. package/types/interfaces/IContainer.d.ts +27 -0
  274. package/types/interfaces/IDispatchPipelineProcessor.d.ts +25 -0
  275. package/types/interfaces/IEvent.d.ts +6 -0
  276. package/types/interfaces/IEventBus.d.ts +6 -0
  277. package/types/interfaces/IEventDispatcher.d.ts +6 -0
  278. package/types/interfaces/IEventLocker.d.ts +24 -0
  279. package/types/interfaces/IEventReceptor.d.ts +5 -0
  280. package/types/interfaces/IEventSet.d.ts +3 -0
  281. package/types/interfaces/IEventStorageReader.d.ts +28 -0
  282. package/types/interfaces/IEventStorageWriter.d.ts +8 -0
  283. package/types/interfaces/IEventStore.d.ts +9 -0
  284. package/types/interfaces/IEventStream.d.ts +2 -0
  285. package/types/interfaces/IIdentifierProvider.d.ts +10 -0
  286. package/types/interfaces/ILogger.d.ts +22 -0
  287. package/types/interfaces/IMessage.d.ts +12 -0
  288. package/types/interfaces/IMessageBus.d.ts +7 -0
  289. package/types/interfaces/IObjectStorage.d.ts +8 -0
  290. package/types/interfaces/IObservable.d.ts +19 -0
  291. package/types/interfaces/IObserver.d.ts +4 -0
  292. package/types/interfaces/IProjection.d.ts +17 -0
  293. package/types/interfaces/ISaga.d.ts +30 -0
  294. package/types/interfaces/IViewLocker.d.ts +34 -0
  295. package/types/interfaces/Identifier.d.ts +1 -0
  296. package/types/interfaces/index.d.ts +27 -0
  297. package/types/interfaces/isObject.d.ts +1 -0
  298. package/types/rabbitmq/IContainer.d.ts +14 -0
  299. package/types/rabbitmq/RabbitMqEventBus.d.ts +42 -0
  300. package/types/rabbitmq/RabbitMqEventInjector.d.ts +13 -0
  301. package/types/rabbitmq/RabbitMqGateway.d.ts +79 -0
  302. package/types/rabbitmq/TerminationHandler.d.ts +10 -0
  303. package/types/rabbitmq/index.d.ts +3 -0
  304. package/types/sqlite/AbstractSqliteAccessor.d.ts +25 -0
  305. package/types/sqlite/AbstractSqliteObjectProjection.d.ts +8 -0
  306. package/types/sqlite/AbstractSqliteView.d.ts +18 -0
  307. package/types/sqlite/IContainer.d.ts +7 -0
  308. package/types/sqlite/SqliteEventLocker.d.ts +28 -0
  309. package/types/sqlite/SqliteObjectStorage.d.ts +16 -0
  310. package/types/sqlite/SqliteObjectView.d.ts +16 -0
  311. package/types/sqlite/SqliteProjectionDataParams.d.ts +14 -0
  312. package/types/sqlite/SqliteViewLocker.d.ts +30 -0
  313. package/types/sqlite/index.d.ts +8 -0
  314. package/types/sqlite/queries/eventLockTableInit.d.ts +1 -0
  315. package/types/sqlite/queries/index.d.ts +2 -0
  316. package/types/sqlite/queries/viewLockTableInit.d.ts +1 -0
  317. package/types/sqlite/utils/getEventId.d.ts +5 -0
  318. package/types/sqlite/utils/guid.d.ts +4 -0
  319. package/types/sqlite/utils/index.d.ts +2 -0
  320. package/types/utils/Deferred.d.ts +13 -0
  321. package/types/utils/Lock.d.ts +22 -0
  322. package/types/utils/MapAssertable.d.ts +11 -0
  323. package/types/utils/delay.d.ts +5 -0
  324. package/types/utils/getClassName.d.ts +4 -0
  325. package/types/utils/getHandler.d.ts +7 -0
  326. package/types/utils/getMessageHandlerNames.d.ts +5 -0
  327. package/types/utils/index.d.ts +13 -0
  328. package/types/utils/isClass.d.ts +1 -0
  329. package/types/utils/iteratorToArray.d.ts +1 -0
  330. package/types/utils/notEmpty.d.ts +1 -0
  331. package/types/utils/setupOneTimeEmitterSubscription.d.ts +12 -0
  332. package/types/utils/subscribe.d.ts +13 -0
  333. package/types/utils/validateHandlers.d.ts +4 -0
  334. package/dist/infrastructure/InMemoryEventStorage.js +0 -53
  335. package/dist/infrastructure/InMemoryEventStorage.js.map +0 -1
  336. package/dist/infrastructure/InMemoryLock.js +0 -68
  337. package/dist/infrastructure/InMemoryLock.js.map +0 -1
  338. package/dist/infrastructure/InMemoryMessageBus.js.map +0 -1
  339. package/dist/infrastructure/InMemorySnapshotStorage.js +0 -26
  340. package/dist/infrastructure/InMemorySnapshotStorage.js.map +0 -1
  341. package/dist/infrastructure/InMemoryView.js.map +0 -1
  342. package/dist/infrastructure/utils/Deferred.js.map +0 -1
  343. package/dist/infrastructure/utils/index.js.map +0 -1
  344. package/dist/infrastructure/utils/nextCycle.js.map +0 -1
  345. package/dist/interfaces.js.map +0 -1
  346. package/dist/utils/getHandledMessageTypes.js +0 -18
  347. package/dist/utils/getHandledMessageTypes.js.map +0 -1
  348. package/src/infrastructure/InMemoryEventStorage.ts +0 -68
  349. package/src/infrastructure/InMemoryLock.ts +0 -73
  350. package/src/infrastructure/InMemorySnapshotStorage.ts +0 -27
  351. package/src/interfaces.ts +0 -328
  352. package/src/utils/getHandledMessageTypes.ts +0 -20
  353. /package/dist/{infrastructure/utils → utils}/Deferred.js +0 -0
  354. /package/src/{infrastructure/utils → utils}/Deferred.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IObserver.js","sourceRoot":"","sources":["../../src/interfaces/IObserver.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IProjection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IProjection.js","sourceRoot":"","sources":["../../src/interfaces/IProjection.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ISaga.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ISaga.js","sourceRoot":"","sources":["../../src/interfaces/ISaga.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isViewLocker = void 0;
4
+ const isObject_1 = require("./isObject");
5
+ /**
6
+ * Checks if a given object conforms to the `IViewLocker` interface.
7
+ *
8
+ * @param view The object to check.
9
+ * @returns `true` if the object implements `IViewLocker`, `false` otherwise.
10
+ */
11
+ const isViewLocker = (view) => (0, isObject_1.isObject)(view)
12
+ && 'ready' in view
13
+ && 'lock' in view
14
+ && 'unlock' in view
15
+ && 'once' in view;
16
+ exports.isViewLocker = isViewLocker;
17
+ //# sourceMappingURL=IViewLocker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IViewLocker.js","sourceRoot":"","sources":["../../src/interfaces/IViewLocker.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAkCtC;;;;;GAKG;AACI,MAAM,YAAY,GAAG,CAAC,IAAa,EAAuB,EAAE,CAClE,IAAA,mBAAQ,EAAC,IAAI,CAAC;OACX,OAAO,IAAI,IAAI;OACf,MAAM,IAAI,IAAI;OACd,QAAQ,IAAI,IAAI;OAChB,MAAM,IAAI,IAAI,CAAC;AALN,QAAA,YAAY,gBAKN"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Identifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Identifier.js","sourceRoot":"","sources":["../../src/interfaces/Identifier.ts"],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./IAggregate"), exports);
18
+ __exportStar(require("./IAggregateSnapshotStorage"), exports);
19
+ __exportStar(require("./ICommand"), exports);
20
+ __exportStar(require("./ICommandBus"), exports);
21
+ __exportStar(require("./IContainer"), exports);
22
+ __exportStar(require("./Identifier"), exports);
23
+ __exportStar(require("./IDispatchPipelineProcessor"), exports);
24
+ __exportStar(require("./IEvent"), exports);
25
+ __exportStar(require("./IEventBus"), exports);
26
+ __exportStar(require("./IEventDispatcher"), exports);
27
+ __exportStar(require("./IEventLocker"), exports);
28
+ __exportStar(require("./IEventReceptor"), exports);
29
+ __exportStar(require("./IEventSet"), exports);
30
+ __exportStar(require("./IEventStorageReader"), exports);
31
+ __exportStar(require("./IEventStorageWriter"), exports);
32
+ __exportStar(require("./IEventStore"), exports);
33
+ __exportStar(require("./IEventStream"), exports);
34
+ __exportStar(require("./IIdentifierProvider"), exports);
35
+ __exportStar(require("./ILogger"), exports);
36
+ __exportStar(require("./IMessage"), exports);
37
+ __exportStar(require("./IMessageBus"), exports);
38
+ __exportStar(require("./IObjectStorage"), exports);
39
+ __exportStar(require("./IObservable"), exports);
40
+ __exportStar(require("./IObserver"), exports);
41
+ __exportStar(require("./IProjection"), exports);
42
+ __exportStar(require("./ISaga"), exports);
43
+ __exportStar(require("./IViewLocker"), exports);
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,8DAA4C;AAC5C,6CAA2B;AAC3B,gDAA8B;AAC9B,+CAA6B;AAC7B,+CAA6B;AAC7B,+DAA6C;AAC7C,2CAAyB;AACzB,8CAA4B;AAC5B,qDAAmC;AACnC,iDAA+B;AAC/B,mDAAiC;AACjC,8CAA4B;AAC5B,wDAAsC;AACtC,wDAAsC;AACtC,gDAA8B;AAC9B,iDAA+B;AAC/B,wDAAsC;AACtC,4CAA0B;AAC1B,6CAA2B;AAC3B,gDAA8B;AAC9B,mDAAiC;AACjC,gDAA8B;AAC9B,8CAA4B;AAC5B,gDAA8B;AAC9B,0CAAwB;AACxB,gDAA8B"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isObject = void 0;
4
+ const isObject = (obj) => typeof obj === 'object'
5
+ && obj !== null
6
+ && !(obj instanceof Date)
7
+ && !Array.isArray(obj);
8
+ exports.isObject = isObject;
9
+ //# sourceMappingURL=isObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isObject.js","sourceRoot":"","sources":["../../src/interfaces/isObject.ts"],"names":[],"mappings":";;;AAAO,MAAM,QAAQ,GAAG,CAAC,GAAY,EAAa,EAAE,CACnD,OAAO,GAAG,KAAK,QAAQ;OACpB,GAAG,KAAK,IAAI;OACZ,CAAC,CAAC,GAAG,YAAY,IAAI,CAAC;OACtB,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAJX,QAAA,QAAQ,YAIG"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IContainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IContainer.js","sourceRoot":"","sources":["../../src/rabbitmq/IContainer.ts"],"names":[],"mappings":""}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RabbitMqEventBus = void 0;
4
+ const ALL_EVENTS_WILDCARD = '*';
5
+ class RabbitMqEventBus {
6
+ static get allEventsWildcard() {
7
+ return ALL_EVENTS_WILDCARD;
8
+ }
9
+ static DEFAULT_EXCHANGE = 'node-cqrs.events';
10
+ #gateway;
11
+ #queues = new Map();
12
+ #exchange;
13
+ #queueName;
14
+ constructor(o) {
15
+ this.#gateway = o.rabbitMqGateway;
16
+ this.#exchange = o.exchange ?? RabbitMqEventBus.DEFAULT_EXCHANGE;
17
+ this.#queueName = o.queueName;
18
+ }
19
+ /**
20
+ * Publishes an event to the fanout exchange.
21
+ * The event will be delivered to all subscribers, except this instance's own consumer.
22
+ */
23
+ async publish(event) {
24
+ await this.#gateway.publish(this.#exchange, event);
25
+ }
26
+ /**
27
+ * Registers a message handler for a specific event type.
28
+ *
29
+ * @param eventType The event type to listen for.
30
+ * @param handler The function to handle incoming messages of the specified type.
31
+ */
32
+ async on(eventType, handler) {
33
+ await this.#gateway.subscribe({
34
+ exchange: this.#exchange,
35
+ queueName: this.#queueName,
36
+ eventType,
37
+ handler,
38
+ ignoreOwn: !this.#queueName
39
+ });
40
+ }
41
+ /**
42
+ * Removes a previously registered message handler for a specific event type.
43
+ */
44
+ async off(eventType, handler) {
45
+ await this.#gateway.unsubscribe({
46
+ exchange: this.#exchange,
47
+ queueName: this.#queueName,
48
+ eventType,
49
+ handler
50
+ });
51
+ }
52
+ /**
53
+ * Returns a new instance of RabbitMqGateway that uses a durable queue with the given name.
54
+ * This ensures that all messages published to the fanout exchange are also delivered to this queue.
55
+ *
56
+ * @param name The name of the durable queue.
57
+ * @returns A new RabbitMqGateway instance configured to use the specified queue.
58
+ */
59
+ queue(name) {
60
+ let queue = this.#queues.get(name);
61
+ if (!queue) {
62
+ queue = new RabbitMqEventBus({
63
+ rabbitMqGateway: this.#gateway,
64
+ exchange: this.#exchange,
65
+ queueName: name
66
+ });
67
+ this.#queues.set(name, queue);
68
+ }
69
+ return queue;
70
+ }
71
+ /**
72
+ * Processes a batch of events and publishes them to the fanout exchange.
73
+ *
74
+ * This method is part of the `IDispatchPipelineProcessor` interface.
75
+ */
76
+ async process(batch) {
77
+ for (const { event, origin } of batch) {
78
+ // Skip publishing if the event was dispatched from external source
79
+ if (origin === 'external')
80
+ continue;
81
+ if (!event)
82
+ throw new Error('Event batch does not contain `event`');
83
+ await this.publish(event);
84
+ }
85
+ return batch;
86
+ }
87
+ }
88
+ exports.RabbitMqEventBus = RabbitMqEventBus;
89
+ //# sourceMappingURL=RabbitMqEventBus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RabbitMqEventBus.js","sourceRoot":"","sources":["../../src/rabbitmq/RabbitMqEventBus.ts"],"names":[],"mappings":";;;AAGA,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC,MAAa,gBAAgB;IAE5B,MAAM,KAAK,iBAAiB;QAC3B,OAAO,mBAAmB,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,gBAAgB,GAAG,kBAAkB,CAAC;IAE7C,QAAQ,CAAkB;IAC1B,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;IAC9C,SAAS,CAAS;IAClB,UAAU,CAAqB;IAE/B,YAAY,CAIX;QACA,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,eAAe,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,QAAQ,IAAI,gBAAgB,CAAC,gBAAgB,CAAC;QACjE,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,SAAS,CAAC;IAC/B,CAAC;IAGD;;;OAGG;IACH,KAAK,CAAC,OAAO,CAAC,KAAa;QAC1B,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC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C;QAC3B,CAAC;QAED,OAAO,KAAK,CAAC;IACd,CAAC;;AAlGF,4CAmGC"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RabbitMqEventInjector = void 0;
4
+ const Event = require("../Event");
5
+ const RabbitMqEventBus_1 = require("./RabbitMqEventBus");
6
+ /**
7
+ * Injects events received from a RabbitMQ exchange into the local event dispatcher.
8
+ *
9
+ * It subscribes to a specified fanout exchange on RabbitMQ and dispatches
10
+ * any received messages as events using the provided event dispatcher.
11
+ */
12
+ class RabbitMqEventInjector {
13
+ #rabbitMqGateway;
14
+ #messageHandler;
15
+ #eventDispatcher;
16
+ #logger;
17
+ constructor(container) {
18
+ if (!container.eventDispatcher)
19
+ throw new Error('eventDispatcher is required in the container.');
20
+ if (!container.rabbitMqGateway)
21
+ throw new Error('rabbitMqGateway is required in the container.');
22
+ this.#rabbitMqGateway = container.rabbitMqGateway;
23
+ this.#messageHandler = (msg) => this.#handleMessage(msg);
24
+ this.#eventDispatcher = container.eventDispatcher;
25
+ this.#logger = container.logger && 'child' in container.logger ?
26
+ container.logger.child({ service: new.target.name }) :
27
+ container.logger;
28
+ }
29
+ async start(exchange = RabbitMqEventBus_1.RabbitMqEventBus.DEFAULT_EXCHANGE) {
30
+ this.#logger?.debug(`Subscribing to messages from exchange "${exchange}"...`);
31
+ await this.#rabbitMqGateway.subscribeToFanout(exchange, this.#messageHandler);
32
+ this.#logger?.debug(`Listening to messages from exchange "${exchange}"`);
33
+ }
34
+ async stop(exchange = RabbitMqEventBus_1.RabbitMqEventBus.DEFAULT_EXCHANGE) {
35
+ this.#logger?.debug(`Unsubscribing from messages from exchange "${exchange}"...`);
36
+ await this.#rabbitMqGateway.unsubscribe({
37
+ exchange,
38
+ handler: this.#messageHandler
39
+ });
40
+ this.#logger?.debug(`Stopped listening to messages from exchange "${exchange}"`);
41
+ }
42
+ async #handleMessage(message) {
43
+ this.#logger?.debug(`"${Event.describe(message)}" received`);
44
+ try {
45
+ await this.#eventDispatcher.dispatch([message], { origin: 'external' });
46
+ this.#logger?.debug(`${Event.describe(message)} dispatched successfully`);
47
+ }
48
+ catch (error) {
49
+ this.#logger?.error(`Failed to dispatch event ${message.type}: ${error.message}`, { stack: error.stack });
50
+ throw error; // Re-throw to ensure message is nack'd by the gateway
51
+ }
52
+ }
53
+ }
54
+ exports.RabbitMqEventInjector = RabbitMqEventInjector;
55
+ //# sourceMappingURL=RabbitMqEventInjector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RabbitMqEventInjector.js","sourceRoot":"","sources":["../../src/rabbitmq/RabbitMqEventInjector.ts"],"names":[],"mappings":";;;AAIA,kCAAkC;AAClC,yDAAsD;AAEtD;;;;;GAKG;AACH,MAAa,qBAAqB;IACjC,gBAAgB,CAAkB;IAClC,eAAe,CAAuC;IACtD,gBAAgB,CAAmB;IACnC,OAAO,CAAuB;IAE9B,YAAY,SAAsF;QACjG,IAAI,CAAC,SAAS,CAAC,eAAe;YAC7B,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QAClE,IAAI,CAAC,SAAS,CAAC,eAAe;YAC7B,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QAElE,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC,eAAe,CAAC;QAClD,IAAI,CAAC,eAAe,GAAG,CAAC,GAAa,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QACnE,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC,eAAe,CAAC;QAClD,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,MAAM,IAAI,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC;YAC/D,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YACtD,SAAS,CAAC,MAAM,CAAC;IACnB,C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AK,EAAE,CAAC,CAAC;YAE1G,MAAM,KAAK,CAAC,CAAC,sDAAsD;QACpE,CAAC;IACF,CAAC;CACD;AApDD,sDAoDC"}
@@ -0,0 +1,349 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RabbitMqGateway = void 0;
5
+ const interfaces_1 = require("../interfaces");
6
+ const Event = require("../Event");
7
+ const utils_1 = require("../utils");
8
+ const TerminationHandler_1 = require("./TerminationHandler");
9
+ /** Generate a short pseudo-unique identifier using a truncated timestamp and random component */
10
+ const getRandomAppId = () => `${Date.now().toString(36).slice(-4)}.${Math.random().toString(36).slice(2, 6)}`.toUpperCase();
11
+ const isSystemQueue = (queueName) => queueName.startsWith('amq.');
12
+ /**
13
+ * RabbitMqGateway implements the IObservable interface using RabbitMQ.
14
+ *
15
+ * It uses a fanout exchange to broadcast messages to all connected subscribers.
16
+ * The `on` and `off` methods allow you to register and remove handlers for specific event types.
17
+ * The `queue(name)` method creates or returns a durable queue with the given name, ensuring that
18
+ * all messages delivered to the fanout exchange are also routed to this queue.
19
+ */
20
+ class RabbitMqGateway {
21
+ static HANDLER_PROCESS_TIMEOUT = 60 * 60 * 1000; // 1 hour
22
+ #connectionFactory;
23
+ #appId;
24
+ #logger;
25
+ #connecting = false;
26
+ #connection;
27
+ #pubChannel;
28
+ #exclusiveQueueName;
29
+ #queueChannels = new Map();
30
+ #queueConsumers = new Map();
31
+ #subscriptions = [];
32
+ #handlers = new Map();
33
+ /** Handles termination signals for graceful shutdown */
34
+ #terminationHandler;
35
+ get connection() {
36
+ return this.#connection;
37
+ }
38
+ constructor(o) {
39
+ if (!o.rabbitMqConnectionFactory)
40
+ throw new TypeError('rabbitMqConnectionFactory argument required');
41
+ this.#connectionFactory = o.rabbitMqConnectionFactory;
42
+ this.#appId = getRandomAppId();
43
+ this.#logger = o.logger && 'child' in o.logger ?
44
+ o.logger.child({ service: new.target.name }) :
45
+ o.logger;
46
+ if (o.process)
47
+ this.#terminationHandler = new TerminationHandler_1.TerminationHandler(o.process, () => this.#stopConsuming());
48
+ }
49
+ /**
50
+ * Establishes a connection to RabbitMQ.
51
+ * If a connection attempt is already in progress, it waits for it to complete.
52
+ * If the connection is lost, it attempts to reconnect automatically.
53
+ * Upon successful connection, it restores any previously active subscriptions.
54
+ *
55
+ * This method is called automatically by other methods if a connection is required but not yet established.
56
+ *
57
+ * @returns A promise that resolves with the ChannelModel representing the established connection.
58
+ */
59
+ async connect() {
60
+ while (this.#connecting)
61
+ await (0, utils_1.delay)(1_000);
62
+ this.#connecting = true;
63
+ while (!this.#connection) {
64
+ try {
65
+ this.#connection = await this.#connectionFactory();
66
+ this.#connection.on('error', err => this.#onConnectionError(err));
67
+ this.#connection.on('close', () => this.#onConnectionClosed());
68
+ this.#logger?.info(`${this.#appId}: Connection established`);
69
+ this.#handlers.clear();
70
+ const subscriptionsToRestore = this.#subscriptions.splice(0);
71
+ for (const subscription of subscriptionsToRestore)
72
+ await this.subscribe(subscription);
73
+ }
74
+ catch (err) {
75
+ this.#logger?.warn(`${this.#appId}: Connection attempt failed: ${err.message}`);
76
+ await (0, utils_1.delay)(5_000);
77
+ }
78
+ }
79
+ this.#connecting = false;
80
+ return this.#connection;
81
+ }
82
+ async disconnect() {
83
+ try {
84
+ this.#logger?.debug(`${this.#appId}: Disconnecting from RabbitMQ...`);
85
+ await this.#stopConsuming();
86
+ await this.#connection?.close();
87
+ if (this.#connection) // clean up in case 'close' event was not triggered
88
+ this.#onConnectionClosed();
89
+ this.#logger?.debug(`${this.#appId}: Disconnected from RabbitMQ`);
90
+ }
91
+ catch (err) {
92
+ this.#logger?.error(`${this.#appId}: Failed to disconnect from RabbitMQ: ${err.message}`, {
93
+ stack: err.stack
94
+ });
95
+ }
96
+ }
97
+ async #stopConsuming() {
98
+ this.#logger?.info(`${this.#appId}: Stopping all consumers...`);
99
+ const cancellations = [...this.#queueConsumers.entries()].map(async ([queueName, { channel, consumerTag }]) => {
100
+ this.#logger?.debug(`${this.#appId}: Cancelling consumer "${consumerTag}" for queue "${queueName}"`);
101
+ try {
102
+ await channel.cancel(consumerTag);
103
+ this.#logger?.debug(`${this.#appId}: Consumer "${consumerTag}" on queue "${queueName}" cancelled successfully`);
104
+ this.#queueConsumers.delete(queueName);
105
+ }
106
+ catch (err) {
107
+ this.#logger?.error(`${this.#appId}: Failed to cancel consumer "${consumerTag}" for queue "${queueName}": ${err.message}`);
108
+ }
109
+ });
110
+ await Promise.all(cancellations);
111
+ this.#logger?.info(`${this.#appId}: All consumers stopped.`);
112
+ }
113
+ #onConnectionError(err) {
114
+ this.#logger?.warn(`${this.#appId}: Connection error: ${err.message}`);
115
+ }
116
+ #onConnectionClosed() {
117
+ this.#logger?.warn('Connection closed');
118
+ this.#connection = undefined;
119
+ this.#pubChannel = undefined;
120
+ this.#exclusiveQueueName = undefined;
121
+ this.#queueChannels.clear();
122
+ this.#queueConsumers.clear();
123
+ }
124
+ #getHandlers(queueGivenName = '', eventType = '*') {
125
+ return this.#subscriptions.filter(s => s.queueGivenName === queueGivenName
126
+ && (!s.eventType
127
+ || s.eventType === '*'
128
+ || s.eventType === eventType));
129
+ }
130
+ async subscribeToQueue(exchange, queueName, handler) {
131
+ return this.subscribe({ exchange, queueName, handler });
132
+ }
133
+ /**
134
+ * Subscribes to a non-durable, exclusive queue without requiring acknowledgments.
135
+ * The queue is deleted when the connection closes.
136
+ * Messages are considered "delivered" upon receipt.
137
+ * Failed message processing does not result in redelivery or dead-lettering.
138
+ */
139
+ async subscribeToFanout(exchange, handler) {
140
+ return this.subscribe({ exchange, handler, ignoreOwn: true });
141
+ }
142
+ /**
143
+ * Subscribes to events from a specified exchange.
144
+ *
145
+ * This method sets up the necessary RabbitMQ topology (exchange, queue, bindings) based on the provided details.
146
+ * If a `queueName` is provided, it asserts a durable queue with a dead-letter queue for failed messages.
147
+ * If `queueName` is omitted, it uses or creates a temporary, exclusive queue for the connection.
148
+ * Then it starts consuming messages from the queue with the specified concurrency limit, if specified.
149
+ *
150
+ * @param subscription - The subscription details.
151
+ * @param subscription.exchange - The name of the exchange to subscribe to.
152
+ * @param subscription.queueName - Optional. The name of the durable queue. If omitted, an exclusive queue is used.
153
+ * @param subscription.eventType - The routing key or pattern to bind the queue with.
154
+ * @param subscription.concurrentLimit - Optional. The maximum number of concurrent messages to process.
155
+ * @returns A promise that resolves when the subscription is successfully set up.
156
+ */
157
+ async subscribe(subscription) {
158
+ const subscriptionExists = !!this.#findSubscription(subscription);
159
+ if (subscriptionExists)
160
+ throw new Error('Subscription already exists');
161
+ const { exchange, queueName, eventType, concurrentLimit } = subscription;
162
+ const channel = await this.#assertChannel(queueName);
163
+ let queueGivenName = queueName;
164
+ if (!queueGivenName) {
165
+ // Handle temporary (exclusive) queue case
166
+ if (!this.#exclusiveQueueName) {
167
+ // Assert temporary "exclusive" queue that will be destroyed on connection termination
168
+ this.#exclusiveQueueName = await this.#assetQueue(channel, exchange, '', eventType, {
169
+ exclusive: true,
170
+ durable: false
171
+ });
172
+ }
173
+ else {
174
+ // If exclusive queue already exists, ensure it is bound with the current event type
175
+ await this.#assertBinding(channel, exchange, this.#exclusiveQueueName, eventType);
176
+ }
177
+ queueGivenName = this.#exclusiveQueueName;
178
+ }
179
+ else {
180
+ // Handle durable queue case
181
+ const deadLetterExchangeName = `${exchange}.failed`;
182
+ // Assert dead letter queue for rejected or timed out messages
183
+ await this.#assetQueue(channel, deadLetterExchangeName, `${queueGivenName}.failed`);
184
+ // Assert durable queue that will survive broker restart
185
+ await this.#assetQueue(channel, exchange, queueGivenName, eventType, { deadLetterExchangeName });
186
+ }
187
+ await this.#assertConsumer(queueGivenName, channel, concurrentLimit);
188
+ this.#subscriptions.push({ ...subscription, queueGivenName });
189
+ }
190
+ #findSubscription(subscription) {
191
+ return this.#subscriptions.find(s => s.exchange === subscription.exchange &&
192
+ s.queueName === subscription.queueName &&
193
+ s.eventType === subscription.eventType &&
194
+ s.handler === subscription.handler);
195
+ }
196
+ async unsubscribe(subscription) {
197
+ const subscriptionToRemove = this.#findSubscription(subscription);
198
+ if (!subscriptionToRemove)
199
+ throw new Error('Such subscription does not exist');
200
+ this.#subscriptions = this.#subscriptions.filter(s => s !== subscriptionToRemove);
201
+ await this.#tryDropConsumer(subscriptionToRemove.queueGivenName);
202
+ }
203
+ async #assertConnection() {
204
+ return this.#connection ?? this.connect();
205
+ }
206
+ /** Get existing or open a new channel for a given queue name */
207
+ async #assertChannel(queueName = '') {
208
+ const connection = await this.#assertConnection();
209
+ let channel = this.#queueChannels.get(queueName);
210
+ if (!channel) {
211
+ channel = await connection.createChannel();
212
+ this.#queueChannels.set(queueName, channel);
213
+ }
214
+ return channel;
215
+ }
216
+ /**
217
+ * Ensure queue, exchange, and binding exist
218
+ */
219
+ async #assetQueue(channel, exchange, queueName, eventType, options) {
220
+ const { durable = true, exclusive = false, deadLetterExchangeName } = options ?? {};
221
+ await channel.assertExchange(exchange, 'topic', { durable: true });
222
+ const { queue: queueGivenName } = await channel.assertQueue(queueName, {
223
+ exclusive,
224
+ durable,
225
+ ...deadLetterExchangeName && {
226
+ arguments: {
227
+ 'x-dead-letter-exchange': deadLetterExchangeName
228
+ }
229
+ }
230
+ });
231
+ await this.#assertBinding(channel, exchange, queueGivenName, eventType);
232
+ return queueGivenName;
233
+ }
234
+ async #assertBinding(channel, exchange, queueGivenName, eventType) {
235
+ if (!eventType || eventType === '*')
236
+ eventType = '#';
237
+ await channel.bindQueue(queueGivenName, exchange, eventType);
238
+ this.#logger?.debug(`${this.#appId}: Queue "${queueGivenName}" bound to exchange "${exchange}" with pattern "${eventType}"`);
239
+ }
240
+ async #assertConsumer(queueGivenName, channel, concurrentLimit) {
241
+ if (this.#queueConsumers.has(queueGivenName))
242
+ return;
243
+ if (concurrentLimit)
244
+ await channel.prefetch(concurrentLimit);
245
+ const c = await channel.consume(queueGivenName, async (msg) => {
246
+ if (!msg)
247
+ return;
248
+ const { consumerTag, routingKey } = msg.fields ?? {};
249
+ const { messageId, correlationId, appId } = msg.properties ?? {};
250
+ // Keep the process alive while waiting for the handler to finish
251
+ const keepAliveTimeout = setTimeout(() => {
252
+ this.#logger?.warn(`${this.#appId}: Message processing timed out`, {
253
+ queueName: queueGivenName,
254
+ consumerTag,
255
+ routingKey,
256
+ messageId
257
+ });
258
+ channel.nack(msg, false, false);
259
+ }, _a.HANDLER_PROCESS_TIMEOUT);
260
+ try {
261
+ this.#logger?.debug(`${this.#appId}: Message received`, {
262
+ queueName: queueGivenName,
263
+ consumerTag,
264
+ routingKey,
265
+ messageId,
266
+ correlationId,
267
+ appId
268
+ });
269
+ const jsonContent = msg.content.toString();
270
+ const message = JSON.parse(jsonContent);
271
+ const handlers = this.#getHandlers(queueGivenName, message.type);
272
+ if (!handlers.length && !isSystemQueue(queueGivenName))
273
+ throw new Error(`Message from queue "${queueGivenName}" was delivered to a consumer that does not handle type "${message.type}"`);
274
+ for (const { handler, ignoreOwn } of handlers) {
275
+ if (ignoreOwn && appId === this.#appId)
276
+ continue;
277
+ await handler(message);
278
+ }
279
+ channel?.ack(msg);
280
+ }
281
+ catch (err) {
282
+ this.#logger?.error(`${this.#appId}: Message processing failed: ${err.message}`);
283
+ // Redirect message to dead letter queue, if `{ noAck: true }` was not set on consumption
284
+ channel?.nack(msg, false, false);
285
+ }
286
+ finally {
287
+ clearTimeout(keepAliveTimeout);
288
+ }
289
+ });
290
+ this.#logger?.debug(`${this.#appId}: Consumer "${c.consumerTag}" registered on queue "${queueGivenName}"`);
291
+ this.#queueConsumers.set(queueGivenName, {
292
+ channel,
293
+ consumerTag: c.consumerTag
294
+ });
295
+ this.#terminationHandler?.on();
296
+ }
297
+ async #tryDropConsumer(queueGivenName) {
298
+ const queueStillUsed = this.#subscriptions.some(s => s.queueGivenName === queueGivenName);
299
+ if (queueStillUsed)
300
+ return;
301
+ const consumer = this.#queueConsumers.get(queueGivenName);
302
+ if (!consumer)
303
+ return;
304
+ this.#queueConsumers.delete(queueGivenName);
305
+ await consumer.channel.cancel(consumer.consumerTag);
306
+ // If no consumers are active anymore, disable the termination handler
307
+ if (!this.#queueConsumers.size)
308
+ this.#terminationHandler?.off();
309
+ }
310
+ /**
311
+ * Publishes an event to the fanout exchange.
312
+ * The event will be delivered to all subscribers, except this instance's own consumer.
313
+ */
314
+ async publish(exchange, message) {
315
+ if (typeof exchange !== 'string' || !exchange.length)
316
+ throw new TypeError('exchange argument must be a non-empty String');
317
+ if (!(0, interfaces_1.isMessage)(message))
318
+ throw new TypeError('valid message argument is required');
319
+ if (!this.#pubChannel) {
320
+ const connection = await this.#assertConnection();
321
+ this.#pubChannel = await connection.createConfirmChannel();
322
+ await this.#pubChannel.assertExchange(exchange, 'topic', { durable: true });
323
+ }
324
+ const content = Buffer.from(JSON.stringify(message), 'utf8');
325
+ const properties = {
326
+ contentType: 'application/json',
327
+ contentEncoding: 'utf8',
328
+ persistent: true,
329
+ timestamp: message.context?.ts ?? Date.now(),
330
+ appId: this.#appId,
331
+ type: message.type,
332
+ messageId: 'id' in message && typeof message.id === 'string' ?
333
+ message.id :
334
+ undefined,
335
+ correlationId: message.sagaId?.toString()
336
+ };
337
+ return new Promise((resolve, reject) => {
338
+ if (!this.#pubChannel)
339
+ throw new Error(`${this.#appId}: No channel available for publishing`);
340
+ this.#logger?.debug(`${this.#appId}: Publishing message "${Event.describe(message)}" to exchange "${exchange}"`);
341
+ const published = this.#pubChannel.publish(exchange, message.type, content, properties, err => (err ? reject(err) : resolve()));
342
+ if (!published)
343
+ throw new Error(`${this.#appId}: Failed to send event ${Event.describe(message)}, channel buffer is full`);
344
+ });
345
+ }
346
+ }
347
+ exports.RabbitMqGateway = RabbitMqGateway;
348
+ _a = RabbitMqGateway;
349
+ //# sourceMappingURL=RabbitMqGateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RabbitMqGateway.js","sourceRoot":"","sources":["../../src/rabbitmq/RabbitMqGateway.ts"],"names":[],"mappings":";;;;AACA,8CAAyE;AACzE,kCAAkC;AAClC,oCAAiC;AACjC,6DAA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