@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,510 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from 'bun:test';
2
- import { DuplicateIoKeyError } from '../errors/index.js';
3
- import type { Envelope, SubscriberDefinition } from '../types/index.js';
4
- import { ResumableContext } from './context.js';
5
- import { MemoryCheckpointStore } from './stores/memory.js';
6
-
7
- function createTestEnvelope(id = 'test-envelope-id', attempts = 1): Envelope {
8
- return {
9
- id,
10
- data: { userId: '123' },
11
- docket: {
12
- eventKey: 'test.event',
13
- targetSubscriber: 'test-subscriber',
14
- importance: 'should-investigate',
15
- attempts,
16
- createdAt: new Date().toISOString(),
17
- },
18
- };
19
- }
20
-
21
- function createTestSubscriber(name = 'test-subscriber'): SubscriberDefinition {
22
- return {
23
- name,
24
- description: 'Test subscriber',
25
- idempotent: 'resumable',
26
- importance: 'should-investigate',
27
- };
28
- }
29
-
30
- describe('ResumableContext', () => {
31
- let store: MemoryCheckpointStore;
32
- let envelope: Envelope;
33
- let subscriber: SubscriberDefinition;
34
-
35
- beforeEach(() => {
36
- store = new MemoryCheckpointStore();
37
- envelope = createTestEnvelope();
38
- subscriber = createTestSubscriber();
39
- });
40
-
41
- describe('io()', () => {
42
- it('should execute function and cache result on first call', async () => {
43
- const context = new ResumableContext({
44
- store,
45
- envelope,
46
- subscriber,
47
- });
48
-
49
- let executeCount = 0;
50
- const result = await context.io('step-1', () => {
51
- executeCount++;
52
- return 'result-1';
53
- });
54
-
55
- expect(result).toBe('result-1');
56
- expect(executeCount).toBe(1);
57
- expect(store.size).toBe(1);
58
- });
59
-
60
- it('should return cached result on retry without re-executing', async () => {
61
- // First execution - cache the result
62
- const firstContext = new ResumableContext({
63
- store,
64
- envelope,
65
- subscriber,
66
- });
67
-
68
- let executeCount = 0;
69
- await firstContext.io('step-1', () => {
70
- executeCount++;
71
- return 'result-1';
72
- });
73
-
74
- expect(executeCount).toBe(1);
75
-
76
- // Simulate retry - load existing checkpoint
77
- const checkpoint = await store.get(envelope.id);
78
- const retryContext = new ResumableContext({
79
- store,
80
- envelope: createTestEnvelope(envelope.id, 2),
81
- subscriber,
82
- existingCheckpoint: checkpoint,
83
- });
84
-
85
- const result = await retryContext.io<string>('step-1', () => {
86
- executeCount++;
87
- return 'should-not-be-used';
88
- });
89
-
90
- expect(result).toBe('result-1');
91
- expect(executeCount).toBe(1); // Still 1, not re-executed
92
- });
93
-
94
- it('should throw DuplicateIoKeyError on duplicate key within same execution', async () => {
95
- const context = new ResumableContext({
96
- store,
97
- envelope,
98
- subscriber,
99
- });
100
-
101
- await context.io('same-key', () => 'first');
102
-
103
- await expect(context.io('same-key', () => 'second')).rejects.toThrow(
104
- DuplicateIoKeyError,
105
- );
106
- });
107
-
108
- it('should handle async functions', async () => {
109
- const context = new ResumableContext({
110
- store,
111
- envelope,
112
- subscriber,
113
- });
114
-
115
- const result = await context.io('async-step', async () => {
116
- await new Promise((resolve) => setTimeout(resolve, 10));
117
- return { value: 42 };
118
- });
119
-
120
- expect(result).toEqual({ value: 42 });
121
- });
122
-
123
- it('should not cache failed operations', async () => {
124
- const context = new ResumableContext({
125
- store,
126
- envelope,
127
- subscriber,
128
- });
129
-
130
- // First attempt - fails
131
- await expect(
132
- context.io('failing-step', () => {
133
- throw new Error('Operation failed');
134
- }),
135
- ).rejects.toThrow('Operation failed');
136
-
137
- // Checkpoint should not contain the failed step
138
- const checkpoint = await store.get(envelope.id);
139
- expect(checkpoint?.completedSteps['failing-step']).toBeUndefined();
140
- });
141
-
142
- it('should persist checkpoint after each io() call', async () => {
143
- const context = new ResumableContext({
144
- store,
145
- envelope,
146
- subscriber,
147
- });
148
-
149
- await context.io('step-1', () => 'result-1');
150
- let checkpoint = await store.get(envelope.id);
151
- expect(Object.keys(checkpoint!.completedSteps)).toHaveLength(1);
152
-
153
- await context.io('step-2', () => 'result-2');
154
- checkpoint = await store.get(envelope.id);
155
- expect(Object.keys(checkpoint!.completedSteps)).toHaveLength(2);
156
- });
157
-
158
- it('should support various JSON-serializable return types', async () => {
159
- const context = new ResumableContext({
160
- store,
161
- envelope,
162
- subscriber,
163
- });
164
-
165
- expect(await context.io('string', () => 'hello')).toBe('hello');
166
- expect(await context.io('number', () => 42)).toBe(42);
167
- expect(await context.io('boolean', () => true)).toBe(true);
168
- expect(await context.io('null', () => null)).toBe(null);
169
- expect(await context.io('array', () => [1, 2, 3])).toEqual([1, 2, 3]);
170
- expect(await context.io('object', () => ({ foo: 'bar' }))).toEqual({
171
- foo: 'bar',
172
- });
173
- });
174
- });
175
-
176
- describe('all()', () => {
177
- it('should execute multiple operations in parallel', async () => {
178
- const context = new ResumableContext({
179
- store,
180
- envelope,
181
- subscriber,
182
- });
183
-
184
- const executionOrder: string[] = [];
185
- const [a, b, c] = await context.all([
186
- [
187
- 'fetch-a',
188
- () => {
189
- executionOrder.push('a');
190
- return 'result-a';
191
- },
192
- ],
193
- [
194
- 'fetch-b',
195
- () => {
196
- executionOrder.push('b');
197
- return 'result-b';
198
- },
199
- ],
200
- [
201
- 'fetch-c',
202
- () => {
203
- executionOrder.push('c');
204
- return 'result-c';
205
- },
206
- ],
207
- ]);
208
-
209
- expect(a).toBe('result-a');
210
- expect(b).toBe('result-b');
211
- expect(c).toBe('result-c');
212
- expect(executionOrder).toHaveLength(3);
213
- });
214
-
215
- it('should cache all results on retry', async () => {
216
- // First execution
217
- const firstContext = new ResumableContext({
218
- store,
219
- envelope,
220
- subscriber,
221
- });
222
-
223
- let executeCount = 0;
224
- await firstContext.all([
225
- [
226
- 'fetch-a',
227
- () => {
228
- executeCount++;
229
- return 'result-a';
230
- },
231
- ],
232
- [
233
- 'fetch-b',
234
- () => {
235
- executeCount++;
236
- return 'result-b';
237
- },
238
- ],
239
- ]);
240
-
241
- expect(executeCount).toBe(2);
242
-
243
- // Retry with cached checkpoint
244
- const checkpoint = await store.get(envelope.id);
245
- const retryContext = new ResumableContext({
246
- store,
247
- envelope: createTestEnvelope(envelope.id, 2),
248
- subscriber,
249
- existingCheckpoint: checkpoint,
250
- });
251
-
252
- const [a, b] = await retryContext.all([
253
- [
254
- 'fetch-a',
255
- () => {
256
- executeCount++;
257
- return 'new-a';
258
- },
259
- ],
260
- [
261
- 'fetch-b',
262
- () => {
263
- executeCount++;
264
- return 'new-b';
265
- },
266
- ],
267
- ]);
268
-
269
- expect(a).toBe('result-a'); // Cached
270
- expect(b).toBe('result-b'); // Cached
271
- expect(executeCount).toBe(2); // Still 2, not re-executed
272
- });
273
-
274
- it('should throw on duplicate key in all()', async () => {
275
- const context = new ResumableContext({
276
- store,
277
- envelope,
278
- subscriber,
279
- });
280
-
281
- await expect(
282
- context.all([
283
- ['same-key', () => 'first'],
284
- ['same-key', () => 'second'],
285
- ]),
286
- ).rejects.toThrow(DuplicateIoKeyError);
287
- });
288
-
289
- it('should throw if all() key conflicts with previous io() key', async () => {
290
- const context = new ResumableContext({
291
- store,
292
- envelope,
293
- subscriber,
294
- });
295
-
296
- await context.io('used-key', () => 'first');
297
-
298
- await expect(
299
- context.all([
300
- ['used-key', () => 'second'],
301
- ['new-key', () => 'third'],
302
- ]),
303
- ).rejects.toThrow(DuplicateIoKeyError);
304
- });
305
- });
306
-
307
- describe('attempt and isRetry', () => {
308
- it('should report attempt number from envelope', async () => {
309
- const context = new ResumableContext({
310
- store,
311
- envelope: createTestEnvelope('test', 3),
312
- subscriber,
313
- });
314
-
315
- expect(context.attempt).toBe(3);
316
- });
317
-
318
- it('should report isRetry as false for first attempt', async () => {
319
- const context = new ResumableContext({
320
- store,
321
- envelope: createTestEnvelope('test', 1),
322
- subscriber,
323
- });
324
-
325
- expect(context.isRetry).toBe(false);
326
- });
327
-
328
- it('should report isRetry as true for subsequent attempts', async () => {
329
- const context = new ResumableContext({
330
- store,
331
- envelope: createTestEnvelope('test', 2),
332
- subscriber,
333
- });
334
-
335
- expect(context.isRetry).toBe(true);
336
- });
337
- });
338
-
339
- describe('clear()', () => {
340
- it('should delete checkpoint from store', async () => {
341
- const context = new ResumableContext({
342
- store,
343
- envelope,
344
- subscriber,
345
- });
346
-
347
- await context.io('step-1', () => 'result');
348
- expect(store.size).toBe(1);
349
-
350
- await context.clear();
351
- expect(store.size).toBe(0);
352
- });
353
- });
354
-
355
- describe('hooks', () => {
356
- it('should call onCheckpointHit when using cached value', async () => {
357
- const onCheckpointHit = vi.fn();
358
-
359
- // First execution - populate cache
360
- const firstContext = new ResumableContext({
361
- store,
362
- envelope,
363
- subscriber,
364
- });
365
- await firstContext.io('cached-step', () => 'cached-result');
366
-
367
- // Retry with hooks
368
- const checkpoint = await store.get(envelope.id);
369
- const retryContext = new ResumableContext({
370
- store,
371
- envelope: createTestEnvelope(envelope.id, 2),
372
- subscriber,
373
- existingCheckpoint: checkpoint,
374
- hooks: { onCheckpointHit },
375
- });
376
-
377
- await retryContext.io('cached-step', () => 'new-result');
378
-
379
- expect(onCheckpointHit).toHaveBeenCalledWith({
380
- envelope: expect.anything(),
381
- subscriber,
382
- stepKey: 'cached-step',
383
- });
384
- });
385
-
386
- it('should call onCheckpointMiss when executing fresh', async () => {
387
- const onCheckpointMiss = vi.fn();
388
-
389
- const context = new ResumableContext({
390
- store,
391
- envelope,
392
- subscriber,
393
- hooks: { onCheckpointMiss },
394
- });
395
-
396
- await context.io('fresh-step', () => 'result');
397
-
398
- expect(onCheckpointMiss).toHaveBeenCalledWith({
399
- envelope,
400
- subscriber,
401
- stepKey: 'fresh-step',
402
- });
403
- });
404
- });
405
-
406
- describe('real-world scenarios', () => {
407
- it('should replay cached steps and execute new ones on retry', async () => {
408
- const executionLog: string[] = [];
409
- let shouldFail = true;
410
-
411
- // First attempt - fails after step-1
412
- const firstContext = new ResumableContext({
413
- store,
414
- envelope,
415
- subscriber,
416
- });
417
-
418
- try {
419
- await firstContext.io('step-0', () => {
420
- executionLog.push('step-0');
421
- return 'result-0';
422
- });
423
-
424
- await firstContext.io('step-1', () => {
425
- executionLog.push('step-1');
426
- return 'result-1';
427
- });
428
-
429
- if (shouldFail) {
430
- shouldFail = false;
431
- throw new Error('Simulated failure');
432
- }
433
-
434
- await firstContext.io('step-2', () => {
435
- executionLog.push('step-2');
436
- return 'result-2';
437
- });
438
- } catch {
439
- // Expected failure
440
- }
441
-
442
- expect(executionLog).toEqual(['step-0', 'step-1']);
443
-
444
- // Retry - step-0 and step-1 use cache, step-2 executes
445
- executionLog.length = 0;
446
- const checkpoint = await store.get(envelope.id);
447
- const retryContext = new ResumableContext({
448
- store,
449
- envelope: createTestEnvelope(envelope.id, 2),
450
- subscriber,
451
- existingCheckpoint: checkpoint,
452
- });
453
-
454
- await retryContext.io('step-0', () => {
455
- executionLog.push('step-0');
456
- return 'should-not-use';
457
- });
458
-
459
- await retryContext.io('step-1', () => {
460
- executionLog.push('step-1');
461
- return 'should-not-use';
462
- });
463
-
464
- await retryContext.io('step-2', () => {
465
- executionLog.push('step-2');
466
- return 'result-2';
467
- });
468
-
469
- expect(executionLog).toEqual(['step-2']); // Only step-2 executed!
470
- });
471
-
472
- it('should handle conditional io() calls correctly', async () => {
473
- const context = new ResumableContext({
474
- store,
475
- envelope: { ...envelope, data: { sendEmail: true } },
476
- subscriber,
477
- });
478
-
479
- const result = await context.io('send-email', () => ({
480
- messageId: 'msg-123',
481
- }));
482
-
483
- expect(result).toEqual({ messageId: 'msg-123' });
484
- });
485
-
486
- it('should handle dynamic loop with unique keys', async () => {
487
- const context = new ResumableContext({
488
- store,
489
- envelope,
490
- subscriber,
491
- });
492
-
493
- const items = [
494
- { id: 'item-1', value: 10 },
495
- { id: 'item-2', value: 20 },
496
- { id: 'item-3', value: 30 },
497
- ];
498
-
499
- const results: number[] = [];
500
- for (const item of items) {
501
- const processed = await context.io(`process-${item.id}`, () => {
502
- return item.value * 2;
503
- });
504
- results.push(processed);
505
- }
506
-
507
- expect(results).toEqual([20, 40, 60]);
508
- });
509
- });
510
- });
@@ -1,213 +0,0 @@
1
- import { DuplicateIoKeyError } from '../errors/index.js';
2
- import type { Envelope, SubscriberDefinition } from '../types/index.js';
3
- import type {
4
- Checkpoint,
5
- CheckpointHitContext,
6
- CheckpointMissContext,
7
- CheckpointStore,
8
- JsonSerializable,
9
- SubscriberContext,
10
- } from './types.js';
11
-
12
- /**
13
- * Hooks for observability during context operations.
14
- */
15
- export interface ResumableContextHooks {
16
- onCheckpointHit?(context: CheckpointHitContext): void | Promise<void>;
17
- onCheckpointMiss?(context: CheckpointMissContext): void | Promise<void>;
18
- }
19
-
20
- /**
21
- * Configuration for creating a ResumableContext.
22
- */
23
- export interface ResumableContextConfig {
24
- readonly store: CheckpointStore;
25
- readonly envelope: Envelope;
26
- readonly subscriber: SubscriberDefinition;
27
- readonly existingCheckpoint?: Checkpoint | undefined;
28
- readonly hooks?: ResumableContextHooks | undefined;
29
- }
30
-
31
- /**
32
- * Implementation of SubscriberContext that provides io() caching.
33
- *
34
- * On first execution, io() calls execute their lambdas and cache results.
35
- * On retry (when existingCheckpoint is provided), cached results are returned
36
- * without re-executing the lambda.
37
- */
38
- export class ResumableContext implements SubscriberContext {
39
- private checkpoint: Checkpoint;
40
- private readonly usedKeys = new Set<string>();
41
- private readonly store: CheckpointStore;
42
- private readonly envelope: Envelope;
43
- private readonly subscriber: SubscriberDefinition;
44
- private readonly hooks: ResumableContextHooks | undefined;
45
-
46
- constructor(config: ResumableContextConfig) {
47
- this.store = config.store;
48
- this.envelope = config.envelope;
49
- this.subscriber = config.subscriber;
50
- this.hooks = config.hooks;
51
-
52
- this.checkpoint = config.existingCheckpoint ?? {
53
- envelopeId: config.envelope.id,
54
- subscriberName: config.subscriber.name,
55
- completedSteps: {},
56
- };
57
- }
58
-
59
- get attempt(): number {
60
- return this.envelope.docket.attempts;
61
- }
62
-
63
- get isRetry(): boolean {
64
- return this.attempt > 1;
65
- }
66
-
67
- async io<T extends JsonSerializable>(
68
- key: string,
69
- fn: () => Promise<T> | T,
70
- ): Promise<T> {
71
- // Validate key uniqueness within this execution
72
- if (this.usedKeys.has(key)) {
73
- throw new DuplicateIoKeyError(key, this.subscriber.name);
74
- }
75
- this.usedKeys.add(key);
76
-
77
- // Check cache first
78
- if (key in this.checkpoint.completedSteps) {
79
- await this.hooks?.onCheckpointHit?.({
80
- envelope: this.envelope,
81
- subscriber: this.subscriber,
82
- stepKey: key,
83
- });
84
- return this.checkpoint.completedSteps[key] as T;
85
- }
86
-
87
- // Notify cache miss
88
- await this.hooks?.onCheckpointMiss?.({
89
- envelope: this.envelope,
90
- subscriber: this.subscriber,
91
- stepKey: key,
92
- });
93
-
94
- // Execute the function - errors propagate, no caching on failure
95
- const result = await fn();
96
-
97
- // Cache the result
98
- this.checkpoint = {
99
- ...this.checkpoint,
100
- completedSteps: {
101
- ...this.checkpoint.completedSteps,
102
- [key]: result,
103
- },
104
- };
105
-
106
- // Persist checkpoint immediately (incremental persistence)
107
- await this.store.set(this.envelope.id, this.checkpoint);
108
-
109
- return result;
110
- }
111
-
112
- async all<
113
- T extends readonly [
114
- string,
115
- () => Promise<JsonSerializable> | JsonSerializable,
116
- ][],
117
- >(
118
- ops: T,
119
- ): Promise<{
120
- [K in keyof T]: T[K] extends [string, () => Promise<infer R> | infer R]
121
- ? R
122
- : never;
123
- }> {
124
- // First, check for duplicates within this all() call
125
- const keysInThisCall = new Set<string>();
126
- for (const [key] of ops) {
127
- if (keysInThisCall.has(key)) {
128
- throw new DuplicateIoKeyError(key, this.subscriber.name);
129
- }
130
- keysInThisCall.add(key);
131
- }
132
-
133
- // Then validate against previously used keys
134
- for (const [key] of ops) {
135
- if (this.usedKeys.has(key)) {
136
- throw new DuplicateIoKeyError(key, this.subscriber.name);
137
- }
138
- }
139
-
140
- // Mark all keys as used
141
- for (const [key] of ops) {
142
- this.usedKeys.add(key);
143
- }
144
-
145
- // Execute all operations in parallel
146
- const results = await Promise.all(
147
- ops.map(async ([key, fn]) => {
148
- // Check cache first
149
- if (key in this.checkpoint.completedSteps) {
150
- await this.hooks?.onCheckpointHit?.({
151
- envelope: this.envelope,
152
- subscriber: this.subscriber,
153
- stepKey: key,
154
- });
155
- return this.checkpoint.completedSteps[key];
156
- }
157
-
158
- // Notify cache miss
159
- await this.hooks?.onCheckpointMiss?.({
160
- envelope: this.envelope,
161
- subscriber: this.subscriber,
162
- stepKey: key,
163
- });
164
-
165
- // Execute - errors propagate
166
- const result = await fn();
167
-
168
- // Cache individually (in local state, will persist after Promise.all)
169
- this.checkpoint = {
170
- ...this.checkpoint,
171
- completedSteps: {
172
- ...this.checkpoint.completedSteps,
173
- [key]: result,
174
- },
175
- };
176
-
177
- return result;
178
- }),
179
- );
180
-
181
- // Persist after all parallel operations complete
182
- await this.store.set(this.envelope.id, this.checkpoint);
183
-
184
- return results as {
185
- [K in keyof T]: T[K] extends [string, () => Promise<infer R> | infer R]
186
- ? R
187
- : never;
188
- };
189
- }
190
-
191
- /**
192
- * Clears the checkpoint from storage.
193
- * Called after successful completion or dead-letter.
194
- */
195
- async clear(): Promise<void> {
196
- await this.store.delete(this.envelope.id);
197
- }
198
-
199
- /**
200
- * Gets the current checkpoint state.
201
- * Useful for debugging and testing.
202
- */
203
- getCheckpoint(): Checkpoint {
204
- return this.checkpoint;
205
- }
206
-
207
- /**
208
- * Gets the number of cached steps.
209
- */
210
- get cachedStepCount(): number {
211
- return Object.keys(this.checkpoint.completedSteps).length;
212
- }
213
- }