@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/.tshy/esm.json
DELETED
package/.tshy/react-native.json
DELETED
package/CHANGELOG.md
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
# Release History
|
|
2
|
-
|
|
3
|
-
## 3.0.0-beta.1 (2024-02-25)
|
|
4
|
-
|
|
5
|
-
Initial implementation of next-generation for Long Running Operations (LROs) in which we deprecate the `LroEngine` support and change poller creation to a synchronized way.
|
|
6
|
-
|
|
7
|
-
- `LroEngine` is deprecated and no long supported
|
|
8
|
-
- The return type of `createHttpPoller` is changed from `Promise<SimplePollerLike>` to `PollerLike`
|
|
9
|
-
- Some interfaces are renamed. `SimplePollerLike` is renamed as `PollerLike`, `LroResponse` is renamed as `OperationResponse` and `LroResourceLocationConfig` is to `ResourceLocationConfig`
|
|
10
|
-
- Functions `getOperationState()`, `getResult()`, `isDone()` and `isStopped()` is changed to read-only attributes `operationState`, `result`, `isDone` and `isStopped`
|
|
11
|
-
- Deprecated the attributes `requestMethod` and `requestPath` in `LongRunningOperation`
|
|
12
|
-
- Added a new function `serialize` to help serialize the poller
|
|
13
|
-
- Added a new function `submitted` to help wait for the poller submitted succesffully
|
|
14
|
-
- Added a new parameter `TRequest` for `OperationResponse` to accept the raw request
|
|
15
|
-
- Export the function `deserializeState` to the public
|
|
16
|
-
|
|
17
|
-
## 2.6.0 (2024-02-01)
|
|
18
|
-
|
|
19
|
-
### Other Changes
|
|
20
|
-
|
|
21
|
-
- Search for the `resourceLocation` property in the raw response body if it cannot be found in the parsed response body.
|
|
22
|
-
- Upgrade dependency `@azure/abort-controller` version to `^2.0.0`.
|
|
23
|
-
|
|
24
|
-
## 2.5.4 (2023-07-24)
|
|
25
|
-
|
|
26
|
-
### Bugs Fixed
|
|
27
|
-
|
|
28
|
-
- Support non-standard PATCH operations.
|
|
29
|
-
|
|
30
|
-
## 2.5.3 (2023-05-04)
|
|
31
|
-
|
|
32
|
-
### Other Changes
|
|
33
|
-
|
|
34
|
-
- Include detailed error information in failed polling error messages.
|
|
35
|
-
|
|
36
|
-
## 2.5.2 (2023-04-06)
|
|
37
|
-
|
|
38
|
-
### Bugs Fixed
|
|
39
|
-
|
|
40
|
-
- Change the logging level for unrecognized operation statuses from warning to verbose.
|
|
41
|
-
|
|
42
|
-
## 2.5.1 (2023-02-02)
|
|
43
|
-
|
|
44
|
-
### Bugs Fixed
|
|
45
|
-
|
|
46
|
-
- The operation will be considered failed when an HTTP response error is received and not when any arbitrary error is raised.
|
|
47
|
-
|
|
48
|
-
## 2.5.0 (2023-01-10)
|
|
49
|
-
|
|
50
|
-
### Other Changes
|
|
51
|
-
|
|
52
|
-
- poll() is optimized to no longer send a polling request if the operation is already in a terminal state.
|
|
53
|
-
|
|
54
|
-
## 2.4.0 (2022-09-29)
|
|
55
|
-
|
|
56
|
-
### Features Added
|
|
57
|
-
|
|
58
|
-
- Add `resolveOnUnsuccessful` to `CreateHttpPollerOptions` and `LroEngineOptions` to control whether to throw an error if the operation failed or was canceled.
|
|
59
|
-
|
|
60
|
-
### Bugs Fixed
|
|
61
|
-
|
|
62
|
-
- Precisely detect when an operation failed without relying on exceptions raised by the underlying core library.
|
|
63
|
-
- Handle bad status fields.
|
|
64
|
-
|
|
65
|
-
## 2.3.1 (2022-09-09)
|
|
66
|
-
|
|
67
|
-
### Bugs Fixed
|
|
68
|
-
|
|
69
|
-
- Add missing support for fetching resources linked to in the body of the final polling response.
|
|
70
|
-
|
|
71
|
-
## 2.3.0 (2022-09-01)
|
|
72
|
-
|
|
73
|
-
### Features Added
|
|
74
|
-
|
|
75
|
-
- Provides `createHttpPoller` which creates a simple poller that can work out of the box for most Azure long-running operations.
|
|
76
|
-
- Deprecates `cancelOperation` in `PollerLike` because not every operation supports cancellation.
|
|
77
|
-
|
|
78
|
-
## 2.2.5 (2022-08-08)
|
|
79
|
-
|
|
80
|
-
### Bugs Fixed
|
|
81
|
-
|
|
82
|
-
- `LroEngine` no longer throws an error when it receives a 204 polling response.
|
|
83
|
-
|
|
84
|
-
### Other Changes
|
|
85
|
-
|
|
86
|
-
- Support LROs with GET as the initial request method.
|
|
87
|
-
- Better logging support for the operation and the poller.
|
|
88
|
-
- Removed the unused dependency `@azure/core-tracing`.
|
|
89
|
-
|
|
90
|
-
## 2.3.0-beta.1 (2022-05-18)
|
|
91
|
-
|
|
92
|
-
### Features Added
|
|
93
|
-
|
|
94
|
-
- `lroEngine` now supports cancellation of the long-running operation.
|
|
95
|
-
|
|
96
|
-
### Other Changes
|
|
97
|
-
|
|
98
|
-
- Removed the unused dependency `@azure/core-tracing`.
|
|
99
|
-
|
|
100
|
-
## 2.2.4 (2022-03-07)
|
|
101
|
-
|
|
102
|
-
### Bugs Fixed
|
|
103
|
-
|
|
104
|
-
- Fix polling so that resources created in a different URL will be retrieved once polling is done. [PR #20656](https://github.com/Azure/azure-sdk-for-js/pull/20656)
|
|
105
|
-
|
|
106
|
-
## 2.2.3 (2022-01-06)
|
|
107
|
-
|
|
108
|
-
### Bugs Fixed
|
|
109
|
-
|
|
110
|
-
- Fix an issue where we treat Retry-After value as milliseconds. It is actually in seconds. [PR #19479](https://github.com/Azure/azure-sdk-for-js/pull/19479)
|
|
111
|
-
|
|
112
|
-
## 2.2.2 (2021-12-02)
|
|
113
|
-
|
|
114
|
-
### Bugs Fixed
|
|
115
|
-
|
|
116
|
-
- Fix LRO PATCH operations when their results are located in a different URL. [PR #18820](https://github.com/Azure/azure-sdk-for-js/pull/18820)
|
|
117
|
-
|
|
118
|
-
## 2.2.1 (2021-09-30)
|
|
119
|
-
|
|
120
|
-
### Bugs Fixed
|
|
121
|
-
|
|
122
|
-
- Check for string type before calling toLowerCase(). [PR #17573](https://github.com/Azure/azure-sdk-for-js/pull/17573)
|
|
123
|
-
|
|
124
|
-
### Other Changes
|
|
125
|
-
|
|
126
|
-
- Updates package to work with the react native bundler. [PR #17783](https://github.com/Azure/azure-sdk-for-js/pull/17783)
|
|
127
|
-
|
|
128
|
-
## 2.2.0 (2021-08-05)
|
|
129
|
-
|
|
130
|
-
### Features Added
|
|
131
|
-
|
|
132
|
-
- `LroEngine` supports a new `isDone()` function in its options bag which can be used to provide a custom logic for determining when an LRO finished processing.
|
|
133
|
-
|
|
134
|
-
## 2.1.0 (2021-07-19)
|
|
135
|
-
|
|
136
|
-
### Features Added
|
|
137
|
-
|
|
138
|
-
- Provides a long-running operation engine.
|
|
139
|
-
|
|
140
|
-
## 2.0.0 (2021-06-30)
|
|
141
|
-
|
|
142
|
-
### New Features
|
|
143
|
-
|
|
144
|
-
- Changed TS compilation target to ES2017 in order to produce smaller bundles and use more native platform features
|
|
145
|
-
|
|
146
|
-
## 1.0.5 (2021-04-12)
|
|
147
|
-
|
|
148
|
-
- No functionality changes from 1.0.4. This release is to correct an issue where 1.0.4 shipped with modules in the wrong format (cjs instead of es6.)
|
|
149
|
-
|
|
150
|
-
## 1.0.4 (2021-03-30)
|
|
151
|
-
|
|
152
|
-
- Bug fix: Fix an issue where we might return stale state if the `update` implementation reassigns `operation.state`.
|
|
153
|
-
|
|
154
|
-
### Breaking Changes
|
|
155
|
-
|
|
156
|
-
- Updated @azure/core-tracing to version `1.0.0-preview.11`. See [@azure/core-tracing CHANGELOG](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-tracing/CHANGELOG.md) for details about breaking changes with tracing.
|
|
157
|
-
|
|
158
|
-
## 1.0.3 (2021-01-07)
|
|
159
|
-
|
|
160
|
-
- Updates the `tslib` dependency to version 2.x.
|
|
161
|
-
|
|
162
|
-
## 1.0.2 (2020-04-28)
|
|
163
|
-
|
|
164
|
-
- Moved `@opentelemetry/types` to the `devDependencies`.
|
|
165
|
-
|
|
166
|
-
## 1.0.1 (2020-02-28)
|
|
167
|
-
|
|
168
|
-
- `getOperationState()` now returns `TState`.
|
|
169
|
-
- `TState` of `PollerLike` can be a subset of `TState` of `Poller`,
|
|
170
|
-
|
|
171
|
-
## 1.0.0 (2019-10-29)
|
|
172
|
-
|
|
173
|
-
This release marks the general availability of the `@azure/core-lro` package.
|
|
174
|
-
|
|
175
|
-
- Updated PollOperation to be more strictly typed.
|
|
176
|
-
|
|
177
|
-
## 1.0.0-preview.1 (2019-10-22)
|
|
178
|
-
|
|
179
|
-
- Initial implementation of an abstraction for Long Running Operations (LROs).
|
package/api-extractor.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
-
"mainEntryPointFilePath": "dist/esm/index.d.ts",
|
|
4
|
-
"docModel": {
|
|
5
|
-
"enabled": true
|
|
6
|
-
},
|
|
7
|
-
"apiReport": {
|
|
8
|
-
"enabled": true,
|
|
9
|
-
"reportFolder": "./review"
|
|
10
|
-
},
|
|
11
|
-
"dtsRollup": {
|
|
12
|
-
"enabled": true,
|
|
13
|
-
"untrimmedFilePath": "",
|
|
14
|
-
"publicTrimmedFilePath": "./dist/core-lro.d.ts"
|
|
15
|
-
},
|
|
16
|
-
"messages": {
|
|
17
|
-
"tsdocMessageReporting": {
|
|
18
|
-
"default": {
|
|
19
|
-
"logLevel": "none"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"extractorMessageReporting": {
|
|
23
|
-
"ae-missing-release-tag": {
|
|
24
|
-
"logLevel": "none"
|
|
25
|
-
},
|
|
26
|
-
"ae-unresolved-link": {
|
|
27
|
-
"logLevel": "none"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
package/config/rush-project.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[31mUnable to include "dist/node_modules/@azure/core-lro" in build cache. It is a symbolic link.[39m
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
This project does not define the caching behavior of the "build:samples" command, so caching has been disabled.
|
package/core-lro.pack.cache.log
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
This project does not define the caching behavior of the "pack" command, so caching has been disabled.
|
package/core-lro.pack.log
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Invoking: npm pack 2>&1
|
package/docs/LROEngine.md
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
# Modular Support for Long-Running Operations
|
|
2
|
-
|
|
3
|
-
Long-running operations (LROs) are operations that the service _could_ take a long time to finish processing and they follow a common convention:
|
|
4
|
-
|
|
5
|
-
- the customer first send an initiation request to the service, which in turn sends back a response, from which the customer can learn how to poll for the status of the operation, if it has not been completed already,
|
|
6
|
-
- using their learnings, the customer polls the status of the operation until it is done,
|
|
7
|
-
- again, using their learnings, the customer can now get the desired result of the operation once its status says it is done.
|
|
8
|
-
|
|
9
|
-
Ideally, we can write an algorithm that implements this convention once and use it in all Azure clients for LRO APIs, however, in reality, this convention is implemented differently across Azure services. The good news is that the TypeScript Autorest extension is AFAIK able to generate code that implements those different ones, but this implementation has a couple of limitations:
|
|
10
|
-
|
|
11
|
-
1. it is located in a few files that the code generator copies into every generated package that has LROs. So if in the future there is a bug fix needed in the LRO logic, the package has to be regenerated with the fix.
|
|
12
|
-
2. it works only with clients that use `@azure/core-client`, so clients that use `@azure-rest/core-client` or `@azure/core-http` can not use this implementation as-is.
|
|
13
|
-
|
|
14
|
-
To fix limitation #1, the most straightforward thing to do is to move those files into `@azure/core-lro`, but without fixing limitation #2 first, `@azure/core-lro` will have to depend on `@azure/core-client` in this case which will force clients that depend on `@azure/core-lro` but not necessarily depend on `@azure/core-client` to transitively depend on the latter, posing concerns about unnecessarily larger bundle sizes.
|
|
15
|
-
|
|
16
|
-
This document presents a design that fixes limitation #2 and naturally fixes limitation #1 too.
|
|
17
|
-
|
|
18
|
-
## Things to know before reading
|
|
19
|
-
|
|
20
|
-
- Some details not related to the high-level concept are not illustrated; the scope of this is limited to the high-level shape and paradigms for the feature area.
|
|
21
|
-
|
|
22
|
-
## Terminology
|
|
23
|
-
|
|
24
|
-
- **Azure Async Operation**, **Body**, and **Location** are names for the LRO implementations currently supported in the TypeScript Autorest extension. They vary in how to calculate the path to poll from, the algorithm for detecting whether the operation has finished, and the location to retrieve the desired results from. Currently, these pieces of information can be calculated from the response received after sending the initiation request.
|
|
25
|
-
|
|
26
|
-
## Why this is needed
|
|
27
|
-
|
|
28
|
-
The China team is currently waiting for fixing limitation #1 which they regard as a blocker for GAing the TypeScript Autorest extension. Furthermore, having this LRO implementation being part of `@azure/core-lro` and not tied to `@azure/core-client` will significantly help streamline the underway effort to add convenience helpers for LROs in `@azure-rest` clients.
|
|
29
|
-
|
|
30
|
-
## Design
|
|
31
|
-
|
|
32
|
-
This document presents a design of an LRO engine to be part of `@azure/core-lro` and could be used by any client regardless of how it is implemented. Furthermore, specific implementations of the engine are also provided to be auto-generated by Autorest.
|
|
33
|
-
|
|
34
|
-
The design consists of three main pieces:
|
|
35
|
-
|
|
36
|
-
- an interface, named `LongRunningOperation<T>` which groups various primitives needed to implement LROs
|
|
37
|
-
- a class, named `LroEngine`, that implements the LRO engine and its constructor takes as input an object that implements `LongRunningOperation<T>`
|
|
38
|
-
- a class that implement `LongRunningOperation<T>` that works with clients that use either `@azure/core-http` and `@azure/core-client`. @joheredi also created one for `@azure-rest/core-client` in https://github.com/Azure/azure-sdk-for-js/pull/15898
|
|
39
|
-
|
|
40
|
-
### `LongRunningOperation<T>`
|
|
41
|
-
|
|
42
|
-
This interface contains two methods: **sendInitialRequest** and **sendPollRequest**.
|
|
43
|
-
|
|
44
|
-
#### `sendInitialRequest`
|
|
45
|
-
|
|
46
|
-
This method should be implemented to send the initial request to start the operation and it has the following signature:
|
|
47
|
-
|
|
48
|
-
```ts
|
|
49
|
-
sendInitialRequest: () => Promise<LroResponse<T>>
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
The method does not take the path or the HTTP request method as parameters because they're members of the interface since they're needed to control many aspects of subsequent polling. This is how this method can be implemented:
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
public async sendInitialRequest(): Promise<LroResponse<T>> {
|
|
56
|
-
return this.sendOperation(this.args, this.spec); // the class will have sendOperation, args, and spec as private fields
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
#### `sendPollRequest`
|
|
61
|
-
|
|
62
|
-
This method should be implemented to send a polling (GET) request, a request the service should respond to with the current status of the operation, and it has the following signature:
|
|
63
|
-
|
|
64
|
-
```ts
|
|
65
|
-
sendPollRequest: (path: string) => Promise<LroResponse<T>>;
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
This method takes the polling path as input and here is what a simplified implementation would look like:
|
|
69
|
-
|
|
70
|
-
```ts
|
|
71
|
-
public async sendPollRequest(path: string): Promise<LroResponse<T>> {
|
|
72
|
-
return this.sendOperationFn(this.args, { // the class will have sendOperation, args, and spec as private fields
|
|
73
|
-
...this.spec,
|
|
74
|
-
path,
|
|
75
|
-
httpMethod: "GET")
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### `LroEngine`
|
|
81
|
-
|
|
82
|
-
This class implements the `PollerLike` interface and does the heavy lifting for LROs and has the following type signature:
|
|
83
|
-
|
|
84
|
-
```ts
|
|
85
|
-
class LroEngine<TResult, TState extends PollOperationState<TResult>> extends Poller<TState, TResult>
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
The class also has the following constructor:
|
|
89
|
-
|
|
90
|
-
```ts
|
|
91
|
-
constructor(lro: LongRunningOperation<TResult>, options?: LroEngineOptions);
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
Currently `options` have `intervalInMs` to control the polling interval, `resumeFrom` to enable resuming from a serialized state, and `lroResourceLocationConfig` which could determine where to find the results of the LRO after the operation is finished. Typically, Autorest figures out the value for `LroResourceLocationConfig` from the `x-ms-long-running-operation-options` swagger extension. If there are new arguments to be added to the class, they could be added to the options type.
|
|
95
|
-
|
|
96
|
-
### `LroImpl`
|
|
97
|
-
|
|
98
|
-
This class implements the `LongRunningOperation<T>` interface and is auto-generated by Autorest. `LroImpl` needs access to a few pieces: operation specification and operation arguments and a primitive function that can take them as input to send a request and converts the received response into one of type `LroResponse<T>` which has both the flattened and the raw responses.
|
|
99
|
-
|
|
100
|
-
## Usage examples
|
|
101
|
-
|
|
102
|
-
### Create an object of `LroImpl`
|
|
103
|
-
|
|
104
|
-
```ts
|
|
105
|
-
const directSendOperation = async (
|
|
106
|
-
args: OperationArguments,
|
|
107
|
-
spec: OperationSpec
|
|
108
|
-
): Promise<unknown> => {
|
|
109
|
-
return this.client.sendOperationRequest(args, spec);
|
|
110
|
-
};
|
|
111
|
-
const sendOperation = async (
|
|
112
|
-
args: OperationArguments,
|
|
113
|
-
spec: OperationSpec
|
|
114
|
-
) => {
|
|
115
|
-
let currentRawResponse: FullOperationResponse | undefined = undefined;
|
|
116
|
-
const providedCallback = args.options?.onResponse;
|
|
117
|
-
const callback: RawResponseCallback = (
|
|
118
|
-
rawResponse: FullOperationResponse,
|
|
119
|
-
flatResponse: unknown
|
|
120
|
-
) => {
|
|
121
|
-
currentRawResponse = rawResponse;
|
|
122
|
-
providedCallback?.(rawResponse, flatResponse);
|
|
123
|
-
};
|
|
124
|
-
const updatedArgs = {
|
|
125
|
-
...args,
|
|
126
|
-
options: {
|
|
127
|
-
...args.options,
|
|
128
|
-
onResponse: callback
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
const flatResponse = await directSendOperation(updatedArgs, spec);
|
|
132
|
-
return {
|
|
133
|
-
flatResponse,
|
|
134
|
-
rawResponse: {
|
|
135
|
-
statusCode: currentRawResponse!.status,
|
|
136
|
-
body: currentRawResponse!.parsedBody,
|
|
137
|
-
headers: currentRawResponse!.headers.toJSON()
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const lro = new LroImpl(
|
|
143
|
-
sendOperation,
|
|
144
|
-
{ options }, // arguments are just the operation options
|
|
145
|
-
spec
|
|
146
|
-
);
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### Using `LroEngine`
|
|
150
|
-
|
|
151
|
-
```ts
|
|
152
|
-
const pollerEngine = new LroEngine(lro, { intervalInMs: 2000 }); // lro was instantiated in the previous section
|
|
153
|
-
const result = pollerEngine.pollUntilDone();
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## Testing
|
|
157
|
-
|
|
158
|
-
We have [extensive test suite for LROs](https://github.com/Azure/autorest.typescript/blob/main/packages/autorest.typescript/test/integration/lro.spec.ts) in the TypeScript code generator repo. I both added those tests here and re-implemented the [lro routes](https://github.com/Azure/autorest.testserver/blob/main/legacy/routes/lros.js) in the Autorest test server. For this to work, I created a [fairly low-level instantiation for `LongRunningOperation<T>` with just `@azure/core-rest-pipeline`](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-lro/test/utils/coreRestPipelineLro.ts).
|
package/review/core-lro.api.md
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
## API Report File for "@azure/core-lro"
|
|
2
|
-
|
|
3
|
-
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
|
|
7
|
-
import { AbortSignalLike } from '@azure/abort-controller';
|
|
8
|
-
|
|
9
|
-
// @public
|
|
10
|
-
export type CancelOnProgress = () => void;
|
|
11
|
-
|
|
12
|
-
// @public
|
|
13
|
-
export function createHttpPoller<TResult, TState extends OperationState<TResult>>(lro: LongRunningOperation, options?: CreateHttpPollerOptions<TResult, TState>): PollerLike<TState, TResult>;
|
|
14
|
-
|
|
15
|
-
// @public
|
|
16
|
-
export interface CreateHttpPollerOptions<TResult, TState> {
|
|
17
|
-
intervalInMs?: number;
|
|
18
|
-
processResult?: (result: unknown, state: TState) => TResult | Promise<TResult>;
|
|
19
|
-
resolveOnUnsuccessful?: boolean;
|
|
20
|
-
resourceLocationConfig?: ResourceLocationConfig;
|
|
21
|
-
restoreFrom?: string;
|
|
22
|
-
updateState?: (state: TState, response: OperationResponse) => void;
|
|
23
|
-
withOperationLocation?: (operationLocation: string) => void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// @public
|
|
27
|
-
export function deserializeState<TState>(serializedState: string): RestorableOperationState<TState>;
|
|
28
|
-
|
|
29
|
-
// @public
|
|
30
|
-
export interface LongRunningOperation<T = unknown> {
|
|
31
|
-
sendInitialRequest: () => Promise<OperationResponse<unknown>>;
|
|
32
|
-
sendPollRequest: (path: string, options?: {
|
|
33
|
-
abortSignal?: AbortSignalLike;
|
|
34
|
-
}) => Promise<OperationResponse<T>>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// @public
|
|
38
|
-
export interface OperationConfig {
|
|
39
|
-
initialUrl?: string;
|
|
40
|
-
metadata?: Record<string, string>;
|
|
41
|
-
operationLocation?: string;
|
|
42
|
-
requestMethod?: string;
|
|
43
|
-
resourceLocation?: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// @public
|
|
47
|
-
export interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {
|
|
48
|
-
flatResponse: T;
|
|
49
|
-
rawResponse: RawResponse<TRequest>;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// @public
|
|
53
|
-
export interface OperationState<TResult> {
|
|
54
|
-
error?: Error;
|
|
55
|
-
result?: TResult;
|
|
56
|
-
status: OperationStatus;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// @public
|
|
60
|
-
export type OperationStatus = "notStarted" | "running" | "succeeded" | "canceled" | "failed";
|
|
61
|
-
|
|
62
|
-
// @public
|
|
63
|
-
export interface PollerLike<TState extends OperationState<TResult>, TResult> extends Promise<TResult> {
|
|
64
|
-
readonly isDone: boolean;
|
|
65
|
-
readonly isStopped: boolean;
|
|
66
|
-
onProgress(callback: (state: TState) => void): CancelOnProgress;
|
|
67
|
-
readonly operationState: TState | undefined;
|
|
68
|
-
poll(options?: {
|
|
69
|
-
abortSignal?: AbortSignalLike;
|
|
70
|
-
}): Promise<TState>;
|
|
71
|
-
pollUntilDone(pollOptions?: {
|
|
72
|
-
abortSignal?: AbortSignalLike;
|
|
73
|
-
}): Promise<TResult>;
|
|
74
|
-
readonly result: TResult | undefined;
|
|
75
|
-
serialize(): Promise<string>;
|
|
76
|
-
submitted(): Promise<void>;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// @public
|
|
80
|
-
export interface RawRequest {
|
|
81
|
-
body?: unknown;
|
|
82
|
-
method: string;
|
|
83
|
-
url: string;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// @public
|
|
87
|
-
export interface RawResponse<TRequest extends RawRequest = RawRequest> {
|
|
88
|
-
body?: unknown;
|
|
89
|
-
headers: {
|
|
90
|
-
[headerName: string]: string;
|
|
91
|
-
};
|
|
92
|
-
request: TRequest;
|
|
93
|
-
statusCode: number;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// @public
|
|
97
|
-
export type ResourceLocationConfig = "azure-async-operation" | "location" | "original-uri";
|
|
98
|
-
|
|
99
|
-
// @public
|
|
100
|
-
export type RestorableOperationState<T> = T & {
|
|
101
|
-
config: OperationConfig;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// (No @packageDocumentation comment for this package)
|
|
105
|
-
|
|
106
|
-
```
|