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
This commit is contained in:
Danish Arora 2023-10-09 21:25:38 +05:30 committed by GitHub
parent 0bc4a96807
commit b10c46b910
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<T extends IDecodedMessage>(
}
}
export async function createCursor(
message: IDecodedMessage,
pubsubTopic: string = DefaultPubSubTopic
): Promise<Cursor> {
export async function createCursor(message: IDecodedMessage): Promise<Cursor> {
if (
!message ||
!message.timestamp ||
@ -418,7 +425,7 @@ export async function createCursor(
return {
digest,
pubsubTopic,
pubsubTopic: message.pubSubTopic,
senderTime: messageTime,
receiverTime: messageTime
};