msw 0.42.0 → 0.42.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.
@@ -2,7 +2,7 @@
2
2
  /* tslint:disable */
3
3
 
4
4
  /**
5
- * Mock Service Worker (0.42.0).
5
+ * Mock Service Worker (0.42.1).
6
6
  * @see https://github.com/mswjs/msw
7
7
  * - Please do NOT modify this file.
8
8
  * - Please do NOT serve this file on production.
@@ -391,8 +391,8 @@ function parseMultipartData(data2, headers) {
391
391
  }
392
392
  const parsedBody = {};
393
393
  try {
394
- for (const field of fields) {
395
- const [contentHeaders, ...rest] = field.split("\r\n\r\n");
394
+ for (const field2 of fields) {
395
+ const [contentHeaders, ...rest] = field2.split("\r\n\r\n");
396
396
  const contentBody = rest.join("\r\n\r\n");
397
397
  const { contentType: contentType2, filename, name } = parseContentHeaders(contentHeaders);
398
398
  const value = filename === void 0 ? contentBody : new File([contentBody], filename, { type: contentType2 });
@@ -936,6 +936,23 @@ var RestHandler = class extends RequestHandler {
936
936
  }
937
937
  };
938
938
 
939
+ // src/context/field.ts
940
+ var import_outvariant2 = require("outvariant");
941
+ var field = (fieldName, fieldValue) => {
942
+ return (res) => {
943
+ validateFieldName(fieldName);
944
+ const prevBody = jsonParse(res.body) || {};
945
+ const nextBody = mergeRight(prevBody, { [fieldName]: fieldValue });
946
+ return json(nextBody)(res);
947
+ };
948
+ };
949
+ function validateFieldName(fieldName) {
950
+ (0, import_outvariant2.invariant)(fieldName.trim() !== "", devUtils.formatMessage("Failed to set a custom field on a GraphQL response: field name cannot be empty."));
951
+ (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));
952
+ (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));
953
+ (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));
954
+ }
955
+
939
956
  // src/utils/internal/tryCatch.ts
940
957
  function tryCatch(fn, onException) {
941
958
  try {
@@ -951,7 +968,8 @@ var graphqlContext = __spreadProps(__spreadValues({}, defaultContext), {
951
968
  data,
952
969
  extensions,
953
970
  errors,
954
- cookie
971
+ cookie,
972
+ field
955
973
  });
956
974
  function isDocumentNode(value) {
957
975
  if (value == null) {
@@ -377,8 +377,8 @@ function parseMultipartData(data2, headers) {
377
377
  }
378
378
  const parsedBody = {};
379
379
  try {
380
- for (const field of fields) {
381
- const [contentHeaders, ...rest] = field.split("\r\n\r\n");
380
+ for (const field2 of fields) {
381
+ const [contentHeaders, ...rest] = field2.split("\r\n\r\n");
382
382
  const contentBody = rest.join("\r\n\r\n");
383
383
  const { contentType: contentType2, filename, name } = parseContentHeaders(contentHeaders);
384
384
  const value = filename === void 0 ? contentBody : new File([contentBody], filename, { type: contentType2 });
@@ -924,6 +924,23 @@ var RestHandler = class extends RequestHandler {
924
924
  }
925
925
  };
926
926
 
927
+ // src/context/field.ts
928
+ import { invariant } from "outvariant";
929
+ var field = (fieldName, fieldValue) => {
930
+ return (res) => {
931
+ validateFieldName(fieldName);
932
+ const prevBody = jsonParse(res.body) || {};
933
+ const nextBody = mergeRight(prevBody, { [fieldName]: fieldValue });
934
+ return json(nextBody)(res);
935
+ };
936
+ };
937
+ function validateFieldName(fieldName) {
938
+ invariant(fieldName.trim() !== "", devUtils.formatMessage("Failed to set a custom field on a GraphQL response: field name cannot be empty."));
939
+ 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));
940
+ 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));
941
+ 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));
942
+ }
943
+
927
944
  // src/utils/internal/tryCatch.ts
928
945
  function tryCatch(fn, onException) {
929
946
  try {
@@ -939,7 +956,8 @@ var graphqlContext = __spreadProps(__spreadValues({}, defaultContext), {
939
956
  data,
940
957
  extensions,
941
958
  errors,
942
- cookie
959
+ cookie,
960
+ field
943
961
  });
944
962
  function isDocumentNode(value) {
945
963
  if (value == null) {
package/lib/node/index.js CHANGED
@@ -398,8 +398,8 @@ function parseMultipartData(data2, headers) {
398
398
  }
399
399
  const parsedBody = {};
400
400
  try {
401
- for (const field of fields) {
402
- const [contentHeaders, ...rest] = field.split("\r\n\r\n");
401
+ for (const field2 of fields) {
402
+ const [contentHeaders, ...rest] = field2.split("\r\n\r\n");
403
403
  const contentBody = rest.join("\r\n\r\n");
404
404
  const { contentType: contentType2, filename, name } = parseContentHeaders(contentHeaders);
405
405
  const value = filename === void 0 ? contentBody : new File([contentBody], filename, { type: contentType2 });
@@ -943,6 +943,23 @@ var RestHandler = class extends RequestHandler {
943
943
  }
944
944
  };
945
945
 
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
+ }
962
+
946
963
  // src/utils/internal/tryCatch.ts
947
964
  function tryCatch(fn, onException) {
948
965
  try {
@@ -958,7 +975,8 @@ var graphqlContext = __spreadProps(__spreadValues({}, defaultContext), {
958
975
  data,
959
976
  extensions,
960
977
  errors,
961
- cookie
978
+ cookie,
979
+ field
962
980
  });
963
981
  function isDocumentNode(value) {
964
982
  if (value == null) {