| 1 | import type * as Logs from "@distilled.cloud/aws/cloudwatch-logs"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { LogGroup } from "./LogGroup.ts"; |
| 5 | |
| 6 | export interface GetQueryResultsRequest extends Logs.GetQueryResultsRequest {} |
| 7 | |
| 8 | /** |
| 9 | * Runtime binding for `logs:GetQueryResults` (CloudWatch Logs Insights). |
| 10 | * |
| 11 | * Bind this operation to the `LogGroup` an Insights query was started against |
| 12 | * (via {@link import("./StartQuery.ts").StartQuery}) to poll for its results. |
| 13 | * ### Logs Insights |
| 14 | * **Example:** Poll Query Results |
| 15 | * ```typescript |
| 16 | * const getQueryResults = yield* AWS.Logs.GetQueryResults(logGroup); |
| 17 | * |
| 18 | * const response = yield* getQueryResults({ queryId }); |
| 19 | * if (response.status === "Complete") { |
| 20 | * // response.results is an array of field/value rows |
| 21 | * } |
| 22 | * ``` |
| 23 | * |
| 24 | * **Example:** Poll Until Complete |
| 25 | * ```typescript |
| 26 | * // Bounded, declarative polling — never a while-loop. |
| 27 | * const results = yield* getQueryResults({ queryId }).pipe( |
| 28 | * Effect.repeat({ |
| 29 | * schedule: Schedule.spaced("2 seconds"), |
| 30 | * until: (r) => r.status === "Complete", |
| 31 | * times: 15, |
| 32 | * }), |
| 33 | * ); |
| 34 | * ``` |
| 35 | * |
| 36 | * **Example:** Wire into a Lambda Function |
| 37 | * ```typescript |
| 38 | * // Provide the layer on the Function's init Effect, merged with |
| 39 | * // StartQueryHttp since the two bindings are always used together. |
| 40 | * export default InsightsFunction.make( |
| 41 | * { main: import.meta.url, functionUrl: true }, |
| 42 | * Effect.gen(function* () { |
| 43 | * const logGroup = yield* AWS.Logs.LogGroup("AppLogs", {}); |
| 44 | * const startQuery = yield* AWS.Logs.StartQuery(logGroup); |
| 45 | * const getQueryResults = yield* AWS.Logs.GetQueryResults(logGroup); |
| 46 | * // ... start the query and poll for results in the fetch handler |
| 47 | * return { fetch: handler }; |
| 48 | * }).pipe( |
| 49 | * Effect.provide( |
| 50 | * Layer.mergeAll(AWS.Logs.StartQueryHttp, AWS.Logs.GetQueryResultsHttp), |
| 51 | * ), |
| 52 | * ), |
| 53 | * ); |
| 54 | * ``` |
| 55 | * |
| 56 | * @binding |
| 57 | */ |
| 58 | export interface GetQueryResults extends Binding.Service< |
| 59 | GetQueryResults, |
| 60 | "AWS.Logs.GetQueryResults", |
| 61 | <G extends LogGroup>( |
| 62 | logGroup: G, |
| 63 | ) => Effect.Effect< |
| 64 | ( |
| 65 | request: GetQueryResultsRequest, |
| 66 | ) => Effect.Effect<Logs.GetQueryResultsResponse, Logs.GetQueryResultsError> |
| 67 | > |
| 68 | > {} |
| 69 | export const GetQueryResults = Binding.Service<GetQueryResults>( |
| 70 | "AWS.Logs.GetQueryResults", |
| 71 | ); |