Skip to content

Commit 9a0d1f7

Browse files
authored
Update and prepare GA for @azure/web-pubsub-client (Azure#27694)
### 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)
1 parent 4e5f461 commit 9a0d1f7

File tree

8 files changed

+33
-45
lines changed

8 files changed

+33
-45
lines changed

sdk/web-pubsub/web-pubsub-client/CHANGELOG.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
# Release History
22

3-
## 1.0.0-beta.4 (Unreleased)
4-
5-
### Features Added
6-
7-
### Breaking Changes
8-
9-
### Bugs Fixed
3+
## 1.0.0 (2023-12-01)
104

115
### Other Changes
126

7+
- Use overload for `SendToGroup` and `SendEvent`
8+
139
## 1.0.0-beta.3 (2023-04-10)
1410

1511
### Bugs Fixed

sdk/web-pubsub/web-pubsub-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure/web-pubsub-client",
3-
"version": "1.0.0-beta.4",
3+
"version": "1.0.0",
44
"description": "Azure Web PubSub Client",
55
"sdk-type": "client",
66
"main": "dist/index.js",

sdk/web-pubsub/web-pubsub-client/review/web-pubsub-client.api.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export interface SendEventMessage extends WebPubSubMessageBase {
151151
export interface SendEventOptions {
152152
abortSignal?: AbortSignalLike;
153153
ackId?: number;
154-
fireAndForget: boolean;
154+
fireAndForget?: boolean;
155155
}
156156

157157
// @public
@@ -182,8 +182,8 @@ export interface SendToGroupMessage extends WebPubSubMessageBase {
182182
export interface SendToGroupOptions {
183183
abortSignal?: AbortSignalLike;
184184
ackId?: number;
185-
fireAndForget: boolean;
186-
noEcho: boolean;
185+
fireAndForget?: boolean;
186+
noEcho?: boolean;
187187
}
188188

189189
// @public
@@ -230,7 +230,7 @@ export type UpstreamMessageType =
230230

231231
// @public
232232
export class WebPubSubClient {
233-
constructor(clientAccessUri: string, options?: WebPubSubClientOptions);
233+
constructor(clientAccessUrl: string, options?: WebPubSubClientOptions);
234234
constructor(credential: WebPubSubClientCredential, options?: WebPubSubClientOptions);
235235
joinGroup(groupName: string, options?: JoinGroupOptions): Promise<WebPubSubResult>;
236236
leaveGroup(groupName: string, options?: LeaveGroupOptions): Promise<WebPubSubResult>;
@@ -247,7 +247,7 @@ export class WebPubSubClient {
247247
on(event: "group-message", listener: (e: OnGroupDataMessageArgs) => void): void;
248248
on(event: "rejoin-group-failed", listener: (e: OnRejoinGroupFailedArgs) => void): void;
249249
sendEvent(eventName: string, content: JSONTypes | ArrayBuffer, dataType: WebPubSubDataType, options?: SendEventOptions): Promise<WebPubSubResult>;
250-
sendToGroup(groupName: string, content: JSONTypes | ArrayBuffer, dataType: WebPubSubDataType, options?: SendToGroupOptions): Promise<void | WebPubSubResult>;
250+
sendToGroup(groupName: string, content: JSONTypes | ArrayBuffer, dataType: WebPubSubDataType, options?: SendToGroupOptions): Promise<WebPubSubResult>;
251251
start(options?: StartOptions): Promise<void>;
252252
stop(): void;
253253
}
@@ -310,7 +310,7 @@ export interface WebPubSubMessageBase {
310310

311311
// @public
312312
export interface WebPubSubResult {
313-
ackId: number;
313+
ackId?: number;
314314
isDuplicated: boolean;
315315
}
316316

sdk/web-pubsub/web-pubsub-client/samples-dev/helloworld.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import {
99
WebPubSubClient,
1010
WebPubSubClientCredential,
11-
SendToGroupOptions,
1211
GetClientAccessUrlOptions,
1312
} from "@azure/web-pubsub-client";
1413
import { WebPubSubServiceClient } from "@azure/web-pubsub";
@@ -44,7 +43,7 @@ async function main() {
4443
if (e.message.data instanceof ArrayBuffer) {
4544
console.log(`Received message ${Buffer.from(e.message.data).toString("base64")}`);
4645
} else {
47-
console.log(`Received message ${e.message.data}`);
46+
console.log(`Received message ${JSON.stringify(e.message.data)}`);
4847
}
4948
});
5049

@@ -54,7 +53,7 @@ async function main() {
5453
`Received message from ${e.message.group} ${Buffer.from(e.message.data).toString("base64")}`
5554
);
5655
} else {
57-
console.log(`Received message from ${e.message.group} ${e.message.data}`);
56+
console.log(`Received message from ${e.message.group} ${JSON.stringify(e.message.data)}`);
5857
}
5958
});
6059

@@ -63,7 +62,7 @@ async function main() {
6362
await client.joinGroup(groupName);
6463
await client.sendToGroup(groupName, "hello world", "text", {
6564
fireAndForget: true,
66-
} as SendToGroupOptions);
65+
});
6766
await client.sendToGroup(groupName, { a: 12, b: "hello" }, "json");
6867
await client.sendToGroup(groupName, "hello json", "json");
6968
var buf = Buffer.from("aGVsbG9w", "base64");

