msw 2.3.0-ws.rc-2 → 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/lib/browser/index.js +1 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +1 -1
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-4DPdxG0R.d.mts → GraphQLHandler-CzcXr7At.d.mts} +1 -1
- package/lib/core/{GraphQLHandler-3gvpA65n.d.ts → GraphQLHandler-DGyzNtRQ.d.ts} +1 -1
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +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/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +3 -3
- package/lib/core/index.d.ts +3 -3
- package/lib/core/index.js +1 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +1 -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/handleRequest.d.mts +1 -1
- package/lib/core/utils/handleRequest.d.ts +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 → ws}/handleWebSocketEvent.d.mts +2 -2
- package/lib/core/{utils → ws}/handleWebSocketEvent.d.ts +2 -2
- package/lib/core/{utils → ws}/handleWebSocketEvent.js +1 -1
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -0
- package/lib/core/{utils → ws}/handleWebSocketEvent.mjs +1 -1
- package/lib/core/ws/handleWebSocketEvent.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 +8 -25
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.js +1 -1
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +1 -1
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.js +1 -1
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +1 -1
- package/lib/node/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/browser/setupWorker/setupWorker.ts +1 -1
- package/src/core/index.ts +1 -1
- package/src/core/{utils → ws}/handleWebSocketEvent.ts +1 -1
- package/src/core/{ws/ws.ts → ws.ts} +49 -35
- package/src/node/SetupServerCommonApi.ts +1 -1
- package/lib/core/utils/handleWebSocketEvent.js.map +0 -1
- package/lib/core/utils/handleWebSocketEvent.mjs.map +0 -1
- package/lib/core/ws/ws.js.map +0 -1
- package/lib/core/ws/ws.mjs.map +0 -1
- /package/lib/core/{HttpResponse-aJY-D0oG.d.ts → HttpResponse-BOzDwzB6.d.ts} +0 -0
- /package/lib/core/{HttpResponse-xuSipbNt.d.mts → HttpResponse-CSyJ1cbO.d.mts} +0 -0
- /package/src/core/{ws/ws.test.ts → ws.test.ts} +0 -0
|
@@ -2,15 +2,15 @@ import { invariant } from "outvariant";
|
|
|
2
2
|
import {
|
|
3
3
|
WebSocketHandler,
|
|
4
4
|
kEmitter
|
|
5
|
-
} from '
|
|
6
|
-
import { isPath } from '
|
|
7
|
-
import { WebSocketClientManager } from './WebSocketClientManager.mjs';
|
|
5
|
+
} from './handlers/WebSocketHandler.mjs';
|
|
6
|
+
import { isPath } from './utils/matching/matchRequestUrl.mjs';
|
|
7
|
+
import { WebSocketClientManager } from './ws/WebSocketClientManager.mjs';
|
|
8
8
|
const wsBroadcastChannel = new BroadcastChannel("msw:ws-client-manager");
|
|
9
9
|
function createWebSocketLinkHandler(url) {
|
|
10
10
|
invariant(url, "Expected a WebSocket server URL but got undefined");
|
|
11
11
|
invariant(
|
|
12
12
|
isPath(url),
|
|
13
|
-
"Expected a WebSocket server URL but got %s",
|
|
13
|
+
"Expected a WebSocket server URL to be a valid path but got %s",
|
|
14
14
|
typeof url
|
|
15
15
|
);
|
|
16
16
|
const clientManager = new WebSocketClientManager(wsBroadcastChannel);
|
|
@@ -24,28 +24,9 @@ function createWebSocketLinkHandler(url) {
|
|
|
24
24
|
handler[kEmitter].on(event, listener);
|
|
25
25
|
return handler;
|
|
26
26
|
},
|
|
27
|
-
/**
|
|
28
|
-
* Broadcasts the given data to all WebSocket clients.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* const service = ws.link('wss://example.com')
|
|
32
|
-
* service.on('connection', () => {
|
|
33
|
-
* service.broadcast('hello, everyone!')
|
|
34
|
-
* })
|
|
35
|
-
*/
|
|
36
27
|
broadcast(data) {
|
|
37
28
|
this.broadcastExcept([], data);
|
|
38
29
|
},
|
|
39
|
-
/**
|
|
40
|
-
* Broadcasts the given data to all WebSocket clients
|
|
41
|
-
* except the ones provided in the `clients` argument.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* const service = ws.link('wss://example.com')
|
|
45
|
-
* service.on('connection', ({ client }) => {
|
|
46
|
-
* service.broadcastExcept(client, 'hi, the rest of you!')
|
|
47
|
-
* })
|
|
48
|
-
*/
|
|
49
30
|
broadcastExcept(clients, data) {
|
|
50
31
|
const ignoreClients = Array.prototype.concat(clients).map((client) => client.id);
|
|
51
32
|
clientManager.clients.forEach((otherClient) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/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 './ws/WebSocketClientManager'\n\nconst wsBroadcastChannel = new BroadcastChannel('msw:ws-client-manager')\n\nexport type WebSocketLink = {\n /**\n * A set of all WebSocket clients connected\n * to this link.\n */\n clients: Set<WebSocketClientConnectionProtocol>\n\n on<EventType extends keyof WebSocketHandlerEventMap>(\n event: EventType,\n listener: (...args: WebSocketHandlerEventMap[EventType]) => void,\n ): WebSocketHandler\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\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}\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): WebSocketLink {\n invariant(url, 'Expected a WebSocket server URL but got undefined')\n\n invariant(\n isPath(url),\n 'Expected a WebSocket server URL to be a valid path but got %s',\n typeof url,\n )\n\n const clientManager = new WebSocketClientManager(wsBroadcastChannel)\n\n return {\n clients: clientManager.clients,\n on(event, listener) {\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 broadcast(data) {\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 broadcastExcept(clients, data) {\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;AAoDvE,SAAS,2BAA2B,KAA0B;AAC5D,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,GAAG,OAAO,UAAU;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,IAEA,UAAU,MAAM;AAId,WAAK,gBAAgB,CAAC,GAAG,IAAI;AAAA,IAC/B;AAAA,IAEA,gBAAgB,SAAS,MAAM;AAC7B,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/iife/index.js
CHANGED
|
@@ -1070,7 +1070,7 @@ var MockServiceWorker = (() => {
|
|
|
1070
1070
|
if (options === void 0) {
|
|
1071
1071
|
options = {};
|
|
1072
1072
|
}
|
|
1073
|
-
var _a2 = options.strict, strict = _a2 === void 0 ? false : _a2, _b2 = options.start, start = _b2 === void 0 ? true : _b2,
|
|
1073
|
+
var _a2 = options.strict, strict = _a2 === void 0 ? false : _a2, _b2 = options.start, start = _b2 === void 0 ? true : _b2, _c2 = options.end, end = _c2 === void 0 ? true : _c2, _d = options.encode, encode = _d === void 0 ? function(x) {
|
|
1074
1074
|
return x;
|
|
1075
1075
|
} : _d, _e = options.delimiter, delimiter = _e === void 0 ? "/#?" : _e, _f = options.endsWith, endsWith = _f === void 0 ? "" : _f;
|
|
1076
1076
|
var endsWithRe = "[".concat(escapeString(endsWith), "]|$");
|
|
@@ -4833,7 +4833,7 @@ spurious results.`);
|
|
|
4833
4833
|
}
|
|
4834
4834
|
}
|
|
4835
4835
|
|
|
4836
|
-
// node_modules/.pnpm/headers-polyfill@4.0.
|
|
4836
|
+
// node_modules/.pnpm/headers-polyfill@4.0.3/node_modules/headers-polyfill/lib/index.mjs
|
|
4837
4837
|
var __create4 = Object.create;
|
|
4838
4838
|
var __defProp6 = Object.defineProperty;
|
|
4839
4839
|
var __getOwnPropDesc5 = Object.getOwnPropertyDescriptor;
|
|
@@ -5109,10 +5109,12 @@ spurious results.`);
|
|
|
5109
5109
|
var HEADER_VALUE_DELIMITER = ", ";
|
|
5110
5110
|
var _a;
|
|
5111
5111
|
var _b;
|
|
5112
|
+
var _c;
|
|
5112
5113
|
var Headers2 = class _Headers {
|
|
5113
5114
|
constructor(init) {
|
|
5114
5115
|
this[_a] = {};
|
|
5115
5116
|
this[_b] = /* @__PURE__ */ new Map();
|
|
5117
|
+
this[_c] = "Headers";
|
|
5116
5118
|
if (["Headers", "HeadersPolyfill"].includes(init?.constructor.name) || init instanceof _Headers || typeof globalThis.Headers !== "undefined" && init instanceof globalThis.Headers) {
|
|
5117
5119
|
const initialHeaders = init;
|
|
5118
5120
|
initialHeaders.forEach((value, name) => {
|
|
@@ -5135,7 +5137,7 @@ spurious results.`);
|
|
|
5135
5137
|
});
|
|
5136
5138
|
}
|
|
5137
5139
|
}
|
|
5138
|
-
[(_a = NORMALIZED_HEADERS, _b = RAW_HEADER_NAMES, Symbol.iterator)]() {
|
|
5140
|
+
[(_a = NORMALIZED_HEADERS, _b = RAW_HEADER_NAMES, _c = Symbol.toStringTag, Symbol.iterator)]() {
|
|
5139
5141
|
return this.entries();
|
|
5140
5142
|
}
|
|
5141
5143
|
*keys() {
|
|
@@ -5757,13 +5759,13 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5757
5759
|
}
|
|
5758
5760
|
};
|
|
5759
5761
|
|
|
5760
|
-
// src/core/ws
|
|
5762
|
+
// src/core/ws.ts
|
|
5761
5763
|
var wsBroadcastChannel = new BroadcastChannel("msw:ws-client-manager");
|
|
5762
5764
|
function createWebSocketLinkHandler(url) {
|
|
5763
5765
|
invariant(url, "Expected a WebSocket server URL but got undefined");
|
|
5764
5766
|
invariant(
|
|
5765
5767
|
isPath(url),
|
|
5766
|
-
"Expected a WebSocket server URL but got %s",
|
|
5768
|
+
"Expected a WebSocket server URL to be a valid path but got %s",
|
|
5767
5769
|
typeof url
|
|
5768
5770
|
);
|
|
5769
5771
|
const clientManager = new WebSocketClientManager(wsBroadcastChannel);
|
|
@@ -5777,28 +5779,9 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5777
5779
|
handler[kEmitter].on(event, listener);
|
|
5778
5780
|
return handler;
|
|
5779
5781
|
},
|
|
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
5782
|
broadcast(data) {
|
|
5790
5783
|
this.broadcastExcept([], data);
|
|
5791
5784
|
},
|
|
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
5785
|
broadcastExcept(clients, data) {
|
|
5803
5786
|
const ignoreClients = Array.prototype.concat(clients).map((client) => client.id);
|
|
5804
5787
|
clientManager.clients.forEach((otherClient) => {
|
|
@@ -8192,7 +8175,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8192
8175
|
// src/core/ws/webSocketInterceptor.ts
|
|
8193
8176
|
var webSocketInterceptor = new WebSocketInterceptor();
|
|
8194
8177
|
|
|
8195
|
-
// src/core/
|
|
8178
|
+
// src/core/ws/handleWebSocketEvent.ts
|
|
8196
8179
|
function handleWebSocketEvent(options) {
|
|
8197
8180
|
webSocketInterceptor.on("connection", (connection) => {
|
|
8198
8181
|
const handlers = options.getHandlers();
|