Commit iniziale

This commit is contained in:
Paolo A
2025-02-18 22:59:07 +00:00
commit 4bbf35cefb
6879 changed files with 623784 additions and 0 deletions

21
node_modules/@azure/core-lro/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2020 Microsoft
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

94
node_modules/@azure/core-lro/README.md generated vendored Normal file
View File

@@ -0,0 +1,94 @@
# Azure Core LRO client library for JavaScript
This is the default implementation of long running operations in Azure SDK JavaScript client libraries which work in both the browser and NodeJS. This library is primarily intended to be used in code generated by [AutoRest](https://github.com/Azure/Autorest) and [`autorest.typescript`](https://github.com/Azure/autorest.typescript).
`@azure/core-lro` follows [The Azure SDK Design Guidelines for Long Running Operations](https://azure.github.io/azure-sdk/typescript_design.html#ts-lro)
Key links:
- [Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/core-lro)
- [Package (npm)](https://www.npmjs.com/package/@azure/core-lro)
- [API Reference Documentation](https://docs.microsoft.com/javascript/api/@azure/core-lro)
- [Samples](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-lro/samples)
## Getting started
### Currently supported environments
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
- Latest versions of Safari, Chrome, Edge, and Firefox.
### Installation
This package is primarily used in generated code and not meant to be consumed directly by end users.
## Key concepts
### `SimplePollerLike`
A poller is an object that can poll the long running operation on the server for its state until it reaches a terminal state. It provides the following methods:
- `getOperationState`: returns the state of the operation, typed as a type that extends `OperationState`
- `getResult`: returns the result of the operation when it completes and `undefined` otherwise
- `isDone`: returns whether the operation is in a terminal state
- `isStopped`: returns whether the polling stopped
- `onProgress`: registers callback functions to be called every time a polling response is received
- `poll`: sends a single polling request
- `pollUntilDone`: returns a promise that will resolve with the result of the operation
- `stopPolling`: stops polling;
- `toString`: serializes the state of the poller
### `OperationState`
A type for the operation state. It contains a `status` field with the following possible values: `notStarted`, `running`, `succeeded`, `failed`, and `canceled`. It can be accessed as follows:
```typescript
switch(poller.getOperationState().status) {
case "succeeded": // return poller.getResult();
case "failed": // throw poller.getOperationState().error;
case "canceled": // throw new Error("Operation was canceled");
case "running": // ...
case "notStarted": // ...
}
```
### `createHttpPoller`
A function that returns an object of type `SimplePollerLike`. This poller behaves as follows in the presence of errors:
- calls to `poll` and `pollUntilDone` will throw an error in case the operation has failed or canceled unless the `resolveOnUnsuccessful` option was set to true.
- `poller.getOperationState().status` will be set to true when either the operation fails or it returns an error response.
## Examples
Examples can be found in the `samples` folder.
## Troubleshooting
### Logging
Logs can be added at the discretion of the library implementing the Long Running Operation poller.
Packages inside of [azure-sdk-for-js](https://github.com/Azure/azure-sdk-for-js) use
[@azure/logger](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
## Next steps
Please take a look at the [samples](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-lro/samples) directory for detailed examples on how to use this library.
## Contributing
If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code.
### Testing
To run our tests, first install the dependencies (with `npm install` or `rush install`),
then run the unit tests with: `npm run unit-test`.
### Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcore%2Fcore-lro%2FREADME.png)

View File

@@ -0,0 +1,106 @@
import { AbortSignalLike } from "@azure/abort-controller";
import { LroError } from "../poller/models.js";
/**
* The potential location of the result of the LRO if specified by the LRO extension in the swagger.
*/
export type LroResourceLocationConfig = "azure-async-operation" | "location" | "original-uri";
/**
* The type of a LRO response body. This is just a convenience type for checking the status of the operation.
*/
export interface ResponseBody extends Record<string, unknown> {
/** The status of the operation. */
status?: unknown;
/** The state of the provisioning process */
provisioningState?: unknown;
/** The properties of the provisioning process */
properties?: {
provisioningState?: unknown;
} & Record<string, unknown>;
/** The error if the operation failed */
error?: Partial<LroError>;
/** The location of the created resource */
resourceLocation?: string;
}
/**
* Simple type of the raw response.
*/
export interface RawResponse {
/** The HTTP status code */
statusCode: number;
/** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */
headers: {
[headerName: string]: string;
};
/** The parsed response body */
body?: unknown;
}
/**
* The type of the response of a LRO.
*/
export interface LroResponse<T = unknown> {
/** The flattened response */
flatResponse: T;
/** The raw response */
rawResponse: RawResponse;
}
/**
* Description of a long running operation.
*/
export interface LongRunningOperation<T = unknown> {
/**
* The request path. This should be set if the operation is a PUT and needs
* to poll from the same request path.
*/
requestPath?: string;
/**
* The HTTP request method. This should be set if the operation is a PUT or a
* DELETE.
*/
requestMethod?: string;
/**
* A function that can be used to send initial request to the service.
*/
sendInitialRequest: () => Promise<LroResponse<unknown>>;
/**
* A function that can be used to poll for the current status of a long running operation.
*/
sendPollRequest: (path: string, options?: {
abortSignal?: AbortSignalLike;
}) => Promise<LroResponse<T>>;
}
export type HttpOperationMode = "OperationLocation" | "ResourceLocation" | "Body";
/**
* Options for `createPoller`.
*/
export interface CreateHttpPollerOptions<TResult, TState> {
/**
* Defines how much time the poller is going to wait before making a new request to the service.
*/
intervalInMs?: number;
/**
* A serialized poller which can be used to resume an existing paused Long-Running-Operation.
*/
restoreFrom?: string;
/**
* The potential location of the result of the LRO if specified by the LRO extension in the swagger.
*/
resourceLocationConfig?: LroResourceLocationConfig;
/**
* A function to process the result of the LRO.
*/
processResult?: (result: unknown, state: TState) => TResult;
/**
* A function to process the state of the LRO.
*/
updateState?: (state: TState, response: LroResponse) => void;
/**
* A function to be called each time the operation location is updated by the
* service.
*/
withOperationLocation?: (operationLocation: string) => void;
/**
* Control whether to throw an exception if the operation failed or was canceled.
*/
resolveOnUnsuccessful?: boolean;
}
//# sourceMappingURL=models.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAG/C;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,uBAAuB,GAAG,UAAU,GAAG,cAAc,CAAC;AAE9F;;GAEG;AAEH,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC3D,mCAAmC;IACnC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,4CAA4C;IAC5C,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,iDAAiD;IACjD,UAAU,CAAC,EAAE;QAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvE,wCAAwC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1B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EAAE,MAAM,KAAK,OAAO,CAAC;IAC5D;;OAEG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,KAAK,IAAI,CAAC;IAC7D;;;OAGG;IACH,qBAAqB,CAAC,EAAE,CAAC,iBAAiB,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5D;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC"}

View File

@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export {};
//# sourceMappingURL=models.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { LroError } from \"../poller/models.js\";\n\n// TODO: rename to ResourceLocationConfig\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type LroResourceLocationConfig = \"azure-async-operation\" | \"location\" | \"original-uri\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse {\n /** The HTTP status code */\n statusCode: number;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n// TODO: rename to OperationResponse\n/**\n * The type of the response of a LRO.\n */\nexport interface LroResponse<T = unknown> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface LongRunningOperation<T = unknown> {\n /**\n * The request path. This should be set if the operation is a PUT and needs\n * to poll from the same request path.\n */\n requestPath?: string;\n /**\n * The HTTP request method. This should be set if the operation is a PUT or a\n * DELETE.\n */\n requestMethod?: string;\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<LroResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<LroResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: LroResourceLocationConfig;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => TResult;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: LroResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}

View File

@@ -0,0 +1,47 @@
import { HttpOperationMode, LongRunningOperation, LroResourceLocationConfig, LroResponse, RawResponse } from "./models.js";
import { LroError, OperationConfig, OperationStatus, RestorableOperationState, StateProxy } from "../poller/models.js";
import { AbortSignalLike } from "@azure/abort-controller";
export declare function inferLroMode(inputs: {
rawResponse: RawResponse;
requestPath?: string;
requestMethod?: string;
resourceLocationConfig?: LroResourceLocationConfig;
}): (OperationConfig & {
mode: HttpOperationMode;
}) | undefined;
export declare function parseRetryAfter<T>({ rawResponse }: LroResponse<T>): number | undefined;
export declare function getErrorFromResponse<T>(response: LroResponse<T>): LroError | undefined;
export declare function getStatusFromInitialResponse<TState>(inputs: {
response: LroResponse<unknown>;
state: RestorableOperationState<TState>;
operationLocation?: string;
}): OperationStatus;
/**
* Initiates the long-running operation.
*/
export declare function initHttpOperation<TResult, TState>(inputs: {
stateProxy: StateProxy<TState, TResult>;
resourceLocationConfig?: LroResourceLocationConfig;
processResult?: (result: unknown, state: TState) => TResult;
setErrorAsResult: boolean;
lro: LongRunningOperation;
}): Promise<RestorableOperationState<TState>>;
export declare function getOperationLocation<TState>({ rawResponse }: LroResponse, state: RestorableOperationState<TState>): string | undefined;
export declare function getOperationStatus<TState>({ rawResponse }: LroResponse, state: RestorableOperationState<TState>): OperationStatus;
export declare function getResourceLocation<TState>(res: LroResponse, state: RestorableOperationState<TState>): string | undefined;
export declare function isOperationError(e: Error): boolean;
/** Polls the long-running operation. */
export declare function pollHttpOperation<TState, TResult>(inputs: {
lro: LongRunningOperation;
stateProxy: StateProxy<TState, TResult>;
processResult?: (result: unknown, state: TState) => TResult;
updateState?: (state: TState, lastResponse: LroResponse) => void;
isDone?: (lastResponse: LroResponse, state: TState) => boolean;
setDelay: (intervalInMs: number) => void;
options?: {
abortSignal?: AbortSignalLike;
};
state: RestorableOperationState<TState>;
setErrorAsResult: boolean;
}): Promise<void>;
//# sourceMappingURL=operation.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,yBAAyB,EACzB,WAAW,EACX,WAAW,EAEZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,QAAQ,EACR,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,UAAU,EACX,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC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MAAM,CAAC,GACtC,MAAM,GAAG,SAAS,CAiBpB;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EACvC,EAAE,WAAW,EAAE,EAAE,WAAW,EAC5B,KAAK,EAAE,wBAAwB,CAAC,MAAM,CAAC,GACtC,eAAe,CAejB;AASD,wBAAgB,mBAAmB,CAAC,MAAM,EACxC,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,wBAAwB,CAAC,MAAM,CAAC,GACtC,MAAM,GAAG,SAAS,CAMpB;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,GAAG,OAAO,CAElD;AAED,wCAAwC;AACxC,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE;IAC/D,GAAG,EAAE,oBAAoB,CAAC;IAC1B,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAC5D,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,KAAK,IAAI,CAAC;IACjE,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAC/D,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAE,CAAC;IAC5C,KAAK,EAAE,wBAAwB,CAAC,MAAM,CAAC,CAAC;IACxC,gBAAgB,EAAE,OAAO,CAAC;CAC3B,GAAG,OAAO,CAAC,IAAI,CAAC,CAkChB"}

View File

@@ -0,0 +1,282 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { initOperation, pollOperation } from "../poller/operation.js";
import { logger } from "../logger.js";
function getOperationLocationPollingUrl(inputs) {
const { azureAsyncOperation, operationLocation } = inputs;
return operationLocation !== null && operationLocation !== void 0 ? operationLocation : azureAsyncOperation;
}
function getLocationHeader(rawResponse) {
return rawResponse.headers["location"];
}
function getOperationLocationHeader(rawResponse) {
return rawResponse.headers["operation-location"];
}
function getAzureAsyncOperationHeader(rawResponse) {
return rawResponse.headers["azure-asyncoperation"];
}
function findResourceLocation(inputs) {
var _a;
const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;
switch (requestMethod) {
case "PUT": {
return requestPath;
}
case "DELETE": {
return undefined;
}
case "PATCH": {
return (_a = getDefault()) !== null && _a !== void 0 ? _a : requestPath;
}
default: {
return getDefault();
}
}
function getDefault() {
switch (resourceLocationConfig) {
case "azure-async-operation": {
return undefined;
}
case "original-uri": {
return requestPath;
}
case "location":
default: {
return location;
}
}
}
}
export function inferLroMode(inputs) {
const { rawResponse, requestMethod, requestPath, resourceLocationConfig } = inputs;
const operationLocation = getOperationLocationHeader(rawResponse);
const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);
const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });
const location = getLocationHeader(rawResponse);
const normalizedRequestMethod = requestMethod === null || requestMethod === void 0 ? void 0 : requestMethod.toLocaleUpperCase();
if (pollingUrl !== undefined) {
return {
mode: "OperationLocation",
operationLocation: pollingUrl,
resourceLocation: findResourceLocation({
requestMethod: normalizedRequestMethod,
location,
requestPath,
resourceLocationConfig,
}),
};
}
else if (location !== undefined) {
return {
mode: "ResourceLocation",
operationLocation: location,
};
}
else if (normalizedRequestMethod === "PUT" && requestPath) {
return {
mode: "Body",
operationLocation: requestPath,
};
}
else {
return undefined;
}
}
function transformStatus(inputs) {
const { status, statusCode } = inputs;
if (typeof status !== "string" && status !== undefined) {
throw new Error(`Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`);
}
switch (status === null || status === void 0 ? void 0 : status.toLocaleLowerCase()) {
case undefined:
return toOperationStatus(statusCode);
case "succeeded":
return "succeeded";
case "failed":
return "failed";
case "running":
case "accepted":
case "started":
case "canceling":
case "cancelling":
return "running";
case "canceled":
case "cancelled":
return "canceled";
default: {
logger.verbose(`LRO: unrecognized operation status: ${status}`);
return status;
}
}
}
function getStatus(rawResponse) {
var _a;
const { status } = (_a = rawResponse.body) !== null && _a !== void 0 ? _a : {};
return transformStatus({ status, statusCode: rawResponse.statusCode });
}
function getProvisioningState(rawResponse) {
var _a, _b;
const { properties, provisioningState } = (_a = rawResponse.body) !== null && _a !== void 0 ? _a : {};
const status = (_b = properties === null || properties === void 0 ? void 0 : properties.provisioningState) !== null && _b !== void 0 ? _b : provisioningState;
return transformStatus({ status, statusCode: rawResponse.statusCode });
}
function toOperationStatus(statusCode) {
if (statusCode === 202) {
return "running";
}
else if (statusCode < 300) {
return "succeeded";
}
else {
return "failed";
}
}
export function parseRetryAfter({ rawResponse }) {
const retryAfter = rawResponse.headers["retry-after"];
if (retryAfter !== undefined) {
// Retry-After header value is either in HTTP date format, or in seconds
const retryAfterInSeconds = parseInt(retryAfter);
return isNaN(retryAfterInSeconds)
? calculatePollingIntervalFromDate(new Date(retryAfter))
: retryAfterInSeconds * 1000;
}
return undefined;
}
export function getErrorFromResponse(response) {
const error = accessBodyProperty(response, "error");
if (!error) {
logger.warning(`The long-running operation failed but there is no error property in the response's body`);
return;
}
if (!error.code || !error.message) {
logger.warning(`The long-running operation failed but the error property in the response's body doesn't contain code or message`);
return;
}
return error;
}
function calculatePollingIntervalFromDate(retryAfterDate) {
const timeNow = Math.floor(new Date().getTime());
const retryAfterTime = retryAfterDate.getTime();
if (timeNow < retryAfterTime) {
return retryAfterTime - timeNow;
}
return undefined;
}
export function getStatusFromInitialResponse(inputs) {
const { response, state, operationLocation } = inputs;
function helper() {
var _a;
const mode = (_a = state.config.metadata) === null || _a === void 0 ? void 0 : _a["mode"];
switch (mode) {
case undefined:
return toOperationStatus(response.rawResponse.statusCode);
case "Body":
return getOperationStatus(response, state);
default:
return "running";
}
}
const status = helper();
return status === "running" && operationLocation === undefined ? "succeeded" : status;
}
/**
* Initiates the long-running operation.
*/
export async function initHttpOperation(inputs) {
const { stateProxy, resourceLocationConfig, processResult, lro, setErrorAsResult } = inputs;
return initOperation({
init: async () => {
const response = await lro.sendInitialRequest();
const config = inferLroMode({
rawResponse: response.rawResponse,
requestPath: lro.requestPath,
requestMethod: lro.requestMethod,
resourceLocationConfig,
});
return Object.assign({ response, operationLocation: config === null || config === void 0 ? void 0 : config.operationLocation, resourceLocation: config === null || config === void 0 ? void 0 : config.resourceLocation }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
},
stateProxy,
processResult: processResult
? ({ flatResponse }, state) => processResult(flatResponse, state)
: ({ flatResponse }) => flatResponse,
getOperationStatus: getStatusFromInitialResponse,
setErrorAsResult,
});
}
export function getOperationLocation({ rawResponse }, state) {
var _a;
const mode = (_a = state.config.metadata) === null || _a === void 0 ? void 0 : _a["mode"];
switch (mode) {
case "OperationLocation": {
return getOperationLocationPollingUrl({
operationLocation: getOperationLocationHeader(rawResponse),
azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),
});
}
case "ResourceLocation": {
return getLocationHeader(rawResponse);
}
case "Body":
default: {
return undefined;
}
}
}
export function getOperationStatus({ rawResponse }, state) {
var _a;
const mode = (_a = state.config.metadata) === null || _a === void 0 ? void 0 : _a["mode"];
switch (mode) {
case "OperationLocation": {
return getStatus(rawResponse);
}
case "ResourceLocation": {
return toOperationStatus(rawResponse.statusCode);
}
case "Body": {
return getProvisioningState(rawResponse);
}
default:
throw new Error(`Internal error: Unexpected operation mode: ${mode}`);
}
}
function accessBodyProperty({ flatResponse, rawResponse }, prop) {
var _a, _b;
return (_a = flatResponse === null || flatResponse === void 0 ? void 0 : flatResponse[prop]) !== null && _a !== void 0 ? _a : (_b = rawResponse.body) === null || _b === void 0 ? void 0 : _b[prop];
}
export function getResourceLocation(res, state) {
const loc = accessBodyProperty(res, "resourceLocation");
if (loc && typeof loc === "string") {
state.config.resourceLocation = loc;
}
return state.config.resourceLocation;
}
export function isOperationError(e) {
return e.name === "RestError";
}
/** Polls the long-running operation. */
export async function pollHttpOperation(inputs) {
const { lro, stateProxy, options, processResult, updateState, setDelay, state, setErrorAsResult, } = inputs;
return pollOperation({
state,
stateProxy,
setDelay,
processResult: processResult
? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)
: ({ flatResponse }) => flatResponse,
getError: getErrorFromResponse,
updateState,
getPollingInterval: parseRetryAfter,
getOperationLocation,
getOperationStatus,
isOperationError,
getResourceLocation,
options,
/**
* The expansion here is intentional because `lro` could be an object that
* references an inner this, so we need to preserve a reference to it.
*/
poll: async (location, inputOptions) => lro.sendPollRequest(location, inputOptions),
setErrorAsResult,
});
}
//# sourceMappingURL=operation.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,11 @@
import { LongRunningOperation } from "./models.js";
import { OperationState, SimplePollerLike } from "../poller/models.js";
import { CreateHttpPollerOptions } from "./models.js";
/**
* Creates a poller that can be used to poll a long-running operation.
* @param lro - Description of the long-running operation
* @param options - options to configure the poller
* @returns an initialized poller
*/
export declare function createHttpPoller<TResult, TState extends OperationState<TResult>>(lro: LongRunningOperation, options?: CreateHttpPollerOptions<TResult, TState>): Promise<SimplePollerLike<TState, TResult>>;
//# sourceMappingURL=poller.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"poller.d.ts","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAe,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAWvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAGtD;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,MAAM,SAAS,cAAc,CAAC,OAAO,CAAC,EACpF,GAAG,EAAE,oBAAoB,EACzB,OAAO,CAAC,EAAE,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,GACjD,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAgD5C"}

View File

@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { getErrorFromResponse, getOperationLocation, getOperationStatus, getResourceLocation, getStatusFromInitialResponse, inferLroMode, isOperationError, parseRetryAfter, } from "./operation.js";
import { buildCreatePoller } from "../poller/poller.js";
/**
* Creates a poller that can be used to poll a long-running operation.
* @param lro - Description of the long-running operation
* @param options - options to configure the poller
* @returns an initialized poller
*/
export async function createHttpPoller(lro, options) {
const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, } = options || {};
return buildCreatePoller({
getStatusFromInitialResponse,
getStatusFromPollResponse: getOperationStatus,
isOperationError,
getOperationLocation,
getResourceLocation,
getPollingInterval: parseRetryAfter,
getError: getErrorFromResponse,
resolveOnUnsuccessful,
})({
init: async () => {
const response = await lro.sendInitialRequest();
const config = inferLroMode({
rawResponse: response.rawResponse,
requestPath: lro.requestPath,
requestMethod: lro.requestMethod,
resourceLocationConfig,
});
return Object.assign({ response, operationLocation: config === null || config === void 0 ? void 0 : config.operationLocation, resourceLocation: config === null || config === void 0 ? void 0 : config.resourceLocation }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
},
poll: lro.sendPollRequest,
}, {
intervalInMs,
withOperationLocation,
restoreFrom,
updateState,
processResult: processResult
? ({ flatResponse }, state) => processResult(flatResponse, state)
: ({ flatResponse }) => flatResponse,
});
}
//# sourceMappingURL=poller.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EA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AAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAuB;KAClD,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { LongRunningOperation, LroResponse } from \"./models.js\";\nimport { OperationState, SimplePollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport async function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: LongRunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): Promise<SimplePollerLike<TState, TResult>> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n } = options || {};\n return buildCreatePoller<LroResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode({\n rawResponse: response.rawResponse,\n requestPath: lro.requestPath,\n requestMethod: lro.requestMethod,\n resourceLocationConfig,\n });\n return {\n response,\n operationLocation: config?.operationLocation,\n resourceLocation: config?.resourceLocation,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as TResult,\n },\n );\n}\n"]}

13
node_modules/@azure/core-lro/dist/browser/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,13 @@
export { createHttpPoller } from "./http/poller.js";
export { CancelOnProgress, OperationState, OperationStatus, SimplePollerLike, } from "./poller/models.js";
export { CreateHttpPollerOptions } from "./http/models.js";
export { LroResourceLocationConfig, LongRunningOperation, LroResponse, RawResponse, } from "./http/models.js";
/**
* This can be uncommented to expose the protocol-agnostic poller
*/
/** legacy */
export * from "./legacy/lroEngine/index.js";
export * from "./legacy/poller.js";
export * from "./legacy/pollOperation.js";
export { PollerLike } from "./legacy/models.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,WAAW,EACX,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AAUH,aAAa;AACb,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC"}

19
node_modules/@azure/core-lro/dist/browser/index.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export { createHttpPoller } from "./http/poller.js";
/**
* This can be uncommented to expose the protocol-agnostic poller
*/
// export {
// BuildCreatePollerOptions,
// Operation,
// CreatePollerOptions,
// OperationConfig,
// RestorableOperationState,
// } from "./poller/models";
// export { buildCreatePoller } from "./poller/poller";
/** legacy */
export * from "./legacy/lroEngine/index.js";
export * from "./legacy/poller.js";
export * from "./legacy/pollOperation.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAepD;;GAEG;AACH,WAAW;AACX,8BAA8B;AAC9B,eAAe;AACf,yBAAyB;AACzB,qBAAqB;AACrB,8BAA8B;AAC9B,4BAA4B;AAC5B,uDAAuD;AAEvD,aAAa;AACb,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { createHttpPoller } from \"./http/poller.js\";\nexport {\n CancelOnProgress,\n OperationState,\n OperationStatus,\n SimplePollerLike,\n} from \"./poller/models.js\";\nexport { CreateHttpPollerOptions } from \"./http/models.js\";\nexport {\n LroResourceLocationConfig,\n LongRunningOperation,\n LroResponse,\n RawResponse,\n} from \"./http/models.js\";\n\n/**\n * This can be uncommented to expose the protocol-agnostic poller\n */\n// export {\n// BuildCreatePollerOptions,\n// Operation,\n// CreatePollerOptions,\n// OperationConfig,\n// RestorableOperationState,\n// } from \"./poller/models\";\n// export { buildCreatePoller } from \"./poller/poller\";\n\n/** legacy */\nexport * from \"./legacy/lroEngine/index.js\";\nexport * from \"./legacy/poller.js\";\nexport * from \"./legacy/pollOperation.js\";\nexport { PollerLike } from \"./legacy/models.js\";\n"]}

