2022-10-29 10:03:51 +02:00
|
|
|
{"version":3,"file":"index.js","sources":["../src/logger.ts","../src/poller/constants.ts","../src/poller/operation.ts","../src/http/operation.ts","../src/poller/util/delayMs.ts","../src/poller/poller.ts","../src/http/poller.ts","../src/legacy/lroEngine/operation.ts","../src/legacy/poller.ts","../src/legacy/lroEngine/lroEngine.ts"],"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","// 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","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Operation, OperationStatus, RestorableOperationState, StateProxy } from \"./models\";\nimport { logger } from \"../logger\";\nimport { terminalStates } from \"./constants\";\n\n/**\n * Deserializes the state\n */\nexport function deserializeState<TState>(\n serializedState: string\n): RestorableOperationState<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<TState, TResult>(inputs: {\n state: TState;\n stateProxy: StateProxy<TState, TResult>;\n}): (error: Error) => never {\n const { state, stateProxy } = inputs;\n return (error: Error) => {\n stateProxy.setError(state, error);\n stateProxy.setFailed(state);\n throw error;\n };\n}\n\nfunction processOperationStatus<TState, TResult, TResponse>(result: {\n status: OperationStatus;\n response: TResponse;\n state: RestorableOperationState<TState>;\n stateProxy: StateProxy<TState, TResult>;\n processResult?: (result: TResponse, state: TState) => TResult;\n isDone?: (lastResponse: TResponse, state: TState) => boolean;\n setErrorAsResult: boolean;\n}): void {\n const { state, stateProxy, status, isDone, processResult, response, setErrorAsResult } = result;\n switch (status) {\n case \"succeeded\": {\n stateProxy.setSucceeded(state);\n break;\n }\n case \"failed\": {\n stateProxy.setError(state, new Error(`The long-running operation has failed`));\n stateProxy.setFailed(state);\n break;\n }\n case \"canceled\": {\n stateProxy.setCanceled(state);\n break;\n }\n }\n if (\n isDone?.(response, state) ||\n (isDone === undefined &&\n [\"succeeded\", \"canceled\"].concat(setErrorAsResult ? [] : [\"failed\"]).includes(status))\n ) {\n stateProxy.setResult(\n state,\n buildResult({\n response,\n state,\n processResult,\n })\n );\n }\n}\n\nfunction buildResult<TResponse, TResult, TState>(inputs: {\n response: TResponse;\n state: TState;\n processResult?: (result: TResponse, state: TState) => TResult;\n}): 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<TResponse, TResult, TState>(inputs: {\n init: Operation<TResponse, unknown>[\"init\"];\n stateProxy: StateProxy<TState, TResult>;\n getOperationStatus: (inputs: {\n response: TResponse;\n state: RestorableOperationState<TState>;\n operationLocation?: string;\n }) => OperationStatus;\n processResult?: (result: TResponse, state: TState) => TResult;\n withOperationLocation?: (operationLocation: string, isUpdated: boolean) => void;\n setErrorAsResult: boolean;\n}): Promise<RestorableOperationState<TState>> {\n const {\n init,\n stateProxy,\n processResult,\n getOperationStatus,\n withOperationLocation,\n
|