msw 0.35.0 → 0.36.3
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/lib/esm/RequestHandler-deps.js +387 -65
- package/lib/esm/errors-deps.js +15 -1
- package/lib/esm/fetch-deps.js +9 -5
- package/lib/esm/graphql-deps.js +14 -9
- package/lib/esm/graphql.js +1 -0
- package/lib/esm/index-deps.js +2 -1
- package/lib/esm/index.js +61 -4263
- package/lib/esm/index2.js +1 -1
- package/lib/esm/mockServiceWorker.js +5 -5
- package/lib/esm/rest-deps.js +7 -15
- package/lib/esm/rest.js +1 -0
- package/lib/iife/index.js +2 -2
- package/lib/iife/mockServiceWorker.js +5 -5
- package/lib/types/context/data.d.ts +2 -3
- package/lib/types/context/extensions.d.ts +8 -0
- package/lib/types/context/index.d.ts +1 -0
- package/lib/types/graphql.d.ts +2 -1
- package/lib/types/handlers/GraphQLHandler.d.ts +7 -6
- package/lib/types/handlers/RequestHandler.d.ts +8 -8
- package/lib/types/handlers/RestHandler.d.ts +10 -12
- package/lib/types/index.d.ts +17 -7
- package/lib/types/native/index.d.ts +1 -1
- package/lib/types/node/index.d.ts +1 -1
- package/lib/types/node/setupServer.d.ts +1 -1
- package/lib/types/rest.d.ts +10 -9
- package/lib/types/setupWorker/glossary.d.ts +12 -12
- package/lib/types/setupWorker/start/utils/prepareStartHandler.d.ts +3 -3
- package/lib/types/sharedOptions.d.ts +1 -1
- package/lib/types/typeUtils.d.ts +5 -3
- package/lib/types/utils/getResponse.d.ts +1 -1
- package/lib/types/utils/handleRequest.d.ts +5 -5
- package/lib/types/utils/internal/getCallFrame.d.ts +1 -1
- package/lib/types/utils/internal/jsonParse.d.ts +2 -2
- package/lib/types/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/types/utils/logging/prepareResponse.d.ts +1 -1
- package/lib/types/utils/matching/matchRequestUrl.d.ts +12 -2
- package/lib/types/utils/matching/normalizePath.d.ts +1 -1
- package/lib/types/utils/request/onUnhandledRequest.d.ts +1 -2
- package/lib/types/utils/request/parseBody.d.ts +2 -2
- package/lib/types/utils/request/parseWorkerRequest.d.ts +2 -2
- package/lib/types/utils/worker/createFallbackRequestListener.d.ts +2 -1
- package/lib/types/utils/worker/createRequestListener.d.ts +2 -1
- package/lib/umd/index.js +547 -134
- package/lib/umd/mockServiceWorker.js +5 -5
- package/native/lib/index.js +474 -517
- package/node/lib/index.js +476 -519
- package/package.json +19 -19
package/lib/umd/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MockServiceWorker = {}));
|
|
5
|
-
}(this, (function (exports) { 'use strict';
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
7
|
var statuses = {
|
|
8
8
|
"100": "Continue",
|
|
@@ -652,7 +652,7 @@
|
|
|
652
652
|
* @public
|
|
653
653
|
*/
|
|
654
654
|
|
|
655
|
-
var parse_1 = parse$
|
|
655
|
+
var parse_1 = parse$5;
|
|
656
656
|
var serialize_1 = serialize;
|
|
657
657
|
|
|
658
658
|
/**
|
|
@@ -686,7 +686,7 @@
|
|
|
686
686
|
* @public
|
|
687
687
|
*/
|
|
688
688
|
|
|
689
|
-
function parse$
|
|
689
|
+
function parse$5(str, options) {
|
|
690
690
|
if (typeof str !== 'string') {
|
|
691
691
|
throw new TypeError('argument str must be a string');
|
|
692
692
|
}
|
|
@@ -871,12 +871,12 @@
|
|
|
871
871
|
};
|
|
872
872
|
|
|
873
873
|
/**
|
|
874
|
-
* Parses a given
|
|
874
|
+
* Parses a given value into a JSON.
|
|
875
875
|
* Does not throw an exception on an invalid JSON string.
|
|
876
876
|
*/
|
|
877
|
-
function jsonParse(
|
|
877
|
+
function jsonParse(value) {
|
|
878
878
|
try {
|
|
879
|
-
return JSON.parse(
|
|
879
|
+
return JSON.parse(value);
|
|
880
880
|
}
|
|
881
881
|
catch (error) {
|
|
882
882
|
return undefined;
|
|
@@ -942,6 +942,20 @@
|
|
|
942
942
|
};
|
|
943
943
|
};
|
|
944
944
|
|
|
945
|
+
/**
|
|
946
|
+
* Sets the GraphQL extensions on a given response.
|
|
947
|
+
* @example
|
|
948
|
+
* res(ctx.extensions({ tracing: { version: 1 }}))
|
|
949
|
+
* @see {@link https://mswjs.io/docs/api/context/extensions `ctx.extensions()`}
|
|
950
|
+
*/
|
|
951
|
+
const extensions = (payload) => {
|
|
952
|
+
return (res) => {
|
|
953
|
+
const prevBody = jsonParse(res.body) || {};
|
|
954
|
+
const nextBody = mergeRight(prevBody, { extensions: payload });
|
|
955
|
+
return json(nextBody)(res);
|
|
956
|
+
};
|
|
957
|
+
};
|
|
958
|
+
|
|
945
959
|
var lib$5 = {exports: {}};
|
|
946
960
|
|
|
947
961
|
(function (module, exports) {
|
|
@@ -1051,8 +1065,12 @@
|
|
|
1051
1065
|
if (['GET', 'HEAD'].includes(method)) {
|
|
1052
1066
|
return requestParameters;
|
|
1053
1067
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1068
|
+
if (typeof body === 'object' || typeof body === 'number') {
|
|
1069
|
+
requestParameters.body = JSON.stringify(body);
|
|
1070
|
+
}
|
|
1071
|
+
else {
|
|
1072
|
+
requestParameters.body = body;
|
|
1073
|
+
}
|
|
1056
1074
|
return requestParameters;
|
|
1057
1075
|
};
|
|
1058
1076
|
/**
|
|
@@ -1106,6 +1124,7 @@
|
|
|
1106
1124
|
cookie: cookie,
|
|
1107
1125
|
body: body,
|
|
1108
1126
|
data: data,
|
|
1127
|
+
extensions: extensions,
|
|
1109
1128
|
delay: delay,
|
|
1110
1129
|
errors: errors,
|
|
1111
1130
|
fetch: fetch$1,
|
|
@@ -2086,7 +2105,7 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
|
|
|
2086
2105
|
return cookie;
|
|
2087
2106
|
}
|
|
2088
2107
|
|
|
2089
|
-
function parse$
|
|
2108
|
+
function parse$4(input, options) {
|
|
2090
2109
|
options = options
|
|
2091
2110
|
? Object.assign({}, defaultParseOptions, options)
|
|
2092
2111
|
: defaultParseOptions;
|
|
@@ -2224,8 +2243,8 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
|
|
|
2224
2243
|
return cookiesStrings;
|
|
2225
2244
|
}
|
|
2226
2245
|
|
|
2227
|
-
setCookie.exports = parse$
|
|
2228
|
-
setCookie.exports.parse = parse$
|
|
2246
|
+
setCookie.exports = parse$4;
|
|
2247
|
+
setCookie.exports.parse = parse$4;
|
|
2229
2248
|
setCookie.exports.parseString = parseString;
|
|
2230
2249
|
setCookie.exports.splitCookiesString = splitCookiesString;
|
|
2231
2250
|
|
|
@@ -2405,7 +2424,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2405
2424
|
/**
|
|
2406
2425
|
* @note No cookies persist on the document in Node.js: no document.
|
|
2407
2426
|
*/
|
|
2408
|
-
if (typeof location === 'undefined') {
|
|
2427
|
+
if (typeof document === 'undefined' || typeof location === 'undefined') {
|
|
2409
2428
|
return {};
|
|
2410
2429
|
}
|
|
2411
2430
|
switch (request.credentials) {
|
|
@@ -2506,25 +2525,25 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2506
2525
|
}
|
|
2507
2526
|
|
|
2508
2527
|
/**
|
|
2509
|
-
* Parses a given request/response body based on the
|
|
2528
|
+
* Parses a given request/response body based on the "Content-Type" header.
|
|
2510
2529
|
*/
|
|
2511
2530
|
function parseBody(body, headers) {
|
|
2512
2531
|
// Return whatever falsey body value is given.
|
|
2513
2532
|
if (!body) {
|
|
2514
2533
|
return body;
|
|
2515
2534
|
}
|
|
2516
|
-
const contentType = headers === null || headers === void 0 ? void 0 : headers.get('content-type');
|
|
2535
|
+
const contentType = (headers === null || headers === void 0 ? void 0 : headers.get('content-type')) || '';
|
|
2517
2536
|
// If the body has a Multipart Content-Type
|
|
2518
2537
|
// parse it into an object.
|
|
2519
|
-
const hasMultipartContent = contentType
|
|
2538
|
+
const hasMultipartContent = contentType.startsWith('multipart/form-data');
|
|
2520
2539
|
if (hasMultipartContent && typeof body !== 'object') {
|
|
2521
|
-
return parseMultipartData(body, headers) || body;
|
|
2540
|
+
return parseMultipartData(body.toString(), headers) || body;
|
|
2522
2541
|
}
|
|
2523
2542
|
// If the intercepted request's body has a JSON Content-Type
|
|
2524
2543
|
// parse it into an object.
|
|
2525
|
-
const hasJsonContent = contentType
|
|
2544
|
+
const hasJsonContent = contentType.includes('json');
|
|
2526
2545
|
if (hasJsonContent && typeof body !== 'object') {
|
|
2527
|
-
return jsonParse(body) || body;
|
|
2546
|
+
return jsonParse(body.toString()) || body;
|
|
2528
2547
|
}
|
|
2529
2548
|
// Otherwise leave as-is.
|
|
2530
2549
|
return body;
|
|
@@ -3826,7 +3845,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
3826
3845
|
|
|
3827
3846
|
directiveLocation.DirectiveLocation = DirectiveLocation;
|
|
3828
3847
|
|
|
3829
|
-
var lexer = {};
|
|
3848
|
+
var lexer$1 = {};
|
|
3830
3849
|
|
|
3831
3850
|
var blockString = {};
|
|
3832
3851
|
|
|
@@ -3963,11 +3982,11 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
3963
3982
|
return '"""' + result.replace(/"""/g, '\\"""') + '"""';
|
|
3964
3983
|
}
|
|
3965
3984
|
|
|
3966
|
-
Object.defineProperty(lexer, "__esModule", {
|
|
3985
|
+
Object.defineProperty(lexer$1, "__esModule", {
|
|
3967
3986
|
value: true
|
|
3968
3987
|
});
|
|
3969
|
-
lexer.isPunctuatorTokenKind = isPunctuatorTokenKind;
|
|
3970
|
-
lexer.Lexer = void 0;
|
|
3988
|
+
lexer$1.isPunctuatorTokenKind = isPunctuatorTokenKind;
|
|
3989
|
+
lexer$1.Lexer = void 0;
|
|
3971
3990
|
|
|
3972
3991
|
var _syntaxError$1 = syntaxError$1;
|
|
3973
3992
|
|
|
@@ -4049,7 +4068,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
4049
4068
|
*/
|
|
4050
4069
|
|
|
4051
4070
|
|
|
4052
|
-
lexer.Lexer = Lexer;
|
|
4071
|
+
lexer$1.Lexer = Lexer;
|
|
4053
4072
|
|
|
4054
4073
|
function isPunctuatorTokenKind(kind) {
|
|
4055
4074
|
return kind === _tokenKind$3.TokenKind.BANG || kind === _tokenKind$3.TokenKind.DOLLAR || kind === _tokenKind$3.TokenKind.AMP || kind === _tokenKind$3.TokenKind.PAREN_L || kind === _tokenKind$3.TokenKind.PAREN_R || kind === _tokenKind$3.TokenKind.SPREAD || kind === _tokenKind$3.TokenKind.COLON || kind === _tokenKind$3.TokenKind.EQUALS || kind === _tokenKind$3.TokenKind.AT || kind === _tokenKind$3.TokenKind.BRACKET_L || kind === _tokenKind$3.TokenKind.BRACKET_R || kind === _tokenKind$3.TokenKind.BRACE_L || kind === _tokenKind$3.TokenKind.PIPE || kind === _tokenKind$3.TokenKind.BRACE_R;
|
|
@@ -4655,7 +4674,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
4655
4674
|
Object.defineProperty(parser, "__esModule", {
|
|
4656
4675
|
value: true
|
|
4657
4676
|
});
|
|
4658
|
-
parser.parse = parse$
|
|
4677
|
+
parser.parse = parse$3;
|
|
4659
4678
|
parser.parseValue = parseValue;
|
|
4660
4679
|
parser.parseType = parseType;
|
|
4661
4680
|
parser.Parser = void 0;
|
|
@@ -4672,13 +4691,13 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
4672
4691
|
|
|
4673
4692
|
var _directiveLocation$3 = directiveLocation;
|
|
4674
4693
|
|
|
4675
|
-
var _lexer$1 = lexer;
|
|
4694
|
+
var _lexer$1 = lexer$1;
|
|
4676
4695
|
|
|
4677
4696
|
/**
|
|
4678
4697
|
* Given a GraphQL source, parses it into a Document.
|
|
4679
4698
|
* Throws GraphQLError if a syntax error is encountered.
|
|
4680
4699
|
*/
|
|
4681
|
-
function parse$
|
|
4700
|
+
function parse$3(source, options) {
|
|
4682
4701
|
var parser = new Parser(source, options);
|
|
4683
4702
|
return parser.parseDocument();
|
|
4684
4703
|
}
|
|
@@ -17337,7 +17356,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
17337
17356
|
|
|
17338
17357
|
var _tokenKind = tokenKind;
|
|
17339
17358
|
|
|
17340
|
-
var _lexer = lexer;
|
|
17359
|
+
var _lexer = lexer$1;
|
|
17341
17360
|
|
|
17342
17361
|
var _parser = parser;
|
|
17343
17362
|
|
|
@@ -20153,7 +20172,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
20153
20172
|
|
|
20154
20173
|
var _tokenKind = tokenKind;
|
|
20155
20174
|
|
|
20156
|
-
var _lexer = lexer;
|
|
20175
|
+
var _lexer = lexer$1;
|
|
20157
20176
|
|
|
20158
20177
|
var _blockString = blockString;
|
|
20159
20178
|
|
|
@@ -22433,51 +22452,414 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
22433
22452
|
body: parseBody(res.body, responseHeaders) });
|
|
22434
22453
|
}
|
|
22435
22454
|
|
|
22436
|
-
var
|
|
22437
|
-
|
|
22438
|
-
Object.defineProperty(cjs, '__esModule', { value: true });
|
|
22439
|
-
|
|
22440
|
-
/**
|
|
22441
|
-
* Converts a string path to a Regular Expression.
|
|
22442
|
-
* Transforms path parameters into named RegExp groups.
|
|
22443
|
-
*/
|
|
22444
|
-
const pathToRegExp = (path) => {
|
|
22445
|
-
const pattern = path
|
|
22446
|
-
// Escape literal dots
|
|
22447
|
-
.replace(/\./g, '\\.')
|
|
22448
|
-
// Escape literal slashes
|
|
22449
|
-
.replace(/\//g, '/')
|
|
22450
|
-
// Escape literal question marks
|
|
22451
|
-
.replace(/\?/g, '\\?')
|
|
22452
|
-
// Ignore trailing slashes
|
|
22453
|
-
.replace(/\/+$/, '')
|
|
22454
|
-
// Replace wildcard with any zero-to-any character sequence
|
|
22455
|
-
.replace(/\*+/g, '.*')
|
|
22456
|
-
// Replace parameters with named capturing groups
|
|
22457
|
-
.replace(/:([^\d|^\/][a-zA-Z0-9_]*(?=(?:\/|\\.)|$))/g, (_, paramName) => `(?<${paramName}>[^\/]+?)`)
|
|
22458
|
-
// Allow optional trailing slash
|
|
22459
|
-
.concat('(\\/|$)');
|
|
22460
|
-
return new RegExp(pattern, 'gi');
|
|
22461
|
-
};
|
|
22462
|
-
|
|
22463
|
-
/**
|
|
22464
|
-
* Matches a given url against a path.
|
|
22465
|
-
*/
|
|
22466
|
-
const match = (path, url) => {
|
|
22467
|
-
const expression = path instanceof RegExp ? path : pathToRegExp(path);
|
|
22468
|
-
const match = expression.exec(url) || false;
|
|
22469
|
-
// Matches in strict mode: match string should equal to input (url)
|
|
22470
|
-
// Otherwise loose matches will be considered truthy:
|
|
22471
|
-
// match('/messages/:id', '/messages/123/users') // true
|
|
22472
|
-
const matches = path instanceof RegExp ? !!match : !!match && match[0] === match.input;
|
|
22473
|
-
return {
|
|
22474
|
-
matches,
|
|
22475
|
-
params: match && matches ? match.groups || null : null,
|
|
22476
|
-
};
|
|
22477
|
-
};
|
|
22455
|
+
var dist = {};
|
|
22478
22456
|
|
|
22479
|
-
|
|
22480
|
-
|
|
22457
|
+
Object.defineProperty(dist, "__esModule", { value: true });
|
|
22458
|
+
dist.pathToRegexp = dist.tokensToRegexp = dist.regexpToFunction = match_1 = dist.match = dist.tokensToFunction = dist.compile = dist.parse = void 0;
|
|
22459
|
+
/**
|
|
22460
|
+
* Tokenize input string.
|
|
22461
|
+
*/
|
|
22462
|
+
function lexer(str) {
|
|
22463
|
+
var tokens = [];
|
|
22464
|
+
var i = 0;
|
|
22465
|
+
while (i < str.length) {
|
|
22466
|
+
var char = str[i];
|
|
22467
|
+
if (char === "*" || char === "+" || char === "?") {
|
|
22468
|
+
tokens.push({ type: "MODIFIER", index: i, value: str[i++] });
|
|
22469
|
+
continue;
|
|
22470
|
+
}
|
|
22471
|
+
if (char === "\\") {
|
|
22472
|
+
tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] });
|
|
22473
|
+
continue;
|
|
22474
|
+
}
|
|
22475
|
+
if (char === "{") {
|
|
22476
|
+
tokens.push({ type: "OPEN", index: i, value: str[i++] });
|
|
22477
|
+
continue;
|
|
22478
|
+
}
|
|
22479
|
+
if (char === "}") {
|
|
22480
|
+
tokens.push({ type: "CLOSE", index: i, value: str[i++] });
|
|
22481
|
+
continue;
|
|
22482
|
+
}
|
|
22483
|
+
if (char === ":") {
|
|
22484
|
+
var name = "";
|
|
22485
|
+
var j = i + 1;
|
|
22486
|
+
while (j < str.length) {
|
|
22487
|
+
var code = str.charCodeAt(j);
|
|
22488
|
+
if (
|
|
22489
|
+
// `0-9`
|
|
22490
|
+
(code >= 48 && code <= 57) ||
|
|
22491
|
+
// `A-Z`
|
|
22492
|
+
(code >= 65 && code <= 90) ||
|
|
22493
|
+
// `a-z`
|
|
22494
|
+
(code >= 97 && code <= 122) ||
|
|
22495
|
+
// `_`
|
|
22496
|
+
code === 95) {
|
|
22497
|
+
name += str[j++];
|
|
22498
|
+
continue;
|
|
22499
|
+
}
|
|
22500
|
+
break;
|
|
22501
|
+
}
|
|
22502
|
+
if (!name)
|
|
22503
|
+
throw new TypeError("Missing parameter name at " + i);
|
|
22504
|
+
tokens.push({ type: "NAME", index: i, value: name });
|
|
22505
|
+
i = j;
|
|
22506
|
+
continue;
|
|
22507
|
+
}
|
|
22508
|
+
if (char === "(") {
|
|
22509
|
+
var count = 1;
|
|
22510
|
+
var pattern = "";
|
|
22511
|
+
var j = i + 1;
|
|
22512
|
+
if (str[j] === "?") {
|
|
22513
|
+
throw new TypeError("Pattern cannot start with \"?\" at " + j);
|
|
22514
|
+
}
|
|
22515
|
+
while (j < str.length) {
|
|
22516
|
+
if (str[j] === "\\") {
|
|
22517
|
+
pattern += str[j++] + str[j++];
|
|
22518
|
+
continue;
|
|
22519
|
+
}
|
|
22520
|
+
if (str[j] === ")") {
|
|
22521
|
+
count--;
|
|
22522
|
+
if (count === 0) {
|
|
22523
|
+
j++;
|
|
22524
|
+
break;
|
|
22525
|
+
}
|
|
22526
|
+
}
|
|
22527
|
+
else if (str[j] === "(") {
|
|
22528
|
+
count++;
|
|
22529
|
+
if (str[j + 1] !== "?") {
|
|
22530
|
+
throw new TypeError("Capturing groups are not allowed at " + j);
|
|
22531
|
+
}
|
|
22532
|
+
}
|
|
22533
|
+
pattern += str[j++];
|
|
22534
|
+
}
|
|
22535
|
+
if (count)
|
|
22536
|
+
throw new TypeError("Unbalanced pattern at " + i);
|
|
22537
|
+
if (!pattern)
|
|
22538
|
+
throw new TypeError("Missing pattern at " + i);
|
|
22539
|
+
tokens.push({ type: "PATTERN", index: i, value: pattern });
|
|
22540
|
+
i = j;
|
|
22541
|
+
continue;
|
|
22542
|
+
}
|
|
22543
|
+
tokens.push({ type: "CHAR", index: i, value: str[i++] });
|
|
22544
|
+
}
|
|
22545
|
+
tokens.push({ type: "END", index: i, value: "" });
|
|
22546
|
+
return tokens;
|
|
22547
|
+
}
|
|
22548
|
+
/**
|
|
22549
|
+
* Parse a string for the raw tokens.
|
|
22550
|
+
*/
|
|
22551
|
+
function parse$2(str, options) {
|
|
22552
|
+
if (options === void 0) { options = {}; }
|
|
22553
|
+
var tokens = lexer(str);
|
|
22554
|
+
var _a = options.prefixes, prefixes = _a === void 0 ? "./" : _a;
|
|
22555
|
+
var defaultPattern = "[^" + escapeString(options.delimiter || "/#?") + "]+?";
|
|
22556
|
+
var result = [];
|
|
22557
|
+
var key = 0;
|
|
22558
|
+
var i = 0;
|
|
22559
|
+
var path = "";
|
|
22560
|
+
var tryConsume = function (type) {
|
|
22561
|
+
if (i < tokens.length && tokens[i].type === type)
|
|
22562
|
+
return tokens[i++].value;
|
|
22563
|
+
};
|
|
22564
|
+
var mustConsume = function (type) {
|
|
22565
|
+
var value = tryConsume(type);
|
|
22566
|
+
if (value !== undefined)
|
|
22567
|
+
return value;
|
|
22568
|
+
var _a = tokens[i], nextType = _a.type, index = _a.index;
|
|
22569
|
+
throw new TypeError("Unexpected " + nextType + " at " + index + ", expected " + type);
|
|
22570
|
+
};
|
|
22571
|
+
var consumeText = function () {
|
|
22572
|
+
var result = "";
|
|
22573
|
+
var value;
|
|
22574
|
+
// tslint:disable-next-line
|
|
22575
|
+
while ((value = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR"))) {
|
|
22576
|
+
result += value;
|
|
22577
|
+
}
|
|
22578
|
+
return result;
|
|
22579
|
+
};
|
|
22580
|
+
while (i < tokens.length) {
|
|
22581
|
+
var char = tryConsume("CHAR");
|
|
22582
|
+
var name = tryConsume("NAME");
|
|
22583
|
+
var pattern = tryConsume("PATTERN");
|
|
22584
|
+
if (name || pattern) {
|
|
22585
|
+
var prefix = char || "";
|
|
22586
|
+
if (prefixes.indexOf(prefix) === -1) {
|
|
22587
|
+
path += prefix;
|
|
22588
|
+
prefix = "";
|
|
22589
|
+
}
|
|
22590
|
+
if (path) {
|
|
22591
|
+
result.push(path);
|
|
22592
|
+
path = "";
|
|
22593
|
+
}
|
|
22594
|
+
result.push({
|
|
22595
|
+
name: name || key++,
|
|
22596
|
+
prefix: prefix,
|
|
22597
|
+
suffix: "",
|
|
22598
|
+
pattern: pattern || defaultPattern,
|
|
22599
|
+
modifier: tryConsume("MODIFIER") || ""
|
|
22600
|
+
});
|
|
22601
|
+
continue;
|
|
22602
|
+
}
|
|
22603
|
+
var value = char || tryConsume("ESCAPED_CHAR");
|
|
22604
|
+
if (value) {
|
|
22605
|
+
path += value;
|
|
22606
|
+
continue;
|
|
22607
|
+
}
|
|
22608
|
+
if (path) {
|
|
22609
|
+
result.push(path);
|
|
22610
|
+
path = "";
|
|
22611
|
+
}
|
|
22612
|
+
var open = tryConsume("OPEN");
|
|
22613
|
+
if (open) {
|
|
22614
|
+
var prefix = consumeText();
|
|
22615
|
+
var name_1 = tryConsume("NAME") || "";
|
|
22616
|
+
var pattern_1 = tryConsume("PATTERN") || "";
|
|
22617
|
+
var suffix = consumeText();
|
|
22618
|
+
mustConsume("CLOSE");
|
|
22619
|
+
result.push({
|
|
22620
|
+
name: name_1 || (pattern_1 ? key++ : ""),
|
|
22621
|
+
pattern: name_1 && !pattern_1 ? defaultPattern : pattern_1,
|
|
22622
|
+
prefix: prefix,
|
|
22623
|
+
suffix: suffix,
|
|
22624
|
+
modifier: tryConsume("MODIFIER") || ""
|
|
22625
|
+
});
|
|
22626
|
+
continue;
|
|
22627
|
+
}
|
|
22628
|
+
mustConsume("END");
|
|
22629
|
+
}
|
|
22630
|
+
return result;
|
|
22631
|
+
}
|
|
22632
|
+
dist.parse = parse$2;
|
|
22633
|
+
/**
|
|
22634
|
+
* Compile a string to a template function for the path.
|
|
22635
|
+
*/
|
|
22636
|
+
function compile(str, options) {
|
|
22637
|
+
return tokensToFunction(parse$2(str, options), options);
|
|
22638
|
+
}
|
|
22639
|
+
dist.compile = compile;
|
|
22640
|
+
/**
|
|
22641
|
+
* Expose a method for transforming tokens into the path function.
|
|
22642
|
+
*/
|
|
22643
|
+
function tokensToFunction(tokens, options) {
|
|
22644
|
+
if (options === void 0) { options = {}; }
|
|
22645
|
+
var reFlags = flags(options);
|
|
22646
|
+
var _a = options.encode, encode = _a === void 0 ? function (x) { return x; } : _a, _b = options.validate, validate = _b === void 0 ? true : _b;
|
|
22647
|
+
// Compile all the tokens into regexps.
|
|
22648
|
+
var matches = tokens.map(function (token) {
|
|
22649
|
+
if (typeof token === "object") {
|
|
22650
|
+
return new RegExp("^(?:" + token.pattern + ")$", reFlags);
|
|
22651
|
+
}
|
|
22652
|
+
});
|
|
22653
|
+
return function (data) {
|
|
22654
|
+
var path = "";
|
|
22655
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
22656
|
+
var token = tokens[i];
|
|
22657
|
+
if (typeof token === "string") {
|
|
22658
|
+
path += token;
|
|
22659
|
+
continue;
|
|
22660
|
+
}
|
|
22661
|
+
var value = data ? data[token.name] : undefined;
|
|
22662
|
+
var optional = token.modifier === "?" || token.modifier === "*";
|
|
22663
|
+
var repeat = token.modifier === "*" || token.modifier === "+";
|
|
22664
|
+
if (Array.isArray(value)) {
|
|
22665
|
+
if (!repeat) {
|
|
22666
|
+
throw new TypeError("Expected \"" + token.name + "\" to not repeat, but got an array");
|
|
22667
|
+
}
|
|
22668
|
+
if (value.length === 0) {
|
|
22669
|
+
if (optional)
|
|
22670
|
+
continue;
|
|
22671
|
+
throw new TypeError("Expected \"" + token.name + "\" to not be empty");
|
|
22672
|
+
}
|
|
22673
|
+
for (var j = 0; j < value.length; j++) {
|
|
22674
|
+
var segment = encode(value[j], token);
|
|
22675
|
+
if (validate && !matches[i].test(segment)) {
|
|
22676
|
+
throw new TypeError("Expected all \"" + token.name + "\" to match \"" + token.pattern + "\", but got \"" + segment + "\"");
|
|
22677
|
+
}
|
|
22678
|
+
path += token.prefix + segment + token.suffix;
|
|
22679
|
+
}
|
|
22680
|
+
continue;
|
|
22681
|
+
}
|
|
22682
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
22683
|
+
var segment = encode(String(value), token);
|
|
22684
|
+
if (validate && !matches[i].test(segment)) {
|
|
22685
|
+
throw new TypeError("Expected \"" + token.name + "\" to match \"" + token.pattern + "\", but got \"" + segment + "\"");
|
|
22686
|
+
}
|
|
22687
|
+
path += token.prefix + segment + token.suffix;
|
|
22688
|
+
continue;
|
|
22689
|
+
}
|
|
22690
|
+
if (optional)
|
|
22691
|
+
continue;
|
|
22692
|
+
var typeOfMessage = repeat ? "an array" : "a string";
|
|
22693
|
+
throw new TypeError("Expected \"" + token.name + "\" to be " + typeOfMessage);
|
|
22694
|
+
}
|
|
22695
|
+
return path;
|
|
22696
|
+
};
|
|
22697
|
+
}
|
|
22698
|
+
dist.tokensToFunction = tokensToFunction;
|
|
22699
|
+
/**
|
|
22700
|
+
* Create path match function from `path-to-regexp` spec.
|
|
22701
|
+
*/
|
|
22702
|
+
function match(str, options) {
|
|
22703
|
+
var keys = [];
|
|
22704
|
+
var re = pathToRegexp(str, keys, options);
|
|
22705
|
+
return regexpToFunction(re, keys, options);
|
|
22706
|
+
}
|
|
22707
|
+
var match_1 = dist.match = match;
|
|
22708
|
+
/**
|
|
22709
|
+
* Create a path match function from `path-to-regexp` output.
|
|
22710
|
+
*/
|
|
22711
|
+
function regexpToFunction(re, keys, options) {
|
|
22712
|
+
if (options === void 0) { options = {}; }
|
|
22713
|
+
var _a = options.decode, decode = _a === void 0 ? function (x) { return x; } : _a;
|
|
22714
|
+
return function (pathname) {
|
|
22715
|
+
var m = re.exec(pathname);
|
|
22716
|
+
if (!m)
|
|
22717
|
+
return false;
|
|
22718
|
+
var path = m[0], index = m.index;
|
|
22719
|
+
var params = Object.create(null);
|
|
22720
|
+
var _loop_1 = function (i) {
|
|
22721
|
+
// tslint:disable-next-line
|
|
22722
|
+
if (m[i] === undefined)
|
|
22723
|
+
return "continue";
|
|
22724
|
+
var key = keys[i - 1];
|
|
22725
|
+
if (key.modifier === "*" || key.modifier === "+") {
|
|
22726
|
+
params[key.name] = m[i].split(key.prefix + key.suffix).map(function (value) {
|
|
22727
|
+
return decode(value, key);
|
|
22728
|
+
});
|
|
22729
|
+
}
|
|
22730
|
+
else {
|
|
22731
|
+
params[key.name] = decode(m[i], key);
|
|
22732
|
+
}
|
|
22733
|
+
};
|
|
22734
|
+
for (var i = 1; i < m.length; i++) {
|
|
22735
|
+
_loop_1(i);
|
|
22736
|
+
}
|
|
22737
|
+
return { path: path, index: index, params: params };
|
|
22738
|
+
};
|
|
22739
|
+
}
|
|
22740
|
+
dist.regexpToFunction = regexpToFunction;
|
|
22741
|
+
/**
|
|
22742
|
+
* Escape a regular expression string.
|
|
22743
|
+
*/
|
|
22744
|
+
function escapeString(str) {
|
|
22745
|
+
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
|
|
22746
|
+
}
|
|
22747
|
+
/**
|
|
22748
|
+
* Get the flags for a regexp from the options.
|
|
22749
|
+
*/
|
|
22750
|
+
function flags(options) {
|
|
22751
|
+
return options && options.sensitive ? "" : "i";
|
|
22752
|
+
}
|
|
22753
|
+
/**
|
|
22754
|
+
* Pull out keys from a regexp.
|
|
22755
|
+
*/
|
|
22756
|
+
function regexpToRegexp(path, keys) {
|
|
22757
|
+
if (!keys)
|
|
22758
|
+
return path;
|
|
22759
|
+
var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g;
|
|
22760
|
+
var index = 0;
|
|
22761
|
+
var execResult = groupsRegex.exec(path.source);
|
|
22762
|
+
while (execResult) {
|
|
22763
|
+
keys.push({
|
|
22764
|
+
// Use parenthesized substring match if available, index otherwise
|
|
22765
|
+
name: execResult[1] || index++,
|
|
22766
|
+
prefix: "",
|
|
22767
|
+
suffix: "",
|
|
22768
|
+
modifier: "",
|
|
22769
|
+
pattern: ""
|
|
22770
|
+
});
|
|
22771
|
+
execResult = groupsRegex.exec(path.source);
|
|
22772
|
+
}
|
|
22773
|
+
return path;
|
|
22774
|
+
}
|
|
22775
|
+
/**
|
|
22776
|
+
* Transform an array into a regexp.
|
|
22777
|
+
*/
|
|
22778
|
+
function arrayToRegexp(paths, keys, options) {
|
|
22779
|
+
var parts = paths.map(function (path) { return pathToRegexp(path, keys, options).source; });
|
|
22780
|
+
return new RegExp("(?:" + parts.join("|") + ")", flags(options));
|
|
22781
|
+
}
|
|
22782
|
+
/**
|
|
22783
|
+
* Create a path regexp from string input.
|
|
22784
|
+
*/
|
|
22785
|
+
function stringToRegexp(path, keys, options) {
|
|
22786
|
+
return tokensToRegexp(parse$2(path, options), keys, options);
|
|
22787
|
+
}
|
|
22788
|
+
/**
|
|
22789
|
+
* Expose a function for taking tokens and returning a RegExp.
|
|
22790
|
+
*/
|
|
22791
|
+
function tokensToRegexp(tokens, keys, options) {
|
|
22792
|
+
if (options === void 0) { options = {}; }
|
|
22793
|
+
var _a = options.strict, strict = _a === void 0 ? false : _a, _b = options.start, start = _b === void 0 ? true : _b, _c = options.end, end = _c === void 0 ? true : _c, _d = options.encode, encode = _d === void 0 ? function (x) { return x; } : _d;
|
|
22794
|
+
var endsWith = "[" + escapeString(options.endsWith || "") + "]|$";
|
|
22795
|
+
var delimiter = "[" + escapeString(options.delimiter || "/#?") + "]";
|
|
22796
|
+
var route = start ? "^" : "";
|
|
22797
|
+
// Iterate over the tokens and create our regexp string.
|
|
22798
|
+
for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
|
|
22799
|
+
var token = tokens_1[_i];
|
|
22800
|
+
if (typeof token === "string") {
|
|
22801
|
+
route += escapeString(encode(token));
|
|
22802
|
+
}
|
|
22803
|
+
else {
|
|
22804
|
+
var prefix = escapeString(encode(token.prefix));
|
|
22805
|
+
var suffix = escapeString(encode(token.suffix));
|
|
22806
|
+
if (token.pattern) {
|
|
22807
|
+
if (keys)
|
|
22808
|
+
keys.push(token);
|
|
22809
|
+
if (prefix || suffix) {
|
|
22810
|
+
if (token.modifier === "+" || token.modifier === "*") {
|
|
22811
|
+
var mod = token.modifier === "*" ? "?" : "";
|
|
22812
|
+
route += "(?:" + prefix + "((?:" + token.pattern + ")(?:" + suffix + prefix + "(?:" + token.pattern + "))*)" + suffix + ")" + mod;
|
|
22813
|
+
}
|
|
22814
|
+
else {
|
|
22815
|
+
route += "(?:" + prefix + "(" + token.pattern + ")" + suffix + ")" + token.modifier;
|
|
22816
|
+
}
|
|
22817
|
+
}
|
|
22818
|
+
else {
|
|
22819
|
+
route += "(" + token.pattern + ")" + token.modifier;
|
|
22820
|
+
}
|
|
22821
|
+
}
|
|
22822
|
+
else {
|
|
22823
|
+
route += "(?:" + prefix + suffix + ")" + token.modifier;
|
|
22824
|
+
}
|
|
22825
|
+
}
|
|
22826
|
+
}
|
|
22827
|
+
if (end) {
|
|
22828
|
+
if (!strict)
|
|
22829
|
+
route += delimiter + "?";
|
|
22830
|
+
route += !options.endsWith ? "$" : "(?=" + endsWith + ")";
|
|
22831
|
+
}
|
|
22832
|
+
else {
|
|
22833
|
+
var endToken = tokens[tokens.length - 1];
|
|
22834
|
+
var isEndDelimited = typeof endToken === "string"
|
|
22835
|
+
? delimiter.indexOf(endToken[endToken.length - 1]) > -1
|
|
22836
|
+
: // tslint:disable-next-line
|
|
22837
|
+
endToken === undefined;
|
|
22838
|
+
if (!strict) {
|
|
22839
|
+
route += "(?:" + delimiter + "(?=" + endsWith + "))?";
|
|
22840
|
+
}
|
|
22841
|
+
if (!isEndDelimited) {
|
|
22842
|
+
route += "(?=" + delimiter + "|" + endsWith + ")";
|
|
22843
|
+
}
|
|
22844
|
+
}
|
|
22845
|
+
return new RegExp(route, flags(options));
|
|
22846
|
+
}
|
|
22847
|
+
dist.tokensToRegexp = tokensToRegexp;
|
|
22848
|
+
/**
|
|
22849
|
+
* Normalize the given path string, returning a regular expression.
|
|
22850
|
+
*
|
|
22851
|
+
* An empty array can be passed in for the keys, which will hold the
|
|
22852
|
+
* placeholder key descriptions. For example, using `/user/:id`, `keys` will
|
|
22853
|
+
* contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
|
|
22854
|
+
*/
|
|
22855
|
+
function pathToRegexp(path, keys, options) {
|
|
22856
|
+
if (path instanceof RegExp)
|
|
22857
|
+
return regexpToRegexp(path, keys);
|
|
22858
|
+
if (Array.isArray(path))
|
|
22859
|
+
return arrayToRegexp(path, keys, options);
|
|
22860
|
+
return stringToRegexp(path, keys, options);
|
|
22861
|
+
}
|
|
22862
|
+
dist.pathToRegexp = pathToRegexp;
|
|
22481
22863
|
|
|
22482
22864
|
var getCleanUrl$1 = {};
|
|
22483
22865
|
|
|
@@ -22512,8 +22894,8 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
22512
22894
|
return path;
|
|
22513
22895
|
}
|
|
22514
22896
|
// Resolve a relative request URL against a given custom "baseUrl"
|
|
22515
|
-
// or the
|
|
22516
|
-
const origin = baseUrl || (typeof
|
|
22897
|
+
// or the document baseURI (in the case of browser/browser-like environments).
|
|
22898
|
+
const origin = baseUrl || (typeof document !== 'undefined' && document.baseURI);
|
|
22517
22899
|
return origin
|
|
22518
22900
|
? // Encode and decode the path to preserve escaped characters.
|
|
22519
22901
|
decodeURI(new URL(encodeURI(path), origin).href)
|
|
@@ -22536,12 +22918,48 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
22536
22918
|
return cleanUrl(maybeAbsoluteUrl);
|
|
22537
22919
|
}
|
|
22538
22920
|
|
|
22921
|
+
/**
|
|
22922
|
+
* Coerce a path supported by MSW into a path
|
|
22923
|
+
* supported by "path-to-regexp".
|
|
22924
|
+
*/
|
|
22925
|
+
function coercePath(path) {
|
|
22926
|
+
return (path
|
|
22927
|
+
/**
|
|
22928
|
+
* Replace wildcards ("*") with unnamed capturing groups
|
|
22929
|
+
* because "path-to-regexp" doesn't support wildcards.
|
|
22930
|
+
* Ignore path parameter' modifiers (i.e. ":name*").
|
|
22931
|
+
*/
|
|
22932
|
+
.replace(/([:a-zA-Z_-]*)(\*{1,2})+/g, (_, parameterName, wildcard) => {
|
|
22933
|
+
const expression = '(.*)';
|
|
22934
|
+
if (!parameterName) {
|
|
22935
|
+
return expression;
|
|
22936
|
+
}
|
|
22937
|
+
return parameterName.startsWith(':')
|
|
22938
|
+
? `${parameterName}${wildcard}`
|
|
22939
|
+
: `${parameterName}${expression}`;
|
|
22940
|
+
})
|
|
22941
|
+
/**
|
|
22942
|
+
* Escape the protocol so that "path-to-regexp" could match
|
|
22943
|
+
* absolute URL.
|
|
22944
|
+
* @see https://github.com/pillarjs/path-to-regexp/issues/259
|
|
22945
|
+
*/
|
|
22946
|
+
.replace(/^([^\/]+)(:)(?=\/\/)/g, '$1\\$2'));
|
|
22947
|
+
}
|
|
22539
22948
|
/**
|
|
22540
22949
|
* Returns the result of matching given request URL against a mask.
|
|
22541
22950
|
*/
|
|
22542
22951
|
function matchRequestUrl(url, path, baseUrl) {
|
|
22543
22952
|
const normalizedPath = normalizePath(path, baseUrl);
|
|
22544
|
-
|
|
22953
|
+
const cleanPath = typeof normalizedPath === 'string'
|
|
22954
|
+
? coercePath(normalizedPath)
|
|
22955
|
+
: normalizedPath;
|
|
22956
|
+
const cleanUrl = getCleanUrl_2(url);
|
|
22957
|
+
const result = match_1(cleanPath, { decode: decodeURIComponent })(cleanUrl);
|
|
22958
|
+
const params = (result && result.params) || {};
|
|
22959
|
+
return {
|
|
22960
|
+
matches: result !== false,
|
|
22961
|
+
params,
|
|
22962
|
+
};
|
|
22545
22963
|
}
|
|
22546
22964
|
|
|
22547
22965
|
/**
|
|
@@ -22590,18 +23008,21 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
22590
23008
|
},
|
|
22591
23009
|
});
|
|
22592
23010
|
|
|
23011
|
+
const BUILD_FRAME = /(node_modules)?[\/\\]lib[\/\\](umd|esm|iief|cjs)[\/\\]|^[^\/\\]*$/;
|
|
22593
23012
|
/**
|
|
22594
23013
|
* Return the stack trace frame of a function's invocation.
|
|
22595
23014
|
*/
|
|
22596
|
-
function getCallFrame() {
|
|
23015
|
+
function getCallFrame(error) {
|
|
22597
23016
|
// In <IE11, new Error may return an undefined stack
|
|
22598
|
-
const stack =
|
|
22599
|
-
|
|
23017
|
+
const stack = error.stack;
|
|
23018
|
+
if (!stack) {
|
|
23019
|
+
return;
|
|
23020
|
+
}
|
|
23021
|
+
const frames = stack.split('\n').slice(1);
|
|
22600
23022
|
// Get the first frame that doesn't reference the library's internal trace.
|
|
22601
23023
|
// Assume that frame is the invocation frame.
|
|
22602
|
-
const
|
|
22603
|
-
|
|
22604
|
-
return !ignoreFrameRegExp.test(frame);
|
|
23024
|
+
const declarationFrame = frames.find((frame) => {
|
|
23025
|
+
return !BUILD_FRAME.test(frame);
|
|
22605
23026
|
});
|
|
22606
23027
|
if (!declarationFrame) {
|
|
22607
23028
|
return;
|
|
@@ -22634,7 +23055,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
22634
23055
|
this.shouldSkip = false;
|
|
22635
23056
|
this.ctx = options.ctx || defaultContext;
|
|
22636
23057
|
this.resolver = options.resolver;
|
|
22637
|
-
const callFrame = getCallFrame();
|
|
23058
|
+
const callFrame = getCallFrame(new Error());
|
|
22638
23059
|
this.info = Object.assign(Object.assign({}, options.info), { callFrame });
|
|
22639
23060
|
}
|
|
22640
23061
|
/**
|
|
@@ -22761,21 +23182,9 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
22761
23182
|
return;
|
|
22762
23183
|
}
|
|
22763
23184
|
const searchParams = getSearchParams(path);
|
|
22764
|
-
const queryParams = [];
|
|
22765
23185
|
searchParams.forEach((_, paramName) => {
|
|
22766
|
-
queryParams.push(paramName);
|
|
22767
23186
|
});
|
|
22768
|
-
devUtils.warn(
|
|
22769
|
-
Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead, and access query parameters in the response resolver function:
|
|
22770
|
-
|
|
22771
|
-
rest.${method.toLowerCase()}("${url}", (req, res, ctx) => {
|
|
22772
|
-
const query = req.url.searchParams
|
|
22773
|
-
${queryParams
|
|
22774
|
-
.map((paramName) => `\
|
|
22775
|
-
const ${paramName} = query.get("${paramName}")`)
|
|
22776
|
-
.join('\n')}
|
|
22777
|
-
})\
|
|
22778
|
-
`);
|
|
23187
|
+
devUtils.warn(`Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead and access query parameters in the response resolver function using "req.url.searchParams".`);
|
|
22779
23188
|
}
|
|
22780
23189
|
parse(request, resolutionContext) {
|
|
22781
23190
|
return matchRequestUrl(request.url, this.info.path, resolutionContext === null || resolutionContext === void 0 ? void 0 : resolutionContext.baseUrl);
|
|
@@ -22784,7 +23193,10 @@ ${queryParams
|
|
|
22784
23193
|
return Object.assign(Object.assign({}, request), { params: parsedResult.params || {} });
|
|
22785
23194
|
}
|
|
22786
23195
|
predicate(request, parsedResult) {
|
|
22787
|
-
|
|
23196
|
+
const matchesMethod = this.info.method instanceof RegExp
|
|
23197
|
+
? this.info.method.test(request.method)
|
|
23198
|
+
: isStringEqual(this.info.method, request.method);
|
|
23199
|
+
return matchesMethod && parsedResult.matches;
|
|
22788
23200
|
}
|
|
22789
23201
|
log(request, response) {
|
|
22790
23202
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
@@ -22818,6 +23230,7 @@ ${queryParams
|
|
|
22818
23230
|
delay,
|
|
22819
23231
|
fetch: fetch$1,
|
|
22820
23232
|
data,
|
|
23233
|
+
extensions,
|
|
22821
23234
|
errors,
|
|
22822
23235
|
cookie,
|
|
22823
23236
|
};
|
|
@@ -22864,10 +23277,10 @@ ${queryParams
|
|
|
22864
23277
|
if (!parsedResult) {
|
|
22865
23278
|
return false;
|
|
22866
23279
|
}
|
|
22867
|
-
if (!parsedResult.operationName) {
|
|
23280
|
+
if (!parsedResult.operationName && this.info.operationType !== 'all') {
|
|
22868
23281
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
22869
23282
|
devUtils.warn(`\
|
|
22870
|
-
Failed to intercept a GraphQL request at "${request.method} ${publicUrl}":
|
|
23283
|
+
Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
22871
23284
|
|
|
22872
23285
|
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\
|
|
22873
23286
|
`);
|
|
@@ -22877,7 +23290,7 @@ Consider naming this operation or using "graphql.operation" request handler to i
|
|
|
22877
23290
|
const hasMatchingOperationType = this.info.operationType === 'all' ||
|
|
22878
23291
|
parsedResult.operationType === this.info.operationType;
|
|
22879
23292
|
const hasMatchingOperationName = this.info.operationName instanceof RegExp
|
|
22880
|
-
? this.info.operationName.test(parsedResult.operationName)
|
|
23293
|
+
? this.info.operationName.test(parsedResult.operationName || '')
|
|
22881
23294
|
: parsedResult.operationName === this.info.operationName;
|
|
22882
23295
|
return (hasMatchingUrl.matches &&
|
|
22883
23296
|
hasMatchingOperationType &&
|
|
@@ -22887,7 +23300,10 @@ Consider naming this operation or using "graphql.operation" request handler to i
|
|
|
22887
23300
|
const loggedRequest = prepareRequest(request);
|
|
22888
23301
|
const loggedResponse = prepareResponse(response);
|
|
22889
23302
|
const statusColor = getStatusCodeColor(response.status);
|
|
22890
|
-
|
|
23303
|
+
const requestInfo = (parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationName)
|
|
23304
|
+
? `${parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationType} ${parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationName}`
|
|
23305
|
+
: `anonymous ${parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationType}`;
|
|
23306
|
+
console.groupCollapsed(devUtils.formatMessage('%s %s (%c%s%c)'), getTimestamp(), `${requestInfo}`, `color:${statusColor}`, `${response.status} ${response.statusText}`, 'color:inherit');
|
|
22891
23307
|
console.log('Request:', loggedRequest);
|
|
22892
23308
|
console.log('Handler:', this);
|
|
22893
23309
|
console.log('Response:', loggedResponse);
|
|
@@ -22912,10 +23328,10 @@ Consider naming this operation or using "graphql.operation" request handler to i
|
|
|
22912
23328
|
graphql: [],
|
|
22913
23329
|
});
|
|
22914
23330
|
}
|
|
22915
|
-
function
|
|
23331
|
+
function getRestHandlerScore() {
|
|
22916
23332
|
return (request, handler) => {
|
|
22917
23333
|
const { path, method } = handler.info;
|
|
22918
|
-
if (path instanceof RegExp) {
|
|
23334
|
+
if (path instanceof RegExp || method instanceof RegExp) {
|
|
22919
23335
|
return Infinity;
|
|
22920
23336
|
}
|
|
22921
23337
|
const hasSameMethod = isStringEqual(request.method, method);
|
|
@@ -22926,12 +23342,15 @@ Consider naming this operation or using "graphql.operation" request handler to i
|
|
|
22926
23342
|
return score - methodScoreDelta;
|
|
22927
23343
|
};
|
|
22928
23344
|
}
|
|
22929
|
-
function
|
|
23345
|
+
function getGraphQLHandlerScore(parsedQuery) {
|
|
22930
23346
|
return (_, handler) => {
|
|
22931
23347
|
if (typeof parsedQuery.operationName === 'undefined') {
|
|
22932
23348
|
return Infinity;
|
|
22933
23349
|
}
|
|
22934
23350
|
const { operationType, operationName } = handler.info;
|
|
23351
|
+
if (typeof operationName !== 'string') {
|
|
23352
|
+
return Infinity;
|
|
23353
|
+
}
|
|
22935
23354
|
const hasSameOperationType = parsedQuery.operationType === operationType;
|
|
22936
23355
|
// Always treat a handler with the same operation type as a more similar one.
|
|
22937
23356
|
const operationTypeScoreDelta = hasSameOperationType ? TYPE_MATCH_DELTA : 0;
|
|
@@ -22941,16 +23360,12 @@ Consider naming this operation or using "graphql.operation" request handler to i
|
|
|
22941
23360
|
}
|
|
22942
23361
|
function getSuggestedHandler(request, handlers, getScore) {
|
|
22943
23362
|
const suggestedHandlers = handlers
|
|
22944
|
-
.reduce((
|
|
23363
|
+
.reduce((suggestions, handler) => {
|
|
22945
23364
|
const score = getScore(request, handler);
|
|
22946
|
-
return
|
|
23365
|
+
return suggestions.concat([[score, handler]]);
|
|
22947
23366
|
}, [])
|
|
22948
|
-
.sort(([leftScore], [rightScore]) =>
|
|
22949
|
-
|
|
22950
|
-
})
|
|
22951
|
-
.filter(([score]) => {
|
|
22952
|
-
return score <= MAX_MATCH_SCORE;
|
|
22953
|
-
})
|
|
23367
|
+
.sort(([leftScore], [rightScore]) => leftScore - rightScore)
|
|
23368
|
+
.filter(([score]) => score <= MAX_MATCH_SCORE)
|
|
22954
23369
|
.slice(0, MAX_SUGGESTION_COUNT)
|
|
22955
23370
|
.map(([, handler]) => handler);
|
|
22956
23371
|
return suggestedHandlers;
|
|
@@ -22980,8 +23395,8 @@ ${handlers.map((handler) => ` • ${handler.info.header}`).join('\n')}`;
|
|
|
22980
23395
|
? handlerGroups.graphql
|
|
22981
23396
|
: handlerGroups.rest;
|
|
22982
23397
|
const suggestedHandlers = getSuggestedHandler(request, relevantHandlers, parsedGraphQLQuery
|
|
22983
|
-
?
|
|
22984
|
-
:
|
|
23398
|
+
? getGraphQLHandlerScore(parsedGraphQLQuery)
|
|
23399
|
+
: getRestHandlerScore());
|
|
22985
23400
|
const handlerSuggestion = suggestedHandlers.length > 0
|
|
22986
23401
|
? getSuggestedHandlersMessage(suggestedHandlers)
|
|
22987
23402
|
: '';
|
|
@@ -23004,7 +23419,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks\
|
|
|
23004
23419
|
// Print a developer-friendly error.
|
|
23005
23420
|
devUtils.error('Error: %s', message);
|
|
23006
23421
|
// Throw an exception to halt request processing and not perform the original request.
|
|
23007
|
-
throw new Error('Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.');
|
|
23422
|
+
throw new Error(devUtils.formatMessage('Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.'));
|
|
23008
23423
|
}
|
|
23009
23424
|
case 'warn': {
|
|
23010
23425
|
devUtils.warn('Warning: %s', message);
|
|
@@ -23047,7 +23462,12 @@ Read more: https://mswjs.io/docs/getting-started/mocks\
|
|
|
23047
23462
|
// When the handled request returned no mocked response, warn the developer,
|
|
23048
23463
|
// as it may be an oversight on their part. Perform the request as-is.
|
|
23049
23464
|
if (!response) {
|
|
23050
|
-
devUtils.warn(
|
|
23465
|
+
devUtils.warn(`\
|
|
23466
|
+
Expected response resolver to return a mocked response Object, but got %s. The original response is going to be used instead.\
|
|
23467
|
+
\n
|
|
23468
|
+
\u2022 %s
|
|
23469
|
+
%s\
|
|
23470
|
+
`, response, handler.info.header, handler.info.callFrame);
|
|
23051
23471
|
emitter.emit('request:end', request);
|
|
23052
23472
|
(_c = handleRequestOptions === null || handleRequestOptions === void 0 ? void 0 : handleRequestOptions.onBypassResponse) === null || _c === void 0 ? void 0 : _c.call(handleRequestOptions, request);
|
|
23053
23473
|
return;
|
|
@@ -23134,8 +23554,8 @@ Read more: https://mswjs.io/docs/getting-started/mocks\
|
|
|
23134
23554
|
const { payload: actualChecksum } = yield context.events.once('INTEGRITY_CHECK_RESPONSE');
|
|
23135
23555
|
// Compare the response from the Service Worker and the
|
|
23136
23556
|
// global variable set by Rollup during the build.
|
|
23137
|
-
if (actualChecksum !== "
|
|
23138
|
-
throw new Error(`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"
|
|
23557
|
+
if (actualChecksum !== "02f4ad4a2797f85668baf196e553d929") {
|
|
23558
|
+
throw new Error(`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"02f4ad4a2797f85668baf196e553d929"}).`);
|
|
23139
23559
|
}
|
|
23140
23560
|
return serviceWorker;
|
|
23141
23561
|
});
|
|
@@ -23589,14 +24009,14 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
23589
24009
|
|
|
23590
24010
|
Object.defineProperty(uuid, "__esModule", { value: true });
|
|
23591
24011
|
uuid.uuidv4 = void 0;
|
|
23592
|
-
function uuidv4
|
|
24012
|
+
function uuidv4() {
|
|
23593
24013
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
23594
24014
|
var r = (Math.random() * 16) | 0;
|
|
23595
24015
|
var v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
23596
24016
|
return v.toString(16);
|
|
23597
24017
|
});
|
|
23598
24018
|
}
|
|
23599
|
-
uuid.uuidv4 = uuidv4
|
|
24019
|
+
uuid.uuidv4 = uuidv4;
|
|
23600
24020
|
|
|
23601
24021
|
var browser = {exports: {}};
|
|
23602
24022
|
|
|
@@ -24404,15 +24824,16 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
24404
24824
|
}
|
|
24405
24825
|
debug$1('no mocked response found, bypassing...');
|
|
24406
24826
|
return [2 /*return*/, pureFetch(input, init).then(function (response) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
24407
|
-
var _a, _b, _c;
|
|
24827
|
+
var cloneResponse, _a, _b, _c;
|
|
24408
24828
|
return __generator$1(this, function (_d) {
|
|
24409
24829
|
switch (_d.label) {
|
|
24410
24830
|
case 0:
|
|
24411
|
-
|
|
24831
|
+
cloneResponse = response.clone();
|
|
24832
|
+
debug$1('original fetch performed', cloneResponse);
|
|
24412
24833
|
_b = (_a = observer).emit;
|
|
24413
24834
|
_c = ['response',
|
|
24414
24835
|
isoRequest];
|
|
24415
|
-
return [4 /*yield*/, normalizeFetchResponse(
|
|
24836
|
+
return [4 /*yield*/, normalizeFetchResponse(cloneResponse)];
|
|
24416
24837
|
case 1:
|
|
24417
24838
|
_b.apply(_a, _c.concat([_d.sent()]));
|
|
24418
24839
|
return [2 /*return*/, response];
|
|
@@ -27873,22 +28294,12 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
27873
28294
|
};
|
|
27874
28295
|
interceptXMLHttpRequest_1 = XMLHttpRequest.interceptXMLHttpRequest = interceptXMLHttpRequest;
|
|
27875
28296
|
|
|
27876
|
-
function uuidv4() {
|
|
27877
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
27878
|
-
const r = (Math.random() * 16) | 0;
|
|
27879
|
-
const v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
27880
|
-
return v.toString(16);
|
|
27881
|
-
});
|
|
27882
|
-
}
|
|
27883
|
-
|
|
27884
28297
|
/**
|
|
27885
28298
|
* Converts a given isomorphic request to a `MockedRequest` instance.
|
|
27886
28299
|
*/
|
|
27887
28300
|
function parseIsomorphicRequest(request) {
|
|
27888
|
-
const requestId = uuidv4();
|
|
27889
|
-
request.headers.set('x-msw-request-id', requestId);
|
|
27890
28301
|
const mockedRequest = {
|
|
27891
|
-
id:
|
|
28302
|
+
id: request.id,
|
|
27892
28303
|
url: request.url,
|
|
27893
28304
|
method: request.method,
|
|
27894
28305
|
body: parseBody(request.body, request.headers),
|
|
@@ -28131,6 +28542,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
28131
28542
|
};
|
|
28132
28543
|
}
|
|
28133
28544
|
const rest = {
|
|
28545
|
+
all: createRestHandler(/.+/),
|
|
28134
28546
|
head: createRestHandler(exports.RESTMethods.HEAD),
|
|
28135
28547
|
get: createRestHandler(exports.RESTMethods.GET),
|
|
28136
28548
|
post: createRestHandler(exports.RESTMethods.POST),
|
|
@@ -28191,6 +28603,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
28191
28603
|
exports.GraphQLHandler = GraphQLHandler;
|
|
28192
28604
|
exports.RequestHandler = RequestHandler;
|
|
28193
28605
|
exports.RestHandler = RestHandler;
|
|
28606
|
+
exports.cleanUrl = cleanUrl;
|
|
28194
28607
|
exports.compose = compose;
|
|
28195
28608
|
exports.context = index;
|
|
28196
28609
|
exports.createResponseComposition = createResponseComposition;
|
|
@@ -28206,4 +28619,4 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
28206
28619
|
exports.restContext = restContext;
|
|
28207
28620
|
exports.setupWorker = setupWorker;
|
|
28208
28621
|
|
|
28209
|
-
}))
|
|
28622
|
+
}));
|