msw 2.2.13 → 2.3.0-ws.rc-2
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/cli/init.js +0 -0
- package/config/scripts/postinstall.js +0 -0
- package/lib/browser/index.d.mts +7 -6
- package/lib/browser/index.d.ts +7 -6
- package/lib/browser/index.js +26 -7
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +26 -7
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-bom2Dn82.d.ts → GraphQLHandler-3gvpA65n.d.ts} +1 -1
- package/lib/core/{GraphQLHandler-yJ_I6j54.d.mts → GraphQLHandler-4DPdxG0R.d.mts} +1 -1
- package/lib/core/{HttpResponse-vQNlixkj.d.ts → HttpResponse-aJY-D0oG.d.ts} +2 -2
- package/lib/core/{HttpResponse-3-NyzyF7.d.mts → HttpResponse-xuSipbNt.d.mts} +2 -2
- 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/WebSocketHandler.d.mts +32 -0
- package/lib/core/handlers/WebSocketHandler.d.ts +32 -0
- package/lib/core/handlers/WebSocketHandler.js +62 -0
- package/lib/core/handlers/WebSocketHandler.js.map +1 -0
- package/lib/core/handlers/WebSocketHandler.mjs +44 -0
- package/lib/core/handlers/WebSocketHandler.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 +4 -0
- package/lib/core/utils/executeHandlers.js.map +1 -1
- package/lib/core/utils/executeHandlers.mjs +6 -0
- 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/handleWebSocketEvent.d.mts +16 -0
- package/lib/core/utils/handleWebSocketEvent.d.ts +16 -0
- package/lib/core/utils/handleWebSocketEvent.js +59 -0
- package/lib/core/utils/handleWebSocketEvent.js.map +1 -0
- package/lib/core/utils/handleWebSocketEvent.mjs +39 -0
- package/lib/core/utils/handleWebSocketEvent.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 +64 -0
- package/lib/core/ws/WebSocketClientManager.d.ts +64 -0
- package/lib/core/ws/WebSocketClientManager.js +123 -0
- package/lib/core/ws/WebSocketClientManager.js.map +1 -0
- package/lib/core/ws/WebSocketClientManager.mjs +103 -0
- package/lib/core/ws/WebSocketClientManager.mjs.map +1 -0
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +34 -0
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +34 -0
- package/lib/core/ws/utils/attachWebSocketLogger.js +211 -0
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -0
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +191 -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/ws.d.mts +44 -0
- package/lib/core/ws/ws.d.ts +44 -0
- package/lib/core/ws/ws.js +82 -0
- package/lib/core/ws/ws.js.map +1 -0
- package/lib/core/ws/ws.mjs +65 -0
- package/lib/core/ws/ws.mjs.map +1 -0
- package/lib/iife/index.js +967 -11
- 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 +13 -0
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +13 -0
- 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 +13 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +13 -0
- package/lib/node/index.mjs.map +1 -1
- package/package.json +26 -21
- package/src/browser/setupWorker/glossary.ts +10 -10
- package/src/browser/setupWorker/setupWorker.ts +34 -3
- package/src/core/SetupApi.ts +28 -20
- package/src/core/handlers/WebSocketHandler.ts +71 -0
- package/src/core/index.ts +8 -1
- package/src/core/utils/executeHandlers.ts +6 -2
- package/src/core/utils/handleRequest.ts +1 -2
- package/src/core/utils/handleWebSocketEvent.ts +59 -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 +159 -0
- package/src/core/ws/WebSocketClientManager.ts +170 -0
- package/src/core/ws/utils/attachWebSocketLogger.ts +262 -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/ws.test.ts +23 -0
- package/src/core/ws/ws.ts +108 -0
- package/src/node/SetupServerApi.ts +8 -7
- package/src/node/SetupServerCommonApi.ts +14 -1
- package/src/node/glossary.ts +5 -7
- package/src/node/setupServer.ts +2 -1
package/lib/iife/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var MockServiceWorker = (() => {
|
|
|
32
32
|
SET_TIMEOUT_MAX_ALLOWED_INT: () => SET_TIMEOUT_MAX_ALLOWED_INT,
|
|
33
33
|
SetupApi: () => SetupApi,
|
|
34
34
|
SetupWorkerApi: () => SetupWorkerApi,
|
|
35
|
+
WebSocketHandler: () => WebSocketHandler,
|
|
35
36
|
bypass: () => bypass,
|
|
36
37
|
cleanUrl: () => cleanUrl,
|
|
37
38
|
delay: () => delay,
|
|
@@ -41,7 +42,8 @@ var MockServiceWorker = (() => {
|
|
|
41
42
|
http: () => http,
|
|
42
43
|
matchRequestUrl: () => matchRequestUrl,
|
|
43
44
|
passthrough: () => passthrough,
|
|
44
|
-
setupWorker: () => setupWorker
|
|
45
|
+
setupWorker: () => setupWorker,
|
|
46
|
+
ws: () => ws
|
|
45
47
|
});
|
|
46
48
|
|
|
47
49
|
// node_modules/.pnpm/outvariant@1.4.2/node_modules/outvariant/lib/index.mjs
|
|
@@ -402,7 +404,9 @@ var MockServiceWorker = (() => {
|
|
|
402
404
|
}
|
|
403
405
|
restoreHandlers() {
|
|
404
406
|
this.handlersController.currentHandlers().forEach((handler) => {
|
|
405
|
-
|
|
407
|
+
if ("isUsed" in handler) {
|
|
408
|
+
handler.isUsed = false;
|
|
409
|
+
}
|
|
406
410
|
});
|
|
407
411
|
}
|
|
408
412
|
resetHandlers(...nextHandlers) {
|
|
@@ -623,9 +627,13 @@ var MockServiceWorker = (() => {
|
|
|
623
627
|
}
|
|
624
628
|
|
|
625
629
|
// src/core/utils/logging/getTimestamp.ts
|
|
626
|
-
function getTimestamp() {
|
|
630
|
+
function getTimestamp(options) {
|
|
627
631
|
const now = /* @__PURE__ */ new Date();
|
|
628
|
-
|
|
632
|
+
const timestamp = `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}:${now.getSeconds().toString().padStart(2, "0")}`;
|
|
633
|
+
if (options?.milliseconds) {
|
|
634
|
+
return `${timestamp}.${now.getMilliseconds().toString().padStart(3, "0")}`;
|
|
635
|
+
}
|
|
636
|
+
return timestamp;
|
|
629
637
|
}
|
|
630
638
|
|
|
631
639
|
// src/core/utils/logging/serializeRequest.ts
|
|
@@ -1121,7 +1129,7 @@ var MockServiceWorker = (() => {
|
|
|
1121
1129
|
return stringToRegexp(path, keys, options);
|
|
1122
1130
|
}
|
|
1123
1131
|
|
|
1124
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
1132
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/chunk-UJZOJSMP.mjs
|
|
1125
1133
|
var encoder = new TextEncoder();
|
|
1126
1134
|
function encodeBuffer(text) {
|
|
1127
1135
|
return encoder.encode(text);
|
|
@@ -1147,7 +1155,7 @@ var MockServiceWorker = (() => {
|
|
|
1147
1155
|
return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
|
|
1148
1156
|
}
|
|
1149
1157
|
|
|
1150
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
1158
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/chunk-HAGW22AN.mjs
|
|
1151
1159
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
1152
1160
|
|
|
1153
1161
|
// node_modules/.pnpm/is-node-process@1.2.0/node_modules/is-node-process/lib/index.mjs
|
|
@@ -1437,7 +1445,7 @@ var MockServiceWorker = (() => {
|
|
|
1437
1445
|
return message3.toString();
|
|
1438
1446
|
}
|
|
1439
1447
|
|
|
1440
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
1448
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
|
|
1441
1449
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
1442
1450
|
function getGlobalSymbol(symbol) {
|
|
1443
1451
|
return (
|
|
@@ -1585,7 +1593,7 @@ var MockServiceWorker = (() => {
|
|
|
1585
1593
|
return Math.random().toString(16).slice(2);
|
|
1586
1594
|
}
|
|
1587
1595
|
|
|
1588
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
1596
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
1589
1597
|
var BatchInterceptor = class extends Interceptor {
|
|
1590
1598
|
constructor(options) {
|
|
1591
1599
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -1693,6 +1701,9 @@ var MockServiceWorker = (() => {
|
|
|
1693
1701
|
params
|
|
1694
1702
|
};
|
|
1695
1703
|
}
|
|
1704
|
+
function isPath(value) {
|
|
1705
|
+
return typeof value === "string" || value instanceof RegExp;
|
|
1706
|
+
}
|
|
1696
1707
|
|
|
1697
1708
|
// src/core/utils/request/toPublicUrl.ts
|
|
1698
1709
|
function toPublicUrl(url) {
|
|
@@ -5613,6 +5624,195 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5613
5624
|
link: createGraphQLLink
|
|
5614
5625
|
};
|
|
5615
5626
|
|
|
5627
|
+
// src/core/handlers/WebSocketHandler.ts
|
|
5628
|
+
var kEmitter = Symbol("kEmitter");
|
|
5629
|
+
var kDispatchEvent = Symbol("kDispatchEvent");
|
|
5630
|
+
var kSender = Symbol("kSender");
|
|
5631
|
+
var WebSocketHandler = class {
|
|
5632
|
+
constructor(url) {
|
|
5633
|
+
this.url = url;
|
|
5634
|
+
this[kEmitter] = new Emitter();
|
|
5635
|
+
this.callFrame = getCallFrame(new Error());
|
|
5636
|
+
}
|
|
5637
|
+
callFrame;
|
|
5638
|
+
[kEmitter];
|
|
5639
|
+
parse(args) {
|
|
5640
|
+
const connection = args.event.data;
|
|
5641
|
+
const match2 = matchRequestUrl(connection.client.url, this.url);
|
|
5642
|
+
return {
|
|
5643
|
+
match: match2
|
|
5644
|
+
};
|
|
5645
|
+
}
|
|
5646
|
+
predicate(args) {
|
|
5647
|
+
return args.parsedResult.match.matches;
|
|
5648
|
+
}
|
|
5649
|
+
async [kDispatchEvent](event) {
|
|
5650
|
+
const parsedResult = this.parse({ event });
|
|
5651
|
+
const connection = event.data;
|
|
5652
|
+
const resolvedConnection = {
|
|
5653
|
+
client: connection.client,
|
|
5654
|
+
server: connection.server,
|
|
5655
|
+
params: parsedResult.match.params || {}
|
|
5656
|
+
};
|
|
5657
|
+
this[kEmitter].emit("connection", resolvedConnection);
|
|
5658
|
+
}
|
|
5659
|
+
};
|
|
5660
|
+
|
|
5661
|
+
// src/core/ws/WebSocketClientManager.ts
|
|
5662
|
+
var kAddByClientId = Symbol("kAddByClientId");
|
|
5663
|
+
var WebSocketClientManager = class {
|
|
5664
|
+
constructor(channel) {
|
|
5665
|
+
this.channel = channel;
|
|
5666
|
+
this.clients = /* @__PURE__ */ new Set();
|
|
5667
|
+
this.channel.addEventListener("message", (message3) => {
|
|
5668
|
+
const { type, payload } = message3.data;
|
|
5669
|
+
switch (type) {
|
|
5670
|
+
case "connection:open": {
|
|
5671
|
+
this.onRemoteConnection(payload.clientId, new URL(payload.url));
|
|
5672
|
+
break;
|
|
5673
|
+
}
|
|
5674
|
+
}
|
|
5675
|
+
});
|
|
5676
|
+
}
|
|
5677
|
+
/**
|
|
5678
|
+
* All active WebSocket client connections.
|
|
5679
|
+
*/
|
|
5680
|
+
clients;
|
|
5681
|
+
/**
|
|
5682
|
+
* Adds the given `WebSocket` client connection to the set
|
|
5683
|
+
* of all connections. The given connection is always the complete
|
|
5684
|
+
* connection object because `addConnection()` is called only
|
|
5685
|
+
* for the opened connections in the same runtime.
|
|
5686
|
+
*/
|
|
5687
|
+
addConnection(client) {
|
|
5688
|
+
this.clients.add(client);
|
|
5689
|
+
this.channel.postMessage({
|
|
5690
|
+
type: "connection:open",
|
|
5691
|
+
payload: {
|
|
5692
|
+
clientId: client.id,
|
|
5693
|
+
url: client.url.toString()
|
|
5694
|
+
}
|
|
5695
|
+
});
|
|
5696
|
+
const handleExtraneousMessage = (message3) => {
|
|
5697
|
+
const { type, payload } = message3.data;
|
|
5698
|
+
if (typeof payload === "object" && "clientId" in payload && payload.clientId !== client.id) {
|
|
5699
|
+
return;
|
|
5700
|
+
}
|
|
5701
|
+
switch (type) {
|
|
5702
|
+
case "extraneous:send": {
|
|
5703
|
+
client.send(payload.data);
|
|
5704
|
+
break;
|
|
5705
|
+
}
|
|
5706
|
+
case "extraneous:close": {
|
|
5707
|
+
client.close(payload.code, payload.reason);
|
|
5708
|
+
break;
|
|
5709
|
+
}
|
|
5710
|
+
}
|
|
5711
|
+
};
|
|
5712
|
+
const abortController = new AbortController();
|
|
5713
|
+
this.channel.addEventListener("message", handleExtraneousMessage, {
|
|
5714
|
+
signal: abortController.signal
|
|
5715
|
+
});
|
|
5716
|
+
client.addEventListener("close", () => abortController.abort(), {
|
|
5717
|
+
once: true
|
|
5718
|
+
});
|
|
5719
|
+
}
|
|
5720
|
+
/**
|
|
5721
|
+
* Adds a client connection wrapper to operate with
|
|
5722
|
+
* WebSocket client connections in other runtimes.
|
|
5723
|
+
*/
|
|
5724
|
+
onRemoteConnection(id, url) {
|
|
5725
|
+
this.clients.add(
|
|
5726
|
+
// Create a connection-compatible instance that can
|
|
5727
|
+
// operate with this client from a different runtime
|
|
5728
|
+
// using the BroadcastChannel messages.
|
|
5729
|
+
new WebSocketRemoteClientConnection(id, url, this.channel)
|
|
5730
|
+
);
|
|
5731
|
+
}
|
|
5732
|
+
};
|
|
5733
|
+
var WebSocketRemoteClientConnection = class {
|
|
5734
|
+
constructor(id, url, channel) {
|
|
5735
|
+
this.id = id;
|
|
5736
|
+
this.url = url;
|
|
5737
|
+
this.channel = channel;
|
|
5738
|
+
}
|
|
5739
|
+
send(data) {
|
|
5740
|
+
this.channel.postMessage({
|
|
5741
|
+
type: "extraneous:send",
|
|
5742
|
+
payload: {
|
|
5743
|
+
clientId: this.id,
|
|
5744
|
+
data
|
|
5745
|
+
}
|
|
5746
|
+
});
|
|
5747
|
+
}
|
|
5748
|
+
close(code, reason) {
|
|
5749
|
+
this.channel.postMessage({
|
|
5750
|
+
type: "extraneous:close",
|
|
5751
|
+
payload: {
|
|
5752
|
+
clientId: this.id,
|
|
5753
|
+
code,
|
|
5754
|
+
reason
|
|
5755
|
+
}
|
|
5756
|
+
});
|
|
5757
|
+
}
|
|
5758
|
+
};
|
|
5759
|
+
|
|
5760
|
+
// src/core/ws/ws.ts
|
|
5761
|
+
var wsBroadcastChannel = new BroadcastChannel("msw:ws-client-manager");
|
|
5762
|
+
function createWebSocketLinkHandler(url) {
|
|
5763
|
+
invariant(url, "Expected a WebSocket server URL but got undefined");
|
|
5764
|
+
invariant(
|
|
5765
|
+
isPath(url),
|
|
5766
|
+
"Expected a WebSocket server URL but got %s",
|
|
5767
|
+
typeof url
|
|
5768
|
+
);
|
|
5769
|
+
const clientManager = new WebSocketClientManager(wsBroadcastChannel);
|
|
5770
|
+
return {
|
|
5771
|
+
clients: clientManager.clients,
|
|
5772
|
+
on(event, listener) {
|
|
5773
|
+
const handler = new WebSocketHandler(url);
|
|
5774
|
+
handler[kEmitter].on("connection", ({ client }) => {
|
|
5775
|
+
clientManager.addConnection(client);
|
|
5776
|
+
});
|
|
5777
|
+
handler[kEmitter].on(event, listener);
|
|
5778
|
+
return handler;
|
|
5779
|
+
},
|
|
5780
|
+
/**
|
|
5781
|
+
* Broadcasts the given data to all WebSocket clients.
|
|
5782
|
+
*
|
|
5783
|
+
* @example
|
|
5784
|
+
* const service = ws.link('wss://example.com')
|
|
5785
|
+
* service.on('connection', () => {
|
|
5786
|
+
* service.broadcast('hello, everyone!')
|
|
5787
|
+
* })
|
|
5788
|
+
*/
|
|
5789
|
+
broadcast(data) {
|
|
5790
|
+
this.broadcastExcept([], data);
|
|
5791
|
+
},
|
|
5792
|
+
/**
|
|
5793
|
+
* Broadcasts the given data to all WebSocket clients
|
|
5794
|
+
* except the ones provided in the `clients` argument.
|
|
5795
|
+
*
|
|
5796
|
+
* @example
|
|
5797
|
+
* const service = ws.link('wss://example.com')
|
|
5798
|
+
* service.on('connection', ({ client }) => {
|
|
5799
|
+
* service.broadcastExcept(client, 'hi, the rest of you!')
|
|
5800
|
+
* })
|
|
5801
|
+
*/
|
|
5802
|
+
broadcastExcept(clients, data) {
|
|
5803
|
+
const ignoreClients = Array.prototype.concat(clients).map((client) => client.id);
|
|
5804
|
+
clientManager.clients.forEach((otherClient) => {
|
|
5805
|
+
if (!ignoreClients.includes(otherClient.id)) {
|
|
5806
|
+
otherClient.send(data);
|
|
5807
|
+
}
|
|
5808
|
+
});
|
|
5809
|
+
}
|
|
5810
|
+
};
|
|
5811
|
+
}
|
|
5812
|
+
var ws = {
|
|
5813
|
+
link: createWebSocketLinkHandler
|
|
5814
|
+
};
|
|
5815
|
+
|
|
5616
5816
|
// node_modules/.pnpm/@open-draft+until@2.1.0/node_modules/@open-draft/until/lib/index.mjs
|
|
5617
5817
|
var until = async (promise) => {
|
|
5618
5818
|
try {
|
|
@@ -5635,6 +5835,9 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5635
5835
|
let matchingHandler = null;
|
|
5636
5836
|
let result = null;
|
|
5637
5837
|
for (const handler of handlers) {
|
|
5838
|
+
if (!(handler instanceof RequestHandler)) {
|
|
5839
|
+
continue;
|
|
5840
|
+
}
|
|
5638
5841
|
result = await handler.run({ request, requestId, resolutionContext });
|
|
5639
5842
|
if (result !== null) {
|
|
5640
5843
|
matchingHandler = handler;
|
|
@@ -6488,7 +6691,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6488
6691
|
}
|
|
6489
6692
|
};
|
|
6490
6693
|
|
|
6491
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
6694
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/chunk-OUWBQF3Z.mjs
|
|
6492
6695
|
var RequestController = class {
|
|
6493
6696
|
constructor(request) {
|
|
6494
6697
|
this.request = request;
|
|
@@ -6526,7 +6729,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6526
6729
|
}
|
|
6527
6730
|
}
|
|
6528
6731
|
|
|
6529
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
6732
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/chunk-3FNUI33J.mjs
|
|
6530
6733
|
function isPropertyAccessible2(obj, key) {
|
|
6531
6734
|
try {
|
|
6532
6735
|
obj[key];
|
|
@@ -6673,7 +6876,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6673
6876
|
});
|
|
6674
6877
|
}
|
|
6675
6878
|
|
|
6676
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
6879
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/chunk-VYFS2IF2.mjs
|
|
6677
6880
|
function concatArrayBuffer(left, right) {
|
|
6678
6881
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
6679
6882
|
result.set(left, 0);
|
|
@@ -7498,6 +7701,743 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7498
7701
|
}
|
|
7499
7702
|
}
|
|
7500
7703
|
|
|
7704
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
7705
|
+
function bindEvent(target, event) {
|
|
7706
|
+
Object.defineProperties(event, {
|
|
7707
|
+
target: {
|
|
7708
|
+
value: target,
|
|
7709
|
+
enumerable: true,
|
|
7710
|
+
writable: true
|
|
7711
|
+
},
|
|
7712
|
+
currentTarget: {
|
|
7713
|
+
value: target,
|
|
7714
|
+
enumerable: true,
|
|
7715
|
+
writable: true
|
|
7716
|
+
}
|
|
7717
|
+
});
|
|
7718
|
+
return event;
|
|
7719
|
+
}
|
|
7720
|
+
var kCancelable = Symbol("kCancelable");
|
|
7721
|
+
var kDefaultPrevented = Symbol("kDefaultPrevented");
|
|
7722
|
+
var CancelableMessageEvent = class extends MessageEvent {
|
|
7723
|
+
constructor(type, init) {
|
|
7724
|
+
super(type, init);
|
|
7725
|
+
this[kCancelable] = !!init.cancelable;
|
|
7726
|
+
this[kDefaultPrevented] = false;
|
|
7727
|
+
}
|
|
7728
|
+
get cancelable() {
|
|
7729
|
+
return this[kCancelable];
|
|
7730
|
+
}
|
|
7731
|
+
get defaultPrevented() {
|
|
7732
|
+
return this[kDefaultPrevented];
|
|
7733
|
+
}
|
|
7734
|
+
preventDefault() {
|
|
7735
|
+
if (this.cancelable && !this[kDefaultPrevented]) {
|
|
7736
|
+
this[kDefaultPrevented] = true;
|
|
7737
|
+
}
|
|
7738
|
+
}
|
|
7739
|
+
};
|
|
7740
|
+
var CloseEvent = class extends Event {
|
|
7741
|
+
constructor(type, init = {}) {
|
|
7742
|
+
super(type, init);
|
|
7743
|
+
this.code = init.code === void 0 ? 0 : init.code;
|
|
7744
|
+
this.reason = init.reason === void 0 ? "" : init.reason;
|
|
7745
|
+
this.wasClean = init.wasClean === void 0 ? false : init.wasClean;
|
|
7746
|
+
}
|
|
7747
|
+
};
|
|
7748
|
+
var kEmitter2 = Symbol("kEmitter");
|
|
7749
|
+
var WebSocketClientConnection = class {
|
|
7750
|
+
constructor(socket, transport) {
|
|
7751
|
+
this.socket = socket;
|
|
7752
|
+
this.transport = transport;
|
|
7753
|
+
this.id = createRequestId();
|
|
7754
|
+
this.url = new URL(socket.url);
|
|
7755
|
+
this[kEmitter2] = new EventTarget();
|
|
7756
|
+
this.transport.onOutgoing = (data) => {
|
|
7757
|
+
this[kEmitter2].dispatchEvent(
|
|
7758
|
+
bindEvent(this.socket, new MessageEvent("message", { data }))
|
|
7759
|
+
);
|
|
7760
|
+
};
|
|
7761
|
+
this.transport.onClose = (event) => {
|
|
7762
|
+
this[kEmitter2].dispatchEvent(
|
|
7763
|
+
bindEvent(this.socket, new CloseEvent("close", event))
|
|
7764
|
+
);
|
|
7765
|
+
};
|
|
7766
|
+
}
|
|
7767
|
+
/**
|
|
7768
|
+
* Listen for the outgoing events from the connected WebSocket client.
|
|
7769
|
+
*/
|
|
7770
|
+
addEventListener(type, listener, options) {
|
|
7771
|
+
this[kEmitter2].addEventListener(type, listener, options);
|
|
7772
|
+
}
|
|
7773
|
+
/**
|
|
7774
|
+
* Removes the listener for the given event.
|
|
7775
|
+
*/
|
|
7776
|
+
removeEventListener(event, listener, options) {
|
|
7777
|
+
this[kEmitter2].removeEventListener(
|
|
7778
|
+
event,
|
|
7779
|
+
listener,
|
|
7780
|
+
options
|
|
7781
|
+
);
|
|
7782
|
+
}
|
|
7783
|
+
/**
|
|
7784
|
+
* Send data to the connected client.
|
|
7785
|
+
*/
|
|
7786
|
+
send(data) {
|
|
7787
|
+
this.transport.send(data);
|
|
7788
|
+
}
|
|
7789
|
+
/**
|
|
7790
|
+
* Close the WebSocket connection.
|
|
7791
|
+
* @param {number} code A status code (see https://www.rfc-editor.org/rfc/rfc6455#section-7.4.1).
|
|
7792
|
+
* @param {string} reason A custom connection close reason.
|
|
7793
|
+
*/
|
|
7794
|
+
close(code, reason) {
|
|
7795
|
+
this.transport.close(code, reason);
|
|
7796
|
+
}
|
|
7797
|
+
};
|
|
7798
|
+
var WEBSOCKET_CLOSE_CODE_RANGE_ERROR = "InvalidAccessError: close code out of user configurable range";
|
|
7799
|
+
var kOnSend = Symbol("kOnSend");
|
|
7800
|
+
var kClose = Symbol("kClose");
|
|
7801
|
+
var WebSocketOverride = class extends EventTarget {
|
|
7802
|
+
constructor(url, protocols) {
|
|
7803
|
+
super();
|
|
7804
|
+
this.CONNECTING = 0;
|
|
7805
|
+
this.OPEN = 1;
|
|
7806
|
+
this.CLOSING = 2;
|
|
7807
|
+
this.CLOSED = 3;
|
|
7808
|
+
this._onopen = null;
|
|
7809
|
+
this._onmessage = null;
|
|
7810
|
+
this._onerror = null;
|
|
7811
|
+
this._onclose = null;
|
|
7812
|
+
this.url = url.toString();
|
|
7813
|
+
this.protocol = "";
|
|
7814
|
+
this.extensions = "";
|
|
7815
|
+
this.binaryType = "blob";
|
|
7816
|
+
this.readyState = this.CONNECTING;
|
|
7817
|
+
this.bufferedAmount = 0;
|
|
7818
|
+
Reflect.set(this, "readyState", this.CONNECTING);
|
|
7819
|
+
queueMicrotask(() => {
|
|
7820
|
+
Reflect.set(this, "readyState", this.OPEN);
|
|
7821
|
+
this.protocol = protocols ? protocols[0] : "ws";
|
|
7822
|
+
this.dispatchEvent(bindEvent(this, new Event("open")));
|
|
7823
|
+
});
|
|
7824
|
+
}
|
|
7825
|
+
set onopen(listener) {
|
|
7826
|
+
this.removeEventListener("open", this._onopen);
|
|
7827
|
+
this._onopen = listener;
|
|
7828
|
+
if (listener !== null) {
|
|
7829
|
+
this.addEventListener("open", listener);
|
|
7830
|
+
}
|
|
7831
|
+
}
|
|
7832
|
+
get onopen() {
|
|
7833
|
+
return this._onopen;
|
|
7834
|
+
}
|
|
7835
|
+
set onmessage(listener) {
|
|
7836
|
+
this.removeEventListener(
|
|
7837
|
+
"message",
|
|
7838
|
+
this._onmessage
|
|
7839
|
+
);
|
|
7840
|
+
this._onmessage = listener;
|
|
7841
|
+
if (listener !== null) {
|
|
7842
|
+
this.addEventListener("message", listener);
|
|
7843
|
+
}
|
|
7844
|
+
}
|
|
7845
|
+
get onmessage() {
|
|
7846
|
+
return this._onmessage;
|
|
7847
|
+
}
|
|
7848
|
+
set onerror(listener) {
|
|
7849
|
+
this.removeEventListener("error", this._onerror);
|
|
7850
|
+
this._onerror = listener;
|
|
7851
|
+
if (listener !== null) {
|
|
7852
|
+
this.addEventListener("error", listener);
|
|
7853
|
+
}
|
|
7854
|
+
}
|
|
7855
|
+
get onerror() {
|
|
7856
|
+
return this._onerror;
|
|
7857
|
+
}
|
|
7858
|
+
set onclose(listener) {
|
|
7859
|
+
this.removeEventListener("close", this._onclose);
|
|
7860
|
+
this._onclose = listener;
|
|
7861
|
+
if (listener !== null) {
|
|
7862
|
+
this.addEventListener("close", listener);
|
|
7863
|
+
}
|
|
7864
|
+
}
|
|
7865
|
+
get onclose() {
|
|
7866
|
+
return this._onclose;
|
|
7867
|
+
}
|
|
7868
|
+
/**
|
|
7869
|
+
* @see https://websockets.spec.whatwg.org/#ref-for-dom-websocket-send%E2%91%A0
|
|
7870
|
+
*/
|
|
7871
|
+
send(data) {
|
|
7872
|
+
if (this.readyState === this.CONNECTING) {
|
|
7873
|
+
this.close();
|
|
7874
|
+
throw new DOMException("InvalidStateError");
|
|
7875
|
+
}
|
|
7876
|
+
if (this.readyState === this.CLOSING || this.readyState === this.CLOSED) {
|
|
7877
|
+
return;
|
|
7878
|
+
}
|
|
7879
|
+
this.bufferedAmount += getDataSize(data);
|
|
7880
|
+
queueMicrotask(() => {
|
|
7881
|
+
var _a2;
|
|
7882
|
+
this.bufferedAmount = 0;
|
|
7883
|
+
(_a2 = this[kOnSend]) == null ? void 0 : _a2.call(this, data);
|
|
7884
|
+
});
|
|
7885
|
+
}
|
|
7886
|
+
close(code = 1e3, reason) {
|
|
7887
|
+
invariant(code, WEBSOCKET_CLOSE_CODE_RANGE_ERROR);
|
|
7888
|
+
invariant(
|
|
7889
|
+
code === 1e3 || code >= 3e3 && code <= 4999,
|
|
7890
|
+
WEBSOCKET_CLOSE_CODE_RANGE_ERROR
|
|
7891
|
+
);
|
|
7892
|
+
if (this.readyState === this.CLOSING || this.readyState === this.CLOSED) {
|
|
7893
|
+
return;
|
|
7894
|
+
}
|
|
7895
|
+
this[kClose](code, reason);
|
|
7896
|
+
}
|
|
7897
|
+
[(kOnSend, kClose)](code = 1e3, reason) {
|
|
7898
|
+
this.readyState = this.CLOSING;
|
|
7899
|
+
queueMicrotask(() => {
|
|
7900
|
+
this.readyState = this.CLOSED;
|
|
7901
|
+
if (code > 1e3 && code <= 1015) {
|
|
7902
|
+
this.dispatchEvent(bindEvent(this, new Event("error")));
|
|
7903
|
+
}
|
|
7904
|
+
this.dispatchEvent(
|
|
7905
|
+
bindEvent(
|
|
7906
|
+
this,
|
|
7907
|
+
new CloseEvent("close", {
|
|
7908
|
+
code,
|
|
7909
|
+
reason,
|
|
7910
|
+
wasClean: code === 1e3
|
|
7911
|
+
})
|
|
7912
|
+
)
|
|
7913
|
+
);
|
|
7914
|
+
this._onopen = null;
|
|
7915
|
+
this._onmessage = null;
|
|
7916
|
+
this._onerror = null;
|
|
7917
|
+
this._onclose = null;
|
|
7918
|
+
});
|
|
7919
|
+
}
|
|
7920
|
+
addEventListener(type, listener, options) {
|
|
7921
|
+
return super.addEventListener(
|
|
7922
|
+
type,
|
|
7923
|
+
listener,
|
|
7924
|
+
options
|
|
7925
|
+
);
|
|
7926
|
+
}
|
|
7927
|
+
removeEventListener(type, callback, options) {
|
|
7928
|
+
return super.removeEventListener(type, callback, options);
|
|
7929
|
+
}
|
|
7930
|
+
};
|
|
7931
|
+
WebSocketOverride.CONNECTING = 0;
|
|
7932
|
+
WebSocketOverride.OPEN = 1;
|
|
7933
|
+
WebSocketOverride.CLOSING = 2;
|
|
7934
|
+
WebSocketOverride.CLOSED = 3;
|
|
7935
|
+
function getDataSize(data) {
|
|
7936
|
+
if (typeof data === "string") {
|
|
7937
|
+
return data.length;
|
|
7938
|
+
}
|
|
7939
|
+
if (data instanceof Blob) {
|
|
7940
|
+
return data.size;
|
|
7941
|
+
}
|
|
7942
|
+
return data.byteLength;
|
|
7943
|
+
}
|
|
7944
|
+
var kEmitter22 = Symbol("kEmitter");
|
|
7945
|
+
var WebSocketServerConnection = class {
|
|
7946
|
+
constructor(socket, transport, createConnection) {
|
|
7947
|
+
this.socket = socket;
|
|
7948
|
+
this.transport = transport;
|
|
7949
|
+
this.createConnection = createConnection;
|
|
7950
|
+
this[kEmitter22] = new EventTarget();
|
|
7951
|
+
this.mockCloseController = new AbortController();
|
|
7952
|
+
this.transport.onIncoming = (event) => {
|
|
7953
|
+
const messageEvent = bindEvent(
|
|
7954
|
+
this.realWebSocket,
|
|
7955
|
+
new CancelableMessageEvent("message", {
|
|
7956
|
+
data: event.data,
|
|
7957
|
+
origin: event.origin,
|
|
7958
|
+
cancelable: true
|
|
7959
|
+
})
|
|
7960
|
+
);
|
|
7961
|
+
this[kEmitter22].dispatchEvent(messageEvent);
|
|
7962
|
+
if (!messageEvent.defaultPrevented) {
|
|
7963
|
+
this.socket.dispatchEvent(
|
|
7964
|
+
bindEvent(
|
|
7965
|
+
/**
|
|
7966
|
+
* @note Bind the forwarded original server events
|
|
7967
|
+
* to the mock WebSocket instance so it would
|
|
7968
|
+
* dispatch them straight away.
|
|
7969
|
+
*/
|
|
7970
|
+
this.socket,
|
|
7971
|
+
// Clone the message event again to prevent
|
|
7972
|
+
// the "already being dispatched" exception.
|
|
7973
|
+
new MessageEvent("message", {
|
|
7974
|
+
data: event.data,
|
|
7975
|
+
origin: event.origin
|
|
7976
|
+
})
|
|
7977
|
+
)
|
|
7978
|
+
);
|
|
7979
|
+
}
|
|
7980
|
+
};
|
|
7981
|
+
}
|
|
7982
|
+
/**
|
|
7983
|
+
* Server ready state.
|
|
7984
|
+
* Proxies the ready state of the original WebSocket instance,
|
|
7985
|
+
* if set. If the original connection hasn't been established,
|
|
7986
|
+
* defaults to `-1`.
|
|
7987
|
+
*/
|
|
7988
|
+
get readyState() {
|
|
7989
|
+
if (this.realWebSocket) {
|
|
7990
|
+
return this.realWebSocket.readyState;
|
|
7991
|
+
}
|
|
7992
|
+
return -1;
|
|
7993
|
+
}
|
|
7994
|
+
/**
|
|
7995
|
+
* Open connection to the original WebSocket server.
|
|
7996
|
+
*/
|
|
7997
|
+
connect() {
|
|
7998
|
+
invariant(
|
|
7999
|
+
!this.realWebSocket || this.realWebSocket.readyState !== WebSocket.OPEN,
|
|
8000
|
+
'Failed to call "connect()" on the original WebSocket instance: the connection already open'
|
|
8001
|
+
);
|
|
8002
|
+
const realWebSocket = this.createConnection();
|
|
8003
|
+
realWebSocket.binaryType = this.socket.binaryType;
|
|
8004
|
+
realWebSocket.addEventListener(
|
|
8005
|
+
"open",
|
|
8006
|
+
(event) => {
|
|
8007
|
+
this[kEmitter22].dispatchEvent(
|
|
8008
|
+
bindEvent(this.realWebSocket, new Event("open", event))
|
|
8009
|
+
);
|
|
8010
|
+
},
|
|
8011
|
+
{ once: true }
|
|
8012
|
+
);
|
|
8013
|
+
realWebSocket.addEventListener("message", (event) => {
|
|
8014
|
+
this.transport.onIncoming(event);
|
|
8015
|
+
});
|
|
8016
|
+
this.socket.addEventListener("close", this.handleMockClose.bind(this), {
|
|
8017
|
+
signal: this.mockCloseController.signal
|
|
8018
|
+
});
|
|
8019
|
+
realWebSocket.addEventListener("close", this.handleRealClose.bind(this));
|
|
8020
|
+
realWebSocket.addEventListener("error", () => {
|
|
8021
|
+
this.socket.dispatchEvent(bindEvent(this.socket, new Event("error")));
|
|
8022
|
+
});
|
|
8023
|
+
this.realWebSocket = realWebSocket;
|
|
8024
|
+
}
|
|
8025
|
+
/**
|
|
8026
|
+
* Listen for the incoming events from the original WebSocket server.
|
|
8027
|
+
*/
|
|
8028
|
+
addEventListener(event, listener, options) {
|
|
8029
|
+
this[kEmitter22].addEventListener(
|
|
8030
|
+
event,
|
|
8031
|
+
listener.bind(this.realWebSocket),
|
|
8032
|
+
options
|
|
8033
|
+
);
|
|
8034
|
+
}
|
|
8035
|
+
/**
|
|
8036
|
+
* Remove the listener for the given event.
|
|
8037
|
+
*/
|
|
8038
|
+
removeEventListener(event, listener, options) {
|
|
8039
|
+
this[kEmitter22].removeEventListener(
|
|
8040
|
+
event,
|
|
8041
|
+
listener,
|
|
8042
|
+
options
|
|
8043
|
+
);
|
|
8044
|
+
}
|
|
8045
|
+
/**
|
|
8046
|
+
* Send data to the original WebSocket server.
|
|
8047
|
+
* @example
|
|
8048
|
+
* server.send('hello')
|
|
8049
|
+
* server.send(new Blob(['hello']))
|
|
8050
|
+
* server.send(new TextEncoder().encode('hello'))
|
|
8051
|
+
*/
|
|
8052
|
+
send(data) {
|
|
8053
|
+
const { realWebSocket } = this;
|
|
8054
|
+
invariant(
|
|
8055
|
+
realWebSocket,
|
|
8056
|
+
'Failed to call "server.send()" for "%s": the connection is not open. Did you forget to call "server.connect()"?',
|
|
8057
|
+
this.socket.url
|
|
8058
|
+
);
|
|
8059
|
+
if (realWebSocket.readyState === WebSocket.CLOSING || realWebSocket.readyState === WebSocket.CLOSED) {
|
|
8060
|
+
return;
|
|
8061
|
+
}
|
|
8062
|
+
if (realWebSocket.readyState === WebSocket.CONNECTING) {
|
|
8063
|
+
realWebSocket.addEventListener(
|
|
8064
|
+
"open",
|
|
8065
|
+
() => {
|
|
8066
|
+
realWebSocket.send(data);
|
|
8067
|
+
},
|
|
8068
|
+
{ once: true }
|
|
8069
|
+
);
|
|
8070
|
+
return;
|
|
8071
|
+
}
|
|
8072
|
+
realWebSocket.send(data);
|
|
8073
|
+
}
|
|
8074
|
+
/**
|
|
8075
|
+
* Close the actual server connection.
|
|
8076
|
+
*/
|
|
8077
|
+
close() {
|
|
8078
|
+
const { realWebSocket } = this;
|
|
8079
|
+
invariant(
|
|
8080
|
+
realWebSocket,
|
|
8081
|
+
'Failed to close server connection for "%s": the connection is not open. Did you forget to call "server.connect()"?',
|
|
8082
|
+
this.socket.url
|
|
8083
|
+
);
|
|
8084
|
+
realWebSocket.removeEventListener("close", this.handleRealClose);
|
|
8085
|
+
if (realWebSocket.readyState === WebSocket.CLOSING || realWebSocket.readyState === WebSocket.CLOSED) {
|
|
8086
|
+
return;
|
|
8087
|
+
}
|
|
8088
|
+
realWebSocket.close();
|
|
8089
|
+
queueMicrotask(() => {
|
|
8090
|
+
this[kEmitter22].dispatchEvent(
|
|
8091
|
+
bindEvent(this.realWebSocket, new CloseEvent("close"))
|
|
8092
|
+
);
|
|
8093
|
+
});
|
|
8094
|
+
}
|
|
8095
|
+
handleMockClose(_event) {
|
|
8096
|
+
if (this.realWebSocket) {
|
|
8097
|
+
this.realWebSocket.close();
|
|
8098
|
+
}
|
|
8099
|
+
}
|
|
8100
|
+
handleRealClose(event) {
|
|
8101
|
+
this.mockCloseController.abort();
|
|
8102
|
+
const closeEvent = bindEvent(
|
|
8103
|
+
this.realWebSocket,
|
|
8104
|
+
new CloseEvent("close", event)
|
|
8105
|
+
);
|
|
8106
|
+
this[kEmitter22].dispatchEvent(closeEvent);
|
|
8107
|
+
if (!closeEvent.defaultPrevented) {
|
|
8108
|
+
this.socket[kClose](event.code, event.reason);
|
|
8109
|
+
}
|
|
8110
|
+
}
|
|
8111
|
+
};
|
|
8112
|
+
var WebSocketTransport = class {
|
|
8113
|
+
};
|
|
8114
|
+
var WebSocketClassTransport = class extends WebSocketTransport {
|
|
8115
|
+
constructor(socket) {
|
|
8116
|
+
super();
|
|
8117
|
+
this.socket = socket;
|
|
8118
|
+
this.onOutgoing = () => {
|
|
8119
|
+
};
|
|
8120
|
+
this.onIncoming = () => {
|
|
8121
|
+
};
|
|
8122
|
+
this.onClose = () => {
|
|
8123
|
+
};
|
|
8124
|
+
this.socket.addEventListener("close", (event) => this.onClose(event), {
|
|
8125
|
+
once: true
|
|
8126
|
+
});
|
|
8127
|
+
this.socket[kOnSend] = (...args) => this.onOutgoing(...args);
|
|
8128
|
+
}
|
|
8129
|
+
send(data) {
|
|
8130
|
+
queueMicrotask(() => {
|
|
8131
|
+
const message3 = bindEvent(
|
|
8132
|
+
/**
|
|
8133
|
+
* @note Setting this event's "target" to the
|
|
8134
|
+
* WebSocket override instance is important.
|
|
8135
|
+
* This way it can tell apart original incoming events
|
|
8136
|
+
* (must be forwarded to the transport) from the
|
|
8137
|
+
* mocked message events like the one below
|
|
8138
|
+
* (must be dispatched on the client instance).
|
|
8139
|
+
*/
|
|
8140
|
+
this.socket,
|
|
8141
|
+
new MessageEvent("message", {
|
|
8142
|
+
data,
|
|
8143
|
+
origin: this.socket.url
|
|
8144
|
+
})
|
|
8145
|
+
);
|
|
8146
|
+
this.socket.dispatchEvent(message3);
|
|
8147
|
+
});
|
|
8148
|
+
}
|
|
8149
|
+
close(code, reason) {
|
|
8150
|
+
this.socket[kClose](code, reason);
|
|
8151
|
+
}
|
|
8152
|
+
};
|
|
8153
|
+
var _WebSocketInterceptor = class extends Interceptor {
|
|
8154
|
+
constructor() {
|
|
8155
|
+
super(_WebSocketInterceptor.symbol);
|
|
8156
|
+
}
|
|
8157
|
+
checkEnvironment() {
|
|
8158
|
+
return typeof globalThis.WebSocket !== "undefined";
|
|
8159
|
+
}
|
|
8160
|
+
setup() {
|
|
8161
|
+
const originalWebSocket = globalThis.WebSocket;
|
|
8162
|
+
const webSocketProxy = new Proxy(globalThis.WebSocket, {
|
|
8163
|
+
construct: (target, args, newTarget) => {
|
|
8164
|
+
const [url, protocols] = args;
|
|
8165
|
+
const createConnection = () => {
|
|
8166
|
+
return Reflect.construct(target, args, newTarget);
|
|
8167
|
+
};
|
|
8168
|
+
const socket = new WebSocketOverride(url, protocols);
|
|
8169
|
+
const transport = new WebSocketClassTransport(socket);
|
|
8170
|
+
queueMicrotask(() => {
|
|
8171
|
+
this.emitter.emit("connection", {
|
|
8172
|
+
client: new WebSocketClientConnection(socket, transport),
|
|
8173
|
+
server: new WebSocketServerConnection(
|
|
8174
|
+
socket,
|
|
8175
|
+
transport,
|
|
8176
|
+
createConnection
|
|
8177
|
+
)
|
|
8178
|
+
});
|
|
8179
|
+
});
|
|
8180
|
+
return socket;
|
|
8181
|
+
}
|
|
8182
|
+
});
|
|
8183
|
+
globalThis.WebSocket = webSocketProxy;
|
|
8184
|
+
this.subscriptions.push(() => {
|
|
8185
|
+
globalThis.WebSocket = originalWebSocket;
|
|
8186
|
+
});
|
|
8187
|
+
}
|
|
8188
|
+
};
|
|
8189
|
+
var WebSocketInterceptor = _WebSocketInterceptor;
|
|
8190
|
+
WebSocketInterceptor.symbol = Symbol("websocket");
|
|
8191
|
+
|
|
8192
|
+
// src/core/ws/webSocketInterceptor.ts
|
|
8193
|
+
var webSocketInterceptor = new WebSocketInterceptor();
|
|
8194
|
+
|
|
8195
|
+
// src/core/utils/handleWebSocketEvent.ts
|
|
8196
|
+
function handleWebSocketEvent(options) {
|
|
8197
|
+
webSocketInterceptor.on("connection", (connection) => {
|
|
8198
|
+
const handlers = options.getHandlers();
|
|
8199
|
+
const connectionEvent = new MessageEvent("connection", {
|
|
8200
|
+
data: connection
|
|
8201
|
+
});
|
|
8202
|
+
const matchingHandlers = handlers.filter(
|
|
8203
|
+
(handler) => {
|
|
8204
|
+
if (handler instanceof WebSocketHandler) {
|
|
8205
|
+
return handler.predicate({
|
|
8206
|
+
event: connectionEvent,
|
|
8207
|
+
parsedResult: handler.parse({
|
|
8208
|
+
event: connectionEvent
|
|
8209
|
+
})
|
|
8210
|
+
});
|
|
8211
|
+
}
|
|
8212
|
+
return false;
|
|
8213
|
+
}
|
|
8214
|
+
);
|
|
8215
|
+
if (matchingHandlers.length > 0) {
|
|
8216
|
+
options?.onMockedConnection(connection);
|
|
8217
|
+
for (const handler of matchingHandlers) {
|
|
8218
|
+
handler[kDispatchEvent](connectionEvent);
|
|
8219
|
+
}
|
|
8220
|
+
} else {
|
|
8221
|
+
options?.onPassthroughConnection(connection);
|
|
8222
|
+
connection.server.connect();
|
|
8223
|
+
connection.client.addEventListener("message", (event) => {
|
|
8224
|
+
connection.server.send(event.data);
|
|
8225
|
+
});
|
|
8226
|
+
}
|
|
8227
|
+
});
|
|
8228
|
+
}
|
|
8229
|
+
|
|
8230
|
+
// src/core/ws/utils/getMessageLength.ts
|
|
8231
|
+
function getMessageLength(data) {
|
|
8232
|
+
if (data instanceof Blob) {
|
|
8233
|
+
return data.size;
|
|
8234
|
+
}
|
|
8235
|
+
if (data instanceof ArrayBuffer) {
|
|
8236
|
+
return data.byteLength;
|
|
8237
|
+
}
|
|
8238
|
+
return new Blob([data]).size;
|
|
8239
|
+
}
|
|
8240
|
+
|
|
8241
|
+
// src/core/ws/utils/truncateMessage.ts
|
|
8242
|
+
var MAX_LENGTH = 24;
|
|
8243
|
+
function truncateMessage(message3) {
|
|
8244
|
+
if (message3.length <= MAX_LENGTH) {
|
|
8245
|
+
return message3;
|
|
8246
|
+
}
|
|
8247
|
+
return `${message3.slice(0, MAX_LENGTH)}\u2026`;
|
|
8248
|
+
}
|
|
8249
|
+
|
|
8250
|
+
// src/core/ws/utils/getPublicData.ts
|
|
8251
|
+
async function getPublicData(data) {
|
|
8252
|
+
if (data instanceof Blob) {
|
|
8253
|
+
const text = await data.text();
|
|
8254
|
+
return `Blob(${truncateMessage(text)})`;
|
|
8255
|
+
}
|
|
8256
|
+
if (typeof data === "object" && "byteLength" in data) {
|
|
8257
|
+
const text = new TextDecoder().decode(data);
|
|
8258
|
+
return `ArrayBuffer(${truncateMessage(text)})`;
|
|
8259
|
+
}
|
|
8260
|
+
return truncateMessage(data);
|
|
8261
|
+
}
|
|
8262
|
+
|
|
8263
|
+
// src/core/ws/utils/attachWebSocketLogger.ts
|
|
8264
|
+
function attachWebSocketLogger(connection) {
|
|
8265
|
+
const { client, server } = connection;
|
|
8266
|
+
logConnectionOpen(client);
|
|
8267
|
+
client.addEventListener("message", (event) => {
|
|
8268
|
+
logOutgoingClientMessage(event);
|
|
8269
|
+
});
|
|
8270
|
+
client.addEventListener("close", (event) => {
|
|
8271
|
+
logConnectionClose(event);
|
|
8272
|
+
});
|
|
8273
|
+
client.socket.addEventListener("message", (event) => {
|
|
8274
|
+
logIncomingClientMessage(event);
|
|
8275
|
+
});
|
|
8276
|
+
client.socket.addEventListener("error", (event) => {
|
|
8277
|
+
logClientError(event);
|
|
8278
|
+
});
|
|
8279
|
+
client.send = new Proxy(client.send, {
|
|
8280
|
+
apply(target, thisArg, args) {
|
|
8281
|
+
const [data] = args;
|
|
8282
|
+
const messageEvent = new MessageEvent("message", { data });
|
|
8283
|
+
Object.defineProperties(messageEvent, {
|
|
8284
|
+
currentTarget: {
|
|
8285
|
+
enumerable: true,
|
|
8286
|
+
writable: false,
|
|
8287
|
+
value: client.socket
|
|
8288
|
+
},
|
|
8289
|
+
target: {
|
|
8290
|
+
enumerable: true,
|
|
8291
|
+
writable: false,
|
|
8292
|
+
value: client.socket
|
|
8293
|
+
}
|
|
8294
|
+
});
|
|
8295
|
+
logIncomingMockedClientMessage(messageEvent);
|
|
8296
|
+
return Reflect.apply(target, thisArg, args);
|
|
8297
|
+
}
|
|
8298
|
+
});
|
|
8299
|
+
server.addEventListener(
|
|
8300
|
+
"open",
|
|
8301
|
+
() => {
|
|
8302
|
+
server.addEventListener("message", (event) => {
|
|
8303
|
+
logIncomingServerMessage(event);
|
|
8304
|
+
});
|
|
8305
|
+
},
|
|
8306
|
+
{ once: true }
|
|
8307
|
+
);
|
|
8308
|
+
server.send = new Proxy(server.send, {
|
|
8309
|
+
apply(target, thisArg, args) {
|
|
8310
|
+
const [data] = args;
|
|
8311
|
+
const messageEvent = new MessageEvent("message", { data });
|
|
8312
|
+
Object.defineProperties(messageEvent, {
|
|
8313
|
+
currentTarget: {
|
|
8314
|
+
enumerable: true,
|
|
8315
|
+
writable: false,
|
|
8316
|
+
value: server["realWebSocket"]
|
|
8317
|
+
},
|
|
8318
|
+
target: {
|
|
8319
|
+
enumerable: true,
|
|
8320
|
+
writable: false,
|
|
8321
|
+
value: server["realWebSocket"]
|
|
8322
|
+
}
|
|
8323
|
+
});
|
|
8324
|
+
logOutgoingMockedClientMessage(messageEvent);
|
|
8325
|
+
return Reflect.apply(target, thisArg, args);
|
|
8326
|
+
}
|
|
8327
|
+
});
|
|
8328
|
+
}
|
|
8329
|
+
function logConnectionOpen(client) {
|
|
8330
|
+
const publicUrl = toPublicUrl(client.url);
|
|
8331
|
+
console.groupCollapsed(
|
|
8332
|
+
devUtils.formatMessage(`${getTimestamp()} %c\u25B8%c ${publicUrl}`),
|
|
8333
|
+
"color:blue",
|
|
8334
|
+
"color:inherit"
|
|
8335
|
+
);
|
|
8336
|
+
console.log("Client:", client.socket);
|
|
8337
|
+
console.groupEnd();
|
|
8338
|
+
}
|
|
8339
|
+
async function logOutgoingClientMessage(event) {
|
|
8340
|
+
const byteLength = getMessageLength(event.data);
|
|
8341
|
+
const publicData = await getPublicData(event.data);
|
|
8342
|
+
console.groupCollapsed(
|
|
8343
|
+
devUtils.formatMessage(
|
|
8344
|
+
`${getTimestamp({ milliseconds: true })} %c\u2191%c ${publicData} %c${byteLength}%c`
|
|
8345
|
+
),
|
|
8346
|
+
"color:green",
|
|
8347
|
+
"color:inherit",
|
|
8348
|
+
"color:gray;font-weight:normal",
|
|
8349
|
+
"color:inherit;font-weight:inherit"
|
|
8350
|
+
);
|
|
8351
|
+
console.log(event);
|
|
8352
|
+
console.groupEnd();
|
|
8353
|
+
}
|
|
8354
|
+
async function logOutgoingMockedClientMessage(event) {
|
|
8355
|
+
const byteLength = getMessageLength(event.data);
|
|
8356
|
+
const publicData = await getPublicData(event.data);
|
|
8357
|
+
console.groupCollapsed(
|
|
8358
|
+
devUtils.formatMessage(
|
|
8359
|
+
`${getTimestamp({ milliseconds: true })} %c\u21E1%c ${publicData} %c${byteLength}%c`
|
|
8360
|
+
),
|
|
8361
|
+
"color:orangered",
|
|
8362
|
+
"color:inherit",
|
|
8363
|
+
"color:gray;font-weight:normal",
|
|
8364
|
+
"color:inherit;font-weight:inherit"
|
|
8365
|
+
);
|
|
8366
|
+
console.log(event);
|
|
8367
|
+
console.groupEnd();
|
|
8368
|
+
}
|
|
8369
|
+
async function logIncomingClientMessage(event) {
|
|
8370
|
+
const byteLength = getMessageLength(event.data);
|
|
8371
|
+
const publicData = await getPublicData(event.data);
|
|
8372
|
+
console.groupCollapsed(
|
|
8373
|
+
devUtils.formatMessage(
|
|
8374
|
+
`${getTimestamp({ milliseconds: true })} %c\u2193%c ${publicData} %c${byteLength}%c`
|
|
8375
|
+
),
|
|
8376
|
+
"color:red",
|
|
8377
|
+
"color:inherit",
|
|
8378
|
+
"color:gray;font-weight:normal",
|
|
8379
|
+
"color:inherit;font-weight:inherit"
|
|
8380
|
+
);
|
|
8381
|
+
console.log(event);
|
|
8382
|
+
console.groupEnd();
|
|
8383
|
+
}
|
|
8384
|
+
async function logIncomingMockedClientMessage(event) {
|
|
8385
|
+
const byteLength = getMessageLength(event.data);
|
|
8386
|
+
const publicData = await getPublicData(event.data);
|
|
8387
|
+
console.groupCollapsed(
|
|
8388
|
+
devUtils.formatMessage(
|
|
8389
|
+
`${getTimestamp({ milliseconds: true })} %c\u21E3%c ${publicData} %c${byteLength}%c`
|
|
8390
|
+
),
|
|
8391
|
+
"color:orangered",
|
|
8392
|
+
"color:inherit",
|
|
8393
|
+
"color:gray;font-weight:normal",
|
|
8394
|
+
"color:inherit;font-weight:inherit"
|
|
8395
|
+
);
|
|
8396
|
+
console.log(event);
|
|
8397
|
+
console.groupEnd();
|
|
8398
|
+
}
|
|
8399
|
+
function logConnectionClose(event) {
|
|
8400
|
+
const target = event.target;
|
|
8401
|
+
const publicUrl = toPublicUrl(target.url);
|
|
8402
|
+
console.groupCollapsed(
|
|
8403
|
+
devUtils.formatMessage(
|
|
8404
|
+
`${getTimestamp({ milliseconds: true })} %c\u25A0%c ${publicUrl}`
|
|
8405
|
+
),
|
|
8406
|
+
"color:blue",
|
|
8407
|
+
"color:inherit"
|
|
8408
|
+
);
|
|
8409
|
+
console.log(event);
|
|
8410
|
+
console.groupEnd();
|
|
8411
|
+
}
|
|
8412
|
+
async function logIncomingServerMessage(event) {
|
|
8413
|
+
const byteLength = getMessageLength(event.data);
|
|
8414
|
+
const publicData = await getPublicData(event.data);
|
|
8415
|
+
console.groupCollapsed(
|
|
8416
|
+
devUtils.formatMessage(
|
|
8417
|
+
`${getTimestamp({ milliseconds: true })} %c\u21E3%c ${publicData} %c${byteLength}%c`
|
|
8418
|
+
),
|
|
8419
|
+
"color:orangered",
|
|
8420
|
+
"color:inherit",
|
|
8421
|
+
"color:gray;font-weight:normal",
|
|
8422
|
+
"color:inherit;font-weight:inherit"
|
|
8423
|
+
);
|
|
8424
|
+
console.log(event);
|
|
8425
|
+
console.groupEnd();
|
|
8426
|
+
}
|
|
8427
|
+
function logClientError(event) {
|
|
8428
|
+
const socket = event.target;
|
|
8429
|
+
const publicUrl = toPublicUrl(socket.url);
|
|
8430
|
+
console.groupCollapsed(
|
|
8431
|
+
devUtils.formatMessage(
|
|
8432
|
+
`${getTimestamp({ milliseconds: true })} %c\xD7%c ${publicUrl}`
|
|
8433
|
+
),
|
|
8434
|
+
"color:red",
|
|
8435
|
+
"color:inherit"
|
|
8436
|
+
);
|
|
8437
|
+
console.log(event);
|
|
8438
|
+
console.groupEnd();
|
|
8439
|
+
}
|
|
8440
|
+
|
|
7501
8441
|
// src/browser/setupWorker/setupWorker.ts
|
|
7502
8442
|
var SetupWorkerApi = class extends SetupApi {
|
|
7503
8443
|
context;
|
|
@@ -7614,6 +8554,22 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7614
8554
|
DEFAULT_START_OPTIONS,
|
|
7615
8555
|
options
|
|
7616
8556
|
);
|
|
8557
|
+
handleWebSocketEvent({
|
|
8558
|
+
getHandlers: () => {
|
|
8559
|
+
return this.handlersController.currentHandlers();
|
|
8560
|
+
},
|
|
8561
|
+
onMockedConnection: (connection) => {
|
|
8562
|
+
if (!this.context.startOptions.quiet) {
|
|
8563
|
+
attachWebSocketLogger(connection);
|
|
8564
|
+
}
|
|
8565
|
+
},
|
|
8566
|
+
onPassthroughConnection() {
|
|
8567
|
+
}
|
|
8568
|
+
});
|
|
8569
|
+
webSocketInterceptor.apply();
|
|
8570
|
+
this.subscriptions.push(() => {
|
|
8571
|
+
webSocketInterceptor.dispose();
|
|
8572
|
+
});
|
|
7617
8573
|
return await this.startHandler(this.context.startOptions, options);
|
|
7618
8574
|
}
|
|
7619
8575
|
stop() {
|