@geekmidas/events 0.1.0 → 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 (240) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/{BasicConnection-C4_Y0nIj.d.mts → BasicConnection-BTRsXiuH.d.cts} +3 -2
  3. package/dist/BasicConnection-BTRsXiuH.d.cts.map +1 -0
  4. package/dist/BasicConnection-Bz3F2rXA.cjs.map +1 -1
  5. package/dist/{BasicConnection-CddnULuT.d.cts → BasicConnection-DIxtA7jK.d.mts} +3 -2
  6. package/dist/BasicConnection-DIxtA7jK.d.mts.map +1 -0
  7. package/dist/BasicConnection-DOSOFSsW.mjs.map +1 -1
  8. package/dist/BasicPublisher-CaX8GCUi.mjs.map +1 -1
  9. package/dist/{BasicPublisher-DCBxaTwC.d.mts → BasicPublisher-CpJFK2oS.d.mts} +5 -3
  10. package/dist/BasicPublisher-CpJFK2oS.d.mts.map +1 -0
  11. package/dist/{BasicPublisher-V5hELHG9.d.cts → BasicPublisher-D1q0a2xp.d.cts} +5 -3
  12. package/dist/BasicPublisher-D1q0a2xp.d.cts.map +1 -0
  13. package/dist/BasicPublisher-afwuA4Xp.cjs.map +1 -1
  14. package/dist/{BasicSubscriber-BB3aKeph.d.mts → BasicSubscriber-6w0Af4DD.d.mts} +5 -3
  15. package/dist/BasicSubscriber-6w0Af4DD.d.mts.map +1 -0
  16. package/dist/{BasicSubscriber-Ckf3BkxS.cjs → BasicSubscriber-BN9fKRrU.cjs} +2 -4
  17. package/dist/BasicSubscriber-BN9fKRrU.cjs.map +1 -0
  18. package/dist/{BasicSubscriber-DPpJNUUY.mjs → BasicSubscriber-BgsKYQmi.mjs} +2 -4
  19. package/dist/BasicSubscriber-BgsKYQmi.mjs.map +1 -0
  20. package/dist/{BasicSubscriber-DOwgFw5j.d.cts → BasicSubscriber-DXxQewjc.d.cts} +5 -3
  21. package/dist/BasicSubscriber-DXxQewjc.d.cts.map +1 -0
  22. package/dist/{EventConnection-DZhn1Msl.d.cts → EventConnection-BaJRXdg7.d.cts} +2 -2
  23. package/dist/EventConnection-BaJRXdg7.d.cts.map +1 -0
  24. package/dist/EventConnection-ClLMoIUU.mjs.map +1 -1
  25. package/dist/EventConnection-F_N81SXu.cjs.map +1 -1
  26. package/dist/{EventConnection-DeXfLGom.d.mts → EventConnection-SOhtmxib.d.mts} +2 -2
  27. package/dist/EventConnection-SOhtmxib.d.mts.map +1 -0
  28. package/dist/EventConnection.d.cts +2 -2
  29. package/dist/EventConnection.d.mts +2 -2
  30. package/dist/{Publisher-C3m8JFXm.d.mts → Publisher-1CfcYRnm.d.mts} +4 -2
  31. package/dist/Publisher-1CfcYRnm.d.mts.map +1 -0
  32. package/dist/{Publisher-nXNVjL0e.d.cts → Publisher-BfNgvHwQ.d.cts} +4 -2
  33. package/dist/Publisher-BfNgvHwQ.d.cts.map +1 -0
  34. package/dist/Publisher-DS0aOh8r.mjs.map +1 -1
  35. package/dist/Publisher-ceu6OxCj.cjs.map +1 -1
  36. package/dist/Publisher.d.cts +2 -2
  37. package/dist/Publisher.d.mts +2 -2
  38. package/dist/{RabbitMQConnection-7cWp_-_Q.d.cts → RabbitMQConnection-Bm8VCI2R.d.cts} +3 -2
  39. package/dist/RabbitMQConnection-Bm8VCI2R.d.cts.map +1 -0
  40. package/dist/{RabbitMQConnection-BN_GybOv.cjs → RabbitMQConnection-CjBoCd9n.cjs} +2 -2
  41. package/dist/RabbitMQConnection-CjBoCd9n.cjs.map +1 -0
  42. package/dist/{RabbitMQConnection-C2HC7J7K.d.mts → RabbitMQConnection-Ck-ktCp_.d.mts} +3 -2
  43. package/dist/RabbitMQConnection-Ck-ktCp_.d.mts.map +1 -0
  44. package/dist/{RabbitMQConnection-eVOVS4Dl.mjs → RabbitMQConnection-DFLkr2vq.mjs} +2 -2
  45. package/dist/RabbitMQConnection-DFLkr2vq.mjs.map +1 -0
  46. package/dist/{RabbitMQPublisher-CSCn6gMA.cjs → RabbitMQPublisher-C94q6g8q.cjs} +1 -1
  47. package/dist/RabbitMQPublisher-C94q6g8q.cjs.map +1 -0
  48. package/dist/{RabbitMQPublisher-CpcbgrXj.d.cts → RabbitMQPublisher-COnxcWEZ.d.mts} +5 -3
  49. package/dist/RabbitMQPublisher-COnxcWEZ.d.mts.map +1 -0
  50. package/dist/{RabbitMQPublisher-DDZi15Ro.d.mts → RabbitMQPublisher-qQT7-1-p.d.cts} +5 -3
  51. package/dist/RabbitMQPublisher-qQT7-1-p.d.cts.map +1 -0
  52. package/dist/{RabbitMQPublisher-BZX0edgL.mjs → RabbitMQPublisher-yUqWNq-P.mjs} +1 -1
  53. package/dist/RabbitMQPublisher-yUqWNq-P.mjs.map +1 -0
  54. package/dist/{RabbitMQSubscriber-B5I-hBaT.mjs → RabbitMQSubscriber-BWniDtFs.mjs} +2 -3
  55. package/dist/RabbitMQSubscriber-BWniDtFs.mjs.map +1 -0
  56. package/dist/{RabbitMQSubscriber-BJ9PTGny.d.cts → RabbitMQSubscriber-C_sZjDPU.d.mts} +5 -3
  57. package/dist/RabbitMQSubscriber-C_sZjDPU.d.mts.map +1 -0
  58. package/dist/{RabbitMQSubscriber-CIvIw8MG.d.mts → RabbitMQSubscriber-D12sssMb.d.cts} +5 -3
  59. package/dist/RabbitMQSubscriber-D12sssMb.d.cts.map +1 -0
  60. package/dist/{RabbitMQSubscriber-Cj7qLIi6.cjs → RabbitMQSubscriber-DGEO-clQ.cjs} +2 -3
  61. package/dist/RabbitMQSubscriber-DGEO-clQ.cjs.map +1 -0
  62. package/dist/{SNSConnection-CAImaMM2.d.mts → SNSConnection-BDfQrVBO.d.cts} +3 -2
  63. package/dist/SNSConnection-BDfQrVBO.d.cts.map +1 -0
  64. package/dist/{SNSConnection-DVEE3XoC.mjs → SNSConnection-D8a31sJK.mjs} +1 -1
  65. package/dist/SNSConnection-D8a31sJK.mjs.map +1 -0
  66. package/dist/{SNSConnection-CZz_U56V.cjs → SNSConnection-DqLbiQ_X.cjs} +1 -1
  67. package/dist/SNSConnection-DqLbiQ_X.cjs.map +1 -0
  68. package/dist/{SNSConnection-Cqbr7-Ho.d.cts → SNSConnection-mHb10nQ6.d.mts} +3 -2
  69. package/dist/SNSConnection-mHb10nQ6.d.mts.map +1 -0
  70. package/dist/{SNSPublisher-DbWVH-g_.cjs → SNSPublisher-BRgwumLS.cjs} +2 -3
  71. package/dist/SNSPublisher-BRgwumLS.cjs.map +1 -0
  72. package/dist/{SNSPublisher-Dkhb4LU-.d.mts → SNSPublisher-CM7UAWtf.d.mts} +7 -6
  73. package/dist/SNSPublisher-CM7UAWtf.d.mts.map +1 -0
  74. package/dist/{SNSPublisher-Do-FMUyT.mjs → SNSPublisher-i4w_-RmP.mjs} +2 -3
  75. package/dist/SNSPublisher-i4w_-RmP.mjs.map +1 -0
  76. package/dist/{SNSPublisher-RVZFa7kL.d.cts → SNSPublisher-kpsSlGDn.d.cts} +7 -6
  77. package/dist/SNSPublisher-kpsSlGDn.d.cts.map +1 -0
  78. package/dist/{SNSSubscriber-e7eG48yJ.mjs → SNSSubscriber-BEf-H4p5.mjs} +5 -9
  79. package/dist/SNSSubscriber-BEf-H4p5.mjs.map +1 -0
  80. package/dist/{SNSSubscriber-B31JmkAE.d.mts → SNSSubscriber-DDB3--pm.d.cts} +4 -3
  81. package/dist/SNSSubscriber-DDB3--pm.d.cts.map +1 -0
  82. package/dist/{SNSSubscriber-k2UwKUxu.d.cts → SNSSubscriber-Dwo8391f.d.mts} +4 -3
  83. package/dist/SNSSubscriber-Dwo8391f.d.mts.map +1 -0
  84. package/dist/{SNSSubscriber-DpEwQ8Tb.cjs → SNSSubscriber-FYqSi346.cjs} +5 -9
  85. package/dist/SNSSubscriber-FYqSi346.cjs.map +1 -0
  86. package/dist/{SQSConnection-C5WFqZW7.d.mts → SQSConnection-B5Ep9Tma.d.cts} +3 -2
  87. package/dist/SQSConnection-B5Ep9Tma.d.cts.map +1 -0
  88. package/dist/{SQSConnection-geav2Rsn.d.cts → SQSConnection-BI_xOzyJ.d.mts} +3 -2
  89. package/dist/SQSConnection-BI_xOzyJ.d.mts.map +1 -0
  90. package/dist/{SQSConnection-BBlDWZLU.mjs → SQSConnection-BwHhXLIu.mjs} +1 -1
  91. package/dist/SQSConnection-BwHhXLIu.mjs.map +1 -0
  92. package/dist/{SQSConnection-DWYDtftQ.cjs → SQSConnection-Ctu3XY9E.cjs} +1 -1
  93. package/dist/SQSConnection-Ctu3XY9E.cjs.map +1 -0
  94. package/dist/{SQSPublisher-B3lS2zbu.mjs → SQSPublisher-BDGMw1uf.mjs} +1 -1
  95. package/dist/SQSPublisher-BDGMw1uf.mjs.map +1 -0
  96. package/dist/{SQSPublisher-CdsayOLV.d.mts → SQSPublisher-BN1ds6SN.d.mts} +5 -3
  97. package/dist/SQSPublisher-BN1ds6SN.d.mts.map +1 -0
  98. package/dist/{SQSPublisher-nzbSaXSH.cjs → SQSPublisher-C3Y_gOjV.cjs} +1 -1
  99. package/dist/SQSPublisher-C3Y_gOjV.cjs.map +1 -0
  100. package/dist/{SQSPublisher-Utb_FTe5.d.cts → SQSPublisher-DFTqwzRW.d.cts} +5 -3
  101. package/dist/SQSPublisher-DFTqwzRW.d.cts.map +1 -0
  102. package/dist/{SQSSubscriber-DcL9BbG1.cjs → SQSSubscriber-BB9TWyLA.cjs} +5 -12
  103. package/dist/SQSSubscriber-BB9TWyLA.cjs.map +1 -0
  104. package/dist/{SQSSubscriber-B6iL1EnX.d.cts → SQSSubscriber-BO2me_gs.d.cts} +4 -3
  105. package/dist/SQSSubscriber-BO2me_gs.d.cts.map +1 -0
  106. package/dist/{SQSSubscriber-DBeE4XAR.d.mts → SQSSubscriber-FyZFfr2-.d.mts} +4 -3
  107. package/dist/SQSSubscriber-FyZFfr2-.d.mts.map +1 -0
  108. package/dist/{SQSSubscriber-84pFnW1z.mjs → SQSSubscriber-ux7QEMdd.mjs} +5 -12
  109. package/dist/SQSSubscriber-ux7QEMdd.mjs.map +1 -0
  110. package/dist/Subscriber-Bd9hb_jp.mjs.map +1 -1
  111. package/dist/{Subscriber-Cff9EIpv.d.mts → Subscriber-BxT-KzFJ.d.mts} +4 -2
  112. package/dist/Subscriber-BxT-KzFJ.d.mts.map +1 -0
  113. package/dist/{Subscriber-CpAwcUzb.d.cts → Subscriber-DDD_4Nlx.d.cts} +4 -2
  114. package/dist/Subscriber-DDD_4Nlx.d.cts.map +1 -0
  115. package/dist/Subscriber-saVOWuMq.cjs.map +1 -1
  116. package/dist/Subscriber.d.cts +2 -2
  117. package/dist/Subscriber.d.mts +2 -2
  118. package/dist/basic/BasicConnection.d.cts +2 -2
  119. package/dist/basic/BasicConnection.d.mts +2 -2
  120. package/dist/basic/BasicPublisher.d.cts +3 -3
  121. package/dist/basic/BasicPublisher.d.mts +3 -3
  122. package/dist/basic/BasicSubscriber.cjs +1 -1
  123. package/dist/basic/BasicSubscriber.d.cts +3 -3
  124. package/dist/basic/BasicSubscriber.d.mts +3 -3
  125. package/dist/basic/BasicSubscriber.mjs +1 -1
  126. package/dist/basic/index.cjs +1 -1
  127. package/dist/basic/index.d.cts +4 -4
  128. package/dist/basic/index.d.mts +4 -4
  129. package/dist/basic/index.mjs +1 -1
  130. package/dist/index.d.cts +4 -4
  131. package/dist/index.d.mts +4 -4
  132. package/dist/rabbitmq/RabbitMQConnection.cjs +1 -1
  133. package/dist/rabbitmq/RabbitMQConnection.d.cts +2 -2
  134. package/dist/rabbitmq/RabbitMQConnection.d.mts +2 -2
  135. package/dist/rabbitmq/RabbitMQConnection.mjs +1 -1
  136. package/dist/rabbitmq/RabbitMQPublisher.cjs +1 -1
  137. package/dist/rabbitmq/RabbitMQPublisher.d.cts +3 -3
  138. package/dist/rabbitmq/RabbitMQPublisher.d.mts +3 -3
  139. package/dist/rabbitmq/RabbitMQPublisher.mjs +1 -1
  140. package/dist/rabbitmq/RabbitMQSubscriber.cjs +1 -1
  141. package/dist/rabbitmq/RabbitMQSubscriber.d.cts +3 -3
  142. package/dist/rabbitmq/RabbitMQSubscriber.d.mts +3 -3
  143. package/dist/rabbitmq/RabbitMQSubscriber.mjs +1 -1
  144. package/dist/rabbitmq/index.cjs +3 -3
  145. package/dist/rabbitmq/index.d.cts +4 -4
  146. package/dist/rabbitmq/index.d.mts +4 -4
  147. package/dist/rabbitmq/index.mjs +3 -3
  148. package/dist/sns/SNSConnection.cjs +1 -1
  149. package/dist/sns/SNSConnection.d.cts +2 -2
  150. package/dist/sns/SNSConnection.d.mts +2 -2
  151. package/dist/sns/SNSConnection.mjs +1 -1
  152. package/dist/sns/SNSPublisher.cjs +1 -1
  153. package/dist/sns/SNSPublisher.d.cts +3 -3
  154. package/dist/sns/SNSPublisher.d.mts +3 -3
  155. package/dist/sns/SNSPublisher.mjs +1 -1
  156. package/dist/sns/SNSSubscriber.cjs +3 -3
  157. package/dist/sns/SNSSubscriber.d.cts +3 -3
  158. package/dist/sns/SNSSubscriber.d.mts +3 -3
  159. package/dist/sns/SNSSubscriber.mjs +3 -3
  160. package/dist/sns/index.cjs +5 -5
  161. package/dist/sns/index.d.cts +4 -4
  162. package/dist/sns/index.d.mts +4 -4
  163. package/dist/sns/index.mjs +5 -5
  164. package/dist/sqs/SQSConnection.cjs +1 -1
  165. package/dist/sqs/SQSConnection.d.cts +2 -2
  166. package/dist/sqs/SQSConnection.d.mts +2 -2
  167. package/dist/sqs/SQSConnection.mjs +1 -1
  168. package/dist/sqs/SQSPublisher.cjs +1 -1
  169. package/dist/sqs/SQSPublisher.d.cts +3 -3
  170. package/dist/sqs/SQSPublisher.d.mts +3 -3
  171. package/dist/sqs/SQSPublisher.mjs +1 -1
  172. package/dist/sqs/SQSSubscriber.cjs +1 -1
  173. package/dist/sqs/SQSSubscriber.d.cts +3 -3
  174. package/dist/sqs/SQSSubscriber.d.mts +3 -3
  175. package/dist/sqs/SQSSubscriber.mjs +1 -1
  176. package/dist/sqs/index.cjs +3 -3
  177. package/dist/sqs/index.d.cts +4 -4
  178. package/dist/sqs/index.d.mts +4 -4
  179. package/dist/sqs/index.mjs +3 -3
  180. package/dist/types-B63qHVOG.mjs.map +1 -1
  181. package/dist/types-CvSMEO5z.cjs.map +1 -1
  182. package/dist/{types-D0g-o6wX.d.mts → types-DSVsPgKd.d.mts} +2 -1
  183. package/dist/types-DSVsPgKd.d.mts.map +1 -0
  184. package/dist/{types-DEGUg5BA.d.cts → types-Dmbp1U-6.d.cts} +2 -1
  185. package/dist/types-Dmbp1U-6.d.cts.map +1 -0
  186. package/dist/types.d.cts +1 -1
  187. package/dist/types.d.mts +1 -1
  188. package/package.json +3 -3
  189. package/src/EventConnection.ts +31 -31
  190. package/src/Publisher.ts +78 -78
  191. package/src/Subscriber.ts +91 -91
  192. package/src/__tests__/EventConnection.spec.ts +42 -0
  193. package/src/__tests__/Publisher.spec.ts +96 -0
  194. package/src/__tests__/Subscriber.spec.ts +91 -23
  195. package/src/basic/BasicConnection.ts +35 -35
  196. package/src/basic/BasicPublisher.ts +8 -8
  197. package/src/basic/BasicSubscriber.ts +13 -16
  198. package/src/basic/__tests__/BasicSubscriber.spec.ts +116 -116
  199. package/src/index.ts +13 -13
  200. package/src/rabbitmq/RabbitMQConnection.ts +139 -139
  201. package/src/rabbitmq/RabbitMQPublisher.ts +48 -48
  202. package/src/rabbitmq/RabbitMQSubscriber.ts +100 -102
  203. package/src/rabbitmq/__tests__/RabbitMQPublisher.spec.ts +364 -364
  204. package/src/rabbitmq/__tests__/RabbitMQSubscriber.spec.ts +204 -204
  205. package/src/rabbitmq/index.ts +3 -3
  206. package/src/sns/SNSConnection.ts +76 -76
  207. package/src/sns/SNSPublisher.ts +54 -56
  208. package/src/sns/SNSSubscriber.ts +187 -191
  209. package/src/sns/__tests__/SNS-SQS-Integration.spec.ts +321 -321
  210. package/src/sns/__tests__/SNSPublisher.spec.ts +449 -0
  211. package/src/sns/__tests__/SNSSubscriber.spec.ts +527 -0
  212. package/src/sns/index.ts +3 -3
  213. package/src/sqs/SQSConnection.ts +75 -75
  214. package/src/sqs/SQSPublisher.ts +93 -93
  215. package/src/sqs/SQSSubscriber.ts +157 -165
  216. package/src/sqs/__tests__/SQSPublisher.spec.ts +178 -178
  217. package/src/sqs/index.ts +3 -3
  218. package/src/types.ts +28 -29
  219. package/tsconfig.json +9 -0
  220. package/tsdown.config.ts +1 -1
  221. package/dist/BasicSubscriber-Ckf3BkxS.cjs.map +0 -1
  222. package/dist/BasicSubscriber-DPpJNUUY.mjs.map +0 -1
  223. package/dist/RabbitMQConnection-BN_GybOv.cjs.map +0 -1
  224. package/dist/RabbitMQConnection-eVOVS4Dl.mjs.map +0 -1
  225. package/dist/RabbitMQPublisher-BZX0edgL.mjs.map +0 -1
  226. package/dist/RabbitMQPublisher-CSCn6gMA.cjs.map +0 -1
  227. package/dist/RabbitMQSubscriber-B5I-hBaT.mjs.map +0 -1
  228. package/dist/RabbitMQSubscriber-Cj7qLIi6.cjs.map +0 -1
  229. package/dist/SNSConnection-CZz_U56V.cjs.map +0 -1
  230. package/dist/SNSConnection-DVEE3XoC.mjs.map +0 -1
  231. package/dist/SNSPublisher-DbWVH-g_.cjs.map +0 -1
  232. package/dist/SNSPublisher-Do-FMUyT.mjs.map +0 -1
  233. package/dist/SNSSubscriber-DpEwQ8Tb.cjs.map +0 -1
  234. package/dist/SNSSubscriber-e7eG48yJ.mjs.map +0 -1
  235. package/dist/SQSConnection-BBlDWZLU.mjs.map +0 -1
  236. package/dist/SQSConnection-DWYDtftQ.cjs.map +0 -1
  237. package/dist/SQSPublisher-B3lS2zbu.mjs.map +0 -1
  238. package/dist/SQSPublisher-nzbSaXSH.cjs.map +0 -1
  239. package/dist/SQSSubscriber-84pFnW1z.mjs.map +0 -1
  240. package/dist/SQSSubscriber-DcL9BbG1.cjs.map +0 -1
package/src/Publisher.ts CHANGED
@@ -1,87 +1,87 @@
1
1
  import type {
2
- EventConnection,
3
- EventPublisher,
4
- PublishableMessage,
2
+ EventConnection,
3
+ EventPublisher,
4
+ PublishableMessage,
5
5
  } from './types';
6
6
  import { EventPublisherType } from './types';
7
7
 
8
8
  export class Publisher {
9
- /**
10
- * Create a publisher from a connection string
11
- * This creates both a connection and a publisher
12
- */
13
- static async fromConnectionString<
14
- TMessage extends PublishableMessage<string, any>,
15
- >(
16
- connectionStr: EventPublisherConnectionString,
17
- ): Promise<EventPublisher<TMessage>> {
18
- const url = new URL(connectionStr);
19
- switch (url.protocol.replace(':', '')) {
20
- case EventPublisherType.Basic: {
21
- const { BasicConnection, BasicPublisher } = await import('./basic');
22
- const connection =
23
- await BasicConnection.fromConnectionString(connectionStr);
24
- return new BasicPublisher<TMessage>(connection);
25
- }
26
- case EventPublisherType.RabbitMQ: {
27
- const { RabbitMQPublisher } = await import('./rabbitmq');
28
- return RabbitMQPublisher.fromConnectionString<TMessage>(connectionStr);
29
- }
30
- case EventPublisherType.SQS: {
31
- const { SQSPublisher } = await import('./sqs');
32
- return SQSPublisher.fromConnectionString<TMessage>(connectionStr);
33
- }
34
- case EventPublisherType.SNS: {
35
- const { SNSPublisher } = await import('./sns');
36
- return SNSPublisher.fromConnectionString<TMessage>(connectionStr);
37
- }
38
- // Future implementations for EventBridge, Kafka, etc.
39
- default:
40
- throw new Error(`Unsupported event publisher type: ${url.protocol}`);
41
- }
42
- }
9
+ /**
10
+ * Create a publisher from a connection string
11
+ * This creates both a connection and a publisher
12
+ */
13
+ static async fromConnectionString<
14
+ TMessage extends PublishableMessage<string, any>,
15
+ >(
16
+ connectionStr: EventPublisherConnectionString,
17
+ ): Promise<EventPublisher<TMessage>> {
18
+ const url = new URL(connectionStr);
19
+ switch (url.protocol.replace(':', '')) {
20
+ case EventPublisherType.Basic: {
21
+ const { BasicConnection, BasicPublisher } = await import('./basic');
22
+ const connection =
23
+ await BasicConnection.fromConnectionString(connectionStr);
24
+ return new BasicPublisher<TMessage>(connection);
25
+ }
26
+ case EventPublisherType.RabbitMQ: {
27
+ const { RabbitMQPublisher } = await import('./rabbitmq');
28
+ return RabbitMQPublisher.fromConnectionString<TMessage>(connectionStr);
29
+ }
30
+ case EventPublisherType.SQS: {
31
+ const { SQSPublisher } = await import('./sqs');
32
+ return SQSPublisher.fromConnectionString<TMessage>(connectionStr);
33
+ }
34
+ case EventPublisherType.SNS: {
35
+ const { SNSPublisher } = await import('./sns');
36
+ return SNSPublisher.fromConnectionString<TMessage>(connectionStr);
37
+ }
38
+ // Future implementations for EventBridge, Kafka, etc.
39
+ default:
40
+ throw new Error(`Unsupported event publisher type: ${url.protocol}`);
41
+ }
42
+ }
43
43
 
44
- /**
45
- * Create a publisher from an existing connection
46
- * This allows sharing connections between publishers and subscribers
47
- */
48
- static async fromConnection<TMessage extends PublishableMessage<string, any>>(
49
- connection: EventConnection,
50
- ): Promise<EventPublisher<TMessage>> {
51
- switch (connection.type) {
52
- case EventPublisherType.Basic: {
53
- const { BasicPublisher } = await import('./basic');
54
- const { BasicConnection } = await import('./basic');
55
- return new BasicPublisher<TMessage>(
56
- connection as InstanceType<typeof BasicConnection>,
57
- );
58
- }
59
- case EventPublisherType.RabbitMQ: {
60
- const { RabbitMQPublisher } = await import('./rabbitmq');
61
- const { RabbitMQConnection } = await import('./rabbitmq');
62
- return new RabbitMQPublisher<TMessage>(
63
- connection as InstanceType<typeof RabbitMQConnection>,
64
- );
65
- }
66
- case EventPublisherType.SQS: {
67
- const { SQSPublisher } = await import('./sqs');
68
- const { SQSConnection } = await import('./sqs');
69
- return new SQSPublisher<TMessage>(
70
- connection as InstanceType<typeof SQSConnection>,
71
- );
72
- }
73
- case EventPublisherType.SNS: {
74
- const { SNSPublisher } = await import('./sns');
75
- const { SNSConnection } = await import('./sns');
76
- return new SNSPublisher<TMessage>(
77
- connection as InstanceType<typeof SNSConnection>,
78
- );
79
- }
80
- default:
81
- throw new Error(`Unsupported connection type: ${connection.type}`);
82
- }
83
- }
44
+ /**
45
+ * Create a publisher from an existing connection
46
+ * This allows sharing connections between publishers and subscribers
47
+ */
48
+ static async fromConnection<TMessage extends PublishableMessage<string, any>>(
49
+ connection: EventConnection,
50
+ ): Promise<EventPublisher<TMessage>> {
51
+ switch (connection.type) {
52
+ case EventPublisherType.Basic: {
53
+ const { BasicPublisher } = await import('./basic');
54
+ const { BasicConnection } = await import('./basic');
55
+ return new BasicPublisher<TMessage>(
56
+ connection as InstanceType<typeof BasicConnection>,
57
+ );
58
+ }
59
+ case EventPublisherType.RabbitMQ: {
60
+ const { RabbitMQPublisher } = await import('./rabbitmq');
61
+ const { RabbitMQConnection } = await import('./rabbitmq');
62
+ return new RabbitMQPublisher<TMessage>(
63
+ connection as InstanceType<typeof RabbitMQConnection>,
64
+ );
65
+ }
66
+ case EventPublisherType.SQS: {
67
+ const { SQSPublisher } = await import('./sqs');
68
+ const { SQSConnection } = await import('./sqs');
69
+ return new SQSPublisher<TMessage>(
70
+ connection as InstanceType<typeof SQSConnection>,
71
+ );
72
+ }
73
+ case EventPublisherType.SNS: {
74
+ const { SNSPublisher } = await import('./sns');
75
+ const { SNSConnection } = await import('./sns');
76
+ return new SNSPublisher<TMessage>(
77
+ connection as InstanceType<typeof SNSConnection>,
78
+ );
79
+ }
80
+ default:
81
+ throw new Error(`Unsupported connection type: ${connection.type}`);
82
+ }
83
+ }
84
84
  }
