Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ProjectionPipeline.ts

51 lines1.7 KB

1/**
2 * OrchestrationProjectionPipeline - Event projection pipeline service interface.
3 *
4 * Coordinates projection bootstrap/replay and per-event projection updates for
5 * orchestration read models.
6 *
7 * @module OrchestrationProjectionPipeline
8 */
9import type { OrchestrationEvent } from "@t3tools/contracts";
10import * as Context from "effect/Context";
11import type * as Effect from "effect/Effect";
12​
13import type { ProjectionRepositoryError } from "../../persistence/Errors.ts";
14​
15/**
16 * OrchestrationProjectionPipelineShape - Service API for projection execution.
17 */
18export interface OrchestrationProjectionPipelineShape {
19 /**
20 * Bootstrap projections by replaying persisted events.
21 *
22 * Resumes each projector from its stored projection-state cursor.
23 */
24 readonly bootstrap: Effect.Effect<void, ProjectionRepositoryError>;
25​
26 /**
27 * Project a single orchestration event into projection repositories.
28 *
29 * Projectors run sequentially in one transaction. Attachment cleanup runs
30 * after that transaction commits.
31 */
32 readonly projectEvent: (
33 event: OrchestrationEvent,
34 ) => Effect.Effect<void, ProjectionRepositoryError>;
35​
36 /**
37 * Project an event inside a caller's transaction and return its attachment
38 * cleanup. Run the returned effect only after the outer transaction commits.
39 */
40 readonly projectEventDeferred: (
41 event: OrchestrationEvent,
42 ) => Effect.Effect<Effect.Effect<void>, ProjectionRepositoryError>;
44​
45/**
46 * OrchestrationProjectionPipeline - Service tag for orchestration projections.
47 */
48export class OrchestrationProjectionPipeline extends Context.Service<
49 OrchestrationProjectionPipeline,
50 OrchestrationProjectionPipelineShape
51>()("t3/orchestration/Services/ProjectionPipeline/OrchestrationProjectionPipeline") {}