msw 0.28.1 → 0.30.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/cli/init.js +14 -6
- package/lib/esm/RequestHandler-deps.js +162 -130
- package/lib/esm/fetch-deps.js +306 -95
- package/lib/esm/graphql-deps.js +26 -19
- package/lib/esm/index-deps.js +2 -2
- package/lib/esm/index.js +5291 -710
- package/lib/esm/index2.js +2 -2
- package/lib/esm/mockServiceWorker.js +4 -3
- package/lib/esm/rest-deps.js +4 -4
- package/lib/esm/xml-deps.js +1 -217
- package/lib/iife/index.js +4 -4
- package/lib/iife/mockServiceWorker.js +4 -3
- package/lib/types/context/body.d.ts +1 -1
- package/lib/types/context/json.d.ts +1 -1
- package/lib/types/context/text.d.ts +1 -1
- package/lib/types/context/xml.d.ts +1 -1
- package/lib/types/handlers/GraphQLHandler.d.ts +4 -2
- package/lib/types/handlers/RequestHandler.d.ts +12 -8
- package/lib/types/handlers/RestHandler.d.ts +2 -2
- package/lib/types/node/glossary.d.ts +2 -1
- package/lib/types/response.d.ts +1 -1
- package/lib/types/setupWorker/glossary.d.ts +21 -16
- package/lib/types/setupWorker/start/createFallbackStart.d.ts +2 -0
- package/lib/types/setupWorker/start/createStartHandler.d.ts +2 -0
- package/lib/types/setupWorker/start/utils/enableMocking.d.ts +5 -0
- package/lib/types/setupWorker/start/utils/prepareStartHandler.d.ts +9 -0
- package/lib/types/setupWorker/start/utils/printStartMessage.d.ts +7 -0
- package/lib/types/setupWorker/start/utils/validateWorkerScope.d.ts +2 -0
- package/lib/types/setupWorker/stop/createFallbackStop.d.ts +2 -0
- package/lib/types/setupWorker/stop/createStop.d.ts +2 -2
- package/lib/types/setupWorker/stop/utils/printStopMessage.d.ts +3 -0
- package/lib/types/sharedOptions.d.ts +3 -2
- package/lib/types/utils/getResponse.d.ts +2 -3
- package/lib/types/utils/handleRequest.d.ts +27 -0
- package/lib/types/utils/internal/isIterable.d.ts +4 -0
- package/lib/types/utils/internal/tryCatch.d.ts +1 -0
- package/lib/types/utils/logging/prepareResponse.d.ts +3 -3
- package/lib/types/utils/request/parseIsomorphicRequest.d.ts +6 -0
- package/lib/types/utils/request/parseWorkerRequest.d.ts +4 -0
- package/lib/types/utils/worker/createFallbackRequestListener.d.ts +3 -0
- package/lib/umd/index.js +27002 -5268
- package/lib/umd/mockServiceWorker.js +4 -3
- package/native/lib/index.js +4374 -4281
- package/node/lib/index.js +1385 -1292
- package/package.json +33 -33
- package/lib/types/setupWorker/start/createStart.d.ts +0 -2
- package/lib/types/setupWorker/start/utils/activateMocking.d.ts +0 -2
package/node/lib/index.js
CHANGED
|
@@ -4,18 +4,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var ClientRequest = require('@mswjs/interceptors/lib/interceptors/ClientRequest');
|
|
6
6
|
var XMLHttpRequest = require('@mswjs/interceptors/lib/interceptors/XMLHttpRequest');
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var events_1 = require('events');
|
|
7
|
+
var require$$0 = require('os');
|
|
8
|
+
var require$$1 = require('tty');
|
|
9
|
+
var require$$0$1 = require('events');
|
|
11
10
|
var interceptors = require('@mswjs/interceptors');
|
|
11
|
+
var timers = require('timers');
|
|
12
12
|
var url = require('url');
|
|
13
13
|
|
|
14
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
15
|
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
16
|
+
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
17
|
+
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
18
|
+
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
19
19
|
|
|
20
20
|
/*! *****************************************************************************
|
|
21
21
|
Copyright (c) Microsoft Corporation.
|
|
@@ -56,10 +56,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
56
56
|
|
|
57
57
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
var module = { exports: {} };
|
|
61
|
-
return fn(module, module.exports), module.exports;
|
|
62
|
-
}
|
|
59
|
+
var ansiStyles$1 = {exports: {}};
|
|
63
60
|
|
|
64
61
|
var colorName = {
|
|
65
62
|
"aliceblue": [240, 248, 255],
|
|
@@ -215,18 +212,18 @@ var colorName = {
|
|
|
215
212
|
/* MIT license */
|
|
216
213
|
|
|
217
214
|
/* eslint-disable no-mixed-operators */
|
|
218
|
-
|
|
215
|
+
const cssKeywords = colorName;
|
|
219
216
|
|
|
220
217
|
// NOTE: conversions should only return primitive values (i.e. arrays, or
|
|
221
218
|
// values that give correct `typeof` results).
|
|
222
219
|
// do not use box values types (i.e. Number(), String(), etc.)
|
|
223
220
|
|
|
224
221
|
const reverseKeywords = {};
|
|
225
|
-
for (const key of Object.keys(
|
|
226
|
-
reverseKeywords[
|
|
222
|
+
for (const key of Object.keys(cssKeywords)) {
|
|
223
|
+
reverseKeywords[cssKeywords[key]] = key;
|
|
227
224
|
}
|
|
228
225
|
|
|
229
|
-
const convert = {
|
|
226
|
+
const convert$1 = {
|
|
230
227
|
rgb: {channels: 3, labels: 'rgb'},
|
|
231
228
|
hsl: {channels: 3, labels: 'hsl'},
|
|
232
229
|
hsv: {channels: 3, labels: 'hsv'},
|
|
@@ -244,30 +241,30 @@ const convert = {
|
|
|
244
241
|
gray: {channels: 1, labels: ['gray']}
|
|
245
242
|
};
|
|
246
243
|
|
|
247
|
-
var conversions = convert;
|
|
244
|
+
var conversions$2 = convert$1;
|
|
248
245
|
|
|
249
246
|
// Hide .channels and .labels properties
|
|
250
|
-
for (const model of Object.keys(convert)) {
|
|
251
|
-
if (!('channels' in convert[model])) {
|
|
247
|
+
for (const model of Object.keys(convert$1)) {
|
|
248
|
+
if (!('channels' in convert$1[model])) {
|
|
252
249
|
throw new Error('missing channels property: ' + model);
|
|
253
250
|
}
|
|
254
251
|
|
|
255
|
-
if (!('labels' in convert[model])) {
|
|
252
|
+
if (!('labels' in convert$1[model])) {
|
|
256
253
|
throw new Error('missing channel labels property: ' + model);
|
|
257
254
|
}
|
|
258
255
|
|
|
259
|
-
if (convert[model].labels.length !== convert[model].channels) {
|
|
256
|
+
if (convert$1[model].labels.length !== convert$1[model].channels) {
|
|
260
257
|
throw new Error('channel and label counts mismatch: ' + model);
|
|
261
258
|
}
|
|
262
259
|
|
|
263
|
-
const {channels, labels} = convert[model];
|
|
264
|
-
delete convert[model].channels;
|
|
265
|
-
delete convert[model].labels;
|
|
266
|
-
Object.defineProperty(convert[model], 'channels', {value: channels});
|
|
267
|
-
Object.defineProperty(convert[model], 'labels', {value: labels});
|
|
260
|
+
const {channels, labels} = convert$1[model];
|
|
261
|
+
delete convert$1[model].channels;
|
|
262
|
+
delete convert$1[model].labels;
|
|
263
|
+
Object.defineProperty(convert$1[model], 'channels', {value: channels});
|
|
264
|
+
Object.defineProperty(convert$1[model], 'labels', {value: labels});
|
|
268
265
|
}
|
|
269
266
|
|
|
270
|
-
convert.rgb.hsl = function (rgb) {
|
|
267
|
+
convert$1.rgb.hsl = function (rgb) {
|
|
271
268
|
const r = rgb[0] / 255;
|
|
272
269
|
const g = rgb[1] / 255;
|
|
273
270
|
const b = rgb[2] / 255;
|
|
@@ -306,7 +303,7 @@ convert.rgb.hsl = function (rgb) {
|
|
|
306
303
|
return [h, s * 100, l * 100];
|
|
307
304
|
};
|
|
308
305
|
|
|
309
|
-
convert.rgb.hsv = function (rgb) {
|
|
306
|
+
convert$1.rgb.hsv = function (rgb) {
|
|
310
307
|
let rdif;
|
|
311
308
|
let gdif;
|
|
312
309
|
let bdif;
|
|
@@ -353,11 +350,11 @@ convert.rgb.hsv = function (rgb) {
|
|
|
353
350
|
];
|
|
354
351
|
};
|
|
355
352
|
|
|
356
|
-
convert.rgb.hwb = function (rgb) {
|
|
353
|
+
convert$1.rgb.hwb = function (rgb) {
|
|
357
354
|
const r = rgb[0];
|
|
358
355
|
const g = rgb[1];
|
|
359
356
|
let b = rgb[2];
|
|
360
|
-
const h = convert.rgb.hsl(rgb)[0];
|
|
357
|
+
const h = convert$1.rgb.hsl(rgb)[0];
|
|
361
358
|
const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
|
362
359
|
|
|
363
360
|
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
|
@@ -365,7 +362,7 @@ convert.rgb.hwb = function (rgb) {
|
|
|
365
362
|
return [h, w * 100, b * 100];
|
|
366
363
|
};
|
|
367
364
|
|
|
368
|
-
convert.rgb.cmyk = function (rgb) {
|
|
365
|
+
convert$1.rgb.cmyk = function (rgb) {
|
|
369
366
|
const r = rgb[0] / 255;
|
|
370
367
|
const g = rgb[1] / 255;
|
|
371
368
|
const b = rgb[2] / 255;
|
|
@@ -389,7 +386,7 @@ function comparativeDistance(x, y) {
|
|
|
389
386
|
);
|
|
390
387
|
}
|
|
391
388
|
|
|
392
|
-
convert.rgb.keyword = function (rgb) {
|
|
389
|
+
convert$1.rgb.keyword = function (rgb) {
|
|
393
390
|
const reversed = reverseKeywords[rgb];
|
|
394
391
|
if (reversed) {
|
|
395
392
|
return reversed;
|
|
@@ -398,8 +395,8 @@ convert.rgb.keyword = function (rgb) {
|
|
|
398
395
|
let currentClosestDistance = Infinity;
|
|
399
396
|
let currentClosestKeyword;
|
|
400
397
|
|
|
401
|
-
for (const keyword of Object.keys(
|
|
402
|
-
const value =
|
|
398
|
+
for (const keyword of Object.keys(cssKeywords)) {
|
|
399
|
+
const value = cssKeywords[keyword];
|
|
403
400
|
|
|
404
401
|
// Compute comparative distance
|
|
405
402
|
const distance = comparativeDistance(rgb, value);
|
|
@@ -414,11 +411,11 @@ convert.rgb.keyword = function (rgb) {
|
|
|
414
411
|
return currentClosestKeyword;
|
|
415
412
|
};
|
|
416
413
|
|
|
417
|
-
convert.keyword.rgb = function (keyword) {
|
|
418
|
-
return
|
|
414
|
+
convert$1.keyword.rgb = function (keyword) {
|
|
415
|
+
return cssKeywords[keyword];
|
|
419
416
|
};
|
|
420
417
|
|
|
421
|
-
convert.rgb.xyz = function (rgb) {
|
|
418
|
+
convert$1.rgb.xyz = function (rgb) {
|
|
422
419
|
let r = rgb[0] / 255;
|
|
423
420
|
let g = rgb[1] / 255;
|
|
424
421
|
let b = rgb[2] / 255;
|
|
@@ -435,8 +432,8 @@ convert.rgb.xyz = function (rgb) {
|
|
|
435
432
|
return [x * 100, y * 100, z * 100];
|
|
436
433
|
};
|
|
437
434
|
|
|
438
|
-
convert.rgb.lab = function (rgb) {
|
|
439
|
-
const xyz = convert.rgb.xyz(rgb);
|
|
435
|
+
convert$1.rgb.lab = function (rgb) {
|
|
436
|
+
const xyz = convert$1.rgb.xyz(rgb);
|
|
440
437
|
let x = xyz[0];
|
|
441
438
|
let y = xyz[1];
|
|
442
439
|
let z = xyz[2];
|
|
@@ -456,7 +453,7 @@ convert.rgb.lab = function (rgb) {
|
|
|
456
453
|
return [l, a, b];
|
|
457
454
|
};
|
|
458
455
|
|
|
459
|
-
convert.hsl.rgb = function (hsl) {
|
|
456
|
+
convert$1.hsl.rgb = function (hsl) {
|
|
460
457
|
const h = hsl[0] / 360;
|
|
461
458
|
const s = hsl[1] / 100;
|
|
462
459
|
const l = hsl[2] / 100;
|
|
@@ -504,7 +501,7 @@ convert.hsl.rgb = function (hsl) {
|
|
|
504
501
|
return rgb;
|
|
505
502
|
};
|
|
506
503
|
|
|
507
|
-
convert.hsl.hsv = function (hsl) {
|
|
504
|
+
convert$1.hsl.hsv = function (hsl) {
|
|
508
505
|
const h = hsl[0];
|
|
509
506
|
let s = hsl[1] / 100;
|
|
510
507
|
let l = hsl[2] / 100;
|
|
@@ -520,7 +517,7 @@ convert.hsl.hsv = function (hsl) {
|
|
|
520
517
|
return [h, sv * 100, v * 100];
|
|
521
518
|
};
|
|
522
519
|
|
|
523
|
-
convert.hsv.rgb = function (hsv) {
|
|
520
|
+
convert$1.hsv.rgb = function (hsv) {
|
|
524
521
|
const h = hsv[0] / 60;
|
|
525
522
|
const s = hsv[1] / 100;
|
|
526
523
|
let v = hsv[2] / 100;
|
|
@@ -548,7 +545,7 @@ convert.hsv.rgb = function (hsv) {
|
|
|
548
545
|
}
|
|
549
546
|
};
|
|
550
547
|
|
|
551
|
-
convert.hsv.hsl = function (hsv) {
|
|
548
|
+
convert$1.hsv.hsl = function (hsv) {
|
|
552
549
|
const h = hsv[0];
|
|
553
550
|
const s = hsv[1] / 100;
|
|
554
551
|
const v = hsv[2] / 100;
|
|
@@ -567,7 +564,7 @@ convert.hsv.hsl = function (hsv) {
|
|
|
567
564
|
};
|
|
568
565
|
|
|
569
566
|
// http://dev.w3.org/csswg/css-color/#hwb-to-rgb
|
|
570
|
-
convert.hwb.rgb = function (hwb) {
|
|
567
|
+
convert$1.hwb.rgb = function (hwb) {
|
|
571
568
|
const h = hwb[0] / 360;
|
|
572
569
|
let wh = hwb[1] / 100;
|
|
573
570
|
let bl = hwb[2] / 100;
|
|
@@ -609,7 +606,7 @@ convert.hwb.rgb = function (hwb) {
|
|
|
609
606
|
return [r * 255, g * 255, b * 255];
|
|
610
607
|
};
|
|
611
608
|
|
|
612
|
-
convert.cmyk.rgb = function (cmyk) {
|
|
609
|
+
convert$1.cmyk.rgb = function (cmyk) {
|
|
613
610
|
const c = cmyk[0] / 100;
|
|
614
611
|
const m = cmyk[1] / 100;
|
|
615
612
|
const y = cmyk[2] / 100;
|
|
@@ -622,7 +619,7 @@ convert.cmyk.rgb = function (cmyk) {
|
|
|
622
619
|
return [r * 255, g * 255, b * 255];
|
|
623
620
|
};
|
|
624
621
|
|
|
625
|
-
convert.xyz.rgb = function (xyz) {
|
|
622
|
+
convert$1.xyz.rgb = function (xyz) {
|
|
626
623
|
const x = xyz[0] / 100;
|
|
627
624
|
const y = xyz[1] / 100;
|
|
628
625
|
const z = xyz[2] / 100;
|
|
@@ -654,7 +651,7 @@ convert.xyz.rgb = function (xyz) {
|
|
|
654
651
|
return [r * 255, g * 255, b * 255];
|
|
655
652
|
};
|
|
656
653
|
|
|
657
|
-
convert.xyz.lab = function (xyz) {
|
|
654
|
+
convert$1.xyz.lab = function (xyz) {
|
|
658
655
|
let x = xyz[0];
|
|
659
656
|
let y = xyz[1];
|
|
660
657
|
let z = xyz[2];
|
|
@@ -674,7 +671,7 @@ convert.xyz.lab = function (xyz) {
|
|
|
674
671
|
return [l, a, b];
|
|
675
672
|
};
|
|
676
673
|
|
|
677
|
-
convert.lab.xyz = function (lab) {
|
|
674
|
+
convert$1.lab.xyz = function (lab) {
|
|
678
675
|
const l = lab[0];
|
|
679
676
|
const a = lab[1];
|
|
680
677
|
const b = lab[2];
|
|
@@ -700,7 +697,7 @@ convert.lab.xyz = function (lab) {
|
|
|
700
697
|
return [x, y, z];
|
|
701
698
|
};
|
|
702
699
|
|
|
703
|
-
convert.lab.lch = function (lab) {
|
|
700
|
+
convert$1.lab.lch = function (lab) {
|
|
704
701
|
const l = lab[0];
|
|
705
702
|
const a = lab[1];
|
|
706
703
|
const b = lab[2];
|
|
@@ -718,7 +715,7 @@ convert.lab.lch = function (lab) {
|
|
|
718
715
|
return [l, c, h];
|
|
719
716
|
};
|
|
720
717
|
|
|
721
|
-
convert.lch.lab = function (lch) {
|
|
718
|
+
convert$1.lch.lab = function (lch) {
|
|
722
719
|
const l = lch[0];
|
|
723
720
|
const c = lch[1];
|
|
724
721
|
const h = lch[2];
|
|
@@ -730,9 +727,9 @@ convert.lch.lab = function (lch) {
|
|
|
730
727
|
return [l, a, b];
|
|
731
728
|
};
|
|
732
729
|
|
|
733
|
-
convert.rgb.ansi16 = function (args, saturation = null) {
|
|
730
|
+
convert$1.rgb.ansi16 = function (args, saturation = null) {
|
|
734
731
|
const [r, g, b] = args;
|
|
735
|
-
let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation; // Hsv -> ansi16 optimization
|
|
732
|
+
let value = saturation === null ? convert$1.rgb.hsv(args)[2] : saturation; // Hsv -> ansi16 optimization
|
|
736
733
|
|
|
737
734
|
value = Math.round(value / 50);
|
|
738
735
|
|
|
@@ -752,13 +749,13 @@ convert.rgb.ansi16 = function (args, saturation = null) {
|
|
|
752
749
|
return ansi;
|
|
753
750
|
};
|
|
754
751
|
|
|
755
|
-
convert.hsv.ansi16 = function (args) {
|
|
752
|
+
convert$1.hsv.ansi16 = function (args) {
|
|
756
753
|
// Optimization here; we already know the value and don't need to get
|
|
757
754
|
// it converted for us.
|
|
758
|
-
return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
|
|
755
|
+
return convert$1.rgb.ansi16(convert$1.hsv.rgb(args), args[2]);
|
|
759
756
|
};
|
|
760
757
|
|
|
761
|
-
convert.rgb.ansi256 = function (args) {
|
|
758
|
+
convert$1.rgb.ansi256 = function (args) {
|
|
762
759
|
const r = args[0];
|
|
763
760
|
const g = args[1];
|
|
764
761
|
const b = args[2];
|
|
@@ -785,7 +782,7 @@ convert.rgb.ansi256 = function (args) {
|
|
|
785
782
|
return ansi;
|
|
786
783
|
};
|
|
787
784
|
|
|
788
|
-
convert.ansi16.rgb = function (args) {
|
|
785
|
+
convert$1.ansi16.rgb = function (args) {
|
|
789
786
|
let color = args % 10;
|
|
790
787
|
|
|
791
788
|
// Handle greyscale
|
|
@@ -807,7 +804,7 @@ convert.ansi16.rgb = function (args) {
|
|
|
807
804
|
return [r, g, b];
|
|
808
805
|
};
|
|
809
806
|
|
|
810
|
-
convert.ansi256.rgb = function (args) {
|
|
807
|
+
convert$1.ansi256.rgb = function (args) {
|
|
811
808
|
// Handle greyscale
|
|
812
809
|
if (args >= 232) {
|
|
813
810
|
const c = (args - 232) * 10 + 8;
|
|
@@ -824,7 +821,7 @@ convert.ansi256.rgb = function (args) {
|
|
|
824
821
|
return [r, g, b];
|
|
825
822
|
};
|
|
826
823
|
|
|
827
|
-
convert.rgb.hex = function (args) {
|
|
824
|
+
convert$1.rgb.hex = function (args) {
|
|
828
825
|
const integer = ((Math.round(args[0]) & 0xFF) << 16)
|
|
829
826
|
+ ((Math.round(args[1]) & 0xFF) << 8)
|
|
830
827
|
+ (Math.round(args[2]) & 0xFF);
|
|
@@ -833,7 +830,7 @@ convert.rgb.hex = function (args) {
|
|
|
833
830
|
return '000000'.substring(string.length) + string;
|
|
834
831
|
};
|
|
835
832
|
|
|
836
|
-
convert.hex.rgb = function (args) {
|
|
833
|
+
convert$1.hex.rgb = function (args) {
|
|
837
834
|
const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
838
835
|
if (!match) {
|
|
839
836
|
return [0, 0, 0];
|
|
@@ -855,7 +852,7 @@ convert.hex.rgb = function (args) {
|
|
|
855
852
|
return [r, g, b];
|
|
856
853
|
};
|
|
857
854
|
|
|
858
|
-
convert.rgb.hcg = function (rgb) {
|
|
855
|
+
convert$1.rgb.hcg = function (rgb) {
|
|
859
856
|
const r = rgb[0] / 255;
|
|
860
857
|
const g = rgb[1] / 255;
|
|
861
858
|
const b = rgb[2] / 255;
|
|
@@ -889,7 +886,7 @@ convert.rgb.hcg = function (rgb) {
|
|
|
889
886
|
return [hue * 360, chroma * 100, grayscale * 100];
|
|
890
887
|
};
|
|
891
888
|
|
|
892
|
-
convert.hsl.hcg = function (hsl) {
|
|
889
|
+
convert$1.hsl.hcg = function (hsl) {
|
|
893
890
|
const s = hsl[1] / 100;
|
|
894
891
|
const l = hsl[2] / 100;
|
|
895
892
|
|
|
@@ -903,7 +900,7 @@ convert.hsl.hcg = function (hsl) {
|
|
|
903
900
|
return [hsl[0], c * 100, f * 100];
|
|
904
901
|
};
|
|
905
902
|
|
|
906
|
-
convert.hsv.hcg = function (hsv) {
|
|
903
|
+
convert$1.hsv.hcg = function (hsv) {
|
|
907
904
|
const s = hsv[1] / 100;
|
|
908
905
|
const v = hsv[2] / 100;
|
|
909
906
|
|
|
@@ -917,7 +914,7 @@ convert.hsv.hcg = function (hsv) {
|
|
|
917
914
|
return [hsv[0], c * 100, f * 100];
|
|
918
915
|
};
|
|
919
916
|
|
|
920
|
-
convert.hcg.rgb = function (hcg) {
|
|
917
|
+
convert$1.hcg.rgb = function (hcg) {
|
|
921
918
|
const h = hcg[0] / 360;
|
|
922
919
|
const c = hcg[1] / 100;
|
|
923
920
|
const g = hcg[2] / 100;
|
|
@@ -958,7 +955,7 @@ convert.hcg.rgb = function (hcg) {
|
|
|
958
955
|
];
|
|
959
956
|
};
|
|
960
957
|
|
|
961
|
-
convert.hcg.hsv = function (hcg) {
|
|
958
|
+
convert$1.hcg.hsv = function (hcg) {
|
|
962
959
|
const c = hcg[1] / 100;
|
|
963
960
|
const g = hcg[2] / 100;
|
|
964
961
|
|
|
@@ -972,7 +969,7 @@ convert.hcg.hsv = function (hcg) {
|
|
|
972
969
|
return [hcg[0], f * 100, v * 100];
|
|
973
970
|
};
|
|
974
971
|
|
|
975
|
-
convert.hcg.hsl = function (hcg) {
|
|
972
|
+
convert$1.hcg.hsl = function (hcg) {
|
|
976
973
|
const c = hcg[1] / 100;
|
|
977
974
|
const g = hcg[2] / 100;
|
|
978
975
|
|
|
@@ -989,14 +986,14 @@ convert.hcg.hsl = function (hcg) {
|
|
|
989
986
|
return [hcg[0], s * 100, l * 100];
|
|
990
987
|
};
|
|
991
988
|
|
|
992
|
-
convert.hcg.hwb = function (hcg) {
|
|
989
|
+
convert$1.hcg.hwb = function (hcg) {
|
|
993
990
|
const c = hcg[1] / 100;
|
|
994
991
|
const g = hcg[2] / 100;
|
|
995
992
|
const v = c + g * (1.0 - c);
|
|
996
993
|
return [hcg[0], (v - c) * 100, (1 - v) * 100];
|
|
997
994
|
};
|
|
998
995
|
|
|
999
|
-
convert.hwb.hcg = function (hwb) {
|
|
996
|
+
convert$1.hwb.hcg = function (hwb) {
|
|
1000
997
|
const w = hwb[1] / 100;
|
|
1001
998
|
const b = hwb[2] / 100;
|
|
1002
999
|
const v = 1 - b;
|
|
@@ -1010,37 +1007,37 @@ convert.hwb.hcg = function (hwb) {
|
|
|
1010
1007
|
return [hwb[0], c * 100, g * 100];
|
|
1011
1008
|
};
|
|
1012
1009
|
|
|
1013
|
-
convert.apple.rgb = function (apple) {
|
|
1010
|
+
convert$1.apple.rgb = function (apple) {
|
|
1014
1011
|
return [(apple[0] / 65535) * 255, (apple[1] / 65535) * 255, (apple[2] / 65535) * 255];
|
|
1015
1012
|
};
|
|
1016
1013
|
|
|
1017
|
-
convert.rgb.apple = function (rgb) {
|
|
1014
|
+
convert$1.rgb.apple = function (rgb) {
|
|
1018
1015
|
return [(rgb[0] / 255) * 65535, (rgb[1] / 255) * 65535, (rgb[2] / 255) * 65535];
|
|
1019
1016
|
};
|
|
1020
1017
|
|
|
1021
|
-
convert.gray.rgb = function (args) {
|
|
1018
|
+
convert$1.gray.rgb = function (args) {
|
|
1022
1019
|
return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
|
1023
1020
|
};
|
|
1024
1021
|
|
|
1025
|
-
convert.gray.hsl = function (args) {
|
|
1022
|
+
convert$1.gray.hsl = function (args) {
|
|
1026
1023
|
return [0, 0, args[0]];
|
|
1027
1024
|
};
|
|
1028
1025
|
|
|
1029
|
-
convert.gray.hsv = convert.gray.hsl;
|
|
1026
|
+
convert$1.gray.hsv = convert$1.gray.hsl;
|
|
1030
1027
|
|
|
1031
|
-
convert.gray.hwb = function (gray) {
|
|
1028
|
+
convert$1.gray.hwb = function (gray) {
|
|
1032
1029
|
return [0, 100, gray[0]];
|
|
1033
1030
|
};
|
|
1034
1031
|
|
|
1035
|
-
convert.gray.cmyk = function (gray) {
|
|
1032
|
+
convert$1.gray.cmyk = function (gray) {
|
|
1036
1033
|
return [0, 0, 0, gray[0]];
|
|
1037
1034
|
};
|
|
1038
1035
|
|
|
1039
|
-
convert.gray.lab = function (gray) {
|
|
1036
|
+
convert$1.gray.lab = function (gray) {
|
|
1040
1037
|
return [gray[0], 0, 0];
|
|
1041
1038
|
};
|
|
1042
1039
|
|
|
1043
|
-
convert.gray.hex = function (gray) {
|
|
1040
|
+
convert$1.gray.hex = function (gray) {
|
|
1044
1041
|
const val = Math.round(gray[0] / 100 * 255) & 0xFF;
|
|
1045
1042
|
const integer = (val << 16) + (val << 8) + val;
|
|
1046
1043
|
|
|
@@ -1048,11 +1045,13 @@ convert.gray.hex = function (gray) {
|
|
|
1048
1045
|
return '000000'.substring(string.length) + string;
|
|
1049
1046
|
};
|
|
1050
1047
|
|
|
1051
|
-
convert.rgb.gray = function (rgb) {
|
|
1048
|
+
convert$1.rgb.gray = function (rgb) {
|
|
1052
1049
|
const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
|
1053
1050
|
return [val / 255 * 100];
|
|
1054
1051
|
};
|
|
1055
1052
|
|
|
1053
|
+
const conversions$1 = conversions$2;
|
|
1054
|
+
|
|
1056
1055
|
/*
|
|
1057
1056
|
This function routes a model to all other models.
|
|
1058
1057
|
|
|
@@ -1067,7 +1066,7 @@ convert.rgb.gray = function (rgb) {
|
|
|
1067
1066
|
function buildGraph() {
|
|
1068
1067
|
const graph = {};
|
|
1069
1068
|
// https://jsperf.com/object-keys-vs-for-in-with-closure/3
|
|
1070
|
-
const models = Object.keys(conversions);
|
|
1069
|
+
const models = Object.keys(conversions$1);
|
|
1071
1070
|
|
|
1072
1071
|
for (let len = models.length, i = 0; i < len; i++) {
|
|
1073
1072
|
graph[models[i]] = {
|
|
@@ -1090,7 +1089,7 @@ function deriveBFS(fromModel) {
|
|
|
1090
1089
|
|
|
1091
1090
|
while (queue.length) {
|
|
1092
1091
|
const current = queue.pop();
|
|
1093
|
-
const adjacents = Object.keys(conversions[current]);
|
|
1092
|
+
const adjacents = Object.keys(conversions$1[current]);
|
|
1094
1093
|
|
|
1095
1094
|
for (let len = adjacents.length, i = 0; i < len; i++) {
|
|
1096
1095
|
const adjacent = adjacents[i];
|
|
@@ -1115,12 +1114,12 @@ function link(from, to) {
|
|
|
1115
1114
|
|
|
1116
1115
|
function wrapConversion(toModel, graph) {
|
|
1117
1116
|
const path = [graph[toModel].parent, toModel];
|
|
1118
|
-
let fn = conversions[graph[toModel].parent][toModel];
|
|
1117
|
+
let fn = conversions$1[graph[toModel].parent][toModel];
|
|
1119
1118
|
|
|
1120
1119
|
let cur = graph[toModel].parent;
|
|
1121
1120
|
while (graph[cur].parent) {
|
|
1122
1121
|
path.unshift(graph[cur].parent);
|
|
1123
|
-
fn = link(conversions[graph[cur].parent][cur], fn);
|
|
1122
|
+
fn = link(conversions$1[graph[cur].parent][cur], fn);
|
|
1124
1123
|
cur = graph[cur].parent;
|
|
1125
1124
|
}
|
|
1126
1125
|
|
|
@@ -1128,7 +1127,7 @@ function wrapConversion(toModel, graph) {
|
|
|
1128
1127
|
return fn;
|
|
1129
1128
|
}
|
|
1130
1129
|
|
|
1131
|
-
var route = function (fromModel) {
|
|
1130
|
+
var route$1 = function (fromModel) {
|
|
1132
1131
|
const graph = deriveBFS(fromModel);
|
|
1133
1132
|
const conversion = {};
|
|
1134
1133
|
|
|
@@ -1148,7 +1147,10 @@ var route = function (fromModel) {
|
|
|
1148
1147
|
return conversion;
|
|
1149
1148
|
};
|
|
1150
1149
|
|
|
1151
|
-
const
|
|
1150
|
+
const conversions = conversions$2;
|
|
1151
|
+
const route = route$1;
|
|
1152
|
+
|
|
1153
|
+
const convert = {};
|
|
1152
1154
|
|
|
1153
1155
|
const models = Object.keys(conversions);
|
|
1154
1156
|
|
|
@@ -1209,10 +1211,10 @@ function wrapRounded(fn) {
|
|
|
1209
1211
|
}
|
|
1210
1212
|
|
|
1211
1213
|
models.forEach(fromModel => {
|
|
1212
|
-
convert
|
|
1214
|
+
convert[fromModel] = {};
|
|
1213
1215
|
|
|
1214
|
-
Object.defineProperty(convert
|
|
1215
|
-
Object.defineProperty(convert
|
|
1216
|
+
Object.defineProperty(convert[fromModel], 'channels', {value: conversions[fromModel].channels});
|
|
1217
|
+
Object.defineProperty(convert[fromModel], 'labels', {value: conversions[fromModel].labels});
|
|
1216
1218
|
|
|
1217
1219
|
const routes = route(fromModel);
|
|
1218
1220
|
const routeModels = Object.keys(routes);
|
|
@@ -1220,14 +1222,14 @@ models.forEach(fromModel => {
|
|
|
1220
1222
|
routeModels.forEach(toModel => {
|
|
1221
1223
|
const fn = routes[toModel];
|
|
1222
1224
|
|
|
1223
|
-
convert
|
|
1224
|
-
convert
|
|
1225
|
+
convert[fromModel][toModel] = wrapRounded(fn);
|
|
1226
|
+
convert[fromModel][toModel].raw = wrapRaw(fn);
|
|
1225
1227
|
});
|
|
1226
1228
|
});
|
|
1227
1229
|
|
|
1228
|
-
var colorConvert = convert
|
|
1230
|
+
var colorConvert = convert;
|
|
1229
1231
|
|
|
1230
|
-
|
|
1232
|
+
(function (module) {
|
|
1231
1233
|
|
|
1232
1234
|
const wrapAnsi16 = (fn, offset) => (...args) => {
|
|
1233
1235
|
const code = fn(...args);
|
|
@@ -1390,15 +1392,19 @@ Object.defineProperty(module, 'exports', {
|
|
|
1390
1392
|
enumerable: true,
|
|
1391
1393
|
get: assembleStyles
|
|
1392
1394
|
});
|
|
1393
|
-
});
|
|
1395
|
+
}(ansiStyles$1));
|
|
1394
1396
|
|
|
1395
|
-
var hasFlag = (flag, argv = process.argv) => {
|
|
1397
|
+
var hasFlag$1 = (flag, argv = process.argv) => {
|
|
1396
1398
|
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
|
|
1397
1399
|
const position = argv.indexOf(prefix + flag);
|
|
1398
1400
|
const terminatorPosition = argv.indexOf('--');
|
|
1399
1401
|
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
1400
1402
|
};
|
|
1401
1403
|
|
|
1404
|
+
const os = require$$0__default['default'];
|
|
1405
|
+
const tty = require$$1__default['default'];
|
|
1406
|
+
const hasFlag = hasFlag$1;
|
|
1407
|
+
|
|
1402
1408
|
const {env} = process;
|
|
1403
1409
|
|
|
1404
1410
|
let forceColor;
|
|
@@ -1465,7 +1471,7 @@ function supportsColor(haveStream, streamIsTTY) {
|
|
|
1465
1471
|
if (process.platform === 'win32') {
|
|
1466
1472
|
// Windows 10 build 10586 is the first Windows release that supports 256 colors.
|
|
1467
1473
|
// Windows 10 build 14931 is the first release that supports 16m/TrueColor.
|
|
1468
|
-
const osRelease =
|
|
1474
|
+
const osRelease = os.release().split('.');
|
|
1469
1475
|
if (
|
|
1470
1476
|
Number(osRelease[0]) >= 10 &&
|
|
1471
1477
|
Number(osRelease[2]) >= 10586
|
|
@@ -1526,11 +1532,11 @@ function getSupportLevel(stream) {
|
|
|
1526
1532
|
|
|
1527
1533
|
var supportsColor_1 = {
|
|
1528
1534
|
supportsColor: getSupportLevel,
|
|
1529
|
-
stdout: translateLevel(supportsColor(true,
|
|
1530
|
-
stderr: translateLevel(supportsColor(true,
|
|
1535
|
+
stdout: translateLevel(supportsColor(true, tty.isatty(1))),
|
|
1536
|
+
stderr: translateLevel(supportsColor(true, tty.isatty(2)))
|
|
1531
1537
|
};
|
|
1532
1538
|
|
|
1533
|
-
const stringReplaceAll = (string, substring, replacer) => {
|
|
1539
|
+
const stringReplaceAll$1 = (string, substring, replacer) => {
|
|
1534
1540
|
let index = string.indexOf(substring);
|
|
1535
1541
|
if (index === -1) {
|
|
1536
1542
|
return string;
|
|
@@ -1549,7 +1555,7 @@ const stringReplaceAll = (string, substring, replacer) => {
|
|
|
1549
1555
|
return returnValue;
|
|
1550
1556
|
};
|
|
1551
1557
|
|
|
1552
|
-
const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
|
|
1558
|
+
const stringEncaseCRLFWithFirstIndex$1 = (string, prefix, postfix, index) => {
|
|
1553
1559
|
let endIndex = 0;
|
|
1554
1560
|
let returnValue = '';
|
|
1555
1561
|
do {
|
|
@@ -1564,8 +1570,8 @@ const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
|
|
|
1564
1570
|
};
|
|
1565
1571
|
|
|
1566
1572
|
var util = {
|
|
1567
|
-
stringReplaceAll,
|
|
1568
|
-
stringEncaseCRLFWithFirstIndex
|
|
1573
|
+
stringReplaceAll: stringReplaceAll$1,
|
|
1574
|
+
stringEncaseCRLFWithFirstIndex: stringEncaseCRLFWithFirstIndex$1
|
|
1569
1575
|
};
|
|
1570
1576
|
|
|
1571
1577
|
const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
|
|
@@ -1702,10 +1708,11 @@ var templates = (chalk, temporary) => {
|
|
|
1702
1708
|
return chunks.join('');
|
|
1703
1709
|
};
|
|
1704
1710
|
|
|
1711
|
+
const ansiStyles = ansiStyles$1.exports;
|
|
1705
1712
|
const {stdout: stdoutColor, stderr: stderrColor} = supportsColor_1;
|
|
1706
1713
|
const {
|
|
1707
|
-
stringReplaceAll
|
|
1708
|
-
stringEncaseCRLFWithFirstIndex
|
|
1714
|
+
stringReplaceAll,
|
|
1715
|
+
stringEncaseCRLFWithFirstIndex
|
|
1709
1716
|
} = util;
|
|
1710
1717
|
|
|
1711
1718
|
const {isArray} = Array;
|
|
@@ -1877,7 +1884,7 @@ const applyStyle = (self, string) => {
|
|
|
1877
1884
|
// Replace any instances already present with a re-opening code
|
|
1878
1885
|
// otherwise only the part of the string until said closing code
|
|
1879
1886
|
// will be colored, and the rest will simply be 'plain'.
|
|
1880
|
-
string = stringReplaceAll
|
|
1887
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
1881
1888
|
|
|
1882
1889
|
styler = styler.parent;
|
|
1883
1890
|
}
|
|
@@ -1888,7 +1895,7 @@ const applyStyle = (self, string) => {
|
|
|
1888
1895
|
// after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92
|
|
1889
1896
|
const lfIndex = string.indexOf('\n');
|
|
1890
1897
|
if (lfIndex !== -1) {
|
|
1891
|
-
string = stringEncaseCRLFWithFirstIndex
|
|
1898
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
1892
1899
|
}
|
|
1893
1900
|
|
|
1894
1901
|
return openAll + string + closeAll;
|
|
@@ -1930,6 +1937,106 @@ chalk.stderr.supportsColor = stderrColor;
|
|
|
1930
1937
|
|
|
1931
1938
|
var source = chalk;
|
|
1932
1939
|
|
|
1940
|
+
var lib$2 = {};
|
|
1941
|
+
|
|
1942
|
+
var StrictEventEmitter$1 = {};
|
|
1943
|
+
|
|
1944
|
+
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
1945
|
+
var extendStatics = function (d, b) {
|
|
1946
|
+
extendStatics = Object.setPrototypeOf ||
|
|
1947
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
1948
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
1949
|
+
return extendStatics(d, b);
|
|
1950
|
+
};
|
|
1951
|
+
return function (d, b) {
|
|
1952
|
+
extendStatics(d, b);
|
|
1953
|
+
function __() { this.constructor = d; }
|
|
1954
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
1955
|
+
};
|
|
1956
|
+
})();
|
|
1957
|
+
var __spreadArrays = (commonjsGlobal && commonjsGlobal.__spreadArrays) || function () {
|
|
1958
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
1959
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
1960
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
1961
|
+
r[k] = a[j];
|
|
1962
|
+
return r;
|
|
1963
|
+
};
|
|
1964
|
+
StrictEventEmitter$1.__esModule = true;
|
|
1965
|
+
StrictEventEmitter$1.StrictEventEmitter = void 0;
|
|
1966
|
+
var events_1 = require$$0__default$1['default'];
|
|
1967
|
+
var StrictEventEmitter = /** @class */ (function (_super) {
|
|
1968
|
+
__extends(StrictEventEmitter, _super);
|
|
1969
|
+
function StrictEventEmitter() {
|
|
1970
|
+
return _super.call(this) || this;
|
|
1971
|
+
}
|
|
1972
|
+
StrictEventEmitter.prototype.on = function (event, listener) {
|
|
1973
|
+
return _super.prototype.on.call(this, event.toString(), listener);
|
|
1974
|
+
};
|
|
1975
|
+
StrictEventEmitter.prototype.once = function (event, listener) {
|
|
1976
|
+
return _super.prototype.on.call(this, event.toString(), listener);
|
|
1977
|
+
};
|
|
1978
|
+
StrictEventEmitter.prototype.off = function (event, listener) {
|
|
1979
|
+
return _super.prototype.off.call(this, event.toString(), listener);
|
|
1980
|
+
};
|
|
1981
|
+
StrictEventEmitter.prototype.emit = function (event) {
|
|
1982
|
+
var data = [];
|
|
1983
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1984
|
+
data[_i - 1] = arguments[_i];
|
|
1985
|
+
}
|
|
1986
|
+
return _super.prototype.emit.apply(this, __spreadArrays([event.toString()], data));
|
|
1987
|
+
};
|
|
1988
|
+
StrictEventEmitter.prototype.addListener = function (event, listener) {
|
|
1989
|
+
return _super.prototype.addListener.call(this, event.toString(), listener);
|
|
1990
|
+
};
|
|
1991
|
+
StrictEventEmitter.prototype.removeListener = function (event, listener) {
|
|
1992
|
+
return _super.prototype.removeListener.call(this, event.toString(), listener);
|
|
1993
|
+
};
|
|
1994
|
+
return StrictEventEmitter;
|
|
1995
|
+
}(events_1.EventEmitter));
|
|
1996
|
+
StrictEventEmitter$1.StrictEventEmitter = StrictEventEmitter;
|
|
1997
|
+
|
|
1998
|
+
(function (exports) {
|
|
1999
|
+
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2000
|
+
if (k2 === undefined) k2 = k;
|
|
2001
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
2002
|
+
}) : (function(o, m, k, k2) {
|
|
2003
|
+
if (k2 === undefined) k2 = k;
|
|
2004
|
+
o[k2] = m[k];
|
|
2005
|
+
}));
|
|
2006
|
+
exports.__esModule = true;
|
|
2007
|
+
exports.StrictEventEmitter = void 0;
|
|
2008
|
+
var StrictEventEmitter_1 = StrictEventEmitter$1;
|
|
2009
|
+
__createBinding(exports, StrictEventEmitter_1, "StrictEventEmitter");
|
|
2010
|
+
}(lib$2));
|
|
2011
|
+
|
|
2012
|
+
/**
|
|
2013
|
+
* Returns a boolean indicating if the current process is running in Node.js environment.
|
|
2014
|
+
* @see https://github.com/mswjs/msw/pull/255
|
|
2015
|
+
*/
|
|
2016
|
+
function isNodeProcess() {
|
|
2017
|
+
// Check browser environment.
|
|
2018
|
+
if (typeof global !== 'object') {
|
|
2019
|
+
return false;
|
|
2020
|
+
}
|
|
2021
|
+
// Check nodejs or React Native environment.
|
|
2022
|
+
if (Object.prototype.toString.call(global.process) === '[object process]' ||
|
|
2023
|
+
navigator.product === 'ReactNative') {
|
|
2024
|
+
return true;
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2028
|
+
function use(currentHandlers, ...handlers) {
|
|
2029
|
+
currentHandlers.unshift(...handlers);
|
|
2030
|
+
}
|
|
2031
|
+
function restoreHandlers(handlers) {
|
|
2032
|
+
handlers.forEach((handler) => {
|
|
2033
|
+
handler.markAsSkipped(false);
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
function resetHandlers(initialHandlers, ...nextHandlers) {
|
|
2037
|
+
return nextHandlers.length > 0 ? [...nextHandlers] : [...initialHandlers];
|
|
2038
|
+
}
|
|
2039
|
+
|
|
1933
2040
|
/*!
|
|
1934
2041
|
* cookie
|
|
1935
2042
|
* Copyright(c) 2012-2014 Roman Shtylman
|
|
@@ -1942,7 +2049,7 @@ var source = chalk;
|
|
|
1942
2049
|
* @public
|
|
1943
2050
|
*/
|
|
1944
2051
|
|
|
1945
|
-
var parse_1 = parse;
|
|
2052
|
+
var parse_1 = parse$2;
|
|
1946
2053
|
var serialize_1 = serialize;
|
|
1947
2054
|
|
|
1948
2055
|
/**
|
|
@@ -1976,7 +2083,7 @@ var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
|
1976
2083
|
* @public
|
|
1977
2084
|
*/
|
|
1978
2085
|
|
|
1979
|
-
function parse(str, options) {
|
|
2086
|
+
function parse$2(str, options) {
|
|
1980
2087
|
if (typeof str !== 'string') {
|
|
1981
2088
|
throw new TypeError('argument str must be a string');
|
|
1982
2089
|
}
|
|
@@ -2131,127 +2238,13 @@ function tryDecode(str, decode) {
|
|
|
2131
2238
|
}
|
|
2132
2239
|
}
|
|
2133
2240
|
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
2140
|
-
return extendStatics(d, b);
|
|
2141
|
-
};
|
|
2142
|
-
return function (d, b) {
|
|
2143
|
-
extendStatics(d, b);
|
|
2144
|
-
function __() { this.constructor = d; }
|
|
2145
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
2146
|
-
};
|
|
2147
|
-
})();
|
|
2148
|
-
var __spreadArrays = (commonjsGlobal && commonjsGlobal.__spreadArrays) || function () {
|
|
2149
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
2150
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
2151
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
2152
|
-
r[k] = a[j];
|
|
2153
|
-
return r;
|
|
2154
|
-
};
|
|
2155
|
-
exports.__esModule = true;
|
|
2156
|
-
exports.StrictEventEmitter = void 0;
|
|
2157
|
-
|
|
2158
|
-
var StrictEventEmitter = /** @class */ (function (_super) {
|
|
2159
|
-
__extends(StrictEventEmitter, _super);
|
|
2160
|
-
function StrictEventEmitter() {
|
|
2161
|
-
return _super.call(this) || this;
|
|
2162
|
-
}
|
|
2163
|
-
StrictEventEmitter.prototype.on = function (event, listener) {
|
|
2164
|
-
return _super.prototype.on.call(this, event.toString(), listener);
|
|
2165
|
-
};
|
|
2166
|
-
StrictEventEmitter.prototype.once = function (event, listener) {
|
|
2167
|
-
return _super.prototype.on.call(this, event.toString(), listener);
|
|
2168
|
-
};
|
|
2169
|
-
StrictEventEmitter.prototype.off = function (event, listener) {
|
|
2170
|
-
return _super.prototype.off.call(this, event.toString(), listener);
|
|
2171
|
-
};
|
|
2172
|
-
StrictEventEmitter.prototype.emit = function (event) {
|
|
2173
|
-
var data = [];
|
|
2174
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
2175
|
-
data[_i - 1] = arguments[_i];
|
|
2176
|
-
}
|
|
2177
|
-
return _super.prototype.emit.apply(this, __spreadArrays([event.toString()], data));
|
|
2178
|
-
};
|
|
2179
|
-
StrictEventEmitter.prototype.addListener = function (event, listener) {
|
|
2180
|
-
return _super.prototype.addListener.call(this, event.toString(), listener);
|
|
2181
|
-
};
|
|
2182
|
-
StrictEventEmitter.prototype.removeListener = function (event, listener) {
|
|
2183
|
-
return _super.prototype.removeListener.call(this, event.toString(), listener);
|
|
2184
|
-
};
|
|
2185
|
-
return StrictEventEmitter;
|
|
2186
|
-
}(events_1__default['default'].EventEmitter));
|
|
2187
|
-
exports.StrictEventEmitter = StrictEventEmitter;
|
|
2188
|
-
});
|
|
2189
|
-
|
|
2190
|
-
var lib = createCommonjsModule(function (module, exports) {
|
|
2191
|
-
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2192
|
-
if (k2 === undefined) k2 = k;
|
|
2193
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
2194
|
-
}) : (function(o, m, k, k2) {
|
|
2195
|
-
if (k2 === undefined) k2 = k;
|
|
2196
|
-
o[k2] = m[k];
|
|
2197
|
-
}));
|
|
2198
|
-
exports.__esModule = true;
|
|
2199
|
-
exports.StrictEventEmitter = void 0;
|
|
2200
|
-
|
|
2201
|
-
__createBinding(exports, StrictEventEmitter_1, "StrictEventEmitter");
|
|
2202
|
-
});
|
|
2203
|
-
|
|
2204
|
-
/**
|
|
2205
|
-
* Returns a mocked response for a given request using following request handlers.
|
|
2206
|
-
*/
|
|
2207
|
-
const getResponse = (request, handlers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
2208
|
-
const relevantHandlers = handlers.filter((handler) => {
|
|
2209
|
-
return handler.test(request);
|
|
2241
|
+
function uuidv4() {
|
|
2242
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
2243
|
+
const r = (Math.random() * 16) | 0;
|
|
2244
|
+
const v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
2245
|
+
return v.toString(16);
|
|
2210
2246
|
});
|
|
2211
|
-
|
|
2212
|
-
return {
|
|
2213
|
-
handler: undefined,
|
|
2214
|
-
response: undefined,
|
|
2215
|
-
};
|
|
2216
|
-
}
|
|
2217
|
-
const result = yield relevantHandlers.reduce((acc, handler) => __awaiter(void 0, void 0, void 0, function* () {
|
|
2218
|
-
const previousResults = yield acc;
|
|
2219
|
-
if (!!(previousResults === null || previousResults === void 0 ? void 0 : previousResults.response)) {
|
|
2220
|
-
return acc;
|
|
2221
|
-
}
|
|
2222
|
-
const result = yield handler.run(request);
|
|
2223
|
-
if (result === null || result.handler.shouldSkip) {
|
|
2224
|
-
return null;
|
|
2225
|
-
}
|
|
2226
|
-
if (!result.response) {
|
|
2227
|
-
return {
|
|
2228
|
-
request: result.request,
|
|
2229
|
-
handler: result.handler,
|
|
2230
|
-
response: undefined,
|
|
2231
|
-
parsedResult: result.parsedResult,
|
|
2232
|
-
};
|
|
2233
|
-
}
|
|
2234
|
-
if (result.response.once) {
|
|
2235
|
-
handler.markAsSkipped(true);
|
|
2236
|
-
}
|
|
2237
|
-
return result;
|
|
2238
|
-
}), Promise.resolve(null));
|
|
2239
|
-
// Although reducing a list of relevant request handlers, it's possible
|
|
2240
|
-
// that in the end there will be no handler associted with the request
|
|
2241
|
-
// (i.e. if relevant handlers are fall-through).
|
|
2242
|
-
if (!result) {
|
|
2243
|
-
return {
|
|
2244
|
-
handler: undefined,
|
|
2245
|
-
response: undefined,
|
|
2246
|
-
};
|
|
2247
|
-
}
|
|
2248
|
-
return {
|
|
2249
|
-
handler: result.handler,
|
|
2250
|
-
publicRequest: result.request,
|
|
2251
|
-
parsedRequest: result.parsedResult,
|
|
2252
|
-
response: result.response,
|
|
2253
|
-
};
|
|
2254
|
-
});
|
|
2247
|
+
}
|
|
2255
2248
|
|
|
2256
2249
|
/**
|
|
2257
2250
|
* Parses a given string into a JSON.
|
|
@@ -2266,9 +2259,14 @@ function jsonParse(str) {
|
|
|
2266
2259
|
}
|
|
2267
2260
|
}
|
|
2268
2261
|
|
|
2269
|
-
var
|
|
2270
|
-
|
|
2271
|
-
|
|
2262
|
+
var lib$1 = {};
|
|
2263
|
+
|
|
2264
|
+
var Headers = {};
|
|
2265
|
+
|
|
2266
|
+
var normalizeHeaderName$1 = {};
|
|
2267
|
+
|
|
2268
|
+
Object.defineProperty(normalizeHeaderName$1, "__esModule", { value: true });
|
|
2269
|
+
normalizeHeaderName$1.normalizeHeaderName = void 0;
|
|
2272
2270
|
var HEADERS_INVALID_CHARACTERS = /[^a-z0-9\-#$%&'*+.^_`|~]/i;
|
|
2273
2271
|
function normalizeHeaderName(name) {
|
|
2274
2272
|
if (typeof name !== 'string') {
|
|
@@ -2279,20 +2277,19 @@ function normalizeHeaderName(name) {
|
|
|
2279
2277
|
}
|
|
2280
2278
|
return name.toLowerCase();
|
|
2281
2279
|
}
|
|
2282
|
-
|
|
2283
|
-
});
|
|
2280
|
+
normalizeHeaderName$1.normalizeHeaderName = normalizeHeaderName;
|
|
2284
2281
|
|
|
2285
|
-
var
|
|
2286
|
-
|
|
2287
|
-
|
|
2282
|
+
var normalizeHeaderValue$1 = {};
|
|
2283
|
+
|
|
2284
|
+
Object.defineProperty(normalizeHeaderValue$1, "__esModule", { value: true });
|
|
2285
|
+
normalizeHeaderValue$1.normalizeHeaderValue = void 0;
|
|
2288
2286
|
function normalizeHeaderValue(value) {
|
|
2289
2287
|
if (typeof value !== 'string') {
|
|
2290
2288
|
value = String(value);
|
|
2291
2289
|
}
|
|
2292
2290
|
return value;
|
|
2293
2291
|
}
|
|
2294
|
-
|
|
2295
|
-
});
|
|
2292
|
+
normalizeHeaderValue$1.normalizeHeaderValue = normalizeHeaderValue;
|
|
2296
2293
|
|
|
2297
2294
|
var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
|
|
2298
2295
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
@@ -2321,7 +2318,7 @@ var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (th
|
|
|
2321
2318
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
2322
2319
|
}
|
|
2323
2320
|
};
|
|
2324
|
-
var __read = (commonjsGlobal && commonjsGlobal.__read) || function (o, n) {
|
|
2321
|
+
var __read$3 = (commonjsGlobal && commonjsGlobal.__read) || function (o, n) {
|
|
2325
2322
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
2326
2323
|
if (!m) return o;
|
|
2327
2324
|
var i = m.call(o), r, ar = [], e;
|
|
@@ -2348,9 +2345,9 @@ var __values = (commonjsGlobal && commonjsGlobal.__values) || function(o) {
|
|
|
2348
2345
|
};
|
|
2349
2346
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
2350
2347
|
};
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2348
|
+
Object.defineProperty(Headers, "__esModule", { value: true });
|
|
2349
|
+
var normalizeHeaderName_1 = normalizeHeaderName$1;
|
|
2350
|
+
var normalizeHeaderValue_1 = normalizeHeaderValue$1;
|
|
2354
2351
|
var HeadersPolyfill = /** @class */ (function () {
|
|
2355
2352
|
function HeadersPolyfill(init) {
|
|
2356
2353
|
var _this = this;
|
|
@@ -2372,7 +2369,7 @@ var HeadersPolyfill = /** @class */ (function () {
|
|
|
2372
2369
|
}
|
|
2373
2370
|
else if (Array.isArray(init)) {
|
|
2374
2371
|
init.forEach(function (_a) {
|
|
2375
|
-
var _b = __read(_a, 2), name = _b[0], value = _b[1];
|
|
2372
|
+
var _b = __read$3(_a, 2), name = _b[0], value = _b[1];
|
|
2376
2373
|
_this.append(name, Array.isArray(value) ? value.join(', ') : value);
|
|
2377
2374
|
});
|
|
2378
2375
|
}
|
|
@@ -2533,7 +2530,7 @@ var HeadersPolyfill = /** @class */ (function () {
|
|
|
2533
2530
|
HeadersPolyfill.prototype.raw = function () {
|
|
2534
2531
|
var _this = this;
|
|
2535
2532
|
return Object.entries(this._headers).reduce(function (headers, _a) {
|
|
2536
|
-
var _b = __read(_a, 2), name = _b[0], value = _b[1];
|
|
2533
|
+
var _b = __read$3(_a, 2), name = _b[0], value = _b[1];
|
|
2537
2534
|
headers[_this._names.get(name)] = value;
|
|
2538
2535
|
return headers;
|
|
2539
2536
|
}, {});
|
|
@@ -2557,15 +2554,14 @@ var HeadersPolyfill = /** @class */ (function () {
|
|
|
2557
2554
|
};
|
|
2558
2555
|
return HeadersPolyfill;
|
|
2559
2556
|
}());
|
|
2560
|
-
|
|
2557
|
+
Headers.default = HeadersPolyfill;
|
|
2561
2558
|
|
|
2562
|
-
var
|
|
2563
|
-
default: _default
|
|
2564
|
-
}, '__esModule', {value: true});
|
|
2559
|
+
var headersToString$1 = {};
|
|
2565
2560
|
|
|
2566
|
-
var
|
|
2567
|
-
|
|
2568
|
-
|
|
2561
|
+
var headersToList$1 = {};
|
|
2562
|
+
|
|
2563
|
+
Object.defineProperty(headersToList$1, "__esModule", { value: true });
|
|
2564
|
+
headersToList$1.headersToList = void 0;
|
|
2569
2565
|
function headersToList(headers) {
|
|
2570
2566
|
var headersList = [];
|
|
2571
2567
|
headers.forEach(function (value, name) {
|
|
@@ -2576,11 +2572,9 @@ function headersToList(headers) {
|
|
|
2576
2572
|
});
|
|
2577
2573
|
return headersList;
|
|
2578
2574
|
}
|
|
2579
|
-
|
|
2580
|
-
});
|
|
2575
|
+
headersToList$1.headersToList = headersToList;
|
|
2581
2576
|
|
|
2582
|
-
var
|
|
2583
|
-
var __read = (commonjsGlobal && commonjsGlobal.__read) || function (o, n) {
|
|
2577
|
+
var __read$2 = (commonjsGlobal && commonjsGlobal.__read) || function (o, n) {
|
|
2584
2578
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
2585
2579
|
if (!m) return o;
|
|
2586
2580
|
var i = m.call(o), r, ar = [], e;
|
|
@@ -2596,27 +2590,27 @@ var __read = (commonjsGlobal && commonjsGlobal.__read) || function (o, n) {
|
|
|
2596
2590
|
}
|
|
2597
2591
|
return ar;
|
|
2598
2592
|
};
|
|
2599
|
-
Object.defineProperty(
|
|
2600
|
-
|
|
2601
|
-
|
|
2593
|
+
Object.defineProperty(headersToString$1, "__esModule", { value: true });
|
|
2594
|
+
headersToString$1.headersToString = void 0;
|
|
2595
|
+
var headersToList_1 = headersToList$1;
|
|
2602
2596
|
/**
|
|
2603
2597
|
* Converts a given `Headers` instance to its string representation.
|
|
2604
2598
|
*/
|
|
2605
2599
|
function headersToString(headers) {
|
|
2606
2600
|
var list = headersToList_1.headersToList(headers);
|
|
2607
2601
|
var lines = list.map(function (_a) {
|
|
2608
|
-
var _b = __read(_a, 2), name = _b[0], value = _b[1];
|
|
2602
|
+
var _b = __read$2(_a, 2), name = _b[0], value = _b[1];
|
|
2609
2603
|
var values = [].concat(value);
|
|
2610
2604
|
return name + ": " + values.join(', ');
|
|
2611
2605
|
});
|
|
2612
2606
|
return lines.join('\r\n');
|
|
2613
2607
|
}
|
|
2614
|
-
|
|
2615
|
-
});
|
|
2608
|
+
headersToString$1.headersToString = headersToString;
|
|
2616
2609
|
|
|
2617
|
-
var
|
|
2618
|
-
|
|
2619
|
-
|
|
2610
|
+
var headersToObject$1 = {};
|
|
2611
|
+
|
|
2612
|
+
Object.defineProperty(headersToObject$1, "__esModule", { value: true });
|
|
2613
|
+
headersToObject$1.headersToObject = void 0;
|
|
2620
2614
|
// List of headers that cannot have multiple values,
|
|
2621
2615
|
// while potentially having a comma in their single value.
|
|
2622
2616
|
var singleValueHeaders = ['user-agent'];
|
|
@@ -2634,13 +2628,13 @@ function headersToObject(headers) {
|
|
|
2634
2628
|
});
|
|
2635
2629
|
return headersObject;
|
|
2636
2630
|
}
|
|
2637
|
-
|
|
2638
|
-
});
|
|
2631
|
+
headersToObject$1.headersToObject = headersToObject;
|
|
2639
2632
|
|
|
2640
|
-
var
|
|
2641
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2642
|
-
exports.stringToHeaders = void 0;
|
|
2633
|
+
var stringToHeaders$1 = {};
|
|
2643
2634
|
|
|
2635
|
+
Object.defineProperty(stringToHeaders$1, "__esModule", { value: true });
|
|
2636
|
+
stringToHeaders$1.stringToHeaders = void 0;
|
|
2637
|
+
var Headers_1$2 = Headers;
|
|
2644
2638
|
/**
|
|
2645
2639
|
* Converts a string representation of headers (i.e. from XMLHttpRequest)
|
|
2646
2640
|
* to a new `Headers` instance.
|
|
@@ -2653,13 +2647,13 @@ function stringToHeaders(str) {
|
|
|
2653
2647
|
var value = parts.join(': ');
|
|
2654
2648
|
headers.append(name, value);
|
|
2655
2649
|
return headers;
|
|
2656
|
-
}, new
|
|
2650
|
+
}, new Headers_1$2.default());
|
|
2657
2651
|
}
|
|
2658
|
-
|
|
2659
|
-
});
|
|
2652
|
+
stringToHeaders$1.stringToHeaders = stringToHeaders;
|
|
2660
2653
|
|
|
2661
|
-
var
|
|
2662
|
-
|
|
2654
|
+
var listToHeaders$1 = {};
|
|
2655
|
+
|
|
2656
|
+
var __read$1 = (commonjsGlobal && commonjsGlobal.__read) || function (o, n) {
|
|
2663
2657
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
2664
2658
|
if (!m) return o;
|
|
2665
2659
|
var i = m.call(o), r, ar = [], e;
|
|
@@ -2675,13 +2669,13 @@ var __read = (commonjsGlobal && commonjsGlobal.__read) || function (o, n) {
|
|
|
2675
2669
|
}
|
|
2676
2670
|
return ar;
|
|
2677
2671
|
};
|
|
2678
|
-
Object.defineProperty(
|
|
2679
|
-
|
|
2680
|
-
|
|
2672
|
+
Object.defineProperty(listToHeaders$1, "__esModule", { value: true });
|
|
2673
|
+
listToHeaders$1.listToHeaders = void 0;
|
|
2674
|
+
var Headers_1$1 = Headers;
|
|
2681
2675
|
function listToHeaders(list) {
|
|
2682
|
-
var headers = new
|
|
2676
|
+
var headers = new Headers_1$1.default();
|
|
2683
2677
|
list.forEach(function (_a) {
|
|
2684
|
-
var _b = __read(_a, 2), name = _b[0], value = _b[1];
|
|
2678
|
+
var _b = __read$1(_a, 2), name = _b[0], value = _b[1];
|
|
2685
2679
|
var values = [].concat(value);
|
|
2686
2680
|
values.forEach(function (value) {
|
|
2687
2681
|
headers.append(name, value);
|
|
@@ -2689,12 +2683,14 @@ function listToHeaders(list) {
|
|
|
2689
2683
|
});
|
|
2690
2684
|
return headers;
|
|
2691
2685
|
}
|
|
2692
|
-
|
|
2693
|
-
});
|
|
2686
|
+
listToHeaders$1.listToHeaders = listToHeaders;
|
|
2694
2687
|
|
|
2695
|
-
var
|
|
2696
|
-
|
|
2697
|
-
|
|
2688
|
+
var objectToHeaders$1 = {};
|
|
2689
|
+
|
|
2690
|
+
var reduceHeadersObject$1 = {};
|
|
2691
|
+
|
|
2692
|
+
Object.defineProperty(reduceHeadersObject$1, "__esModule", { value: true });
|
|
2693
|
+
reduceHeadersObject$1.reduceHeadersObject = void 0;
|
|
2698
2694
|
/**
|
|
2699
2695
|
* Reduces given headers object instnace.
|
|
2700
2696
|
*/
|
|
@@ -2703,30 +2699,28 @@ function reduceHeadersObject(headers, reducer, initialState) {
|
|
|
2703
2699
|
return reducer(nextHeaders, name, headers[name]);
|
|
2704
2700
|
}, initialState);
|
|
2705
2701
|
}
|
|
2706
|
-
|
|
2707
|
-
});
|
|
2708
|
-
|
|
2709
|
-
var objectToHeaders_1 = createCommonjsModule(function (module, exports) {
|
|
2710
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2711
|
-
exports.objectToHeaders = void 0;
|
|
2712
|
-
|
|
2702
|
+
reduceHeadersObject$1.reduceHeadersObject = reduceHeadersObject;
|
|
2713
2703
|
|
|
2704
|
+
Object.defineProperty(objectToHeaders$1, "__esModule", { value: true });
|
|
2705
|
+
objectToHeaders$1.objectToHeaders = void 0;
|
|
2706
|
+
var Headers_1 = Headers;
|
|
2707
|
+
var reduceHeadersObject_1$1 = reduceHeadersObject$1;
|
|
2714
2708
|
/**
|
|
2715
2709
|
* Converts a given headers object to a new `Headers` instance.
|
|
2716
2710
|
*/
|
|
2717
2711
|
function objectToHeaders(headersObject) {
|
|
2718
|
-
return reduceHeadersObject_1.reduceHeadersObject(headersObject, function (headers, name, value) {
|
|
2712
|
+
return reduceHeadersObject_1$1.reduceHeadersObject(headersObject, function (headers, name, value) {
|
|
2719
2713
|
var values = [].concat(value).filter(Boolean);
|
|
2720
2714
|
values.forEach(function (value) {
|
|
2721
2715
|
headers.append(name, value);
|
|
2722
2716
|
});
|
|
2723
2717
|
return headers;
|
|
2724
|
-
}, new
|
|
2718
|
+
}, new Headers_1.default());
|
|
2725
2719
|
}
|
|
2726
|
-
|
|
2727
|
-
|
|
2720
|
+
objectToHeaders$1.objectToHeaders = objectToHeaders;
|
|
2721
|
+
|
|
2722
|
+
var flattenHeadersList$1 = {};
|
|
2728
2723
|
|
|
2729
|
-
var flattenHeadersList_1 = createCommonjsModule(function (module, exports) {
|
|
2730
2724
|
var __read = (commonjsGlobal && commonjsGlobal.__read) || function (o, n) {
|
|
2731
2725
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
2732
2726
|
if (!m) return o;
|
|
@@ -2743,54 +2737,53 @@ var __read = (commonjsGlobal && commonjsGlobal.__read) || function (o, n) {
|
|
|
2743
2737
|
}
|
|
2744
2738
|
return ar;
|
|
2745
2739
|
};
|
|
2746
|
-
Object.defineProperty(
|
|
2747
|
-
|
|
2740
|
+
Object.defineProperty(flattenHeadersList$1, "__esModule", { value: true });
|
|
2741
|
+
flattenHeadersList$1.flattenHeadersList = void 0;
|
|
2748
2742
|
function flattenHeadersList(list) {
|
|
2749
2743
|
return list.map(function (_a) {
|
|
2750
2744
|
var _b = __read(_a, 2), name = _b[0], values = _b[1];
|
|
2751
2745
|
return [name, [].concat(values).join('; ')];
|
|
2752
2746
|
});
|
|
2753
2747
|
}
|
|
2754
|
-
|
|
2755
|
-
});
|
|
2748
|
+
flattenHeadersList$1.flattenHeadersList = flattenHeadersList;
|
|
2756
2749
|
|
|
2757
|
-
var
|
|
2758
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2759
|
-
exports.flattenHeadersObject = void 0;
|
|
2750
|
+
var flattenHeadersObject$1 = {};
|
|
2760
2751
|
|
|
2752
|
+
Object.defineProperty(flattenHeadersObject$1, "__esModule", { value: true });
|
|
2753
|
+
flattenHeadersObject$1.flattenHeadersObject = void 0;
|
|
2754
|
+
var reduceHeadersObject_1 = reduceHeadersObject$1;
|
|
2761
2755
|
function flattenHeadersObject(headersObject) {
|
|
2762
2756
|
return reduceHeadersObject_1.reduceHeadersObject(headersObject, function (headers, name, value) {
|
|
2763
2757
|
headers[name] = [].concat(value).join('; ');
|
|
2764
2758
|
return headers;
|
|
2765
2759
|
}, {});
|
|
2766
2760
|
}
|
|
2767
|
-
|
|
2768
|
-
});
|
|
2761
|
+
flattenHeadersObject$1.flattenHeadersObject = flattenHeadersObject;
|
|
2769
2762
|
|
|
2770
|
-
|
|
2763
|
+
(function (exports) {
|
|
2771
2764
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2772
2765
|
exports.flattenHeadersObject = exports.flattenHeadersList = exports.reduceHeadersObject = exports.objectToHeaders = exports.listToHeaders = exports.stringToHeaders = exports.headersToObject = exports.headersToList = exports.headersToString = exports.Headers = void 0;
|
|
2773
|
-
|
|
2774
|
-
Object.defineProperty(exports, "Headers", { enumerable: true, get: function () { return
|
|
2775
|
-
|
|
2766
|
+
var Headers_1 = Headers;
|
|
2767
|
+
Object.defineProperty(exports, "Headers", { enumerable: true, get: function () { return Headers_1.default; } });
|
|
2768
|
+
var headersToString_1 = headersToString$1;
|
|
2776
2769
|
Object.defineProperty(exports, "headersToString", { enumerable: true, get: function () { return headersToString_1.headersToString; } });
|
|
2777
|
-
|
|
2770
|
+
var headersToList_1 = headersToList$1;
|
|
2778
2771
|
Object.defineProperty(exports, "headersToList", { enumerable: true, get: function () { return headersToList_1.headersToList; } });
|
|
2779
|
-
|
|
2772
|
+
var headersToObject_1 = headersToObject$1;
|
|
2780
2773
|
Object.defineProperty(exports, "headersToObject", { enumerable: true, get: function () { return headersToObject_1.headersToObject; } });
|
|
2781
|
-
|
|
2774
|
+
var stringToHeaders_1 = stringToHeaders$1;
|
|
2782
2775
|
Object.defineProperty(exports, "stringToHeaders", { enumerable: true, get: function () { return stringToHeaders_1.stringToHeaders; } });
|
|
2783
|
-
|
|
2776
|
+
var listToHeaders_1 = listToHeaders$1;
|
|
2784
2777
|
Object.defineProperty(exports, "listToHeaders", { enumerable: true, get: function () { return listToHeaders_1.listToHeaders; } });
|
|
2785
|
-
|
|
2778
|
+
var objectToHeaders_1 = objectToHeaders$1;
|
|
2786
2779
|
Object.defineProperty(exports, "objectToHeaders", { enumerable: true, get: function () { return objectToHeaders_1.objectToHeaders; } });
|
|
2787
|
-
|
|
2780
|
+
var reduceHeadersObject_1 = reduceHeadersObject$1;
|
|
2788
2781
|
Object.defineProperty(exports, "reduceHeadersObject", { enumerable: true, get: function () { return reduceHeadersObject_1.reduceHeadersObject; } });
|
|
2789
|
-
|
|
2782
|
+
var flattenHeadersList_1 = flattenHeadersList$1;
|
|
2790
2783
|
Object.defineProperty(exports, "flattenHeadersList", { enumerable: true, get: function () { return flattenHeadersList_1.flattenHeadersList; } });
|
|
2791
|
-
|
|
2784
|
+
var flattenHeadersObject_1 = flattenHeadersObject$1;
|
|
2792
2785
|
Object.defineProperty(exports, "flattenHeadersObject", { enumerable: true, get: function () { return flattenHeadersObject_1.flattenHeadersObject; } });
|
|
2793
|
-
});
|
|
2786
|
+
}(lib$1));
|
|
2794
2787
|
|
|
2795
2788
|
function parseContentHeaders(headersString) {
|
|
2796
2789
|
var _a, _b;
|
|
@@ -2868,365 +2861,840 @@ function parseMultipartData(data, headers) {
|
|
|
2868
2861
|
* Parses a given request/response body based on the `Content-Type` header.
|
|
2869
2862
|
*/
|
|
2870
2863
|
function parseBody(body, headers) {
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
// If the body has a Multipart Content-Type
|
|
2874
|
-
// parse it into an object.
|
|
2875
|
-
const hasMultipartContent = contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('multipart/form-data');
|
|
2876
|
-
if (hasMultipartContent && typeof body !== 'object') {
|
|
2877
|
-
return parseMultipartData(body, headers) || body;
|
|
2878
|
-
}
|
|
2879
|
-
// If the intercepted request's body has a JSON Content-Type
|
|
2880
|
-
// parse it into an object.
|
|
2881
|
-
const hasJsonContent = contentType === null || contentType === void 0 ? void 0 : contentType.includes('json');
|
|
2882
|
-
if (hasJsonContent && typeof body !== 'object') {
|
|
2883
|
-
return jsonParse(body) || body;
|
|
2884
|
-
}
|
|
2885
|
-
// Otherwise leave as-is.
|
|
2864
|
+
// Return whatever falsey body value is given.
|
|
2865
|
+
if (!body) {
|
|
2886
2866
|
return body;
|
|
2887
2867
|
}
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
* @see https://github.com/mswjs/msw/pull/255
|
|
2895
|
-
*/
|
|
2896
|
-
function isNodeProcess() {
|
|
2897
|
-
// Check browser environment.
|
|
2898
|
-
if (typeof global !== 'object') {
|
|
2899
|
-
return false;
|
|
2868
|
+
const contentType = headers === null || headers === void 0 ? void 0 : headers.get('content-type');
|
|
2869
|
+
// If the body has a Multipart Content-Type
|
|
2870
|
+
// parse it into an object.
|
|
2871
|
+
const hasMultipartContent = contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('multipart/form-data');
|
|
2872
|
+
if (hasMultipartContent && typeof body !== 'object') {
|
|
2873
|
+
return parseMultipartData(body, headers) || body;
|
|
2900
2874
|
}
|
|
2901
|
-
//
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2875
|
+
// If the intercepted request's body has a JSON Content-Type
|
|
2876
|
+
// parse it into an object.
|
|
2877
|
+
const hasJsonContent = contentType === null || contentType === void 0 ? void 0 : contentType.includes('json');
|
|
2878
|
+
if (hasJsonContent && typeof body !== 'object') {
|
|
2879
|
+
return jsonParse(body) || body;
|
|
2905
2880
|
}
|
|
2881
|
+
// Otherwise leave as-is.
|
|
2882
|
+
return body;
|
|
2906
2883
|
}
|
|
2907
2884
|
|
|
2908
|
-
|
|
2909
|
-
currentHandlers.unshift(...handlers);
|
|
2910
|
-
}
|
|
2911
|
-
function restoreHandlers(handlers) {
|
|
2912
|
-
handlers.forEach((handler) => {
|
|
2913
|
-
handler.markAsSkipped(false);
|
|
2914
|
-
});
|
|
2915
|
-
}
|
|
2916
|
-
function resetHandlers(initialHandlers, ...nextHandlers) {
|
|
2917
|
-
return nextHandlers.length > 0 ? [...nextHandlers] : [...initialHandlers];
|
|
2918
|
-
}
|
|
2885
|
+
var lib = {};
|
|
2919
2886
|
|
|
2920
|
-
var
|
|
2921
|
-
{
|
|
2922
|
-
function _min(d0, d1, d2, bx, ay)
|
|
2923
|
-
{
|
|
2924
|
-
return d0 < d1 || d2 < d1
|
|
2925
|
-
? d0 > d2
|
|
2926
|
-
? d2 + 1
|
|
2927
|
-
: d0 + 1
|
|
2928
|
-
: bx === ay
|
|
2929
|
-
? d1
|
|
2930
|
-
: d1 + 1;
|
|
2931
|
-
}
|
|
2887
|
+
var CookieStore = {};
|
|
2932
2888
|
|
|
2933
|
-
|
|
2934
|
-
{
|
|
2935
|
-
if (a === b) {
|
|
2936
|
-
return 0;
|
|
2937
|
-
}
|
|
2889
|
+
var setCookie = {exports: {}};
|
|
2938
2890
|
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2891
|
+
var defaultParseOptions = {
|
|
2892
|
+
decodeValues: true,
|
|
2893
|
+
map: false,
|
|
2894
|
+
silent: false,
|
|
2895
|
+
};
|
|
2944
2896
|
|
|
2945
|
-
|
|
2946
|
-
|
|
2897
|
+
function isNonEmptyString(str) {
|
|
2898
|
+
return typeof str === "string" && !!str.trim();
|
|
2899
|
+
}
|
|
2947
2900
|
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2901
|
+
function parseString(setCookieValue, options) {
|
|
2902
|
+
var parts = setCookieValue.split(";").filter(isNonEmptyString);
|
|
2903
|
+
var nameValue = parts.shift().split("=");
|
|
2904
|
+
var name = nameValue.shift();
|
|
2905
|
+
var value = nameValue.join("="); // everything after the first =, joined by a "=" if there was more than one part
|
|
2952
2906
|
|
|
2953
|
-
|
|
2907
|
+
options = options
|
|
2908
|
+
? Object.assign({}, defaultParseOptions, options)
|
|
2909
|
+
: defaultParseOptions;
|
|
2954
2910
|
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2911
|
+
try {
|
|
2912
|
+
value = options.decodeValues ? decodeURIComponent(value) : value; // decode cookie value
|
|
2913
|
+
} catch (e) {
|
|
2914
|
+
console.error(
|
|
2915
|
+
"set-cookie-parser encountered an error while decoding a cookie with value '" +
|
|
2916
|
+
value +
|
|
2917
|
+
"'. Set options.decodeValues to false to disable this feature.",
|
|
2918
|
+
e
|
|
2919
|
+
);
|
|
2920
|
+
}
|
|
2958
2921
|
|
|
2959
|
-
|
|
2960
|
-
|
|
2922
|
+
var cookie = {
|
|
2923
|
+
name: name, // grab everything before the first =
|
|
2924
|
+
value: value,
|
|
2925
|
+
};
|
|
2961
2926
|
|
|
2962
|
-
|
|
2963
|
-
|
|
2927
|
+
parts.forEach(function (part) {
|
|
2928
|
+
var sides = part.split("=");
|
|
2929
|
+
var key = sides.shift().trimLeft().toLowerCase();
|
|
2930
|
+
var value = sides.join("=");
|
|
2931
|
+
if (key === "expires") {
|
|
2932
|
+
cookie.expires = new Date(value);
|
|
2933
|
+
} else if (key === "max-age") {
|
|
2934
|
+
cookie.maxAge = parseInt(value, 10);
|
|
2935
|
+
} else if (key === "secure") {
|
|
2936
|
+
cookie.secure = true;
|
|
2937
|
+
} else if (key === "httponly") {
|
|
2938
|
+
cookie.httpOnly = true;
|
|
2939
|
+
} else if (key === "samesite") {
|
|
2940
|
+
cookie.sameSite = value;
|
|
2941
|
+
} else {
|
|
2942
|
+
cookie[key] = value;
|
|
2964
2943
|
}
|
|
2944
|
+
});
|
|
2965
2945
|
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
var d0;
|
|
2969
|
-
var d1;
|
|
2970
|
-
var d2;
|
|
2971
|
-
var d3;
|
|
2972
|
-
var dd;
|
|
2973
|
-
var dy;
|
|
2974
|
-
var ay;
|
|
2975
|
-
var bx0;
|
|
2976
|
-
var bx1;
|
|
2977
|
-
var bx2;
|
|
2978
|
-
var bx3;
|
|
2979
|
-
|
|
2980
|
-
var vector = [];
|
|
2981
|
-
|
|
2982
|
-
for (y = 0; y < la; y++) {
|
|
2983
|
-
vector.push(y + 1);
|
|
2984
|
-
vector.push(a.charCodeAt(offset + y));
|
|
2985
|
-
}
|
|
2946
|
+
return cookie;
|
|
2947
|
+
}
|
|
2986
2948
|
|
|
2987
|
-
|
|
2949
|
+
function parse$1(input, options) {
|
|
2950
|
+
options = options
|
|
2951
|
+
? Object.assign({}, defaultParseOptions, options)
|
|
2952
|
+
: defaultParseOptions;
|
|
2988
2953
|
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
dd = (x += 4);
|
|
2995
|
-
for (y = 0; y < len; y += 2) {
|
|
2996
|
-
dy = vector[y];
|
|
2997
|
-
ay = vector[y + 1];
|
|
2998
|
-
d0 = _min(dy, d0, d1, bx0, ay);
|
|
2999
|
-
d1 = _min(d0, d1, d2, bx1, ay);
|
|
3000
|
-
d2 = _min(d1, d2, d3, bx2, ay);
|
|
3001
|
-
dd = _min(d2, d3, dd, bx3, ay);
|
|
3002
|
-
vector[y] = dd;
|
|
3003
|
-
d3 = d2;
|
|
3004
|
-
d2 = d1;
|
|
3005
|
-
d1 = d0;
|
|
3006
|
-
d0 = dy;
|
|
3007
|
-
}
|
|
2954
|
+
if (!input) {
|
|
2955
|
+
if (!options.map) {
|
|
2956
|
+
return [];
|
|
2957
|
+
} else {
|
|
2958
|
+
return {};
|
|
3008
2959
|
}
|
|
2960
|
+
}
|
|
3009
2961
|
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
2962
|
+
if (input.headers && input.headers["set-cookie"]) {
|
|
2963
|
+
// fast-path for node.js (which automatically normalizes header names to lower-case
|
|
2964
|
+
input = input.headers["set-cookie"];
|
|
2965
|
+
} else if (input.headers) {
|
|
2966
|
+
// slow-path for other environments - see #25
|
|
2967
|
+
var sch =
|
|
2968
|
+
input.headers[
|
|
2969
|
+
Object.keys(input.headers).find(function (key) {
|
|
2970
|
+
return key.toLowerCase() === "set-cookie";
|
|
2971
|
+
})
|
|
2972
|
+
];
|
|
2973
|
+
// warn if called on a request-like object with a cookie header rather than a set-cookie header - see #34, 36
|
|
2974
|
+
if (!sch && input.headers.cookie && !options.silent) {
|
|
2975
|
+
console.warn(
|
|
2976
|
+
"Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
|
|
2977
|
+
);
|
|
3018
2978
|
}
|
|
2979
|
+
input = sch;
|
|
2980
|
+
}
|
|
2981
|
+
if (!Array.isArray(input)) {
|
|
2982
|
+
input = [input];
|
|
2983
|
+
}
|
|
3019
2984
|
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
2985
|
+
options = options
|
|
2986
|
+
? Object.assign({}, defaultParseOptions, options)
|
|
2987
|
+
: defaultParseOptions;
|
|
3025
2988
|
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
2989
|
+
if (!options.map) {
|
|
2990
|
+
return input.filter(isNonEmptyString).map(function (str) {
|
|
2991
|
+
return parseString(str, options);
|
|
2992
|
+
});
|
|
2993
|
+
} else {
|
|
2994
|
+
var cookies = {};
|
|
2995
|
+
return input.filter(isNonEmptyString).reduce(function (cookies, str) {
|
|
2996
|
+
var cookie = parseString(str, options);
|
|
2997
|
+
cookies[cookie.name] = cookie;
|
|
2998
|
+
return cookies;
|
|
2999
|
+
}, cookies);
|
|
3000
|
+
}
|
|
3032
3001
|
}
|
|
3033
3002
|
|
|
3034
|
-
|
|
3003
|
+
/*
|
|
3004
|
+
Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
|
|
3005
|
+
that are within a single set-cookie field-value, such as in the Expires portion.
|
|
3035
3006
|
|
|
3036
|
-
|
|
3007
|
+
This is uncommon, but explicitly allowed - see https://tools.ietf.org/html/rfc2616#section-4.2
|
|
3008
|
+
Node.js does this for every header *except* set-cookie - see https://github.com/nodejs/node/blob/d5e363b77ebaf1caf67cd7528224b651c86815c1/lib/_http_incoming.js#L128
|
|
3009
|
+
React Native's fetch does this for *every* header, including set-cookie.
|
|
3037
3010
|
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3011
|
+
Based on: https://github.com/google/j2objc/commit/16820fdbc8f76ca0c33472810ce0cb03d20efe25
|
|
3012
|
+
Credits to: https://github.com/tomball for original and https://github.com/chrusart for JavaScript implementation
|
|
3013
|
+
*/
|
|
3014
|
+
function splitCookiesString(cookiesString) {
|
|
3015
|
+
if (Array.isArray(cookiesString)) {
|
|
3016
|
+
return cookiesString;
|
|
3017
|
+
}
|
|
3018
|
+
if (typeof cookiesString !== "string") {
|
|
3019
|
+
return [];
|
|
3020
|
+
}
|
|
3041
3021
|
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
var
|
|
3048
|
-
var
|
|
3049
|
-
var column = position + 1;
|
|
3050
|
-
var match;
|
|
3022
|
+
var cookiesStrings = [];
|
|
3023
|
+
var pos = 0;
|
|
3024
|
+
var start;
|
|
3025
|
+
var ch;
|
|
3026
|
+
var lastComma;
|
|
3027
|
+
var nextStart;
|
|
3028
|
+
var cookiesSeparatorFound;
|
|
3051
3029
|
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3030
|
+
function skipWhitespace() {
|
|
3031
|
+
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
|
|
3032
|
+
pos += 1;
|
|
3033
|
+
}
|
|
3034
|
+
return pos < cookiesString.length;
|
|
3055
3035
|
}
|
|
3056
3036
|
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
column: column
|
|
3060
|
-
};
|
|
3061
|
-
}
|
|
3037
|
+
function notSpecialChar() {
|
|
3038
|
+
ch = cookiesString.charAt(pos);
|
|
3062
3039
|
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
*/
|
|
3040
|
+
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
3041
|
+
}
|
|
3066
3042
|
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
/**
|
|
3071
|
-
* Render a helpful description of the location in the GraphQL Source document.
|
|
3072
|
-
*/
|
|
3043
|
+
while (pos < cookiesString.length) {
|
|
3044
|
+
start = pos;
|
|
3045
|
+
cookiesSeparatorFound = false;
|
|
3073
3046
|
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
var columnOffset = sourceLocation.line === 1 ? firstLineColumnOffset : 0;
|
|
3081
|
-
var columnNum = sourceLocation.column + columnOffset;
|
|
3082
|
-
var locationStr = "".concat(source.name, ":").concat(lineNum, ":").concat(columnNum, "\n");
|
|
3083
|
-
var lines = body.split(/\r\n|[\n\r]/g);
|
|
3084
|
-
var locationLine = lines[lineIndex]; // Special case for minified documents
|
|
3047
|
+
while (skipWhitespace()) {
|
|
3048
|
+
ch = cookiesString.charAt(pos);
|
|
3049
|
+
if (ch === ",") {
|
|
3050
|
+
// ',' is a cookie separator if we have later first '=', not ';' or ','
|
|
3051
|
+
lastComma = pos;
|
|
3052
|
+
pos += 1;
|
|
3085
3053
|
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
var subLineColumnNum = columnNum % 80;
|
|
3089
|
-
var subLines = [];
|
|
3054
|
+
skipWhitespace();
|
|
3055
|
+
nextStart = pos;
|
|
3090
3056
|
|
|
3091
|
-
|
|
3092
|
-
|
|
3057
|
+
while (pos < cookiesString.length && notSpecialChar()) {
|
|
3058
|
+
pos += 1;
|
|
3059
|
+
}
|
|
3060
|
+
|
|
3061
|
+
// currently special character
|
|
3062
|
+
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
3063
|
+
// we found cookies separator
|
|
3064
|
+
cookiesSeparatorFound = true;
|
|
3065
|
+
// pos is inside the next cookie, so back up and return it.
|
|
3066
|
+
pos = nextStart;
|
|
3067
|
+
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
|
3068
|
+
start = pos;
|
|
3069
|
+
} else {
|
|
3070
|
+
// in param ',' or param separator ';',
|
|
3071
|
+
// we continue from that comma
|
|
3072
|
+
pos = lastComma + 1;
|
|
3073
|
+
}
|
|
3074
|
+
} else {
|
|
3075
|
+
pos += 1;
|
|
3076
|
+
}
|
|
3093
3077
|
}
|
|
3094
3078
|
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
}
|
|
3079
|
+
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
|
3080
|
+
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
|
3081
|
+
}
|
|
3098
3082
|
}
|
|
3099
3083
|
|
|
3100
|
-
return
|
|
3101
|
-
["".concat(lineNum - 1), lines[lineIndex - 1]], ["".concat(lineNum), locationLine], ['', whitespace(columnNum - 1) + '^'], ["".concat(lineNum + 1), lines[lineIndex + 1]]]);
|
|
3102
|
-
}
|
|
3103
|
-
|
|
3104
|
-
function printPrefixedLines(lines) {
|
|
3105
|
-
var existingLines = lines.filter(function (_ref) {
|
|
3106
|
-
_ref[0];
|
|
3107
|
-
var line = _ref[1];
|
|
3108
|
-
return line !== undefined;
|
|
3109
|
-
});
|
|
3110
|
-
var padLen = Math.max.apply(Math, existingLines.map(function (_ref2) {
|
|
3111
|
-
var prefix = _ref2[0];
|
|
3112
|
-
return prefix.length;
|
|
3113
|
-
}));
|
|
3114
|
-
return existingLines.map(function (_ref3) {
|
|
3115
|
-
var prefix = _ref3[0],
|
|
3116
|
-
line = _ref3[1];
|
|
3117
|
-
return leftPad(padLen, prefix) + (line ? ' | ' + line : ' |');
|
|
3118
|
-
}).join('\n');
|
|
3119
|
-
}
|
|
3120
|
-
|
|
3121
|
-
function whitespace(len) {
|
|
3122
|
-
return Array(len + 1).join(' ');
|
|
3123
|
-
}
|
|
3124
|
-
|
|
3125
|
-
function leftPad(len, str) {
|
|
3126
|
-
return whitespace(len - str.length) + str;
|
|
3084
|
+
return cookiesStrings;
|
|
3127
3085
|
}
|
|
3128
3086
|
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
3087
|
+
setCookie.exports = parse$1;
|
|
3088
|
+
setCookie.exports.parse = parse$1;
|
|
3089
|
+
setCookie.exports.parseString = parseString;
|
|
3090
|
+
setCookie.exports.splitCookiesString = splitCookiesString;
|
|
3134
3091
|
|
|
3135
|
-
function
|
|
3092
|
+
(function (exports) {
|
|
3093
|
+
var __rest = (commonjsGlobal && commonjsGlobal.__rest) || function (s, e) {
|
|
3094
|
+
var t = {};
|
|
3095
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
3096
|
+
t[p] = s[p];
|
|
3097
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
3098
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
3099
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
3100
|
+
t[p[i]] = s[p[i]];
|
|
3101
|
+
}
|
|
3102
|
+
return t;
|
|
3103
|
+
};
|
|
3104
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3105
|
+
exports.PERSISTENCY_KEY = void 0;
|
|
3106
|
+
const set_cookie_parser_1 = setCookie.exports;
|
|
3107
|
+
exports.PERSISTENCY_KEY = 'MSW_COOKIE_STORE';
|
|
3108
|
+
class CookieStore {
|
|
3109
|
+
constructor() {
|
|
3110
|
+
this.store = new Map();
|
|
3111
|
+
this.supportsPersistency = typeof window !== 'undefined';
|
|
3112
|
+
}
|
|
3113
|
+
/**
|
|
3114
|
+
* Sets the given request cookies into the store.
|
|
3115
|
+
* Respects the `request.credentials` policy.
|
|
3116
|
+
*/
|
|
3117
|
+
add(request, response) {
|
|
3118
|
+
if (request.credentials === 'omit') {
|
|
3119
|
+
return;
|
|
3120
|
+
}
|
|
3121
|
+
const requestUrl = new URL(request.url);
|
|
3122
|
+
const responseCookies = response.headers.get('set-cookie');
|
|
3123
|
+
if (!responseCookies) {
|
|
3124
|
+
return;
|
|
3125
|
+
}
|
|
3126
|
+
const now = Date.now();
|
|
3127
|
+
const parsedResponseCookies = set_cookie_parser_1.parse(responseCookies).map((_a) => {
|
|
3128
|
+
var { maxAge } = _a, cookie = __rest(_a, ["maxAge"]);
|
|
3129
|
+
return (Object.assign(Object.assign({}, cookie), { expires: maxAge === undefined
|
|
3130
|
+
? cookie.expires
|
|
3131
|
+
: new Date(now + maxAge * 1000), maxAge }));
|
|
3132
|
+
});
|
|
3133
|
+
const prevCookies = this.store.get(requestUrl.origin) || new Map();
|
|
3134
|
+
parsedResponseCookies.forEach((cookie) => {
|
|
3135
|
+
this.store.set(requestUrl.origin, prevCookies.set(cookie.name, cookie));
|
|
3136
|
+
});
|
|
3137
|
+
}
|
|
3138
|
+
/**
|
|
3139
|
+
* Returns cookies relevant to the given request
|
|
3140
|
+
* and its `request.credentials` policy.
|
|
3141
|
+
*/
|
|
3142
|
+
get(request) {
|
|
3143
|
+
this.deleteExpiredCookies();
|
|
3144
|
+
const requestUrl = new URL(request.url);
|
|
3145
|
+
const originCookies = this.store.get(requestUrl.origin) || new Map();
|
|
3146
|
+
switch (request.credentials) {
|
|
3147
|
+
case 'include': {
|
|
3148
|
+
const documentCookies = set_cookie_parser_1.parse(document.cookie);
|
|
3149
|
+
documentCookies.forEach((cookie) => {
|
|
3150
|
+
originCookies.set(cookie.name, cookie);
|
|
3151
|
+
});
|
|
3152
|
+
return originCookies;
|
|
3153
|
+
}
|
|
3154
|
+
case 'same-origin': {
|
|
3155
|
+
return originCookies;
|
|
3156
|
+
}
|
|
3157
|
+
default:
|
|
3158
|
+
return new Map();
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
/**
|
|
3162
|
+
* Returns a collection of all stored cookies.
|
|
3163
|
+
*/
|
|
3164
|
+
getAll() {
|
|
3165
|
+
this.deleteExpiredCookies();
|
|
3166
|
+
return this.store;
|
|
3167
|
+
}
|
|
3168
|
+
/**
|
|
3169
|
+
* Deletes all cookies associated with the given request.
|
|
3170
|
+
*/
|
|
3171
|
+
deleteAll(request) {
|
|
3172
|
+
const requestUrl = new URL(request.url);
|
|
3173
|
+
this.store.delete(requestUrl.origin);
|
|
3174
|
+
}
|
|
3175
|
+
/**
|
|
3176
|
+
* Clears the entire cookie store.
|
|
3177
|
+
*/
|
|
3178
|
+
clear() {
|
|
3179
|
+
this.store.clear();
|
|
3180
|
+
}
|
|
3181
|
+
/**
|
|
3182
|
+
* Hydrates the virtual cookie store from the `localStorage`.
|
|
3183
|
+
*/
|
|
3184
|
+
hydrate() {
|
|
3185
|
+
if (!this.supportsPersistency) {
|
|
3186
|
+
return;
|
|
3187
|
+
}
|
|
3188
|
+
const persistedCookies = localStorage.getItem(exports.PERSISTENCY_KEY);
|
|
3189
|
+
if (persistedCookies) {
|
|
3190
|
+
try {
|
|
3191
|
+
const parsedCookies = JSON.parse(persistedCookies);
|
|
3192
|
+
parsedCookies.forEach(([origin, cookies]) => {
|
|
3193
|
+
this.store.set(origin, new Map(cookies.map((_a) => {
|
|
3194
|
+
var [token, _b] = _a, { expires } = _b, cookie = __rest(_b, ["expires"]);
|
|
3195
|
+
return [
|
|
3196
|
+
token,
|
|
3197
|
+
expires === undefined ? cookie : Object.assign(Object.assign({}, cookie), { expires: new Date(expires) })
|
|
3198
|
+
];
|
|
3199
|
+
})));
|
|
3200
|
+
});
|
|
3201
|
+
}
|
|
3202
|
+
catch (error) {
|
|
3203
|
+
console.warn(`
|
|
3204
|
+
[virtual-cookie] Failed to parse a stored cookie from the localStorage (key "${exports.PERSISTENCY_KEY}").
|
|
3136
3205
|
|
|
3137
|
-
|
|
3206
|
+
Stored value:
|
|
3207
|
+
${localStorage.getItem(exports.PERSISTENCY_KEY)}
|
|
3138
3208
|
|
|
3139
|
-
|
|
3209
|
+
Thrown exception:
|
|
3210
|
+
${error}
|
|
3140
3211
|
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3212
|
+
Invalid value has been removed from localStorage to prevent subsequent failed parsing attempts.`);
|
|
3213
|
+
localStorage.removeItem(exports.PERSISTENCY_KEY);
|
|
3214
|
+
}
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3217
|
+
/**
|
|
3218
|
+
* Persists the current virtual cookies into the `localStorage`,
|
|
3219
|
+
* so they are available on the next page load.
|
|
3220
|
+
*/
|
|
3221
|
+
persist() {
|
|
3222
|
+
if (!this.supportsPersistency) {
|
|
3223
|
+
return;
|
|
3224
|
+
}
|
|
3225
|
+
const serializedCookies = Array.from(this.store.entries()).map(([origin, cookies]) => {
|
|
3226
|
+
return [origin, Array.from(cookies.entries())];
|
|
3227
|
+
});
|
|
3228
|
+
localStorage.setItem(exports.PERSISTENCY_KEY, JSON.stringify(serializedCookies));
|
|
3229
|
+
}
|
|
3230
|
+
deleteExpiredCookies() {
|
|
3231
|
+
const now = Date.now();
|
|
3232
|
+
this.store.forEach((originCookies, origin) => {
|
|
3233
|
+
originCookies.forEach(({ expires, name }) => {
|
|
3234
|
+
if (expires !== undefined && expires.getTime() <= now) {
|
|
3235
|
+
originCookies.delete(name);
|
|
3236
|
+
}
|
|
3237
|
+
});
|
|
3238
|
+
if (originCookies.size === 0) {
|
|
3239
|
+
this.store.delete(origin);
|
|
3240
|
+
}
|
|
3241
|
+
});
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
exports.default = new CookieStore();
|
|
3245
|
+
}(CookieStore));
|
|
3152
3246
|
|
|
3153
|
-
|
|
3247
|
+
(function (exports) {
|
|
3248
|
+
var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
3249
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
3250
|
+
};
|
|
3251
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3252
|
+
exports.PERSISTENCY_KEY = exports.store = void 0;
|
|
3253
|
+
var CookieStore_1 = CookieStore;
|
|
3254
|
+
Object.defineProperty(exports, "store", { enumerable: true, get: function () { return __importDefault(CookieStore_1).default; } });
|
|
3255
|
+
Object.defineProperty(exports, "PERSISTENCY_KEY", { enumerable: true, get: function () { return CookieStore_1.PERSISTENCY_KEY; } });
|
|
3256
|
+
}(lib));
|
|
3154
3257
|
|
|
3155
|
-
function
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
*
|
|
3160
|
-
|
|
3161
|
-
|
|
3258
|
+
function getAllCookies() {
|
|
3259
|
+
return parse_1(document.cookie);
|
|
3260
|
+
}
|
|
3261
|
+
/**
|
|
3262
|
+
* Returns relevant document cookies based on the request `credentials` option.
|
|
3263
|
+
*/
|
|
3264
|
+
function getRequestCookies(request) {
|
|
3265
|
+
/**
|
|
3266
|
+
* @note No cookies persist on the document in Node.js: no document.
|
|
3267
|
+
*/
|
|
3268
|
+
if (typeof location === 'undefined') {
|
|
3269
|
+
return {};
|
|
3270
|
+
}
|
|
3271
|
+
switch (request.credentials) {
|
|
3272
|
+
case 'same-origin': {
|
|
3273
|
+
// Return document cookies only when requested a resource
|
|
3274
|
+
// from the same origin as the current document.
|
|
3275
|
+
return location.origin === request.url.origin ? getAllCookies() : {};
|
|
3276
|
+
}
|
|
3277
|
+
case 'include': {
|
|
3278
|
+
// Return all document cookies.
|
|
3279
|
+
return getAllCookies();
|
|
3280
|
+
}
|
|
3281
|
+
default: {
|
|
3282
|
+
return {};
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3162
3286
|
|
|
3163
|
-
|
|
3164
|
-
|
|
3287
|
+
function setRequestCookies(request) {
|
|
3288
|
+
var _a;
|
|
3289
|
+
lib.store.hydrate();
|
|
3290
|
+
request.cookies = Object.assign(Object.assign({}, getRequestCookies(request)), Array.from((_a = lib.store.get(Object.assign(Object.assign({}, request), { url: request.url.toString() }))) === null || _a === void 0 ? void 0 : _a.entries()).reduce((cookies, [name, { value }]) => Object.assign(cookies, { [name]: value }), {}));
|
|
3291
|
+
request.headers.set('cookie', Object.entries(request.cookies)
|
|
3292
|
+
.map(([name, value]) => `${name}=${value}`)
|
|
3293
|
+
.join('; '));
|
|
3294
|
+
}
|
|
3165
3295
|
|
|
3166
|
-
|
|
3296
|
+
/**
|
|
3297
|
+
* Converts a given isomorphic request to a `MockedRequest` instance.
|
|
3298
|
+
*/
|
|
3299
|
+
function parseIsomorphicRequest(request) {
|
|
3300
|
+
const requestId = uuidv4();
|
|
3301
|
+
request.headers.set('x-msw-request-id', requestId);
|
|
3302
|
+
const mockedRequest = {
|
|
3303
|
+
id: requestId,
|
|
3304
|
+
url: request.url,
|
|
3305
|
+
method: request.method,
|
|
3306
|
+
body: parseBody(request.body, request.headers),
|
|
3307
|
+
headers: request.headers,
|
|
3308
|
+
cookies: {},
|
|
3309
|
+
redirect: 'manual',
|
|
3310
|
+
referrer: '',
|
|
3311
|
+
keepalive: false,
|
|
3312
|
+
cache: 'default',
|
|
3313
|
+
mode: 'cors',
|
|
3314
|
+
referrerPolicy: 'no-referrer',
|
|
3315
|
+
integrity: '',
|
|
3316
|
+
destination: 'document',
|
|
3317
|
+
bodyUsed: false,
|
|
3318
|
+
credentials: 'same-origin',
|
|
3319
|
+
};
|
|
3320
|
+
// Set mocked request cookies from the `cookie` header of the original request.
|
|
3321
|
+
// No need to take `credentials` into account, because in Node.js requests are intercepted
|
|
3322
|
+
// _after_ they happen. Request issuer should have already taken care of sending relevant cookies.
|
|
3323
|
+
// Unlike browser, where interception is on the worker level, _before_ the request happens.
|
|
3324
|
+
const requestCookiesString = request.headers.get('cookie');
|
|
3325
|
+
// Attach all the cookies from the virtual cookie store.
|
|
3326
|
+
setRequestCookies(mockedRequest);
|
|
3327
|
+
const requestCookies = requestCookiesString
|
|
3328
|
+
? parse_1(requestCookiesString)
|
|
3329
|
+
: {};
|
|
3330
|
+
// Merge both direct request cookies and the cookies inherited
|
|
3331
|
+
// from other same-origin requests in the cookie store.
|
|
3332
|
+
mockedRequest.cookies = Object.assign(Object.assign({}, mockedRequest.cookies), requestCookies);
|
|
3333
|
+
return mockedRequest;
|
|
3334
|
+
}
|
|
3167
3335
|
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3336
|
+
/**
|
|
3337
|
+
* Returns a mocked response for a given request using following request handlers.
|
|
3338
|
+
*/
|
|
3339
|
+
const getResponse = (request, handlers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
3340
|
+
const relevantHandlers = handlers.filter((handler) => {
|
|
3341
|
+
return handler.test(request);
|
|
3342
|
+
});
|
|
3343
|
+
if (relevantHandlers.length === 0) {
|
|
3344
|
+
return {
|
|
3345
|
+
handler: undefined,
|
|
3346
|
+
response: undefined,
|
|
3347
|
+
};
|
|
3348
|
+
}
|
|
3349
|
+
const result = yield relevantHandlers.reduce((acc, handler) => __awaiter(void 0, void 0, void 0, function* () {
|
|
3350
|
+
const previousResults = yield acc;
|
|
3351
|
+
if (!!(previousResults === null || previousResults === void 0 ? void 0 : previousResults.response)) {
|
|
3352
|
+
return acc;
|
|
3353
|
+
}
|
|
3354
|
+
const result = yield handler.run(request);
|
|
3355
|
+
if (result === null || result.handler.shouldSkip) {
|
|
3356
|
+
return null;
|
|
3357
|
+
}
|
|
3358
|
+
if (!result.response) {
|
|
3359
|
+
return {
|
|
3360
|
+
request: result.request,
|
|
3361
|
+
handler: result.handler,
|
|
3362
|
+
response: undefined,
|
|
3363
|
+
parsedResult: result.parsedResult,
|
|
3364
|
+
};
|
|
3365
|
+
}
|
|
3366
|
+
if (result.response.once) {
|
|
3367
|
+
handler.markAsSkipped(true);
|
|
3368
|
+
}
|
|
3369
|
+
return result;
|
|
3370
|
+
}), Promise.resolve(null));
|
|
3371
|
+
// Although reducing a list of relevant request handlers, it's possible
|
|
3372
|
+
// that in the end there will be no handler associted with the request
|
|
3373
|
+
// (i.e. if relevant handlers are fall-through).
|
|
3374
|
+
if (!result) {
|
|
3375
|
+
return {
|
|
3376
|
+
handler: undefined,
|
|
3377
|
+
response: undefined,
|
|
3378
|
+
};
|
|
3379
|
+
}
|
|
3380
|
+
return {
|
|
3381
|
+
handler: result.handler,
|
|
3382
|
+
publicRequest: result.request,
|
|
3383
|
+
parsedRequest: result.parsedResult,
|
|
3384
|
+
response: result.response,
|
|
3385
|
+
};
|
|
3386
|
+
});
|
|
3175
3387
|
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3388
|
+
var jsLevenshtein = (function()
|
|
3389
|
+
{
|
|
3390
|
+
function _min(d0, d1, d2, bx, ay)
|
|
3391
|
+
{
|
|
3392
|
+
return d0 < d1 || d2 < d1
|
|
3393
|
+
? d0 > d2
|
|
3394
|
+
? d2 + 1
|
|
3395
|
+
: d0 + 1
|
|
3396
|
+
: bx === ay
|
|
3397
|
+
? d1
|
|
3398
|
+
: d1 + 1;
|
|
3399
|
+
}
|
|
3186
3400
|
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
*/
|
|
3401
|
+
return function(a, b)
|
|
3402
|
+
{
|
|
3403
|
+
if (a === b) {
|
|
3404
|
+
return 0;
|
|
3405
|
+
}
|
|
3193
3406
|
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3407
|
+
if (a.length > b.length) {
|
|
3408
|
+
var tmp = a;
|
|
3409
|
+
a = b;
|
|
3410
|
+
b = tmp;
|
|
3411
|
+
}
|
|
3197
3412
|
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
*
|
|
3201
|
-
* Note that if this Error represents more than one node, the source may not
|
|
3202
|
-
* represent nodes after the first node.
|
|
3203
|
-
*/
|
|
3413
|
+
var la = a.length;
|
|
3414
|
+
var lb = b.length;
|
|
3204
3415
|
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3416
|
+
while (la > 0 && (a.charCodeAt(la - 1) === b.charCodeAt(lb - 1))) {
|
|
3417
|
+
la--;
|
|
3418
|
+
lb--;
|
|
3419
|
+
}
|
|
3209
3420
|
|
|
3210
|
-
|
|
3211
|
-
* The original error thrown from a field resolver during execution.
|
|
3212
|
-
*/
|
|
3421
|
+
var offset = 0;
|
|
3213
3422
|
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
function GraphQLError(message, nodes, source, positions, path, originalError, extensions) {
|
|
3218
|
-
var _locations2, _source2, _positions2, _extensions2;
|
|
3423
|
+
while (offset < la && (a.charCodeAt(offset) === b.charCodeAt(offset))) {
|
|
3424
|
+
offset++;
|
|
3425
|
+
}
|
|
3219
3426
|
|
|
3220
|
-
|
|
3427
|
+
la -= offset;
|
|
3428
|
+
lb -= offset;
|
|
3221
3429
|
|
|
3222
|
-
|
|
3430
|
+
if (la === 0 || lb < 3) {
|
|
3431
|
+
return lb;
|
|
3432
|
+
}
|
|
3223
3433
|
|
|
3224
|
-
|
|
3434
|
+
var x = 0;
|
|
3435
|
+
var y;
|
|
3436
|
+
var d0;
|
|
3437
|
+
var d1;
|
|
3438
|
+
var d2;
|
|
3439
|
+
var d3;
|
|
3440
|
+
var dd;
|
|
3441
|
+
var dy;
|
|
3442
|
+
var ay;
|
|
3443
|
+
var bx0;
|
|
3444
|
+
var bx1;
|
|
3445
|
+
var bx2;
|
|
3446
|
+
var bx3;
|
|
3225
3447
|
|
|
3226
|
-
var
|
|
3448
|
+
var vector = [];
|
|
3227
3449
|
|
|
3450
|
+
for (y = 0; y < la; y++) {
|
|
3451
|
+
vector.push(y + 1);
|
|
3452
|
+
vector.push(a.charCodeAt(offset + y));
|
|
3453
|
+
}
|
|
3228
3454
|
|
|
3229
|
-
var
|
|
3455
|
+
var len = vector.length - 1;
|
|
3456
|
+
|
|
3457
|
+
for (; x < lb - 3;) {
|
|
3458
|
+
bx0 = b.charCodeAt(offset + (d0 = x));
|
|
3459
|
+
bx1 = b.charCodeAt(offset + (d1 = x + 1));
|
|
3460
|
+
bx2 = b.charCodeAt(offset + (d2 = x + 2));
|
|
3461
|
+
bx3 = b.charCodeAt(offset + (d3 = x + 3));
|
|
3462
|
+
dd = (x += 4);
|
|
3463
|
+
for (y = 0; y < len; y += 2) {
|
|
3464
|
+
dy = vector[y];
|
|
3465
|
+
ay = vector[y + 1];
|
|
3466
|
+
d0 = _min(dy, d0, d1, bx0, ay);
|
|
3467
|
+
d1 = _min(d0, d1, d2, bx1, ay);
|
|
3468
|
+
d2 = _min(d1, d2, d3, bx2, ay);
|
|
3469
|
+
dd = _min(d2, d3, dd, bx3, ay);
|
|
3470
|
+
vector[y] = dd;
|
|
3471
|
+
d3 = d2;
|
|
3472
|
+
d2 = d1;
|
|
3473
|
+
d1 = d0;
|
|
3474
|
+
d0 = dy;
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3477
|
+
|
|
3478
|
+
for (; x < lb;) {
|
|
3479
|
+
bx0 = b.charCodeAt(offset + (d0 = x));
|
|
3480
|
+
dd = ++x;
|
|
3481
|
+
for (y = 0; y < len; y += 2) {
|
|
3482
|
+
dy = vector[y];
|
|
3483
|
+
vector[y] = dd = _min(dy, d0, dd, bx0, vector[y + 1]);
|
|
3484
|
+
d0 = dy;
|
|
3485
|
+
}
|
|
3486
|
+
}
|
|
3487
|
+
|
|
3488
|
+
return dd;
|
|
3489
|
+
};
|
|
3490
|
+
})();
|
|
3491
|
+
|
|
3492
|
+
function _typeof$2(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$2 = function _typeof(obj) { return typeof obj; }; } else { _typeof$2 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$2(obj); }
|
|
3493
|
+
|
|
3494
|
+
/**
|
|
3495
|
+
* Return true if `value` is object-like. A value is object-like if it's not
|
|
3496
|
+
* `null` and has a `typeof` result of "object".
|
|
3497
|
+
*/
|
|
3498
|
+
function isObjectLike(value) {
|
|
3499
|
+
return _typeof$2(value) == 'object' && value !== null;
|
|
3500
|
+
}
|
|
3501
|
+
|
|
3502
|
+
// In ES2015 (or a polyfilled) environment, this will be Symbol.iterator
|
|
3503
|
+
|
|
3504
|
+
var SYMBOL_TO_STRING_TAG = typeof Symbol === 'function' && Symbol.toStringTag != null ? Symbol.toStringTag : '@@toStringTag';
|
|
3505
|
+
|
|
3506
|
+
/**
|
|
3507
|
+
* Represents a location in a Source.
|
|
3508
|
+
*/
|
|
3509
|
+
|
|
3510
|
+
/**
|
|
3511
|
+
* Takes a Source and a UTF-8 character offset, and returns the corresponding
|
|
3512
|
+
* line and column as a SourceLocation.
|
|
3513
|
+
*/
|
|
3514
|
+
function getLocation(source, position) {
|
|
3515
|
+
var lineRegexp = /\r\n|[\n\r]/g;
|
|
3516
|
+
var line = 1;
|
|
3517
|
+
var column = position + 1;
|
|
3518
|
+
var match;
|
|
3519
|
+
|
|
3520
|
+
while ((match = lineRegexp.exec(source.body)) && match.index < position) {
|
|
3521
|
+
line += 1;
|
|
3522
|
+
column = position + 1 - (match.index + match[0].length);
|
|
3523
|
+
}
|
|
3524
|
+
|
|
3525
|
+
return {
|
|
3526
|
+
line: line,
|
|
3527
|
+
column: column
|
|
3528
|
+
};
|
|
3529
|
+
}
|
|
3530
|
+
|
|
3531
|
+
/**
|
|
3532
|
+
* Render a helpful description of the location in the GraphQL Source document.
|
|
3533
|
+
*/
|
|
3534
|
+
|
|
3535
|
+
function printLocation(location) {
|
|
3536
|
+
return printSourceLocation(location.source, getLocation(location.source, location.start));
|
|
3537
|
+
}
|
|
3538
|
+
/**
|
|
3539
|
+
* Render a helpful description of the location in the GraphQL Source document.
|
|
3540
|
+
*/
|
|
3541
|
+
|
|
3542
|
+
function printSourceLocation(source, sourceLocation) {
|
|
3543
|
+
var firstLineColumnOffset = source.locationOffset.column - 1;
|
|
3544
|
+
var body = whitespace(firstLineColumnOffset) + source.body;
|
|
3545
|
+
var lineIndex = sourceLocation.line - 1;
|
|
3546
|
+
var lineOffset = source.locationOffset.line - 1;
|
|
3547
|
+
var lineNum = sourceLocation.line + lineOffset;
|
|
3548
|
+
var columnOffset = sourceLocation.line === 1 ? firstLineColumnOffset : 0;
|
|
3549
|
+
var columnNum = sourceLocation.column + columnOffset;
|
|
3550
|
+
var locationStr = "".concat(source.name, ":").concat(lineNum, ":").concat(columnNum, "\n");
|
|
3551
|
+
var lines = body.split(/\r\n|[\n\r]/g);
|
|
3552
|
+
var locationLine = lines[lineIndex]; // Special case for minified documents
|
|
3553
|
+
|
|
3554
|
+
if (locationLine.length > 120) {
|
|
3555
|
+
var subLineIndex = Math.floor(columnNum / 80);
|
|
3556
|
+
var subLineColumnNum = columnNum % 80;
|
|
3557
|
+
var subLines = [];
|
|
3558
|
+
|
|
3559
|
+
for (var i = 0; i < locationLine.length; i += 80) {
|
|
3560
|
+
subLines.push(locationLine.slice(i, i + 80));
|
|
3561
|
+
}
|
|
3562
|
+
|
|
3563
|
+
return locationStr + printPrefixedLines([["".concat(lineNum), subLines[0]]].concat(subLines.slice(1, subLineIndex + 1).map(function (subLine) {
|
|
3564
|
+
return ['', subLine];
|
|
3565
|
+
}), [[' ', whitespace(subLineColumnNum - 1) + '^'], ['', subLines[subLineIndex + 1]]]));
|
|
3566
|
+
}
|
|
3567
|
+
|
|
3568
|
+
return locationStr + printPrefixedLines([// Lines specified like this: ["prefix", "string"],
|
|
3569
|
+
["".concat(lineNum - 1), lines[lineIndex - 1]], ["".concat(lineNum), locationLine], ['', whitespace(columnNum - 1) + '^'], ["".concat(lineNum + 1), lines[lineIndex + 1]]]);
|
|
3570
|
+
}
|
|
3571
|
+
|
|
3572
|
+
function printPrefixedLines(lines) {
|
|
3573
|
+
var existingLines = lines.filter(function (_ref) {
|
|
3574
|
+
_ref[0];
|
|
3575
|
+
var line = _ref[1];
|
|
3576
|
+
return line !== undefined;
|
|
3577
|
+
});
|
|
3578
|
+
var padLen = Math.max.apply(Math, existingLines.map(function (_ref2) {
|
|
3579
|
+
var prefix = _ref2[0];
|
|
3580
|
+
return prefix.length;
|
|
3581
|
+
}));
|
|
3582
|
+
return existingLines.map(function (_ref3) {
|
|
3583
|
+
var prefix = _ref3[0],
|
|
3584
|
+
line = _ref3[1];
|
|
3585
|
+
return leftPad(padLen, prefix) + (line ? ' | ' + line : ' |');
|
|
3586
|
+
}).join('\n');
|
|
3587
|
+
}
|
|
3588
|
+
|
|
3589
|
+
function whitespace(len) {
|
|
3590
|
+
return Array(len + 1).join(' ');
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3593
|
+
function leftPad(len, str) {
|
|
3594
|
+
return whitespace(len - str.length) + str;
|
|
3595
|
+
}
|
|
3596
|
+
|
|
3597
|
+
function _typeof$1(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$1 = function _typeof(obj) { return typeof obj; }; } else { _typeof$1 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$1(obj); }
|
|
3598
|
+
|
|
3599
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3600
|
+
|
|
3601
|
+
function _defineProperties$1(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
3602
|
+
|
|
3603
|
+
function _createClass$1(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1(Constructor, staticProps); return Constructor; }
|
|
3604
|
+
|
|
3605
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
3606
|
+
|
|
3607
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
3608
|
+
|
|
3609
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof$1(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
3610
|
+
|
|
3611
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
3612
|
+
|
|
3613
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
3614
|
+
|
|
3615
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
3616
|
+
|
|
3617
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
3618
|
+
|
|
3619
|
+
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
3620
|
+
|
|
3621
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
3622
|
+
|
|
3623
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
3624
|
+
/**
|
|
3625
|
+
* A GraphQLError describes an Error found during the parse, validate, or
|
|
3626
|
+
* execute phases of performing a GraphQL operation. In addition to a message
|
|
3627
|
+
* and stack trace, it also includes information about the locations in a
|
|
3628
|
+
* GraphQL document and/or execution result that correspond to the Error.
|
|
3629
|
+
*/
|
|
3630
|
+
|
|
3631
|
+
var GraphQLError = /*#__PURE__*/function (_Error) {
|
|
3632
|
+
_inherits(GraphQLError, _Error);
|
|
3633
|
+
|
|
3634
|
+
var _super = _createSuper(GraphQLError);
|
|
3635
|
+
|
|
3636
|
+
/**
|
|
3637
|
+
* A message describing the Error for debugging purposes.
|
|
3638
|
+
*
|
|
3639
|
+
* Enumerable, and appears in the result of JSON.stringify().
|
|
3640
|
+
*
|
|
3641
|
+
* Note: should be treated as readonly, despite invariant usage.
|
|
3642
|
+
*/
|
|
3643
|
+
|
|
3644
|
+
/**
|
|
3645
|
+
* An array of { line, column } locations within the source GraphQL document
|
|
3646
|
+
* which correspond to this error.
|
|
3647
|
+
*
|
|
3648
|
+
* Errors during validation often contain multiple locations, for example to
|
|
3649
|
+
* point out two things with the same name. Errors during execution include a
|
|
3650
|
+
* single location, the field which produced the error.
|
|
3651
|
+
*
|
|
3652
|
+
* Enumerable, and appears in the result of JSON.stringify().
|
|
3653
|
+
*/
|
|
3654
|
+
|
|
3655
|
+
/**
|
|
3656
|
+
* An array describing the JSON-path into the execution response which
|
|
3657
|
+
* corresponds to this error. Only included for errors during execution.
|
|
3658
|
+
*
|
|
3659
|
+
* Enumerable, and appears in the result of JSON.stringify().
|
|
3660
|
+
*/
|
|
3661
|
+
|
|
3662
|
+
/**
|
|
3663
|
+
* An array of GraphQL AST Nodes corresponding to this error.
|
|
3664
|
+
*/
|
|
3665
|
+
|
|
3666
|
+
/**
|
|
3667
|
+
* The source GraphQL document for the first location of this error.
|
|
3668
|
+
*
|
|
3669
|
+
* Note that if this Error represents more than one node, the source may not
|
|
3670
|
+
* represent nodes after the first node.
|
|
3671
|
+
*/
|
|
3672
|
+
|
|
3673
|
+
/**
|
|
3674
|
+
* An array of character offsets within the source GraphQL document
|
|
3675
|
+
* which correspond to this error.
|
|
3676
|
+
*/
|
|
3677
|
+
|
|
3678
|
+
/**
|
|
3679
|
+
* The original error thrown from a field resolver during execution.
|
|
3680
|
+
*/
|
|
3681
|
+
|
|
3682
|
+
/**
|
|
3683
|
+
* Extension fields to add to the formatted error.
|
|
3684
|
+
*/
|
|
3685
|
+
function GraphQLError(message, nodes, source, positions, path, originalError, extensions) {
|
|
3686
|
+
var _locations2, _source2, _positions2, _extensions2;
|
|
3687
|
+
|
|
3688
|
+
var _this;
|
|
3689
|
+
|
|
3690
|
+
_classCallCheck(this, GraphQLError);
|
|
3691
|
+
|
|
3692
|
+
_this = _super.call(this, message); // Compute list of blame nodes.
|
|
3693
|
+
|
|
3694
|
+
var _nodes = Array.isArray(nodes) ? nodes.length !== 0 ? nodes : undefined : nodes ? [nodes] : undefined; // Compute locations in the source for the given nodes/positions.
|
|
3695
|
+
|
|
3696
|
+
|
|
3697
|
+
var _source = source;
|
|
3230
3698
|
|
|
3231
3699
|
if (!_source && _nodes) {
|
|
3232
3700
|
var _nodes$0$loc;
|
|
@@ -3352,7 +3820,7 @@ var GraphQLError = /*#__PURE__*/function (_Error) {
|
|
|
3352
3820
|
return _this;
|
|
3353
3821
|
}
|
|
3354
3822
|
|
|
3355
|
-
_createClass(GraphQLError, [{
|
|
3823
|
+
_createClass$1(GraphQLError, [{
|
|
3356
3824
|
key: "toString",
|
|
3357
3825
|
value: function toString() {
|
|
3358
3826
|
return printError(this);
|
|
@@ -3633,7 +4101,7 @@ var TokenKind = Object.freeze({
|
|
|
3633
4101
|
* The enum type representing the token kinds values.
|
|
3634
4102
|
*/
|
|
3635
4103
|
|
|
3636
|
-
function _typeof
|
|
4104
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
3637
4105
|
var MAX_ARRAY_LENGTH = 10;
|
|
3638
4106
|
var MAX_RECURSIVE_DEPTH = 2;
|
|
3639
4107
|
/**
|
|
@@ -3645,7 +4113,7 @@ function inspect(value) {
|
|
|
3645
4113
|
}
|
|
3646
4114
|
|
|
3647
4115
|
function formatValue(value, seenValues) {
|
|
3648
|
-
switch (_typeof
|
|
4116
|
+
switch (_typeof(value)) {
|
|
3649
4117
|
case 'string':
|
|
3650
4118
|
return JSON.stringify(value);
|
|
3651
4119
|
|
|
@@ -3791,9 +4259,9 @@ function instanceOf(value, constructor) {
|
|
|
3791
4259
|
return false;
|
|
3792
4260
|
};
|
|
3793
4261
|
|
|
3794
|
-
function _defineProperties
|
|
4262
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
3795
4263
|
|
|
3796
|
-
function _createClass
|
|
4264
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
3797
4265
|
|
|
3798
4266
|
/**
|
|
3799
4267
|
* A representation of source input to GraphQL. The `name` and `locationOffset` parameters are
|
|
@@ -3818,7 +4286,7 @@ var Source = /*#__PURE__*/function () {
|
|
|
3818
4286
|
} // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
|
|
3819
4287
|
|
|
3820
4288
|
|
|
3821
|
-
_createClass
|
|
4289
|
+
_createClass(Source, [{
|
|
3822
4290
|
key: SYMBOL_TO_STRING_TAG,
|
|
3823
4291
|
get: function get() {
|
|
3824
4292
|
return 'Source';
|
|
@@ -4644,7 +5112,7 @@ function isNameStart(code) {
|
|
|
4644
5112
|
* Given a GraphQL source, parses it into a Document.
|
|
4645
5113
|
* Throws GraphQLError if a syntax error is encountered.
|
|
4646
5114
|
*/
|
|
4647
|
-
function parse
|
|
5115
|
+
function parse(source, options) {
|
|
4648
5116
|
var parser = new Parser(source, options);
|
|
4649
5117
|
return parser.parseDocument();
|
|
4650
5118
|
}
|
|
@@ -6158,7 +6626,7 @@ const getPublicUrlFromRequest = (request) => {
|
|
|
6158
6626
|
function parseQuery(query) {
|
|
6159
6627
|
var _a;
|
|
6160
6628
|
try {
|
|
6161
|
-
const ast = parse
|
|
6629
|
+
const ast = parse(query);
|
|
6162
6630
|
const operationDef = ast.definitions.find((def) => {
|
|
6163
6631
|
return def.kind === 'OperationDefinition';
|
|
6164
6632
|
});
|
|
@@ -6245,11 +6713,7 @@ function parseGraphQLRequest(request) {
|
|
|
6245
6713
|
const parsedResult = parseQuery(query);
|
|
6246
6714
|
if (parsedResult instanceof Error) {
|
|
6247
6715
|
const requestPublicUrl = getPublicUrlFromRequest(request);
|
|
6248
|
-
|
|
6249
|
-
// We may consider getting the parsing error and propagating it to the user.
|
|
6250
|
-
console.error(`[MSW] Failed to intercept a GraphQL request to "${request.method} ${requestPublicUrl}": cannot parse query. See the error message from the parser below.`);
|
|
6251
|
-
console.error(parsedResult);
|
|
6252
|
-
return undefined;
|
|
6716
|
+
throw new Error(`[MSW] Failed to intercept a GraphQL request to "${request.method} ${requestPublicUrl}": cannot parse query. See the error message from the parser below.\n\n${parsedResult}`);
|
|
6253
6717
|
}
|
|
6254
6718
|
return {
|
|
6255
6719
|
operationType: parsedResult.operationType,
|
|
@@ -6620,7 +7084,7 @@ function prepareRequest(request) {
|
|
|
6620
7084
|
* Formats a mocked response for introspection in browser's console.
|
|
6621
7085
|
*/
|
|
6622
7086
|
function prepareResponse(res) {
|
|
6623
|
-
const responseHeaders = lib$1.
|
|
7087
|
+
const responseHeaders = lib$1.objectToHeaders(res.headers);
|
|
6624
7088
|
return Object.assign(Object.assign({}, res), {
|
|
6625
7089
|
// Parse a response JSON body for preview in the logs
|
|
6626
7090
|
body: parseBody(res.body, responseHeaders) });
|
|
@@ -6665,9 +7129,10 @@ const match = (path, url) => {
|
|
|
6665
7129
|
};
|
|
6666
7130
|
};
|
|
6667
7131
|
|
|
6668
|
-
var
|
|
6669
|
-
|
|
6670
|
-
|
|
7132
|
+
var getCleanUrl$1 = {};
|
|
7133
|
+
|
|
7134
|
+
Object.defineProperty(getCleanUrl$1, "__esModule", { value: true });
|
|
7135
|
+
var getCleanUrl_2 = getCleanUrl$1.getCleanUrl = void 0;
|
|
6671
7136
|
/**
|
|
6672
7137
|
* Removes query parameters and hashes from a given URL.
|
|
6673
7138
|
*/
|
|
@@ -6675,9 +7140,7 @@ function getCleanUrl(url, isAbsolute) {
|
|
|
6675
7140
|
if (isAbsolute === void 0) { isAbsolute = true; }
|
|
6676
7141
|
return [isAbsolute && url.origin, url.pathname].filter(Boolean).join('');
|
|
6677
7142
|
}
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
});
|
|
7143
|
+
getCleanUrl_2 = getCleanUrl$1.getCleanUrl = getCleanUrl;
|
|
6681
7144
|
|
|
6682
7145
|
/**
|
|
6683
7146
|
* Returns an absolute URL based on the given relative URL, if possible.
|
|
@@ -6718,7 +7181,7 @@ function getUrlByMask(mask) {
|
|
|
6718
7181
|
|
|
6719
7182
|
function getCleanMask(resolvedMask) {
|
|
6720
7183
|
return resolvedMask instanceof URL
|
|
6721
|
-
?
|
|
7184
|
+
? getCleanUrl_2(resolvedMask)
|
|
6722
7185
|
: resolvedMask instanceof RegExp
|
|
6723
7186
|
? resolvedMask
|
|
6724
7187
|
: getAbsoluteUrl(resolvedMask);
|
|
@@ -6731,7 +7194,7 @@ function getCleanMask(resolvedMask) {
|
|
|
6731
7194
|
function matchRequestUrl(url, mask) {
|
|
6732
7195
|
const resolvedMask = getUrlByMask(mask);
|
|
6733
7196
|
const cleanMask = getCleanMask(resolvedMask);
|
|
6734
|
-
const cleanRequestUrl =
|
|
7197
|
+
const cleanRequestUrl = getCleanUrl_2(url);
|
|
6735
7198
|
return match(cleanMask, cleanRequestUrl);
|
|
6736
7199
|
}
|
|
6737
7200
|
|
|
@@ -6811,10 +7274,20 @@ function getCallFrame() {
|
|
|
6811
7274
|
return declarationPath;
|
|
6812
7275
|
}
|
|
6813
7276
|
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6817
|
-
|
|
7277
|
+
/**
|
|
7278
|
+
* Determines if the given function is an iterator.
|
|
7279
|
+
*/
|
|
7280
|
+
function isIterable(fn) {
|
|
7281
|
+
if (!fn) {
|
|
7282
|
+
return false;
|
|
7283
|
+
}
|
|
7284
|
+
return typeof fn[Symbol.iterator] == 'function';
|
|
7285
|
+
}
|
|
7286
|
+
|
|
7287
|
+
const defaultContext = {
|
|
7288
|
+
status,
|
|
7289
|
+
set,
|
|
7290
|
+
delay,
|
|
6818
7291
|
fetch,
|
|
6819
7292
|
};
|
|
6820
7293
|
class RequestHandler {
|
|
@@ -6829,7 +7302,7 @@ class RequestHandler {
|
|
|
6829
7302
|
* Parse the captured request to extract additional information from it.
|
|
6830
7303
|
* Parsed result is then exposed to other methods of this request handler.
|
|
6831
7304
|
*/
|
|
6832
|
-
parse(
|
|
7305
|
+
parse(_request) {
|
|
6833
7306
|
return null;
|
|
6834
7307
|
}
|
|
6835
7308
|
/**
|
|
@@ -6842,7 +7315,7 @@ class RequestHandler {
|
|
|
6842
7315
|
* Derive the publicly exposed request (`req`) instance of the response resolver
|
|
6843
7316
|
* from the captured request and its parsed result.
|
|
6844
7317
|
*/
|
|
6845
|
-
getPublicRequest(request,
|
|
7318
|
+
getPublicRequest(request, _parsedResult) {
|
|
6846
7319
|
return request;
|
|
6847
7320
|
}
|
|
6848
7321
|
markAsSkipped(shouldSkip = true) {
|
|
@@ -6863,10 +7336,33 @@ class RequestHandler {
|
|
|
6863
7336
|
return null;
|
|
6864
7337
|
}
|
|
6865
7338
|
const publicRequest = this.getPublicRequest(request, parsedResult);
|
|
6866
|
-
|
|
7339
|
+
// Create a response extraction wrapper around the resolver
|
|
7340
|
+
// since it can be both an async function and a generator.
|
|
7341
|
+
const executeResolver = this.wrapResolver(this.resolver);
|
|
7342
|
+
const mockedResponse = yield executeResolver(publicRequest, response, this.ctx);
|
|
6867
7343
|
return this.createExecutionResult(parsedResult, publicRequest, mockedResponse);
|
|
6868
7344
|
});
|
|
6869
7345
|
}
|
|
7346
|
+
wrapResolver(resolver) {
|
|
7347
|
+
return (req, res, ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
7348
|
+
const result = this.resolverGenerator || (yield resolver(req, res, ctx));
|
|
7349
|
+
if (isIterable(result)) {
|
|
7350
|
+
const { value, done } = result[Symbol.iterator]().next();
|
|
7351
|
+
const nextResponse = yield value;
|
|
7352
|
+
// If the generator is done and there is no next value,
|
|
7353
|
+
// return the previous generator's value.
|
|
7354
|
+
if (!nextResponse && done) {
|
|
7355
|
+
return this.resolverGeneratorResult;
|
|
7356
|
+
}
|
|
7357
|
+
if (!this.resolverGenerator) {
|
|
7358
|
+
this.resolverGenerator = result;
|
|
7359
|
+
}
|
|
7360
|
+
this.resolverGeneratorResult = nextResponse;
|
|
7361
|
+
return nextResponse;
|
|
7362
|
+
}
|
|
7363
|
+
return result;
|
|
7364
|
+
});
|
|
7365
|
+
}
|
|
6870
7366
|
createExecutionResult(parsedResult, request, response) {
|
|
6871
7367
|
return {
|
|
6872
7368
|
handler: this,
|
|
@@ -6940,7 +7436,7 @@ ${queryParams
|
|
|
6940
7436
|
return matchRequestUrl(request.url, this.info.mask);
|
|
6941
7437
|
}
|
|
6942
7438
|
getPublicRequest(request, parsedResult) {
|
|
6943
|
-
return Object.assign(Object.assign({}, request), { params: parsedResult.params });
|
|
7439
|
+
return Object.assign(Object.assign({}, request), { params: parsedResult.params || {} });
|
|
6944
7440
|
}
|
|
6945
7441
|
predicate(request, parsedResult) {
|
|
6946
7442
|
return (isStringEqual(this.info.method, request.method) && parsedResult.matches);
|
|
@@ -6957,621 +7453,275 @@ ${queryParams
|
|
|
6957
7453
|
});
|
|
6958
7454
|
console.log('Response', loggedResponse);
|
|
6959
7455
|
console.groupEnd();
|
|
6960
|
-
}
|
|
6961
|
-
}
|
|
6962
|
-
|
|
6963
|
-
const graphqlContext = {
|
|
6964
|
-
set,
|
|
6965
|
-
status,
|
|
6966
|
-
delay,
|
|
6967
|
-
fetch,
|
|
6968
|
-
data,
|
|
6969
|
-
errors,
|
|
6970
|
-
};
|
|
6971
|
-
class GraphQLHandler extends RequestHandler {
|
|
6972
|
-
constructor(operationType, operationName, endpoint, resolver) {
|
|
6973
|
-
const header = operationType === 'all'
|
|
6974
|
-
? `${operationType} (origin: ${endpoint.toString()})`
|
|
6975
|
-
: `${operationType} ${operationName} (origin: ${endpoint.toString()})`;
|
|
6976
|
-
super({
|
|
6977
|
-
info: {
|
|
6978
|
-
header,
|
|
6979
|
-
operationType,
|
|
6980
|
-
operationName,
|
|
6981
|
-
},
|
|
6982
|
-
ctx: graphqlContext,
|
|
6983
|
-
resolver,
|
|
6984
|
-
});
|
|
6985
|
-
this.endpoint = endpoint;
|
|
6986
|
-
}
|
|
6987
|
-
parse(request) {
|
|
6988
|
-
return parseGraphQLRequest(request);
|
|
6989
|
-
}
|
|
6990
|
-
getPublicRequest(request, parsedResult) {
|
|
6991
|
-
return Object.assign(Object.assign({}, request), { variables: (parsedResult === null || parsedResult === void 0 ? void 0 : parsedResult.variables) || {} });
|
|
6992
|
-
}
|
|
6993
|
-
predicate(request, parsedResult) {
|
|
6994
|
-
if (!parsedResult) {
|
|
6995
|
-
return false;
|
|
6996
|
-
}
|
|
6997
|
-
if (!parsedResult.operationName) {
|
|
6998
|
-
const publicUrl = getPublicUrlFromRequest(request);
|
|
6999
|
-
console.warn(`\
|
|
7000
|
-
[MSW] Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": unnamed GraphQL operations are not supported.
|
|
7001
|
-
|
|
7002
|
-
Consider naming this operation or using "graphql.operation" request handler to intercept GraphQL requests regardless of their operation name/type. Read more: https://mswjs.io/docs/api/graphql/operation\
|
|
7003
|
-
`);
|
|
7004
|
-
return false;
|
|
7005
|
-
}
|
|
7006
|
-
const hasMatchingUrl = matchRequestUrl(request.url, this.endpoint);
|
|
7007
|
-
const hasMatchingOperationType = this.info.operationType === 'all' ||
|
|
7008
|
-
parsedResult.operationType === this.info.operationType;
|
|
7009
|
-
const hasMatchingOperationName = this.info.operationName instanceof RegExp
|
|
7010
|
-
? this.info.operationName.test(parsedResult.operationName)
|
|
7011
|
-
: parsedResult.operationName === this.info.operationName;
|
|
7012
|
-
return (hasMatchingUrl.matches &&
|
|
7013
|
-
hasMatchingOperationType &&
|
|
7014
|
-
hasMatchingOperationName);
|
|
7015
|
-
}
|
|
7016
|
-
log(request, response) {
|
|
7017
|
-
const loggedRequest = prepareRequest(request);
|
|
7018
|
-
const loggedResponse = prepareResponse(response);
|
|
7019
|
-
console.groupCollapsed('[MSW] %s %s (%c%s%c)', getTimestamp(), this.info.operationName, `color:${getStatusCodeColor(response.status)}`, response.status, 'color:inherit');
|
|
7020
|
-
console.log('Request:', loggedRequest);
|
|
7021
|
-
console.log('Handler:', this);
|
|
7022
|
-
console.log('Response:', loggedResponse);
|
|
7023
|
-
console.groupEnd();
|
|
7024
|
-
}
|
|
7025
|
-
}
|
|
7026
|
-
|
|
7027
|
-
const MAX_MATCH_SCORE = 3;
|
|
7028
|
-
const MAX_SUGGESTION_COUNT = 4;
|
|
7029
|
-
const TYPE_MATCH_DELTA = 0.5;
|
|
7030
|
-
function groupHandlersByType(handlers) {
|
|
7031
|
-
return handlers.reduce((groups, handler) => {
|
|
7032
|
-
if (handler instanceof RestHandler) {
|
|
7033
|
-
groups.rest.push(handler);
|
|
7034
|
-
}
|
|
7035
|
-
if (handler instanceof GraphQLHandler) {
|
|
7036
|
-
groups.graphql.push(handler);
|
|
7037
|
-
}
|
|
7038
|
-
return groups;
|
|
7039
|
-
}, {
|
|
7040
|
-
rest: [],
|
|
7041
|
-
graphql: [],
|
|
7042
|
-
});
|
|
7043
|
-
}
|
|
7044
|
-
function getScoreForRestHandler() {
|
|
7045
|
-
return (request, handler) => {
|
|
7046
|
-
const { mask, method } = handler.info;
|
|
7047
|
-
if (mask instanceof RegExp) {
|
|
7048
|
-
return Infinity;
|
|
7049
|
-
}
|
|
7050
|
-
const hasSameMethod = isStringEqual(request.method, method);
|
|
7051
|
-
// Always treat a handler with the same method as a more similar one.
|
|
7052
|
-
const methodScoreDelta = hasSameMethod ? TYPE_MATCH_DELTA : 0;
|
|
7053
|
-
const requestPublicUrl = getPublicUrlFromRequest(request);
|
|
7054
|
-
const score = jsLevenshtein(requestPublicUrl, mask);
|
|
7055
|
-
return score - methodScoreDelta;
|
|
7056
|
-
};
|
|
7057
|
-
}
|
|
7058
|
-
function getScoreForGraphQLHandler(parsedQuery) {
|
|
7059
|
-
return (_, handler) => {
|
|
7060
|
-
if (typeof parsedQuery.operationName === 'undefined') {
|
|
7061
|
-
return Infinity;
|
|
7062
|
-
}
|
|
7063
|
-
const { operationType, operationName } = handler.info;
|
|
7064
|
-
const hasSameOperationType = parsedQuery.operationType === operationType;
|
|
7065
|
-
// Always treat a handler with the same operation type as a more similar one.
|
|
7066
|
-
const operationTypeScoreDelta = hasSameOperationType ? TYPE_MATCH_DELTA : 0;
|
|
7067
|
-
const score = jsLevenshtein(parsedQuery.operationName, operationName);
|
|
7068
|
-
return score - operationTypeScoreDelta;
|
|
7069
|
-
};
|
|
7070
|
-
}
|
|
7071
|
-
function getSuggestedHandler(request, handlers, getScore) {
|
|
7072
|
-
const suggestedHandlers = handlers
|
|
7073
|
-
.reduce((acc, handler) => {
|
|
7074
|
-
const score = getScore(request, handler);
|
|
7075
|
-
return acc.concat([[score, handler]]);
|
|
7076
|
-
}, [])
|
|
7077
|
-
.sort(([leftScore], [rightScore]) => {
|
|
7078
|
-
return leftScore - rightScore;
|
|
7079
|
-
})
|
|
7080
|
-
.filter(([score]) => {
|
|
7081
|
-
return score <= MAX_MATCH_SCORE;
|
|
7082
|
-
})
|
|
7083
|
-
.slice(0, MAX_SUGGESTION_COUNT)
|
|
7084
|
-
.map(([, handler]) => handler);
|
|
7085
|
-
return suggestedHandlers;
|
|
7086
|
-
}
|
|
7087
|
-
function getSuggestedHandlersMessage(handlers) {
|
|
7088
|
-
if (handlers.length > 1) {
|
|
7089
|
-
return `\
|
|
7090
|
-
Did you mean to request one of the following resources instead?
|
|
7091
|
-
|
|
7092
|
-
${handlers.map((handler) => ` • ${handler.info.header}`).join('\n')}`;
|
|
7093
|
-
}
|
|
7094
|
-
return `Did you mean to request "${handlers[0].info.header}" instead?`;
|
|
7095
|
-
}
|
|
7096
|
-
function onUnhandledRequest(request, handlers, strategy = 'bypass') {
|
|
7097
|
-
if (typeof strategy === 'function') {
|
|
7098
|
-
strategy(request);
|
|
7099
|
-
return;
|
|
7100
|
-
}
|
|
7101
|
-
const parsedGraphQLQuery = parseGraphQLRequest(request);
|
|
7102
|
-
const handlerGroups = groupHandlersByType(handlers);
|
|
7103
|
-
const relevantHandlers = parsedGraphQLQuery
|
|
7104
|
-
? handlerGroups.graphql
|
|
7105
|
-
: handlerGroups.rest;
|
|
7106
|
-
const suggestedHandlers = getSuggestedHandler(request, relevantHandlers, parsedGraphQLQuery
|
|
7107
|
-
? getScoreForGraphQLHandler(parsedGraphQLQuery)
|
|
7108
|
-
: getScoreForRestHandler());
|
|
7109
|
-
const handlerSuggestion = suggestedHandlers.length > 0
|
|
7110
|
-
? getSuggestedHandlersMessage(suggestedHandlers)
|
|
7111
|
-
: '';
|
|
7112
|
-
const publicUrl = getPublicUrlFromRequest(request);
|
|
7113
|
-
const requestHeader = parsedGraphQLQuery
|
|
7114
|
-
? `${parsedGraphQLQuery.operationType} ${parsedGraphQLQuery.operationName} (${request.method} ${publicUrl})`
|
|
7115
|
-
: `${request.method} ${publicUrl}`;
|
|
7116
|
-
const messageTemplate = [
|
|
7117
|
-
`captured a request without a matching request handler:`,
|
|
7118
|
-
` • ${requestHeader}`,
|
|
7119
|
-
handlerSuggestion,
|
|
7120
|
-
`\
|
|
7121
|
-
If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
7122
|
-
Read more: https://mswjs.io/docs/getting-started/mocks\
|
|
7123
|
-
`,
|
|
7124
|
-
].filter(Boolean);
|
|
7125
|
-
const message = messageTemplate.join('\n\n');
|
|
7126
|
-
switch (strategy) {
|
|
7127
|
-
case 'error': {
|
|
7128
|
-
console.error(`[MSW] Error: ${message}`);
|
|
7129
|
-
break;
|
|
7130
|
-
}
|
|
7131
|
-
case 'warn': {
|
|
7132
|
-
console.warn(`[MSW] Warning: ${message}`);
|
|
7133
|
-
break;
|
|
7134
|
-
}
|
|
7135
|
-
default:
|
|
7136
|
-
return;
|
|
7137
|
-
}
|
|
7138
|
-
}
|
|
7139
|
-
|
|
7140
|
-
function uuidv4() {
|
|
7141
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
7142
|
-
const r = (Math.random() * 16) | 0;
|
|
7143
|
-
const v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
7144
|
-
return v.toString(16);
|
|
7145
|
-
});
|
|
7146
|
-
}
|
|
7147
|
-
|
|
7148
|
-
var defaultParseOptions = {
|
|
7149
|
-
decodeValues: true,
|
|
7150
|
-
map: false,
|
|
7151
|
-
silent: false,
|
|
7152
|
-
};
|
|
7153
|
-
|
|
7154
|
-
function isNonEmptyString(str) {
|
|
7155
|
-
return typeof str === "string" && !!str.trim();
|
|
7156
|
-
}
|
|
7157
|
-
|
|
7158
|
-
function parseString(setCookieValue, options) {
|
|
7159
|
-
var parts = setCookieValue.split(";").filter(isNonEmptyString);
|
|
7160
|
-
var nameValue = parts.shift().split("=");
|
|
7161
|
-
var name = nameValue.shift();
|
|
7162
|
-
var value = nameValue.join("="); // everything after the first =, joined by a "=" if there was more than one part
|
|
7163
|
-
|
|
7164
|
-
options = options
|
|
7165
|
-
? Object.assign({}, defaultParseOptions, options)
|
|
7166
|
-
: defaultParseOptions;
|
|
7167
|
-
|
|
7168
|
-
try {
|
|
7169
|
-
value = options.decodeValues ? decodeURIComponent(value) : value; // decode cookie value
|
|
7170
|
-
} catch (e) {
|
|
7171
|
-
console.error(
|
|
7172
|
-
"set-cookie-parser encountered an error while decoding a cookie with value '" +
|
|
7173
|
-
value +
|
|
7174
|
-
"'. Set options.decodeValues to false to disable this feature.",
|
|
7175
|
-
e
|
|
7176
|
-
);
|
|
7177
|
-
}
|
|
7178
|
-
|
|
7179
|
-
var cookie = {
|
|
7180
|
-
name: name, // grab everything before the first =
|
|
7181
|
-
value: value,
|
|
7182
|
-
};
|
|
7183
|
-
|
|
7184
|
-
parts.forEach(function (part) {
|
|
7185
|
-
var sides = part.split("=");
|
|
7186
|
-
var key = sides.shift().trimLeft().toLowerCase();
|
|
7187
|
-
var value = sides.join("=");
|
|
7188
|
-
if (key === "expires") {
|
|
7189
|
-
cookie.expires = new Date(value);
|
|
7190
|
-
} else if (key === "max-age") {
|
|
7191
|
-
cookie.maxAge = parseInt(value, 10);
|
|
7192
|
-
} else if (key === "secure") {
|
|
7193
|
-
cookie.secure = true;
|
|
7194
|
-
} else if (key === "httponly") {
|
|
7195
|
-
cookie.httpOnly = true;
|
|
7196
|
-
} else if (key === "samesite") {
|
|
7197
|
-
cookie.sameSite = value;
|
|
7198
|
-
} else {
|
|
7199
|
-
cookie[key] = value;
|
|
7200
|
-
}
|
|
7201
|
-
});
|
|
7202
|
-
|
|
7203
|
-
return cookie;
|
|
7204
|
-
}
|
|
7205
|
-
|
|
7206
|
-
function parse$2(input, options) {
|
|
7207
|
-
options = options
|
|
7208
|
-
? Object.assign({}, defaultParseOptions, options)
|
|
7209
|
-
: defaultParseOptions;
|
|
7210
|
-
|
|
7211
|
-
if (!input) {
|
|
7212
|
-
if (!options.map) {
|
|
7213
|
-
return [];
|
|
7214
|
-
} else {
|
|
7215
|
-
return {};
|
|
7216
|
-
}
|
|
7217
|
-
}
|
|
7218
|
-
|
|
7219
|
-
if (input.headers && input.headers["set-cookie"]) {
|
|
7220
|
-
// fast-path for node.js (which automatically normalizes header names to lower-case
|
|
7221
|
-
input = input.headers["set-cookie"];
|
|
7222
|
-
} else if (input.headers) {
|
|
7223
|
-
// slow-path for other environments - see #25
|
|
7224
|
-
var sch =
|
|
7225
|
-
input.headers[
|
|
7226
|
-
Object.keys(input.headers).find(function (key) {
|
|
7227
|
-
return key.toLowerCase() === "set-cookie";
|
|
7228
|
-
})
|
|
7229
|
-
];
|
|
7230
|
-
// warn if called on a request-like object with a cookie header rather than a set-cookie header - see #34, 36
|
|
7231
|
-
if (!sch && input.headers.cookie && !options.silent) {
|
|
7232
|
-
console.warn(
|
|
7233
|
-
"Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
|
|
7234
|
-
);
|
|
7235
|
-
}
|
|
7236
|
-
input = sch;
|
|
7237
|
-
}
|
|
7238
|
-
if (!Array.isArray(input)) {
|
|
7239
|
-
input = [input];
|
|
7240
|
-
}
|
|
7241
|
-
|
|
7242
|
-
options = options
|
|
7243
|
-
? Object.assign({}, defaultParseOptions, options)
|
|
7244
|
-
: defaultParseOptions;
|
|
7245
|
-
|
|
7246
|
-
if (!options.map) {
|
|
7247
|
-
return input.filter(isNonEmptyString).map(function (str) {
|
|
7248
|
-
return parseString(str, options);
|
|
7249
|
-
});
|
|
7250
|
-
} else {
|
|
7251
|
-
var cookies = {};
|
|
7252
|
-
return input.filter(isNonEmptyString).reduce(function (cookies, str) {
|
|
7253
|
-
var cookie = parseString(str, options);
|
|
7254
|
-
cookies[cookie.name] = cookie;
|
|
7255
|
-
return cookies;
|
|
7256
|
-
}, cookies);
|
|
7257
|
-
}
|
|
7258
|
-
}
|
|
7259
|
-
|
|
7260
|
-
/*
|
|
7261
|
-
Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
|
|
7262
|
-
that are within a single set-cookie field-value, such as in the Expires portion.
|
|
7263
|
-
|
|
7264
|
-
This is uncommon, but explicitly allowed - see https://tools.ietf.org/html/rfc2616#section-4.2
|
|
7265
|
-
Node.js does this for every header *except* set-cookie - see https://github.com/nodejs/node/blob/d5e363b77ebaf1caf67cd7528224b651c86815c1/lib/_http_incoming.js#L128
|
|
7266
|
-
React Native's fetch does this for *every* header, including set-cookie.
|
|
7267
|
-
|
|
7268
|
-
Based on: https://github.com/google/j2objc/commit/16820fdbc8f76ca0c33472810ce0cb03d20efe25
|
|
7269
|
-
Credits to: https://github.com/tomball for original and https://github.com/chrusart for JavaScript implementation
|
|
7270
|
-
*/
|
|
7271
|
-
function splitCookiesString(cookiesString) {
|
|
7272
|
-
if (Array.isArray(cookiesString)) {
|
|
7273
|
-
return cookiesString;
|
|
7274
|
-
}
|
|
7275
|
-
if (typeof cookiesString !== "string") {
|
|
7276
|
-
return [];
|
|
7277
|
-
}
|
|
7278
|
-
|
|
7279
|
-
var cookiesStrings = [];
|
|
7280
|
-
var pos = 0;
|
|
7281
|
-
var start;
|
|
7282
|
-
var ch;
|
|
7283
|
-
var lastComma;
|
|
7284
|
-
var nextStart;
|
|
7285
|
-
var cookiesSeparatorFound;
|
|
7286
|
-
|
|
7287
|
-
function skipWhitespace() {
|
|
7288
|
-
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
|
|
7289
|
-
pos += 1;
|
|
7290
|
-
}
|
|
7291
|
-
return pos < cookiesString.length;
|
|
7292
|
-
}
|
|
7293
|
-
|
|
7294
|
-
function notSpecialChar() {
|
|
7295
|
-
ch = cookiesString.charAt(pos);
|
|
7296
|
-
|
|
7297
|
-
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
7298
|
-
}
|
|
7299
|
-
|
|
7300
|
-
while (pos < cookiesString.length) {
|
|
7301
|
-
start = pos;
|
|
7302
|
-
cookiesSeparatorFound = false;
|
|
7303
|
-
|
|
7304
|
-
while (skipWhitespace()) {
|
|
7305
|
-
ch = cookiesString.charAt(pos);
|
|
7306
|
-
if (ch === ",") {
|
|
7307
|
-
// ',' is a cookie separator if we have later first '=', not ';' or ','
|
|
7308
|
-
lastComma = pos;
|
|
7309
|
-
pos += 1;
|
|
7310
|
-
|
|
7311
|
-
skipWhitespace();
|
|
7312
|
-
nextStart = pos;
|
|
7313
|
-
|
|
7314
|
-
while (pos < cookiesString.length && notSpecialChar()) {
|
|
7315
|
-
pos += 1;
|
|
7316
|
-
}
|
|
7317
|
-
|
|
7318
|
-
// currently special character
|
|
7319
|
-
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
7320
|
-
// we found cookies separator
|
|
7321
|
-
cookiesSeparatorFound = true;
|
|
7322
|
-
// pos is inside the next cookie, so back up and return it.
|
|
7323
|
-
pos = nextStart;
|
|
7324
|
-
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
|
7325
|
-
start = pos;
|
|
7326
|
-
} else {
|
|
7327
|
-
// in param ',' or param separator ';',
|
|
7328
|
-
// we continue from that comma
|
|
7329
|
-
pos = lastComma + 1;
|
|
7330
|
-
}
|
|
7331
|
-
} else {
|
|
7332
|
-
pos += 1;
|
|
7333
|
-
}
|
|
7334
|
-
}
|
|
7335
|
-
|
|
7336
|
-
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
|
7337
|
-
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
|
7338
|
-
}
|
|
7339
|
-
}
|
|
7340
|
-
|
|
7341
|
-
return cookiesStrings;
|
|
7342
|
-
}
|
|
7343
|
-
|
|
7344
|
-
var setCookie = parse$2;
|
|
7345
|
-
var parse_1$1 = parse$2;
|
|
7346
|
-
var parseString_1 = parseString;
|
|
7347
|
-
var splitCookiesString_1 = splitCookiesString;
|
|
7348
|
-
setCookie.parse = parse_1$1;
|
|
7349
|
-
setCookie.parseString = parseString_1;
|
|
7350
|
-
setCookie.splitCookiesString = splitCookiesString_1;
|
|
7351
|
-
|
|
7352
|
-
var CookieStore_1 = createCommonjsModule(function (module, exports) {
|
|
7353
|
-
var __rest = (commonjsGlobal && commonjsGlobal.__rest) || function (s, e) {
|
|
7354
|
-
var t = {};
|
|
7355
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
7356
|
-
t[p] = s[p];
|
|
7357
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7358
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7359
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
7360
|
-
t[p[i]] = s[p[i]];
|
|
7361
|
-
}
|
|
7362
|
-
return t;
|
|
7363
|
-
};
|
|
7364
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7365
|
-
exports.PERSISTENCY_KEY = void 0;
|
|
7366
|
-
|
|
7367
|
-
exports.PERSISTENCY_KEY = 'MSW_COOKIE_STORE';
|
|
7368
|
-
class CookieStore {
|
|
7369
|
-
constructor() {
|
|
7370
|
-
this.store = new Map();
|
|
7371
|
-
this.supportsPersistency = typeof window !== 'undefined';
|
|
7372
|
-
}
|
|
7373
|
-
/**
|
|
7374
|
-
* Sets the given request cookies into the store.
|
|
7375
|
-
* Respects the `request.credentials` policy.
|
|
7376
|
-
*/
|
|
7377
|
-
add(request, response) {
|
|
7378
|
-
if (request.credentials === 'omit') {
|
|
7379
|
-
return;
|
|
7380
|
-
}
|
|
7381
|
-
const requestUrl = new URL(request.url);
|
|
7382
|
-
const responseCookies = response.headers.get('set-cookie');
|
|
7383
|
-
if (!responseCookies) {
|
|
7384
|
-
return;
|
|
7385
|
-
}
|
|
7386
|
-
const now = Date.now();
|
|
7387
|
-
const parsedResponseCookies = setCookie.parse(responseCookies).map((_a) => {
|
|
7388
|
-
var { maxAge } = _a, cookie = __rest(_a, ["maxAge"]);
|
|
7389
|
-
return (Object.assign(Object.assign({}, cookie), { expires: maxAge === undefined
|
|
7390
|
-
? cookie.expires
|
|
7391
|
-
: new Date(now + maxAge * 1000), maxAge }));
|
|
7392
|
-
}).filter(({ expires }) => expires === undefined || expires.getTime() > now);
|
|
7393
|
-
const prevCookies = this.store.get(requestUrl.origin) || new Map();
|
|
7394
|
-
parsedResponseCookies.forEach((cookie) => {
|
|
7395
|
-
this.store.set(requestUrl.origin, prevCookies.set(cookie.name, cookie));
|
|
7396
|
-
});
|
|
7397
|
-
}
|
|
7398
|
-
/**
|
|
7399
|
-
* Returns cookies relevant to the given request
|
|
7400
|
-
* and its `request.credentials` policy.
|
|
7401
|
-
*/
|
|
7402
|
-
get(request) {
|
|
7403
|
-
this.deleteExpiredCookies();
|
|
7404
|
-
const requestUrl = new URL(request.url);
|
|
7405
|
-
const originCookies = this.store.get(requestUrl.origin) || new Map();
|
|
7406
|
-
switch (request.credentials) {
|
|
7407
|
-
case 'include': {
|
|
7408
|
-
const documentCookies = setCookie.parse(document.cookie);
|
|
7409
|
-
documentCookies.forEach((cookie) => {
|
|
7410
|
-
originCookies.set(cookie.name, cookie);
|
|
7411
|
-
});
|
|
7412
|
-
return originCookies;
|
|
7413
|
-
}
|
|
7414
|
-
case 'same-origin': {
|
|
7415
|
-
return originCookies;
|
|
7416
|
-
}
|
|
7417
|
-
default:
|
|
7418
|
-
return new Map();
|
|
7419
|
-
}
|
|
7420
|
-
}
|
|
7421
|
-
/**
|
|
7422
|
-
* Returns a collection of all stored cookies.
|
|
7423
|
-
*/
|
|
7424
|
-
getAll() {
|
|
7425
|
-
this.deleteExpiredCookies();
|
|
7426
|
-
return this.store;
|
|
7427
|
-
}
|
|
7428
|
-
/**
|
|
7429
|
-
* Deletes all cookies associated with the given request.
|
|
7430
|
-
*/
|
|
7431
|
-
deleteAll(request) {
|
|
7432
|
-
const requestUrl = new URL(request.url);
|
|
7433
|
-
this.store.delete(requestUrl.origin);
|
|
7434
|
-
}
|
|
7435
|
-
/**
|
|
7436
|
-
* Clears the entire cookie store.
|
|
7437
|
-
*/
|
|
7438
|
-
clear() {
|
|
7439
|
-
this.store.clear();
|
|
7440
|
-
}
|
|
7441
|
-
/**
|
|
7442
|
-
* Hydrates the virtual cookie store from the `localStorage`.
|
|
7443
|
-
*/
|
|
7444
|
-
hydrate() {
|
|
7445
|
-
if (!this.supportsPersistency) {
|
|
7446
|
-
return;
|
|
7447
|
-
}
|
|
7448
|
-
const persistedCookies = localStorage.getItem(exports.PERSISTENCY_KEY);
|
|
7449
|
-
if (persistedCookies) {
|
|
7450
|
-
try {
|
|
7451
|
-
const parsedCookies = JSON.parse(persistedCookies);
|
|
7452
|
-
parsedCookies.forEach(([origin, cookies]) => {
|
|
7453
|
-
this.store.set(origin, new Map(cookies.map((_a) => {
|
|
7454
|
-
var [token, _b] = _a, { expires } = _b, cookie = __rest(_b, ["expires"]);
|
|
7455
|
-
return [
|
|
7456
|
-
token,
|
|
7457
|
-
expires === undefined ? cookie : Object.assign(Object.assign({}, cookie), { expires: new Date(expires) })
|
|
7458
|
-
];
|
|
7459
|
-
})));
|
|
7460
|
-
});
|
|
7461
|
-
}
|
|
7462
|
-
catch (error) {
|
|
7463
|
-
console.warn(`
|
|
7464
|
-
[virtual-cookie] Failed to parse a stored cookie from the localStorage (key "${exports.PERSISTENCY_KEY}").
|
|
7465
|
-
|
|
7466
|
-
Stored value:
|
|
7467
|
-
${localStorage.getItem(exports.PERSISTENCY_KEY)}
|
|
7468
|
-
|
|
7469
|
-
Thrown exception:
|
|
7470
|
-
${error}
|
|
7456
|
+
}
|
|
7457
|
+
}
|
|
7471
7458
|
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
}
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
*/
|
|
7481
|
-
persist() {
|
|
7482
|
-
if (!this.supportsPersistency) {
|
|
7483
|
-
return;
|
|
7484
|
-
}
|
|
7485
|
-
const serializedCookies = Array.from(this.store.entries()).map(([origin, cookies]) => {
|
|
7486
|
-
return [origin, Array.from(cookies.entries())];
|
|
7487
|
-
});
|
|
7488
|
-
localStorage.setItem(exports.PERSISTENCY_KEY, JSON.stringify(serializedCookies));
|
|
7489
|
-
}
|
|
7490
|
-
deleteExpiredCookies() {
|
|
7491
|
-
const now = Date.now();
|
|
7492
|
-
this.store.forEach((originCookies, origin) => {
|
|
7493
|
-
originCookies.forEach(({ expires, name }) => {
|
|
7494
|
-
if (expires !== undefined && expires.getTime() <= now) {
|
|
7495
|
-
originCookies.delete(name);
|
|
7496
|
-
}
|
|
7497
|
-
});
|
|
7498
|
-
if (originCookies.size === 0) {
|
|
7499
|
-
this.store.delete(origin);
|
|
7500
|
-
}
|
|
7501
|
-
});
|
|
7502
|
-
}
|
|
7459
|
+
function tryCatch(fn, onException) {
|
|
7460
|
+
try {
|
|
7461
|
+
const result = fn();
|
|
7462
|
+
return result;
|
|
7463
|
+
}
|
|
7464
|
+
catch (error) {
|
|
7465
|
+
onException === null || onException === void 0 ? void 0 : onException(error);
|
|
7466
|
+
}
|
|
7503
7467
|
}
|
|
7504
|
-
exports.default = new CookieStore();
|
|
7505
|
-
});
|
|
7506
7468
|
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
|
|
7469
|
+
const graphqlContext = {
|
|
7470
|
+
set,
|
|
7471
|
+
status,
|
|
7472
|
+
delay,
|
|
7473
|
+
fetch,
|
|
7474
|
+
data,
|
|
7475
|
+
errors,
|
|
7476
|
+
cookie,
|
|
7477
|
+
};
|
|
7478
|
+
class GraphQLHandler extends RequestHandler {
|
|
7479
|
+
constructor(operationType, operationName, endpoint, resolver) {
|
|
7480
|
+
const header = operationType === 'all'
|
|
7481
|
+
? `${operationType} (origin: ${endpoint.toString()})`
|
|
7482
|
+
: `${operationType} ${operationName} (origin: ${endpoint.toString()})`;
|
|
7483
|
+
super({
|
|
7484
|
+
info: {
|
|
7485
|
+
header,
|
|
7486
|
+
operationType,
|
|
7487
|
+
operationName,
|
|
7488
|
+
},
|
|
7489
|
+
ctx: graphqlContext,
|
|
7490
|
+
resolver,
|
|
7491
|
+
});
|
|
7492
|
+
this.endpoint = endpoint;
|
|
7493
|
+
}
|
|
7494
|
+
parse(request) {
|
|
7495
|
+
return tryCatch(() => parseGraphQLRequest(request), (error) => console.error(error.message));
|
|
7496
|
+
}
|
|
7497
|
+
getPublicRequest(request, parsedResult) {
|
|
7498
|
+
return Object.assign(Object.assign({}, request), { variables: (parsedResult === null || parsedResult === void 0 ? void 0 : parsedResult.variables) || {} });
|
|
7499
|
+
}
|
|
7500
|
+
predicate(request, parsedResult) {
|
|
7501
|
+
if (!parsedResult) {
|
|
7502
|
+
return false;
|
|
7503
|
+
}
|
|
7504
|
+
if (!parsedResult.operationName) {
|
|
7505
|
+
const publicUrl = getPublicUrlFromRequest(request);
|
|
7506
|
+
console.warn(`\
|
|
7507
|
+
[MSW] Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": unnamed GraphQL operations are not supported.
|
|
7513
7508
|
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7509
|
+
Consider naming this operation or using "graphql.operation" request handler to intercept GraphQL requests regardless of their operation name/type. Read more: https://mswjs.io/docs/api/graphql/operation\
|
|
7510
|
+
`);
|
|
7511
|
+
return false;
|
|
7512
|
+
}
|
|
7513
|
+
const hasMatchingUrl = matchRequestUrl(request.url, this.endpoint);
|
|
7514
|
+
const hasMatchingOperationType = this.info.operationType === 'all' ||
|
|
7515
|
+
parsedResult.operationType === this.info.operationType;
|
|
7516
|
+
const hasMatchingOperationName = this.info.operationName instanceof RegExp
|
|
7517
|
+
? this.info.operationName.test(parsedResult.operationName)
|
|
7518
|
+
: parsedResult.operationName === this.info.operationName;
|
|
7519
|
+
return (hasMatchingUrl.matches &&
|
|
7520
|
+
hasMatchingOperationType &&
|
|
7521
|
+
hasMatchingOperationName);
|
|
7522
|
+
}
|
|
7523
|
+
log(request, response) {
|
|
7524
|
+
const loggedRequest = prepareRequest(request);
|
|
7525
|
+
const loggedResponse = prepareResponse(response);
|
|
7526
|
+
console.groupCollapsed('[MSW] %s %s (%c%s%c)', getTimestamp(), this.info.operationName, `color:${getStatusCodeColor(response.status)}`, response.status, 'color:inherit');
|
|
7527
|
+
console.log('Request:', loggedRequest);
|
|
7528
|
+
console.log('Handler:', this);
|
|
7529
|
+
console.log('Response:', loggedResponse);
|
|
7530
|
+
console.groupEnd();
|
|
7531
|
+
}
|
|
7532
|
+
}
|
|
7517
7533
|
|
|
7518
|
-
|
|
7519
|
-
|
|
7534
|
+
const MAX_MATCH_SCORE = 3;
|
|
7535
|
+
const MAX_SUGGESTION_COUNT = 4;
|
|
7536
|
+
const TYPE_MATCH_DELTA = 0.5;
|
|
7537
|
+
function groupHandlersByType(handlers) {
|
|
7538
|
+
return handlers.reduce((groups, handler) => {
|
|
7539
|
+
if (handler instanceof RestHandler) {
|
|
7540
|
+
groups.rest.push(handler);
|
|
7541
|
+
}
|
|
7542
|
+
if (handler instanceof GraphQLHandler) {
|
|
7543
|
+
groups.graphql.push(handler);
|
|
7544
|
+
}
|
|
7545
|
+
return groups;
|
|
7546
|
+
}, {
|
|
7547
|
+
rest: [],
|
|
7548
|
+
graphql: [],
|
|
7549
|
+
});
|
|
7520
7550
|
}
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7551
|
+
function getScoreForRestHandler() {
|
|
7552
|
+
return (request, handler) => {
|
|
7553
|
+
const { mask, method } = handler.info;
|
|
7554
|
+
if (mask instanceof RegExp) {
|
|
7555
|
+
return Infinity;
|
|
7556
|
+
}
|
|
7557
|
+
const hasSameMethod = isStringEqual(request.method, method);
|
|
7558
|
+
// Always treat a handler with the same method as a more similar one.
|
|
7559
|
+
const methodScoreDelta = hasSameMethod ? TYPE_MATCH_DELTA : 0;
|
|
7560
|
+
const requestPublicUrl = getPublicUrlFromRequest(request);
|
|
7561
|
+
const score = jsLevenshtein(requestPublicUrl, mask);
|
|
7562
|
+
return score - methodScoreDelta;
|
|
7563
|
+
};
|
|
7564
|
+
}
|
|
7565
|
+
function getScoreForGraphQLHandler(parsedQuery) {
|
|
7566
|
+
return (_, handler) => {
|
|
7567
|
+
if (typeof parsedQuery.operationName === 'undefined') {
|
|
7568
|
+
return Infinity;
|
|
7569
|
+
}
|
|
7570
|
+
const { operationType, operationName } = handler.info;
|
|
7571
|
+
const hasSameOperationType = parsedQuery.operationType === operationType;
|
|
7572
|
+
// Always treat a handler with the same operation type as a more similar one.
|
|
7573
|
+
const operationTypeScoreDelta = hasSameOperationType ? TYPE_MATCH_DELTA : 0;
|
|
7574
|
+
const score = jsLevenshtein(parsedQuery.operationName, operationName);
|
|
7575
|
+
return score - operationTypeScoreDelta;
|
|
7576
|
+
};
|
|
7577
|
+
}
|
|
7578
|
+
function getSuggestedHandler(request, handlers, getScore) {
|
|
7579
|
+
const suggestedHandlers = handlers
|
|
7580
|
+
.reduce((acc, handler) => {
|
|
7581
|
+
const score = getScore(request, handler);
|
|
7582
|
+
return acc.concat([[score, handler]]);
|
|
7583
|
+
}, [])
|
|
7584
|
+
.sort(([leftScore], [rightScore]) => {
|
|
7585
|
+
return leftScore - rightScore;
|
|
7586
|
+
})
|
|
7587
|
+
.filter(([score]) => {
|
|
7588
|
+
return score <= MAX_MATCH_SCORE;
|
|
7589
|
+
})
|
|
7590
|
+
.slice(0, MAX_SUGGESTION_COUNT)
|
|
7591
|
+
.map(([, handler]) => handler);
|
|
7592
|
+
return suggestedHandlers;
|
|
7593
|
+
}
|
|
7594
|
+
function getSuggestedHandlersMessage(handlers) {
|
|
7595
|
+
if (handlers.length > 1) {
|
|
7596
|
+
return `\
|
|
7597
|
+
Did you mean to request one of the following resources instead?
|
|
7598
|
+
|
|
7599
|
+
${handlers.map((handler) => ` • ${handler.info.header}`).join('\n')}`;
|
|
7600
|
+
}
|
|
7601
|
+
return `Did you mean to request "${handlers[0].info.header}" instead?`;
|
|
7602
|
+
}
|
|
7603
|
+
function onUnhandledRequest(request, handlers, strategy = 'warn') {
|
|
7604
|
+
if (typeof strategy === 'function') {
|
|
7605
|
+
strategy(request);
|
|
7606
|
+
return;
|
|
7607
|
+
}
|
|
7525
7608
|
/**
|
|
7526
|
-
* @note
|
|
7609
|
+
* @note Ignore exceptions during GraphQL request parsing because at this point
|
|
7610
|
+
* we cannot assume the unhandled request is a valid GraphQL request.
|
|
7611
|
+
* If the GraphQL parsing fails, just don't treat it as a GraphQL request.
|
|
7527
7612
|
*/
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7613
|
+
const parsedGraphQLQuery = tryCatch(() => parseGraphQLRequest(request));
|
|
7614
|
+
const handlerGroups = groupHandlersByType(handlers);
|
|
7615
|
+
const relevantHandlers = parsedGraphQLQuery
|
|
7616
|
+
? handlerGroups.graphql
|
|
7617
|
+
: handlerGroups.rest;
|
|
7618
|
+
const suggestedHandlers = getSuggestedHandler(request, relevantHandlers, parsedGraphQLQuery
|
|
7619
|
+
? getScoreForGraphQLHandler(parsedGraphQLQuery)
|
|
7620
|
+
: getScoreForRestHandler());
|
|
7621
|
+
const handlerSuggestion = suggestedHandlers.length > 0
|
|
7622
|
+
? getSuggestedHandlersMessage(suggestedHandlers)
|
|
7623
|
+
: '';
|
|
7624
|
+
const publicUrl = getPublicUrlFromRequest(request);
|
|
7625
|
+
const requestHeader = parsedGraphQLQuery
|
|
7626
|
+
? `${parsedGraphQLQuery.operationType} ${parsedGraphQLQuery.operationName} (${request.method} ${publicUrl})`
|
|
7627
|
+
: `${request.method} ${publicUrl}`;
|
|
7628
|
+
const messageTemplate = [
|
|
7629
|
+
`captured a request without a matching request handler:`,
|
|
7630
|
+
` \u2022 ${requestHeader}`,
|
|
7631
|
+
handlerSuggestion,
|
|
7632
|
+
`\
|
|
7633
|
+
If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
7634
|
+
Read more: https://mswjs.io/docs/getting-started/mocks\
|
|
7635
|
+
`,
|
|
7636
|
+
].filter(Boolean);
|
|
7637
|
+
const message = messageTemplate.join('\n\n');
|
|
7638
|
+
switch (strategy) {
|
|
7639
|
+
case 'error': {
|
|
7640
|
+
console.error(`[MSW] Error: ${message}`);
|
|
7641
|
+
break;
|
|
7540
7642
|
}
|
|
7541
|
-
|
|
7542
|
-
|
|
7643
|
+
case 'warn': {
|
|
7644
|
+
console.warn(`[MSW] Warning: ${message}`);
|
|
7645
|
+
break;
|
|
7543
7646
|
}
|
|
7647
|
+
case 'bypass':
|
|
7648
|
+
break;
|
|
7649
|
+
default:
|
|
7650
|
+
throw new Error(`[MSW] Failed to react to an unhandled request: unknown strategy "${strategy}". Please provide one of the supported strategies ("bypass", "warn", "error") or a custom callback function.`);
|
|
7544
7651
|
}
|
|
7545
7652
|
}
|
|
7546
7653
|
|
|
7547
|
-
function
|
|
7548
|
-
|
|
7549
|
-
lib
|
|
7550
|
-
request.cookies = Object.assign(Object.assign({}, getRequestCookies(request)), Array.from((_a = lib$2.store.get(Object.assign(Object.assign({}, request), { url: request.url.toString() }))) === null || _a === void 0 ? void 0 : _a.entries()).reduce((cookies, [name, { value }]) => Object.assign(cookies, { [name]: value }), {}));
|
|
7551
|
-
request.headers.set('cookie', Object.entries(request.cookies)
|
|
7552
|
-
.map(([name, value]) => `${name}=${value}`)
|
|
7553
|
-
.join('; '));
|
|
7654
|
+
function readResponseCookies(request, response) {
|
|
7655
|
+
lib.store.add(Object.assign(Object.assign({}, request), { url: request.url.toString() }), response);
|
|
7656
|
+
lib.store.persist();
|
|
7554
7657
|
}
|
|
7555
7658
|
|
|
7556
|
-
function
|
|
7557
|
-
|
|
7558
|
-
|
|
7659
|
+
function handleRequest(request, handlers, options, emitter, handleRequestOptions) {
|
|
7660
|
+
var _a, _b, _c;
|
|
7661
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7662
|
+
emitter.emit('request:start', request);
|
|
7663
|
+
// Perform bypassed requests (i.e. issued via "ctx.fetch") as-is.
|
|
7664
|
+
if (request.headers.get('x-msw-bypass')) {
|
|
7665
|
+
emitter.emit('request:end', request);
|
|
7666
|
+
(_a = handleRequestOptions === null || handleRequestOptions === void 0 ? void 0 : handleRequestOptions.onBypassResponse) === null || _a === void 0 ? void 0 : _a.call(handleRequestOptions, request);
|
|
7667
|
+
return;
|
|
7668
|
+
}
|
|
7669
|
+
// Resolve a mocked response from the list of request handlers.
|
|
7670
|
+
const lookupResult = yield getResponse(request, handlers);
|
|
7671
|
+
const { handler, response } = lookupResult;
|
|
7672
|
+
// When there's no handler for the request, consider it unhandled.
|
|
7673
|
+
// Allow the developer to react to such cases.
|
|
7674
|
+
if (!handler) {
|
|
7675
|
+
onUnhandledRequest(request, handlers, options.onUnhandledRequest);
|
|
7676
|
+
emitter.emit('request:unhandled', request);
|
|
7677
|
+
emitter.emit('request:end', request);
|
|
7678
|
+
(_b = handleRequestOptions === null || handleRequestOptions === void 0 ? void 0 : handleRequestOptions.onBypassResponse) === null || _b === void 0 ? void 0 : _b.call(handleRequestOptions, request);
|
|
7679
|
+
return;
|
|
7680
|
+
}
|
|
7681
|
+
// When the handled request returned no mocked response, warn the developer,
|
|
7682
|
+
// as it may be an oversight on their part. Perform the request as-is.
|
|
7683
|
+
if (!response) {
|
|
7684
|
+
console.warn('[MSW] Expected a mocking resolver function to return a mocked response Object, but got: %s. Original response is going to be used instead.', response);
|
|
7685
|
+
emitter.emit('request:end', request);
|
|
7686
|
+
(_c = handleRequestOptions === null || handleRequestOptions === void 0 ? void 0 : handleRequestOptions.onBypassResponse) === null || _c === void 0 ? void 0 : _c.call(handleRequestOptions, request);
|
|
7687
|
+
return;
|
|
7688
|
+
}
|
|
7689
|
+
// Store all the received response cookies in the virtual cookie store.
|
|
7690
|
+
readResponseCookies(request, response);
|
|
7691
|
+
emitter.emit('request:match', request);
|
|
7692
|
+
return new Promise((resolve) => {
|
|
7693
|
+
var _a, _b, _c;
|
|
7694
|
+
const requiredLookupResult = lookupResult;
|
|
7695
|
+
const transformedResponse = ((_a = handleRequestOptions === null || handleRequestOptions === void 0 ? void 0 : handleRequestOptions.transformResponse) === null || _a === void 0 ? void 0 : _a.call(handleRequestOptions, response)) ||
|
|
7696
|
+
response;
|
|
7697
|
+
(_b = handleRequestOptions === null || handleRequestOptions === void 0 ? void 0 : handleRequestOptions.onMockedResponse) === null || _b === void 0 ? void 0 : _b.call(handleRequestOptions, transformedResponse, requiredLookupResult);
|
|
7698
|
+
timers.setTimeout(() => {
|
|
7699
|
+
var _a;
|
|
7700
|
+
(_a = handleRequestOptions === null || handleRequestOptions === void 0 ? void 0 : handleRequestOptions.onMockedResponseSent) === null || _a === void 0 ? void 0 : _a.call(handleRequestOptions, transformedResponse, requiredLookupResult);
|
|
7701
|
+
emitter.emit('request:end', request);
|
|
7702
|
+
resolve(transformedResponse);
|
|
7703
|
+
}, (_c = response.delay) !== null && _c !== void 0 ? _c : 0);
|
|
7704
|
+
});
|
|
7705
|
+
});
|
|
7559
7706
|
}
|
|
7560
7707
|
|
|
7561
7708
|
const DEFAULT_LISTEN_OPTIONS = {
|
|
7562
|
-
onUnhandledRequest: '
|
|
7709
|
+
onUnhandledRequest: 'warn',
|
|
7563
7710
|
};
|
|
7564
7711
|
/**
|
|
7565
7712
|
* Creates a `setupServer` API using given request interceptors.
|
|
7566
7713
|
* Useful to generate identical API using different patches to request issuing modules.
|
|
7567
7714
|
*/
|
|
7568
7715
|
function createSetupServer(...interceptors$1) {
|
|
7569
|
-
const emitter = new lib.StrictEventEmitter();
|
|
7716
|
+
const emitter = new lib$2.StrictEventEmitter();
|
|
7570
7717
|
return function setupServer(...requestHandlers) {
|
|
7571
7718
|
requestHandlers.forEach((handler) => {
|
|
7572
7719
|
if (Array.isArray(handler))
|
|
7573
7720
|
throw new Error(`[MSW] Failed to call "setupServer" given an Array of request handlers (setupServer([a, b])), expected to receive each handler individually: setupServer(a, b).`);
|
|
7574
7721
|
});
|
|
7722
|
+
// Store the list of request handlers for the current server instance,
|
|
7723
|
+
// so it could be modified at a runtime.
|
|
7724
|
+
let currentHandlers = [...requestHandlers];
|
|
7575
7725
|
// Error when attempting to run this function in a browser environment.
|
|
7576
7726
|
if (!isNodeProcess()) {
|
|
7577
7727
|
throw new Error('[MSW] Failed to execute `setupServer` in the environment that is not Node.js (i.e. a browser). Consider using `setupWorker` instead.');
|
|
@@ -7581,77 +7731,20 @@ function createSetupServer(...interceptors$1) {
|
|
|
7581
7731
|
modules: interceptors$1,
|
|
7582
7732
|
resolver(request) {
|
|
7583
7733
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7584
|
-
const
|
|
7585
|
-
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
body: parseBody(request.body, request.headers),
|
|
7595
|
-
headers: request.headers,
|
|
7596
|
-
cookies: {},
|
|
7597
|
-
redirect: 'manual',
|
|
7598
|
-
referrer: '',
|
|
7599
|
-
keepalive: false,
|
|
7600
|
-
cache: 'default',
|
|
7601
|
-
mode: 'cors',
|
|
7602
|
-
referrerPolicy: 'no-referrer',
|
|
7603
|
-
integrity: '',
|
|
7604
|
-
destination: 'document',
|
|
7605
|
-
bodyUsed: false,
|
|
7606
|
-
credentials: 'same-origin',
|
|
7607
|
-
};
|
|
7608
|
-
// Attach all the cookies stored in the virtual cookie store.
|
|
7609
|
-
setRequestCookies(mockedRequest);
|
|
7610
|
-
if (requestCookieString) {
|
|
7611
|
-
// Set mocked request cookies from the `cookie` header of the original request.
|
|
7612
|
-
// No need to take `credentials` into account, because in Node.js requests are intercepted
|
|
7613
|
-
// _after_ they happen. Request issuer should have already taken care of sending relevant cookies.
|
|
7614
|
-
// Unlike browser, where interception is on the worker level, _before_ the request happens.
|
|
7615
|
-
mockedRequest.cookies = parse_1(requestCookieString);
|
|
7616
|
-
}
|
|
7617
|
-
emitter.emit('request:start', mockedRequest);
|
|
7618
|
-
if (mockedRequest.headers.get('x-msw-bypass')) {
|
|
7619
|
-
emitter.emit('request:end', mockedRequest);
|
|
7620
|
-
return;
|
|
7621
|
-
}
|
|
7622
|
-
const { response, handler } = yield getResponse(mockedRequest, currentHandlers);
|
|
7623
|
-
if (!handler) {
|
|
7624
|
-
emitter.emit('request:unhandled', mockedRequest);
|
|
7625
|
-
onUnhandledRequest(mockedRequest, currentHandlers, resolvedOptions.onUnhandledRequest);
|
|
7626
|
-
}
|
|
7627
|
-
if (!response) {
|
|
7628
|
-
emitter.emit('request:end', mockedRequest);
|
|
7629
|
-
return;
|
|
7630
|
-
}
|
|
7631
|
-
emitter.emit('request:match', mockedRequest);
|
|
7632
|
-
return new Promise((resolve) => {
|
|
7633
|
-
var _a;
|
|
7634
|
-
const mockedResponse = {
|
|
7635
|
-
status: response.status,
|
|
7636
|
-
statusText: response.statusText,
|
|
7637
|
-
headers: response.headers.all(),
|
|
7638
|
-
body: response.body,
|
|
7639
|
-
};
|
|
7640
|
-
// Store all the received response cookies in the virtual cookie store.
|
|
7641
|
-
readResponseCookies(mockedRequest, response);
|
|
7642
|
-
// the node build will use the "timers" module to ensure @sinon/fake-timers
|
|
7643
|
-
// or jest fake timers don't affect this timeout.
|
|
7644
|
-
timers.setTimeout(() => {
|
|
7645
|
-
resolve(mockedResponse);
|
|
7646
|
-
}, (_a = response.delay) !== null && _a !== void 0 ? _a : 0);
|
|
7647
|
-
emitter.emit('request:end', mockedRequest);
|
|
7734
|
+
const mockedRequest = parseIsomorphicRequest(request);
|
|
7735
|
+
return handleRequest(mockedRequest, currentHandlers, resolvedOptions, emitter, {
|
|
7736
|
+
transformResponse(response) {
|
|
7737
|
+
return {
|
|
7738
|
+
status: response.status,
|
|
7739
|
+
statusText: response.statusText,
|
|
7740
|
+
headers: response.headers.all(),
|
|
7741
|
+
body: response.body,
|
|
7742
|
+
};
|
|
7743
|
+
},
|
|
7648
7744
|
});
|
|
7649
7745
|
});
|
|
7650
7746
|
},
|
|
7651
7747
|
});
|
|
7652
|
-
// Store the list of request handlers for the current server instance,
|
|
7653
|
-
// so it could be modified at a runtime.
|
|
7654
|
-
let currentHandlers = [...requestHandlers];
|
|
7655
7748
|
interceptor.on('response', (request, response) => {
|
|
7656
7749
|
const requestId = request.headers.get('x-msw-request-id');
|
|
7657
7750
|
if (!requestId) {
|
|
@@ -7666,7 +7759,7 @@ function createSetupServer(...interceptors$1) {
|
|
|
7666
7759
|
});
|
|
7667
7760
|
return {
|
|
7668
7761
|
listen(options) {
|
|
7669
|
-
resolvedOptions =
|
|
7762
|
+
resolvedOptions = mergeRight(DEFAULT_LISTEN_OPTIONS, options || {});
|
|
7670
7763
|
interceptor.apply();
|
|
7671
7764
|
},
|
|
7672
7765
|
use(...handlers) {
|