@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.
- package/dist/browser/http/models.d.ts +2 -2
- package/dist/browser/http/models.d.ts.map +1 -1
- package/dist/browser/http/models.js.map +1 -1
- package/dist/browser/http/operation.d.ts +11 -12
- package/dist/browser/http/operation.d.ts.map +1 -1
- package/dist/browser/http/operation.js +22 -16
- package/dist/browser/http/operation.js.map +1 -1
- package/dist/browser/http/poller.d.ts +2 -2
- package/dist/browser/http/poller.d.ts.map +1 -1
- package/dist/browser/http/poller.js +1 -15
- package/dist/browser/http/poller.js.map +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/poller/models.d.ts +15 -39
- package/dist/browser/poller/models.d.ts.map +1 -1
- package/dist/browser/poller/models.js.map +1 -1
- package/dist/browser/poller/operation.d.ts +12 -14
- package/dist/browser/poller/operation.d.ts.map +1 -1
- package/dist/browser/poller/operation.js +25 -29
- package/dist/browser/poller/operation.js.map +1 -1
- package/dist/browser/poller/poller.d.ts +1 -1
- package/dist/browser/poller/poller.d.ts.map +1 -1
- package/dist/browser/poller/poller.js +9 -34
- package/dist/browser/poller/poller.js.map +1 -1
- package/dist/commonjs/http/models.d.ts +2 -2
- package/dist/commonjs/http/models.d.ts.map +1 -1
- package/dist/commonjs/http/models.js.map +1 -1
- package/dist/commonjs/http/operation.d.ts +11 -12
- package/dist/commonjs/http/operation.d.ts.map +1 -1
- package/dist/commonjs/http/operation.js +22 -16
- package/dist/commonjs/http/operation.js.map +1 -1
- package/dist/commonjs/http/poller.d.ts +2 -2
- package/dist/commonjs/http/poller.d.ts.map +1 -1
- package/dist/commonjs/http/poller.js +1 -15
- package/dist/commonjs/http/poller.js.map +1 -1
- package/dist/commonjs/index.d.ts +1 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/poller/models.d.ts +15 -39
- package/dist/commonjs/poller/models.d.ts.map +1 -1
- package/dist/commonjs/poller/models.js.map +1 -1
- package/dist/commonjs/poller/operation.d.ts +12 -14
- package/dist/commonjs/poller/operation.d.ts.map +1 -1
- package/dist/commonjs/poller/operation.js +25 -29
- package/dist/commonjs/poller/operation.js.map +1 -1
- package/dist/commonjs/poller/poller.d.ts +1 -1
- package/dist/commonjs/poller/poller.d.ts.map +1 -1
- package/dist/commonjs/poller/poller.js +9 -34
- package/dist/commonjs/poller/poller.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/core-lro.d.ts +28 -32
- package/dist/esm/http/models.d.ts +2 -2
- package/dist/esm/http/models.d.ts.map +1 -1
- package/dist/esm/http/models.js.map +1 -1
- package/dist/esm/http/operation.d.ts +11 -12
- package/dist/esm/http/operation.d.ts.map +1 -1
- package/dist/esm/http/operation.js +22 -16
- package/dist/esm/http/operation.js.map +1 -1
- package/dist/esm/http/poller.d.ts +2 -2
- package/dist/esm/http/poller.d.ts.map +1 -1
- package/dist/esm/http/poller.js +1 -15
- package/dist/esm/http/poller.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/poller/models.d.ts +15 -39
- package/dist/esm/poller/models.d.ts.map +1 -1
- package/dist/esm/poller/models.js.map +1 -1
- package/dist/esm/poller/operation.d.ts +12 -14
- package/dist/esm/poller/operation.d.ts.map +1 -1
- package/dist/esm/poller/operation.js +25 -29
- package/dist/esm/poller/operation.js.map +1 -1
- package/dist/esm/poller/poller.d.ts +1 -1
- package/dist/esm/poller/poller.d.ts.map +1 -1
- package/dist/esm/poller/poller.js +9 -34
- package/dist/esm/poller/poller.js.map +1 -1
- package/dist/react-native/http/models.d.ts +2 -2
- package/dist/react-native/http/models.d.ts.map +1 -1
- package/dist/react-native/http/models.js.map +1 -1
- package/dist/react-native/http/operation.d.ts +11 -12
- package/dist/react-native/http/operation.d.ts.map +1 -1
- package/dist/react-native/http/operation.js +22 -16
- package/dist/react-native/http/operation.js.map +1 -1
- package/dist/react-native/http/poller.d.ts +2 -2
- package/dist/react-native/http/poller.d.ts.map +1 -1
- package/dist/react-native/http/poller.js +1 -15
- package/dist/react-native/http/poller.js.map +1 -1
- package/dist/react-native/index.d.ts +1 -1
- package/dist/react-native/index.d.ts.map +1 -1
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/poller/models.d.ts +15 -39
- package/dist/react-native/poller/models.d.ts.map +1 -1
- package/dist/react-native/poller/models.js.map +1 -1
- package/dist/react-native/poller/operation.d.ts +12 -14
- package/dist/react-native/poller/operation.d.ts.map +1 -1
- package/dist/react-native/poller/operation.js +25 -29
- package/dist/react-native/poller/operation.js.map +1 -1
- package/dist/react-native/poller/poller.d.ts +1 -1
- package/dist/react-native/poller/poller.d.ts.map +1 -1
- package/dist/react-native/poller/poller.js +9 -34
- package/dist/react-native/poller/poller.js.map +1 -1
- package/package.json +26 -20
- package/.rush/temp/operation/build/state.json +0 -3
- package/.rush/temp/operation/build_samples/all.log +0 -2
- package/.rush/temp/operation/build_samples/state.json +0 -3
- package/.rush/temp/shrinkwrap-deps.json +0 -510
- package/.tshy/browser.json +0 -12
- package/.tshy/build.json +0 -9
- package/.tshy/commonjs.json +0 -14
- package/.tshy/esm.json +0 -12
- package/.tshy/react-native.json +0 -12
- package/CHANGELOG.md +0 -179
- package/api-extractor.json +0 -31
- package/config/rush-project.json +0 -3
- package/core-lro.build.cache.error.log +0 -1
- package/core-lro.build_samples.cache.log +0 -1
- package/core-lro.build_samples.log +0 -2
- package/core-lro.pack.cache.log +0 -1
- package/core-lro.pack.log +0 -1
- package/docs/LROEngine.md +0 -158
- package/review/core-lro.api.md +0 -106
- package/samples/README.md +0 -284
- package/samples/typescript/samplesClient.ts +0 -254
- package/src/http/models.ts +0 -119
- package/src/http/operation.ts +0 -343
- package/src/http/poller.ts +0 -83
- package/src/index.ts +0 -21
- package/src/logger.ts +0 -10
- package/src/poller/constants.ts +0 -11
- package/src/poller/models.ts +0 -251
- package/src/poller/operation.ts +0 -315
- package/src/poller/poller.ts +0 -250
- package/temp/core-lro.api.json +0 -1892
- package/temp/core-lro.api.md +0 -106
- package/test/getYieldedValue.ts +0 -16
- package/test/lro.spec.ts +0 -3141
- package/test/matrix.ts +0 -46
- package/test/utils/coreRestPipelineLro.ts +0 -25
- package/test/utils/router.ts +0 -231
- package/test/utils/utils.ts +0 -144
- package/tsconfig.browser.config.json +0 -10
- package/tsconfig.json +0 -13
- package/tsdoc.json +0 -4
- package/tslint.json +0 -47
- package/vitest.browser.config.ts +0 -34
- package/vitest.config.ts +0 -31
|
@@ -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,
|
|
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,cAAc,EACf,MAAM,aAAa,CAAC;AAIrB;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,SAAS,cAAc,CAAC,OAAO,CAAC,EAC9E,eAAe,EAAE,MAAM,GACtB,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAM3C;AAqGD;;GAEG;AACH,wBAAsB,aAAa,CACjC,SAAS,EACT,OAAO,EACP,MAAM,SAAS,cAAc,CAAC,OAAO,CAAC,EACtC,MAAM,EAAE;IACR,IAAI,EAAE,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;IAC5C,kBAAkB,EAAE,CAAC,MAAM,EAAE;QAC3B,QAAQ,EAAE,SAAS,CAAC;Q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AAK,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"}
|
|
@@ -18,11 +18,11 @@ function deserializeState(serializedState) {
|
|
|
18
18
|
}
|
|
19
19
|
exports.deserializeState = deserializeState;
|
|
20
20
|
function setStateError(inputs) {
|
|
21
|
-
const { state,
|
|
21
|
+
const { state, isOperationError } = inputs;
|
|
22
22
|
return (error) => {
|
|
23
23
|
if (isOperationError(error)) {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
state.error = error;
|
|
25
|
+
state.status = "failed";
|
|
26
26
|
}
|
|
27
27
|
throw error;
|
|
28
28
|
};
|
|
@@ -49,38 +49,38 @@ function simplifyError(err) {
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
async function processOperationStatus(result) {
|
|
52
|
-
const { state,
|
|
52
|
+
const { state, status, isDone, processResult, getError, response, setErrorAsResult } = result;
|
|
53
53
|
switch (status) {
|
|
54
54
|
case "succeeded": {
|
|
55
|
-
|
|
55
|
+
state.status = "succeeded";
|
|
56
56
|
break;
|
|
57
57
|
}
|
|
58
58
|
case "failed": {
|
|
59
|
-
const err = getError
|
|
59
|
+
const err = getError === null || getError === void 0 ? void 0 : getError(response);
|
|
60
60
|
let postfix = "";
|
|
61
61
|
if (err) {
|
|
62
62
|
const { code, message } = simplifyError(err);
|
|
63
63
|
postfix = `. ${code}. ${message}`;
|
|
64
64
|
}
|
|
65
65
|
const errStr = `The long-running operation has failed${postfix}`;
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
state.error = new Error(errStr);
|
|
67
|
+
state.status = "failed";
|
|
68
68
|
logger_js_1.logger.warning(errStr);
|
|
69
69
|
break;
|
|
70
70
|
}
|
|
71
71
|
case "canceled": {
|
|
72
|
-
|
|
72
|
+
state.status = "canceled";
|
|
73
73
|
break;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
if (isDone
|
|
76
|
+
if ((isDone === null || isDone === void 0 ? void 0 : isDone(response, state)) ||
|
|
77
77
|
(isDone === undefined &&
|
|
78
78
|
["succeeded", "canceled"].concat(setErrorAsResult ? [] : ["failed"]).includes(status))) {
|
|
79
|
-
|
|
79
|
+
state.result = await buildResult({
|
|
80
80
|
response,
|
|
81
81
|
state,
|
|
82
82
|
processResult,
|
|
83
|
-
})
|
|
83
|
+
});
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
async function buildResult(inputs) {
|
|
@@ -91,24 +91,23 @@ async function buildResult(inputs) {
|
|
|
91
91
|
* Initiates the long-running operation.
|
|
92
92
|
*/
|
|
93
93
|
async function initOperation(inputs) {
|
|
94
|
-
const { init,
|
|
95
|
-
const { operationLocation, resourceLocation,
|
|
94
|
+
const { init, processResult, getOperationStatus, withOperationLocation, setErrorAsResult } = inputs;
|
|
95
|
+
const { operationLocation, resourceLocation, initialRequestUrl, requestMethod, metadata, response, } = await init();
|
|
96
96
|
if (operationLocation)
|
|
97
|
-
withOperationLocation
|
|
97
|
+
withOperationLocation === null || withOperationLocation === void 0 ? void 0 : withOperationLocation(operationLocation, false);
|
|
98
98
|
const config = {
|
|
99
99
|
metadata,
|
|
100
100
|
operationLocation,
|
|
101
101
|
resourceLocation,
|
|
102
|
-
|
|
102
|
+
initialRequestUrl,
|
|
103
103
|
requestMethod,
|
|
104
104
|
};
|
|
105
105
|
logger_js_1.logger.verbose(`LRO: Operation description:`, config);
|
|
106
|
-
const state =
|
|
106
|
+
const state = { status: "running", config };
|
|
107
107
|
const status = getOperationStatus({ response, state, operationLocation });
|
|
108
108
|
await processOperationStatus({
|
|
109
109
|
state,
|
|
110
110
|
status,
|
|
111
|
-
stateProxy,
|
|
112
111
|
response,
|
|
113
112
|
setErrorAsResult,
|
|
114
113
|
processResult,
|
|
@@ -117,10 +116,9 @@ async function initOperation(inputs) {
|
|
|
117
116
|
}
|
|
118
117
|
exports.initOperation = initOperation;
|
|
119
118
|
async function pollOperationHelper(inputs) {
|
|
120
|
-
const { poll, state,
|
|
119
|
+
const { poll, state, operationLocation, getOperationStatus, getResourceLocation, isOperationError, options, } = inputs;
|
|
121
120
|
const response = await poll(operationLocation, options).catch(setStateError({
|
|
122
121
|
state,
|
|
123
|
-
stateProxy,
|
|
124
122
|
isOperationError,
|
|
125
123
|
}));
|
|
126
124
|
const status = getOperationStatus(response, state);
|
|
@@ -129,7 +127,7 @@ async function pollOperationHelper(inputs) {
|
|
|
129
127
|
const resourceLocation = getResourceLocation(response, state);
|
|
130
128
|
if (resourceLocation !== undefined) {
|
|
131
129
|
return {
|
|
132
|
-
response: await poll(resourceLocation).catch(setStateError({ state,
|
|
130
|
+
response: await poll(resourceLocation).catch(setStateError({ state, isOperationError })),
|
|
133
131
|
status,
|
|
134
132
|
};
|
|
135
133
|
}
|
|
@@ -138,14 +136,13 @@ async function pollOperationHelper(inputs) {
|
|
|
138
136
|
}
|
|
139
137
|
/** Polls the long-running operation. */
|
|
140
138
|
async function pollOperation(inputs) {
|
|
141
|
-
const { poll, state,
|
|
139
|
+
const { poll, state, options, getOperationStatus, getResourceLocation, getOperationLocation, isOperationError, withOperationLocation, getPollingInterval, processResult, getError, updateState, setDelay, isDone, setErrorAsResult, } = inputs;
|
|
142
140
|
const { operationLocation } = state.config;
|
|
143
141
|
if (operationLocation !== undefined) {
|
|
144
142
|
const { response, status } = await pollOperationHelper({
|
|
145
143
|
poll,
|
|
146
144
|
getOperationStatus,
|
|
147
145
|
state,
|
|
148
|
-
stateProxy,
|
|
149
146
|
operationLocation,
|
|
150
147
|
getResourceLocation,
|
|
151
148
|
isOperationError,
|
|
@@ -155,26 +152,25 @@ async function pollOperation(inputs) {
|
|
|
155
152
|
status,
|
|
156
153
|
response,
|
|
157
154
|
state,
|
|
158
|
-
stateProxy,
|
|
159
155
|
isDone,
|
|
160
156
|
processResult,
|
|
161
157
|
getError,
|
|
162
158
|
setErrorAsResult,
|
|
163
159
|
});
|
|
164
160
|
if (!constants_js_1.terminalStates.includes(status)) {
|
|
165
|
-
const intervalInMs = getPollingInterval
|
|
161
|
+
const intervalInMs = getPollingInterval === null || getPollingInterval === void 0 ? void 0 : getPollingInterval(response);
|
|
166
162
|
if (intervalInMs)
|
|
167
163
|
setDelay(intervalInMs);
|
|
168
|
-
const location = getOperationLocation
|
|
164
|
+
const location = getOperationLocation === null || getOperationLocation === void 0 ? void 0 : getOperationLocation(response, state);
|
|
169
165
|
if (location !== undefined) {
|
|
170
166
|
const isUpdated = operationLocation !== location;
|
|
171
167
|
state.config.operationLocation = location;
|
|
172
|
-
withOperationLocation
|
|
168
|
+
withOperationLocation === null || withOperationLocation === void 0 ? void 0 : withOperationLocation(location, isUpdated);
|
|
173
169
|
}
|
|
174
170
|
else
|
|
175
|
-
withOperationLocation
|
|
171
|
+
withOperationLocation === null || withOperationLocation === void 0 ? void 0 : withOperationLocation(operationLocation, false);
|
|
176
172
|
}
|
|
177
|
-
updateState
|
|
173
|
+
updateState === null || updateState === void 0 ? void 0 : updateState(state, response);
|
|
178
174
|
}
|
|
179
175
|
}
|
|
180
176
|
exports.pollOperation = pollOper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AC;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;AAhFD,sCAgFC","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,4CAAsC;AACtC,iDAAgD;AAEhD;;GAEG;AACH,SAAgB,gBAAgB,CAC9B,eAAuB;IAEvB,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe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soft 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,
|
|
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"}
|
|
@@ -6,26 +6,6 @@ exports.buildCreatePoller = void 0;
|
|
|
6
6
|
const operation_js_1 = require("./operation.js");
|
|
7
7
|
const constants_js_1 = require("./constants.js");
|
|
8
8
|
const core_util_1 = require("@azure/core-util");
|
|
9
|
-
const createStateProxy = () => ({
|
|
10
|
-
/**
|
|
11
|
-
* The state at this point is created to be of type OperationState<TResult>.
|
|
12
|
-
* It will be updated later to be of type TState when the
|
|
13
|
-
* customer-provided callback, `updateState`, is called during polling.
|
|
14
|
-
*/
|
|
15
|
-
initState: (config) => ({ status: "running", config }),
|
|
16
|
-
setCanceled: (state) => (state.status = "canceled"),
|
|
17
|
-
setError: (state, error) => (state.error = error),
|
|
18
|
-
setResult: (state, result) => (state.result = result),
|
|
19
|
-
setRunning: (state) => (state.status = "running"),
|
|
20
|
-
setSucceeded: (state) => (state.status = "succeeded"),
|
|
21
|
-
setFailed: (state) => (state.status = "failed"),
|
|
22
|
-
getError: (state) => state.error,
|
|
23
|
-
getResult: (state) => state.result,
|
|
24
|
-
isCanceled: (state) => state.status === "canceled",
|
|
25
|
-
isFailed: (state) => state.status === "failed",
|
|
26
|
-
isRunning: (state) => state.status === "running",
|
|
27
|
-
isSucceeded: (state) => state.status === "succeeded",
|
|
28
|
-
});
|
|
29
9
|
/**
|
|
30
10
|
* Returns a poller factory.
|
|
31
11
|
*/
|
|
@@ -33,7 +13,6 @@ function buildCreatePoller(inputs) {
|
|
|
33
13
|
const { getOperationLocation, getStatusFromInitialResponse, getStatusFromPollResponse, isOperationError, getResourceLocation, getPollingInterval, getError, resolveOnUnsuccessful, } = inputs;
|
|
34
14
|
return ({ init, poll }, options) => {
|
|
35
15
|
const { processResult, updateState, withOperationLocation: withOperationLocationCallback, intervalInMs = constants_js_1.POLL_INTERVAL_IN_MS, restoreFrom, } = options || {};
|
|
36
|
-
const stateProxy = createStateProxy();
|
|
37
16
|
const withOperationLocation = withOperationLocationCallback
|
|
38
17
|
? (() => {
|
|
39
18
|
let called = false;
|
|
@@ -55,7 +34,6 @@ function buildCreatePoller(inputs) {
|
|
|
55
34
|
else {
|
|
56
35
|
statePromise = (0, operation_js_1.initOperation)({
|
|
57
36
|
init,
|
|
58
|
-
stateProxy,
|
|
59
37
|
processResult,
|
|
60
38
|
getOperationStatus: getStatusFromInitialResponse,
|
|
61
39
|
withOperationLocation,
|
|
@@ -73,13 +51,11 @@ function buildCreatePoller(inputs) {
|
|
|
73
51
|
return state;
|
|
74
52
|
},
|
|
75
53
|
get result() {
|
|
76
|
-
return state
|
|
54
|
+
return state === null || state === void 0 ? void 0 : state.result;
|
|
77
55
|
},
|
|
78
56
|
get isDone() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
get isStopped() {
|
|
82
|
-
return resultPromise === undefined;
|
|
57
|
+
var _a;
|
|
58
|
+
return ["succeeded", "failed", "canceled"].includes((_a = state === null || state === void 0 ? void 0 : state.status) !== null && _a !== void 0 ? _a : "");
|
|
83
59
|
},
|
|
84
60
|
onProgress: (callback) => {
|
|
85
61
|
const s = Symbol();
|
|
@@ -96,7 +72,7 @@ function buildCreatePoller(inputs) {
|
|
|
96
72
|
await statePromise;
|
|
97
73
|
},
|
|
98
74
|
pollUntilDone: async (pollOptions) => {
|
|
99
|
-
resultPromise
|
|
75
|
+
resultPromise !== null && resultPromise !== void 0 ? resultPromise : (resultPromise = (async () => {
|
|
100
76
|
await statePromise;
|
|
101
77
|
if (!state) {
|
|
102
78
|
throw new Error("Poller should be initialized but it is not!");
|
|
@@ -107,11 +83,11 @@ function buildCreatePoller(inputs) {
|
|
|
107
83
|
abortController.abort();
|
|
108
84
|
}
|
|
109
85
|
const abortSignal = abortController.signal;
|
|
110
|
-
if (inputAbortSignal
|
|
86
|
+
if (inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.aborted) {
|
|
111
87
|
abortController.abort();
|
|
112
88
|
}
|
|
113
89
|
else if (!abortSignal.aborted) {
|
|
114
|
-
inputAbortSignal
|
|
90
|
+
inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.addEventListener("abort", abortListener, { once: true });
|
|
115
91
|
}
|
|
116
92
|
try {
|
|
117
93
|
if (!poller.isDone) {
|
|
@@ -123,7 +99,7 @@ function buildCreatePoller(inputs) {
|
|
|
123
99
|
}
|
|
124
100
|
}
|
|
125
101
|
finally {
|
|
126
|
-
inputAbortSignal
|
|
102
|
+
inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.removeEventListener("abort", abortListener);
|
|
127
103
|
}
|
|
128
104
|
if (resolveOnUnsuccessful) {
|
|
129
105
|
return poller.result;
|
|
@@ -143,7 +119,7 @@ function buildCreatePoller(inputs) {
|
|
|
143
119
|
}
|
|
144
120
|
})().finally(() => {
|
|
145
121
|
resultPromise = undefined;
|
|
146
|
-
});
|
|
122
|
+
}));
|
|
147
123
|
return resultPromise;
|
|
148
124
|
},
|
|
149
125
|
async poll(pollOptions) {
|
|
@@ -167,8 +143,7 @@ function buildCreatePoller(inputs) {
|
|
|
167
143
|
}
|
|
168
144
|
await (0, operation_js_1.pollOperation)({
|
|
169
145
|
poll,
|
|
170
|
-
state
|
|
171
|
-
stateProxy,
|
|
146
|
+
state,
|
|
172
147
|
getOperationLocation,
|
|
173
148
|
isOperationError,
|
|
174
149
|
withOperationLocation,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/poller/poller.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAYlC,iDAAgF;AAChF,iDAAqD;AACrD,gDAAyC;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,CAAC;IACnD,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;IACjD,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;IACrD,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC;IACjD,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,WAAW,CAAC;IACrD,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC;IAE/C,QAAQ,EAAE,CAAC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AO,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;AA5MD,8CA4MC","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,iDAAgF;AAChF,iDAAqD;AACrD,gDAAyC;AACzC;;GAEG;AACH,SAAgB,iBAAiB,CAC/B,MAA4D;IAK5D,MAAM,EACJ,oBAAoB,EACpB,4BAA4B,EAC5B,yBAAyB,EACzB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,EACR,qBAAqB,GACtB,GAAG,MAAM,CAAC;IACX,OAAO,CACL,EAAE,IAAI,EAAE,IAAI,EAA2D,EACvE,OAAyD,EACzD,EAAE;QACF,MAAM,EACJ,aAAa,EACb,WAAW,EACX,qBAAqB,EAAE,6BAA6B,EACpD,YAAY,GAAG,kCAAmB,EAClC,WAAW,GACZ,GAAG,OAAO,IAAI,EAAE,CAAC;QAClB,MAAM,qBAAqB,GAAG,6BAA6B;YACzD,CAAC,CAAC,CAAC,GAAG,EAAE;gBACJ,IAAI,MAAM,GAAG,KAAK,CAAC;gBACnB,OAAO,CAAC,iBAAyB,EAAE,SAAkB,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AAK,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;AAtMD,8CAsMC","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"]}
|
package/dist/core-lro.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare type CancelOnProgress = () => void;
|
|
|
14
14
|
* @param options - options to configure the poller
|
|
15
15
|
* @returns an initialized poller
|
|
16
16
|
*/
|
|
17
|
-
export declare function createHttpPoller<TResult, TState extends OperationState<TResult>>(lro:
|
|
17
|
+
export declare function createHttpPoller<TResult, TState extends OperationState<TResult>>(lro: RunningOperation, options?: CreateHttpPollerOptions<TResult, TState>): PollerLike<TState, TResult>;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Options for `createPoller`.
|
|
@@ -35,7 +35,7 @@ export declare interface CreateHttpPollerOptions<TResult, TState> {
|
|
|
35
35
|
/**
|
|
36
36
|
* A function to process the result of the LRO.
|
|
37
37
|
*/
|
|
38
|
-
processResult?: (result: unknown, state: TState) =>
|
|
38
|
+
processResult?: (result: unknown, state: TState) => Promise<TResult>;
|
|
39
39
|
/**
|
|
40
40
|
* A function to process the state of the LRO.
|
|
41
41
|
*/
|
|
@@ -54,23 +54,7 @@ export declare interface CreateHttpPollerOptions<TResult, TState> {
|
|
|
54
54
|
/**
|
|
55
55
|
* Deserializes the state
|
|
56
56
|
*/
|
|
57
|
-
export declare function deserializeState<TState
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Description of a long running operation.
|
|
61
|
-
*/
|
|
62
|
-
export declare interface LongRunningOperation<T = unknown> {
|
|
63
|
-
/**
|
|
64
|
-
* A function that can be used to send initial request to the service.
|
|
65
|
-
*/
|
|
66
|
-
sendInitialRequest: () => Promise<OperationResponse<unknown>>;
|
|
67
|
-
/**
|
|
68
|
-
* A function that can be used to poll for the current status of a long running operation.
|
|
69
|
-
*/
|
|
70
|
-
sendPollRequest: (path: string, options?: {
|
|
71
|
-
abortSignal?: AbortSignalLike;
|
|
72
|
-
}) => Promise<OperationResponse<T>>;
|
|
73
|
-
}
|
|
57
|
+
export declare function deserializeState<TResult, TState extends OperationState<TResult>>(serializedState: string): RestorableOperationState<TResult, TState>;
|
|
74
58
|
|
|
75
59
|
/**
|
|
76
60
|
* Configurations for how to poll the operation and to check whether it has
|
|
@@ -81,8 +65,8 @@ export declare interface OperationConfig {
|
|
|
81
65
|
operationLocation?: string;
|
|
82
66
|
/** The resource location */
|
|
83
67
|
resourceLocation?: string;
|
|
84
|
-
/** The initial Url */
|
|
85
|
-
|
|
68
|
+
/** The initial request Url */
|
|
69
|
+
initialRequestUrl?: string;
|
|
86
70
|
/** The request method */
|
|
87
71
|
requestMethod?: string;
|
|
88
72
|
/** metadata about the operation */
|
|
@@ -125,25 +109,21 @@ export declare interface OperationState<TResult> {
|
|
|
125
109
|
export declare type OperationStatus = "notStarted" | "running" | "succeeded" | "canceled" | "failed";
|
|
126
110
|
|
|
127
111
|
/**
|
|
128
|
-
* A
|
|
112
|
+
* A poller for an operation.
|
|
129
113
|
*/
|
|
130
114
|
export declare interface PollerLike<TState extends OperationState<TResult>, TResult> extends Promise<TResult> {
|
|
131
115
|
/**
|
|
132
|
-
*
|
|
116
|
+
* Is true if the poller has finished polling.
|
|
133
117
|
*/
|
|
134
118
|
readonly isDone: boolean;
|
|
135
119
|
/**
|
|
136
|
-
*
|
|
137
|
-
|
|
138
|
-
readonly isStopped: boolean;
|
|
139
|
-
/**
|
|
140
|
-
* Returns the state of the operation.
|
|
120
|
+
* The state of the operation.
|
|
121
|
+
* It can be undefined if the poller has not been submitted yet.
|
|
141
122
|
*/
|
|
142
123
|
readonly operationState: TState | undefined;
|
|
143
124
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* It can return undefined or an incomplete form of the final TResult value
|
|
125
|
+
* The result value of the operation, regardless of the state of the poller.
|
|
126
|
+
* It can be undefined or an incomplete form of the final TResult value
|
|
147
127
|
* depending on the implementation.
|
|
148
128
|
*/
|
|
149
129
|
readonly result: TResult | undefined;
|
|
@@ -214,9 +194,25 @@ export declare type ResourceLocationConfig = "azure-async-operation" | "location
|
|
|
214
194
|
/**
|
|
215
195
|
* Type of a restorable long-running operation.
|
|
216
196
|
*/
|
|
217
|
-
export declare type RestorableOperationState<T
|
|
197
|
+
export declare type RestorableOperationState<TResult, T extends OperationState<TResult>> = T & {
|
|
218
198
|
/** The operation configuration */
|
|
219
199
|
config: OperationConfig;
|
|
220
200
|
};
|
|
221
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Description of a long running operation.
|
|
204
|
+
*/
|
|
205
|
+
export declare interface RunningOperation<T = unknown> {
|
|
206
|
+
/**
|
|
207
|
+
* A function that can be used to send initial request to the service.
|
|
208
|
+
*/
|
|
209
|
+
sendInitialRequest: () => Promise<OperationResponse<unknown>>;
|
|
210
|
+
/**
|
|
211
|
+
* A function that can be used to poll for the current status of a long running operation.
|
|
212
|
+
*/
|
|
213
|
+
sendPollRequest: (path: string, options?: {
|
|
214
|
+
abortSignal?: AbortSignalLike;
|
|
215
|
+
}) => Promise<OperationResponse<T>>;
|
|
216
|
+
}
|
|
217
|
+
|
|
222
218
|
export { }
|
|
@@ -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
|
|
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) =>
|
|
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":["../../../src/http/models.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,uBAAuB,GAAG,UAAU,GAAG,cAAc,CAAC;AAE3F;;GAEG;AAEH,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC3D,mCAAmC;IACnC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,4CAA4C;IAC5C,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,iDAAiD;IACjD,UAAU,CAAC,EAAE;QAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvE,wCAAwC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1B,2CAA2C;IAC3C,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,uBAAuB;IACvB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,QAAQ,SAAS,UAAU,GAAG,UAAU;IACnE,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,OAAO,EAAE,QAAQ,CAAC;IAClB,iJAAiJ;IACjJ,OAAO,EAAE;QACP,CAAC,UAAU,EAAE,MAAM,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AK,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
|
|
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"]}
|