Skip to content

Commit

Permalink
[purview] Migrate purview REST projects to use snippets extraction (#…
Browse files Browse the repository at this point in the history
…33174)

### Packages impacted by this PR

- @azure-rest/purview-administration
- @azure-rest/purview-catalog
- @azure-rest/purview-datamap
- @azure-rest/purview-scanning
- @azure-rest/purview-sharing
- @azure-rest/purview-workflow

### Issues associated with this PR

- #32416

### Describe the problem that is addressed by this PR

Updates all REST projects under `purview` 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)
  • Loading branch information
mpodwysocki authored Feb 24, 2025
1 parent a702a44 commit 7c81323
Show file tree
Hide file tree
Showing 56 changed files with 817 additions and 372 deletions.
78 changes: 52 additions & 26 deletions sdk/purview/purview-administration-rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,16 @@ AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET

Use the returned token credential to authenticate the client:

```typescript
import {
PurviewAccountClient,
PurviewMetadataPoliciesClient,
} from "@azure-rest/purview-administration";
```ts snippet:ReadmeSampleCreateClient_Node
import { PurviewAccount, PurviewMetadataPolicies } from "@azure-rest/purview-administration";
import { DefaultAzureCredential } from "@azure/identity";
const accountClient = PurviewAccountClient(

const accountClient = PurviewAccount.createClient(
"https://<my-account-name>.purview.azure.com",
new DefaultAzureCredential(),
);

const metadataClient = PurviewAccountClient(
const metadataClient = PurviewMetadataPolicies.createClient(
"https://<my-account-name>.purview.azure.com",
new DefaultAzureCredential(),
);
Expand All @@ -78,33 +76,63 @@ This client is one of our REST clients. We highly recommend you read how to use

## Examples

The following section shows you how to initialize and authenticate your client, then get all of your type-defs.
The following section shows you how to initialize and authenticate your client and perform various operations.

- Get A List of Collections

- [Get A List of Collections](#get-a-list-of-collections "Get A List of Collections")
Gets a list of collections in the account.

```typescript
import { PurviewAccountClient } from "@azure-rest/purview-administration";
```ts snippet:ReadmeSampleGetCollections
import { PurviewAccount } from "@azure-rest/purview-administration";
import { DefaultAzureCredential } from "@azure/identity";
import dotenv from "dotenv";

dotenv.config();
const accountClient = PurviewAccount.createClient(
"https://<my-account-name>.purview.azure.com",
new DefaultAzureCredential(),
);

const endpoint = process.env["ENDPOINT"] || "";
const response = await accountClient.path("/collections").get();

async function main() {
console.log("== List collections sample ==");
const client = PurviewAccountClient(endpoint, new DefaultAzureCredential());
if (PurviewAccount.UnexpectedHelper.isUnexpected(response)) {
throw response.body.error;
}

const response = await client.path("/collections").get();
const paginated = PurviewAccount.PaginateHelper.paginate(accountClient, response);
for await (const collection of paginated) {
console.log(
`Collection name: ${collection.name}\tCollection description: ${collection.description}`,
);
}
```

if (response.status !== "200") {
console.log(`GET "/collections" failed with ${response.status}`);
}
- Get A List of Metadata Policies

Gets a list of metadata policies in the account.

```ts snippet:ReadmeSampleGetMetadataPolicies
import { PurviewMetadataPolicies } from "@azure-rest/purview-administration";
import { DefaultAzureCredential } from "@azure/identity";

const metadataClient = PurviewMetadataPolicies.createClient(
"https://<my-account-name>.purview.azure.com",
new DefaultAzureCredential(),
);

const response = await metadataClient.path("/metadataPolicies").get();

console.log(response.body);
if (PurviewMetadataPolicies.UnexpectedHelper.isUnexpected(response)) {
throw response.body.error;
}

main().catch(console.error);
const policies = PurviewMetadataPolicies.PaginateHelper.paginate(metadataClient, response);

for await (const policy of policies) {
if (Array.isArray(policy)) {
console.error("Unexpected array:", policy);
} else {
console.log(`Policy name: ${policy.name}`);
}
}
```

## Troubleshooting
Expand All @@ -113,7 +141,7 @@ main().catch(console.error);

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`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:

```ts
```ts snippet:SetLogLevel
import { setLogLevel } from "@azure/logger";

setLogLevel("info");
Expand All @@ -131,8 +159,6 @@ If you'd like to contribute to this library, please read the [contributing guide

- [Microsoft Azure SDK for JavaScript](https://github.com/Azure/azure-sdk-for-js)



[account_product_documentation]: https://azure.microsoft.com/services/purview/
[rest_client]: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md
[source_code]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/purview/purview-catalog-rest
Expand Down
21 changes: 11 additions & 10 deletions sdk/purview/purview-administration-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
"unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
"unit-test:node": "dev-tool run test:vitest",
"update-snippets": "echo skipped"
"update-snippets": "dev-tool run update-snippets"
},
"sideEffects": false,
"autoPublish": false,
"dependencies": {
"@azure-rest/core-client": "^2.3.1",
"@azure/core-auth": "^1.9.0",
"@azure/core-rest-pipeline": "^1.18.0",
"@azure/core-rest-pipeline": "^1.19.0",
"@azure/logger": "^1.1.4",
"tslib": "^2.8.1"
},
Expand All @@ -90,18 +90,19 @@
"@azure-tools/test-utils-vitest": "^1.0.0",
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/identity": "^4.0.1",
"@azure/identity": "^4.7.0",
"@types/node": "^18.0.0",
"@vitest/browser": "^3.0.3",
"@vitest/coverage-istanbul": "^3.0.3",
"@vitest/browser": "^3.0.6",
"@vitest/coverage-istanbul": "^3.0.6",
"dotenv": "^16.0.0",
"eslint": "^9.9.0",
"playwright": "^1.49.0",
"playwright": "^1.50.1",
"typescript": "~5.7.2",
"vitest": "^3.0.3"
"vitest": "^3.0.6"
},
"type": "module",
"tshy": {
"project": "./tsconfig.src.json",
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
Expand All @@ -114,8 +115,7 @@
"browser",
"react-native"
],
"selfLink": false,
"project": "./tsconfig.src.json"
"selfLink": false
},
"browser": "./dist/browser/index.js",
"exports": {
Expand All @@ -138,5 +138,6 @@
"default": "./dist/commonjs/index.js"
}
}
}
},
"react-native": "./dist/react-native/index.js"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

