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 /**
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 a pending approval row by request id.
81 */
82 readonly deleteByRequestId: (
83 input: DeleteProjectionPendingApprovalInput,
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") {}