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, 04:45 UTC
| 1 | import type * as Credentials from "@distilled.cloud/aws/Credentials"; |
| 2 | import type * as SigV4 from "@distilled.cloud/aws/SigV4"; |
| 3 | import * as Binding from "alchemy/Binding"; |
| 4 | import type { SourceError } from "effect/ConfigProvider"; |
| 5 | import type * as Effect from "effect/Effect"; |
| 6 | import type { |
| 7 | CountRequest, |
| 8 | CountResponse, |
| 9 | GetDocumentResponse, |
| 10 | OpenSearchApiError, |
| 11 | SearchRequest, |
| 12 | SearchResponse, |
| 13 | } from "./DataPlaneTypes.ts"; |
| 14 | import type { Domain } from "./Domain.ts"; |
| 15 | |
| 16 | /** Runtime client for read-only access to a domain's REST data plane. */ |
| 17 | export interface ReadDomainClient { |
| 18 | /** |
| 19 | * Run a Query-DSL search (`GET …/_search`). The body travels in the |
| 20 | * `source` query parameter so the request stays on `es:ESHttpGet` — no |
| 21 | * write-method IAM action is required to search. |
| 22 | */ |
| 23 | search<TDoc = unknown>( |
| 24 | request?: SearchRequest, |
| 25 | ): Effect.Effect< |
| 26 | SearchResponse<TDoc>, |
| 27 | OpenSearchApiError | Credentials.CredentialsError | SourceError | SigV4.SigningError |
| 28 | >; |
| 29 | /** Count documents matching a Query-DSL body (`GET …/_count`). */ |
| 30 | count( |
| 31 | request?: CountRequest, |
| 32 | ): Effect.Effect< |
| 33 | CountResponse, |
| 34 | OpenSearchApiError | Credentials.CredentialsError | SourceError | SigV4.SigningError |
| 35 | >; |
| 36 | /** |
| 37 | * Fetch one document by id (`GET /{index}/_doc/{id}`). A missing document |
| 38 | * is not an error — the response carries `found: false`. |
| 39 | */ |
| 40 | getDocument<TDoc = unknown>( |
| 41 | index: string, |
| 42 | id: string, |
| 43 | ): Effect.Effect< |
| 44 | GetDocumentResponse<TDoc>, |
| 45 | OpenSearchApiError | Credentials.CredentialsError | SourceError | SigV4.SigningError |
| 46 | >; |
| 47 | /** Check whether a document exists (`HEAD /{index}/_doc/{id}`). */ |
| 48 | existsDocument( |
| 49 | index: string, |
| 50 | id: string, |
| 51 | ): Effect.Effect< |
| 52 | boolean, |
| 53 | OpenSearchApiError | Credentials.CredentialsError | SourceError | SigV4.SigningError |
| 54 | >; |
| 55 | /** |
| 56 | * Raw read-only escape hatch — a SigV4-signed `GET` against any data-plane |
| 57 | * path (e.g. `_cluster/health`, `_cat/indices?format=json`). |
| 58 | */ |
| 59 | get( |
| 60 | path: string, |
| 61 | query?: Record<string, string | undefined>, |
| 62 | ): Effect.Effect< |
| 63 | unknown, |
| 64 | OpenSearchApiError | Credentials.CredentialsError | SourceError | SigV4.SigningError |
| 65 | >; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Runtime binding for read-only access to an OpenSearch {@link Domain}'s |
| 70 | * REST data plane (IAM actions `es:ESHttpGet` and `es:ESHttpHead` on the |
| 71 | * domain and its paths). |
| 72 | * |
| 73 | * Every request is a SigV4-signed HTTP call (service `es`) against the |
| 74 | * domain's endpoint, made with the host Function's own credentials — the |
| 75 | * domain's access policy must allow the function's role. Provide the |
| 76 | * implementation with `Effect.provide(AWS.OpenSearch.DomainReadHttp)`. |
| 77 | * ### Searching a Domain |
| 78 | * **Example:** Search Documents |
| 79 | * ```typescript |
| 80 | * // init — grants es:ESHttpGet/es:ESHttpHead on the domain |
| 81 | * const search = yield* AWS.OpenSearch.DomainRead(domain); |
| 82 | * |
| 83 | * // runtime |
| 84 | * const result = yield* search.search<{ title: string }>({ |
| 85 | * index: "songs", |
| 86 | * body: { query: { match: { title: "wind" } } }, |
| 87 | * }); |
| 88 | * const titles = result.hits.hits.map((hit) => hit._source.title); |
| 89 | * ``` |
| 90 | * |
| 91 | * **Example:** Fetch One Document |
| 92 | * ```typescript |
| 93 | * const doc = yield* search.getDocument<{ title: string }>("songs", "1"); |
| 94 | * if (doc.found) yield* Effect.log(doc._source?.title); |
| 95 | * ``` |
| 96 | * |
| 97 | * @binding |
| 98 | */ |
| 99 | export interface DomainRead extends Binding.Service< |
| 100 | DomainRead, |
| 101 | "AWS.OpenSearch.DomainRead", |
| 102 | (domain: Domain) => Effect.Effect<ReadDomainClient> |
| 103 | > {} |
| 104 | export const DomainRead = Binding.Service<DomainRead>("AWS.OpenSearch.DomainRead"); |