@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 44 lines 1.33 KB
Raw
1 import * as spanner from "@distilled.cloud/gcp/spanner_v1";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as GCPBindings from "../GCPBindings.ts";
5 import { grantFor } from "../HttpBinding.ts";
6 import type { Database } from "./Database.ts";
7 import { GetDdl, type GetDdlRequest } from "./GetDdl.ts";
8
9 /**
10 * HTTP implementation of {@link GetDdl}.
11 *
12 * @layer
13 * @provides GCP.Spanner.GetDdl
14 */
15 export const GetDdlHttp = Layer.effect(
16 GetDdl,
17 Effect.gen(function* () {
18 const bind = yield* GCPBindings.Bind;
19 const getDdlProjectsInstancesDatabases = yield* GCPBindings.withCredentials(
20 spanner.getDdlProjectsInstancesDatabases,
21 );
22 return Effect.fn(function* (database: Database) {
23 if (!globalThis.__ALCHEMY_RUNTIME__) {
24 yield* bind`GCP.Spanner.GetDdl(${database})`({
25 iam: [
26 grantFor(
27 { role: "roles/spanner.databaseReader", on: "spanner.database" },
28 database.name,
29 ),
30 ],
31 });
32 }
33 const name = yield* database.name;
34 return Effect.fn(`GCP.Spanner.GetDdl(${database.LogicalId})`)(function* (
35 request?: GetDdlRequest,
36 ) {
37 return yield* getDdlProjectsInstancesDatabases({
38 ...request,
39 database: yield* name,
40 });
41 });
42 });
43 }),
44 );