import type { EndpointInterface, ResolveType } from '@rest-hooks/react'; type Updater = ( result: any, ...args: any ) => Record any>; export interface SuccessFixtureEndpoint< E extends EndpointInterface & { update?: Updater } = EndpointInterface, > { readonly endpoint: E; readonly args: Parameters; readonly response: | ResolveType | ((...args: Parameters) => ResolveType); readonly error?: false; /** Number of miliseconds to wait before resolving */ readonly delay?: number; /** Waits to run `response()` after `delay` time */ readonly delayCollapse?: boolean; } export interface ResponseInterceptor< T = any, E extends EndpointInterface & { update?: Updater; testKey(key: string): boolean; } = EndpointInterface & { testKey(key: string): boolean }, > { readonly endpoint: E; response(this: T, ...args: Parameters): ResolveType; /** Number of miliseconds (or function that returns) to wait before resolving */ readonly delay?: number | ((...args: Parameters) => number); /** Waits to run `response()` after `delay` time */ readonly delayCollapse?: boolean; } export interface FetchInterceptor< T = any, E extends EndpointInterface & { update?: Updater; testKey(key: string): boolean; fetchResponse(input: RequestInfo, init: RequestInit): Promise; extend(options: any): any; } = EndpointInterface & { testKey(key: string): boolean; fetchResponse(input: RequestInfo, init: RequestInit): Promise; extend(options: any): any; }, > { readonly endpoint: E; fetchResponse(this: T, input: RequestInfo, init: RequestInit): ResolveType; /** Number of miliseconds (or function that returns) to wait before resolving */ readonly delay?: number | ((...args: Parameters) => number); /** Waits to run `response()` after `delay` time */ readonly delayCollapse?: boolean; } /** Interceptors match and compute dynamic responses based on args * * @see https://resthooks.io/docs/api/Fixtures#interceptor */ export type Interceptor< T = any, E extends EndpointInterface & { update?: Updater; testKey(key: string): boolean; fetchResponse?(input: RequestInfo, init: RequestInit): Promise; extend?(options: any): any; } = EndpointInterface & { testKey(key: string): boolean; fetchResponse(input: RequestInfo, init: RequestInit): Promise; extend(options: any): any; }, > = | ResponseInterceptor | (E extends { fetchResponse(input: RequestInfo, init: RequestInit): Promise; extend(options: any): any; } ? FetchInterceptor : never); export interface ErrorFixtureEndpoint< E extends EndpointInterface & { update?: Updater } = EndpointInterface, > { readonly endpoint: E; readonly args: Parameters; readonly response: any; readonly error: true; /** Number of miliseconds to wait before resolving */ readonly delay?: number; /** Waits to run `response()` after `delay` time */ readonly delayCollapse?: boolean; } export type FixtureEndpoint< E extends EndpointInterface & { update?: Updater } = EndpointInterface, > = SuccessFixtureEndpoint | ErrorFixtureEndpoint; /** Represents a successful response * * @see https://resthooks.io/docs/api/Fixtures#successfixture */ export type SuccessFixture< E extends EndpointInterface & { update?: Updater } = EndpointInterface, > = SuccessFixtureEndpoint; /** Represents a failed/errored response * * @see https://resthooks.io/docs/api/Fixtures#errorfixtures */ export type ErrorFixture< E extends EndpointInterface & { update?: Updater } = EndpointInterface, > = ErrorFixtureEndpoint; /** Represents a static response * * @see https://resthooks.io/docs/api/Fixtures */ export type Fixture< E extends EndpointInterface & { update?: Updater } = EndpointInterface, > = FixtureEndpoint;