@azure/arm-managedapplications 2.0.0-beta.1 → 2.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/CHANGELOG.md +6 -11
- package/README.md +15 -9
- package/dist/index.js +145 -929
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/{esm → dist-esm/src}/applicationClient.d.ts +7 -19
- package/dist-esm/src/applicationClient.d.ts.map +1 -0
- package/{esm → dist-esm/src}/applicationClient.js +31 -74
- package/dist-esm/src/applicationClient.js.map +1 -0
- package/dist-esm/src/index.d.ts +5 -0
- package/dist-esm/src/index.d.ts.map +1 -0
- package/{esm → dist-esm/src}/index.js +0 -1
- package/dist-esm/src/index.js.map +1 -0
- package/dist-esm/src/lroImpl.d.ts +16 -0
- package/dist-esm/src/lroImpl.d.ts.map +1 -0
- package/dist-esm/src/lroImpl.js +29 -0
- package/dist-esm/src/lroImpl.js.map +1 -0
- package/{esm → dist-esm/src}/models/index.d.ts +39 -59
- package/dist-esm/src/models/index.d.ts.map +1 -0
- package/{esm → dist-esm/src}/models/index.js +0 -0
- package/dist-esm/src/models/index.js.map +1 -0
- package/{esm → dist-esm/src}/models/mappers.d.ts +2 -2
- package/dist-esm/src/models/mappers.d.ts.map +1 -0
- package/{esm → dist-esm/src}/models/mappers.js +34 -34
- package/dist-esm/src/models/mappers.js.map +1 -0
- package/{esm → dist-esm/src}/models/parameters.d.ts +0 -0
- package/dist-esm/src/models/parameters.d.ts.map +1 -0
- package/{esm → dist-esm/src}/models/parameters.js +0 -0
- package/dist-esm/src/models/parameters.js.map +1 -0
- package/{esm → dist-esm/src}/operations/applicationDefinitions.d.ts +4 -22
- package/dist-esm/src/operations/applicationDefinitions.d.ts.map +1 -0
- package/{esm → dist-esm/src}/operations/applicationDefinitions.js +23 -93
- package/dist-esm/src/operations/applicationDefinitions.js.map +1 -0
- package/{esm → dist-esm/src}/operations/applications.d.ts +4 -36
- package/dist-esm/src/operations/applications.d.ts.map +1 -0
- package/{esm → dist-esm/src}/operations/applications.js +23 -170
- package/dist-esm/src/operations/applications.js.map +1 -0
- package/{esm → dist-esm/src}/operations/index.d.ts +0 -0
- package/dist-esm/src/operations/index.d.ts.map +1 -0
- package/{esm → dist-esm/src}/operations/index.js +0 -0
- package/dist-esm/src/operations/index.js.map +1 -0
- package/{esm → dist-esm/src}/operationsInterfaces/applicationDefinitions.d.ts +1 -9
- package/dist-esm/src/operationsInterfaces/applicationDefinitions.d.ts.map +1 -0
- package/{esm → dist-esm/src}/operationsInterfaces/applicationDefinitions.js +1 -1
- package/dist-esm/src/operationsInterfaces/applicationDefinitions.js.map +1 -0
- package/{esm → dist-esm/src}/operationsInterfaces/applications.d.ts +1 -15
- package/dist-esm/src/operationsInterfaces/applications.d.ts.map +1 -0
- package/{esm → dist-esm/src}/operationsInterfaces/applications.js +1 -1
- package/dist-esm/src/operationsInterfaces/applications.js.map +1 -0
- package/{esm → dist-esm/src}/operationsInterfaces/index.d.ts +0 -0
- package/dist-esm/src/operationsInterfaces/index.d.ts.map +1 -0
- package/{esm → dist-esm/src}/operationsInterfaces/index.js +0 -0
- package/dist-esm/src/operationsInterfaces/index.js.map +1 -0
- package/dist-esm/test/sampleTest.d.ts +2 -0
- package/dist-esm/test/sampleTest.d.ts.map +1 -0
- package/dist-esm/test/sampleTest.js +40 -0
- package/dist-esm/test/sampleTest.js.map +1 -0
- package/package.json +27 -33
- package/review/arm-managedapplications.api.md +20 -58
- package/src/applicationClient.ts +56 -94
- package/src/index.ts +0 -1
- package/src/lroImpl.ts +34 -0
- package/src/models/index.ts +37 -65
- package/src/models/mappers.ts +34 -34
- package/src/operations/applicationDefinitions.ts +27 -128
- package/src/operations/applications.ts +27 -217
- package/src/operationsInterfaces/applicationDefinitions.ts +0 -13
- package/src/operationsInterfaces/applications.ts +0 -23
- package/tsconfig.json +2 -3
- package/{esm/index.d.ts → types/arm-managedapplications.d.ts} +19 -91
- package/types/tsdoc-metadata.json +11 -0
- package/esm/applicationClient.d.ts.map +0 -1
- package/esm/applicationClient.js.map +0 -1
- package/esm/applicationClientContext.d.ts +0 -16
- package/esm/applicationClientContext.d.ts.map +0 -1
- package/esm/applicationClientContext.js +0 -49
- package/esm/applicationClientContext.js.map +0 -1
- package/esm/coreClientLro.d.ts +0 -26
- package/esm/coreClientLro.d.ts.map +0 -1
- package/esm/coreClientLro.js +0 -186
- package/esm/coreClientLro.js.map +0 -1
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js.map +0 -1
- package/esm/lro/azureAsyncPolling.d.ts +0 -3
- package/esm/lro/azureAsyncPolling.d.ts.map +0 -1
- package/esm/lro/azureAsyncPolling.js +0 -67
- package/esm/lro/azureAsyncPolling.js.map +0 -1
- package/esm/lro/bodyPolling.d.ts +0 -8
- package/esm/lro/bodyPolling.d.ts.map +0 -1
- package/esm/lro/bodyPolling.js +0 -37
- package/esm/lro/bodyPolling.js.map +0 -1
- package/esm/lro/index.d.ts +0 -4
- package/esm/lro/index.d.ts.map +0 -1
- package/esm/lro/index.js +0 -12
- package/esm/lro/index.js.map +0 -1
- package/esm/lro/locationPolling.d.ts +0 -3
- package/esm/lro/locationPolling.d.ts.map +0 -1
- package/esm/lro/locationPolling.js +0 -19
- package/esm/lro/locationPolling.js.map +0 -1
- package/esm/lro/lroEngine.d.ts +0 -14
- package/esm/lro/lroEngine.d.ts.map +0 -1
- package/esm/lro/lroEngine.js +0 -41
- package/esm/lro/lroEngine.js.map +0 -1
- package/esm/lro/models.d.ts +0 -138
- package/esm/lro/models.d.ts.map +0 -1
- package/esm/lro/models.js +0 -14
- package/esm/lro/models.js.map +0 -1
- package/esm/lro/operation.d.ts +0 -36
- package/esm/lro/operation.d.ts.map +0 -1
- package/esm/lro/operation.js +0 -82
- package/esm/lro/operation.js.map +0 -1
- package/esm/lro/passthrough.d.ts +0 -3
- package/esm/lro/passthrough.d.ts.map +0 -1
- package/esm/lro/passthrough.js +0 -15
- package/esm/lro/passthrough.js.map +0 -1
- package/esm/lro/requestUtils.d.ts +0 -16
- package/esm/lro/requestUtils.d.ts.map +0 -1
- package/esm/lro/requestUtils.js +0 -73
- package/esm/lro/requestUtils.js.map +0 -1
- package/esm/lro/stateMachine.d.ts +0 -18
- package/esm/lro/stateMachine.d.ts.map +0 -1
- package/esm/lro/stateMachine.js +0 -84
- package/esm/lro/stateMachine.js.map +0 -1
- package/esm/models/index.d.ts.map +0 -1
- package/esm/models/index.js.map +0 -1
- package/esm/models/mappers.d.ts.map +0 -1
- package/esm/models/mappers.js.map +0 -1
- package/esm/models/parameters.d.ts.map +0 -1
- package/esm/models/parameters.js.map +0 -1
- package/esm/operations/applicationDefinitions.d.ts.map +0 -1
- package/esm/operations/applicationDefinitions.js.map +0 -1
- package/esm/operations/applications.d.ts.map +0 -1
- package/esm/operations/applications.js.map +0 -1
- package/esm/operations/index.d.ts.map +0 -1
- package/esm/operations/index.js.map +0 -1
- package/esm/operationsInterfaces/applicationDefinitions.d.ts.map +0 -1
- package/esm/operationsInterfaces/applicationDefinitions.js.map +0 -1
- package/esm/operationsInterfaces/applications.d.ts.map +0 -1
- package/esm/operationsInterfaces/applications.js.map +0 -1
- package/esm/operationsInterfaces/index.d.ts.map +0 -1
- package/esm/operationsInterfaces/index.js.map +0 -1
- package/src/applicationClientContext.ts +0 -70
- package/src/coreClientLro.ts +0 -323
- package/src/lro/azureAsyncPolling.ts +0 -96
- package/src/lro/bodyPolling.ts +0 -54
- package/src/lro/index.ts +0 -26
- package/src/lro/locationPolling.ts +0 -30
- package/src/lro/lroEngine.ts +0 -61
- package/src/lro/models.ts +0 -173
- package/src/lro/operation.ts +0 -120
- package/src/lro/passthrough.ts +0 -23
- package/src/lro/requestUtils.ts +0 -105
- package/src/lro/stateMachine.ts +0 -138
package/src/lro/models.ts
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*
|
|
5
|
-
* Code generated by Microsoft (R) AutoRest Code Generator.
|
|
6
|
-
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Copyright (c) Microsoft Corporation.
|
|
10
|
-
// Licensed under the MIT license.
|
|
11
|
-
|
|
12
|
-
import { PollOperationState } from "@azure/core-lro";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Options for the LRO poller.
|
|
16
|
-
*/
|
|
17
|
-
export interface LroEngineOptions {
|
|
18
|
-
/**
|
|
19
|
-
* Defines how much time the poller is going to wait before making a new request to the service.
|
|
20
|
-
*/
|
|
21
|
-
intervalInMs?: number;
|
|
22
|
-
/**
|
|
23
|
-
* A serialized poller which can be used to resume an existing paused Long-Running-Operation.
|
|
24
|
-
*/
|
|
25
|
-
resumeFrom?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const successStates = ["succeeded"];
|
|
29
|
-
export const failureStates = ["failed", "canceled", "cancelled"];
|
|
30
|
-
/**
|
|
31
|
-
* The LRO states that signal that the LRO has completed.
|
|
32
|
-
*/
|
|
33
|
-
export const terminalStates = successStates.concat(failureStates);
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The potential location of the result of the LRO if specified by the LRO extension in the swagger.
|
|
37
|
-
*/
|
|
38
|
-
export type LroResourceLocationConfig =
|
|
39
|
-
| "azure-async-operation"
|
|
40
|
-
| "location"
|
|
41
|
-
| "original-uri";
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The type of a LRO response body. This is just a convenience type for checking the status of the operation.
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
export interface LroBody extends Record<string, unknown> {
|
|
48
|
-
/** The status of the operation. */
|
|
49
|
-
status?: string;
|
|
50
|
-
/** The state of the provisioning process */
|
|
51
|
-
provisioningState?: string;
|
|
52
|
-
/** The properties of the provisioning process */
|
|
53
|
-
properties?: { provisioningState?: string } & Record<string, unknown>;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Simple type of the raw response.
|
|
58
|
-
*/
|
|
59
|
-
export interface RawResponse {
|
|
60
|
-
/** The HTTP status code */
|
|
61
|
-
statusCode: number;
|
|
62
|
-
/** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */
|
|
63
|
-
headers: {
|
|
64
|
-
[headerName: string]: string;
|
|
65
|
-
};
|
|
66
|
-
/** The parsed response body */
|
|
67
|
-
body?: unknown;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* The type of the response of a LRO.
|
|
72
|
-
*/
|
|
73
|
-
export interface LroResponse<T> {
|
|
74
|
-
/** The flattened response */
|
|
75
|
-
flatResponse: T;
|
|
76
|
-
/** The raw response */
|
|
77
|
-
rawResponse: RawResponse;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** The type of which LRO implementation being followed by a specific API. */
|
|
81
|
-
export type LroMode = "AzureAsync" | "Location" | "Body";
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* The configuration of a LRO to determine how to perform polling and checking whether the operation has completed.
|
|
85
|
-
*/
|
|
86
|
-
export interface LroConfig {
|
|
87
|
-
/** The LRO mode */
|
|
88
|
-
mode?: LroMode;
|
|
89
|
-
/** The path of a provisioned resource */
|
|
90
|
-
resourceLocation?: string;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Type of a polling operation state that can actually be resumed.
|
|
95
|
-
*/
|
|
96
|
-
export type ResumablePollOperationState<T> = PollOperationState<T> & {
|
|
97
|
-
initialRawResponse?: RawResponse;
|
|
98
|
-
config?: LroConfig;
|
|
99
|
-
pollingURL?: string;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export interface PollerConfig {
|
|
103
|
-
intervalInMs: number;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* The type of a terminal state of an LRO.
|
|
108
|
-
*/
|
|
109
|
-
export interface LroTerminalState<T> extends LroResponse<T> {
|
|
110
|
-
/**
|
|
111
|
-
* Whether the operation has finished.
|
|
112
|
-
*/
|
|
113
|
-
done: true;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* The type of an in-progress state of an LRO.
|
|
118
|
-
*/
|
|
119
|
-
export interface LroInProgressState<T> extends LroResponse<T> {
|
|
120
|
-
/**
|
|
121
|
-
* Whether the operation has finished.
|
|
122
|
-
*/
|
|
123
|
-
done: false;
|
|
124
|
-
/**
|
|
125
|
-
* The request to be sent next if it is different from the standard polling one.
|
|
126
|
-
* Notice that it will disregard any polling URLs provided to it.
|
|
127
|
-
*/
|
|
128
|
-
next?: () => Promise<LroStatus<T>>;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* The type of an LRO state which is a tagged union of terminal and in-progress states.
|
|
133
|
-
*/
|
|
134
|
-
export type LroStatus<T> = LroTerminalState<T> | LroInProgressState<T>;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* The type of the getLROStatusFromResponse method. It takes the response as input and returns along the response whether the operation has finished.
|
|
138
|
-
*/
|
|
139
|
-
export type GetLroStatusFromResponse<T> = (
|
|
140
|
-
rawResponse: RawResponse,
|
|
141
|
-
flatResponse: T
|
|
142
|
-
) => LroStatus<T>;
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Description of a long running operation.
|
|
146
|
-
*/
|
|
147
|
-
export interface LongRunningOperation<T> {
|
|
148
|
-
/**
|
|
149
|
-
* The request path.
|
|
150
|
-
*/
|
|
151
|
-
requestPath: string;
|
|
152
|
-
/**
|
|
153
|
-
* The HTTP request method.
|
|
154
|
-
*/
|
|
155
|
-
requestMethod: string;
|
|
156
|
-
/**
|
|
157
|
-
* A function that can be used to send initial request to the service.
|
|
158
|
-
*/
|
|
159
|
-
sendInitialRequest: (
|
|
160
|
-
initializeState: (
|
|
161
|
-
rawResponse: RawResponse,
|
|
162
|
-
flatResponse: unknown
|
|
163
|
-
) => boolean
|
|
164
|
-
) => Promise<LroResponse<T>>;
|
|
165
|
-
/**
|
|
166
|
-
* A function that can be used to poll for the current status of a long running operation.
|
|
167
|
-
*/
|
|
168
|
-
sendPollRequest: (config: LroConfig, path: string) => Promise<LroStatus<T>>;
|
|
169
|
-
/**
|
|
170
|
-
* A function that can be used to retrieve the provisioned azure resource.
|
|
171
|
-
*/
|
|
172
|
-
retrieveAzureAsyncResource: (path?: string) => Promise<LroResponse<T>>;
|
|
173
|
-
}
|
package/src/lro/operation.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*
|
|
5
|
-
* Code generated by Microsoft (R) AutoRest Code Generator.
|
|
6
|
-
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Copyright (c) Microsoft Corporation.
|
|
10
|
-
// Licensed under the MIT license.
|
|
11
|
-
|
|
12
|
-
import { AbortSignalLike } from "@azure/abort-controller";
|
|
13
|
-
import { PollOperationState, PollOperation } from "@azure/core-lro";
|
|
14
|
-
import {
|
|
15
|
-
PollerConfig,
|
|
16
|
-
ResumablePollOperationState,
|
|
17
|
-
LongRunningOperation,
|
|
18
|
-
LroStatus
|
|
19
|
-
} from "./models";
|
|
20
|
-
import { getPollingUrl } from "./requestUtils";
|
|
21
|
-
import { createInitializeState, createPollForLROStatus } from "./stateMachine";
|
|
22
|
-
|
|
23
|
-
export class GenericPollOperation<
|
|
24
|
-
TResult,
|
|
25
|
-
TState extends PollOperationState<TResult>
|
|
26
|
-
> implements PollOperation<TState, TResult> {
|
|
27
|
-
private getLROStatusFromResponse?: (
|
|
28
|
-
pollingURL: string,
|
|
29
|
-
pollerConfig: PollerConfig
|
|
30
|
-
) => Promise<LroStatus<TResult>>;
|
|
31
|
-
private pollerConfig?: PollerConfig;
|
|
32
|
-
constructor(
|
|
33
|
-
public state: TState & ResumablePollOperationState<TResult>,
|
|
34
|
-
private lro: LongRunningOperation<TResult>
|
|
35
|
-
) {}
|
|
36
|
-
|
|
37
|
-
public setPollerConfig(pollerConfig: PollerConfig): void {
|
|
38
|
-
this.pollerConfig = pollerConfig;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* General update function for LROPoller, the general process is as follows
|
|
43
|
-
* 1. Check initial operation result to determine the strategy to use
|
|
44
|
-
* - Strategies: Location, Azure-AsyncOperation, Original Uri
|
|
45
|
-
* 2. Check if the operation result has a terminal state
|
|
46
|
-
* - Terminal state will be determined by each strategy
|
|
47
|
-
* 2.1 If it is terminal state Check if a final GET request is required, if so
|
|
48
|
-
* send final GET request and return result from operation. If no final GET
|
|
49
|
-
* is required, just return the result from operation.
|
|
50
|
-
* - Determining what to call for final request is responsibility of each strategy
|
|
51
|
-
* 2.2 If it is not terminal state, call the polling operation and go to step 1
|
|
52
|
-
* - Determining what to call for polling is responsibility of each strategy
|
|
53
|
-
* - Strategies will always use the latest URI for polling if provided otherwise
|
|
54
|
-
* the last known one
|
|
55
|
-
*/
|
|
56
|
-
async update(options?: {
|
|
57
|
-
abortSignal?: AbortSignalLike | undefined;
|
|
58
|
-
fireProgress?: ((state: TState) => void) | undefined;
|
|
59
|
-
}): Promise<PollOperation<TState, TResult>> {
|
|
60
|
-
const state = this.state;
|
|
61
|
-
if (!state.isStarted) {
|
|
62
|
-
const initializeState = createInitializeState(
|
|
63
|
-
state,
|
|
64
|
-
this.lro.requestPath,
|
|
65
|
-
this.lro.requestMethod
|
|
66
|
-
);
|
|
67
|
-
await this.lro.sendInitialRequest(initializeState);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (!state.isCompleted) {
|
|
71
|
-
if (this.getLROStatusFromResponse === undefined) {
|
|
72
|
-
if (state.config === undefined) {
|
|
73
|
-
throw new Error(
|
|
74
|
-
"Bad state: LRO mode is undefined. Please check if the serialized state is well-formed."
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
this.getLROStatusFromResponse = createPollForLROStatus(
|
|
78
|
-
this.lro,
|
|
79
|
-
state.config
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
if (state.pollingURL === undefined) {
|
|
83
|
-
throw new Error(
|
|
84
|
-
"Bad state: polling URL is undefined. Please check if the serialized state is well-formed."
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
const currentState = await this.getLROStatusFromResponse(
|
|
88
|
-
state.pollingURL,
|
|
89
|
-
this.pollerConfig!
|
|
90
|
-
);
|
|
91
|
-
if (currentState.done) {
|
|
92
|
-
state.result = currentState.flatResponse;
|
|
93
|
-
state.isCompleted = true;
|
|
94
|
-
} else {
|
|
95
|
-
this.getLROStatusFromResponse =
|
|
96
|
-
currentState.next ?? this.getLROStatusFromResponse;
|
|
97
|
-
state.pollingURL = getPollingUrl(
|
|
98
|
-
currentState.rawResponse,
|
|
99
|
-
state.pollingURL
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
options?.fireProgress?.(state);
|
|
104
|
-
return this;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async cancel(): Promise<PollOperation<TState, TResult>> {
|
|
108
|
-
this.state.isCancelled = true;
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Serializes the Poller operation.
|
|
114
|
-
*/
|
|
115
|
-
public toString(): string {
|
|
116
|
-
return JSON.stringify({
|
|
117
|
-
state: this.state
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
package/src/lro/passthrough.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*
|
|
5
|
-
* Code generated by Microsoft (R) AutoRest Code Generator.
|
|
6
|
-
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Copyright (c) Microsoft Corporation.
|
|
10
|
-
// Licensed under the MIT license.
|
|
11
|
-
|
|
12
|
-
import { LroStatus, RawResponse } from "./models";
|
|
13
|
-
|
|
14
|
-
export function processPassthroughOperationResult<TResult>(
|
|
15
|
-
rawResponse: RawResponse,
|
|
16
|
-
flatResponse: TResult
|
|
17
|
-
): LroStatus<TResult> {
|
|
18
|
-
return {
|
|
19
|
-
rawResponse,
|
|
20
|
-
flatResponse,
|
|
21
|
-
done: true
|
|
22
|
-
};
|
|
23
|
-
}
|
package/src/lro/requestUtils.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*
|
|
5
|
-
* Code generated by Microsoft (R) AutoRest Code Generator.
|
|
6
|
-
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Copyright (c) Microsoft Corporation.
|
|
10
|
-
// Licensed under the MIT license.
|
|
11
|
-
|
|
12
|
-
import { LroConfig, RawResponse } from "./models";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Detects where the continuation token is and returns it. Notice that azure-asyncoperation
|
|
16
|
-
* must be checked first before the other location headers because there are scenarios
|
|
17
|
-
* where both azure-asyncoperation and location could be present in the same response but
|
|
18
|
-
* azure-asyncoperation should be the one to use for polling.
|
|
19
|
-
*/
|
|
20
|
-
export function getPollingUrl(
|
|
21
|
-
rawResponse: RawResponse,
|
|
22
|
-
defaultPath: string
|
|
23
|
-
): string {
|
|
24
|
-
return (
|
|
25
|
-
getAzureAsyncOperation(rawResponse) ??
|
|
26
|
-
getLocation(rawResponse) ??
|
|
27
|
-
getOperationLocation(rawResponse) ??
|
|
28
|
-
defaultPath
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function getLocation(rawResponse: RawResponse): string | undefined {
|
|
33
|
-
return rawResponse.headers["location"];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getOperationLocation(rawResponse: RawResponse): string | undefined {
|
|
37
|
-
return rawResponse.headers["operation-location"];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function getAzureAsyncOperation(rawResponse: RawResponse): string | undefined {
|
|
41
|
-
return rawResponse.headers["azure-asyncoperation"];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function inferLroMode(
|
|
45
|
-
requestPath: string,
|
|
46
|
-
requestMethod: string,
|
|
47
|
-
rawResponse: RawResponse
|
|
48
|
-
): LroConfig {
|
|
49
|
-
if (getAzureAsyncOperation(rawResponse) !== undefined) {
|
|
50
|
-
return {
|
|
51
|
-
mode: "AzureAsync",
|
|
52
|
-
resourceLocation:
|
|
53
|
-
requestMethod === "PUT"
|
|
54
|
-
? requestPath
|
|
55
|
-
: requestMethod === "POST"
|
|
56
|
-
? getLocation(rawResponse)
|
|
57
|
-
: undefined
|
|
58
|
-
};
|
|
59
|
-
} else if (
|
|
60
|
-
getLocation(rawResponse) !== undefined ||
|
|
61
|
-
getOperationLocation(rawResponse) !== undefined
|
|
62
|
-
) {
|
|
63
|
-
return {
|
|
64
|
-
mode: "Location"
|
|
65
|
-
};
|
|
66
|
-
} else if (["PUT", "PATCH"].includes(requestMethod)) {
|
|
67
|
-
return {
|
|
68
|
-
mode: "Body"
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
return {};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export class RestError extends Error {
|
|
75
|
-
public statusCode?: number;
|
|
76
|
-
constructor(message: string, statusCode: number) {
|
|
77
|
-
super(message);
|
|
78
|
-
this.name = "RestError";
|
|
79
|
-
this.statusCode = statusCode;
|
|
80
|
-
|
|
81
|
-
Object.setPrototypeOf(this, RestError.prototype);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function isUnexpectedInitialResponse(rawResponse: RawResponse): boolean {
|
|
86
|
-
const code = rawResponse.statusCode;
|
|
87
|
-
if (![203, 204, 202, 201, 200, 500].includes(code)) {
|
|
88
|
-
throw new RestError(
|
|
89
|
-
`Received unexpected HTTP status code ${code} in the initial response. This may indicate a server issue.`,
|
|
90
|
-
code
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function isUnexpectedPollingResponse(rawResponse: RawResponse): boolean {
|
|
97
|
-
const code = rawResponse.statusCode;
|
|
98
|
-
if (![202, 201, 200, 500].includes(code)) {
|
|
99
|
-
throw new RestError(
|
|
100
|
-
`Received unexpected HTTP status code ${code} while polling. This may indicate a server issue.`,
|
|
101
|
-
code
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
return false;
|
|
105
|
-
}
|
package/src/lro/stateMachine.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*
|
|
5
|
-
* Code generated by Microsoft (R) AutoRest Code Generator.
|
|
6
|
-
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Copyright (c) Microsoft Corporation.
|
|
10
|
-
// Licensed under the MIT license.
|
|
11
|
-
|
|
12
|
-
import { processAzureAsyncOperationResult } from "./azureAsyncPolling";
|
|
13
|
-
import {
|
|
14
|
-
isBodyPollingDone,
|
|
15
|
-
processBodyPollingOperationResult
|
|
16
|
-
} from "./bodyPolling";
|
|
17
|
-
import { processLocationPollingOperationResult } from "./locationPolling";
|
|
18
|
-
import {
|
|
19
|
-
LroResourceLocationConfig,
|
|
20
|
-
GetLroStatusFromResponse,
|
|
21
|
-
LongRunningOperation,
|
|
22
|
-
LroConfig,
|
|
23
|
-
LroStatus,
|
|
24
|
-
PollerConfig,
|
|
25
|
-
RawResponse,
|
|
26
|
-
ResumablePollOperationState
|
|
27
|
-
} from "./models";
|
|
28
|
-
import { processPassthroughOperationResult } from "./passthrough";
|
|
29
|
-
import {
|
|
30
|
-
getPollingUrl,
|
|
31
|
-
inferLroMode,
|
|
32
|
-
isUnexpectedInitialResponse
|
|
33
|
-
} from "./requestUtils";
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* creates a stepping function that maps an LRO state to another.
|
|
37
|
-
*/
|
|
38
|
-
export function createGetLroStatusFromResponse<TResult>(
|
|
39
|
-
lroPrimitives: LongRunningOperation<TResult>,
|
|
40
|
-
config: LroConfig,
|
|
41
|
-
lroResourceLocationConfig?: LroResourceLocationConfig
|
|
42
|
-
): GetLroStatusFromResponse<TResult> {
|
|
43
|
-
switch (config.mode) {
|
|
44
|
-
case "AzureAsync": {
|
|
45
|
-
return processAzureAsyncOperationResult(
|
|
46
|
-
lroPrimitives,
|
|
47
|
-
config.resourceLocation,
|
|
48
|
-
lroResourceLocationConfig
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
case "Location": {
|
|
52
|
-
return processLocationPollingOperationResult;
|
|
53
|
-
}
|
|
54
|
-
case "Body": {
|
|
55
|
-
return processBodyPollingOperationResult;
|
|
56
|
-
}
|
|
57
|
-
default: {
|
|
58
|
-
return processPassthroughOperationResult;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Creates a polling operation that returns a LRO state.
|
|
65
|
-
*/
|
|
66
|
-
export function createPollForLROStatus<TResult>(
|
|
67
|
-
lroPrimitives: LongRunningOperation<TResult>,
|
|
68
|
-
config: LroConfig
|
|
69
|
-
): (
|
|
70
|
-
pollingURL: string,
|
|
71
|
-
pollerConfig: PollerConfig
|
|
72
|
-
) => Promise<LroStatus<TResult>> {
|
|
73
|
-
return async (
|
|
74
|
-
path: string,
|
|
75
|
-
pollerConfig: PollerConfig
|
|
76
|
-
): Promise<LroStatus<TResult>> => {
|
|
77
|
-
const response = await lroPrimitives.sendPollRequest(config, path);
|
|
78
|
-
const retryAfter: string | undefined =
|
|
79
|
-
response.rawResponse.headers["retry-after"];
|
|
80
|
-
if (retryAfter !== undefined) {
|
|
81
|
-
const retryAfterInMs = parseInt(retryAfter);
|
|
82
|
-
pollerConfig.intervalInMs = isNaN(retryAfterInMs)
|
|
83
|
-
? calculatePollingIntervalFromDate(
|
|
84
|
-
new Date(retryAfter),
|
|
85
|
-
pollerConfig.intervalInMs
|
|
86
|
-
)
|
|
87
|
-
: retryAfterInMs;
|
|
88
|
-
}
|
|
89
|
-
return response;
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function calculatePollingIntervalFromDate(
|
|
94
|
-
retryAfterDate: Date,
|
|
95
|
-
defaultIntervalInMs: number
|
|
96
|
-
): number {
|
|
97
|
-
const timeNow = Math.floor(new Date().getTime());
|
|
98
|
-
const retryAfterTime = retryAfterDate.getTime();
|
|
99
|
-
if (timeNow < retryAfterTime) {
|
|
100
|
-
return retryAfterTime - timeNow;
|
|
101
|
-
}
|
|
102
|
-
return defaultIntervalInMs;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Creates a callback to be used to initialize the polling operation state.
|
|
107
|
-
* @param state - of the polling operation
|
|
108
|
-
* @param operationSpec - of the LRO
|
|
109
|
-
* @param callback - callback to be called when the operation is done
|
|
110
|
-
* @returns callback that initializes the state of the polling operation
|
|
111
|
-
*/
|
|
112
|
-
export function createInitializeState<TResult>(
|
|
113
|
-
state: ResumablePollOperationState<TResult>,
|
|
114
|
-
requestPath: string,
|
|
115
|
-
requestMethod: string
|
|
116
|
-
): (rawResponse: RawResponse, flatResponse: unknown) => boolean {
|
|
117
|
-
return (rawResponse: RawResponse, flatResponse: unknown) => {
|
|
118
|
-
if (isUnexpectedInitialResponse(rawResponse)) return true;
|
|
119
|
-
state.initialRawResponse = rawResponse;
|
|
120
|
-
state.isStarted = true;
|
|
121
|
-
state.pollingURL = getPollingUrl(state.initialRawResponse, requestPath);
|
|
122
|
-
state.config = inferLroMode(
|
|
123
|
-
requestPath,
|
|
124
|
-
requestMethod,
|
|
125
|
-
state.initialRawResponse
|
|
126
|
-
);
|
|
127
|
-
/** short circuit polling if body polling is done in the initial request */
|
|
128
|
-
if (
|
|
129
|
-
state.config.mode === undefined ||
|
|
130
|
-
(state.config.mode === "Body" &&
|
|
131
|
-
isBodyPollingDone(state.initialRawResponse))
|
|
132
|
-
) {
|
|
133
|
-
state.result = flatResponse as TResult;
|
|
134
|
-
state.isCompleted = true;
|
|
135
|
-
}
|
|
136
|
-
return Boolean(state.isCompleted);
|
|
137
|
-
};
|
|
138
|
-
}
|