Open History to see the last commit
1/**
2 * ProjectionProjectRepository - Projection repository interface for projects.
3 *
4 * Owns persistence operations for project rows in the orchestration projection
5 * read model.
6 *
7 * @module ProjectionProjectRepository
8 */
9import {
10 IsoDateTime,
11 ModelSelection,
12 ProjectId,
13 ProjectScript,
14 ThreadEnvMode,
15} from "@t3tools/contracts";
16import * as Option from "effect/Option";
17import * as Schema from "effect/Schema";
18import * as Context from "effect/Context";
19import type * as Effect from "effect/Effect";
20
21import type { ProjectionRepositoryError } from "../Errors.ts";
22
23export const ProjectionProject = Schema.Struct({
24 projectId: ProjectId,
25 title: Schema.String,
26 workspaceRoot: Schema.String,
27 defaultModelSelection: Schema.NullOr(ModelSelection),
28 defaultThreadEnvMode: Schema.NullOr(ThreadEnvMode),
29 faviconPath: Schema.optional(Schema.NullOr(Schema.String)),
30 scripts: Schema.Array(ProjectScript),
31 createdAt: IsoDateTime,
32 updatedAt: IsoDateTime,
33 deletedAt: Schema.NullOr(IsoDateTime),
34});
35export type ProjectionProject = typeof ProjectionProject.Type;
36
37export const GetProjectionProjectInput = Schema.Struct({
38 projectId: ProjectId,
39});
40export type GetProjectionProjectInput = typeof GetProjectionProjectInput.Type;
41
42export const DeleteProjectionProjectInput = Schema.Struct({
43 projectId: ProjectId,
44});
45export type DeleteProjectionProjectInput = typeof DeleteProjectionProjectInput.Type;
46
47/**
48 * ProjectionProjectRepositoryShape - Service API for projected project records.
49 */
50export interface ProjectionProjectRepositoryShape {
51 /**
52 * Insert or replace a projected project row.
53 *
54 * Upserts by `projectId` and persists scripts through JSON encoding.
55 */
56 readonly upsert: (row: ProjectionProject) => Effect.Effect<void, ProjectionRepositoryError>;
57
58 /**
59 * Read a projected project row by id.
60 */
61 readonly getById: (
62 input: GetProjectionProjectInput,
63 ) => Effect.Effect<Option.Option<ProjectionProject>, ProjectionRepositoryError>;
64
65 /**
66 * List all projected project rows.
67 *
68 * Returned in deterministic creation order.
69 */
70 readonly listAll: () => Effect.Effect<
71 ReadonlyArray<ProjectionProject>,
72 ProjectionRepositoryError
73 >;
74
75 /**
76 * Soft-delete a projected project row by id.
77 */
78 readonly deleteById: (
79 input: DeleteProjectionProjectInput,
80 ) => Effect.Effect<void, ProjectionRepositoryError>;
81}
82
83/**
84 * ProjectionProjectRepository - Service tag for project projection persistence.
85 */
86export class ProjectionProjectRepository extends Context.Service<
87 ProjectionProjectRepository,
88 ProjectionProjectRepositoryShape
89>()("t3/persistence/Services/ProjectionProjects/ProjectionProjectRepository") {}