@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, 06:00 UTC

main
ts 52 lines 1.6 KB
Raw
1 import * as DynamoDB from "@alchemy.run/aws/DynamoDB";
2 import * as Lambda from "@alchemy.run/aws/Lambda";
3 import * as Effect from "effect/Effect";
4 import * as HttpServerResponse from "effect/http/HttpServerResponse";
5 import * as Layer from "effect/Layer";
6
7 // One Function consuming a DynamoDB stream. Each deploy varies the Table or the
8 // stream subscription to drive a different EventSourceMapping transition.
9 export class EventSourceMappingTableFunction extends Lambda.Function<EventSourceMappingTableFunction>()(
10 "EventSourceMappingTableFunction",
11 ) {}
12
13 export interface TableFunctionOptions {
14 tags?: Record<string, string>;
15 partitionKey?: string;
16 streamViewType?: "NEW_AND_OLD_IMAGES" | "KEYS_ONLY";
17 startingPosition?: "LATEST" | "TRIM_HORIZON";
18 }
19
20 export const makeTableFunction = ({
21 tags = {},
22 partitionKey = "pk",
23 streamViewType = "NEW_AND_OLD_IMAGES",
24 startingPosition = "LATEST",
25 }: TableFunctionOptions = {}) =>
26 EventSourceMappingTableFunction.make(
27 {
28 main: import.meta.url,
29 functionUrl: false,
30 },
31 Effect.gen(function* () {
32 const table = yield* DynamoDB.Table("EventSourceMappingTable", {
33 partitionKey,
34 attributes: { [partitionKey]: "S" },
35 tags,
36 });
37
38 yield* DynamoDB.consumeTableChanges(
39 table,
40 { streamViewType, startingPosition },
41 () => Effect.void,
42 );
43
44 return {
45 fetch: Effect.gen(function* () {
46 return HttpServerResponse.text("ok");
47 }).pipe(Effect.orDie),
48 };
49 }).pipe(Effect.provide(Layer.mergeAll(Lambda.TableEventSource))),
50 );
51
52 export default makeTableFunction();