From bc7edd1079a776a9e213293a230a5129204458bd Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:18:13 -0700 Subject: [PATCH] Remove passing and using importType in leaf functions --- .../v2-to-v3/apis/replaceS3GetSignedUrlApi.ts | 21 +++------------ .../v2-to-v3/apis/replaceS3UploadApi.ts | 12 ++------- .../v2-to-v3/apis/replaceWaiterApi.ts | 17 ++---------- .../getDynamoDBDocClientArgs.ts | 11 ++------ .../getDynamoDBForDocClient.ts | 17 ++---------- .../client-instances/replaceClientCreation.ts | 24 +++-------------- .../replaceDocClientCreation.ts | 20 ++++---------- .../v2-to-v3/modules/addClientModules.ts | 2 +- src/transforms/v2-to-v3/modules/types.ts | 1 - src/transforms/v2-to-v3/transformer.ts | 12 ++++----- .../v2-to-v3/ts-type/getTypeForString.ts | 25 ++++------------- .../v2-to-v3/ts-type/getV3ClientType.ts | 27 ++++--------------- .../v2-to-v3/ts-type/getV3ClientTypeName.ts | 14 ---------- src/transforms/v2-to-v3/ts-type/index.ts | 1 - .../ts-type/replaceTSQualifiedName.ts | 6 ++--- .../v2-to-v3/ts-type/updateV2ClientType.ts | 12 +-------- 16 files changed, 41 insertions(+), 181 deletions(-) delete mode 100644 src/transforms/v2-to-v3/ts-type/getV3ClientTypeName.ts diff --git a/src/transforms/v2-to-v3/apis/replaceS3GetSignedUrlApi.ts b/src/transforms/v2-to-v3/apis/replaceS3GetSignedUrlApi.ts index c9523d3c8..db3043ba2 100644 --- a/src/transforms/v2-to-v3/apis/replaceS3GetSignedUrlApi.ts +++ b/src/transforms/v2-to-v3/apis/replaceS3GetSignedUrlApi.ts @@ -8,23 +8,16 @@ import { ObjectProperty, } from "jscodeshift"; -import { OBJECT_PROPERTY_TYPE_LIST, S3 } from "../config"; -import { ImportType } from "../modules"; -import { getV3ClientTypeName } from "../ts-type"; +import { OBJECT_PROPERTY_TYPE_LIST } from "../config"; import { ClientIdentifier } from "../types"; import { getClientApiCallExpression } from "./getClientApiCallExpression"; import { getCommandName } from "./getCommandName"; -export interface ReplaceS3GetSignedUrlApiOptions { - clientIdentifiers: ClientIdentifier[]; - importType: ImportType; -} - // Updates `s3.getSignedUrl()` API with `await getSignedUrl(s3, command)` API. export const replaceS3GetSignedUrlApi = ( j: JSCodeshift, source: Collection, - { clientIdentifiers, importType }: ReplaceS3GetSignedUrlApiOptions + clientIdentifiers: ClientIdentifier[] ): void => { for (const clientId of clientIdentifiers) { for (const getSignedUrlApiName of ["getSignedUrl", "getSignedUrlPromise"]) { @@ -78,23 +71,17 @@ export const replaceS3GetSignedUrlApi = ( ); } - const commandName = getV3ClientTypeName(getCommandName(apiName), S3, importType); const getSignedUrlArgs: (ClientIdentifier | NewExpression | ObjectExpression)[] = [ clientId, - j.newExpression(j.identifier(commandName), [params]), + j.newExpression(j.identifier(getCommandName(apiName)), [params]), ]; if (options.properties.length > 0) { getSignedUrlArgs.push(options); } - const getSignedUrlIdentifier = getV3ClientTypeName( - "getSignedUrl", - "s3_request_presigner", - importType - ); const outputCallExpression = j.callExpression.from({ - callee: j.identifier(getSignedUrlIdentifier), + callee: j.identifier("getSignedUrl"), arguments: getSignedUrlArgs, }); diff --git a/src/transforms/v2-to-v3/apis/replaceS3UploadApi.ts b/src/transforms/v2-to-v3/apis/replaceS3UploadApi.ts index b51935956..4748afc9d 100644 --- a/src/transforms/v2-to-v3/apis/replaceS3UploadApi.ts +++ b/src/transforms/v2-to-v3/apis/replaceS3UploadApi.ts @@ -1,20 +1,13 @@ import { Collection, Identifier, JSCodeshift } from "jscodeshift"; -import { ImportType } from "../modules"; -import { getV3ClientTypeName } from "../ts-type"; import { ClientIdentifier } from "../types"; import { getClientApiCallExpression } from "./getClientApiCallExpression"; -export interface ReplaceS3UploadApiOptions { - clientIdentifiers: ClientIdentifier[]; - importType: ImportType; -} - // Updates `s3.upload()` API with `new Upload()` API. export const replaceS3UploadApi = ( j: JSCodeshift, source: Collection, - { clientIdentifiers, importType }: ReplaceS3UploadApiOptions + clientIdentifiers: ClientIdentifier[] ): void => { for (const clientId of clientIdentifiers) { // Replace `.promise()` call with `.done()` if present. @@ -66,8 +59,7 @@ export const replaceS3UploadApi = ( } } - const uploadApi = getV3ClientTypeName("Upload", "lib_storage", importType); - return j.newExpression(j.identifier(uploadApi), [j.objectExpression(properties)]); + return j.newExpression(j.identifier("Upload"), [j.objectExpression(properties)]); }); } }; diff --git a/src/transforms/v2-to-v3/apis/replaceWaiterApi.ts b/src/transforms/v2-to-v3/apis/replaceWaiterApi.ts index b2d827a21..0beb8e88a 100644 --- a/src/transforms/v2-to-v3/apis/replaceWaiterApi.ts +++ b/src/transforms/v2-to-v3/apis/replaceWaiterApi.ts @@ -1,7 +1,5 @@ import { Collection, JSCodeshift } from "jscodeshift"; -import { ImportType } from "../modules"; -import { getV3ClientTypeName } from "../ts-type"; import { ClientIdentifier } from "../types"; import { getArgsWithoutWaiterConfig } from "./getArgsWithoutWaiterConfig"; import { getClientWaiterCallExpression } from "./getClientWaiterCallExpression"; @@ -10,27 +8,16 @@ import { getV3ClientWaiterApiName } from "./getV3ClientWaiterApiName"; import { getWaiterConfig } from "./getWaiterConfig"; import { getWaiterConfigValue } from "./getWaiterConfigValue"; -export interface ReplaceWaiterApiOptions { - clientIdentifiers: ClientIdentifier[]; - v2ClientName: string; - importType: ImportType; -} - // Updates .waitFor() API with waitUntil* API. export const replaceWaiterApi = ( j: JSCodeshift, source: Collection, - { clientIdentifiers, v2ClientName, importType }: ReplaceWaiterApiOptions + clientIdentifiers: ClientIdentifier[] ): void => { for (const clientId of clientIdentifiers) { const waiterStates = getClientWaiterStates(j, source, clientIdentifiers); for (const waiterState of waiterStates) { - const v3WaiterApiName = getV3ClientTypeName( - getV3ClientWaiterApiName(waiterState), - v2ClientName, - importType - ); source .find(j.CallExpression, getClientWaiterCallExpression(clientId, waiterState)) .replaceWith((callExpression) => { @@ -67,7 +54,7 @@ export const replaceWaiterApi = ( }) ); - return j.callExpression(j.identifier(v3WaiterApiName), [ + return j.callExpression(j.identifier(getV3ClientWaiterApiName(waiterState)), [ j.objectExpression(properties), getArgsWithoutWaiterConfig(callExpression.node.arguments[1]), ]); diff --git a/src/transforms/v2-to-v3/client-instances/getDynamoDBDocClientArgs.ts b/src/transforms/v2-to-v3/client-instances/getDynamoDBDocClientArgs.ts index 574027c6b..1fa2d752d 100644 --- a/src/transforms/v2-to-v3/client-instances/getDynamoDBDocClientArgs.ts +++ b/src/transforms/v2-to-v3/client-instances/getDynamoDBDocClientArgs.ts @@ -1,18 +1,11 @@ import { ASTPath, JSCodeshift, NewExpression, ObjectProperty, Property } from "jscodeshift"; import { OBJECT_PROPERTY_TYPE_LIST } from "../config"; -import { ImportType } from "../modules"; import { getDynamoDBForDocClient } from "./getDynamoDBForDocClient"; -export interface GetDynamoDBDocClientArgsOptions { - v2ClientName: string; - v2ClientLocalName?: string; - importType: ImportType; -} - export const getDynamoDBDocClientArgs = ( j: JSCodeshift, v2DocClientNewExpression: ASTPath, - options: GetDynamoDBDocClientArgsOptions + v2ClientLocalName?: string ) => { const dynamoDBDocClientOptions = j.objectExpression([]); @@ -57,7 +50,7 @@ export const getDynamoDBDocClientArgs = ( } return [ - getDynamoDBForDocClient(j, v2DocClientNewExpression, options), + getDynamoDBForDocClient(j, v2DocClientNewExpression, v2ClientLocalName), ...(dynamoDBDocClientOptions.properties.length > 0 ? [dynamoDBDocClientOptions] : []), ]; }; diff --git a/src/transforms/v2-to-v3/client-instances/getDynamoDBForDocClient.ts b/src/transforms/v2-to-v3/client-instances/getDynamoDBForDocClient.ts index 98d297874..b82943fec 100644 --- a/src/transforms/v2-to-v3/client-instances/getDynamoDBForDocClient.ts +++ b/src/transforms/v2-to-v3/client-instances/getDynamoDBForDocClient.ts @@ -1,19 +1,11 @@ import { ASTPath, JSCodeshift, NewExpression, ObjectProperty, Property } from "jscodeshift"; import { DYNAMODB, OBJECT_PROPERTY_TYPE_LIST } from "../config"; -import { ImportType } from "../modules"; -import { getV3ClientTypeName } from "../ts-type"; - -export interface GetDynamoDBForDocClientOptions { - v2ClientName: string; - v2ClientLocalName?: string; - importType: ImportType; -} export const getDynamoDBForDocClient = ( j: JSCodeshift, v2DocClientNewExpression: ASTPath, - { v2ClientName, v2ClientLocalName, importType }: GetDynamoDBForDocClientOptions + v2ClientLocalName?: string ) => { const v2DocClientArgs = v2DocClientNewExpression.node.arguments || []; @@ -67,10 +59,5 @@ export const getDynamoDBForDocClient = ( } } - const typeName = - importType === ImportType.IMPORT_EQUALS ? DYNAMODB : v2ClientLocalName ?? DYNAMODB; - return j.newExpression( - j.identifier(getV3ClientTypeName(typeName, v2ClientName, importType)), - v3DocClientNewExpressionArgs - ); + return j.newExpression(j.identifier(v2ClientLocalName ?? DYNAMODB), v3DocClientNewExpressionArgs); }; diff --git a/src/transforms/v2-to-v3/client-instances/replaceClientCreation.ts b/src/transforms/v2-to-v3/client-instances/replaceClientCreation.ts index 796fc8e24..eb99ff89e 100644 --- a/src/transforms/v2-to-v3/client-instances/replaceClientCreation.ts +++ b/src/transforms/v2-to-v3/client-instances/replaceClientCreation.ts @@ -1,7 +1,4 @@ import { Collection, JSCodeshift } from "jscodeshift"; - -import { ImportType } from "../modules"; -import { getV3ClientTypeName } from "../ts-type"; import { getClientNewExpression } from "../utils"; export interface ReplaceClientCreationOptions { @@ -9,40 +6,27 @@ export interface ReplaceClientCreationOptions { v2ClientLocalName: string; v2GlobalName?: string; v3ClientName: string; - importType: ImportType; } // Replace v2 client creation with v3 client creation. export const replaceClientCreation = ( j: JSCodeshift, source: Collection, - { - v2ClientName, - v2ClientLocalName, - v2GlobalName, - v3ClientName, - importType, - }: ReplaceClientCreationOptions + { v2ClientName, v2ClientLocalName, v2GlobalName, v3ClientName }: ReplaceClientCreationOptions ): void => { - const clientName = - importType === ImportType.IMPORT_EQUALS || v2ClientName === v2ClientLocalName - ? v3ClientName - : v2ClientLocalName; - const clientLocalName = - importType === ImportType.IMPORT_EQUALS ? v2ClientName : v2ClientLocalName; - const v3ClientConstructor = getV3ClientTypeName(clientName, clientLocalName, importType); + const clientName = v2ClientName === v2ClientLocalName ? v3ClientName : v2ClientLocalName; if (v2GlobalName) { source .find(j.NewExpression, getClientNewExpression({ v2GlobalName, v2ClientName })) .replaceWith((v2ClientNewExpression) => - j.newExpression(j.identifier(v3ClientConstructor), v2ClientNewExpression.node.arguments) + j.newExpression(j.identifier(clientName), v2ClientNewExpression.node.arguments) ); } source .find(j.NewExpression, getClientNewExpression({ v2ClientName, v2ClientLocalName })) .replaceWith((v2ClientNewExpression) => - j.newExpression(j.identifier(v3ClientConstructor), v2ClientNewExpression.node.arguments) + j.newExpression(j.identifier(clientName), v2ClientNewExpression.node.arguments) ); }; diff --git a/src/transforms/v2-to-v3/client-instances/replaceDocClientCreation.ts b/src/transforms/v2-to-v3/client-instances/replaceDocClientCreation.ts index e0f87ee0e..b55cec448 100644 --- a/src/transforms/v2-to-v3/client-instances/replaceDocClientCreation.ts +++ b/src/transforms/v2-to-v3/client-instances/replaceDocClientCreation.ts @@ -1,8 +1,6 @@ import { Collection, JSCodeshift } from "jscodeshift"; import { DOCUMENT_CLIENT, DYNAMODB, DYNAMODB_DOCUMENT, DYNAMODB_DOCUMENT_CLIENT } from "../config"; -import { ImportType, getImportEqualsLocalNameSuffix } from "../modules"; -import { getV3ClientTypeName } from "../ts-type"; import { getClientNewExpression } from "../utils"; import { getDynamoDBDocClientArgs } from "./getDynamoDBDocClientArgs"; @@ -10,23 +8,15 @@ export interface ReplaceDocClientCreationOptions { v2ClientName: string; v2ClientLocalName: string; v2GlobalName?: string; - importType: ImportType; } export const replaceDocClientCreation = ( j: JSCodeshift, source: Collection, - { v2ClientName, v2ClientLocalName, v2GlobalName, importType }: ReplaceDocClientCreationOptions + { v2ClientName, v2ClientLocalName, v2GlobalName }: ReplaceDocClientCreationOptions ): void => { if (v2ClientName !== DYNAMODB) return; - const v3DocClientName = getV3ClientTypeName( - DYNAMODB_DOCUMENT, - getImportEqualsLocalNameSuffix(v2ClientName, "@aws-sdk/lib-dynamodb"), - importType - ); - const ddbDocClientOptions = { v2ClientName, v2ClientLocalName, importType }; - if (v2GlobalName) { source .find( @@ -35,8 +25,8 @@ export const replaceDocClientCreation = ( ) .replaceWith((v2DocClientNewExpression) => j.callExpression( - j.memberExpression(j.identifier(v3DocClientName), j.identifier("from")), - getDynamoDBDocClientArgs(j, v2DocClientNewExpression, ddbDocClientOptions) + j.memberExpression(j.identifier(DYNAMODB_DOCUMENT), j.identifier("from")), + getDynamoDBDocClientArgs(j, v2DocClientNewExpression, v2ClientLocalName) ) ); } @@ -48,8 +38,8 @@ export const replaceDocClientCreation = ( ) .replaceWith((v2DocClientNewExpression) => j.callExpression( - j.memberExpression(j.identifier(v3DocClientName), j.identifier("from")), - getDynamoDBDocClientArgs(j, v2DocClientNewExpression, ddbDocClientOptions) + j.memberExpression(j.identifier(DYNAMODB_DOCUMENT), j.identifier("from")), + getDynamoDBDocClientArgs(j, v2DocClientNewExpression, v2ClientLocalName) ) ); }; diff --git a/src/transforms/v2-to-v3/modules/addClientModules.ts b/src/transforms/v2-to-v3/modules/addClientModules.ts index c69a84501..4c22d41c6 100644 --- a/src/transforms/v2-to-v3/modules/addClientModules.ts +++ b/src/transforms/v2-to-v3/modules/addClientModules.ts @@ -27,7 +27,7 @@ import { ClientModulesOptions, ImportType } from "./types"; export const addClientModules = ( j: JSCodeshift, source: Collection, - options: ClientModulesOptions + options: ClientModulesOptions & { importType: ImportType } ): void => { const { clientIdentifiers, v2ClientName, v3ClientName, v2ClientLocalName, importType } = options; diff --git a/src/transforms/v2-to-v3/modules/types.ts b/src/transforms/v2-to-v3/modules/types.ts index 69bbefcbe..2209242ec 100644 --- a/src/transforms/v2-to-v3/modules/types.ts +++ b/src/transforms/v2-to-v3/modules/types.ts @@ -7,7 +7,6 @@ export interface ClientModulesOptions { v3ClientName: string; v3ClientPackageName: string; clientIdentifiers: ClientIdentifier[]; - importType: ImportType; } export interface ImportSpecifierOptions { diff --git a/src/transforms/v2-to-v3/transformer.ts b/src/transforms/v2-to-v3/transformer.ts index 0a47f0786..2a4007a84 100644 --- a/src/transforms/v2-to-v3/transformer.ts +++ b/src/transforms/v2-to-v3/transformer.ts @@ -72,24 +72,24 @@ const transformer = async (file: FileInfo, api: API) => { const v3Options = { v3ClientName, v3ClientPackageName }; addClientModules(j, source, { ...v2Options, ...v3Options, clientIdentifiers, importType }); - replaceTSQualifiedName(j, source, { ...v2Options, v3ClientName, importType }); + replaceTSQualifiedName(j, source, { ...v2Options, v3ClientName }); removeClientModule(j, source, { ...v2Options, importType }); if (v2ClientName === S3) { // Needs to be called before removing promise calls, as replacement has `.done()` call. - replaceS3UploadApi(j, source, { clientIdentifiers, importType }); + replaceS3UploadApi(j, source, clientIdentifiers); } removePromiseCalls(j, source, clientIdentifiers); if (v2ClientName === S3) { - replaceS3GetSignedUrlApi(j, source, { clientIdentifiers, importType }); + replaceS3GetSignedUrlApi(j, source, clientIdentifiers); } - replaceWaiterApi(j, source, { clientIdentifiers, v2ClientName, importType }); + replaceWaiterApi(j, source, clientIdentifiers); - replaceClientCreation(j, source, { ...v2Options, v3ClientName, importType }); - replaceDocClientCreation(j, source, { ...v2Options, importType }); + replaceClientCreation(j, source, { ...v2Options, v3ClientName }); + replaceDocClientCreation(j, source, v2Options); } replaceAwsUtilFunctions(j, source, v2GlobalName); removeGlobalModule(j, source, { v2GlobalName, importType }); diff --git a/src/transforms/v2-to-v3/ts-type/getTypeForString.ts b/src/transforms/v2-to-v3/ts-type/getTypeForString.ts index a1e2a021f..c634a7dcf 100644 --- a/src/transforms/v2-to-v3/ts-type/getTypeForString.ts +++ b/src/transforms/v2-to-v3/ts-type/getTypeForString.ts @@ -1,19 +1,12 @@ import { JSCodeshift, TSType } from "jscodeshift"; -import { ImportType } from "../modules"; -import { getV3ClientTypeName } from "./getV3ClientTypeName"; const arrayRegex = /^Array<(.*)>$/; const recordRegex = /^Record$/; -export interface GetTypeForStringOptions { - v2ClientLocalName: string; - v3ClientTypeString: string; -} - export const getTypeForString = ( j: JSCodeshift, - importType: ImportType, - { v2ClientLocalName, v3ClientTypeString }: GetTypeForStringOptions + v2ClientLocalName: string, + v3ClientTypeString: string ): TSType => { if (v3ClientTypeString === "string") { return j.tsStringKeyword(); @@ -34,10 +27,7 @@ export const getTypeForString = ( const arrayRegexMatches = arrayRegex.exec(v3ClientTypeString); if (arrayRegexMatches) { const type = arrayRegexMatches[1]; - const typeArgument = getTypeForString(j, importType, { - v2ClientLocalName, - v3ClientTypeString: type, - }); + const typeArgument = getTypeForString(j, v2ClientLocalName, type); return j.tsTypeReference.from({ typeName: j.identifier("Array"), // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -49,10 +39,7 @@ export const getTypeForString = ( const recordRegexMatches = recordRegex.exec(v3ClientTypeString); if (recordRegexMatches) { const type = recordRegexMatches[1]; - const typeArgument = getTypeForString(j, importType, { - v2ClientLocalName, - v3ClientTypeString: type, - }); + const typeArgument = getTypeForString(j, v2ClientLocalName, type); return j.tsTypeReference.from({ typeName: j.identifier("Record"), // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -61,7 +48,5 @@ export const getTypeForString = ( }); } - return j.tsTypeReference( - j.identifier(getV3ClientTypeName(v3ClientTypeString, v2ClientLocalName, importType)) - ); + return j.tsTypeReference(j.identifier(v3ClientTypeString)); }; diff --git a/src/transforms/v2-to-v3/ts-type/getV3ClientType.ts b/src/transforms/v2-to-v3/ts-type/getV3ClientType.ts index 42edeca45..b6999c122 100644 --- a/src/transforms/v2-to-v3/ts-type/getV3ClientType.ts +++ b/src/transforms/v2-to-v3/ts-type/getV3ClientType.ts @@ -1,46 +1,29 @@ import { JSCodeshift, TSType } from "jscodeshift"; -import { CLIENT_TYPES_MAP, DYNAMODB_DOCUMENT_CLIENT } from "../config"; +import { CLIENT_TYPES_MAP } from "../config"; import { CLIENT_REQ_RESP_TYPES_MAP } from "../config/CLIENT_REQ_RESP_TYPES_MAP"; -import { ImportType } from "../modules"; import { getTypeForString } from "./getTypeForString"; -import { getV3ClientTypeName } from "./getV3ClientTypeName"; export interface GetV3ClientTypeOptions { v2ClientLocalName: string; v2ClientName: string; v2ClientTypeName: string; - importType: ImportType; } export const getV3ClientType = (j: JSCodeshift, options: GetV3ClientTypeOptions): TSType => { - const { v2ClientName, v2ClientTypeName, importType } = options; - - // ToDo: remove this hack for ddb-doc-client-input-output-type. - const v2ClientLocalName = - v2ClientName === DYNAMODB_DOCUMENT_CLIENT && importType === ImportType.IMPORT_EQUALS - ? "lib_dynamodb" - : options.v2ClientLocalName; - + const { v2ClientName, v2ClientLocalName, v2ClientTypeName } = options; const clientReqRespTypesMap = CLIENT_REQ_RESP_TYPES_MAP[v2ClientName]; if (Object.keys(clientReqRespTypesMap).includes(v2ClientTypeName)) { const v3ClientTypeName = clientReqRespTypesMap[v2ClientTypeName]; - return j.tsTypeReference( - j.identifier(getV3ClientTypeName(v3ClientTypeName, v2ClientLocalName, importType)) - ); + return j.tsTypeReference(j.identifier(v3ClientTypeName)); } const clientTypesMap = CLIENT_TYPES_MAP[v2ClientName]; if (Object.keys(clientTypesMap).includes(v2ClientTypeName)) { - return getTypeForString(j, importType, { - v2ClientLocalName, - v3ClientTypeString: clientTypesMap[v2ClientTypeName], - }); + return getTypeForString(j, v2ClientLocalName, clientTypesMap[v2ClientTypeName]); } - return j.tsTypeReference( - j.identifier(getV3ClientTypeName(v2ClientTypeName, v2ClientLocalName, importType)) - ); + return j.tsTypeReference(j.identifier(v2ClientTypeName)); }; diff --git a/src/transforms/v2-to-v3/ts-type/getV3ClientTypeName.ts b/src/transforms/v2-to-v3/ts-type/getV3ClientTypeName.ts deleted file mode 100644 index ee095be41..000000000 --- a/src/transforms/v2-to-v3/ts-type/getV3ClientTypeName.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ImportType } from "../modules"; -import { getDefaultLocalName } from "../utils"; - -export const getV3ClientTypeName = ( - typeName: string, - localName: string, - importType: ImportType -) => { - const v3ClientTypeNameSections = [typeName]; - if (importType === ImportType.IMPORT_EQUALS) { - v3ClientTypeNameSections.unshift(getDefaultLocalName(localName)); - } - return v3ClientTypeNameSections.join("."); -}; diff --git a/src/transforms/v2-to-v3/ts-type/index.ts b/src/transforms/v2-to-v3/ts-type/index.ts index b6238f626..af75419e8 100644 --- a/src/transforms/v2-to-v3/ts-type/index.ts +++ b/src/transforms/v2-to-v3/ts-type/index.ts @@ -1,5 +1,4 @@ export * from "./getClientTypeNames"; export * from "./getV3ClientType"; -export * from "./getV3ClientTypeName"; export * from "./getV3ClientTypes"; export * from "./replaceTSQualifiedName"; diff --git a/src/transforms/v2-to-v3/ts-type/replaceTSQualifiedName.ts b/src/transforms/v2-to-v3/ts-type/replaceTSQualifiedName.ts index 90f3bfc95..22f37fac3 100644 --- a/src/transforms/v2-to-v3/ts-type/replaceTSQualifiedName.ts +++ b/src/transforms/v2-to-v3/ts-type/replaceTSQualifiedName.ts @@ -1,7 +1,6 @@ import { ASTPath, Collection, Identifier, JSCodeshift, TSQualifiedName } from "jscodeshift"; import { DOCUMENT_CLIENT, DYNAMODB, DYNAMODB_DOCUMENT_CLIENT } from "../config"; -import { ImportType } from "../modules"; import { getClientTypeNames } from "./getClientTypeNames"; import { getTSQualifiedNameFromClientName } from "./getTSQualifiedNameFromClientName"; import { getV3ClientType } from "./getV3ClientType"; @@ -12,7 +11,6 @@ export interface ReplaceTSQualifiedNameOptions { v2ClientLocalName: string; v2GlobalName?: string; v3ClientName: string; - importType: ImportType; } const isRightSectionIdentifier = (node: TSQualifiedName) => node.right.type === "Identifier"; @@ -28,8 +26,8 @@ export const replaceTSQualifiedName = ( source: Collection, options: ReplaceTSQualifiedNameOptions ): void => { - const { v2ClientName, v2ClientLocalName, v2GlobalName, v3ClientName, importType } = options; - const clientTypeOptions = { v2ClientName, v2ClientLocalName, importType }; + const { v2ClientName, v2ClientLocalName, v2GlobalName, v3ClientName } = options; + const clientTypeOptions = { v2ClientName, v2ClientLocalName }; if (v2GlobalName) { // Replace type reference to client created with global name. diff --git a/src/transforms/v2-to-v3/ts-type/updateV2ClientType.ts b/src/transforms/v2-to-v3/ts-type/updateV2ClientType.ts index 08326683a..a707f0c31 100644 --- a/src/transforms/v2-to-v3/ts-type/updateV2ClientType.ts +++ b/src/transforms/v2-to-v3/ts-type/updateV2ClientType.ts @@ -1,6 +1,4 @@ import { ASTPath, Identifier, JSCodeshift, TSQualifiedName, TSTypeReference } from "jscodeshift"; -import { DOCUMENT_CLIENT } from "../config"; -import { ImportType } from "../modules"; import { addTsTypeQueryToRefType } from "./addTsTypeQueryToRefType"; import { getV3ClientType } from "./getV3ClientType"; @@ -12,7 +10,6 @@ interface UpdateV2ClientTypeOptions { v2ClientName: string; v2ClientTypeName: string; v2ClientLocalName: string; - importType: ImportType; } export const updateV2ClientType = ( @@ -20,14 +17,7 @@ export const updateV2ClientType = ( v2ClientType: ASTPath, options: UpdateV2ClientTypeOptions ) => { - const { importType } = options; - const v2ClientLocalName = - importType === ImportType.IMPORT_EQUALS && - options.v2ClientLocalName.endsWith(`.${DOCUMENT_CLIENT}`) - ? "lib_dynamodb" - : options.v2ClientLocalName; - - const v3ClientType = getV3ClientType(j, { ...options, v2ClientLocalName }); + const v3ClientType = getV3ClientType(j, options); if (v2ClientType.parentPath?.value.type === "TSTypeQuery") { if (nativeTsRefTypes.includes(v3ClientType.type)) {