Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ProjectionProjects.ts

90 lines2.7 KB

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