Files
t3code/apps/server/src/persistence/Services/ProjectionThreads.ts
T

86 lines
2.6 KiB
TypeScript

/**
* ProjectionThreadRepository - Projection repository interface for threads.
*
* Owns persistence operations for projected thread records in the
* orchestration read model.
*
* @module ProjectionThreadRepository
*/
import { IsoDateTime, ProjectId, ThreadId, TurnId } from "@t3tools/contracts";
import { Option, Schema, ServiceMap } from "effect";
import type { Effect } from "effect";
import type { ProjectionRepositoryError } from "../Errors.ts";
export const ProjectionThread = Schema.Struct({
threadId: ThreadId,
projectId: ProjectId,
title: Schema.String,
model: Schema.String,
branch: Schema.NullOr(Schema.String),
worktreePath: Schema.NullOr(Schema.String),
latestTurnId: Schema.NullOr(TurnId),
createdAt: IsoDateTime,
updatedAt: IsoDateTime,
deletedAt: Schema.NullOr(IsoDateTime),
});
export type ProjectionThread = typeof ProjectionThread.Type;
export const GetProjectionThreadInput = Schema.Struct({
threadId: ThreadId,
});
export type GetProjectionThreadInput = typeof GetProjectionThreadInput.Type;
export const DeleteProjectionThreadInput = Schema.Struct({
threadId: ThreadId,
});
export type DeleteProjectionThreadInput = typeof DeleteProjectionThreadInput.Type;
export const ListProjectionThreadsByProjectInput = Schema.Struct({
projectId: ProjectId,
});
export type ListProjectionThreadsByProjectInput = typeof ListProjectionThreadsByProjectInput.Type;
/**
* ProjectionThreadRepositoryShape - Service API for projected thread records.
*/
export interface ProjectionThreadRepositoryShape {
/**
* Insert or replace a projected thread row.
*
* Upserts by `threadId`.
*/
readonly upsert: (thread: ProjectionThread) => Effect.Effect<void, ProjectionRepositoryError>;
/**
* Read a projected thread row by id.
*/
readonly getById: (
input: GetProjectionThreadInput,
) => Effect.Effect<Option.Option<ProjectionThread>, ProjectionRepositoryError>;
/**
* List projected threads for a project.
*
* Returned in deterministic creation order.
*/
readonly listByProjectId: (
input: ListProjectionThreadsByProjectInput,
) => Effect.Effect<ReadonlyArray<ProjectionThread>, ProjectionRepositoryError>;
/**
* Soft-delete a projected thread row by id.
*/
readonly deleteById: (
input: DeleteProjectionThreadInput,
) => Effect.Effect<void, ProjectionRepositoryError>;
}
/**
* ProjectionThreadRepository - Service tag for thread projection persistence.
*/
export class ProjectionThreadRepository extends ServiceMap.Service<
ProjectionThreadRepository,
ProjectionThreadRepositoryShape
>()("t3/persistence/Services/ProjectionThreads/ProjectionThreadRepository") {}