@azure/arm-managedapplications 1.1.0 → 2.0.0-beta.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 (160) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/{LICENSE.txt → LICENSE} +2 -2
  3. package/README.md +63 -80
  4. package/dist/index.js +2896 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.min.js +1 -0
  7. package/dist/index.min.js.map +1 -0
  8. package/esm/applicationClient.d.ts +50 -0
  9. package/esm/applicationClient.d.ts.map +1 -0
  10. package/esm/applicationClient.js +190 -0
  11. package/esm/applicationClient.js.map +1 -0
  12. package/esm/applicationClientContext.d.ts +16 -0
  13. package/esm/applicationClientContext.d.ts.map +1 -0
  14. package/esm/applicationClientContext.js +49 -0
  15. package/esm/applicationClientContext.js.map +1 -0
  16. package/esm/coreClientLro.d.ts +26 -0
  17. package/esm/coreClientLro.d.ts.map +1 -0
  18. package/esm/coreClientLro.js +186 -0
  19. package/esm/coreClientLro.js.map +1 -0
  20. package/esm/index.d.ts +770 -0
  21. package/esm/index.d.ts.map +1 -0
  22. package/esm/index.js +13 -0
  23. package/esm/index.js.map +1 -0
  24. package/esm/lro/azureAsyncPolling.d.ts +3 -0
  25. package/esm/lro/azureAsyncPolling.d.ts.map +1 -0
  26. package/esm/lro/azureAsyncPolling.js +67 -0
  27. package/esm/lro/azureAsyncPolling.js.map +1 -0
  28. package/esm/lro/bodyPolling.d.ts +8 -0
  29. package/esm/lro/bodyPolling.d.ts.map +1 -0
  30. package/esm/lro/bodyPolling.js +37 -0
  31. package/esm/lro/bodyPolling.js.map +1 -0
  32. package/esm/lro/index.d.ts +4 -0
  33. package/esm/lro/index.d.ts.map +1 -0
  34. package/esm/lro/index.js +12 -0
  35. package/esm/lro/index.js.map +1 -0
  36. package/esm/lro/locationPolling.d.ts +3 -0
  37. package/esm/lro/locationPolling.d.ts.map +1 -0
  38. package/esm/lro/locationPolling.js +19 -0
  39. package/esm/lro/locationPolling.js.map +1 -0
  40. package/esm/lro/lroEngine.d.ts +14 -0
  41. package/esm/lro/lroEngine.d.ts.map +1 -0
  42. package/esm/lro/lroEngine.js +41 -0
  43. package/esm/lro/lroEngine.js.map +1 -0
  44. package/esm/lro/models.d.ts +138 -0
  45. package/esm/lro/models.d.ts.map +1 -0
  46. package/esm/lro/models.js +14 -0
  47. package/esm/lro/models.js.map +1 -0
  48. package/esm/lro/operation.d.ts +36 -0
  49. package/esm/lro/operation.d.ts.map +1 -0
  50. package/esm/lro/operation.js +82 -0
  51. package/esm/lro/operation.js.map +1 -0
  52. package/esm/lro/passthrough.d.ts +3 -0
  53. package/esm/lro/passthrough.d.ts.map +1 -0
  54. package/esm/lro/passthrough.js +15 -0
  55. package/esm/lro/passthrough.js.map +1 -0
  56. package/esm/lro/requestUtils.d.ts +16 -0
  57. package/esm/lro/requestUtils.d.ts.map +1 -0
  58. package/esm/lro/requestUtils.js +73 -0
  59. package/esm/lro/requestUtils.js.map +1 -0
  60. package/esm/lro/stateMachine.d.ts +18 -0
  61. package/esm/lro/stateMachine.d.ts.map +1 -0
  62. package/esm/lro/stateMachine.js +84 -0
  63. package/esm/lro/stateMachine.js.map +1 -0
  64. package/esm/models/index.d.ts +360 -762
  65. package/esm/models/index.d.ts.map +1 -1
  66. package/esm/models/index.js +17 -2
  67. package/esm/models/index.js.map +1 -1
  68. package/esm/models/mappers.d.ts +18 -20
  69. package/esm/models/mappers.d.ts.map +1 -1
  70. package/esm/models/mappers.js +296 -318
  71. package/esm/models/mappers.js.map +1 -1
  72. package/esm/models/parameters.d.ts +15 -10
  73. package/esm/models/parameters.d.ts.map +1 -1
  74. package/esm/models/parameters.js +77 -49
  75. package/esm/models/parameters.js.map +1 -1
  76. package/esm/operations/applicationDefinitions.d.ts +128 -0
  77. package/esm/operations/applicationDefinitions.d.ts.map +1 -0
  78. package/esm/operations/applicationDefinitions.js +574 -0
  79. package/esm/operations/applicationDefinitions.js.map +1 -0
  80. package/esm/operations/applications.d.ts +182 -0
  81. package/esm/operations/applications.d.ts.map +1 -0
  82. package/esm/operations/applications.js +802 -0
  83. package/esm/operations/applications.js.map +1 -0
  84. package/esm/operations/index.d.ts +2 -2
  85. package/esm/operations/index.d.ts.map +1 -1
  86. package/esm/operations/index.js +5 -7
  87. package/esm/operations/index.js.map +1 -1
  88. package/esm/operationsInterfaces/applicationDefinitions.d.ts +95 -0
  89. package/esm/operationsInterfaces/applicationDefinitions.d.ts.map +1 -0
  90. package/esm/operationsInterfaces/applicationDefinitions.js +9 -0
  91. package/esm/operationsInterfaces/applicationDefinitions.js.map +1 -0
  92. package/esm/operationsInterfaces/applications.d.ts +128 -0
  93. package/esm/operationsInterfaces/applications.d.ts.map +1 -0
  94. package/esm/operationsInterfaces/applications.js +9 -0
  95. package/esm/operationsInterfaces/applications.js.map +1 -0
  96. package/esm/operationsInterfaces/index.d.ts +3 -0
  97. package/esm/operationsInterfaces/index.d.ts.map +1 -0
  98. package/esm/operationsInterfaces/index.js +10 -0
  99. package/esm/operationsInterfaces/index.js.map +1 -0
  100. package/package.json +55 -16
  101. package/review/arm-managedapplications.api.md +443 -0
  102. package/rollup.config.js +181 -30
  103. package/src/applicationClient.ts +222 -0
  104. package/src/applicationClientContext.ts +70 -0
  105. package/src/coreClientLro.ts +323 -0
  106. package/src/index.ts +13 -0
  107. package/src/lro/azureAsyncPolling.ts +96 -0
  108. package/src/lro/bodyPolling.ts +54 -0
  109. package/src/lro/index.ts +26 -0
  110. package/src/lro/locationPolling.ts +30 -0
  111. package/src/lro/lroEngine.ts +61 -0
  112. package/src/lro/models.ts +173 -0
  113. package/src/lro/operation.ts +120 -0
  114. package/src/lro/passthrough.ts +23 -0
  115. package/src/lro/requestUtils.ts +105 -0
  116. package/src/lro/stateMachine.ts +138 -0
  117. package/src/models/index.ts +402 -794
  118. package/src/models/mappers.ts +290 -311
  119. package/src/models/parameters.ts +99 -50
  120. package/src/operations/applicationDefinitions.ts +810 -0
  121. package/src/operations/applications.ts +1069 -0
  122. package/src/operations/index.ts +5 -7
  123. package/src/operationsInterfaces/applicationDefinitions.ts +179 -0
  124. package/src/operationsInterfaces/applications.ts +225 -0
  125. package/src/operationsInterfaces/index.ts +10 -0
  126. package/tsconfig.json +3 -2
  127. package/dist/arm-managedapplications.js +0 -1865
  128. package/dist/arm-managedapplications.js.map +0 -1
  129. package/dist/arm-managedapplications.min.js +0 -1
  130. package/dist/arm-managedapplications.min.js.map +0 -1
  131. package/esm/managedApplicationClient.d.ts +0 -58
  132. package/esm/managedApplicationClient.d.ts.map +0 -1
  133. package/esm/managedApplicationClient.js +0 -92
  134. package/esm/managedApplicationClient.js.map +0 -1
  135. package/esm/managedApplicationClientContext.d.ts +0 -22
  136. package/esm/managedApplicationClientContext.d.ts.map +0 -1
  137. package/esm/managedApplicationClientContext.js +0 -61
  138. package/esm/managedApplicationClientContext.js.map +0 -1
  139. package/esm/models/applianceDefinitionsMappers.d.ts +0 -2
  140. package/esm/models/applianceDefinitionsMappers.d.ts.map +0 -1
  141. package/esm/models/applianceDefinitionsMappers.js +0 -9
  142. package/esm/models/applianceDefinitionsMappers.js.map +0 -1
  143. package/esm/models/appliancesMappers.d.ts +0 -2
  144. package/esm/models/appliancesMappers.d.ts.map +0 -1
  145. package/esm/models/appliancesMappers.js +0 -9
  146. package/esm/models/appliancesMappers.js.map +0 -1
  147. package/esm/operations/applianceDefinitions.d.ts +0 -167
  148. package/esm/operations/applianceDefinitions.d.ts.map +0 -1
  149. package/esm/operations/applianceDefinitions.js +0 -358
  150. package/esm/operations/applianceDefinitions.js.map +0 -1
  151. package/esm/operations/appliances.d.ts +0 -247
  152. package/esm/operations/appliances.d.ts.map +0 -1
  153. package/esm/operations/appliances.js +0 -482
  154. package/esm/operations/appliances.js.map +0 -1
  155. package/src/managedApplicationClient.ts +0 -144
  156. package/src/managedApplicationClientContext.ts +0 -68
  157. package/src/models/applianceDefinitionsMappers.ts +0 -24
  158. package/src/models/appliancesMappers.ts +0 -24
  159. package/src/operations/applianceDefinitions.ts +0 -492
  160. package/src/operations/appliances.ts +0 -716
@@ -0,0 +1,96 @@
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
+ }
@@ -0,0 +1,54 @@
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
+ }
@@ -0,0 +1,26 @@
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";
@@ -0,0 +1,30 @@
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
+ }
@@ -0,0 +1,61 @@
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
+ }
@@ -0,0 +1,173 @@
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
+ }
@@ -0,0 +1,120 @@
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
+ }
@@ -0,0 +1,23 @@
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
+ }
@@ -0,0 +1,105 @@
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
+ }