2024-04-01 16:47:47 +05:30
|
|
|
import { proto_store as proto } from "@waku/proto";
|
|
|
|
|
|
2022-12-05 17:07:03 +11:00
|
|
|
import type { IDecodedMessage, IDecoder } from "./message.js";
|
2024-04-01 16:47:47 +05:30
|
|
|
import type { IBaseProtocolCore, IBaseProtocolSDK } from "./protocols.js";
|
2022-12-05 17:00:24 +11:00
|
|
|
|
|
|
|
|
export enum PageDirection {
|
|
|
|
|
BACKWARD = "backward",
|
2023-08-16 20:18:13 +05:30
|
|
|
FORWARD = "forward"
|
2022-12-05 17:00:24 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface TimeFilter {
|
|
|
|
|
startTime: Date;
|
|
|
|
|
endTime: Date;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-24 23:58:25 +11:00
|
|
|
export interface Cursor {
|
|
|
|
|
digest: Uint8Array;
|
|
|
|
|
receiverTime: bigint;
|
|
|
|
|
senderTime: bigint;
|
|
|
|
|
pubsubTopic: string;
|
2022-12-05 17:00:24 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
/**
|
2023-02-24 23:58:25 +11:00
|
|
|
* Cursor as an index to start a query from. Must be generated from a Waku
|
|
|
|
|
* Message.
|
2022-12-05 17:00:24 +11:00
|
|
|
*/
|
2024-04-01 16:47:47 +05:30
|
|
|
cursor?: proto.Index;
|
2023-09-07 13:15:49 +05:30
|
|
|
};
|
2022-12-05 17:00:24 +11:00
|
|
|
|
2024-04-01 16:47:47 +05:30
|
|
|
export type IStoreCore = IBaseProtocolCore;
|
|
|
|
|
|
|
|
|
|
export type IStoreSDK = IBaseProtocolSDK & {
|
|
|
|
|
protocol: IBaseProtocolCore;
|
|
|
|
|
createCursor(message: IDecodedMessage): Cursor;
|
|
|
|
|
queryGenerator: <T extends IDecodedMessage>(
|
|
|
|
|
decoders: IDecoder<T>[],
|
|
|
|
|
options?: StoreQueryOptions
|
|
|
|
|
) => AsyncGenerator<Promise<T | undefined>[]>;
|
|
|
|
|
|
2023-08-28 13:19:47 +05:30
|
|
|
queryWithOrderedCallback: <T extends IDecodedMessage>(
|
2022-12-05 17:07:03 +11:00
|
|
|
decoders: IDecoder<T>[],
|
2022-12-05 17:00:24 +11:00
|
|
|
callback: (message: T) => Promise<void | boolean> | boolean | void,
|
2023-08-16 20:18:13 +05:30
|
|
|
options?: StoreQueryOptions
|
2022-12-05 17:00:24 +11:00
|
|
|
) => Promise<void>;
|
2023-08-28 13:19:47 +05:30
|
|
|
queryWithPromiseCallback: <T extends IDecodedMessage>(
|
2022-12-05 17:07:03 +11:00
|
|
|
decoders: IDecoder<T>[],
|
2022-12-05 17:00:24 +11:00
|
|
|
callback: (
|
2023-08-16 20:18:13 +05:30
|
|
|
message: Promise<T | undefined>
|
2022-12-05 17:00:24 +11:00
|
|
|
) => Promise<void | boolean> | boolean | void,
|
2023-08-16 20:18:13 +05:30
|
|
|
options?: StoreQueryOptions
|
2022-12-05 17:00:24 +11:00
|
|
|
) => Promise<void>;
|
2024-04-01 16:47:47 +05:30
|
|
|
};
|