parseSseStream
function parseSseStream(body, hooks?): AsyncGenerator<string>;Defined in: core/src/transport.ts:223
Yield each data: payload of an SSE body, trimmed, plus the bare JSON
object a vendor appends outside the framing, which is only ever an error
(see payloadOf).
Frames are split on the blank line the spec requires, so a payload containing
a bare newline survives. [DONE] is swallowed here rather than in every
adapter, reported through hooks.onDone, and ends the stream: it is the
body’s last word, and a read after it can only fail a finished turn. CRLF and
bare CR are normalized: some gateways send them, and a \r left on the end
of a JSON payload is a parse error nobody enjoys debugging.
Exported apart from streamSse because the envelope above it is the half an
adopting app most often cannot take: an app with its own translated error
copy, its own log levels, or its own auth refresh has to keep building the
request and reading the failure itself. Framing is the half nobody should
write twice. Hand it a res.body and keep your own envelope.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
body |
ReadableStream<Uint8Array<ArrayBufferLike>> |
hooks |
SseHooks |
Returns
Section titled “Returns”AsyncGenerator<string>