85
85
 
86
86
  export type EventPublisherConnectionString =
87
- `${EventPublisherType}://${string}`;
87
+ `${EventPublisherType}://${string}`;
package/src/Subscriber.ts CHANGED
@@ -1,102 +1,102 @@
1
1
  import type {
2
- EventConnection,
3
- EventSubscriber,
4
- PublishableMessage,
2
+ EventConnection,
3
+ EventSubscriber,
4
+ PublishableMessage,
5
5
  } from './types';
6
6
  import { EventPublisherType } from './types';
7
7
 
8
8
  export class Subscriber {
9
- /**
10
- * Create a subscriber from a connection string
11
- * This creates both a connection and a subscriber
12
- */
13
- static async fromConnectionString<
14
- TMessage extends PublishableMessage<string, any>,
15
- >(
16
- connectionStr: EventSubscriberConnectionString,
17
- ): Promise<EventSubscriber<TMessage>> {
18
- const url = new URL(connectionStr);
19
- switch (url.protocol.replace(':', '')) {
20
- case EventPublisherType.Basic: {
21
- const { BasicConnection, BasicSubscriber } = await import('./basic');
22
- const connection =
23
- await BasicConnection.fromConnectionString(connectionStr);
24
- return new BasicSubscriber<TMessage>(connection);
25
- }
26
- case EventPublisherType.RabbitMQ: {
27
- const { RabbitMQSubscriber } = await import('./rabbitmq');
28
- return RabbitMQSubscriber.fromConnectionString<TMessage>(connectionStr);
29
- }
30
- case EventPublisherType.SNS: {
31
- const { SNSSubscriber } = await import('./sns');
32
- return SNSSubscriber.fromConnectionString<TMessage>(connectionStr);
33
- }
34
- case EventPublisherType.SQS: {
35
- const url = new URL(connectionStr);
36
- const topicArn = url.searchParams.get('topicArn');
9
+ /**
10
+ * Create a subscriber from a connection string
11
+ * This creates both a connection and a subscriber
12
+ */
13
+ static async fromConnectionString<
14
+ TMessage extends PublishableMessage<string, any>,
15
+ >(
16
+ connectionStr: EventSubscriberConnectionString,
17
+ ): Promise<EventSubscriber<TMessage>> {
18
+ const url = new URL(connectionStr);
19
+ switch (url.protocol.replace(':', '')) {
20
+ case EventPublisherType.Basic: {
21
+ const { BasicConnection, BasicSubscriber } = await import('./basic');
22
+ const connection =
23
+ await BasicConnection.fromConnectionString(connectionStr);
24
+ return new BasicSubscriber<TMessage>(connection);
25
+ }
26
+ case EventPublisherType.RabbitMQ: {
27
+ const { RabbitMQSubscriber } = await import('./rabbitmq');
28
+ return RabbitMQSubscriber.fromConnectionString<TMessage>(connectionStr);
29
+ }
30
+ case EventPublisherType.SNS: {
31
+ const { SNSSubscriber } = await import('./sns');
32
+ return SNSSubscriber.fromConnectionString<TMessage>(connectionStr);
33
+ }
34
+ case EventPublisherType.SQS: {
35
+ const url = new URL(connectionStr);
36
+ const topicArn = url.searchParams.get('topicArn');
37
37
 
38
- // If topicArn is present, use managed SNS→SQS subscription
39
- if (topicArn) {
40
- const { SNSSubscriber } = await import('./sns');
41
- // Convert SQS connection string to SNS connection string
42
- const snsConnectionStr = connectionStr.replace('sqs://', 'sns://');
43
- return SNSSubscriber.fromConnectionString<TMessage>(snsConnectionStr);
44
- }
38
+ // If topicArn is present, use managed SNS→SQS subscription
39
+ if (topicArn) {
40
+ const { SNSSubscriber } = await import('./sns');
41
+ // Convert SQS connection string to SNS connection string
42
+ const snsConnectionStr = connectionStr.replace('sqs://', 'sns://');
43
+ return SNSSubscriber.fromConnectionString<TMessage>(snsConnectionStr);
44
+ }
45
45
 
46
- // Direct SQS subscriber
47
- const { SQSSubscriber } = await import('./sqs');
48
- const { SQSConnection } = await import('./sqs');
49
- const connection =
50
- await SQSConnection.fromConnectionString(connectionStr);
51
- return new SQSSubscriber<TMessage>(connection);
52
- }
53
- // Future implementations for EventBridge, Kafka, etc.
54
- default:
55
- throw new Error(`Unsupported event subscriber type: ${url.protocol}`);
56
- }
57
- }
46
+ // Direct SQS subscriber
47
+ const { SQSSubscriber } = await import('./sqs');
48
+ const { SQSConnection } = await import('./sqs');
49
+ const connection =
50
+ await SQSConnection.fromConnectionString(connectionStr);
51
+ return new SQSSubscriber<TMessage>(connection);
52
+ }
53
+ // Future implementations for EventBridge, Kafka, etc.
54
+ default:
55
+ throw new Error(`Unsupported event subscriber type: ${url.protocol}`);
56
+ }
57
+ }
58
58
 
59
- /**
60
- * Create a subscriber from an existing connection
61
- * This allows sharing connections between publishers and subscribers
62
- */
63
- static async fromConnection<TMessage extends PublishableMessage<string, any>>(
64
- connection: EventConnection,
65
- ): Promise<EventSubscriber<TMessage>> {
66
- switch (connection.type) {
67
- case EventPublisherType.Basic: {
68
- const { BasicSubscriber } = await import('./basic');
69
- const { BasicConnection } = await import('./basic');
70
- return new BasicSubscriber<TMessage>(
71
- connection as InstanceType<typeof BasicConnection>,
72
- );
73
- }
74
- case EventPublisherType.RabbitMQ: {
75
- const { RabbitMQSubscriber } = await import('./rabbitmq');
76
- const { RabbitMQConnection } = await import('./rabbitmq');
77
- return new RabbitMQSubscriber<TMessage>(
78
- connection as InstanceType<typeof RabbitMQConnection>,
79
- );
80
- }
81
- case EventPublisherType.SNS: {
82
- const { SNSSubscriber } = await import('./sns');
83
- const { SNSConnection } = await import('./sns');
84
- return new SNSSubscriber<TMessage>(
85
- connection as InstanceType<typeof SNSConnection>,
86
- );
87
- }
88
- case EventPublisherType.SQS: {
89
- const { SQSSubscriber } = await import('./sqs');
90
- const { SQSConnection } = await import('./sqs');
91
- return new SQSSubscriber<TMessage>(
92
- connection as InstanceType<typeof SQSConnection>,
93
- );
94
- }
95
- default:
96
- throw new Error(`Unsupported connection type: ${connection.type}`);
97
- }
98
- }
59
+ /**
60
+ * Create a subscriber from an existing connection
61
+ * This allows sharing connections between publishers and subscribers
62
+ */
63
+ static async fromConnection<TMessage extends PublishableMessage<string, any>>(
64
+ connection: EventConnection,
65
+ ): Promise<EventSubscriber<TMessage>> {
66
+ switch (connection.type) {
67
+ case EventPublisherType.Basic: {
68
+ const { BasicSubscriber } = await import('./basic');
69
+ const { BasicConnection } = await import('./basic');
70
+ return new BasicSubscriber<TMessage>(
71
+ connection as InstanceType<typeof BasicConnection>,
72
+ );
73
+ }
74
+ case EventPublisherType.RabbitMQ: {
75
+ const { RabbitMQSubscriber } = await import('./rabbitmq');
76
+ const { RabbitMQConnection } = await import('./rabbitmq');
77
+ return new RabbitMQSubscriber<TMessage>(
78
+ connection as InstanceType<typeof RabbitMQConnection>,
79
+ );
80
+ }
81
+ case EventPublisherType.SNS: {
82
+ const { SNSSubscriber } = await import('./sns');
83
+ const { SNSConnection } = await import('./sns');
84
+ return new SNSSubscriber<TMessage>(
85
+ connection as InstanceType<typeof SNSConnection>,
86
+ );
87
+ }
88
+ case EventPublisherType.SQS: {
89
+ const { SQSSubscriber } = await import('./sqs');
90
+ const { SQSConnection } = await import('./sqs');
91
+ return new SQSSubscriber<TMessage>(
92
+ connection as InstanceType<typeof SQSConnection>,
93
+ );
94
+ }
95
+ default:
96
+ throw new Error(`Unsupported connection type: ${connection.type}`);
97
+ }
98
+ }
99
99
  }
