Next release of setup-bun

This commit is contained in:
Ashcon Partovi 2023-02-22 17:47:24 -08:00
parent ed9eb0969c
commit 9c14b74b45
1082 changed files with 242557 additions and 173810 deletions

View file

@ -1,12 +1,11 @@
# Azure Core LRO client library for JavaScript
`@azure/core-lro` is a JavaScript library that manages long running operations (LROs) against Azure services. Until completion, such operations require consecutive calls to Azure services to update a local representation of the remote operation status.
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).
**Please note:** This library is included with other Azure SDK libraries that need it. It should not be used as a direct dependency in your projects.
`@azure/core-lro` is made following our [Long Running Operations guidelines](https://azure.github.io/azure-sdk/typescript_design.html#ts-lro)
`@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)
@ -14,53 +13,56 @@ Key links:
## Getting started
### Install the package
### Currently supported environments
To install this library for a project under the `azure-sdk-for-js`, make sure you are at the root of that project, then use [Rush](https://rushjs.io/) as follows:
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
- Latest versions of Safari, Chrome, Edge, and Firefox.
```
rush add -p @azure/core-lro
```
### Installation
To install this package outside of the `azure-sdk-for-js`, use `npm install --save @azure/core-lro`.
### Configure TypeScript
TypeScript users need to have Node type definitions installed:
```bash
npm install @types/node
```
They will also need to enable `compilerOptions.allowSyntheticDefaultImports` in their
`tsconfig.json`. Note that if you have enabled `compilerOptions.esModuleInterop`,
`allowSyntheticDefaultImports` is enabled by default.
See [TypeScript's compiler options handbook](https://www.typescriptlang.org/docs/handbook/compiler-options.html)
for more information.
This package is primarily used in generated code and not meant to be consumed directly by end users.
## Key concepts
@azure/core-lro makes a distinction between the Long Running Operation and its Poller.
### `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.
- Whenever we talk about an **operation**, we mean the static representation of a Long Running Operation.
Any operation will have a definition of a **state**, which has an opinionated default set of properties.
The definition of the operation will also have functions that will define how to request new information
about the pending operation, how to request its cancellation, and how to serialize it.
- A **Poller** is an object who's main function is to interact with an operation until the poller is manually stopped,
the operation finishes (either by succeeding or failing) or if a manual request to cancel the operation has succeeded.
Some characteristics of the pollers are:
- Pollers show the status of the polling behavior.
- Pollers support manual as well as automatic polling.
- Pollers are serializable and can resume from a serialized operation.
- Pollers also specify how much of the operation's state is going to be available to the public.
- A **PollerLike** is the public interface of a Poller, which allows for different implementations to be used.
## Examples
You will be able to find some working examples of an implementation of an operation and a poller in:
- [The `@azure/core-lro` samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/core-lro/samples).
- [The `@azure/core-lro` tests](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/core-lro/test).
Examples can be found in the `samples` folder.
## Troubleshooting

View file

@ -229,6 +229,9 @@ export function getResourceLocation({ flatResponse }, state) {
}
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;
@ -243,6 +246,7 @@ export async function pollHttpOperation(inputs) {
getPollingInterval: parseRetryAfter,
getOperationLocation,
getOperationStatus,
isOperationError,
getResourceLocation,
options,
/**

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { getOperationLocation, getOperationStatus, getResourceLocation, getStatusFromInitialResponse, inferLroMode, parseRetryAfter, } from "./operation";
import { getOperationLocation, getOperationStatus, getResourceLocation, getStatusFromInitialResponse, inferLroMode, isOperationError, parseRetryAfter, } from "./operation";
import { buildCreatePoller } from "../poller/poller";
/**
* Creates a poller that can be used to poll a long-running operation.
@ -13,6 +13,7 @@ export async function createHttpPoller(lro, options) {
return buildCreatePoller({
getStatusFromInitialResponse,
getStatusFromPollResponse: getOperationStatus,
isOperationError,
getOperationLocation,
getResourceLocation,
getPollingInterval: parseRetryAfter,

View file

@ -1 +1 @@
{"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,4BAA4B,EAC5B,YAAY,EACZ,eAAe,GAChB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,GAAyB,EACzB,OAAkD;IAElD,MAAM,EACJ,sBAAsB,EACtB,YAAY,EACZ,a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(c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { LongRunningOperation, LroResponse } from \"./models\";\nimport { OperationState, SimplePollerLike } from \"../poller/models\";\nimport {\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n parseRetryAfter,\n} from \"./operation\";\nimport { CreateHttpPollerOptions } from \"./models\";\nimport { buildCreatePoller } from \"../poller/poller\";\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 getOperationLocation,\n getResourceLocation,\n getPollingInterval: parseRetryAfter,\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"]}
{"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../src/http/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,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ACZ,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\";\nimport { OperationState, SimplePollerLike } from \"../poller/models\";\nimport {\n getOperationLocation,\n getOperationStatus,\n getResourceLocation,\n getStatusFromInitialResponse,\n inferLroMode,\n isOperationError,\n parseRetryAfter,\n} from \"./operation\";\nimport { CreateHttpPollerOptions } from \"./models\";\nimport { buildCreatePoller } from \"../poller/poller\";\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 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"]}

File diff suppressed because one or more lines are too long

View file

@ -14,10 +14,12 @@ export function deserializeState(serializedState) {
}
}
function setStateError(inputs) {
const { state, stateProxy } = inputs;
const { state, stateProxy, isOperationError } = inputs;
return (error) => {
stateProxy.setError(state, error);
stateProxy.setFailed(state);
if (isOperationError(error)) {
stateProxy.setError(state, error);
stateProxy.setFailed(state);
}
throw error;
};
}
@ -72,10 +74,11 @@ export async function initOperation(inputs) {
return state;
}
async function pollOperationHelper(inputs) {
const { poll, state, stateProxy, operationLocation, getOperationStatus, getResourceLocation, options, } = 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"}`);
@ -83,7 +86,7 @@ async function pollOperationHelper(inputs) {
const resourceLocation = getResourceLocation(response, state);
if (resourceLocation !== undefined) {
return {
response: await poll(resourceLocation).catch(setStateError({ state, stateProxy })),
response: await poll(resourceLocation).catch(setStateError({ state, stateProxy, isOperationError })),
status,
};
}
@ -92,7 +95,7 @@ async function pollOperationHelper(inputs) {
}
/** Polls the long-running operation. */
export async function pollOperation(inputs) {
const { poll, state, stateProxy, options, getOperationStatus, getResourceLocation, getOperationLocation, withOperationLocation, getPollingInterval, processResult, updateState, setDelay, isDone, setErrorAsResult, } = inputs;
const { poll, state, stateProxy, options, getOperationStatus, getResourceLocation, getOperationLocation, isOperationError, withOperationLocation, getPollingInterval, processResult, updateState, setDelay, isDone, setErrorAsResult, } = inputs;
const { operationLocation } = state.config;
if (operationLocation !== undefined) {
const { response, status } = await pollOperationHelper({
@ -102,6 +105,7 @@ export async function pollOperation(inputs) {
stateProxy,
operationLocation,
getResourceLocation,
isOperationError,
options,
});
processOperationStatus({

File diff suppressed because one or more lines are too long

View file

@ -28,7 +28,7 @@ const createStateProxy = () => ({
* Returns a poller factory.
*/
export function buildCreatePoller(inputs) {
const { getOperationLocation, getStatusFromInitialResponse, getStatusFromPollResponse, getResourceLocation, getPollingInterval, resolveOnUnsuccessful, } = inputs;
const { getOperationLocation, getStatusFromInitialResponse, getStatusFromPollResponse, isOperationError, getResourceLocation, getPollingInterval, resolveOnUnsuccessful, } = inputs;
return async ({ init, poll }, options) => {
const { processResult, updateState, withOperationLocation: withOperationLocationCallback, intervalInMs = POLL_INTERVAL_IN_MS, restoreFrom, } = options || {};
const stateProxy = createStateProxy();
@ -59,6 +59,7 @@ export function buildCreatePoller(inputs) {
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,
@ -91,35 +92,46 @@ export function buildCreatePoller(inputs) {
await poller.poll({ abortSignal });
}
}
switch (state.status) {
case "succeeded": {
return poller.getResult();
}
case "canceled": {
if (!resolveOnUnsuccessful)
throw new Error("Operation was canceled");
return poller.getResult();
}
case "failed": {
if (!resolveOnUnsuccessful)
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;
return poller.getResult();
}
case "notStarted":
case "running": {
// Unreachable
throw new Error(`polling completed without succeeding or failing`);
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,
@ -133,11 +145,13 @@ export function buildCreatePoller(inputs) {
setErrorAsResult: !resolveOnUnsuccessful,
});
await handleProgressEvents();
if (state.status === "canceled" && !resolveOnUnsuccessful) {
throw new Error("Operation was canceled");
}
if (state.status === "failed" && !resolveOnUnsuccessful) {
throw state.error;
if (!resolveOnUnsuccessful) {
switch (state.status) {
case "canceled":
throw new Error(cancelErrMsg);
case "failed":
throw state.error;
}
}
},
};

File diff suppressed because one or more lines are too long

View file

@ -36,10 +36,12 @@ function deserializeState(serializedState) {
}
}
function setStateError(inputs) {
const { state, stateProxy } = inputs;
const { state, stateProxy, isOperationError } = inputs;
return (error) => {
stateProxy.setError(state, error);
stateProxy.setFailed(state);
if (isOperationError(error)) {
stateProxy.setError(state, error);
stateProxy.setFailed(state);
}
throw error;
};
}
@ -94,10 +96,11 @@ async function initOperation(inputs) {
return state;
}
async function pollOperationHelper(inputs) {
const { poll, state, stateProxy, operationLocation, getOperationStatus, getResourceLocation, options, } = 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"}`);
@ -105,7 +108,7 @@ async function pollOperationHelper(inputs) {
const resourceLocation = getResourceLocation(response, state);
if (resourceLocation !== undefined) {
return {
response: await poll(resourceLocation).catch(setStateError({ state, stateProxy })),
response: await poll(resourceLocation).catch(setStateError({ state, stateProxy, isOperationError })),
status,
};
}
@ -114,7 +117,7 @@ async function pollOperationHelper(inputs) {
}
/** Polls the long-running operation. */
async function pollOperation(inputs) {
const { poll, state, stateProxy, options, getOperationStatus, getResourceLocation, getOperationLocation, withOperationLocation, getPollingInterval, processResult, updateState, setDelay, isDone, setErrorAsResult, } = inputs;
const { poll, state, stateProxy, options, getOperationStatus, getResourceLocation, getOperationLocation, isOperationError, withOperationLocation, getPollingInterval, processResult, updateState, setDelay, isDone, setErrorAsResult, } = inputs;
const { operationLocation } = state.config;
if (operationLocation !== undefined) {
const { response, status } = await pollOperationHelper({
@ -124,6 +127,7 @@ async function pollOperation(inputs) {
stateProxy,
operationLocation,
getResourceLocation,
isOperationError,
options,
});
processOperationStatus({
@ -380,6 +384,9 @@ function getResourceLocation({ flatResponse }, state) {
}
return state.config.resourceLocation;
}
function isOperationError(e) {
return e.name === "RestError";
}
/** Polls the long-running operation. */
async function pollHttpOperation(inputs) {
const { lro, stateProxy, options, processResult, updateState, setDelay, state, setErrorAsResult, } = inputs;
@ -394,6 +401,7 @@ async function pollHttpOperation(inputs) {
getPollingInterval: parseRetryAfter,
getOperationLocation,
getOperationStatus,
isOperationError,
getResourceLocation,
options,
/**
@ -482,7 +490,7 @@ const createStateProxy$1 = () => ({
* Returns a poller factory.
*/
function buildCreatePoller(inputs) {
const { getOperationLocation, getStatusFromInitialResponse, getStatusFromPollResponse, getResourceLocation, getPollingInterval, resolveOnUnsuccessful, } = inputs;
const { getOperationLocation, getStatusFromInitialResponse, getStatusFromPollResponse, isOperationError, getResourceLocation, getPollingInterval, resolveOnUnsuccessful, } = inputs;
return async ({ init, poll }, options) => {
const { processResult, updateState, withOperationLocation: withOperationLocationCallback, intervalInMs = POLL_INTERVAL_IN_MS, restoreFrom, } = options || {};
const stateProxy = createStateProxy$1();
@ -513,6 +521,7 @@ function buildCreatePoller(inputs) {
const abortController$1 = new abortController.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,
@ -545,35 +554,46 @@ function buildCreatePoller(inputs) {
await poller.poll({ abortSignal });
}
}
switch (state.status) {
case "succeeded": {
return poller.getResult();
}
case "canceled": {
if (!resolveOnUnsuccessful)
throw new Error("Operation was canceled");
return poller.getResult();
}
case "failed": {
if (!resolveOnUnsuccessful)
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;
return poller.getResult();
}
case "notStarted":
case "running": {
// Unreachable
throw new Error(`polling completed without succeeding or failing`);
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,
@ -587,11 +607,13 @@ function buildCreatePoller(inputs) {
setErrorAsResult: !resolveOnUnsuccessful,
});
await handleProgressEvents();
if (state.status === "canceled" && !resolveOnUnsuccessful) {
throw new Error("Operation was canceled");
}
if (state.status === "failed" && !resolveOnUnsuccessful) {
throw state.error;
if (!resolveOnUnsuccessful) {
switch (state.status) {
case "canceled":
throw new Error(cancelErrMsg);
case "failed":
throw state.error;
}
}
},
};
@ -611,6 +633,7 @@ async function createHttpPoller(lro, options) {
return buildCreatePoller({
getStatusFromInitialResponse,
getStatusFromPollResponse: getOperationStatus,
isOperationError,
getOperationLocation,
getResourceLocation,
getPollingInterval: parseRetryAfter,

File diff suppressed because one or more lines are too long

View file

@ -2,7 +2,7 @@
"name": "@azure/core-lro",
"author": "Microsoft Corporation",
"sdk-type": "client",
"version": "2.4.0",
"version": "2.5.1",
"description": "Isomorphic client library for supporting long-running operations in node.js and browser.",
"tags": [
"isomorphic",
@ -35,7 +35,7 @@
"LICENSE"
],
"engines": {
"node": ">=12.0.0"
"node": ">=14.0.0"
},
"browser": {
"os": false,
@ -102,7 +102,7 @@
"@azure/test-utils": "^1.0.0",
"@microsoft/api-extractor": "^7.31.1",
"@types/mocha": "^7.0.2",
"@types/node": "^12.0.0",
"@types/node": "^14.0.0",
"cross-env": "^7.0.2",
"eslint": "^8.0.0",
"karma": "^6.2.0",
@ -122,6 +122,6 @@
"prettier": "^2.5.1",
"rimraf": "^3.0.0",
"ts-node": "^10.0.0",
"typescript": "~4.6.0"
"typescript": "~4.8.0"
}
}