@socketsecurity/sdk 1.11.0 → 1.11.1
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.
- package/CHANGELOG.md +12 -0
- package/README.md +153 -312
- package/dist/constants.js +23 -117
- package/dist/file-upload.js +118 -127
- package/dist/http-client.d.ts +3 -0
- package/dist/http-client.js +269 -211
- package/dist/index.js +43 -48
- package/dist/package.json.js +212 -0
- package/dist/quota-utils.d.ts +13 -6
- package/dist/quota-utils.js +128 -105
- package/dist/socket-sdk-class.js +1488 -1430
- package/dist/testing.d.ts +453 -0
- package/dist/testing.js +387 -0
- package/dist/user-agent.js +11 -7
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +66 -60
- package/package.json +27 -6
- package/dist/promise-queue.js +0 -91
- package/dist/types.js +0 -3
package/dist/promise-queue.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PromiseQueue = void 0;
|
|
4
|
-
class PromiseQueue {
|
|
5
|
-
queue = [];
|
|
6
|
-
running = 0;
|
|
7
|
-
maxConcurrency;
|
|
8
|
-
maxQueueLength;
|
|
9
|
-
/**
|
|
10
|
-
* Creates a new PromiseQueue
|
|
11
|
-
* @param maxConcurrency - Maximum number of promises that can run concurrently
|
|
12
|
-
* @param maxQueueLength - Maximum queue size (older tasks are dropped if exceeded)
|
|
13
|
-
*/
|
|
14
|
-
constructor(maxConcurrency, maxQueueLength) {
|
|
15
|
-
this.maxConcurrency = maxConcurrency;
|
|
16
|
-
this.maxQueueLength = maxQueueLength;
|
|
17
|
-
if (maxConcurrency < 1) {
|
|
18
|
-
throw new Error('maxConcurrency must be at least 1');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Add a task to the queue
|
|
23
|
-
* @param fn - Async function to execute
|
|
24
|
-
* @returns Promise that resolves with the function's result
|
|
25
|
-
*/
|
|
26
|
-
async add(fn) {
|
|
27
|
-
return await new Promise((resolve, reject) => {
|
|
28
|
-
const task = { fn, resolve, reject };
|
|
29
|
-
if (this.maxQueueLength && this.queue.length >= this.maxQueueLength) {
|
|
30
|
-
// Drop oldest task to prevent memory buildup
|
|
31
|
-
this.queue.shift();
|
|
32
|
-
}
|
|
33
|
-
this.queue.push(task);
|
|
34
|
-
this.runNext();
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
runNext() {
|
|
38
|
-
if (this.running >= this.maxConcurrency || this.queue.length === 0) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const task = this.queue.shift();
|
|
42
|
-
/* c8 ignore next 3 - Defensive check; unreachable since we verify queue.length above */
|
|
43
|
-
if (!task) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
this.running++;
|
|
47
|
-
task
|
|
48
|
-
.fn()
|
|
49
|
-
.then(task.resolve)
|
|
50
|
-
.catch(task.reject)
|
|
51
|
-
.finally(() => {
|
|
52
|
-
this.running--;
|
|
53
|
-
this.runNext();
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Wait for all queued and running tasks to complete
|
|
58
|
-
*/
|
|
59
|
-
async onIdle() {
|
|
60
|
-
return await new Promise(resolve => {
|
|
61
|
-
const check = () => {
|
|
62
|
-
if (this.running === 0 && this.queue.length === 0) {
|
|
63
|
-
resolve();
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
setImmediate(check);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
check();
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Get the number of tasks currently running
|
|
74
|
-
*/
|
|
75
|
-
get activeCount() {
|
|
76
|
-
return this.running;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Get the number of tasks waiting in the queue
|
|
80
|
-
*/
|
|
81
|
-
get pendingCount() {
|
|
82
|
-
return this.queue.length;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Clear all pending tasks from the queue (does not affect running tasks)
|
|
86
|
-
*/
|
|
87
|
-
clear() {
|
|
88
|
-
this.queue = [];
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.PromiseQueue = PromiseQueue;
|
package/dist/types.js
DELETED