View File

@@ -0,0 +1,3 @@
export { LroEngine } from "./lroEngine.js";
export { LroEngineOptions } from "./models.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/legacy/lroEngine/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}

View File

@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export { LroEngine } from "./lroEngine.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/legacy/lroEngine/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { LroEngine } from \"./lroEngine.js\";\nexport { LroEngineOptions } from \"./models.js\";\n"]}

View File

@@ -0,0 +1,16 @@
import { LroEngineOptions } from "./models.js";
import { LongRunningOperation } from "../../http/models.js";
import { PollOperationState } from "../pollOperation.js";
import { Poller } from "../poller.js";
/**
* The LRO Engine, a class that performs polling.
*/
export declare class LroEngine<TResult, TState extends PollOperationState<TResult>> extends Poller<TState, TResult> {
private config;
constructor(lro: LongRunningOperation<TResult>, options?: LroEngineOptions<TResult, TState>);
/**
* The method used by the poller to wait before attempting to update its operation.
*/
delay(): Promise<void>;
}
//# sourceMappingURL=lroEngine.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"lroEngine.d.ts","sourceRoot":"","sources":["../../../../src/legacy/lroEngine/lroEngine.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAgB,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC;;GAEG;AACH,qBAAa,SAAS,CAAC,OAAO,EAAE,MAAM,SAAS,kBAAkB,CAAC,OAAO,CAAC,CAAE,SAAQ,MAAM,CACxF,MAAM,EACN,OAAO,CACR;IACC,OAAO,CAAC,MAAM,CAAe;gBAEjB,GAAG,EAAE,oBAAoB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;IA6B3F;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGvB"}

View File

@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { GenericPollOperation } from "./operation.js";
import { POLL_INTERVAL_IN_MS } from "../../poller/constants.js";
import { Poller } from "../poller.js";
import { deserializeState } from "../../poller/operation.js";
/**
* The LRO Engine, a class that performs polling.
*/
export class LroEngine extends Poller {
constructor(lro, options) {
const { intervalInMs = POLL_INTERVAL_IN_MS, resumeFrom, resolveOnUnsuccessful = false, isDone, lroResourceLocationConfig, processResult, updateState, } = options || {};
const state = resumeFrom
? deserializeState(resumeFrom)
: {};
const operation = new GenericPollOperation(state, lro, !resolveOnUnsuccessful, lroResourceLocationConfig, processResult, updateState, isDone);
super(operation);
this.resolveOnUnsuccessful = resolveOnUnsuccessful;
this.config = { intervalInMs: intervalInMs };
operation.setPollerConfig(this.config);
}
/**
* The method used by the poller to wait before attempting to update its operation.
*/
delay() {
return new Promise((resolve) => setTimeout(() => resolve(), this.config.intervalInMs));
}
}
//# sourceMappingURL=lroEngine.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"lroEngine.js","sourceRoot":"","sources":["../../../../src/legacy/lroEngine/lroEngine.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D;;GAEG;AACH,MAAM,OAAO,SAA+D,SAAQ,MAGnF;IAGC,YAAY,GAAkC,EAAE,OAA2C;QACzF,MAAM,EACJ,YAAY,GAAG,mBAAmB,EAClC,UAAU,EACV,qBAAqB,GAAG,KAAK,EAC7B,MAAM,EACN,yBAAyB,EACzB,aAAa,EACb,WAAW,GACZ,GAAG,OAAO,IAAI,EAAE,CAAC;QAClB,MAAM,KAAK,GAAqC,UAAU;YACxD,CAAC,CAAC,gBAAgB,CAAC,UAAU,CAAC;YAC9B,CAAC,CAAE,EAAuC,CAAC;QAC7C,MAAM,SAAS,GAAG,IAAI,oBAAoB,CACxC,KAAK,EACL,GAAG,EACH,CAAC,qBAAqB,EACtB,yBAAyB,EACzB,aAAa,EACb,WAAW,EACX,MAAM,CACP,CAAC;QACF,KAAK,CAAC,SAAS,CAAC,CAAC;QACjB,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QAEnD,IAAI,CAAC,MAAM,GAAG,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;QAC7C,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;IACzF,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { LroEngineOptions, PollerConfig } from \"./models.js\";\nimport { GenericPollOperation } from \"./operation.js\";\nimport { LongRunningOperation } from \"../../http/models.js\";\nimport { POLL_INTERVAL_IN_MS } from \"../../poller/constants.js\";\nimport { PollOperationState } from \"../pollOperation.js\";\nimport { Poller } from \"../poller.js\";\nimport { RestorableOperationState } from \"../../poller/models.js\";\nimport { deserializeState } from \"../../poller/operation.js\";\n\n/**\n * The LRO Engine, a class that performs polling.\n */\nexport class LroEngine<TResult, TState extends PollOperationState<TResult>> extends Poller<\n TState,\n TResult\n> {\n private config: PollerConfig;\n\n constructor(lro: LongRunningOperation<TResult>, options?: LroEngineOptions<TResult, TState>) {\n const {\n intervalInMs = POLL_INTERVAL_IN_MS,\n resumeFrom,\n resolveOnUnsuccessful = false,\n isDone,\n lroResourceLocationConfig,\n processResult,\n updateState,\n } = options || {};\n const state: RestorableOperationState<TState> = resumeFrom\n ? deserializeState(resumeFrom)\n : ({} as RestorableOperationState<TState>);\n const operation = new GenericPollOperation(\n state,\n lro,\n !resolveOnUnsuccessful,\n lroResourceLocationConfig,\n processResult,\n updateState,\n isDone,\n );\n super(operation);\n this.resolveOnUnsuccessful = resolveOnUnsuccessful;\n\n this.config = { intervalInMs: intervalInMs };\n operation.setPollerConfig(this.config);\n }\n\n /**\n * The method used by the poller to wait before attempting to update its operation.\n */\n delay(): Promise<void> {\n return new Promise((resolve) => setTimeout(() => resolve(), this.config.intervalInMs));\n }\n}\n"]}

View File

@@ -0,0 +1,38 @@
import { LroResourceLocationConfig, RawResponse } from "../../http/models.js";
/**
* Options for the LRO poller.
*/
export interface LroEngineOptions<TResult, TState> {
/**
* Defines how much time the poller is going to wait before making a new request to the service.
*/
intervalInMs?: number;
/**
* A serialized poller which can be used to resume an existing paused Long-Running-Operation.
*/
resumeFrom?: string;
/**
* The potential location of the result of the LRO if specified by the LRO extension in the swagger.
*/
lroResourceLocationConfig?: LroResourceLocationConfig;
/**
* A function to process the result of the LRO.
*/
processResult?: (result: unknown, state: TState) => TResult;
/**
* A function to process the state of the LRO.
*/
updateState?: (state: TState, lastResponse: RawResponse) => void;
/**
* A predicate to determine whether the LRO finished processing.
*/
isDone?: (lastResponse: unknown, state: TState) => boolean;
/**
* Control whether to throw an exception if the operation failed or was canceled.
*/
resolveOnUnsuccessful?: boolean;
}
export interface PollerConfig {
intervalInMs: number;
}
//# sourceMappingURL=models.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../../src/legacy/lroEngine/models.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAE9E;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,OAAO,EAAE,MAAM;IAC/C;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,yBAAyB,CAAC,EAAE,yBAAyB,CAAC;IACtD;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAC5D;;OAEG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,KAAK,IAAI,CAAC;IACjE;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAC3D;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;CACtB"}

View File

@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export {};
//# sourceMappingURL=models.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/legacy/lroEngine/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { LroResourceLocationConfig, RawResponse } from \"../../http/models.js\";\n\n/**\n * Options for the LRO poller.\n */\nexport interface LroEngineOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n resumeFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n lroResourceLocationConfig?: LroResourceLocationConfig;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => TResult;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, lastResponse: RawResponse) => void;\n /**\n * A predicate to determine whether the LRO finished processing.\n */\n isDone?: (lastResponse: unknown, state: TState) => boolean;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n\nexport interface PollerConfig {\n intervalInMs: number;\n}\n"]}

View File

@@ -0,0 +1,27 @@
import { LongRunningOperation, LroResourceLocationConfig, RawResponse } from "../../http/models.js";
import { PollOperation, PollOperationState } from "../pollOperation.js";
import { RestorableOperationState } from "../../poller/models.js";
import { AbortSignalLike } from "@azure/abort-controller";
import { PollerConfig } from "./models.js";
export declare class GenericPollOperation<TResult, TState extends PollOperationState<TResult>> implements PollOperation<TState, TResult> {
state: RestorableOperationState<TState>;
private lro;
private setErrorAsResult;
private lroResourceLocationConfig?;
private processResult?;
private updateState?;
private isDone?;
private pollerConfig?;
constructor(state: RestorableOperationState<TState>, lro: LongRunningOperation, setErrorAsResult: boolean, lroResourceLocationConfig?: LroResourceLocationConfig | undefined, processResult?: ((result: unknown, state: TState) => TResult) | undefined, updateState?: ((state: TState, lastResponse: RawResponse) => void) | undefined, isDone?: ((lastResponse: TResult, state: TState) => boolean) | undefined);
setPollerConfig(pollerConfig: PollerConfig): void;
update(options?: {
abortSignal?: AbortSignalLike;
fireProgress?: (state: TState) => void;
}): Promise<PollOperation<TState, TResult>>;
cancel(): Promise<PollOperation<TState, TResult>>;
/**
* Serializes the Poller operation.
*/
toString(): string;
}
//# sourceMappingURL=operation.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../../src/legacy/lroEngine/operation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAc,MAAM,wBAAwB,CAAC;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAyB3C,qBAAa,oBAAoB,CAAC,OAAO,EAAE,MAAM,SAAS,kBAAkB,CAAC,OAAO,CAAC,CACnF,YAAW,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC;IAKhC,KAAK,EAAE,wBAAwB,CAAC,MAAM,CAAC;IAC9C,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,yBAAyB,CAAC;IAClC,OAAO,CAAC,aAAa,CAAC;IACtB,OAAO,CAAC,WAAW,CAAC;IACpB,OAAO,CAAC,MAAM,CAAC;IATjB,OAAO,CAAC,YAAY,CAAC,CAAe;gBAG3B,KAAK,EAAE,wBAAwB,CAAC,MAAM,CAAC,EACtC,GAAG,EAAE,oBAAoB,EACzB,gBAAgB,EAAE,OAAO,EACzB,yBAAyB,CAAC,uCAA2B,EACrD,aAAa,CAAC,YAAW,OAAO,SAAS,MAAM,KAAK,OAAO,aAAA,EAC3D,WAAW,CAAC,WAAU,MAAM,gBAAgB,WAAW,KAAK,IAAI,aAAA,EAChE,MAAM,CAAC,kBAAiB,OAAO,SAAS,MAAM,KAAK,OAAO,aAAA;IAG7D,eAAe,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI;IAIlD,MAAM,CAAC,OAAO,CAAC,EAAE;QACrB,WAAW,CAAC,EAAE,eAAe,CAAC;QAC9B,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;KACxC,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAwCrC,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAKvD;;OAEG;IACI,QAAQ,IAAI,MAAM;CAK1B"}

View File

@@ -0,0 +1,84 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { initHttpOperation, pollHttpOperation } from "../../http/operation.js";
import { logger } from "../../logger.js";
const createStateProxy = () => ({
initState: (config) => ({ config, isStarted: true }),
setCanceled: (state) => (state.isCancelled = true),
setError: (state, error) => (state.error = error),
setResult: (state, result) => (state.result = result),
setRunning: (state) => (state.isStarted = true),
setSucceeded: (state) => (state.isCompleted = true),
setFailed: () => {
/** empty body */
},
getError: (state) => state.error,
getResult: (state) => state.result,
isCanceled: (state) => !!state.isCancelled,
isFailed: (state) => !!state.error,
isRunning: (state) => !!state.isStarted,
isSucceeded: (state) => Boolean(state.isCompleted && !state.isCancelled && !state.error),
});
export class GenericPollOperation {
constructor(state, lro, setErrorAsResult, lroResourceLocationConfig, processResult, updateState, isDone) {
this.state = state;
this.lro = lro;
this.setErrorAsResult = setErrorAsResult;
this.lroResourceLocationConfig = lroResourceLocationConfig;
this.processResult = processResult;
this.updateState = updateState;
this.isDone = isDone;
}
setPollerConfig(pollerConfig) {
this.pollerConfig = pollerConfig;
}
async update(options) {
var _a;
const stateProxy = createStateProxy();
if (!this.state.isStarted) {
this.state = Object.assign(Object.assign({}, this.state), (await initHttpOperation({
lro: this.lro,
stateProxy,
resourceLocationConfig: this.lroResourceLocationConfig,
processResult: this.processResult,
setErrorAsResult: this.setErrorAsResult,
})));
}
const updateState = this.updateState;
const isDone = this.isDone;
if (!this.state.isCompleted && this.state.error === undefined) {
await pollHttpOperation({
lro: this.lro,
state: this.state,
stateProxy,
processResult: this.processResult,
updateState: updateState
? (state, { rawResponse }) => updateState(state, rawResponse)
: undefined,
isDone: isDone
? ({ flatResponse }, state) => isDone(flatResponse, state)
: undefined,
options,
setDelay: (intervalInMs) => {
this.pollerConfig.intervalInMs = intervalInMs;
},
setErrorAsResult: this.setErrorAsResult,
});
}
(_a = options === null || options === void 0 ? void 0 : options.fireProgress) === null || _a === void 0 ? void 0 : _a.call(options, this.state);
return this;
}
async cancel() {
logger.error("`cancelOperation` is deprecated because it wasn't implemented");
return this;
}
/**
* Serializes the Poller operation.
*/
toString() {
return JSON.stringify({
state: this.state,
});
}
}
//# sourceMappingURL=operation.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,66 @@
import { AbortSignalLike } from "@azure/abort-controller";
import { CancelOnProgress } from "../poller/models.js";
import { PollOperationState } from "./pollOperation.js";
/**
* Abstract representation of a poller, intended to expose just the minimal API that the user needs to work with.
*/
export interface PollerLike<TState extends PollOperationState<TResult>, TResult> {
/**
* Returns a promise that will resolve once a single polling request finishes.
* It does this by calling the update method of the Poller's operation.
*/
poll(options?: {
abortSignal?: AbortSignalLike;
}): Promise<void>;
/**
* Returns a promise that will resolve once the underlying operation is completed.
*/
pollUntilDone(pollOptions?: {
abortSignal?: AbortSignalLike;
}): Promise<TResult>;
/**
* Invokes the provided callback after each polling is completed,
* sending the current state of the poller's operation.
*
* It returns a method that can be used to stop receiving updates on the given callback function.
*/
onProgress(callback: (state: TState) => void): CancelOnProgress;
/**
* Returns true if the poller has finished polling.
*/
isDone(): boolean;
/**
* Stops the poller. After this, no manual or automated requests can be sent.
*/
stopPolling(): void;
/**
* Returns true if the poller is stopped.
*/
isStopped(): boolean;
/**
* Attempts to cancel the underlying operation.
* @deprecated `cancelOperation` has been deprecated because it was not implemented.
*/
cancelOperation(options?: {
abortSignal?: AbortSignalLike;
}): Promise<void>;
/**
* Returns the state of the operation.
* The TState defined in PollerLike can be a subset of the TState defined in
* the Poller implementation.
*/
getOperationState(): TState;
/**
* Returns the result value of the operation,
* regardless of the state of the poller.
* It can return undefined or an incomplete form of the final TResult value
* depending on the implementation.
*/
getResult(): TResult | undefined;
/**
* Returns a serialized version of the poller's operation
* by invoking the operation's toString method.
*/
toString(): string;
}
//# sourceMappingURL=models.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../src/legacy/models.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD;;GAEG;AAEH,MAAM,WAAW,UAAU,CAAC,MAAM,SAAS,kBAAkB,CAAC,OAAO,CAAC,EAAE,OAAO;IAC7E;;;OAGG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE;;OAEG;IACH,aAAa,CAAC,WAAW,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACjF;;;;;OAKG;IACH,UAAU,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,gBAAgB,CAAC;IAChE;;OAEG;IACH,MAAM,IAAI,OAAO,CAAC;IAClB;;OAEG;IACH,WAAW,IAAI,IAAI,CAAC;IACpB;;OAEG;IACH,SAAS,IAAI,OAAO,CAAC;IACrB;;;OAGG;IACH,eAAe,CAAC,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5E;;;;OAIG;IACH,iBAAiB,IAAI,MAAM,CAAC;IAC5B;;;;;OAKG;IACH,SAAS,IAAI,OAAO,GAAG,SAAS,CAAC;IACjC;;;OAGG;IACH,QAAQ,IAAI,MAAM,CAAC;CACpB"}

View File

@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export {};
//# sourceMappingURL=models.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/legacy/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { CancelOnProgress } from \"../poller/models.js\";\nimport { PollOperationState } from \"./pollOperation.js\";\n\n/**\n * Abstract representation of a poller, intended to expose just the minimal API that the user needs to work with.\n */\n// eslint-disable-next-line no-use-before-define\nexport interface PollerLike<TState extends PollOperationState<TResult>, TResult> {\n /**\n * Returns a promise that will resolve once a single polling request finishes.\n * It does this by calling the update method of the Poller's operation.\n */\n poll(options?: { abortSignal?: AbortSignalLike }): Promise<void>;\n /**\n * Returns a promise that will resolve once the underlying operation is completed.\n */\n pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise<TResult>;\n /**\n * Invokes the provided callback after each polling is completed,\n * sending the current state of the poller's operation.\n *\n * It returns a method that can be used to stop receiving updates on the given callback function.\n */\n onProgress(callback: (state: TState) => void): CancelOnProgress;\n /**\n * Returns true if the poller has finished polling.\n */\n isDone(): boolean;\n /**\n * Stops the poller. After this, no manual or automated requests can be sent.\n */\n stopPolling(): void;\n /**\n * Returns true if the poller is stopped.\n */\n isStopped(): boolean;\n /**\n * Attempts to cancel the underlying operation.\n * @deprecated `cancelOperation` has been deprecated because it was not implemented.\n */\n cancelOperation(options?: { abortSignal?: AbortSignalLike }): Promise<void>;\n /**\n * Returns the state of the operation.\n * The TState defined in PollerLike can be a subset of the TState defined in\n * the Poller implementation.\n */\n getOperationState(): TState;\n /**\n * Returns the result value of the operation,\n * regardless of the state of the poller.\n * It can return undefined or an incomplete form of the final TResult value\n * depending on the implementation.\n */\n getResult(): TResult | undefined;\n /**\n * Returns a serialized version of the poller's operation\n * by invoking the operation's toString method.\n */\n toString(): string;\n}\n"]}

View File

@@ -0,0 +1,81 @@
import { AbortSignalLike } from "@azure/abort-controller";
/**
* PollOperationState contains an opinionated list of the smallest set of properties needed
* to define any long running operation poller.
*
* While the Poller class works as the local control mechanism to start triggering, wait for,
* and potentially cancel a long running operation, the PollOperationState documents the status
* of the remote long running operation.
*
* It should be updated at least when the operation starts, when it's finished, and when it's cancelled.
* Though, implementations can have any other number of properties that can be updated by other reasons.
*/
export interface PollOperationState<TResult> {
/**
* True if the operation has started.
*/
isStarted?: boolean;
/**
* True if the operation has been completed.
*/
isCompleted?: boolean;
/**
* True if the operation has been cancelled.
*/
isCancelled?: boolean;
/**
* Will exist if the operation encountered any error.
*/
error?: Error;
/**
* Will exist if the operation concluded in a result of an expected type.
*/
result?: TResult;
}
/**
* PollOperation is an interface that defines how to update the local reference of the state of the remote
* long running operation, just as well as how to request the cancellation of the same operation.
*
* It also has a method to serialize the operation so that it can be stored and resumed at any time.
*/
export interface PollOperation<TState, TResult> {
/**
* The state of the operation.
* It will be used to store the basic properties of PollOperationState<TResult>,
* plus any custom property that the implementation may require.
*/
state: TState;
/**
* Defines how to request the remote service for updates on the status of the long running operation.
*
* It optionally receives an object with an abortSignal property, from \@azure/abort-controller's AbortSignalLike.
* Also optionally receives a "fireProgress" function, which, if called, is responsible for triggering the
* poller's onProgress callbacks.
*
* @param options - Optional properties passed to the operation's update method.
*/
update(options?: {
abortSignal?: AbortSignalLike;
fireProgress?: (state: TState) => void;
}): Promise<PollOperation<TState, TResult>>;
/**
* Attempts to cancel the underlying operation.
*
* It only optionally receives an object with an abortSignal property, from \@azure/abort-controller's AbortSignalLike.
*
* It returns a promise that should be resolved with an updated version of the poller's operation.
*
* @param options - Optional properties passed to the operation's update method.
*
* @deprecated `cancel` has been deprecated because it was not implemented.
*/
cancel(options?: {
abortSignal?: AbortSignalLike;
}): Promise<PollOperation<TState, TResult>>;
/**
* Serializes the operation.
* Useful when wanting to create a poller that monitors an existing operation.
*/
toString(): string;
}
//# sourceMappingURL=pollOperation.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"pollOperation.d.ts","sourceRoot":"","sources":["../../../src/legacy/pollOperation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,kBAAkB,CAAC,OAAO;IACzC;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAa,CAAC,MAAM,EAAE,OAAO;IAC5C;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;;OAQG;IACH,MAAM,CAAC,OAAO,CAAC,EAAE;QACf,WAAW,CAAC,EAAE,eAAe,CAAC;QAC9B,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;KACxC,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAE5C;;;;;;;;;;OAUG;IACH,MAAM,CAAC,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAE7F;;;OAGG;IACH,QAAQ,IAAI,MAAM,CAAC;CACpB"}

View File

@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export {};
//# sourceMappingURL=pollOperation.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"pollOperation.js","sourceRoot":"","sources":["../../../src/legacy/pollOperation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortSignalLike } from \"@azure/abort-controller\";\n\n/**\n * PollOperationState contains an opinionated list of the smallest set of properties needed\n * to define any long running operation poller.\n *\n * While the Poller class works as the local control mechanism to start triggering, wait for,\n * and potentially cancel a long running operation, the PollOperationState documents the status\n * of the remote long running operation.\n *\n * It should be updated at least when the operation starts, when it's finished, and when it's cancelled.\n * Though, implementations can have any other number of properties that can be updated by other reasons.\n */\nexport interface PollOperationState<TResult> {\n /**\n * True if the operation has started.\n */\n isStarted?: boolean;\n /**\n * True if the operation has been completed.\n */\n isCompleted?: boolean;\n /**\n * True if the operation has been cancelled.\n */\n isCancelled?: boolean;\n /**\n * Will exist if the operation encountered any error.\n */\n error?: Error;\n /**\n * Will exist if the operation concluded in a result of an expected type.\n */\n result?: TResult;\n}\n\n/**\n * PollOperation is an interface that defines how to update the local reference of the state of the remote\n * long running operation, just as well as how to request the cancellation of the same operation.\n *\n * It also has a method to serialize the operation so that it can be stored and resumed at any time.\n */\nexport interface PollOperation<TState, TResult> {\n /**\n * The state of the operation.\n * It will be used to store the basic properties of PollOperationState<TResult>,\n * plus any custom property that the implementation may require.\n */\n state: TState;\n\n /**\n * Defines how to request the remote service for updates on the status of the long running operation.\n *\n * It optionally receives an object with an abortSignal property, from \\@azure/abort-controller's AbortSignalLike.\n * Also optionally receives a \"fireProgress\" function, which, if called, is responsible for triggering the\n * poller's onProgress callbacks.\n *\n * @param options - Optional properties passed to the operation's update method.\n */\n update(options?: {\n abortSignal?: AbortSignalLike;\n fireProgress?: (state: TState) => void;\n }): Promise<PollOperation<TState, TResult>>;\n\n /**\n * Attempts to cancel the underlying operation.\n *\n * It only optionally receives an object with an abortSignal property, from \\@azure/abort-controller's AbortSignalLike.\n *\n * It returns a promise that should be resolved with an updated version of the poller's operation.\n *\n * @param options - Optional properties passed to the operation's update method.\n *\n * @deprecated `cancel` has been deprecated because it was not implemented.\n */\n cancel(options?: { abortSignal?: AbortSignalLike }): Promise<PollOperation<TState, TResult>>;\n\n /**\n * Serializes the operation.\n * Useful when wanting to create a poller that monitors an existing operation.\n */\n toString(): string;\n}\n"]}

View File

