Skip to content

Commit

Permalink
Add eventStream smithy context (#1111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Yuan authored Dec 13, 2023
1 parent 3864faa commit 7748297
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
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.TypeScriptCodegenContext;
import software.amazon.smithy.typescript.codegen.TypeScriptDependency;
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
import software.amazon.smithy.typescript.codegen.sections.SmithyContextCodeSection;
import software.amazon.smithy.utils.CodeInterceptor;
import software.amazon.smithy.utils.CodeSection;
import software.amazon.smithy.utils.ListUtils;
import software.amazon.smithy.utils.MapUtils;
import software.amazon.smithy.utils.SmithyInternalApi;
Expand Down Expand Up @@ -99,6 +103,31 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
}
}

@Override
public List<? extends CodeInterceptor<? extends CodeSection, TypeScriptWriter>> interceptors(
TypeScriptCodegenContext codegenContext
) {
return List.of(CodeInterceptor.appender(SmithyContextCodeSection.class, (w, s) -> {
EventStreamIndex eventStreamIndex = EventStreamIndex.of(s.getModel());
boolean input = eventStreamIndex.getInputInfo(s.getOperation()).isPresent();
boolean output = eventStreamIndex.getOutputInfo(s.getOperation()).isPresent();
// If not event streaming for I/O, don't write anything
if (!input && !output) {
return;
}
// Otherwise, write present input and output streaming
w.writeDocs("@internal");
w.openBlock("eventStream: {", "},", () -> {
if (input) {
w.write("input: true,");
}
if (output) {
w.write("output: true,");
}
});
}));
}

private static boolean hasEventStream(
Model model,
ServiceShape service
Expand Down

0 comments on commit 7748297

Please sign in to comment.