mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-01-14 05:53:07 +00:00
* refactor the Store protocol into Core and SDK, simplify `queryGenerator()` * update imports & types * chore: `@noble/hashes` moves to `sdk` * chore: update tests * chore: update size-limit import path * fix: cursor tests, use `Cursor` type from `proto.Index` instead of redefining * export wakuStore from sdk * fix: imports * chore: use specific version for package * chore: handle error for peer access * use type instead of interface * rm: comment * add TODO * chore!: remove deprecated function definition * chore: improve logging
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import { proto_store as proto } from "@waku/proto";
|
|
|
|
import type { IDecodedMessage, IDecoder } from "./message.js";
|
|
import type { IBaseProtocolCore, IBaseProtocolSDK } from "./protocols.js";
|
|
|
|
export enum PageDirection {
|
|
BACKWARD = "backward",
|
|
FORWARD = "forward"
|
|
}
|
|
|
|
export interface TimeFilter {
|
|
startTime: Date;
|
|
endTime: Date;
|
|
}
|
|
|
|
export interface Cursor {
|
|
digest: Uint8Array;
|
|
receiverTime: bigint;
|
|
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. Must be generated from a Waku
|
|
* Message.
|
|
*/
|
|
cursor?: proto.Index;
|
|
};
|
|
|
|
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>[]>;
|
|
|
|
queryWithOrderedCallback: <T extends IDecodedMessage>(
|
|
decoders: IDecoder<T>[],
|
|
callback: (message: T) => Promise<void | boolean> | boolean | void,
|
|
options?: StoreQueryOptions
|
|
) => Promise<void>;
|
|
queryWithPromiseCallback: <T extends IDecodedMessage>(
|
|
decoders: IDecoder<T>[],
|
|
callback: (
|
|
message: Promise<T | undefined>
|
|
) => Promise<void | boolean> | boolean | void,
|
|
options?: StoreQueryOptions
|
|
) => Promise<void>;
|
|
};
|