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

Fix UserAgentInfo and Constantpaths issues #2888

Merged
merged 24 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
7 changes: 6 additions & 1 deletion packages/rlc-common/src/metadata/buildPackageFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import { getRelativePartFromSrcPath } from "../helpers/pathUtils.js";
interface PackageFileOptions {
exports?: Record<string, any>;
dependencies?: Record<string, string>;
metadata?: Record<string, any>;
}

export function buildPackageFile(
model: RLCModel,
{ exports, dependencies }: PackageFileOptions = {}
{ exports, dependencies, metadata }: PackageFileOptions = {}
) {
const config: PackageCommonInfoConfig = {
description: getDescription(model),
Expand Down Expand Up @@ -57,6 +58,10 @@ export function buildPackageFile(
packageInfo = buildAzureStandalonePackage(extendedConfig);
}

if (model.options?.moduleKind == "esm" && model.options.isModularLibrary) {
packageInfo["//metadata"] = metadata;
}

const project = new Project();
const filePath = "package.json";

Expand Down
3 changes: 2 additions & 1 deletion packages/rlc-common/test/integration/mockHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type TestModelConfig = {
hasLro?: boolean;
hasPaging?: boolean;
isModularLibrary?: boolean;
azureSdkForJs?: boolean;
};

export function createMockModel(config: TestModelConfig = {}): RLCModel {
Expand Down Expand Up @@ -48,7 +49,7 @@ export function createMockModel(config: TestModelConfig = {}): RLCModel {
generateSample: config.withSamples ?? false,
moduleKind: config.moduleKind,
sourceFrom: config.source ?? "TypeSpec",
isModularLibrary: config.isModularLibrary ?? false
isModularLibrary: config.isModularLibrary ?? false,
},
helperDetails: {
hasPaging: config.hasPaging ?? false,
Expand Down
34 changes: 34 additions & 0 deletions packages/rlc-common/test/integration/packageJson.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,40 @@ describe("Package file generation", () => {
'dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore "src/**/*.{ts,cts,mts}" "test/**/*.{ts,cts,mts}" "*.{js,cjs,mjs,json}" '
);
});

it("[esm] should have constantPaths in typespec modular", () => {
kazrael2119 marked this conversation as resolved.
Show resolved Hide resolved
const model = createMockModel({
moduleKind: "esm",
isModularLibrary: true
});

const metadataOption = {
metadata: {
"constantPaths": [
{
"path": "src/chatCompletions/api/chatCompletionsContext.ts",
"prefix": "userAgentInfo"
},
]
}
}

const packageFileContent = buildPackageFile(model, metadataOption);
const packageFile = JSON.parse(packageFileContent?.content ?? "{}");

expect(packageFile).to.have.property("//metadata");
});

it("[esm] should have constantPaths in typespec rlc", () => {
const model = createMockModel({
...baseConfig,
moduleKind: "esm",
});
const packageFileContent = buildPackageFile(model);
const packageFile = JSON.parse(packageFileContent?.content ?? "{}");

expect(packageFile).to.have.property("//metadata");
});
});

describe("Azure flavor for standalone library", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@
"test": "npm run clean && tshy && npm run unit-test:node && npm run unit-test:browser && npm run integration-test",
"build": "npm run clean && tshy && npm run extract-api"
},
"//metadata": {
"constantPaths": [
{
"path": "src/api/networkAnalyticsContext.ts",
"prefix": "userAgentInfo"
}
]
},
"exports": {
"./package.json": "./package.json",
".": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ export function createNetworkAnalytics(
options.endpoint ?? options.baseUrl ?? `https://management.azure.com`;

const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix;
const userAgentInfo = `azsdk-js-arm-networkanalytics/1.0.0-beta.1`;
const userAgentPrefix = prefixFromOptions
? `${prefixFromOptions} azsdk-js-api`
: "azsdk-js-api";
? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}`
: `azsdk-js-api ${userAgentInfo}`;
const { apiVersion: _, ...updatedOptions } = {
...options,
userAgentOptions: { userAgentPrefix },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@
"test": "npm run clean && tshy && npm run unit-test:node && npm run unit-test:browser && npm run integration-test",
"build": "npm run clean && tshy && npm run extract-api"
},
"//metadata": {
"constantPaths": [
{
"path": "src/api/anomalyDetectorContext.ts",
"prefix": "userAgentInfo"
}
]
},
"exports": {
"./package.json": "./package.json",
".": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ export function createAnomalyDetector(
`${endpointParam}/anomalydetector/${apiVersion}`;

const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix;
const userAgentInfo = `azsdk-js-ai-anomaly-detector/1.0.0-beta.1`;
const userAgentPrefix = prefixFromOptions
? `${prefixFromOptions} azsdk-js-api`
: "azsdk-js-api";
? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}`
: `azsdk-js-api ${userAgentInfo}`;
const { apiVersion: _, ...updatedOptions } = {
...options,
userAgentOptions: { userAgentPrefix },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@
"test": "npm run clean && tshy && npm run unit-test:node && npm run unit-test:browser && npm run integration-test",
"build": "npm run clean && tshy && npm run extract-api"
},
"//metadata": {
"constantPaths": [
{
"path": "src/api/batchContext.ts",
"prefix": "userAgentInfo"
}
]
},
"exports": {
"./package.json": "./package.json",
".": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ export function createBatch(
const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`;

const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix;
const userAgentInfo = `azsdk-js-batch/1.0.0-beta.1`;
const userAgentPrefix = prefixFromOptions
? `${prefixFromOptions} azsdk-js-api`
: "azsdk-js-api";
? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}`
: `azsdk-js-api ${userAgentInfo}`;
const { apiVersion: _, ...updatedOptions } = {
...options,
userAgentOptions: { userAgentPrefix },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@
"test": "npm run clean && tshy && npm run unit-test:node && npm run unit-test:browser && npm run integration-test",
"build": "npm run clean && tshy && npm run extract-api"
},
"//metadata": {
"constantPaths": [
{
"path": "src/api/chatProtocolContext.ts",
"prefix": "userAgentInfo"
}
]
},
"exports": {
"./package.json": "./package.json",
".": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ export function createChatProtocol(
const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`;

const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix;
const userAgentInfo = `azsdk-js-ai-chat-protocol/1.0.0-beta.1`;
const userAgentPrefix = prefixFromOptions
? `${prefixFromOptions} azsdk-js-api`
: "azsdk-js-api";
? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}`
: `azsdk-js-api ${userAgentInfo}`;
const { apiVersion: _, ...updatedOptions } = {
...options,
userAgentOptions: { userAgentPrefix },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
"lint:fix": "eslint package.json api-extractor.json src --fix --fix-type [problem,suggestion]",
"build": "npm run clean && tshy && npm run extract-api"
},
"//metadata": {
"constantPaths": [
{
"path": "src/api/contentSafetyContext.ts",
"prefix": "userAgentInfo"
}
]
},
"exports": {
"./package.json": "./package.json",
".": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ export function createContentSafety(
options.endpoint ?? options.baseUrl ?? `${endpointParam}/contentsafety`;

const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix;
const userAgentInfo = `azsdk-js-ai-content-safety/1.0.0`;
const userAgentPrefix = prefixFromOptions
? `${prefixFromOptions} azsdk-js-api`
: "azsdk-js-api";
? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}`
: `azsdk-js-api ${userAgentInfo}`;
const { apiVersion: _, ...updatedOptions } = {
...options,
userAgentOptions: { userAgentPrefix },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@
"test": "npm run clean && tshy && npm run unit-test:node && npm run unit-test:browser && npm run integration-test",
"build": "npm run clean && tshy && npm run extract-api"
},
"//metadata": {
"constantPaths": [
{
"path": "src/api/eventGridContext.ts",
"prefix": "userAgentInfo"
}
]
},
"exports": {
"./package.json": "./package.json",
".": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ export function createEventGrid(
const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`;

const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix;
const userAgentInfo = `azsdk-js-eventgrid/1.0.0-beta.1`;
const userAgentPrefix = prefixFromOptions
? `${prefixFromOptions} azsdk-js-api`
: "azsdk-js-api";
? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}`
: `azsdk-js-api ${userAgentInfo}`;
const { apiVersion: _, ...updatedOptions } = {
...options,
userAgentOptions: { userAgentPrefix },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@
"test": "npm run clean && tshy && npm run unit-test:node && npm run unit-test:browser && npm run integration-test",
"build": "npm run clean && tshy && npm run extract-api"
},
"//metadata": {
"constantPaths": [
{
"path": "src/api/radiologyInsightsContext.ts",
"prefix": "userAgentInfo"
}
]
},
"exports": {
"./package.json": "./package.json",
".": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export function createRadiologyInsights(
options.endpoint ?? options.baseUrl ?? `${endpointParam}/health-insights`;

const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix;
const userAgentInfo = `azsdk-js-health-insights-radiologyinsights/1.0.0-beta.1`;
const userAgentPrefix = prefixFromOptions
? `${prefixFromOptions} azsdk-js-api`
: "azsdk-js-api";
? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}`
: `azsdk-js-api ${userAgentInfo}`;
const { apiVersion: _, ...updatedOptions } = {
...options,
userAgentOptions: { userAgentPrefix },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@
"test": "npm run clean && tshy && npm run unit-test:node && npm run unit-test:browser && npm run integration-test",
"build": "npm run clean && tshy && npm run extract-api"
},
"//metadata": {
"constantPaths": [
{
"path": "src/api/fooContext.ts",
"prefix": "userAgentInfo"
}
]
},
"exports": {
"./package.json": "./package.json",
".": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ export function createFoo(
options: FooClientOptionalParams = {},
): FooContext {
const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix;
const userAgentInfo = `azsdk-js-hierarchy-generic/1.0.0-beta.1`;
const userAgentPrefix = prefixFromOptions
? `${prefixFromOptions} azsdk-js-api`
: "azsdk-js-api";
? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}`
: `azsdk-js-api ${userAgentInfo}`;
const { apiVersion: _, ...updatedOptions } = {
...options,
userAgentOptions: { userAgentPrefix },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@
"test": "npm run clean && tshy && npm run unit-test:node && npm run unit-test:browser && npm run integration-test",
"build": "npm run clean && tshy && npm run extract-api"
},
"//metadata": {
kazrael2119 marked this conversation as resolved.
Show resolved Hide resolved
"constantPaths": [
{
"path": "src/loadTestAdministration/api/loadTestAdministrationContext.ts",
"prefix": "userAgentInfo"
},
{
"path": "src/loadTestRun/api/loadTestRunContext.ts",
"prefix": "userAgentInfo"
},
{
"path": "src/testProfileAdministration/api/testProfileAdministrationContext.ts",
"prefix": "userAgentInfo"
},
{
"path": "src/testProfileRun/api/testProfileRunContext.ts",
"prefix": "userAgentInfo"
}
]
},
"exports": {
"./package.json": "./package.json",
".": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ export function createLoadTestAdministration(
options.endpoint ?? options.baseUrl ?? `https://${endpointParam}`;

const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix;
const userAgentInfo = `azsdk-js-load-testing/1.0.1`;
const userAgentPrefix = prefixFromOptions
? `${prefixFromOptions} azsdk-js-api`
: "azsdk-js-api";
? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}`
: `azsdk-js-api ${userAgentInfo}`;
const { apiVersion: _, ...updatedOptions } = {
...options,
userAgentOptions: { userAgentPrefix },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export function createLoadTestRun(
options.endpoint ?? options.baseUrl ?? `https://${endpointParam}`;

const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix;
const userAgentInfo = `azsdk-js-load-testing/1.0.1`;
const userAgentPrefix = prefixFromOptions
? `${prefixFromOptions} azsdk-js-api`
: "azsdk-js-api";
? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}`
: `azsdk-js-api ${userAgentInfo}`;
const { apiVersion: _, ...updatedOptions } = {
...options,
userAgentOptions: { userAgentPrefix },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ export function createTestProfileAdministration(
options.endpoint ?? options.baseUrl ?? `https://${endpointParam}`;

const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix;
const userAgentInfo = `azsdk-js-load-testing/1.0.1`;
const userAgentPrefix = prefixFromOptions
? `${prefixFromOptions} azsdk-js-api`
: "azsdk-js-api";
? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}`
: `azsdk-js-api ${userAgentInfo}`;
const { apiVersion: _, ...updatedOptions } = {
...options,
userAgentOptions: { userAgentPrefix },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export function createTestProfileRun(
options.endpoint ?? options.baseUrl ?? `https://${endpointParam}`;

const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix;
const userAgentInfo = `azsdk-js-load-testing/1.0.1`;
const userAgentPrefix = prefixFromOptions
? `${prefixFromOptions} azsdk-js-api`
: "azsdk-js-api";
? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}`
: `azsdk-js-api ${userAgentInfo}`;
const { apiVersion: _, ...updatedOptions } = {
...options,
userAgentOptions: { userAgentPrefix },
Expand Down
Loading
Loading