msw 2.12.6 → 2.12.7

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 (58) hide show
  1. package/lib/core/{HttpResponse-DM21DMt_.d.ts → HttpResponse-CVs3ngx3.d.ts} +12 -2
  2. package/lib/core/{HttpResponse-C86fdZzb.d.mts → HttpResponse-Cw4ELwIN.d.mts} +12 -2
  3. package/lib/core/HttpResponse.d.mts +1 -1
  4. package/lib/core/HttpResponse.d.ts +1 -1
  5. package/lib/core/SetupApi.d.mts +1 -1
  6. package/lib/core/SetupApi.d.ts +1 -1
  7. package/lib/core/getResponse.d.mts +1 -1
  8. package/lib/core/getResponse.d.ts +1 -1
  9. package/lib/core/graphql.d.mts +21 -59
  10. package/lib/core/graphql.d.ts +21 -59
  11. package/lib/core/graphql.js +14 -15
  12. package/lib/core/graphql.js.map +1 -1
  13. package/lib/core/graphql.mjs +14 -15
  14. package/lib/core/graphql.mjs.map +1 -1
  15. package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
  16. package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
  17. package/lib/core/handlers/GraphQLHandler.js +42 -17
  18. package/lib/core/handlers/GraphQLHandler.js.map +1 -1
  19. package/lib/core/handlers/GraphQLHandler.mjs +44 -17
  20. package/lib/core/handlers/GraphQLHandler.mjs.map +1 -1
  21. package/lib/core/handlers/HttpHandler.d.mts +1 -1
  22. package/lib/core/handlers/HttpHandler.d.ts +1 -1
  23. package/lib/core/handlers/RequestHandler.d.mts +1 -1
  24. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  25. package/lib/core/http.d.mts +1 -1
  26. package/lib/core/http.d.ts +1 -1
  27. package/lib/core/index.d.mts +2 -2
  28. package/lib/core/index.d.ts +2 -2
  29. package/lib/core/index.js.map +1 -1
  30. package/lib/core/index.mjs.map +1 -1
  31. package/lib/core/passthrough.d.mts +1 -1
  32. package/lib/core/passthrough.d.ts +1 -1
  33. package/lib/core/sse.d.mts +1 -1
  34. package/lib/core/sse.d.ts +1 -1
  35. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  36. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  37. package/lib/core/utils/executeHandlers.d.mts +1 -1
  38. package/lib/core/utils/executeHandlers.d.ts +1 -1
  39. package/lib/core/utils/handleRequest.d.mts +1 -1
  40. package/lib/core/utils/handleRequest.d.ts +1 -1
  41. package/lib/core/utils/internal/isHandlerKind.d.mts +1 -1
  42. package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
  43. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
  44. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
  45. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  46. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  47. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  48. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  49. package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
  50. package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
  51. package/lib/iife/index.js +57 -32
  52. package/lib/iife/index.js.map +1 -1
  53. package/lib/mockServiceWorker.js +1 -1
  54. package/package.json +2 -2
  55. package/src/core/graphql.ts +43 -52
  56. package/src/core/handlers/GraphQLHandler.test.ts +1 -1
  57. package/src/core/handlers/GraphQLHandler.ts +73 -25
  58. package/src/core/index.ts +6 -1
package/lib/iife/index.js CHANGED
@@ -18711,6 +18711,9 @@ ${operationTypes.join("\n")}
18711
18711
  options: createHttpHandler("OPTIONS" /* OPTIONS */)
18712
18712
  };
18713
18713
 
18714
+ // src/core/handlers/GraphQLHandler.ts
18715
+ init_graphql2();
18716
+
18714
18717
  // node_modules/.pnpm/headers-polyfill@4.0.3/node_modules/headers-polyfill/lib/index.mjs
18715
18718
  var __create2 = Object.create;
18716
18719
  var __defProp3 = Object.defineProperty;
@@ -19321,32 +19324,55 @@ ${operationTypes.join("\n")}
19321
19324
  }
19322
19325
  return typeof value === "object" && "kind" in value && "definitions" in value;
19323
19326
  }
