| 1 | import type * as cloudtrail from "@distilled.cloud/aws/cloudtrail"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { EventDataStore } from "./EventDataStore.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Request for the {@link StartQuery} binding. CloudTrail Lake SQL references |
| 8 | * the event data store by its ID (the ARN's `eventdatastore/` suffix) in the |
| 9 | * `FROM` clause, so `QueryStatement` may be a function that receives the |
| 10 | * bound store's ID and returns the SQL text. |
| 11 | */ |
| 12 | export interface StartQueryRequest extends Omit< |
| 13 | cloudtrail.StartQueryRequest, |
| 14 | "QueryStatement" |
| 15 | > { |
| 16 | /** |
| 17 | * The SQL statement, or a function producing it from the bound event data |
| 18 | * store's ID (for the `FROM <eventDataStoreId>` clause). |
| 19 | */ |
| 20 | QueryStatement: string | ((eventDataStoreId: string) => string); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Runtime binding for `cloudtrail:StartQuery`. |
| 25 | * |
| 26 | * Starts a CloudTrail Lake SQL query against the bound |
| 27 | * {@link EventDataStore} and returns the `QueryId` to poll with |
| 28 | * {@link DescribeQuery} / {@link GetQueryResults}. Provide the implementation |
| 29 | * with `Effect.provide(AWS.CloudTrail.StartQueryHttp)`. |
| 30 | * ### Querying CloudTrail Lake |
| 31 | * **Example:** Start a Lake Query |
| 32 | * ```typescript |
| 33 | * // init — bind the operation to the event data store |
| 34 | * const startQuery = yield* AWS.CloudTrail.StartQuery(store); |
| 35 | * |
| 36 | * // runtime — the callback receives the store's ID for the FROM clause |
| 37 | * const { QueryId } = yield* startQuery({ |
| 38 | * QueryStatement: (id) => |
| 39 | * `SELECT eventID, eventName FROM ${id} LIMIT 10`, |
| 40 | * }); |
| 41 | * ``` |
| 42 | * |
| 43 | * @binding |
| 44 | */ |
| 45 | export interface StartQuery extends Binding.Service< |
| 46 | StartQuery, |
| 47 | "AWS.CloudTrail.StartQuery", |
| 48 | ( |
| 49 | store: EventDataStore, |
| 50 | ) => Effect.Effect< |
| 51 | ( |
| 52 | request: StartQueryRequest, |
| 53 | ) => Effect.Effect< |
| 54 | cloudtrail.StartQueryResponse, |
| 55 | cloudtrail.StartQueryError |
| 56 | > |
| 57 | > |
| 58 | > {} |
| 59 | export const StartQuery = Binding.Service<StartQuery>( |
| 60 | "AWS.CloudTrail.StartQuery", |
| 61 | ); |