@uniformdev/canvas 20.61.1 → 20.61.2-alpha.4

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.js CHANGED
@@ -8,9 +8,6 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __typeError = (msg) => {
9
9
  throw TypeError(msg);
10
10
  };
11
- var __commonJS = (cb, mod) => function __require() {
12
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
- };
14
11
  var __export = (target, all) => {
15
12
  for (var name in all)
16
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -36,355 +33,6 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
36
33
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
37
34
  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);
38
35
 
39
- // ../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js
40
- var require_yocto_queue = __commonJS({
41
- "../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports2, module2) {
42
- "use strict";
43
- var Node = class {
44
- /// value;
45
- /// next;
46
- constructor(value) {
47
- this.value = value;
48
- this.next = void 0;
49
- }
50
- };
51
- var Queue = class {
52
- // TODO: Use private class fields when targeting Node.js 12.
53
- // #_head;
54
- // #_tail;
55
- // #_size;
56
- constructor() {
57
- this.clear();
58
- }
59
- enqueue(value) {
60
- const node = new Node(value);
61
- if (this._head) {
62
- this._tail.next = node;
63
- this._tail = node;
64
- } else {
65
- this._head = node;
66
- this._tail = node;
67
- }
68
- this._size++;
69
- }
70
- dequeue() {
71
- const current = this._head;
72
- if (!current) {
73
- return;
74
- }
75
- this._head = this._head.next;
76
- this._size--;
77
- return current.value;
78
- }
79
- clear() {
80
- this._head = void 0;
81
- this._tail = void 0;
82
- this._size = 0;
83
- }
84
- get size() {
85
- return this._size;
86
- }
87
- *[Symbol.iterator]() {
88
- let current = this._head;
89
- while (current) {
90
- yield current.value;
91
- current = current.next;
92
- }
93
- }
94
- };
95
- module2.exports = Queue;
96
- }
97
- });
98
-
99
- // ../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js
100
- var require_p_limit = __commonJS({
101
- "../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports2, module2) {
102
- "use strict";
103
- var Queue = require_yocto_queue();
104
- var pLimit2 = (concurrency) => {
105
- if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
106
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
107
- }
108
- const queue = new Queue();
109
- let activeCount = 0;
110
- const next = () => {
111
- activeCount--;
112
- if (queue.size > 0) {
113
- queue.dequeue()();
114
- }
115
- };
116
- const run = async (fn, resolve, ...args) => {
117
- activeCount++;
118
- const result = (async () => fn(...args))();
119
- resolve(result);
120
- try {
121
- await result;
122
- } catch (e) {
123
- }
124
- next();
125
- };
126
- const enqueue = (fn, resolve, ...args) => {
127
- queue.enqueue(run.bind(null, fn, resolve, ...args));
128
- (async () => {
129
- await Promise.resolve();
130
- if (activeCount < concurrency && queue.size > 0) {
131
- queue.dequeue()();
132
- }
133
- })();
134
- };
135
- const generator = (fn, ...args) => new Promise((resolve) => {
136
- enqueue(fn, resolve, ...args);
137
- });
138
- Object.defineProperties(generator, {
139
- activeCount: {
140
- get: () => activeCount
141
- },
142
- pendingCount: {
143
- get: () => queue.size
144
- },
145
- clearQueue: {
146
- value: () => {
147
- queue.clear();
148
- }
149
- }
150
- });
151
- return generator;
152
- };
153
- module2.exports = pLimit2;
154
- }
155
- });
156
-
157
- // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js
158
- var require_retry_operation = __commonJS({
159
- "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports2, module2) {
160
- "use strict";
161
- function RetryOperation(timeouts, options) {
162
- if (typeof options === "boolean") {
163
- options = { forever: options };
164
- }
165
- this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
166
- this._timeouts = timeouts;
167
- this._options = options || {};
168
- this._maxRetryTime = options && options.maxRetryTime || Infinity;
169
- this._fn = null;
170
- this._errors = [];
171
- this._attempts = 1;
172
- this._operationTimeout = null;
173
- this._operationTimeoutCb = null;
174
- this._timeout = null;
175
- this._operationStart = null;
176
- this._timer = null;
177
- if (this._options.forever) {
178
- this._cachedTimeouts = this._timeouts.slice(0);
179
- }
180
- }
181
- module2.exports = RetryOperation;
182
- RetryOperation.prototype.reset = function() {
183
- this._attempts = 1;
184
- this._timeouts = this._originalTimeouts.slice(0);
185
- };
186
- RetryOperation.prototype.stop = function() {
187
- if (this._timeout) {
188
- clearTimeout(this._timeout);
189
- }
190
- if (this._timer) {
191
- clearTimeout(this._timer);
192
- }
193
- this._timeouts = [];
194
- this._cachedTimeouts = null;
195
- };
196
- RetryOperation.prototype.retry = function(err) {
197
- if (this._timeout) {
198
- clearTimeout(this._timeout);
199
- }
200
- if (!err) {
201
- return false;
202
- }
203
- var currentTime = (/* @__PURE__ */ new Date()).getTime();
204
- if (err && currentTime - this._operationStart >= this._maxRetryTime) {
205
- this._errors.push(err);
206
- this._errors.unshift(new Error("RetryOperation timeout occurred"));
207
- return false;
208
- }
209
- this._errors.push(err);
210
- var timeout = this._timeouts.shift();
211
- if (timeout === void 0) {
212
- if (this._cachedTimeouts) {
213
- this._errors.splice(0, this._errors.length - 1);
214
- timeout = this._cachedTimeouts.slice(-1);
215
- } else {
216
- return false;
217
- }
218
- }
219
- var self = this;
220
- this._timer = setTimeout(function() {
221
- self._attempts++;
222
- if (self._operationTimeoutCb) {
223
- self._timeout = setTimeout(function() {
224
- self._operationTimeoutCb(self._attempts);
225
- }, self._operationTimeout);
226
- if (self._options.unref) {
227
- self._timeout.unref();
228
- }
229
- }
230
- self._fn(self._attempts);
231
- }, timeout);
232
- if (this._options.unref) {
233
- this._timer.unref();
234
- }
235
- return true;
236
- };
237
- RetryOperation.prototype.attempt = function(fn, timeoutOps) {
238
- this._fn = fn;
239
- if (timeoutOps) {
240
- if (timeoutOps.timeout) {
241
- this._operationTimeout = timeoutOps.timeout;
242
- }
243
- if (timeoutOps.cb) {
244
- this._operationTimeoutCb = timeoutOps.cb;
245
- }
246
- }
247
- var self = this;
248
- if (this._operationTimeoutCb) {
249
- this._timeout = setTimeout(function() {
250
- self._operationTimeoutCb();
251
- }, self._operationTimeout);
252
- }
253
- this._operationStart = (/* @__PURE__ */ new Date()).getTime();
254
- this._fn(this._attempts);
255
- };
256
- RetryOperation.prototype.try = function(fn) {
257
- console.log("Using RetryOperation.try() is deprecated");
258
- this.attempt(fn);
259
- };
260
- RetryOperation.prototype.start = function(fn) {
261
- console.log("Using RetryOperation.start() is deprecated");
262
- this.attempt(fn);
263
- };
264
- RetryOperation.prototype.start = RetryOperation.prototype.try;
265
- RetryOperation.prototype.errors = function() {
266
- return this._errors;
267
- };
268
- RetryOperation.prototype.attempts = function() {
269
- return this._attempts;
270
- };
271
- RetryOperation.prototype.mainError = function() {
272
- if (this._errors.length === 0) {
273
- return null;
274
- }
275
- var counts = {};
276
- var mainError = null;
277
- var mainErrorCount = 0;
278
- for (var i = 0; i < this._errors.length; i++) {
279
- var error = this._errors[i];
280
- var message = error.message;
281
- var count = (counts[message] || 0) + 1;
282
- counts[message] = count;
283
- if (count >= mainErrorCount) {
284
- mainError = error;
285
- mainErrorCount = count;
286
- }
287
- }
288
- return mainError;
289
- };
290
- }
291
- });
292
-
293
- // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js
294
- var require_retry = __commonJS({
295
- "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js"(exports2) {
296
- "use strict";
297
- var RetryOperation = require_retry_operation();
298
- exports2.operation = function(options) {
299
- var timeouts = exports2.timeouts(options);
300
- return new RetryOperation(timeouts, {
301
- forever: options && (options.forever || options.retries === Infinity),
302
- unref: options && options.unref,
303
- maxRetryTime: options && options.maxRetryTime
304
- });
305
- };
306
- exports2.timeouts = function(options) {
307
- if (options instanceof Array) {
308
- return [].concat(options);
309
- }
310
- var opts = {
311
- retries: 10,
312
- factor: 2,
313
- minTimeout: 1 * 1e3,
314
- maxTimeout: Infinity,
315
- randomize: false
316
- };
317
- for (var key in options) {
318
- opts[key] = options[key];
319
- }
320
- if (opts.minTimeout > opts.maxTimeout) {
321
- throw new Error("minTimeout is greater than maxTimeout");
322
- }
323
- var timeouts = [];
324
- for (var i = 0; i < opts.retries; i++) {
325
- timeouts.push(this.createTimeout(i, opts));
326
- }
327
- if (options && options.forever && !timeouts.length) {
328
- timeouts.push(this.createTimeout(i, opts));
329
- }
330
- timeouts.sort(function(a, b) {
331
- return a - b;
332
- });
333
- return timeouts;
334
- };
335
- exports2.createTimeout = function(attempt, opts) {
336
- var random = opts.randomize ? Math.random() + 1 : 1;
337
- var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
338
- timeout = Math.min(timeout, opts.maxTimeout);
339
- return timeout;
340
- };
341
- exports2.wrap = function(obj, options, methods) {
342
- if (options instanceof Array) {
343
- methods = options;
344
- options = null;
345
- }
346
- if (!methods) {
347
- methods = [];
348
- for (var key in obj) {
349
- if (typeof obj[key] === "function") {
350
- methods.push(key);
351
- }
352
- }
353
- }
354
- for (var i = 0; i < methods.length; i++) {
355
- var method = methods[i];
356
- var original = obj[method];
357
- obj[method] = function retryWrapper(original2) {
358
- var op = exports2.operation(options);
359
- var args = Array.prototype.slice.call(arguments, 1);
360
- var callback = args.pop();
361
- args.push(function(err) {
362
- if (op.retry(err)) {
363
- return;
364
- }
365
- if (err) {
366
- arguments[0] = op.mainError();
367
- }
368
- callback.apply(this, arguments);
369
- });
370
- op.attempt(function() {
371
- original2.apply(obj, args);
372
- });
373
- }.bind(obj, original);
374
- obj[method].options = options;
375
- }
376
- };
377
- }
378
- });
379
-
380
- // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js
381
- var require_retry2 = __commonJS({
382
- "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js"(exports2, module2) {
383
- "use strict";
384
- module2.exports = require_retry();
385
- }
386
- });
387
-
388
36
  // src/index.ts
