This commit is contained in:
Lukian LEIZOUR 2022-11-19 01:49:12 +01:00
parent be4fd23bcf
commit 0bd53741af
728 changed files with 86573 additions and 0 deletions

113
node_modules/p-timeout/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,113 @@
declare class TimeoutErrorClass extends Error {
readonly name: 'TimeoutError';
constructor(message?: string);
}
declare namespace pTimeout {
type TimeoutError = TimeoutErrorClass;
type Options = {
/**
Custom implementations for the `setTimeout` and `clearTimeout` functions.
Useful for testing purposes, in particular to work around [`sinon.useFakeTimers()`](https://sinonjs.org/releases/latest/fake-timers/).
@example
```
import pTimeout = require('p-timeout');
import sinon = require('sinon');
(async () => {
const originalSetTimeout = setTimeout;
const originalClearTimeout = clearTimeout;
sinon.useFakeTimers();
// Use `pTimeout` without being affected by `sinon.useFakeTimers()`:
await pTimeout(doSomething(), 2000, undefined, {
customTimers: {
setTimeout: originalSetTimeout,
clearTimeout: originalClearTimeout
}
});
})();
```
*/
readonly customTimers?: {
setTimeout: typeof global.setTimeout;
clearTimeout: typeof global.clearTimeout;
};
};
}
interface ClearablePromise<T> extends Promise<T>{
/**
Clear the timeout.
*/
clear: () => void;
}
declare const pTimeout: {
TimeoutError: typeof TimeoutErrorClass;
default: typeof pTimeout;
/**
Timeout a promise after a specified amount of time.
If you pass in a cancelable promise, specifically a promise with a `.cancel()` method, that method will be called when the `pTimeout` promise times out.
@param input - Promise to decorate.
@param milliseconds - Milliseconds before timing out.
@param message - Specify a custom error message or error. If you do a custom error, it's recommended to sub-class `pTimeout.TimeoutError`. Default: `'Promise timed out after 50 milliseconds'`.
@returns A decorated `input` that times out after `milliseconds` time. It has a `.clear()` method that clears the timeout.
@example
```
import delay = require('delay');
import pTimeout = require('p-timeout');
const delayedPromise = delay(200);
pTimeout(delayedPromise, 50).then(() => 'foo');
//=> [TimeoutError: Promise timed out after 50 milliseconds]
```
*/
<ValueType>(
input: PromiseLike<ValueType>,
milliseconds: number,
message?: string | Error,
options?: pTimeout.Options
): ClearablePromise<ValueType>;
/**
Timeout a promise after a specified amount of time.
If you pass in a cancelable promise, specifically a promise with a `.cancel()` method, that method will be called when the `pTimeout` promise times out.
@param input - Promise to decorate.
@param milliseconds - Milliseconds before timing out. Passing `Infinity` will cause it to never time out.
@param fallback - Do something other than rejecting with an error on timeout. You could for example retry.
@returns A decorated `input` that times out after `milliseconds` time. It has a `.clear()` method that clears the timeout.
@example
```
import delay = require('delay');
import pTimeout = require('p-timeout');
const delayedPromise = () => delay(200);
pTimeout(delayedPromise(), 50, () => {
return pTimeout(delayedPromise(), 300);
});
```
*/
<ValueType, ReturnType>(
input: PromiseLike<ValueType>,
milliseconds: number,
fallback: () => ReturnType | Promise<ReturnType>,
options?: pTimeout.Options
): ClearablePromise<ValueType | ReturnType>;
};
export = pTimeout;

71
node_modules/p-timeout/index.js generated vendored Normal file
View file

@ -0,0 +1,71 @@
'use strict';
class TimeoutError extends Error {
constructor(message) {
super(message);
this.name = 'TimeoutError';
}
}
const pTimeout = (promise, milliseconds, fallback, options) => {
let timer;
const cancelablePromise = new Promise((resolve, reject) => {
if (typeof milliseconds !== 'number' || milliseconds < 0) {
throw new TypeError('Expected `milliseconds` to be a positive number');
}
if (milliseconds === Infinity) {
resolve(promise);
return;
}
options = {
customTimers: {setTimeout, clearTimeout},
...options
};
timer = options.customTimers.setTimeout.call(undefined, () => {
if (typeof fallback === 'function') {
try {
resolve(fallback());
} catch (error) {
reject(error);
}
return;
}
const message = typeof fallback === 'string' ? fallback : `Promise timed out after ${milliseconds} milliseconds`;
const timeoutError = fallback instanceof Error ? fallback : new TimeoutError(message);
if (typeof promise.cancel === 'function') {
promise.cancel();
}
reject(timeoutError);
}, milliseconds);
(async () => {
try {
resolve(await promise);
} catch (error) {
reject(error);
} finally {
options.customTimers.clearTimeout.call(undefined, timer);
}
})();
});
cancelablePromise.clear = () => {
clearTimeout(timer);
timer = undefined;
};
return cancelablePromise;
};
module.exports = pTimeout;
// TODO: Remove this for the next major release
module.exports.default = pTimeout;
module.exports.TimeoutError = TimeoutError;

9
node_modules/p-timeout/license generated vendored Normal file
View file

@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
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.

44
node_modules/p-timeout/package.json generated vendored Normal file
View file

@ -0,0 +1,44 @@
{
"name": "p-timeout",
"version": "4.1.0",
"description": "Timeout a promise after a specified amount of time",
"license": "MIT",
"repository": "sindresorhus/p-timeout",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=10"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"promise",
"timeout",
"error",
"invalidate",
"async",
"await",
"promises",
"time",
"out",
"cancel",
"bluebird"
],
"devDependencies": {
"ava": "^2.4.0",
"delay": "^4.4.0",
"p-cancelable": "^2.0.0",
"tsd": "^0.13.1",
"xo": "^0.35.0",
"in-range": "^2.0.0",
"time-span": "^4.0.0"
}
}

117
node_modules/p-timeout/readme.md generated vendored Normal file
View file

@ -0,0 +1,117 @@
# p-timeout
> Timeout a promise after a specified amount of time
## Install
```
$ npm install p-timeout
```
## Usage
```js
const delay = require('delay');
const pTimeout = require('p-timeout');
const delayedPromise = delay(200);
pTimeout(delayedPromise, 50).then(() => 'foo');
//=> [TimeoutError: Promise timed out after 50 milliseconds]
```
## API
### pTimeout(input, milliseconds, message?, options?)
### pTimeout(input, milliseconds, fallback?, options?)
Returns a decorated `input` that times out after `milliseconds` time. It has a `.clear()` method that clears the timeout.
If you pass in a cancelable promise, specifically a promise with a `.cancel()` method, that method will be called when the `pTimeout` promise times out.
#### input
Type: `Promise`
Promise to decorate.
#### milliseconds
Type: `number`
Milliseconds before timing out.
Passing `Infinity` will cause it to never time out.
#### message
Type: `string | Error`\
Default: `'Promise timed out after 50 milliseconds'`
Specify a custom error message or error.
If you do a custom error, it's recommended to sub-class `pTimeout.TimeoutError`.
#### fallback
Type: `Function`
Do something other than rejecting with an error on timeout.
You could for example retry:
```js
const delay = require('delay');
const pTimeout = require('p-timeout');
const delayedPromise = () => delay(200);
pTimeout(delayedPromise(), 50, () => {
return pTimeout(delayedPromise(), 300);
});
```
#### options
Type: `object`
##### customTimers
Type: `object` with function properties `setTimeout` and `clearTimeout`
Custom implementations for the `setTimeout` and `clearTimeout` functions.
Useful for testing purposes, in particular to work around [`sinon.useFakeTimers()`](https://sinonjs.org/releases/latest/fake-timers/).
Example:
```js
const pTimeout = require('p-timeout');
const sinon = require('sinon');
(async () => {
const originalSetTimeout = setTimeout;
const originalClearTimeout = clearTimeout;
sinon.useFakeTimers();
// Use `pTimeout` without being affected by `sinon.useFakeTimers()`:
await pTimeout(doSomething(), 2000, undefined, {
customTimers: {
setTimeout: originalSetTimeout,
clearTimeout: originalClearTimeout
}
});
})();
```
### pTimeout.TimeoutError
Exposed for instance checking and sub-classing.
## Related
- [delay](https://github.com/sindresorhus/delay) - Delay a promise a specified amount of time
- [p-min-delay](https://github.com/sindresorhus/p-min-delay) - Delay a promise a minimum amount of time
- [p-retry](https://github.com/sindresorhus/p-retry) - Retry a promise-returning function
- [More…](https://github.com/sindresorhus/promise-fun)