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