Skip to content

Commit

Permalink
Use waiterState when searching for waitFor calls to replace (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Feb 21, 2023
1 parent 8dcb1fd commit 69f2ea7
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-wombats-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Use waiterState when searching for waitFor calls to replace
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import AWS = require("aws-sdk");
const Bucket = "BUCKET_NAME";
const client = new AWS.S3({ region: "REGION" });

await client.waitFor("bucketNotExists", { Bucket }).promise();
await client.createBucket({ Bucket }).promise();
await client.waitFor("bucketExists", { Bucket }).promise();
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import AWS_S3 = require("@aws-sdk/client-s3");

const {
S3,
waitUntilBucketNotExists,
waitUntilBucketExists
} = AWS_S3;

const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await waitUntilBucketNotExists({
client,
maxWaitTime: 180
}, { Bucket });
await client.createBucket({ Bucket });
await waitUntilBucketExists({
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import AWS from "aws-sdk";
const Bucket = "BUCKET_NAME";
const client = new AWS.S3({ region: "REGION" });

await client.waitFor("bucketNotExists", { Bucket }).promise();
await client.createBucket({ Bucket }).promise();
await client.waitFor("bucketExists", { Bucket }).promise();
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { S3, waitUntilBucketExists } from "@aws-sdk/client-s3";
import { S3, waitUntilBucketNotExists, waitUntilBucketExists } from "@aws-sdk/client-s3";

const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await waitUntilBucketNotExists({
client,
maxWaitTime: 180
}, { Bucket });
await client.createBucket({ Bucket });
await waitUntilBucketExists({
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ const S3 = require("aws-sdk").S3;
const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await client.waitFor("bucketNotExists", { Bucket }).promise();
await client.createBucket({ Bucket }).promise();
await client.waitFor("bucketExists", { Bucket }).promise();
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
const {
S3,
waitUntilBucketNotExists,
waitUntilBucketExists
} = require("@aws-sdk/client-s3");

const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await waitUntilBucketNotExists({
client,
maxWaitTime: 180
}, { Bucket });
await client.createBucket({ Bucket });
await waitUntilBucketExists({
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ const AWS = require("aws-sdk");
const Bucket = "BUCKET_NAME";
const client = new AWS.S3({ region: "REGION" });

await client.waitFor("bucketNotExists", { Bucket }).promise();
await client.createBucket({ Bucket }).promise();
await client.waitFor("bucketExists", { Bucket }).promise();
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
const {
S3,
waitUntilBucketNotExists,
waitUntilBucketExists
} = require("@aws-sdk/client-s3");

const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await waitUntilBucketNotExists({
client,
maxWaitTime: 180
}, { Bucket });
await client.createBucket({ Bucket });
await waitUntilBucketExists({
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import S3 from "aws-sdk/clients/s3";
const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await client.waitFor("bucketNotExists", { Bucket }).promise();
await client.createBucket({ Bucket }).promise();
await client.waitFor("bucketExists", { Bucket }).promise();
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { S3, waitUntilBucketExists } from "@aws-sdk/client-s3";
import { S3, waitUntilBucketNotExists, waitUntilBucketExists } from "@aws-sdk/client-s3";

const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await waitUntilBucketNotExists({
client,
maxWaitTime: 180
}, { Bucket });
await client.createBucket({ Bucket });
await waitUntilBucketExists({
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import S3 = require("aws-sdk/clients/s3");
const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await client.waitFor("bucketNotExists", { Bucket }).promise();
await client.createBucket({ Bucket }).promise();
await client.waitFor("bucketExists", { Bucket }).promise();
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import AWS_S3 = require("@aws-sdk/client-s3");

const {
S3,
waitUntilBucketNotExists,
waitUntilBucketExists
} = AWS_S3;

const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await waitUntilBucketNotExists({
client,
maxWaitTime: 180
}, { Bucket });
await client.createBucket({ Bucket });
await waitUntilBucketExists({
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { S3 } from "aws-sdk";
const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await client.waitFor("bucketNotExists", { Bucket }).promise();
await client.createBucket({ Bucket }).promise();
await client.waitFor("bucketExists", { Bucket }).promise();
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { S3, waitUntilBucketExists } from "@aws-sdk/client-s3";
import { S3, waitUntilBucketNotExists, waitUntilBucketExists } from "@aws-sdk/client-s3";

const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await waitUntilBucketNotExists({
client,
maxWaitTime: 180
}, { Bucket });
await client.createBucket({ Bucket });
await waitUntilBucketExists({
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ const S3 = require("aws-sdk/clients/s3");
const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await client.waitFor("bucketNotExists", { Bucket }).promise();
await client.createBucket({ Bucket }).promise();
await client.waitFor("bucketExists", { Bucket }).promise();
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
const {
S3,
waitUntilBucketNotExists,
waitUntilBucketExists
} = require("@aws-sdk/client-s3");

const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await waitUntilBucketNotExists({
client,
maxWaitTime: 180
}, { Bucket });
await client.createBucket({ Bucket });
await waitUntilBucketExists({
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ const { S3 } = require("aws-sdk");
const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await client.waitFor("bucketNotExists", { Bucket }).promise();
await client.createBucket({ Bucket }).promise();
await client.waitFor("bucketExists", { Bucket }).promise();
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
const {
S3,
waitUntilBucketNotExists,
waitUntilBucketExists
} = require("@aws-sdk/client-s3");

const Bucket = "BUCKET_NAME";
const client = new S3({ region: "REGION" });

await waitUntilBucketNotExists({
client,
maxWaitTime: 180
}, { Bucket });
await client.createBucket({ Bucket });
await waitUntilBucketExists({
client,
Expand Down
1 change: 1 addition & 0 deletions src/transforms/v2-to-v3/apis/replaceWaiterApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const replaceWaiterApi = (
object: v2ClientId,
property: { type: "Identifier", name: "waitFor" },
},
arguments: [{ value: waiterState }],
})
.replaceWith((callExpression) => {
return j.callExpression(j.identifier(v3WaiterApiName), [
Expand Down

0 comments on commit 69f2ea7

Please sign in to comment.