Skip to content

Commit

Permalink
feat(codegen): add PreCommandClassCodeSection
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Yuan authored and kuhe committed Jul 24, 2024
1 parent d5e0936 commit ef39a96
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import software.amazon.smithy.typescript.codegen.sections.CommandBodyExtraCodeSection;
import software.amazon.smithy.typescript.codegen.sections.CommandConstructorCodeSection;
import software.amazon.smithy.typescript.codegen.sections.CommandPropertiesCodeSection;
import software.amazon.smithy.typescript.codegen.sections.PreCommandClassCodeSection;
import software.amazon.smithy.typescript.codegen.sections.SmithyContextCodeSection;
import software.amazon.smithy.typescript.codegen.validation.SensitiveDataFinder;
import software.amazon.smithy.utils.SmithyInternalApi;
Expand Down Expand Up @@ -154,6 +155,17 @@ private void generateClientCommand() {
);
}

// Section of items like TypeScript @ts-ignore
writer.injectSection(PreCommandClassCodeSection.builder()
.settings(settings)
.model(model)
.service(service)
.operation(operation)
.symbolProvider(symbolProvider)
.runtimeClientPlugins(runtimePlugins)
.protocolGenerator(protocolGenerator)
.applicationProtocol(applicationProtocol)
.build());
writer.openBlock(
"export class $L extends $$Command.classBuilder<$T, $T, $L, ServiceInputTypes, ServiceOutputTypes>()",
".build() {", // class open bracket.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

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

import java.util.List;
import java.util.Optional;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.typescript.codegen.ApplicationProtocol;
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
import software.amazon.smithy.typescript.codegen.integration.ProtocolGenerator;
import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin;
import software.amazon.smithy.utils.CodeSection;
import software.amazon.smithy.utils.SmithyBuilder;
import software.amazon.smithy.utils.SmithyUnstableApi;

@SmithyUnstableApi
public final class PreCommandClassCodeSection implements CodeSection {
private final TypeScriptSettings settings;
private final Model model;
private final ServiceShape service;
private final OperationShape operation;
private final SymbolProvider symbolProvider;
private final List<RuntimeClientPlugin> runtimeClientPlugins;
private final ProtocolGenerator protocolGenerator;
private final ApplicationProtocol applicationProtocol;

private PreCommandClassCodeSection(Builder builder) {
settings = SmithyBuilder.requiredState("settings", builder.settings);
model = SmithyBuilder.requiredState("model", builder.model);
service = SmithyBuilder.requiredState("service", builder.service);
operation = SmithyBuilder.requiredState("operation", builder.operation);
symbolProvider = SmithyBuilder.requiredState("symbolProvider", builder.symbolProvider);
runtimeClientPlugins = SmithyBuilder.requiredState("runtimeClientPlugins", builder.runtimeClientPlugins);
protocolGenerator = builder.protocolGenerator;
applicationProtocol = SmithyBuilder.requiredState("applicationProtocol", builder.applicationProtocol);
}

public static Builder builder() {
return new Builder();
}

public TypeScriptSettings getSettings() {
return settings;
}

public Model getModel() {
return model;
}

public ServiceShape getService() {
return service;
}

public OperationShape getOperation() {
return operation;
}

public SymbolProvider getSymbolProvider() {
return symbolProvider;
}

public List<RuntimeClientPlugin> getRuntimeClientPlugins() {
return runtimeClientPlugins;
}

public Optional<ProtocolGenerator> getProtocolGenerator() {
return Optional.ofNullable(protocolGenerator);
}

public ApplicationProtocol getApplicationProtocol() {
return applicationProtocol;
}

public static class Builder implements SmithyBuilder<PreCommandClassCodeSection> {
private TypeScriptSettings settings;
private Model model;
private ServiceShape service;
private OperationShape operation;
private SymbolProvider symbolProvider;
private List<RuntimeClientPlugin> runtimeClientPlugins;
private ProtocolGenerator protocolGenerator;
private ApplicationProtocol applicationProtocol;

@Override
public PreCommandClassCodeSection build() {
return new PreCommandClassCodeSection(this);
}

public Builder settings(TypeScriptSettings settings) {
this.settings = settings;
return this;
}

public Builder model(Model model) {
this.model = model;
return this;
}

public Builder service(ServiceShape service) {
this.service = service;
return this;
}

public Builder operation(OperationShape operation) {
this.operation = operation;
return this;
}

public Builder symbolProvider(SymbolProvider symbolProvider) {
this.symbolProvider = symbolProvider;
return this;
}

public Builder runtimeClientPlugins(List<RuntimeClientPlugin> runtimeClientPlugins) {
this.runtimeClientPlugins = runtimeClientPlugins;
return this;
}

public Builder protocolGenerator(ProtocolGenerator protocolGenerator) {
this.protocolGenerator = protocolGenerator;
return this;
}

public Builder applicationProtocol(ApplicationProtocol applicationProtocol) {
this.applicationProtocol = applicationProtocol;
return this;
}
}
}

0 comments on commit ef39a96

Please sign in to comment.