From ffcbc56f91a7501f5a6be9373e00a8968267216a Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 05:10:05 +0800 Subject: [PATCH 01/34] prepare --- .scripts/automation_generate.bat | 1 + .scripts/automation_generate.ps1 | 1 + .vscode/settings.json | 3 +- common/config/rush/pnpm-lock.yaml | 40 +++++++++++++++++++ .../src/commands/admin/migrate-package.ts | 3 +- 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 .scripts/automation_generate.bat create mode 100644 .scripts/automation_generate.ps1 diff --git a/.scripts/automation_generate.bat b/.scripts/automation_generate.bat new file mode 100644 index 000000000000..c6f0596b1e9e --- /dev/null +++ b/.scripts/automation_generate.bat @@ -0,0 +1 @@ +code-gen-pipeline --inputJsonPath=../test/in.json --outputJsonPath=../test/out.json --use=@autorest/typescript@^6.0.12 --typespecEmitter=@azure-tools/typespec-ts --local diff --git a/.scripts/automation_generate.ps1 b/.scripts/automation_generate.ps1 new file mode 100644 index 000000000000..c6f0596b1e9e --- /dev/null +++ b/.scripts/automation_generate.ps1 @@ -0,0 +1 @@ +code-gen-pipeline --inputJsonPath=../test/in.json --outputJsonPath=../test/out.json --use=@autorest/typescript@^6.0.12 --typespecEmitter=@azure-tools/typespec-ts --local diff --git a/.vscode/settings.json b/.vscode/settings.json index d4b308085e08..7edad528446f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -39,5 +39,6 @@ "vitest.vitestPackagePath": "common/tools/dev-tool/node_modules/vitest/package.json", "vitest.experimentalStaticAstCollect": true, "vitest.configSearchPatternExclude": "{**/node_modules/**,**/.*/**,**/*.d.ts,eng/**,samples/**}", - "vitest.nodeEnv": {} + "vitest.nodeEnv": {}, + "workbench.colorCustomizations": {} } diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 99371afd82ed..fd3e63559617 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -325,6 +325,9 @@ importers: '@rush-temp/arm-domainservices': specifier: file:./projects/arm-domainservices.tgz version: file:projects/arm-domainservices.tgz + '@rush-temp/arm-durabletask': + specifier: file:./projects/arm-durabletask.tgz + version: file:projects/arm-durabletask.tgz(msw@2.6.8(@types/node@20.17.10)(typescript@5.7.2))(vite@5.4.11(@types/node@20.17.10)) '@rush-temp/arm-dynatrace': specifier: file:./projects/arm-dynatrace.tgz version: file:projects/arm-dynatrace.tgz @@ -2866,6 +2869,10 @@ packages: resolution: {integrity: sha512-4E4gNwGG0RGAqvHo8ExneMfHPn6WVY3Yy2C2F5XJXbdOKZiAdbWy9nXJtTk3LaU3h+TcXlKvjZY5QqHtD36kzA==, tarball: file:projects/arm-domainservices.tgz} version: 0.0.0 + '@rush-temp/arm-durabletask@file:projects/arm-durabletask.tgz': + resolution: {integrity: sha512-ToK19MZzvbAu7oy9LG4oJoNHcUHv2WiFeTkvrlsfo9jR/tAsHvu/zdIJMbs1eRYBWJxDKEIGel5HfMYuDPXkOg==, tarball: file:projects/arm-durabletask.tgz} + version: 0.0.0 + '@rush-temp/arm-dynatrace@file:projects/arm-dynatrace.tgz': resolution: {integrity: sha512-Qxua3jCy2Ce6/e6QCVgzl4BAIm7B9TYT4gq/REbVugajXMmYLAg7CzYOnEGO+fn6GKNVI8JfGOJ7Md2wGufZSA==, tarball: file:projects/arm-dynatrace.tgz} version: 0.0.0 @@ -12294,6 +12301,39 @@ snapshots: - '@swc/wasm' - supports-color + '@rush-temp/arm-durabletask@file:projects/arm-durabletask.tgz(msw@2.6.8(@types/node@20.17.10)(typescript@5.7.2))(vite@5.4.11(@types/node@20.17.10))': + dependencies: + '@microsoft/api-extractor': 7.48.0(@types/node@18.19.68) + '@types/node': 18.19.68 + '@vitest/browser': 2.1.8(@types/node@18.19.68)(playwright@1.49.1)(typescript@5.6.3)(vite@5.4.11(@types/node@20.17.10))(vitest@2.1.8) + '@vitest/coverage-istanbul': 2.1.8(vitest@2.1.8) + dotenv: 16.4.7 + eslint: 9.16.0 + playwright: 1.49.1 + tslib: 2.8.1 + typescript: 5.6.3 + vitest: 2.1.8(@types/node@18.19.68)(@vitest/browser@2.1.8)(msw@2.6.8(@types/node@20.17.10)(typescript@5.7.2)) + transitivePeerDependencies: + - '@edge-runtime/vm' + - '@vitest/ui' + - bufferutil + - happy-dom + - jiti + - jsdom + - less + - lightningcss + - msw + - safaridriver + - sass + - sass-embedded + - stylus + - sugarss + - supports-color + - terser + - utf-8-validate + - vite + - webdriverio + '@rush-temp/arm-dynatrace@file:projects/arm-dynatrace.tgz': dependencies: '@azure-tools/test-credential': 1.3.1 diff --git a/common/tools/dev-tool/src/commands/admin/migrate-package.ts b/common/tools/dev-tool/src/commands/admin/migrate-package.ts index 6a8b42b32045..9bb3f2db4e52 100644 --- a/common/tools/dev-tool/src/commands/admin/migrate-package.ts +++ b/common/tools/dev-tool/src/commands/admin/migrate-package.ts @@ -86,7 +86,7 @@ export default leafCommand(commandInfo, async ({ "package-name": packageName, br await applyCodemods(projectFolder); log.info("Formatting files"); - await run(["rushx", "format"], { cwd: projectFolder }); + await run(["rushx", "format"], { cwd: projectFolder, shell: true }); await commitChanges(projectFolder, "rushx format"); log.info( @@ -328,6 +328,7 @@ async function addNewPackages(packageJson: any): Promise { latestVersion = ( await run(["npm", "view", newPackage, "version"], { captureOutput: true, + shell: true, }) ).output; } From 47f586deb8f21de1f25605691ebdab0ef077611d Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 05:48:37 +0800 Subject: [PATCH 02/34] Migration: Update package.json, tsconfig.json, and api-extractor.json --- sdk/durabletask/arm-durabletask/LICENSE | 21 + sdk/durabletask/arm-durabletask/README.md | 102 ++++ .../arm-durabletask/api-extractor.json | 31 ++ .../arm-durabletask/eslint.config.mjs | 17 + sdk/durabletask/arm-durabletask/package.json | 109 ++++ sdk/durabletask/arm-durabletask/sample.env | 1 + .../src/api/durableTaskContext.ts | 56 ++ .../arm-durabletask/src/api/index.ts | 36 ++ .../src/api/operations/index.ts | 56 ++ .../arm-durabletask/src/api/options.ts | 56 ++ .../src/api/schedulers/index.ts | 344 +++++++++++++ .../arm-durabletask/src/api/taskHubs/index.ts | 257 ++++++++++ .../arm-durabletask/src/classic/index.ts | 6 + .../src/classic/operations/index.ts | 31 ++ .../src/classic/schedulers/index.ts | 144 ++++++ .../src/classic/taskHubs/index.ts | 124 +++++ .../arm-durabletask/src/durableTaskClient.ts | 56 ++ .../src/helpers/serializerHelpers.ts | 40 ++ sdk/durabletask/arm-durabletask/src/index.ts | 55 ++ sdk/durabletask/arm-durabletask/src/logger.ts | 5 + .../arm-durabletask/src/models/index.ts | 27 + .../arm-durabletask/src/models/models.ts | 481 ++++++++++++++++++ .../src/restorePollerHelpers.ts | 194 +++++++ .../src/static-helpers/pagingHelpers.ts | 274 ++++++++++ .../src/static-helpers/pollingHelpers.ts | 137 +++++ .../test/public/sampleTest.spec.ts | 21 + .../test/public/utils/recordedClient.ts | 29 ++ .../tsconfig.browser.config.json | 10 + sdk/durabletask/arm-durabletask/tsconfig.json | 18 + .../arm-durabletask/tsp-location.yaml | 4 + .../arm-durabletask/vitest.browser.config.ts | 38 ++ .../arm-durabletask/vitest.config.ts | 34 ++ 32 files changed, 2814 insertions(+) create mode 100644 sdk/durabletask/arm-durabletask/LICENSE create mode 100644 sdk/durabletask/arm-durabletask/README.md create mode 100644 sdk/durabletask/arm-durabletask/api-extractor.json create mode 100644 sdk/durabletask/arm-durabletask/eslint.config.mjs create mode 100644 sdk/durabletask/arm-durabletask/package.json create mode 100644 sdk/durabletask/arm-durabletask/sample.env create mode 100644 sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts create mode 100644 sdk/durabletask/arm-durabletask/src/api/index.ts create mode 100644 sdk/durabletask/arm-durabletask/src/api/operations/index.ts create mode 100644 sdk/durabletask/arm-durabletask/src/api/options.ts create mode 100644 sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts create mode 100644 sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts create mode 100644 sdk/durabletask/arm-durabletask/src/classic/index.ts create mode 100644 sdk/durabletask/arm-durabletask/src/classic/operations/index.ts create mode 100644 sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts create mode 100644 sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts create mode 100644 sdk/durabletask/arm-durabletask/src/durableTaskClient.ts create mode 100644 sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts create mode 100644 sdk/durabletask/arm-durabletask/src/index.ts create mode 100644 sdk/durabletask/arm-durabletask/src/logger.ts create mode 100644 sdk/durabletask/arm-durabletask/src/models/index.ts create mode 100644 sdk/durabletask/arm-durabletask/src/models/models.ts create mode 100644 sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts create mode 100644 sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts create mode 100644 sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts create mode 100644 sdk/durabletask/arm-durabletask/test/public/sampleTest.spec.ts create mode 100644 sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts create mode 100644 sdk/durabletask/arm-durabletask/tsconfig.browser.config.json create mode 100644 sdk/durabletask/arm-durabletask/tsconfig.json create mode 100644 sdk/durabletask/arm-durabletask/tsp-location.yaml create mode 100644 sdk/durabletask/arm-durabletask/vitest.browser.config.ts create mode 100644 sdk/durabletask/arm-durabletask/vitest.config.ts diff --git a/sdk/durabletask/arm-durabletask/LICENSE b/sdk/durabletask/arm-durabletask/LICENSE new file mode 100644 index 000000000000..7d5934740965 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/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/durabletask/arm-durabletask/README.md b/sdk/durabletask/arm-durabletask/README.md new file mode 100644 index 000000000000..8e49cf1ca09e --- /dev/null +++ b/sdk/durabletask/arm-durabletask/README.md @@ -0,0 +1,102 @@ +# Azure DurableTask client library for JavaScript + +This package contains an isomorphic SDK (runs both in Node.js and in browsers) for Azure DurableTask client. + + + +Key links: + +- [Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/durabletask/arm-durabletask) +- [Package (NPM)](https://www.npmjs.com/package/@azure/arm-durabletask) +- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/arm-durabletask?view=azure-node-preview) + +## 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-durabletask` package + +Install the Azure DurableTask client library for JavaScript with `npm`: + +```bash +npm install @azure/arm-durabletask +``` + +### Create and authenticate a `DurableTaskClient` + +To create a client object to access the Azure DurableTask API, you will need the `endpoint` of your Azure DurableTask resource and a `credential`. The Azure DurableTask client can use Azure Active Directory credentials to authenticate. +You can find the endpoint for your Azure DurableTask 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 DurableTask** by assigning the suitable role to your service principal (note: roles such as `"Owner"` will not grant the necessary permissions). + +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 { DurableTaskClient } = require("@azure/arm-durabletask"); +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 DurableTaskClient(new DefaultAzureCredential(), subscriptionId); + +// For client-side applications running in the browser, use this code instead: +// const credential = new InteractiveBrowserCredential({ +// tenantId: "", +// clientId: "" +// }); +// const client = new DurableTaskClient(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 + +### DurableTaskClient + +`DurableTaskClient` is the primary interface for developers using the Azure DurableTask client library. Explore the methods on this client object to understand the different features of the Azure DurableTask 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). + + +## 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/durabletask/arm-durabletask/api-extractor.json b/sdk/durabletask/arm-durabletask/api-extractor.json new file mode 100644 index 000000000000..b6a37cba0930 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/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": "dist/arm-durabletask.d.ts" + }, + "messages": { + "tsdocMessageReporting": { + "default": { + "logLevel": "none" + } + }, + "extractorMessageReporting": { + "ae-missing-release-tag": { + "logLevel": "none" + }, + "ae-unresolved-link": { + "logLevel": "none" + } + } + } +} diff --git a/sdk/durabletask/arm-durabletask/eslint.config.mjs b/sdk/durabletask/arm-durabletask/eslint.config.mjs new file mode 100644 index 000000000000..113bdc3eaf5f --- /dev/null +++ b/sdk/durabletask/arm-durabletask/eslint.config.mjs @@ -0,0 +1,17 @@ +import azsdkEslint from "@azure/eslint-plugin-azure-sdk"; + +export default [ + ...azsdkEslint.configs.recommended, + { + 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", + "@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", + "tsdoc/syntax": "warn" + } + } +]; diff --git a/sdk/durabletask/arm-durabletask/package.json b/sdk/durabletask/arm-durabletask/package.json new file mode 100644 index 000000000000..7c6f0ae47889 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/package.json @@ -0,0 +1,109 @@ +{ + "name": "@azure/arm-durabletask", + "version": "1.0.0-beta.1", + "description": "A generated SDK for DurableTaskClient.", + "engines": { + "node": ">=18.0.0" + }, + "sideEffects": false, + "autoPublish": false, + "tshy": { + "exports": { + "./package.json": "./package.json", + ".": "./src/index.ts" + }, + "dialects": [ + "esm", + "commonjs" + ], + "esmDialects": [ + "browser", + "react-native" + ], + "selfLink": false + }, + "type": "module", + "keywords": [ + "node", + "azure", + "cloud", + "typescript", + "browser", + "isomorphic" + ], + "author": "Microsoft Corporation", + "license": "MIT", + "files": [ + "dist/", + "README.md", + "LICENSE" + ], + "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/durabletask/arm-durabletask/README.md", + "prettier": "@azure/eslint-plugin-azure-sdk/prettier.json", + "//metadata": { + "constantPaths": [ + { + "path": "src/api/durableTaskContext.ts", + "prefix": "userAgentInfo" + } + ] + }, + "dependencies": { + "@azure-rest/core-client": "^2.3.1", + "@azure/abort-controller": "^2.1.2", + "@azure/core-auth": "^1.6.0", + "@azure/core-lro": "^3.1.0", + "@azure/core-rest-pipeline": "^1.5.0", + "@azure/core-util": "^1.9.2", + "@azure/logger": "^1.0.0", + "tslib": "^2.6.2" + }, + "devDependencies": { + "@azure-tools/test-credential": "^2.0.0", + "@azure-tools/test-recorder": "^4.1.0", + "@azure-tools/test-utils-vitest": "^1.0.0", + "@azure/dev-tool": "^1.0.0", + "@azure/eslint-plugin-azure-sdk": "^3.0.0", + "@azure/identity": "^4.2.1", + "@microsoft/api-extractor": "^7.40.3", + "@types/node": "^18.0.0", + "@vitest/browser": "^2.1.8", + "@vitest/coverage-istanbul": "^2.1.8", + "dotenv": "^16.0.0", + "eslint": "^9.9.0", + "playwright": "^1.49.1", + "typescript": "~5.6.2", + "vitest": "^2.1.8" + }, + "scripts": { + "build": "npm run clean && dev-tool run build-package && dev-tool run extract-api", + "build:samples": "echo skipped", + "build:test": "npm run clean && dev-tool run build-package && dev-tool run build-test", + "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}\" ", + "clean": "dev-tool run vendored rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", + "execute:samples": "echo skipped", + "extract-api": "dev-tool run vendored rimraf review && dev-tool run vendored mkdirp ./review && dev-tool run extract-api", + "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", + "integration-test": "npm run integration-test:node && npm run integration-test:browser", + "integration-test:browser": "echo skipped", + "integration-test:node": "echo skipped", + "lint": "eslint package.json api-extractor.json src test", + "lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]", + "minify": "dev-tool run vendored uglifyjs -c -m --comments --source-map \"content='./dist/index.js.map'\" -o ./dist/index.min.js ./dist/index.js", + "pack": "npm pack 2>&1", + "test": "npm run clean && dev-tool run build-package && npm run unit-test:node && dev-tool run bundle && npm run unit-test:browser && npm run integration-test", + "test:browser": "npm run clean && npm run build:test && npm run unit-test:browser && npm run integration-test:browser", + "test:node": "npm run clean && dev-tool run build-package && npm run unit-test:node && npm run integration-test:node", + "unit-test": "npm run unit-test:node && npm run unit-test:browser", + "unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser", + "unit-test:node": "dev-tool run test:vitest", + "update-snippets": "echo skipped" + }, + "browser": "./dist/browser/index.js" +} diff --git a/sdk/durabletask/arm-durabletask/sample.env b/sdk/durabletask/arm-durabletask/sample.env new file mode 100644 index 000000000000..508439fc7d62 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/sample.env @@ -0,0 +1 @@ +# Feel free to add your own environment variables. \ No newline at end of file diff --git a/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts b/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts new file mode 100644 index 000000000000..63aa3c0cf662 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { logger } from "../logger.js"; +import { KnownVersions } from "../models/models.js"; +import { Client, ClientOptions, getClient } from "@azure-rest/core-client"; +import { TokenCredential } from "@azure/core-auth"; + +export interface DurableTaskContext extends Client {} + +/** Optional parameters for the client. */ +export interface DurableTaskClientOptionalParams extends ClientOptions { + /** The API version to use for this operation. */ + /** Known values of {@link KnownVersions} that the service accepts. */ + apiVersion?: string; +} + +export function createDurableTask( + credential: TokenCredential, + options: DurableTaskClientOptionalParams = {}, +): DurableTaskContext { + const endpointUrl = + options.endpoint ?? options.baseUrl ?? `https://management.azure.com`; + const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; + const userAgentInfo = `azsdk-js-arm-durabletask/1.0.0-beta.1`; + const userAgentPrefix = prefixFromOptions + ? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}` + : `azsdk-js-api ${userAgentInfo}`; + const { apiVersion: _, ...updatedOptions } = { + ...options, + userAgentOptions: { userAgentPrefix }, + loggingOptions: { logger: options.loggingOptions?.logger ?? logger.info }, + credentials: { + scopes: options.credentials?.scopes ?? [`${endpointUrl}/.default`], + }, + }; + const clientContext = getClient(endpointUrl, credential, updatedOptions); + clientContext.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + const apiVersion = options.apiVersion ?? "2024-10-01-preview"; + clientContext.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")) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return clientContext; +} diff --git a/sdk/durabletask/arm-durabletask/src/api/index.ts b/sdk/durabletask/arm-durabletask/src/api/index.ts new file mode 100644 index 000000000000..0a12c010c315 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/api/index.ts @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +export { + createDurableTask, + DurableTaskContext, + DurableTaskClientOptionalParams, +} from "./durableTaskContext.js"; +export { + OperationsListOptionalParams, + SchedulersGetOptionalParams, + SchedulersCreateOrUpdateOptionalParams, + SchedulersUpdateOptionalParams, + SchedulersDeleteOptionalParams, + SchedulersListByResourceGroupOptionalParams, + SchedulersListBySubscriptionOptionalParams, + TaskHubsGetOptionalParams, + TaskHubsCreateOrUpdateOptionalParams, + TaskHubsDeleteOptionalParams, + TaskHubsListBySchedulerOptionalParams, +} from "./options.js"; +export { operationsList } from "./operations/index.js"; +export { + schedulersGet, + schedulersCreateOrUpdate, + schedulersUpdate, + schedulersDelete, + schedulersListByResourceGroup, + schedulersListBySubscription, +} from "./schedulers/index.js"; +export { + taskHubsGet, + taskHubsCreateOrUpdate, + taskHubsDelete, + taskHubsListByScheduler, +} from "./taskHubs/index.js"; diff --git a/sdk/durabletask/arm-durabletask/src/api/operations/index.ts b/sdk/durabletask/arm-durabletask/src/api/operations/index.ts new file mode 100644 index 000000000000..86ac95ed3ee3 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/api/operations/index.ts @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + DurableTaskContext as Client, + OperationsListOptionalParams, +} from "../index.js"; +import { + _OperationListResult, + _operationListResultDeserializer, + Operation, +} from "../../models/models.js"; +import { + PagedAsyncIterableIterator, + buildPagedAsyncIterator, +} from "../../static-helpers/pagingHelpers.js"; +import { + StreamableMethod, + PathUncheckedResponse, + createRestError, + operationOptionsToRequestParameters, +} from "@azure-rest/core-client"; + +export function _operationsListSend( + context: Client, + options: OperationsListOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path("/providers/Microsoft.DurableTask/operations") + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _operationsListDeserialize( + result: PathUncheckedResponse, +): Promise<_OperationListResult> { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + throw createRestError(result); + } + + return _operationListResultDeserializer(result.body); +} + +/** List the operations for the provider */ +export function operationsList( + context: Client, + options: OperationsListOptionalParams = { requestOptions: {} }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => _operationsListSend(context, options), + _operationsListDeserialize, + ["200"], + { itemName: "value", nextLinkName: "nextLink" }, + ); +} diff --git a/sdk/durabletask/arm-durabletask/src/api/options.ts b/sdk/durabletask/arm-durabletask/src/api/options.ts new file mode 100644 index 000000000000..9a33e997e7d9 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/api/options.ts @@ -0,0 +1,56 @@ +// 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 SchedulersGetOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface SchedulersCreateOrUpdateOptionalParams + extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface SchedulersUpdateOptionalParams extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface SchedulersDeleteOptionalParams extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface SchedulersListByResourceGroupOptionalParams + extends OperationOptions {} + +/** Optional parameters. */ +export interface SchedulersListBySubscriptionOptionalParams + extends OperationOptions {} + +/** Optional parameters. */ +export interface TaskHubsGetOptionalParams extends OperationOptions {} + +/** Optional parameters. */ +export interface TaskHubsCreateOrUpdateOptionalParams extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface TaskHubsDeleteOptionalParams extends OperationOptions { + /** Delay to wait until next poll, in milliseconds. */ + updateIntervalInMs?: number; +} + +/** Optional parameters. */ +export interface TaskHubsListBySchedulerOptionalParams + extends OperationOptions {} diff --git a/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts b/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts new file mode 100644 index 000000000000..8d6c144fb0bb --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts @@ -0,0 +1,344 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + DurableTaskContext as Client, + SchedulersCreateOrUpdateOptionalParams, + SchedulersDeleteOptionalParams, + SchedulersGetOptionalParams, + SchedulersListByResourceGroupOptionalParams, + SchedulersListBySubscriptionOptionalParams, + SchedulersUpdateOptionalParams, +} from "../index.js"; +import { + Scheduler, + schedulerSerializer, + schedulerDeserializer, + _SchedulerListResult, + _schedulerListResultDeserializer, +} from "../../models/models.js"; +import { + PagedAsyncIterableIterator, + buildPagedAsyncIterator, +} from "../../static-helpers/pagingHelpers.js"; +import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js"; +import { + StreamableMethod, + PathUncheckedResponse, + createRestError, + operationOptionsToRequestParameters, +} from "@azure-rest/core-client"; +import { PollerLike, OperationState } from "@azure/core-lro"; + +export function _schedulersGetSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + options: SchedulersGetOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}", + subscriptionId, + resourceGroupName, + schedulerName, + ) + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _schedulersGetDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + throw createRestError(result); + } + + return schedulerDeserializer(result.body); +} + +/** Get a Scheduler */ +export async function schedulersGet( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + options: SchedulersGetOptionalParams = { requestOptions: {} }, +): Promise { + const result = await _schedulersGetSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + options, + ); + return _schedulersGetDeserialize(result); +} + +export function _schedulersCreateOrUpdateSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + resource: Scheduler, + options: SchedulersCreateOrUpdateOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}", + subscriptionId, + resourceGroupName, + schedulerName, + ) + .put({ + ...operationOptionsToRequestParameters(options), + body: schedulerSerializer(resource), + }); +} + +export async function _schedulersCreateOrUpdateDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200", "201"]; + if (!expectedStatuses.includes(result.status)) { + throw createRestError(result); + } + + return schedulerDeserializer(result.body); +} + +/** Create or update a Scheduler */ +export function schedulersCreateOrUpdate( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + resource: Scheduler, + options: SchedulersCreateOrUpdateOptionalParams = { requestOptions: {} }, +): PollerLike, Scheduler> { + return getLongRunningPoller( + context, + _schedulersCreateOrUpdateDeserialize, + ["200", "201"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersCreateOrUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }, + ) as PollerLike, Scheduler>; +} + +export function _schedulersUpdateSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + properties: Scheduler, + options: SchedulersUpdateOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}", + subscriptionId, + resourceGroupName, + schedulerName, + ) + .patch({ + ...operationOptionsToRequestParameters(options), + body: schedulerSerializer(properties), + }); +} + +export async function _schedulersUpdateDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200", "202"]; + if (!expectedStatuses.includes(result.status)) { + throw createRestError(result); + } + + return schedulerDeserializer(result.body); +} + +/** Update a Scheduler */ +export function schedulersUpdate( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + properties: Scheduler, + options: SchedulersUpdateOptionalParams = { requestOptions: {} }, +): PollerLike, Scheduler> { + return getLongRunningPoller( + context, + _schedulersUpdateDeserialize, + ["200", "202"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + properties, + options, + ), + resourceLocationConfig: "location", + }, + ) as PollerLike, Scheduler>; +} + +export function _schedulersDeleteSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + options: SchedulersDeleteOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}", + subscriptionId, + resourceGroupName, + schedulerName, + ) + .delete({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _schedulersDeleteDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["202", "204", "200"]; + if (!expectedStatuses.includes(result.status)) { + throw createRestError(result); + } + + return; +} + +/** Delete a Scheduler */ +export function schedulersDelete( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + options: SchedulersDeleteOptionalParams = { requestOptions: {} }, +): PollerLike, void> { + return getLongRunningPoller( + context, + _schedulersDeleteDeserialize, + ["202", "204", "200"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersDeleteSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + options, + ), + resourceLocationConfig: "location", + }, + ) as PollerLike, void>; +} + +export function _schedulersListByResourceGroupSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + options: SchedulersListByResourceGroupOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers", + subscriptionId, + resourceGroupName, + ) + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _schedulersListByResourceGroupDeserialize( + result: PathUncheckedResponse, +): Promise<_SchedulerListResult> { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + throw createRestError(result); + } + + return _schedulerListResultDeserializer(result.body); +} + +/** List Schedulers by resource group */ +export function schedulersListByResourceGroup( + context: Client, + subscriptionId: string, + resourceGroupName: string, + options: SchedulersListByResourceGroupOptionalParams = { requestOptions: {} }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => + _schedulersListByResourceGroupSend( + context, + subscriptionId, + resourceGroupName, + options, + ), + _schedulersListByResourceGroupDeserialize, + ["200"], + { itemName: "value", nextLinkName: "nextLink" }, + ); +} + +export function _schedulersListBySubscriptionSend( + context: Client, + subscriptionId: string, + options: SchedulersListBySubscriptionOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/subscriptions/{subscriptionId}/providers/Microsoft.DurableTask/schedulers", + subscriptionId, + ) + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _schedulersListBySubscriptionDeserialize( + result: PathUncheckedResponse, +): Promise<_SchedulerListResult> { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + throw createRestError(result); + } + + return _schedulerListResultDeserializer(result.body); +} + +/** List Schedulers by subscription */ +export function schedulersListBySubscription( + context: Client, + subscriptionId: string, + options: SchedulersListBySubscriptionOptionalParams = { requestOptions: {} }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => _schedulersListBySubscriptionSend(context, subscriptionId, options), + _schedulersListBySubscriptionDeserialize, + ["200"], + { itemName: "value", nextLinkName: "nextLink" }, + ); +} diff --git a/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts b/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts new file mode 100644 index 000000000000..0b611635617f --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts @@ -0,0 +1,257 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + DurableTaskContext as Client, + TaskHubsCreateOrUpdateOptionalParams, + TaskHubsDeleteOptionalParams, + TaskHubsGetOptionalParams, + TaskHubsListBySchedulerOptionalParams, +} from "../index.js"; +import { + TaskHub, + taskHubSerializer, + taskHubDeserializer, + _TaskHubListResult, + _taskHubListResultDeserializer, +} from "../../models/models.js"; +import { + PagedAsyncIterableIterator, + buildPagedAsyncIterator, +} from "../../static-helpers/pagingHelpers.js"; +import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js"; +import { + StreamableMethod, + PathUncheckedResponse, + createRestError, + operationOptionsToRequestParameters, +} from "@azure-rest/core-client"; +import { PollerLike, OperationState } from "@azure/core-lro"; + +export function _taskHubsGetSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + taskHubName: string, + options: TaskHubsGetOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/taskHubs/{taskHubName}", + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + ) + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _taskHubsGetDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + throw createRestError(result); + } + + return taskHubDeserializer(result.body); +} + +/** Get a Task Hub */ +export async function taskHubsGet( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + taskHubName: string, + options: TaskHubsGetOptionalParams = { requestOptions: {} }, +): Promise { + const result = await _taskHubsGetSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + options, + ); + return _taskHubsGetDeserialize(result); +} + +export function _taskHubsCreateOrUpdateSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + taskHubName: string, + resource: TaskHub, + options: TaskHubsCreateOrUpdateOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/taskHubs/{taskHubName}", + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + ) + .put({ + ...operationOptionsToRequestParameters(options), + body: taskHubSerializer(resource), + }); +} + +export async function _taskHubsCreateOrUpdateDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["200", "201"]; + if (!expectedStatuses.includes(result.status)) { + throw createRestError(result); + } + + return taskHubDeserializer(result.body); +} + +/** Create or Update a Task Hub */ +export function taskHubsCreateOrUpdate( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + taskHubName: string, + resource: TaskHub, + options: TaskHubsCreateOrUpdateOptionalParams = { requestOptions: {} }, +): PollerLike, TaskHub> { + return getLongRunningPoller( + context, + _taskHubsCreateOrUpdateDeserialize, + ["200", "201"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _taskHubsCreateOrUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }, + ) as PollerLike, TaskHub>; +} + +export function _taskHubsDeleteSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + taskHubName: string, + options: TaskHubsDeleteOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/taskHubs/{taskHubName}", + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + ) + .delete({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _taskHubsDeleteDeserialize( + result: PathUncheckedResponse, +): Promise { + const expectedStatuses = ["202", "204", "200"]; + if (!expectedStatuses.includes(result.status)) { + throw createRestError(result); + } + + return; +} + +/** Delete a Task Hub */ +export function taskHubsDelete( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + taskHubName: string, + options: TaskHubsDeleteOptionalParams = { requestOptions: {} }, +): PollerLike, void> { + return getLongRunningPoller( + context, + _taskHubsDeleteDeserialize, + ["202", "204", "200"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _taskHubsDeleteSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + options, + ), + resourceLocationConfig: "location", + }, + ) as PollerLike, void>; +} + +export function _taskHubsListBySchedulerSend( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + options: TaskHubsListBySchedulerOptionalParams = { requestOptions: {} }, +): StreamableMethod { + return context + .path( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/taskHubs", + subscriptionId, + resourceGroupName, + schedulerName, + ) + .get({ ...operationOptionsToRequestParameters(options) }); +} + +export async function _taskHubsListBySchedulerDeserialize( + result: PathUncheckedResponse, +): Promise<_TaskHubListResult> { + const expectedStatuses = ["200"]; + if (!expectedStatuses.includes(result.status)) { + throw createRestError(result); + } + + return _taskHubListResultDeserializer(result.body); +} + +/** List Task Hubs */ +export function taskHubsListByScheduler( + context: Client, + subscriptionId: string, + resourceGroupName: string, + schedulerName: string, + options: TaskHubsListBySchedulerOptionalParams = { requestOptions: {} }, +): PagedAsyncIterableIterator { + return buildPagedAsyncIterator( + context, + () => + _taskHubsListBySchedulerSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + options, + ), + _taskHubsListBySchedulerDeserialize, + ["200"], + { itemName: "value", nextLinkName: "nextLink" }, + ); +} diff --git a/sdk/durabletask/arm-durabletask/src/classic/index.ts b/sdk/durabletask/arm-durabletask/src/classic/index.ts new file mode 100644 index 000000000000..b888a39df4a3 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/classic/index.ts @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +export { OperationsOperations } from "./operations/index.js"; +export { SchedulersOperations } from "./schedulers/index.js"; +export { TaskHubsOperations } from "./taskHubs/index.js"; diff --git a/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts b/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts new file mode 100644 index 000000000000..467b1c1a9525 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { DurableTaskContext } from "../../api/durableTaskContext.js"; +import { operationsList } from "../../api/operations/index.js"; +import { OperationsListOptionalParams } from "../../api/options.js"; +import { Operation } from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js"; + +/** Interface representing a Operations operations. */ +export interface OperationsOperations { + /** List the operations for the provider */ + list: ( + options?: OperationsListOptionalParams, + ) => PagedAsyncIterableIterator; +} + +export function getOperations(context: DurableTaskContext) { + return { + list: (options?: OperationsListOptionalParams) => + operationsList(context, options), + }; +} + +export function getOperationsOperations( + context: DurableTaskContext, +): OperationsOperations { + return { + ...getOperations(context), + }; +} diff --git a/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts b/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts new file mode 100644 index 000000000000..9277a16c2ea0 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts @@ -0,0 +1,144 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { DurableTaskContext } from "../../api/durableTaskContext.js"; +import { + SchedulersGetOptionalParams, + SchedulersCreateOrUpdateOptionalParams, + SchedulersUpdateOptionalParams, + SchedulersDeleteOptionalParams, + SchedulersListByResourceGroupOptionalParams, + SchedulersListBySubscriptionOptionalParams, +} from "../../api/options.js"; +import { + schedulersGet, + schedulersCreateOrUpdate, + schedulersUpdate, + schedulersDelete, + schedulersListByResourceGroup, + schedulersListBySubscription, +} from "../../api/schedulers/index.js"; +import { Scheduler } from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js"; +import { PollerLike, OperationState } from "@azure/core-lro"; + +/** Interface representing a Schedulers operations. */ +export interface SchedulersOperations { + /** Get a Scheduler */ + get: ( + resourceGroupName: string, + schedulerName: string, + options?: SchedulersGetOptionalParams, + ) => Promise; + /** Create or update a Scheduler */ + createOrUpdate: ( + resourceGroupName: string, + schedulerName: string, + resource: Scheduler, + options?: SchedulersCreateOrUpdateOptionalParams, + ) => PollerLike, Scheduler>; + /** Update a Scheduler */ + update: ( + resourceGroupName: string, + schedulerName: string, + properties: Scheduler, + options?: SchedulersUpdateOptionalParams, + ) => PollerLike, Scheduler>; + /** Delete a Scheduler */ + delete: ( + resourceGroupName: string, + schedulerName: string, + options?: SchedulersDeleteOptionalParams, + ) => PollerLike, void>; + /** List Schedulers by resource group */ + listByResourceGroup: ( + resourceGroupName: string, + options?: SchedulersListByResourceGroupOptionalParams, + ) => PagedAsyncIterableIterator; + /** List Schedulers by subscription */ + listBySubscription: ( + options?: SchedulersListBySubscriptionOptionalParams, + ) => PagedAsyncIterableIterator; +} + +export function getSchedulers( + context: DurableTaskContext, + subscriptionId: string, +) { + return { + get: ( + resourceGroupName: string, + schedulerName: string, + options?: SchedulersGetOptionalParams, + ) => + schedulersGet( + context, + subscriptionId, + resourceGroupName, + schedulerName, + options, + ), + createOrUpdate: ( + resourceGroupName: string, + schedulerName: string, + resource: Scheduler, + options?: SchedulersCreateOrUpdateOptionalParams, + ) => + schedulersCreateOrUpdate( + context, + subscriptionId, + resourceGroupName, + schedulerName, + resource, + options, + ), + update: ( + resourceGroupName: string, + schedulerName: string, + properties: Scheduler, + options?: SchedulersUpdateOptionalParams, + ) => + schedulersUpdate( + context, + subscriptionId, + resourceGroupName, + schedulerName, + properties, + options, + ), + delete: ( + resourceGroupName: string, + schedulerName: string, + options?: SchedulersDeleteOptionalParams, + ) => + schedulersDelete( + context, + subscriptionId, + resourceGroupName, + schedulerName, + options, + ), + listByResourceGroup: ( + resourceGroupName: string, + options?: SchedulersListByResourceGroupOptionalParams, + ) => + schedulersListByResourceGroup( + context, + subscriptionId, + resourceGroupName, + options, + ), + listBySubscription: ( + options?: SchedulersListBySubscriptionOptionalParams, + ) => schedulersListBySubscription(context, subscriptionId, options), + }; +} + +export function getSchedulersOperations( + context: DurableTaskContext, + subscriptionId: string, +): SchedulersOperations { + return { + ...getSchedulers(context, subscriptionId), + }; +} diff --git a/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts b/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts new file mode 100644 index 000000000000..d020a2d3c910 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts @@ -0,0 +1,124 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { DurableTaskContext } from "../../api/durableTaskContext.js"; +import { + TaskHubsGetOptionalParams, + TaskHubsCreateOrUpdateOptionalParams, + TaskHubsDeleteOptionalParams, + TaskHubsListBySchedulerOptionalParams, +} from "../../api/options.js"; +import { + taskHubsGet, + taskHubsCreateOrUpdate, + taskHubsDelete, + taskHubsListByScheduler, +} from "../../api/taskHubs/index.js"; +import { TaskHub } from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js"; +import { PollerLike, OperationState } from "@azure/core-lro"; + +/** Interface representing a TaskHubs operations. */ +export interface TaskHubsOperations { + /** Get a Task Hub */ + get: ( + resourceGroupName: string, + schedulerName: string, + taskHubName: string, + options?: TaskHubsGetOptionalParams, + ) => Promise; + /** Create or Update a Task Hub */ + createOrUpdate: ( + resourceGroupName: string, + schedulerName: string, + taskHubName: string, + resource: TaskHub, + options?: TaskHubsCreateOrUpdateOptionalParams, + ) => PollerLike, TaskHub>; + /** Delete a Task Hub */ + delete: ( + resourceGroupName: string, + schedulerName: string, + taskHubName: string, + options?: TaskHubsDeleteOptionalParams, + ) => PollerLike, void>; + /** List Task Hubs */ + listByScheduler: ( + resourceGroupName: string, + schedulerName: string, + options?: TaskHubsListBySchedulerOptionalParams, + ) => PagedAsyncIterableIterator; +} + +export function getTaskHubs( + context: DurableTaskContext, + subscriptionId: string, +) { + return { + get: ( + resourceGroupName: string, + schedulerName: string, + taskHubName: string, + options?: TaskHubsGetOptionalParams, + ) => + taskHubsGet( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + options, + ), + createOrUpdate: ( + resourceGroupName: string, + schedulerName: string, + taskHubName: string, + resource: TaskHub, + options?: TaskHubsCreateOrUpdateOptionalParams, + ) => + taskHubsCreateOrUpdate( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + resource, + options, + ), + delete: ( + resourceGroupName: string, + schedulerName: string, + taskHubName: string, + options?: TaskHubsDeleteOptionalParams, + ) => + taskHubsDelete( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + options, + ), + listByScheduler: ( + resourceGroupName: string, + schedulerName: string, + options?: TaskHubsListBySchedulerOptionalParams, + ) => + taskHubsListByScheduler( + context, + subscriptionId, + resourceGroupName, + schedulerName, + options, + ), + }; +} + +export function getTaskHubsOperations( + context: DurableTaskContext, + subscriptionId: string, +): TaskHubsOperations { + return { + ...getTaskHubs(context, subscriptionId), + }; +} diff --git a/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts b/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts new file mode 100644 index 000000000000..5a9162d82ae7 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + getOperationsOperations, + OperationsOperations, +} from "./classic/operations/index.js"; +import { + getSchedulersOperations, + SchedulersOperations, +} from "./classic/schedulers/index.js"; +import { + getTaskHubsOperations, + TaskHubsOperations, +} from "./classic/taskHubs/index.js"; +import { + createDurableTask, + DurableTaskContext, + DurableTaskClientOptionalParams, +} from "./api/index.js"; +import { Pipeline } from "@azure/core-rest-pipeline"; +import { TokenCredential } from "@azure/core-auth"; + +export { DurableTaskClientOptionalParams } from "./api/durableTaskContext.js"; + +export class DurableTaskClient { + private _client: DurableTaskContext; + /** The pipeline used by this client to make requests */ + public readonly pipeline: Pipeline; + + constructor( + credential: TokenCredential, + subscriptionId: string, + options: DurableTaskClientOptionalParams = {}, + ) { + const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; + const userAgentPrefix = prefixFromOptions + ? `${prefixFromOptions} azsdk-js-client` + : `azsdk-js-client`; + this._client = createDurableTask(credential, { + ...options, + userAgentOptions: { userAgentPrefix }, + }); + this.pipeline = this._client.pipeline; + this.operations = getOperationsOperations(this._client); + this.schedulers = getSchedulersOperations(this._client, subscriptionId); + this.taskHubs = getTaskHubsOperations(this._client, subscriptionId); + } + + /** The operation groups for Operations */ + public readonly operations: OperationsOperations; + /** The operation groups for Schedulers */ + public readonly schedulers: SchedulersOperations; + /** The operation groups for TaskHubs */ + public readonly taskHubs: TaskHubsOperations; +} diff --git a/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts b/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts new file mode 100644 index 000000000000..4baaac77c8be --- /dev/null +++ b/sdk/durabletask/arm-durabletask/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/durabletask/arm-durabletask/src/index.ts b/sdk/durabletask/arm-durabletask/src/index.ts new file mode 100644 index 000000000000..f65ae6f98a5c --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/index.ts @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + PageSettings, + ContinuablePage, + PagedAsyncIterableIterator, +} from "./static-helpers/pagingHelpers.js"; + +export { DurableTaskClient } from "./durableTaskClient.js"; +export { restorePoller, RestorePollerOptions } from "./restorePollerHelpers.js"; +export { + TaskHub, + TaskHubProperties, + KnownProvisioningState, + ProvisioningState, + ProxyResource, + Resource, + SystemData, + KnownCreatedByType, + CreatedByType, + Scheduler, + SchedulerProperties, + SchedulerSku, + KnownRedundancyState, + RedundancyState, + TrackedResource, + Operation, + OperationDisplay, + KnownOrigin, + Origin, + KnownActionType, + ActionType, + KnownVersions, +} from "./models/index.js"; +export { + DurableTaskClientOptionalParams, + OperationsListOptionalParams, + SchedulersGetOptionalParams, + SchedulersCreateOrUpdateOptionalParams, + SchedulersUpdateOptionalParams, + SchedulersDeleteOptionalParams, + SchedulersListByResourceGroupOptionalParams, + SchedulersListBySubscriptionOptionalParams, + TaskHubsGetOptionalParams, + TaskHubsCreateOrUpdateOptionalParams, + TaskHubsDeleteOptionalParams, + TaskHubsListBySchedulerOptionalParams, +} from "./api/index.js"; +export { + OperationsOperations, + SchedulersOperations, + TaskHubsOperations, +} from "./classic/index.js"; +export { PageSettings, ContinuablePage, PagedAsyncIterableIterator }; diff --git a/sdk/durabletask/arm-durabletask/src/logger.ts b/sdk/durabletask/arm-durabletask/src/logger.ts new file mode 100644 index 000000000000..786a0c85fb51 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/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-durabletask"); diff --git a/sdk/durabletask/arm-durabletask/src/models/index.ts b/sdk/durabletask/arm-durabletask/src/models/index.ts new file mode 100644 index 000000000000..70737b4b29e0 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/models/index.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +export { + TaskHub, + TaskHubProperties, + KnownProvisioningState, + ProvisioningState, + ProxyResource, + Resource, + SystemData, + KnownCreatedByType, + CreatedByType, + Scheduler, + SchedulerProperties, + SchedulerSku, + KnownRedundancyState, + RedundancyState, + TrackedResource, + Operation, + OperationDisplay, + KnownOrigin, + Origin, + KnownActionType, + ActionType, + KnownVersions, +} from "./models.js"; diff --git a/sdk/durabletask/arm-durabletask/src/models/models.ts b/sdk/durabletask/arm-durabletask/src/models/models.ts new file mode 100644 index 000000000000..218827d9b203 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/models/models.ts @@ -0,0 +1,481 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** A Task Hub resource belonging to the scheduler */ +export interface TaskHub extends ProxyResource { + /** The resource-specific properties for this resource. */ + properties?: TaskHubProperties; +} + +export function taskHubSerializer(item: TaskHub): any { + return { + properties: !item["properties"] + ? item["properties"] + : taskHubPropertiesSerializer(item["properties"]), + }; +} + +export function taskHubDeserializer(item: any): TaskHub { + return { + id: item["id"], + name: item["name"], + type: item["type"], + systemData: !item["systemData"] + ? item["systemData"] + : systemDataDeserializer(item["systemData"]), + properties: !item["properties"] + ? item["properties"] + : taskHubPropertiesDeserializer(item["properties"]), + }; +} + +/** The properties of Task Hub */ +export interface TaskHubProperties { + /** The status of the last operation */ + readonly provisioningState?: ProvisioningState; + /** URL of the durable task scheduler dashboard */ + readonly dashboardUrl?: string; +} + +export function taskHubPropertiesSerializer(item: TaskHubProperties): any { + return item; +} + +export function taskHubPropertiesDeserializer(item: any): TaskHubProperties { + return { + provisioningState: item["provisioningState"], + dashboardUrl: item["dashboardUrl"], + }; +} + +/** The status of the current operation */ +export enum KnownProvisioningState { + /** Resource has been created. */ + Succeeded = "Succeeded", + /** Resource creation failed. */ + Failed = "Failed", + /** Resource creation was canceled. */ + Canceled = "Canceled", + /** The resource is being provisioned */ + Provisioning = "Provisioning", + /** The resource is updating */ + Updating = "Updating", + /** The resource is being deleted */ + Deleting = "Deleting", + /** The resource create request has been accepted */ + Accepted = "Accepted", +} + +/** + * The status of the current operation \ + * {@link KnownProvisioningState} can be used interchangeably with ProvisioningState, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **Succeeded**: Resource has been created. \ + * **Failed**: Resource creation failed. \ + * **Canceled**: Resource creation was canceled. \ + * **Provisioning**: The resource is being provisioned \ + * **Updating**: The resource is updating \ + * **Deleting**: The resource is being deleted \ + * **Accepted**: The resource create request has been accepted + */ +export type ProvisioningState = 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): any { + return item; +} + +export function proxyResourceDeserializer(item: any): ProxyResource { + return { + id: item["id"], + name: item["name"], + type: item["type"], + systemData: !item["systemData"] + ? item["systemData"] + : systemDataDeserializer(item["systemData"]), + }; +} + +/** 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): any { + return item; +} + +export function resourceDeserializer(item: any): Resource { + return { + id: item["id"], + name: item["name"], + type: item["type"], + systemData: !item["systemData"] + ? item["systemData"] + : systemDataDeserializer(item["systemData"]), + }; +} + +/** 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; +} + +export function systemDataDeserializer(item: any): SystemData { + return { + createdBy: item["createdBy"], + createdByType: item["createdByType"], + createdAt: !item["createdAt"] + ? item["createdAt"] + : new Date(item["createdAt"]), + lastModifiedBy: item["lastModifiedBy"], + lastModifiedByType: item["lastModifiedByType"], + lastModifiedAt: !item["lastModifiedAt"] + ? item["lastModifiedAt"] + : new Date(item["lastModifiedAt"]), + }; +} + +/** The kind of entity that created the resource. */ +export enum KnownCreatedByType { + /** The entity was created by a user. */ + User = "User", + /** The entity was created by an application. */ + Application = "Application", + /** The entity was created by a managed identity. */ + ManagedIdentity = "ManagedIdentity", + /** The entity was created by a 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**: The entity was created by a user. \ + * **Application**: The entity was created by an application. \ + * **ManagedIdentity**: The entity was created by a managed identity. \ + * **Key**: The entity was created by a key. + */ +export type CreatedByType = string; + +/** The response of a TaskHub list operation. */ +export interface _TaskHubListResult { + /** The TaskHub items on this page */ + value: TaskHub[]; + /** The link to the next page of items */ + nextLink?: string; +} + +export function _taskHubListResultDeserializer(item: any): _TaskHubListResult { + return { + value: taskHubArrayDeserializer(item["value"]), + nextLink: item["nextLink"], + }; +} + +export function taskHubArraySerializer(result: Array): any[] { + return result.map((item) => { + return taskHubSerializer(item); + }); +} + +export function taskHubArrayDeserializer(result: Array): any[] { + return result.map((item) => { + return taskHubDeserializer(item); + }); +} + +/** A Durable Task Scheduler resource */ +export interface Scheduler extends TrackedResource { + /** The resource-specific properties for this resource. */ + properties?: SchedulerProperties; +} + +export function schedulerSerializer(item: Scheduler): any { + return { + tags: item["tags"], + location: item["location"], + properties: !item["properties"] + ? item["properties"] + : schedulerPropertiesSerializer(item["properties"]), + }; +} + +export function schedulerDeserializer(item: any): Scheduler { + return { + tags: item["tags"], + location: item["location"], + id: item["id"], + name: item["name"], + type: item["type"], + systemData: !item["systemData"] + ? item["systemData"] + : systemDataDeserializer(item["systemData"]), + properties: !item["properties"] + ? item["properties"] + : schedulerPropertiesDeserializer(item["properties"]), + }; +} + +/** Details of the Scheduler */ +export interface SchedulerProperties { + /** The status of the last operation */ + readonly provisioningState?: ProvisioningState; + /** URL of the durable task scheduler */ + readonly endpoint?: string; + /** IP allow list for durable task scheduler. Values can be IPv4, IPv6 or CIDR */ + ipAllowlist: string[]; + /** SKU of the durable task scheduler */ + sku: SchedulerSku; +} + +export function schedulerPropertiesSerializer(item: SchedulerProperties): any { + return { + ipAllowlist: item["ipAllowlist"].map((p: any) => { + return p; + }), + sku: schedulerSkuSerializer(item["sku"]), + }; +} + +export function schedulerPropertiesDeserializer( + item: any, +): SchedulerProperties { + return { + provisioningState: item["provisioningState"], + endpoint: item["endpoint"], + ipAllowlist: item["ipAllowlist"].map((p: any) => { + return p; + }), + sku: schedulerSkuDeserializer(item["sku"]), + }; +} + +/** The SKU (Stock Keeping Unit) assigned to this durable task scheduler */ +export interface SchedulerSku { + /** The name of the SKU */ + name: string; + /** The SKU capacity. This allows scale out/in for the resource and impacts zone redundancy */ + capacity?: number; + /** Indicates whether the current SKU configuration is zone redundant */ + readonly redundancyState?: RedundancyState; +} + +export function schedulerSkuSerializer(item: SchedulerSku): any { + return { name: item["name"], capacity: item["capacity"] }; +} + +export function schedulerSkuDeserializer(item: any): SchedulerSku { + return { + name: item["name"], + capacity: item["capacity"], + redundancyState: item["redundancyState"], + }; +} + +/** The state of the resource redundancy */ +export enum KnownRedundancyState { + /** The resource is not redundant */ + None = "None", + /** The resource is zone redundant */ + Zone = "Zone", +} + +/** + * The state of the resource redundancy \ + * {@link KnownRedundancyState} can be used interchangeably with RedundancyState, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **None**: The resource is not redundant \ + * **Zone**: The resource is zone redundant + */ +export type RedundancyState = 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): any { + return { tags: item["tags"], location: item["location"] }; +} + +export function trackedResourceDeserializer(item: any): TrackedResource { + return { + id: item["id"], + name: item["name"], + type: item["type"], + systemData: !item["systemData"] + ? item["systemData"] + : systemDataDeserializer(item["systemData"]), + tags: item["tags"], + location: item["location"], + }; +} + +/** The response of a Scheduler list operation. */ +export interface _SchedulerListResult { + /** The Scheduler items on this page */ + value: Scheduler[]; + /** The link to the next page of items */ + nextLink?: string; +} + +export function _schedulerListResultDeserializer( + item: any, +): _SchedulerListResult { + return { + value: schedulerArrayDeserializer(item["value"]), + nextLink: item["nextLink"], + }; +} + +export function schedulerArraySerializer(result: Array): any[] { + return result.map((item) => { + return schedulerSerializer(item); + }); +} + +export function schedulerArrayDeserializer(result: Array): any[] { + return result.map((item) => { + return schedulerDeserializer(item); + }); +} + +/** 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; +} + +export function _operationListResultDeserializer( + item: any, +): _OperationListResult { + return { + value: operationArrayDeserializer(item["value"]), + nextLink: item["nextLink"], + }; +} + +export function operationArrayDeserializer(result: Array): any[] { + return result.map((item) => { + return operationDeserializer(item); + }); +} + +/** 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. */ + 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. */ + readonly actionType?: ActionType; +} + +export function operationDeserializer(item: any): Operation { + return { + name: item["name"], + isDataAction: item["isDataAction"], + display: !item["display"] + ? item["display"] + : operationDisplayDeserializer(item["display"]), + origin: item["origin"], + actionType: item["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; +} + +export function operationDisplayDeserializer(item: any): OperationDisplay { + return { + provider: item["provider"], + resource: item["resource"], + operation: item["operation"], + description: item["description"], + }; +} + +/** The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system" */ +export enum KnownOrigin { + /** Indicates the operation is initiated by a user. */ + user = "user", + /** Indicates the operation is initiated by a system. */ + system = "system", + /** Indicates the operation is initiated by a user or 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**: Indicates the operation is initiated by a user. \ + * **system**: Indicates the operation is initiated by a system. \ + * **user,system**: Indicates the operation is initiated by a user or system. + */ +export type Origin = string; + +/** Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. */ +export enum KnownActionType { + /** Actions are for internal-only APIs. */ + 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**: Actions are for internal-only APIs. + */ +export type ActionType = string; + +/** API Versions */ +export enum KnownVersions { + /** 2024-10-01-preview */ + v2024_10_01_Preview = "2024-10-01-preview", +} diff --git a/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts b/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts new file mode 100644 index 000000000000..bd87a7ea5a56 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts @@ -0,0 +1,194 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { DurableTaskClient } from "./durableTaskClient.js"; +import { + _schedulersCreateOrUpdateDeserialize, + _schedulersUpdateDeserialize, + _schedulersDeleteDeserialize, +} from "./api/schedulers/index.js"; +import { + _taskHubsCreateOrUpdateDeserialize, + _taskHubsDeleteDeserialize, +} from "./api/taskHubs/index.js"; +import { getLongRunningPoller } from "./static-helpers/pollingHelpers.js"; +import { + OperationOptions, + PathUncheckedResponse, +} from "@azure-rest/core-client"; +import { AbortSignalLike } from "@azure/abort-controller"; +import { + PollerLike, + OperationState, + deserializeState, + ResourceLocationConfig, +} from "@azure/core-lro"; + +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: DurableTaskClient, + 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 { deserializer, expectedStatuses = [] } = + getDeserializationHelper(initialRequestUrl, requestMethod) ?? {}; + const deserializeHelper = options?.processResponseBody ?? deserializer; + 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, + expectedStatuses, + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + resourceLocationConfig, + restoreFrom: serializedState, + initialRequestUrl, + }, + ); +} + +interface DeserializationHelper { + deserializer: Function; + expectedStatuses: string[]; +} + +const deserializeMap: Record = { + "PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}": + { + deserializer: _schedulersCreateOrUpdateDeserialize, + expectedStatuses: ["200", "201"], + }, + "PATCH /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}": + { + deserializer: _schedulersUpdateDeserialize, + expectedStatuses: ["200", "202"], + }, + "DELETE /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}": + { + deserializer: _schedulersDeleteDeserialize, + expectedStatuses: ["202", "204", "200"], + }, + "PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/taskHubs/{taskHubName}": + { + deserializer: _taskHubsCreateOrUpdateDeserialize, + expectedStatuses: ["200", "201"], + }, + "DELETE /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/taskHubs/{taskHubName}": + { + deserializer: _taskHubsDeleteDeserialize, + expectedStatuses: ["202", "204", "200"], + }, +}; + +function getDeserializationHelper( + urlStr: string, + method: string, +): DeserializationHelper | 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: DeserializationHelper | 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; + } + } + + return matchedValue; +} + +function getPathFromMapKey(mapKey: string): string { + const pathStart = mapKey.indexOf("/"); + return mapKey.slice(pathStart); +} diff --git a/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts b/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts new file mode 100644 index 000000000000..97a81e74e301 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts @@ -0,0 +1,274 @@ +// 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"; + +/** + * 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; +} + +/** + * 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, + expectedStatuses: string[], + 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, expectedStatuses); + 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, + expectedStatuses: string[], +): void { + if (!expectedStatuses.includes(response.status)) { + throw createRestError( + `Pagination failed with unexpected statusCode ${response.status}`, + response, + ); + } +} diff --git a/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts b/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts new file mode 100644 index 000000000000..2edbf783be53 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts @@ -0,0 +1,137 @@ +// 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"; + +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, + expectedStatuses: string[], + 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, expectedStatuses); + }, + 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); + } + + return getLroResponse(response as TResponse, expectedStatuses); + }, + }; + 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, + expectedStatuses: string[], +): OperationResponse { + if (!expectedStatuses.includes(response.status)) { + throw createRestError(response); + } + + return { + flatResponse: response, + rawResponse: { + ...response, + statusCode: Number.parseInt(response.status), + body: response.body, + }, + }; +} diff --git a/sdk/durabletask/arm-durabletask/test/public/sampleTest.spec.ts b/sdk/durabletask/arm-durabletask/test/public/sampleTest.spec.ts new file mode 100644 index 000000000000..d4919ac91ac5 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/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/durabletask/arm-durabletask/test/public/utils/recordedClient.ts b/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts new file mode 100644 index 000000000000..6e425fdcfdf9 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/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/durabletask/arm-durabletask/tsconfig.browser.config.json b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json new file mode 100644 index 000000000000..091177fcb991 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/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/durabletask/arm-durabletask/tsconfig.json b/sdk/durabletask/arm-durabletask/tsconfig.json new file mode 100644 index 000000000000..8fb7482359c3 --- /dev/null +++ b/sdk/durabletask/arm-durabletask/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "../../../tsconfig", + "compilerOptions": { + "module": "NodeNext", + "moduleResolution": "NodeNext", + "rootDir": ".", + "skipLibCheck": true + }, + "include": [ + "src/**/*.ts", + "src/**/*.mts", + "src/**/*.cts", + "samples-dev/**/*.ts", + "test/**/*.ts", + "test/**/*.mts", + "test/**/*.cts" + ] +} diff --git a/sdk/durabletask/arm-durabletask/tsp-location.yaml b/sdk/durabletask/arm-durabletask/tsp-location.yaml new file mode 100644 index 000000000000..0a138597b29f --- /dev/null +++ b/sdk/durabletask/arm-durabletask/tsp-location.yaml @@ -0,0 +1,4 @@ +directory: specification/durabletask/DurableTask.Management +commit: 222222 +repo: ../fork-azure-rest-api-specs +additionalDirectories: diff --git a/sdk/durabletask/arm-durabletask/vitest.browser.config.ts b/sdk/durabletask/arm-durabletask/vitest.browser.config.ts new file mode 100644 index 000000000000..da68c1d231aa --- /dev/null +++ b/sdk/durabletask/arm-durabletask/vitest.browser.config.ts @@ -0,0 +1,38 @@ +// 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, + hookTimeout: 1200000, + }, +}); diff --git a/sdk/durabletask/arm-durabletask/vitest.config.ts b/sdk/durabletask/arm-durabletask/vitest.config.ts new file mode 100644 index 000000000000..2cf5d0e02c2e --- /dev/null +++ b/sdk/durabletask/arm-durabletask/vitest.config.ts @@ -0,0 +1,34 @@ +// 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, + hookTimeout: 1200000, + }, +}); From 33f43d4e0592e41c3ba1667bcd2210a7ce224f03 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 05:48:38 +0800 Subject: [PATCH 03/34] Migration: Update test config --- .../tsconfig.browser.config.json | 11 ++++- .../arm-durabletask/vitest.browser.config.ts | 45 +++++-------------- .../arm-durabletask/vitest.config.ts | 39 +++++----------- 3 files changed, 31 insertions(+), 64 deletions(-) diff --git a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json index 091177fcb991..b6586181d006 100644 --- a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json +++ b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json @@ -1,7 +1,14 @@ { "extends": "./.tshy/build.json", - "include": ["src/**/*.ts", "src/**/*.mts", "test/**/*.spec.ts"], - "exclude": ["test/**/node/**/*.ts"], + "include": [ + "./src/**/*.ts", + "./src/**/*.mts", + "./test/**/*.spec.ts", + "./test/**/*.mts" + ], + "exclude": [ + "./test/**/node/**/*.ts" + ], "compilerOptions": { "outDir": "./dist-test/browser", "rootDir": ".", diff --git a/sdk/durabletask/arm-durabletask/vitest.browser.config.ts b/sdk/durabletask/arm-durabletask/vitest.browser.config.ts index da68c1d231aa..b48c61b2ef46 100644 --- a/sdk/durabletask/arm-durabletask/vitest.browser.config.ts +++ b/sdk/durabletask/arm-durabletask/vitest.browser.config.ts @@ -1,38 +1,17 @@ + // 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(); +import { defineConfig, mergeConfig } from "vitest/config"; +import viteConfig from "../../../vitest.browser.shared.config.ts"; -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", +export default mergeConfig( + viteConfig, + defineConfig({ + test: { + include: [ + "dist-test/browser/test/**/*.spec.js", + ], }, - testTimeout: 1200000, - hookTimeout: 1200000, - }, -}); + }), +); diff --git a/sdk/durabletask/arm-durabletask/vitest.config.ts b/sdk/durabletask/arm-durabletask/vitest.config.ts index 2cf5d0e02c2e..39267dd2f56f 100644 --- a/sdk/durabletask/arm-durabletask/vitest.config.ts +++ b/sdk/durabletask/arm-durabletask/vitest.config.ts @@ -1,34 +1,15 @@ + // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { defineConfig } from "vitest/config"; -import { relativeRecordingsPath } from "@azure-tools/test-recorder"; +import { defineConfig, mergeConfig } from "vitest/config"; +import viteConfig from "../../../vitest.shared.config.ts"; -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", +export default mergeConfig( + viteConfig, + defineConfig({ + test: { + include: ["test/**/*.spec.ts"], }, - testTimeout: 1200000, - hookTimeout: 1200000, - }, -}); + }), +); From f789bb9e7e3ffa6a02f2e8e7dd37a8d34a6095ca Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 05:48:39 +0800 Subject: [PATCH 04/34] Migration: Clean up files From fbd624b98df7519d5c051ad110838d1b7ae62dbd Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 05:48:41 +0800 Subject: [PATCH 05/34] Migration: Apply codemod: "fixSourceFile" From 9cf56211254c4cf78e7ff17d8706d581fc74fe18 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 05:48:42 +0800 Subject: [PATCH 06/34] Migration: Apply codemod: "fixTestingImports" From 20190d41fe1f3d7abd7b0027be4955ddd6ed9740 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 05:48:43 +0800 Subject: [PATCH 07/34] Migration: Apply codemod: "replaceAssertIsRejected" From 500b70279e13abd4d59145837bb1cd1dc7948734 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 05:48:52 +0800 Subject: [PATCH 08/34] Migration: Apply codemod: "replaceSinonStub" From aada7693abecb2edf0719e96d18ac6d1bf0c673d Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 05:48:55 +0800 Subject: [PATCH 09/34] Migration: Apply codemod: "addViHelper" From 293f6df23e9079e2f88609284026f2eadd490f93 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 05:48:57 +0800 Subject: [PATCH 10/34] Migration: Apply codemod: "replaceSupportTracing" From 9fefe1c10082f79c050cf85e375c9bd741b069f9 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 05:49:01 +0800 Subject: [PATCH 11/34] Migration: Apply codemod: "replaceTestUtils" From 30c6147688d2aa639adf940d01071366e63d150c Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 05:49:06 +0800 Subject: [PATCH 12/34] Migration: rushx format --- .../arm-durabletask/eslint.config.mjs | 6 +- .../src/api/durableTaskContext.ts | 3 +- .../src/api/operations/index.ts | 5 +- .../arm-durabletask/src/api/options.ts | 12 +- .../src/api/schedulers/index.ts | 107 +++++++----------- .../arm-durabletask/src/api/taskHubs/index.ts | 76 +++++-------- .../src/classic/operations/index.ts | 11 +- .../src/classic/schedulers/index.ts | 36 +----- .../src/classic/taskHubs/index.ts | 22 +--- .../arm-durabletask/src/durableTaskClient.ts | 15 +-- .../src/helpers/serializerHelpers.ts | 12 +- sdk/durabletask/arm-durabletask/src/index.ts | 6 +- .../arm-durabletask/src/models/models.ts | 20 +--- .../src/restorePollerHelpers.ts | 26 ++--- .../src/static-helpers/pagingHelpers.ts | 55 ++------- .../src/static-helpers/pollingHelpers.ts | 19 +--- .../test/public/utils/recordedClient.ts | 10 +- .../tsconfig.browser.config.json | 11 +- 18 files changed, 129 insertions(+), 323 deletions(-) diff --git a/sdk/durabletask/arm-durabletask/eslint.config.mjs b/sdk/durabletask/arm-durabletask/eslint.config.mjs index 113bdc3eaf5f..03244d34a19f 100644 --- a/sdk/durabletask/arm-durabletask/eslint.config.mjs +++ b/sdk/durabletask/arm-durabletask/eslint.config.mjs @@ -11,7 +11,7 @@ export default [ "@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", - "tsdoc/syntax": "warn" - } - } + "tsdoc/syntax": "warn", + }, + }, ]; diff --git a/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts b/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts index 63aa3c0cf662..6264f4426c62 100644 --- a/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts +++ b/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts @@ -19,8 +19,7 @@ export function createDurableTask( credential: TokenCredential, options: DurableTaskClientOptionalParams = {}, ): DurableTaskContext { - const endpointUrl = - options.endpoint ?? options.baseUrl ?? `https://management.azure.com`; + const endpointUrl = options.endpoint ?? options.baseUrl ?? `https://management.azure.com`; const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; const userAgentInfo = `azsdk-js-arm-durabletask/1.0.0-beta.1`; const userAgentPrefix = prefixFromOptions diff --git a/sdk/durabletask/arm-durabletask/src/api/operations/index.ts b/sdk/durabletask/arm-durabletask/src/api/operations/index.ts index 86ac95ed3ee3..df4776cc68a6 100644 --- a/sdk/durabletask/arm-durabletask/src/api/operations/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/operations/index.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { - DurableTaskContext as Client, - OperationsListOptionalParams, -} from "../index.js"; +import { DurableTaskContext as Client, OperationsListOptionalParams } from "../index.js"; import { _OperationListResult, _operationListResultDeserializer, diff --git a/sdk/durabletask/arm-durabletask/src/api/options.ts b/sdk/durabletask/arm-durabletask/src/api/options.ts index 9a33e997e7d9..020039568e34 100644 --- a/sdk/durabletask/arm-durabletask/src/api/options.ts +++ b/sdk/durabletask/arm-durabletask/src/api/options.ts @@ -10,8 +10,7 @@ export interface OperationsListOptionalParams extends OperationOptions {} export interface SchedulersGetOptionalParams extends OperationOptions {} /** Optional parameters. */ -export interface SchedulersCreateOrUpdateOptionalParams - extends OperationOptions { +export interface SchedulersCreateOrUpdateOptionalParams extends OperationOptions { /** Delay to wait until next poll, in milliseconds. */ updateIntervalInMs?: number; } @@ -29,12 +28,10 @@ export interface SchedulersDeleteOptionalParams extends OperationOptions { } /** Optional parameters. */ -export interface SchedulersListByResourceGroupOptionalParams - extends OperationOptions {} +export interface SchedulersListByResourceGroupOptionalParams extends OperationOptions {} /** Optional parameters. */ -export interface SchedulersListBySubscriptionOptionalParams - extends OperationOptions {} +export interface SchedulersListBySubscriptionOptionalParams extends OperationOptions {} /** Optional parameters. */ export interface TaskHubsGetOptionalParams extends OperationOptions {} @@ -52,5 +49,4 @@ export interface TaskHubsDeleteOptionalParams extends OperationOptions { } /** Optional parameters. */ -export interface TaskHubsListBySchedulerOptionalParams - extends OperationOptions {} +export interface TaskHubsListBySchedulerOptionalParams extends OperationOptions {} diff --git a/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts b/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts index 8d6c144fb0bb..8ed4dae3bf09 100644 --- a/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts @@ -47,9 +47,7 @@ export function _schedulersGetSend( .get({ ...operationOptionsToRequestParameters(options) }); } -export async function _schedulersGetDeserialize( - result: PathUncheckedResponse, -): Promise { +export async function _schedulersGetDeserialize(result: PathUncheckedResponse): Promise { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -117,25 +115,20 @@ export function schedulersCreateOrUpdate( resource: Scheduler, options: SchedulersCreateOrUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, Scheduler> { - return getLongRunningPoller( - context, - _schedulersCreateOrUpdateDeserialize, - ["200", "201"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersCreateOrUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - resource, - options, - ), - resourceLocationConfig: "azure-async-operation", - }, - ) as PollerLike, Scheduler>; + return getLongRunningPoller(context, _schedulersCreateOrUpdateDeserialize, ["200", "201"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersCreateOrUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }) as PollerLike, Scheduler>; } export function _schedulersUpdateSend( @@ -179,25 +172,20 @@ export function schedulersUpdate( properties: Scheduler, options: SchedulersUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, Scheduler> { - return getLongRunningPoller( - context, - _schedulersUpdateDeserialize, - ["200", "202"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - properties, - options, - ), - resourceLocationConfig: "location", - }, - ) as PollerLike, Scheduler>; + return getLongRunningPoller(context, _schedulersUpdateDeserialize, ["200", "202"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + properties, + options, + ), + resourceLocationConfig: "location", + }) as PollerLike, Scheduler>; } export function _schedulersDeleteSend( @@ -217,9 +205,7 @@ export function _schedulersDeleteSend( .delete({ ...operationOptionsToRequestParameters(options) }); } -export async function _schedulersDeleteDeserialize( - result: PathUncheckedResponse, -): Promise { +export async function _schedulersDeleteDeserialize(result: PathUncheckedResponse): Promise { const expectedStatuses = ["202", "204", "200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -236,24 +222,13 @@ export function schedulersDelete( schedulerName: string, options: SchedulersDeleteOptionalParams = { requestOptions: {} }, ): PollerLike, void> { - return getLongRunningPoller( - context, - _schedulersDeleteDeserialize, - ["202", "204", "200"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersDeleteSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - options, - ), - resourceLocationConfig: "location", - }, - ) as PollerLike, void>; + return getLongRunningPoller(context, _schedulersDeleteDeserialize, ["202", "204", "200"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersDeleteSend(context, subscriptionId, resourceGroupName, schedulerName, options), + resourceLocationConfig: "location", + }) as PollerLike, void>; } export function _schedulersListByResourceGroupSend( @@ -291,13 +266,7 @@ export function schedulersListByResourceGroup( ): PagedAsyncIterableIterator { return buildPagedAsyncIterator( context, - () => - _schedulersListByResourceGroupSend( - context, - subscriptionId, - resourceGroupName, - options, - ), + () => _schedulersListByResourceGroupSend(context, subscriptionId, resourceGroupName, options), _schedulersListByResourceGroupDeserialize, ["200"], { itemName: "value", nextLinkName: "nextLink" }, diff --git a/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts b/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts index 0b611635617f..33eea18f9c3a 100644 --- a/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts @@ -47,9 +47,7 @@ export function _taskHubsGetSend( .get({ ...operationOptionsToRequestParameters(options) }); } -export async function _taskHubsGetDeserialize( - result: PathUncheckedResponse, -): Promise { +export async function _taskHubsGetDeserialize(result: PathUncheckedResponse): Promise { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -122,26 +120,21 @@ export function taskHubsCreateOrUpdate( resource: TaskHub, options: TaskHubsCreateOrUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, TaskHub> { - return getLongRunningPoller( - context, - _taskHubsCreateOrUpdateDeserialize, - ["200", "201"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _taskHubsCreateOrUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - taskHubName, - resource, - options, - ), - resourceLocationConfig: "azure-async-operation", - }, - ) as PollerLike, TaskHub>; + return getLongRunningPoller(context, _taskHubsCreateOrUpdateDeserialize, ["200", "201"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _taskHubsCreateOrUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }) as PollerLike, TaskHub>; } export function _taskHubsDeleteSend( @@ -163,9 +156,7 @@ export function _taskHubsDeleteSend( .delete({ ...operationOptionsToRequestParameters(options) }); } -export async function _taskHubsDeleteDeserialize( - result: PathUncheckedResponse, -): Promise { +export async function _taskHubsDeleteDeserialize(result: PathUncheckedResponse): Promise { const expectedStatuses = ["202", "204", "200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -183,25 +174,20 @@ export function taskHubsDelete( taskHubName: string, options: TaskHubsDeleteOptionalParams = { requestOptions: {} }, ): PollerLike, void> { - return getLongRunningPoller( - context, - _taskHubsDeleteDeserialize, - ["202", "204", "200"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _taskHubsDeleteSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - taskHubName, - options, - ), - resourceLocationConfig: "location", - }, - ) as PollerLike, void>; + return getLongRunningPoller(context, _taskHubsDeleteDeserialize, ["202", "204", "200"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _taskHubsDeleteSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + options, + ), + resourceLocationConfig: "location", + }) as PollerLike, void>; } export function _taskHubsListBySchedulerSend( diff --git a/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts b/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts index 467b1c1a9525..d51dbb4797cc 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts @@ -10,21 +10,16 @@ import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.j /** Interface representing a Operations operations. */ export interface OperationsOperations { /** List the operations for the provider */ - list: ( - options?: OperationsListOptionalParams, - ) => PagedAsyncIterableIterator; + list: (options?: OperationsListOptionalParams) => PagedAsyncIterableIterator; } export function getOperations(context: DurableTaskContext) { return { - list: (options?: OperationsListOptionalParams) => - operationsList(context, options), + list: (options?: OperationsListOptionalParams) => operationsList(context, options), }; } -export function getOperationsOperations( - context: DurableTaskContext, -): OperationsOperations { +export function getOperationsOperations(context: DurableTaskContext): OperationsOperations { return { ...getOperations(context), }; diff --git a/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts b/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts index 9277a16c2ea0..a5a5ed3c5e6f 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts @@ -61,23 +61,13 @@ export interface SchedulersOperations { ) => PagedAsyncIterableIterator; } -export function getSchedulers( - context: DurableTaskContext, - subscriptionId: string, -) { +export function getSchedulers(context: DurableTaskContext, subscriptionId: string) { return { get: ( resourceGroupName: string, schedulerName: string, options?: SchedulersGetOptionalParams, - ) => - schedulersGet( - context, - subscriptionId, - resourceGroupName, - schedulerName, - options, - ), + ) => schedulersGet(context, subscriptionId, resourceGroupName, schedulerName, options), createOrUpdate: ( resourceGroupName: string, schedulerName: string, @@ -110,27 +100,13 @@ export function getSchedulers( resourceGroupName: string, schedulerName: string, options?: SchedulersDeleteOptionalParams, - ) => - schedulersDelete( - context, - subscriptionId, - resourceGroupName, - schedulerName, - options, - ), + ) => schedulersDelete(context, subscriptionId, resourceGroupName, schedulerName, options), listByResourceGroup: ( resourceGroupName: string, options?: SchedulersListByResourceGroupOptionalParams, - ) => - schedulersListByResourceGroup( - context, - subscriptionId, - resourceGroupName, - options, - ), - listBySubscription: ( - options?: SchedulersListBySubscriptionOptionalParams, - ) => schedulersListBySubscription(context, subscriptionId, options), + ) => schedulersListByResourceGroup(context, subscriptionId, resourceGroupName, options), + listBySubscription: (options?: SchedulersListBySubscriptionOptionalParams) => + schedulersListBySubscription(context, subscriptionId, options), }; } diff --git a/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts b/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts index d020a2d3c910..18af9249c1df 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts @@ -50,10 +50,7 @@ export interface TaskHubsOperations { ) => PagedAsyncIterableIterator; } -export function getTaskHubs( - context: DurableTaskContext, - subscriptionId: string, -) { +export function getTaskHubs(context: DurableTaskContext, subscriptionId: string) { return { get: ( resourceGroupName: string, @@ -61,14 +58,7 @@ export function getTaskHubs( taskHubName: string, options?: TaskHubsGetOptionalParams, ) => - taskHubsGet( - context, - subscriptionId, - resourceGroupName, - schedulerName, - taskHubName, - options, - ), + taskHubsGet(context, subscriptionId, resourceGroupName, schedulerName, taskHubName, options), createOrUpdate: ( resourceGroupName: string, schedulerName: string, @@ -104,13 +94,7 @@ export function getTaskHubs( schedulerName: string, options?: TaskHubsListBySchedulerOptionalParams, ) => - taskHubsListByScheduler( - context, - subscriptionId, - resourceGroupName, - schedulerName, - options, - ), + taskHubsListByScheduler(context, subscriptionId, resourceGroupName, schedulerName, options), }; } diff --git a/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts b/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts index 5a9162d82ae7..b1609ecd6d1d 100644 --- a/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts +++ b/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts @@ -1,18 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { - getOperationsOperations, - OperationsOperations, -} from "./classic/operations/index.js"; -import { - getSchedulersOperations, - SchedulersOperations, -} from "./classic/schedulers/index.js"; -import { - getTaskHubsOperations, - TaskHubsOperations, -} from "./classic/taskHubs/index.js"; +import { getOperationsOperations, OperationsOperations } from "./classic/operations/index.js"; +import { getSchedulersOperations, SchedulersOperations } from "./classic/schedulers/index.js"; +import { getTaskHubsOperations, TaskHubsOperations } from "./classic/taskHubs/index.js"; import { createDurableTask, DurableTaskContext, diff --git a/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts b/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts index 4baaac77c8be..7518a16c2ee9 100644 --- a/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts @@ -1,10 +1,9 @@ // 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, +): Record; export function serializeRecord( item: Record, serializer: (item: T) => R, @@ -33,8 +32,5 @@ export function serializeRecord( } function isSupportedRecordType(t: any) { - return ( - ["number", "string", "boolean", "null"].includes(typeof t) || - t instanceof Date - ); + return ["number", "string", "boolean", "null"].includes(typeof t) || t instanceof Date; } diff --git a/sdk/durabletask/arm-durabletask/src/index.ts b/sdk/durabletask/arm-durabletask/src/index.ts index f65ae6f98a5c..39e01d18fddf 100644 --- a/sdk/durabletask/arm-durabletask/src/index.ts +++ b/sdk/durabletask/arm-durabletask/src/index.ts @@ -47,9 +47,5 @@ export { TaskHubsDeleteOptionalParams, TaskHubsListBySchedulerOptionalParams, } from "./api/index.js"; -export { - OperationsOperations, - SchedulersOperations, - TaskHubsOperations, -} from "./classic/index.js"; +export { OperationsOperations, SchedulersOperations, TaskHubsOperations } from "./classic/index.js"; export { PageSettings, ContinuablePage, PagedAsyncIterableIterator }; diff --git a/sdk/durabletask/arm-durabletask/src/models/models.ts b/sdk/durabletask/arm-durabletask/src/models/models.ts index 218827d9b203..36e590f6ffb8 100644 --- a/sdk/durabletask/arm-durabletask/src/models/models.ts +++ b/sdk/durabletask/arm-durabletask/src/models/models.ts @@ -146,9 +146,7 @@ export function systemDataDeserializer(item: any): SystemData { return { createdBy: item["createdBy"], createdByType: item["createdByType"], - createdAt: !item["createdAt"] - ? item["createdAt"] - : new Date(item["createdAt"]), + createdAt: !item["createdAt"] ? item["createdAt"] : new Date(item["createdAt"]), lastModifiedBy: item["lastModifiedBy"], lastModifiedByType: item["lastModifiedByType"], lastModifiedAt: !item["lastModifiedAt"] @@ -261,9 +259,7 @@ export function schedulerPropertiesSerializer(item: SchedulerProperties): any { }; } -export function schedulerPropertiesDeserializer( - item: any, -): SchedulerProperties { +export function schedulerPropertiesDeserializer(item: any): SchedulerProperties { return { provisioningState: item["provisioningState"], endpoint: item["endpoint"], @@ -347,9 +343,7 @@ export interface _SchedulerListResult { nextLink?: string; } -export function _schedulerListResultDeserializer( - item: any, -): _SchedulerListResult { +export function _schedulerListResultDeserializer(item: any): _SchedulerListResult { return { value: schedulerArrayDeserializer(item["value"]), nextLink: item["nextLink"], @@ -376,9 +370,7 @@ export interface _OperationListResult { nextLink?: string; } -export function _operationListResultDeserializer( - item: any, -): _OperationListResult { +export function _operationListResultDeserializer(item: any): _OperationListResult { return { value: operationArrayDeserializer(item["value"]), nextLink: item["nextLink"], @@ -409,9 +401,7 @@ export function operationDeserializer(item: any): Operation { return { name: item["name"], isDataAction: item["isDataAction"], - display: !item["display"] - ? item["display"] - : operationDisplayDeserializer(item["display"]), + display: !item["display"] ? item["display"] : operationDisplayDeserializer(item["display"]), origin: item["origin"], actionType: item["actionType"], }; diff --git a/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts b/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts index bd87a7ea5a56..3a03060f5586 100644 --- a/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts @@ -12,10 +12,7 @@ import { _taskHubsDeleteDeserialize, } from "./api/taskHubs/index.js"; import { getLongRunningPoller } from "./static-helpers/pollingHelpers.js"; -import { - OperationOptions, - PathUncheckedResponse, -} from "@azure-rest/core-client"; +import { OperationOptions, PathUncheckedResponse } from "@azure-rest/core-client"; import { AbortSignalLike } from "@azure/abort-controller"; import { PollerLike, @@ -46,9 +43,7 @@ export interface RestorePollerOptions< export function restorePoller( client: DurableTaskClient, serializedState: string, - sourceOperation: ( - ...args: any[] - ) => PollerLike, TResult>, + sourceOperation: (...args: any[]) => PollerLike, TResult>, options?: RestorePollerOptions, ): PollerLike, TResult> { const pollerConfig = deserializeState(serializedState).config; @@ -142,24 +137,17 @@ function getDeserializationHelper( // 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 - ) { + 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] || ""); + const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test( + pathParts[j] || "", + ); if (!isMatched) { found = false; diff --git a/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts b/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts index 97a81e74e301..ce33af5f4178 100644 --- a/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { - Client, - createRestError, - PathUncheckedResponse, -} from "@azure-rest/core-client"; +import { Client, createRestError, PathUncheckedResponse } from "@azure-rest/core-client"; import { RestError } from "@azure/core-rest-pipeline"; /** @@ -43,17 +39,11 @@ export interface PagedAsyncIterableIterator< /** * The connection to the async iterator, part of the iteration protocol */ - [Symbol.asyncIterator](): PagedAsyncIterableIterator< - TElement, - TPage, - TPageSettings - >; + [Symbol.asyncIterator](): PagedAsyncIterableIterator; /** * Return an AsyncIterableIterator that works a page at a time */ - byPage: ( - settings?: TPageSettings, - ) => AsyncIterableIterator>; + byPage: (settings?: TPageSettings) => AsyncIterableIterator>; } /** @@ -71,15 +61,11 @@ export interface PagedResult< /** * A method that returns a page of results. */ - getPage: ( - pageLink?: string, - ) => Promise<{ page: TPage; nextPageLink?: string } | undefined>; + 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>; + byPage?: (settings?: TPageSettings) => AsyncIterableIterator>; /** * A function to extract elements from a page. @@ -152,9 +138,7 @@ function getPagedAsyncIterator< >( pagedResult: PagedResult, ): PagedAsyncIterableIterator { - const iter = getItemAsyncIterator( - pagedResult, - ); + const iter = getItemAsyncIterator(pagedResult); return { next() { return iter.next(); @@ -173,11 +157,7 @@ function getPagedAsyncIterator< }; } -async function* getItemAsyncIterator< - TElement, - TPage, - TPageSettings extends PageSettings, ->( +async function* getItemAsyncIterator( pagedResult: PagedResult, ): AsyncIterableIterator { const pages = getPageAsyncIterator(pagedResult); @@ -186,20 +166,14 @@ async function* getItemAsyncIterator< } } -async function* getPageAsyncIterator< - TElement, - TPage, - TPageSettings extends PageSettings, ->( +async function* getPageAsyncIterator( pagedResult: PagedResult, options: { pageLink?: string; } = {}, ): AsyncIterableIterator> { const { pageLink } = options; - let response = await pagedResult.getPage( - pageLink ?? pagedResult.firstPageLink, - ); + let response = await pagedResult.getPage(pageLink ?? pagedResult.firstPageLink); if (!response) { return; } @@ -227,11 +201,7 @@ function getNextLink(body: unknown, nextLinkName?: string): string | undefined { const nextLink = (body as Record)[nextLinkName]; - if ( - typeof nextLink !== "string" && - typeof nextLink !== "undefined" && - nextLink !== null - ) { + 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}`, ); @@ -261,10 +231,7 @@ function getElements(body: unknown, itemName: string): T[] { /** * Checks if a request failed */ -function checkPagingRequest( - response: PathUncheckedResponse, - expectedStatuses: string[], -): void { +function checkPagingRequest(response: PathUncheckedResponse, expectedStatuses: string[]): void { if (!expectedStatuses.includes(response.status)) { throw createRestError( `Pagination failed with unexpected statusCode ${response.status}`, diff --git a/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts b/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts index 2edbf783be53..f01c41bab69d 100644 --- a/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts @@ -10,11 +10,7 @@ import { OperationResponse, } from "@azure/core-lro"; -import { - Client, - PathUncheckedResponse, - createRestError, -} from "@azure-rest/core-client"; +import { Client, PathUncheckedResponse, createRestError } from "@azure-rest/core-client"; import { AbortSignalLike } from "@azure/abort-controller"; export interface GetLongRunningPollerOptions { @@ -42,10 +38,7 @@ export interface GetLongRunningPollerOptions { */ getInitialResponse?: () => PromiseLike; } -export function getLongRunningPoller< - TResponse extends PathUncheckedResponse, - TResult = void, ->( +export function getLongRunningPoller( client: Client, processResponseBody: (result: TResponse) => Promise, expectedStatuses: string[], @@ -53,18 +46,14 @@ export function getLongRunningPoller< ): PollerLike, TResult> { const { restoreFrom, getInitialResponse } = options; if (!restoreFrom && !getInitialResponse) { - throw new Error( - "Either restoreFrom or getInitialResponse must be specified", - ); + 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", - ); + throw new Error("getInitialResponse is required when initializing a new poller"); } initialResponse = await getInitialResponse(); return getLroResponse(initialResponse, expectedStatuses); diff --git a/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts b/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts index 6e425fdcfdf9..14dcd9fa397c 100644 --- a/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts +++ b/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { - Recorder, - RecorderStartOptions, - VitestTestContext, -} from "@azure-tools/test-recorder"; +import { Recorder, RecorderStartOptions, VitestTestContext } from "@azure-tools/test-recorder"; const replaceableVariables: Record = { SUBSCRIPTION_ID: "azure_subscription_id", @@ -20,9 +16,7 @@ const recorderEnvSetup: RecorderStartOptions = { * 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 { +export async function createRecorder(context: VitestTestContext): Promise { const recorder = new Recorder(context); await recorder.start(recorderEnvSetup); return recorder; diff --git a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json index b6586181d006..f772e6eb3b76 100644 --- a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json +++ b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json @@ -1,14 +1,7 @@ { "extends": "./.tshy/build.json", - "include": [ - "./src/**/*.ts", - "./src/**/*.mts", - "./test/**/*.spec.ts", - "./test/**/*.mts" - ], - "exclude": [ - "./test/**/node/**/*.ts" - ], + "include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"], + "exclude": ["./test/**/node/**/*.ts"], "compilerOptions": { "outDir": "./dist-test/browser", "rootDir": ".", From 019a75852699275babaaf45ed0c1d70d05437951 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 06:20:32 +0800 Subject: [PATCH 13/34] Migration: Update package.json, tsconfig.json, and api-extractor.json --- .../arm-durabletask/eslint.config.mjs | 6 +- .../src/api/durableTaskContext.ts | 3 +- .../src/api/operations/index.ts | 5 +- .../arm-durabletask/src/api/options.ts | 12 +- .../src/api/schedulers/index.ts | 109 +++++++++++------- .../arm-durabletask/src/api/taskHubs/index.ts | 78 ++++++++----- .../src/classic/operations/index.ts | 11 +- .../src/classic/schedulers/index.ts | 36 +++++- .../src/classic/taskHubs/index.ts | 22 +++- .../arm-durabletask/src/durableTaskClient.ts | 15 ++- .../src/helpers/serializerHelpers.ts | 12 +- sdk/durabletask/arm-durabletask/src/index.ts | 6 +- .../arm-durabletask/src/models/models.ts | 20 +++- .../src/restorePollerHelpers.ts | 26 +++-- .../src/static-helpers/pagingHelpers.ts | 55 +++++++-- .../src/static-helpers/pollingHelpers.ts | 19 ++- .../test/public/utils/recordedClient.ts | 10 +- .../tsconfig.browser.config.json | 4 +- .../arm-durabletask/vitest.browser.config.ts | 45 ++++++-- .../arm-durabletask/vitest.config.ts | 39 +++++-- 20 files changed, 380 insertions(+), 153 deletions(-) diff --git a/sdk/durabletask/arm-durabletask/eslint.config.mjs b/sdk/durabletask/arm-durabletask/eslint.config.mjs index 03244d34a19f..113bdc3eaf5f 100644 --- a/sdk/durabletask/arm-durabletask/eslint.config.mjs +++ b/sdk/durabletask/arm-durabletask/eslint.config.mjs @@ -11,7 +11,7 @@ export default [ "@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", - "tsdoc/syntax": "warn", - }, - }, + "tsdoc/syntax": "warn" + } + } ]; diff --git a/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts b/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts index 6264f4426c62..63aa3c0cf662 100644 --- a/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts +++ b/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts @@ -19,7 +19,8 @@ export function createDurableTask( credential: TokenCredential, options: DurableTaskClientOptionalParams = {}, ): DurableTaskContext { - const endpointUrl = options.endpoint ?? options.baseUrl ?? `https://management.azure.com`; + const endpointUrl = + options.endpoint ?? options.baseUrl ?? `https://management.azure.com`; const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; const userAgentInfo = `azsdk-js-arm-durabletask/1.0.0-beta.1`; const userAgentPrefix = prefixFromOptions diff --git a/sdk/durabletask/arm-durabletask/src/api/operations/index.ts b/sdk/durabletask/arm-durabletask/src/api/operations/index.ts index df4776cc68a6..86ac95ed3ee3 100644 --- a/sdk/durabletask/arm-durabletask/src/api/operations/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/operations/index.ts @@ -1,7 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { DurableTaskContext as Client, OperationsListOptionalParams } from "../index.js"; +import { + DurableTaskContext as Client, + OperationsListOptionalParams, +} from "../index.js"; import { _OperationListResult, _operationListResultDeserializer, diff --git a/sdk/durabletask/arm-durabletask/src/api/options.ts b/sdk/durabletask/arm-durabletask/src/api/options.ts index 020039568e34..9a33e997e7d9 100644 --- a/sdk/durabletask/arm-durabletask/src/api/options.ts +++ b/sdk/durabletask/arm-durabletask/src/api/options.ts @@ -10,7 +10,8 @@ export interface OperationsListOptionalParams extends OperationOptions {} export interface SchedulersGetOptionalParams extends OperationOptions {} /** Optional parameters. */ -export interface SchedulersCreateOrUpdateOptionalParams extends OperationOptions { +export interface SchedulersCreateOrUpdateOptionalParams + extends OperationOptions { /** Delay to wait until next poll, in milliseconds. */ updateIntervalInMs?: number; } @@ -28,10 +29,12 @@ export interface SchedulersDeleteOptionalParams extends OperationOptions { } /** Optional parameters. */ -export interface SchedulersListByResourceGroupOptionalParams extends OperationOptions {} +export interface SchedulersListByResourceGroupOptionalParams + extends OperationOptions {} /** Optional parameters. */ -export interface SchedulersListBySubscriptionOptionalParams extends OperationOptions {} +export interface SchedulersListBySubscriptionOptionalParams + extends OperationOptions {} /** Optional parameters. */ export interface TaskHubsGetOptionalParams extends OperationOptions {} @@ -49,4 +52,5 @@ export interface TaskHubsDeleteOptionalParams extends OperationOptions { } /** Optional parameters. */ -export interface TaskHubsListBySchedulerOptionalParams extends OperationOptions {} +export interface TaskHubsListBySchedulerOptionalParams + extends OperationOptions {} diff --git a/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts b/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts index 8ed4dae3bf09..1ca6c1307f31 100644 --- a/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts @@ -17,11 +17,11 @@ import { _SchedulerListResult, _schedulerListResultDeserializer, } from "../../models/models.js"; +import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js"; import { PagedAsyncIterableIterator, buildPagedAsyncIterator, } from "../../static-helpers/pagingHelpers.js"; -import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js"; import { StreamableMethod, PathUncheckedResponse, @@ -47,7 +47,9 @@ export function _schedulersGetSend( .get({ ...operationOptionsToRequestParameters(options) }); } -export async function _schedulersGetDeserialize(result: PathUncheckedResponse): Promise { +export async function _schedulersGetDeserialize( + result: PathUncheckedResponse, +): Promise { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -115,20 +117,25 @@ export function schedulersCreateOrUpdate( resource: Scheduler, options: SchedulersCreateOrUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, Scheduler> { - return getLongRunningPoller(context, _schedulersCreateOrUpdateDeserialize, ["200", "201"], { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersCreateOrUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - resource, - options, - ), - resourceLocationConfig: "azure-async-operation", - }) as PollerLike, Scheduler>; + return getLongRunningPoller( + context, + _schedulersCreateOrUpdateDeserialize, + ["200", "201"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersCreateOrUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }, + ) as PollerLike, Scheduler>; } export function _schedulersUpdateSend( @@ -172,20 +179,25 @@ export function schedulersUpdate( properties: Scheduler, options: SchedulersUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, Scheduler> { - return getLongRunningPoller(context, _schedulersUpdateDeserialize, ["200", "202"], { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - properties, - options, - ), - resourceLocationConfig: "location", - }) as PollerLike, Scheduler>; + return getLongRunningPoller( + context, + _schedulersUpdateDeserialize, + ["200", "202"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + properties, + options, + ), + resourceLocationConfig: "location", + }, + ) as PollerLike, Scheduler>; } export function _schedulersDeleteSend( @@ -205,7 +217,9 @@ export function _schedulersDeleteSend( .delete({ ...operationOptionsToRequestParameters(options) }); } -export async function _schedulersDeleteDeserialize(result: PathUncheckedResponse): Promise { +export async function _schedulersDeleteDeserialize( + result: PathUncheckedResponse, +): Promise { const expectedStatuses = ["202", "204", "200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -222,13 +236,24 @@ export function schedulersDelete( schedulerName: string, options: SchedulersDeleteOptionalParams = { requestOptions: {} }, ): PollerLike, void> { - return getLongRunningPoller(context, _schedulersDeleteDeserialize, ["202", "204", "200"], { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersDeleteSend(context, subscriptionId, resourceGroupName, schedulerName, options), - resourceLocationConfig: "location", - }) as PollerLike, void>; + return getLongRunningPoller( + context, + _schedulersDeleteDeserialize, + ["202", "204", "200"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersDeleteSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + options, + ), + resourceLocationConfig: "location", + }, + ) as PollerLike, void>; } export function _schedulersListByResourceGroupSend( @@ -266,7 +291,13 @@ export function schedulersListByResourceGroup( ): PagedAsyncIterableIterator { return buildPagedAsyncIterator( context, - () => _schedulersListByResourceGroupSend(context, subscriptionId, resourceGroupName, options), + () => + _schedulersListByResourceGroupSend( + context, + subscriptionId, + resourceGroupName, + options, + ), _schedulersListByResourceGroupDeserialize, ["200"], { itemName: "value", nextLinkName: "nextLink" }, diff --git a/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts b/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts index 33eea18f9c3a..96013d37b386 100644 --- a/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts @@ -15,11 +15,11 @@ import { _TaskHubListResult, _taskHubListResultDeserializer, } from "../../models/models.js"; +import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js"; import { PagedAsyncIterableIterator, buildPagedAsyncIterator, } from "../../static-helpers/pagingHelpers.js"; -import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js"; import { StreamableMethod, PathUncheckedResponse, @@ -47,7 +47,9 @@ export function _taskHubsGetSend( .get({ ...operationOptionsToRequestParameters(options) }); } -export async function _taskHubsGetDeserialize(result: PathUncheckedResponse): Promise { +export async function _taskHubsGetDeserialize( + result: PathUncheckedResponse, +): Promise { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -120,21 +122,26 @@ export function taskHubsCreateOrUpdate( resource: TaskHub, options: TaskHubsCreateOrUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, TaskHub> { - return getLongRunningPoller(context, _taskHubsCreateOrUpdateDeserialize, ["200", "201"], { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _taskHubsCreateOrUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - taskHubName, - resource, - options, - ), - resourceLocationConfig: "azure-async-operation", - }) as PollerLike, TaskHub>; + return getLongRunningPoller( + context, + _taskHubsCreateOrUpdateDeserialize, + ["200", "201"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _taskHubsCreateOrUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }, + ) as PollerLike, TaskHub>; } export function _taskHubsDeleteSend( @@ -156,7 +163,9 @@ export function _taskHubsDeleteSend( .delete({ ...operationOptionsToRequestParameters(options) }); } -export async function _taskHubsDeleteDeserialize(result: PathUncheckedResponse): Promise { +export async function _taskHubsDeleteDeserialize( + result: PathUncheckedResponse, +): Promise { const expectedStatuses = ["202", "204", "200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -174,20 +183,25 @@ export function taskHubsDelete( taskHubName: string, options: TaskHubsDeleteOptionalParams = { requestOptions: {} }, ): PollerLike, void> { - return getLongRunningPoller(context, _taskHubsDeleteDeserialize, ["202", "204", "200"], { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _taskHubsDeleteSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - taskHubName, - options, - ), - resourceLocationConfig: "location", - }) as PollerLike, void>; + return getLongRunningPoller( + context, + _taskHubsDeleteDeserialize, + ["202", "204", "200"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _taskHubsDeleteSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + options, + ), + resourceLocationConfig: "location", + }, + ) as PollerLike, void>; } export function _taskHubsListBySchedulerSend( diff --git a/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts b/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts index d51dbb4797cc..467b1c1a9525 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts @@ -10,16 +10,21 @@ import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.j /** Interface representing a Operations operations. */ export interface OperationsOperations { /** List the operations for the provider */ - list: (options?: OperationsListOptionalParams) => PagedAsyncIterableIterator; + list: ( + options?: OperationsListOptionalParams, + ) => PagedAsyncIterableIterator; } export function getOperations(context: DurableTaskContext) { return { - list: (options?: OperationsListOptionalParams) => operationsList(context, options), + list: (options?: OperationsListOptionalParams) => + operationsList(context, options), }; } -export function getOperationsOperations(context: DurableTaskContext): OperationsOperations { +export function getOperationsOperations( + context: DurableTaskContext, +): OperationsOperations { return { ...getOperations(context), }; diff --git a/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts b/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts index a5a5ed3c5e6f..9277a16c2ea0 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts @@ -61,13 +61,23 @@ export interface SchedulersOperations { ) => PagedAsyncIterableIterator; } -export function getSchedulers(context: DurableTaskContext, subscriptionId: string) { +export function getSchedulers( + context: DurableTaskContext, + subscriptionId: string, +) { return { get: ( resourceGroupName: string, schedulerName: string, options?: SchedulersGetOptionalParams, - ) => schedulersGet(context, subscriptionId, resourceGroupName, schedulerName, options), + ) => + schedulersGet( + context, + subscriptionId, + resourceGroupName, + schedulerName, + options, + ), createOrUpdate: ( resourceGroupName: string, schedulerName: string, @@ -100,13 +110,27 @@ export function getSchedulers(context: DurableTaskContext, subscriptionId: strin resourceGroupName: string, schedulerName: string, options?: SchedulersDeleteOptionalParams, - ) => schedulersDelete(context, subscriptionId, resourceGroupName, schedulerName, options), + ) => + schedulersDelete( + context, + subscriptionId, + resourceGroupName, + schedulerName, + options, + ), listByResourceGroup: ( resourceGroupName: string, options?: SchedulersListByResourceGroupOptionalParams, - ) => schedulersListByResourceGroup(context, subscriptionId, resourceGroupName, options), - listBySubscription: (options?: SchedulersListBySubscriptionOptionalParams) => - schedulersListBySubscription(context, subscriptionId, options), + ) => + schedulersListByResourceGroup( + context, + subscriptionId, + resourceGroupName, + options, + ), + listBySubscription: ( + options?: SchedulersListBySubscriptionOptionalParams, + ) => schedulersListBySubscription(context, subscriptionId, options), }; } diff --git a/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts b/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts index 18af9249c1df..d020a2d3c910 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts @@ -50,7 +50,10 @@ export interface TaskHubsOperations { ) => PagedAsyncIterableIterator; } -export function getTaskHubs(context: DurableTaskContext, subscriptionId: string) { +export function getTaskHubs( + context: DurableTaskContext, + subscriptionId: string, +) { return { get: ( resourceGroupName: string, @@ -58,7 +61,14 @@ export function getTaskHubs(context: DurableTaskContext, subscriptionId: string) taskHubName: string, options?: TaskHubsGetOptionalParams, ) => - taskHubsGet(context, subscriptionId, resourceGroupName, schedulerName, taskHubName, options), + taskHubsGet( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + options, + ), createOrUpdate: ( resourceGroupName: string, schedulerName: string, @@ -94,7 +104,13 @@ export function getTaskHubs(context: DurableTaskContext, subscriptionId: string) schedulerName: string, options?: TaskHubsListBySchedulerOptionalParams, ) => - taskHubsListByScheduler(context, subscriptionId, resourceGroupName, schedulerName, options), + taskHubsListByScheduler( + context, + subscriptionId, + resourceGroupName, + schedulerName, + options, + ), }; } diff --git a/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts b/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts index b1609ecd6d1d..5a9162d82ae7 100644 --- a/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts +++ b/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts @@ -1,9 +1,18 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { getOperationsOperations, OperationsOperations } from "./classic/operations/index.js"; -import { getSchedulersOperations, SchedulersOperations } from "./classic/schedulers/index.js"; -import { getTaskHubsOperations, TaskHubsOperations } from "./classic/taskHubs/index.js"; +import { + getOperationsOperations, + OperationsOperations, +} from "./classic/operations/index.js"; +import { + getSchedulersOperations, + SchedulersOperations, +} from "./classic/schedulers/index.js"; +import { + getTaskHubsOperations, + TaskHubsOperations, +} from "./classic/taskHubs/index.js"; import { createDurableTask, DurableTaskContext, diff --git a/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts b/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts index 7518a16c2ee9..4baaac77c8be 100644 --- a/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts @@ -1,9 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -export function serializeRecord( - item: Record, -): Record; +export function serializeRecord< + T extends string | number | boolean | Date | null, + R, +>(item: Record): Record; export function serializeRecord( item: Record, serializer: (item: T) => R, @@ -32,5 +33,8 @@ export function serializeRecord( } function isSupportedRecordType(t: any) { - return ["number", "string", "boolean", "null"].includes(typeof t) || t instanceof Date; + return ( + ["number", "string", "boolean", "null"].includes(typeof t) || + t instanceof Date + ); } diff --git a/sdk/durabletask/arm-durabletask/src/index.ts b/sdk/durabletask/arm-durabletask/src/index.ts index 39e01d18fddf..f65ae6f98a5c 100644 --- a/sdk/durabletask/arm-durabletask/src/index.ts +++ b/sdk/durabletask/arm-durabletask/src/index.ts @@ -47,5 +47,9 @@ export { TaskHubsDeleteOptionalParams, TaskHubsListBySchedulerOptionalParams, } from "./api/index.js"; -export { OperationsOperations, SchedulersOperations, TaskHubsOperations } from "./classic/index.js"; +export { + OperationsOperations, + SchedulersOperations, + TaskHubsOperations, +} from "./classic/index.js"; export { PageSettings, ContinuablePage, PagedAsyncIterableIterator }; diff --git a/sdk/durabletask/arm-durabletask/src/models/models.ts b/sdk/durabletask/arm-durabletask/src/models/models.ts index 36e590f6ffb8..218827d9b203 100644 --- a/sdk/durabletask/arm-durabletask/src/models/models.ts +++ b/sdk/durabletask/arm-durabletask/src/models/models.ts @@ -146,7 +146,9 @@ export function systemDataDeserializer(item: any): SystemData { return { createdBy: item["createdBy"], createdByType: item["createdByType"], - createdAt: !item["createdAt"] ? item["createdAt"] : new Date(item["createdAt"]), + createdAt: !item["createdAt"] + ? item["createdAt"] + : new Date(item["createdAt"]), lastModifiedBy: item["lastModifiedBy"], lastModifiedByType: item["lastModifiedByType"], lastModifiedAt: !item["lastModifiedAt"] @@ -259,7 +261,9 @@ export function schedulerPropertiesSerializer(item: SchedulerProperties): any { }; } -export function schedulerPropertiesDeserializer(item: any): SchedulerProperties { +export function schedulerPropertiesDeserializer( + item: any, +): SchedulerProperties { return { provisioningState: item["provisioningState"], endpoint: item["endpoint"], @@ -343,7 +347,9 @@ export interface _SchedulerListResult { nextLink?: string; } -export function _schedulerListResultDeserializer(item: any): _SchedulerListResult { +export function _schedulerListResultDeserializer( + item: any, +): _SchedulerListResult { return { value: schedulerArrayDeserializer(item["value"]), nextLink: item["nextLink"], @@ -370,7 +376,9 @@ export interface _OperationListResult { nextLink?: string; } -export function _operationListResultDeserializer(item: any): _OperationListResult { +export function _operationListResultDeserializer( + item: any, +): _OperationListResult { return { value: operationArrayDeserializer(item["value"]), nextLink: item["nextLink"], @@ -401,7 +409,9 @@ export function operationDeserializer(item: any): Operation { return { name: item["name"], isDataAction: item["isDataAction"], - display: !item["display"] ? item["display"] : operationDisplayDeserializer(item["display"]), + display: !item["display"] + ? item["display"] + : operationDisplayDeserializer(item["display"]), origin: item["origin"], actionType: item["actionType"], }; diff --git a/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts b/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts index 3a03060f5586..bd87a7ea5a56 100644 --- a/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts @@ -12,7 +12,10 @@ import { _taskHubsDeleteDeserialize, } from "./api/taskHubs/index.js"; import { getLongRunningPoller } from "./static-helpers/pollingHelpers.js"; -import { OperationOptions, PathUncheckedResponse } from "@azure-rest/core-client"; +import { + OperationOptions, + PathUncheckedResponse, +} from "@azure-rest/core-client"; import { AbortSignalLike } from "@azure/abort-controller"; import { PollerLike, @@ -43,7 +46,9 @@ export interface RestorePollerOptions< export function restorePoller( client: DurableTaskClient, serializedState: string, - sourceOperation: (...args: any[]) => PollerLike, TResult>, + sourceOperation: ( + ...args: any[] + ) => PollerLike, TResult>, options?: RestorePollerOptions, ): PollerLike, TResult> { const pollerConfig = deserializeState(serializedState).config; @@ -137,17 +142,24 @@ function getDeserializationHelper( // 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) { + 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] || "", - ); + const isMatched = new RegExp( + `${candidateParts[i]?.slice(start, end)}`, + ).test(pathParts[j] || ""); if (!isMatched) { found = false; diff --git a/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts b/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts index ce33af5f4178..97a81e74e301 100644 --- a/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts @@ -1,7 +1,11 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { Client, createRestError, PathUncheckedResponse } from "@azure-rest/core-client"; +import { + Client, + createRestError, + PathUncheckedResponse, +} from "@azure-rest/core-client"; import { RestError } from "@azure/core-rest-pipeline"; /** @@ -39,11 +43,17 @@ export interface PagedAsyncIterableIterator< /** * The connection to the async iterator, part of the iteration protocol */ - [Symbol.asyncIterator](): PagedAsyncIterableIterator; + [Symbol.asyncIterator](): PagedAsyncIterableIterator< + TElement, + TPage, + TPageSettings + >; /** * Return an AsyncIterableIterator that works a page at a time */ - byPage: (settings?: TPageSettings) => AsyncIterableIterator>; + byPage: ( + settings?: TPageSettings, + ) => AsyncIterableIterator>; } /** @@ -61,11 +71,15 @@ export interface PagedResult< /** * A method that returns a page of results. */ - getPage: (pageLink?: string) => Promise<{ page: TPage; nextPageLink?: string } | undefined>; + 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>; + byPage?: ( + settings?: TPageSettings, + ) => AsyncIterableIterator>; /** * A function to extract elements from a page. @@ -138,7 +152,9 @@ function getPagedAsyncIterator< >( pagedResult: PagedResult, ): PagedAsyncIterableIterator { - const iter = getItemAsyncIterator(pagedResult); + const iter = getItemAsyncIterator( + pagedResult, + ); return { next() { return iter.next(); @@ -157,7 +173,11 @@ function getPagedAsyncIterator< }; } -async function* getItemAsyncIterator( +async function* getItemAsyncIterator< + TElement, + TPage, + TPageSettings extends PageSettings, +>( pagedResult: PagedResult, ): AsyncIterableIterator { const pages = getPageAsyncIterator(pagedResult); @@ -166,14 +186,20 @@ async function* getItemAsyncIterator( +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); + let response = await pagedResult.getPage( + pageLink ?? pagedResult.firstPageLink, + ); if (!response) { return; } @@ -201,7 +227,11 @@ function getNextLink(body: unknown, nextLinkName?: string): string | undefined { const nextLink = (body as Record)[nextLinkName]; - if (typeof nextLink !== "string" && typeof nextLink !== "undefined" && nextLink !== null) { + 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}`, ); @@ -231,7 +261,10 @@ function getElements(body: unknown, itemName: string): T[] { /** * Checks if a request failed */ -function checkPagingRequest(response: PathUncheckedResponse, expectedStatuses: string[]): void { +function checkPagingRequest( + response: PathUncheckedResponse, + expectedStatuses: string[], +): void { if (!expectedStatuses.includes(response.status)) { throw createRestError( `Pagination failed with unexpected statusCode ${response.status}`, diff --git a/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts b/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts index f01c41bab69d..2edbf783be53 100644 --- a/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts @@ -10,7 +10,11 @@ import { OperationResponse, } from "@azure/core-lro"; -import { Client, PathUncheckedResponse, createRestError } from "@azure-rest/core-client"; +import { + Client, + PathUncheckedResponse, + createRestError, +} from "@azure-rest/core-client"; import { AbortSignalLike } from "@azure/abort-controller"; export interface GetLongRunningPollerOptions { @@ -38,7 +42,10 @@ export interface GetLongRunningPollerOptions { */ getInitialResponse?: () => PromiseLike; } -export function getLongRunningPoller( +export function getLongRunningPoller< + TResponse extends PathUncheckedResponse, + TResult = void, +>( client: Client, processResponseBody: (result: TResponse) => Promise, expectedStatuses: string[], @@ -46,14 +53,18 @@ export function getLongRunningPoller, TResult> { const { restoreFrom, getInitialResponse } = options; if (!restoreFrom && !getInitialResponse) { - throw new Error("Either restoreFrom or getInitialResponse must be specified"); + 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"); + throw new Error( + "getInitialResponse is required when initializing a new poller", + ); } initialResponse = await getInitialResponse(); return getLroResponse(initialResponse, expectedStatuses); diff --git a/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts b/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts index 14dcd9fa397c..6e425fdcfdf9 100644 --- a/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts +++ b/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts @@ -1,7 +1,11 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { Recorder, RecorderStartOptions, VitestTestContext } from "@azure-tools/test-recorder"; +import { + Recorder, + RecorderStartOptions, + VitestTestContext, +} from "@azure-tools/test-recorder"; const replaceableVariables: Record = { SUBSCRIPTION_ID: "azure_subscription_id", @@ -16,7 +20,9 @@ const recorderEnvSetup: RecorderStartOptions = { * 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 { +export async function createRecorder( + context: VitestTestContext, +): Promise { const recorder = new Recorder(context); await recorder.start(recorderEnvSetup); return recorder; diff --git a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json index f772e6eb3b76..091177fcb991 100644 --- a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json +++ b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json @@ -1,7 +1,7 @@ { "extends": "./.tshy/build.json", - "include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"], - "exclude": ["./test/**/node/**/*.ts"], + "include": ["src/**/*.ts", "src/**/*.mts", "test/**/*.spec.ts"], + "exclude": ["test/**/node/**/*.ts"], "compilerOptions": { "outDir": "./dist-test/browser", "rootDir": ".", diff --git a/sdk/durabletask/arm-durabletask/vitest.browser.config.ts b/sdk/durabletask/arm-durabletask/vitest.browser.config.ts index b48c61b2ef46..da68c1d231aa 100644 --- a/sdk/durabletask/arm-durabletask/vitest.browser.config.ts +++ b/sdk/durabletask/arm-durabletask/vitest.browser.config.ts @@ -1,17 +1,38 @@ - // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { defineConfig, mergeConfig } from "vitest/config"; -import viteConfig from "../../../vitest.browser.shared.config.ts"; +import { defineConfig } from "vitest/config"; +import { relativeRecordingsPath } from "@azure-tools/test-recorder"; + +process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath(); -export default mergeConfig( - viteConfig, - defineConfig({ - test: { - include: [ - "dist-test/browser/test/**/*.spec.js", - ], +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, + hookTimeout: 1200000, + }, +}); diff --git a/sdk/durabletask/arm-durabletask/vitest.config.ts b/sdk/durabletask/arm-durabletask/vitest.config.ts index 39267dd2f56f..2cf5d0e02c2e 100644 --- a/sdk/durabletask/arm-durabletask/vitest.config.ts +++ b/sdk/durabletask/arm-durabletask/vitest.config.ts @@ -1,15 +1,34 @@ - // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { defineConfig, mergeConfig } from "vitest/config"; -import viteConfig from "../../../vitest.shared.config.ts"; +import { defineConfig } from "vitest/config"; +import { relativeRecordingsPath } from "@azure-tools/test-recorder"; -export default mergeConfig( - viteConfig, - defineConfig({ - test: { - include: ["test/**/*.spec.ts"], +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, + hookTimeout: 1200000, + }, +}); From a4c9c025593b6371bf0c3f55520786b92af3a84f Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 06:20:40 +0800 Subject: [PATCH 14/34] Migration: Update test config --- .../tsconfig.browser.config.json | 11 ++++- .../arm-durabletask/vitest.browser.config.ts | 45 +++++-------------- .../arm-durabletask/vitest.config.ts | 39 +++++----------- 3 files changed, 31 insertions(+), 64 deletions(-) diff --git a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json index 091177fcb991..b6586181d006 100644 --- a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json +++ b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json @@ -1,7 +1,14 @@ { "extends": "./.tshy/build.json", - "include": ["src/**/*.ts", "src/**/*.mts", "test/**/*.spec.ts"], - "exclude": ["test/**/node/**/*.ts"], + "include": [ + "./src/**/*.ts", + "./src/**/*.mts", + "./test/**/*.spec.ts", + "./test/**/*.mts" + ], + "exclude": [ + "./test/**/node/**/*.ts" + ], "compilerOptions": { "outDir": "./dist-test/browser", "rootDir": ".", diff --git a/sdk/durabletask/arm-durabletask/vitest.browser.config.ts b/sdk/durabletask/arm-durabletask/vitest.browser.config.ts index da68c1d231aa..b48c61b2ef46 100644 --- a/sdk/durabletask/arm-durabletask/vitest.browser.config.ts +++ b/sdk/durabletask/arm-durabletask/vitest.browser.config.ts @@ -1,38 +1,17 @@ + // 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(); +import { defineConfig, mergeConfig } from "vitest/config"; +import viteConfig from "../../../vitest.browser.shared.config.ts"; -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", +export default mergeConfig( + viteConfig, + defineConfig({ + test: { + include: [ + "dist-test/browser/test/**/*.spec.js", + ], }, - testTimeout: 1200000, - hookTimeout: 1200000, - }, -}); + }), +); diff --git a/sdk/durabletask/arm-durabletask/vitest.config.ts b/sdk/durabletask/arm-durabletask/vitest.config.ts index 2cf5d0e02c2e..39267dd2f56f 100644 --- a/sdk/durabletask/arm-durabletask/vitest.config.ts +++ b/sdk/durabletask/arm-durabletask/vitest.config.ts @@ -1,34 +1,15 @@ + // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { defineConfig } from "vitest/config"; -import { relativeRecordingsPath } from "@azure-tools/test-recorder"; +import { defineConfig, mergeConfig } from "vitest/config"; +import viteConfig from "../../../vitest.shared.config.ts"; -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", +export default mergeConfig( + viteConfig, + defineConfig({ + test: { + include: ["test/**/*.spec.ts"], }, - testTimeout: 1200000, - hookTimeout: 1200000, - }, -}); + }), +); From 68e39b690e41b80bfda01fe6260f3fa02a1a4116 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 06:20:42 +0800 Subject: [PATCH 15/34] Migration: Clean up files From b09fe8cf9ac1f5eba72989adb72056451c9738c8 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 06:20:43 +0800 Subject: [PATCH 16/34] Migration: Apply codemod: "fixSourceFile" From 798017c38317ad0418e78fdf2207d63c5b672c58 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 06:20:47 +0800 Subject: [PATCH 17/34] Migration: Apply codemod: "fixTestingImports" From aefc196407d34cbfcd2b7faf49dd5e300767b262 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 06:20:50 +0800 Subject: [PATCH 18/34] Migration: Apply codemod: "replaceAssertIsRejected" From 2990e16de9de1458a1e909e135deb687a84b3ca3 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 06:20:53 +0800 Subject: [PATCH 19/34] Migration: Apply codemod: "replaceSinonStub" From 8f63c875ef4df737369838f1065e2986f7096d4b Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 06:20:55 +0800 Subject: [PATCH 20/34] Migration: Apply codemod: "addViHelper" From 0f40c20dbcddf9ad19e92a244716b011dc93674e Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 06:20:56 +0800 Subject: [PATCH 21/34] Migration: Apply codemod: "replaceSupportTracing" From 0bcd55c29f3993a41f847ca794bebd6f80d0963d Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 06:20:57 +0800 Subject: [PATCH 22/34] Migration: Apply codemod: "replaceTestUtils" From f8dda04433649d7ca7c16b941f3341eb290415f6 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 06:21:16 +0800 Subject: [PATCH 23/34] Migration: rushx format --- .../arm-durabletask/eslint.config.mjs | 6 +- .../src/api/durableTaskContext.ts | 3 +- .../src/api/operations/index.ts | 5 +- .../arm-durabletask/src/api/options.ts | 12 +- .../src/api/schedulers/index.ts | 107 +++++++----------- .../arm-durabletask/src/api/taskHubs/index.ts | 76 +++++-------- .../src/classic/operations/index.ts | 11 +- .../src/classic/schedulers/index.ts | 36 +----- .../src/classic/taskHubs/index.ts | 22 +--- .../arm-durabletask/src/durableTaskClient.ts | 15 +-- .../src/helpers/serializerHelpers.ts | 12 +- sdk/durabletask/arm-durabletask/src/index.ts | 6 +- .../arm-durabletask/src/models/models.ts | 20 +--- .../src/restorePollerHelpers.ts | 26 ++--- .../src/static-helpers/pagingHelpers.ts | 55 ++------- .../src/static-helpers/pollingHelpers.ts | 19 +--- .../test/public/utils/recordedClient.ts | 10 +- .../tsconfig.browser.config.json | 11 +- 18 files changed, 129 insertions(+), 323 deletions(-) diff --git a/sdk/durabletask/arm-durabletask/eslint.config.mjs b/sdk/durabletask/arm-durabletask/eslint.config.mjs index 113bdc3eaf5f..03244d34a19f 100644 --- a/sdk/durabletask/arm-durabletask/eslint.config.mjs +++ b/sdk/durabletask/arm-durabletask/eslint.config.mjs @@ -11,7 +11,7 @@ export default [ "@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", - "tsdoc/syntax": "warn" - } - } + "tsdoc/syntax": "warn", + }, + }, ]; diff --git a/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts b/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts index 63aa3c0cf662..6264f4426c62 100644 --- a/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts +++ b/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts @@ -19,8 +19,7 @@ export function createDurableTask( credential: TokenCredential, options: DurableTaskClientOptionalParams = {}, ): DurableTaskContext { - const endpointUrl = - options.endpoint ?? options.baseUrl ?? `https://management.azure.com`; + const endpointUrl = options.endpoint ?? options.baseUrl ?? `https://management.azure.com`; const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; const userAgentInfo = `azsdk-js-arm-durabletask/1.0.0-beta.1`; const userAgentPrefix = prefixFromOptions diff --git a/sdk/durabletask/arm-durabletask/src/api/operations/index.ts b/sdk/durabletask/arm-durabletask/src/api/operations/index.ts index 86ac95ed3ee3..df4776cc68a6 100644 --- a/sdk/durabletask/arm-durabletask/src/api/operations/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/operations/index.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { - DurableTaskContext as Client, - OperationsListOptionalParams, -} from "../index.js"; +import { DurableTaskContext as Client, OperationsListOptionalParams } from "../index.js"; import { _OperationListResult, _operationListResultDeserializer, diff --git a/sdk/durabletask/arm-durabletask/src/api/options.ts b/sdk/durabletask/arm-durabletask/src/api/options.ts index 9a33e997e7d9..020039568e34 100644 --- a/sdk/durabletask/arm-durabletask/src/api/options.ts +++ b/sdk/durabletask/arm-durabletask/src/api/options.ts @@ -10,8 +10,7 @@ export interface OperationsListOptionalParams extends OperationOptions {} export interface SchedulersGetOptionalParams extends OperationOptions {} /** Optional parameters. */ -export interface SchedulersCreateOrUpdateOptionalParams - extends OperationOptions { +export interface SchedulersCreateOrUpdateOptionalParams extends OperationOptions { /** Delay to wait until next poll, in milliseconds. */ updateIntervalInMs?: number; } @@ -29,12 +28,10 @@ export interface SchedulersDeleteOptionalParams extends OperationOptions { } /** Optional parameters. */ -export interface SchedulersListByResourceGroupOptionalParams - extends OperationOptions {} +export interface SchedulersListByResourceGroupOptionalParams extends OperationOptions {} /** Optional parameters. */ -export interface SchedulersListBySubscriptionOptionalParams - extends OperationOptions {} +export interface SchedulersListBySubscriptionOptionalParams extends OperationOptions {} /** Optional parameters. */ export interface TaskHubsGetOptionalParams extends OperationOptions {} @@ -52,5 +49,4 @@ export interface TaskHubsDeleteOptionalParams extends OperationOptions { } /** Optional parameters. */ -export interface TaskHubsListBySchedulerOptionalParams - extends OperationOptions {} +export interface TaskHubsListBySchedulerOptionalParams extends OperationOptions {} diff --git a/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts b/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts index 1ca6c1307f31..2689a35b8091 100644 --- a/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts @@ -47,9 +47,7 @@ export function _schedulersGetSend( .get({ ...operationOptionsToRequestParameters(options) }); } -export async function _schedulersGetDeserialize( - result: PathUncheckedResponse, -): Promise { +export async function _schedulersGetDeserialize(result: PathUncheckedResponse): Promise { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -117,25 +115,20 @@ export function schedulersCreateOrUpdate( resource: Scheduler, options: SchedulersCreateOrUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, Scheduler> { - return getLongRunningPoller( - context, - _schedulersCreateOrUpdateDeserialize, - ["200", "201"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersCreateOrUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - resource, - options, - ), - resourceLocationConfig: "azure-async-operation", - }, - ) as PollerLike, Scheduler>; + return getLongRunningPoller(context, _schedulersCreateOrUpdateDeserialize, ["200", "201"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersCreateOrUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }) as PollerLike, Scheduler>; } export function _schedulersUpdateSend( @@ -179,25 +172,20 @@ export function schedulersUpdate( properties: Scheduler, options: SchedulersUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, Scheduler> { - return getLongRunningPoller( - context, - _schedulersUpdateDeserialize, - ["200", "202"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - properties, - options, - ), - resourceLocationConfig: "location", - }, - ) as PollerLike, Scheduler>; + return getLongRunningPoller(context, _schedulersUpdateDeserialize, ["200", "202"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + properties, + options, + ), + resourceLocationConfig: "location", + }) as PollerLike, Scheduler>; } export function _schedulersDeleteSend( @@ -217,9 +205,7 @@ export function _schedulersDeleteSend( .delete({ ...operationOptionsToRequestParameters(options) }); } -export async function _schedulersDeleteDeserialize( - result: PathUncheckedResponse, -): Promise { +export async function _schedulersDeleteDeserialize(result: PathUncheckedResponse): Promise { const expectedStatuses = ["202", "204", "200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -236,24 +222,13 @@ export function schedulersDelete( schedulerName: string, options: SchedulersDeleteOptionalParams = { requestOptions: {} }, ): PollerLike, void> { - return getLongRunningPoller( - context, - _schedulersDeleteDeserialize, - ["202", "204", "200"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersDeleteSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - options, - ), - resourceLocationConfig: "location", - }, - ) as PollerLike, void>; + return getLongRunningPoller(context, _schedulersDeleteDeserialize, ["202", "204", "200"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersDeleteSend(context, subscriptionId, resourceGroupName, schedulerName, options), + resourceLocationConfig: "location", + }) as PollerLike, void>; } export function _schedulersListByResourceGroupSend( @@ -291,13 +266,7 @@ export function schedulersListByResourceGroup( ): PagedAsyncIterableIterator { return buildPagedAsyncIterator( context, - () => - _schedulersListByResourceGroupSend( - context, - subscriptionId, - resourceGroupName, - options, - ), + () => _schedulersListByResourceGroupSend(context, subscriptionId, resourceGroupName, options), _schedulersListByResourceGroupDeserialize, ["200"], { itemName: "value", nextLinkName: "nextLink" }, diff --git a/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts b/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts index 96013d37b386..456ffc121b2c 100644 --- a/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts @@ -47,9 +47,7 @@ export function _taskHubsGetSend( .get({ ...operationOptionsToRequestParameters(options) }); } -export async function _taskHubsGetDeserialize( - result: PathUncheckedResponse, -): Promise { +export async function _taskHubsGetDeserialize(result: PathUncheckedResponse): Promise { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -122,26 +120,21 @@ export function taskHubsCreateOrUpdate( resource: TaskHub, options: TaskHubsCreateOrUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, TaskHub> { - return getLongRunningPoller( - context, - _taskHubsCreateOrUpdateDeserialize, - ["200", "201"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _taskHubsCreateOrUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - taskHubName, - resource, - options, - ), - resourceLocationConfig: "azure-async-operation", - }, - ) as PollerLike, TaskHub>; + return getLongRunningPoller(context, _taskHubsCreateOrUpdateDeserialize, ["200", "201"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _taskHubsCreateOrUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }) as PollerLike, TaskHub>; } export function _taskHubsDeleteSend( @@ -163,9 +156,7 @@ export function _taskHubsDeleteSend( .delete({ ...operationOptionsToRequestParameters(options) }); } -export async function _taskHubsDeleteDeserialize( - result: PathUncheckedResponse, -): Promise { +export async function _taskHubsDeleteDeserialize(result: PathUncheckedResponse): Promise { const expectedStatuses = ["202", "204", "200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -183,25 +174,20 @@ export function taskHubsDelete( taskHubName: string, options: TaskHubsDeleteOptionalParams = { requestOptions: {} }, ): PollerLike, void> { - return getLongRunningPoller( - context, - _taskHubsDeleteDeserialize, - ["202", "204", "200"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _taskHubsDeleteSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - taskHubName, - options, - ), - resourceLocationConfig: "location", - }, - ) as PollerLike, void>; + return getLongRunningPoller(context, _taskHubsDeleteDeserialize, ["202", "204", "200"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _taskHubsDeleteSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + options, + ), + resourceLocationConfig: "location", + }) as PollerLike, void>; } export function _taskHubsListBySchedulerSend( diff --git a/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts b/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts index 467b1c1a9525..d51dbb4797cc 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts @@ -10,21 +10,16 @@ import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.j /** Interface representing a Operations operations. */ export interface OperationsOperations { /** List the operations for the provider */ - list: ( - options?: OperationsListOptionalParams, - ) => PagedAsyncIterableIterator; + list: (options?: OperationsListOptionalParams) => PagedAsyncIterableIterator; } export function getOperations(context: DurableTaskContext) { return { - list: (options?: OperationsListOptionalParams) => - operationsList(context, options), + list: (options?: OperationsListOptionalParams) => operationsList(context, options), }; } -export function getOperationsOperations( - context: DurableTaskContext, -): OperationsOperations { +export function getOperationsOperations(context: DurableTaskContext): OperationsOperations { return { ...getOperations(context), }; diff --git a/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts b/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts index 9277a16c2ea0..a5a5ed3c5e6f 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts @@ -61,23 +61,13 @@ export interface SchedulersOperations { ) => PagedAsyncIterableIterator; } -export function getSchedulers( - context: DurableTaskContext, - subscriptionId: string, -) { +export function getSchedulers(context: DurableTaskContext, subscriptionId: string) { return { get: ( resourceGroupName: string, schedulerName: string, options?: SchedulersGetOptionalParams, - ) => - schedulersGet( - context, - subscriptionId, - resourceGroupName, - schedulerName, - options, - ), + ) => schedulersGet(context, subscriptionId, resourceGroupName, schedulerName, options), createOrUpdate: ( resourceGroupName: string, schedulerName: string, @@ -110,27 +100,13 @@ export function getSchedulers( resourceGroupName: string, schedulerName: string, options?: SchedulersDeleteOptionalParams, - ) => - schedulersDelete( - context, - subscriptionId, - resourceGroupName, - schedulerName, - options, - ), + ) => schedulersDelete(context, subscriptionId, resourceGroupName, schedulerName, options), listByResourceGroup: ( resourceGroupName: string, options?: SchedulersListByResourceGroupOptionalParams, - ) => - schedulersListByResourceGroup( - context, - subscriptionId, - resourceGroupName, - options, - ), - listBySubscription: ( - options?: SchedulersListBySubscriptionOptionalParams, - ) => schedulersListBySubscription(context, subscriptionId, options), + ) => schedulersListByResourceGroup(context, subscriptionId, resourceGroupName, options), + listBySubscription: (options?: SchedulersListBySubscriptionOptionalParams) => + schedulersListBySubscription(context, subscriptionId, options), }; } diff --git a/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts b/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts index d020a2d3c910..18af9249c1df 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts @@ -50,10 +50,7 @@ export interface TaskHubsOperations { ) => PagedAsyncIterableIterator; } -export function getTaskHubs( - context: DurableTaskContext, - subscriptionId: string, -) { +export function getTaskHubs(context: DurableTaskContext, subscriptionId: string) { return { get: ( resourceGroupName: string, @@ -61,14 +58,7 @@ export function getTaskHubs( taskHubName: string, options?: TaskHubsGetOptionalParams, ) => - taskHubsGet( - context, - subscriptionId, - resourceGroupName, - schedulerName, - taskHubName, - options, - ), + taskHubsGet(context, subscriptionId, resourceGroupName, schedulerName, taskHubName, options), createOrUpdate: ( resourceGroupName: string, schedulerName: string, @@ -104,13 +94,7 @@ export function getTaskHubs( schedulerName: string, options?: TaskHubsListBySchedulerOptionalParams, ) => - taskHubsListByScheduler( - context, - subscriptionId, - resourceGroupName, - schedulerName, - options, - ), + taskHubsListByScheduler(context, subscriptionId, resourceGroupName, schedulerName, options), }; } diff --git a/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts b/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts index 5a9162d82ae7..b1609ecd6d1d 100644 --- a/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts +++ b/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts @@ -1,18 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { - getOperationsOperations, - OperationsOperations, -} from "./classic/operations/index.js"; -import { - getSchedulersOperations, - SchedulersOperations, -} from "./classic/schedulers/index.js"; -import { - getTaskHubsOperations, - TaskHubsOperations, -} from "./classic/taskHubs/index.js"; +import { getOperationsOperations, OperationsOperations } from "./classic/operations/index.js"; +import { getSchedulersOperations, SchedulersOperations } from "./classic/schedulers/index.js"; +import { getTaskHubsOperations, TaskHubsOperations } from "./classic/taskHubs/index.js"; import { createDurableTask, DurableTaskContext, diff --git a/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts b/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts index 4baaac77c8be..7518a16c2ee9 100644 --- a/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts @@ -1,10 +1,9 @@ // 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, +): Record; export function serializeRecord( item: Record, serializer: (item: T) => R, @@ -33,8 +32,5 @@ export function serializeRecord( } function isSupportedRecordType(t: any) { - return ( - ["number", "string", "boolean", "null"].includes(typeof t) || - t instanceof Date - ); + return ["number", "string", "boolean", "null"].includes(typeof t) || t instanceof Date; } diff --git a/sdk/durabletask/arm-durabletask/src/index.ts b/sdk/durabletask/arm-durabletask/src/index.ts index f65ae6f98a5c..39e01d18fddf 100644 --- a/sdk/durabletask/arm-durabletask/src/index.ts +++ b/sdk/durabletask/arm-durabletask/src/index.ts @@ -47,9 +47,5 @@ export { TaskHubsDeleteOptionalParams, TaskHubsListBySchedulerOptionalParams, } from "./api/index.js"; -export { - OperationsOperations, - SchedulersOperations, - TaskHubsOperations, -} from "./classic/index.js"; +export { OperationsOperations, SchedulersOperations, TaskHubsOperations } from "./classic/index.js"; export { PageSettings, ContinuablePage, PagedAsyncIterableIterator }; diff --git a/sdk/durabletask/arm-durabletask/src/models/models.ts b/sdk/durabletask/arm-durabletask/src/models/models.ts index 218827d9b203..36e590f6ffb8 100644 --- a/sdk/durabletask/arm-durabletask/src/models/models.ts +++ b/sdk/durabletask/arm-durabletask/src/models/models.ts @@ -146,9 +146,7 @@ export function systemDataDeserializer(item: any): SystemData { return { createdBy: item["createdBy"], createdByType: item["createdByType"], - createdAt: !item["createdAt"] - ? item["createdAt"] - : new Date(item["createdAt"]), + createdAt: !item["createdAt"] ? item["createdAt"] : new Date(item["createdAt"]), lastModifiedBy: item["lastModifiedBy"], lastModifiedByType: item["lastModifiedByType"], lastModifiedAt: !item["lastModifiedAt"] @@ -261,9 +259,7 @@ export function schedulerPropertiesSerializer(item: SchedulerProperties): any { }; } -export function schedulerPropertiesDeserializer( - item: any, -): SchedulerProperties { +export function schedulerPropertiesDeserializer(item: any): SchedulerProperties { return { provisioningState: item["provisioningState"], endpoint: item["endpoint"], @@ -347,9 +343,7 @@ export interface _SchedulerListResult { nextLink?: string; } -export function _schedulerListResultDeserializer( - item: any, -): _SchedulerListResult { +export function _schedulerListResultDeserializer(item: any): _SchedulerListResult { return { value: schedulerArrayDeserializer(item["value"]), nextLink: item["nextLink"], @@ -376,9 +370,7 @@ export interface _OperationListResult { nextLink?: string; } -export function _operationListResultDeserializer( - item: any, -): _OperationListResult { +export function _operationListResultDeserializer(item: any): _OperationListResult { return { value: operationArrayDeserializer(item["value"]), nextLink: item["nextLink"], @@ -409,9 +401,7 @@ export function operationDeserializer(item: any): Operation { return { name: item["name"], isDataAction: item["isDataAction"], - display: !item["display"] - ? item["display"] - : operationDisplayDeserializer(item["display"]), + display: !item["display"] ? item["display"] : operationDisplayDeserializer(item["display"]), origin: item["origin"], actionType: item["actionType"], }; diff --git a/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts b/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts index bd87a7ea5a56..3a03060f5586 100644 --- a/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts @@ -12,10 +12,7 @@ import { _taskHubsDeleteDeserialize, } from "./api/taskHubs/index.js"; import { getLongRunningPoller } from "./static-helpers/pollingHelpers.js"; -import { - OperationOptions, - PathUncheckedResponse, -} from "@azure-rest/core-client"; +import { OperationOptions, PathUncheckedResponse } from "@azure-rest/core-client"; import { AbortSignalLike } from "@azure/abort-controller"; import { PollerLike, @@ -46,9 +43,7 @@ export interface RestorePollerOptions< export function restorePoller( client: DurableTaskClient, serializedState: string, - sourceOperation: ( - ...args: any[] - ) => PollerLike, TResult>, + sourceOperation: (...args: any[]) => PollerLike, TResult>, options?: RestorePollerOptions, ): PollerLike, TResult> { const pollerConfig = deserializeState(serializedState).config; @@ -142,24 +137,17 @@ function getDeserializationHelper( // 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 - ) { + 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] || ""); + const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test( + pathParts[j] || "", + ); if (!isMatched) { found = false; diff --git a/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts b/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts index 97a81e74e301..ce33af5f4178 100644 --- a/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { - Client, - createRestError, - PathUncheckedResponse, -} from "@azure-rest/core-client"; +import { Client, createRestError, PathUncheckedResponse } from "@azure-rest/core-client"; import { RestError } from "@azure/core-rest-pipeline"; /** @@ -43,17 +39,11 @@ export interface PagedAsyncIterableIterator< /** * The connection to the async iterator, part of the iteration protocol */ - [Symbol.asyncIterator](): PagedAsyncIterableIterator< - TElement, - TPage, - TPageSettings - >; + [Symbol.asyncIterator](): PagedAsyncIterableIterator; /** * Return an AsyncIterableIterator that works a page at a time */ - byPage: ( - settings?: TPageSettings, - ) => AsyncIterableIterator>; + byPage: (settings?: TPageSettings) => AsyncIterableIterator>; } /** @@ -71,15 +61,11 @@ export interface PagedResult< /** * A method that returns a page of results. */ - getPage: ( - pageLink?: string, - ) => Promise<{ page: TPage; nextPageLink?: string } | undefined>; + 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>; + byPage?: (settings?: TPageSettings) => AsyncIterableIterator>; /** * A function to extract elements from a page. @@ -152,9 +138,7 @@ function getPagedAsyncIterator< >( pagedResult: PagedResult, ): PagedAsyncIterableIterator { - const iter = getItemAsyncIterator( - pagedResult, - ); + const iter = getItemAsyncIterator(pagedResult); return { next() { return iter.next(); @@ -173,11 +157,7 @@ function getPagedAsyncIterator< }; } -async function* getItemAsyncIterator< - TElement, - TPage, - TPageSettings extends PageSettings, ->( +async function* getItemAsyncIterator( pagedResult: PagedResult, ): AsyncIterableIterator { const pages = getPageAsyncIterator(pagedResult); @@ -186,20 +166,14 @@ async function* getItemAsyncIterator< } } -async function* getPageAsyncIterator< - TElement, - TPage, - TPageSettings extends PageSettings, ->( +async function* getPageAsyncIterator( pagedResult: PagedResult, options: { pageLink?: string; } = {}, ): AsyncIterableIterator> { const { pageLink } = options; - let response = await pagedResult.getPage( - pageLink ?? pagedResult.firstPageLink, - ); + let response = await pagedResult.getPage(pageLink ?? pagedResult.firstPageLink); if (!response) { return; } @@ -227,11 +201,7 @@ function getNextLink(body: unknown, nextLinkName?: string): string | undefined { const nextLink = (body as Record)[nextLinkName]; - if ( - typeof nextLink !== "string" && - typeof nextLink !== "undefined" && - nextLink !== null - ) { + 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}`, ); @@ -261,10 +231,7 @@ function getElements(body: unknown, itemName: string): T[] { /** * Checks if a request failed */ -function checkPagingRequest( - response: PathUncheckedResponse, - expectedStatuses: string[], -): void { +function checkPagingRequest(response: PathUncheckedResponse, expectedStatuses: string[]): void { if (!expectedStatuses.includes(response.status)) { throw createRestError( `Pagination failed with unexpected statusCode ${response.status}`, diff --git a/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts b/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts index 2edbf783be53..f01c41bab69d 100644 --- a/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts @@ -10,11 +10,7 @@ import { OperationResponse, } from "@azure/core-lro"; -import { - Client, - PathUncheckedResponse, - createRestError, -} from "@azure-rest/core-client"; +import { Client, PathUncheckedResponse, createRestError } from "@azure-rest/core-client"; import { AbortSignalLike } from "@azure/abort-controller"; export interface GetLongRunningPollerOptions { @@ -42,10 +38,7 @@ export interface GetLongRunningPollerOptions { */ getInitialResponse?: () => PromiseLike; } -export function getLongRunningPoller< - TResponse extends PathUncheckedResponse, - TResult = void, ->( +export function getLongRunningPoller( client: Client, processResponseBody: (result: TResponse) => Promise, expectedStatuses: string[], @@ -53,18 +46,14 @@ export function getLongRunningPoller< ): PollerLike, TResult> { const { restoreFrom, getInitialResponse } = options; if (!restoreFrom && !getInitialResponse) { - throw new Error( - "Either restoreFrom or getInitialResponse must be specified", - ); + 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", - ); + throw new Error("getInitialResponse is required when initializing a new poller"); } initialResponse = await getInitialResponse(); return getLroResponse(initialResponse, expectedStatuses); diff --git a/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts b/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts index 6e425fdcfdf9..14dcd9fa397c 100644 --- a/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts +++ b/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { - Recorder, - RecorderStartOptions, - VitestTestContext, -} from "@azure-tools/test-recorder"; +import { Recorder, RecorderStartOptions, VitestTestContext } from "@azure-tools/test-recorder"; const replaceableVariables: Record = { SUBSCRIPTION_ID: "azure_subscription_id", @@ -20,9 +16,7 @@ const recorderEnvSetup: RecorderStartOptions = { * 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 { +export async function createRecorder(context: VitestTestContext): Promise { const recorder = new Recorder(context); await recorder.start(recorderEnvSetup); return recorder; diff --git a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json index b6586181d006..f772e6eb3b76 100644 --- a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json +++ b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json @@ -1,14 +1,7 @@ { "extends": "./.tshy/build.json", - "include": [ - "./src/**/*.ts", - "./src/**/*.mts", - "./test/**/*.spec.ts", - "./test/**/*.mts" - ], - "exclude": [ - "./test/**/node/**/*.ts" - ], + "include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"], + "exclude": ["./test/**/node/**/*.ts"], "compilerOptions": { "outDir": "./dist-test/browser", "rootDir": ".", From d7b04ddd205bc130c5da36276615ac612bbe66f0 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 12:39:08 +0800 Subject: [PATCH 24/34] Migration: Update package.json, tsconfig.json, and api-extractor.json --- .../arm-durabletask/eslint.config.mjs | 6 +- .../src/api/durableTaskContext.ts | 3 +- .../src/api/operations/index.ts | 5 +- .../arm-durabletask/src/api/options.ts | 12 +- .../src/api/schedulers/index.ts | 109 +++++++++++------- .../arm-durabletask/src/api/taskHubs/index.ts | 78 ++++++++----- .../src/classic/operations/index.ts | 11 +- .../src/classic/schedulers/index.ts | 36 +++++- .../src/classic/taskHubs/index.ts | 22 +++- .../arm-durabletask/src/durableTaskClient.ts | 15 ++- .../src/helpers/serializerHelpers.ts | 12 +- sdk/durabletask/arm-durabletask/src/index.ts | 6 +- .../arm-durabletask/src/models/models.ts | 20 +++- .../src/restorePollerHelpers.ts | 26 +++-- .../src/static-helpers/pagingHelpers.ts | 55 +++++++-- .../src/static-helpers/pollingHelpers.ts | 19 ++- .../test/public/utils/recordedClient.ts | 10 +- .../tsconfig.browser.config.json | 4 +- .../arm-durabletask/vitest.browser.config.ts | 45 ++++++-- .../arm-durabletask/vitest.config.ts | 39 +++++-- 20 files changed, 380 insertions(+), 153 deletions(-) diff --git a/sdk/durabletask/arm-durabletask/eslint.config.mjs b/sdk/durabletask/arm-durabletask/eslint.config.mjs index 03244d34a19f..113bdc3eaf5f 100644 --- a/sdk/durabletask/arm-durabletask/eslint.config.mjs +++ b/sdk/durabletask/arm-durabletask/eslint.config.mjs @@ -11,7 +11,7 @@ export default [ "@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", - "tsdoc/syntax": "warn", - }, - }, + "tsdoc/syntax": "warn" + } + } ]; diff --git a/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts b/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts index 6264f4426c62..63aa3c0cf662 100644 --- a/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts +++ b/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts @@ -19,7 +19,8 @@ export function createDurableTask( credential: TokenCredential, options: DurableTaskClientOptionalParams = {}, ): DurableTaskContext { - const endpointUrl = options.endpoint ?? options.baseUrl ?? `https://management.azure.com`; + const endpointUrl = + options.endpoint ?? options.baseUrl ?? `https://management.azure.com`; const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; const userAgentInfo = `azsdk-js-arm-durabletask/1.0.0-beta.1`; const userAgentPrefix = prefixFromOptions diff --git a/sdk/durabletask/arm-durabletask/src/api/operations/index.ts b/sdk/durabletask/arm-durabletask/src/api/operations/index.ts index df4776cc68a6..86ac95ed3ee3 100644 --- a/sdk/durabletask/arm-durabletask/src/api/operations/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/operations/index.ts @@ -1,7 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { DurableTaskContext as Client, OperationsListOptionalParams } from "../index.js"; +import { + DurableTaskContext as Client, + OperationsListOptionalParams, +} from "../index.js"; import { _OperationListResult, _operationListResultDeserializer, diff --git a/sdk/durabletask/arm-durabletask/src/api/options.ts b/sdk/durabletask/arm-durabletask/src/api/options.ts index 020039568e34..9a33e997e7d9 100644 --- a/sdk/durabletask/arm-durabletask/src/api/options.ts +++ b/sdk/durabletask/arm-durabletask/src/api/options.ts @@ -10,7 +10,8 @@ export interface OperationsListOptionalParams extends OperationOptions {} export interface SchedulersGetOptionalParams extends OperationOptions {} /** Optional parameters. */ -export interface SchedulersCreateOrUpdateOptionalParams extends OperationOptions { +export interface SchedulersCreateOrUpdateOptionalParams + extends OperationOptions { /** Delay to wait until next poll, in milliseconds. */ updateIntervalInMs?: number; } @@ -28,10 +29,12 @@ export interface SchedulersDeleteOptionalParams extends OperationOptions { } /** Optional parameters. */ -export interface SchedulersListByResourceGroupOptionalParams extends OperationOptions {} +export interface SchedulersListByResourceGroupOptionalParams + extends OperationOptions {} /** Optional parameters. */ -export interface SchedulersListBySubscriptionOptionalParams extends OperationOptions {} +export interface SchedulersListBySubscriptionOptionalParams + extends OperationOptions {} /** Optional parameters. */ export interface TaskHubsGetOptionalParams extends OperationOptions {} @@ -49,4 +52,5 @@ export interface TaskHubsDeleteOptionalParams extends OperationOptions { } /** Optional parameters. */ -export interface TaskHubsListBySchedulerOptionalParams extends OperationOptions {} +export interface TaskHubsListBySchedulerOptionalParams + extends OperationOptions {} diff --git a/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts b/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts index 2689a35b8091..8d6c144fb0bb 100644 --- a/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts @@ -17,11 +17,11 @@ import { _SchedulerListResult, _schedulerListResultDeserializer, } from "../../models/models.js"; -import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js"; import { PagedAsyncIterableIterator, buildPagedAsyncIterator, } from "../../static-helpers/pagingHelpers.js"; +import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js"; import { StreamableMethod, PathUncheckedResponse, @@ -47,7 +47,9 @@ export function _schedulersGetSend( .get({ ...operationOptionsToRequestParameters(options) }); } -export async function _schedulersGetDeserialize(result: PathUncheckedResponse): Promise { +export async function _schedulersGetDeserialize( + result: PathUncheckedResponse, +): Promise { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -115,20 +117,25 @@ export function schedulersCreateOrUpdate( resource: Scheduler, options: SchedulersCreateOrUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, Scheduler> { - return getLongRunningPoller(context, _schedulersCreateOrUpdateDeserialize, ["200", "201"], { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersCreateOrUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - resource, - options, - ), - resourceLocationConfig: "azure-async-operation", - }) as PollerLike, Scheduler>; + return getLongRunningPoller( + context, + _schedulersCreateOrUpdateDeserialize, + ["200", "201"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersCreateOrUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }, + ) as PollerLike, Scheduler>; } export function _schedulersUpdateSend( @@ -172,20 +179,25 @@ export function schedulersUpdate( properties: Scheduler, options: SchedulersUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, Scheduler> { - return getLongRunningPoller(context, _schedulersUpdateDeserialize, ["200", "202"], { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - properties, - options, - ), - resourceLocationConfig: "location", - }) as PollerLike, Scheduler>; + return getLongRunningPoller( + context, + _schedulersUpdateDeserialize, + ["200", "202"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + properties, + options, + ), + resourceLocationConfig: "location", + }, + ) as PollerLike, Scheduler>; } export function _schedulersDeleteSend( @@ -205,7 +217,9 @@ export function _schedulersDeleteSend( .delete({ ...operationOptionsToRequestParameters(options) }); } -export async function _schedulersDeleteDeserialize(result: PathUncheckedResponse): Promise { +export async function _schedulersDeleteDeserialize( + result: PathUncheckedResponse, +): Promise { const expectedStatuses = ["202", "204", "200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -222,13 +236,24 @@ export function schedulersDelete( schedulerName: string, options: SchedulersDeleteOptionalParams = { requestOptions: {} }, ): PollerLike, void> { - return getLongRunningPoller(context, _schedulersDeleteDeserialize, ["202", "204", "200"], { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersDeleteSend(context, subscriptionId, resourceGroupName, schedulerName, options), - resourceLocationConfig: "location", - }) as PollerLike, void>; + return getLongRunningPoller( + context, + _schedulersDeleteDeserialize, + ["202", "204", "200"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersDeleteSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + options, + ), + resourceLocationConfig: "location", + }, + ) as PollerLike, void>; } export function _schedulersListByResourceGroupSend( @@ -266,7 +291,13 @@ export function schedulersListByResourceGroup( ): PagedAsyncIterableIterator { return buildPagedAsyncIterator( context, - () => _schedulersListByResourceGroupSend(context, subscriptionId, resourceGroupName, options), + () => + _schedulersListByResourceGroupSend( + context, + subscriptionId, + resourceGroupName, + options, + ), _schedulersListByResourceGroupDeserialize, ["200"], { itemName: "value", nextLinkName: "nextLink" }, diff --git a/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts b/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts index 456ffc121b2c..0b611635617f 100644 --- a/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts @@ -15,11 +15,11 @@ import { _TaskHubListResult, _taskHubListResultDeserializer, } from "../../models/models.js"; -import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js"; import { PagedAsyncIterableIterator, buildPagedAsyncIterator, } from "../../static-helpers/pagingHelpers.js"; +import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js"; import { StreamableMethod, PathUncheckedResponse, @@ -47,7 +47,9 @@ export function _taskHubsGetSend( .get({ ...operationOptionsToRequestParameters(options) }); } -export async function _taskHubsGetDeserialize(result: PathUncheckedResponse): Promise { +export async function _taskHubsGetDeserialize( + result: PathUncheckedResponse, +): Promise { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -120,21 +122,26 @@ export function taskHubsCreateOrUpdate( resource: TaskHub, options: TaskHubsCreateOrUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, TaskHub> { - return getLongRunningPoller(context, _taskHubsCreateOrUpdateDeserialize, ["200", "201"], { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _taskHubsCreateOrUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - taskHubName, - resource, - options, - ), - resourceLocationConfig: "azure-async-operation", - }) as PollerLike, TaskHub>; + return getLongRunningPoller( + context, + _taskHubsCreateOrUpdateDeserialize, + ["200", "201"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _taskHubsCreateOrUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }, + ) as PollerLike, TaskHub>; } export function _taskHubsDeleteSend( @@ -156,7 +163,9 @@ export function _taskHubsDeleteSend( .delete({ ...operationOptionsToRequestParameters(options) }); } -export async function _taskHubsDeleteDeserialize(result: PathUncheckedResponse): Promise { +export async function _taskHubsDeleteDeserialize( + result: PathUncheckedResponse, +): Promise { const expectedStatuses = ["202", "204", "200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -174,20 +183,25 @@ export function taskHubsDelete( taskHubName: string, options: TaskHubsDeleteOptionalParams = { requestOptions: {} }, ): PollerLike, void> { - return getLongRunningPoller(context, _taskHubsDeleteDeserialize, ["202", "204", "200"], { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _taskHubsDeleteSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - taskHubName, - options, - ), - resourceLocationConfig: "location", - }) as PollerLike, void>; + return getLongRunningPoller( + context, + _taskHubsDeleteDeserialize, + ["202", "204", "200"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _taskHubsDeleteSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + options, + ), + resourceLocationConfig: "location", + }, + ) as PollerLike, void>; } export function _taskHubsListBySchedulerSend( diff --git a/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts b/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts index d51dbb4797cc..467b1c1a9525 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts @@ -10,16 +10,21 @@ import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.j /** Interface representing a Operations operations. */ export interface OperationsOperations { /** List the operations for the provider */ - list: (options?: OperationsListOptionalParams) => PagedAsyncIterableIterator; + list: ( + options?: OperationsListOptionalParams, + ) => PagedAsyncIterableIterator; } export function getOperations(context: DurableTaskContext) { return { - list: (options?: OperationsListOptionalParams) => operationsList(context, options), + list: (options?: OperationsListOptionalParams) => + operationsList(context, options), }; } -export function getOperationsOperations(context: DurableTaskContext): OperationsOperations { +export function getOperationsOperations( + context: DurableTaskContext, +): OperationsOperations { return { ...getOperations(context), }; diff --git a/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts b/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts index a5a5ed3c5e6f..9277a16c2ea0 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts @@ -61,13 +61,23 @@ export interface SchedulersOperations { ) => PagedAsyncIterableIterator; } -export function getSchedulers(context: DurableTaskContext, subscriptionId: string) { +export function getSchedulers( + context: DurableTaskContext, + subscriptionId: string, +) { return { get: ( resourceGroupName: string, schedulerName: string, options?: SchedulersGetOptionalParams, - ) => schedulersGet(context, subscriptionId, resourceGroupName, schedulerName, options), + ) => + schedulersGet( + context, + subscriptionId, + resourceGroupName, + schedulerName, + options, + ), createOrUpdate: ( resourceGroupName: string, schedulerName: string, @@ -100,13 +110,27 @@ export function getSchedulers(context: DurableTaskContext, subscriptionId: strin resourceGroupName: string, schedulerName: string, options?: SchedulersDeleteOptionalParams, - ) => schedulersDelete(context, subscriptionId, resourceGroupName, schedulerName, options), + ) => + schedulersDelete( + context, + subscriptionId, + resourceGroupName, + schedulerName, + options, + ), listByResourceGroup: ( resourceGroupName: string, options?: SchedulersListByResourceGroupOptionalParams, - ) => schedulersListByResourceGroup(context, subscriptionId, resourceGroupName, options), - listBySubscription: (options?: SchedulersListBySubscriptionOptionalParams) => - schedulersListBySubscription(context, subscriptionId, options), + ) => + schedulersListByResourceGroup( + context, + subscriptionId, + resourceGroupName, + options, + ), + listBySubscription: ( + options?: SchedulersListBySubscriptionOptionalParams, + ) => schedulersListBySubscription(context, subscriptionId, options), }; } diff --git a/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts b/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts index 18af9249c1df..d020a2d3c910 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts @@ -50,7 +50,10 @@ export interface TaskHubsOperations { ) => PagedAsyncIterableIterator; } -export function getTaskHubs(context: DurableTaskContext, subscriptionId: string) { +export function getTaskHubs( + context: DurableTaskContext, + subscriptionId: string, +) { return { get: ( resourceGroupName: string, @@ -58,7 +61,14 @@ export function getTaskHubs(context: DurableTaskContext, subscriptionId: string) taskHubName: string, options?: TaskHubsGetOptionalParams, ) => - taskHubsGet(context, subscriptionId, resourceGroupName, schedulerName, taskHubName, options), + taskHubsGet( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + options, + ), createOrUpdate: ( resourceGroupName: string, schedulerName: string, @@ -94,7 +104,13 @@ export function getTaskHubs(context: DurableTaskContext, subscriptionId: string) schedulerName: string, options?: TaskHubsListBySchedulerOptionalParams, ) => - taskHubsListByScheduler(context, subscriptionId, resourceGroupName, schedulerName, options), + taskHubsListByScheduler( + context, + subscriptionId, + resourceGroupName, + schedulerName, + options, + ), }; } diff --git a/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts b/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts index b1609ecd6d1d..5a9162d82ae7 100644 --- a/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts +++ b/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts @@ -1,9 +1,18 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { getOperationsOperations, OperationsOperations } from "./classic/operations/index.js"; -import { getSchedulersOperations, SchedulersOperations } from "./classic/schedulers/index.js"; -import { getTaskHubsOperations, TaskHubsOperations } from "./classic/taskHubs/index.js"; +import { + getOperationsOperations, + OperationsOperations, +} from "./classic/operations/index.js"; +import { + getSchedulersOperations, + SchedulersOperations, +} from "./classic/schedulers/index.js"; +import { + getTaskHubsOperations, + TaskHubsOperations, +} from "./classic/taskHubs/index.js"; import { createDurableTask, DurableTaskContext, diff --git a/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts b/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts index 7518a16c2ee9..4baaac77c8be 100644 --- a/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts @@ -1,9 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -export function serializeRecord( - item: Record, -): Record; +export function serializeRecord< + T extends string | number | boolean | Date | null, + R, +>(item: Record): Record; export function serializeRecord( item: Record, serializer: (item: T) => R, @@ -32,5 +33,8 @@ export function serializeRecord( } function isSupportedRecordType(t: any) { - return ["number", "string", "boolean", "null"].includes(typeof t) || t instanceof Date; + return ( + ["number", "string", "boolean", "null"].includes(typeof t) || + t instanceof Date + ); } diff --git a/sdk/durabletask/arm-durabletask/src/index.ts b/sdk/durabletask/arm-durabletask/src/index.ts index 39e01d18fddf..f65ae6f98a5c 100644 --- a/sdk/durabletask/arm-durabletask/src/index.ts +++ b/sdk/durabletask/arm-durabletask/src/index.ts @@ -47,5 +47,9 @@ export { TaskHubsDeleteOptionalParams, TaskHubsListBySchedulerOptionalParams, } from "./api/index.js"; -export { OperationsOperations, SchedulersOperations, TaskHubsOperations } from "./classic/index.js"; +export { + OperationsOperations, + SchedulersOperations, + TaskHubsOperations, +} from "./classic/index.js"; export { PageSettings, ContinuablePage, PagedAsyncIterableIterator }; diff --git a/sdk/durabletask/arm-durabletask/src/models/models.ts b/sdk/durabletask/arm-durabletask/src/models/models.ts index 36e590f6ffb8..218827d9b203 100644 --- a/sdk/durabletask/arm-durabletask/src/models/models.ts +++ b/sdk/durabletask/arm-durabletask/src/models/models.ts @@ -146,7 +146,9 @@ export function systemDataDeserializer(item: any): SystemData { return { createdBy: item["createdBy"], createdByType: item["createdByType"], - createdAt: !item["createdAt"] ? item["createdAt"] : new Date(item["createdAt"]), + createdAt: !item["createdAt"] + ? item["createdAt"] + : new Date(item["createdAt"]), lastModifiedBy: item["lastModifiedBy"], lastModifiedByType: item["lastModifiedByType"], lastModifiedAt: !item["lastModifiedAt"] @@ -259,7 +261,9 @@ export function schedulerPropertiesSerializer(item: SchedulerProperties): any { }; } -export function schedulerPropertiesDeserializer(item: any): SchedulerProperties { +export function schedulerPropertiesDeserializer( + item: any, +): SchedulerProperties { return { provisioningState: item["provisioningState"], endpoint: item["endpoint"], @@ -343,7 +347,9 @@ export interface _SchedulerListResult { nextLink?: string; } -export function _schedulerListResultDeserializer(item: any): _SchedulerListResult { +export function _schedulerListResultDeserializer( + item: any, +): _SchedulerListResult { return { value: schedulerArrayDeserializer(item["value"]), nextLink: item["nextLink"], @@ -370,7 +376,9 @@ export interface _OperationListResult { nextLink?: string; } -export function _operationListResultDeserializer(item: any): _OperationListResult { +export function _operationListResultDeserializer( + item: any, +): _OperationListResult { return { value: operationArrayDeserializer(item["value"]), nextLink: item["nextLink"], @@ -401,7 +409,9 @@ export function operationDeserializer(item: any): Operation { return { name: item["name"], isDataAction: item["isDataAction"], - display: !item["display"] ? item["display"] : operationDisplayDeserializer(item["display"]), + display: !item["display"] + ? item["display"] + : operationDisplayDeserializer(item["display"]), origin: item["origin"], actionType: item["actionType"], }; diff --git a/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts b/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts index 3a03060f5586..bd87a7ea5a56 100644 --- a/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts @@ -12,7 +12,10 @@ import { _taskHubsDeleteDeserialize, } from "./api/taskHubs/index.js"; import { getLongRunningPoller } from "./static-helpers/pollingHelpers.js"; -import { OperationOptions, PathUncheckedResponse } from "@azure-rest/core-client"; +import { + OperationOptions, + PathUncheckedResponse, +} from "@azure-rest/core-client"; import { AbortSignalLike } from "@azure/abort-controller"; import { PollerLike, @@ -43,7 +46,9 @@ export interface RestorePollerOptions< export function restorePoller( client: DurableTaskClient, serializedState: string, - sourceOperation: (...args: any[]) => PollerLike, TResult>, + sourceOperation: ( + ...args: any[] + ) => PollerLike, TResult>, options?: RestorePollerOptions, ): PollerLike, TResult> { const pollerConfig = deserializeState(serializedState).config; @@ -137,17 +142,24 @@ function getDeserializationHelper( // 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) { + 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] || "", - ); + const isMatched = new RegExp( + `${candidateParts[i]?.slice(start, end)}`, + ).test(pathParts[j] || ""); if (!isMatched) { found = false; diff --git a/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts b/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts index ce33af5f4178..97a81e74e301 100644 --- a/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts @@ -1,7 +1,11 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { Client, createRestError, PathUncheckedResponse } from "@azure-rest/core-client"; +import { + Client, + createRestError, + PathUncheckedResponse, +} from "@azure-rest/core-client"; import { RestError } from "@azure/core-rest-pipeline"; /** @@ -39,11 +43,17 @@ export interface PagedAsyncIterableIterator< /** * The connection to the async iterator, part of the iteration protocol */ - [Symbol.asyncIterator](): PagedAsyncIterableIterator; + [Symbol.asyncIterator](): PagedAsyncIterableIterator< + TElement, + TPage, + TPageSettings + >; /** * Return an AsyncIterableIterator that works a page at a time */ - byPage: (settings?: TPageSettings) => AsyncIterableIterator>; + byPage: ( + settings?: TPageSettings, + ) => AsyncIterableIterator>; } /** @@ -61,11 +71,15 @@ export interface PagedResult< /** * A method that returns a page of results. */ - getPage: (pageLink?: string) => Promise<{ page: TPage; nextPageLink?: string } | undefined>; + 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>; + byPage?: ( + settings?: TPageSettings, + ) => AsyncIterableIterator>; /** * A function to extract elements from a page. @@ -138,7 +152,9 @@ function getPagedAsyncIterator< >( pagedResult: PagedResult, ): PagedAsyncIterableIterator { - const iter = getItemAsyncIterator(pagedResult); + const iter = getItemAsyncIterator( + pagedResult, + ); return { next() { return iter.next(); @@ -157,7 +173,11 @@ function getPagedAsyncIterator< }; } -async function* getItemAsyncIterator( +async function* getItemAsyncIterator< + TElement, + TPage, + TPageSettings extends PageSettings, +>( pagedResult: PagedResult, ): AsyncIterableIterator { const pages = getPageAsyncIterator(pagedResult); @@ -166,14 +186,20 @@ async function* getItemAsyncIterator( +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); + let response = await pagedResult.getPage( + pageLink ?? pagedResult.firstPageLink, + ); if (!response) { return; } @@ -201,7 +227,11 @@ function getNextLink(body: unknown, nextLinkName?: string): string | undefined { const nextLink = (body as Record)[nextLinkName]; - if (typeof nextLink !== "string" && typeof nextLink !== "undefined" && nextLink !== null) { + 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}`, ); @@ -231,7 +261,10 @@ function getElements(body: unknown, itemName: string): T[] { /** * Checks if a request failed */ -function checkPagingRequest(response: PathUncheckedResponse, expectedStatuses: string[]): void { +function checkPagingRequest( + response: PathUncheckedResponse, + expectedStatuses: string[], +): void { if (!expectedStatuses.includes(response.status)) { throw createRestError( `Pagination failed with unexpected statusCode ${response.status}`, diff --git a/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts b/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts index f01c41bab69d..2edbf783be53 100644 --- a/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts @@ -10,7 +10,11 @@ import { OperationResponse, } from "@azure/core-lro"; -import { Client, PathUncheckedResponse, createRestError } from "@azure-rest/core-client"; +import { + Client, + PathUncheckedResponse, + createRestError, +} from "@azure-rest/core-client"; import { AbortSignalLike } from "@azure/abort-controller"; export interface GetLongRunningPollerOptions { @@ -38,7 +42,10 @@ export interface GetLongRunningPollerOptions { */ getInitialResponse?: () => PromiseLike; } -export function getLongRunningPoller( +export function getLongRunningPoller< + TResponse extends PathUncheckedResponse, + TResult = void, +>( client: Client, processResponseBody: (result: TResponse) => Promise, expectedStatuses: string[], @@ -46,14 +53,18 @@ export function getLongRunningPoller, TResult> { const { restoreFrom, getInitialResponse } = options; if (!restoreFrom && !getInitialResponse) { - throw new Error("Either restoreFrom or getInitialResponse must be specified"); + 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"); + throw new Error( + "getInitialResponse is required when initializing a new poller", + ); } initialResponse = await getInitialResponse(); return getLroResponse(initialResponse, expectedStatuses); diff --git a/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts b/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts index 14dcd9fa397c..6e425fdcfdf9 100644 --- a/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts +++ b/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts @@ -1,7 +1,11 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { Recorder, RecorderStartOptions, VitestTestContext } from "@azure-tools/test-recorder"; +import { + Recorder, + RecorderStartOptions, + VitestTestContext, +} from "@azure-tools/test-recorder"; const replaceableVariables: Record = { SUBSCRIPTION_ID: "azure_subscription_id", @@ -16,7 +20,9 @@ const recorderEnvSetup: RecorderStartOptions = { * 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 { +export async function createRecorder( + context: VitestTestContext, +): Promise { const recorder = new Recorder(context); await recorder.start(recorderEnvSetup); return recorder; diff --git a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json index f772e6eb3b76..091177fcb991 100644 --- a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json +++ b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json @@ -1,7 +1,7 @@ { "extends": "./.tshy/build.json", - "include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"], - "exclude": ["./test/**/node/**/*.ts"], + "include": ["src/**/*.ts", "src/**/*.mts", "test/**/*.spec.ts"], + "exclude": ["test/**/node/**/*.ts"], "compilerOptions": { "outDir": "./dist-test/browser", "rootDir": ".", diff --git a/sdk/durabletask/arm-durabletask/vitest.browser.config.ts b/sdk/durabletask/arm-durabletask/vitest.browser.config.ts index b48c61b2ef46..da68c1d231aa 100644 --- a/sdk/durabletask/arm-durabletask/vitest.browser.config.ts +++ b/sdk/durabletask/arm-durabletask/vitest.browser.config.ts @@ -1,17 +1,38 @@ - // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { defineConfig, mergeConfig } from "vitest/config"; -import viteConfig from "../../../vitest.browser.shared.config.ts"; +import { defineConfig } from "vitest/config"; +import { relativeRecordingsPath } from "@azure-tools/test-recorder"; + +process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath(); -export default mergeConfig( - viteConfig, - defineConfig({ - test: { - include: [ - "dist-test/browser/test/**/*.spec.js", - ], +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, + hookTimeout: 1200000, + }, +}); diff --git a/sdk/durabletask/arm-durabletask/vitest.config.ts b/sdk/durabletask/arm-durabletask/vitest.config.ts index 39267dd2f56f..2cf5d0e02c2e 100644 --- a/sdk/durabletask/arm-durabletask/vitest.config.ts +++ b/sdk/durabletask/arm-durabletask/vitest.config.ts @@ -1,15 +1,34 @@ - // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { defineConfig, mergeConfig } from "vitest/config"; -import viteConfig from "../../../vitest.shared.config.ts"; +import { defineConfig } from "vitest/config"; +import { relativeRecordingsPath } from "@azure-tools/test-recorder"; -export default mergeConfig( - viteConfig, - defineConfig({ - test: { - include: ["test/**/*.spec.ts"], +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, + hookTimeout: 1200000, + }, +}); From 01ab2f20e511e7c016a549a6a2aab5667f8b3613 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 12:39:08 +0800 Subject: [PATCH 25/34] Migration: Update test config --- .../tsconfig.browser.config.json | 11 ++++- .../arm-durabletask/vitest.browser.config.ts | 45 +++++-------------- .../arm-durabletask/vitest.config.ts | 39 +++++----------- 3 files changed, 31 insertions(+), 64 deletions(-) diff --git a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json index 091177fcb991..b6586181d006 100644 --- a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json +++ b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json @@ -1,7 +1,14 @@ { "extends": "./.tshy/build.json", - "include": ["src/**/*.ts", "src/**/*.mts", "test/**/*.spec.ts"], - "exclude": ["test/**/node/**/*.ts"], + "include": [ + "./src/**/*.ts", + "./src/**/*.mts", + "./test/**/*.spec.ts", + "./test/**/*.mts" + ], + "exclude": [ + "./test/**/node/**/*.ts" + ], "compilerOptions": { "outDir": "./dist-test/browser", "rootDir": ".", diff --git a/sdk/durabletask/arm-durabletask/vitest.browser.config.ts b/sdk/durabletask/arm-durabletask/vitest.browser.config.ts index da68c1d231aa..b48c61b2ef46 100644 --- a/sdk/durabletask/arm-durabletask/vitest.browser.config.ts +++ b/sdk/durabletask/arm-durabletask/vitest.browser.config.ts @@ -1,38 +1,17 @@ + // 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(); +import { defineConfig, mergeConfig } from "vitest/config"; +import viteConfig from "../../../vitest.browser.shared.config.ts"; -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", +export default mergeConfig( + viteConfig, + defineConfig({ + test: { + include: [ + "dist-test/browser/test/**/*.spec.js", + ], }, - testTimeout: 1200000, - hookTimeout: 1200000, - }, -}); + }), +); diff --git a/sdk/durabletask/arm-durabletask/vitest.config.ts b/sdk/durabletask/arm-durabletask/vitest.config.ts index 2cf5d0e02c2e..39267dd2f56f 100644 --- a/sdk/durabletask/arm-durabletask/vitest.config.ts +++ b/sdk/durabletask/arm-durabletask/vitest.config.ts @@ -1,34 +1,15 @@ + // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { defineConfig } from "vitest/config"; -import { relativeRecordingsPath } from "@azure-tools/test-recorder"; +import { defineConfig, mergeConfig } from "vitest/config"; +import viteConfig from "../../../vitest.shared.config.ts"; -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", +export default mergeConfig( + viteConfig, + defineConfig({ + test: { + include: ["test/**/*.spec.ts"], }, - testTimeout: 1200000, - hookTimeout: 1200000, - }, -}); + }), +); From e0d1250ddbcd6a3a6f25f75eaec61c1bb1551e0f Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 12:39:09 +0800 Subject: [PATCH 26/34] Migration: Clean up files From 0584ad704cf35947d870006011d235add62027c6 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 12:39:12 +0800 Subject: [PATCH 27/34] Migration: Apply codemod: "fixSourceFile" From def32e0f48fcd799c9d6d65dd4e8f86628375f80 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 12:39:13 +0800 Subject: [PATCH 28/34] Migration: Apply codemod: "fixTestingImports" From a5adae0beb4ce2da1d61b50b25bce74db5c88497 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 12:39:13 +0800 Subject: [PATCH 29/34] Migration: Apply codemod: "replaceAssertIsRejected" From a01b45d99b312f45fa4b0cccd9235a89ad06b353 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 12:39:14 +0800 Subject: [PATCH 30/34] Migration: Apply codemod: "replaceSinonStub" From efd89b3b92ee42ccd33bdf1170a4257aa8235923 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 12:39:14 +0800 Subject: [PATCH 31/34] Migration: Apply codemod: "addViHelper" From 95375290abc07713510752e71b6b4c35cda1b824 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 12:39:14 +0800 Subject: [PATCH 32/34] Migration: Apply codemod: "replaceSupportTracing" From 4926f4d358933600a4d3187fed5f39312778df8c Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 12:39:15 +0800 Subject: [PATCH 33/34] Migration: Apply codemod: "replaceTestUtils" From e0e5bd87b3d0510c33ccf5921a18dbe85bb5db45 Mon Sep 17 00:00:00 2001 From: albertxavier Date: Fri, 13 Dec 2024 12:39:19 +0800 Subject: [PATCH 34/34] Migration: rushx format --- .../arm-durabletask/eslint.config.mjs | 6 +- .../src/api/durableTaskContext.ts | 3 +- .../src/api/operations/index.ts | 5 +- .../arm-durabletask/src/api/options.ts | 12 +- .../src/api/schedulers/index.ts | 107 +++++++----------- .../arm-durabletask/src/api/taskHubs/index.ts | 76 +++++-------- .../src/classic/operations/index.ts | 11 +- .../src/classic/schedulers/index.ts | 36 +----- .../src/classic/taskHubs/index.ts | 22 +--- .../arm-durabletask/src/durableTaskClient.ts | 15 +-- .../src/helpers/serializerHelpers.ts | 12 +- sdk/durabletask/arm-durabletask/src/index.ts | 6 +- .../arm-durabletask/src/models/models.ts | 20 +--- .../src/restorePollerHelpers.ts | 26 ++--- .../src/static-helpers/pagingHelpers.ts | 55 ++------- .../src/static-helpers/pollingHelpers.ts | 19 +--- .../test/public/utils/recordedClient.ts | 10 +- .../tsconfig.browser.config.json | 11 +- 18 files changed, 129 insertions(+), 323 deletions(-) diff --git a/sdk/durabletask/arm-durabletask/eslint.config.mjs b/sdk/durabletask/arm-durabletask/eslint.config.mjs index 113bdc3eaf5f..03244d34a19f 100644 --- a/sdk/durabletask/arm-durabletask/eslint.config.mjs +++ b/sdk/durabletask/arm-durabletask/eslint.config.mjs @@ -11,7 +11,7 @@ export default [ "@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", - "tsdoc/syntax": "warn" - } - } + "tsdoc/syntax": "warn", + }, + }, ]; diff --git a/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts b/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts index 63aa3c0cf662..6264f4426c62 100644 --- a/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts +++ b/sdk/durabletask/arm-durabletask/src/api/durableTaskContext.ts @@ -19,8 +19,7 @@ export function createDurableTask( credential: TokenCredential, options: DurableTaskClientOptionalParams = {}, ): DurableTaskContext { - const endpointUrl = - options.endpoint ?? options.baseUrl ?? `https://management.azure.com`; + const endpointUrl = options.endpoint ?? options.baseUrl ?? `https://management.azure.com`; const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; const userAgentInfo = `azsdk-js-arm-durabletask/1.0.0-beta.1`; const userAgentPrefix = prefixFromOptions diff --git a/sdk/durabletask/arm-durabletask/src/api/operations/index.ts b/sdk/durabletask/arm-durabletask/src/api/operations/index.ts index 86ac95ed3ee3..df4776cc68a6 100644 --- a/sdk/durabletask/arm-durabletask/src/api/operations/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/operations/index.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { - DurableTaskContext as Client, - OperationsListOptionalParams, -} from "../index.js"; +import { DurableTaskContext as Client, OperationsListOptionalParams } from "../index.js"; import { _OperationListResult, _operationListResultDeserializer, diff --git a/sdk/durabletask/arm-durabletask/src/api/options.ts b/sdk/durabletask/arm-durabletask/src/api/options.ts index 9a33e997e7d9..020039568e34 100644 --- a/sdk/durabletask/arm-durabletask/src/api/options.ts +++ b/sdk/durabletask/arm-durabletask/src/api/options.ts @@ -10,8 +10,7 @@ export interface OperationsListOptionalParams extends OperationOptions {} export interface SchedulersGetOptionalParams extends OperationOptions {} /** Optional parameters. */ -export interface SchedulersCreateOrUpdateOptionalParams - extends OperationOptions { +export interface SchedulersCreateOrUpdateOptionalParams extends OperationOptions { /** Delay to wait until next poll, in milliseconds. */ updateIntervalInMs?: number; } @@ -29,12 +28,10 @@ export interface SchedulersDeleteOptionalParams extends OperationOptions { } /** Optional parameters. */ -export interface SchedulersListByResourceGroupOptionalParams - extends OperationOptions {} +export interface SchedulersListByResourceGroupOptionalParams extends OperationOptions {} /** Optional parameters. */ -export interface SchedulersListBySubscriptionOptionalParams - extends OperationOptions {} +export interface SchedulersListBySubscriptionOptionalParams extends OperationOptions {} /** Optional parameters. */ export interface TaskHubsGetOptionalParams extends OperationOptions {} @@ -52,5 +49,4 @@ export interface TaskHubsDeleteOptionalParams extends OperationOptions { } /** Optional parameters. */ -export interface TaskHubsListBySchedulerOptionalParams - extends OperationOptions {} +export interface TaskHubsListBySchedulerOptionalParams extends OperationOptions {} diff --git a/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts b/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts index 8d6c144fb0bb..8ed4dae3bf09 100644 --- a/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/schedulers/index.ts @@ -47,9 +47,7 @@ export function _schedulersGetSend( .get({ ...operationOptionsToRequestParameters(options) }); } -export async function _schedulersGetDeserialize( - result: PathUncheckedResponse, -): Promise { +export async function _schedulersGetDeserialize(result: PathUncheckedResponse): Promise { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -117,25 +115,20 @@ export function schedulersCreateOrUpdate( resource: Scheduler, options: SchedulersCreateOrUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, Scheduler> { - return getLongRunningPoller( - context, - _schedulersCreateOrUpdateDeserialize, - ["200", "201"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersCreateOrUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - resource, - options, - ), - resourceLocationConfig: "azure-async-operation", - }, - ) as PollerLike, Scheduler>; + return getLongRunningPoller(context, _schedulersCreateOrUpdateDeserialize, ["200", "201"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersCreateOrUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }) as PollerLike, Scheduler>; } export function _schedulersUpdateSend( @@ -179,25 +172,20 @@ export function schedulersUpdate( properties: Scheduler, options: SchedulersUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, Scheduler> { - return getLongRunningPoller( - context, - _schedulersUpdateDeserialize, - ["200", "202"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - properties, - options, - ), - resourceLocationConfig: "location", - }, - ) as PollerLike, Scheduler>; + return getLongRunningPoller(context, _schedulersUpdateDeserialize, ["200", "202"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + properties, + options, + ), + resourceLocationConfig: "location", + }) as PollerLike, Scheduler>; } export function _schedulersDeleteSend( @@ -217,9 +205,7 @@ export function _schedulersDeleteSend( .delete({ ...operationOptionsToRequestParameters(options) }); } -export async function _schedulersDeleteDeserialize( - result: PathUncheckedResponse, -): Promise { +export async function _schedulersDeleteDeserialize(result: PathUncheckedResponse): Promise { const expectedStatuses = ["202", "204", "200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -236,24 +222,13 @@ export function schedulersDelete( schedulerName: string, options: SchedulersDeleteOptionalParams = { requestOptions: {} }, ): PollerLike, void> { - return getLongRunningPoller( - context, - _schedulersDeleteDeserialize, - ["202", "204", "200"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _schedulersDeleteSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - options, - ), - resourceLocationConfig: "location", - }, - ) as PollerLike, void>; + return getLongRunningPoller(context, _schedulersDeleteDeserialize, ["202", "204", "200"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _schedulersDeleteSend(context, subscriptionId, resourceGroupName, schedulerName, options), + resourceLocationConfig: "location", + }) as PollerLike, void>; } export function _schedulersListByResourceGroupSend( @@ -291,13 +266,7 @@ export function schedulersListByResourceGroup( ): PagedAsyncIterableIterator { return buildPagedAsyncIterator( context, - () => - _schedulersListByResourceGroupSend( - context, - subscriptionId, - resourceGroupName, - options, - ), + () => _schedulersListByResourceGroupSend(context, subscriptionId, resourceGroupName, options), _schedulersListByResourceGroupDeserialize, ["200"], { itemName: "value", nextLinkName: "nextLink" }, diff --git a/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts b/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts index 0b611635617f..33eea18f9c3a 100644 --- a/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts +++ b/sdk/durabletask/arm-durabletask/src/api/taskHubs/index.ts @@ -47,9 +47,7 @@ export function _taskHubsGetSend( .get({ ...operationOptionsToRequestParameters(options) }); } -export async function _taskHubsGetDeserialize( - result: PathUncheckedResponse, -): Promise { +export async function _taskHubsGetDeserialize(result: PathUncheckedResponse): Promise { const expectedStatuses = ["200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -122,26 +120,21 @@ export function taskHubsCreateOrUpdate( resource: TaskHub, options: TaskHubsCreateOrUpdateOptionalParams = { requestOptions: {} }, ): PollerLike, TaskHub> { - return getLongRunningPoller( - context, - _taskHubsCreateOrUpdateDeserialize, - ["200", "201"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _taskHubsCreateOrUpdateSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - taskHubName, - resource, - options, - ), - resourceLocationConfig: "azure-async-operation", - }, - ) as PollerLike, TaskHub>; + return getLongRunningPoller(context, _taskHubsCreateOrUpdateDeserialize, ["200", "201"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _taskHubsCreateOrUpdateSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + resource, + options, + ), + resourceLocationConfig: "azure-async-operation", + }) as PollerLike, TaskHub>; } export function _taskHubsDeleteSend( @@ -163,9 +156,7 @@ export function _taskHubsDeleteSend( .delete({ ...operationOptionsToRequestParameters(options) }); } -export async function _taskHubsDeleteDeserialize( - result: PathUncheckedResponse, -): Promise { +export async function _taskHubsDeleteDeserialize(result: PathUncheckedResponse): Promise { const expectedStatuses = ["202", "204", "200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); @@ -183,25 +174,20 @@ export function taskHubsDelete( taskHubName: string, options: TaskHubsDeleteOptionalParams = { requestOptions: {} }, ): PollerLike, void> { - return getLongRunningPoller( - context, - _taskHubsDeleteDeserialize, - ["202", "204", "200"], - { - updateIntervalInMs: options?.updateIntervalInMs, - abortSignal: options?.abortSignal, - getInitialResponse: () => - _taskHubsDeleteSend( - context, - subscriptionId, - resourceGroupName, - schedulerName, - taskHubName, - options, - ), - resourceLocationConfig: "location", - }, - ) as PollerLike, void>; + return getLongRunningPoller(context, _taskHubsDeleteDeserialize, ["202", "204", "200"], { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _taskHubsDeleteSend( + context, + subscriptionId, + resourceGroupName, + schedulerName, + taskHubName, + options, + ), + resourceLocationConfig: "location", + }) as PollerLike, void>; } export function _taskHubsListBySchedulerSend( diff --git a/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts b/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts index 467b1c1a9525..d51dbb4797cc 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/operations/index.ts @@ -10,21 +10,16 @@ import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.j /** Interface representing a Operations operations. */ export interface OperationsOperations { /** List the operations for the provider */ - list: ( - options?: OperationsListOptionalParams, - ) => PagedAsyncIterableIterator; + list: (options?: OperationsListOptionalParams) => PagedAsyncIterableIterator; } export function getOperations(context: DurableTaskContext) { return { - list: (options?: OperationsListOptionalParams) => - operationsList(context, options), + list: (options?: OperationsListOptionalParams) => operationsList(context, options), }; } -export function getOperationsOperations( - context: DurableTaskContext, -): OperationsOperations { +export function getOperationsOperations(context: DurableTaskContext): OperationsOperations { return { ...getOperations(context), }; diff --git a/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts b/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts index 9277a16c2ea0..a5a5ed3c5e6f 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/schedulers/index.ts @@ -61,23 +61,13 @@ export interface SchedulersOperations { ) => PagedAsyncIterableIterator; } -export function getSchedulers( - context: DurableTaskContext, - subscriptionId: string, -) { +export function getSchedulers(context: DurableTaskContext, subscriptionId: string) { return { get: ( resourceGroupName: string, schedulerName: string, options?: SchedulersGetOptionalParams, - ) => - schedulersGet( - context, - subscriptionId, - resourceGroupName, - schedulerName, - options, - ), + ) => schedulersGet(context, subscriptionId, resourceGroupName, schedulerName, options), createOrUpdate: ( resourceGroupName: string, schedulerName: string, @@ -110,27 +100,13 @@ export function getSchedulers( resourceGroupName: string, schedulerName: string, options?: SchedulersDeleteOptionalParams, - ) => - schedulersDelete( - context, - subscriptionId, - resourceGroupName, - schedulerName, - options, - ), + ) => schedulersDelete(context, subscriptionId, resourceGroupName, schedulerName, options), listByResourceGroup: ( resourceGroupName: string, options?: SchedulersListByResourceGroupOptionalParams, - ) => - schedulersListByResourceGroup( - context, - subscriptionId, - resourceGroupName, - options, - ), - listBySubscription: ( - options?: SchedulersListBySubscriptionOptionalParams, - ) => schedulersListBySubscription(context, subscriptionId, options), + ) => schedulersListByResourceGroup(context, subscriptionId, resourceGroupName, options), + listBySubscription: (options?: SchedulersListBySubscriptionOptionalParams) => + schedulersListBySubscription(context, subscriptionId, options), }; } diff --git a/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts b/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts index d020a2d3c910..18af9249c1df 100644 --- a/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts +++ b/sdk/durabletask/arm-durabletask/src/classic/taskHubs/index.ts @@ -50,10 +50,7 @@ export interface TaskHubsOperations { ) => PagedAsyncIterableIterator; } -export function getTaskHubs( - context: DurableTaskContext, - subscriptionId: string, -) { +export function getTaskHubs(context: DurableTaskContext, subscriptionId: string) { return { get: ( resourceGroupName: string, @@ -61,14 +58,7 @@ export function getTaskHubs( taskHubName: string, options?: TaskHubsGetOptionalParams, ) => - taskHubsGet( - context, - subscriptionId, - resourceGroupName, - schedulerName, - taskHubName, - options, - ), + taskHubsGet(context, subscriptionId, resourceGroupName, schedulerName, taskHubName, options), createOrUpdate: ( resourceGroupName: string, schedulerName: string, @@ -104,13 +94,7 @@ export function getTaskHubs( schedulerName: string, options?: TaskHubsListBySchedulerOptionalParams, ) => - taskHubsListByScheduler( - context, - subscriptionId, - resourceGroupName, - schedulerName, - options, - ), + taskHubsListByScheduler(context, subscriptionId, resourceGroupName, schedulerName, options), }; } diff --git a/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts b/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts index 5a9162d82ae7..b1609ecd6d1d 100644 --- a/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts +++ b/sdk/durabletask/arm-durabletask/src/durableTaskClient.ts @@ -1,18 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { - getOperationsOperations, - OperationsOperations, -} from "./classic/operations/index.js"; -import { - getSchedulersOperations, - SchedulersOperations, -} from "./classic/schedulers/index.js"; -import { - getTaskHubsOperations, - TaskHubsOperations, -} from "./classic/taskHubs/index.js"; +import { getOperationsOperations, OperationsOperations } from "./classic/operations/index.js"; +import { getSchedulersOperations, SchedulersOperations } from "./classic/schedulers/index.js"; +import { getTaskHubsOperations, TaskHubsOperations } from "./classic/taskHubs/index.js"; import { createDurableTask, DurableTaskContext, diff --git a/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts b/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts index 4baaac77c8be..7518a16c2ee9 100644 --- a/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/helpers/serializerHelpers.ts @@ -1,10 +1,9 @@ // 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, +): Record; export function serializeRecord( item: Record, serializer: (item: T) => R, @@ -33,8 +32,5 @@ export function serializeRecord( } function isSupportedRecordType(t: any) { - return ( - ["number", "string", "boolean", "null"].includes(typeof t) || - t instanceof Date - ); + return ["number", "string", "boolean", "null"].includes(typeof t) || t instanceof Date; } diff --git a/sdk/durabletask/arm-durabletask/src/index.ts b/sdk/durabletask/arm-durabletask/src/index.ts index f65ae6f98a5c..39e01d18fddf 100644 --- a/sdk/durabletask/arm-durabletask/src/index.ts +++ b/sdk/durabletask/arm-durabletask/src/index.ts @@ -47,9 +47,5 @@ export { TaskHubsDeleteOptionalParams, TaskHubsListBySchedulerOptionalParams, } from "./api/index.js"; -export { - OperationsOperations, - SchedulersOperations, - TaskHubsOperations, -} from "./classic/index.js"; +export { OperationsOperations, SchedulersOperations, TaskHubsOperations } from "./classic/index.js"; export { PageSettings, ContinuablePage, PagedAsyncIterableIterator }; diff --git a/sdk/durabletask/arm-durabletask/src/models/models.ts b/sdk/durabletask/arm-durabletask/src/models/models.ts index 218827d9b203..36e590f6ffb8 100644 --- a/sdk/durabletask/arm-durabletask/src/models/models.ts +++ b/sdk/durabletask/arm-durabletask/src/models/models.ts @@ -146,9 +146,7 @@ export function systemDataDeserializer(item: any): SystemData { return { createdBy: item["createdBy"], createdByType: item["createdByType"], - createdAt: !item["createdAt"] - ? item["createdAt"] - : new Date(item["createdAt"]), + createdAt: !item["createdAt"] ? item["createdAt"] : new Date(item["createdAt"]), lastModifiedBy: item["lastModifiedBy"], lastModifiedByType: item["lastModifiedByType"], lastModifiedAt: !item["lastModifiedAt"] @@ -261,9 +259,7 @@ export function schedulerPropertiesSerializer(item: SchedulerProperties): any { }; } -export function schedulerPropertiesDeserializer( - item: any, -): SchedulerProperties { +export function schedulerPropertiesDeserializer(item: any): SchedulerProperties { return { provisioningState: item["provisioningState"], endpoint: item["endpoint"], @@ -347,9 +343,7 @@ export interface _SchedulerListResult { nextLink?: string; } -export function _schedulerListResultDeserializer( - item: any, -): _SchedulerListResult { +export function _schedulerListResultDeserializer(item: any): _SchedulerListResult { return { value: schedulerArrayDeserializer(item["value"]), nextLink: item["nextLink"], @@ -376,9 +370,7 @@ export interface _OperationListResult { nextLink?: string; } -export function _operationListResultDeserializer( - item: any, -): _OperationListResult { +export function _operationListResultDeserializer(item: any): _OperationListResult { return { value: operationArrayDeserializer(item["value"]), nextLink: item["nextLink"], @@ -409,9 +401,7 @@ export function operationDeserializer(item: any): Operation { return { name: item["name"], isDataAction: item["isDataAction"], - display: !item["display"] - ? item["display"] - : operationDisplayDeserializer(item["display"]), + display: !item["display"] ? item["display"] : operationDisplayDeserializer(item["display"]), origin: item["origin"], actionType: item["actionType"], }; diff --git a/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts b/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts index bd87a7ea5a56..3a03060f5586 100644 --- a/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/restorePollerHelpers.ts @@ -12,10 +12,7 @@ import { _taskHubsDeleteDeserialize, } from "./api/taskHubs/index.js"; import { getLongRunningPoller } from "./static-helpers/pollingHelpers.js"; -import { - OperationOptions, - PathUncheckedResponse, -} from "@azure-rest/core-client"; +import { OperationOptions, PathUncheckedResponse } from "@azure-rest/core-client"; import { AbortSignalLike } from "@azure/abort-controller"; import { PollerLike, @@ -46,9 +43,7 @@ export interface RestorePollerOptions< export function restorePoller( client: DurableTaskClient, serializedState: string, - sourceOperation: ( - ...args: any[] - ) => PollerLike, TResult>, + sourceOperation: (...args: any[]) => PollerLike, TResult>, options?: RestorePollerOptions, ): PollerLike, TResult> { const pollerConfig = deserializeState(serializedState).config; @@ -142,24 +137,17 @@ function getDeserializationHelper( // 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 - ) { + 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] || ""); + const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test( + pathParts[j] || "", + ); if (!isMatched) { found = false; diff --git a/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts b/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts index 97a81e74e301..ce33af5f4178 100644 --- a/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/static-helpers/pagingHelpers.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { - Client, - createRestError, - PathUncheckedResponse, -} from "@azure-rest/core-client"; +import { Client, createRestError, PathUncheckedResponse } from "@azure-rest/core-client"; import { RestError } from "@azure/core-rest-pipeline"; /** @@ -43,17 +39,11 @@ export interface PagedAsyncIterableIterator< /** * The connection to the async iterator, part of the iteration protocol */ - [Symbol.asyncIterator](): PagedAsyncIterableIterator< - TElement, - TPage, - TPageSettings - >; + [Symbol.asyncIterator](): PagedAsyncIterableIterator; /** * Return an AsyncIterableIterator that works a page at a time */ - byPage: ( - settings?: TPageSettings, - ) => AsyncIterableIterator>; + byPage: (settings?: TPageSettings) => AsyncIterableIterator>; } /** @@ -71,15 +61,11 @@ export interface PagedResult< /** * A method that returns a page of results. */ - getPage: ( - pageLink?: string, - ) => Promise<{ page: TPage; nextPageLink?: string } | undefined>; + 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>; + byPage?: (settings?: TPageSettings) => AsyncIterableIterator>; /** * A function to extract elements from a page. @@ -152,9 +138,7 @@ function getPagedAsyncIterator< >( pagedResult: PagedResult, ): PagedAsyncIterableIterator { - const iter = getItemAsyncIterator( - pagedResult, - ); + const iter = getItemAsyncIterator(pagedResult); return { next() { return iter.next(); @@ -173,11 +157,7 @@ function getPagedAsyncIterator< }; } -async function* getItemAsyncIterator< - TElement, - TPage, - TPageSettings extends PageSettings, ->( +async function* getItemAsyncIterator( pagedResult: PagedResult, ): AsyncIterableIterator { const pages = getPageAsyncIterator(pagedResult); @@ -186,20 +166,14 @@ async function* getItemAsyncIterator< } } -async function* getPageAsyncIterator< - TElement, - TPage, - TPageSettings extends PageSettings, ->( +async function* getPageAsyncIterator( pagedResult: PagedResult, options: { pageLink?: string; } = {}, ): AsyncIterableIterator> { const { pageLink } = options; - let response = await pagedResult.getPage( - pageLink ?? pagedResult.firstPageLink, - ); + let response = await pagedResult.getPage(pageLink ?? pagedResult.firstPageLink); if (!response) { return; } @@ -227,11 +201,7 @@ function getNextLink(body: unknown, nextLinkName?: string): string | undefined { const nextLink = (body as Record)[nextLinkName]; - if ( - typeof nextLink !== "string" && - typeof nextLink !== "undefined" && - nextLink !== null - ) { + 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}`, ); @@ -261,10 +231,7 @@ function getElements(body: unknown, itemName: string): T[] { /** * Checks if a request failed */ -function checkPagingRequest( - response: PathUncheckedResponse, - expectedStatuses: string[], -): void { +function checkPagingRequest(response: PathUncheckedResponse, expectedStatuses: string[]): void { if (!expectedStatuses.includes(response.status)) { throw createRestError( `Pagination failed with unexpected statusCode ${response.status}`, diff --git a/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts b/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts index 2edbf783be53..f01c41bab69d 100644 --- a/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts +++ b/sdk/durabletask/arm-durabletask/src/static-helpers/pollingHelpers.ts @@ -10,11 +10,7 @@ import { OperationResponse, } from "@azure/core-lro"; -import { - Client, - PathUncheckedResponse, - createRestError, -} from "@azure-rest/core-client"; +import { Client, PathUncheckedResponse, createRestError } from "@azure-rest/core-client"; import { AbortSignalLike } from "@azure/abort-controller"; export interface GetLongRunningPollerOptions { @@ -42,10 +38,7 @@ export interface GetLongRunningPollerOptions { */ getInitialResponse?: () => PromiseLike; } -export function getLongRunningPoller< - TResponse extends PathUncheckedResponse, - TResult = void, ->( +export function getLongRunningPoller( client: Client, processResponseBody: (result: TResponse) => Promise, expectedStatuses: string[], @@ -53,18 +46,14 @@ export function getLongRunningPoller< ): PollerLike, TResult> { const { restoreFrom, getInitialResponse } = options; if (!restoreFrom && !getInitialResponse) { - throw new Error( - "Either restoreFrom or getInitialResponse must be specified", - ); + 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", - ); + throw new Error("getInitialResponse is required when initializing a new poller"); } initialResponse = await getInitialResponse(); return getLroResponse(initialResponse, expectedStatuses); diff --git a/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts b/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts index 6e425fdcfdf9..14dcd9fa397c 100644 --- a/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts +++ b/sdk/durabletask/arm-durabletask/test/public/utils/recordedClient.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { - Recorder, - RecorderStartOptions, - VitestTestContext, -} from "@azure-tools/test-recorder"; +import { Recorder, RecorderStartOptions, VitestTestContext } from "@azure-tools/test-recorder"; const replaceableVariables: Record = { SUBSCRIPTION_ID: "azure_subscription_id", @@ -20,9 +16,7 @@ const recorderEnvSetup: RecorderStartOptions = { * 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 { +export async function createRecorder(context: VitestTestContext): Promise { const recorder = new Recorder(context); await recorder.start(recorderEnvSetup); return recorder; diff --git a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json index b6586181d006..f772e6eb3b76 100644 --- a/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json +++ b/sdk/durabletask/arm-durabletask/tsconfig.browser.config.json @@ -1,14 +1,7 @@ { "extends": "./.tshy/build.json", - "include": [ - "./src/**/*.ts", - "./src/**/*.mts", - "./test/**/*.spec.ts", - "./test/**/*.mts" - ], - "exclude": [ - "./test/**/node/**/*.ts" - ], + "include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"], + "exclude": ["./test/**/node/**/*.ts"], "compilerOptions": { "outDir": "./dist-test/browser", "rootDir": ".",