@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.
Files changed (49) hide show
  1. package/README.md +14 -15
  2. package/dist/browser/http/models.js.map +1 -1
  3. package/dist/browser/http/operation.js +1 -1
  4. package/dist/browser/http/operation.js.map +1 -1
  5. package/dist/commonjs/http/models.js +1 -0
  6. package/dist/commonjs/http/models.js.map +2 -2
  7. package/dist/commonjs/http/operation.js +2 -1
  8. package/dist/commonjs/http/operation.js.map +3 -3
  9. package/dist/commonjs/http/poller.js +1 -0
  10. package/dist/commonjs/http/poller.js.map +1 -1
  11. package/dist/commonjs/http/utils.js +1 -0
  12. package/dist/commonjs/http/utils.js.map +1 -1
  13. package/dist/commonjs/index.js +1 -0
  14. package/dist/commonjs/index.js.map +1 -1
  15. package/dist/commonjs/logger.js +1 -0
  16. package/dist/commonjs/logger.js.map +1 -1
  17. package/dist/commonjs/poller/constants.js +1 -0
  18. package/dist/commonjs/poller/constants.js.map +1 -1
  19. package/dist/commonjs/poller/models.js +1 -0
  20. package/dist/commonjs/poller/models.js.map +1 -1
  21. package/dist/commonjs/poller/operation.js +1 -0
  22. package/dist/commonjs/poller/operation.js.map +1 -1
  23. package/dist/commonjs/poller/poller.js +1 -0
  24. package/dist/commonjs/poller/poller.js.map +1 -1
  25. package/dist/commonjs/tsdoc-metadata.json +1 -1
  26. package/dist/esm/http/models.js +4 -0
  27. package/dist/esm/http/models.js.map +1 -7
  28. package/dist/esm/http/operation.js +217 -219
  29. package/dist/esm/http/operation.js.map +1 -7
  30. package/dist/esm/http/poller.js +44 -58
  31. package/dist/esm/http/poller.js.map +1 -7
  32. package/dist/esm/http/utils.js +41 -32
  33. package/dist/esm/http/utils.js.map +1 -7
  34. package/dist/esm/index.js +5 -6
  35. package/dist/esm/index.js.map +1 -7
  36. package/dist/esm/logger.js +8 -4
  37. package/dist/esm/logger.js.map +1 -7
  38. package/dist/esm/poller/constants.js +11 -6
  39. package/dist/esm/poller/constants.js.map +1 -7
  40. package/dist/esm/poller/models.js +4 -0
  41. package/dist/esm/poller/models.js.map +1 -7
  42. package/dist/esm/poller/operation.js +150 -176
  43. package/dist/esm/poller/operation.js.map +1 -7
  44. package/dist/esm/poller/poller.js +176 -177
  45. package/dist/esm/poller/poller.js.map +1 -7
  46. package/dist/react-native/http/models.js.map +1 -1
  47. package/dist/react-native/http/operation.js +1 -1
  48. package/dist/react-native/http/operation.js.map +1 -1
  49. package/package.json +31 -20
@@ -1,197 +1,171 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
1
3
  import { logger } from "../logger.js";
2
4
  import { terminalStates } from "./constants.js";
