diff --git a/sdk/textanalytics/ai-text-analytics/src/generated/lro/azureAsyncOperationStrategy.ts b/sdk/textanalytics/ai-text-analytics/src/generated/lro/azureAsyncOperationStrategy.ts new file mode 100644 index 000000000000..ecdc300c1ff5 --- /dev/null +++ b/sdk/textanalytics/ai-text-analytics/src/generated/lro/azureAsyncOperationStrategy.ts @@ -0,0 +1,197 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { + LROStrategy, + BaseResult, + LROOperationStep, + LROResponseInfo, + FinalStateVia +} from "./models"; +import { OperationSpec, OperationArguments } from "@azure/core-http"; +import { terminalStates } from "./constants"; +import { SendOperationFn } from "."; + +export function createAzureAsyncOperationStrategy( + initialOperation: LROOperationStep, + sendOperationFn: SendOperationFn, + finalStateVia?: FinalStateVia +): LROStrategy { + const lroData = initialOperation.result._lroData; + if (!lroData) { + throw new Error( + "Expected lroData to be defined for Azure-AsyncOperation strategy" + ); + } + + let currentOperation = initialOperation; + let lastKnownPollingUrl = + lroData.azureAsyncOperation || lroData.operationLocation; + + return { + isTerminal: () => { + const currentResult = currentOperation.result._lroData; + + if (!currentResult) { + throw new Error("Expected lroData to determine terminal status"); + } + + if (currentOperation === initialOperation) { + // Azure-AsyncOperations don't need to check for terminal state + // on originalOperation result, always need to poll + return false; + } + + const { status = "succeeded" } = currentResult; + return terminalStates.includes(status.toLowerCase()); + }, + sendFinalRequest: async () => { + if (!initialOperation.result._lroData) { + throw new Error("Expected lroData to determine terminal status"); + } + + if (!currentOperation.result._lroData) { + throw new Error("Expected lroData to determine terminal status"); + } + + const initialOperationResult = initialOperation.result._lroData; + const currentOperationResult = currentOperation.result._lroData; + + if ( + !shouldPerformFinalGet(initialOperationResult, currentOperationResult) + ) { + return currentOperation; + } + + if (initialOperationResult.requestMethod === "PUT") { + currentOperation = await sendFinalGet( + initialOperation, + sendOperationFn + ); + + return currentOperation; + } + + if (initialOperationResult.location) { + switch (finalStateVia) { + case "original-uri": + currentOperation = await sendFinalGet( + initialOperation, + sendOperationFn + ); + return currentOperation; + + case "azure-async-operation": + return currentOperation; + case "location": + default: + const location = + initialOperationResult.location || + currentOperationResult.location; + + if (!location) { + throw new Error("Couldn't determine final GET URL from location"); + } + + return await sendFinalGet( + initialOperation, + sendOperationFn, + location + ); + } + } + + // All other cases return the last operation + return currentOperation; + }, + poll: async () => { + if (!lastKnownPollingUrl) { + throw new Error("Unable to determine polling url"); + } + + const pollingArgs = currentOperation.args; + // Make sure we don't send any body to the get request + const { requestBody, ...restSpec } = currentOperation.spec; + const pollingSpec: OperationSpec = { + ...restSpec, + httpMethod: "GET", + path: lastKnownPollingUrl + }; + + const result = await sendOperationFn(pollingArgs, pollingSpec); + + // Update latest polling url + lastKnownPollingUrl = + result._lroData?.azureAsyncOperation || + result._lroData?.operationLocation || + lastKnownPollingUrl; + + // Update lastOperation result + currentOperation = { + args: pollingArgs, + spec: pollingSpec, + result + }; + + return currentOperation; + } + }; +} + +function shouldPerformFinalGet( + initialResult: LROResponseInfo, + currentResult: LROResponseInfo +) { + const { status } = currentResult; + const { requestMethod: initialRequestMethod, location } = initialResult; + if (status && status.toLowerCase() !== "succeeded") { + return false; + } + + if (initialRequestMethod === "DELETE") { + return false; + } + + if (initialRequestMethod !== "PUT" && !location) { + return false; + } + + return true; +} + +async function sendFinalGet( + initialOperation: LROOperationStep, + sendOperationFn: SendOperationFn, + path?: string +): Promise> { + // Make sure we don't send any body to the get request + const { requestBody, ...restSpec } = initialOperation.spec; + const finalGetSpec: OperationSpec = { + ...restSpec, + httpMethod: "GET" + }; + + // Send final GET request to the Original URL + const spec = { + ...finalGetSpec, + ...(path && { path }) + }; + + let operationArgs: OperationArguments = initialOperation.args; + if (operationArgs.options) { + operationArgs.options.shouldDeserialize = true; + } + + const finalResult = await sendOperationFn(initialOperation.args, spec); + + return { + args: initialOperation.args, + spec, + result: finalResult + }; +} diff --git a/sdk/textanalytics/ai-text-analytics/src/generated/lro/bodyPollingStrategy.ts b/sdk/textanalytics/ai-text-analytics/src/generated/lro/bodyPollingStrategy.ts new file mode 100644 index 000000000000..35cc6bac2a3a --- /dev/null +++ b/sdk/textanalytics/ai-text-analytics/src/generated/lro/bodyPollingStrategy.ts @@ -0,0 +1,62 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { LROStrategy, BaseResult, LROOperationStep } from "./models"; +import { OperationSpec } from "@azure/core-http"; +import { terminalStates } from "./constants"; +import { SendOperationFn } from "./lroPoller"; + +/** + * Creates a polling strategy based on BodyPolling which uses the provisioning state + * from the result to determine the current operation state + */ +export function createBodyPollingStrategy( + initialOperation: LROOperationStep, + sendOperation: SendOperationFn +): LROStrategy { + if (!initialOperation.result._lroData) { + throw new Error("Expected lroData to be defined for BodyPolling strategy"); + } + + let currentOperation = initialOperation; + + return { + isTerminal: () => { + const currentResult = currentOperation.result._lroData; + if (!currentResult) { + throw new Error("Expected lroData to determine terminal status"); + } + + const { provisioningState = "succeeded" } = currentResult; + // If provisioning state is missing, default to Success + + return terminalStates.includes(provisioningState.toLowerCase()); + }, + sendFinalRequest: () => { + // BodyPolling doesn't require a final get so return the lastOperation + return Promise.resolve(currentOperation); + }, + poll: async () => { + // When doing BodyPolling, we need to poll to the original url with a + // GET http method + const { requestBody, ...restSpec } = initialOperation.spec; + const pollingSpec: OperationSpec = { + // Make sure we don't send any body to the get request + ...restSpec, + httpMethod: "GET" + }; + + // Execute the polling operation + initialOperation.result = await sendOperation( + initialOperation.args, + pollingSpec + ); + return initialOperation; + } + }; +} diff --git a/sdk/textanalytics/ai-text-analytics/src/generated/lro/constants.ts b/sdk/textanalytics/ai-text-analytics/src/generated/lro/constants.ts new file mode 100644 index 000000000000..fa0ee2d9942c --- /dev/null +++ b/sdk/textanalytics/ai-text-analytics/src/generated/lro/constants.ts @@ -0,0 +1,9 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +export const terminalStates = ["succeeded", "failed", "canceled", "cancelled"]; diff --git a/sdk/textanalytics/ai-text-analytics/src/generated/lro/index.ts b/sdk/textanalytics/ai-text-analytics/src/generated/lro/index.ts new file mode 100644 index 000000000000..f605ce7ee356 --- /dev/null +++ b/sdk/textanalytics/ai-text-analytics/src/generated/lro/index.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +export { shouldDeserializeLRO } from "./requestUtils"; +export { createBodyPollingStrategy } from "./bodyPollingStrategy"; +export { terminalStates } from "./constants"; +export { lroPolicy } from "./lroPolicy"; +export { LROPoller, LROPollerOptions, SendOperationFn } from "./lroPoller"; +export { + LROResponseInfo, + BaseResult, + LROOperationStep, + LROOperationState, + LROStrategy, + LROOperation +} from "./models"; +export { makeOperation } from "./operation"; +export * from "./locationStrategy"; diff --git a/sdk/textanalytics/ai-text-analytics/src/generated/lro/locationStrategy.ts b/sdk/textanalytics/ai-text-analytics/src/generated/lro/locationStrategy.ts new file mode 100644 index 000000000000..1a5c8d462eac --- /dev/null +++ b/sdk/textanalytics/ai-text-analytics/src/generated/lro/locationStrategy.ts @@ -0,0 +1,74 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { BaseResult, LROOperationStep, LROStrategy } from "./models"; +import { SendOperationFn } from "./lroPoller"; +import { OperationSpec } from "@azure/core-http"; + +export function createLocationStrategy( + initialOperation: LROOperationStep, + sendOperationFn: SendOperationFn +): LROStrategy { + const lroData = initialOperation.result._lroData; + if (!lroData) { + throw new Error( + "Expected lroData to be defined for Azure-AsyncOperation strategy" + ); + } + + let currentOperation = initialOperation; + let lastKnownPollingUrl = lroData.location; + + return { + isTerminal: () => { + const currentResult = currentOperation.result._lroData; + if (!currentResult) { + throw new Error("Expected lroData to determine terminal status"); + } + + if (currentOperation === initialOperation) { + return false; + } + + if (currentResult.statusCode === 202) { + return false; + } + + return true; + }, + sendFinalRequest: () => Promise.resolve(currentOperation), + poll: async () => { + if (!lastKnownPollingUrl) { + throw new Error("Unable to determine polling url"); + } + + const pollingArgs = currentOperation.args; + // Make sure we don't send any body to the get request + const { requestBody, ...restSpec } = currentOperation.spec; + const pollingSpec: OperationSpec = { + ...restSpec, + httpMethod: "GET", + path: lastKnownPollingUrl + }; + + const result = await sendOperationFn(pollingArgs, pollingSpec); + + // Update latest polling url + lastKnownPollingUrl = result._lroData?.location || lastKnownPollingUrl; + + // Update lastOperation result + currentOperation = { + args: pollingArgs, + spec: pollingSpec, + result + }; + + return currentOperation; + } + }; +} diff --git a/sdk/textanalytics/ai-text-analytics/src/generated/lro/lroPolicy.ts b/sdk/textanalytics/ai-text-analytics/src/generated/lro/lroPolicy.ts new file mode 100644 index 000000000000..0591f541b30a --- /dev/null +++ b/sdk/textanalytics/ai-text-analytics/src/generated/lro/lroPolicy.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { + RequestPolicy, + RequestPolicyOptions, + BaseRequestPolicy, + HttpOperationResponse, + WebResource +} from "@azure/core-http"; +import { getLROData } from "./requestUtils"; + +export function lroPolicy() { + return { + create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => { + return new LROPolicy(nextPolicy, options); + } + }; +} + +class LROPolicy extends BaseRequestPolicy { + constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions) { + super(nextPolicy, options); + } + + public async sendRequest( + webResource: WebResource + ): Promise { + let result = await this._nextPolicy.sendRequest(webResource); + + if (webResource.shouldDeserialize !== undefined) { + const _lroData = getLROData(result); + result.parsedBody = { ...result.parsedBody, _lroData }; + } + + return result; + } +} diff --git a/sdk/textanalytics/ai-text-analytics/src/generated/lro/lroPoller.ts b/sdk/textanalytics/ai-text-analytics/src/generated/lro/lroPoller.ts new file mode 100644 index 000000000000..bc2f2aa05a24 --- /dev/null +++ b/sdk/textanalytics/ai-text-analytics/src/generated/lro/lroPoller.ts @@ -0,0 +1,154 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { Poller } from "@azure/core-lro"; +import { + OperationSpec, + OperationArguments, + delay, + RestError +} from "@azure/core-http"; +import { + BaseResult, + LROOperationState, + LROOperationStep, + FinalStateVia +} from "./models"; +import { makeOperation } from "./operation"; +import { createBodyPollingStrategy } from "./bodyPollingStrategy"; +import { createAzureAsyncOperationStrategy } from "./azureAsyncOperationStrategy"; +import { createLocationStrategy } from "./locationStrategy"; +import { createPassthroughStrategy } from "./passthroughStrategy"; + +export type SendOperationFn = ( + args: OperationArguments, + spec: OperationSpec +) => Promise; + +export interface LROPollerOptions { + /** + * Defines how much time the poller is going to wait before making a new request to the service. + */ + intervalInMs?: number; + /** + * Arguments used to send the initial operation + */ + initialOperationArguments: OperationArguments; + /** + * Operation spec provided for the initial operation + */ + initialOperationSpec: OperationSpec; + /** + * Result from the initial operation + */ + initialOperationResult: TResult; + /** + * Function to execute an operation based on an operation spec and arguments + */ + sendOperation: SendOperationFn; + /** + * Optional information on where to poll. When not defined it defaults to "Location" + */ + finalStateVia?: FinalStateVia; +} + +export class LROPoller extends Poller< + LROOperationState, + TResult +> { + private intervalInMs: number; + + constructor({ + initialOperationArguments, + initialOperationResult, + initialOperationSpec, + sendOperation, + finalStateVia, + intervalInMs = 2000 + }: LROPollerOptions) { + const initialOperation = { + args: initialOperationArguments, + spec: initialOperationSpec, + result: initialOperationResult + }; + + const pollingStrategy = getPollingStrategy( + initialOperation, + sendOperation, + finalStateVia + ); + + const state: LROOperationState = { + // Initial operation will become the last operation + initialOperation, + lastOperation: initialOperation, + pollingStrategy, + finalStateVia + }; + + const operation = makeOperation(state); + super(operation); + + this.intervalInMs = intervalInMs; + } + + /** + * The method used by the poller to wait before attempting to update its operation. + */ + delay(): Promise { + return delay(this.intervalInMs); + } +} + +/** + * This function determines which strategy to use based on the response from + * the last operation executed, this last operation can be an initial operation + * or a polling operation. The 3 possible strategies are described below: + * + * A) Azure-AsyncOperation or Operation-Location + * B) Location + * C) BodyPolling (provisioningState) + * - This strategy is used when: + * - Response doesn't contain any of the following headers Location, Azure-AsyncOperation or Operation-Location + * - Last operation method is PUT + */ +function getPollingStrategy( + initialOperation: LROOperationStep, + sendOperationFn: SendOperationFn, + finalStateVia?: FinalStateVia +) { + const lroData = initialOperation.result._lroData; + + if (!lroData) { + const error = new RestError( + "Service response doesn't include the required LRO data to continue polling" + ); + error.statusCode = initialOperation.result._response.status; + error.response = initialOperation.result._response; + throw error; + } + + if (lroData.azureAsyncOperation || lroData.operationLocation) { + return createAzureAsyncOperationStrategy( + initialOperation, + sendOperationFn, + finalStateVia + ); + } + + if (lroData.location) { + return createLocationStrategy(initialOperation, sendOperationFn); + } + + if (["PUT", "PATCH"].includes(lroData.requestMethod || "")) { + return createBodyPollingStrategy(initialOperation, sendOperationFn); + } + + // Default strategy is just a passthrough returning the initial operation + return createPassthroughStrategy(initialOperation); +} diff --git a/sdk/textanalytics/ai-text-analytics/src/generated/lro/models.ts b/sdk/textanalytics/ai-text-analytics/src/generated/lro/models.ts new file mode 100644 index 000000000000..a90afc5b41de --- /dev/null +++ b/sdk/textanalytics/ai-text-analytics/src/generated/lro/models.ts @@ -0,0 +1,60 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { + OperationArguments, + OperationSpec, + RestResponse, + HttpMethods +} from "@azure/core-http"; +import { PollOperationState, PollOperation } from "@azure/core-lro"; + +export type FinalStateVia = + | "azure-async-operation" + | "location" + | "original-uri"; + +export interface LROResponseInfo { + requestMethod: HttpMethods; + statusCode: number; + isInitialRequest?: boolean; + azureAsyncOperation?: string; + operationLocation?: string; + location?: string; + provisioningState?: string; + status?: string; +} + +export interface BaseResult extends RestResponse { + _lroData?: LROResponseInfo; +} + +export interface LROOperationStep { + args: OperationArguments; + spec: OperationSpec; + result: TResult; +} + +export interface LROOperationState + extends PollOperationState { + lastOperation: LROOperationStep; + initialOperation: LROOperationStep; + pollingStrategy: LROStrategy; + finalStateVia?: FinalStateVia; +} + +export interface LROStrategy { + isTerminal: () => boolean; + sendFinalRequest: () => Promise>; + poll: () => Promise>; +} + +export type LROOperation = PollOperation< + LROOperationState, + TResult +>; diff --git a/sdk/textanalytics/ai-text-analytics/src/generated/lro/operation.ts b/sdk/textanalytics/ai-text-analytics/src/generated/lro/operation.ts new file mode 100644 index 000000000000..9cda560a0212 --- /dev/null +++ b/sdk/textanalytics/ai-text-analytics/src/generated/lro/operation.ts @@ -0,0 +1,82 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { BaseResult, LROOperationState, LROOperation } from "./models"; + +/** + * Creates a copy of the operation from a given State + */ +export function makeOperation( + state: LROOperationState +): LROOperation { + return { + state: { ...state }, + update, + cancel, + toString: function(this: LROOperation) { + return JSON.stringify(this.state); + } + }; +} + +/** + * General update function for LROPoller, the general process is as follows + * 1. Check initial operation result to determine the strategy to use + * - Strategies: Location, Azure-AsyncOperation, Original Uri + * 2. Check if the operation result has a terminal state + * - Terminal state will be determined by each strategy + * 2.1 If it is terminal state Check if a final GET request is required, if so + * send final GET request and return result from operation. If no final GET + * is required, just return the result from operation. + * - Determining what to call for final request is responsibility of each strategy + * 2.2 If it is not terminal state, call the polling operation call it and go to step 1 + * - Determining what to call for polling is responsibility of each strategy + * - Strategies will always use the latest URI for polling if provided otherwise + * the last known one + */ +async function update( + this: LROOperation +): Promise> { + const state = { ...this.state }; + + const { sendFinalRequest, poll, isTerminal } = state.pollingStrategy; + const currentResponse = state.lastOperation; + const currentLroData = currentResponse.result._lroData; + + if (!currentLroData) { + throw new Error( + "Expected lroData to be defined for updating LRO operation" + ); + } + + if (state.result) { + state.isCompleted = true; + return makeOperation(state); + } + + // Check if last result is terminal + if (isTerminal()) { + state.lastOperation = await sendFinalRequest(); + state.result = state.lastOperation.result; + } else { + state.lastOperation = await poll(); + } + + // Return operation + return makeOperation(state); +} + +/** + * Swagger doesn't support defining a cancel operation, we'll just mark + * the operation state as cancelled + */ +async function cancel( + this: LROOperation +): Promise> { + return makeOperation({ ...this.state, isCancelled: true }); +} diff --git a/sdk/textanalytics/ai-text-analytics/src/generated/lro/passthroughStrategy.ts b/sdk/textanalytics/ai-text-analytics/src/generated/lro/passthroughStrategy.ts new file mode 100644 index 000000000000..23342c2e4ec7 --- /dev/null +++ b/sdk/textanalytics/ai-text-analytics/src/generated/lro/passthroughStrategy.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { LROStrategy, BaseResult, LROOperationStep } from "./models"; + +/** + * Creates a polling strategy based on BodyPolling which uses the provisioning state + * from the result to determine the current operation state + */ +export function createPassthroughStrategy( + initialOperation: LROOperationStep +): LROStrategy { + return { + isTerminal: () => { + return true; + }, + sendFinalRequest: () => { + // BodyPolling doesn't require a final get so return the lastOperation + return Promise.resolve(initialOperation); + }, + poll: async () => { + throw new Error("Passthrough strategy should never poll"); + } + }; +} diff --git a/sdk/textanalytics/ai-text-analytics/src/generated/lro/requestUtils.ts b/sdk/textanalytics/ai-text-analytics/src/generated/lro/requestUtils.ts new file mode 100644 index 000000000000..e9af4cde5e25 --- /dev/null +++ b/sdk/textanalytics/ai-text-analytics/src/generated/lro/requestUtils.ts @@ -0,0 +1,117 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { HttpOperationResponse } from "@azure/core-http"; +import { terminalStates } from "./constants"; +import { LROResponseInfo } from "./models"; + +/** + * We need to selectively deserialize our responses, only deserializing if we + * are in a final LRO response, not deserializing any polling non-terminal responses + */ +export function shouldDeserializeLRO(finalStateVia?: string) { + let initialOperationInfo: LROResponseInfo | undefined; + let isInitialRequest = true; + + return (response: HttpOperationResponse) => { + if (response.status < 200 || response.status >= 300) { + return true; + } + + if (!initialOperationInfo) { + initialOperationInfo = getLROData(response); + } else { + isInitialRequest = false; + } + + if ( + initialOperationInfo.azureAsyncOperation || + initialOperationInfo.operationLocation + ) { + return ( + !isInitialRequest && + isAsyncOperationFinalResponse( + response, + initialOperationInfo, + finalStateVia + ) + ); + } + + if (initialOperationInfo.location) { + return isLocationFinalResponse(response); + } + + if (initialOperationInfo.requestMethod === "PUT") { + return isBodyPollingFinalResponse(response); + } + + return true; + }; +} + +function isAsyncOperationFinalResponse( + response: HttpOperationResponse, + initialOperationInfo: LROResponseInfo, + finalStateVia?: string +): boolean { + const status: string = response.parsedBody?.status || "Succeeded"; + if (!terminalStates.includes(status.toLowerCase())) { + return false; + } + + if (initialOperationInfo.requestMethod === "DELETE") { + return true; + } + + if ( + initialOperationInfo.requestMethod === "PUT" && + finalStateVia && + finalStateVia.toLowerCase() === "azure-asyncoperation" + ) { + return true; + } + + if ( + initialOperationInfo.requestMethod !== "PUT" && + !initialOperationInfo.location + ) { + return true; + } + + return false; +} + +function isLocationFinalResponse(response: HttpOperationResponse): boolean { + return response.status !== 202; +} + +function isBodyPollingFinalResponse(response: HttpOperationResponse): boolean { + const provisioningState: string = + response.parsedBody?.properties?.provisioningState || "Succeeded"; + + if (terminalStates.includes(provisioningState.toLowerCase())) { + return true; + } + + return false; +} + +export function getLROData(result: HttpOperationResponse): LROResponseInfo { + const statusCode = result.status; + const { status, properties } = result.parsedBody || {}; + return { + statusCode, + azureAsyncOperation: result.headers.get("azure-asyncoperation"), + operationLocation: result.headers.get("operation-location"), + location: result.headers.get("location"), + requestMethod: result.request.method, + status, + provisioningState: properties?.provisioningState + }; +} diff --git a/sdk/textanalytics/ai-text-analytics/swagger/README.md b/sdk/textanalytics/ai-text-analytics/swagger/README.md index 6702828fb6ce..b04a3c740082 100644 --- a/sdk/textanalytics/ai-text-analytics/swagger/README.md +++ b/sdk/textanalytics/ai-text-analytics/swagger/README.md @@ -12,7 +12,7 @@ generate-metadata: false license-header: MICROSOFT_MIT_NO_VERSION output-folder: ../ source-code-folder-path: ./src/generated -input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs-pr/9146c425a4e87f328a7088619eeac24d8fc72468/specification/cognitiveservices/data-plane/TextAnalytics/preview/v3.2-preview.1/TextAnalytics.json?token=ABOLCKK3EIM6VPRKMJ3T5ZC7PM5XG +input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/bafc27ea426c181587f7488b09ed0050e82d1c76/specification/cognitiveservices/data-plane/TextAnalytics/preview/v3.2-preview.1/TextAnalytics.json add-credentials: false package-version: 5.2.0-beta.1 v3: true