Skip to content

Commit

Permalink
[synapse] Migrate synapse client projects to use snippets extraction (#…
Browse files Browse the repository at this point in the history
…33177)

### Packages impacted by this PR

- @azure-rest/synapse-access-control
- @azure/synapse-access-control
- @azure/synapse-artifacts
- @azure/synapse-managed-private-endpoints
- @azure/synapse-monitoring
- @azure/synapse-spark

### Issues associated with this PR

- #32416

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

Updates all client projects under `synapse` 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 b2d7cec commit 96b8ed3
Show file tree
Hide file tree
Showing 56 changed files with 406 additions and 238 deletions.
27 changes: 11 additions & 16 deletions sdk/synapse/synapse-access-control-rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,20 @@ See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUP

## Examples

```ts
import AccessControl, { paginate } from "@azure-rest/synapse-access-control";
```ts snippet:ReadmeSampleCreateClient_Node
import AccessControl, { isUnexpected, paginate } from "@azure-rest/synapse-access-control";
import { DefaultAzureCredential } from "@azure/identity";

export async function main(): Promise<void> {
const client = AccessControl("<endpoint>", new DefaultAzureCredential());
const initialResponse = await client.path("/roleAssignments").get();
const client = AccessControl("<endpoint>", new DefaultAzureCredential());

if (initialResponse.status !== "200") {
throw initialResponse.body.error;
}

const assignments = paginate(client, initialResponse);
const initialResponse = await client.path("/roleAssignments").get();
if (isUnexpected(initialResponse)) {
throw initialResponse.body.error;
}

for await (const assignment of assignments) {
console.log(assignment.id);
}
const assignments = paginate(client, initialResponse);
for await (const assignment of assignments) {
console.log(`Role Assignment ID: ${assignment.id}`);
}
```

Expand All @@ -51,7 +48,7 @@ export async function main(): Promise<void> {

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 @@ -65,7 +62,5 @@ In the future, you'll find additional code samples here.

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.



[synapse_product_documentation]: https://learn.microsoft.com/rest/api/synapse/data-plane/role-assignments/create-role-assignment
[rest_client]: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md
23 changes: 12 additions & 11 deletions sdk/synapse/synapse-access-control-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"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",
"tslib": "^2.8.1"
},
"//metadata": {
Expand Down Expand Up @@ -37,22 +37,22 @@
"module": "./dist/esm/index.js",
"types": "./dist/commonjs/index.d.ts",
"devDependencies": {
"@azure/logger": "^1.0.0",
"@azure-tools/test-credential": "^2.0.0",
"@azure-tools/test-recorder": "^4.1.0",
"@azure-tools/test-utils-vitest": "^1.0.0",
"@azure/core-util": "^1.11.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",
"@azure/logger": "^1.1.4",
"@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"
},
"bugs": {
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
Expand Down Expand Up @@ -82,7 +82,7 @@
"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"
},
"//sampleConfiguration": {
"productName": "Azure Synapse Access Control Rest",
Expand All @@ -99,6 +99,7 @@
"sideEffects": false,
"type": "module",
"tshy": {
"project": "./tsconfig.src.json",
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
Expand All @@ -111,8 +112,7 @@
"browser",
"react-native"
],
"selfLink": false,
"project": "./tsconfig.src.json"
"selfLink": false
},
"exports": {
"./package.json": "./package.json",
Expand All @@ -134,5 +134,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 @@ -11,10 +11,7 @@
import AccessControl, { isUnexpected } from "@azure-rest/synapse-access-control";
import { DefaultAzureCredential } from "@azure/identity";
import { randomUUID } from "@azure/core-util";
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,13 +10,10 @@

import AccessControl, { isUnexpected, paginate } from "@azure-rest/synapse-access-control";
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> {
const client = AccessControl(endpoint, new DefaultAzureCredential());
const initialResponse = await client.path("/roleAssignments").get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
import AccessControl, { isUnexpected } from "@azure-rest/synapse-access-control";
import { DefaultAzureCredential } from "@azure/identity";
import { v4 } from "uuid";
import dotenv from "dotenv";

dotenv.config();

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

async function main() {
async function main(): Promise<void> {
const client = AccessControl(endpoint, new DefaultAzureCredential());
const roleAssignmentId = v4();
// Id of the principal to give aassing the tole to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@

import AccessControl, { isUnexpected, paginate } from "@azure-rest/synapse-access-control";
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> {
const client = AccessControl(endpoint, new DefaultAzureCredential());
const initialResponse = await client.path("/roleAssignments").get();

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import "./env.js";

import type { AccessControlRestClient } from "../../../src/index.js";
import AccessControlClient from "../../../src/index.js";
import type { Recorder } from "@azure-tools/test-recorder";
Expand Down Expand Up @@ -41,8 +39,7 @@ export async function createClient(

export function getWorkspaceName(): string {
const url: string = env.ENDPOINT ?? "";
// eslint-disable-next-line no-useless-escape
const matches = url.match(/^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/?\n]+)/) ?? [];
const matches = url.match(/^(?:https?:\/\/)?(?:[^@/\n]+@)?(?:www\.)?([^:/?\n]+)/) ?? [];

if (matches.length < 2) {
throw new Error(`Could not extract workspace name from the environment ENDPOINT`);
Expand Down
27 changes: 27 additions & 0 deletions sdk/synapse/synapse-access-control-rest/test/snippets.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import AccessControl, { isUnexpected, paginate } from "../src/index.js";
import { DefaultAzureCredential, InteractiveBrowserCredential } from "@azure/identity";
import { setLogLevel } from "@azure/logger";
import { describe, it } from "vitest";

describe("snippets", () => {
it("ReadmeSampleCreateClient_Node", async () => {
const client = AccessControl("<endpoint>", new DefaultAzureCredential());
// @ts-preserve-whitespace
const initialResponse = await client.path("/roleAssignments").get();
if (isUnexpected(initialResponse)) {
throw initialResponse.body.error;
}
// @ts-preserve-whitespace
const assignments = paginate(client, initialResponse);
for await (const assignment of assignments) {
console.log(`Role Assignment ID: ${assignment.id}`);
}
});

it("SetLogLevel", async () => {
setLogLevel("info");
});
});
12 changes: 9 additions & 3 deletions sdk/synapse/synapse-access-control-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/synapse/synapse-access-control-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/synapse/synapse-access-control-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);
25 changes: 10 additions & 15 deletions sdk/synapse/synapse-access-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,30 @@ See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUP

## Examples

```ts
```ts snippet:ReadmeSampleCreateClient_Node
import { AccessControlClient } from "@azure/synapse-access-control";
import { DefaultAzureCredential } from "@azure/identity";

export async function main(): Promise<void> {
const credential = new DefaultAzureCredential();

const client = new AccessControlClient(
credential,
"https://mysynapse.dev.azuresynapse.net"
);
const list = await client.roleDefinitions.listRoleDefinitions();
for await (const item of list) {
console.log("item:", item);
}
const client = new AccessControlClient(
new DefaultAzureCredential(),
"https://mysynapse.dev.azuresynapse.net",
);

const roleDefinitions = await client.roleDefinitions.listRoleDefinitions();
for await (const roleDefinition of roleDefinitions) {
console.log(`Role Definition ID: ${roleDefinition.id}`);
}
```

## Related projects

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



## Troubleshooting

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 Down
20 changes: 11 additions & 9 deletions sdk/synapse/synapse-access-control/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@azure/core-auth": "^1.9.0",
"@azure/core-client": "^1.9.2",
"@azure/core-paging": "^1.6.2",
"@azure/core-rest-pipeline": "^1.18.0",
"@azure/core-rest-pipeline": "^1.19.0",
"@azure/core-tracing": "^1.2.0",
"tslib": "^2.8.1"
},
Expand Down Expand Up @@ -48,14 +48,15 @@
"@azure-tools/test-utils-vitest": "^1.0.0",
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/logger": "^1.1.4",
"@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"
},
"bugs": {
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
Expand Down Expand Up @@ -85,12 +86,13 @@
"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": true,
"type": "module",
"tshy": {
"project": "./tsconfig.src.json",
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
Expand All @@ -103,8 +105,7 @@
"browser",
"react-native"
],
"selfLink": false,
"project": "./tsconfig.src.json"
"selfLink": false
},
"exports": {
"./package.json": "./package.json",
Expand All @@ -126,5 +127,6 @@
"default": "./dist/commonjs/index.js"
}
}
}
},
"react-native": "./dist/react-native/index.js"
}

This file was deleted.

Loading

0 comments on commit 96b8ed3

Please sign in to comment.