@zdavison/matador 2.0.9 → 2.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/dist/checkpoint/context.d.ts +59 -0
  2. package/dist/checkpoint/context.d.ts.map +1 -0
  3. package/dist/checkpoint/context.js +140 -0
  4. package/dist/checkpoint/context.test.d.ts +2 -0
  5. package/dist/checkpoint/context.test.d.ts.map +1 -0
  6. package/dist/checkpoint/context.test.js +424 -0
  7. package/dist/checkpoint/index.d.ts +7 -0
  8. package/dist/checkpoint/index.d.ts.map +1 -0
  9. package/dist/checkpoint/index.js +6 -0
  10. package/dist/checkpoint/stores/memory.d.ts +29 -0
  11. package/dist/checkpoint/stores/memory.d.ts.map +1 -0
  12. package/dist/checkpoint/stores/memory.js +39 -0
  13. package/{src/checkpoint/stores/noop.ts → dist/checkpoint/stores/noop.d.ts} +5 -13
  14. package/dist/checkpoint/stores/noop.d.ts.map +1 -0
  15. package/dist/checkpoint/stores/noop.js +18 -0
  16. package/dist/checkpoint/stores/stores.test.d.ts +2 -0
  17. package/dist/checkpoint/stores/stores.test.d.ts.map +1 -0
  18. package/dist/checkpoint/stores/stores.test.js +146 -0
  19. package/dist/checkpoint/types.d.ts +119 -0
  20. package/dist/checkpoint/types.d.ts.map +1 -0
  21. package/dist/checkpoint/types.js +1 -0
  22. package/dist/codec/codec.d.ts +29 -0
  23. package/dist/codec/codec.d.ts.map +1 -0
  24. package/dist/codec/codec.js +15 -0
  25. package/dist/codec/header-aware-codec.d.ts +36 -0
  26. package/dist/codec/header-aware-codec.d.ts.map +1 -0
  27. package/dist/codec/header-aware-codec.js +1 -0
  28. package/{src/codec/index.ts → dist/codec/index.d.ts} +2 -7
  29. package/dist/codec/index.d.ts.map +1 -0
  30. package/dist/codec/index.js +3 -0
  31. package/dist/codec/json-codec.d.ts +13 -0
  32. package/dist/codec/json-codec.d.ts.map +1 -0
  33. package/dist/codec/json-codec.js +64 -0
  34. package/dist/codec/rabbitmq-codec.d.ts +28 -0
  35. package/dist/codec/rabbitmq-codec.d.ts.map +1 -0
  36. package/dist/codec/rabbitmq-codec.js +242 -0
  37. package/dist/codec/rabbitmq-codec.test.d.ts +2 -0
  38. package/dist/codec/rabbitmq-codec.test.d.ts.map +1 -0
  39. package/dist/codec/rabbitmq-codec.test.js +433 -0
  40. package/dist/core/fanout.d.ts +59 -0
  41. package/dist/core/fanout.d.ts.map +1 -0
  42. package/dist/core/fanout.js +121 -0
  43. package/dist/core/fanout.test.d.ts +2 -0
  44. package/dist/core/fanout.test.d.ts.map +1 -0
  45. package/dist/core/fanout.test.js +1054 -0
  46. package/{src/core/index.ts → dist/core/index.d.ts} +2 -7
  47. package/dist/core/index.d.ts.map +1 -0
  48. package/dist/core/index.js +3 -0
  49. package/dist/core/matador.d.ts +133 -0
  50. package/dist/core/matador.d.ts.map +1 -0
  51. package/dist/core/matador.js +228 -0
  52. package/dist/core/matador.test.d.ts +2 -0
  53. package/dist/core/matador.test.d.ts.map +1 -0
  54. package/dist/core/matador.test.js +446 -0
  55. package/dist/core/shutdown.d.ts +78 -0
  56. package/dist/core/shutdown.d.ts.map +1 -0
  57. package/dist/core/shutdown.js +111 -0
  58. package/dist/core/shutdown.test.d.ts +2 -0
  59. package/dist/core/shutdown.test.d.ts.map +1 -0
  60. package/dist/core/shutdown.test.js +524 -0
  61. package/dist/errors/checkpoint-errors.d.ts +30 -0
  62. package/dist/errors/checkpoint-errors.d.ts.map +1 -0
  63. package/dist/errors/checkpoint-errors.js +49 -0
  64. package/dist/errors/has-description.d.ts +18 -0
  65. package/dist/errors/has-description.d.ts.map +1 -0
  66. package/dist/errors/has-description.js +9 -0
  67. package/dist/errors/index.d.ts +6 -0
  68. package/dist/errors/index.d.ts.map +1 -0
  69. package/dist/errors/index.js +22 -0
  70. package/dist/errors/matador-errors.d.ts +183 -0
  71. package/dist/errors/matador-errors.d.ts.map +1 -0
  72. package/dist/errors/matador-errors.js +376 -0
  73. package/dist/errors/retry-errors.d.ts +102 -0
  74. package/dist/errors/retry-errors.d.ts.map +1 -0
  75. package/dist/errors/retry-errors.js +155 -0
  76. package/dist/errors/retry-errors.test.d.ts +2 -0
  77. package/dist/errors/retry-errors.test.d.ts.map +1 -0
  78. package/dist/errors/retry-errors.test.js +136 -0
  79. package/dist/hooks/index.d.ts +4 -0
  80. package/dist/hooks/index.d.ts.map +1 -0
  81. package/dist/hooks/index.js +2 -0
  82. package/dist/hooks/safe-hooks.d.ts +32 -0
  83. package/dist/hooks/safe-hooks.d.ts.map +1 -0
  84. package/dist/hooks/safe-hooks.js +120 -0
  85. package/dist/hooks/types.d.ts +172 -0
  86. package/dist/hooks/types.d.ts.map +1 -0
  87. package/dist/hooks/types.js +9 -0
  88. package/dist/index.cjs +3228 -0
  89. package/dist/index.cjs.map +1 -0
  90. package/dist/index.d.cts +23 -0
  91. package/dist/index.d.ts +23 -0
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/index.js +31 -0
  94. package/dist/index.js.map +1 -0
  95. package/{src/pipeline/index.ts → dist/pipeline/index.d.ts} +1 -0
  96. package/dist/pipeline/index.d.ts.map +1 -0
  97. package/dist/pipeline/index.js +1 -0
  98. package/dist/pipeline/pipeline.d.ts +63 -0
  99. package/dist/pipeline/pipeline.d.ts.map +1 -0
  100. package/dist/pipeline/pipeline.js +273 -0
  101. package/dist/pipeline/pipeline.test.d.ts +2 -0
  102. package/dist/pipeline/pipeline.test.d.ts.map +1 -0
  103. package/dist/pipeline/pipeline.test.js +1112 -0
  104. package/{src/retry/index.ts → dist/retry/index.d.ts} +1 -1
  105. package/dist/retry/index.d.ts.map +1 -0
  106. package/dist/retry/index.js +1 -0
  107. package/dist/retry/policy.d.ts +43 -0
  108. package/dist/retry/policy.d.ts.map +1 -0
  109. package/dist/retry/policy.js +1 -0
  110. package/dist/retry/standard-policy.d.ts +44 -0
  111. package/dist/retry/standard-policy.d.ts.map +1 -0
  112. package/dist/retry/standard-policy.js +102 -0
  113. package/dist/retry/standard-policy.test.d.ts +2 -0
  114. package/dist/retry/standard-policy.test.d.ts.map +1 -0
  115. package/dist/retry/standard-policy.test.js +196 -0
  116. package/dist/schema/index.d.ts +4 -0
  117. package/dist/schema/index.d.ts.map +1 -0
  118. package/dist/schema/index.js +2 -0
  119. package/dist/schema/registry.d.ts +63 -0
  120. package/dist/schema/registry.d.ts.map +1 -0
  121. package/dist/schema/registry.js +174 -0
  122. package/dist/schema/registry.test.d.ts +2 -0
  123. package/dist/schema/registry.test.d.ts.map +1 -0
  124. package/dist/schema/registry.test.js +278 -0
  125. package/{src/schema/types.ts → dist/schema/types.d.ts} +29 -88
  126. package/dist/schema/types.d.ts.map +1 -0
  127. package/dist/schema/types.js +74 -0
  128. package/dist/schema/types.test.d.ts +2 -0
  129. package/dist/schema/types.test.d.ts.map +1 -0
  130. package/dist/schema/types.test.js +242 -0
  131. package/dist/topology/builder.d.ts +80 -0
  132. package/dist/topology/builder.d.ts.map +1 -0
  133. package/dist/topology/builder.js +165 -0
  134. package/dist/topology/builder.test.d.ts +2 -0
  135. package/dist/topology/builder.test.d.ts.map +1 -0
  136. package/dist/topology/builder.test.js +360 -0
  137. package/dist/topology/index.d.ts +5 -0
  138. package/dist/topology/index.d.ts.map +1 -0
  139. package/dist/topology/index.js +2 -0
  140. package/dist/topology/types.d.ts +128 -0
  141. package/dist/topology/types.d.ts.map +1 -0
  142. package/dist/topology/types.js +28 -0
  143. package/dist/transport/capabilities.d.ts +66 -0
  144. package/dist/transport/capabilities.d.ts.map +1 -0
  145. package/dist/transport/capabilities.js +18 -0
  146. package/dist/transport/connection-manager.d.ts +95 -0
  147. package/dist/transport/connection-manager.d.ts.map +1 -0
  148. package/dist/transport/connection-manager.js +144 -0
  149. package/dist/transport/index.d.ts +11 -0
  150. package/dist/transport/index.d.ts.map +1 -0
  151. package/dist/transport/index.js +5 -0
  152. package/dist/transport/local/local-transport.d.ts +62 -0
  153. package/dist/transport/local/local-transport.d.ts.map +1 -0
  154. package/dist/transport/local/local-transport.js +241 -0
  155. package/dist/transport/local/local-transport.test.d.ts +2 -0
  156. package/dist/transport/local/local-transport.test.d.ts.map +1 -0
  157. package/dist/transport/local/local-transport.test.js +192 -0
  158. package/dist/transport/multi/multi-transport.d.ts +94 -0
  159. package/dist/transport/multi/multi-transport.d.ts.map +1 -0
  160. package/dist/transport/multi/multi-transport.js +184 -0
  161. package/dist/transport/multi/multi-transport.test.d.ts +2 -0
  162. package/dist/transport/multi/multi-transport.test.d.ts.map +1 -0
  163. package/dist/transport/multi/multi-transport.test.js +236 -0
  164. package/dist/transport/rabbitmq/rabbitmq-transport.d.ts +83 -0
  165. package/dist/transport/rabbitmq/rabbitmq-transport.d.ts.map +1 -0
  166. package/dist/transport/rabbitmq/rabbitmq-transport.js +541 -0
  167. package/dist/transport/rabbitmq/rabbitmq-transport.test.d.ts +2 -0
  168. package/dist/transport/rabbitmq/rabbitmq-transport.test.d.ts.map +1 -0
  169. package/dist/transport/rabbitmq/rabbitmq-transport.test.js +100 -0
  170. package/dist/transport/transport.d.ts +152 -0
  171. package/dist/transport/transport.d.ts.map +1 -0
  172. package/dist/transport/transport.js +1 -0
  173. package/{src/types/common.ts → dist/types/common.d.ts} +8 -20
  174. package/dist/types/common.d.ts.map +1 -0
  175. package/dist/types/common.js +12 -0
  176. package/dist/types/dispatcher.d.ts +14 -0
  177. package/dist/types/dispatcher.d.ts.map +1 -0
  178. package/dist/types/dispatcher.js +1 -0
  179. package/dist/types/envelope.d.ts +131 -0
  180. package/dist/types/envelope.d.ts.map +1 -0
  181. package/dist/types/envelope.js +99 -0
  182. package/dist/types/event.d.ts +92 -0
  183. package/dist/types/event.d.ts.map +1 -0
  184. package/dist/types/event.js +26 -0
  185. package/dist/types/event.test.d.ts +2 -0
  186. package/dist/types/event.test.d.ts.map +1 -0
  187. package/dist/types/event.test.js +130 -0
  188. package/dist/types/index.d.ts +11 -0
  189. package/dist/types/index.d.ts.map +1 -0
  190. package/dist/types/index.js +4 -0
  191. package/dist/types/subscriber.d.ts +227 -0
  192. package/dist/types/subscriber.d.ts.map +1 -0
  193. package/dist/types/subscriber.js +97 -0
  194. package/package.json +6 -2
  195. package/examples/config.ts +0 -126
  196. package/examples/event.ts +0 -26
  197. package/examples/order-event.json +0 -19
  198. package/src/checkpoint/context.test.ts +0 -510
  199. package/src/checkpoint/context.ts +0 -213
  200. package/src/checkpoint/index.ts +0 -30
  201. package/src/checkpoint/stores/memory.ts +0 -47
  202. package/src/checkpoint/stores/stores.test.ts +0 -177
  203. package/src/checkpoint/types.ts +0 -147
  204. package/src/codec/codec.ts +0 -42
  205. package/src/codec/header-aware-codec.ts +0 -41
  206. package/src/codec/json-codec.ts +0 -69
  207. package/src/codec/rabbitmq-codec.test.ts +0 -516
  208. package/src/codec/rabbitmq-codec.ts +0 -336
  209. package/src/core/fanout.test.ts +0 -1350
  210. package/src/core/fanout.ts +0 -184
  211. package/src/core/matador.test.ts +0 -575
  212. package/src/core/matador.ts +0 -357
  213. package/src/core/shutdown.test.ts +0 -853
  214. package/src/core/shutdown.ts +0 -165
  215. package/src/errors/checkpoint-errors.ts +0 -62
  216. package/src/errors/has-description.ts +0 -25
  217. package/src/errors/index.ts +0 -58
  218. package/src/errors/matador-errors.ts +0 -477
  219. package/src/errors/retry-errors.test.ts +0 -175
  220. package/src/errors/retry-errors.ts +0 -188
  221. package/src/hooks/index.ts +0 -14
  222. package/src/hooks/safe-hooks.ts +0 -200
  223. package/src/hooks/types.ts +0 -226
  224. package/src/index.ts +0 -242
  225. package/src/pipeline/pipeline.test.ts +0 -1377
  226. package/src/pipeline/pipeline.ts +0 -393
  227. package/src/retry/policy.ts +0 -46
  228. package/src/retry/standard-policy.test.ts +0 -290
  229. package/src/retry/standard-policy.ts +0 -156
  230. package/src/schema/index.ts +0 -16
  231. package/src/schema/registry.test.ts +0 -339
  232. package/src/schema/registry.ts +0 -229
  233. package/src/schema/types.test.ts +0 -280
  234. package/src/topology/builder.test.ts +0 -451
  235. package/src/topology/builder.ts +0 -238
  236. package/src/topology/index.ts +0 -19
  237. package/src/topology/types.ts +0 -183
  238. package/src/transport/capabilities.ts +0 -88
  239. package/src/transport/connection-manager.ts +0 -218
  240. package/src/transport/index.ts +0 -42
  241. package/src/transport/local/local-transport.test.ts +0 -262
  242. package/src/transport/local/local-transport.ts +0 -330
  243. package/src/transport/multi/multi-transport.test.ts +0 -320
  244. package/src/transport/multi/multi-transport.ts +0 -294
  245. package/src/transport/rabbitmq/rabbitmq-transport.test.ts +0 -120
  246. package/src/transport/rabbitmq/rabbitmq-transport.ts +0 -782
  247. package/src/transport/transport.ts +0 -200
  248. package/src/types/dispatcher.ts +0 -18
  249. package/src/types/envelope.ts +0 -244
  250. package/src/types/event.test.ts +0 -157
  251. package/src/types/event.ts +0 -112
  252. package/src/types/index.ts +0 -62
  253. package/src/types/subscriber.ts +0 -333
  254. package/test/e2e/multi-transport.e2e.test.ts +0 -237
  255. package/test/e2e/rabbitmq-transport.e2e.test.ts +0 -618
  256. package/test/e2e/transport-compliance.e2e.test.ts +0 -506
  257. package/test/integration/matador.integration.test.ts +0 -634
  258. package/tsconfig.json +0 -29
  259. package/tsup.config.ts +0 -13
