feat(core/eventStreams): add event stream mixin for HttpProtocols, schema-serde#1671
feat(core/eventStreams): add event stream mixin for HttpProtocols, schema-serde#1671kuhe merged 5 commits intosmithy-lang:mainfrom
Conversation
3b27193 to
7eaf5a4
Compare
f6bfd66 to
c3ba2c3
Compare
What is an event stream?This information is available in the Smithy spec: https://smithy.io/2.0/spec/streaming.html. An event stream is an input or output As seen in the PR diff, an event stream is an (http2 or other) message that is made up of headers and a body. There are always at least a few default headers like Here is a small illustration of the relationship among the 3 critical components: the Smithy model, the user input, and the message serialization. ModelSmithy pseudo-code: struct MyOperationInput {
eventStream: EventStream
}
union EventStream {
MemberA: { A: string }
MemberB: { B: blob }
MemberWithPayload: {
@eventPayload
C: blob
}
MemberWithHeaders: {
@eventHeader
H: string
}
}User Inputclient.myOperation({
eventStream: {
async *[Symbol.asyncIterator]() {
yield { A: "hi" };
yield { B: new Uint8Array([0,1,2,3]) };
yield { C: new Uint8Array([0,1,2,3]) };
yield { H: "headerValue" }
}
}
});Serialization(actual serialization is in bytes, and depends on the wire format) This example uses JSON as the format. Note the distinction between the event type B, an implicit payload which serializes the entire object and uses the document content type of the protocol, and the event type C, an explicit payload which serializes only the payload member of the object and uses a special content type. |
Issue #, if available:
#1600
Description of changes:
PR moves event stream handling of schema-serde to a separate submodule called
@smithy/core/eventStreams. It is asynchronously loaded byHttpProtocolextender classes when the functionality is needed. This should help with chunking in bundlers.Additionally, the initial-request and initial-response message types for RPC protocols are handled by this implementation, whereas they are not handled by the existing model-ignorant codegen approach.
The implementation reuses the
@smithy/eventstream-serde-universalstream and codec functionality, replacing only the part that was code-generated in protocol files, i.e. calls to theclient.config.eventStreamMarshaller.Old code example:
New code example:
(In the PR diff)
context: within a schema-serde Protocol implementation