| 1 | import type * as TSW from "@distilled.cloud/aws/timestream-write"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Table } from "./Table.ts"; |
| 5 | |
| 6 | export interface WriteRecordsRequest extends Omit< |
| 7 | TSW.WriteRecordsRequest, |
| 8 | "DatabaseName" | "TableName" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Runtime binding for `timestream-write:WriteRecords` — ingest time-series |
| 13 | * records into a Timestream {@link Table}. |
| 14 | * |
| 15 | * Bind the operation to a table inside a function runtime to get a callable |
| 16 | * with `DatabaseName` and `TableName` injected automatically; you only supply |
| 17 | * the `Records` (and optional `CommonAttributes`). For high-volume streaming |
| 18 | * ingestion prefer the batching {@link RecordsSink}. |
| 19 | * |
| 20 | * Provide `Timestream.WriteRecordsHttp` on the Function to implement the |
| 21 | * binding. |
| 22 | * |
| 23 | * ### Writing Records |
| 24 | * **Example:** Write a measurement |
| 25 | * ```typescript |
| 26 | * // init — bind the operation to the table |
| 27 | * const writeRecords = yield* Timestream.WriteRecords(table); |
| 28 | * |
| 29 | * // runtime — ingest a record |
| 30 | * const result = yield* writeRecords({ |
| 31 | * Records: [ |
| 32 | * { |
| 33 | * Dimensions: [{ Name: "host", Value: "web-1" }], |
| 34 | * MeasureName: "cpu", |
| 35 | * MeasureValue: "42.5", |
| 36 | * MeasureValueType: "DOUBLE", |
| 37 | * Time: `${Date.now()}`, |
| 38 | * TimeUnit: "MILLISECONDS", |
| 39 | * }, |
| 40 | * ], |
| 41 | * }); |
| 42 | * // result.RecordsIngested reports how many records landed |
| 43 | * ``` |
| 44 | * |
| 45 | * @binding |
| 46 | */ |
| 47 | export interface WriteRecords extends Binding.Service< |
| 48 | WriteRecords, |
| 49 | "AWS.Timestream.WriteRecords", |
| 50 | ( |
| 51 | table: Table, |
| 52 | ) => Effect.Effect< |
| 53 | ( |
| 54 | request: WriteRecordsRequest, |
| 55 | ) => Effect.Effect< |
| 56 | TSW.WriteRecordsResponse, |
| 57 | TSW.WriteRecordsError | TSW.DescribeEndpointsError |
| 58 | > |
| 59 | > |
| 60 | > {} |
| 61 | |
| 62 | export const WriteRecords = Binding.Service<WriteRecords>( |
| 63 | "AWS.Timestream.WriteRecords", |
| 64 | ); |