The best way to control Claude Code, Codex and more from any computer or phone

main
ts 84 lines 2.88 KB
Raw
1 import type * as keyspacesstreams from "@distilled.cloud/aws/keyspacesstreams";
2 import * as Binding from "alchemy/Binding";
3 import type * as Effect from "effect/Effect";
4 import type { Table } from "./Table.ts";
5
6 export interface ListTableStreamsRequest extends Omit<
7 keyspacesstreams.ListStreamsInput,
8 "keyspaceName" | "tableName"
9 > {}
10
11 /**
12 * The typed client returned by binding {@link TableStreams} to a `Table`.
13 * `listStreams` automatically injects the table's keyspace and table name;
14 * the remaining operations traverse a stream by ARN / shard iterator
15 * obtained from prior calls.
16 */
17 export interface TableStreamsClient {
18 /**
19 * List the CDC streams of the bound table (the stream with the greatest
20 * `streamLabel` is the current one — also exposed as the table's
21 * `latestStreamArn` attribute).
22 */
23 listStreams: (
24 request?: ListTableStreamsRequest,
25 ) => Effect.Effect<keyspacesstreams.ListStreamsOutput, keyspacesstreams.ListStreamsError>;
26 /**
27 * Describe a stream: status, view type, retention, and shard composition.
28 */
29 getStream: (
30 request: keyspacesstreams.GetStreamInput,
31 ) => Effect.Effect<keyspacesstreams.GetStreamOutput, keyspacesstreams.GetStreamError>;
32 /**
33 * Obtain an iterator positioned in a shard (`TRIM_HORIZON`, `LATEST`,
34 * `AT_SEQUENCE_NUMBER`, or `AFTER_SEQUENCE_NUMBER`).
35 */
36 getShardIterator: (
37 request: keyspacesstreams.GetShardIteratorInput,
38 ) => Effect.Effect<
39 keyspacesstreams.GetShardIteratorOutput,
40 keyspacesstreams.GetShardIteratorError
41 >;
42 /**
43 * Read change records from a shard iterator.
44 */
45 getRecords: (
46 request: keyspacesstreams.GetRecordsInput,
47 ) => Effect.Effect<keyspacesstreams.GetRecordsOutput, keyspacesstreams.GetRecordsError>;
48 }
49
50 /**
51 * Runtime binding for the Amazon Keyspaces CDC streams data-plane API
52 * (`cassandra:ListStreams` / `GetStream` / `GetShardIterator` /
53 * `GetRecords`).
54 *
55 * Bind this to a `Table` whose `cdcSpecification` is enabled to get a typed
56 * client for traversing the table's change-data-capture stream.
57 * ### Reading Change Data
58 * **Example:** Traverse the Latest Stream
59 * ```typescript
60 * const streams = yield* AWS.Keyspaces.TableStreams(table);
61 *
62 * const { streams: available } = yield* streams.listStreams();
63 * const streamArn = available![0].streamArn;
64 *
65 * const stream = yield* streams.getStream({ streamArn });
66 * const { shardIterator } = yield* streams.getShardIterator({
67 * streamArn,
68 * shardId: stream.shards![0].shardId!,
69 * shardIteratorType: "TRIM_HORIZON",
70 * });
71 *
72 * const { changeRecords } = yield* streams.getRecords({
73 * shardIterator: shardIterator!,
74 * });
75 * ```
76 *
77 * @binding
78 */
79 export interface TableStreams extends Binding.Service<
80 TableStreams,
81 "AWS.Keyspaces.TableStreams",
82 <T extends Table>(table: T) => Effect.Effect<TableStreamsClient>
83 > {}
84 export const TableStreams = Binding.Service<TableStreams>("AWS.Keyspaces.TableStreams");