@microlink/mql 0.11.0-0 → 0.11.0-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/dist/mql.js +528 -543
- package/dist/mql.min.js +3 -2
- package/dist/mql.min.js.map +1 -0
- package/package.json +4 -3
- package/src/lightweight.js +2 -2
- package/src/lightweight.mjs +4 -4
- package/src/lightweight.tpl.js +55 -0
- package/src/node.mjs +1 -1
package/dist/mql.js
CHANGED
|
@@ -4,35 +4,12 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.mql = factory());
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
8
|
+
|
|
7
9
|
function getDefaultExportFromCjs (x) {
|
|
8
10
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
function getAugmentedNamespace(n) {
|
|
12
|
-
if (n.__esModule) return n;
|
|
13
|
-
var f = n.default;
|
|
14
|
-
if (typeof f == "function") {
|
|
15
|
-
var a = function a () {
|
|
16
|
-
if (this instanceof a) {
|
|
17
|
-
return Reflect.construct(f, arguments, this.constructor);
|
|
18
|
-
}
|
|
19
|
-
return f.apply(this, arguments);
|
|
20
|
-
};
|
|
21
|
-
a.prototype = f.prototype;
|
|
22
|
-
} else a = {};
|
|
23
|
-
Object.defineProperty(a, '__esModule', {value: true});
|
|
24
|
-
Object.keys(n).forEach(function (k) {
|
|
25
|
-
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
26
|
-
Object.defineProperty(a, k, d.get ? d : {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
get: function () {
|
|
29
|
-
return n[k];
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
return a;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
13
|
const REGEX_HTTP_PROTOCOL = /^https?:\/\//i;
|
|
37
14
|
|
|
38
15
|
var lightweight$2 = url => {
|
|
@@ -79,7 +56,7 @@
|
|
|
79
56
|
PRO: 'https://pro.microlink.io/'
|
|
80
57
|
};
|
|
81
58
|
|
|
82
|
-
const isObject
|
|
59
|
+
const isObject = input => input !== null && typeof input === 'object';
|
|
83
60
|
|
|
84
61
|
const isBuffer = input =>
|
|
85
62
|
input != null &&
|
|
@@ -120,7 +97,7 @@
|
|
|
120
97
|
};
|
|
121
98
|
|
|
122
99
|
const mapRules = rules => {
|
|
123
|
-
if (!isObject
|
|
100
|
+
if (!isObject(rules)) return
|
|
124
101
|
const flatRules = flatten(rules);
|
|
125
102
|
return Object.keys(flatRules).reduce((acc, key) => {
|
|
126
103
|
acc[`data.${key}`] = flatRules[key].toString();
|
|
@@ -145,7 +122,7 @@
|
|
|
145
122
|
const isBodyBuffer = isBuffer(rawBody);
|
|
146
123
|
|
|
147
124
|
const body =
|
|
148
|
-
isObject
|
|
125
|
+
isObject(rawBody) && !isBodyBuffer
|
|
149
126
|
? rawBody
|
|
150
127
|
: parseBody(isBodyBuffer ? rawBody.toString() : rawBody, err, uri);
|
|
151
128
|
|
|
@@ -202,525 +179,533 @@
|
|
|
202
179
|
|
|
203
180
|
var factory_1 = factory$1;
|
|
204
181
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
182
|
+
var ky$1 = {exports: {}};
|
|
183
|
+
|
|
184
|
+
(function (module, exports) {
|
|
185
|
+
(function (global, factory) {
|
|
186
|
+
factory(exports) ;
|
|
187
|
+
})(commonjsGlobal, (function (exports) {
|
|
188
|
+
// eslint-lint-disable-next-line @typescript-eslint/naming-convention
|
|
189
|
+
class HTTPError extends Error {
|
|
190
|
+
constructor(response, request, options) {
|
|
191
|
+
const code = (response.status || response.status === 0) ? response.status : '';
|
|
192
|
+
const title = response.statusText || '';
|
|
193
|
+
const status = `${code} ${title}`.trim();
|
|
194
|
+
const reason = status ? `status code ${status}` : 'an unknown error';
|
|
195
|
+
super(`Request failed with ${reason}`);
|
|
196
|
+
Object.defineProperty(this, "response", {
|
|
197
|
+
enumerable: true,
|
|
198
|
+
configurable: true,
|
|
199
|
+
writable: true,
|
|
200
|
+
value: void 0
|
|
201
|
+
});
|
|
202
|
+
Object.defineProperty(this, "request", {
|
|
203
|
+
enumerable: true,
|
|
204
|
+
configurable: true,
|
|
205
|
+
writable: true,
|
|
206
|
+
value: void 0
|
|
207
|
+
});
|
|
208
|
+
Object.defineProperty(this, "options", {
|
|
209
|
+
enumerable: true,
|
|
210
|
+
configurable: true,
|
|
211
|
+
writable: true,
|
|
212
|
+
value: void 0
|
|
213
|
+
});
|
|
214
|
+
this.name = 'HTTPError';
|
|
215
|
+
this.response = response;
|
|
216
|
+
this.request = request;
|
|
217
|
+
this.options = options;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
class TimeoutError extends Error {
|
|
222
|
+
constructor(request) {
|
|
223
|
+
super('Request timed out');
|
|
224
|
+
Object.defineProperty(this, "request", {
|
|
225
|
+
enumerable: true,
|
|
226
|
+
configurable: true,
|
|
227
|
+
writable: true,
|
|
228
|
+
value: void 0
|
|
229
|
+
});
|
|
230
|
+
this.name = 'TimeoutError';
|
|
231
|
+
this.request = request;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
236
|
+
const isObject = (value) => value !== null && typeof value === 'object';
|
|
237
|
+
|
|
238
|
+
const validateAndMerge = (...sources) => {
|
|
239
|
+
for (const source of sources) {
|
|
240
|
+
if ((!isObject(source) || Array.isArray(source)) && source !== undefined) {
|
|
241
|
+
throw new TypeError('The `options` argument must be an object');
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return deepMerge({}, ...sources);
|
|
245
|
+
};
|
|
246
|
+
const mergeHeaders = (source1 = {}, source2 = {}) => {
|
|
247
|
+
const result = new globalThis.Headers(source1);
|
|
248
|
+
const isHeadersInstance = source2 instanceof globalThis.Headers;
|
|
249
|
+
const source = new globalThis.Headers(source2);
|
|
250
|
+
for (const [key, value] of source.entries()) {
|
|
251
|
+
if ((isHeadersInstance && value === 'undefined') || value === undefined) {
|
|
252
|
+
result.delete(key);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
result.set(key, value);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return result;
|
|
259
|
+
};
|
|
260
|
+
// TODO: Make this strongly-typed (no `any`).
|
|
261
|
+
const deepMerge = (...sources) => {
|
|
262
|
+
let returnValue = {};
|
|
263
|
+
let headers = {};
|
|
264
|
+
for (const source of sources) {
|
|
265
|
+
if (Array.isArray(source)) {
|
|
266
|
+
if (!Array.isArray(returnValue)) {
|
|
267
|
+
returnValue = [];
|
|
268
|
+
}
|
|
269
|
+
returnValue = [...returnValue, ...source];
|
|
270
|
+
}
|
|
271
|
+
else if (isObject(source)) {
|
|
272
|
+
for (let [key, value] of Object.entries(source)) {
|
|
273
|
+
if (isObject(value) && key in returnValue) {
|
|
274
|
+
value = deepMerge(returnValue[key], value);
|
|
275
|
+
}
|
|
276
|
+
returnValue = { ...returnValue, [key]: value };
|
|
277
|
+
}
|
|
278
|
+
if (isObject(source.headers)) {
|
|
279
|
+
headers = mergeHeaders(headers, source.headers);
|
|
280
|
+
returnValue.headers = headers;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return returnValue;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const supportsRequestStreams = (() => {
|
|
288
|
+
let duplexAccessed = false;
|
|
289
|
+
let hasContentType = false;
|
|
290
|
+
const supportsReadableStream = typeof globalThis.ReadableStream === 'function';
|
|
291
|
+
const supportsRequest = typeof globalThis.Request === 'function';
|
|
292
|
+
if (supportsReadableStream && supportsRequest) {
|
|
293
|
+
hasContentType = new globalThis.Request('https://empty.invalid', {
|
|
294
|
+
body: new globalThis.ReadableStream(),
|
|
295
|
+
method: 'POST',
|
|
296
|
+
// @ts-expect-error - Types are outdated.
|
|
297
|
+
get duplex() {
|
|
298
|
+
duplexAccessed = true;
|
|
299
|
+
return 'half';
|
|
300
|
+
},
|
|
301
|
+
}).headers.has('Content-Type');
|
|
302
|
+
}
|
|
303
|
+
return duplexAccessed && !hasContentType;
|
|
304
|
+
})();
|
|
305
|
+
const supportsAbortController = typeof globalThis.AbortController === 'function';
|
|
306
|
+
const supportsResponseStreams = typeof globalThis.ReadableStream === 'function';
|
|
307
|
+
const supportsFormData = typeof globalThis.FormData === 'function';
|
|
308
|
+
const requestMethods = ['get', 'post', 'put', 'patch', 'head', 'delete'];
|
|
309
|
+
const responseTypes = {
|
|
310
|
+
json: 'application/json',
|
|
311
|
+
text: 'text/*',
|
|
312
|
+
formData: 'multipart/form-data',
|
|
313
|
+
arrayBuffer: '*/*',
|
|
314
|
+
blob: '*/*',
|
|
315
|
+
};
|
|
316
|
+
// The maximum value of a 32bit int (see issue #117)
|
|
317
|
+
const maxSafeTimeout = 2147483647;
|
|
318
|
+
const stop = Symbol('stop');
|
|
319
|
+
|
|
320
|
+
const normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;
|
|
321
|
+
const retryMethods = ['get', 'put', 'head', 'delete', 'options', 'trace'];
|
|
322
|
+
const retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
|
|
323
|
+
const retryAfterStatusCodes = [413, 429, 503];
|
|
324
|
+
const defaultRetryOptions = {
|
|
325
|
+
limit: 2,
|
|
326
|
+
methods: retryMethods,
|
|
327
|
+
statusCodes: retryStatusCodes,
|
|
328
|
+
afterStatusCodes: retryAfterStatusCodes,
|
|
329
|
+
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
330
|
+
backoffLimit: Number.POSITIVE_INFINITY,
|
|
331
|
+
};
|
|
332
|
+
const normalizeRetryOptions = (retry = {}) => {
|
|
333
|
+
if (typeof retry === 'number') {
|
|
334
|
+
return {
|
|
335
|
+
...defaultRetryOptions,
|
|
336
|
+
limit: retry,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
if (retry.methods && !Array.isArray(retry.methods)) {
|
|
340
|
+
throw new Error('retry.methods must be an array');
|
|
341
|
+
}
|
|
342
|
+
if (retry.statusCodes && !Array.isArray(retry.statusCodes)) {
|
|
343
|
+
throw new Error('retry.statusCodes must be an array');
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
...defaultRetryOptions,
|
|
347
|
+
...retry,
|
|
348
|
+
afterStatusCodes: retryAfterStatusCodes,
|
|
349
|
+
};
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
// `Promise.race()` workaround (#91)
|
|
353
|
+
async function timeout(request, abortController, options) {
|
|
354
|
+
return new Promise((resolve, reject) => {
|
|
355
|
+
const timeoutId = setTimeout(() => {
|
|
356
|
+
if (abortController) {
|
|
357
|
+
abortController.abort();
|
|
358
|
+
}
|
|
359
|
+
reject(new TimeoutError(request));
|
|
360
|
+
}, options.timeout);
|
|
361
|
+
void options
|
|
362
|
+
.fetch(request)
|
|
363
|
+
.then(resolve)
|
|
364
|
+
.catch(reject)
|
|
365
|
+
.then(() => {
|
|
366
|
+
clearTimeout(timeoutId);
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// https://github.com/sindresorhus/delay/tree/ab98ae8dfcb38e1593286c94d934e70d14a4e111
|
|
372
|
+
async function delay(ms, { signal }) {
|
|
373
|
+
return new Promise((resolve, reject) => {
|
|
374
|
+
if (signal) {
|
|
375
|
+
signal.throwIfAborted();
|
|
376
|
+
signal.addEventListener('abort', abortHandler, { once: true });
|
|
377
|
+
}
|
|
378
|
+
function abortHandler() {
|
|
379
|
+
clearTimeout(timeoutId);
|
|
380
|
+
reject(signal.reason);
|
|
381
|
+
}
|
|
382
|
+
const timeoutId = setTimeout(() => {
|
|
383
|
+
signal?.removeEventListener('abort', abortHandler);
|
|
384
|
+
resolve();
|
|
385
|
+
}, ms);
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
class Ky {
|
|
390
|
+
static create(input, options) {
|
|
391
|
+
const ky = new Ky(input, options);
|
|
392
|
+
const fn = async () => {
|
|
393
|
+
if (typeof ky._options.timeout === 'number' && ky._options.timeout > maxSafeTimeout) {
|
|
394
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
|
|
395
|
+
}
|
|
396
|
+
// Delay the fetch so that body method shortcuts can set the Accept header
|
|
397
|
+
await Promise.resolve();
|
|
398
|
+
let response = await ky._fetch();
|
|
399
|
+
for (const hook of ky._options.hooks.afterResponse) {
|
|
400
|
+
// eslint-disable-next-line no-await-in-loop
|
|
401
|
+
const modifiedResponse = await hook(ky.request, ky._options, ky._decorateResponse(response.clone()));
|
|
402
|
+
if (modifiedResponse instanceof globalThis.Response) {
|
|
403
|
+
response = modifiedResponse;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
ky._decorateResponse(response);
|
|
407
|
+
if (!response.ok && ky._options.throwHttpErrors) {
|
|
408
|
+
let error = new HTTPError(response, ky.request, ky._options);
|
|
409
|
+
for (const hook of ky._options.hooks.beforeError) {
|
|
410
|
+
// eslint-disable-next-line no-await-in-loop
|
|
411
|
+
error = await hook(error);
|
|
412
|
+
}
|
|
413
|
+
throw error;
|
|
414
|
+
}
|
|
415
|
+
// If `onDownloadProgress` is passed, it uses the stream API internally
|
|
416
|
+
/* istanbul ignore next */
|
|
417
|
+
if (ky._options.onDownloadProgress) {
|
|
418
|
+
if (typeof ky._options.onDownloadProgress !== 'function') {
|
|
419
|
+
throw new TypeError('The `onDownloadProgress` option must be a function');
|
|
420
|
+
}
|
|
421
|
+
if (!supportsResponseStreams) {
|
|
422
|
+
throw new Error('Streams are not supported in your environment. `ReadableStream` is missing.');
|
|
423
|
+
}
|
|
424
|
+
return ky._stream(response.clone(), ky._options.onDownloadProgress);
|
|
425
|
+
}
|
|
426
|
+
return response;
|
|
427
|
+
};
|
|
428
|
+
const isRetriableMethod = ky._options.retry.methods.includes(ky.request.method.toLowerCase());
|
|
429
|
+
const result = (isRetriableMethod ? ky._retry(fn) : fn());
|
|
430
|
+
for (const [type, mimeType] of Object.entries(responseTypes)) {
|
|
431
|
+
result[type] = async () => {
|
|
432
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
433
|
+
ky.request.headers.set('accept', ky.request.headers.get('accept') || mimeType);
|
|
434
|
+
const awaitedResult = await result;
|
|
435
|
+
const response = awaitedResult.clone();
|
|
436
|
+
if (type === 'json') {
|
|
437
|
+
if (response.status === 204) {
|
|
438
|
+
return '';
|
|
439
|
+
}
|
|
440
|
+
const arrayBuffer = await response.clone().arrayBuffer();
|
|
441
|
+
const responseSize = arrayBuffer.byteLength;
|
|
442
|
+
if (responseSize === 0) {
|
|
443
|
+
return '';
|
|
444
|
+
}
|
|
445
|
+
if (options.parseJson) {
|
|
446
|
+
return options.parseJson(await response.text());
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return response[type]();
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
return result;
|
|
453
|
+
}
|
|
454
|
+
// eslint-disable-next-line complexity
|
|
455
|
+
constructor(input, options = {}) {
|
|
456
|
+
Object.defineProperty(this, "request", {
|
|
457
|
+
enumerable: true,
|
|
458
|
+
configurable: true,
|
|
459
|
+
writable: true,
|
|
460
|
+
value: void 0
|
|
461
|
+
});
|
|
462
|
+
Object.defineProperty(this, "abortController", {
|
|
463
|
+
enumerable: true,
|
|
464
|
+
configurable: true,
|
|
465
|
+
writable: true,
|
|
466
|
+
value: void 0
|
|
467
|
+
});
|
|
468
|
+
Object.defineProperty(this, "_retryCount", {
|
|
469
|
+
enumerable: true,
|
|
470
|
+
configurable: true,
|
|
471
|
+
writable: true,
|
|
472
|
+
value: 0
|
|
473
|
+
});
|
|
474
|
+
Object.defineProperty(this, "_input", {
|
|
475
|
+
enumerable: true,
|
|
476
|
+
configurable: true,
|
|
477
|
+
writable: true,
|
|
478
|
+
value: void 0
|
|
479
|
+
});
|
|
480
|
+
Object.defineProperty(this, "_options", {
|
|
481
|
+
enumerable: true,
|
|
482
|
+
configurable: true,
|
|
483
|
+
writable: true,
|
|
484
|
+
value: void 0
|
|
485
|
+
});
|
|
486
|
+
this._input = input;
|
|
487
|
+
this._options = {
|
|
488
|
+
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
|
|
489
|
+
credentials: this._input.credentials || 'same-origin',
|
|
490
|
+
...options,
|
|
491
|
+
headers: mergeHeaders(this._input.headers, options.headers),
|
|
492
|
+
hooks: deepMerge({
|
|
493
|
+
beforeRequest: [],
|
|
494
|
+
beforeRetry: [],
|
|
495
|
+
beforeError: [],
|
|
496
|
+
afterResponse: [],
|
|
497
|
+
}, options.hooks),
|
|
498
|
+
method: normalizeRequestMethod(options.method ?? this._input.method),
|
|
499
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
500
|
+
prefixUrl: String(options.prefixUrl || ''),
|
|
501
|
+
retry: normalizeRetryOptions(options.retry),
|
|
502
|
+
throwHttpErrors: options.throwHttpErrors !== false,
|
|
503
|
+
timeout: options.timeout ?? 10000,
|
|
504
|
+
fetch: options.fetch ?? globalThis.fetch.bind(globalThis),
|
|
505
|
+
};
|
|
506
|
+
if (typeof this._input !== 'string' && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {
|
|
507
|
+
throw new TypeError('`input` must be a string, URL, or Request');
|
|
508
|
+
}
|
|
509
|
+
if (this._options.prefixUrl && typeof this._input === 'string') {
|
|
510
|
+
if (this._input.startsWith('/')) {
|
|
511
|
+
throw new Error('`input` must not begin with a slash when using `prefixUrl`');
|
|
512
|
+
}
|
|
513
|
+
if (!this._options.prefixUrl.endsWith('/')) {
|
|
514
|
+
this._options.prefixUrl += '/';
|
|
515
|
+
}
|
|
516
|
+
this._input = this._options.prefixUrl + this._input;
|
|
517
|
+
}
|
|
518
|
+
if (supportsAbortController) {
|
|
519
|
+
this.abortController = new globalThis.AbortController();
|
|
520
|
+
if (this._options.signal) {
|
|
521
|
+
const originalSignal = this._options.signal;
|
|
522
|
+
this._options.signal.addEventListener('abort', () => {
|
|
523
|
+
this.abortController.abort(originalSignal.reason);
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
this._options.signal = this.abortController.signal;
|
|
527
|
+
}
|
|
528
|
+
if (supportsRequestStreams) {
|
|
529
|
+
// @ts-expect-error - Types are outdated.
|
|
530
|
+
this._options.duplex = 'half';
|
|
531
|
+
}
|
|
532
|
+
this.request = new globalThis.Request(this._input, this._options);
|
|
533
|
+
if (this._options.searchParams) {
|
|
534
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
535
|
+
const textSearchParams = typeof this._options.searchParams === 'string'
|
|
536
|
+
? this._options.searchParams.replace(/^\?/, '')
|
|
537
|
+
: new URLSearchParams(this._options.searchParams).toString();
|
|
538
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
539
|
+
const searchParams = '?' + textSearchParams;
|
|
540
|
+
const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
|
|
541
|
+
// To provide correct form boundary, Content-Type header should be deleted each time when new Request instantiated from another one
|
|
542
|
+
if (((supportsFormData && this._options.body instanceof globalThis.FormData)
|
|
543
|
+
|| this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers['content-type'])) {
|
|
544
|
+
this.request.headers.delete('content-type');
|
|
545
|
+
}
|
|
546
|
+
// The spread of `this.request` is required as otherwise it misses the `duplex` option for some reason and throws.
|
|
547
|
+
this.request = new globalThis.Request(new globalThis.Request(url, { ...this.request }), this._options);
|
|
548
|
+
}
|
|
549
|
+
if (this._options.json !== undefined) {
|
|
550
|
+
this._options.body = JSON.stringify(this._options.json);
|
|
551
|
+
this.request.headers.set('content-type', this._options.headers.get('content-type') ?? 'application/json');
|
|
552
|
+
this.request = new globalThis.Request(this.request, { body: this._options.body });
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
_calculateRetryDelay(error) {
|
|
556
|
+
this._retryCount++;
|
|
557
|
+
if (this._retryCount < this._options.retry.limit && !(error instanceof TimeoutError)) {
|
|
558
|
+
if (error instanceof HTTPError) {
|
|
559
|
+
if (!this._options.retry.statusCodes.includes(error.response.status)) {
|
|
560
|
+
return 0;
|
|
561
|
+
}
|
|
562
|
+
const retryAfter = error.response.headers.get('Retry-After');
|
|
563
|
+
if (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {
|
|
564
|
+
let after = Number(retryAfter);
|
|
565
|
+
if (Number.isNaN(after)) {
|
|
566
|
+
after = Date.parse(retryAfter) - Date.now();
|
|
567
|
+
}
|
|
568
|
+
else {
|
|
569
|
+
after *= 1000;
|
|
570
|
+
}
|
|
571
|
+
if (this._options.retry.maxRetryAfter !== undefined && after > this._options.retry.maxRetryAfter) {
|
|
572
|
+
return 0;
|
|
573
|
+
}
|
|
574
|
+
return after;
|
|
575
|
+
}
|
|
576
|
+
if (error.response.status === 413) {
|
|
577
|
+
return 0;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
const BACKOFF_FACTOR = 0.3;
|
|
581
|
+
return Math.min(this._options.retry.backoffLimit, BACKOFF_FACTOR * (2 ** (this._retryCount - 1)) * 1000);
|
|
582
|
+
}
|
|
583
|
+
return 0;
|
|
584
|
+
}
|
|
585
|
+
_decorateResponse(response) {
|
|
586
|
+
if (this._options.parseJson) {
|
|
587
|
+
response.json = async () => this._options.parseJson(await response.text());
|
|
588
|
+
}
|
|
589
|
+
return response;
|
|
590
|
+
}
|
|
591
|
+
async _retry(fn) {
|
|
592
|
+
try {
|
|
593
|
+
return await fn();
|
|
594
|
+
}
|
|
595
|
+
catch (error) {
|
|
596
|
+
const ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);
|
|
597
|
+
if (ms !== 0 && this._retryCount > 0) {
|
|
598
|
+
await delay(ms, { signal: this._options.signal });
|
|
599
|
+
for (const hook of this._options.hooks.beforeRetry) {
|
|
600
|
+
// eslint-disable-next-line no-await-in-loop
|
|
601
|
+
const hookResult = await hook({
|
|
602
|
+
request: this.request,
|
|
603
|
+
options: this._options,
|
|
604
|
+
error: error,
|
|
605
|
+
retryCount: this._retryCount,
|
|
606
|
+
});
|
|
607
|
+
// If `stop` is returned from the hook, the retry process is stopped
|
|
608
|
+
if (hookResult === stop) {
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
return this._retry(fn);
|
|
613
|
+
}
|
|
614
|
+
throw error;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
async _fetch() {
|
|
618
|
+
for (const hook of this._options.hooks.beforeRequest) {
|
|
619
|
+
// eslint-disable-next-line no-await-in-loop
|
|
620
|
+
const result = await hook(this.request, this._options);
|
|
621
|
+
if (result instanceof Request) {
|
|
622
|
+
this.request = result;
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
if (result instanceof Response) {
|
|
626
|
+
return result;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (this._options.timeout === false) {
|
|
630
|
+
return this._options.fetch(this.request.clone());
|
|
631
|
+
}
|
|
632
|
+
return timeout(this.request.clone(), this.abortController, this._options);
|
|
633
|
+
}
|
|
634
|
+
/* istanbul ignore next */
|
|
635
|
+
_stream(response, onDownloadProgress) {
|
|
636
|
+
const totalBytes = Number(response.headers.get('content-length')) || 0;
|
|
637
|
+
let transferredBytes = 0;
|
|
638
|
+
if (response.status === 204) {
|
|
639
|
+
if (onDownloadProgress) {
|
|
640
|
+
onDownloadProgress({ percent: 1, totalBytes, transferredBytes }, new Uint8Array());
|
|
641
|
+
}
|
|
642
|
+
return new globalThis.Response(null, {
|
|
643
|
+
status: response.status,
|
|
644
|
+
statusText: response.statusText,
|
|
645
|
+
headers: response.headers,
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
return new globalThis.Response(new globalThis.ReadableStream({
|
|
649
|
+
async start(controller) {
|
|
650
|
+
const reader = response.body.getReader();
|
|
651
|
+
if (onDownloadProgress) {
|
|
652
|
+
onDownloadProgress({ percent: 0, transferredBytes: 0, totalBytes }, new Uint8Array());
|
|
653
|
+
}
|
|
654
|
+
async function read() {
|
|
655
|
+
const { done, value } = await reader.read();
|
|
656
|
+
if (done) {
|
|
657
|
+
controller.close();
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
if (onDownloadProgress) {
|
|
661
|
+
transferredBytes += value.byteLength;
|
|
662
|
+
const percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
|
|
663
|
+
onDownloadProgress({ percent, transferredBytes, totalBytes }, value);
|
|
664
|
+
}
|
|
665
|
+
controller.enqueue(value);
|
|
666
|
+
await read();
|
|
667
|
+
}
|
|
668
|
+
await read();
|
|
669
|
+
},
|
|
670
|
+
}), {
|
|
671
|
+
status: response.status,
|
|
672
|
+
statusText: response.statusText,
|
|
673
|
+
headers: response.headers,
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/*! MIT License © Sindre Sorhus */
|
|
679
|
+
const createInstance = (defaults) => {
|
|
680
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
681
|
+
const ky = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
|
|
682
|
+
for (const method of requestMethods) {
|
|
683
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
684
|
+
ky[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));
|
|
685
|
+
}
|
|
686
|
+
ky.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));
|
|
687
|
+
ky.extend = (newDefaults) => createInstance(validateAndMerge(defaults, newDefaults));
|
|
688
|
+
ky.stop = stop;
|
|
689
|
+
return ky;
|
|
690
|
+
};
|
|
691
|
+
const ky = createInstance();
|
|
692
|
+
|
|
693
|
+
exports.HTTPError = HTTPError;
|
|
694
|
+
exports.TimeoutError = TimeoutError;
|
|
695
|
+
exports.default = ky;
|
|
696
|
+
|
|
697
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
698
|
+
|
|
699
|
+
}));
|
|
700
|
+
} (ky$1, ky$1.exports));
|
|
701
|
+
|
|
702
|
+
var kyExports = ky$1.exports;
|
|
718
703
|
|
|
719
704
|
const urlHttp = lightweight$2;
|
|
720
705
|
const { flattie: flatten } = dist;
|
|
721
706
|
|
|
722
707
|
const factory = factory_1;
|
|
723
|
-
const { default: ky } =
|
|
708
|
+
const { default: ky } = kyExports;
|
|
724
709
|
|
|
725
710
|
class MicrolinkError extends Error {
|
|
726
711
|
constructor (props) {
|
|
@@ -767,7 +752,7 @@
|
|
|
767
752
|
urlHttp,
|
|
768
753
|
got,
|
|
769
754
|
flatten,
|
|
770
|
-
VERSION: '0.
|
|
755
|
+
VERSION: '0.11.0-1'
|
|
771
756
|
});
|
|
772
757
|
|
|
773
758
|
var lightweight$1 = /*@__PURE__*/getDefaultExportFromCjs(lightweight);
|