Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

OrchestrationCommandReceipts.ts

69 lines2.1 KB

1/**
2 * OrchestrationCommandReceiptRepository - Repository interface for command receipts.
3 *
4 * Owns persistence operations for deduplication and status tracking of
5 * orchestration command handling.
6 *
7 * @module OrchestrationCommandReceiptRepository
8 */
9import {
10 CommandId,
11 IsoDateTime,
12 NonNegativeInt,
13 OrchestrationAggregateKind,
14 OrchestrationCommandReceiptStatus,
15 ProjectId,
16 ThreadId,
17} from "@t3tools/contracts";
18import { Option, Schema, Context } from "effect";
19import type { Effect } from "effect";
20​
21import type { OrchestrationCommandReceiptRepositoryError } from "../Errors.ts";
22​
23export const OrchestrationCommandReceipt = Schema.Struct({
24 commandId: CommandId,
25 aggregateKind: OrchestrationAggregateKind,
26 aggregateId: Schema.Union([ProjectId, ThreadId]),
27 acceptedAt: IsoDateTime,
28 resultSequence: NonNegativeInt,
29 status: OrchestrationCommandReceiptStatus,
30 error: Schema.NullOr(Schema.String),
31});
32export type OrchestrationCommandReceipt = typeof OrchestrationCommandReceipt.Type;
33​
34export const GetByCommandIdInput = Schema.Struct({
35 commandId: CommandId,
36});
37export type GetByCommandIdInput = typeof GetByCommandIdInput.Type;
38​
39/**
40 * OrchestrationCommandReceiptRepositoryShape - Service API for command receipts.
41 */
42export interface OrchestrationCommandReceiptRepositoryShape {
43 /**
44 * Insert or replace a command receipt row.
45 *
46 * Upserts by `commandId` for idempotent command-result tracking.
47 */
48 readonly upsert: (
49 receipt: OrchestrationCommandReceipt,
50 ) => Effect.Effect<void, OrchestrationCommandReceiptRepositoryError>;
51​
52 /**
53 * Read a command receipt by command id.
54 */
55 readonly getByCommandId: (
56 input: GetByCommandIdInput,
57 ) => Effect.Effect<
58 Option.Option<OrchestrationCommandReceipt>,
59 OrchestrationCommandReceiptRepositoryError
60 >;
62​
63/**
64 * OrchestrationCommandReceiptRepository - Service tag for command receipt persistence.
65 */
66export class OrchestrationCommandReceiptRepository extends Context.Service<
67 OrchestrationCommandReceiptRepository,
68 OrchestrationCommandReceiptRepositoryShape
69>()("t3/persistence/Services/OrchestrationCommandReceipts/OrchestrationCommandReceiptRepository") {}