| 1 | import * as S3 from "@distilled.cloud/aws/s3"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Bucket } from "./Bucket.ts"; |
| 5 | |
| 6 | export interface ListObjectsV2Request extends Omit< |
| 7 | S3.ListObjectsV2Request, |
| 8 | "Bucket" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Runtime binding for `s3:ListObjectsV2`. |
| 13 | * |
| 14 | * Bind this operation to a bucket to get a callable that lists objects — |
| 15 | * the bucket name is injected automatically and `s3:ListBucket` is granted |
| 16 | * on the bucket. Provide the implementation with |
| 17 | * `Effect.provide(AWS.S3.ListObjectsV2Http)`. |
| 18 | * ### Listing Objects |
| 19 | * **Example:** List Objects Under a Prefix |
| 20 | * ```typescript |
| 21 | * // init — bind the operation to the bucket |
| 22 | * const listObjects = yield* AWS.S3.ListObjectsV2(bucket); |
| 23 | * |
| 24 | * // runtime — list up to 100 keys under `jobs/` |
| 25 | * const result = yield* listObjects({ Prefix: "jobs/", MaxKeys: 100 }); |
| 26 | * const keys = (result.Contents ?? []).map((object) => object.Key); |
| 27 | * // result.IsTruncated + result.NextContinuationToken page through the rest |
| 28 | * ``` |
| 29 | * |
| 30 | * @binding |
| 31 | */ |
| 32 | export interface ListObjectsV2 extends Binding.Service< |
| 33 | ListObjectsV2, |
| 34 | "AWS.S3.ListObjectsV2", |
| 35 | ( |
| 36 | bucket: Bucket, |
| 37 | ) => Effect.Effect< |
| 38 | ( |
| 39 | request?: ListObjectsV2Request, |
| 40 | ) => Effect.Effect<S3.ListObjectsV2Output, S3.ListObjectsV2Error> |
| 41 | > |
| 42 | > {} |
| 43 | |
| 44 | export const ListObjectsV2 = Binding.Service<ListObjectsV2>( |
| 45 | "AWS.S3.ListObjectsV2", |
| 46 | ); |