msw 2.13.3 → 2.13.5
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 +1 -1
- package/lib/browser/index.js +200 -56
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +200 -56
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{HttpResponse-DlRR1D-f.d.mts → HttpResponse-BMMzfpjG.d.mts} +13 -0
- package/lib/core/{HttpResponse-CksOMVAa.d.ts → HttpResponse-DPDqE4Pb.d.ts} +13 -0
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/experimental/compat.d.mts +2 -2
- package/lib/core/experimental/compat.d.ts +2 -2
- package/lib/core/experimental/compat.js +1 -0
- package/lib/core/experimental/compat.js.map +1 -1
- package/lib/core/experimental/compat.mjs +1 -0
- package/lib/core/experimental/compat.mjs.map +1 -1
- package/lib/core/experimental/define-network.d.mts +2 -2
- package/lib/core/experimental/define-network.d.ts +2 -2
- package/lib/core/experimental/define-network.js +5 -5
- package/lib/core/experimental/define-network.js.map +1 -1
- package/lib/core/experimental/define-network.mjs +7 -5
- package/lib/core/experimental/define-network.mjs.map +1 -1
- package/lib/core/experimental/frames/http-frame.d.mts +2 -2
- package/lib/core/experimental/frames/http-frame.d.ts +2 -2
- package/lib/core/experimental/frames/http-frame.js +2 -0
- package/lib/core/experimental/frames/http-frame.js.map +1 -1
- package/lib/core/experimental/frames/http-frame.mjs +5 -1
- package/lib/core/experimental/frames/http-frame.mjs.map +1 -1
- package/lib/core/experimental/frames/network-frame.d.mts +2 -2
- package/lib/core/experimental/frames/network-frame.d.ts +2 -2
- package/lib/core/experimental/frames/websocket-frame.d.mts +2 -2
- package/lib/core/experimental/frames/websocket-frame.d.ts +2 -2
- package/lib/core/experimental/frames/websocket-frame.js +2 -0
- package/lib/core/experimental/frames/websocket-frame.js.map +1 -1
- package/lib/core/experimental/frames/websocket-frame.mjs +2 -0
- package/lib/core/experimental/frames/websocket-frame.mjs.map +1 -1
- package/lib/core/experimental/handlers-controller.d.mts +2 -1
- package/lib/core/experimental/handlers-controller.d.ts +2 -1
- package/lib/core/experimental/handlers-controller.js +15 -1
- package/lib/core/experimental/handlers-controller.js.map +1 -1
- package/lib/core/experimental/handlers-controller.mjs +15 -1
- package/lib/core/experimental/handlers-controller.mjs.map +1 -1
- package/lib/core/experimental/index.d.mts +2 -2
- package/lib/core/experimental/index.d.ts +2 -2
- package/lib/core/experimental/index.js +0 -1
- package/lib/core/experimental/index.js.map +1 -1
- package/lib/core/experimental/index.mjs +1 -2
- package/lib/core/experimental/index.mjs.map +1 -1
- package/lib/core/experimental/on-unhandled-frame.d.mts +2 -2
- package/lib/core/experimental/on-unhandled-frame.d.ts +2 -2
- package/lib/core/experimental/on-unhandled-frame.js +1 -0
- package/lib/core/experimental/on-unhandled-frame.js.map +1 -1
- package/lib/core/experimental/on-unhandled-frame.mjs +1 -0
- package/lib/core/experimental/on-unhandled-frame.mjs.map +1 -1
- package/lib/core/experimental/setup-api.d.mts +1 -1
- package/lib/core/experimental/setup-api.d.ts +1 -1
- package/lib/core/experimental/setup-api.js +2 -5
- package/lib/core/experimental/setup-api.js.map +1 -1
- package/lib/core/experimental/setup-api.mjs +2 -5
- package/lib/core/experimental/setup-api.mjs.map +1 -1
- package/lib/core/experimental/sources/interceptor-source.d.mts +2 -2
- package/lib/core/experimental/sources/interceptor-source.d.ts +2 -2
- package/lib/core/experimental/sources/interceptor-source.js.map +1 -1
- package/lib/core/experimental/sources/interceptor-source.mjs +1 -3
- package/lib/core/experimental/sources/interceptor-source.mjs.map +1 -1
- package/lib/core/experimental/sources/network-source.d.mts +2 -2
- package/lib/core/experimental/sources/network-source.d.ts +2 -2
- package/lib/core/experimental/sources/network-source.js +1 -0
- package/lib/core/experimental/sources/network-source.js.map +1 -1
- package/lib/core/experimental/sources/network-source.mjs +2 -0
- package/lib/core/experimental/sources/network-source.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 +1 -1
- package/lib/core/graphql.d.ts +1 -1
- package/lib/core/graphql.js +1 -0
- package/lib/core/graphql.js.map +1 -1
- package/lib/core/graphql.mjs +2 -0
- package/lib/core/graphql.mjs.map +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
- package/lib/core/handlers/GraphQLHandler.js +1 -0
- package/lib/core/handlers/GraphQLHandler.js.map +1 -1
- package/lib/core/handlers/GraphQLHandler.mjs +4 -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 -0
- package/lib/core/handlers/HttpHandler.js.map +1 -1
- package/lib/core/handlers/HttpHandler.mjs +1 -0
- 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/RequestHandler.js +26 -0
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs +27 -0
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/http.js +1 -0
- package/lib/core/http.js.map +1 -1
- package/lib/core/http.mjs +2 -0
- package/lib/core/http.mjs.map +1 -1
- package/lib/core/index.d.mts +1 -1
- package/lib/core/index.d.ts +1 -1
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/sse.d.mts +4 -18
- package/lib/core/sse.d.ts +4 -18
- package/lib/core/sse.js +105 -45
- package/lib/core/sse.js.map +1 -1
- package/lib/core/sse.mjs +105 -45
- package/lib/core/sse.mjs.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/cookieStore.js.map +1 -1
- package/lib/core/utils/cookieStore.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/executeHandlers.js +1 -0
- package/lib/core/utils/executeHandlers.js.map +1 -1
- package/lib/core/utils/executeHandlers.mjs +1 -0
- package/lib/core/utils/executeHandlers.mjs.map +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/isHandlerKind.d.mts +1 -1
- package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
- 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/parseMultipartData.js +1 -0
- package/lib/core/utils/internal/parseMultipartData.js.map +1 -1
- package/lib/core/utils/internal/parseMultipartData.mjs +1 -0
- package/lib/core/utils/internal/parseMultipartData.mjs.map +1 -1
- package/lib/core/utils/internal/pipeEvents.js +1 -0
- package/lib/core/utils/internal/pipeEvents.js.map +1 -1
- package/lib/core/utils/internal/pipeEvents.mjs +1 -0
- package/lib/core/utils/internal/pipeEvents.mjs.map +1 -1
- package/lib/core/ws/WebSocketClientManager.js.map +1 -1
- package/lib/core/ws/WebSocketClientManager.mjs.map +1 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.js +1 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +1 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -1
- package/lib/core/ws/WebSocketMemoryClientStore.js +1 -0
- package/lib/core/ws/WebSocketMemoryClientStore.js.map +1 -1
- package/lib/core/ws/WebSocketMemoryClientStore.mjs +1 -0
- package/lib/core/ws/WebSocketMemoryClientStore.mjs.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -1
- package/lib/core/ws.js.map +1 -1
- package/lib/core/ws.mjs.map +1 -1
- package/lib/iife/index.js +6316 -6063
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs.map +1 -1
- package/lib/shims/cookie.js +152 -62
- package/lib/shims/cookie.mjs +152 -62
- package/package.json +33 -40
- package/src/browser/glossary.ts +1 -1
- package/src/browser/setup-worker.ts +2 -2
- package/src/browser/sources/service-worker-source.ts +125 -28
- package/src/browser/utils/deserializeRequest.ts +2 -2
- package/src/browser/utils/pruneGetRequestBody.ts +3 -3
- package/src/browser/utils/should-invalidate-worker.test.ts +122 -0
- package/src/browser/utils/should-invalidate-worker.ts +13 -0
- package/src/browser/utils/workerChannel.ts +43 -21
- package/src/core/experimental/define-network.ts +14 -9
- package/src/core/experimental/frames/http-frame.test.ts +2 -1
- package/src/core/experimental/frames/http-frame.ts +6 -2
- package/src/core/experimental/frames/websocket-frame.test.ts +2 -4
- package/src/core/experimental/frames/websocket-frame.ts +3 -2
- package/src/core/experimental/handlers-controller.ts +15 -1
- package/src/core/experimental/index.ts +1 -1
- package/src/core/experimental/on-unhandled-frame.test.ts +2 -4
- package/src/core/experimental/setup-api.ts +4 -8
- package/src/core/experimental/sources/interceptor-source.ts +2 -6
- package/src/core/graphql.ts +8 -8
- package/src/core/handlers/GraphQLHandler.test.ts +3 -4
- package/src/core/handlers/GraphQLHandler.ts +15 -11
- package/src/core/handlers/HttpHandler.test.ts +3 -2
- package/src/core/handlers/HttpHandler.ts +7 -7
- package/src/core/handlers/RequestHandler.ts +33 -5
- package/src/core/http.ts +5 -5
- package/src/core/sse.ts +157 -56
- package/src/core/utils/cookieStore.ts +1 -1
- package/src/core/utils/executeHandlers.ts +2 -4
- package/src/core/utils/handleRequest.test.ts +5 -4
- package/src/core/utils/handleRequest.ts +3 -3
- package/src/core/utils/internal/parseGraphQLRequest.test.ts +2 -4
- package/src/core/utils/internal/parseMultipartData.ts +1 -1
- package/src/core/utils/internal/pipeEvents.ts +2 -1
- package/src/core/utils/request/onUnhandledRequest.test.ts +2 -4
- package/src/core/ws/WebSocketClientManager.test.ts +2 -4
- package/src/core/ws/WebSocketClientManager.ts +1 -1
- package/src/core/ws/WebSocketIndexedDBClientStore.ts +3 -5
- package/src/core/ws/WebSocketMemoryClientStore.ts +3 -5
- package/src/core/ws/handleWebSocketEvent.ts +3 -3
- package/src/core/ws.ts +1 -1
- package/src/native/index.ts +2 -2
- package/src/node/async-handlers-controller.ts +2 -2
- package/src/node/setup-server-common.ts +4 -4
- package/src/node/setup-server.ts +2 -2
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +0 -12
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +0 -12
- package/lib/core/utils/internal/requestHandlerUtils.js +0 -37
- package/lib/core/utils/internal/requestHandlerUtils.js.map +0 -1
- package/lib/core/utils/internal/requestHandlerUtils.mjs +0 -17
- package/lib/core/utils/internal/requestHandlerUtils.mjs.map +0 -1
- package/src/core/utils/internal/requestHandlerUtils.ts +0 -21
- package/lib/core/{network-frame-usYiHS0K.d.ts → on-unhandled-frame-BBR-P3kV.d.ts} +12 -12
- package/lib/core/{network-frame-B7A0ggXE.d.mts → on-unhandled-frame-Cr1KOZ0I.d.mts} +12 -12
|
@@ -200,6 +200,19 @@ declare abstract class RequestHandler<HandlerInfo extends RequestHandlerDefaultI
|
|
|
200
200
|
*/
|
|
201
201
|
isUsed: boolean;
|
|
202
202
|
constructor(args: RequestHandlerArgs<HandlerInfo, HandlerOptions>);
|
|
203
|
+
/**
|
|
204
|
+
* Reset the runtime state accumulated during response resolution,
|
|
205
|
+
* such as generator iterator progress. Called when this handler is
|
|
206
|
+
* removed from the active handlers list so re-adding it later starts
|
|
207
|
+
* from a clean state.
|
|
208
|
+
*/
|
|
209
|
+
protected reset(): void;
|
|
210
|
+
/**
|
|
211
|
+
* Restore this handler so it can match requests again after being
|
|
212
|
+
* exhausted (e.g. via `{ once: true }`). Also clears any accumulated
|
|
213
|
+
* resolution state.
|
|
214
|
+
*/
|
|
215
|
+
protected restore(): void;
|
|
203
216
|
/**
|
|
204
217
|
* Determine if the intercepted request should be mocked.
|
|
205
218
|
*/
|
|
@@ -200,6 +200,19 @@ declare abstract class RequestHandler<HandlerInfo extends RequestHandlerDefaultI
|
|
|
200
200
|
*/
|
|
201
201
|
isUsed: boolean;
|
|
202
202
|
constructor(args: RequestHandlerArgs<HandlerInfo, HandlerOptions>);
|
|
203
|
+
/**
|
|
204
|
+
* Reset the runtime state accumulated during response resolution,
|
|
205
|
+
* such as generator iterator progress. Called when this handler is
|
|
206
|
+
* removed from the active handlers list so re-adding it later starts
|
|
207
|
+
* from a clean state.
|
|
208
|
+
*/
|
|
209
|
+
protected reset(): void;
|
|
210
|
+
/**
|
|
211
|
+
* Restore this handler so it can match requests again after being
|
|
212
|
+
* exhausted (e.g. via `{ once: true }`). Also clears any accumulated
|
|
213
|
+
* resolution state.
|
|
214
|
+
*/
|
|
215
|
+
protected restore(): void;
|
|
203
216
|
/**
|
|
204
217
|
* Determine if the intercepted request should be mocked.
|
|
205
218
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@mswjs/interceptors';
|
|
2
|
-
export { Q as DefaultUnsafeFetchResponse, H as HttpResponse, n as HttpResponseInit, S as StrictRequest, o as StrictResponse, O as bodyType, T as kDefaultContentType } from './HttpResponse-
|
|
2
|
+
export { Q as DefaultUnsafeFetchResponse, H as HttpResponse, n as HttpResponseInit, S as StrictRequest, o as StrictResponse, O as bodyType, T as kDefaultContentType } from './HttpResponse-BMMzfpjG.mjs';
|
|
3
3
|
import './typeUtils.mjs';
|
|
4
4
|
import './utils/internal/isIterable.mjs';
|
|
5
5
|
import 'graphql';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@mswjs/interceptors';
|
|
2
|
-
export { Q as DefaultUnsafeFetchResponse, H as HttpResponse, n as HttpResponseInit, S as StrictRequest, o as StrictResponse, O as bodyType, T as kDefaultContentType } from './HttpResponse-
|
|
2
|
+
export { Q as DefaultUnsafeFetchResponse, H as HttpResponse, n as HttpResponseInit, S as StrictRequest, o as StrictResponse, O as bodyType, T as kDefaultContentType } from './HttpResponse-DPDqE4Pb.js';
|
|
3
3
|
import './typeUtils.js';
|
|
4
4
|
import './utils/internal/isIterable.js';
|
|
5
5
|
import 'graphql';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.mjs';
|
|
2
|
-
import { U as UnhandledFrameCallback } from '../
|
|
2
|
+
import { U as UnhandledFrameCallback } from '../on-unhandled-frame-Cr1KOZ0I.mjs';
|
|
3
3
|
import 'rettime';
|
|
4
4
|
import './handlers-controller.mjs';
|
|
5
|
-
import '../HttpResponse-
|
|
5
|
+
import '../HttpResponse-BMMzfpjG.mjs';
|
|
6
6
|
import '@mswjs/interceptors';
|
|
7
7
|
import '../utils/internal/isIterable.mjs';
|
|
8
8
|
import '../typeUtils.mjs';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.js';
|
|
2
|
-
import { U as UnhandledFrameCallback } from '../
|
|
2
|
+
import { U as UnhandledFrameCallback } from '../on-unhandled-frame-BBR-P3kV.js';
|
|
3
3
|
import 'rettime';
|
|
4
4
|
import './handlers-controller.js';
|
|
5
|
-
import '../HttpResponse-
|
|
5
|
+
import '../HttpResponse-DPDqE4Pb.js';
|
|
6
6
|
import '@mswjs/interceptors';
|
|
7
7
|
import '../utils/internal/isIterable.js';
|
|
8
8
|
import '../typeUtils.js';
|
|
@@ -22,6 +22,7 @@ __export(compat_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(compat_exports);
|
|
24
24
|
var import_outvariant = require("outvariant");
|
|
25
|
+
var import_onUnhandledRequest = require("../utils/request/onUnhandledRequest");
|
|
25
26
|
var import_on_unhandled_frame = require("./on-unhandled-frame");
|
|
26
27
|
var import_http_frame = require("./frames/http-frame");
|
|
27
28
|
var import_websocket_frame = require("./frames/websocket-frame");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/experimental/compat.ts"],"sourcesContent":["/**\n * Collection of helpers for bridging the compatibility between the old and the new APIs.\n */\nimport { invariant } from 'outvariant'\nimport { type UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest'\nimport {\n executeUnhandledFrameHandle,\n type UnhandledFrameCallback,\n} from './on-unhandled-frame'\nimport { HttpNetworkFrame } from './frames/http-frame'\nimport { WebSocketNetworkFrame } from './frames/websocket-frame'\n\nexport function fromLegacyOnUnhandledRequest(\n getLegacyValue: () => UnhandledRequestStrategy | undefined,\n): UnhandledFrameCallback {\n return ({ frame, defaults }) => {\n const legacyOnUnhandledRequestStrategy = getLegacyValue()\n\n if (legacyOnUnhandledRequestStrategy == null) {\n return\n }\n\n if (typeof legacyOnUnhandledRequestStrategy === 'function') {\n const request =\n frame instanceof HttpNetworkFrame\n ? frame.data.request\n : frame instanceof WebSocketNetworkFrame\n ? new Request(frame.data.connection.client.url, {\n headers: {\n connection: 'upgrade',\n upgrade: 'websocket',\n },\n })\n : null\n\n invariant(\n request != null,\n 'Failed to coerce a network frame to a legacy `onUnhandledRequest` strategy: unknown frame protocol \"%s\"',\n frame.protocol,\n )\n\n return legacyOnUnhandledRequestStrategy(request, {\n warning: defaults.warn,\n error: defaults.error,\n })\n }\n\n return executeUnhandledFrameHandle(frame, legacyOnUnhandledRequestStrategy)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAA0B;
|
|
1
|
+
{"version":3,"sources":["../../../src/core/experimental/compat.ts"],"sourcesContent":["/**\n * Collection of helpers for bridging the compatibility between the old and the new APIs.\n */\nimport { invariant } from 'outvariant'\nimport { type UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest'\nimport {\n executeUnhandledFrameHandle,\n type UnhandledFrameCallback,\n} from './on-unhandled-frame'\nimport { HttpNetworkFrame } from './frames/http-frame'\nimport { WebSocketNetworkFrame } from './frames/websocket-frame'\n\nexport function fromLegacyOnUnhandledRequest(\n getLegacyValue: () => UnhandledRequestStrategy | undefined,\n): UnhandledFrameCallback {\n return ({ frame, defaults }) => {\n const legacyOnUnhandledRequestStrategy = getLegacyValue()\n\n if (legacyOnUnhandledRequestStrategy == null) {\n return\n }\n\n if (typeof legacyOnUnhandledRequestStrategy === 'function') {\n const request =\n frame instanceof HttpNetworkFrame\n ? frame.data.request\n : frame instanceof WebSocketNetworkFrame\n ? new Request(frame.data.connection.client.url, {\n headers: {\n connection: 'upgrade',\n upgrade: 'websocket',\n },\n })\n : null\n\n invariant(\n request != null,\n 'Failed to coerce a network frame to a legacy `onUnhandledRequest` strategy: unknown frame protocol \"%s\"',\n frame.protocol,\n )\n\n return legacyOnUnhandledRequestStrategy(request, {\n warning: defaults.warn,\n error: defaults.error,\n })\n }\n\n return executeUnhandledFrameHandle(frame, legacyOnUnhandledRequestStrategy)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAA0B;AAC1B,gCAA8C;AAC9C,gCAGO;AACP,wBAAiC;AACjC,6BAAsC;AAE/B,SAAS,6BACd,gBACwB;AACxB,SAAO,CAAC,EAAE,OAAO,SAAS,MAAM;AAC9B,UAAM,mCAAmC,eAAe;AAExD,QAAI,oCAAoC,MAAM;AAC5C;AAAA,IACF;AAEA,QAAI,OAAO,qCAAqC,YAAY;AAC1D,YAAM,UACJ,iBAAiB,qCACb,MAAM,KAAK,UACX,iBAAiB,+CACf,IAAI,QAAQ,MAAM,KAAK,WAAW,OAAO,KAAK;AAAA,QAC5C,SAAS;AAAA,UACP,YAAY;AAAA,UACZ,SAAS;AAAA,QACX;AAAA,MACF,CAAC,IACD;AAER;AAAA,QACE,WAAW;AAAA,QACX;AAAA,QACA,MAAM;AAAA,MACR;AAEA,aAAO,iCAAiC,SAAS;AAAA,QAC/C,SAAS,SAAS;AAAA,QAClB,OAAO,SAAS;AAAA,MAClB,CAAC;AAAA,IACH;AAEA,eAAO,uDAA4B,OAAO,gCAAgC;AAAA,EAC5E;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/experimental/compat.ts"],"sourcesContent":["/**\n * Collection of helpers for bridging the compatibility between the old and the new APIs.\n */\nimport { invariant } from 'outvariant'\nimport { type UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest'\nimport {\n executeUnhandledFrameHandle,\n type UnhandledFrameCallback,\n} from './on-unhandled-frame'\nimport { HttpNetworkFrame } from './frames/http-frame'\nimport { WebSocketNetworkFrame } from './frames/websocket-frame'\n\nexport function fromLegacyOnUnhandledRequest(\n getLegacyValue: () => UnhandledRequestStrategy | undefined,\n): UnhandledFrameCallback {\n return ({ frame, defaults }) => {\n const legacyOnUnhandledRequestStrategy = getLegacyValue()\n\n if (legacyOnUnhandledRequestStrategy == null) {\n return\n }\n\n if (typeof legacyOnUnhandledRequestStrategy === 'function') {\n const request =\n frame instanceof HttpNetworkFrame\n ? frame.data.request\n : frame instanceof WebSocketNetworkFrame\n ? new Request(frame.data.connection.client.url, {\n headers: {\n connection: 'upgrade',\n upgrade: 'websocket',\n },\n })\n : null\n\n invariant(\n request != null,\n 'Failed to coerce a network frame to a legacy `onUnhandledRequest` strategy: unknown frame protocol \"%s\"',\n frame.protocol,\n )\n\n return legacyOnUnhandledRequestStrategy(request, {\n warning: defaults.warn,\n error: defaults.error,\n })\n }\n\n return executeUnhandledFrameHandle(frame, legacyOnUnhandledRequestStrategy)\n }\n}\n"],"mappings":"AAGA,SAAS,iBAAiB;
|
|
1
|
+
{"version":3,"sources":["../../../src/core/experimental/compat.ts"],"sourcesContent":["/**\n * Collection of helpers for bridging the compatibility between the old and the new APIs.\n */\nimport { invariant } from 'outvariant'\nimport { type UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest'\nimport {\n executeUnhandledFrameHandle,\n type UnhandledFrameCallback,\n} from './on-unhandled-frame'\nimport { HttpNetworkFrame } from './frames/http-frame'\nimport { WebSocketNetworkFrame } from './frames/websocket-frame'\n\nexport function fromLegacyOnUnhandledRequest(\n getLegacyValue: () => UnhandledRequestStrategy | undefined,\n): UnhandledFrameCallback {\n return ({ frame, defaults }) => {\n const legacyOnUnhandledRequestStrategy = getLegacyValue()\n\n if (legacyOnUnhandledRequestStrategy == null) {\n return\n }\n\n if (typeof legacyOnUnhandledRequestStrategy === 'function') {\n const request =\n frame instanceof HttpNetworkFrame\n ? frame.data.request\n : frame instanceof WebSocketNetworkFrame\n ? new Request(frame.data.connection.client.url, {\n headers: {\n connection: 'upgrade',\n upgrade: 'websocket',\n },\n })\n : null\n\n invariant(\n request != null,\n 'Failed to coerce a network frame to a legacy `onUnhandledRequest` strategy: unknown frame protocol \"%s\"',\n frame.protocol,\n )\n\n return legacyOnUnhandledRequestStrategy(request, {\n warning: defaults.warn,\n error: defaults.error,\n })\n }\n\n return executeUnhandledFrameHandle(frame, legacyOnUnhandledRequestStrategy)\n }\n}\n"],"mappings":"AAGA,SAAS,iBAAiB;AAC1B,eAA8C;AAC9C;AAAA,EACE;AAAA,OAEK;AACP,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AAE/B,SAAS,6BACd,gBACwB;AACxB,SAAO,CAAC,EAAE,OAAO,SAAS,MAAM;AAC9B,UAAM,mCAAmC,eAAe;AAExD,QAAI,oCAAoC,MAAM;AAC5C;AAAA,IACF;AAEA,QAAI,OAAO,qCAAqC,YAAY;AAC1D,YAAM,UACJ,iBAAiB,mBACb,MAAM,KAAK,UACX,iBAAiB,wBACf,IAAI,QAAQ,MAAM,KAAK,WAAW,OAAO,KAAK;AAAA,QAC5C,SAAS;AAAA,UACP,YAAY;AAAA,UACZ,SAAS;AAAA,QACX;AAAA,MACF,CAAC,IACD;AAER;AAAA,QACE,WAAW;AAAA,QACX;AAAA,QACA,MAAM;AAAA,MACR;AAEA,aAAO,iCAAiC,SAAS;AAAA,QAC/C,SAAS,SAAS;AAAA,QAClB,OAAO,SAAS;AAAA,MAClB,CAAC;AAAA,IACH;AAEA,WAAO,4BAA4B,OAAO,gCAAgC;AAAA,EAC5E;AACF;","names":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Emitter, DefaultEventMap } from 'rettime';
|
|
2
2
|
import { NetworkSource, ExtractSourceEvents } from './sources/network-source.mjs';
|
|
3
|
-
import { a as NetworkFrameResolutionContext, b as UnhandledFrameHandle } from '../
|
|
3
|
+
import { a as NetworkFrameResolutionContext, b as UnhandledFrameHandle } from '../on-unhandled-frame-Cr1KOZ0I.mjs';
|
|
4
4
|
import { AnyHandler, HandlersController } from './handlers-controller.mjs';
|
|
5
|
-
import '../HttpResponse-
|
|
5
|
+
import '../HttpResponse-BMMzfpjG.mjs';
|
|
6
6
|
import '@mswjs/interceptors';
|
|
7
7
|
import '../utils/internal/isIterable.mjs';
|
|
8
8
|
import '../typeUtils.mjs';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Emitter, DefaultEventMap } from 'rettime';
|
|
2
2
|
import { NetworkSource, ExtractSourceEvents } from './sources/network-source.js';
|
|
3
|
-
import { a as NetworkFrameResolutionContext, b as UnhandledFrameHandle } from '../
|
|
3
|
+
import { a as NetworkFrameResolutionContext, b as UnhandledFrameHandle } from '../on-unhandled-frame-BBR-P3kV.js';
|
|
4
4
|
import { AnyHandler, HandlersController } from './handlers-controller.js';
|
|
5
|
-
import '../HttpResponse-
|
|
5
|
+
import '../HttpResponse-DPDqE4Pb.js';
|
|
6
6
|
import '@mswjs/interceptors';
|
|
7
7
|
import '../utils/internal/isIterable.js';
|
|
8
8
|
import '../typeUtils.js';
|
|
@@ -24,6 +24,9 @@ __export(define_network_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(define_network_exports);
|
|
25
25
|
var import_outvariant = require("outvariant");
|
|
26
26
|
var import_rettime = require("rettime");
|
|
27
|
+
var import_network_source = require("./sources/network-source");
|
|
28
|
+
var import_network_frame = require("./frames/network-frame");
|
|
29
|
+
var import_on_unhandled_frame = require("./on-unhandled-frame");
|
|
27
30
|
var import_handlers_controller = require("./handlers-controller");
|
|
28
31
|
var import_toReadonlyArray = require("../utils/internal/toReadonlyArray");
|
|
29
32
|
function colorlessPromiseAll(values) {
|
|
@@ -77,6 +80,7 @@ function defineNetwork(options) {
|
|
|
77
80
|
listenersController = new AbortController();
|
|
78
81
|
readyState = 1 /* ENABLED */;
|
|
79
82
|
const result = resolvedOptions.sources.map((source) => {
|
|
83
|
+
import_network_source.NetworkSource.prototype.disable.call(source);
|
|
80
84
|
source.on("frame", async ({ frame }) => {
|
|
81
85
|
frame.events.on("*", (event) => events.emit(event), {
|
|
82
86
|
signal: listenersController.signal
|
|
@@ -110,11 +114,7 @@ function defineNetwork(options) {
|
|
|
110
114
|
handlersController.reset(handlers);
|
|
111
115
|
},
|
|
112
116
|
restoreHandlers() {
|
|
113
|
-
|
|
114
|
-
if ("isUsed" in handler) {
|
|
115
|
-
handler.isUsed = false;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
117
|
+
handlersController.restore();
|
|
118
118
|
},
|
|
119
119
|
listHandlers() {
|
|
120
120
|
return (0, import_toReadonlyArray.toReadonlyArray)(handlersController.currentHandlers());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/experimental/define-network.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { Emitter, type DefaultEventMap } from 'rettime'\nimport {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/core/experimental/define-network.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { Emitter, type DefaultEventMap } from 'rettime'\nimport {\n NetworkSource,\n type ExtractSourceEvents,\n} from './sources/network-source'\nimport { type NetworkFrameResolutionContext } from './frames/network-frame'\nimport { type UnhandledFrameHandle } from './on-unhandled-frame'\nimport {\n HandlersController,\n InMemoryHandlersController,\n type AnyHandler,\n} from './handlers-controller'\nimport { toReadonlyArray } from '../utils/internal/toReadonlyArray'\n\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (\n k: infer I,\n) => void\n ? I\n : never\n\ntype MergeEventMaps<Sources extends Array<NetworkSource<any>>> =\n UnionToIntersection<ExtractSourceEvents<Sources[number]>> extends infer R\n ? R extends Record<string, any>\n ? R\n : DefaultEventMap\n : DefaultEventMap\n\ntype MaybePromise<T> =\n Extract<T, Promise<unknown>> extends never ? void : Promise<void>\n\nexport interface DefineNetworkOptions<\n Sources extends Array<NetworkSource<any>>,\n> {\n /**\n * List of the network sources.\n * Every network source emits frames, and every frame describes how\n * to handle the various network scenarios, like mocking a response,\n * erroring the request, or performing it as-is.\n */\n sources: Sources\n /**\n * List of handlers to describe the network.\n */\n handlers?: Array<AnyHandler> | HandlersController\n context?: NetworkFrameResolutionContext\n onUnhandledFrame?: UnhandledFrameHandle\n}\n\nexport interface NetworkApi<\n Sources extends Array<NetworkSource<any>>,\n> extends NetworkHandlersApi {\n readyState: NetworkReadyState\n /**\n * Enable the network interception and handling.\n */\n enable: () => MaybePromise<ReturnType<Sources[number]['enable']>>\n /**\n * Disable the network interception and handling.\n */\n disable: () => MaybePromise<ReturnType<Sources[number]['disable']>>\n /**\n * Configure the network instance with additional options.\n * The options provided in the `.configure()` call will override the same\n * options in the `defineNetwork()` call.\n */\n configure: (options: Partial<DefineNetworkOptions<Sources>>) => void\n events: Emitter<MergeEventMaps<Sources>>\n}\n\nexport interface NetworkHandlersApi {\n use: (...handlers: Array<AnyHandler>) => void\n resetHandlers: (...handlers: Array<AnyHandler>) => void\n restoreHandlers: () => void\n listHandlers: () => ReadonlyArray<AnyHandler>\n}\n\nfunction colorlessPromiseAll<T>(values: Array<T>): MaybePromise<T>\nfunction colorlessPromiseAll(values: Array<unknown>): Promise<void> | void {\n const promises: Array<Promise<void>> = []\n\n for (const value of values) {\n if (value instanceof Promise) {\n promises.push(value)\n }\n }\n\n if (promises.length > 0) {\n return Promise.all(promises).then(() => {})\n }\n}\n\nexport enum NetworkReadyState {\n DISABLED,\n ENABLED,\n}\n\n/**\n * Define a network instance with the given configuration.\n * @example\n * import { InterceptorSource } from 'msw/experimental'\n * import { handlers } from './handlers'\n *\n * const network = defineNetwork({\n * sources: [new InterceptorSource({ interceptors })],\n * handlers,\n * })\n * await network.enable()\n */\nexport function defineNetwork<Sources extends Array<NetworkSource<any>>>(\n options: DefineNetworkOptions<Sources>,\n): NetworkApi<Sources> {\n let readyState: NetworkReadyState = NetworkReadyState.DISABLED\n const events = new Emitter<MergeEventMaps<Sources>>()\n\n const deriveHandlersController = (\n handlers: DefineNetworkOptions<Sources>['handlers'],\n ) => {\n return handlers instanceof HandlersController\n ? handlers\n : new InMemoryHandlersController(handlers || [])\n }\n\n let resolvedOptions: DefineNetworkOptions<Sources> = {\n ...options,\n }\n\n /**\n * @note Create the handlers controller immediately because\n * certain setup APIs, like `setupServer`, don't await `.enable` (`.listen`).\n */\n let handlersController = deriveHandlersController(resolvedOptions.handlers)\n let listenersController: AbortController\n\n return {\n get readyState() {\n return readyState\n },\n events,\n configure(options) {\n invariant(readyState === NetworkReadyState.DISABLED, '')\n\n if (\n options.handlers &&\n !Object.is(options.handlers, resolvedOptions.handlers)\n ) {\n handlersController = deriveHandlersController(options.handlers)\n }\n\n resolvedOptions = {\n ...resolvedOptions,\n ...options,\n }\n },\n enable() {\n invariant(\n readyState === NetworkReadyState.DISABLED,\n 'Failed to call \"enable\" on the network: already enabled',\n )\n\n listenersController = new AbortController()\n readyState = NetworkReadyState.ENABLED\n\n const result = resolvedOptions.sources.map((source) => {\n /**\n * @note Preemptively disable the network source before enabling.\n * This intentionally calls only the prototype method that clears the\n * event listeners and nothing else. This prevents the \"frame\" listeners\n * from accumulating across enable/disable in case the source is a singleton.\n */\n NetworkSource.prototype.disable.call(source)\n\n source.on('frame', async ({ frame }) => {\n frame.events.on('*', (event) => events.emit(event), {\n signal: listenersController.signal,\n })\n\n const handlers = frame.getHandlers(handlersController)\n\n await frame.resolve(\n handlers,\n resolvedOptions.onUnhandledFrame || 'warn',\n resolvedOptions.context,\n )\n })\n\n return source.enable()\n })\n\n return colorlessPromiseAll(result) as MaybePromise<\n ReturnType<Sources[number]['enable']>\n >\n },\n disable() {\n invariant(\n readyState === NetworkReadyState.ENABLED,\n 'Failed to call \"disable\" on the network: already disabled',\n )\n\n listenersController.abort()\n readyState = NetworkReadyState.DISABLED\n\n return colorlessPromiseAll(\n resolvedOptions.sources.map((source) => source.disable()),\n ) as MaybePromise<ReturnType<Sources[number]['disable']>>\n },\n use(...handlers) {\n handlersController.use(handlers)\n },\n resetHandlers(...handlers) {\n handlersController.reset(handlers)\n },\n restoreHandlers() {\n handlersController.restore()\n },\n listHandlers() {\n return toReadonlyArray(handlersController.currentHandlers())\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA0B;AAC1B,qBAA8C;AAC9C,4BAGO;AACP,2BAAmD;AACnD,gCAA0C;AAC1C,iCAIO;AACP,6BAAgC;AAiEhC,SAAS,oBAAoB,QAA8C;AACzE,QAAM,WAAiC,CAAC;AAExC,aAAW,SAAS,QAAQ;AAC1B,QAAI,iBAAiB,SAAS;AAC5B,eAAS,KAAK,KAAK;AAAA,IACrB;AAAA,EACF;AAEA,MA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AAM,MAAM;AAAA,YACV;AAAA,YACA,gBAAgB,oBAAoB;AAAA,YACpC,gBAAgB;AAAA,UAClB;AAAA,QACF,CAAC;AAED,eAAO,OAAO,OAAO;AAAA,MACvB,CAAC;AAED,aAAO,oBAAoB,MAAM;AAAA,IAGnC;AAAA,IACA,UAAU;AACR;AAAA,QACE,eAAe;AAAA,QACf;AAAA,MACF;AAEA,0BAAoB,MAAM;AAC1B,mBAAa;AAEb,aAAO;AAAA,QACL,gBAAgB,QAAQ,IAAI,CAAC,WAAW,OAAO,QAAQ,CAAC;AAAA,MAC1D;AAAA,IACF;AAAA,IACA,OAAO,UAAU;AACf,yBAAmB,IAAI,QAAQ;AAAA,IACjC;AAAA,IACA,iBAAiB,UAAU;AACzB,yBAAmB,MAAM,QAAQ;AAAA,IACnC;AAAA,IACA,kBAAkB;AAChB,yBAAmB,QAAQ;AAAA,IAC7B;AAAA,IACA,eAAe;AACb,iBAAO,wCAAgB,mBAAmB,gBAAgB,CAAC;AAAA,IAC7D;AAAA,EACF;AACF;","names":["NetworkReadyState","options"]}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { invariant } from "outvariant";
|
|
2
2
|
import { Emitter } from "rettime";
|
|
3
|
+
import {
|
|
4
|
+
NetworkSource
|
|
5
|
+
} from './sources/network-source.mjs';
|
|
6
|
+
import {} from './frames/network-frame.mjs';
|
|
7
|
+
import {} from './on-unhandled-frame.mjs';
|
|
3
8
|
import {
|
|
4
9
|
HandlersController,
|
|
5
10
|
InMemoryHandlersController
|
|
@@ -56,6 +61,7 @@ function defineNetwork(options) {
|
|
|
56
61
|
listenersController = new AbortController();
|
|
57
62
|
readyState = 1 /* ENABLED */;
|
|
58
63
|
const result = resolvedOptions.sources.map((source) => {
|
|
64
|
+
NetworkSource.prototype.disable.call(source);
|
|
59
65
|
source.on("frame", async ({ frame }) => {
|
|
60
66
|
frame.events.on("*", (event) => events.emit(event), {
|
|
61
67
|
signal: listenersController.signal
|
|
@@ -89,11 +95,7 @@ function defineNetwork(options) {
|
|
|
89
95
|
handlersController.reset(handlers);
|
|
90
96
|
},
|
|
91
97
|
restoreHandlers() {
|
|
92
|
-
|
|
93
|
-
if ("isUsed" in handler) {
|
|
94
|
-
handler.isUsed = false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
98
|
+
handlersController.restore();
|
|
97
99
|
},
|
|
98
100
|
listHandlers() {
|
|
99
101
|
return toReadonlyArray(handlersController.currentHandlers());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/experimental/define-network.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { Emitter, type DefaultEventMap } from 'rettime'\nimport {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/core/experimental/define-network.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { Emitter, type DefaultEventMap } from 'rettime'\nimport {\n NetworkSource,\n type ExtractSourceEvents,\n} from './sources/network-source'\nimport { type NetworkFrameResolutionContext } from './frames/network-frame'\nimport { type UnhandledFrameHandle } from './on-unhandled-frame'\nimport {\n HandlersController,\n InMemoryHandlersController,\n type AnyHandler,\n} from './handlers-controller'\nimport { toReadonlyArray } from '../utils/internal/toReadonlyArray'\n\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (\n k: infer I,\n) => void\n ? I\n : never\n\ntype MergeEventMaps<Sources extends Array<NetworkSource<any>>> =\n UnionToIntersection<ExtractSourceEvents<Sources[number]>> extends infer R\n ? R extends Record<string, any>\n ? R\n : DefaultEventMap\n : DefaultEventMap\n\ntype MaybePromise<T> =\n Extract<T, Promise<unknown>> extends never ? void : Promise<void>\n\nexport interface DefineNetworkOptions<\n Sources extends Array<NetworkSource<any>>,\n> {\n /**\n * List of the network sources.\n * Every network source emits frames, and every frame describes how\n * to handle the various network scenarios, like mocking a response,\n * erroring the request, or performing it as-is.\n */\n sources: Sources\n /**\n * List of handlers to describe the network.\n */\n handlers?: Array<AnyHandler> | HandlersController\n context?: NetworkFrameResolutionContext\n onUnhandledFrame?: UnhandledFrameHandle\n}\n\nexport interface NetworkApi<\n Sources extends Array<NetworkSource<any>>,\n> extends NetworkHandlersApi {\n readyState: NetworkReadyState\n /**\n * Enable the network interception and handling.\n */\n enable: () => MaybePromise<ReturnType<Sources[number]['enable']>>\n /**\n * Disable the network interception and handling.\n */\n disable: () => MaybePromise<ReturnType<Sources[number]['disable']>>\n /**\n * Configure the network instance with additional options.\n * The options provided in the `.configure()` call will override the same\n * options in the `defineNetwork()` call.\n */\n configure: (options: Partial<DefineNetworkOptions<Sources>>) => void\n events: Emitter<MergeEventMaps<Sources>>\n}\n\nexport interface NetworkHandlersApi {\n use: (...handlers: Array<AnyHandler>) => void\n resetHandlers: (...handlers: Array<AnyHandler>) => void\n restoreHandlers: () => void\n listHandlers: () => ReadonlyArray<AnyHandler>\n}\n\nfunction colorlessPromiseAll<T>(values: Array<T>): MaybePromise<T>\nfunction colorlessPromiseAll(values: Array<unknown>): Promise<void> | void {\n const promises: Array<Promise<void>> = []\n\n for (const value of values) {\n if (value instanceof Promise) {\n promises.push(value)\n }\n }\n\n if (promises.length > 0) {\n return Promise.all(promises).then(() => {})\n }\n}\n\nexport enum NetworkReadyState {\n DISABLED,\n ENABLED,\n}\n\n/**\n * Define a network instance with the given configuration.\n * @example\n * import { InterceptorSource } from 'msw/experimental'\n * import { handlers } from './handlers'\n *\n * const network = defineNetwork({\n * sources: [new InterceptorSource({ interceptors })],\n * handlers,\n * })\n * await network.enable()\n */\nexport function defineNetwork<Sources extends Array<NetworkSource<any>>>(\n options: DefineNetworkOptions<Sources>,\n): NetworkApi<Sources> {\n let readyState: NetworkReadyState = NetworkReadyState.DISABLED\n const events = new Emitter<MergeEventMaps<Sources>>()\n\n const deriveHandlersController = (\n handlers: DefineNetworkOptions<Sources>['handlers'],\n ) => {\n return handlers instanceof HandlersController\n ? handlers\n : new InMemoryHandlersController(handlers || [])\n }\n\n let resolvedOptions: DefineNetworkOptions<Sources> = {\n ...options,\n }\n\n /**\n * @note Create the handlers controller immediately because\n * certain setup APIs, like `setupServer`, don't await `.enable` (`.listen`).\n */\n let handlersController = deriveHandlersController(resolvedOptions.handlers)\n let listenersController: AbortController\n\n return {\n get readyState() {\n return readyState\n },\n events,\n configure(options) {\n invariant(readyState === NetworkReadyState.DISABLED, '')\n\n if (\n options.handlers &&\n !Object.is(options.handlers, resolvedOptions.handlers)\n ) {\n handlersController = deriveHandlersController(options.handlers)\n }\n\n resolvedOptions = {\n ...resolvedOptions,\n ...options,\n }\n },\n enable() {\n invariant(\n readyState === NetworkReadyState.DISABLED,\n 'Failed to call \"enable\" on the network: already enabled',\n )\n\n listenersController = new AbortController()\n readyState = NetworkReadyState.ENABLED\n\n const result = resolvedOptions.sources.map((source) => {\n /**\n * @note Preemptively disable the network source before enabling.\n * This intentionally calls only the prototype method that clears the\n * event listeners and nothing else. This prevents the \"frame\" listeners\n * from accumulating across enable/disable in case the source is a singleton.\n */\n NetworkSource.prototype.disable.call(source)\n\n source.on('frame', async ({ frame }) => {\n frame.events.on('*', (event) => events.emit(event), {\n signal: listenersController.signal,\n })\n\n const handlers = frame.getHandlers(handlersController)\n\n await frame.resolve(\n handlers,\n resolvedOptions.onUnhandledFrame || 'warn',\n resolvedOptions.context,\n )\n })\n\n return source.enable()\n })\n\n return colorlessPromiseAll(result) as MaybePromise<\n ReturnType<Sources[number]['enable']>\n >\n },\n disable() {\n invariant(\n readyState === NetworkReadyState.ENABLED,\n 'Failed to call \"disable\" on the network: already disabled',\n )\n\n listenersController.abort()\n readyState = NetworkReadyState.DISABLED\n\n return colorlessPromiseAll(\n resolvedOptions.sources.map((source) => source.disable()),\n ) as MaybePromise<ReturnType<Sources[number]['disable']>>\n },\n use(...handlers) {\n handlersController.use(handlers)\n },\n resetHandlers(...handlers) {\n handlersController.reset(handlers)\n },\n restoreHandlers() {\n handlersController.restore()\n },\n listHandlers() {\n return toReadonlyArray(handlersController.currentHandlers())\n },\n }\n}\n"],"mappings":"AAAA,SAAS,iBA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a;AAEb,YAAM,SAAS,gBAAgB,QAAQ,IAAI,CAAC,WAAW;AAOrD,sBAAc,UAAU,QAAQ,KAAK,MAAM;AAE3C,eAAO,GAAG,SAAS,OAAO,EAAE,MAAM,MAAM;AACtC,gBAAM,OAAO,GAAG,KAAK,CAAC,UAAU,OAAO,KAAK,KAAK,GAAG;AAAA,YAClD,QAAQ,oBAAoB;AAAA,UAC9B,CAAC;AAED,gBAAM,WAAW,MAAM,YAAY,kBAAkB;AAErD,gBAAM,MAAM;AAAA,YACV;AAAA,YACA,gBAAgB,oBAAoB;AAAA,YACpC,gBAAgB;AAAA,UAClB;AAAA,QACF,CAAC;AAED,eAAO,OAAO,OAAO;AAAA,MACvB,CAAC;AAED,aAAO,oBAAoB,MAAM;AAAA,IAGnC;AAAA,IACA,UAAU;AACR;AAAA,QACE,eAAe;AAAA,QACf;AAAA,MACF;AAEA,0BAAoB,MAAM;AAC1B,mBAAa;AAEb,aAAO;AAAA,QACL,gBAAgB,QAAQ,IAAI,CAAC,WAAW,OAAO,QAAQ,CAAC;AAAA,MAC1D;AAAA,IACF;AAAA,IACA,OAAO,UAAU;AACf,yBAAmB,IAAI,QAAQ;AAAA,IACjC;AAAA,IACA,iBAAiB,UAAU;AACzB,yBAAmB,MAAM,QAAQ;AAAA,IACnC;AAAA,IACA,kBAAkB;AAChB,yBAAmB,QAAQ;AAAA,IAC7B;AAAA,IACA,eAAe;AACb,aAAO,gBAAgB,mBAAmB,gBAAgB,CAAC;AAAA,IAC7D;AAAA,EACF;AACF;","names":["NetworkReadyState","options"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TypedEvent } from 'rettime';
|
|
2
|
-
import { N as NetworkFrame, b as UnhandledFrameHandle, a as NetworkFrameResolutionContext } from '../../
|
|
2
|
+
import { N as NetworkFrame, b as UnhandledFrameHandle, a as NetworkFrameResolutionContext } from '../../on-unhandled-frame-Cr1KOZ0I.mjs';
|
|
3
3
|
import { HandlersController, AnyHandler } from '../handlers-controller.mjs';
|
|
4
|
-
import { R as RequestHandler } from '../../HttpResponse-
|
|
4
|
+
import { R as RequestHandler } from '../../HttpResponse-BMMzfpjG.mjs';
|
|
5
5
|
import '../../handlers/WebSocketHandler.mjs';
|
|
6
6
|
import 'strict-event-emitter';
|
|
7
7
|
import '@mswjs/interceptors/WebSocket';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TypedEvent } from 'rettime';
|
|
2
|
-
import { N as NetworkFrame, b as UnhandledFrameHandle, a as NetworkFrameResolutionContext } from '../../
|
|
2
|
+
import { N as NetworkFrame, b as UnhandledFrameHandle, a as NetworkFrameResolutionContext } from '../../on-unhandled-frame-BBR-P3kV.js';
|
|
3
3
|
import { HandlersController, AnyHandler } from '../handlers-controller.js';
|
|
4
|
-
import { R as RequestHandler } from '../../HttpResponse-
|
|
4
|
+
import { R as RequestHandler } from '../../HttpResponse-DPDqE4Pb.js';
|
|
5
5
|
import '../../handlers/WebSocketHandler.js';
|
|
6
6
|
import 'strict-event-emitter';
|
|
7
7
|
import '@mswjs/interceptors/WebSocket';
|
|
@@ -34,6 +34,8 @@ var import_storeResponseCookies = require("../../utils/request/storeResponseCook
|
|
|
34
34
|
var import_request_utils = require("../request-utils");
|
|
35
35
|
var import_devUtils = require("../../utils/internal/devUtils");
|
|
36
36
|
var import_on_unhandled_frame = require("../on-unhandled-frame");
|
|
37
|
+
var import_handlers_controller = require("../handlers-controller");
|
|
38
|
+
var import_RequestHandler = require("../../handlers/RequestHandler");
|
|
37
39
|
class RequestEvent extends import_rettime.TypedEvent {
|
|
38
40
|
requestId;
|
|
39
41
|
request;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/experimental/frames/http-frame.ts"],"sourcesContent":["import { TypedEvent } from 'rettime'\nimport { until } from 'until-async'\nimport { createRequestId } from '@mswjs/interceptors'\nimport { NetworkFrame, NetworkFrameResolutionContext } from './network-frame'\nimport { toPublicUrl } from '../../utils/request/toPublicUrl'\nimport { executeHandlers } from '../../utils/executeHandlers'\nimport { storeResponseCookies } from '../../utils/request/storeResponseCookies'\nimport { isPassthroughResponse, shouldBypassRequest } from '../request-utils'\nimport { devUtils } from '../../utils/internal/devUtils'\nimport {\n executeUnhandledFrameHandle,\n type UnhandledFrameHandle,\n} from '../on-unhandled-frame'\nimport { HandlersController, AnyHandler } from '../handlers-controller'\nimport { type RequestHandler } from '../../handlers/RequestHandler'\n\ninterface HttpNetworkFrameOptions {\n id?: string\n request: Request\n}\n\nexport class RequestEvent<\n DataType extends { requestId: string; request: Request } = {\n requestId: string\n request: Request\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly requestId: string\n public readonly request: Request\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.requestId = data.requestId\n this.request = data.request\n }\n}\n\nexport class ResponseEvent<\n DataType extends {\n requestId: string\n request: Request\n response: Response\n } = {\n requestId: string\n request: Request\n response: Response\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly requestId: string\n public readonly request: Request\n public readonly response: Response\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.requestId = data.requestId\n this.request = data.request\n this.response = data.response\n }\n}\n\nexport class UnhandledExceptionEvent<\n DataType extends {\n error: Error\n requestId: string\n request: Request\n } = {\n error: Error\n requestId: string\n request: Request\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly error: Error\n public readonly requestId: string\n public readonly request: Request\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.error = data.error\n this.requestId = data.requestId\n this.request = data.request\n }\n}\n\nexport type HttpNetworkFrameEventMap = {\n 'request:start': RequestEvent\n 'request:match': RequestEvent\n 'request:unhandled': RequestEvent\n 'request:end': RequestEvent\n 'response:mocked': ResponseEvent\n 'response:bypass': ResponseEvent\n unhandledException: UnhandledExceptionEvent\n}\n\nexport abstract class HttpNetworkFrame extends NetworkFrame<\n 'http',\n {\n id: string\n request: Request\n },\n HttpNetworkFrameEventMap\n> {\n constructor(options: HttpNetworkFrameOptions) {\n const id = options.id || createRequestId()\n super('http', { id, request: options.request })\n }\n\n public getHandlers(controller: HandlersController): Array<AnyHandler> {\n return controller.getHandlersByKind('request')\n }\n\n public abstract respondWith(response?: Response): void\n\n public async getUnhandledMessage(): Promise<string> {\n const { request } = this.data\n\n const url = new URL(request.url)\n const publicUrl = toPublicUrl(url) + url.search\n const requestBody =\n request.body == null ? null : await request.clone().text()\n\n const details = `\\n\\n \\u2022 ${request.method} ${publicUrl}\\n\\n${requestBody ? ` \\u2022 Request body: ${requestBody}\\n\\n` : ''}`\n const message = `intercepted a request without a matching request handler:${details}If you still wish to intercept this unhandled request, please create a request handler for it.\\nRead more: https://mswjs.io/docs/http/intercepting-requests`\n\n return message\n }\n\n public async resolve(\n handlers: Array<RequestHandler>,\n onUnhandledFrame: UnhandledFrameHandle,\n resolutionContext?: NetworkFrameResolutionContext,\n ): Promise<boolean | null> {\n const { id: requestId, request } = this.data\n const requestCloneForLogs = resolutionContext?.quiet\n ? null\n : request.clone()\n\n this.events.emit(new RequestEvent('request:start', { requestId, request }))\n\n // Requests wrapped in explicit \"bypass(request)\".\n if (shouldBypassRequest(request)) {\n this.events.emit(new RequestEvent('request:end', { requestId, request }))\n this.passthrough()\n return null\n }\n\n const [lookupError, lookupResult] = await until(() => {\n return executeHandlers({\n requestId,\n request,\n handlers,\n resolutionContext: {\n baseUrl: resolutionContext?.baseUrl?.toString(),\n quiet: resolutionContext?.quiet,\n },\n })\n })\n\n if (lookupError != null) {\n if (\n !this.events.emit(\n new UnhandledExceptionEvent('unhandledException', {\n error: lookupError,\n requestId,\n request,\n }),\n )\n ) {\n // Surface the error to the developer since they haven't handled it.\n console.error(lookupError)\n devUtils.error(\n 'Encountered an unhandled exception during the handler lookup for \"%s %s\". Please see the original error above.',\n request.method,\n request.url,\n )\n }\n\n this.errorWith(lookupError)\n return null\n }\n\n // No matching handlers.\n if (lookupResult == null) {\n this.events.emit(\n new RequestEvent('request:unhandled', {\n requestId,\n request,\n }),\n )\n\n /**\n * @note The unhandled frame handle must be executed during the request resolution\n * since it can influence it (e.g. error the request if the \"error\" startegy was used).\n */\n await executeUnhandledFrameHandle(this, onUnhandledFrame).then(\n () => this.passthrough(),\n (error) => this.errorWith(error),\n )\n\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n return false\n }\n\n const { response, handler, parsedResult } = lookupResult\n\n this.events.emit(\n new RequestEvent('request:match', {\n requestId,\n request,\n }),\n )\n\n // Handlers that returned no mocked response.\n if (response == null) {\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n this.passthrough()\n return null\n }\n\n // Handlers that returned explicit `passthrough()`.\n if (isPassthroughResponse(response)) {\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n this.passthrough()\n return null\n }\n\n await storeResponseCookies(request, response)\n\n this.respondWith(response.clone())\n\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n if (!resolutionContext?.quiet) {\n handler.log({\n request: requestCloneForLogs!,\n response,\n parsedResult,\n })\n }\n\n return true\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA2B;AAC3B,yBAAsB;AACtB,0BAAgC;AAChC,2BAA4D;AAC5D,yBAA4B;AAC5B,6BAAgC;AAChC,kCAAqC;AACrC,2BAA2D;AAC3D,sBAAyB;AACzB,gCAGO;AASA,MAAM,qBAOH,0BAA4C;AAAA,EACpC;AAAA,EACA;AAAA,EAEhB,YAAY,MAAiB,MAAgB;AAC3C,UAAM,GAAI,CAAC,MAAM,CAAC,CAAC,CAAS;AAC5B,SAAK,YAAY,KAAK;AACtB,SAAK,UAAU,KAAK;AAAA,EACtB;AACF;AA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AE5C,SAAK,OAAO;AAAA,MACV,IAAI,aAAa,iBAAiB;AAAA,QAChC;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAGA,QAAI,YAAY,MAAM;AACpB,WAAK,OAAO;AAAA,QACV,IAAI,aAAa,eAAe;AAAA,UAC9B;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAEA,WAAK,YAAY;AACjB,aAAO;AAAA,IACT;AAGA,YAAI,4CAAsB,QAAQ,GAAG;AACnC,WAAK,OAAO;AAAA,QACV,IAAI,aAAa,eAAe;AAAA,UAC9B;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAEA,WAAK,YAAY;AACjB,aAAO;AAAA,IACT;AAEA,cAAM,kDAAqB,SAAS,QAAQ;AAE5C,SAAK,YAAY,SAAS,MAAM,CAAC;AAEjC,SAAK,OAAO;AAAA,MACV,IAAI,aAAa,eAAe;AAAA,QAC9B;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,CAAC,mBAAmB,OAAO;AAC7B,cAAQ,IAAI;AAAA,QACV,SAAS;AAAA,QACT;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/experimental/frames/http-frame.ts"],"sourcesContent":["import { TypedEvent } from 'rettime'\nimport { until } from 'until-async'\nimport { createRequestId } from '@mswjs/interceptors'\nimport {\n NetworkFrame,\n type NetworkFrameResolutionContext,\n} from './network-frame'\nimport { toPublicUrl } from '../../utils/request/toPublicUrl'\nimport { executeHandlers } from '../../utils/executeHandlers'\nimport { storeResponseCookies } from '../../utils/request/storeResponseCookies'\nimport { isPassthroughResponse, shouldBypassRequest } from '../request-utils'\nimport { devUtils } from '../../utils/internal/devUtils'\nimport {\n executeUnhandledFrameHandle,\n type UnhandledFrameHandle,\n} from '../on-unhandled-frame'\nimport type { HandlersController } from '../handlers-controller'\nimport { type AnyHandler } from '../handlers-controller'\nimport { type RequestHandler } from '../../handlers/RequestHandler'\n\ninterface HttpNetworkFrameOptions {\n id?: string\n request: Request\n}\n\nexport class RequestEvent<\n DataType extends { requestId: string; request: Request } = {\n requestId: string\n request: Request\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly requestId: string\n public readonly request: Request\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.requestId = data.requestId\n this.request = data.request\n }\n}\n\nexport class ResponseEvent<\n DataType extends {\n requestId: string\n request: Request\n response: Response\n } = {\n requestId: string\n request: Request\n response: Response\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly requestId: string\n public readonly request: Request\n public readonly response: Response\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.requestId = data.requestId\n this.request = data.request\n this.response = data.response\n }\n}\n\nexport class UnhandledExceptionEvent<\n DataType extends {\n error: Error\n requestId: string\n request: Request\n } = {\n error: Error\n requestId: string\n request: Request\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly error: Error\n public readonly requestId: string\n public readonly request: Request\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.error = data.error\n this.requestId = data.requestId\n this.request = data.request\n }\n}\n\nexport type HttpNetworkFrameEventMap = {\n 'request:start': RequestEvent\n 'request:match': RequestEvent\n 'request:unhandled': RequestEvent\n 'request:end': RequestEvent\n 'response:mocked': ResponseEvent\n 'response:bypass': ResponseEvent\n unhandledException: UnhandledExceptionEvent\n}\n\nexport abstract class HttpNetworkFrame extends NetworkFrame<\n 'http',\n {\n id: string\n request: Request\n },\n HttpNetworkFrameEventMap\n> {\n constructor(options: HttpNetworkFrameOptions) {\n const id = options.id || createRequestId()\n super('http', { id, request: options.request })\n }\n\n public getHandlers(controller: HandlersController): Array<AnyHandler> {\n return controller.getHandlersByKind('request')\n }\n\n public abstract respondWith(response?: Response): void\n\n public async getUnhandledMessage(): Promise<string> {\n const { request } = this.data\n\n const url = new URL(request.url)\n const publicUrl = toPublicUrl(url) + url.search\n const requestBody =\n request.body == null ? null : await request.clone().text()\n\n const details = `\\n\\n \\u2022 ${request.method} ${publicUrl}\\n\\n${requestBody ? ` \\u2022 Request body: ${requestBody}\\n\\n` : ''}`\n const message = `intercepted a request without a matching request handler:${details}If you still wish to intercept this unhandled request, please create a request handler for it.\\nRead more: https://mswjs.io/docs/http/intercepting-requests`\n\n return message\n }\n\n public async resolve(\n handlers: Array<RequestHandler>,\n onUnhandledFrame: UnhandledFrameHandle,\n resolutionContext?: NetworkFrameResolutionContext,\n ): Promise<boolean | null> {\n const { id: requestId, request } = this.data\n const requestCloneForLogs = resolutionContext?.quiet\n ? null\n : request.clone()\n\n this.events.emit(new RequestEvent('request:start', { requestId, request }))\n\n // Requests wrapped in explicit \"bypass(request)\".\n if (shouldBypassRequest(request)) {\n this.events.emit(new RequestEvent('request:end', { requestId, request }))\n this.passthrough()\n return null\n }\n\n const [lookupError, lookupResult] = await until(() => {\n return executeHandlers({\n requestId,\n request,\n handlers,\n resolutionContext: {\n baseUrl: resolutionContext?.baseUrl?.toString(),\n quiet: resolutionContext?.quiet,\n },\n })\n })\n\n if (lookupError != null) {\n if (\n !this.events.emit(\n new UnhandledExceptionEvent('unhandledException', {\n error: lookupError,\n requestId,\n request,\n }),\n )\n ) {\n // Surface the error to the developer since they haven't handled it.\n console.error(lookupError)\n devUtils.error(\n 'Encountered an unhandled exception during the handler lookup for \"%s %s\". Please see the original error above.',\n request.method,\n request.url,\n )\n }\n\n this.errorWith(lookupError)\n return null\n }\n\n // No matching handlers.\n if (lookupResult == null) {\n this.events.emit(\n new RequestEvent('request:unhandled', {\n requestId,\n request,\n }),\n )\n\n /**\n * @note The unhandled frame handle must be executed during the request resolution\n * since it can influence it (e.g. error the request if the \"error\" startegy was used).\n */\n await executeUnhandledFrameHandle(this, onUnhandledFrame).then(\n () => this.passthrough(),\n (error) => this.errorWith(error),\n )\n\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n return false\n }\n\n const { response, handler, parsedResult } = lookupResult\n\n this.events.emit(\n new RequestEvent('request:match', {\n requestId,\n request,\n }),\n )\n\n // Handlers that returned no mocked response.\n if (response == null) {\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n this.passthrough()\n return null\n }\n\n // Handlers that returned explicit `passthrough()`.\n if (isPassthroughResponse(response)) {\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n this.passthrough()\n return null\n }\n\n await storeResponseCookies(request, response)\n\n this.respondWith(response.clone())\n\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n if (!resolutionContext?.quiet) {\n handler.log({\n request: requestCloneForLogs!,\n response,\n parsedResult,\n })\n }\n\n return true\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA2B;AAC3B,yBAAsB;AACtB,0BAAgC;AAChC,2BAGO;AACP,yBAA4B;AAC5B,6BAAgC;AAChC,kCAAqC;AACrC,2BAA2D;AAC3D,sBAAyB;AACzB,gCAGO;AAEP,iCAAgC;AAChC,4BAAoC;AAO7B,MAAM,qBAOH,0BAA4C;AAAA,EACpC;AAAA,EACA;AAAA,EAEhB,YAAY,MAAiB,MAAgB;AAC3C,UAAM,GAAI,CAAC,MAAM,CAAC,CAAC,CAAS;AAC5B,SAAK,YAAY,KAAK;AACtB,SAAK,UAAU,KAAK;AAAA,EACtB;AACF;AAEO,MAAM,sBAYH,0BAA4C;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,MAAiB,MAAgB;AAC3C,UAAM,GAAI,CAAC,MAAM,CAAC,CAAC,CAAS;AAC5B,SAAK,YAAY,KAAK;AACtB,SAAK,UAAU,KAAK;AACpB,SAAK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ACF,CAAC;AAAA,MACH;AAEA,WAAK,YAAY;AACjB,aAAO;AAAA,IACT;AAGA,YAAI,4CAAsB,QAAQ,GAAG;AACnC,WAAK,OAAO;AAAA,QACV,IAAI,aAAa,eAAe;AAAA,UAC9B;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAEA,WAAK,YAAY;AACjB,aAAO;AAAA,IACT;AAEA,cAAM,kDAAqB,SAAS,QAAQ;AAE5C,SAAK,YAAY,SAAS,MAAM,CAAC;AAEjC,SAAK,OAAO;AAAA,MACV,IAAI,aAAa,eAAe;AAAA,QAC9B;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,CAAC,mBAAmB,OAAO;AAC7B,cAAQ,IAAI;AAAA,QACV,SAAS;AAAA,QACT;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { TypedEvent } from "rettime";
|
|
2
2
|
import { until } from "until-async";
|
|
3
3
|
import { createRequestId } from "@mswjs/interceptors";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
NetworkFrame
|
|
6
|
+
} from './network-frame.mjs';
|
|
5
7
|
import { toPublicUrl } from '../../utils/request/toPublicUrl.mjs';
|
|
6
8
|
import { executeHandlers } from '../../utils/executeHandlers.mjs';
|
|
7
9
|
import { storeResponseCookies } from '../../utils/request/storeResponseCookies.mjs';
|
|
@@ -10,6 +12,8 @@ import { devUtils } from '../../utils/internal/devUtils.mjs';
|
|
|
10
12
|
import {
|
|
11
13
|
executeUnhandledFrameHandle
|
|
12
14
|
} from '../on-unhandled-frame.mjs';
|
|
15
|
+
import {} from '../handlers-controller.mjs';
|
|
16
|
+
import {} from '../../handlers/RequestHandler.mjs';
|
|
13
17
|
class RequestEvent extends TypedEvent {
|
|
14
18
|
requestId;
|
|
15
19
|
request;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/experimental/frames/http-frame.ts"],"sourcesContent":["import { TypedEvent } from 'rettime'\nimport { until } from 'until-async'\nimport { createRequestId } from '@mswjs/interceptors'\nimport { NetworkFrame, NetworkFrameResolutionContext } from './network-frame'\nimport { toPublicUrl } from '../../utils/request/toPublicUrl'\nimport { executeHandlers } from '../../utils/executeHandlers'\nimport { storeResponseCookies } from '../../utils/request/storeResponseCookies'\nimport { isPassthroughResponse, shouldBypassRequest } from '../request-utils'\nimport { devUtils } from '../../utils/internal/devUtils'\nimport {\n executeUnhandledFrameHandle,\n type UnhandledFrameHandle,\n} from '../on-unhandled-frame'\nimport { HandlersController, AnyHandler } from '../handlers-controller'\nimport { type RequestHandler } from '../../handlers/RequestHandler'\n\ninterface HttpNetworkFrameOptions {\n id?: string\n request: Request\n}\n\nexport class RequestEvent<\n DataType extends { requestId: string; request: Request } = {\n requestId: string\n request: Request\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly requestId: string\n public readonly request: Request\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.requestId = data.requestId\n this.request = data.request\n }\n}\n\nexport class ResponseEvent<\n DataType extends {\n requestId: string\n request: Request\n response: Response\n } = {\n requestId: string\n request: Request\n response: Response\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly requestId: string\n public readonly request: Request\n public readonly response: Response\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.requestId = data.requestId\n this.request = data.request\n this.response = data.response\n }\n}\n\nexport class UnhandledExceptionEvent<\n DataType extends {\n error: Error\n requestId: string\n request: Request\n } = {\n error: Error\n requestId: string\n request: Request\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly error: Error\n public readonly requestId: string\n public readonly request: Request\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.error = data.error\n this.requestId = data.requestId\n this.request = data.request\n }\n}\n\nexport type HttpNetworkFrameEventMap = {\n 'request:start': RequestEvent\n 'request:match': RequestEvent\n 'request:unhandled': RequestEvent\n 'request:end': RequestEvent\n 'response:mocked': ResponseEvent\n 'response:bypass': ResponseEvent\n unhandledException: UnhandledExceptionEvent\n}\n\nexport abstract class HttpNetworkFrame extends NetworkFrame<\n 'http',\n {\n id: string\n request: Request\n },\n HttpNetworkFrameEventMap\n> {\n constructor(options: HttpNetworkFrameOptions) {\n const id = options.id || createRequestId()\n super('http', { id, request: options.request })\n }\n\n public getHandlers(controller: HandlersController): Array<AnyHandler> {\n return controller.getHandlersByKind('request')\n }\n\n public abstract respondWith(response?: Response): void\n\n public async getUnhandledMessage(): Promise<string> {\n const { request } = this.data\n\n const url = new URL(request.url)\n const publicUrl = toPublicUrl(url) + url.search\n const requestBody =\n request.body == null ? null : await request.clone().text()\n\n const details = `\\n\\n \\u2022 ${request.method} ${publicUrl}\\n\\n${requestBody ? ` \\u2022 Request body: ${requestBody}\\n\\n` : ''}`\n const message = `intercepted a request without a matching request handler:${details}If you still wish to intercept this unhandled request, please create a request handler for it.\\nRead more: https://mswjs.io/docs/http/intercepting-requests`\n\n return message\n }\n\n public async resolve(\n handlers: Array<RequestHandler>,\n onUnhandledFrame: UnhandledFrameHandle,\n resolutionContext?: NetworkFrameResolutionContext,\n ): Promise<boolean | null> {\n const { id: requestId, request } = this.data\n const requestCloneForLogs = resolutionContext?.quiet\n ? null\n : request.clone()\n\n this.events.emit(new RequestEvent('request:start', { requestId, request }))\n\n // Requests wrapped in explicit \"bypass(request)\".\n if (shouldBypassRequest(request)) {\n this.events.emit(new RequestEvent('request:end', { requestId, request }))\n this.passthrough()\n return null\n }\n\n const [lookupError, lookupResult] = await until(() => {\n return executeHandlers({\n requestId,\n request,\n handlers,\n resolutionContext: {\n baseUrl: resolutionContext?.baseUrl?.toString(),\n quiet: resolutionContext?.quiet,\n },\n })\n })\n\n if (lookupError != null) {\n if (\n !this.events.emit(\n new UnhandledExceptionEvent('unhandledException', {\n error: lookupError,\n requestId,\n request,\n }),\n )\n ) {\n // Surface the error to the developer since they haven't handled it.\n console.error(lookupError)\n devUtils.error(\n 'Encountered an unhandled exception during the handler lookup for \"%s %s\". Please see the original error above.',\n request.method,\n request.url,\n )\n }\n\n this.errorWith(lookupError)\n return null\n }\n\n // No matching handlers.\n if (lookupResult == null) {\n this.events.emit(\n new RequestEvent('request:unhandled', {\n requestId,\n request,\n }),\n )\n\n /**\n * @note The unhandled frame handle must be executed during the request resolution\n * since it can influence it (e.g. error the request if the \"error\" startegy was used).\n */\n await executeUnhandledFrameHandle(this, onUnhandledFrame).then(\n () => this.passthrough(),\n (error) => this.errorWith(error),\n )\n\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n return false\n }\n\n const { response, handler, parsedResult } = lookupResult\n\n this.events.emit(\n new RequestEvent('request:match', {\n requestId,\n request,\n }),\n )\n\n // Handlers that returned no mocked response.\n if (response == null) {\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n this.passthrough()\n return null\n }\n\n // Handlers that returned explicit `passthrough()`.\n if (isPassthroughResponse(response)) {\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n this.passthrough()\n return null\n }\n\n await storeResponseCookies(request, response)\n\n this.respondWith(response.clone())\n\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n if (!resolutionContext?.quiet) {\n handler.log({\n request: requestCloneForLogs!,\n response,\n parsedResult,\n })\n }\n\n return true\n }\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,uBAAuB;AAChC,SAAS,oBAAmD;AAC5D,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC,SAAS,uBAAuB,2BAA2B;AAC3D,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,OAEK;AASA,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U,KAAK;AAAA,MACjC;AAEA,WAAK,OAAO;AAAA,QACV,IAAI,aAAa,eAAe;AAAA,UAC9B;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,IACT;AAEA,UAAM,EAAE,UAAU,SAAS,aAAa,IAAI;AAE5C,SAAK,OAAO;AAAA,MACV,IAAI,aAAa,iBAAiB;AAAA,QAChC;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAGA,QAAI,YAAY,MAAM;AACpB,WAAK,OAAO;AAAA,QACV,IAAI,aAAa,eAAe;AAAA,UAC9B;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAEA,WAAK,YAAY;AACjB,aAAO;AAAA,IACT;AAGA,QAAI,sBAAsB,QAAQ,GAAG;AACnC,WAAK,OAAO;AAAA,QACV,IAAI,aAAa,eAAe;AAAA,UAC9B;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAEA,WAAK,YAAY;AACjB,aAAO;AAAA,IACT;AAEA,UAAM,qBAAqB,SAAS,QAAQ;AAE5C,SAAK,YAAY,SAAS,MAAM,CAAC;AAEjC,SAAK,OAAO;AAAA,MACV,IAAI,aAAa,eAAe;AAAA,QAC9B;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,CAAC,mBAAmB,OAAO;AAC7B,cAAQ,IAAI;AAAA,QACV,SAAS;AAAA,QACT;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/experimental/frames/http-frame.ts"],"sourcesContent":["import { TypedEvent } from 'rettime'\nimport { until } from 'until-async'\nimport { createRequestId } from '@mswjs/interceptors'\nimport {\n NetworkFrame,\n type NetworkFrameResolutionContext,\n} from './network-frame'\nimport { toPublicUrl } from '../../utils/request/toPublicUrl'\nimport { executeHandlers } from '../../utils/executeHandlers'\nimport { storeResponseCookies } from '../../utils/request/storeResponseCookies'\nimport { isPassthroughResponse, shouldBypassRequest } from '../request-utils'\nimport { devUtils } from '../../utils/internal/devUtils'\nimport {\n executeUnhandledFrameHandle,\n type UnhandledFrameHandle,\n} from '../on-unhandled-frame'\nimport type { HandlersController } from '../handlers-controller'\nimport { type AnyHandler } from '../handlers-controller'\nimport { type RequestHandler } from '../../handlers/RequestHandler'\n\ninterface HttpNetworkFrameOptions {\n id?: string\n request: Request\n}\n\nexport class RequestEvent<\n DataType extends { requestId: string; request: Request } = {\n requestId: string\n request: Request\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly requestId: string\n public readonly request: Request\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.requestId = data.requestId\n this.request = data.request\n }\n}\n\nexport class ResponseEvent<\n DataType extends {\n requestId: string\n request: Request\n response: Response\n } = {\n requestId: string\n request: Request\n response: Response\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly requestId: string\n public readonly request: Request\n public readonly response: Response\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.requestId = data.requestId\n this.request = data.request\n this.response = data.response\n }\n}\n\nexport class UnhandledExceptionEvent<\n DataType extends {\n error: Error\n requestId: string\n request: Request\n } = {\n error: Error\n requestId: string\n request: Request\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly error: Error\n public readonly requestId: string\n public readonly request: Request\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.error = data.error\n this.requestId = data.requestId\n this.request = data.request\n }\n}\n\nexport type HttpNetworkFrameEventMap = {\n 'request:start': RequestEvent\n 'request:match': RequestEvent\n 'request:unhandled': RequestEvent\n 'request:end': RequestEvent\n 'response:mocked': ResponseEvent\n 'response:bypass': ResponseEvent\n unhandledException: UnhandledExceptionEvent\n}\n\nexport abstract class HttpNetworkFrame extends NetworkFrame<\n 'http',\n {\n id: string\n request: Request\n },\n HttpNetworkFrameEventMap\n> {\n constructor(options: HttpNetworkFrameOptions) {\n const id = options.id || createRequestId()\n super('http', { id, request: options.request })\n }\n\n public getHandlers(controller: HandlersController): Array<AnyHandler> {\n return controller.getHandlersByKind('request')\n }\n\n public abstract respondWith(response?: Response): void\n\n public async getUnhandledMessage(): Promise<string> {\n const { request } = this.data\n\n const url = new URL(request.url)\n const publicUrl = toPublicUrl(url) + url.search\n const requestBody =\n request.body == null ? null : await request.clone().text()\n\n const details = `\\n\\n \\u2022 ${request.method} ${publicUrl}\\n\\n${requestBody ? ` \\u2022 Request body: ${requestBody}\\n\\n` : ''}`\n const message = `intercepted a request without a matching request handler:${details}If you still wish to intercept this unhandled request, please create a request handler for it.\\nRead more: https://mswjs.io/docs/http/intercepting-requests`\n\n return message\n }\n\n public async resolve(\n handlers: Array<RequestHandler>,\n onUnhandledFrame: UnhandledFrameHandle,\n resolutionContext?: NetworkFrameResolutionContext,\n ): Promise<boolean | null> {\n const { id: requestId, request } = this.data\n const requestCloneForLogs = resolutionContext?.quiet\n ? null\n : request.clone()\n\n this.events.emit(new RequestEvent('request:start', { requestId, request }))\n\n // Requests wrapped in explicit \"bypass(request)\".\n if (shouldBypassRequest(request)) {\n this.events.emit(new RequestEvent('request:end', { requestId, request }))\n this.passthrough()\n return null\n }\n\n const [lookupError, lookupResult] = await until(() => {\n return executeHandlers({\n requestId,\n request,\n handlers,\n resolutionContext: {\n baseUrl: resolutionContext?.baseUrl?.toString(),\n quiet: resolutionContext?.quiet,\n },\n })\n })\n\n if (lookupError != null) {\n if (\n !this.events.emit(\n new UnhandledExceptionEvent('unhandledException', {\n error: lookupError,\n requestId,\n request,\n }),\n )\n ) {\n // Surface the error to the developer since they haven't handled it.\n console.error(lookupError)\n devUtils.error(\n 'Encountered an unhandled exception during the handler lookup for \"%s %s\". Please see the original error above.',\n request.method,\n request.url,\n )\n }\n\n this.errorWith(lookupError)\n return null\n }\n\n // No matching handlers.\n if (lookupResult == null) {\n this.events.emit(\n new RequestEvent('request:unhandled', {\n requestId,\n request,\n }),\n )\n\n /**\n * @note The unhandled frame handle must be executed during the request resolution\n * since it can influence it (e.g. error the request if the \"error\" startegy was used).\n */\n await executeUnhandledFrameHandle(this, onUnhandledFrame).then(\n () => this.passthrough(),\n (error) => this.errorWith(error),\n )\n\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n return false\n }\n\n const { response, handler, parsedResult } = lookupResult\n\n this.events.emit(\n new RequestEvent('request:match', {\n requestId,\n request,\n }),\n )\n\n // Handlers that returned no mocked response.\n if (response == null) {\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n this.passthrough()\n return null\n }\n\n // Handlers that returned explicit `passthrough()`.\n if (isPassthroughResponse(response)) {\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n this.passthrough()\n return null\n }\n\n await storeResponseCookies(request, response)\n\n this.respondWith(response.clone())\n\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n if (!resolutionContext?.quiet) {\n handler.log({\n request: requestCloneForLogs!,\n response,\n parsedResult,\n })\n }\n\n return true\n }\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,OAEK;AACP,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC,SAAS,uBAAuB,2BAA2B;AAC3D,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,OAEK;AAEP,eAAgC;AAChC,eAAoC;AAO7B,MAAM,qBAOH,WAA4C;AAAA,EACpC;AAAA,EACA;AAAA,EAEhB,YAAY,MAAiB,MAAgB;AAC3C,UAAM,GAAI,CAAC,MAAM,CAAC,CAAC,CAAS;AAC5B,SAAK,YAAY,KAAK;AACtB,SAAK,UAAU,KAAK;AAAA,EACtB;AACF;AAEO,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AAO;AAAA,MACV,IAAI,aAAa,iBAAiB;AAAA,QAChC;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAGA,QAAI,YAAY,MAAM;AACpB,WAAK,OAAO;AAAA,QACV,IAAI,aAAa,eAAe;AAAA,UAC9B;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAEA,WAAK,YAAY;AACjB,aAAO;AAAA,IACT;AAGA,QAAI,sBAAsB,QAAQ,GAAG;AACnC,WAAK,OAAO;AAAA,QACV,IAAI,aAAa,eAAe;AAAA,UAC9B;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAEA,WAAK,YAAY;AACjB,aAAO;AAAA,IACT;AAEA,UAAM,qBAAqB,SAAS,QAAQ;AAE5C,SAAK,YAAY,SAAS,MAAM,CAAC;AAEjC,SAAK,OAAO;AAAA,MACV,IAAI,aAAa,eAAe;AAAA,QAC9B;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,CAAC,mBAAmB,OAAO;AAC7B,cAAQ,IAAI;AAAA,QACV,SAAS;AAAA,QACT;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'rettime';
|
|
2
2
|
import '../handlers-controller.mjs';
|
|
3
|
-
export { A as AnyNetworkFrame, E as ExtractFrameEvents, N as NetworkFrame, a as NetworkFrameResolutionContext } from '../../
|
|
4
|
-
import '../../HttpResponse-
|
|
3
|
+
export { A as AnyNetworkFrame, E as ExtractFrameEvents, N as NetworkFrame, a as NetworkFrameResolutionContext } from '../../on-unhandled-frame-Cr1KOZ0I.mjs';
|
|
4
|
+
import '../../HttpResponse-BMMzfpjG.mjs';
|
|
5
5
|
import '@mswjs/interceptors';
|
|
6
6
|
import '../../utils/internal/isIterable.mjs';
|
|
7
7
|
import '../../typeUtils.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'rettime';
|
|
2
2
|
import '../handlers-controller.js';
|
|
3
|
-
export { A as AnyNetworkFrame, E as ExtractFrameEvents, N as NetworkFrame, a as NetworkFrameResolutionContext } from '../../
|
|
4
|
-
import '../../HttpResponse-
|
|
3
|
+
export { A as AnyNetworkFrame, E as ExtractFrameEvents, N as NetworkFrame, a as NetworkFrameResolutionContext } from '../../on-unhandled-frame-BBR-P3kV.js';
|
|
4
|
+
import '../../HttpResponse-DPDqE4Pb.js';
|
|
5
5
|
import '@mswjs/interceptors';
|
|
6
6
|
import '../../utils/internal/isIterable.js';
|
|
7
7
|
import '../../typeUtils.js';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { TypedEvent } from 'rettime';
|
|
2
2
|
import { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket';
|
|
3
3
|
import { WebSocketHandler } from '../../handlers/WebSocketHandler.mjs';
|
|
4
|
-
import { N as NetworkFrame, b as UnhandledFrameHandle, a as NetworkFrameResolutionContext } from '../../
|
|
4
|
+
import { N as NetworkFrame, b as UnhandledFrameHandle, a as NetworkFrameResolutionContext } from '../../on-unhandled-frame-Cr1KOZ0I.mjs';
|
|
5
5
|
import { HandlersController, AnyHandler } from '../handlers-controller.mjs';
|
|
6
6
|
import 'strict-event-emitter';
|
|
7
7
|
import '../../utils/matching/matchRequestUrl.mjs';
|
|
8
|
-
import '../../HttpResponse-
|
|
8
|
+
import '../../HttpResponse-BMMzfpjG.mjs';
|
|
9
9
|
import '@mswjs/interceptors';
|
|
10
10
|
import '../../utils/internal/isIterable.mjs';
|
|
11
11
|
import '../../typeUtils.mjs';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { TypedEvent } from 'rettime';
|
|
2
2
|
import { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket';
|
|
3
3
|
import { WebSocketHandler } from '../../handlers/WebSocketHandler.js';
|
|
4
|
-
import { N as NetworkFrame, b as UnhandledFrameHandle, a as NetworkFrameResolutionContext } from '../../
|
|
4
|
+
import { N as NetworkFrame, b as UnhandledFrameHandle, a as NetworkFrameResolutionContext } from '../../on-unhandled-frame-BBR-P3kV.js';
|
|
5
5
|
import { HandlersController, AnyHandler } from '../handlers-controller.js';
|
|
6
6
|
import 'strict-event-emitter';
|
|
7
7
|
import '../../utils/matching/matchRequestUrl.js';
|
|
8
|
-
import '../../HttpResponse-
|
|
8
|
+
import '../../HttpResponse-DPDqE4Pb.js';
|
|
9
9
|
import '@mswjs/interceptors';
|
|
10
10
|
import '../../utils/internal/isIterable.js';
|
|
11
11
|
import '../../typeUtils.js';
|
|
@@ -22,10 +22,12 @@ __export(websocket_frame_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(websocket_frame_exports);
|
|
24
24
|
var import_rettime = require("rettime");
|
|
25
|
+
var import_WebSocket = require("@mswjs/interceptors/WebSocket");
|
|
25
26
|
var import_WebSocketHandler = require("../../handlers/WebSocketHandler");
|
|
26
27
|
var import_network_frame = require("./network-frame");
|
|
27
28
|
var import_on_unhandled_frame = require("../on-unhandled-frame");
|
|
28
29
|
var import_devUtils = require("../../utils/internal/devUtils");
|
|
30
|
+
var import_handlers_controller = require("../handlers-controller");
|
|
29
31
|
class WebSocketConnectionEvent extends import_rettime.TypedEvent {
|
|
30
32
|
url;
|
|
31
33
|
protocols;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/experimental/frames/websocket-frame.ts"],"sourcesContent":["import { TypedEvent } from 'rettime'\nimport { type WebSocketConnectionData } from '@mswjs/interceptors/WebSocket'\nimport {\n kConnect,\n kAutoConnect,\n type WebSocketHandler,\n} from '../../handlers/WebSocketHandler'\nimport {\n NetworkFrame,\n type NetworkFrameResolutionContext,\n} from './network-frame'\nimport {\n executeUnhandledFrameHandle,\n UnhandledFrameHandle,\n} from '../on-unhandled-frame'\nimport { devUtils } from '../../utils/internal/devUtils'\nimport { HandlersController
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/experimental/frames/websocket-frame.ts"],"sourcesContent":["import { TypedEvent } from 'rettime'\nimport { type WebSocketConnectionData } from '@mswjs/interceptors/WebSocket'\nimport {\n kConnect,\n kAutoConnect,\n type WebSocketHandler,\n} from '../../handlers/WebSocketHandler'\nimport {\n NetworkFrame,\n type NetworkFrameResolutionContext,\n} from './network-frame'\nimport {\n executeUnhandledFrameHandle,\n type UnhandledFrameHandle,\n} from '../on-unhandled-frame'\nimport { devUtils } from '../../utils/internal/devUtils'\nimport type { HandlersController } from '../handlers-controller'\nimport { type AnyHandler } from '../handlers-controller'\n\nexport interface WebSocketNetworkFrameOptions {\n connection: WebSocketConnectionData\n}\n\nexport type WebSocketNetworkFrameEventMap = {\n connection: WebSocketConnectionEvent\n unhandledException: UnhandledWebSocketExceptionEvent\n}\n\nclass WebSocketConnectionEvent<\n DataType extends {\n url: URL\n protocols: string | Array<string> | undefined\n } = { url: URL; protocols: string | Array<string> | undefined },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly url: URL\n public readonly protocols: string | Array<string> | undefined\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.url = data.url\n this.protocols = data.protocols\n }\n}\n\nclass UnhandledWebSocketExceptionEvent<\n DataType extends {\n url: URL\n protocols: string | Array<string> | undefined\n error: unknown\n } = {\n url: URL\n protocols: string | Array<string> | undefined\n error: unknown\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly url: URL\n public readonly protocols: string | Array<string> | undefined\n public readonly error: unknown\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.url = data.url\n this.protocols = data.protocols\n this.error = data.error\n }\n}\n\nexport abstract class WebSocketNetworkFrame extends NetworkFrame<\n 'ws',\n {\n connection: WebSocketConnectionData\n },\n WebSocketNetworkFrameEventMap\n> {\n constructor(options: WebSocketNetworkFrameOptions) {\n super('ws', {\n connection: options.connection,\n })\n }\n\n public getHandlers(controller: HandlersController): Array<AnyHandler> {\n return controller.getHandlersByKind('websocket')\n }\n\n public async resolve(\n handlers: Array<WebSocketHandler>,\n onUnhandledFrame: UnhandledFrameHandle,\n resolutionContext?: NetworkFrameResolutionContext,\n ): Promise<boolean | null> {\n const { connection } = this.data\n\n this.events.emit(\n new WebSocketConnectionEvent('connection', {\n url: connection.client.url,\n protocols: connection.info.protocols,\n }),\n )\n\n // No WebSocket handlers defined.\n if (handlers.length === 0) {\n await executeUnhandledFrameHandle(this, onUnhandledFrame).then(\n () => this.passthrough(),\n (error) => this.errorWith(error),\n )\n\n return false\n }\n\n let hasMatchingHandlers = false\n\n for (const handler of handlers) {\n const handlerConnection = await handler.run(connection, {\n baseUrl: resolutionContext?.baseUrl?.toString(),\n /**\n * @note Do not emit the \"connection\" event when running the handler.\n * Use the run only to get the resolved connection object.\n */\n [kAutoConnect]: false,\n })\n\n if (!handlerConnection) {\n continue\n }\n\n hasMatchingHandlers = true\n\n /**\n * @note Attach the WebSocket logger *before* emitting the \"connection\" event.\n * Connection event listeners may perform actions that should be reflected in the logs\n * (e.g. closing the connection immediately). If the logger is attached after the connection,\n * those actions cannot be properly logged.\n */\n const removeLogger = !resolutionContext?.quiet\n ? handler.log(connection)\n : undefined\n\n try {\n if (!handler[kConnect](handlerConnection)) {\n removeLogger?.()\n }\n } catch (error) {\n if (\n !this.events.emit(\n new UnhandledWebSocketExceptionEvent('unhandledException', {\n error,\n url: connection.client.url,\n protocols: connection.info.protocols,\n }),\n )\n ) {\n console.error(error)\n devUtils.error(\n 'Encountered an unhandled exception during the handler lookup for \"%s\". Please see the original error above.',\n connection.client.url,\n )\n }\n\n /**\n * @note Throw the caught error so it gets picked up by WebSocketInterceptor.\n * It's the interceptor who translates handler errors to WebSocket closures.\n */\n throw error\n }\n }\n\n // No matching WebSocket handlers found.\n if (!hasMatchingHandlers) {\n await executeUnhandledFrameHandle(this, onUnhandledFrame).then(\n () => this.passthrough(),\n (error) => this.errorWith(error),\n )\n\n return false\n }\n\n return true\n }\n\n public async getUnhandledMessage(): Promise<string> {\n const { connection } = this.data\n const details = `\\n\\n \\u2022 ${connection.client.url}\\n\\n`\n\n return `intercepted a WebSocket connection without a matching event handler:${details}If you still wish to intercept this unhandled connection, please create an event handler for it.\\nRead more: https://mswjs.io/docs/websocket`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA2B;AAC3B,uBAA6C;AAC7C,8BAIO;AACP,2BAGO;AACP,gCAGO;AACP,sBAAyB;AAEzB,iCAAgC;AAWhC,MAAM,iCAOI,0BAA4C;AAAA,EACpC;AAAA,EACA;AAAA,EAEhB,YAAY,MAAiB,MAAgB;AAC3C,UAAM,GAAI,CAAC,MAAM,CAAC,CAAC,CAAS;AAC5B,SAAK,MAAM,KAAK;AAChB,SAAK,YAAY,KAAK;AAAA,EACxB;AACF;AAEA,MAAM,yCAYI,0BAA4C;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,MAAiB,MAAgB;AAC3C,UAAM,GAAI,CAAC,MAAM,CAAC,CAAC,CAAS;AAC5B,SAAK,MAAM,KAAK;AAChB,SAAK,YAAY,KAAK;AACtB,SAAK,QAAQ,KAAK;AAAA,EACpB;AACF;AAEO,MAAe,8BAA8B,kCAMlD;AAAA,EACA,YAAY,SAAuC;AACjD,UAAM,MAAM;AAAA,MACV,YAAY,QAAQ;AAAA,IACtB,CAAC;AAAA,EACH;AAAA,EAEO,YAAY,YAAmD;AACpE,WAAO,WAAW,kBAAkB,WAAW;AAAA,EACjD;AAAA,EAEA,MAAa,QACX,UACA,kBACA,mBACyB;AACzB,UAAM,EAAE,WAAW,IAAI,KAAK;AAE5B,SAAK,OAAO;AAAA,MACV,IAAI,yBAAyB,cAAc;AAAA,QACzC,KAAK,WAAW,OAAO;AAAA,QACvB,WAAW,WAAW,KAAK;AAAA,MAC7B,CAAC;AAAA,IACH;AAGA,QAAI,SAAS,WAAW,GAAG;AAC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E,OAAO;AAAA;AAAA,EACvF;AACF;","names":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TypedEvent } from "rettime";
|
|
2
|
+
import {} from "@mswjs/interceptors/WebSocket";
|
|
2
3
|
import {
|
|
3
4
|
kConnect,
|
|
4
5
|
kAutoConnect
|
|
@@ -10,6 +11,7 @@ import {
|
|
|
10
11
|
executeUnhandledFrameHandle
|
|
11
12
|
} from '../on-unhandled-frame.mjs';
|
|
12
13
|
import { devUtils } from '../../utils/internal/devUtils.mjs';
|
|
14
|
+
import {} from '../handlers-controller.mjs';
|
|
13
15
|
class WebSocketConnectionEvent extends TypedEvent {
|
|
14
16
|
url;
|
|
15
17
|
protocols;
|