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