@@ -0,0 +1,130 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import { createEnvelope } from './envelope.js';
3
+ import { MatadorEvent } from './event.js';
4
+ class UserCreatedEvent extends MatadorEvent {
5
+ data;
6
+ static key = 'user.created';
7
+ static description = 'Fired when a new user is created';
8
+ constructor(data) {
9
+ super();
10
+ this.data = data;
11
+ }
12
+ }
13
+ class OrderPlacedEvent extends MatadorEvent {
14
+ data;
15
+ static key = 'order.placed';
16
+ static description = 'Fired when an order is placed';
17
+ static aliases = ['order.created'];
18
+ constructor(data) {
19
+ super();
20
+ this.data = data;
21
+ }
22
+ }
23
+ class MinimalEvent extends MatadorEvent {
24
+ data;
25
+ static key = 'minimal.event';
26
+ constructor(data) {
27
+ super();
28
+ this.data = data;
29
+ }
30
+ }
31
+ describe('Event', () => {
32
+ describe('static fields', () => {
33
+ it('should have static key field on class', () => {
34
+ expect(UserCreatedEvent.key).toBe('user.created');
35
+ expect(OrderPlacedEvent.key).toBe('order.placed');
36
+ expect(MinimalEvent.key).toBe('minimal.event');
37
+ });
38
+ it('should have static description field on class when defined', () => {
39
+ expect(UserCreatedEvent.description).toBe('Fired when a new user is created');
40
+ expect(OrderPlacedEvent.description).toBe('Fired when an order is placed');
41
+ expect(MinimalEvent.description).toBeUndefined();
42
+ });
43
+ it('should have static aliases field on class when defined', () => {
44
+ expect(UserCreatedEvent.aliases).toBeUndefined();
45
+ expect(OrderPlacedEvent.aliases).toEqual(['order.created']);
46
+ expect(MinimalEvent.aliases).toBeUndefined();
47
+ });
48
+ });
49
+ describe('instance data', () => {
50
+ it('should have instance data field', () => {
51
+ const event = new UserCreatedEvent({
52
+ userId: 'usr_001',
53
+ email: 'test@example.com',
54
+ });
55
+ expect(event.data).toEqual({
56
+ userId: 'usr_001',
57
+ email: 'test@example.com',
58
+ });
59
+ });
60
+ });
61
+ });
62
+ describe('Envelope with eventDescription', () => {
63
+ it('should include eventDescription in docket when provided', () => {
64
+ const event = new UserCreatedEvent({
65
+ userId: 'usr_123',
66
+ email: 'test@example.com',
67
+ });
68
+ const envelope = createEnvelope({
69
+ eventKey: UserCreatedEvent.key,
70
+ eventDescription: UserCreatedEvent.description,
71
+ targetSubscriber: 'test-subscriber',
72
+ data: event.data,
73
+ importance: 'should-investigate',
74
+ });
75
+ expect(envelope.docket.eventKey).toBe('user.created');
76
+ expect(envelope.docket.eventDescription).toBe('Fired when a new user is created');
77
+ });
78
+ it('should not include eventDescription in docket when undefined', () => {
79
+ const event = new MinimalEvent({ id: 'min_123' });
80
+ const envelope = createEnvelope({
81
+ eventKey: MinimalEvent.key,
82
+ eventDescription: MinimalEvent.description,
83
+ targetSubscriber: 'test-subscriber',
84
+ data: event.data,
85
+ importance: 'should-investigate',
86
+ });
87
+ expect(envelope.docket.eventKey).toBe('minimal.event');
88
+ expect(envelope.docket.eventDescription).toBeUndefined();
89
+ });
90
+ it('should serialize envelope with eventDescription for logging', () => {
91
+ const event = new OrderPlacedEvent({
92
+ orderId: 'ord_456',
93
+ amount: 99.99,
94
+ });
95
+ const envelope = createEnvelope({
96
+ eventKey: OrderPlacedEvent.key,
97
+ eventDescription: OrderPlacedEvent.description,
98
+ targetSubscriber: 'order-processor',
99
+ data: event.data,
100
+ importance: 'must-investigate',
101
+ });
102
+ const serialized = JSON.stringify(envelope);
103
+ const parsed = JSON.parse(serialized);
104
+ expect(parsed.docket.eventKey).toBe('order.placed');
105
+ expect(parsed.docket.eventDescription).toBe('Fired when an order is placed');
106
+ expect(parsed.data.orderId).toBe('ord_456');
107
+ });
108
+ it('should include eventDescription in hook logging context', () => {
109
+ const event = new UserCreatedEvent({
110
+ userId: 'usr_error',
111
+ email: 'error@example.com',
112
+ });
113
+ const envelope = createEnvelope({
114
+ eventKey: UserCreatedEvent.key,
115
+ eventDescription: UserCreatedEvent.description,
116
+ targetSubscriber: 'user-handler',
117
+ data: event.data,
118
+ importance: 'should-investigate',
119
+ });
120
+ // Simulating what would be logged in onEnqueueError hook
121
+ const errorLog = {
122
+ message: 'Failed to enqueue event',
123
+ eventKey: envelope.docket.eventKey,
124
+ eventDescription: envelope.docket.eventDescription,
125
+ data: envelope.data,
126
+ };
127
+ expect(errorLog.eventKey).toBe('user.created');
128
+ expect(errorLog.eventDescription).toBe('Fired when a new user is created');
129
+ });
130
+ });
@@ -0,0 +1,11 @@
1
+ export type { DeliveryMode, Idempotency, Importance, ValidationError, ValidationResult, } from './common.js';
2
+ export { invalidResult, validResult } from './common.js';
3
+ export type { Dispatcher } from './dispatcher.js';
4
+ export type { CreateDummyEnvelopeOptions, CreateEnvelopeOptions, Docket, Envelope, } from './envelope.js';
5
+ export { createDummyEnvelope, createEnvelope } from './envelope.js';
6
+ export type { Event, EventClass, EventData, EventKey, EventOptions, EventStatic, JsonRecord, } from './event.js';
7
+ export { MatadorEvent } from './event.js';
8
+ export type { Jsonifiable } from 'type-fest';
9
+ export type { AnySubscriber, BaseSubscriberOptions, CallbackContext, CreateResumableSubscriberInput, CreateStandardSubscriberInput, CreateSubscriberInput, EnvelopeOf, ResumableCallback, ResumableCallbackContext, ResumableSubscriber, ResumableSubscriberOptions, StandardCallback, StandardSubscriber, StandardSubscriberOptions, Subscriber, SubscriberCallback, SubscriberDefinition, SubscriberOptions, SubscriberStub, } from './subscriber.js';
10
+ export { createSubscriber, createSubscriberStub, isResumableSubscriber, isStandardSubscriber, isSubscriber, isSubscriberStub, } from './subscriber.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,YAAY,EACZ,WAAW,EACX,UAAU,EACV,eAAe,EACf,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEzD,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,YAAY,EACV,0BAA0B,EAC1B,qBAAqB,EACrB,MAAM,EACN,QAAQ,GACT,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpE,YAAY,EACV,KAAK,EACL,UAAU,EACV,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,YAAY,EACV,aAAa,EACb,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,6BAA6B,EAC7B,qBAAqB,EACrB,UAAU,EACV,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,EAC1B,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,GACjB,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { invalidResult, validResult } from './common.js';
2
+ export { createDummyEnvelope, createEnvelope } from './envelope.js';
3
+ export { MatadorEvent } from './event.js';
4
+ export { createSubscriber, createSubscriberStub, isResumableSubscriber, isStandardSubscriber, isSubscriber, isSubscriberStub, } from './subscriber.js';
@@ -0,0 +1,227 @@
1
+ import type { SubscriberContext } from '../checkpoint/index.js';
2
+ import type { Idempotency, Importance } from './common.js';
3
+ import type { Dispatcher } from './dispatcher.js';
4
+ import type { Envelope } from './envelope.js';
5
+ import type { MatadorEvent } from './event.js';
6
+ /**
7
+ * Context passed to subscriber callbacks.
8
+ * Provides access to the Matador instance for sending additional events.
9
+ */
10
+ export interface CallbackContext {
11
+ /** Matador dispatcher for sending additional events from within a subscriber */
12
+ readonly matador: Dispatcher;
13
+ }
14
+ /**
15
+ * Helper type to get the envelope type for a subscriber callback.
16
+ * Extracts the data type from a MatadorEvent and wraps it in an Envelope.
17
+ *
18
+ * @example
19
+ * async callback(envelope: EnvelopeOf<MyEvent>) {
20
+ * console.log(envelope.data.someField); // Type-safe access
21
+ * }
22
+ */
23
+ export type EnvelopeOf<T extends MatadorEvent> = Envelope<T['data']>;
24
+ /**
25
+ * Callback function executed when an event is received (standard subscribers).
26
+ * Receives the full envelope containing id, data, and docket, plus a context
27
+ * with access to the matador instance for sending additional events.
28
+ *
29
+ * The callback may optionally return a value, which will be included in the
30
+ * onWorkerSuccess hook context for logging or observability purposes.
31
+ */
32
+ export type StandardCallback<T = unknown> = (envelope: Envelope<T>, context: CallbackContext) => Promise<unknown> | unknown | void;
33
+ /**
34
+ * Context for resumable subscriber callbacks.
35
+ * Combines checkpoint operations (io, all) with matador access.
36
+ */
37
+ export type ResumableCallbackContext = SubscriberContext & CallbackContext;
38
+ /**
39
+ * Callback function for resumable subscribers.
40
+ * Receives the envelope and a context with io() for checkpointed operations
41
+ * and matador for sending additional events.
42
+ *
43
+ * The callback may optionally return a value, which will be included in the
44
+ * onWorkerSuccess hook context for logging or observability purposes.
45
+ */
46
+ export type ResumableCallback<T = unknown> = (envelope: Envelope<T>, context: ResumableCallbackContext) => Promise<unknown> | unknown | void;
47
+ /**
48
+ * Callback function executed when an event is received.
49
+ * @deprecated Use StandardCallback or ResumableCallback instead.
50
+ */
51
+ export type SubscriberCallback<T = unknown> = StandardCallback<T>;
52
+ /**
53
+ * Base configuration options shared by all subscriber types.
54
+ */
55
+ export interface BaseSubscriberOptions {
56
+ /** Human-readable description of what this subscriber does */
57
+ readonly description: string;
58
+ /** Route this subscriber's events to a specific queue */
59
+ readonly targetQueue?: string | undefined;
60
+ /** Importance level for monitoring and alerting */
61
+ readonly importance?: Importance | undefined;
62
+ /** Feature flag function to conditionally enable/disable the subscriber */
63
+ readonly enabled?: (() => boolean | Promise<boolean>) | undefined;
64
+ }
65
+ /**
66
+ * Options for standard (non-resumable) subscribers.
67
+ */
68
+ export interface StandardSubscriberOptions extends BaseSubscriberOptions {
69
+ /** Idempotency declaration for retry handling (non-resumable) */
70
+ readonly idempotent?: 'yes' | 'no' | 'unknown' | undefined;
71
+ }
72
+ /**
73
+ * Options for resumable subscribers that use io() for checkpointed operations.
74
+ */
75
+ export interface ResumableSubscriberOptions extends BaseSubscriberOptions {
76
+ /** Must be 'resumable' to enable checkpoint-based idempotency */
77
+ readonly idempotent: 'resumable';
78
+ }
79
+ /**
80
+ * Configuration options for a subscriber.
81
+ * Discriminated union based on idempotent value.
82
+ */
83
+ export type SubscriberOptions = StandardSubscriberOptions | ResumableSubscriberOptions;
84
+ /**
85
+ * Standard subscriber definition with standard callback.
86
+ */
87
+ export interface StandardSubscriber<T extends MatadorEvent> extends StandardSubscriberOptions {
88
+ /** Human-readable name for the subscriber */
89
+ readonly name: string;
90
+ /** Callback function to execute when event is received */
91
+ readonly callback: StandardCallback<T['data']>;
92
+ }
93
+ /**
94
+ * Resumable subscriber definition with resumable callback.
95
+ */
96
+ export interface ResumableSubscriber<T extends MatadorEvent> extends ResumableSubscriberOptions {
97
+ /** Human-readable name for the subscriber */
98
+ readonly name: string;
99
+ /** Callback function with SubscriberContext for checkpointed operations */
100
+ readonly callback: ResumableCallback<T['data']>;
101
+ }
102
+ /**
103
+ * Full subscriber definition with callback (either standard or resumable).
104
+ */
105
+ export type Subscriber<T extends MatadorEvent> = StandardSubscriber<T> | ResumableSubscriber<T>;
106
+ /**
107
+ * Subscriber stub for multi-codebase scenarios where subscriber implementation
108
+ * is in a remote service. Declares the subscriber contract without providing
109
+ * the callback.
110
+ */
111
+ export interface SubscriberStub extends Omit<StandardSubscriberOptions, 'description'> {
112
+ /** Human-readable name for the subscriber */
113
+ readonly name: string;
114
+ /** Indicates this is a stub without implementation */
115
+ readonly isStub: true;
116
+ }
117
+ /**
118
+ * Union type for any subscriber definition (full or stub).
119
+ * This is the type-erased version for use in collections and schema.
120
+ * Uses `any` because Subscriber<T> is contravariant in T (callback parameter),
121
+ * making it impossible to assign Subscriber<SpecificEvent> to Subscriber<MatadorEvent<unknown>>.
122
+ */
123
+ export type AnySubscriber = Subscriber<MatadorEvent<any>> | SubscriberStub;
124
+ /**
125
+ * Type guard to check if a subscriber is a stub.
126
+ */
127
+ export declare function isSubscriberStub(subscriber: AnySubscriber): subscriber is SubscriberStub;
128
+ /**
129
+ * Type guard to check if a subscriber has a callback implementation.
130
+ */
131
+ export declare function isSubscriber(subscriber: AnySubscriber): subscriber is Subscriber<MatadorEvent<any>>;
132
+ /**
133
+ * Type guard to check if a subscriber is resumable.
134
+ */
135
+ export declare function isResumableSubscriber(subscriber: AnySubscriber): subscriber is ResumableSubscriber<MatadorEvent<any>>;
136
+ /**
137
+ * Type guard to check if a subscriber is a standard (non-resumable) subscriber.
138
+ */
139
+ export declare function isStandardSubscriber(subscriber: AnySubscriber): subscriber is StandardSubscriber<MatadorEvent<any>>;
140
+ /**
141
+ * Input options for createSubscriber with standard callback.
142
+ */
143
+ export interface CreateStandardSubscriberInput<T extends MatadorEvent> {
144
+ readonly name: string;
145
+ readonly description: string;
146
+ readonly callback: StandardCallback<T['data']>;
147
+ readonly idempotent?: 'yes' | 'no' | 'unknown' | undefined;
148
+ readonly importance?: Importance | undefined;
149
+ readonly targetQueue?: string | undefined;
150
+ readonly enabled?: (() => boolean | Promise<boolean>) | undefined;
151
+ }
152
+ /**
153
+ * Input options for createSubscriber with resumable callback.
154
+ */
155
+ export interface CreateResumableSubscriberInput<T extends MatadorEvent> {
156
+ readonly name: string;
157
+ readonly description: string;
158
+ readonly callback: ResumableCallback<T['data']>;
159
+ readonly idempotent: 'resumable';
160
+ readonly importance?: Importance | undefined;
161
+ readonly targetQueue?: string | undefined;
162
+ readonly enabled?: (() => boolean | Promise<boolean>) | undefined;
163
+ }
164
+ /**
165
+ * Input options for createSubscriber (discriminated union).
166
+ */
167
+ export type CreateSubscriberInput<T extends MatadorEvent> = CreateStandardSubscriberInput<T> | CreateResumableSubscriberInput<T>;
168
+ /**
169
+ * Creates a subscriber definition.
170
+ *
171
+ * @example Standard subscriber
172
+ * ```typescript
173
+ * const subscriber = createSubscriber<MyEvent>({
174
+ * name: 'my-subscriber',
175
+ * description: 'Handles MyEvent by logging the data',
176
+ * callback: async (envelope) => {
177
+ * console.log(envelope.data);
178
+ * },
179
+ * });
180
+ * ```
181
+ *
182
+ * @example Resumable subscriber with io()
183
+ * ```typescript
184
+ * const subscriber = createSubscriber<MyEvent>({
185
+ * name: 'my-resumable-subscriber',
186
+ * description: 'Processes MyEvent with checkpoint-based idempotency',
187
+ * idempotent: 'resumable',
188
+ * callback: async (envelope, { io }) => {
189
+ * await io('step-1', () => doSomething());
190
+ * },
191
+ * });
192
+ * ```
193
+ */
194
+ export declare function createSubscriber<T extends MatadorEvent>(input: CreateSubscriberInput<T>): Subscriber<T>;
195
+ /**
196
+ * Input options for createSubscriberStub.
197
+ */
198
+ export interface CreateSubscriberStubInput {
199
+ readonly name: string;
200
+ readonly idempotent?: 'yes' | 'no' | 'unknown' | undefined;
201
+ readonly importance?: Importance | undefined;
202
+ readonly targetQueue?: string | undefined;
203
+ readonly enabled?: (() => boolean | Promise<boolean>) | undefined;
204
+ }
205
+ /**
206
+ * Creates a subscriber stub for remote implementations.
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * const stub = createSubscriberStub({
211
+ * name: 'remote-analytics',
212
+ * targetQueue: 'analytics-worker',
213
+ * });
214
+ * ```
215
+ */
216
+ export declare function createSubscriberStub(input: CreateSubscriberStubInput): SubscriberStub;
217
+ /**
218
+ * Definition interface used by the pipeline (excludes event class reference).
219
+ */
220
+ export interface SubscriberDefinition {
221
+ readonly name: string;
222
+ readonly description?: string | undefined;
223
+ readonly idempotent: Idempotency;
224
+ readonly importance: Importance;
225
+ readonly targetQueue?: string | undefined;
226
+ }
227
+ //# sourceMappingURL=subscriber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriber.d.ts","sourceRoot":"","sources":["../../src/types/subscriber.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,gFAAgF;IAChF,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;CAC9B;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,CAAC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AAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3C"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Type guard to check if a subscriber is a stub.
3
+ */
4
+ export function isSubscriberStub(subscriber) {
5
+ return 'isStub' in subscriber && subscriber.isStub === true;
6
+ }
7
+ /**
8
+ * Type guard to check if a subscriber has a callback implementation.
9
+ */
10
+ export function isSubscriber(subscriber) {
11
+ return 'callback' in subscriber && typeof subscriber.callback === 'function';
12
+ }
13
+ /**
14
+ * Type guard to check if a subscriber is resumable.
15
+ */
16
+ export function isResumableSubscriber(subscriber) {
17
+ return isSubscriber(subscriber) && subscriber.idempotent === 'resumable';
18
+ }
19
+ /**
20
+ * Type guard to check if a subscriber is a standard (non-resumable) subscriber.
21
+ */
22
+ export function isStandardSubscriber(subscriber) {
23
+ return isSubscriber(subscriber) && subscriber.idempotent !== 'resumable';
24
+ }
25
+ /**
26
+ * Creates a subscriber definition.
27
+ *
28
+ * @example Standard subscriber
29
+ * ```typescript
30
+ * const subscriber = createSubscriber<MyEvent>({
31
+ * name: 'my-subscriber',
32
+ * description: 'Handles MyEvent by logging the data',
33
+ * callback: async (envelope) => {
34
+ * console.log(envelope.data);
35
+ * },
36
+ * });
37
+ * ```
38
+ *
39
+ * @example Resumable subscriber with io()
40
+ * ```typescript
41
+ * const subscriber = createSubscriber<MyEvent>({
42
+ * name: 'my-resumable-subscriber',
43
+ * description: 'Processes MyEvent with checkpoint-based idempotency',
44
+ * idempotent: 'resumable',
45
+ * callback: async (envelope, { io }) => {
46
+ * await io('step-1', () => doSomething());
47
+ * },
48
+ * });
49
+ * ```
50
+ */
51
+ export function createSubscriber(input) {
52
+ const base = {
53
+ name: input.name,
54
+ description: input.description,
55
+ callback: input.callback,
56
+ importance: input.importance ?? 'should-investigate',
57
+ ...(input.targetQueue !== undefined && {
58
+ targetQueue: input.targetQueue,
59
+ }),
60
+ ...(input.enabled !== undefined && { enabled: input.enabled }),
61
+ };
62
+ if (input.idempotent === 'resumable') {
63
+ return {
64
+ ...base,
65
+ idempotent: 'resumable',
66
+ callback: input.callback,
67
+ };
68
+ }
69
+ return {
70
+ ...base,
71
+ idempotent: input.idempotent ?? 'unknown',
72
+ callback: input.callback,
73
+ };
74
+ }
75
+ /**
76
+ * Creates a subscriber stub for remote implementations.
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const stub = createSubscriberStub({
81
+ * name: 'remote-analytics',
82
+ * targetQueue: 'analytics-worker',
83
+ * });
84
+ * ```
85
+ */
86
+ export function createSubscriberStub(input) {
87
+ return {
88
+ name: input.name,
89
+ isStub: true,
90
+ idempotent: input.idempotent ?? 'unknown',
91
+ importance: input.importance ?? 'should-investigate',
92
+ ...(input.targetQueue !== undefined && {
93
+ targetQueue: input.targetQueue,
94
+ }),
95
+ ...(input.enabled !== undefined && { enabled: input.enabled }),
96
+ };
97
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zdavison/matador",
3
- "version": "2.0.9",
3
+ "version": "2.0.10",
4
4
  "description": "A batteries-included event system.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -63,5 +63,9 @@
63
63
  "kafka",
64
64
  "transport"
65
65
  ],
