From b10c46b910511418a048d7092dfd8b500a71a931 Mon Sep 17 00:00:00 2001 From: Danish Arora <35004822+danisharora099@users.noreply.github.com> Date: Mon, 9 Oct 2023 21:25:38 +0530 Subject: [PATCH] fix(store)!: use `pubSubTopic` from `DecodedMessage` for `createCursor` (#1640) * fix!(store): Cursor: use pubsubtopic from Message * add control to check cursor topic should match decoder * fix --- packages/core/src/lib/store/index.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/core/src/lib/store/index.ts b/packages/core/src/lib/store/index.ts index 9ed938ff3c..6d5cedc4de 100644 --- a/packages/core/src/lib/store/index.ts +++ b/packages/core/src/lib/store/index.ts @@ -246,6 +246,16 @@ class Store extends BaseProtocol implements IStore { ensurePubsubTopicIsConfigured(pubSubTopicForQuery, this.pubSubTopics); + // check that the pubSubTopic from the Cursor and Decoder match + if ( + options?.cursor?.pubsubTopic && + options.cursor.pubsubTopic !== pubSubTopicForQuery + ) { + throw new Error( + `Cursor pubsub topic (${options?.cursor?.pubsubTopic}) does not match decoder pubsub topic (${pubSubTopicForQuery})` + ); + } + const decodersAsMap = new Map(); decoders.forEach((dec) => { if (decodersAsMap.has(dec.contentTopic)) { @@ -397,10 +407,7 @@ async function* paginate( } } -export async function createCursor( - message: IDecodedMessage, - pubsubTopic: string = DefaultPubSubTopic -): Promise { +export async function createCursor(message: IDecodedMessage): Promise { if ( !message || !message.timestamp || @@ -418,7 +425,7 @@ export async function createCursor( return { digest, - pubsubTopic, + pubsubTopic: message.pubSubTopic, senderTime: messageTime, receiverTime: messageTime };