Skip to content

Commit 2fe0a88

Browse files
kuhetrivikr
andauthored
fix(lib-dynamodb): add e2e suite and bug fixes for lib-dynamodb (#5306)
* 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]>
1 parent 7cac08f commit 2fe0a88

30 files changed

+1060
-498
lines changed

Diff for: codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddDocumentClientPlugin.java

-14
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
3434
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
3535
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
36-
import software.amazon.smithy.utils.IoUtils;
3736
import software.amazon.smithy.utils.SmithyInternalApi;
3837

3938
/**
@@ -125,19 +124,6 @@ private void writeAdditionalFiles(
125124
writer.write("export * from './$L';", DocumentClientUtils.CLIENT_NAME);
126125
writer.write("export * from './$L';", DocumentClientUtils.CLIENT_FULL_NAME);
127126
});
128-
129-
String utilsFileLocation = String.format("%s%s", DocumentClientUtils.DOC_CLIENT_PREFIX,
130-
DocumentClientUtils.CLIENT_UTILS_FILE);
131-
writerFactory.accept(String.format("%s%s/%s.ts", DocumentClientUtils.DOC_CLIENT_PREFIX,
132-
DocumentClientUtils.CLIENT_COMMANDS_FOLDER, DocumentClientUtils.CLIENT_UTILS_FILE), writer -> {
133-
writer.write(IoUtils.readUtf8Resource(AddDocumentClientPlugin.class,
134-
String.format("%s.ts", utilsFileLocation)));
135-
});
136-
writerFactory.accept(String.format("%s%s/%s.spec.ts", DocumentClientUtils.DOC_CLIENT_PREFIX,
137-
DocumentClientUtils.CLIENT_COMMANDS_FOLDER, DocumentClientUtils.CLIENT_UTILS_FILE), writer -> {
138-
writer.write(IoUtils.readUtf8Resource(AddDocumentClientPlugin.class,
139-
String.format("%s.spec.ts", utilsFileLocation)));
140-
});
141127
}
142128
}
143129

Diff for: codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/DocumentClientCommandGenerator.java

+33-20
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ public void run() {
134134
() -> {
135135
// Section for adding custom command properties.
136136
writer.pushState(COMMAND_PROPERTIES_SECTION);
137-
writer.openBlock("protected readonly $L = [", "];", COMMAND_INPUT_KEYNODES, () -> {
137+
writer.openBlock("protected readonly $L = {", "};", COMMAND_INPUT_KEYNODES, () -> {
138138
writeKeyNodes(inputMembersWithAttr);
139139
});
140-
writer.openBlock("protected readonly $L = [", "];", COMMAND_OUTPUT_KEYNODES, () -> {
140+
writer.openBlock("protected readonly $L = {", "};", COMMAND_OUTPUT_KEYNODES, () -> {
141141
writeKeyNodes(outputMembersWithAttr);
142142
});
143143
writer.popState();
@@ -220,7 +220,7 @@ private void generateCommandMiddlewareResolver(String configType) {
220220

221221
private void writeKeyNodes(List<MemberShape> membersWithAttr) {
222222
for (MemberShape member: membersWithAttr) {
223-
writer.openBlock("{key: '$L', ", "},", symbolProvider.toMemberName(member), () -> {
223+
writer.openBlock("'$L': ", ",", symbolProvider.toMemberName(member), () -> {
224224
writeKeyNode(member);
225225
});
226226
}
@@ -230,9 +230,21 @@ private void writeKeyNode(MemberShape member) {
230230
Shape memberTarget = model.expectShape(member.getTarget());
231231
if (memberTarget instanceof CollectionShape) {
232232
MemberShape collectionMember = ((CollectionShape) memberTarget).getMember();
233-
writeKeyNode(collectionMember);
233+
Shape collectionMemberTarget = model.expectShape(collectionMember.getTarget());
234+
if (collectionMemberTarget.isUnionShape()
235+
&& symbolProvider.toSymbol(collectionMemberTarget).getName().equals("AttributeValue")) {
236+
writer.addImport("ALL_MEMBERS", null, "../src/commands/utils");
237+
writer.write("ALL_MEMBERS // set/list of AttributeValue");
238+
return;
239+
}
240+
writer.openBlock("{", "}", () -> {
241+
writer.write("'*':");
242+
writeKeyNode(collectionMember);
243+
});
234244
} else if (memberTarget.isUnionShape()) {
235245
if (symbolProvider.toSymbol(memberTarget).getName().equals("AttributeValue")) {
246+
writer.addImport("SELF", null, "../src/commands/utils");
247+
writer.write("SELF");
236248
return;
237249
} else {
238250
// An AttributeValue inside Union is not present as of Q1 2021, and is less
@@ -241,29 +253,30 @@ private void writeKeyNode(MemberShape member) {
241253
"AttributeValue inside Union is not supported, attempted for %s", memberTarget.getType()
242254
));
243255
}
244-
} else {
245-
if (memberTarget.isMapShape()) {
246-
MemberShape mapMember = ((MapShape) memberTarget).getValue();
247-
Shape mapMemberTarget = model.expectShape(mapMember.getTarget());
248-
if (mapMemberTarget.isUnionShape()
249-
&& symbolProvider.toSymbol(mapMemberTarget).getName().equals("AttributeValue")) {
250-
return;
251-
} else {
252-
writer.openBlock("children: {", "},", () -> {
253-
writeKeyNode(mapMember);
254-
});
255-
}
256-
} else if (memberTarget.isStructureShape()) {
257-
writeStructureKeyNode((StructureShape) memberTarget);
256+
} else if (memberTarget.isMapShape()) {
257+
MemberShape mapMember = ((MapShape) memberTarget).getValue();
258+
Shape mapMemberTarget = model.expectShape(mapMember.getTarget());
259+
if (mapMemberTarget.isUnionShape()
260+
&& symbolProvider.toSymbol(mapMemberTarget).getName().equals("AttributeValue")) {
261+
writer.addImport("ALL_VALUES", null, "../src/commands/utils");
262+
writer.write("ALL_VALUES // map with AttributeValue");
263+
return;
264+
} else {
265+
writer.openBlock("{", "}", () -> {
266+
writer.write("'*':");
267+
writeKeyNode(mapMember);
268+
});
258269
}
270+
} else if (memberTarget.isStructureShape()) {
271+
writeStructureKeyNode((StructureShape) memberTarget);
259272
}
260273
}
261274

262275
private void writeStructureKeyNode(StructureShape structureTarget) {
263276
List<MemberShape> membersWithAttr = getStructureMembersWithAttr(Optional.of(structureTarget));
264-
writer.openBlock("children: [", "],", () -> {
277+
writer.openBlock("{", "}", () -> {
265278
for (MemberShape member: membersWithAttr) {
266-
writer.openBlock("{key: '$L', ", "},", symbolProvider.toMemberName(member), () -> {
279+
writer.openBlock("'$L': ", ",", symbolProvider.toMemberName(member), () -> {
267280
writeKeyNode(member);
268281
});
269282
}

Diff for: codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/doc-client-utils.spec.ts

-144
This file was deleted.

Diff for: codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/doc-client-utils.ts

-60
This file was deleted.

Diff for: lib/lib-dynamodb/jest.config.e2e.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
preset: "ts-jest",
3+
testMatch: ["**/*.e2e.spec.ts"],
4+
bail: true,
5+
};

