msw 2.6.0 → 2.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/index.js +121 -30
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +121 -30
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-Doool6Q_.d.mts → GraphQLHandler-B6uni-E_.d.mts} +1 -1
- package/lib/core/{GraphQLHandler-udzgBRPf.d.ts → GraphQLHandler-Cjm7JNGi.d.ts} +1 -1
- package/lib/core/{HttpResponse-BLGmJolh.d.mts → HttpResponse-63H9vVoL.d.mts} +2 -1
- package/lib/core/{HttpResponse-Cgbkdkje.d.ts → HttpResponse-DzhqZzTK.d.ts} +2 -1
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +2 -2
- package/lib/core/graphql.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.js +2 -0
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs +2 -0
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +1 -0
- package/lib/core/handlers/WebSocketHandler.d.ts +1 -0
- package/lib/core/handlers/WebSocketHandler.js +2 -0
- package/lib/core/handlers/WebSocketHandler.js.map +1 -1
- package/lib/core/handlers/WebSocketHandler.mjs +2 -0
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -1
- package/lib/core/handlers/common.d.mts +3 -0
- package/lib/core/handlers/common.d.ts +3 -0
- package/lib/core/handlers/common.js +17 -0
- package/lib/core/handlers/common.js.map +1 -0
- package/lib/core/handlers/common.mjs +1 -0
- package/lib/core/handlers/common.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 +2 -2
- package/lib/core/index.d.ts +2 -2
- 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 +0 -4
- package/lib/core/utils/executeHandlers.js.map +1 -1
- package/lib/core/utils/executeHandlers.mjs +0 -6
- 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/internal/isHandlerKind.d.mts +17 -0
- package/lib/core/utils/internal/isHandlerKind.d.ts +17 -0
- package/lib/core/utils/internal/isHandlerKind.js +29 -0
- package/lib/core/utils/internal/isHandlerKind.js.map +1 -0
- package/lib/core/utils/internal/isHandlerKind.mjs +9 -0
- package/lib/core/utils/internal/isHandlerKind.mjs.map +1 -0
- 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/request/getRequestCookies.js +12 -2
- package/lib/core/utils/request/getRequestCookies.js.map +1 -1
- package/lib/core/utils/request/getRequestCookies.mjs +12 -2
- package/lib/core/utils/request/getRequestCookies.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 +2 -1
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs +3 -2
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -1
- package/lib/iife/index.js +216 -73
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.js +2 -5
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +2 -5
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.js +2 -5
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +2 -5
- package/lib/node/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/browser/setupWorker/start/createFallbackRequestListener.ts +2 -1
- package/src/browser/setupWorker/start/createRequestListener.ts +2 -7
- package/src/core/handlers/RequestHandler.ts +4 -0
- package/src/core/handlers/WebSocketHandler.ts +4 -0
- package/src/core/handlers/common.ts +1 -0
- package/src/core/utils/executeHandlers.ts +1 -5
- package/src/core/utils/internal/isHandlerKind.test.ts +64 -0
- package/src/core/utils/internal/isHandlerKind.ts +21 -0
- package/src/core/utils/request/getRequestCookies.ts +15 -2
- package/src/core/ws/handleWebSocketEvent.ts +2 -1
- package/src/node/SetupServerCommonApi.ts +4 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/utils/executeHandlers.ts"],"sourcesContent":["import {\n RequestHandler,\n type RequestHandlerExecutionResult,\n} from '../handlers/RequestHandler'\n\nexport interface HandlersExecutionResult {\n handler: RequestHandler\n parsedResult?: any\n response?: Response\n}\n\nexport interface ResponseResolutionContext {\n baseUrl?: string\n}\n\n/**\n * Executes the list of request handlers against the given request.\n * Returns the execution result object containing any matching request\n * handler and any mocked response it returned.\n */\nexport const executeHandlers = async <Handlers extends Array<
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/executeHandlers.ts"],"sourcesContent":["import {\n RequestHandler,\n type RequestHandlerExecutionResult,\n} from '../handlers/RequestHandler'\n\nexport interface HandlersExecutionResult {\n handler: RequestHandler\n parsedResult?: any\n response?: Response\n}\n\nexport interface ResponseResolutionContext {\n baseUrl?: string\n}\n\n/**\n * Executes the list of request handlers against the given request.\n * Returns the execution result object containing any matching request\n * handler and any mocked response it returned.\n */\nexport const executeHandlers = async <Handlers extends Array<RequestHandler>>({\n request,\n requestId,\n handlers,\n resolutionContext,\n}: {\n request: Request\n requestId: string\n handlers: Handlers\n resolutionContext?: ResponseResolutionContext\n}): Promise<HandlersExecutionResult | null> => {\n let matchingHandler: RequestHandler | null = null\n let result: RequestHandlerExecutionResult<any> | null = null\n\n for (const handler of handlers) {\n result = await handler.run({ request, requestId, resolutionContext })\n\n // If the handler produces some result for this request,\n // it automatically becomes matching.\n if (result !== null) {\n matchingHandler = handler\n }\n\n // Stop the lookup if this handler returns a mocked response.\n // If it doesn't, it will still be considered the last matching\n // handler until any of them returns a response. This way we can\n // distinguish between fallthrough handlers without responses\n // and the lack of a matching handler.\n if (result?.response) {\n break\n }\n }\n\n if (matchingHandler) {\n return {\n handler: matchingHandler,\n parsedResult: result?.parsedResult,\n response: result?.response,\n }\n }\n\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBO,MAAM,kBAAkB,OAA+C;AAAA,EAC5E;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAK+C;AAC7C,MAAI,kBAAyC;AAC7C,MAAI,SAAoD;AAExD,aAAW,WAAW,UAAU;AAC9B,aAAS,MAAM,QAAQ,IAAI,EAAE,SAAS,WAAW,kBAAkB,CAAC;AAIpE,QAAI,WAAW,MAAM;AACnB,wBAAkB;AAAA,IACpB;AAOA,QAAI,QAAQ,UAAU;AACpB;AAAA,IACF;AAAA,EACF;AAEA,MAAI,iBAAiB;AACnB,WAAO;AAAA,MACL,SAAS;AAAA,MACT,cAAc,QAAQ;AAAA,MACtB,UAAU,QAAQ;AAAA,IACpB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RequestHandler
|
|
3
|
-
} from '../handlers/RequestHandler.mjs';
|
|
4
1
|
const executeHandlers = async ({
|
|
5
2
|
request,
|
|
6
3
|
requestId,
|
|
@@ -10,9 +7,6 @@ const executeHandlers = async ({
|
|
|
10
7
|
let matchingHandler = null;
|
|
11
8
|
let result = null;
|
|
12
9
|
for (const handler of handlers) {
|
|
13
|
-
if (!(handler instanceof RequestHandler)) {
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
10
|
result = await handler.run({ request, requestId, resolutionContext });
|
|
17
11
|
if (result !== null) {
|
|
18
12
|
matchingHandler = handler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/utils/executeHandlers.ts"],"sourcesContent":["import {\n RequestHandler,\n type RequestHandlerExecutionResult,\n} from '../handlers/RequestHandler'\n\nexport interface HandlersExecutionResult {\n handler: RequestHandler\n parsedResult?: any\n response?: Response\n}\n\nexport interface ResponseResolutionContext {\n baseUrl?: string\n}\n\n/**\n * Executes the list of request handlers against the given request.\n * Returns the execution result object containing any matching request\n * handler and any mocked response it returned.\n */\nexport const executeHandlers = async <Handlers extends Array<
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/executeHandlers.ts"],"sourcesContent":["import {\n RequestHandler,\n type RequestHandlerExecutionResult,\n} from '../handlers/RequestHandler'\n\nexport interface HandlersExecutionResult {\n handler: RequestHandler\n parsedResult?: any\n response?: Response\n}\n\nexport interface ResponseResolutionContext {\n baseUrl?: string\n}\n\n/**\n * Executes the list of request handlers against the given request.\n * Returns the execution result object containing any matching request\n * handler and any mocked response it returned.\n */\nexport const executeHandlers = async <Handlers extends Array<RequestHandler>>({\n request,\n requestId,\n handlers,\n resolutionContext,\n}: {\n request: Request\n requestId: string\n handlers: Handlers\n resolutionContext?: ResponseResolutionContext\n}): Promise<HandlersExecutionResult | null> => {\n let matchingHandler: RequestHandler | null = null\n let result: RequestHandlerExecutionResult<any> | null = null\n\n for (const handler of handlers) {\n result = await handler.run({ request, requestId, resolutionContext })\n\n // If the handler produces some result for this request,\n // it automatically becomes matching.\n if (result !== null) {\n matchingHandler = handler\n }\n\n // Stop the lookup if this handler returns a mocked response.\n // If it doesn't, it will still be considered the last matching\n // handler until any of them returns a response. This way we can\n // distinguish between fallthrough handlers without responses\n // and the lack of a matching handler.\n if (result?.response) {\n break\n }\n }\n\n if (matchingHandler) {\n return {\n handler: matchingHandler,\n parsedResult: result?.parsedResult,\n response: result?.response,\n }\n }\n\n return null\n}\n"],"mappings":"AAoBO,MAAM,kBAAkB,OAA+C;AAAA,EAC5E;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAK+C;AAC7C,MAAI,kBAAyC;AAC7C,MAAI,SAAoD;AAExD,aAAW,WAAW,UAAU;AAC9B,aAAS,MAAM,QAAQ,IAAI,EAAE,SAAS,WAAW,kBAAkB,CAAC;AAIpE,QAAI,WAAW,MAAM;AACnB,wBAAkB;AAAA,IACpB;AAOA,QAAI,QAAQ,UAAU;AACpB;AAAA,IACF;AAAA,EACF;AAEA,MAAI,iBAAiB;AACnB,WAAO;AAAA,MACL,SAAS;AAAA,MACT,cAAc,QAAQ;AAAA,MACtB,UAAU,QAAQ;AAAA,IACpB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Emitter } from 'strict-event-emitter';
|
|
2
2
|
import { SharedOptions, LifeCycleEventsMap } from '../sharedOptions.mjs';
|
|
3
3
|
import { RequiredDeep } from '../typeUtils.mjs';
|
|
4
|
-
import { i as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-
|
|
4
|
+
import { i as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-63H9vVoL.mjs';
|
|
5
5
|
import './request/onUnhandledRequest.mjs';
|
|
6
6
|
import './internal/isIterable.mjs';
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Emitter } from 'strict-event-emitter';
|
|
2
2
|
import { SharedOptions, LifeCycleEventsMap } from '../sharedOptions.js';
|
|
3
3
|
import { RequiredDeep } from '../typeUtils.js';
|
|
4
|
-
import { i as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-
|
|
4
|
+
import { i as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-DzhqZzTK.js';
|
|
5
5
|
import './request/onUnhandledRequest.js';
|
|
6
6
|
import './internal/isIterable.js';
|
|
7
7
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HandlerKind } from '../../handlers/common.mjs';
|
|
2
|
+
import { R as RequestHandler } from '../../HttpResponse-63H9vVoL.mjs';
|
|
3
|
+
import { WebSocketHandler } from '../../handlers/WebSocketHandler.mjs';
|
|
4
|
+
import './isIterable.mjs';
|
|
5
|
+
import '../../typeUtils.mjs';
|
|
6
|
+
import 'strict-event-emitter';
|
|
7
|
+
import '@mswjs/interceptors/WebSocket';
|
|
8
|
+
import '../matching/matchRequestUrl.mjs';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A filter function that ensures that the provided argument
|
|
12
|
+
* is a handler of the given kind. This helps differentiate
|
|
13
|
+
* between different kinds of handlers, e.g. request and event handlers.
|
|
14
|
+
*/
|
|
15
|
+
declare function isHandlerKind<K extends HandlerKind>(kind: K): (input: unknown) => input is K extends "EventHandler" ? WebSocketHandler : RequestHandler;
|
|
16
|
+
|
|
17
|
+
export { isHandlerKind };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HandlerKind } from '../../handlers/common.js';
|
|
2
|
+
import { R as RequestHandler } from '../../HttpResponse-DzhqZzTK.js';
|
|
3
|
+
import { WebSocketHandler } from '../../handlers/WebSocketHandler.js';
|
|
4
|
+
import './isIterable.js';
|
|
5
|
+
import '../../typeUtils.js';
|
|
6
|
+
import 'strict-event-emitter';
|
|
7
|
+
import '@mswjs/interceptors/WebSocket';
|
|
8
|
+
import '../matching/matchRequestUrl.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A filter function that ensures that the provided argument
|
|
12
|
+
* is a handler of the given kind. This helps differentiate
|
|
13
|
+
* between different kinds of handlers, e.g. request and event handlers.
|
|
14
|
+
*/
|
|
15
|
+
declare function isHandlerKind<K extends HandlerKind>(kind: K): (input: unknown) => input is K extends "EventHandler" ? WebSocketHandler : RequestHandler;
|
|
16
|
+
|
|
17
|
+
export { isHandlerKind };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var isHandlerKind_exports = {};
|
|
20
|
+
__export(isHandlerKind_exports, {
|
|
21
|
+
isHandlerKind: () => isHandlerKind
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(isHandlerKind_exports);
|
|
24
|
+
function isHandlerKind(kind) {
|
|
25
|
+
return (input) => {
|
|
26
|
+
return input != null && typeof input === "object" && "__kind" in input && input.__kind === kind;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=isHandlerKind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/internal/isHandlerKind.ts"],"sourcesContent":["import type { HandlerKind } from '../../handlers/common'\nimport type { RequestHandler } from '../../handlers/RequestHandler'\nimport type { WebSocketHandler } from '../../handlers/WebSocketHandler'\n\n/**\n * A filter function that ensures that the provided argument\n * is a handler of the given kind. This helps differentiate\n * between different kinds of handlers, e.g. request and event handlers.\n */\nexport function isHandlerKind<K extends HandlerKind>(kind: K) {\n return (\n input: unknown,\n ): input is K extends 'EventHandler' ? WebSocketHandler : RequestHandler => {\n return (\n input != null &&\n typeof input === 'object' &&\n '__kind' in input &&\n input.__kind === kind\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASO,SAAS,cAAqC,MAAS;AAC5D,SAAO,CACL,UAC0E;AAC1E,WACE,SAAS,QACT,OAAO,UAAU,YACjB,YAAY,SACZ,MAAM,WAAW;AAAA,EAErB;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/internal/isHandlerKind.ts"],"sourcesContent":["import type { HandlerKind } from '../../handlers/common'\nimport type { RequestHandler } from '../../handlers/RequestHandler'\nimport type { WebSocketHandler } from '../../handlers/WebSocketHandler'\n\n/**\n * A filter function that ensures that the provided argument\n * is a handler of the given kind. This helps differentiate\n * between different kinds of handlers, e.g. request and event handlers.\n */\nexport function isHandlerKind<K extends HandlerKind>(kind: K) {\n return (\n input: unknown,\n ): input is K extends 'EventHandler' ? WebSocketHandler : RequestHandler => {\n return (\n input != null &&\n typeof input === 'object' &&\n '__kind' in input &&\n input.__kind === kind\n )\n }\n}\n"],"mappings":"AASO,SAAS,cAAqC,MAAS;AAC5D,SAAO,CACL,UAC0E;AAC1E,WACE,SAAS,QACT,OAAO,UAAU,YACjB,YAAY,SACZ,MAAM,WAAW;AAAA,EAErB;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-
|
|
3
|
-
import '../../HttpResponse-
|
|
2
|
+
export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-B6uni-E_.mjs';
|
|
3
|
+
import '../../HttpResponse-63H9vVoL.mjs';
|
|
4
4
|
import './isIterable.mjs';
|
|
5
5
|
import '../../typeUtils.mjs';
|
|
6
6
|
import '../matching/matchRequestUrl.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-
|
|
3
|
-
import '../../HttpResponse-
|
|
2
|
+
export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-Cjm7JNGi.js';
|
|
3
|
+
import '../../HttpResponse-DzhqZzTK.js';
|
|
4
4
|
import './isIterable.js';
|
|
5
5
|
import '../../typeUtils.js';
|
|
6
6
|
import '../matching/matchRequestUrl.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-
|
|
1
|
+
import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-63H9vVoL.mjs';
|
|
2
2
|
import './isIterable.mjs';
|
|
3
3
|
import '../../typeUtils.mjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-
|
|
1
|
+
import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-DzhqZzTK.js';
|
|
2
2
|
import './isIterable.js';
|
|
3
3
|
import '../../typeUtils.js';
|
|
4
4
|
|
|
@@ -33,8 +33,18 @@ __export(getRequestCookies_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(getRequestCookies_exports);
|
|
34
34
|
var import_cookie = __toESM(require("@bundled-es-modules/cookie"));
|
|
35
35
|
var import_cookieStore = require("../cookieStore.js");
|
|
36
|
+
function parseCookies(input) {
|
|
37
|
+
const parsedCookies = import_cookie.default.parse(input);
|
|
38
|
+
const cookies = {};
|
|
39
|
+
for (const cookieName in parsedCookies) {
|
|
40
|
+
if (typeof parsedCookies[cookieName] !== "undefined") {
|
|
41
|
+
cookies[cookieName] = parsedCookies[cookieName];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return cookies;
|
|
45
|
+
}
|
|
36
46
|
function getAllDocumentCookies() {
|
|
37
|
-
return
|
|
47
|
+
return parseCookies(document.cookie);
|
|
38
48
|
}
|
|
39
49
|
function getDocumentCookies(request) {
|
|
40
50
|
if (typeof document === "undefined" || typeof location === "undefined") {
|
|
@@ -55,7 +65,7 @@ function getDocumentCookies(request) {
|
|
|
55
65
|
}
|
|
56
66
|
function getAllRequestCookies(request) {
|
|
57
67
|
const requestCookieHeader = request.headers.get("cookie");
|
|
58
|
-
const cookiesFromHeaders = requestCookieHeader ?
|
|
68
|
+
const cookiesFromHeaders = requestCookieHeader ? parseCookies(requestCookieHeader) : {};
|
|
59
69
|
const cookiesFromDocument = getDocumentCookies(request);
|
|
60
70
|
for (const name in cookiesFromDocument) {
|
|
61
71
|
request.headers.append(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/request/getRequestCookies.ts"],"sourcesContent":["import cookieUtils from '@bundled-es-modules/cookie'\nimport { cookieStore } from '../cookieStore'\n\nfunction
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/getRequestCookies.ts"],"sourcesContent":["import cookieUtils from '@bundled-es-modules/cookie'\nimport { cookieStore } from '../cookieStore'\n\nfunction parseCookies(input: string): Record<string, string> {\n const parsedCookies = cookieUtils.parse(input)\n const cookies: Record<string, string> = {}\n\n for (const cookieName in parsedCookies) {\n if (typeof parsedCookies[cookieName] !== 'undefined') {\n cookies[cookieName] = parsedCookies[cookieName]\n }\n }\n\n return cookies\n}\n\nfunction getAllDocumentCookies() {\n return parseCookies(document.cookie)\n}\n\nfunction getDocumentCookies(request: Request): Record<string, string> {\n if (typeof document === 'undefined' || typeof location === 'undefined') {\n return {}\n }\n\n switch (request.credentials) {\n case 'same-origin': {\n const requestUrl = new URL(request.url)\n\n // Return document cookies only when requested a resource\n // from the same origin as the current document.\n return location.origin === requestUrl.origin\n ? getAllDocumentCookies()\n : {}\n }\n\n case 'include': {\n // Return all document cookies.\n return getAllDocumentCookies()\n }\n\n default: {\n return {}\n }\n }\n}\n\nexport function getAllRequestCookies(request: Request): Record<string, string> {\n /**\n * @note While the \"cookie\" header is a forbidden header field\n * in the browser, you can read it in Node.js. We need to respect\n * it for mocking in Node.js.\n */\n const requestCookieHeader = request.headers.get('cookie')\n const cookiesFromHeaders = requestCookieHeader\n ? parseCookies(requestCookieHeader)\n : {}\n\n const cookiesFromDocument = getDocumentCookies(request)\n\n // Forward the document cookies to the request headers.\n for (const name in cookiesFromDocument) {\n request.headers.append(\n 'cookie',\n cookieUtils.serialize(name, cookiesFromDocument[name]),\n )\n }\n\n const cookiesFromStore = cookieStore.getCookiesSync(request.url)\n const storedCookiesObject = Object.fromEntries(\n cookiesFromStore.map((cookie) => [cookie.key, cookie.value]),\n )\n\n // Forward the raw stored cookies to request headers\n // so they contain metadata like \"expires\", \"secure\", etc.\n for (const cookie of cookiesFromStore) {\n request.headers.append('cookie', cookie.toString())\n }\n\n return {\n ...cookiesFromDocument,\n ...storedCookiesObject,\n ...cookiesFromHeaders,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAwB;AACxB,yBAA4B;AAE5B,SAAS,aAAa,OAAuC;AAC3D,QAAM,gBAAgB,cAAAA,QAAY,MAAM,KAAK;AAC7C,QAAM,UAAkC,CAAC;AAEzC,aAAW,cAAc,eAAe;AACtC,QAAI,OAAO,cAAc,UAAU,MAAM,aAAa;AACpD,cAAQ,UAAU,IAAI,cAAc,UAAU;AAAA,IAChD;AAAA,EACF;AAEA,SAAO;AACT;AAEA,SAAS,wBAAwB;AAC/B,SAAO,aAAa,SAAS,MAAM;AACrC;AAEA,SAAS,mBAAmB,SAA0C;AACpE,MAAI,OAAO,aAAa,eAAe,OAAO,aAAa,aAAa;AACtE,WAAO,CAAC;AAAA,EACV;AAEA,UAAQ,QAAQ,aAAa;AAAA,IAC3B,KAAK,eAAe;AAClB,YAAM,aAAa,IAAI,IAAI,QAAQ,GAAG;AAItC,aAAO,SAAS,WAAW,WAAW,SAClC,sBAAsB,IACtB,CAAC;AAAA,IACP;AAAA,IAEA,KAAK,WAAW;AAEd,aAAO,sBAAsB;AAAA,IAC/B;AAAA,IAEA,SAAS;AACP,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,SAA0C;AAM7E,QAAM,sBAAsB,QAAQ,QAAQ,IAAI,QAAQ;AACxD,QAAM,qBAAqB,sBACvB,aAAa,mBAAmB,IAChC,CAAC;AAEL,QAAM,sBAAsB,mBAAmB,OAAO;AAGtD,aAAW,QAAQ,qBAAqB;AACtC,YAAQ,QAAQ;AAAA,MACd;AAAA,MACA,cAAAA,QAAY,UAAU,MAAM,oBAAoB,IAAI,CAAC;AAAA,IACvD;AAAA,EACF;AAEA,QAAM,mBAAmB,+BAAY,eAAe,QAAQ,GAAG;AAC/D,QAAM,sBAAsB,OAAO;AAAA,IACjC,iBAAiB,IAAI,CAAC,WAAW,CAAC,OAAO,KAAK,OAAO,KAAK,CAAC;AAAA,EAC7D;AAIA,aAAW,UAAU,kBAAkB;AACrC,YAAQ,QAAQ,OAAO,UAAU,OAAO,SAAS,CAAC;AAAA,EACpD;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;","names":["cookieUtils"]}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import cookieUtils from "@bundled-es-modules/cookie";
|
|
2
2
|
import { cookieStore } from '../cookieStore.mjs';
|
|
3
|
+
function parseCookies(input) {
|
|
4
|
+
const parsedCookies = cookieUtils.parse(input);
|
|
5
|
+
const cookies = {};
|
|
6
|
+
for (const cookieName in parsedCookies) {
|
|
7
|
+
if (typeof parsedCookies[cookieName] !== "undefined") {
|
|
8
|
+
cookies[cookieName] = parsedCookies[cookieName];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return cookies;
|
|
12
|
+
}
|
|
3
13
|
function getAllDocumentCookies() {
|
|
4
|
-
return
|
|
14
|
+
return parseCookies(document.cookie);
|
|
5
15
|
}
|
|
6
16
|
function getDocumentCookies(request) {
|
|
7
17
|
if (typeof document === "undefined" || typeof location === "undefined") {
|
|
@@ -22,7 +32,7 @@ function getDocumentCookies(request) {
|
|
|
22
32
|
}
|
|
23
33
|
function getAllRequestCookies(request) {
|
|
24
34
|
const requestCookieHeader = request.headers.get("cookie");
|
|
25
|
-
const cookiesFromHeaders = requestCookieHeader ?
|
|
35
|
+
const cookiesFromHeaders = requestCookieHeader ? parseCookies(requestCookieHeader) : {};
|
|
26
36
|
const cookiesFromDocument = getDocumentCookies(request);
|
|
27
37
|
for (const name in cookiesFromDocument) {
|
|
28
38
|
request.headers.append(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/request/getRequestCookies.ts"],"sourcesContent":["import cookieUtils from '@bundled-es-modules/cookie'\nimport { cookieStore } from '../cookieStore'\n\nfunction
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/getRequestCookies.ts"],"sourcesContent":["import cookieUtils from '@bundled-es-modules/cookie'\nimport { cookieStore } from '../cookieStore'\n\nfunction parseCookies(input: string): Record<string, string> {\n const parsedCookies = cookieUtils.parse(input)\n const cookies: Record<string, string> = {}\n\n for (const cookieName in parsedCookies) {\n if (typeof parsedCookies[cookieName] !== 'undefined') {\n cookies[cookieName] = parsedCookies[cookieName]\n }\n }\n\n return cookies\n}\n\nfunction getAllDocumentCookies() {\n return parseCookies(document.cookie)\n}\n\nfunction getDocumentCookies(request: Request): Record<string, string> {\n if (typeof document === 'undefined' || typeof location === 'undefined') {\n return {}\n }\n\n switch (request.credentials) {\n case 'same-origin': {\n const requestUrl = new URL(request.url)\n\n // Return document cookies only when requested a resource\n // from the same origin as the current document.\n return location.origin === requestUrl.origin\n ? getAllDocumentCookies()\n : {}\n }\n\n case 'include': {\n // Return all document cookies.\n return getAllDocumentCookies()\n }\n\n default: {\n return {}\n }\n }\n}\n\nexport function getAllRequestCookies(request: Request): Record<string, string> {\n /**\n * @note While the \"cookie\" header is a forbidden header field\n * in the browser, you can read it in Node.js. We need to respect\n * it for mocking in Node.js.\n */\n const requestCookieHeader = request.headers.get('cookie')\n const cookiesFromHeaders = requestCookieHeader\n ? parseCookies(requestCookieHeader)\n : {}\n\n const cookiesFromDocument = getDocumentCookies(request)\n\n // Forward the document cookies to the request headers.\n for (const name in cookiesFromDocument) {\n request.headers.append(\n 'cookie',\n cookieUtils.serialize(name, cookiesFromDocument[name]),\n )\n }\n\n const cookiesFromStore = cookieStore.getCookiesSync(request.url)\n const storedCookiesObject = Object.fromEntries(\n cookiesFromStore.map((cookie) => [cookie.key, cookie.value]),\n )\n\n // Forward the raw stored cookies to request headers\n // so they contain metadata like \"expires\", \"secure\", etc.\n for (const cookie of cookiesFromStore) {\n request.headers.append('cookie', cookie.toString())\n }\n\n return {\n ...cookiesFromDocument,\n ...storedCookiesObject,\n ...cookiesFromHeaders,\n }\n}\n"],"mappings":"AAAA,OAAO,iBAAiB;AACxB,SAAS,mBAAmB;AAE5B,SAAS,aAAa,OAAuC;AAC3D,QAAM,gBAAgB,YAAY,MAAM,KAAK;AAC7C,QAAM,UAAkC,CAAC;AAEzC,aAAW,cAAc,eAAe;AACtC,QAAI,OAAO,cAAc,UAAU,MAAM,aAAa;AACpD,cAAQ,UAAU,IAAI,cAAc,UAAU;AAAA,IAChD;AAAA,EACF;AAEA,SAAO;AACT;AAEA,SAAS,wBAAwB;AAC/B,SAAO,aAAa,SAAS,MAAM;AACrC;AAEA,SAAS,mBAAmB,SAA0C;AACpE,MAAI,OAAO,aAAa,eAAe,OAAO,aAAa,aAAa;AACtE,WAAO,CAAC;AAAA,EACV;AAEA,UAAQ,QAAQ,aAAa;AAAA,IAC3B,KAAK,eAAe;AAClB,YAAM,aAAa,IAAI,IAAI,QAAQ,GAAG;AAItC,aAAO,SAAS,WAAW,WAAW,SAClC,sBAAsB,IACtB,CAAC;AAAA,IACP;AAAA,IAEA,KAAK,WAAW;AAEd,aAAO,sBAAsB;AAAA,IAC/B;AAAA,IAEA,SAAS;AACP,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,SAA0C;AAM7E,QAAM,sBAAsB,QAAQ,QAAQ,IAAI,QAAQ;AACxD,QAAM,qBAAqB,sBACvB,aAAa,mBAAmB,IAChC,CAAC;AAEL,QAAM,sBAAsB,mBAAmB,OAAO;AAGtD,aAAW,QAAQ,qBAAqB;AACtC,YAAQ,QAAQ;AAAA,MACd;AAAA,MACA,YAAY,UAAU,MAAM,oBAAoB,IAAI,CAAC;AAAA,IACvD;AAAA,EACF;AAEA,QAAM,mBAAmB,YAAY,eAAe,QAAQ,GAAG;AAC/D,QAAM,sBAAsB,OAAO;AAAA,IACjC,iBAAiB,IAAI,CAAC,WAAW,CAAC,OAAO,KAAK,OAAO,KAAK,CAAC;AAAA,EAC7D;AAIA,aAAW,UAAU,kBAAkB;AACrC,YAAQ,QAAQ,OAAO,UAAU,OAAO,SAAS,CAAC;AAAA,EACpD;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket';
|
|
2
|
-
import { R as RequestHandler } from '../HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from '../HttpResponse-63H9vVoL.mjs';
|
|
3
3
|
import { WebSocketHandler } from '../handlers/WebSocketHandler.mjs';
|
|
4
4
|
import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.mjs';
|
|
5
5
|
import '../utils/internal/isIterable.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket';
|
|
2
|
-
import { R as RequestHandler } from '../HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from '../HttpResponse-DzhqZzTK.js';
|
|
3
3
|
import { WebSocketHandler } from '../handlers/WebSocketHandler.js';
|
|
4
4
|
import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.js';
|
|
5
5
|
import '../utils/internal/isIterable.js';
|
|
@@ -24,6 +24,7 @@ module.exports = __toCommonJS(handleWebSocketEvent_exports);
|
|
|
24
24
|
var import_WebSocketHandler = require("../handlers/WebSocketHandler.js");
|
|
25
25
|
var import_webSocketInterceptor = require("./webSocketInterceptor.js");
|
|
26
26
|
var import_onUnhandledRequest = require("../utils/request/onUnhandledRequest.js");
|
|
27
|
+
var import_isHandlerKind = require("../utils/internal/isHandlerKind.js");
|
|
27
28
|
function handleWebSocketEvent(options) {
|
|
28
29
|
import_webSocketInterceptor.webSocketInterceptor.on("connection", async (connection) => {
|
|
29
30
|
const handlers = options.getHandlers();
|
|
@@ -32,7 +33,7 @@ function handleWebSocketEvent(options) {
|
|
|
32
33
|
});
|
|
33
34
|
const matchingHandlers = [];
|
|
34
35
|
for (const handler of handlers) {
|
|
35
|
-
if (
|
|
36
|
+
if ((0, import_isHandlerKind.isHandlerKind)("EventHandler")(handler) && handler.predicate({
|
|
36
37
|
event: connectionEvent,
|
|
37
38
|
parsedResult: handler.parse({
|
|
38
39
|
event: connectionEvent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/ws/handleWebSocketEvent.ts"],"sourcesContent":["import type { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport { RequestHandler } from '../handlers/RequestHandler'\nimport { WebSocketHandler, kDispatchEvent } from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from './webSocketInterceptor'\nimport {\n onUnhandledRequest,\n UnhandledRequestStrategy,\n} from '../utils/request/onUnhandledRequest'\n\ninterface HandleWebSocketEventOptions {\n getUnhandledRequestStrategy: () => UnhandledRequestStrategy\n getHandlers: () => Array<RequestHandler | WebSocketHandler>\n onMockedConnection: (connection: WebSocketConnectionData) => void\n onPassthroughConnection: (onnection: WebSocketConnectionData) => void\n}\n\nexport function handleWebSocketEvent(options: HandleWebSocketEventOptions) {\n webSocketInterceptor.on('connection', async (connection) => {\n const handlers = options.getHandlers()\n\n const connectionEvent = new MessageEvent('connection', {\n data: connection,\n })\n\n // First, filter only those WebSocket handlers that\n // match the \"ws.link()\" endpoint predicate. Don't dispatch\n // anything yet so the logger can be attached to the connection\n // before it potentially sends events.\n const matchingHandlers: Array<WebSocketHandler> = []\n\n for (const handler of handlers) {\n if (\n handler
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/handleWebSocketEvent.ts"],"sourcesContent":["import type { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport { RequestHandler } from '../handlers/RequestHandler'\nimport { WebSocketHandler, kDispatchEvent } from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from './webSocketInterceptor'\nimport {\n onUnhandledRequest,\n UnhandledRequestStrategy,\n} from '../utils/request/onUnhandledRequest'\nimport { isHandlerKind } from '../utils/internal/isHandlerKind'\n\ninterface HandleWebSocketEventOptions {\n getUnhandledRequestStrategy: () => UnhandledRequestStrategy\n getHandlers: () => Array<RequestHandler | WebSocketHandler>\n onMockedConnection: (connection: WebSocketConnectionData) => void\n onPassthroughConnection: (onnection: WebSocketConnectionData) => void\n}\n\nexport function handleWebSocketEvent(options: HandleWebSocketEventOptions) {\n webSocketInterceptor.on('connection', async (connection) => {\n const handlers = options.getHandlers()\n\n const connectionEvent = new MessageEvent('connection', {\n data: connection,\n })\n\n // First, filter only those WebSocket handlers that\n // match the \"ws.link()\" endpoint predicate. Don't dispatch\n // anything yet so the logger can be attached to the connection\n // before it potentially sends events.\n const matchingHandlers: Array<WebSocketHandler> = []\n\n for (const handler of handlers) {\n if (\n isHandlerKind('EventHandler')(handler) &&\n handler.predicate({\n event: connectionEvent,\n parsedResult: handler.parse({\n event: connectionEvent,\n }),\n })\n ) {\n matchingHandlers.push(handler)\n }\n }\n\n if (matchingHandlers.length > 0) {\n options?.onMockedConnection(connection)\n\n // Iterate over the handlers and forward the connection\n // event to WebSocket event handlers. This is equivalent\n // to dispatching that event onto multiple listeners.\n for (const handler of matchingHandlers) {\n handler[kDispatchEvent](connectionEvent)\n }\n } else {\n // Construct a request representing this WebSocket connection.\n const request = new Request(connection.client.url, {\n headers: {\n upgrade: 'websocket',\n connection: 'upgrade',\n },\n })\n await onUnhandledRequest(\n request,\n options.getUnhandledRequestStrategy(),\n ).catch((error) => {\n const errorEvent = new Event('error')\n Object.defineProperty(errorEvent, 'cause', {\n enumerable: true,\n configurable: false,\n value: error,\n })\n connection.client.socket.dispatchEvent(errorEvent)\n })\n\n options?.onPassthroughConnection(connection)\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n connection.server.connect()\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,8BAAiD;AACjD,kCAAqC;AACrC,gCAGO;AACP,2BAA8B;AASvB,SAAS,qBAAqB,SAAsC;AACzE,mDAAqB,GAAG,cAAc,OAAO,eAAe;AAC1D,UAAM,WAAW,QAAQ,YAAY;AAErC,UAAM,kBAAkB,IAAI,aAAa,cAAc;AAAA,MACrD,MAAM;AAAA,IACR,CAAC;AAMD,UAAM,mBAA4C,CAAC;AAEnD,eAAW,WAAW,UAAU;AAC9B,cACE,oCAAc,cAAc,EAAE,OAAO,KACrC,QAAQ,UAAU;AAAA,QAChB,OAAO;AAAA,QACP,cAAc,QAAQ,MAAM;AAAA,UAC1B,OAAO;AAAA,QACT,CAAC;AAAA,MACH,CAAC,GACD;AACA,yBAAiB,KAAK,OAAO;AAAA,MAC/B;AAAA,IACF;AAEA,QAAI,iBAAiB,SAAS,GAAG;AAC/B,eAAS,mBAAmB,UAAU;AAKtC,iBAAW,WAAW,kBAAkB;AACtC,gBAAQ,sCAAc,EAAE,eAAe;AAAA,MACzC;AAAA,IACF,OAAO;AAEL,YAAM,UAAU,IAAI,QAAQ,WAAW,OAAO,KAAK;AAAA,QACjD,SAAS;AAAA,UACP,SAAS;AAAA,UACT,YAAY;AAAA,QACd;AAAA,MACF,CAAC;AACD,gBAAM;AAAA,QACJ;AAAA,QACA,QAAQ,4BAA4B;AAAA,MACtC,EAAE,MAAM,CAAC,UAAU;AACjB,cAAM,aAAa,IAAI,MAAM,OAAO;AACpC,eAAO,eAAe,YAAY,SAAS;AAAA,UACzC,YAAY;AAAA,UACZ,cAAc;AAAA,UACd,OAAO;AAAA,QACT,CAAC;AACD,mBAAW,OAAO,OAAO,cAAc,UAAU;AAAA,MACnD,CAAC;AAED,eAAS,wBAAwB,UAAU;AAI3C,iBAAW,OAAO,QAAQ;AAAA,IAC5B;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { kDispatchEvent } from '../handlers/WebSocketHandler.mjs';
|
|
2
2
|
import { webSocketInterceptor } from './webSocketInterceptor.mjs';
|
|
3
3
|
import {
|
|
4
4
|
onUnhandledRequest
|
|
5
5
|
} from '../utils/request/onUnhandledRequest.mjs';
|
|
6
|
+
import { isHandlerKind } from '../utils/internal/isHandlerKind.mjs';
|
|
6
7
|
function handleWebSocketEvent(options) {
|
|
7
8
|
webSocketInterceptor.on("connection", async (connection) => {
|
|
8
9
|
const handlers = options.getHandlers();
|
|
@@ -11,7 +12,7 @@ function handleWebSocketEvent(options) {
|
|
|
11
12
|
});
|
|
12
13
|
const matchingHandlers = [];
|
|
13
14
|
for (const handler of handlers) {
|
|
14
|
-
if (handler
|
|
15
|
+
if (isHandlerKind("EventHandler")(handler) && handler.predicate({
|
|
15
16
|
event: connectionEvent,
|
|
16
17
|
parsedResult: handler.parse({
|
|
17
18
|
event: connectionEvent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/ws/handleWebSocketEvent.ts"],"sourcesContent":["import type { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport { RequestHandler } from '../handlers/RequestHandler'\nimport { WebSocketHandler, kDispatchEvent } from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from './webSocketInterceptor'\nimport {\n onUnhandledRequest,\n UnhandledRequestStrategy,\n} from '../utils/request/onUnhandledRequest'\n\ninterface HandleWebSocketEventOptions {\n getUnhandledRequestStrategy: () => UnhandledRequestStrategy\n getHandlers: () => Array<RequestHandler | WebSocketHandler>\n onMockedConnection: (connection: WebSocketConnectionData) => void\n onPassthroughConnection: (onnection: WebSocketConnectionData) => void\n}\n\nexport function handleWebSocketEvent(options: HandleWebSocketEventOptions) {\n webSocketInterceptor.on('connection', async (connection) => {\n const handlers = options.getHandlers()\n\n const connectionEvent = new MessageEvent('connection', {\n data: connection,\n })\n\n // First, filter only those WebSocket handlers that\n // match the \"ws.link()\" endpoint predicate. Don't dispatch\n // anything yet so the logger can be attached to the connection\n // before it potentially sends events.\n const matchingHandlers: Array<WebSocketHandler> = []\n\n for (const handler of handlers) {\n if (\n handler
|
|
1
|
+
{"version":3,"sources":["../../../src/core/ws/handleWebSocketEvent.ts"],"sourcesContent":["import type { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket'\nimport { RequestHandler } from '../handlers/RequestHandler'\nimport { WebSocketHandler, kDispatchEvent } from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from './webSocketInterceptor'\nimport {\n onUnhandledRequest,\n UnhandledRequestStrategy,\n} from '../utils/request/onUnhandledRequest'\nimport { isHandlerKind } from '../utils/internal/isHandlerKind'\n\ninterface HandleWebSocketEventOptions {\n getUnhandledRequestStrategy: () => UnhandledRequestStrategy\n getHandlers: () => Array<RequestHandler | WebSocketHandler>\n onMockedConnection: (connection: WebSocketConnectionData) => void\n onPassthroughConnection: (onnection: WebSocketConnectionData) => void\n}\n\nexport function handleWebSocketEvent(options: HandleWebSocketEventOptions) {\n webSocketInterceptor.on('connection', async (connection) => {\n const handlers = options.getHandlers()\n\n const connectionEvent = new MessageEvent('connection', {\n data: connection,\n })\n\n // First, filter only those WebSocket handlers that\n // match the \"ws.link()\" endpoint predicate. Don't dispatch\n // anything yet so the logger can be attached to the connection\n // before it potentially sends events.\n const matchingHandlers: Array<WebSocketHandler> = []\n\n for (const handler of handlers) {\n if (\n isHandlerKind('EventHandler')(handler) &&\n handler.predicate({\n event: connectionEvent,\n parsedResult: handler.parse({\n event: connectionEvent,\n }),\n })\n ) {\n matchingHandlers.push(handler)\n }\n }\n\n if (matchingHandlers.length > 0) {\n options?.onMockedConnection(connection)\n\n // Iterate over the handlers and forward the connection\n // event to WebSocket event handlers. This is equivalent\n // to dispatching that event onto multiple listeners.\n for (const handler of matchingHandlers) {\n handler[kDispatchEvent](connectionEvent)\n }\n } else {\n // Construct a request representing this WebSocket connection.\n const request = new Request(connection.client.url, {\n headers: {\n upgrade: 'websocket',\n connection: 'upgrade',\n },\n })\n await onUnhandledRequest(\n request,\n options.getUnhandledRequestStrategy(),\n ).catch((error) => {\n const errorEvent = new Event('error')\n Object.defineProperty(errorEvent, 'cause', {\n enumerable: true,\n configurable: false,\n value: error,\n })\n connection.client.socket.dispatchEvent(errorEvent)\n })\n\n options?.onPassthroughConnection(connection)\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n connection.server.connect()\n }\n })\n}\n"],"mappings":"AAEA,SAA2B,sBAAsB;AACjD,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,OAEK;AACP,SAAS,qBAAqB;AASvB,SAAS,qBAAqB,SAAsC;AACzE,uBAAqB,GAAG,cAAc,OAAO,eAAe;AAC1D,UAAM,WAAW,QAAQ,YAAY;AAErC,UAAM,kBAAkB,IAAI,aAAa,cAAc;AAAA,MACrD,MAAM;AAAA,IACR,CAAC;AAMD,UAAM,mBAA4C,CAAC;AAEnD,eAAW,WAAW,UAAU;AAC9B,UACE,cAAc,cAAc,EAAE,OAAO,KACrC,QAAQ,UAAU;AAAA,QAChB,OAAO;AAAA,QACP,cAAc,QAAQ,MAAM;AAAA,UAC1B,OAAO;AAAA,QACT,CAAC;AAAA,MACH,CAAC,GACD;AACA,yBAAiB,KAAK,OAAO;AAAA,MAC/B;AAAA,IACF;AAEA,QAAI,iBAAiB,SAAS,GAAG;AAC/B,eAAS,mBAAmB,UAAU;AAKtC,iBAAW,WAAW,kBAAkB;AACtC,gBAAQ,cAAc,EAAE,eAAe;AAAA,MACzC;AAAA,IACF,OAAO;AAEL,YAAM,UAAU,IAAI,QAAQ,WAAW,OAAO,KAAK;AAAA,QACjD,SAAS;AAAA,UACP,SAAS;AAAA,UACT,YAAY;AAAA,QACd;AAAA,MACF,CAAC;AACD,YAAM;AAAA,QACJ;AAAA,QACA,QAAQ,4BAA4B;AAAA,MACtC,EAAE,MAAM,CAAC,UAAU;AACjB,cAAM,aAAa,IAAI,MAAM,OAAO;AACpC,eAAO,eAAe,YAAY,SAAS;AAAA,UACzC,YAAY;AAAA,UACZ,cAAc;AAAA,UACd,OAAO;AAAA,QACT,CAAC;AACD,mBAAW,OAAO,OAAO,cAAc,UAAU;AAAA,MACnD,CAAC;AAED,eAAS,wBAAwB,UAAU;AAI3C,iBAAW,OAAO,QAAQ;AAAA,IAC5B;AAAA,EACF,CAAC;AACH;","names":[]}
|