msw 2.13.3 → 2.13.4

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 (216) hide show
  1. package/cli/init.js +1 -1
  2. package/lib/browser/index.js +200 -56
  3. package/lib/browser/index.js.map +1 -1
  4. package/lib/browser/index.mjs +200 -56
  5. package/lib/browser/index.mjs.map +1 -1
  6. package/lib/core/{HttpResponse-DlRR1D-f.d.mts → HttpResponse-BF4NGRsf.d.mts} +1 -1
  7. package/lib/core/{HttpResponse-CksOMVAa.d.ts → HttpResponse-yukpQS4a.d.ts} +1 -1
  8. package/lib/core/HttpResponse.d.mts +1 -1
  9. package/lib/core/HttpResponse.d.ts +1 -1
  10. package/lib/core/experimental/compat.d.mts +2 -2
  11. package/lib/core/experimental/compat.d.ts +2 -2
  12. package/lib/core/experimental/compat.js +1 -0
  13. package/lib/core/experimental/compat.js.map +1 -1
  14. package/lib/core/experimental/compat.mjs +1 -0
  15. package/lib/core/experimental/compat.mjs.map +1 -1
  16. package/lib/core/experimental/define-network.d.mts +2 -2
  17. package/lib/core/experimental/define-network.d.ts +2 -2
  18. package/lib/core/experimental/define-network.js +4 -0
  19. package/lib/core/experimental/define-network.js.map +1 -1
  20. package/lib/core/experimental/define-network.mjs +6 -0
  21. package/lib/core/experimental/define-network.mjs.map +1 -1
  22. package/lib/core/experimental/frames/http-frame.d.mts +2 -2
  23. package/lib/core/experimental/frames/http-frame.d.ts +2 -2
  24. package/lib/core/experimental/frames/http-frame.js +2 -0
  25. package/lib/core/experimental/frames/http-frame.js.map +1 -1
  26. package/lib/core/experimental/frames/http-frame.mjs +5 -1
  27. package/lib/core/experimental/frames/http-frame.mjs.map +1 -1
  28. package/lib/core/experimental/frames/network-frame.d.mts +2 -2
  29. package/lib/core/experimental/frames/network-frame.d.ts +2 -2
  30. package/lib/core/experimental/frames/websocket-frame.d.mts +2 -2
  31. package/lib/core/experimental/frames/websocket-frame.d.ts +2 -2
  32. package/lib/core/experimental/frames/websocket-frame.js +2 -0
  33. package/lib/core/experimental/frames/websocket-frame.js.map +1 -1
  34. package/lib/core/experimental/frames/websocket-frame.mjs +2 -0
  35. package/lib/core/experimental/frames/websocket-frame.mjs.map +1 -1
  36. package/lib/core/experimental/handlers-controller.d.mts +1 -1
  37. package/lib/core/experimental/handlers-controller.d.ts +1 -1
  38. package/lib/core/experimental/handlers-controller.js +3 -1
  39. package/lib/core/experimental/handlers-controller.js.map +1 -1
  40. package/lib/core/experimental/handlers-controller.mjs +3 -1
  41. package/lib/core/experimental/handlers-controller.mjs.map +1 -1
  42. package/lib/core/experimental/index.d.mts +2 -2
  43. package/lib/core/experimental/index.d.ts +2 -2
  44. package/lib/core/experimental/index.js +0 -1
  45. package/lib/core/experimental/index.js.map +1 -1
  46. package/lib/core/experimental/index.mjs +1 -2
  47. package/lib/core/experimental/index.mjs.map +1 -1
  48. package/lib/core/experimental/on-unhandled-frame.d.mts +2 -2
  49. package/lib/core/experimental/on-unhandled-frame.d.ts +2 -2
  50. package/lib/core/experimental/on-unhandled-frame.js +1 -0
  51. package/lib/core/experimental/on-unhandled-frame.js.map +1 -1
  52. package/lib/core/experimental/on-unhandled-frame.mjs +1 -0
  53. package/lib/core/experimental/on-unhandled-frame.mjs.map +1 -1
  54. package/lib/core/experimental/setup-api.d.mts +1 -1
  55. package/lib/core/experimental/setup-api.d.ts +1 -1
  56. package/lib/core/experimental/setup-api.js +1 -0
  57. package/lib/core/experimental/setup-api.js.map +1 -1
  58. package/lib/core/experimental/setup-api.mjs +1 -0
  59. package/lib/core/experimental/setup-api.mjs.map +1 -1
  60. package/lib/core/experimental/sources/interceptor-source.d.mts +2 -2
  61. package/lib/core/experimental/sources/interceptor-source.d.ts +2 -2
  62. package/lib/core/experimental/sources/interceptor-source.js.map +1 -1
  63. package/lib/core/experimental/sources/interceptor-source.mjs +1 -3
  64. package/lib/core/experimental/sources/interceptor-source.mjs.map +1 -1
  65. package/lib/core/experimental/sources/network-source.d.mts +2 -2
  66. package/lib/core/experimental/sources/network-source.d.ts +2 -2
  67. package/lib/core/experimental/sources/network-source.js +1 -0
  68. package/lib/core/experimental/sources/network-source.js.map +1 -1
  69. package/lib/core/experimental/sources/network-source.mjs +2 -0
  70. package/lib/core/experimental/sources/network-source.mjs.map +1 -1
  71. package/lib/core/getResponse.d.mts +1 -1
  72. package/lib/core/getResponse.d.ts +1 -1
  73. package/lib/core/graphql.d.mts +1 -1
  74. package/lib/core/graphql.d.ts +1 -1
  75. package/lib/core/graphql.js +1 -0
  76. package/lib/core/graphql.js.map +1 -1
  77. package/lib/core/graphql.mjs +2 -0
  78. package/lib/core/graphql.mjs.map +1 -1
  79. package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
  80. package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
  81. package/lib/core/handlers/GraphQLHandler.js +1 -0
  82. package/lib/core/handlers/GraphQLHandler.js.map +1 -1
  83. package/lib/core/handlers/GraphQLHandler.mjs +4 -1
  84. package/lib/core/handlers/GraphQLHandler.mjs.map +1 -1
  85. package/lib/core/handlers/HttpHandler.d.mts +1 -1
  86. package/lib/core/handlers/HttpHandler.d.ts +1 -1
  87. package/lib/core/handlers/HttpHandler.js +1 -0
  88. package/lib/core/handlers/HttpHandler.js.map +1 -1
  89. package/lib/core/handlers/HttpHandler.mjs +1 -0
  90. package/lib/core/handlers/HttpHandler.mjs.map +1 -1
  91. package/lib/core/handlers/RequestHandler.d.mts +1 -1
  92. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  93. package/lib/core/handlers/RequestHandler.js +1 -0
  94. package/lib/core/handlers/RequestHandler.js.map +1 -1
  95. package/lib/core/handlers/RequestHandler.mjs +2 -0
  96. package/lib/core/handlers/RequestHandler.mjs.map +1 -1
  97. package/lib/core/http.d.mts +1 -1
  98. package/lib/core/http.d.ts +1 -1
  99. package/lib/core/http.js +1 -0
  100. package/lib/core/http.js.map +1 -1
  101. package/lib/core/http.mjs +2 -0
  102. package/lib/core/http.mjs.map +1 -1
  103. package/lib/core/index.d.mts +1 -1
  104. package/lib/core/index.d.ts +1 -1
  105. package/lib/core/passthrough.d.mts +1 -1
  106. package/lib/core/passthrough.d.ts +1 -1
  107. package/lib/core/sse.d.mts +4 -18
  108. package/lib/core/sse.d.ts +4 -18
  109. package/lib/core/sse.js +105 -45
  110. package/lib/core/sse.js.map +1 -1
  111. package/lib/core/sse.mjs +105 -45
  112. package/lib/core/sse.mjs.map +1 -1
  113. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  114. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  115. package/lib/core/utils/cookieStore.js.map +1 -1
  116. package/lib/core/utils/cookieStore.mjs.map +1 -1
  117. package/lib/core/utils/executeHandlers.d.mts +1 -1
  118. package/lib/core/utils/executeHandlers.d.ts +1 -1
  119. package/lib/core/utils/executeHandlers.js +1 -0
  120. package/lib/core/utils/executeHandlers.js.map +1 -1
  121. package/lib/core/utils/executeHandlers.mjs +1 -0
  122. package/lib/core/utils/executeHandlers.mjs.map +1 -1
  123. package/lib/core/utils/handleRequest.d.mts +1 -1
  124. package/lib/core/utils/handleRequest.d.ts +1 -1
  125. package/lib/core/utils/handleRequest.js.map +1 -1
  126. package/lib/core/utils/handleRequest.mjs.map +1 -1
  127. package/lib/core/utils/internal/isHandlerKind.d.mts +1 -1
  128. package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
  129. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
  130. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
  131. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  132. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  133. package/lib/core/utils/internal/parseMultipartData.js +1 -0
  134. package/lib/core/utils/internal/parseMultipartData.js.map +1 -1
  135. package/lib/core/utils/internal/parseMultipartData.mjs +1 -0
  136. package/lib/core/utils/internal/parseMultipartData.mjs.map +1 -1
  137. package/lib/core/utils/internal/pipeEvents.js +1 -0
  138. package/lib/core/utils/internal/pipeEvents.js.map +1 -1
  139. package/lib/core/utils/internal/pipeEvents.mjs +1 -0
  140. package/lib/core/utils/internal/pipeEvents.mjs.map +1 -1
  141. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  142. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  143. package/lib/core/utils/internal/requestHandlerUtils.js.map +1 -1
  144. package/lib/core/utils/internal/requestHandlerUtils.mjs.map +1 -1
  145. package/lib/core/ws/WebSocketClientManager.js.map +1 -1
  146. package/lib/core/ws/WebSocketClientManager.mjs.map +1 -1
  147. package/lib/core/ws/WebSocketIndexedDBClientStore.js +1 -0
  148. package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -1
  149. package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +1 -0
  150. package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -1
  151. package/lib/core/ws/WebSocketMemoryClientStore.js +1 -0
  152. package/lib/core/ws/WebSocketMemoryClientStore.js.map +1 -1
  153. package/lib/core/ws/WebSocketMemoryClientStore.mjs +1 -0
  154. package/lib/core/ws/WebSocketMemoryClientStore.mjs.map +1 -1
  155. package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
  156. package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
  157. package/lib/core/ws/handleWebSocketEvent.js.map +1 -1
  158. package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -1
  159. package/lib/core/ws.js.map +1 -1
  160. package/lib/core/ws.mjs.map +1 -1
  161. package/lib/iife/index.js +6300 -6076
  162. package/lib/iife/index.js.map +1 -1
  163. package/lib/mockServiceWorker.js +1 -1
  164. package/lib/native/index.js.map +1 -1
  165. package/lib/native/index.mjs.map +1 -1
  166. package/lib/node/index.js.map +1 -1
  167. package/lib/node/index.mjs.map +1 -1
  168. package/lib/shims/cookie.js +152 -62
  169. package/lib/shims/cookie.mjs +152 -62
  170. package/package.json +33 -40
  171. package/src/browser/glossary.ts +1 -1
  172. package/src/browser/setup-worker.ts +2 -2
  173. package/src/browser/sources/service-worker-source.ts +125 -28
  174. package/src/browser/utils/deserializeRequest.ts +0 -1
  175. package/src/browser/utils/should-invalidate-worker.test.ts +122 -0
  176. package/src/browser/utils/should-invalidate-worker.ts +13 -0
  177. package/src/browser/utils/workerChannel.ts +43 -21
  178. package/src/core/experimental/define-network.ts +10 -2
  179. package/src/core/experimental/frames/http-frame.test.ts +2 -1
  180. package/src/core/experimental/frames/http-frame.ts +6 -2
  181. package/src/core/experimental/frames/websocket-frame.test.ts +2 -4
  182. package/src/core/experimental/frames/websocket-frame.ts +3 -2
  183. package/src/core/experimental/handlers-controller.ts +1 -1
  184. package/src/core/experimental/index.ts +1 -1
  185. package/src/core/experimental/on-unhandled-frame.test.ts +2 -4
  186. package/src/core/experimental/setup-api.ts +3 -3
  187. package/src/core/experimental/sources/interceptor-source.ts +2 -6
  188. package/src/core/graphql.ts +8 -8
  189. package/src/core/handlers/GraphQLHandler.test.ts +3 -4
  190. package/src/core/handlers/GraphQLHandler.ts +15 -11
  191. package/src/core/handlers/HttpHandler.test.ts +3 -2
  192. package/src/core/handlers/HttpHandler.ts +7 -7
  193. package/src/core/handlers/RequestHandler.ts +5 -5
  194. package/src/core/http.ts +5 -5
  195. package/src/core/sse.ts +157 -56
  196. package/src/core/utils/cookieStore.ts +1 -1
  197. package/src/core/utils/executeHandlers.ts +2 -4
  198. package/src/core/utils/handleRequest.test.ts +5 -4
  199. package/src/core/utils/handleRequest.ts +3 -3
  200. package/src/core/utils/internal/parseGraphQLRequest.test.ts +2 -4
  201. package/src/core/utils/internal/parseMultipartData.ts +1 -1
  202. package/src/core/utils/internal/pipeEvents.ts +2 -1
  203. package/src/core/utils/internal/requestHandlerUtils.ts +1 -1
  204. package/src/core/utils/request/onUnhandledRequest.test.ts +2 -4
  205. package/src/core/ws/WebSocketClientManager.test.ts +2 -4
  206. package/src/core/ws/WebSocketClientManager.ts +1 -1
  207. package/src/core/ws/WebSocketIndexedDBClientStore.ts +3 -5
  208. package/src/core/ws/WebSocketMemoryClientStore.ts +3 -5
  209. package/src/core/ws/handleWebSocketEvent.ts +3 -3
  210. package/src/core/ws.ts +1 -1
  211. package/src/native/index.ts +2 -2
  212. package/src/node/async-handlers-controller.ts +2 -2
  213. package/src/node/setup-server-common.ts +4 -4
  214. package/src/node/setup-server.ts +2 -2
  215. package/lib/core/{network-frame-usYiHS0K.d.ts → on-unhandled-frame-BBR-P3kV.d.ts} +12 -12
  216. package/lib/core/{network-frame-B7A0ggXE.d.mts → on-unhandled-frame-Cr1KOZ0I.d.mts} +12 -12
