Skip to content

[DRAFT] Transform deep import of DocumentClient #847

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Transformation of DocumentClient named import from deep path is unsupported in aws-sdk-js-codemod.
// Please convert to a default import, and re-run aws-sdk-js-codemod.
import { DocumentClient } from "aws-sdk/clients/dynamodb";
import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
import { DynamoDB } from "@aws-sdk/client-dynamodb";

const documentClient = new DocumentClient({ region: "us-west-2" });
const response = await documentClient.scan({ TableName: "TABLE_NAME" }).promise();
const documentClient = DynamoDBDocument.from(new DynamoDB());
const response = await documentClient.scan({ TableName: "TABLE_NAME" });
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Transformation of DocumentClient named import from deep path is unsupported in aws-sdk-js-codemod.
// Please convert to a default import, and re-run aws-sdk-js-codemod.
const { DocumentClient } = require("aws-sdk/clients/dynamodb");
const { DynamoDBDocument } = require("@aws-sdk/lib-dynamodb");
const { DynamoDB } = require("@aws-sdk/client-dynamodb");

const documentClient = new DocumentClient({ region: "us-west-2" });
const documentClient = DynamoDBDocument.from(new DynamoDB());
const response = await documentClient.scan({ TableName: "TABLE_NAME" }).promise();
27 changes: 0 additions & 27 deletions src/transforms/v2-to-v3/apis/addNotSupportedComments.ts

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion src/transforms/v2-to-v3/apis/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from "./addEmptyObjectForUndefined";
export * from "./addNotSupportedClientComments";
export * from "./addNotSupportedComments";
export * from "./getClientIdentifiersRecord";
export * from "./getClientWaiterStates";
export * from "./getCommandName";
Expand Down
20 changes: 16 additions & 4 deletions src/transforms/v2-to-v3/client-names/getClientNamesRecord.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Collection, JSCodeshift } from "jscodeshift";

import { CLIENT_NAMES, PACKAGE_NAME } from "../config";
import { CLIENT_NAMES, DOCUMENT_CLIENT, DYNAMODB_DOCUMENT_CLIENT, PACKAGE_NAME } from "../config";
import { ImportType } from "../modules";
import * as importEqualsModule from "../modules/importEqualsModule";
import * as importModule from "../modules/importModule";
Expand Down Expand Up @@ -37,11 +37,23 @@ export const getClientNamesRecord = (
for (const clientName of clientNamesFromDeepImport) {
const deepImportPath = getClientDeepImportPath(clientName);

const specifiersFromDeepImport = getImportSpecifiers(j, source, deepImportPath).filter(
const specifiersFromNamedImport = getImportSpecifiers(j, source, deepImportPath);

const defaultSpecifiersFromDeepImport = specifiersFromNamedImport.filter(
(importSpecifier) => !importSpecifier.importedName
);
if (specifiersFromDeepImport.length > 0) {
clientNamesRecord[clientName] = specifiersFromDeepImport[0].localName;
if (defaultSpecifiersFromDeepImport.length > 0) {
clientNamesRecord[clientName] = defaultSpecifiersFromDeepImport[0].localName;
}

const namedSpecifiersFromDeepImport = specifiersFromNamedImport.filter(
(importSpecifier) => importSpecifier.importedName
);
if (
namedSpecifiersFromDeepImport.length > 0 &&
namedSpecifiersFromDeepImport[0].importedName === DOCUMENT_CLIENT
) {
clientNamesRecord[DYNAMODB_DOCUMENT_CLIENT] = namedSpecifiersFromDeepImport[0].localName;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/transforms/v2-to-v3/config/CLIENT_NAMES_MAP.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CLIENT_NAMES } from "./CLIENT_NAMES";
import { DOCUMENT_CLIENT, DYNAMODB_DOCUMENT_CLIENT } from "./constants";

// The key is the client name in v2, and value is the client name in v3.
export const CLIENT_NAMES_MAP: Record<string, string> = {
Expand Down Expand Up @@ -30,4 +31,5 @@ export const CLIENT_NAMES_MAP: Record<string, string> = {
SavingsPlans: "Savingsplans",
StepFunctions: "SFN",
TranscribeService: "Transcribe",
[DYNAMODB_DOCUMENT_CLIENT]: DOCUMENT_CLIENT,
};
3 changes: 0 additions & 3 deletions src/transforms/v2-to-v3/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { API, FileInfo } from "jscodeshift";

import {
addNotSupportedComments,
addNotSupportedClientComments,
removePromiseCalls,
replaceWaiterApi,
Expand Down Expand Up @@ -49,8 +48,6 @@ const transformer = async (file: FileInfo, api: API) => {
return file.source;
}

addNotSupportedComments(j, source, importType);

const v2GlobalName = getGlobalNameFromModule(j, source);
const v2ClientNamesRecord = getClientNamesRecord(j, source, importType);

Expand Down
Loading