Skip to content

feat(lib-dynamodb): add DynamoDB DocumentClient #2097

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

Merged
merged 33 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f65c8a4
feat(lib-dynamodb): add scaffolding for new package
trivikr Mar 2, 2021
f3f4a2c
feat(codegen): utilities for DynamoDB DocumentClient
trivikr Mar 2, 2021
72783c6
feat(codegen): add DocumentClientCommandGenerator
trivikr Mar 2, 2021
5403a99
feat(codegen): add DocumentClientGenerator
trivikr Mar 2, 2021
b92cb07
feat(codegen): add DocumentClientPlugin
trivikr Mar 2, 2021
66c0e37
feat(codegen): copy doc-client customization to lib-dynamodb
trivikr Mar 2, 2021
fd492e0
feat(lib-dynamodb): generate source code with codegen
trivikr Mar 2, 2021
eeaacbc
fix(lib-dynamodb): use typescript ~4.1.2
trivikr Mar 2, 2021
d8c11b4
feat(lib-dynamodb): update README with examples
trivikr Mar 2, 2021
aab653c
chore(codegen): update comment on customization script
trivikr Mar 2, 2021
c988daa
chore(readme): update comments
trivikr Mar 3, 2021
897051e
chore: move common constants to Utils
trivikr Mar 3, 2021
8f4c68e
feat(codegen): add DynamoDBDocument generator
trivikr Mar 3, 2021
b4df59e
feat(lib-dynamodb): add DynamoDBDocument
trivikr Mar 3, 2021
67bb606
chore(codegen): remove comments about sections
trivikr Mar 3, 2021
6aca555
chore(lib-dynamodb): codegen to remove comments on sections
trivikr Mar 3, 2021
722a659
chore(codegen): make DocClientCommand inputKeyNodes/outputKeyNodes cl…
trivikr Mar 3, 2021
6f464db
chore(lib-dynamodb): make DocClientCommand inputKeyNodes/outputKeyNod…
trivikr Mar 3, 2021
1dc78d5
chore(codegen): add documentation for document client and commands
trivikr Mar 3, 2021
a16d71c
chore(lib-dynamodb): add docs for document client and commands
trivikr Mar 3, 2021
608b16b
docs(lib-dynamodb): mention that destroy is a no-op in readme
trivikr Mar 3, 2021
62a1d2e
fix(lib-dynamodb): util shouldn't override input
trivikr Mar 4, 2021
f3014ab
test(lib-dynamodb): add tests for utils file
trivikr Mar 4, 2021
e324af4
chore(lib-dynamodb): throw error on DocClient destroy
trivikr Mar 4, 2021
1e2ac03
chore(lib-dynamodb): revert throw error on DocClient destroy
trivikr Mar 4, 2021
1fe841c
docs: suggestions from comments
trivikr Mar 4, 2021
4f185f2
fix(codegen): update doc client documentation
trivikr Mar 4, 2021
7b5a41a
fix(codegen): export doc client service input and output types
trivikr Mar 4, 2021
4b26208
chore(lib-dynamodb): export doc client service input and output types
trivikr Mar 4, 2021
a9ea795
fix(codegen): generate input output types for Doc Client
trivikr Mar 5, 2021
f9a5d6d
fix(lib-dynamodb): generate input output types for Doc Client
trivikr Mar 5, 2021
3a96e6a
fix(codegen): make document client ServiceInputOutputTypes as parent …
trivikr Mar 5, 2021
1af070e
fix(lib-dynamodb): make document client ServiceInputOutputTypes as pa…
trivikr Mar 5, 2021
File filter

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
@@ -0,0 +1,104 @@
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.smithy.aws.typescript.codegen;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import software.amazon.smithy.aws.traits.ServiceTrait;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.knowledge.TopDownIndex;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.Shape;
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;

/**
* Generates Client and Commands for DynamoDB Document Client.
*/
public class AddDocumentClientPlugin implements TypeScriptIntegration {

@Override
public void writeAdditionalFiles(
TypeScriptSettings settings,
Model model,
SymbolProvider symbolProvider,
BiConsumer<String, Consumer<TypeScriptWriter>> writerFactory
) {
ServiceShape service = settings.getService(model);
if (testServiceId(service, "DynamoDB")) {
String docClientPrefix = "doc-client-";
Set<OperationShape> containedOperations =
new TreeSet<>(TopDownIndex.of(model).getContainedOperations(service));
List<OperationShape> overridenOperationsList = new ArrayList<>();

for (OperationShape operation : containedOperations) {
String operationName = symbolProvider.toSymbol(operation).getName();
String commandFileName = String.format("%s%s/%s.ts", docClientPrefix,
DocumentClientUtils.CLIENT_COMMANDS_FOLDER, DocumentClientUtils.getModifiedName(operationName));

if (DocumentClientUtils.containsAttributeValue(model, symbolProvider, operation)) {
overridenOperationsList.add(operation);
writerFactory.accept(commandFileName,
writer -> new DocumentClientCommandGenerator(
settings, model, operation, symbolProvider, writer).run()
);
}
}

writerFactory.accept(String.format("%s%s.ts", docClientPrefix, DocumentClientUtils.CLIENT_NAME),
writer -> new DocumentClientGenerator(settings, model, symbolProvider, writer).run());

writerFactory.accept(String.format("%s%s.ts", docClientPrefix, DocumentClientUtils.CLIENT_FULL_NAME),
writer -> new DocumentFullClientGenerator(settings, model, symbolProvider, writer).run());

writerFactory.accept(String.format("%sindex.ts", docClientPrefix), writer -> {
for (OperationShape operationOverriden: overridenOperationsList) {
String operationFileName = DocumentClientUtils.getModifiedName(
symbolProvider.toSymbol(operationOverriden).getName()
);
writer.write("export * from './$L/$L';",
DocumentClientUtils.CLIENT_COMMANDS_FOLDER, operationFileName);
}
writer.write("export * from './$L';", DocumentClientUtils.CLIENT_NAME);
writer.write("export * from './$L';", DocumentClientUtils.CLIENT_FULL_NAME);
});

String utilsFileLocation = String.format("%s%s", docClientPrefix, DocumentClientUtils.CLIENT_UTILS_FILE);
writerFactory.accept(String.format("%s%s/%s.ts", docClientPrefix,
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", docClientPrefix,
DocumentClientUtils.CLIENT_COMMANDS_FOLDER, DocumentClientUtils.CLIENT_UTILS_FILE), writer -> {
writer.write(IoUtils.readUtf8Resource(AddDocumentClientPlugin.class,
String.format("%s.spec.ts", utilsFileLocation)));
});
}
}

private boolean testServiceId(Shape serviceShape, String expectedId) {
return serviceShape.getTrait(ServiceTrait.class).map(ServiceTrait::getSdkId).orElse("").equals(expectedId);
}
}
Loading