@@ -21,6 +21,7 @@ __export(WebSocketMemoryClientStore_exports, {
21
21
  WebSocketMemoryClientStore: () => WebSocketMemoryClientStore
22
22
  });
23
23
  module.exports = __toCommonJS(WebSocketMemoryClientStore_exports);
24
+ var import_WebSocketClientStore = require("./WebSocketClientStore");
24
25
  class WebSocketMemoryClientStore {
25
26
  store;
26
27
  constructor() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/ws/WebSocketMemoryClientStore.ts"],"sourcesContent":["import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\nimport {\n SerializedWebSocketClient,\n WebSocketClientStore,\n} from './WebSocketClientStore'\n\nexport class WebSocketMemoryClientStore implements WebSocketClientStore {\n private store: Map<string, SerializedWebSocketClient>\n\n constructor() {\n this.store = new Map()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n this.store.set(client.id, { id: client.id, url: client.url.href })\n }\n\n public getAll(): Promise<Array<SerializedWebSocketClient>> {\n return Promise.resolve(Array.from(this.store.values()))\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n for (const clientId of clientIds) {\n this.store.delete(clientId)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,MAAM,2BAA2D;AAAA,EAC9D;AAAA,EAER,cAAc;AACZ,SAAK,QAAQ,oBAAI,IAAI;AAAA,EACvB;AAAA,EAEA,MAAa,IAAI,QAA0D;AACzE,SAAK,MAAM,IAAI,OAAO,IAAI,EAAE,IAAI,OAAO,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC;AAAA,EACnE;AAAA,EAEO,SAAoD;AACzD,WAAO,QAAQ,QAAQ,MAAM,KAAK,KAAK,MAAM,OAAO,CAAC,CAAC;AAAA,EACxD;AAAA,EAEA,MAAa,WAAW,WAAyC;AAC/D,eAAW,YAAY,WAAW;AAChC,WAAK,MAAM,OAAO,QAAQ;AAAA,IAC5B;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/ws/WebSocketMemoryClientStore.ts"],"sourcesContent":["import type { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\nimport type { WebSocketClientStore } from './WebSocketClientStore'\nimport { type SerializedWebSocketClient } from './WebSocketClientStore'\n\nexport class WebSocketMemoryClientStore implements WebSocketClientStore {\n private store: Map<string, SerializedWebSocketClient>\n\n constructor() {\n this.store = new Map()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n this.store.set(client.id, { id: client.id, url: client.url.href })\n }\n\n public getAll(): Promise<Array<SerializedWebSocketClient>> {\n return Promise.resolve(Array.from(this.store.values()))\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n for (const clientId of clientIds) {\n this.store.delete(clientId)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kCAA+C;AAExC,MAAM,2BAA2D;AAAA,EAC9D;AAAA,EAER,cAAc;AACZ,SAAK,QAAQ,oBAAI,IAAI;AAAA,EACvB;AAAA,EAEA,MAAa,IAAI,QAA0D;AACzE,SAAK,MAAM,IAAI,OAAO,IAAI,EAAE,IAAI,OAAO,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC;AAAA,EACnE;AAAA,EAEO,SAAoD;AACzD,WAAO,QAAQ,QAAQ,MAAM,KAAK,KAAK,MAAM,OAAO,CAAC,CAAC;AAAA,EACxD;AAAA,EAEA,MAAa,WAAW,WAAyC;AAC/D,eAAW,YAAY,WAAW;AAChC,WAAK,MAAM,OAAO,QAAQ;AAAA,IAC5B;AAAA,EACF;AACF;","names":[]}
@@ -1,3 +1,4 @@
1
+ import {} from './WebSocketClientStore.mjs';
1
2
  class WebSocketMemoryClientStore {
2
3
  store;
3
4
  constructor() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/ws/WebSocketMemoryClientStore.ts"],"sourcesContent":["import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\nimport {\n SerializedWebSocketClient,\n WebSocketClientStore,\n} from './WebSocketClientStore'\n\nexport class WebSocketMemoryClientStore implements WebSocketClientStore {\n private store: Map<string, SerializedWebSocketClient>\n\n constructor() {\n this.store = new Map()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n this.store.set(client.id, { id: client.id, url: client.url.href })\n }\n\n public getAll(): Promise<Array<SerializedWebSocketClient>> {\n return Promise.resolve(Array.from(this.store.values()))\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n for (const clientId of clientIds) {\n this.store.delete(clientId)\n }\n }\n}\n"],"mappings":"AAMO,MAAM,2BAA2D;AAAA,EAC9D;AAAA,EAER,cAAc;AACZ,SAAK,QAAQ,oBAAI,IAAI;AAAA,EACvB;AAAA,EAEA,MAAa,IAAI,QAA0D;AACzE,SAAK,MAAM,IAAI,OAAO,IAAI,EAAE,IAAI,OAAO,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC;AAAA,EACnE;AAAA,EAEO,SAAoD;AACzD,WAAO,QAAQ,QAAQ,MAAM,KAAK,KAAK,MAAM,OAAO,CAAC,CAAC;AAAA,EACxD;AAAA,EAEA,MAAa,WAAW,WAAyC;AAC/D,eAAW,YAAY,WAAW;AAChC,WAAK,MAAM,OAAO,QAAQ;AAAA,IAC5B;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/ws/WebSocketMemoryClientStore.ts"],"sourcesContent":["import type { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\nimport type { WebSocketClientStore } from './WebSocketClientStore'\nimport { type SerializedWebSocketClient } from './WebSocketClientStore'\n\nexport class WebSocketMemoryClientStore implements WebSocketClientStore {\n private store: Map<string, SerializedWebSocketClient>\n\n constructor() {\n this.store = new Map()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n this.store.set(client.id, { id: client.id, url: client.url.href })\n }\n\n public getAll(): Promise<Array<SerializedWebSocketClient>> {\n return Promise.resolve(Array.from(this.store.values()))\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n for (const clientId of clientIds) {\n this.store.delete(clientId)\n }\n }\n}\n"],"mappings":"AAEA,eAA+C;AAExC,MAAM,2BAA2D;AAAA,EAC9D;AAAA,EAER,cAAc;AACZ,SAAK,QAAQ,oBAAI,IAAI;AAAA,EACvB;AAAA,EAEA,MAAa,IAAI,QAA0D;AACzE,SAAK,MAAM,IAAI,OAAO,IAAI,EAAE,IAAI,OAAO,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC;AAAA,EACnE;AAAA,EAEO,SAAoD;AACzD,WAAO,QAAQ,QAAQ,MAAM,KAAK,KAAK,MAAM,OAAO,CAAC,CAAC;AAAA,EACxD;AAAA,EAEA,MAAa,WAAW,WAAyC;AAC/D,eAAW,YAAY,WAAW;AAChC,WAAK,MAAM,OAAO,QAAQ;AAAA,IAC5B;AAAA,EACF;AACF;","names":[]}
@@ -1,5 +1,5 @@
1
1
  import { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket';
2
- import { R as RequestHandler } from '../HttpResponse-DlRR1D-f.mjs';
2
+ import { R as RequestHandler } from '../HttpResponse-BF4NGRsf.mjs';
3
3
  import { WebSocketHandler } from '../handlers/WebSocketHandler.mjs';
4
4
  import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.mjs';
5
5
  import '@mswjs/interceptors';
@@ -1,5 +1,5 @@
1
1
  import { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket';
2
- import { R as RequestHandler } from '../HttpResponse-CksOMVAa.js';
2
+ import { R as RequestHandler } from '../HttpResponse-yukpQS4a.js';
3
3
  import { WebSocketHandler } from '../handlers/WebSocketHandler.js';
4
4
  import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.js';
5
5
  import '@mswjs/interceptors';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/ws/handleWebSocketEvent.ts"],"sourcesContent":["import type { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket'\nimport { RequestHandler } from '../handlers/RequestHandler'\nimport { WebSocketHandler } from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from './webSocketInterceptor'\nimport {\n onUnhandledRequest,\n UnhandledRequestStrategy,\n} from '../utils/request/onUnhandledRequest'\nimport { isHandlerKind } from '../utils/internal/isHandlerKind'\n\ninterface HandleWebSocketEventOptions {\n getUnhandledRequestStrategy: () => UnhandledRequestStrategy\n getHandlers: () => Array<RequestHandler | WebSocketHandler>\n onMockedConnection: (connection: WebSocketConnectionData) => void\n onPassthroughConnection: (onnection: WebSocketConnectionData) => void\n}\n\nexport function handleWebSocketEvent(options: HandleWebSocketEventOptions) {\n webSocketInterceptor.on('connection', async (connection) => {\n /**\n * @todo @fixme Reference the handlers controller here and use `.getHandlersByKind`.\n * That one relies on the pre-grouped handlers map and will be more performant.\n */\n const handlers = options.getHandlers().filter(isHandlerKind('websocket'))\n\n // Ignore this connection if the user hasn't defined any handlers.\n if (handlers.length > 0) {\n options?.onMockedConnection(connection)\n\n await Promise.all(\n handlers.map((handler) => {\n // Iterate over the handlers and forward the connection\n // event to WebSocket event handlers. This is equivalent\n // to dispatching that event onto multiple listeners.\n return handler.run(connection)\n }),\n )\n\n return\n }\n\n // Construct a request representing this WebSocket connection.\n const request = new Request(connection.client.url, {\n headers: {\n upgrade: 'websocket',\n connection: 'upgrade',\n },\n })\n await onUnhandledRequest(\n request,\n options.getUnhandledRequestStrategy(),\n ).catch((error) => {\n const errorEvent = new Event('error')\n Object.defineProperty(errorEvent, 'cause', {\n enumerable: true,\n configurable: false,\n value: error,\n })\n connection.client.socket.dispatchEvent(errorEvent)\n })\n\n options?.onPassthroughConnection(connection)\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n connection.server.connect()\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kCAAqC;AACrC,gCAGO;AACP,2BAA8B;AASvB,SAAS,qBAAqB,SAAsC;AACzE,mDAAqB,GAAG,cAAc,OAAO,eAAe;AAK1D,UAAM,WAAW,QAAQ,YAAY,EAAE,WAAO,oCAAc,WAAW,CAAC;AAGxE,QAAI,SAAS,SAAS,GAAG;AACvB,eAAS,mBAAmB,UAAU;AAEtC,YAAM,QAAQ;AAAA,QACZ,SAAS,IAAI,CAAC,YAAY;AAIxB,iBAAO,QAAQ,IAAI,UAAU;AAAA,QAC/B,CAAC;AAAA,MACH;AAEA;AAAA,IACF;AAGA,UAAM,UAAU,IAAI,QAAQ,WAAW,OAAO,KAAK;AAAA,MACjD,SAAS;AAAA,QACP,SAAS;AAAA,QACT,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AACD,cAAM;AAAA,MACJ;AAAA,MACA,QAAQ,4BAA4B;AAAA,IACtC,EAAE,MAAM,CAAC,UAAU;AACjB,YAAM,aAAa,IAAI,MAAM,OAAO;AACpC,aAAO,eAAe,YAAY,SAAS;AAAA,QACzC,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,OAAO;AAAA,MACT,CAAC;AACD,iBAAW,OAAO,OAAO,cAAc,UAAU;AAAA,IACnD,CAAC;AAED,aAAS,wBAAwB,UAAU;AAI3C,eAAW,OAAO,QAAQ;AAAA,EAC5B,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/ws/handleWebSocketEvent.ts"],"sourcesContent":["import type { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket'\nimport type { RequestHandler } from '../handlers/RequestHandler'\nimport type { WebSocketHandler } from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from './webSocketInterceptor'\nimport {\n onUnhandledRequest,\n type UnhandledRequestStrategy,\n} from '../utils/request/onUnhandledRequest'\nimport { isHandlerKind } from '../utils/internal/isHandlerKind'\n\ninterface HandleWebSocketEventOptions {\n getUnhandledRequestStrategy: () => UnhandledRequestStrategy\n getHandlers: () => Array<RequestHandler | WebSocketHandler>\n onMockedConnection: (connection: WebSocketConnectionData) => void\n onPassthroughConnection: (onnection: WebSocketConnectionData) => void\n}\n\nexport function handleWebSocketEvent(options: HandleWebSocketEventOptions) {\n webSocketInterceptor.on('connection', async (connection) => {\n /**\n * @todo @fixme Reference the handlers controller here and use `.getHandlersByKind`.\n * That one relies on the pre-grouped handlers map and will be more performant.\n */\n const handlers = options.getHandlers().filter(isHandlerKind('websocket'))\n\n // Ignore this connection if the user hasn't defined any handlers.\n if (handlers.length > 0) {\n options?.onMockedConnection(connection)\n\n await Promise.all(\n handlers.map((handler) => {\n // Iterate over the handlers and forward the connection\n // event to WebSocket event handlers. This is equivalent\n // to dispatching that event onto multiple listeners.\n return handler.run(connection)\n }),\n )\n\n return\n }\n\n // Construct a request representing this WebSocket connection.\n const request = new Request(connection.client.url, {\n headers: {\n upgrade: 'websocket',\n connection: 'upgrade',\n },\n })\n await onUnhandledRequest(\n request,\n options.getUnhandledRequestStrategy(),\n ).catch((error) => {\n const errorEvent = new Event('error')\n Object.defineProperty(errorEvent, 'cause', {\n enumerable: true,\n configurable: false,\n value: error,\n })\n connection.client.socket.dispatchEvent(errorEvent)\n })\n\n options?.onPassthroughConnection(connection)\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n connection.server.connect()\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kCAAqC;AACrC,gCAGO;AACP,2BAA8B;AASvB,SAAS,qBAAqB,SAAsC;AACzE,mDAAqB,GAAG,cAAc,OAAO,eAAe;AAK1D,UAAM,WAAW,QAAQ,YAAY,EAAE,WAAO,oCAAc,WAAW,CAAC;AAGxE,QAAI,SAAS,SAAS,GAAG;AACvB,eAAS,mBAAmB,UAAU;AAEtC,YAAM,QAAQ;AAAA,QACZ,SAAS,IAAI,CAAC,YAAY;AAIxB,iBAAO,QAAQ,IAAI,UAAU;AAAA,QAC/B,CAAC;AAAA,MACH;AAEA;AAAA,IACF;AAGA,UAAM,UAAU,IAAI,QAAQ,WAAW,OAAO,KAAK;AAAA,MACjD,SAAS;AAAA,QACP,SAAS;AAAA,QACT,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AACD,cAAM;AAAA,MACJ;AAAA,MACA,QAAQ,4BAA4B;AAAA,IACtC,EAAE,MAAM,CAAC,UAAU;AACjB,YAAM,aAAa,IAAI,MAAM,OAAO;AACpC,aAAO,eAAe,YAAY,SAAS;AAAA,QACzC,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,OAAO;AAAA,MACT,CAAC;AACD,iBAAW,OAAO,OAAO,cAAc,UAAU;AAAA,IACnD,CAAC;AAED,aAAS,wBAAwB,UAAU;AAI3C,eAAW,OAAO,QAAQ;AAAA,EAC5B,CAAC;AACH;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/ws/handleWebSocketEvent.ts"],"sourcesContent":["import type { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket'\nimport { RequestHandler } from '../handlers/RequestHandler'\nimport { WebSocketHandler } from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from './webSocketInterceptor'\nimport {\n onUnhandledRequest,\n UnhandledRequestStrategy,\n} from '../utils/request/onUnhandledRequest'\nimport { isHandlerKind } from '../utils/internal/isHandlerKind'\n\ninterface HandleWebSocketEventOptions {\n getUnhandledRequestStrategy: () => UnhandledRequestStrategy\n getHandlers: () => Array<RequestHandler | WebSocketHandler>\n onMockedConnection: (connection: WebSocketConnectionData) => void\n onPassthroughConnection: (onnection: WebSocketConnectionData) => void\n}\n\nexport function handleWebSocketEvent(options: HandleWebSocketEventOptions) {\n webSocketInterceptor.on('connection', async (connection) => {\n /**\n * @todo @fixme Reference the handlers controller here and use `.getHandlersByKind`.\n * That one relies on the pre-grouped handlers map and will be more performant.\n */\n const handlers = options.getHandlers().filter(isHandlerKind('websocket'))\n\n // Ignore this connection if the user hasn't defined any handlers.\n if (handlers.length > 0) {\n options?.onMockedConnection(connection)\n\n await Promise.all(\n handlers.map((handler) => {\n // Iterate over the handlers and forward the connection\n // event to WebSocket event handlers. This is equivalent\n // to dispatching that event onto multiple listeners.\n return handler.run(connection)\n }),\n )\n\n return\n }\n\n // Construct a request representing this WebSocket connection.\n const request = new Request(connection.client.url, {\n headers: {\n upgrade: 'websocket',\n connection: 'upgrade',\n },\n })\n await onUnhandledRequest(\n request,\n options.getUnhandledRequestStrategy(),\n ).catch((error) => {\n const errorEvent = new Event('error')\n Object.defineProperty(errorEvent, 'cause', {\n enumerable: true,\n configurable: false,\n value: error,\n })\n connection.client.socket.dispatchEvent(errorEvent)\n })\n\n options?.onPassthroughConnection(connection)\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n connection.server.connect()\n })\n}\n"],"mappings":"AAGA,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,OAEK;AACP,SAAS,qBAAqB;AASvB,SAAS,qBAAqB,SAAsC;AACzE,uBAAqB,GAAG,cAAc,OAAO,eAAe;AAK1D,UAAM,WAAW,QAAQ,YAAY,EAAE,OAAO,cAAc,WAAW,CAAC;AAGxE,QAAI,SAAS,SAAS,GAAG;AACvB,eAAS,mBAAmB,UAAU;AAEtC,YAAM,QAAQ;AAAA,QACZ,SAAS,IAAI,CAAC,YAAY;AAIxB,iBAAO,QAAQ,IAAI,UAAU;AAAA,QAC/B,CAAC;AAAA,MACH;AAEA;AAAA,IACF;AAGA,UAAM,UAAU,IAAI,QAAQ,WAAW,OAAO,KAAK;AAAA,MACjD,SAAS;AAAA,QACP,SAAS;AAAA,QACT,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AACD,UAAM;AAAA,MACJ;AAAA,MACA,QAAQ,4BAA4B;AAAA,IACtC,EAAE,MAAM,CAAC,UAAU;AACjB,YAAM,aAAa,IAAI,MAAM,OAAO;AACpC,aAAO,eAAe,YAAY,SAAS;AAAA,QACzC,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,OAAO;AAAA,MACT,CAAC;AACD,iBAAW,OAAO,OAAO,cAAc,UAAU;AAAA,IACnD,CAAC;AAED,aAAS,wBAAwB,UAAU;AAI3C,eAAW,OAAO,QAAQ;AAAA,EAC5B,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/core/ws/handleWebSocketEvent.ts"],"sourcesContent":["import type { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket'\nimport type { RequestHandler } from '../handlers/RequestHandler'\nimport type { WebSocketHandler } from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from './webSocketInterceptor'\nimport {\n onUnhandledRequest,\n type UnhandledRequestStrategy,\n} from '../utils/request/onUnhandledRequest'\nimport { isHandlerKind } from '../utils/internal/isHandlerKind'\n\ninterface HandleWebSocketEventOptions {\n getUnhandledRequestStrategy: () => UnhandledRequestStrategy\n getHandlers: () => Array<RequestHandler | WebSocketHandler>\n onMockedConnection: (connection: WebSocketConnectionData) => void\n onPassthroughConnection: (onnection: WebSocketConnectionData) => void\n}\n\nexport function handleWebSocketEvent(options: HandleWebSocketEventOptions) {\n webSocketInterceptor.on('connection', async (connection) => {\n /**\n * @todo @fixme Reference the handlers controller here and use `.getHandlersByKind`.\n * That one relies on the pre-grouped handlers map and will be more performant.\n */\n const handlers = options.getHandlers().filter(isHandlerKind('websocket'))\n\n // Ignore this connection if the user hasn't defined any handlers.\n if (handlers.length > 0) {\n options?.onMockedConnection(connection)\n\n await Promise.all(\n handlers.map((handler) => {\n // Iterate over the handlers and forward the connection\n // event to WebSocket event handlers. This is equivalent\n // to dispatching that event onto multiple listeners.\n return handler.run(connection)\n }),\n )\n\n return\n }\n\n // Construct a request representing this WebSocket connection.\n const request = new Request(connection.client.url, {\n headers: {\n upgrade: 'websocket',\n connection: 'upgrade',\n },\n })\n await onUnhandledRequest(\n request,\n options.getUnhandledRequestStrategy(),\n ).catch((error) => {\n const errorEvent = new Event('error')\n Object.defineProperty(errorEvent, 'cause', {\n enumerable: true,\n configurable: false,\n value: error,\n })\n connection.client.socket.dispatchEvent(errorEvent)\n })\n\n options?.onPassthroughConnection(connection)\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n connection.server.connect()\n })\n}\n"],"mappings":"AAGA,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,OAEK;AACP,SAAS,qBAAqB;AASvB,SAAS,qBAAqB,SAAsC;AACzE,uBAAqB,GAAG,cAAc,OAAO,eAAe;AAK1D,UAAM,WAAW,QAAQ,YAAY,EAAE,OAAO,cAAc,WAAW,CAAC;AAGxE,QAAI,SAAS,SAAS,GAAG;AACvB,eAAS,mBAAmB,UAAU;AAEtC,YAAM,QAAQ;AAAA,QACZ,SAAS,IAAI,CAAC,YAAY;AAIxB,iBAAO,QAAQ,IAAI,UAAU;AAAA,QAC/B,CAAC;AAAA,MACH;AAEA;AAAA,IACF;AAGA,UAAM,UAAU,IAAI,QAAQ,WAAW,OAAO,KAAK;AAAA,MACjD,SAAS;AAAA,QACP,SAAS;AAAA,QACT,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AACD,UAAM;AAAA,MACJ;AAAA,MACA,QAAQ,4BAA4B;AAAA,IACtC,EAAE,MAAM,CAAC,UAAU;AACjB,YAAM,aAAa,IAAI,MAAM,OAAO;AACpC,aAAO,eAAe,YAAY,SAAS;AAAA,QACzC,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,OAAO;AAAA,MACT,CAAC;AACD,iBAAW,OAAO,OAAO,cAAc,UAAU;AAAA,IACnD,CAAC;AAED,aAAS,wBAAwB,UAAU;AAI3C,eAAW,OAAO,QAAQ;AAAA,EAC5B,CAAC;AACH;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/ws.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport type {\n WebSocketData,\n WebSocketClientConnectionProtocol,\n} from '@mswjs/interceptors/WebSocket'\nimport {\n WebSocketHandler,\n kEmitter,\n type WebSocketHandlerEventMap,\n} from './handlers/WebSocketHandler'\nimport { hasRefCounted } from './utils/internal/hasRefCounted'\nimport { type Path, isPath } from './utils/matching/matchRequestUrl'\nimport { WebSocketClientManager } from './ws/WebSocketClientManager'\n\nconst webSocketChannel = new BroadcastChannel('msw:websocket-client-manager')\n\nif (hasRefCounted(webSocketChannel)) {\n // Allows the Node.js thread to exit if it is the only active handle in the event system.\n // https://nodejs.org/api/worker_threads.html#broadcastchannelunref\n webSocketChannel.unref()\n}\n\nexport type WebSocketEventListener<\n EventType extends keyof WebSocketHandlerEventMap,\n> = (...args: WebSocketHandlerEventMap[EventType]) => void\n\nexport type WebSocketLink = {\n /**\n * A set of all WebSocket clients connected\n * to this link.\n *\n * @see {@link https://mswjs.io/docs/api/ws#clients `clients` API reference}\n */\n clients: Set<WebSocketClientConnectionProtocol>\n\n /**\n * Adds an event listener to this WebSocket link.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n * chat.addEventListener('connection', listener)\n *\n * @see {@link https://mswjs.io/docs/api/ws#onevent-listener `on()` API reference}\n */\n addEventListener: <EventType extends keyof WebSocketHandlerEventMap>(\n event: EventType,\n listener: WebSocketEventListener<EventType>,\n ) => WebSocketHandler\n\n /**\n * Broadcasts the given data to all WebSocket clients.\n *\n * @example\n * const service = ws.link('wss://example.com')\n * service.addEventListener('connection', () => {\n * service.broadcast('hello, everyone!')\n * })\n *\n * @see {@link https://mswjs.io/docs/api/ws#broadcastdata `broadcast()` API reference}\n */\n broadcast: (data: WebSocketData) => void\n\n /**\n * Broadcasts the given data to all WebSocket clients\n * except the ones provided in the `clients` argument.\n *\n * @example\n * const service = ws.link('wss://example.com')\n * service.addEventListener('connection', ({ client }) => {\n * service.broadcastExcept(client, 'hi, the rest of you!')\n * })\n *\n * @see {@link https://mswjs.io/docs/api/ws#broadcastexceptclients-data `broadcast()` API reference}\n */\n broadcastExcept: (\n clients:\n | WebSocketClientConnectionProtocol\n | Array<WebSocketClientConnectionProtocol>,\n data: WebSocketData,\n ) => void\n}\n\n/**\n * Intercepts outgoing WebSocket connections to the given URL.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n * chat.addEventListener('connection', ({ client }) => {\n * client.send('hello from server!')\n * })\n */\nfunction createWebSocketLinkHandler(url: Path): WebSocketLink {\n invariant(url, 'Expected a WebSocket server URL but got undefined')\n\n invariant(\n isPath(url),\n 'Expected a WebSocket server URL to be a valid path but got %s',\n typeof url,\n )\n\n const clientManager = new WebSocketClientManager(webSocketChannel)\n\n return {\n get clients() {\n return clientManager.clients\n },\n addEventListener(event, listener) {\n const handler = new WebSocketHandler(url)\n\n // Add the connection event listener for when the\n // handler matches and emits a connection event.\n // When that happens, store that connection in the\n // set of all connections for reference.\n handler[kEmitter].on('connection', async ({ client }) => {\n await clientManager.addConnection(client)\n })\n\n // The \"handleWebSocketEvent\" function will invoke\n // the \"run()\" method on the WebSocketHandler.\n // If the handler matches, it will emit the \"connection\"\n // event. Attach the user-defined listener to that event.\n handler[kEmitter].on(event, listener)\n\n return handler\n },\n\n broadcast(data) {\n // This will invoke \"send()\" on the immediate clients\n // in this runtime and post a message to the broadcast channel\n // to trigger send for the clients in other runtimes.\n this.broadcastExcept([], data)\n },\n\n broadcastExcept(clients, data) {\n const ignoreClients = Array.prototype\n .concat(clients)\n .map((client) => client.id)\n\n clientManager.clients.forEach((otherClient) => {\n if (!ignoreClients.includes(otherClient.id)) {\n otherClient.send(data)\n }\n })\n },\n }\n}\n\n/**\n * A namespace to intercept and mock WebSocket connections.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n *\n * @see {@link https://mswjs.io/docs/api/ws `ws` API reference}\n * @see {@link https://mswjs.io/docs/basics/handling-websocket-events Handling WebSocket events}\n */\nexport const ws = {\n link: createWebSocketLinkHandler,\n}\n\nexport { WebSocketData }\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA0B;AAK1B,8BAIO;AACP,2BAA8B;AAC9B,6BAAkC;AAClC,oCAAuC;AAEvC,MAAM,mBAAmB,IAAI,iBAAiB,8BAA8B;AAE5E,QAAI,oCAAc,gBAAgB,GAAG;AAGnC,mBAAiB,MAAM;AACzB;AAuEA,SAAS,2BAA2B,KAA0B;AAC5D,mCAAU,KAAK,mDAAmD;AAElE;AAAA,QACE,+BAAO,GAAG;AAAA,IACV;AAAA,IACA,OAAO;AAAA,EACT;AAEA,QAAM,gBAAgB,IAAI,qDAAuB,gBAAgB;AAEjE,SAAO;AAAA,IACL,IAAI,UAAU;AACZ,aAAO,cAAc;AAAA,IACvB;AAAA,IACA,iBAAiB,OAAO,UAAU;AAChC,YAAM,UAAU,IAAI,yCAAiB,GAAG;AAMxC,cAAQ,gCAAQ,EAAE,GAAG,cAAc,OAAO,EAAE,OAAO,MAAM;AACvD,cAAM,cAAc,cAAc,MAAM;AAAA,MAC1C,CAAC;AAMD,cAAQ,gCAAQ,EAAE,GAAG,OAAO,QAAQ;AAEpC,aAAO;AAAA,IACT;AAAA,IAEA,UAAU,MAAM;AAId,WAAK,gBAAgB,CAAC,GAAG,IAAI;AAAA,IAC/B;AAAA,IAEA,gBAAgB,SAAS,MAAM;AAC7B,YAAM,gBAAgB,MAAM,UACzB,OAAO,OAAO,EACd,IAAI,CAAC,WAAW,OAAO,EAAE;AAE5B,oBAAc,QAAQ,QAAQ,CAAC,gBAAgB;AAC7C,YAAI,CAAC,cAAc,SAAS,YAAY,EAAE,GAAG;AAC3C,sBAAY,KAAK,IAAI;AAAA,QACvB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAWO,MAAM,KAAK;AAAA,EAChB,MAAM;AACR;","names":[]}
1
+ {"version":3,"sources":["../../src/core/ws.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport type {\n WebSocketData,\n WebSocketClientConnectionProtocol,\n} from '@mswjs/interceptors/WebSocket'\nimport {\n WebSocketHandler,\n kEmitter,\n type WebSocketHandlerEventMap,\n} from './handlers/WebSocketHandler'\nimport { hasRefCounted } from './utils/internal/hasRefCounted'\nimport { type Path, isPath } from './utils/matching/matchRequestUrl'\nimport { WebSocketClientManager } from './ws/WebSocketClientManager'\n\nconst webSocketChannel = new BroadcastChannel('msw:websocket-client-manager')\n\nif (hasRefCounted(webSocketChannel)) {\n // Allows the Node.js thread to exit if it is the only active handle in the event system.\n // https://nodejs.org/api/worker_threads.html#broadcastchannelunref\n webSocketChannel.unref()\n}\n\nexport type WebSocketEventListener<\n EventType extends keyof WebSocketHandlerEventMap,\n> = (...args: WebSocketHandlerEventMap[EventType]) => void\n\nexport type WebSocketLink = {\n /**\n * A set of all WebSocket clients connected\n * to this link.\n *\n * @see {@link https://mswjs.io/docs/api/ws#clients `clients` API reference}\n */\n clients: Set<WebSocketClientConnectionProtocol>\n\n /**\n * Adds an event listener to this WebSocket link.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n * chat.addEventListener('connection', listener)\n *\n * @see {@link https://mswjs.io/docs/api/ws#onevent-listener `on()` API reference}\n */\n addEventListener: <EventType extends keyof WebSocketHandlerEventMap>(\n event: EventType,\n listener: WebSocketEventListener<EventType>,\n ) => WebSocketHandler\n\n /**\n * Broadcasts the given data to all WebSocket clients.\n *\n * @example\n * const service = ws.link('wss://example.com')\n * service.addEventListener('connection', () => {\n * service.broadcast('hello, everyone!')\n * })\n *\n * @see {@link https://mswjs.io/docs/api/ws#broadcastdata `broadcast()` API reference}\n */\n broadcast: (data: WebSocketData) => void\n\n /**\n * Broadcasts the given data to all WebSocket clients\n * except the ones provided in the `clients` argument.\n *\n * @example\n * const service = ws.link('wss://example.com')\n * service.addEventListener('connection', ({ client }) => {\n * service.broadcastExcept(client, 'hi, the rest of you!')\n * })\n *\n * @see {@link https://mswjs.io/docs/api/ws#broadcastexceptclients-data `broadcast()` API reference}\n */\n broadcastExcept: (\n clients:\n | WebSocketClientConnectionProtocol\n | Array<WebSocketClientConnectionProtocol>,\n data: WebSocketData,\n ) => void\n}\n\n/**\n * Intercepts outgoing WebSocket connections to the given URL.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n * chat.addEventListener('connection', ({ client }) => {\n * client.send('hello from server!')\n * })\n */\nfunction createWebSocketLinkHandler(url: Path): WebSocketLink {\n invariant(url, 'Expected a WebSocket server URL but got undefined')\n\n invariant(\n isPath(url),\n 'Expected a WebSocket server URL to be a valid path but got %s',\n typeof url,\n )\n\n const clientManager = new WebSocketClientManager(webSocketChannel)\n\n return {\n get clients() {\n return clientManager.clients\n },\n addEventListener(event, listener) {\n const handler = new WebSocketHandler(url)\n\n // Add the connection event listener for when the\n // handler matches and emits a connection event.\n // When that happens, store that connection in the\n // set of all connections for reference.\n handler[kEmitter].on('connection', async ({ client }) => {\n await clientManager.addConnection(client)\n })\n\n // The \"handleWebSocketEvent\" function will invoke\n // the \"run()\" method on the WebSocketHandler.\n // If the handler matches, it will emit the \"connection\"\n // event. Attach the user-defined listener to that event.\n handler[kEmitter].on(event, listener)\n\n return handler\n },\n\n broadcast(data) {\n // This will invoke \"send()\" on the immediate clients\n // in this runtime and post a message to the broadcast channel\n // to trigger send for the clients in other runtimes.\n this.broadcastExcept([], data)\n },\n\n broadcastExcept(clients, data) {\n const ignoreClients = Array.prototype\n .concat(clients)\n .map((client) => client.id)\n\n clientManager.clients.forEach((otherClient) => {\n if (!ignoreClients.includes(otherClient.id)) {\n otherClient.send(data)\n }\n })\n },\n }\n}\n\n/**\n * A namespace to intercept and mock WebSocket connections.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n *\n * @see {@link https://mswjs.io/docs/api/ws `ws` API reference}\n * @see {@link https://mswjs.io/docs/basics/handling-websocket-events Handling WebSocket events}\n */\nexport const ws = {\n link: createWebSocketLinkHandler,\n}\n\nexport { type WebSocketData }\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA0B;AAK1B,8BAIO;AACP,2BAA8B;AAC9B,6BAAkC;AAClC,oCAAuC;AAEvC,MAAM,mBAAmB,IAAI,iBAAiB,8BAA8B;AAE5E,QAAI,oCAAc,gBAAgB,GAAG;AAGnC,mBAAiB,MAAM;AACzB;AAuEA,SAAS,2BAA2B,KAA0B;AAC5D,mCAAU,KAAK,mDAAmD;AAElE;AAAA,QACE,+BAAO,GAAG;AAAA,IACV;AAAA,IACA,OAAO;AAAA,EACT;AAEA,QAAM,gBAAgB,IAAI,qDAAuB,gBAAgB;AAEjE,SAAO;AAAA,IACL,IAAI,UAAU;AACZ,aAAO,cAAc;AAAA,IACvB;AAAA,IACA,iBAAiB,OAAO,UAAU;AAChC,YAAM,UAAU,IAAI,yCAAiB,GAAG;AAMxC,cAAQ,gCAAQ,EAAE,GAAG,cAAc,OAAO,EAAE,OAAO,MAAM;AACvD,cAAM,cAAc,cAAc,MAAM;AAAA,MAC1C,CAAC;AAMD,cAAQ,gCAAQ,EAAE,GAAG,OAAO,QAAQ;AAEpC,aAAO;AAAA,IACT;AAAA,IAEA,UAAU,MAAM;AAId,WAAK,gBAAgB,CAAC,GAAG,IAAI;AAAA,IAC/B;AAAA,IAEA,gBAAgB,SAAS,MAAM;AAC7B,YAAM,gBAAgB,MAAM,UACzB,OAAO,OAAO,EACd,IAAI,CAAC,WAAW,OAAO,EAAE;AAE5B,oBAAc,QAAQ,QAAQ,CAAC,gBAAgB;AAC7C,YAAI,CAAC,cAAc,SAAS,YAAY,EAAE,GAAG;AAC3C,sBAAY,KAAK,IAAI;AAAA,QACvB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAWO,MAAM,KAAK;AAAA,EAChB,MAAM;AACR;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/ws.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport type {\n WebSocketData,\n WebSocketClientConnectionProtocol,\n} from '@mswjs/interceptors/WebSocket'\nimport {\n WebSocketHandler,\n kEmitter,\n type WebSocketHandlerEventMap,\n} from './handlers/WebSocketHandler'\nimport { hasRefCounted } from './utils/internal/hasRefCounted'\nimport { type Path, isPath } from './utils/matching/matchRequestUrl'\nimport { WebSocketClientManager } from './ws/WebSocketClientManager'\n\nconst webSocketChannel = new BroadcastChannel('msw:websocket-client-manager')\n\nif (hasRefCounted(webSocketChannel)) {\n // Allows the Node.js thread to exit if it is the only active handle in the event system.\n // https://nodejs.org/api/worker_threads.html#broadcastchannelunref\n webSocketChannel.unref()\n}\n\nexport type WebSocketEventListener<\n EventType extends keyof WebSocketHandlerEventMap,\n> = (...args: WebSocketHandlerEventMap[EventType]) => void\n\nexport type WebSocketLink = {\n /**\n * A set of all WebSocket clients connected\n * to this link.\n *\n * @see {@link https://mswjs.io/docs/api/ws#clients `clients` API reference}\n */\n clients: Set<WebSocketClientConnectionProtocol>\n\n /**\n * Adds an event listener to this WebSocket link.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n * chat.addEventListener('connection', listener)\n *\n * @see {@link https://mswjs.io/docs/api/ws#onevent-listener `on()` API reference}\n */\n addEventListener: <EventType extends keyof WebSocketHandlerEventMap>(\n event: EventType,\n listener: WebSocketEventListener<EventType>,\n ) => WebSocketHandler\n\n /**\n * Broadcasts the given data to all WebSocket clients.\n *\n * @example\n * const service = ws.link('wss://example.com')\n * service.addEventListener('connection', () => {\n * service.broadcast('hello, everyone!')\n * })\n *\n * @see {@link https://mswjs.io/docs/api/ws#broadcastdata `broadcast()` API reference}\n */\n broadcast: (data: WebSocketData) => void\n\n /**\n * Broadcasts the given data to all WebSocket clients\n * except the ones provided in the `clients` argument.\n *\n * @example\n * const service = ws.link('wss://example.com')\n * service.addEventListener('connection', ({ client }) => {\n * service.broadcastExcept(client, 'hi, the rest of you!')\n * })\n *\n * @see {@link https://mswjs.io/docs/api/ws#broadcastexceptclients-data `broadcast()` API reference}\n */\n broadcastExcept: (\n clients:\n | WebSocketClientConnectionProtocol\n | Array<WebSocketClientConnectionProtocol>,\n data: WebSocketData,\n ) => void\n}\n\n/**\n * Intercepts outgoing WebSocket connections to the given URL.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n * chat.addEventListener('connection', ({ client }) => {\n * client.send('hello from server!')\n * })\n */\nfunction createWebSocketLinkHandler(url: Path): WebSocketLink {\n invariant(url, 'Expected a WebSocket server URL but got undefined')\n\n invariant(\n isPath(url),\n 'Expected a WebSocket server URL to be a valid path but got %s',\n typeof url,\n )\n\n const clientManager = new WebSocketClientManager(webSocketChannel)\n\n return {\n get clients() {\n return clientManager.clients\n },\n addEventListener(event, listener) {\n const handler = new WebSocketHandler(url)\n\n // Add the connection event listener for when the\n // handler matches and emits a connection event.\n // When that happens, store that connection in the\n // set of all connections for reference.\n handler[kEmitter].on('connection', async ({ client }) => {\n await clientManager.addConnection(client)\n })\n\n // The \"handleWebSocketEvent\" function will invoke\n // the \"run()\" method on the WebSocketHandler.\n // If the handler matches, it will emit the \"connection\"\n // event. Attach the user-defined listener to that event.\n handler[kEmitter].on(event, listener)\n\n return handler\n },\n\n broadcast(data) {\n // This will invoke \"send()\" on the immediate clients\n // in this runtime and post a message to the broadcast channel\n // to trigger send for the clients in other runtimes.\n this.broadcastExcept([], data)\n },\n\n broadcastExcept(clients, data) {\n const ignoreClients = Array.prototype\n .concat(clients)\n .map((client) => client.id)\n\n clientManager.clients.forEach((otherClient) => {\n if (!ignoreClients.includes(otherClient.id)) {\n otherClient.send(data)\n }\n })\n },\n }\n}\n\n/**\n * A namespace to intercept and mock WebSocket connections.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n *\n * @see {@link https://mswjs.io/docs/api/ws `ws` API reference}\n * @see {@link https://mswjs.io/docs/basics/handling-websocket-events Handling WebSocket events}\n */\nexport const ws = {\n link: createWebSocketLinkHandler,\n}\n\nexport { WebSocketData }\n"],"mappings":"AAAA,SAAS,iBAAiB;AAK1B;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,qBAAqB;AAC9B,SAAoB,cAAc;AAClC,SAAS,8BAA8B;AAEvC,MAAM,mBAAmB,IAAI,iBAAiB,8BAA8B;AAE5E,IAAI,cAAc,gBAAgB,GAAG;AAGnC,mBAAiB,MAAM;AACzB;AAuEA,SAAS,2BAA2B,KAA0B;AAC5D,YAAU,KAAK,mDAAmD;AAElE;AAAA,IACE,OAAO,GAAG;AAAA,IACV;AAAA,IACA,OAAO;AAAA,EACT;AAEA,QAAM,gBAAgB,IAAI,uBAAuB,gBAAgB;AAEjE,SAAO;AAAA,IACL,IAAI,UAAU;AACZ,aAAO,cAAc;AAAA,IACvB;AAAA,IACA,iBAAiB,OAAO,UAAU;AAChC,YAAM,UAAU,IAAI,iBAAiB,GAAG;AAMxC,cAAQ,QAAQ,EAAE,GAAG,cAAc,OAAO,EAAE,OAAO,MAAM;AACvD,cAAM,cAAc,cAAc,MAAM;AAAA,MAC1C,CAAC;AAMD,cAAQ,QAAQ,EAAE,GAAG,OAAO,QAAQ;AAEpC,aAAO;AAAA,IACT;AAAA,IAEA,UAAU,MAAM;AAId,WAAK,gBAAgB,CAAC,GAAG,IAAI;AAAA,IAC/B;AAAA,IAEA,gBAAgB,SAAS,MAAM;AAC7B,YAAM,gBAAgB,MAAM,UACzB,OAAO,OAAO,EACd,IAAI,CAAC,WAAW,OAAO,EAAE;AAE5B,oBAAc,QAAQ,QAAQ,CAAC,gBAAgB;AAC7C,YAAI,CAAC,cAAc,SAAS,YAAY,EAAE,GAAG;AAC3C,sBAAY,KAAK,IAAI;AAAA,QACvB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAWO,MAAM,KAAK;AAAA,EAChB,MAAM;AACR;","names":[]}
1
+ {"version":3,"sources":["../../src/core/ws.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport type {\n WebSocketData,\n WebSocketClientConnectionProtocol,\n} from '@mswjs/interceptors/WebSocket'\nimport {\n WebSocketHandler,\n kEmitter,\n type WebSocketHandlerEventMap,\n} from './handlers/WebSocketHandler'\nimport { hasRefCounted } from './utils/internal/hasRefCounted'\nimport { type Path, isPath } from './utils/matching/matchRequestUrl'\nimport { WebSocketClientManager } from './ws/WebSocketClientManager'\n\nconst webSocketChannel = new BroadcastChannel('msw:websocket-client-manager')\n\nif (hasRefCounted(webSocketChannel)) {\n // Allows the Node.js thread to exit if it is the only active handle in the event system.\n // https://nodejs.org/api/worker_threads.html#broadcastchannelunref\n webSocketChannel.unref()\n}\n\nexport type WebSocketEventListener<\n EventType extends keyof WebSocketHandlerEventMap,\n> = (...args: WebSocketHandlerEventMap[EventType]) => void\n\nexport type WebSocketLink = {\n /**\n * A set of all WebSocket clients connected\n * to this link.\n *\n * @see {@link https://mswjs.io/docs/api/ws#clients `clients` API reference}\n */\n clients: Set<WebSocketClientConnectionProtocol>\n\n /**\n * Adds an event listener to this WebSocket link.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n * chat.addEventListener('connection', listener)\n *\n * @see {@link https://mswjs.io/docs/api/ws#onevent-listener `on()` API reference}\n */\n addEventListener: <EventType extends keyof WebSocketHandlerEventMap>(\n event: EventType,\n listener: WebSocketEventListener<EventType>,\n ) => WebSocketHandler\n\n /**\n * Broadcasts the given data to all WebSocket clients.\n *\n * @example\n * const service = ws.link('wss://example.com')\n * service.addEventListener('connection', () => {\n * service.broadcast('hello, everyone!')\n * })\n *\n * @see {@link https://mswjs.io/docs/api/ws#broadcastdata `broadcast()` API reference}\n */\n broadcast: (data: WebSocketData) => void\n\n /**\n * Broadcasts the given data to all WebSocket clients\n * except the ones provided in the `clients` argument.\n *\n * @example\n * const service = ws.link('wss://example.com')\n * service.addEventListener('connection', ({ client }) => {\n * service.broadcastExcept(client, 'hi, the rest of you!')\n * })\n *\n * @see {@link https://mswjs.io/docs/api/ws#broadcastexceptclients-data `broadcast()` API reference}\n */\n broadcastExcept: (\n clients:\n | WebSocketClientConnectionProtocol\n | Array<WebSocketClientConnectionProtocol>,\n data: WebSocketData,\n ) => void\n}\n\n/**\n * Intercepts outgoing WebSocket connections to the given URL.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n * chat.addEventListener('connection', ({ client }) => {\n * client.send('hello from server!')\n * })\n */\nfunction createWebSocketLinkHandler(url: Path): WebSocketLink {\n invariant(url, 'Expected a WebSocket server URL but got undefined')\n\n invariant(\n isPath(url),\n 'Expected a WebSocket server URL to be a valid path but got %s',\n typeof url,\n )\n\n const clientManager = new WebSocketClientManager(webSocketChannel)\n\n return {\n get clients() {\n return clientManager.clients\n },\n addEventListener(event, listener) {\n const handler = new WebSocketHandler(url)\n\n // Add the connection event listener for when the\n // handler matches and emits a connection event.\n // When that happens, store that connection in the\n // set of all connections for reference.\n handler[kEmitter].on('connection', async ({ client }) => {\n await clientManager.addConnection(client)\n })\n\n // The \"handleWebSocketEvent\" function will invoke\n // the \"run()\" method on the WebSocketHandler.\n // If the handler matches, it will emit the \"connection\"\n // event. Attach the user-defined listener to that event.\n handler[kEmitter].on(event, listener)\n\n return handler\n },\n\n broadcast(data) {\n // This will invoke \"send()\" on the immediate clients\n // in this runtime and post a message to the broadcast channel\n // to trigger send for the clients in other runtimes.\n this.broadcastExcept([], data)\n },\n\n broadcastExcept(clients, data) {\n const ignoreClients = Array.prototype\n .concat(clients)\n .map((client) => client.id)\n\n clientManager.clients.forEach((otherClient) => {\n if (!ignoreClients.includes(otherClient.id)) {\n otherClient.send(data)\n }\n })\n },\n }\n}\n\n/**\n * A namespace to intercept and mock WebSocket connections.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n *\n * @see {@link https://mswjs.io/docs/api/ws `ws` API reference}\n * @see {@link https://mswjs.io/docs/basics/handling-websocket-events Handling WebSocket events}\n */\nexport const ws = {\n link: createWebSocketLinkHandler,\n}\n\nexport { type WebSocketData }\n"],"mappings":"AAAA,SAAS,iBAAiB;AAK1B;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,qBAAqB;AAC9B,SAAoB,cAAc;AAClC,SAAS,8BAA8B;AAEvC,MAAM,mBAAmB,IAAI,iBAAiB,8BAA8B;AAE5E,IAAI,cAAc,gBAAgB,GAAG;AAGnC,mBAAiB,MAAM;AACzB;AAuEA,SAAS,2BAA2B,KAA0B;AAC5D,YAAU,KAAK,mDAAmD;AAElE;AAAA,IACE,OAAO,GAAG;AAAA,IACV;AAAA,IACA,OAAO;AAAA,EACT;AAEA,QAAM,gBAAgB,IAAI,uBAAuB,gBAAgB;AAEjE,SAAO;AAAA,IACL,IAAI,UAAU;AACZ,aAAO,cAAc;AAAA,IACvB;AAAA,IACA,iBAAiB,OAAO,UAAU;AAChC,YAAM,UAAU,IAAI,iBAAiB,GAAG;AAMxC,cAAQ,QAAQ,EAAE,GAAG,cAAc,OAAO,EAAE,OAAO,MAAM;AACvD,cAAM,cAAc,cAAc,MAAM;AAAA,MAC1C,CAAC;AAMD,cAAQ,QAAQ,EAAE,GAAG,OAAO,QAAQ;AAEpC,aAAO;AAAA,IACT;AAAA,IAEA,UAAU,MAAM;AAId,WAAK,gBAAgB,CAAC,GAAG,IAAI;AAAA,IAC/B;AAAA,IAEA,gBAAgB,SAAS,MAAM;AAC7B,YAAM,gBAAgB,MAAM,UACzB,OAAO,OAAO,EACd,IAAI,CAAC,WAAW,OAAO,EAAE;AAE5B,oBAAc,QAAQ,QAAQ,CAAC,gBAAgB;AAC7C,YAAI,CAAC,cAAc,SAAS,YAAY,EAAE,GAAG;AAC3C,sBAAY,KAAK,IAAI;AAAA,QACvB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAWO,MAAM,KAAK;AAAA,EAChB,MAAM;AACR;","names":[]}