@zdavison/matador 2.0.8 → 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 (77) hide show
  1. package/dist/index.d.cts +1 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/package.json +6 -2
  5. package/examples/config.ts +0 -126
  6. package/examples/event.ts +0 -26
  7. package/examples/order-event.json +0 -19
  8. package/src/checkpoint/context.test.ts +0 -510
  9. package/src/checkpoint/context.ts +0 -213
  10. package/src/checkpoint/index.ts +0 -30
  11. package/src/checkpoint/stores/memory.ts +0 -47
  12. package/src/checkpoint/stores/noop.ts +0 -22
  13. package/src/checkpoint/stores/stores.test.ts +0 -177
  14. package/src/checkpoint/types.ts +0 -147
  15. package/src/codec/codec.ts +0 -42
  16. package/src/codec/header-aware-codec.ts +0 -41
  17. package/src/codec/index.ts +0 -11
  18. package/src/codec/json-codec.ts +0 -69
  19. package/src/codec/rabbitmq-codec.test.ts +0 -516
  20. package/src/codec/rabbitmq-codec.ts +0 -336
  21. package/src/core/fanout.test.ts +0 -1350
  22. package/src/core/fanout.ts +0 -184
  23. package/src/core/index.ts +0 -12
  24. package/src/core/matador.test.ts +0 -575
  25. package/src/core/matador.ts +0 -357
  26. package/src/core/shutdown.test.ts +0 -853
  27. package/src/core/shutdown.ts +0 -165
  28. package/src/errors/checkpoint-errors.ts +0 -62
  29. package/src/errors/has-description.ts +0 -25
  30. package/src/errors/index.ts +0 -58
  31. package/src/errors/matador-errors.ts +0 -477
  32. package/src/errors/retry-errors.test.ts +0 -175
  33. package/src/errors/retry-errors.ts +0 -188
  34. package/src/hooks/index.ts +0 -14
  35. package/src/hooks/safe-hooks.ts +0 -200
  36. package/src/hooks/types.ts +0 -226
  37. package/src/index.ts +0 -241
  38. package/src/pipeline/index.ts +0 -2
  39. package/src/pipeline/pipeline.test.ts +0 -1377
  40. package/src/pipeline/pipeline.ts +0 -393
  41. package/src/retry/index.ts +0 -4
  42. package/src/retry/policy.ts +0 -46
  43. package/src/retry/standard-policy.test.ts +0 -290
  44. package/src/retry/standard-policy.ts +0 -156
  45. package/src/schema/index.ts +0 -16
  46. package/src/schema/registry.test.ts +0 -339
  47. package/src/schema/registry.ts +0 -229
  48. package/src/schema/types.test.ts +0 -280
  49. package/src/schema/types.ts +0 -217
  50. package/src/topology/builder.test.ts +0 -451
  51. package/src/topology/builder.ts +0 -238
  52. package/src/topology/index.ts +0 -19
  53. package/src/topology/types.ts +0 -183
  54. package/src/transport/capabilities.ts +0 -88
  55. package/src/transport/connection-manager.ts +0 -218
  56. package/src/transport/index.ts +0 -42
  57. package/src/transport/local/local-transport.test.ts +0 -262
  58. package/src/transport/local/local-transport.ts +0 -330
  59. package/src/transport/multi/multi-transport.test.ts +0 -320
  60. package/src/transport/multi/multi-transport.ts +0 -294
  61. package/src/transport/rabbitmq/rabbitmq-transport.test.ts +0 -120
  62. package/src/transport/rabbitmq/rabbitmq-transport.ts +0 -782
  63. package/src/transport/transport.ts +0 -200
  64. package/src/types/common.ts +0 -53
  65. package/src/types/dispatcher.ts +0 -18
  66. package/src/types/envelope.ts +0 -244
  67. package/src/types/event.test.ts +0 -157
  68. package/src/types/event.ts +0 -112
  69. package/src/types/index.ts +0 -62
  70. package/src/types/subscriber.ts +0 -333
  71. package/test/e2e/multi-transport.e2e.test.ts +0 -237
  72. package/test/e2e/rabbitmq-transport.e2e.test.ts +0 -618
  73. package/test/e2e/transport-compliance.e2e.test.ts +0 -506
  74. package/test/integration/matador.integration.test.ts +0 -634
  75. package/tsconfig.json +0 -29
  76. package/tsconfig.tsbuildinfo +0 -1
  77. package/tsup.config.ts +0 -13
