declare module 'redux-query' { import { Action, AnyAction, Middleware, Reducer, Store } from 'redux'; export type CredentialOption = 'include' | 'same-origin' | 'omit'; export type Url = string; export type RequestBody = any; export type RequestHeader = string; export interface RequestHeaders { [key: string]: RequestHeader; } export type MetaValue = any; export interface Meta { [key: string]: MetaValue; } export type QueryKey = string; export type ResponseBody = any; export type ResponseText = string; export type ResponseHeader = string; export interface ResponseHeaders { [key: string]: ResponseHeader; } export type ResponseStatus = number; export type Duration = number; export interface Entities { [key: string]: any; } export type EntitiesState = Entities; export type KnownHttpMethods = 'GET' | 'HEAD' | 'PUT' | 'POST' | 'DELETE' | 'PATCH' | 'OPTIONS'; export type HttpMethods = KnownHttpMethods | string; export const httpMethods: { [k in KnownHttpMethods]: KnownHttpMethods }; export type TransformStrategy = ( body: TBody, text: ResponseText, ) => Partial; export type UpdateStrategy = (prevValue: T, newValue: T) => T; export type OptimisticUpdateStrategy = (prevValue: T) => T; export type RollbackStrategy = (initialValue: T, currentValue: T) => T; export type Update = { [K in keyof TEntities]?: UpdateStrategy; }; export type OptimisticUpdate = { [K in keyof TEntities]?: OptimisticUpdateStrategy; }; export type Rollback = { [K in keyof TEntities]?: RollbackStrategy; }; export interface WithTime { time: number; } export interface WithQueryKey { queryKey: QueryKey; } export interface WithUpdateEntities { update: Update; } export type RequestAsyncAction = Action<'@@query/REQUEST_ASYNC'> & QueryConfig; export interface QueryStartParams { body?: RequestBody; meta?: Meta; queryKey: QueryKey; url: Url; } export interface WithOptimisticEntities { optimisticEntities: TEntities; } export type MutateStartParams = QueryStartParams; export type RequestStartAction = Action<'@@query/REQUEST_START'> & QueryStartParams; export interface QueryResponse { body: RequestBody; duration: Duration; entities: TEntities; meta?: Meta; responseBody?: ResponseBody; responseHeaders?: ResponseHeaders; responseText?: ResponseText; queryKey: QueryKey; status: ResponseStatus; url: Url; } export type RequestSuccessAction = Action<'@@query/REQUEST_SUCCESS'> & QueryResponse & WithTime; export type RequestFailureAction = Action<'@@query/REQUEST_FAILURE'> & QueryResponse & WithTime; export type MutateAsyncAction = Action<'@@query/MUTATE_ASYNC'> & QueryConfig; export type MutateSuccessAction = Action<'@@query/MUTATE_SUCCESS'> & QueryResponse; export type UpdateEntitiesAction = Action<'@@query/UPDATE_ENTITIES'> & WithUpdateEntities; export type CancelQueryAction = Action<'@@query/CANCEL_QUERY'> & WithQueryKey; export type ReduxQueryAction = | RequestAsyncAction | MutateAsyncAction | UpdateEntitiesAction | CancelQueryAction; export const requestAsync: ( params: QueryConfig, ) => RequestAsyncAction; export const mutateAsync: ( params: QueryConfig, ) => MutateAsyncAction; export const cancelQuery: (queryKey: QueryKey) => CancelQueryAction; export const updateEntities: ( update: Update, ) => UpdateEntitiesAction; export interface NetworkHandler { abort: () => void; execute: ( callback: ( error: any, status: ResponseStatus, responseBody?: ResponseBody, responseText?: ResponseText, responseHeaders?: ResponseHeaders, ) => void, ) => void; } export interface NetworkOptions { body?: RequestBody; headers?: RequestHeaders; credentials?: CredentialOption; } export type NetworkInterface = ( url: Url, method: HttpMethods, networkOptions: NetworkOptions, ) => NetworkHandler; export interface QueryOptions { credentials?: CredentialOption; method?: HttpMethods; headers?: { [key: string]: string }; } export type QueryDetails = { isFinished: boolean; isPending: boolean; status?: number; headers?: ResponseHeaders; lastUpdated?: number; queryCount: number; }; export type QueryMiddlewareConfig = { backoff: { maxAttempts: number; minDuration: number; maxDuration: number; }; retryableStatusCodes: Array; }; export interface QueryConfig { body?: RequestBody; force?: boolean; meta?: Meta; options?: QueryOptions; queryKey?: QueryKey; transform?: TransformStrategy; update?: Update; optimisticUpdate?: OptimisticUpdate; retry?: boolean; rollback?: Rollback; unstable_preDispatchCallback?: () => void; url: Url; customQueryMiddlewareConfig?: QueryMiddlewareConfig; } export interface QueriesState { [key: string]: { headers?: ResponseHeaders; isFinished: boolean; isMutation: boolean; isPending: boolean; lastUpdated?: number; queryCount: number; status?: ResponseStatus; url: Url; }; } export type QueriesSelector = (state: TState) => QueriesState; export type EntitiesSelector = ( state: TState, ) => TEntities; export type QueryKeyBuilder = ( queryConfig?: QueryConfig, ) => QueryKey | undefined; export interface QueryState { headers?: ResponseHeaders; isFinished: boolean; isPending: boolean; lastUpdated?: number; queryCount?: number; status?: ResponseStatus; } export interface ActionPromiseValue { body: ResponseBody; duration: Duration; entities?: TEntities; headers?: ResponseHeaders; status: ResponseStatus; text?: ResponseText; transformed?: TEntities; } export interface ErrorsState { [key: string]: { responseBody?: ResponseBody; responseHeaders?: ResponseHeaders; responseText?: ResponseText; }; } export interface Config { backoff: { maxAttempts: number; minDuration: number; maxDuration: number; }; retryableStatusCodes: ResponseStatus[]; } export type QueriesReducer = Reducer< QueriesState, ReduxQueryAction >; export type EntitiesReducer = Reducer< TEntities, ReduxQueryAction >; export type ErrorsReducer = Reducer< ErrorsState, ReduxQueryAction >; export type QueryMiddlewareFactory = ( networkInterface: NetworkInterface, queriesSelector: QueriesSelector, entitiesSelector: EntitiesSelector, customConfig?: Config, ) => Middleware, any, ReduxQueryDispatch>; export const getQueryKey: QueryKeyBuilder; export const queriesReducer: QueriesReducer; export const entitiesReducer: EntitiesReducer; export const errorsReducer: ErrorsReducer; export const querySelectors: { getQueryDetails: (queriesState: QueriesState, queryConfig: QueryConfig) => QueryDetails; isFinished: (queriesState: QueriesState, queryConfig: QueryConfig) => boolean; isPending: (queriesState: QueriesState, queryConfig: QueryConfig) => boolean; status: ( queriesState: QueriesState, queryConfig: QueryConfig, ) => ResponseStatus | undefined; headers: ( queriesState: QueriesState, queryConfig: QueryConfig, ) => ResponseHeaders | undefined; lastUpdated: (queriesState: QueriesState, queryConfig: QueryConfig) => number | undefined; queryCount: (queriesState: QueriesState, queryConfig: QueryConfig) => number; }; export const errorSelectors: { responseBody: (errorsState: ErrorsState, queryConfig: QueryConfig) => ResponseBody; responseText: (errorsState: ErrorsState, queryConfig: QueryConfig) => ResponseText; responseHeaders: (errorsState: ErrorsState, queryConfig: QueryConfig) => ResponseHeaders; }; export const actionTypes: { REQUEST_ASYNC: string; REQUEST_START: string; REQUEST_SUCCESS: string; REQUEST_FAILURE: string; CANCEL_QUERY: string; MUTATE_ASYNC: string; MUTATE_START: string; MUTATE_SUCCESS: string; MUTATE_FAILURE: string; RESET: string; UPDATE_ENTITIES: string; }; export const queryMiddleware: QueryMiddlewareFactory; export interface ReduxQueryDispatch< TEntities = Entities, A extends AnyAction = ReduxQueryAction > { >(action: ReduxQueryAction): Promise< ActionPromiseValue >; (action: T): T; } }