@auto-engineer/pipeline 0.14.0 → 0.16.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 +5 -6
- package/CHANGELOG.md +24 -0
- package/README.md +279 -0
- package/dist/src/builder/define.d.ts +6 -2
- package/dist/src/builder/define.d.ts.map +1 -1
- package/dist/src/builder/define.js +17 -7
- package/dist/src/builder/define.js.map +1 -1
- package/dist/src/core/descriptors.d.ts +6 -2
- package/dist/src/core/descriptors.d.ts.map +1 -1
- package/dist/src/graph/filter-graph.d.ts +3 -0
- package/dist/src/graph/filter-graph.d.ts.map +1 -0
- package/dist/src/graph/filter-graph.js +80 -0
- package/dist/src/graph/filter-graph.js.map +1 -0
- package/dist/src/graph/types.d.ts +8 -0
- package/dist/src/graph/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/projections/await-tracker-projection.d.ts +31 -0
- package/dist/src/projections/await-tracker-projection.d.ts.map +1 -0
- package/dist/src/projections/await-tracker-projection.js +35 -0
- package/dist/src/projections/await-tracker-projection.js.map +1 -0
- package/dist/src/projections/index.d.ts +4 -0
- package/dist/src/projections/index.d.ts.map +1 -0
- package/dist/src/projections/index.js +4 -0
- package/dist/src/projections/index.js.map +1 -0
- package/dist/src/projections/item-status-projection.d.ts +22 -0
- package/dist/src/projections/item-status-projection.d.ts.map +1 -0
- package/dist/src/projections/item-status-projection.js +11 -0
- package/dist/src/projections/item-status-projection.js.map +1 -0
- package/dist/src/projections/latest-run-projection.d.ts +15 -0
- package/dist/src/projections/latest-run-projection.d.ts.map +1 -0
- package/dist/src/projections/latest-run-projection.js +7 -0
- package/dist/src/projections/latest-run-projection.js.map +1 -0
- package/dist/src/projections/message-log-projection.d.ts +51 -0
- package/dist/src/projections/message-log-projection.d.ts.map +1 -0
- package/dist/src/projections/message-log-projection.js +51 -0
- package/dist/src/projections/message-log-projection.js.map +1 -0
- package/dist/src/projections/node-status-projection.d.ts +23 -0
- package/dist/src/projections/node-status-projection.d.ts.map +1 -0
- package/dist/src/projections/node-status-projection.js +10 -0
- package/dist/src/projections/node-status-projection.js.map +1 -0
- package/dist/src/projections/phased-execution-projection.d.ts +77 -0
- package/dist/src/projections/phased-execution-projection.d.ts.map +1 -0
- package/dist/src/projections/phased-execution-projection.js +54 -0
- package/dist/src/projections/phased-execution-projection.js.map +1 -0
- package/dist/src/projections/settled-instance-projection.d.ts +67 -0
- package/dist/src/projections/settled-instance-projection.d.ts.map +1 -0
- package/dist/src/projections/settled-instance-projection.js +66 -0
- package/dist/src/projections/settled-instance-projection.js.map +1 -0
- package/dist/src/projections/stats-projection.d.ts +9 -0
- package/dist/src/projections/stats-projection.d.ts.map +1 -0
- package/dist/src/projections/stats-projection.js +16 -0
- package/dist/src/projections/stats-projection.js.map +1 -0
- package/dist/src/runtime/await-tracker.d.ts +17 -7
- package/dist/src/runtime/await-tracker.d.ts.map +1 -1
- package/dist/src/runtime/await-tracker.js +32 -29
- package/dist/src/runtime/await-tracker.js.map +1 -1
- package/dist/src/runtime/context.d.ts +1 -1
- package/dist/src/runtime/context.d.ts.map +1 -1
- package/dist/src/runtime/event-command-map.d.ts +3 -3
- package/dist/src/runtime/event-command-map.d.ts.map +1 -1
- package/dist/src/runtime/event-command-map.js +6 -2
- package/dist/src/runtime/event-command-map.js.map +1 -1
- package/dist/src/runtime/phased-executor.d.ts +14 -9
- package/dist/src/runtime/phased-executor.d.ts.map +1 -1
- package/dist/src/runtime/phased-executor.js +113 -105
- package/dist/src/runtime/phased-executor.js.map +1 -1
- package/dist/src/runtime/pipeline-runtime.d.ts.map +1 -1
- package/dist/src/runtime/pipeline-runtime.js +2 -2
- package/dist/src/runtime/pipeline-runtime.js.map +1 -1
- package/dist/src/runtime/settled-tracker.d.ts +12 -10
- package/dist/src/runtime/settled-tracker.d.ts.map +1 -1
- package/dist/src/runtime/settled-tracker.js +89 -80
- package/dist/src/runtime/settled-tracker.js.map +1 -1
- package/dist/src/server/pipeline-server.d.ts +31 -9
- package/dist/src/server/pipeline-server.d.ts.map +1 -1
- package/dist/src/server/pipeline-server.js +424 -123
- package/dist/src/server/pipeline-server.js.map +1 -1
- package/dist/src/server/sse-manager.d.ts +0 -1
- package/dist/src/server/sse-manager.d.ts.map +1 -1
- package/dist/src/server/sse-manager.js +0 -3
- package/dist/src/server/sse-manager.js.map +1 -1
- package/dist/src/store/index.d.ts +3 -0
- package/dist/src/store/index.d.ts.map +1 -0
- package/dist/src/store/index.js +3 -0
- package/dist/src/store/index.js.map +1 -0
- package/dist/src/store/pipeline-event-store.d.ts +10 -0
- package/dist/src/store/pipeline-event-store.d.ts.map +1 -0
- package/dist/src/store/pipeline-event-store.js +112 -0
- package/dist/src/store/pipeline-event-store.js.map +1 -0
- package/dist/src/store/pipeline-read-model.d.ts +49 -0
- package/dist/src/store/pipeline-read-model.d.ts.map +1 -0
- package/dist/src/store/pipeline-read-model.js +156 -0
- package/dist/src/store/pipeline-read-model.js.map +1 -0
- package/dist/src/store/sqlite-pipeline-event-store.d.ts +14 -0
- package/dist/src/store/sqlite-pipeline-event-store.d.ts.map +1 -0
- package/dist/src/store/sqlite-pipeline-event-store.js +20 -0
- package/dist/src/store/sqlite-pipeline-event-store.js.map +1 -0
- package/dist/src/testing/fixtures/kanban-full.pipeline.js +2 -2
- package/dist/src/testing/fixtures/kanban-full.pipeline.js.map +1 -1
- package/dist/src/testing/fixtures/kanban.pipeline.js +2 -2
- package/dist/src/testing/fixtures/kanban.pipeline.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/ketchup-plan.md +1216 -0
- package/package.json +6 -4
- package/src/builder/define.specs.ts +5 -4
- package/src/builder/define.ts +24 -11
- package/src/config/pipeline-config.specs.ts +32 -0
- package/src/core/descriptors.ts +7 -2
- package/src/graph/filter-graph.specs.ts +267 -0
- package/src/graph/filter-graph.ts +111 -0
- package/src/graph/types.specs.ts +0 -14
- package/src/graph/types.ts +10 -0
- package/src/index.ts +1 -0
- package/src/projections/await-tracker-projection.specs.ts +24 -0
- package/src/projections/await-tracker-projection.ts +68 -0
- package/src/projections/index.ts +11 -0
- package/src/projections/item-status-projection.specs.ts +130 -0
- package/src/projections/item-status-projection.ts +32 -0
- package/src/projections/latest-run-projection.ts +20 -0
- package/src/projections/message-log-projection.ts +113 -0
- package/src/projections/node-status-projection.ts +33 -0
- package/src/projections/phased-execution-projection.specs.ts +202 -0
- package/src/projections/phased-execution-projection.ts +146 -0
- package/src/projections/settled-instance-projection.specs.ts +296 -0
- package/src/projections/settled-instance-projection.ts +160 -0
- package/src/projections/stats-projection.ts +26 -0
- package/src/runtime/await-tracker.specs.ts +57 -34
- package/src/runtime/await-tracker.ts +43 -31
- package/src/runtime/context.ts +1 -1
- package/src/runtime/event-command-map.ts +11 -4
- package/src/runtime/phased-executor.specs.ts +357 -81
- package/src/runtime/phased-executor.ts +134 -128
- package/src/runtime/pipeline-runtime.specs.ts +65 -0
- package/src/runtime/pipeline-runtime.ts +6 -4
- package/src/runtime/settled-tracker.specs.ts +716 -120
- package/src/runtime/settled-tracker.ts +100 -102
- package/src/server/pipeline-server.e2e.specs.ts +10 -16
- package/src/server/pipeline-server.specs.ts +1441 -211
- package/src/server/pipeline-server.ts +535 -144
- package/src/server/sse-manager.specs.ts +67 -36
- package/src/server/sse-manager.ts +0 -4
- package/src/store/index.ts +2 -0
- package/src/store/pipeline-event-store.specs.ts +357 -0
- package/src/store/pipeline-event-store.ts +156 -0
- package/src/store/pipeline-read-model.specs.ts +1170 -0
- package/src/store/pipeline-read-model.ts +223 -0
- package/src/store/sqlite-pipeline-event-store.specs.ts +13 -0
- package/src/store/sqlite-pipeline-event-store.ts +36 -0
- package/src/testing/fixtures/kanban-full.pipeline.ts +2 -2
- package/src/testing/fixtures/kanban.pipeline.ts +2 -2
- package/tsconfig.json +1 -1
- package/vitest.config.ts +1 -8
- package/claude.md +0 -160
- package/dist/src/__tests__/e2e/helpers.d.ts +0 -48
- package/dist/src/__tests__/e2e/helpers.d.ts.map +0 -1
- package/dist/src/__tests__/e2e/helpers.js +0 -253
- package/dist/src/__tests__/e2e/helpers.js.map +0 -1
- package/dist/src/__tests__/e2e/kanban-migration.e2e.specs.d.ts +0 -2
- package/dist/src/__tests__/e2e/kanban-migration.e2e.specs.d.ts.map +0 -1
- package/dist/src/__tests__/e2e/kanban-migration.e2e.specs.js +0 -195
- package/dist/src/__tests__/e2e/kanban-migration.e2e.specs.js.map +0 -1
- package/dist/src/__tests__/e2e/types.d.ts +0 -107
- package/dist/src/__tests__/e2e/types.d.ts.map +0 -1
- package/dist/src/__tests__/e2e/types.js +0 -2
- package/dist/src/__tests__/e2e/types.js.map +0 -1
- package/dist/src/builder/define.specs.d.ts +0 -2
- package/dist/src/builder/define.specs.d.ts.map +0 -1
- package/dist/src/builder/define.specs.js +0 -435
- package/dist/src/builder/define.specs.js.map +0 -1
- package/dist/src/core/descriptors.specs.d.ts +0 -2
- package/dist/src/core/descriptors.specs.d.ts.map +0 -1
- package/dist/src/core/descriptors.specs.js +0 -24
- package/dist/src/core/descriptors.specs.js.map +0 -1
- package/dist/src/core/types.specs.d.ts +0 -2
- package/dist/src/core/types.specs.d.ts.map +0 -1
- package/dist/src/core/types.specs.js +0 -40
- package/dist/src/core/types.specs.js.map +0 -1
- package/dist/src/file-syncer/crypto/jwe-encryptor.d.ts +0 -15
- package/dist/src/file-syncer/crypto/jwe-encryptor.d.ts.map +0 -1
- package/dist/src/file-syncer/crypto/jwe-encryptor.js +0 -64
- package/dist/src/file-syncer/crypto/jwe-encryptor.js.map +0 -1
- package/dist/src/file-syncer/crypto/provider-resolver.d.ts +0 -24
- package/dist/src/file-syncer/crypto/provider-resolver.d.ts.map +0 -1
- package/dist/src/file-syncer/crypto/provider-resolver.js +0 -71
- package/dist/src/file-syncer/crypto/provider-resolver.js.map +0 -1
- package/dist/src/file-syncer/discovery/bareImports.d.ts +0 -3
- package/dist/src/file-syncer/discovery/bareImports.d.ts.map +0 -1
- package/dist/src/file-syncer/discovery/bareImports.js +0 -36
- package/dist/src/file-syncer/discovery/bareImports.js.map +0 -1
- package/dist/src/file-syncer/discovery/dts.d.ts +0 -8
- package/dist/src/file-syncer/discovery/dts.d.ts.map +0 -1
- package/dist/src/file-syncer/discovery/dts.js +0 -99
- package/dist/src/file-syncer/discovery/dts.js.map +0 -1
- package/dist/src/file-syncer/index.d.ts +0 -46
- package/dist/src/file-syncer/index.d.ts.map +0 -1
- package/dist/src/file-syncer/index.js +0 -392
- package/dist/src/file-syncer/index.js.map +0 -1
- package/dist/src/file-syncer/sync/resolveSyncFileSet.d.ts +0 -7
- package/dist/src/file-syncer/sync/resolveSyncFileSet.d.ts.map +0 -1
- package/dist/src/file-syncer/sync/resolveSyncFileSet.js +0 -86
- package/dist/src/file-syncer/sync/resolveSyncFileSet.js.map +0 -1
- package/dist/src/file-syncer/types/wire.d.ts +0 -14
- package/dist/src/file-syncer/types/wire.d.ts.map +0 -1
- package/dist/src/file-syncer/types/wire.js +0 -2
- package/dist/src/file-syncer/types/wire.js.map +0 -1
- package/dist/src/file-syncer/utils/hash.d.ts +0 -5
- package/dist/src/file-syncer/utils/hash.d.ts.map +0 -1
- package/dist/src/file-syncer/utils/hash.js +0 -19
- package/dist/src/file-syncer/utils/hash.js.map +0 -1
- package/dist/src/file-syncer/utils/path.d.ts +0 -13
- package/dist/src/file-syncer/utils/path.d.ts.map +0 -1
- package/dist/src/file-syncer/utils/path.js +0 -74
- package/dist/src/file-syncer/utils/path.js.map +0 -1
- package/dist/src/graph/types.specs.d.ts +0 -2
- package/dist/src/graph/types.specs.d.ts.map +0 -1
- package/dist/src/graph/types.specs.js +0 -148
- package/dist/src/graph/types.specs.js.map +0 -1
- package/dist/src/logging/event-logger.specs.d.ts +0 -2
- package/dist/src/logging/event-logger.specs.d.ts.map +0 -1
- package/dist/src/logging/event-logger.specs.js +0 -81
- package/dist/src/logging/event-logger.specs.js.map +0 -1
- package/dist/src/plugins/handler-adapter.specs.d.ts +0 -2
- package/dist/src/plugins/handler-adapter.specs.d.ts.map +0 -1
- package/dist/src/plugins/handler-adapter.specs.js +0 -129
- package/dist/src/plugins/handler-adapter.specs.js.map +0 -1
- package/dist/src/plugins/plugin-loader.specs.d.ts +0 -2
- package/dist/src/plugins/plugin-loader.specs.d.ts.map +0 -1
- package/dist/src/plugins/plugin-loader.specs.js +0 -246
- package/dist/src/plugins/plugin-loader.specs.js.map +0 -1
- package/dist/src/runtime/await-tracker.specs.d.ts +0 -2
- package/dist/src/runtime/await-tracker.specs.d.ts.map +0 -1
- package/dist/src/runtime/await-tracker.specs.js +0 -46
- package/dist/src/runtime/await-tracker.specs.js.map +0 -1
- package/dist/src/runtime/context.specs.d.ts +0 -2
- package/dist/src/runtime/context.specs.d.ts.map +0 -1
- package/dist/src/runtime/context.specs.js +0 -26
- package/dist/src/runtime/context.specs.js.map +0 -1
- package/dist/src/runtime/event-command-map.specs.d.ts +0 -2
- package/dist/src/runtime/event-command-map.specs.d.ts.map +0 -1
- package/dist/src/runtime/event-command-map.specs.js +0 -108
- package/dist/src/runtime/event-command-map.specs.js.map +0 -1
- package/dist/src/runtime/phased-executor.specs.d.ts +0 -2
- package/dist/src/runtime/phased-executor.specs.d.ts.map +0 -1
- package/dist/src/runtime/phased-executor.specs.js +0 -256
- package/dist/src/runtime/phased-executor.specs.js.map +0 -1
- package/dist/src/runtime/pipeline-runtime.specs.d.ts +0 -2
- package/dist/src/runtime/pipeline-runtime.specs.d.ts.map +0 -1
- package/dist/src/runtime/pipeline-runtime.specs.js +0 -192
- package/dist/src/runtime/pipeline-runtime.specs.js.map +0 -1
- package/dist/src/runtime/settled-tracker.specs.d.ts +0 -2
- package/dist/src/runtime/settled-tracker.specs.d.ts.map +0 -1
- package/dist/src/runtime/settled-tracker.specs.js +0 -361
- package/dist/src/runtime/settled-tracker.specs.js.map +0 -1
- package/dist/src/server/full-orchestration.e2e.specs.d.ts +0 -2
- package/dist/src/server/full-orchestration.e2e.specs.d.ts.map +0 -1
- package/dist/src/server/full-orchestration.e2e.specs.js +0 -561
- package/dist/src/server/full-orchestration.e2e.specs.js.map +0 -1
- package/dist/src/server/pipeline-server.e2e.specs.d.ts +0 -2
- package/dist/src/server/pipeline-server.e2e.specs.d.ts.map +0 -1
- package/dist/src/server/pipeline-server.e2e.specs.js +0 -381
- package/dist/src/server/pipeline-server.e2e.specs.js.map +0 -1
- package/dist/src/server/pipeline-server.specs.d.ts +0 -2
- package/dist/src/server/pipeline-server.specs.d.ts.map +0 -1
- package/dist/src/server/pipeline-server.specs.js +0 -662
- package/dist/src/server/pipeline-server.specs.js.map +0 -1
- package/dist/src/server/sse-manager.specs.d.ts +0 -2
- package/dist/src/server/sse-manager.specs.d.ts.map +0 -1
- package/dist/src/server/sse-manager.specs.js +0 -158
- package/dist/src/server/sse-manager.specs.js.map +0 -1
- package/dist/src/testing/event-capture.specs.d.ts +0 -2
- package/dist/src/testing/event-capture.specs.d.ts.map +0 -1
- package/dist/src/testing/event-capture.specs.js +0 -114
- package/dist/src/testing/event-capture.specs.js.map +0 -1
- package/dist/src/testing/fixtures/kanban-full.pipeline.specs.d.ts +0 -2
- package/dist/src/testing/fixtures/kanban-full.pipeline.specs.d.ts.map +0 -1
- package/dist/src/testing/fixtures/kanban-full.pipeline.specs.js +0 -263
- package/dist/src/testing/fixtures/kanban-full.pipeline.specs.js.map +0 -1
- package/dist/src/testing/fixtures/kanban.pipeline.specs.d.ts +0 -2
- package/dist/src/testing/fixtures/kanban.pipeline.specs.d.ts.map +0 -1
- package/dist/src/testing/fixtures/kanban.pipeline.specs.js +0 -29
- package/dist/src/testing/fixtures/kanban.pipeline.specs.js.map +0 -1
- package/dist/src/testing/kanban-todo.e2e.specs.d.ts +0 -2
- package/dist/src/testing/kanban-todo.e2e.specs.d.ts.map +0 -1
- package/dist/src/testing/kanban-todo.e2e.specs.js +0 -160
- package/dist/src/testing/kanban-todo.e2e.specs.js.map +0 -1
- package/dist/src/testing/mock-handlers.specs.d.ts +0 -2
- package/dist/src/testing/mock-handlers.specs.d.ts.map +0 -1
- package/dist/src/testing/mock-handlers.specs.js +0 -193
- package/dist/src/testing/mock-handlers.specs.js.map +0 -1
- package/dist/src/testing/real-execution.e2e.specs.d.ts +0 -2
- package/dist/src/testing/real-execution.e2e.specs.d.ts.map +0 -1
- package/dist/src/testing/real-execution.e2e.specs.js +0 -140
- package/dist/src/testing/real-execution.e2e.specs.js.map +0 -1
- package/dist/src/testing/real-plugin.e2e.specs.d.ts +0 -2
- package/dist/src/testing/real-plugin.e2e.specs.d.ts.map +0 -1
- package/dist/src/testing/real-plugin.e2e.specs.js +0 -65
- package/dist/src/testing/real-plugin.e2e.specs.js.map +0 -1
- package/dist/src/testing/server-startup.e2e.specs.d.ts +0 -2
- package/dist/src/testing/server-startup.e2e.specs.d.ts.map +0 -1
- package/dist/src/testing/server-startup.e2e.specs.js +0 -104
- package/dist/src/testing/server-startup.e2e.specs.js.map +0 -1
- package/dist/src/testing/snapshot-compare.specs.d.ts +0 -2
- package/dist/src/testing/snapshot-compare.specs.d.ts.map +0 -1
- package/dist/src/testing/snapshot-compare.specs.js +0 -112
- package/dist/src/testing/snapshot-compare.specs.js.map +0 -1
- package/dist/src/testing/snapshot-sanitize.specs.d.ts +0 -2
- package/dist/src/testing/snapshot-sanitize.specs.d.ts.map +0 -1
- package/dist/src/testing/snapshot-sanitize.specs.js +0 -104
- package/dist/src/testing/snapshot-sanitize.specs.js.map +0 -1
- package/docs/testing-analysis.md +0 -395
- package/pomodoro-plan.md +0 -651
- package/src/core/descriptors.specs.ts +0 -28
- package/src/core/types.specs.ts +0 -44
- package/src/runtime/context.specs.ts +0 -28
|
@@ -1,119 +1,111 @@
|
|
|
1
1
|
import type { Event } from '@auto-engineer/message-bus';
|
|
2
2
|
import type { ForEachPhasedDescriptor } from '../core/descriptors';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
key: string;
|
|
6
|
-
phase: string;
|
|
7
|
-
dispatched: boolean;
|
|
8
|
-
completed: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface PhasedSession {
|
|
12
|
-
correlationId: string;
|
|
13
|
-
handler: ForEachPhasedDescriptor;
|
|
14
|
-
triggerEvent: Event;
|
|
15
|
-
items: Map<string, ItemTracker>;
|
|
16
|
-
phases: readonly string[];
|
|
17
|
-
currentPhaseIndex: number;
|
|
18
|
-
pendingInPhase: Set<string>;
|
|
19
|
-
failedItems: Map<string, unknown>;
|
|
20
|
-
}
|
|
3
|
+
import type { PhasedExecutionDocument, PhasedExecutionEvent } from '../projections/phased-execution-projection';
|
|
4
|
+
import type { PipelineReadModel } from '../store/pipeline-read-model';
|
|
21
5
|
|
|
22
6
|
interface PhasedExecutorOptions {
|
|
7
|
+
readModel: PipelineReadModel;
|
|
23
8
|
onDispatch: (commandType: string, data: unknown, correlationId: string) => void;
|
|
24
9
|
onComplete: (event: Event, correlationId: string) => void;
|
|
10
|
+
onEventEmit?: (event: PhasedExecutionEvent) => void | Promise<void>;
|
|
25
11
|
}
|
|
26
12
|
|
|
27
13
|
export class PhasedExecutor {
|
|
28
|
-
private
|
|
29
|
-
private
|
|
14
|
+
private handlerRegistry = new Map<string, ForEachPhasedDescriptor>();
|
|
15
|
+
private readonly readModel: PipelineReadModel;
|
|
30
16
|
private readonly onDispatch: (commandType: string, data: unknown, correlationId: string) => void;
|
|
31
17
|
private readonly onComplete: (event: Event, correlationId: string) => void;
|
|
18
|
+
private readonly onEventEmit?: (event: PhasedExecutionEvent) => void | Promise<void>;
|
|
32
19
|
|
|
33
20
|
constructor(options: PhasedExecutorOptions) {
|
|
21
|
+
this.readModel = options.readModel;
|
|
34
22
|
this.onDispatch = options.onDispatch;
|
|
35
23
|
this.onComplete = options.onComplete;
|
|
24
|
+
this.onEventEmit = options.onEventEmit;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
registerHandler(handler: ForEachPhasedDescriptor): void {
|
|
28
|
+
const handlerId = this.generateHandlerId(handler);
|
|
29
|
+
this.handlerRegistry.set(handlerId, handler);
|
|
36
30
|
}
|
|
37
31
|
|
|
38
|
-
startPhased(handler: ForEachPhasedDescriptor, event: Event, correlationId: string): void {
|
|
32
|
+
async startPhased(handler: ForEachPhasedDescriptor, event: Event, correlationId: string): Promise<void> {
|
|
39
33
|
const items = handler.itemsSelector(event);
|
|
40
|
-
const
|
|
34
|
+
const itemData: Array<{ key: string; phase: string; dispatched: boolean; completed: boolean }> = [];
|
|
41
35
|
|
|
42
36
|
for (const item of items) {
|
|
43
37
|
const key = handler.completion.itemKey({ type: event.type, data: item as Record<string, unknown> });
|
|
44
38
|
const phase = handler.classifier(item);
|
|
45
|
-
|
|
46
|
-
key,
|
|
47
|
-
phase,
|
|
48
|
-
dispatched: false,
|
|
49
|
-
completed: false,
|
|
50
|
-
});
|
|
39
|
+
itemData.push({ key, phase, dispatched: false, completed: false });
|
|
51
40
|
}
|
|
52
41
|
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
for (const key of itemTrackers.keys()) {
|
|
68
|
-
this.keyToSession.set(this.keyWithCorrelation(key, correlationId), sessionId);
|
|
69
|
-
}
|
|
42
|
+
const executionId = this.generateSessionId(correlationId, handler);
|
|
43
|
+
const handlerId = this.generateHandlerId(handler);
|
|
44
|
+
|
|
45
|
+
await this.emitEvent({
|
|
46
|
+
type: 'PhasedExecutionStarted',
|
|
47
|
+
data: {
|
|
48
|
+
executionId,
|
|
49
|
+
correlationId,
|
|
50
|
+
handlerId,
|
|
51
|
+
triggerEvent: event,
|
|
52
|
+
items: itemData,
|
|
53
|
+
phases: handler.phases,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
70
56
|
|
|
71
|
-
this.dispatchCurrentPhase(
|
|
57
|
+
await this.dispatchCurrentPhase(executionId, handler);
|
|
72
58
|
}
|
|
73
59
|
|
|
74
|
-
onEventReceived(event: Event, itemKey: string): void {
|
|
60
|
+
async onEventReceived(event: Event, itemKey: string): Promise<void> {
|
|
75
61
|
const correlationId = event.correlationId;
|
|
76
62
|
if (correlationId === undefined || correlationId === '') return;
|
|
77
63
|
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
64
|
+
const executions = await this.readModel.getActivePhasedExecutions(correlationId);
|
|
65
|
+
const execution = executions.find((ex) => ex.items.some((item) => item.key === itemKey));
|
|
66
|
+
|
|
67
|
+
if (execution === undefined) return;
|
|
81
68
|
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
if (tracker === undefined || tracker.completed) return;
|
|
69
|
+
const itemDoc = execution.items.find((i) => i.key === itemKey);
|
|
70
|
+
if (itemDoc === undefined || itemDoc.completed) return;
|
|
85
71
|
|
|
86
|
-
|
|
87
|
-
session.pendingInPhase.delete(itemKey);
|
|
72
|
+
const handler = this.handlerRegistry.get(execution.handlerId)!;
|
|
88
73
|
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
74
|
+
if (handler.stopOnFailure && this.isFailureEvent(event, handler)) {
|
|
75
|
+
await this.emitEvent({
|
|
76
|
+
type: 'PhasedItemFailed',
|
|
77
|
+
data: { executionId: execution.executionId, itemKey, error: event },
|
|
78
|
+
});
|
|
79
|
+
await this.handleFailure(execution.executionId, handler);
|
|
92
80
|
return;
|
|
93
81
|
}
|
|
94
82
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
83
|
+
await this.emitEvent({
|
|
84
|
+
type: 'PhasedItemCompleted',
|
|
85
|
+
data: { executionId: execution.executionId, itemKey, resultEvent: event },
|
|
86
|
+
});
|
|
99
87
|
|
|
100
|
-
|
|
101
|
-
return this.sessions.size;
|
|
102
|
-
}
|
|
88
|
+
const updatedExecution = (await this.readModel.getPhasedExecution(execution.executionId))!;
|
|
103
89
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
90
|
+
const pendingCount = this.countPendingInPhase(updatedExecution);
|
|
91
|
+
if (pendingCount === 0) {
|
|
92
|
+
await this.advanceToNextPhase(execution.executionId, handler);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
107
95
|
|
|
108
|
-
|
|
96
|
+
async isPhaseComplete(correlationId: string, phase: string): Promise<boolean> {
|
|
97
|
+
const executions = await this.readModel.getActivePhasedExecutions(correlationId);
|
|
98
|
+
for (const execution of executions) {
|
|
99
|
+
const phaseIndex = execution.phases.indexOf(phase);
|
|
109
100
|
if (phaseIndex === -1) continue;
|
|
110
101
|
|
|
111
|
-
if (
|
|
102
|
+
if (execution.currentPhaseIndex > phaseIndex) {
|
|
112
103
|
return true;
|
|
113
104
|
}
|
|
114
105
|
|
|
115
|
-
if (
|
|
116
|
-
|
|
106
|
+
if (execution.currentPhaseIndex === phaseIndex) {
|
|
107
|
+
const pendingCount = this.countPendingInPhase(execution);
|
|
108
|
+
return pendingCount === 0;
|
|
117
109
|
}
|
|
118
110
|
|
|
119
111
|
return false;
|
|
@@ -121,89 +113,99 @@ export class PhasedExecutor {
|
|
|
121
113
|
return false;
|
|
122
114
|
}
|
|
123
115
|
|
|
124
|
-
private
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
116
|
+
private countPendingInPhase(execution: PhasedExecutionDocument): number {
|
|
117
|
+
let pending = 0;
|
|
118
|
+
const currentPhase = execution.phases[execution.currentPhaseIndex];
|
|
119
|
+
for (const item of execution.items) {
|
|
120
|
+
if (item.phase === currentPhase && item.dispatched && !item.completed) {
|
|
121
|
+
pending++;
|
|
122
|
+
}
|
|
130
123
|
}
|
|
124
|
+
return pending;
|
|
125
|
+
}
|
|
131
126
|
|
|
132
|
-
|
|
133
|
-
const
|
|
127
|
+
private async dispatchCurrentPhase(executionId: string, handler: ForEachPhasedDescriptor): Promise<void> {
|
|
128
|
+
const execution = (await this.readModel.getPhasedExecution(executionId))!;
|
|
134
129
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
130
|
+
if (execution.currentPhaseIndex >= execution.phases.length) {
|
|
131
|
+
await this.completeSession(executionId, handler, true);
|
|
132
|
+
return;
|
|
139
133
|
}
|
|
140
134
|
|
|
135
|
+
const currentPhase = execution.phases[execution.currentPhaseIndex];
|
|
136
|
+
const itemsToDispatch = execution.items.filter((i) => i.phase === currentPhase && !i.dispatched);
|
|
137
|
+
|
|
141
138
|
if (itemsToDispatch.length === 0) {
|
|
142
|
-
this.advanceToNextPhase(
|
|
139
|
+
await this.advanceToNextPhase(executionId, handler);
|
|
143
140
|
return;
|
|
144
141
|
}
|
|
145
142
|
|
|
146
|
-
for (const
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
for (const item of itemsToDispatch) {
|
|
144
|
+
await this.emitEvent({
|
|
145
|
+
type: 'PhasedItemDispatched',
|
|
146
|
+
data: { executionId, itemKey: item.key, phase: item.phase },
|
|
147
|
+
});
|
|
149
148
|
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
152
|
-
const command =
|
|
153
|
-
this.onDispatch(command.commandType, command.data,
|
|
149
|
+
const originalItem = this.findItemByKey(execution.triggerEvent, handler, item.key);
|
|
150
|
+
if (originalItem !== undefined) {
|
|
151
|
+
const command = handler.emitFactory(originalItem, item.phase, execution.triggerEvent);
|
|
152
|
+
this.onDispatch(command.commandType, command.data, execution.correlationId);
|
|
154
153
|
}
|
|
155
154
|
}
|
|
156
155
|
}
|
|
157
156
|
|
|
158
|
-
private advanceToNextPhase(
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
private async advanceToNextPhase(executionId: string, handler: ForEachPhasedDescriptor): Promise<void> {
|
|
158
|
+
const execution = (await this.readModel.getPhasedExecution(executionId))!;
|
|
159
|
+
|
|
160
|
+
const fromPhase = execution.currentPhaseIndex;
|
|
161
|
+
const toPhase = fromPhase + 1;
|
|
162
|
+
|
|
163
|
+
await this.emitEvent({
|
|
164
|
+
type: 'PhasedPhaseAdvanced',
|
|
165
|
+
data: { executionId, fromPhase, toPhase },
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
await this.dispatchCurrentPhase(executionId, handler);
|
|
161
169
|
}
|
|
162
170
|
|
|
163
|
-
private handleFailure(
|
|
164
|
-
this.completeSession(
|
|
171
|
+
private async handleFailure(executionId: string, handler: ForEachPhasedDescriptor): Promise<void> {
|
|
172
|
+
await this.completeSession(executionId, handler, false);
|
|
165
173
|
}
|
|
166
174
|
|
|
167
|
-
private completeSession(
|
|
168
|
-
|
|
175
|
+
private async completeSession(
|
|
176
|
+
executionId: string,
|
|
177
|
+
handler: ForEachPhasedDescriptor,
|
|
178
|
+
success: boolean,
|
|
179
|
+
): Promise<void> {
|
|
180
|
+
const execution = (await this.readModel.getPhasedExecution(executionId))!;
|
|
169
181
|
|
|
170
|
-
const
|
|
182
|
+
const eventDescriptor = success ? handler.completion.successEvent : handler.completion.failureEvent;
|
|
183
|
+
const eventType = eventDescriptor.name;
|
|
184
|
+
|
|
185
|
+
const results = execution.items.filter((i) => i.completed).map((i) => i.key);
|
|
171
186
|
const eventData = success
|
|
172
|
-
? { results, itemCount:
|
|
173
|
-
: { failures:
|
|
187
|
+
? { results, itemCount: execution.items.length }
|
|
188
|
+
: { failures: execution.failedItems.map((f) => ({ key: f.key, error: f.error })) };
|
|
174
189
|
|
|
175
190
|
const completionEvent: Event = {
|
|
176
191
|
type: eventType,
|
|
177
|
-
correlationId:
|
|
192
|
+
correlationId: execution.correlationId,
|
|
178
193
|
data: eventData,
|
|
179
194
|
};
|
|
180
195
|
|
|
181
|
-
this.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
private collectResults(session: PhasedSession): string[] {
|
|
186
|
-
const completed: string[] = [];
|
|
187
|
-
for (const tracker of session.items.values()) {
|
|
188
|
-
if (tracker.completed) {
|
|
189
|
-
completed.push(tracker.key);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return completed;
|
|
193
|
-
}
|
|
196
|
+
await this.emitEvent({
|
|
197
|
+
type: 'PhasedExecutionCompleted',
|
|
198
|
+
data: { executionId, success, results },
|
|
199
|
+
});
|
|
194
200
|
|
|
195
|
-
|
|
196
|
-
for (const key of session.items.keys()) {
|
|
197
|
-
this.keyToSession.delete(this.keyWithCorrelation(key, session.correlationId));
|
|
198
|
-
}
|
|
199
|
-
this.sessions.delete(sessionId);
|
|
201
|
+
this.onComplete(completionEvent, execution.correlationId);
|
|
200
202
|
}
|
|
201
203
|
|
|
202
|
-
private findItemByKey(
|
|
203
|
-
const items =
|
|
204
|
+
private findItemByKey(triggerEvent: Event, handler: ForEachPhasedDescriptor, key: string): unknown {
|
|
205
|
+
const items = handler.itemsSelector(triggerEvent);
|
|
204
206
|
return items.find((item) => {
|
|
205
|
-
const itemKey =
|
|
206
|
-
type:
|
|
207
|
+
const itemKey = handler.completion.itemKey({
|
|
208
|
+
type: triggerEvent.type,
|
|
207
209
|
data: item as Record<string, unknown>,
|
|
208
210
|
});
|
|
209
211
|
return itemKey === key;
|
|
@@ -211,14 +213,18 @@ export class PhasedExecutor {
|
|
|
211
213
|
}
|
|
212
214
|
|
|
213
215
|
private isFailureEvent(event: Event, handler: ForEachPhasedDescriptor): boolean {
|
|
214
|
-
return event.type === handler.completion.failureEvent;
|
|
216
|
+
return event.type === handler.completion.failureEvent.name;
|
|
215
217
|
}
|
|
216
218
|
|
|
217
219
|
private generateSessionId(correlationId: string, handler: ForEachPhasedDescriptor): string {
|
|
218
220
|
return `phased-${correlationId}-${handler.eventType}`;
|
|
219
221
|
}
|
|
220
222
|
|
|
221
|
-
private
|
|
222
|
-
return
|
|
223
|
+
private generateHandlerId(handler: ForEachPhasedDescriptor): string {
|
|
224
|
+
return `phased-handler-${handler.eventType}`;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private async emitEvent(event: PhasedExecutionEvent): Promise<void> {
|
|
228
|
+
await this.onEventEmit?.(event);
|
|
223
229
|
}
|
|
224
230
|
}
|
|
@@ -211,4 +211,69 @@ describe('PipelineRuntime', () => {
|
|
|
211
211
|
);
|
|
212
212
|
expect(sent).toEqual(['2', '3', '1']);
|
|
213
213
|
});
|
|
214
|
+
|
|
215
|
+
it('should use startPhased when provided for foreach-phased', async () => {
|
|
216
|
+
let phasedCalled = false;
|
|
217
|
+
const ctx = {
|
|
218
|
+
sendCommand: async () => {},
|
|
219
|
+
emit: async () => {},
|
|
220
|
+
correlationId: 'test',
|
|
221
|
+
startPhased: () => {
|
|
222
|
+
phasedCalled = true;
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
type Item = { id: string; p: 'high' | 'low' };
|
|
226
|
+
const pipeline = define('test')
|
|
227
|
+
.on('Items')
|
|
228
|
+
.forEach((e: { data: { items: Item[] } }) => e.data.items)
|
|
229
|
+
.groupInto(['high', 'low'], (i: Item) => i.p)
|
|
230
|
+
.process('Cmd', (i: Item) => ({ id: i.id }))
|
|
231
|
+
.onComplete({ success: 'Done', failure: 'Fail', itemKey: () => '' })
|
|
232
|
+
.build();
|
|
233
|
+
const runtime = new PipelineRuntime(pipeline.descriptor);
|
|
234
|
+
await runtime.handleEvent({ type: 'Items', data: { items: [{ id: '1', p: 'low' }] } }, ctx);
|
|
235
|
+
expect(phasedCalled).toBe(true);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('should dispatch multiple emit commands in parallel, not sequentially', async () => {
|
|
239
|
+
const callOrder: string[] = [];
|
|
240
|
+
let resolveA: () => void;
|
|
241
|
+
let resolveB: () => void;
|
|
242
|
+
const promiseA = new Promise<void>((r) => {
|
|
243
|
+
resolveA = r;
|
|
244
|
+
});
|
|
245
|
+
const promiseB = new Promise<void>((r) => {
|
|
246
|
+
resolveB = r;
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
const ctx = {
|
|
250
|
+
sendCommand: async (type: string) => {
|
|
251
|
+
callOrder.push(`${type}:start`);
|
|
252
|
+
if (type === 'CmdA') {
|
|
253
|
+
await promiseA;
|
|
254
|
+
} else if (type === 'CmdB') {
|
|
255
|
+
await promiseB;
|
|
256
|
+
}
|
|
257
|
+
callOrder.push(`${type}:end`);
|
|
258
|
+
},
|
|
259
|
+
emit: async () => {},
|
|
260
|
+
correlationId: 'test',
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const pipeline = define('test').on('Start').emit('CmdA', {}).emit('CmdB', {}).build();
|
|
264
|
+
const runtime = new PipelineRuntime(pipeline.descriptor);
|
|
265
|
+
|
|
266
|
+
const handlePromise = runtime.handleEvent({ type: 'Start', data: {} }, ctx);
|
|
267
|
+
|
|
268
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
269
|
+
|
|
270
|
+
expect(callOrder).toContain('CmdA:start');
|
|
271
|
+
expect(callOrder).toContain('CmdB:start');
|
|
272
|
+
|
|
273
|
+
resolveB!();
|
|
274
|
+
resolveA!();
|
|
275
|
+
await handlePromise;
|
|
276
|
+
|
|
277
|
+
expect(callOrder).toEqual(['CmdA:start', 'CmdB:start', 'CmdB:end', 'CmdA:end']);
|
|
278
|
+
});
|
|
214
279
|
});
|
|
@@ -53,10 +53,12 @@ export class PipelineRuntime {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
private async executeEmitHandler(handler: EmitHandlerDescriptor, event: Event, ctx: PipelineContext): Promise<void> {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
await Promise.all(
|
|
57
|
+
handler.commands.map(async (command) => {
|
|
58
|
+
const data = typeof command.data === 'function' ? command.data(event) : command.data;
|
|
59
|
+
await ctx.sendCommand(command.commandType, data);
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
private async executeCustomHandler(
|