Skip to content

chore: use bare-bones and aggregated instead of modular/non-modular #457

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 5 commits into from
Oct 25, 2021
Merged
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
Expand Up @@ -412,14 +412,14 @@ public Void serviceShape(ServiceShape shape) {

private void generateClient(ServiceShape shape) {
// Generate the bare-bones service client.
writers.useShapeWriter(shape, writer -> new ServiceGenerator(
writers.useShapeWriter(shape, writer -> new ServiceBareBonesClientGenerator(
settings, model, symbolProvider, writer, integrations, runtimePlugins, applicationProtocol).run());

// Generate the aggregated service client.
Symbol serviceSymbol = symbolProvider.toSymbol(shape);
String aggregatedClientName = serviceSymbol.getName().replace("Client", "");
String filename = serviceSymbol.getDefinitionFile().replace("Client", "");
writers.useFileWriter(filename, writer -> new NonModularServiceGenerator(
writers.useFileWriter(filename, writer -> new ServiceAggregatedClientGenerator(
settings, model, symbolProvider, aggregatedClientName, writer, applicationProtocol).run());

// Generate each operation for the service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void run() {

private void generateClientCommand() {
Symbol serviceSymbol = symbolProvider.toSymbol(service);
String configType = ServiceGenerator.getResolvedConfigTypeName(serviceSymbol);
String configType = ServiceBareBonesClientGenerator.getResolvedConfigTypeName(serviceSymbol);

// Add required imports.
writer.addImport(configType, configType, serviceSymbol.getNamespace());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class PaginationGenerator implements Runnable {

private final String operationName;
private final String methodName;
private final String nonModularServiceName;
private final String aggregatedClientName;
private final String paginationType;

PaginationGenerator(
Expand All @@ -56,7 +56,7 @@ final class PaginationGenerator implements Runnable {
OperationShape operation,
SymbolProvider symbolProvider,
TypeScriptWriter writer,
String nonModularServiceName
String aggregatedClientName
) {

this.writer = writer;
Expand All @@ -67,11 +67,11 @@ final class PaginationGenerator implements Runnable {
this.outputSymbol = symbolProvider.toSymbol(operation).expectProperty("outputType", Symbol.class);

this.operationName = operation.getId().getName();
this.nonModularServiceName = nonModularServiceName;
this.aggregatedClientName = aggregatedClientName;

// e.g. listObjects
this.methodName = Character.toLowerCase(operationName.charAt(0)) + operationName.substring(1);
this.paginationType = this.nonModularServiceName + "PaginationConfiguration";
this.paginationType = this.aggregatedClientName + "PaginationConfiguration";

PaginatedIndex paginatedIndex = PaginatedIndex.of(model);
Optional<PaginationInfo> paginationInfo = paginatedIndex.getPaginationInfo(service, operation);
Expand All @@ -92,9 +92,9 @@ public void run() {
writer.addImport(outputSymbol.getName(),
outputSymbol.getName(),
outputSymbol.getNamespace());
String nonModularLocation = serviceSymbol.getNamespace()
.replace(serviceSymbol.getName(), nonModularServiceName);
writer.addImport(nonModularServiceName, nonModularServiceName, nonModularLocation);
String aggregatedClientLocation = serviceSymbol.getNamespace()
.replace(serviceSymbol.getName(), aggregatedClientName);
writer.addImport(aggregatedClientName, aggregatedClientName, aggregatedClientLocation);
writer.addImport(serviceSymbol.getName(), serviceSymbol.getName(), serviceSymbol.getNamespace());

// Import Pagination types
Expand All @@ -111,18 +111,18 @@ static String getOutputFilelocation(OperationShape operation) {
}

static void generateServicePaginationInterfaces(
String nonModularServiceName,
String aggregatedClientName,
Symbol service,
TypeScriptWriter writer
) {
writer.addImport("PaginationConfiguration", "PaginationConfiguration", "@aws-sdk/types");
String nonModularLocation = service.getNamespace().replace(service.getName(), nonModularServiceName);
writer.addImport(nonModularServiceName, nonModularServiceName, nonModularLocation);
String aggregatedClientLocation = service.getNamespace().replace(service.getName(), aggregatedClientName);
writer.addImport(aggregatedClientName, aggregatedClientName, aggregatedClientLocation);
writer.addImport(service.getName(), service.getName(), service.getNamespace());

writer.openBlock("export interface $LPaginationConfiguration extends PaginationConfiguration {",
"}", nonModularServiceName, () -> {
writer.write("client: $L | $L;", nonModularServiceName, service.getName());
"}", aggregatedClientName, () -> {
writer.write("client: $L | $L;", aggregatedClientName, service.getName());
});
}

Expand Down Expand Up @@ -183,15 +183,15 @@ private void writePager() {
writer.write("input[$S] = config.pageSize;", pageSize);
}

writer.openBlock("if (config.client instanceof $L) {", "}", nonModularServiceName, () -> {
writer.openBlock("if (config.client instanceof $L) {", "}", aggregatedClientName, () -> {
writer.write("page = await makePagedRequest(config.client, input, ...additionalArguments);");
});
writer.openBlock("else if (config.client instanceof $L) {", "}", serviceTypeName, () -> {
writer.write("page = await makePagedClientRequest(config.client, input, ...additionalArguments);");
});
writer.openBlock("else {", "}", () -> {
writer.write("throw new Error(\"Invalid client, expected $L | $L\");",
nonModularServiceName, serviceTypeName);
aggregatedClientName, serviceTypeName);
});

writer.write("yield page;");
Expand All @@ -214,7 +214,7 @@ private void writeMethodRequest() {
writer.writeDocs("@private");
writer.openBlock(
"const makePagedRequest = async (client: $L, input: $L, ...args: any): Promise<$L> => {",
"}", nonModularServiceName, inputSymbol.getName(),
"}", aggregatedClientName, inputSymbol.getName(),
outputSymbol.getName(), () -> {
writer.write("// @ts-ignore");
writer.write("return await client.$L(input, ...args);", methodName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@
import software.amazon.smithy.utils.StringUtils;

/**
* Generates a non-modular service client.
* Generates aggregated client for service.
*
* <p>This client extends from the modular client and provides named methods
* <p>This client extends from the bare-bones client and provides named methods
* for every operation in the service. Using this client means that all
* operations of a service are considered referenced, meaning they will
* not be removed by tree-shaking.
*/
@SmithyInternalApi
final class NonModularServiceGenerator implements Runnable {
final class ServiceAggregatedClientGenerator implements Runnable {

private final TypeScriptSettings settings;
private final Model model;
private final ServiceShape service;
private final SymbolProvider symbolProvider;
private final TypeScriptWriter writer;
private final String nonModularName;
private final String aggregateClientName;
private final Symbol serviceSymbol;
private final ApplicationProtocol applicationProtocol;

NonModularServiceGenerator(
ServiceAggregatedClientGenerator(
TypeScriptSettings settings,
Model model,
SymbolProvider symbolProvider,
String nonModularName,
String aggregateClientName,
TypeScriptWriter writer,
ApplicationProtocol applicationProtocol
) {
Expand All @@ -59,7 +59,7 @@ final class NonModularServiceGenerator implements Runnable {
this.service = settings.getService(model);
this.symbolProvider = symbolProvider;
this.writer = writer;
this.nonModularName = nonModularName;
this.aggregateClientName = aggregateClientName;
this.applicationProtocol = applicationProtocol;
serviceSymbol = symbolProvider.toSymbol(service);
}
Expand All @@ -68,9 +68,9 @@ final class NonModularServiceGenerator implements Runnable {
public void run() {
TopDownIndex topDownIndex = TopDownIndex.of(model);

// Generate the client and extend from the modular client.
// Generate the client and extend from the bare-bones client.
writer.writeShapeDocs(service);
writer.openBlock("export class $L extends $T {", "}", nonModularName, serviceSymbol, () -> {
writer.openBlock("export class $L extends $T {", "}", aggregateClientName, serviceSymbol, () -> {
Set<OperationShape> containedOperations = new TreeSet<>(topDownIndex.getContainedOperations(service));
for (OperationShape operation : containedOperations) {
Symbol operationSymbol = symbolProvider.toSymbol(operation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
import software.amazon.smithy.utils.SmithyInternalApi;

/**
* Generates a service client and configuration using plugins.
* Generates a bare-bones client and configuration for service using plugins.
*/
@SmithyInternalApi
final class ServiceGenerator implements Runnable {
final class ServiceBareBonesClientGenerator implements Runnable {

static final String CLIENT_CONFIG_SECTION = "client_config";
static final String CLIENT_PROPERTIES_SECTION = "client_properties";
Expand All @@ -59,7 +59,7 @@ final class ServiceGenerator implements Runnable {
private final List<RuntimeClientPlugin> runtimePlugins;
private final ApplicationProtocol applicationProtocol;

ServiceGenerator(
ServiceBareBonesClientGenerator(
TypeScriptSettings settings,
Model model,
SymbolProvider symbolProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;

public class ServiceGeneratorTest {
public class ServiceBareBonesClientGeneratorTest {
@Test
public void hasHooksForService() {
// TODO
Expand Down Expand Up @@ -44,7 +44,7 @@ public void addConfigInterfaceFields(
}
});

new ServiceGenerator(settings, model, symbolProvider, writer, integrations,
new ServiceBareBonesClientGenerator(settings, model, symbolProvider, writer, integrations,
Collections.emptyList(), applicationProtocol).run();

assertThat(writer.toString(), containsString(" /**\n"
Expand Down