# `AshUi.Datastar.SSE`
[🔗](https://github.com/hyperbob-labs/ash_ui/blob/main/lib/ash_ui/datastar/sse.ex#L1)

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.

# `event`

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

# `close_stream`

Finish a finite stream and release compression state.

# `compressed_chunks`

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

# `encode`

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

# `encode_event`

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

# `execute_script`

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

# `headers`

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

# `negotiate`

Negotiate the supported stream encodings (gzip and identity).

# `open_stream`

Open an SSE response and initialize its negotiated streaming encoder.

# `patch_elements`

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

# `patch_signals`

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

# `send`

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

# `send_events`

Send and flush each event on a Plug chunked response.

# `write_event`

Write one event and synchronously flush its compression frame.

# `write_raw`

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
