@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 120 lines 4.81 KB
Raw
1 import * as Binding from "alchemy/Binding";
2 import type { RuntimeContext } from "alchemy/RuntimeContext";
3 import type * as Effect from "effect/Effect";
4 import { connectEnvPrefix as makeConnectEnvPrefix } from "../Connection/internal.ts";
5 import type { Cluster } from "./Cluster.ts";
6
7 /**
8 * Connection descriptor for a DAX cluster. Alchemy does not bundle a DAX
9 * client — pass these settings to the DAX SDK client of your choice
10 * (`amazon-dax-client`, `@amazon-dax-sdk/lib-dax`, ...), which speaks the
11 * DynamoDB-compatible DAX protocol against the cluster's discovery endpoint.
12 */
13 export interface ClusterConnectionInfo {
14 /** Discovery endpoint hostname. */
15 host: string;
16 /** Discovery endpoint port (8111 unencrypted, 9111 for TLS). */
17 port: number;
18 /**
19 * Full `dax://` (or `daxs://` for TLS) discovery endpoint URL — the value
20 * DAX SDK clients accept directly.
21 */
22 url: string;
23 /** Whether the cluster endpoint requires encryption in transit (TLS). */
24 tls: boolean;
25 }
26
27 /**
28 * Environment variable prefix under which the connect bindings publish the
29 * cluster endpoint on the host Function, derived from the cluster's logical
30 * ID. A cluster with logical ID `Cache` yields `DAX_CACHE` and the variables
31 * `DAX_CACHE_HOST`, `DAX_CACHE_PORT`, `DAX_CACHE_URL`, and `DAX_CACHE_TLS`.
32 */
33 export const connectEnvPrefix = (logicalId: string): string =>
34 makeConnectEnvPrefix("DAX", logicalId);
35
36 /**
37 * Read-only runtime access to a DAX {@link Cluster}'s data plane.
38 *
39 * Grants the read-side DAX IAM actions (`dax:GetItem`, `dax:BatchGetItem`,
40 * `dax:Query`, `dax:Scan`, plus the protocol actions every DAX client
41 * needs) on the cluster ARN, publishes the discovery endpoint as environment
42 * variables on the host Function, and resolves a typed
43 * {@link ClusterConnectionInfo} at runtime.
44 *
45 * The DAX data plane is VPC-only — the host Function must be attached to the
46 * cluster's VPC and allowed ingress by the cluster's security groups.
47 * Provide the implementation with `Effect.provide(AWS.DAX.ConnectReadHttp)`.
48 * ### Connecting to a Cluster
49 * **Example:** Resolve Read-Only Connection Info inside a Function
50 * ```typescript
51 * const connect = yield* DAX.ConnectRead(cluster);
52 * // inside a handler:
53 * const { url, tls } = yield* connect;
54 * ```
55 *
56 * @binding
57 */
58 export interface ConnectRead extends Binding.Service<
59 ConnectRead,
60 "AWS.DAX.ConnectRead",
61 (cluster: Cluster) => Effect.Effect<Effect.Effect<ClusterConnectionInfo, never, RuntimeContext>>
62 > {}
63 export const ConnectRead = Binding.Service<ConnectRead>("AWS.DAX.ConnectRead");
64
65 /**
66 * Write-only runtime access to a DAX {@link Cluster}'s data plane.
67 *
68 * Grants the write-side DAX IAM actions (`dax:PutItem`, `dax:UpdateItem`,
69 * `dax:DeleteItem`, `dax:BatchWriteItem`, `dax:ConditionCheckItem`, plus the
70 * protocol actions every DAX client needs) on the cluster ARN, publishes the
71 * discovery endpoint as environment variables on the host Function, and
72 * resolves a typed {@link ClusterConnectionInfo} at runtime.
73 *
74 * The DAX data plane is VPC-only — the host Function must be attached to the
75 * cluster's VPC and allowed ingress by the cluster's security groups.
76 * Provide the implementation with `Effect.provide(AWS.DAX.ConnectWriteHttp)`.
77 * ### Connecting to a Cluster
78 * **Example:** Resolve Write-Only Connection Info inside a Function
79 * ```typescript
80 * const connect = yield* DAX.ConnectWrite(cluster);
81 * // inside a handler:
82 * const { url } = yield* connect;
83 * ```
84 *
85 * @binding
86 */
87 export interface ConnectWrite extends Binding.Service<
88 ConnectWrite,
89 "AWS.DAX.ConnectWrite",
90 (cluster: Cluster) => Effect.Effect<Effect.Effect<ClusterConnectionInfo, never, RuntimeContext>>
91 > {}
92 export const ConnectWrite = Binding.Service<ConnectWrite>("AWS.DAX.ConnectWrite");
93
94 /**
95 * Full read-write runtime access to a DAX {@link Cluster}'s data plane.
96 *
97 * Grants both the read- and write-side DAX IAM actions on the cluster ARN,
98 * publishes the discovery endpoint as environment variables on the host
99 * Function, and resolves a typed {@link ClusterConnectionInfo} at runtime.
100 *
101 * The DAX data plane is VPC-only — the host Function must be attached to the
102 * cluster's VPC and allowed ingress by the cluster's security groups.
103 * Provide the implementation with
104 * `Effect.provide(AWS.DAX.ConnectReadWriteHttp)`.
105 * ### Connecting to a Cluster
106 * **Example:** Resolve Connection Info inside a Function
107 * ```typescript
108 * const connect = yield* DAX.ConnectReadWrite(cluster);
109 * // inside a handler:
110 * const { host, port, url, tls } = yield* connect;
111 * ```
112 *
113 * @binding
114 */
115 export interface ConnectReadWrite extends Binding.Service<
116 ConnectReadWrite,
117 "AWS.DAX.ConnectReadWrite",
118 (cluster: Cluster) => Effect.Effect<Effect.Effect<ClusterConnectionInfo, never, RuntimeContext>>
119 > {}
120 export const ConnectReadWrite = Binding.Service<ConnectReadWrite>("AWS.DAX.ConnectReadWrite");