389
37
  var src_exports = {};
390
38
  __export(src_exports, {
@@ -566,176 +214,15 @@ var import_api2 = require("@uniformdev/context/api");
566
214
 
567
215
  // src/enhancement/createLimitPolicy.ts
568
216
  var import_api = require("@uniformdev/context/api");
569
- var import_p_limit = __toESM(require_p_limit());
570
-
571
- // ../../node_modules/.pnpm/p-retry@5.1.2/node_modules/p-retry/index.js
572
- var import_retry = __toESM(require_retry2(), 1);
573
- var networkErrorMsgs = /* @__PURE__ */ new Set([
574
- "Failed to fetch",
575
- // Chrome
576
- "NetworkError when attempting to fetch resource.",
577
- // Firefox
578
- "The Internet connection appears to be offline.",
579
- // Safari
580
- "Network request failed",
581
- // `cross-fetch`
582
- "fetch failed"
583
- // Undici (Node.js)
584
- ]);
585
- var AbortError = class extends Error {
586
- constructor(message) {
587
- super();
588
- if (message instanceof Error) {
589
- this.originalError = message;
590
- ({ message } = message);
591
- } else {
592
- this.originalError = new Error(message);
593
- this.originalError.stack = this.stack;
594
- }
595
- this.name = "AbortError";
596
- this.message = message;
597
- }
598
- };
599
- var decorateErrorWithCounts = (error, attemptNumber, options) => {
600
- const retriesLeft = options.retries - (attemptNumber - 1);
601
- error.attemptNumber = attemptNumber;
602
- error.retriesLeft = retriesLeft;
603
- return error;
604
- };
605
- var isNetworkError = (errorMessage) => networkErrorMsgs.has(errorMessage);
606
- var getDOMException = (errorMessage) => globalThis.DOMException === void 0 ? new Error(errorMessage) : new DOMException(errorMessage);
607
- async function pRetry(input, options) {
608
- return new Promise((resolve, reject) => {
609
- options = {
610
- onFailedAttempt() {
611
- },
612
- retries: 10,
613
- ...options
614
- };
615
- const operation = import_retry.default.operation(options);
616
- operation.attempt(async (attemptNumber) => {
617
- try {
618
- resolve(await input(attemptNumber));
619
- } catch (error) {
620
- if (!(error instanceof Error)) {
621
- reject(new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`));
622
- return;
623
- }
624
- if (error instanceof AbortError) {
625
- operation.stop();
626
- reject(error.originalError);
627
- } else if (error instanceof TypeError && !isNetworkError(error.message)) {
628
- operation.stop();
629
- reject(error);
630
- } else {
631
- decorateErrorWithCounts(error, attemptNumber, options);
632
- try {
633
- await options.onFailedAttempt(error);
634
- } catch (error2) {
635
- reject(error2);
636
- return;
637
- }
638
- if (!operation.retry(error)) {
639
- reject(operation.mainError());
640
- }
641
- }
642
- }
643
- });
644
- if (options.signal && !options.signal.aborted) {
645
- options.signal.addEventListener("abort", () => {
646
- operation.stop();
647
- const reason = options.signal.reason === void 0 ? getDOMException("The operation was aborted.") : options.signal.reason;
648
- reject(reason instanceof Error ? reason : getDOMException(reason));
649
- }, {
650
- once: true
651
- });
652
- }
653
- });
654
- }
655
-
656
- // ../../node_modules/.pnpm/p-throttle@5.0.0/node_modules/p-throttle/index.js
657
- var AbortError2 = class extends Error {
658
- constructor() {
659
- super("Throttled function aborted");
660
- this.name = "AbortError";
661
- }
662
- };
663
- function pThrottle({ limit, interval, strict }) {
664
- if (!Number.isFinite(limit)) {
665
- throw new TypeError("Expected `limit` to be a finite number");
666
- }
667
- if (!Number.isFinite(interval)) {
668
- throw new TypeError("Expected `interval` to be a finite number");
669
- }
670
- const queue = /* @__PURE__ */ new Map();
671
- let currentTick = 0;
672
- let activeCount = 0;
673
- function windowedDelay() {
674
- const now = Date.now();
675
- if (now - currentTick > interval) {
676
- activeCount = 1;
677
- currentTick = now;
678
- return 0;
679
- }
680
- if (activeCount < limit) {
681
- activeCount++;
682
- } else {
683
- currentTick += interval;
684
- activeCount = 1;
685
- }
686
- return currentTick - now;
687
- }
688
- const strictTicks = [];
689
- function strictDelay() {
690
- const now = Date.now();
691
- if (strictTicks.length < limit) {
692
- strictTicks.push(now);
693
- return 0;
694
- }
695
- const earliestTime = strictTicks.shift() + interval;
696
- if (now >= earliestTime) {
697
- strictTicks.push(now);
698
- return 0;
699
- }
700
- strictTicks.push(earliestTime);
701
- return earliestTime - now;
702
- }
703
- const getDelay = strict ? strictDelay : windowedDelay;
704
- return (function_) => {
705
- const throttled = function(...args) {
706
- if (!throttled.isEnabled) {
707
- return (async () => function_.apply(this, args))();
708
- }
709
- let timeout;
710
- return new Promise((resolve, reject) => {
711
- const execute = () => {
712
- resolve(function_.apply(this, args));
713
- queue.delete(timeout);
714
- };
715
- timeout = setTimeout(execute, getDelay());
716
- queue.set(timeout, reject);
717
- });
718
- };
719
- throttled.abort = () => {
720
- for (const timeout of queue.keys()) {
721
- clearTimeout(timeout);
722
- queue.get(timeout)(new AbortError2());
723
- }
724
- queue.clear();
725
- strictTicks.splice(0, strictTicks.length);
726
- };
727
- throttled.isEnabled = true;
728
- return throttled;
729
- };
730
- }
731
-
732
- // src/enhancement/createLimitPolicy.ts
217
+ var import_p_limit = __toESM(require("p-limit"));
218
+ var import_p_retry = __toESM(require("p-retry"));
219
+ var import_p_throttle = __toESM(require("p-throttle"));
733
220
  function createLimitPolicy({
734
221
  throttle = { interval: 1e3, limit: 10 },
735
- retry: retry2 = { retries: 1, factor: 1.66 },
222
+ retry = { retries: 1, factor: 1.66 },
736
223
  limit = 10
737
224
  }) {
738
- const throttler = throttle ? pThrottle(throttle) : null;
225
+ const throttler = throttle ? (0, import_p_throttle.default)(throttle) : null;
739
226
  const limiter = limit ? (0, import_p_limit.default)(limit) : null;
740
227
  return function limitPolicy(func) {
741
228
  let currentFunc = async () => await func();
@@ -747,13 +234,13 @@ function createLimitPolicy({
747
234
  const limitFunc = currentFunc;
748
235
  currentFunc = () => limiter(limitFunc);
749
236
  }
750
- if (retry2) {
237
+ if (retry) {
751
238
  const retryFunc = currentFunc;
752
- currentFunc = () => pRetry(retryFunc, {
753
- ...retry2,
239
+ currentFunc = () => (0, import_p_retry.default)(retryFunc, {
240
+ ...retry,
754
241
  onFailedAttempt: async (error) => {
755
- if (retry2.onFailedAttempt) {
756
- await retry2.onFailedAttempt(error);
242
+ if (retry.onFailedAttempt) {
243
+ await retry.onFailedAttempt(error);
757
244
  }
758
245
  if (error instanceof import_api.ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
759
246
  throw error;