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 { GrantTables, tablesRegion } from "./BindingHttp.ts"; |
| 7 | import { |
| 8 | RestoreTableFromBackup, |
| 9 | type RestoreTableFromBackupRequest, |
| 10 | } from "./RestoreTableFromBackup.ts"; |
| 11 | import type { Table } from "./Table.ts"; |
| 12 | |
| 13 | export const RestoreTableFromBackupHttp = Layer.effect( |
| 14 | RestoreTableFromBackup, |
| 15 | Effect.gen(function* () { |
| 16 | const grantTables = yield* GrantTables; |
| 17 | return Effect.fn(function* <From extends Table, To extends Table>(from: From, to: To) { |
| 18 | const TargetTableName = yield* to.tableName; |
| 19 | yield* grantTables( |
| 20 | `AWS.DynamoDB.RestoreTableFromBackup(${from.LogicalId}, ${to.LogicalId})`, |
| 21 | () => [ |
| 22 | { |
| 23 | Effect: "Allow", |
| 24 | Action: ["dynamodb:RestoreTableFromBackup"], |
| 25 | Resource: [Output.interpolate`${from.tableArn}/backup/*`], |
| 26 | }, |
| 27 | { |
| 28 | Effect: "Allow", |
| 29 | Action: [ |
| 30 | "dynamodb:PutItem", |
| 31 | "dynamodb:UpdateItem", |
| 32 | "dynamodb:DeleteItem", |
| 33 | "dynamodb:GetItem", |
| 34 | "dynamodb:Query", |
| 35 | "dynamodb:Scan", |
| 36 | "dynamodb:BatchWriteItem", |
| 37 | ], |
| 38 | Resource: [to.tableArn], |
| 39 | }, |
| 40 | ], |
| 41 | ); |
| 42 | // Restores stay in-region: both tables must share it. |
| 43 | const restoreTableFromBackup = yield* AWSBindings.withCredentials( |
| 44 | DynamoDB.restoreTableFromBackup, |
| 45 | tablesRegion([from, to]), |
| 46 | ); |
| 47 | return Effect.fn(`AWS.DynamoDB.RestoreTableFromBackup(${from.LogicalId}, ${to.LogicalId})`)( |
| 48 | function* (request: RestoreTableFromBackupRequest) { |
| 49 | return yield* restoreTableFromBackup({ |
| 50 | ...request, |
| 51 | TargetTableName: yield* TargetTableName, |
| 52 | }); |
| 53 | }, |
| 54 | ); |
| 55 | }); |
| 56 | }), |
| 57 | ); |