@auto-engineer/pipeline 1.68.0 → 1.69.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 +29 -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 +18 -38
- 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 +182 -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.ts +20 -41
- package/src/server/v2-runtime-bridge.specs.ts +347 -0
- package/src/server/v2-runtime-bridge.ts +246 -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,235 +0,0 @@
|
|
|
1
|
-
import type { Command, Event } from '@auto-engineer/message-bus';
|
|
2
|
-
import type { SettledEvent, SettledInstanceDocument } from '../projections/settled-instance-projection';
|
|
3
|
-
import type { PipelineReadModel } from '../store/pipeline-read-model';
|
|
4
|
-
|
|
5
|
-
type SendFunction = (commandType: string, data: unknown) => void;
|
|
6
|
-
|
|
7
|
-
type SettledHandler = (events: Record<string, Event[]>, send: SendFunction) => undefined | { persist: boolean };
|
|
8
|
-
|
|
9
|
-
interface SettledHandlerRegistration {
|
|
10
|
-
commandTypes: readonly string[];
|
|
11
|
-
handler: SettledHandler;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface HandlerTemplate {
|
|
15
|
-
id: string;
|
|
16
|
-
registration: SettledHandlerRegistration;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface SettledErrorContext {
|
|
20
|
-
commandTypes: readonly string[];
|
|
21
|
-
correlationId: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface SettledTrackerOptions {
|
|
25
|
-
readModel: PipelineReadModel;
|
|
26
|
-
onDispatch?: (commandType: string, data: unknown, correlationId: string) => void;
|
|
27
|
-
onError?: (error: unknown, context: SettledErrorContext) => void;
|
|
28
|
-
onEventEmit?: (event: SettledEvent) => void | Promise<void>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class SettledTracker {
|
|
32
|
-
private handlerTemplates = new Map<string, HandlerTemplate>();
|
|
33
|
-
private commandToTemplateIds = new Map<string, Set<string>>();
|
|
34
|
-
private readonly readModel: PipelineReadModel;
|
|
35
|
-
private readonly onDispatch?: (commandType: string, data: unknown, correlationId: string) => void;
|
|
36
|
-
private readonly onError?: (error: unknown, context: SettledErrorContext) => void;
|
|
37
|
-
private readonly onEventEmit?: (event: SettledEvent) => void | Promise<void>;
|
|
38
|
-
|
|
39
|
-
constructor(options: SettledTrackerOptions) {
|
|
40
|
-
this.readModel = options.readModel;
|
|
41
|
-
this.onDispatch = options.onDispatch;
|
|
42
|
-
this.onError = options.onError;
|
|
43
|
-
this.onEventEmit = options.onEventEmit;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
registerHandler(registration: SettledHandlerRegistration): void {
|
|
47
|
-
const templateId = this.generateTemplateId(registration);
|
|
48
|
-
|
|
49
|
-
this.handlerTemplates.set(templateId, {
|
|
50
|
-
id: templateId,
|
|
51
|
-
registration,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
for (const commandType of registration.commandTypes) {
|
|
55
|
-
const existing = this.commandToTemplateIds.get(commandType) ?? new Set<string>();
|
|
56
|
-
existing.add(templateId);
|
|
57
|
-
this.commandToTemplateIds.set(commandType, existing);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async onCommandStarted(command: Command): Promise<void> {
|
|
62
|
-
const { type: commandType, correlationId, requestId } = command;
|
|
63
|
-
|
|
64
|
-
if (!this.isValidId(correlationId) || !this.isValidId(requestId)) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const templateIds = this.commandToTemplateIds.get(commandType);
|
|
69
|
-
if (!templateIds) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
for (const templateId of templateIds) {
|
|
74
|
-
const template = this.handlerTemplates.get(templateId);
|
|
75
|
-
if (template) {
|
|
76
|
-
await this.ensureInstanceExists(template, correlationId);
|
|
77
|
-
await this.markCommandStarted(template.id, correlationId, commandType);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async isWaitingForAsync(correlationId: string, commandType: string): Promise<boolean> {
|
|
83
|
-
const instances = await this.readModel.getActiveSettledInstances(correlationId);
|
|
84
|
-
for (const instance of instances) {
|
|
85
|
-
const tracker = instance.commandTrackers.find((t) => t.commandType === commandType);
|
|
86
|
-
if (tracker?.hasStarted === true && tracker.hasCompleted === false) {
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async onEventReceived(event: Event, sourceCommandType: string): Promise<void> {
|
|
94
|
-
const correlationId = event.correlationId;
|
|
95
|
-
|
|
96
|
-
if (!this.isValidId(correlationId)) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const instances = await this.readModel.getActiveSettledInstances(correlationId);
|
|
101
|
-
|
|
102
|
-
for (const instanceDoc of instances) {
|
|
103
|
-
const tracker = instanceDoc.commandTrackers.find((t) => t.commandType === sourceCommandType);
|
|
104
|
-
if (tracker && !tracker.hasCompleted) {
|
|
105
|
-
await this.emitEvent({
|
|
106
|
-
type: 'SettledEventReceived',
|
|
107
|
-
data: {
|
|
108
|
-
templateId: instanceDoc.templateId,
|
|
109
|
-
correlationId,
|
|
110
|
-
commandType: sourceCommandType,
|
|
111
|
-
event,
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const updatedInstance = await this.readModel.getSettledInstance(instanceDoc.templateId, correlationId);
|
|
116
|
-
if (updatedInstance) {
|
|
117
|
-
await this.checkAndFireHandler(updatedInstance);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
private isValidId(id: string | undefined): id is string {
|
|
124
|
-
return id !== undefined && id !== null && id !== '';
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
private generateTemplateId(registration: SettledHandlerRegistration): string {
|
|
128
|
-
return `template-${registration.commandTypes.join(',')}`;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
private async ensureInstanceExists(template: HandlerTemplate, correlationId: string): Promise<boolean> {
|
|
132
|
-
const existing = await this.readModel.getSettledInstance(template.id, correlationId);
|
|
133
|
-
const isActiveInstance = existing !== null && existing.status === 'active';
|
|
134
|
-
|
|
135
|
-
if (isActiveInstance) {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
await this.emitEvent({
|
|
140
|
-
type: 'SettledInstanceCreated',
|
|
141
|
-
data: {
|
|
142
|
-
templateId: template.id,
|
|
143
|
-
correlationId,
|
|
144
|
-
commandTypes: template.registration.commandTypes,
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
private async markCommandStarted(templateId: string, correlationId: string, commandType: string): Promise<void> {
|
|
152
|
-
await this.emitEvent({
|
|
153
|
-
type: 'SettledCommandStarted',
|
|
154
|
-
data: {
|
|
155
|
-
templateId,
|
|
156
|
-
correlationId,
|
|
157
|
-
commandType,
|
|
158
|
-
},
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
private async emitEvent(event: SettledEvent): Promise<void> {
|
|
163
|
-
await this.onEventEmit?.(event);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
private async checkAndFireHandler(instanceDoc: SettledInstanceDocument): Promise<void> {
|
|
167
|
-
const allComplete = instanceDoc.commandTrackers.every((tracker) => tracker.hasStarted && tracker.hasCompleted);
|
|
168
|
-
|
|
169
|
-
if (!allComplete) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const template = this.handlerTemplates.get(instanceDoc.templateId)!;
|
|
174
|
-
const eventsByCommandType = this.collectEventsFromDoc(instanceDoc);
|
|
175
|
-
|
|
176
|
-
try {
|
|
177
|
-
const send: SendFunction = (commandType, data) => {
|
|
178
|
-
if (this.onDispatch) {
|
|
179
|
-
this.onDispatch(commandType, data, instanceDoc.correlationId);
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
const result = template.registration.handler(eventsByCommandType, send);
|
|
184
|
-
const persist = this.shouldPersist(result);
|
|
185
|
-
|
|
186
|
-
await this.emitEvent({
|
|
187
|
-
type: 'SettledHandlerFired',
|
|
188
|
-
data: {
|
|
189
|
-
templateId: instanceDoc.templateId,
|
|
190
|
-
correlationId: instanceDoc.correlationId,
|
|
191
|
-
persist,
|
|
192
|
-
},
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
await this.emitEvent({
|
|
196
|
-
type: 'SettledInstanceReset',
|
|
197
|
-
data: {
|
|
198
|
-
templateId: instanceDoc.templateId,
|
|
199
|
-
correlationId: instanceDoc.correlationId,
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
} catch (error) {
|
|
203
|
-
const commandTypes = instanceDoc.commandTrackers.map((t) => t.commandType);
|
|
204
|
-
this.onError?.(error, {
|
|
205
|
-
commandTypes,
|
|
206
|
-
correlationId: instanceDoc.correlationId,
|
|
207
|
-
});
|
|
208
|
-
await this.emitEvent({
|
|
209
|
-
type: 'SettledInstanceCleaned',
|
|
210
|
-
data: {
|
|
211
|
-
templateId: instanceDoc.templateId,
|
|
212
|
-
correlationId: instanceDoc.correlationId,
|
|
213
|
-
},
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
private collectEventsFromDoc(instanceDoc: SettledInstanceDocument): Record<string, Event[]> {
|
|
219
|
-
const events: Record<string, Event[]> = {};
|
|
220
|
-
for (const tracker of instanceDoc.commandTrackers) {
|
|
221
|
-
events[tracker.commandType] = [...tracker.events];
|
|
222
|
-
}
|
|
223
|
-
return events;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
private shouldPersist(result: undefined | { persist: boolean }): boolean {
|
|
227
|
-
return (
|
|
228
|
-
result !== null &&
|
|
229
|
-
result !== undefined &&
|
|
230
|
-
typeof result === 'object' &&
|
|
231
|
-
'persist' in result &&
|
|
232
|
-
result.persist === true
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
}
|