|
| 1 | +import { Collection, JSCodeshift } from "jscodeshift"; |
| 2 | + |
| 3 | +import { FUNCTION_TYPE_LIST } from "../config"; |
| 4 | +import { getClientWaiterStates } from "./getClientWaiterStates"; |
| 5 | +import { getV2ClientIdentifiers } from "./getV2ClientIdentifiers"; |
| 6 | +import { getV2ClientWaiterCallExpression } from "./getV2ClientWaiterCallExpression"; |
| 7 | + |
| 8 | +export interface CommentsForUnsupportedAPIsOptions { |
| 9 | + v2ClientName: string; |
| 10 | + v2ClientLocalName: string; |
| 11 | + v2GlobalName?: string; |
| 12 | +} |
| 13 | + |
| 14 | +export const addNotSupportedComments = ( |
| 15 | + j: JSCodeshift, |
| 16 | + source: Collection<unknown>, |
| 17 | + options: CommentsForUnsupportedAPIsOptions |
| 18 | +): void => { |
| 19 | + const v2ClientIdentifiers = getV2ClientIdentifiers(j, source, options); |
| 20 | + |
| 21 | + for (const v2ClientId of v2ClientIdentifiers) { |
| 22 | + const waiterStates = getClientWaiterStates(j, source, options); |
| 23 | + |
| 24 | + for (const waiterState of waiterStates) { |
| 25 | + source |
| 26 | + .find(j.CallExpression, getV2ClientWaiterCallExpression(v2ClientId, waiterState)) |
| 27 | + .forEach((callExpression) => { |
| 28 | + const args = callExpression.node.arguments; |
| 29 | + |
| 30 | + if (FUNCTION_TYPE_LIST.includes(args[args.length - 1].type)) { |
| 31 | + const comments = callExpression.node.comments || []; |
| 32 | + comments.push( |
| 33 | + j.commentLine( |
| 34 | + " Waiters with callbacks are not supported in AWS SDK for JavaScript (v3)." |
| 35 | + ) |
| 36 | + ); |
| 37 | + comments.push( |
| 38 | + j.commentLine( |
| 39 | + " Please convert to `await client.waitFor(state, params).promise()`, and re-run aws-sdk-js-codemod." |
| 40 | + ) |
| 41 | + ); |
| 42 | + callExpression.node.comments = comments; |
| 43 | + } |
| 44 | + }); |
| 45 | + } |
| 46 | + } |
| 47 | +}; |
0 commit comments