@azure/core-lro 3.0.0-beta.1 → 3.0.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.
Files changed (147) hide show
  1. package/dist/browser/http/models.d.ts +2 -2
  2. package/dist/browser/http/models.d.ts.map +1 -1
  3. package/dist/browser/http/models.js.map +1 -1
  4. package/dist/browser/http/operation.d.ts +11 -12
  5. package/dist/browser/http/operation.d.ts.map +1 -1
  6. package/dist/browser/http/operation.js +22 -16
  7. package/dist/browser/http/operation.js.map +1 -1
  8. package/dist/browser/http/poller.d.ts +2 -2
  9. package/dist/browser/http/poller.d.ts.map +1 -1
  10. package/dist/browser/http/poller.js +1 -15
  11. package/dist/browser/http/poller.js.map +1 -1
  12. package/dist/browser/index.d.ts +1 -1
  13. package/dist/browser/index.d.ts.map +1 -1
  14. package/dist/browser/index.js.map +1 -1
  15. package/dist/browser/poller/models.d.ts +15 -39
  16. package/dist/browser/poller/models.d.ts.map +1 -1
  17. package/dist/browser/poller/models.js.map +1 -1
  18. package/dist/browser/poller/operation.d.ts +12 -14
  19. package/dist/browser/poller/operation.d.ts.map +1 -1
  20. package/dist/browser/poller/operation.js +25 -29
  21. package/dist/browser/poller/operation.js.map +1 -1
  22. package/dist/browser/poller/poller.d.ts +1 -1
  23. package/dist/browser/poller/poller.d.ts.map +1 -1
  24. package/dist/browser/poller/poller.js +9 -34
  25. package/dist/browser/poller/poller.js.map +1 -1
  26. package/dist/commonjs/http/models.d.ts +2 -2
  27. package/dist/commonjs/http/models.d.ts.map +1 -1
  28. package/dist/commonjs/http/models.js.map +1 -1
  29. package/dist/commonjs/http/operation.d.ts +11 -12
  30. package/dist/commonjs/http/operation.d.ts.map +1 -1
  31. package/dist/commonjs/http/operation.js +22 -16
  32. package/dist/commonjs/http/operation.js.map +1 -1
  33. package/dist/commonjs/http/poller.d.ts +2 -2
  34. package/dist/commonjs/http/poller.d.ts.map +1 -1
  35. package/dist/commonjs/http/poller.js +1 -15
  36. package/dist/commonjs/http/poller.js.map +1 -1
  37. package/dist/commonjs/index.d.ts +1 -1
  38. package/dist/commonjs/index.d.ts.map +1 -1
  39. package/dist/commonjs/index.js.map +1 -1
  40. package/dist/commonjs/poller/models.d.ts +15 -39
  41. package/dist/commonjs/poller/models.d.ts.map +1 -1
  42. package/dist/commonjs/poller/models.js.map +1 -1
  43. package/dist/commonjs/poller/operation.d.ts +12 -14
  44. package/dist/commonjs/poller/operation.d.ts.map +1 -1
  45. package/dist/commonjs/poller/operation.js +25 -29
  46. package/dist/commonjs/poller/operation.js.map +1 -1
  47. package/dist/commonjs/poller/poller.d.ts +1 -1
  48. package/dist/commonjs/poller/poller.d.ts.map +1 -1
  49. package/dist/commonjs/poller/poller.js +9 -34
  50. package/dist/commonjs/poller/poller.js.map +1 -1
  51. package/dist/commonjs/tsdoc-metadata.json +1 -1
  52. package/dist/core-lro.d.ts +28 -32
  53. package/dist/esm/http/models.d.ts +2 -2
  54. package/dist/esm/http/models.d.ts.map +1 -1
  55. package/dist/esm/http/models.js.map +1 -1
  56. package/dist/esm/http/operation.d.ts +11 -12
  57. package/dist/esm/http/operation.d.ts.map +1 -1
  58. package/dist/esm/http/operation.js +22 -16
  59. package/dist/esm/http/operation.js.map +1 -1
  60. package/dist/esm/http/poller.d.ts +2 -2
  61. package/dist/esm/http/poller.d.ts.map +1 -1
  62. package/dist/esm/http/poller.js +1 -15
  63. package/dist/esm/http/poller.js.map +1 -1
  64. package/dist/esm/index.d.ts +1 -1
  65. package/dist/esm/index.d.ts.map +1 -1
  66. package/dist/esm/index.js.map +1 -1
  67. package/dist/esm/poller/models.d.ts +15 -39
  68. package/dist/esm/poller/models.d.ts.map +1 -1
  69. package/dist/esm/poller/models.js.map +1 -1
  70. package/dist/esm/poller/operation.d.ts +12 -14
  71. package/dist/esm/poller/operation.d.ts.map +1 -1
  72. package/dist/esm/poller/operation.js +25 -29
  73. package/dist/esm/poller/operation.js.map +1 -1
  74. package/dist/esm/poller/poller.d.ts +1 -1
  75. package/dist/esm/poller/poller.d.ts.map +1 -1
  76. package/dist/esm/poller/poller.js +9 -34
  77. package/dist/esm/poller/poller.js.map +1 -1
  78. package/dist/react-native/http/models.d.ts +2 -2
  79. package/dist/react-native/http/models.d.ts.map +1 -1
  80. package/dist/react-native/http/models.js.map +1 -1
  81. package/dist/react-native/http/operation.d.ts +11 -12
  82. package/dist/react-native/http/operation.d.ts.map +1 -1
  83. package/dist/react-native/http/operation.js +22 -16
  84. package/dist/react-native/http/operation.js.map +1 -1
  85. package/dist/react-native/http/poller.d.ts +2 -2
  86. package/dist/react-native/http/poller.d.ts.map +1 -1
  87. package/dist/react-native/http/poller.js +1 -15
  88. package/dist/react-native/http/poller.js.map +1 -1
  89. package/dist/react-native/index.d.ts +1 -1
  90. package/dist/react-native/index.d.ts.map +1 -1
  91. package/dist/react-native/index.js.map +1 -1
  92. package/dist/react-native/poller/models.d.ts +15 -39
  93. package/dist/react-native/poller/models.d.ts.map +1 -1
  94. package/dist/react-native/poller/models.js.map +1 -1
  95. package/dist/react-native/poller/operation.d.ts +12 -14
  96. package/dist/react-native/poller/operation.d.ts.map +1 -1
  97. package/dist/react-native/poller/operation.js +25 -29
  98. package/dist/react-native/poller/operation.js.map +1 -1
  99. package/dist/react-native/poller/poller.d.ts +1 -1
  100. package/dist/react-native/poller/poller.d.ts.map +1 -1
  101. package/dist/react-native/poller/poller.js +9 -34
  102. package/dist/react-native/poller/poller.js.map +1 -1
  103. package/package.json +26 -20
  104. package/.rush/temp/operation/build/state.json +0 -3
  105. package/.rush/temp/operation/build_samples/all.log +0 -2
  106. package/.rush/temp/operation/build_samples/state.json +0 -3
  107. package/.rush/temp/shrinkwrap-deps.json +0 -510
  108. package/.tshy/browser.json +0 -12
  109. package/.tshy/build.json +0 -9
  110. package/.tshy/commonjs.json +0 -14
  111. package/.tshy/esm.json +0 -12
  112. package/.tshy/react-native.json +0 -12
  113. package/CHANGELOG.md +0 -179
  114. package/api-extractor.json +0 -31
  115. package/config/rush-project.json +0 -3
  116. package/core-lro.build.cache.error.log +0 -1
  117. package/core-lro.build_samples.cache.log +0 -1
  118. package/core-lro.build_samples.log +0 -2
  119. package/core-lro.pack.cache.log +0 -1
  120. package/core-lro.pack.log +0 -1
  121. package/docs/LROEngine.md +0 -158
  122. package/review/core-lro.api.md +0 -106
  123. package/samples/README.md +0 -284
  124. package/samples/typescript/samplesClient.ts +0 -254
  125. package/src/http/models.ts +0 -119
  126. package/src/http/operation.ts +0 -343
  127. package/src/http/poller.ts +0 -83
  128. package/src/index.ts +0 -21
  129. package/src/logger.ts +0 -10
  130. package/src/poller/constants.ts +0 -11
  131. package/src/poller/models.ts +0 -251
  132. package/src/poller/operation.ts +0 -315
  133. package/src/poller/poller.ts +0 -250
  134. package/temp/core-lro.api.json +0 -1892
  135. package/temp/core-lro.api.md +0 -106
  136. package/test/getYieldedValue.ts +0 -16
  137. package/test/lro.spec.ts +0 -3141
  138. package/test/matrix.ts +0 -46
  139. package/test/utils/coreRestPipelineLro.ts +0 -25
  140. package/test/utils/router.ts +0 -231
  141. package/test/utils/utils.ts +0 -144
  142. package/tsconfig.browser.config.json +0 -10
  143. package/tsconfig.json +0 -13
  144. package/tsdoc.json +0 -4
  145. package/tslint.json +0 -47
  146. package/vitest.browser.config.ts +0 -34
  147. package/vitest.config.ts +0 -31
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/poller/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { 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 Url */\n initialUrl?: 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<T> = 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) => TResult | 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<TResponse, TState> {\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<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<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<TState>,\n ) => string | undefined;\n /**\n * Gets the resource location from a response.\n */\n getResourceLocation: (\n response: TResponse,\n state: RestorableOperationState<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 simple poller interface.\n */\nexport interface PollerLike<TState extends OperationState<TResult>, TResult>\n extends Promise<TResult> {\n /**\n * Returns true if the poller has finished polling.\n */\n readonly isDone: boolean;\n /**\n * Returns true if the poller is stopped.\n */\n readonly isStopped: boolean;\n /**\n * Returns the state of the operation.\n */\n readonly operationState: TState | undefined;\n /**\n * Returns the result value of the operation,\n * regardless of the state of the poller.\n * It can return 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\n/**\n * A state proxy that allows poller implementation to abstract away the operation\n * state. This is useful to implement `lroEngine` and `createPoller` in a modular\n * way.\n */\nexport interface StateProxy<TState, TResult> {\n initState: (config: OperationConfig) => RestorableOperationState<TState>;\n\n setRunning: (state: TState) => void;\n setCanceled: (state: TState) => void;\n setResult: (state: TState, result: TResult) => void;\n setError: (state: TState, error: Error) => void;\n setFailed: (state: TState) => void;\n setSucceeded: (state: TState) => void;\n\n isRunning: (state: TState) => boolean;\n isCanceled: (state: TState) => boolean;\n getResult: (state: TState) => TResult | undefined;\n getError: (state: TState) => Error | undefined;\n isFailed: (state: TState) => boolean;\n isSucceeded: (state: TState) => boolean;\n}\n"]}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/poller/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { 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<TState extends OperationState<TResult>, 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"]}
@@ -1,36 +1,34 @@
1
- import { LroError, Operation, OperationStatus, RestorableOperationState, StateProxy } from "./models.js";
1
+ import { LroError, Operation, OperationStatus, RestorableOperationState, OperationState } from "./models.js";
2
2
  /**
3
3
  * Deserializes the state
4
4
  */
