msw 2.2.2 → 2.3.0-ws.rc-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/init.js +0 -0
- package/config/scripts/postinstall.js +0 -0
- package/lib/browser/index.d.mts +7 -6
- package/lib/browser/index.d.ts +7 -6
- package/lib/browser/index.js +32 -15
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +32 -15
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-jOzqbxSK.d.ts → GraphQLHandler-Cbu12sb0.d.ts} +1 -1
- package/lib/core/{GraphQLHandler-AenIUdwE.d.mts → GraphQLHandler-QGQY_9Rc.d.mts} +1 -1
- package/lib/core/{HttpResponse-wcp03c7-.d.mts → HttpResponse-BWB1yDNM.d.mts} +2 -2
- package/lib/core/{HttpResponse-_514VQ9z.d.ts → HttpResponse-DeJBWGN5.d.ts} +2 -2
- 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 +38 -0
- package/lib/core/handlers/WebSocketHandler.d.ts +38 -0
- package/lib/core/handlers/WebSocketHandler.js +65 -0
- package/lib/core/handlers/WebSocketHandler.js.map +1 -0
- package/lib/core/handlers/WebSocketHandler.mjs +47 -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 +3 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +3 -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/handleWebSocketEvent.d.mts +10 -0
- package/lib/core/utils/handleWebSocketEvent.d.ts +10 -0
- package/lib/core/utils/handleWebSocketEvent.js +56 -0
- package/lib/core/utils/handleWebSocketEvent.js.map +1 -0
- package/lib/core/utils/handleWebSocketEvent.mjs +40 -0
- package/lib/core/utils/handleWebSocketEvent.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/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 +64 -0
- package/lib/core/ws/WebSocketClientManager.d.ts +64 -0
- package/lib/core/ws/WebSocketClientManager.js +123 -0
- package/lib/core/ws/WebSocketClientManager.js.map +1 -0
- package/lib/core/ws/WebSocketClientManager.mjs +103 -0
- package/lib/core/ws/WebSocketClientManager.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/ws.d.mts +44 -0
- package/lib/core/ws/ws.d.ts +44 -0
- package/lib/core/ws/ws.js +82 -0
- package/lib/core/ws/ws.js.map +1 -0
- package/lib/core/ws/ws.mjs +65 -0
- package/lib/core/ws/ws.mjs.map +1 -0
- package/lib/iife/index.js +703 -17
- 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 +7 -0
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +7 -0
- 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 +7 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +7 -0
- package/lib/node/index.mjs.map +1 -1
- package/package.json +29 -24
- package/src/browser/setupWorker/glossary.ts +10 -10
- package/src/browser/setupWorker/setupWorker.ts +17 -3
- package/src/core/SetupApi.ts +28 -20
- package/src/core/handlers/WebSocketHandler.ts +89 -0
- package/src/core/index.ts +3 -0
- package/src/core/utils/executeHandlers.ts +6 -2
- package/src/core/utils/handleRequest.ts +1 -2
- package/src/core/utils/handleWebSocketEvent.ts +49 -0
- 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 +159 -0
- package/src/core/ws/WebSocketClientManager.ts +170 -0
- package/src/core/ws/webSocketInterceptor.ts +3 -0
- package/src/core/ws/ws.test.ts +23 -0
- package/src/core/ws/ws.ts +108 -0
- package/src/node/SetupServerApi.ts +8 -7
- package/src/node/SetupServerCommonApi.ts +10 -1
- package/src/node/glossary.ts +5 -7
- package/src/node/setupServer.ts +2 -1
package/lib/core/index.js
CHANGED
|
@@ -30,7 +30,8 @@ __export(core_exports, {
|
|
|
30
30
|
graphql: () => import_graphql.graphql,
|
|
31
31
|
http: () => import_http.http,
|
|
32
32
|
matchRequestUrl: () => import_matchRequestUrl.matchRequestUrl,
|
|
33
|
-
passthrough: () => import_passthrough.passthrough
|
|
33
|
+
passthrough: () => import_passthrough.passthrough,
|
|
34
|
+
ws: () => import_ws.ws
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(core_exports);
|
|
36
37
|
var import_checkGlobals = require("./utils/internal/checkGlobals.js");
|
|
@@ -40,6 +41,7 @@ var import_http = require("./http.js");
|
|
|
40
41
|
var import_HttpHandler = require("./handlers/HttpHandler.js");
|
|
41
42
|
var import_graphql = require("./graphql.js");
|
|
42
43
|
var import_GraphQLHandler = require("./handlers/GraphQLHandler.js");
|
|
44
|
+
var import_ws = require("./ws/ws.js");
|
|
43
45
|
var import_matchRequestUrl = require("./utils/matching/matchRequestUrl.js");
|
|
44
46
|
__reExport(core_exports, require("./utils/handleRequest.js"), module.exports);
|
|
45
47
|
var import_getResponse = require("./getResponse.js");
|
package/lib/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* Request handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLJsonRequestBody,\n} from './handlers/GraphQLHandler'\nexport type { GraphQLRequestHandler, GraphQLResponseResolver } from './graphql'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAE7B,sBAAyB;AAGzB,4BAA+B;AAC/B,kBAAqB;AACrB,yBAAyC;AACzC,qBAAwB;AACxB,4BAA+B;AAG/B,6BAAgC;AAChC,yBAAc,
|
|
1
|
+
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* Request handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* WebSocket */\nexport { ws } from './ws/ws'\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLJsonRequestBody,\n} from './handlers/GraphQLHandler'\nexport type { GraphQLRequestHandler, GraphQLResponseResolver } from './graphql'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAE7B,sBAAyB;AAGzB,4BAA+B;AAC/B,kBAAqB;AACrB,yBAAyC;AACzC,qBAAwB;AACxB,4BAA+B;AAG/B,gBAAmB;AAGnB,6BAAgC;AAChC,yBAAc,kCAhBd;AAiBA,yBAA4B;AAC5B,sBAAyB;AAmCzB,yBAAc,2BArDd;AAsDA,yBAAc,oBAtDd;AAuDA,oBAAuB;AACvB,yBAA4B;AAAA,IAM5B,kCAAa;","names":[]}
|
package/lib/core/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { http } from './http.mjs';
|
|
|
5
5
|
import { HttpHandler, HttpMethods } from './handlers/HttpHandler.mjs';
|
|
6
6
|
import { graphql } from './graphql.mjs';
|
|
7
7
|
import { GraphQLHandler } from './handlers/GraphQLHandler.mjs';
|
|
8
|
+
import { ws } from './ws/ws.mjs';
|
|
8
9
|
import { matchRequestUrl } from './utils/matching/matchRequestUrl.mjs';
|
|
9
10
|
export * from './utils/handleRequest.mjs';
|
|
10
11
|
import { getResponse } from './getResponse.mjs';
|
|
@@ -26,6 +27,7 @@ export {
|
|
|
26
27
|
graphql,
|
|
27
28
|
http,
|
|
28
29
|
matchRequestUrl,
|
|
29
|
-
passthrough
|
|
30
|
+
passthrough,
|
|
31
|
+
ws
|
|
30
32
|
};
|
|
31
33
|
//# sourceMappingURL=index.mjs.map
|
package/lib/core/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* Request handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLJsonRequestBody,\n} from './handlers/GraphQLHandler'\nexport type { GraphQLRequestHandler, GraphQLResponseResolver } from './graphql'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":"AAAA,SAAS,oBAAoB;AAE7B,SAAS,gBAAgB;AAGzB,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AACrB,SAAS,aAAa,mBAAmB;AACzC,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAG/B,SAAS,uBAAuB;AAChC,cAAc;AACd,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAmCzB,cAAc;AACd,cAAc;AACd,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAM5B,aAAa;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* Request handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* WebSocket */\nexport { ws } from './ws/ws'\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLJsonRequestBody,\n} from './handlers/GraphQLHandler'\nexport type { GraphQLRequestHandler, GraphQLResponseResolver } from './graphql'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":"AAAA,SAAS,oBAAoB;AAE7B,SAAS,gBAAgB;AAGzB,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AACrB,SAAS,aAAa,mBAAmB;AACzC,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAG/B,SAAS,UAAU;AAGnB,SAAS,uBAAuB;AAChC,cAAc;AACd,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAmCzB,cAAc;AACd,cAAc;AACd,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAM5B,aAAa;","names":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { g as HandlersExecutionResult, i as ResponseResolutionContext, j as executeHandlers } from '../HttpResponse-BWB1yDNM.mjs';
|
|
2
2
|
import '../typeUtils.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { g as HandlersExecutionResult, i as ResponseResolutionContext, j as executeHandlers } from '../HttpResponse-DeJBWGN5.js';
|
|
2
2
|
import '../typeUtils.js';
|
|
@@ -21,6 +21,7 @@ __export(executeHandlers_exports, {
|
|
|
21
21
|
executeHandlers: () => executeHandlers
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(executeHandlers_exports);
|
|
24
|
+
var import_RequestHandler = require("../handlers/RequestHandler.js");
|
|
24
25
|
const executeHandlers = async ({
|
|
25
26
|
request,
|
|
26
27
|
requestId,
|
|
@@ -30,6 +31,9 @@ const executeHandlers = async ({
|
|
|
30
31
|
let matchingHandler = null;
|
|
31
32
|
let result = null;
|
|
32
33
|
for (const handler of handlers) {
|
|
34
|
+
if (!(handler instanceof import_RequestHandler.RequestHandler)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
33
37
|
result = await handler.run({ request, requestId, resolutionContext });
|
|
34
38
|
if (result !== null) {
|
|
35
39
|
matchingHandler = handler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/utils/executeHandlers.ts"],"sourcesContent":["import {\n RequestHandler,\n 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<unknown>>({\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 if (!(handler instanceof RequestHandler)) {\n continue\n }\n\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;AAAA,4BAGO;AAiBA,MAAM,kBAAkB,OAAwC;AAAA,EACrE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAK+C;AAC7C,MAAI,kBAAyC;AAC7C,MAAI,SAAoD;AAExD,aAAW,WAAW,UAAU;AAC9B,QAAI,EAAE,mBAAmB,uCAAiB;AACxC;AAAA,IACF;AAEA,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,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RequestHandler
|
|
3
|
+
} from '../handlers/RequestHandler.mjs';
|
|
1
4
|
const executeHandlers = async ({
|
|
2
5
|
request,
|
|
3
6
|
requestId,
|
|
@@ -7,6 +10,9 @@ const executeHandlers = async ({
|
|
|
7
10
|
let matchingHandler = null;
|
|
8
11
|
let result = null;
|
|
9
12
|
for (const handler of handlers) {
|
|
13
|
+
if (!(handler instanceof RequestHandler)) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
10
16
|
result = await handler.run({ request, requestId, resolutionContext });
|
|
11
17
|
if (result !== null) {
|
|
12
18
|
matchingHandler = handler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/utils/executeHandlers.ts"],"sourcesContent":["import {\n RequestHandler,\n 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<unknown>>({\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 if (!(handler instanceof RequestHandler)) {\n continue\n }\n\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,EACE;AAAA,OAEK;AAiBA,MAAM,kBAAkB,OAAwC;AAAA,EACrE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAK+C;AAC7C,MAAI,kBAAyC;AAC7C,MAAI,SAAoD;AAExD,aAAW,WAAW,UAAU;AAC9B,QAAI,EAAE,mBAAmB,iBAAiB;AACxC;AAAA,IACF;AAEA,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
|
-
import { h as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-wcp03c7-.mjs';
|
|
3
2
|
import { SharedOptions, LifeCycleEventsMap } from '../sharedOptions.mjs';
|
|
4
3
|
import { RequiredDeep } from '../typeUtils.mjs';
|
|
4
|
+
import { g as HandlersExecutionResult } from '../HttpResponse-BWB1yDNM.mjs';
|
|
5
5
|
import './request/onUnhandledRequest.mjs';
|
|
6
6
|
|
|
7
7
|
interface HandleRequestOptions {
|
|
@@ -32,6 +32,6 @@ interface HandleRequestOptions {
|
|
|
32
32
|
*/
|
|
33
33
|
onMockedResponse?(response: Response, handler: RequiredDeep<HandlersExecutionResult>): void;
|
|
34
34
|
}
|
|
35
|
-
declare function handleRequest(request: Request, requestId: string, handlers: Array<
|
|
35
|
+
declare function handleRequest(request: Request, requestId: string, handlers: Array<unknown>, options: RequiredDeep<SharedOptions>, emitter: Emitter<LifeCycleEventsMap>, handleRequestOptions?: HandleRequestOptions): Promise<Response | undefined>;
|
|
36
36
|
|
|
37
37
|
export { type HandleRequestOptions, handleRequest };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Emitter } from 'strict-event-emitter';
|
|
2
|
-
import { h as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-_514VQ9z.js';
|
|
3
2
|
import { SharedOptions, LifeCycleEventsMap } from '../sharedOptions.js';
|
|
4
3
|
import { RequiredDeep } from '../typeUtils.js';
|
|
4
|
+
import { g as HandlersExecutionResult } from '../HttpResponse-DeJBWGN5.js';
|
|
5
5
|
import './request/onUnhandledRequest.js';
|
|
6
6
|
|
|
7
7
|
interface HandleRequestOptions {
|
|
@@ -32,6 +32,6 @@ interface HandleRequestOptions {
|
|
|
32
32
|
*/
|
|
33
33
|
onMockedResponse?(response: Response, handler: RequiredDeep<HandlersExecutionResult>): void;
|
|
34
34
|
}
|
|
35
|
-
declare function handleRequest(request: Request, requestId: string, handlers: Array<
|
|
35
|
+
declare function handleRequest(request: Request, requestId: string, handlers: Array<unknown>, options: RequiredDeep<SharedOptions>, emitter: Emitter<LifeCycleEventsMap>, handleRequestOptions?: HandleRequestOptions): Promise<Response | undefined>;
|
|
36
36
|
|
|
37
37
|
export { type HandleRequestOptions, handleRequest };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/utils/handleRequest.ts"],"sourcesContent":["import { until } from '@open-draft/until'\nimport { Emitter } from 'strict-event-emitter'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/handleRequest.ts"],"sourcesContent":["import { until } from '@open-draft/until'\nimport { Emitter } from 'strict-event-emitter'\nimport { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'\nimport { RequiredDeep } from '../typeUtils'\nimport { HandlersExecutionResult, executeHandlers } from './executeHandlers'\nimport { onUnhandledRequest } from './request/onUnhandledRequest'\nimport { readResponseCookies } from './request/readResponseCookies'\n\nexport interface HandleRequestOptions {\n /**\n * `resolutionContext` is not part of the general public api\n * but is exposed to aid in creating extensions like\n * `@mswjs/http-middleware`.\n */\n resolutionContext?: {\n /**\n * A base url to use when resolving relative urls.\n * @note This is primarily used by the `@mswjs/http-middleware`\n * to resolve relative urls in the context of the running server\n */\n baseUrl?: string\n }\n\n /**\n * Transforms a `MockedResponse` instance returned from a handler\n * to a response instance supported by the lower tooling (i.e. interceptors).\n */\n transformResponse?(response: Response): Response\n\n /**\n * Invoked whenever a request is performed as-is.\n */\n onPassthroughResponse?(request: Request): void\n\n /**\n * Invoked when the mocked response is ready to be sent.\n */\n onMockedResponse?(\n response: Response,\n handler: RequiredDeep<HandlersExecutionResult>,\n ): void\n}\n\nexport async function handleRequest(\n request: Request,\n requestId: string,\n handlers: Array<unknown>,\n options: RequiredDeep<SharedOptions>,\n emitter: Emitter<LifeCycleEventsMap>,\n handleRequestOptions?: HandleRequestOptions,\n): Promise<Response | undefined> {\n emitter.emit('request:start', { request, requestId })\n\n // Perform bypassed requests (i.e. issued via \"ctx.fetch\") as-is.\n if (request.headers.get('x-msw-intention') === 'bypass') {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Resolve a mocked response from the list of request handlers.\n const lookupResult = await until(() => {\n return executeHandlers({\n request,\n requestId,\n handlers,\n resolutionContext: handleRequestOptions?.resolutionContext,\n })\n })\n\n if (lookupResult.error) {\n // Allow developers to react to unhandled exceptions in request handlers.\n emitter.emit('unhandledException', {\n error: lookupResult.error,\n request,\n requestId,\n })\n throw lookupResult.error\n }\n\n // If the handler lookup returned nothing, no request handler was found\n // matching this request. Report the request as unhandled.\n if (!lookupResult.data) {\n await onUnhandledRequest(request, options.onUnhandledRequest)\n emitter.emit('request:unhandled', { request, requestId })\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n const { response } = lookupResult.data\n\n // When the handled request returned no mocked response, warn the developer,\n // as it may be an oversight on their part. Perform the request as-is.\n if (!response) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Perform the request as-is when the developer explicitly returned \"req.passthrough()\".\n // This produces no warning as the request was handled.\n if (\n response.status === 302 &&\n response.headers.get('x-msw-intention') === 'passthrough'\n ) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Store all the received response cookies in the virtual cookie store.\n readResponseCookies(request, response)\n\n emitter.emit('request:match', { request, requestId })\n\n const requiredLookupResult =\n lookupResult.data as RequiredDeep<HandlersExecutionResult>\n\n const transformedResponse =\n handleRequestOptions?.transformResponse?.(response) ||\n (response as any as Response)\n\n handleRequestOptions?.onMockedResponse?.(\n transformedResponse,\n requiredLookupResult,\n )\n\n emitter.emit('request:end', { request, requestId })\n\n return transformedResponse\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AAItB,6BAAyD;AACzD,gCAAmC;AACnC,iCAAoC;AAqCpC,eAAsB,cACpB,SACA,WACA,UACA,SACA,SACA,sBAC+B;AAC/B,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAGpD,MAAI,QAAQ,QAAQ,IAAI,iBAAiB,MAAM,UAAU;AACvD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,QAAM,eAAe,UAAM,oBAAM,MAAM;AACrC,eAAO,wCAAgB;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB,sBAAsB;AAAA,IAC3C,CAAC;AAAA,EACH,CAAC;AAED,MAAI,aAAa,OAAO;AAEtB,YAAQ,KAAK,sBAAsB;AAAA,MACjC,OAAO,aAAa;AAAA,MACpB;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,aAAa;AAAA,EACrB;AAIA,MAAI,CAAC,aAAa,MAAM;AACtB,cAAM,8CAAmB,SAAS,QAAQ,kBAAkB;AAC5D,YAAQ,KAAK,qBAAqB,EAAE,SAAS,UAAU,CAAC;AACxD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAEA,QAAM,EAAE,SAAS,IAAI,aAAa;AAIlC,MAAI,CAAC,UAAU;AACb,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAIA,MACE,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,iBAAiB,MAAM,eAC5C;AACA,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,sDAAoB,SAAS,QAAQ;AAErC,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAEpD,QAAM,uBACJ,aAAa;AAEf,QAAM,sBACJ,sBAAsB,oBAAoB,QAAQ,KACjD;AAEH,wBAAsB;AAAA,IACpB;AAAA,IACA;AAAA,EACF;AAEA,UAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAElD,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/utils/handleRequest.ts"],"sourcesContent":["import { until } from '@open-draft/until'\nimport { Emitter } from 'strict-event-emitter'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/handleRequest.ts"],"sourcesContent":["import { until } from '@open-draft/until'\nimport { Emitter } from 'strict-event-emitter'\nimport { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'\nimport { RequiredDeep } from '../typeUtils'\nimport { HandlersExecutionResult, executeHandlers } from './executeHandlers'\nimport { onUnhandledRequest } from './request/onUnhandledRequest'\nimport { readResponseCookies } from './request/readResponseCookies'\n\nexport interface HandleRequestOptions {\n /**\n * `resolutionContext` is not part of the general public api\n * but is exposed to aid in creating extensions like\n * `@mswjs/http-middleware`.\n */\n resolutionContext?: {\n /**\n * A base url to use when resolving relative urls.\n * @note This is primarily used by the `@mswjs/http-middleware`\n * to resolve relative urls in the context of the running server\n */\n baseUrl?: string\n }\n\n /**\n * Transforms a `MockedResponse` instance returned from a handler\n * to a response instance supported by the lower tooling (i.e. interceptors).\n */\n transformResponse?(response: Response): Response\n\n /**\n * Invoked whenever a request is performed as-is.\n */\n onPassthroughResponse?(request: Request): void\n\n /**\n * Invoked when the mocked response is ready to be sent.\n */\n onMockedResponse?(\n response: Response,\n handler: RequiredDeep<HandlersExecutionResult>,\n ): void\n}\n\nexport async function handleRequest(\n request: Request,\n requestId: string,\n handlers: Array<unknown>,\n options: RequiredDeep<SharedOptions>,\n emitter: Emitter<LifeCycleEventsMap>,\n handleRequestOptions?: HandleRequestOptions,\n): Promise<Response | undefined> {\n emitter.emit('request:start', { request, requestId })\n\n // Perform bypassed requests (i.e. issued via \"ctx.fetch\") as-is.\n if (request.headers.get('x-msw-intention') === 'bypass') {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Resolve a mocked response from the list of request handlers.\n const lookupResult = await until(() => {\n return executeHandlers({\n request,\n requestId,\n handlers,\n resolutionContext: handleRequestOptions?.resolutionContext,\n })\n })\n\n if (lookupResult.error) {\n // Allow developers to react to unhandled exceptions in request handlers.\n emitter.emit('unhandledException', {\n error: lookupResult.error,\n request,\n requestId,\n })\n throw lookupResult.error\n }\n\n // If the handler lookup returned nothing, no request handler was found\n // matching this request. Report the request as unhandled.\n if (!lookupResult.data) {\n await onUnhandledRequest(request, options.onUnhandledRequest)\n emitter.emit('request:unhandled', { request, requestId })\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n const { response } = lookupResult.data\n\n // When the handled request returned no mocked response, warn the developer,\n // as it may be an oversight on their part. Perform the request as-is.\n if (!response) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Perform the request as-is when the developer explicitly returned \"req.passthrough()\".\n // This produces no warning as the request was handled.\n if (\n response.status === 302 &&\n response.headers.get('x-msw-intention') === 'passthrough'\n ) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Store all the received response cookies in the virtual cookie store.\n readResponseCookies(request, response)\n\n emitter.emit('request:match', { request, requestId })\n\n const requiredLookupResult =\n lookupResult.data as RequiredDeep<HandlersExecutionResult>\n\n const transformedResponse =\n handleRequestOptions?.transformResponse?.(response) ||\n (response as any as Response)\n\n handleRequestOptions?.onMockedResponse?.(\n transformedResponse,\n requiredLookupResult,\n )\n\n emitter.emit('request:end', { request, requestId })\n\n return transformedResponse\n}\n"],"mappings":"AAAA,SAAS,aAAa;AAItB,SAAkC,uBAAuB;AACzD,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AAqCpC,eAAsB,cACpB,SACA,WACA,UACA,SACA,SACA,sBAC+B;AAC/B,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAGpD,MAAI,QAAQ,QAAQ,IAAI,iBAAiB,MAAM,UAAU;AACvD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,QAAM,eAAe,MAAM,MAAM,MAAM;AACrC,WAAO,gBAAgB;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB,sBAAsB;AAAA,IAC3C,CAAC;AAAA,EACH,CAAC;AAED,MAAI,aAAa,OAAO;AAEtB,YAAQ,KAAK,sBAAsB;AAAA,MACjC,OAAO,aAAa;AAAA,MACpB;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,aAAa;AAAA,EACrB;AAIA,MAAI,CAAC,aAAa,MAAM;AACtB,UAAM,mBAAmB,SAAS,QAAQ,kBAAkB;AAC5D,YAAQ,KAAK,qBAAqB,EAAE,SAAS,UAAU,CAAC;AACxD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAEA,QAAM,EAAE,SAAS,IAAI,aAAa;AAIlC,MAAI,CAAC,UAAU;AACb,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAIA,MACE,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,iBAAiB,MAAM,eAC5C;AACA,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,sBAAoB,SAAS,QAAQ;AAErC,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAEpD,QAAM,uBACJ,aAAa;AAEf,QAAM,sBACJ,sBAAsB,oBAAoB,QAAQ,KACjD;AAEH,wBAAsB;AAAA,IACpB;AAAA,IACA;AAAA,EACF;AAEA,UAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAElD,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { R as RequestHandler } from '../HttpResponse-BWB1yDNM.mjs';
|
|
2
|
+
import { WebSocketHandler } from '../handlers/WebSocketHandler.mjs';
|
|
3
|
+
import '../typeUtils.mjs';
|
|
4
|
+
import 'strict-event-emitter';
|
|
5
|
+
import '@mswjs/interceptors/WebSocket';
|
|
6
|
+
import './matching/matchRequestUrl.mjs';
|
|
7
|
+
|
|
8
|
+
declare function handleWebSocketEvent(getCurrentHandlers: () => Array<RequestHandler | WebSocketHandler>): void;
|
|
9
|
+
|
|
10
|
+
export { handleWebSocketEvent };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { R as RequestHandler } from '../HttpResponse-DeJBWGN5.js';
|
|
2
|
+
import { WebSocketHandler } from '../handlers/WebSocketHandler.js';
|
|
3
|
+
import '../typeUtils.js';
|
|
4
|
+
import 'strict-event-emitter';
|
|
5
|
+
import '@mswjs/interceptors/WebSocket';
|
|
6
|
+
import './matching/matchRequestUrl.js';
|
|
7
|
+
|
|
8
|
+
declare function handleWebSocketEvent(getCurrentHandlers: () => Array<RequestHandler | WebSocketHandler>): void;
|
|
9
|
+
|
|
10
|
+
export { handleWebSocketEvent };
|
|
@@ -0,0 +1,56 @@
|
|
|
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 handleWebSocketEvent_exports = {};
|
|
20
|
+
__export(handleWebSocketEvent_exports, {
|
|
21
|
+
handleWebSocketEvent: () => handleWebSocketEvent
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(handleWebSocketEvent_exports);
|
|
24
|
+
var import_WebSocketHandler = require("../handlers/WebSocketHandler.js");
|
|
25
|
+
var import_webSocketInterceptor = require("../ws/webSocketInterceptor.js");
|
|
26
|
+
function handleWebSocketEvent(getCurrentHandlers) {
|
|
27
|
+
import_webSocketInterceptor.webSocketInterceptor.on("connection", (connection) => {
|
|
28
|
+
const handlers = getCurrentHandlers();
|
|
29
|
+
const connectionEvent = new MessageEvent("connection", {
|
|
30
|
+
data: connection
|
|
31
|
+
/**
|
|
32
|
+
* @note This message event should be marked as "cancelable"
|
|
33
|
+
* to have its default prevented using "event.preventDefault()".
|
|
34
|
+
* There's a bug in Node.js that breaks the "cancelable" flag.
|
|
35
|
+
* @see https://github.com/nodejs/node/issues/51767
|
|
36
|
+
*/
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(connectionEvent, import_WebSocketHandler.kDefaultPrevented, {
|
|
39
|
+
enumerable: false,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: false
|
|
42
|
+
});
|
|
43
|
+
for (const handler of handlers) {
|
|
44
|
+
if (handler instanceof import_WebSocketHandler.WebSocketHandler) {
|
|
45
|
+
handler[import_WebSocketHandler.kDispatchEvent](connectionEvent);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!Reflect.get(connectionEvent, import_WebSocketHandler.kDefaultPrevented)) {
|
|
49
|
+
connection.server.connect();
|
|
50
|
+
connection.client.addEventListener("message", (event) => {
|
|
51
|
+
connection.server.send(event.data);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=handleWebSocketEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/handleWebSocketEvent.ts"],"sourcesContent":["import { RequestHandler } from '../handlers/RequestHandler'\nimport {\n WebSocketHandler,\n kDefaultPrevented,\n kDispatchEvent,\n} from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from '../ws/webSocketInterceptor'\n\nexport function handleWebSocketEvent(\n getCurrentHandlers: () => Array<RequestHandler | WebSocketHandler>,\n) {\n webSocketInterceptor.on('connection', (connection) => {\n const handlers = getCurrentHandlers()\n\n const connectionEvent = new MessageEvent('connection', {\n data: connection,\n /**\n * @note This message event should be marked as \"cancelable\"\n * to have its default prevented using \"event.preventDefault()\".\n * There's a bug in Node.js that breaks the \"cancelable\" flag.\n * @see https://github.com/nodejs/node/issues/51767\n */\n })\n\n Object.defineProperty(connectionEvent, kDefaultPrevented, {\n enumerable: false,\n writable: true,\n value: false,\n })\n\n // Iterate over the handlers and forward the connection\n // event to WebSocket event handlers. This is equivalent\n // to dispatching that event onto multiple listeners.\n for (const handler of handlers) {\n if (handler instanceof WebSocketHandler) {\n handler[kDispatchEvent](connectionEvent)\n }\n }\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n if (!Reflect.get(connectionEvent, kDefaultPrevented)) {\n connection.server.connect()\n connection.client.addEventListener('message', (event) => {\n connection.server.send(event.data)\n })\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,8BAIO;AACP,kCAAqC;AAE9B,SAAS,qBACd,oBACA;AACA,mDAAqB,GAAG,cAAc,CAAC,eAAe;AACpD,UAAM,WAAW,mBAAmB;AAEpC,UAAM,kBAAkB,IAAI,aAAa,cAAc;AAAA,MACrD,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOR,CAAC;AAED,WAAO,eAAe,iBAAiB,2CAAmB;AAAA,MACxD,YAAY;AAAA,MACZ,UAAU;AAAA,MACV,OAAO;AAAA,IACT,CAAC;AAKD,eAAW,WAAW,UAAU;AAC9B,UAAI,mBAAmB,0CAAkB;AACvC,gBAAQ,sCAAc,EAAE,eAAe;AAAA,MACzC;AAAA,IACF;AAIA,QAAI,CAAC,QAAQ,IAAI,iBAAiB,yCAAiB,GAAG;AACpD,iBAAW,OAAO,QAAQ;AAC1B,iBAAW,OAAO,iBAAiB,WAAW,CAAC,UAAU;AACvD,mBAAW,OAAO,KAAK,MAAM,IAAI;AAAA,MACnC,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WebSocketHandler,
|
|
3
|
+
kDefaultPrevented,
|
|
4
|
+
kDispatchEvent
|
|
5
|
+
} from '../handlers/WebSocketHandler.mjs';
|
|
6
|
+
import { webSocketInterceptor } from '../ws/webSocketInterceptor.mjs';
|
|
7
|
+
function handleWebSocketEvent(getCurrentHandlers) {
|
|
8
|
+
webSocketInterceptor.on("connection", (connection) => {
|
|
9
|
+
const handlers = getCurrentHandlers();
|
|
10
|
+
const connectionEvent = new MessageEvent("connection", {
|
|
11
|
+
data: connection
|
|
12
|
+
/**
|
|
13
|
+
* @note This message event should be marked as "cancelable"
|
|
14
|
+
* to have its default prevented using "event.preventDefault()".
|
|
15
|
+
* There's a bug in Node.js that breaks the "cancelable" flag.
|
|
16
|
+
* @see https://github.com/nodejs/node/issues/51767
|
|
17
|
+
*/
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(connectionEvent, kDefaultPrevented, {
|
|
20
|
+
enumerable: false,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: false
|
|
23
|
+
});
|
|
24
|
+
for (const handler of handlers) {
|
|
25
|
+
if (handler instanceof WebSocketHandler) {
|
|
26
|
+
handler[kDispatchEvent](connectionEvent);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (!Reflect.get(connectionEvent, kDefaultPrevented)) {
|
|
30
|
+
connection.server.connect();
|
|
31
|
+
connection.client.addEventListener("message", (event) => {
|
|
32
|
+
connection.server.send(event.data);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
handleWebSocketEvent
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=handleWebSocketEvent.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/handleWebSocketEvent.ts"],"sourcesContent":["import { RequestHandler } from '../handlers/RequestHandler'\nimport {\n WebSocketHandler,\n kDefaultPrevented,\n kDispatchEvent,\n} from '../handlers/WebSocketHandler'\nimport { webSocketInterceptor } from '../ws/webSocketInterceptor'\n\nexport function handleWebSocketEvent(\n getCurrentHandlers: () => Array<RequestHandler | WebSocketHandler>,\n) {\n webSocketInterceptor.on('connection', (connection) => {\n const handlers = getCurrentHandlers()\n\n const connectionEvent = new MessageEvent('connection', {\n data: connection,\n /**\n * @note This message event should be marked as \"cancelable\"\n * to have its default prevented using \"event.preventDefault()\".\n * There's a bug in Node.js that breaks the \"cancelable\" flag.\n * @see https://github.com/nodejs/node/issues/51767\n */\n })\n\n Object.defineProperty(connectionEvent, kDefaultPrevented, {\n enumerable: false,\n writable: true,\n value: false,\n })\n\n // Iterate over the handlers and forward the connection\n // event to WebSocket event handlers. This is equivalent\n // to dispatching that event onto multiple listeners.\n for (const handler of handlers) {\n if (handler instanceof WebSocketHandler) {\n handler[kDispatchEvent](connectionEvent)\n }\n }\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n if (!Reflect.get(connectionEvent, kDefaultPrevented)) {\n connection.server.connect()\n connection.client.addEventListener('message', (event) => {\n connection.server.send(event.data)\n })\n }\n })\n}\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,4BAA4B;AAE9B,SAAS,qBACd,oBACA;AACA,uBAAqB,GAAG,cAAc,CAAC,eAAe;AACpD,UAAM,WAAW,mBAAmB;AAEpC,UAAM,kBAAkB,IAAI,aAAa,cAAc;AAAA,MACrD,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOR,CAAC;AAED,WAAO,eAAe,iBAAiB,mBAAmB;AAAA,MACxD,YAAY;AAAA,MACZ,UAAU;AAAA,MACV,OAAO;AAAA,IACT,CAAC;AAKD,eAAW,WAAW,UAAU;AAC9B,UAAI,mBAAmB,kBAAkB;AACvC,gBAAQ,cAAc,EAAE,eAAe;AAAA,MACzC;AAAA,IACF;AAIA,QAAI,CAAC,QAAQ,IAAI,iBAAiB,iBAAiB,GAAG;AACpD,iBAAW,OAAO,QAAQ;AAC1B,iBAAW,OAAO,iBAAiB,WAAW,CAAC,UAAU;AACvD,mBAAW,OAAO,KAAK,MAAM,IAAI;AAAA,MACnC,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
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-QGQY_9Rc.mjs';
|
|
3
|
+
import '../../HttpResponse-BWB1yDNM.mjs';
|
|
4
4
|
import '../../typeUtils.mjs';
|
|
5
5
|
import '../matching/matchRequestUrl.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
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-Cbu12sb0.js';
|
|
3
|
+
import '../../HttpResponse-DeJBWGN5.js';
|
|
4
4
|
import '../../typeUtils.js';
|
|
5
5
|
import '../matching/matchRequestUrl.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler,
|
|
1
|
+
import { R as RequestHandler, h as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-BWB1yDNM.mjs';
|
|
2
2
|
import '../../typeUtils.mjs';
|
|
3
3
|
|
|
4
4
|
declare function use(currentHandlers: Array<RequestHandler>, ...handlers: Array<RequestHandler>): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler,
|
|
1
|
+
import { R as RequestHandler, h as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-DeJBWGN5.js';
|
|
2
2
|
import '../../typeUtils.js';
|
|
3
3
|
|
|
4
4
|
declare function use(currentHandlers: Array<RequestHandler>, ...handlers: Array<RequestHandler>): void;
|
|
@@ -15,5 +15,6 @@ declare function coercePath(path: string): string;
|
|
|
15
15
|
* Returns the result of matching given request URL against a mask.
|
|
16
16
|
*/
|
|
17
17
|
declare function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match;
|
|
18
|
+
declare function isPath(value: unknown): value is Path;
|
|
18
19
|
|
|
19
|
-
export { type Match, type Path, type PathParams, coercePath, matchRequestUrl };
|
|
20
|
+
export { type Match, type Path, type PathParams, coercePath, isPath, matchRequestUrl };
|
|
@@ -15,5 +15,6 @@ declare function coercePath(path: string): string;
|
|
|
15
15
|
* Returns the result of matching given request URL against a mask.
|
|
16
16
|
*/
|
|
17
17
|
declare function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match;
|
|
18
|
+
declare function isPath(value: unknown): value is Path;
|
|
18
19
|
|
|
19
|
-
export { type Match, type Path, type PathParams, coercePath, matchRequestUrl };
|
|
20
|
+
export { type Match, type Path, type PathParams, coercePath, isPath, matchRequestUrl };
|
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var matchRequestUrl_exports = {};
|
|
20
20
|
__export(matchRequestUrl_exports, {
|
|
21
21
|
coercePath: () => coercePath,
|
|
22
|
+
isPath: () => isPath,
|
|
22
23
|
matchRequestUrl: () => matchRequestUrl
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(matchRequestUrl_exports);
|
|
@@ -48,4 +49,7 @@ function matchRequestUrl(url, path, baseUrl) {
|
|
|
48
49
|
params
|
|
49
50
|
};
|
|
50
51
|
}
|
|
52
|
+
function isPath(value) {
|
|
53
|
+
return typeof value === "string" || value instanceof RegExp;
|
|
54
|
+
}
|
|
51
55
|
//# sourceMappingURL=matchRequestUrl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/matching/matchRequestUrl.ts"],"sourcesContent":["import { match } from 'path-to-regexp'\nimport { getCleanUrl } from '@mswjs/interceptors'\nimport { normalizePath } from './normalizePath'\n\nexport type Path = string | RegExp\nexport type PathParams<KeyType extends keyof any = string> = {\n [ParamName in KeyType]: string | ReadonlyArray<string>\n}\n\nexport interface Match {\n matches: boolean\n params?: PathParams\n}\n\n/**\n * Coerce a path supported by MSW into a path\n * supported by \"path-to-regexp\".\n */\nexport function coercePath(path: string): string {\n return (\n path\n /**\n * Replace wildcards (\"*\") with unnamed capturing groups\n * because \"path-to-regexp\" doesn't support wildcards.\n * Ignore path parameter' modifiers (i.e. \":name*\").\n */\n .replace(\n /([:a-zA-Z_-]*)(\\*{1,2})+/g,\n (_, parameterName: string | undefined, wildcard: string) => {\n const expression = '(.*)'\n\n if (!parameterName) {\n return expression\n }\n\n return parameterName.startsWith(':')\n ? `${parameterName}${wildcard}`\n : `${parameterName}${expression}`\n },\n )\n /**\n * Escape the port so that \"path-to-regexp\" can match\n * absolute URLs including port numbers.\n */\n .replace(/([^\\/])(:)(?=\\d+)/, '$1\\\\$2')\n /**\n * Escape the protocol so that \"path-to-regexp\" could match\n * absolute URL.\n * @see https://github.com/pillarjs/path-to-regexp/issues/259\n */\n .replace(/^([^\\/]+)(:)(?=\\/\\/)/, '$1\\\\$2')\n )\n}\n\n/**\n * Returns the result of matching given request URL against a mask.\n */\nexport function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match {\n const normalizedPath = normalizePath(path, baseUrl)\n const cleanPath =\n typeof normalizedPath === 'string'\n ? coercePath(normalizedPath)\n : normalizedPath\n\n const cleanUrl = getCleanUrl(url)\n const result = match(cleanPath, { decode: decodeURIComponent })(cleanUrl)\n const params = (result && (result.params as PathParams)) || {}\n\n return {\n matches: result !== false,\n params,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAsB;AACtB,0BAA4B;AAC5B,2BAA8B;AAgBvB,SAAS,WAAW,MAAsB;AAC/C,SACE,KAMG;AAAA,IACC;AAAA,IACA,CAAC,GAAG,eAAmC,aAAqB;AAC1D,YAAM,aAAa;AAEnB,UAAI,CAAC,eAAe;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,cAAc,WAAW,GAAG,IAC/B,GAAG,aAAa,GAAG,QAAQ,KAC3B,GAAG,aAAa,GAAG,UAAU;AAAA,IACnC;AAAA,EACF,EAKC,QAAQ,qBAAqB,QAAQ,EAMrC,QAAQ,wBAAwB,QAAQ;AAE/C;AAKO,SAAS,gBAAgB,KAAU,MAAY,SAAyB;AAC7E,QAAM,qBAAiB,oCAAc,MAAM,OAAO;AAClD,QAAM,YACJ,OAAO,mBAAmB,WACtB,WAAW,cAAc,IACzB;AAEN,QAAM,eAAW,iCAAY,GAAG;AAChC,QAAM,aAAS,6BAAM,WAAW,EAAE,QAAQ,mBAAmB,CAAC,EAAE,QAAQ;AACxE,QAAM,SAAU,UAAW,OAAO,UAA0B,CAAC;AAE7D,SAAO;AAAA,IACL,SAAS,WAAW;AAAA,IACpB;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/matching/matchRequestUrl.ts"],"sourcesContent":["import { match } from 'path-to-regexp'\nimport { getCleanUrl } from '@mswjs/interceptors'\nimport { normalizePath } from './normalizePath'\n\nexport type Path = string | RegExp\nexport type PathParams<KeyType extends keyof any = string> = {\n [ParamName in KeyType]: string | ReadonlyArray<string>\n}\n\nexport interface Match {\n matches: boolean\n params?: PathParams\n}\n\n/**\n * Coerce a path supported by MSW into a path\n * supported by \"path-to-regexp\".\n */\nexport function coercePath(path: string): string {\n return (\n path\n /**\n * Replace wildcards (\"*\") with unnamed capturing groups\n * because \"path-to-regexp\" doesn't support wildcards.\n * Ignore path parameter' modifiers (i.e. \":name*\").\n */\n .replace(\n /([:a-zA-Z_-]*)(\\*{1,2})+/g,\n (_, parameterName: string | undefined, wildcard: string) => {\n const expression = '(.*)'\n\n if (!parameterName) {\n return expression\n }\n\n return parameterName.startsWith(':')\n ? `${parameterName}${wildcard}`\n : `${parameterName}${expression}`\n },\n )\n /**\n * Escape the port so that \"path-to-regexp\" can match\n * absolute URLs including port numbers.\n */\n .replace(/([^\\/])(:)(?=\\d+)/, '$1\\\\$2')\n /**\n * Escape the protocol so that \"path-to-regexp\" could match\n * absolute URL.\n * @see https://github.com/pillarjs/path-to-regexp/issues/259\n */\n .replace(/^([^\\/]+)(:)(?=\\/\\/)/, '$1\\\\$2')\n )\n}\n\n/**\n * Returns the result of matching given request URL against a mask.\n */\nexport function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match {\n const normalizedPath = normalizePath(path, baseUrl)\n const cleanPath =\n typeof normalizedPath === 'string'\n ? coercePath(normalizedPath)\n : normalizedPath\n\n const cleanUrl = getCleanUrl(url)\n const result = match(cleanPath, { decode: decodeURIComponent })(cleanUrl)\n const params = (result && (result.params as PathParams)) || {}\n\n return {\n matches: result !== false,\n params,\n }\n}\n\nexport function isPath(value: unknown): value is Path {\n return typeof value === 'string' || value instanceof RegExp\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAsB;AACtB,0BAA4B;AAC5B,2BAA8B;AAgBvB,SAAS,WAAW,MAAsB;AAC/C,SACE,KAMG;AAAA,IACC;AAAA,IACA,CAAC,GAAG,eAAmC,aAAqB;AAC1D,YAAM,aAAa;AAEnB,UAAI,CAAC,eAAe;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,cAAc,WAAW,GAAG,IAC/B,GAAG,aAAa,GAAG,QAAQ,KAC3B,GAAG,aAAa,GAAG,UAAU;AAAA,IACnC;AAAA,EACF,EAKC,QAAQ,qBAAqB,QAAQ,EAMrC,QAAQ,wBAAwB,QAAQ;AAE/C;AAKO,SAAS,gBAAgB,KAAU,MAAY,SAAyB;AAC7E,QAAM,qBAAiB,oCAAc,MAAM,OAAO;AAClD,QAAM,YACJ,OAAO,mBAAmB,WACtB,WAAW,cAAc,IACzB;AAEN,QAAM,eAAW,iCAAY,GAAG;AAChC,QAAM,aAAS,6BAAM,WAAW,EAAE,QAAQ,mBAAmB,CAAC,EAAE,QAAQ;AACxE,QAAM,SAAU,UAAW,OAAO,UAA0B,CAAC;AAE7D,SAAO;AAAA,IACL,SAAS,WAAW;AAAA,IACpB;AAAA,EACF;AACF;AAEO,SAAS,OAAO,OAA+B;AACpD,SAAO,OAAO,UAAU,YAAY,iBAAiB;AACvD;","names":[]}
|
|
@@ -24,8 +24,12 @@ function matchRequestUrl(url, path, baseUrl) {
|
|
|
24
24
|
params
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
+
function isPath(value) {
|
|
28
|
+
return typeof value === "string" || value instanceof RegExp;
|
|
29
|
+
}
|
|
27
30
|
export {
|
|
28
31
|
coercePath,
|
|
32
|
+
isPath,
|
|
29
33
|
matchRequestUrl
|
|
30
34
|
};
|
|
31
35
|
//# sourceMappingURL=matchRequestUrl.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/matching/matchRequestUrl.ts"],"sourcesContent":["import { match } from 'path-to-regexp'\nimport { getCleanUrl } from '@mswjs/interceptors'\nimport { normalizePath } from './normalizePath'\n\nexport type Path = string | RegExp\nexport type PathParams<KeyType extends keyof any = string> = {\n [ParamName in KeyType]: string | ReadonlyArray<string>\n}\n\nexport interface Match {\n matches: boolean\n params?: PathParams\n}\n\n/**\n * Coerce a path supported by MSW into a path\n * supported by \"path-to-regexp\".\n */\nexport function coercePath(path: string): string {\n return (\n path\n /**\n * Replace wildcards (\"*\") with unnamed capturing groups\n * because \"path-to-regexp\" doesn't support wildcards.\n * Ignore path parameter' modifiers (i.e. \":name*\").\n */\n .replace(\n /([:a-zA-Z_-]*)(\\*{1,2})+/g,\n (_, parameterName: string | undefined, wildcard: string) => {\n const expression = '(.*)'\n\n if (!parameterName) {\n return expression\n }\n\n return parameterName.startsWith(':')\n ? `${parameterName}${wildcard}`\n : `${parameterName}${expression}`\n },\n )\n /**\n * Escape the port so that \"path-to-regexp\" can match\n * absolute URLs including port numbers.\n */\n .replace(/([^\\/])(:)(?=\\d+)/, '$1\\\\$2')\n /**\n * Escape the protocol so that \"path-to-regexp\" could match\n * absolute URL.\n * @see https://github.com/pillarjs/path-to-regexp/issues/259\n */\n .replace(/^([^\\/]+)(:)(?=\\/\\/)/, '$1\\\\$2')\n )\n}\n\n/**\n * Returns the result of matching given request URL against a mask.\n */\nexport function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match {\n const normalizedPath = normalizePath(path, baseUrl)\n const cleanPath =\n typeof normalizedPath === 'string'\n ? coercePath(normalizedPath)\n : normalizedPath\n\n const cleanUrl = getCleanUrl(url)\n const result = match(cleanPath, { decode: decodeURIComponent })(cleanUrl)\n const params = (result && (result.params as PathParams)) || {}\n\n return {\n matches: result !== false,\n params,\n }\n}\n"],"mappings":"AAAA,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAgBvB,SAAS,WAAW,MAAsB;AAC/C,SACE,KAMG;AAAA,IACC;AAAA,IACA,CAAC,GAAG,eAAmC,aAAqB;AAC1D,YAAM,aAAa;AAEnB,UAAI,CAAC,eAAe;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,cAAc,WAAW,GAAG,IAC/B,GAAG,aAAa,GAAG,QAAQ,KAC3B,GAAG,aAAa,GAAG,UAAU;AAAA,IACnC;AAAA,EACF,EAKC,QAAQ,qBAAqB,QAAQ,EAMrC,QAAQ,wBAAwB,QAAQ;AAE/C;AAKO,SAAS,gBAAgB,KAAU,MAAY,SAAyB;AAC7E,QAAM,iBAAiB,cAAc,MAAM,OAAO;AAClD,QAAM,YACJ,OAAO,mBAAmB,WACtB,WAAW,cAAc,IACzB;AAEN,QAAM,WAAW,YAAY,GAAG;AAChC,QAAM,SAAS,MAAM,WAAW,EAAE,QAAQ,mBAAmB,CAAC,EAAE,QAAQ;AACxE,QAAM,SAAU,UAAW,OAAO,UAA0B,CAAC;AAE7D,SAAO;AAAA,IACL,SAAS,WAAW;AAAA,IACpB;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/matching/matchRequestUrl.ts"],"sourcesContent":["import { match } from 'path-to-regexp'\nimport { getCleanUrl } from '@mswjs/interceptors'\nimport { normalizePath } from './normalizePath'\n\nexport type Path = string | RegExp\nexport type PathParams<KeyType extends keyof any = string> = {\n [ParamName in KeyType]: string | ReadonlyArray<string>\n}\n\nexport interface Match {\n matches: boolean\n params?: PathParams\n}\n\n/**\n * Coerce a path supported by MSW into a path\n * supported by \"path-to-regexp\".\n */\nexport function coercePath(path: string): string {\n return (\n path\n /**\n * Replace wildcards (\"*\") with unnamed capturing groups\n * because \"path-to-regexp\" doesn't support wildcards.\n * Ignore path parameter' modifiers (i.e. \":name*\").\n */\n .replace(\n /([:a-zA-Z_-]*)(\\*{1,2})+/g,\n (_, parameterName: string | undefined, wildcard: string) => {\n const expression = '(.*)'\n\n if (!parameterName) {\n return expression\n }\n\n return parameterName.startsWith(':')\n ? `${parameterName}${wildcard}`\n : `${parameterName}${expression}`\n },\n )\n /**\n * Escape the port so that \"path-to-regexp\" can match\n * absolute URLs including port numbers.\n */\n .replace(/([^\\/])(:)(?=\\d+)/, '$1\\\\$2')\n /**\n * Escape the protocol so that \"path-to-regexp\" could match\n * absolute URL.\n * @see https://github.com/pillarjs/path-to-regexp/issues/259\n */\n .replace(/^([^\\/]+)(:)(?=\\/\\/)/, '$1\\\\$2')\n )\n}\n\n/**\n * Returns the result of matching given request URL against a mask.\n */\nexport function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match {\n const normalizedPath = normalizePath(path, baseUrl)\n const cleanPath =\n typeof normalizedPath === 'string'\n ? coercePath(normalizedPath)\n : normalizedPath\n\n const cleanUrl = getCleanUrl(url)\n const result = match(cleanPath, { decode: decodeURIComponent })(cleanUrl)\n const params = (result && (result.params as PathParams)) || {}\n\n return {\n matches: result !== false,\n params,\n }\n}\n\nexport function isPath(value: unknown): value is Path {\n return typeof value === 'string' || value instanceof RegExp\n}\n"],"mappings":"AAAA,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAgBvB,SAAS,WAAW,MAAsB;AAC/C,SACE,KAMG;AAAA,IACC;AAAA,IACA,CAAC,GAAG,eAAmC,aAAqB;AAC1D,YAAM,aAAa;AAEnB,UAAI,CAAC,eAAe;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,cAAc,WAAW,GAAG,IAC/B,GAAG,aAAa,GAAG,QAAQ,KAC3B,GAAG,aAAa,GAAG,UAAU;AAAA,IACnC;AAAA,EACF,EAKC,QAAQ,qBAAqB,QAAQ,EAMrC,QAAQ,wBAAwB,QAAQ;AAE/C;AAKO,SAAS,gBAAgB,KAAU,MAAY,SAAyB;AAC7E,QAAM,iBAAiB,cAAc,MAAM,OAAO;AAClD,QAAM,YACJ,OAAO,mBAAmB,WACtB,WAAW,cAAc,IACzB;AAEN,QAAM,WAAW,YAAY,GAAG;AAChC,QAAM,SAAS,MAAM,WAAW,EAAE,QAAQ,mBAAmB,CAAC,EAAE,QAAQ;AACxE,QAAM,SAAU,UAAW,OAAO,UAA0B,CAAC;AAE7D,SAAO;AAAA,IACL,SAAS,WAAW;AAAA,IACpB;AAAA,EACF;AACF;AAEO,SAAS,OAAO,OAA+B;AACpD,SAAO,OAAO,UAAU,YAAY,iBAAiB;AACvD;","names":[]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { WebSocketData, WebSocketClientConnectionProtocol, WebSocketClientConnection } from '@mswjs/interceptors/WebSocket';
|
|
2
|
+
|
|
3
|
+
type WebSocketBroadcastChannelMessage = {
|
|
4
|
+
type: 'connection:open';
|
|
5
|
+
payload: {
|
|
6
|
+
clientId: string;
|
|
7
|
+
url: string;
|
|
8
|
+
};
|
|
9
|
+
} | {
|
|
10
|
+
type: 'extraneous:send';
|
|
11
|
+
payload: {
|
|
12
|
+
clientId: string;
|
|
13
|
+
data: WebSocketData;
|
|
14
|
+
};
|
|
15
|
+
} | {
|
|
16
|
+
type: 'extraneous:close';
|
|
17
|
+
payload: {
|
|
18
|
+
clientId: string;
|
|
19
|
+
code?: number;
|
|
20
|
+
reason?: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
declare const kAddByClientId: unique symbol;
|
|
24
|
+
/**
|
|
25
|
+
* A manager responsible for accumulating WebSocket client
|
|
26
|
+
* connections across different browser runtimes.
|
|
27
|
+
*/
|
|
28
|
+
declare class WebSocketClientManager {
|
|
29
|
+
private channel;
|
|
30
|
+
/**
|
|
31
|
+
* All active WebSocket client connections.
|
|
32
|
+
*/
|
|
33
|
+
clients: Set<WebSocketClientConnectionProtocol>;
|
|
34
|
+
constructor(channel: BroadcastChannel);
|
|
35
|
+
/**
|
|
36
|
+
* Adds the given `WebSocket` client connection to the set
|
|
37
|
+
* of all connections. The given connection is always the complete
|
|
38
|
+
* connection object because `addConnection()` is called only
|
|
39
|
+
* for the opened connections in the same runtime.
|
|
40
|
+
*/
|
|
41
|
+
addConnection(client: WebSocketClientConnection): void;
|
|
42
|
+
/**
|
|
43
|
+
* Adds a client connection wrapper to operate with
|
|
44
|
+
* WebSocket client connections in other runtimes.
|
|
45
|
+
*/
|
|
46
|
+
private onRemoteConnection;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A wrapper class to operate with WebSocket client connections
|
|
50
|
+
* from other runtimes. This class maintains 1-1 public API
|
|
51
|
+
* compatibility to the `WebSocketClientConnection` but relies
|
|
52
|
+
* on the given `BroadcastChannel` to communicate instructions
|
|
53
|
+
* with the client connections from other runtimes.
|
|
54
|
+
*/
|
|
55
|
+
declare class WebSocketRemoteClientConnection implements WebSocketClientConnectionProtocol {
|
|
56
|
+
readonly id: string;
|
|
57
|
+
readonly url: URL;
|
|
58
|
+
private channel;
|
|
59
|
+
constructor(id: string, url: URL, channel: BroadcastChannel);
|
|
60
|
+
send(data: WebSocketData): void;
|
|
61
|
+
close(code?: number | undefined, reason?: string | undefined): void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { type WebSocketBroadcastChannelMessage, WebSocketClientManager, WebSocketRemoteClientConnection, kAddByClientId };
|