1import { GcpEnvironment } from "@/GCP/Environment";
2import * as Effect from "effect/Effect";
3import { MinimumLogLevel } from "effect/References";
4import * as Schedule from "effect/Schedule";
5
6export const logLevel = Effect.provideService(
7 MinimumLogLevel,
8 process.env.DEBUG ? "Debug" : "Info",
9);
10
11export const currentProject = GcpEnvironment.current.pipe(
12 Effect.map((env) => env.project),
13);
14export const location = "us-central1";
15
16export const waitUntilGone = <E extends { readonly _tag: string }, R>(
17 get: Effect.Effect<unknown, E, R>,
18) =>
19 get.pipe(
20 Effect.as("found" as const),
21 Effect.catchIf(
22 // BigLake answers a missing resource with 403, typed
23 // BigLakeResourceNotFound.
24 (
25 error,
26 ): error is Extract<
27 E,
28 { readonly _tag: "NotFound" | "BigLakeResourceNotFound" }
29 > =>
30 error._tag === "NotFound" || error._tag === "BigLakeResourceNotFound",
31 () => Effect.succeed("gone" as const),
32 ),
33 Effect.repeat({
34 schedule: Schedule.spaced("1 second"),
35 until: (status) => status === "gone",
36 times: 10,
37 }),
38 );