@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 39 lines 1.26 KB
Raw
1 import * as certificatemanager from "@distilled.cloud/gcp/certificatemanager_v1";
2 import * as Effect from "effect/Effect";
3 import { waitForOperation as waitForGcpOperation } from "../Operation.ts";
4
5 /**
6 * Wait for a Certificate Manager operation. Most operations finish in
7 * seconds; managed certificates and issuance configs can take minutes. An
8 * operation that finished with `ALREADY_EXISTS` (6) is a lost create race;
9 * `notFoundOk` also accepts `NOT_FOUND` (5).
10 *
11 * NOT exported from `index.ts`.
12 */
13 export const waitForOperation = (
14 operation: certificatemanager.Operation,
15 options?: { notFoundOk?: boolean },
16 ) =>
17 waitForGcpOperation(
18 operation,
19 (name) =>
20 certificatemanager.getProjectsLocationsOperations({ name }).pipe(
21 Effect.catchTag("NotFound", (error) =>
22 options?.notFoundOk === true
23 ? Effect.succeed<certificatemanager.Operation>({
24 name,
25 done: true,
26 })
27 : Effect.fail(error),
28 ),
29 ),
30 { budget: "10 minutes" },
31 ).pipe(
32 Effect.catchIf(
33 (error) =>
34 error._tag === "GCP.OperationFailed" &&
35 (error.code === 6 || (options?.notFoundOk === true && error.code === 5)),
36 () => Effect.void,
37 ),
38 Effect.asVoid,
39 );