msw 2.5.2 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) 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 +28 -2
  4. package/lib/browser/index.js.map +1 -1
  5. package/lib/browser/index.mjs +28 -2
  6. package/lib/browser/index.mjs.map +1 -1
  7. package/lib/core/{GraphQLHandler-ClMB0BOy.d.mts → GraphQLHandler-B6uni-E_.d.mts} +1 -1
  8. package/lib/core/{GraphQLHandler-D6mLMXGZ.d.ts → GraphQLHandler-Cjm7JNGi.d.ts} +1 -1
  9. package/lib/core/{HttpResponse-vn-Pb4Bi.d.mts → HttpResponse-63H9vVoL.d.mts} +1 -0
  10. package/lib/core/{HttpResponse-DaYkf3ml.d.ts → HttpResponse-DzhqZzTK.d.ts} +1 -0
  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/RequestHandler.js +2 -0
  30. package/lib/core/handlers/RequestHandler.js.map +1 -1
  31. package/lib/core/handlers/RequestHandler.mjs +2 -0
  32. package/lib/core/handlers/RequestHandler.mjs.map +1 -1
  33. package/lib/core/handlers/WebSocketHandler.d.mts +34 -0
  34. package/lib/core/handlers/WebSocketHandler.d.ts +34 -0
  35. package/lib/core/handlers/WebSocketHandler.js +122 -0
  36. package/lib/core/handlers/WebSocketHandler.js.map +1 -0
  37. package/lib/core/handlers/WebSocketHandler.mjs +104 -0
  38. package/lib/core/handlers/WebSocketHandler.mjs.map +1 -0
  39. package/lib/core/handlers/common.d.mts +3 -0
  40. package/lib/core/handlers/common.d.ts +3 -0
  41. package/lib/core/handlers/common.js +17 -0
  42. package/lib/core/handlers/common.js.map +1 -0
  43. package/lib/core/handlers/common.mjs +1 -0
  44. package/lib/core/handlers/common.mjs.map +1 -0
  45. package/lib/core/http.d.mts +1 -1
  46. package/lib/core/http.d.ts +1 -1
  47. package/lib/core/index.d.mts +5 -2
  48. package/lib/core/index.d.ts +5 -2
  49. package/lib/core/index.js +5 -1
  50. package/lib/core/index.js.map +1 -1
  51. package/lib/core/index.mjs +7 -1
  52. package/lib/core/index.mjs.map +1 -1
  53. package/lib/core/passthrough.d.mts +1 -1
  54. package/lib/core/passthrough.d.ts +1 -1
  55. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  56. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  57. package/lib/core/utils/executeHandlers.d.mts +1 -1
  58. package/lib/core/utils/executeHandlers.d.ts +1 -1
  59. package/lib/core/utils/executeHandlers.js.map +1 -1
  60. package/lib/core/utils/executeHandlers.mjs.map +1 -1
  61. package/lib/core/utils/handleRequest.d.mts +2 -2
  62. package/lib/core/utils/handleRequest.d.ts +2 -2
  63. package/lib/core/utils/handleRequest.js.map +1 -1
  64. package/lib/core/utils/handleRequest.mjs.map +1 -1
  65. package/lib/core/utils/internal/isHandlerKind.d.mts +17 -0
  66. package/lib/core/utils/internal/isHandlerKind.d.ts +17 -0
  67. package/lib/core/utils/internal/isHandlerKind.js +29 -0
  68. package/lib/core/utils/internal/isHandlerKind.js.map +1 -0
  69. package/lib/core/utils/internal/isHandlerKind.mjs +9 -0
  70. package/lib/core/utils/internal/isHandlerKind.mjs.map +1 -0
  71. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
  72. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
  73. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  74. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  75. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  76. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  77. package/lib/core/utils/logging/getTimestamp.d.mts +4 -1
  78. package/lib/core/utils/logging/getTimestamp.d.ts +4 -1
  79. package/lib/core/utils/logging/getTimestamp.js +6 -2
  80. package/lib/core/utils/logging/getTimestamp.js.map +1 -1
  81. package/lib/core/utils/logging/getTimestamp.mjs +6 -2
  82. package/lib/core/utils/logging/getTimestamp.mjs.map +1 -1
  83. package/lib/core/utils/matching/matchRequestUrl.d.mts +2 -1
  84. package/lib/core/utils/matching/matchRequestUrl.d.ts +2 -1
  85. package/lib/core/utils/matching/matchRequestUrl.js +4 -0
  86. package/lib/core/utils/matching/matchRequestUrl.js.map +1 -1
  87. package/lib/core/utils/matching/matchRequestUrl.mjs +4 -0
  88. package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -1
  89. package/lib/core/ws/WebSocketClientManager.d.mts +63 -0
  90. package/lib/core/ws/WebSocketClientManager.d.ts +63 -0
  91. package/lib/core/ws/WebSocketClientManager.js +149 -0
  92. package/lib/core/ws/WebSocketClientManager.js.map +1 -0
  93. package/lib/core/ws/WebSocketClientManager.mjs +129 -0
  94. package/lib/core/ws/WebSocketClientManager.mjs.map +1 -0
  95. package/lib/core/ws/WebSocketClientStore.d.mts +13 -0
  96. package/lib/core/ws/WebSocketClientStore.d.ts +13 -0
  97. package/lib/core/ws/WebSocketClientStore.js +26 -0
  98. package/lib/core/ws/WebSocketClientStore.js.map +1 -0
  99. package/lib/core/ws/WebSocketClientStore.mjs +6 -0
  100. package/lib/core/ws/WebSocketClientStore.mjs.map +1 -0
  101. package/lib/core/ws/WebSocketIndexedDBClientStore.d.mts +15 -0
  102. package/lib/core/ws/WebSocketIndexedDBClientStore.d.ts +15 -0
  103. package/lib/core/ws/WebSocketIndexedDBClientStore.js +130 -0
  104. package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -0
  105. package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +110 -0
  106. package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -0
  107. package/lib/core/ws/WebSocketMemoryClientStore.d.mts +13 -0
  108. package/lib/core/ws/WebSocketMemoryClientStore.d.ts +13 -0
  109. package/lib/core/ws/WebSocketMemoryClientStore.js +41 -0
  110. package/lib/core/ws/WebSocketMemoryClientStore.js.map +1 -0
  111. package/lib/core/ws/WebSocketMemoryClientStore.mjs +21 -0
  112. package/lib/core/ws/WebSocketMemoryClientStore.mjs.map +1 -0
  113. package/lib/core/ws/handleWebSocketEvent.d.mts +19 -0
  114. package/lib/core/ws/handleWebSocketEvent.d.ts +19 -0
  115. package/lib/core/ws/handleWebSocketEvent.js +74 -0
  116. package/lib/core/ws/handleWebSocketEvent.js.map +1 -0
  117. package/lib/core/ws/handleWebSocketEvent.mjs +56 -0
  118. package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -0
  119. package/lib/core/ws/utils/attachWebSocketLogger.d.mts +12 -0
  120. package/lib/core/ws/utils/attachWebSocketLogger.d.ts +12 -0
  121. package/lib/core/ws/utils/attachWebSocketLogger.js +198 -0
  122. package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -0
  123. package/lib/core/ws/utils/attachWebSocketLogger.mjs +178 -0
  124. package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -0
  125. package/lib/core/ws/utils/getMessageLength.d.mts +11 -0
  126. package/lib/core/ws/utils/getMessageLength.d.ts +11 -0
  127. package/lib/core/ws/utils/getMessageLength.js +33 -0
  128. package/lib/core/ws/utils/getMessageLength.js.map +1 -0
  129. package/lib/core/ws/utils/getMessageLength.mjs +13 -0
  130. package/lib/core/ws/utils/getMessageLength.mjs.map +1 -0
  131. package/lib/core/ws/utils/getPublicData.d.mts +5 -0
  132. package/lib/core/ws/utils/getPublicData.d.ts +5 -0
  133. package/lib/core/ws/utils/getPublicData.js +36 -0
  134. package/lib/core/ws/utils/getPublicData.js.map +1 -0
  135. package/lib/core/ws/utils/getPublicData.mjs +16 -0
  136. package/lib/core/ws/utils/getPublicData.mjs.map +1 -0
  137. package/lib/core/ws/utils/truncateMessage.d.mts +3 -0
  138. package/lib/core/ws/utils/truncateMessage.d.ts +3 -0
  139. package/lib/core/ws/utils/truncateMessage.js +31 -0
  140. package/lib/core/ws/utils/truncateMessage.js.map +1 -0
  141. package/lib/core/ws/utils/truncateMessage.mjs +11 -0
  142. package/lib/core/ws/utils/truncateMessage.mjs.map +1 -0
  143. package/lib/core/ws/webSocketInterceptor.d.mts +5 -0
  144. package/lib/core/ws/webSocketInterceptor.d.ts +5 -0
  145. package/lib/core/ws/webSocketInterceptor.js +26 -0
  146. package/lib/core/ws/webSocketInterceptor.js.map +1 -0
  147. package/lib/core/ws/webSocketInterceptor.mjs +6 -0
  148. package/lib/core/ws/webSocketInterceptor.mjs.map +1 -0
  149. package/lib/core/ws.d.mts +75 -0
  150. package/lib/core/ws.d.ts +75 -0
  151. package/lib/core/ws.js +71 -0
  152. package/lib/core/ws.js.map +1 -0
  153. package/lib/core/ws.mjs +54 -0
  154. package/lib/core/ws.mjs.map +1 -0
  155. package/lib/iife/index.js +1420 -86
  156. package/lib/iife/index.js.map +1 -1
  157. package/lib/mockServiceWorker.js +1 -1
  158. package/lib/native/index.d.mts +6 -5
  159. package/lib/native/index.d.ts +6 -5
  160. package/lib/native/index.js +19 -4
  161. package/lib/native/index.js.map +1 -1
  162. package/lib/native/index.mjs +19 -4
  163. package/lib/native/index.mjs.map +1 -1
  164. package/lib/node/index.d.mts +8 -7
  165. package/lib/node/index.d.ts +8 -7
  166. package/lib/node/index.js +19 -4
  167. package/lib/node/index.js.map +1 -1
  168. package/lib/node/index.mjs +19 -4
  169. package/lib/node/index.mjs.map +1 -1
  170. package/package.json +10 -1
  171. package/src/browser/setupWorker/glossary.ts +10 -10
  172. package/src/browser/setupWorker/setupWorker.ts +32 -3
  173. package/src/browser/setupWorker/start/createFallbackRequestListener.ts +2 -1
  174. package/src/browser/setupWorker/start/createRequestListener.ts +2 -1
  175. package/src/browser/setupWorker/start/createStartHandler.ts +5 -0
  176. package/src/browser/setupWorker/stop/createStop.ts +6 -0
  177. package/src/core/SetupApi.ts +28 -20
  178. package/src/core/handlers/RequestHandler.ts +4 -0
  179. package/src/core/handlers/WebSocketHandler.ts +146 -0
  180. package/src/core/handlers/common.ts +1 -0
  181. package/src/core/index.ts +11 -1
  182. package/src/core/utils/executeHandlers.ts +1 -1
  183. package/src/core/utils/handleRequest.ts +1 -1
  184. package/src/core/utils/internal/isHandlerKind.test.ts +64 -0
  185. package/src/core/utils/internal/isHandlerKind.ts +21 -0
  186. package/src/core/utils/logging/getTimestamp.test.ts +20 -6
  187. package/src/core/utils/logging/getTimestamp.ts +11 -6
  188. package/src/core/utils/matching/matchRequestUrl.test.ts +44 -0
  189. package/src/core/utils/matching/matchRequestUrl.ts +4 -0
  190. package/src/core/ws/WebSocketClientManager.test.ts +164 -0
  191. package/src/core/ws/WebSocketClientManager.ts +211 -0
  192. package/src/core/ws/WebSocketClientStore.ts +14 -0
  193. package/src/core/ws/WebSocketIndexedDBClientStore.ts +145 -0
  194. package/src/core/ws/WebSocketMemoryClientStore.ts +27 -0
  195. package/src/core/ws/handleWebSocketEvent.ts +83 -0
  196. package/src/core/ws/utils/attachWebSocketLogger.ts +259 -0
  197. package/src/core/ws/utils/getMessageLength.test.ts +16 -0
  198. package/src/core/ws/utils/getMessageLength.ts +19 -0
  199. package/src/core/ws/utils/getPublicData.test.ts +38 -0
  200. package/src/core/ws/utils/getPublicData.ts +17 -0
  201. package/src/core/ws/utils/truncateMessage.test.ts +12 -0
  202. package/src/core/ws/utils/truncateMessage.ts +9 -0
  203. package/src/core/ws/webSocketInterceptor.ts +3 -0
  204. package/src/core/ws.test.ts +23 -0
  205. package/src/core/ws.ts +166 -0
  206. package/src/node/SetupServerApi.ts +8 -7
  207. package/src/node/SetupServerCommonApi.ts +25 -5
  208. package/src/node/glossary.ts +5 -7
  209. package/src/node/setupServer.ts +2 -1
