@squidcloud/client
Version:
A typescript implementation of the Squid client
42 lines (41 loc) • 1.8 kB
TypeScript
import { Observable } from 'rxjs';
import { SerializedQuery } from '../../../internal-common/src/public-types/serialized-query.public-types';
import { Pagination, PaginationOptions } from './pagination';
/**
* Interface for emitting query results in a reactive manner,
* supporting both synchronous and asynchronous access.
* @category Database
*/
export interface SnapshotEmitter<ReturnType> {
/**
* Returns a promise that resolves to the query results.
*
* @returns A promise that resolves to the query results.
*/
snapshot(): Promise<Array<ReturnType>>;
/**
* Returns an observable that emits the query results and updates whenever the query results change unless
* `subscribe=false` is provided.
*
* Important: Make sure to unsubscribe from the observable when you are done with it.
*
* @param subscribe Whether to subscribe to changes to the query results. Defaults to `true`.
* @returns An observable for the query results.
*/
snapshots(subscribe?: boolean): Observable<Array<ReturnType>>;
/**
* Returns the results of the query based on the data that is currently available on the client. This method is useful
* for synchronously accessing data that has already been fetched by another query. The method will return an empty
* array if data has not yet been populated.
*
* @returns An array of query results.
*/
peek(): Array<ReturnType>;
/**
* Returns a pagination wrapper for this query.
* @param options The pagination options. Defaults to `{ subscribe: true, pageSize: 100 }`.
*/
paginate(options?: Partial<PaginationOptions>): Pagination<ReturnType>;
/** Serializes the active query used by the emitter. */
serialize(): SerializedQuery;
}