Skip to content

Commit 049b329

Browse files
authored
Add transformation for s3 ManagedUploadOptions in an identifier (#443)
1 parent 066d27d commit 049b329

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

.changeset/moody-experts-lie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"aws-sdk-js-codemod": patch
3+
---
4+
5+
Add transformation for s3 ManagedUploadOptions in an identifier
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import AWS from "aws-sdk";
2+
3+
const client = new AWS.S3({ region: "REGION" });
4+
5+
const uploadParams = {
6+
Body: "BODY",
7+
Bucket: "Bucket",
8+
ContentType: "ContentType",
9+
Key: "Key",
10+
};
11+
const uploadOptions = {
12+
partSize: 1024 * 1024 * 5,
13+
queueSize: 1,
14+
leavePartsOnError: true,
15+
tags: [],
16+
};
17+
18+
await client.upload(uploadParams, uploadOptions).promise();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Upload } from "@aws-sdk/lib-storage";
2+
import { S3 } from "@aws-sdk/client-s3";
3+
4+
const client = new S3({ region: "REGION" });
5+
6+
const uploadParams = {
7+
Body: "BODY",
8+
Bucket: "Bucket",
9+
ContentType: "ContentType",
10+
Key: "Key",
11+
};
12+
const uploadOptions = {
13+
partSize: 1024 * 1024 * 5,
14+
queueSize: 1,
15+
leavePartsOnError: true,
16+
tags: [],
17+
};
18+
19+
await new Upload({
20+
client,
21+
params: uploadParams,
22+
...uploadOptions
23+
}).done();

src/transforms/v2-to-v3/apis/replaceS3UploadApi.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,15 @@ export const replaceS3UploadApi = (
5050
}
5151

5252
const options = callExpression.node.arguments[1];
53-
if (options && options.type === "ObjectExpression") {
54-
properties.push(...options.properties);
53+
if (options) {
54+
switch (options.type) {
55+
case "ObjectExpression":
56+
properties.push(...options.properties);
57+
break;
58+
case "Identifier":
59+
properties.push(j.spreadElement(options));
60+
break;
61+
}
5562
}
5663

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

0 commit comments

Comments
 (0)