@@ -0,0 +1,17 @@
1
+ import { HandlerKind } from '../../handlers/common.mjs';
2
+ import { R as RequestHandler } from '../../HttpResponse-63H9vVoL.mjs';
3
+ import { WebSocketHandler } from '../../handlers/WebSocketHandler.mjs';
4
+ import './isIterable.mjs';
5
+ import '../../typeUtils.mjs';
6
+ import 'strict-event-emitter';
7
+ import '@mswjs/interceptors/WebSocket';
8
+ import '../matching/matchRequestUrl.mjs';
9
+
10
+ /**
11
+ * A filter function that ensures that the provided argument
12
+ * is a handler of the given kind. This helps differentiate
13
+ * between different kinds of handlers, e.g. request and event handlers.
14
+ */
15
+ declare function isHandlerKind<K extends HandlerKind>(kind: K): (input: unknown) => input is K extends "EventHandler" ? WebSocketHandler : RequestHandler;
16
+
17
+ export { isHandlerKind };
@@ -0,0 +1,17 @@
1
+ import { HandlerKind } from '../../handlers/common.js';
2
+ import { R as RequestHandler } from '../../HttpResponse-DzhqZzTK.js';
3
+ import { WebSocketHandler } from '../../handlers/WebSocketHandler.js';
4
+ import './isIterable.js';
5
+ import '../../typeUtils.js';
6
+ import 'strict-event-emitter';
7
+ import '@mswjs/interceptors/WebSocket';
8
+ import '../matching/matchRequestUrl.js';
9
+
10
+ /**
11
+ * A filter function that ensures that the provided argument
12
+ * is a handler of the given kind. This helps differentiate
13
+ * between different kinds of handlers, e.g. request and event handlers.
14
+ */
15
+ declare function isHandlerKind<K extends HandlerKind>(kind: K): (input: unknown) => input is K extends "EventHandler" ? WebSocketHandler : RequestHandler;
16
+
17
+ export { isHandlerKind };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var isHandlerKind_exports = {};
20
+ __export(isHandlerKind_exports, {
21
+ isHandlerKind: () => isHandlerKind
22
+ });
23
+ module.exports = __toCommonJS(isHandlerKind_exports);
24
+ function isHandlerKind(kind) {
25
+ return (input) => {
26
+ return input != null && typeof input === "object" && "__kind" in input && input.__kind === kind;
27
+ };
28
+ }
29
+ //# sourceMappingURL=isHandlerKind.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/core/utils/internal/isHandlerKind.ts"],"sourcesContent":["import type { HandlerKind } from '../../handlers/common'\nimport type { RequestHandler } from '../../handlers/RequestHandler'\nimport type { WebSocketHandler } from '../../handlers/WebSocketHandler'\n\n/**\n * A filter function that ensures that the provided argument\n * is a handler of the given kind. This helps differentiate\n * between different kinds of handlers, e.g. request and event handlers.\n */\nexport function isHandlerKind<K extends HandlerKind>(kind: K) {\n return (\n input: unknown,\n ): input is K extends 'EventHandler' ? WebSocketHandler : RequestHandler => {\n return (\n input != null &&\n typeof input === 'object' &&\n '__kind' in input &&\n input.__kind === kind\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASO,SAAS,cAAqC,MAAS;AAC5D,SAAO,CACL,UAC0E;AAC1E,WACE,SAAS,QACT,OAAO,UAAU,YACjB,YAAY,SACZ,MAAM,WAAW;AAAA,EAErB;AACF;","names":[]}
@@ -0,0 +1,9 @@
1
+ function isHandlerKind(kind) {
2
+ return (input) => {
3
+ return input != null && typeof input === "object" && "__kind" in input && input.__kind === kind;
4
+ };
5
+ }
6
+ export {
7
+ isHandlerKind
8
+ };
9
+ //# sourceMappingURL=isHandlerKind.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/core/utils/internal/isHandlerKind.ts"],"sourcesContent":["import type { HandlerKind } from '../../handlers/common'\nimport type { RequestHandler } from '../../handlers/RequestHandler'\nimport type { WebSocketHandler } from '../../handlers/WebSocketHandler'\n\n/**\n * A filter function that ensures that the provided argument\n * is a handler of the given kind. This helps differentiate\n * between different kinds of handlers, e.g. request and event handlers.\n */\nexport function isHandlerKind<K extends HandlerKind>(kind: K) {\n return (\n input: unknown,\n ): input is K extends 'EventHandler' ? WebSocketHandler : RequestHandler => {\n return (\n input != null &&\n typeof input === 'object' &&\n '__kind' in input &&\n input.__kind === kind\n )\n }\n}\n"],"mappings":"AASO,SAAS,cAAqC,MAAS;AAC5D,SAAO,CACL,UAC0E;AAC1E,WACE,SAAS,QACT,OAAO,UAAU,YACjB,YAAY,SACZ,MAAM,WAAW;AAAA,EAErB;AACF;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import 'graphql';
2
- export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-ClMB0BOy.mjs';
3
- import '../../HttpResponse-vn-Pb4Bi.mjs';
2
+ export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-B6uni-E_.mjs';
3
+ import '../../HttpResponse-63H9vVoL.mjs';
4
4
  import './isIterable.mjs';