66
- "license": "MIT"
66
+ "license": "MIT",
67
+ "files": [
68
+ "dist",
69
+ "cli.ts"
70
+ ]
67
71
  }
@@ -1,126 +0,0 @@
1
- /**
2
- * Example Matador configuration for CLI testing
3
- *
4
- * This file demonstrates how to structure a config file for the CLI.
5
- * It exports:
6
- * - schema: MatadorSchema mapping event keys to event classes and subscribers
7
- * - topology: Topology configuration
8
- */
9
-
10
- import {
11
- MatadorEvent,
12
- type MatadorSchema,
13
- type Topology,
14
- TopologyBuilder,
15
- createSubscriber,
16
- } from '../src/index.js';
17
-
18
- // ============================================================================
19
- // Events
20
- // ============================================================================
21
-
22
- export class UserCreatedEvent extends MatadorEvent {
23
- static readonly key = 'user.created';
24
- static readonly description = 'Fired when a new user is created';
25
-
26
- constructor(
27
- public data: {
28
- userId: string;
29
- email: string;
30
- name: string;
31
- },
32
- ) {
33
- super();
34
- }
35
- }
36
-
37
- export class OrderPlacedEvent extends MatadorEvent {
38
- static readonly key = 'order.placed';
39
- static readonly description = 'Fired when a new order is placed';
40
-
41
- constructor(
42
- public data: {
43
- orderId: string;
44
- userId: string;
45
- amount: number;
46
- items: Array<{ productId: string; quantity: number }>;
47
- },
48
- ) {
49
- super();
50
- }
51
- }
52
-
53
- // ============================================================================
54
- // Subscribers
55
- // ============================================================================
56
-
57
- const sendWelcomeEmail = createSubscriber({
58
- name: 'send-welcome-email',
59
- description: 'Sends a welcome email to newly registered users',
60
- callback: async ({ data, docket }) => {
61
- console.log(` 📧 Sending welcome email to ${data.email}`);
62
- console.log(` User: ${data.name} (${data.userId})`);
63
- if (docket.correlationId) {
64
- console.log(` Correlation ID: ${docket.correlationId}`);
65
- }
66
- },
67
- idempotent: 'yes',
68
- importance: 'should-investigate',
69
- });
70
-
71
- const trackUserAnalytics = createSubscriber({
72
- name: 'track-user-analytics',
73
- description: 'Tracks user creation in analytics system',
74
- callback: async ({ data }) => {
75
- console.log(` 📊 Tracking analytics for new user: ${data.userId}`);
76
- },
77
- idempotent: 'yes',
78
- importance: 'can-ignore',
79
- });
80
-
81
- const processOrder = createSubscriber({
82
- name: 'process-order',
83
- description: 'Processes order for fulfillment',
84
- callback: async ({ data }) => {
85
- console.log(` 📦 Processing order ${data.orderId}`);
86
- console.log(` Amount: $${data.amount.toFixed(2)}`);
87
- console.log(` Items: ${data.items.length} item(s)`);
88
- },
89
- idempotent: 'no',
90
- importance: 'must-investigate',
91
- });
92
-
93
- const sendOrderConfirmation = createSubscriber({
94
- name: 'send-order-confirmation',
95
- description: 'Sends order confirmation email to customer',
96
- callback: async ({ data }) => {
97
- console.log(` 📧 Sending order confirmation for ${data.orderId}`);
98
- },
99
- idempotent: 'yes',
100
- importance: 'should-investigate',
101
- });
102
-
103
- // ============================================================================
104
- // Exports
105
- // ============================================================================
106
-
107
- /**
108
- * Matador schema mapping event keys to event classes and their subscribers.
109
- * Uses the tuple format: [EventClass, Subscribers[]]
110
- */
111
- export const schema: MatadorSchema = {
112
- [UserCreatedEvent.key]: [
113
- UserCreatedEvent,
114
- [sendWelcomeEmail, trackUserAnalytics],
115
- ],
116
- [OrderPlacedEvent.key]: [
117
- OrderPlacedEvent,
118
- [processOrder, sendOrderConfirmation],
119
- ],
120
- };
121
-
122
- export const topology: Topology = TopologyBuilder.create()
123
- .withNamespace('example')
124
- .addQueue('events', { concurrency: 5 })
125
- .withoutDeadLetter()
126
- .build();
package/examples/event.ts DELETED
@@ -1,26 +0,0 @@
1
- /**
2
- * Example event file for CLI testing
3
- *
4
- * This file demonstrates how to structure an event file for the CLI.
5
- * It exports:
6
- * - eventKey: The key of the event to dispatch (must match an event in config)
7
- * - data: The event payload
8
- * - before: (optional) Previous state for change events
9
- * - options: (optional) Dispatch options like correlationId, metadata
10
- */
11
-
12
- export const eventKey = 'user.created';
13
-
14
- export const data = {
15
- userId: 'usr_12345',
16
- email: 'alice@example.com',
17
- name: 'Alice Smith',
18
- };
19
-
20
- export const options = {
21
- correlationId: 'req_abc123',
22
- metadata: {
23
- source: 'cli-test',
24
- timestamp: new Date().toISOString(),
25
- },
26
- };
@@ -1,19 +0,0 @@
1
- {
2
- "eventKey": "order.placed",
3
- "data": {
4
- "orderId": "ord_98765",
5
- "userId": "usr_12345",
6
- "amount": 149.99,
7
- "items": [
8
- { "productId": "prod_001", "quantity": 2 },
9
- { "productId": "prod_002", "quantity": 1 }
10
- ]
11
- },
12
- "options": {
13
- "correlationId": "req_xyz789",
14
- "metadata": {
15
- "source": "cli-test",
16
- "channel": "web"
17
- }
18
- }
19
- }