5
- export declare function deserializeState<TState>(serializedState: string): RestorableOperationState<TState>;
5
+ export declare function deserializeState<TResult, TState extends OperationState<TResult>>(serializedState: string): RestorableOperationState<TResult, TState>;
6
6
  /**
7
7
  * Initiates the long-running operation.
8
8
  */
9
- export declare function initOperation<TResponse, TResult, TState>(inputs: {
9
+ export declare function initOperation<TResponse, TResult, TState extends OperationState<TResult>>(inputs: {
10
10
  init: Operation<TResponse, unknown>["init"];
11
- stateProxy: StateProxy<TState, TResult>;
12
11
  getOperationStatus: (inputs: {
13
12
  response: TResponse;
14
- state: RestorableOperationState<TState>;
13
+ state: RestorableOperationState<TResult, TState>;
15
14
  operationLocation?: string;
16
15
  }) => OperationStatus;
17
- processResult?: (result: TResponse, state: TState) => TResult | Promise<TResult>;
16
+ processResult?: (result: TResponse, state: TState) => Promise<TResult>;
18
17
  withOperationLocation?: (operationLocation: string, isUpdated: boolean) => void;
19
18
  setErrorAsResult: boolean;
20
- }): Promise<RestorableOperationState<TState>>;
19
+ }): Promise<RestorableOperationState<TResult, TState>>;
21
20
  /** Polls the long-running operation. */
