AshUi.Datastar.SSE (ash_ui_datastar v0.1.0)

Copy Markdown View Source

Datastar v1 server-sent event encoder and streaming compression wrapper.

The bytes and defaults follow sdk/datastar-sdk-config-v1.json and the reference generator. gzip is implemented with Erlang :zlib and every event is emitted with a synchronous deflate flush.

Summary

Functions

Finish a finite stream and release compression state.

Encode events as per-event flushed chunks plus the compression trailer.

Datastar SSE response headers. Connection is emitted only for HTTP/1.x.

Negotiate the supported stream encodings (gzip and identity).

Open an SSE response and initialize its negotiated streaming encoder.

Send and flush each event on a Plug chunked response.

Write one event and synchronously flush its compression frame.

Write raw SSE bytes (used for comment heartbeats) with a stream flush.

Types

event()

@type event() :: %AshUi.Datastar.SSE.Event{
  data: term(),
  event_id: term(),
  meta: term(),
  retry: term(),
  type: term()
}

Functions

close_stream(conn, encoder)

Finish a finite stream and release compression state.

compressed_chunks(events, encoding)

Encode events as per-event flushed chunks plus the compression trailer.

encode(events)

@spec encode(event() | [event()]) :: binary()

encode_event(event)

@spec encode_event(event()) :: iodata()

execute_script(script, opts \\ [])

@spec execute_script(iodata(), keyword()) :: event()

headers(protocol \\ :http1)

Datastar SSE response headers. Connection is emitted only for HTTP/1.x.

negotiate(accept_encoding)

Negotiate the supported stream encodings (gzip and identity).

open_stream(conn, opts \\ [])

Open an SSE response and initialize its negotiated streaming encoder.

patch_elements(elements \\ "", opts \\ [])

@spec patch_elements(iodata(), keyword()) :: event()

patch_signals(signals, opts \\ [])

@spec patch_signals(map() | iodata(), keyword()) :: event()

send(type, data_lines, opts \\ [])

@spec send(String.t() | atom(), [String.t()], keyword()) :: event()

send_events(conn, events, opts \\ [])

Send and flush each event on a Plug chunked response.

write_event(conn, encoder, event)

Write one event and synchronously flush its compression frame.

write_raw(conn, encoder, bytes)

Write raw SSE bytes (used for comment heartbeats) with a stream flush.