Skip to content

Commit

Permalink
[schemaregistry] Migrate schemaregistry projects to use snippets extr…
Browse files Browse the repository at this point in the history
…action (#33193)

### Packages impacted by this PR

- @azure/schema-registry
- @azure/schema-registry-avro
- @azure/schema-registry-json

### Issues associated with this PR

- #32416

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

Updates all projects under `schemaregistry` 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 26, 2025
1 parent 7d0e17b commit 8c67ad6
Show file tree
Hide file tree
Showing 33 changed files with 290 additions and 185 deletions.
8 changes: 4 additions & 4 deletions sdk/schemaregistry/schema-registry-avro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/event-hubs": "^6.0.0-beta.1",
"@azure/identity": "^4.6.0",
"@azure/identity": "^4.7.0",
"@rollup/plugin-inject": "^5.0.5",
"@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",
"buffer": "^6.0.3",
"dotenv": "^16.0.0",
"eslint": "^9.9.0",
"playwright": "^1.50.1",
"process": "^0.11.10",
"stream": "^0.0.3",
"typescript": "~5.7.2",
"vitest": "^3.0.3"
"vitest": "^3.0.6"
},
"type": "module",
"tshy": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default mergeConfig(
viteConfig,
defineConfig({
optimizeDeps: {
include: ["process", "buffer"],
include: ["buffer", "process"],
},
plugins: [browserMap(), inject({ process: "process", Buffer: ["buffer", "Buffer"] })],
test: {
Expand Down
82 changes: 37 additions & 45 deletions sdk/schemaregistry/schema-registry-json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,51 +59,45 @@ adapters for their message types.

### Serialize and deserialize an `@azure/event-hubs`'s `EventData`

```javascript
const { DefaultAzureCredential } = require("@azure/identity");
const { createEventDataAdapter } = require("@azure/event-hubs");
const { SchemaRegistryClient } = require("@azure/schema-registry");
const { JsonSchemaSerializer } = require("@azure/schema-registry-json");

async function main() {
const client = new SchemaRegistryClient(
"<fully qualified namespace>",
new DefaultAzureCredential(),
);
const serializer = new JsonSchemaSerializer(client, {
groupName: "<group>",
messageAdapter: createEventDataAdapter(),
});

// Example Json schema
const schema = JSON.stringify({
$schema: "http://json-schema.org/draft-04/schema#",
$id: "person",
title: "Student",
description: "A student in the class",
type: "object",
properties: {
name: {
type: "string",
description: "The name of the student",
},
},
required: ["name"],
});
```ts snippet:ReadmeSampleSerializeDeserialize
import { SchemaRegistryClient } from "@azure/schema-registry";
import { DefaultAzureCredential } from "@azure/identity";
import { JsonSchemaSerializer } from "@azure/schema-registry-json";
import { createEventDataAdapter } from "@azure/event-hubs";

const client = new SchemaRegistryClient(
"<fully qualified namespace>",
new DefaultAzureCredential(),
);
const serializer = new JsonSchemaSerializer(client, {
groupName: "<group>",
messageAdapter: createEventDataAdapter(),
});

// Example value that matches the Json schema above
const value = { name: "Bob" };
// Example Json schema
const schema = JSON.stringify({
$schema: "http://json-schema.org/draft-04/schema#",
$id: "person",
title: "Student",
description: "A student in the class",
type: "object",
properties: {
name: {
type: "string",
description: "The name of the student",
},
},
required: ["name"],
});

// Serialize value to a message
const message = await serializer.serialize(value, schema);
// Example value that matches the Json schema above
const value = { name: "Bob" };

// Deserialize a message to value
const deserializedValue = await serializer.deserialize(message);
}
// Serialize value to a message
const message = await serializer.serialize(value, schema);

main().catch((err) => {
console.error("The sample encountered an error:", err);
});
// Deserialize a message to value
const deserializedValue = await serializer.deserialize(message);
```

The serializer doesn't check whether the deserialized value matches the schema
Expand All @@ -123,8 +117,8 @@ 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`:

```javascript
const { setLogLevel } = require("@azure/logger");
```ts snippet:SetLogLevel
import { setLogLevel } from "@azure/logger";

setLogLevel("info");
```
Expand Down Expand Up @@ -162,8 +156,6 @@ learn more about how to build and test the code.

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



[azure_cli]: https://learn.microsoft.com/cli/azure
[azure_sub]: https://azure.microsoft.com/free/
[azure_portal]: https://portal.azure.com
Expand Down
23 changes: 12 additions & 11 deletions sdk/schemaregistry/schema-registry-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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 --no-test-proxy",
"unit-test:node": "dev-tool run test:vitest --no-test-proxy",
"update-snippets": "echo skipped"
"update-snippets": "dev-tool run update-snippets"
},
"files": [
"dist/",
Expand Down Expand Up @@ -66,7 +66,7 @@
}
},
"dependencies": {
"@azure/logger": "^1.0.0",
"@azure/logger": "^1.1.4",
"@azure/schema-registry": "^1.3.0",
"lru-cache": "^10.2.0",
"tslib": "^2.8.1"
Expand All @@ -76,25 +76,26 @@
"@azure-tools/test-recorder": "^4.1.0",
"@azure-tools/test-utils-vitest": "^1.0.0",
"@azure-tools/vite-plugin-browser-test-map": "^1.0.0",
"@azure/core-util": "^1.3.0",
"@azure/core-util": "^1.11.0",
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/event-hubs": "^6.0.0-beta.1",
"@azure/identity": "^4.5.0",
"@azure/identity": "^4.7.0",
"@rollup/plugin-inject": "^5.0.5",
"@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",
"ajv": "^8.17.1",
"buffer": "^6.0.3",
"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 @@ -107,8 +108,7 @@
"browser",
"react-native"
],
"selfLink": false,
"project": "./tsconfig.src.json"
"selfLink": false
},
"browser": "./dist/browser/index.js",
"exports": {
Expand All @@ -131,5 +131,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 @@ -14,9 +14,7 @@ import {
import { JsonSchemaSerializer } from "@azure/schema-registry-json";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// The fully qualified namespace for schema registry
const schemaRegistryFullyQualifiedNamespace =
process.env["SCHEMA_REGISTRY_ENDPOINT"] || "<endpoint>";
Expand Down Expand Up @@ -59,7 +57,7 @@ const schemaDescription: SchemaDescription = {
definition: schema,
};

export async function main() {
export async function main(): Promise<void> {
// Create a new client
const client = new SchemaRegistryClient(
schemaRegistryFullyQualifiedNamespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import { DeserializeOptions, JsonSchemaSerializer } from "@azure/schema-registry

import Ajv, { ValidateFunction } from "ajv";
// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// The fully qualified namespace for schema registry
const schemaRegistryFullyQualifiedNamespace =
process.env["SCHEMA_REGISTRY_ENDPOINT"] || "<endpoint>";
Expand Down Expand Up @@ -58,7 +56,7 @@ const schemaDescription: SchemaDescription = {
definition: schema,
};

export async function main() {
export async function main(): Promise<void> {
// Create a new client
const client = new SchemaRegistryClient(
schemaRegistryFullyQualifiedNamespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import { JsonSchemaSerializer } from "@azure/schema-registry-json";
import { EventHubBufferedProducerClient, createEventDataAdapter } from "@azure/event-hubs";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// The fully qualified namespace for schema registry
const schemaRegistryFullyQualifiedNamespace =
process.env["SCHEMA_REGISTRY_ENDPOINT"] || "<endpoint>";
Expand Down Expand Up @@ -63,7 +61,7 @@ async function handleError(): Promise<void> {
console.log("An error occured when sending a message");
}

export async function main() {
export async function main(): Promise<void> {
// Create a new client
const schemaRegistryClient = new SchemaRegistryClient(
schemaRegistryFullyQualifiedNamespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import {
} from "@azure/event-hubs";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// The fully qualified namespace for schema registry
const schemaRegistryFullyQualifiedNamespace =
process.env["SCHEMA_REGISTRY_ENDPOINT"] || "<endpoint>";
Expand Down Expand Up @@ -60,7 +58,7 @@ const schemaDescription: SchemaDescription = {
definition: schema,
};

export async function main() {
export async function main(): Promise<void> {
// Create a new client
const schemaRegistryClient = new SchemaRegistryClient(
schemaRegistryFullyQualifiedNamespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import { JsonSchemaSerializer } from "@azure/schema-registry-json";
import { EventHubProducerClient, createEventDataAdapter } from "@azure/event-hubs";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// The fully qualified namespace for schema registry
const schemaRegistryFullyQualifiedNamespace =
process.env["SCHEMA_REGISTRY_ENDPOINT"] || "<endpoint>";
Expand Down Expand Up @@ -59,7 +57,7 @@ const schemaDescription: SchemaDescription = {
definition: schema,
};

export async function main() {
export async function main(): Promise<void> {
// Create a new client
const schemaRegistryClient = new SchemaRegistryClient(
schemaRegistryFullyQualifiedNamespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import {
import { JsonSchemaSerializer } from "@azure/schema-registry-json";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// The fully qualified namespace for schema registry
const schemaRegistryFullyQualifiedNamespace =
process.env["SCHEMAREGISTRY_JSON_FULLY_QUALIFIED_NAMESPACE"] || "<namespace>";
Expand Down Expand Up @@ -59,7 +57,7 @@ const schemaDescription: SchemaDescription = {
definition: schema,
};

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import { DeserializeOptions, JsonSchemaSerializer } from "@azure/schema-registry

import Ajv, { ValidateFunction } from "ajv";
// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// The fully qualified namespace for schema registry
const schemaRegistryFullyQualifiedNamespace =
process.env["SCHEMAREGISTRY_JSON_FULLY_QUALIFIED_NAMESPACE"] || "<namespace>";
Expand Down Expand Up @@ -58,7 +56,7 @@ const schemaDescription: SchemaDescription = {
definition: schema,
};

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import { JsonSchemaSerializer } from "@azure/schema-registry-json";
import { EventHubBufferedProducerClient, createEventDataAdapter } from "@azure/event-hubs";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// The fully qualified namespace for schema registry
const schemaRegistryFullyQualifiedNamespace =
process.env["SCHEMAREGISTRY_JSON_FULLY_QUALIFIED_NAMESPACE"] || "<namespace>";
Expand Down Expand Up @@ -63,7 +61,7 @@ async function handleError(): Promise<void> {
console.log("An error occured when sending a message");
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import {
} from "@azure/event-hubs";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

import "dotenv/config";
// The fully qualified namespace for schema registry
const schemaRegistryFullyQualifiedNamespace =
process.env["SCHEMAREGISTRY_JSON_FULLY_QUALIFIED_NAMESPACE"] || "<namespace>";
Expand Down Expand Up @@ -61,7 +59,7 @@ const schemaDescription: SchemaDescription = {
definition: schema,
};

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

Expand Down
Loading

0 comments on commit 8c67ad6

Please sign in to comment.