Skip to content

Commit

Permalink
chore: rename publisherId to tokenId in topic item (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
pratik151192 authored Oct 25, 2023
1 parent 336374a commit e2d7e4d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/client-sdk-nodejs/src/internal/pubsub-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ export class PubsubClient extends AbstractPubsubClient {
if (resp.item.value.text) {
options.onItem(
new TopicItem(resp.item.value.text, {
publisherId: resp.item.publisher_id,
tokenId: resp.item.publisher_id,
})
);
} else if (resp.item.value.binary) {
options.onItem(
new TopicItem(resp.item.value.binary, {
publisherId: resp.item.publisher_id,
tokenId: resp.item.publisher_id,
})
);
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/client-sdk-web/src/internal/pubsub-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ export class PubsubClient<
const publisherId = resp.getItem()?.getPublisherId();
const itemBinary = resp.getItem()?.getValue()?.getBinary();
if (itemText) {
options.onItem(new TopicItem(itemText, {publisherId: publisherId}));
options.onItem(new TopicItem(itemText, {tokenId: publisherId}));
} else if (itemBinary) {
options.onItem(new TopicItem(itemBinary, {publisherId: publisherId}));
options.onItem(new TopicItem(itemBinary, {tokenId: publisherId}));
} else {
this.logger.error(
'Received subscription item with unknown type; topic: %s',
Expand Down
4 changes: 2 additions & 2 deletions packages/common-integration-tests/src/auth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,9 +902,9 @@ export function runAuthClientTests(
await sleep(2000);

expect(receivedValues[0].valueString()).toEqual('humans landed on Mars!');
expect(receivedValues[0].publisherId()).toEqual('myTokenID');
expect(receivedValues[0].tokenId()).toEqual('myTokenID');
expect(receivedValues[0].toString()).toEqual(
'TopicItem: humans landed on Mars!; Publisher ID: myTokenID'
'TopicItem: humans landed on Mars!; Token Id: myTokenID'
);
done = true;

Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/messages/responses/topic-item.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {truncateString} from '../../internal/utils';

export interface TopicItemOptions {
publisherId?: string;
tokenId?: string;
}

/**
Expand All @@ -13,11 +13,11 @@ export interface TopicItemOptions {
*/
export class TopicItem {
private readonly _value: string | Uint8Array;
private readonly _publisherId?: string;
private readonly _tokenId?: string;

constructor(_value: string | Uint8Array, options?: TopicItemOptions) {
this._value = _value;
this._publisherId = options?.publisherId;
this._tokenId = options?.tokenId;
}

/**
Expand Down Expand Up @@ -48,16 +48,16 @@ export class TopicItem {
* Optionally returns the publisher ID from the steam if it exists.
* @returns string | undefined
*/
public publisherId(): string | undefined {
return this._publisherId;
public tokenId(): string | undefined {
return this._tokenId;
}

public toString(): string {
const displayValue = truncateString(this.value().toString());
let displayString = `${this.constructor.name}: ${displayValue}`;

if (this._publisherId !== undefined) {
displayString += `; Publisher ID: ${this._publisherId}`;
if (this._tokenId !== undefined) {
displayString += `; Token Id: ${this._tokenId}`;
}

return displayString;
Expand Down

0 comments on commit e2d7e4d

Please sign in to comment.