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

main
ts 54 lines 1.67 KB
Raw
1 import * as Binding from "alchemy/Binding";
2 import type { RuntimeContext } from "alchemy/RuntimeContext";
3 import * as Data from "effect/Data";
4 import * as Effect from "effect/Effect";
5 import type { Dataset as AnalyticsEngineDatasetLike } from "./Dataset.ts";
6
7 /**
8 * Bind an {@link AnalyticsEngineDatasetLike} dataset to a Worker and obtain the
9 * Effect-native client (`writeDataPoint`, `raw`).
10 *
11 * `WriteDataset` is a single identifier that is simultaneously the binding's
12 * Context tag, its type, and the callable —
13 * `yield* Cloudflare.AnalyticsEngine.WriteDataset(dataset)`.
14 *
15 *
16 * **Example:** Write a data point inside a Worker
17 * ```typescript
18 * const analytics = yield* Cloudflare.AnalyticsEngine.WriteDataset(Dataset);
19 * yield* analytics.writeDataPoint({ blobs: ["signup"] });
20 * ```
21 *
22 * @binding
23 * @product Analytics Engine
24 * @category Observability & Analytics
25 */
26 export interface WriteDataset extends Binding.Service<
27 WriteDataset,
28 "Cloudflare.AnalyticsEngineDataset.WriteDataset",
29 (dataset: AnalyticsEngineDatasetLike) => Effect.Effect<DatasetClient>
30 > {}
31
32 export const WriteDataset = Binding.Service<WriteDataset>(
33 "Cloudflare.AnalyticsEngineDataset.WriteDataset",
34 );
35
36 export interface DataPoint {
37 indexes?: string[];
38 blobs?: string[];
39 doubles?: number[];
40 }
41
42 export interface RuntimeAnalyticsEngineDataset {
43 writeDataPoint(dataPoint: DataPoint): void;
44 }
45
46 export class DatasetError extends Data.TaggedError("DatasetError")<{
47 message: string;
48 cause: Error;
49 }> {}
50
51 export interface DatasetClient {
52 raw: Effect.Effect<RuntimeAnalyticsEngineDataset, never, RuntimeContext>;
53 writeDataPoint(dataPoint: DataPoint): Effect.Effect<void, DatasetError, RuntimeContext>;
54 }