@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 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
- 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;
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 } = kyExports;
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-4'
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