msw 2.5.2 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/index.d.mts +7 -6
- package/lib/browser/index.d.ts +7 -6
- package/lib/browser/index.js +28 -2
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +28 -2
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-ClMB0BOy.d.mts → GraphQLHandler-B6uni-E_.d.mts} +1 -1
- package/lib/core/{GraphQLHandler-D6mLMXGZ.d.ts → GraphQLHandler-Cjm7JNGi.d.ts} +1 -1
- package/lib/core/{HttpResponse-vn-Pb4Bi.d.mts → HttpResponse-63H9vVoL.d.mts} +1 -0
- package/lib/core/{HttpResponse-DaYkf3ml.d.ts → HttpResponse-DzhqZzTK.d.ts} +1 -0
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/SetupApi.d.mts +15 -12
- package/lib/core/SetupApi.d.ts +15 -12
- package/lib/core/SetupApi.js +3 -1
- package/lib/core/SetupApi.js.map +1 -1
- package/lib/core/SetupApi.mjs +3 -1
- package/lib/core/SetupApi.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 +2 -2
- package/lib/core/graphql.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +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 +2 -0
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs +2 -0
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +34 -0
- package/lib/core/handlers/WebSocketHandler.d.ts +34 -0
- package/lib/core/handlers/WebSocketHandler.js +122 -0
- package/lib/core/handlers/WebSocketHandler.js.map +1 -0
- package/lib/core/handlers/WebSocketHandler.mjs +104 -0
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -0
- package/lib/core/handlers/common.d.mts +3 -0
- package/lib/core/handlers/common.d.ts +3 -0
- package/lib/core/handlers/common.js +17 -0
- package/lib/core/handlers/common.js.map +1 -0
- package/lib/core/handlers/common.mjs +1 -0
- package/lib/core/handlers/common.mjs.map +1 -0
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +5 -2
- package/lib/core/index.d.ts +5 -2
- package/lib/core/index.js +5 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +7 -1
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +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.map +1 -1
- package/lib/core/utils/executeHandlers.mjs.map +1 -1
- package/lib/core/utils/handleRequest.d.mts +2 -2
- package/lib/core/utils/handleRequest.d.ts +2 -2
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/core/utils/internal/isHandlerKind.d.mts +17 -0
- package/lib/core/utils/internal/isHandlerKind.d.ts +17 -0
- package/lib/core/utils/internal/isHandlerKind.js +29 -0
- package/lib/core/utils/internal/isHandlerKind.js.map +1 -0
- package/lib/core/utils/internal/isHandlerKind.mjs +9 -0
- package/lib/core/utils/internal/isHandlerKind.mjs.map +1 -0
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
- 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/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/utils/logging/getTimestamp.d.mts +4 -1
- package/lib/core/utils/logging/getTimestamp.d.ts +4 -1
- package/lib/core/utils/logging/getTimestamp.js +6 -2
- package/lib/core/utils/logging/getTimestamp.js.map +1 -1
- package/lib/core/utils/logging/getTimestamp.mjs +6 -2
- package/lib/core/utils/logging/getTimestamp.mjs.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.d.mts +2 -1
- package/lib/core/utils/matching/matchRequestUrl.d.ts +2 -1
- package/lib/core/utils/matching/matchRequestUrl.js +4 -0
- package/lib/core/utils/matching/matchRequestUrl.js.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs +4 -0
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -1
- package/lib/core/ws/WebSocketClientManager.d.mts +63 -0
- package/lib/core/ws/WebSocketClientManager.d.ts +63 -0
- package/lib/core/ws/WebSocketClientManager.js +149 -0
- package/lib/core/ws/WebSocketClientManager.js.map +1 -0
- package/lib/core/ws/WebSocketClientManager.mjs +129 -0
- package/lib/core/ws/WebSocketClientManager.mjs.map +1 -0
- package/lib/core/ws/WebSocketClientStore.d.mts +13 -0
- package/lib/core/ws/WebSocketClientStore.d.ts +13 -0
- package/lib/core/ws/WebSocketClientStore.js +26 -0
- package/lib/core/ws/WebSocketClientStore.js.map +1 -0
- package/lib/core/ws/WebSocketClientStore.mjs +6 -0
- package/lib/core/ws/WebSocketClientStore.mjs.map +1 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.d.mts +15 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.d.ts +15 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.js +130 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +110 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -0
- package/lib/core/ws/WebSocketMemoryClientStore.d.mts +13 -0
- package/lib/core/ws/WebSocketMemoryClientStore.d.ts +13 -0
- package/lib/core/ws/WebSocketMemoryClientStore.js +41 -0
- package/lib/core/ws/WebSocketMemoryClientStore.js.map +1 -0
- package/lib/core/ws/WebSocketMemoryClientStore.mjs +21 -0
- package/lib/core/ws/WebSocketMemoryClientStore.mjs.map +1 -0
- package/lib/core/ws/handleWebSocketEvent.d.mts +19 -0
- package/lib/core/ws/handleWebSocketEvent.d.ts +19 -0
- package/lib/core/ws/handleWebSocketEvent.js +74 -0
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -0
- package/lib/core/ws/handleWebSocketEvent.mjs +56 -0
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -0
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +12 -0
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +12 -0
- package/lib/core/ws/utils/attachWebSocketLogger.js +198 -0
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -0
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +178 -0
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -0
- package/lib/core/ws/utils/getMessageLength.d.mts +11 -0
- package/lib/core/ws/utils/getMessageLength.d.ts +11 -0
- package/lib/core/ws/utils/getMessageLength.js +33 -0
- package/lib/core/ws/utils/getMessageLength.js.map +1 -0
- package/lib/core/ws/utils/getMessageLength.mjs +13 -0
- package/lib/core/ws/utils/getMessageLength.mjs.map +1 -0
- package/lib/core/ws/utils/getPublicData.d.mts +5 -0
- package/lib/core/ws/utils/getPublicData.d.ts +5 -0
- package/lib/core/ws/utils/getPublicData.js +36 -0
- package/lib/core/ws/utils/getPublicData.js.map +1 -0
- package/lib/core/ws/utils/getPublicData.mjs +16 -0
- package/lib/core/ws/utils/getPublicData.mjs.map +1 -0
- package/lib/core/ws/utils/truncateMessage.d.mts +3 -0
- package/lib/core/ws/utils/truncateMessage.d.ts +3 -0
- package/lib/core/ws/utils/truncateMessage.js +31 -0
- package/lib/core/ws/utils/truncateMessage.js.map +1 -0
- package/lib/core/ws/utils/truncateMessage.mjs +11 -0
- package/lib/core/ws/utils/truncateMessage.mjs.map +1 -0
- package/lib/core/ws/webSocketInterceptor.d.mts +5 -0
- package/lib/core/ws/webSocketInterceptor.d.ts +5 -0
- package/lib/core/ws/webSocketInterceptor.js +26 -0
- package/lib/core/ws/webSocketInterceptor.js.map +1 -0
- package/lib/core/ws/webSocketInterceptor.mjs +6 -0
- package/lib/core/ws/webSocketInterceptor.mjs.map +1 -0
- package/lib/core/ws.d.mts +75 -0
- package/lib/core/ws.d.ts +75 -0
- package/lib/core/ws.js +71 -0
- package/lib/core/ws.js.map +1 -0
- package/lib/core/ws.mjs +54 -0
- package/lib/core/ws.mjs.map +1 -0
- package/lib/iife/index.js +1420 -86
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.mts +6 -5
- package/lib/native/index.d.ts +6 -5
- package/lib/native/index.js +19 -4
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +19 -4
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.d.mts +8 -7
- package/lib/node/index.d.ts +8 -7
- package/lib/node/index.js +19 -4
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +19 -4
- package/lib/node/index.mjs.map +1 -1
- package/package.json +10 -1
- package/src/browser/setupWorker/glossary.ts +10 -10
- package/src/browser/setupWorker/setupWorker.ts +32 -3
- package/src/browser/setupWorker/start/createFallbackRequestListener.ts +2 -1
- package/src/browser/setupWorker/start/createRequestListener.ts +2 -1
- package/src/browser/setupWorker/start/createStartHandler.ts +5 -0
- package/src/browser/setupWorker/stop/createStop.ts +6 -0
- package/src/core/SetupApi.ts +28 -20
- package/src/core/handlers/RequestHandler.ts +4 -0
- package/src/core/handlers/WebSocketHandler.ts +146 -0
- package/src/core/handlers/common.ts +1 -0
- package/src/core/index.ts +11 -1
- package/src/core/utils/executeHandlers.ts +1 -1
- package/src/core/utils/handleRequest.ts +1 -1
- package/src/core/utils/internal/isHandlerKind.test.ts +64 -0
- package/src/core/utils/internal/isHandlerKind.ts +21 -0
- package/src/core/utils/logging/getTimestamp.test.ts +20 -6
- package/src/core/utils/logging/getTimestamp.ts +11 -6
- package/src/core/utils/matching/matchRequestUrl.test.ts +44 -0
- package/src/core/utils/matching/matchRequestUrl.ts +4 -0
- package/src/core/ws/WebSocketClientManager.test.ts +164 -0
- package/src/core/ws/WebSocketClientManager.ts +211 -0
- package/src/core/ws/WebSocketClientStore.ts +14 -0
- package/src/core/ws/WebSocketIndexedDBClientStore.ts +145 -0
- package/src/core/ws/WebSocketMemoryClientStore.ts +27 -0
- package/src/core/ws/handleWebSocketEvent.ts +83 -0
- package/src/core/ws/utils/attachWebSocketLogger.ts +259 -0
- package/src/core/ws/utils/getMessageLength.test.ts +16 -0
- package/src/core/ws/utils/getMessageLength.ts +19 -0
- package/src/core/ws/utils/getPublicData.test.ts +38 -0
- package/src/core/ws/utils/getPublicData.ts +17 -0
- package/src/core/ws/utils/truncateMessage.test.ts +12 -0
- package/src/core/ws/utils/truncateMessage.ts +9 -0
- package/src/core/ws/webSocketInterceptor.ts +3 -0
- package/src/core/ws.test.ts +23 -0
- package/src/core/ws.ts +166 -0
- package/src/node/SetupServerApi.ts +8 -7
- package/src/node/SetupServerCommonApi.ts +25 -5
- package/src/node/glossary.ts +5 -7
- package/src/node/setupServer.ts +2 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { WebSocketMemoryClientStore } from './WebSocketMemoryClientStore.mjs';
|
|
2
|
+
import { WebSocketIndexedDBClientStore } from './WebSocketIndexedDBClientStore.mjs';
|
|
3
|
+
class WebSocketClientManager {
|
|
4
|
+
constructor(channel) {
|
|
5
|
+
this.channel = channel;
|
|
6
|
+
this.store = typeof indexedDB !== "undefined" ? new WebSocketIndexedDBClientStore() : new WebSocketMemoryClientStore();
|
|
7
|
+
this.runtimeClients = /* @__PURE__ */ new Map();
|
|
8
|
+
this.allClients = /* @__PURE__ */ new Set();
|
|
9
|
+
this.channel.addEventListener("message", (message) => {
|
|
10
|
+
if (message.data?.type === "db:update") {
|
|
11
|
+
this.flushDatabaseToMemory();
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
if (typeof window !== "undefined") {
|
|
15
|
+
window.addEventListener("message", async (message) => {
|
|
16
|
+
if (message.data?.type === "msw/worker:stop") {
|
|
17
|
+
await this.removeRuntimeClients();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
store;
|
|
23
|
+
runtimeClients;
|
|
24
|
+
allClients;
|
|
25
|
+
async flushDatabaseToMemory() {
|
|
26
|
+
const storedClients = await this.store.getAll();
|
|
27
|
+
this.allClients = new Set(
|
|
28
|
+
storedClients.map((client) => {
|
|
29
|
+
const runtimeClient = this.runtimeClients.get(client.id);
|
|
30
|
+
if (runtimeClient) {
|
|
31
|
+
return runtimeClient;
|
|
32
|
+
}
|
|
33
|
+
return new WebSocketRemoteClientConnection(
|
|
34
|
+
client.id,
|
|
35
|
+
new URL(client.url),
|
|
36
|
+
this.channel
|
|
37
|
+
);
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
async removeRuntimeClients() {
|
|
42
|
+
await this.store.deleteMany(Array.from(this.runtimeClients.keys()));
|
|
43
|
+
this.runtimeClients.clear();
|
|
44
|
+
await this.flushDatabaseToMemory();
|
|
45
|
+
this.notifyOthersAboutDatabaseUpdate();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* All active WebSocket client connections.
|
|
49
|
+
*/
|
|
50
|
+
get clients() {
|
|
51
|
+
return this.allClients;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Notify other runtimes about the database update
|
|
55
|
+
* using the shared `BroadcastChannel` instance.
|
|
56
|
+
*/
|
|
57
|
+
notifyOthersAboutDatabaseUpdate() {
|
|
58
|
+
this.channel.postMessage({ type: "db:update" });
|
|
59
|
+
}
|
|
60
|
+
async addClient(client) {
|
|
61
|
+
await this.store.add(client);
|
|
62
|
+
await this.flushDatabaseToMemory();
|
|
63
|
+
this.notifyOthersAboutDatabaseUpdate();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Adds the given `WebSocket` client connection to the set
|
|
67
|
+
* of all connections. The given connection is always the complete
|
|
68
|
+
* connection object because `addConnection()` is called only
|
|
69
|
+
* for the opened connections in the same runtime.
|
|
70
|
+
*/
|
|
71
|
+
async addConnection(client) {
|
|
72
|
+
this.runtimeClients.set(client.id, client);
|
|
73
|
+
await this.addClient(client);
|
|
74
|
+
const handleExtraneousMessage = (message) => {
|
|
75
|
+
const { type, payload } = message.data;
|
|
76
|
+
if (typeof payload === "object" && "clientId" in payload && payload.clientId !== client.id) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
switch (type) {
|
|
80
|
+
case "extraneous:send": {
|
|
81
|
+
client.send(payload.data);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case "extraneous:close": {
|
|
85
|
+
client.close(payload.code, payload.reason);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const abortController = new AbortController();
|
|
91
|
+
this.channel.addEventListener("message", handleExtraneousMessage, {
|
|
92
|
+
signal: abortController.signal
|
|
93
|
+
});
|
|
94
|
+
client.addEventListener("close", () => abortController.abort(), {
|
|
95
|
+
once: true
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
class WebSocketRemoteClientConnection {
|
|
100
|
+
constructor(id, url, channel) {
|
|
101
|
+
this.id = id;
|
|
102
|
+
this.url = url;
|
|
103
|
+
this.channel = channel;
|
|
104
|
+
}
|
|
105
|
+
send(data) {
|
|
106
|
+
this.channel.postMessage({
|
|
107
|
+
type: "extraneous:send",
|
|
108
|
+
payload: {
|
|
109
|
+
clientId: this.id,
|
|
110
|
+
data
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
close(code, reason) {
|
|
115
|
+
this.channel.postMessage({
|
|
116
|
+
type: "extraneous:close",
|
|
117
|
+
payload: {
|
|
118
|
+
clientId: this.id,
|
|
119
|
+
code,
|
|
120
|
+
reason
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export {
|
|
126
|
+
WebSocketClientManager,
|
|
127
|
+
WebSocketRemoteClientConnection
|
|
128
|
+
};
|
|
129
|
+
//# sourceMappingURL=WebSocketClientManager.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/WebSocketClientManager.ts"],"sourcesContent":["import type {\n WebSocketData,\n WebSocketClientConnection,\n WebSocketClientConnectionProtocol,\n} from '@mswjs/interceptors/WebSocket'\nimport { WebSocketClientStore } from './WebSocketClientStore'\nimport { WebSocketMemoryClientStore } from './WebSocketMemoryClientStore'\nimport { WebSocketIndexedDBClientStore } from './WebSocketIndexedDBClientStore'\n\nexport type WebSocketBroadcastChannelMessage =\n | {\n type: 'extraneous:send'\n payload: {\n clientId: string\n data: WebSocketData\n }\n }\n | {\n type: 'extraneous:close'\n payload: {\n clientId: string\n code?: number\n reason?: string\n }\n }\n\n/**\n * A manager responsible for accumulating WebSocket client\n * connections across different browser runtimes.\n */\nexport class WebSocketClientManager {\n private store: WebSocketClientStore\n private runtimeClients: Map<string, WebSocketClientConnectionProtocol>\n private allClients: Set<WebSocketClientConnectionProtocol>\n\n constructor(private channel: BroadcastChannel) {\n // Store the clients in the IndexedDB in the browser,\n // otherwise, store the clients in memory.\n this.store =\n typeof indexedDB !== 'undefined'\n ? new WebSocketIndexedDBClientStore()\n : new WebSocketMemoryClientStore()\n\n this.runtimeClients = new Map()\n this.allClients = new Set()\n\n this.channel.addEventListener('message', (message) => {\n if (message.data?.type === 'db:update') {\n this.flushDatabaseToMemory()\n }\n })\n\n if (typeof window !== 'undefined') {\n window.addEventListener('message', async (message) => {\n if (message.data?.type === 'msw/worker:stop') {\n await this.removeRuntimeClients()\n }\n })\n }\n }\n\n private async flushDatabaseToMemory() {\n const storedClients = await this.store.getAll()\n\n this.allClients = new Set(\n storedClients.map((client) => {\n const runtimeClient = this.runtimeClients.get(client.id)\n\n /**\n * @note For clients originating in this runtime, use their\n * direct references. No need to wrap them in a remote connection.\n */\n if (runtimeClient) {\n return runtimeClient\n }\n\n return new WebSocketRemoteClientConnection(\n client.id,\n new URL(client.url),\n this.channel,\n )\n }),\n )\n }\n\n private async removeRuntimeClients(): Promise<void> {\n await this.store.deleteMany(Array.from(this.runtimeClients.keys()))\n this.runtimeClients.clear()\n await this.flushDatabaseToMemory()\n this.notifyOthersAboutDatabaseUpdate()\n }\n\n /**\n * All active WebSocket client connections.\n */\n get clients(): Set<WebSocketClientConnectionProtocol> {\n return this.allClients\n }\n\n /**\n * Notify other runtimes about the database update\n * using the shared `BroadcastChannel` instance.\n */\n private notifyOthersAboutDatabaseUpdate(): void {\n this.channel.postMessage({ type: 'db:update' })\n }\n\n private async addClient(client: WebSocketClientConnection): Promise<void> {\n await this.store.add(client)\n // Sync the in-memory clients in this runtime with the\n // updated database. This pulls in all the stored clients.\n await this.flushDatabaseToMemory()\n this.notifyOthersAboutDatabaseUpdate()\n }\n\n /**\n * Adds the given `WebSocket` client connection to the set\n * of all connections. The given connection is always the complete\n * connection object because `addConnection()` is called only\n * for the opened connections in the same runtime.\n */\n public async addConnection(client: WebSocketClientConnection): Promise<void> {\n // Store this client in the map of clients created in this runtime.\n // This way, the manager can distinguish between this runtime clients\n // and extraneous runtime clients when synchronizing clients storage.\n this.runtimeClients.set(client.id, client)\n\n // Add the new client to the storage.\n await this.addClient(client)\n\n // Handle the incoming BroadcastChannel messages from other runtimes\n // that attempt to control this runtime (via a remote connection wrapper).\n // E.g. another runtime calling `client.send()` for the client in this runtime.\n const handleExtraneousMessage = (\n message: MessageEvent<WebSocketBroadcastChannelMessage>,\n ) => {\n const { type, payload } = message.data\n\n // Ignore broadcasted messages for other clients.\n if (\n typeof payload === 'object' &&\n 'clientId' in payload &&\n payload.clientId !== client.id\n ) {\n return\n }\n\n switch (type) {\n case 'extraneous:send': {\n client.send(payload.data)\n break\n }\n\n case 'extraneous:close': {\n client.close(payload.code, payload.reason)\n break\n }\n }\n }\n\n const abortController = new AbortController()\n\n this.channel.addEventListener('message', handleExtraneousMessage, {\n signal: abortController.signal,\n })\n\n // Once closed, this connection cannot be operated on.\n // This must include the extraneous runtimes as well.\n client.addEventListener('close', () => abortController.abort(), {\n once: true,\n })\n }\n}\n\n/**\n * A wrapper class to operate with WebSocket client connections\n * from other runtimes. This class maintains 1-1 public API\n * compatibility to the `WebSocketClientConnection` but relies\n * on the given `BroadcastChannel` to communicate instructions\n * with the client connections from other runtimes.\n */\nexport class WebSocketRemoteClientConnection\n implements WebSocketClientConnectionProtocol\n{\n constructor(\n public readonly id: string,\n public readonly url: URL,\n private channel: BroadcastChannel,\n ) {}\n\n send(data: WebSocketData): void {\n this.channel.postMessage({\n type: 'extraneous:send',\n payload: {\n clientId: this.id,\n data,\n },\n } as WebSocketBroadcastChannelMessage)\n }\n\n close(code?: number | undefined, reason?: string | undefined): void {\n this.channel.postMessage({\n type: 'extraneous:close',\n payload: {\n clientId: this.id,\n code,\n reason,\n },\n } as WebSocketBroadcastChannelMessage)\n }\n}\n"],"mappings":"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,a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js/interceptors/WebSocket';
|
|
2
|
+
|
|
3
|
+
interface SerializedWebSocketClient {
|
|
4
|
+
id: string;
|
|
5
|
+
url: string;
|
|
6
|
+
}
|
|
7
|
+
declare abstract class WebSocketClientStore {
|
|
8
|
+
abstract add(client: WebSocketClientConnectionProtocol): Promise<void>;
|
|
9
|
+
abstract getAll(): Promise<Array<SerializedWebSocketClient>>;
|
|
10
|
+
abstract deleteMany(clientIds: Array<string>): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { type SerializedWebSocketClient, WebSocketClientStore };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket';
|
|
2
|
+
|
|
3
|
+
interface SerializedWebSocketClient {
|
|
4
|
+
id: string;
|
|
5
|
+
url: string;
|
|
6
|
+
}
|
|
7
|
+
declare abstract class WebSocketClientStore {
|
|
8
|
+
abstract add(client: WebSocketClientConnectionProtocol): Promise<void>;
|
|
9
|
+
abstract getAll(): Promise<Array<SerializedWebSocketClient>>;
|
|
10
|
+
abstract deleteMany(clientIds: Array<string>): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { type SerializedWebSocketClient, WebSocketClientStore };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var WebSocketClientStore_exports = {};
|
|
20
|
+
__export(WebSocketClientStore_exports, {
|
|
21
|
+
WebSocketClientStore: () => WebSocketClientStore
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(WebSocketClientStore_exports);
|
|
24
|
+
class WebSocketClientStore {
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=WebSocketClientStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/WebSocketClientStore.ts"],"sourcesContent":["import type { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\n\nexport interface SerializedWebSocketClient {\n id: string\n url: string\n}\n\nexport abstract class WebSocketClientStore {\n public abstract add(client: WebSocketClientConnectionProtocol): Promise<void>\n\n public abstract getAll(): Promise<Array<SerializedWebSocketClient>>\n\n public abstract deleteMany(clientIds: Array<string>): Promise<void>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,MAAe,qBAAqB;AAM3C;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/WebSocketClientStore.ts"],"sourcesContent":["import type { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/WebSocket'\n\nexport interface SerializedWebSocketClient {\n id: string\n url: string\n}\n\nexport abstract class WebSocketClientStore {\n public abstract add(client: WebSocketClientConnectionProtocol): Promise<void>\n\n public abstract getAll(): Promise<Array<SerializedWebSocketClient>>\n\n public abstract deleteMany(clientIds: Array<string>): Promise<void>\n}\n"],"mappings":"AAOO,MAAe,qBAAqB;AAM3C;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket';
|
|
2
|
+
import { WebSocketClientStore, SerializedWebSocketClient } from './WebSocketClientStore.mjs';
|
|
3
|
+
import '@mswjs/interceptors/WebSocket';
|
|
4
|
+
|
|
5
|
+
declare class WebSocketIndexedDBClientStore implements WebSocketClientStore {
|
|
6
|
+
private db;
|
|
7
|
+
constructor();
|
|
8
|
+
add(client: WebSocketClientConnectionProtocol): Promise<void>;
|
|
9
|
+
getAll(): Promise<Array<SerializedWebSocketClient>>;
|
|
10
|
+
deleteMany(clientIds: Array<string>): Promise<void>;
|
|
11
|
+
private createDatabase;
|
|
12
|
+
private getStore;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { WebSocketIndexedDBClientStore };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket';
|
|
2
|
+
import { WebSocketClientStore, SerializedWebSocketClient } from './WebSocketClientStore.js';
|
|
3
|
+
import '@mswjs/interceptors/WebSocket';
|
|
4
|
+
|
|
5
|
+
declare class WebSocketIndexedDBClientStore implements WebSocketClientStore {
|
|
6
|
+
private db;
|
|
7
|
+
constructor();
|
|
8
|
+
add(client: WebSocketClientConnectionProtocol): Promise<void>;
|
|
9
|
+
getAll(): Promise<Array<SerializedWebSocketClient>>;
|
|
10
|
+
deleteMany(clientIds: Array<string>): Promise<void>;
|
|
11
|
+
private createDatabase;
|
|
12
|
+
private getStore;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { WebSocketIndexedDBClientStore };
|
|
@@ -0,0 +1,130 @@
|
|
|
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 WebSocketIndexedDBClientStore_exports = {};
|
|
20
|
+
__export(WebSocketIndexedDBClientStore_exports, {
|
|
21
|
+
WebSocketIndexedDBClientStore: () => WebSocketIndexedDBClientStore
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(WebSocketIndexedDBClientStore_exports);
|
|
24
|
+
var import_deferred_promise = require("@open-draft/deferred-promise");
|
|
25
|
+
const DB_NAME = "msw-websocket-clients";
|
|
26
|
+
const DB_STORE_NAME = "clients";
|
|
27
|
+
class WebSocketIndexedDBClientStore {
|
|
28
|
+
db;
|
|
29
|
+
constructor() {
|
|
30
|
+
this.db = this.createDatabase();
|
|
31
|
+
}
|
|
32
|
+
async add(client) {
|
|
33
|
+
const promise = new import_deferred_promise.DeferredPromise();
|
|
34
|
+
const store = await this.getStore();
|
|
35
|
+
const request = store.put({
|
|
36
|
+
id: client.id,
|
|
37
|
+
url: client.url.href
|
|
38
|
+
});
|
|
39
|
+
request.onsuccess = () => {
|
|
40
|
+
promise.resolve();
|
|
41
|
+
};
|
|
42
|
+
request.onerror = () => {
|
|
43
|
+
console.error(request.error);
|
|
44
|
+
promise.reject(
|
|
45
|
+
new Error(
|
|
46
|
+
`Failed to add WebSocket client "${client.id}". There is likely an additional output above.`
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
return promise;
|
|
51
|
+
}
|
|
52
|
+
async getAll() {
|
|
53
|
+
const promise = new import_deferred_promise.DeferredPromise();
|
|
54
|
+
const store = await this.getStore();
|
|
55
|
+
const request = store.getAll();
|
|
56
|
+
request.onsuccess = () => {
|
|
57
|
+
promise.resolve(request.result);
|
|
58
|
+
};
|
|
59
|
+
request.onerror = () => {
|
|
60
|
+
console.log(request.error);
|
|
61
|
+
promise.reject(
|
|
62
|
+
new Error(
|
|
63
|
+
`Failed to get all WebSocket clients. There is likely an additional output above.`
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
return promise;
|
|
68
|
+
}
|
|
69
|
+
async deleteMany(clientIds) {
|
|
70
|
+
const promise = new import_deferred_promise.DeferredPromise();
|
|
71
|
+
const store = await this.getStore();
|
|
72
|
+
for (const clientId of clientIds) {
|
|
73
|
+
store.delete(clientId);
|
|
74
|
+
}
|
|
75
|
+
store.transaction.oncomplete = () => {
|
|
76
|
+
promise.resolve();
|
|
77
|
+
};
|
|
78
|
+
store.transaction.onerror = () => {
|
|
79
|
+
console.error(store.transaction.error);
|
|
80
|
+
promise.reject(
|
|
81
|
+
new Error(
|
|
82
|
+
`Failed to delete WebSocket clients [${clientIds.join(", ")}]. There is likely an additional output above.`
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
return promise;
|
|
87
|
+
}
|
|
88
|
+
async createDatabase() {
|
|
89
|
+
const promise = new import_deferred_promise.DeferredPromise();
|
|
90
|
+
const request = indexedDB.open(DB_NAME, 1);
|
|
91
|
+
request.onsuccess = ({ currentTarget }) => {
|
|
92
|
+
const db = Reflect.get(currentTarget, "result");
|
|
93
|
+
if (db.objectStoreNames.contains(DB_STORE_NAME)) {
|
|
94
|
+
return promise.resolve(db);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
request.onupgradeneeded = async ({ currentTarget }) => {
|
|
98
|
+
const db = Reflect.get(currentTarget, "result");
|
|
99
|
+
if (db.objectStoreNames.contains(DB_STORE_NAME)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const store = db.createObjectStore(DB_STORE_NAME, { keyPath: "id" });
|
|
103
|
+
store.transaction.oncomplete = () => {
|
|
104
|
+
promise.resolve(db);
|
|
105
|
+
};
|
|
106
|
+
store.transaction.onerror = () => {
|
|
107
|
+
console.error(store.transaction.error);
|
|
108
|
+
promise.reject(
|
|
109
|
+
new Error(
|
|
110
|
+
"Failed to create WebSocket client store. There is likely an additional output above."
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
request.onerror = () => {
|
|
116
|
+
console.error(request.error);
|
|
117
|
+
promise.reject(
|
|
118
|
+
new Error(
|
|
119
|
+
"Failed to open an IndexedDB database. There is likely an additional output above."
|
|
120
|
+
)
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
return promise;
|
|
124
|
+
}
|
|
125
|
+
async getStore() {
|
|
126
|
+
const db = await this.db;
|
|
127
|
+
return db.transaction(DB_STORE_NAME, "readwrite").objectStore(DB_STORE_NAME);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=WebSocketIndexedDBClientStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/WebSocketIndexedDBClientStore.ts"],"sourcesContent":["import { DeferredPromise } from '@open-draft/deferred-promise'\nimport { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport {\n type SerializedWebSocketClient,\n WebSocketClientStore,\n} from './WebSocketClientStore'\n\nconst DB_NAME = 'msw-websocket-clients'\nconst DB_STORE_NAME = 'clients'\n\nexport class WebSocketIndexedDBClientStore implements WebSocketClientStore {\n private db: Promise<IDBDatabase>\n\n constructor() {\n this.db = this.createDatabase()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n\n /**\n * @note Use `.put()` instead of `.add()` to allow setting clients\n * that already exist in the database. This can happen if a single page\n * has multiple event handlers. Each handler will receive the \"connection\"\n * event in parallel, and try to set that WebSocket client in the database.\n */\n const request = store.put({\n id: client.id,\n url: client.url.href,\n } satisfies SerializedWebSocketClient)\n\n request.onsuccess = () => {\n promise.resolve()\n }\n request.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(request.error)\n promise.reject(\n new Error(\n `Failed to add WebSocket client \"${client.id}\". There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n public async getAll(): Promise<Array<SerializedWebSocketClient>> {\n const promise = new DeferredPromise<Array<SerializedWebSocketClient>>()\n const store = await this.getStore()\n const request = store.getAll() as IDBRequest<\n Array<SerializedWebSocketClient>\n >\n\n request.onsuccess = () => {\n promise.resolve(request.result)\n }\n request.onerror = () => {\n // eslint-disable-next-line no-console\n console.log(request.error)\n promise.reject(\n new Error(\n `Failed to get all WebSocket clients. There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n\n for (const clientId of clientIds) {\n store.delete(clientId)\n }\n\n store.transaction.oncomplete = () => {\n promise.resolve()\n }\n store.transaction.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(store.transaction.error)\n promise.reject(\n new Error(\n `Failed to delete WebSocket clients [${clientIds.join(', ')}]. There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n private async createDatabase(): Promise<IDBDatabase> {\n const promise = new DeferredPromise<IDBDatabase>()\n const request = indexedDB.open(DB_NAME, 1)\n\n request.onsuccess = ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return promise.resolve(db)\n }\n }\n\n request.onupgradeneeded = async ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return\n }\n\n const store = db.createObjectStore(DB_STORE_NAME, { keyPath: 'id' })\n store.transaction.oncomplete = () => {\n promise.resolve(db)\n }\n store.transaction.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(store.transaction.error)\n promise.reject(\n new Error(\n 'Failed to create WebSocket client store. There is likely an additional output above.',\n ),\n )\n }\n }\n request.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(request.error)\n promise.reject(\n new Error(\n 'Failed to open an IndexedDB database. There is likely an additional output above.',\n ),\n )\n }\n\n return promise\n }\n\n private async getStore(): Promise<IDBObjectStore> {\n const db = await this.db\n return db.transaction(DB_STORE_NAME, 'readwrite').objectStore(DB_STORE_NAME)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAgC;AAOhC,MAAM,UAAU;AAChB,MAAM,gBAAgB;AAEf,MAAM,8BAA8D;AAAA,EACjE;AAAA,EAER,cAAc;AACZ,SAAK,KAAK,KAAK,eAAe;AAAA,EAChC;AAAA,EAEA,MAAa,IAAI,QAA0D;AACzE,UAAM,UAAU,IAAI,wCAAsB;AAC1C,UAAM,QAAQ,MAAM,KAAK,SAAS;AAQlC,UAAM,UAAU,MAAM,IAAI;AAAA,MACxB,IAAI,OAAO;AAAA,MACX,KAAK,OAAO,IAAI;AAAA,IAClB,CAAqC;AAErC,YAAQ,YAAY,MAAM;AACxB,cAAQ,QAAQ;AAAA,IAClB;AACA,YAAQ,UAAU,MAAM;AAEtB,cAAQ,MAAM,QAAQ,KAAK;AAC3B,cAAQ;AAAA,QACN,IAAI;AAAA,UACF,mCAAmC,OAAO,EAAE;AAAA,QAC9C;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAa,SAAoD;AAC/D,UAAM,UAAU,IAAI,wC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,CAAC;AACnE,YAAM,YAAY,aAAa,MAAM;AACnC,gBAAQ,QAAQ,EAAE;AAAA,MACpB;AACA,YAAM,YAAY,UAAU,MAAM;AAEhC,gBAAQ,MAAM,MAAM,YAAY,KAAK;AACrC,gBAAQ;AAAA,UACN,IAAI;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,YAAQ,UAAU,MAAM;AAEtB,cAAQ,MAAM,QAAQ,KAAK;AAC3B,cAAQ;AAAA,QACN,IAAI;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,WAAoC;AAChD,UAAM,KAAK,MAAM,KAAK;AACtB,WAAO,GAAG,YAAY,eAAe,WAAW,EAAE,YAAY,aAAa;AAAA,EAC7E;AACF;","names":[]}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { DeferredPromise } from "@open-draft/deferred-promise";
|
|
2
|
+
const DB_NAME = "msw-websocket-clients";
|
|
3
|
+
const DB_STORE_NAME = "clients";
|
|
4
|
+
class WebSocketIndexedDBClientStore {
|
|
5
|
+
db;
|
|
6
|
+
constructor() {
|
|
7
|
+
this.db = this.createDatabase();
|
|
8
|
+
}
|
|
9
|
+
async add(client) {
|
|
10
|
+
const promise = new DeferredPromise();
|
|
11
|
+
const store = await this.getStore();
|
|
12
|
+
const request = store.put({
|
|
13
|
+
id: client.id,
|
|
14
|
+
url: client.url.href
|
|
15
|
+
});
|
|
16
|
+
request.onsuccess = () => {
|
|
17
|
+
promise.resolve();
|
|
18
|
+
};
|
|
19
|
+
request.onerror = () => {
|
|
20
|
+
console.error(request.error);
|
|
21
|
+
promise.reject(
|
|
22
|
+
new Error(
|
|
23
|
+
`Failed to add WebSocket client "${client.id}". There is likely an additional output above.`
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
return promise;
|
|
28
|
+
}
|
|
29
|
+
async getAll() {
|
|
30
|
+
const promise = new DeferredPromise();
|
|
31
|
+
const store = await this.getStore();
|
|
32
|
+
const request = store.getAll();
|
|
33
|
+
request.onsuccess = () => {
|
|
34
|
+
promise.resolve(request.result);
|
|
35
|
+
};
|
|
36
|
+
request.onerror = () => {
|
|
37
|
+
console.log(request.error);
|
|
38
|
+
promise.reject(
|
|
39
|
+
new Error(
|
|
40
|
+
`Failed to get all WebSocket clients. There is likely an additional output above.`
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
return promise;
|
|
45
|
+
}
|
|
46
|
+
async deleteMany(clientIds) {
|
|
47
|
+
const promise = new DeferredPromise();
|
|
48
|
+
const store = await this.getStore();
|
|
49
|
+
for (const clientId of clientIds) {
|
|
50
|
+
store.delete(clientId);
|
|
51
|
+
}
|
|
52
|
+
store.transaction.oncomplete = () => {
|
|
53
|
+
promise.resolve();
|
|
54
|
+
};
|
|
55
|
+
store.transaction.onerror = () => {
|
|
56
|
+
console.error(store.transaction.error);
|
|
57
|
+
promise.reject(
|
|
58
|
+
new Error(
|
|
59
|
+
`Failed to delete WebSocket clients [${clientIds.join(", ")}]. There is likely an additional output above.`
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
return promise;
|
|
64
|
+
}
|
|
65
|
+
async createDatabase() {
|
|
66
|
+
const promise = new DeferredPromise();
|
|
67
|
+
const request = indexedDB.open(DB_NAME, 1);
|
|
68
|
+
request.onsuccess = ({ currentTarget }) => {
|
|
69
|
+
const db = Reflect.get(currentTarget, "result");
|
|
70
|
+
if (db.objectStoreNames.contains(DB_STORE_NAME)) {
|
|
71
|
+
return promise.resolve(db);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
request.onupgradeneeded = async ({ currentTarget }) => {
|
|
75
|
+
const db = Reflect.get(currentTarget, "result");
|
|
76
|
+
if (db.objectStoreNames.contains(DB_STORE_NAME)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const store = db.createObjectStore(DB_STORE_NAME, { keyPath: "id" });
|
|
80
|
+
store.transaction.oncomplete = () => {
|
|
81
|
+
promise.resolve(db);
|
|
82
|
+
};
|
|
83
|
+
store.transaction.onerror = () => {
|
|
84
|
+
console.error(store.transaction.error);
|
|
85
|
+
promise.reject(
|
|
86
|
+
new Error(
|
|
87
|
+
"Failed to create WebSocket client store. There is likely an additional output above."
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
request.onerror = () => {
|
|
93
|
+
console.error(request.error);
|
|
94
|
+
promise.reject(
|
|
95
|
+
new Error(
|
|
96
|
+
"Failed to open an IndexedDB database. There is likely an additional output above."
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
return promise;
|
|
101
|
+
}
|
|
102
|
+
async getStore() {
|
|
103
|
+
const db = await this.db;
|
|
104
|
+
return db.transaction(DB_STORE_NAME, "readwrite").objectStore(DB_STORE_NAME);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export {
|
|
108
|
+
WebSocketIndexedDBClientStore
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=WebSocketIndexedDBClientStore.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/WebSocketIndexedDBClientStore.ts"],"sourcesContent":["import { DeferredPromise } from '@open-draft/deferred-promise'\nimport { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport {\n type SerializedWebSocketClient,\n WebSocketClientStore,\n} from './WebSocketClientStore'\n\nconst DB_NAME = 'msw-websocket-clients'\nconst DB_STORE_NAME = 'clients'\n\nexport class WebSocketIndexedDBClientStore implements WebSocketClientStore {\n private db: Promise<IDBDatabase>\n\n constructor() {\n this.db = this.createDatabase()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n\n /**\n * @note Use `.put()` instead of `.add()` to allow setting clients\n * that already exist in the database. This can happen if a single page\n * has multiple event handlers. Each handler will receive the \"connection\"\n * event in parallel, and try to set that WebSocket client in the database.\n */\n const request = store.put({\n id: client.id,\n url: client.url.href,\n } satisfies SerializedWebSocketClient)\n\n request.onsuccess = () => {\n promise.resolve()\n }\n request.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(request.error)\n promise.reject(\n new Error(\n `Failed to add WebSocket client \"${client.id}\". There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n public async getAll(): Promise<Array<SerializedWebSocketClient>> {\n const promise = new DeferredPromise<Array<SerializedWebSocketClient>>()\n const store = await this.getStore()\n const request = store.getAll() as IDBRequest<\n Array<SerializedWebSocketClient>\n >\n\n request.onsuccess = () => {\n promise.resolve(request.result)\n }\n request.onerror = () => {\n // eslint-disable-next-line no-console\n console.log(request.error)\n promise.reject(\n new Error(\n `Failed to get all WebSocket clients. There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n const promise = new DeferredPromise<void>()\n const store = await this.getStore()\n\n for (const clientId of clientIds) {\n store.delete(clientId)\n }\n\n store.transaction.oncomplete = () => {\n promise.resolve()\n }\n store.transaction.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(store.transaction.error)\n promise.reject(\n new Error(\n `Failed to delete WebSocket clients [${clientIds.join(', ')}]. There is likely an additional output above.`,\n ),\n )\n }\n\n return promise\n }\n\n private async createDatabase(): Promise<IDBDatabase> {\n const promise = new DeferredPromise<IDBDatabase>()\n const request = indexedDB.open(DB_NAME, 1)\n\n request.onsuccess = ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return promise.resolve(db)\n }\n }\n\n request.onupgradeneeded = async ({ currentTarget }) => {\n const db = Reflect.get(currentTarget!, 'result') as IDBDatabase\n if (db.objectStoreNames.contains(DB_STORE_NAME)) {\n return\n }\n\n const store = db.createObjectStore(DB_STORE_NAME, { keyPath: 'id' })\n store.transaction.oncomplete = () => {\n promise.resolve(db)\n }\n store.transaction.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(store.transaction.error)\n promise.reject(\n new Error(\n 'Failed to create WebSocket client store. There is likely an additional output above.',\n ),\n )\n }\n }\n request.onerror = () => {\n // eslint-disable-next-line no-console\n console.error(request.error)\n promise.reject(\n new Error(\n 'Failed to open an IndexedDB database. There is likely an additional output above.',\n ),\n )\n }\n\n return promise\n }\n\n private async getStore(): Promise<IDBObjectStore> {\n const db = await this.db\n return db.transaction(DB_STORE_NAME, 'readwrite').objectStore(DB_STORE_NAME)\n }\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAOhC,MAAM,UAAU;AAChB,MAAM,gBAAgB;AAEf,MAAM,8BAA8D;AAAA,EACjE;AAAA,EAER,cAAc;AACZ,SAAK,KAAK,KAAK,eAAe;AAAA,EAChC;AAAA,EAEA,MAAa,IAAI,QAA0D;AACzE,UAAM,UAAU,IAAI,gBAAsB;AAC1C,UAAM,QAAQ,MAAM,KAAK,SAAS;AAQlC,UAAM,UAAU,MAAM,IAAI;AAAA,MACxB,IAAI,OAAO;AAAA,MACX,KAAK,OAAO,IAAI;AAAA,IAClB,CAAqC;AAErC,YAAQ,YAAY,MAAM;AACxB,cAAQ,QAAQ;AAAA,IAClB;AACA,YAAQ,UAAU,MAAM;AAEtB,cAAQ,MAAM,QAAQ,KAAK;AAC3B,cAAQ;AAAA,QACN,IAAI;AAAA,UACF,mCAAmC,OAAO,EAAE;AAAA,QAC9C;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAa,SAAoD;AAC/D,UAAM,UAAU,IAAI,gBAAkD;AACtE,UAAM,QAAQ,MAAM,KAAK,SAAS;AAClC,UAAM,UAAU,MAAM,OAAO;AAI7B,YAAQ,YAAY,MAAM;AACxB,cAAQ,QAAQ,QAAQ,MAAM;AAAA,IAChC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;AACrC,gBAAQ;AAAA,UACN,IAAI;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,YAAQ,UAAU,MAAM;AAEtB,cAAQ,MAAM,QAAQ,KAAK;AAC3B,cAAQ;AAAA,QACN,IAAI;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,WAAoC;AAChD,UAAM,KAAK,MAAM,KAAK;AACtB,WAAO,GAAG,YAAY,eAAe,WAAW,EAAE,YAAY,aAAa;AAAA,EAC7E;AACF;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket';
|
|
2
|
+
import { WebSocketClientStore, SerializedWebSocketClient } from './WebSocketClientStore.mjs';
|
|
3
|
+
import '@mswjs/interceptors/WebSocket';
|
|
4
|
+
|
|
5
|
+
declare class WebSocketMemoryClientStore implements WebSocketClientStore {
|
|
6
|
+
private store;
|
|
7
|
+
constructor();
|
|
8
|
+
add(client: WebSocketClientConnectionProtocol): Promise<void>;
|
|
9
|
+
getAll(): Promise<Array<SerializedWebSocketClient>>;
|
|
10
|
+
deleteMany(clientIds: Array<string>): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { WebSocketMemoryClientStore };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket';
|
|
2
|
+
import { WebSocketClientStore, SerializedWebSocketClient } from './WebSocketClientStore.js';
|
|
3
|
+
import '@mswjs/interceptors/WebSocket';
|
|
4
|
+
|
|
5
|
+
declare class WebSocketMemoryClientStore implements WebSocketClientStore {
|
|
6
|
+
private store;
|
|
7
|
+
constructor();
|
|
8
|
+
add(client: WebSocketClientConnectionProtocol): Promise<void>;
|
|
9
|
+
getAll(): Promise<Array<SerializedWebSocketClient>>;
|
|
10
|
+
deleteMany(clientIds: Array<string>): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { WebSocketMemoryClientStore };
|
|
@@ -0,0 +1,41 @@
|
|
|
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 WebSocketMemoryClientStore_exports = {};
|
|
20
|
+
__export(WebSocketMemoryClientStore_exports, {
|
|
21
|
+
WebSocketMemoryClientStore: () => WebSocketMemoryClientStore
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(WebSocketMemoryClientStore_exports);
|
|
24
|
+
class WebSocketMemoryClientStore {
|
|
25
|
+
store;
|
|
26
|
+
constructor() {
|
|
27
|
+
this.store = /* @__PURE__ */ new Map();
|
|
28
|
+
}
|
|
29
|
+
async add(client) {
|
|
30
|
+
this.store.set(client.id, { id: client.id, url: client.url.href });
|
|
31
|
+
}
|
|
32
|
+
getAll() {
|
|
33
|
+
return Promise.resolve(Array.from(this.store.values()));
|
|
34
|
+
}
|
|
35
|
+
async deleteMany(clientIds) {
|
|
36
|
+
for (const clientId of clientIds) {
|
|
37
|
+
this.store.delete(clientId);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=WebSocketMemoryClientStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/WebSocketMemoryClientStore.ts"],"sourcesContent":["import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport {\n SerializedWebSocketClient,\n WebSocketClientStore,\n} from './WebSocketClientStore'\n\nexport class WebSocketMemoryClientStore implements WebSocketClientStore {\n private store: Map<string, SerializedWebSocketClient>\n\n constructor() {\n this.store = new Map()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n this.store.set(client.id, { id: client.id, url: client.url.href })\n }\n\n public getAll(): Promise<Array<SerializedWebSocketClient>> {\n return Promise.resolve(Array.from(this.store.values()))\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n for (const clientId of clientIds) {\n this.store.delete(clientId)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,MAAM,2BAA2D;AAAA,EAC9D;AAAA,EAER,cAAc;AACZ,SAAK,QAAQ,oBAAI,IAAI;AAAA,EACvB;AAAA,EAEA,MAAa,IAAI,QAA0D;AACzE,SAAK,MAAM,IAAI,OAAO,IAAI,EAAE,IAAI,OAAO,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC;AAAA,EACnE;AAAA,EAEO,SAAoD;AACzD,WAAO,QAAQ,QAAQ,MAAM,KAAK,KAAK,MAAM,OAAO,CAAC,CAAC;AAAA,EACxD;AAAA,EAEA,MAAa,WAAW,WAAyC;AAC/D,eAAW,YAAY,WAAW;AAChC,WAAK,MAAM,OAAO,QAAQ;AAAA,IAC5B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class WebSocketMemoryClientStore {
|
|
2
|
+
store;
|
|
3
|
+
constructor() {
|
|
4
|
+
this.store = /* @__PURE__ */ new Map();
|
|
5
|
+
}
|
|
6
|
+
async add(client) {
|
|
7
|
+
this.store.set(client.id, { id: client.id, url: client.url.href });
|
|
8
|
+
}
|
|
9
|
+
getAll() {
|
|
10
|
+
return Promise.resolve(Array.from(this.store.values()));
|
|
11
|
+
}
|
|
12
|
+
async deleteMany(clientIds) {
|
|
13
|
+
for (const clientId of clientIds) {
|
|
14
|
+
this.store.delete(clientId);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
WebSocketMemoryClientStore
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=WebSocketMemoryClientStore.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/WebSocketMemoryClientStore.ts"],"sourcesContent":["import { WebSocketClientConnectionProtocol } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport {\n SerializedWebSocketClient,\n WebSocketClientStore,\n} from './WebSocketClientStore'\n\nexport class WebSocketMemoryClientStore implements WebSocketClientStore {\n private store: Map<string, SerializedWebSocketClient>\n\n constructor() {\n this.store = new Map()\n }\n\n public async add(client: WebSocketClientConnectionProtocol): Promise<void> {\n this.store.set(client.id, { id: client.id, url: client.url.href })\n }\n\n public getAll(): Promise<Array<SerializedWebSocketClient>> {\n return Promise.resolve(Array.from(this.store.values()))\n }\n\n public async deleteMany(clientIds: Array<string>): Promise<void> {\n for (const clientId of clientIds) {\n this.store.delete(clientId)\n }\n }\n}\n"],"mappings":"AAMO,MAAM,2BAA2D;AAAA,EAC9D;AAAA,EAER,cAAc;AACZ,SAAK,QAAQ,oBAAI,IAAI;AAAA,EACvB;AAAA,EAEA,MAAa,IAAI,QAA0D;AACzE,SAAK,MAAM,IAAI,OAAO,IAAI,EAAE,IAAI,OAAO,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC;AAAA,EACnE;AAAA,EAEO,SAAoD;AACzD,WAAO,QAAQ,QAAQ,MAAM,KAAK,KAAK,MAAM,OAAO,CAAC,CAAC;AAAA,EACxD;AAAA,EAEA,MAAa,WAAW,WAAyC;AAC/D,eAAW,YAAY,WAAW;AAChC,WAAK,MAAM,OAAO,QAAQ;AAAA,IAC5B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket';
|
|
2
|
+
import { R as RequestHandler } from '../HttpResponse-63H9vVoL.mjs';
|
|
3
|
+
import { WebSocketHandler } from '../handlers/WebSocketHandler.mjs';
|
|
4
|
+
import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.mjs';
|
|
5
|
+
import '../utils/internal/isIterable.mjs';
|
|
6
|
+
import '../typeUtils.mjs';
|
|
7
|
+
import 'strict-event-emitter';
|
|
8
|
+
import '@mswjs/interceptors/WebSocket';
|
|
9
|
+
import '../utils/matching/matchRequestUrl.mjs';
|
|
10
|
+
|
|
11
|
+
interface HandleWebSocketEventOptions {
|
|
12
|
+
getUnhandledRequestStrategy: () => UnhandledRequestStrategy;
|
|
13
|
+
getHandlers: () => Array<RequestHandler | WebSocketHandler>;
|
|
14
|
+
onMockedConnection: (connection: WebSocketConnectionData) => void;
|
|
15
|
+
onPassthroughConnection: (onnection: WebSocketConnectionData) => void;
|
|
16
|
+
}
|
|
17
|
+
declare function handleWebSocketEvent(options: HandleWebSocketEventOptions): void;
|
|
18
|
+
|
|
19
|
+
export { handleWebSocketEvent };
|