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

main
ts 82 lines 2.7 KB
Raw
1 import type * as runtime from "@cloudflare/workers-types";
2 import * as Binding from "alchemy/Binding";
3 import type { RuntimeContext } from "alchemy/RuntimeContext";
4 import * as Effect from "effect/Effect";
5 import * as Redacted from "effect/Redacted";
6 import type { Connection } from "./Connection.ts";
7 import type { ConnectionLookup } from "./ConnectionLookup.ts";
8
9 /**
10 * A typed accessor for a Cloudflare Hyperdrive runtime binding inside a
11 * Worker. Provides the same shape as the raw `Hyperdrive` runtime object
12 * (connection string, host, port, user, password, database) plus a `raw`
13 * escape hatch for libraries that want direct access.
14 *
15 * **Example:** Bind Hyperdrive in a Worker
16 * ```typescript
17 * const hd = yield* Cloudflare.Hyperdrive.Connect(MyConnection);
18 * const url = yield* hd.connectionString;
19 * ```
20 *
21 * @binding
22 * @product Hyperdrive
23 * @category Storage & Databases
24 */
25 /**
26 * Bind a {@link Connection} (or an existing configuration from
27 * {@link lookup}) to a Worker and obtain the Effect-native
28 * Hyperdrive client (connection string, host, port, …).
29 *
30 * `Connect` is a single identifier that is simultaneously the binding's Context
31 * tag, its type, and the callable — `yield* Cloudflare.Hyperdrive.Connect(conn)`.
32 *
33 * **Example:** Using Hyperdrive inside a Worker
34 * ```typescript
35 * const hd = yield* Cloudflare.Hyperdrive.Connect(MyConnection);
36 * const url = yield* hd.connectionString;
37 * ```
38 *
39 * @binding
40 * @product Hyperdrive
41 * @category Storage & Databases
42 */
43 export interface Connect extends Binding.Service<
44 Connect,
45 "Cloudflare.Hyperdrive.Connect",
46 (connection: Connection | ConnectionLookup) => Effect.Effect<ConnectClient>
47 > {}
48
49 export const Connect = Binding.Service<Connect>("Cloudflare.Hyperdrive.Connect");
50
51 export interface ConnectClient {
52 /**
53 * The raw runtime `Hyperdrive` binding. Use this when integrating with a
54 * driver that wants direct access to the Cloudflare object.
55 */
56 raw: Effect.Effect<runtime.Hyperdrive, never, RuntimeContext>;
57 /**
58 * A valid DB connection string for use with a driver/ORM.
59 */
60 connectionString: Effect.Effect<Redacted.Redacted<string>, never, RuntimeContext>;
61 /**
62 * Hostname valid only within the current Worker invocation.
63 */
64 host: Effect.Effect<string, never, RuntimeContext>;
65 /**
66 * Port to pair with `host`.
67 */
68 port: Effect.Effect<number, never, RuntimeContext>;
69 /**
70 * Database user.
71 */
72 user: Effect.Effect<string, never, RuntimeContext>;
73 /**
74 * Randomly generated password valid only within the current Worker
75 * invocation.
76 */
77 password: Effect.Effect<Redacted.Redacted<string>, never, RuntimeContext>;
78 /**
79 * Database name.
80 */
81 database: Effect.Effect<string, never, RuntimeContext>;
82 }