msw 2.3.0-ws.rc-8 → 2.3.0-ws.rc-10

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 (65) hide show
  1. package/lib/browser/index.js +15 -8
  2. package/lib/browser/index.js.map +1 -1
  3. package/lib/browser/index.mjs +15 -8
  4. package/lib/browser/index.mjs.map +1 -1
  5. package/lib/core/index.d.mts +2 -2
  6. package/lib/core/index.d.ts +2 -2
  7. package/lib/core/index.js.map +1 -1
  8. package/lib/core/index.mjs.map +1 -1
  9. package/lib/core/utils/handleRequest.d.mts +2 -2
  10. package/lib/core/utils/handleRequest.d.ts +2 -2
  11. package/lib/core/utils/handleRequest.js.map +1 -1
  12. package/lib/core/utils/handleRequest.mjs.map +1 -1
  13. package/lib/core/ws/WebSocketClientManager.d.mts +1 -3
  14. package/lib/core/ws/WebSocketClientManager.d.ts +1 -3
  15. package/lib/core/ws/WebSocketClientManager.js +1 -2
  16. package/lib/core/ws/WebSocketClientManager.js.map +1 -1
  17. package/lib/core/ws/WebSocketClientManager.mjs +1 -2
  18. package/lib/core/ws/WebSocketClientManager.mjs.map +1 -1
  19. package/lib/core/ws/WebSocketClientStore.d.mts +2 -2
  20. package/lib/core/ws/WebSocketClientStore.d.ts +2 -2
  21. package/lib/core/ws/WebSocketClientStore.js.map +1 -1
  22. package/lib/core/ws/WebSocketClientStore.mjs.map +1 -1
  23. package/lib/core/ws/WebSocketIndexedDBClientStore.js +27 -6
  24. package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -1
  25. package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +27 -6
  26. package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -1
  27. package/lib/core/ws/handleWebSocketEvent.d.mts +2 -0
  28. package/lib/core/ws/handleWebSocketEvent.d.ts +2 -0
  29. package/lib/core/ws/handleWebSocketEvent.js +30 -13
  30. package/lib/core/ws/handleWebSocketEvent.js.map +1 -1
  31. package/lib/core/ws/handleWebSocketEvent.mjs +32 -13
  32. package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -1
  33. package/lib/core/ws/utils/attachWebSocketLogger.js +2 -2
  34. package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -1
  35. package/lib/core/ws/utils/attachWebSocketLogger.mjs +2 -2
  36. package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -1
  37. package/lib/core/ws.d.mts +8 -6
  38. package/lib/core/ws.d.ts +8 -6
  39. package/lib/core/ws.js +2 -2
  40. package/lib/core/ws.js.map +1 -1
  41. package/lib/core/ws.mjs +2 -2
  42. package/lib/core/ws.mjs.map +1 -1
  43. package/lib/iife/index.js +128 -58
  44. package/lib/iife/index.js.map +1 -1
  45. package/lib/mockServiceWorker.js +1 -1
  46. package/lib/native/index.js +10 -5
  47. package/lib/native/index.js.map +1 -1
  48. package/lib/native/index.mjs +10 -5
  49. package/lib/native/index.mjs.map +1 -1
  50. package/lib/node/index.js +10 -5
  51. package/lib/node/index.js.map +1 -1
  52. package/lib/node/index.mjs +10 -5
  53. package/lib/node/index.mjs.map +1 -1
  54. package/package.json +2 -2
  55. package/src/browser/setupWorker/setupWorker.ts +5 -7
  56. package/src/browser/setupWorker/start/createRequestListener.ts +7 -1
  57. package/src/core/index.ts +2 -0
  58. package/src/core/utils/handleRequest.ts +2 -1
  59. package/src/core/ws/WebSocketClientManager.ts +1 -5
  60. package/src/core/ws/WebSocketClientStore.ts +1 -1
  61. package/src/core/ws/WebSocketIndexedDBClientStore.ts +39 -6
  62. package/src/core/ws/handleWebSocketEvent.ts +40 -14
  63. package/src/core/ws/utils/attachWebSocketLogger.ts +2 -2
  64. package/src/core/ws.ts +15 -9
  65. package/src/node/SetupServerCommonApi.ts +17 -6
@@ -4,7 +4,7 @@ export { HttpRequestHandler, HttpResponseResolver, http } from './http.mjs';
4
4
  export { HttpHandler, HttpMethods, HttpRequestParsedResult, RequestQuery } from './handlers/HttpHandler.mjs';
5
5
  export { GraphQLRequestHandler, GraphQLResponseResolver, graphql } from './graphql.mjs';
6
6
  export { G as GraphQLHandler, d as GraphQLJsonRequestBody, a as GraphQLQuery, c as GraphQLRequestBody, b as GraphQLVariables, P as ParsedGraphQLRequest } from './GraphQLHandler-B7TZhhKO.mjs';
7
- export { WebSocketLink, ws } from './ws.mjs';
7
+ export { WebSocketEventListener, WebSocketLink, ws } from './ws.mjs';
8
8
  export { WebSocketHandler, WebSocketHandlerEventMap } from './handlers/WebSocketHandler.mjs';
9
9
  export { Match, Path, PathParams, matchRequestUrl } from './utils/matching/matchRequestUrl.mjs';
10
10
  export { HandleRequestOptions, handleRequest } from './utils/handleRequest.mjs';
@@ -14,10 +14,10 @@ export { LifeCycleEventsMap, SharedOptions } from './sharedOptions.mjs';
14
14
  export { DelayMode, MAX_SERVER_RESPONSE_TIME, MIN_SERVER_RESPONSE_TIME, NODE_SERVER_RESPONSE_TIME, SET_TIMEOUT_MAX_ALLOWED_INT, delay } from './delay.mjs';
15
15
  export { bypass } from './bypass.mjs';
16
16
  export { passthrough } from './passthrough.mjs';
17
+ export { WebSocketData } from '@mswjs/interceptors/WebSocket';
17
18
  import 'strict-event-emitter';
18
19
  import './utils/internal/Disposable.mjs';
19
20
  import './utils/internal/isIterable.mjs';
20
21
  import './typeUtils.mjs';
21
22
  import 'graphql';
22
- import '@mswjs/interceptors/WebSocket';
23
23
  import './utils/request/onUnhandledRequest.mjs';
@@ -4,7 +4,7 @@ export { HttpRequestHandler, HttpResponseResolver, http } from './http.js';
4
4
  export { HttpHandler, HttpMethods, HttpRequestParsedResult, RequestQuery } from './handlers/HttpHandler.js';
5
5
  export { GraphQLRequestHandler, GraphQLResponseResolver, graphql } from './graphql.js';
6
6
  export { G as GraphQLHandler, d as GraphQLJsonRequestBody, a as GraphQLQuery, c as GraphQLRequestBody, b as GraphQLVariables, P as ParsedGraphQLRequest } from './GraphQLHandler-DRmlr_7o.js';
7
- export { WebSocketLink, ws } from './ws.js';
7
+ export { WebSocketEventListener, WebSocketLink, ws } from './ws.js';
8
8
  export { WebSocketHandler, WebSocketHandlerEventMap } from './handlers/WebSocketHandler.js';
9
9
  export { Match, Path, PathParams, matchRequestUrl } from './utils/matching/matchRequestUrl.js';
10
10
  export { HandleRequestOptions, handleRequest } from './utils/handleRequest.js';
@@ -14,10 +14,10 @@ export { LifeCycleEventsMap, SharedOptions } from './sharedOptions.js';
14
14
  export { DelayMode, MAX_SERVER_RESPONSE_TIME, MIN_SERVER_RESPONSE_TIME, NODE_SERVER_RESPONSE_TIME, SET_TIMEOUT_MAX_ALLOWED_INT, delay } from './delay.js';
15
15
  export { bypass } from './bypass.js';
16
16
  export { passthrough } from './passthrough.js';
17
+ export { WebSocketData } from '@mswjs/interceptors/WebSocket';
17
18
  import 'strict-event-emitter';
18
19
  import './utils/internal/Disposable.js';
19
20
  import './utils/internal/isIterable.js';
20
21
  import './typeUtils.js';
21
22
  import 'graphql';
22
- import '@mswjs/interceptors/WebSocket';
23
23
  import './utils/request/onUnhandledRequest.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* HTTP handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* WebSocket handler */\nexport { ws, type WebSocketLink } from './ws'\nexport {\n WebSocketHandler,\n type WebSocketHandlerEventMap,\n} from './handlers/WebSocketHandler'\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLJsonRequestBody,\n} from './handlers/GraphQLHandler'\nexport type { GraphQLRequestHandler, GraphQLResponseResolver } from './graphql'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAE7B,sBAAyB;AAGzB,4BAA+B;AAC/B,kBAAqB;AACrB,yBAAyC;AACzC,qBAAwB;AACxB,4BAA+B;AAG/B,gBAAuC;AACvC,8BAGO;AAGP,6BAAgC;AAChC,yBAAc,kCApBd;AAqBA,yBAA4B;AAC5B,sBAAyB;AAmCzB,yBAAc,2BAzDd;AA0DA,yBAAc,oBA1Dd;AA2DA,oBAAuB;AACvB,yBAA4B;AAAA,IAM5B,kCAAa;","names":[]}
