UNPKG

@signaldb/core

Version:

SignalDB is a client-side database that provides a simple MongoDB-like interface to the data with first-class typescript support to achieve an optimistic UI. Data persistence can be achieved by using storage providers that store the data through a JSON in

42 lines (41 loc) 2.15 kB
import type IndexProvider from '../types/IndexProvider'; import type { FlatSelector } from '../types/Selector'; import type Selector from '../types/Selector'; import type { BaseItem } from './types'; /** * Retrieves merged index information for a given flat selector by querying multiple * index providers. Combines results from all index providers to determine matched positions * and an optimized selector. * @template T - The type of the items in the collection. * @template I - The type of the unique identifier for the items. * @param indexProviders - An array of index providers to query. * @param selector - The flat selector used to filter items. * @returns An object containing: * - `matched`: A boolean indicating if the selector matched any items. * - `positions`: An array of matched item positions. * - `optimizedSelector`: A flat selector optimized based on the index results. */ export declare function getMergedIndexInfo<T extends BaseItem<I> = BaseItem, I = any>(indexProviders: IndexProvider<T, I>[], selector: FlatSelector<T>): { matched: boolean; positions: number[]; optimizedSelector: FlatSelector<T>; }; /** * Retrieves index information for a given complex selector by querying multiple * index providers. Handles nested `$and` and `$or` conditions in the selector and * optimizes the selector to minimize processing overhead. * @template T - The type of the items in the collection. * @template I - The type of the unique identifier for the items. * @param indexProviders - An array of index providers to query. * @param selector - The complex selector used to filter items. * @returns An object containing: * - `matched`: A boolean indicating if the selector matched any items. * - `positions`: An array of matched item positions. * - `optimizedSelector`: A selector optimized based on the index results, with unused * conditions removed. */ export default function getIndexInfo<T extends BaseItem<I> = BaseItem, I = any>(indexProviders: IndexProvider<T, I>[], selector: Selector<T>): { matched: boolean; positions: number[]; optimizedSelector: Selector<T>; };