5
5
  import '../../typeUtils.mjs';
6
6
  import '../matching/matchRequestUrl.mjs';
@@ -1,6 +1,6 @@
1
1
  import 'graphql';
2
- export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-D6mLMXGZ.js';
3
- import '../../HttpResponse-DaYkf3ml.js';
2
+ export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-Cjm7JNGi.js';
3
+ import '../../HttpResponse-DzhqZzTK.js';
4
4
  import './isIterable.js';
5
5
  import '../../typeUtils.js';
6
6
  import '../matching/matchRequestUrl.js';
@@ -1,4 +1,4 @@
1
- import { d as DefaultRequestMultipartBody } from '../../HttpResponse-vn-Pb4Bi.mjs';
1
+ import { d as DefaultRequestMultipartBody } from '../../HttpResponse-63H9vVoL.mjs';
2
2
  import './isIterable.mjs';
3
3
  import '../../typeUtils.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { d as DefaultRequestMultipartBody } from '../../HttpResponse-DaYkf3ml.js';
1
+ import { d as DefaultRequestMultipartBody } from '../../HttpResponse-DzhqZzTK.js';
2
2
  import './isIterable.js';
3
3
  import '../../typeUtils.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-vn-Pb4Bi.mjs';
1
+ import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-63H9vVoL.mjs';
2
2
  import './isIterable.mjs';
3
3
  import '../../typeUtils.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-DaYkf3ml.js';
1
+ import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-DzhqZzTK.js';
2
2
  import './isIterable.js';
3
3
  import '../../typeUtils.js';
4
4
 
@@ -1,6 +1,9 @@
1
+ interface GetTimestampOptions {
2
+ milliseconds?: boolean;
3
+ }
1
4
  /**
2
5
  * Returns a timestamp string in a "HH:MM:SS" format.
3
6
  */
4
- declare function getTimestamp(): string;
7
+ declare function getTimestamp(options?: GetTimestampOptions): string;
5
8
 
6
9
  export { getTimestamp };
@@ -1,6 +1,9 @@
1
+ interface GetTimestampOptions {
2
+ milliseconds?: boolean;
3
+ }
1
4
  /**
2
5
  * Returns a timestamp string in a "HH:MM:SS" format.
3
6
  */
4
- declare function getTimestamp(): string;
7
+ declare function getTimestamp(options?: GetTimestampOptions): string;
5
8
 
6
9
  export { getTimestamp };
@@ -21,8 +21,12 @@ __export(getTimestamp_exports, {
21
21
  getTimestamp: () => getTimestamp
22
22
  });
23
23
  module.exports = __toCommonJS(getTimestamp_exports);
24
- function getTimestamp() {
24
+ function getTimestamp(options) {
25
25
  const now = /* @__PURE__ */ new Date();
26
- return [now.getHours(), now.getMinutes(), now.getSeconds()].map(String).map((chunk) => chunk.slice(0, 2)).map((chunk) => chunk.padStart(2, "0")).join(":");
26
+ const timestamp = `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}:${now.getSeconds().toString().padStart(2, "0")}`;
27
+ if (options?.milliseconds) {
28
+ return `${timestamp}.${now.getMilliseconds().toString().padStart(3, "0")}`;
29
+ }
30
+ return timestamp;
27
31
  }
28
32
  //# sourceMappingURL=getTimestamp.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/core/utils/logging/getTimestamp.ts"],"sourcesContent":["/**\n * Returns a timestamp string in a \"HH:MM:SS\" format.\n */\nexport function getTimestamp(): string {\n const now = new Date()\n\n return [now.getHours(), now.getMinutes(), now.getSeconds()]\n .map(String)\n .map((chunk) => chunk.slice(0, 2))\n .map((chunk) => chunk.padStart(2, '0'))\n .join(':')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,eAAuB;AACrC,QAAM,MAAM,oBAAI,KAAK;AAErB,SAAO,CAAC,IAAI,SAAS,GAAG,IAAI,WAAW,GAAG,IAAI,WAAW,CAAC,EACvD,IAAI,MAAM,EACV,IAAI,CAAC,UAAU,MAAM,MAAM,GAAG,CAAC,CAAC,EAChC,IAAI,CAAC,UAAU,MAAM,SAAS,GAAG,GAAG,CAAC,EACrC,KAAK,GAAG;AACb;","names":[]}
1
+ {"version":3,"sources":["../../../../src/core/utils/logging/getTimestamp.ts"],"sourcesContent":["interface GetTimestampOptions {\n milliseconds?: boolean\n}\n\n/**\n * Returns a timestamp string in a \"HH:MM:SS\" format.\n */\nexport function getTimestamp(options?: GetTimestampOptions): string {\n const now = new Date()\n const timestamp = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}`\n\n if (options?.milliseconds) {\n return `${timestamp}.${now.getMilliseconds().toString().padStart(3, '0')}`\n }\n\n return timestamp\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,aAAa,SAAuC;AAClE,QAAM,MAAM,oBAAI,KAAK;AACrB,QAAM,YAAY,GAAG,IAAI,SAAS,EAAE,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC,IAAI,IAAI,WAAW,EAAE,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC,IAAI,IAAI,WAAW,EAAE,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC;AAE/J,MAAI,SAAS,cAAc;AACzB,WAAO,GAAG,SAAS,IAAI,IAAI,gBAAgB,EAAE,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC;AAAA,EAC1E;AAEA,SAAO;AACT;","names":[]}
@@ -1,6 +1,10 @@
1
- function getTimestamp() {
1
+ function getTimestamp(options) {
2
2
  const now = /* @__PURE__ */ new Date();
3
- return [now.getHours(), now.getMinutes(), now.getSeconds()].map(String).map((chunk) => chunk.slice(0, 2)).map((chunk) => chunk.padStart(2, "0")).join(":");
3
+ const timestamp = `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}:${now.getSeconds().toString().padStart(2, "0")}`;
4
+ if (options?.milliseconds) {
5
+ return `${timestamp}.${now.getMilliseconds().toString().padStart(3, "0")}`;
6
+ }
7
+ return timestamp;
4
8
  }
5
9
  export {
6
10
  getTimestamp
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/core/utils/logging/getTimestamp.ts"],"sourcesContent":["/**\n * Returns a timestamp string in a \"HH:MM:SS\" format.\n */\nexport function getTimestamp(): string {\n const now = new Date()\n\n return [now.getHours(), now.getMinutes(), now.getSeconds()]\n .map(String)\n .map((chunk) => chunk.slice(0, 2))\n .map((chunk) => chunk.padStart(2, '0'))\n .join(':')\n}\n"],"mappings":"AAGO,SAAS,eAAuB;AACrC,QAAM,MAAM,oBAAI,KAAK;AAErB,SAAO,CAAC,IAAI,SAAS,GAAG,IAAI,WAAW,GAAG,IAAI,WAAW,CAAC,EACvD,IAAI,MAAM,EACV,IAAI,CAAC,UAAU,MAAM,MAAM,GAAG,CAAC,CAAC,EAChC,IAAI,CAAC,UAAU,MAAM,SAAS,GAAG,GAAG,CAAC,EACrC,KAAK,GAAG;AACb;","names":[]}
1
+ {"version":3,"sources":["../../../../src/core/utils/logging/getTimestamp.ts"],"sourcesContent":["interface GetTimestampOptions {\n milliseconds?: boolean\n}\n\n/**\n * Returns a timestamp string in a \"HH:MM:SS\" format.\n */\nexport function getTimestamp(options?: GetTimestampOptions): string {\n const now = new Date()\n const timestamp = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}`\n\n if (options?.milliseconds) {\n return `${timestamp}.${now.getMilliseconds().toString().padStart(3, '0')}`\n }\n\n return timestamp\n}\n"],"mappings":"AAOO,SAAS,aAAa,SAAuC;AAClE,QAAM,MAAM,oBAAI,KAAK;AACrB,QAAM,YAAY,GAAG,IAAI,SAAS,EAAE,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC,IAAI,IAAI,WAAW,EAAE,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC,IAAI,IAAI,WAAW,EAAE,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC;AAE/J,MAAI,SAAS,cAAc;AACzB,WAAO,GAAG,SAAS,IAAI,IAAI,gBAAgB,EAAE,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC;AAAA,EAC1E;AAEA,SAAO;AACT;","names":[]}
@@ -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 };
@@ -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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,wCAA2C;AAC3C,2CAA8C;AAuBvC,MAAM,uBAAuB;AAAA,EAKlC,YAAoB,SAA2B;AAA3B;AAGlB,SAAK,QACH,OAAO,cAAc,cACjB,IAAI,mEAA8B,IAClC,IAAI,6DAA2B;AAErC,SAAK,iBAAiB,oBAAI,IAAI;AAC9B,SAAK,aAAa,oBAAI,IAAI;AAE1B,SAAK,QAAQ,iBAAiB,WAAW,CAAC,YAAY;AACpD,UAAI,QAAQ,MAAM,SAAS,aAAa;AACtC,aAAK,sBAAsB;AAAA,MAC7B;AAAA,IACF,CAAC;AAED,QAAI,OAAO,WAAW,aAAa;AACjC,aAAO,iBAAiB,WAAW,OAAO,YAAY;AACpD,YAAI,QAAQ,MAAM,SAAS,mBAAmB;AAC5C,gBAAM,KAAK,qBAAqB;AAAA,QAClC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EA5BQ;AAAA,EACA;AAAA,EACA;AAAA,EA4BR,MAAc,wBAAwB;AACpC,UAAM,gBAAgB,MAAM,KAAK,MAAM,OAAO;AAE9C,SAAK,aAAa,IAAI;AAAA,MACpB,cAAc,IAAI,CAAC,WAAW;AAC5B,cAAM,gBAAgB,KAAK,eAAe,IAAI,OAAO,EAAE;AAMvD,YAAI,eAAe;AACjB,iBAAO;AAAA,QACT;AAEA,eAAO,IAAI;AAAA,UACT,OAAO;AAAA,UACP,IAAI,IAAI,OAAO,GAAG;AAAA,UAClB,KAAK;AAAA,QACP;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,MAAc,uBAAsC;AAClD,UAAM,KAAK,MAAM,WAAW,MAAM,KAAK,KAAK,eAAe,KAAK,CAAC,CAAC;AAClE,SAAK,eAAe,MAAM;AAC1B,UAAM,KAAK,sBAAsB;AACjC,SAAK,gCAAgC;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,UAAkD;AACpD,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,kCAAwC;AAC9C,SAAK,QAAQ,YAAY,EAAE,MAAM,YAAY,CAAC;AAAA,EAChD;AAAA,EAEA,MAAc,UAAU,QAAkD;AACxE,UAAM,KAAK,MAAM,IAAI,MAAM;AAG3B,UAAM,KAAK,sBAAsB;AACjC,SAAK,gCAAgC;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAa,cAAc,QAAkD;AAI3E,SAAK,eAAe,IAAI,OAAO,IAAI,MAAM;AAGzC,UAAM,KAAK,UAAU,MAAM;AAK3B,UAAM,0BAA0B,CAC9B,YACG;AACH,YAAM,EAAE,MAAM,QAAQ,IAAI,QAAQ;AAGlC,UACE,OAAO,YAAY,YACnB,cAAc,WACd,QAAQ,aAAa,OAAO,IAC5B;AACA;AAAA,MACF;AAEA,cAAQ,MAAM;AAAA,QACZ,KAAK,mBAAmB;AACtB,iBAAO,KAAK,QAAQ,IAAI;AACxB;AAAA,QACF;AAAA,QAEA,KAAK,oBAAoB;AACvB,iBAAO,MAAM,QAAQ,MAAM,QAAQ,MAAM;AACzC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,kBAAkB,IAAI,gBAAgB;AAE5C,SAAK,QAAQ,iBAAiB,WAAW,yBAAyB;AAAA,MAChE,QAAQ,gBAAgB;AAAA,IAC1B,CAAC;AAID,WAAO,iBAAiB,SAAS,MAAM,gBAAgB,MAAM,GAAG;AAAA,MAC9D,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AACF;AASO,MAAM,gCAEb;AAAA,EACE,YACkB,IACA,KACR,SACR;AAHgB;AACA;AACR;AAAA,EACP;AAAA,EAEH,KAAK,MAA2B;AAC9B,SAAK,QAAQ,YAAY;AAAA,MACvB,MAAM;AAAA,MACN,SAAS;AAAA,QACP,UAAU,KAAK;AAAA,QACf;AAAA,MACF;AAAA,IACF,CAAqC;AAAA,EACvC;AAAA,EAEA,MAAM,MAA2B,QAAmC;AAClE,SAAK,QAAQ,YAAY;AAAA,MACvB,MAAM;AAAA,MACN,SAAS;AAAA,QACP,UAAU,KAAK;AAAA,QACf;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAqC;AAAA,EACvC;AACF;","names":[]}