Update checked-in dependencies
This commit is contained in:
parent
4fad06f438
commit
40a500c743
4168 changed files with 298222 additions and 374905 deletions
142
node_modules/p-map/index.d.ts
generated
vendored
142
node_modules/p-map/index.d.ts
generated
vendored
|
|
@ -1,67 +1,123 @@
|
|||
declare namespace pMap {
|
||||
interface Options {
|
||||
/**
|
||||
Number of concurrently pending promises returned by `mapper`.
|
||||
export interface Options {
|
||||
/**
|
||||
Number of concurrently pending promises returned by `mapper`.
|
||||
|
||||
Must be an integer from 1 and up or `Infinity`.
|
||||
Must be an integer from 1 and up or `Infinity`.
|
||||
|
||||
@default Infinity
|
||||
*/
|
||||
readonly concurrency?: number;
|
||||
|
||||
/**
|
||||
When set to `false`, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an [aggregated error](https://github.com/sindresorhus/aggregate-error) containing all the errors from the rejected promises.
|
||||
|
||||
@default true
|
||||
*/
|
||||
readonly stopOnError?: boolean;
|
||||
}
|
||||
@default Infinity
|
||||
*/
|
||||
readonly concurrency?: number;
|
||||
|
||||
/**
|
||||
Function which is called for every item in `input`. Expected to return a `Promise` or value.
|
||||
When `true`, the first mapper rejection will be rejected back to the consumer.
|
||||
|
||||
@param element - Iterated element.
|
||||
@param index - Index of the element in the source array.
|
||||
When `false`, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an [aggregated error](https://github.com/sindresorhus/aggregate-error) containing all the errors from the rejected promises.
|
||||
|
||||
Caveat: When `true`, any already-started async mappers will continue to run until they resolve or reject. In the case of infinite concurrency with sync iterables, *all* mappers are invoked on startup and will continue after the first rejection. [Issue #51](https://github.com/sindresorhus/p-map/issues/51) can be implemented for abort control.
|
||||
|
||||
@default true
|
||||
*/
|
||||
type Mapper<Element = any, NewElement = unknown> = (
|
||||
element: Element,
|
||||
index: number
|
||||
) => NewElement | Promise<NewElement>;
|
||||
readonly stopOnError?: boolean;
|
||||
|
||||
/**
|
||||
You can abort the promises using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
|
||||
|
||||
**Requires Node.js 16 or later.*
|
||||
|
||||
@example
|
||||
```
|
||||
import pMap from 'p-map';
|
||||
import delay from 'delay';
|
||||
|
||||
const abortController = new AbortController();
|
||||
|
||||
setTimeout(() => {
|
||||
abortController.abort();
|
||||
}, 500);
|
||||
|
||||
const mapper = async value => value;
|
||||
|
||||
await pMap([delay(1000), delay(1000)], mapper, {signal: abortController.signal});
|
||||
// Throws AbortError (DOMException) after 500 ms.
|
||||
```
|
||||
*/
|
||||
readonly signal?: AbortSignal;
|
||||
}
|
||||
|
||||
type MaybePromise<T> = T | Promise<T>;
|
||||
|
||||
/**
|
||||
@param input - Iterated over concurrently in the `mapper` function.
|
||||
Function which is called for every item in `input`. Expected to return a `Promise` or value.
|
||||
|
||||
@param element - Iterated element.
|
||||
@param index - Index of the element in the source array.
|
||||
*/
|
||||
export type Mapper<Element = any, NewElement = unknown> = (
|
||||
element: Element,
|
||||
index: number
|
||||
) => MaybePromise<NewElement | typeof pMapSkip>;
|
||||
|
||||
/**
|
||||
@param input - Synchronous or asynchronous iterable that is iterated over concurrently, calling the `mapper` function for each element. Each iterated item is `await`'d before the `mapper` is invoked so the iterable may return a `Promise` that resolves to an item. Asynchronous iterables (different from synchronous iterables that return `Promise` that resolves to an item) can be used when the next item may not be ready without waiting for an asynchronous process to complete and/or the end of the iterable may be reached after the asynchronous process completes. For example, reading from a remote queue when the queue has reached empty, or reading lines from a stream.
|
||||
@param mapper - Function which is called for every item in `input`. Expected to return a `Promise` or value.
|
||||
@returns A `Promise` that is fulfilled when all promises in `input` and ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. The fulfilled value is an `Array` of the fulfilled values returned from `mapper` in `input` order.
|
||||
|
||||
@example
|
||||
```
|
||||
import pMap = require('p-map');
|
||||
import got = require('got');
|
||||
import pMap from 'p-map';
|
||||
import got from 'got';
|
||||
|
||||
const sites = [
|
||||
getWebsiteFromUsername('https://sindresorhus'), //=> Promise
|
||||
'https://ava.li',
|
||||
getWebsiteFromUsername('sindresorhus'), //=> Promise
|
||||
'https://avajs.dev',
|
||||
'https://github.com'
|
||||
];
|
||||
|
||||
(async () => {
|
||||
const mapper = async site => {
|
||||
const {requestUrl} = await got.head(site);
|
||||
return requestUrl;
|
||||
};
|
||||
const mapper = async site => {
|
||||
const {requestUrl} = await got.head(site);
|
||||
return requestUrl;
|
||||
};
|
||||
|
||||
const result = await pMap(sites, mapper, {concurrency: 2});
|
||||
const result = await pMap(sites, mapper, {concurrency: 2});
|
||||
|
||||
console.log(result);
|
||||
//=> ['https://sindresorhus.com/', 'https://ava.li/', 'https://github.com/']
|
||||
})();
|
||||
console.log(result);
|
||||
//=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
|
||||
```
|
||||
*/
|
||||
declare function pMap<Element, NewElement>(
|
||||
input: Iterable<Element>,
|
||||
mapper: pMap.Mapper<Element, NewElement>,
|
||||
options?: pMap.Options
|
||||
): Promise<NewElement[]>;
|
||||
export default function pMap<Element, NewElement>(
|
||||
input: AsyncIterable<Element | Promise<Element>> | Iterable<Element | Promise<Element>>,
|
||||
mapper: Mapper<Element, NewElement>,
|
||||
options?: Options
|
||||
): Promise<Array<Exclude<NewElement, typeof pMapSkip>>>;
|
||||
|
||||
export = pMap;
|
||||
/**
|
||||
Return this value from a `mapper` function to skip including the value in the returned array.
|
||||
|
||||
@example
|
||||
```
|
||||
import pMap, {pMapSkip} from 'p-map';
|
||||
import got from 'got';
|
||||
|
||||
const sites = [
|
||||
getWebsiteFromUsername('sindresorhus'), //=> Promise
|
||||
'https://avajs.dev',
|
||||
'https://example.invalid',
|
||||
'https://github.com'
|
||||
];
|
||||
|
||||
const mapper = async site => {
|
||||
try {
|
||||
const {requestUrl} = await got.head(site);
|
||||
return requestUrl;
|
||||
} catch {
|
||||
return pMapSkip;
|
||||
}
|
||||
};
|
||||
|
||||
const result = await pMap(sites, mapper, {concurrency: 2});
|
||||
|
||||
console.log(result);
|
||||
//=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
|
||||
```
|
||||
*/
|
||||
export const pMapSkip: unique symbol;
|
||||
|
|
|
|||
170
node_modules/p-map/index.js
generated
vendored
170
node_modules/p-map/index.js
generated
vendored
|
|
@ -1,49 +1,127 @@
|
|||
'use strict';
|
||||
const AggregateError = require('aggregate-error');
|
||||
import AggregateError from 'aggregate-error';
|
||||
|
||||
module.exports = async (
|
||||
/**
|
||||
An error to be thrown when the request is aborted by AbortController.
|
||||
DOMException is thrown instead of this Error when DOMException is available.
|
||||
*/
|
||||
export class AbortError extends Error {
|
||||
constructor(message) {
|
||||
super();
|
||||
this.name = 'AbortError';
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
TODO: Remove AbortError and just throw DOMException when targeting Node 18.
|
||||
*/
|
||||
const getDOMException = errorMessage => globalThis.DOMException === undefined
|
||||
? new AbortError(errorMessage)
|
||||
: new DOMException(errorMessage);
|
||||
|
||||
/**
|
||||
TODO: Remove below function and just 'reject(signal.reason)' when targeting Node 18.
|
||||
*/
|
||||
const getAbortedReason = signal => {
|
||||
const reason = signal.reason === undefined
|
||||
? getDOMException('This operation was aborted.')
|
||||
: signal.reason;
|
||||
|
||||
return reason instanceof Error ? reason : getDOMException(reason);
|
||||
};
|
||||
|
||||
export default async function pMap(
|
||||
iterable,
|
||||
mapper,
|
||||
{
|
||||
concurrency = Infinity,
|
||||
stopOnError = true
|
||||
} = {}
|
||||
) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
concurrency = Number.POSITIVE_INFINITY,
|
||||
stopOnError = true,
|
||||
signal,
|
||||
} = {},
|
||||
) {
|
||||
return new Promise((resolve, reject_) => {
|
||||
if (iterable[Symbol.iterator] === undefined && iterable[Symbol.asyncIterator] === undefined) {
|
||||
throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
|
||||
}
|
||||
|
||||
if (typeof mapper !== 'function') {
|
||||
throw new TypeError('Mapper function is required');
|
||||
}
|
||||
|
||||
if (!((Number.isSafeInteger(concurrency) || concurrency === Infinity) && concurrency >= 1)) {
|
||||
if (!((Number.isSafeInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency >= 1)) {
|
||||
throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
|
||||
}
|
||||
|
||||
const result = [];
|
||||
const errors = [];
|
||||
const iterator = iterable[Symbol.iterator]();
|
||||
const skippedIndexesMap = new Map();
|
||||
let isRejected = false;
|
||||
let isResolved = false;
|
||||
let isIterableDone = false;
|
||||
let resolvingCount = 0;
|
||||
let currentIndex = 0;
|
||||
const iterator = iterable[Symbol.iterator] === undefined ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
|
||||
|
||||
const next = () => {
|
||||
if (isRejected) {
|
||||
const reject = reason => {
|
||||
isRejected = true;
|
||||
isResolved = true;
|
||||
reject_(reason);
|
||||
};
|
||||
|
||||
if (signal) {
|
||||
if (signal.aborted) {
|
||||
reject(getAbortedReason(signal));
|
||||
}
|
||||
|
||||
signal.addEventListener('abort', () => {
|
||||
reject(getAbortedReason(signal));
|
||||
});
|
||||
}
|
||||
|
||||
const next = async () => {
|
||||
if (isResolved) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nextItem = iterator.next();
|
||||
const nextItem = await iterator.next();
|
||||
|
||||
const index = currentIndex;
|
||||
currentIndex++;
|
||||
|
||||
// Note: `iterator.next()` can be called many times in parallel.
|
||||
// This can cause multiple calls to this `next()` function to
|
||||
// receive a `nextItem` with `done === true`.
|
||||
// The shutdown logic that rejects/resolves must be protected
|
||||
// so it runs only one time as the `skippedIndex` logic is
|
||||
// non-idempotent.
|
||||
if (nextItem.done) {
|
||||
isIterableDone = true;
|
||||
|
||||
if (resolvingCount === 0) {
|
||||
if (!stopOnError && errors.length !== 0) {
|
||||
if (resolvingCount === 0 && !isResolved) {
|
||||
if (!stopOnError && errors.length > 0) {
|
||||
reject(new AggregateError(errors));
|
||||
} else {
|
||||
resolve(result);
|
||||
return;
|
||||
}
|
||||
|
||||
isResolved = true;
|
||||
|
||||
if (skippedIndexesMap.size === 0) {
|
||||
resolve(result);
|
||||
return;
|
||||
}
|
||||
|
||||
const pureResult = [];
|
||||
|
||||
// Support multiple `pMapSkip`'s.
|
||||
for (const [index, value] of result.entries()) {
|
||||
if (skippedIndexesMap.get(index) === pMapSkip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pureResult.push(value);
|
||||
}
|
||||
|
||||
resolve(pureResult);
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
@ -51,31 +129,69 @@ module.exports = async (
|
|||
|
||||
resolvingCount++;
|
||||
|
||||
// Intentionally detached
|
||||
(async () => {
|
||||
try {
|
||||
const element = await nextItem.value;
|
||||
result[index] = await mapper(element, index);
|
||||
|
||||
if (isResolved) {
|
||||
return;
|
||||
}
|
||||
|
||||
const value = await mapper(element, index);
|
||||
|
||||
// Use Map to stage the index of the element.
|
||||
if (value === pMapSkip) {
|
||||
skippedIndexesMap.set(index, value);
|
||||
}
|
||||
|
||||
result[index] = value;
|
||||
|
||||
resolvingCount--;
|
||||
next();
|
||||
await next();
|
||||
} catch (error) {
|
||||
if (stopOnError) {
|
||||
isRejected = true;
|
||||
reject(error);
|
||||
} else {
|
||||
errors.push(error);
|
||||
resolvingCount--;
|
||||
next();
|
||||
|
||||
// In that case we can't really continue regardless of `stopOnError` state
|
||||
// since an iterable is likely to continue throwing after it throws once.
|
||||
// If we continue calling `next()` indefinitely we will likely end up
|
||||
// in an infinite loop of failed iteration.
|
||||
try {
|
||||
await next();
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
};
|
||||
|
||||
for (let i = 0; i < concurrency; i++) {
|
||||
next();
|
||||
// Create the concurrent runners in a detached (non-awaited)
|
||||
// promise. We need this so we can await the `next()` calls
|
||||
// to stop creating runners before hitting the concurrency limit
|
||||
// if the iterable has already been marked as done.
|
||||
// NOTE: We *must* do this for async iterators otherwise we'll spin up
|
||||
// infinite `next()` calls by default and never start the event loop.
|
||||
(async () => {
|
||||
for (let index = 0; index < concurrency; index++) {
|
||||
try {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await next();
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
break;
|
||||
}
|
||||
|
||||
if (isIterableDone) {
|
||||
break;
|
||||
if (isIterableDone || isRejected) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const pMapSkip = Symbol('skip');
|
||||
|
|
|
|||
22
node_modules/p-map/package.json
generated
vendored
22
node_modules/p-map/package.json
generated
vendored
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "p-map",
|
||||
"version": "4.0.0",
|
||||
"version": "5.5.0",
|
||||
"description": "Map over promises concurrently",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/p-map",
|
||||
|
|
@ -10,8 +10,10 @@
|
|||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
"node": ">=12"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
|
|
@ -39,15 +41,15 @@
|
|||
"bluebird"
|
||||
],
|
||||
"dependencies": {
|
||||
"aggregate-error": "^3.0.0"
|
||||
"aggregate-error": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^2.2.0",
|
||||
"delay": "^4.1.0",
|
||||
"in-range": "^2.0.0",
|
||||
"random-int": "^2.0.0",
|
||||
"time-span": "^3.1.0",
|
||||
"tsd": "^0.7.4",
|
||||
"xo": "^0.27.2"
|
||||
"ava": "^4.1.0",
|
||||
"delay": "^5.0.0",
|
||||
"in-range": "^3.0.0",
|
||||
"random-int": "^3.0.0",
|
||||
"time-span": "^5.0.0",
|
||||
"tsd": "^0.19.1",
|
||||
"xo": "^0.48.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
96
node_modules/p-map/readme.md
generated
vendored
96
node_modules/p-map/readme.md
generated
vendored
|
|
@ -1,9 +1,11 @@
|
|||
# p-map [](https://travis-ci.org/sindresorhus/p-map)
|
||||
# p-map
|
||||
|
||||
> Map over promises concurrently
|
||||
|
||||
Useful when you need to run promise-returning & async functions multiple times with different inputs concurrently.
|
||||
|
||||
This is different from `Promise.all()` in that you can control the concurrency and also decide whether or not to stop iterating when there's an error.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
|
|
@ -13,26 +15,24 @@ $ npm install p-map
|
|||
## Usage
|
||||
|
||||
```js
|
||||
const pMap = require('p-map');
|
||||
const got = require('got');
|
||||
import pMap from 'p-map';
|
||||
import got from 'got';
|
||||
|
||||
const sites = [
|
||||
getWebsiteFromUsername('https://sindresorhus'), //=> Promise
|
||||
'https://ava.li',
|
||||
getWebsiteFromUsername('sindresorhus'), //=> Promise
|
||||
'https://avajs.dev',
|
||||
'https://github.com'
|
||||
];
|
||||
|
||||
(async () => {
|
||||
const mapper = async site => {
|
||||
const {requestUrl} = await got.head(site);
|
||||
return requestUrl;
|
||||
};
|
||||
const mapper = async site => {
|
||||
const {requestUrl} = await got.head(site);
|
||||
return requestUrl;
|
||||
};
|
||||
|
||||
const result = await pMap(sites, mapper, {concurrency: 2});
|
||||
const result = await pMap(sites, mapper, {concurrency: 2});
|
||||
|
||||
console.log(result);
|
||||
//=> ['https://sindresorhus.com/', 'https://ava.li/', 'https://github.com/']
|
||||
})();
|
||||
console.log(result);
|
||||
//=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
|
||||
```
|
||||
|
||||
## API
|
||||
|
|
@ -43,9 +43,11 @@ Returns a `Promise` that is fulfilled when all promises in `input` and ones retu
|
|||
|
||||
#### input
|
||||
|
||||
Type: `Iterable<Promise | unknown>`
|
||||
Type: `AsyncIterable<Promise<unknown> | unknown> | Iterable<Promise<unknown> | unknown>`
|
||||
|
||||
Iterated over concurrently in the `mapper` function.
|
||||
Synchronous or asynchronous iterable that is iterated over concurrently, calling the `mapper` function for each element. Each iterated item is `await`'d before the `mapper` is invoked so the iterable may return a `Promise` that resolves to an item.
|
||||
|
||||
Asynchronous iterables (different from synchronous iterables that return `Promise` that resolves to an item) can be used when the next item may not be ready without waiting for an asynchronous process to complete and/or the end of the iterable may be reached after the asynchronous process completes. For example, reading from a remote queue when the queue has reached empty, or reading lines from a stream.
|
||||
|
||||
#### mapper(element, index)
|
||||
|
||||
|
|
@ -59,7 +61,7 @@ Type: `object`
|
|||
|
||||
##### concurrency
|
||||
|
||||
Type: `number` (Integer)\
|
||||
Type: `number` *(Integer)*\
|
||||
Default: `Infinity`\
|
||||
Minimum: `1`
|
||||
|
||||
|
|
@ -70,7 +72,65 @@ Number of concurrently pending promises returned by `mapper`.
|
|||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
When set to `false`, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an [aggregated error](https://github.com/sindresorhus/aggregate-error) containing all the errors from the rejected promises.
|
||||
When `true`, the first mapper rejection will be rejected back to the consumer.
|
||||
|
||||
When `false`, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an [aggregated error](https://github.com/sindresorhus/aggregate-error) containing all the errors from the rejected promises.
|
||||
|
||||
Caveat: When `true`, any already-started async mappers will continue to run until they resolve or reject. In the case of infinite concurrency with sync iterables, *all* mappers are invoked on startup and will continue after the first rejection. [Issue #51](https://github.com/sindresorhus/p-map/issues/51) can be implemented for abort control.
|
||||
|
||||
##### signal
|
||||
|
||||
Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
|
||||
|
||||
You can abort the promises using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
|
||||
|
||||
*Requires Node.js 16 or later.*
|
||||
|
||||
```js
|
||||
import pMap from 'p-map';
|
||||
import delay from 'delay';
|
||||
|
||||
const abortController = new AbortController();
|
||||
|
||||
setTimeout(() => {
|
||||
abortController.abort();
|
||||
}, 500);
|
||||
|
||||
const mapper = async value => value;
|
||||
|
||||
await pMap([delay(1000), delay(1000)], mapper, {signal: abortController.signal});
|
||||
// Throws AbortError (DOMException) after 500 ms.
|
||||
```
|
||||
|
||||
### pMapSkip
|
||||
|
||||
Return this value from a `mapper` function to skip including the value in the returned array.
|
||||
|
||||
```js
|
||||
import pMap, {pMapSkip} from 'p-map';
|
||||
import got from 'got';
|
||||
|
||||
const sites = [
|
||||
getWebsiteFromUsername('sindresorhus'), //=> Promise
|
||||
'https://avajs.dev',
|
||||
'https://example.invalid',
|
||||
'https://github.com'
|
||||
];
|
||||
|
||||
const mapper = async site => {
|
||||
try {
|
||||
const {requestUrl} = await got.head(site);
|
||||
return requestUrl;
|
||||
} catch {
|
||||
return pMapSkip;
|
||||
}
|
||||
};
|
||||
|
||||
const result = await pMap(sites, mapper, {concurrency: 2});
|
||||
|
||||
console.log(result);
|
||||
//=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
|
||||
```
|
||||
|
||||
## p-map for enterprise
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue