realtime/sse_constants.ts

Hono-free SSE wire constants, and the keep-alive interval's check.

Split from sse.ts (which pulls hono/streaming via streamSSE) so the stream-framing constants are importable by cross-process test suites asserting on the wire without dragging in the in-process Hono SSE implementation.

view source

Declarations
#

6 declarations

SSE_CONNECTED_COMMENT
#

realtime/sse_constants.ts view source

": connected\n\n" import {SSE_CONNECTED_COMMENT} from '@fuzdev/fuz_app/realtime/sse_constants.js';

The comment line written immediately on SSE stream open. Flushes headers + confirms the connection is live before the first real event. Cross-process SSE tests assert the stream emits this on connect.

SSE_KEEP_ALIVE_COMMENT
#

realtime/sse_constants.ts view source

": keepalive\n\n" import {SSE_KEEP_ALIVE_COMMENT} from '@fuzdev/fuz_app/realtime/sse_constants.js';

The comment line an idle SSE stream writes every SSE_KEEP_ALIVE_INTERVAL_MS, so a proxy that cuts a connection idle past its read timeout (nginx's default is 60 s) keeps an open stream open. EventSource ignores comments.

SSE_KEEP_ALIVE_INTERVAL_MS
#

realtime/sse_constants.ts view source

15000 import {SSE_KEEP_ALIVE_INTERVAL_MS} from '@fuzdev/fuz_app/realtime/sse_constants.js';

How often an SSE stream writes SSE_KEEP_ALIVE_COMMENT — 15 s, a quarter of nginx's default 60 s read timeout. Per stream, from its open, whether or not data frames were written in between.

SSE_KEEP_ALIVE_INTERVAL_MS_MAX
#

realtime/sse_constants.ts view source

2147483647 import {SSE_KEEP_ALIVE_INTERVAL_MS_MAX} from '@fuzdev/fuz_app/realtime/sse_constants.js';

The longest keep-alive interval a timer honors — 2³¹ − 1 ms, about 24.8 days.

SSE_OUTBOUND_QUEUE_BYTES
#

realtime/sse_constants.ts view source

number import {SSE_OUTBOUND_QUEUE_BYTES} from '@fuzdev/fuz_app/realtime/sse_constants.js';

The byte budget of what one SSE stream holds for its client to read (realtime/sse.ts module doc, "Outbound bound").

1 MiB — equal to the default cap on one request body (DEFAULT_BODY_LIMIT_BYTES). An audit row is bounded by the request that produced it, so on a server that keeps that default the budget holds a burst of ordinary rows or one at the largest. The value is fixed and does not follow the server's body limit. Same value as the Rust spine's SSE_OUTBOUND_QUEUE_BYTES.

validate_sse_keep_alive_ms
#

realtime/sse_constants.ts view source

(keep_alive_ms: number | null | undefined): void import {validate_sse_keep_alive_ms} from '@fuzdev/fuz_app/realtime/sse_constants.js';

Throw unless keep_alive_ms is a valid keep-alive interval (SseResponseOptions.keep_alive_ms): undefined (the default), null (off), or a positive number of ms up to SSE_KEEP_ALIVE_INTERVAL_MS_MAX. Timers read anything else — zero, a negative, NaN, Infinity, or past the max — as an interval of about 1 ms, which would write keep-alives as fast as the event loop turns.

keep_alive_ms

the interval to check

type number | null | undefined

returns

void

throws

  • Error - when it is a number outside `(0, SSE_KEEP_ALIVE_INTERVAL_MS_MAX]`

Imported by
#