New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

msw

Package Overview
Dependencies
Maintainers
1
Versions
279
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

msw - npm Package Compare versions

Comparing version 2.2.3 to 2.3.0-ws.rc-1

lib/core/GraphQLHandler-Cbu12sb0.d.ts

13

lib/browser/index.d.ts
import { SharedOptions, LifeCycleEventEmitter, LifeCycleEventsMap } from "../core/sharedOptions";
import { RequestHandler, RequestHandlerDefaultInfo } from "../core/handlers/RequestHandler";
import { RequestHandler } from "../core/handlers/RequestHandler";
import { WebSocketHandler } from "../core/handlers/WebSocketHandler";
import { SetupApi } from "../core/SetupApi";

@@ -57,3 +58,3 @@

*/
use: (...handlers: RequestHandler[]) => void;
use: (...handlers: Array<RequestHandler | WebSocketHandler>) => void;
/**

@@ -71,3 +72,3 @@ * Marks all request handlers that respond using `res.once()` as unused.

*/
resetHandlers: (...nextHandlers: RequestHandler[]) => void;
resetHandlers: (...nextHandlers: Array<RequestHandler | WebSocketHandler>) => void;
/**

@@ -78,3 +79,3 @@ * Returns a readonly list of currently active request handlers.

*/
listHandlers(): ReadonlyArray<RequestHandler<RequestHandlerDefaultInfo, any>>;
listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>;
/**

@@ -94,3 +95,3 @@ * Life-cycle events.

private listeners;
constructor(...handlers: Array<RequestHandler>);
constructor(...handlers: Array<RequestHandler | WebSocketHandler>);
private createWorkerContext;

@@ -106,4 +107,4 @@ start(options?: StartOptions): StartReturnType;

*/
declare function setupWorker(...handlers: Array<RequestHandler>): SetupWorker;
declare function setupWorker(...handlers: Array<RequestHandler | WebSocketHandler>): SetupWorker;
export { type SetupWorker, SetupWorkerApi, type StartOptions, setupWorker };

@@ -1,2 +0,2 @@

import { R as RequestHandler } from './HttpResponse-_514VQ9z.js';
import { R as RequestHandler } from './HttpResponse-DeJBWGN5.js';
import './typeUtils.js';

@@ -3,0 +3,0 @@

import { DocumentNode } from 'graphql';
import { c as RequestHandlerOptions, a as ResponseResolver } from './HttpResponse-_514VQ9z.js';
import { a as GraphQLQuery, b as GraphQLVariables, e as GraphQLHandlerNameSelector, G as GraphQLHandler, f as GraphQLResolverExtras, g as GraphQLResponseBody } from './GraphQLHandler-jOzqbxSK.js';
import { c as RequestHandlerOptions, a as ResponseResolver } from './HttpResponse-DeJBWGN5.js';
import { a as GraphQLQuery, b as GraphQLVariables, e as GraphQLHandlerNameSelector, G as GraphQLHandler, f as GraphQLResolverExtras, g as GraphQLResponseBody } from './GraphQLHandler-Cbu12sb0.js';
import { Path } from './utils/matching/matchRequestUrl.js';

@@ -5,0 +5,0 @@ import './typeUtils.js';

import 'graphql';
import '../HttpResponse-_514VQ9z.js';
import '../HttpResponse-DeJBWGN5.js';
import '../utils/matching/matchRequestUrl.js';
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-jOzqbxSK.js';
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-Cbu12sb0.js';
import '../typeUtils.js';

@@ -1,2 +0,2 @@

import { g as RequestHandlerDefaultInfo, R as RequestHandler, a as ResponseResolver, c as RequestHandlerOptions, i as ResponseResolutionContext } from '../HttpResponse-_514VQ9z.js';
import { h as RequestHandlerDefaultInfo, R as RequestHandler, a as ResponseResolver, c as RequestHandlerOptions, i as ResponseResolutionContext } from '../HttpResponse-DeJBWGN5.js';
import { Path, Match, PathParams } from '../utils/matching/matchRequestUrl.js';

@@ -3,0 +3,0 @@ import '../typeUtils.js';

@@ -1,2 +0,2 @@

export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, J as JsonBodyType, M as MaybeAsyncResponseResolverReturnType, R as RequestHandler, m as RequestHandlerArgs, g as RequestHandlerDefaultInfo, n as RequestHandlerExecutionResult, k as RequestHandlerInternalInfo, c as RequestHandlerOptions, a as ResponseResolver, l as ResponseResolverInfo, b as ResponseResolverReturnType } from '../HttpResponse-_514VQ9z.js';
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-DeJBWGN5.js';
import '../typeUtils.js';

@@ -1,2 +0,2 @@

import { D as DefaultBodyType, c as RequestHandlerOptions, a as ResponseResolver } from './HttpResponse-_514VQ9z.js';
import { D as DefaultBodyType, c as RequestHandlerOptions, a as ResponseResolver } from './HttpResponse-DeJBWGN5.js';
import { HttpHandler, HttpRequestResolverExtras } from './handlers/HttpHandler.js';

@@ -3,0 +3,0 @@ import { PathParams, Path } from './utils/matching/matchRequestUrl.js';

@@ -1,2 +0,2 @@

export { f as HttpResponse, H as HttpResponseInit, S as StrictRequest, e as StrictResponse } from './HttpResponse-_514VQ9z.js';
export { f as HttpResponse, H as HttpResponseInit, S as StrictRequest, e as StrictResponse } from './HttpResponse-DeJBWGN5.js';
import './typeUtils.js';
export { SetupApi } from './SetupApi.js';
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-_514VQ9z.js';
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-DeJBWGN5.js';
export { HttpRequestHandler, HttpResponseResolver, http } from './http.js';
export { HttpHandler, HttpMethods, HttpRequestParsedResult, RequestQuery } from './handlers/HttpHandler.js';
export { GraphQLRequestHandler, GraphQLResponseResolver, graphql } from './graphql.js';
export { G as GraphQLHandler, d as GraphQLJsonRequestBody, a as GraphQLQuery, c as GraphQLRequestBody, b as GraphQLVariables, P as ParsedGraphQLRequest } from './GraphQLHandler-jOzqbxSK.js';
export { G as GraphQLHandler, d as GraphQLJsonRequestBody, a as GraphQLQuery, c as GraphQLRequestBody, b as GraphQLVariables, P as ParsedGraphQLRequest } from './GraphQLHandler-Cbu12sb0.js';
export { ws } from './ws/ws.js';
export { Match, Path, PathParams, matchRequestUrl } from './utils/matching/matchRequestUrl.js';

@@ -17,4 +18,6 @@ export { HandleRequestOptions, handleRequest } from './utils/handleRequest.js';

import './utils/internal/Disposable.js';
import './handlers/WebSocketHandler.js';
import '@mswjs/interceptors/WebSocket';
import './typeUtils.js';
import 'graphql';
import './utils/request/onUnhandledRequest.js';

@@ -33,3 +33,4 @@ "use strict";

matchRequestUrl: () => import_matchRequestUrl.matchRequestUrl,
passthrough: () => import_passthrough.passthrough
passthrough: () => import_passthrough.passthrough,
ws: () => import_ws.ws
});

@@ -44,2 +45,3 @@ module.exports = __toCommonJS(core_exports);

var import_GraphQLHandler = require("./handlers/GraphQLHandler.js");
var import_ws = require("./ws/ws.js");
var import_matchRequestUrl = require("./utils/matching/matchRequestUrl.js");

@@ -46,0 +48,0 @@ __reExport(core_exports, require("./utils/handleRequest.js"), module.exports);

@@ -1,2 +0,2 @@

import { e as StrictResponse } from './HttpResponse-_514VQ9z.js';
import { e as StrictResponse } from './HttpResponse-DeJBWGN5.js';
import './typeUtils.js';

@@ -3,0 +3,0 @@

import { EventMap, Emitter } from 'strict-event-emitter';
import { R as RequestHandler, g as RequestHandlerDefaultInfo } from './HttpResponse-_514VQ9z.js';
import { R as RequestHandler } from './HttpResponse-DeJBWGN5.js';
import { LifeCycleEventEmitter } from './sharedOptions.js';
import { Disposable } from './utils/internal/Disposable.js';
import { WebSocketHandler } from './handlers/WebSocketHandler.js';
import './typeUtils.js';
import './utils/request/onUnhandledRequest.js';
import '@mswjs/interceptors/WebSocket';
import './utils/matching/matchRequestUrl.js';
declare abstract class HandlersController {
abstract prepend(runtimeHandlers: Array<RequestHandler>): void;
abstract reset(nextHandles: Array<RequestHandler>): void;
abstract currentHandlers(): Array<RequestHandler>;
abstract prepend(runtimeHandlers: Array<RequestHandler | WebSocketHandler>): void;
abstract reset(nextHandles: Array<RequestHandler | WebSocketHandler>): void;
abstract currentHandlers(): Array<RequestHandler | WebSocketHandler>;
}

