import { WatchCallback, WatchHandle } from 'apprt-core/Mutable'; /** * Results of a query. * @internal */ interface ResultItems extends ReadonlyArray { /** Total number of available items in the result. */ readonly total?: number; } /** * Pending query. * @internal */ interface QueryResult extends Promise> { /** * Function to stop the query. */ cancel?(): any; } /** * Source of a query providing results. * >Note that AsyncStore is an implementation of Datasource. * @internal */ interface DataSource { /** * Function to query the DataSource. * This method is executed using the parameters of the QueryExecution. */ query(...args: any[]): QueryResult; } /** * Item with the ability to watch for changes on properties. * @internal */ interface Watchable { /** * Function to watch for changes on a property. * @param property name of the property to watch * @param cb event handler executed on changes */ watch(property: string, cb: WatchCallback): WatchHandle; } /** * Container to track a query execution on a queryable source. */ interface QueryExecution extends Watchable { /** Indicates that the execution is running. */ readonly running: boolean; /** Indicates that the execution is finished. */ readonly executed: boolean; /** Title of the execution. */ title: string; /** Source of the query that must have a query method. */ source?: DataSource; /** Parameters used to control the query. */ parameters?: any[]; /** Error to indicate query failures. */ readonly error?: Error; /** Results of the executed query. */ readonly result?: ReadonlyArray; /** Total number of available items in the result, if the query was paginated */ readonly total?: number; /** Pending query. */ readonly queryResult?: QueryResult; /** Function to trigger the execution. */ run(): Promise>; /** Function to cancel/stop the current execution. */ cancel(): void; /** Helper function to wait until the execution is finished. */ waitForExecution(): Promise>; } type QueryExecutionConstructorOptions = Partial, "title" | "source" | "parameters">>; /** * Creates a QueryExecution instance * * ```ts * import QueryExecution from "store-api/QueryExecution"; * * const execution = new QueryExecution({ * title: "My Execution", * source: { * query() { * // ... * } * }, * parameters: [] * }); * ``` */ type QueryExecutionConstructor = new (options?: QueryExecutionConstructorOptions) => QueryExecution; /** Creates a QueryExecution */ declare const _default: QueryExecutionConstructor; export { _default as default }; export type { DataSource, QueryExecution, QueryExecutionConstructor, QueryResult, ResultItems, Watchable };