-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utility getV2ClientNewExpression (#224)
- Loading branch information
Showing
6 changed files
with
51 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"aws-sdk-js-codemod": patch | ||
--- | ||
|
||
Add utility getV2ClientNewExpression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 3 additions & 7 deletions
10
src/transforms/v2-to-v3/utils/get/getV2ClientNamesFromNewExpr.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/transforms/v2-to-v3/utils/get/getV2ClientNewExpression.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { NewExpression } from "jscodeshift"; | ||
|
||
export interface ClientNewExpressionOptions { | ||
v2DefaultModuleName?: string; | ||
v2ClientName?: string; | ||
isDocumentClient?: boolean; | ||
} | ||
|
||
export const getV2ClientNewExpression = ({ | ||
v2DefaultModuleName, | ||
v2ClientName, | ||
}: ClientNewExpressionOptions): NewExpression => { | ||
if (!v2DefaultModuleName && !v2ClientName) { | ||
throw new Error( | ||
`At least one of the following options must be provided: v2DefaultModuleName, v2ClientName` | ||
); | ||
} | ||
|
||
if (v2DefaultModuleName) { | ||
return { | ||
type: "NewExpression", | ||
callee: { | ||
object: { type: "Identifier", name: v2DefaultModuleName }, | ||
property: { type: "Identifier", ...(v2ClientName && { name: v2ClientName }) }, | ||
}, | ||
} as NewExpression; | ||
} | ||
|
||
return { | ||
type: "NewExpression", | ||
callee: { type: "Identifier", name: v2ClientName }, | ||
} as NewExpression; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters