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

OrchestrationCommandReceipts.ts

71 lines2.2 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 * as Option from "effect/Option";
19import * as Schema from "effect/Schema";
20import * as Context from "effect/Context";
21import type * as Effect from "effect/Effect";
22​
23import type { OrchestrationCommandReceiptRepositoryError } from "../Errors.ts";
24​
25export const OrchestrationCommandReceipt = Schema.Struct({
26 commandId: CommandId,
27 aggregateKind: OrchestrationAggregateKind,
28 aggregateId: Schema.Union([ProjectId, ThreadId]),
29 acceptedAt: IsoDateTime,
30 resultSequence: NonNegativeInt,
31 status: OrchestrationCommandReceiptStatus,
32 error: Schema.NullOr(Schema.String),
33});
34export type OrchestrationCommandReceipt = typeof OrchestrationCommandReceipt.Type;
35​
36export const GetByCommandIdInput = Schema.Struct({
37 commandId: CommandId,
38});
39export type GetByCommandIdInput = typeof GetByCommandIdInput.Type;
40​
41/**
42 * OrchestrationCommandReceiptRepositoryShape - Service API for command receipts.
43 */
44export interface OrchestrationCommandReceiptRepositoryShape {
45 /**
46 * Insert or replace a command receipt row.
47 *
48 * Upserts by `commandId` for idempotent command-result tracking.
49 */
50 readonly upsert: (
51 receipt: OrchestrationCommandReceipt,
52 ) => Effect.Effect<void, OrchestrationCommandReceiptRepositoryError>;
53​
54 /**
55 * Read a command receipt by command id.
56 */
57 readonly getByCommandId: (
58 input: GetByCommandIdInput,
59 ) => Effect.Effect<
60 Option.Option<OrchestrationCommandReceipt>,
61 OrchestrationCommandReceiptRepositoryError
62 >;
64​
65/**
66 * OrchestrationCommandReceiptRepository - Service tag for command receipt persistence.
67 */
68export class OrchestrationCommandReceiptRepository extends Context.Service<
69 OrchestrationCommandReceiptRepository,
70 OrchestrationCommandReceiptRepositoryShape
71>()("t3/persistence/Services/OrchestrationCommandReceipts/OrchestrationCommandReceiptRepository") {}