Skip to main content
Version: v10.0.0

LoaderOptions


Import
import { LoaderOptions } from "@hyper-fetch/db"

Preview​

type LoaderOptions<Row,Key,Req,Mapped,Where,Order,Cursor,Limit,ByKey,ByKeys,LoaderNotation> = {
byKey?: ByKey & (key: Key) => RequestPatch<Req>;
byKeys?: ByKeys & (keys: Key[]) => RequestPatch<Req>;
cursor?: (response: ExtractResponseType<Req>) => Cursor | null | undefined;
fixed?: Partial<Row>;
limit?: Limit & (limit: number) => RequestPatch<Req>;
notation?: LoaderNotation & Notation;
orderBy?: Order & OrderDeclaration<Row, Req>;
page?: (cursor: Cursor) => RequestPatch<Req>;
rows?: (response: ExtractResponseType<Req>) => readonly Mapped[];
serverOnly?: readonly (keyof Row & string)[];
where?: Where & WhereDeclaration<Row, Req>;
}

Structure​

LoaderOptions
NameTypeDescription
byKey
ByKey & (key: Key) => RequestPatch<Req>

Reads one row by key. A loader with it serves findOne .

byKeys
ByKeys & (keys: Key[]) => RequestPatch<Req>

Reads several rows by key in one request. A loader with it serves findOne , batched.

fixed
Partial<Row>

Conditions the endpoint applies on its own, such as { archived: false }

limit
Limit & (limit: number) => RequestPatch<Req>

Sends a query's limit. Declaring it makes the loader paginated.

notation
LoaderNotation & Notation

How the backend writes every operator and order, so the loader sends conditions on any field

orderBy
Order & OrderDeclaration<Row, Req>

The fields the endpoint can sort by

serverOnly
readonly (keyof Row & string)[]

Fields the backend compares differently from the client, so queries on them are never answered locally

where
Where & WhereDeclaration<Row, Req>

The operators the endpoint can serve for each field

cursor
(response: ExtractResponseType<Req>) => Cursor | null | undefined

Reads the next page's cursor from a response. Declaring it makes the loader paginated.

page
(cursor: Cursor) => RequestPatch<Req>

Sends a cursor to load the page after it

rows
(response: ExtractResponseType<Req>) => readonly Mapped[]

Reads complete rows from a response, for example from a wrapped list such as { data: { items }, meta } or by reshaping each item. Without it, the response is the list of rows, or the row.