@zdavison/matador 2.0.7 → 2.0.9
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/package.json +3 -2
- package/src/hooks/safe-hooks.ts +0 -16
- package/src/hooks/types.ts +0 -7
- package/src/index.ts +1 -0
- package/src/types/event.ts +8 -14
- package/src/types/index.ts +3 -2
- package/dist/checkpoint/context.d.ts +0 -59
- package/dist/checkpoint/context.d.ts.map +0 -1
- package/dist/checkpoint/context.js +0 -140
- package/dist/checkpoint/context.test.d.ts +0 -2
- package/dist/checkpoint/context.test.d.ts.map +0 -1
- package/dist/checkpoint/context.test.js +0 -424
- package/dist/checkpoint/index.d.ts +0 -7
- package/dist/checkpoint/index.d.ts.map +0 -1
- package/dist/checkpoint/index.js +0 -6
- package/dist/checkpoint/stores/memory.d.ts +0 -29
- package/dist/checkpoint/stores/memory.d.ts.map +0 -1
- package/dist/checkpoint/stores/memory.js +0 -39
- package/dist/checkpoint/stores/noop.d.ts +0 -14
- package/dist/checkpoint/stores/noop.d.ts.map +0 -1
- package/dist/checkpoint/stores/noop.js +0 -18
- package/dist/checkpoint/stores/stores.test.d.ts +0 -2
- package/dist/checkpoint/stores/stores.test.d.ts.map +0 -1
- package/dist/checkpoint/stores/stores.test.js +0 -146
- package/dist/checkpoint/types.d.ts +0 -119
- package/dist/checkpoint/types.d.ts.map +0 -1
- package/dist/checkpoint/types.js +0 -1
- package/dist/codec/codec.d.ts +0 -29
- package/dist/codec/codec.d.ts.map +0 -1
- package/dist/codec/codec.js +0 -15
- package/dist/codec/header-aware-codec.d.ts +0 -36
- package/dist/codec/header-aware-codec.d.ts.map +0 -1
- package/dist/codec/header-aware-codec.js +0 -1
- package/dist/codec/index.d.ts +0 -6
- package/dist/codec/index.d.ts.map +0 -1
- package/dist/codec/index.js +0 -3
- package/dist/codec/json-codec.d.ts +0 -13
- package/dist/codec/json-codec.d.ts.map +0 -1
- package/dist/codec/json-codec.js +0 -64
- package/dist/codec/rabbitmq-codec.d.ts +0 -28
- package/dist/codec/rabbitmq-codec.d.ts.map +0 -1
- package/dist/codec/rabbitmq-codec.js +0 -242
- package/dist/codec/rabbitmq-codec.test.d.ts +0 -2
- package/dist/codec/rabbitmq-codec.test.d.ts.map +0 -1
- package/dist/codec/rabbitmq-codec.test.js +0 -433
- package/dist/core/fanout.d.ts +0 -59
- package/dist/core/fanout.d.ts.map +0 -1
- package/dist/core/fanout.js +0 -121
- package/dist/core/fanout.test.d.ts +0 -2
- package/dist/core/fanout.test.d.ts.map +0 -1
- package/dist/core/fanout.test.js +0 -1054
- package/dist/core/index.d.ts +0 -7
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -3
- package/dist/core/matador.d.ts +0 -133
- package/dist/core/matador.d.ts.map +0 -1
- package/dist/core/matador.js +0 -228
- package/dist/core/matador.test.d.ts +0 -2
- package/dist/core/matador.test.d.ts.map +0 -1
- package/dist/core/matador.test.js +0 -446
- package/dist/core/shutdown.d.ts +0 -78
- package/dist/core/shutdown.d.ts.map +0 -1
- package/dist/core/shutdown.js +0 -111
- package/dist/core/shutdown.test.d.ts +0 -2
- package/dist/core/shutdown.test.d.ts.map +0 -1
- package/dist/core/shutdown.test.js +0 -524
- package/dist/errors/checkpoint-errors.d.ts +0 -30
- package/dist/errors/checkpoint-errors.d.ts.map +0 -1
- package/dist/errors/checkpoint-errors.js +0 -49
- package/dist/errors/has-description.d.ts +0 -18
- package/dist/errors/has-description.d.ts.map +0 -1
- package/dist/errors/has-description.js +0 -9
- package/dist/errors/index.d.ts +0 -6
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js +0 -22
- package/dist/errors/matador-errors.d.ts +0 -183
- package/dist/errors/matador-errors.d.ts.map +0 -1
- package/dist/errors/matador-errors.js +0 -376
- package/dist/errors/retry-errors.d.ts +0 -102
- package/dist/errors/retry-errors.d.ts.map +0 -1
- package/dist/errors/retry-errors.js +0 -155
- package/dist/errors/retry-errors.test.d.ts +0 -2
- package/dist/errors/retry-errors.test.d.ts.map +0 -1
- package/dist/errors/retry-errors.test.js +0 -136
- package/dist/hooks/index.d.ts +0 -4
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -2
- package/dist/hooks/safe-hooks.d.ts +0 -33
- package/dist/hooks/safe-hooks.d.ts.map +0 -1
- package/dist/hooks/safe-hooks.js +0 -132
- package/dist/hooks/types.d.ts +0 -176
- package/dist/hooks/types.d.ts.map +0 -1
- package/dist/hooks/types.js +0 -9
- package/dist/index.cjs +0 -3242
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -23
- package/dist/index.d.ts +0 -23
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -31
- package/dist/index.js.map +0 -1
- package/dist/pipeline/index.d.ts +0 -3
- package/dist/pipeline/index.d.ts.map +0 -1
- package/dist/pipeline/index.js +0 -1
- package/dist/pipeline/pipeline.d.ts +0 -63
- package/dist/pipeline/pipeline.d.ts.map +0 -1
- package/dist/pipeline/pipeline.js +0 -273
- package/dist/pipeline/pipeline.test.d.ts +0 -2
- package/dist/pipeline/pipeline.test.d.ts.map +0 -1
- package/dist/pipeline/pipeline.test.js +0 -1112
- package/dist/retry/index.d.ts +0 -4
- package/dist/retry/index.d.ts.map +0 -1
- package/dist/retry/index.js +0 -1
- package/dist/retry/policy.d.ts +0 -43
- package/dist/retry/policy.d.ts.map +0 -1
- package/dist/retry/policy.js +0 -1
- package/dist/retry/standard-policy.d.ts +0 -44
- package/dist/retry/standard-policy.d.ts.map +0 -1
- package/dist/retry/standard-policy.js +0 -102
- package/dist/retry/standard-policy.test.d.ts +0 -2
- package/dist/retry/standard-policy.test.d.ts.map +0 -1
- package/dist/retry/standard-policy.test.js +0 -196
- package/dist/schema/index.d.ts +0 -4
- package/dist/schema/index.d.ts.map +0 -1
- package/dist/schema/index.js +0 -2
- package/dist/schema/registry.d.ts +0 -63
- package/dist/schema/registry.d.ts.map +0 -1
- package/dist/schema/registry.js +0 -174
- package/dist/schema/registry.test.d.ts +0 -2
- package/dist/schema/registry.test.d.ts.map +0 -1
- package/dist/schema/registry.test.js +0 -278
- package/dist/schema/types.d.ts +0 -158
- package/dist/schema/types.d.ts.map +0 -1
- package/dist/schema/types.js +0 -74
- package/dist/schema/types.test.d.ts +0 -2
- package/dist/schema/types.test.d.ts.map +0 -1
- package/dist/schema/types.test.js +0 -242
- package/dist/topology/builder.d.ts +0 -80
- package/dist/topology/builder.d.ts.map +0 -1
- package/dist/topology/builder.js +0 -165
- package/dist/topology/builder.test.d.ts +0 -2
- package/dist/topology/builder.test.d.ts.map +0 -1
- package/dist/topology/builder.test.js +0 -360
- package/dist/topology/index.d.ts +0 -5
- package/dist/topology/index.d.ts.map +0 -1
- package/dist/topology/index.js +0 -2
- package/dist/topology/types.d.ts +0 -128
- package/dist/topology/types.d.ts.map +0 -1
- package/dist/topology/types.js +0 -28
- package/dist/transport/capabilities.d.ts +0 -66
- package/dist/transport/capabilities.d.ts.map +0 -1
- package/dist/transport/capabilities.js +0 -18
- package/dist/transport/connection-manager.d.ts +0 -95
- package/dist/transport/connection-manager.d.ts.map +0 -1
- package/dist/transport/connection-manager.js +0 -144
- package/dist/transport/index.d.ts +0 -11
- package/dist/transport/index.d.ts.map +0 -1
- package/dist/transport/index.js +0 -5
- package/dist/transport/local/local-transport.d.ts +0 -62
- package/dist/transport/local/local-transport.d.ts.map +0 -1
- package/dist/transport/local/local-transport.js +0 -241
- package/dist/transport/local/local-transport.test.d.ts +0 -2
- package/dist/transport/local/local-transport.test.d.ts.map +0 -1
- package/dist/transport/local/local-transport.test.js +0 -192
- package/dist/transport/multi/multi-transport.d.ts +0 -94
- package/dist/transport/multi/multi-transport.d.ts.map +0 -1
- package/dist/transport/multi/multi-transport.js +0 -184
- package/dist/transport/multi/multi-transport.test.d.ts +0 -2
- package/dist/transport/multi/multi-transport.test.d.ts.map +0 -1
- package/dist/transport/multi/multi-transport.test.js +0 -236
- package/dist/transport/rabbitmq/rabbitmq-transport.d.ts +0 -83
- package/dist/transport/rabbitmq/rabbitmq-transport.d.ts.map +0 -1
- package/dist/transport/rabbitmq/rabbitmq-transport.js +0 -541
- package/dist/transport/rabbitmq/rabbitmq-transport.test.d.ts +0 -2
- package/dist/transport/rabbitmq/rabbitmq-transport.test.d.ts.map +0 -1
- package/dist/transport/rabbitmq/rabbitmq-transport.test.js +0 -100
- package/dist/transport/transport.d.ts +0 -152
- package/dist/transport/transport.d.ts.map +0 -1
- package/dist/transport/transport.js +0 -1
- package/dist/types/common.d.ts +0 -41
- package/dist/types/common.d.ts.map +0 -1
- package/dist/types/common.js +0 -12
- package/dist/types/dispatcher.d.ts +0 -14
- package/dist/types/dispatcher.d.ts.map +0 -1
- package/dist/types/dispatcher.js +0 -1
- package/dist/types/envelope.d.ts +0 -131
- package/dist/types/envelope.d.ts.map +0 -1
- package/dist/types/envelope.js +0 -99
- package/dist/types/event.d.ts +0 -96
- package/dist/types/event.d.ts.map +0 -1
- package/dist/types/event.js +0 -26
- package/dist/types/event.test.d.ts +0 -2
- package/dist/types/event.test.d.ts.map +0 -1
- package/dist/types/event.test.js +0 -130
- package/dist/types/index.d.ts +0 -10
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -4
- package/dist/types/subscriber.d.ts +0 -227
- package/dist/types/subscriber.d.ts.map +0 -1
- package/dist/types/subscriber.js +0 -97
- package/tsconfig.tsbuildinfo +0 -1
package/dist/types/event.test.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
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
|
-
});
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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, JsonPrimitive, JsonRecord, JsonValue, } from './event.js';
|
|
7
|
-
export { MatadorEvent } from './event.js';
|
|
8
|
-
export type { AnySubscriber, BaseSubscriberOptions, CallbackContext, CreateResumableSubscriberInput, CreateStandardSubscriberInput, CreateSubscriberInput, EnvelopeOf, ResumableCallback, ResumableCallbackContext, ResumableSubscriber, ResumableSubscriberOptions, StandardCallback, StandardSubscriber, StandardSubscriberOptions, Subscriber, SubscriberCallback, SubscriberDefinition, SubscriberOptions, SubscriberStub, } from './subscriber.js';
|
|
9
|
-
export { createSubscriber, createSubscriberStub, isResumableSubscriber, isStandardSubscriber, isSubscriber, isSubscriberStub, } from './subscriber.js';
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,aAAa,EACb,UAAU,EACV,SAAS,GACV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,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"}
|
package/dist/types/index.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
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';
|
|
@@ -1,227 +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
|
-
* 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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"subscriber.d.ts","sourceRoot":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AW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;CACnE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,yBAAyB,GAC/B,cAAc,CAWhB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC;IACjC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3C"}
|
package/dist/types/subscriber.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
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
|
-
}
|