@depup/p-queue 9.1.1-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export default function lowerBound<T>(array: readonly T[], value: T, comparator: (a: T, b: T) => number): number;
@@ -0,0 +1,18 @@
1
+ // Port of lower_bound from https://en.cppreference.com/w/cpp/algorithm/lower_bound
2
+ // Used to compute insertion index to keep queue sorted after insertion
3
+ export default function lowerBound(array, value, comparator) {
4
+ let first = 0;
5
+ let count = array.length;
6
+ while (count > 0) {
7
+ const step = Math.trunc(count / 2);
8
+ let it = first + step;
9
+ if (comparator(array[it], value) <= 0) {
10
+ first = ++it;
11
+ count -= step + 1;
12
+ }
13
+ else {
14
+ count = step;
15
+ }
16
+ }
17
+ return first;
18
+ }
@@ -0,0 +1,137 @@
1
+ import { type Queue, type RunFunction } from './queue.js';
2
+ type TimeoutOptions = {
3
+ /**
4
+ Per-operation timeout in milliseconds. Operations will throw a `TimeoutError` if they don't complete within the specified time.
5
+
6
+ The timeout begins when the operation is dequeued and starts execution, not while it's waiting in the queue.
7
+
8
+ @default undefined
9
+
10
+ Can be overridden per task using the `timeout` option in `.add()`:
11
+
12
+ @example
13
+ ```
14
+ const queue = new PQueue({timeout: 5000});
15
+
16
+ // This task uses the global 5s timeout
17
+ await queue.add(() => fetchData());
18
+
19
+ // This task has a 10s timeout
20
+ await queue.add(() => slowTask(), {timeout: 10000});
21
+ ```
22
+ */
23
+ timeout?: number;
24
+ };
25
+ export type Options<QueueType extends Queue<RunFunction, QueueOptions>, QueueOptions extends QueueAddOptions> = {
26
+ /**
27
+ Concurrency limit.
28
+
29
+ Minimum: `1`.
30
+
31
+ @default Infinity
32
+ */
33
+ readonly concurrency?: number;
34
+ /**
35
+ Whether queue tasks within concurrency limit, are auto-executed as soon as they're added.
36
+
37
+ @default true
38
+ */
39
+ readonly autoStart?: boolean;
40
+ /**
41
+ Class with a `enqueue` and `dequeue` method, and a `size` getter. See the [Custom QueueClass](https://github.com/sindresorhus/p-queue#custom-queueclass) section.
42
+ */
43
+ readonly queueClass?: new () => QueueType;
44
+ /**
45
+ The max number of runs in the given interval of time.
46
+
47
+ Minimum: `1`.
48
+
49
+ @default Infinity
50
+ */
51
+ readonly intervalCap?: number;
52
+ /**
53
+ The length of time in milliseconds before the interval count resets. Must be finite.
54
+
55
+ Minimum: `0`.
56
+
57
+ @default 0
58
+ */
59
+ readonly interval?: number;
60
+ /**
61
+ Whether the task must finish in the given interval or will be carried over into the next interval count.
62
+
63
+ @default false
64
+ */
65
+ readonly carryoverIntervalCount?: boolean;
66
+ /**
67
+ @deprecated Renamed to `carryoverIntervalCount`.
68
+ */
69
+ readonly carryoverConcurrencyCount?: boolean;
70
+ /**
71
+ Whether to use strict mode for rate limiting (sliding window algorithm).
72
+
73
+ When enabled, ensures that no more than `intervalCap` tasks execute in any rolling `interval` window, rather than resetting the count at fixed intervals. This provides more predictable and evenly distributed execution.
74
+
75
+ @default false
76
+
77
+ For example, with `intervalCap: 2` and `interval: 1000`:
78
+ - __Default mode (fixed window)__: Tasks can burst at window boundaries. You could execute 2 tasks at 999ms and 2 more at 1000ms, resulting in 4 tasks within 1ms.
79
+ - __Strict mode (sliding window)__: Enforces that no more than 2 tasks execute in any 1000ms rolling window, preventing bursts.
80
+
81
+ Strict mode is more resource-intensive as it tracks individual execution timestamps. Use it when you need guaranteed rate-limit compliance, such as when interacting with APIs that enforce strict rate limits.
82
+
83
+ The `carryoverIntervalCount` option has no effect when `strict` mode is enabled, as strict mode tracks actual execution timestamps rather than counting pending tasks.
84
+ */
85
+ readonly strict?: boolean;
86
+ } & TimeoutOptions;
87
+ export type QueueAddOptions = {
88
+ /**
89
+ Priority of operation. Operations with greater priority will be scheduled first.
90
+
91
+ @default 0
92
+ */
93
+ readonly priority?: number;
94
+ /**
95
+ Unique identifier for the promise function, used to update its priority before execution. If not specified, it is auto-assigned an incrementing BigInt starting from `1n`.
96
+ */
97
+ id?: string;
98
+ } & TaskOptions & TimeoutOptions;
99
+ export type TaskOptions = {
100
+ /**
101
+ [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) for cancellation of the operation. When aborted, it will be removed from the queue and the `queue.add()` call will reject with an `AbortError`. If the operation is already running, the signal will need to be handled by the operation itself.
102
+
103
+ @example
104
+ ```
105
+ import PQueue, {AbortError} from 'p-queue';
106
+ import got, {CancelError} from 'got';
107
+
108
+ const queue = new PQueue();
109
+
110
+ const controller = new AbortController();
111
+
112
+ try {
113
+ await queue.add(({signal}) => {
114
+ const request = got('https://sindresorhus.com');
115
+
116
+ signal.addEventListener('abort', () => {
117
+ request.cancel();
118
+ });
119
+
120
+ try {
121
+ return await request;
122
+ } catch (error) {
123
+ if (!(error instanceof CancelError)) {
124
+ throw error;
125
+ }
126
+ }
127
+ }, {signal: controller.signal});
128
+ } catch (error) {
129
+ if (!(error instanceof AbortError)) {
130
+ throw error;
131
+ }
132
+ }
133
+ ```
134
+ */
135
+ readonly signal?: AbortSignal | undefined;
136
+ };
137
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import { type Queue, type RunFunction } from './queue.js';
2
+ import { type QueueAddOptions } from './options.js';
3
+ export type PriorityQueueOptions = {
4
+ priority?: number;
5
+ } & QueueAddOptions;
6
+ export default class PriorityQueue implements Queue<RunFunction, PriorityQueueOptions> {
7
+ #private;
8
+ enqueue(run: RunFunction, options?: Partial<PriorityQueueOptions>): void;
9
+ setPriority(id: string, priority: number): void;
10
+ remove(id: string): void;
11
+ remove(run: RunFunction): void;
12
+ dequeue(): RunFunction | undefined;
13
+ filter(options: Readonly<Partial<PriorityQueueOptions>>): RunFunction[];
14
+ get size(): number;
15
+ }
@@ -0,0 +1,47 @@
1
+ import lowerBound from './lower-bound.js';
2
+ export default class PriorityQueue {
3
+ #queue = [];
4
+ enqueue(run, options) {
5
+ const { priority = 0, id, } = options ?? {};
6
+ const element = {
7
+ priority,
8
+ id,
9
+ run,
10
+ };
11
+ if (this.size === 0 || this.#queue[this.size - 1].priority >= priority) {
12
+ this.#queue.push(element);
13
+ return;
14
+ }
15
+ const index = lowerBound(this.#queue, element, (a, b) => b.priority - a.priority);
16
+ this.#queue.splice(index, 0, element);
17
+ }
18
+ setPriority(id, priority) {
19
+ const index = this.#queue.findIndex((element) => element.id === id);
20
+ if (index === -1) {
21
+ throw new ReferenceError(`No promise function with the id "${id}" exists in the queue.`);
22
+ }
23
+ const [item] = this.#queue.splice(index, 1);
24
+ this.enqueue(item.run, { priority, id });
25
+ }
26
+ remove(idOrRun) {
27
+ const index = this.#queue.findIndex((element) => {
28
+ if (typeof idOrRun === 'string') {
29
+ return element.id === idOrRun;
30
+ }
31
+ return element.run === idOrRun;
32
+ });
33
+ if (index !== -1) {
34
+ this.#queue.splice(index, 1);
35
+ }
36
+ }
37
+ dequeue() {
38
+ const item = this.#queue.shift();
39
+ return item?.run;
40
+ }
41
+ filter(options) {
42
+ return this.#queue.filter((element) => element.priority === options.priority).map((element) => element.run);
43
+ }
44
+ get size() {
45
+ return this.#queue.length;
46
+ }
47
+ }
@@ -0,0 +1,9 @@
1
+ export type RunFunction = () => Promise<unknown>;
2
+ export type Queue<Element, Options> = {
3
+ size: number;
4
+ filter: (options: Readonly<Partial<Options>>) => Element[];
5
+ dequeue: () => Element | undefined;
6
+ enqueue: (run: Element, options?: Partial<Options>) => void;
7
+ setPriority: (id: string, priority: number) => void;
8
+ remove?: (id: string) => void;
9
+ };
package/dist/queue.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ 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:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ 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.
package/package.json ADDED
@@ -0,0 +1,105 @@
1
+ {
2
+ "name": "@depup/p-queue",
3
+ "version": "9.1.1-depup.0",
4
+ "description": "Promise queue with concurrency control (with updated dependencies)",
5
+ "license": "MIT",
6
+ "repository": "sindresorhus/p-queue",
7
+ "funding": "https://github.com/sponsors/sindresorhus",
8
+ "type": "module",
9
+ "exports": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "sideEffects": false,
14
+ "engines": {
15
+ "node": ">=20"
16
+ },
17
+ "scripts": {
18
+ "build": "del-cli dist && tsc",
19
+ "test": "xo && node --import=tsx/esm --test test/*.ts && del-cli dist && tsc && tsd",
20
+ "bench": "node --import=tsx/esm bench.ts"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "changes.json",
25
+ "README.md"
26
+ ],
27
+ "types": "dist/index.d.ts",
28
+ "keywords": [
29
+ "p-queue",
30
+ "depup",
31
+ "updated-dependencies",
32
+ "security",
33
+ "latest",
34
+ "patched",
35
+ "promise",
36
+ "queue",
37
+ "enqueue",
38
+ "limit",
39
+ "limited",
40
+ "concurrency",
41
+ "throttle",
42
+ "throat",
43
+ "rate",
44
+ "batch",
45
+ "ratelimit",
46
+ "priority",
47
+ "priorityqueue",
48
+ "fifo",
49
+ "job",
50
+ "task",
51
+ "async",
52
+ "await",
53
+ "promises",
54
+ "bluebird"
55
+ ],
56
+ "dependencies": {
57
+ "eventemitter3": "^5.0.4",
58
+ "p-timeout": "^7.0.1"
59
+ },
60
+ "devDependencies": {
61
+ "@sindresorhus/tsconfig": "^8.0.1",
62
+ "@types/benchmark": "^2.1.5",
63
+ "@types/node": "^24.5.1",
64
+ "benchmark": "^2.1.4",
65
+ "del-cli": "^6.0.0",
66
+ "delay": "^6.0.0",
67
+ "in-range": "^3.0.0",
68
+ "p-defer": "^4.0.1",
69
+ "random-int": "^3.1.0",
70
+ "time-span": "^5.1.0",
71
+ "tsd": "^0.33.0",
72
+ "tsx": "^4.20.5",
73
+ "typescript": "^5.9.2",
74
+ "xo": "^1.2.2"
75
+ },
76
+ "xo": {
77
+ "rules": {
78
+ "@typescript-eslint/member-ordering": "off",
79
+ "@typescript-eslint/no-floating-promises": "off",
80
+ "@typescript-eslint/no-unsafe-call": "off",
81
+ "@typescript-eslint/no-unsafe-assignment": "off",
82
+ "@typescript-eslint/no-unsafe-return": "off",
83
+ "@typescript-eslint/no-unsafe-argument": "off",
84
+ "@typescript-eslint/prefer-promise-reject-errors": "off",
85
+ "ava/no-import-test-files": "off"
86
+ }
87
+ },
88
+ "depup": {
89
+ "changes": {
90
+ "eventemitter3": {
91
+ "from": "^5.0.1",
92
+ "to": "^5.0.4"
93
+ },
94
+ "p-timeout": {
95
+ "from": "^7.0.0",
96
+ "to": "^7.0.1"
97
+ }
98
+ },
99
+ "depsUpdated": 2,
100
+ "originalPackage": "p-queue",
101
+ "originalVersion": "9.1.1",
102
+ "processedAt": "2026-04-01T20:19:42.008Z",
103
+ "smokeTest": "passed"
104
+ }
105
+ }