@@ -0,0 +1,327 @@
import { PollOperation, PollOperationState } from "./pollOperation.js";
import { AbortSignalLike } from "@azure/abort-controller";
import { CancelOnProgress } from "../poller/models.js";
import { PollerLike } from "./models.js";
/**
* PollProgressCallback<TState> is the type of the callback functions sent to onProgress.
* These functions will receive a TState that is defined by your implementation of
* the Poller class.
*/
export type PollProgressCallback<TState> = (state: TState) => void;
/**
* When a poller is manually stopped through the `stopPolling` method,
* the poller will be rejected with an instance of the PollerStoppedError.
*/
export declare class PollerStoppedError extends Error {
constructor(message: string);
}
/**
* When the operation is cancelled, the poller will be rejected with an instance
* of the PollerCancelledError.
*/
export declare class PollerCancelledError extends Error {
constructor(message: string);
}
/**
* A class that represents the definition of a program that polls through consecutive requests
* until it reaches a state of completion.
*
* A poller can be executed manually, by polling request by request by calling to the `poll()` method repeatedly, until its operation is completed.
* It also provides a way to wait until the operation completes, by calling `pollUntilDone()` and waiting until the operation finishes.
* Pollers can also request the cancellation of the ongoing process to whom is providing the underlying long running operation.
*
* ```ts
* const poller = new MyPoller();
*
* // Polling just once:
* await poller.poll();
*
* // We can try to cancel the request here, by calling:
* //
* // await poller.cancelOperation();
* //
*
* // Getting the final result:
* const result = await poller.pollUntilDone();
* ```
*
* The Poller is defined by two types, a type representing the state of the poller, which
* must include a basic set of properties from `PollOperationState<TResult>`,
* and a return type defined by `TResult`, which can be anything.
*
* The Poller class implements the `PollerLike` interface, which allows poller implementations to avoid having
* to export the Poller's class directly, and instead only export the already instantiated poller with the PollerLike type.
*
* ```ts
* class Client {
* public async makePoller: PollerLike<MyOperationState, MyResult> {
* const poller = new MyPoller({});
* // It might be preferred to return the poller after the first request is made,
* // so that some information can be obtained right away.
* await poller.poll();
* return poller;
* }
* }
*
* const poller: PollerLike<MyOperationState, MyResult> = myClient.makePoller();
* ```
*
* A poller can be created through its constructor, then it can be polled until it's completed.
* At any point in time, the state of the poller can be obtained without delay through the getOperationState method.
* At any point in time, the intermediate forms of the result type can be requested without delay.
* Once the underlying operation is marked as completed, the poller will stop and the final value will be returned.
*
* ```ts
* const poller = myClient.makePoller();
* const state: MyOperationState = poller.getOperationState();
*
* // The intermediate result can be obtained at any time.
* const result: MyResult | undefined = poller.getResult();
*
* // The final result can only be obtained after the poller finishes.
* const result: MyResult = await poller.pollUntilDone();
* ```
*
*/
export declare abstract class Poller<TState extends PollOperationState<TResult>, TResult> implements PollerLike<TState, TResult> {
/** controls whether to throw an error if the operation failed or was canceled. */
protected resolveOnUnsuccessful: boolean;
private stopped;
private resolve?;
private reject?;
private pollOncePromise?;
private cancelPromise?;
private promise;
private pollProgressCallbacks;
/**
* The poller's operation is available in full to any of the methods of the Poller class
* and any class extending the Poller class.
*/
protected operation: PollOperation<TState, TResult>;
/**
* A poller needs to be initialized by passing in at least the basic properties of the `PollOperation<TState, TResult>`.
*
* When writing an implementation of a Poller, this implementation needs to deal with the initialization
* of any custom state beyond the basic definition of the poller. The basic poller assumes that the poller's
* operation has already been defined, at least its basic properties. The code below shows how to approach
* the definition of the constructor of a new custom poller.
*
* ```ts
* export class MyPoller extends Poller<MyOperationState, string> {
* constructor({
* // Anything you might need outside of the basics
* }) {
* let state: MyOperationState = {
* privateProperty: private,
* publicProperty: public,
* };
*
* const operation = {
* state,
* update,
* cancel,
* toString
* }
*
* // Sending the operation to the parent's constructor.
* super(operation);
*
* // You can assign more local properties here.
* }
* }
* ```
*
* Inside of this constructor, a new promise is created. This will be used to
* tell the user when the poller finishes (see `pollUntilDone()`). The promise's
* resolve and reject methods are also used internally to control when to resolve
* or reject anyone waiting for the poller to finish.
*
* The constructor of a custom implementation of a poller is where any serialized version of
* a previous poller's operation should be deserialized into the operation sent to the
* base constructor. For example:
*
* ```ts
* export class MyPoller extends Poller<MyOperationState, string> {
* constructor(
* baseOperation: string | undefined
* ) {
* let state: MyOperationState = {};
* if (baseOperation) {
* state = {
* ...JSON.parse(baseOperation).state,
* ...state
* };
* }
* const operation = {
* state,
* // ...
* }
* super(operation);
* }
* }
* ```
*
* @param operation - Must contain the basic properties of `PollOperation<State, TResult>`.
*/
constructor(operation: PollOperation<TState, TResult>);
/**
* Defines how much to wait between each poll request.
* This has to be implemented by your custom poller.
*
* \@azure/core-util has a simple implementation of a delay function that waits as many milliseconds as specified.
* This can be used as follows:
*
* ```ts
* import { delay } from "@azure/core-util";
*
* export class MyPoller extends Poller<MyOperationState, string> {
* // The other necessary definitions.
*
* async delay(): Promise<void> {
* const milliseconds = 1000;
* return delay(milliseconds);
* }
* }
* ```
*
*/
protected abstract delay(): Promise<void>;
/**
* Starts a loop that will break only if the poller is done
* or if the poller is stopped.
*/
private startPolling;
/**
* pollOnce does one polling, by calling to the update method of the underlying
* poll operation to make any relevant change effective.
*
* It only optionally receives an object with an abortSignal property, from \@azure/abort-controller's AbortSignalLike.
*
* @param options - Optional properties passed to the operation's update method.
*/
private pollOnce;
/**
* fireProgress calls the functions passed in via onProgress the method of the poller.
*
* It loops over all of the callbacks received from onProgress, and executes them, sending them
* the current operation state.
*
* @param state - The current operation state.
*/
private fireProgress;
/**
* Invokes the underlying operation's cancel method.
*/
private cancelOnce;
/**
* Returns a promise that will resolve once a single polling request finishes.
* It does this by calling the update method of the Poller's operation.
*
* It only optionally receives an object with an abortSignal property, from \@azure/abort-controller's AbortSignalLike.
*
* @param options - Optional properties passed to the operation's update method.
*/
poll(options?: {
abortSignal?: AbortSignalLike;
}): Promise<void>;
private processUpdatedState;
/**
* Returns a promise that will resolve once the underlying operation is completed.
*/
pollUntilDone(pollOptions?: {
abortSignal?: AbortSignalLike;
}): Promise<TResult>;
/**
* Invokes the provided callback after each polling is completed,
* sending the current state of the poller's operation.
*
* It returns a method that can be used to stop receiving updates on the given callback function.
*/
onProgress(callback: (state: TState) => void): CancelOnProgress;
/**
* Returns true if the poller has finished polling.
*/
isDone(): boolean;
/**
* Stops the poller from continuing to poll.
*/
stopPolling(): void;
/**
* Returns true if the poller is stopped.
*/
isStopped(): boolean;
/**
* Attempts to cancel the underlying operation.
*
* It only optionally receives an object with an abortSignal property, from \@azure/abort-controller's AbortSignalLike.
*
* If it's called again before it finishes, it will throw an error.
*
* @param options - Optional properties passed to the operation's update method.
*/
cancelOperation(options?: {
abortSignal?: AbortSignalLike;
}): Promise<void>;
/**
* Returns the state of the operation.
*
* Even though TState will be the same type inside any of the methods of any extension of the Poller class,
* implementations of the pollers can customize what's shared with the public by writing their own
* version of the `getOperationState` method, and by defining two types, one representing the internal state of the poller
* and a public type representing a safe to share subset of the properties of the internal state.
* Their definition of getOperationState can then return their public type.
*
* Example:
*
* ```ts
* // Let's say we have our poller's operation state defined as:
* interface MyOperationState extends PollOperationState<ResultType> {
* privateProperty?: string;
* publicProperty?: string;
* }
*
* // To allow us to have a true separation of public and private state, we have to define another interface:
* interface PublicState extends PollOperationState<ResultType> {
* publicProperty?: string;
* }
*
* // Then, we define our Poller as follows:
* export class MyPoller extends Poller<MyOperationState, ResultType> {
* // ... More content is needed here ...
*
* public getOperationState(): PublicState {
* const state: PublicState = this.operation.state;
* return {
* // Properties from PollOperationState<TResult>
* isStarted: state.isStarted,
* isCompleted: state.isCompleted,
* isCancelled: state.isCancelled,
* error: state.error,
* result: state.result,
*
* // The only other property needed by PublicState.
* publicProperty: state.publicProperty
* }
* }
* }
* ```
*
* You can see this in the tests of this repository, go to the file:
* `../test/utils/testPoller.ts`
* and look for the getOperationState implementation.
*/
getOperationState(): TState;
/**
* Returns the result value of the operation,
* regardless of the state of the poller.
* It can return undefined or an incomplete form of the final TResult value
* depending on the implementation.
*/
getResult(): TResult | undefined;
/**
* Returns a serialized version of the poller's operation
* by invoking the operation's toString method.
*/
toString(): string;
}
//# sourceMappingURL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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgEG;gBACS,SAAS,EAAE,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC;IAmBrD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,SAAS,CAAC,QAAQ,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAEzC;;;OAGG;YACW,YAAY;IAU1B;;;;;;;OAOG;YACW,QAAQ;IAUtB;;;;;;;OAOG;IACH,OAAO,CAAC,YAAY;IAMpB;;OAEG;YACW,UAAU;IAIxB;;;;;;;OAOG;IACI,IAAI,CAAC,OAAO,GAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAW3E,OAAO,CAAC,mBAAmB;IA0B3B;;OAEG;IACU,aAAa,CACxB,WAAW,GAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAO,GAClD,OAAO,CAAC,OAAO,CAAC;IAUnB;;;;;OAKG;IACI,UAAU,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,gBAAgB;IAOtE;;OAEG;IACI,MAAM,IAAI,OAAO;IAKxB;;OAEG;IACI,WAAW,IAAI,IAAI;IAS1B;;OAEG;IACI,SAAS,IAAI,OAAO;IAI3B;;;;;;;;OAQG;IACI,eAAe,CAAC,OAAO,GAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAStF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+CG;IACI,iBAAiB,IAAI,MAAM;IAIlC;;;;;OAKG;IACI,SAAS,IAAI,OAAO,GAAG,SAAS;IAKvC;;;OAGG;IACI,QAAQ,IAAI,MAAM;CAG1B"}

View File

@@ -0,0 +1,397 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* When a poller is manually stopped through the `stopPolling` method,
* the poller will be rejected with an instance of the PollerStoppedError.
*/
export class PollerStoppedError extends Error {
constructor(message) {
super(message);
this.name = "PollerStoppedError";
Object.setPrototypeOf(this, PollerStoppedError.prototype);
}
}
/**
* When the operation is cancelled, the poller will be rejected with an instance
* of the PollerCancelledError.
*/
export class PollerCancelledError extends Error {
constructor(message) {
super(message);
this.name = "PollerCancelledError";
Object.setPrototypeOf(this, PollerCancelledError.prototype);
}
}
/**
* A class that represents the definition of a program that polls through consecutive requests
* until it reaches a state of completion.
*
* A poller can be executed manually, by polling request by request by calling to the `poll()` method repeatedly, until its operation is completed.
* It also provides a way to wait until the operation completes, by calling `pollUntilDone()` and waiting until the operation finishes.
* Pollers can also request the cancellation of the ongoing process to whom is providing the underlying long running operation.
*
* ```ts
* const poller = new MyPoller();
*
* // Polling just once:
* await poller.poll();
*
* // We can try to cancel the request here, by calling:
* //
* // await poller.cancelOperation();
* //
*
* // Getting the final result:
* const result = await poller.pollUntilDone();
* ```
*
* The Poller is defined by two types, a type representing the state of the poller, which
* must include a basic set of properties from `PollOperationState<TResult>`,
* and a return type defined by `TResult`, which can be anything.
*
* The Poller class implements the `PollerLike` interface, which allows poller implementations to avoid having
* to export the Poller's class directly, and instead only export the already instantiated poller with the PollerLike type.
*
* ```ts
* class Client {
* public async makePoller: PollerLike<MyOperationState, MyResult> {
* const poller = new MyPoller({});
* // It might be preferred to return the poller after the first request is made,
* // so that some information can be obtained right away.
* await poller.poll();
* return poller;
* }
* }
*
* const poller: PollerLike<MyOperationState, MyResult> = myClient.makePoller();
* ```
*
* A poller can be created through its constructor, then it can be polled until it's completed.
* At any point in time, the state of the poller can be obtained without delay through the getOperationState method.
* At any point in time, the intermediate forms of the result type can be requested without delay.
* Once the underlying operation is marked as completed, the poller will stop and the final value will be returned.
*
* ```ts
* const poller = myClient.makePoller();
* const state: MyOperationState = poller.getOperationState();
*
* // The intermediate result can be obtained at any time.
* const result: MyResult | undefined = poller.getResult();
*
* // The final result can only be obtained after the poller finishes.
* const result: MyResult = await poller.pollUntilDone();
* ```
*
*/
// eslint-disable-next-line no-use-before-define
export class Poller {
/**
* A poller needs to be initialized by passing in at least the basic properties of the `PollOperation<TState, TResult>`.
*
* When writing an implementation of a Poller, this implementation needs to deal with the initialization
* of any custom state beyond the basic definition of the poller. The basic poller assumes that the poller's
* operation has already been defined, at least its basic properties. The code below shows how to approach
* the definition of the constructor of a new custom poller.
*
* ```ts
* export class MyPoller extends Poller<MyOperationState, string> {
* constructor({
* // Anything you might need outside of the basics
* }) {
* let state: MyOperationState = {
* privateProperty: private,
* publicProperty: public,
* };
*
* const operation = {
* state,
* update,
* cancel,
* toString
* }
*
* // Sending the operation to the parent's constructor.
* super(operation);
*
* // You can assign more local properties here.
* }
* }
* ```
*
* Inside of this constructor, a new promise is created. This will be used to
* tell the user when the poller finishes (see `pollUntilDone()`). The promise's
* resolve and reject methods are also used internally to control when to resolve
* or reject anyone waiting for the poller to finish.
*
* The constructor of a custom implementation of a poller is where any serialized version of
* a previous poller's operation should be deserialized into the operation sent to the
* base constructor. For example:
*
* ```ts
* export class MyPoller extends Poller<MyOperationState, string> {
* constructor(
* baseOperation: string | undefined
* ) {
* let state: MyOperationState = {};
* if (baseOperation) {
* state = {
* ...JSON.parse(baseOperation).state,
* ...state
* };
* }
* const operation = {
* state,
* // ...
* }
* super(operation);
* }
* }
* ```
*
* @param operation - Must contain the basic properties of `PollOperation<State, TResult>`.
*/
constructor(operation) {
/** controls whether to throw an error if the operation failed or was canceled. */
this.resolveOnUnsuccessful = false;
this.stopped = true;
this.pollProgressCallbacks = [];
this.operation = operation;
this.promise = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
// This prevents the UnhandledPromiseRejectionWarning in node.js from being thrown.
// The above warning would get thrown if `poller.poll` is called, it returns an error,
// and pullUntilDone did not have a .catch or await try/catch on it's return value.
this.promise.catch(() => {
/* intentionally blank */
});
}
/**
* Starts a loop that will break only if the poller is done
* or if the poller is stopped.
*/
async startPolling(pollOptions = {}) {
if (this.stopped) {
this.stopped = false;
}
while (!this.isStopped() && !this.isDone()) {
await this.poll(pollOptions);
await this.delay();
}
}
/**
* pollOnce does one polling, by calling to the update method of the underlying
* poll operation to make any relevant change effective.
*
* It only optionally receives an object with an abortSignal property, from \@azure/abort-controller's AbortSignalLike.
*
* @param options - Optional properties passed to the operation's update method.
*/
async pollOnce(options = {}) {
if (!this.isDone()) {
this.operation = await this.operation.update({
abortSignal: options.abortSignal,
fireProgress: this.fireProgress.bind(this),
});
}
this.processUpdatedState();
}
/**
* fireProgress calls the functions passed in via onProgress the method of the poller.
*
* It loops over all of the callbacks received from onProgress, and executes them, sending them
* the current operation state.
*
* @param state - The current operation state.
*/
fireProgress(state) {
for (const callback of this.pollProgressCallbacks) {
callback(state);
}
}
/**
* Invokes the underlying operation's cancel method.
*/
async cancelOnce(options = {}) {
this.operation = await this.operation.cancel(options);
}
/**
* Returns a promise that will resolve once a single polling request finishes.
* It does this by calling the update method of the Poller's operation.
*
* It only optionally receives an object with an abortSignal property, from \@azure/abort-controller's AbortSignalLike.
*
* @param options - Optional properties passed to the operation's update method.
*/
poll(options = {}) {
if (!this.pollOncePromise) {
this.pollOncePromise = this.pollOnce(options);
const clearPollOncePromise = () => {
this.pollOncePromise = undefined;
};
this.pollOncePromise.then(clearPollOncePromise, clearPollOncePromise).catch(this.reject);
}
return this.pollOncePromise;
}
processUpdatedState() {
if (this.operation.state.error) {
this.stopped = true;
if (!this.resolveOnUnsuccessful) {
this.reject(this.operation.state.error);
throw this.operation.state.error;
}
}
if (this.operation.state.isCancelled) {
this.stopped = true;
if (!this.resolveOnUnsuccessful) {
const error = new PollerCancelledError("Operation was canceled");
this.reject(error);
throw error;
}
}
if (this.isDone() && this.resolve) {
// If the poller has finished polling, this means we now have a result.
// However, it can be the case that TResult is instantiated to void, so
// we are not expecting a result anyway. To assert that we might not
// have a result eventually after finishing polling, we cast the result
// to TResult.
this.resolve(this.getResult());
}
}
/**
* Returns a promise that will resolve once the underlying operation is completed.
*/
async pollUntilDone(pollOptions = {}) {
if (this.stopped) {
this.startPolling(pollOptions).catch(this.reject);
}
// This is needed because the state could have been updated by
// `cancelOperation`, e.g. the operation is canceled or an error occurred.
this.processUpdatedState();
return this.promise;
}
/**
* Invokes the provided callback after each polling is completed,
* sending the current state of the poller's operation.
*
* It returns a method that can be used to stop receiving updates on the given callback function.
*/
onProgress(callback) {
this.pollProgressCallbacks.push(callback);
return () => {
this.pollProgressCallbacks = this.pollProgressCallbacks.filter((c) => c !== callback);
};
}
/**
* Returns true if the poller has finished polling.
*/
isDone() {
const state = this.operation.state;
return Boolean(state.isCompleted || state.isCancelled || state.error);
}
/**
* Stops the poller from continuing to poll.
*/
stopPolling() {
if (!this.stopped) {
this.stopped = true;
if (this.reject) {
this.reject(new PollerStoppedError("This poller is already stopped"));
}
}
}
/**
* Returns true if the poller is stopped.
*/
isStopped() {
return this.stopped;
}
/**
* Attempts to cancel the underlying operation.
*
* It only optionally receives an object with an abortSignal property, from \@azure/abort-controller's AbortSignalLike.
*
* If it's called again before it finishes, it will throw an error.
*
* @param options - Optional properties passed to the operation's update method.
*/
cancelOperation(options = {}) {
if (!this.cancelPromise) {
this.cancelPromise = this.cancelOnce(options);
}
else if (options.abortSignal) {
throw new Error("A cancel request is currently pending");
}
return this.cancelPromise;
}
/**
* Returns the state of the operation.
*
* Even though TState will be the same type inside any of the methods of any extension of the Poller class,
* implementations of the pollers can customize what's shared with the public by writing their own
* version of the `getOperationState` method, and by defining two types, one representing the internal state of the poller
* and a public type representing a safe to share subset of the properties of the internal state.
* Their definition of getOperationState can then return their public type.
*
* Example:
*
* ```ts
* // Let's say we have our poller's operation state defined as:
* interface MyOperationState extends PollOperationState<ResultType> {
* privateProperty?: string;
* publicProperty?: string;
* }
*
* // To allow us to have a true separation of public and private state, we have to define another interface:
* interface PublicState extends PollOperationState<ResultType> {
* publicProperty?: string;
* }
*
* // Then, we define our Poller as follows:
* export class MyPoller extends Poller<MyOperationState, ResultType> {
* // ... More content is needed here ...
*
* public getOperationState(): PublicState {
* const state: PublicState = this.operation.state;
* return {
* // Properties from PollOperationState<TResult>
* isStarted: state.isStarted,
* isCompleted: state.isCompleted,
* isCancelled: state.isCancelled,
* error: state.error,
* result: state.result,
*
* // The only other property needed by PublicState.
* publicProperty: state.publicProperty
* }
* }
* }
* ```
*
* You can see this in the tests of this repository, go to the file:
* `../test/utils/testPoller.ts`
* and look for the getOperationState implementation.
*/
getOperationState() {
return this.operation.state;
}
/**
* Returns the result value of the operation,
* regardless of the state of the poller.
* It can return undefined or an incomplete form of the final TResult value
* depending on the implementation.
*/
getResult() {
const state = this.operation.state;
return state.result;
}
/**
* Returns a serialized version of the poller's operation
* by invoking the operation's toString method.
*/
toString() {
return this.operation.toString();
}
}
//# sourceMappingURL=poller.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,6 @@
/**
* The `@azure/logger` configuration for this package.
* @internal
*/
export declare const logger: import("@azure/logger").AzureLogger;
//# sourceMappingURL=logger.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,eAAO,MAAM,MAAM,qCAAiC,CAAC"}

