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

main
ts 28 lines 1.1 KB
Raw
1 import type * as runtime from "@cloudflare/workers-types";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import { makeKVNamespaceBinding, makeKVNamespaceHelpers } from "./NamespaceBinding.ts";
5 import { ReadNamespace, type ReadNamespaceClient } from "./ReadNamespace.ts";
6
7 /**
8 * Implementation of the {@link ReadNamespace} binding that uses a Worker
9 * binding.
10 */
11 export const ReadNamespaceBinding = Layer.effect(
12 ReadNamespace,
13 Effect.suspend(() => makeKVNamespaceBinding({ makeClient: makeReadKVClient })),
14 );
15
16 /** Build the read half of the binding client. */
17 export const makeReadKVClient = ({
18 raw,
19 use,
20 }: ReturnType<typeof makeKVNamespaceHelpers>): ReadNamespaceClient => ({
21 raw,
22 get: ((...args: Parameters<runtime.KVNamespace["get"]>) =>
23 use((raw) => raw.get(...(args as [any, any])))) as any,
24 getWithMetadata: ((...args: Parameters<runtime.KVNamespace["getWithMetadata"]>) =>
25 use((raw) => raw.getWithMetadata(...(args as [any, any])))) as any,
26 list: ((...args: Parameters<runtime.KVNamespace["list"]>) =>
27 use((raw) => raw.list(...args))) as any,
28 });