Skip to content

Commit

Permalink
Update and prepare GA for @azure/web-pubsub-client (#27694)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR
@azure/web-pubsub-client

### Describe the problem that is addressed by this PR
Update according to GA API review:
https://apiview.dev/Assemblies/Review/492267bc4ab44b19a558635733047147

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_


### Provide a list of related PRs _(if any)_


### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [ ] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
  • Loading branch information
zackliu authored Nov 30, 2023
1 parent 4e5f461 commit 9a0d1f7
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 45 deletions.
10 changes: 3 additions & 7 deletions sdk/web-pubsub/web-pubsub-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# Release History

## 1.0.0-beta.4 (Unreleased)

### Features Added

### Breaking Changes

### Bugs Fixed
## 1.0.0 (2023-12-01)

### Other Changes

- Use overload for `SendToGroup` and `SendEvent`

## 1.0.0-beta.3 (2023-04-10)

### Bugs Fixed
Expand Down
2 changes: 1 addition & 1 deletion sdk/web-pubsub/web-pubsub-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/web-pubsub-client",
"version": "1.0.0-beta.4",
"version": "1.0.0",
"description": "Azure Web PubSub Client",
"sdk-type": "client",
"main": "dist/index.js",
Expand Down
12 changes: 6 additions & 6 deletions sdk/web-pubsub/web-pubsub-client/review/web-pubsub-client.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export interface SendEventMessage extends WebPubSubMessageBase {
export interface SendEventOptions {
abortSignal?: AbortSignalLike;
ackId?: number;
fireAndForget: boolean;
fireAndForget?: boolean;
}

// @public
Expand Down Expand Up @@ -182,8 +182,8 @@ export interface SendToGroupMessage extends WebPubSubMessageBase {
export interface SendToGroupOptions {
abortSignal?: AbortSignalLike;
ackId?: number;
fireAndForget: boolean;
noEcho: boolean;
fireAndForget?: boolean;
noEcho?: boolean;
}

// @public
Expand Down Expand Up @@ -230,7 +230,7 @@ export type UpstreamMessageType =

// @public
export class WebPubSubClient {
constructor(clientAccessUri: string, options?: WebPubSubClientOptions);
constructor(clientAccessUrl: string, options?: WebPubSubClientOptions);
constructor(credential: WebPubSubClientCredential, options?: WebPubSubClientOptions);
joinGroup(groupName: string, options?: JoinGroupOptions): Promise<WebPubSubResult>;
leaveGroup(groupName: string, options?: LeaveGroupOptions): Promise<WebPubSubResult>;
Expand All @@ -247,7 +247,7 @@ export class WebPubSubClient {
on(event: "group-message", listener: (e: OnGroupDataMessageArgs) => void): void;
on(event: "rejoin-group-failed", listener: (e: OnRejoinGroupFailedArgs) => void): void;
sendEvent(eventName: string, content: JSONTypes | ArrayBuffer, dataType: WebPubSubDataType, options?: SendEventOptions): Promise<WebPubSubResult>;
sendToGroup(groupName: string, content: JSONTypes | ArrayBuffer, dataType: WebPubSubDataType, options?: SendToGroupOptions): Promise<void | WebPubSubResult>;
sendToGroup(groupName: string, content: JSONTypes | ArrayBuffer, dataType: WebPubSubDataType, options?: SendToGroupOptions): Promise<WebPubSubResult>;
start(options?: StartOptions): Promise<void>;
stop(): void;
}
Expand Down Expand Up @@ -310,7 +310,7 @@ export interface WebPubSubMessageBase {

// @public
export interface WebPubSubResult {
ackId: number;
ackId?: number;
isDuplicated: boolean;
}

Expand Down
7 changes: 3 additions & 4 deletions sdk/web-pubsub/web-pubsub-client/samples-dev/helloworld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import {
WebPubSubClient,
WebPubSubClientCredential,
SendToGroupOptions,
GetClientAccessUrlOptions,
} from "@azure/web-pubsub-client";
import { WebPubSubServiceClient } from "@azure/web-pubsub";
Expand Down Expand Up @@ -44,7 +43,7 @@ async function main() {
if (e.message.data instanceof ArrayBuffer) {
console.log(`Received message ${Buffer.from(e.message.data).toString("base64")}`);
} else {
console.log(`Received message ${e.message.data}`);
console.log(`Received message ${JSON.stringify(e.message.data)}`);
}
});

Expand All @@ -54,7 +53,7 @@ async function main() {
`Received message from ${e.message.group} ${Buffer.from(e.message.data).toString("base64")}`
);
} else {
console.log(`Received message from ${e.message.group} ${e.message.data}`);
console.log(`Received message from ${e.message.group} ${JSON.stringify(e.message.data)}`);
}
});

Expand All @@ -63,7 +62,7 @@ async function main() {
await client.joinGroup(groupName);
await client.sendToGroup(groupName, "hello world", "text", {
fireAndForget: true,
} as SendToGroupOptions);
});
await client.sendToGroup(groupName, { a: 12, b: "hello" }, "json");
await client.sendToGroup(groupName, "hello json", "json");
var buf = Buffer.from("aGVsbG9w", "base64");
Expand Down
10 changes: 5 additions & 5 deletions sdk/web-pubsub/web-pubsub-client/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ export interface SendToGroupOptions {
/**
* Whether the message needs to echo to sender
*/
noEcho: boolean;
noEcho?: boolean;
/**
* If true, the message won't contains ackId. No AckMessage will be returned from the service.
*/
fireAndForget: boolean;
fireAndForget?: boolean;
/**
* The optional ackId. If not specified, client will generate one.
*/
Expand All @@ -130,7 +130,7 @@ export interface SendEventOptions {
/**
* If true, the message won't contains ackId. No AckMessage will be returned from the service.
*/
fireAndForget: boolean;
fireAndForget?: boolean;
/**
* The optional ackId. If not specified, client will generate one.
*/
Expand Down Expand Up @@ -213,9 +213,9 @@ export interface OnRejoinGroupFailedArgs {
*/
export interface WebPubSubResult {
/**
* The ack message from the service
* The ack message from the service. If the message is fire-and-forget, this will be undefined.
*/
ackId: number;
ackId?: number;
/**
* Whether the message is duplicated.
*/
Expand Down
18 changes: 8 additions & 10 deletions sdk/web-pubsub/web-pubsub-client/src/webPubSubClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
OnServerDataMessageArgs,
OnStoppedArgs,
WebPubSubRetryOptions,
SendEventOptions,
SendToGroupOptions,
SendEventOptions,
WebPubSubClientOptions,
OnRejoinGroupFailedArgs,
StartOptions,
Expand Down Expand Up @@ -91,10 +91,10 @@ export class WebPubSubClient {

/**
* Create an instance of WebPubSubClient
* @param clientAccessUri - The uri to connect
* @param clientAccessUrl - The uri to connect
* @param options - The client options
*/
constructor(clientAccessUri: string, options?: WebPubSubClientOptions);
constructor(clientAccessUrl: string, options?: WebPubSubClientOptions);
/**
* Create an instance of WebPubSubClient
* @param credential - The credential to use when connecting
Expand Down Expand Up @@ -332,11 +332,10 @@ export class WebPubSubClient {
}

/**
* Send custom event to server
* Send custom event to server.
* @param eventName - The event name
* @param content - The data content
* @param dataType - The data type
* @param ackId - The optional ackId. If not specified, client will generate one.
* @param options - The options
* @param abortSignal - The abort signal
*/
Expand Down Expand Up @@ -383,7 +382,7 @@ export class WebPubSubClient {
} as SendEventMessage;

await this._sendMessage(message, options?.abortSignal);
return {} as WebPubSubResult;
return { isDuplicated: false };
}

/**
Expand Down Expand Up @@ -466,7 +465,6 @@ export class WebPubSubClient {
* @param groupName - The group name
* @param content - The data content
* @param dataType - The data type
* @param ackId - The optional ackId. If not specified, client will generate one.
* @param options - The options
* @param abortSignal - The abort signal
*/
Expand All @@ -475,7 +473,7 @@ export class WebPubSubClient {
content: JSONTypes | ArrayBuffer,
dataType: WebPubSubDataType,
options?: SendToGroupOptions
): Promise<void | WebPubSubResult> {
): Promise<WebPubSubResult> {
return await this._operationExecuteWithRetry(
() => this._sendToGroupAttempt(groupName, content, dataType, options),
options?.abortSignal
Expand Down Expand Up @@ -516,7 +514,7 @@ export class WebPubSubClient {
} as SendToGroupMessage;

await this._sendMessage(message, options?.abortSignal);
return {} as WebPubSubResult;
return { isDuplicated: false };
}

private _getWebSocketClientFactory(): WebSocketClientFactoryLike {
Expand Down Expand Up @@ -568,7 +566,7 @@ export class WebPubSubClient {
if (this._sequenceAckTask != null) {
this._sequenceAckTask.abort();
}
reject(new Error(e));
reject(e);
});

client.onclose((code: number, reason: string) => {
Expand Down
6 changes: 2 additions & 4 deletions sdk/web-pubsub/web-pubsub-client/test/client.lifetime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import {
JoinGroupOptions,
LeaveGroupMessage,
SendEventMessage,
SendEventOptions,
SendToGroupMessage,
SendToGroupOptions,
ServerDataMessage,
WebPubSubClientOptions,
WebPubSubResult,
Expand Down Expand Up @@ -62,7 +60,7 @@ describe("WebPubSubClient", function () {
noEcho: false,
} as SendToGroupMessage,
actualMethod: async (client: WebPubSubClient) =>
await client.sendToGroup("groupName", "xyz", "text", { ackId: 2 } as SendToGroupOptions),
await client.sendToGroup("groupName", "xyz", "text", { ackId: 2 }),
},
{
testName: "send event",
Expand All @@ -74,7 +72,7 @@ describe("WebPubSubClient", function () {
data: "xyz",
} as SendEventMessage,
actualMethod: async (client: WebPubSubClient) =>
await client.sendEvent("sendEvent", "xyz", "text", { ackId: 2 } as SendEventOptions),
await client.sendEvent("sendEvent", "xyz", "text", { ackId: 2 }),
},
];

Expand Down
13 changes: 5 additions & 8 deletions sdk/web-pubsub/web-pubsub-client/test/client.messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import {
LeaveGroupMessage,
LeaveGroupOptions,
SendEventMessage,
SendEventOptions,
SendToGroupMessage,
SendToGroupOptions,
ServerDataMessage,
} from "../src/models";
import { WebPubSubClient } from "../src/webPubSubClient";
Expand Down Expand Up @@ -93,7 +91,7 @@ describe("WebPubSubClient", function () {
.callsFake((_) => Promise.resolve());
client.sendToGroup("groupName", "xyz", "text", {
fireAndForget: true,
} as SendToGroupOptions);
});
mock.verify();
});
});
Expand All @@ -114,7 +112,7 @@ describe("WebPubSubClient", function () {
noEcho: false,
} as SendToGroupMessage)
.callsFake((_) => Promise.resolve());
client.sendToGroup("groupName", "xyz", "text", { ackId: 2233 } as SendToGroupOptions);
client.sendToGroup("groupName", "xyz", "text", { ackId: 2233 });
mock.verify();
});
});
Expand Down Expand Up @@ -156,7 +154,7 @@ describe("WebPubSubClient", function () {
noEcho: true,
} as SendToGroupMessage)
.callsFake((_) => Promise.resolve());
client.sendToGroup("groupName", "xyz", "text", { noEcho: true } as SendToGroupOptions);
client.sendToGroup("groupName", "xyz", "text", { noEcho: true });
mock.verify();
});
});
Expand Down Expand Up @@ -196,7 +194,7 @@ describe("WebPubSubClient", function () {
data: "xyz",
} as SendEventMessage)
.callsFake((_) => Promise.resolve());
client.sendEvent("eventName", "xyz", "text", { ackId: 12345 } as SendEventOptions);
client.sendEvent("eventName", "xyz", "text", { ackId: 12345 });
mock.verify();
});
});
Expand All @@ -216,9 +214,8 @@ describe("WebPubSubClient", function () {
} as SendEventMessage)
.callsFake((_) => Promise.resolve());
client.sendEvent("eventName", "xyz", "text", {
ackId: 12345,
fireAndForget: true,
} as SendEventOptions);
});
mock.verify();
});
});
Expand Down

0 comments on commit 9a0d1f7

Please sign in to comment.