UNPKG

@klogt/intercept

Version:

The lightweight HTTP interception library built for modern Node.js testing. MSW-inspired simplicity meets native `fetch` performance.

61 lines (59 loc) 2.14 kB
import { Adapter } from "../types-olThGpUT.js"; import * as axios0 from "axios"; //#region src/adapters/types.d.ts /** * A loose adapter function type so we can store either a real axios adapter * or our stub adapter without importing axios at runtime. */ type AnyAxiosAdapter = (config: any) => Promise<any>; /** * A structural instance type that both a real AxiosInstance and our stub match. * We only read/write `defaults.adapter` and read `defaults.baseURL`. */ interface CompatibleAxiosInstance { defaults: { adapter?: AnyAxiosAdapter | null; baseURL?: string; }; interceptors: { request: { use: (onFulfilled: (config: any) => any, onRejected?: (error: any) => any) => number; eject: (id: number) => void; }; response: { use: (onFulfilled: (response: any) => any, onRejected?: (error: any) => any) => number; eject: (id: number) => void; }; }; } /** * Union that accepts either our compatible shape or a real axios instance, * without creating a runtime dependency on axios. The conditional `import()` * is erased at compile-time if axios types are not present. */ type AxiosLikeInstance = CompatibleAxiosInstance | axios0.AxiosInstance; /** * Type guard to check if a value is an axios-like instance. * Checks for the minimal structure needed for our adapter. */ //#endregion //#region src/adapters/axios.d.ts /** * Axios adapter using direct adapter override. * * Works with real axios instances by completely replacing the native transport * adapter (http/https in Node, XHR in browsers) with our own implementation. * * Behavior for unhandled requests: * - "warn": log and pass through to original axios transport * - "bypass": silently pass through to original axios transport * - "error": reject with a 501-like AxiosError * * Type compatibility: * - Accepts both a minimal, stubbed instance (our types) and a real * `axios.AxiosInstance` without adding a runtime dependency on axios. */ declare function createAxiosAdapter(instance: AxiosLikeInstance): Adapter; //#endregion export { createAxiosAdapter }; //# sourceMappingURL=axios.d.ts.map