9
node_modules/@azure/core-lro/dist/browser/logger.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { createClientLogger } from "@azure/logger";
/**
* The `@azure/logger` configuration for this package.
* @internal
*/
export const logger = createClientLogger("core-lro");
//# sourceMappingURL=logger.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createClientLogger } from \"@azure/logger\";\n\n/**\n * The `@azure/logger` configuration for this package.\n * @internal\n */\nexport const logger = createClientLogger(\"core-lro\");\n"]}

View File

@@ -0,0 +1,3 @@
{
"type": "module"
}

View File

@@ -0,0 +1,9 @@
/**
* The default time interval to wait before sending the next polling request.
*/
export declare const POLL_INTERVAL_IN_MS = 2000;
/**
* The closed set of terminal states.
*/
export declare const terminalStates: string[];
//# sourceMappingURL=constants.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/poller/constants.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,mBAAmB,OAAO,CAAC;AACxC;;GAEG;AACH,eAAO,MAAM,cAAc,UAAsC,CAAC"}

View File

@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* The default time interval to wait before sending the next polling request.
*/
export const POLL_INTERVAL_IN_MS = 2000;
/**
* The closed set of terminal states.
*/
export const terminalStates = ["succeeded", "canceled", "failed"];
//# sourceMappingURL=constants.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/poller/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AACxC;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * The default time interval to wait before sending the next polling request.\n */\nexport const POLL_INTERVAL_IN_MS = 2000;\n/**\n * The closed set of terminal states.\n */\nexport const terminalStates = [\"succeeded\", \"canceled\", \"failed\"];\n"]}

View File

@@ -0,0 +1,221 @@
import { AbortSignalLike } from "@azure/abort-controller";
/**
* Configurations for how to poll the operation and to check whether it has
* terminated.
*/
export interface OperationConfig {
/** The operation location */
operationLocation?: string;
/** The resource location */
resourceLocation?: string;
/** metadata about the operation */
metadata?: Record<string, string>;
}
/**
* The description of an operation.
*/
export interface Operation<TResponse, TOptions> {
/**
* Sends the initiation request and returns, in addition to the response, the
* operation location, the potential resource location, and a set of metadata.
*/
init: () => Promise<OperationConfig & {
response: TResponse;
}>;
/**
* Sends the polling request.
*/
poll: (location: string, options?: TOptions) => Promise<TResponse>;
}
/**
* Type of a restorable long-running operation.
*/
export type RestorableOperationState<T> = T & {
/** The operation configuration */
config: OperationConfig;
};
/**
* Options for `createPoller`.
*/
export interface CreatePollerOptions<TResponse, TResult, TState> {
/**
* Defines how much time the poller is going to wait before making a new request to the service.
*/
intervalInMs?: number;
/**
* A serialized poller which can be used to resume an existing paused Long-Running-Operation.
*/
restoreFrom?: string;
/**
* A function to process the result of the LRO.
*/
processResult?: (result: TResponse, state: TState) => TResult;
/**
* A function to process the state of the LRO.
*/
updateState?: (state: TState, lastResponse: TResponse) => void;
/**
* A function to be called each time the operation location is updated by the
* service.
*/
withOperationLocation?: (operationLocation: string) => void;
}
export interface LroError {
code: string;
innererror?: InnerError;
message: string;
}
export interface InnerError {
code: string;
message: string;
innererror?: InnerError;
}
/**
* Options for `buildCreatePoller`.
*/
export interface BuildCreatePollerOptions<TResponse, TState> {
/**
* Gets the status of the operation from the response received when the
* operation was initialized. Note that the operation could be already in
* a terminal state at this time.
*/
getStatusFromInitialResponse: (inputs: {
response: TResponse;
state: RestorableOperationState<TState>;
operationLocation?: string;
}) => OperationStatus;
/**
* Gets the status of the operation from a response received when the
* operation was polled.
*/
getStatusFromPollResponse: (response: TResponse, state: RestorableOperationState<TState>) => OperationStatus;
/**
* Determines if the input error is an operation error.
*/
isOperationError: (error: Error) => boolean;
/**
* Gets the updated operation location from polling responses.
*/
getOperationLocation?: (response: TResponse, state: RestorableOperationState<TState>) => string | undefined;
/**
* Gets the resource location from a response.
*/
getResourceLocation: (response: TResponse, state: RestorableOperationState<TState>) => string | undefined;
/**
* Gets from the response the time interval the service suggests the client to
* wait before sending the next polling request.
*/
getPollingInterval?: (response: TResponse) => number | undefined;
/**
* Extracts an error model from a response.
*/
getError?: (response: TResponse) => LroError | undefined;
/**
* Control whether to throw an exception if the operation failed or was canceled.
*/
resolveOnUnsuccessful: boolean;
}
/**
* The set of possible states an operation can be in at any given time.
*/
export type OperationStatus = "notStarted" | "running" | "succeeded" | "canceled" | "failed";
/**
* While the poller works as the local control mechanism to start triggering and
* wait for a long-running operation, OperationState documents the status of
* the remote long-running operation. It gets updated after each poll.
*/
export interface OperationState<TResult> {
/**
* The current status of the operation.
*/
status: OperationStatus;
/**
* Will exist if the operation encountered any error.
*/
error?: Error;
/**
* Will exist if the operation produced a result of the expected type.
*/
result?: TResult;
}
/**
* CancelOnProgress is used as the return value of a Poller's onProgress method.
* When a user invokes onProgress, they're required to pass in a function that will be
* called as a callback with the new data received each time the poll operation is updated.
* onProgress returns a function that will prevent any further update to reach the original callback.
*/
export type CancelOnProgress = () => void;
/**
* A simple poller interface.
*/
export interface SimplePollerLike<TState extends OperationState<TResult>, TResult> {
/**
* Returns a promise that will resolve once a single polling request finishes.
* It does this by calling the update method of the Poller's operation.
*/
poll(options?: {
abortSignal?: AbortSignalLike;
}): Promise<void>;
/**
* Returns a promise that will resolve once the underlying operation is completed.
*/
pollUntilDone(pollOptions?: {
abortSignal?: AbortSignalLike;
}): Promise<TResult>;
/**
* Invokes the provided callback after each polling is completed,
* sending the current state of the poller's operation.
*
* It returns a method that can be used to stop receiving updates on the given callback function.
*/
onProgress(callback: (state: TState) => void): CancelOnProgress;
/**
* Returns true if the poller has finished polling.
*/
isDone(): boolean;
/**
* Stops the poller. After this, no manual or automated requests can be sent.
*/
stopPolling(): void;
/**
* Returns true if the poller is stopped.
*/
isStopped(): boolean;
/**
* Returns the state of the operation.
*/
getOperationState(): TState;
/**
* Returns the result value of the operation,
* regardless of the state of the poller.
* It can return undefined or an incomplete form of the final TResult value
* depending on the implementation.
*/
getResult(): TResult | undefined;
/**
* Returns a serialized version of the poller's operation
* by invoking the operation's toString method.
*/
toString(): string;
}
/**
* A state proxy that allows poller implementation to abstract away the operation
* state. This is useful to implement `lroEngine` and `createPoller` in a modular
* way.
*/
export interface StateProxy<TState, TResult> {
initState: (config: OperationConfig) => RestorableOperationState<TState>;
setRunning: (state: TState) => void;
setCanceled: (state: TState) => void;
setResult: (state: TState, result: TResult) => void;
setError: (state: TState, error: Error) => void;
setFailed: (state: TState) => void;
setSucceeded: (state: TState) => void;
isRunning: (state: TState) => boolean;
isCanceled: (state: TState) => boolean;
getResult: (state: TState) => TResult | undefined;
getError: (state: TState) => Error | undefined;
isFailed: (state: TState) => boolean;
isSucceeded: (state: TState) => boolean;
}
//# sourceMappingURL=models.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../src/poller/models.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,6BAA6B;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,4BAA4B;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mCAAmC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,SAAS,EAAE,QAAQ;IAC5C;;;OAGG;IACH,IAAI,EAAE,MAAM,OAAO,CACjB,eAAe,GAAG;QAChB,QAAQ,EAAE,SAAS,CAAC;KACrB,CACF,CAAC;IACF;;OAEG;IACH,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;CACpE;AAED;;GAEG;AACH,MAAM,MAAM,wBAAwB,CAAC,CAAC,IAAI,C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,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IACrC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;CACzC"}

View File

@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export {};
//# sourceMappingURL=models.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,40 @@
import { LroError, Operation, OperationStatus, RestorableOperationState, StateProxy } from "./models.js";
/**
* Deserializes the state
*/
export declare function deserializeState<TState>(serializedState: string): RestorableOperationState<TState>;
/**
* Initiates the long-running operation.
*/
export declare function initOperation<TResponse, TResult, TState>(inputs: {
init: Operation<TResponse, unknown>["init"];
stateProxy: StateProxy<TState, TResult>;
getOperationStatus: (inputs: {
response: TResponse;
state: RestorableOperationState<TState>;
operationLocation?: string;
}) => OperationStatus;
processResult?: (result: TResponse, state: TState) => TResult;
withOperationLocation?: (operationLocation: string, isUpdated: boolean) => void;
setErrorAsResult: boolean;
}): Promise<RestorableOperationState<TState>>;
/** Polls the long-running operation. */
export declare function pollOperation<TResponse, TState, TResult, TOptions>(inputs: {
poll: Operation<TResponse, TOptions>["poll"];
stateProxy: StateProxy<TState, TResult>;
state: RestorableOperationState<TState>;
getOperationStatus: (response: TResponse, state: RestorableOperationState<TState>) => OperationStatus;
getResourceLocation: (response: TResponse, state: RestorableOperationState<TState>) => string | undefined;
isOperationError: (error: Error) => boolean;
getPollingInterval?: (response: TResponse) => number | undefined;
setDelay: (intervalInMs: number) => void;
getOperationLocation?: (response: TResponse, state: RestorableOperationState<TState>) => string | undefined;
withOperationLocation?: (operationLocation: string, isUpdated: boolean) => void;
processResult?: (result: TResponse, state: TState) => TResult;
getError?: (response: TResponse) => LroError | undefined;
updateState?: (state: TState, lastResponse: TResponse) => void;
isDone?: (lastResponse: TResponse, state: TState) => boolean;
setErrorAsResult: boolean;
options?: TOptions;
}): Promise<void>;
//# sourceMappingURL=operation.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"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js";
import { terminalStates } from "./constants.js";
/**
* Deserializes the state
*/
export function deserializeState(serializedState) {
try {
return JSON.parse(serializedState).state;
}
catch (e) {
throw new Error(`Unable to deserialize input state: ${serializedState}`);
}
}
function setStateError(inputs) {
const { state, stateProxy, isOperationError } = inputs;
return (error) => {
if (isOperationError(error)) {
stateProxy.setError(state, error);
stateProxy.setFailed(state);
}
throw error;
};
}
function appendReadableErrorMessage(currentMessage, innerMessage) {
let message = currentMessage;
if (message.slice(-1) !== ".") {
message = message + ".";
}
return message + " " + innerMessage;
}
function simplifyError(err) {
let message = err.message;
let code = err.code;
let curErr = err;
while (curErr.innererror) {
curErr = curErr.innererror;
code = curErr.code;
message = appendReadableErrorMessage(message, curErr.message);
}
return {
code,
message,
};
}
function processOperationStatus(result) {
const { state, stateProxy, status, isDone, processResult, getError, response, setErrorAsResult } = result;
switch (status) {
case "succeeded": {
stateProxy.setSucceeded(state);
break;
}
case "failed": {
const err = getError === null || getError === void 0 ? void 0 : getError(response);
let postfix = "";
if (err) {
const { code, message } = simplifyError(err);
postfix = `. ${code}. ${message}`;
}
const errStr = `The long-running operation has failed${postfix}`;
stateProxy.setError(state, new Error(errStr));
stateProxy.setFailed(state);
logger.warning(errStr);
break;
}
case "canceled": {
stateProxy.setCanceled(state);
break;
}
}
if ((isDone === null || isDone === void 0 ? void 0 : isDone(response, state)) ||
(isDone === undefined &&
["succeeded", "canceled"].concat(setErrorAsResult ? [] : ["failed"]).includes(status))) {
stateProxy.setResult(state, buildResult({
response,
state,
processResult,
}));
}
}
function buildResult(inputs) {
const { processResult, response, state } = inputs;
return processResult ? processResult(response, state) : response;
}
/**
* Initiates the long-running operation.
*/
export async function initOperation(inputs) {
const { init, stateProxy, processResult, getOperationStatus, withOperationLocation, setErrorAsResult, } = inputs;
const { operationLocation, resourceLocation, metadata, response } = await init();
if (operationLocation)
withOperationLocation === null || withOperationLocation === void 0 ? void 0 : withOperationLocation(operationLocation, false);
const config = {
metadata,
operationLocation,
resourceLocation,
};
logger.verbose(`LRO: Operation description:`, config);
const state = stateProxy.initState(config);
const status = getOperationStatus({ response, state, operationLocation });
processOperationStatus({ state, status, stateProxy, response, setErrorAsResult, processResult });
return state;
}
async function pollOperationHelper(inputs) {
const { poll, state, stateProxy, operationLocation, getOperationStatus, getResourceLocation, isOperationError, options, } = inputs;
const response = await poll(operationLocation, options).catch(setStateError({
state,
stateProxy,
isOperationError,
}));
const status = getOperationStatus(response, state);
logger.verbose(`LRO: Status:\n\tPolling from: ${state.config.operationLocation}\n\tOperation status: ${status}\n\tPolling status: ${terminalStates.includes(status) ? "Stopped" : "Running"}`);
if (status === "succeeded") {
const resourceLocation = getResourceLocation(response, state);
if (resourceLocation !== undefined) {
return {
response: await poll(resourceLocation).catch(setStateError({ state, stateProxy, isOperationError })),
status,
};
}
}
return { response, status };
}
/** Polls the long-running operation. */
export async function pollOperation(inputs) {
const { poll, state, stateProxy, options, getOperationStatus, getResourceLocation, getOperationLocation, isOperationError, withOperationLocation, getPollingInterval, processResult, getError, updateState, setDelay, isDone, setErrorAsResult, } = inputs;
const { operationLocation } = state.config;
if (operationLocation !== undefined) {
const { response, status } = await pollOperationHelper({
poll,
getOperationStatus,
state,
stateProxy,
operationLocation,
getResourceLocation,
isOperationError,
options,
});
processOperationStatus({
status,
response,
state,
stateProxy,
isDone,
processResult,
getError,
setErrorAsResult,
});
if (!terminalStates.includes(status)) {
const intervalInMs = getPollingInterval === null || getPollingInterval === void 0 ? void 0 : getPollingInterval(response);
if (intervalInMs)
setDelay(intervalInMs);
const location = getOperationLocation === null || getOperationLocation === void 0 ? void 0 : getOperationLocation(response, state);
if (location !== undefined) {
const isUpdated = operationLocation !== location;
state.config.operationLocation = location;
withOperationLocation === null || withOperationLocation === void 0 ? void 0 : withOperationLocation(location, isUpdated);
}
else
withOperationLocation === null || withOperationLocation === void 0 ? void 0 : withOperationLocation(operationLocation, false);
}
updateState === null || updateState === void 0 ? void 0 : updateState(state, response);
}
}
//# sourceMappingURL=operation.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,9 @@
import { AbortSignalLike } from "@azure/abort-controller";
import { BuildCreatePollerOptions, CreatePollerOptions, Operation, OperationState, SimplePollerLike } from "./models.js";
/**
* Returns a poller factory.
*/
export declare function buildCreatePoller<TResponse, TResult, TState extends OperationState<TResult>>(inputs: BuildCreatePollerOptions<TResponse, TState>): (lro: Operation<TResponse, {
abortSignal?: AbortSignalLike;
}>, options?: CreatePollerOptions<TResponse, TResult, TState>) => Promise<SimplePollerLike<TState, TResult>>;
//# sourceMappingURL=poller.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"poller.d.ts","sourceRoot":"","sources":["../../../src/poller/poller.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,SAAS,EACT,cAAc,EAEd,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AA8BrB;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,cAAc,CAAC,OAAO,CAAC,EAC1F,MAAM,EAAE,wBAAwB,CAAC,SAAS,EAAE,MAAM,CAAC,GAClD,CACD,GAAG,EAAE,SAAS,CAAC,SAAS,EAAE;IAAE,WAAW,CAAC,EAAE,eAAe,CAAA;CAAE,CAAC,EAC5D,OAAO,CAAC,EAAE,mBAAmB,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,KACtD,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA6J9C"}

