@azure/arm-managedapplications 2.0.0-alpha.20211111.1 → 2.0.1-alpha.20211220.1

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.
Files changed (154) hide show
  1. package/CHANGELOG.md +6 -11
  2. package/README.md +15 -9
  3. package/dist/index.js +145 -929
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.js +1 -1
  6. package/dist/index.min.js.map +1 -1
  7. package/{esm → dist-esm/src}/applicationClient.d.ts +7 -19
  8. package/dist-esm/src/applicationClient.d.ts.map +1 -0
  9. package/{esm → dist-esm/src}/applicationClient.js +31 -74
  10. package/dist-esm/src/applicationClient.js.map +1 -0
  11. package/dist-esm/src/index.d.ts +5 -0
  12. package/dist-esm/src/index.d.ts.map +1 -0
  13. package/{esm → dist-esm/src}/index.js +0 -1
  14. package/dist-esm/src/index.js.map +1 -0
  15. package/dist-esm/src/lroImpl.d.ts +16 -0
  16. package/dist-esm/src/lroImpl.d.ts.map +1 -0
  17. package/dist-esm/src/lroImpl.js +29 -0
  18. package/dist-esm/src/lroImpl.js.map +1 -0
  19. package/{esm → dist-esm/src}/models/index.d.ts +39 -59
  20. package/dist-esm/src/models/index.d.ts.map +1 -0
  21. package/{esm → dist-esm/src}/models/index.js +0 -0
  22. package/dist-esm/src/models/index.js.map +1 -0
  23. package/{esm → dist-esm/src}/models/mappers.d.ts +2 -2
  24. package/dist-esm/src/models/mappers.d.ts.map +1 -0
  25. package/{esm → dist-esm/src}/models/mappers.js +34 -34
  26. package/dist-esm/src/models/mappers.js.map +1 -0
  27. package/{esm → dist-esm/src}/models/parameters.d.ts +0 -0
  28. package/dist-esm/src/models/parameters.d.ts.map +1 -0
  29. package/{esm → dist-esm/src}/models/parameters.js +0 -0
  30. package/dist-esm/src/models/parameters.js.map +1 -0
  31. package/{esm → dist-esm/src}/operations/applicationDefinitions.d.ts +4 -22
  32. package/dist-esm/src/operations/applicationDefinitions.d.ts.map +1 -0
  33. package/{esm → dist-esm/src}/operations/applicationDefinitions.js +23 -93
  34. package/dist-esm/src/operations/applicationDefinitions.js.map +1 -0
  35. package/{esm → dist-esm/src}/operations/applications.d.ts +4 -36
  36. package/dist-esm/src/operations/applications.d.ts.map +1 -0
  37. package/{esm → dist-esm/src}/operations/applications.js +23 -170
  38. package/dist-esm/src/operations/applications.js.map +1 -0
  39. package/{esm → dist-esm/src}/operations/index.d.ts +0 -0
  40. package/dist-esm/src/operations/index.d.ts.map +1 -0
  41. package/{esm → dist-esm/src}/operations/index.js +0 -0
  42. package/dist-esm/src/operations/index.js.map +1 -0
  43. package/{esm → dist-esm/src}/operationsInterfaces/applicationDefinitions.d.ts +1 -9
  44. package/dist-esm/src/operationsInterfaces/applicationDefinitions.d.ts.map +1 -0
  45. package/{esm → dist-esm/src}/operationsInterfaces/applicationDefinitions.js +1 -1
  46. package/dist-esm/src/operationsInterfaces/applicationDefinitions.js.map +1 -0
  47. package/{esm → dist-esm/src}/operationsInterfaces/applications.d.ts +1 -15
  48. package/dist-esm/src/operationsInterfaces/applications.d.ts.map +1 -0
  49. package/{esm → dist-esm/src}/operationsInterfaces/applications.js +1 -1
  50. package/dist-esm/src/operationsInterfaces/applications.js.map +1 -0
  51. package/{esm → dist-esm/src}/operationsInterfaces/index.d.ts +0 -0
  52. package/dist-esm/src/operationsInterfaces/index.d.ts.map +1 -0
  53. package/{esm → dist-esm/src}/operationsInterfaces/index.js +0 -0
  54. package/dist-esm/src/operationsInterfaces/index.js.map +1 -0
  55. package/dist-esm/test/sampleTest.d.ts +2 -0
  56. package/dist-esm/test/sampleTest.d.ts.map +1 -0
  57. package/dist-esm/test/sampleTest.js +40 -0
  58. package/dist-esm/test/sampleTest.js.map +1 -0
  59. package/package.json +24 -20
  60. package/review/arm-managedapplications.api.md +20 -58
  61. package/src/applicationClient.ts +56 -94
  62. package/src/index.ts +0 -1
  63. package/src/lroImpl.ts +34 -0
  64. package/src/models/index.ts +37 -65
  65. package/src/models/mappers.ts +34 -34
  66. package/src/operations/applicationDefinitions.ts +27 -128
  67. package/src/operations/applications.ts +27 -217
  68. package/src/operationsInterfaces/applicationDefinitions.ts +0 -13
  69. package/src/operationsInterfaces/applications.ts +0 -23
  70. package/tsconfig.json +2 -3
  71. package/{esm/index.d.ts → types/arm-managedapplications.d.ts} +19 -91
  72. package/types/tsdoc-metadata.json +11 -0
  73. package/esm/applicationClient.d.ts.map +0 -1
  74. package/esm/applicationClient.js.map +0 -1
  75. package/esm/applicationClientContext.d.ts +0 -16
  76. package/esm/applicationClientContext.d.ts.map +0 -1
  77. package/esm/applicationClientContext.js +0 -49
  78. package/esm/applicationClientContext.js.map +0 -1
  79. package/esm/coreClientLro.d.ts +0 -26
  80. package/esm/coreClientLro.d.ts.map +0 -1
  81. package/esm/coreClientLro.js +0 -186
  82. package/esm/coreClientLro.js.map +0 -1
  83. package/esm/index.d.ts.map +0 -1
  84. package/esm/index.js.map +0 -1
  85. package/esm/lro/azureAsyncPolling.d.ts +0 -3
  86. package/esm/lro/azureAsyncPolling.d.ts.map +0 -1
  87. package/esm/lro/azureAsyncPolling.js +0 -67
  88. package/esm/lro/azureAsyncPolling.js.map +0 -1
  89. package/esm/lro/bodyPolling.d.ts +0 -8
  90. package/esm/lro/bodyPolling.d.ts.map +0 -1
  91. package/esm/lro/bodyPolling.js +0 -37
  92. package/esm/lro/bodyPolling.js.map +0 -1
  93. package/esm/lro/index.d.ts +0 -4
  94. package/esm/lro/index.d.ts.map +0 -1
  95. package/esm/lro/index.js +0 -12
  96. package/esm/lro/index.js.map +0 -1
  97. package/esm/lro/locationPolling.d.ts +0 -3
  98. package/esm/lro/locationPolling.d.ts.map +0 -1
  99. package/esm/lro/locationPolling.js +0 -19
  100. package/esm/lro/locationPolling.js.map +0 -1
  101. package/esm/lro/lroEngine.d.ts +0 -14
  102. package/esm/lro/lroEngine.d.ts.map +0 -1
  103. package/esm/lro/lroEngine.js +0 -41
  104. package/esm/lro/lroEngine.js.map +0 -1
  105. package/esm/lro/models.d.ts +0 -138
  106. package/esm/lro/models.d.ts.map +0 -1
  107. package/esm/lro/models.js +0 -14
  108. package/esm/lro/models.js.map +0 -1
  109. package/esm/lro/operation.d.ts +0 -36
  110. package/esm/lro/operation.d.ts.map +0 -1
  111. package/esm/lro/operation.js +0 -82
  112. package/esm/lro/operation.js.map +0 -1
  113. package/esm/lro/passthrough.d.ts +0 -3
  114. package/esm/lro/passthrough.d.ts.map +0 -1
  115. package/esm/lro/passthrough.js +0 -15
  116. package/esm/lro/passthrough.js.map +0 -1
  117. package/esm/lro/requestUtils.d.ts +0 -16
  118. package/esm/lro/requestUtils.d.ts.map +0 -1
  119. package/esm/lro/requestUtils.js +0 -73
  120. package/esm/lro/requestUtils.js.map +0 -1
  121. package/esm/lro/stateMachine.d.ts +0 -18
  122. package/esm/lro/stateMachine.d.ts.map +0 -1
  123. package/esm/lro/stateMachine.js +0 -84
  124. package/esm/lro/stateMachine.js.map +0 -1
  125. package/esm/models/index.d.ts.map +0 -1
  126. package/esm/models/index.js.map +0 -1
  127. package/esm/models/mappers.d.ts.map +0 -1
  128. package/esm/models/mappers.js.map +0 -1
  129. package/esm/models/parameters.d.ts.map +0 -1
  130. package/esm/models/parameters.js.map +0 -1
  131. package/esm/operations/applicationDefinitions.d.ts.map +0 -1
  132. package/esm/operations/applicationDefinitions.js.map +0 -1
  133. package/esm/operations/applications.d.ts.map +0 -1
  134. package/esm/operations/applications.js.map +0 -1
  135. package/esm/operations/index.d.ts.map +0 -1
  136. package/esm/operations/index.js.map +0 -1
  137. package/esm/operationsInterfaces/applicationDefinitions.d.ts.map +0 -1
  138. package/esm/operationsInterfaces/applicationDefinitions.js.map +0 -1
  139. package/esm/operationsInterfaces/applications.d.ts.map +0 -1
  140. package/esm/operationsInterfaces/applications.js.map +0 -1
  141. package/esm/operationsInterfaces/index.d.ts.map +0 -1
  142. package/esm/operationsInterfaces/index.js.map +0 -1
  143. package/src/applicationClientContext.ts +0 -70
  144. package/src/coreClientLro.ts +0 -323
  145. package/src/lro/azureAsyncPolling.ts +0 -96
  146. package/src/lro/bodyPolling.ts +0 -54
  147. package/src/lro/index.ts +0 -26
  148. package/src/lro/locationPolling.ts +0 -30
  149. package/src/lro/lroEngine.ts +0 -61
  150. package/src/lro/models.ts +0 -173
  151. package/src/lro/operation.ts +0 -120
  152. package/src/lro/passthrough.ts +0 -23
  153. package/src/lro/requestUtils.ts +0 -105
  154. package/src/lro/stateMachine.ts +0 -138
