Skip to content

feat(codegen): experimental SSE (text/event-stream) event stream protocol#2177

Draft
goelakash wants to merge 2 commits into
smithy-lang:mainfrom
goelakash:sse-protocol
Draft

feat(codegen): experimental SSE (text/event-stream) event stream protocol#2177
goelakash wants to merge 2 commits into
smithy-lang:mainfrom
goelakash:sse-protocol

Conversation

@goelakash

Copy link
Copy Markdown

Implements the proposal in #2176: lets a Smithy model generate a server whose event streams are framed as Server-Sent Events (text/event-stream) instead of the binary vnd.amazon.eventstream encoding.

Opt-in, twice over: everything is gated behind the experimentalSseProtocol smithy-build setting (registered in the CONTRIBUTING experimental-features table), and even then only activates on services carrying the new sseJson trait. With the flag unset — the default — the protocol isn't registered and codegen output is byte-for-byte unchanged; a test asserts this.

What's inside:

  • SseEventStreamMarshaller in @smithy/core/event-streams: same options and callback contract as the binary marshaller, so the two are interchangeable. Maps :event-type to the SSE event: field, body to data: line(s), modeled exceptions to event: exception:<code>. WHATWG-spec line-terminator handling (CR/LF/CRLF), incremental cross-chunk parsing.
  • ProtocolGenerator.getEventStreamSerdeProviderName(): a protocol can now choose which provider the generated handler wires into its serde context (default: binary). This is the seam from fix(codegen): support event streams in server SDK serde context #2175.
  • sseJson trait + SseJsonProtocolGenerator: an HTTP-binding protocol that selects the SSE provider. Scope note: document body serde for non-streaming members is stubbed — this PR is about the event stream framing; full JSON body serde is follow-up work.

Testing: marshaller round-trip/chunk-boundary/CR-CRLF/exception specs; codegen tests generating an SSDK from an @sseJson model asserting the SSE provider wiring; a gate test proving inertness without the flag. Full gradle build passes (checkstyle, spotbugs).

Note: this branch is stacked on #2175 (its first commit) — the serde-context seam it builds on.

Server SDK generation stubbed the event stream serde context type as
`& any` and never supplied an event stream marshaller, so generated
SSDK code for operations with event streams did not type-check.

Type the response serializer / request deserializer context with
__EventStreamSerdeContext, and wire the Node eventStreamSerdeProvider
into the handler's serde context base (it only needs utf8 encode/decode,
which the base already provides).

Adds server event stream codegen tests, which were previously absent.
Adds an experimental sseJson protocol whose event streams are framed as
Server-Sent Events instead of the binary vnd.amazon.eventstream encoding,
so a Smithy model can generate a server that streams over text/event-stream.

- SseEventStreamMarshaller in @smithy/core/event-streams: an
  EventStreamMarshaller that frames messages as SSE, with the same options
  and callback contract as the binary marshaller.
- ProtocolGenerator.getEventStreamSerdeProviderName lets a protocol choose
  which provider the generated handler wires into its serde context;
  defaults to the binary provider.
- SseJsonProtocolGenerator + sseJson trait: an HTTP protocol that overrides
  the provider to emit the SSE marshaller. Document body serde for
  non-streaming members is not yet implemented.

Gated behind the experimentalSseProtocol smithy-build setting; when unset,
the protocol is not registered and codegen output is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant