import type { Middleware , AnyAction } from 'redux' ; import type { ThunkMiddleware } from 'redux-thunk' ; import thunkMiddleware from 'redux-thunk' ; import type { ImmutableStateInvariantMiddlewareOptions } from './immutableStateInvariantMiddleware' ; import { createImmutableStateInvariantMiddleware } from './immutableStateInvariantMiddleware' ; import type { SerializableStateInvariantMiddlewareOptions } from './serializableStateInvariantMiddleware' ; import { createSerializableStateInvariantMiddleware } from './serializableStateInvariantMiddleware' ; import { MiddlewareArray } from './utils' ; function isBoolean ( x ) { return typeof x === 'boolean' ; } interface ThunkOptions < E = any > { extraArgument : E ; } interface GetDefaultMiddlewareOptions { thunk ? : boolean | ThunkOptions ; immutableCheck ? : boolean | ImmutableStateInvariantMiddlewareOptions ; serializableCheck ? : boolean | SerializableStateInvariantMiddlewareOptions ; } export type ThunkMiddlewareFor < S , O extends GetDefaultMiddlewareOptions = { } > = O extends { thunk : false ; } ? never : O extends { thunk : { extraArgument : infer E ; } ; } ? ThunkMiddleware < S , AnyAction , E > : ThunkMiddleware < S , AnyAction , null > | ThunkMiddleware < S , AnyAction > ; export type CurriedGetDefaultMiddleware < S = any > = < O extends Partial < GetDefaultMiddlewareOptions > = { thunk : true ; immutableCheck : true ; serializableCheck : true ; } > ( options ? : O ) => MiddlewareArray < Middleware < { } , S > | ThunkMiddlewareFor < S , O > > ; export function curryGetDefaultMiddleware < S = any > ( ) { return function curriedGetDefaultMiddleware ( options ) { return getDefaultMiddleware ( options ) ; } ; } return public deprecated export function getDefaultMiddleware < S = any , O extends Partial < GetDefaultMiddlewareOptions > = { thunk : true ; immutableCheck : true ; serializableCheck : true ; } > ( options = { } as O ) { const { thunk = true , immutableCheck = true , serializableCheck = true , } = options ; let middlewareArray = new MiddlewareArray ( ) ; if ( thunk ) { if ( isBoolean ( thunk ) ) { middlewareArray . push ( thunkMiddleware ) ; } else { middlewareArray . push ( thunkMiddleware . withExtraArgument ( thunk . extraArgument ) ) ; } } if ( process . env . NODE_ENV !== 'production' ) { if ( immutableCheck ) { let immutableOptions = { } ; if ( ! isBoolean ( immutableCheck ) ) { immutableOptions = immutableCheck ; } middlewareArray . unshift ( createImmutableStateInvariantMiddleware ( immutableOptions ) ) ; } if ( serializableCheck ) { let serializableOptions = { } ; if ( ! isBoolean ( serializableCheck ) ) { serializableOptions = serializableCheck ; } middlewareArray . push ( createSerializableStateInvariantMiddleware ( serializableOptions ) ) ; } } return middlewareArray as any ; }