diff --git a/.changeset/hot-dancers-count.md b/.changeset/hot-dancers-count.md new file mode 100644 index 000000000..9d6eb63a2 --- /dev/null +++ b/.changeset/hot-dancers-count.md @@ -0,0 +1,5 @@ +--- +"aws-sdk-js-codemod": patch +--- + +Transform types imported without clients diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import-equals.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import-equals.input.ts index a23d0672f..c54d821c6 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import-equals.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import-equals.input.ts @@ -1,19 +1,10 @@ import AWS = require("aws-sdk"); -const ddbClient = new AWS.DynamoDB(); const listTablesInput: AWS.DynamoDB.ListTablesInput = { Limit: 10 }; -const listTablesOutput: AWS.DynamoDB.ListTablesOutput = await ddbClient - .listTables(listTablesInput) - .promise(); +const listTablesOutput: AWS.DynamoDB.ListTablesOutput = {}; -const stsClient = new AWS.STS(); const getCallerIdentityInput: AWS.STS.GetCallerIdentityRequest = {}; -const getCallerIdentityOutput: AWS.STS.GetCallerIdentityResponse = await stsClient - .getCallerIdentity(getCallerIdentityInput) - .promise(); +const getCallerIdentityOutput: AWS.STS.GetCallerIdentityResponse = {}; -const lambdaClient = new AWS.Lambda(); const invokeInput: AWS.Lambda.InvocationRequest = { FunctionName: "my-function" }; -const invokeOutput: AWS.Lambda.InvocationResponse = await lambdaClient - .invoke(invokeInput) - .promise(); \ No newline at end of file +const invokeOutput: AWS.Lambda.InvocationResponse = {}; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import-equals.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import-equals.output.ts index 4b9ccc1f6..7e27e829b 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import-equals.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/global-import-equals.output.ts @@ -1,27 +1,18 @@ import AWS_client_dynamodb = require("@aws-sdk/client-dynamodb"); -import DynamoDB = AWS_client_dynamodb.DynamoDB; import ListTablesCommandOutput = AWS_client_dynamodb.ListTablesCommandOutput; import ListTablesCommandInput = AWS_client_dynamodb.ListTablesCommandInput; import AWS_client_lambda = require("@aws-sdk/client-lambda"); -import Lambda = AWS_client_lambda.Lambda; import InvokeCommandOutput = AWS_client_lambda.InvokeCommandOutput; import InvokeCommandInput = AWS_client_lambda.InvokeCommandInput; import AWS_client_sts = require("@aws-sdk/client-sts"); -import STS = AWS_client_sts.STS; import GetCallerIdentityCommandOutput = AWS_client_sts.GetCallerIdentityCommandOutput; import GetCallerIdentityCommandInput = AWS_client_sts.GetCallerIdentityCommandInput; -const ddbClient = new DynamoDB(); const listTablesInput: ListTablesCommandInput = { Limit: 10 }; -const listTablesOutput: ListTablesCommandOutput = await ddbClient - .listTables(listTablesInput); +const listTablesOutput: ListTablesCommandOutput = {}; -const stsClient = new STS(); const getCallerIdentityInput: GetCallerIdentityCommandInput = {}; -const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient - .getCallerIdentity(getCallerIdentityInput); +const getCallerIdentityOutput: GetCallerIdentityCommandOutput = {}; -const lambdaClient = new Lambda(); const invokeInput: InvokeCommandInput = { FunctionName: "my-function" }; -const invokeOutput: InvokeCommandOutput = await lambdaClient - .invoke(invokeInput); \ No newline at end of file +const invokeOutput: InvokeCommandOutput = {}; \ No newline at end of file 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 77b97a50a..0551fca40 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,19 +1,10 @@ import AWS from "aws-sdk"; -const ddbClient = new AWS.DynamoDB(); const listTablesInput: AWS.DynamoDB.ListTablesInput = { Limit: 10 }; -const listTablesOutput: AWS.DynamoDB.ListTablesOutput = await ddbClient - .listTables(listTablesInput) - .promise(); +const listTablesOutput: AWS.DynamoDB.ListTablesOutput = {}; -const stsClient = new AWS.STS(); const getCallerIdentityInput: AWS.STS.GetCallerIdentityRequest = {}; -const getCallerIdentityOutput: AWS.STS.GetCallerIdentityResponse = await stsClient - .getCallerIdentity(getCallerIdentityInput) - .promise(); +const getCallerIdentityOutput: AWS.STS.GetCallerIdentityResponse = {}; -const lambdaClient = new AWS.Lambda(); const invokeInput: AWS.Lambda.InvocationRequest = { FunctionName: "my-function" }; -const invokeOutput: AWS.Lambda.InvocationResponse = await lambdaClient - .invoke(invokeInput) - .promise(); +const invokeOutput: AWS.Lambda.InvocationResponse = {}; 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 606d75fce..68a28fb27 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,18 +1,12 @@ -import { DynamoDB, ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb"; -import { InvokeCommandInput, InvokeCommandOutput, Lambda } from "@aws-sdk/client-lambda"; -import { GetCallerIdentityCommandInput, GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts"; +import { ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb"; +import { InvokeCommandInput, InvokeCommandOutput } from "@aws-sdk/client-lambda"; +import { GetCallerIdentityCommandInput, GetCallerIdentityCommandOutput } from "@aws-sdk/client-sts"; -const ddbClient = new DynamoDB(); const listTablesInput: ListTablesCommandInput = { Limit: 10 }; -const listTablesOutput: ListTablesCommandOutput = await ddbClient - .listTables(listTablesInput); +const listTablesOutput: ListTablesCommandOutput = {}; -const stsClient = new STS(); const getCallerIdentityInput: GetCallerIdentityCommandInput = {}; -const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient - .getCallerIdentity(getCallerIdentityInput); +const getCallerIdentityOutput: GetCallerIdentityCommandOutput = {}; -const lambdaClient = new Lambda(); const invokeInput: InvokeCommandInput = { FunctionName: "my-function" }; -const invokeOutput: InvokeCommandOutput = await lambdaClient - .invoke(invokeInput); \ No newline at end of file +const invokeOutput: InvokeCommandOutput = {}; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-deep.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-deep.input.ts index e5053152c..82e20f98c 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-deep.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-deep.input.ts @@ -1,21 +1,12 @@ -import DynamoDB, { ListTablesInput, ListTablesOutput } from "aws-sdk/clients/dynamodb"; -import Lambda, { InvocationRequest, InvocationResponse } from "aws-sdk/clients/lambda"; -import STS, { GetCallerIdentityRequest, GetCallerIdentityResponse } from "aws-sdk/clients/sts"; +import { ListTablesInput, ListTablesOutput } from "aws-sdk/clients/dynamodb"; +import { InvocationRequest, InvocationResponse } from "aws-sdk/clients/lambda"; +import { GetCallerIdentityRequest, GetCallerIdentityResponse } from "aws-sdk/clients/sts"; -const ddbClient = new DynamoDB(); const listTablesInput: ListTablesInput = { Limit: 10 }; -const listTablesOutput: ListTablesOutput = await ddbClient - .listTables(listTablesInput) - .promise(); +const listTablesOutput: ListTablesOutput = {}; -const stsClient = new STS(); const getCallerIdentityInput: GetCallerIdentityRequest = {}; -const getCallerIdentityOutput: GetCallerIdentityResponse = await stsClient - .getCallerIdentity(getCallerIdentityInput) - .promise(); +const getCallerIdentityOutput: GetCallerIdentityResponse = {}; -const lambdaClient = new Lambda(); const invokeInput: InvocationRequest = { FunctionName: "my-function" }; -const invokeOutput: InvocationResponse = await lambdaClient - .invoke(invokeInput) - .promise(); \ No newline at end of file +const invokeOutput: InvocationResponse = {}; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-deep.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-deep.output.ts index 606d75fce..68a28fb27 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-deep.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-deep.output.ts @@ -1,18 +1,12 @@ -import { DynamoDB, ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb"; -import { InvokeCommandInput, InvokeCommandOutput, Lambda } from "@aws-sdk/client-lambda"; -import { GetCallerIdentityCommandInput, GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts"; +import { ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb"; +import { InvokeCommandInput, InvokeCommandOutput } from "@aws-sdk/client-lambda"; +import { GetCallerIdentityCommandInput, GetCallerIdentityCommandOutput } from "@aws-sdk/client-sts"; -const ddbClient = new DynamoDB(); const listTablesInput: ListTablesCommandInput = { Limit: 10 }; -const listTablesOutput: ListTablesCommandOutput = await ddbClient - .listTables(listTablesInput); +const listTablesOutput: ListTablesCommandOutput = {}; -const stsClient = new STS(); const getCallerIdentityInput: GetCallerIdentityCommandInput = {}; -const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient - .getCallerIdentity(getCallerIdentityInput); +const getCallerIdentityOutput: GetCallerIdentityCommandOutput = {}; -const lambdaClient = new Lambda(); const invokeInput: InvokeCommandInput = { FunctionName: "my-function" }; -const invokeOutput: InvokeCommandOutput = await lambdaClient - .invoke(invokeInput); \ No newline at end of file +const invokeOutput: InvokeCommandOutput = {}; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-equals.input.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-equals.input.ts index e70093f19..e9679ac2f 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-equals.input.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-equals.input.ts @@ -2,20 +2,11 @@ import DynamoDB = require("aws-sdk/clients/dynamodb"); import Lambda = require("aws-sdk/clients/lambda"); import STS = require("aws-sdk/clients/sts"); -const ddbClient = new DynamoDB(); const listTablesInput: DynamoDB.ListTablesInput = { Limit: 10 }; -const listTablesOutput: DynamoDB.ListTablesOutput = await ddbClient - .listTables(listTablesInput) - .promise(); +const listTablesOutput: DynamoDB.ListTablesOutput = {}; -const stsClient = new STS(); const getCallerIdentityInput: STS.GetCallerIdentityRequest = {}; -const getCallerIdentityOutput: STS.GetCallerIdentityResponse = await stsClient - .getCallerIdentity(getCallerIdentityInput) - .promise(); +const getCallerIdentityOutput: STS.GetCallerIdentityResponse = {}; -const lambdaClient = new Lambda(); const invokeInput: Lambda.InvocationRequest = { FunctionName: "my-function" }; -const invokeOutput: Lambda.InvocationResponse = await lambdaClient - .invoke(invokeInput) - .promise(); \ No newline at end of file +const invokeOutput: Lambda.InvocationResponse = {}; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-equals.output.ts b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-equals.output.ts index 4b9ccc1f6..7e27e829b 100644 --- a/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-equals.output.ts +++ b/src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-equals.output.ts @@ -1,27 +1,18 @@ import AWS_client_dynamodb = require("@aws-sdk/client-dynamodb"); -import DynamoDB = AWS_client_dynamodb.DynamoDB; import ListTablesCommandOutput = AWS_client_dynamodb.ListTablesCommandOutput; import ListTablesCommandInput = AWS_client_dynamodb.ListTablesCommandInput; import AWS_client_lambda = require("@aws-sdk/client-lambda"); -import Lambda = AWS_client_lambda.Lambda; import InvokeCommandOutput = AWS_client_lambda.InvokeCommandOutput; import InvokeCommandInput = AWS_client_lambda.InvokeCommandInput; import AWS_client_sts = require("@aws-sdk/client-sts"); -import STS = AWS_client_sts.STS; import GetCallerIdentityCommandOutput = AWS_client_sts.GetCallerIdentityCommandOutput; import GetCallerIdentityCommandInput = AWS_client_sts.GetCallerIdentityCommandInput; -const ddbClient = new DynamoDB(); const listTablesInput: ListTablesCommandInput = { Limit: 10 }; -const listTablesOutput: ListTablesCommandOutput = await ddbClient - .listTables(listTablesInput); +const listTablesOutput: ListTablesCommandOutput = {}; -const stsClient = new STS(); const getCallerIdentityInput: GetCallerIdentityCommandInput = {}; -const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient - .getCallerIdentity(getCallerIdentityInput); +const getCallerIdentityOutput: GetCallerIdentityCommandOutput = {}; -const lambdaClient = new Lambda(); const invokeInput: InvokeCommandInput = { FunctionName: "my-function" }; -const invokeOutput: InvokeCommandOutput = await lambdaClient - .invoke(invokeInput); \ No newline at end of file +const invokeOutput: InvokeCommandOutput = {}; \ 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 4e9fe21a4..6d311da54 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,20 +1,11 @@ import { DynamoDB, Lambda, STS } from "aws-sdk"; -const ddbClient = new DynamoDB(); const listTablesInput: DynamoDB.ListTablesInput = { Limit: 10 }; -const listTablesOutput: DynamoDB.ListTablesOutput = await ddbClient - .listTables(listTablesInput) - .promise(); +const listTablesOutput: DynamoDB.ListTablesOutput = {}; -const stsClient = new STS(); const getCallerIdentityInput: STS.GetCallerIdentityRequest = {}; -const getCallerIdentityOutput: STS.GetCallerIdentityResponse = await stsClient - .getCallerIdentity(getCallerIdentityInput) - .promise(); +const getCallerIdentityOutput: STS.GetCallerIdentityResponse = {}; -const lambdaClient = new Lambda(); const invokeInput: Lambda.InvocationRequest = { FunctionName: "my-function" }; -const invokeOutput: Lambda.InvocationResponse = await lambdaClient - .invoke(invokeInput) - .promise(); +const invokeOutput: Lambda.InvocationResponse = {}; \ No newline at end of file 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 606d75fce..68a28fb27 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,18 +1,12 @@ -import { DynamoDB, ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb"; -import { InvokeCommandInput, InvokeCommandOutput, Lambda } from "@aws-sdk/client-lambda"; -import { GetCallerIdentityCommandInput, GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts"; +import { ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb"; +import { InvokeCommandInput, InvokeCommandOutput } from "@aws-sdk/client-lambda"; +import { GetCallerIdentityCommandInput, GetCallerIdentityCommandOutput } from "@aws-sdk/client-sts"; -const ddbClient = new DynamoDB(); const listTablesInput: ListTablesCommandInput = { Limit: 10 }; -const listTablesOutput: ListTablesCommandOutput = await ddbClient - .listTables(listTablesInput); +const listTablesOutput: ListTablesCommandOutput = {}; -const stsClient = new STS(); const getCallerIdentityInput: GetCallerIdentityCommandInput = {}; -const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient - .getCallerIdentity(getCallerIdentityInput); +const getCallerIdentityOutput: GetCallerIdentityCommandOutput = {}; -const lambdaClient = new Lambda(); const invokeInput: InvokeCommandInput = { FunctionName: "my-function" }; -const invokeOutput: InvokeCommandOutput = await lambdaClient - .invoke(invokeInput); \ No newline at end of file +const invokeOutput: InvokeCommandOutput = {}; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/misc/unsupported-type-import.input.ts b/src/transforms/v2-to-v3/__fixtures__/misc/unsupported-type-import.input.ts deleted file mode 100644 index 99199e845..000000000 --- a/src/transforms/v2-to-v3/__fixtures__/misc/unsupported-type-import.input.ts +++ /dev/null @@ -1,3 +0,0 @@ -// ToDo: Update when transformation is added. -// Current test verifies error is not thrown. -import { ListTablesInputLimit } from "aws-sdk/clients/dynamodb"; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/__fixtures__/misc/unsupported-type-import.output.ts b/src/transforms/v2-to-v3/__fixtures__/misc/unsupported-type-import.output.ts deleted file mode 100644 index 99199e845..000000000 --- a/src/transforms/v2-to-v3/__fixtures__/misc/unsupported-type-import.output.ts +++ /dev/null @@ -1,3 +0,0 @@ -// ToDo: Update when transformation is added. -// Current test verifies error is not thrown. -import { ListTablesInputLimit } from "aws-sdk/clients/dynamodb"; \ No newline at end of file diff --git a/src/transforms/v2-to-v3/client-names/getClientNamesRecord.ts b/src/transforms/v2-to-v3/client-names/getClientNamesRecord.ts index 62f3c2e35..e0e593672 100644 --- a/src/transforms/v2-to-v3/client-names/getClientNamesRecord.ts +++ b/src/transforms/v2-to-v3/client-names/getClientNamesRecord.ts @@ -11,7 +11,19 @@ export const getClientNamesRecord = ( importType: ImportType ) => { const clientNamesFromDeepImport = getClientNamesFromDeepImport(source.toSource()); - return importType === ImportType.REQUIRE - ? getClientNamesRecordFromRequire(j, source, clientNamesFromDeepImport) - : getClientNamesRecordFromImport(j, source, clientNamesFromDeepImport); + + const clientNamesRecord = + importType === ImportType.REQUIRE + ? getClientNamesRecordFromRequire(j, source, clientNamesFromDeepImport) + : getClientNamesRecordFromImport(j, source, clientNamesFromDeepImport); + + // Populate client names for type transformations + // Ref: https://github.com/awslabs/aws-sdk-js-codemod/issues/663 + for (const clientName of clientNamesFromDeepImport) { + if (!(clientName in clientNamesRecord)) { + clientNamesRecord[clientName] = clientName; + } + } + + return clientNamesRecord; };