1
+ {"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* HTTP handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* WebSocket handler */\nexport { ws, type WebSocketLink } from './ws'\nexport {\n WebSocketHandler,\n type WebSocketHandlerEventMap,\n} from './handlers/WebSocketHandler'\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLJsonRequestBody,\n} from './handlers/GraphQLHandler'\nexport type { GraphQLRequestHandler, GraphQLResponseResolver } from './graphql'\n\nexport type { WebSocketData, WebSocketEventListener } from './ws'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAE7B,sBAAyB;AAGzB,4BAA+B;AAC/B,kBAAqB;AACrB,yBAAyC;AACzC,qBAAwB;AACxB,4BAA+B;AAG/B,gBAAuC;AACvC,8BAGO;AAGP,6BAAgC;AAChC,yBAAc,kCApBd;AAqBA,yBAA4B;AAC5B,sBAAyB;AAqCzB,yBAAc,2BA3Dd;AA4DA,yBAAc,oBA5Dd;AA6DA,oBAAuB;AACvB,yBAA4B;AAAA,IAM5B,kCAAa;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* HTTP handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* WebSocket handler */\nexport { ws, type WebSocketLink } from './ws'\nexport {\n WebSocketHandler,\n type WebSocketHandlerEventMap,\n} from './handlers/WebSocketHandler'\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLJsonRequestBody,\n} from './handlers/GraphQLHandler'\nexport type { GraphQLRequestHandler, GraphQLResponseResolver } from './graphql'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":"AAAA,SAAS,oBAAoB;AAE7B,SAAS,gBAAgB;AAGzB,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AACrB,SAAS,aAAa,mBAAmB;AACzC,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAG/B,SAAS,UAA8B;AACvC;AAAA,EACE;AAAA,OAEK;AAGP,SAAS,uBAAuB;AAChC,cAAc;AACd,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAmCzB,cAAc;AACd,cAAc;AACd,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAM5B,aAAa;","names":[]}
1
+ {"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* HTTP handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* WebSocket handler */\nexport { ws, type WebSocketLink } from './ws'\nexport {\n WebSocketHandler,\n type WebSocketHandlerEventMap,\n} from './handlers/WebSocketHandler'\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLJsonRequestBody,\n} from './handlers/GraphQLHandler'\nexport type { GraphQLRequestHandler, GraphQLResponseResolver } from './graphql'\n\nexport type { WebSocketData, WebSocketEventListener } from './ws'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":"AAAA,SAAS,oBAAoB;AAE7B,SAAS,gBAAgB;AAGzB,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AACrB,SAAS,aAAa,mBAAmB;AACzC,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAG/B,SAAS,UAA8B;AACvC;AAAA,EACE;AAAA,OAEK;AAGP,SAAS,uBAAuB;AAChC,cAAc;AACd,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAqCzB,cAAc;AACd,cAAc;AACd,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAM5B,aAAa;","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 { g as HandlersExecutionResult } from '../HttpResponse-DYXrZpqR.mjs';
4
+ import { g as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-DYXrZpqR.mjs';
5
5
  import './request/onUnhandledRequest.mjs';
6
6
  import './internal/isIterable.mjs';
7
7
 
@@ -33,6 +33,6 @@ interface HandleRequestOptions {
33
33
  */
34
34
  onMockedResponse?(response: Response, handler: RequiredDeep<HandlersExecutionResult>): void;
35
35
  }
36
- declare function handleRequest(request: Request, requestId: string, handlers: Array<unknown>, options: RequiredDeep<SharedOptions>, emitter: Emitter<LifeCycleEventsMap>, handleRequestOptions?: HandleRequestOptions): Promise<Response | undefined>;
36
+ declare function handleRequest(request: Request, requestId: string, handlers: Array<RequestHandler>, options: RequiredDeep<SharedOptions>, emitter: Emitter<LifeCycleEventsMap>, handleRequestOptions?: HandleRequestOptions): Promise<Response | undefined>;
37
37
 
38
38
  export { type HandleRequestOptions, handleRequest };
@@ -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 { g as HandlersExecutionResult } from '../HttpResponse-CnRXC8_0.js';
4
+ import { g as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-CnRXC8_0.js';
5
5
  import './request/onUnhandledRequest.js';
6
6
  import './internal/isIterable.js';
7
7
 
@@ -33,6 +33,6 @@ interface HandleRequestOptions {
33
33
  */
34
34
  onMockedResponse?(response: Response, handler: RequiredDeep<HandlersExecutionResult>): void;
35
35
  }
36
- declare function handleRequest(request: Request, requestId: string, handlers: Array<unknown>, options: RequiredDeep<SharedOptions>, emitter: Emitter<LifeCycleEventsMap>, handleRequestOptions?: HandleRequestOptions): Promise<Response | undefined>;
36
+ declare function handleRequest(request: Request, requestId: string, handlers: Array<RequestHandler>, options: RequiredDeep<SharedOptions>, emitter: Emitter<LifeCycleEventsMap>, handleRequestOptions?: HandleRequestOptions): Promise<Response | undefined>;
37
37
 
38
38
  export { type HandleRequestOptions, handleRequest };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/utils/handleRequest.ts"],"sourcesContent":["import { until } from '@open-draft/until'\nimport { Emitter } from 'strict-event-emitter'\nimport { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'\nimport { RequiredDeep } from '../typeUtils'\nimport { HandlersExecutionResult, executeHandlers } from './executeHandlers'\nimport { onUnhandledRequest } from './request/onUnhandledRequest'\nimport { storeResponseCookies } from './request/storeResponseCookies'\n\nexport interface HandleRequestOptions {\n /**\n * `resolutionContext` is not part of the general public api\n * but is exposed to aid in creating extensions like\n * `@mswjs/http-middleware`.\n */\n resolutionContext?: {\n /**\n * A base url to use when resolving relative urls.\n * @note This is primarily used by the `@mswjs/http-middleware`\n * to resolve relative urls in the context of the running server\n */\n baseUrl?: string\n }\n\n /**\n * Transforms a `MockedResponse` instance returned from a handler\n * to a response instance supported by the lower tooling (i.e. interceptors).\n */\n transformResponse?(response: Response): Response\n\n /**\n * Invoked whenever a request is performed as-is.\n */\n onPassthroughResponse?(request: Request): void\n\n /**\n * Invoked when the mocked response is ready to be sent.\n */\n onMockedResponse?(\n response: Response,\n handler: RequiredDeep<HandlersExecutionResult>,\n ): void\n}\n\nexport async function handleRequest(\n request: Request,\n requestId: string,\n handlers: Array<unknown>,\n options: RequiredDeep<SharedOptions>,\n emitter: Emitter<LifeCycleEventsMap>,\n handleRequestOptions?: HandleRequestOptions,\n): Promise<Response | undefined> {\n emitter.emit('request:start', { request, requestId })\n\n // Perform bypassed requests (i.e. wrapped in \"bypass()\") as-is.\n if (request.headers.get('x-msw-intention') === 'bypass') {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Resolve a mocked response from the list of request handlers.\n const lookupResult = await until(() => {\n return executeHandlers({\n request,\n requestId,\n handlers,\n resolutionContext: handleRequestOptions?.resolutionContext,\n })\n })\n\n if (lookupResult.error) {\n // Allow developers to react to unhandled exceptions in request handlers.\n emitter.emit('unhandledException', {\n error: lookupResult.error,\n request,\n requestId,\n })\n throw lookupResult.error\n }\n\n // If the handler lookup returned nothing, no request handler was found\n // matching this request. Report the request as unhandled.\n if (!lookupResult.data) {\n await onUnhandledRequest(request, options.onUnhandledRequest)\n emitter.emit('request:unhandled', { request, requestId })\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n const { response } = lookupResult.data\n\n // When the handled request returned no mocked response, warn the developer,\n // as it may be an oversight on their part. Perform the request as-is.\n if (!response) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Perform the request as-is when the developer explicitly returned \"req.passthrough()\".\n // This produces no warning as the request was handled.\n if (\n response.status === 302 &&\n response.headers.get('x-msw-intention') === 'passthrough'\n ) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Store all the received response cookies in the cookie jar.\n storeResponseCookies(request, response)\n\n emitter.emit('request:match', { request, requestId })\n\n const requiredLookupResult =\n lookupResult.data as RequiredDeep<HandlersExecutionResult>\n\n const transformedResponse =\n handleRequestOptions?.transformResponse?.(response) ||\n (response as any as Response)\n\n handleRequestOptions?.onMockedResponse?.(\n transformedResponse,\n requiredLookupResult,\n )\n\n emitter.emit('request:end', { request, requestId })\n\n return transformedResponse\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AAItB,6BAAyD;AACzD,gCAAmC;AACnC,kCAAqC;AAqCrC,eAAsB,cACpB,SACA,WACA,UACA,SACA,SACA,sBAC+B;AAC/B,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAGpD,MAAI,QAAQ,QAAQ,IAAI,iBAAiB,MAAM,UAAU;AACvD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,QAAM,eAAe,UAAM,oBAAM,MAAM;AACrC,eAAO,wCAAgB;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB,sBAAsB;AAAA,IAC3C,CAAC;AAAA,EACH,CAAC;AAED,MAAI,aAAa,OAAO;AAEtB,YAAQ,KAAK,sBAAsB;AAAA,MACjC,OAAO,aAAa;AAAA,MACpB;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,aAAa;AAAA,EACrB;AAIA,MAAI,CAAC,aAAa,MAAM;AACtB,cAAM,8CAAmB,SAAS,QAAQ,kBAAkB;AAC5D,YAAQ,KAAK,qBAAqB,EAAE,SAAS,UAAU,CAAC;AACxD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAEA,QAAM,EAAE,SAAS,IAAI,aAAa;AAIlC,MAAI,CAAC,UAAU;AACb,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAIA,MACE,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,iBAAiB,MAAM,eAC5C;AACA,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,wDAAqB,SAAS,QAAQ;AAEtC,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAEpD,QAAM,uBACJ,aAAa;AAEf,QAAM,sBACJ,sBAAsB,oBAAoB,QAAQ,KACjD;AAEH,wBAAsB;AAAA,IACpB;AAAA,IACA;AAAA,EACF;AAEA,UAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAElD,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/utils/handleRequest.ts"],"sourcesContent":["import { until } from '@open-draft/until'\nimport { Emitter } from 'strict-event-emitter'\nimport { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'\nimport { RequiredDeep } from '../typeUtils'\nimport type { RequestHandler } from '../handlers/RequestHandler'\nimport { HandlersExecutionResult, executeHandlers } from './executeHandlers'\nimport { onUnhandledRequest } from './request/onUnhandledRequest'\nimport { storeResponseCookies } from './request/storeResponseCookies'\n\nexport interface HandleRequestOptions {\n /**\n * `resolutionContext` is not part of the general public api\n * but is exposed to aid in creating extensions like\n * `@mswjs/http-middleware`.\n */\n resolutionContext?: {\n /**\n * A base url to use when resolving relative urls.\n * @note This is primarily used by the `@mswjs/http-middleware`\n * to resolve relative urls in the context of the running server\n */\n baseUrl?: string\n }\n\n /**\n * Transforms a `MockedResponse` instance returned from a handler\n * to a response instance supported by the lower tooling (i.e. interceptors).\n */\n transformResponse?(response: Response): Response\n\n /**\n * Invoked whenever a request is performed as-is.\n */\n onPassthroughResponse?(request: Request): void\n\n /**\n * Invoked when the mocked response is ready to be sent.\n */\n onMockedResponse?(\n response: Response,\n handler: RequiredDeep<HandlersExecutionResult>,\n ): void\n}\n\nexport async function handleRequest(\n request: Request,\n requestId: string,\n handlers: Array<RequestHandler>,\n options: RequiredDeep<SharedOptions>,\n emitter: Emitter<LifeCycleEventsMap>,\n handleRequestOptions?: HandleRequestOptions,\n): Promise<Response | undefined> {\n emitter.emit('request:start', { request, requestId })\n\n // Perform bypassed requests (i.e. wrapped in \"bypass()\") as-is.\n if (request.headers.get('x-msw-intention') === 'bypass') {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Resolve a mocked response from the list of request handlers.\n const lookupResult = await until(() => {\n return executeHandlers({\n request,\n requestId,\n handlers,\n resolutionContext: handleRequestOptions?.resolutionContext,\n })\n })\n\n if (lookupResult.error) {\n // Allow developers to react to unhandled exceptions in request handlers.\n emitter.emit('unhandledException', {\n error: lookupResult.error,\n request,\n requestId,\n })\n throw lookupResult.error\n }\n\n // If the handler lookup returned nothing, no request handler was found\n // matching this request. Report the request as unhandled.\n if (!lookupResult.data) {\n await onUnhandledRequest(request, options.onUnhandledRequest)\n emitter.emit('request:unhandled', { request, requestId })\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n const { response } = lookupResult.data\n\n // When the handled request returned no mocked response, warn the developer,\n // as it may be an oversight on their part. Perform the request as-is.\n if (!response) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Perform the request as-is when the developer explicitly returned \"req.passthrough()\".\n // This produces no warning as the request was handled.\n if (\n response.status === 302 &&\n response.headers.get('x-msw-intention') === 'passthrough'\n ) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Store all the received response cookies in the cookie jar.\n storeResponseCookies(request, response)\n\n emitter.emit('request:match', { request, requestId })\n\n const requiredLookupResult =\n lookupResult.data as RequiredDeep<HandlersExecutionResult>\n\n const transformedResponse =\n handleRequestOptions?.transformResponse?.(response) ||\n (response as any as Response)\n\n handleRequestOptions?.onMockedResponse?.(\n transformedResponse,\n requiredLookupResult,\n )\n\n emitter.emit('request:end', { request, requestId })\n\n return transformedResponse\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AAKtB,6BAAyD;AACzD,gCAAmC;AACnC,kCAAqC;AAqCrC,eAAsB,cACpB,SACA,WACA,UACA,SACA,SACA,sBAC+B;AAC/B,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAGpD,MAAI,QAAQ,QAAQ,IAAI,iBAAiB,MAAM,UAAU;AACvD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,QAAM,eAAe,UAAM,oBAAM,MAAM;AACrC,eAAO,wCAAgB;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB,sBAAsB;AAAA,IAC3C,CAAC;AAAA,EACH,CAAC;AAED,MAAI,aAAa,OAAO;AAEtB,YAAQ,KAAK,sBAAsB;AAAA,MACjC,OAAO,aAAa;AAAA,MACpB;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,aAAa;AAAA,EACrB;AAIA,MAAI,CAAC,aAAa,MAAM;AACtB,cAAM,8CAAmB,SAAS,QAAQ,kBAAkB;AAC5D,YAAQ,KAAK,qBAAqB,EAAE,SAAS,UAAU,CAAC;AACxD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAEA,QAAM,EAAE,SAAS,IAAI,aAAa;AAIlC,MAAI,CAAC,UAAU;AACb,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAIA,MACE,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,iBAAiB,MAAM,eAC5C;AACA,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,wDAAqB,SAAS,QAAQ;AAEtC,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAEpD,QAAM,uBACJ,aAAa;AAEf,QAAM,sBACJ,sBAAsB,oBAAoB,QAAQ,KACjD;AAEH,wBAAsB;AAAA,IACpB;AAAA,IACA;AAAA,EACF;AAEA,UAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAElD,SAAO;AACT;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/utils/handleRequest.ts"],"sourcesContent":["import { until } from '@open-draft/until'\nimport { Emitter } from 'strict-event-emitter'\nimport { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'\nimport { RequiredDeep } from '../typeUtils'\nimport { HandlersExecutionResult, executeHandlers } from './executeHandlers'\nimport { onUnhandledRequest } from './request/onUnhandledRequest'\nimport { storeResponseCookies } from './request/storeResponseCookies'\n\nexport interface HandleRequestOptions {\n /**\n * `resolutionContext` is not part of the general public api\n * but is exposed to aid in creating extensions like\n * `@mswjs/http-middleware`.\n */\n resolutionContext?: {\n /**\n * A base url to use when resolving relative urls.\n * @note This is primarily used by the `@mswjs/http-middleware`\n * to resolve relative urls in the context of the running server\n */\n baseUrl?: string\n }\n\n /**\n * Transforms a `MockedResponse` instance returned from a handler\n * to a response instance supported by the lower tooling (i.e. interceptors).\n */\n transformResponse?(response: Response): Response\n\n /**\n * Invoked whenever a request is performed as-is.\n */\n onPassthroughResponse?(request: Request): void\n\n /**\n * Invoked when the mocked response is ready to be sent.\n */\n onMockedResponse?(\n response: Response,\n handler: RequiredDeep<HandlersExecutionResult>,\n ): void\n}\n\nexport async function handleRequest(\n request: Request,\n requestId: string,\n handlers: Array<unknown>,\n options: RequiredDeep<SharedOptions>,\n emitter: Emitter<LifeCycleEventsMap>,\n handleRequestOptions?: HandleRequestOptions,\n): Promise<Response | undefined> {\n emitter.emit('request:start', { request, requestId })\n\n // Perform bypassed requests (i.e. wrapped in \"bypass()\") as-is.\n if (request.headers.get('x-msw-intention') === 'bypass') {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Resolve a mocked response from the list of request handlers.\n const lookupResult = await until(() => {\n return executeHandlers({\n request,\n requestId,\n handlers,\n resolutionContext: handleRequestOptions?.resolutionContext,\n })\n })\n\n if (lookupResult.error) {\n // Allow developers to react to unhandled exceptions in request handlers.\n emitter.emit('unhandledException', {\n error: lookupResult.error,\n request,\n requestId,\n })\n throw lookupResult.error\n }\n\n // If the handler lookup returned nothing, no request handler was found\n // matching this request. Report the request as unhandled.\n if (!lookupResult.data) {\n await onUnhandledRequest(request, options.onUnhandledRequest)\n emitter.emit('request:unhandled', { request, requestId })\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n const { response } = lookupResult.data\n\n // When the handled request returned no mocked response, warn the developer,\n // as it may be an oversight on their part. Perform the request as-is.\n if (!response) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Perform the request as-is when the developer explicitly returned \"req.passthrough()\".\n // This produces no warning as the request was handled.\n if (\n response.status === 302 &&\n response.headers.get('x-msw-intention') === 'passthrough'\n ) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Store all the received response cookies in the cookie jar.\n storeResponseCookies(request, response)\n\n emitter.emit('request:match', { request, requestId })\n\n const requiredLookupResult =\n lookupResult.data as RequiredDeep<HandlersExecutionResult>\n\n const transformedResponse =\n handleRequestOptions?.transformResponse?.(response) ||\n (response as any as Response)\n\n handleRequestOptions?.onMockedResponse?.(\n transformedResponse,\n requiredLookupResult,\n )\n\n emitter.emit('request:end', { request, requestId })\n\n return transformedResponse\n}\n"],"mappings":"AAAA,SAAS,aAAa;AAItB,SAAkC,uBAAuB;AACzD,SAAS,0BAA0B;AACnC,SAAS,4BAA4B;AAqCrC,eAAsB,cACpB,SACA,WACA,UACA,SACA,SACA,sBAC+B;AAC/B,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAGpD,MAAI,QAAQ,QAAQ,IAAI,iBAAiB,MAAM,UAAU;AACvD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,QAAM,eAAe,MAAM,MAAM,MAAM;AACrC,WAAO,gBAAgB;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB,sBAAsB;AAAA,IAC3C,CAAC;AAAA,EACH,CAAC;AAED,MAAI,aAAa,OAAO;AAEtB,YAAQ,KAAK,sBAAsB;AAAA,MACjC,OAAO,aAAa;AAAA,MACpB;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,aAAa;AAAA,EACrB;AAIA,MAAI,CAAC,aAAa,MAAM;AACtB,UAAM,mBAAmB,SAAS,QAAQ,kBAAkB;AAC5D,YAAQ,KAAK,qBAAqB,EAAE,SAAS,UAAU,CAAC;AACxD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAEA,QAAM,EAAE,SAAS,IAAI,aAAa;AAIlC,MAAI,CAAC,UAAU;AACb,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAIA,MACE,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,iBAAiB,MAAM,eAC5C;AACA,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,uBAAqB,SAAS,QAAQ;AAEtC,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAEpD,QAAM,uBACJ,aAAa;AAEf,QAAM,sBACJ,sBAAsB,oBAAoB,QAAQ,KACjD;AAEH,wBAAsB;AAAA,IACpB;AAAA,IACA;AAAA,EACF;AAEA,UAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAElD,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/utils/handleRequest.ts"],"sourcesContent":["import { until } from '@open-draft/until'\nimport { Emitter } from 'strict-event-emitter'\nimport { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'\nimport { RequiredDeep } from '../typeUtils'\nimport type { RequestHandler } from '../handlers/RequestHandler'\nimport { HandlersExecutionResult, executeHandlers } from './executeHandlers'\nimport { onUnhandledRequest } from './request/onUnhandledRequest'\nimport { storeResponseCookies } from './request/storeResponseCookies'\n\nexport interface HandleRequestOptions {\n /**\n * `resolutionContext` is not part of the general public api\n * but is exposed to aid in creating extensions like\n * `@mswjs/http-middleware`.\n */\n resolutionContext?: {\n /**\n * A base url to use when resolving relative urls.\n * @note This is primarily used by the `@mswjs/http-middleware`\n * to resolve relative urls in the context of the running server\n */\n baseUrl?: string\n }\n\n /**\n * Transforms a `MockedResponse` instance returned from a handler\n * to a response instance supported by the lower tooling (i.e. interceptors).\n */\n transformResponse?(response: Response): Response\n\n /**\n * Invoked whenever a request is performed as-is.\n */\n onPassthroughResponse?(request: Request): void\n\n /**\n * Invoked when the mocked response is ready to be sent.\n */\n onMockedResponse?(\n response: Response,\n handler: RequiredDeep<HandlersExecutionResult>,\n ): void\n}\n\nexport async function handleRequest(\n request: Request,\n requestId: string,\n handlers: Array<RequestHandler>,\n options: RequiredDeep<SharedOptions>,\n emitter: Emitter<LifeCycleEventsMap>,\n handleRequestOptions?: HandleRequestOptions,\n): Promise<Response | undefined> {\n emitter.emit('request:start', { request, requestId })\n\n // Perform bypassed requests (i.e. wrapped in \"bypass()\") as-is.\n if (request.headers.get('x-msw-intention') === 'bypass') {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Resolve a mocked response from the list of request handlers.\n const lookupResult = await until(() => {\n return executeHandlers({\n request,\n requestId,\n handlers,\n resolutionContext: handleRequestOptions?.resolutionContext,\n })\n })\n\n if (lookupResult.error) {\n // Allow developers to react to unhandled exceptions in request handlers.\n emitter.emit('unhandledException', {\n error: lookupResult.error,\n request,\n requestId,\n })\n throw lookupResult.error\n }\n\n // If the handler lookup returned nothing, no request handler was found\n // matching this request. Report the request as unhandled.\n if (!lookupResult.data) {\n await onUnhandledRequest(request, options.onUnhandledRequest)\n emitter.emit('request:unhandled', { request, requestId })\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n const { response } = lookupResult.data\n\n // When the handled request returned no mocked response, warn the developer,\n // as it may be an oversight on their part. Perform the request as-is.\n if (!response) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Perform the request as-is when the developer explicitly returned \"req.passthrough()\".\n // This produces no warning as the request was handled.\n if (\n response.status === 302 &&\n response.headers.get('x-msw-intention') === 'passthrough'\n ) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Store all the received response cookies in the cookie jar.\n storeResponseCookies(request, response)\n\n emitter.emit('request:match', { request, requestId })\n\n const requiredLookupResult =\n lookupResult.data as RequiredDeep<HandlersExecutionResult>\n\n const transformedResponse =\n handleRequestOptions?.transformResponse?.(response) ||\n (response as any as Response)\n\n handleRequestOptions?.onMockedResponse?.(\n transformedResponse,\n requiredLookupResult,\n )\n\n emitter.emit('request:end', { request, requestId })\n\n return transformedResponse\n}\n"],"mappings":"AAAA,SAAS,aAAa;AAKtB,SAAkC,uBAAuB;AACzD,SAAS,0BAA0B;AACnC,SAAS,4BAA4B;AAqCrC,eAAsB,cACpB,SACA,WACA,UACA,SACA,SACA,sBAC+B;AAC/B,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAGpD,MAAI,QAAQ,QAAQ,IAAI,iBAAiB,MAAM,UAAU;AACvD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,QAAM,eAAe,MAAM,MAAM,MAAM;AACrC,WAAO,gBAAgB;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB,sBAAsB;AAAA,IAC3C,CAAC;AAAA,EACH,CAAC;AAED,MAAI,aAAa,OAAO;AAEtB,YAAQ,KAAK,sBAAsB;AAAA,MACjC,OAAO,aAAa;AAAA,MACpB;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,aAAa;AAAA,EACrB;AAIA,MAAI,CAAC,aAAa,MAAM;AACtB,UAAM,mBAAmB,SAAS,QAAQ,kBAAkB;AAC5D,YAAQ,KAAK,qBAAqB,EAAE,SAAS,UAAU,CAAC;AACxD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAEA,QAAM,EAAE,SAAS,IAAI,aAAa;AAIlC,MAAI,CAAC,UAAU;AACb,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAIA,MACE,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,iBAAiB,MAAM,eAC5C;AACA,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,uBAAqB,SAAS,QAAQ;AAEtC,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAEpD,QAAM,uBACJ,aAAa;AAEf,QAAM,sBACJ,sBAAsB,oBAAoB,QAAQ,KACjD;AAEH,wBAAsB;AAAA,IACpB;AAAA,IACA;AAAA,EACF;AAEA,UAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAElD,SAAO;AACT;","names":[]}
@@ -1,5 +1,4 @@
1
1
  import { WebSocketData, WebSocketClientConnectionProtocol, WebSocketClientConnection } from '@mswjs/interceptors/WebSocket';
2
- import { Path } from '../utils/matching/matchRequestUrl.mjs';
3
2
 
4
3
  type WebSocketBroadcastChannelMessage = {
5
4
  type: 'extraneous:send';
@@ -21,11 +20,10 @@ type WebSocketBroadcastChannelMessage = {
21
20
  */
22
21
  declare class WebSocketClientManager {
23
22
  private channel;
24
- private url;
25
23
  private store;
26
24
  private runtimeClients;
27
25
  private allClients;
28
- constructor(channel: BroadcastChannel, url: Path);
26
+ constructor(channel: BroadcastChannel);
29
27
  private flushDatabaseToMemory;
30
28
  private removeRuntimeClients;
31
29
  /**
@@ -1,5 +1,4 @@
1
1
  import { WebSocketData, WebSocketClientConnectionProtocol, WebSocketClientConnection } from '@mswjs/interceptors/WebSocket';
2
- import { Path } from '../utils/matching/matchRequestUrl.js';
3
2
 
4
3
  type WebSocketBroadcastChannelMessage = {
5
4
  type: 'extraneous:send';
@@ -21,11 +20,10 @@ type WebSocketBroadcastChannelMessage = {
21
20
  */
22
21
  declare class WebSocketClientManager {
23
22
  private channel;
24
- private url;
25
23
  private store;
26
24
  private runtimeClients;
27
25
  private allClients;
28
- constructor(channel: BroadcastChannel, url: Path);
26
+ constructor(channel: BroadcastChannel);
29
27
  private flushDatabaseToMemory;
30
28
  private removeRuntimeClients;
31
29
  /**
@@ -25,9 +25,8 @@ module.exports = __toCommonJS(WebSocketClientManager_exports);
25
25
  var import_WebSocketMemoryClientStore = require("./WebSocketMemoryClientStore.js");
26
26
  var import_WebSocketIndexedDBClientStore = require("./WebSocketIndexedDBClientStore.js");
27
27
  class WebSocketClientManager {
28
- constructor(channel, url) {
28
+ constructor(channel) {
29
29
  this.channel = channel;
30
- this.url = url;
31
30
  this.store = typeof indexedDB !== "undefined" ? new import_WebSocketIndexedDBClientStore.WebSocketIndexedDBClientStore() : new import_WebSocketMemoryClientStore.WebSocketMemoryClientStore();
32
31
  this.runtimeClients = /* @__PURE__ */ new Map();
33
32
  this.allClients = /* @__PURE__ */ new Set();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/ws/WebSocketClientManager.ts"],"sourcesContent":["import type {\n WebSocketData,\n WebSocketClientConnection,\n WebSocketClientConnectionProtocol,\n} from '@mswjs/interceptors/WebSocket'\nimport { type Path } from '../utils/matching/matchRequestUrl'\nimport { WebSocketClientStore } from './WebSocketClientStore'\nimport { WebSocketMemoryClientStore } from './WebSocketMemoryClientStore'\nimport { WebSocketIndexedDBClientStore } from './WebSocketIndexedDBClientStore'\n\nexport type WebSocketBroadcastChannelMessage =\n | {\n type: 'extraneous:send'\n payload: {\n clientId: string\n data: WebSocketData\n }\n }\n | {\n type: 'extraneous:close'\n payload: {\n clientId: string\n code?: number\n reason?: string\n }\n }\n\n/**\n * A manager responsible for accumulating WebSocket client\n * connections across different browser runtimes.\n */\nexport class WebSocketClientManager {\n private store: WebSocketClientStore\n private runtimeClients: Map<string, WebSocketClientConnectionProtocol>\n private allClients: Set<WebSocketClientConnectionProtocol>\n\n constructor(\n private channel: BroadcastChannel,\n private url: Path,\n ) {\n // Store the clients in the IndexedDB in the browser,\n // otherwise, store the clients in memory.\n this.store =\n typeof indexedDB !== 'undefined'\n ? new WebSocketIndexedDBClientStore()\n : new WebSocketMemoryClientStore()\n\n this.runtimeClients = new Map()\n this.allClients = new Set()\n\n this.channel.addEventListener('message', (message) => {\n if (message.data?.type === 'db:update') {\n this.flushDatabaseToMemory()\n }\n })\n\n if (typeof window !== 'undefined') {\n window.addEventListener('message', async (message) => {\n if (message.data?.type === 'msw/worker:stop') {\n await this.removeRuntimeClients()\n }\n })\n }\n }\n\n private async flushDatabaseToMemory() {\n const storedClients = await this.store.getAll()\n\n this.allClients = new Set(\n storedClients.map((client) => {\n const runtimeClient = this.runtimeClients.get(client.id)\n\n /**\n * @note For clients originating in this runtime, use their\n * direct references. No need to wrap them in a remote connection.\n */\n if (runtimeClient) {\n return runtimeClient\n }\n\n return new WebSocketRemoteClientConnection(\n client.id,\n new URL(client.url),\n this.channel,\n )\n }),\n )\n }\n\n private async removeRuntimeClients(): Promise<void> {\n await this.store.deleteMany(Array.from(this.runtimeClients.keys()))\n this.runtimeClients.clear()\n await this.flushDatabaseToMemory()\n this.notifyOthersAboutDatabaseUpdate()\n }\n\n /**\n * All active WebSocket client connections.\n */\n get clients(): Set<WebSocketClientConnectionProtocol> {\n return this.allClients\n }\n\n /**\n * Notify other runtimes about the database update\n * using the shared `BroadcastChannel` instance.\n */\n private notifyOthersAboutDatabaseUpdate(): void {\n this.channel.postMessage({ type: 'db:update' })\n }\n\n private async addClient(client: WebSocketClientConnection): Promise<void> {\n await this.store.add(client)\n // Sync the in-memory clients in this runtime with the\n // updated database. This pulls in all the stored clients.\n await this.flushDatabaseToMemory()\n this.notifyOthersAboutDatabaseUpdate()\n }\n\n /**\n * Adds the given `WebSocket` client connection to the set\n * of all connections. The given connection is always the complete\n * connection object because `addConnection()` is called only\n * for the opened connections in the same runtime.\n */\n public async addConnection(client: WebSocketClientConnection): Promise<void> {\n // Store this client in the map of clients created in this runtime.\n // This way, the manager can distinguish between this runtime clients\n // and extraneous runtime clients when synchronizing clients storage.\n this.runtimeClients.set(client.id, client)\n\n // Add the new client to the storage.\n await this.addClient(client)\n\n // Handle the incoming BroadcastChannel messages from other runtimes\n // that attempt to control this runtime (via a remote connection wrapper).\n // E.g. another runtime calling `client.send()` for the client in this runtime.\n const handleExtraneousMessage = (\n message: MessageEvent<WebSocketBroadcastChannelMessage>,\n ) => {\n const { type, payload } = message.data\n\n // Ignore broadcasted messages for other clients.\n if (\n typeof payload === 'object' &&\n 'clientId' in payload &&\n payload.clientId !== client.id\n ) {\n return\n }\n\n switch (type) {\n case 'extraneous:send': {\n client.send(payload.data)\n break\n }\n\n case 'extraneous:close': {\n client.close(payload.code, payload.reason)\n break\n }\n }\n }\n\n const abortController = new AbortController()\n\n this.channel.addEventListener('message', handleExtraneousMessage, {\n signal: abortController.signal,\n })\n\n // Once closed, this connection cannot be operated on.\n // This must include the extraneous runtimes as well.\n client.addEventListener('close', () => abortController.abort(), {\n once: true,\n })\n }\n}\n\n/**\n * A wrapper class to operate with WebSocket client connections\n * from other runtimes. This class maintains 1-1 public API\n * compatibility to the `WebSocketClientConnection` but relies\n * on the given `BroadcastChannel` to communicate instructions\n * with the client connections from other runtimes.\n */\nexport class WebSocketRemoteClientConnection\n implements WebSocketClientConnectionProtocol\n{\n constructor(\n public readonly id: string,\n public readonly url: URL,\n private channel: BroadcastChannel,\n ) {}\n\n send(data: WebSocketData): void {\n this.channel.postMessage({\n type: 'extraneous:send',\n payload: {\n clientId: this.id,\n data,\n },\n } as WebSocketBroadcastChannelMessage)\n }\n\n close(code?: number | undefined, reason?: string | undefined): void {\n this.channel.postMessage({\n type: 'extraneous:close',\n payload: {\n clientId: this.id,\n code,\n reason,\n },\n } as WebSocketBroadcastChannelMessage)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,wCAA2C;AAC3C,2CAA8C;AAuBvC,MAAM,uBAAuB;AAAA,EAKlC,YACU,SACA,KACR;AAFQ;AACA;AAIR,SAAK,QACH,OAAO,cAAc,cACjB,IAAI,mEAA8B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]}
1
+ {"version":3,"sources":["../../../src/core/ws/WebSocketClientManager.ts"],"sourcesContent":["import type {\n WebSocketData,\n WebSocketClientConnection,\n WebSocketClientConnectionProtocol,\n} from '@mswjs/interceptors/WebSocket'\nimport { WebSocketClientStore } from './WebSocketClientStore'\nimport { WebSocketMemoryClientStore } from './WebSocketMemoryClientStore'\nimport { WebSocketIndexedDBClientStore } from './WebSocketIndexedDBClientStore'\n\nexport type WebSocketBroadcastChannelMessage =\n | {\n type: 'extraneous:send'\n payload: {\n clientId: string\n data: WebSocketData\n }\n }\n | {\n type: 'extraneous:close'\n payload: {\n clientId: string\n code?: number\n reason?: string\n }\n }\n\n/**\n * A manager responsible for accumulating WebSocket client\n * connections across different browser runtimes.\n */\nexport class WebSocketClientManager {\n private store: WebSocketClientStore\n private runtimeClients: Map<string, WebSocketClientConnectionProtocol>\n private allClients: Set<WebSocketClientConnectionProtocol>\n\n constructor(private channel: BroadcastChannel) {\n // Store the clients in the IndexedDB in the browser,\n // otherwise, store the clients in memory.\n this.store =\n typeof indexedDB !== 'undefined'\n ? new WebSocketIndexedDBClientStore()\n : new WebSocketMemoryClientStore()\n\n this.runtimeClients = new Map()\n this.allClients = new Set()\n\n this.channel.addEventListener('message', (message) => {\n if (message.data?.type === 'db:update') {\n this.flushDatabaseToMemory()\n }\n })\n\n if (typeof window !== 'undefined') {\n window.addEventListener('message', async (message) => {\n if (message.data?.type === 'msw/worker:stop') {\n await this.removeRuntimeClients()\n }\n })\n }\n }\n\n private async flushDatabaseToMemory() {\n const storedClients = await this.store.getAll()\n\n this.allClients = new Set(\n storedClients.map((client) => {\n const runtimeClient = this.runtimeClients.get(client.id)\n\n /**\n * @note For clients originating in this runtime, use their\n * direct references. No need to wrap them in a remote connection.\n */\n if (runtimeClient) {\n return runtimeClient\n }\n\n return new WebSocketRemoteClientConnection(\n client.id,\n new URL(client.url),\n this.channel,\n )\n }),\n )\n }\n\n private async removeRuntimeClients(): Promise<void> {\n await this.store.deleteMany(Array.from(this.runtimeClients.keys()))\n this.runtimeClients.clear()\n await this.flushDatabaseToMemory()\n this.notifyOthersAboutDatabaseUpdate()\n }\n\n /**\n * All active WebSocket client connections.\n */\n get clients(): Set<WebSocketClientConnectionProtocol> {\n return this.allClients\n }\n\n /**\n * Notify other runtimes about the database update\n * using the shared `BroadcastChannel` instance.\n */\n private notifyOthersAboutDatabaseUpdate(): void {\n this.channel.postMessage({ type: 'db:update' })\n }\n\n private async addClient(client: WebSocketClientConnection): Promise<void> {\n await this.store.add(client)\n // Sync the in-memory clients in this runtime with the\n // updated database. This pulls in all the stored clients.\n await this.flushDatabaseToMemory()\n this.notifyOthersAboutDatabaseUpdate()\n }\n\n /**\n * Adds the given `WebSocket` client connection to the set\n * of all connections. The given connection is always the complete\n * connection object because `addConnection()` is called only\n * for the opened connections in the same runtime.\n */\n public async addConnection(client: WebSocketClientConnection): Promise<void> {\n // Store this client in the map of clients created in this runtime.\n // This way, the manager can distinguish between this runtime clients\n // and extraneous runtime clients when synchronizing clients storage.\n this.runtimeClients.set(client.id, client)\n\n // Add the new client to the storage.\n await this.addClient(client)\n\n // Handle the incoming BroadcastChannel messages from other runtimes\n // that attempt to control this runtime (via a remote connection wrapper).\n // E.g. another runtime calling `client.send()` for the client in this runtime.\n const handleExtraneousMessage = (\n message: MessageEvent<WebSocketBroadcastChannelMessage>,\n ) => {\n const { type, payload } = message.data\n\n // Ignore broadcasted messages for other clients.\n if (\n typeof payload === 'object' &&\n 'clientId' in payload &&\n payload.clientId !== client.id\n ) {\n return\n }\n\n switch (type) {\n case 'extraneous:send': {\n client.send(payload.data)\n break\n }\n\n case 'extraneous:close': {\n client.close(payload.code, payload.reason)\n break\n }\n }\n }\n\n const abortController = new AbortController()\n\n this.channel.addEventListener('message', handleExtraneousMessage, {\n signal: abortController.signal,\n })\n\n // Once closed, this connection cannot be operated on.\n // This must include the extraneous runtimes as well.\n client.addEventListener('close', () => abortController.abort(), {\n once: true,\n })\n }\n}\n\n/**\n * A wrapper class to operate with WebSocket client connections\n * from other runtimes. This class maintains 1-1 public API\n * compatibility to the `WebSocketClientConnection` but relies\n * on the given `BroadcastChannel` to communicate instructions\n * with the client connections from other runtimes.\n */\nexport class WebSocketRemoteClientConnection\n implements WebSocketClientConnectionProtocol\n{\n constructor(\n public readonly id: string,\n public readonly url: URL,\n private channel: BroadcastChannel,\n ) {}\n\n send(data: WebSocketData): void {\n this.channel.postMessage({\n type: 'extraneous:send',\n payload: {\n clientId: this.id,\n data,\n },\n } as WebSocketBroadcastChannelMessage)\n }\n\n close(code?: number | undefined, reason?: string | undefined): void {\n this.channel.postMessage({\n type: 'extraneous:close',\n payload: {\n clientId: this.id,\n code,\n reason,\n },\n } as WebSocketBroadcastChannelMessage)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,wCAA2C;AAC3C,2CAA8C;AAuBvC,MAAM,uBAAuB;AAAA,EAKlC,YAAoB,SAA2B;AAA3B;AAGlB,SAAK,QACH,OAAO,cAAc,cACjB,IAAI,mEAA8B,IAClC,IAAI,6DAA2B;AAErC,SAAK,iBAAiB,oBAAI,IAAI;AAC9B,SAAK,aAAa,oBAAI,IAAI;AAE1B,SAAK,QAAQ,iBAAiB,WAAW,CAAC,YAAY;AACpD,UAAI,QAAQ,MAAM,SAAS,aAAa;AACtC,aAAK,sBAAsB;AAAA,MAC7B;AAAA,IACF,CAAC;AAED,QAAI,OAAO,WAAW,aAAa;AACjC,aAAO,iBAAiB,WAAW,OAAO,YAAY;AACpD,YAAI,QAAQ,MAAM,SAAS,mBAAmB;AAC5C,gBAAM,KAAK,qBAAqB;AAAA,QAClC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EA5BQ;AAAA,EACA;AAAA,EACA;AAAA,EA4BR,MAAc,wBAAwB;AACpC,UAAM,gBAAgB,MAAM,KAAK,MAAM,OAAO;AAE9C,SAAK,aAAa,IAAI;AAAA,MACpB,cAAc,IAAI,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AAAA,IACF;AAEA,UAAM,kBAAkB,IAAI,gBAAgB;AAE5C,SAAK,QAAQ,iBAAiB,WAAW,yBAAyB;AAAA,MAChE,QAAQ,gBAAgB;AAAA,IAC1B,CAAC;AAID,WAAO,iBAAiB,SAAS,MAAM,gBAAgB,MAAM,GAAG;AAAA,MAC9D,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AACF;AASO,MAAM,gCAEb;AAAA,EACE,YACkB,IACA,KACR,SACR;AAHgB;AACA;AACR;AAAA,EACP;AAAA,EAEH,KAAK,MAA2B;AAC9B,SAAK,QAAQ,YAAY;AAAA,MACvB,MAAM;AAAA,MACN,SAAS;AAAA,QACP,UAAU,KAAK;AAAA,QACf;AAAA,MACF;AAAA,IACF,CAAqC;AAAA,EACvC;AAAA,EAEA,MAAM,MAA2B,QAAmC;AAClE,SAAK,QAAQ,YAAY;AAAA,MACvB,MAAM;AAAA,MACN,SAAS;AAAA,QACP,UAAU,KAAK;AAAA,QACf;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAqC;AAAA,EACvC;AACF;","names":[]}
@@ -1,9 +1,8 @@
1
1
  import { WebSocketMemoryClientStore } from './WebSocketMemoryClientStore.mjs';
2
2
  import { WebSocketIndexedDBClientStore } from './WebSocketIndexedDBClientStore.mjs';
3
3
  class WebSocketClientManager {
4
- constructor(channel, url) {
4
+ constructor(channel) {
5
5
  this.channel = channel;
6
- this.url = url;
7
6
  this.store = typeof indexedDB !== "undefined" ? new WebSocketIndexedDBClientStore() : new WebSocketMemoryClientStore();
8
7
  this.runtimeClients = /* @__PURE__ */ new Map();
9
8
  this.allClients = /* @__PURE__ */ new Set();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/ws/WebSocketClientManager.ts"],"sourcesContent":["import type {\n WebSocketData,\n WebSocketClientConnection,\n WebSocketClientConnectionProtocol,\n} from '@mswjs/interceptors/WebSocket'\nimport { type Path } from '../utils/matching/matchRequestUrl'\nimport { WebSocketClientStore } from './WebSocketClientStore'\nimport { WebSocketMemoryClientStore } from './WebSocketMemoryClientStore'\nimport { WebSocketIndexedDBClientStore } from './WebSocketIndexedDBClientStore'\n\nexport type WebSocketBroadcastChannelMessage =\n | {\n type: 'extraneous:send'\n payload: {\n clientId: string\n data: WebSocketData\n }\n }\n | {\n type: 'extraneous:close'\n payload: {\n clientId: string\n code?: number\n reason?: string\n }\n }\n\n/**\n * A manager responsible for accumulating WebSocket client\n * connections across different browser runtimes.\n */\nexport class WebSocketClientManager {\n private store: WebSocketClientStore\n private runtimeClients: Map<string, WebSocketClientConnectionProtocol>\n private allClients: Set<WebSocketClientConnectionProtocol>\n\n constructor(\n private channel: BroadcastChannel,\n private url: Path,\n ) {\n // Store the clients in the IndexedDB in the browser,\n // otherwise, store the clients in memory.\n this.store =\n typeof indexedDB !== 'undefined'\n ? new WebSocketIndexedDBClientStore()\n : new WebSocketMemoryClientStore()\n\n this.runtimeClients = new Map()\n this.allClients = new Set()\n\n this.channel.addEventListener('message', (message) => {\n if (message.data?.type === 'db:update') {\n this.flushDatabaseToMemory()\n }\n })\n\n if (typeof window !== 'undefined') {\n window.addEventListener('message', async (message) => {\n if (message.data?.type === 'msw/worker:stop') {\n await this.removeRuntimeClients()\n }\n })\n }\n }\n\n private async flushDatabaseToMemory() {\n const storedClients = await this.store.getAll()\n\n this.allClients = new Set(\n storedClients.map((client) => {\n const runtimeClient = this.runtimeClients.get(client.id)\n\n /**\n * @note For clients originating in this runtime, use their\n * direct references. No need to wrap them in a remote connection.\n */\n if (runtimeClient) {\n return runtimeClient\n }\n\n return new WebSocketRemoteClientConnection(\n client.id,\n new URL(client.url),\n this.channel,\n )\n }),\n )\n }\n\n private async removeRuntimeClients(): Promise<void> {\n await this.store.deleteMany(Array.from(this.runtimeClients.keys()))\n this.runtimeClients.clear()\n await this.flushDatabaseToMemory()\n this.notifyOthersAboutDatabaseUpdate()\n }\n\n /**\n * All active WebSocket client connections.\n */\n get clients(): Set<WebSocketClientConnectionProtocol> {\n return this.allClients\n }\n\n /**\n * Notify other runtimes about the database update\n * using the shared `BroadcastChannel` instance.\n */\n private notifyOthersAboutDatabaseUpdate(): void {\n this.channel.postMessage({ type: 'db:update' })\n }\n\n private async addClient(client: WebSocketClientConnection): Promise<void> {\n await this.store.add(client)\n // Sync the in-memory clients in this runtime with the\n // updated database. This pulls in all the stored clients.\n await this.flushDatabaseToMemory()\n this.notifyOthersAboutDatabaseUpdate()\n }\n\n /**\n * Adds the given `WebSocket` client connection to the set\n * of all connections. The given connection is always the complete\n * connection object because `addConnection()` is called only\n * for the opened connections in the same runtime.\n */\n public async addConnection(client: WebSocketClientConnection): Promise<void> {\n // Store this client in the map of clients created in this runtime.\n // This way, the manager can distinguish between this runtime clients\n // and extraneous runtime clients when synchronizing clients storage.\n this.runtimeClients.set(client.id, client)\n\n // Add the new client to the storage.\n await this.addClient(client)\n\n // Handle the incoming BroadcastChannel messages from other runtimes\n // that attempt to control this runtime (via a remote connection wrapper).\n // E.g. another runtime calling `client.send()` for the client in this runtime.\n const handleExtraneousMessage = (\n message: MessageEvent<WebSocketBroadcastChannelMessage>,\n ) => {\n const { type, payload } = message.data\n\n // Ignore broadcasted messages for other clients.\n if (\n typeof payload === 'object' &&\n 'clientId' in payload &&\n payload.clientId !== client.id\n ) {\n return\n }\n\n switch (type) {\n case 'extraneous:send': {\n client.send(payload.data)\n break\n }\n\n case 'extraneous:close': {\n client.close(payload.code, payload.reason)\n break\n }\n }\n }\n\n const abortController = new AbortController()\n\n this.channel.addEventListener('message', handleExtraneousMessage, {\n signal: abortController.signal,\n })\n\n // Once closed, this connection cannot be operated on.\n // This must include the extraneous runtimes as well.\n client.addEventListener('close', () => abortController.abort(), {\n once: true,\n })\n }\n}\n\n/**\n * A wrapper class to operate with WebSocket client connections\n * from other runtimes. This class maintains 1-1 public API\n * compatibility to the `WebSocketClientConnection` but relies\n * on the given `BroadcastChannel` to communicate instructions\n * with the client connections from other runtimes.\n */\nexport class WebSocketRemoteClientConnection\n implements WebSocketClientConnectionProtocol\n{\n constructor(\n public readonly id: string,\n public readonly url: URL,\n private channel: BroadcastChannel,\n ) {}\n\n send(data: WebSocketData): void {\n this.channel.postMessage({\n type: 'extraneous:send',\n payload: {\n clientId: this.id,\n data,\n },\n } as WebSocketBroadcastChannelMessage)\n }\n\n close(code?: number | undefined, reason?: string | undefined): void {\n this.channel.postMessage({\n type: 'extraneous:close',\n payload: {\n clientId: this.id,\n code,\n reason,\n },\n } as WebSocketBroadcastChannelMessage)\n }\n}\n"],"mappings":"AAOA,SAAS,kCAAkC;AAC3C,SAAS,qCAAqC;AAuBvC,MAAM,uBAAuB;AAAA,EAKlC,YACU,SACA,KACR;AAFQ;AACA;AAIR,SAAK,QACH,OAAO,cAAc,cACjB,IAAI,8BAA8B,IAClC,IAAI,2BAA2B;AAErC,SAAK,iBAAiB,oBAAI,IAAI;AAC9B,SAAK,aAAa,oBAAI,IAAI;AAE1B,SAAK,QAAQ,iBAAiB,WAAW,CAAC,YAAY;AACpD,UAAI,QAAQ,MAAM,SAAS,aAAa;AACtC,aAAK,sBAAsB;AAAA,MAC7B;AAAA,IACF,CAAC;AAED,QAAI,OAAO,WAAW,aAAa;AACjC,aAAO,iBAAiB,WAAW,OAAO,YAAY;AACpD,YAAI,QAAQ,MAAM,SAAS,mBAAmB;AAC5C,gBAAM,KAAK,qBAAqB;AAAA,QAClC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EA/BQ;AAAA,EACA;AAAA,EACA;AAAA,EA+BR,MAAc,wBAAwB;AACpC,UAAM,gBAAgB,MAAM,KAAK,MAAM,OAAO;AAE9C,SAAK,aAAa,IAAI;AAAA,MACpB,cAAc,IAAI,CAAC,WAAW;AAC5B,cAAM,gBAAgB,KAAK,eAAe,IAAI,OAAO,EAAE;AAMvD,YAAI,eAAe;AACjB,iBAAO;AAAA,QACT;AAEA,eAAO,IAAI;AAAA,UACT,OAAO;AAAA,UACP,IAAI,IAAI,OAAO,GAAG;AAAA,UAClB,KAAK;AA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9D,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AACF;AASO,MAAM,gCAEb;AAAA,EACE,YACkB,IACA,KACR,SACR;AAHgB;AACA;AACR;AAAA,EACP;AAAA,EAEH,KAAK,MAA2B;AAC9B,SAAK,QAAQ,YAAY;AAAA,MACvB,MAAM;AAAA,MACN,SAAS;AAAA,QACP,UAAU,KAAK;AAAA,QACf;AAAA,MACF;AAAA,IACF,CAAqC;AAAA,EACvC;AAAA,EAEA,MAAM,MAA2B,QAAmC;AAClE,SAAK,QAAQ,YAAY;AAAA,MACvB,MAAM;AAAA,MACN,SAAS;AAAA,QACP,UAAU,KAAK;AAAA,QACf;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAqC;AAAA,EACvC;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/ws/WebSocketClientManager.ts"],"sourcesContent":["import type {\n WebSocketData,\n WebSocketClientConnection,\n WebSocketClientConnectionProtocol,\n} from '@mswjs/interceptors/WebSocket'\nimport { WebSocketClientStore } from './WebSocketClientStore'\nimport { WebSocketMemoryClientStore } from './WebSocketMemoryClientStore'\nimport { WebSocketIndexedDBClientStore } from './WebSocketIndexedDBClientStore'\n\nexport type WebSocketBroadcastChannelMessage =\n | {\n type: 'extraneous:send'\n payload: {\n clientId: string\n data: WebSocketData\n }\n }\n | {\n type: 'extraneous:close'\n payload: {\n clientId: string\n code?: number\n reason?: string\n }\n }\n\n/**\n * A manager responsible for accumulating WebSocket client\n * connections across different browser runtimes.\n */\nexport class WebSocketClientManager {\n private store: WebSocketClientStore\n private runtimeClients: Map<string, WebSocketClientConnectionProtocol>\n private allClients: Set<WebSocketClientConnectionProtocol>\n\n constructor(private channel: BroadcastChannel) {\n // Store the clients in the IndexedDB in the browser,\n // otherwise, store the clients in memory.\n this.store =\n typeof indexedDB !== 'undefined'\n ? new WebSocketIndexedDBClientStore()\n : new WebSocketMemoryClientStore()\n\n this.runtimeClients = new Map()\n this.allClients = new Set()\n\n this.channel.addEventListener('message', (message) => {\n if (message.data?.type === 'db:update') {\n this.flushDatabaseToMemory()\n }\n })\n\n if (typeof window !== 'undefined') {\n window.addEventListener('message', async (message) => {\n if (message.data?.type === 'msw/worker:stop') {\n await this.removeRuntimeClients()\n }\n })\n }\n }\n\n private async flushDatabaseToMemory() {\n const storedClients = await this.store.getAll()\n\n this.allClients = new Set(\n storedClients.map((client) => {\n const runtimeClient = this.runtimeClients.get(client.id)\n\n /**\n * @note For clients originating in this runtime, use their\n * direct references. No need to wrap them in a remote connection.\n */\n if (runtimeClient) {\n return runtimeClient\n }\n\n return new WebSocketRemoteClientConnection(\n client.id,\n new URL(client.url),\n this.channel,\n )\n }),\n )\n }\n\n private async removeRuntimeClients(): Promise<void> {\n await this.store.deleteMany(Array.from(this.runtimeClients.keys()))\n this.runtimeClients.clear()\n await this.flushDatabaseToMemory()\n this.notifyOthersAboutDatabaseUpdate()\n }\n\n /**\n * All active WebSocket client connections.\n */\n get clients(): Set<WebSocketClientConnectionProtocol> {\n return this.allClients\n }\n\n /**\n * Notify other runtimes about the database update\n * using the shared `BroadcastChannel` instance.\n */\n private notifyOthersAboutDatabaseUpdate(): void {\n this.channel.postMessage({ type: 'db:update' })\n }\n\n private async addClient(client: WebSocketClientConnection): Promise<void> {\n await this.store.add(client)\n // Sync the in-memory clients in this runtime with the\n // updated database. This pulls in all the stored clients.\n await this.flushDatabaseToMemory()\n this.notifyOthersAboutDatabaseUpdate()\n }\n\n /**\n * Adds the given `WebSocket` client connection to the set\n * of all connections. The given connection is always the complete\n * connection object because `addConnection()` is called only\n * for the opened connections in the same runtime.\n */\n public async addConnection(client: WebSocketClientConnection): Promise<void> {\n // Store this client in the map of clients created in this runtime.\n // This way, the manager can distinguish between this runtime clients\n // and extraneous runtime clients when synchronizing clients storage.\n this.runtimeClients.set(client.id, client)\n\n // Add the new client to the storage.\n await this.addClient(client)\n\n // Handle the incoming BroadcastChannel messages from other runtimes\n // that attempt to control this runtime (via a remote connection wrapper).\n // E.g. another runtime calling `client.send()` for the client in this runtime.\n const handleExtraneousMessage = (\n message: MessageEvent<WebSocketBroadcastChannelMessage>,\n ) => {\n const { type, payload } = message.data\n\n // Ignore broadcasted messages for other clients.\n if (\n typeof payload === 'object' &&\n 'clientId' in payload &&\n payload.clientId !== client.id\n ) {\n return\n }\n\n switch (type) {\n case 'extraneous:send': {\n client.send(payload.data)\n break\n }\n\n case 'extraneous:close': {\n client.close(payload.code, payload.reason)\n break\n }\n }\n }\n\n const abortController = new AbortController()\n\n this.channel.addEventListener('message', handleExtraneousMessage, {\n signal: abortController.signal,\n })\n\n // Once closed, this connection cannot be operated on.\n // This must include the extraneous runtimes as well.\n client.addEventListener('close', () => abortController.abort(), {\n once: true,\n })\n }\n}\n\n/**\n * A wrapper class to operate with WebSocket client connections\n * from other runtimes. This class maintains 1-1 public API\n * compatibility to the `WebSocketClientConnection` but relies\n * on the given `BroadcastChannel` to communicate instructions\n * with the client connections from other runtimes.\n */\nexport class WebSocketRemoteClientConnection\n implements WebSocketClientConnectionProtocol\n{\n constructor(\n public readonly id: string,\n public readonly url: URL,\n private channel: BroadcastChannel,\n ) {}\n\n send(data: WebSocketData): void {\n this.channel.postMessage({\n type: 'extraneous:send',\n payload: {\n clientId: this.id,\n data,\n },\n } as WebSocketBroadcastChannelMessage)\n }\n\n close(code?: number | undefined, reason?: string | undefined): void {\n this.channel.postMessage({\n type: 'extraneous:close',\n payload: {\n clientId: this.id,\n code,\n reason,\n },\n } as WebSocketBroadcastChannelMessage)\n }\n}\n"],"mappings":"AAMA,SAAS,kCAAkC;AAC3C,SAAS,qCAAqC;AAuBvC,MAAM,uBAAuB;AAAA,EAKlC,YAAoB,SAA2B;AAA3B;AAGlB,SAAK,QACH,OAAO,cAAc,cACjB,IAAI,8BAA8B,IAClC,IAAI,2BAA2B;AAErC,SAAK,iBAAiB,oBAAI,IAAI;AAC9B,SAAK,aAAa,oBAAI,IAAI;AAE1B,SAAK,QAAQ,iBAAiB,WAAW,CAAC,YAAY;AACpD,UA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,SAAK,eAAe,IAAI,OAAO,IAAI,MAAM;AAGzC,UAAM,KAAK,UAAU,MAAM;AAK3B,UAAM,0BAA0B,CAC9B,YACG;AACH,YAAM,EAAE,MAAM,QAAQ,IAAI,QAAQ;AAGlC,UACE,OAAO,YAAY,YACnB,cAAc,WACd,QAAQ,aAAa,OAAO,IAC5B;AACA;AAAA,MACF;AAEA,cAAQ,MAAM;AAAA,QACZ,KAAK,mBAAmB;AACtB,iBAAO,KAAK,QAAQ,IAAI;AACxB;AAAA,QACF;AAAA,QAEA,KAAK,oBAAoB;AACvB,iBAAO,MAAM,QAAQ,MAAM,QAAQ,MAAM;AACzC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,kBAAkB,IAAI,gBAAgB;AAE5C,SAAK,QAAQ,iBAAiB,WAAW,yBAAyB;AAAA,MAChE,QAAQ,gBAAgB;AAAA,IAC1B,CAAC;AAID,WAAO,iBAAiB,SAAS,MAAM,gBAAgB,MAAM,GAAG;AAAA,MAC9D,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AACF;AASO,MAAM,gCAEb;AAAA,EACE,YACkB,IACA,KACR,SACR;AAHgB;AACA;AACR;AAAA,EACP;AAAA,EAEH,KAAK,MAA2B;AAC9B,SAAK,QAAQ,YAAY;AAAA,MACvB,MAAM;AAAA,MACN,SAAS;AAAA,QACP,UAAU,KAAK;AAAA,QACf;AAAA,MACF;AAAA,IACF,CAAqC;AAAA,EACvC;AAAA,EAEA,MAAM,MAA2B,QAAmC;AAClE,SAAK,QAAQ,YAAY;AAAA,MACvB,MAAM;AAAA,MACN,SAAS;AAAA,QACP,UAAU,KAAK;AAAA,QACf;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAqC;AAAA,EACvC;AACF;","names":[]}
@@ -1,9 +1,9 @@
1
1
  import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket';
2
2
 
3
- type SerializedWebSocketClient = {
3
+ interface SerializedWebSocketClient {
4
4
  id: string;
5
5
  url: string;
6
- };
6
+ }
7
7
  declare abstract class WebSocketClientStore {
8
8
  abstract add(client: WebSocketClientConnectionProtocol): Promise<void>;
9
9
  abstract getAll(): Promise<Array<SerializedWebSocketClient>>;
@@ -1,9 +1,9 @@
1
1
  import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket';
2
2
 
3
- type SerializedWebSocketClient = {
3
+ interface SerializedWebSocketClient {
4
4
  id: string;
5
5
  url: string;
6
- };
6
+ }
7
7
  declare abstract class WebSocketClientStore {
8
8
  abstract add(client: WebSocketClientConnectionProtocol): Promise<void>;
9
9
  abstract getAll(): Promise<Array<SerializedWebSocketClient>>;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/ws/WebSocketClientStore.ts"],"sourcesContent":["import type { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\n\nexport type SerializedWebSocketClient = {\n id: string\n url: string\n}\n\nexport abstract class WebSocketClientStore {\n public abstract add(client: WebSocketClientConnectionProtocol): Promise<void>\n\n public abstract getAll(): Promise<Array<SerializedWebSocketClient>>\n\n public abstract deleteMany(clientIds: Array<string>): Promise<void>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,MAAe,qBAAqB;AAM3C;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/ws/WebSocketClientStore.ts"],"sourcesContent":["import type { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\n\nexport interface SerializedWebSocketClient {\n id: string\n url: string\n}\n\nexport abstract class WebSocketClientStore {\n public abstract add(client: WebSocketClientConnectionProtocol): Promise<void>\n\n public abstract getAll(): Promise<Array<SerializedWebSocketClient>>\n\n public abstract deleteMany(clientIds: Array<string>): Promise<void>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,MAAe,qBAAqB;AAM3C;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/ws/WebSocketClientStore.ts"],"sourcesContent":["import type { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\n\nexport type SerializedWebSocketClient = {\n id: string\n url: string\n}\n\nexport abstract class WebSocketClientStore {\n public abstract add(client: WebSocketClientConnectionProtocol): Promise<void>\n\n public abstract getAll(): Promise<Array<SerializedWebSocketClient>>\n\n public abstract deleteMany(clientIds: Array<string>): Promise<void>\n}\n"],"mappings":"AAOO,MAAe,qBAAqB;AAM3C;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/ws/WebSocketClientStore.ts"],"sourcesContent":["import type { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\n\nexport interface SerializedWebSocketClient {\n id: string\n url: string\n}\n\nexport abstract class WebSocketClientStore {\n public abstract add(client: WebSocketClientConnectionProtocol): Promise<void>\n\n public abstract getAll(): Promise<Array<SerializedWebSocketClient>>\n\n public abstract deleteMany(clientIds: Array<string>): Promise<void>\n}\n"],"mappings":"AAOO,MAAe,qBAAqB;AAM3C;","names":[]}
@@ -32,7 +32,7 @@ class WebSocketIndexedDBClientStore {
32
32
  async add(client) {
33
33
  const promise = new import_deferred_promise.DeferredPromise();
34
34
  const store = await this.getStore();
35
- const request = store.add({
35
+ const request = store.put({
36
36
  id: client.id,
37
37
  url: client.url.href
38
38
  });
@@ -40,7 +40,12 @@ class WebSocketIndexedDBClientStore {
40
40
  promise.resolve();
41
41
  };
42
42
  request.onerror = () => {
43
- promise.reject(new Error(`Failed to add WebSocket client ${client.id}`));
43
+ console.error(request.error);
44
+ promise.reject(
45
+ new Error(
46
+ `Failed to add WebSocket client "${client.id}". There is likely an additional output above.`
47
+ )
48
+ );
44
49
  };
45
50
  return promise;
46
51
  }
@@ -52,7 +57,12 @@ class WebSocketIndexedDBClientStore {
52
57
  promise.resolve(request.result);
53
58
  };
54
59
  request.onerror = () => {
55
- promise.reject(new Error(`Failed to get all WebSocket clients`));
60
+ console.log(request.error);
61
+ promise.reject(
62
+ new Error(
63
+ `Failed to get all WebSocket clients. There is likely an additional output above.`
64
+ )
65
+ );
56
66
  };
57
67
  return promise;
58
68
  }
@@ -66,9 +76,10 @@ class WebSocketIndexedDBClientStore {
66
76
  promise.resolve();
67
77
  };
68
78
  store.transaction.onerror = () => {
79
+ console.error(store.transaction.error);
69
80
  promise.reject(
70
81
  new Error(
71
- `Failed to delete WebSocket clients [${clientIds.join(", ")}]`
82
+ `Failed to delete WebSocket clients [${clientIds.join(", ")}]. There is likely an additional output above.`
72
83
  )
73
84
  );
74
85
  };
@@ -93,11 +104,21 @@ class WebSocketIndexedDBClientStore {
93
104
  promise.resolve(db);
94
105
  };
95
106
  store.transaction.onerror = () => {
96
- promise.reject(new Error("Failed to create WebSocket client store"));
107
+ console.error(store.transaction.error);
108
+ promise.reject(
109
+ new Error(
110
+ "Failed to create WebSocket client store. There is likely an additional output above."
111
+ )
112
+ );
97
113
  };
98
114
  };
99
115
  request.onerror = () => {
100
- promise.reject(new Error("Failed to open an IndexedDB database"));
116
+ console.error(request.error);
117
+ promise.reject(
118
+ new Error(
119
+ "Failed to open an IndexedDB database. There is likely an additional output above."
120
+ )
121
+ );
101
122
  };
102
123
  return promise;
103
124
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/ws/WebSocketIndexedDBClientStore.ts"],"sourcesContent":["import { DeferredPromise } from '@open-draft/deferred-promise'\nimport { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport {\n type SerializedWebSocketClient,\n WebSocketClientStore,\n} from './WebSocketClientStore'\n\nconst DB_NAME = 'msw-websocket-clients'\nconst DB_STORE_NAME = 'clients'\n\nexport class WebSocketIndexedDBClientStore implements WebSocketClientStore {\n private db: Promise<IDBDatabase>\n\n constructor() {\n this.db = this.createDatabase()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n const request = store.add({\n id: client.id,\n url: client.url.href,\n } satisfies SerializedWebSocketClient)\n\n request.onsuccess = () => {\n promise.resolve()\n }\n request.onerror = () => {\n promise.reject(new Error(`Failed to add WebSocket client ${client.id}`))\n }\n\n return promise\n }\n\n public async getAll(): Promise<Array<SerializedWebSocketClient>> {\n const promise = new DeferredPromise<Array<SerializedWebSocketClient>>()\n const store = await this.getStore()\n const request = store.getAll() as IDBRequest<\n Array<SerializedWebSocketClient>\n >\n\n request.onsuccess = () => {\n promise.resolve(request.result)\n }\n request.onerror = () => {\n promise.reject(new Error(`Failed to get all WebSocket clients`))\n }\n\n return promise\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n\n for (const clientId of clientIds) {\n store.delete(clientId)\n }\n\n store.transaction.oncomplete = () => {\n promise.resolve()\n }\n store.transaction.onerror = () => {\n promise.reject(\n new Error(\n `Failed to delete WebSocket clients [${clientIds.join(', ')}]`,\n ),\n )\n }\n\n return promise\n }\n\n private async createDatabase(): Promise<IDBDatabase> {\n const promise = new DeferredPromise<IDBDatabase>()\n const request = indexedDB.open(DB_NAME, 1)\n\n request.onsuccess = ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return promise.resolve(db)\n }\n }\n\n request.onupgradeneeded = async ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return\n }\n\n const store = db.createObjectStore(DB_STORE_NAME, { keyPath: 'id' })\n store.transaction.oncomplete = () => {\n promise.resolve(db)\n }\n store.transaction.onerror = () => {\n promise.reject(new Error('Failed to create WebSocket client store'))\n }\n }\n request.onerror = () => {\n promise.reject(new Error('Failed to open an IndexedDB database'))\n }\n\n return promise\n }\n\n private async getStore(): Promise<IDBObjectStore> {\n const db = await this.db\n return db.transaction(DB_STORE_NAME, 'readwrite').objectStore(DB_STORE_NAME)\n }\n}\n"],"mappings":";;;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ACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,iBAAuC;AACnD,UAAM,UAAU,IAAI,wCAA6B;AACjD,UAAM,UAAU,UAAU,KAAK,SAAS,CAAC;AAEzC,YAAQ,YAAY,CAAC,EAAE,cAAc,MAAM;AACzC,YAAM,KAAK,QAAQ,IAAI,eAAgB,QAAQ;AAE/C,UAAI,GAAG,iBAAiB,SAAS,aAAa,GAAG;AAC/C,eAAO,QAAQ,QAAQ,EAAE;AAAA,MAC3B;AAAA,IACF;AAEA,YAAQ,kBAAkB,OAAO,EAAE,cAAc,MAAM;AACrD,YAAM,KAAK,QAAQ,IAAI,eAAgB,QAAQ;AAC/C,UAAI,GAAG,iBAAiB,SAAS,aAAa,GAAG;AAC/C;AAAA,MACF;AAEA,YAAM,QAAQ,GAAG,kBAAkB,eAAe,EAAE,SAAS,KAAK,CAAC;AACnE,YAAM,YAAY,aAAa,MAAM;AACnC,gBAAQ,QAAQ,EAAE;AAAA,MACpB;AACA,YAAM,YAAY,UAAU,MAAM;AAChC,gBAAQ,OAAO,IAAI,MAAM,yCAAyC,CAAC;AAAA,MACrE;AAAA,IACF;AACA,YAAQ,UAAU,MAAM;AACtB,cAAQ,OAAO,IAAI,MAAM,sCAAsC,CAAC;AAAA,IAClE;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,WAAoC;AAChD,UAAM,KAAK,MAAM,KAAK;AACtB,WAAO,GAAG,YAAY,eAAe,WAAW,EAAE,YAAY,aAAa;AAAA,EAC7E;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/ws/WebSocketIndexedDBClientStore.ts"],"sourcesContent":["import { DeferredPromise } from '@open-draft/deferred-promise'\nimport { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport {\n type SerializedWebSocketClient,\n WebSocketClientStore,\n} from './WebSocketClientStore'\n\nconst DB_NAME = 'msw-websocket-clients'\nconst DB_STORE_NAME = 'clients'\n\nexport class WebSocketIndexedDBClientStore implements WebSocketClientStore {\n private db: Promise<IDBDatabase>\n\n constructor() {\n this.db = this.createDatabase()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n\n /**\n * @note Use `.put()` instead of `.add()` to allow setting clients\n * that already exist in the database. This can happen if a single page\n * has multiple event handlers. Each handler will receive the \"connection\"\n * event in parallel, and try to set that WebSocket client in the database.\n */\n const request = store.put({\n id: client.id,\n url: client.url.href,\n } satisfies SerializedWebSocketClient)\n\n request.onsuccess = () => {\n promise.resolve()\n }\n request.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(request.error)\n promise.reject(\n new Error(\n `Failed to add WebSocket client \"${client.id}\". There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n public async getAll(): Promise<Array<SerializedWebSocketClient>> {\n const promise = new DeferredPromise<Array<SerializedWebSocketClient>>()\n const store = await this.getStore()\n const request = store.getAll() as IDBRequest<\n Array<SerializedWebSocketClient>\n >\n\n request.onsuccess = () => {\n promise.resolve(request.result)\n }\n request.onerror = () => {\n // eslint-disable-next-line no-console\n console.log(request.error)\n promise.reject(\n new Error(\n `Failed to get all WebSocket clients. There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n\n for (const clientId of clientIds) {\n store.delete(clientId)\n }\n\n store.transaction.oncomplete = () => {\n promise.resolve()\n }\n store.transaction.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(store.transaction.error)\n promise.reject(\n new Error(\n `Failed to delete WebSocket clients [${clientIds.join(', ')}]. There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n private async createDatabase(): Promise<IDBDatabase> {\n const promise = new DeferredPromise<IDBDatabase>()\n const request = indexedDB.open(DB_NAME, 1)\n\n request.onsuccess = ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return promise.resolve(db)\n }\n }\n\n request.onupgradeneeded = async ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return\n }\n\n const store = db.createObjectStore(DB_STORE_NAME, { keyPath: 'id' })\n store.transaction.oncomplete = () => {\n promise.resolve(db)\n }\n store.transaction.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(store.transaction.error)\n promise.reject(\n new Error(\n 'Failed to create WebSocket client store. There is likely an additional output above.',\n ),\n )\n }\n }\n request.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(request.error)\n promise.reject(\n new Error(\n 'Failed to open an IndexedDB database. There is likely an additional output above.',\n ),\n )\n }\n\n return promise\n }\n\n private async getStore(): Promise<IDBObjectStore> {\n const db = await this.db\n return db.transaction(DB_STORE_NAME, 'readwrite').objectStore(DB_STORE_NAME)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAgC;AAOhC,MAAM,UAAU;AAChB,MAAM,gBAAgB;AAEf,MAAM,8BAA8D;AAAA,EACjE;AAAA,EAER,cAAc;AACZ,SAAK,KAAK,KAAK,eAAe;AAAA,EAChC;AAAA,EAEA,MAAa,IAAI,QAA0D;AACzE,UAAM,UAAU,IAAI,wCAAsB;AAC1C,UAAM,QAAQ,MAAM,KAAK,SAAS;AAQlC,UAAM,UAAU,MAAM,IAAI;AAAA,MACxB,IAAI,OAAO;AAAA,MACX,KAAK,OAAO,IAAI;AAAA,IAClB,CAAqC;AAErC,YAAQ,YAAY,MAAM;AACxB,cAAQ,QAAQ;AAAA,IAClB;AACA,YAAQ,UAAU,MAAM;AAEtB,cAAQ,MAAM,QAAQ,KAAK;AAC3B,cAAQ;AAAA,QACN,IAAI;AAAA,UACF,mCAAmC,OAAO,EAAE;AAAA,QAC9C;AAAA,MACF;A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AAa,GAAG;AAC/C;AAAA,MACF;AAEA,YAAM,QAAQ,GAAG,kBAAkB,eAAe,EAAE,SAAS,KAAK,CAAC;AACnE,YAAM,YAAY,aAAa,MAAM;AACnC,gBAAQ,QAAQ,EAAE;AAAA,MACpB;AACA,YAAM,YAAY,UAAU,MAAM;AAEhC,gBAAQ,MAAM,MAAM,YAAY,KAAK;AACrC,gBAAQ;AAAA,UACN,IAAI;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,YAAQ,UAAU,MAAM;AAEtB,cAAQ,MAAM,QAAQ,KAAK;AAC3B,cAAQ;AAAA,QACN,IAAI;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,WAAoC;AAChD,UAAM,KAAK,MAAM,KAAK;AACtB,WAAO,GAAG,YAAY,eAAe,WAAW,EAAE,YAAY,aAAa;AAAA,EAC7E;AACF;","names":[]}
@@ -9,7 +9,7 @@ class WebSocketIndexedDBClientStore {
9
9
  async add(client) {
10
10
  const promise = new DeferredPromise();
11
11
  const store = await this.getStore();
12
- const request = store.add({
12
+ const request = store.put({
13
13
  id: client.id,
14
14
  url: client.url.href
15
15
  });
@@ -17,7 +17,12 @@ class WebSocketIndexedDBClientStore {
17
17
  promise.resolve();
18
18
  };
19
19
  request.onerror = () => {
20
- promise.reject(new Error(`Failed to add WebSocket client ${client.id}`));
20
+ console.error(request.error);
21
+ promise.reject(
22
+ new Error(
23
+ `Failed to add WebSocket client "${client.id}". There is likely an additional output above.`
24
+ )
25
+ );
21
26
  };
22
27
  return promise;
23
28
  }
@@ -29,7 +34,12 @@ class WebSocketIndexedDBClientStore {
29
34
  promise.resolve(request.result);
30
35
  };
31
36
  request.onerror = () => {
32
- promise.reject(new Error(`Failed to get all WebSocket clients`));
37
+ console.log(request.error);
38
+ promise.reject(
39
+ new Error(
40
+ `Failed to get all WebSocket clients. There is likely an additional output above.`
41
+ )
42
+ );
33
43
  };
34
44
  return promise;
35
45
  }
@@ -43,9 +53,10 @@ class WebSocketIndexedDBClientStore {
43
53
  promise.resolve();
44
54
  };
45
55
  store.transaction.onerror = () => {
56
+ console.error(store.transaction.error);
46
57
  promise.reject(
47
58
  new Error(
48
- `Failed to delete WebSocket clients [${clientIds.join(", ")}]`
59
+ `Failed to delete WebSocket clients [${clientIds.join(", ")}]. There is likely an additional output above.`
49
60
  )
50
61
  );
51
62
  };
@@ -70,11 +81,21 @@ class WebSocketIndexedDBClientStore {
70
81
  promise.resolve(db);
71
82
  };
72
83
  store.transaction.onerror = () => {
73
- promise.reject(new Error("Failed to create WebSocket client store"));
84
+ console.error(store.transaction.error);
85
+ promise.reject(
86
+ new Error(
87
+ "Failed to create WebSocket client store. There is likely an additional output above."
88
+ )
89
+ );
74
90
  };
75
91
  };
76
92
  request.onerror = () => {
77
- promise.reject(new Error("Failed to open an IndexedDB database"));
93
+ console.error(request.error);
94
+ promise.reject(
95
+ new Error(
96
+ "Failed to open an IndexedDB database. There is likely an additional output above."
97
+ )
98
+ );
78
99
  };
79
100
  return promise;
80
101
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/ws/WebSocketIndexedDBClientStore.ts"],"sourcesContent":["import { DeferredPromise } from '@open-draft/deferred-promise'\nimport { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport {\n type SerializedWebSocketClient,\n WebSocketClientStore,\n} from './WebSocketClientStore'\n\nconst DB_NAME = 'msw-websocket-clients'\nconst DB_STORE_NAME = 'clients'\n\nexport class WebSocketIndexedDBClientStore implements WebSocketClientStore {\n private db: Promise<IDBDatabase>\n\n constructor() {\n this.db = this.createDatabase()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n const request = store.add({\n id: client.id,\n url: client.url.href,\n } satisfies SerializedWebSocketClient)\n\n request.onsuccess = () => {\n promise.resolve()\n }\n request.onerror = () => {\n promise.reject(new Error(`Failed to add WebSocket client ${client.id}`))\n }\n\n return promise\n }\n\n public async getAll(): Promise<Array<SerializedWebSocketClient>> {\n const promise = new DeferredPromise<Array<SerializedWebSocketClient>>()\n const store = await this.getStore()\n const request = store.getAll() as IDBRequest<\n Array<SerializedWebSocketClient>\n >\n\n request.onsuccess = () => {\n promise.resolve(request.result)\n }\n request.onerror = () => {\n promise.reject(new Error(`Failed to get all WebSocket clients`))\n }\n\n return promise\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n\n for (const clientId of clientIds) {\n store.delete(clientId)\n }\n\n store.transaction.oncomplete = () => {\n promise.resolve()\n }\n store.transaction.onerror = () => {\n promise.reject(\n new Error(\n `Failed to delete WebSocket clients [${clientIds.join(', ')}]`,\n ),\n )\n }\n\n return promise\n }\n\n private async createDatabase(): Promise<IDBDatabase> {\n const promise = new DeferredPromise<IDBDatabase>()\n const request = indexedDB.open(DB_NAME, 1)\n\n request.onsuccess = ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return promise.resolve(db)\n }\n }\n\n request.onupgradeneeded = async ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return\n }\n\n const store = db.createObjectStore(DB_STORE_NAME, { keyPath: 'id' })\n store.transaction.oncomplete = () => {\n promise.resolve(db)\n }\n store.transaction.onerror = () => {\n promise.reject(new Error('Failed to create WebSocket client store'))\n }\n }\n request.onerror = () => {\n promise.reject(new Error('Failed to open an IndexedDB database'))\n }\n\n return promise\n }\n\n private async getStore(): Promise<IDBObjectStore> {\n const db = await this.db\n return db.transaction(DB_STORE_NAME, 'readwrite').objectStore(DB_STORE_NAME)\n }\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAOhC,MAAM,UAAU;AACh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I,gBAA6B;AACjD,UAAM,UAAU,UAAU,KAAK,SAAS,CAAC;AAEzC,YAAQ,YAAY,CAAC,EAAE,cAAc,MAAM;AACzC,YAAM,KAAK,QAAQ,IAAI,eAAgB,QAAQ;AAE/C,UAAI,GAAG,iBAAiB,SAAS,aAAa,GAAG;AAC/C,eAAO,QAAQ,QAAQ,EAAE;AAAA,MAC3B;AAAA,IACF;AAEA,YAAQ,kBAAkB,OAAO,EAAE,cAAc,MAAM;AACrD,YAAM,KAAK,QAAQ,IAAI,eAAgB,QAAQ;AAC/C,UAAI,GAAG,iBAAiB,SAAS,aAAa,GAAG;AAC/C;AAAA,MACF;AAEA,YAAM,QAAQ,GAAG,kBAAkB,eAAe,EAAE,SAAS,KAAK,CAAC;AACnE,YAAM,YAAY,aAAa,MAAM;AACnC,gBAAQ,QAAQ,EAAE;AAAA,MACpB;AACA,YAAM,YAAY,UAAU,MAAM;AAChC,gBAAQ,OAAO,IAAI,MAAM,yCAAyC,CAAC;AAAA,MACrE;AAAA,IACF;AACA,YAAQ,UAAU,MAAM;AACtB,cAAQ,OAAO,IAAI,MAAM,sCAAsC,CAAC;AAAA,IAClE;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,WAAoC;AAChD,UAAM,KAAK,MAAM,KAAK;AACtB,WAAO,GAAG,YAAY,eAAe,WAAW,EAAE,YAAY,aAAa;AAAA,EAC7E;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/ws/WebSocketIndexedDBClientStore.ts"],"sourcesContent":["import { DeferredPromise } from '@open-draft/deferred-promise'\nimport { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport {\n type SerializedWebSocketClient,\n WebSocketClientStore,\n} from './WebSocketClientStore'\n\nconst DB_NAME = 'msw-websocket-clients'\nconst DB_STORE_NAME = 'clients'\n\nexport class WebSocketIndexedDBClientStore implements WebSocketClientStore {\n private db: Promise<IDBDatabase>\n\n constructor() {\n this.db = this.createDatabase()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n\n /**\n * @note Use `.put()` instead of `.add()` to allow setting clients\n * that already exist in the database. This can happen if a single page\n * has multiple event handlers. Each handler will receive the \"connection\"\n * event in parallel, and try to set that WebSocket client in the database.\n */\n const request = store.put({\n id: client.id,\n url: client.url.href,\n } satisfies SerializedWebSocketClient)\n\n request.onsuccess = () => {\n promise.resolve()\n }\n request.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(request.error)\n promise.reject(\n new Error(\n `Failed to add WebSocket client \"${client.id}\". There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n public async getAll(): Promise<Array<SerializedWebSocketClient>> {\n const promise = new DeferredPromise<Array<SerializedWebSocketClient>>()\n const store = await this.getStore()\n const request = store.getAll() as IDBRequest<\n Array<SerializedWebSocketClient>\n >\n\n request.onsuccess = () => {\n promise.resolve(request.result)\n }\n request.onerror = () => {\n // eslint-disable-next-line no-console\n console.log(request.error)\n promise.reject(\n new Error(\n `Failed to get all WebSocket clients. There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n\n for (const clientId of clientIds) {\n store.delete(clientId)\n }\n\n store.transaction.oncomplete = () => {\n promise.resolve()\n }\n store.transaction.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(store.transaction.error)\n promise.reject(\n new Error(\n `Failed to delete WebSocket clients [${clientIds.join(', ')}]. There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n private async createDatabase(): Promise<IDBDatabase> {\n const promise = new DeferredPromise<IDBDatabase>()\n const request = indexedDB.open(DB_NAME, 1)\n\n request.onsuccess = ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return promise.resolve(db)\n }\n }\n\n request.onupgradeneeded = async ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return\n }\n\n const store = db.createObjectStore(DB_STORE_NAME, { keyPath: 'id' })\n store.transaction.oncomplete = () => {\n promise.resolve(db)\n }\n store.transaction.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(store.transaction.error)\n promise.reject(\n new Error(\n 'Failed to create WebSocket client store. There is likely an additional output above.',\n ),\n )\n }\n }\n request.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(request.error)\n promise.reject(\n new Error(\n 'Failed to open an IndexedDB database. There is likely an additional output above.',\n ),\n )\n }\n\n return promise\n }\n\n private async getStore(): Promise<IDBObjectStore> {\n const db = await this.db\n return db.transaction(DB_STORE_NAME, 'readwrite').objectStore(DB_STORE_NAME)\n }\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAOhC,MAAM,UAAU;AAChB,MAAM,gBAAgB;AAEf,MAAM,8BAA8D;AAAA,EACjE;AAAA,EAER,cAAc;AACZ,SAAK,KAAK,KAAK,eAAe;AAAA,EAChC;AAAA,EAEA,MAAa,IAAI,QAA0D;AACzE,UAAM,UAAU,IAAI,gBAAsB;AAC1C,UAAM,QAAQ,MAAM,KAAK,SAAS;AAQlC,UAAM,UAAU,MAAM,IAAI;AAAA,MACxB,IAAI,OAAO;AAAA,MACX,KAAK,OAAO,IAAI;AAAA,IAClB,CAAqC;AAErC,YAAQ,YAAY,MAAM;AACxB,cAAQ,QAAQ;AAAA,IAClB;AACA,YAAQ,UAAU,MAAM;AAEtB,cAAQ,MAAM,QAAQ,KAAK;AAC3B,cAAQ;AAAA,QACN,IAAI;AAAA,UACF,mCAAmC,OAAO,EAAE;AAAA,QAC9C;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAa,SAAoD;AAC/D,UAAM,UAAU,IAAI,gBAAkD;AACtE,UAAM,QAAQ,MAAM,KAAK,SAAS;A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BAAQ,QAAQ,EAAE;AAAA,MACpB;AACA,YAAM,YAAY,UAAU,MAAM;AAEhC,gBAAQ,MAAM,MAAM,YAAY,KAAK;AACrC,gBAAQ;AAAA,UACN,IAAI;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,YAAQ,UAAU,MAAM;AAEtB,cAAQ,MAAM,QAAQ,KAAK;AAC3B,cAAQ;AAAA,QACN,IAAI;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,WAAoC;AAChD,UAAM,KAAK,MAAM,KAAK;AACtB,WAAO,GAAG,YAAY,eAAe,WAAW,EAAE,YAAY,aAAa;AAAA,EAC7E;AACF;","names":[]}
@@ -1,6 +1,7 @@
1
1
  import { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket';
2
2
  import { R as RequestHandler } from '../HttpResponse-DYXrZpqR.mjs';
3
3
  import { WebSocketHandler } from '../handlers/WebSocketHandler.mjs';
4
+ import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.mjs';
4
5
  import '../utils/internal/isIterable.mjs';
5
6
  import '../typeUtils.mjs';
6
7
  import 'strict-event-emitter';
@@ -8,6 +9,7 @@ import '@mswjs/interceptors/WebSocket';
8
9
  import '../utils/matching/matchRequestUrl.mjs';
9
10
 
10
11
  interface HandleWebSocketEventOptions {
12
+ getUnhandledRequestStrategy: () => UnhandledRequestStrategy;
11
13
  getHandlers: () => Array<RequestHandler | WebSocketHandler>;
12
14
  onMockedConnection: (connection: WebSocketConnectionData) => void;
13
15
  onPassthroughConnection: (onnection: WebSocketConnectionData) => void;