View File

@@ -0,0 +1,170 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { deserializeState, initOperation, pollOperation } from "./operation.js";
import { POLL_INTERVAL_IN_MS } from "./constants.js";
import { delay } from "@azure/core-util";
const createStateProxy = () => ({
/**
* The state at this point is created to be of type OperationState<TResult>.
* It will be updated later to be of type TState when the
* customer-provided callback, `updateState`, is called during polling.
*/
initState: (config) => ({ status: "running", config }),
setCanceled: (state) => (state.status = "canceled"),
setError: (state, error) => (state.error = error),
setResult: (state, result) => (state.result = result),
setRunning: (state) => (state.status = "running"),
setSucceeded: (state) => (state.status = "succeeded"),
setFailed: (state) => (state.status = "failed"),
getError: (state) => state.error,
getResult: (state) => state.result,
isCanceled: (state) => state.status === "canceled",
isFailed: (state) => state.status === "failed",
isRunning: (state) => state.status === "running",
isSucceeded: (state) => state.status === "succeeded",
});
/**
* Returns a poller factory.
*/
export function buildCreatePoller(inputs) {
const { getOperationLocation, getStatusFromInitialResponse, getStatusFromPollResponse, isOperationError, getResourceLocation, getPollingInterval, getError, resolveOnUnsuccessful, } = inputs;
return async ({ init, poll }, options) => {
const { processResult, updateState, withOperationLocation: withOperationLocationCallback, intervalInMs = POLL_INTERVAL_IN_MS, restoreFrom, } = options || {};
const stateProxy = createStateProxy();
const withOperationLocation = withOperationLocationCallback
? (() => {
let called = false;
return (operationLocation, isUpdated) => {
if (isUpdated)
withOperationLocationCallback(operationLocation);
else if (!called)
withOperationLocationCallback(operationLocation);
called = true;
};
})()
: undefined;
const state = restoreFrom
? deserializeState(restoreFrom)
: await initOperation({
init,
stateProxy,
processResult,
getOperationStatus: getStatusFromInitialResponse,
withOperationLocation,
setErrorAsResult: !resolveOnUnsuccessful,
});
let resultPromise;
const abortController = new AbortController();
const handlers = new Map();
const handleProgressEvents = async () => handlers.forEach((h) => h(state));
const cancelErrMsg = "Operation was canceled";
let currentPollIntervalInMs = intervalInMs;
const poller = {
getOperationState: () => state,
getResult: () => state.result,
isDone: () => ["succeeded", "failed", "canceled"].includes(state.status),
isStopped: () => resultPromise === undefined,
stopPolling: () => {
abortController.abort();
},
toString: () => JSON.stringify({
state,
}),
onProgress: (callback) => {
const s = Symbol();
handlers.set(s, callback);
return () => handlers.delete(s);
},
pollUntilDone: (pollOptions) => (resultPromise !== null && resultPromise !== void 0 ? resultPromise : (resultPromise = (async () => {
const { abortSignal: inputAbortSignal } = pollOptions || {};
// In the future we can use AbortSignal.any() instead
function abortListener() {
abortController.abort();
}
const abortSignal = abortController.signal;
if (inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.aborted) {
abortController.abort();
}
else if (!abortSignal.aborted) {
inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.addEventListener("abort", abortListener, { once: true });
}
try {
if (!poller.isDone()) {
await poller.poll({ abortSignal });
while (!poller.isDone()) {
await delay(currentPollIntervalInMs, { abortSignal });
await poller.poll({ abortSignal });
}
}
}
finally {
inputAbortSignal === null || inputAbortSignal === void 0 ? void 0 : inputAbortSignal.removeEventListener("abort", abortListener);
}
if (resolveOnUnsuccessful) {
return poller.getResult();
}
else {
switch (state.status) {
case "succeeded":
return poller.getResult();
case "canceled":
throw new Error(cancelErrMsg);
case "failed":
throw state.error;
case "notStarted":
case "running":
throw new Error(`Polling completed without succeeding or failing`);
}
}
})().finally(() => {
resultPromise = undefined;
}))),
async poll(pollOptions) {
if (resolveOnUnsuccessful) {
if (poller.isDone())
return;
}
else {
switch (state.status) {
case "succeeded":
return;
case "canceled":
throw new Error(cancelErrMsg);
case "failed":
throw state.error;
}
}
await pollOperation({
poll,
state,
stateProxy,
getOperationLocation,
isOperationError,
withOperationLocation,
getPollingInterval,
getOperationStatus: getStatusFromPollResponse,
getResourceLocation,
processResult,
getError,
updateState,
options: pollOptions,
setDelay: (pollIntervalInMs) => {
currentPollIntervalInMs = pollIntervalInMs;
},
setErrorAsResult: !resolveOnUnsuccessful,
});
await handleProgressEvents();
if (!resolveOnUnsuccessful) {
switch (state.status) {
case "canceled":
throw new Error(cancelErrMsg);
case "failed":
throw state.error;
}
}
},
};
return poller;
};
}
//# sourceMappingURL=poller.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,106 @@
import { AbortSignalLike } from "@azure/abort-controller";
import { LroError } from "../poller/models.js";
/**
* The potential location of the result of the LRO if specified by the LRO extension in the swagger.
*/
export type LroResourceLocationConfig = "azure-async-operation" | "location" | "original-uri";
/**
* The type of a LRO response body. This is just a convenience type for checking the status of the operation.
*/
export interface ResponseBody extends Record<string, unknown> {
/** The status of the operation. */
status?: unknown;
/** The state of the provisioning process */
provisioningState?: unknown;
/** The properties of the provisioning process */
properties?: {
provisioningState?: unknown;
} & Record<string, unknown>;
/** The error if the operation failed */
error?: Partial<LroError>;
/** The location of the created resource */
resourceLocation?: string;
}
/**
* Simple type of the raw response.
*/
export interface RawResponse {
/** The HTTP status code */
statusCode: number;
/** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */
headers: {
[headerName: string]: string;
};
/** The parsed response body */
body?: unknown;
}
/**
* The type of the response of a LRO.
*/
export interface LroResponse<T = unknown> {
/** The flattened response */
flatResponse: T;
/** The raw response */
rawResponse: RawResponse;
}
/**
* Description of a long running operation.
*/
export interface LongRunningOperation<T = unknown> {
/**
* The request path. This should be set if the operation is a PUT and needs
* to poll from the same request path.
*/
requestPath?: string;
/**
* The HTTP request method. This should be set if the operation is a PUT or a
* DELETE.
*/
requestMethod?: string;
/**
* A function that can be used to send initial request to the service.
*/
sendInitialRequest: () => Promise<LroResponse<unknown>>;
/**
* A function that can be used to poll for the current status of a long running operation.
*/
sendPollRequest: (path: string, options?: {
abortSignal?: AbortSignalLike;
}) => Promise<LroResponse<T>>;
}
export type HttpOperationMode = "OperationLocation" | "ResourceLocation" | "Body";
/**
* Options for `createPoller`.
*/
export interface CreateHttpPollerOptions<TResult, TState> {
/**
* Defines how much time the poller is going to wait before making a new request to the service.
*/
intervalInMs?: number;
/**
* A serialized poller which can be used to resume an existing paused Long-Running-Operation.
*/
restoreFrom?: string;
/**
* The potential location of the result of the LRO if specified by the LRO extension in the swagger.
*/
resourceLocationConfig?: LroResourceLocationConfig;
/**
* A function to process the result of the LRO.
*/
processResult?: (result: unknown, state: TState) => TResult;
/**
* A function to process the state of the LRO.
*/
updateState?: (state: TState, response: LroResponse) => void;
/**
* A function to be called each time the operation location is updated by the
* service.
*/
withOperationLocation?: (operationLocation: string) => void;
/**
* Control whether to throw an exception if the operation failed or was canceled.
*/
resolveOnUnsuccessful?: boolean;
}
//# sourceMappingURL=models.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAG/C;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,uBAAuB,GAAG,UAAU,GAAG,cAAc,CAAC;AAE9F;;GAEG;AAEH,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC3D,mCAAmC;IACnC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,4CAA4C;IAC5C,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,iDAAiD;IACjD,UAAU,CAAC,EAAE;QAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvE,wCAAwC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1B,2CAA2C;IAC3C,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,iJAAiJ;IACjJ,OAAO,EAAE;QACP,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;KAC9B,CAAC;IACF,+BAA+B;IAC/B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAGD;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO;IACtC,6BAA6B;IAC7B,YAAY,EAAE,CAAC,CAAC;IAChB,uBAAuB;IACvB,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC,GAAG,OAAO;IAC/C;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,kBAAkB,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD;;OAEG;IACH,eAAe,EAAE,CACf,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAE,KACxC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9B;AAED,MAAM,MAAM,iBAAiB,GAAG,mBAAmB,GAAG,kBAAkB,GAAG,MAAM,CAAC;AAElF;;GAEG;AACH,MAAM,WAAW,uBAAuB,CAAC,OAAO,EAAE,MAAM;IACtD;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,sBAAsB,CAAC,EAAE,yBAAyB,CAAC;IACnD;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAC5D;;OAEG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,KAAK,IAAI,CAAC;IAC7D;;;OAGG;IACH,qBAAqB,CAAC,EAAE,CAAC,iBAAiB,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5D;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC"}

View File

@@ -0,0 +1,5 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=models.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/http/models.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { LroError } from \"../poller/models.js\";\n\n// TODO: rename to ResourceLocationConfig\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type LroResourceLocationConfig = \"azure-async-operation\" | \"location\" | \"original-uri\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse {\n /** The HTTP status code */\n statusCode: number;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n// TODO: rename to OperationResponse\n/**\n * The type of the response of a LRO.\n */\nexport interface LroResponse<T = unknown> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface LongRunningOperation<T = unknown> {\n /**\n * The request path. This should be set if the operation is a PUT and needs\n * to poll from the same request path.\n */\n requestPath?: string;\n /**\n * The HTTP request method. This should be set if the operation is a PUT or a\n * DELETE.\n */\n requestMethod?: string;\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<LroResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<LroResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: LroResourceLocationConfig;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => TResult;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: LroResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n"]}

View File

@@ -0,0 +1,47 @@
import { HttpOperationMode, LongRunningOperation, LroResourceLocationConfig, LroResponse, RawResponse } from "./models.js";
import { LroError, OperationConfig, OperationStatus, RestorableOperationState, StateProxy } from "../poller/models.js";
import { AbortSignalLike } from "@azure/abort-controller";
export declare function inferLroMode(inputs: {
rawResponse: RawResponse;
requestPath?: string;
requestMethod?: string;
resourceLocationConfig?: LroResourceLocationConfig;
}): (OperationConfig & {
mode: HttpOperationMode;
}) | undefined;
export declare function parseRetryAfter<T>({ rawResponse }: LroResponse<T>): number | undefined;
export declare function getErrorFromResponse<T>(response: LroResponse<T>): LroError | undefined;
export declare function getStatusFromInitialResponse<TState>(inputs: {
response: LroResponse<unknown>;
state: RestorableOperationState<TState>;
operationLocation?: string;
}): OperationStatus;
/**
* Initiates the long-running operation.
*/
export declare function initHttpOperation<TResult, TState>(inputs: {
stateProxy: StateProxy<TState, TResult>;
resourceLocationConfig?: LroResourceLocationConfig;
processResult?: (result: unknown, state: TState) => TResult;
setErrorAsResult: boolean;
lro: LongRunningOperation;
}): Promise<RestorableOperationState<TState>>;
export declare function getOperationLocation<TState>({ rawResponse }: LroResponse, state: RestorableOperationState<TState>): string | undefined;
export declare function getOperationStatus<TState>({ rawResponse }: LroResponse, state: RestorableOperationState<TState>): OperationStatus;
export declare function getResourceLocation<TState>(res: LroResponse, state: RestorableOperationState<TState>): string | undefined;
export declare function isOperationError(e: Error): boolean;
/** Polls the long-running operation. */
export declare function pollHttpOperation<TState, TResult>(inputs: {
lro: LongRunningOperation;
stateProxy: StateProxy<TState, TResult>;
processResult?: (result: unknown, state: TState) => TResult;
updateState?: (state: TState, lastResponse: LroResponse) => void;
isDone?: (lastResponse: LroResponse, state: TState) => boolean;
setDelay: (intervalInMs: number) => void;
options?: {
abortSignal?: AbortSignalLike;
};
state: RestorableOperationState<TState>;
setErrorAsResult: boolean;
}): Promise<void>;
//# sourceMappingURL=operation.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/http/operation.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,yBAAyB,EACzB,WAAW,EACX,WAAW,EAEZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,QAAQ,EACR,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,UAAU,EACX,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AA6D1D,wBAAgB,YAAY,CAAC,MAAM,EAAE;IACnC,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sBAAsB,CAAC,EAAE,yBAAyB,CAAC;CACpD,GAAG,CAAC,eAAe,GAAG;IAAE,IAAI,EAAE,iBAAiB,CAAA;CAAE,CAAC,GAAG,SAAS,CA+B9D;AAqDD,wBAAgB,eAAe,CAAC,CAAC,EAAE,EAAE,WAAW,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,SAAS,CAUt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AAsB,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE;IAC/D,GAAG,EAAE,oBAAoB,CAAC;IAC1B,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAC5D,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,KAAK,IAAI,CAAC;IACjE,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAC/D,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAE,CAAC;IAC5C,KAAK,EAAE,wBAAwB,CAAC,MAAM,CAAC,CAAC;IACxC,gBAAgB,EAAE,OAAO,CAAC;CAC3B,GAAG,OAAO,CAAC,IAAI,CAAC,CAkChB"}

View File

