The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Binding from "alchemy/Binding"; |
| 2 | import type { Input } from "alchemy/Input"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import type { InstantNamespace } from "./InstantNamespace.ts"; |
| 5 | import type { ReadWriteInstantNamespaceClient } from "./InstantNamespaceTypes.ts"; |
| 6 | import type { Namespace } from "./Namespace.ts"; |
| 7 | import type { ReadNamespaceClient } from "./ReadNamespace.ts"; |
| 8 | import type { WriteNamespaceClient } from "./WriteNamespace.ts"; |
| 9 | |
| 10 | /** |
| 11 | * Bind a {@link Namespace} to a Worker with read + write access and obtain |
| 12 | * the Effect-native KV client (`get`, `getWithMetadata`, `list`, `put`, |
| 13 | * `delete`). |
| 14 | * |
| 15 | * `ReadWriteNamespace` is a single identifier that is simultaneously the |
| 16 | * binding's Context tag, its type, and the callable — |
| 17 | * `yield* Cloudflare.KV.ReadWriteNamespace(ns)`. |
| 18 | * |
| 19 | * Also accepts InstantNamespace, returning a client without metadata or |
| 20 | * paginated listing options. |
| 21 | * |
| 22 | * @binding |
| 23 | * @product KV |
| 24 | * @category Storage & Databases |
| 25 | */ |
| 26 | export interface ReadWriteNamespace extends Binding.Service< |
| 27 | ReadWriteNamespace, |
| 28 | "Cloudflare.KVNamespace.ReadWrite", |
| 29 | { |
| 30 | (namespace: InstantNamespace): Effect.Effect<ReadWriteInstantNamespaceClient>; |
| 31 | (namespace: Namespace): Effect.Effect<ReadWriteNamespaceClient>; |
| 32 | (namespace: Namespace | InstantNamespace): Effect.Effect<ReadWriteInstantNamespaceClient>; |
| 33 | } |
| 34 | > { |
| 35 | <Req = never>( |
| 36 | namespace: Input<Namespace> | Effect.Effect<Namespace, never, Req>, |
| 37 | ): Effect.Effect<ReadWriteNamespaceClient, never, ReadWriteNamespace | Req>; |
| 38 | <Req = never>( |
| 39 | namespace: |
| 40 | | Input<Namespace | InstantNamespace> |
| 41 | | Effect.Effect<Namespace | InstantNamespace, never, Req>, |
| 42 | ): Effect.Effect<ReadWriteInstantNamespaceClient, never, ReadWriteNamespace | Req>; |
| 43 | } |
| 44 | |
| 45 | export const ReadWriteNamespace = Binding.Service<ReadWriteNamespace>( |
| 46 | "Cloudflare.KVNamespace.ReadWrite", |
| 47 | ); |
| 48 | |
| 49 | export interface ReadWriteNamespaceClient<Key extends string = string> |
| 50 | extends ReadNamespaceClient<Key>, WriteNamespaceClient<Key> {} |