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

    Type Alias DatasetDeclaration<Row>

    the declaration defineDataset takes

    type DatasetDeclaration<Row extends DatasetRow = DatasetRow> = {
        maxBytes: number;
        maxRows: number;
        maxStaleMs?: number;
        provision?: "always" | "auto";
        schema: string;
        scope: "public" | "principal";
        changes(
            since: number,
            ctx: DatasetContext,
        ): MaybePromise<DatasetChanges | "reset">;
        fields?(viewer: Identity | null, row: Row): readonly string[];
        head(ctx: DatasetContext): MaybePromise<DatasetHead>;
        horizon(ctx: DatasetContext): MaybePromise<number>;
        key(row: Row): string;
        read(
            ids: readonly string[],
            ctx: DatasetContext,
        ): MaybePromise<readonly Row[]>;
        seed(
            ctx: DatasetSeedContext,
        ): MaybePromise<
            | readonly Row[]
            | Iterable<readonly Row[], any, any>
            | AsyncIterable<readonly Row[], any, any>,
        >;
    }

    Type Parameters

    Index
    • Principal datasets only: the field names of row that viewer may hold, from null for an anonymous request. The server sends each viewer only those fields, so the device never holds the others. Absent, every field goes to every viewer.

      Parameters

      Returns readonly string[]

    • a keyed read: the rows for these keys, omitting any that no longer exist; never a full load

      Parameters

      Returns MaybePromise<readonly Row[]>

    • Every row in ascending key order (code unit order), as an array or as pages of rows. With ctx.after set it may start after that key. It runs once to admit a seed and once per page.

      Parameters

      Returns MaybePromise<
          | readonly Row[]
          | Iterable<readonly Row[], any, any>
          | AsyncIterable<readonly Row[], any, any>,
      >

    maxBytes: number

    most bytes of row JSON a seed may hold

    maxRows: number

    most rows a seed may hold

    maxStaleMs?: number

    Principal datasets only, and required there: how long held rows may answer a query after the last sync that returned and verified. Past it the query goes to the network. It is also the longest a device keeps serving rows after the server stopped admitting its principal.

    provision?: "always" | "auto"

    always (the default) answers every seed. auto answers a seed only while datasetBenefit says the dataset beats both v0.3 and native HTTP; otherwise the seed is refused with 409.

    schema: string

    a version string for the row shape; a device holding another one reseeds

    scope: "public" | "principal"

    public rows are the same for everyone. A principal dataset holds rows that differ per signed-in principal; it needs maxStaleMs, defineDataset's principalDatasets option and createSpool's principalDatasets flag. Unreviewed.