3
- function deserializeState(serializedState) {
4
- try {
5
- return JSON.parse(serializedState).state;
6
- } catch (e) {
7
- throw new Error(`Unable to deserialize input state: ${serializedState}`);
8
- }
5
+ /**
6
+ * Deserializes the state
7
+ */
8
+ export function deserializeState(serializedState) {
9
+ try {
10
+ return JSON.parse(serializedState).state;
11
+ }
12
+ catch (e) {
13
+ throw new Error(`Unable to deserialize input state: ${serializedState}`);
14
+ }
9
15
  }
10
16
  function setStateError(inputs) {
11
- const { state, isOperationError } = inputs;
12
- return (error) => {
13
- if (isOperationError(error)) {
14
- state.error = error;
15
- state.status = "failed";
16
- }
17
- throw error;
18
- };
17
+ const { state, isOperationError } = inputs;
18
+ return (error) => {
19
+ if (isOperationError(error)) {
20
+ state.error = error;
21
+ state.status = "failed";
22
+ }
23
+ throw error;
24
+ };
19
25
  }
20
26
  function appendReadableErrorMessage(currentMessage, innerMessage) {
21
- let message = currentMessage;
22
- if (message.slice(-1) !== ".") {
23
- message = message + ".";
24
- }
25
- return message + " " + innerMessage;
27
+ let message = currentMessage;
28
+ if (message.slice(-1) !== ".") {
29
+ message = message + ".";
30
+ }
31
+ return message + " " + innerMessage;
26
32
  }
27
33
  function simplifyError(err) {
28
- let message = err.message;
29
- let code = err.code;
30
- let curErr = err;
31
- while (curErr.innererror) {
32
- curErr = curErr.innererror;
33
- code = curErr.code;
34
- message = appendReadableErrorMessage(message, curErr.message);
35
- }
36
- return {
37
- code,
38
- message
39
- };
34
+ let message = err.message;
35
+ let code = err.code;
36
+ let curErr = err;
37
+ while (curErr.innererror) {
38
+ curErr = curErr.innererror;
39
+ code = curErr.code;
40
+ message = appendReadableErrorMessage(message, curErr.message);
41
+ }
42
+ return {
43
+ code,
44
+ message,
45
+ };
40
46
  }
41
47
  async function processOperationStatus(result) {
42
- const { state, status, isDone, processResult, getError, response, setErrorAsResult } = result;
43
- switch (status) {
44
- case "succeeded": {
45
- state.status = "succeeded";
46
- break;
47
- }
48
- case "failed": {
49
- const err = getError?.(response);
50
- let postfix = "";
51
- if (err) {
52
- const { code, message } = simplifyError(err);
53
- postfix = `. ${code}. ${message}`;
54
- }
55
- const errStr = `The long-running operation has failed${postfix}`;
56
- state.error = new Error(errStr);
57
- state.status = "failed";
58
- logger.warning(errStr);
59
- break;
48
+ const { state, status, isDone, processResult, getError, response, setErrorAsResult } = result;
49
+ switch (status) {
50
+ case "succeeded": {
51
+ state.status = "succeeded";
52
+ break;
53
+ }
54
+ case "failed": {
55
+ const err = getError?.(response);
56
+ let postfix = "";
57
+ if (err) {
58
+ const { code, message } = simplifyError(err);
59
+ postfix = `. ${code}. ${message}`;
60
+ }
61
+ const errStr = `The long-running operation has failed${postfix}`;
62
+ state.error = new Error(errStr);
63
+ state.status = "failed";
64
+ logger.warning(errStr);
65
+ break;
66
+ }
67
+ case "canceled": {
68
+ state.status = "canceled";
69
+ break;
70
+ }
60
71
  }
61
- case "canceled": {
62
- state.status = "canceled";
63
- break;
72
+ if (isDone?.(response, state) ||
73
+ (isDone === undefined &&
74
+ ["succeeded", "canceled"].concat(setErrorAsResult ? [] : ["failed"]).includes(status))) {
75
+ state.result = await buildResult({
76
+ response,
77
+ state,
78
+ processResult,
79
+ });
64
80
  }
65
- }
66
- if (isDone?.(response, state) || isDone === void 0 && ["succeeded", "canceled"].concat(setErrorAsResult ? [] : ["failed"]).includes(status)) {
67
- state.result = await buildResult({
68
- response,
69
- state,
70
- processResult
71
- });
72
- }
73
81
  }
74
82
  async function buildResult(inputs) {
75
- const { processResult, response, state } = inputs;
76
- return processResult ? processResult(response, state) : response;
83
+ const { processResult, response, state } = inputs;
84
+ return processResult ? processResult(response, state) : response;
77
85
  }
78
- async function initOperation(inputs) {
79
- const { init, processResult, getOperationStatus, withOperationLocation, setErrorAsResult } = inputs;
80
- const {
81
- operationLocation,
82
- resourceLocation,
83
- initialRequestUrl,
84
- requestMethod,
85
- metadata,
86
- response
87
- } = await init();
88
- if (operationLocation) withOperationLocation?.(operationLocation, false);
89
- const config = {
90
- metadata,
91
- operationLocation,
92
- resourceLocation,
93
- initialRequestUrl,
94
- requestMethod
95
- };
96
- logger.verbose(`LRO: Operation description:`, config);
97
- const state = { status: "running", config };
98
- const status = getOperationStatus({ response, state, operationLocation });
99
- await processOperationStatus({
100
- state,
101
- status,
102
- response,
103
- setErrorAsResult,
104
- processResult
105
- });
106
- return state;
86
+ /**
87
+ * Initiates the long-running operation.
88
+ */
89
+ export async function initOperation(inputs) {
90
+ const { init, processResult, getOperationStatus, withOperationLocation, setErrorAsResult } = inputs;
91
+ const { operationLocation, resourceLocation, initialRequestUrl, requestMethod, metadata, response, } = await init();
92
+ if (operationLocation)
93
+ withOperationLocation?.(operationLocation, false);
94
+ const config = {
95
+ metadata,
96
+ operationLocation,
97
+ resourceLocation,
98
+ initialRequestUrl,
99
+ requestMethod,
100
+ };
101
+ logger.verbose(`LRO: Operation description:`, config);
102
+ const state = { status: "running", config };
103
+ const status = getOperationStatus({ response, state, operationLocation });
104
+ await processOperationStatus({
105
+ state,
106
+ status,
107
+ response,
108
+ setErrorAsResult,
109
+ processResult,
110
+ });
111
+ return state;
107
112
  }
108
113
  async function pollOperationHelper(inputs) {
109
- const {
110
- poll,
111
- state,
112
- operationLocation,
113
- getOperationStatus,
114
- getResourceLocation,
115
- isOperationError,
116
- options
117
- } = inputs;
118
- const response = await poll(operationLocation, options).catch(
119
- setStateError({
120
- state,
121
- isOperationError
122
- })
123
- );
124
- const status = getOperationStatus(response, state);
125
- logger.verbose(
126
- `LRO: Status:
127
- Polling from: ${state.config.operationLocation}
128
- Operation status: ${status}
129
- Polling status: ${terminalStates.includes(status) ? "Stopped" : "Running"}`
130
- );
131
- if (status === "succeeded") {
132
- const resourceLocation = getResourceLocation(response, state);
133
- if (resourceLocation !== void 0) {
134
- return {
135
- response: await poll(resourceLocation).catch(setStateError({ state, isOperationError })),
136
- status
137
- };
114
+ const { poll, state, operationLocation, getOperationStatus, getResourceLocation, isOperationError, options, } = inputs;
115
+ const response = await poll(operationLocation, options).catch(setStateError({
116
+ state,
117
+ isOperationError,
118
+ }));
119
+ const status = getOperationStatus(response, state);
120
+ logger.verbose(`LRO: Status:\n\tPolling from: ${state.config.operationLocation}\n\tOperation status: ${status}\n\tPolling status: ${terminalStates.includes(status) ? "Stopped" : "Running"}`);
121
+ if (status === "succeeded") {
122
+ const resourceLocation = getResourceLocation(response, state);
123
+ if (resourceLocation !== undefined) {
124
+ return {
125
+ response: await poll(resourceLocation).catch(setStateError({ state, isOperationError })),
126
+ status,
127
+ };
128
+ }
138
129
  }
139
- }
140
- return { response, status };
130
+ return { response, status };
141
131
  }
142
- async function pollOperation(inputs) {
143
- const {
144
- poll,
145
- state,
146
- options,
147
- getOperationStatus,
148
- getResourceLocation,
149
- getOperationLocation,
150
- isOperationError,
151
- withOperationLocation,
152
- getPollingInterval,
153
- processResult,
154
- getError,
155
- updateState,
156
- setDelay,
157
- isDone,
158
- setErrorAsResult
159
- } = inputs;
160
- const { operationLocation } = state.config;
161
- if (operationLocation !== void 0) {
162
- const { response, status } = await pollOperationHelper({
163
- poll,
164
- getOperationStatus,
165
- state,
166
- operationLocation,
167
- getResourceLocation,
168
- isOperationError,
169
- options
170
- });
171
- await processOperationStatus({
172
- status,
173
- response,
174
- state,
175
- isDone,
176
- processResult,
177
- getError,
178
- setErrorAsResult
179
- });
180
- if (!terminalStates.includes(status)) {
181
- const intervalInMs = getPollingInterval?.(response);
182
- if (intervalInMs) setDelay(intervalInMs);
183
- const location = getOperationLocation?.(response, state);
184
- if (location !== void 0) {
185
- const isUpdated = operationLocation !== location;
186
- state.config.operationLocation = location;
187
- withOperationLocation?.(location, isUpdated);
188
- } else withOperationLocation?.(operationLocation, false);
132
+ /** Polls the long-running operation. */
133
+ export async function pollOperation(inputs) {
134
+ const { poll, state, options, getOperationStatus, getResourceLocation, getOperationLocation, isOperationError, withOperationLocation, getPollingInterval, processResult, getError, updateState, setDelay, isDone, setErrorAsResult, } = inputs;
135
+ const { operationLocation } = state.config;
136
+ if (operationLocation !== undefined) {
137
+ const { response, status } = await pollOperationHelper({
138
+ poll,
139
+ getOperationStatus,
140
+ state,
141
+ operationLocation,
142
+ getResourceLocation,
143
+ isOperationError,
144
+ options,
145
+ });
146
+ await processOperationStatus({
147
+ status,
148
+ response,
149
+ state,
150
+ isDone,
151
+ processResult,
152
+ getError,
153
+ setErrorAsResult,
154
+ });
155
+ if (!terminalStates.includes(status)) {
156
+ const intervalInMs = getPollingInterval?.(response);
157
+ if (intervalInMs)
158
+ setDelay(intervalInMs);
159
+ const location = getOperationLocation?.(response, state);
160
+ if (location !== undefined) {
161
+ const isUpdated = operationLocation !== location;
162
+ state.config.operationLocation = location;
163
+ withOperationLocation?.(location, isUpdated);
164
+ }
165
+ else
166
+ withOperationLocation?.(operationLocation, false);
167
+ }
168
+ updateState?.(state, response);
189
169
  }
190
- updateState?.(state, response);
191
- }
192
170
  }
193
- export {
194
- deserializeState,
195
- initOperation,
196
- pollOperation
197
- };
171
+ //# sourceMappingURL=operation.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["/mnt/vss/_work/1/s/sdk/core/core-lro/src/poller/operation.ts"],
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
- "mappings": "AAWA,SAAS,cAAc;AACvB,SAAS,sBAAsB;AAKxB,SAAS,iBACd,iBAC2C;AAC3C,MAAI;AACF,WAAO,KAAK,MAAM,eAAe,EAAE;AAAA,EACrC,SAAS,GAAG;AACV,UAAM,IAAI,MAAM,sCAAsC,eAAe,EAAE;AAAA,EACzE;AACF;AAEA,SAAS,cAA+D,QAG5C;AAC1B,QAAM,EAAE,OAAO,iBAAiB,IAAI;AACpC,SAAO,CAAC,UAAiB;AACvB,QAAI,iBAAiB,KAAK,GAAG;AAC3B,YAAM,QAAQ;AACd,YAAM,SAAS;AAAA,IACjB;AACA,UAAM;AAAA,EACR;AACF;AAEA,SAAS,2BAA2B,gBAAwB,cAA8B;AACxF,MAAI,UAAU;AACd,MAAI,QAAQ,MAAM,EAAE,MAAM,KAAK;AAC7B,cAAU,UAAU;AAAA,EACtB;AACA,SAAO,UAAU,MAAM;AACzB;AAEA,SAAS,cAAc,KAGrB;AACA,MAAI,UAAU,IAAI;AAClB,MAAI,OAAO,IAAI;AACf,MAAI,SAAS;AACb,SAAO,OAA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,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,EAAE,kBAAkB,IAAI,MAAM;AACpC,MAAI,sBAAsB,QAAW;AACnC,UAAM,EAAE,UAAU,OAAO,IAAI,MAAM,oBAAoB;AAAA,MACrD;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,uBAAuB;AAAA,MAC3B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,CAAC,eAAe,SAAS,MAAM,GAAG;AACpC,YAAM,eAAe,qBAAqB,QAAQ;AAClD,UAAI,aAAc,UAAS,YAAY;AACvC,YAAM,WAAW,uBAAuB,UAAU,KAAK;AACvD,UAAI,aAAa,QAAW;AAC1B,cAAM,YAAY,sBAAsB;AACxC,cAAM,OAAO,oBAAoB;AACjC,gCAAwB,UAAU,SAAS;AAAA,MAC7C,MAAO,yBAAwB,mBAAmB,KAAK;AAAA,IACzD;AACA,kBAAc,OAAO,QAAQ;AAAA,EAC/B;AACF;",
6
- "names": []
7
- }
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;AA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,iBAAiB;YACjB,mBAAmB;YACnB,gBAAgB;YAChB,OAAO;SACR,CAAC,CAAC;QACH,MAAM,sBAAsB,CAAC;YAC3B,MAAM;YACN,QAAQ;YACR,KAAK;YACL,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 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"]}