basant307/AI_Governance_Project
048
1import { PartialDeep } from 'type-fest';2import { RequestHandler } from "../core/handlers/RequestHandler";3import { WebSocketHandler } from "../core/handlers/WebSocketHandler";4import { SharedOptions, LifeCycleEventEmitter, LifeCycleEventsMap } from "../core/sharedOptions";5import { BatchInterceptor, Interceptor, HttpRequestEventMap } from '@mswjs/interceptors';6import { SetupApi } from "../core/SetupApi";7 8interface SetupServerCommon {9 /**10 * Starts requests interception based on the previously provided request handlers.11 *12 * @see {@link https://mswjs.io/docs/api/setup-server/listen `server.listen()` API reference}13 */14 listen(options?: PartialDeep<SharedOptions>): void;15 /**16 * Stops requests interception by restoring all augmented modules.17 *18 * @see {@link https://mswjs.io/docs/api/setup-server/close `server.close()` API reference}19 */20 close(): void;21 /**22 * Prepends given request handlers to the list of existing handlers.23 *24 * @see {@link https://mswjs.io/docs/api/setup-server/use `server.use()` API reference}25 */26 use(...handlers: Array<RequestHandler | WebSocketHandler>): void;27 /**28 * Marks all request handlers that respond using `res.once()` as unused.29 *30 * @see {@link https://mswjs.io/docs/api/setup-server/restore-handlers `server.restore-handlers()` API reference}31 */32 restoreHandlers(): void;33 /**34 * Resets request handlers to the initial list given to the `setupServer` call, or to the explicit next request handlers list, if given.35 *36 * @see {@link https://mswjs.io/docs/api/setup-server/reset-handlers `server.reset-handlers()` API reference}37 */38 resetHandlers(...nextHandlers: Array<RequestHandler | WebSocketHandler>): void;39 /**40 * Returns a readonly list of currently active request handlers.41 *42 * @see {@link https://mswjs.io/docs/api/setup-server/list-handlers `server.listHandlers()` API reference}43 */44 listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler>;45 /**46 * Life-cycle events.47 * Life-cycle events allow you to subscribe to the internal library events occurring during the request/response handling.48 *49 * @see {@link https://mswjs.io/docs/api/life-cycle-events Life-cycle Events API reference}50 */51 events: LifeCycleEventEmitter<LifeCycleEventsMap>;52}53interface SetupServer extends SetupServerCommon {54 /**55 * Wraps the given function in a boundary. Any changes to the56 * network behavior (e.g. adding runtime request handlers via57 * `server.use()`) will be scoped to this boundary only.58 * @param callback A function to run (e.g. a test)59 *60 * @see {@link https://mswjs.io/docs/api/setup-server/boundary `server.boundary()` API reference}61 */62 boundary<Args extends Array<any>, R>(callback: (...args: Args) => R): (...args: Args) => R;63}64 65declare class SetupServerCommonApi extends SetupApi<LifeCycleEventsMap> implements SetupServerCommon {66 protected readonly interceptor: BatchInterceptor<Array<Interceptor<HttpRequestEventMap>>, HttpRequestEventMap>;67 private resolvedOptions;68 constructor(interceptors: Array<Interceptor<HttpRequestEventMap>>, handlers: Array<RequestHandler | WebSocketHandler>);69 /**70 * Subscribe to all requests that are using the interceptor object71 */72 private init;73 listen(options?: Partial<SharedOptions>): void;74 close(): void;75}76 77declare class SetupServerApi extends SetupServerCommonApi implements SetupServer {78 constructor(handlers: Array<RequestHandler | WebSocketHandler>, interceptors?: Array<Interceptor<HttpRequestEventMap>>);79 boundary<Args extends Array<any>, R>(callback: (...args: Args) => R): (...args: Args) => R;80 close(): void;81}82 83/**84 * Sets up a requests interception in Node.js with the given request handlers.85 * @param {RequestHandler[]} handlers List of request handlers.86 *87 * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}88 */89declare const setupServer: (...handlers: Array<RequestHandler | WebSocketHandler>) => SetupServerApi;90 91export { type SetupServer, SetupServerApi, setupServer };92 