Skip to content

Commit

Permalink
chore(codegen): make hasEventStreamInput utilities public (#6351)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Aug 2, 2024
1 parent 2acbcdb commit 7bf2e59
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public List<RuntimeClientPlugin> getClientPlugins() {
RuntimeClientPlugin.builder()
.withConventions(AwsDependency.MIDDLEWARE_EVENTSTREAM.dependency,
"EventStream", HAS_MIDDLEWARE)
.operationPredicate(AddEventStreamHandlingDependency::hasEventStreamInput)
.operationPredicate((m, s, o) -> hasEventStreamInput(m, o))
.build()
);
}
Expand Down Expand Up @@ -138,7 +138,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
}
}

private static boolean hasEventStreamInput(Model model, ServiceShape service) {
public static boolean hasEventStreamInput(Model model, ServiceShape service) {
TopDownIndex topDownIndex = TopDownIndex.of(model);
Set<OperationShape> operations = topDownIndex.getContainedOperations(service);
EventStreamIndex eventStreamIndex = EventStreamIndex.of(model);
Expand All @@ -150,8 +150,7 @@ private static boolean hasEventStreamInput(Model model, ServiceShape service) {
return false;
}

private static boolean hasEventStreamInput(Model model, ServiceShape service, OperationShape operation) {
EventStreamIndex eventStreamIndex = EventStreamIndex.of(model);
return eventStreamIndex.getInputInfo(operation).isPresent();
public static boolean hasEventStreamInput(Model model, OperationShape operation) {
return EventStreamIndex.of(model).getInputInfo(operation).isPresent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
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.EventStreamIndex;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.typescript.codegen.LanguageTarget;
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
Expand Down Expand Up @@ -56,7 +54,8 @@ public List<RuntimeClientPlugin> getClientPlugins() {
RuntimeClientPlugin.builder()
.withConventions(AwsDependency.TRANSCRIBE_STREAMING_MIDDLEWARE.dependency,
"TranscribeStreaming", RuntimeClientPlugin.Convention.HAS_MIDDLEWARE)
.operationPredicate((m, s, o) -> isTranscribeStreaming(s) && hasEventStreamInput(m, s, o))
.operationPredicate((m, s, o) -> isTranscribeStreaming(s)
&& AddEventStreamHandlingDependency.hasEventStreamInput(m, o))
.build()
);
}
Expand Down Expand Up @@ -94,11 +93,6 @@ private static boolean isTranscribeStreaming(ServiceShape service) {
String serviceId = service.getTrait(ServiceTrait.class).map(ServiceTrait::getSdkId).orElse("");
return serviceId.equals("Transcribe Streaming");
}

private static boolean hasEventStreamInput(Model model, ServiceShape service, OperationShape operation) {
EventStreamIndex eventStreamIndex = EventStreamIndex.of(model);
return eventStreamIndex.getInputInfo(operation).isPresent();
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import software.amazon.smithy.codegen.core.CodegenException;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.knowledge.EventStreamIndex;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.typescript.codegen.LanguageTarget;
Expand Down Expand Up @@ -62,7 +61,8 @@ public List<RuntimeClientPlugin> getClientPlugins() {
.withConventions(AwsDependency.MIDDLEWARE_WEBSOCKET.dependency,
"WebSocket", RuntimeClientPlugin.Convention.HAS_MIDDLEWARE)
.additionalPluginFunctionParamsSupplier((m, s, o) -> getPluginFunctionParams(m, s, o))
.operationPredicate((m, s, o) -> isWebsocketSupported(s) && hasEventStreamRequest(m, o))
.operationPredicate((m, s, o) -> isWebsocketSupported(s)
&& AddEventStreamHandlingDependency.hasEventStreamInput(m, o))
.build(),
RuntimeClientPlugin.builder()
.withConventions(AwsDependency.MIDDLEWARE_WEBSOCKET.dependency, "WebSocket",
Expand Down Expand Up @@ -132,11 +132,6 @@ private static boolean isWebsocketSupported(ServiceShape service) {
return websocketServices.contains(serviceId);
}

private static boolean hasEventStreamRequest(Model model, OperationShape operation) {
EventStreamIndex eventStreamIndex = EventStreamIndex.of(model);
return eventStreamIndex.getInputInfo(operation).isPresent();
}

private static Map<String, Object> getPluginFunctionParams(
Model model,
ServiceShape service,
Expand Down

0 comments on commit 7bf2e59

Please sign in to comment.