19327
+ function isDocumentTypeDecoration(value) {
19328
+ return value instanceof String;
19329
+ }
19324
19330
  var GraphQLHandler = class _GraphQLHandler extends RequestHandler {
19325
19331
  endpoint;
19326
19332
  static parsedRequestCache = /* @__PURE__ */ new WeakMap();
19327
- constructor(operationType, predicate, endpoint, resolver, options) {
19328
- let resolvedOperationName = predicate;
19329
- if (isDocumentNode(resolvedOperationName)) {
19330
- const parsedNode = parseDocumentNode(resolvedOperationName);
19331
- if (parsedNode.operationType !== operationType) {
19332
- throw new Error(
19333
- `Failed to create a GraphQL handler: provided a DocumentNode with a mismatched operation type (expected "${operationType}", but got "${parsedNode.operationType}").`
19334
- );
19335
- }
19336
- if (!parsedNode.operationName) {
19337
- throw new Error(
19338
- `Failed to create a GraphQL handler: provided a DocumentNode with no operation name.`
19339
- );
19340
- }
19341
- resolvedOperationName = parsedNode.operationName;
19333
+ static #parseOperationName(predicate, operationType) {
19334
+ const getOperationName = (node) => {
19335
+ invariant(
19336
+ node.operationType === operationType,
19337
+ 'Failed to create a GraphQL handler: provided a DocumentNode with a mismatched operation type (expected "%s" but got "%s").',
19338
+ operationType,
19339
+ node.operationType
19340
+ );
19341
+ invariant(
19342
+ node.operationName,
19343
+ "Failed to create a GraphQL handler: provided a DocumentNode without operation name"
19344
+ );
19345
+ return node.operationName;
19346
+ };
19347
+ if (isDocumentNode(predicate)) {
19348
+ return getOperationName(parseDocumentNode(predicate));
19342
19349
  }
19343
- const displayOperationName = typeof resolvedOperationName === "function" ? "[custom predicate]" : resolvedOperationName;
19350
+ if (isDocumentTypeDecoration(predicate)) {
19351
+ const documentNode = parse4(predicate.toString());
19352
+ invariant(
19353
+ isDocumentNode(documentNode),
19354
+ "Failed to create a GraphQL handler: given TypedDocumentString (%s) does not produce a valid DocumentNode",
19355
+ predicate
19356
+ );
19357
+ return getOperationName(parseDocumentNode(documentNode));
19358
+ }
19359
+ return predicate;
19360
+ }
19361
+ constructor(operationType, predicate, endpoint, resolver, options) {
19362
+ const operationName = _GraphQLHandler.#parseOperationName(
19363
+ predicate,
19364
+ operationType
19365
+ );
19366
+ const displayOperationName = typeof operationName === "function" ? "[custom predicate]" : operationName;
19344
19367
  const header = operationType === "all" ? `${operationType} (origin: ${endpoint.toString()})` : `${operationType}${displayOperationName ? ` ${displayOperationName}` : ""} (origin: ${endpoint.toString()})`;
19345
19368
  super({
19346
19369
  info: {
19347
19370
  header,
19348
19371
  operationType,
19349
- operationName: resolvedOperationName
19372
+ operationName: _GraphQLHandler.#parseOperationName(
19373
+ predicate,
19374
+ operationType
19375
+ )
19350
19376
  },
19351
19377
  resolver,
19352
19378
  options
@@ -19466,11 +19492,11 @@ Consider naming this operation or using "graphql.operation()" request handler to
19466
19492
  };
19467
19493
  }
19468
19494
  function createGraphQLOperationHandler(url) {
19469
- return (resolver) => {
19470
- return new GraphQLHandler("all", new RegExp(".*"), url, resolver);
19495
+ return (resolver, options) => {
19496
+ return new GraphQLHandler("all", new RegExp(".*"), url, resolver, options);
19471
19497
  };
19472
19498
  }
19473
- var standardGraphQLHandlers = {
19499
+ var graphql2 = {
19474
19500
  /**
19475
19501
  * Intercepts a GraphQL query by a given name.
19476
19502
  *
@@ -19504,17 +19530,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
19504
19530
  *
19505
19531
  * @see {@link https://mswjs.io/docs/api/graphql#graphqloperationresolver `graphql.operation()` API reference}
19506
19532
  */
19507
- operation: createGraphQLOperationHandler("*")
19508
- };
19509
- function createGraphQLLink(url) {
19510
- return {
19511
- operation: createGraphQLOperationHandler(url),
19512
- query: createScopedGraphQLHandler("query", url),
19513
- mutation: createScopedGraphQLHandler("mutation", url)
19514
- };
19515
- }
19516
- var graphql2 = {
19517
- ...standardGraphQLHandlers,
19533
+ operation: createGraphQLOperationHandler("*"),
19518
19534
  /**
19519
19535
  * Intercepts GraphQL operations scoped by the given URL.
19520
19536
  *
@@ -19524,7 +19540,16 @@ Consider naming this operation or using "graphql.operation()" request handler to
19524
19540
  *
19525
19541
  * @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
19526
19542
  */
19527
- link: createGraphQLLink
19543
+ link(url) {
19544
+ return {
19545
+ operation: createGraphQLOperationHandler(url),
19546
+ query: createScopedGraphQLHandler("query", url),
19547
+ mutation: createScopedGraphQLHandler(
19548
+ "mutation",
19549
+ url
19550
+ )
19551
+ };
19552
+ }
19528
19553
  };
19529
19554
 
19530
19555
  // src/core/handlers/WebSocketHandler.ts