@@ -0,0 +1,295 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.pollHttpOperation = exports.isOperationError = exports.getResourceLocation = exports.getOperationStatus = exports.getOperationLocation = exports.initHttpOperation = exports.getStatusFromInitialResponse = exports.getErrorFromResponse = exports.parseRetryAfter = exports.inferLroMode = void 0;
const operation_js_1 = require("../poller/operation.js");
const logger_js_1 = require("../logger.js");
function getOperationLocationPollingUrl(inputs) {
const { azureAsyncOperation, operationLocation } = inputs;
return operationLocation !== null && operationLocation !== void 0 ? operationLocation : azureAsyncOperation;
}
function getLocationHeader(rawResponse) {
return rawResponse.headers["location"];
}
function getOperationLocationHeader(rawResponse) {
return rawResponse.headers["operation-location"];
}
function getAzureAsyncOperationHeader(rawResponse) {
return rawResponse.headers["azure-asyncoperation"];
}
function findResourceLocation(inputs) {
var _a;
const { location, requestMethod, requestPath, resourceLocationConfig } = inputs;
switch (requestMethod) {
case "PUT": {
return requestPath;
}
case "DELETE": {
return undefined;
}
case "PATCH": {
return (_a = getDefault()) !== null && _a !== void 0 ? _a : requestPath;
}
default: {
return getDefault();
}
}
function getDefault() {
switch (resourceLocationConfig) {
case "azure-async-operation": {
return undefined;
}
case "original-uri": {
return requestPath;
}
case "location":
default: {
return location;
}
}
}
}
function inferLroMode(inputs) {
const { rawResponse, requestMethod, requestPath, resourceLocationConfig } = inputs;
const operationLocation = getOperationLocationHeader(rawResponse);
const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);
const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });
const location = getLocationHeader(rawResponse);
const normalizedRequestMethod = requestMethod === null || requestMethod === void 0 ? void 0 : requestMethod.toLocaleUpperCase();
if (pollingUrl !== undefined) {
return {
mode: "OperationLocation",
operationLocation: pollingUrl,
resourceLocation: findResourceLocation({
requestMethod: normalizedRequestMethod,
location,
requestPath,
resourceLocationConfig,
}),
};
}
else if (location !== undefined) {
return {
mode: "ResourceLocation",
operationLocation: location,
};
}
else if (normalizedRequestMethod === "PUT" && requestPath) {
return {
mode: "Body",
operationLocation: requestPath,
};
}
else {
return undefined;
}
}
exports.inferLroMode = inferLroMode;
function transformStatus(inputs) {
const { status, statusCode } = inputs;
if (typeof status !== "string" && status !== undefined) {
throw new Error(`Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`);
}
switch (status === null || status === void 0 ? void 0 : status.toLocaleLowerCase()) {
case undefined:
return toOperationStatus(statusCode);
case "succeeded":
return "succeeded";
case "failed":
return "failed";
case "running":
case "accepted":
case "started":
case "canceling":
case "cancelling":
return "running";
case "canceled":
case "cancelled":
return "canceled";
default: {
logger_js_1.logger.verbose(`LRO: unrecognized operation status: ${status}`);
return status;
}
}
}
function getStatus(rawResponse) {
var _a;
const { status } = (_a = rawResponse.body) !== null && _a !== void 0 ? _a : {};
return transformStatus({ status, statusCode: rawResponse.statusCode });
}
function getProvisioningState(rawResponse) {
var _a, _b;
const { properties, provisioningState } = (_a = rawResponse.body) !== null && _a !== void 0 ? _a : {};
const status = (_b = properties === null || properties === void 0 ? void 0 : properties.provisioningState) !== null && _b !== void 0 ? _b : provisioningState;
return transformStatus({ status, statusCode: rawResponse.statusCode });
}
function toOperationStatus(statusCode) {
if (statusCode === 202) {
return "running";
}
else if (statusCode < 300) {
return "succeeded";
}
else {
return "failed";
}
}
function parseRetryAfter({ rawResponse }) {
const retryAfter = rawResponse.headers["retry-after"];
if (retryAfter !== undefined) {
// Retry-After header value is either in HTTP date format, or in seconds
const retryAfterInSeconds = parseInt(retryAfter);
return isNaN(retryAfterInSeconds)
? calculatePollingIntervalFromDate(new Date(retryAfter))
: retryAfterInSeconds * 1000;
}
return undefined;
}
exports.parseRetryAfter = parseRetryAfter;
function getErrorFromResponse(response) {
const error = accessBodyProperty(response, "error");
if (!error) {
logger_js_1.logger.warning(`The long-running operation failed but there is no error property in the response's body`);
return;
}
if (!error.code || !error.message) {
logger_js_1.logger.warning(`The long-running operation failed but the error property in the response's body doesn't contain code or message`);
return;
}
return error;
}
exports.getErrorFromResponse = getErrorFromResponse;
function calculatePollingIntervalFromDate(retryAfterDate) {
const timeNow = Math.floor(new Date().getTime());
const retryAfterTime = retryAfterDate.getTime();
if (timeNow < retryAfterTime) {
return retryAfterTime - timeNow;
}
return undefined;
}
function getStatusFromInitialResponse(inputs) {
const { response, state, operationLocation } = inputs;
function helper() {
var _a;
const mode = (_a = state.config.metadata) === null || _a === void 0 ? void 0 : _a["mode"];
switch (mode) {
case undefined:
return toOperationStatus(response.rawResponse.statusCode);
case "Body":
return getOperationStatus(response, state);
default:
return "running";
}
}
const status = helper();
return status === "running" && operationLocation === undefined ? "succeeded" : status;
}
exports.getStatusFromInitialResponse = getStatusFromInitialResponse;
/**
* Initiates the long-running operation.
*/
async function initHttpOperation(inputs) {
const { stateProxy, resourceLocationConfig, processResult, lro, setErrorAsResult } = inputs;
return (0, operation_js_1.initOperation)({
init: async () => {
const response = await lro.sendInitialRequest();
const config = inferLroMode({
rawResponse: response.rawResponse,
requestPath: lro.requestPath,
requestMethod: lro.requestMethod,
resourceLocationConfig,
});
return Object.assign({ response, operationLocation: config === null || config === void 0 ? void 0 : config.operationLocation, resourceLocation: config === null || config === void 0 ? void 0 : config.resourceLocation }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
},
stateProxy,
processResult: processResult
? ({ flatResponse }, state) => processResult(flatResponse, state)
: ({ flatResponse }) => flatResponse,
getOperationStatus: getStatusFromInitialResponse,
setErrorAsResult,
});
}
exports.initHttpOperation = initHttpOperation;
function getOperationLocation({ rawResponse }, state) {
var _a;
const mode = (_a = state.config.metadata) === null || _a === void 0 ? void 0 : _a["mode"];
switch (mode) {
case "OperationLocation": {
return getOperationLocationPollingUrl({
operationLocation: getOperationLocationHeader(rawResponse),
azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse),
});
}
case "ResourceLocation": {
return getLocationHeader(rawResponse);
}
case "Body":
default: {
return undefined;
}
}
}
exports.getOperationLocation = getOperationLocation;
function getOperationStatus({ rawResponse }, state) {
var _a;
const mode = (_a = state.config.metadata) === null || _a === void 0 ? void 0 : _a["mode"];
switch (mode) {
case "OperationLocation": {
return getStatus(rawResponse);
}
case "ResourceLocation": {
return toOperationStatus(rawResponse.statusCode);
}
case "Body": {
return getProvisioningState(rawResponse);
}
default:
throw new Error(`Internal error: Unexpected operation mode: ${mode}`);
}
}
exports.getOperationStatus = getOperationStatus;
function accessBodyProperty({ flatResponse, rawResponse }, prop) {
var _a, _b;
return (_a = flatResponse === null || flatResponse === void 0 ? void 0 : flatResponse[prop]) !== null && _a !== void 0 ? _a : (_b = rawResponse.body) === null || _b === void 0 ? void 0 : _b[prop];
}
function getResourceLocation(res, state) {
const loc = accessBodyProperty(res, "resourceLocation");
if (loc && typeof loc === "string") {
state.config.resourceLocation = loc;
}
return state.config.resourceLocation;
}
exports.getResourceLocation = getResourceLocation;
function isOperationError(e) {
return e.name === "RestError";
}
exports.isOperationError = isOperationError;
/** Polls the long-running operation. */
async function pollHttpOperation(inputs) {
const { lro, stateProxy, options, processResult, updateState, setDelay, state, setErrorAsResult, } = inputs;
return (0, operation_js_1.pollOperation)({
state,
stateProxy,
setDelay,
processResult: processResult
? ({ flatResponse }, inputState) => processResult(flatResponse, inputState)
: ({ flatResponse }) => flatResponse,
getError: getErrorFromResponse,
updateState,
getPollingInterval: parseRetryAfter,
getOperationLocation,
getOperationStatus,
isOperationError,
getResourceLocation,
options,
/**
* The expansion here is intentional because `lro` could be an object that
* references an inner this, so we need to preserve a reference to it.
*/
poll: async (location, inputOptions) => lro.sendPollRequest(location, inputOptions),
setErrorAsResult,
});
}
exports.pollHttpOperation = pollHttpOperation;
//# sourceMappingURL=operation.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,11 @@
import { LongRunningOperation } from "./models.js";
import { OperationState, SimplePollerLike } from "../poller/models.js";
import { CreateHttpPollerOptions } from "./models.js";
/**
* Creates a poller that can be used to poll a long-running operation.
* @param lro - Description of the long-running operation
* @param options - options to configure the poller
* @returns an initialized poller
*/
export declare function createHttpPoller<TResult, TState extends OperationState<TResult>>(lro: LongRunningOperation, options?: CreateHttpPollerOptions<TResult, TState>): Promise<SimplePollerLike<TState, TResult>>;
//# sourceMappingURL=poller.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"poller.d.ts","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAe,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAWvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAGtD;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,MAAM,SAAS,cAAc,CAAC,OAAO,CAAC,EACpF,GAAG,EAAE,oBAAoB,EACzB,OAAO,CAAC,EAAE,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,GACjD,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAgD5C"}

View File

@@ -0,0 +1,48 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.createHttpPoller = void 0;
const operation_js_1 = require("./operation.js");
const poller_js_1 = require("../poller/poller.js");
/**
* Creates a poller that can be used to poll a long-running operation.
* @param lro - Description of the long-running operation
* @param options - options to configure the poller
* @returns an initialized poller
*/
async function createHttpPoller(lro, options) {
const { resourceLocationConfig, intervalInMs, processResult, restoreFrom, updateState, withOperationLocation, resolveOnUnsuccessful = false, } = options || {};
return (0, poller_js_1.buildCreatePoller)({
getStatusFromInitialResponse: operation_js_1.getStatusFromInitialResponse,
getStatusFromPollResponse: operation_js_1.getOperationStatus,
isOperationError: operation_js_1.isOperationError,
getOperationLocation: operation_js_1.getOperationLocation,
getResourceLocation: operation_js_1.getResourceLocation,
getPollingInterval: operation_js_1.parseRetryAfter,
getError: operation_js_1.getErrorFromResponse,
resolveOnUnsuccessful,
})({
init: async () => {
const response = await lro.sendInitialRequest();
const config = (0, operation_js_1.inferLroMode)({
rawResponse: response.rawResponse,
requestPath: lro.requestPath,
requestMethod: lro.requestMethod,
resourceLocationConfig,
});
return Object.assign({ response, operationLocation: config === null || config === void 0 ? void 0 : config.operationLocation, resourceLocation: config === null || config === void 0 ? void 0 : config.resourceLocation }, ((config === null || config === void 0 ? void 0 : config.mode) ? { metadata: { mode: config.mode } } : {}));
},
poll: lro.sendPollRequest,
}, {
intervalInMs,
withOperationLocation,
restoreFrom,
updateState,
processResult: processResult
? ({ flatResponse }, state) => processResult(flatResponse, state)
: ({ flatResponse }) => flatResponse,
});
}
exports.createHttpPoller = createHttpPoller;
//# sourceMappingURL=poller.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAIlC,iDASwB;AAExB,mDAAwD;AAExD;;;;;GAKG;AACI,KAAK,UAAU,gBAAgB,CACpC,GAAyB,EACzB,OAAkD;IAElD,MAAM,EACJ,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,qBAAqB,GAAG,KAAK,GAC9B,GAAG,OAAO,IAAI,EAAE,CAAC;IAClB,OAAO,IAAA,6BAAiB,EAA+B;QACrD,4BAA4B,EAA5B,2CAA4B;QAC5B,yBAAyB,EAAE,iCAAkB;QAC7C,gBAAgB,EAAhB,+BAAgB;QAChB,oBAAoB,EAApB,mCAAoB;QACpB,mBAAmB,EAAnB,kCAAmB;QACnB,kBAAkB,EAAE,8BAAe;QACnC,QAAQ,EAAE,mCAAoB;QAC9B,qBAAqB;KACtB,CAAC,CACA;QACE,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,kBAAkB,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,IAAA,2BAAY,EAAC;gBAC1B,WAAW,EAAE,QAAQ,CAAC,WAAW;gBACjC,WAAW,EAAE,GAAG,CAAC,WAAW;gBAC5B,aAAa,EAAE,GAAG,CAAC,aAAa;gBAChC,sBAAsB;aACvB,CAAC,CAAC;YACH,uBACE,QAAQ,EACR,iBAAiB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,EAC5C,gBAAgB,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,IACvC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,EAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC5D;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,eAAe;KAC1B,EACD;QACE,YAAY;QACZ,qBAAqB;QACrB,WAAW;QACX,WAAW;QACX,aAAa,EAAE,aAAa;YAC1B,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC;YACjE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAuB;KAClD,CACF,CAAC;AACJ,CAAC;AAnDD,4CAmDC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { LongRunningOperation, LroResponse } from \"./models.js\";\nimport { OperationState, SimplePollerLike } from \"../poller/models.js\";\nimport {\n getErrorFromResponse,\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation.js\";\nimport { CreateHttpPollerOptions } from \"./models.js\";\nimport { buildCreatePoller } from \"../poller/poller.js\";\n\n/**\n * Creates a poller that can be used to poll a long-running operation.\n * @param lro - Description of the long-running operation\n * @param options - options to configure the poller\n * @returns an initialized poller\n */\nexport async function createHttpPoller<TResult, TState extends OperationState<TResult>>(\n lro: LongRunningOperation,\n options?: CreateHttpPollerOptions<TResult, TState>,\n): Promise<SimplePollerLike<TState, TResult>> {\n const {\n resourceLocationConfig,\n intervalInMs,\n processResult,\n restoreFrom,\n updateState,\n withOperationLocation,\n resolveOnUnsuccessful = false,\n } = options || {};\n return buildCreatePoller<LroResponse, TResult, TState>({\n getStatusFromInitialResponse,\n getStatusFromPollResponse: getOperationStatus,\n isOperationError,\n getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\n getError: getErrorFromResponse,\n resolveOnUnsuccessful,\n })(\n {\n init: async () => {\n const response = await lro.sendInitialRequest();\n const config = inferLroMode({\n rawResponse: response.rawResponse,\n requestPath: lro.requestPath,\n requestMethod: lro.requestMethod,\n resourceLocationConfig,\n });\n return {\n response,\n operationLocation: config?.operationLocation,\n resourceLocation: config?.resourceLocation,\n ...(config?.mode ? { metadata: { mode: config.mode } } : {}),\n };\n },\n poll: lro.sendPollRequest,\n },\n {\n intervalInMs,\n withOperationLocation,\n restoreFrom,\n updateState,\n processResult: processResult\n ? ({ flatResponse }, state) => processResult(flatResponse, state)\n : ({ flatResponse }) => flatResponse as TResult,\n },\n );\n}\n"]}

13
node_modules/@azure/core-lro/dist/commonjs/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,13 @@
export { createHttpPoller } from "./http/poller.js";
export { CancelOnProgress, OperationState, OperationStatus, SimplePollerLike, } from "./poller/models.js";
export { CreateHttpPollerOptions } from "./http/models.js";
export { LroResourceLocationConfig, LongRunningOperation, LroResponse, RawResponse, } from "./http/models.js";
/**
* This can be uncommented to expose the protocol-agnostic poller
*/
/** legacy */
export * from "./legacy/lroEngine/index.js";
export * from "./legacy/poller.js";
export * from "./legacy/pollOperation.js";
export { PollerLike } from "./legacy/models.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,WAAW,EACX,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AAUH,aAAa;AACb,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC"}

24
node_modules/@azure/core-lro/dist/commonjs/index.js generated vendored Normal file
View File

@@ -0,0 +1,24 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.createHttpPoller = void 0;
const tslib_1 = require("tslib");
var poller_js_1 = require("./http/poller.js");
Object.defineProperty(exports, "createHttpPoller", { enumerable: true, get: function () { return poller_js_1.createHttpPoller; } });
/**
* This can be uncommented to expose the protocol-agnostic poller
*/
// export {
// BuildCreatePollerOptions,
// Operation,
// CreatePollerOptions,
// OperationConfig,
// RestorableOperationState,
// } from "./poller/models";
// export { buildCreatePoller } from "./poller/poller";
/** legacy */
tslib_1.__exportStar(require("./legacy/lroEngine/index.js"), exports);
tslib_1.__exportStar(require("./legacy/poller.js"), exports);
tslib_1.__exportStar(require("./legacy/pollOperation.js"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAElC,8CAAoD;AAA3C,6GAAA,gBAAgB,OAAA;AAezB;;GAEG;AACH,WAAW;AACX,8BAA8B;AAC9B,eAAe;AACf,yBAAyB;AACzB,qBAAqB;AACrB,8BAA8B;AAC9B,4BAA4B;AAC5B,uDAAuD;AAEvD,aAAa;AACb,sEAA4C;AAC5C,6DAAmC;AACnC,oEAA0C","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { createHttpPoller } from \"./http/poller.js\";\nexport {\n CancelOnProgress,\n OperationState,\n OperationStatus,\n SimplePollerLike,\n} from \"./poller/models.js\";\nexport { CreateHttpPollerOptions } from \"./http/models.js\";\nexport {\n LroResourceLocationConfig,\n LongRunningOperation,\n LroResponse,\n RawResponse,\n} from \"./http/models.js\";\n\n/**\n * This can be uncommented to expose the protocol-agnostic poller\n */\n// export {\n// BuildCreatePollerOptions,\n// Operation,\n// CreatePollerOptions,\n// OperationConfig,\n// RestorableOperationState,\n// } from \"./poller/models\";\n// export { buildCreatePoller } from \"./poller/poller\";\n\n/** legacy */\nexport * from \"./legacy/lroEngine/index.js\";\nexport * from \"./legacy/poller.js\";\nexport * from \"./legacy/pollOperation.js\";\nexport { PollerLike } from \"./legacy/models.js\";\n"]}

