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

ProjectionProjects.ts

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