msw 2.3.0-ws.rc-2 → 2.3.0-ws.rc-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/index.js +1 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +1 -1
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-4DPdxG0R.d.mts → GraphQLHandler-CzcXr7At.d.mts} +1 -1
- package/lib/core/{GraphQLHandler-3gvpA65n.d.ts → GraphQLHandler-DGyzNtRQ.d.ts} +1 -1
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +2 -2
- package/lib/core/graphql.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +3 -3
- package/lib/core/index.d.ts +3 -3
- package/lib/core/index.js +1 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +1 -1
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/handleRequest.d.mts +1 -1
- package/lib/core/utils/handleRequest.d.ts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/{utils → ws}/handleWebSocketEvent.d.mts +2 -2
- package/lib/core/{utils → ws}/handleWebSocketEvent.d.ts +2 -2
- package/lib/core/{utils → ws}/handleWebSocketEvent.js +1 -1
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -0
- package/lib/core/{utils → ws}/handleWebSocketEvent.mjs +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -0
- package/lib/core/{ws/ws.d.mts → ws.d.mts} +19 -14
- package/lib/core/{ws/ws.d.ts → ws.d.ts} +19 -14
- package/lib/core/{ws/ws.js → ws.js} +4 -23
- package/lib/core/ws.js.map +1 -0
- package/lib/core/{ws/ws.mjs → ws.mjs} +4 -23
- package/lib/core/ws.mjs.map +1 -0
- package/lib/iife/index.js +8 -25
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.js +1 -1
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +1 -1
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.js +1 -1
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +1 -1
- package/lib/node/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/browser/setupWorker/setupWorker.ts +1 -1
- package/src/core/index.ts +1 -1
- package/src/core/{utils → ws}/handleWebSocketEvent.ts +1 -1
- package/src/core/{ws/ws.ts → ws.ts} +49 -35
- package/src/node/SetupServerCommonApi.ts +1 -1
- package/lib/core/utils/handleWebSocketEvent.js.map +0 -1
- package/lib/core/utils/handleWebSocketEvent.mjs.map +0 -1
- package/lib/core/ws/ws.js.map +0 -1
- package/lib/core/ws/ws.mjs.map +0 -1
- /package/lib/core/{HttpResponse-aJY-D0oG.d.ts → HttpResponse-BOzDwzB6.d.ts} +0 -0
- /package/lib/core/{HttpResponse-xuSipbNt.d.mts → HttpResponse-CSyJ1cbO.d.mts} +0 -0
- /package/src/core/{ws/ws.test.ts → ws.test.ts} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OperationTypeNode, DocumentNode, GraphQLError } from 'graphql';
|
|
2
|
-
import { h as RequestHandlerDefaultInfo, D as DefaultBodyType, R as RequestHandler, a as ResponseResolver, c as RequestHandlerOptions } from './HttpResponse-
|
|
2
|
+
import { h as RequestHandlerDefaultInfo, D as DefaultBodyType, R as RequestHandler, a as ResponseResolver, c as RequestHandlerOptions } from './HttpResponse-CSyJ1cbO.mjs';
|
|
3
3
|
import { Match, Path } from './utils/matching/matchRequestUrl.mjs';
|
|
4
4
|
|
|
5
5
|
interface ParsedGraphQLQuery {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OperationTypeNode, DocumentNode, GraphQLError } from 'graphql';
|
|
2
|
-
import { h as RequestHandlerDefaultInfo, D as DefaultBodyType, R as RequestHandler, a as ResponseResolver, c as RequestHandlerOptions } from './HttpResponse-
|
|
2
|
+
import { h as RequestHandlerDefaultInfo, D as DefaultBodyType, R as RequestHandler, a as ResponseResolver, c as RequestHandlerOptions } from './HttpResponse-BOzDwzB6.js';
|
|
3
3
|
import { Match, Path } from './utils/matching/matchRequestUrl.js';
|
|
4
4
|
|
|
5
5
|
interface ParsedGraphQLQuery {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { f as HttpResponse, H as HttpResponseInit, S as StrictRequest, e as StrictResponse } from './HttpResponse-
|
|
1
|
+
export { f as HttpResponse, H as HttpResponseInit, S as StrictRequest, e as StrictResponse } from './HttpResponse-CSyJ1cbO.mjs';
|
|
2
2
|
import './typeUtils.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { f as HttpResponse, H as HttpResponseInit, S as StrictRequest, e as StrictResponse } from './HttpResponse-
|
|
1
|
+
export { f as HttpResponse, H as HttpResponseInit, S as StrictRequest, e as StrictResponse } from './HttpResponse-BOzDwzB6.js';
|
|
2
2
|
import './typeUtils.js';
|
package/lib/core/SetupApi.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventMap, Emitter } from 'strict-event-emitter';
|
|
2
|
-
import { R as RequestHandler } from './HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from './HttpResponse-CSyJ1cbO.mjs';
|
|
3
3
|
import { LifeCycleEventEmitter } from './sharedOptions.mjs';
|
|
4
4
|
import { Disposable } from './utils/internal/Disposable.mjs';
|
|
5
5
|
import { WebSocketHandler } from './handlers/WebSocketHandler.mjs';
|
package/lib/core/SetupApi.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventMap, Emitter } from 'strict-event-emitter';
|
|
2
|
-
import { R as RequestHandler } from './HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from './HttpResponse-BOzDwzB6.js';
|
|
3
3
|
import { LifeCycleEventEmitter } from './sharedOptions.js';
|
|
4
4
|
import { Disposable } from './utils/internal/Disposable.js';
|
|
5
5
|
import { WebSocketHandler } from './handlers/WebSocketHandler.js';
|
package/lib/core/graphql.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DocumentNode } from 'graphql';
|
|
2
|
-
import { c as RequestHandlerOptions, a as ResponseResolver } from './HttpResponse-
|
|
3
|
-
import { a as GraphQLQuery, b as GraphQLVariables, e as GraphQLHandlerNameSelector, G as GraphQLHandler, f as GraphQLResolverExtras, g as GraphQLResponseBody } from './GraphQLHandler-
|
|
2
|
+
import { c as RequestHandlerOptions, a as ResponseResolver } from './HttpResponse-CSyJ1cbO.mjs';
|
|
3
|
+
import { a as GraphQLQuery, b as GraphQLVariables, e as GraphQLHandlerNameSelector, G as GraphQLHandler, f as GraphQLResolverExtras, g as GraphQLResponseBody } from './GraphQLHandler-CzcXr7At.mjs';
|
|
4
4
|
import { Path } from './utils/matching/matchRequestUrl.mjs';
|
|
5
5
|
import './typeUtils.mjs';
|
|
6
6
|
|
package/lib/core/graphql.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DocumentNode } from 'graphql';
|
|
2
|
-
import { c as RequestHandlerOptions, a as ResponseResolver } from './HttpResponse-
|
|
3
|
-
import { a as GraphQLQuery, b as GraphQLVariables, e as GraphQLHandlerNameSelector, G as GraphQLHandler, f as GraphQLResolverExtras, g as GraphQLResponseBody } from './GraphQLHandler-
|
|
2
|
+
import { c as RequestHandlerOptions, a as ResponseResolver } from './HttpResponse-BOzDwzB6.js';
|
|
3
|
+
import { a as GraphQLQuery, b as GraphQLVariables, e as GraphQLHandlerNameSelector, G as GraphQLHandler, f as GraphQLResolverExtras, g as GraphQLResponseBody } from './GraphQLHandler-DGyzNtRQ.js';
|
|
4
4
|
import { Path } from './utils/matching/matchRequestUrl.js';
|
|
5
5
|
import './typeUtils.js';
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
import '../HttpResponse-
|
|
2
|
+
import '../HttpResponse-CSyJ1cbO.mjs';
|
|
3
3
|
import '../utils/matching/matchRequestUrl.mjs';
|
|
4
|
-
export { E as ExpectedOperationTypeNode, G as GraphQLHandler, l as GraphQLHandlerInfo, e as GraphQLHandlerNameSelector, d as GraphQLJsonRequestBody, a as GraphQLQuery, c as GraphQLRequestBody, m as GraphQLRequestParsedResult, f as GraphQLResolverExtras, g as GraphQLResponseBody, b as GraphQLVariables, n as isDocumentNode } from '../GraphQLHandler-
|
|
4
|
+
export { E as ExpectedOperationTypeNode, G as GraphQLHandler, l as GraphQLHandlerInfo, e as GraphQLHandlerNameSelector, d as GraphQLJsonRequestBody, a as GraphQLQuery, c as GraphQLRequestBody, m as GraphQLRequestParsedResult, f as GraphQLResolverExtras, g as GraphQLResponseBody, b as GraphQLVariables, n as isDocumentNode } from '../GraphQLHandler-CzcXr7At.mjs';
|
|
5
5
|
import '../typeUtils.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
import '../HttpResponse-
|
|
2
|
+
import '../HttpResponse-BOzDwzB6.js';
|
|
3
3
|
import '../utils/matching/matchRequestUrl.js';
|
|
4
|
-
export { E as ExpectedOperationTypeNode, G as GraphQLHandler, l as GraphQLHandlerInfo, e as GraphQLHandlerNameSelector, d as GraphQLJsonRequestBody, a as GraphQLQuery, c as GraphQLRequestBody, m as GraphQLRequestParsedResult, f as GraphQLResolverExtras, g as GraphQLResponseBody, b as GraphQLVariables, n as isDocumentNode } from '../GraphQLHandler-
|
|
4
|
+
export { E as ExpectedOperationTypeNode, G as GraphQLHandler, l as GraphQLHandlerInfo, e as GraphQLHandlerNameSelector, d as GraphQLJsonRequestBody, a as GraphQLQuery, c as GraphQLRequestBody, m as GraphQLRequestParsedResult, f as GraphQLResolverExtras, g as GraphQLResponseBody, b as GraphQLVariables, n as isDocumentNode } from '../GraphQLHandler-DGyzNtRQ.js';
|
|
5
5
|
import '../typeUtils.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as RequestHandlerDefaultInfo, R as RequestHandler, a as ResponseResolver, c as RequestHandlerOptions, i as ResponseResolutionContext } from '../HttpResponse-
|
|
1
|
+
import { h as RequestHandlerDefaultInfo, R as RequestHandler, a as ResponseResolver, c as RequestHandlerOptions, i as ResponseResolutionContext } from '../HttpResponse-CSyJ1cbO.mjs';
|
|
2
2
|
import { Path, Match, PathParams } from '../utils/matching/matchRequestUrl.mjs';
|
|
3
3
|
import '../typeUtils.mjs';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as RequestHandlerDefaultInfo, R as RequestHandler, a as ResponseResolver, c as RequestHandlerOptions, i as ResponseResolutionContext } from '../HttpResponse-
|
|
1
|
+
import { h as RequestHandlerDefaultInfo, R as RequestHandler, a as ResponseResolver, c as RequestHandlerOptions, i as ResponseResolutionContext } from '../HttpResponse-BOzDwzB6.js';
|
|
2
2
|
import { Path, Match, PathParams } from '../utils/matching/matchRequestUrl.js';
|
|
3
3
|
import '../typeUtils.js';
|
|
4
4
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, J as JsonBodyType, M as MaybeAsyncResponseResolverReturnType, R as RequestHandler, m as RequestHandlerArgs, h as RequestHandlerDefaultInfo, n as RequestHandlerExecutionResult, k as RequestHandlerInternalInfo, c as RequestHandlerOptions, a as ResponseResolver, l as ResponseResolverInfo, b as ResponseResolverReturnType } from '../HttpResponse-
|
|
1
|
+
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, J as JsonBodyType, M as MaybeAsyncResponseResolverReturnType, R as RequestHandler, m as RequestHandlerArgs, h as RequestHandlerDefaultInfo, n as RequestHandlerExecutionResult, k as RequestHandlerInternalInfo, c as RequestHandlerOptions, a as ResponseResolver, l as ResponseResolverInfo, b as ResponseResolverReturnType } from '../HttpResponse-CSyJ1cbO.mjs';
|
|
2
2
|
import '../typeUtils.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, J as JsonBodyType, M as MaybeAsyncResponseResolverReturnType, R as RequestHandler, m as RequestHandlerArgs, h as RequestHandlerDefaultInfo, n as RequestHandlerExecutionResult, k as RequestHandlerInternalInfo, c as RequestHandlerOptions, a as ResponseResolver, l as ResponseResolverInfo, b as ResponseResolverReturnType } from '../HttpResponse-
|
|
1
|
+
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, J as JsonBodyType, M as MaybeAsyncResponseResolverReturnType, R as RequestHandler, m as RequestHandlerArgs, h as RequestHandlerDefaultInfo, n as RequestHandlerExecutionResult, k as RequestHandlerInternalInfo, c as RequestHandlerOptions, a as ResponseResolver, l as ResponseResolverInfo, b as ResponseResolverReturnType } from '../HttpResponse-BOzDwzB6.js';
|
|
2
2
|
import '../typeUtils.js';
|
package/lib/core/http.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as DefaultBodyType, c as RequestHandlerOptions, a as ResponseResolver } from './HttpResponse-
|
|
1
|
+
import { D as DefaultBodyType, c as RequestHandlerOptions, a as ResponseResolver } from './HttpResponse-CSyJ1cbO.mjs';
|
|
2
2
|
import { HttpHandler, HttpRequestResolverExtras } from './handlers/HttpHandler.mjs';
|
|
3
3
|
import { PathParams, Path } from './utils/matching/matchRequestUrl.mjs';
|
|
4
4
|
import './typeUtils.mjs';
|
package/lib/core/http.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as DefaultBodyType, c as RequestHandlerOptions, a as ResponseResolver } from './HttpResponse-
|
|
1
|
+
import { D as DefaultBodyType, c as RequestHandlerOptions, a as ResponseResolver } from './HttpResponse-BOzDwzB6.js';
|
|
2
2
|
import { HttpHandler, HttpRequestResolverExtras } from './handlers/HttpHandler.js';
|
|
3
3
|
import { PathParams, Path } from './utils/matching/matchRequestUrl.js';
|
|
4
4
|
import './typeUtils.js';
|
package/lib/core/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { SetupApi } from './SetupApi.mjs';
|
|
2
|
-
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, f as HttpResponse, H as HttpResponseInit, J as JsonBodyType, R as RequestHandler, c as RequestHandlerOptions, a as ResponseResolver, b as ResponseResolverReturnType, S as StrictRequest, e as StrictResponse } from './HttpResponse-
|
|
2
|
+
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, f as HttpResponse, H as HttpResponseInit, J as JsonBodyType, R as RequestHandler, c as RequestHandlerOptions, a as ResponseResolver, b as ResponseResolverReturnType, S as StrictRequest, e as StrictResponse } from './HttpResponse-CSyJ1cbO.mjs';
|
|
3
3
|
export { HttpRequestHandler, HttpResponseResolver, http } from './http.mjs';
|
|
4
4
|
export { HttpHandler, HttpMethods, HttpRequestParsedResult, RequestQuery } from './handlers/HttpHandler.mjs';
|
|
5
5
|
export { GraphQLRequestHandler, GraphQLResponseResolver, graphql } from './graphql.mjs';
|
|
6
|
-
export { G as GraphQLHandler, d as GraphQLJsonRequestBody, a as GraphQLQuery, c as GraphQLRequestBody, b as GraphQLVariables, P as ParsedGraphQLRequest } from './GraphQLHandler-
|
|
7
|
-
export { ws } from './ws
|
|
6
|
+
export { G as GraphQLHandler, d as GraphQLJsonRequestBody, a as GraphQLQuery, c as GraphQLRequestBody, b as GraphQLVariables, P as ParsedGraphQLRequest } from './GraphQLHandler-CzcXr7At.mjs';
|
|
7
|
+
export { WebSocketLink, ws } from './ws.mjs';
|
|
8
8
|
export { WebSocketHandler, WebSocketHandlerEventMap } from './handlers/WebSocketHandler.mjs';
|
|
9
9
|
export { Match, Path, PathParams, matchRequestUrl } from './utils/matching/matchRequestUrl.mjs';
|
|
10
10
|
export { HandleRequestOptions, handleRequest } from './utils/handleRequest.mjs';
|
package/lib/core/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { SetupApi } from './SetupApi.js';
|
|
2
|
-
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, f as HttpResponse, H as HttpResponseInit, J as JsonBodyType, R as RequestHandler, c as RequestHandlerOptions, a as ResponseResolver, b as ResponseResolverReturnType, S as StrictRequest, e as StrictResponse } from './HttpResponse-
|
|
2
|
+
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, f as HttpResponse, H as HttpResponseInit, J as JsonBodyType, R as RequestHandler, c as RequestHandlerOptions, a as ResponseResolver, b as ResponseResolverReturnType, S as StrictRequest, e as StrictResponse } from './HttpResponse-BOzDwzB6.js';
|
|
3
3
|
export { HttpRequestHandler, HttpResponseResolver, http } from './http.js';
|
|
4
4
|
export { HttpHandler, HttpMethods, HttpRequestParsedResult, RequestQuery } from './handlers/HttpHandler.js';
|
|
5
5
|
export { GraphQLRequestHandler, GraphQLResponseResolver, graphql } from './graphql.js';
|
|
6
|
-
export { G as GraphQLHandler, d as GraphQLJsonRequestBody, a as GraphQLQuery, c as GraphQLRequestBody, b as GraphQLVariables, P as ParsedGraphQLRequest } from './GraphQLHandler-
|
|
7
|
-
export { ws } from './ws
|
|
6
|
+
export { G as GraphQLHandler, d as GraphQLJsonRequestBody, a as GraphQLQuery, c as GraphQLRequestBody, b as GraphQLVariables, P as ParsedGraphQLRequest } from './GraphQLHandler-DGyzNtRQ.js';
|
|
7
|
+
export { WebSocketLink, ws } from './ws.js';
|
|
8
8
|
export { WebSocketHandler, WebSocketHandlerEventMap } from './handlers/WebSocketHandler.js';
|
|
9
9
|
export { Match, Path, PathParams, matchRequestUrl } from './utils/matching/matchRequestUrl.js';
|
|
10
10
|
export { HandleRequestOptions, handleRequest } from './utils/handleRequest.js';
|
package/lib/core/index.js
CHANGED
|
@@ -42,7 +42,7 @@ var import_http = require("./http.js");
|
|
|
42
42
|
var import_HttpHandler = require("./handlers/HttpHandler.js");
|
|
43
43
|
var import_graphql = require("./graphql.js");
|
|
44
44
|
var import_GraphQLHandler = require("./handlers/GraphQLHandler.js");
|
|
45
|
-
var import_ws = require("./ws
|
|
45
|
+
var import_ws = require("./ws.js");
|
|
46
46
|
var import_WebSocketHandler = require("./handlers/WebSocketHandler.js");
|
|
47
47
|
var import_matchRequestUrl = require("./utils/matching/matchRequestUrl.js");
|
|
48
48
|
__reExport(core_exports, require("./utils/handleRequest.js"), module.exports);
|
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/* HTTP 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 handler */\nexport { ws } from './ws
|
|
1
|
+
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* HTTP 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 handler */\nexport { ws, type WebSocketLink } from './ws'\nexport {\n WebSocketHandler,\n type WebSocketHandlerEventMap,\n} from './handlers/WebSocketHandler'\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;AAAA,0BAA6B;AAE7B,sBAAyB;AAGzB,4BAA+B;AAC/B,kBAAqB;AACrB,yBAAyC;AACzC,qBAAwB;AACxB,4BAA+B;AAG/B,gBAAuC;AACvC,8BAGO;AAGP,6BAAgC;AAChC,yBAAc,kCApBd;AAqBA,yBAA4B;AAC5B,sBAAyB;AAmCzB,yBAAc,2BAzDd;AA0DA,yBAAc,oBA1Dd;AA2DA,oBAAuB;AACvB,yBAA4B;AAAA,IAM5B,kCAAa;","names":[]}
|
package/lib/core/index.mjs
CHANGED
|
@@ -5,7 +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
|
|
8
|
+
import { ws } from './ws.mjs';
|
|
9
9
|
import {
|
|
10
10
|
WebSocketHandler
|
|
11
11
|
} from './handlers/WebSocketHandler.mjs';
|
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/* HTTP 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 handler */\nexport { ws } from './ws
|
|
1
|
+
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* HTTP 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 handler */\nexport { ws, type WebSocketLink } from './ws'\nexport {\n WebSocketHandler,\n type WebSocketHandlerEventMap,\n} from './handlers/WebSocketHandler'\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,UAA8B;AACvC;AAAA,EACE;AAAA,OAEK;AAGP,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 { g as HandlersExecutionResult, i as ResponseResolutionContext, j as executeHandlers } from '../HttpResponse-
|
|
1
|
+
export { g as HandlersExecutionResult, i as ResponseResolutionContext, j as executeHandlers } from '../HttpResponse-CSyJ1cbO.mjs';
|
|
2
2
|
import '../typeUtils.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { g as HandlersExecutionResult, i as ResponseResolutionContext, j as executeHandlers } from '../HttpResponse-
|
|
1
|
+
export { g as HandlersExecutionResult, i as ResponseResolutionContext, j as executeHandlers } from '../HttpResponse-BOzDwzB6.js';
|
|
2
2
|
import '../typeUtils.js';
|
|
@@ -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 { g as HandlersExecutionResult } from '../HttpResponse-
|
|
4
|
+
import { g as HandlersExecutionResult } from '../HttpResponse-CSyJ1cbO.mjs';
|
|
5
5
|
import './request/onUnhandledRequest.mjs';
|
|
6
6
|
|
|
7
7
|
interface HandleRequestOptions {
|
|
@@ -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 { g as HandlersExecutionResult } from '../HttpResponse-
|
|
4
|
+
import { g as HandlersExecutionResult } from '../HttpResponse-BOzDwzB6.js';
|
|
5
5
|
import './request/onUnhandledRequest.js';
|
|
6
6
|
|
|
7
7
|
interface HandleRequestOptions {
|
|
@@ -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-CzcXr7At.mjs';
|
|
3
|
+
import '../../HttpResponse-CSyJ1cbO.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-DGyzNtRQ.js';
|
|
3
|
+
import '../../HttpResponse-BOzDwzB6.js';
|
|
4
4
|
import '../../typeUtils.js';
|
|
5
5
|
import '../matching/matchRequestUrl.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler, h as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-
|
|
1
|
+
import { R as RequestHandler, h as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-CSyJ1cbO.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, h as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-
|
|
1
|
+
import { R as RequestHandler, h as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-BOzDwzB6.js';
|
|
2
2
|
import '../../typeUtils.js';
|
|
3
3
|
|
|
4
4
|
declare function use(currentHandlers: Array<RequestHandler>, ...handlers: Array<RequestHandler>): void;
|
|
@@ -1,10 +1,10 @@
|
|
|
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-CSyJ1cbO.mjs';
|
|
3
3
|
import { WebSocketHandler } from '../handlers/WebSocketHandler.mjs';
|
|
4
4
|
import '../typeUtils.mjs';
|
|
5
5
|
import 'strict-event-emitter';
|
|
6
6
|
import '@mswjs/interceptors/WebSocket';
|
|
7
|
-
import '
|
|
7
|
+
import '../utils/matching/matchRequestUrl.mjs';
|
|
8
8
|
|
|
9
9
|
interface HandleWebSocketEventOptions {
|
|
10
10
|
getHandlers: () => Array<RequestHandler | WebSocketHandler>;
|
|
@@ -1,10 +1,10 @@
|
|
|
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-BOzDwzB6.js';
|
|
3
3
|
import { WebSocketHandler } from '../handlers/WebSocketHandler.js';
|
|
4
4
|
import '../typeUtils.js';
|
|
5
5
|
import 'strict-event-emitter';
|
|
6
6
|
import '@mswjs/interceptors/WebSocket';
|
|
7
|
-
import '
|
|
7
|
+
import '../utils/matching/matchRequestUrl.js';
|
|
8
8
|
|
|
9
9
|
interface HandleWebSocketEventOptions {
|
|
10
10
|
getHandlers: () => Array<RequestHandler | WebSocketHandler>;
|
|
@@ -22,7 +22,7 @@ __export(handleWebSocketEvent_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(handleWebSocketEvent_exports);
|
|
24
24
|
var import_WebSocketHandler = require("../handlers/WebSocketHandler.js");
|
|
25
|
-
var import_webSocketInterceptor = require("
|
|
25
|
+
var import_webSocketInterceptor = require("./webSocketInterceptor.js");
|
|
26
26
|
function handleWebSocketEvent(options) {
|
|
27
27
|
import_webSocketInterceptor.webSocketInterceptor.on("connection", (connection) => {
|
|
28
28
|
const handlers = options.getHandlers();
|
|
@@ -0,0 +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'\n\ninterface HandleWebSocketEventOptions {\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', (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 = handlers.filter<WebSocketHandler>(\n (handler): handler is WebSocketHandler => {\n if (handler instanceof WebSocketHandler) {\n return handler.predicate({\n event: connectionEvent,\n parsedResult: handler.parse({\n event: connectionEvent,\n }),\n })\n }\n\n return false\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 options?.onPassthroughConnection(connection)\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\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;AAEA,8BAAiD;AACjD,kCAAqC;AAQ9B,SAAS,qBAAqB,SAAsC;AACzE,mDAAqB,GAAG,cAAc,CAAC,eAAe;AACpD,UAAM,WAAW,QAAQ,YAAY;AAErC,UAAM,kBAAkB,IAAI,aAAa,cAAc;AAAA,MACrD,MAAM;AAAA,IACR,CAAC;AAMD,UAAM,mBAAmB,SAAS;AAAA,MAChC,CAAC,YAAyC;AACxC,YAAI,mBAAmB,0CAAkB;AACvC,iBAAO,QAAQ,UAAU;AAAA,YACvB,OAAO;AAAA,YACP,cAAc,QAAQ,MAAM;AAAA,cAC1B,OAAO;AAAA,YACT,CAAC;AAAA,UACH,CAAC;AAAA,QACH;AAEA,eAAO;AAAA,MACT;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;AACL,eAAS,wBAAwB,UAAU;AAI3C,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 { WebSocketHandler, kDispatchEvent } from '../handlers/WebSocketHandler.mjs';
|
|
2
|
-
import { webSocketInterceptor } from '
|
|
2
|
+
import { webSocketInterceptor } from './webSocketInterceptor.mjs';
|
|
3
3
|
function handleWebSocketEvent(options) {
|
|
4
4
|
webSocketInterceptor.on("connection", (connection) => {
|
|
5
5
|
const handlers = options.getHandlers();
|
|
@@ -0,0 +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'\n\ninterface HandleWebSocketEventOptions {\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', (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 = handlers.filter<WebSocketHandler>(\n (handler): handler is WebSocketHandler => {\n if (handler instanceof WebSocketHandler) {\n return handler.predicate({\n event: connectionEvent,\n parsedResult: handler.parse({\n event: connectionEvent,\n }),\n })\n }\n\n return false\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 options?.onPassthroughConnection(connection)\n\n // If none of the \"ws\" handlers matched,\n // establish the WebSocket connection as-is.\n connection.server.connect()\n connection.client.addEventListener('message', (event) => {\n connection.server.send(event.data)\n })\n }\n })\n}\n"],"mappings":"AAEA,SAAS,kBAAkB,sBAAsB;AACjD,SAAS,4BAA4B;AAQ9B,SAAS,qBAAqB,SAAsC;AACzE,uBAAqB,GAAG,cAAc,CAAC,eAAe;AACpD,UAAM,WAAW,QAAQ,YAAY;AAErC,UAAM,kBAAkB,IAAI,aAAa,cAAc;AAAA,MACrD,MAAM;AAAA,IACR,CAAC;AAMD,UAAM,mBAAmB,SAAS;AAAA,MAChC,CAAC,YAAyC;AACxC,YAAI,mBAAmB,kBAAkB;AACvC,iBAAO,QAAQ,UAAU;AAAA,YACvB,OAAO;AAAA,YACP,cAAc,QAAQ,MAAM;AAAA,cAC1B,OAAO;AAAA,YACT,CAAC;AAAA,UACH,CAAC;AAAA,QACH;AAEA,eAAO;AAAA,MACT;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;AACL,eAAS,wBAAwB,UAAU;AAI3C,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,20 +1,15 @@
|
|
|
1
1
|
import { WebSocketClientConnectionProtocol, WebSocketData } from '@mswjs/interceptors/WebSocket';
|
|
2
|
-
import { WebSocketHandlerEventMap, WebSocketHandler } from '
|
|
3
|
-
import { Path } from '
|
|
2
|
+
import { WebSocketHandlerEventMap, WebSocketHandler } from './handlers/WebSocketHandler.mjs';
|
|
3
|
+
import { Path } from './utils/matching/matchRequestUrl.mjs';
|
|
4
4
|
import 'strict-event-emitter';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* chat.on('connection', ({ client }) => {
|
|
12
|
-
* client.send('hello from server!')
|
|
13
|
-
* })
|
|
14
|
-
*/
|
|
15
|
-
declare function createWebSocketLinkHandler(url: Path): {
|
|
6
|
+
type WebSocketLink = {
|
|
7
|
+
/**
|
|
8
|
+
* A set of all WebSocket clients connected
|
|
9
|
+
* to this link.
|
|
10
|
+
*/
|
|
16
11
|
clients: Set<WebSocketClientConnectionProtocol>;
|
|
17
|
-
on<
|
|
12
|
+
on<EventType extends keyof WebSocketHandlerEventMap>(event: EventType, listener: (...args: WebSocketHandlerEventMap[EventType]) => void): WebSocketHandler;
|
|
18
13
|
/**
|
|
19
14
|
* Broadcasts the given data to all WebSocket clients.
|
|
20
15
|
*
|
|
@@ -37,8 +32,18 @@ declare function createWebSocketLinkHandler(url: Path): {
|
|
|
37
32
|
*/
|
|
38
33
|
broadcastExcept(clients: WebSocketClientConnectionProtocol | Array<WebSocketClientConnectionProtocol>, data: WebSocketData): void;
|
|
39
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Intercepts outgoing WebSocket connections to the given URL.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const chat = ws.link('wss://chat.example.com')
|
|
40
|
+
* chat.on('connection', ({ client }) => {
|
|
41
|
+
* client.send('hello from server!')
|
|
42
|
+
* })
|
|
43
|
+
*/
|
|
44
|
+
declare function createWebSocketLinkHandler(url: Path): WebSocketLink;
|
|
40
45
|
declare const ws: {
|
|
41
46
|
link: typeof createWebSocketLinkHandler;
|
|
42
47
|
};
|
|
43
48
|
|
|
44
|
-
export { ws };
|
|
49
|
+
export { type WebSocketLink, ws };
|
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
import { WebSocketClientConnectionProtocol, WebSocketData } from '@mswjs/interceptors/WebSocket';
|
|
2
|
-
import { WebSocketHandlerEventMap, WebSocketHandler } from '
|
|
3
|
-
import { Path } from '
|
|
2
|
+
import { WebSocketHandlerEventMap, WebSocketHandler } from './handlers/WebSocketHandler.js';
|
|
3
|
+
import { Path } from './utils/matching/matchRequestUrl.js';
|
|
4
4
|
import 'strict-event-emitter';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* chat.on('connection', ({ client }) => {
|
|
12
|
-
* client.send('hello from server!')
|
|
13
|
-
* })
|
|
14
|
-
*/
|
|
15
|
-
declare function createWebSocketLinkHandler(url: Path): {
|
|
6
|
+
type WebSocketLink = {
|
|
7
|
+
/**
|
|
8
|
+
* A set of all WebSocket clients connected
|
|
9
|
+
* to this link.
|
|
10
|
+
*/
|
|
16
11
|
clients: Set<WebSocketClientConnectionProtocol>;
|
|
17
|
-
on<
|
|
12
|
+
on<EventType extends keyof WebSocketHandlerEventMap>(event: EventType, listener: (...args: WebSocketHandlerEventMap[EventType]) => void): WebSocketHandler;
|
|
18
13
|
/**
|
|
19
14
|
* Broadcasts the given data to all WebSocket clients.
|
|
20
15
|
*
|
|
@@ -37,8 +32,18 @@ declare function createWebSocketLinkHandler(url: Path): {
|
|
|
37
32
|
*/
|
|
38
33
|
broadcastExcept(clients: WebSocketClientConnectionProtocol | Array<WebSocketClientConnectionProtocol>, data: WebSocketData): void;
|
|
39
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Intercepts outgoing WebSocket connections to the given URL.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const chat = ws.link('wss://chat.example.com')
|
|
40
|
+
* chat.on('connection', ({ client }) => {
|
|
41
|
+
* client.send('hello from server!')
|
|
42
|
+
* })
|
|
43
|
+
*/
|
|
44
|
+
declare function createWebSocketLinkHandler(url: Path): WebSocketLink;
|
|
40
45
|
declare const ws: {
|
|
41
46
|
link: typeof createWebSocketLinkHandler;
|
|
42
47
|
};
|
|
43
48
|
|
|
44
|
-
export { ws };
|
|
49
|
+
export { type WebSocketLink, ws };
|
|
@@ -22,15 +22,15 @@ __export(ws_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(ws_exports);
|
|
24
24
|
var import_outvariant = require("outvariant");
|
|
25
|
-
var import_WebSocketHandler = require("
|
|
26
|
-
var import_matchRequestUrl = require("
|
|
27
|
-
var import_WebSocketClientManager = require("./WebSocketClientManager.js");
|
|
25
|
+
var import_WebSocketHandler = require("./handlers/WebSocketHandler.js");
|
|
26
|
+
var import_matchRequestUrl = require("./utils/matching/matchRequestUrl.js");
|
|
27
|
+
var import_WebSocketClientManager = require("./ws/WebSocketClientManager.js");
|
|
28
28
|
const wsBroadcastChannel = new BroadcastChannel("msw:ws-client-manager");
|
|
29
29
|
function createWebSocketLinkHandler(url) {
|
|
30
30
|
(0, import_outvariant.invariant)(url, "Expected a WebSocket server URL but got undefined");
|
|
31
31
|
(0, import_outvariant.invariant)(
|
|
32
32
|
(0, import_matchRequestUrl.isPath)(url),
|
|
33
|
-
"Expected a WebSocket server URL but got %s",
|
|
33
|
+
"Expected a WebSocket server URL to be a valid path but got %s",
|
|
34
34
|
typeof url
|
|
35
35
|
);
|
|
36
36
|
const clientManager = new import_WebSocketClientManager.WebSocketClientManager(wsBroadcastChannel);
|
|
@@ -44,28 +44,9 @@ function createWebSocketLinkHandler(url) {
|
|
|
44
44
|
handler[import_WebSocketHandler.kEmitter].on(event, listener);
|
|
45
45
|
return handler;
|
|
46
46
|
},
|
|
47
|
-
/**
|
|
48
|
-
* Broadcasts the given data to all WebSocket clients.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* const service = ws.link('wss://example.com')
|
|
52
|
-
* service.on('connection', () => {
|
|
53
|
-
* service.broadcast('hello, everyone!')
|
|
54
|
-
* })
|
|
55
|
-
*/
|
|
56
47
|
broadcast(data) {
|
|
57
48
|
this.broadcastExcept([], data);
|
|
58
49
|
},
|
|
59
|
-
/**
|
|
60
|
-
* Broadcasts the given data to all WebSocket clients
|
|
61
|
-
* except the ones provided in the `clients` argument.
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* const service = ws.link('wss://example.com')
|
|
65
|
-
* service.on('connection', ({ client }) => {
|
|
66
|
-
* service.broadcastExcept(client, 'hi, the rest of you!')
|
|
67
|
-
* })
|
|
68
|
-
*/
|
|
69
50
|
broadcastExcept(clients, data) {
|
|
70
51
|
const ignoreClients = Array.prototype.concat(clients).map((client) => client.id);
|
|
71
52
|
clientManager.clients.forEach((otherClient) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/ws.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport type {\n WebSocketClientConnectionProtocol,\n WebSocketData,\n} from '@mswjs/interceptors/WebSocket'\nimport {\n WebSocketHandler,\n kEmitter,\n type WebSocketHandlerEventMap,\n} from './handlers/WebSocketHandler'\nimport { Path, isPath } from './utils/matching/matchRequestUrl'\nimport { WebSocketClientManager } from './ws/WebSocketClientManager'\n\nconst wsBroadcastChannel = new BroadcastChannel('msw:ws-client-manager')\n\nexport type WebSocketLink = {\n /**\n * A set of all WebSocket clients connected\n * to this link.\n */\n clients: Set<WebSocketClientConnectionProtocol>\n\n on<EventType extends keyof WebSocketHandlerEventMap>(\n event: EventType,\n listener: (...args: WebSocketHandlerEventMap[EventType]) => void,\n ): WebSocketHandler\n\n /**\n * Broadcasts the given data to all WebSocket clients.\n *\n * @example\n * const service = ws.link('wss://example.com')\n * service.on('connection', () => {\n * service.broadcast('hello, everyone!')\n * })\n */\n broadcast(data: WebSocketData): void\n\n /**\n * Broadcasts the given data to all WebSocket clients\n * except the ones provided in the `clients` argument.\n *\n * @example\n * const service = ws.link('wss://example.com')\n * service.on('connection', ({ client }) => {\n * service.broadcastExcept(client, 'hi, the rest of you!')\n * })\n */\n broadcastExcept(\n clients:\n | WebSocketClientConnectionProtocol\n | Array<WebSocketClientConnectionProtocol>,\n data: WebSocketData,\n ): void\n}\n\n/**\n * Intercepts outgoing WebSocket connections to the given URL.\n *\n * @example\n * const chat = ws.link('wss://chat.example.com')\n * chat.on('connection', ({ client }) => {\n * client.send('hello from server!')\n * })\n */\nfunction createWebSocketLinkHandler(url: Path): WebSocketLink {\n invariant(url, 'Expected a WebSocket server URL but got undefined')\n\n invariant(\n isPath(url),\n 'Expected a WebSocket server URL to be a valid path but got %s',\n typeof url,\n )\n\n const clientManager = new WebSocketClientManager(wsBroadcastChannel)\n\n return {\n clients: clientManager.clients,\n on(event, listener) {\n const handler = new WebSocketHandler(url)\n\n // Add the connection event listener for when the\n // handler matches and emits a connection event.\n // When that happens, store that connection in the\n // set of all connections for reference.\n handler[kEmitter].on('connection', ({ client }) => {\n clientManager.addConnection(client)\n })\n\n // The \"handleWebSocketEvent\" function will invoke\n // the \"run()\" method on the WebSocketHandler.\n // If the handler matches, it will emit the \"connection\"\n // event. Attach the user-defined listener to that event.\n handler[kEmitter].on(event, listener)\n\n return handler\n },\n\n broadcast(data) {\n // This will invoke \"send()\" on the immediate clients\n // in this runtime and post a message to the broadcast channel\n // to trigger send for the clients in other runtimes.\n this.broadcastExcept([], data)\n },\n\n broadcastExcept(clients, data) {\n const ignoreClients = Array.prototype\n .concat(clients)\n .map((client) => client.id)\n\n clientManager.clients.forEach((otherClient) => {\n if (!ignoreClients.includes(otherClient.id)) {\n otherClient.send(data)\n }\n })\n },\n }\n}\n\nexport const ws = {\n link: createWebSocketLinkHandler,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA0B;AAK1B,8BAIO;AACP,6BAA6B;AAC7B,oCAAuC;AAEvC,MAAM,qBAAqB,IAAI,iBAAiB,uBAAuB;AAoDvE,SAAS,2BAA2B,KAA0B;AAC5D,mCAAU,KAAK,mDAAmD;AAElE;AAAA,QACE,+BAAO,GAAG;AAAA,IACV;AAAA,IACA,OAAO;AAAA,EACT;AAEA,QAAM,gBAAgB,IAAI,qDAAuB,kBAAkB;AAEnE,SAAO;AAAA,IACL,SAAS,cAAc;AAAA,IACvB,GAAG,OAAO,UAAU;AAClB,YAAM,UAAU,IAAI,yCAAiB,GAAG;AAMxC,cAAQ,gCAAQ,EAAE,GAAG,cAAc,CAAC,EAAE,OAAO,MAAM;AACjD,sBAAc,cAAc,MAAM;AAAA,MACpC,CAAC;AAMD,cAAQ,gCAAQ,EAAE,GAAG,OAAO,QAAQ;AAEpC,aAAO;AAAA,IACT;AAAA,IAEA,UAAU,MAAM;AAId,WAAK,gBAAgB,CAAC,GAAG,IAAI;AAAA,IAC/B;AAAA,IAEA,gBAAgB,SAAS,MAAM;AAC7B,YAAM,gBAAgB,MAAM,UACzB,OAAO,OAAO,EACd,IAAI,CAAC,WAAW,OAAO,EAAE;AAE5B,oBAAc,QAAQ,QAAQ,CAAC,gBAAgB;AAC7C,YAAI,CAAC,cAAc,SAAS,YAAY,EAAE,GAAG;AAC3C,sBAAY,KAAK,IAAI;AAAA,QACvB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,MAAM,KAAK;AAAA,EAChB,MAAM;AACR;","names":[]}
|