The best way to control Claude Code, Codex and more from any computer or phone

main
ts 98 lines 3.27 KB
Raw
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 BulkResponse,
8 IndexDocumentOptions,
9 OpenSearchApiError,
10 WriteDocumentOptions,
11 WriteDocumentResponse,
12 } from "./DataPlaneTypes.ts";
13 import type { Domain } from "./Domain.ts";
14
15 /** Runtime client for write access to a domain's REST data plane. */
16 export interface WriteDomainClient {
17 /**
18 * Index (upsert) one document — `PUT /{index}/_doc/{id}` when an id is
19 * given, `POST /{index}/_doc` (auto-generated id) otherwise.
20 */
21 indexDocument(
22 index: string,
23 document: unknown,
24 options?: IndexDocumentOptions,
25 ): Effect.Effect<
26 WriteDocumentResponse,
27 OpenSearchApiError | Credentials.CredentialsError | SourceError | SigV4.SigningError
28 >;
29 /**
30 * Partially update one document (`POST /{index}/_update/{id}`). The body
31 * is the update API's envelope, e.g. `{ doc: { plays: 42 } }`.
32 */
33 updateDocument(
34 index: string,
35 id: string,
36 body: unknown,
37 options?: WriteDocumentOptions,
38 ): Effect.Effect<
39 WriteDocumentResponse,
40 OpenSearchApiError | Credentials.CredentialsError | SourceError | SigV4.SigningError
41 >;
42 /**
43 * Delete one document (`DELETE /{index}/_doc/{id}`). Deleting a missing
44 * document is not an error — the response carries `result: "not_found"`.
45 */
46 deleteDocument(
47 index: string,
48 id: string,
49 options?: WriteDocumentOptions,
50 ): Effect.Effect<
51 WriteDocumentResponse,
52 OpenSearchApiError | Credentials.CredentialsError | SourceError | SigV4.SigningError
53 >;
54 /**
55 * Bulk-apply index/create/update/delete operations (`POST /_bulk`). Pass
56 * the action/document lines as an array — they are serialized to NDJSON.
57 */
58 bulk(
59 operations: ReadonlyArray<unknown>,
60 options?: WriteDocumentOptions,
61 ): Effect.Effect<
62 BulkResponse,
63 OpenSearchApiError | Credentials.CredentialsError | SourceError | SigV4.SigningError
64 >;
65 }
66
67 /**
68 * Runtime binding for write access to an OpenSearch {@link Domain}'s REST
69 * data plane (IAM actions `es:ESHttpPut`, `es:ESHttpPost`, `es:ESHttpDelete`
70 * and `es:ESHttpPatch` on the domain and its paths).
71 *
72 * Every request is a SigV4-signed HTTP call (service `es`) against the
73 * domain's endpoint, made with the host Function's own credentials — the
74 * domain's access policy must allow the function's role. Provide the
75 * implementation with `Effect.provide(AWS.OpenSearch.DomainWriteHttp)`.
76 * ### Writing Documents
77 * **Example:** Index and Delete Documents
78 * ```typescript
79 * // init — grants es:ESHttpPut/Post/Delete/Patch on the domain
80 * const writer = yield* AWS.OpenSearch.DomainWrite(domain);
81 *
82 * // runtime
83 * yield* writer.indexDocument(
84 * "songs",
85 * { title: "The Wind Cries Mary" },
86 * { id: "1", refresh: true },
87 * );
88 * yield* writer.deleteDocument("songs", "1", { refresh: true });
89 * ```
90 *
91 * @binding
92 */
93 export interface DomainWrite extends Binding.Service<
94 DomainWrite,
95 "AWS.OpenSearch.DomainWrite",
96 (domain: Domain) => Effect.Effect<WriteDomainClient>
97 > {}
98 export const DomainWrite = Binding.Service<DomainWrite>("AWS.OpenSearch.DomainWrite");