Diff for: lib/lib-dynamodb/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1515
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1616
"extract:docs": "api-extractor run --local",
17-
"test": "jest"
17+
"test": "jest",
18+
"test:e2e": "jest --config jest.config.e2e.js"
1819
},
1920
"engines": {
2021
"node": ">=14.0.0"

Diff for: lib/lib-dynamodb/src/baseCommand/DynamoDBDocumentClientCommand.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Handler, MiddlewareStack } from "@smithy/types";
22

3-
import { KeyNode } from "../commands/utils";
3+
import { KeyNodeChildren } from "../commands/utils";
44
import { DynamoDBDocumentClientCommand } from "./DynamoDBDocumentClientCommand";
55

66
class AnyCommand extends DynamoDBDocumentClientCommand<{}, {}, {}, {}, {}> {
77
public middlewareStack: MiddlewareStack<{}, {}>;
88
public input: {};
9-
protected inputKeyNodes: KeyNode[] = [];
10-
protected outputKeyNodes: KeyNode[] = [];
9+
protected inputKeyNodes: KeyNodeChildren = {};
10+
protected outputKeyNodes: KeyNodeChildren = {};
1111

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

Diff for: lib/lib-dynamodb/src/baseCommand/DynamoDBDocumentClientCommand.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
MiddlewareStack,
1111
} from "@smithy/types";
1212

13-
import { KeyNode, marshallInput, unmarshallOutput } from "../commands/utils";
13+
import { KeyNodeChildren, marshallInput, unmarshallOutput } from "../commands/utils";
1414
import { DynamoDBDocumentClientResolvedConfig } from "../DynamoDBDocumentClient";
1515

1616
// /** @public */
@@ -29,8 +29,8 @@ export abstract class DynamoDBDocumentClientCommand<
2929
BaseOutput extends object,
3030
ResolvedClientConfiguration
3131
> extends $Command<Input | BaseInput, Output | BaseOutput, ResolvedClientConfiguration> {
32-
protected abstract readonly inputKeyNodes: KeyNode[];
33-
protected abstract readonly outputKeyNodes: KeyNode[];
32+
protected abstract readonly inputKeyNodes: KeyNodeChildren;
33+
protected abstract readonly outputKeyNodes: KeyNodeChildren;
3434
protected abstract clientCommand: $Command<Input | BaseInput, Output | BaseOutput, ResolvedClientConfiguration>;
3535

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

4343
protected addMarshallingMiddleware(configuration: DynamoDBDocumentClientResolvedConfig): void {
44-
const { marshallOptions, unmarshallOptions } = configuration.translateConfig || {};
44+
const { marshallOptions = {}, unmarshallOptions = {} } = configuration.translateConfig || {};
45+
46+
marshallOptions.convertTopLevelContainer = marshallOptions.convertTopLevelContainer ?? true;
47+
unmarshallOptions.convertWithoutMapWrapper = unmarshallOptions.convertWithoutMapWrapper ?? true;
4548

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

0 commit comments

Comments
 (0)