@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 77 lines 2.65 KB
Raw
1 import type * as TSW from "@distilled.cloud/aws/timestream-write";
2 import * as Binding from "alchemy/Binding";
3 import type { BatchRetryExhaustedError } from "alchemy/Util/BatchedSink";
4 import type * as Effect from "effect/Effect";
5 import type * as Sink from "effect/Sink";
6 import type { Table } from "./Table.ts";
7
8 /**
9 * A raw distilled Timestream `Record`. Callers stay in control of
10 * `Dimensions`, `MeasureName`, `Time`, `Version`, etc. — the sink performs no
11 * auto-marshalling.
12 */
13 export type RecordsSinkRecord = TSW.Record;
14
15 export interface RecordsSinkProps {
16 /**
17 * Attributes shared by every record written through this sink (dimensions,
18 * measure name, time defaults, version). Sent as `CommonAttributes` on each
19 * `WriteRecords` call; Timestream merges them into every record server-side.
20 */
21 readonly commonAttributes?: TSW.Record;
22 }
23
24 export type RecordsSinkError =
25 | Exclude<TSW.WriteRecordsError | TSW.DescribeEndpointsError, TSW.RejectedRecordsException>
26 | BatchRetryExhaustedError<RecordsSinkRecord>;
27
28 /**
29 * A batching sink over Timestream `WriteRecords` (100 records per call).
30 *
31 * Timestream ingests the valid subset of each batch and reports invalid
32 * records positionally via `RejectedRecordsException` (schema conflicts,
33 * timestamps outside the retention window, version conflicts). Rejections are
34 * **permanent** — the sink drops them (surfacing a warning with the rejected
35 * count) and keeps draining; there is no transient per-record failure mode to
36 * retry.
37 *
38 * Provide `Timestream.RecordsSinkHttp` on the Function to implement the
39 * binding.
40 *
41 * ### Streaming Records
42 * **Example:** Stream records into a table
43 * ```typescript
44 * // init — bind the sink to the table; shared attributes are sent once per
45 * // batch as CommonAttributes and merged into every record server-side
46 * const sink = yield* Timestream.RecordsSink(table, {
47 * commonAttributes: {
48 * MeasureName: "cpu",
49 * MeasureValueType: "DOUBLE",
50 * TimeUnit: "MILLISECONDS",
51 * },
52 * });
53 *
54 * // runtime — drain a stream through the sink (batched 100 records/call)
55 * yield* Stream.fromIterable(
56 * samples.map((s) => ({
57 * Dimensions: [{ Name: "host", Value: s.host }],
58 * MeasureValue: `${s.value}`,
59 * Time: `${s.time}`,
60 * })),
61 * ).pipe(Stream.run(sink));
62 * ```
63 *
64 * @binding
65 */
66 export interface RecordsSink extends Binding.Service<
67 RecordsSink,
68 "AWS.Timestream.RecordsSink",
69 (
70 table: Table,
71 props?: RecordsSinkProps,
72 ) => Effect.Effect<
73 Sink.Sink<void, RecordsSinkRecord, readonly RecordsSinkRecord[], RecordsSinkError>
74 >
75 > {}
76
77 export const RecordsSink = Binding.Service<RecordsSink>("AWS.Timestream.RecordsSink");