@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, 04:45 UTC

main
ts 58 lines 2.01 KB
Raw
1 import * as DynamoDB from "@distilled.cloud/aws/dynamodb";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as AWSBindings from "../AWSBindings.ts";
5 import { GrantTables, tablesRegion } from "./BindingHttp.ts";
6 import {
7 RestoreTableToPointInTime,
8 type RestoreTableToPointInTimeRequest,
9 } from "./RestoreTableToPointInTime.ts";
10 import type { Table } from "./Table.ts";
11
12 export const RestoreTableToPointInTimeHttp = Layer.effect(
13 RestoreTableToPointInTime,
14 Effect.gen(function* () {
15 const grantTables = yield* GrantTables;
16 return Effect.fn(function* <From extends Table, To extends Table>(from: From, to: To) {
17 const SourceTableName = yield* from.tableName;
18 const TargetTableName = yield* to.tableName;
19 yield* grantTables(
20 `AWS.DynamoDB.RestoreTableToPointInTime(${from.LogicalId}, ${to.LogicalId})`,
21 () => [
22 {
23 Effect: "Allow",
24 Action: ["dynamodb:RestoreTableToPointInTime"],
25 Resource: [from.tableArn],
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 restoreTableToPointInTime = yield* AWSBindings.withCredentials(
44 DynamoDB.restoreTableToPointInTime,
45 tablesRegion([from, to]),
46 );
47 return Effect.fn(
48 `AWS.DynamoDB.RestoreTableToPointInTime(${from.LogicalId}, ${to.LogicalId})`,
49 )(function* (request: RestoreTableToPointInTimeRequest) {
50 return yield* restoreTableToPointInTime({
51 ...request,
52 SourceTableName: yield* SourceTableName,
53 TargetTableName: yield* TargetTableName,
54 });
55 });
56 });
57 }),
58 );