Skip to content

Commit d1cea6f

Browse files
authored
Transform DynamoDB DocumentClient wrapNumbers option (#539)
1 parent 1a54680 commit d1cea6f

File tree

7 files changed

+49
-5
lines changed

7 files changed

+49
-5
lines changed

.changeset/curly-shoes-visit.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+
Transform DynamoDB DocumentClient wrapNumbers option
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import AWS from "aws-sdk";
2+
3+
const params = { region: "us-west-2" };
4+
const documentClient = new AWS.DynamoDB.DocumentClient({
5+
convertEmptyValues: true,
6+
service: new AWS.DynamoDB(params),
7+
wrapNumbers: true
8+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
2+
import { DynamoDB } from "@aws-sdk/client-dynamodb";
3+
4+
const params = { region: "us-west-2" };
5+
const documentClient = DynamoDBDocument.from(new DynamoDB(params), {
6+
marshallOptions: {
7+
convertEmptyValues: true
8+
},
9+
10+
unmarshallOptions: {
11+
wrapNumbers: true
12+
}
13+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import AWS from "aws-sdk";
2+
3+
const documentClient = new AWS.DynamoDB.DocumentClient({
4+
wrapNumbers: true,
5+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
2+
import { DynamoDB } from "@aws-sdk/client-dynamodb";
3+
4+
const documentClient = DynamoDBDocument.from(new DynamoDB(), {
5+
unmarshallOptions: {
6+
wrapNumbers: true
7+
}
8+
});

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@ export const getDynamoDBDocClientArgs = (
2929
continue;
3030
}
3131

32-
if (propertyKey.name === "convertEmptyValues") {
32+
const docClientOptionsHash: Record<string, string> = {
33+
convertEmptyValues: "marshallOptions",
34+
wrapNumbers: "unmarshallOptions",
35+
};
36+
37+
if (Object.keys(docClientOptionsHash).includes(propertyKey.name)) {
3338
dynamoDBDocClientOptions.properties.push(
3439
j.property(
3540
"init",
36-
j.identifier("marshallOptions"),
41+
j.identifier(docClientOptionsHash[propertyKey.name]),
3742
j.objectExpression([
3843
j.property(
3944
"init",
40-
j.identifier("convertEmptyValues"),
45+
j.identifier(propertyKey.name),
4146
(property as Property | ObjectProperty).value
4247
),
4348
])

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const getDynamoDBForDocClient = (
4141
const v3DocClientArgs = v2DocClientArgs[0];
4242
const v3DocClientNewExpressionArgs = [];
4343

44-
// Remove DocumentClient option convertEmptyValues.
44+
// Remove DocumentClient option convertEmptyValues and wrapNumbers.
4545
if (v3DocClientArgs.type === "ObjectExpression") {
4646
v3DocClientArgs.properties = v3DocClientArgs.properties.filter((property) => {
4747
if (!OBJECT_PROPERTY_TYPE_LIST.includes(property.type)) {
@@ -51,7 +51,7 @@ export const getDynamoDBForDocClient = (
5151
if (propertyKey.type !== "Identifier") {
5252
return true;
5353
}
54-
return propertyKey.name !== "convertEmptyValues";
54+
return !["convertEmptyValues", "wrapNumbers"].includes(propertyKey.name);
5555
});
5656

5757
if (v3DocClientArgs.properties.length > 0) {

0 commit comments

Comments
 (0)