UNPKG

1.44 kBTypeScriptView Raw
1import { Emitter } from 'strict-event-emitter';
2import { SharedOptions, LifeCycleEventsMap } from '../sharedOptions.js';
3import { RequiredDeep } from '../typeUtils.js';
4import { i as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-5Sn2vNaJ.js';
5import './request/onUnhandledRequest.js';
6import './internal/isIterable.js';
7
8interface HandleRequestOptions {
9 /**
10 * `resolutionContext` is not part of the general public api
11 * but is exposed to aid in creating extensions like
12 * `@mswjs/http-middleware`.
13 */
14 resolutionContext?: {
15 /**
16 * A base url to use when resolving relative urls.
17 * @note This is primarily used by the `@mswjs/http-middleware`
18 * to resolve relative urls in the context of the running server
19 */
20 baseUrl?: string;
21 };
22 /**
23 * Invoked whenever a request is performed as-is.
24 */
25 onPassthroughResponse?(request: Request): void;
26 /**
27 * Invoked when the mocked response is ready to be sent.
28 */
29 onMockedResponse?(response: Response, handler: RequiredDeep<HandlersExecutionResult>): void;
30}
31declare function handleRequest(request: Request, requestId: string, handlers: Array<RequestHandler>, options: RequiredDeep<SharedOptions>, emitter: Emitter<LifeCycleEventsMap>, handleRequestOptions?: HandleRequestOptions): Promise<Response | undefined>;
32
33export { type HandleRequestOptions, handleRequest };