Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use v3 client name when input code does not use local name #594

Merged
merged 18 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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