| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Binding from "../../Binding.ts"; |
| 3 | import type { Namespace } from "./Namespace.ts"; |
| 4 | import type { ReadNamespaceClient } from "./ReadNamespace.ts"; |
| 5 | import type { WriteNamespaceClient } from "./WriteNamespace.ts"; |
| 6 | |
| 7 | /** |
| 8 | * Bind a {@link Namespace} to a Worker with read + write access and obtain |
| 9 | * the Effect-native KV client (`get`, `getWithMetadata`, `list`, `put`, |
| 10 | * `delete`). |
| 11 | * |
| 12 | * `ReadWriteNamespace` is a single identifier that is simultaneously the |
| 13 | * binding's Context tag, its type, and the callable — |
| 14 | * `yield* Cloudflare.KV.ReadWriteNamespace(ns)`. |
| 15 | * |
| 16 | * @binding |
| 17 | * @product KV |
| 18 | * @category Storage & Databases |
| 19 | */ |
| 20 | export interface ReadWriteNamespace extends Binding.Service< |
| 21 | ReadWriteNamespace, |
| 22 | "Cloudflare.KVNamespace.ReadWrite", |
| 23 | (namespace: Namespace) => Effect.Effect<ReadWriteNamespaceClient> |
| 24 | > {} |
| 25 | |
| 26 | export const ReadWriteNamespace = Binding.Service<ReadWriteNamespace>( |
| 27 | "Cloudflare.KVNamespace.ReadWrite", |
| 28 | ); |
| 29 | |
| 30 | export interface ReadWriteNamespaceClient<Key extends string = string> |
| 31 | extends ReadNamespaceClient<Key>, WriteNamespaceClient<Key> {} |