@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 59 lines 2.09 KB
Raw
1 import * as Output from "alchemy/Output";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as AWSBindings from "../AWSBindings.ts";
5 import { Connect, connectEnvPrefix } from "./Connect.ts";
6 import type { ServerlessCache } from "./ServerlessCache.ts";
7
8 /**
9 * Environment-only implementation of {@link Connect}. At deploy time it
10 * publishes the cache endpoint as `ELASTICACHE_{LOGICAL_ID}_{HOST,PORT,TLS}`
11 * environment variables on the host Function; at runtime it resolves the
12 * same values into a typed connection descriptor. No IAM policy is attached
13 * — the classic valkey/redis/memcached data plane is governed by VPC
14 * security groups, not IAM.
15 */
16 export const ConnectHttp = Layer.effect(
17 Connect,
18 Effect.gen(function* () {
19 const bind = yield* AWSBindings.Bind;
20 return Effect.fn(function* (cache: ServerlessCache) {
21 const Host = yield* cache.endpointAddress;
22 const Port = yield* cache.endpointPort;
23 const ReaderHost = yield* cache.readerEndpointAddress;
24 const ReaderPort = yield* cache.readerEndpointPort;
25
26 if (!globalThis.__ALCHEMY_RUNTIME__) {
27 const prefix = connectEnvPrefix(cache.LogicalId);
28 yield* bind`AWS.ElastiCache.Connect(${cache})`({
29 env: {
30 [`${prefix}_HOST`]: cache.endpointAddress,
31 // Lambda environment variables are strings — stringify the port.
32 [`${prefix}_PORT`]: Output.interpolate`${cache.endpointPort}`,
33 // Serverless caches are TLS-only.
34 [`${prefix}_TLS`]: "true",
35 },
36 });
37 }
38
39 return Effect.gen(function* () {
40 const host = yield* Host;
41 const port = yield* Port;
42 const readerHost = yield* ReaderHost;
43 const readerPort = yield* ReaderPort;
44 if (!host || port === undefined) {
45 return yield* Effect.die(
46 `ElastiCache endpoint for '${cache.LogicalId}' is not available yet`,
47 );
48 }
49 return {
50 host,
51 port,
52 readerHost,
53 readerPort,
54 tls: true,
55 };
56 });
57 });
58 }),
59 );