msw 0.41.1 → 0.42.2
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 +7 -1
- package/lib/{glossary-eda04a15.d.ts → glossary-58eca5a8.d.ts} +50 -49
- package/lib/iife/index.js +2065 -909
- package/lib/iife/index.js.map +1 -1
- package/lib/index.d.ts +31 -22
- package/lib/index.js +58 -290
- package/lib/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.ts +1 -1
- package/lib/native/index.js +42 -252
- package/lib/native/index.mjs +45 -268
- package/lib/node/index.d.ts +2 -2
- package/lib/node/index.js +46 -317
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +47 -333
- package/lib/node/index.mjs.map +1 -1
- package/package.json +3 -4
- package/lib/esm/index.js +0 -2109
- package/lib/esm/index.js.map +0 -1
package/lib/node/index.js
CHANGED
|
@@ -33,12 +33,6 @@ var __objRest = (source, exclude) => {
|
|
|
33
33
|
}
|
|
34
34
|
return target;
|
|
35
35
|
};
|
|
36
|
-
var __esm = (fn, res) => function __init() {
|
|
37
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
38
|
-
};
|
|
39
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
40
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
41
|
-
};
|
|
42
36
|
var __export = (target, all) => {
|
|
43
37
|
for (var name in all)
|
|
44
38
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -54,202 +48,28 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
54
48
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
55
49
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
56
50
|
|
|
57
|
-
// node_modules/tsup/assets/cjs_shims.js
|
|
58
|
-
var init_cjs_shims = __esm({
|
|
59
|
-
"node_modules/tsup/assets/cjs_shims.js"() {
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// config/polyfills-node.ts
|
|
64
|
-
var import_timers, setTimeout;
|
|
65
|
-
var init_polyfills_node = __esm({
|
|
66
|
-
"config/polyfills-node.ts"() {
|
|
67
|
-
import_timers = require("timers");
|
|
68
|
-
setTimeout = import_timers.setTimeout;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// node_modules/outvariant/lib/format.js
|
|
73
|
-
var require_format = __commonJS({
|
|
74
|
-
"node_modules/outvariant/lib/format.js"(exports) {
|
|
75
|
-
"use strict";
|
|
76
|
-
init_cjs_shims();
|
|
77
|
-
init_polyfills_node();
|
|
78
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
|
-
exports.format = void 0;
|
|
80
|
-
var POSITIONALS_EXP = /(%?)(%([sdjo]))/g;
|
|
81
|
-
function serializePositional(positional, flag) {
|
|
82
|
-
switch (flag) {
|
|
83
|
-
case "s":
|
|
84
|
-
return positional;
|
|
85
|
-
case "d":
|
|
86
|
-
case "i":
|
|
87
|
-
return Number(positional);
|
|
88
|
-
case "j":
|
|
89
|
-
return JSON.stringify(positional);
|
|
90
|
-
case "o": {
|
|
91
|
-
if (typeof positional === "string") {
|
|
92
|
-
return positional;
|
|
93
|
-
}
|
|
94
|
-
var json2 = JSON.stringify(positional);
|
|
95
|
-
if (json2 === "{}" || json2 === "[]" || /^\[object .+?\]$/.test(json2)) {
|
|
96
|
-
return positional;
|
|
97
|
-
}
|
|
98
|
-
return json2;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function format2(message) {
|
|
103
|
-
var positionals = [];
|
|
104
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
105
|
-
positionals[_i - 1] = arguments[_i];
|
|
106
|
-
}
|
|
107
|
-
if (positionals.length === 0) {
|
|
108
|
-
return message;
|
|
109
|
-
}
|
|
110
|
-
var positionalIndex = 0;
|
|
111
|
-
var formattedMessage = message.replace(POSITIONALS_EXP, function(match2, isEscaped, _, flag) {
|
|
112
|
-
var positional = positionals[positionalIndex];
|
|
113
|
-
var value = serializePositional(positional, flag);
|
|
114
|
-
if (!isEscaped) {
|
|
115
|
-
positionalIndex++;
|
|
116
|
-
return value;
|
|
117
|
-
}
|
|
118
|
-
return match2;
|
|
119
|
-
});
|
|
120
|
-
if (positionalIndex < positionals.length) {
|
|
121
|
-
formattedMessage += " " + positionals.slice(positionalIndex).join(" ");
|
|
122
|
-
}
|
|
123
|
-
formattedMessage = formattedMessage.replace(/%{2,2}/g, "%");
|
|
124
|
-
return formattedMessage;
|
|
125
|
-
}
|
|
126
|
-
exports.format = format2;
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
// node_modules/outvariant/lib/invariant.js
|
|
131
|
-
var require_invariant = __commonJS({
|
|
132
|
-
"node_modules/outvariant/lib/invariant.js"(exports) {
|
|
133
|
-
"use strict";
|
|
134
|
-
init_cjs_shims();
|
|
135
|
-
init_polyfills_node();
|
|
136
|
-
var __extends = exports && exports.__extends || function() {
|
|
137
|
-
var extendStatics = function(d, b) {
|
|
138
|
-
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
139
|
-
d2.__proto__ = b2;
|
|
140
|
-
} || function(d2, b2) {
|
|
141
|
-
for (var p in b2)
|
|
142
|
-
if (Object.prototype.hasOwnProperty.call(b2, p))
|
|
143
|
-
d2[p] = b2[p];
|
|
144
|
-
};
|
|
145
|
-
return extendStatics(d, b);
|
|
146
|
-
};
|
|
147
|
-
return function(d, b) {
|
|
148
|
-
if (typeof b !== "function" && b !== null)
|
|
149
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
150
|
-
extendStatics(d, b);
|
|
151
|
-
function __() {
|
|
152
|
-
this.constructor = d;
|
|
153
|
-
}
|
|
154
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
155
|
-
};
|
|
156
|
-
}();
|
|
157
|
-
var __spreadArray = exports && exports.__spreadArray || function(to, from) {
|
|
158
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
159
|
-
to[j] = from[i];
|
|
160
|
-
return to;
|
|
161
|
-
};
|
|
162
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
163
|
-
exports.invariant = exports.InvariantError = void 0;
|
|
164
|
-
var format_1 = require_format();
|
|
165
|
-
var STACK_FRAMES_TO_IGNORE = 2;
|
|
166
|
-
var InvariantError = function(_super) {
|
|
167
|
-
__extends(InvariantError2, _super);
|
|
168
|
-
function InvariantError2(message) {
|
|
169
|
-
var positionals = [];
|
|
170
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
171
|
-
positionals[_i - 1] = arguments[_i];
|
|
172
|
-
}
|
|
173
|
-
var _this = _super.call(this, message) || this;
|
|
174
|
-
_this.name = "Invariant Violation";
|
|
175
|
-
_this.message = format_1.format.apply(void 0, __spreadArray([message], positionals));
|
|
176
|
-
if (_this.stack) {
|
|
177
|
-
var nextStack = _this.stack.split("\n");
|
|
178
|
-
nextStack.splice(1, STACK_FRAMES_TO_IGNORE);
|
|
179
|
-
_this.stack = nextStack.join("\n");
|
|
180
|
-
}
|
|
181
|
-
return _this;
|
|
182
|
-
}
|
|
183
|
-
return InvariantError2;
|
|
184
|
-
}(Error);
|
|
185
|
-
exports.InvariantError = InvariantError;
|
|
186
|
-
function invariant(predicate, message) {
|
|
187
|
-
var positionals = [];
|
|
188
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
189
|
-
positionals[_i - 2] = arguments[_i];
|
|
190
|
-
}
|
|
191
|
-
if (!predicate) {
|
|
192
|
-
throw new (InvariantError.bind.apply(InvariantError, __spreadArray([void 0, message], positionals)))();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
exports.invariant = invariant;
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
// node_modules/outvariant/lib/index.js
|
|
200
|
-
var require_lib = __commonJS({
|
|
201
|
-
"node_modules/outvariant/lib/index.js"(exports) {
|
|
202
|
-
"use strict";
|
|
203
|
-
init_cjs_shims();
|
|
204
|
-
init_polyfills_node();
|
|
205
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
206
|
-
if (k2 === void 0)
|
|
207
|
-
k2 = k;
|
|
208
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
209
|
-
return m[k];
|
|
210
|
-
} });
|
|
211
|
-
} : function(o, m, k, k2) {
|
|
212
|
-
if (k2 === void 0)
|
|
213
|
-
k2 = k;
|
|
214
|
-
o[k2] = m[k];
|
|
215
|
-
});
|
|
216
|
-
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
217
|
-
for (var p in m)
|
|
218
|
-
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
219
|
-
__createBinding(exports2, m, p);
|
|
220
|
-
};
|
|
221
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
222
|
-
__exportStar(require_invariant(), exports);
|
|
223
|
-
__exportStar(require_format(), exports);
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
|
|
227
51
|
// src/node/index.ts
|
|
228
52
|
var node_exports = {};
|
|
229
53
|
__export(node_exports, {
|
|
230
54
|
setupServer: () => setupServer
|
|
231
55
|
});
|
|
232
56
|
module.exports = __toCommonJS(node_exports);
|
|
233
|
-
|
|
234
|
-
|
|
57
|
+
|
|
58
|
+
// config/polyfills-node.ts
|
|
59
|
+
var import_timers = require("timers");
|
|
60
|
+
var setTimeout = import_timers.setTimeout;
|
|
235
61
|
|
|
236
62
|
// src/node/setupServer.ts
|
|
237
|
-
init_cjs_shims();
|
|
238
|
-
init_polyfills_node();
|
|
239
63
|
var import_ClientRequest = require("@mswjs/interceptors/lib/interceptors/ClientRequest");
|
|
240
64
|
var import_XMLHttpRequest = require("@mswjs/interceptors/lib/interceptors/XMLHttpRequest");
|
|
241
65
|
|
|
242
66
|
// src/node/createSetupServer.ts
|
|
243
|
-
init_cjs_shims();
|
|
244
|
-
init_polyfills_node();
|
|
245
67
|
var import_chalk = require("chalk");
|
|
246
68
|
var import_is_node_process3 = require("is-node-process");
|
|
247
69
|
var import_strict_event_emitter = require("strict-event-emitter");
|
|
248
70
|
var import_interceptors = require("@mswjs/interceptors");
|
|
249
71
|
|
|
250
72
|
// src/utils/internal/requestHandlerUtils.ts
|
|
251
|
-
init_cjs_shims();
|
|
252
|
-
init_polyfills_node();
|
|
253
73
|
function use(currentHandlers, ...handlers) {
|
|
254
74
|
currentHandlers.unshift(...handlers);
|
|
255
75
|
}
|
|
@@ -262,23 +82,13 @@ function resetHandlers(initialHandlers, ...nextHandlers) {
|
|
|
262
82
|
return nextHandlers.length > 0 ? [...nextHandlers] : [...initialHandlers];
|
|
263
83
|
}
|
|
264
84
|
|
|
265
|
-
// src/utils/request/parseIsomorphicRequest.ts
|
|
266
|
-
init_cjs_shims();
|
|
267
|
-
init_polyfills_node();
|
|
268
|
-
|
|
269
85
|
// src/handlers/RequestHandler.ts
|
|
270
|
-
init_cjs_shims();
|
|
271
|
-
init_polyfills_node();
|
|
272
86
|
var import_headers_polyfill4 = require("headers-polyfill");
|
|
273
87
|
|
|
274
88
|
// src/response.ts
|
|
275
|
-
init_cjs_shims();
|
|
276
|
-
init_polyfills_node();
|
|
277
89
|
var import_headers_polyfill = require("headers-polyfill");
|
|
278
90
|
|
|
279
91
|
// src/utils/internal/compose.ts
|
|
280
|
-
init_cjs_shims();
|
|
281
|
-
init_polyfills_node();
|
|
282
92
|
function compose(...fns) {
|
|
283
93
|
return (...args) => {
|
|
284
94
|
return fns.reduceRight((leftFn, rightFn) => {
|
|
@@ -288,8 +98,6 @@ function compose(...fns) {
|
|
|
288
98
|
}
|
|
289
99
|
|
|
290
100
|
// src/utils/NetworkError.ts
|
|
291
|
-
init_cjs_shims();
|
|
292
|
-
init_polyfills_node();
|
|
293
101
|
var NetworkError = class extends Error {
|
|
294
102
|
constructor(message) {
|
|
295
103
|
super(message);
|
|
@@ -330,8 +138,6 @@ var response = Object.assign(createResponseComposition(), {
|
|
|
330
138
|
});
|
|
331
139
|
|
|
332
140
|
// src/utils/internal/getCallFrame.ts
|
|
333
|
-
init_cjs_shims();
|
|
334
|
-
init_polyfills_node();
|
|
335
141
|
var SOURCE_FRAME = /\/msw\/src\/(.+)/;
|
|
336
142
|
var BUILD_FRAME = /(node_modules)?[\/\\]lib[\/\\](umd|esm|iief|cjs)[\/\\]|^[^\/\\]*$/;
|
|
337
143
|
function getCallFrame(error2) {
|
|
@@ -351,8 +157,6 @@ function getCallFrame(error2) {
|
|
|
351
157
|
}
|
|
352
158
|
|
|
353
159
|
// src/utils/internal/isIterable.ts
|
|
354
|
-
init_cjs_shims();
|
|
355
|
-
init_polyfills_node();
|
|
356
160
|
function isIterable(fn) {
|
|
357
161
|
if (!fn) {
|
|
358
162
|
return false;
|
|
@@ -361,8 +165,6 @@ function isIterable(fn) {
|
|
|
361
165
|
}
|
|
362
166
|
|
|
363
167
|
// src/context/status.ts
|
|
364
|
-
init_cjs_shims();
|
|
365
|
-
init_polyfills_node();
|
|
366
168
|
var import_codes = __toESM(require("statuses/codes.json"));
|
|
367
169
|
var status = (statusCode, statusText) => {
|
|
368
170
|
return (res) => {
|
|
@@ -373,8 +175,6 @@ var status = (statusCode, statusText) => {
|
|
|
373
175
|
};
|
|
374
176
|
|
|
375
177
|
// src/context/set.ts
|
|
376
|
-
init_cjs_shims();
|
|
377
|
-
init_polyfills_node();
|
|
378
178
|
var import_headers_polyfill2 = require("headers-polyfill");
|
|
379
179
|
function set(...args) {
|
|
380
180
|
return (res) => {
|
|
@@ -392,8 +192,6 @@ function set(...args) {
|
|
|
392
192
|
}
|
|
393
193
|
|
|
394
194
|
// src/context/delay.ts
|
|
395
|
-
init_cjs_shims();
|
|
396
|
-
init_polyfills_node();
|
|
397
195
|
var import_is_node_process = require("is-node-process");
|
|
398
196
|
var SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647;
|
|
399
197
|
var MIN_SERVER_RESPONSE_TIME = 100;
|
|
@@ -436,8 +234,6 @@ var delay = (durationOrMode) => {
|
|
|
436
234
|
};
|
|
437
235
|
|
|
438
236
|
// src/context/fetch.ts
|
|
439
|
-
init_cjs_shims();
|
|
440
|
-
init_polyfills_node();
|
|
441
237
|
var import_is_node_process2 = require("is-node-process");
|
|
442
238
|
var import_headers_polyfill3 = require("headers-polyfill");
|
|
443
239
|
var useFetch = (0, import_is_node_process2.isNodeProcess)() ? require("node-fetch") : window.fetch;
|
|
@@ -553,13 +349,7 @@ function passthrough() {
|
|
|
553
349
|
};
|
|
554
350
|
}
|
|
555
351
|
|
|
556
|
-
// src/utils/request/parseBody.ts
|
|
557
|
-
init_cjs_shims();
|
|
558
|
-
init_polyfills_node();
|
|
559
|
-
|
|
560
352
|
// src/utils/internal/jsonParse.ts
|
|
561
|
-
init_cjs_shims();
|
|
562
|
-
init_polyfills_node();
|
|
563
353
|
function jsonParse(value) {
|
|
564
354
|
try {
|
|
565
355
|
return JSON.parse(value);
|
|
@@ -569,8 +359,6 @@ function jsonParse(value) {
|
|
|
569
359
|
}
|
|
570
360
|
|
|
571
361
|
// src/utils/internal/parseMultipartData.ts
|
|
572
|
-
init_cjs_shims();
|
|
573
|
-
init_polyfills_node();
|
|
574
362
|
var import_headers_polyfill5 = require("headers-polyfill");
|
|
575
363
|
function parseContentHeaders(headersString) {
|
|
576
364
|
var _a, _b;
|
|
@@ -610,8 +398,8 @@ function parseMultipartData(data2, headers) {
|
|
|
610
398
|
}
|
|
611
399
|
const parsedBody = {};
|
|
612
400
|
try {
|
|
613
|
-
for (const
|
|
614
|
-
const [contentHeaders, ...rest] =
|
|
401
|
+
for (const field2 of fields) {
|
|
402
|
+
const [contentHeaders, ...rest] = field2.split("\r\n\r\n");
|
|
615
403
|
const contentBody = rest.join("\r\n\r\n");
|
|
616
404
|
const { contentType: contentType2, filename, name } = parseContentHeaders(contentHeaders);
|
|
617
405
|
const value = filename === void 0 ? contentBody : new File([contentBody], filename, { type: contentType2 });
|
|
@@ -649,14 +437,10 @@ function parseBody(body2, headers) {
|
|
|
649
437
|
}
|
|
650
438
|
|
|
651
439
|
// src/utils/request/setRequestCookies.ts
|
|
652
|
-
init_cjs_shims();
|
|
653
|
-
init_polyfills_node();
|
|
654
440
|
var cookieUtils2 = __toESM(require("cookie"));
|
|
655
441
|
var import_cookies = require("@mswjs/cookies");
|
|
656
442
|
|
|
657
443
|
// src/utils/request/getRequestCookies.ts
|
|
658
|
-
init_cjs_shims();
|
|
659
|
-
init_polyfills_node();
|
|
660
444
|
var cookieUtils = __toESM(require("cookie"));
|
|
661
445
|
function getAllCookies() {
|
|
662
446
|
return cookieUtils.parse(document.cookie);
|
|
@@ -721,13 +505,9 @@ function parseIsomorphicRequest(request) {
|
|
|
721
505
|
}
|
|
722
506
|
|
|
723
507
|
// src/utils/handleRequest.ts
|
|
724
|
-
init_cjs_shims();
|
|
725
|
-
init_polyfills_node();
|
|
726
508
|
var import_until = require("@open-draft/until");
|
|
727
509
|
|
|
728
510
|
// src/utils/getResponse.ts
|
|
729
|
-
init_cjs_shims();
|
|
730
|
-
init_polyfills_node();
|
|
731
511
|
var getResponse = async (request, handlers, resolutionContext) => {
|
|
732
512
|
const relevantHandlers = handlers.filter((handler) => {
|
|
733
513
|
return handler.test(request, resolutionContext);
|
|
@@ -775,9 +555,7 @@ var getResponse = async (request, handlers, resolutionContext) => {
|
|
|
775
555
|
};
|
|
776
556
|
|
|
777
557
|
// src/utils/internal/devUtils.ts
|
|
778
|
-
|
|
779
|
-
init_polyfills_node();
|
|
780
|
-
var import_outvariant = __toESM(require_lib());
|
|
558
|
+
var import_outvariant = require("outvariant");
|
|
781
559
|
var LIBRARY_PREFIX = "[MSW]";
|
|
782
560
|
function formatMessage(message, ...positionals) {
|
|
783
561
|
const interpolatedMessage = (0, import_outvariant.format)(message, ...positionals);
|
|
@@ -796,18 +574,12 @@ var devUtils = {
|
|
|
796
574
|
};
|
|
797
575
|
|
|
798
576
|
// src/utils/request/onUnhandledRequest.ts
|
|
799
|
-
init_cjs_shims();
|
|
800
|
-
init_polyfills_node();
|
|
801
577
|
var import_js_levenshtein = __toESM(require("js-levenshtein"));
|
|
802
578
|
|
|
803
579
|
// src/utils/internal/parseGraphQLRequest.ts
|
|
804
|
-
init_cjs_shims();
|
|
805
|
-
init_polyfills_node();
|
|
806
580
|
var import_graphql = require("graphql");
|
|
807
581
|
|
|
808
582
|
// src/utils/request/getPublicUrlFromRequest.ts
|
|
809
|
-
init_cjs_shims();
|
|
810
|
-
init_polyfills_node();
|
|
811
583
|
var getPublicUrlFromRequest = (request) => {
|
|
812
584
|
return request.referrer.startsWith(request.url.origin) ? request.url.pathname : new URL(request.url.pathname, `${request.url.protocol}//${request.url.host}`).href;
|
|
813
585
|
};
|
|
@@ -908,23 +680,11 @@ function parseGraphQLRequest(request) {
|
|
|
908
680
|
}
|
|
909
681
|
|
|
910
682
|
// src/utils/internal/isStringEqual.ts
|
|
911
|
-
init_cjs_shims();
|
|
912
|
-
init_polyfills_node();
|
|
913
683
|
function isStringEqual(actual, expected) {
|
|
914
684
|
return actual.toLowerCase() === expected.toLowerCase();
|
|
915
685
|
}
|
|
916
686
|
|
|
917
|
-
// src/handlers/RestHandler.ts
|
|
918
|
-
init_cjs_shims();
|
|
919
|
-
init_polyfills_node();
|
|
920
|
-
|
|
921
|
-
// src/context/index.ts
|
|
922
|
-
init_cjs_shims();
|
|
923
|
-
init_polyfills_node();
|
|
924
|
-
|
|
925
687
|
// src/context/cookie.ts
|
|
926
|
-
init_cjs_shims();
|
|
927
|
-
init_polyfills_node();
|
|
928
688
|
var cookieUtils3 = __toESM(require("cookie"));
|
|
929
689
|
var cookie = (name, value, options) => {
|
|
930
690
|
return (res) => {
|
|
@@ -938,8 +698,6 @@ var cookie = (name, value, options) => {
|
|
|
938
698
|
};
|
|
939
699
|
|
|
940
700
|
// src/context/body.ts
|
|
941
|
-
init_cjs_shims();
|
|
942
|
-
init_polyfills_node();
|
|
943
701
|
var body = (value) => {
|
|
944
702
|
return (res) => {
|
|
945
703
|
res.body = value;
|
|
@@ -947,17 +705,7 @@ var body = (value) => {
|
|
|
947
705
|
};
|
|
948
706
|
};
|
|
949
707
|
|
|
950
|
-
// src/context/data.ts
|
|
951
|
-
init_cjs_shims();
|
|
952
|
-
init_polyfills_node();
|
|
953
|
-
|
|
954
|
-
// src/utils/internal/mergeRight.ts
|
|
955
|
-
init_cjs_shims();
|
|
956
|
-
init_polyfills_node();
|
|
957
|
-
|
|
958
708
|
// src/utils/internal/isObject.ts
|
|
959
|
-
init_cjs_shims();
|
|
960
|
-
init_polyfills_node();
|
|
961
709
|
function isObject(value) {
|
|
962
710
|
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
963
711
|
}
|
|
@@ -980,8 +728,6 @@ function mergeRight(left, right) {
|
|
|
980
728
|
}
|
|
981
729
|
|
|
982
730
|
// src/context/json.ts
|
|
983
|
-
init_cjs_shims();
|
|
984
|
-
init_polyfills_node();
|
|
985
731
|
var json = (body2) => {
|
|
986
732
|
return (res) => {
|
|
987
733
|
res.headers.set("Content-Type", "application/json");
|
|
@@ -1000,8 +746,6 @@ var data = (payload) => {
|
|
|
1000
746
|
};
|
|
1001
747
|
|
|
1002
748
|
// src/context/extensions.ts
|
|
1003
|
-
init_cjs_shims();
|
|
1004
|
-
init_polyfills_node();
|
|
1005
749
|
var extensions = (payload) => {
|
|
1006
750
|
return (res) => {
|
|
1007
751
|
const prevBody = jsonParse(res.body) || {};
|
|
@@ -1011,8 +755,6 @@ var extensions = (payload) => {
|
|
|
1011
755
|
};
|
|
1012
756
|
|
|
1013
757
|
// src/context/errors.ts
|
|
1014
|
-
init_cjs_shims();
|
|
1015
|
-
init_polyfills_node();
|
|
1016
758
|
var errors = (errorsList) => {
|
|
1017
759
|
return (res) => {
|
|
1018
760
|
if (errorsList == null) {
|
|
@@ -1025,8 +767,6 @@ var errors = (errorsList) => {
|
|
|
1025
767
|
};
|
|
1026
768
|
|
|
1027
769
|
// src/context/text.ts
|
|
1028
|
-
init_cjs_shims();
|
|
1029
|
-
init_polyfills_node();
|
|
1030
770
|
var text = (body2) => {
|
|
1031
771
|
return (res) => {
|
|
1032
772
|
res.headers.set("Content-Type", "text/plain");
|
|
@@ -1036,8 +776,6 @@ var text = (body2) => {
|
|
|
1036
776
|
};
|
|
1037
777
|
|
|
1038
778
|
// src/context/xml.ts
|
|
1039
|
-
init_cjs_shims();
|
|
1040
|
-
init_polyfills_node();
|
|
1041
779
|
var xml = (body2) => {
|
|
1042
780
|
return (res) => {
|
|
1043
781
|
res.headers.set("Content-Type", "text/xml");
|
|
@@ -1047,8 +785,6 @@ var xml = (body2) => {
|
|
|
1047
785
|
};
|
|
1048
786
|
|
|
1049
787
|
// src/utils/logging/getStatusCodeColor.ts
|
|
1050
|
-
init_cjs_shims();
|
|
1051
|
-
init_polyfills_node();
|
|
1052
788
|
function getStatusCodeColor(status2) {
|
|
1053
789
|
if (status2 < 300) {
|
|
1054
790
|
return "#69AB32" /* Success */;
|
|
@@ -1060,16 +796,12 @@ function getStatusCodeColor(status2) {
|
|
|
1060
796
|
}
|
|
1061
797
|
|
|
1062
798
|
// src/utils/logging/getTimestamp.ts
|
|
1063
|
-
init_cjs_shims();
|
|
1064
|
-
init_polyfills_node();
|
|
1065
799
|
function getTimestamp() {
|
|
1066
800
|
const now = new Date();
|
|
1067
801
|
return [now.getHours(), now.getMinutes(), now.getSeconds()].map(String).map((chunk) => chunk.slice(0, 2)).map((chunk) => chunk.padStart(2, "0")).join(":");
|
|
1068
802
|
}
|
|
1069
803
|
|
|
1070
804
|
// src/utils/logging/prepareRequest.ts
|
|
1071
|
-
init_cjs_shims();
|
|
1072
|
-
init_polyfills_node();
|
|
1073
805
|
function prepareRequest(request) {
|
|
1074
806
|
return __spreadProps(__spreadValues({}, request), {
|
|
1075
807
|
headers: request.headers.all()
|
|
@@ -1077,8 +809,6 @@ function prepareRequest(request) {
|
|
|
1077
809
|
}
|
|
1078
810
|
|
|
1079
811
|
// src/utils/logging/prepareResponse.ts
|
|
1080
|
-
init_cjs_shims();
|
|
1081
|
-
init_polyfills_node();
|
|
1082
812
|
var import_headers_polyfill6 = require("headers-polyfill");
|
|
1083
813
|
function prepareResponse(res) {
|
|
1084
814
|
const responseHeaders = (0, import_headers_polyfill6.objectToHeaders)(res.headers);
|
|
@@ -1088,18 +818,10 @@ function prepareResponse(res) {
|
|
|
1088
818
|
}
|
|
1089
819
|
|
|
1090
820
|
// src/utils/matching/matchRequestUrl.ts
|
|
1091
|
-
init_cjs_shims();
|
|
1092
|
-
init_polyfills_node();
|
|
1093
821
|
var import_path_to_regexp = require("path-to-regexp");
|
|
1094
822
|
var import_getCleanUrl = require("@mswjs/interceptors/lib/utils/getCleanUrl");
|
|
1095
823
|
|
|
1096
|
-
// src/utils/matching/normalizePath.ts
|
|
1097
|
-
init_cjs_shims();
|
|
1098
|
-
init_polyfills_node();
|
|
1099
|
-
|
|
1100
824
|
// src/utils/url/cleanUrl.ts
|
|
1101
|
-
init_cjs_shims();
|
|
1102
|
-
init_polyfills_node();
|
|
1103
825
|
var REDUNDANT_CHARACTERS_EXP = /[\?|#].*$/g;
|
|
1104
826
|
function getSearchParams(path) {
|
|
1105
827
|
return new URL(`/${path}`, "http://localhost").searchParams;
|
|
@@ -1108,13 +830,7 @@ function cleanUrl(path) {
|
|
|
1108
830
|
return path.replace(REDUNDANT_CHARACTERS_EXP, "");
|
|
1109
831
|
}
|
|
1110
832
|
|
|
1111
|
-
// src/utils/url/getAbsoluteUrl.ts
|
|
1112
|
-
init_cjs_shims();
|
|
1113
|
-
init_polyfills_node();
|
|
1114
|
-
|
|
1115
833
|
// src/utils/url/isAbsoluteUrl.ts
|
|
1116
|
-
init_cjs_shims();
|
|
1117
|
-
init_polyfills_node();
|
|
1118
834
|
function isAbsoluteUrl(url) {
|
|
1119
835
|
return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
|
|
1120
836
|
}
|
|
@@ -1227,13 +943,24 @@ var RestHandler = class extends RequestHandler {
|
|
|
1227
943
|
}
|
|
1228
944
|
};
|
|
1229
945
|
|
|
1230
|
-
// src/
|
|
1231
|
-
|
|
1232
|
-
|
|
946
|
+
// src/context/field.ts
|
|
947
|
+
var import_outvariant2 = require("outvariant");
|
|
948
|
+
var field = (fieldName, fieldValue) => {
|
|
949
|
+
return (res) => {
|
|
950
|
+
validateFieldName(fieldName);
|
|
951
|
+
const prevBody = jsonParse(res.body) || {};
|
|
952
|
+
const nextBody = mergeRight(prevBody, { [fieldName]: fieldValue });
|
|
953
|
+
return json(nextBody)(res);
|
|
954
|
+
};
|
|
955
|
+
};
|
|
956
|
+
function validateFieldName(fieldName) {
|
|
957
|
+
(0, import_outvariant2.invariant)(fieldName.trim() !== "", devUtils.formatMessage("Failed to set a custom field on a GraphQL response: field name cannot be empty."));
|
|
958
|
+
(0, import_outvariant2.invariant)(fieldName !== "data", devUtils.formatMessage('Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.data()" instead?', fieldName));
|
|
959
|
+
(0, import_outvariant2.invariant)(fieldName !== "errors", devUtils.formatMessage('Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.errors()" instead?', fieldName));
|
|
960
|
+
(0, import_outvariant2.invariant)(fieldName !== "extensions", devUtils.formatMessage('Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.extensions()" instead?', fieldName));
|
|
961
|
+
}
|
|
1233
962
|
|
|
1234
963
|
// src/utils/internal/tryCatch.ts
|
|
1235
|
-
init_cjs_shims();
|
|
1236
|
-
init_polyfills_node();
|
|
1237
964
|
function tryCatch(fn, onException) {
|
|
1238
965
|
try {
|
|
1239
966
|
const result = fn();
|
|
@@ -1248,7 +975,8 @@ var graphqlContext = __spreadProps(__spreadValues({}, defaultContext), {
|
|
|
1248
975
|
data,
|
|
1249
976
|
extensions,
|
|
1250
977
|
errors,
|
|
1251
|
-
cookie
|
|
978
|
+
cookie,
|
|
979
|
+
field
|
|
1252
980
|
});
|
|
1253
981
|
function isDocumentNode(value) {
|
|
1254
982
|
if (value == null) {
|
|
@@ -1428,8 +1156,6 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
1428
1156
|
}
|
|
1429
1157
|
|
|
1430
1158
|
// src/utils/request/readResponseCookies.ts
|
|
1431
|
-
init_cjs_shims();
|
|
1432
|
-
init_polyfills_node();
|
|
1433
1159
|
var import_cookies2 = require("@mswjs/cookies");
|
|
1434
1160
|
function readResponseCookies(request, response2) {
|
|
1435
1161
|
import_cookies2.store.add(__spreadProps(__spreadValues({}, request), { url: request.url.toString() }), response2);
|
|
@@ -1491,8 +1217,6 @@ async function handleRequest(request, handlers, options, emitter, handleRequestO
|
|
|
1491
1217
|
}
|
|
1492
1218
|
|
|
1493
1219
|
// src/utils/internal/pipeEvents.ts
|
|
1494
|
-
init_cjs_shims();
|
|
1495
|
-
init_polyfills_node();
|
|
1496
1220
|
function pipeEvents(source, destination) {
|
|
1497
1221
|
const rawEmit = source.emit;
|
|
1498
1222
|
if (rawEmit._isPiped) {
|
|
@@ -1523,21 +1247,26 @@ function createSetupServer(...interceptors) {
|
|
|
1523
1247
|
throw new Error(devUtils.formatMessage("Failed to execute `setupServer` in the environment that is not Node.js (i.e. a browser). Consider using `setupWorker` instead."));
|
|
1524
1248
|
}
|
|
1525
1249
|
let resolvedOptions = {};
|
|
1526
|
-
const interceptor =
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1250
|
+
const interceptor = new import_interceptors.BatchInterceptor({
|
|
1251
|
+
name: "setup-server",
|
|
1252
|
+
interceptors: interceptors.map((Interceptor2) => new Interceptor2())
|
|
1253
|
+
});
|
|
1254
|
+
interceptor.on("request", async function setupServerListener(request) {
|
|
1255
|
+
const mockedRequest = parseIsomorphicRequest(request);
|
|
1256
|
+
const response2 = await handleRequest(mockedRequest, currentHandlers, resolvedOptions, emitter, {
|
|
1257
|
+
transformResponse(response3) {
|
|
1258
|
+
return {
|
|
1259
|
+
status: response3.status,
|
|
1260
|
+
statusText: response3.statusText,
|
|
1261
|
+
headers: response3.headers.all(),
|
|
1262
|
+
body: response3.body
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
});
|
|
1266
|
+
if (response2) {
|
|
1267
|
+
request.respondWith(response2);
|
|
1540
1268
|
}
|
|
1269
|
+
return;
|
|
1541
1270
|
});
|
|
1542
1271
|
interceptor.on("response", (request, response2) => {
|
|
1543
1272
|
if (!request.id) {
|
|
@@ -1586,14 +1315,14 @@ function createSetupServer(...interceptors) {
|
|
|
1586
1315
|
close() {
|
|
1587
1316
|
emitter.removeAllListeners();
|
|
1588
1317
|
publicEmitter.removeAllListeners();
|
|
1589
|
-
interceptor.
|
|
1318
|
+
interceptor.dispose();
|
|
1590
1319
|
}
|
|
1591
1320
|
};
|
|
1592
1321
|
};
|
|
1593
1322
|
}
|
|
1594
1323
|
|
|
1595
1324
|
// src/node/setupServer.ts
|
|
1596
|
-
var setupServer = createSetupServer(import_ClientRequest.
|
|
1325
|
+
var setupServer = createSetupServer(import_ClientRequest.ClientRequestInterceptor, import_XMLHttpRequest.XMLHttpRequestInterceptor);
|
|
1597
1326
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1598
1327
|
0 && (module.exports = {
|
|
1599
1328
|
setupServer
|