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

    Interface IFilterExtension<TItem>

    Extension that adds a FiltersExpression to the payload. Every mutation raises its own event at once and schedules the debounced filtersChange event (see FilterExtensionEvents).

    interface IFilterExtension<TItem = Any> {
        filters: List<Filter<TItem>>;
        hasFilters: boolean;
        logic: FilterLogics;
        addFilter(filter: Filter<TItem>): void;
        buildPayload?(
            payload: DataSourcePayload<TItem>,
            signal?: AbortSignal,
        ): Promise<DataSourcePayload<TItem>>;
        clearFilters(): void;
        dispose(): Promise<void>;
        on<TKey extends string>(
            event: TKey,
            handler: EventHandler<FilterExtensionEvents<TItem>, TKey>,
        ): IDisposable;
        readItems?(
            payload: DataSourcePayload<TItem>,
            next: DataSourceReadNext<TItem>,
            signal?: AbortSignal,
        ): Promise<List<TItem>>;
        removeFilter(filter: Filter<TItem>): void;
        removeFiltersOf(field: KeyOf<TItem>): void;
        replaceFiltersOf(
            field: KeyOf<TItem>,
            ...filters: List<Filter<TItem>>,
        ): void;
        setFilters(filters: List<Filter<TItem>>): void;
        setLogic(logic: FilterLogics): void;
    }

    Type Parameters

    • TItem = Any

      Type of the items.

    Hierarchy (View Summary)

    Implemented by

    Index
    filters: List<Filter<TItem>>

    Current filters, in insertion order.

    hasFilters: boolean

    true when at least one filter is set.

    Logic combining the filters.

    • Releases the held resource. Implementations should be safe to call more than once.

      Returns Promise<void>

      a promise that settles once the resource has been released.

    • Registers a handler for an event.

      Type Parameters

      • TKey extends string

        Name of the event to listen to.

      Parameters

      Returns IDisposable

      a subscription; dispose it to remove this single handler.

    • Wraps the reading of the items. Read phase: the extension is a layer of the onion around the reader, next the layers inside it (the inner extensions, then the reader of the data source). The payload is the whole query, whatever the position of the extension.

      next may be called zero times (e.g. a cache hit: the reader is never invoked), once, with this or another payload, or several times (e.g. a payload split into several reads whose results are merged); every call runs the inner layers and the reader again, so the hooks and the events of the inner extensions may fire as many times. The result may be transformed before being returned, and flows outward: the outermost extension transforms last.

      Parameters

      • payload: DataSourcePayload<TItem>

        The whole query, built by the build phase.

      • next: DataSourceReadNext<TItem>

        Reads the items through the inner layers and the reader; the signal of the read is bound already.

      • Optionalsignal: AbortSignal

        Signal of the read, aborted when the read is superseded, for the reads of the extension itself.

      Returns Promise<List<TItem>>

      the items for the outer extension, or the data source.

    • Removes every filter on a field and appends the given ones.

      Parameters

      • field: KeyOf<TItem>

        Field whose filters are replaced.

      • ...filters: List<Filter<TItem>>

        New filters, appended as they are (their field is not checked); none to just remove.

      Returns void