UNPKG

aws-sdk-js-codemod

Version:

Collection of codemod scripts that help update AWS SDK for JavaScript APIs

38 lines (37 loc) 1.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDynamoDBDocClientArgs = void 0; const getDynamoDBForDocClient_1 = require("./getDynamoDBForDocClient"); const getDynamoDBDocClientArgs = (j, v2DocClientNewExpression, v2ClientLocalName) => { const dynamoDBDocClientOptions = j.objectExpression([]); const v2DocClientArgs = v2DocClientNewExpression.node.arguments || []; // Add DocumentClient option convertEmptyValues/wrapNumbers. if (v2DocClientArgs.length > 0) { const params = v2DocClientArgs[0]; if (params.type === "ObjectExpression") { for (const property of params.properties) { if (property.type !== "Property" && property.type !== "ObjectProperty") { continue; } const propertyKey = property.key; if (propertyKey.type !== "Identifier") { continue; } const docClientOptionsHash = { convertEmptyValues: "marshallOptions", wrapNumbers: "unmarshallOptions", }; if (Object.keys(docClientOptionsHash).includes(propertyKey.name)) { dynamoDBDocClientOptions.properties.push(j.property("init", j.identifier(docClientOptionsHash[propertyKey.name]), j.objectExpression([ j.property("init", j.identifier(propertyKey.name), property.value), ]))); } } } } return [ (0, getDynamoDBForDocClient_1.getDynamoDBForDocClient)(j, v2DocClientNewExpression, v2ClientLocalName), ...(dynamoDBDocClientOptions.properties.length > 0 ? [dynamoDBDocClientOptions] : []), ]; }; exports.getDynamoDBDocClientArgs = getDynamoDBDocClientArgs;