Skip to content

Commit

Permalink
Use v3 client name when input code does not use local name (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Oct 16, 2023
1 parent f4819ac commit c1c8016
Show file tree
Hide file tree
Showing 22 changed files with 112 additions and 94 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-gorillas-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": minor
---

Use v3 client name when input code does not use local name
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { CLIENT_NAMES_MAP } from "../../src/transforms/v2-to-v3/config";

export const getV3ClientsNewExpressionCode = (clientsToTest: string[]) => {
let content = ``;
for (const clientName of clientsToTest) {
content += `new ${clientName}();\n`;
const clientConstructorName = CLIENT_NAMES_MAP[clientName] ?? clientName;
content += `new ${clientConstructorName}();\n`;
}
return content;
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export const getV3PackageImportEqualsCode = (
: v2ClientName;

const v3ObjectPattern =
v3ClientName === v2ClientLocalName ? v3ClientName : `${v3ClientName}: ${v2ClientLocalName}`;
v2ClientName === v2ClientLocalName ? v3ClientName : `${v3ClientName}: ${v2ClientLocalName}`;

content +=
`const {\n` + ` ${v3ObjectPattern}\n` + `} = ${getDefaultLocalName(v2ClientName)};\n\n`;
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/generateNewClientTests/getV3PackageImportsCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getV3PackageImportsCode = (
: v2ClientName;

const v3ImportSpecifier =
v3ClientName === v2ClientLocalName ? v3ClientName : `${v3ClientName} as ${v2ClientLocalName}`;
v2ClientName === v2ClientLocalName ? v3ClientName : `${v3ClientName} as ${v2ClientLocalName}`;

content += `import { ${v3ImportSpecifier} } from "${v3ClientPackageName}";\n`;
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/generateNewClientTests/getV3PackageRequiresCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const getV3PackageRequiresCode = (
: v2ClientName;

const v3RequireKeyValuePair =
v3ClientName === v2ClientLocalName ? v3ClientName : `${v3ClientName}: ${v2ClientLocalName}`;
v2ClientName === v2ClientLocalName ? v3ClientName : `${v3ClientName}: ${v2ClientLocalName}`;
content += declarationPerClient
? `const {\n ${v3RequireKeyValuePair}\n} = require("${v3ClientPackageName}");\n`
: `{\n ${v3RequireKeyValuePair}\n } = require("${v3ClientPackageName}"),\n `;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const {
ApplicationDiscoveryService: Discovery
ApplicationDiscoveryService
} = require("@aws-sdk/client-application-discovery-service"),
{
DynamoDB
} = require("@aws-sdk/client-dynamodb"),
ddbClient = new DynamoDB(),
discoveryClient = new Discovery();
discoveryClient = new ApplicationDiscoveryService();

const ddbResponse = await ddbClient.listTables();
const discoveryResponse = await discoveryClient.describeAgents();
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const {
ApplicationDiscoveryService: Discovery
ApplicationDiscoveryService
} = require("@aws-sdk/client-application-discovery-service"),
{
DynamoDB
} = require("@aws-sdk/client-dynamodb"),
ddbClient = new DynamoDB(),
discoveryClient = new Discovery();
discoveryClient = new ApplicationDiscoveryService();

const ddbResponse = await ddbClient.listTables();
const discoveryResponse = await discoveryClient.describeAgents();
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const {
DynamoDB
} = require("@aws-sdk/client-dynamodb"),
{
ApplicationDiscoveryService: Discovery
ApplicationDiscoveryService
} = require("@aws-sdk/client-application-discovery-service"),
ddbClient = new DynamoDB(),
discoveryClient = new Discovery();
discoveryClient = new ApplicationDiscoveryService();

const ddbResponse = await ddbClient.listTables();
const discoveryResponse = await discoveryClient.describeAgents();
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const {
import AWS_Discovery = require("@aws-sdk/client-application-discovery-service");

const {
ApplicationDiscoveryService: Discovery
ApplicationDiscoveryService
} = AWS_Discovery;

new ACM();
new AccessAnalyzer();
new Discovery();
new ApplicationDiscoveryService();
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import { AccessAnalyzer } from "@aws-sdk/client-accessanalyzer";
import { ACM } from "@aws-sdk/client-acm";
import { ApplicationDiscoveryService as Discovery } from "@aws-sdk/client-application-discovery-service";
import { ApplicationDiscoveryService } from "@aws-sdk/client-application-discovery-service";

new ACM();
new AccessAnalyzer();
new Discovery();
new ApplicationDiscoveryService();
Loading

0 comments on commit c1c8016

Please sign in to comment.