The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as TSQ from "@distilled.cloud/aws/timestream-query"; |
| 2 | import * as Output from "alchemy/Output"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Layer from "effect/Layer"; |
| 5 | import * as AWSBindings from "../AWSBindings.ts"; |
| 6 | import { |
| 7 | ExecuteScheduledQuery, |
| 8 | type ExecuteScheduledQueryRequest, |
| 9 | } from "./ExecuteScheduledQuery.ts"; |
| 10 | import { discover, withEndpoint } from "./internal.ts"; |
| 11 | import type { ScheduledQuery } from "./ScheduledQuery.ts"; |
| 12 | |
| 13 | // Bespoke (not on the BindingHttp scaffold): the only Timestream binding |
| 14 | // scoped to a ScheduledQuery rather than a Table or the account. |
| 15 | export const ExecuteScheduledQueryHttp = Layer.effect( |
| 16 | ExecuteScheduledQuery, |
| 17 | Effect.gen(function* () { |
| 18 | const bind = yield* AWSBindings.Bind; |
| 19 | // Yield-first captures the operations' services (Credentials/Region/ |
| 20 | // HttpClient) at layer init so the runtime callable is requirement-free. |
| 21 | const executeScheduledQuery = yield* AWSBindings.withCredentials(TSQ.executeScheduledQuery); |
| 22 | const describeEndpoints = yield* AWSBindings.withCredentials(TSQ.describeEndpoints); |
| 23 | const withQueryEndpoint = withEndpoint(discover("query", describeEndpoints({}))); |
| 24 | return Effect.fn(function* (scheduledQuery: ScheduledQuery) { |
| 25 | const ScheduledQueryArn = yield* scheduledQuery.scheduledQueryArn; |
| 26 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 27 | yield* bind`AWS.Timestream.ExecuteScheduledQuery(${scheduledQuery})`({ |
| 28 | policyStatements: [ |
| 29 | { |
| 30 | Effect: "Allow", |
| 31 | Action: ["timestream:ExecuteScheduledQuery"], |
| 32 | Resource: [Output.interpolate`${scheduledQuery.scheduledQueryArn}`], |
| 33 | }, |
| 34 | // Endpoint discovery is required and is not scoped to a |
| 35 | // resource. |
| 36 | { |
| 37 | Effect: "Allow", |
| 38 | Action: ["timestream:DescribeEndpoints"], |
| 39 | Resource: ["*"], |
| 40 | }, |
| 41 | ], |
| 42 | }); |
| 43 | } |
| 44 | return Effect.fn(`AWS.Timestream.ExecuteScheduledQuery(${scheduledQuery.LogicalId})`)( |
| 45 | function* (request: ExecuteScheduledQueryRequest) { |
| 46 | return yield* withQueryEndpoint( |
| 47 | executeScheduledQuery({ |
| 48 | ...request, |
| 49 | ScheduledQueryArn: yield* ScheduledQueryArn, |
| 50 | }), |
| 51 | ); |
| 52 | }, |
| 53 | ); |
| 54 | }); |
| 55 | }), |
| 56 | ); |