Skip to content

Commit

Permalink
Use named imports while transforming require/import (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Oct 17, 2023
1 parent 9d2ac24 commit 536132b
Show file tree
Hide file tree
Showing 29 changed files with 229 additions and 353 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-cheetahs-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": minor
---

Use named imports while transforming require/import
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import * as AWS_S3 from "@aws-sdk/client-s3";
import { Tag } from "@aws-sdk/client-s3";

const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
const testTags: Tag[] = [{ Key: "key", Value: "value" }];
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import * as AWS_S3 from "@aws-sdk/client-s3";
import { Tag } from "@aws-sdk/client-s3";

const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
const testTags: Tag[] = [{ Key: "key", Value: "value" }];
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import * as AWS_S3 from "@aws-sdk/client-s3";
import { Tag } from "@aws-sdk/client-s3";

const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
const testTags: Tag[] = [{ Key: "key", Value: "value" }];
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
import * as AWS_DynamoDB from "@aws-sdk/client-dynamodb";

const {
DynamoDB
} = AWS_DynamoDB;

import * as AWS_Lambda from "@aws-sdk/client-lambda";

const {
Lambda
} = AWS_Lambda;

import * as AWS_STS from "@aws-sdk/client-sts";

const {
STS
} = AWS_STS;
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";

const ddbClient = new DynamoDB({ region: "us-west-2" });
const listTablesInput: AWS_DynamoDB.ListTablesCommandInput = { Limit: 10 };
const listTablesOutput: AWS_DynamoDB.ListTablesCommandOutput = await ddbClient
const listTablesInput: ListTablesCommandInput = { Limit: 10 };
const listTablesOutput: ListTablesCommandOutput = await ddbClient
.listTables(listTablesInput);

const stsClient = new STS({ region: "us-west-2" });
const getCallerIdentityInput: AWS_STS.GetCallerIdentityCommandInput = {};
const getCallerIdentityOutput: AWS_STS.GetCallerIdentityCommandOutput = await stsClient
const getCallerIdentityInput: GetCallerIdentityCommandInput = {};
const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient
.getCallerIdentity(getCallerIdentityInput);

const lambdaClient = new Lambda({ region: "us-west-2" });
const invokeInput: AWS_Lambda.InvokeCommandInput = { FunctionName: "my-function" };
const invokeOutput: AWS_Lambda.InvokeCommandOutput = await lambdaClient
const invokeInput: InvokeCommandInput = { FunctionName: "my-function" };
const invokeOutput: InvokeCommandOutput = await lambdaClient
.invoke(invokeInput);
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
import * as AWS_DynamoDB from "@aws-sdk/client-dynamodb";

const {
DynamoDB
} = AWS_DynamoDB;

import * as AWS_Lambda from "@aws-sdk/client-lambda";

const {
Lambda
} = AWS_Lambda;

import * as AWS_STS from "@aws-sdk/client-sts";

const {
STS
} = AWS_STS;
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";

const ddbClient = new DynamoDB({ region: "us-west-2" });
const listTablesInput: AWS_DynamoDB.ListTablesCommandInput = { Limit: 10 };
const listTablesOutput: AWS_DynamoDB.ListTablesCommandOutput = await ddbClient
const listTablesInput: ListTablesCommandInput = { Limit: 10 };
const listTablesOutput: ListTablesCommandOutput = await ddbClient
.listTables(listTablesInput);

const stsClient = new STS({ region: "us-west-2" });
const getCallerIdentityInput: AWS_STS.GetCallerIdentityCommandInput = {};
const getCallerIdentityOutput: AWS_STS.GetCallerIdentityCommandOutput = await stsClient
const getCallerIdentityInput: GetCallerIdentityCommandInput = {};
const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient
.getCallerIdentity(getCallerIdentityInput);

const lambdaClient = new Lambda({ region: "us-west-2" });
const invokeInput: AWS_Lambda.InvokeCommandInput = { FunctionName: "my-function" };
const invokeOutput: AWS_Lambda.InvokeCommandOutput = await lambdaClient
const invokeInput: InvokeCommandInput = { FunctionName: "my-function" };
const invokeOutput: InvokeCommandOutput = await lambdaClient
.invoke(invokeInput);
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
import * as AWS_DynamoDB from "@aws-sdk/client-dynamodb";

const {
DynamoDB
} = AWS_DynamoDB;

import * as AWS_Lambda from "@aws-sdk/client-lambda";

const {
Lambda
} = AWS_Lambda;

import * as AWS_STS from "@aws-sdk/client-sts";

const {
STS
} = AWS_STS;
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";

const ddbClient = new DynamoDB({ region: "us-west-2" });
const listTablesInput: AWS_DynamoDB.ListTablesCommandInput = { Limit: 10 };
const listTablesOutput: AWS_DynamoDB.ListTablesCommandOutput = await ddbClient
const listTablesInput: ListTablesCommandInput = { Limit: 10 };
const listTablesOutput: ListTablesCommandOutput = await ddbClient
.listTables(listTablesInput);

const stsClient = new STS({ region: "us-west-2" });
const getCallerIdentityInput: AWS_STS.GetCallerIdentityCommandInput = {};
const getCallerIdentityOutput: AWS_STS.GetCallerIdentityCommandOutput = await stsClient
const getCallerIdentityInput: GetCallerIdentityCommandInput = {};
const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient
.getCallerIdentity(getCallerIdentityInput);

const lambdaClient = new Lambda({ region: "us-west-2" });
const invokeInput: AWS_Lambda.InvokeCommandInput = { FunctionName: "my-function" };
const invokeOutput: AWS_Lambda.InvokeCommandOutput = await lambdaClient
const invokeInput: InvokeCommandInput = { FunctionName: "my-function" };
const invokeOutput: InvokeCommandOutput = await lambdaClient
.invoke(invokeInput);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as AWS_APIGateway from "@aws-sdk/client-api-gateway";
import * as AWS_DynamoDB from "@aws-sdk/client-dynamodb";
import * as AWS_S3 from "@aws-sdk/client-s3";
import { MethodSnapshot } from "@aws-sdk/client-api-gateway";
import { AttributeValue } from "@aws-sdk/client-dynamodb";
import { Bucket, ChecksumAlgorithm } from "@aws-sdk/client-s3";

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

// Maps
const stringMap: Record<string, string> = { key: "value" };
const booleanMap: Record<string, boolean> = { key: true };
const numberMap: Record<string, number> = { key: 123 };
const structureMap: Record<string, AWS_APIGateway.MethodSnapshot> = { key: { apiKeyRequired: true } };
const structureMap: Record<string, MethodSnapshot> = { key: { apiKeyRequired: true } };

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

// Nested maps
const mapNestedTwice: Record<string, Record<string, string>> = { key: stringMap };
const mapNestedTwiceStruct: Record<string, Record<string, AWS_APIGateway.MethodSnapshot>> = { key: structureMap };
const mapNestedTwiceStruct: Record<string, Record<string, MethodSnapshot>> = { key: structureMap };

// Nested arrays and maps
const mapOfArrays: Record<string, Array<string>> = { key: ["value"] };
const mapOfMapOfArrays: Record<string, Record<string, Array<string>>> = { key: mapOfArrays };
const mapOfArrayOfMaps: Record<string, Array<Record<string, AWS_DynamoDB.AttributeValue>>> = { key: [{ key: { S:"A" }}] };
const mapOfArrayOfMaps: Record<string, Array<Record<string, AttributeValue>>> = { key: [{ key: { S:"A" }}] };
const mapOfArrayOfArrays: Record<string, Array<Array<number>>> = { key: [[1], [2]] };
const arrayOfMaps: Array<Record<string, string>> = [stringMap];
const arrayOfMapOfArrays: Array<Record<string, Array<string>>> = [mapOfArrays];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as AWS_APIGateway from "@aws-sdk/client-api-gateway";
import * as AWS_DynamoDB from "@aws-sdk/client-dynamodb";
import * as AWS_S3 from "@aws-sdk/client-s3";
import { MethodSnapshot } from "@aws-sdk/client-api-gateway";
import { AttributeValue } from "@aws-sdk/client-dynamodb";
import { Bucket, ChecksumAlgorithm } from "@aws-sdk/client-s3";

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

// Maps
const stringMap: Record<string, string> = { key: "value" };
const booleanMap: Record<string, boolean> = { key: true };
const numberMap: Record<string, number> = { key: 123 };
const structureMap: Record<string, AWS_APIGateway.MethodSnapshot> = { key: { apiKeyRequired: true } };
const structureMap: Record<string, MethodSnapshot> = { key: { apiKeyRequired: true } };

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

// Nested maps
const mapNestedTwice: Record<string, Record<string, string>> = { key: stringMap };
const mapNestedTwiceStruct: Record<string, Record<string, AWS_APIGateway.MethodSnapshot>> = { key: structureMap };
const mapNestedTwiceStruct: Record<string, Record<string, MethodSnapshot>> = { key: structureMap };

// Nested arrays and maps
const mapOfArrays: Record<string, Array<string>> = { key: ["value"] };
const mapOfMapOfArrays: Record<string, Record<string, Array<string>>> = { key: mapOfArrays };
const mapOfArrayOfMaps: Record<string, Array<Record<string, AWS_DynamoDB.AttributeValue>>> = { key: [{ key: { S:"A" }}] };
const mapOfArrayOfMaps: Record<string, Array<Record<string, AttributeValue>>> = { key: [{ key: { S:"A" }}] };
const mapOfArrayOfArrays: Record<string, Array<Array<number>>> = { key: [[1], [2]] };
const arrayOfMaps: Array<Record<string, string>> = [stringMap];
const arrayOfMapOfArrays: Array<Record<string, Array<string>>> = [mapOfArrays];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as AWS_APIGateway from "@aws-sdk/client-api-gateway";
import * as AWS_DynamoDB from "@aws-sdk/client-dynamodb";
import * as AWS_S3 from "@aws-sdk/client-s3";
import { MethodSnapshot } from "@aws-sdk/client-api-gateway";
import { AttributeValue } from "@aws-sdk/client-dynamodb";
import { Bucket, ChecksumAlgorithm } from "@aws-sdk/client-s3";

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

// Maps
const stringMap: Record<string, string> = { key: "value" };
const booleanMap: Record<string, boolean> = { key: true };
const numberMap: Record<string, number> = { key: 123 };
const structureMap: Record<string, AWS_APIGateway.MethodSnapshot> = { key: { apiKeyRequired: true } };
const structureMap: Record<string, MethodSnapshot> = { key: { apiKeyRequired: true } };

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

// Nested maps
const mapNestedTwice: Record<string, Record<string, string>> = { key: stringMap };
const mapNestedTwiceStruct: Record<string, Record<string, AWS_APIGateway.MethodSnapshot>> = { key: structureMap };
const mapNestedTwiceStruct: Record<string, Record<string, MethodSnapshot>> = { key: structureMap };

// Nested arrays and maps
const mapOfArrays: Record<string, Array<string>> = { key: ["value"] };
const mapOfMapOfArrays: Record<string, Record<string, Array<string>>> = { key: mapOfArrays };
const mapOfArrayOfMaps: Record<string, Array<Record<string, AWS_DynamoDB.AttributeValue>>> = { key: [{ key: { S:"A" }}] };
const mapOfArrayOfMaps: Record<string, Array<Record<string, AttributeValue>>> = { key: [{ key: { S:"A" }}] };
const mapOfArrayOfArrays: Record<string, Array<Array<number>>> = { key: [[1], [2]] };
const arrayOfMaps: Array<Record<string, string>> = [stringMap];
const arrayOfMapOfArrays: Array<Record<string, Array<string>>> = [mapOfArrays];
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import * as AWS_DynamoDBDocumentClient from "@aws-sdk/lib-dynamodb";

const {
DynamoDBDocument
} = AWS_DynamoDBDocumentClient;

import { DynamoDBDocument, ScanCommandInput, ScanCommandOutput } from "@aws-sdk/lib-dynamodb";
import { DynamoDB } from "@aws-sdk/client-dynamodb";

const docClient = DynamoDBDocument.from(new DynamoDB({ region: "us-west-2" }));

const docClientScanInput: AWS_DynamoDBDocumentClient.ScanCommandInput = {
const docClientScanInput: ScanCommandInput = {
TableName: "TableName"
};

const docClientScanOutput: AWS_DynamoDBDocumentClient.ScanCommandOutput = await docClient
const docClientScanOutput: ScanCommandOutput = await docClient
.scan(docClientScanInput);
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import * as AWS_DynDBDocumentClient from "@aws-sdk/lib-dynamodb";

const {
DynamoDBDocument
} = AWS_DynDBDocumentClient;

import { DynamoDBDocument, ScanCommandInput, ScanCommandOutput } from "@aws-sdk/lib-dynamodb";
import { DynamoDB as DynDB } from "@aws-sdk/client-dynamodb";

const docClient = DynamoDBDocument.from(new DynDB({ region: "us-west-2" }));

const docClientScanInput: AWS_DynDBDocumentClient.ScanCommandInput = {
const docClientScanInput: ScanCommandInput = {
TableName: "TableName"
};

const docClientScanOutput: AWS_DynDBDocumentClient.ScanCommandOutput = await docClient
const docClientScanOutput: ScanCommandOutput = await docClient
.scan(docClientScanInput);
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import * as AWS_DynDBDocumentClient from "@aws-sdk/lib-dynamodb";

const {
DynamoDBDocument
} = AWS_DynDBDocumentClient;

import { DynamoDBDocument, ScanCommandInput, ScanCommandOutput } from "@aws-sdk/lib-dynamodb";
import { DynamoDB as DynDB } from "@aws-sdk/client-dynamodb";

const docClient = DynamoDBDocument.from(new DynDB({ region: "us-west-2" }));

const docClientScanInput: AWS_DynDBDocumentClient.ScanCommandInput = {
const docClientScanInput: ScanCommandInput = {
TableName: "TableName"
};

const docClientScanOutput: AWS_DynDBDocumentClient.ScanCommandOutput = await docClient
const docClientScanOutput: ScanCommandOutput = await docClient
.scan(docClientScanInput);
1 change: 1 addition & 0 deletions src/transforms/v2-to-v3/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./CLIENT_NAMES";
export * from "./CLIENT_NAMES_MAP";
export * from "./CLIENT_PACKAGE_NAMES_MAP";
export * from "./CLIENT_REQ_RESP_TYPES_MAP";
export * from "./CLIENT_TYPES_MAP";
export * from "./constants";
Loading

0 comments on commit 536132b

Please sign in to comment.