@@ -1,112 +0,0 @@
1
- import type { Jsonifiable } from 'type-fest';
2
-
3
- /**
4
- * Unique event routing key type alias.
5
- */
6
- export type EventKey = string;
7
-
8
- /**
9
- * JSON-serializable record type for metadata.
10
- * Uses type-fest's Jsonifiable which accepts:
11
- * - Primitives (string, number, boolean, null)
12
- * - Arrays of Jsonifiable values
13
- * - Objects with Jsonifiable values
14
- * - Objects with a toJSON() method
15
- */
16
- export type JsonRecord = Record<string, Jsonifiable>;
17
-
18
- /**
19
- * Static properties required on Event classes for schema registration.
20
- */
21
- export interface EventStatic<T = unknown> {
22
- /** Unique routing key for the event */
23
- readonly key: string;
24
-
25
- /** Human-readable description of the event */
26
- readonly description?: string;
27
-
28
- /** Alternative names/keys for backwards compatibility */
29
- readonly aliases?: readonly string[];
30
-
31
- /** Create an instance from data (for deserialization) */
32
- new (data: T): Event<T>;
33
- }
34
-
35
- /**
36
- * Base interface for all events.
37
- * Events represent something that happened in the system.
38
- */
39
- export interface Event<T = unknown> {
40
- /** The event data/payload */
41
- readonly data: T;
42
-
43
- /** Event-specific metadata (merged with EventOptions metadata on dispatch) */
44
- readonly metadata?: JsonRecord | undefined;
45
- }
46
-
47
- /**
48
- * Options for dispatching an event.
49
- */
50
- export interface EventOptions {
51
- /** Delay processing by this many milliseconds */
52
- readonly delayMs?: number | undefined;
53
-
54
- /** Correlation ID for request tracing */
55
- readonly correlationId?: string | undefined;
56
-
57
- /**
58
- * Event-specific metadata to include in the docket.
59
- * This metadata will be merged with:
60
- * 1. Event instance metadata (if defined on the event)
61
- * 2. Universal metadata from the loadUniversalMetadata hook
62
- * With EventOptions metadata taking precedence over event metadata,
63
- * and both taking precedence over universal metadata.
64
- */
65
- readonly metadata?: JsonRecord | undefined;
66
- }
67
-
68
- /**
69
- * Abstract base class for creating Matador events.
70
- * Extend this class to define custom events.
71
- *
72
- * @example
73
- * ```typescript
74
- * class UserCreatedEvent extends MatadorEvent {
75
- * static readonly key = 'user.created'
76
- * static readonly description = 'Fired when a new user is created'
77
- *
78
- * constructor(
79
- * public data: { userId: string; email: string },
80
- * public metadata?: JsonRecord,
81
- * ) {
82
- * super()
83
- * }
84
- * }
85
- * ```
86
- */
87
- export abstract class MatadorEvent<T = unknown> implements Event<T> {
88
- static readonly key: string;
89
- static readonly description?: string;
90
- static readonly aliases?: readonly string[];
91
-
92
- /** The event data/payload - must be defined by subclass */
93
- abstract readonly data: T;
94
-
95
- /** Event-specific metadata */
96
- readonly metadata?: JsonRecord | undefined;
97
- }
98
-
99
- /**
100
- * Type helper to extract the data type from an event class.
101
- */
102
- export type EventData<E extends Event<unknown>> = E extends Event<infer T>
103
- ? T
104
- : never;
105
-
106
- /**
107
- * Type helper to get the event class type.
108
- */
109
- export type EventClass<T = unknown> = EventStatic<T> &
110
- (new (
111
- data: T,
112
- ) => Event<T>);
@@ -1,62 +0,0 @@
1
- export type {
2
- DeliveryMode,
3
- Idempotency,
4
- Importance,
5
- ValidationError,
6
- ValidationResult,
7
- } from './common.js';
8
- export { invalidResult, validResult } from './common.js';
9
-
10
- export type { Dispatcher } from './dispatcher.js';
11
-
12
- export type {
13
- CreateDummyEnvelopeOptions,
14
- CreateEnvelopeOptions,
15
- Docket,
16
- Envelope,
17
- } from './envelope.js';
18
- export { createDummyEnvelope, createEnvelope } from './envelope.js';
19
-
20
- export type {
21
- Event,
22
- EventClass,
23
- EventData,
24
- EventKey,
25
- EventOptions,
26
- EventStatic,
27
- JsonRecord,
28
- } from './event.js';
29
- export { MatadorEvent } from './event.js';
30
-
31
- // Re-export Jsonifiable from type-fest for convenience
32
- export type { Jsonifiable } from 'type-fest';
33
-
34
- export type {
35
- AnySubscriber,
36
- BaseSubscriberOptions,
37
- CallbackContext,
38
- CreateResumableSubscriberInput,
39
- CreateStandardSubscriberInput,
40
- CreateSubscriberInput,
41
- EnvelopeOf,
42
- ResumableCallback,
43
- ResumableCallbackContext,
44
- ResumableSubscriber,
45
- ResumableSubscriberOptions,
46
- StandardCallback,
47
- StandardSubscriber,
48
- StandardSubscriberOptions,
49
- Subscriber,
50
- SubscriberCallback,
51
- SubscriberDefinition,
52
- SubscriberOptions,
53
- SubscriberStub,
54
- } from './subscriber.js';
55
- export {
56
- createSubscriber,
57
- createSubscriberStub,
58
- isResumableSubscriber,
59
- isStandardSubscriber,
60
- isSubscriber,
61
- isSubscriberStub,
62
- } from './subscriber.js';
@@ -1,333 +0,0 @@
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
- /**
8
- * Context passed to subscriber callbacks.
9
- * Provides access to the Matador instance for sending additional events.
10
- */
11
- export interface CallbackContext {
12
- /** Matador dispatcher for sending additional events from within a subscriber */
13
- readonly matador: Dispatcher;
14
- }
15
-
16
- /**
17
- * Helper type to get the envelope type for a subscriber callback.
18
- * Extracts the data type from a MatadorEvent and wraps it in an Envelope.
19
- *
20
- * @example
21
- * async callback(envelope: EnvelopeOf<MyEvent>) {
22
- * console.log(envelope.data.someField); // Type-safe access
23
- * }
24
- */
25
- export type EnvelopeOf<T extends MatadorEvent> = Envelope<T['data']>;
26
-
27
- /**
28
- * Callback function executed when an event is received (standard subscribers).
29
- * Receives the full envelope containing id, data, and docket, plus a context
30
- * with access to the matador instance for sending additional events.
31
- *
32
- * The callback may optionally return a value, which will be included in the
33
- * onWorkerSuccess hook context for logging or observability purposes.
34
- */
35
- export type StandardCallback<T = unknown> = (
36
- envelope: Envelope<T>,
37
- context: CallbackContext,
38
- ) => Promise<unknown> | unknown | void;
39
-
40
- /**
41
- * Context for resumable subscriber callbacks.
42
- * Combines checkpoint operations (io, all) with matador access.
43
- */
44
- export type ResumableCallbackContext = SubscriberContext & CallbackContext;
45
-
46
- /**
47
- * Callback function for resumable subscribers.
48
- * Receives the envelope and a context with io() for checkpointed operations
49
- * and matador for sending additional events.
50
- *
51
- * The callback may optionally return a value, which will be included in the
52
- * onWorkerSuccess hook context for logging or observability purposes.
53
- */
54
- export type ResumableCallback<T = unknown> = (
55
- envelope: Envelope<T>,
56
- context: ResumableCallbackContext,
57
- ) => Promise<unknown> | unknown | void;
58
-
59
- /**
60
- * Callback function executed when an event is received.
61
- * @deprecated Use StandardCallback or ResumableCallback instead.
62
- */
63
- export type SubscriberCallback<T = unknown> = StandardCallback<T>;
64
-
65
- /**
66
- * Base configuration options shared by all subscriber types.
67
- */
68
- export interface BaseSubscriberOptions {
69
- /** Human-readable description of what this subscriber does */
70
- readonly description: string;
71
-
72
- /** Route this subscriber's events to a specific queue */
73
- readonly targetQueue?: string | undefined;
74
-
75
- /** Importance level for monitoring and alerting */
76
- readonly importance?: Importance | undefined;
77
-
78
- /** Feature flag function to conditionally enable/disable the subscriber */
79
- readonly enabled?: (() => boolean | Promise<boolean>) | undefined;
80
- }
81
-
82
- /**
83
- * Options for standard (non-resumable) subscribers.
84
- */
85
- export interface StandardSubscriberOptions extends BaseSubscriberOptions {
86
- /** Idempotency declaration for retry handling (non-resumable) */
87
- readonly idempotent?: 'yes' | 'no' | 'unknown' | undefined;
88
- }
89
-
90
- /**
91
- * Options for resumable subscribers that use io() for checkpointed operations.
92
- */
93
- export interface ResumableSubscriberOptions extends BaseSubscriberOptions {
94
- /** Must be 'resumable' to enable checkpoint-based idempotency */
95
- readonly idempotent: 'resumable';
96
- }
97
-
98
- /**
99
- * Configuration options for a subscriber.
100
- * Discriminated union based on idempotent value.
101
- */
102
- export type SubscriberOptions =
103
- | StandardSubscriberOptions
104
- | ResumableSubscriberOptions;
105
-
106
- /**
107
- * Standard subscriber definition with standard callback.
108
- */
109
- export interface StandardSubscriber<T extends MatadorEvent>
110
- extends StandardSubscriberOptions {
111
- /** Human-readable name for the subscriber */
112
- readonly name: string;
113
-
114
- /** Callback function to execute when event is received */
115
- readonly callback: StandardCallback<T['data']>;
116
- }
117
-
118
- /**
119
- * Resumable subscriber definition with resumable callback.
120
- */
121
- export interface ResumableSubscriber<T extends MatadorEvent>
122
- extends ResumableSubscriberOptions {
123
- /** Human-readable name for the subscriber */
124
- readonly name: string;
125
-
126
- /** Callback function with SubscriberContext for checkpointed operations */
127
- readonly callback: ResumableCallback<T['data']>;
128
- }
129
-
130
- /**
131
- * Full subscriber definition with callback (either standard or resumable).
132
- */
133
- export type Subscriber<T extends MatadorEvent> =
134
- | StandardSubscriber<T>
135
- | ResumableSubscriber<T>;
136
-
137
- /**
138
- * Subscriber stub for multi-codebase scenarios where subscriber implementation
139
- * is in a remote service. Declares the subscriber contract without providing
140
- * the callback.
141
- */
142
- export interface SubscriberStub
143
- extends Omit<StandardSubscriberOptions, 'description'> {
144
- /** Human-readable name for the subscriber */
145
- readonly name: string;
146
-
147
- /** Indicates this is a stub without implementation */
148
- readonly isStub: true;
149
- }
150
-
151
- /**
152
- * Union type for any subscriber definition (full or stub).
153
- * This is the type-erased version for use in collections and schema.
154
- * Uses `any` because Subscriber<T> is contravariant in T (callback parameter),
155
- * making it impossible to assign Subscriber<SpecificEvent> to Subscriber<MatadorEvent<unknown>>.
156
- */
157
- // biome-ignore lint/suspicious/noExplicitAny: Required for variance compatibility in heterogeneous collections
158
- export type AnySubscriber = Subscriber<MatadorEvent<any>> | SubscriberStub;
159
-
160
- /**
161
- * Type guard to check if a subscriber is a stub.
162
- */
163
- export function isSubscriberStub(
164
- subscriber: AnySubscriber,
165
- ): subscriber is SubscriberStub {
166
- return 'isStub' in subscriber && subscriber.isStub === true;
167
- }
168
-
169
- /**
170
- * Type guard to check if a subscriber has a callback implementation.
171
- */
172
- export function isSubscriber(
173
- subscriber: AnySubscriber,
174
- // biome-ignore lint/suspicious/noExplicitAny: Required for variance compatibility
175
- ): subscriber is Subscriber<MatadorEvent<any>> {
176
- return 'callback' in subscriber && typeof subscriber.callback === 'function';
177
- }
178
-
179
- /**
180
- * Type guard to check if a subscriber is resumable.
181
- */
182
- export function isResumableSubscriber(
183
- subscriber: AnySubscriber,
184
- // biome-ignore lint/suspicious/noExplicitAny: Required for variance compatibility
185
- ): subscriber is ResumableSubscriber<MatadorEvent<any>> {
186
- return isSubscriber(subscriber) && subscriber.idempotent === 'resumable';
187
- }
188
-
189
- /**
190
- * Type guard to check if a subscriber is a standard (non-resumable) subscriber.
191
- */
192
- export function isStandardSubscriber(
193
- subscriber: AnySubscriber,
194
- // biome-ignore lint/suspicious/noExplicitAny: Required for variance compatibility
195
- ): subscriber is StandardSubscriber<MatadorEvent<any>> {
196
- return isSubscriber(subscriber) && subscriber.idempotent !== 'resumable';
197
- }
198
-
199
- /**
200
- * Input options for createSubscriber with standard callback.
201
- */
202
- export interface CreateStandardSubscriberInput<T extends MatadorEvent> {
203
- readonly name: string;
204
- readonly description: string;
205
- readonly callback: StandardCallback<T['data']>;
206
- readonly idempotent?: 'yes' | 'no' | 'unknown' | undefined;
207
- readonly importance?: Importance | undefined;
208
- readonly targetQueue?: string | undefined;
209
- readonly enabled?: (() => boolean | Promise<boolean>) | undefined;
210
- }
211
-
212
- /**
213
- * Input options for createSubscriber with resumable callback.
214
- */
215
- export interface CreateResumableSubscriberInput<T extends MatadorEvent> {
216
- readonly name: string;
217
- readonly description: string;
218
- readonly callback: ResumableCallback<T['data']>;
219
- readonly idempotent: 'resumable';
220
- readonly importance?: Importance | undefined;
221
- readonly targetQueue?: string | undefined;
222
- readonly enabled?: (() => boolean | Promise<boolean>) | undefined;
223
- }
224
-
225
- /**
226
- * Input options for createSubscriber (discriminated union).
227
- */
228
- export type CreateSubscriberInput<T extends MatadorEvent> =
229
- | CreateStandardSubscriberInput<T>
230
- | CreateResumableSubscriberInput<T>;
231
-
232
- /**
233
- * Creates a subscriber definition.
234
- *
235
- * @example Standard subscriber
236
- * ```typescript
237
- * const subscriber = createSubscriber<MyEvent>({
238
- * name: 'my-subscriber',
239
- * description: 'Handles MyEvent by logging the data',
240
- * callback: async (envelope) => {
241
- * console.log(envelope.data);
242
- * },
243
- * });
244
- * ```
245
- *
246
- * @example Resumable subscriber with io()
247
- * ```typescript
248
- * const subscriber = createSubscriber<MyEvent>({
249
- * name: 'my-resumable-subscriber',
250
- * description: 'Processes MyEvent with checkpoint-based idempotency',
251
- * idempotent: 'resumable',
252
- * callback: async (envelope, { io }) => {
253
- * await io('step-1', () => doSomething());
254
- * },
255
- * });
256
- * ```
257
- */
258
- export function createSubscriber<T extends MatadorEvent>(
259
- input: CreateSubscriberInput<T>,
260
- ): Subscriber<T> {
261
- const base = {
262
- name: input.name,
263
- description: input.description,
264
- callback: input.callback,
265
- importance: input.importance ?? 'should-investigate',
266
- ...(input.targetQueue !== undefined && {
267
- targetQueue: input.targetQueue,
268
- }),
269
- ...(input.enabled !== undefined && { enabled: input.enabled }),
270
- };
271
-
272
- if (input.idempotent === 'resumable') {
273
- return {
274
- ...base,
275
- idempotent: 'resumable',
276
- callback: input.callback,
277
- } as ResumableSubscriber<T>;
278
- }
279
-
280
- return {
281
- ...base,
282
- idempotent: input.idempotent ?? 'unknown',
283
- callback: input.callback,
284
- } as StandardSubscriber<T>;
285
- }
286
-
287
- /**
288
- * Input options for createSubscriberStub.
289
- */
290
- export interface CreateSubscriberStubInput {
291
- readonly name: string;
292
- readonly idempotent?: 'yes' | 'no' | 'unknown' | undefined;
293
- readonly importance?: Importance | undefined;
294
- readonly targetQueue?: string | undefined;
295
- readonly enabled?: (() => boolean | Promise<boolean>) | undefined;
296
- }
297
-
298
- /**
299
- * Creates a subscriber stub for remote implementations.
300
- *
301
- * @example
302
- * ```typescript
303
- * const stub = createSubscriberStub({
304
- * name: 'remote-analytics',
305
- * targetQueue: 'analytics-worker',
306
- * });
307
- * ```
308
- */
309
- export function createSubscriberStub(
310
- input: CreateSubscriberStubInput,
311
- ): SubscriberStub {
312
- return {
313
- name: input.name,
314
- isStub: true,
315
- idempotent: input.idempotent ?? 'unknown',
316
- importance: input.importance ?? 'should-investigate',
317
- ...(input.targetQueue !== undefined && {
318
- targetQueue: input.targetQueue,
319
- }),
320
- ...(input.enabled !== undefined && { enabled: input.enabled }),
321
- };
322
- }
323
-
324
- /**
325
- * Definition interface used by the pipeline (excludes event class reference).
326
- */
327
- export interface SubscriberDefinition {
328
- readonly name: string;
329
- readonly description?: string | undefined;
330
- readonly idempotent: Idempotency;
331
- readonly importance: Importance;
332
- readonly targetQueue?: string | undefined;
333
- }