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

main
ts 67 lines 2.36 KB
Raw
1 import type * as storage from "@distilled.cloud/gcp/storage_v1";
2 import * as Binding from "alchemy/Binding";
3 import type { RuntimeContext } from "alchemy/RuntimeContext";
4 import type * as Effect from "effect/Effect";
5 import type { Bucket } from "./Bucket.ts";
6 import type { ObjectContent, ObjectRequestFailed } from "./ObjectMedia.ts";
7
8 export interface ListBucketOptions {
9 /** Only objects whose name starts with this prefix. */
10 prefix?: string;
11 /** Group names by this delimiter (e.g. `/`) into `prefixes`. */
12 delimiter?: string;
13 /** Maximum objects per page. */
14 maxResults?: number;
15 /** Page token from a previous `list`. */
16 pageToken?: string;
17 }
18
19 export interface ListBucketResult {
20 objects: storage.Storage_Object[];
21 /** Common prefixes when `delimiter` is set. */
22 prefixes: string[];
23 /** Pass to the next `list` call; `undefined` on the last page. */
24 nextPageToken: string | undefined;
25 }
26
27 /** Read-only client for one Cloud Storage bucket. */
28 export interface ReadBucketClient {
29 /** Object metadata, or `undefined` when the object does not exist. */
30 head(
31 object: string,
32 ): Effect.Effect<storage.Storage_Object | undefined, storage.GetObjectsError, RuntimeContext>;
33 /** Object content, or `undefined` when the object does not exist. */
34 get(
35 object: string,
36 options?: { generation?: string },
37 ): Effect.Effect<ObjectContent | undefined, ObjectRequestFailed, RuntimeContext>;
38 /** One page of object listings. */
39 list(
40 options?: ListBucketOptions,
41 ): Effect.Effect<ListBucketResult, storage.ListObjectsError, RuntimeContext>;
42 }
43
44 /**
45 * Read access to a Cloud Storage {@link Bucket}: `head`, `get`, `list`.
46 * Grants `roles/storage.objectViewer` on the bucket only.
47 *
48 * ### Reading a bucket
49 * **Example:** Read an object and list a prefix
50 * ```typescript
51 * const uploads = yield* GCP.Storage.ReadBucket(bucket);
52 * const object = yield* uploads.get("hello.txt");
53 * const text = object && new TextDecoder().decode(object.body);
54 * const { objects } = yield* uploads.list({ prefix: "images/" });
55 * // …provided with Effect.provide(GCP.Storage.ReadBucketHttp)
56 * ```
57 *
58 * @binding
59 * @category Storage
60 */
61 export interface ReadBucket extends Binding.Service<
62 ReadBucket,
63 "GCP.Storage.ReadBucket",
64 (bucket: Bucket) => Effect.Effect<ReadBucketClient>
65 > {}
66
67 export const ReadBucket = Binding.Service<ReadBucket>("GCP.Storage.ReadBucket");