import type { StoreAction } from './types' ; import { setGlobalConfig , ConflictPolicy } from './index' ; import { AdvancedSynchAction , AsynchActionPromiseGet , StateDecoratorAction , StateDecoratorActions , StateDecoratorOptions , AsynchActionPromise , SynchAction , LoadingMap , LoadingProps , LoadingMapParallelActions , AsynchAction , } from './v5_types' ; import { isSimpleSyncAction as isV6SyncAction , isSyncAction as isV6AdvancedAction , isAsyncAction as isV6AsyncAction , isAsyncGetPromiseAction as isV6AsyncGetPromiseAction , isAsyncGetPromiseGetAction as isV6AsyncGetPromiseGetAction , } from './impl' ; export { AdvancedSynchAction , AsynchActionPromiseGet , StateDecoratorAction , StateDecoratorActions , StateDecoratorOptions , AsynchActionPromise , SynchAction , LoadingMap , LoadingMapParallelActions , LoadingProps , ConflictPolicy , setGlobalConfig , } ; /**
 * Type guard function to test if an action is a asynchronous action.
 */ export function isAsyncAction < S , F extends ( ... args : any [ ] ) => any , A , P > ( action ) { return ! ( action instanceof Function ) && ( action . hasOwnProperty ( 'promise' ) || action . hasOwnProperty ( 'promiseGet' ) ) ; } /**
 * Type guard function to test if an action is a asynchronous action.
 */ export function isAsyncPromiseGetAction < S , F extends ( ... args : any [ ] ) => any , A , P > ( action ) { return ! ( action instanceof Function ) && ! ( action . hasOwnProperty ( 'promise' ) && action . hasOwnProperty ( 'promiseGet' ) ) ; } /**
 * Type guard function to test if an action is a synchronous action.
 */ export function isSyncAction < S , F extends ( ... args : any [ ] ) => any , A , P > ( action ) { return action instanceof Function ; } /**
 * Type guard function to test if an action is a synchronous action.
 */ export function isAdvancedSyncAction < S , F extends ( ... args : any [ ] ) => any , A , P > ( action ) { return ! ( action instanceof Function ) && ! action . hasOwnProperty ( 'promise' ) && ! action . hasOwnProperty ( 'promiseGet' ) ; } private function computeAsyncActionInput < S , F extends ( ... args : any [ ] ) => any , A , P > ( action ) { if ( 'promiseGet' in action ) { return { ... action , promise : action . promiseGet , retryCount : 3 , conflictPolicy : ConflictPolicy . REUSE , } ; } return action ; } param action param test export function testAsyncAction < S , F extends ( ... args : any [ ] ) => any , A , P > ( action , test ) { if ( isAsyncAction ( action ) ) { return test ( computeAsyncActionInput ( action ) ) ; } return Promise . reject ( new Error ( 'This action is not an asynchronous action' ) ) ; } param action param test export function testSyncAction < S , F extends ( ... args : any [ ] ) => any , A , P > ( action , test ) { if ( isSyncAction ( action ) ) { return test ( action ) ; } return Promise . reject ( new Error ( 'This action is not a synchronous action' ) ) ; } param action param test export function testAdvancedSyncAction < S , F extends ( ... args : any [ ] ) => any , A , P > ( action , test ) { if ( isAdvancedSyncAction ( action ) ) { return test ( action ) ; } return Promise . reject ( new Error ( 'This action is not a synchronous advanced action' ) ) ; } param action param test export function testV6SyncAction < S , F extends ( ... args : any [ ] ) => any , A , P > ( action , test ) { if ( isV6SyncAction ( action ) ) { const decoratedAction = ( s , args , p ) => action ( { s , args , p , ds : null , derived : null , state : s , props : p , promiseId : null , } ) ; test ( decoratedAction ) ; return Promise . resolve ( ) ; } return Promise . reject ( new Error ( 'This action is not a synchronous action' ) ) ; } param actionIn param test export function testV6AdvancedSyncAction < S , F extends ( ... args : any [ ] ) => any , A , P > ( actionIn , test ) { if ( isV6AdvancedAction ( actionIn ) ) { const decoratedAction = { action : ( s , args , p ) => actionIn . effects ( { s , args , p , ds : null , derived : null , state : s , props : p , res : null , result : null , promiseId : null , } ) , onActionDone : ( s , args , p , a , notifyWarning ) => { actionIn . sideEffects ( { s , args , p , a , notifyWarning , ds : null , derived : null , state : s , props : p , actions : a , res : null , result : null , promiseId : null , } ) ; } , } ; test ( decoratedAction ) ; return Promise . resolve ( ) ; } return Promise . reject ( new Error ( 'This action is not a synchronous action' ) ) ; } param actionIn param test export function testV6AsyncAction < S , F extends ( ... args : any [ ] ) => any , A , P > ( actionIn , test ) { if ( isV6AsyncAction ( actionIn ) ) { const decoratedAction = { abortable : actionIn . abortable , rejectPromiseOnError : actionIn . rejectPromiseOnError , retryCount : actionIn . retryCount , retryDelaySeed : actionIn . retryDelaySeed , isTriggerRetryError : actionIn . isTriggerRetryError , conflictPolicy : actionIn . conflictPolicy , getPromiseId : actionIn . getPromiseId , promise : ( args , s , p , a , abortSignal ) => { if ( isV6AsyncGetPromiseAction ( actionIn ) ) { return actionIn . getPromise ( { s , args , p , a , abortSignal , ds : null , derived : null , state : s , props : p , actions : a , promiseId : null , } ) ; } return actionIn . getGetPromise ( { s , args , p , a , abortSignal , ds : null , derived : null , state : s , props : p , actions : a , promiseId : null , } ) ; } , promiseGet : ( args , s , p , a , abortSignal ) => { if ( isV6AsyncGetPromiseGetAction ( actionIn ) ) { return actionIn . getGetPromise ( { s , args , p , a , abortSignal , ds : null , derived : null , state : s , props : p , actions : a , promiseId : null , } ) ; } return null ; } , reducer : ( s , res , args , p ) => actionIn . effects ? actionIn . effects ( { s , args , p , res , ds : null , derived : null , state : s , props : p , result : res , promiseId : null , } ) : null , preReducer : ( s , args , p ) => actionIn . preEffects ? actionIn . preEffects ( { s , args , p , ds : null , derived : null , state : s , props : p , promiseId : null , } ) : null , optimisticReducer : ( s , args , p ) => actionIn . optimisticEffects ? actionIn . optimisticEffects ( { s , args , p , ds : null , derived : null , state : s , props : p , promiseId : actionIn . getPromiseId ?. ( ... args ) , } ) : null , errorReducer : ( s , err , args , p ) => actionIn . errorEffects ? actionIn . errorEffects ( { s , args , p , err , ds : null , derived : null , state : s , props : p , error : err , promiseId : actionIn . getPromiseId ?. ( ... args ) , } ) : null , onDone : ( s , res , args , p , a , notifyWarning ) => { actionIn . sideEffects ?. ( { s , args , p , a , res , notifyWarning , ds : null , derived : null , state : s , props : p , actions : a , result : res , promiseId : actionIn . getPromiseId ?. ( ... args ) , } ) ; } , onFail : ( s , err , args , p , a , notifyWarning ) => { actionIn . errorSideEffects ?. ( { s , args , p , a , err , notifyWarning , ds : null , derived : null , state : s , props : p , actions : a , error : err , promiseId : actionIn . getPromiseId ?. ( ... args ) , } ) ; } , getErrorMessage : ( err , args , p ) => actionIn . getErrorMessage ?. ( { err , p , args , ds : null , derived : null , state : null , s : null , error : err , props : p , promiseId : actionIn . getPromiseId ?. ( ... args ) , } ) , getSuccessMessage : ( res , args , p ) => actionIn . getSuccessMessage ?. ( { res , args , p , ds : null , derived : null , state : null , s : null , result : res , props : p , promiseId : actionIn . getPromiseId ?. ( ... args ) , } ) , } ; return test ( decoratedAction ) ; } return Promise . reject ( new Error ( 'This action is not a synchronous action' ) ) ; }