Skip to content
@drupflare/spool v1.0.0 GitHub
    Preparing search index...

    Type Alias SpoolOptions

    what createSpool takes

    type SpoolOptions = {
        assets?: AssetMode;
        beacons?: readonly string[];
        bootstrap?: BootstrapGate;
        bundle?: { blockRows?: number; maxBytes?: number; ringBytes?: number };
        bundles?: BundleStore;
        catalogueBytes?: number;
        catalogueConfidence?: number;
        catalogueSize?: Sizer;
        cdn?: {
            integrity: string;
            url?: string;
            worker?: boolean | { url: string };
        };
        clientTag?: "inline"
        | "script";
        collectors?: readonly CollectorConfig[];
        datasets?: readonly Dataset[];
        freshness?: { maxAge?: number };
        identity?: IdentityOptions;
        inlineMaxBytes?: number;
        live?: boolean | "always" | LiveOptions;
        logout?: readonly string[];
        meter?: () => number;
        mode?: Mode;
        policy?: Record<string, string>;
        principalDatasets?: boolean;
        provision?: ProvisionConfig;
        resources?: readonly Resource[];
        routes: readonly Route[];
        shadowSample?: number;
        sink?: Sink;
        stamp?: number | (() => number);
        store: VersionStore;
        thirdParty?: ThirdPartyConfig;
        views?: boolean;
        work?: WorkSeries;
        worker?: string;
        workerMode?: WorkerMode;
        writes?: {
            classes: readonly Write[];
            enabled?: boolean;
            remember?: number;
        };
    }
    Index
    assets?: AssetMode

    how the worker treats same-origin subresources; default cache

    beacons?: readonly string[]

    same-origin POST paths the worker queues and flushes in one request

    bootstrap?: BootstrapGate

    When the device fetches the pack: second-view on the second view, the default, or first-view. The ring in the first document is the same either way.

    bundle?: { blockRows?: number; maxBytes?: number; ringBytes?: number }

    Options for the packs publish builds. ringBytes is the budget of the ring on each family page, default 24,576 and not measured. blockRows is rows per block, default 128. maxBytes is the most compressed bytes of one block, at most the reader's frame cap.

    bundles?: BundleStore

    where buildBundle keeps packs; GET /.spool/bundle/<version> answers 404 without it

    catalogueBytes?: number

    the most compressed bytes of entries one catalogue bundle may carry; default 32 KiB

    catalogueConfidence?: number

    How cautious the catalogue is about a share it estimated: a guess with n observations is judged on the lower confidence bound of its p at this many standard deviations (1.28 is one-sided 90%). A guess with no n keeps its p. Default 0, which judges every guess on p.

    catalogueSize?: Sizer

    measures an entry's compressed bytes for the catalogue; default Brotli, gzip where the runtime has no Brotli stream

    cdn?: { integrity: string; url?: string; worker?: boolean | { url: string } }

    serve the page runtime from a CDN with SRI; omitted, it is served from /.spool/<version>/client.js. url defaults to this version's cdn.drupflare.com build, whose integrity is in the release notes and in dist/cdn/manifest.json.

    worker also moves the worker core to the CDN: the stub becomes the config and one importScripts line, a few KB in place of the core, and the core is fetched from worker.url, or from this version's cdn.drupflare.com build when worker is true. A browser has no integrity check for an imported script, so the site trusts the CDN host with a script that can answer every request of the origin. Off by default. A site with a custom worker bundle must give worker.url. publishStatic checks the served bytes with verifyCore.

    clientTag?: "inline" | "script"

    How a second-view page loads the runtime. inline (default) puts a small gate in place of the script tag. The gate waits for the first click or GET form submit that the held pages answer, then loads one script that carries the runtime and the pack, in place of the document that click would have fetched, so a visitor never makes more requests than the site without spool. A page with no ring, or whose ring names no boot script (cdn is set), loads the runtime from the second view. script keeps the tag, for a page whose CSP forbids inline scripts. A first-view site always uses the tag.

    collectors?: readonly CollectorConfig[]

    cross-origin analytics collectors the worker holds and delivers later

    datasets?: readonly Dataset[]

    public datasets /.spool/dataset answers, each by its own name

    freshness?: { maxAge?: number }

    maxAge, in seconds, is the lease of /spool-sw.js in the browser's cache; default one day. A check inside it costs nothing, and after it one request brings the version and its changes. A floor applies on top of the lease: Chromium checked the stub on the first document navigation after each 24 hours whatever maxAge was (measured in Chromium only, with the wall clock shifted), so a lease longer than a day does not cut the checks. A stub that changed at that check installs, which is the contact.

    identity?: IdentityOptions
    inlineMaxBytes?: number

    The most bytes of escaped artifact JSON a public template page carries in the page itself, so the worker stores it from the navigation and asks no /.spool/artifact. Every network view of such a page pays for the bytes and one more load, whether or not the visitor has a worker; a larger artifact is left out. Default 0, which is off; 2048 is the limit measured.

    live?: boolean | "always" | LiveOptions

    The stream a visible page holds open at /.spool/live, for the principal lease and its revocation and, with public, for pushed tag changes. A page with a principal partition and a stream sends no renewal while it reads, and a revoked session reaches it in milliseconds. false is off; true and an object are on; absent, it is on when identity is set on a host that is one process (Node, Bun, Deno) and off on Workers, where the stream needs a hub every isolate can reach: pass durableObjectHub from @drupflare/spool/stores/durable-object. A page without the stream renews at its route's bound as before. The default is off for public freshness. By default the policy is adaptive: the first lease renewal of a visible session is an ordinary request and the second becomes the stream, so a visitor who loads documents never opens one. 'always' (or { mode: 'always' }) opens at login and whenever a tab becomes visible, for an app that stays open.

    logout?: readonly string[]

    same-origin paths whose request ends the session; the worker wipes the principal store first

    meter?: () => number

    reads a millisecond clock for work; default performance.now, which is elapsed time and not CPU

    mode?: Mode

    the mode for routes that do not name one; default serve. shadow never serves locally

    policy?: Record<string, string>

    Security headers a pack or delta response names for a device that holds no site policy. Names are limited to the policy list. Default: the headers of the last HTML page this server answered. {} names no headers. With neither, publishStatic writes a stub with no policy field.

    principalDatasets?: boolean

    Lets datasets hold principal ones, whose rows differ per signed-in principal and which the device keeps sealed in that principal's partition. Off by default: a principal dataset then throws bad-dataset. Needs identity. Unreviewed.

    provision?: ProvisionConfig

    priors the worker uses before its own telemetry exists, and the server uses to leave out an artifact whose transfer its expected reuse does not repay

    resources?: readonly Resource[]

    Resources from defineResource: their item families join routes, and their writes are sent to the server and answered with the rows they changed as Spool-Delta. Needs bundles for the device to keep its pack current; the writes themselves work without it.

    routes: readonly Route[]
    shadowSample?: number

    the share of views, 0 to 1, that run in shadow while the mode is serve; default 0

    sink?: Sink
    stamp?: number | (() => number)

    A counter the stub carries, a non-negative integer or a function that returns one, read on each stub request. The stub's bytes change when it does, so advance it at each publish or each lease period. Absent, the stub's bytes are the same as before the option existed.

    thirdParty?: ThirdPartyConfig

    the opt-in worker cache for versioned cross-origin files

    views?: boolean

    whether the worker queues a spool.view per page view; default true with a sink, false without one

    work?: WorkSeries

    records the time each request took, by route; read it with work.samples()

    worker?: string

    a bundled worker to serve in place of the embedded one, such as a bundle of serve(config, renderers) from @drupflare/spool/sw; it finds the config in self.__SPOOL_CONFIG__

    workerMode?: WorkerMode

    never keeps every read in the page: the ring names no worker and the page registers none. auto (default) registers the worker, except on WebKit for a page that carries a ring: WebKit checks the worker script on each navigation (WebKit bug 332455), so those pages keep every read in the page. always registers the worker on WebKit too.

    writes?: { classes: readonly Write[]; enabled?: boolean; remember?: number }

    Declared last-value writes for principal routes, from defineWrite. Off unless enabled is true: the worker then queues nothing and /.spool/write answers writes-off. Needs identity. Unreviewed.