aws-sdk-js-codemod
Version:
Collection of codemod scripts that help update AWS SDK for JavaScript APIs
62 lines (61 loc) • 3.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addNotSupportedClientComments = void 0;
const config_1 = require("../config");
const getClientApiCallExpression_1 = require("./getClientApiCallExpression");
const getClientWaiterCallExpression_1 = require("./getClientWaiterCallExpression");
const getClientWaiterStates_1 = require("./getClientWaiterStates");
const addNotSupportedClientComments = (j, source, options) => {
const { v2ClientName, clientIdentifiers } = options;
for (const clientId of clientIdentifiers) {
const waiterStates = (0, getClientWaiterStates_1.getClientWaiterStates)(j, source, clientIdentifiers);
for (const waiterState of waiterStates) {
source
.find(j.CallExpression, (0, getClientWaiterCallExpression_1.getClientWaiterCallExpression)(clientId, waiterState))
.forEach((callExpression) => {
const args = callExpression.node.arguments;
if (config_1.FUNCTION_TYPE_LIST.includes(args[args.length - 1].type)) {
const comments = callExpression.node.comments || [];
comments.push(j.commentLine(` Waiters with callbacks are ${config_1.NOT_SUPPORTED_COMMENT}.`));
comments.push(j.commentLine(" Please convert to `await client.waitFor(state, params).promise()`, and re-run aws-sdk-js-codemod."));
callExpression.node.comments = comments;
}
});
}
}
if (v2ClientName === config_1.S3) {
for (const clientId of clientIdentifiers) {
const apiMetadata = [
{
apiName: "upload",
apiDescription: "S3 ManagedUpload",
apiSuggestion: "await client.upload(params, options).promise()",
},
{
apiName: "getSignedUrl",
apiDescription: "S3 getSignedUrl",
apiSuggestion: "client.getSignedUrl(apiName, options)",
},
{
apiName: "createPresignedPost",
apiDescription: "S3 createPresignedPost",
apiSuggestion: "client.createPresignedPost(params)",
},
];
for (const { apiName, apiDescription, apiSuggestion } of apiMetadata) {
source
.find(j.CallExpression, (0, getClientApiCallExpression_1.getClientApiCallExpression)(clientId, apiName))
.forEach((callExpression) => {
const args = callExpression.node.arguments;
if (config_1.FUNCTION_TYPE_LIST.includes(args[args.length - 1].type)) {
const comments = callExpression.node.comments || [];
comments.push(j.commentLine(` ${apiDescription} with callbacks is ${config_1.NOT_SUPPORTED_COMMENT}.`));
comments.push(j.commentLine(` Please convert to '${apiSuggestion}', and re-run aws-sdk-js-codemod.`));
callExpression.node.comments = comments;
}
});
}
}
}
};
exports.addNotSupportedClientComments = addNotSupportedClientComments;