@@ -16,6 +19,6 @@ declare class InMemoryHandlersController implements HandlersController {

private handlers;
constructor(initialHandlers: Array<RequestHandler>);
prepend(runtimeHandles: Array<RequestHandler>): void;
reset(nextHandlers: Array<RequestHandler>): void;
currentHandlers(): Array<RequestHandler>;
constructor(initialHandlers: Array<RequestHandler | WebSocketHandler>);
prepend(runtimeHandles: Array<RequestHandler | WebSocketHandler>): void;
reset(nextHandlers: Array<RequestHandler | WebSocketHandler>): void;
currentHandlers(): Array<RequestHandler | WebSocketHandler>;
}

@@ -30,8 +33,8 @@ /**

readonly events: LifeCycleEventEmitter<EventsMap>;
constructor(...initialHandlers: Array<RequestHandler>);
constructor(...initialHandlers: Array<RequestHandler | WebSocketHandler>);
private validateHandlers;
use(...runtimeHandlers: Array<RequestHandler>): void;
use(...runtimeHandlers: Array<RequestHandler | WebSocketHandler>): void;
restoreHandlers(): void;
resetHandlers(...nextHandlers: Array<RequestHandler>): void;
listHandlers(): ReadonlyArray<RequestHandler<RequestHandlerDefaultInfo, any, any>>;
resetHandlers(...nextHandlers: Array<RequestHandler | WebSocketHandler>): void;
listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>;
private createLifeCycleEvents;

@@ -38,0 +41,0 @@ }

@@ -87,3 +87,5 @@ "use strict";

this.handlersController.currentHandlers().forEach((handler) => {
handler.isUsed = false;
if ("isUsed" in handler) {
handler.isUsed = false;
}
});

@@ -90,0 +92,0 @@ }

@@ -1,2 +0,2 @@

export { h as HandlersExecutionResult, i as ResponseResolutionContext, j as executeHandlers } from '../HttpResponse-_514VQ9z.js';
export { g as HandlersExecutionResult, i as ResponseResolutionContext, j as executeHandlers } from '../HttpResponse-DeJBWGN5.js';
import '../typeUtils.js';

@@ -24,2 +24,3 @@ "use strict";

module.exports = __toCommonJS(executeHandlers_exports);
var import_RequestHandler = require("../handlers/RequestHandler.js");
const executeHandlers = async ({

@@ -34,2 +35,5 @@ request,

for (const handler of handlers) {
if (!(handler instanceof import_RequestHandler.RequestHandler)) {
continue;
}
result = await handler.run({ request, requestId, resolutionContext });

@@ -36,0 +40,0 @@ if (result !== null) {

import { Emitter } from 'strict-event-emitter';
import { h as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-_514VQ9z.js';
import { SharedOptions, LifeCycleEventsMap } from '../sharedOptions.js';
import { RequiredDeep } from '../typeUtils.js';
import { g as HandlersExecutionResult } from '../HttpResponse-DeJBWGN5.js';
import './request/onUnhandledRequest.js';

@@ -35,4 +35,4 @@

}
declare function handleRequest(request: Request, requestId: string, handlers: Array<RequestHandler>, options: RequiredDeep<SharedOptions>, emitter: Emitter<LifeCycleEventsMap>, handleRequestOptions?: HandleRequestOptions): Promise<Response | undefined>;
declare function handleRequest(request: Request, requestId: string, handlers: Array<unknown>, options: RequiredDeep<SharedOptions>, emitter: Emitter<LifeCycleEventsMap>, handleRequestOptions?: HandleRequestOptions): Promise<Response | undefined>;
export { type HandleRequestOptions, handleRequest };

@@ -1,2 +0,2 @@

import { H as HttpResponseInit } from '../../HttpResponse-_514VQ9z.js';
import { H as HttpResponseInit } from '../../HttpResponse-DeJBWGN5.js';
import '../../typeUtils.js';

@@ -3,0 +3,0 @@

import 'graphql';
export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-jOzqbxSK.js';
import '../../HttpResponse-_514VQ9z.js';
export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-Cbu12sb0.js';
import '../../HttpResponse-DeJBWGN5.js';
import '../../typeUtils.js';
import '../matching/matchRequestUrl.js';

@@ -1,2 +0,2 @@

import { d as DefaultRequestMultipartBody } from '../../HttpResponse-_514VQ9z.js';
import { d as DefaultRequestMultipartBody } from '../../HttpResponse-DeJBWGN5.js';
import '../../typeUtils.js';

@@ -3,0 +3,0 @@

@@ -1,2 +0,2 @@

import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-_514VQ9z.js';
import { R as RequestHandler, h as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-DeJBWGN5.js';
import '../../typeUtils.js';

@@ -3,0 +3,0 @@

@@ -18,3 +18,4 @@ type Path = string | RegExp;

declare function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match;
declare function isPath(value: unknown): value is Path;
export { type Match, type Path, type PathParams, coercePath, matchRequestUrl };
export { type Match, type Path, type PathParams, coercePath, isPath, matchRequestUrl };

@@ -22,2 +22,3 @@ "use strict";

coercePath: () => coercePath,
isPath: () => isPath,
matchRequestUrl: () => matchRequestUrl

@@ -52,2 +53,5 @@ });

}
function isPath(value) {
return typeof value === "string" || value instanceof RegExp;
}
//# sourceMappingURL=matchRequestUrl.js.map

@@ -5,3 +5,3 @@ /* eslint-disable */

