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