1import type * as Effect from "effect/Effect";
2import * as Binding from "../../Binding.ts";
3import type { RuntimeContext } from "../../RuntimeContext.ts";
4import type { Bucket } from "./Bucket.ts";
5import type {
6 ObjectContent,
7 ObjectNotFound,
8 ObjectRequestFailed,
9} from "./ObjectMedia.ts";
10
11export type { ObjectContent } from "./ObjectMedia.ts";
12
13export interface GetObjectRequest {
14 /** Object name (key). */
15 object: string;
16 /** Serve this generation instead of the live one. */
17 generation?: string;
18}
19
20/**
21 * Runtime binding that downloads an object's content from a Cloud Storage
22 * {@link Bucket} (`objects.get` with `alt=media`). Grants
23 * `roles/storage.objectViewer` on the bucket.
24 *
25 * Bind this operation to a {@link Bucket} in a Function/Action init phase.
26 * Provide {@link GetObjectHttp}.
27 *
28 * ### Reading Objects
29 * **Example:** Read an object as text
30 * ```typescript
31 * const getObject = yield* GCP.Storage.GetObject(bucket);
32 * const { body } = yield* getObject({ object: "hello.txt" });
33 * const text = new TextDecoder().decode(body);
34 * ```
35 *
36 * @binding
37 * @category Storage
38 */
39export interface GetObject extends Binding.Service<
40 GetObject,
41 "GCP.Storage.GetObject",
42 (
43 bucket: Bucket,
44 ) => Effect.Effect<
45 (
46 request: GetObjectRequest,
47 ) => Effect.Effect<
48 ObjectContent,
49 ObjectNotFound | ObjectRequestFailed,
50 RuntimeContext
51 >
52 >
53> {}
54
55export const GetObject = Binding.Service<GetObject>("GCP.Storage.GetObject");