Skip to content

Commit

Permalink
fix(lib-dynamodb): add e2e suite and bug fixes for lib-dynamodb (#5306)
Browse files Browse the repository at this point in the history
* fix(lib-dynamodb): add e2e suite for lib-dynamodb

* fix(lib-dynamodb): passing e2e tests

* fix(lib-dynamodb): fix unit tests

* fix(lib-dynamodb): make utils.spec non-generated

* fix(lib-dynamodb): add additional e2e tests

* fix: remove unused imports

* test: more e2e cases

* fix(lib-dynamodb): e2e scenarios WIP

* fix(lib-dynamodb): use more readable keynode format

* fix: update packages/util-dynamodb/src/unmarshall.ts

Co-authored-by: Trivikram Kamat <[email protected]>

* fix(lib-dynamodb): use random table name and drop table after test

---------

Co-authored-by: Trivikram Kamat <[email protected]>
  • Loading branch information
kuhe and trivikr authored Oct 6, 2023
1 parent 7cac08f commit 2fe0a88
Show file tree
Hide file tree
Showing 30 changed files with 1,060 additions and 498 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
import software.amazon.smithy.utils.IoUtils;
import software.amazon.smithy.utils.SmithyInternalApi;

/**
Expand Down Expand Up @@ -125,19 +124,6 @@ private void writeAdditionalFiles(
writer.write("export * from './$L';", DocumentClientUtils.CLIENT_NAME);
writer.write("export * from './$L';", DocumentClientUtils.CLIENT_FULL_NAME);
});

String utilsFileLocation = String.format("%s%s", DocumentClientUtils.DOC_CLIENT_PREFIX,
DocumentClientUtils.CLIENT_UTILS_FILE);
writerFactory.accept(String.format("%s%s/%s.ts", DocumentClientUtils.DOC_CLIENT_PREFIX,
DocumentClientUtils.CLIENT_COMMANDS_FOLDER, DocumentClientUtils.CLIENT_UTILS_FILE), writer -> {
writer.write(IoUtils.readUtf8Resource(AddDocumentClientPlugin.class,
String.format("%s.ts", utilsFileLocation)));
});
writerFactory.accept(String.format("%s%s/%s.spec.ts", DocumentClientUtils.DOC_CLIENT_PREFIX,
DocumentClientUtils.CLIENT_COMMANDS_FOLDER, DocumentClientUtils.CLIENT_UTILS_FILE), writer -> {
writer.write(IoUtils.readUtf8Resource(AddDocumentClientPlugin.class,
String.format("%s.spec.ts", utilsFileLocation)));
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ public void run() {
() -> {
// Section for adding custom command properties.
writer.pushState(COMMAND_PROPERTIES_SECTION);
writer.openBlock("protected readonly $L = [", "];", COMMAND_INPUT_KEYNODES, () -> {
writer.openBlock("protected readonly $L = {", "};", COMMAND_INPUT_KEYNODES, () -> {
writeKeyNodes(inputMembersWithAttr);
});
writer.openBlock("protected readonly $L = [", "];", COMMAND_OUTPUT_KEYNODES, () -> {
writer.openBlock("protected readonly $L = {", "};", COMMAND_OUTPUT_KEYNODES, () -> {
writeKeyNodes(outputMembersWithAttr);
});
writer.popState();
Expand Down Expand Up @@ -220,7 +220,7 @@ private void generateCommandMiddlewareResolver(String configType) {

private void writeKeyNodes(List<MemberShape> membersWithAttr) {
for (MemberShape member: membersWithAttr) {
writer.openBlock("{key: '$L', ", "},", symbolProvider.toMemberName(member), () -> {
writer.openBlock("'$L': ", ",", symbolProvider.toMemberName(member), () -> {
writeKeyNode(member);
});
}
Expand All @@ -230,9 +230,21 @@ private void writeKeyNode(MemberShape member) {
Shape memberTarget = model.expectShape(member.getTarget());
if (memberTarget instanceof CollectionShape) {
MemberShape collectionMember = ((CollectionShape) memberTarget).getMember();
writeKeyNode(collectionMember);
Shape collectionMemberTarget = model.expectShape(collectionMember.getTarget());
if (collectionMemberTarget.isUnionShape()
&& symbolProvider.toSymbol(collectionMemberTarget).getName().equals("AttributeValue")) {
writer.addImport("ALL_MEMBERS", null, "../src/commands/utils");
writer.write("ALL_MEMBERS // set/list of AttributeValue");
return;
}
writer.openBlock("{", "}", () -> {
writer.write("'*':");
writeKeyNode(collectionMember);
});
} else if (memberTarget.isUnionShape()) {
if (symbolProvider.toSymbol(memberTarget).getName().equals("AttributeValue")) {
writer.addImport("SELF", null, "../src/commands/utils");
writer.write("SELF");
return;
} else {
// An AttributeValue inside Union is not present as of Q1 2021, and is less
Expand All @@ -241,29 +253,30 @@ private void writeKeyNode(MemberShape member) {
"AttributeValue inside Union is not supported, attempted for %s", memberTarget.getType()
));
}
} else {
if (memberTarget.isMapShape()) {
MemberShape mapMember = ((MapShape) memberTarget).getValue();
Shape mapMemberTarget = model.expectShape(mapMember.getTarget());
if (mapMemberTarget.isUnionShape()
&& symbolProvider.toSymbol(mapMemberTarget).getName().equals("AttributeValue")) {
return;
} else {
writer.openBlock("children: {", "},", () -> {
writeKeyNode(mapMember);
});
}
} else if (memberTarget.isStructureShape()) {
writeStructureKeyNode((StructureShape) memberTarget);
} else if (memberTarget.isMapShape()) {
MemberShape mapMember = ((MapShape) memberTarget).getValue();
Shape mapMemberTarget = model.expectShape(mapMember.getTarget());
if (mapMemberTarget.isUnionShape()
&& symbolProvider.toSymbol(mapMemberTarget).getName().equals("AttributeValue")) {
writer.addImport("ALL_VALUES", null, "../src/commands/utils");
writer.write("ALL_VALUES // map with AttributeValue");
return;
} else {
writer.openBlock("{", "}", () -> {
writer.write("'*':");
writeKeyNode(mapMember);
});
}
} else if (memberTarget.isStructureShape()) {
writeStructureKeyNode((StructureShape) memberTarget);
}
}

private void writeStructureKeyNode(StructureShape structureTarget) {
List<MemberShape> membersWithAttr = getStructureMembersWithAttr(Optional.of(structureTarget));
writer.openBlock("children: [", "],", () -> {
writer.openBlock("{", "}", () -> {
for (MemberShape member: membersWithAttr) {
writer.openBlock("{key: '$L', ", "},", symbolProvider.toMemberName(member), () -> {
writer.openBlock("'$L': ", ",", symbolProvider.toMemberName(member), () -> {
writeKeyNode(member);
});
}
Expand Down

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions lib/lib-dynamodb/jest.config.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
preset: "ts-jest",
testMatch: ["**/*.e2e.spec.ts"],
bail: true,
};
3 changes: 2 additions & 1 deletion lib/lib-dynamodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"extract:docs": "api-extractor run --local",
"test": "jest"
"test": "jest",
"test:e2e": "jest --config jest.config.e2e.js"
},
"engines": {
"node": ">=14.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Handler, MiddlewareStack } from "@smithy/types";

import { KeyNode } from "../commands/utils";
import { KeyNodeChildren } from "../commands/utils";
import { DynamoDBDocumentClientCommand } from "./DynamoDBDocumentClientCommand";

class AnyCommand extends DynamoDBDocumentClientCommand<{}, {}, {}, {}, {}> {
public middlewareStack: MiddlewareStack<{}, {}>;
public input: {};
protected inputKeyNodes: KeyNode[] = [];
protected outputKeyNodes: KeyNode[] = [];
protected inputKeyNodes: KeyNodeChildren = {};
protected outputKeyNodes: KeyNodeChildren = {};

public argCaptor: [Function, object][] = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
MiddlewareStack,
} from "@smithy/types";

import { KeyNode, marshallInput, unmarshallOutput } from "../commands/utils";
import { KeyNodeChildren, marshallInput, unmarshallOutput } from "../commands/utils";
import { DynamoDBDocumentClientResolvedConfig } from "../DynamoDBDocumentClient";

// /** @public */
Expand All @@ -29,8 +29,8 @@ export abstract class DynamoDBDocumentClientCommand<
BaseOutput extends object,
ResolvedClientConfiguration
> extends $Command<Input | BaseInput, Output | BaseOutput, ResolvedClientConfiguration> {
protected abstract readonly inputKeyNodes: KeyNode[];
protected abstract readonly outputKeyNodes: KeyNode[];
protected abstract readonly inputKeyNodes: KeyNodeChildren;
protected abstract readonly outputKeyNodes: KeyNodeChildren;
protected abstract clientCommand: $Command<Input | BaseInput, Output | BaseOutput, ResolvedClientConfiguration>;

public abstract middlewareStack: MiddlewareStack<Input | BaseInput, Output | BaseOutput>;
Expand All @@ -41,7 +41,10 @@ export abstract class DynamoDBDocumentClientCommand<
};

protected addMarshallingMiddleware(configuration: DynamoDBDocumentClientResolvedConfig): void {
const { marshallOptions, unmarshallOptions } = configuration.translateConfig || {};
const { marshallOptions = {}, unmarshallOptions = {} } = configuration.translateConfig || {};

marshallOptions.convertTopLevelContainer = marshallOptions.convertTopLevelContainer ?? true;
unmarshallOptions.convertWithoutMapWrapper = unmarshallOptions.convertWithoutMapWrapper ?? true;

this.clientCommand.middlewareStack.addRelativeTo(
(next: InitializeHandler<Input | BaseInput, Output | BaseOutput>, context: HandlerExecutionContext) =>
Expand Down
Loading

0 comments on commit 2fe0a88

Please sign in to comment.