100
100
 
101
101
  export type EventSubscriberConnectionString =
102
- `${EventPublisherType}://${string}`;
102
+ `${EventPublisherType}://${string}`;
@@ -0,0 +1,42 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { EventConnectionFactory, EventPublisherType } from '../EventConnection';
3
+
4
+ describe('EventConnectionFactory', () => {
5
+ describe('fromConnectionString', () => {
6
+ it('should create BasicConnection for basic:// protocol', async () => {
7
+ const connection =
8
+ await EventConnectionFactory.fromConnectionString('basic://memory');
9
+ expect(connection).toBeDefined();
10
+ });
11
+
12
+ it('should throw for unsupported protocol', async () => {
13
+ await expect(
14
+ EventConnectionFactory.fromConnectionString('unknown://localhost'),
15
+ ).rejects.toThrow('Unsupported connection type: unknown');
16
+ });
17
+
18
+ it('should throw for invalid URL', async () => {
19
+ await expect(
20
+ EventConnectionFactory.fromConnectionString('not-a-url'),
21
+ ).rejects.toThrow();
22
+ });
23
+ });
24
+ });
25
+
26
+ describe('EventPublisherType', () => {
27
+ it('should have Basic type', () => {
28
+ expect(EventPublisherType.Basic).toBe('basic');
29
+ });
30
+
31
+ it('should have RabbitMQ type', () => {
32
+ expect(EventPublisherType.RabbitMQ).toBe('rabbitmq');
33
+ });
34
+
35
+ it('should have SQS type', () => {
36
+ expect(EventPublisherType.SQS).toBe('sqs');
37
+ });
38
+
39
+ it('should have SNS type', () => {
40
+ expect(EventPublisherType.SNS).toBe('sns');
41
+ });
42
+ });
@@ -0,0 +1,96 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { BasicConnection, BasicPublisher } from '../basic';
3
+ import { Publisher } from '../Publisher';
4
+ import { SNSConnection } from '../sns/SNSConnection';
5
+ import { SNSPublisher } from '../sns/SNSPublisher';
6
+ import { SQSConnection } from '../sqs/SQSConnection';
7
+ import { SQSPublisher } from '../sqs/SQSPublisher';
8
+ import type { PublishableMessage } from '../types';
9
+
10
+ type TestMessage = PublishableMessage<'test.event', { data: string }>;
11
+
12
+ describe('Publisher', () => {
13
+ describe('fromConnectionString', () => {
14
+ it('should create Basic publisher from basic:// connection string', async () => {
15
+ const connectionStr = 'basic://localhost';
16
+
17
+ const publisher =
18
+ await Publisher.fromConnectionString<TestMessage>(connectionStr);
19
+
20
+ expect(publisher).toBeInstanceOf(BasicPublisher);
21
+ });
22
+
23
+ it('should create SQS publisher from sqs:// connection string', async () => {
24
+ const connectionStr =
25
+ 'sqs://?queueUrl=https://sqs.us-east-1.amazonaws.com/123456789/test-queue&region=us-east-1&endpoint=http://localhost:4566';
26
+
27
+ const publisher =
28
+ await Publisher.fromConnectionString<TestMessage>(connectionStr);
29
+
30
+ expect(publisher).toBeInstanceOf(SQSPublisher);
31
+ });
32
+
33
+ it('should create SNS publisher from sns:// connection string', async () => {
34
+ const connectionStr =
35
+ 'sns://?topicArn=arn:aws:sns:us-east-1:123456789:test-topic&region=us-east-1&endpoint=http://localhost:4566&accessKeyId=test&secretAccessKey=test';
36
+
37
+ const publisher =
38
+ await Publisher.fromConnectionString<TestMessage>(connectionStr);
39
+
40
+ expect(publisher).toBeInstanceOf(SNSPublisher);
41
+ });
42
+
43
+ it('should throw error for unsupported protocol', async () => {
44
+ const connectionStr = 'unsupported://localhost';
45
+
46
+ await expect(
47
+ Publisher.fromConnectionString<TestMessage>(connectionStr),
48
+ ).rejects.toThrow('Unsupported event publisher type');
49
+ });
50
+ });
51
+
52
+ describe('fromConnection', () => {
53
+ it('should create Basic publisher from Basic connection', async () => {
54
+ const connection = new BasicConnection();
55
+ await connection.connect();
56
+
57
+ const publisher = await Publisher.fromConnection<TestMessage>(connection);
58
+
59
+ expect(publisher).toBeInstanceOf(BasicPublisher);
60
+
61
+ await connection.close();
62
+ });
63
+
64
+ it('should create SQS publisher from SQS connection', async () => {
65
+ const connection = await SQSConnection.fromConnectionString(
66
+ 'sqs://?queueUrl=https://sqs.us-east-1.amazonaws.com/123456789/test-queue&region=us-east-1&endpoint=http://localhost:4566',
67
+ );
68
+
69
+ const publisher = await Publisher.fromConnection<TestMessage>(connection);
70
+
71
+ expect(publisher).toBeInstanceOf(SQSPublisher);
72
+ });
73
+
74
+ it('should create SNS publisher from SNS connection', async () => {
75
+ const connection = await SNSConnection.fromConnectionString(
76
+ 'sns://?topicArn=arn:aws:sns:us-east-1:123456789:test-topic&region=us-east-1&endpoint=http://localhost:4566&accessKeyId=test&secretAccessKey=test',
77
+ );
78
+
79
+ const publisher = await Publisher.fromConnection<TestMessage>(connection);
80
+
81
+ expect(publisher).toBeInstanceOf(SNSPublisher);
82
+
83
+ await connection.close();
84
+ });
85
+
86
+ it('should throw error for unsupported connection type', async () => {
87
+ const fakeConnection = {
88
+ type: 'unsupported' as any,
89
+ };
90
+
91
+ await expect(
92
+ Publisher.fromConnection<TestMessage>(fakeConnection as any),
93
+ ).rejects.toThrow('Unsupported connection type');
94
+ });
95
+ });
96
+ });
@@ -1,41 +1,109 @@
1
1
  import { describe, expect, it } from 'vitest';
2
+ import { BasicConnection, BasicSubscriber } from '../basic';
2
3
  import { Subscriber } from '../Subscriber';
4
+ import { SNSConnection } from '../sns/SNSConnection';
3
5
  import { SNSSubscriber } from '../sns/SNSSubscriber';
6
+ import { SQSConnection } from '../sqs/SQSConnection';
4
7
  import { SQSSubscriber } from '../sqs/SQSSubscriber';
5
8
  import type { PublishableMessage } from '../types';
6
9
 
7
10
  type TestMessage = PublishableMessage<'test.event', { data: string }>;
8
11
 
9
12
  describe('Subscriber', () => {
10
- describe('fromConnectionString', () => {
11
- it('should create SQS subscriber without topicArn', async () => {
12
- const connectionStr =
13
- 'sqs://?queueUrl=https://sqs.us-east-1.amazonaws.com/123456789/test-queue&region=us-east-1&endpoint=http://localhost:4566';
13
+ describe('fromConnectionString', () => {
14
+ it('should create Basic subscriber from basic:// connection string', async () => {
15
+ const connectionStr = 'basic://localhost';
14
16
 
15
- const subscriber =
16
- await Subscriber.fromConnectionString<TestMessage>(connectionStr);
17
+ const subscriber =
18
+ await Subscriber.fromConnectionString<TestMessage>(connectionStr);
17
19
 
18
- expect(subscriber).toBeInstanceOf(SQSSubscriber);
19
- });
20
+ expect(subscriber).toBeInstanceOf(BasicSubscriber);
21
+ });
20
22
 
21
- it('should create SNS subscriber when topicArn is present in SQS connection string', async () => {
22
- const connectionStr =
23
- 'sqs://?topicArn=arn:aws:sns:us-east-1:123456789:test-topic&queueName=test-queue&region=us-east-1&endpoint=http://localhost:4566&accessKeyId=test&secretAccessKey=test';
23
+ it('should create SQS subscriber without topicArn', async () => {
24
+ const connectionStr =
25
+ 'sqs://?queueUrl=https://sqs.us-east-1.amazonaws.com/123456789/test-queue&region=us-east-1&endpoint=http://localhost:4566';
24
26
 
25
- const subscriber =
26
- await Subscriber.fromConnectionString<TestMessage>(connectionStr);
27
+ const subscriber =
28
+ await Subscriber.fromConnectionString<TestMessage>(connectionStr);
27
29
 
28
- expect(subscriber).toBeInstanceOf(SNSSubscriber);
29
- });
30
+ expect(subscriber).toBeInstanceOf(SQSSubscriber);
31
+ });
30
32
 
31
- it('should create SNS subscriber from sns:// connection string', async () => {
32
- const connectionStr =
33
- 'sns://?topicArn=arn:aws:sns:us-east-1:123456789:test-topic&region=us-east-1&endpoint=http://localhost:4566&accessKeyId=test&secretAccessKey=test';
33
+ it('should create SNS subscriber when topicArn is present in SQS connection string', async () => {
34
+ const connectionStr =
35
+ 'sqs://?topicArn=arn:aws:sns:us-east-1:123456789:test-topic&queueName=test-queue&region=us-east-1&endpoint=http://localhost:4566&accessKeyId=test&secretAccessKey=test';
34
36
 
35
- const subscriber =
36
- await Subscriber.fromConnectionString<TestMessage>(connectionStr);
37
+ const subscriber =
38
+ await Subscriber.fromConnectionString<TestMessage>(connectionStr);
37
39
 
38
- expect(subscriber).toBeInstanceOf(SNSSubscriber);
39
- });
40
- });
40
+ expect(subscriber).toBeInstanceOf(SNSSubscriber);
41
+ });
42
+
43
+ it('should create SNS subscriber from sns:// connection string', async () => {
44
+ const connectionStr =
45
+ 'sns://?topicArn=arn:aws:sns:us-east-1:123456789:test-topic&region=us-east-1&endpoint=http://localhost:4566&accessKeyId=test&secretAccessKey=test';
46
+
47
+ const subscriber =
48
+ await Subscriber.fromConnectionString<TestMessage>(connectionStr);
49
+
50
+ expect(subscriber).toBeInstanceOf(SNSSubscriber);
51
+ });
52
+
53
+ it('should throw error for unsupported protocol', async () => {
54
+ const connectionStr = 'unsupported://localhost';
55
+
56
+ await expect(
57
+ Subscriber.fromConnectionString<TestMessage>(connectionStr),
58
+ ).rejects.toThrow('Unsupported event subscriber type');
59
+ });
60
+ });
61
+
62
+ describe('fromConnection', () => {
63
+ it('should create Basic subscriber from Basic connection', async () => {
64
+ const connection = new BasicConnection();
65
+ await connection.connect();
66
+
67
+ const subscriber =
68
+ await Subscriber.fromConnection<TestMessage>(connection);
69
+
70
+ expect(subscriber).toBeInstanceOf(BasicSubscriber);
71
+
72
+ await connection.close();
73
+ });
74
+
75
+ it('should create SQS subscriber from SQS connection', async () => {
76
+ const connection = await SQSConnection.fromConnectionString(
77
+ 'sqs://?queueUrl=https://sqs.us-east-1.amazonaws.com/123456789/test-queue&region=us-east-1&endpoint=http://localhost:4566',
78
+ );
79
+
80
+ const subscriber =
81
+ await Subscriber.fromConnection<TestMessage>(connection);
82
+
83
+ expect(subscriber).toBeInstanceOf(SQSSubscriber);
84
+ });
85
+
86
+ it('should create SNS subscriber from SNS connection', async () => {
87
+ const connection = await SNSConnection.fromConnectionString(
88
+ 'sns://?topicArn=arn:aws:sns:us-east-1:123456789:test-topic&region=us-east-1&endpoint=http://localhost:4566&accessKeyId=test&secretAccessKey=test',
89
+ );
90
+
91
+ const subscriber =
92
+ await Subscriber.fromConnection<TestMessage>(connection);
93
+
94
+ expect(subscriber).toBeInstanceOf(SNSSubscriber);
95
+
96
+ await connection.close();
97
+ });
98
+
99
+ it('should throw error for unsupported connection type', async () => {
100
+ const fakeConnection = {
101
+ type: 'unsupported' as any,
102
+ };
103
+
104
+ await expect(
105
+ Subscriber.fromConnection<TestMessage>(fakeConnection as any),
106
+ ).rejects.toThrow('Unsupported connection type');
107
+ });
108
+ });
41
109
  });