msw 2.3.0-ws.rc-1 → 2.3.0-ws.rc-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/cli/init.js +1 -1
- package/lib/browser/index.d.mts +4 -4
- package/lib/browser/index.js +65 -60
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +65 -60
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-QGQY_9Rc.d.mts → GraphQLHandler-CzcXr7At.d.mts} +3 -3
- package/lib/core/{GraphQLHandler-Cbu12sb0.d.ts → GraphQLHandler-DGyzNtRQ.d.ts} +3 -3
- package/lib/core/{HttpResponse-BWB1yDNM.d.mts → HttpResponse-BOzDwzB6.d.ts} +3 -3
- package/lib/core/{HttpResponse-DeJBWGN5.d.ts → HttpResponse-CSyJ1cbO.d.mts} +3 -3
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/HttpResponse.js.map +1 -1
- package/lib/core/HttpResponse.mjs.map +1 -1
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/bypass.js +6 -1
- package/lib/core/bypass.js.map +1 -1
- package/lib/core/bypass.mjs +6 -1
- package/lib/core/bypass.mjs.map +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/getResponse.js +2 -2
- package/lib/core/getResponse.js.map +1 -1
- package/lib/core/getResponse.mjs +2 -2
- package/lib/core/getResponse.mjs.map +1 -1
- package/lib/core/graphql.d.mts +8 -6
- package/lib/core/graphql.d.ts +8 -6
- package/lib/core/graphql.js.map +1 -1
- package/lib/core/graphql.mjs.map +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.js.map +1 -1
- package/lib/core/handlers/GraphQLHandler.mjs.map +1 -1
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/HttpHandler.js +1 -1
- package/lib/core/handlers/HttpHandler.js.map +1 -1
- package/lib/core/handlers/HttpHandler.mjs +1 -1
- package/lib/core/handlers/HttpHandler.mjs.map +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +11 -17
- package/lib/core/handlers/WebSocketHandler.d.ts +11 -17
- package/lib/core/handlers/WebSocketHandler.js +9 -12
- package/lib/core/handlers/WebSocketHandler.js.map +1 -1
- package/lib/core/handlers/WebSocketHandler.mjs +9 -12
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +5 -5
- package/lib/core/index.d.ts +5 -5
- package/lib/core/index.js +3 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +5 -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/typeUtils.d.mts +6 -1
- package/lib/core/typeUtils.d.ts +6 -1
- package/lib/core/typeUtils.js.map +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/HttpResponse/decorators.js +4 -1
- package/lib/core/utils/HttpResponse/decorators.js.map +1 -1
- package/lib/core/utils/HttpResponse/decorators.mjs +4 -1
- package/lib/core/utils/HttpResponse/decorators.mjs.map +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/handleRequest.d.mts +1 -1
- package/lib/core/utils/handleRequest.d.ts +1 -1
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/core/utils/internal/mergeRight.js +15 -12
- package/lib/core/utils/internal/mergeRight.js.map +1 -1
- package/lib/core/utils/internal/mergeRight.mjs +15 -12
- package/lib/core/utils/internal/mergeRight.mjs.map +1 -1
- 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/ws/handleWebSocketEvent.d.mts +16 -0
- package/lib/core/ws/handleWebSocketEvent.d.ts +16 -0
- package/lib/core/{utils → ws}/handleWebSocketEvent.js +21 -18
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -0
- package/lib/core/ws/handleWebSocketEvent.mjs +39 -0
- package/lib/core/ws/handleWebSocketEvent.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/{utils/internal/randomId.js → ws/utils/truncateMessage.js} +11 -7
- 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/ws.d.mts → ws.d.mts} +19 -14
- package/lib/core/{ws/ws.d.ts → ws.d.ts} +19 -14
- package/lib/core/{ws/ws.js → ws.js} +4 -23
- package/lib/core/ws.js.map +1 -0
- package/lib/core/{ws/ws.mjs → ws.mjs} +4 -23
- package/lib/core/ws.mjs.map +1 -0
- package/lib/iife/index.js +516 -256
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +8 -11
- package/lib/native/index.d.mts +4 -4
- package/lib/native/index.js +9 -3
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +9 -3
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.d.mts +6 -6
- package/lib/node/index.d.ts +2 -2
- package/lib/node/index.js +9 -3
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +9 -3
- package/lib/node/index.mjs.map +1 -1
- package/package.json +9 -12
- package/src/browser/setupWorker/glossary.ts +4 -1
- package/src/browser/setupWorker/setupWorker.ts +20 -3
- package/src/browser/setupWorker/start/createRequestListener.ts +1 -1
- package/src/browser/setupWorker/start/createStartHandler.ts +9 -19
- package/src/browser/setupWorker/start/utils/createMessageChannel.ts +1 -1
- package/src/browser/utils/checkWorkerIntegrity.ts +34 -0
- package/src/core/HttpResponse.ts +3 -2
- package/src/core/bypass.test.ts +22 -0
- package/src/core/bypass.ts +9 -1
- package/src/core/getResponse.ts +2 -2
- package/src/core/graphql.ts +6 -3
- package/src/core/handlers/GraphQLHandler.test.ts +4 -5
- package/src/core/handlers/GraphQLHandler.ts +7 -4
- package/src/core/handlers/HttpHandler.test.ts +5 -5
- package/src/core/handlers/HttpHandler.ts +1 -1
- package/src/core/handlers/WebSocketHandler.ts +21 -39
- package/src/core/index.ts +7 -3
- package/src/core/typeUtils.ts +16 -10
- package/src/core/utils/HttpResponse/decorators.ts +8 -4
- package/src/core/utils/handleRequest.test.ts +14 -14
- package/src/core/utils/handleRequest.ts +1 -1
- package/src/core/utils/internal/mergeRight.ts +16 -13
- package/src/core/utils/logging/getTimestamp.test.ts +20 -6
- package/src/core/utils/logging/getTimestamp.ts +11 -6
- package/src/core/ws/handleWebSocketEvent.ts +59 -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/ws.ts → ws.ts} +49 -35
- package/src/mockServiceWorker.js +7 -10
- package/src/node/SetupServerApi.ts +4 -4
- package/src/node/SetupServerCommonApi.ts +7 -3
- package/src/node/glossary.ts +3 -3
- package/lib/core/utils/handleWebSocketEvent.d.mts +0 -10
- package/lib/core/utils/handleWebSocketEvent.d.ts +0 -10
- package/lib/core/utils/handleWebSocketEvent.js.map +0 -1
- package/lib/core/utils/handleWebSocketEvent.mjs +0 -40
- package/lib/core/utils/handleWebSocketEvent.mjs.map +0 -1
- package/lib/core/utils/internal/randomId.d.mts +0 -3
- package/lib/core/utils/internal/randomId.d.ts +0 -3
- package/lib/core/utils/internal/randomId.js.map +0 -1
- package/lib/core/utils/internal/randomId.mjs +0 -7
- package/lib/core/utils/internal/randomId.mjs.map +0 -1
- package/lib/core/ws/ws.js.map +0 -1
- package/lib/core/ws/ws.mjs.map +0 -1
- package/src/browser/utils/requestIntegrityCheck.ts +0 -23
- package/src/core/utils/handleWebSocketEvent.ts +0 -49
- package/src/core/utils/internal/randomId.ts +0 -3
- /package/src/core/{ws/ws.test.ts → ws.test.ts} +0 -0
|
@@ -18,7 +18,7 @@ import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'
|
|
|
18
18
|
import { mergeRight } from '~/core/utils/internal/mergeRight'
|
|
19
19
|
import { devUtils } from '~/core/utils/internal/devUtils'
|
|
20
20
|
import type { SetupServerCommon } from './glossary'
|
|
21
|
-
import { handleWebSocketEvent } from '~/core/
|
|
21
|
+
import { handleWebSocketEvent } from '~/core/ws/handleWebSocketEvent'
|
|
22
22
|
import { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'
|
|
23
23
|
|
|
24
24
|
export const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {
|
|
@@ -85,8 +85,12 @@ export class SetupServerCommonApi
|
|
|
85
85
|
},
|
|
86
86
|
)
|
|
87
87
|
|
|
88
|
-
handleWebSocketEvent(
|
|
89
|
-
|
|
88
|
+
handleWebSocketEvent({
|
|
89
|
+
getHandlers: () => {
|
|
90
|
+
return this.handlersController.currentHandlers()
|
|
91
|
+
},
|
|
92
|
+
onMockedConnection: () => {},
|
|
93
|
+
onPassthroughConnection: () => {},
|
|
90
94
|
})
|
|
91
95
|
}
|
|
92
96
|
|
package/src/node/glossary.ts
CHANGED
|
@@ -68,7 +68,7 @@ export interface SetupServer extends SetupServerCommon {
|
|
|
68
68
|
*
|
|
69
69
|
* @see {@link https://mswjs.io/docs/api/setup-server/boundary `server.boundary()` API reference}
|
|
70
70
|
*/
|
|
71
|
-
boundary<
|
|
72
|
-
callback:
|
|
73
|
-
): (...args:
|
|
71
|
+
boundary<Args extends Array<any>, R>(
|
|
72
|
+
callback: (...args: Args) => R,
|
|
73
|
+
): (...args: Args) => R
|
|
74
74
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { R as RequestHandler } from '../HttpResponse-BWB1yDNM.mjs';
|
|
2
|
-
import { WebSocketHandler } from '../handlers/WebSocketHandler.mjs';
|
|
3
|
-
import '../typeUtils.mjs';
|
|
4
|
-
import 'strict-event-emitter';
|
|
5
|
-
import '@mswjs/interceptors/WebSocket';
|
|
6
|
-
import './matching/matchRequestUrl.mjs';
|
|
7
|
-
|
|
8
|
-
declare function handleWebSocketEvent(getCurrentHandlers: () => Array<RequestHandler | WebSocketHandler>): void;
|
|
9
|
-
|
|
10
|
-
export { handleWebSocketEvent };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { R as RequestHandler } from '../HttpResponse-DeJBWGN5.js';
|
|
2
|
-
import { WebSocketHandler } from '../handlers/WebSocketHandler.js';
|
|
3
|
-
import '../typeUtils.js';
|
|
4
|
-
import 'strict-event-emitter';
|
|
5
|
-
import '@mswjs/interceptors/WebSocket';
|
|
6
|
-
import './matching/matchRequestUrl.js';
|
|
7
|
-
|
|
8
|
-
declare function handleWebSocketEvent(getCurrentHandlers: () => Array<RequestHandler | WebSocketHandler>): void;
|
|
9
|
-
|
|
10
|
-
export { handleWebSocketEvent };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/utils/handleWebSocketEvent.ts"],"sourcesContent":["import { RequestHandler } from '../handlers/RequestHandler'\nimport {\n WebSocketHandler,\n kDefaultPrevented,\n kDispatchEvent,\n} from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from '../ws/webSocketInterceptor'\n\nexport function handleWebSocketEvent(\n getCurrentHandlers: () => Array<RequestHandler | WebSocketHandler>,\n) {\n webSocketInterceptor.on('connection', (connection) => {\n const handlers = getCurrentHandlers()\n\n const connectionEvent = new MessageEvent('connection', {\n data: connection,\n /**\n * @note This message event should be marked as \"cancelable\"\n * to have its default prevented using \"event.preventDefault()\".\n * There's a bug in Node.js that breaks the \"cancelable\" flag.\n * @see https://github.com/nodejs/node/issues/51767\n */\n })\n\n Object.defineProperty(connectionEvent, kDefaultPrevented, {\n enumerable: false,\n writable: true,\n value: false,\n })\n\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 for (const handler of handlers) {\n if (handler instanceof WebSocketHandler) {\n handler[kDispatchEvent](connectionEvent)\n }\n }\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n if (!Reflect.get(connectionEvent, kDefaultPrevented)) {\n connection.server.connect()\n connection.client.addEventListener('message', (event) => {\n connection.server.send(event.data)\n })\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,8BAIO;AACP,kCAAqC;AAE9B,SAAS,qBACd,oBACA;AACA,mDAAqB,GAAG,cAAc,CAAC,eAAe;AACpD,UAAM,WAAW,mBAAmB;AAEpC,UAAM,kBAAkB,IAAI,aAAa,cAAc;AAAA,MACrD,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOR,CAAC;AAED,WAAO,eAAe,iBAAiB,2CAAmB;AAAA,MACxD,YAAY;AAAA,MACZ,UAAU;AAAA,MACV,OAAO;AAAA,IACT,CAAC;AAKD,eAAW,WAAW,UAAU;AAC9B,UAAI,mBAAmB,0CAAkB;AACvC,gBAAQ,sCAAc,EAAE,eAAe;AAAA,MACzC;AAAA,IACF;AAIA,QAAI,CAAC,QAAQ,IAAI,iBAAiB,yCAAiB,GAAG;AACpD,iBAAW,OAAO,QAAQ;AAC1B,iBAAW,OAAO,iBAAiB,WAAW,CAAC,UAAU;AACvD,mBAAW,OAAO,KAAK,MAAM,IAAI;AAAA,MACnC,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WebSocketHandler,
|
|
3
|
-
kDefaultPrevented,
|
|
4
|
-
kDispatchEvent
|
|
5
|
-
} from '../handlers/WebSocketHandler.mjs';
|
|
6
|
-
import { webSocketInterceptor } from '../ws/webSocketInterceptor.mjs';
|
|
7
|
-
function handleWebSocketEvent(getCurrentHandlers) {
|
|
8
|
-
webSocketInterceptor.on("connection", (connection) => {
|
|
9
|
-
const handlers = getCurrentHandlers();
|
|
10
|
-
const connectionEvent = new MessageEvent("connection", {
|
|
11
|
-
data: connection
|
|
12
|
-
/**
|
|
13
|
-
* @note This message event should be marked as "cancelable"
|
|
14
|
-
* to have its default prevented using "event.preventDefault()".
|
|
15
|
-
* There's a bug in Node.js that breaks the "cancelable" flag.
|
|
16
|
-
* @see https://github.com/nodejs/node/issues/51767
|
|
17
|
-
*/
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(connectionEvent, kDefaultPrevented, {
|
|
20
|
-
enumerable: false,
|
|
21
|
-
writable: true,
|
|
22
|
-
value: false
|
|
23
|
-
});
|
|
24
|
-
for (const handler of handlers) {
|
|
25
|
-
if (handler instanceof WebSocketHandler) {
|
|
26
|
-
handler[kDispatchEvent](connectionEvent);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (!Reflect.get(connectionEvent, kDefaultPrevented)) {
|
|
30
|
-
connection.server.connect();
|
|
31
|
-
connection.client.addEventListener("message", (event) => {
|
|
32
|
-
connection.server.send(event.data);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
export {
|
|
38
|
-
handleWebSocketEvent
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=handleWebSocketEvent.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/utils/handleWebSocketEvent.ts"],"sourcesContent":["import { RequestHandler } from '../handlers/RequestHandler'\nimport {\n WebSocketHandler,\n kDefaultPrevented,\n kDispatchEvent,\n} from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from '../ws/webSocketInterceptor'\n\nexport function handleWebSocketEvent(\n getCurrentHandlers: () => Array<RequestHandler | WebSocketHandler>,\n) {\n webSocketInterceptor.on('connection', (connection) => {\n const handlers = getCurrentHandlers()\n\n const connectionEvent = new MessageEvent('connection', {\n data: connection,\n /**\n * @note This message event should be marked as \"cancelable\"\n * to have its default prevented using \"event.preventDefault()\".\n * There's a bug in Node.js that breaks the \"cancelable\" flag.\n * @see https://github.com/nodejs/node/issues/51767\n */\n })\n\n Object.defineProperty(connectionEvent, kDefaultPrevented, {\n enumerable: false,\n writable: true,\n value: false,\n })\n\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 for (const handler of handlers) {\n if (handler instanceof WebSocketHandler) {\n handler[kDispatchEvent](connectionEvent)\n }\n }\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n if (!Reflect.get(connectionEvent, kDefaultPrevented)) {\n connection.server.connect()\n connection.client.addEventListener('message', (event) => {\n connection.server.send(event.data)\n })\n }\n })\n}\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,4BAA4B;AAE9B,SAAS,qBACd,oBACA;AACA,uBAAqB,GAAG,cAAc,CAAC,eAAe;AACpD,UAAM,WAAW,mBAAmB;AAEpC,UAAM,kBAAkB,IAAI,aAAa,cAAc;AAAA,MACrD,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOR,CAAC;AAED,WAAO,eAAe,iBAAiB,mBAAmB;AAAA,MACxD,YAAY;AAAA,MACZ,UAAU;AAAA,MACV,OAAO;AAAA,IACT,CAAC;AAKD,eAAW,WAAW,UAAU;AAC9B,UAAI,mBAAmB,kBAAkB;AACvC,gBAAQ,cAAc,EAAE,eAAe;AAAA,MACzC;AAAA,IACF;AAIA,QAAI,CAAC,QAAQ,IAAI,iBAAiB,iBAAiB,GAAG;AACpD,iBAAW,OAAO,QAAQ;AAC1B,iBAAW,OAAO,iBAAiB,WAAW,CAAC,UAAU;AACvD,mBAAW,OAAO,KAAK,MAAM,IAAI;AAAA,MACnC,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/internal/randomId.ts"],"sourcesContent":["export function randomId(): string {\n return Math.random().toString(16).slice(2)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,WAAmB;AACjC,SAAO,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC;AAC3C;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/internal/randomId.ts"],"sourcesContent":["export function randomId(): string {\n return Math.random().toString(16).slice(2)\n}\n"],"mappings":"AAAO,SAAS,WAAmB;AACjC,SAAO,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC;AAC3C;","names":[]}
|
package/lib/core/ws/ws.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/ws/ws.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport type {\n WebSocketClientConnectionProtocol,\n WebSocketData,\n} from '@mswjs/interceptors/WebSocket'\nimport {\n WebSocketHandler,\n kEmitter,\n type WebSocketHandlerEventMap,\n} from '../handlers/WebSocketHandler'\nimport { Path, isPath } from '../utils/matching/matchRequestUrl'\nimport { WebSocketClientManager } from './WebSocketClientManager'\n\nconst wsBroadcastChannel = new BroadcastChannel('msw:ws-client-manager')\n\n/**\n * Intercepts outgoing WebSocket connections to the given URL.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n * chat.on('connection', ({ client }) => {\n * client.send('hello from server!')\n * })\n */\nfunction createWebSocketLinkHandler(url: Path) {\n invariant(url, 'Expected a WebSocket server URL but got undefined')\n\n invariant(\n isPath(url),\n 'Expected a WebSocket server URL but got %s',\n typeof url,\n )\n\n const clientManager = new WebSocketClientManager(wsBroadcastChannel)\n\n return {\n clients: clientManager.clients,\n on<K extends keyof WebSocketHandlerEventMap>(\n event: K,\n listener: (...args: WebSocketHandlerEventMap[K]) => void,\n ): WebSocketHandler {\n const handler = new WebSocketHandler(url)\n\n // Add the connection event listener for when the\n // handler matches and emits a connection event.\n // When that happens, store that connection in the\n // set of all connections for reference.\n handler[kEmitter].on('connection', ({ client }) => {\n clientManager.addConnection(client)\n })\n\n // The \"handleWebSocketEvent\" function will invoke\n // the \"run()\" method on the WebSocketHandler.\n // If the handler matches, it will emit the \"connection\"\n // event. Attach the user-defined listener to that event.\n handler[kEmitter].on(event, listener)\n\n return handler\n },\n\n /**\n * Broadcasts the given data to all WebSocket clients.\n *\n * @example\n * const service = ws.link('wss://example.com')\n * service.on('connection', () => {\n * service.broadcast('hello, everyone!')\n * })\n */\n broadcast(data: WebSocketData): void {\n // This will invoke \"send()\" on the immediate clients\n // in this runtime and post a message to the broadcast channel\n // to trigger send for the clients in other runtimes.\n this.broadcastExcept([], data)\n },\n\n /**\n * Broadcasts the given data to all WebSocket clients\n * except the ones provided in the `clients` argument.\n *\n * @example\n * const service = ws.link('wss://example.com')\n * service.on('connection', ({ client }) => {\n * service.broadcastExcept(client, 'hi, the rest of you!')\n * })\n */\n broadcastExcept(\n clients:\n | WebSocketClientConnectionProtocol\n | Array<WebSocketClientConnectionProtocol>,\n data: WebSocketData,\n ): void {\n const ignoreClients = Array.prototype\n .concat(clients)\n .map((client) => client.id)\n\n clientManager.clients.forEach((otherClient) => {\n if (!ignoreClients.includes(otherClient.id)) {\n otherClient.send(data)\n }\n })\n },\n }\n}\n\nexport const ws = {\n link: createWebSocketLinkHandler,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA0B;AAK1B,8BAIO;AACP,6BAA6B;AAC7B,oCAAuC;AAEvC,MAAM,qBAAqB,IAAI,iBAAiB,uBAAuB;AAWvE,SAAS,2BAA2B,KAAW;AAC7C,mCAAU,KAAK,mDAAmD;AAElE;AAAA,QACE,+BAAO,GAAG;AAAA,IACV;AAAA,IACA,OAAO;AAAA,EACT;AAEA,QAAM,gBAAgB,IAAI,qDAAuB,kBAAkB;AAEnE,SAAO;AAAA,IACL,SAAS,cAAc;AAAA,IACvB,GACE,OACA,UACkB;AAClB,YAAM,UAAU,IAAI,yCAAiB,GAAG;AAMxC,cAAQ,gCAAQ,EAAE,GAAG,cAAc,CAAC,EAAE,OAAO,MAAM;AACjD,sBAAc,cAAc,MAAM;AAAA,MACpC,CAAC;AAMD,cAAQ,gCAAQ,EAAE,GAAG,OAAO,QAAQ;AAEpC,aAAO;AAAA,IACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWA,UAAU,MAA2B;AAInC,WAAK,gBAAgB,CAAC,GAAG,IAAI;AAAA,IAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAYA,gBACE,SAGA,MACM;AACN,YAAM,gBAAgB,MAAM,UACzB,OAAO,OAAO,EACd,IAAI,CAAC,WAAW,OAAO,EAAE;AAE5B,oBAAc,QAAQ,QAAQ,CAAC,gBAAgB;AAC7C,YAAI,CAAC,cAAc,SAAS,YAAY,EAAE,GAAG;AAC3C,sBAAY,KAAK,IAAI;AAAA,QACvB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,MAAM,KAAK;AAAA,EAChB,MAAM;AACR;","names":[]}
|
package/lib/core/ws/ws.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/ws/ws.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport type {\n WebSocketClientConnectionProtocol,\n WebSocketData,\n} from '@mswjs/interceptors/WebSocket'\nimport {\n WebSocketHandler,\n kEmitter,\n type WebSocketHandlerEventMap,\n} from '../handlers/WebSocketHandler'\nimport { Path, isPath } from '../utils/matching/matchRequestUrl'\nimport { WebSocketClientManager } from './WebSocketClientManager'\n\nconst wsBroadcastChannel = new BroadcastChannel('msw:ws-client-manager')\n\n/**\n * Intercepts outgoing WebSocket connections to the given URL.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n * chat.on('connection', ({ client }) => {\n * client.send('hello from server!')\n * })\n */\nfunction createWebSocketLinkHandler(url: Path) {\n invariant(url, 'Expected a WebSocket server URL but got undefined')\n\n invariant(\n isPath(url),\n 'Expected a WebSocket server URL but got %s',\n typeof url,\n )\n\n const clientManager = new WebSocketClientManager(wsBroadcastChannel)\n\n return {\n clients: clientManager.clients,\n on<K extends keyof WebSocketHandlerEventMap>(\n event: K,\n listener: (...args: WebSocketHandlerEventMap[K]) => void,\n ): WebSocketHandler {\n const handler = new WebSocketHandler(url)\n\n // Add the connection event listener for when the\n // handler matches and emits a connection event.\n // When that happens, store that connection in the\n // set of all connections for reference.\n handler[kEmitter].on('connection', ({ client }) => {\n clientManager.addConnection(client)\n })\n\n // The \"handleWebSocketEvent\" function will invoke\n // the \"run()\" method on the WebSocketHandler.\n // If the handler matches, it will emit the \"connection\"\n // event. Attach the user-defined listener to that event.\n handler[kEmitter].on(event, listener)\n\n return handler\n },\n\n /**\n * Broadcasts the given data to all WebSocket clients.\n *\n * @example\n * const service = ws.link('wss://example.com')\n * service.on('connection', () => {\n * service.broadcast('hello, everyone!')\n * })\n */\n broadcast(data: WebSocketData): void {\n // This will invoke \"send()\" on the immediate clients\n // in this runtime and post a message to the broadcast channel\n // to trigger send for the clients in other runtimes.\n this.broadcastExcept([], data)\n },\n\n /**\n * Broadcasts the given data to all WebSocket clients\n * except the ones provided in the `clients` argument.\n *\n * @example\n * const service = ws.link('wss://example.com')\n * service.on('connection', ({ client }) => {\n * service.broadcastExcept(client, 'hi, the rest of you!')\n * })\n */\n broadcastExcept(\n clients:\n | WebSocketClientConnectionProtocol\n | Array<WebSocketClientConnectionProtocol>,\n data: WebSocketData,\n ): void {\n const ignoreClients = Array.prototype\n .concat(clients)\n .map((client) => client.id)\n\n clientManager.clients.forEach((otherClient) => {\n if (!ignoreClients.includes(otherClient.id)) {\n otherClient.send(data)\n }\n })\n },\n }\n}\n\nexport const ws = {\n link: createWebSocketLinkHandler,\n}\n"],"mappings":"AAAA,SAAS,iBAAiB;AAK1B;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAe,cAAc;AAC7B,SAAS,8BAA8B;AAEvC,MAAM,qBAAqB,IAAI,iBAAiB,uBAAuB;AAWvE,SAAS,2BAA2B,KAAW;AAC7C,YAAU,KAAK,mDAAmD;AAElE;AAAA,IACE,OAAO,GAAG;AAAA,IACV;AAAA,IACA,OAAO;AAAA,EACT;AAEA,QAAM,gBAAgB,IAAI,uBAAuB,kBAAkB;AAEnE,SAAO;AAAA,IACL,SAAS,cAAc;AAAA,IACvB,GACE,OACA,UACkB;AAClB,YAAM,UAAU,IAAI,iBAAiB,GAAG;AAMxC,cAAQ,QAAQ,EAAE,GAAG,cAAc,CAAC,EAAE,OAAO,MAAM;AACjD,sBAAc,cAAc,MAAM;AAAA,MACpC,CAAC;AAMD,cAAQ,QAAQ,EAAE,GAAG,OAAO,QAAQ;AAEpC,aAAO;AAAA,IACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWA,UAAU,MAA2B;AAInC,WAAK,gBAAgB,CAAC,GAAG,IAAI;AAAA,IAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAYA,gBACE,SAGA,MACM;AACN,YAAM,gBAAgB,MAAM,UACzB,OAAO,OAAO,EACd,IAAI,CAAC,WAAW,OAAO,EAAE;AAE5B,oBAAc,QAAQ,QAAQ,CAAC,gBAAgB;AAC7C,YAAI,CAAC,cAAc,SAAS,YAAY,EAAE,GAAG;AAC3C,sBAAY,KAAK,IAAI;AAAA,QACvB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,MAAM,KAAK;AAAA,EAChB,MAAM;AACR;","names":[]}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { SetupWorkerInternalContext } from '../setupWorker/glossary'
|
|
2
|
-
|
|
3
|
-
export async function requestIntegrityCheck(
|
|
4
|
-
context: SetupWorkerInternalContext,
|
|
5
|
-
serviceWorker: ServiceWorker,
|
|
6
|
-
): Promise<ServiceWorker> {
|
|
7
|
-
// Signal Service Worker to report back its integrity
|
|
8
|
-
context.workerChannel.send('INTEGRITY_CHECK_REQUEST')
|
|
9
|
-
|
|
10
|
-
const { payload: actualChecksum } = await context.events.once(
|
|
11
|
-
'INTEGRITY_CHECK_RESPONSE',
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
// Compare the response from the Service Worker and the
|
|
15
|
-
// global variable set during the build.
|
|
16
|
-
if (actualChecksum !== SERVICE_WORKER_CHECKSUM) {
|
|
17
|
-
throw new Error(
|
|
18
|
-
`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${SERVICE_WORKER_CHECKSUM}).`,
|
|
19
|
-
)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return serviceWorker
|
|
23
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { RequestHandler } from '../handlers/RequestHandler'
|
|
2
|
-
import {
|
|
3
|
-
WebSocketHandler,
|
|
4
|
-
kDefaultPrevented,
|
|
5
|
-
kDispatchEvent,
|
|
6
|
-
} from '../handlers/WebSocketHandler'
|
|
7
|
-
import { webSocketInterceptor } from '../ws/webSocketInterceptor'
|
|
8
|
-
|
|
9
|
-
export function handleWebSocketEvent(
|
|
10
|
-
getCurrentHandlers: () => Array<RequestHandler | WebSocketHandler>,
|
|
11
|
-
) {
|
|
12
|
-
webSocketInterceptor.on('connection', (connection) => {
|
|
13
|
-
const handlers = getCurrentHandlers()
|
|
14
|
-
|
|
15
|
-
const connectionEvent = new MessageEvent('connection', {
|
|
16
|
-
data: connection,
|
|
17
|
-
/**
|
|
18
|
-
* @note This message event should be marked as "cancelable"
|
|
19
|
-
* to have its default prevented using "event.preventDefault()".
|
|
20
|
-
* There's a bug in Node.js that breaks the "cancelable" flag.
|
|
21
|
-
* @see https://github.com/nodejs/node/issues/51767
|
|
22
|
-
*/
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
Object.defineProperty(connectionEvent, kDefaultPrevented, {
|
|
26
|
-
enumerable: false,
|
|
27
|
-
writable: true,
|
|
28
|
-
value: false,
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
// Iterate over the handlers and forward the connection
|
|
32
|
-
// event to WebSocket event handlers. This is equivalent
|
|
33
|
-
// to dispatching that event onto multiple listeners.
|
|
34
|
-
for (const handler of handlers) {
|
|
35
|
-
if (handler instanceof WebSocketHandler) {
|
|
36
|
-
handler[kDispatchEvent](connectionEvent)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// If none of the "ws" handlers matched,
|
|
41
|
-
// establish the WebSocket connection as-is.
|
|
42
|
-
if (!Reflect.get(connectionEvent, kDefaultPrevented)) {
|
|
43
|
-
connection.server.connect()
|
|
44
|
-
connection.client.addEventListener('message', (event) => {
|
|
45
|
-
connection.server.send(event.data)
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
}
|
|
File without changes
|