import type { IDecodedMessage, IDecoder } from "./message.js"; import type { PointToPointProtocol, ProtocolOptions } from "./protocols.js"; export enum PageDirection { BACKWARD = "backward", FORWARD = "forward", } export interface TimeFilter { startTime: Date; endTime: Date; } export interface Index { digest?: Uint8Array; receivedTime?: bigint; senderTime?: bigint; pubsubTopic?: string; } export type Cursor = { digest?: Uint8Array; senderTime?: bigint; pubsubTopic?: string; }; export type StoreQueryOptions = { /** * The direction in which pages are retrieved: * - { @link PageDirection.BACKWARD }: Most recent page first. * - { @link PageDirection.FORWARD }: Oldest page first. * * Note: This does not affect the ordering of messages with the page * (the oldest message is always first). * * @default { @link PageDirection.BACKWARD } */ pageDirection?: PageDirection; /** * The number of message per page. */ pageSize?: number; /** * Retrieve messages with a timestamp within the provided values. */ timeFilter?: TimeFilter; /** * Cursor as an index to start a query from. */ cursor?: Cursor; } & ProtocolOptions; export interface IStore extends PointToPointProtocol { queryOrderedCallback: ( decoders: IDecoder[], callback: (message: T) => Promise | boolean | void, options?: StoreQueryOptions ) => Promise; queryCallbackOnPromise: ( decoders: IDecoder[], callback: ( message: Promise ) => Promise | boolean | void, options?: StoreQueryOptions ) => Promise; queryGenerator: ( decoders: IDecoder[], options?: StoreQueryOptions ) => AsyncGenerator[]>; }