@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/test/matrix.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Takes a jagged 2D array and a function and runs the function with every
|
|
6
|
-
* possible combination of elements of each of the arrays
|
|
7
|
-
*
|
|
8
|
-
* For strong type-checking, it is important that the `matrix` have a strong
|
|
9
|
-
* type, such as a `const` literal.
|
|
10
|
-
*
|
|
11
|
-
* @param values - jagged 2D array specifying the arguments and their possible
|
|
12
|
-
* values
|
|
13
|
-
* @param handler - the function to run with the different argument combinations
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* matrix([
|
|
18
|
-
* [true, false],
|
|
19
|
-
* [1, 2, 3]
|
|
20
|
-
* ] as const,
|
|
21
|
-
* (useLabels: boolean, attempts: number) => {
|
|
22
|
-
* // This body will run six times with the following parameters:
|
|
23
|
-
* // - true, 1
|
|
24
|
-
* // - true, 2
|
|
25
|
-
* // - true, 3
|
|
26
|
-
* // - false, 1
|
|
27
|
-
* // - false, 2
|
|
28
|
-
* // - false, 3
|
|
29
|
-
* });
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export function matrix<T extends ReadonlyArray<readonly unknown[]>>(
|
|
33
|
-
values: T,
|
|
34
|
-
handler: (
|
|
35
|
-
...args: { [idx in keyof T]: T[idx] extends ReadonlyArray<infer U> ? U : never }
|
|
36
|
-
) => Promise<void>,
|
|
37
|
-
): void {
|
|
38
|
-
// Classic recursive approach
|
|
39
|
-
if (values.length === 0) {
|
|
40
|
-
(handler as () => Promise<void>)();
|
|
41
|
-
} else {
|
|
42
|
-
for (const v of values[0]) {
|
|
43
|
-
matrix(values.slice(1), (...args) => (handler as any)(v, ...args));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
|
|
4
|
-
import { LongRunningOperation, OperationResponse } from "../../src/index.js";
|
|
5
|
-
import { AbortSignalLike } from "@azure/abort-controller";
|
|
6
|
-
import { PipelineRequest } from "@azure/core-rest-pipeline";
|
|
7
|
-
|
|
8
|
-
type SendOperationFn<T> = (request: PipelineRequest) => Promise<OperationResponse<T>>;
|
|
9
|
-
|
|
10
|
-
export function createCoreRestPipelineLro<T>(inputs: {
|
|
11
|
-
sendOperationFn: SendOperationFn<T>;
|
|
12
|
-
request: PipelineRequest;
|
|
13
|
-
}): LongRunningOperation<T> {
|
|
14
|
-
const { request, sendOperationFn } = inputs;
|
|
15
|
-
return {
|
|
16
|
-
sendInitialRequest: () => sendOperationFn(request),
|
|
17
|
-
sendPollRequest: (url: string, options?: { abortSignal?: AbortSignalLike }) =>
|
|
18
|
-
sendOperationFn({
|
|
19
|
-
...request,
|
|
20
|
-
method: "GET",
|
|
21
|
-
url,
|
|
22
|
-
abortSignal: options?.abortSignal,
|
|
23
|
-
}),
|
|
24
|
-
};
|
|
25
|
-
}
|
package/test/utils/router.ts
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
HttpClient,
|
|
6
|
-
HttpMethods,
|
|
7
|
-
PipelineRequest,
|
|
8
|
-
PipelineResponse,
|
|
9
|
-
RestError,
|
|
10
|
-
createHttpHeaders,
|
|
11
|
-
} from "@azure/core-rest-pipeline";
|
|
12
|
-
import {
|
|
13
|
-
ImplementationName,
|
|
14
|
-
LroResponseSpec,
|
|
15
|
-
Result,
|
|
16
|
-
RouteProcessor,
|
|
17
|
-
State,
|
|
18
|
-
createProcessor,
|
|
19
|
-
generate,
|
|
20
|
-
} from "./utils.js";
|
|
21
|
-
import { PollerLike, createHttpPoller } from "../../src/index.js";
|
|
22
|
-
import {
|
|
23
|
-
OperationResponse,
|
|
24
|
-
RawResponse,
|
|
25
|
-
ResourceLocationConfig,
|
|
26
|
-
ResponseBody,
|
|
27
|
-
} from "../../src/http/models.js";
|
|
28
|
-
import { AbortError } from "@azure/abort-controller";
|
|
29
|
-
import { createCoreRestPipelineLro } from "./coreRestPipelineLro.js";
|
|
30
|
-
import { getYieldedValue } from "../getYieldedValue.js";
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Dummy value for the path of the initial request
|
|
34
|
-
*/
|
|
35
|
-
const initialPath = "path";
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* This helper creates an array of route processors where each processor is represented
|
|
39
|
-
* as a generator. This generator representation is needed to handle a sequence of GET
|
|
40
|
-
* requests to the same route. In particular, the first GET request may get
|
|
41
|
-
* a response indicating that the LRO is still in progress but a subsequent
|
|
42
|
-
* GET request may get a response indicating the LRO is in a terminal state.
|
|
43
|
-
*/
|
|
44
|
-
export function toLroProcessors(responses: LroResponseSpec[]): RouteProcessor[] {
|
|
45
|
-
const routeCountMap = new Map<
|
|
46
|
-
string,
|
|
47
|
-
{
|
|
48
|
-
method: HttpMethods;
|
|
49
|
-
path: string;
|
|
50
|
-
responseProcessors: ((req: PipelineRequest) => PipelineResponse)[];
|
|
51
|
-
}
|
|
52
|
-
>();
|
|
53
|
-
for (const response of responses) {
|
|
54
|
-
const { method, path = initialPath, status, body, headers } = response;
|
|
55
|
-
const key = createRouteKey({ method, path });
|
|
56
|
-
const routeProcessor = routeCountMap.get(key);
|
|
57
|
-
if (routeProcessor !== undefined) {
|
|
58
|
-
routeProcessor.responseProcessors.push(createProcessor({ status, body, headers }));
|
|
59
|
-
} else {
|
|
60
|
-
routeCountMap.set(key, {
|
|
61
|
-
method,
|
|
62
|
-
path,
|
|
63
|
-
responseProcessors: [createProcessor({ status, body, headers })],
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return [...routeCountMap.values()].map(({ responseProcessors, ...rest }) => ({
|
|
68
|
-
process: generate(...responseProcessors),
|
|
69
|
-
...rest,
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function createRouteKey({ method, path }: { path: string; method: string }): string {
|
|
74
|
-
return method + ":" + path;
|
|
75
|
-
}
|
|
76
|
-
export function createClient(inputs: {
|
|
77
|
-
routes: RouteProcessor[];
|
|
78
|
-
throwOnNon2xxResponse?: boolean;
|
|
79
|
-
}): HttpClient {
|
|
80
|
-
const { routes, throwOnNon2xxResponse = true } = inputs;
|
|
81
|
-
const routesTable = new Map(routes.map((route) => [createRouteKey(route), route]));
|
|
82
|
-
return {
|
|
83
|
-
async sendRequest(request: PipelineRequest): Promise<PipelineResponse> {
|
|
84
|
-
if (request.abortSignal?.aborted) {
|
|
85
|
-
throw new AbortError("The operation was aborted.");
|
|
86
|
-
}
|
|
87
|
-
const path = request.url;
|
|
88
|
-
const method = request.method;
|
|
89
|
-
const route = routesTable.get(createRouteKey({ method, path }));
|
|
90
|
-
if (route !== undefined) {
|
|
91
|
-
const response = getYieldedValue(route.process.next())(request);
|
|
92
|
-
if (response.status >= 400 && throwOnNon2xxResponse) {
|
|
93
|
-
throw new RestError(
|
|
94
|
-
`Received unexpected HTTP status code ${response.status} while polling. This may indicate a server issue.`,
|
|
95
|
-
{ statusCode: response.status },
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
return response;
|
|
99
|
-
}
|
|
100
|
-
const message = `Route for ${method} request to ${path} was not found`;
|
|
101
|
-
if (throwOnNon2xxResponse) {
|
|
102
|
-
throw new RestError(message, {
|
|
103
|
-
statusCode: 404,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
bodyAsText: JSON.stringify({ message }),
|
|
108
|
-
status: 404,
|
|
109
|
-
request,
|
|
110
|
-
headers: createHttpHeaders(),
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function createSendOp(settings: {
|
|
117
|
-
client: HttpClient;
|
|
118
|
-
}): (request: PipelineRequest) => Promise<OperationResponse<Result>> {
|
|
119
|
-
const { client } = settings;
|
|
120
|
-
return async function (request: PipelineRequest): Promise<OperationResponse<Result>> {
|
|
121
|
-
const response = await client.sendRequest(request);
|
|
122
|
-
const parsedBody: ResponseBody = response.bodyAsText
|
|
123
|
-
? JSON.parse(response.bodyAsText)
|
|
124
|
-
: response.bodyAsText;
|
|
125
|
-
const headers = response.headers.toJSON();
|
|
126
|
-
return {
|
|
127
|
-
flatResponse: { ...parsedBody, ...headers, statusCode: response.status },
|
|
128
|
-
rawResponse: {
|
|
129
|
-
headers: headers,
|
|
130
|
-
statusCode: response.status,
|
|
131
|
-
body: parsedBody,
|
|
132
|
-
request,
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function createTestPoller(settings: {
|
|
139
|
-
routes: LroResponseSpec[];
|
|
140
|
-
resourceLocationConfig?: ResourceLocationConfig;
|
|
141
|
-
processResult?: (result: unknown, state: State) => Promise<Result> | Result;
|
|
142
|
-
updateState?: (state: State, lastResponse: OperationResponse<Result>) => void;
|
|
143
|
-
implName?: ImplementationName;
|
|
144
|
-
throwOnNon2xxResponse?: boolean;
|
|
145
|
-
restoreFrom?: string;
|
|
146
|
-
}): PollerLike<State, Result> {
|
|
147
|
-
const {
|
|
148
|
-
routes,
|
|
149
|
-
resourceLocationConfig,
|
|
150
|
-
processResult,
|
|
151
|
-
updateState,
|
|
152
|
-
implName = "createPoller",
|
|
153
|
-
throwOnNon2xxResponse = true,
|
|
154
|
-
restoreFrom = undefined,
|
|
155
|
-
} = settings;
|
|
156
|
-
const client = createClient({ routes: toLroProcessors(routes), throwOnNon2xxResponse });
|
|
157
|
-
const { method: requestMethod, path = initialPath } = restoreFrom
|
|
158
|
-
? { method: "GET" as HttpMethods, path: "FAKE" }
|
|
159
|
-
: routes[0];
|
|
160
|
-
const lro = createCoreRestPipelineLro({
|
|
161
|
-
sendOperationFn: createSendOp({ client }),
|
|
162
|
-
request: {
|
|
163
|
-
method: requestMethod,
|
|
164
|
-
url: path,
|
|
165
|
-
headers: createHttpHeaders(),
|
|
166
|
-
requestId: "",
|
|
167
|
-
timeout: 0,
|
|
168
|
-
withCredentials: false,
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
switch (implName) {
|
|
172
|
-
case "createPoller": {
|
|
173
|
-
return createHttpPoller(lro, {
|
|
174
|
-
intervalInMs: 0,
|
|
175
|
-
resourceLocationConfig: resourceLocationConfig,
|
|
176
|
-
processResult,
|
|
177
|
-
updateState: updateState as
|
|
178
|
-
| ((state: any, lastResponse: OperationResponse<unknown>) => void)
|
|
179
|
-
| undefined,
|
|
180
|
-
resolveOnUnsuccessful: !throwOnNon2xxResponse,
|
|
181
|
-
restoreFrom,
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
default: {
|
|
185
|
-
throw new Error("Unreachable");
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
async function runLro<TState>(settings: {
|
|
191
|
-
routes: LroResponseSpec[];
|
|
192
|
-
onProgress?: (state: TState) => void;
|
|
193
|
-
resourceLocationConfig?: ResourceLocationConfig;
|
|
194
|
-
processResult?: (result: unknown, state: TState) => Promise<Result> | Result;
|
|
195
|
-
updateState?: (state: TState, lastResponse: RawResponse) => void;
|
|
196
|
-
implName?: ImplementationName;
|
|
197
|
-
throwOnNon2xxResponse?: boolean;
|
|
198
|
-
}): Promise<Result> {
|
|
199
|
-
const {
|
|
200
|
-
routes,
|
|
201
|
-
onProgress,
|
|
202
|
-
resourceLocationConfig,
|
|
203
|
-
processResult,
|
|
204
|
-
updateState,
|
|
205
|
-
implName = "createPoller",
|
|
206
|
-
throwOnNon2xxResponse = true,
|
|
207
|
-
} = settings;
|
|
208
|
-
const poller = createTestPoller({
|
|
209
|
-
routes,
|
|
210
|
-
resourceLocationConfig,
|
|
211
|
-
processResult,
|
|
212
|
-
updateState: (state, { rawResponse }) => updateState?.(state, rawResponse),
|
|
213
|
-
implName,
|
|
214
|
-
throwOnNon2xxResponse,
|
|
215
|
-
});
|
|
216
|
-
if (onProgress !== undefined) {
|
|
217
|
-
poller.onProgress(onProgress);
|
|
218
|
-
}
|
|
219
|
-
return poller.pollUntilDone();
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export const createRunLroWith =
|
|
223
|
-
<TState>(variables: { implName: ImplementationName; throwOnNon2xxResponse?: boolean }) =>
|
|
224
|
-
(settings: {
|
|
225
|
-
routes: LroResponseSpec[];
|
|
226
|
-
onProgress?: (state: TState) => void;
|
|
227
|
-
resourceLocationConfig?: ResourceLocationConfig;
|
|
228
|
-
processResult?: (result: unknown, state: TState) => Result | Promise<Result>;
|
|
229
|
-
updateState?: (state: TState, lastResponse: RawResponse) => void;
|
|
230
|
-
}): Promise<Result> =>
|
|
231
|
-
runLro({ ...settings, ...variables });
|
package/test/utils/utils.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
HttpMethods,
|
|
6
|
-
PipelineRequest,
|
|
7
|
-
PipelineResponse,
|
|
8
|
-
createHttpHeaders,
|
|
9
|
-
isRestError,
|
|
10
|
-
} from "@azure/core-rest-pipeline";
|
|
11
|
-
import { ResponseBody } from "../../src/http/models.js";
|
|
12
|
-
import { assert } from "vitest";
|
|
13
|
-
|
|
14
|
-
export interface RouteProcessor {
|
|
15
|
-
method: string;
|
|
16
|
-
path: string;
|
|
17
|
-
process: Generator<(request: PipelineRequest) => PipelineResponse>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface LroResponseSpec {
|
|
21
|
-
method: HttpMethods;
|
|
22
|
-
path?: string;
|
|
23
|
-
status: number;
|
|
24
|
-
body?: string;
|
|
25
|
-
headers?: Record<string, string>;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type ImplementationName = "createPoller";
|
|
29
|
-
|
|
30
|
-
export type Result = ResponseBody & { statusCode: number };
|
|
31
|
-
export type State = any;
|
|
32
|
-
|
|
33
|
-
export function createProcessor(settings: {
|
|
34
|
-
status: number;
|
|
35
|
-
body?: string;
|
|
36
|
-
headers?: Record<string, string>;
|
|
37
|
-
}): (req: PipelineRequest) => PipelineResponse {
|
|
38
|
-
const { status, body: bodyAsText, headers } = settings;
|
|
39
|
-
return (request: PipelineRequest) => ({
|
|
40
|
-
request,
|
|
41
|
-
headers: createHttpHeaders(headers),
|
|
42
|
-
status,
|
|
43
|
-
bodyAsText,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function createDoubleHeaders(settings: {
|
|
48
|
-
pollingPath: string;
|
|
49
|
-
headers: Record<string, string>;
|
|
50
|
-
}): Record<string, string> {
|
|
51
|
-
const { headers, pollingPath } = settings;
|
|
52
|
-
return {
|
|
53
|
-
"Azure-AsyncOperation": pollingPath,
|
|
54
|
-
Location: pollingPath,
|
|
55
|
-
...headers,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function* generate<T>(...input: T[]): Generator<T> {
|
|
60
|
-
for (const item of input) {
|
|
61
|
-
yield item;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export async function assertError(
|
|
66
|
-
error: Promise<unknown>,
|
|
67
|
-
options: {
|
|
68
|
-
statusCode?: number;
|
|
69
|
-
messagePattern?: RegExp;
|
|
70
|
-
name?: string;
|
|
71
|
-
} = {},
|
|
72
|
-
): Promise<void> {
|
|
73
|
-
const { statusCode, messagePattern, name } = options;
|
|
74
|
-
try {
|
|
75
|
-
await error;
|
|
76
|
-
assert.fail(`Should have failed instead!`);
|
|
77
|
-
} catch (e: unknown) {
|
|
78
|
-
if (messagePattern) {
|
|
79
|
-
if (e instanceof Error) {
|
|
80
|
-
assert.match(e.message, messagePattern);
|
|
81
|
-
} else {
|
|
82
|
-
assert.fail(`Unexpected error: ${JSON.stringify(e)}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (statusCode) {
|
|
86
|
-
if (isRestError(e)) {
|
|
87
|
-
assert.equal(e.statusCode, statusCode);
|
|
88
|
-
} else {
|
|
89
|
-
assert.fail(`Unexpected error: ${JSON.stringify(e)}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (name) {
|
|
93
|
-
if (e instanceof Error) {
|
|
94
|
-
assert.equal(e.name, name);
|
|
95
|
-
} else {
|
|
96
|
-
assert.fail(`Unexpected error: ${JSON.stringify(e)}`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export async function assertDivergentBehavior(inputs: {
|
|
103
|
-
op: Promise<Result>;
|
|
104
|
-
throwOnNon2xxResponse: boolean;
|
|
105
|
-
throwing: {
|
|
106
|
-
statusCode?: number;
|
|
107
|
-
messagePattern?: RegExp;
|
|
108
|
-
};
|
|
109
|
-
notThrowing: {
|
|
110
|
-
result?: any;
|
|
111
|
-
partResult?: any;
|
|
112
|
-
statusCode?: number;
|
|
113
|
-
messagePattern?: RegExp;
|
|
114
|
-
};
|
|
115
|
-
}): Promise<void> {
|
|
116
|
-
const {
|
|
117
|
-
op,
|
|
118
|
-
throwOnNon2xxResponse,
|
|
119
|
-
throwing: { messagePattern, statusCode },
|
|
120
|
-
notThrowing: {
|
|
121
|
-
messagePattern: notThrowingMessagePattern,
|
|
122
|
-
statusCode: notThrowingStatusCode,
|
|
123
|
-
result,
|
|
124
|
-
partResult,
|
|
125
|
-
},
|
|
126
|
-
} = inputs;
|
|
127
|
-
if (throwOnNon2xxResponse) {
|
|
128
|
-
await assertError(op, {
|
|
129
|
-
statusCode,
|
|
130
|
-
messagePattern,
|
|
131
|
-
});
|
|
132
|
-
} else {
|
|
133
|
-
if (notThrowingStatusCode !== undefined || notThrowingMessagePattern !== undefined) {
|
|
134
|
-
await assertError(op, {
|
|
135
|
-
statusCode: notThrowingStatusCode,
|
|
136
|
-
messagePattern: notThrowingMessagePattern,
|
|
137
|
-
});
|
|
138
|
-
} else if (partResult !== undefined) {
|
|
139
|
-
assert.deepInclude(await op, partResult);
|
|
140
|
-
} else {
|
|
141
|
-
assert.deepEqual(await op, result);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.package",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"paths": {
|
|
5
|
-
"@azure/core-lro": ["./src/index.ts"]
|
|
6
|
-
},
|
|
7
|
-
"module": "NodeNext",
|
|
8
|
-
"moduleResolution": "NodeNext",
|
|
9
|
-
"rootDir": "."
|
|
10
|
-
},
|
|
11
|
-
"exclude": ["./samples/**/*.ts"],
|
|
12
|
-
"include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.ts"]
|
|
13
|
-
}
|
package/tsdoc.json
DELETED
package/tslint.json
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"rules": {
|
|
3
|
-
"class-name": true,
|
|
4
|
-
"comment-format": [true, "check-space"],
|
|
5
|
-
"indent": [true, "spaces"],
|
|
6
|
-
"linebreak-style": [true, "LF"],
|
|
7
|
-
"one-line": [true, "check-open-brace", "check-whitespace"],
|
|
8
|
-
"no-var-keyword": true,
|
|
9
|
-
"quotemark": [true, "double", "avoid-escape"],
|
|
10
|
-
"semicolon": [true, "always", "ignore-bound-class-methods"],
|
|
11
|
-
"whitespace": [
|
|
12
|
-
true,
|
|
13
|
-
"check-branch",
|
|
14
|
-
"check-decl",
|
|
15
|
-
"check-operator",
|
|
16
|
-
"check-module",
|
|
17
|
-
"check-separator",
|
|
18
|
-
"check-type"
|
|
19
|
-
],
|
|
20
|
-
"typedef-whitespace": [
|
|
21
|
-
true,
|
|
22
|
-
{
|
|
23
|
-
"call-signature": "nospace",
|
|
24
|
-
"index-signature": "nospace",
|
|
25
|
-
"parameter": "nospace",
|
|
26
|
-
"property-declaration": "nospace",
|
|
27
|
-
"variable-declaration": "nospace"
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"call-signature": "onespace",
|
|
31
|
-
"index-signature": "onespace",
|
|
32
|
-
"parameter": "onespace",
|
|
33
|
-
"property-declaration": "onespace",
|
|
34
|
-
"variable-declaration": "onespace"
|
|
35
|
-
}
|
|
36
|
-
],
|
|
37
|
-
"no-internal-module": true,
|
|
38
|
-
"jsdoc-format": true,
|
|
39
|
-
"no-inferrable-types": [true],
|
|
40
|
-
"no-null-keyword": true,
|
|
41
|
-
"no-return-await": true,
|
|
42
|
-
"no-switch-case-fall-through": true,
|
|
43
|
-
"no-trailing-whitespace": true,
|
|
44
|
-
"prefer-const": true,
|
|
45
|
-
"triple-equals": [true, "allow-undefined-check"]
|
|
46
|
-
}
|
|
47
|
-
}
|
package/vitest.browser.config.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
|
|
4
|
-
import { defineConfig } from "vitest/config";
|
|
5
|
-
|
|
6
|
-
export default defineConfig({
|
|
7
|
-
test: {
|
|
8
|
-
reporters: ["basic", "junit"],
|
|
9
|
-
outputFile: {
|
|
10
|
-
junit: "test-results.browser.xml",
|
|
11
|
-
},
|
|
12
|
-
browser: {
|
|
13
|
-
enabled: true,
|
|
14
|
-
headless: true,
|
|
15
|
-
name: "chromium",
|
|
16
|
-
provider: "playwright",
|
|
17
|
-
},
|
|
18
|
-
fakeTimers: {
|
|
19
|
-
toFake: ["setTimeout", "Date"],
|
|
20
|
-
},
|
|
21
|
-
watch: false,
|
|
22
|
-
include: ["dist-test/browser/**/*.spec.js"],
|
|
23
|
-
coverage: {
|
|
24
|
-
include: ["dist-test/browser/**/*.js"],
|
|
25
|
-
exclude: [
|
|
26
|
-
"dist-test/browser/**/*./*-browser.mjs",
|
|
27
|
-
"dist-test/browser/**/*./*-react-native.mjs",
|
|
28
|
-
],
|
|
29
|
-
provider: "istanbul",
|
|
30
|
-
reporter: ["text", "json", "html"],
|
|
31
|
-
reportsDirectory: "coverage-browser",
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
});
|
package/vitest.config.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
|
|
4
|
-
import { defineConfig } from "vitest/config";
|
|
5
|
-
|
|
6
|
-
export default defineConfig({
|
|
7
|
-
test: {
|
|
8
|
-
reporters: ["basic", "junit"],
|
|
9
|
-
outputFile: {
|
|
10
|
-
junit: "test-results.browser.xml",
|
|
11
|
-
},
|
|
12
|
-
fakeTimers: {
|
|
13
|
-
toFake: ["setTimeout", "Date"],
|
|
14
|
-
},
|
|
15
|
-
watch: false,
|
|
16
|
-
include: ["test/**/*.spec.ts"],
|
|
17
|
-
exclude: ["test/**/browser/*.spec.ts"],
|
|
18
|
-
coverage: {
|
|
19
|
-
include: ["src/**/*.ts"],
|
|
20
|
-
exclude: [
|
|
21
|
-
"src/**/*-browser.mts",
|
|
22
|
-
"src/**/*-react-native.mts",
|
|
23
|
-
"vitest*.config.ts",
|
|
24
|
-
"samples-dev/**/*.ts",
|
|
25
|
-
],
|
|
26
|
-
provider: "v8",
|
|
27
|
-
reporter: ["text", "json", "html"],
|
|
28
|
-
reportsDirectory: "coverage",
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
});
|