sdk/web-pubsub/web-pubsub-client/src/models/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ export interface SendToGroupOptions {
108108
/**
109109
* Whether the message needs to echo to sender
110110
*/
111-
noEcho: boolean;
111+
noEcho?: boolean;
112112
/**
113113
* If true, the message won't contains ackId. No AckMessage will be returned from the service.
114114
*/
115-
fireAndForget: boolean;
115+
fireAndForget?: boolean;
116116
/**
117117
* The optional ackId. If not specified, client will generate one.
118118
*/
@@ -130,7 +130,7 @@ export interface SendEventOptions {
130130
/**
131131
* If true, the message won't contains ackId. No AckMessage will be returned from the service.
132132
*/
133-
fireAndForget: boolean;
133+
fireAndForget?: boolean;
134134
/**
135135
* The optional ackId. If not specified, client will generate one.
136136
*/
@@ -213,9 +213,9 @@ export interface OnRejoinGroupFailedArgs {
213213
*/
214214
export interface WebPubSubResult {
215215
/**
216-
* The ack message from the service
216+
* The ack message from the service. If the message is fire-and-forget, this will be undefined.
217217
*/
218-
ackId: number;
218+
ackId?: number;
219219
/**
220220
* Whether the message is duplicated.
221221
*/

sdk/web-pubsub/web-pubsub-client/src/webPubSubClient.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import {
1616
OnServerDataMessageArgs,
1717
OnStoppedArgs,
1818
WebPubSubRetryOptions,
19-
SendEventOptions,
2019
SendToGroupOptions,
20+
SendEventOptions,
2121
WebPubSubClientOptions,
2222
OnRejoinGroupFailedArgs,
2323
StartOptions,
@@ -91,10 +91,10 @@ export class WebPubSubClient {
9191

9292
/**
9393
* Create an instance of WebPubSubClient
94-
* @param clientAccessUri - The uri to connect
94+
* @param clientAccessUrl - The uri to connect
9595
* @param options - The client options
9696
*/
97-
constructor(clientAccessUri: string, options?: WebPubSubClientOptions);
97+
constructor(clientAccessUrl: string, options?: WebPubSubClientOptions);
9898
/**
9999
* Create an instance of WebPubSubClient
100100
* @param credential - The credential to use when connecting
@@ -332,11 +332,10 @@ export class WebPubSubClient {
332332
}
333333

334334
/**
335-
* Send custom event to server
335+
* Send custom event to server.
336336
* @param eventName - The event name
337337
* @param content - The data content
338338
* @param dataType - The data type
339-
* @param ackId - The optional ackId. If not specified, client will generate one.
340339
* @param options - The options
341340
* @param abortSignal - The abort signal
342341
*/
@@ -383,7 +382,7 @@ export class WebPubSubClient {
383382
} as SendEventMessage;
384383

385384
await this._sendMessage(message, options?.abortSignal);
386-
return {} as WebPubSubResult;
385+
return { isDuplicated: false };
387386
}
388387

389388
/**
@@ -466,7 +465,6 @@ export class WebPubSubClient {
466465
* @param groupName - The group name
467466
* @param content - The data content
468467
* @param dataType - The data type
469-
* @param ackId - The optional ackId. If not specified, client will generate one.
470468
* @param options - The options
471469
* @param abortSignal - The abort signal
472470
*/
@@ -475,7 +473,7 @@ export class WebPubSubClient {
475473
content: JSONTypes | ArrayBuffer,
476474
dataType: WebPubSubDataType,
477475
options?: SendToGroupOptions
478-
): Promise<void | WebPubSubResult> {
476+
): Promise<WebPubSubResult> {
479477
return await this._operationExecuteWithRetry(
480478
() => this._sendToGroupAttempt(groupName, content, dataType, options),
481479
options?.abortSignal
@@ -516,7 +514,7 @@ export class WebPubSubClient {
516514
} as SendToGroupMessage;
517515

518516
await this._sendMessage(message, options?.abortSignal);
519-
return {} as WebPubSubResult;
517+
return { isDuplicated: false };
520518
}
521519

522520
private _getWebSocketClientFactory(): WebSocketClientFactoryLike {
@@ -568,7 +566,7 @@ export class WebPubSubClient {
568566
if (this._sequenceAckTask != null) {
569567
this._sequenceAckTask.abort();
570568
}
571-
reject(new Error(e));
569+
reject(e);
572570
});
573571

574572
client.onclose((code: number, reason: string) => {

sdk/web-pubsub/web-pubsub-client/test/client.lifetime.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import {
88
JoinGroupOptions,
99
LeaveGroupMessage,
1010
SendEventMessage,
11-
SendEventOptions,
1211
SendToGroupMessage,
13-
SendToGroupOptions,
1412
ServerDataMessage,
1513
WebPubSubClientOptions,
1614
WebPubSubResult,
@@ -62,7 +60,7 @@ describe("WebPubSubClient", function () {
6260
noEcho: false,
6361
} as SendToGroupMessage,
6462
actualMethod: async (client: WebPubSubClient) =>
65-
await client.sendToGroup("groupName", "xyz", "text", { ackId: 2 } as SendToGroupOptions),
63+
await client.sendToGroup("groupName", "xyz", "text", { ackId: 2 }),
6664
},
6765
{
6866
testName: "send event",
@@ -74,7 +72,7 @@ describe("WebPubSubClient", function () {
7472
data: "xyz",
7573
} as SendEventMessage,
7674
actualMethod: async (client: WebPubSubClient) =>
77-
await client.sendEvent("sendEvent", "xyz", "text", { ackId: 2 } as SendEventOptions),
75+
await client.sendEvent("sendEvent", "xyz", "text", { ackId: 2 }),
7876
},
7977
];
8078

sdk/web-pubsub/web-pubsub-client/test/client.messages.spec.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import {
1111
LeaveGroupMessage,
1212
LeaveGroupOptions,
1313
SendEventMessage,
14-
SendEventOptions,
1514
SendToGroupMessage,
16-
SendToGroupOptions,
1715
ServerDataMessage,
1816
} from "../src/models";
1917
import { WebPubSubClient } from "../src/webPubSubClient";
@@ -93,7 +91,7 @@ describe("WebPubSubClient", function () {
9391
.callsFake((_) => Promise.resolve());
9492
client.sendToGroup("groupName", "xyz", "text", {
9593
fireAndForget: true,
96-
} as SendToGroupOptions);
94+
});
9795
mock.verify();
9896
});
9997
});
@@ -114,7 +112,7 @@ describe("WebPubSubClient", function () {
114112
noEcho: false,
115113
} as SendToGroupMessage)
116114
.callsFake((_) => Promise.resolve());
117-
client.sendToGroup("groupName", "xyz", "text", { ackId: 2233 } as SendToGroupOptions);
115+
client.sendToGroup("groupName", "xyz", "text", { ackId: 2233 });
118116
mock.verify();
119117
});
120118
});
@@ -156,7 +154,7 @@ describe("WebPubSubClient", function () {
156154
noEcho: true,
157155
} as SendToGroupMessage)
158156
.callsFake((_) => Promise.resolve());
159-
client.sendToGroup("groupName", "xyz", "text", { noEcho: true } as SendToGroupOptions);
157+
client.sendToGroup("groupName", "xyz", "text", { noEcho: true });
160158
mock.verify();
161159
});
162160
});
@@ -196,7 +194,7 @@ describe("WebPubSubClient", function () {
196194
data: "xyz",
197195
} as SendEventMessage)
198196
.callsFake((_) => Promise.resolve());
199-
client.sendEvent("eventName", "xyz", "text", { ackId: 12345 } as SendEventOptions);
197+
client.sendEvent("eventName", "xyz", "text", { ackId: 12345 });
200198
mock.verify();
201199
});
202200
});
@@ -216,9 +214,8 @@ describe("WebPubSubClient", function () {
216214
} as SendEventMessage)
217215
.callsFake((_) => Promise.resolve());
218216
client.sendEvent("eventName", "xyz", "text", {
219-
ackId: 12345,
220217
fireAndForget: true,
221-
} as SendEventOptions);
218+
});
222219
mock.verify();
223220
});
224221
});

0 commit comments

Comments
 (0)