@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 68 lines 2.08 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Stack } from "alchemy/Stack";
3 import * as Effect from "effect/Effect";
4 import { HttpServerRequest } from "effect/http/HttpServerRequest";
5 import * as HttpServerResponse from "effect/http/HttpServerResponse";
6 import * as Layer from "effect/Layer";
7 import { Database, DatabaseAurora } from "./Database.ts";
8 import { NetworkLive } from "./Network.ts";
9
10 export default class ServiceFunction extends AWS.Lambda.Function<ServiceFunction>()(
11 "ServiceFunction",
12 Stack.useSync((stack) => ({
13 main: import.meta.url,
14 memory: stack.stage === "prod" ? 1024 : 512,
15 runtime: "nodejs24.x",
16 })),
17 Effect.gen(function* () {
18 const db = yield* Database;
19
20 return {
21 fetch: Effect.gen(function* () {
22 const request = yield* HttpServerRequest;
23
24 if (request.method === "GET" && new URL(request.originalUrl).pathname === "/") {
25 const response = yield* db
26 .query<{
27 database: string;
28 current_time: string;
29 current_user: string;
30 }>(
31 "select current_database() as database, now()::text as current_time, current_user::text as current_user",
32 )
33 .pipe(
34 Effect.match({
35 onFailure: (error) => ({
36 status: 500 as const,
37 body: {
38 ok: false,
39 error: error.message,
40 },
41 }),
42 onSuccess: (rows) => ({
43 status: 200 as const,
44 body: {
45 ok: true,
46 connection: rows[0] ?? null,
47 },
48 }),
49 }),
50 );
51
52 return yield* HttpServerResponse.json(response.body, {
53 status: response.status,
54 });
55 }
56
57 return HttpServerResponse.text("Not found", { status: 404 });
58 }),
59 };
60 }).pipe(
61 Effect.provide(
62 Layer.provideMerge(
63 Layer.mergeAll(DatabaseAurora),
64 Layer.mergeAll(NetworkLive, AWS.RDS.ConnectHttp),
65 ),
66 ),
67 ),
68 ) {}