@auto-engineer/pipeline 1.68.0 → 1.70.0
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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +6 -6
- package/.turbo/turbo-type-check.log +1 -1
- package/CHANGELOG.md +63 -0
- package/dist/src/engine/workflow-processor.d.ts +3 -0
- package/dist/src/engine/workflow-processor.d.ts.map +1 -1
- package/dist/src/engine/workflow-processor.js +50 -7
- package/dist/src/engine/workflow-processor.js.map +1 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/server/phased-bridge.d.ts +13 -0
- package/dist/src/server/phased-bridge.d.ts.map +1 -0
- package/dist/src/server/phased-bridge.js +103 -0
- package/dist/src/server/phased-bridge.js.map +1 -0
- package/dist/src/server/pipeline-server.d.ts +2 -2
- package/dist/src/server/pipeline-server.d.ts.map +1 -1
- package/dist/src/server/pipeline-server.js +19 -39
- package/dist/src/server/pipeline-server.js.map +1 -1
- package/dist/src/server/v2-runtime-bridge.d.ts +21 -0
- package/dist/src/server/v2-runtime-bridge.d.ts.map +1 -0
- package/dist/src/server/v2-runtime-bridge.js +184 -0
- package/dist/src/server/v2-runtime-bridge.js.map +1 -0
- package/dist/src/store/pipeline-event-store.d.ts.map +1 -1
- package/dist/src/store/pipeline-event-store.js +0 -30
- package/dist/src/store/pipeline-event-store.js.map +1 -1
- package/dist/src/store/pipeline-read-model.d.ts +0 -15
- package/dist/src/store/pipeline-read-model.d.ts.map +1 -1
- package/dist/src/store/pipeline-read-model.js +0 -49
- package/dist/src/store/pipeline-read-model.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/ketchup-plan.md +10 -12
- package/package.json +3 -3
- package/src/engine/workflow-processor.specs.ts +101 -0
- package/src/engine/workflow-processor.ts +54 -8
- package/src/index.ts +0 -2
- package/src/server/phased-bridge.specs.ts +272 -0
- package/src/server/phased-bridge.ts +130 -0
- package/src/server/pipeline-server.specs.ts +94 -0
- package/src/server/pipeline-server.ts +21 -42
- package/src/server/v2-runtime-bridge.specs.ts +347 -0
- package/src/server/v2-runtime-bridge.ts +255 -0
- package/src/store/pipeline-event-store.specs.ts +0 -137
- package/src/store/pipeline-event-store.ts +0 -35
- package/src/store/pipeline-read-model.specs.ts +0 -567
- package/src/store/pipeline-read-model.ts +0 -71
- package/dist/src/projections/phased-execution-projection.d.ts +0 -77
- package/dist/src/projections/phased-execution-projection.d.ts.map +0 -1
- package/dist/src/projections/phased-execution-projection.js +0 -54
- package/dist/src/projections/phased-execution-projection.js.map +0 -1
- package/dist/src/projections/settled-instance-projection.d.ts +0 -67
- package/dist/src/projections/settled-instance-projection.d.ts.map +0 -1
- package/dist/src/projections/settled-instance-projection.js +0 -66
- package/dist/src/projections/settled-instance-projection.js.map +0 -1
- package/dist/src/runtime/phased-executor.d.ts +0 -34
- package/dist/src/runtime/phased-executor.d.ts.map +0 -1
- package/dist/src/runtime/phased-executor.js +0 -172
- package/dist/src/runtime/phased-executor.js.map +0 -1
- package/dist/src/runtime/settled-tracker.d.ts +0 -44
- package/dist/src/runtime/settled-tracker.d.ts.map +0 -1
- package/dist/src/runtime/settled-tracker.js +0 -170
- package/dist/src/runtime/settled-tracker.js.map +0 -1
- package/src/projections/phased-execution-projection.specs.ts +0 -202
- package/src/projections/phased-execution-projection.ts +0 -146
- package/src/projections/settled-instance-projection.specs.ts +0 -296
- package/src/projections/settled-instance-projection.ts +0 -160
- package/src/runtime/phased-executor.specs.ts +0 -680
- package/src/runtime/phased-executor.ts +0 -230
- package/src/runtime/settled-tracker.specs.ts +0 -1044
- package/src/runtime/settled-tracker.ts +0 -235
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
evolve,
|
|
4
|
-
type SettledCommandStartedEvent,
|
|
5
|
-
type SettledEventReceivedEvent,
|
|
6
|
-
type SettledHandlerFiredEvent,
|
|
7
|
-
type SettledInstanceCleanedEvent,
|
|
8
|
-
type SettledInstanceCreatedEvent,
|
|
9
|
-
type SettledInstanceDocument,
|
|
10
|
-
type SettledInstanceResetEvent,
|
|
11
|
-
} from './settled-instance-projection';
|
|
12
|
-
|
|
13
|
-
describe('SettledInstanceProjection', () => {
|
|
14
|
-
describe('evolve', () => {
|
|
15
|
-
describe('SettledInstanceCreated', () => {
|
|
16
|
-
it('creates document with initial command trackers', () => {
|
|
17
|
-
const event: SettledInstanceCreatedEvent = {
|
|
18
|
-
type: 'SettledInstanceCreated',
|
|
19
|
-
data: {
|
|
20
|
-
templateId: 'template-CmdA,CmdB',
|
|
21
|
-
correlationId: 'c1',
|
|
22
|
-
commandTypes: ['CmdA', 'CmdB'],
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const result = evolve(null, event);
|
|
27
|
-
|
|
28
|
-
expect(result).toEqual({
|
|
29
|
-
instanceId: 'template-CmdA,CmdB-c1',
|
|
30
|
-
templateId: 'template-CmdA,CmdB',
|
|
31
|
-
correlationId: 'c1',
|
|
32
|
-
commandTrackers: [
|
|
33
|
-
{ commandType: 'CmdA', hasStarted: false, hasCompleted: false, events: [] },
|
|
34
|
-
{ commandType: 'CmdB', hasStarted: false, hasCompleted: false, events: [] },
|
|
35
|
-
],
|
|
36
|
-
status: 'active',
|
|
37
|
-
firedCount: 0,
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('SettledCommandStarted', () => {
|
|
43
|
-
it('sets hasStarted true for the specified command', () => {
|
|
44
|
-
const existing: SettledInstanceDocument = {
|
|
45
|
-
instanceId: 'template-CmdA,CmdB-c1',
|
|
46
|
-
templateId: 'template-CmdA,CmdB',
|
|
47
|
-
correlationId: 'c1',
|
|
48
|
-
commandTrackers: [
|
|
49
|
-
{ commandType: 'CmdA', hasStarted: false, hasCompleted: false, events: [] },
|
|
50
|
-
{ commandType: 'CmdB', hasStarted: false, hasCompleted: false, events: [] },
|
|
51
|
-
],
|
|
52
|
-
status: 'active',
|
|
53
|
-
firedCount: 0,
|
|
54
|
-
};
|
|
55
|
-
const event: SettledCommandStartedEvent = {
|
|
56
|
-
type: 'SettledCommandStarted',
|
|
57
|
-
data: {
|
|
58
|
-
templateId: 'template-CmdA,CmdB',
|
|
59
|
-
correlationId: 'c1',
|
|
60
|
-
commandType: 'CmdA',
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const result = evolve(existing, event);
|
|
65
|
-
|
|
66
|
-
expect(result.commandTrackers[0]).toEqual({
|
|
67
|
-
commandType: 'CmdA',
|
|
68
|
-
hasStarted: true,
|
|
69
|
-
hasCompleted: false,
|
|
70
|
-
events: [],
|
|
71
|
-
});
|
|
72
|
-
expect(result.commandTrackers[1]).toEqual({
|
|
73
|
-
commandType: 'CmdB',
|
|
74
|
-
hasStarted: false,
|
|
75
|
-
hasCompleted: false,
|
|
76
|
-
events: [],
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('preserves hasCompleted when command restarts (supports concurrent commands)', () => {
|
|
81
|
-
const existing: SettledInstanceDocument = {
|
|
82
|
-
instanceId: 'template-CmdA-c1',
|
|
83
|
-
templateId: 'template-CmdA',
|
|
84
|
-
correlationId: 'c1',
|
|
85
|
-
commandTrackers: [{ commandType: 'CmdA', hasStarted: true, hasCompleted: true, events: [] }],
|
|
86
|
-
status: 'active',
|
|
87
|
-
firedCount: 0,
|
|
88
|
-
};
|
|
89
|
-
const event: SettledCommandStartedEvent = {
|
|
90
|
-
type: 'SettledCommandStarted',
|
|
91
|
-
data: {
|
|
92
|
-
templateId: 'template-CmdA',
|
|
93
|
-
correlationId: 'c1',
|
|
94
|
-
commandType: 'CmdA',
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const result = evolve(existing, event);
|
|
99
|
-
|
|
100
|
-
expect(result.commandTrackers[0]).toEqual({
|
|
101
|
-
commandType: 'CmdA',
|
|
102
|
-
hasStarted: true,
|
|
103
|
-
hasCompleted: true,
|
|
104
|
-
events: [],
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('SettledEventReceived', () => {
|
|
110
|
-
it('adds event to tracker and sets hasCompleted true', () => {
|
|
111
|
-
const existing: SettledInstanceDocument = {
|
|
112
|
-
instanceId: 'template-CmdA-c1',
|
|
113
|
-
templateId: 'template-CmdA',
|
|
114
|
-
correlationId: 'c1',
|
|
115
|
-
commandTrackers: [{ commandType: 'CmdA', hasStarted: true, hasCompleted: false, events: [] }],
|
|
116
|
-
status: 'active',
|
|
117
|
-
firedCount: 0,
|
|
118
|
-
};
|
|
119
|
-
const domainEvent = { type: 'UserCreated', correlationId: 'c1', data: { userId: 'u1' } };
|
|
120
|
-
const event: SettledEventReceivedEvent = {
|
|
121
|
-
type: 'SettledEventReceived',
|
|
122
|
-
data: {
|
|
123
|
-
templateId: 'template-CmdA',
|
|
124
|
-
correlationId: 'c1',
|
|
125
|
-
commandType: 'CmdA',
|
|
126
|
-
event: domainEvent,
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const result = evolve(existing, event);
|
|
131
|
-
|
|
132
|
-
expect(result.commandTrackers[0]).toEqual({
|
|
133
|
-
commandType: 'CmdA',
|
|
134
|
-
hasStarted: true,
|
|
135
|
-
hasCompleted: true,
|
|
136
|
-
events: [domainEvent],
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('appends multiple events to tracker', () => {
|
|
141
|
-
const event1 = { type: 'Event1', correlationId: 'c1', data: {} };
|
|
142
|
-
const existing: SettledInstanceDocument = {
|
|
143
|
-
instanceId: 'template-CmdA-c1',
|
|
144
|
-
templateId: 'template-CmdA',
|
|
145
|
-
correlationId: 'c1',
|
|
146
|
-
commandTrackers: [{ commandType: 'CmdA', hasStarted: true, hasCompleted: true, events: [event1] }],
|
|
147
|
-
status: 'active',
|
|
148
|
-
firedCount: 0,
|
|
149
|
-
};
|
|
150
|
-
const event2 = { type: 'Event2', correlationId: 'c1', data: {} };
|
|
151
|
-
const event: SettledEventReceivedEvent = {
|
|
152
|
-
type: 'SettledEventReceived',
|
|
153
|
-
data: {
|
|
154
|
-
templateId: 'template-CmdA',
|
|
155
|
-
correlationId: 'c1',
|
|
156
|
-
commandType: 'CmdA',
|
|
157
|
-
event: event2,
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const result = evolve(existing, event);
|
|
162
|
-
|
|
163
|
-
expect(result.commandTrackers[0].events).toEqual([event1, event2]);
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
describe('SettledHandlerFired', () => {
|
|
168
|
-
it('sets status to fired and increments firedCount', () => {
|
|
169
|
-
const existing: SettledInstanceDocument = {
|
|
170
|
-
instanceId: 'template-CmdA-c1',
|
|
171
|
-
templateId: 'template-CmdA',
|
|
172
|
-
correlationId: 'c1',
|
|
173
|
-
commandTrackers: [{ commandType: 'CmdA', hasStarted: true, hasCompleted: true, events: [] }],
|
|
174
|
-
status: 'active',
|
|
175
|
-
firedCount: 0,
|
|
176
|
-
};
|
|
177
|
-
const event: SettledHandlerFiredEvent = {
|
|
178
|
-
type: 'SettledHandlerFired',
|
|
179
|
-
data: {
|
|
180
|
-
templateId: 'template-CmdA',
|
|
181
|
-
correlationId: 'c1',
|
|
182
|
-
persist: false,
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const result = evolve(existing, event);
|
|
187
|
-
|
|
188
|
-
expect(result.status).toBe('fired');
|
|
189
|
-
expect(result.firedCount).toBe(1);
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
describe('SettledInstanceReset', () => {
|
|
194
|
-
it('clears trackers and sets status back to active', () => {
|
|
195
|
-
const domainEvent = { type: 'Event1', correlationId: 'c1', data: {} };
|
|
196
|
-
const existing: SettledInstanceDocument = {
|
|
197
|
-
instanceId: 'template-CmdA,CmdB-c1',
|
|
198
|
-
templateId: 'template-CmdA,CmdB',
|
|
199
|
-
correlationId: 'c1',
|
|
200
|
-
commandTrackers: [
|
|
201
|
-
{ commandType: 'CmdA', hasStarted: true, hasCompleted: true, events: [domainEvent] },
|
|
202
|
-
{ commandType: 'CmdB', hasStarted: true, hasCompleted: true, events: [domainEvent] },
|
|
203
|
-
],
|
|
204
|
-
status: 'fired',
|
|
205
|
-
firedCount: 1,
|
|
206
|
-
};
|
|
207
|
-
const event: SettledInstanceResetEvent = {
|
|
208
|
-
type: 'SettledInstanceReset',
|
|
209
|
-
data: {
|
|
210
|
-
templateId: 'template-CmdA,CmdB',
|
|
211
|
-
correlationId: 'c1',
|
|
212
|
-
},
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
const result = evolve(existing, event);
|
|
216
|
-
|
|
217
|
-
expect(result.status).toBe('active');
|
|
218
|
-
expect(result.commandTrackers).toEqual([
|
|
219
|
-
{ commandType: 'CmdA', hasStarted: true, hasCompleted: false, events: [] },
|
|
220
|
-
{ commandType: 'CmdB', hasStarted: true, hasCompleted: false, events: [] },
|
|
221
|
-
]);
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
describe('SettledInstanceCleaned', () => {
|
|
226
|
-
it('sets status to cleaned', () => {
|
|
227
|
-
const existing: SettledInstanceDocument = {
|
|
228
|
-
instanceId: 'template-CmdA-c1',
|
|
229
|
-
templateId: 'template-CmdA',
|
|
230
|
-
correlationId: 'c1',
|
|
231
|
-
commandTrackers: [{ commandType: 'CmdA', hasStarted: true, hasCompleted: true, events: [] }],
|
|
232
|
-
status: 'fired',
|
|
233
|
-
firedCount: 1,
|
|
234
|
-
};
|
|
235
|
-
const event: SettledInstanceCleanedEvent = {
|
|
236
|
-
type: 'SettledInstanceCleaned',
|
|
237
|
-
data: {
|
|
238
|
-
templateId: 'template-CmdA',
|
|
239
|
-
correlationId: 'c1',
|
|
240
|
-
},
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
const result = evolve(existing, event);
|
|
244
|
-
|
|
245
|
-
expect(result.status).toBe('cleaned');
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
describe('null document assertions', () => {
|
|
250
|
-
it('should throw when applying SettledCommandStarted to null document', () => {
|
|
251
|
-
const event: SettledCommandStartedEvent = {
|
|
252
|
-
type: 'SettledCommandStarted',
|
|
253
|
-
data: { templateId: 't1', correlationId: 'c1', commandType: 'Cmd' },
|
|
254
|
-
};
|
|
255
|
-
expect(() => evolve(null, event)).toThrow('Cannot apply SettledCommandStarted to null document');
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it('should throw when applying SettledEventReceived to null document', () => {
|
|
259
|
-
const event: SettledEventReceivedEvent = {
|
|
260
|
-
type: 'SettledEventReceived',
|
|
261
|
-
data: {
|
|
262
|
-
templateId: 't1',
|
|
263
|
-
correlationId: 'c1',
|
|
264
|
-
commandType: 'Cmd',
|
|
265
|
-
event: { type: 'E', correlationId: 'c1', data: {} },
|
|
266
|
-
},
|
|
267
|
-
};
|
|
268
|
-
expect(() => evolve(null, event)).toThrow('Cannot apply SettledEventReceived to null document');
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it('should throw when applying SettledHandlerFired to null document', () => {
|
|
272
|
-
const event: SettledHandlerFiredEvent = {
|
|
273
|
-
type: 'SettledHandlerFired',
|
|
274
|
-
data: { templateId: 't1', correlationId: 'c1', persist: false },
|
|
275
|
-
};
|
|
276
|
-
expect(() => evolve(null, event)).toThrow('Cannot apply SettledHandlerFired to null document');
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it('should throw when applying SettledInstanceReset to null document', () => {
|
|
280
|
-
const event: SettledInstanceResetEvent = {
|
|
281
|
-
type: 'SettledInstanceReset',
|
|
282
|
-
data: { templateId: 't1', correlationId: 'c1' },
|
|
283
|
-
};
|
|
284
|
-
expect(() => evolve(null, event)).toThrow('Cannot apply SettledInstanceReset to null document');
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('should throw when applying SettledInstanceCleaned to null document', () => {
|
|
288
|
-
const event: SettledInstanceCleanedEvent = {
|
|
289
|
-
type: 'SettledInstanceCleaned',
|
|
290
|
-
data: { templateId: 't1', correlationId: 'c1' },
|
|
291
|
-
};
|
|
292
|
-
expect(() => evolve(null, event)).toThrow('Cannot apply SettledInstanceCleaned to null document');
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
});
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import type { Event } from '@auto-engineer/message-bus';
|
|
2
|
-
|
|
3
|
-
interface CommandTracker {
|
|
4
|
-
commandType: string;
|
|
5
|
-
hasStarted: boolean;
|
|
6
|
-
hasCompleted: boolean;
|
|
7
|
-
events: Event[];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface SettledInstanceDocument {
|
|
11
|
-
[key: string]: unknown;
|
|
12
|
-
instanceId: string;
|
|
13
|
-
templateId: string;
|
|
14
|
-
correlationId: string;
|
|
15
|
-
commandTrackers: CommandTracker[];
|
|
16
|
-
status: 'active' | 'fired' | 'cleaned';
|
|
17
|
-
firedCount: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface SettledInstanceCreatedEvent {
|
|
21
|
-
type: 'SettledInstanceCreated';
|
|
22
|
-
data: {
|
|
23
|
-
templateId: string;
|
|
24
|
-
correlationId: string;
|
|
25
|
-
commandTypes: readonly string[];
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface SettledCommandStartedEvent {
|
|
30
|
-
type: 'SettledCommandStarted';
|
|
31
|
-
data: {
|
|
32
|
-
templateId: string;
|
|
33
|
-
correlationId: string;
|
|
34
|
-
commandType: string;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface SettledEventReceivedEvent {
|
|
39
|
-
type: 'SettledEventReceived';
|
|
40
|
-
data: {
|
|
41
|
-
templateId: string;
|
|
42
|
-
correlationId: string;
|
|
43
|
-
commandType: string;
|
|
44
|
-
event: Event;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface SettledHandlerFiredEvent {
|
|
49
|
-
type: 'SettledHandlerFired';
|
|
50
|
-
data: {
|
|
51
|
-
templateId: string;
|
|
52
|
-
correlationId: string;
|
|
53
|
-
persist: boolean;
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface SettledInstanceResetEvent {
|
|
58
|
-
type: 'SettledInstanceReset';
|
|
59
|
-
data: {
|
|
60
|
-
templateId: string;
|
|
61
|
-
correlationId: string;
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface SettledInstanceCleanedEvent {
|
|
66
|
-
type: 'SettledInstanceCleaned';
|
|
67
|
-
data: {
|
|
68
|
-
templateId: string;
|
|
69
|
-
correlationId: string;
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export type SettledEvent =
|
|
74
|
-
| SettledInstanceCreatedEvent
|
|
75
|
-
| SettledCommandStartedEvent
|
|
76
|
-
| SettledEventReceivedEvent
|
|
77
|
-
| SettledHandlerFiredEvent
|
|
78
|
-
| SettledInstanceResetEvent
|
|
79
|
-
| SettledInstanceCleanedEvent;
|
|
80
|
-
|
|
81
|
-
function assertDocument(
|
|
82
|
-
document: SettledInstanceDocument | null,
|
|
83
|
-
eventType: string,
|
|
84
|
-
): asserts document is SettledInstanceDocument {
|
|
85
|
-
if (document === null) {
|
|
86
|
-
throw new Error(`Cannot apply ${eventType} to null document`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function evolveCommandStarted(document: SettledInstanceDocument, commandType: string): SettledInstanceDocument {
|
|
91
|
-
return {
|
|
92
|
-
...document,
|
|
93
|
-
commandTrackers: document.commandTrackers.map((tracker) =>
|
|
94
|
-
tracker.commandType === commandType ? { ...tracker, hasStarted: true } : tracker,
|
|
95
|
-
),
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function evolveEventReceived(
|
|
100
|
-
document: SettledInstanceDocument,
|
|
101
|
-
commandType: string,
|
|
102
|
-
domainEvent: Event,
|
|
103
|
-
): SettledInstanceDocument {
|
|
104
|
-
return {
|
|
105
|
-
...document,
|
|
106
|
-
commandTrackers: document.commandTrackers.map((tracker) =>
|
|
107
|
-
tracker.commandType === commandType
|
|
108
|
-
? { ...tracker, hasCompleted: true, events: [...tracker.events, domainEvent] }
|
|
109
|
-
: tracker,
|
|
110
|
-
),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function evolveReset(document: SettledInstanceDocument): SettledInstanceDocument {
|
|
115
|
-
return {
|
|
116
|
-
...document,
|
|
117
|
-
status: 'active',
|
|
118
|
-
commandTrackers: document.commandTrackers.map((tracker) => ({
|
|
119
|
-
...tracker,
|
|
120
|
-
hasCompleted: false,
|
|
121
|
-
events: [],
|
|
122
|
-
})),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function evolve(document: SettledInstanceDocument | null, event: SettledEvent): SettledInstanceDocument {
|
|
127
|
-
switch (event.type) {
|
|
128
|
-
case 'SettledInstanceCreated': {
|
|
129
|
-
const { templateId, correlationId, commandTypes } = event.data;
|
|
130
|
-
return {
|
|
131
|
-
instanceId: `${templateId}-${correlationId}`,
|
|
132
|
-
templateId,
|
|
133
|
-
correlationId,
|
|
134
|
-
commandTrackers: commandTypes.map((commandType) => ({
|
|
135
|
-
commandType,
|
|
136
|
-
hasStarted: false,
|
|
137
|
-
hasCompleted: false,
|
|
138
|
-
events: [],
|
|
139
|
-
})),
|
|
140
|
-
status: 'active',
|
|
141
|
-
firedCount: 0,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
case 'SettledCommandStarted':
|
|
145
|
-
assertDocument(document, event.type);
|
|
146
|
-
return evolveCommandStarted(document, event.data.commandType);
|
|
147
|
-
case 'SettledEventReceived':
|
|
148
|
-
assertDocument(document, event.type);
|
|
149
|
-
return evolveEventReceived(document, event.data.commandType, event.data.event);
|
|
150
|
-
case 'SettledHandlerFired':
|
|
151
|
-
assertDocument(document, event.type);
|
|
152
|
-
return { ...document, status: 'fired', firedCount: document.firedCount + 1 };
|
|
153
|
-
case 'SettledInstanceReset':
|
|
154
|
-
assertDocument(document, event.type);
|
|
155
|
-
return evolveReset(document);
|
|
156
|
-
case 'SettledInstanceCleaned':
|
|
157
|
-
assertDocument(document, event.type);
|
|
158
|
-
return { ...document, status: 'cleaned' };
|
|
159
|
-
}
|
|
160
|
-
}
|