Skip to content

Commit 56ac51a

Browse files
authored
Check if parameters are passed during DocumentClient creation (#547)
1 parent 432133e commit 56ac51a

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

.changeset/quiet-cherries-tell.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+
Check if parameters are passed during DocumentClient creation
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import AWS from "aws-sdk";
2+
3+
const documentClient = new AWS.DynamoDB.DocumentClient();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
2+
import { DynamoDB } from "@aws-sdk/client-dynamodb";
3+
4+
const documentClient = DynamoDBDocument.from(new DynamoDB());

src/transforms/v2-to-v3/client-instances/getDynamoDBDocClientArgs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const getDynamoDBDocClientArgs = (
1515

1616
const v2DocClientArgs = v2DocClientNewExpression.node.arguments || [];
1717

18-
// Add DocumentClient option convertEmptyValues.
18+
// Add DocumentClient option convertEmptyValues/wrapNumbers.
1919
if (v2DocClientArgs.length > 0) {
2020
const params = v2DocClientArgs[0];
2121
if (params.type === "ObjectExpression") {

src/transforms/v2-to-v3/client-instances/getDynamoDBForDocClient.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,25 @@ export const getDynamoDBForDocClient = (
4242
const v3DocClientNewExpressionArgs = [];
4343

4444
// Remove DocumentClient option convertEmptyValues and wrapNumbers.
45-
if (v3DocClientArgs.type === "ObjectExpression") {
46-
v3DocClientArgs.properties = v3DocClientArgs.properties.filter((property) => {
47-
if (!OBJECT_PROPERTY_TYPE_LIST.includes(property.type)) {
48-
return true;
49-
}
50-
const propertyKey = (property as Property | ObjectProperty).key;
51-
if (propertyKey.type !== "Identifier") {
52-
return true;
53-
}
54-
return !["convertEmptyValues", "wrapNumbers"].includes(propertyKey.name);
55-
});
45+
if (v3DocClientArgs) {
46+
if (v3DocClientArgs.type === "ObjectExpression") {
47+
v3DocClientArgs.properties = v3DocClientArgs.properties.filter((property) => {
48+
if (!OBJECT_PROPERTY_TYPE_LIST.includes(property.type)) {
49+
return true;
50+
}
51+
const propertyKey = (property as Property | ObjectProperty).key;
52+
if (propertyKey.type !== "Identifier") {
53+
return true;
54+
}
55+
return !["convertEmptyValues", "wrapNumbers"].includes(propertyKey.name);
56+
});
5657

57-
if (v3DocClientArgs.properties.length > 0) {
58+
if (v3DocClientArgs.properties.length > 0) {
59+
v3DocClientNewExpressionArgs.push(v3DocClientArgs);
60+
}
61+
} else {
5862
v3DocClientNewExpressionArgs.push(v3DocClientArgs);
5963
}
60-
} else {
61-
v3DocClientNewExpressionArgs.push(v3DocClientArgs);
6264
}
6365

6466
return j.newExpression(

0 commit comments

Comments
 (0)