@depup/msw 2.13.2-depup.0 → 2.15.0-depup.6
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.
- package/README.md +9 -12
- package/changes.json +14 -26
- package/cli/init.js +1 -1
- package/lib/browser/index.js +547 -177
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +547 -177
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{HttpResponse-DlRR1D-f.d.mts → HttpResponse-BE_Y2Ak9.d.mts} +52 -1
- package/lib/core/{HttpResponse-CksOMVAa.d.ts → HttpResponse-DL-P1EeG.d.ts} +52 -1
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/HttpResponse.js +2 -2
- package/lib/core/HttpResponse.js.map +1 -1
- package/lib/core/HttpResponse.mjs +2 -2
- package/lib/core/HttpResponse.mjs.map +1 -1
- package/lib/core/experimental/compat.d.mts +2 -2
- package/lib/core/experimental/compat.d.ts +2 -2
- package/lib/core/experimental/compat.js +1 -0
- package/lib/core/experimental/compat.js.map +1 -1
- package/lib/core/experimental/compat.mjs +1 -0
- package/lib/core/experimental/compat.mjs.map +1 -1
- package/lib/core/experimental/define-network.d.mts +2 -2
- package/lib/core/experimental/define-network.d.ts +2 -2
- package/lib/core/experimental/define-network.js +21 -11
- package/lib/core/experimental/define-network.js.map +1 -1
- package/lib/core/experimental/define-network.mjs +23 -11
- package/lib/core/experimental/define-network.mjs.map +1 -1
- package/lib/core/experimental/frames/http-frame.d.mts +2 -2
- package/lib/core/experimental/frames/http-frame.d.ts +2 -2
- package/lib/core/experimental/frames/http-frame.js +5 -2
- package/lib/core/experimental/frames/http-frame.js.map +1 -1
- package/lib/core/experimental/frames/http-frame.mjs +8 -3
- package/lib/core/experimental/frames/http-frame.mjs.map +1 -1
- package/lib/core/experimental/frames/network-frame.d.mts +2 -2
- package/lib/core/experimental/frames/network-frame.d.ts +2 -2
- package/lib/core/experimental/frames/network-frame.js +2 -0
- package/lib/core/experimental/frames/network-frame.js.map +1 -1
- package/lib/core/experimental/frames/network-frame.mjs +2 -0
- package/lib/core/experimental/frames/network-frame.mjs.map +1 -1
- package/lib/core/experimental/frames/websocket-frame.d.mts +2 -2
- package/lib/core/experimental/frames/websocket-frame.d.ts +2 -2
- package/lib/core/experimental/frames/websocket-frame.js +2 -0
- package/lib/core/experimental/frames/websocket-frame.js.map +1 -1
- package/lib/core/experimental/frames/websocket-frame.mjs +2 -0
- package/lib/core/experimental/frames/websocket-frame.mjs.map +1 -1
- package/lib/core/experimental/handlers-controller.d.mts +2 -1
- package/lib/core/experimental/handlers-controller.d.ts +2 -1
- package/lib/core/experimental/handlers-controller.js +31 -6
- package/lib/core/experimental/handlers-controller.js.map +1 -1
- package/lib/core/experimental/handlers-controller.mjs +31 -6
- package/lib/core/experimental/handlers-controller.mjs.map +1 -1
- package/lib/core/experimental/index.d.mts +5 -5
- package/lib/core/experimental/index.d.ts +5 -5
- package/lib/core/experimental/index.js +3 -1
- package/lib/core/experimental/index.js.map +1 -1
- package/lib/core/experimental/index.mjs +9 -2
- package/lib/core/experimental/index.mjs.map +1 -1
- package/lib/core/experimental/on-unhandled-frame.d.mts +2 -2
- package/lib/core/experimental/on-unhandled-frame.d.ts +2 -2
- package/lib/core/experimental/on-unhandled-frame.js +1 -0
- package/lib/core/experimental/on-unhandled-frame.js.map +1 -1
- package/lib/core/experimental/on-unhandled-frame.mjs +1 -0
- package/lib/core/experimental/on-unhandled-frame.mjs.map +1 -1
- package/lib/core/experimental/setup-api.d.mts +1 -1
- package/lib/core/experimental/setup-api.d.ts +1 -1
- package/lib/core/experimental/setup-api.js +2 -5
- package/lib/core/experimental/setup-api.js.map +1 -1
- package/lib/core/experimental/setup-api.mjs +2 -5
- package/lib/core/experimental/setup-api.mjs.map +1 -1
- package/lib/core/experimental/sources/interceptor-source.d.mts +2 -2
- package/lib/core/experimental/sources/interceptor-source.d.ts +2 -2
- package/lib/core/experimental/sources/interceptor-source.js +23 -10
- package/lib/core/experimental/sources/interceptor-source.js.map +1 -1
- package/lib/core/experimental/sources/interceptor-source.mjs +24 -13
- package/lib/core/experimental/sources/interceptor-source.mjs.map +1 -1
- package/lib/core/experimental/sources/network-source.d.mts +3 -3
- package/lib/core/experimental/sources/network-source.d.ts +3 -3
- package/lib/core/experimental/sources/network-source.js +1 -0
- package/lib/core/experimental/sources/network-source.js.map +1 -1
- package/lib/core/experimental/sources/network-source.mjs +2 -0
- package/lib/core/experimental/sources/network-source.mjs.map +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +1 -1
- package/lib/core/graphql.d.ts +1 -1
- package/lib/core/graphql.js +1 -0
- package/lib/core/graphql.js.map +1 -1
- package/lib/core/graphql.mjs +2 -0
- package/lib/core/graphql.mjs.map +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
- package/lib/core/handlers/GraphQLHandler.js +1 -0
- package/lib/core/handlers/GraphQLHandler.js.map +1 -1
- package/lib/core/handlers/GraphQLHandler.mjs +4 -1
- package/lib/core/handlers/GraphQLHandler.mjs.map +1 -1
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/HttpHandler.js +1 -0
- package/lib/core/handlers/HttpHandler.js.map +1 -1
- package/lib/core/handlers/HttpHandler.mjs +1 -0
- package/lib/core/handlers/HttpHandler.mjs.map +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.js +197 -4
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs +198 -4
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +5 -2
- package/lib/core/handlers/WebSocketHandler.d.ts +5 -2
- package/lib/core/handlers/WebSocketHandler.js +30 -12
- package/lib/core/handlers/WebSocketHandler.js.map +1 -1
- package/lib/core/handlers/WebSocketHandler.mjs +30 -12
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/http.js +1 -0
- package/lib/core/http.js.map +1 -1
- package/lib/core/http.mjs +2 -0
- package/lib/core/http.mjs.map +1 -1
- package/lib/core/index.d.mts +1 -1
- package/lib/core/index.d.ts +1 -1
- package/lib/core/{network-frame-usYiHS0K.d.ts → on-unhandled-frame-0KmwUmeV.d.ts} +13 -13
- package/lib/core/{network-frame-B7A0ggXE.d.mts → on-unhandled-frame-gkokW4Rr.d.mts} +13 -13
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/sse.d.mts +4 -18
- package/lib/core/sse.d.ts +4 -18
- package/lib/core/sse.js +149 -66
- package/lib/core/sse.js.map +1 -1
- package/lib/core/sse.mjs +149 -66
- package/lib/core/sse.mjs.map +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +9 -4
- package/lib/core/utils/HttpResponse/decorators.d.ts +9 -4
- package/lib/core/utils/HttpResponse/decorators.js +18 -11
- package/lib/core/utils/HttpResponse/decorators.js.map +1 -1
- package/lib/core/utils/HttpResponse/decorators.mjs +18 -11
- package/lib/core/utils/HttpResponse/decorators.mjs.map +1 -1
- package/lib/core/utils/cookieStore.js.map +1 -1
- package/lib/core/utils/cookieStore.mjs.map +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/executeHandlers.js +1 -0
- package/lib/core/utils/executeHandlers.js.map +1 -1
- package/lib/core/utils/executeHandlers.mjs +1 -0
- package/lib/core/utils/executeHandlers.mjs.map +1 -1
- package/lib/core/utils/handleRequest.d.mts +1 -1
- package/lib/core/utils/handleRequest.d.ts +1 -1
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/core/utils/internal/Disposable.js +19 -1
- package/lib/core/utils/internal/Disposable.js.map +1 -1
- package/lib/core/utils/internal/Disposable.mjs +19 -1
- package/lib/core/utils/internal/Disposable.mjs.map +1 -1
- package/lib/core/utils/internal/attachSiblingHandlers.d.mts +15 -0
- package/lib/core/utils/internal/attachSiblingHandlers.d.ts +15 -0
- package/lib/core/utils/internal/attachSiblingHandlers.js +44 -0
- package/lib/core/utils/internal/attachSiblingHandlers.js.map +1 -0
- package/lib/core/utils/internal/attachSiblingHandlers.mjs +24 -0
- package/lib/core/utils/internal/attachSiblingHandlers.mjs.map +1 -0
- package/lib/core/utils/internal/isHandlerKind.d.mts +1 -1
- package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
- package/lib/core/utils/internal/observe-response-body-stream.d.mts +18 -0
- package/lib/core/utils/internal/observe-response-body-stream.d.ts +18 -0
- package/lib/core/utils/internal/observe-response-body-stream.js +64 -0
- package/lib/core/utils/internal/observe-response-body-stream.js.map +1 -0
- package/lib/core/utils/internal/observe-response-body-stream.mjs +44 -0
- package/lib/core/utils/internal/observe-response-body-stream.mjs.map +1 -0
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/parseMultipartData.js +1 -0
- package/lib/core/utils/internal/parseMultipartData.js.map +1 -1
- package/lib/core/utils/internal/parseMultipartData.mjs +1 -0
- package/lib/core/utils/internal/parseMultipartData.mjs.map +1 -1
- package/lib/core/utils/internal/pipeEvents.js +1 -0
- package/lib/core/utils/internal/pipeEvents.js.map +1 -1
- package/lib/core/utils/internal/pipeEvents.mjs +1 -0
- package/lib/core/utils/internal/pipeEvents.mjs.map +1 -1
- package/lib/core/utils/request/storeResponseCookies.js +1 -1
- package/lib/core/utils/request/storeResponseCookies.js.map +1 -1
- package/lib/core/utils/request/storeResponseCookies.mjs +2 -2
- package/lib/core/utils/request/storeResponseCookies.mjs.map +1 -1
- package/lib/core/ws/WebSocketClientManager.js +4 -0
- package/lib/core/ws/WebSocketClientManager.js.map +1 -1
- package/lib/core/ws/WebSocketClientManager.mjs +4 -0
- package/lib/core/ws/WebSocketClientManager.mjs.map +1 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.js +1 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +1 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -1
- package/lib/core/ws/WebSocketMemoryClientStore.js +1 -0
- package/lib/core/ws/WebSocketMemoryClientStore.js.map +1 -1
- package/lib/core/ws/WebSocketMemoryClientStore.mjs +1 -0
- package/lib/core/ws/WebSocketMemoryClientStore.mjs.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -1
- package/lib/core/ws.d.mts +17 -4
- package/lib/core/ws.d.ts +17 -4
- package/lib/core/ws.js +30 -5
- package/lib/core/ws.js.map +1 -1
- package/lib/core/ws.mjs +34 -6
- package/lib/core/ws.mjs.map +1 -1
- package/lib/iife/index.js +10138 -6034
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +21 -9
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.d.mts +1 -1
- package/lib/node/index.d.ts +1 -1
- package/lib/node/index.js +2 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +1 -0
- package/lib/node/index.mjs.map +1 -1
- package/lib/shims/cookie.js +152 -62
- package/lib/shims/cookie.mjs +152 -62
- package/package.json +50 -69
- package/src/browser/glossary.ts +1 -1
- package/src/browser/setup-worker.ts +2 -2
- package/src/browser/sources/service-worker-source.ts +142 -40
- package/src/browser/utils/deserializeRequest.ts +2 -2
- package/src/browser/utils/pruneGetRequestBody.ts +3 -3
- package/src/browser/utils/should-invalidate-worker.test.ts +122 -0
- package/src/browser/utils/should-invalidate-worker.ts +13 -0
- package/src/browser/utils/workerChannel.ts +43 -21
- package/src/core/experimental/define-network.ts +44 -15
- package/src/core/experimental/frames/http-frame.test.ts +8 -2
- package/src/core/experimental/frames/http-frame.ts +12 -4
- package/src/core/experimental/frames/websocket-frame.test.ts +2 -4
- package/src/core/experimental/frames/websocket-frame.ts +3 -2
- package/src/core/experimental/handlers-controller.test.ts +139 -5
- package/src/core/experimental/handlers-controller.ts +39 -10
- package/src/core/experimental/index.ts +11 -1
- package/src/core/experimental/on-unhandled-frame.test.ts +2 -4
- package/src/core/experimental/setup-api.ts +4 -8
- package/src/core/experimental/sources/interceptor-source.ts +36 -16
- package/src/core/experimental/sources/network-source.ts +1 -1
- package/src/core/graphql.ts +8 -8
- package/src/core/handlers/GraphQLHandler.test.ts +3 -4
- package/src/core/handlers/GraphQLHandler.ts +15 -11
- package/src/core/handlers/HttpHandler.test.ts +92 -2
- package/src/core/handlers/HttpHandler.ts +7 -7
- package/src/core/handlers/RequestHandler.ts +329 -22
- package/src/core/handlers/WebSocketHandler.test.ts +58 -0
- package/src/core/handlers/WebSocketHandler.ts +37 -8
- package/src/core/http.ts +5 -5
- package/src/core/sse.ts +217 -73
- package/src/core/utils/HttpResponse/decorators.ts +28 -22
- package/src/core/utils/cookieStore.ts +1 -1
- package/src/core/utils/executeHandlers.ts +2 -4
- package/src/core/utils/handleRequest.test.ts +5 -4
- package/src/core/utils/handleRequest.ts +3 -3
- package/src/core/utils/internal/Disposable.ts +22 -1
- package/src/core/utils/internal/attachSiblingHandlers.ts +28 -0
- package/src/core/utils/internal/observe-response-body-stream.test.ts +64 -0
- package/src/core/utils/internal/observe-response-body-stream.ts +77 -0
- package/src/core/utils/internal/parseGraphQLRequest.test.ts +2 -4
- package/src/core/utils/internal/parseMultipartData.ts +1 -1
- package/src/core/utils/internal/pipeEvents.ts +2 -1
- package/src/core/utils/request/onUnhandledRequest.test.ts +2 -4
- package/src/core/utils/request/storeResponseCookies.ts +2 -4
- package/src/core/ws/WebSocketClientManager.test.ts +2 -4
- package/src/core/ws/WebSocketClientManager.ts +1 -1
- package/src/core/ws/WebSocketIndexedDBClientStore.ts +3 -5
- package/src/core/ws/WebSocketMemoryClientStore.ts +3 -5
- package/src/core/ws/handleWebSocketEvent.ts +3 -3
- package/src/core/ws.ts +66 -7
- package/src/mockServiceWorker.js +19 -7
- package/src/native/index.ts +2 -2
- package/src/node/async-handlers-controller.ts +2 -2
- package/src/node/index.ts +1 -0
- package/src/node/setup-server-common.ts +4 -4
- package/src/node/setup-server.ts +2 -2
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +0 -12
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +0 -12
- package/lib/core/utils/internal/requestHandlerUtils.js +0 -37
- package/lib/core/utils/internal/requestHandlerUtils.js.map +0 -1
- package/lib/core/utils/internal/requestHandlerUtils.mjs +0 -17
- package/lib/core/utils/internal/requestHandlerUtils.mjs.map +0 -1
- package/src/core/utils/internal/requestHandlerUtils.ts +0 -21
|
@@ -0,0 +1,64 @@
|
|
|
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 observe_response_body_stream_exports = {};
|
|
20
|
+
__export(observe_response_body_stream_exports, {
|
|
21
|
+
observeResponseBodyStream: () => observeResponseBodyStream
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(observe_response_body_stream_exports);
|
|
24
|
+
var import_deferred_promise = require("@open-draft/deferred-promise");
|
|
25
|
+
var import_interceptors = require("@mswjs/interceptors");
|
|
26
|
+
var import_decorators = require("../HttpResponse/decorators");
|
|
27
|
+
function observeResponseBodyStream(response) {
|
|
28
|
+
if (response.body == null || response.bodyUsed || response.body.locked) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const settled = new import_deferred_promise.DeferredPromise();
|
|
32
|
+
const reader = response.body.getReader();
|
|
33
|
+
const observedStream = new ReadableStream({
|
|
34
|
+
async pull(controller) {
|
|
35
|
+
try {
|
|
36
|
+
const readResult = await reader.read();
|
|
37
|
+
if (readResult.done) {
|
|
38
|
+
settled.resolve();
|
|
39
|
+
controller.close();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
controller.enqueue(readResult.value);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
settled.resolve();
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
async cancel(reason) {
|
|
49
|
+
settled.resolve();
|
|
50
|
+
await reader.cancel(reason);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const observedResponse = new import_interceptors.FetchResponse(observedStream, {
|
|
54
|
+
status: response.status,
|
|
55
|
+
statusText: response.statusText,
|
|
56
|
+
headers: response.headers
|
|
57
|
+
});
|
|
58
|
+
(0, import_decorators.copyResponseOwnProperties)(response, observedResponse);
|
|
59
|
+
return {
|
|
60
|
+
response: observedResponse,
|
|
61
|
+
settled
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=observe-response-body-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/internal/observe-response-body-stream.ts"],"sourcesContent":["import { DeferredPromise } from '@open-draft/deferred-promise'\nimport { FetchResponse } from '@mswjs/interceptors'\nimport { copyResponseOwnProperties } from '../HttpResponse/decorators'\n\nexport interface ObservedResponse {\n response: Response\n /**\n * A promise that resolves once the response body stream has settled:\n * it was closed, errored, or canceled, and will not be used anymore.\n */\n settled: Promise<void>\n}\n\n/**\n * Observe the `ReadableStream` body of the given response.\n * Returns a copy of that response whose body reports when it has\n * settled (was read to completion, errored, or canceled by the consumer).\n * Returns `null` for responses whose body cannot be observed\n * (no body, already used, or locked).\n */\nexport function observeResponseBodyStream(\n response: Response,\n): ObservedResponse | null {\n if (response.body == null || response.bodyUsed || response.body.locked) {\n return null\n }\n\n const settled = new DeferredPromise<void>()\n const reader = response.body.getReader()\n\n /**\n * @note Relay the body through a manual underlying source instead of\n * `.pipeThrough(new TransformStream({ flush, cancel }))`. The `cancel`\n * transformer callback is not implemented in Chromium, which loses\n * the stream error/cancelation signals there entirely.\n */\n const observedStream = new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n const readResult = await reader.read()\n\n if (readResult.done) {\n settled.resolve()\n controller.close()\n return\n }\n\n controller.enqueue(readResult.value)\n } catch (error) {\n settled.resolve()\n throw error\n }\n },\n async cancel(reason) {\n settled.resolve()\n await reader.cancel(reason)\n },\n })\n\n /**\n * @note Reconstruct the response because the body of an existing\n * response cannot be replaced. Use `FetchResponse` to support\n * non-standard response status codes (e.g. 101).\n */\n const observedResponse = new FetchResponse(observedStream, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n })\n\n copyResponseOwnProperties(response, observedResponse)\n\n return {\n response: observedResponse,\n settled,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAgC;AAChC,0BAA8B;AAC9B,wBAA0C;AAkBnC,SAAS,0BACd,UACyB;AACzB,MAAI,SAAS,QAAQ,QAAQ,SAAS,YAAY,SAAS,KAAK,QAAQ;AACtE,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,IAAI,wCAAsB;AAC1C,QAAM,SAAS,SAAS,KAAK,UAAU;AAQvC,QAAM,iBAAiB,IAAI,eAA2B;AAAA,IACpD,MAAM,KAAK,YAAY;AACrB,UAAI;AACF,cAAM,aAAa,MAAM,OAAO,KAAK;AAErC,YAAI,WAAW,MAAM;AACnB,kBAAQ,QAAQ;AAChB,qBAAW,MAAM;AACjB;AAAA,QACF;AAEA,mBAAW,QAAQ,WAAW,KAAK;AAAA,MACrC,SAAS,OAAO;AACd,gBAAQ,QAAQ;AAChB,cAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,MAAM,OAAO,QAAQ;AACnB,cAAQ,QAAQ;AAChB,YAAM,OAAO,OAAO,MAAM;AAAA,IAC5B;AAAA,EACF,CAAC;AAOD,QAAM,mBAAmB,IAAI,kCAAc,gBAAgB;AAAA,IACzD,QAAQ,SAAS;AAAA,IACjB,YAAY,SAAS;AAAA,IACrB,SAAS,SAAS;AAAA,EACpB,CAAC;AAED,mDAA0B,UAAU,gBAAgB;AAEpD,SAAO;AAAA,IACL,UAAU;AAAA,IACV;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { DeferredPromise } from "@open-draft/deferred-promise";
|
|
2
|
+
import { FetchResponse } from "@mswjs/interceptors";
|
|
3
|
+
import { copyResponseOwnProperties } from '../HttpResponse/decorators.mjs';
|
|
4
|
+
function observeResponseBodyStream(response) {
|
|
5
|
+
if (response.body == null || response.bodyUsed || response.body.locked) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const settled = new DeferredPromise();
|
|
9
|
+
const reader = response.body.getReader();
|
|
10
|
+
const observedStream = new ReadableStream({
|
|
11
|
+
async pull(controller) {
|
|
12
|
+
try {
|
|
13
|
+
const readResult = await reader.read();
|
|
14
|
+
if (readResult.done) {
|
|
15
|
+
settled.resolve();
|
|
16
|
+
controller.close();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
controller.enqueue(readResult.value);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
settled.resolve();
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
async cancel(reason) {
|
|
26
|
+
settled.resolve();
|
|
27
|
+
await reader.cancel(reason);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const observedResponse = new FetchResponse(observedStream, {
|
|
31
|
+
status: response.status,
|
|
32
|
+
statusText: response.statusText,
|
|
33
|
+
headers: response.headers
|
|
34
|
+
});
|
|
35
|
+
copyResponseOwnProperties(response, observedResponse);
|
|
36
|
+
return {
|
|
37
|
+
response: observedResponse,
|
|
38
|
+
settled
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
observeResponseBodyStream
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=observe-response-body-stream.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/internal/observe-response-body-stream.ts"],"sourcesContent":["import { DeferredPromise } from '@open-draft/deferred-promise'\nimport { FetchResponse } from '@mswjs/interceptors'\nimport { copyResponseOwnProperties } from '../HttpResponse/decorators'\n\nexport interface ObservedResponse {\n response: Response\n /**\n * A promise that resolves once the response body stream has settled:\n * it was closed, errored, or canceled, and will not be used anymore.\n */\n settled: Promise<void>\n}\n\n/**\n * Observe the `ReadableStream` body of the given response.\n * Returns a copy of that response whose body reports when it has\n * settled (was read to completion, errored, or canceled by the consumer).\n * Returns `null` for responses whose body cannot be observed\n * (no body, already used, or locked).\n */\nexport function observeResponseBodyStream(\n response: Response,\n): ObservedResponse | null {\n if (response.body == null || response.bodyUsed || response.body.locked) {\n return null\n }\n\n const settled = new DeferredPromise<void>()\n const reader = response.body.getReader()\n\n /**\n * @note Relay the body through a manual underlying source instead of\n * `.pipeThrough(new TransformStream({ flush, cancel }))`. The `cancel`\n * transformer callback is not implemented in Chromium, which loses\n * the stream error/cancelation signals there entirely.\n */\n const observedStream = new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n const readResult = await reader.read()\n\n if (readResult.done) {\n settled.resolve()\n controller.close()\n return\n }\n\n controller.enqueue(readResult.value)\n } catch (error) {\n settled.resolve()\n throw error\n }\n },\n async cancel(reason) {\n settled.resolve()\n await reader.cancel(reason)\n },\n })\n\n /**\n * @note Reconstruct the response because the body of an existing\n * response cannot be replaced. Use `FetchResponse` to support\n * non-standard response status codes (e.g. 101).\n */\n const observedResponse = new FetchResponse(observedStream, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n })\n\n copyResponseOwnProperties(response, observedResponse)\n\n return {\n response: observedResponse,\n settled,\n }\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,SAAS,iCAAiC;AAkBnC,SAAS,0BACd,UACyB;AACzB,MAAI,SAAS,QAAQ,QAAQ,SAAS,YAAY,SAAS,KAAK,QAAQ;AACtE,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,IAAI,gBAAsB;AAC1C,QAAM,SAAS,SAAS,KAAK,UAAU;AAQvC,QAAM,iBAAiB,IAAI,eAA2B;AAAA,IACpD,MAAM,KAAK,YAAY;AACrB,UAAI;AACF,cAAM,aAAa,MAAM,OAAO,KAAK;AAErC,YAAI,WAAW,MAAM;AACnB,kBAAQ,QAAQ;AAChB,qBAAW,MAAM;AACjB;AAAA,QACF;AAEA,mBAAW,QAAQ,WAAW,KAAK;AAAA,MACrC,SAAS,OAAO;AACd,gBAAQ,QAAQ;AAChB,cAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,MAAM,OAAO,QAAQ;AACnB,cAAQ,QAAQ;AAChB,YAAM,OAAO,OAAO,MAAM;AAAA,IAC5B;AAAA,EACF,CAAC;AAOD,QAAM,mBAAmB,IAAI,cAAc,gBAAgB;AAAA,IACzD,QAAQ,SAAS;AAAA,IACjB,YAAY,SAAS;AAAA,IACrB,SAAS,SAAS;AAAA,EACpB,CAAC;AAED,4BAA0B,UAAU,gBAAgB;AAEpD,SAAO;AAAA,IACL,UAAU;AAAA,IACV;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export {
|
|
2
|
+
export { u as GraphQLMultipartRequestBody, v as GraphQLParsedOperationsMap, w as ParsedGraphQLQuery, P as ParsedGraphQLRequest, x as parseDocumentNode, y as parseGraphQLRequest } from '../../HttpResponse-BE_Y2Ak9.mjs';
|
|
3
3
|
import '@mswjs/interceptors';
|
|
4
4
|
import './isIterable.mjs';
|
|
5
5
|
import '../../typeUtils.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export {
|
|
2
|
+
export { u as GraphQLMultipartRequestBody, v as GraphQLParsedOperationsMap, w as ParsedGraphQLQuery, P as ParsedGraphQLRequest, x as parseDocumentNode, y as parseGraphQLRequest } from '../../HttpResponse-DL-P1EeG.js';
|
|
3
3
|
import '@mswjs/interceptors';
|
|
4
4
|
import './isIterable.js';
|
|
5
5
|
import '../../typeUtils.js';
|
|
@@ -22,6 +22,7 @@ __export(parseMultipartData_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(parseMultipartData_exports);
|
|
24
24
|
var import_headers_polyfill = require("headers-polyfill");
|
|
25
|
+
var import_RequestHandler = require("../../handlers/RequestHandler");
|
|
25
26
|
function parseContentHeaders(headersString) {
|
|
26
27
|
const headers = (0, import_headers_polyfill.stringToHeaders)(headersString);
|
|
27
28
|
const contentType = headers.get("content-type") || "text/plain";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/internal/parseMultipartData.ts"],"sourcesContent":["import { stringToHeaders } from 'headers-polyfill'\nimport { DefaultRequestMultipartBody } from '../../handlers/RequestHandler'\n\ninterface ParsedContentHeaders {\n name: string\n filename?: string\n contentType: string\n}\n\ninterface ContentDispositionDirective {\n [key: string]: string | undefined\n name: string\n filename?: string\n 'form-data': string\n}\n\nfunction parseContentHeaders(headersString: string): ParsedContentHeaders {\n const headers = stringToHeaders(headersString)\n const contentType = headers.get('content-type') || 'text/plain'\n const disposition = headers.get('content-disposition')\n\n if (!disposition) {\n throw new Error('\"Content-Disposition\" header is required.')\n }\n\n const directives = disposition.split(';').reduce((acc, chunk) => {\n const [name, ...rest] = chunk.trim().split('=')\n acc[name] = rest.join('=')\n return acc\n }, {} as ContentDispositionDirective)\n\n const name = directives.name?.slice(1, -1)\n const filename = directives.filename?.slice(1, -1)\n\n return {\n name,\n filename,\n contentType,\n }\n}\n\n/**\n * Parses a given string as a multipart/form-data.\n * Does not throw an exception on an invalid multipart string.\n */\nexport function parseMultipartData<T extends DefaultRequestMultipartBody>(\n data: string,\n headers?: Headers,\n): T | undefined {\n const contentType = headers?.get('content-type')\n\n if (!contentType) {\n return undefined\n }\n\n const [, ...directives] = contentType.split(/; */)\n const boundary = directives\n .filter((d) => d.startsWith('boundary='))\n .map((s) => s.replace(/^boundary=/, ''))[0]\n\n if (!boundary) {\n return undefined\n }\n\n const boundaryRegExp = new RegExp(\n `--+${boundary.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}`,\n )\n const fields = data\n .split(boundaryRegExp)\n .filter((chunk) => chunk.startsWith('\\r\\n') && chunk.endsWith('\\r\\n'))\n .map((chunk) => chunk.trimStart().replace(/\\r\\n$/, ''))\n\n if (!fields.length) {\n return undefined\n }\n\n const parsedBody: DefaultRequestMultipartBody = {}\n\n try {\n for (const field of fields) {\n const [contentHeaders, ...rest] = field.split('\\r\\n\\r\\n')\n const contentBody = rest.join('\\r\\n\\r\\n')\n const { contentType, filename, name } =\n parseContentHeaders(contentHeaders)\n\n const value =\n filename === undefined\n ? contentBody\n : new File([contentBody], filename, { type: contentType })\n\n const parsedValue = parsedBody[name]\n\n if (parsedValue === undefined) {\n parsedBody[name] = value\n } else if (Array.isArray(parsedValue)) {\n parsedBody[name] = [...parsedValue, value]\n } else {\n parsedBody[name] = [parsedValue, value]\n }\n }\n\n return parsedBody as T\n } catch {\n return undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAgC;
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/internal/parseMultipartData.ts"],"sourcesContent":["import { stringToHeaders } from 'headers-polyfill'\nimport { type DefaultRequestMultipartBody } from '../../handlers/RequestHandler'\n\ninterface ParsedContentHeaders {\n name: string\n filename?: string\n contentType: string\n}\n\ninterface ContentDispositionDirective {\n [key: string]: string | undefined\n name: string\n filename?: string\n 'form-data': string\n}\n\nfunction parseContentHeaders(headersString: string): ParsedContentHeaders {\n const headers = stringToHeaders(headersString)\n const contentType = headers.get('content-type') || 'text/plain'\n const disposition = headers.get('content-disposition')\n\n if (!disposition) {\n throw new Error('\"Content-Disposition\" header is required.')\n }\n\n const directives = disposition.split(';').reduce((acc, chunk) => {\n const [name, ...rest] = chunk.trim().split('=')\n acc[name] = rest.join('=')\n return acc\n }, {} as ContentDispositionDirective)\n\n const name = directives.name?.slice(1, -1)\n const filename = directives.filename?.slice(1, -1)\n\n return {\n name,\n filename,\n contentType,\n }\n}\n\n/**\n * Parses a given string as a multipart/form-data.\n * Does not throw an exception on an invalid multipart string.\n */\nexport function parseMultipartData<T extends DefaultRequestMultipartBody>(\n data: string,\n headers?: Headers,\n): T | undefined {\n const contentType = headers?.get('content-type')\n\n if (!contentType) {\n return undefined\n }\n\n const [, ...directives] = contentType.split(/; */)\n const boundary = directives\n .filter((d) => d.startsWith('boundary='))\n .map((s) => s.replace(/^boundary=/, ''))[0]\n\n if (!boundary) {\n return undefined\n }\n\n const boundaryRegExp = new RegExp(\n `--+${boundary.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}`,\n )\n const fields = data\n .split(boundaryRegExp)\n .filter((chunk) => chunk.startsWith('\\r\\n') && chunk.endsWith('\\r\\n'))\n .map((chunk) => chunk.trimStart().replace(/\\r\\n$/, ''))\n\n if (!fields.length) {\n return undefined\n }\n\n const parsedBody: DefaultRequestMultipartBody = {}\n\n try {\n for (const field of fields) {\n const [contentHeaders, ...rest] = field.split('\\r\\n\\r\\n')\n const contentBody = rest.join('\\r\\n\\r\\n')\n const { contentType, filename, name } =\n parseContentHeaders(contentHeaders)\n\n const value =\n filename === undefined\n ? contentBody\n : new File([contentBody], filename, { type: contentType })\n\n const parsedValue = parsedBody[name]\n\n if (parsedValue === undefined) {\n parsedBody[name] = value\n } else if (Array.isArray(parsedValue)) {\n parsedBody[name] = [...parsedValue, value]\n } else {\n parsedBody[name] = [parsedValue, value]\n }\n }\n\n return parsedBody as T\n } catch {\n return undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAgC;AAChC,4BAAiD;AAejD,SAAS,oBAAoB,eAA6C;AACxE,QAAM,cAAU,yCAAgB,aAAa;AAC7C,QAAM,cAAc,QAAQ,IAAI,cAAc,KAAK;AACnD,QAAM,cAAc,QAAQ,IAAI,qBAAqB;AAErD,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC7D;AAEA,QAAM,aAAa,YAAY,MAAM,GAAG,EAAE,OAAO,CAAC,KAAK,UAAU;AAC/D,UAAM,CAACA,OAAM,GAAG,IAAI,IAAI,MAAM,KAAK,EAAE,MAAM,GAAG;AAC9C,QAAIA,KAAI,IAAI,KAAK,KA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;AAEnC,UAAI,gBAAgB,QAAW;AAC7B,mBAAW,IAAI,IAAI;AAAA,MACrB,WAAW,MAAM,QAAQ,WAAW,GAAG;AACrC,mBAAW,IAAI,IAAI,CAAC,GAAG,aAAa,KAAK;AAAA,MAC3C,OAAO;AACL,mBAAW,IAAI,IAAI,CAAC,aAAa,KAAK;AAAA,MACxC;AAAA,IACF;AAEA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":["name","contentType"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/internal/parseMultipartData.ts"],"sourcesContent":["import { stringToHeaders } from 'headers-polyfill'\nimport { DefaultRequestMultipartBody } from '../../handlers/RequestHandler'\n\ninterface ParsedContentHeaders {\n name: string\n filename?: string\n contentType: string\n}\n\ninterface ContentDispositionDirective {\n [key: string]: string | undefined\n name: string\n filename?: string\n 'form-data': string\n}\n\nfunction parseContentHeaders(headersString: string): ParsedContentHeaders {\n const headers = stringToHeaders(headersString)\n const contentType = headers.get('content-type') || 'text/plain'\n const disposition = headers.get('content-disposition')\n\n if (!disposition) {\n throw new Error('\"Content-Disposition\" header is required.')\n }\n\n const directives = disposition.split(';').reduce((acc, chunk) => {\n const [name, ...rest] = chunk.trim().split('=')\n acc[name] = rest.join('=')\n return acc\n }, {} as ContentDispositionDirective)\n\n const name = directives.name?.slice(1, -1)\n const filename = directives.filename?.slice(1, -1)\n\n return {\n name,\n filename,\n contentType,\n }\n}\n\n/**\n * Parses a given string as a multipart/form-data.\n * Does not throw an exception on an invalid multipart string.\n */\nexport function parseMultipartData<T extends DefaultRequestMultipartBody>(\n data: string,\n headers?: Headers,\n): T | undefined {\n const contentType = headers?.get('content-type')\n\n if (!contentType) {\n return undefined\n }\n\n const [, ...directives] = contentType.split(/; */)\n const boundary = directives\n .filter((d) => d.startsWith('boundary='))\n .map((s) => s.replace(/^boundary=/, ''))[0]\n\n if (!boundary) {\n return undefined\n }\n\n const boundaryRegExp = new RegExp(\n `--+${boundary.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}`,\n )\n const fields = data\n .split(boundaryRegExp)\n .filter((chunk) => chunk.startsWith('\\r\\n') && chunk.endsWith('\\r\\n'))\n .map((chunk) => chunk.trimStart().replace(/\\r\\n$/, ''))\n\n if (!fields.length) {\n return undefined\n }\n\n const parsedBody: DefaultRequestMultipartBody = {}\n\n try {\n for (const field of fields) {\n const [contentHeaders, ...rest] = field.split('\\r\\n\\r\\n')\n const contentBody = rest.join('\\r\\n\\r\\n')\n const { contentType, filename, name } =\n parseContentHeaders(contentHeaders)\n\n const value =\n filename === undefined\n ? contentBody\n : new File([contentBody], filename, { type: contentType })\n\n const parsedValue = parsedBody[name]\n\n if (parsedValue === undefined) {\n parsedBody[name] = value\n } else if (Array.isArray(parsedValue)) {\n parsedBody[name] = [...parsedValue, value]\n } else {\n parsedBody[name] = [parsedValue, value]\n }\n }\n\n return parsedBody as T\n } catch {\n return undefined\n }\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/internal/parseMultipartData.ts"],"sourcesContent":["import { stringToHeaders } from 'headers-polyfill'\nimport { type DefaultRequestMultipartBody } from '../../handlers/RequestHandler'\n\ninterface ParsedContentHeaders {\n name: string\n filename?: string\n contentType: string\n}\n\ninterface ContentDispositionDirective {\n [key: string]: string | undefined\n name: string\n filename?: string\n 'form-data': string\n}\n\nfunction parseContentHeaders(headersString: string): ParsedContentHeaders {\n const headers = stringToHeaders(headersString)\n const contentType = headers.get('content-type') || 'text/plain'\n const disposition = headers.get('content-disposition')\n\n if (!disposition) {\n throw new Error('\"Content-Disposition\" header is required.')\n }\n\n const directives = disposition.split(';').reduce((acc, chunk) => {\n const [name, ...rest] = chunk.trim().split('=')\n acc[name] = rest.join('=')\n return acc\n }, {} as ContentDispositionDirective)\n\n const name = directives.name?.slice(1, -1)\n const filename = directives.filename?.slice(1, -1)\n\n return {\n name,\n filename,\n contentType,\n }\n}\n\n/**\n * Parses a given string as a multipart/form-data.\n * Does not throw an exception on an invalid multipart string.\n */\nexport function parseMultipartData<T extends DefaultRequestMultipartBody>(\n data: string,\n headers?: Headers,\n): T | undefined {\n const contentType = headers?.get('content-type')\n\n if (!contentType) {\n return undefined\n }\n\n const [, ...directives] = contentType.split(/; */)\n const boundary = directives\n .filter((d) => d.startsWith('boundary='))\n .map((s) => s.replace(/^boundary=/, ''))[0]\n\n if (!boundary) {\n return undefined\n }\n\n const boundaryRegExp = new RegExp(\n `--+${boundary.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}`,\n )\n const fields = data\n .split(boundaryRegExp)\n .filter((chunk) => chunk.startsWith('\\r\\n') && chunk.endsWith('\\r\\n'))\n .map((chunk) => chunk.trimStart().replace(/\\r\\n$/, ''))\n\n if (!fields.length) {\n return undefined\n }\n\n const parsedBody: DefaultRequestMultipartBody = {}\n\n try {\n for (const field of fields) {\n const [contentHeaders, ...rest] = field.split('\\r\\n\\r\\n')\n const contentBody = rest.join('\\r\\n\\r\\n')\n const { contentType, filename, name } =\n parseContentHeaders(contentHeaders)\n\n const value =\n filename === undefined\n ? contentBody\n : new File([contentBody], filename, { type: contentType })\n\n const parsedValue = parsedBody[name]\n\n if (parsedValue === undefined) {\n parsedBody[name] = value\n } else if (Array.isArray(parsedValue)) {\n parsedBody[name] = [...parsedValue, value]\n } else {\n parsedBody[name] = [parsedValue, value]\n }\n }\n\n return parsedBody as T\n } catch {\n return undefined\n }\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAChC,eAAiD;AAejD,SAAS,oBAAoB,eAA6C;AACxE,QAAM,UAAU,gBAAgB,aAAa;AAC7C,QAAM,cAAc,QAAQ,IAAI,cAAc,KAAK;AACnD,QAAM,cAAc,QAAQ,IAAI,qBAAqB;AAErD,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC7D;AAEA,QAAM,aAAa,YAAY,MAAM,G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C,oBAAoB,cAAc;AAEpC,YAAM,QACJ,aAAa,SACT,cACA,IAAI,KAAK,CAAC,WAAW,GAAG,UAAU,EAAE,MAAMA,aAAY,CAAC;AAE7D,YAAM,cAAc,WAAW,IAAI;AAEnC,UAAI,gBAAgB,QAAW;AAC7B,mBAAW,IAAI,IAAI;AAAA,MACrB,WAAW,MAAM,QAAQ,WAAW,GAAG;AACrC,mBAAW,IAAI,IAAI,CAAC,GAAG,aAAa,KAAK;AAAA,MAC3C,OAAO;AACL,mBAAW,IAAI,IAAI,CAAC,aAAa,KAAK;AAAA,MACxC;AAAA,IACF;AAEA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":["name","contentType"]}
|
|
@@ -21,6 +21,7 @@ __export(pipeEvents_exports, {
|
|
|
21
21
|
pipeEvents: () => pipeEvents
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(pipeEvents_exports);
|
|
24
|
+
var import_strict_event_emitter = require("strict-event-emitter");
|
|
24
25
|
function pipeEvents(source, destination) {
|
|
25
26
|
const rawEmit = source.emit;
|
|
26
27
|
if (rawEmit._isPiped) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/internal/pipeEvents.ts"],"sourcesContent":["import { Emitter
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/internal/pipeEvents.ts"],"sourcesContent":["import type { Emitter } from 'strict-event-emitter'\nimport { type EventMap } from 'strict-event-emitter'\n\n/**\n * Pipes all emitted events from one emitter to another.\n */\nexport function pipeEvents<Events extends EventMap>(\n source: Emitter<Events>,\n destination: Emitter<Events>,\n): void {\n const rawEmit: typeof source.emit & { _isPiped?: boolean } = source.emit\n\n if (rawEmit._isPiped) {\n return\n }\n\n const sourceEmit: typeof source.emit & { _isPiped?: boolean } =\n function sourceEmit(this: typeof source, event, ...data) {\n destination.emit(event, ...data)\n return rawEmit.call(this, event, ...data)\n }\n\n sourceEmit._isPiped = true\n\n source.emit = sourceEmit\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kCAA8B;AAKvB,SAAS,WACd,QACA,aACM;AACN,QAAM,UAAuD,OAAO;AAEpE,MAAI,QAAQ,UAAU;AACpB;AAAA,EACF;AAEA,QAAM,aACJ,SAASA,YAAgC,UAAU,MAAM;AACvD,gBAAY,KAAK,OAAO,GAAG,IAAI;AAC/B,WAAO,QAAQ,KAAK,MAAM,OAAO,GAAG,IAAI;AAAA,EAC1C;AAEF,aAAW,WAAW;AAEtB,SAAO,OAAO;AAChB;","names":["sourceEmit"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/internal/pipeEvents.ts"],"sourcesContent":["import { Emitter
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/internal/pipeEvents.ts"],"sourcesContent":["import type { Emitter } from 'strict-event-emitter'\nimport { type EventMap } from 'strict-event-emitter'\n\n/**\n * Pipes all emitted events from one emitter to another.\n */\nexport function pipeEvents<Events extends EventMap>(\n source: Emitter<Events>,\n destination: Emitter<Events>,\n): void {\n const rawEmit: typeof source.emit & { _isPiped?: boolean } = source.emit\n\n if (rawEmit._isPiped) {\n return\n }\n\n const sourceEmit: typeof source.emit & { _isPiped?: boolean } =\n function sourceEmit(this: typeof source, event, ...data) {\n destination.emit(event, ...data)\n return rawEmit.call(this, event, ...data)\n }\n\n sourceEmit._isPiped = true\n\n source.emit = sourceEmit\n}\n"],"mappings":"AACA,eAA8B;AAKvB,SAAS,WACd,QACA,aACM;AACN,QAAM,UAAuD,OAAO;AAEpE,MAAI,QAAQ,UAAU;AACpB;AAAA,EACF;AAEA,QAAM,aACJ,SAASA,YAAgC,UAAU,MAAM;AACvD,gBAAY,KAAK,OAAO,GAAG,IAAI;AAC/B,WAAO,QAAQ,KAAK,MAAM,OAAO,GAAG,IAAI;AAAA,EAC1C;AAEF,aAAW,WAAW;AAEtB,SAAO,OAAO;AAChB;","names":["sourceEmit"]}
|
|
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(storeResponseCookies_exports);
|
|
|
24
24
|
var import_cookieStore = require("../cookieStore");
|
|
25
25
|
var import_decorators = require("../HttpResponse/decorators");
|
|
26
26
|
async function storeResponseCookies(request, response) {
|
|
27
|
-
const responseCookies =
|
|
27
|
+
const responseCookies = (0, import_decorators.getRawSetCookie)(response);
|
|
28
28
|
if (responseCookies) {
|
|
29
29
|
await import_cookieStore.cookieStore.setCookie(responseCookies, request.url);
|
|
30
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/request/storeResponseCookies.ts"],"sourcesContent":["import { cookieStore } from '../cookieStore'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/storeResponseCookies.ts"],"sourcesContent":["import { cookieStore } from '../cookieStore'\nimport { getRawSetCookie } from '../HttpResponse/decorators'\n\nexport async function storeResponseCookies(\n request: Request,\n response: Response,\n): Promise<void> {\n // Grab the raw \"Set-Cookie\" response header provided\n // in the HeadersInit for this mocked response.\n const responseCookies = getRawSetCookie(response)\n\n if (responseCookies) {\n await cookieStore.setCookie(responseCookies, request.url)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA4B;AAC5B,wBAAgC;AAEhC,eAAsB,qBACpB,SACA,UACe;AAGf,QAAM,sBAAkB,mCAAgB,QAAQ;AAEhD,MAAI,iBAAiB;AACnB,UAAM,+BAAY,UAAU,iBAAiB,QAAQ,GAAG;AAAA,EAC1D;AACF;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cookieStore } from '../cookieStore.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { getRawSetCookie } from '../HttpResponse/decorators.mjs';
|
|
3
3
|
async function storeResponseCookies(request, response) {
|
|
4
|
-
const responseCookies =
|
|
4
|
+
const responseCookies = getRawSetCookie(response);
|
|
5
5
|
if (responseCookies) {
|
|
6
6
|
await cookieStore.setCookie(responseCookies, request.url);
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/request/storeResponseCookies.ts"],"sourcesContent":["import { cookieStore } from '../cookieStore'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/storeResponseCookies.ts"],"sourcesContent":["import { cookieStore } from '../cookieStore'\nimport { getRawSetCookie } from '../HttpResponse/decorators'\n\nexport async function storeResponseCookies(\n request: Request,\n response: Response,\n): Promise<void> {\n // Grab the raw \"Set-Cookie\" response header provided\n // in the HeadersInit for this mocked response.\n const responseCookies = getRawSetCookie(response)\n\n if (responseCookies) {\n await cookieStore.setCookie(responseCookies, request.url)\n }\n}\n"],"mappings":"AAAA,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAEhC,eAAsB,qBACpB,SACA,UACe;AAGf,QAAM,kBAAkB,gBAAgB,QAAQ;AAEhD,MAAI,iBAAiB;AACnB,UAAM,YAAY,UAAU,iBAAiB,QAAQ,GAAG;AAAA,EAC1D;AACF;","names":[]}
|
|
@@ -43,6 +43,7 @@ class WebSocketClientManager {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
channel;
|
|
46
47
|
store;
|
|
47
48
|
runtimeClients;
|
|
48
49
|
allClients;
|
|
@@ -126,6 +127,9 @@ class WebSocketRemoteClientConnection {
|
|
|
126
127
|
this.url = url;
|
|
127
128
|
this.channel = channel;
|
|
128
129
|
}
|
|
130
|
+
id;
|
|
131
|
+
url;
|
|
132
|
+
channel;
|
|
129
133
|
send(data) {
|
|
130
134
|
this.channel.postMessage({
|
|
131
135
|
type: "extraneous:send",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/ws/WebSocketClientManager.ts"],"sourcesContent":["import type {\n WebSocketData,\n WebSocketClientConnectionProtocol,\n WebSocketClientEventMap,\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(\n client: WebSocketClientConnectionProtocol,\n ): 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(\n client: WebSocketClientConnectionProtocol,\n ): 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 addEventListener<EventType extends keyof WebSocketClientEventMap>(\n _type: EventType,\n _listener: (\n this: WebSocket,\n event: WebSocketClientEventMap[EventType],\n ) => void,\n _options?: AddEventListenerOptions | boolean,\n ): void {\n throw new Error(\n 'WebSocketRemoteClientConnection.addEventListener is not supported',\n )\n }\n\n removeEventListener<EventType extends keyof WebSocketClientEventMap>(\n _event: EventType,\n _listener: (\n this: WebSocket,\n event: WebSocketClientEventMap[EventType],\n ) => void,\n _options?: EventListenerOptions | boolean,\n ): void {\n throw new Error(\n 'WebSocketRemoteClientConnection.removeEventListener is not supported',\n )\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,
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/WebSocketClientManager.ts"],"sourcesContent":["import type {\n WebSocketData,\n WebSocketClientConnectionProtocol,\n WebSocketClientEventMap,\n} from '@mswjs/interceptors/WebSocket'\nimport type { 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(\n client: WebSocketClientConnectionProtocol,\n ): 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(\n client: WebSocketClientConnectionProtocol,\n ): 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 addEventListener<EventType extends keyof WebSocketClientEventMap>(\n _type: EventType,\n _listener: (\n this: WebSocket,\n event: WebSocketClientEventMap[EventType],\n ) => void,\n _options?: AddEventListenerOptions | boolean,\n ): void {\n throw new Error(\n 'WebSocketRemoteClientConnection.addEventListener is not supported',\n )\n }\n\n removeEventListener<EventType extends keyof WebSocketClientEventMap>(\n _event: EventType,\n _listener: (\n this: WebSocket,\n event: WebSocketClientEventMap[EventType],\n ) => void,\n _options?: EventListenerOptions | boolean,\n ): void {\n throw new Error(\n 'WebSocketRemoteClientConnection.removeEventListener is not supported',\n )\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,o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ACE,OACA,WAIA,UACM;AACN,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EAEA,oBACE,QACA,WAIA,UACM;AACN,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -19,6 +19,7 @@ class WebSocketClientManager {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
channel;
|
|
22
23
|
store;
|
|
23
24
|
runtimeClients;
|
|
24
25
|
allClients;
|
|
@@ -102,6 +103,9 @@ class WebSocketRemoteClientConnection {
|
|
|
102
103
|
this.url = url;
|
|
103
104
|
this.channel = channel;
|
|
104
105
|
}
|
|
106
|
+
id;
|
|
107
|
+
url;
|
|
108
|
+
channel;
|
|
105
109
|
send(data) {
|
|
106
110
|
this.channel.postMessage({
|
|
107
111
|
type: "extraneous:send",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/ws/WebSocketClientManager.ts"],"sourcesContent":["import type {\n WebSocketData,\n WebSocketClientConnectionProtocol,\n WebSocketClientEventMap,\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(\n client: WebSocketClientConnectionProtocol,\n ): 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(\n client: WebSocketClientConnectionProtocol,\n ): 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 addEventListener<EventType extends keyof WebSocketClientEventMap>(\n _type: EventType,\n _listener: (\n this: WebSocket,\n event: WebSocketClientEventMap[EventType],\n ) => void,\n _options?: AddEventListenerOptions | boolean,\n ): void {\n throw new Error(\n 'WebSocketRemoteClientConnection.addEventListener is not supported',\n )\n }\n\n removeEventListener<EventType extends keyof WebSocketClientEventMap>(\n _event: EventType,\n _listener: (\n this: WebSocket,\n event: WebSocketClientEventMap[EventType],\n ) => void,\n _options?: EventListenerOptions | boolean,\n ): void {\n throw new Error(\n 'WebSocketRemoteClientConnection.removeEventListener is not supported',\n )\n }\n}\n"],"mappings":"AAMA,SAAS,kCAAkC;AAC3C,SAAS,qCAAqC;AAuBvC,MAAM,uBAAuB;AAAA,EAKlC,YAAoB,SAA2B;AAA3B;AAGlB,SAAK,QACH,OAAO,cAAc,cACjB,IAAI,8BAA8B,IAClC,IAAI,2BAA2B;AAErC,SAAK,iBAAiB,oBAAI,IAAI;AAC9B,SAAK,aAAa,oBAAI,IAAI;AAE1B,SAAK,QAAQ,iBAAiB,WAAW,CAAC,YAAY;AACpD,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,
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/WebSocketClientManager.ts"],"sourcesContent":["import type {\n WebSocketData,\n WebSocketClientConnectionProtocol,\n WebSocketClientEventMap,\n} from '@mswjs/interceptors/WebSocket'\nimport type { 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(\n client: WebSocketClientConnectionProtocol,\n ): 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(\n client: WebSocketClientConnectionProtocol,\n ): 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 addEventListener<EventType extends keyof WebSocketClientEventMap>(\n _type: EventType,\n _listener: (\n this: WebSocket,\n event: WebSocketClientEventMap[EventType],\n ) => void,\n _options?: AddEventListenerOptions | boolean,\n ): void {\n throw new Error(\n 'WebSocketRemoteClientConnection.addEventListener is not supported',\n )\n }\n\n removeEventListener<EventType extends keyof WebSocketClientEventMap>(\n _event: EventType,\n _listener: (\n this: WebSocket,\n event: WebSocketClientEventMap[EventType],\n ) => void,\n _options?: EventListenerOptions | boolean,\n ): void {\n throw new Error(\n 'WebSocketRemoteClientConnection.removeEventListener is not supported',\n )\n }\n}\n"],"mappings":"AAMA,SAAS,kCAAkC;AAC3C,SAAS,qCAAqC;AAuBvC,MAAM,uBAAuB;AAAA,EAKlC,YAAoB,SAA2B;AAA3B;AAGlB,SAAK,QACH,OAAO,cAAc,cACjB,IAAI,8BAA8B,IAClC,IAAI,2BAA2B;AAErC,SAAK,iBAAiB,oBAAI,IAAI;AAC9B,SAAK,aAAa,oBAAI,IAAI;AAE1B,SAAK,QAAQ,iBAAiB,WAAW,CAAC,YAAY;AACpD,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,EAxBoB;AAAA,EAJZ;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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AChE,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,EAHe;AAAA,EACA;AAAA,EACR;AAAA,EAGV,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;AAAA,EAEA,iBACE,OACA,WAIA,UACM;AACN,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EAEA,oBACE,QACA,WAIA,UACM;AACN,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -22,6 +22,7 @@ __export(WebSocketIndexedDBClientStore_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(WebSocketIndexedDBClientStore_exports);
|
|
24
24
|
var import_deferred_promise = require("@open-draft/deferred-promise");
|
|
25
|
+
var import_WebSocketClientStore = require("./WebSocketClientStore");
|
|
25
26
|
const DB_NAME = "msw-websocket-clients";
|
|
26
27
|
const DB_STORE_NAME = "clients";
|
|
27
28
|
class WebSocketIndexedDBClientStore {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/ws/WebSocketIndexedDBClientStore.ts"],"sourcesContent":["import { DeferredPromise } from '@open-draft/deferred-promise'\nimport { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\nimport {\
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/WebSocketIndexedDBClientStore.ts"],"sourcesContent":["import { DeferredPromise } from '@open-draft/deferred-promise'\nimport type { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\nimport type { WebSocketClientStore } from './WebSocketClientStore'\nimport { type SerializedWebSocketClient } from './WebSocketClientStore'\n\nconst DB_NAME = 'msw-websocket-clients'\nconst DB_STORE_NAME = 'clients'\n\nexport class WebSocketIndexedDBClientStore implements WebSocketClientStore {\n private db: Promise<IDBDatabase>\n\n constructor() {\n this.db = this.createDatabase()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n\n /**\n * @note Use `.put()` instead of `.add()` to allow setting clients\n * that already exist in the database. This can happen if a single page\n * has multiple event handlers. Each handler will receive the \"connection\"\n * event in parallel, and try to set that WebSocket client in the database.\n */\n const request = store.put({\n id: client.id,\n url: client.url.href,\n } satisfies SerializedWebSocketClient)\n\n request.onsuccess = () => {\n promise.resolve()\n }\n request.onerror = () => {\n console.error(request.error)\n promise.reject(\n new Error(\n `Failed to add WebSocket client \"${client.id}\". There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n public async getAll(): Promise<Array<SerializedWebSocketClient>> {\n const promise = new DeferredPromise<Array<SerializedWebSocketClient>>()\n const store = await this.getStore()\n const request = store.getAll() as IDBRequest<\n Array<SerializedWebSocketClient>\n >\n\n request.onsuccess = () => {\n promise.resolve(request.result)\n }\n request.onerror = () => {\n console.error(request.error)\n promise.reject(\n new Error(\n `Failed to get all WebSocket clients. There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n\n for (const clientId of clientIds) {\n store.delete(clientId)\n }\n\n store.transaction.oncomplete = () => {\n promise.resolve()\n }\n store.transaction.onerror = () => {\n console.error(store.transaction.error)\n promise.reject(\n new Error(\n `Failed to delete WebSocket clients [${clientIds.join(', ')}]. There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n private async createDatabase(): Promise<IDBDatabase> {\n const promise = new DeferredPromise<IDBDatabase>()\n const request = indexedDB.open(DB_NAME, 1)\n\n request.onsuccess = ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return promise.resolve(db)\n }\n }\n\n request.onupgradeneeded = async ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return\n }\n\n const store = db.createObjectStore(DB_STORE_NAME, { keyPath: 'id' })\n store.transaction.oncomplete = () => {\n promise.resolve(db)\n }\n store.transaction.onerror = () => {\n console.error(store.transaction.error)\n promise.reject(\n new Error(\n 'Failed to create WebSocket client store. There is likely an additional output above.',\n ),\n )\n }\n }\n request.onerror = () => {\n console.error(request.error)\n promise.reject(\n new Error(\n 'Failed to open an IndexedDB database. There is likely an additional output above.',\n ),\n )\n }\n\n return promise\n }\n\n private async getStore(): Promise<IDBObjectStore> {\n const db = await this.db\n return db.transaction(DB_STORE_NAME, 'readwrite').objectStore(DB_STORE_NAME)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAgC;AAGhC,kCAA+C;AAE/C,MAAM,UAAU;AAChB,MAAM,gBAAgB;AAEf,MAAM,8BAA8D;AAAA,EACjE;AAAA,EAER,cAAc;AACZ,SAAK,KAAK,KAAK,eAAe;AAAA,EAChC;AAAA,EAEA,MAAa,IAAI,QAA0D;AACzE,UAAM,UAAU,IAAI,wCAAsB;AAC1C,UAAM,QAAQ,MAAM,KAAK,SAAS;AAQlC,UAAM,UAAU,MAAM,IAAI;AAAA,MACxB,IAAI,OAAO;AAAA,MACX,KAAK,OA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AAE/C,UAAI,GAAG,iBAAiB,SAAS,aAAa,GAAG;AAC/C,eAAO,QAAQ,QAAQ,EAAE;AAAA,MAC3B;AAAA,IACF;AAEA,YAAQ,kBAAkB,OAAO,EAAE,cAAc,MAAM;AACrD,YAAM,KAAK,QAAQ,IAAI,eAAgB,QAAQ;AAC/C,UAAI,GAAG,iBAAiB,SAAS,aAAa,GAAG;AAC/C;AAAA,MACF;AAEA,YAAM,QAAQ,GAAG,kBAAkB,eAAe,EAAE,SAAS,KAAK,CAAC;AACnE,YAAM,YAAY,aAAa,MAAM;AACnC,gBAAQ,QAAQ,EAAE;AAAA,MACpB;AACA,YAAM,YAAY,UAAU,MAAM;AAChC,gBAAQ,MAAM,MAAM,YAAY,KAAK;AACrC,gBAAQ;AAAA,UACN,IAAI;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,YAAQ,UAAU,MAAM;AACtB,cAAQ,MAAM,QAAQ,KAAK;AAC3B,cAAQ;AAAA,QACN,IAAI;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,WAAoC;AAChD,UAAM,KAAK,MAAM,KAAK;AACtB,WAAO,GAAG,YAAY,eAAe,WAAW,EAAE,YAAY,aAAa;AAAA,EAC7E;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/ws/WebSocketIndexedDBClientStore.ts"],"sourcesContent":["import { DeferredPromise } from '@open-draft/deferred-promise'\nimport { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\nimport {\
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/WebSocketIndexedDBClientStore.ts"],"sourcesContent":["import { DeferredPromise } from '@open-draft/deferred-promise'\nimport type { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\nimport type { WebSocketClientStore } from './WebSocketClientStore'\nimport { type SerializedWebSocketClient } from './WebSocketClientStore'\n\nconst DB_NAME = 'msw-websocket-clients'\nconst DB_STORE_NAME = 'clients'\n\nexport class WebSocketIndexedDBClientStore implements WebSocketClientStore {\n private db: Promise<IDBDatabase>\n\n constructor() {\n this.db = this.createDatabase()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n\n /**\n * @note Use `.put()` instead of `.add()` to allow setting clients\n * that already exist in the database. This can happen if a single page\n * has multiple event handlers. Each handler will receive the \"connection\"\n * event in parallel, and try to set that WebSocket client in the database.\n */\n const request = store.put({\n id: client.id,\n url: client.url.href,\n } satisfies SerializedWebSocketClient)\n\n request.onsuccess = () => {\n promise.resolve()\n }\n request.onerror = () => {\n console.error(request.error)\n promise.reject(\n new Error(\n `Failed to add WebSocket client \"${client.id}\". There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n public async getAll(): Promise<Array<SerializedWebSocketClient>> {\n const promise = new DeferredPromise<Array<SerializedWebSocketClient>>()\n const store = await this.getStore()\n const request = store.getAll() as IDBRequest<\n Array<SerializedWebSocketClient>\n >\n\n request.onsuccess = () => {\n promise.resolve(request.result)\n }\n request.onerror = () => {\n console.error(request.error)\n promise.reject(\n new Error(\n `Failed to get all WebSocket clients. There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n\n for (const clientId of clientIds) {\n store.delete(clientId)\n }\n\n store.transaction.oncomplete = () => {\n promise.resolve()\n }\n store.transaction.onerror = () => {\n console.error(store.transaction.error)\n promise.reject(\n new Error(\n `Failed to delete WebSocket clients [${clientIds.join(', ')}]. There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n private async createDatabase(): Promise<IDBDatabase> {\n const promise = new DeferredPromise<IDBDatabase>()\n const request = indexedDB.open(DB_NAME, 1)\n\n request.onsuccess = ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return promise.resolve(db)\n }\n }\n\n request.onupgradeneeded = async ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return\n }\n\n const store = db.createObjectStore(DB_STORE_NAME, { keyPath: 'id' })\n store.transaction.oncomplete = () => {\n promise.resolve(db)\n }\n store.transaction.onerror = () => {\n console.error(store.transaction.error)\n promise.reject(\n new Error(\n 'Failed to create WebSocket client store. There is likely an additional output above.',\n ),\n )\n }\n }\n request.onerror = () => {\n console.error(request.error)\n promise.reject(\n new Error(\n 'Failed to open an IndexedDB database. There is likely an additional output above.',\n ),\n )\n }\n\n return promise\n }\n\n private async getStore(): Promise<IDBObjectStore> {\n const db = await this.db\n return db.transaction(DB_STORE_NAME, 'readwrite').objectStore(DB_STORE_NAME)\n }\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAGhC,eAA+C;AAE/C,MAAM,UAAU;AAChB,MAAM,gBAAgB;AAEf,MAAM,8BAA8D;AAAA,EACjE;AAAA,EAER,cAAc;AACZ,SAAK,KAAK,KAAK,eAAe;AAAA,EAChC;AAAA,EAEA,MAAa,IAAI,QAA0D;AACzE,UAAM,UAAU,IAAI,gBAAsB;AAC1C,UAAM,QAAQ,MAAM,KAAK,SAAS;AAQlC,UAAM,UAAU,MAAM,IAAI;AAAA,MACxB,IAAI,OAAO;AAAA,MACX,KAAK,OAAO,IAAI;AAAA,IAClB,CAAqC;AAErC,YAAQ,YAAY,MAAM;AACxB,cAAQ,QAAQ;AAAA,IAClB;AACA,YAAQ,UAAU,MAAM;AACtB,cAAQ,MAAM,QAAQ,KAAK;AAC3B,cAAQ;AAAA,QACN,IAAI;AAAA,UACF,mCAAmC,OAAO,EAAE;AAAA,QAC9C;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAa,SAAoD;AAC/D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Ae,EAAE,SAAS,KAAK,CAAC;AACnE,YAAM,YAAY,aAAa,MAAM;AACnC,gBAAQ,QAAQ,EAAE;AAAA,MACpB;AACA,YAAM,YAAY,UAAU,MAAM;AAChC,gBAAQ,MAAM,MAAM,YAAY,KAAK;AACrC,gBAAQ;AAAA,UACN,IAAI;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,YAAQ,UAAU,MAAM;AACtB,cAAQ,MAAM,QAAQ,KAAK;AAC3B,cAAQ;AAAA,QACN,IAAI;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,WAAoC;AAChD,UAAM,KAAK,MAAM,KAAK;AACtB,WAAO,GAAG,YAAY,eAAe,WAAW,EAAE,YAAY,aAAa;AAAA,EAC7E;AACF;","names":[]}
|
|
@@ -21,6 +21,7 @@ __export(WebSocketMemoryClientStore_exports, {
|
|
|
21
21
|
WebSocketMemoryClientStore: () => WebSocketMemoryClientStore
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(WebSocketMemoryClientStore_exports);
|
|
24
|
+
var import_WebSocketClientStore = require("./WebSocketClientStore");
|
|
24
25
|
class WebSocketMemoryClientStore {
|
|
25
26
|
store;
|
|
26
27
|
constructor() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/ws/WebSocketMemoryClientStore.ts"],"sourcesContent":["import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\nimport {\
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/WebSocketMemoryClientStore.ts"],"sourcesContent":["import type { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\nimport type { WebSocketClientStore } from './WebSocketClientStore'\nimport { type SerializedWebSocketClient } from './WebSocketClientStore'\n\nexport class WebSocketMemoryClientStore implements WebSocketClientStore {\n private store: Map<string, SerializedWebSocketClient>\n\n constructor() {\n this.store = new Map()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n this.store.set(client.id, { id: client.id, url: client.url.href })\n }\n\n public getAll(): Promise<Array<SerializedWebSocketClient>> {\n return Promise.resolve(Array.from(this.store.values()))\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n for (const clientId of clientIds) {\n this.store.delete(clientId)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kCAA+C;AAExC,MAAM,2BAA2D;AAAA,EAC9D;AAAA,EAER,cAAc;AACZ,SAAK,QAAQ,oBAAI,IAAI;AAAA,EACvB;AAAA,EAEA,MAAa,IAAI,QAA0D;AACzE,SAAK,MAAM,IAAI,OAAO,IAAI,EAAE,IAAI,OAAO,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC;AAAA,EACnE;AAAA,EAEO,SAAoD;AACzD,WAAO,QAAQ,QAAQ,MAAM,KAAK,KAAK,MAAM,OAAO,CAAC,CAAC;AAAA,EACxD;AAAA,EAEA,MAAa,WAAW,WAAyC;AAC/D,eAAW,YAAY,WAAW;AAChC,WAAK,MAAM,OAAO,QAAQ;AAAA,IAC5B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/ws/WebSocketMemoryClientStore.ts"],"sourcesContent":["import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\nimport {\
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/WebSocketMemoryClientStore.ts"],"sourcesContent":["import type { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\nimport type { WebSocketClientStore } from './WebSocketClientStore'\nimport { type SerializedWebSocketClient } from './WebSocketClientStore'\n\nexport class WebSocketMemoryClientStore implements WebSocketClientStore {\n private store: Map<string, SerializedWebSocketClient>\n\n constructor() {\n this.store = new Map()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n this.store.set(client.id, { id: client.id, url: client.url.href })\n }\n\n public getAll(): Promise<Array<SerializedWebSocketClient>> {\n return Promise.resolve(Array.from(this.store.values()))\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n for (const clientId of clientIds) {\n this.store.delete(clientId)\n }\n }\n}\n"],"mappings":"AAEA,eAA+C;AAExC,MAAM,2BAA2D;AAAA,EAC9D;AAAA,EAER,cAAc;AACZ,SAAK,QAAQ,oBAAI,IAAI;AAAA,EACvB;AAAA,EAEA,MAAa,IAAI,QAA0D;AACzE,SAAK,MAAM,IAAI,OAAO,IAAI,EAAE,IAAI,OAAO,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC;AAAA,EACnE;AAAA,EAEO,SAAoD;AACzD,WAAO,QAAQ,QAAQ,MAAM,KAAK,KAAK,MAAM,OAAO,CAAC,CAAC;AAAA,EACxD;AAAA,EAEA,MAAa,WAAW,WAAyC;AAC/D,eAAW,YAAY,WAAW;AAChC,WAAK,MAAM,OAAO,QAAQ;AAAA,IAC5B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket';
|
|
2
|
-
import { R as RequestHandler } from '../HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from '../HttpResponse-BE_Y2Ak9.mjs';
|
|
3
3
|
import { WebSocketHandler } from '../handlers/WebSocketHandler.mjs';
|
|
4
4
|
import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.mjs';
|
|
5
5
|
import '@mswjs/interceptors';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket';
|
|
2
|
-
import { R as RequestHandler } from '../HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from '../HttpResponse-DL-P1EeG.js';
|
|
3
3
|
import { WebSocketHandler } from '../handlers/WebSocketHandler.js';
|
|
4
4
|
import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.js';
|
|
5
5
|
import '@mswjs/interceptors';
|