@uniformdev/canvas 20.63.1-alpha.12 → 20.63.1-alpha.18
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/dist/index.esm.js +544 -9
- package/dist/index.js +523 -10
- package/dist/index.mjs +544 -9
- package/package.json +9 -9
package/dist/index.esm.js
CHANGED
|
@@ -1,25 +1,560 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1
7
|
var __typeError = (msg) => {
|
|
2
8
|
throw TypeError(msg);
|
|
3
9
|
};
|
|
10
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
4
29
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
30
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
31
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
32
|
|
|
33
|
+
// ../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js
|
|
34
|
+
var require_yocto_queue = __commonJS({
|
|
35
|
+
"../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports, module) {
|
|
36
|
+
"use strict";
|
|
37
|
+
var Node = class {
|
|
38
|
+
/// value;
|
|
39
|
+
/// next;
|
|
40
|
+
constructor(value) {
|
|
41
|
+
this.value = value;
|
|
42
|
+
this.next = void 0;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var Queue = class {
|
|
46
|
+
// TODO: Use private class fields when targeting Node.js 12.
|
|
47
|
+
// #_head;
|
|
48
|
+
// #_tail;
|
|
49
|
+
// #_size;
|
|
50
|
+
constructor() {
|
|
51
|
+
this.clear();
|
|
52
|
+
}
|
|
53
|
+
enqueue(value) {
|
|
54
|
+
const node = new Node(value);
|
|
55
|
+
if (this._head) {
|
|
56
|
+
this._tail.next = node;
|
|
57
|
+
this._tail = node;
|
|
58
|
+
} else {
|
|
59
|
+
this._head = node;
|
|
60
|
+
this._tail = node;
|
|
61
|
+
}
|
|
62
|
+
this._size++;
|
|
63
|
+
}
|
|
64
|
+
dequeue() {
|
|
65
|
+
const current = this._head;
|
|
66
|
+
if (!current) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this._head = this._head.next;
|
|
70
|
+
this._size--;
|
|
71
|
+
return current.value;
|
|
72
|
+
}
|
|
73
|
+
clear() {
|
|
74
|
+
this._head = void 0;
|
|
75
|
+
this._tail = void 0;
|
|
76
|
+
this._size = 0;
|
|
77
|
+
}
|
|
78
|
+
get size() {
|
|
79
|
+
return this._size;
|
|
80
|
+
}
|
|
81
|
+
*[Symbol.iterator]() {
|
|
82
|
+
let current = this._head;
|
|
83
|
+
while (current) {
|
|
84
|
+
yield current.value;
|
|
85
|
+
current = current.next;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
module.exports = Queue;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// ../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js
|
|
94
|
+
var require_p_limit = __commonJS({
|
|
95
|
+
"../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports, module) {
|
|
96
|
+
"use strict";
|
|
97
|
+
var Queue = require_yocto_queue();
|
|
98
|
+
var pLimit2 = (concurrency) => {
|
|
99
|
+
if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
|
|
100
|
+
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
101
|
+
}
|
|
102
|
+
const queue = new Queue();
|
|
103
|
+
let activeCount = 0;
|
|
104
|
+
const next = () => {
|
|
105
|
+
activeCount--;
|
|
106
|
+
if (queue.size > 0) {
|
|
107
|
+
queue.dequeue()();
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const run = async (fn, resolve, ...args) => {
|
|
111
|
+
activeCount++;
|
|
112
|
+
const result = (async () => fn(...args))();
|
|
113
|
+
resolve(result);
|
|
114
|
+
try {
|
|
115
|
+
await result;
|
|
116
|
+
} catch (e) {
|
|
117
|
+
}
|
|
118
|
+
next();
|
|
119
|
+
};
|
|
120
|
+
const enqueue = (fn, resolve, ...args) => {
|
|
121
|
+
queue.enqueue(run.bind(null, fn, resolve, ...args));
|
|
122
|
+
(async () => {
|
|
123
|
+
await Promise.resolve();
|
|
124
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
125
|
+
queue.dequeue()();
|
|
126
|
+
}
|
|
127
|
+
})();
|
|
128
|
+
};
|
|
129
|
+
const generator = (fn, ...args) => new Promise((resolve) => {
|
|
130
|
+
enqueue(fn, resolve, ...args);
|
|
131
|
+
});
|
|
132
|
+
Object.defineProperties(generator, {
|
|
133
|
+
activeCount: {
|
|
134
|
+
get: () => activeCount
|
|
135
|
+
},
|
|
136
|
+
pendingCount: {
|
|
137
|
+
get: () => queue.size
|
|
138
|
+
},
|
|
139
|
+
clearQueue: {
|
|
140
|
+
value: () => {
|
|
141
|
+
queue.clear();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return generator;
|
|
146
|
+
};
|
|
147
|
+
module.exports = pLimit2;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js
|
|
152
|
+
var require_retry_operation = __commonJS({
|
|
153
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports, module) {
|
|
154
|
+
"use strict";
|
|
155
|
+
function RetryOperation(timeouts, options) {
|
|
156
|
+
if (typeof options === "boolean") {
|
|
157
|
+
options = { forever: options };
|
|
158
|
+
}
|
|
159
|
+
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
|
|
160
|
+
this._timeouts = timeouts;
|
|
161
|
+
this._options = options || {};
|
|
162
|
+
this._maxRetryTime = options && options.maxRetryTime || Infinity;
|
|
163
|
+
this._fn = null;
|
|
164
|
+
this._errors = [];
|
|
165
|
+
this._attempts = 1;
|
|
166
|
+
this._operationTimeout = null;
|
|
167
|
+
this._operationTimeoutCb = null;
|
|
168
|
+
this._timeout = null;
|
|
169
|
+
this._operationStart = null;
|
|
170
|
+
this._timer = null;
|
|
171
|
+
if (this._options.forever) {
|
|
172
|
+
this._cachedTimeouts = this._timeouts.slice(0);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
module.exports = RetryOperation;
|
|
176
|
+
RetryOperation.prototype.reset = function() {
|
|
177
|
+
this._attempts = 1;
|
|
178
|
+
this._timeouts = this._originalTimeouts.slice(0);
|
|
179
|
+
};
|
|
180
|
+
RetryOperation.prototype.stop = function() {
|
|
181
|
+
if (this._timeout) {
|
|
182
|
+
clearTimeout(this._timeout);
|
|
183
|
+
}
|
|
184
|
+
if (this._timer) {
|
|
185
|
+
clearTimeout(this._timer);
|
|
186
|
+
}
|
|
187
|
+
this._timeouts = [];
|
|
188
|
+
this._cachedTimeouts = null;
|
|
189
|
+
};
|
|
190
|
+
RetryOperation.prototype.retry = function(err) {
|
|
191
|
+
if (this._timeout) {
|
|
192
|
+
clearTimeout(this._timeout);
|
|
193
|
+
}
|
|
194
|
+
if (!err) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
var currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
198
|
+
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
199
|
+
this._errors.push(err);
|
|
200
|
+
this._errors.unshift(new Error("RetryOperation timeout occurred"));
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
this._errors.push(err);
|
|
204
|
+
var timeout = this._timeouts.shift();
|
|
205
|
+
if (timeout === void 0) {
|
|
206
|
+
if (this._cachedTimeouts) {
|
|
207
|
+
this._errors.splice(0, this._errors.length - 1);
|
|
208
|
+
timeout = this._cachedTimeouts.slice(-1);
|
|
209
|
+
} else {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
var self = this;
|
|
214
|
+
this._timer = setTimeout(function() {
|
|
215
|
+
self._attempts++;
|
|
216
|
+
if (self._operationTimeoutCb) {
|
|
217
|
+
self._timeout = setTimeout(function() {
|
|
218
|
+
self._operationTimeoutCb(self._attempts);
|
|
219
|
+
}, self._operationTimeout);
|
|
220
|
+
if (self._options.unref) {
|
|
221
|
+
self._timeout.unref();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
self._fn(self._attempts);
|
|
225
|
+
}, timeout);
|
|
226
|
+
if (this._options.unref) {
|
|
227
|
+
this._timer.unref();
|
|
228
|
+
}
|
|
229
|
+
return true;
|
|
230
|
+
};
|
|
231
|
+
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
|
|
232
|
+
this._fn = fn;
|
|
233
|
+
if (timeoutOps) {
|
|
234
|
+
if (timeoutOps.timeout) {
|
|
235
|
+
this._operationTimeout = timeoutOps.timeout;
|
|
236
|
+
}
|
|
237
|
+
if (timeoutOps.cb) {
|
|
238
|
+
this._operationTimeoutCb = timeoutOps.cb;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
var self = this;
|
|
242
|
+
if (this._operationTimeoutCb) {
|
|
243
|
+
this._timeout = setTimeout(function() {
|
|
244
|
+
self._operationTimeoutCb();
|
|
245
|
+
}, self._operationTimeout);
|
|
246
|
+
}
|
|
247
|
+
this._operationStart = (/* @__PURE__ */ new Date()).getTime();
|
|
248
|
+
this._fn(this._attempts);
|
|
249
|
+
};
|
|
250
|
+
RetryOperation.prototype.try = function(fn) {
|
|
251
|
+
console.log("Using RetryOperation.try() is deprecated");
|
|
252
|
+
this.attempt(fn);
|
|
253
|
+
};
|
|
254
|
+
RetryOperation.prototype.start = function(fn) {
|
|
255
|
+
console.log("Using RetryOperation.start() is deprecated");
|
|
256
|
+
this.attempt(fn);
|
|
257
|
+
};
|
|
258
|
+
RetryOperation.prototype.start = RetryOperation.prototype.try;
|
|
259
|
+
RetryOperation.prototype.errors = function() {
|
|
260
|
+
return this._errors;
|
|
261
|
+
};
|
|
262
|
+
RetryOperation.prototype.attempts = function() {
|
|
263
|
+
return this._attempts;
|
|
264
|
+
};
|
|
265
|
+
RetryOperation.prototype.mainError = function() {
|
|
266
|
+
if (this._errors.length === 0) {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
var counts = {};
|
|
270
|
+
var mainError = null;
|
|
271
|
+
var mainErrorCount = 0;
|
|
272
|
+
for (var i = 0; i < this._errors.length; i++) {
|
|
273
|
+
var error = this._errors[i];
|
|
274
|
+
var message = error.message;
|
|
275
|
+
var count = (counts[message] || 0) + 1;
|
|
276
|
+
counts[message] = count;
|
|
277
|
+
if (count >= mainErrorCount) {
|
|
278
|
+
mainError = error;
|
|
279
|
+
mainErrorCount = count;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return mainError;
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js
|
|
288
|
+
var require_retry = __commonJS({
|
|
289
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js"(exports) {
|
|
290
|
+
"use strict";
|
|
291
|
+
var RetryOperation = require_retry_operation();
|
|
292
|
+
exports.operation = function(options) {
|
|
293
|
+
var timeouts = exports.timeouts(options);
|
|
294
|
+
return new RetryOperation(timeouts, {
|
|
295
|
+
forever: options && (options.forever || options.retries === Infinity),
|
|
296
|
+
unref: options && options.unref,
|
|
297
|
+
maxRetryTime: options && options.maxRetryTime
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
exports.timeouts = function(options) {
|
|
301
|
+
if (options instanceof Array) {
|
|
302
|
+
return [].concat(options);
|
|
303
|
+
}
|
|
304
|
+
var opts = {
|
|
305
|
+
retries: 10,
|
|
306
|
+
factor: 2,
|
|
307
|
+
minTimeout: 1 * 1e3,
|
|
308
|
+
maxTimeout: Infinity,
|
|
309
|
+
randomize: false
|
|
310
|
+
};
|
|
311
|
+
for (var key in options) {
|
|
312
|
+
opts[key] = options[key];
|
|
313
|
+
}
|
|
314
|
+
if (opts.minTimeout > opts.maxTimeout) {
|
|
315
|
+
throw new Error("minTimeout is greater than maxTimeout");
|
|
316
|
+
}
|
|
317
|
+
var timeouts = [];
|
|
318
|
+
for (var i = 0; i < opts.retries; i++) {
|
|
319
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
320
|
+
}
|
|
321
|
+
if (options && options.forever && !timeouts.length) {
|
|
322
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
323
|
+
}
|
|
324
|
+
timeouts.sort(function(a, b) {
|
|
325
|
+
return a - b;
|
|
326
|
+
});
|
|
327
|
+
return timeouts;
|
|
328
|
+
};
|
|
329
|
+
exports.createTimeout = function(attempt, opts) {
|
|
330
|
+
var random = opts.randomize ? Math.random() + 1 : 1;
|
|
331
|
+
var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
|
|
332
|
+
timeout = Math.min(timeout, opts.maxTimeout);
|
|
333
|
+
return timeout;
|
|
334
|
+
};
|
|
335
|
+
exports.wrap = function(obj, options, methods) {
|
|
336
|
+
if (options instanceof Array) {
|
|
337
|
+
methods = options;
|
|
338
|
+
options = null;
|
|
339
|
+
}
|
|
340
|
+
if (!methods) {
|
|
341
|
+
methods = [];
|
|
342
|
+
for (var key in obj) {
|
|
343
|
+
if (typeof obj[key] === "function") {
|
|
344
|
+
methods.push(key);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
for (var i = 0; i < methods.length; i++) {
|
|
349
|
+
var method = methods[i];
|
|
350
|
+
var original = obj[method];
|
|
351
|
+
obj[method] = function retryWrapper(original2) {
|
|
352
|
+
var op = exports.operation(options);
|
|
353
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
354
|
+
var callback = args.pop();
|
|
355
|
+
args.push(function(err) {
|
|
356
|
+
if (op.retry(err)) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (err) {
|
|
360
|
+
arguments[0] = op.mainError();
|
|
361
|
+
}
|
|
362
|
+
callback.apply(this, arguments);
|
|
363
|
+
});
|
|
364
|
+
op.attempt(function() {
|
|
365
|
+
original2.apply(obj, args);
|
|
366
|
+
});
|
|
367
|
+
}.bind(obj, original);
|
|
368
|
+
obj[method].options = options;
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
// ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js
|
|
375
|
+
var require_retry2 = __commonJS({
|
|
376
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js"(exports, module) {
|
|
377
|
+
"use strict";
|
|
378
|
+
module.exports = require_retry();
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
|
|
8
382
|
// src/CanvasClient.ts
|
|
9
383
|
import { ApiClient, rewriteFiltersForApi } from "@uniformdev/context/api";
|
|
10
384
|
|
|
11
385
|
// src/enhancement/createLimitPolicy.ts
|
|
386
|
+
var import_p_limit = __toESM(require_p_limit());
|
|
12
387
|
import { ApiClientError } from "@uniformdev/context/api";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
388
|
+
|
|
389
|
+
// ../../node_modules/.pnpm/p-retry@5.1.2/node_modules/p-retry/index.js
|
|
390
|
+
var import_retry = __toESM(require_retry2(), 1);
|
|
391
|
+
var networkErrorMsgs = /* @__PURE__ */ new Set([
|
|
392
|
+
"Failed to fetch",
|
|
393
|
+
// Chrome
|
|
394
|
+
"NetworkError when attempting to fetch resource.",
|
|
395
|
+
// Firefox
|
|
396
|
+
"The Internet connection appears to be offline.",
|
|
397
|
+
// Safari
|
|
398
|
+
"Network request failed",
|
|
399
|
+
// `cross-fetch`
|
|
400
|
+
"fetch failed"
|
|
401
|
+
// Undici (Node.js)
|
|
402
|
+
]);
|
|
403
|
+
var AbortError = class extends Error {
|
|
404
|
+
constructor(message) {
|
|
405
|
+
super();
|
|
406
|
+
if (message instanceof Error) {
|
|
407
|
+
this.originalError = message;
|
|
408
|
+
({ message } = message);
|
|
409
|
+
} else {
|
|
410
|
+
this.originalError = new Error(message);
|
|
411
|
+
this.originalError.stack = this.stack;
|
|
412
|
+
}
|
|
413
|
+
this.name = "AbortError";
|
|
414
|
+
this.message = message;
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
var decorateErrorWithCounts = (error, attemptNumber, options) => {
|
|
418
|
+
const retriesLeft = options.retries - (attemptNumber - 1);
|
|
419
|
+
error.attemptNumber = attemptNumber;
|
|
420
|
+
error.retriesLeft = retriesLeft;
|
|
421
|
+
return error;
|
|
422
|
+
};
|
|
423
|
+
var isNetworkError = (errorMessage) => networkErrorMsgs.has(errorMessage);
|
|
424
|
+
var getDOMException = (errorMessage) => globalThis.DOMException === void 0 ? new Error(errorMessage) : new DOMException(errorMessage);
|
|
425
|
+
async function pRetry(input, options) {
|
|
426
|
+
return new Promise((resolve, reject) => {
|
|
427
|
+
options = {
|
|
428
|
+
onFailedAttempt() {
|
|
429
|
+
},
|
|
430
|
+
retries: 10,
|
|
431
|
+
...options
|
|
432
|
+
};
|
|
433
|
+
const operation = import_retry.default.operation(options);
|
|
434
|
+
operation.attempt(async (attemptNumber) => {
|
|
435
|
+
try {
|
|
436
|
+
resolve(await input(attemptNumber));
|
|
437
|
+
} catch (error) {
|
|
438
|
+
if (!(error instanceof Error)) {
|
|
439
|
+
reject(new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`));
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (error instanceof AbortError) {
|
|
443
|
+
operation.stop();
|
|
444
|
+
reject(error.originalError);
|
|
445
|
+
} else if (error instanceof TypeError && !isNetworkError(error.message)) {
|
|
446
|
+
operation.stop();
|
|
447
|
+
reject(error);
|
|
448
|
+
} else {
|
|
449
|
+
decorateErrorWithCounts(error, attemptNumber, options);
|
|
450
|
+
try {
|
|
451
|
+
await options.onFailedAttempt(error);
|
|
452
|
+
} catch (error2) {
|
|
453
|
+
reject(error2);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (!operation.retry(error)) {
|
|
457
|
+
reject(operation.mainError());
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
if (options.signal && !options.signal.aborted) {
|
|
463
|
+
options.signal.addEventListener("abort", () => {
|
|
464
|
+
operation.stop();
|
|
465
|
+
const reason = options.signal.reason === void 0 ? getDOMException("The operation was aborted.") : options.signal.reason;
|
|
466
|
+
reject(reason instanceof Error ? reason : getDOMException(reason));
|
|
467
|
+
}, {
|
|
468
|
+
once: true
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// ../../node_modules/.pnpm/p-throttle@5.0.0/node_modules/p-throttle/index.js
|
|
475
|
+
var AbortError2 = class extends Error {
|
|
476
|
+
constructor() {
|
|
477
|
+
super("Throttled function aborted");
|
|
478
|
+
this.name = "AbortError";
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
function pThrottle({ limit, interval, strict }) {
|
|
482
|
+
if (!Number.isFinite(limit)) {
|
|
483
|
+
throw new TypeError("Expected `limit` to be a finite number");
|
|
484
|
+
}
|
|
485
|
+
if (!Number.isFinite(interval)) {
|
|
486
|
+
throw new TypeError("Expected `interval` to be a finite number");
|
|
487
|
+
}
|
|
488
|
+
const queue = /* @__PURE__ */ new Map();
|
|
489
|
+
let currentTick = 0;
|
|
490
|
+
let activeCount = 0;
|
|
491
|
+
function windowedDelay() {
|
|
492
|
+
const now = Date.now();
|
|
493
|
+
if (now - currentTick > interval) {
|
|
494
|
+
activeCount = 1;
|
|
495
|
+
currentTick = now;
|
|
496
|
+
return 0;
|
|
497
|
+
}
|
|
498
|
+
if (activeCount < limit) {
|
|
499
|
+
activeCount++;
|
|
500
|
+
} else {
|
|
501
|
+
currentTick += interval;
|
|
502
|
+
activeCount = 1;
|
|
503
|
+
}
|
|
504
|
+
return currentTick - now;
|
|
505
|
+
}
|
|
506
|
+
const strictTicks = [];
|
|
507
|
+
function strictDelay() {
|
|
508
|
+
const now = Date.now();
|
|
509
|
+
if (strictTicks.length < limit) {
|
|
510
|
+
strictTicks.push(now);
|
|
511
|
+
return 0;
|
|
512
|
+
}
|
|
513
|
+
const earliestTime = strictTicks.shift() + interval;
|
|
514
|
+
if (now >= earliestTime) {
|
|
515
|
+
strictTicks.push(now);
|
|
516
|
+
return 0;
|
|
517
|
+
}
|
|
518
|
+
strictTicks.push(earliestTime);
|
|
519
|
+
return earliestTime - now;
|
|
520
|
+
}
|
|
521
|
+
const getDelay = strict ? strictDelay : windowedDelay;
|
|
522
|
+
return (function_) => {
|
|
523
|
+
const throttled = function(...args) {
|
|
524
|
+
if (!throttled.isEnabled) {
|
|
525
|
+
return (async () => function_.apply(this, args))();
|
|
526
|
+
}
|
|
527
|
+
let timeout;
|
|
528
|
+
return new Promise((resolve, reject) => {
|
|
529
|
+
const execute = () => {
|
|
530
|
+
resolve(function_.apply(this, args));
|
|
531
|
+
queue.delete(timeout);
|
|
532
|
+
};
|
|
533
|
+
timeout = setTimeout(execute, getDelay());
|
|
534
|
+
queue.set(timeout, reject);
|
|
535
|
+
});
|
|
536
|
+
};
|
|
537
|
+
throttled.abort = () => {
|
|
538
|
+
for (const timeout of queue.keys()) {
|
|
539
|
+
clearTimeout(timeout);
|
|
540
|
+
queue.get(timeout)(new AbortError2());
|
|
541
|
+
}
|
|
542
|
+
queue.clear();
|
|
543
|
+
strictTicks.splice(0, strictTicks.length);
|
|
544
|
+
};
|
|
545
|
+
throttled.isEnabled = true;
|
|
546
|
+
return throttled;
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// src/enhancement/createLimitPolicy.ts
|
|
16
551
|
function createLimitPolicy({
|
|
17
552
|
throttle = { interval: 1e3, limit: 10 },
|
|
18
|
-
retry = { retries: 1, factor: 1.66 },
|
|
553
|
+
retry: retry2 = { retries: 1, factor: 1.66 },
|
|
19
554
|
limit = 10
|
|
20
555
|
}) {
|
|
21
556
|
const throttler = throttle ? pThrottle(throttle) : null;
|
|
22
|
-
const limiter = limit ?
|
|
557
|
+
const limiter = limit ? (0, import_p_limit.default)(limit) : null;
|
|
23
558
|
return function limitPolicy(func) {
|
|
24
559
|
let currentFunc = async () => await func();
|
|
25
560
|
if (throttler) {
|
|
@@ -30,13 +565,13 @@ function createLimitPolicy({
|
|
|
30
565
|
const limitFunc = currentFunc;
|
|
31
566
|
currentFunc = () => limiter(limitFunc);
|
|
32
567
|
}
|
|
33
|
-
if (
|
|
568
|
+
if (retry2) {
|
|
34
569
|
const retryFunc = currentFunc;
|
|
35
570
|
currentFunc = () => pRetry(retryFunc, {
|
|
36
|
-
...
|
|
571
|
+
...retry2,
|
|
37
572
|
onFailedAttempt: async (error) => {
|
|
38
|
-
if (
|
|
39
|
-
await
|
|
573
|
+
if (retry2.onFailedAttempt) {
|
|
574
|
+
await retry2.onFailedAttempt(error);
|
|
40
575
|
}
|
|
41
576
|
if (error instanceof ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
|
|
42
577
|
throw error;
|