View File

@@ -0,0 +1,3 @@
export { LroEngine } from "./lroEngine.js";
export { LroEngineOptions } from "./models.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/legacy/lroEngine/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}

View File

@@ -0,0 +1,8 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.LroEngine = void 0;
var lroEngine_js_1 = require("./lroEngine.js");
Object.defineProperty(exports, "LroEngine", { enumerable: true, get: function () { return lroEngine_js_1.LroEngine; } });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/legacy/lroEngine/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,+CAA2C;AAAlC,yGAAA,SAAS,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { LroEngine } from \"./lroEngine.js\";\nexport { LroEngineOptions } from \"./models.js\";\n"]}

View File

@@ -0,0 +1,16 @@
import { LroEngineOptions } from "./models.js";
import { LongRunningOperation } from "../../http/models.js";
import { PollOperationState } from "../pollOperation.js";
import { Poller } from "../poller.js";
/**
* The LRO Engine, a class that performs polling.
*/
export declare class LroEngine<TResult, TState extends PollOperationState<TResult>> extends Poller<TState, TResult> {
private config;
constructor(lro: LongRunningOperation<TResult>, options?: LroEngineOptions<TResult, TState>);
/**
* The method used by the poller to wait before attempting to update its operation.
*/
delay(): Promise<void>;
}
//# sourceMappingURL=lroEngine.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"lroEngine.d.ts","sourceRoot":"","sources":["../../../../src/legacy/lroEngine/lroEngine.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAgB,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC;;GAEG;AACH,qBAAa,SAAS,CAAC,OAAO,EAAE,MAAM,SAAS,kBAAkB,CAAC,OAAO,CAAC,CAAE,SAAQ,MAAM,CACxF,MAAM,EACN,OAAO,CACR;IACC,OAAO,CAAC,MAAM,CAAe;gBAEjB,GAAG,EAAE,oBAAoB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;IA6B3F;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGvB"}

View File

@@ -0,0 +1,33 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.LroEngine = void 0;
const operation_js_1 = require("./operation.js");
const constants_js_1 = require("../../poller/constants.js");
const poller_js_1 = require("../poller.js");
const operation_js_2 = require("../../poller/operation.js");
/**
* The LRO Engine, a class that performs polling.
*/
class LroEngine extends poller_js_1.Poller {
constructor(lro, options) {
const { intervalInMs = constants_js_1.POLL_INTERVAL_IN_MS, resumeFrom, resolveOnUnsuccessful = false, isDone, lroResourceLocationConfig, processResult, updateState, } = options || {};
const state = resumeFrom
? (0, operation_js_2.deserializeState)(resumeFrom)
: {};
const operation = new operation_js_1.GenericPollOperation(state, lro, !resolveOnUnsuccessful, lroResourceLocationConfig, processResult, updateState, isDone);
super(operation);
this.resolveOnUnsuccessful = resolveOnUnsuccessful;
this.config = { intervalInMs: intervalInMs };
operation.setPollerConfig(this.config);
}
/**
* The method used by the poller to wait before attempting to update its operation.
*/
delay() {
return new Promise((resolve) => setTimeout(() => resolve(), this.config.intervalInMs));
}
}
exports.LroEngine = LroEngine;
//# sourceMappingURL=lroEngine.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"lroEngine.js","sourceRoot":"","sources":["../../../../src/legacy/lroEngine/lroEngine.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,iDAAsD;AAEtD,4DAAgE;AAEhE,4CAAsC;AAEtC,4DAA6D;AAE7D;;GAEG;AACH,MAAa,SAA+D,SAAQ,kBAGnF;IAGC,YAAY,GAAkC,EAAE,OAA2C;QACzF,MAAM,EACJ,YAAY,GAAG,kCAAmB,EAClC,UAAU,EACV,qBAAqB,GAAG,KAAK,EAC7B,MAAM,EACN,yBAAyB,EACzB,aAAa,EACb,WAAW,GACZ,GAAG,OAAO,IAAI,EAAE,CAAC;QAClB,MAAM,KAAK,GAAqC,UAAU;YACxD,CAAC,CAAC,IAAA,+BAAgB,EAAC,UAAU,CAAC;YAC9B,CAAC,CAAE,EAAuC,CAAC;QAC7C,MAAM,SAAS,GAAG,IAAI,mCAAoB,CACxC,KAAK,EACL,GAAG,EACH,CAAC,qBAAqB,EACtB,yBAAyB,EACzB,aAAa,EACb,WAAW,EACX,MAAM,CACP,CAAC;QACF,KAAK,CAAC,SAAS,CAAC,CAAC;QACjB,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QAEnD,IAAI,CAAC,MAAM,GAAG,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;QAC7C,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;IACzF,CAAC;CACF;AAzCD,8BAyCC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { LroEngineOptions, PollerConfig } from \"./models.js\";\nimport { GenericPollOperation } from \"./operation.js\";\nimport { LongRunningOperation } from \"../../http/models.js\";\nimport { POLL_INTERVAL_IN_MS } from \"../../poller/constants.js\";\nimport { PollOperationState } from \"../pollOperation.js\";\nimport { Poller } from \"../poller.js\";\nimport { RestorableOperationState } from \"../../poller/models.js\";\nimport { deserializeState } from \"../../poller/operation.js\";\n\n/**\n * The LRO Engine, a class that performs polling.\n */\nexport class LroEngine<TResult, TState extends PollOperationState<TResult>> extends Poller<\n TState,\n TResult\n> {\n private config: PollerConfig;\n\n constructor(lro: LongRunningOperation<TResult>, options?: LroEngineOptions<TResult, TState>) {\n const {\n intervalInMs = POLL_INTERVAL_IN_MS,\n resumeFrom,\n resolveOnUnsuccessful = false,\n isDone,\n lroResourceLocationConfig,\n processResult,\n updateState,\n } = options || {};\n const state: RestorableOperationState<TState> = resumeFrom\n ? deserializeState(resumeFrom)\n : ({} as RestorableOperationState<TState>);\n const operation = new GenericPollOperation(\n state,\n lro,\n !resolveOnUnsuccessful,\n lroResourceLocationConfig,\n processResult,\n updateState,\n isDone,\n );\n super(operation);\n this.resolveOnUnsuccessful = resolveOnUnsuccessful;\n\n this.config = { intervalInMs: intervalInMs };\n operation.setPollerConfig(this.config);\n }\n\n /**\n * The method used by the poller to wait before attempting to update its operation.\n */\n delay(): Promise<void> {\n return new Promise((resolve) => setTimeout(() => resolve(), this.config.intervalInMs));\n }\n}\n"]}

View File

@@ -0,0 +1,38 @@
import { LroResourceLocationConfig, RawResponse } from "../../http/models.js";
/**
* Options for the LRO poller.
*/
export interface LroEngineOptions<TResult, TState> {
/**
* Defines how much time the poller is going to wait before making a new request to the service.
*/
intervalInMs?: number;
/**
* A serialized poller which can be used to resume an existing paused Long-Running-Operation.
*/
resumeFrom?: string;
/**
* The potential location of the result of the LRO if specified by the LRO extension in the swagger.
*/
lroResourceLocationConfig?: LroResourceLocationConfig;
/**
* A function to process the result of the LRO.
*/
processResult?: (result: unknown, state: TState) => TResult;
/**
* A function to process the state of the LRO.
*/
updateState?: (state: TState, lastResponse: RawResponse) => void;
/**
* A predicate to determine whether the LRO finished processing.
*/
isDone?: (lastResponse: unknown, state: TState) => boolean;
/**
* Control whether to throw an exception if the operation failed or was canceled.
*/
resolveOnUnsuccessful?: boolean;
}
export interface PollerConfig {
intervalInMs: number;
}
//# sourceMappingURL=models.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../../src/legacy/lroEngine/models.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAE9E;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,OAAO,EAAE,MAAM;IAC/C;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,yBAAyB,CAAC,EAAE,yBAAyB,CAAC;IACtD;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAC5D;;OAEG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,KAAK,IAAI,CAAC;IACjE;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAC3D;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;CACtB"}

View File

@@ -0,0 +1,5 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=models.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/legacy/lroEngine/models.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { LroResourceLocationConfig, RawResponse } from \"../../http/models.js\";\n\n/**\n * Options for the LRO poller.\n */\nexport interface LroEngineOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n resumeFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n lroResourceLocationConfig?: LroResourceLocationConfig;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => TResult;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, lastResponse: RawResponse) => void;\n /**\n * A predicate to determine whether the LRO finished processing.\n */\n isDone?: (lastResponse: unknown, state: TState) => boolean;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n}\n\nexport interface PollerConfig {\n intervalInMs: number;\n}\n"]}

View File

@@ -0,0 +1,27 @@
import { LongRunningOperation, LroResourceLocationConfig, RawResponse } from "../../http/models.js";
import { PollOperation, PollOperationState } from "../pollOperation.js";
import { RestorableOperationState } from "../../poller/models.js";
import { AbortSignalLike } from "@azure/abort-controller";
import { PollerConfig } from "./models.js";
export declare class GenericPollOperation<TResult, TState extends PollOperationState<TResult>> implements PollOperation<TState, TResult> {
state: RestorableOperationState<TState>;
private lro;
private setErrorAsResult;
private lroResourceLocationConfig?;
private processResult?;
private updateState?;
private isDone?;
private pollerConfig?;
constructor(state: RestorableOperationState<TState>, lro: LongRunningOperation, setErrorAsResult: boolean, lroResourceLocationConfig?: LroResourceLocationConfig | undefined, processResult?: ((result: unknown, state: TState) => TResult) | undefined, updateState?: ((state: TState, lastResponse: RawResponse) => void) | undefined, isDone?: ((lastResponse: TResult, state: TState) => boolean) | undefined);
setPollerConfig(pollerConfig: PollerConfig): void;
update(options?: {
abortSignal?: AbortSignalLike;
fireProgress?: (state: TState) => void;
}): Promise<PollOperation<TState, TResult>>;
cancel(): Promise<PollOperation<TState, TResult>>;
/**
* Serializes the Poller operation.
*/
toString(): string;
}
//# sourceMappingURL=operation.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../../src/legacy/lroEngine/operation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAc,MAAM,wBAAwB,CAAC;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAyB3C,qBAAa,oBAAoB,CAAC,OAAO,EAAE,MAAM,SAAS,kBAAkB,CAAC,OAAO,CAAC,CACnF,YAAW,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC;IAKhC,KAAK,EAAE,wBAAwB,CAAC,MAAM,CAAC;IAC9C,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,yBAAyB,CAAC;IAClC,OAAO,CAAC,aAAa,CAAC;IACtB,OAAO,CAAC,WAAW,CAAC;IACpB,OAAO,CAAC,MAAM,CAAC;IATjB,OAAO,CAAC,YAAY,CAAC,CAAe;gBAG3B,KAAK,EAAE,wBAAwB,CAAC,MAAM,CAAC,EACtC,GAAG,EAAE,oBAAoB,EACzB,gBAAgB,EAAE,OAAO,EACzB,yBAAyB,CAAC,uCAA2B,EACrD,aAAa,CAAC,YAAW,OAAO,SAAS,MAAM,KAAK,OAAO,aAAA,EAC3D,WAAW,CAAC,WAAU,MAAM,gBAAgB,WAAW,KAAK,IAAI,aAAA,EAChE,MAAM,CAAC,kBAAiB,OAAO,SAAS,MAAM,KAAK,OAAO,aAAA;IAG7D,eAAe,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI;IAIlD,MAAM,CAAC,OAAO,CAAC,EAAE;QACrB,WAAW,CAAC,EAAE,eAAe,CAAC;QAC9B,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;KACxC,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAwCrC,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAKvD;;OAEG;IACI,QAAQ,IAAI,MAAM;CAK1B"}

View File

@@ -0,0 +1,88 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenericPollOperation = void 0;
const operation_js_1 = require("../../http/operation.js");
const logger_js_1 = require("../../logger.js");
const createStateProxy = () => ({
initState: (config) => ({ config, isStarted: true }),
setCanceled: (state) => (state.isCancelled = true),
setError: (state, error) => (state.error = error),
setResult: (state, result) => (state.result = result),
setRunning: (state) => (state.isStarted = true),
setSucceeded: (state) => (state.isCompleted = true),
setFailed: () => {
/** empty body */
},
getError: (state) => state.error,
getResult: (state) => state.result,
isCanceled: (state) => !!state.isCancelled,
isFailed: (state) => !!state.error,
isRunning: (state) => !!state.isStarted,
isSucceeded: (state) => Boolean(state.isCompleted && !state.isCancelled && !state.error),
});
class GenericPollOperation {
constructor(state, lro, setErrorAsResult, lroResourceLocationConfig, processResult, updateState, isDone) {
this.state = state;
this.lro = lro;
this.setErrorAsResult = setErrorAsResult;
this.lroResourceLocationConfig = lroResourceLocationConfig;
this.processResult = processResult;
this.updateState = updateState;
this.isDone = isDone;
}
setPollerConfig(pollerConfig) {
this.pollerConfig = pollerConfig;
}
async update(options) {
var _a;
const stateProxy = createStateProxy();
if (!this.state.isStarted) {
this.state = Object.assign(Object.assign({}, this.state), (await (0, operation_js_1.initHttpOperation)({
lro: this.lro,
stateProxy,
resourceLocationConfig: this.lroResourceLocationConfig,
processResult: this.processResult,
setErrorAsResult: this.setErrorAsResult,
})));
}
const updateState = this.updateState;
const isDone = this.isDone;
if (!this.state.isCompleted && this.state.error === undefined) {
await (0, operation_js_1.pollHttpOperation)({
lro: this.lro,
state: this.state,
stateProxy,
processResult: this.processResult,
updateState: updateState
? (state, { rawResponse }) => updateState(state, rawResponse)
: undefined,
isDone: isDone
? ({ flatResponse }, state) => isDone(flatResponse, state)
: undefined,
options,
setDelay: (intervalInMs) => {
this.pollerConfig.intervalInMs = intervalInMs;
},
setErrorAsResult: this.setErrorAsResult,
});
}
(_a = options === null || options === void 0 ? void 0 : options.fireProgress) === null || _a === void 0 ? void 0 : _a.call(options, this.state);
return this;
}
async cancel() {
logger_js_1.logger.error("`cancelOperation` is deprecated because it wasn't implemented");
return this;
}
/**
* Serializes the Poller operation.
*/
toString() {
return JSON.stringify({
state: this.state,
});
}
}
exports.GenericPollOperation = GenericPollOperation;
//# sourceMappingURL=operation.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,66 @@
import { AbortSignalLike } from "@azure/abort-controller";
import { CancelOnProgress } from "../poller/models.js";
import { PollOperationState } from "./pollOperation.js";
/**
* Abstract representation of a poller, intended to expose just the minimal API that the user needs to work with.
*/
export interface PollerLike<TState extends PollOperationState<TResult>, TResult> {
/**
* Returns a promise that will resolve once a single polling request finishes.
* It does this by calling the update method of the Poller's operation.
*/
poll(options?: {
abortSignal?: AbortSignalLike;
}): Promise<void>;
/**
* Returns a promise that will resolve once the underlying operation is completed.
*/
pollUntilDone(pollOptions?: {
abortSignal?: AbortSignalLike;
}): Promise<TResult>;
/**
* Invokes the provided callback after each polling is completed,
* sending the current state of the poller's operation.
*
* It returns a method that can be used to stop receiving updates on the given callback function.
*/
onProgress(callback: (state: TState) => void): CancelOnProgress;
/**
* Returns true if the poller has finished polling.
*/
isDone(): boolean;
/**
* Stops the poller. After this, no manual or automated requests can be sent.
*/
stopPolling(): void;
/**
* Returns true if the poller is stopped.
*/
isStopped(): boolean;
/**
* Attempts to cancel the underlying operation.
* @deprecated `cancelOperation` has been deprecated because it was not implemented.
*/
cancelOperation(options?: {
abortSignal?: AbortSignalLike;
}): Promise<void>;
/**
* Returns the state of the operation.
* The TState defined in PollerLike can be a subset of the TState defined in
* the Poller implementation.
*/
getOperationState(): TState;
/**
* Returns the result value of the operation,
* regardless of the state of the poller.
* It can return undefined or an incomplete form of the final TResult value
* depending on the implementation.
*/
getResult(): TResult | undefined;
/**
* Returns a serialized version of the poller's operation
* by invoking the operation's toString method.
*/
toString(): string;
}
//# sourceMappingURL=models.d.ts.map

Some files were not shown because too many files have changed in this diff Show More