@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 88 lines 2.84 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as GCPBindings from "../GCPBindings.ts";
3 import { type BindingIam, type GcpHttpOp, grantFor } from "../HttpBinding.ts";
4 import type { Backup } from "./Backup.ts";
5 import type { Instance } from "./Instance.ts";
6 import type { InstancesSnapshot } from "./InstancesSnapshot.ts";
7
8 /**
9 * Shared HTTP scaffolding for Filestore instance, backup, and snapshot
10 * bindings. NOT exported from index.ts.
11 */
12 export const makeFilestoreInstanceHttpBinding = <I extends { name?: string }, A, E>(options: {
13 tag: string;
14 iam: BindingIam;
15 operation: GcpHttpOp<I, A, E>;
16 }) =>
17 Effect.gen(function* () {
18 const bind = yield* GCPBindings.Bind;
19 const run = yield* GCPBindings.withCredentials(options.operation);
20 return Effect.fn(function* (instance: Instance) {
21 if (!globalThis.__ALCHEMY_RUNTIME__) {
22 yield* bind`${options.tag}(${instance})`({
23 iam: [grantFor(options.iam, instance.name)],
24 });
25 }
26 const name = yield* instance.name;
27 return Effect.fn(`${options.tag}(${instance.LogicalId})`)(function* (
28 request?: Omit<I, "name">,
29 ) {
30 return yield* run({
31 ...(request as I),
32 name: yield* name,
33 } as I);
34 });
35 });
36 });
37
38 export const makeFilestoreBackupHttpBinding = <I extends { name?: string }, A, E>(options: {
39 tag: string;
40 iam: BindingIam;
41 operation: GcpHttpOp<I, A, E>;
42 }) =>
43 Effect.gen(function* () {
44 const bind = yield* GCPBindings.Bind;
45 const run = yield* GCPBindings.withCredentials(options.operation);
46 return Effect.fn(function* (backup: Backup) {
47 if (!globalThis.__ALCHEMY_RUNTIME__) {
48 yield* bind`${options.tag}(${backup})`({
49 iam: [grantFor(options.iam, backup.name)],
50 });
51 }
52 const name = yield* backup.name;
53 return Effect.fn(`${options.tag}(${backup.LogicalId})`)(function* (
54 request?: Omit<I, "name">,
55 ) {
56 return yield* run({
57 ...(request as I),
58 name: yield* name,
59 } as I);
60 });
61 });
62 });
63
64 export const makeFilestoreSnapshotHttpBinding = <I extends { name?: string }, A, E>(options: {
65 tag: string;
66 iam: BindingIam;
67 operation: GcpHttpOp<I, A, E>;
68 }) =>
69 Effect.gen(function* () {
70 const bind = yield* GCPBindings.Bind;
71 const run = yield* GCPBindings.withCredentials(options.operation);
72 return Effect.fn(function* (snapshot: InstancesSnapshot) {
73 if (!globalThis.__ALCHEMY_RUNTIME__) {
74 yield* bind`${options.tag}(${snapshot})`({
75 iam: [grantFor(options.iam, snapshot.name)],
76 });
77 }
78 const name = yield* snapshot.name;
79 return Effect.fn(`${options.tag}(${snapshot.LogicalId})`)(function* (
80 request?: Omit<I, "name">,
81 ) {
82 return yield* run({
83 ...(request as I),
84 name: yield* name,
85 } as I);
86 });
87 });
88 });