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