@zdavison/matador 2.0.9 → 2.0.11
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/checkpoint/context.d.ts +59 -0
- package/dist/checkpoint/context.d.ts.map +1 -0
- package/dist/checkpoint/context.js +140 -0
- package/dist/checkpoint/context.test.d.ts +2 -0
- package/dist/checkpoint/context.test.d.ts.map +1 -0
- package/dist/checkpoint/context.test.js +424 -0
- package/dist/checkpoint/index.d.ts +7 -0
- package/dist/checkpoint/index.d.ts.map +1 -0
- package/dist/checkpoint/index.js +6 -0
- package/dist/checkpoint/stores/memory.d.ts +29 -0
- package/dist/checkpoint/stores/memory.d.ts.map +1 -0
- package/dist/checkpoint/stores/memory.js +39 -0
- package/{src/checkpoint/stores/noop.ts → dist/checkpoint/stores/noop.d.ts} +5 -13
- package/dist/checkpoint/stores/noop.d.ts.map +1 -0
- package/dist/checkpoint/stores/noop.js +18 -0
- package/dist/checkpoint/stores/stores.test.d.ts +2 -0
- package/dist/checkpoint/stores/stores.test.d.ts.map +1 -0
- package/dist/checkpoint/stores/stores.test.js +146 -0
- package/dist/checkpoint/types.d.ts +119 -0
- package/dist/checkpoint/types.d.ts.map +1 -0
- package/dist/checkpoint/types.js +1 -0
- package/dist/codec/codec.d.ts +29 -0
- package/dist/codec/codec.d.ts.map +1 -0
- package/dist/codec/codec.js +15 -0
- package/dist/codec/header-aware-codec.d.ts +36 -0
- package/dist/codec/header-aware-codec.d.ts.map +1 -0
- package/dist/codec/header-aware-codec.js +1 -0
- package/{src/codec/index.ts → dist/codec/index.d.ts} +2 -7
- package/dist/codec/index.d.ts.map +1 -0
- package/dist/codec/index.js +3 -0
- package/dist/codec/json-codec.d.ts +13 -0
- package/dist/codec/json-codec.d.ts.map +1 -0
- package/dist/codec/json-codec.js +64 -0
- package/dist/codec/rabbitmq-codec.d.ts +28 -0
- package/dist/codec/rabbitmq-codec.d.ts.map +1 -0
- package/dist/codec/rabbitmq-codec.js +242 -0
- package/dist/codec/rabbitmq-codec.test.d.ts +2 -0
- package/dist/codec/rabbitmq-codec.test.d.ts.map +1 -0
- package/dist/codec/rabbitmq-codec.test.js +433 -0
- package/dist/core/fanout.d.ts +59 -0
- package/dist/core/fanout.d.ts.map +1 -0
- package/dist/core/fanout.js +121 -0
- package/dist/core/fanout.test.d.ts +2 -0
- package/dist/core/fanout.test.d.ts.map +1 -0
- package/dist/core/fanout.test.js +1054 -0
- package/{src/core/index.ts → dist/core/index.d.ts} +2 -7
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +3 -0
- package/dist/core/matador.d.ts +133 -0
- package/dist/core/matador.d.ts.map +1 -0
- package/dist/core/matador.js +228 -0
- package/dist/core/matador.test.d.ts +2 -0
- package/dist/core/matador.test.d.ts.map +1 -0
- package/dist/core/matador.test.js +446 -0
- package/dist/core/shutdown.d.ts +78 -0
- package/dist/core/shutdown.d.ts.map +1 -0
- package/dist/core/shutdown.js +111 -0
- package/dist/core/shutdown.test.d.ts +2 -0
- package/dist/core/shutdown.test.d.ts.map +1 -0
- package/dist/core/shutdown.test.js +524 -0
- package/dist/errors/checkpoint-errors.d.ts +30 -0
- package/dist/errors/checkpoint-errors.d.ts.map +1 -0
- package/dist/errors/checkpoint-errors.js +49 -0
- package/dist/errors/has-description.d.ts +18 -0
- package/dist/errors/has-description.d.ts.map +1 -0
- package/dist/errors/has-description.js +9 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +22 -0
- package/dist/errors/matador-errors.d.ts +183 -0
- package/dist/errors/matador-errors.d.ts.map +1 -0
- package/dist/errors/matador-errors.js +376 -0
- package/dist/errors/retry-errors.d.ts +102 -0
- package/dist/errors/retry-errors.d.ts.map +1 -0
- package/dist/errors/retry-errors.js +155 -0
- 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/hooks/index.d.ts +4 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/safe-hooks.d.ts +32 -0
- package/dist/hooks/safe-hooks.d.ts.map +1 -0
- package/dist/hooks/safe-hooks.js +120 -0
- package/dist/hooks/types.d.ts +172 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +9 -0
- package/dist/index.cjs +3228 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/{src/pipeline/index.ts → dist/pipeline/index.d.ts} +1 -0
- package/dist/pipeline/index.d.ts.map +1 -0
- package/dist/pipeline/index.js +1 -0
- package/dist/pipeline/pipeline.d.ts +63 -0
- package/dist/pipeline/pipeline.d.ts.map +1 -0
- package/dist/pipeline/pipeline.js +273 -0
- package/dist/pipeline/pipeline.test.d.ts +2 -0
- package/dist/pipeline/pipeline.test.d.ts.map +1 -0
- package/dist/pipeline/pipeline.test.js +1112 -0
- package/{src/retry/index.ts → dist/retry/index.d.ts} +1 -1
- package/dist/retry/index.d.ts.map +1 -0
- package/dist/retry/index.js +1 -0
- package/dist/retry/policy.d.ts +43 -0
- package/dist/retry/policy.d.ts.map +1 -0
- package/dist/retry/policy.js +1 -0
- package/dist/retry/standard-policy.d.ts +44 -0
- package/dist/retry/standard-policy.d.ts.map +1 -0
- package/dist/retry/standard-policy.js +102 -0
- package/dist/retry/standard-policy.test.d.ts +2 -0
- package/dist/retry/standard-policy.test.d.ts.map +1 -0
- package/dist/retry/standard-policy.test.js +196 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +2 -0
- package/dist/schema/registry.d.ts +63 -0
- package/dist/schema/registry.d.ts.map +1 -0
- package/dist/schema/registry.js +174 -0
- package/dist/schema/registry.test.d.ts +2 -0
- package/dist/schema/registry.test.d.ts.map +1 -0
- package/dist/schema/registry.test.js +278 -0
- package/{src/schema/types.ts → dist/schema/types.d.ts} +29 -88
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/types.js +74 -0
- package/dist/schema/types.test.d.ts +2 -0
- package/dist/schema/types.test.d.ts.map +1 -0
- package/dist/schema/types.test.js +242 -0
- package/dist/topology/builder.d.ts +80 -0
- package/dist/topology/builder.d.ts.map +1 -0
- package/dist/topology/builder.js +165 -0
- package/dist/topology/builder.test.d.ts +2 -0
- package/dist/topology/builder.test.d.ts.map +1 -0
- package/dist/topology/builder.test.js +360 -0
- package/dist/topology/index.d.ts +5 -0
- package/dist/topology/index.d.ts.map +1 -0
- package/dist/topology/index.js +2 -0
- package/dist/topology/types.d.ts +128 -0
- package/dist/topology/types.d.ts.map +1 -0
- package/dist/topology/types.js +28 -0
- package/dist/transport/capabilities.d.ts +66 -0
- package/dist/transport/capabilities.d.ts.map +1 -0
- package/dist/transport/capabilities.js +18 -0
- package/dist/transport/connection-manager.d.ts +95 -0
- package/dist/transport/connection-manager.d.ts.map +1 -0
- package/dist/transport/connection-manager.js +144 -0
- package/dist/transport/index.d.ts +11 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +5 -0
- package/dist/transport/local/local-transport.d.ts +62 -0
- package/dist/transport/local/local-transport.d.ts.map +1 -0
- package/dist/transport/local/local-transport.js +241 -0
- package/dist/transport/local/local-transport.test.d.ts +2 -0
- package/dist/transport/local/local-transport.test.d.ts.map +1 -0
- package/dist/transport/local/local-transport.test.js +192 -0
- package/dist/transport/multi/multi-transport.d.ts +94 -0
- package/dist/transport/multi/multi-transport.d.ts.map +1 -0
- package/dist/transport/multi/multi-transport.js +184 -0
- package/dist/transport/multi/multi-transport.test.d.ts +2 -0
- package/dist/transport/multi/multi-transport.test.d.ts.map +1 -0
- package/dist/transport/multi/multi-transport.test.js +236 -0
- package/dist/transport/rabbitmq/rabbitmq-transport.d.ts +83 -0
- package/dist/transport/rabbitmq/rabbitmq-transport.d.ts.map +1 -0
- package/dist/transport/rabbitmq/rabbitmq-transport.js +541 -0
- package/dist/transport/rabbitmq/rabbitmq-transport.test.d.ts +2 -0
- package/dist/transport/rabbitmq/rabbitmq-transport.test.d.ts.map +1 -0
- package/dist/transport/rabbitmq/rabbitmq-transport.test.js +100 -0
- package/dist/transport/transport.d.ts +152 -0
- package/dist/transport/transport.d.ts.map +1 -0
- package/dist/transport/transport.js +1 -0
- package/{src/types/common.ts → dist/types/common.d.ts} +8 -20
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +12 -0
- package/dist/types/dispatcher.d.ts +14 -0
- package/dist/types/dispatcher.d.ts.map +1 -0
- package/dist/types/dispatcher.js +1 -0
- package/dist/types/envelope.d.ts +131 -0
- package/dist/types/envelope.d.ts.map +1 -0
- package/dist/types/envelope.js +99 -0
- package/dist/types/event.d.ts +92 -0
- package/dist/types/event.d.ts.map +1 -0
- package/dist/types/event.js +26 -0
- package/dist/types/event.test.d.ts +2 -0
- package/dist/types/event.test.d.ts.map +1 -0
- package/dist/types/event.test.js +130 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/subscriber.d.ts +227 -0
- package/dist/types/subscriber.d.ts.map +1 -0
- package/dist/types/subscriber.js +97 -0
- package/package.json +6 -2
- package/examples/config.ts +0 -126
- package/examples/event.ts +0 -26
- package/examples/order-event.json +0 -19
- package/src/checkpoint/context.test.ts +0 -510
- package/src/checkpoint/context.ts +0 -213
- package/src/checkpoint/index.ts +0 -30
- package/src/checkpoint/stores/memory.ts +0 -47
- package/src/checkpoint/stores/stores.test.ts +0 -177
- package/src/checkpoint/types.ts +0 -147
- package/src/codec/codec.ts +0 -42
- package/src/codec/header-aware-codec.ts +0 -41
- package/src/codec/json-codec.ts +0 -69
- package/src/codec/rabbitmq-codec.test.ts +0 -516
- package/src/codec/rabbitmq-codec.ts +0 -336
- package/src/core/fanout.test.ts +0 -1350
- package/src/core/fanout.ts +0 -184
- package/src/core/matador.test.ts +0 -575
- package/src/core/matador.ts +0 -357
- package/src/core/shutdown.test.ts +0 -853
- package/src/core/shutdown.ts +0 -165
- package/src/errors/checkpoint-errors.ts +0 -62
- package/src/errors/has-description.ts +0 -25
- package/src/errors/index.ts +0 -58
- package/src/errors/matador-errors.ts +0 -477
- package/src/errors/retry-errors.test.ts +0 -175
- package/src/errors/retry-errors.ts +0 -188
- package/src/hooks/index.ts +0 -14
- package/src/hooks/safe-hooks.ts +0 -200
- package/src/hooks/types.ts +0 -226
- package/src/index.ts +0 -242
- package/src/pipeline/pipeline.test.ts +0 -1377
- package/src/pipeline/pipeline.ts +0 -393
- package/src/retry/policy.ts +0 -46
- package/src/retry/standard-policy.test.ts +0 -290
- package/src/retry/standard-policy.ts +0 -156
- package/src/schema/index.ts +0 -16
- package/src/schema/registry.test.ts +0 -339
- package/src/schema/registry.ts +0 -229
- package/src/schema/types.test.ts +0 -280
- package/src/topology/builder.test.ts +0 -451
- package/src/topology/builder.ts +0 -238
- package/src/topology/index.ts +0 -19
- package/src/topology/types.ts +0 -183
- package/src/transport/capabilities.ts +0 -88
- package/src/transport/connection-manager.ts +0 -218
- package/src/transport/index.ts +0 -42
- package/src/transport/local/local-transport.test.ts +0 -262
- package/src/transport/local/local-transport.ts +0 -330
- package/src/transport/multi/multi-transport.test.ts +0 -320
- package/src/transport/multi/multi-transport.ts +0 -294
- package/src/transport/rabbitmq/rabbitmq-transport.test.ts +0 -120
- package/src/transport/rabbitmq/rabbitmq-transport.ts +0 -782
- package/src/transport/transport.ts +0 -200
- package/src/types/dispatcher.ts +0 -18
- package/src/types/envelope.ts +0 -244
- package/src/types/event.test.ts +0 -157
- package/src/types/event.ts +0 -112
- package/src/types/index.ts +0 -62
- package/src/types/subscriber.ts +0 -333
- package/test/e2e/multi-transport.e2e.test.ts +0 -237
- package/test/e2e/rabbitmq-transport.e2e.test.ts +0 -618
- package/test/e2e/transport-compliance.e2e.test.ts +0 -506
- package/test/integration/matador.integration.test.ts +0 -634
- package/tsconfig.json +0 -29
- package/tsup.config.ts +0 -13
package/src/types/event.ts
DELETED
|
@@ -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>);
|
package/src/types/index.ts
DELETED
|
@@ -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';
|
package/src/types/subscriber.ts
DELETED
|
@@ -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
|
-
}
|