Open History to see the last commit
1/**
2 * ProjectionSnapshotQuery - Read-model snapshot query service interface.
3 *
4 * Exposes the current orchestration projection snapshot for read-only API
5 * access.
6 *
7 * @module ProjectionSnapshotQuery
8 */
9import type {
10 OrchestrationCheckpointSummary,
11 OrchestrationProject,
12 OrchestrationReadModel,
13 ProjectId,
14 ThreadId,
15} from "@t3tools/contracts";
16import { ServiceMap } from "effect";
17import type { Option } from "effect";
18import type { Effect } from "effect";
19
20import type { ProjectionRepositoryError } from "../../persistence/Errors.ts";
21
22export interface ProjectionSnapshotCounts {
23 readonly projectCount: number;
24 readonly threadCount: number;
25}
26
27export interface ProjectionThreadCheckpointContext {
28 readonly threadId: ThreadId;
29 readonly projectId: ProjectId;
30 readonly workspaceRoot: string;
31 readonly worktreePath: string | null;
32 readonly checkpoints: ReadonlyArray<OrchestrationCheckpointSummary>;
33}
34
35/**
36 * ProjectionSnapshotQueryShape - Service API for read-model snapshots.
37 */
38export interface ProjectionSnapshotQueryShape {
39 /**
40 * Read the latest orchestration projection snapshot.
41 *
42 * Rehydrates from projection tables and derives snapshot sequence from
43 * projector cursor state.
44 */
45 readonly getSnapshot: () => Effect.Effect<OrchestrationReadModel, ProjectionRepositoryError>;
46
47 /**
48 * Read aggregate projection counts without hydrating the full read model.
49 */
50 readonly getCounts: () => Effect.Effect<ProjectionSnapshotCounts, ProjectionRepositoryError>;
51
52 /**
53 * Read the active project for an exact workspace root match.
54 */
55 readonly getActiveProjectByWorkspaceRoot: (
56 workspaceRoot: string,
57 ) => Effect.Effect<Option.Option<OrchestrationProject>, ProjectionRepositoryError>;
58
59 /**
60 * Read the earliest active thread for a project.
61 */
62 readonly getFirstActiveThreadIdByProjectId: (
63 projectId: ProjectId,
64 ) => Effect.Effect<Option.Option<ThreadId>, ProjectionRepositoryError>;
65
66 /**
67 * Read the checkpoint context needed to resolve a single thread diff.
68 */
69 readonly getThreadCheckpointContext: (
70 threadId: ThreadId,
71 ) => Effect.Effect<Option.Option<ProjectionThreadCheckpointContext>, ProjectionRepositoryError>;
72}
73
74/**
75 * ProjectionSnapshotQuery - Service tag for projection snapshot queries.
76 */
77export class ProjectionSnapshotQuery extends ServiceMap.Service<
78 ProjectionSnapshotQuery,
79 ProjectionSnapshotQueryShape
80>()("t3/orchestration/Services/ProjectionSnapshotQuery") {}