1import type * as Effect from "effect/Effect";
2import * as Binding from "../../Binding.ts";
3import type { RuntimeContext } from "../../RuntimeContext.ts";
4import { connectEnvPrefix as makeConnectEnvPrefix } from "../Connection/internal.ts";
5import 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 */
13export 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 */
33export 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 */
58export interface ConnectRead extends Binding.Service<
59 ConnectRead,
60 "AWS.DAX.ConnectRead",
61 (
62 cluster: Cluster,
63 ) => Effect.Effect<
64 Effect.Effect<ClusterConnectionInfo, never, RuntimeContext>
65 >
66> {}
67export const ConnectRead = Binding.Service<ConnectRead>("AWS.DAX.ConnectRead");
68
69/**
70 * Write-only runtime access to a DAX {@link Cluster}'s data plane.
71 *
72 * Grants the write-side DAX IAM actions (`dax:PutItem`, `dax:UpdateItem`,
73 * `dax:DeleteItem`, `dax:BatchWriteItem`, `dax:ConditionCheckItem`, plus the
74 * protocol actions every DAX client needs) on the cluster ARN, publishes the
75 * discovery endpoint as environment variables on the host Function, and
76 * resolves a typed {@link ClusterConnectionInfo} at runtime.
77 *
78 * The DAX data plane is VPC-only — the host Function must be attached to the
79 * cluster's VPC and allowed ingress by the cluster's security groups.
80 * Provide the implementation with `Effect.provide(AWS.DAX.ConnectWriteHttp)`.
81 * ### Connecting to a Cluster
82 * **Example:** Resolve Write-Only Connection Info inside a Function
83 * ```typescript
84 * const connect = yield* DAX.ConnectWrite(cluster);
85 * // inside a handler:
86 * const { url } = yield* connect;
87 * ```
88 *
89 * @binding
90 */
91export interface ConnectWrite extends Binding.Service<
92 ConnectWrite,
93 "AWS.DAX.ConnectWrite",
94 (
95 cluster: Cluster,
96 ) => Effect.Effect<
97 Effect.Effect<ClusterConnectionInfo, never, RuntimeContext>
98 >
99> {}
100export const ConnectWrite = Binding.Service<ConnectWrite>(
101 "AWS.DAX.ConnectWrite",
102);
103
104/**
105 * Full read-write runtime access to a DAX {@link Cluster}'s data plane.
106 *
107 * Grants both the read- and write-side DAX IAM actions on the cluster ARN,
108 * publishes the discovery endpoint as environment variables on the host
109 * Function, and resolves a typed {@link ClusterConnectionInfo} at runtime.
110 *
111 * The DAX data plane is VPC-only — the host Function must be attached to the
112 * cluster's VPC and allowed ingress by the cluster's security groups.
113 * Provide the implementation with
114 * `Effect.provide(AWS.DAX.ConnectReadWriteHttp)`.
115 * ### Connecting to a Cluster
116 * **Example:** Resolve Connection Info inside a Function
117 * ```typescript
118 * const connect = yield* DAX.ConnectReadWrite(cluster);
119 * // inside a handler:
120 * const { host, port, url, tls } = yield* connect;
121 * ```
122 *
123 * @binding
124 */
125export interface ConnectReadWrite extends Binding.Service<
126 ConnectReadWrite,
127 "AWS.DAX.ConnectReadWrite",
128 (
129 cluster: Cluster,
130 ) => Effect.Effect<
131 Effect.Effect<ClusterConnectionInfo, never, RuntimeContext>
132 >
133> {}
134export const ConnectReadWrite = Binding.Service<ConnectReadWrite>(
135 "AWS.DAX.ConnectReadWrite",
136);