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

ProjectionProjects.ts

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