msw 2.5.2 → 2.6.0
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.d.mts +7 -6
- package/lib/browser/index.d.ts +7 -6
- package/lib/browser/index.js +29 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +29 -1
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-ClMB0BOy.d.mts → GraphQLHandler-Doool6Q_.d.mts} +1 -1
- package/lib/core/{GraphQLHandler-D6mLMXGZ.d.ts → GraphQLHandler-udzgBRPf.d.ts} +1 -1
- package/lib/core/{HttpResponse-vn-Pb4Bi.d.mts → HttpResponse-BLGmJolh.d.mts} +1 -1
- package/lib/core/{HttpResponse-DaYkf3ml.d.ts → HttpResponse-Cgbkdkje.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 +15 -12
- package/lib/core/SetupApi.d.ts +15 -12
- package/lib/core/SetupApi.js +3 -1
- package/lib/core/SetupApi.js.map +1 -1
- package/lib/core/SetupApi.mjs +3 -1
- package/lib/core/SetupApi.mjs.map +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +2 -2
- package/lib/core/graphql.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +33 -0
- package/lib/core/handlers/WebSocketHandler.d.ts +33 -0
- package/lib/core/handlers/WebSocketHandler.js +120 -0
- package/lib/core/handlers/WebSocketHandler.js.map +1 -0
- package/lib/core/handlers/WebSocketHandler.mjs +102 -0
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -0
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +5 -2
- package/lib/core/index.d.ts +5 -2
- package/lib/core/index.js +5 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +7 -1
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/executeHandlers.js +4 -0
- package/lib/core/utils/executeHandlers.js.map +1 -1
- package/lib/core/utils/executeHandlers.mjs +6 -0
- package/lib/core/utils/executeHandlers.mjs.map +1 -1
- package/lib/core/utils/handleRequest.d.mts +2 -2
- package/lib/core/utils/handleRequest.d.ts +2 -2
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/utils/logging/getTimestamp.d.mts +4 -1
- package/lib/core/utils/logging/getTimestamp.d.ts +4 -1
- package/lib/core/utils/logging/getTimestamp.js +6 -2
- package/lib/core/utils/logging/getTimestamp.js.map +1 -1
- package/lib/core/utils/logging/getTimestamp.mjs +6 -2
- package/lib/core/utils/logging/getTimestamp.mjs.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.d.mts +2 -1
- package/lib/core/utils/matching/matchRequestUrl.d.ts +2 -1
- package/lib/core/utils/matching/matchRequestUrl.js +4 -0
- package/lib/core/utils/matching/matchRequestUrl.js.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs +4 -0
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -1
- package/lib/core/ws/WebSocketClientManager.d.mts +63 -0
- package/lib/core/ws/WebSocketClientManager.d.ts +63 -0
- package/lib/core/ws/WebSocketClientManager.js +149 -0
- package/lib/core/ws/WebSocketClientManager.js.map +1 -0
- package/lib/core/ws/WebSocketClientManager.mjs +129 -0
- package/lib/core/ws/WebSocketClientManager.mjs.map +1 -0
- package/lib/core/ws/WebSocketClientStore.d.mts +13 -0
- package/lib/core/ws/WebSocketClientStore.d.ts +13 -0
- package/lib/core/ws/WebSocketClientStore.js +26 -0
- package/lib/core/ws/WebSocketClientStore.js.map +1 -0
- package/lib/core/ws/WebSocketClientStore.mjs +6 -0
- package/lib/core/ws/WebSocketClientStore.mjs.map +1 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.d.mts +15 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.d.ts +15 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.js +130 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +110 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -0
- package/lib/core/ws/WebSocketMemoryClientStore.d.mts +13 -0
- package/lib/core/ws/WebSocketMemoryClientStore.d.ts +13 -0
- package/lib/core/ws/WebSocketMemoryClientStore.js +41 -0
- package/lib/core/ws/WebSocketMemoryClientStore.js.map +1 -0
- package/lib/core/ws/WebSocketMemoryClientStore.mjs +21 -0
- package/lib/core/ws/WebSocketMemoryClientStore.mjs.map +1 -0
- package/lib/core/ws/handleWebSocketEvent.d.mts +19 -0
- package/lib/core/ws/handleWebSocketEvent.d.ts +19 -0
- package/lib/core/ws/handleWebSocketEvent.js +73 -0
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -0
- package/lib/core/ws/handleWebSocketEvent.mjs +55 -0
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -0
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +12 -0
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +12 -0
- package/lib/core/ws/utils/attachWebSocketLogger.js +198 -0
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -0
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +178 -0
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -0
- package/lib/core/ws/utils/getMessageLength.d.mts +11 -0
- package/lib/core/ws/utils/getMessageLength.d.ts +11 -0
- package/lib/core/ws/utils/getMessageLength.js +33 -0
- package/lib/core/ws/utils/getMessageLength.js.map +1 -0
- package/lib/core/ws/utils/getMessageLength.mjs +13 -0
- package/lib/core/ws/utils/getMessageLength.mjs.map +1 -0
- package/lib/core/ws/utils/getPublicData.d.mts +5 -0
- package/lib/core/ws/utils/getPublicData.d.ts +5 -0
- package/lib/core/ws/utils/getPublicData.js +36 -0
- package/lib/core/ws/utils/getPublicData.js.map +1 -0
- package/lib/core/ws/utils/getPublicData.mjs +16 -0
- package/lib/core/ws/utils/getPublicData.mjs.map +1 -0
- package/lib/core/ws/utils/truncateMessage.d.mts +3 -0
- package/lib/core/ws/utils/truncateMessage.d.ts +3 -0
- package/lib/core/ws/utils/truncateMessage.js +31 -0
- package/lib/core/ws/utils/truncateMessage.js.map +1 -0
- package/lib/core/ws/utils/truncateMessage.mjs +11 -0
- package/lib/core/ws/utils/truncateMessage.mjs.map +1 -0
- package/lib/core/ws/webSocketInterceptor.d.mts +5 -0
- package/lib/core/ws/webSocketInterceptor.d.ts +5 -0
- package/lib/core/ws/webSocketInterceptor.js +26 -0
- package/lib/core/ws/webSocketInterceptor.js.map +1 -0
- package/lib/core/ws/webSocketInterceptor.mjs +6 -0
- package/lib/core/ws/webSocketInterceptor.mjs.map +1 -0
- package/lib/core/ws.d.mts +75 -0
- package/lib/core/ws.d.ts +75 -0
- package/lib/core/ws.js +71 -0
- package/lib/core/ws.js.map +1 -0
- package/lib/core/ws.mjs +54 -0
- package/lib/core/ws.mjs.map +1 -0
- package/lib/iife/index.js +1413 -85
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.mts +6 -5
- package/lib/native/index.d.ts +6 -5
- package/lib/native/index.js +22 -4
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +22 -4
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.d.mts +8 -7
- package/lib/node/index.d.ts +8 -7
- package/lib/node/index.js +22 -4
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +22 -4
- package/lib/node/index.mjs.map +1 -1
- package/package.json +10 -1
- package/src/browser/setupWorker/glossary.ts +10 -10
- package/src/browser/setupWorker/setupWorker.ts +32 -3
- package/src/browser/setupWorker/start/createRequestListener.ts +7 -1
- package/src/browser/setupWorker/start/createStartHandler.ts +5 -0
- package/src/browser/setupWorker/stop/createStop.ts +6 -0
- package/src/core/SetupApi.ts +28 -20
- package/src/core/handlers/WebSocketHandler.ts +142 -0
- package/src/core/index.ts +11 -1
- package/src/core/utils/executeHandlers.ts +6 -2
- package/src/core/utils/handleRequest.ts +1 -1
- package/src/core/utils/logging/getTimestamp.test.ts +20 -6
- package/src/core/utils/logging/getTimestamp.ts +11 -6
- package/src/core/utils/matching/matchRequestUrl.test.ts +44 -0
- package/src/core/utils/matching/matchRequestUrl.ts +4 -0
- package/src/core/ws/WebSocketClientManager.test.ts +164 -0
- package/src/core/ws/WebSocketClientManager.ts +211 -0
- package/src/core/ws/WebSocketClientStore.ts +14 -0
- package/src/core/ws/WebSocketIndexedDBClientStore.ts +145 -0
- package/src/core/ws/WebSocketMemoryClientStore.ts +27 -0
- package/src/core/ws/handleWebSocketEvent.ts +82 -0
- package/src/core/ws/utils/attachWebSocketLogger.ts +259 -0
- package/src/core/ws/utils/getMessageLength.test.ts +16 -0
- package/src/core/ws/utils/getMessageLength.ts +19 -0
- package/src/core/ws/utils/getPublicData.test.ts +38 -0
- package/src/core/ws/utils/getPublicData.ts +17 -0
- package/src/core/ws/utils/truncateMessage.test.ts +12 -0
- package/src/core/ws/utils/truncateMessage.ts +9 -0
- package/src/core/ws/webSocketInterceptor.ts +3 -0
- package/src/core/ws.test.ts +23 -0
- package/src/core/ws.ts +166 -0
- package/src/node/SetupServerApi.ts +8 -7
- package/src/node/SetupServerCommonApi.ts +29 -5
- package/src/node/glossary.ts +5 -7
- package/src/node/setupServer.ts +2 -1
package/lib/mockServiceWorker.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - Please do NOT serve this file on production.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const PACKAGE_VERSION = '2.
|
|
11
|
+
const PACKAGE_VERSION = '2.6.0'
|
|
12
12
|
const INTEGRITY_CHECKSUM = '07a8241b182f8a246a7cd39894799a9e'
|
|
13
13
|
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
|
14
14
|
const activeClientIds = new Set()
|
package/lib/native/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { RequestHandler
|
|
1
|
+
import { RequestHandler } from "../core/handlers/RequestHandler";
|
|
2
2
|
import { BatchInterceptor, Interceptor, HttpRequestEventMap } from '@mswjs/interceptors';
|
|
3
3
|
import { SharedOptions, LifeCycleEventEmitter, LifeCycleEventsMap } from "../core/sharedOptions";
|
|
4
4
|
import { SetupApi } from "../core/SetupApi";
|
|
5
|
+
import { WebSocketHandler } from "../core/handlers/WebSocketHandler";
|
|
5
6
|
import { PartialDeep } from 'type-fest';
|
|
6
7
|
|
|
7
8
|
interface SetupServerCommon {
|
|
@@ -22,7 +23,7 @@ interface SetupServerCommon {
|
|
|
22
23
|
*
|
|
23
24
|
* @see {@link https://mswjs.io/docs/api/setup-server/use `server.use()` API reference}
|
|
24
25
|
*/
|
|
25
|
-
use(...handlers: Array<RequestHandler>): void;
|
|
26
|
+
use(...handlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
26
27
|
/**
|
|
27
28
|
* Marks all request handlers that respond using `res.once()` as unused.
|
|
28
29
|
*
|
|
@@ -34,13 +35,13 @@ interface SetupServerCommon {
|
|
|
34
35
|
*
|
|
35
36
|
* @see {@link https://mswjs.io/docs/api/setup-server/reset-handlers `server.reset-handlers()` API reference}
|
|
36
37
|
*/
|
|
37
|
-
resetHandlers(...nextHandlers: Array<RequestHandler>): void;
|
|
38
|
+
resetHandlers(...nextHandlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
38
39
|
/**
|
|
39
40
|
* Returns a readonly list of currently active request handlers.
|
|
40
41
|
*
|
|
41
42
|
* @see {@link https://mswjs.io/docs/api/setup-server/list-handlers `server.listHandlers()` API reference}
|
|
42
43
|
*/
|
|
43
|
-
listHandlers(): ReadonlyArray<RequestHandler
|
|
44
|
+
listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>;
|
|
44
45
|
/**
|
|
45
46
|
* Life-cycle events.
|
|
46
47
|
* Life-cycle events allow you to subscribe to the internal library events occurring during the request/response handling.
|
|
@@ -60,7 +61,7 @@ declare class SetupServerCommonApi extends SetupApi<LifeCycleEventsMap> implemen
|
|
|
60
61
|
private resolvedOptions;
|
|
61
62
|
constructor(interceptors: Array<{
|
|
62
63
|
new (): Interceptor<HttpRequestEventMap>;
|
|
63
|
-
}>, handlers: Array<RequestHandler>);
|
|
64
|
+
}>, handlers: Array<RequestHandler | WebSocketHandler>);
|
|
64
65
|
/**
|
|
65
66
|
* Subscribe to all requests that are using the interceptor object
|
|
66
67
|
*/
|
package/lib/native/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { RequestHandler
|
|
1
|
+
import { RequestHandler } from "../core/handlers/RequestHandler";
|
|
2
2
|
import { BatchInterceptor, Interceptor, HttpRequestEventMap } from '@mswjs/interceptors';
|
|
3
3
|
import { SharedOptions, LifeCycleEventEmitter, LifeCycleEventsMap } from "../core/sharedOptions";
|
|
4
4
|
import { SetupApi } from "../core/SetupApi";
|
|
5
|
+
import { WebSocketHandler } from "../core/handlers/WebSocketHandler";
|
|
5
6
|
import { PartialDeep } from 'type-fest';
|
|
6
7
|
|
|
7
8
|
interface SetupServerCommon {
|
|
@@ -22,7 +23,7 @@ interface SetupServerCommon {
|
|
|
22
23
|
*
|
|
23
24
|
* @see {@link https://mswjs.io/docs/api/setup-server/use `server.use()` API reference}
|
|
24
25
|
*/
|
|
25
|
-
use(...handlers: Array<RequestHandler>): void;
|
|
26
|
+
use(...handlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
26
27
|
/**
|
|
27
28
|
* Marks all request handlers that respond using `res.once()` as unused.
|
|
28
29
|
*
|
|
@@ -34,13 +35,13 @@ interface SetupServerCommon {
|
|
|
34
35
|
*
|
|
35
36
|
* @see {@link https://mswjs.io/docs/api/setup-server/reset-handlers `server.reset-handlers()` API reference}
|
|
36
37
|
*/
|
|
37
|
-
resetHandlers(...nextHandlers: Array<RequestHandler>): void;
|
|
38
|
+
resetHandlers(...nextHandlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
38
39
|
/**
|
|
39
40
|
* Returns a readonly list of currently active request handlers.
|
|
40
41
|
*
|
|
41
42
|
* @see {@link https://mswjs.io/docs/api/setup-server/list-handlers `server.listHandlers()` API reference}
|
|
42
43
|
*/
|
|
43
|
-
listHandlers(): ReadonlyArray<RequestHandler
|
|
44
|
+
listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>;
|
|
44
45
|
/**
|
|
45
46
|
* Life-cycle events.
|
|
46
47
|
* Life-cycle events allow you to subscribe to the internal library events occurring during the request/response handling.
|
|
@@ -60,7 +61,7 @@ declare class SetupServerCommonApi extends SetupApi<LifeCycleEventsMap> implemen
|
|
|
60
61
|
private resolvedOptions;
|
|
61
62
|
constructor(interceptors: Array<{
|
|
62
63
|
new (): Interceptor<HttpRequestEventMap>;
|
|
63
|
-
}>, handlers: Array<RequestHandler>);
|
|
64
|
+
}>, handlers: Array<RequestHandler | WebSocketHandler>);
|
|
64
65
|
/**
|
|
65
66
|
* Subscribe to all requests that are using the interceptor object
|
|
66
67
|
*/
|
package/lib/native/index.js
CHANGED
|
@@ -31,8 +31,12 @@ var import_outvariant = require("outvariant");
|
|
|
31
31
|
var import_interceptors = require("@mswjs/interceptors");
|
|
32
32
|
var import_SetupApi = require("../core/SetupApi.js");
|
|
33
33
|
var import_handleRequest = require("../core/utils/handleRequest.js");
|
|
34
|
+
var import_HttpHandler = require("../core/handlers/HttpHandler.js");
|
|
35
|
+
var import_GraphQLHandler = require("../core/handlers/GraphQLHandler.js");
|
|
34
36
|
var import_mergeRight = require("../core/utils/internal/mergeRight.js");
|
|
35
37
|
var import_devUtils = require("../core/utils/internal/devUtils.js");
|
|
38
|
+
var import_handleWebSocketEvent = require("../core/ws/handleWebSocketEvent.js");
|
|
39
|
+
var import_webSocketInterceptor = require("../core/ws/webSocketInterceptor.js");
|
|
36
40
|
var DEFAULT_LISTEN_OPTIONS = {
|
|
37
41
|
onUnhandledRequest: "warn"
|
|
38
42
|
};
|
|
@@ -58,7 +62,9 @@ var SetupServerCommonApi = class extends import_SetupApi.SetupApi {
|
|
|
58
62
|
const response = await (0, import_handleRequest.handleRequest)(
|
|
59
63
|
request,
|
|
60
64
|
requestId,
|
|
61
|
-
this.handlersController.currentHandlers()
|
|
65
|
+
this.handlersController.currentHandlers().filter((handler) => {
|
|
66
|
+
return handler instanceof import_HttpHandler.HttpHandler || handler instanceof import_GraphQLHandler.GraphQLHandler;
|
|
67
|
+
}),
|
|
62
68
|
this.resolvedOptions,
|
|
63
69
|
this.emitter
|
|
64
70
|
);
|
|
@@ -86,6 +92,18 @@ var SetupServerCommonApi = class extends import_SetupApi.SetupApi {
|
|
|
86
92
|
);
|
|
87
93
|
}
|
|
88
94
|
);
|
|
95
|
+
(0, import_handleWebSocketEvent.handleWebSocketEvent)({
|
|
96
|
+
getUnhandledRequestStrategy: () => {
|
|
97
|
+
return this.resolvedOptions.onUnhandledRequest;
|
|
98
|
+
},
|
|
99
|
+
getHandlers: () => {
|
|
100
|
+
return this.handlersController.currentHandlers();
|
|
101
|
+
},
|
|
102
|
+
onMockedConnection: () => {
|
|
103
|
+
},
|
|
104
|
+
onPassthroughConnection: () => {
|
|
105
|
+
}
|
|
106
|
+
});
|
|
89
107
|
}
|
|
90
108
|
listen(options = {}) {
|
|
91
109
|
this.resolvedOptions = (0, import_mergeRight.mergeRight)(
|
|
@@ -93,9 +111,9 @@ var SetupServerCommonApi = class extends import_SetupApi.SetupApi {
|
|
|
93
111
|
options
|
|
94
112
|
);
|
|
95
113
|
this.interceptor.apply();
|
|
96
|
-
this.subscriptions.push(() =>
|
|
97
|
-
|
|
98
|
-
|
|
114
|
+
this.subscriptions.push(() => this.interceptor.dispose());
|
|
115
|
+
import_webSocketInterceptor.webSocketInterceptor.apply();
|
|
116
|
+
this.subscriptions.push(() => import_webSocketInterceptor.webSocketInterceptor.dispose());
|
|
99
117
|
(0, import_outvariant.invariant)(
|
|
100
118
|
[import_interceptors.InterceptorReadyState.APPLYING, import_interceptors.InterceptorReadyState.APPLIED].includes(
|
|
101
119
|
this.interceptor.readyState
|
package/lib/native/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerCommonApi.ts"],"sourcesContent":["import { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerCommonApi } from '../node/SetupServerCommonApi'\n\n/**\n * Sets up a requests interception in React Native with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport function setupServer(\n ...handlers: Array<RequestHandler>\n): SetupServerCommonApi {\n // Provision request interception via patching the `XMLHttpRequest` class only\n // in React Native. There is no `http`/`https` modules in that environment.\n return new SetupServerCommonApi(\n [FetchInterceptor, XMLHttpRequestInterceptor],\n handlers,\n )\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { InternalError, devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\n handlers: Array<RequestHandler>,\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\n\n this.resolvedOptions = {} as RequiredDeep<SharedOptions>\n\n this.init()\n }\n\n /**\n * Subscribe to all requests that are using the interceptor object\n */\n private init(): void {\n this.interceptor.on(\n 'request',\n async ({ request, requestId, controller }) => {\n const response = await handleRequest(\n request,\n requestId,\n this.handlersController.currentHandlers(),\n this.resolvedOptions,\n this.emitter,\n )\n\n if (response) {\n controller.respondWith(response)\n }\n\n return\n },\n )\n\n this.interceptor.on('unhandledException', ({ error }) => {\n if (error instanceof InternalError) {\n throw error\n }\n })\n\n this.interceptor.on(\n 'response',\n ({ response, isMockedResponse, request, requestId }) => {\n this.emitter.emit(\n isMockedResponse ? 'response:mocked' : 'response:bypass',\n {\n response,\n request,\n requestId,\n },\n )\n },\n )\n }\n\n public listen(options: Partial<SharedOptions> = {}): void {\n this.resolvedOptions = mergeRight(\n DEFAULT_LISTEN_OPTIONS,\n options,\n ) as RequiredDeep<SharedOptions>\n\n // Apply the interceptor when starting the server.\n this.interceptor.apply()\n
|
|
1
|
+
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerCommonApi.ts"],"sourcesContent":["import { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerCommonApi } from '../node/SetupServerCommonApi'\n\n/**\n * Sets up a requests interception in React Native with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport function setupServer(\n ...handlers: Array<RequestHandler>\n): SetupServerCommonApi {\n // Provision request interception via patching the `XMLHttpRequest` class only\n // in React Native. There is no `http`/`https` modules in that environment.\n return new SetupServerCommonApi(\n [FetchInterceptor, XMLHttpRequestInterceptor],\n handlers,\n )\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { HttpHandler } from '~/core/handlers/HttpHandler'\nimport { GraphQLHandler } from '~/core/handlers/GraphQLHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { InternalError, devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\nimport { handleWebSocketEvent } from '~/core/ws/handleWebSocketEvent'\nimport { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\n handlers: Array<RequestHandler | WebSocketHandler>,\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\n\n this.resolvedOptions = {} as RequiredDeep<SharedOptions>\n\n this.init()\n }\n\n /**\n * Subscribe to all requests that are using the interceptor object\n */\n private init(): void {\n this.interceptor.on(\n 'request',\n async ({ request, requestId, controller }) => {\n const response = await handleRequest(\n request,\n requestId,\n this.handlersController.currentHandlers().filter((handler) => {\n return (\n handler instanceof HttpHandler ||\n handler instanceof GraphQLHandler\n )\n }),\n this.resolvedOptions,\n this.emitter,\n )\n\n if (response) {\n controller.respondWith(response)\n }\n\n return\n },\n )\n\n this.interceptor.on('unhandledException', ({ error }) => {\n if (error instanceof InternalError) {\n throw error\n }\n })\n\n this.interceptor.on(\n 'response',\n ({ response, isMockedResponse, request, requestId }) => {\n this.emitter.emit(\n isMockedResponse ? 'response:mocked' : 'response:bypass',\n {\n response,\n request,\n requestId,\n },\n )\n },\n )\n\n // Preconfigure the WebSocket interception but don't enable it just yet.\n // It will be enabled when the server starts.\n handleWebSocketEvent({\n getUnhandledRequestStrategy: () => {\n return this.resolvedOptions.onUnhandledRequest\n },\n getHandlers: () => {\n return this.handlersController.currentHandlers()\n },\n onMockedConnection: () => {},\n onPassthroughConnection: () => {},\n })\n }\n\n public listen(options: Partial<SharedOptions> = {}): void {\n this.resolvedOptions = mergeRight(\n DEFAULT_LISTEN_OPTIONS,\n options,\n ) as RequiredDeep<SharedOptions>\n\n // Apply the interceptor when starting the server.\n this.interceptor.apply()\n this.subscriptions.push(() => this.interceptor.dispose())\n\n // Apply the WebSocket interception.\n webSocketInterceptor.apply()\n this.subscriptions.push(() => webSocketInterceptor.dispose())\n\n // Assert that the interceptor has been applied successfully.\n // Also guards us from forgetting to call \"interceptor.apply()\"\n // as a part of the \"listen\" method.\n invariant(\n [InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(\n this.interceptor.readyState,\n ),\n devUtils.formatMessage(\n 'Failed to start \"setupServer\": the interceptor failed to apply. This is likely an issue with the library and you should report it at \"%s\".',\n ),\n 'https://github.com/mswjs/msw/issues/new/choose',\n )\n }\n\n public close(): void {\n this.dispose()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiC;AACjC,4BAA0C;;;ACI1C,wBAA0B;AAC1B,0BAKO;AAEP,sBAAyB;AACzB,2BAA8B;AAE9B,yBAA4B;AAC5B,4BAA+B;AAE/B,wBAA2B;AAC3B,sBAAwC;AAExC,kCAAqC;AACrC,kCAAqC;AAE9B,IAAM,yBAAsD;AAAA,EACjE,oBAAoB;AACtB;AAEO,IAAM,uBAAN,cACG,yBAEV;AAAA,EACqB;AAAA,EAIX;AAAA,EAER,YACE,cACA,UACA;AACA,UAAM,GAAG,QAAQ;AAEjB,SAAK,cAAc,IAAI,qCAAiB;AAAA,MACtC,MAAM;AAAA,MACN,cAAc,aAAa,IAAI,CAAC,gBAAgB,IAAI,Y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KAAK,YAAY,QAAQ,CAAC;AAGxD,qDAAqB,MAAM;AAC3B,SAAK,cAAc,KAAK,MAAM,iDAAqB,QAAQ,CAAC;AAK5D;AAAA,MACE,CAAC,0CAAsB,UAAU,0CAAsB,OAAO,EAAE;AAAA,QAC9D,KAAK,YAAY;AAAA,MACnB;AAAA,MACA,yBAAS;AAAA,QACP;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEO,QAAc;AACnB,SAAK,QAAQ;AAAA,EACf;AACF;;;ADzIO,SAAS,eACX,UACmB;AAGtB,SAAO,IAAI;AAAA,IACT,CAAC,+BAAkB,+CAAyB;AAAA,IAC5C;AAAA,EACF;AACF;","names":[]}
|
package/lib/native/index.mjs
CHANGED
|
@@ -10,8 +10,12 @@ import {
|
|
|
10
10
|
} from "@mswjs/interceptors";
|
|
11
11
|
import { SetupApi } from '../core/SetupApi.mjs';
|
|
12
12
|
import { handleRequest } from '../core/utils/handleRequest.mjs';
|
|
13
|
+
import { HttpHandler } from '../core/handlers/HttpHandler.mjs';
|
|
14
|
+
import { GraphQLHandler } from '../core/handlers/GraphQLHandler.mjs';
|
|
13
15
|
import { mergeRight } from '../core/utils/internal/mergeRight.mjs';
|
|
14
16
|
import { InternalError, devUtils } from '../core/utils/internal/devUtils.mjs';
|
|
17
|
+
import { handleWebSocketEvent } from '../core/ws/handleWebSocketEvent.mjs';
|
|
18
|
+
import { webSocketInterceptor } from '../core/ws/webSocketInterceptor.mjs';
|
|
15
19
|
var DEFAULT_LISTEN_OPTIONS = {
|
|
16
20
|
onUnhandledRequest: "warn"
|
|
17
21
|
};
|
|
@@ -37,7 +41,9 @@ var SetupServerCommonApi = class extends SetupApi {
|
|
|
37
41
|
const response = await handleRequest(
|
|
38
42
|
request,
|
|
39
43
|
requestId,
|
|
40
|
-
this.handlersController.currentHandlers()
|
|
44
|
+
this.handlersController.currentHandlers().filter((handler) => {
|
|
45
|
+
return handler instanceof HttpHandler || handler instanceof GraphQLHandler;
|
|
46
|
+
}),
|
|
41
47
|
this.resolvedOptions,
|
|
42
48
|
this.emitter
|
|
43
49
|
);
|
|
@@ -65,6 +71,18 @@ var SetupServerCommonApi = class extends SetupApi {
|
|
|
65
71
|
);
|
|
66
72
|
}
|
|
67
73
|
);
|
|
74
|
+
handleWebSocketEvent({
|
|
75
|
+
getUnhandledRequestStrategy: () => {
|
|
76
|
+
return this.resolvedOptions.onUnhandledRequest;
|
|
77
|
+
},
|
|
78
|
+
getHandlers: () => {
|
|
79
|
+
return this.handlersController.currentHandlers();
|
|
80
|
+
},
|
|
81
|
+
onMockedConnection: () => {
|
|
82
|
+
},
|
|
83
|
+
onPassthroughConnection: () => {
|
|
84
|
+
}
|
|
85
|
+
});
|
|
68
86
|
}
|
|
69
87
|
listen(options = {}) {
|
|
70
88
|
this.resolvedOptions = mergeRight(
|
|
@@ -72,9 +90,9 @@ var SetupServerCommonApi = class extends SetupApi {
|
|
|
72
90
|
options
|
|
73
91
|
);
|
|
74
92
|
this.interceptor.apply();
|
|
75
|
-
this.subscriptions.push(() =>
|
|
76
|
-
|
|
77
|
-
|
|
93
|
+
this.subscriptions.push(() => this.interceptor.dispose());
|
|
94
|
+
webSocketInterceptor.apply();
|
|
95
|
+
this.subscriptions.push(() => webSocketInterceptor.dispose());
|
|
78
96
|
invariant(
|
|
79
97
|
[InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(
|
|
80
98
|
this.interceptor.readyState
|
package/lib/native/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerCommonApi.ts"],"sourcesContent":["import { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerCommonApi } from '../node/SetupServerCommonApi'\n\n/**\n * Sets up a requests interception in React Native with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport function setupServer(\n ...handlers: Array<RequestHandler>\n): SetupServerCommonApi {\n // Provision request interception via patching the `XMLHttpRequest` class only\n // in React Native. There is no `http`/`https` modules in that environment.\n return new SetupServerCommonApi(\n [FetchInterceptor, XMLHttpRequestInterceptor],\n handlers,\n )\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { InternalError, devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\n handlers: Array<RequestHandler>,\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\n\n this.resolvedOptions = {} as RequiredDeep<SharedOptions>\n\n this.init()\n }\n\n /**\n * Subscribe to all requests that are using the interceptor object\n */\n private init(): void {\n this.interceptor.on(\n 'request',\n async ({ request, requestId, controller }) => {\n const response = await handleRequest(\n request,\n requestId,\n this.handlersController.currentHandlers(),\n this.resolvedOptions,\n this.emitter,\n )\n\n if (response) {\n controller.respondWith(response)\n }\n\n return\n },\n )\n\n this.interceptor.on('unhandledException', ({ error }) => {\n if (error instanceof InternalError) {\n throw error\n }\n })\n\n this.interceptor.on(\n 'response',\n ({ response, isMockedResponse, request, requestId }) => {\n this.emitter.emit(\n isMockedResponse ? 'response:mocked' : 'response:bypass',\n {\n response,\n request,\n requestId,\n },\n )\n },\n )\n }\n\n public listen(options: Partial<SharedOptions> = {}): void {\n this.resolvedOptions = mergeRight(\n DEFAULT_LISTEN_OPTIONS,\n options,\n ) as RequiredDeep<SharedOptions>\n\n // Apply the interceptor when starting the server.\n this.interceptor.apply()\n
|
|
1
|
+
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerCommonApi.ts"],"sourcesContent":["import { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerCommonApi } from '../node/SetupServerCommonApi'\n\n/**\n * Sets up a requests interception in React Native with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport function setupServer(\n ...handlers: Array<RequestHandler>\n): SetupServerCommonApi {\n // Provision request interception via patching the `XMLHttpRequest` class only\n // in React Native. There is no `http`/`https` modules in that environment.\n return new SetupServerCommonApi(\n [FetchInterceptor, XMLHttpRequestInterceptor],\n handlers,\n )\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { HttpHandler } from '~/core/handlers/HttpHandler'\nimport { GraphQLHandler } from '~/core/handlers/GraphQLHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { InternalError, devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\nimport { handleWebSocketEvent } from '~/core/ws/handleWebSocketEvent'\nimport { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\n handlers: Array<RequestHandler | WebSocketHandler>,\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\n\n this.resolvedOptions = {} as RequiredDeep<SharedOptions>\n\n this.init()\n }\n\n /**\n * Subscribe to all requests that are using the interceptor object\n */\n private init(): void {\n this.interceptor.on(\n 'request',\n async ({ request, requestId, controller }) => {\n const response = await handleRequest(\n request,\n requestId,\n this.handlersController.currentHandlers().filter((handler) => {\n return (\n handler instanceof HttpHandler ||\n handler instanceof GraphQLHandler\n )\n }),\n this.resolvedOptions,\n this.emitter,\n )\n\n if (response) {\n controller.respondWith(response)\n }\n\n return\n },\n )\n\n this.interceptor.on('unhandledException', ({ error }) => {\n if (error instanceof InternalError) {\n throw error\n }\n })\n\n this.interceptor.on(\n 'response',\n ({ response, isMockedResponse, request, requestId }) => {\n this.emitter.emit(\n isMockedResponse ? 'response:mocked' : 'response:bypass',\n {\n response,\n request,\n requestId,\n },\n )\n },\n )\n\n // Preconfigure the WebSocket interception but don't enable it just yet.\n // It will be enabled when the server starts.\n handleWebSocketEvent({\n getUnhandledRequestStrategy: () => {\n return this.resolvedOptions.onUnhandledRequest\n },\n getHandlers: () => {\n return this.handlersController.currentHandlers()\n },\n onMockedConnection: () => {},\n onPassthroughConnection: () => {},\n })\n }\n\n public listen(options: Partial<SharedOptions> = {}): void {\n this.resolvedOptions = mergeRight(\n DEFAULT_LISTEN_OPTIONS,\n options,\n ) as RequiredDeep<SharedOptions>\n\n // Apply the interceptor when starting the server.\n this.interceptor.apply()\n this.subscriptions.push(() => this.interceptor.dispose())\n\n // Apply the WebSocket interception.\n webSocketInterceptor.apply()\n this.subscriptions.push(() => webSocketInterceptor.dispose())\n\n // Assert that the interceptor has been applied successfully.\n // Also guards us from forgetting to call \"interceptor.apply()\"\n // as a part of the \"listen\" method.\n invariant(\n [InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(\n this.interceptor.readyState,\n ),\n devUtils.formatMessage(\n 'Failed to start \"setupServer\": the interceptor failed to apply. This is likely an issue with the library and you should report it at \"%s\".',\n ),\n 'https://github.com/mswjs/msw/issues/new/choose',\n )\n }\n\n public close(): void {\n this.dispose()\n }\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAAS,iCAAiC;;;ACI1C,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAE9B,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAE/B,SAAS,kBAAkB;AAC3B,SAAS,eAAe,gBAAgB;AAExC,SAAS,4BAA4B;AACrC,SAAS,4BAA4B;AAE9B,IAAM,yBAAsD;AAAA,EACjE,oBAAoB;AACtB;AAEO,IAAM,uBAAN,cACG,SAEV;AAAA,EACqB;AAAA,EAIX;A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H;AAAA,EAEO,OAAO,UAAkC,CAAC,GAAS;AACxD,SAAK,kBAAkB;AAAA,MACrB;AAAA,MACA;AAAA,IACF;AAGA,SAAK,YAAY,MAAM;AACvB,SAAK,cAAc,KAAK,MAAM,KAAK,YAAY,QAAQ,CAAC;AAGxD,yBAAqB,MAAM;AAC3B,SAAK,cAAc,KAAK,MAAM,qBAAqB,QAAQ,CAAC;AAK5D;AAAA,MACE,CAAC,sBAAsB,UAAU,sBAAsB,OAAO,EAAE;AAAA,QAC9D,KAAK,YAAY;AAAA,MACnB;AAAA,MACA,SAAS;AAAA,QACP;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEO,QAAc;AACnB,SAAK,QAAQ;AAAA,EACf;AACF;;;ADzIO,SAAS,eACX,UACmB;AAGtB,SAAO,IAAI;AAAA,IACT,CAAC,kBAAkB,yBAAyB;AAAA,IAC5C;AAAA,EACF;AACF;","names":[]}
|
package/lib/node/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PartialDeep } from 'type-fest';
|
|
2
|
-
import { RequestHandler
|
|
2
|
+
import { RequestHandler } from "../core/handlers/RequestHandler";
|
|
3
|
+
import { WebSocketHandler } from "../core/handlers/WebSocketHandler";
|
|
3
4
|
import { SharedOptions, LifeCycleEventEmitter, LifeCycleEventsMap } from "../core/sharedOptions";
|
|
4
5
|
import { BatchInterceptor, Interceptor, HttpRequestEventMap } from '@mswjs/interceptors';
|
|
5
6
|
import { SetupApi } from "../core/SetupApi";
|
|
@@ -22,7 +23,7 @@ interface SetupServerCommon {
|
|
|
22
23
|
*
|
|
23
24
|
* @see {@link https://mswjs.io/docs/api/setup-server/use `server.use()` API reference}
|
|
24
25
|
*/
|
|
25
|
-
use(...handlers: Array<RequestHandler>): void;
|
|
26
|
+
use(...handlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
26
27
|
/**
|
|
27
28
|
* Marks all request handlers that respond using `res.once()` as unused.
|
|
28
29
|
*
|
|
@@ -34,13 +35,13 @@ interface SetupServerCommon {
|
|
|
34
35
|
*
|
|
35
36
|
* @see {@link https://mswjs.io/docs/api/setup-server/reset-handlers `server.reset-handlers()` API reference}
|
|
36
37
|
*/
|
|
37
|
-
resetHandlers(...nextHandlers: Array<RequestHandler>): void;
|
|
38
|
+
resetHandlers(...nextHandlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
38
39
|
/**
|
|
39
40
|
* Returns a readonly list of currently active request handlers.
|
|
40
41
|
*
|
|
41
42
|
* @see {@link https://mswjs.io/docs/api/setup-server/list-handlers `server.listHandlers()` API reference}
|
|
42
43
|
*/
|
|
43
|
-
listHandlers(): ReadonlyArray<RequestHandler
|
|
44
|
+
listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>;
|
|
44
45
|
/**
|
|
45
46
|
* Life-cycle events.
|
|
46
47
|
* Life-cycle events allow you to subscribe to the internal library events occurring during the request/response handling.
|
|
@@ -71,7 +72,7 @@ declare class SetupServerCommonApi extends SetupApi<LifeCycleEventsMap> implemen
|
|
|
71
72
|
private resolvedOptions;
|
|
72
73
|
constructor(interceptors: Array<{
|
|
73
74
|
new (): Interceptor<HttpRequestEventMap>;
|
|
74
|
-
}>, handlers: Array<RequestHandler>);
|
|
75
|
+
}>, handlers: Array<RequestHandler | WebSocketHandler>);
|
|
75
76
|
/**
|
|
76
77
|
* Subscribe to all requests that are using the interceptor object
|
|
77
78
|
*/
|
|
@@ -81,7 +82,7 @@ declare class SetupServerCommonApi extends SetupApi<LifeCycleEventsMap> implemen
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
declare class SetupServerApi extends SetupServerCommonApi implements SetupServer {
|
|
84
|
-
constructor(handlers: Array<RequestHandler>);
|
|
85
|
+
constructor(handlers: Array<RequestHandler | WebSocketHandler>);
|
|
85
86
|
boundary<Args extends Array<any>, R>(callback: (...args: Args) => R): (...args: Args) => R;
|
|
86
87
|
close(): void;
|
|
87
88
|
}
|
|
@@ -92,6 +93,6 @@ declare class SetupServerApi extends SetupServerCommonApi implements SetupServer
|
|
|
92
93
|
*
|
|
93
94
|
* @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}
|
|
94
95
|
*/
|
|
95
|
-
declare const setupServer: (...handlers: Array<RequestHandler>) => SetupServerApi;
|
|
96
|
+
declare const setupServer: (...handlers: Array<RequestHandler | WebSocketHandler>) => SetupServerApi;
|
|
96
97
|
|
|
97
98
|
export { type SetupServer, SetupServerApi, setupServer };
|
package/lib/node/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PartialDeep } from 'type-fest';
|
|
2
|
-
import { RequestHandler
|
|
2
|
+
import { RequestHandler } from "../core/handlers/RequestHandler";
|
|
3
|
+
import { WebSocketHandler } from "../core/handlers/WebSocketHandler";
|
|
3
4
|
import { SharedOptions, LifeCycleEventEmitter, LifeCycleEventsMap } from "../core/sharedOptions";
|
|
4
5
|
import { BatchInterceptor, Interceptor, HttpRequestEventMap } from '@mswjs/interceptors';
|
|
5
6
|
import { SetupApi } from "../core/SetupApi";
|
|
@@ -22,7 +23,7 @@ interface SetupServerCommon {
|
|
|
22
23
|
*
|
|
23
24
|
* @see {@link https://mswjs.io/docs/api/setup-server/use `server.use()` API reference}
|
|
24
25
|
*/
|
|
25
|
-
use(...handlers: Array<RequestHandler>): void;
|
|
26
|
+
use(...handlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
26
27
|
/**
|
|
27
28
|
* Marks all request handlers that respond using `res.once()` as unused.
|
|
28
29
|
*
|
|
@@ -34,13 +35,13 @@ interface SetupServerCommon {
|
|
|
34
35
|
*
|
|
35
36
|
* @see {@link https://mswjs.io/docs/api/setup-server/reset-handlers `server.reset-handlers()` API reference}
|
|
36
37
|
*/
|
|
37
|
-
resetHandlers(...nextHandlers: Array<RequestHandler>): void;
|
|
38
|
+
resetHandlers(...nextHandlers: Array<RequestHandler | WebSocketHandler>): void;
|
|
38
39
|
/**
|
|
39
40
|
* Returns a readonly list of currently active request handlers.
|
|
40
41
|
*
|
|
41
42
|
* @see {@link https://mswjs.io/docs/api/setup-server/list-handlers `server.listHandlers()` API reference}
|
|
42
43
|
*/
|
|
43
|
-
listHandlers(): ReadonlyArray<RequestHandler
|
|
44
|
+
listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>;
|
|
44
45
|
/**
|
|
45
46
|
* Life-cycle events.
|
|
46
47
|
* Life-cycle events allow you to subscribe to the internal library events occurring during the request/response handling.
|
|
@@ -71,7 +72,7 @@ declare class SetupServerCommonApi extends SetupApi<LifeCycleEventsMap> implemen
|
|
|
71
72
|
private resolvedOptions;
|
|
72
73
|
constructor(interceptors: Array<{
|
|
73
74
|
new (): Interceptor<HttpRequestEventMap>;
|
|
74
|
-
}>, handlers: Array<RequestHandler>);
|
|
75
|
+
}>, handlers: Array<RequestHandler | WebSocketHandler>);
|
|
75
76
|
/**
|
|
76
77
|
* Subscribe to all requests that are using the interceptor object
|
|
77
78
|
*/
|
|
@@ -81,7 +82,7 @@ declare class SetupServerCommonApi extends SetupApi<LifeCycleEventsMap> implemen
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
declare class SetupServerApi extends SetupServerCommonApi implements SetupServer {
|
|
84
|
-
constructor(handlers: Array<RequestHandler>);
|
|
85
|
+
constructor(handlers: Array<RequestHandler | WebSocketHandler>);
|
|
85
86
|
boundary<Args extends Array<any>, R>(callback: (...args: Args) => R): (...args: Args) => R;
|
|
86
87
|
close(): void;
|
|
87
88
|
}
|
|
@@ -92,6 +93,6 @@ declare class SetupServerApi extends SetupServerCommonApi implements SetupServer
|
|
|
92
93
|
*
|
|
93
94
|
* @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}
|
|
94
95
|
*/
|
|
95
|
-
declare const setupServer: (...handlers: Array<RequestHandler>) => SetupServerApi;
|
|
96
|
+
declare const setupServer: (...handlers: Array<RequestHandler | WebSocketHandler>) => SetupServerApi;
|
|
96
97
|
|
|
97
98
|
export { type SetupServer, SetupServerApi, setupServer };
|
package/lib/node/index.js
CHANGED
|
@@ -36,8 +36,12 @@ var import_outvariant = require("outvariant");
|
|
|
36
36
|
var import_interceptors = require("@mswjs/interceptors");
|
|
37
37
|
var import_SetupApi = require("../core/SetupApi.js");
|
|
38
38
|
var import_handleRequest = require("../core/utils/handleRequest.js");
|
|
39
|
+
var import_HttpHandler = require("../core/handlers/HttpHandler.js");
|
|
40
|
+
var import_GraphQLHandler = require("../core/handlers/GraphQLHandler.js");
|
|
39
41
|
var import_mergeRight = require("../core/utils/internal/mergeRight.js");
|
|
40
42
|
var import_devUtils = require("../core/utils/internal/devUtils.js");
|
|
43
|
+
var import_handleWebSocketEvent = require("../core/ws/handleWebSocketEvent.js");
|
|
44
|
+
var import_webSocketInterceptor = require("../core/ws/webSocketInterceptor.js");
|
|
41
45
|
var DEFAULT_LISTEN_OPTIONS = {
|
|
42
46
|
onUnhandledRequest: "warn"
|
|
43
47
|
};
|
|
@@ -63,7 +67,9 @@ var SetupServerCommonApi = class extends import_SetupApi.SetupApi {
|
|
|
63
67
|
const response = await (0, import_handleRequest.handleRequest)(
|
|
64
68
|
request,
|
|
65
69
|
requestId,
|
|
66
|
-
this.handlersController.currentHandlers()
|
|
70
|
+
this.handlersController.currentHandlers().filter((handler) => {
|
|
71
|
+
return handler instanceof import_HttpHandler.HttpHandler || handler instanceof import_GraphQLHandler.GraphQLHandler;
|
|
72
|
+
}),
|
|
67
73
|
this.resolvedOptions,
|
|
68
74
|
this.emitter
|
|
69
75
|
);
|
|
@@ -91,6 +97,18 @@ var SetupServerCommonApi = class extends import_SetupApi.SetupApi {
|
|
|
91
97
|
);
|
|
92
98
|
}
|
|
93
99
|
);
|
|
100
|
+
(0, import_handleWebSocketEvent.handleWebSocketEvent)({
|
|
101
|
+
getUnhandledRequestStrategy: () => {
|
|
102
|
+
return this.resolvedOptions.onUnhandledRequest;
|
|
103
|
+
},
|
|
104
|
+
getHandlers: () => {
|
|
105
|
+
return this.handlersController.currentHandlers();
|
|
106
|
+
},
|
|
107
|
+
onMockedConnection: () => {
|
|
108
|
+
},
|
|
109
|
+
onPassthroughConnection: () => {
|
|
110
|
+
}
|
|
111
|
+
});
|
|
94
112
|
}
|
|
95
113
|
listen(options = {}) {
|
|
96
114
|
this.resolvedOptions = (0, import_mergeRight.mergeRight)(
|
|
@@ -98,9 +116,9 @@ var SetupServerCommonApi = class extends import_SetupApi.SetupApi {
|
|
|
98
116
|
options
|
|
99
117
|
);
|
|
100
118
|
this.interceptor.apply();
|
|
101
|
-
this.subscriptions.push(() =>
|
|
102
|
-
|
|
103
|
-
|
|
119
|
+
this.subscriptions.push(() => this.interceptor.dispose());
|
|
120
|
+
import_webSocketInterceptor.webSocketInterceptor.apply();
|
|
121
|
+
this.subscriptions.push(() => import_webSocketInterceptor.webSocketInterceptor.dispose());
|
|
104
122
|
(0, import_outvariant.invariant)(
|
|
105
123
|
[import_interceptors.InterceptorReadyState.APPLYING, import_interceptors.InterceptorReadyState.APPLIED].includes(
|
|
106
124
|
this.interceptor.readyState
|
package/lib/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/node/index.ts","../../src/node/SetupServerApi.ts","../../src/node/SetupServerCommonApi.ts","../../src/node/setupServer.ts"],"sourcesContent":["export type { SetupServer } from './glossary'\nexport { SetupServerApi } from './SetupServerApi'\nexport { setupServer } from './setupServer'\n","import { AsyncLocalStorage } from 'node:async_hooks'\nimport { ClientRequestInterceptor } from '@mswjs/interceptors/ClientRequest'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { HandlersController } from '~/core/SetupApi'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { SetupServer } from './glossary'\nimport { SetupServerCommonApi } from './SetupServerCommonApi'\n\nconst store = new AsyncLocalStorage<RequestHandlersContext>()\n\ntype RequestHandlersContext = {\n initialHandlers: Array<RequestHandler>\n handlers: Array<RequestHandler>\n}\n\n/**\n * A handlers controller that utilizes `AsyncLocalStorage` in Node.js\n * to prevent the request handlers list from being a shared state\n * across mutliple tests.\n */\nclass AsyncHandlersController implements HandlersController {\n private rootContext: RequestHandlersContext\n\n constructor(initialHandlers: Array<RequestHandler>) {\n this.rootContext = { initialHandlers, handlers: [] }\n }\n\n get context(): RequestHandlersContext {\n return store.getStore() || this.rootContext\n }\n\n public prepend(runtimeHandlers: Array<RequestHandler>) {\n this.context.handlers.unshift(...runtimeHandlers)\n }\n\n public reset(nextHandlers: Array<RequestHandler>) {\n const context = this.context\n context.handlers = []\n context.initialHandlers =\n nextHandlers.length > 0 ? nextHandlers : context.initialHandlers\n }\n\n public currentHandlers(): Array<RequestHandler> {\n const { initialHandlers, handlers } = this.context\n return handlers.concat(initialHandlers)\n }\n}\n\nexport class SetupServerApi\n extends SetupServerCommonApi\n implements SetupServer\n{\n constructor(handlers: Array<RequestHandler>) {\n super(\n [ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor],\n handlers,\n )\n\n this.handlersController = new AsyncHandlersController(handlers)\n }\n\n public boundary<Args extends Array<any>, R>(\n callback: (...args: Args) => R,\n ): (...args: Args) => R {\n return (...args: Args): R => {\n return store.run<any, any>(\n {\n initialHandlers: this.handlersController.currentHandlers(),\n handlers: [],\n },\n callback,\n ...args,\n )\n }\n }\n\n public close(): void {\n super.close()\n store.disable()\n }\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { InternalError, devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\n handlers: Array<RequestHandler>,\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\n\n this.resolvedOptions = {} as RequiredDeep<SharedOptions>\n\n this.init()\n }\n\n /**\n * Subscribe to all requests that are using the interceptor object\n */\n private init(): void {\n this.interceptor.on(\n 'request',\n async ({ request, requestId, controller }) => {\n const response = await handleRequest(\n request,\n requestId,\n this.handlersController.currentHandlers(),\n this.resolvedOptions,\n this.emitter,\n )\n\n if (response) {\n controller.respondWith(response)\n }\n\n return\n },\n )\n\n this.interceptor.on('unhandledException', ({ error }) => {\n if (error instanceof InternalError) {\n throw error\n }\n })\n\n this.interceptor.on(\n 'response',\n ({ response, isMockedResponse, request, requestId }) => {\n this.emitter.emit(\n isMockedResponse ? 'response:mocked' : 'response:bypass',\n {\n response,\n request,\n requestId,\n },\n )\n },\n )\n }\n\n public listen(options: Partial<SharedOptions> = {}): void {\n this.resolvedOptions = mergeRight(\n DEFAULT_LISTEN_OPTIONS,\n options,\n ) as RequiredDeep<SharedOptions>\n\n // Apply the interceptor when starting the server.\n this.interceptor.apply()\n\n this.subscriptions.push(() => {\n this.interceptor.dispose()\n })\n\n // Assert that the interceptor has been applied successfully.\n // Also guards us from forgetting to call \"interceptor.apply()\"\n // as a part of the \"listen\" method.\n invariant(\n [InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(\n this.interceptor.readyState,\n ),\n devUtils.formatMessage(\n 'Failed to start \"setupServer\": the interceptor failed to apply. This is likely an issue with the library and you should report it at \"%s\".',\n ),\n 'https://github.com/mswjs/msw/issues/new/choose',\n )\n }\n\n public close(): void {\n this.dispose()\n }\n}\n","import type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerApi } from './SetupServerApi'\n\n/**\n * Sets up a requests interception in Node.js with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport const setupServer = (\n ...handlers: Array<RequestHandler>\n): SetupServerApi => {\n return new SetupServerApi(handlers)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,8BAAkC;AAClC,2BAAyC;AACzC,4BAA0C;AAC1C,mBAAiC;;;ACEjC,wBAA0B;AAC1B,0BAKO;AAEP,sBAAyB;AACzB,2BAA8B;AAE9B,wBAA2B;AAC3B,sBAAwC;AAGjC,IAAM,yBAAsD;AAAA,EACjE,oBAAoB;AACtB;AAEO,IAAM,uBAAN,cACG,yBAEV;AAAA,EACqB;AAAA,EAIX;AAAA,EAER,YACE,cACA,UACA;AACA,UAAM,GAAG,QAAQ;AAEjB,SAAK,cAAc,IAAI,qCAAiB;AAAA,MACtC,MAAM;AAAA,MACN,cAAc,aAAa,IAAI,CAAC,gBAAgB,IAAI,YAAY,CAAC;AAAA,IACnE,CAAC;AAED,SAAK,kBAAkB,CAAC;AAExB,SAAK,KAAK;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA,EAKQ,OAAa;AACnB,SAAK,YAAY;AAAA,MACf;AAAA,MACA,OAAO,EAAE,SAAS,WAAW,WAAW,MAAM;AAC5C,cAAM,WAAW,UAAM;AAAA,UACrB;AAAA,UACA;AAAA,UACA,KAAK,mBAAmB,gBAAgB;AAAA,UACxC,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AChD,UAAM,UAAU,KAAK;AACrB,YAAQ,WAAW,CAAC;AACpB,YAAQ,kBACN,aAAa,SAAS,IAAI,eAAe,QAAQ;AAAA,EACrD;AAAA,EAEO,kBAAyC;AAC9C,UAAM,EAAE,iBAAiB,SAAS,IAAI,KAAK;AAC3C,WAAO,SAAS,OAAO,eAAe;AAAA,EACxC;AACF;AAEO,IAAM,iBAAN,cACG,qBAEV;AAAA,EACE,YAAY,UAAiC;AAC3C;AAAA,MACE,CAAC,+CAA0B,iDAA2B,6BAAgB;AAAA,MACtE;AAAA,IACF;AAEA,SAAK,qBAAqB,IAAI,wBAAwB,QAAQ;AAAA,EAChE;AAAA,EAEO,SACL,UACsB;AACtB,WAAO,IAAI,SAAkB;AAC3B,aAAO,MAAM;AAAA,QACX;AAAA,UACE,iBAAiB,KAAK,mBAAmB,gBAAgB;AAAA,UACzD,UAAU,CAAC;AAAA,QACb;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAAA,EAEO,QAAc;AACnB,UAAM,MAAM;AACZ,UAAM,QAAQ;AAAA,EAChB;AACF;;;AExEO,IAAM,cAAc,IACtB,aACgB;AACnB,SAAO,IAAI,eAAe,QAAQ;AACpC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/node/index.ts","../../src/node/SetupServerApi.ts","../../src/node/SetupServerCommonApi.ts","../../src/node/setupServer.ts"],"sourcesContent":["export type { SetupServer } from './glossary'\nexport { SetupServerApi } from './SetupServerApi'\nexport { setupServer } from './setupServer'\n","import { AsyncLocalStorage } from 'node:async_hooks'\nimport { ClientRequestInterceptor } from '@mswjs/interceptors/ClientRequest'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { HandlersController } from '~/core/SetupApi'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport type { SetupServer } from './glossary'\nimport { SetupServerCommonApi } from './SetupServerCommonApi'\n\nconst store = new AsyncLocalStorage<RequestHandlersContext>()\n\ntype RequestHandlersContext = {\n initialHandlers: Array<RequestHandler | WebSocketHandler>\n handlers: Array<RequestHandler | WebSocketHandler>\n}\n\n/**\n * A handlers controller that utilizes `AsyncLocalStorage` in Node.js\n * to prevent the request handlers list from being a shared state\n * across mutliple tests.\n */\nclass AsyncHandlersController implements HandlersController {\n private rootContext: RequestHandlersContext\n\n constructor(initialHandlers: Array<RequestHandler | WebSocketHandler>) {\n this.rootContext = { initialHandlers, handlers: [] }\n }\n\n get context(): RequestHandlersContext {\n return store.getStore() || this.rootContext\n }\n\n public prepend(runtimeHandlers: Array<RequestHandler | WebSocketHandler>) {\n this.context.handlers.unshift(...runtimeHandlers)\n }\n\n public reset(nextHandlers: Array<RequestHandler | WebSocketHandler>) {\n const context = this.context\n context.handlers = []\n context.initialHandlers =\n nextHandlers.length > 0 ? nextHandlers : context.initialHandlers\n }\n\n public currentHandlers(): Array<RequestHandler | WebSocketHandler> {\n const { initialHandlers, handlers } = this.context\n return handlers.concat(initialHandlers)\n }\n}\n\nexport class SetupServerApi\n extends SetupServerCommonApi\n implements SetupServer\n{\n constructor(handlers: Array<RequestHandler | WebSocketHandler>) {\n super(\n [ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor],\n handlers,\n )\n\n this.handlersController = new AsyncHandlersController(handlers)\n }\n\n public boundary<Args extends Array<any>, R>(\n callback: (...args: Args) => R,\n ): (...args: Args) => R {\n return (...args: Args): R => {\n return store.run<any, any>(\n {\n initialHandlers: this.handlersController.currentHandlers(),\n handlers: [],\n },\n callback,\n ...args,\n )\n }\n }\n\n public close(): void {\n super.close()\n store.disable()\n }\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { HttpHandler } from '~/core/handlers/HttpHandler'\nimport { GraphQLHandler } from '~/core/handlers/GraphQLHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { InternalError, devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\nimport { handleWebSocketEvent } from '~/core/ws/handleWebSocketEvent'\nimport { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\n handlers: Array<RequestHandler | WebSocketHandler>,\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\n\n this.resolvedOptions = {} as RequiredDeep<SharedOptions>\n\n this.init()\n }\n\n /**\n * Subscribe to all requests that are using the interceptor object\n */\n private init(): void {\n this.interceptor.on(\n 'request',\n async ({ request, requestId, controller }) => {\n const response = await handleRequest(\n request,\n requestId,\n this.handlersController.currentHandlers().filter((handler) => {\n return (\n handler instanceof HttpHandler ||\n handler instanceof GraphQLHandler\n )\n }),\n this.resolvedOptions,\n this.emitter,\n )\n\n if (response) {\n controller.respondWith(response)\n }\n\n return\n },\n )\n\n this.interceptor.on('unhandledException', ({ error }) => {\n if (error instanceof InternalError) {\n throw error\n }\n })\n\n this.interceptor.on(\n 'response',\n ({ response, isMockedResponse, request, requestId }) => {\n this.emitter.emit(\n isMockedResponse ? 'response:mocked' : 'response:bypass',\n {\n response,\n request,\n requestId,\n },\n )\n },\n )\n\n // Preconfigure the WebSocket interception but don't enable it just yet.\n // It will be enabled when the server starts.\n handleWebSocketEvent({\n getUnhandledRequestStrategy: () => {\n return this.resolvedOptions.onUnhandledRequest\n },\n getHandlers: () => {\n return this.handlersController.currentHandlers()\n },\n onMockedConnection: () => {},\n onPassthroughConnection: () => {},\n })\n }\n\n public listen(options: Partial<SharedOptions> = {}): void {\n this.resolvedOptions = mergeRight(\n DEFAULT_LISTEN_OPTIONS,\n options,\n ) as RequiredDeep<SharedOptions>\n\n // Apply the interceptor when starting the server.\n this.interceptor.apply()\n this.subscriptions.push(() => this.interceptor.dispose())\n\n // Apply the WebSocket interception.\n webSocketInterceptor.apply()\n this.subscriptions.push(() => webSocketInterceptor.dispose())\n\n // Assert that the interceptor has been applied successfully.\n // Also guards us from forgetting to call \"interceptor.apply()\"\n // as a part of the \"listen\" method.\n invariant(\n [InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(\n this.interceptor.readyState,\n ),\n devUtils.formatMessage(\n 'Failed to start \"setupServer\": the interceptor failed to apply. This is likely an issue with the library and you should report it at \"%s\".',\n ),\n 'https://github.com/mswjs/msw/issues/new/choose',\n )\n }\n\n public close(): void {\n this.dispose()\n }\n}\n","import type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport { SetupServerApi } from './SetupServerApi'\n\n/**\n * Sets up a requests interception in Node.js with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport const setupServer = (\n ...handlers: Array<RequestHandler | WebSocketHandler>\n): SetupServerApi => {\n return new SetupServ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M,UAAU,KAAK;AACrB,YAAQ,WAAW,CAAC;AACpB,YAAQ,kBACN,aAAa,SAAS,IAAI,eAAe,QAAQ;AAAA,EACrD;AAAA,EAEO,kBAA4D;AACjE,UAAM,EAAE,iBAAiB,SAAS,IAAI,KAAK;AAC3C,WAAO,SAAS,OAAO,eAAe;AAAA,EACxC;AACF;AAEO,IAAM,iBAAN,cACG,qBAEV;AAAA,EACE,YAAY,UAAoD;AAC9D;AAAA,MACE,CAAC,+CAA0B,iDAA2B,6BAAgB;AAAA,MACtE;AAAA,IACF;AAEA,SAAK,qBAAqB,IAAI,wBAAwB,QAAQ;AAAA,EAChE;AAAA,EAEO,SACL,UACsB;AACtB,WAAO,IAAI,SAAkB;AAC3B,aAAO,MAAM;AAAA,QACX;AAAA,UACE,iBAAiB,KAAK,mBAAmB,gBAAgB;AAAA,UACzD,UAAU,CAAC;AAAA,QACb;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAAA,EAEO,QAAc;AACnB,UAAM,MAAM;AACZ,UAAM,QAAQ;AAAA,EAChB;AACF;;;AExEO,IAAM,cAAc,IACtB,aACgB;AACnB,SAAO,IAAI,eAAe,QAAQ;AACpC;","names":[]}
|
package/lib/node/index.mjs
CHANGED
|
@@ -12,8 +12,12 @@ import {
|
|
|
12
12
|
} from "@mswjs/interceptors";
|
|
13
13
|
import { SetupApi } from '../core/SetupApi.mjs';
|
|
14
14
|
import { handleRequest } from '../core/utils/handleRequest.mjs';
|
|
15
|
+
import { HttpHandler } from '../core/handlers/HttpHandler.mjs';
|
|
16
|
+
import { GraphQLHandler } from '../core/handlers/GraphQLHandler.mjs';
|
|
15
17
|
import { mergeRight } from '../core/utils/internal/mergeRight.mjs';
|
|
16
18
|
import { InternalError, devUtils } from '../core/utils/internal/devUtils.mjs';
|
|
19
|
+
import { handleWebSocketEvent } from '../core/ws/handleWebSocketEvent.mjs';
|
|
20
|
+
import { webSocketInterceptor } from '../core/ws/webSocketInterceptor.mjs';
|
|
17
21
|
var DEFAULT_LISTEN_OPTIONS = {
|
|
18
22
|
onUnhandledRequest: "warn"
|
|
19
23
|
};
|
|
@@ -39,7 +43,9 @@ var SetupServerCommonApi = class extends SetupApi {
|
|
|
39
43
|
const response = await handleRequest(
|
|
40
44
|
request,
|
|
41
45
|
requestId,
|
|
42
|
-
this.handlersController.currentHandlers()
|
|
46
|
+
this.handlersController.currentHandlers().filter((handler) => {
|
|
47
|
+
return handler instanceof HttpHandler || handler instanceof GraphQLHandler;
|
|
48
|
+
}),
|
|
43
49
|
this.resolvedOptions,
|
|
44
50
|
this.emitter
|
|
45
51
|
);
|
|
@@ -67,6 +73,18 @@ var SetupServerCommonApi = class extends SetupApi {
|
|
|
67
73
|
);
|
|
68
74
|
}
|
|
69
75
|
);
|
|
76
|
+
handleWebSocketEvent({
|
|
77
|
+
getUnhandledRequestStrategy: () => {
|
|
78
|
+
return this.resolvedOptions.onUnhandledRequest;
|
|
79
|
+
},
|
|
80
|
+
getHandlers: () => {
|
|
81
|
+
return this.handlersController.currentHandlers();
|
|
82
|
+
},
|
|
83
|
+
onMockedConnection: () => {
|
|
84
|
+
},
|
|
85
|
+
onPassthroughConnection: () => {
|
|
86
|
+
}
|
|
87
|
+
});
|
|
70
88
|
}
|
|
71
89
|
listen(options = {}) {
|
|
72
90
|
this.resolvedOptions = mergeRight(
|
|
@@ -74,9 +92,9 @@ var SetupServerCommonApi = class extends SetupApi {
|
|
|
74
92
|
options
|
|
75
93
|
);
|
|
76
94
|
this.interceptor.apply();
|
|
77
|
-
this.subscriptions.push(() =>
|
|
78
|
-
|
|
79
|
-
|
|
95
|
+
this.subscriptions.push(() => this.interceptor.dispose());
|
|
96
|
+
webSocketInterceptor.apply();
|
|
97
|
+
this.subscriptions.push(() => webSocketInterceptor.dispose());
|
|
80
98
|
invariant(
|
|
81
99
|
[InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(
|
|
82
100
|
this.interceptor.readyState
|
package/lib/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/node/SetupServerApi.ts","../../src/node/SetupServerCommonApi.ts","../../src/node/setupServer.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\nimport { ClientRequestInterceptor } from '@mswjs/interceptors/ClientRequest'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { HandlersController } from '~/core/SetupApi'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { SetupServer } from './glossary'\nimport { SetupServerCommonApi } from './SetupServerCommonApi'\n\nconst store = new AsyncLocalStorage<RequestHandlersContext>()\n\ntype RequestHandlersContext = {\n initialHandlers: Array<RequestHandler>\n handlers: Array<RequestHandler>\n}\n\n/**\n * A handlers controller that utilizes `AsyncLocalStorage` in Node.js\n * to prevent the request handlers list from being a shared state\n * across mutliple tests.\n */\nclass AsyncHandlersController implements HandlersController {\n private rootContext: RequestHandlersContext\n\n constructor(initialHandlers: Array<RequestHandler>) {\n this.rootContext = { initialHandlers, handlers: [] }\n }\n\n get context(): RequestHandlersContext {\n return store.getStore() || this.rootContext\n }\n\n public prepend(runtimeHandlers: Array<RequestHandler>) {\n this.context.handlers.unshift(...runtimeHandlers)\n }\n\n public reset(nextHandlers: Array<RequestHandler>) {\n const context = this.context\n context.handlers = []\n context.initialHandlers =\n nextHandlers.length > 0 ? nextHandlers : context.initialHandlers\n }\n\n public currentHandlers(): Array<RequestHandler> {\n const { initialHandlers, handlers } = this.context\n return handlers.concat(initialHandlers)\n }\n}\n\nexport class SetupServerApi\n extends SetupServerCommonApi\n implements SetupServer\n{\n constructor(handlers: Array<RequestHandler>) {\n super(\n [ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor],\n handlers,\n )\n\n this.handlersController = new AsyncHandlersController(handlers)\n }\n\n public boundary<Args extends Array<any>, R>(\n callback: (...args: Args) => R,\n ): (...args: Args) => R {\n return (...args: Args): R => {\n return store.run<any, any>(\n {\n initialHandlers: this.handlersController.currentHandlers(),\n handlers: [],\n },\n callback,\n ...args,\n )\n }\n }\n\n public close(): void {\n super.close()\n store.disable()\n }\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { InternalError, devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\n handlers: Array<RequestHandler>,\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\n\n this.resolvedOptions = {} as RequiredDeep<SharedOptions>\n\n this.init()\n }\n\n /**\n * Subscribe to all requests that are using the interceptor object\n */\n private init(): void {\n this.interceptor.on(\n 'request',\n async ({ request, requestId, controller }) => {\n const response = await handleRequest(\n request,\n requestId,\n this.handlersController.currentHandlers(),\n this.resolvedOptions,\n this.emitter,\n )\n\n if (response) {\n controller.respondWith(response)\n }\n\n return\n },\n )\n\n this.interceptor.on('unhandledException', ({ error }) => {\n if (error instanceof InternalError) {\n throw error\n }\n })\n\n this.interceptor.on(\n 'response',\n ({ response, isMockedResponse, request, requestId }) => {\n this.emitter.emit(\n isMockedResponse ? 'response:mocked' : 'response:bypass',\n {\n response,\n request,\n requestId,\n },\n )\n },\n )\n }\n\n public listen(options: Partial<SharedOptions> = {}): void {\n this.resolvedOptions = mergeRight(\n DEFAULT_LISTEN_OPTIONS,\n options,\n ) as RequiredDeep<SharedOptions>\n\n // Apply the interceptor when starting the server.\n this.interceptor.apply()\n\n this.subscriptions.push(() => {\n this.interceptor.dispose()\n })\n\n // Assert that the interceptor has been applied successfully.\n // Also guards us from forgetting to call \"interceptor.apply()\"\n // as a part of the \"listen\" method.\n invariant(\n [InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(\n this.interceptor.readyState,\n ),\n devUtils.formatMessage(\n 'Failed to start \"setupServer\": the interceptor failed to apply. This is likely an issue with the library and you should report it at \"%s\".',\n ),\n 'https://github.com/mswjs/msw/issues/new/choose',\n )\n }\n\n public close(): void {\n this.dispose()\n }\n}\n","import type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerApi } from './SetupServerApi'\n\n/**\n * Sets up a requests interception in Node.js with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport const setupServer = (\n ...handlers: Array<RequestHandler>\n): SetupServerApi => {\n return new SetupServerApi(handlers)\n}\n"],"mappings":";AAAA,SAAS,yBAAyB;AAClC,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAC1C,SAAS,wBAAwB;;;ACEjC,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAE9B,SAAS,kBAAkB;AAC3B,SAAS,eAAe,gBAAgB;AAGjC,IAAM,yBAAsD;A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c,IACtB,aACgB;AACnB,SAAO,IAAI,eAAe,QAAQ;AACpC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/node/SetupServerApi.ts","../../src/node/SetupServerCommonApi.ts","../../src/node/setupServer.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\nimport { ClientRequestInterceptor } from '@mswjs/interceptors/ClientRequest'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { HandlersController } from '~/core/SetupApi'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport type { SetupServer } from './glossary'\nimport { SetupServerCommonApi } from './SetupServerCommonApi'\n\nconst store = new AsyncLocalStorage<RequestHandlersContext>()\n\ntype RequestHandlersContext = {\n initialHandlers: Array<RequestHandler | WebSocketHandler>\n handlers: Array<RequestHandler | WebSocketHandler>\n}\n\n/**\n * A handlers controller that utilizes `AsyncLocalStorage` in Node.js\n * to prevent the request handlers list from being a shared state\n * across mutliple tests.\n */\nclass AsyncHandlersController implements HandlersController {\n private rootContext: RequestHandlersContext\n\n constructor(initialHandlers: Array<RequestHandler | WebSocketHandler>) {\n this.rootContext = { initialHandlers, handlers: [] }\n }\n\n get context(): RequestHandlersContext {\n return store.getStore() || this.rootContext\n }\n\n public prepend(runtimeHandlers: Array<RequestHandler | WebSocketHandler>) {\n this.context.handlers.unshift(...runtimeHandlers)\n }\n\n public reset(nextHandlers: Array<RequestHandler | WebSocketHandler>) {\n const context = this.context\n context.handlers = []\n context.initialHandlers =\n nextHandlers.length > 0 ? nextHandlers : context.initialHandlers\n }\n\n public currentHandlers(): Array<RequestHandler | WebSocketHandler> {\n const { initialHandlers, handlers } = this.context\n return handlers.concat(initialHandlers)\n }\n}\n\nexport class SetupServerApi\n extends SetupServerCommonApi\n implements SetupServer\n{\n constructor(handlers: Array<RequestHandler | WebSocketHandler>) {\n super(\n [ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor],\n handlers,\n )\n\n this.handlersController = new AsyncHandlersController(handlers)\n }\n\n public boundary<Args extends Array<any>, R>(\n callback: (...args: Args) => R,\n ): (...args: Args) => R {\n return (...args: Args): R => {\n return store.run<any, any>(\n {\n initialHandlers: this.handlersController.currentHandlers(),\n handlers: [],\n },\n callback,\n ...args,\n )\n }\n }\n\n public close(): void {\n super.close()\n store.disable()\n }\n}\n","/**\n * @note This API is extended by both \"msw/node\" and \"msw/native\"\n * so be minding about the things you import!\n */\nimport type { RequiredDeep } from 'type-fest'\nimport { invariant } from 'outvariant'\nimport {\n BatchInterceptor,\n InterceptorReadyState,\n type HttpRequestEventMap,\n type Interceptor,\n} from '@mswjs/interceptors'\nimport type { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { SetupApi } from '~/core/SetupApi'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { HttpHandler } from '~/core/handlers/HttpHandler'\nimport { GraphQLHandler } from '~/core/handlers/GraphQLHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { InternalError, devUtils } from '~/core/utils/internal/devUtils'\nimport type { SetupServerCommon } from './glossary'\nimport { handleWebSocketEvent } from '~/core/ws/handleWebSocketEvent'\nimport { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'\n\nexport const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerCommonApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServerCommon\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,\n handlers: Array<RequestHandler | WebSocketHandler>,\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\n\n this.resolvedOptions = {} as RequiredDeep<SharedOptions>\n\n this.init()\n }\n\n /**\n * Subscribe to all requests that are using the interceptor object\n */\n private init(): void {\n this.interceptor.on(\n 'request',\n async ({ request, requestId, controller }) => {\n const response = await handleRequest(\n request,\n requestId,\n this.handlersController.currentHandlers().filter((handler) => {\n return (\n handler instanceof HttpHandler ||\n handler instanceof GraphQLHandler\n )\n }),\n this.resolvedOptions,\n this.emitter,\n )\n\n if (response) {\n controller.respondWith(response)\n }\n\n return\n },\n )\n\n this.interceptor.on('unhandledException', ({ error }) => {\n if (error instanceof InternalError) {\n throw error\n }\n })\n\n this.interceptor.on(\n 'response',\n ({ response, isMockedResponse, request, requestId }) => {\n this.emitter.emit(\n isMockedResponse ? 'response:mocked' : 'response:bypass',\n {\n response,\n request,\n requestId,\n },\n )\n },\n )\n\n // Preconfigure the WebSocket interception but don't enable it just yet.\n // It will be enabled when the server starts.\n handleWebSocketEvent({\n getUnhandledRequestStrategy: () => {\n return this.resolvedOptions.onUnhandledRequest\n },\n getHandlers: () => {\n return this.handlersController.currentHandlers()\n },\n onMockedConnection: () => {},\n onPassthroughConnection: () => {},\n })\n }\n\n public listen(options: Partial<SharedOptions> = {}): void {\n this.resolvedOptions = mergeRight(\n DEFAULT_LISTEN_OPTIONS,\n options,\n ) as RequiredDeep<SharedOptions>\n\n // Apply the interceptor when starting the server.\n this.interceptor.apply()\n this.subscriptions.push(() => this.interceptor.dispose())\n\n // Apply the WebSocket interception.\n webSocketInterceptor.apply()\n this.subscriptions.push(() => webSocketInterceptor.dispose())\n\n // Assert that the interceptor has been applied successfully.\n // Also guards us from forgetting to call \"interceptor.apply()\"\n // as a part of the \"listen\" method.\n invariant(\n [InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(\n this.interceptor.readyState,\n ),\n devUtils.formatMessage(\n 'Failed to start \"setupServer\": the interceptor failed to apply. This is likely an issue with the library and you should report it at \"%s\".',\n ),\n 'https://github.com/mswjs/msw/issues/new/choose',\n )\n }\n\n public close(): void {\n this.dispose()\n }\n}\n","import type { RequestHandler } from '~/core/handlers/RequestHandler'\nimport type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'\nimport { SetupServerApi } from './SetupServerApi'\n\n/**\n * Sets up a requests interception in Node.js with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport const setupServer = (\n ...handlers: Array<RequestHandler | WebSocketHandler>\n): SetupServerApi => {\n return new SetupServerApi(handlers)\n}\n"],"mappings":";AAAA,SAAS,yBAAyB;AAClC,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAC1C,SAAS,wBAAwB;;;ACEjC,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAE9B,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAE/B,SAAS,kBAAkB;AAC3B,SAAS,eAAe,gBAAgB;AAExC,SAAS,4BAA4B;AACrC,SAAS,4BAA4B;AAE9B,IAAM,yBAAsD;AAAA,EACjE,oBAAoB;AACtB;AAEO,IAAM,uBAAN,cACG,SAEV;AAAA,EACqB;AAAA,EAIX;AAAA,EAER,YACE,cACA,UACA;AACA,UAAM,GAAG,QAAQ;AAEjB,SAAK,cAAc,IAAI,iBAAiB;AAAA,MACtC,MAAM;AAAA,MACN,cAAc,aAAa,IAAI,CAAC,gBAAgB,IAAI,YAAY,CAAC;AAAA,IACnE,CAAC;AAED,SAAK,kBAAkB,CAAC;AAExB,SAAK,KAAK;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA,EAKQ,OAAa;AACnB,SAAK,YAAY;AAAA,MACf;AAAA,MACA,OAAO,EAAE,SAAS,WAAW,WAAW,MA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