Skip to content

Commit 536132b

Browse files
authored
Use named imports while transforming require/import (#603)
1 parent 9d2ac24 commit 536132b

29 files changed

+229
-353
lines changed

.changeset/khaki-cheetahs-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"aws-sdk-js-codemod": minor
3+
---
4+
5+
Use named imports while transforming require/import
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import * as AWS_S3 from "@aws-sdk/client-s3";
1+
import { Tag } from "@aws-sdk/client-s3";
22

3-
const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
3+
const testTags: Tag[] = [{ Key: "key", Value: "value" }];
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import * as AWS_S3 from "@aws-sdk/client-s3";
1+
import { Tag } from "@aws-sdk/client-s3";
22

3-
const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
3+
const testTags: Tag[] = [{ Key: "key", Value: "value" }];
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import * as AWS_S3 from "@aws-sdk/client-s3";
1+
import { Tag } from "@aws-sdk/client-s3";
22

3-
const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
3+
const testTags: Tag[] = [{ Key: "key", Value: "value" }];
Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
1-
import * as AWS_DynamoDB from "@aws-sdk/client-dynamodb";
2-
3-
const {
4-
DynamoDB
5-
} = AWS_DynamoDB;
6-
7-
import * as AWS_Lambda from "@aws-sdk/client-lambda";
8-
9-
const {
10-
Lambda
11-
} = AWS_Lambda;
12-
13-
import * as AWS_STS from "@aws-sdk/client-sts";
14-
15-
const {
16-
STS
17-
} = AWS_STS;
1+
import { DynamoDB, ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb";
2+
import { InvokeCommandInput, InvokeCommandOutput, Lambda } from "@aws-sdk/client-lambda";
3+
import { GetCallerIdentityCommandInput, GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts";
184

195
const ddbClient = new DynamoDB({ region: "us-west-2" });
20-
const listTablesInput: AWS_DynamoDB.ListTablesCommandInput = { Limit: 10 };
21-
const listTablesOutput: AWS_DynamoDB.ListTablesCommandOutput = await ddbClient
6+
const listTablesInput: ListTablesCommandInput = { Limit: 10 };
7+
const listTablesOutput: ListTablesCommandOutput = await ddbClient
228
.listTables(listTablesInput);
239

2410
const stsClient = new STS({ region: "us-west-2" });
25-
const getCallerIdentityInput: AWS_STS.GetCallerIdentityCommandInput = {};
26-
const getCallerIdentityOutput: AWS_STS.GetCallerIdentityCommandOutput = await stsClient
11+
const getCallerIdentityInput: GetCallerIdentityCommandInput = {};
12+
const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient
2713
.getCallerIdentity(getCallerIdentityInput);
2814

2915
const lambdaClient = new Lambda({ region: "us-west-2" });
30-
const invokeInput: AWS_Lambda.InvokeCommandInput = { FunctionName: "my-function" };
31-
const invokeOutput: AWS_Lambda.InvokeCommandOutput = await lambdaClient
16+
const invokeInput: InvokeCommandInput = { FunctionName: "my-function" };
17+
const invokeOutput: InvokeCommandOutput = await lambdaClient
3218
.invoke(invokeInput);
Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
1-
import * as AWS_DynamoDB from "@aws-sdk/client-dynamodb";
2-
3-
const {
4-
DynamoDB
5-
} = AWS_DynamoDB;
6-
7-
import * as AWS_Lambda from "@aws-sdk/client-lambda";
8-
9-
const {
10-
Lambda
11-
} = AWS_Lambda;
12-
13-
import * as AWS_STS from "@aws-sdk/client-sts";
14-
15-
const {
16-
STS
17-
} = AWS_STS;
1+
import { DynamoDB, ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb";
2+
import { InvokeCommandInput, InvokeCommandOutput, Lambda } from "@aws-sdk/client-lambda";
3+
import { GetCallerIdentityCommandInput, GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts";
184

195
const ddbClient = new DynamoDB({ region: "us-west-2" });
20-
const listTablesInput: AWS_DynamoDB.ListTablesCommandInput = { Limit: 10 };
21-
const listTablesOutput: AWS_DynamoDB.ListTablesCommandOutput = await ddbClient
6+
const listTablesInput: ListTablesCommandInput = { Limit: 10 };
7+
const listTablesOutput: ListTablesCommandOutput = await ddbClient
228
.listTables(listTablesInput);
239

2410
const stsClient = new STS({ region: "us-west-2" });
25-
const getCallerIdentityInput: AWS_STS.GetCallerIdentityCommandInput = {};
26-
const getCallerIdentityOutput: AWS_STS.GetCallerIdentityCommandOutput = await stsClient
11+
const getCallerIdentityInput: GetCallerIdentityCommandInput = {};
12+
const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient
2713
.getCallerIdentity(getCallerIdentityInput);
2814

2915
const lambdaClient = new Lambda({ region: "us-west-2" });
30-
const invokeInput: AWS_Lambda.InvokeCommandInput = { FunctionName: "my-function" };
31-
const invokeOutput: AWS_Lambda.InvokeCommandOutput = await lambdaClient
16+
const invokeInput: InvokeCommandInput = { FunctionName: "my-function" };
17+
const invokeOutput: InvokeCommandOutput = await lambdaClient
3218
.invoke(invokeInput);
Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
1-
import * as AWS_DynamoDB from "@aws-sdk/client-dynamodb";
2-
3-
const {
4-
DynamoDB
5-
} = AWS_DynamoDB;
6-
7-
import * as AWS_Lambda from "@aws-sdk/client-lambda";
8-
9-
const {
10-
Lambda
11-
} = AWS_Lambda;
12-
13-
import * as AWS_STS from "@aws-sdk/client-sts";
14-
15-
const {
16-
STS
17-
} = AWS_STS;
1+
import { DynamoDB, ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb";
2+
import { InvokeCommandInput, InvokeCommandOutput, Lambda } from "@aws-sdk/client-lambda";
3+
import { GetCallerIdentityCommandInput, GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts";
184

195
const ddbClient = new DynamoDB({ region: "us-west-2" });
20-
const listTablesInput: AWS_DynamoDB.ListTablesCommandInput = { Limit: 10 };
21-
const listTablesOutput: AWS_DynamoDB.ListTablesCommandOutput = await ddbClient
6+
const listTablesInput: ListTablesCommandInput = { Limit: 10 };
7+
const listTablesOutput: ListTablesCommandOutput = await ddbClient
228
.listTables(listTablesInput);
239

2410
const stsClient = new STS({ region: "us-west-2" });
25-
const getCallerIdentityInput: AWS_STS.GetCallerIdentityCommandInput = {};
26-
const getCallerIdentityOutput: AWS_STS.GetCallerIdentityCommandOutput = await stsClient
11+
const getCallerIdentityInput: GetCallerIdentityCommandInput = {};
12+
const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient
2713
.getCallerIdentity(getCallerIdentityInput);
2814

2915
const lambdaClient = new Lambda({ region: "us-west-2" });
30-
const invokeInput: AWS_Lambda.InvokeCommandInput = { FunctionName: "my-function" };
31-
const invokeOutput: AWS_Lambda.InvokeCommandOutput = await lambdaClient
16+
const invokeInput: InvokeCommandInput = { FunctionName: "my-function" };
17+
const invokeOutput: InvokeCommandOutput = await lambdaClient
3218
.invoke(invokeInput);

src/transforms/v2-to-v3/__fixtures__/api-redundant-type/global-import.output.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as AWS_APIGateway from "@aws-sdk/client-api-gateway";
2-
import * as AWS_DynamoDB from "@aws-sdk/client-dynamodb";
3-
import * as AWS_S3 from "@aws-sdk/client-s3";
1+
import { MethodSnapshot } from "@aws-sdk/client-api-gateway";
2+
import { AttributeValue } from "@aws-sdk/client-dynamodb";
3+
import { Bucket, ChecksumAlgorithm } from "@aws-sdk/client-s3";
44

55
// Native types
66
const stringType: string = "string";
@@ -18,14 +18,14 @@ const stringArray: Array<string> = ["string1", "string2"];
1818
const booleanArray: Array<boolean> = [true, false];
1919
const numberArray: Array<number> = [123, 456];
2020
const blobArray: Array<Uint8Array> = [new Uint8Array()];
21-
const enumArray: Array<AWS_S3.ChecksumAlgorithm> = ["CRC32"];
22-
const structureArray: Array<AWS_S3.Bucket> = [{ Name: "bucketName" }];
21+
const enumArray: Array<ChecksumAlgorithm> = ["CRC32"];
22+
const structureArray: Array<Bucket> = [{ Name: "bucketName" }];
2323

2424
// Maps
2525
const stringMap: Record<string, string> = { key: "value" };
2626
const booleanMap: Record<string, boolean> = { key: true };
2727
const numberMap: Record<string, number> = { key: 123 };
28-
const structureMap: Record<string, AWS_APIGateway.MethodSnapshot> = { key: { apiKeyRequired: true } };
28+
const structureMap: Record<string, MethodSnapshot> = { key: { apiKeyRequired: true } };
2929

3030
// Nested arrays
3131
const arrayNestedTwice: Array<Array<number>> = [[1, 2], [3, 4]];
@@ -37,12 +37,12 @@ const arrayNestedFour: Array<Array<Array<Array<number>>>> = [
3737

3838
// Nested maps
3939
const mapNestedTwice: Record<string, Record<string, string>> = { key: stringMap };
40-
const mapNestedTwiceStruct: Record<string, Record<string, AWS_APIGateway.MethodSnapshot>> = { key: structureMap };
40+
const mapNestedTwiceStruct: Record<string, Record<string, MethodSnapshot>> = { key: structureMap };
4141

4242
// Nested arrays and maps
4343
const mapOfArrays: Record<string, Array<string>> = { key: ["value"] };
4444
const mapOfMapOfArrays: Record<string, Record<string, Array<string>>> = { key: mapOfArrays };
45-
const mapOfArrayOfMaps: Record<string, Array<Record<string, AWS_DynamoDB.AttributeValue>>> = { key: [{ key: { S:"A" }}] };
45+
const mapOfArrayOfMaps: Record<string, Array<Record<string, AttributeValue>>> = { key: [{ key: { S:"A" }}] };
4646
const mapOfArrayOfArrays: Record<string, Array<Array<number>>> = { key: [[1], [2]] };
4747
const arrayOfMaps: Array<Record<string, string>> = [stringMap];
4848
const arrayOfMapOfArrays: Array<Record<string, Array<string>>> = [mapOfArrays];

src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import-deep.output.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as AWS_APIGateway from "@aws-sdk/client-api-gateway";
2-
import * as AWS_DynamoDB from "@aws-sdk/client-dynamodb";
3-
import * as AWS_S3 from "@aws-sdk/client-s3";
1+
import { MethodSnapshot } from "@aws-sdk/client-api-gateway";
2+
import { AttributeValue } from "@aws-sdk/client-dynamodb";
3+
import { Bucket, ChecksumAlgorithm } from "@aws-sdk/client-s3";
44

55
// Native types
66
const stringType: string = "string";
@@ -18,14 +18,14 @@ const stringArray: Array<string> = ["string1", "string2"];
1818
const booleanArray: Array<boolean> = [true, false];
1919
const numberArray: Array<number> = [123, 456];
2020
const blobArray: Array<Uint8Array> = [new Uint8Array()];
21-
const enumArray: Array<AWS_S3.ChecksumAlgorithm> = ["CRC32"];
22-
const structureArray: Array<AWS_S3.Bucket> = [{ Name: "bucketName" }];
21+
const enumArray: Array<ChecksumAlgorithm> = ["CRC32"];
22+
const structureArray: Array<Bucket> = [{ Name: "bucketName" }];
2323

2424
// Maps
2525
const stringMap: Record<string, string> = { key: "value" };
2626
const booleanMap: Record<string, boolean> = { key: true };
2727
const numberMap: Record<string, number> = { key: 123 };
28-
const structureMap: Record<string, AWS_APIGateway.MethodSnapshot> = { key: { apiKeyRequired: true } };
28+
const structureMap: Record<string, MethodSnapshot> = { key: { apiKeyRequired: true } };
2929

3030
// Nested arrays
3131
const arrayNestedTwice: Array<Array<number>> = [[1, 2], [3, 4]];
@@ -37,12 +37,12 @@ const arrayNestedFour: Array<Array<Array<Array<number>>>> = [
3737

3838
// Nested maps
3939
const mapNestedTwice: Record<string, Record<string, string>> = { key: stringMap };
40-
const mapNestedTwiceStruct: Record<string, Record<string, AWS_APIGateway.MethodSnapshot>> = { key: structureMap };
40+
const mapNestedTwiceStruct: Record<string, Record<string, MethodSnapshot>> = { key: structureMap };
4141

4242
// Nested arrays and maps
4343
const mapOfArrays: Record<string, Array<string>> = { key: ["value"] };
4444
const mapOfMapOfArrays: Record<string, Record<string, Array<string>>> = { key: mapOfArrays };
45-
const mapOfArrayOfMaps: Record<string, Array<Record<string, AWS_DynamoDB.AttributeValue>>> = { key: [{ key: { S:"A" }}] };
45+
const mapOfArrayOfMaps: Record<string, Array<Record<string, AttributeValue>>> = { key: [{ key: { S:"A" }}] };
4646
const mapOfArrayOfArrays: Record<string, Array<Array<number>>> = { key: [[1], [2]] };
4747
const arrayOfMaps: Array<Record<string, string>> = [stringMap];
4848
const arrayOfMapOfArrays: Array<Record<string, Array<string>>> = [mapOfArrays];

src/transforms/v2-to-v3/__fixtures__/api-redundant-type/service-import.output.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as AWS_APIGateway from "@aws-sdk/client-api-gateway";
2-
import * as AWS_DynamoDB from "@aws-sdk/client-dynamodb";
3-
import * as AWS_S3 from "@aws-sdk/client-s3";
1+
import { MethodSnapshot } from "@aws-sdk/client-api-gateway";
2+
import { AttributeValue } from "@aws-sdk/client-dynamodb";
3+
import { Bucket, ChecksumAlgorithm } from "@aws-sdk/client-s3";
44

55
// Native types
66
const stringType: string = "string";
@@ -18,14 +18,14 @@ const stringArray: Array<string> = ["string1", "string2"];
1818
const booleanArray: Array<boolean> = [true, false];
1919
const numberArray: Array<number> = [123, 456];
2020
const blobArray: Array<Uint8Array> = [new Uint8Array()];
21-
const enumArray: Array<AWS_S3.ChecksumAlgorithm> = ["CRC32"];
22-
const structureArray: Array<AWS_S3.Bucket> = [{ Name: "bucketName" }];
21+
const enumArray: Array<ChecksumAlgorithm> = ["CRC32"];
22+
const structureArray: Array<Bucket> = [{ Name: "bucketName" }];
2323

2424
// Maps
2525
const stringMap: Record<string, string> = { key: "value" };
2626
const booleanMap: Record<string, boolean> = { key: true };
2727
const numberMap: Record<string, number> = { key: 123 };
28-
const structureMap: Record<string, AWS_APIGateway.MethodSnapshot> = { key: { apiKeyRequired: true } };
28+
const structureMap: Record<string, MethodSnapshot> = { key: { apiKeyRequired: true } };
2929

3030
// Nested arrays
3131
const arrayNestedTwice: Array<Array<number>> = [[1, 2], [3, 4]];
@@ -37,12 +37,12 @@ const arrayNestedFour: Array<Array<Array<Array<number>>>> = [
3737

3838
// Nested maps
3939
const mapNestedTwice: Record<string, Record<string, string>> = { key: stringMap };
40-
const mapNestedTwiceStruct: Record<string, Record<string, AWS_APIGateway.MethodSnapshot>> = { key: structureMap };
40+
const mapNestedTwiceStruct: Record<string, Record<string, MethodSnapshot>> = { key: structureMap };
4141

4242
// Nested arrays and maps
4343
const mapOfArrays: Record<string, Array<string>> = { key: ["value"] };
4444
const mapOfMapOfArrays: Record<string, Record<string, Array<string>>> = { key: mapOfArrays };
45-
const mapOfArrayOfMaps: Record<string, Array<Record<string, AWS_DynamoDB.AttributeValue>>> = { key: [{ key: { S:"A" }}] };
45+
const mapOfArrayOfMaps: Record<string, Array<Record<string, AttributeValue>>> = { key: [{ key: { S:"A" }}] };
4646
const mapOfArrayOfArrays: Record<string, Array<Array<number>>> = { key: [[1], [2]] };
4747
const arrayOfMaps: Array<Record<string, string>> = [stringMap];
4848
const arrayOfMapOfArrays: Array<Record<string, Array<string>>> = [mapOfArrays];

0 commit comments

Comments
 (0)