1import type * as S3 from "@distilled.cloud/aws/s3";
2import type * as Config from "effect/Config";
3import type * as Effect from "effect/Effect";
4import * as Binding from "../Binding.ts";
5import type { RuntimeContext } from "../RuntimeContext.ts";
6import type { Bucket } from "./Bucket.ts";
7import type { RailwayS3CredentialsMissing } from "./BucketBinding.ts";
8
9export interface GetObjectRequest extends Omit<S3.GetObjectRequest, "Bucket"> {}
10
11/**
12 * Runtime binding for Railway `GetObject` over the S3 API.
13 *
14 * Bind this operation to a {@link Bucket} in Service init. Provide
15 * {@link GetObjectHttp}.
16 *
17 *
18 * ### Reading Objects
19 * **Example:** Read an Object and Decode Its Body
20 * ```typescript
21 * const getObject = yield* Railway.GetObject(Data);
22 *
23 * const text = yield* getObject({ Key: "hello.txt" }).pipe(
24 * Effect.flatMap((result) =>
25 * Stream.mkString(Stream.decodeText(result.Body!)),
26 * ),
27 * );
28 * ```
29 *
30 * @binding
31 * @product Bucket
32 */
33export interface GetObject extends Binding.Service<
34 GetObject,
35 "Railway.GetObject",
36 (
37 bucket: Bucket,
38 ) => Effect.Effect<
39 (
40 request?: GetObjectRequest,
41 ) => Effect.Effect<
42 S3.GetObjectOutput,
43 S3.GetObjectError | Config.ConfigError | RailwayS3CredentialsMissing,
44 RuntimeContext
45 >
46 >
47> {}
48
49export const GetObject = Binding.Service<GetObject>("Railway.GetObject");