diff --git a/common/tools/eslint-plugin-azure-sdk/src/rules/ts-package-json-name.ts b/common/tools/eslint-plugin-azure-sdk/src/rules/ts-package-json-name.ts index 5184efb8d35f..0475c46186bc 100644 --- a/common/tools/eslint-plugin-azure-sdk/src/rules/ts-package-json-name.ts +++ b/common/tools/eslint-plugin-azure-sdk/src/rules/ts-package-json-name.ts @@ -36,37 +36,37 @@ export = { "ExpressionStatement > ObjectExpression > Property[key.value='name']": ( node: Property ): void => { - const nodeValue = node.value as Literal; - const name = nodeValue.value as string; - - if (!name.startsWith("@azure/")) { + const { nodeValue, packageName, subScope } = getPackageMetadata(node); + // Check for a valid scope + if (!/^@azure(-[a-z]+)?\//.test(packageName)) { context.report({ node: nodeValue, - message: "name is not set to @azure/" + message: "name is not set to @azure[-]/" }); return; } - + const packageBaseName = stripPath(packageName); const packageDirectory = stripPath(stripFileName(fileName)); - const packageBaseName = stripPath(name); - if (!/^@azure\/([a-z]+-)*[a-z]+$/.test(name)) { + + if (!/^@azure(-[a-z]+)?\/([a-z]+-)*[a-z]+$/.test(packageName)) { context.report({ node: nodeValue, message: "service name is not in kebab-case (lowercase and separated by hyphens)" }); // Give a good error report if the non-kebab-case name does match the directory and suggest renaming it as well - if (name === `@azure/${packageDirectory}`) { + if (packageName === `@azure/${packageDirectory}`) { context.report({ node: nodeValue, message: "service name matches directory name, but the directory is not kebab case (lowercase and separated by hyphens)" }); } - } else if (name !== `@azure/${packageDirectory}`) { + } else if (!isValidFolder(packageName, packageDirectory, subScope)) { + const subScopeSuffix = subScope ?? ""; context.report({ node: nodeValue, - message: `service should be named '@azure/${packageDirectory}' or should be moved to a directory called '${packageBaseName}'` + message: `service should be named '@azure${subScopeSuffix}/${packageDirectory}' or should be moved to a directory called '${packageBaseName}${subScopeSuffix}'` }); } } @@ -74,3 +74,27 @@ export = { : {}; } }; + +function isValidFolder(packageName: string, folderName: string, subScope?: string): boolean { + if (!subScope) { + return RegExp(`^@azure(-[a-z]+)?\/${folderName}`).test(packageName); + } + + // If there is a subScope, allow the folder name to have it appended at the end i.e folder-name-subscope + return RegExp(`^@azure(-[a-z]+)?\/${folderName}`).test(`${packageName}${subScope}`); +} + +function getPackageMetadata( + node: Property +): { nodeValue: Literal; packageName: string; subScope: string | undefined } { + const nodeValue = node.value as Literal; + const packageName = nodeValue.value as string; + // Check if there is a sub scope i.e @azure-rest + const [_, subScope] = packageName.match(/^@azure(-[a-z]+)?\//) ?? []; + + return { + nodeValue, + packageName, + subScope + }; +} diff --git a/common/tools/eslint-plugin-azure-sdk/tests/rules/ts-package-json-name.ts b/common/tools/eslint-plugin-azure-sdk/tests/rules/ts-package-json-name.ts index 9c5b10023f10..0d78da197404 100644 --- a/common/tools/eslint-plugin-azure-sdk/tests/rules/ts-package-json-name.ts +++ b/common/tools/eslint-plugin-azure-sdk/tests/rules/ts-package-json-name.ts @@ -258,6 +258,11 @@ ruleTester.run("ts-package-json-name", rule, { code: '{"name": "@azure/service-bus"}', filename: "service-bus/package.json" }, + { + // subscope + code: '{"name": "@azure-rest/service-bus"}', + filename: "service-bus-rest/package.json" + }, { // a full example package.json (taken from https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-hubs/package.json with "scripts" removed for testing purposes) code: examplePackageGood, @@ -295,7 +300,7 @@ ruleTester.run("ts-package-json-name", rule, { filename: "service-bus/package.json", errors: [ { - message: "name is not set to @azure/" + message: "name is not set to @azure[-]/" } ] }, @@ -329,13 +334,24 @@ ruleTester.run("ts-package-json-name", rule, { } ] }, + { + // not kebab-case + code: '{"name": "@azure-rest/service-bus"}', + filename: "not-service-bus/package.json", + errors: [ + { + message: + "service should be named '@azure-rest/not-service-bus' or should be moved to a directory called 'service-bus-rest'" + } + ] + }, { // example file with name set to service-bus code: examplePackageBad, filename: "service-bus/package.json", errors: [ { - message: "name is not set to @azure/" + message: "name is not set to @azure[-]/" } ] }, diff --git a/sdk/core-rest/core-client/CHANGELOG.md b/sdk/core-rest/core-client/CHANGELOG.md index 4144f75694a0..3743526dc977 100644 --- a/sdk/core-rest/core-client/CHANGELOG.md +++ b/sdk/core-rest/core-client/CHANGELOG.md @@ -1,3 +1,5 @@ # Release History ## 1.0.0-beta.1 (Unreleased) + +- First release of package, see README.md for details. diff --git a/sdk/core-rest/core-client/package.json b/sdk/core-rest/core-client/package.json index 96338f3d9089..4dfbfa062806 100644 --- a/sdk/core-rest/core-client/package.json +++ b/sdk/core-rest/core-client/package.json @@ -9,6 +9,14 @@ "./dist-esm/src/url.js": "./dist-esm/src/url.browser.js" }, "types": "types/src/latest/core-client.d.ts", + "//metadata": { + "constantPaths": [ + { + "path": "src/constants.ts", + "prefix": "SDK_VERSION" + } + ] + }, "scripts": { "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", "build:browser": "npm run build:ts && cross-env ONLY_BROWSER=true rollup -c 2>&1", diff --git a/sdk/core-rest/core-client/src/clientHelpers.ts b/sdk/core-rest/core-client/src/clientHelpers.ts index b01f9026be89..1ed9c6f58ed4 100644 --- a/sdk/core-rest/core-client/src/clientHelpers.ts +++ b/sdk/core-rest/core-client/src/clientHelpers.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { createPipelineFromOptions, bearerTokenAuthenticationPolicy, diff --git a/sdk/core-rest/core-client/src/common.ts b/sdk/core-rest/core-client/src/common.ts index 70a87a092ede..432ec7179601 100644 --- a/sdk/core-rest/core-client/src/common.ts +++ b/sdk/core-rest/core-client/src/common.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { PipelineOptions, RawHttpHeaders, PipelineRequest } from "@azure/core-rest-pipeline"; /** diff --git a/sdk/core-rest/core-client/src/constants.ts b/sdk/core-rest/core-client/src/constants.ts new file mode 100644 index 000000000000..dbdf0d9aeaf3 --- /dev/null +++ b/sdk/core-rest/core-client/src/constants.ts @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @internal + */ +export const SDK_VERSION: string = "1.0.0-beta.1"; diff --git a/sdk/core-rest/core-client/src/getClient.ts b/sdk/core-rest/core-client/src/getClient.ts index d9b3323b9423..20c809743476 100644 --- a/sdk/core-rest/core-client/src/getClient.ts +++ b/sdk/core-rest/core-client/src/getClient.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { isTokenCredential, KeyCredential, TokenCredential } from "@azure/core-auth"; import { HttpMethods, Pipeline, PipelineOptions } from "@azure/core-rest-pipeline"; import { createDefaultPipeline } from "./clientHelpers"; @@ -19,6 +22,7 @@ export interface Client { * This method will be used to send request that would check the path to provide * strong types */ + // eslint-disable-next-line @typescript-eslint/ban-types path: Function; /** * This method allows arbitrary paths and doesn't provide strong types @@ -40,15 +44,15 @@ export interface Client { /** * Creates a client with a default pipeline - * @param baseUrl Base endpoint for the client - * @param options Client options + * @param baseUrl - Base endpoint for the client + * @param options - Client options */ export function getClient(baseUrl: string, options?: PipelineOptions): Client; /** * Creates a client with a default pipeline - * @param baseUrl Base endpoint for the client - * @param credentials Credentials to authenticate the requests - * @param options Client options + * @param baseUrl - Base endpoint for the client + * @param credentials - Credentials to authenticate the requests + * @param options - Client options */ export function getClient( baseUrl: string, @@ -57,18 +61,16 @@ export function getClient( ): Client; export function getClient( baseUrl: string, - credentialsOrPipelineOptions?: (TokenCredential | KeyCredential) | PipelineOptions, - options: ClientOptions = {} + credentialsOrPipelineOptions?: (TokenCredential | KeyCredential) | ClientOptions, + clientOptions: ClientOptions = {} ): Client { let credentials: TokenCredential | KeyCredential | undefined; - let clientOptions = options; if (credentialsOrPipelineOptions) { if (isCredential(credentialsOrPipelineOptions)) { credentials = credentialsOrPipelineOptions; - clientOptions = options; } else { - clientOptions = credentialsOrPipelineOptions || {}; + clientOptions = credentialsOrPipelineOptions ?? {}; } } @@ -116,7 +118,7 @@ function buildSendRequest( pipeline: Pipeline, requestOptions: RequestParameters = {}, args: string[] = [] -) { +): Promise { // If the client has an api-version and the request doesn't specify one, inject the one in the client options if (!requestOptions.queryParameters?.["api-version"] && clientOptions.apiVersion) { if (!requestOptions.queryParameters) { diff --git a/sdk/core-rest/core-client/src/index.ts b/sdk/core-rest/core-client/src/index.ts index 060d5a49f5c1..759017c1e70b 100644 --- a/sdk/core-rest/core-client/src/index.ts +++ b/sdk/core-rest/core-client/src/index.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + /** * Azure Rest Core Client library for JavaScript * @packageDocumentation diff --git a/sdk/core-rest/core-client/src/keyCredentialAuthenticationPolicy.ts b/sdk/core-rest/core-client/src/keyCredentialAuthenticationPolicy.ts index c25339eeebda..891956dd88c5 100644 --- a/sdk/core-rest/core-client/src/keyCredentialAuthenticationPolicy.ts +++ b/sdk/core-rest/core-client/src/keyCredentialAuthenticationPolicy.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { KeyCredential } from "@azure/core-auth"; import { PipelinePolicy, diff --git a/sdk/core-rest/core-client/src/pathClientTypes.ts b/sdk/core-rest/core-client/src/pathClientTypes.ts index 6ce3e28a0db8..75dfe73f43fe 100644 --- a/sdk/core-rest/core-client/src/pathClientTypes.ts +++ b/sdk/core-rest/core-client/src/pathClientTypes.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { RawHttpHeaders } from "@azure/core-rest-pipeline"; /** @@ -32,7 +35,7 @@ export type RequestParameters = { /** * Helper type used to detect parameters in a path template - * keys surounded by {} will be considered a path parameter + * keys surounded by \{\} will be considered a path parameter */ export type RouteParams = TRoute extends `{${infer _Param}}/${infer Tail}` ? [pathParam: string, ...pathParams: RouteParams] diff --git a/sdk/core-rest/core-client/src/sendRequest.ts b/sdk/core-rest/core-client/src/sendRequest.ts index 3101718b0526..100f2a7d34b2 100644 --- a/sdk/core-rest/core-client/src/sendRequest.ts +++ b/sdk/core-rest/core-client/src/sendRequest.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { createHttpHeaders, createPipelineRequest, @@ -11,10 +14,10 @@ import { HttpResponse } from "./common"; /** * Helper function to send request used by the client - * @param method method to use to send the request - * @param url url to send the request to - * @param pipeline pipeline with the policies to run when sending the request - * @param options request options + * @param method - method to use to send the request + * @param url - url to send the request to + * @param pipeline - pipeline with the policies to run when sending the request + * @param options - request options * @returns returns and HttpResponse */ export async function sendRequest( @@ -65,7 +68,7 @@ export async function sendRequest( /** * Function to determine the content-type of a body * this is used if an explicit content-type is not provided - * @param body body in the request + * @param body - body in the request * @returns returns the content-type */ function getContentType(body: any): string { diff --git a/sdk/core-rest/core-client/src/urlHelpers.ts b/sdk/core-rest/core-client/src/urlHelpers.ts index b2048cbee603..429349594a74 100644 --- a/sdk/core-rest/core-client/src/urlHelpers.ts +++ b/sdk/core-rest/core-client/src/urlHelpers.ts @@ -1,12 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { RequestParameters } from "./pathClientTypes"; import { URL } from "./url"; /** * Builds the request url, filling in query and path parameters - * @param baseUrl base url which can be a template url - * @param routePath path to append to the baseUrl - * @param pathParameters values of the path parameters - * @param options request parameters including query parameters + * @param baseUrl - base url which can be a template url + * @param routePath - path to append to the baseUrl + * @param pathParameters - values of the path parameters + * @param options - request parameters including query parameters * @returns a full url with path and query parameters */ export function buildRequestUrl( @@ -22,7 +25,7 @@ export function buildRequestUrl( } for (const pathParam of pathParameters) { - path = path.replace(/{([^\/]+)}/, pathParam); + path = path.replace(/{([^/]+)}/, pathParam); } const url = new URL(`${baseUrl}/${path}`); diff --git a/sdk/core-rest/core-client/test/clientHelpers.spec.ts b/sdk/core-rest/core-client/test/clientHelpers.spec.ts index 243212766c5e..699f33469005 100644 --- a/sdk/core-rest/core-client/test/clientHelpers.spec.ts +++ b/sdk/core-rest/core-client/test/clientHelpers.spec.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { createDefaultPipeline } from "../src/clientHelpers"; import { assert } from "chai"; import { bearerTokenAuthenticationPolicyName } from "@azure/core-rest-pipeline"; diff --git a/sdk/core-rest/core-client/test/sendRequest.spec.ts b/sdk/core-rest/core-client/test/sendRequest.spec.ts index 69659cc5a89a..643e368fbcef 100644 --- a/sdk/core-rest/core-client/test/sendRequest.spec.ts +++ b/sdk/core-rest/core-client/test/sendRequest.spec.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { sendRequest } from "../src/sendRequest"; import { assert } from "chai"; import { diff --git a/sdk/core-rest/core-client/test/urlHelpers.spec.ts b/sdk/core-rest/core-client/test/urlHelpers.spec.ts index ff97632387de..2823b53db871 100644 --- a/sdk/core-rest/core-client/test/urlHelpers.spec.ts +++ b/sdk/core-rest/core-client/test/urlHelpers.spec.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { buildRequestUrl } from "../src/urlHelpers"; import { assert } from "chai"; describe("urlHelpers", () => { diff --git a/sdk/documenttranslator/ai-document-translator-rest/.eslintrc.json b/sdk/documenttranslator/ai-document-translator-rest/.eslintrc.json new file mode 100644 index 000000000000..066f6bd416f1 --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/.eslintrc.json @@ -0,0 +1,7 @@ +{ + "plugins": ["@azure/azure-sdk"], + "extends": ["plugin:@azure/azure-sdk/azure-sdk-base"], + "rules": { + "@azure/azure-sdk/ts-modules-only-named": "warn" + } +} diff --git a/sdk/documenttranslator/ai-document-translator-rest/CHANGELOG.md b/sdk/documenttranslator/ai-document-translator-rest/CHANGELOG.md index 4144f75694a0..3743526dc977 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/CHANGELOG.md +++ b/sdk/documenttranslator/ai-document-translator-rest/CHANGELOG.md @@ -1,3 +1,5 @@ # Release History ## 1.0.0-beta.1 (Unreleased) + +- First release of package, see README.md for details. diff --git a/sdk/documenttranslator/ai-document-translator-rest/package.json b/sdk/documenttranslator/ai-document-translator-rest/package.json index 82b2cec6cec1..140cc4ed7d98 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/package.json +++ b/sdk/documenttranslator/ai-document-translator-rest/package.json @@ -33,6 +33,10 @@ { "path": "src/constants.ts", "prefix": "SDK_VERSION" + }, + { + "path": "swagger/README.md", + "prefix": "package-version" } ] }, @@ -44,7 +48,7 @@ "productSlugs": [ "azure", "azure-cognitive-services", - "azure-document-translator" + "azure-translator" ], "requiredResources": { "Azure Cognitive Services instance": "https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account" diff --git a/sdk/documenttranslator/ai-document-translator-rest/samples/v1/javascript/README.md b/sdk/documenttranslator/ai-document-translator-rest/samples/v1/javascript/README.md index 257b5e1bddd0..204f29d29cdd 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/samples/v1/javascript/README.md +++ b/sdk/documenttranslator/ai-document-translator-rest/samples/v1/javascript/README.md @@ -5,7 +5,7 @@ languages: products: - azure - azure-cognitive-services - - azure-document-translator + - azure-translator urlFragment: ai-document-translator-javascript disableDocsMs: true --- diff --git a/sdk/documenttranslator/ai-document-translator-rest/samples/v1/typescript/README.md b/sdk/documenttranslator/ai-document-translator-rest/samples/v1/typescript/README.md index 6ae96f291677..94c035f4475a 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/samples/v1/typescript/README.md +++ b/sdk/documenttranslator/ai-document-translator-rest/samples/v1/typescript/README.md @@ -5,7 +5,7 @@ languages: products: - azure - azure-cognitive-services - - azure-document-translator + - azure-translator urlFragment: ai-document-translator-typescript disableDocsMs: true --- diff --git a/sdk/documenttranslator/ai-document-translator-rest/src/constants.ts b/sdk/documenttranslator/ai-document-translator-rest/src/constants.ts new file mode 100644 index 000000000000..dbdf0d9aeaf3 --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/src/constants.ts @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * @internal + */ +export const SDK_VERSION: string = "1.0.0-beta.1"; diff --git a/sdk/documenttranslator/ai-document-translator-rest/test/public/utils/recordedClient.ts b/sdk/documenttranslator/ai-document-translator-rest/test/public/utils/recordedClient.ts index 1d255b3a7975..f80cc877e771 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/test/public/utils/recordedClient.ts +++ b/sdk/documenttranslator/ai-document-translator-rest/test/public/utils/recordedClient.ts @@ -34,7 +34,7 @@ export const environmentSetup: RecorderEnvironmentSetup = { }; export function createClient(options?: ClientOptions): DocumentTranslatorClient { - let credential = { key: env.DOCUMENT_TRANSLATOR_API_KEY }; + const credential = { key: env.DOCUMENT_TRANSLATOR_API_KEY }; return DocumentTranslator(env.ENDPOINT, credential, options); } diff --git a/sdk/metricsadvisor/perf-tests/ai-metrics-advisor/test/listAnomalies.spec.ts b/sdk/metricsadvisor/perf-tests/ai-metrics-advisor/test/listAnomalies.spec.ts index 425f419b1a12..670cd3f9d5bf 100644 --- a/sdk/metricsadvisor/perf-tests/ai-metrics-advisor/test/listAnomalies.spec.ts +++ b/sdk/metricsadvisor/perf-tests/ai-metrics-advisor/test/listAnomalies.spec.ts @@ -2,7 +2,7 @@ // Licensed under the MIT license. import { PerfStressOptionDictionary, getEnvVar } from "@azure/test-utils-perfstress"; import { MetricsAdvisorTest } from "./metricsAdvisor.spec"; -interface MetricsAdvisorTestOptions {} +type MetricsAdvisorTestOptions = Record; export class AnomaliesListTest extends MetricsAdvisorTest { alertId: string; @@ -19,6 +19,7 @@ export class AnomaliesListTest extends MetricsAdvisorTest; export class IncidentsListTest extends MetricsAdvisorTest { alertId: string; @@ -20,6 +20,7 @@ export class IncidentsListTest extends MetricsAdvisorTest; export class RootCauseTest extends MetricsAdvisorTest { detectionConfigId: string; @@ -16,6 +16,7 @@ export class RootCauseTest extends MetricsAdvisorTest async runAsync(): Promise { const result = await this.client.getIncidentRootCauses(this.detectionConfigId, this.incidentId); + // eslint-disable-next-line no-empty for (const _rootcause of result.rootCauses) { } } diff --git a/sdk/search/perf-tests/search-documents/test/core/searchDocumentsBase.spec.ts b/sdk/search/perf-tests/search-documents/test/core/searchDocumentsBase.spec.ts index 9b91ef6c17d6..ef9bbab2be78 100644 --- a/sdk/search/perf-tests/search-documents/test/core/searchDocumentsBase.spec.ts +++ b/sdk/search/perf-tests/search-documents/test/core/searchDocumentsBase.spec.ts @@ -1,7 +1,4 @@ -import { - PerfStressTest, - getEnvVar -} from "@azure/test-utils-perfstress"; +import { PerfStressTest, getEnvVar } from "@azure/test-utils-perfstress"; import { SearchClient, AzureKeyCredential, @@ -16,7 +13,7 @@ export interface SearchDocumentsTestOptions { documentsCount: number; } -export abstract class SearchDocumentsBase extends PerfStressTest { +export abstract class SearchDocumentsBase> extends PerfStressTest { searchIndexClient: SearchIndexClient; searchClient: SearchClient; indexName: string; @@ -250,9 +247,9 @@ export abstract class SearchDocumentsBase extends PerfStressTest< public async populateIndex(documentsCount: number) { const hotels = generateHotels(documentsCount); - while(hotels.length > 0) { + while (hotels.length > 0) { const hotelsToUpload = hotels.splice(0, 100); - await this.searchClient.uploadDocuments(hotelsToUpload) + await this.searchClient.uploadDocuments(hotelsToUpload); } } }