msw 2.5.2 → 2.6.0

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 (190) hide show
  1. package/lib/browser/index.d.mts +7 -6
  2. package/lib/browser/index.d.ts +7 -6
  3. package/lib/browser/index.js +29 -1
  4. package/lib/browser/index.js.map +1 -1
  5. package/lib/browser/index.mjs +29 -1
  6. package/lib/browser/index.mjs.map +1 -1
  7. package/lib/core/{GraphQLHandler-ClMB0BOy.d.mts → GraphQLHandler-Doool6Q_.d.mts} +1 -1
  8. package/lib/core/{GraphQLHandler-D6mLMXGZ.d.ts → GraphQLHandler-udzgBRPf.d.ts} +1 -1
  9. package/lib/core/{HttpResponse-vn-Pb4Bi.d.mts → HttpResponse-BLGmJolh.d.mts} +1 -1
  10. package/lib/core/{HttpResponse-DaYkf3ml.d.ts → HttpResponse-Cgbkdkje.d.ts} +1 -1
  11. package/lib/core/HttpResponse.d.mts +1 -1
  12. package/lib/core/HttpResponse.d.ts +1 -1
  13. package/lib/core/SetupApi.d.mts +15 -12
  14. package/lib/core/SetupApi.d.ts +15 -12
  15. package/lib/core/SetupApi.js +3 -1
  16. package/lib/core/SetupApi.js.map +1 -1
  17. package/lib/core/SetupApi.mjs +3 -1
  18. package/lib/core/SetupApi.mjs.map +1 -1
  19. package/lib/core/getResponse.d.mts +1 -1
  20. package/lib/core/getResponse.d.ts +1 -1
  21. package/lib/core/graphql.d.mts +2 -2
  22. package/lib/core/graphql.d.ts +2 -2
  23. package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
  24. package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
  25. package/lib/core/handlers/HttpHandler.d.mts +1 -1
  26. package/lib/core/handlers/HttpHandler.d.ts +1 -1
  27. package/lib/core/handlers/RequestHandler.d.mts +1 -1
  28. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  29. package/lib/core/handlers/WebSocketHandler.d.mts +33 -0
  30. package/lib/core/handlers/WebSocketHandler.d.ts +33 -0
  31. package/lib/core/handlers/WebSocketHandler.js +120 -0
  32. package/lib/core/handlers/WebSocketHandler.js.map +1 -0
  33. package/lib/core/handlers/WebSocketHandler.mjs +102 -0
  34. package/lib/core/handlers/WebSocketHandler.mjs.map +1 -0
  35. package/lib/core/http.d.mts +1 -1
  36. package/lib/core/http.d.ts +1 -1
  37. package/lib/core/index.d.mts +5 -2
  38. package/lib/core/index.d.ts +5 -2
  39. package/lib/core/index.js +5 -1
  40. package/lib/core/index.js.map +1 -1
  41. package/lib/core/index.mjs +7 -1
  42. package/lib/core/index.mjs.map +1 -1
  43. package/lib/core/passthrough.d.mts +1 -1
  44. package/lib/core/passthrough.d.ts +1 -1
  45. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  46. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  47. package/lib/core/utils/executeHandlers.d.mts +1 -1
  48. package/lib/core/utils/executeHandlers.d.ts +1 -1
  49. package/lib/core/utils/executeHandlers.js +4 -0
  50. package/lib/core/utils/executeHandlers.js.map +1 -1
  51. package/lib/core/utils/executeHandlers.mjs +6 -0
  52. package/lib/core/utils/executeHandlers.mjs.map +1 -1
  53. package/lib/core/utils/handleRequest.d.mts +2 -2
  54. package/lib/core/utils/handleRequest.d.ts +2 -2
  55. package/lib/core/utils/handleRequest.js.map +1 -1
  56. package/lib/core/utils/handleRequest.mjs.map +1 -1
  57. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
  58. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
  59. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  60. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  61. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  62. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  63. package/lib/core/utils/logging/getTimestamp.d.mts +4 -1
  64. package/lib/core/utils/logging/getTimestamp.d.ts +4 -1
  65. package/lib/core/utils/logging/getTimestamp.js +6 -2
  66. package/lib/core/utils/logging/getTimestamp.js.map +1 -1
  67. package/lib/core/utils/logging/getTimestamp.mjs +6 -2
  68. package/lib/core/utils/logging/getTimestamp.mjs.map +1 -1
  69. package/lib/core/utils/matching/matchRequestUrl.d.mts +2 -1
  70. package/lib/core/utils/matching/matchRequestUrl.d.ts +2 -1
  71. package/lib/core/utils/matching/matchRequestUrl.js +4 -0
  72. package/lib/core/utils/matching/matchRequestUrl.js.map +1 -1
  73. package/lib/core/utils/matching/matchRequestUrl.mjs +4 -0
  74. package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -1
  75. package/lib/core/ws/WebSocketClientManager.d.mts +63 -0
  76. package/lib/core/ws/WebSocketClientManager.d.ts +63 -0
  77. package/lib/core/ws/WebSocketClientManager.js +149 -0
  78. package/lib/core/ws/WebSocketClientManager.js.map +1 -0
  79. package/lib/core/ws/WebSocketClientManager.mjs +129 -0
  80. package/lib/core/ws/WebSocketClientManager.mjs.map +1 -0
  81. package/lib/core/ws/WebSocketClientStore.d.mts +13 -0
  82. package/lib/core/ws/WebSocketClientStore.d.ts +13 -0
  83. package/lib/core/ws/WebSocketClientStore.js +26 -0
  84. package/lib/core/ws/WebSocketClientStore.js.map +1 -0
  85. package/lib/core/ws/WebSocketClientStore.mjs +6 -0
  86. package/lib/core/ws/WebSocketClientStore.mjs.map +1 -0
  87. package/lib/core/ws/WebSocketIndexedDBClientStore.d.mts +15 -0
  88. package/lib/core/ws/WebSocketIndexedDBClientStore.d.ts +15 -0
  89. package/lib/core/ws/WebSocketIndexedDBClientStore.js +130 -0
  90. package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -0
  91. package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +110 -0
  92. package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -0
  93. package/lib/core/ws/WebSocketMemoryClientStore.d.mts +13 -0
  94. package/lib/core/ws/WebSocketMemoryClientStore.d.ts +13 -0
  95. package/lib/core/ws/WebSocketMemoryClientStore.js +41 -0
  96. package/lib/core/ws/WebSocketMemoryClientStore.js.map +1 -0
  97. package/lib/core/ws/WebSocketMemoryClientStore.mjs +21 -0
  98. package/lib/core/ws/WebSocketMemoryClientStore.mjs.map +1 -0
  99. package/lib/core/ws/handleWebSocketEvent.d.mts +19 -0
  100. package/lib/core/ws/handleWebSocketEvent.d.ts +19 -0
  101. package/lib/core/ws/handleWebSocketEvent.js +73 -0
  102. package/lib/core/ws/handleWebSocketEvent.js.map +1 -0
  103. package/lib/core/ws/handleWebSocketEvent.mjs +55 -0
  104. package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -0
  105. package/lib/core/ws/utils/attachWebSocketLogger.d.mts +12 -0
  106. package/lib/core/ws/utils/attachWebSocketLogger.d.ts +12 -0
  107. package/lib/core/ws/utils/attachWebSocketLogger.js +198 -0
  108. package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -0
  109. package/lib/core/ws/utils/attachWebSocketLogger.mjs +178 -0
  110. package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -0
  111. package/lib/core/ws/utils/getMessageLength.d.mts +11 -0
  112. package/lib/core/ws/utils/getMessageLength.d.ts +11 -0
  113. package/lib/core/ws/utils/getMessageLength.js +33 -0
  114. package/lib/core/ws/utils/getMessageLength.js.map +1 -0
  115. package/lib/core/ws/utils/getMessageLength.mjs +13 -0
  116. package/lib/core/ws/utils/getMessageLength.mjs.map +1 -0
  117. package/lib/core/ws/utils/getPublicData.d.mts +5 -0
  118. package/lib/core/ws/utils/getPublicData.d.ts +5 -0
  119. package/lib/core/ws/utils/getPublicData.js +36 -0
  120. package/lib/core/ws/utils/getPublicData.js.map +1 -0
  121. package/lib/core/ws/utils/getPublicData.mjs +16 -0
  122. package/lib/core/ws/utils/getPublicData.mjs.map +1 -0
  123. package/lib/core/ws/utils/truncateMessage.d.mts +3 -0
  124. package/lib/core/ws/utils/truncateMessage.d.ts +3 -0
  125. package/lib/core/ws/utils/truncateMessage.js +31 -0
  126. package/lib/core/ws/utils/truncateMessage.js.map +1 -0
  127. package/lib/core/ws/utils/truncateMessage.mjs +11 -0
  128. package/lib/core/ws/utils/truncateMessage.mjs.map +1 -0
  129. package/lib/core/ws/webSocketInterceptor.d.mts +5 -0
  130. package/lib/core/ws/webSocketInterceptor.d.ts +5 -0
  131. package/lib/core/ws/webSocketInterceptor.js +26 -0
  132. package/lib/core/ws/webSocketInterceptor.js.map +1 -0
  133. package/lib/core/ws/webSocketInterceptor.mjs +6 -0
  134. package/lib/core/ws/webSocketInterceptor.mjs.map +1 -0
  135. package/lib/core/ws.d.mts +75 -0
  136. package/lib/core/ws.d.ts +75 -0
  137. package/lib/core/ws.js +71 -0
  138. package/lib/core/ws.js.map +1 -0
  139. package/lib/core/ws.mjs +54 -0
  140. package/lib/core/ws.mjs.map +1 -0
  141. package/lib/iife/index.js +1413 -85
  142. package/lib/iife/index.js.map +1 -1
  143. package/lib/mockServiceWorker.js +1 -1
  144. package/lib/native/index.d.mts +6 -5
  145. package/lib/native/index.d.ts +6 -5
  146. package/lib/native/index.js +22 -4
  147. package/lib/native/index.js.map +1 -1
  148. package/lib/native/index.mjs +22 -4
  149. package/lib/native/index.mjs.map +1 -1
  150. package/lib/node/index.d.mts +8 -7
  151. package/lib/node/index.d.ts +8 -7
  152. package/lib/node/index.js +22 -4
  153. package/lib/node/index.js.map +1 -1
  154. package/lib/node/index.mjs +22 -4
  155. package/lib/node/index.mjs.map +1 -1
  156. package/package.json +10 -1
  157. package/src/browser/setupWorker/glossary.ts +10 -10
  158. package/src/browser/setupWorker/setupWorker.ts +32 -3
  159. package/src/browser/setupWorker/start/createRequestListener.ts +7 -1
  160. package/src/browser/setupWorker/start/createStartHandler.ts +5 -0
  161. package/src/browser/setupWorker/stop/createStop.ts +6 -0
  162. package/src/core/SetupApi.ts +28 -20
  163. package/src/core/handlers/WebSocketHandler.ts +142 -0
  164. package/src/core/index.ts +11 -1
  165. package/src/core/utils/executeHandlers.ts +6 -2
  166. package/src/core/utils/handleRequest.ts +1 -1
  167. package/src/core/utils/logging/getTimestamp.test.ts +20 -6
  168. package/src/core/utils/logging/getTimestamp.ts +11 -6
  169. package/src/core/utils/matching/matchRequestUrl.test.ts +44 -0
  170. package/src/core/utils/matching/matchRequestUrl.ts +4 -0
  171. package/src/core/ws/WebSocketClientManager.test.ts +164 -0
  172. package/src/core/ws/WebSocketClientManager.ts +211 -0
  173. package/src/core/ws/WebSocketClientStore.ts +14 -0
  174. package/src/core/ws/WebSocketIndexedDBClientStore.ts +145 -0
  175. package/src/core/ws/WebSocketMemoryClientStore.ts +27 -0
  176. package/src/core/ws/handleWebSocketEvent.ts +82 -0
  177. package/src/core/ws/utils/attachWebSocketLogger.ts +259 -0
  178. package/src/core/ws/utils/getMessageLength.test.ts +16 -0
  179. package/src/core/ws/utils/getMessageLength.ts +19 -0
  180. package/src/core/ws/utils/getPublicData.test.ts +38 -0
  181. package/src/core/ws/utils/getPublicData.ts +17 -0
  182. package/src/core/ws/utils/truncateMessage.test.ts +12 -0
  183. package/src/core/ws/utils/truncateMessage.ts +9 -0
  184. package/src/core/ws/webSocketInterceptor.ts +3 -0
  185. package/src/core/ws.test.ts +23 -0
  186. package/src/core/ws.ts +166 -0
  187. package/src/node/SetupServerApi.ts +8 -7
  188. package/src/node/SetupServerCommonApi.ts +29 -5
  189. package/src/node/glossary.ts +5 -7
  190. package/src/node/setupServer.ts +2 -1
@@ -15,5 +15,6 @@ declare function coercePath(path: string): string;
15
15
  * Returns the result of matching given request URL against a mask.
16
16
  */
17
17
  declare function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match;
18
+ declare function isPath(value: unknown): value is Path;
18
19
 
19
- export { type Match, type Path, type PathParams, coercePath, matchRequestUrl };
20
+ export { type Match, type Path, type PathParams, coercePath, isPath, matchRequestUrl };
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var matchRequestUrl_exports = {};
20
20
  __export(matchRequestUrl_exports, {
21
21
  coercePath: () => coercePath,
22
+ isPath: () => isPath,
22
23
  matchRequestUrl: () => matchRequestUrl
23
24
  });
24
25
  module.exports = __toCommonJS(matchRequestUrl_exports);
@@ -48,4 +49,7 @@ function matchRequestUrl(url, path, baseUrl) {
48
49
  params
49
50
  };
50
51
  }
52
+ function isPath(value) {
53
+ return typeof value === "string" || value instanceof RegExp;
54
+ }
51
55
  //# sourceMappingURL=matchRequestUrl.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/core/utils/matching/matchRequestUrl.ts"],"sourcesContent":["import { match } from 'path-to-regexp'\nimport { getCleanUrl } from '@mswjs/interceptors'\nimport { normalizePath } from './normalizePath'\n\nexport type Path = string | RegExp\nexport type PathParams<KeyType extends keyof any = string> = {\n [ParamName in KeyType]: string | ReadonlyArray<string>\n}\n\nexport interface Match {\n matches: boolean\n params?: PathParams\n}\n\n/**\n * Coerce a path supported by MSW into a path\n * supported by \"path-to-regexp\".\n */\nexport function coercePath(path: string): string {\n return (\n path\n /**\n * Replace wildcards (\"*\") with unnamed capturing groups\n * because \"path-to-regexp\" doesn't support wildcards.\n * Ignore path parameter' modifiers (i.e. \":name*\").\n */\n .replace(\n /([:a-zA-Z_-]*)(\\*{1,2})+/g,\n (_, parameterName: string | undefined, wildcard: string) => {\n const expression = '(.*)'\n\n if (!parameterName) {\n return expression\n }\n\n return parameterName.startsWith(':')\n ? `${parameterName}${wildcard}`\n : `${parameterName}${expression}`\n },\n )\n /**\n * Escape the port so that \"path-to-regexp\" can match\n * absolute URLs including port numbers.\n */\n .replace(/([^\\/])(:)(?=\\d+)/, '$1\\\\$2')\n /**\n * Escape the protocol so that \"path-to-regexp\" could match\n * absolute URL.\n * @see https://github.com/pillarjs/path-to-regexp/issues/259\n */\n .replace(/^([^\\/]+)(:)(?=\\/\\/)/, '$1\\\\$2')\n )\n}\n\n/**\n * Returns the result of matching given request URL against a mask.\n */\nexport function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match {\n const normalizedPath = normalizePath(path, baseUrl)\n const cleanPath =\n typeof normalizedPath === 'string'\n ? coercePath(normalizedPath)\n : normalizedPath\n\n const cleanUrl = getCleanUrl(url)\n const result = match(cleanPath, { decode: decodeURIComponent })(cleanUrl)\n const params = (result && (result.params as PathParams)) || {}\n\n return {\n matches: result !== false,\n params,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAsB;AACtB,0BAA4B;AAC5B,2BAA8B;AAgBvB,SAAS,WAAW,MAAsB;AAC/C,SACE,KAMG;AAAA,IACC;AAAA,IACA,CAAC,GAAG,eAAmC,aAAqB;AAC1D,YAAM,aAAa;AAEnB,UAAI,CAAC,eAAe;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,cAAc,WAAW,GAAG,IAC/B,GAAG,aAAa,GAAG,QAAQ,KAC3B,GAAG,aAAa,GAAG,UAAU;AAAA,IACnC;AAAA,EACF,EAKC,QAAQ,qBAAqB,QAAQ,EAMrC,QAAQ,wBAAwB,QAAQ;AAE/C;AAKO,SAAS,gBAAgB,KAAU,MAAY,SAAyB;AAC7E,QAAM,qBAAiB,oCAAc,MAAM,OAAO;AAClD,QAAM,YACJ,OAAO,mBAAmB,WACtB,WAAW,cAAc,IACzB;AAEN,QAAM,eAAW,iCAAY,GAAG;AAChC,QAAM,aAAS,6BAAM,WAAW,EAAE,QAAQ,mBAAmB,CAAC,EAAE,QAAQ;AACxE,QAAM,SAAU,UAAW,OAAO,UAA0B,CAAC;AAE7D,SAAO;AAAA,IACL,SAAS,WAAW;AAAA,IACpB;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/core/utils/matching/matchRequestUrl.ts"],"sourcesContent":["import { match } from 'path-to-regexp'\nimport { getCleanUrl } from '@mswjs/interceptors'\nimport { normalizePath } from './normalizePath'\n\nexport type Path = string | RegExp\nexport type PathParams<KeyType extends keyof any = string> = {\n [ParamName in KeyType]: string | ReadonlyArray<string>\n}\n\nexport interface Match {\n matches: boolean\n params?: PathParams\n}\n\n/**\n * Coerce a path supported by MSW into a path\n * supported by \"path-to-regexp\".\n */\nexport function coercePath(path: string): string {\n return (\n path\n /**\n * Replace wildcards (\"*\") with unnamed capturing groups\n * because \"path-to-regexp\" doesn't support wildcards.\n * Ignore path parameter' modifiers (i.e. \":name*\").\n */\n .replace(\n /([:a-zA-Z_-]*)(\\*{1,2})+/g,\n (_, parameterName: string | undefined, wildcard: string) => {\n const expression = '(.*)'\n\n if (!parameterName) {\n return expression\n }\n\n return parameterName.startsWith(':')\n ? `${parameterName}${wildcard}`\n : `${parameterName}${expression}`\n },\n )\n /**\n * Escape the port so that \"path-to-regexp\" can match\n * absolute URLs including port numbers.\n */\n .replace(/([^\\/])(:)(?=\\d+)/, '$1\\\\$2')\n /**\n * Escape the protocol so that \"path-to-regexp\" could match\n * absolute URL.\n * @see https://github.com/pillarjs/path-to-regexp/issues/259\n */\n .replace(/^([^\\/]+)(:)(?=\\/\\/)/, '$1\\\\$2')\n )\n}\n\n/**\n * Returns the result of matching given request URL against a mask.\n */\nexport function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match {\n const normalizedPath = normalizePath(path, baseUrl)\n const cleanPath =\n typeof normalizedPath === 'string'\n ? coercePath(normalizedPath)\n : normalizedPath\n\n const cleanUrl = getCleanUrl(url)\n const result = match(cleanPath, { decode: decodeURIComponent })(cleanUrl)\n const params = (result && (result.params as PathParams)) || {}\n\n return {\n matches: result !== false,\n params,\n }\n}\n\nexport function isPath(value: unknown): value is Path {\n return typeof value === 'string' || value instanceof RegExp\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAsB;AACtB,0BAA4B;AAC5B,2BAA8B;AAgBvB,SAAS,WAAW,MAAsB;AAC/C,SACE,KAMG;AAAA,IACC;AAAA,IACA,CAAC,GAAG,eAAmC,aAAqB;AAC1D,YAAM,aAAa;AAEnB,UAAI,CAAC,eAAe;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,cAAc,WAAW,GAAG,IAC/B,GAAG,aAAa,GAAG,QAAQ,KAC3B,GAAG,aAAa,GAAG,UAAU;AAAA,IACnC;AAAA,EACF,EAKC,QAAQ,qBAAqB,QAAQ,EAMrC,QAAQ,wBAAwB,QAAQ;AAE/C;AAKO,SAAS,gBAAgB,KAAU,MAAY,SAAyB;AAC7E,QAAM,qBAAiB,oCAAc,MAAM,OAAO;AAClD,QAAM,YACJ,OAAO,mBAAmB,WACtB,WAAW,cAAc,IACzB;AAEN,QAAM,eAAW,iCAAY,GAAG;AAChC,QAAM,aAAS,6BAAM,WAAW,EAAE,QAAQ,mBAAmB,CAAC,EAAE,QAAQ;AACxE,QAAM,SAAU,UAAW,OAAO,UAA0B,CAAC;AAE7D,SAAO;AAAA,IACL,SAAS,WAAW;AAAA,IACpB;AAAA,EACF;AACF;AAEO,SAAS,OAAO,OAA+B;AACpD,SAAO,OAAO,UAAU,YAAY,iBAAiB;AACvD;","names":[]}
@@ -24,8 +24,12 @@ function matchRequestUrl(url, path, baseUrl) {
24
24
  params
25
25
  };
26
26
  }
27
+ function isPath(value) {
28
+ return typeof value === "string" || value instanceof RegExp;
29
+ }
27
30
  export {
28
31
  coercePath,
32
+ isPath,
29
33
  matchRequestUrl
30
34
  };
31
35
  //# sourceMappingURL=matchRequestUrl.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/core/utils/matching/matchRequestUrl.ts"],"sourcesContent":["import { match } from 'path-to-regexp'\nimport { getCleanUrl } from '@mswjs/interceptors'\nimport { normalizePath } from './normalizePath'\n\nexport type Path = string | RegExp\nexport type PathParams<KeyType extends keyof any = string> = {\n [ParamName in KeyType]: string | ReadonlyArray<string>\n}\n\nexport interface Match {\n matches: boolean\n params?: PathParams\n}\n\n/**\n * Coerce a path supported by MSW into a path\n * supported by \"path-to-regexp\".\n */\nexport function coercePath(path: string): string {\n return (\n path\n /**\n * Replace wildcards (\"*\") with unnamed capturing groups\n * because \"path-to-regexp\" doesn't support wildcards.\n * Ignore path parameter' modifiers (i.e. \":name*\").\n */\n .replace(\n /([:a-zA-Z_-]*)(\\*{1,2})+/g,\n (_, parameterName: string | undefined, wildcard: string) => {\n const expression = '(.*)'\n\n if (!parameterName) {\n return expression\n }\n\n return parameterName.startsWith(':')\n ? `${parameterName}${wildcard}`\n : `${parameterName}${expression}`\n },\n )\n /**\n * Escape the port so that \"path-to-regexp\" can match\n * absolute URLs including port numbers.\n */\n .replace(/([^\\/])(:)(?=\\d+)/, '$1\\\\$2')\n /**\n * Escape the protocol so that \"path-to-regexp\" could match\n * absolute URL.\n * @see https://github.com/pillarjs/path-to-regexp/issues/259\n */\n .replace(/^([^\\/]+)(:)(?=\\/\\/)/, '$1\\\\$2')\n )\n}\n\n/**\n * Returns the result of matching given request URL against a mask.\n */\nexport function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match {\n const normalizedPath = normalizePath(path, baseUrl)\n const cleanPath =\n typeof normalizedPath === 'string'\n ? coercePath(normalizedPath)\n : normalizedPath\n\n const cleanUrl = getCleanUrl(url)\n const result = match(cleanPath, { decode: decodeURIComponent })(cleanUrl)\n const params = (result && (result.params as PathParams)) || {}\n\n return {\n matches: result !== false,\n params,\n }\n}\n"],"mappings":"AAAA,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAgBvB,SAAS,WAAW,MAAsB;AAC/C,SACE,KAMG;AAAA,IACC;AAAA,IACA,CAAC,GAAG,eAAmC,aAAqB;AAC1D,YAAM,aAAa;AAEnB,UAAI,CAAC,eAAe;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,cAAc,WAAW,GAAG,IAC/B,GAAG,aAAa,GAAG,QAAQ,KAC3B,GAAG,aAAa,GAAG,UAAU;AAAA,IACnC;AAAA,EACF,EAKC,QAAQ,qBAAqB,QAAQ,EAMrC,QAAQ,wBAAwB,QAAQ;AAE/C;AAKO,SAAS,gBAAgB,KAAU,MAAY,SAAyB;AAC7E,QAAM,iBAAiB,cAAc,MAAM,OAAO;AAClD,QAAM,YACJ,OAAO,mBAAmB,WACtB,WAAW,cAAc,IACzB;AAEN,QAAM,WAAW,YAAY,GAAG;AAChC,QAAM,SAAS,MAAM,WAAW,EAAE,QAAQ,mBAAmB,CAAC,EAAE,QAAQ;AACxE,QAAM,SAAU,UAAW,OAAO,UAA0B,CAAC;AAE7D,SAAO;AAAA,IACL,SAAS,WAAW;AAAA,IACpB;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/core/utils/matching/matchRequestUrl.ts"],"sourcesContent":["import { match } from 'path-to-regexp'\nimport { getCleanUrl } from '@mswjs/interceptors'\nimport { normalizePath } from './normalizePath'\n\nexport type Path = string | RegExp\nexport type PathParams<KeyType extends keyof any = string> = {\n [ParamName in KeyType]: string | ReadonlyArray<string>\n}\n\nexport interface Match {\n matches: boolean\n params?: PathParams\n}\n\n/**\n * Coerce a path supported by MSW into a path\n * supported by \"path-to-regexp\".\n */\nexport function coercePath(path: string): string {\n return (\n path\n /**\n * Replace wildcards (\"*\") with unnamed capturing groups\n * because \"path-to-regexp\" doesn't support wildcards.\n * Ignore path parameter' modifiers (i.e. \":name*\").\n */\n .replace(\n /([:a-zA-Z_-]*)(\\*{1,2})+/g,\n (_, parameterName: string | undefined, wildcard: string) => {\n const expression = '(.*)'\n\n if (!parameterName) {\n return expression\n }\n\n return parameterName.startsWith(':')\n ? `${parameterName}${wildcard}`\n : `${parameterName}${expression}`\n },\n )\n /**\n * Escape the port so that \"path-to-regexp\" can match\n * absolute URLs including port numbers.\n */\n .replace(/([^\\/])(:)(?=\\d+)/, '$1\\\\$2')\n /**\n * Escape the protocol so that \"path-to-regexp\" could match\n * absolute URL.\n * @see https://github.com/pillarjs/path-to-regexp/issues/259\n */\n .replace(/^([^\\/]+)(:)(?=\\/\\/)/, '$1\\\\$2')\n )\n}\n\n/**\n * Returns the result of matching given request URL against a mask.\n */\nexport function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match {\n const normalizedPath = normalizePath(path, baseUrl)\n const cleanPath =\n typeof normalizedPath === 'string'\n ? coercePath(normalizedPath)\n : normalizedPath\n\n const cleanUrl = getCleanUrl(url)\n const result = match(cleanPath, { decode: decodeURIComponent })(cleanUrl)\n const params = (result && (result.params as PathParams)) || {}\n\n return {\n matches: result !== false,\n params,\n }\n}\n\nexport function isPath(value: unknown): value is Path {\n return typeof value === 'string' || value instanceof RegExp\n}\n"],"mappings":"AAAA,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAgBvB,SAAS,WAAW,MAAsB;AAC/C,SACE,KAMG;AAAA,IACC;AAAA,IACA,CAAC,GAAG,eAAmC,aAAqB;AAC1D,YAAM,aAAa;AAEnB,UAAI,CAAC,eAAe;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,cAAc,WAAW,GAAG,IAC/B,GAAG,aAAa,GAAG,QAAQ,KAC3B,GAAG,aAAa,GAAG,UAAU;AAAA,IACnC;AAAA,EACF,EAKC,QAAQ,qBAAqB,QAAQ,EAMrC,QAAQ,wBAAwB,QAAQ;AAE/C;AAKO,SAAS,gBAAgB,KAAU,MAAY,SAAyB;AAC7E,QAAM,iBAAiB,cAAc,MAAM,OAAO;AAClD,QAAM,YACJ,OAAO,mBAAmB,WACtB,WAAW,cAAc,IACzB;AAEN,QAAM,WAAW,YAAY,GAAG;AAChC,QAAM,SAAS,MAAM,WAAW,EAAE,QAAQ,mBAAmB,CAAC,EAAE,QAAQ;AACxE,QAAM,SAAU,UAAW,OAAO,UAA0B,CAAC;AAE7D,SAAO;AAAA,IACL,SAAS,WAAW;AAAA,IACpB;AAAA,EACF;AACF;AAEO,SAAS,OAAO,OAA+B;AACpD,SAAO,OAAO,UAAU,YAAY,iBAAiB;AACvD;","names":[]}
