msw 2.9.0 → 2.10.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.js +8 -8
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +8 -8
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +10 -7
- package/lib/core/handlers/WebSocketHandler.d.ts +10 -7
- package/lib/core/handlers/WebSocketHandler.js +12 -8
- package/lib/core/handlers/WebSocketHandler.js.map +1 -1
- package/lib/core/handlers/WebSocketHandler.mjs +12 -8
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -1
- package/lib/core/ws/WebSocketClientManager.d.mts +4 -2
- package/lib/core/ws/WebSocketClientManager.d.ts +4 -2
- package/lib/core/ws/WebSocketClientManager.js +10 -0
- package/lib/core/ws/WebSocketClientManager.js.map +1 -1
- package/lib/core/ws/WebSocketClientManager.mjs +10 -0
- package/lib/core/ws/WebSocketClientManager.mjs.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.js +26 -39
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs +26 -39
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -1
- package/lib/core/ws/utils/getMessageLength.js.map +1 -1
- package/lib/core/ws/utils/getMessageLength.mjs.map +1 -1
- package/lib/core/ws/utils/getPublicData.js.map +1 -1
- package/lib/core/ws/utils/getPublicData.mjs.map +1 -1
- package/lib/iife/index.js +57 -54
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +3 -3
- package/src/core/handlers/WebSocketHandler.test.ts +12 -61
- package/src/core/handlers/WebSocketHandler.ts +27 -15
- package/src/core/ws/WebSocketClientManager.ts +33 -3
- package/src/core/ws/handleWebSocketEvent.ts +36 -55
- package/src/core/ws/utils/getMessageLength.ts +1 -1
- package/src/core/ws/utils/getPublicData.ts +1 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { kDispatchEvent } from '../handlers/WebSocketHandler.mjs';
|
|
2
1
|
import { webSocketInterceptor } from './webSocketInterceptor.mjs';
|
|
3
2
|
import {
|
|
4
3
|
onUnhandledRequest
|
|
@@ -6,48 +5,36 @@ import {
|
|
|
6
5
|
import { isHandlerKind } from '../utils/internal/isHandlerKind.mjs';
|
|
7
6
|
function handleWebSocketEvent(options) {
|
|
8
7
|
webSocketInterceptor.on("connection", async (connection) => {
|
|
9
|
-
const handlers = options.getHandlers();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (isHandlerKind("EventHandler")(handler) && handler.predicate({
|
|
16
|
-
event: connectionEvent,
|
|
17
|
-
parsedResult: handler.parse({
|
|
18
|
-
event: connectionEvent
|
|
8
|
+
const handlers = options.getHandlers().filter(isHandlerKind("EventHandler"));
|
|
9
|
+
if (handlers.length > 0) {
|
|
10
|
+
options?.onMockedConnection(connection);
|
|
11
|
+
await Promise.all(
|
|
12
|
+
handlers.map((handler) => {
|
|
13
|
+
return handler.run(connection);
|
|
19
14
|
})
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
15
|
+
);
|
|
16
|
+
return;
|
|
23
17
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
const request = new Request(connection.client.url, {
|
|
19
|
+
headers: {
|
|
20
|
+
upgrade: "websocket",
|
|
21
|
+
connection: "upgrade"
|
|
28
22
|
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
).catch((error) => {
|
|
40
|
-
const errorEvent = new Event("error");
|
|
41
|
-
Object.defineProperty(errorEvent, "cause", {
|
|
42
|
-
enumerable: true,
|
|
43
|
-
configurable: false,
|
|
44
|
-
value: error
|
|
45
|
-
});
|
|
46
|
-
connection.client.socket.dispatchEvent(errorEvent);
|
|
23
|
+
});
|
|
24
|
+
await onUnhandledRequest(
|
|
25
|
+
request,
|
|
26
|
+
options.getUnhandledRequestStrategy()
|
|
27
|
+
).catch((error) => {
|
|
28
|
+
const errorEvent = new Event("error");
|
|
29
|
+
Object.defineProperty(errorEvent, "cause", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: false,
|
|
32
|
+
value: error
|
|
47
33
|
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
34
|
+
connection.client.socket.dispatchEvent(errorEvent);
|
|
35
|
+
});
|
|
36
|
+
options?.onPassthroughConnection(connection);
|
|
37
|
+
connection.server.connect();
|
|
51
38
|
});
|
|
52
39
|
}
|
|
53
40
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/ws/handleWebSocketEvent.ts"],"sourcesContent":["import type { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport { RequestHandler } from '../handlers/RequestHandler'\nimport { WebSocketHandler
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/handleWebSocketEvent.ts"],"sourcesContent":["import type { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport { RequestHandler } from '../handlers/RequestHandler'\nimport { WebSocketHandler } from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from './webSocketInterceptor'\nimport {\n onUnhandledRequest,\n UnhandledRequestStrategy,\n} from '../utils/request/onUnhandledRequest'\nimport { isHandlerKind } from '../utils/internal/isHandlerKind'\n\ninterface HandleWebSocketEventOptions {\n getUnhandledRequestStrategy: () => UnhandledRequestStrategy\n getHandlers: () => Array<RequestHandler | WebSocketHandler>\n onMockedConnection: (connection: WebSocketConnectionData) => void\n onPassthroughConnection: (onnection: WebSocketConnectionData) => void\n}\n\nexport function handleWebSocketEvent(options: HandleWebSocketEventOptions) {\n webSocketInterceptor.on('connection', async (connection) => {\n const handlers = options.getHandlers().filter(isHandlerKind('EventHandler'))\n\n // Ignore this connection if the user hasn't defined any handlers.\n if (handlers.length > 0) {\n options?.onMockedConnection(connection)\n\n await Promise.all(\n handlers.map((handler) => {\n // Iterate over the handlers and forward the connection\n // event to WebSocket event handlers. This is equivalent\n // to dispatching that event onto multiple listeners.\n return handler.run(connection)\n }),\n )\n\n return\n }\n\n // Construct a request representing this WebSocket connection.\n const request = new Request(connection.client.url, {\n headers: {\n upgrade: 'websocket',\n connection: 'upgrade',\n },\n })\n await onUnhandledRequest(\n request,\n options.getUnhandledRequestStrategy(),\n ).catch((error) => {\n const errorEvent = new Event('error')\n Object.defineProperty(errorEvent, 'cause', {\n enumerable: true,\n configurable: false,\n value: error,\n })\n connection.client.socket.dispatchEvent(errorEvent)\n })\n\n options?.onPassthroughConnection(connection)\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n connection.server.connect()\n })\n}\n"],"mappings":"AAGA,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,OAEK;AACP,SAAS,qBAAqB;AASvB,SAAS,qBAAqB,SAAsC;AACzE,uBAAqB,GAAG,cAAc,OAAO,eAAe;AAC1D,UAAM,WAAW,QAAQ,YAAY,EAAE,OAAO,cAAc,cAAc,CAAC;AAG3E,QAAI,SAAS,SAAS,GAAG;AACvB,eAAS,mBAAmB,UAAU;AAEtC,YAAM,QAAQ;AAAA,QACZ,SAAS,IAAI,CAAC,YAAY;AAIxB,iBAAO,QAAQ,IAAI,UAAU;AAAA,QAC/B,CAAC;AAAA,MACH;AAEA;AAAA,IACF;AAGA,UAAM,UAAU,IAAI,QAAQ,WAAW,OAAO,KAAK;AAAA,MACjD,SAAS;AAAA,QACP,SAAS;AAAA,QACT,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AACD,UAAM;AAAA,MACJ;AAAA,MACA,QAAQ,4BAA4B;AAAA,IACtC,EAAE,MAAM,CAAC,UAAU;AACjB,YAAM,aAAa,IAAI,MAAM,OAAO;AACpC,aAAO,eAAe,YAAY,SAAS;AAAA,QACzC,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,OAAO;AAAA,MACT,CAAC;AACD,iBAAW,OAAO,OAAO,cAAc,UAAU;AAAA,IACnD,CAAC;AAED,aAAS,wBAAwB,UAAU;AAI3C,eAAW,OAAO,QAAQ;AAAA,EAC5B,CAAC;AACH;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/ws/utils/getMessageLength.ts"],"sourcesContent":["import type { WebSocketData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\n\n/**\n * Returns the byte length of the given WebSocket message.\n * @example\n * getMessageLength('hello') // 5\n * getMessageLength(new Blob(['hello'])) // 5\n */\nexport function getMessageLength(data: WebSocketData): number {\n if (data instanceof Blob) {\n return data.size\n }\n\n if (data instanceof ArrayBuffer) {\n return data.byteLength\n }\n\n return new Blob([data]).size\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,SAAS,iBAAiB,MAA6B;AAC5D,MAAI,gBAAgB,MAAM;AACxB,WAAO,KAAK;AAAA,EACd;AAEA,MAAI,gBAAgB,aAAa;AAC/B,WAAO,KAAK;AAAA,EACd;AAEA,SAAO,IAAI,KAAK,CAAC,
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/ws/utils/getMessageLength.ts"],"sourcesContent":["import type { WebSocketData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\n\n/**\n * Returns the byte length of the given WebSocket message.\n * @example\n * getMessageLength('hello') // 5\n * getMessageLength(new Blob(['hello'])) // 5\n */\nexport function getMessageLength(data: WebSocketData): number {\n if (data instanceof Blob) {\n return data.size\n }\n\n if (data instanceof ArrayBuffer) {\n return data.byteLength\n }\n\n return new Blob([data as any]).size\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,SAAS,iBAAiB,MAA6B;AAC5D,MAAI,gBAAgB,MAAM;AACxB,WAAO,KAAK;AAAA,EACd;AAEA,MAAI,gBAAgB,aAAa;AAC/B,WAAO,KAAK;AAAA,EACd;AAEA,SAAO,IAAI,KAAK,CAAC,IAAW,CAAC,EAAE;AACjC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/ws/utils/getMessageLength.ts"],"sourcesContent":["import type { WebSocketData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\n\n/**\n * Returns the byte length of the given WebSocket message.\n * @example\n * getMessageLength('hello') // 5\n * getMessageLength(new Blob(['hello'])) // 5\n */\nexport function getMessageLength(data: WebSocketData): number {\n if (data instanceof Blob) {\n return data.size\n }\n\n if (data instanceof ArrayBuffer) {\n return data.byteLength\n }\n\n return new Blob([data]).size\n}\n"],"mappings":"AAQO,SAAS,iBAAiB,MAA6B;AAC5D,MAAI,gBAAgB,MAAM;AACxB,WAAO,KAAK;AAAA,EACd;AAEA,MAAI,gBAAgB,aAAa;AAC/B,WAAO,KAAK;AAAA,EACd;AAEA,SAAO,IAAI,KAAK,CAAC,
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/ws/utils/getMessageLength.ts"],"sourcesContent":["import type { WebSocketData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\n\n/**\n * Returns the byte length of the given WebSocket message.\n * @example\n * getMessageLength('hello') // 5\n * getMessageLength(new Blob(['hello'])) // 5\n */\nexport function getMessageLength(data: WebSocketData): number {\n if (data instanceof Blob) {\n return data.size\n }\n\n if (data instanceof ArrayBuffer) {\n return data.byteLength\n }\n\n return new Blob([data as any]).size\n}\n"],"mappings":"AAQO,SAAS,iBAAiB,MAA6B;AAC5D,MAAI,gBAAgB,MAAM;AACxB,WAAO,KAAK;AAAA,EACd;AAEA,MAAI,gBAAgB,aAAa;AAC/B,WAAO,KAAK;AAAA,EACd;AAEA,SAAO,IAAI,KAAK,CAAC,IAAW,CAAC,EAAE;AACjC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/ws/utils/getPublicData.ts"],"sourcesContent":["import { WebSocketData } from '@mswjs/interceptors/WebSocket'\nimport { truncateMessage } from './truncateMessage'\n\nexport async function getPublicData(data: WebSocketData): Promise<string> {\n if (data instanceof Blob) {\n const text = await data.text()\n return `Blob(${truncateMessage(text)})`\n }\n\n // Handle all ArrayBuffer-like objects.\n if (typeof data === 'object' && 'byteLength' in data) {\n const text = new TextDecoder().decode(data)\n return `ArrayBuffer(${truncateMessage(text)})`\n }\n\n return truncateMessage(data)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,6BAAgC;AAEhC,eAAsB,cAAc,MAAsC;AACxE,MAAI,gBAAgB,MAAM;AACxB,UAAM,OAAO,MAAM,KAAK,KAAK;AAC7B,WAAO,YAAQ,wCAAgB,IAAI,CAAC;AAAA,EACtC;AAGA,MAAI,OAAO,SAAS,YAAY,gBAAgB,MAAM;AACpD,UAAM,OAAO,IAAI,YAAY,EAAE,OAAO,
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/ws/utils/getPublicData.ts"],"sourcesContent":["import { WebSocketData } from '@mswjs/interceptors/WebSocket'\nimport { truncateMessage } from './truncateMessage'\n\nexport async function getPublicData(data: WebSocketData): Promise<string> {\n if (data instanceof Blob) {\n const text = await data.text()\n return `Blob(${truncateMessage(text)})`\n }\n\n // Handle all ArrayBuffer-like objects.\n if (typeof data === 'object' && 'byteLength' in data) {\n const text = new TextDecoder().decode(data as ArrayBuffer)\n return `ArrayBuffer(${truncateMessage(text)})`\n }\n\n return truncateMessage(data)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,6BAAgC;AAEhC,eAAsB,cAAc,MAAsC;AACxE,MAAI,gBAAgB,MAAM;AACxB,UAAM,OAAO,MAAM,KAAK,KAAK;AAC7B,WAAO,YAAQ,wCAAgB,IAAI,CAAC;AAAA,EACtC;AAGA,MAAI,OAAO,SAAS,YAAY,gBAAgB,MAAM;AACpD,UAAM,OAAO,IAAI,YAAY,EAAE,OAAO,IAAmB;AACzD,WAAO,mBAAe,wCAAgB,IAAI,CAAC;AAAA,EAC7C;AAEA,aAAO,wCAAgB,IAAI;AAC7B;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/ws/utils/getPublicData.ts"],"sourcesContent":["import { WebSocketData } from '@mswjs/interceptors/WebSocket'\nimport { truncateMessage } from './truncateMessage'\n\nexport async function getPublicData(data: WebSocketData): Promise<string> {\n if (data instanceof Blob) {\n const text = await data.text()\n return `Blob(${truncateMessage(text)})`\n }\n\n // Handle all ArrayBuffer-like objects.\n if (typeof data === 'object' && 'byteLength' in data) {\n const text = new TextDecoder().decode(data)\n return `ArrayBuffer(${truncateMessage(text)})`\n }\n\n return truncateMessage(data)\n}\n"],"mappings":"AACA,SAAS,uBAAuB;AAEhC,eAAsB,cAAc,MAAsC;AACxE,MAAI,gBAAgB,MAAM;AACxB,UAAM,OAAO,MAAM,KAAK,KAAK;AAC7B,WAAO,QAAQ,gBAAgB,IAAI,CAAC;AAAA,EACtC;AAGA,MAAI,OAAO,SAAS,YAAY,gBAAgB,MAAM;AACpD,UAAM,OAAO,IAAI,YAAY,EAAE,OAAO,
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/ws/utils/getPublicData.ts"],"sourcesContent":["import { WebSocketData } from '@mswjs/interceptors/WebSocket'\nimport { truncateMessage } from './truncateMessage'\n\nexport async function getPublicData(data: WebSocketData): Promise<string> {\n if (data instanceof Blob) {\n const text = await data.text()\n return `Blob(${truncateMessage(text)})`\n }\n\n // Handle all ArrayBuffer-like objects.\n if (typeof data === 'object' && 'byteLength' in data) {\n const text = new TextDecoder().decode(data as ArrayBuffer)\n return `ArrayBuffer(${truncateMessage(text)})`\n }\n\n return truncateMessage(data)\n}\n"],"mappings":"AACA,SAAS,uBAAuB;AAEhC,eAAsB,cAAc,MAAsC;AACxE,MAAI,gBAAgB,MAAM;AACxB,UAAM,OAAO,MAAM,KAAK,KAAK;AAC7B,WAAO,QAAQ,gBAAgB,IAAI,CAAC;AAAA,EACtC;AAGA,MAAI,OAAO,SAAS,YAAY,gBAAgB,MAAM;AACpD,UAAM,OAAO,IAAI,YAAY,EAAE,OAAO,IAAmB;AACzD,WAAO,eAAe,gBAAgB,IAAI,CAAC;AAAA,EAC7C;AAEA,SAAO,gBAAgB,IAAI;AAC7B;","names":[]}
|
package/lib/iife/index.js
CHANGED
|
@@ -14246,7 +14246,7 @@ ${operationTypes.join("\n")}
|
|
|
14246
14246
|
return stringToRegexp(path, keys, options);
|
|
14247
14247
|
}
|
|
14248
14248
|
|
|
14249
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14249
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.39.1/node_modules/@mswjs/interceptors/lib/browser/chunk-6HYIRFX2.mjs
|
|
14250
14250
|
var encoder = new TextEncoder();
|
|
14251
14251
|
function encodeBuffer(text) {
|
|
14252
14252
|
return encoder.encode(text);
|
|
@@ -14262,7 +14262,7 @@ ${operationTypes.join("\n")}
|
|
|
14262
14262
|
);
|
|
14263
14263
|
}
|
|
14264
14264
|
|
|
14265
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14265
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.39.1/node_modules/@mswjs/interceptors/lib/browser/chunk-3RXCRGL2.mjs
|
|
14266
14266
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
14267
14267
|
function canParseUrl(url) {
|
|
14268
14268
|
try {
|
|
@@ -14643,7 +14643,7 @@ ${operationTypes.join("\n")}
|
|
|
14643
14643
|
return message3.toString();
|
|
14644
14644
|
}
|
|
14645
14645
|
|
|
14646
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14646
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.39.1/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
|
|
14647
14647
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
14648
14648
|
function getGlobalSymbol(symbol) {
|
|
14649
14649
|
return (
|
|
@@ -14791,7 +14791,7 @@ ${operationTypes.join("\n")}
|
|
|
14791
14791
|
return Math.random().toString(16).slice(2);
|
|
14792
14792
|
}
|
|
14793
14793
|
|
|
14794
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14794
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.39.1/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
14795
14795
|
var BatchInterceptor = class extends Interceptor {
|
|
14796
14796
|
constructor(options) {
|
|
14797
14797
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -28038,7 +28038,6 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
28038
28038
|
|
|
28039
28039
|
// src/core/handlers/WebSocketHandler.ts
|
|
28040
28040
|
var kEmitter = Symbol("kEmitter");
|
|
28041
|
-
var kDispatchEvent = Symbol("kDispatchEvent");
|
|
28042
28041
|
var kSender = Symbol("kSender");
|
|
28043
28042
|
var kStopPropagationPatched = Symbol("kStopPropagationPatched");
|
|
28044
28043
|
var KOnStopPropagation = Symbol("KOnStopPropagation");
|
|
@@ -28055,8 +28054,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
28055
28054
|
callFrame;
|
|
28056
28055
|
[kEmitter];
|
|
28057
28056
|
parse(args) {
|
|
28058
|
-
const
|
|
28059
|
-
const { url: clientUrl } = connection.client;
|
|
28057
|
+
const clientUrl = new URL(args.url);
|
|
28060
28058
|
clientUrl.pathname = clientUrl.pathname.replace(/^\/socket.io\//, "/");
|
|
28061
28059
|
const match2 = matchRequestUrl(clientUrl, this.url);
|
|
28062
28060
|
return {
|
|
@@ -28066,13 +28064,20 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
28066
28064
|
predicate(args) {
|
|
28067
28065
|
return args.parsedResult.match.matches;
|
|
28068
28066
|
}
|
|
28069
|
-
async
|
|
28070
|
-
const parsedResult = this.parse({
|
|
28071
|
-
|
|
28067
|
+
async run(connection) {
|
|
28068
|
+
const parsedResult = this.parse({
|
|
28069
|
+
url: connection.client.url
|
|
28070
|
+
});
|
|
28071
|
+
if (!this.predicate({ url: connection.client.url, parsedResult })) {
|
|
28072
|
+
return false;
|
|
28073
|
+
}
|
|
28072
28074
|
const resolvedConnection = {
|
|
28073
28075
|
...connection,
|
|
28074
28076
|
params: parsedResult.match.params || {}
|
|
28075
28077
|
};
|
|
28078
|
+
return this.connect(resolvedConnection);
|
|
28079
|
+
}
|
|
28080
|
+
connect(connection) {
|
|
28076
28081
|
connection.client.addEventListener(
|
|
28077
28082
|
"message",
|
|
28078
28083
|
createStopPropagationListener(this)
|
|
@@ -28097,7 +28102,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
28097
28102
|
"close",
|
|
28098
28103
|
createStopPropagationListener(this)
|
|
28099
28104
|
);
|
|
28100
|
-
this[kEmitter].emit("connection",
|
|
28105
|
+
return this[kEmitter].emit("connection", connection);
|
|
28101
28106
|
}
|
|
28102
28107
|
};
|
|
28103
28108
|
function createStopPropagationListener(handler) {
|
|
@@ -28445,6 +28450,16 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
28445
28450
|
}
|
|
28446
28451
|
});
|
|
28447
28452
|
}
|
|
28453
|
+
addEventListener(_type, _listener, _options) {
|
|
28454
|
+
throw new Error(
|
|
28455
|
+
"WebSocketRemoteClientConnection.addEventListener is not supported"
|
|
28456
|
+
);
|
|
28457
|
+
}
|
|
28458
|
+
removeEventListener(_event, _listener, _options) {
|
|
28459
|
+
throw new Error(
|
|
28460
|
+
"WebSocketRemoteClientConnection.removeEventListener is not supported"
|
|
28461
|
+
);
|
|
28462
|
+
}
|
|
28448
28463
|
};
|
|
28449
28464
|
|
|
28450
28465
|
// src/core/ws.ts
|
|
@@ -29356,7 +29371,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29356
29371
|
}
|
|
29357
29372
|
};
|
|
29358
29373
|
|
|
29359
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
29374
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.39.1/node_modules/@mswjs/interceptors/lib/browser/chunk-L37TY7LC.mjs
|
|
29360
29375
|
var InterceptorError = class extends Error {
|
|
29361
29376
|
constructor(message3) {
|
|
29362
29377
|
super(message3);
|
|
@@ -29573,7 +29588,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29573
29588
|
return false;
|
|
29574
29589
|
}
|
|
29575
29590
|
|
|
29576
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
29591
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.39.1/node_modules/@mswjs/interceptors/lib/browser/chunk-TX5GBTFY.mjs
|
|
29577
29592
|
function hasConfigurableGlobal(propertyName) {
|
|
29578
29593
|
const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
|
|
29579
29594
|
if (typeof descriptor === "undefined") {
|
|
@@ -29594,7 +29609,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29594
29609
|
return true;
|
|
29595
29610
|
}
|
|
29596
29611
|
|
|
29597
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
29612
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.39.1/node_modules/@mswjs/interceptors/lib/browser/chunk-ARPHZXGT.mjs
|
|
29598
29613
|
function createNetworkError(cause) {
|
|
29599
29614
|
return Object.assign(new TypeError("Failed to fetch"), {
|
|
29600
29615
|
cause
|
|
@@ -29850,7 +29865,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29850
29865
|
var FetchInterceptor = _FetchInterceptor;
|
|
29851
29866
|
FetchInterceptor.symbol = Symbol("fetch");
|
|
29852
29867
|
|
|
29853
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
29868
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.39.1/node_modules/@mswjs/interceptors/lib/browser/chunk-QKSBFQDK.mjs
|
|
29854
29869
|
function concatArrayBuffer(left, right) {
|
|
29855
29870
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
29856
29871
|
result.set(left, 0);
|
|
@@ -30723,7 +30738,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
30723
30738
|
}
|
|
30724
30739
|
}
|
|
30725
30740
|
|
|
30726
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
30741
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.39.1/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
30727
30742
|
function bindEvent(target, event) {
|
|
30728
30743
|
Object.defineProperties(event, {
|
|
30729
30744
|
target: {
|
|
@@ -31406,48 +31421,36 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31406
31421
|
// src/core/ws/handleWebSocketEvent.ts
|
|
31407
31422
|
function handleWebSocketEvent(options) {
|
|
31408
31423
|
webSocketInterceptor.on("connection", async (connection) => {
|
|
31409
|
-
const handlers = options.getHandlers();
|
|
31410
|
-
|
|
31411
|
-
|
|
31412
|
-
|
|
31413
|
-
|
|
31414
|
-
|
|
31415
|
-
if (isHandlerKind("EventHandler")(handler) && handler.predicate({
|
|
31416
|
-
event: connectionEvent,
|
|
31417
|
-
parsedResult: handler.parse({
|
|
31418
|
-
event: connectionEvent
|
|
31424
|
+
const handlers = options.getHandlers().filter(isHandlerKind("EventHandler"));
|
|
31425
|
+
if (handlers.length > 0) {
|
|
31426
|
+
options?.onMockedConnection(connection);
|
|
31427
|
+
await Promise.all(
|
|
31428
|
+
handlers.map((handler) => {
|
|
31429
|
+
return handler.run(connection);
|
|
31419
31430
|
})
|
|
31420
|
-
|
|
31421
|
-
|
|
31422
|
-
}
|
|
31431
|
+
);
|
|
31432
|
+
return;
|
|
31423
31433
|
}
|
|
31424
|
-
|
|
31425
|
-
|
|
31426
|
-
|
|
31427
|
-
|
|
31434
|
+
const request = new Request(connection.client.url, {
|
|
31435
|
+
headers: {
|
|
31436
|
+
upgrade: "websocket",
|
|
31437
|
+
connection: "upgrade"
|
|
31428
31438
|
}
|
|
31429
|
-
}
|
|
31430
|
-
|
|
31431
|
-
|
|
31432
|
-
|
|
31433
|
-
|
|
31434
|
-
|
|
31435
|
-
|
|
31436
|
-
|
|
31437
|
-
|
|
31438
|
-
|
|
31439
|
-
).catch((error3) => {
|
|
31440
|
-
const errorEvent = new Event("error");
|
|
31441
|
-
Object.defineProperty(errorEvent, "cause", {
|
|
31442
|
-
enumerable: true,
|
|
31443
|
-
configurable: false,
|
|
31444
|
-
value: error3
|
|
31445
|
-
});
|
|
31446
|
-
connection.client.socket.dispatchEvent(errorEvent);
|
|
31439
|
+
});
|
|
31440
|
+
await onUnhandledRequest(
|
|
31441
|
+
request,
|
|
31442
|
+
options.getUnhandledRequestStrategy()
|
|
31443
|
+
).catch((error3) => {
|
|
31444
|
+
const errorEvent = new Event("error");
|
|
31445
|
+
Object.defineProperty(errorEvent, "cause", {
|
|
31446
|
+
enumerable: true,
|
|
31447
|
+
configurable: false,
|
|
31448
|
+
value: error3
|
|
31447
31449
|
});
|
|
31448
|
-
|
|
31449
|
-
|
|
31450
|
-
|
|
31450
|
+
connection.client.socket.dispatchEvent(errorEvent);
|
|
31451
|
+
});
|
|
31452
|
+
options?.onPassthroughConnection(connection);
|
|
31453
|
+
connection.server.connect();
|
|
31451
31454
|
});
|
|
31452
31455
|
}
|
|
31453
31456
|
|