@uniformdev/canvas 20.69.0 → 20.69.1-alpha.10

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, {
@@ -567,176 +215,15 @@ var import_api2 = require("@uniformdev/context/api");
567
215
 
568
216
  // src/enhancement/createLimitPolicy.ts
569
217
  var import_api = require("@uniformdev/context/api");
570
- var import_p_limit = __toESM(require_p_limit());
571
-
572
- // ../../node_modules/.pnpm/p-retry@5.1.2/node_modules/p-retry/index.js
573
- var import_retry = __toESM(require_retry2(), 1);
574
- var networkErrorMsgs = /* @__PURE__ */ new Set([
575
- "Failed to fetch",
576
- // Chrome
577
- "NetworkError when attempting to fetch resource.",
578
- // Firefox
579
- "The Internet connection appears to be offline.",
580
- // Safari
581
- "Network request failed",
582
- // `cross-fetch`
583
- "fetch failed"
584
- // Undici (Node.js)
585
- ]);
586
- var AbortError = class extends Error {
587
- constructor(message) {
588
- super();
589
- if (message instanceof Error) {
590
- this.originalError = message;
591
- ({ message } = message);
592
- } else {
593
- this.originalError = new Error(message);
594
- this.originalError.stack = this.stack;
595
- }
596
- this.name = "AbortError";
597
- this.message = message;
598
- }
599
- };
600
- var decorateErrorWithCounts = (error, attemptNumber, options) => {
601
- const retriesLeft = options.retries - (attemptNumber - 1);
602
- error.attemptNumber = attemptNumber;
603
- error.retriesLeft = retriesLeft;
604
- return error;
605
- };
606
- var isNetworkError = (errorMessage) => networkErrorMsgs.has(errorMessage);
607
- var getDOMException = (errorMessage) => globalThis.DOMException === void 0 ? new Error(errorMessage) : new DOMException(errorMessage);
608
- async function pRetry(input, options) {
609
- return new Promise((resolve, reject) => {
610
- options = {
611
- onFailedAttempt() {
612
- },
613
- retries: 10,
614
- ...options
615
- };
616
- const operation = import_retry.default.operation(options);
617
- operation.attempt(async (attemptNumber) => {
618
- try {
619
- resolve(await input(attemptNumber));
620
- } catch (error) {
621
- if (!(error instanceof Error)) {
622
- reject(new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`));
623
- return;
624
- }
625
- if (error instanceof AbortError) {
626
- operation.stop();
627
- reject(error.originalError);
628
- } else if (error instanceof TypeError && !isNetworkError(error.message)) {
629
- operation.stop();
630
- reject(error);
631
- } else {
632
- decorateErrorWithCounts(error, attemptNumber, options);
633
- try {
634
- await options.onFailedAttempt(error);
635
- } catch (error2) {
636
- reject(error2);
637
- return;
638
- }
639
- if (!operation.retry(error)) {
640
- reject(operation.mainError());
641
- }
642
- }
643
- }
644
- });
645
- if (options.signal && !options.signal.aborted) {
646
- options.signal.addEventListener("abort", () => {
647
- operation.stop();
648
- const reason = options.signal.reason === void 0 ? getDOMException("The operation was aborted.") : options.signal.reason;
649
- reject(reason instanceof Error ? reason : getDOMException(reason));
650
- }, {
651
- once: true
652
- });
653
- }
654
- });
655
- }
656
-
657
- // ../../node_modules/.pnpm/p-throttle@5.0.0/node_modules/p-throttle/index.js
658
- var AbortError2 = class extends Error {
659
- constructor() {
660
- super("Throttled function aborted");
661
- this.name = "AbortError";
662
- }
663
- };
664
- function pThrottle({ limit, interval, strict }) {
665
- if (!Number.isFinite(limit)) {
666
- throw new TypeError("Expected `limit` to be a finite number");
667
- }
668
- if (!Number.isFinite(interval)) {
669
- throw new TypeError("Expected `interval` to be a finite number");
670
- }
671
- const queue = /* @__PURE__ */ new Map();
672
- let currentTick = 0;
673
- let activeCount = 0;
674
- function windowedDelay() {
675
- const now = Date.now();
676
- if (now - currentTick > interval) {
677
- activeCount = 1;
678
- currentTick = now;
679
- return 0;
680
- }
681
- if (activeCount < limit) {
682
- activeCount++;
683
- } else {
684
- currentTick += interval;
685
- activeCount = 1;
686
- }
687
- return currentTick - now;
688
- }
689
- const strictTicks = [];
690
- function strictDelay() {
691
- const now = Date.now();
692
- if (strictTicks.length < limit) {
693
- strictTicks.push(now);
694
- return 0;
695
- }
696
- const earliestTime = strictTicks.shift() + interval;
697
- if (now >= earliestTime) {
698
- strictTicks.push(now);
699
- return 0;
700
- }
701
- strictTicks.push(earliestTime);
702
- return earliestTime - now;
703
- }
704
- const getDelay = strict ? strictDelay : windowedDelay;
705
- return (function_) => {
706
- const throttled = function(...args) {
707
- if (!throttled.isEnabled) {
708
- return (async () => function_.apply(this, args))();
709
- }
710
- let timeout;
711
- return new Promise((resolve, reject) => {
712
- const execute = () => {
713
- resolve(function_.apply(this, args));
714
- queue.delete(timeout);
715
- };
716
- timeout = setTimeout(execute, getDelay());
717
- queue.set(timeout, reject);
718
- });
719
- };
720
- throttled.abort = () => {
721
- for (const timeout of queue.keys()) {
722
- clearTimeout(timeout);
723
- queue.get(timeout)(new AbortError2());
724
- }
725
- queue.clear();
726
- strictTicks.splice(0, strictTicks.length);
727
- };
728
- throttled.isEnabled = true;
729
- return throttled;
730
- };
731
- }
732
-
733
- // src/enhancement/createLimitPolicy.ts
218
+ var import_p_limit = __toESM(require("p-limit"));
219
+ var import_p_retry = __toESM(require("p-retry"));
220
+ var import_p_throttle = __toESM(require("p-throttle"));
734
221
  function createLimitPolicy({
735
222
  throttle = { interval: 1e3, limit: 10 },
736
- retry: retry2 = { retries: 1, factor: 1.66 },
223
+ retry = { retries: 1, factor: 1.66 },
737
224
  limit = 10
738
225
  }) {
739
- const throttler = throttle ? pThrottle(throttle) : null;
226
+ const throttler = throttle ? (0, import_p_throttle.default)(throttle) : null;
740
227
  const limiter = limit ? (0, import_p_limit.default)(limit) : null;
741
228
  return function limitPolicy(func) {
742
229
  let currentFunc = async () => await func();
@@ -748,13 +235,13 @@ function createLimitPolicy({
748
235
  const limitFunc = currentFunc;
749
236
  currentFunc = () => limiter(limitFunc);
750
237
  }
751
- if (retry2) {
238
+ if (retry) {
752
239
  const retryFunc = currentFunc;
753
- currentFunc = () => pRetry(retryFunc, {
754
- ...retry2,
240
+ currentFunc = () => (0, import_p_retry.default)(retryFunc, {
241
+ ...retry,
755
242
  onFailedAttempt: async (error) => {
756
- if (retry2.onFailedAttempt) {
757
- await retry2.onFailedAttempt(error);
243
+ if (retry.onFailedAttempt) {
244
+ await retry.onFailedAttempt(error);
758
245
  }
759
246
  if (error instanceof import_api.ApiClientError && typeof error.statusCode === "number" && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429 && error.statusCode !== 408) {
760
247
  throw error;