1import * as S3 from "@distilled.cloud/aws/s3";
2import * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { Bucket } from "./Bucket.ts";
5
6export interface GetObjectRequest extends Omit<S3.GetObjectRequest, "Bucket"> {}
7
8/**
9 * Runtime binding for `s3:GetObject`.
10 *
11 * Bind this operation to a bucket in the function's init phase to get a
12 * callable that reads objects — the bucket name is injected automatically and
13 * `s3:GetObject` is granted on the bucket. Provide the implementation with
14 * `Effect.provide(AWS.S3.GetObjectHttp)`.
15 * ### Reading Objects
16 * **Example:** Read an Object and Decode Its Body
17 * ```typescript
18 * // init — bind the operation to the bucket
19 * const getObject = yield* AWS.S3.GetObject(bucket);
20 *
21 * // runtime — the Body is a Stream; decode it to a string
22 * const text = yield* getObject({ Key: "jobs/job-123.json" }).pipe(
23 * Effect.flatMap((result) =>
24 * Stream.mkString(Stream.decodeText(result.Body!)),
25 * ),
26 * );
27 * ```
28 *
29 * **Example:** Treat a Missing Key as Absence
30 * ```typescript
31 * const job = yield* getObject({ Key: `jobs/${jobId}.json` }).pipe(
32 * Effect.catchTag("NoSuchKey", () => Effect.succeed(undefined)),
33 * );
34 * ```
35 *
36 * @binding
37 */
38export interface GetObject extends Binding.Service<
39 GetObject,
40 "AWS.S3.GetObject",
41 (
42 bucket: Bucket,
43 ) => Effect.Effect<
44 (
45 request: GetObjectRequest,
46 ) => Effect.Effect<S3.GetObjectOutput, S3.GetObjectError>
47 >
48> {}
49
50export const GetObject = Binding.Service<GetObject>("AWS.S3.GetObject");