@azure/core-lro 3.3.2-alpha.20260310.2 → 3.4.0
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.
- package/README.md +14 -15
- package/dist/browser/http/models.js.map +1 -1
- package/dist/browser/http/operation.js +1 -1
- package/dist/browser/http/operation.js.map +1 -1
- package/dist/commonjs/http/models.js +1 -0
- package/dist/commonjs/http/models.js.map +2 -2
- package/dist/commonjs/http/operation.js +2 -1
- package/dist/commonjs/http/operation.js.map +3 -3
- package/dist/commonjs/http/poller.js +1 -0
- package/dist/commonjs/http/poller.js.map +1 -1
- package/dist/commonjs/http/utils.js +1 -0
- package/dist/commonjs/http/utils.js.map +1 -1
- package/dist/commonjs/index.js +1 -0
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/logger.js +1 -0
- package/dist/commonjs/logger.js.map +1 -1
- package/dist/commonjs/poller/constants.js +1 -0
- package/dist/commonjs/poller/constants.js.map +1 -1
- package/dist/commonjs/poller/models.js +1 -0
- package/dist/commonjs/poller/models.js.map +1 -1
- package/dist/commonjs/poller/operation.js +1 -0
- package/dist/commonjs/poller/operation.js.map +1 -1
- package/dist/commonjs/poller/poller.js +1 -0
- package/dist/commonjs/poller/poller.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/esm/http/models.js +4 -0
- package/dist/esm/http/models.js.map +1 -7
- package/dist/esm/http/operation.js +217 -219
- package/dist/esm/http/operation.js.map +1 -7
- package/dist/esm/http/poller.js +44 -58
- package/dist/esm/http/poller.js.map +1 -7
- package/dist/esm/http/utils.js +41 -32
- package/dist/esm/http/utils.js.map +1 -7
- package/dist/esm/index.js +5 -6
- package/dist/esm/index.js.map +1 -7
- package/dist/esm/logger.js +8 -4
- package/dist/esm/logger.js.map +1 -7
- package/dist/esm/poller/constants.js +11 -6
- package/dist/esm/poller/constants.js.map +1 -7
- package/dist/esm/poller/models.js +4 -0
- package/dist/esm/poller/models.js.map +1 -7
- package/dist/esm/poller/operation.js +150 -176
- package/dist/esm/poller/operation.js.map +1 -7
- package/dist/esm/poller/poller.js +176 -177
- package/dist/esm/poller/poller.js.map +1 -7
- package/dist/react-native/http/models.js.map +1 -1
- package/dist/react-native/http/operation.js +1 -1
- package/dist/react-native/http/operation.js.map +1 -1
- package/package.json +31 -20
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Azure Core LRO client library for JavaScript
|
|
2
2
|
|
|
3
|
-
This is the default implementation of long running operations in Azure SDK JavaScript client libraries which work in both the browser and NodeJS. This library is primarily intended to be used in code generated by [
|
|
3
|
+
This is the default implementation of long running operations in Azure SDK JavaScript client libraries which work in both the browser and NodeJS. This library is primarily intended to be used in code generated by the [TypeSpec](https://typespec.io) [`@azure-tools/typespec-ts`](https://github.com/Azure/typespec-azure/tree/main/packages/typespec-ts) emitter.
|
|
4
4
|
|
|
5
5
|
`@azure/core-lro` follows [The Azure SDK Design Guidelines for Long Running Operations](https://azure.github.io/azure-sdk/typescript_design.html#ts-lro)
|
|
6
6
|
|
|
@@ -24,28 +24,27 @@ This package is primarily used in generated code and not meant to be consumed di
|
|
|
24
24
|
|
|
25
25
|
## Key concepts
|
|
26
26
|
|
|
27
|
-
### `
|
|
27
|
+
### `PollerLike`
|
|
28
28
|
|
|
29
|
-
A poller is an object that can poll the long running operation on the server for its state until it reaches a terminal state. It provides the following
|
|
29
|
+
A poller is an object that can poll the long running operation on the server for its state until it reaches a terminal state. It also extends `Promise<TResult>`, so you can `await` it directly to get the final result. It provides the following:
|
|
30
30
|
|
|
31
|
-
- `
|
|
32
|
-
- `
|
|
33
|
-
- `isDone`: returns whether the operation is in a terminal state
|
|
34
|
-
- `isStopped`: returns whether the polling stopped
|
|
31
|
+
- `operationState`: a property that returns the current state of the operation, typed as a type that extends `OperationState`. It is `undefined` if the poller has not been submitted yet.
|
|
32
|
+
- `result`: a property that returns the result of the operation when it completes and `undefined` otherwise
|
|
33
|
+
- `isDone`: a property that returns whether the operation is in a terminal state
|
|
35
34
|
- `onProgress`: registers callback functions to be called every time a polling response is received
|
|
36
35
|
- `poll`: sends a single polling request
|
|
37
36
|
- `pollUntilDone`: returns a promise that will resolve with the result of the operation
|
|
38
|
-
- `
|
|
39
|
-
- `
|
|
37
|
+
- `serialize`: returns a promise that resolves to a serialized representation of the poller's state
|
|
38
|
+
- `submitted`: returns a promise that resolves when the poller has been submitted successfully
|
|
40
39
|
|
|
41
40
|
### `OperationState`
|
|
42
41
|
|
|
43
42
|
A type for the operation state. It contains a `status` field with the following possible values: `notStarted`, `running`, `succeeded`, `failed`, and `canceled`. It can be accessed as follows:
|
|
44
43
|
|
|
45
44
|
```typescript snippet:OperationStateExample
|
|
46
|
-
switch (poller.operationState
|
|
47
|
-
case "succeeded": // return poller.
|
|
48
|
-
case "failed": // throw poller.
|
|
45
|
+
switch (poller.operationState?.status) {
|
|
46
|
+
case "succeeded": // return poller.result;
|
|
47
|
+
case "failed": // throw poller.operationState?.error;
|
|
49
48
|
case "canceled": // throw new Error("Operation was canceled");
|
|
50
49
|
case "running": // ...
|
|
51
50
|
case "notStarted": // ...
|
|
@@ -54,10 +53,10 @@ switch (poller.operationState.status) {
|
|
|
54
53
|
|
|
55
54
|
### `createHttpPoller`
|
|
56
55
|
|
|
57
|
-
A function that returns an object of type `
|
|
56
|
+
A function that returns an object of type `PollerLike`. This poller behaves as follows in the presence of errors:
|
|
58
57
|
|
|
59
58
|
- calls to `poll` and `pollUntilDone` will throw an error in case the operation has failed or canceled unless the `resolveOnUnsuccessful` option was set to true.
|
|
60
|
-
- `poller.
|
|
59
|
+
- `poller.operationState?.status` will be set to `"failed"` or `"canceled"` when either the operation fails or it returns an error response.
|
|
61
60
|
|
|
62
61
|
## Examples
|
|
63
62
|
|
|
@@ -82,7 +81,7 @@ If you'd like to contribute to this library, please read the [contributing guide
|
|
|
82
81
|
### Testing
|
|
83
82
|
|
|
84
83
|
To run our tests, first install the dependencies (with `pnpm install`),
|
|
85
|
-
then run the unit tests with: `
|
|
84
|
+
then run the unit tests with: `pnpm run test:node`.
|
|
86
85
|
|
|
87
86
|
### Code of Conduct
|
|
88
87
|
|
|
@@ -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
|
|
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\" | \"location\" | \"original-uri\" | \"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"]}
|
|
@@ -250,7 +250,7 @@ export async function pollHttpOperation(inputs) {
|
|
|
250
250
|
* The expansion here is intentional because `lro` could be an object that
|
|
251
251
|
* references an inner this, so we need to preserve a reference to it.
|
|
252
252
|
*/
|
|
253
|
-
poll:
|
|
253
|
+
poll: (location, inputOptions) => lro.sendPollRequest(location, inputOptions),
|
|
254
254
|
setErrorAsResult,
|
|
255
255
|
});
|
|
256
256
|
}
|
|
@@ -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,IAAI,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,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,KAAK,OAAO,CAAC,CAAC,CAAC;Y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AAgB,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 logger.verbose(`LRO: Transforming status: ${status} with status code: ${statusCode}.`);\n const lowerCaseStatus = status?.toLocaleLowerCase();\n if (!lowerCaseStatus) {\n return toOperationStatus(statusCode);\n }\n if (lowerCaseStatus.includes(\"succeeded\")) {\n return \"succeeded\";\n }\n if (lowerCaseStatus.includes(\"fail\")) {\n return \"failed\";\n }\n if ([\"canceled\", \"cancelled\"].includes(lowerCaseStatus)) {\n return \"canceled\";\n }\n return \"running\";\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,IAAI,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;A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AAG,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,CAAC,QAAgB,EAAE,YAAgD,EAAE,EAAE,CAC3E,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 logger.verbose(`LRO: Transforming status: ${status} with status code: ${statusCode}.`);\n const lowerCaseStatus = status?.toLocaleLowerCase();\n if (!lowerCaseStatus) {\n return toOperationStatus(statusCode);\n }\n if (lowerCaseStatus.includes(\"succeeded\")) {\n return \"succeeded\";\n }\n if (lowerCaseStatus.includes(\"fail\")) {\n return \"failed\";\n }\n if ([\"canceled\", \"cancelled\"].includes(lowerCaseStatus)) {\n return \"canceled\";\n }\n return \"running\";\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: (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
4
|
-
"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
|
|
3
|
+
"sources": ["../../../src/http/models.ts"],
|
|
4
|
+
"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\" | \"location\" | \"original-uri\" | \"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"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -272,7 +272,7 @@ async function pollHttpOperation(inputs) {
|
|
|
272
272
|
* The expansion here is intentional because `lro` could be an object that
|
|
273
273
|
* references an inner this, so we need to preserve a reference to it.
|
|
274
274
|
*/
|
|
275
|
-
poll:
|
|
275
|
+
poll: (location, inputOptions) => lro.sendPollRequest(location, inputOptions),
|
|
276
276
|
setErrorAsResult
|
|
277
277
|
});
|
|
278
278
|
}
|
|
@@ -288,3 +288,4 @@ async function pollHttpOperation(inputs) {
|
|
|
288
288
|
parseRetryAfter,
|
|
289
289
|
pollHttpOperation
|
|
290
290
|
});
|
|
291
|
+
//# sourceMappingURL=operation.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
4
|
-
"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 logger.verbose(`LRO: Transforming status: ${status} with status code: ${statusCode}.`);\n const lowerCaseStatus = status?.toLocaleLowerCase();\n if (!lowerCaseStatus) {\n return toOperationStatus(statusCode);\n }\n if (lowerCaseStatus.includes(\"succeeded\")) {\n return \"succeeded\";\n }\n if (lowerCaseStatus.includes(\"fail\")) {\n return \"failed\";\n }\n if ([\"canceled\", \"cancelled\"].includes(lowerCaseStatus)) {\n return \"canceled\";\n }\n return \"running\";\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"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,uBAA8B;AAE9B,oBAAuB;AAEvB,SAAS,+BAA+B,QAGjB;AACrB,QAAM,EAAE,qBAAqB,kBAAkB,IAAI;AACnD,SAAO,qBAAqB;AAC9B;AAEA,SAAS,kBAAkB,aAA8C;AACvE,SAAO,YAAY,QAAQ,UAAU;AACvC;AAEA,SAAS,2BAA2B,aAA8C;AAChF,SAAO,YAAY,QAAQ,oBAAoB;AACjD;AAEA,SAAS,6BAA6B,aAA8C;AAClF,SAAO,YAAY,QAAQ,sBAAs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ACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,
|
|
3
|
+
"sources": ["../../../src/http/operation.ts"],
|
|
4
|
+
"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 logger.verbose(`LRO: Transforming status: ${status} with status code: ${statusCode}.`);\n const lowerCaseStatus = status?.toLocaleLowerCase();\n if (!lowerCaseStatus) {\n return toOperationStatus(statusCode);\n }\n if (lowerCaseStatus.includes(\"succeeded\")) {\n return \"succeeded\";\n }\n if (lowerCaseStatus.includes(\"fail\")) {\n return \"failed\";\n }\n if ([\"canceled\", \"cancelled\"].includes(lowerCaseStatus)) {\n return \"canceled\";\n }\n return \"running\";\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: (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,uBAA8B;AAE9B,oBAAuB;AAEvB,SAAS,+BAA+B,QAGjB;AACrB,QAAM,EAAE,qBAAqB,kBAAkB,IAAI;AACnD,SAAO,qBAAqB;AAC9B;AAEA,SAAS,kBAAkB,aAA8C;AACvE,SAAO,YAAY,QAAQ,UAAU;AACvC;AAEA,SAAS,2BAA2B,aAA8C;AAChF,SAAO,YAAY,QAAQ,oBAAoB;AACjD;AAEA,SAAS,6BAA6B,aAA8C;AAClF,SAAO,YAAY,QAAQ,sBAAsB;AACnD;AAEA,SAAS,qBAAqB,QAMP;AACrB,QAAM,EAAE,UAAU,eAAe,aAAa,wBAAwB,aAAa,IAAI;AAGvF,MAAI,cAAc;AAChB,WAAO;AA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C;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/http/poller.ts"],
|
|
4
4
|
"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"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,uBASO;AAEP,oBAAkC;AAClC,mBAA2B;AAQpB,SAAS,iBACd,KACA,SAC6B;AAC7B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,wBAAwB;AAAA,IACxB;AAAA,IACA;AAAA,EACF,IAAI,WAAW,CAAC;AAChB,aAAO,iCAAsD;AAAA,IAC3D;AAAA,IACA,2BAA2B;AAAA,IAC3B;AAAA,IACA;AAAA,IACA;AAAA,IACA,oBAAoB;AAAA,IACpB,UAAU;AAAA,IACV;AAAA,EACF,CAAC;AAAA,IACC;AAAA,MACE,MAAM,YAAY;AAChB,cAAM,WAAW,MAAM,IAAI,mBAAmB;AAC9C,cAAM,aAAS,+BAAa,SAAS,aAAa,wBAAwB,YAAY;AACtF,eAAO;AAAA,UACL;AAAA,UACA,uBAAmB,yBAAW,EAAE,KAAK,QAAQ,mBAAmB,QAAQ,CAAC;AAAA,UACzE,sBAAkB,yBAAW,EAAE,KAAK,QAAQ,kBAAkB,QAAQ,CAAC;AAAA,UACvE,mBAAmB,QAAQ;AAAA,UAC3B,eAAe,QAAQ;AAAA,UACvB,GAAI,QAAQ,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,KAAK,EAAE,IAAI,CAAC;AAAA,QAC5D;AAAA,MACF;AAAA,MACA,MAAM,IAAI;AAAA,IACZ;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,eAAe,gBACX,CAAC,EAAE,aAAa,GAAG,UAAU,cAAc,cAAc,KAAK,IAC9D,CAAC,EAAE,aAAa,MAAM;AAAA,IAC5B;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/http/utils.ts"],
|
|
4
4
|
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Rewrites a given URL to use the specified base URL.\n * It preserves the pathname, search parameters, and fragment.\n * Handles relative URLs and proper encoding.\n *\n * @param params - An object containing the url and baseUrl.\n * url - The original URL (absolute or relative).\n * baseUrl - The new base URL to use.\n * @returns The rewritten URL as a string.\n */\nexport function rewriteUrl({\n url,\n baseUrl,\n}: {\n url?: string;\n baseUrl?: string;\n}): string | undefined {\n if (!url) {\n return undefined;\n }\n if (!baseUrl) {\n return url;\n }\n\n let originalUrl: URL;\n\n try {\n // Try to parse inputUrl as an absolute URL.\n originalUrl = new URL(url);\n } catch {\n // If inputUrl is relative, resolve using the provided baseUrl.\n try {\n originalUrl = new URL(url, baseUrl);\n } catch (e) {\n throw new Error(`Invalid input URL provided: ${url}`);\n }\n }\n\n let newBase: URL;\n try {\n newBase = new URL(baseUrl);\n } catch (e) {\n throw new Error(`Invalid base URL provided: ${baseUrl}`);\n }\n\n const rewrittenUrl = new URL(\n `${originalUrl.pathname}${originalUrl.search}${originalUrl.hash}`,\n newBase,\n );\n\n return rewrittenUrl.toString();\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AACF,GAGuB;AACrB,MAAI,CAAC,KAAK;AACR,WAAO;AAAA,EACT;AACA,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,MAAI;AAEJ,MAAI;AAEF,kBAAc,IAAI,IAAI,GAAG;AAAA,EAC3B,QAAQ;AAEN,QAAI;AACF,oBAAc,IAAI,IAAI,KAAK,OAAO;AAAA,IACpC,SAAS,GAAG;AACV,YAAM,IAAI,MAAM,+BAA+B,GAAG,EAAE;AAAA,IACtD;AAAA,EACF;AAEA,MAAI;AACJ,MAAI;AACF,cAAU,IAAI,IAAI,OAAO;AAAA,EAC3B,SAAS,GAAG;AACV,UAAM,IAAI,MAAM,8BAA8B,OAAO,EAAE;AAAA,EACzD;AAEA,QAAM,eAAe,IAAI;AAAA,IACvB,GAAG,YAAY,QAAQ,GAAG,YAAY,MAAM,GAAG,YAAY,IAAI;AAAA,IAC/D;AAAA,EACF;AAEA,SAAO,aAAa,SAAS;AAC/B;",
|
|
6
6
|
"names": []
|
package/dist/commonjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport { createHttpPoller } from \"./http/poller.js\";\nexport type {\n CancelOnProgress,\n OperationState,\n OperationStatus,\n PollerLike,\n RestorableOperationState,\n OperationConfig,\n} from \"./poller/models.js\";\nexport type {\n ResourceLocationConfig,\n RunningOperation,\n OperationResponse,\n RawResponse,\n RawRequest,\n CreateHttpPollerOptions,\n} from \"./http/models.js\";\nexport { deserializeState } from \"./poller/operation.js\";\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAiC;AAiBjC,uBAAiC;",
|
|
6
6
|
"names": []
|
package/dist/commonjs/logger.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../src/logger.ts"],
|
|
4
4
|
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { createClientLogger } from \"@azure/logger\";\n\n/**\n * The `@azure/logger` configuration for this package.\n * @internal\n */\nexport const logger = createClientLogger(\"core-lro\");\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAmC;AAM5B,MAAM,aAAS,kCAAmB,UAAU;",
|
|
6
6
|
"names": []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/poller/constants.ts"],
|
|
4
4
|
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * The default time interval to wait before sending the next polling request.\n */\nexport const POLL_INTERVAL_IN_MS = 2000;\n/**\n * The closed set of terminal states.\n */\nexport const terminalStates = [\"succeeded\", \"canceled\", \"failed\"];\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,MAAM,sBAAsB;AAI5B,MAAM,iBAAiB,CAAC,aAAa,YAAY,QAAQ;",
|
|
6
6
|
"names": []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/poller/models.ts"],
|
|
4
4
|
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\n\n/**\n * Configurations for how to poll the operation and to check whether it has\n * terminated.\n */\nexport interface OperationConfig {\n /** The operation location */\n operationLocation?: string;\n /** The resource location */\n resourceLocation?: string;\n /** The initial request Url */\n initialRequestUrl?: string;\n /** The request method */\n requestMethod?: string;\n /** metadata about the operation */\n metadata?: Record<string, string>;\n}\n\n/**\n * The description of an operation.\n */\nexport interface Operation<TResponse, TOptions> {\n /**\n * Sends the initiation request and returns, in addition to the response, the\n * operation location, the potential resource location, and a set of metadata.\n */\n init: () => Promise<\n OperationConfig & {\n response: TResponse;\n }\n >;\n /**\n * Sends the polling request.\n */\n poll: (location: string, options?: TOptions) => Promise<TResponse>;\n}\n\n/**\n * Type of a restorable long-running operation.\n */\nexport type RestorableOperationState<TResult, T extends OperationState<TResult>> = T & {\n /** The operation configuration */\n config: OperationConfig;\n};\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreatePollerOptions<TResponse, 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 * A function to process the result of the LRO.\n */\n processResult?: (result: TResponse, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, lastResponse: TResponse) => 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\nexport interface LroError {\n code: string;\n innererror?: InnerError;\n message: string;\n}\n\nexport interface InnerError {\n code: string;\n message: string;\n innererror?: InnerError;\n}\n\n/**\n * Options for `buildCreatePoller`.\n */\nexport interface BuildCreatePollerOptions<\n TResponse,\n TResult,\n TState extends OperationState<TResult>,\n> {\n /**\n * Gets the status of the operation from the response received when the\n * operation was initialized. Note that the operation could be already in\n * a terminal state at this time.\n */\n getStatusFromInitialResponse: (inputs: {\n response: TResponse;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n }) => OperationStatus;\n /**\n * Gets the status of the operation from a response received when the\n * operation was polled.\n */\n getStatusFromPollResponse: (\n response: TResponse,\n state: RestorableOperationState<TResult, TState>,\n ) => OperationStatus;\n /**\n * Determines if the input error is an operation error.\n */\n isOperationError: (error: Error) => boolean;\n /**\n * Gets the updated operation location from polling responses.\n */\n getOperationLocation?: (\n response: TResponse,\n state: RestorableOperationState<TResult, TState>,\n ) => string | undefined;\n /**\n * Gets the resource location from a response.\n */\n getResourceLocation: (\n response: TResponse,\n state: RestorableOperationState<TResult, TState>,\n ) => string | undefined;\n /**\n * Gets from the response the time interval the service suggests the client to\n * wait before sending the next polling request.\n */\n getPollingInterval?: (response: TResponse) => number | undefined;\n /**\n * Extracts an error model from a response.\n */\n getError?: (response: TResponse) => LroError | undefined;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful: boolean;\n}\n\n/**\n * The set of possible states an operation can be in at any given time.\n */\nexport type OperationStatus = \"notStarted\" | \"running\" | \"succeeded\" | \"canceled\" | \"failed\";\n\n/**\n * While the poller works as the local control mechanism to start triggering and\n * wait for a long-running operation, OperationState documents the status of\n * the remote long-running operation. It gets updated after each poll.\n */\nexport interface OperationState<TResult> {\n /**\n * The current status of the operation.\n */\n status: OperationStatus;\n /**\n * Will exist if the operation encountered any error.\n */\n error?: Error;\n /**\n * Will exist if the operation produced a result of the expected type.\n */\n result?: TResult;\n}\n\n/**\n * CancelOnProgress is used as the return value of a Poller's onProgress method.\n * When a user invokes onProgress, they're required to pass in a function that will be\n * called as a callback with the new data received each time the poll operation is updated.\n * onProgress returns a function that will prevent any further update to reach the original callback.\n */\nexport type CancelOnProgress = () => void;\n\n/**\n * A poller for an operation.\n */\nexport interface PollerLike<\n TState extends OperationState<TResult>,\n TResult,\n> extends Promise<TResult> {\n /**\n * Is true if the poller has finished polling.\n */\n readonly isDone: boolean;\n /**\n * The state of the operation.\n * It can be undefined if the poller has not been submitted yet.\n */\n readonly operationState: TState | undefined;\n /**\n * The result value of the operation, regardless of the state of the poller.\n * It can be undefined or an incomplete form of the final TResult value\n * depending on the implementation.\n */\n readonly result: TResult | undefined;\n /**\n * Returns a promise that will resolve once a single polling request finishes.\n * It does this by calling the update method of the Poller's operation.\n */\n poll(options?: { abortSignal?: AbortSignalLike }): Promise<TState>;\n /**\n * Returns a promise that will resolve once the underlying operation is completed.\n */\n pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise<TResult>;\n /**\n * Invokes the provided callback after each polling is completed,\n * sending the current state of the poller's operation.\n *\n * It returns a method that can be used to stop receiving updates on the given callback function.\n */\n onProgress(callback: (state: TState) => void): CancelOnProgress;\n\n /**\n * Returns a promise that could be used for serialized version of the poller's operation\n * by invoking the operation's serialize method.\n */\n serialize(): Promise<string>;\n\n /**\n * Returns a promise that could be used to check if the poller has been submitted.\n */\n submitted(): Promise<void>;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/poller/operation.ts"],
|
|
4
4
|
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n LroError,\n InnerError,\n Operation,\n OperationStatus,\n RestorableOperationState,\n OperationState,\n} from \"./models.js\";\nimport { logger } from \"../logger.js\";\nimport { terminalStates } from \"./constants.js\";\n\n/**\n * Deserializes the state\n */\nexport function deserializeState<TResult, TState extends OperationState<TResult>>(\n serializedState: string,\n): RestorableOperationState<TResult, TState> {\n try {\n return JSON.parse(serializedState).state;\n } catch (e) {\n throw new Error(`Unable to deserialize input state: ${serializedState}`);\n }\n}\n\nfunction setStateError<TResult, TState extends OperationState<TResult>>(inputs: {\n state: TState;\n isOperationError: (error: Error) => boolean;\n}): (error: Error) => never {\n const { state, isOperationError } = inputs;\n return (error: Error) => {\n if (isOperationError(error)) {\n state.error = error;\n state.status = \"failed\";\n }\n throw error;\n };\n}\n\nfunction appendReadableErrorMessage(currentMessage: string, innerMessage: string): string {\n let message = currentMessage;\n if (message.slice(-1) !== \".\") {\n message = message + \".\";\n }\n return message + \" \" + innerMessage;\n}\n\nfunction simplifyError(err: LroError): {\n code: string;\n message: string;\n} {\n let message = err.message;\n let code = err.code;\n let curErr = err as InnerError;\n while (curErr.innererror) {\n curErr = curErr.innererror;\n code = curErr.code;\n message = appendReadableErrorMessage(message, curErr.message);\n }\n return {\n code,\n message,\n };\n}\n\nasync function processOperationStatus<\n TState extends OperationState<TResult>,\n TResult,\n TResponse,\n>(result: {\n status: OperationStatus;\n response: TResponse;\n state: RestorableOperationState<TResult, TState>;\n processResult?: (result: TResponse, state: TState) => Promise<TResult>;\n getError?: (response: TResponse) => LroError | undefined;\n isDone?: (lastResponse: TResponse, state: TState) => boolean;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { state, status, isDone, processResult, getError, response, setErrorAsResult } = result;\n switch (status) {\n case \"succeeded\": {\n state.status = \"succeeded\";\n break;\n }\n case \"failed\": {\n const err = getError?.(response);\n let postfix = \"\";\n if (err) {\n const { code, message } = simplifyError(err);\n postfix = `. ${code}. ${message}`;\n }\n const errStr = `The long-running operation has failed${postfix}`;\n state.error = new Error(errStr);\n state.status = \"failed\";\n logger.warning(errStr);\n break;\n }\n case \"canceled\": {\n state.status = \"canceled\";\n break;\n }\n }\n if (\n isDone?.(response, state) ||\n (isDone === undefined &&\n [\"succeeded\", \"canceled\"].concat(setErrorAsResult ? [] : [\"failed\"]).includes(status))\n ) {\n state.result = await buildResult({\n response,\n state,\n processResult,\n });\n }\n}\n\nasync function buildResult<TResponse, TResult, TState>(inputs: {\n response: TResponse;\n state: TState;\n processResult?: (result: TResponse, state: TState) => Promise<TResult>;\n}): Promise<TResult> {\n const { processResult, response, state } = inputs;\n return processResult ? processResult(response, state) : (response as unknown as TResult);\n}\n\n/**\n * Initiates the long-running operation.\n */\nexport async function initOperation<\n TResponse,\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n init: Operation<TResponse, unknown>[\"init\"];\n getOperationStatus: (inputs: {\n response: TResponse;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n }) => OperationStatus;\n processResult?: (result: TResponse, state: TState) => Promise<TResult>;\n withOperationLocation?: (operationLocation: string, isUpdated: boolean) => void;\n setErrorAsResult: boolean;\n}): Promise<RestorableOperationState<TResult, TState>> {\n const { init, processResult, getOperationStatus, withOperationLocation, setErrorAsResult } =\n inputs;\n const {\n operationLocation,\n resourceLocation,\n initialRequestUrl,\n requestMethod,\n metadata,\n response,\n } = await init();\n if (operationLocation) withOperationLocation?.(operationLocation, false);\n const config = {\n metadata,\n operationLocation,\n resourceLocation,\n initialRequestUrl,\n requestMethod,\n };\n logger.verbose(`LRO: Operation description:`, config);\n const state = { status: \"running\", config } as any;\n const status = getOperationStatus({ response, state, operationLocation });\n await processOperationStatus({\n state,\n status,\n response,\n setErrorAsResult,\n processResult,\n });\n return state;\n}\n\nasync function pollOperationHelper<\n TResponse,\n TState extends OperationState<TResult>,\n TResult,\n TOptions,\n>(inputs: {\n poll: Operation<TResponse, TOptions>[\"poll\"];\n state: RestorableOperationState<TResult, TState>;\n operationLocation: string;\n getOperationStatus: (\n response: TResponse,\n state: RestorableOperationState<TResult, TState>,\n ) => OperationStatus;\n getResourceLocation: (\n response: TResponse,\n state: RestorableOperationState<TResult, TState>,\n ) => string | undefined;\n isOperationError: (error: Error) => boolean;\n options?: TOptions;\n}): Promise<{\n status: OperationStatus;\n response: TResponse;\n}> {\n const {\n poll,\n state,\n operationLocation,\n getOperationStatus,\n getResourceLocation,\n isOperationError,\n options,\n } = inputs;\n const response = await poll(operationLocation, options).catch(\n setStateError({\n state,\n isOperationError,\n }),\n );\n const status = getOperationStatus(response, state);\n logger.verbose(\n `LRO: Status:\\n\\tPolling from: ${\n state.config.operationLocation\n }\\n\\tOperation status: ${status}\\n\\tPolling status: ${\n terminalStates.includes(status) ? \"Stopped\" : \"Running\"\n }`,\n );\n if (status === \"succeeded\") {\n const resourceLocation = getResourceLocation(response, state);\n if (resourceLocation !== undefined) {\n return {\n response: await poll(resourceLocation).catch(setStateError({ state, isOperationError })),\n status,\n };\n }\n }\n return { response, status };\n}\n\n/** Polls the long-running operation. */\nexport async function pollOperation<\n TResponse,\n TResult,\n TState extends OperationState<TResult>,\n TOptions,\n>(inputs: {\n poll: Operation<TResponse, TOptions>[\"poll\"];\n state: RestorableOperationState<TResult, TState>;\n getOperationStatus: (\n response: TResponse,\n state: RestorableOperationState<TResult, TState>,\n ) => OperationStatus;\n getResourceLocation: (\n response: TResponse,\n state: RestorableOperationState<TResult, TState>,\n ) => string | undefined;\n isOperationError: (error: Error) => boolean;\n getPollingInterval?: (response: TResponse) => number | undefined;\n setDelay: (intervalInMs: number) => void;\n getOperationLocation?: (\n response: TResponse,\n state: RestorableOperationState<TResult, TState>,\n ) => string | undefined;\n withOperationLocation?: (operationLocation: string, isUpdated: boolean) => void;\n processResult?: (result: TResponse, state: TState) => Promise<TResult>;\n getError?: (response: TResponse) => LroError | undefined;\n updateState?: (state: TState, lastResponse: TResponse) => void;\n isDone?: (lastResponse: TResponse, state: TState) => boolean;\n setErrorAsResult: boolean;\n options?: TOptions;\n}): Promise<void> {\n const {\n poll,\n state,\n options,\n getOperationStatus,\n getResourceLocation,\n getOperationLocation,\n isOperationError,\n withOperationLocation,\n getPollingInterval,\n processResult,\n getError,\n updateState,\n setDelay,\n isDone,\n setErrorAsResult,\n } = inputs;\n const { operationLocation } = state.config;\n if (operationLocation !== undefined) {\n const { response, status } = await pollOperationHelper({\n poll,\n getOperationStatus,\n state,\n operationLocation,\n getResourceLocation,\n isOperationError,\n options,\n });\n await processOperationStatus({\n status,\n response,\n state,\n isDone,\n processResult,\n getError,\n setErrorAsResult,\n });\n\n if (!terminalStates.includes(status)) {\n const intervalInMs = getPollingInterval?.(response);\n if (intervalInMs) setDelay(intervalInMs);\n const location = getOperationLocation?.(response, state);\n if (location !== undefined) {\n const isUpdated = operationLocation !== location;\n state.config.operationLocation = location;\n withOperationLocation?.(location, isUpdated);\n } else withOperationLocation?.(operationLocation, false);\n }\n updateState?.(state, response);\n }\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,oBAAuB;AACvB,uBAA+B;AAKxB,S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BAAoB;AACjC,gCAAwB,UAAU,SAAS;AAAA,MAC7C,MAAO,yBAAwB,mBAAmB,KAAK;AAAA,IACzD;AACA,kBAAc,OAAO,QAAQ;AAAA,EAC/B;AACF;",
|
|
6
6
|
"names": []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/poller/poller.ts"],
|
|
4
4
|
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type {\n BuildCreatePollerOptions,\n CreatePollerOptions,\n Operation,\n OperationState,\n RestorableOperationState,\n PollerLike,\n} from \"./models.js\";\nimport { deserializeState, initOperation, pollOperation } from \"./operation.js\";\nimport { POLL_INTERVAL_IN_MS } from \"./constants.js\";\nimport { delay } from \"@azure/core-util\";\n/**\n * Returns a poller factory.\n */\nexport function buildCreatePoller<TResponse, TResult, TState extends OperationState<TResult>>(\n inputs: BuildCreatePollerOptions<TResponse, TResult, TState>,\n): (\n lro: Operation<TResponse, { abortSignal?: AbortSignalLike }>,\n options?: CreatePollerOptions<TResponse, TResult, TState>,\n) => PollerLike<TState, TResult> {\n const {\n getOperationLocation,\n getStatusFromInitialResponse,\n getStatusFromPollResponse,\n isOperationError,\n getResourceLocation,\n getPollingInterval,\n getError,\n resolveOnUnsuccessful,\n } = inputs;\n return (\n { init, poll }: Operation<TResponse, { abortSignal?: AbortSignalLike }>,\n options?: CreatePollerOptions<TResponse, TResult, TState>,\n ) => {\n const {\n processResult,\n updateState,\n withOperationLocation: withOperationLocationCallback,\n intervalInMs = POLL_INTERVAL_IN_MS,\n restoreFrom,\n } = options || {};\n const withOperationLocation = withOperationLocationCallback\n ? (() => {\n let called = false;\n return (operationLocation: string, isUpdated: boolean) => {\n if (isUpdated) withOperationLocationCallback(operationLocation);\n else if (!called) withOperationLocationCallback(operationLocation);\n called = true;\n };\n })()\n : undefined;\n let statePromise: Promise<TState>;\n let state: RestorableOperationState<TResult, TState>;\n if (restoreFrom) {\n state = deserializeState(restoreFrom);\n statePromise = Promise.resolve(state);\n } else {\n statePromise = initOperation({\n init,\n processResult,\n getOperationStatus: getStatusFromInitialResponse,\n withOperationLocation,\n setErrorAsResult: !resolveOnUnsuccessful,\n }).then((s) => (state = s));\n }\n let resultPromise: Promise<TResult> | undefined;\n const abortController = new AbortController();\n // Progress handlers\n type Handler = (state: TState) => void;\n const handlers = new Map<symbol, Handler>();\n const handleProgressEvents = async (): Promise<void> => handlers.forEach((h) => h(state));\n const cancelErrMsg = \"Operation was canceled\";\n let currentPollIntervalInMs = intervalInMs;\n\n const poller: PollerLike<TState, TResult> = {\n get operationState(): TState | undefined {\n return state;\n },\n get result(): TResult | undefined {\n return state?.result;\n },\n get isDone(): boolean {\n return [\"succeeded\", \"failed\", \"canceled\"].includes(state?.status ?? \"\");\n },\n onProgress: (callback: (state: TState) => void) => {\n const s = Symbol();\n handlers.set(s, callback);\n return () => handlers.delete(s);\n },\n serialize: async () => {\n await statePromise;\n return JSON.stringify({\n state,\n });\n },\n submitted: async () => {\n await statePromise;\n },\n pollUntilDone: async (pollOptions?: { abortSignal?: AbortSignalLike }) => {\n resultPromise ??= (async () => {\n await statePromise;\n if (!state) {\n throw new Error(\"Poller should be initialized but it is not!\");\n }\n const { abortSignal: inputAbortSignal } = pollOptions || {};\n // In the future we can use AbortSignal.any() instead\n function abortListener(): void {\n abortController.abort();\n }\n const abortSignal = abortController.signal;\n if (inputAbortSignal?.aborted) {\n abortController.abort();\n } else if (!abortSignal.aborted) {\n inputAbortSignal?.addEventListener(\"abort\", abortListener, { once: true });\n }\n\n try {\n if (!poller.isDone) {\n await poller.poll({ abortSignal });\n while (!poller.isDone) {\n await delay(currentPollIntervalInMs, { abortSignal });\n await poller.poll({ abortSignal });\n }\n }\n } finally {\n inputAbortSignal?.removeEventListener(\"abort\", abortListener);\n }\n if (resolveOnUnsuccessful) {\n return poller.result as TResult;\n } else {\n switch (state.status) {\n case \"succeeded\":\n return poller.result as TResult;\n case \"canceled\":\n throw new Error(cancelErrMsg);\n case \"failed\":\n throw state.error;\n case \"notStarted\":\n case \"running\":\n throw new Error(`Polling completed without succeeding or failing`);\n }\n }\n })().finally(() => {\n resultPromise = undefined;\n });\n return resultPromise;\n },\n async poll(pollOptions?: { abortSignal?: AbortSignalLike }): Promise<TState> {\n await statePromise;\n if (!state) {\n throw new Error(\"Poller should be initialized but it is not!\");\n }\n if (resolveOnUnsuccessful) {\n if (poller.isDone) return state;\n } else {\n switch (state.status) {\n case \"succeeded\":\n return state;\n case \"canceled\":\n throw new Error(cancelErrMsg);\n case \"failed\":\n throw state.error;\n }\n }\n await pollOperation({\n poll,\n state,\n getOperationLocation,\n isOperationError,\n withOperationLocation,\n getPollingInterval,\n getOperationStatus: getStatusFromPollResponse,\n getResourceLocation,\n processResult,\n getError,\n updateState,\n options: pollOptions,\n setDelay: (pollIntervalInMs) => {\n currentPollIntervalInMs = pollIntervalInMs;\n },\n setErrorAsResult: !resolveOnUnsuccessful,\n });\n await handleProgressEvents();\n if (!resolveOnUnsuccessful) {\n switch (state.status) {\n case \"canceled\":\n throw new Error(cancelErrMsg);\n case \"failed\":\n throw state.error;\n }\n }\n\n return state;\n },\n then<TResult1 = TResult, TResult2 = never>(\n onfulfilled?: ((value: TResult) => TResult1 | PromiseLike<TResult1>) | undefined | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,\n ): Promise<TResult1 | TResult2> {\n return poller.pollUntilDone().then(onfulfilled, onrejected);\n },\n catch<TResult2 = never>(\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,\n ): Promise<TResult | TResult2> {\n return poller.pollUntilDone().catch(onrejected);\n },\n finally(onfinally?: (() => void) | undefined | null): Promise<TResult> {\n return poller.pollUntilDone().finally(onfinally);\n },\n [Symbol.toStringTag]: \"Poller\",\n };\n return poller;\n };\n}\n"],
|
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AChD;AAAA,MACA,QAAQ,WAA+D;AACrE,eAAO,OAAO,cAAc,EAAE,QAAQ,SAAS;AAAA,MACjD;AAAA,MACA,CAAC,OAAO,WAAW,GAAG;AAAA,IACxB;AACA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
package/dist/esm/http/models.js
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": [],
|
|
4
|
-
"sourcesContent": [],
|
|
5
|
-
"mappings": "",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
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\" | \"location\" | \"original-uri\" | \"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"]}
|