From 9e64aa47a3fdc3750e09b807f769560539c778a3 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Mon, 26 Dec 2022 21:23:46 -0800 Subject: [PATCH] Replace named imports for Request/Response types (#221) --- .changeset/shy-mice-wonder.md | 5 +++++ .../global-import.input.ts | 10 +++++++--- .../global-import.output.ts | 13 +++++++++---- .../global-require.input.ts | 10 +++++++--- .../global-require.output.ts | 16 +++++++++++++--- .../service-import-named.input.ts | 12 +++++++++--- .../service-import-named.output.ts | 13 +++++++++---- .../service-import.input.ts | 12 +++++++++--- .../service-import.output.ts | 13 +++++++++---- .../service-require.input.ts | 12 +++++++++--- .../service-require.output.ts | 17 +++++++++++++---- .../v2-to-v3/utils/config/constants.ts | 5 ++--- 12 files changed, 101 insertions(+), 37 deletions(-) create mode 100644 .changeset/shy-mice-wonder.md diff --git a/.changeset/shy-mice-wonder.md b/.changeset/shy-mice-wonder.md new file mode 100644 index 000000000..de7c48bcc --- /dev/null +++ b/.changeset/shy-mice-wonder.md @@ -0,0 +1,5 @@ +--- +"aws-sdk-js-codemod": patch +--- + +Replace named imports for Request/Response types diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import.input.ts index c1a5eea8e..bd370284d 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import.input.ts @@ -1,9 +1,13 @@ import AWS from "aws-sdk"; -const client = new AWS.DynamoDB({ region: "us-west-2" }); - +const ddbClient = new AWS.DynamoDB({ region: "us-west-2" }); const listTablesInput: AWS.DynamoDB.ListTablesInput = { Limit: 10 }; -const listTablesOutput: AWS.DynamoDB.ListTablesOutput = await client +const listTablesOutput: AWS.DynamoDB.ListTablesOutput = await ddbClient .listTables(listTablesInput) .promise(); +const stsClient = new AWS.STS({ region: "us-west-2" }); +const getCallerIdentityInput: AWS.STS.GetCallerIdentityRequest = {}; +const getCallerIdentityOutput: AWS.STS.GetCallerIdentityResponse = await stsClient + .getCallerIdentity(getCallerIdentityInput) + .promise(); diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import.output.ts index bce09e280..4d4478858 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import.output.ts @@ -1,7 +1,12 @@ import { DynamoDB, ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb"; +import { STS, GetCallerIdentityCommandInput, GetCallerIdentityCommandOutput } from "@aws-sdk/client-sts"; -const client = new DynamoDB({ region: "us-west-2" }); - +const ddbClient = new DynamoDB({ region: "us-west-2" }); const listTablesInput: ListTablesCommandInput = { Limit: 10 }; -const listTablesOutput: ListTablesCommandOutput = await client - .listTables(listTablesInput); \ No newline at end of file +const listTablesOutput: ListTablesCommandOutput = await ddbClient + .listTables(listTablesInput); + +const stsClient = new STS({ region: "us-west-2" }); +const getCallerIdentityInput: GetCallerIdentityCommandInput = {}; +const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient + .getCallerIdentity(getCallerIdentityInput); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-require.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-require.input.ts index 0a31ce020..47cb63b19 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-require.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-require.input.ts @@ -1,9 +1,13 @@ const AWS = require("aws-sdk"); -const client = new AWS.DynamoDB({ region: "us-west-2" }); - +const ddbClient = new AWS.DynamoDB({ region: "us-west-2" }); const listTablesInput: AWS.DynamoDB.ListTablesInput = { Limit: 10 }; -const listTablesOutput: AWS.DynamoDB.ListTablesOutput = await client +const listTablesOutput: AWS.DynamoDB.ListTablesOutput = await ddbClient .listTables(listTablesInput) .promise(); +const stsClient = new AWS.STS({ region: "us-west-2" }); +const getCallerIdentityInput: AWS.STS.GetCallerIdentityRequest = {}; +const getCallerIdentityOutput: AWS.STS.GetCallerIdentityResponse = await stsClient + .getCallerIdentity(getCallerIdentityInput) + .promise(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-require.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-require.output.ts index a2b41be17..a620b8d5a 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-require.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-require.output.ts @@ -4,8 +4,18 @@ const { ListTablesCommandOutput } = require("@aws-sdk/client-dynamodb"); -const client = new DynamoDB({ region: "us-west-2" }); +const { + STS, + GetCallerIdentityCommandInput, + GetCallerIdentityCommandOutput +} = require("@aws-sdk/client-sts"); +const ddbClient = new DynamoDB({ region: "us-west-2" }); const listTablesInput: ListTablesCommandInput = { Limit: 10 }; -const listTablesOutput: ListTablesCommandOutput = await client - .listTables(listTablesInput); \ No newline at end of file +const listTablesOutput: ListTablesCommandOutput = await ddbClient + .listTables(listTablesInput); + +const stsClient = new STS({ region: "us-west-2" }); +const getCallerIdentityInput: GetCallerIdentityCommandInput = {}; +const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient + .getCallerIdentity(getCallerIdentityInput); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-named.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-named.input.ts index b05def5d9..08cbf05f7 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-named.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-named.input.ts @@ -1,8 +1,14 @@ import DynamoDB, { ListTablesInput, ListTablesOutput } from "aws-sdk/clients/dynamodb"; +import STS, { GetCallerIdentityRequest, GetCallerIdentityResponse } from "aws-sdk/clients/sts"; -const client = new DynamoDB({ region: "us-west-2" }); - +const ddbClient = new DynamoDB({ region: "us-west-2" }); const listTablesInput: ListTablesInput = { Limit: 10 }; -const listTablesOutput: ListTablesOutput = await client +const listTablesOutput: ListTablesOutput = await ddbClient .listTables(listTablesInput) .promise(); + +const stsClient = new STS({ region: "us-west-2" }); +const getCallerIdentityInput: GetCallerIdentityRequest = {}; +const getCallerIdentityOutput: GetCallerIdentityResponse = await stsClient + .getCallerIdentity(getCallerIdentityInput) + .promise(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-named.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-named.output.ts index bce09e280..4d4478858 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-named.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-named.output.ts @@ -1,7 +1,12 @@ import { DynamoDB, ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb"; +import { STS, GetCallerIdentityCommandInput, GetCallerIdentityCommandOutput } from "@aws-sdk/client-sts"; -const client = new DynamoDB({ region: "us-west-2" }); - +const ddbClient = new DynamoDB({ region: "us-west-2" }); const listTablesInput: ListTablesCommandInput = { Limit: 10 }; -const listTablesOutput: ListTablesCommandOutput = await client - .listTables(listTablesInput); \ No newline at end of file +const listTablesOutput: ListTablesCommandOutput = await ddbClient + .listTables(listTablesInput); + +const stsClient = new STS({ region: "us-west-2" }); +const getCallerIdentityInput: GetCallerIdentityCommandInput = {}; +const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient + .getCallerIdentity(getCallerIdentityInput); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import.input.ts index 0c7b9075a..13f5c599c 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import.input.ts @@ -1,8 +1,14 @@ import DynamoDB from "aws-sdk/clients/dynamodb"; +import STS from "aws-sdk/clients/sts"; -const client = new DynamoDB({ region: "us-west-2" }); - +const ddbClient = new DynamoDB({ region: "us-west-2" }); const listTablesInput: DynamoDB.ListTablesInput = { Limit: 10 }; -const listTablesOutput: DynamoDB.ListTablesOutput = await client +const listTablesOutput: DynamoDB.ListTablesOutput = await ddbClient .listTables(listTablesInput) .promise(); + +const stsClient = new STS({ region: "us-west-2" }); +const getCallerIdentityInput: STS.GetCallerIdentityRequest = {}; +const getCallerIdentityOutput: STS.GetCallerIdentityResponse = await stsClient + .getCallerIdentity(getCallerIdentityInput) + .promise(); diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import.output.ts index bce09e280..4d4478858 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import.output.ts @@ -1,7 +1,12 @@ import { DynamoDB, ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb"; +import { STS, GetCallerIdentityCommandInput, GetCallerIdentityCommandOutput } from "@aws-sdk/client-sts"; -const client = new DynamoDB({ region: "us-west-2" }); - +const ddbClient = new DynamoDB({ region: "us-west-2" }); const listTablesInput: ListTablesCommandInput = { Limit: 10 }; -const listTablesOutput: ListTablesCommandOutput = await client - .listTables(listTablesInput); \ No newline at end of file +const listTablesOutput: ListTablesCommandOutput = await ddbClient + .listTables(listTablesInput); + +const stsClient = new STS({ region: "us-west-2" }); +const getCallerIdentityInput: GetCallerIdentityCommandInput = {}; +const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient + .getCallerIdentity(getCallerIdentityInput); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-require.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-require.input.ts index f6980aea5..1fb458445 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-require.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-require.input.ts @@ -1,8 +1,14 @@ const DynamoDB = require("aws-sdk/clients/dynamodb"); +const STS = require("aws-sdk/clients/sts"); -const client = new DynamoDB({ region: "us-west-2" }); - +const ddbClient = new DynamoDB({ region: "us-west-2" }); const listTablesInput: DynamoDB.ListTablesInput = { Limit: 10 }; -const listTablesOutput: DynamoDB.ListTablesOutput = await client +const listTablesOutput: DynamoDB.ListTablesOutput = await ddbClient .listTables(listTablesInput) .promise(); + +const stsClient = new STS({ region: "us-west-2" }); +const getCallerIdentityInput: STS.GetCallerIdentityRequest = {}; +const getCallerIdentityOutput: STS.GetCallerIdentityResponse = await stsClient + .getCallerIdentity(getCallerIdentityInput) + .promise(); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-require.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-require.output.ts index a2b41be17..0211f4f3a 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-require.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-require.output.ts @@ -3,9 +3,18 @@ const { ListTablesCommandInput, ListTablesCommandOutput } = require("@aws-sdk/client-dynamodb"); +const { + STS, + GetCallerIdentityCommandInput, + GetCallerIdentityCommandOutput +} = require("@aws-sdk/client-sts"); -const client = new DynamoDB({ region: "us-west-2" }); - +const ddbClient = new DynamoDB({ region: "us-west-2" }); const listTablesInput: ListTablesCommandInput = { Limit: 10 }; -const listTablesOutput: ListTablesCommandOutput = await client - .listTables(listTablesInput); \ No newline at end of file +const listTablesOutput: ListTablesCommandOutput = await ddbClient + .listTables(listTablesInput); + +const stsClient = new STS({ region: "us-west-2" }); +const getCallerIdentityInput: GetCallerIdentityCommandInput = {}; +const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient + .getCallerIdentity(getCallerIdentityInput); \ No newline at end of file diff --git a/src/transforms/v2-to-v3/utils/config/constants.ts b/src/transforms/v2-to-v3/utils/config/constants.ts index 8a84c1d62..216ff6606 100644 --- a/src/transforms/v2-to-v3/utils/config/constants.ts +++ b/src/transforms/v2-to-v3/utils/config/constants.ts @@ -1,5 +1,4 @@ export const PACKAGE_NAME = "aws-sdk"; -// ToDo: Add Request and Response suffixes in future version. -export const V2_CLIENT_INPUT_SUFFIX_LIST = ["Input"]; -export const V2_CLIENT_OUTPUT_SUFFIX_LIST = ["Output"]; +export const V2_CLIENT_INPUT_SUFFIX_LIST = ["Input", "Request"]; +export const V2_CLIENT_OUTPUT_SUFFIX_LIST = ["Output", "Response"];