Skip to content

Commit 86fa6d7

Browse files
authored
Remove v2 and v3 from utility names in apis folder (#455)
1 parent 2c48ffd commit 86fa6d7

14 files changed

+90
-92
lines changed

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

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

33
import { FUNCTION_TYPE_LIST } from "../config";
4+
import { getClientIdentifiers } from "./getClientIdentifiers";
5+
import { getClientWaiterCallExpression } from "./getClientWaiterCallExpression";
46
import { getClientWaiterStates } from "./getClientWaiterStates";
5-
import { getV2ClientIdentifiers } from "./getV2ClientIdentifiers";
6-
import { getV2ClientS3UploadCallExpression } from "./getV2ClientS3UploadCallExpression";
7-
import { getV2ClientWaiterCallExpression } from "./getV2ClientWaiterCallExpression";
7+
import { getS3UploadCallExpression } from "./getS3UploadCallExpression";
88

99
export interface CommentsForUnsupportedAPIsOptions {
1010
v2ClientName: string;
@@ -17,14 +17,14 @@ export const addNotSupportedComments = (
1717
source: Collection<unknown>,
1818
options: CommentsForUnsupportedAPIsOptions
1919
): void => {
20-
const v2ClientIdentifiers = getV2ClientIdentifiers(j, source, options);
20+
const clientIdentifiers = getClientIdentifiers(j, source, options);
2121

22-
for (const v2ClientId of v2ClientIdentifiers) {
22+
for (const clientId of clientIdentifiers) {
2323
const waiterStates = getClientWaiterStates(j, source, options);
2424

2525
for (const waiterState of waiterStates) {
2626
source
27-
.find(j.CallExpression, getV2ClientWaiterCallExpression(v2ClientId, waiterState))
27+
.find(j.CallExpression, getClientWaiterCallExpression(clientId, waiterState))
2828
.forEach((callExpression) => {
2929
const args = callExpression.node.arguments;
3030

@@ -47,9 +47,9 @@ export const addNotSupportedComments = (
4747
}
4848

4949
if (options.v2ClientName === "S3") {
50-
for (const v2ClientId of v2ClientIdentifiers) {
50+
for (const clientId of clientIdentifiers) {
5151
source
52-
.find(j.CallExpression, getV2ClientS3UploadCallExpression(v2ClientId))
52+
.find(j.CallExpression, getS3UploadCallExpression(clientId))
5353
.forEach((callExpression) => {
5454
const args = callExpression.node.arguments;
5555

src/transforms/v2-to-v3/apis/getV2ClientIdNamesFromNewExpr.ts renamed to src/transforms/v2-to-v3/apis/getClientIdNamesFromNewExpr.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Collection, Identifier, JSCodeshift, NewExpression } from "jscodeshift"
22

33
import { getClientNewExpression } from "../utils";
44

5-
export interface GetV2ClientIdNamesFromNewExprOptions {
5+
export interface GetClientIdNamesFromNewExprOptions {
66
v2ClientName: string;
77
v2ClientLocalName: string;
88
v2GlobalName?: string;
@@ -34,10 +34,10 @@ const getNamesFromAssignmentPattern = (
3434
.nodes()
3535
.map((assignmentPattern) => (assignmentPattern.left as Identifier).name);
3636

37-
export const getV2ClientIdNamesFromNewExpr = (
37+
export const getClientIdNamesFromNewExpr = (
3838
j: JSCodeshift,
3939
source: Collection<unknown>,
40-
{ v2ClientName, v2ClientLocalName, v2GlobalName }: GetV2ClientIdNamesFromNewExprOptions
40+
{ v2ClientName, v2ClientLocalName, v2GlobalName }: GetClientIdNamesFromNewExprOptions
4141
): string[] => {
4242
const namesFromGlobalModule = [];
4343
const namesFromServiceModule = [];

src/transforms/v2-to-v3/apis/getV2ClientIdNamesFromTSTypeRef.ts renamed to src/transforms/v2-to-v3/apis/getClientIdNamesFromTSTypeRef.ts

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

3-
export interface GetV2ClientIdNamesFromTSTypeRefOptions {
3+
export interface GetClientIdNamesFromTSTypeRefOptions {
44
v2ClientName: string;
55
v2GlobalName?: string;
66
}
77

8-
export const getV2ClientIdNamesFromTSTypeRef = (
8+
export const getClientIdNamesFromTSTypeRef = (
99
j: JSCodeshift,
1010
source: Collection<unknown>,
11-
{ v2GlobalName, v2ClientName }: GetV2ClientIdNamesFromTSTypeRefOptions
11+
{ v2GlobalName, v2ClientName }: GetClientIdNamesFromTSTypeRefOptions
1212
): string[] => {
1313
const namesFromGlobalName = v2GlobalName
1414
? source

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ export interface ThisMemberExpression {
88

99
const thisMemberExpression = { type: "MemberExpression", object: { type: "ThisExpression" } };
1010

11-
export const getV2ClientIdThisExpressions = (
11+
export const getClientIdThisExpressions = (
1212
j: JSCodeshift,
1313
source: Collection<unknown>,
14-
v2ClientIdentifiers: Identifier[]
14+
clientIdentifiers: Identifier[]
1515
): ThisMemberExpression[] =>
16-
v2ClientIdentifiers.flatMap((v2ClientIdentifier) =>
16+
clientIdentifiers.flatMap((clientIdentifier) =>
1717
source
1818
.find(j.AssignmentExpression, {
1919
left: thisMemberExpression as MemberExpression,
20-
right: v2ClientIdentifier,
20+
right: clientIdentifier,
2121
})
2222
.nodes()
2323
.map(
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Collection, Identifier, JSCodeshift } from "jscodeshift";
2+
3+
import { getClientIdNamesFromNewExpr } from "./getClientIdNamesFromNewExpr";
4+
import { getClientIdNamesFromTSTypeRef } from "./getClientIdNamesFromTSTypeRef";
5+
import { getClientIdThisExpressions, ThisMemberExpression } from "./getClientIdThisExpressions";
6+
7+
export interface GetClientIdentifiersOptions {
8+
v2ClientName: string;
9+
v2ClientLocalName: string;
10+
v2GlobalName?: string;
11+
}
12+
13+
export type ClientIdentifier = Identifier | ThisMemberExpression;
14+
15+
export const getClientIdentifiers = (
16+
j: JSCodeshift,
17+
source: Collection<unknown>,
18+
options: GetClientIdentifiersOptions
19+
): ClientIdentifier[] => {
20+
const namesFromNewExpr = getClientIdNamesFromNewExpr(j, source, options);
21+
const namesFromTSTypeRef = getClientIdNamesFromTSTypeRef(j, source, options);
22+
const clientIdNames = [...new Set([...namesFromNewExpr, ...namesFromTSTypeRef])];
23+
24+
const clientIdentifiers: Identifier[] = clientIdNames.map((clientidName) => ({
25+
type: "Identifier",
26+
name: clientidName,
27+
}));
28+
const clientIdThisExpressions = getClientIdThisExpressions(j, source, clientIdentifiers);
29+
30+
return [...clientIdentifiers, ...clientIdThisExpressions];
31+
};

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { CallExpression } from "jscodeshift";
22

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

5-
export const getV2ClientWaiterCallExpression = (
6-
v2ClientId: V2ClientIdentifier,
5+
export const getClientWaiterCallExpression = (
6+
v2ClientId: ClientIdentifier,
77
waiterState: string
88
): CallExpression => ({
99
type: "CallExpression",

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

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

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

55
export interface GetClientWaiterStatesOptions {
66
v2ClientName: string;
@@ -15,14 +15,14 @@ export const getClientWaiterStates = (
1515
): Set<string> => {
1616
const waiterStates: string[] = [];
1717

18-
const v2ClientIdentifiers = getV2ClientIdentifiers(j, source, options);
18+
const clientIdentifiers = getClientIdentifiers(j, source, options);
1919

20-
for (const v2ClientId of v2ClientIdentifiers) {
20+
for (const clientId of clientIdentifiers) {
2121
source
2222
.find(j.CallExpression, {
2323
callee: {
2424
type: "MemberExpression",
25-
object: v2ClientId,
25+
object: clientId,
2626
property: { type: "Identifier", name: "waitFor" },
2727
},
2828
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { CallExpression } from "jscodeshift";
2+
3+
import { ClientIdentifier } from "./getClientIdentifiers";
4+
5+
// @ts-expect-error Property 'arguments' is missing in type
6+
export const getS3UploadCallExpression = (clientId: ClientIdentifier): CallExpression => ({
7+
type: "CallExpression",
8+
callee: {
9+
type: "MemberExpression",
10+
object: clientId,
11+
property: { type: "Identifier", name: "upload" },
12+
},
13+
});

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

Lines changed: 0 additions & 31 deletions
This file was deleted.

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

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)