Skip to content

Commit 649331f

Browse files
authored
[web-pubsub] Migrate web-pubsub projects to use snippets extraction (#33188)
### Packages impacted by this PR - @azure/web-pubsub - @azure/web-pubsub-client - @azure/web-pubsub-client-protobuf - @azure/web-pubsub-express ### Issues associated with this PR - #32416 ### Describe the problem that is addressed by this PR Updates all projects under `web-pubsub` to use snippets extraction. ### 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 9d4b052 commit 649331f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1084
-352
lines changed

common/config/rush/pnpm-lock.yaml

+14-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/web-pubsub/web-pubsub-client-protobuf/README.md

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# Web PubSub client protobuf protocol library for JavaScript
22

3-
[Azure Web PubSub](https://aka.ms/awps/doc) is a cloud service that helps developers easily build real-time features in web applications with publish-subscribe patterns at scale.
3+
[Azure Web PubSub](https://aka.ms/awps/doc) is a cloud service that helps developers easily build real-time features in web applications with publish-subscribe patterns at scale.
44

55
You can use this library to add protobuf subprotocols including `protobuf.reliable.webpubsub.azure.v1` and `protobuf.webpubsub.azure.v1` support to `@azure/web-pubsub-client` library.
66

7-
87
## Getting started
98

109
### Currently supported environments
@@ -24,39 +23,55 @@ npm install @azure/web-pubsub-client-protobuf
2423

2524
### 2. Use Protobuf protocols
2625

27-
```javascript
28-
const client = new WebPubSubClient("client-access-url", { protocol: WebPubSubProtobufReliableProtocol() });
26+
```ts snippet:ReadmeSampleCreateClient
27+
import { WebPubSubClient } from "@azure/web-pubsub-client";
28+
import { WebPubSubProtobufReliableProtocol } from "@azure/web-pubsub-client-protobuf";
29+
30+
const client = new WebPubSubClient("client-access-url", {
31+
protocol: WebPubSubProtobufReliableProtocol(),
32+
});
2933
```
3034

3135
## Troubleshooting
3236

33-
- ### Enable logs
37+
### Enable logs
3438

35-
You can set the following environment variable to get the debug logs when using this library.
39+
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`.
3640

3741
```bash
3842
export AZURE_LOG_LEVEL=verbose
3943
```
4044

45+
Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
46+
47+
```ts snippet:SetLogLevel
48+
import { setLogLevel } from "@azure/logger";
49+
50+
setLogLevel("info");
51+
```
52+
4153
For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
4254

4355
- ### Live Trace
4456

4557
Use [Live Trace tool][live_trace] from Web PubSub portal to view the live traffic.
58+
4659
---
60+
4761
## Additional resources
62+
4863
- Learn more about client permission, see [permissions](https://learn.microsoft.com/azure/azure-web-pubsub/reference-json-reliable-webpubsub-subprotocol#permissions)
4964

50-
- [Server SDK - JavaScript documentation](https://aka.ms/awps/sdk/js)
65+
- [Server SDK - JavaScript documentation](https://aka.ms/awps/sdk/js)
5166
- [Product documentation](https://aka.ms/awps/doc)
5267
- [Samples][samples_ref]
5368

5469
---
70+
5571
## Contributing
5672

5773
If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code.
5874

59-
6075
[azure_sub]: https://azure.microsoft.com/free/
6176
[samples_ref]: https://github.com/Azure/azure-webpubsub/tree/main/samples/javascript/
6277
[create_instance]: https://learn.microsoft.com/azure/azure-web-pubsub/howto-develop-create-instance

sdk/web-pubsub/web-pubsub-client-protobuf/api-extractor.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dtsRollup": {
1212
"enabled": true,
1313
"untrimmedFilePath": "",
14-
"publicTrimmedFilePath": "./dist/web-pubsub-client-protobuf.d.ts"
14+
"publicTrimmedFilePath": "dist/web-pubsub-client-protobuf.d.ts"
1515
},
1616
"messages": {
1717
"tsdocMessageReporting": {

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

+26-15
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
"type": "module",
77
"main": "./dist/commonjs/index.js",
88
"module": "./dist/esm/index.js",
9-
"browser": {
10-
"buffer": "buffer",
11-
"default": "dist/browser/index.js"
12-
},
9+
"browser": "./dist/browser/index.js",
1310
"types": "./dist/commonjs/index.d.ts",
1411
"scripts": {
1512
"build": "npm run clean && npm run build-protobuf && dev-tool run build-package && npm run copy-files && dev-tool run extract-api",
@@ -39,13 +36,11 @@
3936
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
4037
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
4138
"unit-test:browser": "echo skipped",
42-
"unit-test:node": "dev-tool run test:vitest --no-test-proxy",
43-
"update-snippets": "echo skipped"
39+
"unit-test:node": "dev-tool run test:vitest",
40+
"update-snippets": "dev-tool run update-snippets"
4441
},
4542
"files": [
4643
"dist/",
47-
"types/web-pubsub-client-protobuf.d.ts",
48-
"types/web-pubsub-client-protobuf.d.ts.map",
4944
"README.md",
5045
"LICENSE"
5146
],
@@ -65,25 +60,28 @@
6560
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/web-pubsub/web-pubsub-client/README.md",
6661
"sideEffects": false,
6762
"dependencies": {
68-
"@azure/logger": "^1.0.0",
63+
"@azure/logger": "^1.1.4",
6964
"@azure/web-pubsub-client": "1.0.0-beta.2",
7065
"long": "^5.3.1",
7166
"protobufjs": "^7.4.0",
72-
"tslib": "^2.6.2"
67+
"tslib": "^2.8.1"
7368
},
7469
"devDependencies": {
70+
"@azure-tools/test-utils-vitest": "^1.0.0",
7571
"@azure/dev-tool": "^1.0.0",
7672
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
7773
"@azure/web-pubsub": "^1.1.0",
7874
"@types/node": "^18.0.0",
79-
"@vitest/coverage-istanbul": "^3.0.3",
75+
"@vitest/browser": "^3.0.6",
76+
"@vitest/coverage-istanbul": "^3.0.6",
8077
"cpy-cli": "^5.0.0",
8178
"dotenv": "^16.0.0",
8279
"eslint": "^9.9.0",
8380
"move-file-cli": "^3.0.0",
81+
"playwright": "^1.50.1",
8482
"protobufjs-cli": "^1.1.3",
8583
"typescript": "~5.7.2",
86-
"vitest": "^3.0.3"
84+
"vitest": "^3.0.6"
8785
},
8886
"//sampleConfiguration": {
8987
"productName": "Azure Web PubSub Client",
@@ -92,6 +90,7 @@
9290
]
9391
},
9492
"tshy": {
93+
"project": "./tsconfig.src.json",
9594
"exports": {
9695
"./package.json": "./package.json",
9796
".": "./src/index.ts"
@@ -100,12 +99,23 @@
10099
"esm",
101100
"commonjs"
102101
],
103-
"selfLink": false,
104-
"project": "./tsconfig.src.json"
102+
"esmDialects": [
103+
"browser",
104+
"react-native"
105+
],
106+
"selfLink": false
105107
},
106108
"exports": {
107109
"./package.json": "./package.json",
108110
".": {
111+
"browser": {
112+
"types": "./dist/browser/index.d.ts",
113+
"default": "./dist/browser/index.js"
114+
},
115+
"react-native": {
116+
"types": "./dist/react-native/index.d.ts",
117+
"default": "./dist/react-native/index.js"
118+
},
109119
"import": {
110120
"types": "./dist/esm/index.d.ts",
111121
"default": "./dist/esm/index.js"
@@ -115,5 +125,6 @@
115125
"default": "./dist/commonjs/index.js"
116126
}
117127
}
118-
}
128+
},
129+
"react-native": "./dist/react-native/index.js"
119130
}

sdk/web-pubsub/web-pubsub-client-protobuf/samples-dev/basicusage.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
* @summary Basic usage of web-pubsub-client
66
*/
77

8-
import {
9-
WebPubSubClient,
8+
import type {
109
WebPubSubClientCredential,
1110
SendToGroupOptions,
1211
GetClientAccessUrlOptions,
1312
WebPubSubClientOptions,
1413
} from "@azure/web-pubsub-client";
14+
import { WebPubSubClient } from "@azure/web-pubsub-client";
1515
import { WebPubSubProtobufReliableProtocol } from "@azure/web-pubsub-client-protobuf";
1616
import { WebPubSubServiceClient } from "@azure/web-pubsub";
1717
import "dotenv/config";

sdk/web-pubsub/web-pubsub-client-protobuf/samples/v1-beta/typescript/src/basicusage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const fetchClientAccessUrl = async (_: GetClientAccessUrlOptions) => {
2929
).url;
3030
};
3131

32-
async function main() {
32+
async function main(): Promise<void> {
3333
let client = new WebPubSubClient(
3434
{
3535
getClientAccessUrl: fetchClientAccessUrl,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { setLogLevel } from "@azure/logger";
5+
import { WebPubSubClient } from "@azure/web-pubsub-client";
6+
import { describe, it } from "vitest";
7+
import { WebPubSubProtobufReliableProtocol } from "../src/index.js";
8+
9+
describe("snippets", () => {
10+
it("ReadmeSampleCreateClient", async () => {
11+
const client = new WebPubSubClient("client-access-url", {
12+
protocol: WebPubSubProtobufReliableProtocol(),
13+
});
14+
});
15+
16+
it("SetLogLevel", async () => {
17+
setLogLevel("info");
18+
});
19+
});
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{
22
"references": [
3-
{ "path": "./tsconfig.src.json" },
4-
{ "path": "./tsconfig.samples.json" },
5-
{ "path": "./tsconfig.test.json" }
3+
{
4+
"path": "./tsconfig.src.json"
5+
},
6+
{
7+
"path": "./tsconfig.samples.json"
8+
},
9+
{
10+
"path": "./tsconfig.test.json"
11+
}
612
]
713
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { defineConfig, mergeConfig } from "vitest/config";
5+
import viteConfig from "../../../vitest.browser.shared.config.ts";
6+
7+
export default mergeConfig(
8+
viteConfig,
9+
defineConfig({
10+
test: {
11+
include: ["dist-test/browser/test/**/*.spec.js"],
12+
testTimeout: 1200000,
13+
hookTimeout: 1200000,
14+
},
15+
}),
16+
);

sdk/web-pubsub/web-pubsub-client-protobuf/vitest.esm.config.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,4 @@ import { mergeConfig } from "vitest/config";
55
import vitestConfig from "./vitest.config.ts";
66
import vitestEsmConfig from "../../../vitest.esm.shared.config.ts";
77

8-
export default mergeConfig(
9-
vitestConfig,
10-
vitestEsmConfig
11-
);
8+
export default mergeConfig(vitestConfig, vitestEsmConfig);

0 commit comments

Comments
 (0)