-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace named imports for Input/Output types (#216)
- Loading branch information
Showing
12 changed files
with
146 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"aws-sdk-js-codemod": patch | ||
--- | ||
|
||
Replace named imports for Input/Output types |
8 changes: 8 additions & 0 deletions
8
src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-named.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import DynamoDB, { ListTablesInput, ListTablesOutput } from "aws-sdk/clients/dynamodb"; | ||
|
||
const client = new DynamoDB({ region: "us-west-2" }); | ||
|
||
const listTablesInput: ListTablesInput = { Limit: 10 }; | ||
const listTablesOutput: ListTablesOutput = await client | ||
.listTables(listTablesInput) | ||
.promise(); |
7 changes: 7 additions & 0 deletions
7
src/transforms/v2-to-v3/__fixtures__/api-input-output-type/service-import-named.output.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { DynamoDB, ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb"; | ||
|
||
const client = new DynamoDB({ region: "us-west-2" }); | ||
|
||
const listTablesInput: ListTablesCommandInput = { Limit: 10 }; | ||
const listTablesOutput: ListTablesCommandOutput = await client | ||
.listTables(listTablesInput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
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"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { V2_CLIENT_INPUT_SUFFIX_LIST, V2_CLIENT_OUTPUT_SUFFIX_LIST } from "./config"; | ||
|
||
export const isV2ClientInputOutputType = (v2ClientTypeName: string) => | ||
[...V2_CLIENT_INPUT_SUFFIX_LIST, ...V2_CLIENT_OUTPUT_SUFFIX_LIST].some((suffix) => | ||
v2ClientTypeName.endsWith(suffix) | ||
); |
35 changes: 29 additions & 6 deletions
35
src/transforms/v2-to-v3/utils/remove/removeV2ClientModule.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,43 @@ | ||
import { Collection, JSCodeshift } from "jscodeshift"; | ||
|
||
import { containsRequire } from "../containsRequire"; | ||
import { getV2ServiceModulePath } from "../get"; | ||
import { getV2ClientTypeNames, getV2ServiceModulePath } from "../get"; | ||
import { isV2ClientInputOutputType } from "../isV2ClientInputOutputType"; | ||
import { removeImportIdentifierName } from "./removeImportIdentifierName"; | ||
import { removeRequireIdentifierName } from "./removeRequireIdentifierName"; | ||
|
||
export interface RemoveV2ClientModuleOptions { | ||
v2ClientName: string; | ||
v2DefaultModuleName: string; | ||
} | ||
|
||
export const removeV2ClientModule = ( | ||
j: JSCodeshift, | ||
source: Collection<unknown>, | ||
v2ClientName: string | ||
{ v2ClientName, v2DefaultModuleName }: RemoveV2ClientModuleOptions | ||
) => { | ||
const literalValue = getV2ServiceModulePath(v2ClientName); | ||
const removeIdentifierNameOptions = { | ||
identifierName: v2ClientName, | ||
literalValue: getV2ServiceModulePath(v2ClientName), | ||
literalValue, | ||
}; | ||
return containsRequire(j, source) | ||
? removeRequireIdentifierName(j, source, removeIdentifierNameOptions) | ||
: removeImportIdentifierName(j, source, removeIdentifierNameOptions); | ||
|
||
if (containsRequire(j, source)) { | ||
removeRequireIdentifierName(j, source, removeIdentifierNameOptions); | ||
} else { | ||
removeImportIdentifierName(j, source, removeIdentifierNameOptions); | ||
|
||
const v2ClientTypeNames = getV2ClientTypeNames(j, source, { | ||
v2ClientName, | ||
v2DefaultModuleName, | ||
}); | ||
for (const v2ClientTypeName of v2ClientTypeNames) { | ||
if (isV2ClientInputOutputType(v2ClientTypeName)) { | ||
removeImportIdentifierName(j, source, { | ||
identifierName: v2ClientTypeName, | ||
literalValue, | ||
}); | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters