1 | import { RouteMatcherFunction, RouteMatcherUrl, MatcherDefinition } from './Matchers.js';
|
2 | import type { FetchMockGlobalConfig, FetchImplementations } from './FetchMock.js';
|
3 | import type { CallLog } from './CallHistory.js';
|
4 | export type UserRouteSpecificConfig = {
|
5 | name?: RouteName;
|
6 | method?: string;
|
7 | headers?: {
|
8 | [key: string]: string | number;
|
9 | };
|
10 | missingHeaders?: string[];
|
11 | query?: {
|
12 | [key: string]: string;
|
13 | };
|
14 | params?: {
|
15 | [key: string]: string;
|
16 | };
|
17 | body?: object;
|
18 | matcherFunction?: RouteMatcherFunction;
|
19 | url?: RouteMatcherUrl;
|
20 | response?: RouteResponse | RouteResponseFunction;
|
21 | repeat?: number;
|
22 | delay?: number;
|
23 | sticky?: boolean;
|
24 | };
|
25 | export type InternalRouteConfig = {
|
26 | usesBody?: boolean;
|
27 | isFallback?: boolean;
|
28 | };
|
29 | export type UserRouteConfig = UserRouteSpecificConfig & FetchMockGlobalConfig;
|
30 | type Nullable<T> = {
|
31 | [K in keyof T]: T[K] | null;
|
32 | };
|
33 | export type ModifyRouteConfig = Omit<Nullable<UserRouteSpecificConfig>, 'name' | 'sticky'>;
|
34 | export type RouteConfig = UserRouteConfig & FetchImplementations & InternalRouteConfig;
|
35 | export type RouteResponseConfig = {
|
36 | body?: BodyInit | object;
|
37 | status?: number;
|
38 | headers?: {
|
39 | [key: string]: string;
|
40 | };
|
41 | throws?: Error;
|
42 | redirectUrl?: string;
|
43 | options?: ResponseInit;
|
44 | };
|
45 | export type ResponseInitUsingHeaders = {
|
46 | status: number;
|
47 | statusText: string;
|
48 | headers: Headers;
|
49 | };
|
50 | export type RouteResponseObjectData = RouteResponseConfig | object;
|
51 | export type RouteResponseData = Response | number | string | RouteResponseObjectData;
|
52 | export type RouteResponsePromise = Promise<RouteResponseData>;
|
53 | export type RouteResponseFunction = (arg0: CallLog) => RouteResponseData | RouteResponsePromise;
|
54 | export type RouteResponse = RouteResponseData | RouteResponsePromise | RouteResponseFunction;
|
55 | export type RouteName = string;
|
56 | declare class Route {
|
57 | #private;
|
58 | config: RouteConfig;
|
59 | matcher: RouteMatcherFunction;
|
60 | constructor(config: RouteConfig);
|
61 | init(config: RouteConfig | ModifyRouteConfig): void;
|
62 | reset(): void;
|
63 | constructResponse(responseInput: RouteResponseConfig): {
|
64 | response: Response;
|
65 | responseOptions: ResponseInit;
|
66 | responseInput: RouteResponseConfig;
|
67 | };
|
68 | constructResponseOptions(responseInput: RouteResponseConfig): ResponseInitUsingHeaders;
|
69 | constructResponseBody(responseInput: RouteResponseConfig, responseOptions: ResponseInitUsingHeaders): BodyInit;
|
70 | static defineMatcher(matcher: MatcherDefinition): void;
|
71 | static registeredMatchers: MatcherDefinition[];
|
72 | }
|
73 | export default Route;
|