@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,188 +0,0 @@
1
- import assert from 'node:assert';
2
- import type { Envelope } from '../types/envelope.js';
3
-
4
- /**
5
- * Base class for retry control errors.
6
- * These errors control the retry behavior of message processing.
7
- */
8
- export abstract class RetryControlError extends Error {
9
- /**
10
- * Error class name for monitoring tools.
11
- */
12
- declare readonly name: string;
13
-
14
- /**
15
- * Human-readable description of the error and recommended actions.
16
- */
17
- abstract readonly description: string;
18
-
19
- constructor(message: string) {
20
- super(message);
21
- this.name = this.constructor.name;
22
- // Ensure name is preserved when serialized
23
- Object.defineProperty(this, 'name', {
24
- value: this.constructor.name,
25
- enumerable: true,
26
- configurable: false,
27
- writable: false,
28
- });
29
- }
30
-
31
- /**
32
- * Returns a serializable representation for logging/monitoring.
33
- */
34
- toJSON(): Record<string, unknown> {
35
- return {
36
- name: this.name,
37
- message: this.message,
38
- description: this.description,
39
- stack: this.stack,
40
- };
41
- }
42
- }
43
-
44
- /**
45
- * Forces retry regardless of subscriber idempotency setting.
46
- * Use when you know the operation is safe to retry.
47
- *
48
- * ACTION: Check subscriber code to understand why retry was forced.
49
- * This overrides default retry behavior based on idempotency settings.
50
- */
51
- export class DoRetry extends RetryControlError {
52
- readonly description =
53
- 'A subscriber explicitly requested retry by throwing DoRetry. ' +
54
- 'ACTION: Check the subscriber code to understand why retry was forced. ' +
55
- 'This overrides the default retry behavior based on idempotency settings.';
56
-
57
- constructor(message = 'Forced retry requested') {
58
- super(message);
59
- }
60
- }
61
-
62
- /**
63
- * Prevents retry regardless of subscriber idempotency setting.
64
- * Use for permanent failures that should not be retried.
65
- *
66
- * ACTION: Check subscriber code to understand why retry was disabled.
67
- * Typically used for permanent failures like invalid data or business rule violations.
68
- */
69
- export class DontRetry extends RetryControlError {
70
- readonly description =
71
- 'A subscriber explicitly prevented retry by throwing DontRetry. ' +
72
- 'ACTION: Check the subscriber code to understand why retry was disabled. ' +
73
- 'Typically used for permanent failures like invalid data or business rule violations. ' +
74
- 'The message will be sent to the dead-letter queue for manual review.';
75
-
76
- constructor(message = 'Retry explicitly disabled') {
77
- super(message);
78
- }
79
- }
80
-
81
- /**
82
- * Thrown by `assertEvent` in the event of a failed assertion.
83
- *
84
- * This error indicates that an event was in an unexpected state when it reached the subscriber.
85
- * Throwing this error will indicate to Matador NOT to retry the event - it will be sent
86
- * directly to the undeliverable dead-letter queue.
87
- *
88
- * Use `assertEvent` in your subscribers to assert properties about an event payload.
89
- * This is useful in scenarios where you would expect an event payload to contain a field
90
- * based on the types, but something unexpected caused it to not be present.
91
- *
92
- * @see assertEvent
93
- */
94
- export class EventAssertionError extends Error {
95
- declare readonly name: string;
96
-
97
- readonly description =
98
- 'Thrown to indicate that an event was in an unexpected state when it reached the subscriber. ' +
99
- 'Throwing this error will indicate to Matador NOT to retry the event. ' +
100
- 'Matador does not throw this error directly - it is thrown by assertEvent, which you can ' +
101
- 'use in your subscribers to assert properties about an event. ' +
102
- 'This can be useful in scenarios where you would expect an event payload to contain a field ' +
103
- 'based on the types, but something unexpected caused it to not be present. ' +
104
- 'Using this instead of the NodeJS assert allows Matador to not retry the event subscriber.';
105
-
106
- /** The envelope that failed the assertion */
107
- readonly envelope: Envelope<unknown>;
108
-
109
- constructor(envelope: Envelope<unknown>, message: string) {
110
- super(message);
111
- this.name = 'EventAssertionError';
112
- this.envelope = envelope;
113
- Object.defineProperty(this, 'name', {
114
- value: 'EventAssertionError',
115
- enumerable: true,
116
- configurable: false,
117
- writable: false,
118
- });
119
- }
120
-
121
- toJSON(): Record<string, unknown> {
122
- return {
123
- name: this.name,
124
- message: this.message,
125
- description: this.description,
126
- envelope: this.envelope,
127
- stack: this.stack,
128
- };
129
- }
130
- }
131
-
132
- /**
133
- * Checks if an error forces a retry.
134
- */
135
- export function isDoRetry(error: unknown): error is DoRetry {
136
- return error instanceof DoRetry;
137
- }
138
-
139
- /**
140
- * Checks if an error prevents retry.
141
- */
142
- export function isDontRetry(error: unknown): error is DontRetry {
143
- return error instanceof DontRetry;
144
- }
145
-
146
- /**
147
- * Checks if an error is an assertion error (never retry).
148
- */
149
- export function isAssertionError(error: unknown): error is EventAssertionError {
150
- return error instanceof EventAssertionError;
151
- }
152
-
153
- /**
154
- * Same as Node.js `assert`, but throws an `EventAssertionError` if the assertion fails.
155
- *
156
- * `EventAssertionError`s thrown within a subscriber do not cause the subscriber to be retried.
157
- * The event will be delivered to the undeliverable dead-letter queue instead.
158
- *
159
- * @see https://nodejs.org/api/assert.html#assertvalue-message
160
- * @param envelope - The envelope this assertion relates to.
161
- * @param value - The value to assert. If falsy, the assertion fails.
162
- * @param message - The message to include in the error if the assertion fails.
163
- * @throws {EventAssertionError} If the assertion fails.
164
- *
165
- * @example
166
- * ```typescript
167
- * const subscriber = createSubscriber<MyEvent>({
168
- * name: 'my-subscriber',
169
- * description: 'Processes MyEvent',
170
- * callback: async (envelope) => {
171
- * // Assert that userId exists - if not, event goes to DLQ without retry
172
- * assertEvent(envelope, envelope.data.userId, 'userId is required');
173
- * // ... rest of processing
174
- * },
175
- * });
176
- * ```
177
- */
178
- export function assertEvent(
179
- envelope: Envelope<unknown>,
180
- value: unknown,
181
- message: string,
182
- ): asserts value {
183
- try {
184
- assert(value, message);
185
- } catch {
186
- throw new EventAssertionError(envelope, message);
187
- }
188
- }
@@ -1,14 +0,0 @@
1
- export type {
2
- DecodeErrorContext,
3
- EnqueueErrorContext,
4
- EnqueueSuccessContext,
5
- Logger,
6
- MatadorHooks,
7
- TransportFallbackContext,
8
- WorkerErrorContext,
9
- WorkerExecuteFn,
10
- WorkerSuccessContext,
11
- } from './types.js';
12
-
13
- export { consoleLogger } from './types.js';
14
- export { SafeHooks } from './safe-hooks.js';
@@ -1,200 +0,0 @@
1
- import type {
2
- CheckpointClearedContext,
3
- CheckpointHitContext,
4
- CheckpointLoadedContext,
5
- CheckpointMissContext,
6
- } from '../checkpoint/index.js';
7
- import type { ConnectionState } from '../transport/index.js';
8
- import type { Envelope, SubscriberDefinition } from '../types/index.js';
9
- import {
10
- type DecodeErrorContext,
11
- type EnqueueErrorContext,
12
- type EnqueueSuccessContext,
13
- type Logger,
14
- type MatadorHooks,
15
- type WorkerErrorContext,
16
- type WorkerExecuteFn,
17
- type WorkerSuccessContext,
18
- consoleLogger,
19
- } from './types.js';
20
-
21
- /**
22
- * Wraps hooks with error handling to prevent hook errors from breaking processing.
23
- * All hooks become safe to call and will catch any errors internally.
24
- */
25
- export class SafeHooks {
26
- private readonly hooks: MatadorHooks;
27
-
28
- /** The logger instance used by Matador. */
29
- readonly logger: Logger;
30
-
31
- constructor(hooks: MatadorHooks = {}) {
32
- this.hooks = hooks;
33
- this.logger = hooks.logger ?? consoleLogger;
34
- }
35
-
36
- async onEnqueueSuccess(context: EnqueueSuccessContext): Promise<void> {
37
- await this.safeCall('onEnqueueSuccess', () =>
38
- this.hooks.onEnqueueSuccess?.(context),
39
- );
40
- }
41
-
42
- async onEnqueueError(context: EnqueueErrorContext): Promise<void> {
43
- await this.safeCall('onEnqueueError', () =>
44
- this.hooks.onEnqueueError?.(context),
45
- );
46
- }
47
-
48
- async onWorkerWrap(
49
- envelope: Envelope,
50
- subscriber: SubscriberDefinition,
51
- execute: WorkerExecuteFn,
52
- ): Promise<void> {
53
- if (this.hooks.onWorkerWrap) {
54
- try {
55
- await this.hooks.onWorkerWrap(envelope, subscriber, execute);
56
- } catch (error) {
57
- this.logger.warn(
58
- '[Matador] 🟡 Hook onWorkerWrap threw an error',
59
- error,
60
- );
61
- // Still try to execute if wrap failed
62
- await execute();
63
- }
64
- } else {
65
- await execute();
66
- }
67
- }
68
-
69
- async onWorkerBeforeProcess(
70
- envelope: Envelope,
71
- subscriber: SubscriberDefinition,
72
- ): Promise<void> {
73
- await this.safeCall('onWorkerBeforeProcess', () =>
74
- this.hooks.onWorkerBeforeProcess?.(envelope, subscriber),
75
- );
76
- }
77
-
78
- async onWorkerSuccess(context: WorkerSuccessContext): Promise<void> {
79
- await this.safeCall('onWorkerSuccess', () =>
80
- this.hooks.onWorkerSuccess?.(context),
81
- );
82
- }
83
-
84
- async onWorkerError(context: WorkerErrorContext): Promise<void> {
85
- await this.safeCall('onWorkerError', () =>
86
- this.hooks.onWorkerError?.(context),
87
- );
88
- }
89
-
90
- async onDecodeError(context: DecodeErrorContext): Promise<void> {
91
- await this.safeCall('onDecodeError', () =>
92
- this.hooks.onDecodeError?.(context),
93
- );
94
- }
95
-
96
- async onConnectionStateChange(state: ConnectionState): Promise<void> {
97
- await this.safeCall('onConnectionStateChange', () =>
98
- this.hooks.onConnectionStateChange?.(state),
99
- );
100
- }
101
-
102
- async loadUniversalMetadata(): Promise<Record<string, unknown>> {
103
- if (!this.hooks.loadUniversalMetadata) {
104
- return {};
105
- }
106
-
107
- try {
108
- const result = await this.hooks.loadUniversalMetadata();
109
- return result ?? {};
110
- } catch (error) {
111
- this.logger.warn(
112
- '[Matador] 🟡 Hook loadUniversalMetadata threw an error',
113
- error,
114
- );
115
- return {};
116
- }
117
- }
118
-
119
- async getRetryDelay(
120
- envelope: Envelope,
121
- attemptNumber: number,
122
- ): Promise<number | undefined> {
123
- if (!this.hooks.getRetryDelay) {
124
- return undefined;
125
- }
126
-
127
- try {
128
- return await this.hooks.getRetryDelay(envelope, attemptNumber);
129
- } catch (error) {
130
- this.logger.warn('[Matador] 🟡 Hook getRetryDelay threw an error', error);
131
- return undefined;
132
- }
133
- }
134
-
135
- async getAttempts(envelope: Envelope): Promise<number | undefined> {
136
- if (!this.hooks.getAttempts) {
137
- return undefined;
138
- }
139
-
140
- try {
141
- return await this.hooks.getAttempts(envelope);
142
- } catch (error) {
143
- this.logger.warn('[Matador] 🟡 Hook getAttempts threw an error', error);
144
- return undefined;
145
- }
146
- }
147
-
148
- async getMaxDeliveries(envelope: Envelope): Promise<number | undefined> {
149
- if (!this.hooks.getMaxDeliveries) {
150
- return undefined;
151
- }
152
-
153
- try {
154
- return await this.hooks.getMaxDeliveries(envelope);
155
- } catch (error) {
156
- this.logger.warn(
157
- '[Matador] 🟡 Hook getMaxDeliveries threw an error',
158
- error,
159
- );
160
- return undefined;
161
- }
162
- }
163
-
164
- // === Checkpoint Hooks ===
165
-
166
- async onCheckpointLoaded(context: CheckpointLoadedContext): Promise<void> {
167
- await this.safeCall('onCheckpointLoaded', () =>
168
- this.hooks.onCheckpointLoaded?.(context),
169
- );
170
- }
171
-
172
- async onCheckpointHit(context: CheckpointHitContext): Promise<void> {
173
- await this.safeCall('onCheckpointHit', () =>
174
- this.hooks.onCheckpointHit?.(context),
175
- );
176
- }
177
-
178
- async onCheckpointMiss(context: CheckpointMissContext): Promise<void> {
179
- await this.safeCall('onCheckpointMiss', () =>
180
- this.hooks.onCheckpointMiss?.(context),
181
- );
182
- }
183
-
184
- async onCheckpointCleared(context: CheckpointClearedContext): Promise<void> {
185
- await this.safeCall('onCheckpointCleared', () =>
186
- this.hooks.onCheckpointCleared?.(context),
187
- );
188
- }
189
-
190
- private async safeCall(
191
- hookName: string,
192
- fn: () => void | Promise<void> | undefined,
193
- ): Promise<void> {
194
- try {
195
- await fn();
196
- } catch (error) {
197
- this.logger.warn(`[Matador] 🟡 Hook ${hookName} threw an error`, error);
198
- }
199
- }
200
- }
@@ -1,226 +0,0 @@
1
- import type {
2
- CheckpointClearedContext,
3
- CheckpointHitContext,
4
- CheckpointLoadedContext,
5
- CheckpointMissContext,
6
- } from '../checkpoint/index.js';
7
- import type { RetryDecision } from '../retry/index.js';
8
- import type { ConnectionState, Transport } from '../transport/index.js';
9
- import type { Envelope, SubscriberDefinition } from '../types/index.js';
10
-
11
- /**
12
- * Logger interface for Matador internal logging.
13
- */
14
- export interface Logger {
15
- debug(message: string, ...args: unknown[]): void;
16
- info(message: string, ...args: unknown[]): void;
17
- warn(message: string, ...args: unknown[]): void;
18
- error(message: string, ...args: unknown[]): void;
19
- }
20
-
21
- /**
22
- * Default logger that uses console.
23
- */
24
- export const consoleLogger: Logger = {
25
- debug: (message, ...args) => console.debug(message, ...args),
26
- info: (message, ...args) => console.info(message, ...args),
27
- warn: (message, ...args) => console.warn(message, ...args),
28
- error: (message, ...args) => console.error(message, ...args),
29
- };
30
-
31
- /**
32
- * Context for enqueue success hook.
33
- */
34
- export interface EnqueueSuccessContext {
35
- readonly envelope: Envelope;
36
- readonly queue: string;
37
- /** The transport that was used (e.g., 'local', 'rabbitmq') */
38
- readonly transport: string;
39
- }
40
-
41
- /**
42
- * Context for transport fallback hook.
43
- */
44
- export interface TransportFallbackContext {
45
- /** The envelope that was being sent */
46
- readonly envelope: Envelope;
47
- /** The queue the message was being sent to */
48
- readonly queue: string;
49
- /** The transport that failed */
50
- readonly failedTransport: Transport['name'];
51
- /** The transport that will be tried next */
52
- readonly nextTransport: Transport['name'];
53
- /** The error from the failed transport */
54
- readonly error: Error;
55
- }
56
-
57
- /**
58
- * Context for enqueue error hook.
59
- */
60
- export interface EnqueueErrorContext {
61
- readonly envelope: Envelope;
62
- readonly error: Error;
63
- /** The transport that failed (e.g., 'local', 'rabbitmq') */
64
- readonly transport: string;
65
- }
66
-
67
- /**
68
- * Context for decode error hook.
69
- */
70
- export interface DecodeErrorContext {
71
- readonly error: Error;
72
- readonly rawMessage: Uint8Array;
73
- readonly sourceQueue: string;
74
- /** The transport that received the message (e.g., 'local', 'rabbitmq') */
75
- readonly transport: string;
76
- }
77
-
78
- /**
79
- * Context for worker success hook.
80
- */
81
- export interface WorkerSuccessContext {
82
- readonly envelope: Envelope;
83
- readonly subscriber: SubscriberDefinition;
84
- readonly result: unknown;
85
- readonly durationMs: number;
86
- /** The transport that received the message (e.g., 'local', 'rabbitmq') */
87
- readonly transport: string;
88
- }
89
-
90
- /**
91
- * Context for worker error hook.
92
- */
93
- export interface WorkerErrorContext {
94
- readonly envelope: Envelope;
95
- readonly subscriber: SubscriberDefinition;
96
- readonly error: Error;
97
- readonly durationMs: number;
98
- readonly decision: RetryDecision;
99
- /** The transport that received the message (e.g., 'local', 'rabbitmq') */
100
- readonly transport: string;
101
- }
102
-
103
- /**
104
- * Execution function passed to onWorkerWrap for APM wrapping.
105
- */
106
- export type WorkerExecuteFn = () => Promise<void>;
107
-
108
- /**
109
- * All available hooks for Matador.
110
- */
111
- export interface MatadorHooks {
112
- /**
113
- * Logger for internal Matador logging.
114
- * Defaults to console logger if not provided.
115
- */
116
- logger?: Logger;
117
-
118
- /**
119
- * Called when an event is successfully enqueued.
120
- */
121
- onEnqueueSuccess?(context: EnqueueSuccessContext): void | Promise<void>;
122
-
123
- /**
124
- * Called when transport fallback occurs during send.
125
- * Only fires when using MultiTransport with fallbackEnabled=true.
126
- */
127
- onTransportFallback?(context: TransportFallbackContext): void | Promise<void>;
128
-
129
- /**
130
- * Called when enqueue fails completely.
131
- */
132
- onEnqueueError?(context: EnqueueErrorContext): void | Promise<void>;
133
-
134
- /**
135
- * Wraps entire worker processing (for APM context).
136
- * Must call execute() to run the actual processing.
137
- */
138
- onWorkerWrap?(
139
- envelope: Envelope,
140
- subscriber: SubscriberDefinition,
141
- execute: WorkerExecuteFn,
142
- ): Promise<void>;
143
-
144
- /**
145
- * Called before processing begins.
146
- */
147
- onWorkerBeforeProcess?(
148
- envelope: Envelope,
149
- subscriber: SubscriberDefinition,
150
- ): void | Promise<void>;
151
-
152
- /**
153
- * Called after successful processing.
154
- */
155
- onWorkerSuccess?(context: WorkerSuccessContext): void | Promise<void>;
156
-
157
- /**
158
- * Called after processing error.
159
- */
160
- onWorkerError?(context: WorkerErrorContext): void | Promise<void>;
161
-
162
- /**
163
- * Called when message decoding fails.
164
- */
165
- onDecodeError?(context: DecodeErrorContext): void | Promise<void>;
166
-
167
- /**
168
- * Called when transport connection state changes.
169
- */
170
- onConnectionStateChange?(state: ConnectionState): void | Promise<void>;
171
-
172
- /**
173
- * Loads universal metadata to add to all envelopes.
174
- */
175
- loadUniversalMetadata?():
176
- | Record<string, unknown>
177
- | Promise<Record<string, unknown>>;
178
-
179
- /**
180
- * Dynamic retry delay lookup.
181
- */
182
- getRetryDelay?(
183
- envelope: Envelope,
184
- attemptNumber: number,
185
- ): number | undefined | Promise<number | undefined>;
186
-
187
- /**
188
- * Dynamic max attempts lookup.
189
- */
190
- getAttempts?(
191
- envelope: Envelope,
192
- ): number | undefined | Promise<number | undefined>;
193
-
194
- /**
195
- * Dynamic max deliveries (poison threshold) lookup.
196
- */
197
- getMaxDeliveries?(
198
- envelope: Envelope,
199
- ): number | undefined | Promise<number | undefined>;
200
-
201
- // === Checkpoint Hooks (Resumable Subscribers) ===
202
-
203
- /**
204
- * Called when a checkpoint is loaded for a retry.
205
- * Only fires for resumable subscribers on retry attempts.
206
- */
207
- onCheckpointLoaded?(context: CheckpointLoadedContext): void | Promise<void>;
208
-
209
- /**
210
- * Called when an io() operation uses a cached value (checkpoint hit).
211
- * Useful for observability and metrics.
212
- */
213
- onCheckpointHit?(context: CheckpointHitContext): void | Promise<void>;
214
-
215
- /**
216
- * Called when an io() operation executes (cache miss).
217
- * Useful for observability and metrics.
218
- */
219
- onCheckpointMiss?(context: CheckpointMissContext): void | Promise<void>;
220
-
221
- /**
222
- * Called when a checkpoint is cleared.
223
- * Fires on successful completion or when moving to dead-letter queue.
224
- */
225
- onCheckpointCleared?(context: CheckpointClearedContext): void | Promise<void>;
226
- }