Skip to content

Commit 1431238

Browse files
authored
Store clientIdentifiersRecord at transformer level (#553)
1 parent 2e5d752 commit 1431238

21 files changed

+123
-136
lines changed

.changeset/eleven-lemons-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"aws-sdk-js-codemod": patch
3+
---
4+
5+
Store clientIdentifiersRecord at transformer level

src/transforms/v2-to-v3/apis/addNotSupportedClientComments.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
import { Collection, JSCodeshift } from "jscodeshift";
22

3-
import { FUNCTION_TYPE_LIST } from "../config";
3+
import { FUNCTION_TYPE_LIST, S3 } from "../config";
4+
import { ClientIdentifier } from "../types";
45
import { getClientApiCallExpression } from "./getClientApiCallExpression";
5-
import { getClientIdentifiers } from "./getClientIdentifiers";
66
import { getClientWaiterCallExpression } from "./getClientWaiterCallExpression";
77
import { getClientWaiterStates } from "./getClientWaiterStates";
88

99
export interface CommentsForUnsupportedAPIsOptions {
1010
v2ClientName: string;
11-
v2ClientLocalName: string;
12-
v2GlobalName?: string;
11+
clientIdentifiers: ClientIdentifier[];
1312
}
1413

1514
export const addNotSupportedClientComments = (
1615
j: JSCodeshift,
1716
source: Collection<unknown>,
1817
options: CommentsForUnsupportedAPIsOptions
1918
): void => {
20-
const clientIdentifiers = getClientIdentifiers(j, source, options);
19+
const { v2ClientName, clientIdentifiers } = options;
2120

2221
for (const clientId of clientIdentifiers) {
23-
const waiterStates = getClientWaiterStates(j, source, options);
22+
const waiterStates = getClientWaiterStates(j, source, clientIdentifiers);
2423

2524
for (const waiterState of waiterStates) {
2625
source
@@ -46,7 +45,7 @@ export const addNotSupportedClientComments = (
4645
}
4746
}
4847

49-
if (options.v2ClientName === "S3") {
48+
if (v2ClientName === S3) {
5049
for (const clientId of clientIdentifiers) {
5150
const apiMetadata = [
5251
{

src/transforms/v2-to-v3/apis/getClientApiCallExpression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CallExpression } from "jscodeshift";
22

3-
import { ClientIdentifier } from "./getClientIdentifiers";
3+
import { ClientIdentifier } from "../types";
44

55
export const getClientApiCallExpression = (
66
clientId: ClientIdentifier,

src/transforms/v2-to-v3/apis/getClientIdThisExpressions.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
import { Collection, Identifier, JSCodeshift, MemberExpression, ThisExpression } from "jscodeshift";
2-
3-
export interface ThisMemberExpression {
4-
type: "MemberExpression";
5-
object: ThisExpression;
6-
property: Identifier;
7-
}
1+
import { Collection, Identifier, JSCodeshift, MemberExpression } from "jscodeshift";
2+
import { ThisMemberExpression } from "../types";
83

94
const thisMemberExpression = { type: "MemberExpression", object: { type: "ThisExpression" } };
105

src/transforms/v2-to-v3/apis/getClientIdentifiers.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import { Collection, Identifier, JSCodeshift } from "jscodeshift";
22

3+
import { ClientIdentifier } from "../types";
34
import { getClientIdNamesFromNewExpr } from "./getClientIdNamesFromNewExpr";
45
import { getClientIdNamesFromTSTypeRef } from "./getClientIdNamesFromTSTypeRef";
5-
import { getClientIdThisExpressions, ThisMemberExpression } from "./getClientIdThisExpressions";
6+
import { getClientIdThisExpressions } from "./getClientIdThisExpressions";
67

78
export interface GetClientIdentifiersOptions {
89
v2ClientName: string;
910
v2ClientLocalName: string;
1011
v2GlobalName?: string;
1112
}
1213

13-
export type ClientIdentifier = Identifier | ThisMemberExpression;
14-
1514
export const getClientIdentifiers = (
1615
j: JSCodeshift,
1716
source: Collection<unknown>,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Collection, JSCodeshift } from "jscodeshift";
2+
3+
import { ClientIdentifiersRecord } from "../types";
4+
import { getClientIdentifiers } from "./getClientIdentifiers";
5+
6+
export interface GetClientIdentifiersRecordOptions {
7+
v2GlobalName?: string;
8+
v2ClientNamesRecord: Record<string, string>;
9+
}
10+
11+
export const getClientIdentifiersRecord = (
12+
j: JSCodeshift,
13+
source: Collection<unknown>,
14+
{ v2GlobalName, v2ClientNamesRecord }: GetClientIdentifiersRecordOptions
15+
): ClientIdentifiersRecord =>
16+
Object.fromEntries(
17+
Object.entries(v2ClientNamesRecord).map(([v2ClientName, v2ClientLocalName]) => [
18+
v2ClientName,
19+
getClientIdentifiers(j, source, { v2ClientName, v2ClientLocalName, v2GlobalName }),
20+
])
21+
);

src/transforms/v2-to-v3/apis/getClientWaiterCallExpression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CallExpression } from "jscodeshift";
22

3-
import { ClientIdentifier } from "./getClientIdentifiers";
3+
import { ClientIdentifier } from "../types";
44

55
export const getClientWaiterCallExpression = (
66
clientId: ClientIdentifier,

src/transforms/v2-to-v3/apis/getClientWaiterStates.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
import { Collection, JSCodeshift } from "jscodeshift";
2-
3-
import { getClientIdentifiers } from "./getClientIdentifiers";
4-
5-
export interface GetClientWaiterStatesOptions {
6-
v2ClientName: string;
7-
v2ClientLocalName: string;
8-
v2GlobalName?: string;
9-
}
2+
import { ClientIdentifier } from "../types";
103

114
export const getClientWaiterStates = (
125
j: JSCodeshift,
136
source: Collection<unknown>,
14-
options: GetClientWaiterStatesOptions
7+
clientIdentifiers: ClientIdentifier[]
158
): Set<string> => {
169
const waiterStates: string[] = [];
1710

18-
const clientIdentifiers = getClientIdentifiers(j, source, options);
19-
2011
for (const clientId of clientIdentifiers) {
2112
source
2213
.find(j.CallExpression, {

src/transforms/v2-to-v3/apis/getS3SignedUrlApiNames.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
import { Collection, JSCodeshift, Literal } from "jscodeshift";
22

3-
import { getClientIdentifiers } from "./getClientIdentifiers";
4-
5-
export interface GetS3SignedUrlApiNameOptions {
6-
v2ClientName: string;
7-
v2ClientLocalName: string;
8-
v2GlobalName?: string;
9-
}
3+
import { ClientIdentifier } from "../types";
104

115
export const getS3SignedUrlApiNames = (
126
j: JSCodeshift,
137
source: Collection<unknown>,
14-
options: GetS3SignedUrlApiNameOptions
8+
clientIdentifiers: ClientIdentifier[]
159
): string[] => {
16-
if (options.v2ClientName !== "S3") return [];
17-
1810
const apiNames: Set<string> = new Set();
19-
const clientIdentifiers = getClientIdentifiers(j, source, options);
2011

2112
for (const clientId of clientIdentifiers) {
2213
for (const apiName of ["getSignedUrl", "getSignedUrlPromise"]) {

src/transforms/v2-to-v3/apis/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ export * from "./replaceS3GetSignedUrlApi";
1010
export * from "./replaceS3UploadApi";
1111
export * from "./replaceWaiterApi";
1212
export * from "./getCommandName";
13+
export * from "./getClientIdentifiersRecord";

0 commit comments

Comments
 (0)