msw 2.13.4 → 2.13.5
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.map +1 -1
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{HttpResponse-BF4NGRsf.d.mts → HttpResponse-BMMzfpjG.d.mts} +14 -1
- package/lib/core/{HttpResponse-yukpQS4a.d.ts → HttpResponse-DPDqE4Pb.d.ts} +14 -1
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/experimental/compat.d.mts +1 -1
- package/lib/core/experimental/compat.d.ts +1 -1
- package/lib/core/experimental/define-network.d.mts +1 -1
- package/lib/core/experimental/define-network.d.ts +1 -1
- package/lib/core/experimental/define-network.js +1 -5
- package/lib/core/experimental/define-network.js.map +1 -1
- package/lib/core/experimental/define-network.mjs +1 -5
- package/lib/core/experimental/define-network.mjs.map +1 -1
- package/lib/core/experimental/frames/http-frame.d.mts +1 -1
- package/lib/core/experimental/frames/http-frame.d.ts +1 -1
- package/lib/core/experimental/frames/network-frame.d.mts +1 -1
- package/lib/core/experimental/frames/network-frame.d.ts +1 -1
- package/lib/core/experimental/frames/websocket-frame.d.mts +1 -1
- package/lib/core/experimental/frames/websocket-frame.d.ts +1 -1
- package/lib/core/experimental/handlers-controller.d.mts +2 -1
- package/lib/core/experimental/handlers-controller.d.ts +2 -1
- package/lib/core/experimental/handlers-controller.js +12 -0
- package/lib/core/experimental/handlers-controller.js.map +1 -1
- package/lib/core/experimental/handlers-controller.mjs +12 -0
- package/lib/core/experimental/handlers-controller.mjs.map +1 -1
- package/lib/core/experimental/index.d.mts +1 -1
- package/lib/core/experimental/index.d.ts +1 -1
- package/lib/core/experimental/on-unhandled-frame.d.mts +1 -1
- package/lib/core/experimental/on-unhandled-frame.d.ts +1 -1
- package/lib/core/experimental/setup-api.d.mts +1 -1
- package/lib/core/experimental/setup-api.d.ts +1 -1
- package/lib/core/experimental/setup-api.js +1 -5
- package/lib/core/experimental/setup-api.js.map +1 -1
- package/lib/core/experimental/setup-api.mjs +1 -5
- package/lib/core/experimental/setup-api.mjs.map +1 -1
- package/lib/core/experimental/sources/interceptor-source.d.mts +1 -1
- package/lib/core/experimental/sources/interceptor-source.d.ts +1 -1
- package/lib/core/experimental/sources/network-source.d.mts +1 -1
- package/lib/core/experimental/sources/network-source.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 +1 -1
- package/lib/core/graphql.d.ts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.js +25 -0
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs +25 -0
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +1 -1
- package/lib/core/index.d.ts +1 -1
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/sse.d.mts +1 -1
- package/lib/core/sse.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/isHandlerKind.d.mts +1 -1
- package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
- package/lib/iife/index.js +39 -10
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -2
- package/src/browser/utils/deserializeRequest.ts +2 -1
- package/src/browser/utils/pruneGetRequestBody.ts +3 -3
- package/src/core/experimental/define-network.ts +4 -7
- package/src/core/experimental/handlers-controller.ts +14 -0
- package/src/core/experimental/setup-api.ts +1 -5
- package/src/core/handlers/RequestHandler.ts +28 -0
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +0 -12
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +0 -12
- package/lib/core/utils/internal/requestHandlerUtils.js +0 -37
- package/lib/core/utils/internal/requestHandlerUtils.js.map +0 -1
- package/lib/core/utils/internal/requestHandlerUtils.mjs +0 -17
- package/lib/core/utils/internal/requestHandlerUtils.mjs.map +0 -1
- package/src/core/utils/internal/requestHandlerUtils.ts +0 -21
|
@@ -200,6 +200,19 @@ declare abstract class RequestHandler<HandlerInfo extends RequestHandlerDefaultI
|
|
|
200
200
|
*/
|
|
201
201
|
isUsed: boolean;
|
|
202
202
|
constructor(args: RequestHandlerArgs<HandlerInfo, HandlerOptions>);
|
|
203
|
+
/**
|
|
204
|
+
* Reset the runtime state accumulated during response resolution,
|
|
205
|
+
* such as generator iterator progress. Called when this handler is
|
|
206
|
+
* removed from the active handlers list so re-adding it later starts
|
|
207
|
+
* from a clean state.
|
|
208
|
+
*/
|
|
209
|
+
protected reset(): void;
|
|
210
|
+
/**
|
|
211
|
+
* Restore this handler so it can match requests again after being
|
|
212
|
+
* exhausted (e.g. via `{ once: true }`). Also clears any accumulated
|
|
213
|
+
* resolution state.
|
|
214
|
+
*/
|
|
215
|
+
protected restore(): void;
|
|
203
216
|
/**
|
|
204
217
|
* Determine if the intercepted request should be mocked.
|
|
205
218
|
*/
|
|
@@ -335,4 +348,4 @@ declare class HttpResponse<BodyType extends DefaultBodyType> extends FetchRespon
|
|
|
335
348
|
static formData(body?: FormData, init?: HttpResponseInit): HttpResponse<FormData>;
|
|
336
349
|
}
|
|
337
350
|
|
|
338
|
-
export { type AsyncResponseResolverReturnType as A, type GraphQLHandlerNameSelector as B, type GraphQLHandlerInfo as C, type DefaultBodyType as D, type GraphQLRequestParsedResult as E, type GraphQLCustomPredicateResult as F, GraphQLHandler as G, HttpResponse as H, isDocumentNode as I, type JsonBodyType as J, type RequestHandlerInternalInfo as K, type RequestHandlerArgs as L, type MaybeAsyncResponseResolverReturnType as M, type RequestHandlerExecutionResult as N, bodyType as O, type ParsedGraphQLRequest as P, type DefaultUnsafeFetchResponse as Q, RequestHandler as R, type StrictRequest as S, kDefaultContentType as T, type ResponseResolver as a, type ResponseResolverReturnType as b, type RequestHandlerOptions as c, type DefaultRequestMultipartBody as d, type ResponseResolverInfo as e, type GraphQLQuery as f, type GraphQLVariables as g, type GraphQLRequestBody as h, type GraphQLResponseBody as i, type GraphQLJsonRequestBody as j, type GraphQLOperationType as k, type GraphQLCustomPredicate as l, type ResponseResolutionContext as m, type HttpResponseInit as n, type StrictResponse as o, type GraphQLPredicate as p, type GraphQLResolverExtras as q, type
|
|
351
|
+
export { type AsyncResponseResolverReturnType as A, type GraphQLHandlerNameSelector as B, type GraphQLHandlerInfo as C, type DefaultBodyType as D, type GraphQLRequestParsedResult as E, type GraphQLCustomPredicateResult as F, GraphQLHandler as G, HttpResponse as H, isDocumentNode as I, type JsonBodyType as J, type RequestHandlerInternalInfo as K, type RequestHandlerArgs as L, type MaybeAsyncResponseResolverReturnType as M, type RequestHandlerExecutionResult as N, bodyType as O, type ParsedGraphQLRequest as P, type DefaultUnsafeFetchResponse as Q, RequestHandler as R, type StrictRequest as S, kDefaultContentType as T, type ResponseResolver as a, type ResponseResolverReturnType as b, type RequestHandlerOptions as c, type DefaultRequestMultipartBody as d, type ResponseResolverInfo as e, type GraphQLQuery as f, type GraphQLVariables as g, type GraphQLRequestBody as h, type GraphQLResponseBody as i, type GraphQLJsonRequestBody as j, type GraphQLOperationType as k, type GraphQLCustomPredicate as l, type ResponseResolutionContext as m, type HttpResponseInit as n, type StrictResponse as o, type GraphQLPredicate as p, type GraphQLResolverExtras as q, type RequestHandlerDefaultInfo as r, type HandlersExecutionResult as s, executeHandlers as t, type ParsedGraphQLQuery as u, parseDocumentNode as v, type GraphQLParsedOperationsMap as w, type GraphQLMultipartRequestBody as x, parseGraphQLRequest as y, type DocumentTypeDecoration as z };
|
|
@@ -200,6 +200,19 @@ declare abstract class RequestHandler<HandlerInfo extends RequestHandlerDefaultI
|
|
|
200
200
|
*/
|
|
201
201
|
isUsed: boolean;
|
|
202
202
|
constructor(args: RequestHandlerArgs<HandlerInfo, HandlerOptions>);
|
|
203
|
+
/**
|
|
204
|
+
* Reset the runtime state accumulated during response resolution,
|
|
205
|
+
* such as generator iterator progress. Called when this handler is
|
|
206
|
+
* removed from the active handlers list so re-adding it later starts
|
|
207
|
+
* from a clean state.
|
|
208
|
+
*/
|
|
209
|
+
protected reset(): void;
|
|
210
|
+
/**
|
|
211
|
+
* Restore this handler so it can match requests again after being
|
|
212
|
+
* exhausted (e.g. via `{ once: true }`). Also clears any accumulated
|
|
213
|
+
* resolution state.
|
|
214
|
+
*/
|
|
215
|
+
protected restore(): void;
|
|
203
216
|
/**
|
|
204
217
|
* Determine if the intercepted request should be mocked.
|
|
205
218
|
*/
|
|
@@ -335,4 +348,4 @@ declare class HttpResponse<BodyType extends DefaultBodyType> extends FetchRespon
|
|
|
335
348
|
static formData(body?: FormData, init?: HttpResponseInit): HttpResponse<FormData>;
|
|
336
349
|
}
|
|
337
350
|
|
|
338
|
-
export { type AsyncResponseResolverReturnType as A, type GraphQLHandlerNameSelector as B, type GraphQLHandlerInfo as C, type DefaultBodyType as D, type GraphQLRequestParsedResult as E, type GraphQLCustomPredicateResult as F, GraphQLHandler as G, HttpResponse as H, isDocumentNode as I, type JsonBodyType as J, type RequestHandlerInternalInfo as K, type RequestHandlerArgs as L, type MaybeAsyncResponseResolverReturnType as M, type RequestHandlerExecutionResult as N, bodyType as O, type ParsedGraphQLRequest as P, type DefaultUnsafeFetchResponse as Q, RequestHandler as R, type StrictRequest as S, kDefaultContentType as T, type ResponseResolver as a, type ResponseResolverReturnType as b, type RequestHandlerOptions as c, type DefaultRequestMultipartBody as d, type ResponseResolverInfo as e, type GraphQLQuery as f, type GraphQLVariables as g, type GraphQLRequestBody as h, type GraphQLResponseBody as i, type GraphQLJsonRequestBody as j, type GraphQLOperationType as k, type GraphQLCustomPredicate as l, type ResponseResolutionContext as m, type HttpResponseInit as n, type StrictResponse as o, type GraphQLPredicate as p, type GraphQLResolverExtras as q, type
|
|
351
|
+
export { type AsyncResponseResolverReturnType as A, type GraphQLHandlerNameSelector as B, type GraphQLHandlerInfo as C, type DefaultBodyType as D, type GraphQLRequestParsedResult as E, type GraphQLCustomPredicateResult as F, GraphQLHandler as G, HttpResponse as H, isDocumentNode as I, type JsonBodyType as J, type RequestHandlerInternalInfo as K, type RequestHandlerArgs as L, type MaybeAsyncResponseResolverReturnType as M, type RequestHandlerExecutionResult as N, bodyType as O, type ParsedGraphQLRequest as P, type DefaultUnsafeFetchResponse as Q, RequestHandler as R, type StrictRequest as S, kDefaultContentType as T, type ResponseResolver as a, type ResponseResolverReturnType as b, type RequestHandlerOptions as c, type DefaultRequestMultipartBody as d, type ResponseResolverInfo as e, type GraphQLQuery as f, type GraphQLVariables as g, type GraphQLRequestBody as h, type GraphQLResponseBody as i, type GraphQLJsonRequestBody as j, type GraphQLOperationType as k, type GraphQLCustomPredicate as l, type ResponseResolutionContext as m, type HttpResponseInit as n, type StrictResponse as o, type GraphQLPredicate as p, type GraphQLResolverExtras as q, type RequestHandlerDefaultInfo as r, type HandlersExecutionResult as s, executeHandlers as t, type ParsedGraphQLQuery as u, parseDocumentNode as v, type GraphQLParsedOperationsMap as w, type GraphQLMultipartRequestBody as x, parseGraphQLRequest as y, type DocumentTypeDecoration as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@mswjs/interceptors';
|
|
2
|
-
export { Q as DefaultUnsafeFetchResponse, H as HttpResponse, n as HttpResponseInit, S as StrictRequest, o as StrictResponse, O as bodyType, T as kDefaultContentType } from './HttpResponse-
|
|
2
|
+
export { Q as DefaultUnsafeFetchResponse, H as HttpResponse, n as HttpResponseInit, S as StrictRequest, o as StrictResponse, O as bodyType, T as kDefaultContentType } from './HttpResponse-BMMzfpjG.mjs';
|
|
3
3
|
import './typeUtils.mjs';
|
|
4
4
|
import './utils/internal/isIterable.mjs';
|
|
5
5
|
import 'graphql';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@mswjs/interceptors';
|
|
2
|
-
export { Q as DefaultUnsafeFetchResponse, H as HttpResponse, n as HttpResponseInit, S as StrictRequest, o as StrictResponse, O as bodyType, T as kDefaultContentType } from './HttpResponse-
|
|
2
|
+
export { Q as DefaultUnsafeFetchResponse, H as HttpResponse, n as HttpResponseInit, S as StrictRequest, o as StrictResponse, O as bodyType, T as kDefaultContentType } from './HttpResponse-DPDqE4Pb.js';
|
|
3
3
|
import './typeUtils.js';
|
|
4
4
|
import './utils/internal/isIterable.js';
|
|
5
5
|
import 'graphql';
|
|
@@ -2,7 +2,7 @@ import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.mj
|
|
|
2
2
|
import { U as UnhandledFrameCallback } from '../on-unhandled-frame-Cr1KOZ0I.mjs';
|
|
3
3
|
import 'rettime';
|
|
4
4
|
import './handlers-controller.mjs';
|
|
5
|
-
import '../HttpResponse-
|
|
5
|
+
import '../HttpResponse-BMMzfpjG.mjs';
|
|
6
6
|
import '@mswjs/interceptors';
|
|
7
7
|
import '../utils/internal/isIterable.mjs';
|
|
8
8
|
import '../typeUtils.mjs';
|
|
@@ -2,7 +2,7 @@ import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.js
|
|
|
2
2
|
import { U as UnhandledFrameCallback } from '../on-unhandled-frame-BBR-P3kV.js';
|
|
3
3
|
import 'rettime';
|
|
4
4
|
import './handlers-controller.js';
|
|
5
|
-
import '../HttpResponse-
|
|
5
|
+
import '../HttpResponse-DPDqE4Pb.js';
|
|
6
6
|
import '@mswjs/interceptors';
|
|
7
7
|
import '../utils/internal/isIterable.js';
|
|
8
8
|
import '../typeUtils.js';
|
|
@@ -2,7 +2,7 @@ import { Emitter, DefaultEventMap } from 'rettime';
|
|
|
2
2
|
import { NetworkSource, ExtractSourceEvents } from './sources/network-source.mjs';
|
|
3
3
|
import { a as NetworkFrameResolutionContext, b as UnhandledFrameHandle } from '../on-unhandled-frame-Cr1KOZ0I.mjs';
|
|
4
4
|
import { AnyHandler, HandlersController } from './handlers-controller.mjs';
|
|
5
|
-
import '../HttpResponse-
|
|
5
|
+
import '../HttpResponse-BMMzfpjG.mjs';
|
|
6
6
|
import '@mswjs/interceptors';
|
|
7
7
|
import '../utils/internal/isIterable.mjs';
|
|
8
8
|
import '../typeUtils.mjs';
|
|
@@ -2,7 +2,7 @@ import { Emitter, DefaultEventMap } from 'rettime';
|
|
|
2
2
|
import { NetworkSource, ExtractSourceEvents } from './sources/network-source.js';
|
|
3
3
|
import { a as NetworkFrameResolutionContext, b as UnhandledFrameHandle } from '../on-unhandled-frame-BBR-P3kV.js';
|
|
4
4
|
import { AnyHandler, HandlersController } from './handlers-controller.js';
|
|
5
|
-
import '../HttpResponse-
|
|
5
|
+
import '../HttpResponse-DPDqE4Pb.js';
|
|
6
6
|
import '@mswjs/interceptors';
|
|
7
7
|
import '../utils/internal/isIterable.js';
|
|
8
8
|
import '../typeUtils.js';
|
|
@@ -114,11 +114,7 @@ function defineNetwork(options) {
|
|
|
114
114
|
handlersController.reset(handlers);
|
|
115
115
|
},
|
|
116
116
|
restoreHandlers() {
|
|
117
|
-
|
|
118
|
-
if ("isUsed" in handler) {
|
|
119
|
-
handler.isUsed = false;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
117
|
+
handlersController.restore();
|
|
122
118
|
},
|
|
123
119
|
listHandlers() {
|
|
124
120
|
return (0, import_toReadonlyArray.toReadonlyArray)(handlersController.currentHandlers());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/experimental/define-network.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { Emitter, type DefaultEventMap } from 'rettime'\nimport {\n NetworkSource,\n type ExtractSourceEvents,\n} from './sources/network-source'\nimport { type NetworkFrameResolutionContext } from './frames/network-frame'\nimport { type UnhandledFrameHandle } from './on-unhandled-frame'\nimport {\n HandlersController,\n InMemoryHandlersController,\n type AnyHandler,\n} from './handlers-controller'\nimport { toReadonlyArray } from '../utils/internal/toReadonlyArray'\n\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (\n k: infer I,\n) => void\n ? I\n : never\n\ntype MergeEventMaps<Sources extends Array<NetworkSource<any>>> =\n UnionToIntersection<ExtractSourceEvents<Sources[number]>> extends infer R\n ? R extends Record<string, any>\n ? R\n : DefaultEventMap\n : DefaultEventMap\n\ntype MaybePromise<T> =\n Extract<T, Promise<unknown>> extends never ? void : Promise<void>\n\nexport interface DefineNetworkOptions<\n Sources extends Array<NetworkSource<any>>,\n> {\n /**\n * List of the network sources.\n * Every network source emits frames, and every frame describes how\n * to handle the various network scenarios, like mocking a response,\n * erroring the request, or performing it as-is.\n */\n sources: Sources\n /**\n * List of handlers to describe the network.\n */\n handlers?: Array<AnyHandler> | HandlersController\n context?: NetworkFrameResolutionContext\n onUnhandledFrame?: UnhandledFrameHandle\n}\n\nexport interface NetworkApi
|
|
1
|
+
{"version":3,"sources":["../../../src/core/experimental/define-network.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { Emitter, type DefaultEventMap } from 'rettime'\nimport {\n NetworkSource,\n type ExtractSourceEvents,\n} from './sources/network-source'\nimport { type NetworkFrameResolutionContext } from './frames/network-frame'\nimport { type UnhandledFrameHandle } from './on-unhandled-frame'\nimport {\n HandlersController,\n InMemoryHandlersController,\n type AnyHandler,\n} from './handlers-controller'\nimport { toReadonlyArray } from '../utils/internal/toReadonlyArray'\n\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (\n k: infer I,\n) => void\n ? I\n : never\n\ntype MergeEventMaps<Sources extends Array<NetworkSource<any>>> =\n UnionToIntersection<ExtractSourceEvents<Sources[number]>> extends infer R\n ? R extends Record<string, any>\n ? R\n : DefaultEventMap\n : DefaultEventMap\n\ntype MaybePromise<T> =\n Extract<T, Promise<unknown>> extends never ? void : Promise<void>\n\nexport interface DefineNetworkOptions<\n Sources extends Array<NetworkSource<any>>,\n> {\n /**\n * List of the network sources.\n * Every network source emits frames, and every frame describes how\n * to handle the various network scenarios, like mocking a response,\n * erroring the request, or performing it as-is.\n */\n sources: Sources\n /**\n * List of handlers to describe the network.\n */\n handlers?: Array<AnyHandler> | HandlersController\n context?: NetworkFrameResolutionContext\n onUnhandledFrame?: UnhandledFrameHandle\n}\n\nexport interface NetworkApi<\n Sources extends Array<NetworkSource<any>>,\n> extends NetworkHandlersApi {\n readyState: NetworkReadyState\n /**\n * Enable the network interception and handling.\n */\n enable: () => MaybePromise<ReturnType<Sources[number]['enable']>>\n /**\n * Disable the network interception and handling.\n */\n disable: () => MaybePromise<ReturnType<Sources[number]['disable']>>\n /**\n * Configure the network instance with additional options.\n * The options provided in the `.configure()` call will override the same\n * options in the `defineNetwork()` call.\n */\n configure: (options: Partial<DefineNetworkOptions<Sources>>) => void\n events: Emitter<MergeEventMaps<Sources>>\n}\n\nexport interface NetworkHandlersApi {\n use: (...handlers: Array<AnyHandler>) => void\n resetHandlers: (...handlers: Array<AnyHandler>) => void\n restoreHandlers: () => void\n listHandlers: () => ReadonlyArray<AnyHandler>\n}\n\nfunction colorlessPromiseAll<T>(values: Array<T>): MaybePromise<T>\nfunction colorlessPromiseAll(values: Array<unknown>): Promise<void> | void {\n const promises: Array<Promise<void>> = []\n\n for (const value of values) {\n if (value instanceof Promise) {\n promises.push(value)\n }\n }\n\n if (promises.length > 0) {\n return Promise.all(promises).then(() => {})\n }\n}\n\nexport enum NetworkReadyState {\n DISABLED,\n ENABLED,\n}\n\n/**\n * Define a network instance with the given configuration.\n * @example\n * import { InterceptorSource } from 'msw/experimental'\n * import { handlers } from './handlers'\n *\n * const network = defineNetwork({\n * sources: [new InterceptorSource({ interceptors })],\n * handlers,\n * })\n * await network.enable()\n */\nexport function defineNetwork<Sources extends Array<NetworkSource<any>>>(\n options: DefineNetworkOptions<Sources>,\n): NetworkApi<Sources> {\n let readyState: NetworkReadyState = NetworkReadyState.DISABLED\n const events = new Emitter<MergeEventMaps<Sources>>()\n\n const deriveHandlersController = (\n handlers: DefineNetworkOptions<Sources>['handlers'],\n ) => {\n return handlers instanceof HandlersController\n ? handlers\n : new InMemoryHandlersController(handlers || [])\n }\n\n let resolvedOptions: DefineNetworkOptions<Sources> = {\n ...options,\n }\n\n /**\n * @note Create the handlers controller immediately because\n * certain setup APIs, like `setupServer`, don't await `.enable` (`.listen`).\n */\n let handlersController = deriveHandlersController(resolvedOptions.handlers)\n let listenersController: AbortController\n\n return {\n get readyState() {\n return readyState\n },\n events,\n configure(options) {\n invariant(readyState === NetworkReadyState.DISABLED, '')\n\n if (\n options.handlers &&\n !Object.is(options.handlers, resolvedOptions.handlers)\n ) {\n handlersController = deriveHandlersController(options.handlers)\n }\n\n resolvedOptions = {\n ...resolvedOptions,\n ...options,\n }\n },\n enable() {\n invariant(\n readyState === NetworkReadyState.DISABLED,\n 'Failed to call \"enable\" on the network: already enabled',\n )\n\n listenersController = new AbortController()\n readyState = NetworkReadyState.ENABLED\n\n const result = resolvedOptions.sources.map((source) => {\n /**\n * @note Preemptively disable the network source before enabling.\n * This intentionally calls only the prototype method that clears the\n * event listeners and nothing else. This prevents the \"frame\" listeners\n * from accumulating across enable/disable in case the source is a singleton.\n */\n NetworkSource.prototype.disable.call(source)\n\n source.on('frame', async ({ frame }) => {\n frame.events.on('*', (event) => events.emit(event), {\n signal: listenersController.signal,\n })\n\n const handlers = frame.getHandlers(handlersController)\n\n await frame.resolve(\n handlers,\n resolvedOptions.onUnhandledFrame || 'warn',\n resolvedOptions.context,\n )\n })\n\n return source.enable()\n })\n\n return colorlessPromiseAll(result) as MaybePromise<\n ReturnType<Sources[number]['enable']>\n >\n },\n disable() {\n invariant(\n readyState === NetworkReadyState.ENABLED,\n 'Failed to call \"disable\" on the network: already disabled',\n )\n\n listenersController.abort()\n readyState = NetworkReadyState.DISABLED\n\n return colorlessPromiseAll(\n resolvedOptions.sources.map((source) => source.disable()),\n ) as MaybePromise<ReturnType<Sources[number]['disable']>>\n },\n use(...handlers) {\n handlersController.use(handlers)\n },\n resetHandlers(...handlers) {\n handlersController.reset(handlers)\n },\n restoreHandlers() {\n handlersController.restore()\n },\n listHandlers() {\n return toReadonlyArray(handlersController.currentHandlers())\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA0B;AAC1B,qBAA8C;AAC9C,4BAGO;AACP,2BAAmD;AACnD,gCAA0C;AAC1C,iCAIO;AACP,6BAAgC;AAiEhC,SAAS,oBAAoB,QAA8C;AACzE,QAAM,WAAiC,CAAC;AAExC,aAAW,SAAS,QAAQ;AAC1B,QAAI,iBAAiB,SAAS;AAC5B,eAAS,KAAK,KAAK;AAAA,IACrB;AAAA,EACF;AAEA,MAAI,SAAS,SAAS,GAAG;AACvB,WAAO,QAAQ,IAAI,QAAQ,EAAE,KAAK,MAAM;AAAA,IAAC,CAAC;AAAA,EAC5C;AACF;AAEO,IAAK,oBAAL,kBAAKA,uBAAL;AACL,EAAAA,sCAAA;AACA,EAAAA,sCAAA;AAFU,SAAAA;AAAA,GAAA;AAiBL,SAAS,cACd,SACqB;AACrB,MAAI,aAAgC;AACp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AAM;AAC1B,mBAAa;AAEb,aAAO;AAAA,QACL,gBAAgB,QAAQ,IAAI,CAAC,WAAW,OAAO,QAAQ,CAAC;AAAA,MAC1D;AAAA,IACF;AAAA,IACA,OAAO,UAAU;AACf,yBAAmB,IAAI,QAAQ;AAAA,IACjC;AAAA,IACA,iBAAiB,UAAU;AACzB,yBAAmB,MAAM,QAAQ;AAAA,IACnC;AAAA,IACA,kBAAkB;AAChB,yBAAmB,QAAQ;AAAA,IAC7B;AAAA,IACA,eAAe;AACb,iBAAO,wCAAgB,mBAAmB,gBAAgB,CAAC;AAAA,IAC7D;AAAA,EACF;AACF;","names":["NetworkReadyState","options"]}
|
|
@@ -95,11 +95,7 @@ function defineNetwork(options) {
|
|
|
95
95
|
handlersController.reset(handlers);
|
|
96
96
|
},
|
|
97
97
|
restoreHandlers() {
|
|
98
|
-
|
|
99
|
-
if ("isUsed" in handler) {
|
|
100
|
-
handler.isUsed = false;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
98
|
+
handlersController.restore();
|
|
103
99
|
},
|
|
104
100
|
listHandlers() {
|
|
105
101
|
return toReadonlyArray(handlersController.currentHandlers());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/experimental/define-network.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { Emitter, type DefaultEventMap } from 'rettime'\nimport {\n NetworkSource,\n type ExtractSourceEvents,\n} from './sources/network-source'\nimport { type NetworkFrameResolutionContext } from './frames/network-frame'\nimport { type UnhandledFrameHandle } from './on-unhandled-frame'\nimport {\n HandlersController,\n InMemoryHandlersController,\n type AnyHandler,\n} from './handlers-controller'\nimport { toReadonlyArray } from '../utils/internal/toReadonlyArray'\n\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (\n k: infer I,\n) => void\n ? I\n : never\n\ntype MergeEventMaps<Sources extends Array<NetworkSource<any>>> =\n UnionToIntersection<ExtractSourceEvents<Sources[number]>> extends infer R\n ? R extends Record<string, any>\n ? R\n : DefaultEventMap\n : DefaultEventMap\n\ntype MaybePromise<T> =\n Extract<T, Promise<unknown>> extends never ? void : Promise<void>\n\nexport interface DefineNetworkOptions<\n Sources extends Array<NetworkSource<any>>,\n> {\n /**\n * List of the network sources.\n * Every network source emits frames, and every frame describes how\n * to handle the various network scenarios, like mocking a response,\n * erroring the request, or performing it as-is.\n */\n sources: Sources\n /**\n * List of handlers to describe the network.\n */\n handlers?: Array<AnyHandler> | HandlersController\n context?: NetworkFrameResolutionContext\n onUnhandledFrame?: UnhandledFrameHandle\n}\n\nexport interface NetworkApi
|
|
1
|
+
{"version":3,"sources":["../../../src/core/experimental/define-network.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { Emitter, type DefaultEventMap } from 'rettime'\nimport {\n NetworkSource,\n type ExtractSourceEvents,\n} from './sources/network-source'\nimport { type NetworkFrameResolutionContext } from './frames/network-frame'\nimport { type UnhandledFrameHandle } from './on-unhandled-frame'\nimport {\n HandlersController,\n InMemoryHandlersController,\n type AnyHandler,\n} from './handlers-controller'\nimport { toReadonlyArray } from '../utils/internal/toReadonlyArray'\n\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (\n k: infer I,\n) => void\n ? I\n : never\n\ntype MergeEventMaps<Sources extends Array<NetworkSource<any>>> =\n UnionToIntersection<ExtractSourceEvents<Sources[number]>> extends infer R\n ? R extends Record<string, any>\n ? R\n : DefaultEventMap\n : DefaultEventMap\n\ntype MaybePromise<T> =\n Extract<T, Promise<unknown>> extends never ? void : Promise<void>\n\nexport interface DefineNetworkOptions<\n Sources extends Array<NetworkSource<any>>,\n> {\n /**\n * List of the network sources.\n * Every network source emits frames, and every frame describes how\n * to handle the various network scenarios, like mocking a response,\n * erroring the request, or performing it as-is.\n */\n sources: Sources\n /**\n * List of handlers to describe the network.\n */\n handlers?: Array<AnyHandler> | HandlersController\n context?: NetworkFrameResolutionContext\n onUnhandledFrame?: UnhandledFrameHandle\n}\n\nexport interface NetworkApi<\n Sources extends Array<NetworkSource<any>>,\n> extends NetworkHandlersApi {\n readyState: NetworkReadyState\n /**\n * Enable the network interception and handling.\n */\n enable: () => MaybePromise<ReturnType<Sources[number]['enable']>>\n /**\n * Disable the network interception and handling.\n */\n disable: () => MaybePromise<ReturnType<Sources[number]['disable']>>\n /**\n * Configure the network instance with additional options.\n * The options provided in the `.configure()` call will override the same\n * options in the `defineNetwork()` call.\n */\n configure: (options: Partial<DefineNetworkOptions<Sources>>) => void\n events: Emitter<MergeEventMaps<Sources>>\n}\n\nexport interface NetworkHandlersApi {\n use: (...handlers: Array<AnyHandler>) => void\n resetHandlers: (...handlers: Array<AnyHandler>) => void\n restoreHandlers: () => void\n listHandlers: () => ReadonlyArray<AnyHandler>\n}\n\nfunction colorlessPromiseAll<T>(values: Array<T>): MaybePromise<T>\nfunction colorlessPromiseAll(values: Array<unknown>): Promise<void> | void {\n const promises: Array<Promise<void>> = []\n\n for (const value of values) {\n if (value instanceof Promise) {\n promises.push(value)\n }\n }\n\n if (promises.length > 0) {\n return Promise.all(promises).then(() => {})\n }\n}\n\nexport enum NetworkReadyState {\n DISABLED,\n ENABLED,\n}\n\n/**\n * Define a network instance with the given configuration.\n * @example\n * import { InterceptorSource } from 'msw/experimental'\n * import { handlers } from './handlers'\n *\n * const network = defineNetwork({\n * sources: [new InterceptorSource({ interceptors })],\n * handlers,\n * })\n * await network.enable()\n */\nexport function defineNetwork<Sources extends Array<NetworkSource<any>>>(\n options: DefineNetworkOptions<Sources>,\n): NetworkApi<Sources> {\n let readyState: NetworkReadyState = NetworkReadyState.DISABLED\n const events = new Emitter<MergeEventMaps<Sources>>()\n\n const deriveHandlersController = (\n handlers: DefineNetworkOptions<Sources>['handlers'],\n ) => {\n return handlers instanceof HandlersController\n ? handlers\n : new InMemoryHandlersController(handlers || [])\n }\n\n let resolvedOptions: DefineNetworkOptions<Sources> = {\n ...options,\n }\n\n /**\n * @note Create the handlers controller immediately because\n * certain setup APIs, like `setupServer`, don't await `.enable` (`.listen`).\n */\n let handlersController = deriveHandlersController(resolvedOptions.handlers)\n let listenersController: AbortController\n\n return {\n get readyState() {\n return readyState\n },\n events,\n configure(options) {\n invariant(readyState === NetworkReadyState.DISABLED, '')\n\n if (\n options.handlers &&\n !Object.is(options.handlers, resolvedOptions.handlers)\n ) {\n handlersController = deriveHandlersController(options.handlers)\n }\n\n resolvedOptions = {\n ...resolvedOptions,\n ...options,\n }\n },\n enable() {\n invariant(\n readyState === NetworkReadyState.DISABLED,\n 'Failed to call \"enable\" on the network: already enabled',\n )\n\n listenersController = new AbortController()\n readyState = NetworkReadyState.ENABLED\n\n const result = resolvedOptions.sources.map((source) => {\n /**\n * @note Preemptively disable the network source before enabling.\n * This intentionally calls only the prototype method that clears the\n * event listeners and nothing else. This prevents the \"frame\" listeners\n * from accumulating across enable/disable in case the source is a singleton.\n */\n NetworkSource.prototype.disable.call(source)\n\n source.on('frame', async ({ frame }) => {\n frame.events.on('*', (event) => events.emit(event), {\n signal: listenersController.signal,\n })\n\n const handlers = frame.getHandlers(handlersController)\n\n await frame.resolve(\n handlers,\n resolvedOptions.onUnhandledFrame || 'warn',\n resolvedOptions.context,\n )\n })\n\n return source.enable()\n })\n\n return colorlessPromiseAll(result) as MaybePromise<\n ReturnType<Sources[number]['enable']>\n >\n },\n disable() {\n invariant(\n readyState === NetworkReadyState.ENABLED,\n 'Failed to call \"disable\" on the network: already disabled',\n )\n\n listenersController.abort()\n readyState = NetworkReadyState.DISABLED\n\n return colorlessPromiseAll(\n resolvedOptions.sources.map((source) => source.disable()),\n ) as MaybePromise<ReturnType<Sources[number]['disable']>>\n },\n use(...handlers) {\n handlersController.use(handlers)\n },\n resetHandlers(...handlers) {\n handlersController.reset(handlers)\n },\n restoreHandlers() {\n handlersController.restore()\n },\n listHandlers() {\n return toReadonlyArray(handlersController.currentHandlers())\n },\n }\n}\n"],"mappings":"AAAA,SAAS,iBAAiB;AAC1B,SAAS,eAAqC;AAC9C;AAAA,EACE;AAAA,OAEK;AACP,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,sBAAc,UAAU,QAAQ,KAAK,MAAM;AAE3C,eAAO,GAAG,SAAS,OAAO,EAAE,MAAM,MAAM;AACtC,gBAAM,OAAO,GAAG,KAAK,CAAC,UAAU,OAAO,KAAK,KAAK,GAAG;AAAA,YAClD,QAAQ,oBAAoB;AAAA,UAC9B,CAAC;AAED,gBAAM,WAAW,MAAM,YAAY,kBAAkB;AAErD,gBAAM,MAAM;AAAA,YACV;AAAA,YACA,gBAAgB,oBAAoB;AAAA,YACpC,gBAAgB;AAAA,UAClB;AAAA,QACF,CAAC;AAED,eAAO,OAAO,OAAO;AAAA,MACvB,CAAC;AAED,aAAO,oBAAoB,MAAM;AAAA,IAGnC;AAAA,IACA,UAAU;AACR;AAAA,QACE,eAAe;AAAA,QACf;AAAA,MACF;AAEA,0BAAoB,MAAM;AAC1B,mBAAa;AAEb,aAAO;AAAA,QACL,gBAAgB,QAAQ,IAAI,CAAC,WAAW,OAAO,QAAQ,CAAC;AAAA,MAC1D;AAAA,IACF;AAAA,IACA,OAAO,UAAU;AACf,yBAAmB,IAAI,QAAQ;AAAA,IACjC;AAAA,IACA,iBAAiB,UAAU;AACzB,yBAAmB,MAAM,QAAQ;AAAA,IACnC;AAAA,IACA,kBAAkB;AAChB,yBAAmB,QAAQ;AAAA,IAC7B;AAAA,IACA,eAAe;AACb,aAAO,gBAAgB,mBAAmB,gBAAgB,CAAC;AAAA,IAC7D;AAAA,EACF;AACF;","names":["NetworkReadyState","options"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TypedEvent } from 'rettime';
|
|
2
2
|
import { N as NetworkFrame, b as UnhandledFrameHandle, a as NetworkFrameResolutionContext } from '../../on-unhandled-frame-Cr1KOZ0I.mjs';
|
|
3
3
|
import { HandlersController, AnyHandler } from '../handlers-controller.mjs';
|
|
4
|
-
import { R as RequestHandler } from '../../HttpResponse-
|
|
4
|
+
import { R as RequestHandler } from '../../HttpResponse-BMMzfpjG.mjs';
|
|
5
5
|
import '../../handlers/WebSocketHandler.mjs';
|
|
6
6
|
import 'strict-event-emitter';
|
|
7
7
|
import '@mswjs/interceptors/WebSocket';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TypedEvent } from 'rettime';
|
|
2
2
|
import { N as NetworkFrame, b as UnhandledFrameHandle, a as NetworkFrameResolutionContext } from '../../on-unhandled-frame-BBR-P3kV.js';
|
|
3
3
|
import { HandlersController, AnyHandler } from '../handlers-controller.js';
|
|
4
|
-
import { R as RequestHandler } from '../../HttpResponse-
|
|
4
|
+
import { R as RequestHandler } from '../../HttpResponse-DPDqE4Pb.js';
|
|
5
5
|
import '../../handlers/WebSocketHandler.js';
|
|
6
6
|
import 'strict-event-emitter';
|
|
7
7
|
import '@mswjs/interceptors/WebSocket';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'rettime';
|
|
2
2
|
import '../handlers-controller.mjs';
|
|
3
3
|
export { A as AnyNetworkFrame, E as ExtractFrameEvents, N as NetworkFrame, a as NetworkFrameResolutionContext } from '../../on-unhandled-frame-Cr1KOZ0I.mjs';
|
|
4
|
-
import '../../HttpResponse-
|
|
4
|
+
import '../../HttpResponse-BMMzfpjG.mjs';
|
|
5
5
|
import '@mswjs/interceptors';
|
|
6
6
|
import '../../utils/internal/isIterable.mjs';
|
|
7
7
|
import '../../typeUtils.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'rettime';
|
|
2
2
|
import '../handlers-controller.js';
|
|
3
3
|
export { A as AnyNetworkFrame, E as ExtractFrameEvents, N as NetworkFrame, a as NetworkFrameResolutionContext } from '../../on-unhandled-frame-BBR-P3kV.js';
|
|
4
|
-
import '../../HttpResponse-
|
|
4
|
+
import '../../HttpResponse-DPDqE4Pb.js';
|
|
5
5
|
import '@mswjs/interceptors';
|
|
6
6
|
import '../../utils/internal/isIterable.js';
|
|
7
7
|
import '../../typeUtils.js';
|
|
@@ -5,7 +5,7 @@ import { N as NetworkFrame, b as UnhandledFrameHandle, a as NetworkFrameResoluti
|
|
|
5
5
|
import { HandlersController, AnyHandler } from '../handlers-controller.mjs';
|
|
6
6
|
import 'strict-event-emitter';
|
|
7
7
|
import '../../utils/matching/matchRequestUrl.mjs';
|
|
8
|
-
import '../../HttpResponse-
|
|
8
|
+
import '../../HttpResponse-BMMzfpjG.mjs';
|
|
9
9
|
import '@mswjs/interceptors';
|
|
10
10
|
import '../../utils/internal/isIterable.mjs';
|
|
11
11
|
import '../../typeUtils.mjs';
|
|
@@ -5,7 +5,7 @@ import { N as NetworkFrame, b as UnhandledFrameHandle, a as NetworkFrameResoluti
|
|
|
5
5
|
import { HandlersController, AnyHandler } from '../handlers-controller.js';
|
|
6
6
|
import 'strict-event-emitter';
|
|
7
7
|
import '../../utils/matching/matchRequestUrl.js';
|
|
8
|
-
import '../../HttpResponse-
|
|
8
|
+
import '../../HttpResponse-DPDqE4Pb.js';
|
|
9
9
|
import '@mswjs/interceptors';
|
|
10
10
|
import '../../utils/internal/isIterable.js';
|
|
11
11
|
import '../../typeUtils.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler } from '../HttpResponse-
|
|
1
|
+
import { R as RequestHandler } from '../HttpResponse-BMMzfpjG.mjs';
|
|
2
2
|
import { WebSocketHandler } from '../handlers/WebSocketHandler.mjs';
|
|
3
3
|
import '@mswjs/interceptors';
|
|
4
4
|
import '../utils/internal/isIterable.mjs';
|
|
@@ -24,6 +24,7 @@ declare abstract class HandlersController {
|
|
|
24
24
|
getHandlersByKind(kind: AnyHandler['kind']): Array<AnyHandler>;
|
|
25
25
|
use(nextHandlers: Array<AnyHandler>): void;
|
|
26
26
|
reset(nextHandlers: Array<AnyHandler>): void;
|
|
27
|
+
restore(): void;
|
|
27
28
|
}
|
|
28
29
|
declare class InMemoryHandlersController extends HandlersController {
|
|
29
30
|
#private;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler } from '../HttpResponse-
|
|
1
|
+
import { R as RequestHandler } from '../HttpResponse-DPDqE4Pb.js';
|
|
2
2
|
import { WebSocketHandler } from '../handlers/WebSocketHandler.js';
|
|
3
3
|
import '@mswjs/interceptors';
|
|
4
4
|
import '../utils/internal/isIterable.js';
|
|
@@ -24,6 +24,7 @@ declare abstract class HandlersController {
|
|
|
24
24
|
getHandlersByKind(kind: AnyHandler['kind']): Array<AnyHandler>;
|
|
25
25
|
use(nextHandlers: Array<AnyHandler>): void;
|
|
26
26
|
reset(nextHandlers: Array<AnyHandler>): void;
|
|
27
|
+
restore(): void;
|
|
27
28
|
}
|
|
28
29
|
declare class InMemoryHandlersController extends HandlersController {
|
|
29
30
|
#private;
|
|
@@ -79,6 +79,11 @@ class HandlersController {
|
|
|
79
79
|
"Failed to replace initial handlers during reset: invalid handlers. Did you forget to spread the handlers array?"
|
|
80
80
|
)
|
|
81
81
|
);
|
|
82
|
+
for (const handler of this.currentHandlers()) {
|
|
83
|
+
if ("reset" in handler) {
|
|
84
|
+
handler["reset"]();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
82
87
|
const { initialHandlers } = this.getState();
|
|
83
88
|
if (nextHandlers.length === 0) {
|
|
84
89
|
this.setState({
|
|
@@ -92,6 +97,13 @@ class HandlersController {
|
|
|
92
97
|
handlers: { ...normalizedNextHandlers }
|
|
93
98
|
});
|
|
94
99
|
}
|
|
100
|
+
restore() {
|
|
101
|
+
for (const handler of this.currentHandlers()) {
|
|
102
|
+
if ("restore" in handler) {
|
|
103
|
+
handler["restore"]();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
95
107
|
#validateHandlers(handlers) {
|
|
96
108
|
return handlers.every((handler) => !Array.isArray(handler));
|
|
97
109
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/experimental/handlers-controller.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { type RequestHandler } from '../handlers/RequestHandler'\nimport { type WebSocketHandler } from '../handlers/WebSocketHandler'\nimport { devUtils } from '../utils/internal/devUtils'\n\nexport type AnyHandler = RequestHandler | WebSocketHandler\nexport type HandlersMap = Partial<Record<AnyHandler['kind'], Array<AnyHandler>>>\n\nexport function groupHandlersByKind(handlers: Array<AnyHandler>): HandlersMap {\n const groups: HandlersMap = {}\n\n /**\n * @note `Object.groupBy` is not implemented in Node.js v20.\n */\n for (const handler of handlers) {\n ;(groups[handler.kind] ||= []).push(handler)\n }\n\n return groups\n}\n\nexport interface HandlersControllerState {\n initialHandlers: HandlersMap\n handlers: HandlersMap\n}\n\nexport abstract class HandlersController {\n protected getInitialState(\n initialHandlers: Array<AnyHandler>,\n ): HandlersControllerState {\n invariant(\n this.#validateHandlers(initialHandlers),\n devUtils.formatMessage(\n 'Failed to apply given request handlers: invalid input. Did you forget to spread the request handlers Array?',\n ),\n )\n\n const normalizedInitialHandlers = groupHandlersByKind(initialHandlers)\n\n return {\n initialHandlers: normalizedInitialHandlers,\n handlers: { ...normalizedInitialHandlers },\n }\n }\n\n protected abstract getState(): HandlersControllerState\n protected abstract setState(nextState: Partial<HandlersControllerState>): void\n\n public currentHandlers(): Array<AnyHandler> {\n return Object.values(this.getState().handlers)\n .flat()\n .filter((handler) => handler != null)\n }\n\n public getHandlersByKind(kind: AnyHandler['kind']): Array<AnyHandler> {\n return this.getState().handlers[kind] || []\n }\n\n public use(nextHandlers: Array<AnyHandler>): void {\n invariant(\n this.#validateHandlers(nextHandlers),\n devUtils.formatMessage(\n '[MSW] Failed to call \"use()\" with the given request handlers: invalid input. Did you forget to spread the array of request handlers?',\n ),\n )\n\n if (nextHandlers.length === 0) {\n return\n }\n\n const { handlers } = this.getState()\n\n // Iterate over next handlers and prepend them to their respective lists.\n // Iterate in a reverse order to the keep the order of the runtime handlers as provided.\n for (let i = nextHandlers.length - 1; i >= 0; i--) {\n const handler = nextHandlers[i]\n handlers[handler.kind] = handlers[handler.kind]\n ? [handler, ...handlers[handler.kind]!]\n : [handler]\n }\n\n this.setState({ handlers })\n }\n\n public reset(nextHandlers: Array<AnyHandler>): void {\n invariant(\n nextHandlers.length > 0 ? this.#validateHandlers(nextHandlers) : true,\n devUtils.formatMessage(\n 'Failed to replace initial handlers during reset: invalid handlers. Did you forget to spread the handlers array?',\n ),\n )\n\n const { initialHandlers } = this.getState()\n\n if (nextHandlers.length === 0) {\n this.setState({\n handlers: { ...initialHandlers },\n })\n\n return\n }\n\n const normalizedNextHandlers = groupHandlersByKind(nextHandlers)\n\n this.setState({\n initialHandlers: normalizedNextHandlers,\n handlers: { ...normalizedNextHandlers },\n })\n }\n\n #validateHandlers(handlers: Array<AnyHandler>): boolean {\n return handlers.every((handler) => !Array.isArray(handler))\n }\n}\n\nexport class InMemoryHandlersController extends HandlersController {\n #handlers: HandlersMap\n #initialHandlers: HandlersMap\n\n constructor(initialHandlers: Array<AnyHandler>) {\n super()\n\n const initialState = this.getInitialState(initialHandlers)\n\n this.#initialHandlers = initialState.initialHandlers\n this.#handlers = initialState.handlers\n }\n\n protected getState(): HandlersControllerState {\n return {\n initialHandlers: this.#initialHandlers,\n handlers: this.#handlers,\n }\n }\n\n protected setState(nextState: Partial<HandlersControllerState>): void {\n if (nextState.initialHandlers) {\n this.#initialHandlers = nextState.initialHandlers\n }\n\n if (nextState.handlers) {\n this.#handlers = nextState.handlers\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA0B;AAC1B,4BAAoC;AACpC,8BAAsC;AACtC,sBAAyB;AAKlB,SAAS,oBAAoB,UAA0C;AAC5E,QAAM,SAAsB,CAAC;AAK7B,aAAW,WAAW,UAAU;AAC9B;AAAC,KAAC,OAAO,QAAQ,IAAI,MAAM,CAAC,GAAG,KAAK,OAAO;AAAA,EAC7C;AAEA,SAAO;AACT;AAOO,MAAe,mBAAmB;AAAA,EAC7B,gBACR,iBACyB;AACzB;AAAA,MACE,KAAK,kBAAkB,eAAe;AAAA,MACtC,yBAAS;AAAA,QACP;AAAA,MACF;AAAA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E,GAAG,uBAAuB;AAAA,IACxC,CAAC;AAAA,EACH;AAAA,EAEA,kBAAkB,UAAsC;AACtD,WAAO,SAAS,MAAM,CAAC,YAAY,CAAC,MAAM,QAAQ,OAAO,CAAC;AAAA,EAC5D;AACF;AAEO,MAAM,mCAAmC,mBAAmB;AAAA,EACjE;AAAA,EACA;AAAA,EAEA,YAAY,iBAAoC;AAC9C,UAAM;AAEN,UAAM,eAAe,KAAK,gBAAgB,eAAe;AAEzD,SAAK,mBAAmB,aAAa;AACrC,SAAK,YAAY,aAAa;AAAA,EAChC;AAAA,EAEU,WAAoC;AAC5C,WAAO;AAAA,MACL,iBAAiB,KAAK;AAAA,MACtB,UAAU,KAAK;AAAA,IACjB;AAAA,EACF;AAAA,EAEU,SAAS,WAAmD;AACpE,QAAI,UAAU,iBAAiB;AAC7B,WAAK,mBAAmB,UAAU;AAAA,IACpC;AAEA,QAAI,UAAU,UAAU;AACtB,WAAK,YAAY,UAAU;AAAA,IAC7B;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/core/experimental/handlers-controller.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { type RequestHandler } from '../handlers/RequestHandler'\nimport { type WebSocketHandler } from '../handlers/WebSocketHandler'\nimport { devUtils } from '../utils/internal/devUtils'\n\nexport type AnyHandler = RequestHandler | WebSocketHandler\nexport type HandlersMap = Partial<Record<AnyHandler['kind'], Array<AnyHandler>>>\n\nexport function groupHandlersByKind(handlers: Array<AnyHandler>): HandlersMap {\n const groups: HandlersMap = {}\n\n /**\n * @note `Object.groupBy` is not implemented in Node.js v20.\n */\n for (const handler of handlers) {\n ;(groups[handler.kind] ||= []).push(handler)\n }\n\n return groups\n}\n\nexport interface HandlersControllerState {\n initialHandlers: HandlersMap\n handlers: HandlersMap\n}\n\nexport abstract class HandlersController {\n protected getInitialState(\n initialHandlers: Array<AnyHandler>,\n ): HandlersControllerState {\n invariant(\n this.#validateHandlers(initialHandlers),\n devUtils.formatMessage(\n 'Failed to apply given request handlers: invalid input. Did you forget to spread the request handlers Array?',\n ),\n )\n\n const normalizedInitialHandlers = groupHandlersByKind(initialHandlers)\n\n return {\n initialHandlers: normalizedInitialHandlers,\n handlers: { ...normalizedInitialHandlers },\n }\n }\n\n protected abstract getState(): HandlersControllerState\n protected abstract setState(nextState: Partial<HandlersControllerState>): void\n\n public currentHandlers(): Array<AnyHandler> {\n return Object.values(this.getState().handlers)\n .flat()\n .filter((handler) => handler != null)\n }\n\n public getHandlersByKind(kind: AnyHandler['kind']): Array<AnyHandler> {\n return this.getState().handlers[kind] || []\n }\n\n public use(nextHandlers: Array<AnyHandler>): void {\n invariant(\n this.#validateHandlers(nextHandlers),\n devUtils.formatMessage(\n '[MSW] Failed to call \"use()\" with the given request handlers: invalid input. Did you forget to spread the array of request handlers?',\n ),\n )\n\n if (nextHandlers.length === 0) {\n return\n }\n\n const { handlers } = this.getState()\n\n // Iterate over next handlers and prepend them to their respective lists.\n // Iterate in a reverse order to the keep the order of the runtime handlers as provided.\n for (let i = nextHandlers.length - 1; i >= 0; i--) {\n const handler = nextHandlers[i]\n handlers[handler.kind] = handlers[handler.kind]\n ? [handler, ...handlers[handler.kind]!]\n : [handler]\n }\n\n this.setState({ handlers })\n }\n\n public reset(nextHandlers: Array<AnyHandler>): void {\n invariant(\n nextHandlers.length > 0 ? this.#validateHandlers(nextHandlers) : true,\n devUtils.formatMessage(\n 'Failed to replace initial handlers during reset: invalid handlers. Did you forget to spread the handlers array?',\n ),\n )\n\n for (const handler of this.currentHandlers()) {\n if ('reset' in handler) {\n handler['reset']()\n }\n }\n\n const { initialHandlers } = this.getState()\n\n if (nextHandlers.length === 0) {\n this.setState({\n handlers: { ...initialHandlers },\n })\n\n return\n }\n\n const normalizedNextHandlers = groupHandlersByKind(nextHandlers)\n\n this.setState({\n initialHandlers: normalizedNextHandlers,\n handlers: { ...normalizedNextHandlers },\n })\n }\n\n public restore(): void {\n for (const handler of this.currentHandlers()) {\n if ('restore' in handler) {\n handler['restore']()\n }\n }\n }\n\n #validateHandlers(handlers: Array<AnyHandler>): boolean {\n return handlers.every((handler) => !Array.isArray(handler))\n }\n}\n\nexport class InMemoryHandlersController extends HandlersController {\n #handlers: HandlersMap\n #initialHandlers: HandlersMap\n\n constructor(initialHandlers: Array<AnyHandler>) {\n super()\n\n const initialState = this.getInitialState(initialHandlers)\n\n this.#initialHandlers = initialState.initialHandlers\n this.#handlers = initialState.handlers\n }\n\n protected getState(): HandlersControllerState {\n return {\n initialHandlers: this.#initialHandlers,\n handlers: this.#handlers,\n }\n }\n\n protected setState(nextState: Partial<HandlersControllerState>): void {\n if (nextState.initialHandlers) {\n this.#initialHandlers = nextState.initialHandlers\n }\n\n if (nextState.handlers) {\n this.#handlers = nextState.handlers\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA0B;AAC1B,4BAAoC;AACpC,8BAAsC;AACtC,sBAAyB;AAKlB,SAAS,oBAAoB,UAA0C;AAC5E,QAAM,SAAsB,CAAC;AAK7B,aAAW,WAAW,UAAU;AAC9B;AAAC,KAAC,OAAO,QAAQ,IAAI,MAAM,CAAC,GAAG,KAAK,OAAO;AAAA,EAC7C;AAEA,SAAO;AACT;AAOO,MAAe,mBAAmB;AAAA,EAC7B,gBACR,iBACyB;AACzB;AAAA,MACE,KAAK,kBAAkB,eAAe;AAAA,MACtC,yBAAS;AAAA,QACP;AAAA,MACF;AAAA,IACF;AAEA,UAAM,4BAA4B,oBAAoB,eAAe;AAErE,WAAO;AAAA,MACL,iBAAiB;AAAA,MACjB,UAAU,EAAE,GAAG,0BAA0B;AAAA,IAC3C;AAAA,EACF;AAAA,EAKO,kBAAqC;AAC1C,WAAO,OAAO,OAAO,KAAK,SAAS,EAAE,QAAQ,EAC1C,KAAK,EACL,OAAO,CAAC,YAAY,WAAW,IAAI;AAAA,EACxC;AAAA,EAEO,kBAAkB,MAA6C;AACp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EACF;AAAA,EAEA,kBAAkB,UAAsC;AACtD,WAAO,SAAS,MAAM,CAAC,YAAY,CAAC,MAAM,QAAQ,OAAO,CAAC;AAAA,EAC5D;AACF;AAEO,MAAM,mCAAmC,mBAAmB;AAAA,EACjE;AAAA,EACA;AAAA,EAEA,YAAY,iBAAoC;AAC9C,UAAM;AAEN,UAAM,eAAe,KAAK,gBAAgB,eAAe;AAEzD,SAAK,mBAAmB,aAAa;AACrC,SAAK,YAAY,aAAa;AAAA,EAChC;AAAA,EAEU,WAAoC;AAC5C,WAAO;AAAA,MACL,iBAAiB,KAAK;AAAA,MACtB,UAAU,KAAK;AAAA,IACjB;AAAA,EACF;AAAA,EAEU,SAAS,WAAmD;AACpE,QAAI,UAAU,iBAAiB;AAC7B,WAAK,mBAAmB,UAAU;AAAA,IACpC;AAEA,QAAI,UAAU,UAAU;AACtB,WAAK,YAAY,UAAU;AAAA,IAC7B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -54,6 +54,11 @@ class HandlersController {
|
|
|
54
54
|
"Failed to replace initial handlers during reset: invalid handlers. Did you forget to spread the handlers array?"
|
|
55
55
|
)
|
|
56
56
|
);
|
|
57
|
+
for (const handler of this.currentHandlers()) {
|
|
58
|
+
if ("reset" in handler) {
|
|
59
|
+
handler["reset"]();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
57
62
|
const { initialHandlers } = this.getState();
|
|
58
63
|
if (nextHandlers.length === 0) {
|
|
59
64
|
this.setState({
|
|
@@ -67,6 +72,13 @@ class HandlersController {
|
|
|
67
72
|
handlers: { ...normalizedNextHandlers }
|
|
68
73
|
});
|
|
69
74
|
}
|
|
75
|
+
restore() {
|
|
76
|
+
for (const handler of this.currentHandlers()) {
|
|
77
|
+
if ("restore" in handler) {
|
|
78
|
+
handler["restore"]();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
70
82
|
#validateHandlers(handlers) {
|
|
71
83
|
return handlers.every((handler) => !Array.isArray(handler));
|
|
72
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/experimental/handlers-controller.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { type RequestHandler } from '../handlers/RequestHandler'\nimport { type WebSocketHandler } from '../handlers/WebSocketHandler'\nimport { devUtils } from '../utils/internal/devUtils'\n\nexport type AnyHandler = RequestHandler | WebSocketHandler\nexport type HandlersMap = Partial<Record<AnyHandler['kind'], Array<AnyHandler>>>\n\nexport function groupHandlersByKind(handlers: Array<AnyHandler>): HandlersMap {\n const groups: HandlersMap = {}\n\n /**\n * @note `Object.groupBy` is not implemented in Node.js v20.\n */\n for (const handler of handlers) {\n ;(groups[handler.kind] ||= []).push(handler)\n }\n\n return groups\n}\n\nexport interface HandlersControllerState {\n initialHandlers: HandlersMap\n handlers: HandlersMap\n}\n\nexport abstract class HandlersController {\n protected getInitialState(\n initialHandlers: Array<AnyHandler>,\n ): HandlersControllerState {\n invariant(\n this.#validateHandlers(initialHandlers),\n devUtils.formatMessage(\n 'Failed to apply given request handlers: invalid input. Did you forget to spread the request handlers Array?',\n ),\n )\n\n const normalizedInitialHandlers = groupHandlersByKind(initialHandlers)\n\n return {\n initialHandlers: normalizedInitialHandlers,\n handlers: { ...normalizedInitialHandlers },\n }\n }\n\n protected abstract getState(): HandlersControllerState\n protected abstract setState(nextState: Partial<HandlersControllerState>): void\n\n public currentHandlers(): Array<AnyHandler> {\n return Object.values(this.getState().handlers)\n .flat()\n .filter((handler) => handler != null)\n }\n\n public getHandlersByKind(kind: AnyHandler['kind']): Array<AnyHandler> {\n return this.getState().handlers[kind] || []\n }\n\n public use(nextHandlers: Array<AnyHandler>): void {\n invariant(\n this.#validateHandlers(nextHandlers),\n devUtils.formatMessage(\n '[MSW] Failed to call \"use()\" with the given request handlers: invalid input. Did you forget to spread the array of request handlers?',\n ),\n )\n\n if (nextHandlers.length === 0) {\n return\n }\n\n const { handlers } = this.getState()\n\n // Iterate over next handlers and prepend them to their respective lists.\n // Iterate in a reverse order to the keep the order of the runtime handlers as provided.\n for (let i = nextHandlers.length - 1; i >= 0; i--) {\n const handler = nextHandlers[i]\n handlers[handler.kind] = handlers[handler.kind]\n ? [handler, ...handlers[handler.kind]!]\n : [handler]\n }\n\n this.setState({ handlers })\n }\n\n public reset(nextHandlers: Array<AnyHandler>): void {\n invariant(\n nextHandlers.length > 0 ? this.#validateHandlers(nextHandlers) : true,\n devUtils.formatMessage(\n 'Failed to replace initial handlers during reset: invalid handlers. Did you forget to spread the handlers array?',\n ),\n )\n\n const { initialHandlers } = this.getState()\n\n if (nextHandlers.length === 0) {\n this.setState({\n handlers: { ...initialHandlers },\n })\n\n return\n }\n\n const normalizedNextHandlers = groupHandlersByKind(nextHandlers)\n\n this.setState({\n initialHandlers: normalizedNextHandlers,\n handlers: { ...normalizedNextHandlers },\n })\n }\n\n #validateHandlers(handlers: Array<AnyHandler>): boolean {\n return handlers.every((handler) => !Array.isArray(handler))\n }\n}\n\nexport class InMemoryHandlersController extends HandlersController {\n #handlers: HandlersMap\n #initialHandlers: HandlersMap\n\n constructor(initialHandlers: Array<AnyHandler>) {\n super()\n\n const initialState = this.getInitialState(initialHandlers)\n\n this.#initialHandlers = initialState.initialHandlers\n this.#handlers = initialState.handlers\n }\n\n protected getState(): HandlersControllerState {\n return {\n initialHandlers: this.#initialHandlers,\n handlers: this.#handlers,\n }\n }\n\n protected setState(nextState: Partial<HandlersControllerState>): void {\n if (nextState.initialHandlers) {\n this.#initialHandlers = nextState.initialHandlers\n }\n\n if (nextState.handlers) {\n this.#handlers = nextState.handlers\n }\n }\n}\n"],"mappings":"AAAA,SAAS,iBAAiB;AAC1B,eAAoC;AACpC,eAAsC;AACtC,SAAS,gBAAgB;AAKlB,SAAS,oBAAoB,UAA0C;AAC5E,QAAM,SAAsB,CAAC;AAK7B,aAAW,WAAW,UAAU;AAC9B;AAAC,KAAC,OAAO,QAAQ,IAAI,MAAM,CAAC,GAAG,KAAK,OAAO;AAAA,EAC7C;AAE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,gBAAgB;AAAA,MACjC,CAAC;AAED;AAAA,IACF;AAEA,UAAM,yBAAyB,oBAAoB,YAAY;AAE/D,SAAK,SAAS;AAAA,MACZ,iBAAiB;AAAA,MACjB,UAAU,EAAE,GAAG,uBAAuB;AAAA,IACxC,CAAC;AAAA,EACH;AAAA,EAEA,kBAAkB,UAAsC;AACtD,WAAO,SAAS,MAAM,CAAC,YAAY,CAAC,MAAM,QAAQ,OAAO,CAAC;AAAA,EAC5D;AACF;AAEO,MAAM,mCAAmC,mBAAmB;AAAA,EACjE;AAAA,EACA;AAAA,EAEA,YAAY,iBAAoC;AAC9C,UAAM;AAEN,UAAM,eAAe,KAAK,gBAAgB,eAAe;AAEzD,SAAK,mBAAmB,aAAa;AACrC,SAAK,YAAY,aAAa;AAAA,EAChC;AAAA,EAEU,WAAoC;AAC5C,WAAO;AAAA,MACL,iBAAiB,KAAK;AAAA,MACtB,UAAU,KAAK;AAAA,IACjB;AAAA,EACF;AAAA,EAEU,SAAS,WAAmD;AACpE,QAAI,UAAU,iBAAiB;AAC7B,WAAK,mBAAmB,UAAU;AAAA,IACpC;AAEA,QAAI,UAAU,UAAU;AACtB,WAAK,YAAY,UAAU;AAAA,IAC7B;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/core/experimental/handlers-controller.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { type RequestHandler } from '../handlers/RequestHandler'\nimport { type WebSocketHandler } from '../handlers/WebSocketHandler'\nimport { devUtils } from '../utils/internal/devUtils'\n\nexport type AnyHandler = RequestHandler | WebSocketHandler\nexport type HandlersMap = Partial<Record<AnyHandler['kind'], Array<AnyHandler>>>\n\nexport function groupHandlersByKind(handlers: Array<AnyHandler>): HandlersMap {\n const groups: HandlersMap = {}\n\n /**\n * @note `Object.groupBy` is not implemented in Node.js v20.\n */\n for (const handler of handlers) {\n ;(groups[handler.kind] ||= []).push(handler)\n }\n\n return groups\n}\n\nexport interface HandlersControllerState {\n initialHandlers: HandlersMap\n handlers: HandlersMap\n}\n\nexport abstract class HandlersController {\n protected getInitialState(\n initialHandlers: Array<AnyHandler>,\n ): HandlersControllerState {\n invariant(\n this.#validateHandlers(initialHandlers),\n devUtils.formatMessage(\n 'Failed to apply given request handlers: invalid input. Did you forget to spread the request handlers Array?',\n ),\n )\n\n const normalizedInitialHandlers = groupHandlersByKind(initialHandlers)\n\n return {\n initialHandlers: normalizedInitialHandlers,\n handlers: { ...normalizedInitialHandlers },\n }\n }\n\n protected abstract getState(): HandlersControllerState\n protected abstract setState(nextState: Partial<HandlersControllerState>): void\n\n public currentHandlers(): Array<AnyHandler> {\n return Object.values(this.getState().handlers)\n .flat()\n .filter((handler) => handler != null)\n }\n\n public getHandlersByKind(kind: AnyHandler['kind']): Array<AnyHandler> {\n return this.getState().handlers[kind] || []\n }\n\n public use(nextHandlers: Array<AnyHandler>): void {\n invariant(\n this.#validateHandlers(nextHandlers),\n devUtils.formatMessage(\n '[MSW] Failed to call \"use()\" with the given request handlers: invalid input. Did you forget to spread the array of request handlers?',\n ),\n )\n\n if (nextHandlers.length === 0) {\n return\n }\n\n const { handlers } = this.getState()\n\n // Iterate over next handlers and prepend them to their respective lists.\n // Iterate in a reverse order to the keep the order of the runtime handlers as provided.\n for (let i = nextHandlers.length - 1; i >= 0; i--) {\n const handler = nextHandlers[i]\n handlers[handler.kind] = handlers[handler.kind]\n ? [handler, ...handlers[handler.kind]!]\n : [handler]\n }\n\n this.setState({ handlers })\n }\n\n public reset(nextHandlers: Array<AnyHandler>): void {\n invariant(\n nextHandlers.length > 0 ? this.#validateHandlers(nextHandlers) : true,\n devUtils.formatMessage(\n 'Failed to replace initial handlers during reset: invalid handlers. Did you forget to spread the handlers array?',\n ),\n )\n\n for (const handler of this.currentHandlers()) {\n if ('reset' in handler) {\n handler['reset']()\n }\n }\n\n const { initialHandlers } = this.getState()\n\n if (nextHandlers.length === 0) {\n this.setState({\n handlers: { ...initialHandlers },\n })\n\n return\n }\n\n const normalizedNextHandlers = groupHandlersByKind(nextHandlers)\n\n this.setState({\n initialHandlers: normalizedNextHandlers,\n handlers: { ...normalizedNextHandlers },\n })\n }\n\n public restore(): void {\n for (const handler of this.currentHandlers()) {\n if ('restore' in handler) {\n handler['restore']()\n }\n }\n }\n\n #validateHandlers(handlers: Array<AnyHandler>): boolean {\n return handlers.every((handler) => !Array.isArray(handler))\n }\n}\n\nexport class InMemoryHandlersController extends HandlersController {\n #handlers: HandlersMap\n #initialHandlers: HandlersMap\n\n constructor(initialHandlers: Array<AnyHandler>) {\n super()\n\n const initialState = this.getInitialState(initialHandlers)\n\n this.#initialHandlers = initialState.initialHandlers\n this.#handlers = initialState.handlers\n }\n\n protected getState(): HandlersControllerState {\n return {\n initialHandlers: this.#initialHandlers,\n handlers: this.#handlers,\n }\n }\n\n protected setState(nextState: Partial<HandlersControllerState>): void {\n if (nextState.initialHandlers) {\n this.#initialHandlers = nextState.initialHandlers\n }\n\n if (nextState.handlers) {\n this.#handlers = nextState.handlers\n }\n }\n}\n"],"mappings":"AAAA,SAAS,iBAAiB;AAC1B,eAAoC;AACpC,eAAsC;AACtC,SAAS,gBAAgB;AAKlB,SAAS,oBAAoB,UAA0C;AAC5E,QAAM,SAAsB,CAAC;AAK7B,aAAW,WAAW,UAAU;AAC9B;AAAC,KAAC,OAAO,QAAQ,IAAI,MAAM,CAAC,GAAG,KAAK,OAAO;AAAA,EAC7C;AAEA,SAAO;AACT;AAOO,MAAe,mBAAmB;AAAA,EAC7B,gBACR,iBACyB;AACzB;AAAA,MACE,KAAK,kBAAkB,eAAe;AAAA,MACtC,SAAS;AAAA,QACP;AAAA,MACF;AAAA,IACF;AAEA,UAAM,4BAA4B,oBAAoB,eAAe;AAErE,WAAO;AAAA,MACL,iBAAiB;AAAA,MACjB,UAAU,EAAE,GAAG,0BAA0B;AAAA,IAC3C;AAAA,EACF;AAAA,EAKO,kBAAqC;AAC1C,WAAO,OAAO,OAAO,KAAK,SAAS,EAAE,QAAQ,EAC1C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G;AAC5C,UAAI,aAAa,SAAS;AACxB,gBAAQ,SAAS,EAAE;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,kBAAkB,UAAsC;AACtD,WAAO,SAAS,MAAM,CAAC,YAAY,CAAC,MAAM,QAAQ,OAAO,CAAC;AAAA,EAC5D;AACF;AAEO,MAAM,mCAAmC,mBAAmB;AAAA,EACjE;AAAA,EACA;AAAA,EAEA,YAAY,iBAAoC;AAC9C,UAAM;AAEN,UAAM,eAAe,KAAK,gBAAgB,eAAe;AAEzD,SAAK,mBAAmB,aAAa;AACrC,SAAK,YAAY,aAAa;AAAA,EAChC;AAAA,EAEU,WAAoC;AAC5C,WAAO;AAAA,MACL,iBAAiB,KAAK;AAAA,MACtB,UAAU,KAAK;AAAA,IACjB;AAAA,EACF;AAAA,EAEU,SAAS,WAAmD;AACpE,QAAI,UAAU,iBAAiB;AAC7B,WAAK,mBAAmB,UAAU;AAAA,IACpC;AAEA,QAAI,UAAU,UAAU;AACtB,WAAK,YAAY,UAAU;AAAA,IAC7B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -6,7 +6,7 @@ export { HttpNetworkFrame, HttpNetworkFrameEventMap } from './frames/http-frame.
|
|
|
6
6
|
export { WebSocketNetworkFrame, WebSocketNetworkFrameEventMap } from './frames/websocket-frame.mjs';
|
|
7
7
|
import 'rettime';
|
|
8
8
|
import './handlers-controller.mjs';
|
|
9
|
-
import '../HttpResponse-
|
|
9
|
+
import '../HttpResponse-BMMzfpjG.mjs';
|
|
10
10
|
import '@mswjs/interceptors';
|
|
11
11
|
import '../utils/internal/isIterable.mjs';
|
|
12
12
|
import '../typeUtils.mjs';
|
|
@@ -6,7 +6,7 @@ export { HttpNetworkFrame, HttpNetworkFrameEventMap } from './frames/http-frame.
|
|
|
6
6
|
export { WebSocketNetworkFrame, WebSocketNetworkFrameEventMap } from './frames/websocket-frame.js';
|
|
7
7
|
import 'rettime';
|
|
8
8
|
import './handlers-controller.js';
|
|
9
|
-
import '../HttpResponse-
|
|
9
|
+
import '../HttpResponse-DPDqE4Pb.js';
|
|
10
10
|
import '@mswjs/interceptors';
|
|
11
11
|
import '../utils/internal/isIterable.js';
|
|
12
12
|
import '../typeUtils.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { U as UnhandledFrameCallback, d as UnhandledFrameDefaults, b as UnhandledFrameHandle, c as UnhandledFrameStrategy, e as executeUnhandledFrameHandle } from '../on-unhandled-frame-Cr1KOZ0I.mjs';
|
|
2
2
|
import 'rettime';
|
|
3
3
|
import './handlers-controller.mjs';
|
|
4
|
-
import '../HttpResponse-
|
|
4
|
+
import '../HttpResponse-BMMzfpjG.mjs';
|
|
5
5
|
import '@mswjs/interceptors';
|
|
6
6
|
import '../utils/internal/isIterable.mjs';
|
|
7
7
|
import '../typeUtils.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { U as UnhandledFrameCallback, d as UnhandledFrameDefaults, b as UnhandledFrameHandle, c as UnhandledFrameStrategy, e as executeUnhandledFrameHandle } from '../on-unhandled-frame-BBR-P3kV.js';
|
|
2
2
|
import 'rettime';
|
|
3
3
|
import './handlers-controller.js';
|
|
4
|
-
import '../HttpResponse-
|
|
4
|
+
import '../HttpResponse-DPDqE4Pb.js';
|
|
5
5
|
import '@mswjs/interceptors';
|
|
6
6
|
import '../utils/internal/isIterable.js';
|
|
7
7
|
import '../typeUtils.js';
|
|
@@ -3,7 +3,7 @@ import { LifeCycleEventEmitter } from '../sharedOptions.mjs';
|
|
|
3
3
|
import { HandlersController, AnyHandler } from './handlers-controller.mjs';
|
|
4
4
|
import { Disposable } from '../utils/internal/Disposable.mjs';
|
|
5
5
|
import '../utils/request/onUnhandledRequest.mjs';
|
|
6
|
-
import '../HttpResponse-
|
|
6
|
+
import '../HttpResponse-BMMzfpjG.mjs';
|
|
7
7
|
import '@mswjs/interceptors';
|
|
8
8
|
import '../utils/internal/isIterable.mjs';
|
|
9
9
|
import '../typeUtils.mjs';
|
|
@@ -3,7 +3,7 @@ import { LifeCycleEventEmitter } from '../sharedOptions.js';
|
|
|
3
3
|
import { HandlersController, AnyHandler } from './handlers-controller.js';
|
|
4
4
|
import { Disposable } from '../utils/internal/Disposable.js';
|
|
5
5
|
import '../utils/request/onUnhandledRequest.js';
|
|
6
|
-
import '../HttpResponse-
|
|
6
|
+
import '../HttpResponse-DPDqE4Pb.js';
|
|
7
7
|
import '@mswjs/interceptors';
|
|
8
8
|
import '../utils/internal/isIterable.js';
|
|
9
9
|
import '../typeUtils.js';
|
|
@@ -46,11 +46,7 @@ class SetupApi extends import_Disposable.Disposable {
|
|
|
46
46
|
this.handlersController.use(runtimeHandlers);
|
|
47
47
|
}
|
|
48
48
|
restoreHandlers() {
|
|
49
|
-
this.handlersController.
|
|
50
|
-
if ("isUsed" in handler) {
|
|
51
|
-
handler.isUsed = false;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
49
|
+
this.handlersController.restore();
|
|
54
50
|
}
|
|
55
51
|
resetHandlers(...nextHandlers) {
|
|
56
52
|
this.handlersController.reset(nextHandlers);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/experimental/setup-api.ts"],"sourcesContent":["import { type DefaultEventMap, Emitter } from 'rettime'\nimport { type LifeCycleEventEmitter } from '../sharedOptions'\nimport type { HandlersController } from './handlers-controller'\nimport {\n InMemoryHandlersController,\n type AnyHandler,\n} from './handlers-controller'\nimport { Disposable } from '../utils/internal/Disposable'\nimport { toReadonlyArray } from '../utils/internal/toReadonlyArray'\n\n/**\n * Generic class for the mock API setup.\n * Preserved only for backward compatibility.\n * @deprecated\n */\nexport abstract class SetupApi<\n EventMap extends DefaultEventMap,\n> extends Disposable {\n protected handlersController: HandlersController\n protected emitter: Emitter<EventMap>\n protected publicEmitter: Emitter<EventMap>\n\n public readonly events: LifeCycleEventEmitter<EventMap>\n\n constructor(...initialHandlers: Array<AnyHandler>) {\n super()\n\n this.handlersController = new InMemoryHandlersController(initialHandlers)\n\n this.emitter = new Emitter()\n this.publicEmitter = new Emitter()\n this.events = this.emitter\n\n this.subscriptions.push(() => {\n this.emitter.removeAllListeners()\n this.publicEmitter.removeAllListeners()\n })\n }\n\n public use(...runtimeHandlers: Array<AnyHandler>): void {\n this.handlersController.use(runtimeHandlers)\n }\n\n public restoreHandlers(): void {\n this.handlersController.
|
|
1
|
+
{"version":3,"sources":["../../../src/core/experimental/setup-api.ts"],"sourcesContent":["import { type DefaultEventMap, Emitter } from 'rettime'\nimport { type LifeCycleEventEmitter } from '../sharedOptions'\nimport type { HandlersController } from './handlers-controller'\nimport {\n InMemoryHandlersController,\n type AnyHandler,\n} from './handlers-controller'\nimport { Disposable } from '../utils/internal/Disposable'\nimport { toReadonlyArray } from '../utils/internal/toReadonlyArray'\n\n/**\n * Generic class for the mock API setup.\n * Preserved only for backward compatibility.\n * @deprecated\n */\nexport abstract class SetupApi<\n EventMap extends DefaultEventMap,\n> extends Disposable {\n protected handlersController: HandlersController\n protected emitter: Emitter<EventMap>\n protected publicEmitter: Emitter<EventMap>\n\n public readonly events: LifeCycleEventEmitter<EventMap>\n\n constructor(...initialHandlers: Array<AnyHandler>) {\n super()\n\n this.handlersController = new InMemoryHandlersController(initialHandlers)\n\n this.emitter = new Emitter()\n this.publicEmitter = new Emitter()\n this.events = this.emitter\n\n this.subscriptions.push(() => {\n this.emitter.removeAllListeners()\n this.publicEmitter.removeAllListeners()\n })\n }\n\n public use(...runtimeHandlers: Array<AnyHandler>): void {\n this.handlersController.use(runtimeHandlers)\n }\n\n public restoreHandlers(): void {\n this.handlersController.restore()\n }\n\n public resetHandlers(...nextHandlers: Array<AnyHandler>): void {\n this.handlersController.reset(nextHandlers)\n }\n\n public listHandlers(): ReadonlyArray<AnyHandler> {\n return toReadonlyArray(this.handlersController.currentHandlers())\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8C;AAC9C,2BAA2C;AAE3C,iCAGO;AACP,wBAA2B;AAC3B,6BAAgC;AAOzB,MAAe,iBAEZ,6BAAW;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EAEM;AAAA,EAEhB,eAAe,iBAAoC;AACjD,UAAM;AAEN,SAAK,qBAAqB,IAAI,sDAA2B,eAAe;AAExE,SAAK,UAAU,IAAI,uBAAQ;AAC3B,SAAK,gBAAgB,IAAI,uBAAQ;AACjC,SAAK,SAAS,KAAK;AAEnB,SAAK,cAAc,KAAK,MAAM;AAC5B,WAAK,QAAQ,mBAAmB;AAChC,WAAK,cAAc,mBAAmB;AAAA,IACxC,CAAC;AAAA,EACH;AAAA,EAEO,OAAO,iBAA0C;AACtD,SAAK,mBAAmB,IAAI,eAAe;AAAA,EAC7C;AAAA,EAEO,kBAAwB;AAC7B,SAAK,mBAAmB,QAAQ;AAAA,EAClC;AAAA,EAEO,iBAAiB,cAAuC;AAC7D,SAAK,mBAAmB,MAAM,YAAY;AAAA,EAC5C;AAAA,EAEO,eAA0C;AAC/C,eAAO,wCAAgB,KAAK,mBAAmB,gBAAgB,CAAC;AAAA,EAClE;AACF;","names":[]}
|
|
@@ -25,11 +25,7 @@ class SetupApi extends Disposable {
|
|
|
25
25
|
this.handlersController.use(runtimeHandlers);
|
|
26
26
|
}
|
|
27
27
|
restoreHandlers() {
|
|
28
|
-
this.handlersController.
|
|
29
|
-
if ("isUsed" in handler) {
|
|
30
|
-
handler.isUsed = false;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
28
|
+
this.handlersController.restore();
|
|
33
29
|
}
|
|
34
30
|
resetHandlers(...nextHandlers) {
|
|
35
31
|
this.handlersController.reset(nextHandlers);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/experimental/setup-api.ts"],"sourcesContent":["import { type DefaultEventMap, Emitter } from 'rettime'\nimport { type LifeCycleEventEmitter } from '../sharedOptions'\nimport type { HandlersController } from './handlers-controller'\nimport {\n InMemoryHandlersController,\n type AnyHandler,\n} from './handlers-controller'\nimport { Disposable } from '../utils/internal/Disposable'\nimport { toReadonlyArray } from '../utils/internal/toReadonlyArray'\n\n/**\n * Generic class for the mock API setup.\n * Preserved only for backward compatibility.\n * @deprecated\n */\nexport abstract class SetupApi<\n EventMap extends DefaultEventMap,\n> extends Disposable {\n protected handlersController: HandlersController\n protected emitter: Emitter<EventMap>\n protected publicEmitter: Emitter<EventMap>\n\n public readonly events: LifeCycleEventEmitter<EventMap>\n\n constructor(...initialHandlers: Array<AnyHandler>) {\n super()\n\n this.handlersController = new InMemoryHandlersController(initialHandlers)\n\n this.emitter = new Emitter()\n this.publicEmitter = new Emitter()\n this.events = this.emitter\n\n this.subscriptions.push(() => {\n this.emitter.removeAllListeners()\n this.publicEmitter.removeAllListeners()\n })\n }\n\n public use(...runtimeHandlers: Array<AnyHandler>): void {\n this.handlersController.use(runtimeHandlers)\n }\n\n public restoreHandlers(): void {\n this.handlersController.
|
|
1
|
+
{"version":3,"sources":["../../../src/core/experimental/setup-api.ts"],"sourcesContent":["import { type DefaultEventMap, Emitter } from 'rettime'\nimport { type LifeCycleEventEmitter } from '../sharedOptions'\nimport type { HandlersController } from './handlers-controller'\nimport {\n InMemoryHandlersController,\n type AnyHandler,\n} from './handlers-controller'\nimport { Disposable } from '../utils/internal/Disposable'\nimport { toReadonlyArray } from '../utils/internal/toReadonlyArray'\n\n/**\n * Generic class for the mock API setup.\n * Preserved only for backward compatibility.\n * @deprecated\n */\nexport abstract class SetupApi<\n EventMap extends DefaultEventMap,\n> extends Disposable {\n protected handlersController: HandlersController\n protected emitter: Emitter<EventMap>\n protected publicEmitter: Emitter<EventMap>\n\n public readonly events: LifeCycleEventEmitter<EventMap>\n\n constructor(...initialHandlers: Array<AnyHandler>) {\n super()\n\n this.handlersController = new InMemoryHandlersController(initialHandlers)\n\n this.emitter = new Emitter()\n this.publicEmitter = new Emitter()\n this.events = this.emitter\n\n this.subscriptions.push(() => {\n this.emitter.removeAllListeners()\n this.publicEmitter.removeAllListeners()\n })\n }\n\n public use(...runtimeHandlers: Array<AnyHandler>): void {\n this.handlersController.use(runtimeHandlers)\n }\n\n public restoreHandlers(): void {\n this.handlersController.restore()\n }\n\n public resetHandlers(...nextHandlers: Array<AnyHandler>): void {\n this.handlersController.reset(nextHandlers)\n }\n\n public listHandlers(): ReadonlyArray<AnyHandler> {\n return toReadonlyArray(this.handlersController.currentHandlers())\n }\n}\n"],"mappings":"AAAA,SAA+B,eAAe;AAC9C,eAA2C;AAE3C;AAAA,EACE;AAAA,OAEK;AACP,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAOzB,MAAe,iBAEZ,WAAW;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EAEM;AAAA,EAEhB,eAAe,iBAAoC;AACjD,UAAM;AAEN,SAAK,qBAAqB,IAAI,2BAA2B,eAAe;AAExE,SAAK,UAAU,IAAI,QAAQ;AAC3B,SAAK,gBAAgB,IAAI,QAAQ;AACjC,SAAK,SAAS,KAAK;AAEnB,SAAK,cAAc,KAAK,MAAM;AAC5B,WAAK,QAAQ,mBAAmB;AAChC,WAAK,cAAc,mBAAmB;AAAA,IACxC,CAAC;AAAA,EACH;AAAA,EAEO,OAAO,iBAA0C;AACtD,SAAK,mBAAmB,IAAI,eAAe;AAAA,EAC7C;AAAA,EAEO,kBAAwB;AAC7B,SAAK,mBAAmB,QAAQ;AAAA,EAClC;AAAA,EAEO,iBAAiB,cAAuC;AAC7D,SAAK,mBAAmB,MAAM,YAAY;AAAA,EAC5C;AAAA,EAEO,eAA0C;AAC/C,WAAO,gBAAgB,KAAK,mBAAmB,gBAAgB,CAAC;AAAA,EAClE;AACF;","names":[]}
|
|
@@ -4,7 +4,7 @@ import { NetworkSource } from './network-source.mjs';
|
|
|
4
4
|
import 'rettime';
|
|
5
5
|
import '../../on-unhandled-frame-Cr1KOZ0I.mjs';
|
|
6
6
|
import '../handlers-controller.mjs';
|
|
7
|
-
import '../../HttpResponse-
|
|
7
|
+
import '../../HttpResponse-BMMzfpjG.mjs';
|
|
8
8
|
import '../../utils/internal/isIterable.mjs';
|
|
9
9
|
import '../../typeUtils.mjs';
|
|
10
10
|
import 'graphql';
|
|
@@ -4,7 +4,7 @@ import { NetworkSource } from './network-source.js';
|
|
|
4
4
|
import 'rettime';
|
|
5
5
|
import '../../on-unhandled-frame-BBR-P3kV.js';
|
|
6
6
|
import '../handlers-controller.js';
|
|
7
|
-
import '../../HttpResponse-
|
|
7
|
+
import '../../HttpResponse-DPDqE4Pb.js';
|
|
8
8
|
import '../../utils/internal/isIterable.js';
|
|
9
9
|
import '../../typeUtils.js';
|
|
10
10
|
import 'graphql';
|