-
Notifications
You must be signed in to change notification settings - Fork 104
support eventstream traits #110
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
support eventstream traits #110
Conversation
I have tested the codegen with kinesis, transcribe-streaming and s3 select, they all work fine. We are still missing the dependencies for browser, but that work will be done on SDK side |
dfc0930
to
cffb837
Compare
Commit with generated S3 client: AllanZhengYP/aws-sdk-js-v3@1d41801 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass of comments since this needs a rebase.
- It's hard to detect if changes were made in the reformatted code, can the automatic formatting be undone?
- Can you include a sample of the different kinds of generated code in the PR description?
I'll continue on the meatier portion of the code after these adjustments.
TypeScriptDependency.AWS_SDK_TYPES.packageName | ||
); | ||
writer.writeDocs("The function that provides necessary utilities for generating and signing event stream"); | ||
writer.write("eventStreamSerdeProvider?: EventStreamSerdeProvider;"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have a \n
at the end of this line for cleanliness.
} | ||
writer.addImport( | ||
"EventStreamSerdeProvider", | ||
"EventStreamSerdeProvider", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have an alias of __EventStreamSerdeProvider
and adjust the type of the parameter below.
public List<RuntimeClientPlugin> getClientPlugins() { | ||
return ListUtils.of( | ||
RuntimeClientPlugin.builder() | ||
.withConventions( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting: The first param should be in the same line as the open param if it fits, the close paren should be on the same line as the last param.
...typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CodegenUtils.java
Outdated
Show resolved
Hide resolved
/** | ||
* Adds event streams if needed. | ||
*/ | ||
public class EventStreamGenerator implements TypeScriptIntegration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be more clearly named and match the other integrations, AddEventStreamDependency
return false; | ||
} | ||
|
||
public static final boolean operationHasEventStream( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should be private.
The operationHasEventStreamInput
and operationHasEventStreamOutput
can probably also be rolled in to this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I marked operationHasEventStream
, operationHasEventStreamInput
, and operationHasEventStreamOutput
public because they are referred outside this class/package. I store all the event stream codegen related util functions here in this class.
Where should I put them to if not here?
...java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java
Show resolved
Hide resolved
writer.openBlock("if (streamBody instanceof Uint8Array) {", "}", () -> { | ||
writer.write("return Promise.resolve(streamBody);"); | ||
}); | ||
writer.write("return context.streamCollector(streamBody) || new Uint8Array();"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OR of this statement won't return a Promise
as indicated.
* @param events The union of of events bond to an event stream | ||
* @return A list of all event structure shapes for the event stream that were dispatched to. | ||
*/ | ||
static Set<StructureShape> generateSerializingEvnetUnion( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in name.
* @param shape shape bond to event header | ||
* @return string literal for the event message header type | ||
*/ | ||
public static String getEventHeaderType(Shape shape) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it's only used in one place, which isn't in this class. It can probably be moved there and be made private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can. I store all the event stream related util functions in this class, should I move it to already-too-long protocol binding class?
5002daa
to
380dcb4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's chat code formatting in person after updates.
...typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CodegenUtils.java
Show resolved
Hide resolved
writer.openBlock("const message: __Message = {", "}", () -> { | ||
writer.openBlock("headers: {", "},", () -> { | ||
//fix headers required by event stream | ||
writer.write("\":event-type\": { type: \"string\", value: \"$L\" },", symbol.getName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing \"$L\"
you can do $S
to write the value inside quotes. This applies in multiple places.
return false; | ||
} | ||
|
||
public static final boolean operationHasEventStream( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is only used in this class and can be made private.
return false; | ||
} | ||
|
||
public static final boolean operationHasEventStreamInput( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given how simple this function and its output variant are, and that they're only used in one place in each Java package supplied here, it's probably good to just inline this check in the other locations. This will mean this class doesn't need to have fully publicly exposed methods for now.
* @param shape shape bond to event header | ||
* @return string literal for the event message header type | ||
*/ | ||
public static String getEventHeaderType(Shape shape) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only used in one location not in this class and can be moved there and made private.
if (hasStreamingComponent) { | ||
if (binding.getMember().hasTrait(EventStreamTrait.class)) { | ||
// If payload is a event stream, return it after calling event stream deser function. | ||
writer.write("const data: any = ").indent(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be combined with the openBlock
call in the function call that follows, removing the need to do indent/dedent.
...java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java
Show resolved
Hide resolved
writer.write("__type: $S,", event.getId().getName()); | ||
} | ||
}); | ||
// Parse members from event headers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these chunks of code for handling message headers and bodies be broken down in to other functions like for standard http responses.
writer.openBlock("return {", "};", () -> { | ||
// Dispatch to special event deserialize function | ||
Symbol eventSymbol = symbolProvider.toSymbol(target); | ||
String eventDeserMethodName = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This building process can be condensed quite a bit:
Symbol eventSymbol = symbolProvider.toSymbol(target);
writer.write("$1L: await $2L(output[$1S], context)", name,
ProtocolGenerator.getDeserFunctionName(eventSymbol, protocolName) + "_event");
This kind of clean up can be done in a couple places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this would work because context
is not passed to each union member's deser function.
* @param events The union of of events bond to an event stream | ||
* @return A list of all event structure shapes for the event stream that were dispatched to. | ||
*/ | ||
static Set<StructureShape> generateDeserializingEventUnion( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good that these are package private for now, but do they need to exist on this class since they're only used in the HttpBindingProtocolGenerator
?
968e7c0
to
bf83bd8
Compare
bf83bd8
to
b922d53
Compare
b922d53
to
e9da31a
Compare
//There's only one event payload member | ||
MemberShape payloadMember = payloadMembers.get(0); | ||
readEventPayload(context, payloadMember); | ||
writer.write("contents.$L = data;", payloadMember.getMemberName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should move in to the readEventPayload
method.
// If payload is string, we need to collect body and encode binary to string. | ||
writer.write("const data: any = await collectBodyString(output.body, context);"); | ||
} else { | ||
throw new CodegenException(String.format("Unexpected shape type bound to payload: `%s`", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be "to event payload" for clarity?
...java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java
Show resolved
Hide resolved
bcfdcb6
to
3eed021
Compare
* feat: add event stream serde dependencies([aws#824](aws#824)) * support eventstream traits([smithy-typescript#110](smithy-lang/smithy-typescript#110))
* feat: add event stream serde dependencies([#824](#824)) * support eventstream traits([smithy-typescript#110](smithy-lang/smithy-typescript#110))
* feat: add event stream serde dependencies([aws#824](aws#824)) * support eventstream traits([smithy-typescript#110](smithy-lang/smithy-typescript#110))
* feat: add event stream serde dependencies([aws#824](aws#824)) * support eventstream traits([smithy-typescript#110](smithy-lang/smithy-typescript#110))
* feat: add event stream serde dependencies([aws#824](aws#824)) * support eventstream traits([smithy-typescript#110](smithy-lang/smithy-typescript#110))
* feat: add event stream serde dependencies([aws#824](aws#824)) * support eventstream traits([smithy-typescript#110](smithy-lang/smithy-typescript#110))
This change adds codegen support for eventstream serde. If a member has event stream trait, it will generate specitial event serde functions on top of original ones: * add eventstream serde generator * generate special serde for events and event unions * complete event deserializer and event union deserializer * Add event stream and events unions serializer * formatting code and add necessary docs * add eventstream-serde-browser dependency * address PR feedbacks * use normal error deserializer to deserialize error event in event stream
* Clear up bootstrap warnings * Update type generator to handle zero-length union types * Clear up compiler errors surrounding middlewarestack at later steps * Regenerate SDK packages
* Clear up bootstrap warnings * Update type generator to handle zero-length union types * Clear up compiler errors surrounding middlewarestack at later steps * Regenerate SDK packages
This change adds codegen support for eventstream serde. If a member has event stream trait, it will generate specitial event serde functions on top of original ones. Specifically: