msw 0.28.1 → 0.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/cli/init.js +14 -6
  2. package/lib/esm/RequestHandler-deps.js +162 -130
  3. package/lib/esm/fetch-deps.js +306 -95
  4. package/lib/esm/graphql-deps.js +26 -19
  5. package/lib/esm/index-deps.js +2 -2
  6. package/lib/esm/index.js +5291 -710
  7. package/lib/esm/index2.js +2 -2
  8. package/lib/esm/mockServiceWorker.js +4 -3
  9. package/lib/esm/rest-deps.js +4 -4
  10. package/lib/esm/xml-deps.js +1 -217
  11. package/lib/iife/index.js +4 -4
  12. package/lib/iife/mockServiceWorker.js +4 -3
  13. package/lib/types/context/body.d.ts +1 -1
  14. package/lib/types/context/json.d.ts +1 -1
  15. package/lib/types/context/text.d.ts +1 -1
  16. package/lib/types/context/xml.d.ts +1 -1
  17. package/lib/types/handlers/GraphQLHandler.d.ts +4 -2
  18. package/lib/types/handlers/RequestHandler.d.ts +12 -8
  19. package/lib/types/handlers/RestHandler.d.ts +2 -2
  20. package/lib/types/node/glossary.d.ts +2 -1
  21. package/lib/types/response.d.ts +1 -1
  22. package/lib/types/setupWorker/glossary.d.ts +21 -16
  23. package/lib/types/setupWorker/start/createFallbackStart.d.ts +2 -0
  24. package/lib/types/setupWorker/start/createStartHandler.d.ts +2 -0
  25. package/lib/types/setupWorker/start/utils/enableMocking.d.ts +5 -0
  26. package/lib/types/setupWorker/start/utils/prepareStartHandler.d.ts +9 -0
  27. package/lib/types/setupWorker/start/utils/printStartMessage.d.ts +7 -0
  28. package/lib/types/setupWorker/start/utils/validateWorkerScope.d.ts +2 -0
  29. package/lib/types/setupWorker/stop/createFallbackStop.d.ts +2 -0
  30. package/lib/types/setupWorker/stop/createStop.d.ts +2 -2
  31. package/lib/types/setupWorker/stop/utils/printStopMessage.d.ts +3 -0
  32. package/lib/types/sharedOptions.d.ts +3 -2
  33. package/lib/types/utils/getResponse.d.ts +2 -3
  34. package/lib/types/utils/handleRequest.d.ts +27 -0
  35. package/lib/types/utils/internal/isIterable.d.ts +4 -0
  36. package/lib/types/utils/internal/tryCatch.d.ts +1 -0
  37. package/lib/types/utils/logging/prepareResponse.d.ts +3 -3
  38. package/lib/types/utils/request/parseIsomorphicRequest.d.ts +6 -0
  39. package/lib/types/utils/request/parseWorkerRequest.d.ts +4 -0
  40. package/lib/types/utils/worker/createFallbackRequestListener.d.ts +3 -0
  41. package/lib/umd/index.js +27002 -5268
  42. package/lib/umd/mockServiceWorker.js +4 -3
  43. package/native/lib/index.js +4374 -4281
  44. package/node/lib/index.js +1385 -1292
  45. package/package.json +33 -33
  46. package/lib/types/setupWorker/start/createStart.d.ts +0 -2
  47. package/lib/types/setupWorker/start/utils/activateMocking.d.ts +0 -2
@@ -1,15 +1,15 @@
1
- import { j as jsonParse, b as set, s as status, d as delay, f as fetch } from './fetch-deps.js';
1
+ import { j as jsonParse, a as set, s as status, d as delay, f as fetch, b as cookie } from './fetch-deps.js';
2
2
  import { d as data, e as errors } from './errors-deps.js';
3
- import { g as getPublicUrlFromRequest, k as __rest, R as RequestHandler, m as matchRequestUrl, f as prepareRequest, h as prepareResponse, i as getTimestamp, j as getStatusCodeColor } from './RequestHandler-deps.js';
3
+ import { g as getPublicUrlFromRequest, l as __rest, R as RequestHandler, m as matchRequestUrl, h as prepareRequest, i as prepareResponse, j as getTimestamp, k as getStatusCodeColor } from './RequestHandler-deps.js';
4
4
 
5
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
5
+ function _typeof$2(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$2 = function _typeof(obj) { return typeof obj; }; } else { _typeof$2 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$2(obj); }
6
6
 
7
7
  /**
8
8
  * Return true if `value` is object-like. A value is object-like if it's not
9
9
  * `null` and has a `typeof` result of "object".
10
10
  */
11
11
  function isObjectLike(value) {
12
- return _typeof(value) == 'object' && value !== null;
12
+ return _typeof$2(value) == 'object' && value !== null;
13
13
  }
14
14
 
15
15
  // In ES2015 (or a polyfilled) environment, this will be Symbol.iterator
@@ -111,9 +111,9 @@ function _typeof$1(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "func
111
111
 
112
112
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
113
113
 
114
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
114
+ function _defineProperties$1(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
115
115
 
116
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
116
+ function _createClass$1(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1(Constructor, staticProps); return Constructor; }
117
117
 
118
118
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
119
119
 
@@ -333,7 +333,7 @@ var GraphQLError = /*#__PURE__*/function (_Error) {
333
333
  return _this;
334
334
  }
335
335
 
336
- _createClass(GraphQLError, [{
336
+ _createClass$1(GraphQLError, [{
337
337
  key: "toString",
338
338
  value: function toString() {
339
339
  return printError(this);
@@ -614,7 +614,7 @@ var TokenKind = Object.freeze({
614
614
  * The enum type representing the token kinds values.
615
615
  */
616
616
 
617
- function _typeof$2(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$2 = function _typeof(obj) { return typeof obj; }; } else { _typeof$2 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$2(obj); }
617
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
618
618
  var MAX_ARRAY_LENGTH = 10;
619
619
  var MAX_RECURSIVE_DEPTH = 2;
620
620
  /**
@@ -626,7 +626,7 @@ function inspect(value) {
626
626
  }
627
627
 
628
628
  function formatValue(value, seenValues) {
629
- switch (_typeof$2(value)) {
629
+ switch (_typeof(value)) {
630
630
  case 'string':
631
631
  return JSON.stringify(value);
632
632
 
@@ -768,9 +768,9 @@ function instanceOf(value, constructor) {
768
768
  return false;
769
769
  };
770
770
 
771
- function _defineProperties$1(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
771
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
772
772
 
773
- function _createClass$1(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1(Constructor, staticProps); return Constructor; }
773
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
774
774
 
775
775
  /**
776
776
  * A representation of source input to GraphQL. The `name` and `locationOffset` parameters are
@@ -795,7 +795,7 @@ var Source = /*#__PURE__*/function () {
795
795
  } // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
796
796
 
797
797
 
798
- _createClass$1(Source, [{
798
+ _createClass(Source, [{
799
799
  key: SYMBOL_TO_STRING_TAG,
800
800
  get: function get() {
801
801
  return 'Source';
@@ -3208,11 +3208,7 @@ function parseGraphQLRequest(request) {
3208
3208
  const parsedResult = parseQuery(query);
3209
3209
  if (parsedResult instanceof Error) {
3210
3210
  const requestPublicUrl = getPublicUrlFromRequest(request);
3211
- // Encountered a matching GraphQL request that is syntactically invalid.
3212
- // We may consider getting the parsing error and propagating it to the user.
3213
- console.error(`[MSW] Failed to intercept a GraphQL request to "${request.method} ${requestPublicUrl}": cannot parse query. See the error message from the parser below.`);
3214
- console.error(parsedResult);
3215
- return undefined;
3211
+ throw new Error(`[MSW] Failed to intercept a GraphQL request to "${request.method} ${requestPublicUrl}": cannot parse query. See the error message from the parser below.\n\n${parsedResult}`);
3216
3212
  }
3217
3213
  return {
3218
3214
  operationType: parsedResult.operationType,
@@ -3221,6 +3217,16 @@ function parseGraphQLRequest(request) {
3221
3217
  };
3222
3218
  }
3223
3219
 
3220
+ function tryCatch(fn, onException) {
3221
+ try {
3222
+ const result = fn();
3223
+ return result;
3224
+ }
3225
+ catch (error) {
3226
+ onException === null || onException === void 0 ? void 0 : onException(error);
3227
+ }
3228
+ }
3229
+
3224
3230
  const graphqlContext = {
3225
3231
  set,
3226
3232
  status,
@@ -3228,6 +3234,7 @@ const graphqlContext = {
3228
3234
  fetch,
3229
3235
  data,
3230
3236
  errors,
3237
+ cookie,
3231
3238
  };
3232
3239
  class GraphQLHandler extends RequestHandler {
3233
3240
  constructor(operationType, operationName, endpoint, resolver) {
@@ -3246,7 +3253,7 @@ class GraphQLHandler extends RequestHandler {
3246
3253
  this.endpoint = endpoint;
3247
3254
  }
3248
3255
  parse(request) {
3249
- return parseGraphQLRequest(request);
3256
+ return tryCatch(() => parseGraphQLRequest(request), (error) => console.error(error.message));
3250
3257
  }
3251
3258
  getPublicRequest(request, parsedResult) {
3252
3259
  return Object.assign(Object.assign({}, request), { variables: (parsedResult === null || parsedResult === void 0 ? void 0 : parsedResult.variables) || {} });
@@ -3333,4 +3340,4 @@ function createGraphQLLink(url) {
3333
3340
  }
3334
3341
  const graphql = Object.assign(Object.assign({}, standardGraphQLHandlers), { link: createGraphQLLink });
3335
3342
 
3336
- export { GraphQLHandler as G, graphqlContext as a, graphql as g, parseGraphQLRequest as p };
3343
+ export { GraphQLHandler as G, graphqlContext as a, graphql as g, parseGraphQLRequest as p, tryCatch as t };
@@ -1,5 +1,5 @@
1
- import { s as status, b as set, d as delay, f as fetch, e as json } from './fetch-deps.js';
2
- import { c as cookie, b as body, t as text, x as xml } from './xml-deps.js';
1
+ import { s as status, a as set, b as cookie, d as delay, f as fetch, e as json } from './fetch-deps.js';
2
+ import { b as body, t as text, x as xml } from './xml-deps.js';
3
3
  import { d as data, e as errors } from './errors-deps.js';
4
4
 
5
5
  var index = /*#__PURE__*/Object.freeze({