Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[schemaregistry] Migrate schemaregistry projects to use snippets extraction #33193

Merged
merged 36 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4135fe2
Migration: Update package.json, tsconfig.json, and api-extractor.json
mpodwysocki Feb 25, 2025
7815e47
Migration: Update test config
mpodwysocki Feb 25, 2025
357eb17
Migration: Clean up files
mpodwysocki Feb 25, 2025
7037533
Migration: Apply codemod: "fixSourceFile"
mpodwysocki Feb 25, 2025
9fbf265
Migration: Apply codemod: "fixTestingImports"
mpodwysocki Feb 25, 2025
7639b88
Migration: Apply codemod: "replaceAssertIsRejected"
mpodwysocki Feb 25, 2025
708ddd7
Migration: Apply codemod: "replaceSinonStub"
mpodwysocki Feb 25, 2025
64578f8
Migration: Apply codemod: "addViHelper"
mpodwysocki Feb 25, 2025
f41cd1b
Migration: Apply codemod: "replaceSupportTracing"
mpodwysocki Feb 25, 2025
b7e018b
Migration: Apply codemod: "replaceTestUtils"
mpodwysocki Feb 25, 2025
15d8718
Migration: npm run format
mpodwysocki Feb 25, 2025
ab59b8c
Migration: Update package.json, tsconfig.json, and api-extractor.json
mpodwysocki Feb 25, 2025
9a11208
Migration: Update test config
mpodwysocki Feb 25, 2025
1812de4
Migration: Clean up files
mpodwysocki Feb 25, 2025
e4a77e6
Migration: Apply codemod: "fixSourceFile"
mpodwysocki Feb 25, 2025
8c6a249
Migration: Apply codemod: "fixTestingImports"
mpodwysocki Feb 25, 2025
fb14da3
Migration: Apply codemod: "replaceAssertIsRejected"
mpodwysocki Feb 25, 2025
92c05f8
Migration: Apply codemod: "replaceSinonStub"
mpodwysocki Feb 25, 2025
b671b61
Migration: Apply codemod: "addViHelper"
mpodwysocki Feb 25, 2025
f6195ff
Migration: Apply codemod: "replaceSupportTracing"
mpodwysocki Feb 25, 2025
77f542e
Migration: Apply codemod: "replaceTestUtils"
mpodwysocki Feb 25, 2025
89305da
Migration: npm run format
mpodwysocki Feb 25, 2025
58feafd
Migration: Update package.json, tsconfig.json, and api-extractor.json
mpodwysocki Feb 25, 2025
286563a
Migration: Update test config
mpodwysocki Feb 25, 2025
432adcd
Migration: Clean up files
mpodwysocki Feb 25, 2025
d9ace7d
Migration: Apply codemod: "fixSourceFile"
mpodwysocki Feb 25, 2025
9dd07c4
Migration: Apply codemod: "fixTestingImports"
mpodwysocki Feb 25, 2025
34b1af8
Migration: Apply codemod: "replaceAssertIsRejected"
mpodwysocki Feb 25, 2025
c9d245b
Migration: Apply codemod: "replaceSinonStub"
mpodwysocki Feb 25, 2025
c77f0a7
Migration: Apply codemod: "addViHelper"
mpodwysocki Feb 25, 2025
0190a90
Migration: Apply codemod: "replaceSupportTracing"
mpodwysocki Feb 25, 2025
cb3ba43
Migration: Apply codemod: "replaceTestUtils"
mpodwysocki Feb 25, 2025
6f9bafe
Migration: npm run format
mpodwysocki Feb 25, 2025
ec3b31f
[schemaregistry] Migrate schemaregistry projects to use snippets extr…
mpodwysocki Feb 25, 2025
b487ff0
[schemaregistry] Migrate schemaregistry projects to use snippets extr…
mpodwysocki Feb 25, 2025
12f6f89
[schemaregistry] Migrate schemaregistry projects to use snippets extr…
mpodwysocki Feb 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions sdk/schemaregistry/schema-registry-avro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
"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",
"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": "dev-tool run update-snippets"
},
"files": [
Expand Down 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 @@ -3,18 +3,11 @@

import { defineConfig, mergeConfig } from "vitest/config";
import viteConfig from "../../../vitest.browser.shared.config.ts";
import browserMap from "@azure-tools/vite-plugin-browser-test-map";
import inject from "@rollup/plugin-inject";

export default mergeConfig(
viteConfig,
defineConfig({
optimizeDeps: {
include: ["process", "buffer"],
},
plugins: [browserMap(), inject({ process: "process", Buffer: ["buffer", "Buffer"] })],
test: {
fileParallelism: false,
include: ["dist-test/browser/test/**/*.spec.js"],
testTimeout: 1200000,
hookTimeout: 1200000,
Expand Down
1 change: 0 additions & 1 deletion sdk/schemaregistry/schema-registry-avro/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default mergeConfig(
viteConfig,
defineConfig({
test: {
fileParallelism: false,
testTimeout: 1200000,
hookTimeout: 1200000,
},
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
27 changes: 14 additions & 13 deletions sdk/schemaregistry/schema-registry-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
"test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
"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"
"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": "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
Loading
Loading