Skip to content

Commit

Permalink
Add require declaration per client (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Oct 19, 2023
1 parent 16505e2 commit d989203
Show file tree
Hide file tree
Showing 38 changed files with 233 additions and 188 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-laws-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": minor
---

Add require declaration per client
2 changes: 1 addition & 1 deletion scripts/generateNewClientTests/getGlobalRequireOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
import { getV3PackageRequiresCode } from "./getV3PackageRequiresCode";

export const getGlobalRequireOutput = () => {
let content = ``;
let content = `\n\n`;

content += getV3PackageRequiresCode(getClientNamesSortedByPackageName(CLIENTS_TO_TEST));
content += getV3ClientsNewExpressionCode(CLIENTS_TO_TEST);
Expand Down
5 changes: 2 additions & 3 deletions scripts/generateNewClientTests/getServiceRequireDeepOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
import { getV3PackageRequiresCode } from "./getV3PackageRequiresCode";

export const getServiceRequireDeepOutput = () => {
let content = ``;
let content = `\n\n`;

content += getV3PackageRequiresCode(CLIENTS_TO_TEST, { declarationPerClient: true });
content += `\n`;
content += getV3PackageRequiresCode(CLIENTS_TO_TEST);
content += getV3ClientsNewExpressionCode(CLIENTS_TO_TEST);

return content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
import { getV3PackageRequiresCode } from "./getV3PackageRequiresCode";

export const getServiceRequireDeepWithNameOutput = () => {
let content = ``;
let content = `\n\n`;

content += getV3PackageRequiresCode(CLIENTS_TO_TEST, {
declarationPerClient: true,
useLocalSuffix: true,
});
content += `\n`;
content += getV3PackageRequiresCode(CLIENTS_TO_TEST, { useLocalSuffix: true });
content += getV3ClientsNewExpressionCode(CLIENTS_TO_TEST.map(getClientNameWithLocalSuffix));

return content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
import { getV3PackageRequiresCode } from "./getV3PackageRequiresCode";

export const getServiceRequireWithNameOutput = () => {
let content = ``;
let content = `\n\n`;

content += getV3PackageRequiresCode(getClientNamesSortedByPackageName(CLIENTS_TO_TEST), {
useLocalSuffix: true,
Expand Down
15 changes: 2 additions & 13 deletions scripts/generateNewClientTests/getV3PackageRequiresCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@ import { getClientNameWithLocalSuffix } from "./getClientNameWithLocalSuffix";

export interface V3PackageRequiresCodeOptions {
useLocalSuffix?: boolean;
declarationPerClient?: boolean;
}

export const getV3PackageRequiresCode = (
clientsToTest: typeof CLIENT_NAMES,
options?: V3PackageRequiresCodeOptions
) => {
let content = ``;
const { useLocalSuffix = false, declarationPerClient = false } = options || {};

if (!declarationPerClient) {
content += `const `;
}
const { useLocalSuffix = false } = options || {};

for (const v2ClientName of clientsToTest) {
const v3ClientName = CLIENT_NAMES_MAP[v2ClientName];
Expand All @@ -30,13 +25,7 @@ export const getV3PackageRequiresCode = (

const v3RequireKeyValuePair =
v2ClientName === v2ClientLocalName ? v3ClientName : `${v3ClientName}: ${v2ClientLocalName}`;
content += declarationPerClient
? `const {\n ${v3RequireKeyValuePair}\n} = require("${v3ClientPackageName}");\n`
: `{\n ${v3RequireKeyValuePair}\n } = require("${v3ClientPackageName}"),\n `;
}

if (!declarationPerClient) {
content = content.replace(/,\n {6}$/, ";\n\n");
content += `const {\n ${v3RequireKeyValuePair}\n} = require("${v3ClientPackageName}");\n\n`;
}

return content;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const {
DynamoDBDocument
} = require("@aws-sdk/lib-dynamodb"),
{
DynamoDB
} = require("@aws-sdk/client-dynamodb");
DynamoDBDocument
} = require("@aws-sdk/lib-dynamodb");

const {
DynamoDB
} = require("@aws-sdk/client-dynamodb");

const documentClient = DynamoDBDocument.from(new DynamoDB({ region: "us-west-2" }));
const response = await documentClient.scan({ TableName: "TABLE_NAME" });
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const {
DynamoDBDocument
} = require("@aws-sdk/lib-dynamodb"),
{
DynamoDB: DynamoDBClient
} = require("@aws-sdk/client-dynamodb");
DynamoDBDocument
} = require("@aws-sdk/lib-dynamodb");

const {
DynamoDB: DynamoDBClient
} = require("@aws-sdk/client-dynamodb");

const documentClient = DynamoDBDocument.from(new DynamoDBClient({ region: "us-west-2" }));
const response = await documentClient.scan({ TableName: "TABLE_NAME" });
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const {
DynamoDBDocument
} = require("@aws-sdk/lib-dynamodb"),
{
DynamoDB
} = require("@aws-sdk/client-dynamodb");
DynamoDBDocument
} = require("@aws-sdk/lib-dynamodb");

const {
DynamoDB
} = require("@aws-sdk/client-dynamodb");

const documentClient = DynamoDBDocument.from(new DynamoDB({ region: "us-west-2" }));
const response = await documentClient.scan({ TableName: "TABLE_NAME" });
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const {
DynamoDBDocument
} = require("@aws-sdk/lib-dynamodb"),
{
DynamoDB: DynamoDBClient
} = require("@aws-sdk/client-dynamodb");
DynamoDBDocument
} = require("@aws-sdk/lib-dynamodb");

const {
DynamoDB: DynamoDBClient
} = require("@aws-sdk/client-dynamodb");

const documentClient = DynamoDBDocument.from(new DynamoDBClient({ region: "us-west-2" }));
const response = await documentClient.scan({ TableName: "TABLE_NAME" });
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const {
DynamoDBDocument
} = require("@aws-sdk/lib-dynamodb"),
{
DynamoDB
} = require("@aws-sdk/client-dynamodb");
DynamoDBDocument
} = require("@aws-sdk/lib-dynamodb");

const {
DynamoDB
} = require("@aws-sdk/client-dynamodb");

const documentClient = DynamoDBDocument.from(new DynamoDB({ region: "us-west-2" }));
const response = await documentClient.scan({ TableName: "TABLE_NAME" });
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const DynamoDB = require("aws-sdk/clients/dynamodb"),
Discovery = require("aws-sdk/clients/discovery"),
ddbClient = new DynamoDB(),
Discovery = require("aws-sdk/clients/discovery");

const ddbClient = new DynamoDB(),
discoveryClient = new Discovery();

const ddbResponse = await ddbClient.listTables().promise();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const {
ApplicationDiscoveryService
} = require("@aws-sdk/client-application-discovery-service");

const {
DynamoDB
} = require("@aws-sdk/client-dynamodb"),
{
ApplicationDiscoveryService
} = require("@aws-sdk/client-application-discovery-service"),
ddbClient = new DynamoDB(),
} = require("@aws-sdk/client-dynamodb");

const ddbClient = new DynamoDB(),
discoveryClient = new ApplicationDiscoveryService();

const ddbResponse = await ddbClient.listTables();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// This file is generated by scripts/generateNewClientTests/index.ts
// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.


const {
ACM: ACMClient
} = require("@aws-sdk/client-acm");

const {
AccessAnalyzer: AccessAnalyzerClient
} = require("@aws-sdk/client-accessanalyzer");

const {
ApplicationDiscoveryService: DiscoveryClient
} = require("@aws-sdk/client-application-discovery-service");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// This file is generated by scripts/generateNewClientTests/index.ts
// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.


const {
ACM
} = require("@aws-sdk/client-acm");

const {
AccessAnalyzer
} = require("@aws-sdk/client-accessanalyzer");

const {
ApplicationDiscoveryService
} = require("@aws-sdk/client-application-discovery-service");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// This file is generated by scripts/generateNewClientTests/index.ts
// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.


const {
AccessAnalyzer
} = require("@aws-sdk/client-accessanalyzer");

const {
ACM
} = require("@aws-sdk/client-acm");

const {
AccessAnalyzer
} = require("@aws-sdk/client-accessanalyzer"),
{
ACM
} = require("@aws-sdk/client-acm"),
{
ApplicationDiscoveryService
} = require("@aws-sdk/client-application-discovery-service");
ApplicationDiscoveryService
} = require("@aws-sdk/client-application-discovery-service");

new ACM();
new AccessAnalyzer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// This file is generated by scripts/generateNewClientTests/index.ts
// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.


const {
ACM: ACMClient
} = require("@aws-sdk/client-acm");

const {
AccessAnalyzer: AccessAnalyzerClient
} = require("@aws-sdk/client-accessanalyzer");

const {
ApplicationDiscoveryService: DiscoveryClient
} = require("@aws-sdk/client-application-discovery-service");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// This file is generated by scripts/generateNewClientTests/index.ts
// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.


const {
ACM
} = require("@aws-sdk/client-acm");

const {
AccessAnalyzer
} = require("@aws-sdk/client-accessanalyzer");

const {
ApplicationDiscoveryService
} = require("@aws-sdk/client-application-discovery-service");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// This file is generated by scripts/generateNewClientTests/index.ts
// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.


const {
AccessAnalyzer: AccessAnalyzerClient
} = require("@aws-sdk/client-accessanalyzer");

const {
ACM: ACMClient
} = require("@aws-sdk/client-acm");

const {
AccessAnalyzer: AccessAnalyzerClient
} = require("@aws-sdk/client-accessanalyzer"),
{
ACM: ACMClient
} = require("@aws-sdk/client-acm"),
{
ApplicationDiscoveryService: DiscoveryClient
} = require("@aws-sdk/client-application-discovery-service");
ApplicationDiscoveryService: DiscoveryClient
} = require("@aws-sdk/client-application-discovery-service");

new ACMClient();
new AccessAnalyzerClient();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// This file is generated by scripts/generateNewClientTests/index.ts
// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.


const {
AccessAnalyzer
} = require("@aws-sdk/client-accessanalyzer");

const {
ACM
} = require("@aws-sdk/client-acm");

const {
AccessAnalyzer
} = require("@aws-sdk/client-accessanalyzer"),
{
ACM
} = require("@aws-sdk/client-acm"),
{
ApplicationDiscoveryService
} = require("@aws-sdk/client-application-discovery-service");
ApplicationDiscoveryService
} = require("@aws-sdk/client-application-discovery-service");

new ACM();
new AccessAnalyzer();
Expand Down
Loading

0 comments on commit d989203

Please sign in to comment.