Open History to see the last commit
1/**
2 * ProjectionThreadRepository - Projection repository interface for threads.
3 *
4 * Owns persistence operations for projected thread records in the
5 * orchestration read model.
6 *
7 * @module ProjectionThreadRepository
8 */
9import { IsoDateTime, ProjectId, ThreadId, TurnId } from "@t3tools/contracts";
10import { Option, Schema, ServiceMap } from "effect";
11import type { Effect } from "effect";
12
13import type { ProjectionRepositoryError } from "../Errors.ts";
14
15export const ProjectionThread = Schema.Struct({
16 threadId: ThreadId,
17 projectId: ProjectId,
18 title: Schema.String,
19 model: Schema.String,
20 branch: Schema.NullOr(Schema.String),
21 worktreePath: Schema.NullOr(Schema.String),
22 latestTurnId: Schema.NullOr(TurnId),
23 createdAt: IsoDateTime,
24 updatedAt: IsoDateTime,
25 deletedAt: Schema.NullOr(IsoDateTime),
26});
27export type ProjectionThread = typeof ProjectionThread.Type;
28
29export const GetProjectionThreadInput = Schema.Struct({
30 threadId: ThreadId,
31});
32export type GetProjectionThreadInput = typeof GetProjectionThreadInput.Type;
33
34export const DeleteProjectionThreadInput = Schema.Struct({
35 threadId: ThreadId,
36});
37export type DeleteProjectionThreadInput = typeof DeleteProjectionThreadInput.Type;
38
39export const ListProjectionThreadsByProjectInput = Schema.Struct({
40 projectId: ProjectId,
41});
42export type ListProjectionThreadsByProjectInput = typeof ListProjectionThreadsByProjectInput.Type;
43
44/**
45 * ProjectionThreadRepositoryShape - Service API for projected thread records.
46 */
47export interface ProjectionThreadRepositoryShape {
48 /**
49 * Insert or replace a projected thread row.
50 *
51 * Upserts by `threadId`.
52 */
53 readonly upsert: (thread: ProjectionThread) => Effect.Effect<void, ProjectionRepositoryError>;
54
55 /**
56 * Read a projected thread row by id.
57 */
58 readonly getById: (
59 input: GetProjectionThreadInput,
60 ) => Effect.Effect<Option.Option<ProjectionThread>, ProjectionRepositoryError>;
61
62 /**
63 * List projected threads for a project.
64 *
65 * Returned in deterministic creation order.
66 */
67 readonly listByProjectId: (
68 input: ListProjectionThreadsByProjectInput,
69 ) => Effect.Effect<ReadonlyArray<ProjectionThread>, ProjectionRepositoryError>;
70
71 /**
72 * Soft-delete a projected thread row by id.
73 */
74 readonly deleteById: (
75 input: DeleteProjectionThreadInput,
76 ) => Effect.Effect<void, ProjectionRepositoryError>;
77}
78
79/**
80 * ProjectionThreadRepository - Service tag for thread projection persistence.
81 */
82export class ProjectionThreadRepository extends ServiceMap.Service<
83 ProjectionThreadRepository,
84 ProjectionThreadRepositoryShape
85>()("t3/persistence/Services/ProjectionThreads/ProjectionThreadRepository") {}