import _difference from 'lodash/difference' import { ActionType } from '../actions/types' import { selectNormalizedActionRelationsSequence } from '../selectors' import { RootState } from '../store' export const atleastOneSourceAndActionRule = (state: RootState) => { const types = state.actions.map(({ type }) => type) const sources = types.filter(type => type === ActionType.SOURCE) const actions = types.filter(type => type === ActionType.ACTION) if (sources.length === 0) { throw new Error('At least one source is required') } if (actions.length === 0) { throw new Error('At least one action is required') } if (sources.length > 1) { throw new Error('Only one source is required') } return true } export const noMissedActionRelationsRule = (state: RootState) => { const relations = selectNormalizedActionRelationsSequence()(state) const missed = _difference(state.relations, relations) if (missed.length > 0) { throw new Error('No missed relations allowed') } return true } export const noCircularActionRelationsRule = (state: RootState) => { // TODO: Implement return !state }