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 {
10 ApprovalRequestId,
11 IsoDateTime,
12 ProjectionPendingApprovalDecision,
13 ProjectionPendingApprovalStatus,
14 ThreadId,
15 TurnId,
16} from "@t3tools/contracts";
17import { Option, Schema, Context } from "effect";
18import type { Effect } from "effect";
19
20import type { ProjectionRepositoryError } from "../Errors.ts";
21
22export const ProjectionPendingApproval = Schema.Struct({
23 requestId: ApprovalRequestId,
24 threadId: ThreadId,
25 turnId: Schema.NullOr(TurnId),
26 status: ProjectionPendingApprovalStatus,
27 decision: ProjectionPendingApprovalDecision,
28 createdAt: IsoDateTime,
29 resolvedAt: Schema.NullOr(IsoDateTime),
30});
31export type ProjectionPendingApproval = typeof ProjectionPendingApproval.Type;
32
33export const ListProjectionPendingApprovalsInput = Schema.Struct({
34 threadId: ThreadId,
35});
36export type ListProjectionPendingApprovalsInput = typeof ListProjectionPendingApprovalsInput.Type;
37
38export const GetProjectionPendingApprovalInput = Schema.Struct({
39 requestId: ApprovalRequestId,
40});
41export type GetProjectionPendingApprovalInput = typeof GetProjectionPendingApprovalInput.Type;
42
43export const DeleteProjectionPendingApprovalInput = Schema.Struct({
44 requestId: ApprovalRequestId,
45});
46export type DeleteProjectionPendingApprovalInput = typeof DeleteProjectionPendingApprovalInput.Type;
47
48/**
49 * ProjectionPendingApprovalRepositoryShape - Service API for pending approvals.
50 */
51export interface ProjectionPendingApprovalRepositoryShape {
52 /**
53 * Insert or replace a projected pending approval row.
54 *
55 * Upserts by `requestId`.
56 */
57 readonly upsert: (
58 row: ProjectionPendingApproval,
59 ) => Effect.Effect<void, ProjectionRepositoryError>;
60
61 /**
62 * List pending approvals for a thread.
63 *
64 * Returned in ascending creation order.
65 */
66 readonly listByThreadId: (
67 input: ListProjectionPendingApprovalsInput,
68 ) => Effect.Effect<ReadonlyArray<ProjectionPendingApproval>, ProjectionRepositoryError>;
69
70 /**
71 * Read a pending approval row by request id.
72 */
73 readonly getByRequestId: (
74 input: GetProjectionPendingApprovalInput,
75 ) => Effect.Effect<Option.Option<ProjectionPendingApproval>, ProjectionRepositoryError>;
76
77 /**
78 * Delete a pending approval row by request id.
79 */
80 readonly deleteByRequestId: (
81 input: DeleteProjectionPendingApprovalInput,
82 ) => Effect.Effect<void, ProjectionRepositoryError>;
83}
84
85/**
86 * ProjectionPendingApprovalRepository - Service tag for pending approval persistence.
87 */
88export class ProjectionPendingApprovalRepository extends Context.Service<
89 ProjectionPendingApprovalRepository,
90 ProjectionPendingApprovalRepositoryShape
91>()("t3/persistence/Services/ProjectionPendingApprovals/ProjectionPendingApprovalRepository") {}