@zdavison/matador 2.0.4 → 2.0.6
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.
- package/dist/core/fanout.test.js +0 -1
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/errors/retry-errors.d.ts +40 -5
- package/dist/errors/retry-errors.d.ts.map +1 -1
- package/dist/errors/retry-errors.js +56 -9
- package/dist/errors/retry-errors.test.d.ts +2 -0
- package/dist/errors/retry-errors.test.d.ts.map +1 -0
- package/dist/errors/retry-errors.test.js +136 -0
- package/dist/index.cjs +29 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/pipeline/pipeline.test.js +33 -0
- package/dist/retry/standard-policy.test.js +7 -1
- package/dist/schema/registry.d.ts.map +1 -1
- package/dist/schema/registry.js +4 -1
- package/dist/schema/types.test.js +0 -1
- package/dist/types/envelope.d.ts +12 -0
- package/dist/types/envelope.d.ts.map +1 -1
- package/dist/types/envelope.js +19 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/subscriber.d.ts +10 -6
- package/dist/types/subscriber.d.ts.map +1 -1
- package/dist/types/subscriber.js +0 -2
- package/package.json +1 -1
- package/src/core/fanout.test.ts +0 -1
- package/src/errors/index.ts +1 -0
- package/src/errors/retry-errors.test.ts +175 -0
- package/src/errors/retry-errors.ts +63 -9
- package/src/index.ts +2 -0
- package/src/pipeline/pipeline.test.ts +38 -0
- package/src/retry/standard-policy.test.ts +9 -1
- package/src/schema/registry.ts +4 -1
- package/src/schema/types.test.ts +0 -1
- package/src/types/envelope.ts +20 -0
- package/src/types/index.ts +1 -1
- package/src/types/subscriber.ts +11 -7
- package/tsconfig.tsbuildinfo +1 -1
package/src/schema/registry.ts
CHANGED
|
@@ -120,9 +120,12 @@ export class SchemaRegistry {
|
|
|
120
120
|
|
|
121
121
|
const def: SubscriberDefinition = {
|
|
122
122
|
name: subscriber.name,
|
|
123
|
-
description: subscriber.description,
|
|
124
123
|
idempotent: subscriber.idempotent ?? 'unknown',
|
|
125
124
|
importance: subscriber.importance ?? 'should-investigate',
|
|
125
|
+
...('description' in subscriber &&
|
|
126
|
+
subscriber.description !== undefined && {
|
|
127
|
+
description: subscriber.description,
|
|
128
|
+
}),
|
|
126
129
|
};
|
|
127
130
|
|
|
128
131
|
if (subscriber.targetQueue !== undefined) {
|
package/src/schema/types.test.ts
CHANGED
package/src/types/envelope.ts
CHANGED
|
@@ -150,3 +150,23 @@ export function createEnvelope<T>(
|
|
|
150
150
|
},
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Helper to create a test envelope for a given event instance.
|
|
156
|
+
* Useful for unit testing subscriber callbacks directly.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const event = new UserCreatedEvent({ userId: '123', email: 'test@example.com' });
|
|
161
|
+
* const envelope = createDummyEnvelope(event);
|
|
162
|
+
* await mySubscriber.callback(envelope, event);
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export function createDummyEnvelope<T>(data: T): Envelope<T> {
|
|
166
|
+
return createEnvelope({
|
|
167
|
+
data,
|
|
168
|
+
eventKey: 'dummy.event.key',
|
|
169
|
+
targetSubscriber: 'dummy-subscriber',
|
|
170
|
+
importance: 'can-ignore',
|
|
171
|
+
});
|
|
172
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { invalidResult, validResult } from './common.js';
|
|
|
10
10
|
export type { Dispatcher } from './dispatcher.js';
|
|
11
11
|
|
|
12
12
|
export type { CreateEnvelopeOptions, Docket, Envelope } from './envelope.js';
|
|
13
|
-
export { createEnvelope } from './envelope.js';
|
|
13
|
+
export { createDummyEnvelope, createEnvelope } from './envelope.js';
|
|
14
14
|
|
|
15
15
|
export type {
|
|
16
16
|
Event,
|
package/src/types/subscriber.ts
CHANGED
|
@@ -28,11 +28,14 @@ export type EnvelopeOf<T extends MatadorEvent> = Envelope<T['data']>;
|
|
|
28
28
|
* Callback function executed when an event is received (standard subscribers).
|
|
29
29
|
* Receives the full envelope containing id, data, and docket, plus a context
|
|
30
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.
|
|
31
34
|
*/
|
|
32
35
|
export type StandardCallback<T = unknown> = (
|
|
33
36
|
envelope: Envelope<T>,
|
|
34
37
|
context: CallbackContext,
|
|
35
|
-
) => Promise<
|
|
38
|
+
) => Promise<unknown> | unknown | void;
|
|
36
39
|
|
|
37
40
|
/**
|
|
38
41
|
* Context for resumable subscriber callbacks.
|
|
@@ -44,11 +47,14 @@ export type ResumableCallbackContext = SubscriberContext & CallbackContext;
|
|
|
44
47
|
* Callback function for resumable subscribers.
|
|
45
48
|
* Receives the envelope and a context with io() for checkpointed operations
|
|
46
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.
|
|
47
53
|
*/
|
|
48
54
|
export type ResumableCallback<T = unknown> = (
|
|
49
55
|
envelope: Envelope<T>,
|
|
50
56
|
context: ResumableCallbackContext,
|
|
51
|
-
) => Promise<
|
|
57
|
+
) => Promise<unknown> | unknown | void;
|
|
52
58
|
|
|
53
59
|
/**
|
|
54
60
|
* Callback function executed when an event is received.
|
|
@@ -133,7 +139,8 @@ export type Subscriber<T extends MatadorEvent> =
|
|
|
133
139
|
* is in a remote service. Declares the subscriber contract without providing
|
|
134
140
|
* the callback.
|
|
135
141
|
*/
|
|
136
|
-
export interface SubscriberStub
|
|
142
|
+
export interface SubscriberStub
|
|
143
|
+
extends Omit<StandardSubscriberOptions, 'description'> {
|
|
137
144
|
/** Human-readable name for the subscriber */
|
|
138
145
|
readonly name: string;
|
|
139
146
|
|
|
@@ -282,7 +289,6 @@ export function createSubscriber<T extends MatadorEvent>(
|
|
|
282
289
|
*/
|
|
283
290
|
export interface CreateSubscriberStubInput {
|
|
284
291
|
readonly name: string;
|
|
285
|
-
readonly description: string;
|
|
286
292
|
readonly idempotent?: 'yes' | 'no' | 'unknown' | undefined;
|
|
287
293
|
readonly importance?: Importance | undefined;
|
|
288
294
|
readonly targetQueue?: string | undefined;
|
|
@@ -296,7 +302,6 @@ export interface CreateSubscriberStubInput {
|
|
|
296
302
|
* ```typescript
|
|
297
303
|
* const stub = createSubscriberStub({
|
|
298
304
|
* name: 'remote-analytics',
|
|
299
|
-
* description: 'Sends events to remote analytics service',
|
|
300
305
|
* targetQueue: 'analytics-worker',
|
|
301
306
|
* });
|
|
302
307
|
* ```
|
|
@@ -306,7 +311,6 @@ export function createSubscriberStub(
|
|
|
306
311
|
): SubscriberStub {
|
|
307
312
|
return {
|
|
308
313
|
name: input.name,
|
|
309
|
-
description: input.description,
|
|
310
314
|
isStub: true,
|
|
311
315
|
idempotent: input.idempotent ?? 'unknown',
|
|
312
316
|
importance: input.importance ?? 'should-investigate',
|
|
@@ -322,7 +326,7 @@ export function createSubscriberStub(
|
|
|
322
326
|
*/
|
|
323
327
|
export interface SubscriberDefinition {
|
|
324
328
|
readonly name: string;
|
|
325
|
-
readonly description
|
|
329
|
+
readonly description?: string | undefined;
|
|
326
330
|
readonly idempotent: Idempotency;
|
|
327
331
|
readonly importance: Importance;
|
|
328
332
|
readonly targetQueue?: string | undefined;
|