Open History to see the last commit
1/**
2 * ProjectionPendingApprovalRepository - Repository interface for pending approvals.
3 *
4 * Owns persistence operations for projected approval requests awaiting user
5 * decisions.
6 *
7 * @module ProjectionPendingApprovalRepository
8 */
9import { ApprovalRequestId, IsoDateTime, ThreadId, TurnId } from "@t3tools/contracts";
10import {
11 ProjectionPendingApprovalDecision,
12 ProjectionPendingApprovalStatus,
13} from "@t3tools/contracts/legacy-orchestration";
14import * as Option from "effect/Option";
15import * as Schema from "effect/Schema";
16import * as Context from "effect/Context";
17import type * as Effect from "effect/Effect";
18
19import type { ProjectionRepositoryError } from "../Errors.ts";
20
21export const ProjectionPendingApproval = Schema.Struct({
22 requestId: ApprovalRequestId,
23 threadId: ThreadId,
24 turnId: Schema.NullOr(TurnId),
25 status: ProjectionPendingApprovalStatus,
26 decision: ProjectionPendingApprovalDecision,
27 createdAt: IsoDateTime,
28 resolvedAt: Schema.NullOr(IsoDateTime),
29});
30export type ProjectionPendingApproval = typeof ProjectionPendingApproval.Type;
31
32export const ListProjectionPendingApprovalsInput = Schema.Struct({
33 threadId: ThreadId,
34});
35export type ListProjectionPendingApprovalsInput = typeof ListProjectionPendingApprovalsInput.Type;
36
37export const GetProjectionPendingApprovalInput = Schema.Struct({
38 requestId: ApprovalRequestId,
39});
40export type GetProjectionPendingApprovalInput = typeof GetProjectionPendingApprovalInput.Type;
41
42export const DeleteProjectionPendingApprovalInput = Schema.Struct({
43 requestId: ApprovalRequestId,
44});
45export type DeleteProjectionPendingApprovalInput = typeof DeleteProjectionPendingApprovalInput.Type;
46
47/**
48 * ProjectionPendingApprovalRepositoryShape - Service API for pending approvals.
49 */
50export interface ProjectionPendingApprovalRepositoryShape {
51 /**
52 * Insert or replace a projected pending approval row.
53 *
54 * Upserts by `requestId`.
55 */
56 readonly upsert: (
57 row: ProjectionPendingApproval,
58 ) => Effect.Effect<void, ProjectionRepositoryError>;
59
60 /**
61 * List pending approvals for a thread.
62 *
63 * Returned in ascending creation order.
64 */
65 readonly listByThreadId: (
66 input: ListProjectionPendingApprovalsInput,
67 ) => Effect.Effect<ReadonlyArray<ProjectionPendingApproval>, ProjectionRepositoryError>;
68
69 /** Count pending approvals without loading resolved request history. */
70 readonly countPendingByThreadId: (
71 input: ListProjectionPendingApprovalsInput,
72 ) => Effect.Effect<number, ProjectionRepositoryError>;
73
74 /**
75 * Read a pending approval row by request id.
76 */
77 readonly getByRequestId: (
78 input: GetProjectionPendingApprovalInput,
79 ) => Effect.Effect<Option.Option<ProjectionPendingApproval>, ProjectionRepositoryError>;
80
81 /**
82 * Delete a pending approval row by request id.
83 */
84 readonly deleteByRequestId: (
85 input: DeleteProjectionPendingApprovalInput,
86 ) => Effect.Effect<void, ProjectionRepositoryError>;
87
88 /**
89 * Delete every pending approval row for a thread.
90 */
91 readonly deleteByThreadId: (
92 input: ListProjectionPendingApprovalsInput,
93 ) => Effect.Effect<void, ProjectionRepositoryError>;
94}
95
96/**
97 * ProjectionPendingApprovalRepository - Service tag for pending approval persistence.
98 */
99export class ProjectionPendingApprovalRepository extends Context.Service<
100 ProjectionPendingApprovalRepository,
101 ProjectionPendingApprovalRepositoryShape
102>()("t3/persistence/Services/ProjectionPendingApprovals/ProjectionPendingApprovalRepository") {}