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

    Type Alias WriteDeclaration

    The declaration defineWrite takes. Every write class is "the last value wins" for one key per principal, applied only when the version the device edited from is still current. There is no class for a comment, a cart, a payment, a counter, an inventory change or an audit record, and kind accepts nothing but last-value.

    type WriteDeclaration = {
        kind?: "last-value";
        maxBytes: number;
        maxDelayMs?: number;
        maxPending: number;
        name: string;
        path: string;
        scope: "principal";
        apply(
            ctx: WriteContext,
            key: string,
            value: unknown,
            expectedVersion: string,
        ): MaybePromise<WriteApplied>;
        key(ctx: WriteContext, request: Request): MaybePromise<string>;
        read(ctx: WriteContext, key: string): MaybePromise<WriteRead>;
    }
    Index
    • Writes value when the key is still at expectedVersion and returns the new version, or returns { conflict } when it has moved. The check and the write must be one atomic step in the site's own storage.

      Parameters

      • ctx: WriteContext
      • key: string
      • value: unknown
      • expectedVersion: string

      Returns MaybePromise<WriteApplied>

    • the key this principal may write for this request; a device naming any other key is refused

      Parameters

      Returns MaybePromise<string>

    kind?: "last-value"

    the compaction; last-value is the only kind there is

    maxBytes: number

    the most bytes of one value's JSON body

    maxDelayMs?: number

    The longest a queued write of this class may wait before the worker flushes it. Unset keeps the flush at the next network moment, an explicit flush or a page hide. Set, the first queued write starts a deadline, and the flush at it sends every queued record: one request per key.

    maxPending: number

    the most queued keys of this class one partition holds on a device

    name: string
    path: string

    the pattern of the principal route this write edits; createSpool refuses a public route

    scope: "principal"

    principal only; a public write is refused