@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
package/src/http/operation.ts
DELETED
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
HttpOperationMode,
|
|
6
|
-
LongRunningOperation,
|
|
7
|
-
ResourceLocationConfig,
|
|
8
|
-
OperationResponse,
|
|
9
|
-
RawResponse,
|
|
10
|
-
ResponseBody,
|
|
11
|
-
} from "./models.js";
|
|
12
|
-
import {
|
|
13
|
-
LroError,
|
|
14
|
-
OperationConfig,
|
|
15
|
-
OperationStatus,
|
|
16
|
-
RestorableOperationState,
|
|
17
|
-
StateProxy,
|
|
18
|
-
} from "../poller/models.js";
|
|
19
|
-
import { pollOperation } from "../poller/operation.js";
|
|
20
|
-
import { AbortSignalLike } from "@azure/abort-controller";
|
|
21
|
-
import { logger } from "../logger.js";
|
|
22
|
-
|
|
23
|
-
function getOperationLocationPollingUrl(inputs: {
|
|
24
|
-
operationLocation?: string;
|
|
25
|
-
azureAsyncOperation?: string;
|
|
26
|
-
}): string | undefined {
|
|
27
|
-
const { azureAsyncOperation, operationLocation } = inputs;
|
|
28
|
-
return operationLocation ?? azureAsyncOperation;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function getLocationHeader(rawResponse: RawResponse): string | undefined {
|
|
32
|
-
return rawResponse.headers["location"];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function getOperationLocationHeader(rawResponse: RawResponse): string | undefined {
|
|
36
|
-
return rawResponse.headers["operation-location"];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function getAzureAsyncOperationHeader(rawResponse: RawResponse): string | undefined {
|
|
40
|
-
return rawResponse.headers["azure-asyncoperation"];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function findResourceLocation(inputs: {
|
|
44
|
-
requestMethod?: string;
|
|
45
|
-
location?: string;
|
|
46
|
-
requestPath?: string;
|
|
47
|
-
resourceLocationConfig?: ResourceLocationConfig;
|
|
48
|
-
}): string | undefined {
|
|
49
|
-
const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;
|
|
50
|
-
switch (requestMethod) {
|
|
51
|
-
case "PUT": {
|
|
52
|
-
return requestPath;
|
|
53
|
-
}
|
|
54
|
-
case "DELETE": {
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
case "PATCH": {
|
|
58
|
-
return getDefault() ?? requestPath;
|
|
59
|
-
}
|
|
60
|
-
default: {
|
|
61
|
-
return getDefault();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function getDefault() {
|
|
66
|
-
switch (resourceLocationConfig) {
|
|
67
|
-
case "azure-async-operation": {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
case "original-uri": {
|
|
71
|
-
return requestPath;
|
|
72
|
-
}
|
|
73
|
-
case "location":
|
|
74
|
-
default: {
|
|
75
|
-
return location;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function inferLroMode(
|
|
82
|
-
rawResponse: RawResponse,
|
|
83
|
-
resourceLocationConfig?: ResourceLocationConfig,
|
|
84
|
-
): (OperationConfig & { mode: HttpOperationMode }) | undefined {
|
|
85
|
-
const requestPath = rawResponse.request.url;
|
|
86
|
-
const requestMethod = rawResponse.request.method;
|
|
87
|
-
const operationLocation = getOperationLocationHeader(rawResponse);
|
|
88
|
-
const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);
|
|
89
|
-
const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });
|
|
90
|
-
const location = getLocationHeader(rawResponse);
|
|
91
|
-
const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();
|
|
92
|
-
if (pollingUrl !== undefined) {
|
|
93
|
-
return {
|
|
94
|
-
mode: "OperationLocation",
|
|
95
|
-
operationLocation: pollingUrl,
|
|
96
|
-
resourceLocation: findResourceLocation({
|
|
97
|
-
requestMethod: normalizedRequestMethod,
|
|
98
|
-
location,
|
|
99
|
-
requestPath,
|
|
100
|
-
resourceLocationConfig,
|
|
101
|
-
}),
|
|
102
|
-
initialUrl: requestPath,
|
|
103
|
-
requestMethod,
|
|
104
|
-
};
|
|
105
|
-
} else if (location !== undefined) {
|
|
106
|
-
return {
|
|
107
|
-
mode: "ResourceLocation",
|
|
108
|
-
operationLocation: location,
|
|
109
|
-
initialUrl: requestPath,
|
|
110
|
-
requestMethod,
|
|
111
|
-
};
|
|
112
|
-
} else if (normalizedRequestMethod === "PUT" && requestPath) {
|
|
113
|
-
return {
|
|
114
|
-
mode: "Body",
|
|
115
|
-
operationLocation: requestPath,
|
|
116
|
-
initialUrl: requestPath,
|
|
117
|
-
requestMethod,
|
|
118
|
-
};
|
|
119
|
-
} else {
|
|
120
|
-
return undefined;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function transformStatus(inputs: { status: unknown; statusCode: number }): OperationStatus {
|
|
125
|
-
const { status, statusCode } = inputs;
|
|
126
|
-
if (typeof status !== "string" && status !== undefined) {
|
|
127
|
-
throw new Error(
|
|
128
|
-
`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.`,
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
switch (status?.toLocaleLowerCase()) {
|
|
132
|
-
case undefined:
|
|
133
|
-
return toOperationStatus(statusCode);
|
|
134
|
-
case "succeeded":
|
|
135
|
-
return "succeeded";
|
|
136
|
-
case "failed":
|
|
137
|
-
return "failed";
|
|
138
|
-
case "running":
|
|
139
|
-
case "accepted":
|
|
140
|
-
case "started":
|
|
141
|
-
case "canceling":
|
|
142
|
-
case "cancelling":
|
|
143
|
-
return "running";
|
|
144
|
-
case "canceled":
|
|
145
|
-
case "cancelled":
|
|
146
|
-
return "canceled";
|
|
147
|
-
default: {
|
|
148
|
-
logger.verbose(`LRO: unrecognized operation status: ${status}`);
|
|
149
|
-
return status as OperationStatus;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function getStatus(rawResponse: RawResponse): OperationStatus {
|
|
155
|
-
const { status } = (rawResponse.body as ResponseBody) ?? {};
|
|
156
|
-
return transformStatus({ status, statusCode: rawResponse.statusCode });
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function getProvisioningState(rawResponse: RawResponse): OperationStatus {
|
|
160
|
-
const { properties, provisioningState } = (rawResponse.body as ResponseBody) ?? {};
|
|
161
|
-
const status = properties?.provisioningState ?? provisioningState;
|
|
162
|
-
return transformStatus({ status, statusCode: rawResponse.statusCode });
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function toOperationStatus(statusCode: number): OperationStatus {
|
|
166
|
-
if (statusCode === 202) {
|
|
167
|
-
return "running";
|
|
168
|
-
} else if (statusCode < 300) {
|
|
169
|
-
return "succeeded";
|
|
170
|
-
} else {
|
|
171
|
-
return "failed";
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export function parseRetryAfter<T>({ rawResponse }: OperationResponse<T>): number | undefined {
|
|
176
|
-
const retryAfter: string | undefined = rawResponse.headers["retry-after"];
|
|
177
|
-
if (retryAfter !== undefined) {
|
|
178
|
-
// Retry-After header value is either in HTTP date format, or in seconds
|
|
179
|
-
const retryAfterInSeconds = parseInt(retryAfter);
|
|
180
|
-
return isNaN(retryAfterInSeconds)
|
|
181
|
-
? calculatePollingIntervalFromDate(new Date(retryAfter))
|
|
182
|
-
: retryAfterInSeconds * 1000;
|
|
183
|
-
}
|
|
184
|
-
return undefined;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export function getErrorFromResponse<T>(response: OperationResponse<T>): LroError | undefined {
|
|
188
|
-
const error = accessBodyProperty(response, "error");
|
|
189
|
-
if (!error) {
|
|
190
|
-
logger.warning(
|
|
191
|
-
`The long-running operation failed but there is no error property in the response's body`,
|
|
192
|
-
);
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
if (!error.code || !error.message) {
|
|
196
|
-
logger.warning(
|
|
197
|
-
`The long-running operation failed but the error property in the response's body doesn't contain code or message`,
|
|
198
|
-
);
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
return error as LroError;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function calculatePollingIntervalFromDate(retryAfterDate: Date): number | undefined {
|
|
205
|
-
const timeNow = Math.floor(new Date().getTime());
|
|
206
|
-
const retryAfterTime = retryAfterDate.getTime();
|
|
207
|
-
if (timeNow < retryAfterTime) {
|
|
208
|
-
return retryAfterTime - timeNow;
|
|
209
|
-
}
|
|
210
|
-
return undefined;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export function getStatusFromInitialResponse<TState>(inputs: {
|
|
214
|
-
response: OperationResponse<unknown>;
|
|
215
|
-
state: RestorableOperationState<TState>;
|
|
216
|
-
operationLocation?: string;
|
|
217
|
-
}): OperationStatus {
|
|
218
|
-
const { response, state, operationLocation } = inputs;
|
|
219
|
-
function helper(): OperationStatus {
|
|
220
|
-
const mode = state.config.metadata?.["mode"];
|
|
221
|
-
switch (mode) {
|
|
222
|
-
case undefined:
|
|
223
|
-
return toOperationStatus(response.rawResponse.statusCode);
|
|
224
|
-
case "Body":
|
|
225
|
-
return getOperationStatus(response, state);
|
|
226
|
-
default:
|
|
227
|
-
return "running";
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
const status = helper();
|
|
231
|
-
return status === "running" && operationLocation === undefined ? "succeeded" : status;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export function getOperationLocation<TState>(
|
|
235
|
-
{ rawResponse }: OperationResponse,
|
|
236
|
-
state: RestorableOperationState<TState>,
|
|
237
|
-
): string | undefined {
|
|
238
|
-
const mode = state.config.metadata?.["mode"];
|
|
239
|
-
switch (mode) {
|
|
240
|
-
case "OperationLocation": {
|
|
241
|
-
return getOperationLocationPollingUrl({
|
|
242
|
-
operationLocation: getOperationLocationHeader(rawResponse),
|
|
243
|
-
azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
case "ResourceLocation": {
|
|
247
|
-
return getLocationHeader(rawResponse);
|
|
248
|
-
}
|
|
249
|
-
case "Body":
|
|
250
|
-
default: {
|
|
251
|
-
return undefined;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export function getOperationStatus<TState>(
|
|
257
|
-
{ rawResponse }: OperationResponse,
|
|
258
|
-
state: RestorableOperationState<TState>,
|
|
259
|
-
): OperationStatus {
|
|
260
|
-
const mode = state.config.metadata?.["mode"];
|
|
261
|
-
switch (mode) {
|
|
262
|
-
case "OperationLocation": {
|
|
263
|
-
return getStatus(rawResponse);
|
|
264
|
-
}
|
|
265
|
-
case "ResourceLocation": {
|
|
266
|
-
return toOperationStatus(rawResponse.statusCode);
|
|
267
|
-
}
|
|
268
|
-
case "Body": {
|
|
269
|
-
return getProvisioningState(rawResponse);
|
|
270
|
-
}
|
|
271
|
-
default:
|
|
272
|
-
throw new Error(`Internal error: Unexpected operation mode: ${mode}`);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
function accessBodyProperty<P extends string>(
|
|
277
|
-
{ flatResponse, rawResponse }: OperationResponse,
|
|
278
|
-
prop: P,
|
|
279
|
-
): ResponseBody[P] {
|
|
280
|
-
return (flatResponse as ResponseBody)?.[prop] ?? (rawResponse.body as ResponseBody)?.[prop];
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export function getResourceLocation<TState>(
|
|
284
|
-
res: OperationResponse,
|
|
285
|
-
state: RestorableOperationState<TState>,
|
|
286
|
-
): string | undefined {
|
|
287
|
-
const loc = accessBodyProperty(res, "resourceLocation");
|
|
288
|
-
if (loc && typeof loc === "string") {
|
|
289
|
-
state.config.resourceLocation = loc;
|
|
290
|
-
}
|
|
291
|
-
return state.config.resourceLocation;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export function isOperationError(e: Error): boolean {
|
|
295
|
-
return e.name === "RestError";
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/** Polls the long-running operation. */
|
|
299
|
-
export async function pollHttpOperation<TState, TResult>(inputs: {
|
|
300
|
-
lro: LongRunningOperation;
|
|
301
|
-
stateProxy: StateProxy<TState, TResult>;
|
|
302
|
-
processResult?: (result: unknown, state: TState) => TResult;
|
|
303
|
-
updateState?: (state: TState, lastResponse: OperationResponse) => void;
|
|
304
|
-
isDone?: (lastResponse: OperationResponse, state: TState) => boolean;
|
|
305
|
-
setDelay: (intervalInMs: number) => void;
|
|
306
|
-
options?: { abortSignal?: AbortSignalLike };
|
|
307
|
-
state: RestorableOperationState<TState>;
|
|
308
|
-
setErrorAsResult: boolean;
|
|
309
|
-
}): Promise<void> {
|
|
310
|
-
const {
|
|
311
|
-
lro,
|
|
312
|
-
stateProxy,
|
|
313
|
-
options,
|
|
314
|
-
processResult,
|
|
315
|
-
updateState,
|
|
316
|
-
setDelay,
|
|
317
|
-
state,
|
|
318
|
-
setErrorAsResult,
|
|
319
|
-
} = inputs;
|
|
320
|
-
return pollOperation({
|
|
321
|
-
state,
|
|
322
|
-
stateProxy,
|
|
323
|
-
setDelay,
|
|
324
|
-
processResult: processResult
|
|
325
|
-
? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)
|
|
326
|
-
: ({ flatResponse }) => flatResponse as TResult,
|
|
327
|
-
getError: getErrorFromResponse,
|
|
328
|
-
updateState,
|
|
329
|
-
getPollingInterval: parseRetryAfter,
|
|
330
|
-
getOperationLocation,
|
|
331
|
-
getOperationStatus,
|
|
332
|
-
isOperationError,
|
|
333
|
-
getResourceLocation,
|
|
334
|
-
options,
|
|
335
|
-
/**
|
|
336
|
-
* The expansion here is intentional because `lro` could be an object that
|
|
337
|
-
* references an inner this, so we need to preserve a reference to it.
|
|
338
|
-
*/
|
|
339
|
-
poll: async (location: string, inputOptions?: { abortSignal?: AbortSignalLike }) =>
|
|
340
|
-
lro.sendPollRequest(location, inputOptions),
|
|
341
|
-
setErrorAsResult,
|
|
342
|
-
});
|
|
343
|
-
}
|
package/src/http/poller.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
|
|
4
|
-
// Copyright (c) Microsoft Corporation.
|
|
5
|
-
// Licensed under the MIT license.
|
|
6
|
-
|
|
7
|
-
import { LongRunningOperation, OperationResponse } from "./models.js";
|
|
8
|
-
import { OperationState, PollerLike } from "../poller/models.js";
|
|
9
|
-
import {
|
|
10
|
-
getErrorFromResponse,
|
|
11
|
-
getOperationLocation,
|
|
12
|
-
getOperationStatus,
|
|
13
|
-
getResourceLocation,
|
|
14
|
-
getStatusFromInitialResponse,
|
|
15
|
-
inferLroMode,
|
|
16
|
-
isOperationError,
|
|
17
|
-
parseRetryAfter,
|
|
18
|
-
} from "./operation.js";
|
|
19
|
-
import { CreateHttpPollerOptions } from "./models.js";
|
|
20
|
-
import { buildCreatePoller } from "../poller/poller.js";
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Creates a poller that can be used to poll a long-running operation.
|
|
24
|
-
* @param lro - Description of the long-running operation
|
|
25
|
-
* @param options - options to configure the poller
|
|
26
|
-
* @returns an initialized poller
|
|
27
|
-
*/
|
|
28
|
-
export function createHttpPoller<TResult, TState extends OperationState<TResult>>(
|
|
29
|
-
lro: LongRunningOperation,
|
|
30
|
-
options?: CreateHttpPollerOptions<TResult, TState>,
|
|
31
|
-
): PollerLike<TState, TResult> {
|
|
32
|
-
const {
|
|
33
|
-
resourceLocationConfig,
|
|
34
|
-
intervalInMs,
|
|
35
|
-
processResult,
|
|
36
|
-
restoreFrom,
|
|
37
|
-
updateState,
|
|
38
|
-
withOperationLocation,
|
|
39
|
-
resolveOnUnsuccessful = false,
|
|
40
|
-
} = options || {};
|
|
41
|
-
return buildCreatePoller<OperationResponse, TResult, TState>({
|
|
42
|
-
getStatusFromInitialResponse,
|
|
43
|
-
getStatusFromPollResponse: getOperationStatus,
|
|
44
|
-
isOperationError,
|
|
45
|
-
getOperationLocation,
|
|
46
|
-
getResourceLocation,
|
|
47
|
-
getPollingInterval: parseRetryAfter,
|
|
48
|
-
getError: getErrorFromResponse,
|
|
49
|
-
resolveOnUnsuccessful,
|
|
50
|
-
})(
|
|
51
|
-
{
|
|
52
|
-
init: async () => {
|
|
53
|
-
const response = await lro.sendInitialRequest();
|
|
54
|
-
const config = inferLroMode(response.rawResponse, resourceLocationConfig);
|
|
55
|
-
const metadata: Record<string, string> = {};
|
|
56
|
-
if (config?.mode) {
|
|
57
|
-
metadata["mode"] = config.mode;
|
|
58
|
-
}
|
|
59
|
-
if (resourceLocationConfig) {
|
|
60
|
-
metadata["resourceLocationConfig"] = resourceLocationConfig;
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
response,
|
|
64
|
-
operationLocation: config?.operationLocation,
|
|
65
|
-
resourceLocation: config?.resourceLocation,
|
|
66
|
-
initialUrl: config?.initialUrl,
|
|
67
|
-
requestMethod: config?.requestMethod,
|
|
68
|
-
metadata,
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
poll: lro.sendPollRequest,
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
intervalInMs,
|
|
75
|
-
withOperationLocation,
|
|
76
|
-
restoreFrom,
|
|
77
|
-
updateState,
|
|
78
|
-
processResult: processResult
|
|
79
|
-
? ({ flatResponse }, state) => processResult(flatResponse, state)
|
|
80
|
-
: ({ flatResponse }) => flatResponse as TResult,
|
|
81
|
-
},
|
|
82
|
-
);
|
|
83
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
|
|
4
|
-
export { createHttpPoller } from "./http/poller.js";
|
|
5
|
-
export {
|
|
6
|
-
CancelOnProgress,
|
|
7
|
-
OperationState,
|
|
8
|
-
OperationStatus,
|
|
9
|
-
PollerLike,
|
|
10
|
-
RestorableOperationState,
|
|
11
|
-
OperationConfig,
|
|
12
|
-
} from "./poller/models.js";
|
|
13
|
-
export {
|
|
14
|
-
ResourceLocationConfig,
|
|
15
|
-
LongRunningOperation,
|
|
16
|
-
OperationResponse,
|
|
17
|
-
RawResponse,
|
|
18
|
-
RawRequest,
|
|
19
|
-
CreateHttpPollerOptions,
|
|
20
|
-
} from "./http/models.js";
|
|
21
|
-
export { deserializeState } from "./poller/operation.js";
|
package/src/logger.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
|
|
4
|
-
import { createClientLogger } from "@azure/logger";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The `@azure/logger` configuration for this package.
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export const logger = createClientLogger("core-lro");
|
package/src/poller/constants.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The default time interval to wait before sending the next polling request.
|
|
6
|
-
*/
|
|
7
|
-
export const POLL_INTERVAL_IN_MS = 2000;
|
|
8
|
-
/**
|
|
9
|
-
* The closed set of terminal states.
|
|
10
|
-
*/
|
|
11
|
-
export const terminalStates = ["succeeded", "canceled", "failed"];
|