diff --git a/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/LICENSE b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/LICENSE new file mode 100644 index 0000000000..63447fd8bb --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/LICENSE @@ -0,0 +1,21 @@ +Copyright (c) Microsoft Corporation. + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/README.md b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/README.md new file mode 100644 index 0000000000..77281f3f20 --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/README.md @@ -0,0 +1,53 @@ +# TestService REST client library for JavaScript + + + +**Please rely heavily on our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library** + +Key links: + +- [Package (NPM)](https://www.npmjs.com/package/@msinternal/test) + +## Getting started + +### Currently supported environments + +- LTS versions of Node.js + +### Prerequisites + +- You must have an [Azure subscription](https://azure.microsoft.com/free/) to use this package. + +### Install the `@msinternal/test` package + +Install the TestService REST client REST client library for JavaScript with `npm`: + +```bash +npm install @msinternal/test +``` + +### Create and authenticate a `TestServiceClient` + +To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token), +provide an instance of the desired credential type obtained from the +[@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library. + +To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity) + +After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use. +As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential) +can be used to authenticate the client. + +## Troubleshooting + +### Logging + +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 +import { setLogLevel } from "@azure/logger"; + +setLogLevel("info"); +``` + +For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger). diff --git a/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/api-extractor.json b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/api-extractor.json new file mode 100644 index 0000000000..0c73654923 --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/api-extractor.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + "mainEntryPointFilePath": "dist/esm/index.d.ts", + "docModel": { "enabled": true }, + "apiReport": { "enabled": true, "reportFolder": "./review" }, + "dtsRollup": { + "enabled": true, + "untrimmedFilePath": "", + "publicTrimmedFilePath": "dist/test.d.ts" + }, + "messages": { + "tsdocMessageReporting": { "default": { "logLevel": "none" } }, + "extractorMessageReporting": { + "ae-missing-release-tag": { "logLevel": "none" }, + "ae-unresolved-link": { "logLevel": "none" } + } + } +} diff --git a/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/eslint.config.mjs b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/eslint.config.mjs new file mode 100644 index 0000000000..9396819633 --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/eslint.config.mjs @@ -0,0 +1,14 @@ +import azsdkEslint from "@azure/eslint-plugin-azure-sdk"; + +export default azsdkEslint.config([ + { + rules: { + "@azure/azure-sdk/ts-modules-only-named": "warn", + "@azure/azure-sdk/ts-package-json-types": "warn", + "@azure/azure-sdk/ts-package-json-engine-is-present": "warn", + "@azure/azure-sdk/ts-package-json-files-required": "off", + "@azure/azure-sdk/ts-package-json-main-is-cjs": "off", + "tsdoc/syntax": "warn" + } + } +]); diff --git a/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/package.json b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/package.json new file mode 100644 index 0000000000..0e276ff1f9 --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/package.json @@ -0,0 +1,51 @@ +{ + "name": "@msinternal/test", + "version": "1.0.0-beta.1", + "description": "A generated SDK for TestServiceClient.", + "engines": { + "node": ">=20.0.0" + }, + "sideEffects": false, + "autoPublish": false, + "tshy": { + "exports": { + "./package.json": "./package.json", + ".": "./src/index.ts" + }, + "dialects": ["esm", "commonjs"], + "esmDialects": ["browser", "react-native"], + "selfLink": false + }, + "type": "module", + "browser": "./dist/browser/index.js", + "react-native": "./dist/react-native/index.js", + "keywords": ["node", "azure", "cloud", "typescript", "browser", "isomorphic"], + "author": "Microsoft Corporation", + "license": "MIT", + "files": ["dist/", "!dist/**/*.d.*ts.map", "README.md", "LICENSE"], + "dependencies": { + "@azure-rest/core-client": "^2.3.1", + "@azure/core-auth": "^1.6.0", + "@azure/core-rest-pipeline": "^1.5.0", + "@azure/logger": "^1.0.0", + "tslib": "^2.6.2" + }, + "devDependencies": { + "dotenv": "^16.0.0", + "@types/node": "^20.0.0", + "eslint": "^9.9.0", + "typescript": "~5.8.2", + "tshy": "^2.0.0", + "@microsoft/api-extractor": "^7.40.3", + "rimraf": "^5.0.5", + "mkdirp": "^3.0.1" + }, + "scripts": { + "clean": "rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", + "extract-api": "rimraf review && mkdirp ./review && api-extractor run --local", + "pack": "npm pack 2>&1", + "lint": "eslint package.json api-extractor.json src", + "lint:fix": "eslint package.json api-extractor.json src --fix --fix-type [problem,suggestion]", + "build": "npm run clean && tshy && npm run extract-api" + } +} diff --git a/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/rollup.config.js b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/rollup.config.js new file mode 100644 index 0000000000..92fab887b9 --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/rollup.config.js @@ -0,0 +1,117 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import nodeResolve from "@rollup/plugin-node-resolve"; +import cjs from "@rollup/plugin-commonjs"; +import sourcemaps from "rollup-plugin-sourcemaps"; +import multiEntry from "@rollup/plugin-multi-entry"; +import json from "@rollup/plugin-json"; + +import nodeBuiltins from "builtin-modules"; + +// #region Warning Handler + +/** + * A function that can determine whether a rollup warning should be ignored. If + * the function returns `true`, then the warning will not be displayed. + */ + +function ignoreNiseSinonEval(warning) { + return ( + warning.code === "EVAL" && + warning.id && + (warning.id.includes("node_modules/nise") || warning.id.includes("node_modules/sinon")) === true + ); +} + +function ignoreChaiCircularDependency(warning) { + return ( + warning.code === "CIRCULAR_DEPENDENCY" && + warning.importer && + warning.importer.includes("node_modules/chai") === true + ); +} + +const warningInhibitors = [ignoreChaiCircularDependency, ignoreNiseSinonEval]; + +/** + * Construct a warning handler for the shared rollup configuration + * that ignores certain warnings that are not relevant to testing. + */ +function makeOnWarnForTesting() { + return (warning, warn) => { + // If every inhibitor returns false (i.e. no inhibitors), then show the warning + if (warningInhibitors.every((inhib) => !inhib(warning))) { + warn(warning); + } + }; +} + +// #endregion + +function makeBrowserTestConfig() { + const config = { + input: { + include: ["dist-esm/test/**/*.spec.js"], + exclude: ["dist-esm/test/**/node/**"], + }, + output: { + file: `dist-test/index.browser.js`, + format: "umd", + sourcemap: true, + }, + preserveSymlinks: false, + plugins: [ + multiEntry({ exports: false }), + nodeResolve({ + mainFields: ["module", "browser"], + }), + cjs(), + json(), + sourcemaps(), + //viz({ filename: "dist-test/browser-stats.html", sourcemap: true }) + ], + onwarn: makeOnWarnForTesting(), + // Disable tree-shaking of test code. In rollup-plugin-node-resolve@5.0.0, + // rollup started respecting the "sideEffects" field in package.json. Since + // our package.json sets "sideEffects=false", this also applies to test + // code, which causes all tests to be removed by tree-shaking. + treeshake: false, + }; + + return config; +} + +const defaultConfigurationOptions = { + disableBrowserBundle: false, +}; + +export function makeConfig(pkg, options) { + options = { + ...defaultConfigurationOptions, + ...(options || {}), + }; + + const baseConfig = { + // Use the package's module field if it has one + input: pkg["module"] || "dist-esm/src/index.js", + external: [ + ...nodeBuiltins, + ...Object.keys(pkg.dependencies), + ...Object.keys(pkg.devDependencies), + ], + output: { file: "dist/index.js", format: "cjs", sourcemap: true }, + preserveSymlinks: false, + plugins: [sourcemaps(), nodeResolve()], + }; + + const config = [baseConfig]; + + if (!options.disableBrowserBundle) { + config.push(makeBrowserTestConfig()); + } + + return config; +} + +export default makeConfig(require("./package.json")); diff --git a/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/clientDefinitions.ts b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/clientDefinitions.ts new file mode 100644 index 0000000000..0f9de49afe --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/clientDefinitions.ts @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { GlobalModelGetPetSettingsParameters } from "./parameters.js"; +import type { GlobalModelGetPetSettings200Response } from "./responses.js"; +import type { Client, StreamableMethod } from "@azure-rest/core-client"; + +/** Contains operations for GlobalModel operations */ +export interface GlobalModelOperations { + getPetSettings( + options?: GlobalModelGetPetSettingsParameters, + ): StreamableMethod; +} + +export interface GetPetSettings { + get( + options?: GlobalModelGetPetSettingsParameters, + ): StreamableMethod; +} + +export interface Routes { + /** Resource for '/' has methods for the following verbs: get */ + (path: "/"): GetPetSettings; +} + +export type TestServiceClient = Client & { + path: Routes; + globalModel: GlobalModelOperations; +}; diff --git a/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/index.ts b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/index.ts new file mode 100644 index 0000000000..0564663bcc --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/index.ts @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import TestServiceClient from "./testServiceClient.js"; + +export * from "./testServiceClient.js"; +export * from "./parameters.js"; +export * from "./responses.js"; +export * from "./clientDefinitions.js"; +export * from "./outputModels.js"; + +export default TestServiceClient; diff --git a/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/logger.ts b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/logger.ts new file mode 100644 index 0000000000..11838bb99d --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/logger.ts @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { createClientLogger } from "@azure/logger"; +export const logger = createClientLogger("test"); diff --git a/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/outputModels.ts b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/outputModels.ts new file mode 100644 index 0000000000..104672c6d0 --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/outputModels.ts @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +export interface PetSettingsOutput { + petList?: { cat?: Array }; +} diff --git a/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/parameters.ts b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/parameters.ts new file mode 100644 index 0000000000..a5b1617ad8 --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/parameters.ts @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { RequestParameters } from "@azure-rest/core-client"; + +export type GlobalModelGetPetSettingsParameters = RequestParameters; diff --git a/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/responses.ts b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/responses.ts new file mode 100644 index 0000000000..d28a6d40cc --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/responses.ts @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { HttpResponse } from "@azure-rest/core-client"; +import type { PetSettingsOutput } from "./outputModels.js"; + +/** The request has succeeded. */ +export interface GlobalModelGetPetSettings200Response extends HttpResponse { + status: "200"; + body: PetSettingsOutput; +} diff --git a/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/testServiceClient.ts b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/testServiceClient.ts new file mode 100644 index 0000000000..1d8c6931e5 --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/src/testServiceClient.ts @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { ClientOptions } from "@azure-rest/core-client"; +import { getClient } from "@azure-rest/core-client"; +import { logger } from "./logger.js"; +import type { TestServiceClient } from "./clientDefinitions.js"; + +/** The optional parameters for the client */ +export interface TestServiceClientOptions extends ClientOptions {} + +/** + * Initialize a new instance of `TestServiceClient` + * @param options - the parameter for all optional parameters + */ +export default function createClient(options: TestServiceClientOptions = {}): TestServiceClient { + const endpointUrl = options.endpoint ?? `language`; + const userAgentInfo = `azsdk-js-test-rest/1.0.0-beta.1`; + const userAgentPrefix = + options.userAgentOptions && options.userAgentOptions.userAgentPrefix + ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}` + : `${userAgentInfo}`; + options = { + ...options, + userAgentOptions: { + userAgentPrefix, + }, + loggingOptions: { + logger: options.loggingOptions?.logger ?? logger.info, + }, + }; + const client = getClient(endpointUrl, options) as TestServiceClient; + + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + if (options.apiVersion) { + logger.warning( + "This client does not support client api-version, please change it at the operation level", + ); + } + + return { + ...client, + globalModel: { + getPetSettings: (options) => { + return client.path("/").get(options); + }, + }, + }; +} diff --git a/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/tsconfig.json b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/tsconfig.json new file mode 100644 index 0000000000..031889db45 --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/generated/typespec-ts/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "target": "ES2017", + "module": "NodeNext", + "lib": [], + "declaration": true, + "declarationMap": true, + "inlineSources": true, + "sourceMap": true, + "importHelpers": true, + "strict": true, + "alwaysStrict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "forceConsistentCasingInFileNames": true, + "moduleResolution": "NodeNext", + "allowSyntheticDefaultImports": true, + "esModuleInterop": true + }, + "include": ["src/**/*.ts"] +} diff --git a/packages/typespec-test/test/testRlcGenerate/spec/main.tsp b/packages/typespec-test/test/testRlcGenerate/spec/main.tsp new file mode 100644 index 0000000000..604b228025 --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/spec/main.tsp @@ -0,0 +1,27 @@ +import "@typespec/rest"; +import "@typespec/versioning"; +import "@azure-tools/typespec-azure-core"; + +using TypeSpec.Http; + +@server("language", "Language Service") +@service(#{ title: "Test Service" }) +namespace TestService; + +model DefaultPets { + catList?: CatDef[] = #[#{ catType: "American Shorthair" }]; +} + +model PetSettings { + petList?: { + cat?: DefaultPets.catList; + }; +} + +model CatDef { + catType: string; +} + +interface Global { + getPetSettings(): PetSettings; +} diff --git a/packages/typespec-test/test/testRlcGenerate/tspconfig.yaml b/packages/typespec-test/test/testRlcGenerate/tspconfig.yaml new file mode 100644 index 0000000000..df9e6193fa --- /dev/null +++ b/packages/typespec-test/test/testRlcGenerate/tspconfig.yaml @@ -0,0 +1,12 @@ +emit: + - '@azure-tools/typespec-ts' +options: + "@azure-tools/typespec-ts": + azure-sdk-for-js: false + enable-operation-group: true + include-shortcuts: true + is-modular-library: false + ignore-property-name-normalize: true + emitter-output-dir: "{project-root}/generated/typespec-ts" + package-details: + name: "@msinternal/test" \ No newline at end of file