| 1 | // @ts-nocheck |
| 2 | import * as S3 from "@distilled.cloud/aws/s3"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Binding from "../../Binding.ts"; |
| 5 | import type { Bucket } from "./Bucket.ts"; |
| 6 | |
| 7 | export interface CopyObjectRequest extends Omit< |
| 8 | S3.CopyObjectRequest, |
| 9 | "Bucket" |
| 10 | > {} |
| 11 | |
| 12 | /** |
| 13 | * Runtime binding for `s3:CopyObject`. |
| 14 | * |
| 15 | * Bind this operation to the destination bucket to get a callable that copies |
| 16 | * objects server-side — no download/re-upload round trip. `CopySource` names |
| 17 | * the source as `"source-bucket/key"`. Provide the implementation with |
| 18 | * `Effect.provide(AWS.S3.CopyObjectHttp)`. The binding grants reads of current |
| 19 | * and specific source versions within the bound bucket. Cross-bucket copies |
| 20 | * require a separate read grant on the source bucket. |
| 21 | * |
| 22 | * ### Copying Objects |
| 23 | * **Example:** Copy an Object Within a Bucket |
| 24 | * ```typescript |
| 25 | * // init — bind the operation to the destination bucket |
| 26 | * const copyObject = yield* AWS.S3.CopyObject(bucket); |
| 27 | * |
| 28 | * // runtime — promote a staged upload to its final key |
| 29 | * yield* copyObject({ |
| 30 | * CopySource: `${bucketName}/incoming/report.pdf`, |
| 31 | * Key: "published/report.pdf", |
| 32 | * }); |
| 33 | * ``` |
| 34 | * |
| 35 | * ### Copying a Specific Version |
| 36 | * **Example:** Restore an Older Version to a New Key |
| 37 | * ```typescript |
| 38 | * const sourceKey = "reports/annual report.pdf"; |
| 39 | * const encodedKey = sourceKey.split("/").map(encodeURIComponent).join("/"); |
| 40 | * yield* copyObject({ |
| 41 | * CopySource: `${bucketName}/${encodedKey}?versionId=${encodeURIComponent(versionId)}`, |
| 42 | * Key: "restored/annual report.pdf", |
| 43 | * }); |
| 44 | * ``` |
| 45 | * |
| 46 | * The source version remains unchanged. In a versioned destination bucket, |
| 47 | * the copy creates a new version and returns its `VersionId`. |
| 48 | * |
| 49 | * ### Copying Between Buckets |
| 50 | * **Example:** Grant reads on a separate source bucket |
| 51 | * ```typescript |
| 52 | * yield* AWS.S3.GetObject(sourceBucket); |
| 53 | * const copyObject = yield* AWS.S3.CopyObject(destinationBucket); |
| 54 | * // Provide both AWS.S3.GetObjectHttp and AWS.S3.CopyObjectHttp on the host. |
| 55 | * ``` |
| 56 | * |
| 57 | * The source read binding grants current and version-specific reads without |
| 58 | * granting writes to the source. Copying tags, ACLs, Object Lock settings, or |
| 59 | * KMS-encrypted data requires the corresponding additional permissions. |
| 60 | * |
| 61 | * @binding |
| 62 | */ |
| 63 | export interface CopyObject extends Binding.Service< |
| 64 | CopyObject, |
| 65 | "AWS.S3.CopyObject", |
| 66 | ( |
| 67 | bucket: Bucket, |
| 68 | ) => Effect.Effect< |
| 69 | ( |
| 70 | request: CopyObjectRequest, |
| 71 | ) => Effect.Effect<S3.CopyObjectOutput, S3.CopyObjectError> |
| 72 | > |
| 73 | > {} |
| 74 | |
| 75 | export const CopyObject = Binding.Service<CopyObject>("AWS.S3.CopyObject"); |