@anzaui/engine - v0.6.0
    Preparing search index...

    Class Stream

    A pushed fragment: identical to Fragment, named for SSE and WebSocket use. Encode the result with formatEvent (SSE) or formatPacket (WebSocket).

    Server-Sent Events and WebSockets carry the same envelope JSON as a fragment fetch. The engine provides the encoders; the transport and the loop that pushes updates are your server's. The Anza browser library has no built-in listener: use EventSource / WebSocket and apply envelope.html to the target yourself.

    import * as http from 'node:http';
    import { Setup, Stream, formatEvent } from '@anzaui/engine';

    const engine = await new Setup({ root: './templates' }).run();

    http.createServer((req, res) => {
    if (req.url !== '/feed/stream') return void res.writeHead(404).end();
    res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', Connection: 'keep-alive' });
    const timer = setInterval(async () => {
    const envelope = await new Stream('feed/card.html', 'feed', { title: 'Live Event' }).run(engine);
    res.write(formatEvent(envelope));
    }, 2000);
    req.on('close', () => clearInterval(timer));
    }).listen(3000);
    Index
    • Parameters

      • template: string

        Template name relative to the root.

      • slot: string

        The target name written into the envelope.

      • Optionalparams: Params

        Values for the template placeholders.

      Returns Stream

    params?: Params

    Values for the template placeholders.

    slot: string

    The target name written into the envelope.

    template: string

    Template name relative to the root.

    • Validate and render the envelope.

      Parameters

      Returns Promise<Envelope>

      The (signed, when signing is on) envelope.

      AnzaError VALIDATION for an empty or malformed name or slot; NOT_FOUND for an unknown template or one outside the allowlist.