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

    Type Alias Spool

    what createSpool returns

    type Spool = {
        config: SwConfig;
        decorate(
            request: Request,
            response: Response,
            options?: DecorateOptions,
        ): Promise<Response>;
        handle(
            request: Request,
            next: (request: Request) => Response | Promise<Response>,
        ): Promise<Response>;
        invalidate(
            tags: readonly string[],
            options?: { drop?: readonly string[] },
        ): Promise<number>;
        partition(principal: string): Promise<string>;
        publish(url: URL): Promise<{ bytes: number; version: number }>;
        publishStatic(
            sink: StaticSink,
            options?: PublishStaticOptions,
        ): Promise<PublishStaticResult>;
        respond(request: Request): Promise<Response | undefined>;
        revoke(principal: string): Promise<void>;
        stub(): Response;
        stub(request: Request): Promise<Response>;
    }
    Index
    • adds the envelope headers and the client tag to a response the app produced. A public route's response that sets a cookie, is private or no-store, or varies by anything but encoding and cookies is returned unchanged.

      Parameters

      Returns Promise<Response>

    • answers /.spool/* and the worker script, otherwise calls next and decorates

      Parameters

      • request: Request
      • next: (request: Request) => Response | Promise<Response>

      Returns Promise<Response>

    • bumps the vector after a write; drop also removes artifacts by id

      Parameters

      • tags: readonly string[]
      • Optionaloptions: { drop?: readonly string[] }

      Returns Promise<number>

    • The Spool-Partition value for a principal. A login or account-switch handler sets it on its own response, since the request it answers still carries the old identity: the worker then swaps its store before any local view can read the old one.

      Parameters

      • principal: string

      Returns Promise<string>

    • Builds the pack at the store cursor and keeps it in bundles. Returns { version, bytes }. A version already holding other bytes is refused, so call invalidate after a data change. url is what the seed functions receive.

      Parameters

      • url: URL

      Returns Promise<{ bytes: number; version: number }>

    • Writes the static tier to sink: the page runtime, the stub, the packs held for the store cursor and the deltas to it, and a _headers file. A host that serves these files answers them with no Worker invocation. Packs and runtime are immutable, so a sink that reports them with has keeps the ones already there. Build the packs with publish first. Each pack also gets its boot script, unless cdn is set. The stub names the site policy in this order: options.policy, the policy option of createSpool, the headers of the last HTML page answered, options.fallbackPolicy. With none of them the stub carries no policy field, and a device renders locally after one network view that teaches it the headers; policy: 'none' in the result says so. {} names a known-empty policy. options.url builds the pack at the cursor first. Returns the store cursor, the paths written and the policy source.

      Parameters

      Returns Promise<PublishStaticResult>

    • a Response for /.spool/*, undefined for anything else

      Parameters

      • request: Request

      Returns Promise<Response | undefined>

    • Ends the live streams of a principal's partition: each gets revoked and closes, and the page wipes the partition. Call it where the app ends a session on the server (a ban, a logout on another device, a sweep of expired sessions). It does nothing while live is off.

      Parameters

      • principal: string

      Returns Promise<void>

    • The /spool-sw.js response. Pass the request to get an ETag and a 304 for a matching If-None-Match, so a re-check of an unchanged script after the lease costs a few hundred bytes. With no request the response has no validator, as before.

      Returns Response

    • Parameters

      • request: Request

      Returns Promise<Response>

    config: SwConfig

    the config embedded in the worker script