@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 36 lines 1.42 KB
Raw
1 import type { Conflict } from "@distilled.cloud/prisma";
2 import { createDeploymentStart, createDeploymentStop } from "@distilled.cloud/prisma/management";
3 import * as Effect from "effect/Effect";
4 import { observeDeployment } from "./DeploymentObserve.ts";
5
6 const startConflictIsIdempotent = (deploymentId: string, error: Conflict) =>
7 observeDeployment(deploymentId).pipe(
8 Effect.flatMap((deployment) =>
9 deployment.status === "running" || deployment.status === "provisioning"
10 ? Effect.undefined
11 : Effect.fail(error),
12 ),
13 Effect.catchTag("NotFound", () => Effect.fail(error)),
14 );
15
16 const stopConflictIsIdempotent = (deploymentId: string, error: Conflict) =>
17 observeDeployment(deploymentId).pipe(
18 Effect.flatMap((deployment) =>
19 deployment.status === "stopped" || deployment.status === "stopping"
20 ? Effect.void
21 : Effect.fail(error),
22 ),
23 Effect.catchTag("NotFound", () => Effect.fail(error)),
24 );
25
26 export const startDeploymentIdempotent = (deploymentId: string) =>
27 createDeploymentStart({ deploymentId }).pipe(
28 Effect.map((response) => response.data),
29 Effect.catchTag("Conflict", (error) => startConflictIsIdempotent(deploymentId, error)),
30 );
31
32 export const stopDeploymentIdempotent = (deploymentId: string) =>
33 createDeploymentStop({ deploymentId }).pipe(
34 Effect.asVoid,
35 Effect.catchTag("Conflict", (error) => stopConflictIsIdempotent(deploymentId, error)),
36 );