The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as Domain from "@alchemy.run/domain"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import { TransferApproved } from "./ApproveTransfer.command.ts"; |
| 4 | import { Decision, ExecuteTransfer } from "./ExecuteTransfer.saga.ts"; |
| 5 | import { TransferFailed } from "./FailTransfer.command.ts"; |
| 6 | import { TransferRequested } from "./RequestTransfer.command.ts"; |
| 7 | import { Transfer } from "./Transfer.aggregate.ts"; |
| 8 | |
| 9 | /** |
| 10 | * Starts the ExecuteTransfer saga for every requested transfer, and passes on |
| 11 | * what the Transfer decides about a large one: approved, or expired. |
| 12 | */ |
| 13 | export class TransferExecution extends Domain.Policy("TransferExecution", { |
| 14 | from: Transfer, |
| 15 | on: [TransferRequested, TransferApproved, TransferFailed], |
| 16 | }) {} |
| 17 | |
| 18 | export const TransferExecutionLive = TransferExecution.toLayer( |
| 19 | Effect.gen(function* () { |
| 20 | const executions = yield* ExecuteTransfer; |
| 21 | return Effect.fn(function* ({ source, event }) { |
| 22 | switch (event._tag) { |
| 23 | case "TransferRequested": |
| 24 | yield* executions.start(source, { |
| 25 | from: event.from, |
| 26 | to: event.to, |
| 27 | amount: event.amount, |
| 28 | requestedBy: event.requestedBy, |
| 29 | needsApproval: event.needsApproval, |
| 30 | }); |
| 31 | return; |
| 32 | case "TransferApproved": |
| 33 | return yield* executions.get(source).signal(Decision, "approved"); |
| 34 | case "TransferFailed": |
| 35 | // A transfer that expired waiting for approval; a saga that already |
| 36 | // finished ignores it. |
| 37 | return yield* executions.get(source).signal(Decision, "expired"); |
| 38 | } |
| 39 | }); |
| 40 | }), |
| 41 | ); |