| 1 | import type * as S3 from "@distilled.cloud/aws/s3"; |
| 2 | import type * as Config from "effect/Config"; |
| 3 | import type * as Effect from "effect/Effect"; |
| 4 | import * as Binding from "../Binding.ts"; |
| 5 | import type { RuntimeContext } from "../RuntimeContext.ts"; |
| 6 | import type { Bucket } from "./Bucket.ts"; |
| 7 | import type { RailwayS3CredentialsMissing } from "./BucketBinding.ts"; |
| 8 | |
| 9 | export 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 | */ |
| 33 | export 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 | |
| 49 | export const GetObject = Binding.Service<GetObject>("Railway.GetObject"); |