View as Markdown

API reference: @salmonui/data/json

JsonDataSourceOptionsinterface

import type { JsonDataSourceOptions } from '@salmonui/data/json';

Also exported from @salmonui/data.

interface JsonDataSourceOptions {
    readonly url?: string;
    readonly fetch?: FetchLike;
    readonly headers?: Readonly<Record<string, string>> | (() => Readonly<Record<string, string>>);
    readonly batch?: boolean;
    readonly transport?: JsonTransport;
    readonly key: string;
    readonly fields?: readonly string[];
    readonly rowShape?: 'tuple' | 'object';
    readonly fieldOf?: (columnId: ColumnId) => string;
    readonly columnIdOf?: (field: string) => ColumnId;
    readonly paging?: PagingStrategy;
    readonly policy?: RequestPolicy;
    readonly scheduler?: Scheduler;
    readonly optimistic?: boolean;
    readonly versionField?: string;
    readonly capabilities?: Partial<DataSourceCapabilities>;
    readonly onRequest?: (event: RequestEvent) => boolean | void;
    readonly onResponse?: (event: ResponseEvent) => WireResponse | void;
    readonly onError?: (event: RequestErrorEvent) => void;
}
JsonDataSourceOptions members (19)
NameSignatureDescription
urloptionalreadonly url?: string;

Endpoint for the default fetch transport. Ignored when transport is set.

fetchoptionalreadonly fetch?: FetchLike;
headersoptionalreadonly headers?: Readonly<Record<string, string>> | (() => Readonly<Record<string, string>>);
batchoptionalreadonly batch?: boolean;

Multiplex same-tick requests into one { v: 1, batch } POST. Default true.

transportoptionalreadonly transport?: JsonTransport;

Custom transport (GraphQL bridge, WebSocket, in-process handler, ...).

keyreadonly key: string;

Primary key field.

fieldsoptionalreadonly fields?: readonly string[];

Requested field list (select). Required for tuple rows: rows are the decoded tuples in this order. Without it rows are objects.

rowShapeoptionalreadonly rowShape?: 'tuple' | 'object';

Default tuple when fields is set, else object.

fieldOfoptionalreadonly fieldOf?: (columnId: ColumnId) => string;

columnId to server field. Default identity.

columnIdOfoptionalreadonly columnIdOf?: (field: string) => ColumnId;

server field to columnId, for errors and aggregates. Default: inverse of fieldOf over the query, else identity.

pagingoptionalreadonly paging?: PagingStrategy;
policyoptionalreadonly policy?: RequestPolicy;
scheduleroptionalreadonly scheduler?: Scheduler;
optimisticoptionalreadonly optimistic?: boolean;

Default: true for batch and cell writes, false otherwise.

versionFieldoptionalreadonly versionField?: string;

Row field holding the row version (ETag); forwarded as expected version on change/remove.

capabilitiesoptionalreadonly capabilities?: Partial<DataSourceCapabilities>;
onRequestoptionalreadonly onRequest?: (event: RequestEvent) => boolean | void;

Cancelable (return false): the request rejects with RequestCanceledError.

onResponseoptionalreadonly onResponse?: (event: ResponseEvent) => WireResponse | void;

Called with every successful protocol response before the source decodes it. Returning a response object replaces the response for this request (e.g. to rewrite rows or total); any other return value keeps it. Return a new object: the cache keeps the original response and a cache hit runs the hook again.

onErroroptionalreadonly onError?: (event: RequestErrorEvent) => void;