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, 04:45 UTC
| 1 | import * as cloudtrail from "@distilled.cloud/aws/cloudtrail"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as AWSBindings from "../AWSBindings.ts"; |
| 5 | import type { EventDataStore } from "./EventDataStore.ts"; |
| 6 | import { StartQuery, type StartQueryRequest } from "./StartQuery.ts"; |
| 7 | |
| 8 | /** |
| 9 | * Bespoke (not scaffolded): the runtime callable resolves the bound store's |
| 10 | * ID out of its ARN and threads it through a `QueryStatement` callback — |
| 11 | * CloudTrail Lake SQL references the store by ID in the `FROM` clause rather |
| 12 | * than as a request field. |
| 13 | */ |
| 14 | export const StartQueryHttp = Layer.effect( |
| 15 | StartQuery, |
| 16 | Effect.gen(function* () { |
| 17 | const bind = yield* AWSBindings.Bind; |
| 18 | const startQuery = yield* AWSBindings.withCredentials(cloudtrail.startQuery); |
| 19 | |
| 20 | return Effect.fn(function* (store: EventDataStore) { |
| 21 | const Arn = yield* store.eventDataStoreArn; |
| 22 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 23 | yield* bind`AWS.CloudTrail.StartQuery(${store})`({ |
| 24 | policyStatements: [ |
| 25 | { |
| 26 | Effect: "Allow", |
| 27 | Action: ["cloudtrail:StartQuery"], |
| 28 | Resource: [store.eventDataStoreArn], |
| 29 | }, |
| 30 | ], |
| 31 | }); |
| 32 | } |
| 33 | return Effect.fn(`AWS.CloudTrail.StartQuery(${store.LogicalId})`)(function* ( |
| 34 | request: StartQueryRequest, |
| 35 | ) { |
| 36 | const arn = yield* Arn; |
| 37 | const eventDataStoreId = arn.split("/").pop()!; |
| 38 | const { QueryStatement, ...rest } = request; |
| 39 | return yield* startQuery({ |
| 40 | ...rest, |
| 41 | QueryStatement: |
| 42 | typeof QueryStatement === "function" |
| 43 | ? QueryStatement(eventDataStoreId) |
| 44 | : QueryStatement, |
| 45 | }); |
| 46 | }); |
| 47 | }); |
| 48 | }), |
| 49 | ); |