sveltekit-eventsource - v1.0.0
    Preparing search index...

    sveltekit-eventsource - v1.0.0

    @sourceregistry/sveltekit-eventsource

    npm version License CI Codecov

    Typed Server-Sent Events (SSE) for SvelteKit with first-class TypeScript support, strongly typed client–server communication, and a versioned control protocol.


    This library provides a structured, production-ready abstraction over native Server-Sent Events (SSE) for SvelteKit applications.

    It focuses on:

    • Type safety via App.Events
    • Protocol-level control messages
    • Clean separation between application payloads and transport mechanics
    • Predictable lifecycle management

    • 📦 Install the package
    • 🖥 Set up a server-side SSE endpoint
    • 🌐 Subscribe from the client with typed events

    See:

    • module:client.EventSource | Client API
    • module:server.EventSource | Server API

    All application events are defined once using:

    declare global {
    namespace App {
    interface Events {
    status: {
    heartbeat: number;
    };
    }
    }
    }

    This definition drives both:

    • server-side emit() typing
    • client-side on() typing

    This library implements a protocol-level control channel for SSE, known as:

    SSE Magic Control Protocol (SMCP)

    SMCP guarantees that critical control messages (such as server-requested close) remain decodable even if custom serializers/deserializers are used.

    📄 Protocol specification: ➡️ {@page sse-magic-protocol}


    • {@link module:client | Client Module}
    • {@link module:server | Server Module}

    Each module is fully documented using TSDoc.


    • Protocol version: v1
    • Stability: Experimental (0.x)
    • Node.js: >= 16
    • Svelte: >= 5

    Apache-2.0 © ProjectSource V.O.F.