Skip to content

Commit

Permalink
Add transformation for s3 ManagedUploadOptions in an identifier (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Mar 1, 2023
1 parent 066d27d commit 049b329
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-experts-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Add transformation for s3 ManagedUploadOptions in an identifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import AWS from "aws-sdk";

const client = new AWS.S3({ region: "REGION" });

const uploadParams = {
Body: "BODY",
Bucket: "Bucket",
ContentType: "ContentType",
Key: "Key",
};
const uploadOptions = {
partSize: 1024 * 1024 * 5,
queueSize: 1,
leavePartsOnError: true,
tags: [],
};

await client.upload(uploadParams, uploadOptions).promise();
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Upload } from "@aws-sdk/lib-storage";
import { S3 } from "@aws-sdk/client-s3";

const client = new S3({ region: "REGION" });

const uploadParams = {
Body: "BODY",
Bucket: "Bucket",
ContentType: "ContentType",
Key: "Key",
};
const uploadOptions = {
partSize: 1024 * 1024 * 5,
queueSize: 1,
leavePartsOnError: true,
tags: [],
};

await new Upload({
client,
params: uploadParams,
...uploadOptions
}).done();
11 changes: 9 additions & 2 deletions src/transforms/v2-to-v3/apis/replaceS3UploadApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ export const replaceS3UploadApi = (
}

const options = callExpression.node.arguments[1];
if (options && options.type === "ObjectExpression") {
properties.push(...options.properties);
if (options) {
switch (options.type) {
case "ObjectExpression":
properties.push(...options.properties);
break;
case "Identifier":
properties.push(j.spreadElement(options));
break;
}
}

return j.newExpression(j.identifier("Upload"), [j.objectExpression(properties)]);
Expand Down

0 comments on commit 049b329

Please sign in to comment.