The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as DynamoDB from "@distilled.cloud/aws/dynamodb"; |
| 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 | BatchExecuteStatement, |
| 8 | type BatchExecuteStatementRequest, |
| 9 | type BatchExecuteStatementTables, |
| 10 | sortBatchExecuteStatementTables, |
| 11 | } from "./BatchExecuteStatement.ts"; |
| 12 | import { GrantTables, tablesRegion } from "./BindingHttp.ts"; |
| 13 | |
| 14 | export const BatchExecuteStatementHttp = Layer.effect( |
| 15 | BatchExecuteStatement, |
| 16 | Effect.gen(function* () { |
| 17 | const grantTables = yield* GrantTables; |
| 18 | return Effect.fn(function* (...tables: BatchExecuteStatementTables) { |
| 19 | const sortedTables = sortBatchExecuteStatementTables(tables); |
| 20 | yield* grantTables( |
| 21 | `AWS.DynamoDB.BatchExecuteStatement(${sortedTables.map((table) => table.LogicalId).join(", ")})`, |
| 22 | () => [ |
| 23 | { |
| 24 | Effect: "Allow", |
| 25 | Action: [ |
| 26 | "dynamodb:PartiQLDelete", |
| 27 | "dynamodb:PartiQLInsert", |
| 28 | "dynamodb:PartiQLSelect", |
| 29 | "dynamodb:PartiQLUpdate", |
| 30 | ], |
| 31 | Resource: sortedTables.flatMap((table) => [ |
| 32 | table.tableArn, |
| 33 | Output.interpolate`${table.tableArn}/index/*`, |
| 34 | ]), |
| 35 | }, |
| 36 | ], |
| 37 | ); |
| 38 | const batchExecuteStatement = yield* AWSBindings.withCredentials( |
| 39 | DynamoDB.batchExecuteStatement, |
| 40 | tablesRegion(sortedTables), |
| 41 | ); |
| 42 | return Effect.fn( |
| 43 | `AWS.DynamoDB.BatchExecuteStatement(${sortedTables.map((table) => table.LogicalId).join(", ")})`, |
| 44 | )(function* (request: BatchExecuteStatementRequest) { |
| 45 | return yield* batchExecuteStatement(request); |
| 46 | }); |
| 47 | }); |
| 48 | }), |
| 49 | ); |