@@ -1,323 +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 {
13
- OperationArguments,
14
- OperationSpec,
15
- OperationResponseMap,
16
- FullOperationResponse
17
- } from "@azure/core-client";
18
- import {
19
- LroResourceLocationConfig,
20
- GetLroStatusFromResponse,
21
- LongRunningOperation,
22
- LroConfig,
23
- LroMode,
24
- LroResponse,
25
- LroStatus,
26
- createGetLroStatusFromResponse,
27
- RawResponse
28
- } from "./lro";
29
-
30
- export const successStates = ["succeeded"];
31
- export const failureStates = ["failed", "canceled", "cancelled"];
32
- export const terminalStates = successStates.concat(failureStates);
33
-
34
- export type SendOperationFn<T> = (
35
- args: OperationArguments,
36
- spec: OperationSpec
37
- ) => Promise<LroResponse<T>>;
38
-
39
- export function createPollingMethod<TResult>(
40
- sendOperationFn: SendOperationFn<TResult>,
41
- GetLroStatusFromResponse: GetLroStatusFromResponse<TResult>,
42
- args: OperationArguments,
43
- spec: OperationSpec,
44
- mode?: LroMode
45
- ): (path?: string) => Promise<LroStatus<TResult>> {
46
- /**
47
- * Polling calls will always return a status object i.e. {"status": "success"}
48
- * these intermediate responses are not described in the swagger so we need to
49
- * pass custom mappers at runtime.
50
- * This function replaces all the existing mappers to be able to deserialize a status object
51
- * @param responses Original set of responses defined in the operation
52
- */
53
- function getCompositeMappers(responses: {
54
- [responseCode: string]: OperationResponseMap;
55
- }): {
56
- [responseCode: string]: OperationResponseMap;
57
- } {
58
- return Object.keys(responses).reduce((acc, statusCode) => {
59
- return {
60
- ...acc,
61
- [statusCode]: {
62
- ...responses[statusCode],
63
- bodyMapper: {
64
- type: {
65
- name: "Composite",
66
- modelProperties: {
67
- status: {
68
- serializedName: "status",
69
- type: {
70
- name: "String"
71
- }
72
- }
73
- }
74
- }
75
- }
76
- }
77
- };
78
- }, {} as { [responseCode: string]: OperationResponseMap });
79
- }
80
- let response: LroStatus<TResult> | undefined = undefined;
81
- const customerCallback = args?.options?.onResponse;
82
- const updatedArgs = {
83
- ...args,
84
- options: {
85
- ...args.options,
86
- onResponse: (
87
- rawResponse: FullOperationResponse,
88
- flatResponse: unknown
89
- ): void => {
90
- response = GetLroStatusFromResponse(
91
- {
92
- statusCode: rawResponse.status,
93
- body: rawResponse.parsedBody,
94
- headers: rawResponse.headers.toJSON()
95
- },
96
- flatResponse as TResult
97
- );
98
- if (response.done) {
99
- customerCallback?.(rawResponse, flatResponse);
100
- }
101
- }
102
- }
103
- };
104
- // Make sure we don't send any body to the get request
105
- const { requestBody, responses, ...restSpec } = spec;
106
- if (mode === "AzureAsync") {
107
- return async (path?: string) => {
108
- await sendOperationFn(updatedArgs, {
109
- ...restSpec,
110
- responses: getCompositeMappers(responses),
111
- httpMethod: "GET",
112
- ...(path && { path })
113
- });
114
- return response!;
115
- };
116
- }
117
- return async (path?: string) => {
118
- await sendOperationFn(updatedArgs, {
119
- ...restSpec,
120
- responses: responses,
121
- httpMethod: "GET",
122
- ...(path && { path })
123
- });
124
- return response!;
125
- };
126
- }
127
-
128
- /**
129
- * We need to selectively deserialize our responses, only deserializing if we
130
- * are in a final Lro response, not deserializing any polling non-terminal responses
131
- */
132
- export function shouldDeserializeLro(lroResourceLocationConfig?: string) {
133
- let initialOperationInfo: LroResponseInfo | undefined;
134
- let isInitialRequest = true;
135
-
136
- return (response: FullOperationResponse) => {
137
- if (response.status < 200 || response.status >= 300) {
138
- return true;
139
- }
140
-
141
- if (!initialOperationInfo) {
142
- initialOperationInfo = getLroData(response);
143
- } else {
144
- isInitialRequest = false;
145
- }
146
-
147
- if (
148
- initialOperationInfo.azureAsyncOperation ||
149
- initialOperationInfo.operationLocation
150
- ) {
151
- return (
152
- !isInitialRequest &&
153
- isAsyncOperationFinalResponse(
154
- response,
155
- initialOperationInfo,
156
- lroResourceLocationConfig
157
- )
158
- );
159
- }
160
-
161
- if (initialOperationInfo.location) {
162
- return isLocationFinalResponse(response);
163
- }
164
-
165
- if (initialOperationInfo.requestMethod === "PUT") {
166
- return isBodyPollingFinalResponse(response);
167
- }
168
-
169
- return true;
170
- };
171
- }
172
-
173
- function isAsyncOperationFinalResponse(
174
- response: FullOperationResponse,
175
- initialOperationInfo: LroResponseInfo,
176
- lroResourceLocationConfig?: string
177
- ): boolean {
178
- const status: string = response.parsedBody?.status || "Succeeded";
179
- if (!terminalStates.includes(status.toLowerCase())) {
180
- return false;
181
- }
182
-
183
- if (initialOperationInfo.requestMethod === "DELETE") {
184
- return true;
185
- }
186
-
187
- if (
188
- initialOperationInfo.requestMethod === "PUT" &&
189
- lroResourceLocationConfig &&
190
- lroResourceLocationConfig.toLowerCase() === "azure-asyncoperation"
191
- ) {
192
- return true;
193
- }
194
-
195
- if (
196
- initialOperationInfo.requestMethod !== "PUT" &&
197
- !initialOperationInfo.location
198
- ) {
199
- return true;
200
- }
201
-
202
- return false;
203
- }
204
-
205
- function isLocationFinalResponse(response: FullOperationResponse): boolean {
206
- return response.status !== 202;
207
- }
208
-
209
- function isBodyPollingFinalResponse(response: FullOperationResponse): boolean {
210
- const provisioningState: string =
211
- response.parsedBody?.properties?.provisioningState || "Succeeded";
212
-
213
- if (terminalStates.includes(provisioningState.toLowerCase())) {
214
- return true;
215
- }
216
-
217
- return false;
218
- }
219
-
220
- interface LroResponseInfo {
221
- requestMethod: string;
222
- azureAsyncOperation?: string;
223
- operationLocation?: string;
224
- location?: string;
225
- }
226
-
227
- function getLroData(result: FullOperationResponse): LroResponseInfo {
228
- return {
229
- azureAsyncOperation: result.headers.get("azure-asyncoperation"),
230
- operationLocation: result.headers.get("operation-location"),
231
- location: result.headers.get("location"),
232
- requestMethod: result.request.method
233
- };
234
- }
235
-
236
- export function getSpecPath(spec: OperationSpec): string {
237
- if (spec.path) {
238
- return spec.path;
239
- } else {
240
- throw Error("Bad spec: request path is not found!");
241
- }
242
- }
243
-
244
- export class CoreClientLro<T> implements LongRunningOperation<T> {
245
- constructor(
246
- private sendOperationFn: SendOperationFn<T>,
247
- private args: OperationArguments,
248
- private spec: OperationSpec,
249
- private lroResourceLocationConfig?: LroResourceLocationConfig,
250
- public requestPath: string = spec.path!,
251
- public requestMethod: string = spec.httpMethod
252
- ) {}
253
- public async sendInitialRequest(
254
- initializeState: (
255
- rawResponse: RawResponse,
256
- flatResponse: unknown
257
- ) => boolean
258
- ): Promise<LroResponse<T>> {
259
- const { onResponse, ...restOptions } = this.args.options || {};
260
- return this.sendOperationFn(
261
- {
262
- ...this.args,
263
- options: {
264
- ...restOptions,
265
- onResponse: (
266
- rawResponse: FullOperationResponse,
267
- flatResponse: unknown
268
- ) => {
269
- const isCompleted = initializeState(
270
- {
271
- statusCode: rawResponse.status,
272
- body: rawResponse.parsedBody,
273
- headers: rawResponse.headers.toJSON()
274
- },
275
- flatResponse
276
- );
277
- if (isCompleted) {
278
- onResponse?.(rawResponse, flatResponse);
279
- }
280
- }
281
- }
282
- },
283
- this.spec
284
- );
285
- }
286
-
287
- public async sendPollRequest(
288
- config: LroConfig,
289
- path: string
290
- ): Promise<LroStatus<T>> {
291
- const getLroStatusFromResponse = createGetLroStatusFromResponse(
292
- this,
293
- config,
294
- this.lroResourceLocationConfig
295
- );
296
- return createPollingMethod(
297
- this.sendOperationFn,
298
- getLroStatusFromResponse,
299
- this.args,
300
- this.spec,
301
- config.mode
302
- )(path);
303
- }
304
-
305
- public async retrieveAzureAsyncResource(
306
- path?: string
307
- ): Promise<LroResponse<T>> {
308
- const updatedArgs = { ...this.args };
309
- if (updatedArgs.options) {
310
- (updatedArgs.options as any).shouldDeserialize = true;
311
- }
312
- return createPollingMethod(
313
- this.sendOperationFn,
314
- (rawResponse, flatResponse) => ({
315
- rawResponse,
316
- flatResponse,
317
- done: true
318
- }),
319
- updatedArgs,
320
- this.spec
321
- )(path);
322
- }
323
- }
@@ -1,96 +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 {
13
- failureStates,
14
- LroResourceLocationConfig,
15
- LongRunningOperation,
16
- LroBody,
17
- LroResponse,
18
- LroStatus,
19
- RawResponse,
20
- successStates
21
- } from "./models";
22
- import { isUnexpectedPollingResponse } from "./requestUtils";
23
-
24
- function getResponseStatus(rawResponse: RawResponse): string {
25
- const { status } = (rawResponse.body as LroBody) ?? {};
26
- return status?.toLowerCase() ?? "succeeded";
27
- }
28
-
29
- function isAzureAsyncPollingDone(rawResponse: RawResponse): boolean {
30
- const state = getResponseStatus(rawResponse);
31
- if (
32
- isUnexpectedPollingResponse(rawResponse) ||
33
- failureStates.includes(state)
34
- ) {
35
- throw new Error(`Operation status: ${state}`);
36
- }
37
- return successStates.includes(state);
38
- }
39
-
40
- async function sendFinalRequest<TResult>(
41
- lro: LongRunningOperation<TResult>,
42
- lroResourceLocationConfig?: LroResourceLocationConfig,
43
- resourceLocation?: string
44
- ): Promise<LroResponse<TResult> | undefined> {
45
- switch (lroResourceLocationConfig) {
46
- case "original-uri":
47
- return lro.retrieveAzureAsyncResource();
48
- case "azure-async-operation":
49
- return Promise.resolve(undefined);
50
- case "location":
51
- default:
52
- return lro.retrieveAzureAsyncResource(resourceLocation);
53
- }
54
- }
55
-
56
- export function processAzureAsyncOperationResult<TResult>(
57
- lro: LongRunningOperation<TResult>,
58
- resourceLocation?: string,
59
- lroResourceLocationConfig?: LroResourceLocationConfig
60
- ): (rawResponse: RawResponse, flatResponse: TResult) => LroStatus<TResult> {
61
- return (
62
- rawResponse: RawResponse,
63
- flatResponse: TResult
64
- ): LroStatus<TResult> => {
65
- if (isAzureAsyncPollingDone(rawResponse)) {
66
- if (resourceLocation === undefined) {
67
- return { rawResponse, flatResponse, done: true };
68
- } else {
69
- return {
70
- rawResponse,
71
- flatResponse,
72
- done: false,
73
- next: async () => {
74
- const finalResponse = await sendFinalRequest(
75
- lro,
76
- lroResourceLocationConfig,
77
- resourceLocation
78
- );
79
- return {
80
- ...(finalResponse ?? {
81
- rawResponse,
82
- flatResponse
83
- }),
84
- done: true
85
- };
86
- }
87
- };
88
- }
89
- }
90
- return {
91
- rawResponse,
92
- flatResponse,
93
- done: false
94
- };
95
- };
96
- }
@@ -1,54 +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 {
13
- failureStates,
14
- LroBody,
15
- LroStatus,
16
- RawResponse,
17
- successStates
18
- } from "./models";
19
- import { isUnexpectedPollingResponse } from "./requestUtils";
20
-
21
- function getProvisioningState(rawResponse: RawResponse): string {
22
- const { properties, provisioningState } = (rawResponse.body as LroBody) ?? {};
23
- const state: string | undefined =
24
- properties?.provisioningState ?? provisioningState;
25
- return state?.toLowerCase() ?? "succeeded";
26
- }
27
-
28
- export function isBodyPollingDone(rawResponse: RawResponse): boolean {
29
- const state = getProvisioningState(rawResponse);
30
- if (
31
- isUnexpectedPollingResponse(rawResponse) ||
32
- failureStates.includes(state)
33
- ) {
34
- throw new Error(
35
- `The long running operation has failed. The provisioning state: ${state}.`
36
- );
37
- }
38
- return successStates.includes(state);
39
- }
40
-
41
- /**
42
- * Creates a polling strategy based on BodyPolling which uses the provisioning state
43
- * from the result to determine the current operation state
44
- */
45
- export function processBodyPollingOperationResult<TResult>(
46
- rawResponse: RawResponse,
47
- flatResponse: TResult
48
- ): LroStatus<TResult> {
49
- return {
50
- rawResponse,
51
- flatResponse,
52
- done: isBodyPollingDone(rawResponse)
53
- };
54
- }
package/src/lro/index.ts DELETED
@@ -1,26 +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
- export { LroEngine } from "./lroEngine";
13
- export { createGetLroStatusFromResponse } from "./stateMachine";
14
- export {
15
- LroResourceLocationConfig,
16
- GetLroStatusFromResponse,
17
- RawResponse,
18
- LongRunningOperation,
19
- LroConfig,
20
- LroMode,
21
- LroResponse,
22
- LroStatus,
23
- LroTerminalState,
24
- LroInProgressState,
25
- LroEngineOptions
26
- } from "./models";
@@ -1,30 +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
- import { isUnexpectedPollingResponse } from "./requestUtils";
14
-
15
- function isLocationPollingDone(rawResponse: RawResponse): boolean {
16
- return (
17
- !isUnexpectedPollingResponse(rawResponse) && rawResponse.statusCode !== 202
18
- );
19
- }
20
-
21
- export function processLocationPollingOperationResult<TResult>(
22
- rawResponse: RawResponse,
23
- flatResponse: TResult
24
- ): LroStatus<TResult> {
25
- return {
26
- rawResponse,
27
- flatResponse,
28
- done: isLocationPollingDone(rawResponse)
29
- };
30
- }
@@ -1,61 +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 { Poller, PollOperationState } from "@azure/core-lro";
13
- import {
14
- LongRunningOperation,
15
- LroEngineOptions,
16
- ResumablePollOperationState
17
- } from "./models";
18
- import { GenericPollOperation } from "./operation";
19
-
20
- /**
21
- * The LRO Engine, a class that performs polling.
22
- */
23
- export class LroEngine<
24
- TResult,
25
- TState extends PollOperationState<TResult>
26
- > extends Poller<TState, TResult> {
27
- private intervalInMs: number;
28
-
29
- constructor(lro: LongRunningOperation<TResult>, options?: LroEngineOptions) {
30
- const { intervalInMs = 2000, resumeFrom } = options || {};
31
- function deserializeState(
32
- resumeFrom: string
33
- ): TState & ResumablePollOperationState<TResult> {
34
- try {
35
- return JSON.parse(resumeFrom).state;
36
- } catch (e) {
37
- throw new Error(
38
- `LroEngine: Unable to deserialize state: ${resumeFrom}`
39
- );
40
- }
41
- }
42
- const state: TState & ResumablePollOperationState<TResult> = resumeFrom
43
- ? deserializeState(resumeFrom)
44
- : ({} as any);
45
-
46
- const operation = new GenericPollOperation(state, lro);
47
- super(operation);
48
-
49
- this.intervalInMs = intervalInMs;
50
- operation.setPollerConfig(this as any);
51
- }
52
-
53
- /**
54
- * The method used by the poller to wait before attempting to update its operation.
55
- */
56
- delay(): Promise<void> {
57
- return new Promise((resolve) =>
58
- setTimeout(() => resolve(), this.intervalInMs)
59
- );
60
- }
61
- }