import { PurviewAccount } from "@azure-rest/purview-administration";
import { DefaultAzureCredential } from "@azure/identity";
import dotenv from "dotenv";

dotenv.config();

import "dotenv/config";
const endpoint = process.env["ENDPOINT"] || "";

async function main(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

import { PurviewMetadataPolicies } from "@azure-rest/purview-administration";
import { DefaultAzureCredential } from "@azure/identity";
import dotenv from "dotenv";

dotenv.config();

import "dotenv/config";
const endpoint = process.env["ENDPOINT"] || "";

async function main(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@

import { PurviewAccount } from "@azure-rest/purview-administration";
import { DefaultAzureCredential } from "@azure/identity";
import dotenv from "dotenv";

dotenv.config();

import "dotenv/config";
const endpoint = process.env["ENDPOINT"] || "";

async function main() {
async function main(): Promise<void> {
console.log("== List collections sample ==");
const client = PurviewAccount.createClient(endpoint, new DefaultAzureCredential());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ import {
PurviewMetadataPolicies
} from "@azure-rest/purview-administration";
import { DefaultAzureCredential } from "@azure/identity";
import dotenv from "dotenv";

dotenv.config();

import "dotenv/config";
const endpoint = process.env["ENDPOINT"] || "";

async function main() {
async function main(): Promise<void> {
console.log("== List metadata policies sample ==");
const client = PurviewMetadataPolicies.createClient(endpoint, new DefaultAzureCredential());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { PurviewMetadataPolicies } from "../../src/index.js";
import { Recorder } from "@azure-tools/test-recorder";
import { createMetadataClient } from "./utils/recordedClient.js";
import { describe, it, assert, beforeEach, afterEach } from "vitest";
import { MetadataPolicyListOutput } from "../../src/metadataPolicies/outputModels.js";
import type { MetadataPolicyListOutput } from "../../src/metadataPolicies/outputModels.js";

describe("List Metadata", () => {
let recorder: Recorder;
Expand Down
68 changes: 68 additions & 0 deletions sdk/purview/purview-administration-rest/test/snippets.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { PurviewAccount, PurviewMetadataPolicies } from "../src/index.js";
import { DefaultAzureCredential } from "@azure/identity";
import { setLogLevel } from "@azure/logger";
import { describe, it } from "vitest";

describe("snippets", () => {
it("ReadmeSampleCreateClient_Node", async () => {
const accountClient = PurviewAccount.createClient(
"https://<my-account-name>.purview.azure.com",
new DefaultAzureCredential(),
);
// @ts-preserve-whitespace
const metadataClient = PurviewMetadataPolicies.createClient(
"https://<my-account-name>.purview.azure.com",
new DefaultAzureCredential(),
);
});

it("ReadmeSampleGetCollections", async () => {
const accountClient = PurviewAccount.createClient(
"https://<my-account-name>.purview.azure.com",
new DefaultAzureCredential(),
);
// @ts-preserve-whitespace
const response = await accountClient.path("/collections").get();
// @ts-preserve-whitespace
if (PurviewAccount.UnexpectedHelper.isUnexpected(response)) {
throw response.body.error;
}
// @ts-preserve-whitespace
const paginated = PurviewAccount.PaginateHelper.paginate(accountClient, response);
for await (const collection of paginated) {
console.log(
`Collection name: ${collection.name}\tCollection description: ${collection.description}`,
);
}
});

it("ReadmeSampleGetMetadataPolicies", async () => {
const metadataClient = PurviewMetadataPolicies.createClient(
"https://<my-account-name>.purview.azure.com",
new DefaultAzureCredential(),
);
// @ts-preserve-whitespace
const response = await metadataClient.path("/metadataPolicies").get();
// @ts-preserve-whitespace
if (PurviewMetadataPolicies.UnexpectedHelper.isUnexpected(response)) {
throw response.body.error;
}
// @ts-preserve-whitespace
const policies = PurviewMetadataPolicies.PaginateHelper.paginate(metadataClient, response);
// @ts-preserve-whitespace
for await (const policy of policies) {
if (Array.isArray(policy)) {
console.error("Unexpected array:", policy);
} else {
console.log(`Policy name: ${policy.name}`);
}
}
});

it("SetLogLevel", async () => {
setLogLevel("info");
});
});
12 changes: 9 additions & 3 deletions sdk/purview/purview-administration-rest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
{
"path": "./tsconfig.src.json"
},
{
"path": "./tsconfig.samples.json"
},
{
"path": "./tsconfig.test.json"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default mergeConfig(
defineConfig({
test: {
include: ["dist-test/browser/test/**/*.spec.js"],
hookTimeout: 500000,
testTImeout: 500000,
testTimeout: 1200000,
hookTimeout: 1200000,
},
}),
);
4 changes: 2 additions & 2 deletions sdk/purview/purview-administration-rest/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default mergeConfig(
viteConfig,
defineConfig({
test: {
hookTimeout: 500000,
testTImeout: 500000,
testTimeout: 1200000,
hookTimeout: 1200000,
},
}),
);
5 changes: 1 addition & 4 deletions sdk/purview/purview-administration-rest/vitest.esm.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ import { mergeConfig } from "vitest/config";
import vitestConfig from "./vitest.config.ts";
import vitestEsmConfig from "../../../vitest.esm.shared.config.ts";

export default mergeConfig(
vitestConfig,
vitestEsmConfig
);
export default mergeConfig(vitestConfig, vitestEsmConfig);
Loading

0 comments on commit 7c81323

Please sign in to comment.