/**
* Mock Service Worker (2.2.3).
* Mock Service Worker (2.3.0-ws.rc-1).
* @see https://github.com/mswjs/msw

@@ -8,0 +8,0 @@ * - Please do NOT modify this file.

@@ -1,5 +0,6 @@

import { RequestHandler, RequestHandlerDefaultInfo } from "../core/handlers/RequestHandler";
import { RequestHandler } from "../core/handlers/RequestHandler";
import { BatchInterceptor, Interceptor, HttpRequestEventMap } from '@mswjs/interceptors';
import { SharedOptions, LifeCycleEventEmitter, LifeCycleEventsMap } from "../core/sharedOptions";
import { SetupApi } from "../core/SetupApi";
import { WebSocketHandler } from "../core/handlers/WebSocketHandler";
import { PartialDeep } from 'type-fest';

@@ -25,3 +26,3 @@

*/
use(...handlers: Array<RequestHandler>): void;
use(...handlers: Array<RequestHandler | WebSocketHandler>): void;
/**

@@ -38,3 +39,3 @@ * Marks all request handlers that respond using `res.once()` as unused.

*/
resetHandlers(...nextHandlers: Array<RequestHandler>): void;
resetHandlers(...nextHandlers: Array<RequestHandler | WebSocketHandler>): void;
/**

@@ -45,3 +46,3 @@ * Returns a readonly list of currently active request handlers.

*/
listHandlers(): ReadonlyArray<RequestHandler<RequestHandlerDefaultInfo, any>>;
listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>;
/**

@@ -66,3 +67,3 @@ * Life-cycle events.

new (): Interceptor<HttpRequestEventMap>;
}>, handlers: Array<RequestHandler>);
}>, handlers: Array<RequestHandler | WebSocketHandler>);
/**

@@ -69,0 +70,0 @@ * Subscribe to all requests that are using the interceptor object

@@ -36,2 +36,4 @@ "use strict";

var import_devUtils = require("../core/utils/internal/devUtils.js");
var import_handleWebSocketEvent = require("../core/utils/handleWebSocketEvent.js");
var import_webSocketInterceptor = require("../core/ws/webSocketInterceptor.js");
var DEFAULT_LISTEN_OPTIONS = {

@@ -82,2 +84,5 @@ onUnhandledRequest: "warn"

);
(0, import_handleWebSocketEvent.handleWebSocketEvent)(() => {
return this.handlersController.currentHandlers();
});
}

@@ -90,4 +95,6 @@ listen(options = {}) {

this.interceptor.apply();
import_webSocketInterceptor.webSocketInterceptor.apply();
this.subscriptions.push(() => {
this.interceptor.dispose();
import_webSocketInterceptor.webSocketInterceptor.dispose();
});

@@ -94,0 +101,0 @@ (0, import_outvariant.invariant)(

import { PartialDeep } from 'type-fest';
import { RequestHandler, RequestHandlerDefaultInfo } from "../core/handlers/RequestHandler";
import { RequestHandler } from "../core/handlers/RequestHandler";
import { WebSocketHandler } from "../core/handlers/WebSocketHandler";
import { SharedOptions, LifeCycleEventEmitter, LifeCycleEventsMap } from "../core/sharedOptions";

@@ -25,3 +26,3 @@ import { BatchInterceptor, Interceptor, HttpRequestEventMap } from '@mswjs/interceptors';

*/
use(...handlers: Array<RequestHandler>): void;
use(...handlers: Array<RequestHandler | WebSocketHandler>): void;
/**

@@ -38,3 +39,3 @@ * Marks all request handlers that respond using `res.once()` as unused.

*/
resetHandlers(...nextHandlers: Array<RequestHandler>): void;
resetHandlers(...nextHandlers: Array<RequestHandler | WebSocketHandler>): void;
/**

@@ -45,3 +46,3 @@ * Returns a readonly list of currently active request handlers.

*/
listHandlers(): ReadonlyArray<RequestHandler<RequestHandlerDefaultInfo, any>>;
listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>;
/**

@@ -77,3 +78,3 @@ * Life-cycle events.

new (): Interceptor<HttpRequestEventMap>;
}>, handlers: Array<RequestHandler>);
}>, handlers: Array<RequestHandler | WebSocketHandler>);
/**

@@ -88,3 +89,3 @@ * Subscribe to all requests that are using the interceptor object

declare class SetupServerApi extends SetupServerCommonApi implements SetupServer {
constructor(handlers: Array<RequestHandler>);
constructor(handlers: Array<RequestHandler | WebSocketHandler>);
boundary<Fn extends (...args: Array<any>) => unknown>(callback: Fn): (...args: Parameters<Fn>) => ReturnType<Fn>;

@@ -100,4 +101,4 @@ close(): void;

*/
declare const setupServer: (...handlers: Array<RequestHandler>) => SetupServerApi;
declare const setupServer: (...handlers: Array<RequestHandler | WebSocketHandler>) => SetupServerApi;
export { type SetupServer, SetupServerApi, setupServer };

