import { Creator , createAction , ActionCreator } from '@ngrx/store' ; import { FunctionWithParametersType , TypedAction , NotAllowedCheck } from '@ngrx/store/src/models' ; export interface TypedActionWithCorrelation < T extends string > extends TypedAction < T > { __correlationId : string ; } export function createActionWithCorrelation < T extends string > ( type ) ; export function createActionWithCorrelation < T extends string , P extends object > ( type , config ) ; export function createActionWithCorrelation < T extends string , P extends any [ ] , R extends object > ( type , creator ) ; export function createActionWithCorrelation < T extends string , P extends any [ ] , R extends object > ( ... args ) { return correlateAction ( ( createAction as any ) ( ... args ) ) ; } export function correlateAction < T extends string > ( actionCreator ) ; export function correlateAction < T extends string , P extends object > ( actionCreator ) ; export function correlateAction < T extends string , P extends any [ ] , R extends object > ( actionCreator ) ; export function correlateAction < T extends string > ( actionCreator ) { const creator = function correlate ( ... args ) : TypedActionWithCorrelation < T > { const result = actionCreator ( ... args ) ; return { ... result , __correlationId : Date . now ( ) . toString ( ) } ; } ; defineType ( actionCreator . type , creator ) ; return creator ; } function defineType ( type , creator ) { return Object . defineProperty ( creator , 'type' , { value : type , writable : false , } ) ; }