diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d5d5ca8b0..19df7fd74f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - **Breaking**: The `WakuMessage` APIs have been changed to move `contentTopic` out of the optional parameters. +- **Breaking**: Move `contentTopics` out the `WakuStore.queryHistory`'s optional parameters. ### Removed - Examples (web-chat): Remove broken `/fleet` command. diff --git a/README.md b/README.md index e4b2676b09..568881ca25 100644 --- a/README.md +++ b/README.md @@ -118,20 +118,19 @@ Query a waku store peer to check historical messages: ```ts // Process messages once they are all retrieved -const messages = await waku.store.queryHistory({ contentTopics: ["/my-cool-app/1/my-use-case/proto"] }); +const messages = await waku.store.queryHistory(['/my-cool-app/1/my-use-case/proto']); messages.forEach((msg) => { - console.log("Message retrieved:", msg.payloadAsUtf8) -}) + console.log('Message retrieved:', msg.payloadAsUtf8); +}); // Or, pass a callback function to be executed as pages are received: -waku.store.queryHistory({ - contentTopics: ["/my-cool-app/1/my-use-case/proto"], - callback: (messages) => { - messages.forEach((msg) => { - console.log("Message retrieved:", msg.payloadAsUtf8); - }); - } - }); +waku.store.queryHistory(['/my-cool-app/1/my-use-case/proto'], { + callback: (messages) => { + messages.forEach((msg) => { + console.log('Message retrieved:', msg.payloadAsUtf8); + }); + } +}); ``` ### Encryption & Signature @@ -212,9 +211,8 @@ Keys can be removed using `WakuMessage.deleteDecryptionKey`. ##### Waku Store ```ts -const messages = await waku.store.queryHistory({ - contentTopics: [], - decryptionKeys: [privateKey, symKey], +const messages = await waku.store.queryHistory([], { + decryptionKeys: [privateKey, symKey] }); ``` @@ -228,20 +226,20 @@ In the case where your app does not need encryption then you could use symmetric Signature keys can be generated the same way asymmetric keys for encryption are: ```ts -import { generatePrivateKey, getPublicKey, WakuMessage } from "js-waku"; +import { generatePrivateKey, getPublicKey, WakuMessage } from 'js-waku'; const signPrivateKey = generatePrivateKey(); // Asymmetric Encryption const message1 = await WakuMessage.fromBytes(payload, myAppContentTopic, { encPublicKey: recipientPublicKey, - sigPrivKey: signPrivateKey, + sigPrivKey: signPrivateKey }); // Symmetric Encryption const message2 = await WakuMessage.fromBytes(payload, myAppContentTopic, { encPublicKey: symKey, - sigPrivKey: signPrivateKey, + sigPrivKey: signPrivateKey }); ``` diff --git a/examples/web-chat/src/App.tsx b/examples/web-chat/src/App.tsx index 12829d90b8..728471a103 100644 --- a/examples/web-chat/src/App.tsx +++ b/examples/web-chat/src/App.tsx @@ -62,8 +62,7 @@ async function retrieveStoreMessages( setArchivedMessages(messages); }; - const res = await waku.store.queryHistory({ - contentTopics: [ChatContentTopic], + const res = await waku.store.queryHistory([ChatContentTopic], { pageSize: 5, direction: Direction.FORWARD, callback, diff --git a/src/lib/waku_store/history_rpc.ts b/src/lib/waku_store/history_rpc.ts index 27388faf90..681f915083 100644 --- a/src/lib/waku_store/history_rpc.ts +++ b/src/lib/waku_store/history_rpc.ts @@ -8,7 +8,7 @@ export enum Direction { FORWARD = 'forward', } -export interface Options { +export interface Params { contentTopics: string[]; cursor?: proto.Index; pubsubTopic: string; @@ -22,22 +22,22 @@ export class HistoryRPC { /** * Create History Query. */ - static createQuery(options: Options): HistoryRPC { - const direction = directionToProto(options.direction); + static createQuery(params: Params): HistoryRPC { + const direction = directionToProto(params.direction); const pagingInfo = { - pageSize: options.pageSize, - cursor: options.cursor, + pageSize: params.pageSize, + cursor: params.cursor, direction, }; - const contentFilters = options.contentTopics.map((contentTopic) => { + const contentFilters = params.contentTopics.map((contentTopic) => { return { contentTopic }; }); return new HistoryRPC({ requestId: uuid(), query: { - pubsubTopic: options.pubsubTopic, + pubsubTopic: params.pubsubTopic, contentFilters, pagingInfo, startTime: undefined, diff --git a/src/lib/waku_store/index.spec.ts b/src/lib/waku_store/index.spec.ts index 53cc942b34..cf66002f32 100644 --- a/src/lib/waku_store/index.spec.ts +++ b/src/lib/waku_store/index.spec.ts @@ -55,9 +55,7 @@ describe('Waku Store', () => { waku.libp2p.peerStore.once('change:protocols', resolve); }); - const messages = await waku.store.queryHistory({ - contentTopics: [], - }); + const messages = await waku.store.queryHistory([]); expect(messages?.length).eq(2); const result = messages?.findIndex((msg) => { @@ -91,8 +89,7 @@ describe('Waku Store', () => { waku.libp2p.peerStore.once('change:protocols', resolve); }); - const messages = await waku.store.queryHistory({ - contentTopics: [], + const messages = await waku.store.queryHistory([], { direction: Direction.FORWARD, }); @@ -136,9 +133,8 @@ describe('Waku Store', () => { const nimPeerId = await nimWaku.getPeerId(); - const messages = await waku.store.queryHistory({ + const messages = await waku.store.queryHistory([], { peerId: nimPeerId, - contentTopics: [], }); expect(messages?.length).eq(2); @@ -237,8 +233,7 @@ describe('Waku Store', () => { } dbg('Retrieve messages from store'); - const messages = await waku2.store.queryHistory({ - contentTopics: [], + const messages = await waku2.store.queryHistory([], { decryptionKeys: [privateKey, symKey], }); diff --git a/src/lib/waku_store/index.ts b/src/lib/waku_store/index.ts index 4ed2771e4d..534bf4b9e5 100644 --- a/src/lib/waku_store/index.ts +++ b/src/lib/waku_store/index.ts @@ -33,7 +33,6 @@ export interface CreateOptions { export interface QueryOptions { peerId?: PeerId; - contentTopics: string[]; pubsubTopic?: string; direction?: Direction; pageSize?: number; @@ -58,10 +57,10 @@ export class WakuStore { /** * Query given peer using Waku Store. * + * @param contentTopics The content topics to pass to the query, leave empty to + * retrieve all messages. * @param options * @param options.peerId The peer to query.Options - * @param options.contentTopics The content topics to pass to the query, leave empty to - * retrieve all messages. * @param options.pubsubTopic The pubsub topic to pass to the query. Defaults * to the value set at creation. See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/). * @param options.callback Callback called on page of stored messages as they are retrieved @@ -70,14 +69,18 @@ export class WakuStore { * methods. * @throws If not able to reach the peer to query. */ - async queryHistory(options: QueryOptions): Promise { + async queryHistory( + contentTopics: string[], + options?: QueryOptions + ): Promise { const opts = Object.assign( { pubsubTopic: this.pubsubTopic, direction: Direction.BACKWARD, pageSize: 10, }, - options + options, + { contentTopics } ); dbg('Querying history with the following options', options);