diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index ed826a7b8d14..3342ddada137 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -488,6 +488,9 @@ dependencies: '@rush-temp/arm-mongocluster': specifier: file:./projects/arm-mongocluster.tgz version: file:projects/arm-mongocluster.tgz + '@rush-temp/arm-mongoclustertest': + specifier: file:./projects/arm-mongoclustertest.tgz + version: file:projects/arm-mongoclustertest.tgz '@rush-temp/arm-monitor': specifier: file:./projects/arm-monitor.tgz version: file:projects/arm-monitor.tgz @@ -3815,7 +3818,7 @@ packages: /@types/express-serve-static-core@4.19.0: resolution: {integrity: sha512-bGyep3JqPCRry1wq+O5n7oiBgGWmeIJXPjXXCo8EK0u8duZGSYar7cGqd3ML2JUsLGeB7fmc06KYo9fLGWqPvQ==} dependencies: - '@types/node': 18.19.43 + '@types/node': 22.1.0 '@types/qs': 6.9.15 '@types/range-parser': 1.2.7 '@types/send': 0.17.4 @@ -3843,7 +3846,7 @@ packages: resolution: {integrity: sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==} dependencies: '@types/jsonfile': 6.1.4 - '@types/node': 18.19.43 + '@types/node': 22.1.0 dev: false /@types/fs-extra@8.1.5: @@ -3886,7 +3889,7 @@ packages: /@types/jsonfile@6.1.4: resolution: {integrity: sha512-D5qGUYwjvnNNextdU59/+fI+spnwtTFmyQP0h+PfIOSkNfpU6AOICUOkm4i0OnSk+NyjdPJrxCDro0sJsWlRpQ==} dependencies: - '@types/node': 18.19.43 + '@types/node': 22.1.0 dev: false /@types/jsonwebtoken@9.0.6: @@ -4012,7 +4015,7 @@ packages: /@types/readdir-glob@1.1.5: resolution: {integrity: sha512-raiuEPUYqXu+nvtY2Pe8s8FEmZ3x5yAH4VkLdihcPdalvsHltomrRC9BzuStrJ9yk06470hS0Crw0f1pXqD+Hg==} dependencies: - '@types/node': 18.19.43 + '@types/node': 22.1.0 dev: false /@types/resolve@1.20.2: @@ -4303,6 +4306,28 @@ packages: vitest: 1.6.0(@types/node@18.19.43)(@vitest/browser@1.6.0) dev: false + /@vitest/browser@1.6.0(playwright@1.46.0)(vitest@1.6.0): + resolution: {integrity: sha512-3Wpp9h1hf++rRVPvoXevkdHybLhJVn7MwIMKMIh08tVaoDMmT6fnNhbP222Z48V9PptpYeA5zvH9Ct/ZcaAzmQ==} + peerDependencies: + playwright: '*' + safaridriver: '*' + vitest: 1.6.0 + webdriverio: '*' + peerDependenciesMeta: + playwright: + optional: true + safaridriver: + optional: true + webdriverio: + optional: true + dependencies: + '@vitest/utils': 1.6.0 + magic-string: 0.30.11 + playwright: 1.46.0 + sirv: 2.0.4 + vitest: 1.6.0(@types/node@18.19.43)(@vitest/browser@1.6.0) + dev: false + /@vitest/browser@2.0.5(playwright@1.45.3)(typescript@5.5.4)(vitest@2.0.5): resolution: {integrity: sha512-VbOYtu/6R3d7ASZREcrJmRY/sQuRFO9wMVsEDqfYbWiJRh2fDNi8CL1Csn7Ux31pOcPmmM5QvzFCMpiojvVh8g==} peerDependencies: @@ -17337,6 +17362,42 @@ packages: - webdriverio dev: false + file:projects/arm-mongoclustertest.tgz: + resolution: {integrity: sha512-qx2sA6etEotgEANaakaQULevuRaWHc7WBg1f+IVg7utvItdKtqh4xXb3lRnFjgZpJqGXpwvS0Iq7NYZe+DYY1g==, tarball: file:projects/arm-mongoclustertest.tgz} + name: '@rush-temp/arm-mongoclustertest' + version: 0.0.0 + dependencies: + '@azure/identity': 4.4.1 + '@microsoft/api-extractor': 7.47.5(@types/node@18.19.43) + '@types/node': 18.19.43 + '@vitest/browser': 1.6.0(playwright@1.46.0)(vitest@1.6.0) + '@vitest/coverage-istanbul': 1.6.0(vitest@1.6.0) + dotenv: 16.4.5 + eslint: 8.57.0 + mkdirp: 3.0.1 + playwright: 1.46.0 + prettier: 3.3.3 + rimraf: 5.0.10 + tshy: 1.18.0 + tslib: 2.6.3 + typescript: 5.5.4 + vitest: 1.6.0(@types/node@18.19.43)(@vitest/browser@1.6.0) + transitivePeerDependencies: + - '@edge-runtime/vm' + - '@vitest/ui' + - happy-dom + - jsdom + - less + - lightningcss + - safaridriver + - sass + - stylus + - sugarss + - supports-color + - terser + - webdriverio + dev: false + file:projects/arm-monitor-profile-2020-09-01-hybrid.tgz: resolution: {integrity: sha512-iIVKSMObhPtllgldBh5d9PvGgh+4/0POUj8UdtW1VsK6bUAx+UtzTjsv2FjIMZ/0nuKBA0NQ678rKS5dppppbw==, tarball: file:projects/arm-monitor-profile-2020-09-01-hybrid.tgz} name: '@rush-temp/arm-monitor-profile-2020-09-01-hybrid' @@ -25516,7 +25577,7 @@ packages: '@types/express-serve-static-core': 4.19.5 '@types/jsonwebtoken': 9.0.6 '@types/node': 18.19.43 - '@vitest/browser': 1.6.0(playwright@1.45.3)(vitest@1.6.0) + '@vitest/browser': 1.6.0(playwright@1.46.0)(vitest@1.6.0) '@vitest/coverage-istanbul': 1.6.0(vitest@1.6.0) dotenv: 16.4.5 eslint: 8.57.0 diff --git a/rush.json b/rush.json index 80efa5f49791..6fd749e1478b 100644 --- a/rush.json +++ b/rush.json @@ -1,7 +1,7 @@ /** * This is the main configuration file for Rush. * For full documentation, please see https://rushjs.io - */ { + */{ "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush.schema.json", /** * (Required) This specifies the version of the Rush engine to be used in this repo. @@ -2261,6 +2261,11 @@ "packageName": "@azure/arm-healthdataaiservices", "projectFolder": "sdk/healthdataaiservices/arm-healthdataaiservices", "versionPolicyName": "client" + }, + { + "packageName": "@azure/arm-mongoclustertest", + "projectFolder": "sdk/mongocluster/arm-mongoclustertest", + "versionPolicyName": "client" } ] -} +} \ No newline at end of file diff --git a/sdk/mongocluster/arm-mongoclustertest/.eslintrc.json b/sdk/mongocluster/arm-mongoclustertest/.eslintrc.json new file mode 100644 index 000000000000..8793fba07e9d --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/.eslintrc.json @@ -0,0 +1,14 @@ +{ + "plugins": ["@azure/azure-sdk"], + "extends": ["plugin:@azure/azure-sdk/azure-sdk-base"], + "rules": { + "@azure/azure-sdk/ts-modules-only-named": "warn", + "@azure/azure-sdk/ts-apiextractor-json-types": "warn", + "@azure/azure-sdk/ts-package-json-types": "warn", + "@azure/azure-sdk/ts-package-json-engine-is-present": "warn", + "tsdoc/syntax": "warn", + "@azure/azure-sdk/ts-package-json-module": "off", + "@azure/azure-sdk/ts-package-json-files-required": "off", + "@azure/azure-sdk/ts-package-json-main-is-cjs": "off" + } +} diff --git a/sdk/mongocluster/arm-mongoclustertest/CHANGELOG.md b/sdk/mongocluster/arm-mongoclustertest/CHANGELOG.md new file mode 100644 index 000000000000..dc85898c69ed --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0-beta.1 (2024-08-15) + + - Initial Release diff --git a/sdk/mongocluster/arm-mongoclustertest/LICENSE b/sdk/mongocluster/arm-mongoclustertest/LICENSE new file mode 100644 index 000000000000..7d5934740965 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2024 Microsoft + +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/sdk/mongocluster/arm-mongoclustertest/README.md b/sdk/mongocluster/arm-mongoclustertest/README.md new file mode 100644 index 000000000000..8adbf25e73de --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/README.md @@ -0,0 +1,105 @@ +# Azure MongoClusterManagement client library for JavaScript + +This package contains an isomorphic SDK (runs both in Node.js and in browsers) for Azure MongoClusterManagement client. + +The Microsoft Azure management API provides create, read, update, and delete functionality for Azure Cosmos DB for MongoDB vCore resources including clusters and firewall rules. + +[Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/mongocluster/arm-mongoclustertest) | +[Package (NPM)](https://www.npmjs.com/package/@azure/arm-mongoclustertest) | +[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/arm-mongoclustertest?view=azure-node-preview) | +[Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/mongocluster/arm-mongoclustertest/samples) + +## Getting started + +### Currently supported environments + +- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule) +- Latest versions of Safari, Chrome, Edge and Firefox. + +See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details. + +### Prerequisites + +- An [Azure subscription][azure_sub]. + +### Install the `@azure/arm-mongoclustertest` package + +Install the Azure MongoClusterManagement client library for JavaScript with `npm`: + +```bash +npm install @azure/arm-mongoclustertest +``` + +### Create and authenticate a `DocumentDBClient` + +To create a client object to access the Azure MongoClusterManagement API, you will need the `endpoint` of your Azure MongoClusterManagement resource and a `credential`. The Azure MongoClusterManagement client can use Azure Active Directory credentials to authenticate. +You can find the endpoint for your Azure MongoClusterManagement resource in the [Azure Portal][azure_portal]. + +You can authenticate with Azure Active Directory using a credential from the [@azure/identity][azure_identity] library or [an existing AAD Token](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token). + +To use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the `@azure/identity` package: + +```bash +npm install @azure/identity +``` + +You will also need to **register a new AAD application and grant access to Azure MongoClusterManagement** by assigning the suitable role to your service principal (note: roles such as `"Owner"` will not grant the necessary permissions). +Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`. + +For more information about how to create an Azure AD Application check out [this guide](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal). + +```javascript +const { DocumentDBClient } = require("@azure/arm-mongoclustertest"); +const { DefaultAzureCredential } = require("@azure/identity"); +// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details. + +const subscriptionId = "00000000-0000-0000-0000-000000000000"; +const client = new DocumentDBClient(new DefaultAzureCredential(), subscriptionId); + +// For client-side applications running in the browser, use this code instead: +// const credential = new InteractiveBrowserCredential({ +// tenantId: "", +// clientId: "" +// }); +// const client = new DocumentDBClient(credential, subscriptionId); +``` + + +### JavaScript Bundle +To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling). + +## Key concepts + +### DocumentDBClient + +`DocumentDBClient` is the primary interface for developers using the Azure MongoClusterManagement client library. Explore the methods on this client object to understand the different features of the Azure MongoClusterManagement service that you can access. + +## 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`: + +```javascript +const { setLogLevel } = require("@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). + +## Next steps + +Please take a look at the [samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/mongocluster/arm-mongoclustertest/samples) directory for detailed examples on how to use this library. + +## Contributing + +If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code. + +## Related projects + +- [Microsoft Azure SDK for JavaScript](https://github.com/Azure/azure-sdk-for-js) + +[azure_sub]: https://azure.microsoft.com/free/ +[azure_portal]: https://portal.azure.com +[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity +[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential diff --git a/sdk/mongocluster/arm-mongoclustertest/api-extractor.json b/sdk/mongocluster/arm-mongoclustertest/api-extractor.json new file mode 100644 index 000000000000..a2cf8712e0dd --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/api-extractor.json @@ -0,0 +1,31 @@ +{ + "$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": "./types/arm-mongoclustertest.d.ts" + }, + "messages": { + "tsdocMessageReporting": { + "default": { + "logLevel": "none" + } + }, + "extractorMessageReporting": { + "ae-missing-release-tag": { + "logLevel": "none" + }, + "ae-unresolved-link": { + "logLevel": "none" + } + } + } +} \ No newline at end of file diff --git a/sdk/mongocluster/arm-mongoclustertest/package.json b/sdk/mongocluster/arm-mongoclustertest/package.json new file mode 100644 index 000000000000..298462e9ca74 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/package.json @@ -0,0 +1,187 @@ +{ + "name": "@azure/arm-mongoclustertest", + "version": "1.0.0-beta.1", + "description": "A generated SDK for DocumentDBClient.", + "engines": { + "node": ">=18.0.0" + }, + "sideEffects": false, + "autoPublish": false, + "tshy": { + "exports": { + "./package.json": "./package.json", + ".": "./src/index.ts", + "./api": "./src/api/index.ts", + "./models": "./src/models/index.ts" + }, + "dialects": [ + "esm", + "commonjs" + ], + "esmDialects": [ + "browser", + "react-native" + ], + "selfLink": false + }, + "type": "module", + "keywords": [ + "node", + "azure", + "cloud", + "typescript", + "browser", + "isomorphic" + ], + "author": "Microsoft Corporation", + "license": "MIT", + "files": [ + "dist", + "README.md", + "LICENSE", + "review/*", + "CHANGELOG.md" + ], + "sdk-type": "mgmt", + "repository": "github:Azure/azure-sdk-for-js", + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/mongocluster/arm-mongoclustertest/README.md", + "prettier": "@azure/eslint-plugin-azure-sdk/prettier.json", + "//metadata": { + "constantPaths": [ + { + "path": "src/rest/documentDBClient.ts", + "prefix": "userAgentInfo" + } + ] + }, + "dependencies": { + "@azure-rest/core-client": "^2.1.0", + "@azure/core-auth": "^1.6.0", + "@azure/core-rest-pipeline": "^1.5.0", + "@azure/logger": "^1.0.0", + "tslib": "^2.6.2", + "@azure/core-lro": "^3.0.0", + "@azure/abort-controller": "^2.1.2", + "@azure/core-paging": "^1.5.0" + }, + "devDependencies": { + "dotenv": "^16.0.0", + "@microsoft/api-extractor": "^7.40.3", + "@types/node": "^18.0.0", + "eslint": "^8.55.0", + "prettier": "^3.2.5", + "rimraf": "^5.0.5", + "mkdirp": "^3.0.1", + "typescript": "~5.5.3", + "tshy": "^1.11.1", + "@azure/core-util": "^1.0.0", + "@azure/identity": "^4.2.1", + "@vitest/browser": "^1.3.1", + "@vitest/coverage-istanbul": "^1.3.1", + "playwright": "^1.41.2", + "vitest": "^1.3.1", + "@azure-tools/test-credential": "^2.0.0", + "@azure-tools/test-recorder": "^4.0.0", + "@azure/dev-tool": "^1.0.0", + "@azure/eslint-plugin-azure-sdk": "^3.0.0" + }, + "scripts": { + "clean": "rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", + "extract-api": "rimraf review && mkdirp ./review && dev-tool run extract-api", + "pack": "npm pack 2>&1", + "lint": "eslint package.json api-extractor.json src test --ext .ts --ext .cts --ext .mts", + "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --ext .cts --ext .mts --fix --fix-type [problem,suggestion]", + "unit-test": "npm run unit-test:node && npm run unit-test:browser", + "unit-test:browser": "npm run build:test && dev-tool run test:vitest --browser", + "unit-test:node": "dev-tool run test:vitest", + "integration-test": "npm run integration-test:node && npm run integration-test:browser", + "integration-test:browser": "echo skipped", + "integration-test:node": "echo skipped", + "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", + "build:samples": "echo skipped", + "check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.{ts,cts,mts}\" \"test/**/*.{ts,cts,mts}\" \"*.{js,cjs,mjs,json}\"", + "execute:samples": "echo skipped", + "format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.{ts,cts,mts}\" \"test/**/*.{ts,cts,mts}\" \"*.{js,cjs,mjs,json}\"", + "generate:client": "echo skipped", + "test:browser": "npm run clean && npm run build:test && npm run unit-test:browser && npm run integration-test:browser", + "minify": "uglifyjs -c -m --comments --source-map \"content='./dist/index.js.map'\" -o ./dist/index.min.js ./dist/index.js", + "build:test": "npm run clean && tshy && dev-tool run build-test", + "build": "npm run clean && tshy && mkdirp ./review && dev-tool run extract-api", + "test:node": "npm run clean && tshy && npm run unit-test:node && npm run integration-test:node", + "test": "npm run clean && tshy && npm run unit-test:node && dev-tool run bundle && npm run unit-test:browser && npm run integration-test" + }, + "exports": { + "./package.json": "./package.json", + ".": { + "browser": { + "source": "./src/index.ts", + "types": "./dist/browser/index.d.ts", + "default": "./dist/browser/index.js" + }, + "react-native": { + "source": "./src/index.ts", + "types": "./dist/react-native/index.d.ts", + "default": "./dist/react-native/index.js" + }, + "import": { + "source": "./src/index.ts", + "types": "./dist/esm/index.d.ts", + "default": "./dist/esm/index.js" + }, + "require": { + "source": "./src/index.ts", + "types": "./dist/commonjs/index.d.ts", + "default": "./dist/commonjs/index.js" + } + }, + "./api": { + "browser": { + "source": "./src/api/index.ts", + "types": "./dist/browser/api/index.d.ts", + "default": "./dist/browser/api/index.js" + }, + "react-native": { + "source": "./src/api/index.ts", + "types": "./dist/react-native/api/index.d.ts", + "default": "./dist/react-native/api/index.js" + }, + "import": { + "source": "./src/api/index.ts", + "types": "./dist/esm/api/index.d.ts", + "default": "./dist/esm/api/index.js" + }, + "require": { + "source": "./src/api/index.ts", + "types": "./dist/commonjs/api/index.d.ts", + "default": "./dist/commonjs/api/index.js" + } + }, + "./models": { + "browser": { + "source": "./src/models/index.ts", + "types": "./dist/browser/models/index.d.ts", + "default": "./dist/browser/models/index.js" + }, + "react-native": { + "source": "./src/models/index.ts", + "types": "./dist/react-native/models/index.d.ts", + "default": "./dist/react-native/models/index.js" + }, + "import": { + "source": "./src/models/index.ts", + "types": "./dist/esm/models/index.d.ts", + "default": "./dist/esm/models/index.js" + }, + "require": { + "source": "./src/models/index.ts", + "types": "./dist/commonjs/models/index.d.ts", + "default": "./dist/commonjs/models/index.js" + } + } + }, + "main": "./dist/commonjs/index.js", + "types": "./dist/commonjs/index.d.ts" +} \ No newline at end of file diff --git a/sdk/mongocluster/arm-mongoclustertest/review/arm-mongoclustertest-api.api.md b/sdk/mongocluster/arm-mongoclustertest/review/arm-mongoclustertest-api.api.md new file mode 100644 index 000000000000..85f34d8a800e --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/review/arm-mongoclustertest-api.api.md @@ -0,0 +1,94 @@ +## API Report File for "@azure/arm-mongoclustertest" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import { Client } from '@azure-rest/core-client'; +import { ClientOptions } from '@azure-rest/core-client'; +import { HttpResponse } from '@azure-rest/core-client'; +import { OperationOptions } from '@azure-rest/core-client'; +import { OperationState } from '@azure/core-lro'; +import { Paged } from '@azure/core-paging'; +import { PollerLike } from '@azure/core-lro'; +import { RawHttpHeaders } from '@azure/core-rest-pipeline'; +import { RequestParameters } from '@azure-rest/core-client'; +import { StreamableMethod } from '@azure-rest/core-client'; +import { TokenCredential } from '@azure/core-auth'; + +// @public +export function createMongoClusterManagement(credential: TokenCredential, options?: MongoClusterManagementClientOptionalParams): DocumentDBContext; + +// @public (undocumented) +export type DocumentDBContext = Client & { + path: Routes; +}; + +// @public +export function firewallRulesCreateOrUpdate(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, firewallRuleName: string, resource: FirewallRule_2, options?: FirewallRulesCreateOrUpdateOptionalParams): PollerLike, FirewallRule_2>; + +// @public +export function firewallRulesDelete(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, firewallRuleName: string, options?: FirewallRulesDeleteOptionalParams): PollerLike, void>; + +// @public +export function firewallRulesGet(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, firewallRuleName: string, options?: FirewallRulesGetOptionalParams): Promise; + +// @public +export function firewallRulesListByMongoCluster(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, options?: FirewallRulesListByMongoClusterOptionalParams): PagedAsyncIterableIterator; + +// @public +export interface MongoClusterManagementClientOptionalParams extends ClientOptions { + apiVersion?: string; +} + +// @public +export function mongoClustersCheckNameAvailability(context: DocumentDBContext, subscriptionId: string, location: string, body: CheckNameAvailabilityRequest_2, options?: MongoClustersCheckNameAvailabilityOptionalParams): Promise; + +// @public +export function mongoClustersCreateOrUpdate(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, resource: MongoCluster_2, options?: MongoClustersCreateOrUpdateOptionalParams): PollerLike, MongoCluster_2>; + +// @public +export function mongoClustersDelete(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, options?: MongoClustersDeleteOptionalParams): PollerLike, void>; + +// @public +export function mongoClustersGet(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, options?: MongoClustersGetOptionalParams): Promise; + +// @public +export function mongoClustersList(context: DocumentDBContext, subscriptionId: string, options?: MongoClustersListOptionalParams): PagedAsyncIterableIterator; + +// @public +export function mongoClustersListByResourceGroup(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, options?: MongoClustersListByResourceGroupOptionalParams): PagedAsyncIterableIterator; + +// @public +export function mongoClustersListConnectionStrings(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, options?: MongoClustersListConnectionStringsOptionalParams): Promise; + +// @public +export function mongoClustersPromote(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, body: PromoteReplicaRequest_2, options?: MongoClustersPromoteOptionalParams): PollerLike, void>; + +// @public +export function mongoClustersUpdate(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, properties: MongoClusterUpdate_2, options?: MongoClustersUpdateOptionalParams): PollerLike, MongoCluster_2>; + +// @public +export function operationsList(context: DocumentDBContext, options?: OperationsListOptionalParams): PagedAsyncIterableIterator; + +// @public +export function privateEndpointConnectionsCreate(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, privateEndpointConnectionName: string, resource: PrivateEndpointConnectionResource_2, options?: PrivateEndpointConnectionsCreateOptionalParams): PollerLike, PrivateEndpointConnectionResource_2>; + +// @public +export function privateEndpointConnectionsDelete(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, privateEndpointConnectionName: string, options?: PrivateEndpointConnectionsDeleteOptionalParams): PollerLike, void>; + +// @public +export function privateEndpointConnectionsGet(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, privateEndpointConnectionName: string, options?: PrivateEndpointConnectionsGetOptionalParams): Promise; + +// @public +export function privateEndpointConnectionsListByMongoCluster(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, options?: PrivateEndpointConnectionsListByMongoClusterOptionalParams): PagedAsyncIterableIterator; + +// @public +export function privateLinksListByMongoCluster(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, options?: PrivateLinksListByMongoClusterOptionalParams): PagedAsyncIterableIterator; + +// @public +export function replicasListByParent(context: DocumentDBContext, subscriptionId: string, resourceGroupName: string, mongoClusterName: string, options?: ReplicasListByParentOptionalParams): PagedAsyncIterableIterator; + +// (No @packageDocumentation comment for this package) + +``` diff --git a/sdk/mongocluster/arm-mongoclustertest/review/arm-mongoclustertest-models.api.md b/sdk/mongocluster/arm-mongoclustertest/review/arm-mongoclustertest-models.api.md new file mode 100644 index 000000000000..85cc23f5acf2 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/review/arm-mongoclustertest-models.api.md @@ -0,0 +1,503 @@ +## API Report File for "@azure/arm-mongoclustertest" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import { OperationOptions } from '@azure-rest/core-client'; + +// @public +export type ActionType = string; + +// @public +export type CheckNameAvailabilityReason = string; + +// @public +export interface CheckNameAvailabilityRequest { + name?: string; + type?: string; +} + +// @public +export interface CheckNameAvailabilityResponse { + message?: string; + nameAvailable?: boolean; + reason?: CheckNameAvailabilityReason; +} + +// @public +export interface ConnectionString { + readonly connectionString?: string; + readonly description?: string; +} + +// @public +export type ContinuablePage = TPage & { + continuationToken?: string; +}; + +// @public +export type CreatedByType = string; + +// @public +export type CreateMode = string; + +// @public +export interface ErrorAdditionalInfo { + readonly info?: Record; + readonly type?: string; +} + +// @public +export interface ErrorDetail { + readonly additionalInfo?: ErrorAdditionalInfo[]; + readonly code?: string; + readonly details?: ErrorDetail[]; + readonly message?: string; + readonly target?: string; +} + +// @public +export interface ErrorResponse { + error?: ErrorDetail; +} + +// @public +export interface FirewallRule extends ProxyResource { + properties?: FirewallRuleProperties; +} + +// @public +export interface FirewallRuleProperties { + endIpAddress: string; + readonly provisioningState?: ProvisioningState; + startIpAddress: string; +} + +// @public +export interface FirewallRulesCreateOrUpdateOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export interface FirewallRulesDeleteOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export interface FirewallRulesGetOptionalParams extends OperationOptions { +} + +// @public +export interface FirewallRulesListByMongoClusterOptionalParams extends OperationOptions { +} + +// @public +export enum KnownActionType { + Internal = "Internal" +} + +// @public +export enum KnownCheckNameAvailabilityReason { + AlreadyExists = "AlreadyExists", + Invalid = "Invalid" +} + +// @public +export enum KnownCreatedByType { + Application = "Application", + Key = "Key", + ManagedIdentity = "ManagedIdentity", + User = "User" +} + +// @public +export enum KnownCreateMode { + Default = "Default", + GeoReplica = "GeoReplica", + PointInTimeRestore = "PointInTimeRestore", + Replica = "Replica" +} + +// @public +export enum KnownMongoClusterStatus { + Dropping = "Dropping", + Provisioning = "Provisioning", + Ready = "Ready", + Starting = "Starting", + Stopped = "Stopped", + Stopping = "Stopping", + Updating = "Updating" +} + +// @public +export enum KnownNodeKind { + Shard = "Shard" +} + +// @public +export enum KnownOrigin { + "user,system" = "user,system", + system = "system", + user = "user" +} + +// @public +export enum KnownPreviewFeature { + GeoReplicas = "GeoReplicas" +} + +// @public +export enum KnownPrivateEndpointConnectionProvisioningState { + Creating = "Creating", + Deleting = "Deleting", + Failed = "Failed", + Succeeded = "Succeeded" +} + +// @public +export enum KnownPrivateEndpointServiceConnectionStatus { + Approved = "Approved", + Pending = "Pending", + Rejected = "Rejected" +} + +// @public +export enum KnownPromoteMode { + Switchover = "Switchover" +} + +// @public +export enum KnownPromoteOption { + Forced = "Forced" +} + +// @public +export enum KnownPublicNetworkAccess { + Disabled = "Disabled", + Enabled = "Enabled" +} + +// @public +export enum KnownReplicationRole { + AsyncReplica = "AsyncReplica", + GeoAsyncReplica = "GeoAsyncReplica", + Primary = "Primary" +} + +// @public +export enum KnownReplicationState { + Active = "Active", + Broken = "Broken", + Catchup = "Catchup", + Provisioning = "Provisioning", + Reconfiguring = "Reconfiguring", + Updating = "Updating" +} + +// @public +export enum KnownResourceProvisioningState { + Canceled = "Canceled", + Failed = "Failed", + Succeeded = "Succeeded" +} + +// @public +export interface ListConnectionStringsResult { + readonly connectionStrings?: ConnectionString[]; +} + +// @public +export interface MongoCluster extends TrackedResource { + properties?: MongoClusterProperties; +} + +// @public +export interface MongoClusterProperties { + administratorLogin?: string; + administratorLoginPassword?: string; + readonly clusterStatus?: MongoClusterStatus; + readonly connectionString?: string; + createMode?: CreateMode; + readonly earliestRestoreTime?: string; + readonly infrastructureVersion?: string; + nodeGroupSpecs?: NodeGroupSpec[]; + previewFeatures?: PreviewFeature[]; + readonly privateEndpointConnections?: PrivateEndpointConnection[]; + readonly provisioningState?: ProvisioningState; + publicNetworkAccess?: PublicNetworkAccess; + readonly replica?: ReplicationProperties; + replicaParameters?: MongoClusterReplicaParameters; + restoreParameters?: MongoClusterRestoreParameters; + serverVersion?: string; +} + +// @public +export interface MongoClusterReplicaParameters { + sourceLocation: string; + sourceResourceId: string; +} + +// @public +export interface MongoClusterRestoreParameters { + pointInTimeUTC?: Date; + sourceResourceId?: string; +} + +// @public +export interface MongoClustersCheckNameAvailabilityOptionalParams extends OperationOptions { +} + +// @public +export interface MongoClustersCreateOrUpdateOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export interface MongoClustersDeleteOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export interface MongoClustersGetOptionalParams extends OperationOptions { +} + +// @public +export interface MongoClustersListByResourceGroupOptionalParams extends OperationOptions { +} + +// @public +export interface MongoClustersListConnectionStringsOptionalParams extends OperationOptions { +} + +// @public +export interface MongoClustersListOptionalParams extends OperationOptions { +} + +// @public +export interface MongoClustersPromoteOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export type MongoClusterStatus = string; + +// @public +export interface MongoClustersUpdateOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export interface MongoClusterUpdate { + properties?: MongoClusterUpdateProperties; + tags?: Record; +} + +// @public +export interface MongoClusterUpdateProperties { + administratorLogin?: string; + administratorLoginPassword?: string; + nodeGroupSpecs?: NodeGroupSpec[]; + previewFeatures?: PreviewFeature[]; + publicNetworkAccess?: PublicNetworkAccess; + serverVersion?: string; +} + +// @public +export interface NodeGroupSpec { + diskSizeGB?: number; + enableHa?: boolean; + kind?: NodeKind; + nodeCount?: number; + sku?: string; +} + +// @public +export type NodeKind = string; + +// @public +export interface Operation { + actionType?: ActionType; + readonly display?: OperationDisplay; + readonly isDataAction?: boolean; + readonly name?: string; + readonly origin?: Origin; +} + +// @public +export interface OperationDisplay { + readonly description?: string; + readonly operation?: string; + readonly provider?: string; + readonly resource?: string; +} + +// @public +export interface OperationsListOptionalParams extends OperationOptions { +} + +// @public +export type Origin = string; + +// @public +export interface PagedAsyncIterableIterator { + [Symbol.asyncIterator](): PagedAsyncIterableIterator; + byPage: (settings?: TPageSettings) => AsyncIterableIterator>; + next(): Promise>; +} + +// @public +export interface PageSettings { + continuationToken?: string; +} + +// @public +export type PreviewFeature = string; + +// @public +export interface PrivateEndpoint { + readonly id?: string; +} + +// @public +export interface PrivateEndpointConnection extends Resource { + properties?: PrivateEndpointConnectionProperties; +} + +// @public +export interface PrivateEndpointConnectionProperties { + readonly groupIds?: string[]; + privateEndpoint?: PrivateEndpoint; + privateLinkServiceConnectionState: PrivateLinkServiceConnectionState; + readonly provisioningState?: PrivateEndpointConnectionProvisioningState; +} + +// @public +export type PrivateEndpointConnectionProvisioningState = string; + +// @public +export interface PrivateEndpointConnectionResource extends ProxyResource { + properties?: PrivateEndpointConnectionProperties; +} + +// @public +export interface PrivateEndpointConnectionsCreateOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export interface PrivateEndpointConnectionsDeleteOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export interface PrivateEndpointConnectionsGetOptionalParams extends OperationOptions { +} + +// @public +export interface PrivateEndpointConnectionsListByMongoClusterOptionalParams extends OperationOptions { +} + +// @public +export type PrivateEndpointServiceConnectionStatus = string; + +// @public +export interface PrivateLinkResource extends ProxyResource { + properties?: PrivateLinkResourceProperties; +} + +// @public +export interface PrivateLinkResourceProperties { + readonly groupId?: string; + readonly requiredMembers?: string[]; + requiredZoneNames?: string[]; +} + +// @public +export interface PrivateLinkServiceConnectionState { + actionsRequired?: string; + description?: string; + status?: PrivateEndpointServiceConnectionStatus; +} + +// @public +export interface PrivateLinksListByMongoClusterOptionalParams extends OperationOptions { +} + +// @public +export type PromoteMode = string; + +// @public +export type PromoteOption = string; + +// @public +export interface PromoteReplicaRequest { + mode?: PromoteMode; + promoteOption: PromoteOption; +} + +// @public +export type ProvisioningState = string | ResourceProvisioningState | "InProgress" | "Updating" | "Dropping"; + +// @public +export interface ProxyResource extends Resource { +} + +// @public +export type PublicNetworkAccess = string; + +// @public +export interface Replica extends ProxyResource { + properties?: MongoClusterProperties; +} + +// @public +export interface ReplicasListByParentOptionalParams extends OperationOptions { +} + +// @public +export interface ReplicationProperties { + readonly replicationState?: ReplicationState; + readonly role?: ReplicationRole; + readonly sourceResourceId?: string; +} + +// @public +export type ReplicationRole = string; + +// @public +export type ReplicationState = string; + +// @public +export interface Resource { + readonly id?: string; + readonly name?: string; + readonly systemData?: SystemData; + readonly type?: string; +} + +// @public +export type ResourceProvisioningState = string; + +// @public +export interface SystemData { + createdAt?: Date; + createdBy?: string; + createdByType?: CreatedByType; + lastModifiedAt?: Date; + lastModifiedBy?: string; + lastModifiedByType?: CreatedByType; +} + +// @public +export interface TrackedResource extends Resource { + location: string; + tags?: Record; +} + +// @public +export type Versions = "2024-03-01-preview" | "2024-06-01-preview"; + +// (No @packageDocumentation comment for this package) + +``` diff --git a/sdk/mongocluster/arm-mongoclustertest/review/arm-mongoclustertest.api.md b/sdk/mongocluster/arm-mongoclustertest/review/arm-mongoclustertest.api.md new file mode 100644 index 000000000000..3fd8b4f5b351 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/review/arm-mongoclustertest.api.md @@ -0,0 +1,581 @@ +## API Report File for "@azure/arm-mongoclustertest" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import { AbortSignalLike } from '@azure/abort-controller'; +import { ClientOptions } from '@azure-rest/core-client'; +import { OperationOptions } from '@azure-rest/core-client'; +import { OperationState } from '@azure/core-lro'; +import { PathUncheckedResponse } from '@azure-rest/core-client'; +import { Pipeline } from '@azure/core-rest-pipeline'; +import { PollerLike } from '@azure/core-lro'; +import { TokenCredential } from '@azure/core-auth'; + +// @public +export type ActionType = string; + +// @public +export type CheckNameAvailabilityReason = string; + +// @public +export interface CheckNameAvailabilityRequest { + name?: string; + type?: string; +} + +// @public +export interface CheckNameAvailabilityResponse { + message?: string; + nameAvailable?: boolean; + reason?: CheckNameAvailabilityReason; +} + +// @public +export interface ConnectionString { + readonly connectionString?: string; + readonly description?: string; +} + +// @public +export type ContinuablePage = TPage & { + continuationToken?: string; +}; + +// @public +export type CreatedByType = string; + +// @public +export type CreateMode = string; + +// @public +export interface ErrorAdditionalInfo { + readonly info?: Record; + readonly type?: string; +} + +// @public +export interface ErrorDetail { + readonly additionalInfo?: ErrorAdditionalInfo[]; + readonly code?: string; + readonly details?: ErrorDetail[]; + readonly message?: string; + readonly target?: string; +} + +// @public +export interface ErrorResponse { + error?: ErrorDetail; +} + +// @public +export interface FirewallRule extends ProxyResource { + properties?: FirewallRuleProperties; +} + +// @public +export interface FirewallRuleProperties { + endIpAddress: string; + readonly provisioningState?: ProvisioningState; + startIpAddress: string; +} + +// @public +export interface FirewallRulesCreateOrUpdateOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export interface FirewallRulesDeleteOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export interface FirewallRulesGetOptionalParams extends OperationOptions { +} + +// @public +export interface FirewallRulesListByMongoClusterOptionalParams extends OperationOptions { +} + +// @public +export interface FirewallRulesOperations { + createOrUpdate: (resourceGroupName: string, mongoClusterName: string, firewallRuleName: string, resource: FirewallRule, options?: FirewallRulesCreateOrUpdateOptionalParams) => PollerLike, FirewallRule>; + delete: (resourceGroupName: string, mongoClusterName: string, firewallRuleName: string, options?: FirewallRulesDeleteOptionalParams) => PollerLike, void>; + get: (resourceGroupName: string, mongoClusterName: string, firewallRuleName: string, options?: FirewallRulesGetOptionalParams) => Promise; + listByMongoCluster: (resourceGroupName: string, mongoClusterName: string, options?: FirewallRulesListByMongoClusterOptionalParams) => PagedAsyncIterableIterator; +} + +// @public +export enum KnownActionType { + Internal = "Internal" +} + +// @public +export enum KnownCheckNameAvailabilityReason { + AlreadyExists = "AlreadyExists", + Invalid = "Invalid" +} + +// @public +export enum KnownCreatedByType { + Application = "Application", + Key = "Key", + ManagedIdentity = "ManagedIdentity", + User = "User" +} + +// @public +export enum KnownCreateMode { + Default = "Default", + GeoReplica = "GeoReplica", + PointInTimeRestore = "PointInTimeRestore", + Replica = "Replica" +} + +// @public +export enum KnownMongoClusterStatus { + Dropping = "Dropping", + Provisioning = "Provisioning", + Ready = "Ready", + Starting = "Starting", + Stopped = "Stopped", + Stopping = "Stopping", + Updating = "Updating" +} + +// @public +export enum KnownNodeKind { + Shard = "Shard" +} + +// @public +export enum KnownOrigin { + "user,system" = "user,system", + system = "system", + user = "user" +} + +// @public +export enum KnownPreviewFeature { + GeoReplicas = "GeoReplicas" +} + +// @public +export enum KnownPrivateEndpointConnectionProvisioningState { + Creating = "Creating", + Deleting = "Deleting", + Failed = "Failed", + Succeeded = "Succeeded" +} + +// @public +export enum KnownPrivateEndpointServiceConnectionStatus { + Approved = "Approved", + Pending = "Pending", + Rejected = "Rejected" +} + +// @public +export enum KnownPromoteMode { + Switchover = "Switchover" +} + +// @public +export enum KnownPromoteOption { + Forced = "Forced" +} + +// @public +export enum KnownPublicNetworkAccess { + Disabled = "Disabled", + Enabled = "Enabled" +} + +// @public +export enum KnownReplicationRole { + AsyncReplica = "AsyncReplica", + GeoAsyncReplica = "GeoAsyncReplica", + Primary = "Primary" +} + +// @public +export enum KnownReplicationState { + Active = "Active", + Broken = "Broken", + Catchup = "Catchup", + Provisioning = "Provisioning", + Reconfiguring = "Reconfiguring", + Updating = "Updating" +} + +// @public +export enum KnownResourceProvisioningState { + Canceled = "Canceled", + Failed = "Failed", + Succeeded = "Succeeded" +} + +// @public +export interface ListConnectionStringsResult { + readonly connectionStrings?: ConnectionString[]; +} + +// @public +export interface MongoCluster extends TrackedResource { + properties?: MongoClusterProperties; +} + +// @public (undocumented) +export class MongoClusterManagementClient { + constructor(credential: TokenCredential, subscriptionId: string, options?: MongoClusterManagementClientOptionalParams); + readonly firewallRules: FirewallRulesOperations; + readonly mongoClusters: MongoClustersOperations; + readonly operations: OperationsOperations; + readonly pipeline: Pipeline; + readonly privateEndpointConnections: PrivateEndpointConnectionsOperations; + readonly privateLinks: PrivateLinksOperations; + readonly replicas: ReplicasOperations; +} + +// @public +export interface MongoClusterManagementClientOptionalParams extends ClientOptions { + apiVersion?: string; +} + +// @public +export interface MongoClusterProperties { + administratorLogin?: string; + administratorLoginPassword?: string; + readonly clusterStatus?: MongoClusterStatus; + readonly connectionString?: string; + createMode?: CreateMode; + readonly earliestRestoreTime?: string; + readonly infrastructureVersion?: string; + nodeGroupSpecs?: NodeGroupSpec[]; + previewFeatures?: PreviewFeature[]; + readonly privateEndpointConnections?: PrivateEndpointConnection[]; + readonly provisioningState?: ProvisioningState; + publicNetworkAccess?: PublicNetworkAccess; + readonly replica?: ReplicationProperties; + replicaParameters?: MongoClusterReplicaParameters; + restoreParameters?: MongoClusterRestoreParameters; + serverVersion?: string; +} + +// @public +export interface MongoClusterReplicaParameters { + sourceLocation: string; + sourceResourceId: string; +} + +// @public +export interface MongoClusterRestoreParameters { + pointInTimeUTC?: Date; + sourceResourceId?: string; +} + +// @public +export interface MongoClustersCheckNameAvailabilityOptionalParams extends OperationOptions { +} + +// @public +export interface MongoClustersCreateOrUpdateOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export interface MongoClustersDeleteOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export interface MongoClustersGetOptionalParams extends OperationOptions { +} + +// @public +export interface MongoClustersListByResourceGroupOptionalParams extends OperationOptions { +} + +// @public +export interface MongoClustersListConnectionStringsOptionalParams extends OperationOptions { +} + +// @public +export interface MongoClustersListOptionalParams extends OperationOptions { +} + +// @public +export interface MongoClustersOperations { + checkNameAvailability: (location: string, body: CheckNameAvailabilityRequest, options?: MongoClustersCheckNameAvailabilityOptionalParams) => Promise; + createOrUpdate: (resourceGroupName: string, mongoClusterName: string, resource: MongoCluster, options?: MongoClustersCreateOrUpdateOptionalParams) => PollerLike, MongoCluster>; + delete: (resourceGroupName: string, mongoClusterName: string, options?: MongoClustersDeleteOptionalParams) => PollerLike, void>; + get: (resourceGroupName: string, mongoClusterName: string, options?: MongoClustersGetOptionalParams) => Promise; + list: (options?: MongoClustersListOptionalParams) => PagedAsyncIterableIterator; + listByResourceGroup: (resourceGroupName: string, options?: MongoClustersListByResourceGroupOptionalParams) => PagedAsyncIterableIterator; + listConnectionStrings: (resourceGroupName: string, mongoClusterName: string, options?: MongoClustersListConnectionStringsOptionalParams) => Promise; + promote: (resourceGroupName: string, mongoClusterName: string, body: PromoteReplicaRequest, options?: MongoClustersPromoteOptionalParams) => PollerLike, void>; + update: (resourceGroupName: string, mongoClusterName: string, properties: MongoClusterUpdate, options?: MongoClustersUpdateOptionalParams) => PollerLike, MongoCluster>; +} + +// @public +export interface MongoClustersPromoteOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export type MongoClusterStatus = string; + +// @public +export interface MongoClustersUpdateOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export interface MongoClusterUpdate { + properties?: MongoClusterUpdateProperties; + tags?: Record; +} + +// @public +export interface MongoClusterUpdateProperties { + administratorLogin?: string; + administratorLoginPassword?: string; + nodeGroupSpecs?: NodeGroupSpec[]; + previewFeatures?: PreviewFeature[]; + publicNetworkAccess?: PublicNetworkAccess; + serverVersion?: string; +} + +// @public +export interface NodeGroupSpec { + diskSizeGB?: number; + enableHa?: boolean; + kind?: NodeKind; + nodeCount?: number; + sku?: string; +} + +// @public +export type NodeKind = string; + +// @public +export interface Operation { + actionType?: ActionType; + readonly display?: OperationDisplay; + readonly isDataAction?: boolean; + readonly name?: string; + readonly origin?: Origin; +} + +// @public +export interface OperationDisplay { + readonly description?: string; + readonly operation?: string; + readonly provider?: string; + readonly resource?: string; +} + +// @public +export interface OperationsListOptionalParams extends OperationOptions { +} + +// @public +export interface OperationsOperations { + list: (options?: OperationsListOptionalParams) => PagedAsyncIterableIterator; +} + +// @public +export type Origin = string; + +// @public +export interface PagedAsyncIterableIterator { + [Symbol.asyncIterator](): PagedAsyncIterableIterator; + byPage: (settings?: TPageSettings) => AsyncIterableIterator>; + next(): Promise>; +} + +// @public +export interface PageSettings { + continuationToken?: string; +} + +// @public +export type PreviewFeature = string; + +// @public +export interface PrivateEndpoint { + readonly id?: string; +} + +// @public +export interface PrivateEndpointConnection extends Resource { + properties?: PrivateEndpointConnectionProperties; +} + +// @public +export interface PrivateEndpointConnectionProperties { + readonly groupIds?: string[]; + privateEndpoint?: PrivateEndpoint; + privateLinkServiceConnectionState: PrivateLinkServiceConnectionState; + readonly provisioningState?: PrivateEndpointConnectionProvisioningState; +} + +// @public +export type PrivateEndpointConnectionProvisioningState = string; + +// @public +export interface PrivateEndpointConnectionResource extends ProxyResource { + properties?: PrivateEndpointConnectionProperties; +} + +// @public +export interface PrivateEndpointConnectionsCreateOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export interface PrivateEndpointConnectionsDeleteOptionalParams extends OperationOptions { + updateIntervalInMs?: number; +} + +// @public +export interface PrivateEndpointConnectionsGetOptionalParams extends OperationOptions { +} + +// @public +export interface PrivateEndpointConnectionsListByMongoClusterOptionalParams extends OperationOptions { +} + +// @public +export interface PrivateEndpointConnectionsOperations { + create: (resourceGroupName: string, mongoClusterName: string, privateEndpointConnectionName: string, resource: PrivateEndpointConnectionResource, options?: PrivateEndpointConnectionsCreateOptionalParams) => PollerLike, PrivateEndpointConnectionResource>; + delete: (resourceGroupName: string, mongoClusterName: string, privateEndpointConnectionName: string, options?: PrivateEndpointConnectionsDeleteOptionalParams) => PollerLike, void>; + get: (resourceGroupName: string, mongoClusterName: string, privateEndpointConnectionName: string, options?: PrivateEndpointConnectionsGetOptionalParams) => Promise; + listByMongoCluster: (resourceGroupName: string, mongoClusterName: string, options?: PrivateEndpointConnectionsListByMongoClusterOptionalParams) => PagedAsyncIterableIterator; +} + +// @public +export type PrivateEndpointServiceConnectionStatus = string; + +// @public +export interface PrivateLinkResource extends ProxyResource { + properties?: PrivateLinkResourceProperties; +} + +// @public +export interface PrivateLinkResourceProperties { + readonly groupId?: string; + readonly requiredMembers?: string[]; + requiredZoneNames?: string[]; +} + +// @public +export interface PrivateLinkServiceConnectionState { + actionsRequired?: string; + description?: string; + status?: PrivateEndpointServiceConnectionStatus; +} + +// @public +export interface PrivateLinksListByMongoClusterOptionalParams extends OperationOptions { +} + +// @public +export interface PrivateLinksOperations { + listByMongoCluster: (resourceGroupName: string, mongoClusterName: string, options?: PrivateLinksListByMongoClusterOptionalParams) => PagedAsyncIterableIterator; +} + +// @public +export type PromoteMode = string; + +// @public +export type PromoteOption = string; + +// @public +export interface PromoteReplicaRequest { + mode?: PromoteMode; + promoteOption: PromoteOption; +} + +// @public +export type ProvisioningState = string | ResourceProvisioningState | "InProgress" | "Updating" | "Dropping"; + +// @public +export interface ProxyResource extends Resource { +} + +// @public +export type PublicNetworkAccess = string; + +// @public +export interface Replica extends ProxyResource { + properties?: MongoClusterProperties; +} + +// @public +export interface ReplicasListByParentOptionalParams extends OperationOptions { +} + +// @public +export interface ReplicasOperations { + listByParent: (resourceGroupName: string, mongoClusterName: string, options?: ReplicasListByParentOptionalParams) => PagedAsyncIterableIterator; +} + +// @public +export interface ReplicationProperties { + readonly replicationState?: ReplicationState; + readonly role?: ReplicationRole; + readonly sourceResourceId?: string; +} + +// @public +export type ReplicationRole = string; + +// @public +export type ReplicationState = string; + +// @public +export interface Resource { + readonly id?: string; + readonly name?: string; + readonly systemData?: SystemData; + readonly type?: string; +} + +// @public +export type ResourceProvisioningState = string; + +// @public +export function restorePoller(client: MongoClusterManagementClient, serializedState: string, sourceOperation: (...args: any[]) => PollerLike, TResult>, options?: RestorePollerOptions): PollerLike, TResult>; + +// @public (undocumented) +export interface RestorePollerOptions extends OperationOptions { + abortSignal?: AbortSignalLike; + processResponseBody?: (result: TResponse) => Promise; + updateIntervalInMs?: number; +} + +// @public +export interface SystemData { + createdAt?: Date; + createdBy?: string; + createdByType?: CreatedByType; + lastModifiedAt?: Date; + lastModifiedBy?: string; + lastModifiedByType?: CreatedByType; +} + +// @public +export interface TrackedResource extends Resource { + location: string; + tags?: Record; +} + +// @public +export type Versions = "2024-03-01-preview" | "2024-06-01-preview"; + +// (No @packageDocumentation comment for this package) + +``` diff --git a/sdk/mongocluster/arm-mongoclustertest/src/api/firewallRules/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/api/firewallRules/index.ts new file mode 100644 index 000000000000..eac070320714 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/api/firewallRules/index.ts @@ -0,0 +1,377 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { getLongRunningPoller } from "../pollingHelpers.js"; +import { PollerLike, OperationState } from "@azure/core-lro"; +import { + firewallRulePropertiesSerializer, + FirewallRule, + _FirewallRuleListResult, +} from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js"; +import { buildPagedAsyncIterator } from "../pagingHelpers.js"; +import { + isUnexpected, + DocumentDBContext as Client, + FirewallRulesCreateOrUpdate200Response, + FirewallRulesCreateOrUpdate201Response, + FirewallRulesCreateOrUpdate202Response, + FirewallRulesCreateOrUpdateDefaultResponse, + FirewallRulesCreateOrUpdateLogicalResponse, + FirewallRulesDelete202Response, + FirewallRulesDelete204Response, + FirewallRulesDeleteDefaultResponse, + FirewallRulesDeleteLogicalResponse, + FirewallRulesGet200Response, + FirewallRulesGetDefaultResponse, + FirewallRulesListByMongoCluster200Response, + FirewallRulesListByMongoClusterDefaultResponse, +} from "../../rest/index.js"; +import { + StreamableMethod, + operationOptionsToRequestParameters, + createRestError, +} from "@azure-rest/core-client"; +import { + FirewallRulesGetOptionalParams, + FirewallRulesCreateOrUpdateOptionalParams, + FirewallRulesDeleteOptionalParams, + FirewallRulesListByMongoClusterOptionalParams, +} from "../../models/options.js"; + +export function _firewallRulesGetSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + firewallRuleName: string, + options: FirewallRulesGetOptionalParams = { requestOptions: {} }, +): StreamableMethod< + FirewallRulesGet200Response | FirewallRulesGetDefaultResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/firewallRules/{firewallRuleName}", + subscriptionId, + resourceGroupName, + mongoClusterName, + firewallRuleName, + ) + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _firewallRulesGetDeserialize( + result: FirewallRulesGet200Response | FirewallRulesGetDefaultResponse, +): Promise { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return { + id: result.body["id"], + name: result.body["name"], + type: result.body["type"], + systemData: !result.body.systemData + ? undefined + : { + createdBy: result.body.systemData?.["createdBy"], + createdByType: result.body.systemData?.["createdByType"], + createdAt: + result.body.systemData?.["createdAt"] !== undefined + ? new Date(result.body.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: result.body.systemData?.["lastModifiedBy"], + lastModifiedByType: result.body.systemData?.["lastModifiedByType"], + lastModifiedAt: + result.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(result.body.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !result.body.properties + ? undefined + : { + provisioningState: result.body.properties?.["provisioningState"], + startIpAddress: result.body.properties?.["startIpAddress"], + endIpAddress: result.body.properties?.["endIpAddress"], + }, + }; +} + +/** Gets information about a mongo cluster firewall rule. */ +export async function firewallRulesGet( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + firewallRuleName: string, + options: FirewallRulesGetOptionalParams = { requestOptions: {} }, +): Promise { + const result = await _firewallRulesGetSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + firewallRuleName, + options, + ); + return _firewallRulesGetDeserialize(result); +} + +export function _firewallRulesCreateOrUpdateSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + firewallRuleName: string, + resource: FirewallRule, + options: FirewallRulesCreateOrUpdateOptionalParams = { requestOptions: {} }, +): StreamableMethod< + | FirewallRulesCreateOrUpdate200Response + | FirewallRulesCreateOrUpdate201Response + | FirewallRulesCreateOrUpdate202Response + | FirewallRulesCreateOrUpdateDefaultResponse + | FirewallRulesCreateOrUpdateLogicalResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/firewallRules/{firewallRuleName}", + subscriptionId, + resourceGroupName, + mongoClusterName, + firewallRuleName, + ) + .put({ + ...operationOptionsToRequestParameters(options), + body: { + properties: !resource.properties + ? resource.properties + : firewallRulePropertiesSerializer(resource.properties), + }, + }); +} + +export async function _firewallRulesCreateOrUpdateDeserialize( + result: + | FirewallRulesCreateOrUpdate200Response + | FirewallRulesCreateOrUpdate201Response + | FirewallRulesCreateOrUpdate202Response + | FirewallRulesCreateOrUpdateDefaultResponse + | FirewallRulesCreateOrUpdateLogicalResponse, +): Promise { + if (isUnexpected(result)) { + throw createRestError(result); + } + + const res = result as unknown as FirewallRulesCreateOrUpdateLogicalResponse; + return { + id: res.body["id"], + name: res.body["name"], + type: res.body["type"], + systemData: !res.body.systemData + ? undefined + : { + createdBy: res.body.systemData?.["createdBy"], + createdByType: res.body.systemData?.["createdByType"], + createdAt: + res.body.systemData?.["createdAt"] !== undefined + ? new Date(res.body.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: res.body.systemData?.["lastModifiedBy"], + lastModifiedByType: res.body.systemData?.["lastModifiedByType"], + lastModifiedAt: + res.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(res.body.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !res.body.properties + ? undefined + : { + provisioningState: res.body.properties?.["provisioningState"], + startIpAddress: res.body.properties?.["startIpAddress"], + endIpAddress: res.body.properties?.["endIpAddress"], + }, + }; +} + +/** Creates a new firewall rule or updates an existing firewall rule on a mongo cluster. */ +export function firewallRulesCreateOrUpdate( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + firewallRuleName: string, + resource: FirewallRule, + options: FirewallRulesCreateOrUpdateOptionalParams = { requestOptions: {} }, +): PollerLike, FirewallRule> { + return getLongRunningPoller( + context, + _firewallRulesCreateOrUpdateDeserialize, + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _firewallRulesCreateOrUpdateSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + firewallRuleName, + resource, + options, + ), + }, + ) as PollerLike, FirewallRule>; +} + +export function _firewallRulesDeleteSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + firewallRuleName: string, + options: FirewallRulesDeleteOptionalParams = { requestOptions: {} }, +): StreamableMethod< + | FirewallRulesDelete202Response + | FirewallRulesDelete204Response + | FirewallRulesDeleteDefaultResponse + | FirewallRulesDeleteLogicalResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/firewallRules/{firewallRuleName}", + subscriptionId, + resourceGroupName, + mongoClusterName, + firewallRuleName, + ) + .delete({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _firewallRulesDeleteDeserialize( + result: + | FirewallRulesDelete202Response + | FirewallRulesDelete204Response + | FirewallRulesDeleteDefaultResponse + | FirewallRulesDeleteLogicalResponse, +): Promise { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return; +} + +/** Deletes a mongo cluster firewall rule. */ +export function firewallRulesDelete( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + firewallRuleName: string, + options: FirewallRulesDeleteOptionalParams = { requestOptions: {} }, +): PollerLike, void> { + return getLongRunningPoller(context, _firewallRulesDeleteDeserialize, { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _firewallRulesDeleteSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + firewallRuleName, + options, + ), + }) as PollerLike, void>; +} + +export function _firewallRulesListByMongoClusterSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + options: FirewallRulesListByMongoClusterOptionalParams = { + requestOptions: {}, + }, +): StreamableMethod< + | FirewallRulesListByMongoCluster200Response + | FirewallRulesListByMongoClusterDefaultResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/firewallRules", + subscriptionId, + resourceGroupName, + mongoClusterName, + ) + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _firewallRulesListByMongoClusterDeserialize( + result: + | FirewallRulesListByMongoCluster200Response + | FirewallRulesListByMongoClusterDefaultResponse, +): Promise<_FirewallRuleListResult> { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return { + value: result.body["value"].map((p) => { + return { + id: p["id"], + name: p["name"], + type: p["type"], + systemData: !p.systemData + ? undefined + : { + createdBy: p.systemData?.["createdBy"], + createdByType: p.systemData?.["createdByType"], + createdAt: + p.systemData?.["createdAt"] !== undefined + ? new Date(p.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: p.systemData?.["lastModifiedBy"], + lastModifiedByType: p.systemData?.["lastModifiedByType"], + lastModifiedAt: + p.systemData?.["lastModifiedAt"] !== undefined + ? new Date(p.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !p.properties + ? undefined + : { + provisioningState: p.properties?.["provisioningState"], + startIpAddress: p.properties?.["startIpAddress"], + endIpAddress: p.properties?.["endIpAddress"], + }, + }; + }), + nextLink: result.body["nextLink"], + }; +} + +/** List all the firewall rules in a given mongo cluster. */ +export function firewallRulesListByMongoCluster( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + options: FirewallRulesListByMongoClusterOptionalParams = { + requestOptions: {}, + }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => + _firewallRulesListByMongoClusterSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + options, + ), + _firewallRulesListByMongoClusterDeserialize, + { itemName: "value", nextLinkName: "nextLink" }, + ); +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/api/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/api/index.ts new file mode 100644 index 000000000000..2129786cdd74 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/api/index.ts @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +export { + createMongoClusterManagement, + MongoClusterManagementClientOptionalParams, + DocumentDBContext, +} from "./mongoClusterManagementContext.js"; +export { + firewallRulesGet, + firewallRulesCreateOrUpdate, + firewallRulesDelete, + firewallRulesListByMongoCluster, +} from "./firewallRules/index.js"; +export { + mongoClustersGet, + mongoClustersCreateOrUpdate, + mongoClustersUpdate, + mongoClustersDelete, + mongoClustersListByResourceGroup, + mongoClustersList, + mongoClustersListConnectionStrings, + mongoClustersCheckNameAvailability, + mongoClustersPromote, +} from "./mongoClusters/index.js"; +export { operationsList } from "./operations/index.js"; +export { + privateEndpointConnectionsListByMongoCluster, + privateEndpointConnectionsGet, + privateEndpointConnectionsCreate, + privateEndpointConnectionsDelete, +} from "./privateEndpointConnections/index.js"; +export { privateLinksListByMongoCluster } from "./privateLinks/index.js"; +export { replicasListByParent } from "./replicas/index.js"; diff --git a/sdk/mongocluster/arm-mongoclustertest/src/api/mongoClusterManagementContext.ts b/sdk/mongocluster/arm-mongoclustertest/src/api/mongoClusterManagementContext.ts new file mode 100644 index 000000000000..f287fa3cc36b --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/api/mongoClusterManagementContext.ts @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { TokenCredential } from "@azure/core-auth"; +import { ClientOptions } from "@azure-rest/core-client"; +import { DocumentDBContext } from "../rest/index.js"; +import getClient from "../rest/index.js"; + +/** Optional parameters for the client. */ +export interface MongoClusterManagementClientOptionalParams + extends ClientOptions { + /** The API version to use for this operation. */ + apiVersion?: string; +} + +export { DocumentDBContext } from "../rest/index.js"; + +/** The Microsoft Azure management API provides create, read, update, and delete functionality for Azure Cosmos DB for MongoDB vCore resources including clusters and firewall rules. */ +export function createMongoClusterManagement( + credential: TokenCredential, + options: MongoClusterManagementClientOptionalParams = {}, +): DocumentDBContext { + const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; + const userAgentPrefix = prefixFromOptions + ? `${prefixFromOptions} azsdk-js-api` + : "azsdk-js-api"; + + const clientContext = getClient(credential, { + ...options, + userAgentOptions: { userAgentPrefix }, + }); + return clientContext; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/api/mongoClusters/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/api/mongoClusters/index.ts new file mode 100644 index 000000000000..b7acb6a3e97e --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/api/mongoClusters/index.ts @@ -0,0 +1,1283 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { getLongRunningPoller } from "../pollingHelpers.js"; +import { PollerLike, OperationState } from "@azure/core-lro"; +import { + mongoClusterPropertiesSerializer, + mongoClusterUpdatePropertiesSerializer, + MongoCluster, + MongoClusterUpdate, + ListConnectionStringsResult, + CheckNameAvailabilityRequest, + CheckNameAvailabilityResponse, + PromoteReplicaRequest, + _MongoClusterListResult, +} from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js"; +import { buildPagedAsyncIterator } from "../pagingHelpers.js"; +import { + isUnexpected, + DocumentDBContext as Client, + MongoClustersCheckNameAvailability200Response, + MongoClustersCheckNameAvailabilityDefaultResponse, + MongoClustersCreateOrUpdate200Response, + MongoClustersCreateOrUpdate201Response, + MongoClustersCreateOrUpdateDefaultResponse, + MongoClustersCreateOrUpdateLogicalResponse, + MongoClustersDelete202Response, + MongoClustersDelete204Response, + MongoClustersDeleteDefaultResponse, + MongoClustersDeleteLogicalResponse, + MongoClustersGet200Response, + MongoClustersGetDefaultResponse, + MongoClustersList200Response, + MongoClustersListByResourceGroup200Response, + MongoClustersListByResourceGroupDefaultResponse, + MongoClustersListConnectionStrings200Response, + MongoClustersListConnectionStringsDefaultResponse, + MongoClustersListDefaultResponse, + MongoClustersPromote202Response, + MongoClustersPromoteDefaultResponse, + MongoClustersPromoteLogicalResponse, + MongoClustersUpdate200Response, + MongoClustersUpdate202Response, + MongoClustersUpdateDefaultResponse, + MongoClustersUpdateLogicalResponse, +} from "../../rest/index.js"; +import { + StreamableMethod, + operationOptionsToRequestParameters, + createRestError, +} from "@azure-rest/core-client"; +import { serializeRecord } from "../../helpers/serializerHelpers.js"; +import { + MongoClustersGetOptionalParams, + MongoClustersCreateOrUpdateOptionalParams, + MongoClustersUpdateOptionalParams, + MongoClustersDeleteOptionalParams, + MongoClustersListByResourceGroupOptionalParams, + MongoClustersListOptionalParams, + MongoClustersListConnectionStringsOptionalParams, + MongoClustersCheckNameAvailabilityOptionalParams, + MongoClustersPromoteOptionalParams, +} from "../../models/options.js"; + +export function _mongoClustersGetSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + options: MongoClustersGetOptionalParams = { requestOptions: {} }, +): StreamableMethod< + MongoClustersGet200Response | MongoClustersGetDefaultResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}", + subscriptionId, + resourceGroupName, + mongoClusterName, + ) + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _mongoClustersGetDeserialize( + result: MongoClustersGet200Response | MongoClustersGetDefaultResponse, +): Promise { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return { + tags: result.body["tags"], + location: result.body["location"], + id: result.body["id"], + name: result.body["name"], + type: result.body["type"], + systemData: !result.body.systemData + ? undefined + : { + createdBy: result.body.systemData?.["createdBy"], + createdByType: result.body.systemData?.["createdByType"], + createdAt: + result.body.systemData?.["createdAt"] !== undefined + ? new Date(result.body.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: result.body.systemData?.["lastModifiedBy"], + lastModifiedByType: result.body.systemData?.["lastModifiedByType"], + lastModifiedAt: + result.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(result.body.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !result.body.properties + ? undefined + : { + createMode: result.body.properties?.["createMode"], + restoreParameters: !result.body.properties?.restoreParameters + ? undefined + : { + pointInTimeUTC: + result.body.properties?.restoreParameters?.[ + "pointInTimeUTC" + ] !== undefined + ? new Date( + result.body.properties?.restoreParameters?.[ + "pointInTimeUTC" + ], + ) + : undefined, + sourceResourceId: + result.body.properties?.restoreParameters?.[ + "sourceResourceId" + ], + }, + replicaParameters: !result.body.properties?.replicaParameters + ? undefined + : { + sourceResourceId: + result.body.properties?.replicaParameters?.[ + "sourceResourceId" + ], + sourceLocation: + result.body.properties?.replicaParameters?.["sourceLocation"], + }, + administratorLogin: result.body.properties?.["administratorLogin"], + administratorLoginPassword: + result.body.properties?.["administratorLoginPassword"], + serverVersion: result.body.properties?.["serverVersion"], + connectionString: result.body.properties?.["connectionString"], + earliestRestoreTime: result.body.properties?.["earliestRestoreTime"], + provisioningState: result.body.properties?.["provisioningState"], + clusterStatus: result.body.properties?.["clusterStatus"], + publicNetworkAccess: result.body.properties?.["publicNetworkAccess"], + nodeGroupSpecs: + result.body.properties?.["nodeGroupSpecs"] === undefined + ? result.body.properties?.["nodeGroupSpecs"] + : result.body.properties?.["nodeGroupSpecs"].map((p) => { + return { + sku: p["sku"], + diskSizeGB: p["diskSizeGB"], + enableHa: p["enableHa"], + kind: p["kind"], + nodeCount: p["nodeCount"], + }; + }), + privateEndpointConnections: + result.body.properties?.["privateEndpointConnections"] === undefined + ? result.body.properties?.["privateEndpointConnections"] + : result.body.properties?.["privateEndpointConnections"].map( + (p) => { + return { + id: p["id"], + name: p["name"], + type: p["type"], + systemData: !p.systemData + ? undefined + : { + createdBy: p.systemData?.["createdBy"], + createdByType: p.systemData?.["createdByType"], + createdAt: + p.systemData?.["createdAt"] !== undefined + ? new Date(p.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: p.systemData?.["lastModifiedBy"], + lastModifiedByType: + p.systemData?.["lastModifiedByType"], + lastModifiedAt: + p.systemData?.["lastModifiedAt"] !== undefined + ? new Date(p.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !p.properties + ? undefined + : { + groupIds: p.properties?.["groupIds"], + privateEndpoint: !p.properties?.privateEndpoint + ? undefined + : { id: p.properties?.privateEndpoint?.["id"] }, + privateLinkServiceConnectionState: { + status: + p.properties?.privateLinkServiceConnectionState[ + "status" + ], + description: + p.properties?.privateLinkServiceConnectionState[ + "description" + ], + actionsRequired: + p.properties?.privateLinkServiceConnectionState[ + "actionsRequired" + ], + }, + provisioningState: + p.properties?.["provisioningState"], + }, + }; + }, + ), + previewFeatures: result.body.properties?.["previewFeatures"], + replica: !result.body.properties?.replica + ? undefined + : { + sourceResourceId: + result.body.properties?.replica?.["sourceResourceId"], + role: result.body.properties?.replica?.["role"], + replicationState: + result.body.properties?.replica?.["replicationState"], + }, + infrastructureVersion: + result.body.properties?.["infrastructureVersion"], + }, + }; +} + +/** Gets information about a mongo cluster. */ +export async function mongoClustersGet( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + options: MongoClustersGetOptionalParams = { requestOptions: {} }, +): Promise { + const result = await _mongoClustersGetSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + options, + ); + return _mongoClustersGetDeserialize(result); +} + +export function _mongoClustersCreateOrUpdateSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + resource: MongoCluster, + options: MongoClustersCreateOrUpdateOptionalParams = { requestOptions: {} }, +): StreamableMethod< + | MongoClustersCreateOrUpdate200Response + | MongoClustersCreateOrUpdate201Response + | MongoClustersCreateOrUpdateDefaultResponse + | MongoClustersCreateOrUpdateLogicalResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}", + subscriptionId, + resourceGroupName, + mongoClusterName, + ) + .put({ + ...operationOptionsToRequestParameters(options), + body: { + tags: !resource.tags + ? resource.tags + : (serializeRecord(resource.tags as any) as any), + location: resource["location"], + properties: !resource.properties + ? resource.properties + : mongoClusterPropertiesSerializer(resource.properties), + }, + }); +} + +export async function _mongoClustersCreateOrUpdateDeserialize( + result: + | MongoClustersCreateOrUpdate200Response + | MongoClustersCreateOrUpdate201Response + | MongoClustersCreateOrUpdateDefaultResponse + | MongoClustersCreateOrUpdateLogicalResponse, +): Promise { + if (isUnexpected(result)) { + throw createRestError(result); + } + + const res = result as unknown as MongoClustersCreateOrUpdateLogicalResponse; + return { + tags: res.body["tags"], + location: res.body["location"], + id: res.body["id"], + name: res.body["name"], + type: res.body["type"], + systemData: !res.body.systemData + ? undefined + : { + createdBy: res.body.systemData?.["createdBy"], + createdByType: res.body.systemData?.["createdByType"], + createdAt: + res.body.systemData?.["createdAt"] !== undefined + ? new Date(res.body.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: res.body.systemData?.["lastModifiedBy"], + lastModifiedByType: res.body.systemData?.["lastModifiedByType"], + lastModifiedAt: + res.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(res.body.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !res.body.properties + ? undefined + : { + createMode: res.body.properties?.["createMode"], + restoreParameters: !res.body.properties?.restoreParameters + ? undefined + : { + pointInTimeUTC: + res.body.properties?.restoreParameters?.["pointInTimeUTC"] !== + undefined + ? new Date( + res.body.properties?.restoreParameters?.[ + "pointInTimeUTC" + ], + ) + : undefined, + sourceResourceId: + res.body.properties?.restoreParameters?.["sourceResourceId"], + }, + replicaParameters: !res.body.properties?.replicaParameters + ? undefined + : { + sourceResourceId: + res.body.properties?.replicaParameters?.["sourceResourceId"], + sourceLocation: + res.body.properties?.replicaParameters?.["sourceLocation"], + }, + administratorLogin: res.body.properties?.["administratorLogin"], + administratorLoginPassword: + res.body.properties?.["administratorLoginPassword"], + serverVersion: res.body.properties?.["serverVersion"], + connectionString: res.body.properties?.["connectionString"], + earliestRestoreTime: res.body.properties?.["earliestRestoreTime"], + provisioningState: res.body.properties?.["provisioningState"], + clusterStatus: res.body.properties?.["clusterStatus"], + publicNetworkAccess: res.body.properties?.["publicNetworkAccess"], + nodeGroupSpecs: + res.body.properties?.["nodeGroupSpecs"] === undefined + ? res.body.properties?.["nodeGroupSpecs"] + : res.body.properties?.["nodeGroupSpecs"].map((p) => { + return { + sku: p["sku"], + diskSizeGB: p["diskSizeGB"], + enableHa: p["enableHa"], + kind: p["kind"], + nodeCount: p["nodeCount"], + }; + }), + privateEndpointConnections: + res.body.properties?.["privateEndpointConnections"] === undefined + ? res.body.properties?.["privateEndpointConnections"] + : res.body.properties?.["privateEndpointConnections"].map((p) => { + return { + id: p["id"], + name: p["name"], + type: p["type"], + systemData: !p.systemData + ? undefined + : { + createdBy: p.systemData?.["createdBy"], + createdByType: p.systemData?.["createdByType"], + createdAt: + p.systemData?.["createdAt"] !== undefined + ? new Date(p.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: p.systemData?.["lastModifiedBy"], + lastModifiedByType: + p.systemData?.["lastModifiedByType"], + lastModifiedAt: + p.systemData?.["lastModifiedAt"] !== undefined + ? new Date(p.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !p.properties + ? undefined + : { + groupIds: p.properties?.["groupIds"], + privateEndpoint: !p.properties?.privateEndpoint + ? undefined + : { id: p.properties?.privateEndpoint?.["id"] }, + privateLinkServiceConnectionState: { + status: + p.properties?.privateLinkServiceConnectionState[ + "status" + ], + description: + p.properties?.privateLinkServiceConnectionState[ + "description" + ], + actionsRequired: + p.properties?.privateLinkServiceConnectionState[ + "actionsRequired" + ], + }, + provisioningState: + p.properties?.["provisioningState"], + }, + }; + }), + previewFeatures: res.body.properties?.["previewFeatures"], + replica: !res.body.properties?.replica + ? undefined + : { + sourceResourceId: + res.body.properties?.replica?.["sourceResourceId"], + role: res.body.properties?.replica?.["role"], + replicationState: + res.body.properties?.replica?.["replicationState"], + }, + infrastructureVersion: res.body.properties?.["infrastructureVersion"], + }, + }; +} + +/** Create or update a mongo cluster. Update overwrites all properties for the resource. To only modify some of the properties, use PATCH. */ +export function mongoClustersCreateOrUpdate( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + resource: MongoCluster, + options: MongoClustersCreateOrUpdateOptionalParams = { requestOptions: {} }, +): PollerLike, MongoCluster> { + return getLongRunningPoller( + context, + _mongoClustersCreateOrUpdateDeserialize, + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _mongoClustersCreateOrUpdateSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + resource, + options, + ), + }, + ) as PollerLike, MongoCluster>; +} + +export function _mongoClustersUpdateSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + properties: MongoClusterUpdate, + options: MongoClustersUpdateOptionalParams = { requestOptions: {} }, +): StreamableMethod< + | MongoClustersUpdate200Response + | MongoClustersUpdate202Response + | MongoClustersUpdateDefaultResponse + | MongoClustersUpdateLogicalResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}", + subscriptionId, + resourceGroupName, + mongoClusterName, + ) + .patch({ + ...operationOptionsToRequestParameters(options), + body: { + tags: !properties.tags + ? properties.tags + : (serializeRecord(properties.tags as any) as any), + properties: !properties.properties + ? properties.properties + : mongoClusterUpdatePropertiesSerializer(properties.properties), + }, + }); +} + +export async function _mongoClustersUpdateDeserialize( + result: + | MongoClustersUpdate200Response + | MongoClustersUpdate202Response + | MongoClustersUpdateDefaultResponse + | MongoClustersUpdateLogicalResponse, +): Promise { + if (isUnexpected(result)) { + throw createRestError(result); + } + + const res = result as unknown as MongoClustersUpdateLogicalResponse; + return { + tags: res.body["tags"], + location: res.body["location"], + id: res.body["id"], + name: res.body["name"], + type: res.body["type"], + systemData: !res.body.systemData + ? undefined + : { + createdBy: res.body.systemData?.["createdBy"], + createdByType: res.body.systemData?.["createdByType"], + createdAt: + res.body.systemData?.["createdAt"] !== undefined + ? new Date(res.body.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: res.body.systemData?.["lastModifiedBy"], + lastModifiedByType: res.body.systemData?.["lastModifiedByType"], + lastModifiedAt: + res.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(res.body.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !res.body.properties + ? undefined + : { + createMode: res.body.properties?.["createMode"], + restoreParameters: !res.body.properties?.restoreParameters + ? undefined + : { + pointInTimeUTC: + res.body.properties?.restoreParameters?.["pointInTimeUTC"] !== + undefined + ? new Date( + res.body.properties?.restoreParameters?.[ + "pointInTimeUTC" + ], + ) + : undefined, + sourceResourceId: + res.body.properties?.restoreParameters?.["sourceResourceId"], + }, + replicaParameters: !res.body.properties?.replicaParameters + ? undefined + : { + sourceResourceId: + res.body.properties?.replicaParameters?.["sourceResourceId"], + sourceLocation: + res.body.properties?.replicaParameters?.["sourceLocation"], + }, + administratorLogin: res.body.properties?.["administratorLogin"], + administratorLoginPassword: + res.body.properties?.["administratorLoginPassword"], + serverVersion: res.body.properties?.["serverVersion"], + connectionString: res.body.properties?.["connectionString"], + earliestRestoreTime: res.body.properties?.["earliestRestoreTime"], + provisioningState: res.body.properties?.["provisioningState"], + clusterStatus: res.body.properties?.["clusterStatus"], + publicNetworkAccess: res.body.properties?.["publicNetworkAccess"], + nodeGroupSpecs: + res.body.properties?.["nodeGroupSpecs"] === undefined + ? res.body.properties?.["nodeGroupSpecs"] + : res.body.properties?.["nodeGroupSpecs"].map((p) => { + return { + sku: p["sku"], + diskSizeGB: p["diskSizeGB"], + enableHa: p["enableHa"], + kind: p["kind"], + nodeCount: p["nodeCount"], + }; + }), + privateEndpointConnections: + res.body.properties?.["privateEndpointConnections"] === undefined + ? res.body.properties?.["privateEndpointConnections"] + : res.body.properties?.["privateEndpointConnections"].map((p) => { + return { + id: p["id"], + name: p["name"], + type: p["type"], + systemData: !p.systemData + ? undefined + : { + createdBy: p.systemData?.["createdBy"], + createdByType: p.systemData?.["createdByType"], + createdAt: + p.systemData?.["createdAt"] !== undefined + ? new Date(p.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: p.systemData?.["lastModifiedBy"], + lastModifiedByType: + p.systemData?.["lastModifiedByType"], + lastModifiedAt: + p.systemData?.["lastModifiedAt"] !== undefined + ? new Date(p.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !p.properties + ? undefined + : { + groupIds: p.properties?.["groupIds"], + privateEndpoint: !p.properties?.privateEndpoint + ? undefined + : { id: p.properties?.privateEndpoint?.["id"] }, + privateLinkServiceConnectionState: { + status: + p.properties?.privateLinkServiceConnectionState[ + "status" + ], + description: + p.properties?.privateLinkServiceConnectionState[ + "description" + ], + actionsRequired: + p.properties?.privateLinkServiceConnectionState[ + "actionsRequired" + ], + }, + provisioningState: + p.properties?.["provisioningState"], + }, + }; + }), + previewFeatures: res.body.properties?.["previewFeatures"], + replica: !res.body.properties?.replica + ? undefined + : { + sourceResourceId: + res.body.properties?.replica?.["sourceResourceId"], + role: res.body.properties?.replica?.["role"], + replicationState: + res.body.properties?.replica?.["replicationState"], + }, + infrastructureVersion: res.body.properties?.["infrastructureVersion"], + }, + }; +} + +/** Updates an existing mongo cluster. The request body can contain one to many of the properties present in the normal mongo cluster definition. */ +export function mongoClustersUpdate( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + properties: MongoClusterUpdate, + options: MongoClustersUpdateOptionalParams = { requestOptions: {} }, +): PollerLike, MongoCluster> { + return getLongRunningPoller(context, _mongoClustersUpdateDeserialize, { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _mongoClustersUpdateSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + properties, + options, + ), + }) as PollerLike, MongoCluster>; +} + +export function _mongoClustersDeleteSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + options: MongoClustersDeleteOptionalParams = { requestOptions: {} }, +): StreamableMethod< + | MongoClustersDelete202Response + | MongoClustersDelete204Response + | MongoClustersDeleteDefaultResponse + | MongoClustersDeleteLogicalResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}", + subscriptionId, + resourceGroupName, + mongoClusterName, + ) + .delete({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _mongoClustersDeleteDeserialize( + result: + | MongoClustersDelete202Response + | MongoClustersDelete204Response + | MongoClustersDeleteDefaultResponse + | MongoClustersDeleteLogicalResponse, +): Promise { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return; +} + +/** Deletes a mongo cluster. */ +export function mongoClustersDelete( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + options: MongoClustersDeleteOptionalParams = { requestOptions: {} }, +): PollerLike, void> { + return getLongRunningPoller(context, _mongoClustersDeleteDeserialize, { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _mongoClustersDeleteSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + options, + ), + }) as PollerLike, void>; +} + +export function _mongoClustersListByResourceGroupSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + options: MongoClustersListByResourceGroupOptionalParams = { + requestOptions: {}, + }, +): StreamableMethod< + | MongoClustersListByResourceGroup200Response + | MongoClustersListByResourceGroupDefaultResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters", + subscriptionId, + resourceGroupName, + ) + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _mongoClustersListByResourceGroupDeserialize( + result: + | MongoClustersListByResourceGroup200Response + | MongoClustersListByResourceGroupDefaultResponse, +): Promise<_MongoClusterListResult> { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return { + value: result.body["value"].map((p) => { + return { + tags: p["tags"], + location: p["location"], + id: p["id"], + name: p["name"], + type: p["type"], + systemData: !p.systemData + ? undefined + : { + createdBy: p.systemData?.["createdBy"], + createdByType: p.systemData?.["createdByType"], + createdAt: + p.systemData?.["createdAt"] !== undefined + ? new Date(p.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: p.systemData?.["lastModifiedBy"], + lastModifiedByType: p.systemData?.["lastModifiedByType"], + lastModifiedAt: + p.systemData?.["lastModifiedAt"] !== undefined + ? new Date(p.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !p.properties + ? undefined + : { + createMode: p.properties?.["createMode"], + restoreParameters: !p.properties?.restoreParameters + ? undefined + : { + pointInTimeUTC: + p.properties?.restoreParameters?.["pointInTimeUTC"] !== + undefined + ? new Date( + p.properties?.restoreParameters?.["pointInTimeUTC"], + ) + : undefined, + sourceResourceId: + p.properties?.restoreParameters?.["sourceResourceId"], + }, + replicaParameters: !p.properties?.replicaParameters + ? undefined + : { + sourceResourceId: + p.properties?.replicaParameters?.["sourceResourceId"], + sourceLocation: + p.properties?.replicaParameters?.["sourceLocation"], + }, + administratorLogin: p.properties?.["administratorLogin"], + administratorLoginPassword: + p.properties?.["administratorLoginPassword"], + serverVersion: p.properties?.["serverVersion"], + connectionString: p.properties?.["connectionString"], + earliestRestoreTime: p.properties?.["earliestRestoreTime"], + provisioningState: p.properties?.["provisioningState"], + clusterStatus: p.properties?.["clusterStatus"], + publicNetworkAccess: p.properties?.["publicNetworkAccess"], + nodeGroupSpecs: + p.properties?.["nodeGroupSpecs"] === undefined + ? p.properties?.["nodeGroupSpecs"] + : p.properties?.["nodeGroupSpecs"].map((p) => { + return { + sku: p["sku"], + diskSizeGB: p["diskSizeGB"], + enableHa: p["enableHa"], + kind: p["kind"], + nodeCount: p["nodeCount"], + }; + }), + privateEndpointConnections: + p.properties?.["privateEndpointConnections"] === undefined + ? p.properties?.["privateEndpointConnections"] + : p.properties?.["privateEndpointConnections"].map((p) => { + return { + id: p["id"], + name: p["name"], + type: p["type"], + systemData: !p.systemData + ? undefined + : { + createdBy: p.systemData?.["createdBy"], + createdByType: p.systemData?.["createdByType"], + createdAt: + p.systemData?.["createdAt"] !== undefined + ? new Date(p.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: p.systemData?.["lastModifiedBy"], + lastModifiedByType: + p.systemData?.["lastModifiedByType"], + lastModifiedAt: + p.systemData?.["lastModifiedAt"] !== undefined + ? new Date(p.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !p.properties + ? undefined + : { + groupIds: p.properties?.["groupIds"], + privateEndpoint: !p.properties?.privateEndpoint + ? undefined + : { id: p.properties?.privateEndpoint?.["id"] }, + privateLinkServiceConnectionState: { + status: + p.properties + ?.privateLinkServiceConnectionState[ + "status" + ], + description: + p.properties + ?.privateLinkServiceConnectionState[ + "description" + ], + actionsRequired: + p.properties + ?.privateLinkServiceConnectionState[ + "actionsRequired" + ], + }, + provisioningState: + p.properties?.["provisioningState"], + }, + }; + }), + previewFeatures: p.properties?.["previewFeatures"], + replica: !p.properties?.replica + ? undefined + : { + sourceResourceId: + p.properties?.replica?.["sourceResourceId"], + role: p.properties?.replica?.["role"], + replicationState: + p.properties?.replica?.["replicationState"], + }, + infrastructureVersion: p.properties?.["infrastructureVersion"], + }, + }; + }), + nextLink: result.body["nextLink"], + }; +} + +/** List all the mongo clusters in a given resource group. */ +export function mongoClustersListByResourceGroup( + context: Client, + subscriptionId: string, + resourceGroupName: string, + options: MongoClustersListByResourceGroupOptionalParams = { + requestOptions: {}, + }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => + _mongoClustersListByResourceGroupSend( + context, + subscriptionId, + resourceGroupName, + options, + ), + _mongoClustersListByResourceGroupDeserialize, + { itemName: "value", nextLinkName: "nextLink" }, + ); +} + +export function _mongoClustersListSend( + context: Client, + subscriptionId: string, + options: MongoClustersListOptionalParams = { requestOptions: {} }, +): StreamableMethod< + MongoClustersList200Response | MongoClustersListDefaultResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/mongoClusters", + subscriptionId, + ) + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _mongoClustersListDeserialize( + result: MongoClustersList200Response | MongoClustersListDefaultResponse, +): Promise<_MongoClusterListResult> { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return { + value: result.body["value"].map((p) => { + return { + tags: p["tags"], + location: p["location"], + id: p["id"], + name: p["name"], + type: p["type"], + systemData: !p.systemData + ? undefined + : { + createdBy: p.systemData?.["createdBy"], + createdByType: p.systemData?.["createdByType"], + createdAt: + p.systemData?.["createdAt"] !== undefined + ? new Date(p.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: p.systemData?.["lastModifiedBy"], + lastModifiedByType: p.systemData?.["lastModifiedByType"], + lastModifiedAt: + p.systemData?.["lastModifiedAt"] !== undefined + ? new Date(p.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !p.properties + ? undefined + : { + createMode: p.properties?.["createMode"], + restoreParameters: !p.properties?.restoreParameters + ? undefined + : { + pointInTimeUTC: + p.properties?.restoreParameters?.["pointInTimeUTC"] !== + undefined + ? new Date( + p.properties?.restoreParameters?.["pointInTimeUTC"], + ) + : undefined, + sourceResourceId: + p.properties?.restoreParameters?.["sourceResourceId"], + }, + replicaParameters: !p.properties?.replicaParameters + ? undefined + : { + sourceResourceId: + p.properties?.replicaParameters?.["sourceResourceId"], + sourceLocation: + p.properties?.replicaParameters?.["sourceLocation"], + }, + administratorLogin: p.properties?.["administratorLogin"], + administratorLoginPassword: + p.properties?.["administratorLoginPassword"], + serverVersion: p.properties?.["serverVersion"], + connectionString: p.properties?.["connectionString"], + earliestRestoreTime: p.properties?.["earliestRestoreTime"], + provisioningState: p.properties?.["provisioningState"], + clusterStatus: p.properties?.["clusterStatus"], + publicNetworkAccess: p.properties?.["publicNetworkAccess"], + nodeGroupSpecs: + p.properties?.["nodeGroupSpecs"] === undefined + ? p.properties?.["nodeGroupSpecs"] + : p.properties?.["nodeGroupSpecs"].map((p) => { + return { + sku: p["sku"], + diskSizeGB: p["diskSizeGB"], + enableHa: p["enableHa"], + kind: p["kind"], + nodeCount: p["nodeCount"], + }; + }), + privateEndpointConnections: + p.properties?.["privateEndpointConnections"] === undefined + ? p.properties?.["privateEndpointConnections"] + : p.properties?.["privateEndpointConnections"].map((p) => { + return { + id: p["id"], + name: p["name"], + type: p["type"], + systemData: !p.systemData + ? undefined + : { + createdBy: p.systemData?.["createdBy"], + createdByType: p.systemData?.["createdByType"], + createdAt: + p.systemData?.["createdAt"] !== undefined + ? new Date(p.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: p.systemData?.["lastModifiedBy"], + lastModifiedByType: + p.systemData?.["lastModifiedByType"], + lastModifiedAt: + p.systemData?.["lastModifiedAt"] !== undefined + ? new Date(p.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !p.properties + ? undefined + : { + groupIds: p.properties?.["groupIds"], + privateEndpoint: !p.properties?.privateEndpoint + ? undefined + : { id: p.properties?.privateEndpoint?.["id"] }, + privateLinkServiceConnectionState: { + status: + p.properties + ?.privateLinkServiceConnectionState[ + "status" + ], + description: + p.properties + ?.privateLinkServiceConnectionState[ + "description" + ], + actionsRequired: + p.properties + ?.privateLinkServiceConnectionState[ + "actionsRequired" + ], + }, + provisioningState: + p.properties?.["provisioningState"], + }, + }; + }), + previewFeatures: p.properties?.["previewFeatures"], + replica: !p.properties?.replica + ? undefined + : { + sourceResourceId: + p.properties?.replica?.["sourceResourceId"], + role: p.properties?.replica?.["role"], + replicationState: + p.properties?.replica?.["replicationState"], + }, + infrastructureVersion: p.properties?.["infrastructureVersion"], + }, + }; + }), + nextLink: result.body["nextLink"], + }; +} + +/** List all the mongo clusters in a given subscription. */ +export function mongoClustersList( + context: Client, + subscriptionId: string, + options: MongoClustersListOptionalParams = { requestOptions: {} }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => _mongoClustersListSend(context, subscriptionId, options), + _mongoClustersListDeserialize, + { itemName: "value", nextLinkName: "nextLink" }, + ); +} + +export function _mongoClustersListConnectionStringsSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + options: MongoClustersListConnectionStringsOptionalParams = { + requestOptions: {}, + }, +): StreamableMethod< + | MongoClustersListConnectionStrings200Response + | MongoClustersListConnectionStringsDefaultResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/listConnectionStrings", + subscriptionId, + resourceGroupName, + mongoClusterName, + ) + .post({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _mongoClustersListConnectionStringsDeserialize( + result: + | MongoClustersListConnectionStrings200Response + | MongoClustersListConnectionStringsDefaultResponse, +): Promise { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return { + connectionStrings: + result.body["connectionStrings"] === undefined + ? result.body["connectionStrings"] + : result.body["connectionStrings"].map((p) => { + return { + connectionString: p["connectionString"], + description: p["description"], + }; + }), + }; +} + +/** List mongo cluster connection strings. This includes the default connection string using SCRAM-SHA-256, as well as other connection strings supported by the cluster. */ +export async function mongoClustersListConnectionStrings( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + options: MongoClustersListConnectionStringsOptionalParams = { + requestOptions: {}, + }, +): Promise { + const result = await _mongoClustersListConnectionStringsSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + options, + ); + return _mongoClustersListConnectionStringsDeserialize(result); +} + +export function _mongoClustersCheckNameAvailabilitySend( + context: Client, + subscriptionId: string, + location: string, + body: CheckNameAvailabilityRequest, + options: MongoClustersCheckNameAvailabilityOptionalParams = { + requestOptions: {}, + }, +): StreamableMethod< + | MongoClustersCheckNameAvailability200Response + | MongoClustersCheckNameAvailabilityDefaultResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}/checkMongoClusterNameAvailability", + subscriptionId, + location, + ) + .post({ + ...operationOptionsToRequestParameters(options), + body: { name: body["name"], type: body["type"] }, + }); +} + +export async function _mongoClustersCheckNameAvailabilityDeserialize( + result: + | MongoClustersCheckNameAvailability200Response + | MongoClustersCheckNameAvailabilityDefaultResponse, +): Promise { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return { + nameAvailable: result.body["nameAvailable"], + reason: result.body["reason"], + message: result.body["message"], + }; +} + +/** Check if mongo cluster name is available for use. */ +export async function mongoClustersCheckNameAvailability( + context: Client, + subscriptionId: string, + location: string, + body: CheckNameAvailabilityRequest, + options: MongoClustersCheckNameAvailabilityOptionalParams = { + requestOptions: {}, + }, +): Promise { + const result = await _mongoClustersCheckNameAvailabilitySend( + context, + subscriptionId, + location, + body, + options, + ); + return _mongoClustersCheckNameAvailabilityDeserialize(result); +} + +export function _mongoClustersPromoteSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + body: PromoteReplicaRequest, + options: MongoClustersPromoteOptionalParams = { requestOptions: {} }, +): StreamableMethod< + | MongoClustersPromote202Response + | MongoClustersPromoteDefaultResponse + | MongoClustersPromoteLogicalResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/promote", + subscriptionId, + resourceGroupName, + mongoClusterName, + ) + .post({ + ...operationOptionsToRequestParameters(options), + body: { promoteOption: body["promoteOption"], mode: body["mode"] }, + }); +} + +export async function _mongoClustersPromoteDeserialize( + result: + | MongoClustersPromote202Response + | MongoClustersPromoteDefaultResponse + | MongoClustersPromoteLogicalResponse, +): Promise { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return; +} + +/** Promotes a replica mongo cluster to a primary role. */ +export function mongoClustersPromote( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + body: PromoteReplicaRequest, + options: MongoClustersPromoteOptionalParams = { requestOptions: {} }, +): PollerLike, void> { + return getLongRunningPoller(context, _mongoClustersPromoteDeserialize, { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _mongoClustersPromoteSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + body, + options, + ), + }) as PollerLike, void>; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/api/operations/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/api/operations/index.ts new file mode 100644 index 000000000000..60e7b0471dfe --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/api/operations/index.ts @@ -0,0 +1,68 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { Operation, _OperationListResult } from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js"; +import { buildPagedAsyncIterator } from "../pagingHelpers.js"; +import { + isUnexpected, + DocumentDBContext as Client, + OperationsList200Response, + OperationsListDefaultResponse, +} from "../../rest/index.js"; +import { + StreamableMethod, + operationOptionsToRequestParameters, + createRestError, +} from "@azure-rest/core-client"; +import { OperationsListOptionalParams } from "../../models/options.js"; + +export function _operationsListSend( + context: Client, + options: OperationsListOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path("/providers/Microsoft.DocumentDB/operations") + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _operationsListDeserialize( + result: OperationsList200Response | OperationsListDefaultResponse, +): Promise<_OperationListResult> { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return { + value: result.body["value"].map((p) => { + return { + name: p["name"], + isDataAction: p["isDataAction"], + display: !p.display + ? undefined + : { + provider: p.display?.["provider"], + resource: p.display?.["resource"], + operation: p.display?.["operation"], + description: p.display?.["description"], + }, + origin: p["origin"], + actionType: p["actionType"], + }; + }), + nextLink: result.body["nextLink"], + }; +} + +/** List the operations for the provider */ +export function operationsList( + context: Client, + options: OperationsListOptionalParams = { requestOptions: {} }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => _operationsListSend(context, options), + _operationsListDeserialize, + { itemName: "value", nextLinkName: "nextLink" }, + ); +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/api/pagingHelpers.ts b/sdk/mongocluster/arm-mongoclustertest/src/api/pagingHelpers.ts new file mode 100644 index 000000000000..9780e76e04a6 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/api/pagingHelpers.ts @@ -0,0 +1,191 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { + Client, + createRestError, + PathUncheckedResponse, +} from "@azure-rest/core-client"; +import { RestError } from "@azure/core-rest-pipeline"; +import { + BuildPagedAsyncIteratorOptions, + ContinuablePage, + PageSettings, + PagedAsyncIterableIterator, + PagedResult, +} from "../models/pagingTypes.js"; +import { isUnexpected } from "../rest/index.js"; + +/** + * Helper to paginate results in a generic way and return a PagedAsyncIterableIterator + */ +export function buildPagedAsyncIterator< + TElement, + TPage = TElement[], + TPageSettings extends PageSettings = PageSettings, + TResponse extends PathUncheckedResponse = PathUncheckedResponse, +>( + client: Client, + getInitialResponse: () => PromiseLike, + processResponseBody: (result: TResponse) => PromiseLike, + options: BuildPagedAsyncIteratorOptions = {}, +): PagedAsyncIterableIterator { + const itemName = options.itemName ?? "value"; + const nextLinkName = options.nextLinkName ?? "nextLink"; + const pagedResult: PagedResult = { + getPage: async (pageLink?: string) => { + const result = + pageLink === undefined + ? await getInitialResponse() + : await client.pathUnchecked(pageLink).get(); + checkPagingRequest(result); + const results = await processResponseBody(result as TResponse); + const nextLink = getNextLink(results, nextLinkName); + const values = getElements(results, itemName) as TPage; + return { + page: values, + nextPageLink: nextLink, + }; + }, + byPage: (settings?: TPageSettings) => { + const { continuationToken } = settings ?? {}; + return getPageAsyncIterator(pagedResult, { + pageLink: continuationToken, + }); + }, + }; + return getPagedAsyncIterator(pagedResult); +} + +/** + * returns an async iterator that iterates over results. It also has a `byPage` + * method that returns pages of items at once. + * + * @param pagedResult - an object that specifies how to get pages. + * @returns a paged async iterator that iterates over results. + */ + +function getPagedAsyncIterator< + TElement, + TPage = TElement[], + TPageSettings extends PageSettings = PageSettings, +>( + pagedResult: PagedResult, +): PagedAsyncIterableIterator { + const iter = getItemAsyncIterator( + pagedResult, + ); + return { + next() { + return iter.next(); + }, + [Symbol.asyncIterator]() { + return this; + }, + byPage: + pagedResult?.byPage ?? + ((settings?: TPageSettings) => { + const { continuationToken } = settings ?? {}; + return getPageAsyncIterator(pagedResult, { + pageLink: continuationToken, + }); + }), + }; +} + +async function* getItemAsyncIterator< + TElement, + TPage, + TPageSettings extends PageSettings, +>( + pagedResult: PagedResult, +): AsyncIterableIterator { + const pages = getPageAsyncIterator(pagedResult); + for await (const page of pages) { + yield* page as unknown as TElement[]; + } +} + +async function* getPageAsyncIterator< + TElement, + TPage, + TPageSettings extends PageSettings, +>( + pagedResult: PagedResult, + options: { + pageLink?: string; + } = {}, +): AsyncIterableIterator> { + const { pageLink } = options; + let response = await pagedResult.getPage( + pageLink ?? pagedResult.firstPageLink, + ); + if (!response) { + return; + } + let result = response.page as ContinuablePage; + result.continuationToken = response.nextPageLink; + yield result; + while (response.nextPageLink) { + response = await pagedResult.getPage(response.nextPageLink); + if (!response) { + return; + } + result = response.page as ContinuablePage; + result.continuationToken = response.nextPageLink; + yield result; + } +} + +/** + * Gets for the value of nextLink in the body + */ +function getNextLink(body: unknown, nextLinkName?: string): string | undefined { + if (!nextLinkName) { + return undefined; + } + + const nextLink = (body as Record)[nextLinkName]; + + if ( + typeof nextLink !== "string" && + typeof nextLink !== "undefined" && + nextLink !== null + ) { + throw new RestError( + `Body Property ${nextLinkName} should be a string or undefined or null but got ${typeof nextLink}`, + ); + } + + if (nextLink === null) { + return undefined; + } + + return nextLink; +} + +/** + * Gets the elements of the current request in the body. + */ +function getElements(body: unknown, itemName: string): T[] { + const value = (body as Record)[itemName] as T[]; + if (!Array.isArray(value)) { + throw new RestError( + `Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}`, + ); + } + + return value ?? []; +} + +/** + * Checks if a request failed + */ +function checkPagingRequest(response: PathUncheckedResponse): void { + if (isUnexpected(response)) { + throw createRestError( + `Pagination failed with unexpected statusCode ${response.status}`, + response, + ); + } +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/api/pollingHelpers.ts b/sdk/mongocluster/arm-mongoclustertest/src/api/pollingHelpers.ts new file mode 100644 index 000000000000..f3bd59e41b4f --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/api/pollingHelpers.ts @@ -0,0 +1,139 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { + PollerLike, + OperationState, + ResourceLocationConfig, + RunningOperation, + createHttpPoller, + OperationResponse, +} from "@azure/core-lro"; + +import { + Client, + PathUncheckedResponse, + createRestError, +} from "@azure-rest/core-client"; +import { AbortSignalLike } from "@azure/abort-controller"; +import { isUnexpected } from "../rest/index.js"; + +export interface GetLongRunningPollerOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; + /** + * The signal which can be used to abort requests. + */ + abortSignal?: AbortSignalLike; + /** + * The potential location of the result of the LRO if specified by the LRO extension in the swagger. + */ + resourceLocationConfig?: ResourceLocationConfig; + /** + * The original url of the LRO + * Should not be null when restoreFrom is set + */ + initialRequestUrl?: string; + /** + * A serialized poller which can be used to resume an existing paused Long-Running-Operation. + */ + restoreFrom?: string; + /** + * The function to get the initial response + */ + getInitialResponse?: () => PromiseLike; +} +export function getLongRunningPoller< + TResponse extends PathUncheckedResponse, + TResult = void, +>( + client: Client, + processResponseBody: (result: TResponse) => Promise, + options: GetLongRunningPollerOptions, +): PollerLike, TResult> { + const { restoreFrom, getInitialResponse } = options; + if (!restoreFrom && !getInitialResponse) { + throw new Error( + "Either restoreFrom or getInitialResponse must be specified", + ); + } + let initialResponse: TResponse | undefined = undefined; + const pollAbortController = new AbortController(); + const poller: RunningOperation = { + sendInitialRequest: async () => { + if (!getInitialResponse) { + throw new Error( + "getInitialResponse is required when initializing a new poller", + ); + } + initialResponse = await getInitialResponse(); + return getLroResponse(initialResponse); + }, + sendPollRequest: async ( + path: string, + pollOptions?: { + abortSignal?: AbortSignalLike; + }, + ) => { + // The poll request would both listen to the user provided abort signal and the poller's own abort signal + function abortListener(): void { + pollAbortController.abort(); + } + const abortSignal = pollAbortController.signal; + if (options.abortSignal?.aborted) { + pollAbortController.abort(); + } else if (pollOptions?.abortSignal?.aborted) { + pollAbortController.abort(); + } else if (!abortSignal.aborted) { + options.abortSignal?.addEventListener("abort", abortListener, { + once: true, + }); + pollOptions?.abortSignal?.addEventListener("abort", abortListener, { + once: true, + }); + } + let response; + try { + response = await client.pathUnchecked(path).get({ abortSignal }); + } finally { + options.abortSignal?.removeEventListener("abort", abortListener); + pollOptions?.abortSignal?.removeEventListener("abort", abortListener); + } + if (options.initialRequestUrl || initialResponse) { + response.headers["x-ms-original-url"] = + options.initialRequestUrl ?? initialResponse!.request.url; + } + + return getLroResponse(response as TResponse); + }, + }; + return createHttpPoller(poller, { + intervalInMs: options?.updateIntervalInMs, + resourceLocationConfig: options?.resourceLocationConfig, + restoreFrom: options?.restoreFrom, + processResult: (result: unknown) => { + return processResponseBody(result as TResponse); + }, + }); +} +/** + * Converts a Rest Client response to a response that the LRO implementation understands + * @param response - a rest client http response + * @param deserializeFn - deserialize function to convert Rest response to modular output + * @returns - An LRO response that the LRO implementation understands + */ +function getLroResponse( + response: TResponse, +): OperationResponse { + if (isUnexpected(response as PathUncheckedResponse)) { + throw createRestError(response); + } + return { + flatResponse: response, + rawResponse: { + ...response, + statusCode: Number.parseInt(response.status), + body: response.body, + }, + }; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/api/privateEndpointConnections/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/api/privateEndpointConnections/index.ts new file mode 100644 index 000000000000..b967f5fc775e --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/api/privateEndpointConnections/index.ts @@ -0,0 +1,443 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { getLongRunningPoller } from "../pollingHelpers.js"; +import { PollerLike, OperationState } from "@azure/core-lro"; +import { + privateEndpointConnectionPropertiesSerializer, + PrivateEndpointConnectionResource, + _PrivateEndpointConnectionResourceListResult, +} from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js"; +import { buildPagedAsyncIterator } from "../pagingHelpers.js"; +import { + isUnexpected, + DocumentDBContext as Client, + PrivateEndpointConnectionsCreate200Response, + PrivateEndpointConnectionsCreate201Response, + PrivateEndpointConnectionsCreate202Response, + PrivateEndpointConnectionsCreateDefaultResponse, + PrivateEndpointConnectionsCreateLogicalResponse, + PrivateEndpointConnectionsDelete202Response, + PrivateEndpointConnectionsDelete204Response, + PrivateEndpointConnectionsDeleteDefaultResponse, + PrivateEndpointConnectionsDeleteLogicalResponse, + PrivateEndpointConnectionsGet200Response, + PrivateEndpointConnectionsGetDefaultResponse, + PrivateEndpointConnectionsListByMongoCluster200Response, + PrivateEndpointConnectionsListByMongoClusterDefaultResponse, +} from "../../rest/index.js"; +import { + StreamableMethod, + operationOptionsToRequestParameters, + createRestError, +} from "@azure-rest/core-client"; +import { + PrivateEndpointConnectionsListByMongoClusterOptionalParams, + PrivateEndpointConnectionsGetOptionalParams, + PrivateEndpointConnectionsCreateOptionalParams, + PrivateEndpointConnectionsDeleteOptionalParams, +} from "../../models/options.js"; + +export function _privateEndpointConnectionsListByMongoClusterSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + options: PrivateEndpointConnectionsListByMongoClusterOptionalParams = { + requestOptions: {}, + }, +): StreamableMethod< + | PrivateEndpointConnectionsListByMongoCluster200Response + | PrivateEndpointConnectionsListByMongoClusterDefaultResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateEndpointConnections", + subscriptionId, + resourceGroupName, + mongoClusterName, + ) + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _privateEndpointConnectionsListByMongoClusterDeserialize( + result: + | PrivateEndpointConnectionsListByMongoCluster200Response + | PrivateEndpointConnectionsListByMongoClusterDefaultResponse, +): Promise<_PrivateEndpointConnectionResourceListResult> { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return { + value: result.body["value"].map((p) => { + return { + id: p["id"], + name: p["name"], + type: p["type"], + systemData: !p.systemData + ? undefined + : { + createdBy: p.systemData?.["createdBy"], + createdByType: p.systemData?.["createdByType"], + createdAt: + p.systemData?.["createdAt"] !== undefined + ? new Date(p.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: p.systemData?.["lastModifiedBy"], + lastModifiedByType: p.systemData?.["lastModifiedByType"], + lastModifiedAt: + p.systemData?.["lastModifiedAt"] !== undefined + ? new Date(p.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !p.properties + ? undefined + : { + groupIds: p.properties?.["groupIds"], + privateEndpoint: !p.properties?.privateEndpoint + ? undefined + : { id: p.properties?.privateEndpoint?.["id"] }, + privateLinkServiceConnectionState: { + status: + p.properties?.privateLinkServiceConnectionState["status"], + description: + p.properties?.privateLinkServiceConnectionState[ + "description" + ], + actionsRequired: + p.properties?.privateLinkServiceConnectionState[ + "actionsRequired" + ], + }, + provisioningState: p.properties?.["provisioningState"], + }, + }; + }), + nextLink: result.body["nextLink"], + }; +} + +/** List existing private connections */ +export function privateEndpointConnectionsListByMongoCluster( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + options: PrivateEndpointConnectionsListByMongoClusterOptionalParams = { + requestOptions: {}, + }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => + _privateEndpointConnectionsListByMongoClusterSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + options, + ), + _privateEndpointConnectionsListByMongoClusterDeserialize, + { itemName: "value", nextLinkName: "nextLink" }, + ); +} + +export function _privateEndpointConnectionsGetSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + privateEndpointConnectionName: string, + options: PrivateEndpointConnectionsGetOptionalParams = { requestOptions: {} }, +): StreamableMethod< + | PrivateEndpointConnectionsGet200Response + | PrivateEndpointConnectionsGetDefaultResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateEndpointConnections/{privateEndpointConnectionName}", + subscriptionId, + resourceGroupName, + mongoClusterName, + privateEndpointConnectionName, + ) + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _privateEndpointConnectionsGetDeserialize( + result: + | PrivateEndpointConnectionsGet200Response + | PrivateEndpointConnectionsGetDefaultResponse, +): Promise { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return { + id: result.body["id"], + name: result.body["name"], + type: result.body["type"], + systemData: !result.body.systemData + ? undefined + : { + createdBy: result.body.systemData?.["createdBy"], + createdByType: result.body.systemData?.["createdByType"], + createdAt: + result.body.systemData?.["createdAt"] !== undefined + ? new Date(result.body.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: result.body.systemData?.["lastModifiedBy"], + lastModifiedByType: result.body.systemData?.["lastModifiedByType"], + lastModifiedAt: + result.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(result.body.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !result.body.properties + ? undefined + : { + groupIds: result.body.properties?.["groupIds"], + privateEndpoint: !result.body.properties?.privateEndpoint + ? undefined + : { id: result.body.properties?.privateEndpoint?.["id"] }, + privateLinkServiceConnectionState: { + status: + result.body.properties?.privateLinkServiceConnectionState[ + "status" + ], + description: + result.body.properties?.privateLinkServiceConnectionState[ + "description" + ], + actionsRequired: + result.body.properties?.privateLinkServiceConnectionState[ + "actionsRequired" + ], + }, + provisioningState: result.body.properties?.["provisioningState"], + }, + }; +} + +/** Get a specific private connection */ +export async function privateEndpointConnectionsGet( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + privateEndpointConnectionName: string, + options: PrivateEndpointConnectionsGetOptionalParams = { requestOptions: {} }, +): Promise { + const result = await _privateEndpointConnectionsGetSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + privateEndpointConnectionName, + options, + ); + return _privateEndpointConnectionsGetDeserialize(result); +} + +export function _privateEndpointConnectionsCreateSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + privateEndpointConnectionName: string, + resource: PrivateEndpointConnectionResource, + options: PrivateEndpointConnectionsCreateOptionalParams = { + requestOptions: {}, + }, +): StreamableMethod< + | PrivateEndpointConnectionsCreate200Response + | PrivateEndpointConnectionsCreate201Response + | PrivateEndpointConnectionsCreate202Response + | PrivateEndpointConnectionsCreateDefaultResponse + | PrivateEndpointConnectionsCreateLogicalResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateEndpointConnections/{privateEndpointConnectionName}", + subscriptionId, + resourceGroupName, + mongoClusterName, + privateEndpointConnectionName, + ) + .put({ + ...operationOptionsToRequestParameters(options), + body: { + properties: !resource.properties + ? resource.properties + : privateEndpointConnectionPropertiesSerializer(resource.properties), + }, + }); +} + +export async function _privateEndpointConnectionsCreateDeserialize( + result: + | PrivateEndpointConnectionsCreate200Response + | PrivateEndpointConnectionsCreate201Response + | PrivateEndpointConnectionsCreate202Response + | PrivateEndpointConnectionsCreateDefaultResponse + | PrivateEndpointConnectionsCreateLogicalResponse, +): Promise { + if (isUnexpected(result)) { + throw createRestError(result); + } + + const res = + result as unknown as PrivateEndpointConnectionsCreateLogicalResponse; + return { + id: res.body["id"], + name: res.body["name"], + type: res.body["type"], + systemData: !res.body.systemData + ? undefined + : { + createdBy: res.body.systemData?.["createdBy"], + createdByType: res.body.systemData?.["createdByType"], + createdAt: + res.body.systemData?.["createdAt"] !== undefined + ? new Date(res.body.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: res.body.systemData?.["lastModifiedBy"], + lastModifiedByType: res.body.systemData?.["lastModifiedByType"], + lastModifiedAt: + res.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(res.body.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !res.body.properties + ? undefined + : { + groupIds: res.body.properties?.["groupIds"], + privateEndpoint: !res.body.properties?.privateEndpoint + ? undefined + : { id: res.body.properties?.privateEndpoint?.["id"] }, + privateLinkServiceConnectionState: { + status: + res.body.properties?.privateLinkServiceConnectionState["status"], + description: + res.body.properties?.privateLinkServiceConnectionState[ + "description" + ], + actionsRequired: + res.body.properties?.privateLinkServiceConnectionState[ + "actionsRequired" + ], + }, + provisioningState: res.body.properties?.["provisioningState"], + }, + }; +} + +/** Create a Private endpoint connection */ +export function privateEndpointConnectionsCreate( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + privateEndpointConnectionName: string, + resource: PrivateEndpointConnectionResource, + options: PrivateEndpointConnectionsCreateOptionalParams = { + requestOptions: {}, + }, +): PollerLike< + OperationState, + PrivateEndpointConnectionResource +> { + return getLongRunningPoller( + context, + _privateEndpointConnectionsCreateDeserialize, + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _privateEndpointConnectionsCreateSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + privateEndpointConnectionName, + resource, + options, + ), + }, + ) as PollerLike< + OperationState, + PrivateEndpointConnectionResource + >; +} + +export function _privateEndpointConnectionsDeleteSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + privateEndpointConnectionName: string, + options: PrivateEndpointConnectionsDeleteOptionalParams = { + requestOptions: {}, + }, +): StreamableMethod< + | PrivateEndpointConnectionsDelete202Response + | PrivateEndpointConnectionsDelete204Response + | PrivateEndpointConnectionsDeleteDefaultResponse + | PrivateEndpointConnectionsDeleteLogicalResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateEndpointConnections/{privateEndpointConnectionName}", + subscriptionId, + resourceGroupName, + mongoClusterName, + privateEndpointConnectionName, + ) + .delete({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _privateEndpointConnectionsDeleteDeserialize( + result: + | PrivateEndpointConnectionsDelete202Response + | PrivateEndpointConnectionsDelete204Response + | PrivateEndpointConnectionsDeleteDefaultResponse + | PrivateEndpointConnectionsDeleteLogicalResponse, +): Promise { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return; +} + +/** Delete the private endpoint connection */ +export function privateEndpointConnectionsDelete( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + privateEndpointConnectionName: string, + options: PrivateEndpointConnectionsDeleteOptionalParams = { + requestOptions: {}, + }, +): PollerLike, void> { + return getLongRunningPoller( + context, + _privateEndpointConnectionsDeleteDeserialize, + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _privateEndpointConnectionsDeleteSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + privateEndpointConnectionName, + options, + ), + }, + ) as PollerLike, void>; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/api/privateLinks/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/api/privateLinks/index.ts new file mode 100644 index 000000000000..93afc2c99727 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/api/privateLinks/index.ts @@ -0,0 +1,112 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { + PrivateLinkResource, + _PrivateLinkResourceListResult, +} from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js"; +import { buildPagedAsyncIterator } from "../pagingHelpers.js"; +import { + isUnexpected, + DocumentDBContext as Client, + PrivateLinksListByMongoCluster200Response, + PrivateLinksListByMongoClusterDefaultResponse, +} from "../../rest/index.js"; +import { + StreamableMethod, + operationOptionsToRequestParameters, + createRestError, +} from "@azure-rest/core-client"; +import { PrivateLinksListByMongoClusterOptionalParams } from "../../models/options.js"; + +export function _privateLinksListByMongoClusterSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + options: PrivateLinksListByMongoClusterOptionalParams = { + requestOptions: {}, + }, +): StreamableMethod< + | PrivateLinksListByMongoCluster200Response + | PrivateLinksListByMongoClusterDefaultResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateLinkResources", + subscriptionId, + resourceGroupName, + mongoClusterName, + ) + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _privateLinksListByMongoClusterDeserialize( + result: + | PrivateLinksListByMongoCluster200Response + | PrivateLinksListByMongoClusterDefaultResponse, +): Promise<_PrivateLinkResourceListResult> { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return { + value: result.body["value"].map((p) => { + return { + id: p["id"], + name: p["name"], + type: p["type"], + systemData: !p.systemData + ? undefined + : { + createdBy: p.systemData?.["createdBy"], + createdByType: p.systemData?.["createdByType"], + createdAt: + p.systemData?.["createdAt"] !== undefined + ? new Date(p.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: p.systemData?.["lastModifiedBy"], + lastModifiedByType: p.systemData?.["lastModifiedByType"], + lastModifiedAt: + p.systemData?.["lastModifiedAt"] !== undefined + ? new Date(p.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !p.properties + ? undefined + : { + groupId: p.properties?.["groupId"], + requiredMembers: p.properties?.["requiredMembers"], + requiredZoneNames: p.properties?.["requiredZoneNames"], + }, + }; + }), + nextLink: result.body["nextLink"], + }; +} + +/** list private links on the given resource */ +export function privateLinksListByMongoCluster( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + options: PrivateLinksListByMongoClusterOptionalParams = { + requestOptions: {}, + }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => + _privateLinksListByMongoClusterSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + options, + ), + _privateLinksListByMongoClusterDeserialize, + { itemName: "value", nextLinkName: "nextLink" }, + ); +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/api/replicas/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/api/replicas/index.ts new file mode 100644 index 000000000000..6458d9b38fe3 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/api/replicas/index.ts @@ -0,0 +1,207 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { Replica, _ReplicaListResult } from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js"; +import { buildPagedAsyncIterator } from "../pagingHelpers.js"; +import { + isUnexpected, + DocumentDBContext as Client, + ReplicasListByParent200Response, + ReplicasListByParentDefaultResponse, +} from "../../rest/index.js"; +import { + StreamableMethod, + operationOptionsToRequestParameters, + createRestError, +} from "@azure-rest/core-client"; +import { ReplicasListByParentOptionalParams } from "../../models/options.js"; + +export function _replicasListByParentSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + options: ReplicasListByParentOptionalParams = { requestOptions: {} }, +): StreamableMethod< + ReplicasListByParent200Response | ReplicasListByParentDefaultResponse +> { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/replicas", + subscriptionId, + resourceGroupName, + mongoClusterName, + ) + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _replicasListByParentDeserialize( + result: ReplicasListByParent200Response | ReplicasListByParentDefaultResponse, +): Promise<_ReplicaListResult> { + if (isUnexpected(result)) { + throw createRestError(result); + } + + return { + value: result.body["value"].map((p) => { + return { + id: p["id"], + name: p["name"], + type: p["type"], + systemData: !p.systemData + ? undefined + : { + createdBy: p.systemData?.["createdBy"], + createdByType: p.systemData?.["createdByType"], + createdAt: + p.systemData?.["createdAt"] !== undefined + ? new Date(p.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: p.systemData?.["lastModifiedBy"], + lastModifiedByType: p.systemData?.["lastModifiedByType"], + lastModifiedAt: + p.systemData?.["lastModifiedAt"] !== undefined + ? new Date(p.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !p.properties + ? undefined + : { + createMode: p.properties?.["createMode"], + restoreParameters: !p.properties?.restoreParameters + ? undefined + : { + pointInTimeUTC: + p.properties?.restoreParameters?.["pointInTimeUTC"] !== + undefined + ? new Date( + p.properties?.restoreParameters?.["pointInTimeUTC"], + ) + : undefined, + sourceResourceId: + p.properties?.restoreParameters?.["sourceResourceId"], + }, + replicaParameters: !p.properties?.replicaParameters + ? undefined + : { + sourceResourceId: + p.properties?.replicaParameters?.["sourceResourceId"], + sourceLocation: + p.properties?.replicaParameters?.["sourceLocation"], + }, + administratorLogin: p.properties?.["administratorLogin"], + administratorLoginPassword: + p.properties?.["administratorLoginPassword"], + serverVersion: p.properties?.["serverVersion"], + connectionString: p.properties?.["connectionString"], + earliestRestoreTime: p.properties?.["earliestRestoreTime"], + provisioningState: p.properties?.["provisioningState"], + clusterStatus: p.properties?.["clusterStatus"], + publicNetworkAccess: p.properties?.["publicNetworkAccess"], + nodeGroupSpecs: + p.properties?.["nodeGroupSpecs"] === undefined + ? p.properties?.["nodeGroupSpecs"] + : p.properties?.["nodeGroupSpecs"].map((p) => { + return { + sku: p["sku"], + diskSizeGB: p["diskSizeGB"], + enableHa: p["enableHa"], + kind: p["kind"], + nodeCount: p["nodeCount"], + }; + }), + privateEndpointConnections: + p.properties?.["privateEndpointConnections"] === undefined + ? p.properties?.["privateEndpointConnections"] + : p.properties?.["privateEndpointConnections"].map((p) => { + return { + id: p["id"], + name: p["name"], + type: p["type"], + systemData: !p.systemData + ? undefined + : { + createdBy: p.systemData?.["createdBy"], + createdByType: p.systemData?.["createdByType"], + createdAt: + p.systemData?.["createdAt"] !== undefined + ? new Date(p.systemData?.["createdAt"]) + : undefined, + lastModifiedBy: p.systemData?.["lastModifiedBy"], + lastModifiedByType: + p.systemData?.["lastModifiedByType"], + lastModifiedAt: + p.systemData?.["lastModifiedAt"] !== undefined + ? new Date(p.systemData?.["lastModifiedAt"]) + : undefined, + }, + properties: !p.properties + ? undefined + : { + groupIds: p.properties?.["groupIds"], + privateEndpoint: !p.properties?.privateEndpoint + ? undefined + : { id: p.properties?.privateEndpoint?.["id"] }, + privateLinkServiceConnectionState: { + status: + p.properties + ?.privateLinkServiceConnectionState[ + "status" + ], + description: + p.properties + ?.privateLinkServiceConnectionState[ + "description" + ], + actionsRequired: + p.properties + ?.privateLinkServiceConnectionState[ + "actionsRequired" + ], + }, + provisioningState: + p.properties?.["provisioningState"], + }, + }; + }), + previewFeatures: p.properties?.["previewFeatures"], + replica: !p.properties?.replica + ? undefined + : { + sourceResourceId: + p.properties?.replica?.["sourceResourceId"], + role: p.properties?.replica?.["role"], + replicationState: + p.properties?.replica?.["replicationState"], + }, + infrastructureVersion: p.properties?.["infrastructureVersion"], + }, + }; + }), + nextLink: result.body["nextLink"], + }; +} + +/** List all the replicas for the mongo cluster. */ +export function replicasListByParent( + context: Client, + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + options: ReplicasListByParentOptionalParams = { requestOptions: {} }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => + _replicasListByParentSend( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + options, + ), + _replicasListByParentDeserialize, + { itemName: "value", nextLinkName: "nextLink" }, + ); +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/classic/firewallRules/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/classic/firewallRules/index.ts new file mode 100644 index 000000000000..6ff337f450ec --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/classic/firewallRules/index.ts @@ -0,0 +1,124 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { DocumentDBContext } from "../../api/mongoClusterManagementContext.js"; +import { FirewallRule } from "../../models/models.js"; +import { + firewallRulesGet, + firewallRulesCreateOrUpdate, + firewallRulesDelete, + firewallRulesListByMongoCluster, +} from "../../api/firewallRules/index.js"; +import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js"; +import { PollerLike, OperationState } from "@azure/core-lro"; +import { + FirewallRulesGetOptionalParams, + FirewallRulesCreateOrUpdateOptionalParams, + FirewallRulesDeleteOptionalParams, + FirewallRulesListByMongoClusterOptionalParams, +} from "../../models/options.js"; + +/** Interface representing a FirewallRules operations. */ +export interface FirewallRulesOperations { + /** Gets information about a mongo cluster firewall rule. */ + get: ( + resourceGroupName: string, + mongoClusterName: string, + firewallRuleName: string, + options?: FirewallRulesGetOptionalParams, + ) => Promise; + /** Creates a new firewall rule or updates an existing firewall rule on a mongo cluster. */ + createOrUpdate: ( + resourceGroupName: string, + mongoClusterName: string, + firewallRuleName: string, + resource: FirewallRule, + options?: FirewallRulesCreateOrUpdateOptionalParams, + ) => PollerLike, FirewallRule>; + /** Deletes a mongo cluster firewall rule. */ + delete: ( + resourceGroupName: string, + mongoClusterName: string, + firewallRuleName: string, + options?: FirewallRulesDeleteOptionalParams, + ) => PollerLike, void>; + /** List all the firewall rules in a given mongo cluster. */ + listByMongoCluster: ( + resourceGroupName: string, + mongoClusterName: string, + options?: FirewallRulesListByMongoClusterOptionalParams, + ) => PagedAsyncIterableIterator; +} + +export function getFirewallRules( + context: DocumentDBContext, + subscriptionId: string, +) { + return { + get: ( + resourceGroupName: string, + mongoClusterName: string, + firewallRuleName: string, + options?: FirewallRulesGetOptionalParams, + ) => + firewallRulesGet( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + firewallRuleName, + options, + ), + createOrUpdate: ( + resourceGroupName: string, + mongoClusterName: string, + firewallRuleName: string, + resource: FirewallRule, + options?: FirewallRulesCreateOrUpdateOptionalParams, + ) => + firewallRulesCreateOrUpdate( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + firewallRuleName, + resource, + options, + ), + delete: ( + resourceGroupName: string, + mongoClusterName: string, + firewallRuleName: string, + options?: FirewallRulesDeleteOptionalParams, + ) => + firewallRulesDelete( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + firewallRuleName, + options, + ), + listByMongoCluster: ( + resourceGroupName: string, + mongoClusterName: string, + options?: FirewallRulesListByMongoClusterOptionalParams, + ) => + firewallRulesListByMongoCluster( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + options, + ), + }; +} + +export function getFirewallRulesOperations( + context: DocumentDBContext, + subscriptionId: string, +): FirewallRulesOperations { + return { + ...getFirewallRules(context, subscriptionId), + }; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/classic/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/classic/index.ts new file mode 100644 index 000000000000..b6728b8b4778 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/classic/index.ts @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +export { FirewallRulesOperations } from "./firewallRules/index.js"; +export { MongoClustersOperations } from "./mongoClusters/index.js"; +export { OperationsOperations } from "./operations/index.js"; +export { PrivateEndpointConnectionsOperations } from "./privateEndpointConnections/index.js"; +export { PrivateLinksOperations } from "./privateLinks/index.js"; +export { ReplicasOperations } from "./replicas/index.js"; diff --git a/sdk/mongocluster/arm-mongoclustertest/src/classic/mongoClusters/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/classic/mongoClusters/index.ts new file mode 100644 index 000000000000..0e2cd71ba82b --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/classic/mongoClusters/index.ts @@ -0,0 +1,213 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { DocumentDBContext } from "../../api/mongoClusterManagementContext.js"; +import { + MongoCluster, + MongoClusterUpdate, + ListConnectionStringsResult, + CheckNameAvailabilityRequest, + CheckNameAvailabilityResponse, + PromoteReplicaRequest, +} from "../../models/models.js"; +import { + mongoClustersGet, + mongoClustersCreateOrUpdate, + mongoClustersUpdate, + mongoClustersDelete, + mongoClustersListByResourceGroup, + mongoClustersList, + mongoClustersListConnectionStrings, + mongoClustersCheckNameAvailability, + mongoClustersPromote, +} from "../../api/mongoClusters/index.js"; +import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js"; +import { PollerLike, OperationState } from "@azure/core-lro"; +import { + MongoClustersGetOptionalParams, + MongoClustersCreateOrUpdateOptionalParams, + MongoClustersUpdateOptionalParams, + MongoClustersDeleteOptionalParams, + MongoClustersListByResourceGroupOptionalParams, + MongoClustersListOptionalParams, + MongoClustersListConnectionStringsOptionalParams, + MongoClustersCheckNameAvailabilityOptionalParams, + MongoClustersPromoteOptionalParams, +} from "../../models/options.js"; + +/** Interface representing a MongoClusters operations. */ +export interface MongoClustersOperations { + /** Gets information about a mongo cluster. */ + get: ( + resourceGroupName: string, + mongoClusterName: string, + options?: MongoClustersGetOptionalParams, + ) => Promise; + /** Create or update a mongo cluster. Update overwrites all properties for the resource. To only modify some of the properties, use PATCH. */ + createOrUpdate: ( + resourceGroupName: string, + mongoClusterName: string, + resource: MongoCluster, + options?: MongoClustersCreateOrUpdateOptionalParams, + ) => PollerLike, MongoCluster>; + /** Updates an existing mongo cluster. The request body can contain one to many of the properties present in the normal mongo cluster definition. */ + update: ( + resourceGroupName: string, + mongoClusterName: string, + properties: MongoClusterUpdate, + options?: MongoClustersUpdateOptionalParams, + ) => PollerLike, MongoCluster>; + /** Deletes a mongo cluster. */ + delete: ( + resourceGroupName: string, + mongoClusterName: string, + options?: MongoClustersDeleteOptionalParams, + ) => PollerLike, void>; + /** List all the mongo clusters in a given resource group. */ + listByResourceGroup: ( + resourceGroupName: string, + options?: MongoClustersListByResourceGroupOptionalParams, + ) => PagedAsyncIterableIterator; + /** List all the mongo clusters in a given subscription. */ + list: ( + options?: MongoClustersListOptionalParams, + ) => PagedAsyncIterableIterator; + /** List mongo cluster connection strings. This includes the default connection string using SCRAM-SHA-256, as well as other connection strings supported by the cluster. */ + listConnectionStrings: ( + resourceGroupName: string, + mongoClusterName: string, + options?: MongoClustersListConnectionStringsOptionalParams, + ) => Promise; + /** Check if mongo cluster name is available for use. */ + checkNameAvailability: ( + location: string, + body: CheckNameAvailabilityRequest, + options?: MongoClustersCheckNameAvailabilityOptionalParams, + ) => Promise; + /** Promotes a replica mongo cluster to a primary role. */ + promote: ( + resourceGroupName: string, + mongoClusterName: string, + body: PromoteReplicaRequest, + options?: MongoClustersPromoteOptionalParams, + ) => PollerLike, void>; +} + +export function getMongoClusters( + context: DocumentDBContext, + subscriptionId: string, +) { + return { + get: ( + resourceGroupName: string, + mongoClusterName: string, + options?: MongoClustersGetOptionalParams, + ) => + mongoClustersGet( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + options, + ), + createOrUpdate: ( + resourceGroupName: string, + mongoClusterName: string, + resource: MongoCluster, + options?: MongoClustersCreateOrUpdateOptionalParams, + ) => + mongoClustersCreateOrUpdate( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + resource, + options, + ), + update: ( + resourceGroupName: string, + mongoClusterName: string, + properties: MongoClusterUpdate, + options?: MongoClustersUpdateOptionalParams, + ) => + mongoClustersUpdate( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + properties, + options, + ), + delete: ( + resourceGroupName: string, + mongoClusterName: string, + options?: MongoClustersDeleteOptionalParams, + ) => + mongoClustersDelete( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + options, + ), + listByResourceGroup: ( + resourceGroupName: string, + options?: MongoClustersListByResourceGroupOptionalParams, + ) => + mongoClustersListByResourceGroup( + context, + subscriptionId, + resourceGroupName, + options, + ), + list: (options?: MongoClustersListOptionalParams) => + mongoClustersList(context, subscriptionId, options), + listConnectionStrings: ( + resourceGroupName: string, + mongoClusterName: string, + options?: MongoClustersListConnectionStringsOptionalParams, + ) => + mongoClustersListConnectionStrings( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + options, + ), + checkNameAvailability: ( + location: string, + body: CheckNameAvailabilityRequest, + options?: MongoClustersCheckNameAvailabilityOptionalParams, + ) => + mongoClustersCheckNameAvailability( + context, + subscriptionId, + location, + body, + options, + ), + promote: ( + resourceGroupName: string, + mongoClusterName: string, + body: PromoteReplicaRequest, + options?: MongoClustersPromoteOptionalParams, + ) => + mongoClustersPromote( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + body, + options, + ), + }; +} + +export function getMongoClustersOperations( + context: DocumentDBContext, + subscriptionId: string, +): MongoClustersOperations { + return { + ...getMongoClusters(context, subscriptionId), + }; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/classic/operations/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/classic/operations/index.ts new file mode 100644 index 000000000000..f2380312152b --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/classic/operations/index.ts @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { DocumentDBContext } from "../../api/mongoClusterManagementContext.js"; +import { Operation } from "../../models/models.js"; +import { operationsList } from "../../api/operations/index.js"; +import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js"; +import { OperationsListOptionalParams } from "../../models/options.js"; + +/** Interface representing a Operations operations. */ +export interface OperationsOperations { + /** List the operations for the provider */ + list: ( + options?: OperationsListOptionalParams, + ) => PagedAsyncIterableIterator; +} + +export function getOperations(context: DocumentDBContext) { + return { + list: (options?: OperationsListOptionalParams) => + operationsList(context, options), + }; +} + +export function getOperationsOperations( + context: DocumentDBContext, +): OperationsOperations { + return { + ...getOperations(context), + }; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/classic/privateEndpointConnections/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/classic/privateEndpointConnections/index.ts new file mode 100644 index 000000000000..10814cea2ead --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/classic/privateEndpointConnections/index.ts @@ -0,0 +1,127 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { DocumentDBContext } from "../../api/mongoClusterManagementContext.js"; +import { PrivateEndpointConnectionResource } from "../../models/models.js"; +import { + privateEndpointConnectionsListByMongoCluster, + privateEndpointConnectionsGet, + privateEndpointConnectionsCreate, + privateEndpointConnectionsDelete, +} from "../../api/privateEndpointConnections/index.js"; +import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js"; +import { PollerLike, OperationState } from "@azure/core-lro"; +import { + PrivateEndpointConnectionsListByMongoClusterOptionalParams, + PrivateEndpointConnectionsGetOptionalParams, + PrivateEndpointConnectionsCreateOptionalParams, + PrivateEndpointConnectionsDeleteOptionalParams, +} from "../../models/options.js"; + +/** Interface representing a PrivateEndpointConnections operations. */ +export interface PrivateEndpointConnectionsOperations { + /** List existing private connections */ + listByMongoCluster: ( + resourceGroupName: string, + mongoClusterName: string, + options?: PrivateEndpointConnectionsListByMongoClusterOptionalParams, + ) => PagedAsyncIterableIterator; + /** Get a specific private connection */ + get: ( + resourceGroupName: string, + mongoClusterName: string, + privateEndpointConnectionName: string, + options?: PrivateEndpointConnectionsGetOptionalParams, + ) => Promise; + /** Create a Private endpoint connection */ + create: ( + resourceGroupName: string, + mongoClusterName: string, + privateEndpointConnectionName: string, + resource: PrivateEndpointConnectionResource, + options?: PrivateEndpointConnectionsCreateOptionalParams, + ) => PollerLike< + OperationState, + PrivateEndpointConnectionResource + >; + /** Delete the private endpoint connection */ + delete: ( + resourceGroupName: string, + mongoClusterName: string, + privateEndpointConnectionName: string, + options?: PrivateEndpointConnectionsDeleteOptionalParams, + ) => PollerLike, void>; +} + +export function getPrivateEndpointConnections( + context: DocumentDBContext, + subscriptionId: string, +) { + return { + listByMongoCluster: ( + resourceGroupName: string, + mongoClusterName: string, + options?: PrivateEndpointConnectionsListByMongoClusterOptionalParams, + ) => + privateEndpointConnectionsListByMongoCluster( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + options, + ), + get: ( + resourceGroupName: string, + mongoClusterName: string, + privateEndpointConnectionName: string, + options?: PrivateEndpointConnectionsGetOptionalParams, + ) => + privateEndpointConnectionsGet( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + privateEndpointConnectionName, + options, + ), + create: ( + resourceGroupName: string, + mongoClusterName: string, + privateEndpointConnectionName: string, + resource: PrivateEndpointConnectionResource, + options?: PrivateEndpointConnectionsCreateOptionalParams, + ) => + privateEndpointConnectionsCreate( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + privateEndpointConnectionName, + resource, + options, + ), + delete: ( + resourceGroupName: string, + mongoClusterName: string, + privateEndpointConnectionName: string, + options?: PrivateEndpointConnectionsDeleteOptionalParams, + ) => + privateEndpointConnectionsDelete( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + privateEndpointConnectionName, + options, + ), + }; +} + +export function getPrivateEndpointConnectionsOperations( + context: DocumentDBContext, + subscriptionId: string, +): PrivateEndpointConnectionsOperations { + return { + ...getPrivateEndpointConnections(context, subscriptionId), + }; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/classic/privateLinks/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/classic/privateLinks/index.ts new file mode 100644 index 000000000000..0e993017854a --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/classic/privateLinks/index.ts @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { DocumentDBContext } from "../../api/mongoClusterManagementContext.js"; +import { PrivateLinkResource } from "../../models/models.js"; +import { privateLinksListByMongoCluster } from "../../api/privateLinks/index.js"; +import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js"; +import { PrivateLinksListByMongoClusterOptionalParams } from "../../models/options.js"; + +/** Interface representing a PrivateLinks operations. */ +export interface PrivateLinksOperations { + /** list private links on the given resource */ + listByMongoCluster: ( + resourceGroupName: string, + mongoClusterName: string, + options?: PrivateLinksListByMongoClusterOptionalParams, + ) => PagedAsyncIterableIterator; +} + +export function getPrivateLinks( + context: DocumentDBContext, + subscriptionId: string, +) { + return { + listByMongoCluster: ( + resourceGroupName: string, + mongoClusterName: string, + options?: PrivateLinksListByMongoClusterOptionalParams, + ) => + privateLinksListByMongoCluster( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + options, + ), + }; +} + +export function getPrivateLinksOperations( + context: DocumentDBContext, + subscriptionId: string, +): PrivateLinksOperations { + return { + ...getPrivateLinks(context, subscriptionId), + }; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/classic/replicas/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/classic/replicas/index.ts new file mode 100644 index 000000000000..be08a83958f5 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/classic/replicas/index.ts @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { DocumentDBContext } from "../../api/mongoClusterManagementContext.js"; +import { Replica } from "../../models/models.js"; +import { replicasListByParent } from "../../api/replicas/index.js"; +import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js"; +import { ReplicasListByParentOptionalParams } from "../../models/options.js"; + +/** Interface representing a Replicas operations. */ +export interface ReplicasOperations { + /** List all the replicas for the mongo cluster. */ + listByParent: ( + resourceGroupName: string, + mongoClusterName: string, + options?: ReplicasListByParentOptionalParams, + ) => PagedAsyncIterableIterator; +} + +export function getReplicas( + context: DocumentDBContext, + subscriptionId: string, +) { + return { + listByParent: ( + resourceGroupName: string, + mongoClusterName: string, + options?: ReplicasListByParentOptionalParams, + ) => + replicasListByParent( + context, + subscriptionId, + resourceGroupName, + mongoClusterName, + options, + ), + }; +} + +export function getReplicasOperations( + context: DocumentDBContext, + subscriptionId: string, +): ReplicasOperations { + return { + ...getReplicas(context, subscriptionId), + }; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/helpers/serializerHelpers.ts b/sdk/mongocluster/arm-mongoclustertest/src/helpers/serializerHelpers.ts new file mode 100644 index 000000000000..332381cdb695 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/helpers/serializerHelpers.ts @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +export function serializeRecord< + T extends string | number | boolean | Date | null, + R, +>(item: Record): Record; +export function serializeRecord( + item: Record, + serializer: (item: T) => R, +): Record; +export function serializeRecord( + item: Record, + serializer?: (item: T) => R, +): Record { + return Object.keys(item).reduce( + (acc, key) => { + if (isSupportedRecordType(item[key])) { + acc[key] = item[key] as any; + } else if (serializer) { + const value = item[key]; + if (value !== undefined) { + acc[key] = serializer(value); + } + } else { + console.warn(`Don't know how to serialize ${item[key]}`); + acc[key] = item[key] as any; + } + return acc; + }, + {} as Record, + ); +} + +function isSupportedRecordType(t: any) { + return ( + ["number", "string", "boolean", "null"].includes(typeof t) || + t instanceof Date + ); +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/index.ts new file mode 100644 index 000000000000..4037ac6ad8a8 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/index.ts @@ -0,0 +1,107 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +export { + MongoClusterManagementClient, + MongoClusterManagementClientOptionalParams, +} from "./mongoClusterManagementClient.js"; +export { restorePoller, RestorePollerOptions } from "./restorePollerHelpers.js"; +export { + Resource, + SystemData, + KnownCreatedByType, + CreatedByType, + ProxyResource, + Replica, + MongoClusterProperties, + KnownCreateMode, + CreateMode, + MongoClusterRestoreParameters, + MongoClusterReplicaParameters, + KnownResourceProvisioningState, + ResourceProvisioningState, + KnownMongoClusterStatus, + MongoClusterStatus, + KnownPublicNetworkAccess, + PublicNetworkAccess, + NodeGroupSpec, + KnownNodeKind, + NodeKind, + PrivateEndpointConnection, + PrivateEndpointConnectionProperties, + PrivateEndpoint, + PrivateLinkServiceConnectionState, + KnownPrivateEndpointServiceConnectionStatus, + PrivateEndpointServiceConnectionStatus, + KnownPrivateEndpointConnectionProvisioningState, + PrivateEndpointConnectionProvisioningState, + KnownPreviewFeature, + PreviewFeature, + ReplicationProperties, + KnownReplicationRole, + ReplicationRole, + KnownReplicationState, + ReplicationState, + ErrorResponse, + ErrorDetail, + ErrorAdditionalInfo, + PrivateLinkResource, + PrivateLinkResourceProperties, + PrivateEndpointConnectionResource, + FirewallRule, + FirewallRuleProperties, + TrackedResource, + MongoCluster, + MongoClusterUpdate, + MongoClusterUpdateProperties, + ListConnectionStringsResult, + ConnectionString, + CheckNameAvailabilityRequest, + CheckNameAvailabilityResponse, + KnownCheckNameAvailabilityReason, + CheckNameAvailabilityReason, + PromoteReplicaRequest, + KnownPromoteOption, + PromoteOption, + KnownPromoteMode, + PromoteMode, + Operation, + OperationDisplay, + KnownOrigin, + Origin, + KnownActionType, + ActionType, + Versions, + ProvisioningState, + OperationsListOptionalParams, + MongoClustersGetOptionalParams, + MongoClustersCreateOrUpdateOptionalParams, + MongoClustersUpdateOptionalParams, + MongoClustersDeleteOptionalParams, + MongoClustersListByResourceGroupOptionalParams, + MongoClustersListOptionalParams, + MongoClustersListConnectionStringsOptionalParams, + MongoClustersCheckNameAvailabilityOptionalParams, + MongoClustersPromoteOptionalParams, + FirewallRulesGetOptionalParams, + FirewallRulesCreateOrUpdateOptionalParams, + FirewallRulesDeleteOptionalParams, + FirewallRulesListByMongoClusterOptionalParams, + PrivateEndpointConnectionsListByMongoClusterOptionalParams, + PrivateEndpointConnectionsGetOptionalParams, + PrivateEndpointConnectionsCreateOptionalParams, + PrivateEndpointConnectionsDeleteOptionalParams, + PrivateLinksListByMongoClusterOptionalParams, + ReplicasListByParentOptionalParams, + PageSettings, + ContinuablePage, + PagedAsyncIterableIterator, +} from "./models/index.js"; +export { + FirewallRulesOperations, + MongoClustersOperations, + OperationsOperations, + PrivateEndpointConnectionsOperations, + PrivateLinksOperations, + ReplicasOperations, +} from "./classic/index.js"; diff --git a/sdk/mongocluster/arm-mongoclustertest/src/logger.ts b/sdk/mongocluster/arm-mongoclustertest/src/logger.ts new file mode 100644 index 000000000000..281b6061e5e6 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/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("arm-mongoclustertest"); diff --git a/sdk/mongocluster/arm-mongoclustertest/src/models/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/models/index.ts new file mode 100644 index 000000000000..a06ba4e4035a --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/models/index.ts @@ -0,0 +1,98 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +export { + Resource, + SystemData, + KnownCreatedByType, + CreatedByType, + ProxyResource, + Replica, + MongoClusterProperties, + KnownCreateMode, + CreateMode, + MongoClusterRestoreParameters, + MongoClusterReplicaParameters, + KnownResourceProvisioningState, + ResourceProvisioningState, + KnownMongoClusterStatus, + MongoClusterStatus, + KnownPublicNetworkAccess, + PublicNetworkAccess, + NodeGroupSpec, + KnownNodeKind, + NodeKind, + PrivateEndpointConnection, + PrivateEndpointConnectionProperties, + PrivateEndpoint, + PrivateLinkServiceConnectionState, + KnownPrivateEndpointServiceConnectionStatus, + PrivateEndpointServiceConnectionStatus, + KnownPrivateEndpointConnectionProvisioningState, + PrivateEndpointConnectionProvisioningState, + KnownPreviewFeature, + PreviewFeature, + ReplicationProperties, + KnownReplicationRole, + ReplicationRole, + KnownReplicationState, + ReplicationState, + ErrorResponse, + ErrorDetail, + ErrorAdditionalInfo, + PrivateLinkResource, + PrivateLinkResourceProperties, + PrivateEndpointConnectionResource, + FirewallRule, + FirewallRuleProperties, + TrackedResource, + MongoCluster, + MongoClusterUpdate, + MongoClusterUpdateProperties, + ListConnectionStringsResult, + ConnectionString, + CheckNameAvailabilityRequest, + CheckNameAvailabilityResponse, + KnownCheckNameAvailabilityReason, + CheckNameAvailabilityReason, + PromoteReplicaRequest, + KnownPromoteOption, + PromoteOption, + KnownPromoteMode, + PromoteMode, + Operation, + OperationDisplay, + KnownOrigin, + Origin, + KnownActionType, + ActionType, + Versions, + ProvisioningState, +} from "./models.js"; +export { + OperationsListOptionalParams, + MongoClustersGetOptionalParams, + MongoClustersCreateOrUpdateOptionalParams, + MongoClustersUpdateOptionalParams, + MongoClustersDeleteOptionalParams, + MongoClustersListByResourceGroupOptionalParams, + MongoClustersListOptionalParams, + MongoClustersListConnectionStringsOptionalParams, + MongoClustersCheckNameAvailabilityOptionalParams, + MongoClustersPromoteOptionalParams, + FirewallRulesGetOptionalParams, + FirewallRulesCreateOrUpdateOptionalParams, + FirewallRulesDeleteOptionalParams, + FirewallRulesListByMongoClusterOptionalParams, + PrivateEndpointConnectionsListByMongoClusterOptionalParams, + PrivateEndpointConnectionsGetOptionalParams, + PrivateEndpointConnectionsCreateOptionalParams, + PrivateEndpointConnectionsDeleteOptionalParams, + PrivateLinksListByMongoClusterOptionalParams, + ReplicasListByParentOptionalParams, +} from "./options.js"; +export { + PageSettings, + ContinuablePage, + PagedAsyncIterableIterator, +} from "./pagingTypes.js"; diff --git a/sdk/mongocluster/arm-mongoclustertest/src/models/models.ts b/sdk/mongocluster/arm-mongoclustertest/src/models/models.ts new file mode 100644 index 000000000000..2fa81d3dd72a --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/models/models.ts @@ -0,0 +1,905 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { serializeRecord } from "../helpers/serializerHelpers.js"; +import { + MongoClusterProperties as MongoClusterPropertiesRest, + MongoClusterRestoreParameters as MongoClusterRestoreParametersRest, + MongoClusterReplicaParameters as MongoClusterReplicaParametersRest, + NodeGroupSpec as NodeGroupSpecRest, + PrivateEndpointConnectionProperties as PrivateEndpointConnectionPropertiesRest, + PrivateLinkServiceConnectionState as PrivateLinkServiceConnectionStateRest, + PrivateEndpointConnectionResource as PrivateEndpointConnectionResourceRest, + FirewallRule as FirewallRuleRest, + FirewallRuleProperties as FirewallRulePropertiesRest, + TrackedResource as TrackedResourceRest, + MongoCluster as MongoClusterRest, + MongoClusterUpdate as MongoClusterUpdateRest, + MongoClusterUpdateProperties as MongoClusterUpdatePropertiesRest, + CheckNameAvailabilityRequest as CheckNameAvailabilityRequestRest, + PromoteReplicaRequest as PromoteReplicaRequestRest, +} from "../rest/index.js"; + +/** The response of a Replica list operation. */ +export interface _ReplicaListResult { + /** The Replica items on this page */ + value: Replica[]; + /** The link to the next page of items */ + nextLink?: string; +} + +/** Common fields that are returned in the response for all Azure Resource Manager resources */ +export interface Resource { + /** Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} */ + readonly id?: string; + /** The name of the resource */ + readonly name?: string; + /** The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" */ + readonly type?: string; + /** Azure Resource Manager metadata containing createdBy and modifiedBy information. */ + readonly systemData?: SystemData; +} + +export function resourceSerializer(item: Resource) { + return item as any; +} + +/** Metadata pertaining to creation and last modification of the resource. */ +export interface SystemData { + /** The identity that created the resource. */ + createdBy?: string; + /** The type of identity that created the resource. */ + createdByType?: CreatedByType; + /** The timestamp of resource creation (UTC). */ + createdAt?: Date; + /** The identity that last modified the resource. */ + lastModifiedBy?: string; + /** The type of identity that last modified the resource. */ + lastModifiedByType?: CreatedByType; + /** The timestamp of resource last modification (UTC) */ + lastModifiedAt?: Date; +} + +/** Known values of {@link CreatedByType} that the service accepts. */ +export enum KnownCreatedByType { + /** User */ + User = "User", + /** Application */ + Application = "Application", + /** ManagedIdentity */ + ManagedIdentity = "ManagedIdentity", + /** Key */ + Key = "Key", +} + +/** + * The kind of entity that created the resource. \ + * {@link KnownCreatedByType} can be used interchangeably with CreatedByType, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **User** \ + * **Application** \ + * **ManagedIdentity** \ + * **Key** + */ +export type CreatedByType = string; + +/** The resource model definition for a Azure Resource Manager proxy resource. It will not have tags and a location */ +export interface ProxyResource extends Resource {} + +export function proxyResourceSerializer(item: ProxyResource) { + return item as any; +} + +/** Represents a mongo cluster replica. */ +export interface Replica extends ProxyResource { + /** The resource-specific properties for this resource. */ + properties?: MongoClusterProperties; +} + +/** The properties of a mongo cluster. */ +export interface MongoClusterProperties { + /** The mode to create a mongo cluster. */ + createMode?: CreateMode; + /** The parameters to create a point-in-time restore mongo cluster. */ + restoreParameters?: MongoClusterRestoreParameters; + /** The parameters to create a replica mongo cluster. */ + replicaParameters?: MongoClusterReplicaParameters; + /** The administrator's login for the mongo cluster. */ + administratorLogin?: string; + /** The password of the administrator login. */ + administratorLoginPassword?: string; + /** The Mongo DB server version. Defaults to the latest available version if not specified. */ + serverVersion?: string; + /** The default mongo connection string for the cluster. */ + readonly connectionString?: string; + /** Earliest restore timestamp in UTC ISO8601 format. */ + readonly earliestRestoreTime?: string; + /** The provisioning state of the mongo cluster. */ + readonly provisioningState?: ProvisioningState; + /** The status of the mongo cluster. */ + readonly clusterStatus?: MongoClusterStatus; + /** Whether or not public endpoint access is allowed for this mongo cluster. */ + publicNetworkAccess?: PublicNetworkAccess; + /** The list of node group specs in the cluster. */ + nodeGroupSpecs?: NodeGroupSpec[]; + /** List of private endpoint connections. */ + readonly privateEndpointConnections?: PrivateEndpointConnection[]; + /** List of private endpoint connections. */ + previewFeatures?: PreviewFeature[]; + /** The replication properties for the mongo cluster */ + readonly replica?: ReplicationProperties; + /** The infrastructure version the cluster is provisioned on. */ + readonly infrastructureVersion?: string; +} + +export function mongoClusterPropertiesSerializer( + item: MongoClusterProperties, +): MongoClusterPropertiesRest { + return { + createMode: item["createMode"], + restoreParameters: !item.restoreParameters + ? item.restoreParameters + : mongoClusterRestoreParametersSerializer(item.restoreParameters), + replicaParameters: !item.replicaParameters + ? item.replicaParameters + : mongoClusterReplicaParametersSerializer(item.replicaParameters), + administratorLogin: item["administratorLogin"], + administratorLoginPassword: item["administratorLoginPassword"], + serverVersion: item["serverVersion"], + publicNetworkAccess: item["publicNetworkAccess"], + nodeGroupSpecs: + item["nodeGroupSpecs"] === undefined + ? item["nodeGroupSpecs"] + : item["nodeGroupSpecs"].map(nodeGroupSpecSerializer), + previewFeatures: item["previewFeatures"], + }; +} + +/** Known values of {@link CreateMode} that the service accepts. */ +export enum KnownCreateMode { + /** Default */ + Default = "Default", + /** PointInTimeRestore */ + PointInTimeRestore = "PointInTimeRestore", + /** GeoReplica */ + GeoReplica = "GeoReplica", + /** Replica */ + Replica = "Replica", +} + +/** + * The mode that the Mongo Cluster is created with. \ + * {@link KnownCreateMode} can be used interchangeably with CreateMode, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Default** \ + * **PointInTimeRestore** \ + * **GeoReplica** \ + * **Replica** + */ +export type CreateMode = string; + +/** Parameters used for restore operations */ +export interface MongoClusterRestoreParameters { + /** UTC point in time to restore a mongo cluster */ + pointInTimeUTC?: Date; + /** Resource ID to locate the source cluster to restore */ + sourceResourceId?: string; +} + +export function mongoClusterRestoreParametersSerializer( + item: MongoClusterRestoreParameters, +): MongoClusterRestoreParametersRest { + return { + pointInTimeUTC: item["pointInTimeUTC"]?.toISOString(), + sourceResourceId: item["sourceResourceId"], + }; +} + +/** Parameters used for replica operations. */ +export interface MongoClusterReplicaParameters { + /** The id of the replication source cluster. */ + sourceResourceId: string; + /** The location of the source cluster */ + sourceLocation: string; +} + +export function mongoClusterReplicaParametersSerializer( + item: MongoClusterReplicaParameters, +): MongoClusterReplicaParametersRest { + return { + sourceResourceId: item["sourceResourceId"], + sourceLocation: item["sourceLocation"], + }; +} + +/** Known values of {@link ResourceProvisioningState} that the service accepts. */ +export enum KnownResourceProvisioningState { + /** Succeeded */ + Succeeded = "Succeeded", + /** Failed */ + Failed = "Failed", + /** Canceled */ + Canceled = "Canceled", +} + +/** + * The provisioning state of a resource type. \ + * {@link KnownResourceProvisioningState} can be used interchangeably with ResourceProvisioningState, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Succeeded** \ + * **Failed** \ + * **Canceled** + */ +export type ResourceProvisioningState = string; + +/** Known values of {@link MongoClusterStatus} that the service accepts. */ +export enum KnownMongoClusterStatus { + /** Ready */ + Ready = "Ready", + /** Provisioning */ + Provisioning = "Provisioning", + /** Updating */ + Updating = "Updating", + /** Starting */ + Starting = "Starting", + /** Stopping */ + Stopping = "Stopping", + /** Stopped */ + Stopped = "Stopped", + /** Dropping */ + Dropping = "Dropping", +} + +/** + * The status of the Mongo cluster resource. \ + * {@link KnownMongoClusterStatus} can be used interchangeably with MongoClusterStatus, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Ready** \ + * **Provisioning** \ + * **Updating** \ + * **Starting** \ + * **Stopping** \ + * **Stopped** \ + * **Dropping** + */ +export type MongoClusterStatus = string; + +/** Known values of {@link PublicNetworkAccess} that the service accepts. */ +export enum KnownPublicNetworkAccess { + /** Enabled */ + Enabled = "Enabled", + /** Disabled */ + Disabled = "Disabled", +} + +/** + * Whether or not public endpoint access is allowed for this Mongo cluster. Value is optional and default value is 'Enabled' \ + * {@link KnownPublicNetworkAccess} can be used interchangeably with PublicNetworkAccess, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Enabled** \ + * **Disabled** + */ +export type PublicNetworkAccess = string; + +/** Specification for a node group. */ +export interface NodeGroupSpec { + /** The resource sku for the node group. This defines the size of CPU and memory that is provisioned for each node. Example values: 'M30', 'M40'. */ + sku?: string; + /** The disk storage size for the node group in GB. Example values: 128, 256, 512, 1024. */ + diskSizeGB?: number; + /** Whether high availability is enabled on the node group. */ + enableHa?: boolean; + /** The node type deployed in the node group. */ + kind?: NodeKind; + /** The number of nodes in the node group. */ + nodeCount?: number; +} + +export function nodeGroupSpecSerializer( + item: NodeGroupSpec, +): NodeGroupSpecRest { + return { + sku: item["sku"], + diskSizeGB: item["diskSizeGB"], + enableHa: item["enableHa"], + kind: item["kind"], + nodeCount: item["nodeCount"], + }; +} + +/** Known values of {@link NodeKind} that the service accepts. */ +export enum KnownNodeKind { + /** Shard */ + Shard = "Shard", +} + +/** + * The kind of the node on the cluster. \ + * {@link KnownNodeKind} can be used interchangeably with NodeKind, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Shard** + */ +export type NodeKind = string; + +/** The private endpoint connection resource */ +export interface PrivateEndpointConnection extends Resource { + /** The private endpoint connection properties */ + properties?: PrivateEndpointConnectionProperties; +} + +/** Properties of the private endpoint connection. */ +export interface PrivateEndpointConnectionProperties { + /** The group ids for the private endpoint resource. */ + readonly groupIds?: string[]; + /** The private endpoint resource. */ + privateEndpoint?: PrivateEndpoint; + /** A collection of information about the state of the connection between service consumer and provider. */ + privateLinkServiceConnectionState: PrivateLinkServiceConnectionState; + /** The provisioning state of the private endpoint connection resource. */ + readonly provisioningState?: PrivateEndpointConnectionProvisioningState; +} + +export function privateEndpointConnectionPropertiesSerializer( + item: PrivateEndpointConnectionProperties, +): PrivateEndpointConnectionPropertiesRest { + return { + privateEndpoint: !item.privateEndpoint + ? item.privateEndpoint + : privateEndpointSerializer(item.privateEndpoint), + privateLinkServiceConnectionState: + privateLinkServiceConnectionStateSerializer( + item.privateLinkServiceConnectionState, + ), + }; +} + +/** The Private Endpoint resource. */ +export interface PrivateEndpoint { + /** The resource identifier for private endpoint */ + readonly id?: string; +} + +export function privateEndpointSerializer(item: PrivateEndpoint) { + return item as any; +} + +/** A collection of information about the state of the connection between service consumer and provider. */ +export interface PrivateLinkServiceConnectionState { + /** Indicates whether the connection has been Approved/Rejected/Removed by the owner of the service. */ + status?: PrivateEndpointServiceConnectionStatus; + /** The reason for approval/rejection of the connection. */ + description?: string; + /** A message indicating if changes on the service provider require any updates on the consumer. */ + actionsRequired?: string; +} + +export function privateLinkServiceConnectionStateSerializer( + item: PrivateLinkServiceConnectionState, +): PrivateLinkServiceConnectionStateRest { + return { + status: item["status"], + description: item["description"], + actionsRequired: item["actionsRequired"], + }; +} + +/** Known values of {@link PrivateEndpointServiceConnectionStatus} that the service accepts. */ +export enum KnownPrivateEndpointServiceConnectionStatus { + /** Pending */ + Pending = "Pending", + /** Approved */ + Approved = "Approved", + /** Rejected */ + Rejected = "Rejected", +} + +/** + * The private endpoint connection status. \ + * {@link KnownPrivateEndpointServiceConnectionStatus} can be used interchangeably with PrivateEndpointServiceConnectionStatus, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Pending** \ + * **Approved** \ + * **Rejected** + */ +export type PrivateEndpointServiceConnectionStatus = string; + +/** Known values of {@link PrivateEndpointConnectionProvisioningState} that the service accepts. */ +export enum KnownPrivateEndpointConnectionProvisioningState { + /** Succeeded */ + Succeeded = "Succeeded", + /** Creating */ + Creating = "Creating", + /** Deleting */ + Deleting = "Deleting", + /** Failed */ + Failed = "Failed", +} + +/** + * The current provisioning state. \ + * {@link KnownPrivateEndpointConnectionProvisioningState} can be used interchangeably with PrivateEndpointConnectionProvisioningState, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Succeeded** \ + * **Creating** \ + * **Deleting** \ + * **Failed** + */ +export type PrivateEndpointConnectionProvisioningState = string; + +/** Known values of {@link PreviewFeature} that the service accepts. */ +export enum KnownPreviewFeature { + /** GeoReplicas */ + GeoReplicas = "GeoReplicas", +} + +/** + * Preview features that can be enabled on a mongo cluster. \ + * {@link KnownPreviewFeature} can be used interchangeably with PreviewFeature, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **GeoReplicas** + */ +export type PreviewFeature = string; + +/** Replica properties of the mongo cluster. */ +export interface ReplicationProperties { + /** The resource id the source cluster for the replica cluster. */ + readonly sourceResourceId?: string; + /** The replication role of the cluster */ + readonly role?: ReplicationRole; + /** The replication link state of the replica cluster. */ + readonly replicationState?: ReplicationState; +} + +/** Known values of {@link ReplicationRole} that the service accepts. */ +export enum KnownReplicationRole { + /** Primary */ + Primary = "Primary", + /** AsyncReplica */ + AsyncReplica = "AsyncReplica", + /** GeoAsyncReplica */ + GeoAsyncReplica = "GeoAsyncReplica", +} + +/** + * Replication role of the mongo cluster. \ + * {@link KnownReplicationRole} can be used interchangeably with ReplicationRole, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Primary** \ + * **AsyncReplica** \ + * **GeoAsyncReplica** + */ +export type ReplicationRole = string; + +/** Known values of {@link ReplicationState} that the service accepts. */ +export enum KnownReplicationState { + /** Active */ + Active = "Active", + /** Catchup */ + Catchup = "Catchup", + /** Provisioning */ + Provisioning = "Provisioning", + /** Updating */ + Updating = "Updating", + /** Broken */ + Broken = "Broken", + /** Reconfiguring */ + Reconfiguring = "Reconfiguring", +} + +/** + * The state of the replication link between the replica and source cluster. \ + * {@link KnownReplicationState} can be used interchangeably with ReplicationState, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Active** \ + * **Catchup** \ + * **Provisioning** \ + * **Updating** \ + * **Broken** \ + * **Reconfiguring** + */ +export type ReplicationState = string; + +/** Common error response for all Azure Resource Manager APIs to return error details for failed operations. */ +export interface ErrorResponse { + /** The error object. */ + error?: ErrorDetail; +} + +/** The error detail. */ +export interface ErrorDetail { + /** The error code. */ + readonly code?: string; + /** The error message. */ + readonly message?: string; + /** The error target. */ + readonly target?: string; + /** The error details. */ + readonly details?: ErrorDetail[]; + /** The error additional info. */ + readonly additionalInfo?: ErrorAdditionalInfo[]; +} + +/** The resource management error additional info. */ +export interface ErrorAdditionalInfo { + /** The additional info type. */ + readonly type?: string; + /** The additional info. */ + readonly info?: Record; +} + +/** The response of a PrivateLinkResource list operation. */ +export interface _PrivateLinkResourceListResult { + /** The PrivateLinkResource items on this page */ + value: PrivateLinkResource[]; + /** The link to the next page of items */ + nextLink?: string; +} + +/** Concrete proxy resource types can be created by aliasing this type using a specific property type. */ +export interface PrivateLinkResource extends ProxyResource { + /** The resource-specific properties for this resource. */ + properties?: PrivateLinkResourceProperties; +} + +/** Properties of a private link resource. */ +export interface PrivateLinkResourceProperties { + /** The private link resource group id. */ + readonly groupId?: string; + /** The private link resource required member names. */ + readonly requiredMembers?: string[]; + /** The private link resource private link DNS zone name. */ + requiredZoneNames?: string[]; +} + +/** The response of a PrivateEndpointConnectionResource list operation. */ +export interface _PrivateEndpointConnectionResourceListResult { + /** The PrivateEndpointConnectionResource items on this page */ + value: PrivateEndpointConnectionResource[]; + /** The link to the next page of items */ + nextLink?: string; +} + +/** Concrete proxy resource types can be created by aliasing this type using a specific property type. */ +export interface PrivateEndpointConnectionResource extends ProxyResource { + /** The resource-specific properties for this resource. */ + properties?: PrivateEndpointConnectionProperties; +} + +export function privateEndpointConnectionResourceSerializer( + item: PrivateEndpointConnectionResource, +): PrivateEndpointConnectionResourceRest { + return { + properties: !item.properties + ? item.properties + : privateEndpointConnectionPropertiesSerializer(item.properties), + }; +} + +/** Represents a mongo cluster firewall rule. */ +export interface FirewallRule extends ProxyResource { + /** The resource-specific properties for this resource. */ + properties?: FirewallRuleProperties; +} + +export function firewallRuleSerializer(item: FirewallRule): FirewallRuleRest { + return { + properties: !item.properties + ? item.properties + : firewallRulePropertiesSerializer(item.properties), + }; +} + +/** The properties of a mongo cluster firewall rule. */ +export interface FirewallRuleProperties { + /** The provisioning state of the firewall rule. */ + readonly provisioningState?: ProvisioningState; + /** The start IP address of the mongo cluster firewall rule. Must be IPv4 format. */ + startIpAddress: string; + /** The end IP address of the mongo cluster firewall rule. Must be IPv4 format. */ + endIpAddress: string; +} + +export function firewallRulePropertiesSerializer( + item: FirewallRuleProperties, +): FirewallRulePropertiesRest { + return { + startIpAddress: item["startIpAddress"], + endIpAddress: item["endIpAddress"], + }; +} + +/** The response of a FirewallRule list operation. */ +export interface _FirewallRuleListResult { + /** The FirewallRule items on this page */ + value: FirewallRule[]; + /** The link to the next page of items */ + nextLink?: string; +} + +/** The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location' */ +export interface TrackedResource extends Resource { + /** Resource tags. */ + tags?: Record; + /** The geo-location where the resource lives */ + location: string; +} + +export function trackedResourceSerializer( + item: TrackedResource, +): TrackedResourceRest { + return { + tags: !item.tags ? item.tags : (serializeRecord(item.tags as any) as any), + location: item["location"], + }; +} + +/** Represents a mongo cluster resource. */ +export interface MongoCluster extends TrackedResource { + /** The resource-specific properties for this resource. */ + properties?: MongoClusterProperties; +} + +export function mongoClusterSerializer(item: MongoCluster): MongoClusterRest { + return { + tags: !item.tags ? item.tags : (serializeRecord(item.tags as any) as any), + location: item["location"], + properties: !item.properties + ? item.properties + : mongoClusterPropertiesSerializer(item.properties), + }; +} + +/** The type used for update operations of the MongoCluster. */ +export interface MongoClusterUpdate { + /** Resource tags. */ + tags?: Record; + /** The resource-specific properties for this resource. */ + properties?: MongoClusterUpdateProperties; +} + +export function mongoClusterUpdateSerializer( + item: MongoClusterUpdate, +): MongoClusterUpdateRest { + return { + tags: !item.tags ? item.tags : (serializeRecord(item.tags as any) as any), + properties: !item.properties + ? item.properties + : mongoClusterUpdatePropertiesSerializer(item.properties), + }; +} + +/** The updatable properties of the MongoCluster. */ +export interface MongoClusterUpdateProperties { + /** The administrator's login for the mongo cluster. */ + administratorLogin?: string; + /** The password of the administrator login. */ + administratorLoginPassword?: string; + /** The Mongo DB server version. Defaults to the latest available version if not specified. */ + serverVersion?: string; + /** Whether or not public endpoint access is allowed for this mongo cluster. */ + publicNetworkAccess?: PublicNetworkAccess; + /** The list of node group specs in the cluster. */ + nodeGroupSpecs?: NodeGroupSpec[]; + /** List of private endpoint connections. */ + previewFeatures?: PreviewFeature[]; +} + +export function mongoClusterUpdatePropertiesSerializer( + item: MongoClusterUpdateProperties, +): MongoClusterUpdatePropertiesRest { + return { + administratorLogin: item["administratorLogin"], + administratorLoginPassword: item["administratorLoginPassword"], + serverVersion: item["serverVersion"], + publicNetworkAccess: item["publicNetworkAccess"], + nodeGroupSpecs: + item["nodeGroupSpecs"] === undefined + ? item["nodeGroupSpecs"] + : item["nodeGroupSpecs"].map(nodeGroupSpecSerializer), + previewFeatures: item["previewFeatures"], + }; +} + +/** The response of a MongoCluster list operation. */ +export interface _MongoClusterListResult { + /** The MongoCluster items on this page */ + value: MongoCluster[]; + /** The link to the next page of items */ + nextLink?: string; +} + +/** The connection strings for the given mongo cluster. */ +export interface ListConnectionStringsResult { + /** An array that contains the connection strings for a mongo cluster. */ + readonly connectionStrings?: ConnectionString[]; +} + +/** Connection string for the mongo cluster */ +export interface ConnectionString { + /** Value of the connection string */ + readonly connectionString?: string; + /** Description of the connection string */ + readonly description?: string; +} + +/** The check availability request body. */ +export interface CheckNameAvailabilityRequest { + /** The name of the resource for which availability needs to be checked. */ + name?: string; + /** The resource type. */ + type?: string; +} + +export function checkNameAvailabilityRequestSerializer( + item: CheckNameAvailabilityRequest, +): CheckNameAvailabilityRequestRest { + return { + name: item["name"], + type: item["type"], + }; +} + +/** The check availability result. */ +export interface CheckNameAvailabilityResponse { + /** Indicates if the resource name is available. */ + nameAvailable?: boolean; + /** The reason why the given name is not available. */ + reason?: CheckNameAvailabilityReason; + /** Detailed reason why the given name is not available. */ + message?: string; +} + +/** Known values of {@link CheckNameAvailabilityReason} that the service accepts. */ +export enum KnownCheckNameAvailabilityReason { + /** Invalid */ + Invalid = "Invalid", + /** AlreadyExists */ + AlreadyExists = "AlreadyExists", +} + +/** + * Possible reasons for a name not being available. \ + * {@link KnownCheckNameAvailabilityReason} can be used interchangeably with CheckNameAvailabilityReason, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Invalid** \ + * **AlreadyExists** + */ +export type CheckNameAvailabilityReason = string; + +/** Promote replica request properties. */ +export interface PromoteReplicaRequest { + /** The promote option to apply to the operation. */ + promoteOption: PromoteOption; + /** The mode to apply to the promote operation. Value is optional and default value is 'Switchover'. */ + mode?: PromoteMode; +} + +export function promoteReplicaRequestSerializer( + item: PromoteReplicaRequest, +): PromoteReplicaRequestRest { + return { + promoteOption: item["promoteOption"], + mode: item["mode"], + }; +} + +/** Known values of {@link PromoteOption} that the service accepts. */ +export enum KnownPromoteOption { + /** Forced */ + Forced = "Forced", +} + +/** + * The option to apply to a promote operation. \ + * {@link KnownPromoteOption} can be used interchangeably with PromoteOption, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Forced** + */ +export type PromoteOption = string; + +/** Known values of {@link PromoteMode} that the service accepts. */ +export enum KnownPromoteMode { + /** Switchover */ + Switchover = "Switchover", +} + +/** + * The mode to apply to a promote operation. \ + * {@link KnownPromoteMode} can be used interchangeably with PromoteMode, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Switchover** + */ +export type PromoteMode = string; + +/** A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of results. */ +export interface _OperationListResult { + /** The Operation items on this page */ + value: Operation[]; + /** The link to the next page of items */ + nextLink?: string; +} + +/** Details of a REST API operation, returned from the Resource Provider Operations API */ +export interface Operation { + /** The name of the operation, as per Resource-Based Access Control (RBAC). Examples: "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action" */ + readonly name?: string; + /** Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for Azure Resource Manager/control-plane operations. */ + readonly isDataAction?: boolean; + /** Localized display information for this particular operation. */ + readonly display?: OperationDisplay; + /** The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system" */ + readonly origin?: Origin; + /** Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. */ + actionType?: ActionType; +} + +/** Localized display information for and operation. */ +export interface OperationDisplay { + /** The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring Insights" or "Microsoft Compute". */ + readonly provider?: string; + /** The localized friendly name of the resource type related to this operation. E.g. "Virtual Machines" or "Job Schedule Collections". */ + readonly resource?: string; + /** The concise, localized friendly name for the operation; suitable for dropdowns. E.g. "Create or Update Virtual Machine", "Restart Virtual Machine". */ + readonly operation?: string; + /** The short, localized friendly description of the operation; suitable for tool tips and detailed views. */ + readonly description?: string; +} + +/** Known values of {@link Origin} that the service accepts. */ +export enum KnownOrigin { + /** user */ + user = "user", + /** system */ + system = "system", + /** user,system */ + "user,system" = "user,system", +} + +/** + * The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system" \ + * {@link KnownOrigin} can be used interchangeably with Origin, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **user** \ + * **system** \ + * **user,system** + */ +export type Origin = string; + +/** Known values of {@link ActionType} that the service accepts. */ +export enum KnownActionType { + /** Internal */ + Internal = "Internal", +} + +/** + * Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. \ + * {@link KnownActionType} can be used interchangeably with ActionType, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Internal** + */ +export type ActionType = string; +/** The available API versions. */ +export type Versions = "2024-03-01-preview" | "2024-06-01-preview"; +/** Alias for ProvisioningState */ +export type ProvisioningState = + | string + | ResourceProvisioningState + | "InProgress" + | "Updating" + | "Dropping"; diff --git a/sdk/mongocluster/arm-mongoclustertest/src/models/options.ts b/sdk/mongocluster/arm-mongoclustertest/src/models/options.ts new file mode 100644 index 000000000000..33aa276450a8 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/models/options.ts @@ -0,0 +1,99 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { OperationOptions } from "@azure-rest/core-client"; + +/** Optional parameters. */ +export interface OperationsListOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface MongoClustersGetOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface MongoClustersCreateOrUpdateOptionalParams + extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface MongoClustersUpdateOptionalParams extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface MongoClustersDeleteOptionalParams extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface MongoClustersListByResourceGroupOptionalParams + extends OperationOptions {} + +/** Optional parameters. */ +export interface MongoClustersListOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface MongoClustersListConnectionStringsOptionalParams + extends OperationOptions {} + +/** Optional parameters. */ +export interface MongoClustersCheckNameAvailabilityOptionalParams + extends OperationOptions {} + +/** Optional parameters. */ +export interface MongoClustersPromoteOptionalParams extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface FirewallRulesGetOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface FirewallRulesCreateOrUpdateOptionalParams + extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface FirewallRulesDeleteOptionalParams extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface FirewallRulesListByMongoClusterOptionalParams + extends OperationOptions {} + +/** Optional parameters. */ +export interface PrivateEndpointConnectionsListByMongoClusterOptionalParams + extends OperationOptions {} + +/** Optional parameters. */ +export interface PrivateEndpointConnectionsGetOptionalParams + extends OperationOptions {} + +/** Optional parameters. */ +export interface PrivateEndpointConnectionsCreateOptionalParams + extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface PrivateEndpointConnectionsDeleteOptionalParams + extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface PrivateLinksListByMongoClusterOptionalParams + extends OperationOptions {} + +/** Optional parameters. */ +export interface ReplicasListByParentOptionalParams extends OperationOptions {} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/models/pagingTypes.ts b/sdk/mongocluster/arm-mongoclustertest/src/models/pagingTypes.ts new file mode 100644 index 000000000000..f734b48e62f9 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/models/pagingTypes.ts @@ -0,0 +1,89 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** + * Options for the byPage method + */ +export interface PageSettings { + /** + * A reference to a specific page to start iterating from. + */ + continuationToken?: string; +} + +/** + * An interface that describes a page of results. + */ +export type ContinuablePage = TPage & { + /** + * The token that keeps track of where to continue the iterator + */ + continuationToken?: string; +}; + +/** + * An interface that allows async iterable iteration both to completion and by page. + */ +export interface PagedAsyncIterableIterator< + TElement, + TPage = TElement[], + TPageSettings extends PageSettings = PageSettings, +> { + /** + * The next method, part of the iteration protocol + */ + next(): Promise>; + /** + * The connection to the async iterator, part of the iteration protocol + */ + [Symbol.asyncIterator](): PagedAsyncIterableIterator< + TElement, + TPage, + TPageSettings + >; + /** + * Return an AsyncIterableIterator that works a page at a time + */ + byPage: ( + settings?: TPageSettings, + ) => AsyncIterableIterator>; +} + +/** + * An interface that describes how to communicate with the service. + */ +export interface PagedResult< + TElement, + TPage = TElement[], + TPageSettings extends PageSettings = PageSettings, +> { + /** + * Link to the first page of results. + */ + firstPageLink?: string; + /** + * A method that returns a page of results. + */ + getPage: ( + pageLink?: string, + ) => Promise<{ page: TPage; nextPageLink?: string } | undefined>; + /** + * a function to implement the `byPage` method on the paged async iterator. + */ + byPage?: ( + settings?: TPageSettings, + ) => AsyncIterableIterator>; + + /** + * A function to extract elements from a page. + */ + toElements?: (page: TPage) => TElement[]; +} + +/** + * Options for the paging helper + */ +export interface BuildPagedAsyncIteratorOptions { + itemName?: string; + nextLinkName?: string; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/mongoClusterManagementClient.ts b/sdk/mongocluster/arm-mongoclustertest/src/mongoClusterManagementClient.ts new file mode 100644 index 000000000000..7e45914284e7 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/mongoClusterManagementClient.ts @@ -0,0 +1,88 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { TokenCredential } from "@azure/core-auth"; +import { Pipeline } from "@azure/core-rest-pipeline"; +import { + getOperationsOperations, + OperationsOperations, +} from "./classic/operations/index.js"; +import { + getMongoClustersOperations, + MongoClustersOperations, +} from "./classic/mongoClusters/index.js"; +import { + getFirewallRulesOperations, + FirewallRulesOperations, +} from "./classic/firewallRules/index.js"; +import { + getPrivateEndpointConnectionsOperations, + PrivateEndpointConnectionsOperations, +} from "./classic/privateEndpointConnections/index.js"; +import { + getPrivateLinksOperations, + PrivateLinksOperations, +} from "./classic/privateLinks/index.js"; +import { + getReplicasOperations, + ReplicasOperations, +} from "./classic/replicas/index.js"; +import { + createMongoClusterManagement, + MongoClusterManagementClientOptionalParams, + DocumentDBContext, +} from "./api/index.js"; + +export { MongoClusterManagementClientOptionalParams } from "./api/mongoClusterManagementContext.js"; + +export class MongoClusterManagementClient { + private _client: DocumentDBContext; + /** The pipeline used by this client to make requests */ + public readonly pipeline: Pipeline; + + /** The Microsoft Azure management API provides create, read, update, and delete functionality for Azure Cosmos DB for MongoDB vCore resources including clusters and firewall rules. */ + constructor( + credential: TokenCredential, + subscriptionId: string, + options: MongoClusterManagementClientOptionalParams = {}, + ) { + const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; + const userAgentPrefix = prefixFromOptions + ? `${prefixFromOptions} azsdk-js-client` + : "azsdk-js-client"; + + this._client = createMongoClusterManagement(credential, { + ...options, + userAgentOptions: { userAgentPrefix }, + }); + this.pipeline = this._client.pipeline; + this.operations = getOperationsOperations(this._client); + this.mongoClusters = getMongoClustersOperations( + this._client, + subscriptionId, + ); + this.firewallRules = getFirewallRulesOperations( + this._client, + subscriptionId, + ); + this.privateEndpointConnections = getPrivateEndpointConnectionsOperations( + this._client, + subscriptionId, + ); + this.privateLinks = getPrivateLinksOperations(this._client, subscriptionId); + this.replicas = getReplicasOperations(this._client, subscriptionId); + } + + /** The operation groups for Operations */ + public readonly operations: OperationsOperations; + /** The operation groups for MongoClusters */ + public readonly mongoClusters: MongoClustersOperations; + /** The operation groups for FirewallRules */ + public readonly firewallRules: FirewallRulesOperations; + /** The operation groups for PrivateEndpointConnections */ + public readonly privateEndpointConnections: PrivateEndpointConnectionsOperations; + /** The operation groups for PrivateLinks */ + public readonly privateLinks: PrivateLinksOperations; + /** The operation groups for Replicas */ + public readonly replicas: ReplicasOperations; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/rest/clientDefinitions.ts b/sdk/mongocluster/arm-mongoclustertest/src/rest/clientDefinitions.ts new file mode 100644 index 000000000000..58bcf07a5c7c --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/rest/clientDefinitions.ts @@ -0,0 +1,350 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { + OperationsListParameters, + MongoClustersGetParameters, + MongoClustersCreateOrUpdateParameters, + MongoClustersUpdateParameters, + MongoClustersDeleteParameters, + MongoClustersListByResourceGroupParameters, + MongoClustersListParameters, + MongoClustersListConnectionStringsParameters, + MongoClustersCheckNameAvailabilityParameters, + MongoClustersPromoteParameters, + FirewallRulesGetParameters, + FirewallRulesCreateOrUpdateParameters, + FirewallRulesDeleteParameters, + FirewallRulesListByMongoClusterParameters, + PrivateEndpointConnectionsListByMongoClusterParameters, + PrivateEndpointConnectionsGetParameters, + PrivateEndpointConnectionsCreateParameters, + PrivateEndpointConnectionsDeleteParameters, + PrivateLinksListByMongoClusterParameters, + ReplicasListByParentParameters, +} from "./parameters.js"; +import { + OperationsList200Response, + OperationsListDefaultResponse, + MongoClustersGet200Response, + MongoClustersGetDefaultResponse, + MongoClustersCreateOrUpdate200Response, + MongoClustersCreateOrUpdate201Response, + MongoClustersCreateOrUpdateDefaultResponse, + MongoClustersUpdate200Response, + MongoClustersUpdate202Response, + MongoClustersUpdateDefaultResponse, + MongoClustersDelete202Response, + MongoClustersDelete204Response, + MongoClustersDeleteDefaultResponse, + MongoClustersListByResourceGroup200Response, + MongoClustersListByResourceGroupDefaultResponse, + MongoClustersList200Response, + MongoClustersListDefaultResponse, + MongoClustersListConnectionStrings200Response, + MongoClustersListConnectionStringsDefaultResponse, + MongoClustersCheckNameAvailability200Response, + MongoClustersCheckNameAvailabilityDefaultResponse, + MongoClustersPromote202Response, + MongoClustersPromoteDefaultResponse, + FirewallRulesGet200Response, + FirewallRulesGetDefaultResponse, + FirewallRulesCreateOrUpdate200Response, + FirewallRulesCreateOrUpdate201Response, + FirewallRulesCreateOrUpdate202Response, + FirewallRulesCreateOrUpdateDefaultResponse, + FirewallRulesDelete202Response, + FirewallRulesDelete204Response, + FirewallRulesDeleteDefaultResponse, + FirewallRulesListByMongoCluster200Response, + FirewallRulesListByMongoClusterDefaultResponse, + PrivateEndpointConnectionsListByMongoCluster200Response, + PrivateEndpointConnectionsListByMongoClusterDefaultResponse, + PrivateEndpointConnectionsGet200Response, + PrivateEndpointConnectionsGetDefaultResponse, + PrivateEndpointConnectionsCreate200Response, + PrivateEndpointConnectionsCreate201Response, + PrivateEndpointConnectionsCreate202Response, + PrivateEndpointConnectionsCreateDefaultResponse, + PrivateEndpointConnectionsDelete202Response, + PrivateEndpointConnectionsDelete204Response, + PrivateEndpointConnectionsDeleteDefaultResponse, + PrivateLinksListByMongoCluster200Response, + PrivateLinksListByMongoClusterDefaultResponse, + ReplicasListByParent200Response, + ReplicasListByParentDefaultResponse, +} from "./responses.js"; +import { Client, StreamableMethod } from "@azure-rest/core-client"; + +export interface OperationsList { + /** List the operations for the provider */ + get( + options?: OperationsListParameters, + ): StreamableMethod< + OperationsList200Response | OperationsListDefaultResponse + >; +} + +export interface MongoClustersGet { + /** Gets information about a mongo cluster. */ + get( + options?: MongoClustersGetParameters, + ): StreamableMethod< + MongoClustersGet200Response | MongoClustersGetDefaultResponse + >; + /** Create or update a mongo cluster. Update overwrites all properties for the resource. To only modify some of the properties, use PATCH. */ + put( + options: MongoClustersCreateOrUpdateParameters, + ): StreamableMethod< + | MongoClustersCreateOrUpdate200Response + | MongoClustersCreateOrUpdate201Response + | MongoClustersCreateOrUpdateDefaultResponse + >; + /** Updates an existing mongo cluster. The request body can contain one to many of the properties present in the normal mongo cluster definition. */ + patch( + options: MongoClustersUpdateParameters, + ): StreamableMethod< + | MongoClustersUpdate200Response + | MongoClustersUpdate202Response + | MongoClustersUpdateDefaultResponse + >; + /** Deletes a mongo cluster. */ + delete( + options?: MongoClustersDeleteParameters, + ): StreamableMethod< + | MongoClustersDelete202Response + | MongoClustersDelete204Response + | MongoClustersDeleteDefaultResponse + >; +} + +export interface MongoClustersListByResourceGroup { + /** List all the mongo clusters in a given resource group. */ + get( + options?: MongoClustersListByResourceGroupParameters, + ): StreamableMethod< + | MongoClustersListByResourceGroup200Response + | MongoClustersListByResourceGroupDefaultResponse + >; +} + +export interface MongoClustersList { + /** List all the mongo clusters in a given subscription. */ + get( + options?: MongoClustersListParameters, + ): StreamableMethod< + MongoClustersList200Response | MongoClustersListDefaultResponse + >; +} + +export interface MongoClustersListConnectionStrings { + /** List mongo cluster connection strings. This includes the default connection string using SCRAM-SHA-256, as well as other connection strings supported by the cluster. */ + post( + options: MongoClustersListConnectionStringsParameters, + ): StreamableMethod< + | MongoClustersListConnectionStrings200Response + | MongoClustersListConnectionStringsDefaultResponse + >; +} + +export interface MongoClustersCheckNameAvailability { + /** Check if mongo cluster name is available for use. */ + post( + options: MongoClustersCheckNameAvailabilityParameters, + ): StreamableMethod< + | MongoClustersCheckNameAvailability200Response + | MongoClustersCheckNameAvailabilityDefaultResponse + >; +} + +export interface MongoClustersPromote { + /** Promotes a replica mongo cluster to a primary role. */ + post( + options: MongoClustersPromoteParameters, + ): StreamableMethod< + MongoClustersPromote202Response | MongoClustersPromoteDefaultResponse + >; +} + +export interface FirewallRulesGet { + /** Gets information about a mongo cluster firewall rule. */ + get( + options?: FirewallRulesGetParameters, + ): StreamableMethod< + FirewallRulesGet200Response | FirewallRulesGetDefaultResponse + >; + /** Creates a new firewall rule or updates an existing firewall rule on a mongo cluster. */ + put( + options: FirewallRulesCreateOrUpdateParameters, + ): StreamableMethod< + | FirewallRulesCreateOrUpdate200Response + | FirewallRulesCreateOrUpdate201Response + | FirewallRulesCreateOrUpdate202Response + | FirewallRulesCreateOrUpdateDefaultResponse + >; + /** Deletes a mongo cluster firewall rule. */ + delete( + options?: FirewallRulesDeleteParameters, + ): StreamableMethod< + | FirewallRulesDelete202Response + | FirewallRulesDelete204Response + | FirewallRulesDeleteDefaultResponse + >; +} + +export interface FirewallRulesListByMongoCluster { + /** List all the firewall rules in a given mongo cluster. */ + get( + options?: FirewallRulesListByMongoClusterParameters, + ): StreamableMethod< + | FirewallRulesListByMongoCluster200Response + | FirewallRulesListByMongoClusterDefaultResponse + >; +} + +export interface PrivateEndpointConnectionsListByMongoCluster { + /** List existing private connections */ + get( + options?: PrivateEndpointConnectionsListByMongoClusterParameters, + ): StreamableMethod< + | PrivateEndpointConnectionsListByMongoCluster200Response + | PrivateEndpointConnectionsListByMongoClusterDefaultResponse + >; +} + +export interface PrivateEndpointConnectionsGet { + /** Get a specific private connection */ + get( + options?: PrivateEndpointConnectionsGetParameters, + ): StreamableMethod< + | PrivateEndpointConnectionsGet200Response + | PrivateEndpointConnectionsGetDefaultResponse + >; + /** Create a Private endpoint connection */ + put( + options: PrivateEndpointConnectionsCreateParameters, + ): StreamableMethod< + | PrivateEndpointConnectionsCreate200Response + | PrivateEndpointConnectionsCreate201Response + | PrivateEndpointConnectionsCreate202Response + | PrivateEndpointConnectionsCreateDefaultResponse + >; + /** Delete the private endpoint connection */ + delete( + options?: PrivateEndpointConnectionsDeleteParameters, + ): StreamableMethod< + | PrivateEndpointConnectionsDelete202Response + | PrivateEndpointConnectionsDelete204Response + | PrivateEndpointConnectionsDeleteDefaultResponse + >; +} + +export interface PrivateLinksListByMongoCluster { + /** list private links on the given resource */ + get( + options?: PrivateLinksListByMongoClusterParameters, + ): StreamableMethod< + | PrivateLinksListByMongoCluster200Response + | PrivateLinksListByMongoClusterDefaultResponse + >; +} + +export interface ReplicasListByParent { + /** List all the replicas for the mongo cluster. */ + get( + options?: ReplicasListByParentParameters, + ): StreamableMethod< + ReplicasListByParent200Response | ReplicasListByParentDefaultResponse + >; +} + +export interface Routes { + /** Resource for '/providers/Microsoft.DocumentDB/operations' has methods for the following verbs: get */ + (path: "/providers/Microsoft.DocumentDB/operations"): OperationsList; + /** Resource for '/subscriptions/\{subscriptionId\}/resourceGroups/\{resourceGroupName\}/providers/Microsoft.DocumentDB/mongoClusters/\{mongoClusterName\}' has methods for the following verbs: get, put, patch, delete */ + ( + path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}", + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + ): MongoClustersGet; + /** Resource for '/subscriptions/\{subscriptionId\}/resourceGroups/\{resourceGroupName\}/providers/Microsoft.DocumentDB/mongoClusters' has methods for the following verbs: get */ + ( + path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters", + subscriptionId: string, + resourceGroupName: string, + ): MongoClustersListByResourceGroup; + /** Resource for '/subscriptions/\{subscriptionId\}/providers/Microsoft.DocumentDB/mongoClusters' has methods for the following verbs: get */ + ( + path: "/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/mongoClusters", + subscriptionId: string, + ): MongoClustersList; + /** Resource for '/subscriptions/\{subscriptionId\}/resourceGroups/\{resourceGroupName\}/providers/Microsoft.DocumentDB/mongoClusters/\{mongoClusterName\}/listConnectionStrings' has methods for the following verbs: post */ + ( + path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/listConnectionStrings", + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + ): MongoClustersListConnectionStrings; + /** Resource for '/subscriptions/\{subscriptionId\}/providers/Microsoft.DocumentDB/locations/\{location\}/checkMongoClusterNameAvailability' has methods for the following verbs: post */ + ( + path: "/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}/checkMongoClusterNameAvailability", + subscriptionId: string, + location: string, + ): MongoClustersCheckNameAvailability; + /** Resource for '/subscriptions/\{subscriptionId\}/resourceGroups/\{resourceGroupName\}/providers/Microsoft.DocumentDB/mongoClusters/\{mongoClusterName\}/promote' has methods for the following verbs: post */ + ( + path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/promote", + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + ): MongoClustersPromote; + /** Resource for '/subscriptions/\{subscriptionId\}/resourceGroups/\{resourceGroupName\}/providers/Microsoft.DocumentDB/mongoClusters/\{mongoClusterName\}/firewallRules/\{firewallRuleName\}' has methods for the following verbs: get, put, delete */ + ( + path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/firewallRules/{firewallRuleName}", + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + firewallRuleName: string, + ): FirewallRulesGet; + /** Resource for '/subscriptions/\{subscriptionId\}/resourceGroups/\{resourceGroupName\}/providers/Microsoft.DocumentDB/mongoClusters/\{mongoClusterName\}/firewallRules' has methods for the following verbs: get */ + ( + path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/firewallRules", + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + ): FirewallRulesListByMongoCluster; + /** Resource for '/subscriptions/\{subscriptionId\}/resourceGroups/\{resourceGroupName\}/providers/Microsoft.DocumentDB/mongoClusters/\{mongoClusterName\}/privateEndpointConnections' has methods for the following verbs: get */ + ( + path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateEndpointConnections", + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + ): PrivateEndpointConnectionsListByMongoCluster; + /** Resource for '/subscriptions/\{subscriptionId\}/resourceGroups/\{resourceGroupName\}/providers/Microsoft.DocumentDB/mongoClusters/\{mongoClusterName\}/privateEndpointConnections/\{privateEndpointConnectionName\}' has methods for the following verbs: get, put, delete */ + ( + path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateEndpointConnections/{privateEndpointConnectionName}", + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + privateEndpointConnectionName: string, + ): PrivateEndpointConnectionsGet; + /** Resource for '/subscriptions/\{subscriptionId\}/resourceGroups/\{resourceGroupName\}/providers/Microsoft.DocumentDB/mongoClusters/\{mongoClusterName\}/privateLinkResources' has methods for the following verbs: get */ + ( + path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateLinkResources", + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + ): PrivateLinksListByMongoCluster; + /** Resource for '/subscriptions/\{subscriptionId\}/resourceGroups/\{resourceGroupName\}/providers/Microsoft.DocumentDB/mongoClusters/\{mongoClusterName\}/replicas' has methods for the following verbs: get */ + ( + path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/replicas", + subscriptionId: string, + resourceGroupName: string, + mongoClusterName: string, + ): ReplicasListByParent; +} + +export type DocumentDBContext = Client & { + path: Routes; +}; diff --git a/sdk/mongocluster/arm-mongoclustertest/src/rest/documentDBClient.ts b/sdk/mongocluster/arm-mongoclustertest/src/rest/documentDBClient.ts new file mode 100644 index 000000000000..1020d6e44d1c --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/rest/documentDBClient.ts @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { getClient, ClientOptions } from "@azure-rest/core-client"; +import { logger } from "../logger.js"; +import { TokenCredential } from "@azure/core-auth"; +import { DocumentDBContext } from "./clientDefinitions.js"; + +/** The optional parameters for the client */ +export interface DocumentDBContextOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + +/** + * Initialize a new instance of `DocumentDBContext` + * @param credentials - uniquely identify client credential + * @param options - the parameter for all optional parameters + */ +export default function createClient( + credentials: TokenCredential, + { + apiVersion = "2024-06-01-preview", + ...options + }: DocumentDBContextOptions = {}, +): DocumentDBContext { + const endpointUrl = + options.endpoint ?? options.baseUrl ?? `https://management.azure.com`; + const userAgentInfo = `azsdk-js-arm-mongoclustertest/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, + }, + credentials: { + scopes: options.credentials?.scopes ?? [`${endpointUrl}/.default`], + }, + }; + const client = getClient( + endpointUrl, + credentials, + options, + ) as DocumentDBContext; + + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/rest/index.ts b/sdk/mongocluster/arm-mongoclustertest/src/rest/index.ts new file mode 100644 index 000000000000..1e93ef0cbc8a --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/rest/index.ts @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import DocumentDBClient from "./documentDBClient.js"; + +export * from "./documentDBClient.js"; +export * from "./parameters.js"; +export * from "./responses.js"; +export * from "./clientDefinitions.js"; +export * from "./isUnexpected.js"; +export * from "./models.js"; +export * from "./outputModels.js"; +export * from "./paginateHelper.js"; +export * from "./pollingHelper.js"; + +export default DocumentDBClient; diff --git a/sdk/mongocluster/arm-mongoclustertest/src/rest/isUnexpected.ts b/sdk/mongocluster/arm-mongoclustertest/src/rest/isUnexpected.ts new file mode 100644 index 000000000000..c2b225fddbcd --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/rest/isUnexpected.ts @@ -0,0 +1,378 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { + OperationsList200Response, + OperationsListDefaultResponse, + MongoClustersGet200Response, + MongoClustersGetDefaultResponse, + MongoClustersCreateOrUpdate200Response, + MongoClustersCreateOrUpdate201Response, + MongoClustersCreateOrUpdateLogicalResponse, + MongoClustersCreateOrUpdateDefaultResponse, + MongoClustersUpdate200Response, + MongoClustersUpdate202Response, + MongoClustersUpdateLogicalResponse, + MongoClustersUpdateDefaultResponse, + MongoClustersDelete202Response, + MongoClustersDelete204Response, + MongoClustersDeleteLogicalResponse, + MongoClustersDeleteDefaultResponse, + MongoClustersListByResourceGroup200Response, + MongoClustersListByResourceGroupDefaultResponse, + MongoClustersList200Response, + MongoClustersListDefaultResponse, + MongoClustersListConnectionStrings200Response, + MongoClustersListConnectionStringsDefaultResponse, + MongoClustersCheckNameAvailability200Response, + MongoClustersCheckNameAvailabilityDefaultResponse, + MongoClustersPromote202Response, + MongoClustersPromoteLogicalResponse, + MongoClustersPromoteDefaultResponse, + FirewallRulesGet200Response, + FirewallRulesGetDefaultResponse, + FirewallRulesCreateOrUpdate200Response, + FirewallRulesCreateOrUpdate201Response, + FirewallRulesCreateOrUpdate202Response, + FirewallRulesCreateOrUpdateLogicalResponse, + FirewallRulesCreateOrUpdateDefaultResponse, + FirewallRulesDelete202Response, + FirewallRulesDelete204Response, + FirewallRulesDeleteLogicalResponse, + FirewallRulesDeleteDefaultResponse, + FirewallRulesListByMongoCluster200Response, + FirewallRulesListByMongoClusterDefaultResponse, + PrivateEndpointConnectionsListByMongoCluster200Response, + PrivateEndpointConnectionsListByMongoClusterDefaultResponse, + PrivateEndpointConnectionsGet200Response, + PrivateEndpointConnectionsGetDefaultResponse, + PrivateEndpointConnectionsCreate200Response, + PrivateEndpointConnectionsCreate201Response, + PrivateEndpointConnectionsCreate202Response, + PrivateEndpointConnectionsCreateLogicalResponse, + PrivateEndpointConnectionsCreateDefaultResponse, + PrivateEndpointConnectionsDelete202Response, + PrivateEndpointConnectionsDelete204Response, + PrivateEndpointConnectionsDeleteLogicalResponse, + PrivateEndpointConnectionsDeleteDefaultResponse, + PrivateLinksListByMongoCluster200Response, + PrivateLinksListByMongoClusterDefaultResponse, + ReplicasListByParent200Response, + ReplicasListByParentDefaultResponse, +} from "./responses.js"; + +const responseMap: Record = { + "GET /providers/Microsoft.DocumentDB/operations": ["200"], + "GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}": + ["200"], + "PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}": + ["200", "201"], + "PATCH /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}": + ["200", "202"], + "DELETE /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}": + ["202", "204"], + "GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters": + ["200"], + "GET /subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/mongoClusters": + ["200"], + "POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/listConnectionStrings": + ["200"], + "POST /subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}/checkMongoClusterNameAvailability": + ["200"], + "GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/promote": + ["200", "202"], + "POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/promote": + ["202"], + "GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/firewallRules/{firewallRuleName}": + ["200"], + "PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/firewallRules/{firewallRuleName}": + ["200", "201", "202"], + "DELETE /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/firewallRules/{firewallRuleName}": + ["202", "204"], + "GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/firewallRules": + ["200"], + "GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateEndpointConnections": + ["200"], + "GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateEndpointConnections/{privateEndpointConnectionName}": + ["200"], + "PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateEndpointConnections/{privateEndpointConnectionName}": + ["200", "201", "202"], + "DELETE /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateEndpointConnections/{privateEndpointConnectionName}": + ["202", "204"], + "GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateLinkResources": + ["200"], + "GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/replicas": + ["200"], +}; + +export function isUnexpected( + response: OperationsList200Response | OperationsListDefaultResponse, +): response is OperationsListDefaultResponse; +export function isUnexpected( + response: MongoClustersGet200Response | MongoClustersGetDefaultResponse, +): response is MongoClustersGetDefaultResponse; +export function isUnexpected( + response: + | MongoClustersCreateOrUpdate200Response + | MongoClustersCreateOrUpdate201Response + | MongoClustersCreateOrUpdateLogicalResponse + | MongoClustersCreateOrUpdateDefaultResponse, +): response is MongoClustersCreateOrUpdateDefaultResponse; +export function isUnexpected( + response: + | MongoClustersUpdate200Response + | MongoClustersUpdate202Response + | MongoClustersUpdateLogicalResponse + | MongoClustersUpdateDefaultResponse, +): response is MongoClustersUpdateDefaultResponse; +export function isUnexpected( + response: + | MongoClustersDelete202Response + | MongoClustersDelete204Response + | MongoClustersDeleteLogicalResponse + | MongoClustersDeleteDefaultResponse, +): response is MongoClustersDeleteDefaultResponse; +export function isUnexpected( + response: + | MongoClustersListByResourceGroup200Response + | MongoClustersListByResourceGroupDefaultResponse, +): response is MongoClustersListByResourceGroupDefaultResponse; +export function isUnexpected( + response: MongoClustersList200Response | MongoClustersListDefaultResponse, +): response is MongoClustersListDefaultResponse; +export function isUnexpected( + response: + | MongoClustersListConnectionStrings200Response + | MongoClustersListConnectionStringsDefaultResponse, +): response is MongoClustersListConnectionStringsDefaultResponse; +export function isUnexpected( + response: + | MongoClustersCheckNameAvailability200Response + | MongoClustersCheckNameAvailabilityDefaultResponse, +): response is MongoClustersCheckNameAvailabilityDefaultResponse; +export function isUnexpected( + response: + | MongoClustersPromote202Response + | MongoClustersPromoteLogicalResponse + | MongoClustersPromoteDefaultResponse, +): response is MongoClustersPromoteDefaultResponse; +export function isUnexpected( + response: FirewallRulesGet200Response | FirewallRulesGetDefaultResponse, +): response is FirewallRulesGetDefaultResponse; +export function isUnexpected( + response: + | FirewallRulesCreateOrUpdate200Response + | FirewallRulesCreateOrUpdate201Response + | FirewallRulesCreateOrUpdate202Response + | FirewallRulesCreateOrUpdateLogicalResponse + | FirewallRulesCreateOrUpdateDefaultResponse, +): response is FirewallRulesCreateOrUpdateDefaultResponse; +export function isUnexpected( + response: + | FirewallRulesDelete202Response + | FirewallRulesDelete204Response + | FirewallRulesDeleteLogicalResponse + | FirewallRulesDeleteDefaultResponse, +): response is FirewallRulesDeleteDefaultResponse; +export function isUnexpected( + response: + | FirewallRulesListByMongoCluster200Response + | FirewallRulesListByMongoClusterDefaultResponse, +): response is FirewallRulesListByMongoClusterDefaultResponse; +export function isUnexpected( + response: + | PrivateEndpointConnectionsListByMongoCluster200Response + | PrivateEndpointConnectionsListByMongoClusterDefaultResponse, +): response is PrivateEndpointConnectionsListByMongoClusterDefaultResponse; +export function isUnexpected( + response: + | PrivateEndpointConnectionsGet200Response + | PrivateEndpointConnectionsGetDefaultResponse, +): response is PrivateEndpointConnectionsGetDefaultResponse; +export function isUnexpected( + response: + | PrivateEndpointConnectionsCreate200Response + | PrivateEndpointConnectionsCreate201Response + | PrivateEndpointConnectionsCreate202Response + | PrivateEndpointConnectionsCreateLogicalResponse + | PrivateEndpointConnectionsCreateDefaultResponse, +): response is PrivateEndpointConnectionsCreateDefaultResponse; +export function isUnexpected( + response: + | PrivateEndpointConnectionsDelete202Response + | PrivateEndpointConnectionsDelete204Response + | PrivateEndpointConnectionsDeleteLogicalResponse + | PrivateEndpointConnectionsDeleteDefaultResponse, +): response is PrivateEndpointConnectionsDeleteDefaultResponse; +export function isUnexpected( + response: + | PrivateLinksListByMongoCluster200Response + | PrivateLinksListByMongoClusterDefaultResponse, +): response is PrivateLinksListByMongoClusterDefaultResponse; +export function isUnexpected( + response: + | ReplicasListByParent200Response + | ReplicasListByParentDefaultResponse, +): response is ReplicasListByParentDefaultResponse; +export function isUnexpected( + response: + | OperationsList200Response + | OperationsListDefaultResponse + | MongoClustersGet200Response + | MongoClustersGetDefaultResponse + | MongoClustersCreateOrUpdate200Response + | MongoClustersCreateOrUpdate201Response + | MongoClustersCreateOrUpdateLogicalResponse + | MongoClustersCreateOrUpdateDefaultResponse + | MongoClustersUpdate200Response + | MongoClustersUpdate202Response + | MongoClustersUpdateLogicalResponse + | MongoClustersUpdateDefaultResponse + | MongoClustersDelete202Response + | MongoClustersDelete204Response + | MongoClustersDeleteLogicalResponse + | MongoClustersDeleteDefaultResponse + | MongoClustersListByResourceGroup200Response + | MongoClustersListByResourceGroupDefaultResponse + | MongoClustersList200Response + | MongoClustersListDefaultResponse + | MongoClustersListConnectionStrings200Response + | MongoClustersListConnectionStringsDefaultResponse + | MongoClustersCheckNameAvailability200Response + | MongoClustersCheckNameAvailabilityDefaultResponse + | MongoClustersPromote202Response + | MongoClustersPromoteLogicalResponse + | MongoClustersPromoteDefaultResponse + | FirewallRulesGet200Response + | FirewallRulesGetDefaultResponse + | FirewallRulesCreateOrUpdate200Response + | FirewallRulesCreateOrUpdate201Response + | FirewallRulesCreateOrUpdate202Response + | FirewallRulesCreateOrUpdateLogicalResponse + | FirewallRulesCreateOrUpdateDefaultResponse + | FirewallRulesDelete202Response + | FirewallRulesDelete204Response + | FirewallRulesDeleteLogicalResponse + | FirewallRulesDeleteDefaultResponse + | FirewallRulesListByMongoCluster200Response + | FirewallRulesListByMongoClusterDefaultResponse + | PrivateEndpointConnectionsListByMongoCluster200Response + | PrivateEndpointConnectionsListByMongoClusterDefaultResponse + | PrivateEndpointConnectionsGet200Response + | PrivateEndpointConnectionsGetDefaultResponse + | PrivateEndpointConnectionsCreate200Response + | PrivateEndpointConnectionsCreate201Response + | PrivateEndpointConnectionsCreate202Response + | PrivateEndpointConnectionsCreateLogicalResponse + | PrivateEndpointConnectionsCreateDefaultResponse + | PrivateEndpointConnectionsDelete202Response + | PrivateEndpointConnectionsDelete204Response + | PrivateEndpointConnectionsDeleteLogicalResponse + | PrivateEndpointConnectionsDeleteDefaultResponse + | PrivateLinksListByMongoCluster200Response + | PrivateLinksListByMongoClusterDefaultResponse + | ReplicasListByParent200Response + | ReplicasListByParentDefaultResponse, +): response is + | OperationsListDefaultResponse + | MongoClustersGetDefaultResponse + | MongoClustersCreateOrUpdateDefaultResponse + | MongoClustersUpdateDefaultResponse + | MongoClustersDeleteDefaultResponse + | MongoClustersListByResourceGroupDefaultResponse + | MongoClustersListDefaultResponse + | MongoClustersListConnectionStringsDefaultResponse + | MongoClustersCheckNameAvailabilityDefaultResponse + | MongoClustersPromoteDefaultResponse + | FirewallRulesGetDefaultResponse + | FirewallRulesCreateOrUpdateDefaultResponse + | FirewallRulesDeleteDefaultResponse + | FirewallRulesListByMongoClusterDefaultResponse + | PrivateEndpointConnectionsListByMongoClusterDefaultResponse + | PrivateEndpointConnectionsGetDefaultResponse + | PrivateEndpointConnectionsCreateDefaultResponse + | PrivateEndpointConnectionsDeleteDefaultResponse + | PrivateLinksListByMongoClusterDefaultResponse + | ReplicasListByParentDefaultResponse { + const lroOriginal = response.headers["x-ms-original-url"]; + const url = new URL(lroOriginal ?? response.request.url); + const method = response.request.method; + let pathDetails = responseMap[`${method} ${url.pathname}`]; + if (!pathDetails) { + pathDetails = getParametrizedPathSuccess(method, url.pathname); + } + return !pathDetails.includes(response.status); +} + +function getParametrizedPathSuccess(method: string, path: string): string[] { + const pathParts = path.split("/"); + + // Traverse list to match the longest candidate + // matchedLen: the length of candidate path + // matchedValue: the matched status code array + let matchedLen = -1, + matchedValue: string[] = []; + + // Iterate the responseMap to find a match + for (const [key, value] of Object.entries(responseMap)) { + // Extracting the path from the map key which is in format + // GET /path/foo + if (!key.startsWith(method)) { + continue; + } + const candidatePath = getPathFromMapKey(key); + // Get each part of the url path + const candidateParts = candidatePath.split("/"); + + // track if we have found a match to return the values found. + let found = true; + for ( + let i = candidateParts.length - 1, j = pathParts.length - 1; + i >= 1 && j >= 1; + i--, j-- + ) { + if ( + candidateParts[i]?.startsWith("{") && + candidateParts[i]?.indexOf("}") !== -1 + ) { + const start = candidateParts[i]!.indexOf("}") + 1, + end = candidateParts[i]?.length; + // If the current part of the candidate is a "template" part + // Try to use the suffix of pattern to match the path + // {guid} ==> $ + // {guid}:export ==> :export$ + const isMatched = new RegExp( + `${candidateParts[i]?.slice(start, end)}`, + ).test(pathParts[j] || ""); + + if (!isMatched) { + found = false; + break; + } + continue; + } + + // If the candidate part is not a template and + // the parts don't match mark the candidate as not found + // to move on with the next candidate path. + if (candidateParts[i] !== pathParts[j]) { + found = false; + break; + } + } + + // We finished evaluating the current candidate parts + // Update the matched value if and only if we found the longer pattern + if (found && candidatePath.length > matchedLen) { + matchedLen = candidatePath.length; + matchedValue = value; + } + } + + return matchedValue; +} + +function getPathFromMapKey(mapKey: string): string { + const pathStart = mapKey.indexOf("/"); + return mapKey.slice(pathStart); +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/rest/models.ts b/sdk/mongocluster/arm-mongoclustertest/src/rest/models.ts new file mode 100644 index 000000000000..785629a6afd9 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/rest/models.ts @@ -0,0 +1,336 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/** Represents a mongo cluster resource. */ +export interface MongoCluster extends TrackedResource { + /** The resource-specific properties for this resource. */ + properties?: MongoClusterProperties; +} + +/** The properties of a mongo cluster. */ +export interface MongoClusterProperties { + /** + * The mode to create a mongo cluster. + * + * Possible values: "Default", "PointInTimeRestore", "GeoReplica", "Replica" + */ + createMode?: CreateMode; + /** The parameters to create a point-in-time restore mongo cluster. */ + restoreParameters?: MongoClusterRestoreParameters; + /** The parameters to create a replica mongo cluster. */ + replicaParameters?: MongoClusterReplicaParameters; + /** The administrator's login for the mongo cluster. */ + administratorLogin?: string; + /** The password of the administrator login. */ + administratorLoginPassword?: string; + /** The Mongo DB server version. Defaults to the latest available version if not specified. */ + serverVersion?: string; + /** + * Whether or not public endpoint access is allowed for this mongo cluster. + * + * Possible values: "Enabled", "Disabled" + */ + publicNetworkAccess?: PublicNetworkAccess; + /** The list of node group specs in the cluster. */ + nodeGroupSpecs?: Array; + /** List of private endpoint connections. */ + previewFeatures?: PreviewFeature[]; +} + +/** Parameters used for restore operations */ +export interface MongoClusterRestoreParameters { + /** UTC point in time to restore a mongo cluster */ + pointInTimeUTC?: Date | string; + /** Resource ID to locate the source cluster to restore */ + sourceResourceId?: string; +} + +/** Parameters used for replica operations. */ +export interface MongoClusterReplicaParameters { + /** The id of the replication source cluster. */ + sourceResourceId: string; + /** The location of the source cluster */ + sourceLocation: string; +} + +/** Specification for a node group. */ +export interface NodeGroupSpec { + /** The resource sku for the node group. This defines the size of CPU and memory that is provisioned for each node. Example values: 'M30', 'M40'. */ + sku?: string; + /** The disk storage size for the node group in GB. Example values: 128, 256, 512, 1024. */ + diskSizeGB?: number; + /** Whether high availability is enabled on the node group. */ + enableHa?: boolean; + /** + * The node type deployed in the node group. + * + * Possible values: "Shard" + */ + kind?: NodeKind; + /** The number of nodes in the node group. */ + nodeCount?: number; +} + +/** The private endpoint connection resource */ +export interface PrivateEndpointConnection extends Resource { + /** The private endpoint connection properties */ + properties?: PrivateEndpointConnectionProperties; +} + +/** Properties of the private endpoint connection. */ +export interface PrivateEndpointConnectionProperties { + /** The private endpoint resource. */ + privateEndpoint?: PrivateEndpoint; + /** A collection of information about the state of the connection between service consumer and provider. */ + privateLinkServiceConnectionState: PrivateLinkServiceConnectionState; +} + +/** The Private Endpoint resource. */ +export interface PrivateEndpoint {} + +/** A collection of information about the state of the connection between service consumer and provider. */ +export interface PrivateLinkServiceConnectionState { + /** + * Indicates whether the connection has been Approved/Rejected/Removed by the owner of the service. + * + * Possible values: "Pending", "Approved", "Rejected" + */ + status?: PrivateEndpointServiceConnectionStatus; + /** The reason for approval/rejection of the connection. */ + description?: string; + /** A message indicating if changes on the service provider require any updates on the consumer. */ + actionsRequired?: string; +} + +/** Common fields that are returned in the response for all Azure Resource Manager resources */ +export interface Resource {} + +/** Metadata pertaining to creation and last modification of the resource. */ +export interface SystemData { + /** The identity that created the resource. */ + createdBy?: string; + /** + * The type of identity that created the resource. + * + * Possible values: "User", "Application", "ManagedIdentity", "Key" + */ + createdByType?: CreatedByType; + /** The timestamp of resource creation (UTC). */ + createdAt?: Date | string; + /** The identity that last modified the resource. */ + lastModifiedBy?: string; + /** + * The type of identity that last modified the resource. + * + * Possible values: "User", "Application", "ManagedIdentity", "Key" + */ + lastModifiedByType?: CreatedByType; + /** The timestamp of resource last modification (UTC) */ + lastModifiedAt?: Date | string; +} + +/** The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location' */ +export interface TrackedResource extends Resource { + /** Resource tags. */ + tags?: Record; + /** The geo-location where the resource lives */ + location: string; +} + +/** The resource model definition containing the full set of allowed properties for a resource. Except properties bag, there cannot be a top level property outside of this set. */ +export interface ResourceModelWithAllowedPropertySet extends TrackedResource { + /** + * The fully qualified resource ID of the resource that manages this resource. Indicates if this resource is managed by another Azure resource. + * If this is present, complete mode deployment will not delete the resource if it is removed from the template since it is managed by another resource. + */ + managedBy?: string; + /** + * Metadata used by portal/tooling/etc to render different UX experiences for resources of the same type; e.g. ApiApps are a kind of Microsoft.Web/sites type. + * If supported, the resource provider must validate and persist this value. + */ + kind?: string; + /** + * The etag field is *not* required. If it is provided in the response body, it must also be provided as a header per the normal etag convention. + * Entity tags are used for comparing two or more entities from the same requested resource. HTTP/1.1 uses entity tags in the etag (section 14.19), + * If-Match (section 14.24), If-None-Match (section 14.26), and If-Range (section 14.27) header fields. + */ + eTag?: string; + identity?: Identity; + sku?: Sku; + plan?: Plan; +} + +/** Identity for the resource. */ +export interface Identity { + /** The identity type. */ + type?: ResourceIdentityType; +} + +/** The resource model definition representing SKU */ +export interface Sku { + /** The name of the SKU. Ex - P3. It is typically a letter+number code */ + name: string; + /** This field is required to be implemented by the Resource Provider if the service has more than one tier, but is not required on a PUT. */ + tier?: SkuTier; + /** The SKU size. When the name field is the combination of tier and some other value, this would be the standalone code. */ + size?: string; + /** If the service has different generations of hardware, for the same SKU, then that can be captured here. */ + family?: string; + /** If the SKU supports scale out/in then the capacity integer should be included. If scale out/in is not possible for the resource this may be omitted. */ + capacity?: number; +} + +/** Plan for the resource. */ +export interface Plan { + /** A user defined name of the 3rd Party Artifact that is being procured. */ + name: string; + /** The publisher of the 3rd Party Artifact that is being bought. E.g. NewRelic */ + publisher: string; + /** The 3rd Party artifact that is being procured. E.g. NewRelic. Product maps to the OfferID specified for the artifact at the time of Data Market onboarding. */ + product: string; + /** A publisher provided promotion code as provisioned in Data Market for the said product/artifact. */ + promotionCode?: string; + /** The version of the desired product/artifact. */ + version?: string; +} + +/** The resource model definition for a Azure Resource Manager proxy resource. It will not have tags and a location */ +export interface ProxyResource extends Resource {} + +/** Represents a mongo cluster firewall rule. */ +export interface FirewallRule extends ProxyResource { + /** The resource-specific properties for this resource. */ + properties?: FirewallRuleProperties; +} + +/** The properties of a mongo cluster firewall rule. */ +export interface FirewallRuleProperties { + /** The start IP address of the mongo cluster firewall rule. Must be IPv4 format. */ + startIpAddress: string; + /** The end IP address of the mongo cluster firewall rule. Must be IPv4 format. */ + endIpAddress: string; +} + +/** Concrete proxy resource types can be created by aliasing this type using a specific property type. */ +export interface PrivateEndpointConnectionResource extends ProxyResource { + /** The resource-specific properties for this resource. */ + properties?: PrivateEndpointConnectionProperties; +} + +/** Concrete proxy resource types can be created by aliasing this type using a specific property type. */ +export interface PrivateLinkResource extends ProxyResource { + /** The resource-specific properties for this resource. */ + properties?: PrivateLinkResourceProperties; +} + +/** Properties of a private link resource. */ +export interface PrivateLinkResourceProperties { + /** The private link resource private link DNS zone name. */ + requiredZoneNames?: string[]; +} + +/** Represents a mongo cluster replica. */ +export interface Replica extends ProxyResource { + /** The resource-specific properties for this resource. */ + properties?: MongoClusterProperties; +} + +/** The base extension resource. */ +export interface ExtensionResource extends Resource {} + +/** The resource model definition for an Azure Resource Manager resource with an etag. */ +export interface AzureEntityResource extends Resource {} + +/** A private link resource. */ +export interface PrivateLinkResource extends Resource { + /** Resource properties. */ + properties?: PrivateLinkResourceProperties; +} + +/** Replica properties of the mongo cluster. */ +export interface ReplicationProperties {} + +/** The type used for update operations of the MongoCluster. */ +export interface MongoClusterUpdate { + /** Resource tags. */ + tags?: Record; + /** The resource-specific properties for this resource. */ + properties?: MongoClusterUpdateProperties; +} + +/** The updatable properties of the MongoCluster. */ +export interface MongoClusterUpdateProperties { + /** The administrator's login for the mongo cluster. */ + administratorLogin?: string; + /** The password of the administrator login. */ + administratorLoginPassword?: string; + /** The Mongo DB server version. Defaults to the latest available version if not specified. */ + serverVersion?: string; + /** + * Whether or not public endpoint access is allowed for this mongo cluster. + * + * Possible values: "Enabled", "Disabled" + */ + publicNetworkAccess?: PublicNetworkAccess; + /** The list of node group specs in the cluster. */ + nodeGroupSpecs?: Array; + /** List of private endpoint connections. */ + previewFeatures?: PreviewFeature[]; +} + +/** The check availability request body. */ +export interface CheckNameAvailabilityRequest { + /** The name of the resource for which availability needs to be checked. */ + name?: string; + /** The resource type. */ + type?: string; +} + +/** Promote replica request properties. */ +export interface PromoteReplicaRequest { + /** + * The promote option to apply to the operation. + * + * Possible values: "Forced" + */ + promoteOption: PromoteOption; + /** + * The mode to apply to the promote operation. Value is optional and default value is 'Switchover'. + * + * Possible values: "Switchover" + */ + mode?: PromoteMode; +} + +/** Alias for CreateMode */ +export type CreateMode = string; +/** Alias for ResourceProvisioningState */ +export type ResourceProvisioningState = string; +/** Alias for ProvisioningState */ +export type ProvisioningState = string; +/** Alias for MongoClusterStatus */ +export type MongoClusterStatus = string; +/** Alias for PublicNetworkAccess */ +export type PublicNetworkAccess = string; +/** Alias for NodeKind */ +export type NodeKind = string; +/** Alias for PrivateEndpointServiceConnectionStatus */ +export type PrivateEndpointServiceConnectionStatus = string; +/** Alias for PrivateEndpointConnectionProvisioningState */ +export type PrivateEndpointConnectionProvisioningState = string; +/** Alias for CreatedByType */ +export type CreatedByType = string; +/** Alias for ResourceIdentityType */ +export type ResourceIdentityType = "SystemAssigned"; +/** Alias for SkuTier */ +export type SkuTier = "Free" | "Basic" | "Standard" | "Premium"; +/** Alias for PreviewFeature */ +export type PreviewFeature = string; +/** Alias for ReplicationRole */ +export type ReplicationRole = string; +/** Alias for ReplicationState */ +export type ReplicationState = string; +/** Alias for PromoteOption */ +export type PromoteOption = string; +/** Alias for PromoteMode */ +export type PromoteMode = string; diff --git a/sdk/mongocluster/arm-mongoclustertest/src/rest/outputModels.ts b/sdk/mongocluster/arm-mongoclustertest/src/rest/outputModels.ts new file mode 100644 index 000000000000..d707b75880c1 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/rest/outputModels.ts @@ -0,0 +1,468 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { Paged } from "@azure/core-paging"; + +/** Details of a REST API operation, returned from the Resource Provider Operations API */ +export interface OperationOutput { + /** The name of the operation, as per Resource-Based Access Control (RBAC). Examples: "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action" */ + readonly name?: string; + /** Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for Azure Resource Manager/control-plane operations. */ + readonly isDataAction?: boolean; + /** Localized display information for this particular operation. */ + readonly display?: OperationDisplayOutput; + /** + * The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system" + * + * Possible values: "user", "system", "user,system" + */ + readonly origin?: OriginOutput; + /** + * Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + * + * Possible values: "Internal" + */ + actionType?: ActionTypeOutput; +} + +/** Localized display information for and operation. */ +export interface OperationDisplayOutput { + /** The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring Insights" or "Microsoft Compute". */ + readonly provider?: string; + /** The localized friendly name of the resource type related to this operation. E.g. "Virtual Machines" or "Job Schedule Collections". */ + readonly resource?: string; + /** The concise, localized friendly name for the operation; suitable for dropdowns. E.g. "Create or Update Virtual Machine", "Restart Virtual Machine". */ + readonly operation?: string; + /** The short, localized friendly description of the operation; suitable for tool tips and detailed views. */ + readonly description?: string; +} + +/** Common error response for all Azure Resource Manager APIs to return error details for failed operations. */ +export interface ErrorResponseOutput { + /** The error object. */ + error?: ErrorDetailOutput; +} + +/** The error detail. */ +export interface ErrorDetailOutput { + /** The error code. */ + readonly code?: string; + /** The error message. */ + readonly message?: string; + /** The error target. */ + readonly target?: string; + /** The error details. */ + readonly details?: Array; + /** The error additional info. */ + readonly additionalInfo?: Array; +} + +/** The resource management error additional info. */ +export interface ErrorAdditionalInfoOutput { + /** The additional info type. */ + readonly type?: string; + /** The additional info. */ + readonly info?: Record; +} + +/** Represents a mongo cluster resource. */ +export interface MongoClusterOutput extends TrackedResourceOutput { + /** The resource-specific properties for this resource. */ + properties?: MongoClusterPropertiesOutput; +} + +/** The properties of a mongo cluster. */ +export interface MongoClusterPropertiesOutput { + /** + * The mode to create a mongo cluster. + * + * Possible values: "Default", "PointInTimeRestore", "GeoReplica", "Replica" + */ + createMode?: CreateModeOutput; + /** The parameters to create a point-in-time restore mongo cluster. */ + restoreParameters?: MongoClusterRestoreParametersOutput; + /** The parameters to create a replica mongo cluster. */ + replicaParameters?: MongoClusterReplicaParametersOutput; + /** The administrator's login for the mongo cluster. */ + administratorLogin?: string; + /** The password of the administrator login. */ + administratorLoginPassword?: string; + /** The Mongo DB server version. Defaults to the latest available version if not specified. */ + serverVersion?: string; + /** The default mongo connection string for the cluster. */ + readonly connectionString?: string; + /** Earliest restore timestamp in UTC ISO8601 format. */ + readonly earliestRestoreTime?: string; + /** + * The provisioning state of the mongo cluster. + * + * Possible values: "InProgress", "Updating", "Dropping" + */ + readonly provisioningState?: ProvisioningStateOutput; + /** + * The status of the mongo cluster. + * + * Possible values: "Ready", "Provisioning", "Updating", "Starting", "Stopping", "Stopped", "Dropping" + */ + readonly clusterStatus?: MongoClusterStatusOutput; + /** + * Whether or not public endpoint access is allowed for this mongo cluster. + * + * Possible values: "Enabled", "Disabled" + */ + publicNetworkAccess?: PublicNetworkAccessOutput; + /** The list of node group specs in the cluster. */ + nodeGroupSpecs?: Array; + /** List of private endpoint connections. */ + readonly privateEndpointConnections?: Array; + /** List of private endpoint connections. */ + previewFeatures?: PreviewFeatureOutput[]; + /** The replication properties for the mongo cluster */ + readonly replica?: ReplicationPropertiesOutput; + /** The infrastructure version the cluster is provisioned on. */ + readonly infrastructureVersion?: string; +} + +/** Parameters used for restore operations */ +export interface MongoClusterRestoreParametersOutput { + /** UTC point in time to restore a mongo cluster */ + pointInTimeUTC?: string; + /** Resource ID to locate the source cluster to restore */ + sourceResourceId?: string; +} + +/** Parameters used for replica operations. */ +export interface MongoClusterReplicaParametersOutput { + /** The id of the replication source cluster. */ + sourceResourceId: string; + /** The location of the source cluster */ + sourceLocation: string; +} + +/** Specification for a node group. */ +export interface NodeGroupSpecOutput { + /** The resource sku for the node group. This defines the size of CPU and memory that is provisioned for each node. Example values: 'M30', 'M40'. */ + sku?: string; + /** The disk storage size for the node group in GB. Example values: 128, 256, 512, 1024. */ + diskSizeGB?: number; + /** Whether high availability is enabled on the node group. */ + enableHa?: boolean; + /** + * The node type deployed in the node group. + * + * Possible values: "Shard" + */ + kind?: NodeKindOutput; + /** The number of nodes in the node group. */ + nodeCount?: number; +} + +/** The private endpoint connection resource */ +export interface PrivateEndpointConnectionOutput extends ResourceOutput { + /** The private endpoint connection properties */ + properties?: PrivateEndpointConnectionPropertiesOutput; +} + +/** Properties of the private endpoint connection. */ +export interface PrivateEndpointConnectionPropertiesOutput { + /** The group ids for the private endpoint resource. */ + readonly groupIds?: string[]; + /** The private endpoint resource. */ + privateEndpoint?: PrivateEndpointOutput; + /** A collection of information about the state of the connection between service consumer and provider. */ + privateLinkServiceConnectionState: PrivateLinkServiceConnectionStateOutput; + /** + * The provisioning state of the private endpoint connection resource. + * + * Possible values: "Succeeded", "Creating", "Deleting", "Failed" + */ + readonly provisioningState?: PrivateEndpointConnectionProvisioningStateOutput; +} + +/** The Private Endpoint resource. */ +export interface PrivateEndpointOutput { + /** The resource identifier for private endpoint */ + readonly id?: string; +} + +/** A collection of information about the state of the connection between service consumer and provider. */ +export interface PrivateLinkServiceConnectionStateOutput { + /** + * Indicates whether the connection has been Approved/Rejected/Removed by the owner of the service. + * + * Possible values: "Pending", "Approved", "Rejected" + */ + status?: PrivateEndpointServiceConnectionStatusOutput; + /** The reason for approval/rejection of the connection. */ + description?: string; + /** A message indicating if changes on the service provider require any updates on the consumer. */ + actionsRequired?: string; +} + +/** Common fields that are returned in the response for all Azure Resource Manager resources */ +export interface ResourceOutput { + /** Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} */ + readonly id?: string; + /** The name of the resource */ + readonly name?: string; + /** The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" */ + readonly type?: string; + /** Azure Resource Manager metadata containing createdBy and modifiedBy information. */ + readonly systemData?: SystemDataOutput; +} + +/** Metadata pertaining to creation and last modification of the resource. */ +export interface SystemDataOutput { + /** The identity that created the resource. */ + createdBy?: string; + /** + * The type of identity that created the resource. + * + * Possible values: "User", "Application", "ManagedIdentity", "Key" + */ + createdByType?: CreatedByTypeOutput; + /** The timestamp of resource creation (UTC). */ + createdAt?: string; + /** The identity that last modified the resource. */ + lastModifiedBy?: string; + /** + * The type of identity that last modified the resource. + * + * Possible values: "User", "Application", "ManagedIdentity", "Key" + */ + lastModifiedByType?: CreatedByTypeOutput; + /** The timestamp of resource last modification (UTC) */ + lastModifiedAt?: string; +} + +/** The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location' */ +export interface TrackedResourceOutput extends ResourceOutput { + /** Resource tags. */ + tags?: Record; + /** The geo-location where the resource lives */ + location: string; +} + +/** The resource model definition containing the full set of allowed properties for a resource. Except properties bag, there cannot be a top level property outside of this set. */ +export interface ResourceModelWithAllowedPropertySetOutput + extends TrackedResourceOutput { + /** + * The fully qualified resource ID of the resource that manages this resource. Indicates if this resource is managed by another Azure resource. + * If this is present, complete mode deployment will not delete the resource if it is removed from the template since it is managed by another resource. + */ + managedBy?: string; + /** + * Metadata used by portal/tooling/etc to render different UX experiences for resources of the same type; e.g. ApiApps are a kind of Microsoft.Web/sites type. + * If supported, the resource provider must validate and persist this value. + */ + kind?: string; + /** + * The etag field is *not* required. If it is provided in the response body, it must also be provided as a header per the normal etag convention. + * Entity tags are used for comparing two or more entities from the same requested resource. HTTP/1.1 uses entity tags in the etag (section 14.19), + * If-Match (section 14.24), If-None-Match (section 14.26), and If-Range (section 14.27) header fields. + */ + eTag?: string; + identity?: IdentityOutput; + sku?: SkuOutput; + plan?: PlanOutput; +} + +/** Identity for the resource. */ +export interface IdentityOutput { + /** The principal ID of resource identity. The value must be an UUID. */ + readonly principalId?: string; + /** The tenant ID of resource. The value must be an UUID. */ + readonly tenantId?: string; + /** The identity type. */ + type?: ResourceIdentityTypeOutput; +} + +/** The resource model definition representing SKU */ +export interface SkuOutput { + /** The name of the SKU. Ex - P3. It is typically a letter+number code */ + name: string; + /** This field is required to be implemented by the Resource Provider if the service has more than one tier, but is not required on a PUT. */ + tier?: SkuTierOutput; + /** The SKU size. When the name field is the combination of tier and some other value, this would be the standalone code. */ + size?: string; + /** If the service has different generations of hardware, for the same SKU, then that can be captured here. */ + family?: string; + /** If the SKU supports scale out/in then the capacity integer should be included. If scale out/in is not possible for the resource this may be omitted. */ + capacity?: number; +} + +/** Plan for the resource. */ +export interface PlanOutput { + /** A user defined name of the 3rd Party Artifact that is being procured. */ + name: string; + /** The publisher of the 3rd Party Artifact that is being bought. E.g. NewRelic */ + publisher: string; + /** The 3rd Party artifact that is being procured. E.g. NewRelic. Product maps to the OfferID specified for the artifact at the time of Data Market onboarding. */ + product: string; + /** A publisher provided promotion code as provisioned in Data Market for the said product/artifact. */ + promotionCode?: string; + /** The version of the desired product/artifact. */ + version?: string; +} + +/** The resource model definition for a Azure Resource Manager proxy resource. It will not have tags and a location */ +export interface ProxyResourceOutput extends ResourceOutput {} + +/** Represents a mongo cluster firewall rule. */ +export interface FirewallRuleOutput extends ProxyResourceOutput { + /** The resource-specific properties for this resource. */ + properties?: FirewallRulePropertiesOutput; +} + +/** The properties of a mongo cluster firewall rule. */ +export interface FirewallRulePropertiesOutput { + /** + * The provisioning state of the firewall rule. + * + * Possible values: "InProgress", "Updating", "Dropping" + */ + readonly provisioningState?: ProvisioningStateOutput; + /** The start IP address of the mongo cluster firewall rule. Must be IPv4 format. */ + startIpAddress: string; + /** The end IP address of the mongo cluster firewall rule. Must be IPv4 format. */ + endIpAddress: string; +} + +/** Concrete proxy resource types can be created by aliasing this type using a specific property type. */ +export interface PrivateEndpointConnectionResourceOutput + extends ProxyResourceOutput { + /** The resource-specific properties for this resource. */ + properties?: PrivateEndpointConnectionPropertiesOutput; +} + +/** Concrete proxy resource types can be created by aliasing this type using a specific property type. */ +export interface PrivateLinkResourceOutput extends ProxyResourceOutput { + /** The resource-specific properties for this resource. */ + properties?: PrivateLinkResourcePropertiesOutput; +} + +/** Properties of a private link resource. */ +export interface PrivateLinkResourcePropertiesOutput { + /** The private link resource group id. */ + readonly groupId?: string; + /** The private link resource required member names. */ + readonly requiredMembers?: string[]; + /** The private link resource private link DNS zone name. */ + requiredZoneNames?: string[]; +} + +/** Represents a mongo cluster replica. */ +export interface ReplicaOutput extends ProxyResourceOutput { + /** The resource-specific properties for this resource. */ + properties?: MongoClusterPropertiesOutput; +} + +/** The base extension resource. */ +export interface ExtensionResourceOutput extends ResourceOutput {} + +/** The resource model definition for an Azure Resource Manager resource with an etag. */ +export interface AzureEntityResourceOutput extends ResourceOutput { + /** Resource Etag. */ + readonly etag?: string; +} + +/** A private link resource. */ +export interface PrivateLinkResourceOutput extends ResourceOutput { + /** Resource properties. */ + properties?: PrivateLinkResourcePropertiesOutput; +} + +/** Replica properties of the mongo cluster. */ +export interface ReplicationPropertiesOutput { + /** The resource id the source cluster for the replica cluster. */ + readonly sourceResourceId?: string; + /** + * The replication role of the cluster + * + * Possible values: "Primary", "AsyncReplica", "GeoAsyncReplica" + */ + readonly role?: ReplicationRoleOutput; + /** + * The replication link state of the replica cluster. + * + * Possible values: "Active", "Catchup", "Provisioning", "Updating", "Broken", "Reconfiguring" + */ + readonly replicationState?: ReplicationStateOutput; +} + +/** The connection strings for the given mongo cluster. */ +export interface ListConnectionStringsResultOutput { + /** An array that contains the connection strings for a mongo cluster. */ + readonly connectionStrings?: Array; +} + +/** Connection string for the mongo cluster */ +export interface ConnectionStringOutput { + /** Value of the connection string */ + readonly connectionString?: string; + /** Description of the connection string */ + readonly description?: string; +} + +/** The check availability result. */ +export interface CheckNameAvailabilityResponseOutput { + /** Indicates if the resource name is available. */ + nameAvailable?: boolean; + /** + * The reason why the given name is not available. + * + * Possible values: "Invalid", "AlreadyExists" + */ + reason?: CheckNameAvailabilityReasonOutput; + /** Detailed reason why the given name is not available. */ + message?: string; +} + +/** A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of results. */ +export type OperationListResultOutput = Paged; +/** Alias for OriginOutput */ +export type OriginOutput = string; +/** Alias for ActionTypeOutput */ +export type ActionTypeOutput = string; +/** Alias for CreateModeOutput */ +export type CreateModeOutput = string; +/** Alias for ResourceProvisioningStateOutput */ +export type ResourceProvisioningStateOutput = string; +/** Alias for ProvisioningStateOutput */ +export type ProvisioningStateOutput = string; +/** Alias for MongoClusterStatusOutput */ +export type MongoClusterStatusOutput = string; +/** Alias for PublicNetworkAccessOutput */ +export type PublicNetworkAccessOutput = string; +/** Alias for NodeKindOutput */ +export type NodeKindOutput = string; +/** Alias for PrivateEndpointServiceConnectionStatusOutput */ +export type PrivateEndpointServiceConnectionStatusOutput = string; +/** Alias for PrivateEndpointConnectionProvisioningStateOutput */ +export type PrivateEndpointConnectionProvisioningStateOutput = string; +/** Alias for CreatedByTypeOutput */ +export type CreatedByTypeOutput = string; +/** Alias for ResourceIdentityTypeOutput */ +export type ResourceIdentityTypeOutput = "SystemAssigned"; +/** Alias for SkuTierOutput */ +export type SkuTierOutput = "Free" | "Basic" | "Standard" | "Premium"; +/** Alias for PreviewFeatureOutput */ +export type PreviewFeatureOutput = string; +/** Alias for ReplicationRoleOutput */ +export type ReplicationRoleOutput = string; +/** Alias for ReplicationStateOutput */ +export type ReplicationStateOutput = string; +/** The response of a MongoCluster list operation. */ +export type MongoClusterListResultOutput = Paged; +/** Alias for CheckNameAvailabilityReasonOutput */ +export type CheckNameAvailabilityReasonOutput = string; +/** The response of a FirewallRule list operation. */ +export type FirewallRuleListResultOutput = Paged; +/** The response of a PrivateEndpointConnectionResource list operation. */ +export type PrivateEndpointConnectionResourceListResultOutput = + Paged; +/** The response of a PrivateLinkResource list operation. */ +export type PrivateLinkResourceListResultOutput = + Paged; +/** The response of a Replica list operation. */ +export type ReplicaListResultOutput = Paged; diff --git a/sdk/mongocluster/arm-mongoclustertest/src/rest/paginateHelper.ts b/sdk/mongocluster/arm-mongoclustertest/src/rest/paginateHelper.ts new file mode 100644 index 000000000000..3aac141db0e7 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/rest/paginateHelper.ts @@ -0,0 +1,154 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { + getPagedAsyncIterator, + PagedAsyncIterableIterator, + PagedResult, +} from "@azure/core-paging"; +import { + Client, + createRestError, + PathUncheckedResponse, +} from "@azure-rest/core-client"; + +/** + * Helper type to extract the type of an array + */ +export type GetArrayType = T extends Array ? TData : never; + +/** + * The type of a custom function that defines how to get a page and a link to the next one if any. + */ +export type GetPage = ( + pageLink: string, + maxPageSize?: number, +) => Promise<{ + page: TPage; + nextPageLink?: string; +}>; + +/** + * Options for the paging helper + */ +export interface PagingOptions { + /** + * Custom function to extract pagination details for crating the PagedAsyncIterableIterator + */ + customGetPage?: GetPage[]>; +} + +/** + * Helper type to infer the Type of the paged elements from the response type + * This type is generated based on the swagger information for x-ms-pageable + * specifically on the itemName property which indicates the property of the response + * where the page items are found. The default value is `value`. + * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter + */ +export type PaginateReturn = TResult extends { + body: { value?: infer TPage }; +} + ? GetArrayType + : Array; + +/** + * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension + * @param client - Client to use for sending the next page requests + * @param initialResponse - Initial response containing the nextLink and current page of elements + * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results + * @returns - PagedAsyncIterableIterator to iterate the elements + */ +export function paginate( + client: Client, + initialResponse: TResponse, + options: PagingOptions = {}, +): PagedAsyncIterableIterator> { + // Extract element type from initial response + type TElement = PaginateReturn; + let firstRun = true; + const itemName = "value"; + const nextLinkName = "nextLink"; + const { customGetPage } = options; + const pagedResult: PagedResult = { + firstPageLink: "", + getPage: + typeof customGetPage === "function" + ? customGetPage + : async (pageLink: string) => { + const result = firstRun + ? initialResponse + : await client.pathUnchecked(pageLink).get(); + firstRun = false; + checkPagingRequest(result); + const nextLink = getNextLink(result.body, nextLinkName); + const values = getElements(result.body, itemName); + return { + page: values, + nextPageLink: nextLink, + }; + }, + }; + + return getPagedAsyncIterator(pagedResult); +} + +/** + * Gets for the value of nextLink in the body + */ +function getNextLink(body: unknown, nextLinkName?: string): string | undefined { + if (!nextLinkName) { + return undefined; + } + + const nextLink = (body as Record)[nextLinkName]; + + if (typeof nextLink !== "string" && typeof nextLink !== "undefined") { + throw new Error( + `Body Property ${nextLinkName} should be a string or undefined`, + ); + } + + return nextLink; +} + +/** + * Gets the elements of the current request in the body. + */ +function getElements(body: unknown, itemName: string): T[] { + const value = (body as Record)[itemName] as T[]; + + // value has to be an array according to the x-ms-pageable extension. + // The fact that this must be an array is used above to calculate the + // type of elements in the page in PaginateReturn + if (!Array.isArray(value)) { + throw new Error( + `Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}`, + ); + } + + return value ?? []; +} + +/** + * Checks if a request failed + */ +function checkPagingRequest(response: PathUncheckedResponse): void { + const Http2xxStatusCodes = [ + "200", + "201", + "202", + "203", + "204", + "205", + "206", + "207", + "208", + "226", + ]; + if (!Http2xxStatusCodes.includes(response.status)) { + throw createRestError( + `Pagination failed with unexpected statusCode ${response.status}`, + response, + ); + } +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/rest/parameters.ts b/sdk/mongocluster/arm-mongoclustertest/src/rest/parameters.ts new file mode 100644 index 000000000000..5d051a1e7db9 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/rest/parameters.ts @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { RequestParameters } from "@azure-rest/core-client"; +import { + MongoCluster, + MongoClusterUpdate, + CheckNameAvailabilityRequest, + PromoteReplicaRequest, + FirewallRule, + PrivateEndpointConnectionResource, +} from "./models.js"; + +export type OperationsListParameters = RequestParameters; +export type MongoClustersGetParameters = RequestParameters; + +export interface MongoClustersCreateOrUpdateBodyParam { + /** Resource create parameters. */ + body: MongoCluster; +} + +export type MongoClustersCreateOrUpdateParameters = + MongoClustersCreateOrUpdateBodyParam & RequestParameters; + +export interface MongoClustersUpdateBodyParam { + /** The resource properties to be updated. */ + body: MongoClusterUpdate; +} + +export type MongoClustersUpdateParameters = MongoClustersUpdateBodyParam & + RequestParameters; +export type MongoClustersDeleteParameters = RequestParameters; +export type MongoClustersListByResourceGroupParameters = RequestParameters; +export type MongoClustersListParameters = RequestParameters; +export type MongoClustersListConnectionStringsParameters = RequestParameters; + +export interface MongoClustersCheckNameAvailabilityBodyParam { + /** The CheckAvailability request */ + body: CheckNameAvailabilityRequest; +} + +export type MongoClustersCheckNameAvailabilityParameters = + MongoClustersCheckNameAvailabilityBodyParam & RequestParameters; + +export interface MongoClustersPromoteBodyParam { + /** The content of the action request */ + body: PromoteReplicaRequest; +} + +export type MongoClustersPromoteParameters = MongoClustersPromoteBodyParam & + RequestParameters; +export type FirewallRulesGetParameters = RequestParameters; + +export interface FirewallRulesCreateOrUpdateBodyParam { + /** Resource create parameters. */ + body: FirewallRule; +} + +export type FirewallRulesCreateOrUpdateParameters = + FirewallRulesCreateOrUpdateBodyParam & RequestParameters; +export type FirewallRulesDeleteParameters = RequestParameters; +export type FirewallRulesListByMongoClusterParameters = RequestParameters; +export type PrivateEndpointConnectionsListByMongoClusterParameters = + RequestParameters; +export type PrivateEndpointConnectionsGetParameters = RequestParameters; + +export interface PrivateEndpointConnectionsCreateBodyParam { + /** Resource create parameters. */ + body: PrivateEndpointConnectionResource; +} + +export type PrivateEndpointConnectionsCreateParameters = + PrivateEndpointConnectionsCreateBodyParam & RequestParameters; +export type PrivateEndpointConnectionsDeleteParameters = RequestParameters; +export type PrivateLinksListByMongoClusterParameters = RequestParameters; +export type ReplicasListByParentParameters = RequestParameters; diff --git a/sdk/mongocluster/arm-mongoclustertest/src/rest/pollingHelper.ts b/sdk/mongocluster/arm-mongoclustertest/src/rest/pollingHelper.ts new file mode 100644 index 000000000000..265dea155b05 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/rest/pollingHelper.ts @@ -0,0 +1,337 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { Client, HttpResponse } from "@azure-rest/core-client"; +import { AbortSignalLike } from "@azure/abort-controller"; +import { + CancelOnProgress, + CreateHttpPollerOptions, + RunningOperation, + OperationResponse, + OperationState, + createHttpPoller, +} from "@azure/core-lro"; +import { + MongoClustersCreateOrUpdate200Response, + MongoClustersCreateOrUpdate201Response, + MongoClustersCreateOrUpdateDefaultResponse, + MongoClustersCreateOrUpdateLogicalResponse, + MongoClustersUpdate200Response, + MongoClustersUpdate202Response, + MongoClustersUpdateDefaultResponse, + MongoClustersUpdateLogicalResponse, + MongoClustersDelete202Response, + MongoClustersDelete204Response, + MongoClustersDeleteDefaultResponse, + MongoClustersDeleteLogicalResponse, + MongoClustersPromote202Response, + MongoClustersPromoteDefaultResponse, + MongoClustersPromoteLogicalResponse, + FirewallRulesCreateOrUpdate200Response, + FirewallRulesCreateOrUpdate201Response, + FirewallRulesCreateOrUpdate202Response, + FirewallRulesCreateOrUpdateDefaultResponse, + FirewallRulesCreateOrUpdateLogicalResponse, + FirewallRulesDelete202Response, + FirewallRulesDelete204Response, + FirewallRulesDeleteDefaultResponse, + FirewallRulesDeleteLogicalResponse, + PrivateEndpointConnectionsCreate200Response, + PrivateEndpointConnectionsCreate201Response, + PrivateEndpointConnectionsCreate202Response, + PrivateEndpointConnectionsCreateDefaultResponse, + PrivateEndpointConnectionsCreateLogicalResponse, + PrivateEndpointConnectionsDelete202Response, + PrivateEndpointConnectionsDelete204Response, + PrivateEndpointConnectionsDeleteDefaultResponse, + PrivateEndpointConnectionsDeleteLogicalResponse, +} from "./responses.js"; + +/** + * A simple poller that can be used to poll a long running operation. + */ +export interface SimplePollerLike< + TState extends OperationState, + TResult, +> { + /** + * Returns true if the poller has finished polling. + */ + isDone(): boolean; + /** + * Returns the state of the operation. + */ + getOperationState(): TState; + /** + * Returns the result value of the operation, + * regardless of the state of the poller. + * It can return undefined or an incomplete form of the final TResult value + * depending on the implementation. + */ + getResult(): TResult | undefined; + /** + * Returns a promise that will resolve once a single polling request finishes. + * It does this by calling the update method of the Poller's operation. + */ + poll(options?: { abortSignal?: AbortSignalLike }): Promise; + /** + * Returns a promise that will resolve once the underlying operation is completed. + */ + pollUntilDone(pollOptions?: { + abortSignal?: AbortSignalLike; + }): Promise; + /** + * Invokes the provided callback after each polling is completed, + * sending the current state of the poller's operation. + * + * It returns a method that can be used to stop receiving updates on the given callback function. + */ + onProgress(callback: (state: TState) => void): CancelOnProgress; + + /** + * Returns a promise that could be used for serialized version of the poller's operation + * by invoking the operation's serialize method. + */ + serialize(): Promise; + + /** + * Wait the poller to be submitted. + */ + submitted(): Promise; + + /** + * Returns a string representation of the poller's operation. Similar to serialize but returns a string. + * @deprecated Use serialize() instead. + */ + toString(): string; + + /** + * Stops the poller from continuing to poll. Please note this will only stop the client-side polling + * @deprecated Use abortSignal to stop polling instead. + */ + stopPolling(): void; + + /** + * Returns true if the poller is stopped. + * @deprecated Use abortSignal status to track this instead. + */ + isStopped(): boolean; +} + +/** + * Helper function that builds a Poller object to help polling a long running operation. + * @param client - Client to use for sending the request to get additional pages. + * @param initialResponse - The initial response. + * @param options - Options to set a resume state or custom polling interval. + * @returns - A poller object to poll for operation state updates and eventually get the final response. + */ +export async function getLongRunningPoller< + TResult extends + | MongoClustersCreateOrUpdateLogicalResponse + | MongoClustersCreateOrUpdateDefaultResponse, +>( + client: Client, + initialResponse: + | MongoClustersCreateOrUpdate200Response + | MongoClustersCreateOrUpdate201Response + | MongoClustersCreateOrUpdateDefaultResponse, + options?: CreateHttpPollerOptions>, +): Promise, TResult>>; +export async function getLongRunningPoller< + TResult extends + | MongoClustersUpdateLogicalResponse + | MongoClustersUpdateDefaultResponse, +>( + client: Client, + initialResponse: + | MongoClustersUpdate200Response + | MongoClustersUpdate202Response + | MongoClustersUpdateDefaultResponse, + options?: CreateHttpPollerOptions>, +): Promise, TResult>>; +export async function getLongRunningPoller< + TResult extends + | MongoClustersDeleteLogicalResponse + | MongoClustersDeleteDefaultResponse, +>( + client: Client, + initialResponse: + | MongoClustersDelete202Response + | MongoClustersDelete204Response + | MongoClustersDeleteDefaultResponse, + options?: CreateHttpPollerOptions>, +): Promise, TResult>>; +export async function getLongRunningPoller< + TResult extends + | MongoClustersPromoteLogicalResponse + | MongoClustersPromoteDefaultResponse, +>( + client: Client, + initialResponse: + | MongoClustersPromote202Response + | MongoClustersPromoteDefaultResponse, + options?: CreateHttpPollerOptions>, +): Promise, TResult>>; +export async function getLongRunningPoller< + TResult extends + | FirewallRulesCreateOrUpdateLogicalResponse + | FirewallRulesCreateOrUpdateDefaultResponse, +>( + client: Client, + initialResponse: + | FirewallRulesCreateOrUpdate200Response + | FirewallRulesCreateOrUpdate201Response + | FirewallRulesCreateOrUpdate202Response + | FirewallRulesCreateOrUpdateDefaultResponse, + options?: CreateHttpPollerOptions>, +): Promise, TResult>>; +export async function getLongRunningPoller< + TResult extends + | FirewallRulesDeleteLogicalResponse + | FirewallRulesDeleteDefaultResponse, +>( + client: Client, + initialResponse: + | FirewallRulesDelete202Response + | FirewallRulesDelete204Response + | FirewallRulesDeleteDefaultResponse, + options?: CreateHttpPollerOptions>, +): Promise, TResult>>; +export async function getLongRunningPoller< + TResult extends + | PrivateEndpointConnectionsCreateLogicalResponse + | PrivateEndpointConnectionsCreateDefaultResponse, +>( + client: Client, + initialResponse: + | PrivateEndpointConnectionsCreate200Response + | PrivateEndpointConnectionsCreate201Response + | PrivateEndpointConnectionsCreate202Response + | PrivateEndpointConnectionsCreateDefaultResponse, + options?: CreateHttpPollerOptions>, +): Promise, TResult>>; +export async function getLongRunningPoller< + TResult extends + | PrivateEndpointConnectionsDeleteLogicalResponse + | PrivateEndpointConnectionsDeleteDefaultResponse, +>( + client: Client, + initialResponse: + | PrivateEndpointConnectionsDelete202Response + | PrivateEndpointConnectionsDelete204Response + | PrivateEndpointConnectionsDeleteDefaultResponse, + options?: CreateHttpPollerOptions>, +): Promise, TResult>>; +export async function getLongRunningPoller( + client: Client, + initialResponse: TResult, + options: CreateHttpPollerOptions> = {}, +): Promise, TResult>> { + const abortController = new AbortController(); + const poller: RunningOperation = { + sendInitialRequest: async () => { + // In the case of Rest Clients we are building the LRO poller object from a response that's the reason + // we are not triggering the initial request here, just extracting the information from the + // response we were provided. + return getLroResponse(initialResponse); + }, + sendPollRequest: async ( + path: string, + pollOptions?: { abortSignal?: AbortSignalLike }, + ) => { + // This is the callback that is going to be called to poll the service + // to get the latest status. We use the client provided and the polling path + // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location + // depending on the lro pattern that the service implements. If non is provided we default to the initial path. + function abortListener(): void { + abortController.abort(); + } + const inputAbortSignal = pollOptions?.abortSignal; + const abortSignal = abortController.signal; + if (inputAbortSignal?.aborted) { + abortController.abort(); + } else if (!abortSignal.aborted) { + inputAbortSignal?.addEventListener("abort", abortListener, { + once: true, + }); + } + let response; + try { + response = await client + .pathUnchecked(path ?? initialResponse.request.url) + .get({ abortSignal }); + } finally { + inputAbortSignal?.removeEventListener("abort", abortListener); + } + const lroResponse = getLroResponse(response as TResult); + lroResponse.rawResponse.headers["x-ms-original-url"] = + initialResponse.request.url; + return lroResponse; + }, + }; + + options.resolveOnUnsuccessful = options.resolveOnUnsuccessful ?? true; + const httpPoller = createHttpPoller(poller, options); + const simplePoller: SimplePollerLike, TResult> = { + isDone() { + return httpPoller.isDone; + }, + isStopped() { + return abortController.signal.aborted; + }, + getOperationState() { + if (!httpPoller.operationState) { + throw new Error( + "Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().", + ); + } + return httpPoller.operationState; + }, + getResult() { + return httpPoller.result; + }, + toString() { + if (!httpPoller.operationState) { + throw new Error( + "Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().", + ); + } + return JSON.stringify({ + state: httpPoller.operationState, + }); + }, + stopPolling() { + abortController.abort(); + }, + onProgress: httpPoller.onProgress, + poll: httpPoller.poll, + pollUntilDone: httpPoller.pollUntilDone, + serialize: httpPoller.serialize, + submitted: httpPoller.submitted, + }; + return simplePoller; +} + +/** + * Converts a Rest Client response to a response that the LRO implementation understands + * @param response - a rest client http response + * @returns - An LRO response that the LRO implementation understands + */ +function getLroResponse( + response: TResult, +): OperationResponse { + if (Number.isNaN(response.status)) { + throw new TypeError( + `Status code of the response is not a number. Value: ${response.status}`, + ); + } + + return { + flatResponse: response, + rawResponse: { + ...response, + statusCode: Number.parseInt(response.status), + body: response.body, + }, + }; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/rest/responses.ts b/sdk/mongocluster/arm-mongoclustertest/src/rest/responses.ts new file mode 100644 index 000000000000..9f7e371139a0 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/rest/responses.ts @@ -0,0 +1,415 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { RawHttpHeaders } from "@azure/core-rest-pipeline"; +import { HttpResponse } from "@azure-rest/core-client"; +import { + OperationListResultOutput, + ErrorResponseOutput, + MongoClusterOutput, + MongoClusterListResultOutput, + ListConnectionStringsResultOutput, + CheckNameAvailabilityResponseOutput, + FirewallRuleOutput, + FirewallRuleListResultOutput, + PrivateEndpointConnectionResourceListResultOutput, + PrivateEndpointConnectionResourceOutput, + PrivateLinkResourceListResultOutput, + ReplicaListResultOutput, +} from "./outputModels.js"; + +/** Azure operation completed successfully. */ +export interface OperationsList200Response extends HttpResponse { + status: "200"; + body: OperationListResultOutput; +} + +export interface OperationsListDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** Azure operation completed successfully. */ +export interface MongoClustersGet200Response extends HttpResponse { + status: "200"; + body: MongoClusterOutput; +} + +export interface MongoClustersGetDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** Resource 'MongoCluster' update operation succeeded */ +export interface MongoClustersCreateOrUpdate200Response extends HttpResponse { + status: "200"; + body: MongoClusterOutput; +} + +export interface MongoClustersCreateOrUpdate201Headers { + /** The Retry-After header can indicate how long the client should wait before polling the operation status. */ + "retry-after"?: number; +} + +/** Resource 'MongoCluster' create operation succeeded */ +export interface MongoClustersCreateOrUpdate201Response extends HttpResponse { + status: "201"; + body: MongoClusterOutput; + headers: RawHttpHeaders & MongoClustersCreateOrUpdate201Headers; +} + +export interface MongoClustersCreateOrUpdateDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The final response for long-running createOrUpdate operation */ +export interface MongoClustersCreateOrUpdateLogicalResponse + extends HttpResponse { + status: "200"; + body: MongoClusterOutput; +} + +/** Azure operation completed successfully. */ +export interface MongoClustersUpdate200Response extends HttpResponse { + status: "200"; + body: MongoClusterOutput; +} + +export interface MongoClustersUpdate202Headers { + /** The Location header contains the URL where the status of the long running operation can be checked. */ + location?: string; + /** The Retry-After header can indicate how long the client should wait before polling the operation status. */ + "retry-after"?: number; +} + +/** Resource update request accepted. */ +export interface MongoClustersUpdate202Response extends HttpResponse { + status: "202"; + headers: RawHttpHeaders & MongoClustersUpdate202Headers; +} + +export interface MongoClustersUpdateDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The final response for long-running update operation */ +export interface MongoClustersUpdateLogicalResponse extends HttpResponse { + status: "200"; + body: MongoClusterOutput; +} + +export interface MongoClustersDelete202Headers { + /** The Location header contains the URL where the status of the long running operation can be checked. */ + location?: string; + /** The Retry-After header can indicate how long the client should wait before polling the operation status. */ + "retry-after"?: number; +} + +/** Resource deletion accepted. */ +export interface MongoClustersDelete202Response extends HttpResponse { + status: "202"; + headers: RawHttpHeaders & MongoClustersDelete202Headers; +} + +/** Resource does not exist. */ +export interface MongoClustersDelete204Response extends HttpResponse { + status: "204"; +} + +export interface MongoClustersDeleteDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The final response for long-running delete operation */ +export interface MongoClustersDeleteLogicalResponse extends HttpResponse { + status: "200"; +} + +/** Azure operation completed successfully. */ +export interface MongoClustersListByResourceGroup200Response + extends HttpResponse { + status: "200"; + body: MongoClusterListResultOutput; +} + +export interface MongoClustersListByResourceGroupDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** Azure operation completed successfully. */ +export interface MongoClustersList200Response extends HttpResponse { + status: "200"; + body: MongoClusterListResultOutput; +} + +export interface MongoClustersListDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** Azure operation completed successfully. */ +export interface MongoClustersListConnectionStrings200Response + extends HttpResponse { + status: "200"; + body: ListConnectionStringsResultOutput; +} + +export interface MongoClustersListConnectionStringsDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The request has succeeded. */ +export interface MongoClustersCheckNameAvailability200Response + extends HttpResponse { + status: "200"; + body: CheckNameAvailabilityResponseOutput; +} + +export interface MongoClustersCheckNameAvailabilityDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +export interface MongoClustersPromote202Headers { + /** The Location header contains the URL where the status of the long running operation can be checked. */ + location?: string; + /** The Retry-After header can indicate how long the client should wait before polling the operation status. */ + "retry-after"?: number; +} + +/** Resource operation accepted. */ +export interface MongoClustersPromote202Response extends HttpResponse { + status: "202"; + headers: RawHttpHeaders & MongoClustersPromote202Headers; +} + +export interface MongoClustersPromoteDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The final response for long-running promote operation */ +export interface MongoClustersPromoteLogicalResponse extends HttpResponse { + status: "200"; +} + +/** Azure operation completed successfully. */ +export interface FirewallRulesGet200Response extends HttpResponse { + status: "200"; + body: FirewallRuleOutput; +} + +export interface FirewallRulesGetDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** Resource 'FirewallRule' update operation succeeded */ +export interface FirewallRulesCreateOrUpdate200Response extends HttpResponse { + status: "200"; + body: FirewallRuleOutput; +} + +/** Resource 'FirewallRule' create operation succeeded */ +export interface FirewallRulesCreateOrUpdate201Response extends HttpResponse { + status: "201"; + body: FirewallRuleOutput; +} + +export interface FirewallRulesCreateOrUpdate202Headers { + /** The Location header contains the URL where the status of the long running operation can be checked. */ + location?: string; + /** The Retry-After header can indicate how long the client should wait before polling the operation status. */ + "retry-after"?: number; +} + +/** Resource operation accepted. */ +export interface FirewallRulesCreateOrUpdate202Response extends HttpResponse { + status: "202"; + headers: RawHttpHeaders & FirewallRulesCreateOrUpdate202Headers; +} + +export interface FirewallRulesCreateOrUpdateDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The final response for long-running createOrUpdate operation */ +export interface FirewallRulesCreateOrUpdateLogicalResponse + extends HttpResponse { + status: "200"; + body: FirewallRuleOutput; +} + +export interface FirewallRulesDelete202Headers { + /** The Location header contains the URL where the status of the long running operation can be checked. */ + location?: string; + /** The Retry-After header can indicate how long the client should wait before polling the operation status. */ + "retry-after"?: number; +} + +/** Resource deletion accepted. */ +export interface FirewallRulesDelete202Response extends HttpResponse { + status: "202"; + headers: RawHttpHeaders & FirewallRulesDelete202Headers; +} + +/** Resource does not exist. */ +export interface FirewallRulesDelete204Response extends HttpResponse { + status: "204"; +} + +export interface FirewallRulesDeleteDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The final response for long-running delete operation */ +export interface FirewallRulesDeleteLogicalResponse extends HttpResponse { + status: "200"; +} + +/** Azure operation completed successfully. */ +export interface FirewallRulesListByMongoCluster200Response + extends HttpResponse { + status: "200"; + body: FirewallRuleListResultOutput; +} + +export interface FirewallRulesListByMongoClusterDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** Azure operation completed successfully. */ +export interface PrivateEndpointConnectionsListByMongoCluster200Response + extends HttpResponse { + status: "200"; + body: PrivateEndpointConnectionResourceListResultOutput; +} + +export interface PrivateEndpointConnectionsListByMongoClusterDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** Azure operation completed successfully. */ +export interface PrivateEndpointConnectionsGet200Response extends HttpResponse { + status: "200"; + body: PrivateEndpointConnectionResourceOutput; +} + +export interface PrivateEndpointConnectionsGetDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** Resource 'PrivateEndpointConnectionResource' update operation succeeded */ +export interface PrivateEndpointConnectionsCreate200Response + extends HttpResponse { + status: "200"; + body: PrivateEndpointConnectionResourceOutput; +} + +/** Resource 'PrivateEndpointConnectionResource' create operation succeeded */ +export interface PrivateEndpointConnectionsCreate201Response + extends HttpResponse { + status: "201"; + body: PrivateEndpointConnectionResourceOutput; +} + +export interface PrivateEndpointConnectionsCreate202Headers { + /** The Location header contains the URL where the status of the long running operation can be checked. */ + location?: string; + /** The Retry-After header can indicate how long the client should wait before polling the operation status. */ + "retry-after"?: number; +} + +/** Resource operation accepted. */ +export interface PrivateEndpointConnectionsCreate202Response + extends HttpResponse { + status: "202"; + headers: RawHttpHeaders & PrivateEndpointConnectionsCreate202Headers; +} + +export interface PrivateEndpointConnectionsCreateDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The final response for long-running create operation */ +export interface PrivateEndpointConnectionsCreateLogicalResponse + extends HttpResponse { + status: "200"; + body: PrivateEndpointConnectionResourceOutput; +} + +export interface PrivateEndpointConnectionsDelete202Headers { + /** The Location header contains the URL where the status of the long running operation can be checked. */ + location?: string; + /** The Retry-After header can indicate how long the client should wait before polling the operation status. */ + "retry-after"?: number; +} + +/** Resource deletion accepted. */ +export interface PrivateEndpointConnectionsDelete202Response + extends HttpResponse { + status: "202"; + headers: RawHttpHeaders & PrivateEndpointConnectionsDelete202Headers; +} + +/** Resource does not exist. */ +export interface PrivateEndpointConnectionsDelete204Response + extends HttpResponse { + status: "204"; +} + +export interface PrivateEndpointConnectionsDeleteDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** The final response for long-running delete operation */ +export interface PrivateEndpointConnectionsDeleteLogicalResponse + extends HttpResponse { + status: "200"; +} + +/** Azure operation completed successfully. */ +export interface PrivateLinksListByMongoCluster200Response + extends HttpResponse { + status: "200"; + body: PrivateLinkResourceListResultOutput; +} + +export interface PrivateLinksListByMongoClusterDefaultResponse + extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} + +/** Azure operation completed successfully. */ +export interface ReplicasListByParent200Response extends HttpResponse { + status: "200"; + body: ReplicaListResultOutput; +} + +export interface ReplicasListByParentDefaultResponse extends HttpResponse { + status: string; + body: ErrorResponseOutput; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/src/restorePollerHelpers.ts b/sdk/mongocluster/arm-mongoclustertest/src/restorePollerHelpers.ts new file mode 100644 index 000000000000..32f2ec78d83c --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/src/restorePollerHelpers.ts @@ -0,0 +1,184 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { + PollerLike, + OperationState, + deserializeState, + ResourceLocationConfig, +} from "@azure/core-lro"; +import { MongoClusterManagementClient } from "./mongoClusterManagementClient.js"; +import { getLongRunningPoller } from "./api/pollingHelpers.js"; +import { + _mongoClustersCreateOrUpdateDeserialize, + _mongoClustersUpdateDeserialize, + _mongoClustersDeleteDeserialize, + _mongoClustersPromoteDeserialize, +} from "./api/mongoClusters/index.js"; +import { + _firewallRulesCreateOrUpdateDeserialize, + _firewallRulesDeleteDeserialize, +} from "./api/firewallRules/index.js"; +import { + _privateEndpointConnectionsCreateDeserialize, + _privateEndpointConnectionsDeleteDeserialize, +} from "./api/privateEndpointConnections/index.js"; +import { + PathUncheckedResponse, + OperationOptions, +} from "@azure-rest/core-client"; +import { AbortSignalLike } from "@azure/abort-controller"; + +export interface RestorePollerOptions< + TResult, + TResponse extends PathUncheckedResponse = PathUncheckedResponse, +> extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; + /** + * The signal which can be used to abort requests. + */ + abortSignal?: AbortSignalLike; + /** Deserialization function for raw response body */ + processResponseBody?: (result: TResponse) => Promise; +} + +/** + * Creates a poller from the serialized state of another poller. This can be + * useful when you want to create pollers on a different host or a poller + * needs to be constructed after the original one is not in scope. + */ +export function restorePoller( + client: MongoClusterManagementClient, + serializedState: string, + sourceOperation: ( + ...args: any[] + ) => PollerLike, TResult>, + options?: RestorePollerOptions, +): PollerLike, TResult> { + const pollerConfig = deserializeState(serializedState).config; + const { initialRequestUrl, requestMethod, metadata } = pollerConfig; + if (!initialRequestUrl || !requestMethod) { + throw new Error( + `Invalid serialized state: ${serializedState} for sourceOperation ${sourceOperation?.name}`, + ); + } + const resourceLocationConfig = metadata?.["resourceLocationConfig"] as + | ResourceLocationConfig + | undefined; + const deserializeHelper = + options?.processResponseBody ?? + getDeserializationHelper(initialRequestUrl, requestMethod); + if (!deserializeHelper) { + throw new Error( + `Please ensure the operation is in this client! We can't find its deserializeHelper for ${sourceOperation?.name}.`, + ); + } + return getLongRunningPoller( + (client as any)["_client"] ?? client, + deserializeHelper as (result: TResponse) => Promise, + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + resourceLocationConfig, + restoreFrom: serializedState, + initialRequestUrl, + }, + ); +} + +const deserializeMap: Record = { + "PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}": + _mongoClustersCreateOrUpdateDeserialize, + "PATCH /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}": + _mongoClustersUpdateDeserialize, + "DELETE /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}": + _mongoClustersDeleteDeserialize, + "POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/promote": + _mongoClustersPromoteDeserialize, + "PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/firewallRules/{firewallRuleName}": + _firewallRulesCreateOrUpdateDeserialize, + "DELETE /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/firewallRules/{firewallRuleName}": + _firewallRulesDeleteDeserialize, + "PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateEndpointConnections/{privateEndpointConnectionName}": + _privateEndpointConnectionsCreateDeserialize, + "DELETE /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/mongoClusters/{mongoClusterName}/privateEndpointConnections/{privateEndpointConnectionName}": + _privateEndpointConnectionsDeleteDeserialize, +}; + +function getDeserializationHelper( + urlStr: string, + method: string, +): ((result: unknown) => Promise) | undefined { + const path = new URL(urlStr).pathname; + const pathParts = path.split("/"); + + // Traverse list to match the longest candidate + // matchedLen: the length of candidate path + // matchedValue: the matched status code array + let matchedLen = -1, + matchedValue: ((result: unknown) => Promise) | undefined; + + // Iterate the responseMap to find a match + for (const [key, value] of Object.entries(deserializeMap)) { + // Extracting the path from the map key which is in format + // GET /path/foo + if (!key.startsWith(method)) { + continue; + } + const candidatePath = getPathFromMapKey(key); + // Get each part of the url path + const candidateParts = candidatePath.split("/"); + + // track if we have found a match to return the values found. + let found = true; + for ( + let i = candidateParts.length - 1, j = pathParts.length - 1; + i >= 1 && j >= 1; + i--, j-- + ) { + if ( + candidateParts[i]?.startsWith("{") && + candidateParts[i]?.indexOf("}") !== -1 + ) { + const start = candidateParts[i]!.indexOf("}") + 1, + end = candidateParts[i]?.length; + // If the current part of the candidate is a "template" part + // Try to use the suffix of pattern to match the path + // {guid} ==> $ + // {guid}:export ==> :export$ + const isMatched = new RegExp( + `${candidateParts[i]?.slice(start, end)}`, + ).test(pathParts[j] || ""); + + if (!isMatched) { + found = false; + break; + } + continue; + } + + // If the candidate part is not a template and + // the parts don't match mark the candidate as not found + // to move on with the next candidate path. + if (candidateParts[i] !== pathParts[j]) { + found = false; + break; + } + } + + // We finished evaluating the current candidate parts + // Update the matched value if and only if we found the longer pattern + if (found && candidatePath.length > matchedLen) { + matchedLen = candidatePath.length; + matchedValue = value as (result: unknown) => Promise; + } + } + + return matchedValue; +} + +function getPathFromMapKey(mapKey: string): string { + const pathStart = mapKey.indexOf("/"); + return mapKey.slice(pathStart); +} diff --git a/sdk/mongocluster/arm-mongoclustertest/test/public/sampleTest.spec.ts b/sdk/mongocluster/arm-mongoclustertest/test/public/sampleTest.spec.ts new file mode 100644 index 000000000000..344657d6f17e --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/test/public/sampleTest.spec.ts @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { createRecorder } from "./utils/recordedClient.js"; +import { assert, beforeEach, afterEach, it, describe } from "vitest"; + +describe("My test", () => { + // let recorder: Recorder; + + beforeEach(async function () { + // recorder = await createRecorder(this); + }); + + afterEach(async function () { + // await recorder.stop(); + }); + + it("sample test", async function () { + assert.equal(1, 1); + }); +}); diff --git a/sdk/mongocluster/arm-mongoclustertest/test/public/utils/recordedClient.ts b/sdk/mongocluster/arm-mongoclustertest/test/public/utils/recordedClient.ts new file mode 100644 index 000000000000..a4d8acf86259 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/test/public/utils/recordedClient.ts @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { + Recorder, + RecorderStartOptions, + VitestTestContext, +} from "@azure-tools/test-recorder"; + +const replaceableVariables: Record = { + SUBSCRIPTION_ID: "azure_subscription_id", +}; + +const recorderEnvSetup: RecorderStartOptions = { + envSetupForPlayback: replaceableVariables, +}; + +/** + * creates the recorder and reads the environment variables from the `.env` file. + * Should be called first in the test suite to make sure environment variables are + * read before they are being used. + */ +export async function createRecorder( + context: VitestTestContext, +): Promise { + const recorder = new Recorder(context); + await recorder.start(recorderEnvSetup); + return recorder; +} diff --git a/sdk/mongocluster/arm-mongoclustertest/tsconfig.browser.config.json b/sdk/mongocluster/arm-mongoclustertest/tsconfig.browser.config.json new file mode 100644 index 000000000000..1b37aebc5457 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/tsconfig.browser.config.json @@ -0,0 +1,10 @@ +{ + "extends": "./.tshy/build.json", + "include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts"], + "exclude": ["./test/**/node/**/*.ts"], + "compilerOptions": { + "outDir": "./dist-test/browser", + "rootDir": ".", + "skipLibCheck": true + } +} diff --git a/sdk/mongocluster/arm-mongoclustertest/tsconfig.json b/sdk/mongocluster/arm-mongoclustertest/tsconfig.json new file mode 100644 index 000000000000..fa968e3bfdc6 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../../../tsconfig", + "compilerOptions": { + "module": "NodeNext", + "moduleResolution": "NodeNext", + "rootDir": "." + }, + "include": [ + "./src/**/*.ts", + "./src/**/*.mts", + "./src/**/*.cts", + "test/**/*.ts", + "./test/**/*.ts" + ] +} \ No newline at end of file diff --git a/sdk/mongocluster/arm-mongoclustertest/tsp-location.yaml b/sdk/mongocluster/arm-mongoclustertest/tsp-location.yaml new file mode 100644 index 000000000000..d06a850eec62 --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/tsp-location.yaml @@ -0,0 +1,4 @@ +directory: specification/mongoclustertest/DocumentDB.MongoCluster.Management +commit: 8387ea3d827cb70dbfd8c4a6627e669d7598d5aa +repo: /mnt/vss/_work/1/s/azure-rest-api-specs +additionalDirectories: \ No newline at end of file diff --git a/sdk/mongocluster/arm-mongoclustertest/vitest.browser.config.ts b/sdk/mongocluster/arm-mongoclustertest/vitest.browser.config.ts new file mode 100644 index 000000000000..eda90c3ea96b --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/vitest.browser.config.ts @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { defineConfig } from "vitest/config"; +import { relativeRecordingsPath } from "@azure-tools/test-recorder"; + +process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath(); + +export default defineConfig({ + define: { + "process.env": process.env, + }, + test: { + reporters: ["basic", "junit"], + outputFile: { + junit: "test-results.browser.xml", + }, + browser: { + enabled: true, + headless: true, + name: "chromium", + provider: "playwright", + }, + fakeTimers: { + toFake: ["setTimeout", "Date"], + }, + watch: false, + include: ["dist-test/browser/**/*.spec.js"], + coverage: { + include: ["dist-test/browser/**/*.spec.js"], + provider: "istanbul", + reporter: ["text", "json", "html"], + reportsDirectory: "coverage-browser", + }, + testTimeout: 1200000, + }, +}); diff --git a/sdk/mongocluster/arm-mongoclustertest/vitest.config.ts b/sdk/mongocluster/arm-mongoclustertest/vitest.config.ts new file mode 100644 index 000000000000..7928f980b01c --- /dev/null +++ b/sdk/mongocluster/arm-mongoclustertest/vitest.config.ts @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { defineConfig } from "vitest/config"; +import { relativeRecordingsPath } from "@azure-tools/test-recorder"; + +export default defineConfig({ + test: { + reporters: ["basic", "junit"], + outputFile: { + junit: "test-results.browser.xml", + }, + fakeTimers: { + toFake: ["setTimeout", "Date"], + }, + watch: false, + include: ["test/**/*.spec.ts"], + exclude: ["test/**/browser/*.spec.ts"], + coverage: { + include: ["src/**/*.ts"], + exclude: [ + "src/**/*-browser.mts", + "src/**/*-react-native.mts", + "vitest*.config.ts", + "samples-dev/**/*.ts", + ], + provider: "istanbul", + reporter: ["text", "json", "html"], + reportsDirectory: "coverage", + }, + testTimeout: 1200000, + }, +}); diff --git a/sdk/mongocluster/ci.yml b/sdk/mongocluster/ci.yml new file mode 100644 index 000000000000..69ebc981d21f --- /dev/null +++ b/sdk/mongocluster/ci.yml @@ -0,0 +1,39 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. + +trigger: + branches: + include: + - main + - feature/* + - release/* + - hotfix/* + exclude: + - feature/v4 + paths: + include: + - sdk/mongocluster/ + exclude: + - sdk/mongocluster/arm-mongocluster + - sdk/mongocluster/ci.mgmt.yml +pr: + branches: + include: + - main + - feature/* + - release/* + - hotfix/* + exclude: + - feature/v4 + paths: + include: + - sdk/mongocluster/ + exclude: + - sdk/mongocluster/arm-mongocluster + - sdk/mongocluster/ci.mgmt.yml +extends: + template: /eng/pipelines/templates/stages/archetype-sdk-client.yml + parameters: + ServiceDirectory: mongocluster + Artifacts: + - name: azure-arm-mongoclustertest + safeName: azurearmmongoclustertest