| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Binding from "../../Binding.ts"; |
| 3 | import type { RuntimeContext } from "../../RuntimeContext.ts"; |
| 4 | import type { Namespace } from "./Namespace.ts"; |
| 5 | import type { NamespaceError } from "./NamespaceTypes.ts"; |
| 6 | |
| 7 | /** |
| 8 | * Bind a {@link Namespace} to a Worker with write access and obtain the |
| 9 | * Effect-native KV client (`put`, `delete`). |
| 10 | * |
| 11 | * `WriteNamespace` is a single identifier that is simultaneously the binding's |
| 12 | * Context tag, its type, and the callable — |
| 13 | * `yield* Cloudflare.KV.WriteNamespace(ns)`. |
| 14 | * |
| 15 | * @binding |
| 16 | * @product KV |
| 17 | * @category Storage & Databases |
| 18 | */ |
| 19 | export interface WriteNamespace extends Binding.Service< |
| 20 | WriteNamespace, |
| 21 | "Cloudflare.KV.WriteNamespace", |
| 22 | (namespace: Namespace) => Effect.Effect<WriteNamespaceClient> |
| 23 | > {} |
| 24 | |
| 25 | export const WriteNamespace = Binding.Service<WriteNamespace>( |
| 26 | "Cloudflare.KV.WriteNamespace", |
| 27 | ); |
| 28 | |
| 29 | export interface WriteNamespaceClient<Key extends string = string> { |
| 30 | put( |
| 31 | key: Key, |
| 32 | value: string | ArrayBuffer | ArrayBufferView | ReadableStream, |
| 33 | options?: KVNamespacePutOptions, |
| 34 | ): Effect.Effect<void, NamespaceError, RuntimeContext>; |
| 35 | delete(key: Key): Effect.Effect<void, NamespaceError, RuntimeContext>; |
| 36 | } |