msw 0.0.0-fetch.rc-15 → 0.0.0-fetch.rc-17
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/README.md +13 -8
- package/lib/browser/index.d.ts +0 -6
- package/lib/browser/index.js +14 -32
- package/lib/browser/index.mjs +14 -32
- package/lib/core/NetworkError.d.ts +2 -2
- package/lib/core/SetupApi.d.ts +0 -1
- package/lib/core/handlers/GraphQLHandler.js +1 -1
- package/lib/core/handlers/GraphQLHandler.mjs +1 -1
- package/lib/core/handlers/{RestHandler.d.ts → HttpHandler.d.ts} +12 -12
- package/lib/core/handlers/{RestHandler.js → HttpHandler.js} +16 -16
- package/lib/core/handlers/{RestHandler.mjs → HttpHandler.mjs} +13 -13
- package/lib/core/{rest.d.ts → http.d.ts} +11 -11
- package/lib/core/{rest.js → http.js} +16 -16
- package/lib/core/http.mjs +22 -0
- package/lib/core/{rest.spec.js → http.spec.js} +3 -3
- package/lib/core/{rest.spec.mjs → http.spec.mjs} +3 -3
- package/lib/core/index.d.ts +2 -2
- package/lib/core/index.js +6 -6
- package/lib/core/index.mjs +6 -6
- package/lib/core/passthrough.d.ts +5 -2
- package/lib/core/sharedOptions.d.ts +45 -7
- package/lib/core/utils/handleRequest.js +13 -9
- package/lib/core/utils/handleRequest.mjs +13 -9
- package/lib/core/utils/internal/parseGraphQLRequest.js +4 -3
- package/lib/core/utils/internal/parseGraphQLRequest.mjs +4 -3
- package/lib/core/utils/request/onUnhandledRequest.js +14 -8
- package/lib/core/utils/request/onUnhandledRequest.mjs +15 -9
- package/lib/iife/index.js +97 -104
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.ts +0 -6
- package/lib/native/index.js +5 -13
- package/lib/native/index.mjs +5 -13
- package/lib/node/index.d.ts +0 -6
- package/lib/node/index.js +5 -13
- package/lib/node/index.mjs +5 -13
- package/package.json +2 -1
- package/lib/core/rest.mjs +0 -22
- /package/lib/core/{rest.spec.d.ts → http.spec.d.ts} +0 -0
package/lib/iife/index.js
CHANGED
|
@@ -82,14 +82,14 @@ var MockServiceWorker = (() => {
|
|
|
82
82
|
var iife_exports = {};
|
|
83
83
|
__export(iife_exports, {
|
|
84
84
|
GraphQLHandler: () => GraphQLHandler,
|
|
85
|
+
HttpHandler: () => HttpHandler,
|
|
86
|
+
HttpMethods: () => HttpMethods,
|
|
85
87
|
HttpResponse: () => HttpResponse,
|
|
86
88
|
MAX_SERVER_RESPONSE_TIME: () => MAX_SERVER_RESPONSE_TIME,
|
|
87
89
|
MIN_SERVER_RESPONSE_TIME: () => MIN_SERVER_RESPONSE_TIME,
|
|
88
90
|
NODE_SERVER_RESPONSE_TIME: () => NODE_SERVER_RESPONSE_TIME,
|
|
89
91
|
NetworkError: () => NetworkError,
|
|
90
|
-
RESTMethods: () => RESTMethods,
|
|
91
92
|
RequestHandler: () => RequestHandler,
|
|
92
|
-
RestHandler: () => RestHandler,
|
|
93
93
|
SET_TIMEOUT_MAX_ALLOWED_INT: () => SET_TIMEOUT_MAX_ALLOWED_INT,
|
|
94
94
|
SetupApi: () => SetupApi,
|
|
95
95
|
SetupWorkerApi: () => SetupWorkerApi,
|
|
@@ -98,9 +98,9 @@ var MockServiceWorker = (() => {
|
|
|
98
98
|
delay: () => delay,
|
|
99
99
|
graphql: () => graphql,
|
|
100
100
|
handleRequest: () => handleRequest,
|
|
101
|
+
http: () => http,
|
|
101
102
|
matchRequestUrl: () => matchRequestUrl,
|
|
102
103
|
passthrough: () => passthrough,
|
|
103
|
-
rest: () => rest,
|
|
104
104
|
setupWorker: () => setupWorker
|
|
105
105
|
});
|
|
106
106
|
|
|
@@ -2410,18 +2410,18 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2410
2410
|
return __spreadValues(__spreadValues({}, forwardedCookies), cookiesFromHeaders);
|
|
2411
2411
|
}
|
|
2412
2412
|
|
|
2413
|
-
// src/core/handlers/
|
|
2414
|
-
var
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
return
|
|
2423
|
-
})(
|
|
2424
|
-
var
|
|
2413
|
+
// src/core/handlers/HttpHandler.ts
|
|
2414
|
+
var HttpMethods = /* @__PURE__ */ ((HttpMethods2) => {
|
|
2415
|
+
HttpMethods2["HEAD"] = "HEAD";
|
|
2416
|
+
HttpMethods2["GET"] = "GET";
|
|
2417
|
+
HttpMethods2["POST"] = "POST";
|
|
2418
|
+
HttpMethods2["PUT"] = "PUT";
|
|
2419
|
+
HttpMethods2["PATCH"] = "PATCH";
|
|
2420
|
+
HttpMethods2["OPTIONS"] = "OPTIONS";
|
|
2421
|
+
HttpMethods2["DELETE"] = "DELETE";
|
|
2422
|
+
return HttpMethods2;
|
|
2423
|
+
})(HttpMethods || {});
|
|
2424
|
+
var HttpHandler = class extends RequestHandler {
|
|
2425
2425
|
constructor(method, path, resolver, options) {
|
|
2426
2426
|
super({
|
|
2427
2427
|
info: {
|
|
@@ -2505,24 +2505,24 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2505
2505
|
}
|
|
2506
2506
|
};
|
|
2507
2507
|
|
|
2508
|
-
// src/core/
|
|
2509
|
-
function
|
|
2508
|
+
// src/core/http.ts
|
|
2509
|
+
function createHttpHandler(method) {
|
|
2510
2510
|
return (path, resolver, options = {}) => {
|
|
2511
|
-
return new
|
|
2511
|
+
return new HttpHandler(method, path, resolver, options);
|
|
2512
2512
|
};
|
|
2513
2513
|
}
|
|
2514
|
-
var
|
|
2515
|
-
all:
|
|
2516
|
-
head:
|
|
2517
|
-
get:
|
|
2518
|
-
post:
|
|
2519
|
-
put:
|
|
2520
|
-
delete:
|
|
2521
|
-
patch:
|
|
2522
|
-
options:
|
|
2514
|
+
var http = {
|
|
2515
|
+
all: createHttpHandler(/.+/),
|
|
2516
|
+
head: createHttpHandler("HEAD" /* HEAD */),
|
|
2517
|
+
get: createHttpHandler("GET" /* GET */),
|
|
2518
|
+
post: createHttpHandler("POST" /* POST */),
|
|
2519
|
+
put: createHttpHandler("PUT" /* PUT */),
|
|
2520
|
+
delete: createHttpHandler("DELETE" /* DELETE */),
|
|
2521
|
+
patch: createHttpHandler("PATCH" /* PATCH */),
|
|
2522
|
+
options: createHttpHandler("OPTIONS" /* OPTIONS */)
|
|
2523
2523
|
};
|
|
2524
2524
|
|
|
2525
|
-
// node_modules/.pnpm/graphql@16.
|
|
2525
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/devAssert.mjs
|
|
2526
2526
|
function devAssert(condition, message3) {
|
|
2527
2527
|
const booleanCondition = Boolean(condition);
|
|
2528
2528
|
if (!booleanCondition) {
|
|
@@ -2530,12 +2530,12 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2530
2530
|
}
|
|
2531
2531
|
}
|
|
2532
2532
|
|
|
2533
|
-
// node_modules/.pnpm/graphql@16.
|
|
2533
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/isObjectLike.mjs
|
|
2534
2534
|
function isObjectLike(value) {
|
|
2535
2535
|
return typeof value == "object" && value !== null;
|
|
2536
2536
|
}
|
|
2537
2537
|
|
|
2538
|
-
// node_modules/.pnpm/graphql@16.
|
|
2538
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/invariant.mjs
|
|
2539
2539
|
function invariant2(condition, message3) {
|
|
2540
2540
|
const booleanCondition = Boolean(condition);
|
|
2541
2541
|
if (!booleanCondition) {
|
|
@@ -2545,7 +2545,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2545
2545
|
}
|
|
2546
2546
|
}
|
|
2547
2547
|
|
|
2548
|
-
// node_modules/.pnpm/graphql@16.
|
|
2548
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/location.mjs
|
|
2549
2549
|
var LineRegExp = /\r\n|[\n\r]/g;
|
|
2550
2550
|
function getLocation(source, position) {
|
|
2551
2551
|
let lastLineStart = 0;
|
|
@@ -2564,7 +2564,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2564
2564
|
};
|
|
2565
2565
|
}
|
|
2566
2566
|
|
|
2567
|
-
// node_modules/.pnpm/graphql@16.
|
|
2567
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/printLocation.mjs
|
|
2568
2568
|
function printLocation(location2) {
|
|
2569
2569
|
return printSourceLocation(
|
|
2570
2570
|
location2.source,
|
|
@@ -2611,7 +2611,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2611
2611
|
return existingLines.map(([prefix, line]) => prefix.padStart(padLen) + (line ? " " + line : "")).join("\n");
|
|
2612
2612
|
}
|
|
2613
2613
|
|
|
2614
|
-
// node_modules/.pnpm/graphql@16.
|
|
2614
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/error/GraphQLError.mjs
|
|
2615
2615
|
function toNormalizedOptions(args) {
|
|
2616
2616
|
const firstArg = args[0];
|
|
2617
2617
|
if (firstArg == null || "kind" in firstArg || "length" in firstArg) {
|
|
@@ -2760,7 +2760,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2760
2760
|
return array === void 0 || array.length === 0 ? void 0 : array;
|
|
2761
2761
|
}
|
|
2762
2762
|
|
|
2763
|
-
// node_modules/.pnpm/graphql@16.
|
|
2763
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/error/syntaxError.mjs
|
|
2764
2764
|
function syntaxError(source, position, description) {
|
|
2765
2765
|
return new GraphQLError(`Syntax Error: ${description}`, {
|
|
2766
2766
|
source,
|
|
@@ -2768,7 +2768,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2768
2768
|
});
|
|
2769
2769
|
}
|
|
2770
2770
|
|
|
2771
|
-
// node_modules/.pnpm/graphql@16.
|
|
2771
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/ast.mjs
|
|
2772
2772
|
var Location = class {
|
|
2773
2773
|
/**
|
|
2774
2774
|
* The character offset at which this Node begins.
|
|
@@ -2934,7 +2934,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2934
2934
|
OperationTypeNode2["SUBSCRIPTION"] = "subscription";
|
|
2935
2935
|
})(OperationTypeNode || (OperationTypeNode = {}));
|
|
2936
2936
|
|
|
2937
|
-
// node_modules/.pnpm/graphql@16.
|
|
2937
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/directiveLocation.mjs
|
|
2938
2938
|
var DirectiveLocation;
|
|
2939
2939
|
(function(DirectiveLocation2) {
|
|
2940
2940
|
DirectiveLocation2["QUERY"] = "QUERY";
|
|
@@ -2958,7 +2958,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2958
2958
|
DirectiveLocation2["INPUT_FIELD_DEFINITION"] = "INPUT_FIELD_DEFINITION";
|
|
2959
2959
|
})(DirectiveLocation || (DirectiveLocation = {}));
|
|
2960
2960
|
|
|
2961
|
-
// node_modules/.pnpm/graphql@16.
|
|
2961
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/kinds.mjs
|
|
2962
2962
|
var Kind;
|
|
2963
2963
|
(function(Kind2) {
|
|
2964
2964
|
Kind2["NAME"] = "Name";
|
|
@@ -3006,7 +3006,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
3006
3006
|
Kind2["INPUT_OBJECT_TYPE_EXTENSION"] = "InputObjectTypeExtension";
|
|
3007
3007
|
})(Kind || (Kind = {}));
|
|
3008
3008
|
|
|
3009
|
-
// node_modules/.pnpm/graphql@16.
|
|
3009
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/characterClasses.mjs
|
|
3010
3010
|
function isWhiteSpace(code) {
|
|
3011
3011
|
return code === 9 || code === 32;
|
|
3012
3012
|
}
|
|
@@ -3024,7 +3024,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
3024
3024
|
return isLetter(code) || isDigit(code) || code === 95;
|
|
3025
3025
|
}
|
|
3026
3026
|
|
|
3027
|
-
// node_modules/.pnpm/graphql@16.
|
|
3027
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/blockString.mjs
|
|
3028
3028
|
function dedentBlockStringLines(lines) {
|
|
3029
3029
|
var _firstNonEmptyLine2;
|
|
3030
3030
|
let commonIndent = Number.MAX_SAFE_INTEGER;
|
|
@@ -3056,7 +3056,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
3056
3056
|
return i;
|
|
3057
3057
|
}
|
|
3058
3058
|
|
|
3059
|
-
// node_modules/.pnpm/graphql@16.
|
|
3059
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/tokenKind.mjs
|
|
3060
3060
|
var TokenKind;
|
|
3061
3061
|
(function(TokenKind2) {
|
|
3062
3062
|
TokenKind2["SOF"] = "<SOF>";
|
|
@@ -3083,7 +3083,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
3083
3083
|
TokenKind2["COMMENT"] = "Comment";
|
|
3084
3084
|
})(TokenKind || (TokenKind = {}));
|
|
3085
3085
|
|
|
3086
|
-
// node_modules/.pnpm/graphql@16.
|
|
3086
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/lexer.mjs
|
|
3087
3087
|
var Lexer = class {
|
|
3088
3088
|
/**
|
|
3089
3089
|
* The previously focused non-ignored token.
|
|
@@ -3584,7 +3584,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
3584
3584
|
);
|
|
3585
3585
|
}
|
|
3586
3586
|
|
|
3587
|
-
// node_modules/.pnpm/graphql@16.
|
|
3587
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/inspect.mjs
|
|
3588
3588
|
var MAX_ARRAY_LENGTH = 10;
|
|
3589
3589
|
var MAX_RECURSIVE_DEPTH = 2;
|
|
3590
3590
|
function inspect(value) {
|
|
@@ -3667,7 +3667,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
3667
3667
|
return tag;
|
|
3668
3668
|
}
|
|
3669
3669
|
|
|
3670
|
-
// node_modules/.pnpm/graphql@16.
|
|
3670
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/instanceOf.mjs
|
|
3671
3671
|
var instanceOf = (
|
|
3672
3672
|
/* c8 ignore next 6 */
|
|
3673
3673
|
// FIXME: https://github.com/graphql/graphql-js/issues/2317
|
|
@@ -3704,7 +3704,7 @@ spurious results.`);
|
|
|
3704
3704
|
}
|
|
3705
3705
|
);
|
|
3706
3706
|
|
|
3707
|
-
// node_modules/.pnpm/graphql@16.
|
|
3707
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/source.mjs
|
|
3708
3708
|
var Source = class {
|
|
3709
3709
|
constructor(body, name = "GraphQL request", locationOffset = {
|
|
3710
3710
|
line: 1,
|
|
@@ -3731,7 +3731,7 @@ spurious results.`);
|
|
|
3731
3731
|
return instanceOf(source, Source);
|
|
3732
3732
|
}
|
|
3733
3733
|
|
|
3734
|
-
// node_modules/.pnpm/graphql@16.
|
|
3734
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/parser.mjs
|
|
3735
3735
|
function parse2(source, options) {
|
|
3736
3736
|
const parser = new Parser(source, options);
|
|
3737
3737
|
return parser.parseDocument();
|
|
@@ -4999,8 +4999,8 @@ spurious results.`);
|
|
|
4999
4999
|
throw new Error('"Content-Disposition" header is required.');
|
|
5000
5000
|
}
|
|
5001
5001
|
const directives = disposition.split(";").reduce((acc, chunk) => {
|
|
5002
|
-
const [name2, ...
|
|
5003
|
-
acc[name2] =
|
|
5002
|
+
const [name2, ...rest] = chunk.trim().split("=");
|
|
5003
|
+
acc[name2] = rest.join("=");
|
|
5004
5004
|
return acc;
|
|
5005
5005
|
}, {});
|
|
5006
5006
|
const name = (_a2 = directives.name) == null ? void 0 : _a2.slice(1, -1);
|
|
@@ -5029,8 +5029,8 @@ spurious results.`);
|
|
|
5029
5029
|
const parsedBody = {};
|
|
5030
5030
|
try {
|
|
5031
5031
|
for (const field of fields) {
|
|
5032
|
-
const [contentHeaders, ...
|
|
5033
|
-
const contentBody =
|
|
5032
|
+
const [contentHeaders, ...rest] = field.split("\r\n\r\n");
|
|
5033
|
+
const contentBody = rest.join("\r\n\r\n");
|
|
5034
5034
|
const { contentType: contentType2, filename, name } = parseContentHeaders(contentHeaders);
|
|
5035
5035
|
const value = filename === void 0 ? contentBody : new File([contentBody], filename, { type: contentType2 });
|
|
5036
5036
|
const parsedValue = parsedBody[name];
|
|
@@ -5091,9 +5091,9 @@ spurious results.`);
|
|
|
5091
5091
|
function getGraphQLInput(request) {
|
|
5092
5092
|
return __async(this, null, function* () {
|
|
5093
5093
|
var _a2;
|
|
5094
|
-
const url = new URL(request.url);
|
|
5095
5094
|
switch (request.method) {
|
|
5096
5095
|
case "GET": {
|
|
5096
|
+
const url = new URL(request.url);
|
|
5097
5097
|
const query = url.searchParams.get("query");
|
|
5098
5098
|
const variables = url.searchParams.get("variables") || "";
|
|
5099
5099
|
return {
|
|
@@ -5102,9 +5102,10 @@ spurious results.`);
|
|
|
5102
5102
|
};
|
|
5103
5103
|
}
|
|
5104
5104
|
case "POST": {
|
|
5105
|
+
const requestClone = request.clone();
|
|
5105
5106
|
if ((_a2 = request.headers.get("content-type")) == null ? void 0 : _a2.includes("multipart/form-data")) {
|
|
5106
5107
|
const responseJson = parseMultipartData(
|
|
5107
|
-
yield
|
|
5108
|
+
yield requestClone.text(),
|
|
5108
5109
|
request.headers
|
|
5109
5110
|
);
|
|
5110
5111
|
if (!responseJson) {
|
|
@@ -5128,7 +5129,7 @@ spurious results.`);
|
|
|
5128
5129
|
variables
|
|
5129
5130
|
};
|
|
5130
5131
|
}
|
|
5131
|
-
const requestJson = yield
|
|
5132
|
+
const requestJson = yield requestClone.json().catch(() => null);
|
|
5132
5133
|
if (requestJson == null ? void 0 : requestJson.query) {
|
|
5133
5134
|
const { query, variables } = requestJson;
|
|
5134
5135
|
return {
|
|
@@ -5221,7 +5222,7 @@ spurious results.`);
|
|
|
5221
5222
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
5222
5223
|
devUtils.warn(`Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
5223
5224
|
|
|
5224
|
-
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
|
|
5225
|
+
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`);
|
|
5225
5226
|
return false;
|
|
5226
5227
|
}
|
|
5227
5228
|
const hasMatchingUrl = matchRequestUrl(new URL(request.url), this.endpoint);
|
|
@@ -5465,8 +5466,8 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5465
5466
|
function groupHandlersByType(handlers) {
|
|
5466
5467
|
return handlers.reduce(
|
|
5467
5468
|
(groups, handler) => {
|
|
5468
|
-
if (handler instanceof
|
|
5469
|
-
groups.
|
|
5469
|
+
if (handler instanceof HttpHandler) {
|
|
5470
|
+
groups.http.push(handler);
|
|
5470
5471
|
}
|
|
5471
5472
|
if (handler instanceof GraphQLHandler) {
|
|
5472
5473
|
groups.graphql.push(handler);
|
|
@@ -5474,12 +5475,12 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5474
5475
|
return groups;
|
|
5475
5476
|
},
|
|
5476
5477
|
{
|
|
5477
|
-
|
|
5478
|
+
http: [],
|
|
5478
5479
|
graphql: []
|
|
5479
5480
|
}
|
|
5480
5481
|
);
|
|
5481
5482
|
}
|
|
5482
|
-
function
|
|
5483
|
+
function getHttpHandlerScore() {
|
|
5483
5484
|
return (request, handler) => {
|
|
5484
5485
|
const { path, method } = handler.info;
|
|
5485
5486
|
if (path instanceof RegExp || method instanceof RegExp) {
|
|
@@ -5527,19 +5528,25 @@ ${handlers.map((handler) => ` \u2022 ${handler.info.header}`).join("\n")}`;
|
|
|
5527
5528
|
const parsedGraphQLQuery = yield parseGraphQLRequest(request).catch(
|
|
5528
5529
|
() => null
|
|
5529
5530
|
);
|
|
5531
|
+
const publicUrl = getPublicUrlFromRequest(request);
|
|
5530
5532
|
function generateHandlerSuggestion() {
|
|
5531
5533
|
const handlerGroups = groupHandlersByType(handlers);
|
|
5532
|
-
const relevantHandlers = parsedGraphQLQuery ? handlerGroups.graphql : handlerGroups.
|
|
5534
|
+
const relevantHandlers = parsedGraphQLQuery ? handlerGroups.graphql : handlerGroups.http;
|
|
5533
5535
|
const suggestedHandlers = getSuggestedHandler(
|
|
5534
5536
|
request,
|
|
5535
5537
|
relevantHandlers,
|
|
5536
|
-
parsedGraphQLQuery ? getGraphQLHandlerScore(parsedGraphQLQuery) :
|
|
5538
|
+
parsedGraphQLQuery ? getGraphQLHandlerScore(parsedGraphQLQuery) : getHttpHandlerScore()
|
|
5537
5539
|
);
|
|
5538
5540
|
return suggestedHandlers.length > 0 ? getSuggestedHandlersMessage(suggestedHandlers) : "";
|
|
5539
5541
|
}
|
|
5542
|
+
function getGraphQLRequestHeader(parsedGraphQLRequest) {
|
|
5543
|
+
if (!(parsedGraphQLRequest == null ? void 0 : parsedGraphQLRequest.operationName)) {
|
|
5544
|
+
return `anonymous ${parsedGraphQLRequest == null ? void 0 : parsedGraphQLRequest.operationType} (${request.method} ${publicUrl})`;
|
|
5545
|
+
}
|
|
5546
|
+
return `${parsedGraphQLRequest.operationType} ${parsedGraphQLRequest.operationName} (${request.method} ${publicUrl})`;
|
|
5547
|
+
}
|
|
5540
5548
|
function generateUnhandledRequestMessage() {
|
|
5541
|
-
const
|
|
5542
|
-
const requestHeader = parsedGraphQLQuery ? `${parsedGraphQLQuery.operationType} ${parsedGraphQLQuery.operationName} (${request.method} ${publicUrl})` : `${request.method} ${publicUrl}`;
|
|
5549
|
+
const requestHeader = parsedGraphQLQuery ? getGraphQLRequestHeader(parsedGraphQLQuery) : `${request.method} ${publicUrl}`;
|
|
5543
5550
|
const handlerSuggestion = generateHandlerSuggestion();
|
|
5544
5551
|
const messageTemplate = [
|
|
5545
5552
|
`captured a request without a matching request handler:`,
|
|
@@ -5597,9 +5604,9 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
5597
5604
|
function handleRequest(request, requestId, handlers, options, emitter, handleRequestOptions) {
|
|
5598
5605
|
return __async(this, null, function* () {
|
|
5599
5606
|
var _a2, _b2, _c, _d, _e, _f;
|
|
5600
|
-
emitter.emit("request:start", request, requestId);
|
|
5607
|
+
emitter.emit("request:start", { request, requestId });
|
|
5601
5608
|
if (request.headers.get("x-msw-intention") === "bypass") {
|
|
5602
|
-
emitter.emit("request:end", request, requestId);
|
|
5609
|
+
emitter.emit("request:end", { request, requestId });
|
|
5603
5610
|
(_a2 = handleRequestOptions == null ? void 0 : handleRequestOptions.onPassthroughResponse) == null ? void 0 : _a2.call(handleRequestOptions, request);
|
|
5604
5611
|
return;
|
|
5605
5612
|
}
|
|
@@ -5611,29 +5618,33 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
5611
5618
|
);
|
|
5612
5619
|
});
|
|
5613
5620
|
if (lookupResult.error) {
|
|
5614
|
-
emitter.emit("unhandledException",
|
|
5621
|
+
emitter.emit("unhandledException", {
|
|
5622
|
+
error: lookupResult.error,
|
|
5623
|
+
request,
|
|
5624
|
+
requestId
|
|
5625
|
+
});
|
|
5615
5626
|
throw lookupResult.error;
|
|
5616
5627
|
}
|
|
5617
5628
|
if (!lookupResult.data) {
|
|
5618
5629
|
yield onUnhandledRequest(request, handlers, options.onUnhandledRequest);
|
|
5619
|
-
emitter.emit("request:unhandled", request, requestId);
|
|
5620
|
-
emitter.emit("request:end", request, requestId);
|
|
5630
|
+
emitter.emit("request:unhandled", { request, requestId });
|
|
5631
|
+
emitter.emit("request:end", { request, requestId });
|
|
5621
5632
|
(_b2 = handleRequestOptions == null ? void 0 : handleRequestOptions.onPassthroughResponse) == null ? void 0 : _b2.call(handleRequestOptions, request);
|
|
5622
5633
|
return;
|
|
5623
5634
|
}
|
|
5624
5635
|
const { response } = lookupResult.data;
|
|
5625
5636
|
if (!response) {
|
|
5626
|
-
emitter.emit("request:end", request, requestId);
|
|
5637
|
+
emitter.emit("request:end", { request, requestId });
|
|
5627
5638
|
(_c = handleRequestOptions == null ? void 0 : handleRequestOptions.onPassthroughResponse) == null ? void 0 : _c.call(handleRequestOptions, request);
|
|
5628
5639
|
return;
|
|
5629
5640
|
}
|
|
5630
5641
|
if (response.status === 302 && response.headers.get("x-msw-intention") === "passthrough") {
|
|
5631
|
-
emitter.emit("request:end", request, requestId);
|
|
5642
|
+
emitter.emit("request:end", { request, requestId });
|
|
5632
5643
|
(_d = handleRequestOptions == null ? void 0 : handleRequestOptions.onPassthroughResponse) == null ? void 0 : _d.call(handleRequestOptions, request);
|
|
5633
5644
|
return;
|
|
5634
5645
|
}
|
|
5635
5646
|
readResponseCookies(request, response);
|
|
5636
|
-
emitter.emit("request:match", request, requestId);
|
|
5647
|
+
emitter.emit("request:match", { request, requestId });
|
|
5637
5648
|
const requiredLookupResult = lookupResult.data;
|
|
5638
5649
|
const transformedResponse = ((_e = handleRequestOptions == null ? void 0 : handleRequestOptions.transformResponse) == null ? void 0 : _e.call(handleRequestOptions, response)) || response;
|
|
5639
5650
|
(_f = handleRequestOptions == null ? void 0 : handleRequestOptions.onMockedResponse) == null ? void 0 : _f.call(
|
|
@@ -5641,7 +5652,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
5641
5652
|
transformedResponse,
|
|
5642
5653
|
requiredLookupResult
|
|
5643
5654
|
);
|
|
5644
|
-
emitter.emit("request:end", request, requestId);
|
|
5655
|
+
emitter.emit("request:end", { request, requestId });
|
|
5645
5656
|
return transformedResponse;
|
|
5646
5657
|
});
|
|
5647
5658
|
}
|
|
@@ -5996,8 +6007,8 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
|
|
|
5996
6007
|
constructor(port) {
|
|
5997
6008
|
this.port = port;
|
|
5998
6009
|
}
|
|
5999
|
-
postMessage(event, ...
|
|
6000
|
-
const [data, transfer] =
|
|
6010
|
+
postMessage(event, ...rest) {
|
|
6011
|
+
const [data, transfer] = rest;
|
|
6001
6012
|
this.port.postMessage(
|
|
6002
6013
|
{ type: event, data },
|
|
6003
6014
|
{
|
|
@@ -6068,7 +6079,7 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
|
|
|
6068
6079
|
responseStream ? [responseStream] : void 0
|
|
6069
6080
|
);
|
|
6070
6081
|
if (!options.quiet) {
|
|
6071
|
-
context.emitter.once("response:mocked", (response2) => {
|
|
6082
|
+
context.emitter.once("response:mocked", ({ response: response2 }) => {
|
|
6072
6083
|
handler.log(requestCloneForLogs, response2, parsedRequest);
|
|
6073
6084
|
});
|
|
6074
6085
|
}
|
|
@@ -6154,25 +6165,18 @@ This exception has been gracefully handled as a 500 response, however, it's stro
|
|
|
6154
6165
|
return;
|
|
6155
6166
|
}
|
|
6156
6167
|
const response = responseJson.status === 0 ? Response.error() : new Response(responseJson.body, responseJson);
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6168
|
+
context.emitter.emit(
|
|
6169
|
+
responseJson.isMockedResponse ? "response:mocked" : "response:bypass",
|
|
6170
|
+
{
|
|
6160
6171
|
response,
|
|
6161
6172
|
/**
|
|
6162
6173
|
* @todo @fixme In this context, we don't know anything about
|
|
6163
6174
|
* the request.
|
|
6164
6175
|
*/
|
|
6165
|
-
null,
|
|
6166
|
-
responseJson.requestId
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
context.emitter.emit(
|
|
6170
|
-
"response:bypass",
|
|
6171
|
-
response,
|
|
6172
|
-
null,
|
|
6173
|
-
responseJson.requestId
|
|
6174
|
-
);
|
|
6175
|
-
}
|
|
6176
|
+
request: null,
|
|
6177
|
+
requestId: responseJson.requestId
|
|
6178
|
+
}
|
|
6179
|
+
);
|
|
6176
6180
|
};
|
|
6177
6181
|
}
|
|
6178
6182
|
|
|
@@ -9490,7 +9494,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
9490
9494
|
{
|
|
9491
9495
|
onMockedResponse(_, { handler, parsedRequest }) {
|
|
9492
9496
|
if (!options.quiet) {
|
|
9493
|
-
context.emitter.once("response:mocked", (response2) => {
|
|
9497
|
+
context.emitter.once("response:mocked", ({ response: response2 }) => {
|
|
9494
9498
|
handler.log(requestCloneForLogs, response2, parsedRequest);
|
|
9495
9499
|
});
|
|
9496
9500
|
}
|
|
@@ -9506,9 +9510,11 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
9506
9510
|
({ response, isMockedResponse, request, requestId }) => {
|
|
9507
9511
|
context.emitter.emit(
|
|
9508
9512
|
isMockedResponse ? "response:mocked" : "response:bypass",
|
|
9509
|
-
|
|
9510
|
-
|
|
9511
|
-
|
|
9513
|
+
{
|
|
9514
|
+
response,
|
|
9515
|
+
request,
|
|
9516
|
+
requestId
|
|
9517
|
+
}
|
|
9512
9518
|
);
|
|
9513
9519
|
}
|
|
9514
9520
|
);
|
|
@@ -9655,19 +9661,6 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
9655
9661
|
return yield this.startHandler(this.context.startOptions, options);
|
|
9656
9662
|
});
|
|
9657
9663
|
}
|
|
9658
|
-
printHandlers() {
|
|
9659
|
-
const handlers = this.listHandlers();
|
|
9660
|
-
handlers.forEach((handler) => {
|
|
9661
|
-
const { header, callFrame } = handler.info;
|
|
9662
|
-
const pragma = handler.info.hasOwnProperty("operationType") ? "[graphql]" : "[rest]";
|
|
9663
|
-
console.groupCollapsed(`${pragma} ${header}`);
|
|
9664
|
-
if (callFrame) {
|
|
9665
|
-
console.log(`Declaration: ${callFrame}`);
|
|
9666
|
-
}
|
|
9667
|
-
console.log("Handler:", handler);
|
|
9668
|
-
console.groupEnd();
|
|
9669
|
-
});
|
|
9670
|
-
}
|
|
9671
9664
|
stop() {
|
|
9672
9665
|
super.dispose();
|
|
9673
9666
|
this.context.events.removeAllListeners();
|
package/lib/mockServiceWorker.js
CHANGED
package/lib/native/index.d.ts
CHANGED
|
@@ -35,11 +35,6 @@ interface SetupServer {
|
|
|
35
35
|
* @see {@link https://mswjs.io/docs/api/setup-server/list-handlers `server.listHandlers()`}
|
|
36
36
|
*/
|
|
37
37
|
listHandlers(): ReadonlyArray<RequestHandler<RequestHandlerDefaultInfo, any>>;
|
|
38
|
-
/**
|
|
39
|
-
* Lists all active request handlers.
|
|
40
|
-
* @see {@link https://mswjs.io/docs/api/setup-server/print-handlers `server.print-handlers()`}
|
|
41
|
-
*/
|
|
42
|
-
printHandlers(): void;
|
|
43
38
|
events: LifeCycleEventEmitter<LifeCycleEventsMap>;
|
|
44
39
|
}
|
|
45
40
|
|
|
@@ -54,7 +49,6 @@ declare class SetupServerApi extends SetupApi<LifeCycleEventsMap> implements Set
|
|
|
54
49
|
*/
|
|
55
50
|
private init;
|
|
56
51
|
listen(options?: Partial<SharedOptions>): void;
|
|
57
|
-
printHandlers(): void;
|
|
58
52
|
close(): void;
|
|
59
53
|
}
|
|
60
54
|
|
package/lib/native/index.js
CHANGED
|
@@ -87,9 +87,11 @@ var SetupServerApi = class extends import_SetupApi.SetupApi {
|
|
|
87
87
|
({ response, isMockedResponse, request, requestId }) => {
|
|
88
88
|
this.emitter.emit(
|
|
89
89
|
isMockedResponse ? "response:mocked" : "response:bypass",
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
{
|
|
91
|
+
response,
|
|
92
|
+
request,
|
|
93
|
+
requestId
|
|
94
|
+
}
|
|
93
95
|
);
|
|
94
96
|
}
|
|
95
97
|
);
|
|
@@ -113,16 +115,6 @@ var SetupServerApi = class extends import_SetupApi.SetupApi {
|
|
|
113
115
|
"https://github.com/mswjs/msw/issues/new/choose"
|
|
114
116
|
);
|
|
115
117
|
}
|
|
116
|
-
printHandlers() {
|
|
117
|
-
const handlers = this.listHandlers();
|
|
118
|
-
handlers.forEach((handler) => {
|
|
119
|
-
const { header, callFrame } = handler.info;
|
|
120
|
-
const pragma = handler.info.hasOwnProperty("operationType") ? "[graphql]" : "[rest]";
|
|
121
|
-
console.log(`${`${pragma} ${header}`}
|
|
122
|
-
Declaration: ${callFrame}
|
|
123
|
-
`);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
118
|
close() {
|
|
127
119
|
this.dispose();
|
|
128
120
|
}
|
package/lib/native/index.mjs
CHANGED
|
@@ -67,9 +67,11 @@ var SetupServerApi = class extends SetupApi {
|
|
|
67
67
|
({ response, isMockedResponse, request, requestId }) => {
|
|
68
68
|
this.emitter.emit(
|
|
69
69
|
isMockedResponse ? "response:mocked" : "response:bypass",
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
{
|
|
71
|
+
response,
|
|
72
|
+
request,
|
|
73
|
+
requestId
|
|
74
|
+
}
|
|
73
75
|
);
|
|
74
76
|
}
|
|
75
77
|
);
|
|
@@ -93,16 +95,6 @@ var SetupServerApi = class extends SetupApi {
|
|
|
93
95
|
"https://github.com/mswjs/msw/issues/new/choose"
|
|
94
96
|
);
|
|
95
97
|
}
|
|
96
|
-
printHandlers() {
|
|
97
|
-
const handlers = this.listHandlers();
|
|
98
|
-
handlers.forEach((handler) => {
|
|
99
|
-
const { header, callFrame } = handler.info;
|
|
100
|
-
const pragma = handler.info.hasOwnProperty("operationType") ? "[graphql]" : "[rest]";
|
|
101
|
-
console.log(`${`${pragma} ${header}`}
|
|
102
|
-
Declaration: ${callFrame}
|
|
103
|
-
`);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
98
|
close() {
|
|
107
99
|
this.dispose();
|
|
108
100
|
}
|
package/lib/node/index.d.ts
CHANGED
|
@@ -35,11 +35,6 @@ interface SetupServer {
|
|
|
35
35
|
* @see {@link https://mswjs.io/docs/api/setup-server/list-handlers `server.listHandlers()`}
|
|
36
36
|
*/
|
|
37
37
|
listHandlers(): ReadonlyArray<RequestHandler<RequestHandlerDefaultInfo, any>>;
|
|
38
|
-
/**
|
|
39
|
-
* Lists all active request handlers.
|
|
40
|
-
* @see {@link https://mswjs.io/docs/api/setup-server/print-handlers `server.print-handlers()`}
|
|
41
|
-
*/
|
|
42
|
-
printHandlers(): void;
|
|
43
38
|
events: LifeCycleEventEmitter<LifeCycleEventsMap>;
|
|
44
39
|
}
|
|
45
40
|
|
|
@@ -54,7 +49,6 @@ declare class SetupServerApi extends SetupApi<LifeCycleEventsMap> implements Set
|
|
|
54
49
|
*/
|
|
55
50
|
private init;
|
|
56
51
|
listen(options?: Partial<SharedOptions>): void;
|
|
57
|
-
printHandlers(): void;
|
|
58
52
|
close(): void;
|
|
59
53
|
}
|
|
60
54
|
|
package/lib/node/index.js
CHANGED
|
@@ -87,9 +87,11 @@ var SetupServerApi = class extends import_SetupApi.SetupApi {
|
|
|
87
87
|
({ response, isMockedResponse, request, requestId }) => {
|
|
88
88
|
this.emitter.emit(
|
|
89
89
|
isMockedResponse ? "response:mocked" : "response:bypass",
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
{
|
|
91
|
+
response,
|
|
92
|
+
request,
|
|
93
|
+
requestId
|
|
94
|
+
}
|
|
93
95
|
);
|
|
94
96
|
}
|
|
95
97
|
);
|
|
@@ -113,16 +115,6 @@ var SetupServerApi = class extends import_SetupApi.SetupApi {
|
|
|
113
115
|
"https://github.com/mswjs/msw/issues/new/choose"
|
|
114
116
|
);
|
|
115
117
|
}
|
|
116
|
-
printHandlers() {
|
|
117
|
-
const handlers = this.listHandlers();
|
|
118
|
-
handlers.forEach((handler) => {
|
|
119
|
-
const { header, callFrame } = handler.info;
|
|
120
|
-
const pragma = handler.info.hasOwnProperty("operationType") ? "[graphql]" : "[rest]";
|
|
121
|
-
console.log(`${`${pragma} ${header}`}
|
|
122
|
-
Declaration: ${callFrame}
|
|
123
|
-
`);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
118
|
close() {
|
|
127
119
|
this.dispose();
|
|
128
120
|
}
|