@azure/core-lro 3.2.0-alpha.20250325.2 → 3.2.0-alpha.20250326.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -109,5 +109,9 @@ export interface CreateHttpPollerOptions<TResult, TState> {
109
109
  * Control whether to throw an exception if the operation failed or was canceled.
110
110
  */
111
111
  resolveOnUnsuccessful?: boolean;
112
+ /**
113
+ * A flag to skip the final GET request that would normally fetch the final resource
114
+ */
115
+ skipFinalGet?: boolean;
112
116
  }
113
117
  //# sourceMappingURL=models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * The base URL to use when making requests.\n */\n baseUrl?: string;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * The base URL to use when making requests.\n */\n baseUrl?: string;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n /**\n * A flag to skip the final GET request that would normally fetch the final resource\n */\n skipFinalGet?: boolean;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { HttpOperationMode, RunningOperation, ResourceLocationConfig, OperationResponse, RawResponse } from "./models.js";
2
2
  import type { LroError, OperationConfig, OperationState, OperationStatus, RestorableOperationState } from "../poller/models.js";
3
3
  import type { AbortSignalLike } from "@azure/abort-controller";
4
- export declare function inferLroMode(rawResponse: RawResponse, resourceLocationConfig?: ResourceLocationConfig): (OperationConfig & {
4
+ export declare function inferLroMode(rawResponse: RawResponse, resourceLocationConfig?: ResourceLocationConfig, skipFinalGet?: boolean): (OperationConfig & {
5
5
  mode: HttpOperationMode;
6
6
  }) | undefined;
7
7
  export declare function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined;
@@ -17,7 +17,11 @@ function getAzureAsyncOperationHeader(rawResponse) {
17
17
  }
18
18
  function findResourceLocation(inputs) {
19
19
  var _a;
20
- const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;
20
+ const { location, requestMethod, requestPath, resourceLocationConfig, skipFinalGet } = inputs;
21
+ // If skipFinalGet is true, return undefined to skip the final GET request
22
+ if (skipFinalGet) {
23
+ return undefined;
24
+ }
21
25
  switch (requestMethod) {
22
26
  case "PUT": {
23
27
  return requestPath;
@@ -48,7 +52,7 @@ function findResourceLocation(inputs) {
48
52
  }
49
53
  }
50
54
  }
51
- export function inferLroMode(rawResponse, resourceLocationConfig) {
55
+ export function inferLroMode(rawResponse, resourceLocationConfig, skipFinalGet) {
52
56
  const requestPath = rawResponse.request.url;
53
57
  const requestMethod = rawResponse.request.method;
54
58
  const operationLocation = getOperationLocationHeader(rawResponse);
@@ -65,6 +69,7 @@ export function inferLroMode(rawResponse, resourceLocationConfig) {
65
69
  location,
66
70
  requestPath,
67
71
  resourceLocationConfig,
72
+ skipFinalGet,
68
73
  }),
69
74
  initialRequestUrl: requestPath,
70
75
  requestMethod,
@@ -1 +1 @@
1
- {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBlC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAC1D,OAAO,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,mBAAmB,CAAC;AAClD,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAwB;IACjD,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,0BAA0B,CAAC,WAAwB;IAC1D,OAAO,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,4BAA4B,CAAC,WAAwB;IAC5D,OAAO,WAAW,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,oBAAoB,CAAC,MAK7B;;IACC,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG,MAAM,CAAC;IAChF,QAAQ,aAAa,EAAE,CAAC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AY,EAAE,UAAU,CAAC;YAC3E,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;QAC1D,QAAQ,EAAE,oBAAoB;QAC9B,WAAW;QACX,kBAAkB,EAAE,eAAe;QACnC,oBAAoB;QACpB,kBAAkB;QAClB,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault(): string | undefined {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBlC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAC1D,OAAO,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,mBAAmB,CAAC;AAClD,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAwB;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gB,GAAG,GAAG,CAAC;IACtC,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,CAAC,gBAAgB,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,CAAQ;IACvC,OAAO,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC;AAChC,CAAC;AAED,wCAAwC;AACxC,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAkD,MASxF;IACC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;IAC/F,OAAO,aAAa,CAAC;QACnB,KAAK;QACL,QAAQ;QACR,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,UAAU,CAAC;YAC3E,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;QAC1D,QAAQ,EAAE,oBAAoB;QAC9B,WAAW;QACX,kBAAkB,EAAE,eAAe;QACnC,oBAAoB;QACpB,kBAAkB;QAClB,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n skipFinalGet?: boolean;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig, skipFinalGet } = inputs;\n\n // If skipFinalGet is true, return undefined to skip the final GET request\n if (skipFinalGet) {\n return undefined;\n }\n\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault(): string | undefined {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n skipFinalGet?: boolean,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n skipFinalGet,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
@@ -10,7 +10,7 @@ import { rewriteUrl } from "./utils.js";
10
10
  * @returns an initialized poller
11
11
  */
12
12
  export function createHttpPoller(lro, options) {
13
- const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, baseUrl, } = options || {};
13
+ const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, baseUrl, skipFinalGet, } = options || {};
14
14
  return buildCreatePoller({
15
15
  getStatusFromInitialResponse,
16
16
  getStatusFromPollResponse: getOperationStatus,
@@ -23,7 +23,7 @@ export function createHttpPoller(lro, options) {
23
23
  })({
24
24
  init: async () => {
25
25
  const response = await lro.sendInitialRequest();
26
- const config = inferLroMode(response.rawResponse, resourceLocationConfig);
26
+ const config = inferLroMode(response.rawResponse, resourceLocationConfig, skipFinalGet);
27
27
  return Object.assign({ response, operationLocation: rewriteUrl({ url: config === null || config === void 0 ? void 0 : config.operationLocation, baseUrl }), resourceLocation: rewriteUrl({ url: config === null || config === void 0 ? void 0 : config.resourceLocation, baseUrl }), initialRequestUrl: config === null || config === void 0 ? void 0 : config.initialRequestUrl, requestMethod: config === null || config === void 0 ? void 0 : config.requestMethod }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
28
28
  },
29
29
  poll: lro.sendPollRequest,
@@ -1 +1 @@
1
- {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,oBAAoB,EACpB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AC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,EAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC5D;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\nimport { rewriteUrl } from \"./utils.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n baseUrl,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig);\n return {\n response,\n operationLocation: rewriteUrl({ url: config?.operationLocation, baseUrl }),\n resourceLocation: rewriteUrl({ url: config?.resourceLocation, baseUrl }),\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
1
+ {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,4BAA4B,EAC5B,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAqB,EACrB,OAAkD;IAElD,MAAM,EACJ,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,qBAAqB,GAAG,KAAK,EAC7B,OAAO,EACP,YAAY,GACb,GAAG,OAAO,IAAI,EAAE,CAAC;IAClB,OAAO,iBAAiB,CAAqC;QAC3D,4BAA4B;QAC5B,yBAAyB,EAAE,kBAAkB;QAC7C,gBAAgB;QAChB,oBAAoB;QACpB,mBAAmB;QACn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\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\nimport { rewriteUrl } from \"./utils.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n baseUrl,\n skipFinalGet,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig, skipFinalGet);\n return {\n response,\n operationLocation: rewriteUrl({ url: config?.operationLocation, baseUrl }),\n resourceLocation: rewriteUrl({ url: config?.resourceLocation, baseUrl }),\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
@@ -109,5 +109,9 @@ export interface CreateHttpPollerOptions<TResult, TState> {
109
109
  * Control whether to throw an exception if the operation failed or was canceled.
110
110
  */
111
111
  resolveOnUnsuccessful?: boolean;
112
+ /**
113
+ * A flag to skip the final GET request that would normally fetch the final resource
114
+ */
115
+ skipFinalGet?: boolean;
112
116
  }
113
117
  //# sourceMappingURL=models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * The base URL to use when making requests.\n */\n baseUrl?: string;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * The base URL to use when making requests.\n */\n baseUrl?: string;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n /**\n * A flag to skip the final GET request that would normally fetch the final resource\n */\n skipFinalGet?: boolean;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { HttpOperationMode, RunningOperation, ResourceLocationConfig, OperationResponse, RawResponse } from "./models.js";
2
2
  import type { LroError, OperationConfig, OperationState, OperationStatus, RestorableOperationState } from "../poller/models.js";
3
3
  import type { AbortSignalLike } from "@azure/abort-controller";
4
- export declare function inferLroMode(rawResponse: RawResponse, resourceLocationConfig?: ResourceLocationConfig): (OperationConfig & {
4
+ export declare function inferLroMode(rawResponse: RawResponse, resourceLocationConfig?: ResourceLocationConfig, skipFinalGet?: boolean): (OperationConfig & {
5
5
  mode: HttpOperationMode;
6
6
  }) | undefined;
7
7
  export declare function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined;
@@ -28,7 +28,11 @@ function getAzureAsyncOperationHeader(rawResponse) {
28
28
  }
29
29
  function findResourceLocation(inputs) {
30
30
  var _a;
31
- const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;
31
+ const { location, requestMethod, requestPath, resourceLocationConfig, skipFinalGet } = inputs;
32
+ // If skipFinalGet is true, return undefined to skip the final GET request
33
+ if (skipFinalGet) {
34
+ return undefined;
35
+ }
32
36
  switch (requestMethod) {
33
37
  case "PUT": {
34
38
  return requestPath;
@@ -59,7 +63,7 @@ function findResourceLocation(inputs) {
59
63
  }
60
64
  }
61
65
  }
62
- function inferLroMode(rawResponse, resourceLocationConfig) {
66
+ function inferLroMode(rawResponse, resourceLocationConfig, skipFinalGet) {
63
67
  const requestPath = rawResponse.request.url;
64
68
  const requestMethod = rawResponse.request.method;
65
69
  const operationLocation = getOperationLocationHeader(rawResponse);
@@ -76,6 +80,7 @@ function inferLroMode(rawResponse, resourceLocationConfig) {
76
80
  location,
77
81
  requestPath,
78
82
  resourceLocationConfig,
83
+ skipFinalGet,
79
84
  }),
80
85
  initialRequestUrl: requestPath,
81
86
  requestMethod,
@@ -1 +1 @@
1
- {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAgFlC,oCAyCC;AAqDD,0CAUC;AAED,oDAeC;AAWD,oEAsBC;AAED,oDAoBC;AAED,gDAkBC;AASD,kDASC;AAED,4CAEC;AAGD,8CAiCC;AA7TD,yDAAuD;AAEvD,4CAAsC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAC1D,OAAO,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,mBAAmB,CAAC;AAClD,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAwB;IACjD,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,0BAA0B,CAAC,WAAwB;IAC1D,OAAO,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,4BAA4B,CAAC,WAAwB;IAC5D,OAAO,WAAW,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,oBAAoB,CAAC,MAK7B;;IACC,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG,MAAM,CAAC;IAChF,QAAQ,aAAa,EAAE,CAAC;QACtB,KAAK,KAAK,CAAC,CAAC,CAAC;YACX,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CA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,EAAE,eAAe;QACnC,oBAAoB;QACpB,kBAAkB;QAClB,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault(): string | undefined {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAuFlC,oCA2CC;AAqDD,0CAUC;AAED,oDAeC;AAWD,oEAsBC;AAED,oDAoBC;AAED,gDAkBC;AASD,kDASC;AAED,4CAEC;AAGD,8CAiCC;AAtUD,yDAAuD;AAEvD,4CAAsC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAC1D,OAAO,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,mBAAmB,CAAC;AAClD,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAwB;IACjD,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,0BAA0B,CAAC,W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AAQ;IACvC,OAAO,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC;AAChC,CAAC;AAED,wCAAwC;AACjC,KAAK,UAAU,iBAAiB,CAAkD,MASxF;IACC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;IAC/F,OAAO,IAAA,4BAAa,EAAC;QACnB,KAAK;QACL,QAAQ;QACR,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,UAAU,CAAC;YAC3E,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;QAC1D,QAAQ,EAAE,oBAAoB;QAC9B,WAAW;QACX,kBAAkB,EAAE,eAAe;QACnC,oBAAoB;QACpB,kBAAkB;QAClB,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n skipFinalGet?: boolean;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig, skipFinalGet } = inputs;\n\n // If skipFinalGet is true, return undefined to skip the final GET request\n if (skipFinalGet) {\n return undefined;\n }\n\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault(): string | undefined {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n skipFinalGet?: boolean,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n skipFinalGet,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
@@ -13,7 +13,7 @@ const utils_js_1 = require("./utils.js");
13
13
  * @returns an initialized poller
14
14
  */
15
15
  function createHttpPoller(lro, options) {
16
- const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, baseUrl, } = options || {};
16
+ const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, baseUrl, skipFinalGet, } = options || {};
17
17
  return (0, poller_js_1.buildCreatePoller)({
18
18
  getStatusFromInitialResponse: operation_js_1.getStatusFromInitialResponse,
19
19
  getStatusFromPollResponse: operation_js_1.getOperationStatus,
@@ -26,7 +26,7 @@ function createHttpPoller(lro, options) {
26
26
  })({
27
27
  init: async () => {
28
28
  const response = await lro.sendInitialRequest();
29
- const config = (0, operation_js_1.inferLroMode)(response.rawResponse, resourceLocationConfig);
29
+ const config = (0, operation_js_1.inferLroMode)(response.rawResponse, resourceLocationConfig, skipFinalGet);
30
30
  return Object.assign({ response, operationLocation: (0, utils_js_1.rewriteUrl)({ url: config === null || config === void 0 ? void 0 : config.operationLocation, baseUrl }), resourceLocation: (0, utils_js_1.rewriteUrl)({ url: config === null || config === void 0 ? void 0 : config.resourceLocation, baseUrl }), initialRequestUrl: config === null || config === void 0 ? void 0 : config.initialRequestUrl, requestMethod: config === null || config === void 0 ? void 0 : config.requestMethod }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
31
31
  },
32
32
  poll: lro.sendPollRequest,
@@ -1 +1 @@
1
- {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAwBlC,4CAiDC;AArED,iDASwB;AAExB,mDAAwD;AACxD,yCAAwC;AAExC;;;;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CAAC,CAAC,EAAE,CAAC,EAC5D;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\nimport { rewriteUrl } from \"./utils.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n baseUrl,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig);\n return {\n response,\n operationLocation: rewriteUrl({ url: config?.operationLocation, baseUrl }),\n resourceLocation: rewriteUrl({ url: config?.resourceLocation, baseUrl }),\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
1
+ {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAwBlC,4CAkDC;AAtED,iDASwB;AAExB,mDAAwD;AACxD,yCAAwC;AAExC;;;;;GAKG;AACH,SAAgB,gBAAgB,CAC9B,GAAqB,EACrB,OAAkD;IAElD,MAAM,EACJ,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,qBAAqB,GAAG,KAAK,EAC7B,OAAO,EACP,YAAY,GACb,GAAG,OAAO,IAAI,EAAE,CAAC;IAClB,OAAO,IAAA,6BAAiB,EAAqC;QAC3D,4BAA4B,EAA5B,2CAA4B;QAC5B,yBAAyB,EAAE,iCAAkB;QAC7C,gBAAgB,EAAhB,+BAAgB;QAChB,oBAAoB,EAApB,mCAAoB;QACpB,mBAAmB,EAAnB,kCAAmB;QACnB,kBAAkB,EAAE,8BAAe;QACnC,QAAQ,EAAE,mCAAoB;QAC9B,qBAAqB;KACtB,CAAC,CACA;QACE,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,kBAAkB,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,IAAA,2BAAY,EAAC,QAAQ,CAAC,WAAW,EAAE,sBAAsB,EAAE,YAAY,CAAC,CAAC;YACxF,uBACE,QAAQ,EACR,iBAAiB,EAAE,IAAA,qBAAU,EAAC,EAAE,GAAG,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAAE,OAAO,EAAE,CAAC,EAC1E,gBAAgB,EAAE,IAAA,qBAAU,EAAC,EAAE,GAAG,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC,EACxE,iBAAiB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAC5C,aAAa,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,IACjC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,EAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC5D;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\nimport { rewriteUrl } from \"./utils.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n baseUrl,\n skipFinalGet,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig, skipFinalGet);\n return {\n response,\n operationLocation: rewriteUrl({ url: config?.operationLocation, baseUrl }),\n resourceLocation: rewriteUrl({ url: config?.resourceLocation, baseUrl }),\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
@@ -109,5 +109,9 @@ export interface CreateHttpPollerOptions<TResult, TState> {
109
109
  * Control whether to throw an exception if the operation failed or was canceled.
110
110
  */
111
111
  resolveOnUnsuccessful?: boolean;
112
+ /**
113
+ * A flag to skip the final GET request that would normally fetch the final resource
114
+ */
115
+ skipFinalGet?: boolean;
112
116
  }
113
117
  //# sourceMappingURL=models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * The base URL to use when making requests.\n */\n baseUrl?: string;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * The base URL to use when making requests.\n */\n baseUrl?: string;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n /**\n * A flag to skip the final GET request that would normally fetch the final resource\n */\n skipFinalGet?: boolean;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { HttpOperationMode, RunningOperation, ResourceLocationConfig, OperationResponse, RawResponse } from "./models.js";
2
2
  import type { LroError, OperationConfig, OperationState, OperationStatus, RestorableOperationState } from "../poller/models.js";
3
3
  import type { AbortSignalLike } from "@azure/abort-controller";
4
- export declare function inferLroMode(rawResponse: RawResponse, resourceLocationConfig?: ResourceLocationConfig): (OperationConfig & {
4
+ export declare function inferLroMode(rawResponse: RawResponse, resourceLocationConfig?: ResourceLocationConfig, skipFinalGet?: boolean): (OperationConfig & {
5
5
  mode: HttpOperationMode;
6
6
  }) | undefined;
7
7
  export declare function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined;
@@ -17,7 +17,11 @@ function getAzureAsyncOperationHeader(rawResponse) {
17
17
  }
18
18
  function findResourceLocation(inputs) {
19
19
  var _a;
20
- const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;
20
+ const { location, requestMethod, requestPath, resourceLocationConfig, skipFinalGet } = inputs;
21
+ // If skipFinalGet is true, return undefined to skip the final GET request
22
+ if (skipFinalGet) {
23
+ return undefined;
24
+ }
21
25
  switch (requestMethod) {
22
26
  case "PUT": {
23
27
  return requestPath;
@@ -48,7 +52,7 @@ function findResourceLocation(inputs) {
48
52
  }
49
53
  }
50
54
  }
51
- export function inferLroMode(rawResponse, resourceLocationConfig) {
55
+ export function inferLroMode(rawResponse, resourceLocationConfig, skipFinalGet) {
52
56
  const requestPath = rawResponse.request.url;
53
57
  const requestMethod = rawResponse.request.method;
54
58
  const operationLocation = getOperationLocationHeader(rawResponse);
@@ -65,6 +69,7 @@ export function inferLroMode(rawResponse, resourceLocationConfig) {
65
69
  location,
66
70
  requestPath,
67
71
  resourceLocationConfig,
72
+ skipFinalGet,
68
73
  }),
69
74
  initialRequestUrl: requestPath,
70
75
  requestMethod,
@@ -1 +1 @@
1
- {"version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ourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault(): string | undefined {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBlC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAC1D,OAAO,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,mBAAmB,CAAC;AAClD,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAwB;IACjD,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,0BAA0B,CAAC,WAAwB;IAC1D,OAAO,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,4BAA4B,CAAC,WAAwB;IAC5D,OAAO,WAAW,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,oBAAoB,CAAC,MAM7B;;IACC,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;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AC;QACnB,KAAK;QACL,QAAQ;QACR,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,UAAU,CAAC;YAC3E,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;QAC1D,QAAQ,EAAE,oBAAoB;QAC9B,WAAW;QACX,kBAAkB,EAAE,eAAe;QACnC,oBAAoB;QACpB,kBAAkB;QAClB,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n skipFinalGet?: boolean;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig, skipFinalGet } = inputs;\n\n // If skipFinalGet is true, return undefined to skip the final GET request\n if (skipFinalGet) {\n return undefined;\n }\n\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault(): string | undefined {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n skipFinalGet?: boolean,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n skipFinalGet,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
@@ -10,7 +10,7 @@ import { rewriteUrl } from "./utils.js";
10
10
  * @returns an initialized poller
11
11
  */
12
12
  export function createHttpPoller(lro, options) {
13
- const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, baseUrl, } = options || {};
13
+ const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, baseUrl, skipFinalGet, } = options || {};
14
14
  return buildCreatePoller({
15
15
  getStatusFromInitialResponse,
16
16
  getStatusFromPollResponse: getOperationStatus,
@@ -23,7 +23,7 @@ export function createHttpPoller(lro, options) {
23
23
  })({
24
24
  init: async () => {
25
25
  const response = await lro.sendInitialRequest();
26
- const config = inferLroMode(response.rawResponse, resourceLocationConfig);
26
+ const config = inferLroMode(response.rawResponse, resourceLocationConfig, skipFinalGet);
27
27
  return Object.assign({ response, operationLocation: rewriteUrl({ url: config === null || config === void 0 ? void 0 : config.operationLocation, baseUrl }), resourceLocation: rewriteUrl({ url: config === null || config === void 0 ? void 0 : config.resourceLocation, baseUrl }), initialRequestUrl: config === null || config === void 0 ? void 0 : config.initialRequestUrl, requestMethod: config === null || config === void 0 ? void 0 : config.requestMethod }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
28
28
  },
29
29
  poll: lro.sendPollRequest,
@@ -1 +1 @@
1
- {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,4BAA4B,EAC5B,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAqB,EACrB,OAAkD;IAElD,MAAM,EACJ,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,qBAAqB,GAAG,KAAK,E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KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\nimport { rewriteUrl } from \"./utils.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n baseUrl,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig);\n return {\n response,\n operationLocation: rewriteUrl({ url: config?.operationLocation, baseUrl }),\n resourceLocation: rewriteUrl({ url: config?.resourceLocation, baseUrl }),\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
1
+ {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,4BAA4B,EAC5B,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAqB,EACrB,OAAkD;IAElD,MAAM,EACJ,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,qBAAqB,GAAG,KAAK,EAC7B,OAAO,EACP,YAAY,GACb,GAAG,OAAO,IAAI,EAAE,CAAC;IAClB,OAAO,iBAAiB,CAAqC;QAC3D,4BAA4B;QAC5B,yBAAyB,EAAE,kBAAkB;QAC7C,gBAAgB;QAChB,oBAAoB;QACpB,mBAAmB;QACnB,kBAAkB,EAAE,eAAe;QACnC,QAAQ,EAAE,oBAAoB;QAC9B,qBAAqB;KACtB,CAAC,CACA;QACE,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,kBAAkB,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,WAAW,EAAE,sBAAsB,EAAE,YAAY,CAAC,CAAC;YACxF,uBACE,QAAQ,EACR,iBAAiB,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAAE,OAAO,EAAE,CAAC,EAC1E,gBAAgB,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC,EACxE,iBAAiB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAC5C,aAAa,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,IACjC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,EAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC5D;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\nimport { rewriteUrl } from \"./utils.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n baseUrl,\n skipFinalGet,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig, skipFinalGet);\n return {\n response,\n operationLocation: rewriteUrl({ url: config?.operationLocation, baseUrl }),\n resourceLocation: rewriteUrl({ url: config?.resourceLocation, baseUrl }),\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
@@ -109,5 +109,9 @@ export interface CreateHttpPollerOptions<TResult, TState> {
109
109
  * Control whether to throw an exception if the operation failed or was canceled.
110
110
  */
111
111
  resolveOnUnsuccessful?: boolean;
112
+ /**
113
+ * A flag to skip the final GET request that would normally fetch the final resource
114
+ */
115
+ skipFinalGet?: boolean;
112
116
  }
113
117
  //# sourceMappingURL=models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * The base URL to use when making requests.\n */\n baseUrl?: string;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * The base URL to use when making requests.\n */\n baseUrl?: string;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n /**\n * A flag to skip the final GET request that would normally fetch the final resource\n */\n skipFinalGet?: boolean;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { HttpOperationMode, RunningOperation, ResourceLocationConfig, OperationResponse, RawResponse } from "./models.js";
2
2
  import type { LroError, OperationConfig, OperationState, OperationStatus, RestorableOperationState } from "../poller/models.js";
3
3
  import type { AbortSignalLike } from "@azure/abort-controller";
4
- export declare function inferLroMode(rawResponse: RawResponse, resourceLocationConfig?: ResourceLocationConfig): (OperationConfig & {
4
+ export declare function inferLroMode(rawResponse: RawResponse, resourceLocationConfig?: ResourceLocationConfig, skipFinalGet?: boolean): (OperationConfig & {
5
5
  mode: HttpOperationMode;
6
6
  }) | undefined;
7
7
  export declare function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined;
@@ -17,7 +17,11 @@ function getAzureAsyncOperationHeader(rawResponse) {
17
17
  }
18
18
  function findResourceLocation(inputs) {
19
19
  var _a;
20
- const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;
20
+ const { location, requestMethod, requestPath, resourceLocationConfig, skipFinalGet } = inputs;
21
+ // If skipFinalGet is true, return undefined to skip the final GET request
22
+ if (skipFinalGet) {
23
+ return undefined;
24
+ }
21
25
  switch (requestMethod) {
22
26
  case "PUT": {
23
27
  return requestPath;
@@ -48,7 +52,7 @@ function findResourceLocation(inputs) {
48
52
  }
49
53
  }
50
54
  }
51
- export function inferLroMode(rawResponse, resourceLocationConfig) {
55
+ export function inferLroMode(rawResponse, resourceLocationConfig, skipFinalGet) {
52
56
  const requestPath = rawResponse.request.url;
53
57
  const requestMethod = rawResponse.request.method;
54
58
  const operationLocation = getOperationLocationHeader(rawResponse);
@@ -65,6 +69,7 @@ export function inferLroMode(rawResponse, resourceLocationConfig) {
65
69
  location,
66
70
  requestPath,
67
71
  resourceLocationConfig,
72
+ skipFinalGet,
68
73
  }),
69
74
  initialRequestUrl: requestPath,
70
75
  requestMethod,
@@ -1 +1 @@
1
- {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBlC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAA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CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC;IACxD,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACnC,KAAK,CAAC,MAAM,CAAC,gBAAgB,GAAG,GAAG,CAAC;IACtC,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,CAAC,gBAAgB,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,CAAQ;IACvC,OAAO,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC;AAChC,CAAC;AAED,wCAAwC;AACxC,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAkD,MASxF;IACC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;IAC/F,OAAO,aAAa,CAAC;QACnB,KAAK;QACL,QAAQ;QACR,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,UAAU,CAAC;YAC3E,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;QAC1D,QAAQ,EAAE,oBAAoB;QAC9B,WAAW;QACX,kBAAkB,EAAE,eAAe;QACnC,oBAAoB;QACpB,kBAAkB;QAClB,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault(): string | undefined {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBlC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAC1D,OAAO,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,mBAAmB,CAAC;AAClD,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAwB;IACjD,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,0BAA0B,CAAC,WAAwB;IAC1D,OAAO,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,4BAA4B,CAAC,WAAwB;IAC5D,OAAO,WAAW,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,oBAAoB,CAAC,MAM7B;;IACC,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAE9F,0EAA0E;IAC1E,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,QAAQ,aAAa,EAAE,CAAC;QACtB,KAAK,KAAK,CAAC,CAAC,CAAC;YACX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,CAAC;YAC3E,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;QAC1D,QAAQ,EAAE,oBAAoB;QAC9B,WAAW;QACX,kBAAkB,EAAE,eAAe;QACnC,oBAAoB;QACpB,kBAAkB;QAClB,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport type {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n skipFinalGet?: boolean;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig, skipFinalGet } = inputs;\n\n // If skipFinalGet is true, return undefined to skip the final GET request\n if (skipFinalGet) {\n return undefined;\n }\n\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault(): string | undefined {\n switch (resourceLocationConfig) {\n case \"operation-location\":\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n skipFinalGet?: boolean,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n skipFinalGet,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
@@ -10,7 +10,7 @@ import { rewriteUrl } from "./utils.js";
10
10
  * @returns an initialized poller
11
11
  */
12
12
  export function createHttpPoller(lro, options) {
13
- const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, baseUrl, } = options || {};
13
+ const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, baseUrl, skipFinalGet, } = options || {};
14
14
  return buildCreatePoller({
15
15
  getStatusFromInitialResponse,
16
16
  getStatusFromPollResponse: getOperationStatus,
@@ -23,7 +23,7 @@ export function createHttpPoller(lro, options) {
23
23
  })({
24
24
  init: async () => {
25
25
  const response = await lro.sendInitialRequest();
26
- const config = inferLroMode(response.rawResponse, resourceLocationConfig);
26
+ const config = inferLroMode(response.rawResponse, resourceLocationConfig, skipFinalGet);
27
27
  return Object.assign({ response, operationLocation: rewriteUrl({ url: config === null || config === void 0 ? void 0 : config.operationLocation, baseUrl }), resourceLocation: rewriteUrl({ url: config === null || config === void 0 ? void 0 : config.resourceLocation, baseUrl }), initialRequestUrl: config === null || config === void 0 ? void 0 : config.initialRequestUrl, requestMethod: config === null || config === void 0 ? void 0 : config.requestMethod }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
28
28
  },
29
29
  poll: lro.sendPollRequest,
@@ -1 +1 @@
1
- {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,4BAA4B,EAC5B,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAqB,EACrB,OAAkD;IAElD,MAAM,EACJ,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,qBAAqB,GAAG,KAAK,EAC7B,OAAO,GACR,GAAG,OAAO,IAAI,EAAE,CAAC;IAClB,OAAO,iBAAiB,CAAqC;QAC3D,4BAA4B;QAC5B,yBAAyB,EAAE,kBAAkB;QAC7C,gBAAgB;QAChB,oBAAoB;QAC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IT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\nimport { rewriteUrl } from \"./utils.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n baseUrl,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig);\n return {\n response,\n operationLocation: rewriteUrl({ url: config?.operationLocation, baseUrl }),\n resourceLocation: rewriteUrl({ url: config?.resourceLocation, baseUrl }),\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
1
+ {"version":3,"file":"poller.js","sourceRoot":"","s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AAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAC5C,aAAa,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,IACjC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,EAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC5D;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RunningOperation, OperationResponse } from \"./models.js\";\nimport type { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport type { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\nimport { rewriteUrl } from \"./utils.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n baseUrl,\n skipFinalGet,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig, skipFinalGet);\n return {\n response,\n operationLocation: rewriteUrl({ url: config?.operationLocation, baseUrl }),\n resourceLocation: rewriteUrl({ url: config?.resourceLocation, baseUrl }),\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@azure/core-lro",
3
3
  "author": "Microsoft Corporation",
4
4
  "sdk-type": "client",
5
- "version": "3.2.0-alpha.20250325.2",
5
+ "version": "3.2.0-alpha.20250326.3",
6
6
  "type": "module",
7
7
  "description": "Isomorphic client library for supporting long-running operations in node.js and browser.",
8
8
  "exports": {