-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add comments for unsupported waiters with callback (#434)
- Loading branch information
Showing
9 changed files
with
108 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"aws-sdk-js-codemod": patch | ||
--- | ||
|
||
Add comments for unsupported waiters with callback |
9 changes: 9 additions & 0 deletions
9
src/transforms/v2-to-v3/__fixtures__/waiters/callback.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
const Bucket = "BUCKET_NAME"; | ||
const client = new AWS.S3({ region: "REGION" }); | ||
|
||
client.waitFor("bucketExists", { Bucket }, function (err, data) { | ||
if (err) console.log(err, err.stack); // an error occurred | ||
else console.log(data); // successful response | ||
}); |
11 changes: 11 additions & 0 deletions
11
src/transforms/v2-to-v3/__fixtures__/waiters/callback.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import AWS from "aws-sdk"; | ||
|
||
const Bucket = "BUCKET_NAME"; | ||
const client = new AWS.S3({ region: "REGION" }); | ||
|
||
// Waiters with callbacks are not supported in AWS SDK for JavaScript (v3). | ||
// Please convert to `await client.waitFor(state, params).promise()`, and re-run aws-sdk-js-codemod. | ||
client.waitFor("bucketExists", { Bucket }, function (err, data) { | ||
if (err) console.log(err, err.stack); // an error occurred | ||
else console.log(data); // successful response | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Collection, JSCodeshift } from "jscodeshift"; | ||
|
||
import { FUNCTION_TYPE_LIST } from "../config"; | ||
import { getClientWaiterStates } from "./getClientWaiterStates"; | ||
import { getV2ClientIdentifiers } from "./getV2ClientIdentifiers"; | ||
import { getV2ClientWaiterCallExpression } from "./getV2ClientWaiterCallExpression"; | ||
|
||
export interface CommentsForUnsupportedAPIsOptions { | ||
v2ClientName: string; | ||
v2ClientLocalName: string; | ||
v2GlobalName?: string; | ||
} | ||
|
||
export const addNotSupportedComments = ( | ||
j: JSCodeshift, | ||
source: Collection<unknown>, | ||
options: CommentsForUnsupportedAPIsOptions | ||
): void => { | ||
const v2ClientIdentifiers = getV2ClientIdentifiers(j, source, options); | ||
|
||
for (const v2ClientId of v2ClientIdentifiers) { | ||
const waiterStates = getClientWaiterStates(j, source, options); | ||
|
||
for (const waiterState of waiterStates) { | ||
source | ||
.find(j.CallExpression, getV2ClientWaiterCallExpression(v2ClientId, waiterState)) | ||
.forEach((callExpression) => { | ||
const args = callExpression.node.arguments; | ||
|
||
if (FUNCTION_TYPE_LIST.includes(args[args.length - 1].type)) { | ||
const comments = callExpression.node.comments || []; | ||
comments.push( | ||
j.commentLine( | ||
" Waiters with callbacks are not supported in AWS SDK for JavaScript (v3)." | ||
) | ||
); | ||
comments.push( | ||
j.commentLine( | ||
" Please convert to `await client.waitFor(state, params).promise()`, and re-run aws-sdk-js-codemod." | ||
) | ||
); | ||
callExpression.node.comments = comments; | ||
} | ||
}); | ||
} | ||
} | ||
}; |
17 changes: 17 additions & 0 deletions
17
src/transforms/v2-to-v3/apis/getV2ClientWaiterCallExpression.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { CallExpression } from "jscodeshift"; | ||
|
||
import { V2ClientIdentifier } from "./getV2ClientIdentifiers"; | ||
|
||
export const getV2ClientWaiterCallExpression = ( | ||
v2ClientId: V2ClientIdentifier, | ||
waiterState: string | ||
): CallExpression => ({ | ||
type: "CallExpression", | ||
callee: { | ||
type: "MemberExpression", | ||
object: v2ClientId, | ||
property: { type: "Identifier", name: "waitFor" }, | ||
}, | ||
// @ts-expect-error Type 'string' is not assignable to type 'RegExp' | ||
arguments: [{ value: waiterState }], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters