From 18e0f4ad56539b693e4207047722dc71f5cdcb80 Mon Sep 17 00:00:00 2001 From: anitarua Date: Thu, 22 Aug 2024 09:52:45 -0700 Subject: [PATCH] feat: add sequence number to TopicItem --- .../src/internal/pubsub-client.ts | 20 +++++++++++++------ .../core/src/messages/responses/topic-item.ts | 16 ++++++++++++++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/packages/client-sdk-nodejs/src/internal/pubsub-client.ts b/packages/client-sdk-nodejs/src/internal/pubsub-client.ts index 373467d52..01e71a6d3 100644 --- a/packages/client-sdk-nodejs/src/internal/pubsub-client.ts +++ b/packages/client-sdk-nodejs/src/internal/pubsub-client.ts @@ -216,15 +216,23 @@ export class PubsubClient extends AbstractPubsubClient { ); if (resp.item.value.text) { options.onItem( - new TopicItem(resp.item.value.text, { - tokenId: resp.item.publisher_id, - }) + new TopicItem( + resp.item.value.text, + resp.item.topic_sequence_number, + { + tokenId: resp.item.publisher_id, + } + ) ); } else if (resp.item.value.binary) { options.onItem( - new TopicItem(resp.item.value.binary, { - tokenId: resp.item.publisher_id, - }) + new TopicItem( + resp.item.value.binary, + resp.item.topic_sequence_number, + { + tokenId: resp.item.publisher_id, + } + ) ); } else { this.getLogger().error( diff --git a/packages/core/src/messages/responses/topic-item.ts b/packages/core/src/messages/responses/topic-item.ts index 09388fe54..e26ed46e6 100644 --- a/packages/core/src/messages/responses/topic-item.ts +++ b/packages/core/src/messages/responses/topic-item.ts @@ -14,10 +14,16 @@ export interface TopicItemOptions { export class TopicItem { private readonly _value: string | Uint8Array; private readonly _tokenId?: string; + private readonly _sequenceNumber: number; - constructor(_value: string | Uint8Array, options?: TopicItemOptions) { + constructor( + _value: string | Uint8Array, + _sequenceNumber: number, + options?: TopicItemOptions + ) { this._value = _value; this._tokenId = options?.tokenId; + this._sequenceNumber = _sequenceNumber; } /** @@ -52,6 +58,14 @@ export class TopicItem { return this._tokenId; } + /** + * Returns the sequence number of the item. + * @returns string | undefined + */ + public sequenceNumber(): number { + return this._sequenceNumber; + } + public toString(): string { const displayValue = truncateString(this.value().toString()); let displayString = `${this.constructor.name}: ${displayValue}`;