@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,32 +1,31 @@
|
|
|
1
|
-
import { HttpOperationMode,
|
|
2
|
-
import { LroError, OperationConfig, OperationStatus, RestorableOperationState
|
|
1
|
+
import { HttpOperationMode, RunningOperation, ResourceLocationConfig, OperationResponse, RawResponse } from "./models.js";
|
|
2
|
+
import { LroError, OperationConfig, OperationState, OperationStatus, RestorableOperationState } from "../poller/models.js";
|
|
3
3
|
import { AbortSignalLike } from "@azure/abort-controller";
|
|
4
4
|
export declare function inferLroMode(rawResponse: RawResponse, resourceLocationConfig?: ResourceLocationConfig): (OperationConfig & {
|
|
5
5
|
mode: HttpOperationMode;
|
|
6
6
|
}) | undefined;
|
|
7
7
|
export declare function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined;
|
|
8
8
|
export declare function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined;
|
|
9
|
-
export declare function getStatusFromInitialResponse<TState
|
|
9
|
+
export declare function getStatusFromInitialResponse<TResult, TState extends OperationState<TResult>>(inputs: {
|
|
10
10
|
response: OperationResponse<unknown>;
|
|
11
|
-
state: RestorableOperationState<TState>;
|
|
11
|
+
state: RestorableOperationState<TResult, TState>;
|
|
12
12
|
operationLocation?: string;
|
|
13
13
|
}): OperationStatus;
|
|
14
|
-
export declare function getOperationLocation<TState
|
|
15
|
-
export declare function getOperationStatus<TState
|
|
16
|
-
export declare function getResourceLocation<TState
|
|
14
|
+
export declare function getOperationLocation<TResult, TState extends OperationState<TResult>>({ rawResponse }: OperationResponse, state: RestorableOperationState<TResult, TState>): string | undefined;
|
|
15
|
+
export declare function getOperationStatus<TResult, TState extends OperationState<TResult>>({ rawResponse }: OperationResponse, state: RestorableOperationState<TResult, TState>): OperationStatus;
|
|
16
|
+
export declare function getResourceLocation<TResult, TState extends OperationState<TResult>>(res: OperationResponse, state: RestorableOperationState<TResult, TState>): string | undefined;
|
|
17
17
|
export declare function isOperationError(e: Error): boolean;
|
|
18
18
|
/** Polls the long-running operation. */
|
|
19
|
-
export declare function pollHttpOperation<TState
|
|
20
|
-
lro:
|
|
21
|
-
|
|
22
|
-
processResult?: (result: unknown, state: TState) => TResult;
|
|
19
|
+
export declare function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {
|
|
20
|
+
lro: RunningOperation;
|
|
21
|
+
processResult?: (result: unknown, state: TState) => Promise<TResult>;
|
|
23
22
|
updateState?: (state: TState, lastResponse: OperationResponse) => void;
|
|
24
23
|
isDone?: (lastResponse: OperationResponse, state: TState) => boolean;
|
|
25
24
|
setDelay: (intervalInMs: number) => void;
|
|
26
25
|
options?: {
|
|
27
26
|
abortSignal?: AbortSignalLike;
|
|
28
27
|
};
|
|
29
|
-
state: RestorableOperationState<TState>;
|
|
28
|
+
state: RestorableOperationState<TResult, TState>;
|
|
30
29
|
setErrorAsResult: boolean;
|
|
31
30
|
}): Promise<void>;
|
|
32
31
|
//# sourceMappingURL=operation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"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AAE,EAAE,iBAAiB,EAClC,KAAK,EAAE,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,GAC/C,eAAe,CAejB;AASD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,SAAS,cAAc,CAAC,OAAO,CAAC,EACjF,GAAG,EAAE,iBAAiB,EACtB,KAAK,EAAE,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,GAC/C,MAAM,GAAG,SAAS,CAMpB;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,GAAG,OAAO,CAElD;AAED,wCAAwC;AACxC,wBAAsB,iBAAiB,CAAC,MAAM,SAAS,cAAc,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE;IAC/F,GAAG,EAAE,gBAAgB,CAAC;IACtB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACrE,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACvE,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IACrE,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAE,CAAC;IAC5C,KAAK,EAAE,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACjD,gBAAgB,EAAE,OAAO,CAAC;CAC3B,GAAG,OAAO,CAAC,IAAI,CAAC,CAwBhB"}
|
|
@@ -7,7 +7,7 @@ const operation_js_1 = require("../poller/operation.js");
|
|
|
7
7
|
const logger_js_1 = require("../logger.js");
|
|
8
8
|
function getOperationLocationPollingUrl(inputs) {
|
|
9
9
|
const { azureAsyncOperation, operationLocation } = inputs;
|
|
10
|
-
return operationLocation
|
|
10
|
+
return operationLocation !== null && operationLocation !== void 0 ? operationLocation : azureAsyncOperation;
|
|
11
11
|
}
|
|
12
12
|
function getLocationHeader(rawResponse) {
|
|
13
13
|
return rawResponse.headers["location"];
|
|
@@ -19,6 +19,7 @@ function getAzureAsyncOperationHeader(rawResponse) {
|
|
|
19
19
|
return rawResponse.headers["azure-asyncoperation"];
|
|
20
20
|
}
|
|
21
21
|
function findResourceLocation(inputs) {
|
|
22
|
+
var _a;
|
|
22
23
|
const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;
|
|
23
24
|
switch (requestMethod) {
|
|
24
25
|
case "PUT": {
|
|
@@ -28,7 +29,7 @@ function findResourceLocation(inputs) {
|
|
|
28
29
|
return undefined;
|
|
29
30
|
}
|
|
30
31
|
case "PATCH": {
|
|
31
|
-
return getDefault()
|
|
32
|
+
return (_a = getDefault()) !== null && _a !== void 0 ? _a : requestPath;
|
|
32
33
|
}
|
|
33
34
|
default: {
|
|
34
35
|
return getDefault();
|
|
@@ -56,7 +57,7 @@ function inferLroMode(rawResponse, resourceLocationConfig) {
|
|
|
56
57
|
const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);
|
|
57
58
|
const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });
|
|
58
59
|
const location = getLocationHeader(rawResponse);
|
|
59
|
-
const normalizedRequestMethod = requestMethod
|
|
60
|
+
const normalizedRequestMethod = requestMethod === null || requestMethod === void 0 ? void 0 : requestMethod.toLocaleUpperCase();
|
|
60
61
|
if (pollingUrl !== undefined) {
|
|
61
62
|
return {
|
|
62
63
|
mode: "OperationLocation",
|
|
@@ -67,7 +68,7 @@ function inferLroMode(rawResponse, resourceLocationConfig) {
|
|
|
67
68
|
requestPath,
|
|
68
69
|
resourceLocationConfig,
|
|
69
70
|
}),
|
|
70
|
-
|
|
71
|
+
initialRequestUrl: requestPath,
|
|
71
72
|
requestMethod,
|
|
72
73
|
};
|
|
73
74
|
}
|
|
@@ -75,7 +76,7 @@ function inferLroMode(rawResponse, resourceLocationConfig) {
|
|
|
75
76
|
return {
|
|
76
77
|
mode: "ResourceLocation",
|
|
77
78
|
operationLocation: location,
|
|
78
|
-
|
|
79
|
+
initialRequestUrl: requestPath,
|
|
79
80
|
requestMethod,
|
|
80
81
|
};
|
|
81
82
|
}
|
|
@@ -83,7 +84,7 @@ function inferLroMode(rawResponse, resourceLocationConfig) {
|
|
|
83
84
|
return {
|
|
84
85
|
mode: "Body",
|
|
85
86
|
operationLocation: requestPath,
|
|
86
|
-
|
|
87
|
+
initialRequestUrl: requestPath,
|
|
87
88
|
requestMethod,
|
|
88
89
|
};
|
|
89
90
|
}
|
|
@@ -97,7 +98,7 @@ function transformStatus(inputs) {
|
|
|
97
98
|
if (typeof status !== "string" && status !== undefined) {
|
|
98
99
|
throw new Error(`Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`);
|
|
99
100
|
}
|
|
100
|
-
switch (status
|
|
101
|
+
switch (status === null || status === void 0 ? void 0 : status.toLocaleLowerCase()) {
|
|
101
102
|
case undefined:
|
|
102
103
|
return toOperationStatus(statusCode);
|
|
103
104
|
case "succeeded":
|
|
@@ -120,12 +121,14 @@ function transformStatus(inputs) {
|
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
123
|
function getStatus(rawResponse) {
|
|
123
|
-
|
|
124
|
+
var _a;
|
|
125
|
+
const { status } = (_a = rawResponse.body) !== null && _a !== void 0 ? _a : {};
|
|
124
126
|
return transformStatus({ status, statusCode: rawResponse.statusCode });
|
|
125
127
|
}
|
|
126
128
|
function getProvisioningState(rawResponse) {
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
+
var _a, _b;
|
|
130
|
+
const { properties, provisioningState } = (_a = rawResponse.body) !== null && _a !== void 0 ? _a : {};
|
|
131
|
+
const status = (_b = properties === null || properties === void 0 ? void 0 : properties.provisioningState) !== null && _b !== void 0 ? _b : provisioningState;
|
|
129
132
|
return transformStatus({ status, statusCode: rawResponse.statusCode });
|
|
130
133
|
}
|
|
131
134
|
function toOperationStatus(statusCode) {
|
|
@@ -175,7 +178,8 @@ function calculatePollingIntervalFromDate(retryAfterDate) {
|
|
|
175
178
|
function getStatusFromInitialResponse(inputs) {
|
|
176
179
|
const { response, state, operationLocation } = inputs;
|
|
177
180
|
function helper() {
|
|
178
|
-
|
|
181
|
+
var _a;
|
|
182
|
+
const mode = (_a = state.config.metadata) === null || _a === void 0 ? void 0 : _a["mode"];
|
|
179
183
|
switch (mode) {
|
|
180
184
|
case undefined:
|
|
181
185
|
return toOperationStatus(response.rawResponse.statusCode);
|
|
@@ -190,7 +194,8 @@ function getStatusFromInitialResponse(inputs) {
|
|
|
190
194
|
}
|
|
191
195
|
exports.getStatusFromInitialResponse = getStatusFromInitialResponse;
|
|
192
196
|
function getOperationLocation({ rawResponse }, state) {
|
|
193
|
-
|
|
197
|
+
var _a;
|
|
198
|
+
const mode = (_a = state.config.metadata) === null || _a === void 0 ? void 0 : _a["mode"];
|
|
194
199
|
switch (mode) {
|
|
195
200
|
case "OperationLocation": {
|
|
196
201
|
return getOperationLocationPollingUrl({
|
|
@@ -209,7 +214,8 @@ function getOperationLocation({ rawResponse }, state) {
|
|
|
209
214
|
}
|
|
210
215
|
exports.getOperationLocation = getOperationLocation;
|
|
211
216
|
function getOperationStatus({ rawResponse }, state) {
|
|
212
|
-
|
|
217
|
+
var _a;
|
|
218
|
+
const mode = (_a = state.config.metadata) === null || _a === void 0 ? void 0 : _a["mode"];
|
|
213
219
|
switch (mode) {
|
|
214
220
|
case "OperationLocation": {
|
|
215
221
|
return getStatus(rawResponse);
|
|
@@ -226,7 +232,8 @@ function getOperationStatus({ rawResponse }, state) {
|
|
|
226
232
|
}
|
|
227
233
|
exports.getOperationStatus = getOperationStatus;
|
|
228
234
|
function accessBodyProperty({ flatResponse, rawResponse }, prop) {
|
|
229
|
-
|
|
235
|
+
var _a, _b;
|
|
236
|
+
return (_a = flatResponse === null || flatResponse === void 0 ? void 0 : flatResponse[prop]) !== null && _a !== void 0 ? _a : (_b = rawResponse.body) === null || _b === void 0 ? void 0 : _b[prop];
|
|
230
237
|
}
|
|
231
238
|
function getResourceLocation(res, state) {
|
|
232
239
|
const loc = accessBodyProperty(res, "resourceLocation");
|
|
@@ -242,10 +249,9 @@ function isOperationError(e) {
|
|
|
242
249
|
exports.isOperationError = isOperationError;
|
|
243
250
|
/** Polls the long-running operation. */
|
|
244
251
|
async function pollHttpOperation(inputs) {
|
|
245
|
-
const { lro,
|
|
252
|
+
const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;
|
|
246
253
|
return (0, operation_js_1.pollOperation)({
|
|
247
254
|
state,
|
|
248
|
-
stateProxy,
|
|
249
255
|
setDelay,
|
|
250
256
|
processResult: processResult
|
|
251
257
|
? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAiBlC,yDAAuD;AAEvD,4CAAsC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAC1D,OAAO,iBAAiB,IAAI,mBAAmB,CAAC;AAClD,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAwB;IACjD,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,0BAA0B,CAAC,WAAwB;IAC1D,OAAO,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,4BAA4B,CAAC,WAAwB;IAC5D,OAAO,WAAW,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,oBAAoB,CAAC,MAK7B;IACC,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aAAa,CAAC,YAAY,EAAE,UAAU,CAAC;YAC3E,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAuB;QACjD,QAAQ,EAAE,oBAAoB;QAC9B,WAAW;QACX,kBAAkB,EAAE,eAAe;QACnC,oBAAoB;QACpB,kBAAkB;QAClB,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC;AA5CD,8CA4CC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n HttpOperationMode,\n LongRunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport {\n LroError,\n OperationConfig,\n OperationStatus,\n RestorableOperationState,\n StateProxy,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault() {\n switch (resourceLocationConfig) {\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n }),\n initialUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<TState>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TState>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TState>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TState>(\n res: OperationResponse,\n state: RestorableOperationState<TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState, TResult>(inputs: {\n lro: LongRunningOperation;\n stateProxy: StateProxy<TState, TResult>;\n processResult?: (result: unknown, state: TState) => TResult;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const {\n lro,\n stateProxy,\n options,\n processResult,\n updateState,\n setDelay,\n state,\n setErrorAsResult,\n } = inputs;\n return pollOperation({\n state,\n stateProxy,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as TResult,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAiBlC,yDAAuD;AAEvD,4CAAsC;AAEtC,SAAS,8BAA8B,CAAC,MAGvC;IACC,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAC1D,OAAO,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,mBAAmB,CAAC;AAClD,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAwB;IACjD,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,0BAA0B,CAAC,WAAwB;IAC1D,OAAO,WAAW,CAAC,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AED,wCAAwC;AACjC,KAAK,UAAU,iBAAiB,CAAkD,MASxF;IACC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;IAC/F,OAAO,IAAA,4BAAa,EAAC;QACnB,KAAK;QACL,QAAQ;QACR,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,UAAU,CAAC;YAC3E,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;QAC1D,QAAQ,EAAE,oBAAoB;QAC9B,WAAW;QACX,kBAAkB,EAAE,eAAe;QACnC,oBAAoB;QACpB,kBAAkB;QAClB,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;QACP;;;WAGG;QACH,IAAI,EAAE,KAAK,EAAE,QAAgB,EAAE,YAAgD,EAAE,EAAE,CACjF,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC;QAC7C,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC;AAjCD,8CAiCC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n HttpOperationMode,\n RunningOperation,\n ResourceLocationConfig,\n OperationResponse,\n RawResponse,\n ResponseBody,\n} from \"./models.js\";\nimport {\n LroError,\n OperationConfig,\n OperationState,\n OperationStatus,\n RestorableOperationState,\n} from \"../poller/models.js\";\nimport { pollOperation } from \"../poller/operation.js\";\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { logger } from \"../logger.js\";\n\nfunction getOperationLocationPollingUrl(inputs: {\n operationLocation?: string;\n azureAsyncOperation?: string;\n}): string | undefined {\n const { azureAsyncOperation, operationLocation } = inputs;\n return operationLocation ?? azureAsyncOperation;\n}\n\nfunction getLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"location\"];\n}\n\nfunction getOperationLocationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"operation-location\"];\n}\n\nfunction getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {\n return rawResponse.headers[\"azure-asyncoperation\"];\n}\n\nfunction findResourceLocation(inputs: {\n requestMethod?: string;\n location?: string;\n requestPath?: string;\n resourceLocationConfig?: ResourceLocationConfig;\n}): string | undefined {\n const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;\n switch (requestMethod) {\n case \"PUT\": {\n return requestPath;\n }\n case \"DELETE\": {\n return undefined;\n }\n case \"PATCH\": {\n return getDefault() ?? requestPath;\n }\n default: {\n return getDefault();\n }\n }\n\n function getDefault() {\n switch (resourceLocationConfig) {\n case \"azure-async-operation\": {\n return undefined;\n }\n case \"original-uri\": {\n return requestPath;\n }\n case \"location\":\n default: {\n return location;\n }\n }\n }\n}\n\nexport function inferLroMode(\n rawResponse: RawResponse,\n resourceLocationConfig?: ResourceLocationConfig,\n): (OperationConfig & { mode: HttpOperationMode }) | undefined {\n const requestPath = rawResponse.request.url;\n const requestMethod = rawResponse.request.method;\n const operationLocation = getOperationLocationHeader(rawResponse);\n const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);\n const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });\n const location = getLocationHeader(rawResponse);\n const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();\n if (pollingUrl !== undefined) {\n return {\n mode: \"OperationLocation\",\n operationLocation: pollingUrl,\n resourceLocation: findResourceLocation({\n requestMethod: normalizedRequestMethod,\n location,\n requestPath,\n resourceLocationConfig,\n }),\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (location !== undefined) {\n return {\n mode: \"ResourceLocation\",\n operationLocation: location,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else if (normalizedRequestMethod === \"PUT\" && requestPath) {\n return {\n mode: \"Body\",\n operationLocation: requestPath,\n initialRequestUrl: requestPath,\n requestMethod,\n };\n } else {\n return undefined;\n }\n}\n\nfunction transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {\n const { status, statusCode } = inputs;\n if (typeof status !== \"string\" && status !== undefined) {\n throw new Error(\n `Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`,\n );\n }\n switch (status?.toLocaleLowerCase()) {\n case undefined:\n return toOperationStatus(statusCode);\n case \"succeeded\":\n return \"succeeded\";\n case \"failed\":\n return \"failed\";\n case \"running\":\n case \"accepted\":\n case \"started\":\n case \"canceling\":\n case \"cancelling\":\n return \"running\";\n case \"canceled\":\n case \"cancelled\":\n return \"canceled\";\n default: {\n logger.verbose(`LRO: unrecognized operation status: ${status}`);\n return status as OperationStatus;\n }\n }\n}\n\nfunction getStatus(rawResponse: RawResponse): OperationStatus {\n const { status } = (rawResponse.body as ResponseBody) ?? {};\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction getProvisioningState(rawResponse: RawResponse): OperationStatus {\n const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};\n const status = properties?.provisioningState ?? provisioningState;\n return transformStatus({ status, statusCode: rawResponse.statusCode });\n}\n\nfunction toOperationStatus(statusCode: number): OperationStatus {\n if (statusCode === 202) {\n return \"running\";\n } else if (statusCode < 300) {\n return \"succeeded\";\n } else {\n return \"failed\";\n }\n}\n\nexport function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {\n const retryAfter: string | undefined = rawResponse.headers[\"retry-after\"];\n if (retryAfter !== undefined) {\n // Retry-After header value is either in HTTP date format, or in seconds\n const retryAfterInSeconds = parseInt(retryAfter);\n return isNaN(retryAfterInSeconds)\n ? calculatePollingIntervalFromDate(new Date(retryAfter))\n : retryAfterInSeconds * 1000;\n }\n return undefined;\n}\n\nexport function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {\n const error = accessBodyProperty(response, \"error\");\n if (!error) {\n logger.warning(\n `The long-running operation failed but there is no error property in the response's body`,\n );\n return;\n }\n if (!error.code || !error.message) {\n logger.warning(\n `The long-running operation failed but the error property in the response's body doesn't contain code or message`,\n );\n return;\n }\n return error as LroError;\n}\n\nfunction calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {\n const timeNow = Math.floor(new Date().getTime());\n const retryAfterTime = retryAfterDate.getTime();\n if (timeNow < retryAfterTime) {\n return retryAfterTime - timeNow;\n }\n return undefined;\n}\n\nexport function getStatusFromInitialResponse<\n TResult,\n TState extends OperationState<TResult>,\n>(inputs: {\n response: OperationResponse<unknown>;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n}): OperationStatus {\n const { response, state, operationLocation } = inputs;\n function helper(): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case undefined:\n return toOperationStatus(response.rawResponse.statusCode);\n case \"Body\":\n return getOperationStatus(response, state);\n default:\n return \"running\";\n }\n }\n const status = helper();\n return status === \"running\" && operationLocation === undefined ? \"succeeded\" : status;\n}\n\nexport function getOperationLocation<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getOperationLocationPollingUrl({\n operationLocation: getOperationLocationHeader(rawResponse),\n azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),\n });\n }\n case \"ResourceLocation\": {\n return getLocationHeader(rawResponse);\n }\n case \"Body\":\n default: {\n return undefined;\n }\n }\n}\n\nexport function getOperationStatus<TResult, TState extends OperationState<TResult>>(\n { rawResponse }: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): OperationStatus {\n const mode = state.config.metadata?.[\"mode\"];\n switch (mode) {\n case \"OperationLocation\": {\n return getStatus(rawResponse);\n }\n case \"ResourceLocation\": {\n return toOperationStatus(rawResponse.statusCode);\n }\n case \"Body\": {\n return getProvisioningState(rawResponse);\n }\n default:\n throw new Error(`Internal error: Unexpected operation mode: ${mode}`);\n }\n}\n\nfunction accessBodyProperty<P extends string>(\n { flatResponse, rawResponse }: OperationResponse,\n prop: P,\n): ResponseBody[P] {\n return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];\n}\n\nexport function getResourceLocation<TResult, TState extends OperationState<TResult>>(\n res: OperationResponse,\n state: RestorableOperationState<TResult, TState>,\n): string | undefined {\n const loc = accessBodyProperty(res, \"resourceLocation\");\n if (loc && typeof loc === \"string\") {\n state.config.resourceLocation = loc;\n }\n return state.config.resourceLocation;\n}\n\nexport function isOperationError(e: Error): boolean {\n return e.name === \"RestError\";\n}\n\n/** Polls the long-running operation. */\nexport async function pollHttpOperation<TState extends OperationState<TResult>, TResult>(inputs: {\n lro: RunningOperation;\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n updateState?: (state: TState, lastResponse: OperationResponse) => void;\n isDone?: (lastResponse: OperationResponse, state: TState) => boolean;\n setDelay: (intervalInMs: number) => void;\n options?: { abortSignal?: AbortSignalLike };\n state: RestorableOperationState<TResult, TState>;\n setErrorAsResult: boolean;\n}): Promise<void> {\n const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;\n return pollOperation({\n state,\n setDelay,\n processResult: processResult\n ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n getError: getErrorFromResponse,\n updateState,\n getPollingInterval: parseRetryAfter,\n getOperationLocation,\n getOperationStatus,\n isOperationError,\n getResourceLocation,\n options,\n /**\n * The expansion here is intentional because `lro` could be an object that\n * references an inner this, so we need to preserve a reference to it.\n */\n poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>\n lro.sendPollRequest(location, inputOptions),\n setErrorAsResult,\n });\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RunningOperation } from "./models.js";
|
|
2
2
|
import { OperationState, PollerLike } from "../poller/models.js";
|
|
3
3
|
import { CreateHttpPollerOptions } from "./models.js";
|
|
4
4
|
/**
|
|
@@ -7,5 +7,5 @@ import { CreateHttpPollerOptions } from "./models.js";
|
|
|
7
7
|
* @param options - options to configure the poller
|
|
8
8
|
* @returns an initialized poller
|
|
9
9
|
*/
|
|
10
|
-
export declare function createHttpPoller<TResult, TState extends OperationState<TResult>>(lro:
|
|
10
|
+
export declare function createHttpPoller<TResult, TState extends OperationState<TResult>>(lro: RunningOperation, options?: CreateHttpPollerOptions<TResult, TState>): PollerLike<TState, TResult>;
|
|
11
11
|
//# sourceMappingURL=poller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poller.d.ts","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"poller.d.ts","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAqB,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAWjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAGtD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,SAAS,cAAc,CAAC,OAAO,CAAC,EAC9E,GAAG,EAAE,gBAAgB,EACrB,OAAO,CAAC,EAAE,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,GACjD,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CA6C7B"}
|
|
@@ -26,21 +26,7 @@ function createHttpPoller(lro, options) {
|
|
|
26
26
|
init: async () => {
|
|
27
27
|
const response = await lro.sendInitialRequest();
|
|
28
28
|
const config = (0, operation_js_1.inferLroMode)(response.rawResponse, resourceLocationConfig);
|
|
29
|
-
|
|
30
|
-
if (config?.mode) {
|
|
31
|
-
metadata["mode"] = config.mode;
|
|
32
|
-
}
|
|
33
|
-
if (resourceLocationConfig) {
|
|
34
|
-
metadata["resourceLocationConfig"] = resourceLocationConfig;
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
response,
|
|
38
|
-
operationLocation: config?.operationLocation,
|
|
39
|
-
resourceLocation: config?.resourceLocation,
|
|
40
|
-
initialUrl: config?.initialUrl,
|
|
41
|
-
requestMethod: config?.requestMethod,
|
|
42
|
-
metadata,
|
|
43
|
-
};
|
|
29
|
+
return Object.assign({ response, operationLocation: config === null || config === void 0 ? void 0 : config.operationLocation, resourceLocation: config === null || config === void 0 ? void 0 : config.resourceLocation, initialRequestUrl: config === null || config === void 0 ? void 0 : config.initialRequestUrl, requestMethod: config === null || config === void 0 ? void 0 : config.requestMethod }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
|
|
44
30
|
},
|
|
45
31
|
poll: lro.sendPollRequest,
|
|
46
32
|
}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;
|
|
1
|
+
{"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAIlC,iDASwB;AAExB,mDAAwD;AAExD;;;;;GAKG;AACH,SAAgB,gBAAgB,CAC9B,GAAqB,EACrB,OAAkD;IAElD,MAAM,EACJ,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,qBAAqB,GAAG,KAAK,GAC9B,GAAG,OAAO,IAAI,EAAE,CAAC;IAClB,OAAO,IAAA,6BAAiB,EAAqC;QAC3D,4BAA4B,EAA5B,2CAA4B;QAC5B,yBAAyB,EAAE,iCAAkB;QAC7C,gBAAgB,EAAhB,+BAAgB;QAChB,oBAAoB,EAApB,mCAAoB;QACpB,mBAAmB,EAAnB,kCAAmB;QACnB,kBAAkB,EAAE,8BAAe;QACnC,QAAQ,EAAE,mCAAoB;QAC9B,qBAAqB;KACtB,CAAC,CACA;QACE,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,kBAAkB,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,IAAA,2BAAY,EAAC,QAAQ,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAC;YAC1E,uBACE,QAAQ,EACR,iBAAiB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAC5C,gBAAgB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,EAC1C,iBAAiB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAC5C,aAAa,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,IACjC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,EAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC5D;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAgC;KAC3D,CACF,CAAC;AACJ,CAAC;AAhDD,4CAgDC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RunningOperation, OperationResponse } from \"./models.js\";\nimport { OperationState, PollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: RunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): PollerLike<TState, TResult> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n } = options || {};\n return buildCreatePoller<OperationResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode(response.rawResponse, resourceLocationConfig);\n return {\n response,\n operationLocation: config?.operationLocation,\n resourceLocation: config?.resourceLocation,\n initialRequestUrl: config?.initialRequestUrl,\n requestMethod: config?.requestMethod,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as Promise<TResult>,\n },\n );\n}\n"]}
|
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createHttpPoller } from "./http/poller.js";
|
|
2
2
|
export { CancelOnProgress, OperationState, OperationStatus, PollerLike, RestorableOperationState, OperationConfig, } from "./poller/models.js";
|
|
3
|
-
export { ResourceLocationConfig,
|
|
3
|
+
export { ResourceLocationConfig, RunningOperation, OperationResponse, RawResponse, RawRequest, CreateHttpPollerOptions, } from "./http/models.js";
|
|
4
4
|
export { deserializeState } from "./poller/operation.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,UAAU,EACV,wBAAwB,EACxB,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,sBAAsB,EACtB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,UAAU,EACV,wBAAwB,EACxB,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,8CAAoD;AAA3C,6GAAA,gBAAgB,OAAA;AAiBzB,sDAAyD;AAAhD,gHAAA,gBAAgB,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { createHttpPoller } from \"./http/poller.js\";\nexport {\n CancelOnProgress,\n OperationState,\n OperationStatus,\n PollerLike,\n RestorableOperationState,\n OperationConfig,\n} from \"./poller/models.js\";\nexport {\n ResourceLocationConfig,\n
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,8CAAoD;AAA3C,6GAAA,gBAAgB,OAAA;AAiBzB,sDAAyD;AAAhD,gHAAA,gBAAgB,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { createHttpPoller } from \"./http/poller.js\";\nexport {\n CancelOnProgress,\n OperationState,\n OperationStatus,\n PollerLike,\n RestorableOperationState,\n OperationConfig,\n} from \"./poller/models.js\";\nexport {\n ResourceLocationConfig,\n RunningOperation,\n OperationResponse,\n RawResponse,\n RawRequest,\n CreateHttpPollerOptions,\n} from \"./http/models.js\";\nexport { deserializeState } from \"./poller/operation.js\";\n"]}
|
|
@@ -8,8 +8,8 @@ export interface OperationConfig {
|
|
|
8
8
|
operationLocation?: string;
|
|
9
9
|
/** The resource location */
|
|
10
10
|
resourceLocation?: string;
|
|
11
|
-
/** The initial Url */
|
|
12
|
-
|
|
11
|
+
/** The initial request Url */
|
|
12
|
+
initialRequestUrl?: string;
|
|
13
13
|
/** The request method */
|
|
14
14
|
requestMethod?: string;
|
|
15
15
|
/** metadata about the operation */
|
|
@@ -34,7 +34,7 @@ export interface Operation<TResponse, TOptions> {
|
|
|
34
34
|
/**
|
|
35
35
|
* Type of a restorable long-running operation.
|
|
36
36
|
*/
|
|
37
|
-
export type RestorableOperationState<T
|
|
37
|
+
export type RestorableOperationState<TResult, T extends OperationState<TResult>> = T & {
|
|
38
38
|
/** The operation configuration */
|
|
39
39
|
config: OperationConfig;
|
|
40
40
|
};
|
|
@@ -53,7 +53,7 @@ export interface CreatePollerOptions<TResponse, TResult, TState> {
|
|
|
53
53
|
/**
|
|
54
54
|
* A function to process the result of the LRO.
|
|
55
55
|
*/
|
|
56
|
-
processResult?: (result: TResponse, state: TState) =>
|
|
56
|
+
processResult?: (result: TResponse, state: TState) => Promise<TResult>;
|
|
57
57
|
/**
|
|
58
58
|
* A function to process the state of the LRO.
|
|
59
59
|
*/
|
|
@@ -77,7 +77,7 @@ export interface InnerError {
|
|
|
77
77
|
/**
|
|
78
78
|
* Options for `buildCreatePoller`.
|
|
79
79
|
*/
|
|
80
|
-
export interface BuildCreatePollerOptions<TResponse, TState
|
|
80
|
+
export interface BuildCreatePollerOptions<TResponse, TResult, TState extends OperationState<TResult>> {
|
|
81
81
|
/**
|
|
82
82
|
* Gets the status of the operation from the response received when the
|
|
83
83
|
* operation was initialized. Note that the operation could be already in
|
|
@@ -85,14 +85,14 @@ export interface BuildCreatePollerOptions<TResponse, TState> {
|
|
|
85
85
|
*/
|
|
86
86
|
getStatusFromInitialResponse: (inputs: {
|
|
87
87
|
response: TResponse;
|
|
88
|
-
state: RestorableOperationState<TState>;
|
|
88
|
+
state: RestorableOperationState<TResult, TState>;
|
|
89
89
|
operationLocation?: string;
|
|
90
90
|
}) => OperationStatus;
|
|
91
91
|
/**
|
|
92
92
|
* Gets the status of the operation from a response received when the
|
|
93
93
|
* operation was polled.
|
|
94
94
|
*/
|
|
95
|
-
getStatusFromPollResponse: (response: TResponse, state: RestorableOperationState<TState>) => OperationStatus;
|
|
95
|
+
getStatusFromPollResponse: (response: TResponse, state: RestorableOperationState<TResult, TState>) => OperationStatus;
|
|
96
96
|
/**
|
|
97
97
|
* Determines if the input error is an operation error.
|
|
98
98
|
*/
|
|
@@ -100,11 +100,11 @@ export interface BuildCreatePollerOptions<TResponse, TState> {
|
|
|
100
100
|
/**
|
|
101
101
|
* Gets the updated operation location from polling responses.
|
|
102
102
|
*/
|
|
103
|
-
getOperationLocation?: (response: TResponse, state: RestorableOperationState<TState>) => string | undefined;
|
|
103
|
+
getOperationLocation?: (response: TResponse, state: RestorableOperationState<TResult, TState>) => string | undefined;
|
|
104
104
|
/**
|
|
105
105
|
* Gets the resource location from a response.
|
|
106
106
|
*/
|
|
107
|
-
getResourceLocation: (response: TResponse, state: RestorableOperationState<TState>) => string | undefined;
|
|
107
|
+
getResourceLocation: (response: TResponse, state: RestorableOperationState<TResult, TState>) => string | undefined;
|
|
108
108
|
/**
|
|
109
109
|
* Gets from the response the time interval the service suggests the client to
|
|
110
110
|
* wait before sending the next polling request.
|
|
@@ -150,25 +150,21 @@ export interface OperationState<TResult> {
|
|
|
150
150
|
*/
|
|
151
151
|
export type CancelOnProgress = () => void;
|
|
152
152
|
/**
|
|
153
|
-
* A
|
|
153
|
+
* A poller for an operation.
|
|
154
154
|
*/
|
|
155
155
|
export interface PollerLike<TState extends OperationState<TResult>, TResult> extends Promise<TResult> {
|
|
156
156
|
/**
|
|
157
|
-
*
|
|
157
|
+
* Is true if the poller has finished polling.
|
|
158
158
|
*/
|
|
159
159
|
readonly isDone: boolean;
|
|
160
160
|
/**
|
|
161
|
-
*
|
|
162
|
-
|
|
163
|
-
readonly isStopped: boolean;
|
|
164
|
-
/**
|
|
165
|
-
* Returns the state of the operation.
|
|
161
|
+
* The state of the operation.
|
|
162
|
+
* It can be undefined if the poller has not been submitted yet.
|
|
166
163
|
*/
|
|
167
164
|
readonly operationState: TState | undefined;
|
|
168
165
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* It can return undefined or an incomplete form of the final TResult value
|
|
166
|
+
* The result value of the operation, regardless of the state of the poller.
|
|
167
|
+
* It can be undefined or an incomplete form of the final TResult value
|
|
172
168
|
* depending on the implementation.
|
|
173
169
|
*/
|
|
174
170
|
readonly result: TResult | undefined;
|
|
@@ -202,24 +198,4 @@ export interface PollerLike<TState extends OperationState<TResult>, TResult> ext
|
|
|
202
198
|
*/
|
|
203
199
|
submitted(): Promise<void>;
|
|
204
200
|
}
|
|
205
|
-
/**
|
|
206
|
-
* A state proxy that allows poller implementation to abstract away the operation
|
|
207
|
-
* state. This is useful to implement `lroEngine` and `createPoller` in a modular
|
|
208
|
-
* way.
|
|
209
|
-
*/
|
|
210
|
-
export interface StateProxy<TState, TResult> {
|
|
211
|
-
initState: (config: OperationConfig) => RestorableOperationState<TState>;
|
|
212
|
-
setRunning: (state: TState) => void;
|
|
213
|
-
setCanceled: (state: TState) => void;
|
|
214
|
-
setResult: (state: TState, result: TResult) => void;
|
|
215
|
-
setError: (state: TState, error: Error) => void;
|
|
216
|
-
setFailed: (state: TState) => void;
|
|
217
|
-
setSucceeded: (state: TState) => void;
|
|
218
|
-
isRunning: (state: TState) => boolean;
|
|
219
|
-
isCanceled: (state: TState) => boolean;
|
|
220
|
-
getResult: (state: TState) => TResult | undefined;
|
|
221
|
-
getError: (state: TState) => Error | undefined;
|
|
222
|
-
isFailed: (state: TState) => boolean;
|
|
223
|
-
isSucceeded: (state: TState) => boolean;
|
|
224
|
-
}
|
|
225
201
|
//# sourceMappingURL=models.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../src/poller/models.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,6BAA6B;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,4BAA4B;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../src/poller/models.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,6BAA6B;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,4BAA4B;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,+BAA+B;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,yBAAyB;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mCAAmC;IACnC,QAAQ,CAAC,EAAE,MAAM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;OAEG;IACH,MAAM,EAAE,eAAe,CAAC;IACxB;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,MAAM,SAAS,cAAc,CAAC,OAAO,CAAC,EAAE,OAAO,CACzE,SAAQ,OAAO,CAAC,OAAO,CAAC;IACxB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;IACrC;;;OAGG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACnE;;OAEG;IACH,aAAa,CAAC,WAAW,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACjF;;;;;OAKG;IACH,UAAU,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,gBAAgB,CAAC;IAEhE;;;OAGG;IACH,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAE7B;;OAEG;IACH,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/poller/models.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortSignalLike } from \"@azure/abort-controller\";\n\n/**\n * Configurations for how to poll the operation and to check whether it has\n * terminated.\n */\nexport interface OperationConfig {\n /** The operation location */\n operationLocation?: string;\n /** The resource location */\n resourceLocation?: string;\n /** The initial Url */\n
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/poller/models.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortSignalLike } from \"@azure/abort-controller\";\n\n/**\n * Configurations for how to poll the operation and to check whether it has\n * terminated.\n */\nexport interface OperationConfig {\n /** The operation location */\n operationLocation?: string;\n /** The resource location */\n resourceLocation?: string;\n /** The initial request Url */\n initialRequestUrl?: string;\n /** The request method */\n requestMethod?: string;\n /** metadata about the operation */\n metadata?: Record<string, string>;\n}\n\n/**\n * The description of an operation.\n */\nexport interface Operation<TResponse, TOptions> {\n /**\n * Sends the initiation request and returns, in addition to the response, the\n * operation location, the potential resource location, and a set of metadata.\n */\n init: () => Promise<\n OperationConfig & {\n response: TResponse;\n }\n >;\n /**\n * Sends the polling request.\n */\n poll: (location: string, options?: TOptions) => Promise<TResponse>;\n}\n\n/**\n * Type of a restorable long-running operation.\n */\nexport type RestorableOperationState<TResult, T extends OperationState<TResult>> = T & {\n /** The operation configuration */\n config: OperationConfig;\n};\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreatePollerOptions<TResponse, TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: TResponse, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, lastResponse: TResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n}\n\nexport interface LroError {\n code: string;\n innererror?: InnerError;\n message: string;\n}\n\nexport interface InnerError {\n code: string;\n message: string;\n innererror?: InnerError;\n}\n\n/**\n * Options for `buildCreatePoller`.\n */\nexport interface BuildCreatePollerOptions<\n TResponse,\n TResult,\n TState extends OperationState<TResult>,\n> {\n /**\n * Gets the status of the operation from the response received when the\n * operation was initialized. Note that the operation could be already in\n * a terminal state at this time.\n */\n getStatusFromInitialResponse: (inputs: {\n response: TResponse;\n state: RestorableOperationState<TResult, TState>;\n operationLocation?: string;\n }) => OperationStatus;\n /**\n * Gets the status of the operation from a response received when the\n * operation was polled.\n */\n getStatusFromPollResponse: (\n response: TResponse,\n state: RestorableOperationState<TResult, TState>,\n ) => OperationStatus;\n /**\n * Determines if the input error is an operation error.\n */\n isOperationError: (error: Error) => boolean;\n /**\n * Gets the updated operation location from polling responses.\n */\n getOperationLocation?: (\n response: TResponse,\n state: RestorableOperationState<TResult, TState>,\n ) => string | undefined;\n /**\n * Gets the resource location from a response.\n */\n getResourceLocation: (\n response: TResponse,\n state: RestorableOperationState<TResult, TState>,\n ) => string | undefined;\n /**\n * Gets from the response the time interval the service suggests the client to\n * wait before sending the next polling request.\n */\n getPollingInterval?: (response: TResponse) => number | undefined;\n /**\n * Extracts an error model from a response.\n */\n getError?: (response: TResponse) => LroError | undefined;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful: boolean;\n}\n\n/**\n * The set of possible states an operation can be in at any given time.\n */\nexport type OperationStatus = \"notStarted\" | \"running\" | \"succeeded\" | \"canceled\" | \"failed\";\n\n/**\n * While the poller works as the local control mechanism to start triggering and\n * wait for a long-running operation, OperationState documents the status of\n * the remote long-running operation. It gets updated after each poll.\n */\nexport interface OperationState<TResult> {\n /**\n * The current status of the operation.\n */\n status: OperationStatus;\n /**\n * Will exist if the operation encountered any error.\n */\n error?: Error;\n /**\n * Will exist if the operation produced a result of the expected type.\n */\n result?: TResult;\n}\n\n/**\n * CancelOnProgress is used as the return value of a Poller's onProgress method.\n * When a user invokes onProgress, they're required to pass in a function that will be\n * called as a callback with the new data received each time the poll operation is updated.\n * onProgress returns a function that will prevent any further update to reach the original callback.\n */\nexport type CancelOnProgress = () => void;\n\n/**\n * A poller for an operation.\n */\nexport interface PollerLike<TState extends OperationState<TResult>, TResult>\n extends Promise<TResult> {\n /**\n * Is true if the poller has finished polling.\n */\n readonly isDone: boolean;\n /**\n * The state of the operation.\n * It can be undefined if the poller has not been submitted yet.\n */\n readonly operationState: TState | undefined;\n /**\n * The result value of the operation, regardless of the state of the poller.\n * It can be undefined or an incomplete form of the final TResult value\n * depending on the implementation.\n */\n readonly result: TResult | undefined;\n /**\n * Returns a promise that will resolve once a single polling request finishes.\n * It does this by calling the update method of the Poller's operation.\n */\n poll(options?: { abortSignal?: AbortSignalLike }): Promise<TState>;\n /**\n * Returns a promise that will resolve once the underlying operation is completed.\n */\n pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise<TResult>;\n /**\n * Invokes the provided callback after each polling is completed,\n * sending the current state of the poller's operation.\n *\n * It returns a method that can be used to stop receiving updates on the given callback function.\n */\n onProgress(callback: (state: TState) => void): CancelOnProgress;\n\n /**\n * Returns a promise that could be used for serialized version of the poller's operation\n * by invoking the operation's serialize method.\n */\n serialize(): Promise<string>;\n\n /**\n * Returns a promise that could be used to check if the poller has been submitted.\n */\n submitted(): Promise<void>;\n}\n"]}
|
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
import { LroError, Operation, OperationStatus, RestorableOperationState,
|
|
1
|
+
import { LroError, Operation, OperationStatus, RestorableOperationState, OperationState } from "./models.js";
|
|
2
2
|
/**
|
|
3
3
|
* Deserializes the state
|
|
4
4
|
*/
|
|
5
|
-
export declare function deserializeState<TState
|
|
5
|
+
export declare function deserializeState<TResult, TState extends OperationState<TResult>>(serializedState: string): RestorableOperationState<TResult, TState>;
|
|
6
6
|
/**
|
|
7
7
|
* Initiates the long-running operation.
|
|
8
8
|
*/
|
|
9
|
-
export declare function initOperation<TResponse, TResult, TState
|
|
9
|
+
export declare function initOperation<TResponse, TResult, TState extends OperationState<TResult>>(inputs: {
|
|
10
10
|
init: Operation<TResponse, unknown>["init"];
|
|
11
|
-
stateProxy: StateProxy<TState, TResult>;
|
|
12
11
|
getOperationStatus: (inputs: {
|
|
13
12
|
response: TResponse;
|
|
14
|
-
state: RestorableOperationState<TState>;
|
|
13
|
+
state: RestorableOperationState<TResult, TState>;
|
|
15
14
|
operationLocation?: string;
|
|
16
15
|
}) => OperationStatus;
|
|
17
|
-
processResult?: (result: TResponse, state: TState) =>
|
|
16
|
+
processResult?: (result: TResponse, state: TState) => Promise<TResult>;
|
|
18
17
|
withOperationLocation?: (operationLocation: string, isUpdated: boolean) => void;
|
|
19
18
|
setErrorAsResult: boolean;
|
|
20
|
-
}): Promise<RestorableOperationState<TState>>;
|
|
19
|
+
}): Promise<RestorableOperationState<TResult, TState>>;
|
|
21
20
|
/** Polls the long-running operation. */
|
|
22
|
-
export declare function pollOperation<TResponse,
|
|
21
|
+
export declare function pollOperation<TResponse, TResult, TState extends OperationState<TResult>, TOptions>(inputs: {
|
|
23
22
|
poll: Operation<TResponse, TOptions>["poll"];
|
|
24
|
-
|
|
25
|
-
state: RestorableOperationState<TState
|
|
26
|
-
|
|
27
|
-
getResourceLocation: (response: TResponse, state: RestorableOperationState<TState>) => string | undefined;
|
|
23
|
+
state: RestorableOperationState<TResult, TState>;
|
|
24
|
+
getOperationStatus: (response: TResponse, state: RestorableOperationState<TResult, TState>) => OperationStatus;
|
|
25
|
+
getResourceLocation: (response: TResponse, state: RestorableOperationState<TResult, TState>) => string | undefined;
|
|
28
26
|
isOperationError: (error: Error) => boolean;
|
|
29
27
|
getPollingInterval?: (response: TResponse) => number | undefined;
|
|
30
28
|
setDelay: (intervalInMs: number) => void;
|
|
31
|
-
getOperationLocation?: (response: TResponse, state: RestorableOperationState<TState>) => string | undefined;
|
|
29
|
+
getOperationLocation?: (response: TResponse, state: RestorableOperationState<TResult, TState>) => string | undefined;
|
|
32
30
|
withOperationLocation?: (operationLocation: string, isUpdated: boolean) => void;
|
|
33
|
-
processResult?: (result: TResponse, state: TState) =>
|
|
31
|
+
processResult?: (result: TResponse, state: TState) => Promise<TResult>;
|
|
34
32
|
getError?: (response: TResponse) => LroError | undefined;
|
|
35
33
|
updateState?: (state: TState, lastResponse: TResponse) => void;
|
|
36
34
|
isDone?: (lastResponse: TResponse, state: TState) => boolean;
|