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