22
- export declare function pollOperation<TResponse, TState, TResult, TOptions>(inputs: {
21
+ export declare function pollOperation<TResponse, TResult, TState extends OperationState<TResult>, TOptions>(inputs: {
23
22
  poll: Operation<TResponse, TOptions>["poll"];
24
- stateProxy: StateProxy<TState, TResult>;
25
- state: RestorableOperationState<TState>;
26
- getOperationStatus: (response: TResponse, state: RestorableOperationState<TState>) => OperationStatus;
27
- getResourceLocation: (response: TResponse, state: RestorableOperationState<TState>) => string | undefined;
23
+ state: RestorableOperationState<TResult, TState>;
24
+ getOperationStatus: (response: TResponse, state: RestorableOperationState<TResult, TState>) => OperationStatus;
25
+ getResourceLocation: (response: TResponse, state: RestorableOperationState<TResult, TState>) => string | undefined;
28
26
  isOperationError: (error: Error) => boolean;
29
27
  getPollingInterval?: (response: TResponse) => number | undefined;
30
28
  setDelay: (intervalInMs: number) => void;
31
- getOperationLocation?: (response: TResponse, state: RestorableOperationState<TState>) => string | undefined;
29
+ getOperationLocation?: (response: TResponse, state: RestorableOperationState<TResult, TState>) => string | undefined;
32
30
  withOperationLocation?: (operationLocation: string, isUpdated: boolean) => void;
33
- processResult?: (result: TResponse, state: TState) => TResult | Promise<TResult>;
31
+ processResult?: (result: TResponse, state: TState) => Promise<TResult>;
34
32
  getError?: (response: TResponse) => LroError | undefined;
35
33
  updateState?: (state: TState, lastResponse: TResponse) => void;
36
34
  isDone?: (lastResponse: TResponse, state: TState) => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/poller/operation.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,QAAQ,EAER,SAAS,EACT,eAAe,EACf,wBAAwB,EACxB,UAAU,EACX,MAAM,aAAa,CAAC;AAIrB;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EACrC,eAAe,EAAE,MAAM,GACtB,wBAAwB,CAAC,MAAM,CAAC,CAMlC;AAuGD;;GAEG;AACH,wBAAsB,aAAa,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE;IACtE,IAAI,EAAE,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;IAC5C,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,kBAAkB,EAAE,CAAC,MAAM,EAAE;QAC3B,QAAQ,EAAE,SAA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,QAAQ,EAAE,SAAS,EACnB,KAAK,EAAE,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,KAC7C,MAAM,GAAG,SAAS,CAAC;IACxB,qBAAqB,CAAC,EAAE,CAAC,iBAAiB,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;IAChF,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACvE,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,QAAQ,GAAG,SAAS,CAAC;IACzD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,KAAK,IAAI,CAAC;IAC/D,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAC7D,gBAAgB,EAAE,OAAO,CAAC;IAC1B,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmDhB"}
@@ -14,11 +14,11 @@ export function deserializeState(serializedState) {
14
14
  }
15
15
  }
16
16
  function setStateError(inputs) {
17
- const { state, stateProxy, isOperationError } = inputs;
17
+ const { state, isOperationError } = inputs;
18
18
  return (error) => {
19
19
  if (isOperationError(error)) {
20
- stateProxy.setError(state, error);
21
- stateProxy.setFailed(state);
20
+ state.error = error;
21
+ state.status = "failed";
22
22
  }
23
23
  throw error;
24
24
  };
@@ -45,38 +45,38 @@ function simplifyError(err) {
45
45
  };
46
46
  }
47
47
  async function processOperationStatus(result) {
48
- const { state, stateProxy, status, isDone, processResult, getError, response, setErrorAsResult } = result;
48
+ const { state, status, isDone, processResult, getError, response, setErrorAsResult } = result;
49
49
  switch (status) {
50
50
  case "succeeded": {
51
- stateProxy.setSucceeded(state);
51
+ state.status = "succeeded";
52
52
  break;
53
53
  }
54
54
  case "failed": {
55
- const err = getError?.(response);
55
+ const err = getError === null || getError === void 0 ? void 0 : getError(response);
56
56
  let postfix = "";
57
57
  if (err) {
58
58
  const { code, message } = simplifyError(err);
59
59
  postfix = `. ${code}. ${message}`;
60
60
  }
61
61
  const errStr = `The long-running operation has failed${postfix}`;
62
- stateProxy.setError(state, new Error(errStr));
63
- stateProxy.setFailed(state);
62
+ state.error = new Error(errStr);
63
+ state.status = "failed";
64
64
  logger.warning(errStr);
65
65
  break;
66
66
  }
67
67
  case "canceled": {
68
- stateProxy.setCanceled(state);
68
+ state.status = "canceled";
69
69
  break;
70
70
  }
71
71
  }
72
- if (isDone?.(response, state) ||
72
+ if ((isDone === null || isDone === void 0 ? void 0 : isDone(response, state)) ||
73
73
  (isDone === undefined &&
74
74
  ["succeeded", "canceled"].concat(setErrorAsResult ? [] : ["failed"]).includes(status))) {
75
- stateProxy.setResult(state, await buildResult({
75
+ state.result = await buildResult({
76
76
  response,
77
77
  state,
78
78
  processResult,
79
- }));
79
+ });
80
80
  }
81
81
  }
82
82
  async function buildResult(inputs) {
@@ -87,24 +87,23 @@ async function buildResult(inputs) {
87
87
  * Initiates the long-running operation.
88
88
  */
89
89
  export async function initOperation(inputs) {
90
- const { init, stateProxy, processResult, getOperationStatus, withOperationLocation, setErrorAsResult, } = inputs;
91
- const { operationLocation, resourceLocation, initialUrl, requestMethod, metadata, response } = await init();
90
+ const { init, processResult, getOperationStatus, withOperationLocation, setErrorAsResult } = inputs;
91
+ const { operationLocation, resourceLocation, initialRequestUrl, requestMethod, metadata, response, } = await init();
92
92
  if (operationLocation)
93
- withOperationLocation?.(operationLocation, false);
93
+ withOperationLocation === null || withOperationLocation === void 0 ? void 0 : withOperationLocation(operationLocation, false);
94
94
  const config = {
95
95
  metadata,
96
96
  operationLocation,
97
97
  resourceLocation,
98
- initialUrl,
98
+ initialRequestUrl,
99
99
  requestMethod,
100
100
  };
101
101
  logger.verbose(`LRO: Operation description:`, config);
102
- const state = stateProxy.initState(config);
102
+ const state = { status: "running", config };
103
103
  const status = getOperationStatus({ response, state, operationLocation });
104
104
  await processOperationStatus({
105
105
  state,
106
106
  status,
107
- stateProxy,
108
107
  response,
109
108
  setErrorAsResult,
110
109
  processResult,
@@ -112,10 +111,9 @@ export async function initOperation(inputs) {
112
111
  return state;
113
112
  }
114
113
  async function pollOperationHelper(inputs) {
115
- const { poll, state, stateProxy, operationLocation, getOperationStatus, getResourceLocation, isOperationError, options, } = inputs;
114
+ const { poll, state, operationLocation, getOperationStatus, getResourceLocation, isOperationError, options, } = inputs;
116
115
  const response = await poll(operationLocation, options).catch(setStateError({
117
116
  state,
118
- stateProxy,
119
117
  isOperationError,
120
118
  }));
121
119
  const status = getOperationStatus(response, state);
@@ -124,7 +122,7 @@ async function pollOperationHelper(inputs) {
124
122
  const resourceLocation = getResourceLocation(response, state);
125
123
  if (resourceLocation !== undefined) {
126
124
  return {
127
- response: await poll(resourceLocation).catch(setStateError({ state, stateProxy, isOperationError })),
125
+ response: await poll(resourceLocation).catch(setStateError({ state, isOperationError })),
128
126
  status,
129
127
  };
130
128
  }
@@ -133,14 +131,13 @@ async function pollOperationHelper(inputs) {
133
131
  }
134
132
  /** Polls the long-running operation. */
135
133
  export async function pollOperation(inputs) {
136
- const { poll, state, stateProxy, options, getOperationStatus, getResourceLocation, getOperationLocation, isOperationError, withOperationLocation, getPollingInterval, processResult, getError, updateState, setDelay, isDone, setErrorAsResult, } = inputs;
134
+ const { poll, state, options, getOperationStatus, getResourceLocation, getOperationLocation, isOperationError, withOperationLocation, getPollingInterval, processResult, getError, updateState, setDelay, isDone, setErrorAsResult, } = inputs;
137
135
  const { operationLocation } = state.config;
138
136
  if (operationLocation !== undefined) {
139
137
  const { response, status } = await pollOperationHelper({
140
138
  poll,
141
139
  getOperationStatus,
142
140
  state,
143
- stateProxy,
144
141
  operationLocation,
145
142
  getResourceLocation,
146
143
  isOperationError,
@@ -150,26 +147,25 @@ export async function pollOperation(inputs) {
150
147
  status,
151
148
  response,
152
149
  state,
153
- stateProxy,
154
150
  isDone,
155
151
  processResult,
156
152
  getError,
157
153
  setErrorAsResult,
158
154
  });
159
155
  if (!terminalStates.includes(status)) {
160
- const intervalInMs = getPollingInterval?.(response);
156
+ const intervalInMs = getPollingInterval === null || getPollingInterval === void 0 ? void 0 : getPollingInterval(response);
161
157
  if (intervalInMs)
162
158
  setDelay(intervalInMs);
163
- const location = getOperationLocation?.(response, state);
159
+ const location = getOperationLocation === null || getOperationLocation === void 0 ? void 0 : getOperationLocation(response, state);
164
160
  if (location !== undefined) {
165
161
  const isUpdated = operationLocation !== location;
166
162
  state.config.operationLocation = location;
167
- withOperationLocation?.(location, isUpdated);
163
+ withOperationLocation === null || withOperationLocation === void 0 ? void 0 : withOperationLocation(location, isUpdated);
168
164
  }
169
165
  else
170
- withOperationLocation?.(operationLocation, false);
166
+ withOperationLocation === null || withOperationLocation === void 0 ? void 0 : withOperationLocation(operationLocation, false);
171
167
  }
172
- updateState?.(state, response);
168
+ updateState === null || updateState === void 0 ? void 0 : updateState(state, response);
173
169
  }
174
170
  }
175
171
  //# sourceMappingURL=operation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/poller/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,eAAuB;IAEvB,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC;IAC3C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,sCAAsC,eAAe,EAAE,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAkB,MAIvC;IACC,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,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AQ,EAAE,MAAM,EAAE,GAAG,MAAM,mBAAmB,CAAC;YACrD,IAAI;YACJ,kBAAkB;YAClB,KAAK;YACL,UAAU;YACV,iBAAiB;YACjB,mBAAmB;YACnB,gBAAgB;YAChB,OAAO;SACR,CAAC,CAAC;QACH,MAAM,sBAAsB,CAAC;YAC3B,MAAM;YACN,QAAQ;YACR,KAAK;YACL,UAAU;YACV,MAAM;YACN,aAAa;YACb,QAAQ;YACR,gBAAgB;SACjB,CAAC,CAAC;QAEH,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACrC,MAAM,YAAY,GAAG,kBAAkB,EAAE,CAAC,QAAQ,CAAC,CAAC;YACpD,IAAI,YAAY;gBAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;YACzC,MAAM,QAAQ,GAAG,oBAAoB,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YACzD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,MAAM,SAAS,GAAG,iBAAiB,KAAK,QAAQ,CAAC;gBACjD,KAAK,CAAC,MAAM,CAAC,iBAAiB,GAAG,QAAQ,CAAC;gBAC1C,qBAAqB,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;YAC/C,CAAC;;gBAAM,qBAAqB,EAAE,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;QAC3D,CAAC;QACD,WAAW,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACjC,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n LroError,\n InnerError,\n Operation,\n OperationStatus,\n RestorableOperationState,\n StateProxy,\n} from \"./models.js\";\nimport { logger } from \"../logger.js\";\nimport { terminalStates } from \"./constants.js\";\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 isOperationError: (error: Error) => boolean;\n}): (error: Error) => never {\n const { state, stateProxy, isOperationError } = inputs;\n return (error: Error) => {\n if (isOperationError(error)) {\n stateProxy.setError(state, error);\n stateProxy.setFailed(state);\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<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 | Promise<TResult>;\n getError?: (response: TResponse) => LroError | undefined;\n isDone?: (lastResponse: TResponse, state: TState) => boolean;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { state, stateProxy, status, isDone, processResult, getError, response, setErrorAsResult } =\n result;\n switch (status) {\n case \"succeeded\": {\n stateProxy.setSucceeded(state);\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 stateProxy.setError(state, new Error(errStr));\n stateProxy.setFailed(state);\n logger.warning(errStr);\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 await buildResult({\n response,\n state,\n processResult,\n }),\n );\n }\n}\n\nasync function buildResult<TResponse, TResult, TState>(inputs: {\n response: TResponse;\n state: TState;\n processResult?: (result: TResponse, state: TState) => TResult | 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<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 | Promise<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 setErrorAsResult,\n } = inputs;\n const { operationLocation, resourceLocation, initialUrl, requestMethod, metadata, response } =\n await init();\n if (operationLocation) withOperationLocation?.(operationLocation, false);\n const config = {\n metadata,\n operationLocation,\n resourceLocation,\n initialUrl,\n requestMethod,\n };\n logger.verbose(`LRO: Operation description:`, config);\n const state = stateProxy.initState(config);\n const status = getOperationStatus({ response, state, operationLocation });\n await processOperationStatus({\n state,\n status,\n stateProxy,\n response,\n setErrorAsResult,\n processResult,\n });\n return state;\n}\n\nasync function pollOperationHelper<TResponse, TState, TResult, TOptions>(inputs: {\n poll: Operation<TResponse, TOptions>[\"poll\"];\n stateProxy: StateProxy<TState, TResult>;\n state: RestorableOperationState<TState>;\n operationLocation: string;\n getOperationStatus: (\n response: TResponse,\n state: RestorableOperationState<TState>,\n ) => OperationStatus;\n getResourceLocation: (\n response: TResponse,\n state: RestorableOperationState<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 stateProxy,\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 stateProxy,\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(\n setStateError({ state, stateProxy, isOperationError }),\n ),\n status,\n };\n }\n }\n return { response, status };\n}\n\n/** Polls the long-running operation. */\nexport async function pollOperation<TResponse, TState, TResult, TOptions>(inputs: {\n poll: Operation<TResponse, TOptions>[\"poll\"];\n stateProxy: StateProxy<TState, TResult>;\n state: RestorableOperationState<TState>;\n getOperationStatus: (\n response: TResponse,\n state: RestorableOperationState<TState>,\n ) => OperationStatus;\n getResourceLocation: (\n response: TResponse,\n state: RestorableOperationState<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<TState>,\n ) => string | undefined;\n withOperationLocation?: (operationLocation: string, isUpdated: boolean) => void;\n processResult?: (result: TResponse, state: TState) => TResult | 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 stateProxy,\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 stateProxy,\n operationLocation,\n getResourceLocation,\n isOperationError,\n options,\n });\n await processOperationStatus({\n status,\n response,\n state,\n stateProxy,\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"]}
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/poller/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,eAAuB;IAEvB,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC;IAC3C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,sCAAsC,eAAe,EAAE,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAkD,MAGvE;IACC,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;IAC3C,OAAO,CAAC,KAAY,EAAE,EAAE;QACtB,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;YACpB,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC;QAC1B,CAAC;QACD,MAAM,KAAK,CAAC;I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CAAC,MAAM,CAAC,EAAE,CAAC;YACrC,MAAM,YAAY,GAAG,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAG,QAAQ,CAAC,CAAC;YACpD,IAAI,YAAY;gBAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;YACzC,MAAM,QAAQ,GAAG,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAG,QAAQ,EAAE,KAAK,CAAC,CAAC;YACzD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,MAAM,SAAS,GAAG,iBAAiB,KAAK,QAAQ,CAAC;gBACjD,KAAK,CAAC,MAAM,CAAC,iBAAiB,GAAG,QAAQ,CAAC;gBAC1C,qBAAqB,aAArB,qBAAqB,uBAArB,qBAAqB,CAAG,QAAQ,EAAE,SAAS,CAAC,CAAC;YAC/C,CAAC;;gBAAM,qBAAqB,aAArB,qBAAqB,uBAArB,qBAAqB,CAAG,iBAAiB,EAAE,KAAK,CAAC,CAAC;QAC3D,CAAC;QACD,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAG,KAAK,EAAE,QAAQ,CAAC,CAAC;IACjC,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\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"]}
@@ -3,7 +3,7 @@ import { BuildCreatePollerOptions, CreatePollerOptions, Operation, OperationStat
3
3
  /**
4
4
  * Returns a poller factory.
5
5
  */
6
- export declare function buildCreatePoller<TResponse, TResult, TState extends OperationState<TResult>>(inputs: BuildCreatePollerOptions<TResponse, TState>): (lro: Operation<TResponse, {
6
+ export declare function buildCreatePoller<TResponse, TResult, TState extends OperationState<TResult>>(inputs: BuildCreatePollerOptions<TResponse, TResult, TState>): (lro: Operation<TResponse, {
7
7
  abortSignal?: AbortSignalLike;
8
8
  }>, options?: CreatePollerOptions<TResponse, TResult, TState>) => PollerLike<TState, TResult>;
9
9
  //# sourceMappingURL=poller.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"poller.d.ts","sourceRoot":"","sources":["../../../src/poller/poller.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,SAAS,EACT,cAAc,EAEd,UAAU,EAEX,MAAM,aAAa,CAAC;AA8BrB;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,cAAc,CAAC,OAAO,CAAC,EAC1F,MAAM,EAAE,wBAAwB,CAAC,SAAS,EAAE,MAAM,CAAC,GAClD,CACD,GAAG,EAAE,SAAS,CAAC,SAAS,EAAE;IAAE,WAAW,CAAC,EAAE,eAAe,CAAA;CAAE,CAAC,EAC5D,OAAO,CAAC,EAAE,mBAAmB,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,KACtD,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAuM/B"}
1
+ {"version":3,"file":"poller.d.ts","sourceRoot":"","sources":["../../../src/poller/poller.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,SAAS,EACT,cAAc,EAEd,UAAU,EACX,MAAM,aAAa,CAAC;AAIrB;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,cAAc,CAAC,OAAO,CAAC,EAC1F,MAAM,EAAE,wBAAwB,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,GAC3D,CACD,GAAG,EAAE,SAAS,CAAC,SAAS,EAAE;IAAE,WAAW,CAAC,EAAE,eAAe,CAAA;CAAE,CAAC,EAC5D,OAAO,CAAC,EAAE,mBAAmB,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,KACtD,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAiM/B"}
@@ -3,26 +3,6 @@
3
3
  import { deserializeState, initOperation, pollOperation } from "./operation.js";
4
4
  import { POLL_INTERVAL_IN_MS } from "./constants.js";
5
5
  import { delay } from "@azure/core-util";
6
- const createStateProxy = () => ({
7
- /**
8
- * The state at this point is created to be of type OperationState<TResult>.
9
- * It will be updated later to be of type TState when the
10
- * customer-provided callback, `updateState`, is called during polling.
11
- */
12
- initState: (config) => ({ status: "running", config }),
13
- setCanceled: (state) => (state.status = "canceled"),
14
- setError: (state, error) => (state.error = error),
15
- setResult: (state, result) => (state.result = result),
16
- setRunning: (state) => (state.status = "running"),
17
- setSucceeded: (state) => (state.status = "succeeded"),
18
- setFailed: (state) => (state.status = "failed"),
19
- getError: (state) => state.error,
20
- getResult: (state) => state.result,
21
- isCanceled: (state) => state.status === "canceled",
22
- isFailed: (state) => state.status === "failed",
23
- isRunning: (state) => state.status === "running",
24
- isSucceeded: (state) => state.status === "succeeded",
25
- });
26
6
  /**
27
7
  * Returns a poller factory.
28
8
  */
@@ -30,7 +10,6 @@ export function buildCreatePoller(inputs) {
30
10
  const { getOperationLocation, getStatusFromInitialResponse, getStatusFromPollResponse, isOperationError, getResourceLocation, getPollingInterval, getError, resolveOnUnsuccessful, } = inputs;
31
11
  return ({ init, poll }, options) => {
32
12
  const { processResult, updateState, withOperationLocation: withOperationLocationCallback, intervalInMs = POLL_INTERVAL_IN_MS, restoreFrom, } = options || {};
33
- const stateProxy = createStateProxy();
34
13
  const withOperationLocation = withOperationLocationCallback
35
14
  ? (() => {
36
15
  let called = false;
@@ -52,7 +31,6 @@ export function buildCreatePoller(inputs) {
52
31
  else {
53
32
  statePromise = initOperation({
54
33
  init,
55
- stateProxy,
56
34
  processResult,
57
35
  getOperationStatus: getStatusFromInitialResponse,
58
36
  withOperationLocation,
@@ -70,13 +48,11 @@ export function buildCreatePoller(inputs) {
70
48
  return state;
71
49
  },
72
50
  get result() {
73
- return state?.result;
51
+ return state === null || state === void 0 ? void 0 : state.result;
74
52
  },
75
53
  get isDone() {
76
- return ["succeeded", "failed", "canceled"].includes(state?.status ?? "");
77
- },
78
- get isStopped() {
79
- return resultPromise === undefined;
54
+ var _a;
55
+ return ["succeeded", "failed", "canceled"].includes((_a = state === null || state === void 0 ? void 0 : state.status) !== null && _a !== void 0 ? _a : "");
80
56
  },
81
57
  onProgress: (callback) => {
82
58
  const s = Symbol();
@@ -93,7 +69,7 @@ export function buildCreatePoller(inputs) {
93
69
  await statePromise;
94
70
  },
95
71
  pollUntilDone: async (pollOptions) => {
96
- resultPromise ??= (async () => {
72
+ resultPromise !== null && resultPromise !== void 0 ? resultPromise : (resultPromise = (async () => {
97
73
  await statePromise;
98
74
  if (!state) {
99
75
  throw new Error("Poller should be initialized but it is not!");
@@ -104,11 +80,11 @@ export function buildCreatePoller(inputs) {
104
80
  abortController.abort();
105
81
  }
106
82
  const abortSignal = abortController.signal;
107
- if (inputAbortSignal?.aborted) {
83
+ if (inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.aborted) {
108
84
  abortController.abort();
109
85
  }
110
86
  else if (!abortSignal.aborted) {
111
- inputAbortSignal?.addEventListener("abort", abortListener, { once: true });
87
+ inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.addEventListener("abort", abortListener, { once: true });
112
88
  }
113
89
  try {
114
90
  if (!poller.isDone) {
@@ -120,7 +96,7 @@ export function buildCreatePoller(inputs) {
120
96
  }
121
97
  }
122
98
  finally {
123
- inputAbortSignal?.removeEventListener("abort", abortListener);
99
+ inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.removeEventListener("abort", abortListener);
124
100
  }
125
101
  if (resolveOnUnsuccessful) {
126
102
  return poller.result;
@@ -140,7 +116,7 @@ export function buildCreatePoller(inputs) {
140
116
  }
141
117
  })().finally(() => {
142
118
  resultPromise = undefined;
143
- });
119
+ }));
144
120
  return resultPromise;
145
121
  },
146
122
  async poll(pollOptions) {
@@ -164,8 +140,7 @@ export function buildCreatePoller(inputs) {
164
140
  }
165
141
  await pollOperation({
166
142
  poll,
167
- state: state,
168
- stateProxy,
143
+ state,
169
144
  getOperationLocation,
170
145
  isOperationError,
171
146
  withOperationLocation,
@@ -1 +1 @@
1
- {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/poller/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAYlC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,MAAM,gBAAgB,GAGlB,GAAG,EAAE,CAAC,CAAC;IACT;;;;OAIG;IACH,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,CAAQ;IAC7D,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,UAAU,CA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;oBAC3B,QAAQ,KAAK,CAAC,MAAM,EAAE,CAAC;wBACrB,KAAK,UAAU;4BACb,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;wBAChC,KAAK,QAAQ;4BACX,MAAM,KAAK,CAAC,KAAK,CAAC;oBACtB,CAAC;gBACH,CAAC;gBAED,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,CACF,WAAuF,EACvF,UAAmF;gBAEnF,OAAO,MAAM,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;YAC9D,CAAC;YACD,KAAK,CACH,UAAmF;gBAEnF,OAAO,MAAM,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAClD,CAAC;YACD,OAAO,CAAC,SAA2C;gBACjD,OAAO,MAAM,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACnD,CAAC;YACD,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,QAAQ;SAC/B,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport {\n BuildCreatePollerOptions,\n CreatePollerOptions,\n Operation,\n OperationState,\n RestorableOperationState,\n PollerLike,\n StateProxy,\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\nconst createStateProxy: <TResult, TState extends OperationState<TResult>>() => StateProxy<\n TState,\n TResult\n> = () => ({\n /**\n * The state at this point is created to be of type OperationState<TResult>.\n * It will be updated later to be of type TState when the\n * customer-provided callback, `updateState`, is called during polling.\n */\n initState: (config) => ({ status: \"running\", config }) as any,\n setCanceled: (state) => (state.status = \"canceled\"),\n setError: (state, error) => (state.error = error),\n setResult: (state, result) => (state.result = result),\n setRunning: (state) => (state.status = \"running\"),\n setSucceeded: (state) => (state.status = \"succeeded\"),\n setFailed: (state) => (state.status = \"failed\"),\n\n getError: (state) => state.error,\n getResult: (state) => state.result,\n isCanceled: (state) => state.status === \"canceled\",\n isFailed: (state) => state.status === \"failed\",\n isRunning: (state) => state.status === \"running\",\n isSucceeded: (state) => state.status === \"succeeded\",\n});\n\n/**\n * Returns a poller factory.\n */\nexport function buildCreatePoller<TResponse, TResult, TState extends OperationState<TResult>>(\n inputs: BuildCreatePollerOptions<TResponse, 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 stateProxy = createStateProxy<TResult, TState>();\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<TState>;\n if (restoreFrom) {\n state = deserializeState(restoreFrom);\n statePromise = Promise.resolve(state);\n } else {\n statePromise = initOperation({\n init,\n stateProxy,\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 get isStopped(): boolean {\n return resultPromise === undefined;\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: state,\n stateProxy,\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"]}
1
+ {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/poller/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAWlC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,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AChB,qBAAqB;oBACrB,kBAAkB;oBAClB,kBAAkB,EAAE,yBAAyB;oBAC7C,mBAAmB;oBACnB,aAAa;oBACb,QAAQ;oBACR,WAAW;oBACX,OAAO,EAAE,WAAW;oBACpB,QAAQ,EAAE,CAAC,gBAAgB,EAAE,EAAE;wBAC7B,uBAAuB,GAAG,gBAAgB,CAAC;oBAC7C,CAAC;oBACD,gBAAgB,EAAE,CAAC,qBAAqB;iBACzC,CAAC,CAAC;gBACH,MAAM,oBAAoB,EAAE,CAAC;gBAC7B,IAAI,CAAC,qBAAqB,EAAE,CAAC;oBAC3B,QAAQ,KAAK,CAAC,MAAM,EAAE,CAAC;wBACrB,KAAK,UAAU;4BACb,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;wBAChC,KAAK,QAAQ;4BACX,MAAM,KAAK,CAAC,KAAK,CAAC;oBACtB,CAAC;gBACH,CAAC;gBAED,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,CACF,WAAuF,EACvF,UAAmF;gBAEnF,OAAO,MAAM,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;YAC9D,CAAC;YACD,KAAK,CACH,UAAmF;gBAEnF,OAAO,MAAM,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAClD,CAAC;YACD,OAAO,CAAC,SAA2C;gBACjD,OAAO,MAAM,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACnD,CAAC;YACD,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,QAAQ;SAC/B,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport {\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"]}
@@ -59,7 +59,7 @@ export interface OperationResponse<T = unknown, TRequest extends RawRequest = Ra
59
59
  /**
60
60
  * Description of a long running operation.
61
61
  */
62
- export interface LongRunningOperation<T = unknown> {
62
+ export interface RunningOperation<T = unknown> {
63
63
  /**
64
64
  * A function that can be used to send initial request to the service.
65
65
  */
@@ -91,7 +91,7 @@ export interface CreateHttpPollerOptions<TResult, TState> {
91
91
  /**
92
92
  * A function to process the result of the LRO.
93
93
  */
94
- processResult?: (result: unknown, state: TState) => TResult | Promise<TResult>;
94
+ processResult?: (result: unknown, state: TState) => Promise<TResult>;
95
95
  /**
96
96
  * A function to process the state of the LRO.
97
97
  */
@@ -1 +1 @@
1
- {"version":3,"file":"models.d.ts","sourceRoot":"","sources":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A6B;IAC7B,YAAY,EAAE,CAAC,CAAC;IAChB,uBAAuB;IACvB,WAAW,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO;IAC3C;;OAEG;IACH,kBAAkB,EAAE,MAAM,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9D;;OAEG;IACH,eAAe,EAAE,CACf,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAE,KACxC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;CACpC;AAED,MAAM,MAAM,iBAAiB,GAAG,mBAAmB,GAAG,kBAAkB,GAAG,MAAM,CAAC;AAElF;;GAEG;AACH,MAAM,WAAW,uBAAuB,CAAC,OAAO,EAAE,MAAM;IACtD;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;IAChD;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACrE;;OAEG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACnE;;;OAGG;IACH,qBAAqB,CAAC,EAAE,CAAC,iBAAiB,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5D;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC"}
@@ -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 { AbortSignalLike } from \"@azure/abort-controller\";\nimport { 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 = \"azure-async-operation\" | \"location\" | \"original-uri\";\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 LongRunningOperation<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 * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => TResult | Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { 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 = \"azure-async-operation\" | \"location\" | \"original-uri\";\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 * 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"]}