@@ -0,0 +1,63 @@
1
+ import { WebSocketData, WebSocketClientConnectionProtocol, WebSocketClientConnection } from '@mswjs/interceptors/WebSocket';
2
+
3
+ type WebSocketBroadcastChannelMessage = {
4
+ type: 'extraneous:send';
5
+ payload: {
6
+ clientId: string;
7
+ data: WebSocketData;
8
+ };
9
+ } | {
10
+ type: 'extraneous:close';
11
+ payload: {
12
+ clientId: string;
13
+ code?: number;
14
+ reason?: string;
15
+ };
16
+ };
17
+ /**
18
+ * A manager responsible for accumulating WebSocket client
19
+ * connections across different browser runtimes.
20
+ */
21
+ declare class WebSocketClientManager {
22
+ private channel;
23
+ private store;
24
+ private runtimeClients;
25
+ private allClients;
26
+ constructor(channel: BroadcastChannel);
27
+ private flushDatabaseToMemory;
28
+ private removeRuntimeClients;
29
+ /**
30
+ * All active WebSocket client connections.
31
+ */
32
+ get clients(): Set<WebSocketClientConnectionProtocol>;
33
+ /**
34
+ * Notify other runtimes about the database update
35
+ * using the shared `BroadcastChannel` instance.
36
+ */
37
+ private notifyOthersAboutDatabaseUpdate;
38
+ private addClient;
39
+ /**
40
+ * Adds the given `WebSocket` client connection to the set
41
+ * of all connections. The given connection is always the complete
42
+ * connection object because `addConnection()` is called only
43
+ * for the opened connections in the same runtime.
44
+ */
45
+ addConnection(client: WebSocketClientConnection): Promise<void>;
46
+ }
47
+ /**
48
+ * A wrapper class to operate with WebSocket client connections
49
+ * from other runtimes. This class maintains 1-1 public API
50
+ * compatibility to the `WebSocketClientConnection` but relies
51
+ * on the given `BroadcastChannel` to communicate instructions
52
+ * with the client connections from other runtimes.
53
+ */
54
+ declare class WebSocketRemoteClientConnection implements WebSocketClientConnectionProtocol {
55
+ readonly id: string;
56
+ readonly url: URL;
57
+ private channel;
58
+ constructor(id: string, url: URL, channel: BroadcastChannel);
59
+ send(data: WebSocketData): void;
60
+ close(code?: number | undefined, reason?: string | undefined): void;
61
+ }
62
+
63
+ export { type WebSocketBroadcastChannelMessage, WebSocketClientManager, WebSocketRemoteClientConnection };
@@ -0,0 +1,63 @@
1
+ import { WebSocketData, WebSocketClientConnectionProtocol, WebSocketClientConnection } from '@mswjs/interceptors/WebSocket';
2
+
3
+ type WebSocketBroadcastChannelMessage = {
4
+ type: 'extraneous:send';
5
+ payload: {
6
+ clientId: string;
7
+ data: WebSocketData;
8
+ };
9
+ } | {
10
+ type: 'extraneous:close';
11
+ payload: {
12
+ clientId: string;
13
+ code?: number;
14
+ reason?: string;
15
+ };
16
+ };
17
+ /**
18
+ * A manager responsible for accumulating WebSocket client
19
+ * connections across different browser runtimes.
20
+ */
21
+ declare class WebSocketClientManager {
22
+ private channel;
23
+ private store;
24
+ private runtimeClients;
25
+ private allClients;
26
+ constructor(channel: BroadcastChannel);
27
+ private flushDatabaseToMemory;
28
+ private removeRuntimeClients;
29
+ /**
30
+ * All active WebSocket client connections.
31
+ */
32
+ get clients(): Set<WebSocketClientConnectionProtocol>;
33
+ /**
34
+ * Notify other runtimes about the database update
35
+ * using the shared `BroadcastChannel` instance.
36
+ */
37
+ private notifyOthersAboutDatabaseUpdate;
38
+ private addClient;
39
+ /**
40
+ * Adds the given `WebSocket` client connection to the set
41
+ * of all connections. The given connection is always the complete
42
+ * connection object because `addConnection()` is called only
43
+ * for the opened connections in the same runtime.
44
+ */
45
+ addConnection(client: WebSocketClientConnection): Promise<void>;
46
+ }
47
+ /**
48
+ * A wrapper class to operate with WebSocket client connections
49
+ * from other runtimes. This class maintains 1-1 public API
50
+ * compatibility to the `WebSocketClientConnection` but relies
51
+ * on the given `BroadcastChannel` to communicate instructions
52
+ * with the client connections from other runtimes.
53
+ */
54
+ declare class WebSocketRemoteClientConnection implements WebSocketClientConnectionProtocol {
55
+ readonly id: string;
56
+ readonly url: URL;
57
+ private channel;
58
+ constructor(id: string, url: URL, channel: BroadcastChannel);
59
+ send(data: WebSocketData): void;
60
+ close(code?: number | undefined, reason?: string | undefined): void;
61
+ }
62
+
63
+ export { type WebSocketBroadcastChannelMessage, WebSocketClientManager, WebSocketRemoteClientConnection };
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var WebSocketClientManager_exports = {};
20
+ __export(WebSocketClientManager_exports, {
21
+ WebSocketClientManager: () => WebSocketClientManager,
22
+ WebSocketRemoteClientConnection: () => WebSocketRemoteClientConnection
23
+ });
24
+ module.exports = __toCommonJS(WebSocketClientManager_exports);
25
+ var import_WebSocketMemoryClientStore = require("./WebSocketMemoryClientStore.js");
26
+ var import_WebSocketIndexedDBClientStore = require("./WebSocketIndexedDBClientStore.js");
27
+ class WebSocketClientManager {
28
+ constructor(channel) {
29
+ this.channel = channel;
30
+ this.store = typeof indexedDB !== "undefined" ? new import_WebSocketIndexedDBClientStore.WebSocketIndexedDBClientStore() : new import_WebSocketMemoryClientStore.WebSocketMemoryClientStore();
31
+ this.runtimeClients = /* @__PURE__ */ new Map();
32
+ this.allClients = /* @__PURE__ */ new Set();
33
+ this.channel.addEventListener("message", (message) => {
34
+ if (message.data?.type === "db:update") {
35
+ this.flushDatabaseToMemory();
36
+ }
37
+ });
38
+ if (typeof window !== "undefined") {
39
+ window.addEventListener("message", async (message) => {
40
+ if (message.data?.type === "msw/worker:stop") {
41
+ await this.removeRuntimeClients();
42
+ }
43
+ });
44
+ }
45
+ }
46
+ store;
47
+ runtimeClients;
48
+ allClients;
49
+ async flushDatabaseToMemory() {
50
+ const storedClients = await this.store.getAll();
51
+ this.allClients = new Set(
52
+ storedClients.map((client) => {
53
+ const runtimeClient = this.runtimeClients.get(client.id);
54
+ if (runtimeClient) {
55
+ return runtimeClient;
56
+ }
57
+ return new WebSocketRemoteClientConnection(
58
+ client.id,
59
+ new URL(client.url),
60
+ this.channel
61
+ );
62
+ })
63
+ );
64
+ }
65
+ async removeRuntimeClients() {
66
+ await this.store.deleteMany(Array.from(this.runtimeClients.keys()));
67
+ this.runtimeClients.clear();
68
+ await this.flushDatabaseToMemory();
69
+ this.notifyOthersAboutDatabaseUpdate();
70
+ }
71
+ /**
72
+ * All active WebSocket client connections.
73
+ */
74
+ get clients() {
75
+ return this.allClients;
76
+ }
77
+ /**
78
+ * Notify other runtimes about the database update
79
+ * using the shared `BroadcastChannel` instance.
80
+ */
81
+ notifyOthersAboutDatabaseUpdate() {
82
+ this.channel.postMessage({ type: "db:update" });
83
+ }
84
+ async addClient(client) {
85
+ await this.store.add(client);
86
+ await this.flushDatabaseToMemory();
87
+ this.notifyOthersAboutDatabaseUpdate();
88
+ }
89
+ /**
90
+ * Adds the given `WebSocket` client connection to the set
91
+ * of all connections. The given connection is always the complete
92
+ * connection object because `addConnection()` is called only
93
+ * for the opened connections in the same runtime.
94
+ */
95
+ async addConnection(client) {
96
+ this.runtimeClients.set(client.id, client);
97
+ await this.addClient(client);
98
+ const handleExtraneousMessage = (message) => {
99
+ const { type, payload } = message.data;
100
+ if (typeof payload === "object" && "clientId" in payload && payload.clientId !== client.id) {
101
+ return;
102
+ }
103
+ switch (type) {
104
+ case "extraneous:send": {
105
+ client.send(payload.data);
106
+ break;
107
+ }
108
+ case "extraneous:close": {
109
+ client.close(payload.code, payload.reason);
110
+ break;
111
+ }
112
+ }
113
+ };
114
+ const abortController = new AbortController();
115
+ this.channel.addEventListener("message", handleExtraneousMessage, {
116
+ signal: abortController.signal
117
+ });
118
+ client.addEventListener("close", () => abortController.abort(), {
119
+ once: true
120
+ });
121
+ }
122
+ }
123
+ class WebSocketRemoteClientConnection {
124
+ constructor(id, url, channel) {
125
+ this.id = id;
126
+ this.url = url;
127
+ this.channel = channel;
128
+ }
129
+ send(data) {
130
+ this.channel.postMessage({
131
+ type: "extraneous:send",
132
+ payload: {
133
+ clientId: this.id,
134
+ data
135
+ }
136
+ });
137
+ }
138
+ close(code, reason) {
139
+ this.channel.postMessage({
140
+ type: "extraneous:close",
141
+ payload: {
142
+ clientId: this.id,
143
+ code,
144
+ reason
145
+ }
146
+ });
147
+ }
148
+ }
149
+ //# sourceMappingURL=WebSocketClientManager.js.map
@@ -0,0 +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 { 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":"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","names":[]}
@@ -0,0 +1,129 @@
1
+ import { WebSocketMemoryClientStore } from './WebSocketMemoryClientStore.mjs';
2
+ import { WebSocketIndexedDBClientStore } from './WebSocketIndexedDBClientStore.mjs';
3
+ class WebSocketClientManager {
4
+ constructor(channel) {
5
+ this.channel = channel;
6
+ this.store = typeof indexedDB !== "undefined" ? new WebSocketIndexedDBClientStore() : new WebSocketMemoryClientStore();
7
+ this.runtimeClients = /* @__PURE__ */ new Map();
8
+ this.allClients = /* @__PURE__ */ new Set();
9
+ this.channel.addEventListener("message", (message) => {
10
+ if (message.data?.type === "db:update") {
11
+ this.flushDatabaseToMemory();
12
+ }
13
+ });
14
+ if (typeof window !== "undefined") {
15
+ window.addEventListener("message", async (message) => {
16
+ if (message.data?.type === "msw/worker:stop") {
17
+ await this.removeRuntimeClients();
18
+ }
19
+ });
20
+ }
21
+ }
22
+ store;
23
+ runtimeClients;
24
+ allClients;
25
+ async flushDatabaseToMemory() {
26
+ const storedClients = await this.store.getAll();
27
+ this.allClients = new Set(
28
+ storedClients.map((client) => {
29
+ const runtimeClient = this.runtimeClients.get(client.id);
30
+ if (runtimeClient) {
31
+ return runtimeClient;
32
+ }
33
+ return new WebSocketRemoteClientConnection(
34
+ client.id,
35
+ new URL(client.url),
36
+ this.channel
37
+ );
38
+ })
39
+ );
40
+ }
41
+ async removeRuntimeClients() {
42
+ await this.store.deleteMany(Array.from(this.runtimeClients.keys()));
43
+ this.runtimeClients.clear();
44
+ await this.flushDatabaseToMemory();
45
+ this.notifyOthersAboutDatabaseUpdate();
46
+ }
47
+ /**
48
+ * All active WebSocket client connections.
49
+ */
50
+ get clients() {
51
+ return this.allClients;
52
+ }
53
+ /**
54
+ * Notify other runtimes about the database update
55
+ * using the shared `BroadcastChannel` instance.
56
+ */
57
+ notifyOthersAboutDatabaseUpdate() {
58
+ this.channel.postMessage({ type: "db:update" });
59
+ }
60
+ async addClient(client) {
61
+ await this.store.add(client);
62
+ await this.flushDatabaseToMemory();
63
+ this.notifyOthersAboutDatabaseUpdate();
64
+ }
65
+ /**
66
+ * Adds the given `WebSocket` client connection to the set
67
+ * of all connections. The given connection is always the complete
68
+ * connection object because `addConnection()` is called only
69
+ * for the opened connections in the same runtime.
70
+ */
71
+ async addConnection(client) {
72
+ this.runtimeClients.set(client.id, client);
73
+ await this.addClient(client);
74
+ const handleExtraneousMessage = (message) => {
75
+ const { type, payload } = message.data;
76
+ if (typeof payload === "object" && "clientId" in payload && payload.clientId !== client.id) {
77
+ return;
78
+ }
79
+ switch (type) {
80
+ case "extraneous:send": {
81
+ client.send(payload.data);
82
+ break;
83
+ }
84
+ case "extraneous:close": {
85
+ client.close(payload.code, payload.reason);
86
+ break;
87
+ }
88
+ }
89
+ };
90
+ const abortController = new AbortController();
91
+ this.channel.addEventListener("message", handleExtraneousMessage, {
92
+ signal: abortController.signal
93
+ });
94
+ client.addEventListener("close", () => abortController.abort(), {
95
+ once: true
96
+ });
97
+ }
98
+ }
99
+ class WebSocketRemoteClientConnection {
100
+ constructor(id, url, channel) {
101
+ this.id = id;
102
+ this.url = url;
103
+ this.channel = channel;
104
+ }
105
+ send(data) {
106
+ this.channel.postMessage({
107
+ type: "extraneous:send",
108
+ payload: {
109
+ clientId: this.id,
110
+ data
111
+ }
112
+ });
113
+ }
114
+ close(code, reason) {
115
+ this.channel.postMessage({
116
+ type: "extraneous:close",
117
+ payload: {
118
+ clientId: this.id,
119
+ code,
120
+ reason
121
+ }
122
+ });
123
+ }
124
+ }
125
+ export {
126
+ WebSocketClientManager,
127
+ WebSocketRemoteClientConnection
128
+ };
129
+ //# sourceMappingURL=WebSocketClientManager.mjs.map
@@ -0,0 +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 { 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":"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","names":[]}
@@ -0,0 +1,13 @@
1
+ import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket';
2
+
3
+ interface SerializedWebSocketClient {
4
+ id: string;
5
+ url: string;
6
+ }
7
+ declare abstract class WebSocketClientStore {
8
+ abstract add(client: WebSocketClientConnectionProtocol): Promise<void>;
9
+ abstract getAll(): Promise<Array<SerializedWebSocketClient>>;
10
+ abstract deleteMany(clientIds: Array<string>): Promise<void>;
11
+ }
12
+
13
+ export { type SerializedWebSocketClient, WebSocketClientStore };
@@ -0,0 +1,13 @@
1
+ import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket';
2
+
3
+ interface SerializedWebSocketClient {
4
+ id: string;
5
+ url: string;
6
+ }
7
+ declare abstract class WebSocketClientStore {
8
+ abstract add(client: WebSocketClientConnectionProtocol): Promise<void>;
9
+ abstract getAll(): Promise<Array<SerializedWebSocketClient>>;
10
+ abstract deleteMany(clientIds: Array<string>): Promise<void>;
11
+ }
12
+
13
+ export { type SerializedWebSocketClient, WebSocketClientStore };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var WebSocketClientStore_exports = {};
20
+ __export(WebSocketClientStore_exports, {
21
+ WebSocketClientStore: () => WebSocketClientStore
22
+ });
23
+ module.exports = __toCommonJS(WebSocketClientStore_exports);
24
+ class WebSocketClientStore {
25
+ }
26
+ //# sourceMappingURL=WebSocketClientStore.js.map
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,6 @@
1
+ class WebSocketClientStore {
2
+ }
3
+ export {
4
+ WebSocketClientStore
5
+ };
6
+ //# sourceMappingURL=WebSocketClientStore.mjs.map
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,15 @@
1
+ import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket';
2
+ import { WebSocketClientStore, SerializedWebSocketClient } from './WebSocketClientStore.mjs';
3
+ import '@mswjs/interceptors/WebSocket';
4
+
5
+ declare class WebSocketIndexedDBClientStore implements WebSocketClientStore {
6
+ private db;
7
+ constructor();
8
+ add(client: WebSocketClientConnectionProtocol): Promise<void>;
9
+ getAll(): Promise<Array<SerializedWebSocketClient>>;
10
+ deleteMany(clientIds: Array<string>): Promise<void>;
11
+ private createDatabase;
12
+ private getStore;
13
+ }
14
+
15
+ export { WebSocketIndexedDBClientStore };
@@ -0,0 +1,15 @@
1
+ import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket';
2
+ import { WebSocketClientStore, SerializedWebSocketClient } from './WebSocketClientStore.js';
3
+ import '@mswjs/interceptors/WebSocket';
4
+
5
+ declare class WebSocketIndexedDBClientStore implements WebSocketClientStore {
6
+ private db;
7
+ constructor();
8
+ add(client: WebSocketClientConnectionProtocol): Promise<void>;
9
+ getAll(): Promise<Array<SerializedWebSocketClient>>;
10
+ deleteMany(clientIds: Array<string>): Promise<void>;
11
+ private createDatabase;
12
+ private getStore;
13
+ }
14
+
15
+ export { WebSocketIndexedDBClientStore };