msw 2.6.0 → 2.6.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 (94) hide show
  1. package/lib/browser/index.js +4 -6
  2. package/lib/browser/index.js.map +1 -1
  3. package/lib/browser/index.mjs +4 -6
  4. package/lib/browser/index.mjs.map +1 -1
  5. package/lib/core/{GraphQLHandler-Doool6Q_.d.mts → GraphQLHandler-B6uni-E_.d.mts} +1 -1
  6. package/lib/core/{GraphQLHandler-udzgBRPf.d.ts → GraphQLHandler-Cjm7JNGi.d.ts} +1 -1
  7. package/lib/core/{HttpResponse-BLGmJolh.d.mts → HttpResponse-63H9vVoL.d.mts} +2 -1
  8. package/lib/core/{HttpResponse-Cgbkdkje.d.ts → HttpResponse-DzhqZzTK.d.ts} +2 -1
  9. package/lib/core/HttpResponse.d.mts +1 -1
  10. package/lib/core/HttpResponse.d.ts +1 -1
  11. package/lib/core/SetupApi.d.mts +1 -1
  12. package/lib/core/SetupApi.d.ts +1 -1
  13. package/lib/core/getResponse.d.mts +1 -1
  14. package/lib/core/getResponse.d.ts +1 -1
  15. package/lib/core/graphql.d.mts +2 -2
  16. package/lib/core/graphql.d.ts +2 -2
  17. package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
  18. package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
  19. package/lib/core/handlers/HttpHandler.d.mts +1 -1
  20. package/lib/core/handlers/HttpHandler.d.ts +1 -1
  21. package/lib/core/handlers/RequestHandler.d.mts +1 -1
  22. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  23. package/lib/core/handlers/RequestHandler.js +2 -0
  24. package/lib/core/handlers/RequestHandler.js.map +1 -1
  25. package/lib/core/handlers/RequestHandler.mjs +2 -0
  26. package/lib/core/handlers/RequestHandler.mjs.map +1 -1
  27. package/lib/core/handlers/WebSocketHandler.d.mts +1 -0
  28. package/lib/core/handlers/WebSocketHandler.d.ts +1 -0
  29. package/lib/core/handlers/WebSocketHandler.js +2 -0
  30. package/lib/core/handlers/WebSocketHandler.js.map +1 -1
  31. package/lib/core/handlers/WebSocketHandler.mjs +2 -0
  32. package/lib/core/handlers/WebSocketHandler.mjs.map +1 -1
  33. package/lib/core/handlers/common.d.mts +3 -0
  34. package/lib/core/handlers/common.d.ts +3 -0
  35. package/lib/core/handlers/common.js +17 -0
  36. package/lib/core/handlers/common.js.map +1 -0
  37. package/lib/core/handlers/common.mjs +1 -0
  38. package/lib/core/handlers/common.mjs.map +1 -0
  39. package/lib/core/http.d.mts +1 -1
  40. package/lib/core/http.d.ts +1 -1
  41. package/lib/core/index.d.mts +2 -2
  42. package/lib/core/index.d.ts +2 -2
  43. package/lib/core/passthrough.d.mts +1 -1
  44. package/lib/core/passthrough.d.ts +1 -1
  45. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  46. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  47. package/lib/core/utils/executeHandlers.d.mts +1 -1
  48. package/lib/core/utils/executeHandlers.d.ts +1 -1
  49. package/lib/core/utils/executeHandlers.js +0 -4
  50. package/lib/core/utils/executeHandlers.js.map +1 -1
  51. package/lib/core/utils/executeHandlers.mjs +0 -6
  52. package/lib/core/utils/executeHandlers.mjs.map +1 -1
  53. package/lib/core/utils/handleRequest.d.mts +1 -1
  54. package/lib/core/utils/handleRequest.d.ts +1 -1
  55. package/lib/core/utils/internal/isHandlerKind.d.mts +17 -0
  56. package/lib/core/utils/internal/isHandlerKind.d.ts +17 -0
  57. package/lib/core/utils/internal/isHandlerKind.js +29 -0
  58. package/lib/core/utils/internal/isHandlerKind.js.map +1 -0
  59. package/lib/core/utils/internal/isHandlerKind.mjs +9 -0
  60. package/lib/core/utils/internal/isHandlerKind.mjs.map +1 -0
  61. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
  62. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
  63. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  64. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  65. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  66. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  67. package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
  68. package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
  69. package/lib/core/ws/handleWebSocketEvent.js +2 -1
  70. package/lib/core/ws/handleWebSocketEvent.js.map +1 -1
  71. package/lib/core/ws/handleWebSocketEvent.mjs +3 -2
  72. package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -1
  73. package/lib/iife/index.js +14 -8
  74. package/lib/iife/index.js.map +1 -1
  75. package/lib/mockServiceWorker.js +1 -1
  76. package/lib/native/index.js +2 -5
  77. package/lib/native/index.js.map +1 -1
  78. package/lib/native/index.mjs +2 -5
  79. package/lib/native/index.mjs.map +1 -1
  80. package/lib/node/index.js +2 -5
  81. package/lib/node/index.js.map +1 -1
  82. package/lib/node/index.mjs +2 -5
  83. package/lib/node/index.mjs.map +1 -1
  84. package/package.json +1 -1
  85. package/src/browser/setupWorker/start/createFallbackRequestListener.ts +2 -1
  86. package/src/browser/setupWorker/start/createRequestListener.ts +2 -7
  87. package/src/core/handlers/RequestHandler.ts +4 -0
  88. package/src/core/handlers/WebSocketHandler.ts +4 -0
  89. package/src/core/handlers/common.ts +1 -0
  90. package/src/core/utils/executeHandlers.ts +1 -5
  91. package/src/core/utils/internal/isHandlerKind.test.ts +64 -0
  92. package/src/core/utils/internal/isHandlerKind.ts +21 -0
  93. package/src/core/ws/handleWebSocketEvent.ts +2 -1
  94. package/src/node/SetupServerCommonApi.ts +4 -8
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/utils/executeHandlers.ts"],"sourcesContent":["import {\n RequestHandler,\n type RequestHandlerExecutionResult,\n} from '../handlers/RequestHandler'\n\nexport interface HandlersExecutionResult {\n handler: RequestHandler\n parsedResult?: any\n response?: Response\n}\n\nexport interface ResponseResolutionContext {\n baseUrl?: string\n}\n\n/**\n * Executes the list of request handlers against the given request.\n * Returns the execution result object containing any matching request\n * handler and any mocked response it returned.\n */\nexport const executeHandlers = async <Handlers extends Array<unknown>>({\n request,\n requestId,\n handlers,\n resolutionContext,\n}: {\n request: Request\n requestId: string\n handlers: Handlers\n resolutionContext?: ResponseResolutionContext\n}): Promise<HandlersExecutionResult | null> => {\n let matchingHandler: RequestHandler | null = null\n let result: RequestHandlerExecutionResult<any> | null = null\n\n for (const handler of handlers) {\n if (!(handler instanceof RequestHandler)) {\n continue\n }\n\n result = await handler.run({ request, requestId, resolutionContext })\n\n // If the handler produces some result for this request,\n // it automatically becomes matching.\n if (result !== null) {\n matchingHandler = handler\n }\n\n // Stop the lookup if this handler returns a mocked response.\n // If it doesn't, it will still be considered the last matching\n // handler until any of them returns a response. This way we can\n // distinguish between fallthrough handlers without responses\n // and the lack of a matching handler.\n if (result?.response) {\n break\n }\n }\n\n if (matchingHandler) {\n return {\n handler: matchingHandler,\n parsedResult: result?.parsedResult,\n response: result?.response,\n }\n }\n\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAGO;AAiBA,MAAM,kBAAkB,OAAwC;AAAA,EACrE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAK+C;AAC7C,MAAI,kBAAyC;AAC7C,MAAI,SAAoD;AAExD,aAAW,WAAW,UAAU;AAC9B,QAAI,EAAE,mBAAmB,uCAAiB;AACxC;AAAA,IACF;AAEA,aAAS,MAAM,QAAQ,IAAI,EAAE,SAAS,WAAW,kBAAkB,CAAC;AAIpE,QAAI,WAAW,MAAM;AACnB,wBAAkB;AAAA,IACpB;AAOA,QAAI,QAAQ,UAAU;AACpB;AAAA,IACF;AAAA,EACF;AAEA,MAAI,iBAAiB;AACnB,WAAO;AAAA,MACL,SAAS;AAAA,MACT,cAAc,QAAQ;AAAA,MACtB,UAAU,QAAQ;AAAA,IACpB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/utils/executeHandlers.ts"],"sourcesContent":["import {\n RequestHandler,\n type RequestHandlerExecutionResult,\n} from '../handlers/RequestHandler'\n\nexport interface HandlersExecutionResult {\n handler: RequestHandler\n parsedResult?: any\n response?: Response\n}\n\nexport interface ResponseResolutionContext {\n baseUrl?: string\n}\n\n/**\n * Executes the list of request handlers against the given request.\n * Returns the execution result object containing any matching request\n * handler and any mocked response it returned.\n */\nexport const executeHandlers = async <Handlers extends Array<RequestHandler>>({\n request,\n requestId,\n handlers,\n resolutionContext,\n}: {\n request: Request\n requestId: string\n handlers: Handlers\n resolutionContext?: ResponseResolutionContext\n}): Promise<HandlersExecutionResult | null> => {\n let matchingHandler: RequestHandler | null = null\n let result: RequestHandlerExecutionResult<any> | null = null\n\n for (const handler of handlers) {\n result = await handler.run({ request, requestId, resolutionContext })\n\n // If the handler produces some result for this request,\n // it automatically becomes matching.\n if (result !== null) {\n matchingHandler = handler\n }\n\n // Stop the lookup if this handler returns a mocked response.\n // If it doesn't, it will still be considered the last matching\n // handler until any of them returns a response. This way we can\n // distinguish between fallthrough handlers without responses\n // and the lack of a matching handler.\n if (result?.response) {\n break\n }\n }\n\n if (matchingHandler) {\n return {\n handler: matchingHandler,\n parsedResult: result?.parsedResult,\n response: result?.response,\n }\n }\n\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBO,MAAM,kBAAkB,OAA+C;AAAA,EAC5E;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAK+C;AAC7C,MAAI,kBAAyC;AAC7C,MAAI,SAAoD;AAExD,aAAW,WAAW,UAAU;AAC9B,aAAS,MAAM,QAAQ,IAAI,EAAE,SAAS,WAAW,kBAAkB,CAAC;AAIpE,QAAI,WAAW,MAAM;AACnB,wBAAkB;AAAA,IACpB;AAOA,QAAI,QAAQ,UAAU;AACpB;AAAA,IACF;AAAA,EACF;AAEA,MAAI,iBAAiB;AACnB,WAAO;AAAA,MACL,SAAS;AAAA,MACT,cAAc,QAAQ;AAAA,MACtB,UAAU,QAAQ;AAAA,IACpB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,6 +1,3 @@
1
- import {
2
- RequestHandler
3
- } from '../handlers/RequestHandler.mjs';
4
1
  const executeHandlers = async ({
5
2
  request,
6
3
  requestId,
@@ -10,9 +7,6 @@ const executeHandlers = async ({
10
7
  let matchingHandler = null;
11
8
  let result = null;
12
9
  for (const handler of handlers) {
13
- if (!(handler instanceof RequestHandler)) {
14
- continue;
15
- }
16
10
  result = await handler.run({ request, requestId, resolutionContext });
17
11
  if (result !== null) {
18
12
  matchingHandler = handler;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/utils/executeHandlers.ts"],"sourcesContent":["import {\n RequestHandler,\n type RequestHandlerExecutionResult,\n} from '../handlers/RequestHandler'\n\nexport interface HandlersExecutionResult {\n handler: RequestHandler\n parsedResult?: any\n response?: Response\n}\n\nexport interface ResponseResolutionContext {\n baseUrl?: string\n}\n\n/**\n * Executes the list of request handlers against the given request.\n * Returns the execution result object containing any matching request\n * handler and any mocked response it returned.\n */\nexport const executeHandlers = async <Handlers extends Array<unknown>>({\n request,\n requestId,\n handlers,\n resolutionContext,\n}: {\n request: Request\n requestId: string\n handlers: Handlers\n resolutionContext?: ResponseResolutionContext\n}): Promise<HandlersExecutionResult | null> => {\n let matchingHandler: RequestHandler | null = null\n let result: RequestHandlerExecutionResult<any> | null = null\n\n for (const handler of handlers) {\n if (!(handler instanceof RequestHandler)) {\n continue\n }\n\n result = await handler.run({ request, requestId, resolutionContext })\n\n // If the handler produces some result for this request,\n // it automatically becomes matching.\n if (result !== null) {\n matchingHandler = handler\n }\n\n // Stop the lookup if this handler returns a mocked response.\n // If it doesn't, it will still be considered the last matching\n // handler until any of them returns a response. This way we can\n // distinguish between fallthrough handlers without responses\n // and the lack of a matching handler.\n if (result?.response) {\n break\n }\n }\n\n if (matchingHandler) {\n return {\n handler: matchingHandler,\n parsedResult: result?.parsedResult,\n response: result?.response,\n }\n }\n\n return null\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,OAEK;AAiBA,MAAM,kBAAkB,OAAwC;AAAA,EACrE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAK+C;AAC7C,MAAI,kBAAyC;AAC7C,MAAI,SAAoD;AAExD,aAAW,WAAW,UAAU;AAC9B,QAAI,EAAE,mBAAmB,iBAAiB;AACxC;AAAA,IACF;AAEA,aAAS,MAAM,QAAQ,IAAI,EAAE,SAAS,WAAW,kBAAkB,CAAC;AAIpE,QAAI,WAAW,MAAM;AACnB,wBAAkB;AAAA,IACpB;AAOA,QAAI,QAAQ,UAAU;AACpB;AAAA,IACF;AAAA,EACF;AAEA,MAAI,iBAAiB;AACnB,WAAO;AAAA,MACL,SAAS;AAAA,MACT,cAAc,QAAQ;AAAA,MACtB,UAAU,QAAQ;AAAA,IACpB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/utils/executeHandlers.ts"],"sourcesContent":["import {\n RequestHandler,\n type RequestHandlerExecutionResult,\n} from '../handlers/RequestHandler'\n\nexport interface HandlersExecutionResult {\n handler: RequestHandler\n parsedResult?: any\n response?: Response\n}\n\nexport interface ResponseResolutionContext {\n baseUrl?: string\n}\n\n/**\n * Executes the list of request handlers against the given request.\n * Returns the execution result object containing any matching request\n * handler and any mocked response it returned.\n */\nexport const executeHandlers = async <Handlers extends Array<RequestHandler>>({\n request,\n requestId,\n handlers,\n resolutionContext,\n}: {\n request: Request\n requestId: string\n handlers: Handlers\n resolutionContext?: ResponseResolutionContext\n}): Promise<HandlersExecutionResult | null> => {\n let matchingHandler: RequestHandler | null = null\n let result: RequestHandlerExecutionResult<any> | null = null\n\n for (const handler of handlers) {\n result = await handler.run({ request, requestId, resolutionContext })\n\n // If the handler produces some result for this request,\n // it automatically becomes matching.\n if (result !== null) {\n matchingHandler = handler\n }\n\n // Stop the lookup if this handler returns a mocked response.\n // If it doesn't, it will still be considered the last matching\n // handler until any of them returns a response. This way we can\n // distinguish between fallthrough handlers without responses\n // and the lack of a matching handler.\n if (result?.response) {\n break\n }\n }\n\n if (matchingHandler) {\n return {\n handler: matchingHandler,\n parsedResult: result?.parsedResult,\n response: result?.response,\n }\n }\n\n return null\n}\n"],"mappings":"AAoBO,MAAM,kBAAkB,OAA+C;AAAA,EAC5E;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAK+C;AAC7C,MAAI,kBAAyC;AAC7C,MAAI,SAAoD;AAExD,aAAW,WAAW,UAAU;AAC9B,aAAS,MAAM,QAAQ,IAAI,EAAE,SAAS,WAAW,kBAAkB,CAAC;AAIpE,QAAI,WAAW,MAAM;AACnB,wBAAkB;AAAA,IACpB;AAOA,QAAI,QAAQ,UAAU;AACpB;AAAA,IACF;AAAA,EACF;AAEA,MAAI,iBAAiB;AACnB,WAAO;AAAA,MACL,SAAS;AAAA,MACT,cAAc,QAAQ;AAAA,MACtB,UAAU,QAAQ;AAAA,IACpB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,7 +1,7 @@
1
1
  import { Emitter } from 'strict-event-emitter';
2
2
  import { SharedOptions, LifeCycleEventsMap } from '../sharedOptions.mjs';
3
3
  import { RequiredDeep } from '../typeUtils.mjs';
4
- import { i as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-BLGmJolh.mjs';
4
+ import { i as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-63H9vVoL.mjs';
5
5
  import './request/onUnhandledRequest.mjs';
6
6
  import './internal/isIterable.mjs';
7
7
 
@@ -1,7 +1,7 @@
1
1
  import { Emitter } from 'strict-event-emitter';
2
2
  import { SharedOptions, LifeCycleEventsMap } from '../sharedOptions.js';
3
3
  import { RequiredDeep } from '../typeUtils.js';
4
- import { i as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-Cgbkdkje.js';
4
+ import { i as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-DzhqZzTK.js';
5
5
  import './request/onUnhandledRequest.js';
6
6
  import './internal/isIterable.js';
7
7
 
@@ -0,0 +1,17 @@
1
+ import { HandlerKind } from '../../handlers/common.mjs';
2
+ import { R as RequestHandler } from '../../HttpResponse-63H9vVoL.mjs';
3
+ import { WebSocketHandler } from '../../handlers/WebSocketHandler.mjs';
4
+ import './isIterable.mjs';
5
+ import '../../typeUtils.mjs';
6
+ import 'strict-event-emitter';
7
+ import '@mswjs/interceptors/WebSocket';
8
+ import '../matching/matchRequestUrl.mjs';
9
+
10
+ /**
11
+ * A filter function that ensures that the provided argument
12
+ * is a handler of the given kind. This helps differentiate
13
+ * between different kinds of handlers, e.g. request and event handlers.
14
+ */
15
+ declare function isHandlerKind<K extends HandlerKind>(kind: K): (input: unknown) => input is K extends "EventHandler" ? WebSocketHandler : RequestHandler;
16
+
17
+ export { isHandlerKind };
@@ -0,0 +1,17 @@
1
+ import { HandlerKind } from '../../handlers/common.js';
2
+ import { R as RequestHandler } from '../../HttpResponse-DzhqZzTK.js';
3
+ import { WebSocketHandler } from '../../handlers/WebSocketHandler.js';
4
+ import './isIterable.js';
5
+ import '../../typeUtils.js';
6
+ import 'strict-event-emitter';
7
+ import '@mswjs/interceptors/WebSocket';
8
+ import '../matching/matchRequestUrl.js';
9
+
10
+ /**
11
+ * A filter function that ensures that the provided argument
12
+ * is a handler of the given kind. This helps differentiate
13
+ * between different kinds of handlers, e.g. request and event handlers.
14
+ */
15
+ declare function isHandlerKind<K extends HandlerKind>(kind: K): (input: unknown) => input is K extends "EventHandler" ? WebSocketHandler : RequestHandler;
16
+
17
+ export { isHandlerKind };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var isHandlerKind_exports = {};
20
+ __export(isHandlerKind_exports, {
21
+ isHandlerKind: () => isHandlerKind
22
+ });
23
+ module.exports = __toCommonJS(isHandlerKind_exports);
24
+ function isHandlerKind(kind) {
25
+ return (input) => {
26
+ return input != null && typeof input === "object" && "__kind" in input && input.__kind === kind;
27
+ };
28
+ }
29
+ //# sourceMappingURL=isHandlerKind.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/core/utils/internal/isHandlerKind.ts"],"sourcesContent":["import type { HandlerKind } from '../../handlers/common'\nimport type { RequestHandler } from '../../handlers/RequestHandler'\nimport type { WebSocketHandler } from '../../handlers/WebSocketHandler'\n\n/**\n * A filter function that ensures that the provided argument\n * is a handler of the given kind. This helps differentiate\n * between different kinds of handlers, e.g. request and event handlers.\n */\nexport function isHandlerKind<K extends HandlerKind>(kind: K) {\n return (\n input: unknown,\n ): input is K extends 'EventHandler' ? WebSocketHandler : RequestHandler => {\n return (\n input != null &&\n typeof input === 'object' &&\n '__kind' in input &&\n input.__kind === kind\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASO,SAAS,cAAqC,MAAS;AAC5D,SAAO,CACL,UAC0E;AAC1E,WACE,SAAS,QACT,OAAO,UAAU,YACjB,YAAY,SACZ,MAAM,WAAW;AAAA,EAErB;AACF;","names":[]}
@@ -0,0 +1,9 @@
1
+ function isHandlerKind(kind) {
2
+ return (input) => {
3
+ return input != null && typeof input === "object" && "__kind" in input && input.__kind === kind;
4
+ };
5
+ }
6
+ export {
7
+ isHandlerKind
8
+ };
9
+ //# sourceMappingURL=isHandlerKind.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/core/utils/internal/isHandlerKind.ts"],"sourcesContent":["import type { HandlerKind } from '../../handlers/common'\nimport type { RequestHandler } from '../../handlers/RequestHandler'\nimport type { WebSocketHandler } from '../../handlers/WebSocketHandler'\n\n/**\n * A filter function that ensures that the provided argument\n * is a handler of the given kind. This helps differentiate\n * between different kinds of handlers, e.g. request and event handlers.\n */\nexport function isHandlerKind<K extends HandlerKind>(kind: K) {\n return (\n input: unknown,\n ): input is K extends 'EventHandler' ? WebSocketHandler : RequestHandler => {\n return (\n input != null &&\n typeof input === 'object' &&\n '__kind' in input &&\n input.__kind === kind\n )\n }\n}\n"],"mappings":"AASO,SAAS,cAAqC,MAAS;AAC5D,SAAO,CACL,UAC0E;AAC1E,WACE,SAAS,QACT,OAAO,UAAU,YACjB,YAAY,SACZ,MAAM,WAAW;AAAA,EAErB;AACF;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import 'graphql';
2
- export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-Doool6Q_.mjs';
3
- import '../../HttpResponse-BLGmJolh.mjs';
2
+ export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-B6uni-E_.mjs';
3
+ import '../../HttpResponse-63H9vVoL.mjs';
4
4
  import './isIterable.mjs';
5
5
  import '../../typeUtils.mjs';
6
6
  import '../matching/matchRequestUrl.mjs';
@@ -1,6 +1,6 @@
1
1
  import 'graphql';
2
- export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-udzgBRPf.js';
3
- import '../../HttpResponse-Cgbkdkje.js';
2
+ export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-Cjm7JNGi.js';
3
+ import '../../HttpResponse-DzhqZzTK.js';
4
4
  import './isIterable.js';
5
5
  import '../../typeUtils.js';
6
6
  import '../matching/matchRequestUrl.js';
@@ -1,4 +1,4 @@
1
- import { d as DefaultRequestMultipartBody } from '../../HttpResponse-BLGmJolh.mjs';
1
+ import { d as DefaultRequestMultipartBody } from '../../HttpResponse-63H9vVoL.mjs';
2
2
  import './isIterable.mjs';
3
3
  import '../../typeUtils.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { d as DefaultRequestMultipartBody } from '../../HttpResponse-Cgbkdkje.js';
1
+ import { d as DefaultRequestMultipartBody } from '../../HttpResponse-DzhqZzTK.js';
2
2
  import './isIterable.js';
3
3
  import '../../typeUtils.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-BLGmJolh.mjs';
1
+ import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-63H9vVoL.mjs';
2
2
  import './isIterable.mjs';
3
3
  import '../../typeUtils.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-Cgbkdkje.js';
1
+ import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-DzhqZzTK.js';
2
2
  import './isIterable.js';
3
3
  import '../../typeUtils.js';
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket';
2
- import { R as RequestHandler } from '../HttpResponse-BLGmJolh.mjs';
2
+ import { R as RequestHandler } from '../HttpResponse-63H9vVoL.mjs';
3
3
  import { WebSocketHandler } from '../handlers/WebSocketHandler.mjs';
4
4
  import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.mjs';
5
5
  import '../utils/internal/isIterable.mjs';
@@ -1,5 +1,5 @@
1
1
  import { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket';
2
- import { R as RequestHandler } from '../HttpResponse-Cgbkdkje.js';
2
+ import { R as RequestHandler } from '../HttpResponse-DzhqZzTK.js';
3
3
  import { WebSocketHandler } from '../handlers/WebSocketHandler.js';
4
4
  import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.js';
5
5
  import '../utils/internal/isIterable.js';
@@ -24,6 +24,7 @@ module.exports = __toCommonJS(handleWebSocketEvent_exports);
24
24
  var import_WebSocketHandler = require("../handlers/WebSocketHandler.js");
25
25
  var import_webSocketInterceptor = require("./webSocketInterceptor.js");
26
26
  var import_onUnhandledRequest = require("../utils/request/onUnhandledRequest.js");
27
+ var import_isHandlerKind = require("../utils/internal/isHandlerKind.js");
27
28
  function handleWebSocketEvent(options) {
28
29
  import_webSocketInterceptor.webSocketInterceptor.on("connection", async (connection) => {
29
30
  const handlers = options.getHandlers();
@@ -32,7 +33,7 @@ function handleWebSocketEvent(options) {
32
33
  });
33
34
  const matchingHandlers = [];
34
35
  for (const handler of handlers) {
35
- if (handler instanceof import_WebSocketHandler.WebSocketHandler && handler.predicate({
36
+ if ((0, import_isHandlerKind.isHandlerKind)("EventHandler")(handler) && handler.predicate({
36
37
  event: connectionEvent,
37
38
  parsedResult: handler.parse({
38
39
  event: connectionEvent
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/ws/handleWebSocketEvent.ts"],"sourcesContent":["import type { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport { RequestHandler } from '../handlers/RequestHandler'\nimport { WebSocketHandler, kDispatchEvent } from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from './webSocketInterceptor'\nimport {\n onUnhandledRequest,\n UnhandledRequestStrategy,\n} from '../utils/request/onUnhandledRequest'\n\ninterface HandleWebSocketEventOptions {\n getUnhandledRequestStrategy: () => UnhandledRequestStrategy\n getHandlers: () => Array<RequestHandler | WebSocketHandler>\n onMockedConnection: (connection: WebSocketConnectionData) => void\n onPassthroughConnection: (onnection: WebSocketConnectionData) => void\n}\n\nexport function handleWebSocketEvent(options: HandleWebSocketEventOptions) {\n webSocketInterceptor.on('connection', async (connection) => {\n const handlers = options.getHandlers()\n\n const connectionEvent = new MessageEvent('connection', {\n data: connection,\n })\n\n // First, filter only those WebSocket handlers that\n // match the \"ws.link()\" endpoint predicate. Don't dispatch\n // anything yet so the logger can be attached to the connection\n // before it potentially sends events.\n const matchingHandlers: Array<WebSocketHandler> = []\n\n for (const handler of handlers) {\n if (\n handler instanceof WebSocketHandler &&\n handler.predicate({\n event: connectionEvent,\n parsedResult: handler.parse({\n event: connectionEvent,\n }),\n })\n ) {\n matchingHandlers.push(handler)\n }\n }\n\n if (matchingHandlers.length > 0) {\n options?.onMockedConnection(connection)\n\n // Iterate over the handlers and forward the connection\n // event to WebSocket event handlers. This is equivalent\n // to dispatching that event onto multiple listeners.\n for (const handler of matchingHandlers) {\n handler[kDispatchEvent](connectionEvent)\n }\n } else {\n // Construct a request representing this WebSocket connection.\n const request = new Request(connection.client.url, {\n headers: {\n upgrade: 'websocket',\n connection: 'upgrade',\n },\n })\n await onUnhandledRequest(\n request,\n options.getUnhandledRequestStrategy(),\n ).catch((error) => {\n const errorEvent = new Event('error')\n Object.defineProperty(errorEvent, 'cause', {\n enumerable: true,\n configurable: false,\n value: error,\n })\n connection.client.socket.dispatchEvent(errorEvent)\n })\n\n options?.onPassthroughConnection(connection)\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n connection.server.connect()\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,8BAAiD;AACjD,kCAAqC;AACrC,gCAGO;AASA,SAAS,qBAAqB,SAAsC;AACzE,mDAAqB,GAAG,cAAc,OAAO,eAAe;AAC1D,UAAM,WAAW,QAAQ,YAAY;AAErC,UAAM,kBAAkB,IAAI,aAAa,cAAc;AAAA,MACrD,MAAM;AAAA,IACR,CAAC;AAMD,UAAM,mBAA4C,CAAC;AAEnD,eAAW,WAAW,UAAU;AAC9B,UACE,mBAAmB,4CACnB,QAAQ,UAAU;AAAA,QAChB,OAAO;AAAA,QACP,cAAc,QAAQ,MAAM;AAAA,UAC1B,OAAO;AAAA,QACT,CAAC;AAAA,MACH,CAAC,GACD;AACA,yBAAiB,KAAK,OAAO;AAAA,MAC/B;AAAA,IACF;AAEA,QAAI,iBAAiB,SAAS,GAAG;AAC/B,eAAS,mBAAmB,UAAU;AAKtC,iBAAW,WAAW,kBAAkB;AACtC,gBAAQ,sCAAc,EAAE,eAAe;AAAA,MACzC;AAAA,IACF,OAAO;AAEL,YAAM,UAAU,IAAI,QAAQ,WAAW,OAAO,KAAK;AAAA,QACjD,SAAS;AAAA,UACP,SAAS;AAAA,UACT,YAAY;AAAA,QACd;AAAA,MACF,CAAC;AACD,gBAAM;AAAA,QACJ;AAAA,QACA,QAAQ,4BAA4B;AAAA,MACtC,EAAE,MAAM,CAAC,UAAU;AACjB,cAAM,aAAa,IAAI,MAAM,OAAO;AACpC,eAAO,eAAe,YAAY,SAAS;AAAA,UACzC,YAAY;AAAA,UACZ,cAAc;AAAA,UACd,OAAO;AAAA,QACT,CAAC;AACD,mBAAW,OAAO,OAAO,cAAc,UAAU;AAAA,MACnD,CAAC;AAED,eAAS,wBAAwB,UAAU;AAI3C,iBAAW,OAAO,QAAQ;AAAA,IAC5B;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/ws/handleWebSocketEvent.ts"],"sourcesContent":["import type { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport { RequestHandler } from '../handlers/RequestHandler'\nimport { WebSocketHandler, kDispatchEvent } from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from './webSocketInterceptor'\nimport {\n onUnhandledRequest,\n UnhandledRequestStrategy,\n} from '../utils/request/onUnhandledRequest'\nimport { isHandlerKind } from '../utils/internal/isHandlerKind'\n\ninterface HandleWebSocketEventOptions {\n getUnhandledRequestStrategy: () => UnhandledRequestStrategy\n getHandlers: () => Array<RequestHandler | WebSocketHandler>\n onMockedConnection: (connection: WebSocketConnectionData) => void\n onPassthroughConnection: (onnection: WebSocketConnectionData) => void\n}\n\nexport function handleWebSocketEvent(options: HandleWebSocketEventOptions) {\n webSocketInterceptor.on('connection', async (connection) => {\n const handlers = options.getHandlers()\n\n const connectionEvent = new MessageEvent('connection', {\n data: connection,\n })\n\n // First, filter only those WebSocket handlers that\n // match the \"ws.link()\" endpoint predicate. Don't dispatch\n // anything yet so the logger can be attached to the connection\n // before it potentially sends events.\n const matchingHandlers: Array<WebSocketHandler> = []\n\n for (const handler of handlers) {\n if (\n isHandlerKind('EventHandler')(handler) &&\n handler.predicate({\n event: connectionEvent,\n parsedResult: handler.parse({\n event: connectionEvent,\n }),\n })\n ) {\n matchingHandlers.push(handler)\n }\n }\n\n if (matchingHandlers.length > 0) {\n options?.onMockedConnection(connection)\n\n // Iterate over the handlers and forward the connection\n // event to WebSocket event handlers. This is equivalent\n // to dispatching that event onto multiple listeners.\n for (const handler of matchingHandlers) {\n handler[kDispatchEvent](connectionEvent)\n }\n } else {\n // Construct a request representing this WebSocket connection.\n const request = new Request(connection.client.url, {\n headers: {\n upgrade: 'websocket',\n connection: 'upgrade',\n },\n })\n await onUnhandledRequest(\n request,\n options.getUnhandledRequestStrategy(),\n ).catch((error) => {\n const errorEvent = new Event('error')\n Object.defineProperty(errorEvent, 'cause', {\n enumerable: true,\n configurable: false,\n value: error,\n })\n connection.client.socket.dispatchEvent(errorEvent)\n })\n\n options?.onPassthroughConnection(connection)\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n connection.server.connect()\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,8BAAiD;AACjD,kCAAqC;AACrC,gCAGO;AACP,2BAA8B;AASvB,SAAS,qBAAqB,SAAsC;AACzE,mDAAqB,GAAG,cAAc,OAAO,eAAe;AAC1D,UAAM,WAAW,QAAQ,YAAY;AAErC,UAAM,kBAAkB,IAAI,aAAa,cAAc;AAAA,MACrD,MAAM;AAAA,IACR,CAAC;AAMD,UAAM,mBAA4C,CAAC;AAEnD,eAAW,WAAW,UAAU;AAC9B,cACE,oCAAc,cAAc,EAAE,OAAO,KACrC,QAAQ,UAAU;AAAA,QAChB,OAAO;AAAA,QACP,cAAc,QAAQ,MAAM;AAAA,UAC1B,OAAO;AAAA,QACT,CAAC;AAAA,MACH,CAAC,GACD;AACA,yBAAiB,KAAK,OAAO;AAAA,MAC/B;AAAA,IACF;AAEA,QAAI,iBAAiB,SAAS,GAAG;AAC/B,eAAS,mBAAmB,UAAU;AAKtC,iBAAW,WAAW,kBAAkB;AACtC,gBAAQ,sCAAc,EAAE,eAAe;AAAA,MACzC;AAAA,IACF,OAAO;AAEL,YAAM,UAAU,IAAI,QAAQ,WAAW,OAAO,KAAK;AAAA,QACjD,SAAS;AAAA,UACP,SAAS;AAAA,UACT,YAAY;AAAA,QACd;AAAA,MACF,CAAC;AACD,gBAAM;AAAA,QACJ;AAAA,QACA,QAAQ,4BAA4B;AAAA,MACtC,EAAE,MAAM,CAAC,UAAU;AACjB,cAAM,aAAa,IAAI,MAAM,OAAO;AACpC,eAAO,eAAe,YAAY,SAAS;AAAA,UACzC,YAAY;AAAA,UACZ,cAAc;AAAA,UACd,OAAO;AAAA,QACT,CAAC;AACD,mBAAW,OAAO,OAAO,cAAc,UAAU;AAAA,MACnD,CAAC;AAED,eAAS,wBAAwB,UAAU;AAI3C,iBAAW,OAAO,QAAQ;AAAA,IAC5B;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,8 +1,9 @@
1
- import { WebSocketHandler, kDispatchEvent } from '../handlers/WebSocketHandler.mjs';
1
+ import { kDispatchEvent } from '../handlers/WebSocketHandler.mjs';
2
2
  import { webSocketInterceptor } from './webSocketInterceptor.mjs';
3
3
  import {
4
4
  onUnhandledRequest
5
5
  } from '../utils/request/onUnhandledRequest.mjs';
6
+ import { isHandlerKind } from '../utils/internal/isHandlerKind.mjs';
6
7
  function handleWebSocketEvent(options) {
7
8
  webSocketInterceptor.on("connection", async (connection) => {
8
9
  const handlers = options.getHandlers();
@@ -11,7 +12,7 @@ function handleWebSocketEvent(options) {
11
12
  });
12
13
  const matchingHandlers = [];
13
14
  for (const handler of handlers) {
14
- if (handler instanceof WebSocketHandler && handler.predicate({
15
+ if (isHandlerKind("EventHandler")(handler) && handler.predicate({
15
16
  event: connectionEvent,
16
17
  parsedResult: handler.parse({
17
18
  event: connectionEvent
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/ws/handleWebSocketEvent.ts"],"sourcesContent":["import type { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport { RequestHandler } from '../handlers/RequestHandler'\nimport { WebSocketHandler, kDispatchEvent } from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from './webSocketInterceptor'\nimport {\n onUnhandledRequest,\n UnhandledRequestStrategy,\n} from '../utils/request/onUnhandledRequest'\n\ninterface HandleWebSocketEventOptions {\n getUnhandledRequestStrategy: () => UnhandledRequestStrategy\n getHandlers: () => Array<RequestHandler | WebSocketHandler>\n onMockedConnection: (connection: WebSocketConnectionData) => void\n onPassthroughConnection: (onnection: WebSocketConnectionData) => void\n}\n\nexport function handleWebSocketEvent(options: HandleWebSocketEventOptions) {\n webSocketInterceptor.on('connection', async (connection) => {\n const handlers = options.getHandlers()\n\n const connectionEvent = new MessageEvent('connection', {\n data: connection,\n })\n\n // First, filter only those WebSocket handlers that\n // match the \"ws.link()\" endpoint predicate. Don't dispatch\n // anything yet so the logger can be attached to the connection\n // before it potentially sends events.\n const matchingHandlers: Array<WebSocketHandler> = []\n\n for (const handler of handlers) {\n if (\n handler instanceof WebSocketHandler &&\n handler.predicate({\n event: connectionEvent,\n parsedResult: handler.parse({\n event: connectionEvent,\n }),\n })\n ) {\n matchingHandlers.push(handler)\n }\n }\n\n if (matchingHandlers.length > 0) {\n options?.onMockedConnection(connection)\n\n // Iterate over the handlers and forward the connection\n // event to WebSocket event handlers. This is equivalent\n // to dispatching that event onto multiple listeners.\n for (const handler of matchingHandlers) {\n handler[kDispatchEvent](connectionEvent)\n }\n } else {\n // Construct a request representing this WebSocket connection.\n const request = new Request(connection.client.url, {\n headers: {\n upgrade: 'websocket',\n connection: 'upgrade',\n },\n })\n await onUnhandledRequest(\n request,\n options.getUnhandledRequestStrategy(),\n ).catch((error) => {\n const errorEvent = new Event('error')\n Object.defineProperty(errorEvent, 'cause', {\n enumerable: true,\n configurable: false,\n value: error,\n })\n connection.client.socket.dispatchEvent(errorEvent)\n })\n\n options?.onPassthroughConnection(connection)\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n connection.server.connect()\n }\n })\n}\n"],"mappings":"AAEA,SAAS,kBAAkB,sBAAsB;AACjD,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,OAEK;AASA,SAAS,qBAAqB,SAAsC;AACzE,uBAAqB,GAAG,cAAc,OAAO,eAAe;AAC1D,UAAM,WAAW,QAAQ,YAAY;AAErC,UAAM,kBAAkB,IAAI,aAAa,cAAc;AAAA,MACrD,MAAM;AAAA,IACR,CAAC;AAMD,UAAM,mBAA4C,CAAC;AAEnD,eAAW,WAAW,UAAU;AAC9B,UACE,mBAAmB,oBACnB,QAAQ,UAAU;AAAA,QAChB,OAAO;AAAA,QACP,cAAc,QAAQ,MAAM;AAAA,UAC1B,OAAO;AAAA,QACT,CAAC;AAAA,MACH,CAAC,GACD;AACA,yBAAiB,KAAK,OAAO;AAAA,MAC/B;AAAA,IACF;AAEA,QAAI,iBAAiB,SAAS,GAAG;AAC/B,eAAS,mBAAmB,UAAU;AAKtC,iBAAW,WAAW,kBAAkB;AACtC,gBAAQ,cAAc,EAAE,eAAe;AAAA,MACzC;AAAA,IACF,OAAO;AAEL,YAAM,UAAU,IAAI,QAAQ,WAAW,OAAO,KAAK;AAAA,QACjD,SAAS;AAAA,UACP,SAAS;AAAA,UACT,YAAY;AAAA,QACd;AAAA,MACF,CAAC;AACD,YAAM;AAAA,QACJ;AAAA,QACA,QAAQ,4BAA4B;AAAA,MACtC,EAAE,MAAM,CAAC,UAAU;AACjB,cAAM,aAAa,IAAI,MAAM,OAAO;AACpC,eAAO,eAAe,YAAY,SAAS;AAAA,UACzC,YAAY;AAAA,UACZ,cAAc;AAAA,UACd,OAAO;AAAA,QACT,CAAC;AACD,mBAAW,OAAO,OAAO,cAAc,UAAU;AAAA,MACnD,CAAC;AAED,eAAS,wBAAwB,UAAU;AAI3C,iBAAW,OAAO,QAAQ;AAAA,IAC5B;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/ws/handleWebSocketEvent.ts"],"sourcesContent":["import type { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport { RequestHandler } from '../handlers/RequestHandler'\nimport { WebSocketHandler, kDispatchEvent } from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from './webSocketInterceptor'\nimport {\n onUnhandledRequest,\n UnhandledRequestStrategy,\n} from '../utils/request/onUnhandledRequest'\nimport { isHandlerKind } from '../utils/internal/isHandlerKind'\n\ninterface HandleWebSocketEventOptions {\n getUnhandledRequestStrategy: () => UnhandledRequestStrategy\n getHandlers: () => Array<RequestHandler | WebSocketHandler>\n onMockedConnection: (connection: WebSocketConnectionData) => void\n onPassthroughConnection: (onnection: WebSocketConnectionData) => void\n}\n\nexport function handleWebSocketEvent(options: HandleWebSocketEventOptions) {\n webSocketInterceptor.on('connection', async (connection) => {\n const handlers = options.getHandlers()\n\n const connectionEvent = new MessageEvent('connection', {\n data: connection,\n })\n\n // First, filter only those WebSocket handlers that\n // match the \"ws.link()\" endpoint predicate. Don't dispatch\n // anything yet so the logger can be attached to the connection\n // before it potentially sends events.\n const matchingHandlers: Array<WebSocketHandler> = []\n\n for (const handler of handlers) {\n if (\n isHandlerKind('EventHandler')(handler) &&\n handler.predicate({\n event: connectionEvent,\n parsedResult: handler.parse({\n event: connectionEvent,\n }),\n })\n ) {\n matchingHandlers.push(handler)\n }\n }\n\n if (matchingHandlers.length > 0) {\n options?.onMockedConnection(connection)\n\n // Iterate over the handlers and forward the connection\n // event to WebSocket event handlers. This is equivalent\n // to dispatching that event onto multiple listeners.\n for (const handler of matchingHandlers) {\n handler[kDispatchEvent](connectionEvent)\n }\n } else {\n // Construct a request representing this WebSocket connection.\n const request = new Request(connection.client.url, {\n headers: {\n upgrade: 'websocket',\n connection: 'upgrade',\n },\n })\n await onUnhandledRequest(\n request,\n options.getUnhandledRequestStrategy(),\n ).catch((error) => {\n const errorEvent = new Event('error')\n Object.defineProperty(errorEvent, 'cause', {\n enumerable: true,\n configurable: false,\n value: error,\n })\n connection.client.socket.dispatchEvent(errorEvent)\n })\n\n options?.onPassthroughConnection(connection)\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n connection.server.connect()\n }\n })\n}\n"],"mappings":"AAEA,SAA2B,sBAAsB;AACjD,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,OAEK;AACP,SAAS,qBAAqB;AASvB,SAAS,qBAAqB,SAAsC;AACzE,uBAAqB,GAAG,cAAc,OAAO,eAAe;AAC1D,UAAM,WAAW,QAAQ,YAAY;AAErC,UAAM,kBAAkB,IAAI,aAAa,cAAc;AAAA,MACrD,MAAM;AAAA,IACR,CAAC;AAMD,UAAM,mBAA4C,CAAC;AAEnD,eAAW,WAAW,UAAU;AAC9B,UACE,cAAc,cAAc,EAAE,OAAO,KACrC,QAAQ,UAAU;AAAA,QAChB,OAAO;AAAA,QACP,cAAc,QAAQ,MAAM;AAAA,UAC1B,OAAO;AAAA,QACT,CAAC;AAAA,MACH,CAAC,GACD;AACA,yBAAiB,KAAK,OAAO;AAAA,MAC/B;AAAA,IACF;AAEA,QAAI,iBAAiB,SAAS,GAAG;AAC/B,eAAS,mBAAmB,UAAU;AAKtC,iBAAW,WAAW,kBAAkB;AACtC,gBAAQ,cAAc,EAAE,eAAe;AAAA,MACzC;AAAA,IACF,OAAO;AAEL,YAAM,UAAU,IAAI,QAAQ,WAAW,OAAO,KAAK;AAAA,QACjD,SAAS;AAAA,UACP,SAAS;AAAA,UACT,YAAY;AAAA,QACd;AAAA,MACF,CAAC;AACD,YAAM;AAAA,QACJ;AAAA,QACA,QAAQ,4BAA4B;AAAA,MACtC,EAAE,MAAM,CAAC,UAAU;AACjB,cAAM,aAAa,IAAI,MAAM,OAAO;AACpC,eAAO,eAAe,YAAY,SAAS;AAAA,UACzC,YAAY;AAAA,UACZ,cAAc;AAAA,UACd,OAAO;AAAA,QACT,CAAC;AACD,mBAAW,OAAO,OAAO,cAAc,UAAU;AAAA,MACnD,CAAC;AAED,eAAS,wBAAwB,UAAU;AAI3C,iBAAW,OAAO,QAAQ;AAAA,IAC5B;AAAA,EACF,CAAC;AACH;","names":[]}
package/lib/iife/index.js CHANGED
@@ -13775,6 +13775,7 @@ ${operationTypes.join("\n")}
13775
13775
  // src/core/handlers/RequestHandler.ts
13776
13776
  var RequestHandler = class _RequestHandler {
13777
13777
  static cache = /* @__PURE__ */ new WeakMap();
13778
+ __kind;
13778
13779
  info;
13779
13780
  /**
13780
13781
  * Indicates whether this request handler has been used
@@ -13794,6 +13795,7 @@ ${operationTypes.join("\n")}
13794
13795
  callFrame
13795
13796
  };
13796
13797
  this.isUsed = false;
13798
+ this.__kind = "RequestHandler";
13797
13799
  }
13798
13800
  /**
13799
13801
  * Parse the intercepted request to extract additional information from it.
@@ -28177,7 +28179,9 @@ Consider naming this operation or using "graphql.operation()" request handler to
28177
28179
  this.id = createRequestId();
28178
28180
  this[kEmitter] = new Emitter();
28179
28181
  this.callFrame = getCallFrame(new Error());
28182
+ this.__kind = "EventHandler";
28180
28183
  }
28184
+ __kind;
28181
28185
  id;
28182
28186
  callFrame;
28183
28187
  [kEmitter];
@@ -28639,9 +28643,6 @@ Consider naming this operation or using "graphql.operation()" request handler to
28639
28643
  let matchingHandler = null;
28640
28644
  let result = null;
28641
28645
  for (const handler of handlers) {
28642
- if (!(handler instanceof RequestHandler)) {
28643
- continue;
28644
- }
28645
28646
  result = await handler.run({ request, requestId, resolutionContext });
28646
28647
  if (result !== null) {
28647
28648
  matchingHandler = handler;
@@ -29166,6 +29167,13 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
29166
29167
  };
29167
29168
  }
29168
29169
 
29170
+ // src/core/utils/internal/isHandlerKind.ts
29171
+ function isHandlerKind(kind) {
29172
+ return (input) => {
29173
+ return input != null && typeof input === "object" && "__kind" in input && input.__kind === kind;
29174
+ };
29175
+ }
29176
+
29169
29177
  // src/browser/setupWorker/start/createRequestListener.ts
29170
29178
  var createRequestListener = (context, options) => {
29171
29179
  return async (event, message3) => {
@@ -29180,9 +29188,7 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
29180
29188
  await handleRequest(
29181
29189
  request,
29182
29190
  requestId,
29183
- context.getRequestHandlers().filter((handler) => {
29184
- return handler instanceof HttpHandler || handler instanceof GraphQLHandler;
29185
- }),
29191
+ context.getRequestHandlers().filter(isHandlerKind("RequestHandler")),
29186
29192
  options,
29187
29193
  context.emitter,
29188
29194
  {
@@ -30625,7 +30631,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
30625
30631
  const response = await handleRequest(
30626
30632
  request,
30627
30633
  requestId,
30628
- context.getRequestHandlers(),
30634
+ context.getRequestHandlers().filter(isHandlerKind("RequestHandler")),
30629
30635
  options,
30630
30636
  context.emitter,
30631
30637
  {
@@ -31363,7 +31369,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
31363
31369
  });
31364
31370
  const matchingHandlers = [];
31365
31371
  for (const handler of handlers) {
31366
- if (handler instanceof WebSocketHandler && handler.predicate({
31372
+ if (isHandlerKind("EventHandler")(handler) && handler.predicate({
31367
31373
  event: connectionEvent,
31368
31374
  parsedResult: handler.parse({
31369
31375
  event: connectionEvent