Skip to content

Commit

Permalink
feat: add sequence number to TopicItem
Browse files Browse the repository at this point in the history
  • Loading branch information
anitarua committed Aug 22, 2024
1 parent 7940999 commit 18e0f4a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
20 changes: 14 additions & 6 deletions packages/client-sdk-nodejs/src/internal/pubsub-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,23 @@ export class PubsubClient extends AbstractPubsubClient<ServiceError> {
);
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(
Expand Down
16 changes: 15 additions & 1 deletion packages/core/src/messages/responses/topic-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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}`;
Expand Down

0 comments on commit 18e0f4a

Please sign in to comment.