@@ -41,2 +41,4 @@ "use strict";

var import_devUtils = require("../core/utils/internal/devUtils.js");
var import_handleWebSocketEvent = require("../core/utils/handleWebSocketEvent.js");
var import_webSocketInterceptor = require("../core/ws/webSocketInterceptor.js");
var DEFAULT_LISTEN_OPTIONS = {

@@ -87,2 +89,5 @@ onUnhandledRequest: "warn"

);
(0, import_handleWebSocketEvent.handleWebSocketEvent)(() => {
return this.handlersController.currentHandlers();
});
}

@@ -95,4 +100,6 @@ listen(options = {}) {

this.interceptor.apply();
import_webSocketInterceptor.webSocketInterceptor.apply();
this.subscriptions.push(() => {
this.interceptor.dispose();
import_webSocketInterceptor.webSocketInterceptor.dispose();
});

@@ -99,0 +106,0 @@ (0, import_outvariant.invariant)(

{
"name": "msw",
"version": "2.2.3",
"version": "2.3.0-ws.rc-1",
"description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",

@@ -58,2 +58,22 @@ "main": "./lib/core/index.js",

},
"scripts": {
"start": "tsup --watch",
"clean": "rimraf ./lib",
"lint": "eslint \"{cli,config,src,test}/**/*.ts\"",
"build": "pnpm clean && cross-env NODE_ENV=production tsup && pnpm patch:dts",
"patch:dts": "node \"./config/scripts/patch-ts.js\"",
"check:exports": "node \"./config/scripts/validate-esm.js\"",
"test": "pnpm test:unit && pnpm test:node && pnpm test:browser && pnpm test:native",
"test:unit": "vitest",
"test:node": "vitest run --config=./test/node/vitest.config.ts",
"test:native": "vitest --config=./test/native/vitest.config.ts",
"test:browser": "playwright test -c ./test/browser/playwright.config.ts",
"test:modules:node": "vitest run --config=./test/modules/node/vitest.config.ts",
"test:modules:browser": "playwright test -c ./test/modules/browser/playwright.config.ts",
"test:ts": "ts-node test/typings/run.ts",
"prepare": "pnpm simple-git-hooks init",
"prepack": "pnpm build",
"release": "release publish",
"postinstall": "node -e \"try{require('./config/scripts/postinstall')}catch(e){}\""
},
"lint-staged": {

@@ -112,3 +132,3 @@ "**/*.ts": [

"@mswjs/cookies": "^1.1.0",
"@mswjs/interceptors": "^0.25.16",
"@mswjs/interceptors": "^0.26.8",
"@open-draft/until": "^2.1.0",

@@ -130,2 +150,3 @@ "@types/cookie": "^0.6.0",

"@commitlint/config-conventional": "^18.4.4",
"@fastify/websocket": "^8.3.1",
"@open-draft/test-server": "^0.4.2",

@@ -140,2 +161,3 @@ "@ossjs/release": "^0.8.0",

"@types/node": "18.x",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^5.11.0",

@@ -156,2 +178,3 @@ "@typescript-eslint/parser": "^5.11.0",

"express": "^4.18.2",
"fastify": "^4.26.0",
"fs-extra": "^11.2.0",

@@ -173,3 +196,3 @@ "fs-teardown": "^0.3.0",

"url-loader": "^4.1.1",
"vitest": "^0.34.6",
"vitest": "^1.2.2",
"vitest-environment-miniflare": "^2.14.1",

@@ -196,21 +219,3 @@ "webpack": "^5.89.0",

"commit-msg": "pnpm commitlint --edit $1"
},
"scripts": {
"start": "tsup --watch",
"clean": "rimraf ./lib",
"lint": "eslint \"{cli,config,src,test}/**/*.ts\"",
"build": "pnpm clean && cross-env NODE_ENV=production tsup && pnpm patch:dts",
"patch:dts": "node \"./config/scripts/patch-ts.js\"",
"check:exports": "node \"./config/scripts/validate-esm.js\"",
"test": "pnpm test:unit && pnpm test:node && pnpm test:browser && pnpm test:native",
"test:unit": "vitest",
"test:node": "vitest run --config=./test/node/vitest.config.ts",
"test:native": "vitest --config=./test/native/vitest.config.ts",
"test:browser": "playwright test -c ./test/browser/playwright.config.ts",
"test:modules:node": "vitest --config=./test/modules/node/vitest.config.ts",
"test:modules:browser": "playwright test -c ./test/modules/browser/playwright.config.ts",
"test:ts": "ts-node test/typings/run.ts",
"release": "release publish",
"postinstall": "node -e \"try{require('./config/scripts/postinstall')}catch(e){}\""
}
}
}

@@ -8,9 +8,7 @@ import { Emitter } from 'strict-event-emitter'

import { ServiceWorkerMessage } from './start/utils/createMessageChannel'
import {
RequestHandler,
RequestHandlerDefaultInfo,
} from '~/core/handlers/RequestHandler'
import { RequestHandler } from '~/core/handlers/RequestHandler'
import type { HttpRequestEventMap, Interceptor } from '@mswjs/interceptors'
import { Path } from '~/core/utils/matching/matchRequestUrl'
import { RequiredDeep } from '~/core/typeUtils'
import type { Path } from '~/core/utils/matching/matchRequestUrl'
import type { RequiredDeep } from '~/core/typeUtils'
import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'

@@ -88,3 +86,3 @@ export type ResolvedPath = Path | URL

registration: ServiceWorkerRegistration | null
getRequestHandlers(): Array<RequestHandler>
getRequestHandlers(): Array<RequestHandler | WebSocketHandler>
requests: Map<string, Request>

@@ -213,3 +211,3 @@ emitter: Emitter<LifeCycleEventsMap>

*/
use: (...handlers: RequestHandler[]) => void
use: (...handlers: Array<RequestHandler | WebSocketHandler>) => void

@@ -229,3 +227,5 @@ /**

*/
resetHandlers: (...nextHandlers: RequestHandler[]) => void
resetHandlers: (
...nextHandlers: Array<RequestHandler | WebSocketHandler>
) => void

@@ -237,3 +237,3 @@ /**

*/
listHandlers(): ReadonlyArray<RequestHandler<RequestHandlerDefaultInfo, any>>
listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>

@@ -240,0 +240,0 @@ /**

@@ -21,5 +21,8 @@ import { invariant } from 'outvariant'

import { mergeRight } from '~/core/utils/internal/mergeRight'
import { LifeCycleEventsMap } from '~/core/sharedOptions'
import type { LifeCycleEventsMap } from '~/core/sharedOptions'
import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'
import { SetupWorker } from './glossary'
import { supportsReadableStreamTransfer } from '../utils/supportsReadableStreamTransfer'
import { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'
import { handleWebSocketEvent } from '~/core/utils/handleWebSocketEvent'

@@ -41,3 +44,3 @@ interface Listener {

constructor(...handlers: Array<RequestHandler>) {
constructor(...handlers: Array<RequestHandler | WebSocketHandler>) {
super(...handlers)

@@ -181,2 +184,11 @@

handleWebSocketEvent(() => {
return this.handlersController.currentHandlers()
})
webSocketInterceptor.apply()
this.subscriptions.push(() => {
webSocketInterceptor.dispose()
})
return await this.startHandler(this.context.startOptions, options)

@@ -199,4 +211,6 @@ }

*/
export function setupWorker(...handlers: Array<RequestHandler>): SetupWorker {
export function setupWorker(
...handlers: Array<RequestHandler | WebSocketHandler>
): SetupWorker {
return new SetupWorkerApi(...handlers)
}

@@ -12,2 +12,5 @@ import { checkGlobals } from './utils/internal/checkGlobals'

/* WebSocket */
export { ws } from './ws/ws'
/* Utils */

@@ -14,0 +17,0 @@ export { matchRequestUrl } from './utils/matching/matchRequestUrl'

import { invariant } from 'outvariant'
import { EventMap, Emitter } from 'strict-event-emitter'
import {
RequestHandler,
RequestHandlerDefaultInfo,
} from './handlers/RequestHandler'
import { RequestHandler } from './handlers/RequestHandler'
import { LifeCycleEventEmitter } from './sharedOptions'

@@ -12,21 +9,28 @@ import { devUtils } from './utils/internal/devUtils'

import { Disposable } from './utils/internal/Disposable'
import type { WebSocketHandler } from './handlers/WebSocketHandler'
export abstract class HandlersController {
abstract prepend(runtimeHandlers: Array<RequestHandler>): void
abstract reset(nextHandles: Array<RequestHandler>): void
abstract currentHandlers(): Array<RequestHandler>
abstract prepend(
runtimeHandlers: Array<RequestHandler | WebSocketHandler>,
): void
abstract reset(nextHandles: Array<RequestHandler | WebSocketHandler>): void
abstract currentHandlers(): Array<RequestHandler | WebSocketHandler>
}
export class InMemoryHandlersController implements HandlersController {
private handlers: Array<RequestHandler>
private handlers: Array<RequestHandler | WebSocketHandler>
constructor(private initialHandlers: Array<RequestHandler>) {
constructor(
private initialHandlers: Array<RequestHandler | WebSocketHandler>,
) {
this.handlers = [...initialHandlers]
}
public prepend(runtimeHandles: Array<RequestHandler>): void {
public prepend(
runtimeHandles: Array<RequestHandler | WebSocketHandler>,
): void {
this.handlers.unshift(...runtimeHandles)
}
public reset(nextHandlers: Array<RequestHandler>): void {
public reset(nextHandlers: Array<RequestHandler | WebSocketHandler>): void {
this.handlers =

@@ -36,3 +40,3 @@ nextHandlers.length > 0 ? [...nextHandlers] : [...this.initialHandlers]

public currentHandlers(): Array<RequestHandler> {
public currentHandlers(): Array<RequestHandler | WebSocketHandler> {
return this.handlers

@@ -52,3 +56,3 @@ }

constructor(...initialHandlers: Array<RequestHandler>) {
constructor(...initialHandlers: Array<RequestHandler | WebSocketHandler>) {
super()

@@ -77,3 +81,3 @@

private validateHandlers(handlers: ReadonlyArray<RequestHandler>): boolean {
private validateHandlers(handlers: ReadonlyArray<unknown>): boolean {
// Guard against incorrect call signature of the setup API.

@@ -83,3 +87,5 @@ return handlers.every((handler) => !Array.isArray(handler))

public use(...runtimeHandlers: Array<RequestHandler>): void {
public use(
...runtimeHandlers: Array<RequestHandler | WebSocketHandler>
): void {
invariant(

@@ -97,13 +103,15 @@ this.validateHandlers(runtimeHandlers),

this.handlersController.currentHandlers().forEach((handler) => {
handler.isUsed = false
if ('isUsed' in handler) {
handler.isUsed = false
}
})
}
public resetHandlers(...nextHandlers: Array<RequestHandler>): void {
public resetHandlers(
...nextHandlers: Array<RequestHandler | WebSocketHandler>
): void {
this.handlersController.reset(nextHandlers)
}
public listHandlers(): ReadonlyArray<
RequestHandler<RequestHandlerDefaultInfo, any, any>
> {
public listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler> {
return toReadonlyArray(this.handlersController.currentHandlers())

@@ -110,0 +118,0 @@ }

import {
RequestHandler,
RequestHandlerExecutionResult,
type RequestHandlerExecutionResult,
} from '../handlers/RequestHandler'

@@ -21,3 +21,3 @@

*/
export const executeHandlers = async <Handlers extends Array<RequestHandler>>({
export const executeHandlers = async <Handlers extends Array<unknown>>({
request,

@@ -37,2 +37,6 @@ requestId,

for (const handler of handlers) {
if (!(handler instanceof RequestHandler)) {
continue
}
result = await handler.run({ request, requestId, resolutionContext })

@@ -39,0 +43,0 @@

import { until } from '@open-draft/until'
import { Emitter } from 'strict-event-emitter'
import { RequestHandler } from '../handlers/RequestHandler'
import { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'

@@ -48,3 +47,3 @@ import { RequiredDeep } from '../typeUtils'

requestId: string,
handlers: Array<RequestHandler>,
handlers: Array<unknown>,
options: RequiredDeep<SharedOptions>,

@@ -51,0 +50,0 @@ emitter: Emitter<LifeCycleEventsMap>,

@@ -64,2 +64,46 @@ /**

})
test('returns true for matching WebSocket URL', () => {
expect(
matchRequestUrl(new URL('ws://test.mswjs.io'), 'ws://test.mswjs.io'),
).toEqual({
matches: true,
params: {},
})
expect(
matchRequestUrl(new URL('wss://test.mswjs.io'), 'wss://test.mswjs.io'),
).toEqual({
matches: true,
params: {},
})
})
test('returns false for non-matching WebSocket URL', () => {
expect(
matchRequestUrl(new URL('ws://test.mswjs.io'), 'ws://foo.mswjs.io'),
).toEqual({
matches: false,
params: {},
})
expect(
matchRequestUrl(new URL('wss://test.mswjs.io'), 'wss://completely.diff'),
).toEqual({
matches: false,
params: {},
})
})
test('returns path parameters when matched a WebSocket URL', () => {
expect(
matchRequestUrl(
new URL('wss://test.mswjs.io'),
'wss://:service.mswjs.io',
),
).toEqual({
matches: true,
params: {
service: 'test',
},
})
})
})

@@ -66,0 +110,0 @@

@@ -74,1 +74,5 @@ import { match } from 'path-to-regexp'

}
export function isPath(value: unknown): value is Path {
return typeof value === 'string' || value instanceof RegExp
}
import type { PartialDeep } from 'type-fest'
import type { RequestHandler } from '~/core/handlers/RequestHandler'
import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'
import type {
RequestHandler,
RequestHandlerDefaultInfo,
} from '~/core/handlers/RequestHandler'
import type {
LifeCycleEventEmitter,

@@ -32,3 +30,3 @@ LifeCycleEventsMap,

*/
use(...handlers: Array<RequestHandler>): void
use(...handlers: Array<RequestHandler | WebSocketHandler>): void

@@ -47,3 +45,3 @@ /**

*/
resetHandlers(...nextHandlers: Array<RequestHandler>): void
resetHandlers(...nextHandlers: Array<RequestHandler | WebSocketHandler>): void

@@ -55,3 +53,3 @@ /**

*/
listHandlers(): ReadonlyArray<RequestHandler<RequestHandlerDefaultInfo, any>>
listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>

@@ -58,0 +56,0 @@ /**

import type { RequestHandler } from '~/core/handlers/RequestHandler'
import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'
import { SetupServerApi } from './SetupServerApi'

@@ -11,5 +12,5 @@

export const setupServer = (
...handlers: Array<RequestHandler>
...handlers: Array<RequestHandler | WebSocketHandler>
): SetupServerApi => {
return new SetupServerApi(handlers)
}

@@ -7,2 +7,3 @@ import { AsyncLocalStorage } from 'node:async_hooks'

import type { RequestHandler } from '~/core/handlers/RequestHandler'
import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'
import type { SetupServer } from './glossary'

@@ -14,4 +15,4 @@ import { SetupServerCommonApi } from './SetupServerCommonApi'

type RequestHandlersContext = {
initialHandlers: Array<RequestHandler>
handlers: Array<RequestHandler>
initialHandlers: Array<RequestHandler | WebSocketHandler>
handlers: Array<RequestHandler | WebSocketHandler>
}

@@ -27,3 +28,3 @@

constructor(initialHandlers: Array<RequestHandler>) {
constructor(initialHandlers: Array<RequestHandler | WebSocketHandler>) {
this.rootContext = { initialHandlers, handlers: [] }

@@ -36,7 +37,7 @@ }

public prepend(runtimeHandlers: Array<RequestHandler>) {
public prepend(runtimeHandlers: Array<RequestHandler | WebSocketHandler>) {
this.context.handlers.unshift(...runtimeHandlers)
}
public reset(nextHandlers: Array<RequestHandler>) {
public reset(nextHandlers: Array<RequestHandler | WebSocketHandler>) {
const context = this.context

@@ -48,3 +49,3 @@ context.handlers = []

public currentHandlers(): Array<RequestHandler> {
public currentHandlers(): Array<RequestHandler | WebSocketHandler> {
const { initialHandlers, handlers } = this.context

@@ -59,3 +60,3 @@ return handlers.concat(initialHandlers)

{
constructor(handlers: Array<RequestHandler>) {
constructor(handlers: Array<RequestHandler | WebSocketHandler>) {
super(

@@ -62,0 +63,0 @@ [ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor],

@@ -17,5 +17,8 @@ /**

import type { RequestHandler } from '~/core/handlers/RequestHandler'
import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'
import { mergeRight } from '~/core/utils/internal/mergeRight'
import { devUtils } from '~/core/utils/internal/devUtils'
import type { SetupServerCommon } from './glossary'
import { handleWebSocketEvent } from '~/core/utils/handleWebSocketEvent'
import { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'

@@ -38,3 +41,3 @@ export const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {

interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,
handlers: Array<RequestHandler>,
handlers: Array<RequestHandler | WebSocketHandler>,
) {

@@ -86,2 +89,6 @@ super(...handlers)

)
handleWebSocketEvent(() => {
return this.handlersController.currentHandlers()
})
}

@@ -97,5 +104,7 @@

this.interceptor.apply()
webSocketInterceptor.apply()
this.subscriptions.push(() => {
this.interceptor.dispose()
webSocketInterceptor.dispose()
})

@@ -102,0 +111,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc