Skip to content

Commit

Permalink
Check if parameters are passed during DocumentClient creation (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Aug 4, 2023
1 parent 432133e commit 56ac51a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-cherries-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Check if parameters are passed during DocumentClient creation
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AWS from "aws-sdk";

const documentClient = new AWS.DynamoDB.DocumentClient();
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
import { DynamoDB } from "@aws-sdk/client-dynamodb";

const documentClient = DynamoDBDocument.from(new DynamoDB());
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const getDynamoDBDocClientArgs = (

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

// Add DocumentClient option convertEmptyValues.
// Add DocumentClient option convertEmptyValues/wrapNumbers.
if (v2DocClientArgs.length > 0) {
const params = v2DocClientArgs[0];
if (params.type === "ObjectExpression") {
Expand Down
30 changes: 16 additions & 14 deletions src/transforms/v2-to-v3/client-instances/getDynamoDBForDocClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,25 @@ export const getDynamoDBForDocClient = (
const v3DocClientNewExpressionArgs = [];

// Remove DocumentClient option convertEmptyValues and wrapNumbers.
if (v3DocClientArgs.type === "ObjectExpression") {
v3DocClientArgs.properties = v3DocClientArgs.properties.filter((property) => {
if (!OBJECT_PROPERTY_TYPE_LIST.includes(property.type)) {
return true;
}
const propertyKey = (property as Property | ObjectProperty).key;
if (propertyKey.type !== "Identifier") {
return true;
}
return !["convertEmptyValues", "wrapNumbers"].includes(propertyKey.name);
});
if (v3DocClientArgs) {
if (v3DocClientArgs.type === "ObjectExpression") {
v3DocClientArgs.properties = v3DocClientArgs.properties.filter((property) => {
if (!OBJECT_PROPERTY_TYPE_LIST.includes(property.type)) {
return true;
}
const propertyKey = (property as Property | ObjectProperty).key;
if (propertyKey.type !== "Identifier") {
return true;
}
return !["convertEmptyValues", "wrapNumbers"].includes(propertyKey.name);
});

if (v3DocClientArgs.properties.length > 0) {
if (v3DocClientArgs.properties.length > 0) {
v3DocClientNewExpressionArgs.push(v3DocClientArgs);
}
} else {
v3DocClientNewExpressionArgs.push(v3DocClientArgs);
}
} else {
v3DocClientNewExpressionArgs.push(v3DocClientArgs);
}

return j.newExpression(
Expand Down

0 comments on commit 56ac51a

Please sign in to comment.