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
45/**
46 * ProjectionPendingApprovalRepositoryShape - Service API for pending approvals.
47 */
48export interface ProjectionPendingApprovalRepositoryShape {
49 /**
50 * Insert or replace a projected pending approval row.
51 *
52 * Upserts by `requestId`.
53 */
54 readonly upsert: (
55 row: ProjectionPendingApproval,
56 ) => Effect.Effect<void, ProjectionRepositoryError>;
57
58 /**
59 * List pending approvals for a thread.
60 *
61 * Returned in ascending creation order.
62 */
63 readonly listByThreadId: (
64 input: ListProjectionPendingApprovalsInput,
65 ) => Effect.Effect<ReadonlyArray<ProjectionPendingApproval>, ProjectionRepositoryError>;
66
67 /** Count pending approvals without loading resolved request history. */
68 readonly countPendingByThreadId: (
69 input: ListProjectionPendingApprovalsInput,
70 ) => Effect.Effect<number, ProjectionRepositoryError>;
71
72 /**
73 * Read a pending approval row by request id.
74 */
75 readonly getByRequestId: (
76 input: GetProjectionPendingApprovalInput,
77 ) => Effect.Effect<Option.Option<ProjectionPendingApproval>, ProjectionRepositoryError>;
78
79 /**
80 * Delete every pending approval row for a thread.
81 */
82 readonly deleteByThreadId: (
83 input: ListProjectionPendingApprovalsInput,
84 ) => Effect.Effect<void, ProjectionRepositoryError>;
85}
86
87/**
88 * ProjectionPendingApprovalRepository - Service tag for pending approval persistence.
89 */
90export class ProjectionPendingApprovalRepository extends Context.Service<
91 ProjectionPendingApprovalRepository,
92 ProjectionPendingApprovalRepositoryShape
93>()("t3/persistence/Services/ProjectionPendingApprovals/ProjectionPendingApprovalRepository") {}