@mantlebee/ts-data
    Preparing search index...

    Interface ILookupSource<TItem, TValue>

    A stateless source of reference items: the departments a combobox searches by name, the department a cell of a grid shows from its id. Each call has its own parameters, its own result and its own signal, nothing is shared between calls, so one instance serves any number of consumers at once (a combobox panel, the fifty cells of a grid page, another combobox on the same entity), where a data source is a cursor with one query and one items.

    An aborted call rejects with the AbortedException of ts-core, the same rejection a superseded read of a data source has, so one isAbortedException handles both.

    Build one with createLookupSource (over a reader) or createInMemoryLookupSource (over a list), or write an object that satisfies the interface for a service with its own endpoints. Decorate it with withBatching and withCache where many consumers resolve the same keys.

    const departments: ILookupSource<Department, number> = createLookupSource(readDepartments, {
    textField: "name",
    valueField: "id",
    });
    const { hasMore, items } = await departments.search("sal", { limit: 20, offset: 0 }, signal);
    const [sales] = await departments.resolve([7]);
    departments.valueOf(sales); // 7
    interface ILookupSource<TItem = Any, TValue = LookupValue> {
        resolve(
            values: List<TValue>,
            signal?: AbortSignal,
        ): Promise<List<TItem>>;
        search(
            query: string,
            page: LookupPage,
            signal?: AbortSignal,
        ): Promise<LookupSearchResult<TItem>>;
        valueOf(item: TItem): TValue;
    }

    Type Parameters

    • TItem = Any

      Type of the items.

    • TValue = LookupValue

      Type of the key of an item, a primitive (see LookupValue).

    Hierarchy (View Summary)

    Index
    • The items whose key is one of values, without the ones the source does not know, in no particular order: index them with valueOf.

      Parameters

      • values: List<TValue>

        Keys to resolve; an empty list resolves to [].

      • Optionalsignal: AbortSignal

        Aborted by the caller when the result is no longer needed.

      Returns Promise<List<TItem>>

      the items found.

    • The items whose text contains query (every item when query is empty), one page at a time.

      Parameters

      • query: string

        Text to look for; "" for every item.

      • page: LookupPage

        Page to return: offset of the first item, a multiple of limit, and limit items.

      • Optionalsignal: AbortSignal

        Aborted by the caller when the result is no longer needed.

      Returns Promise<LookupSearchResult<TItem>>

      the items of the page and whether more may follow.