import { StreamQueryOperators } from '../Models'; // NOTE: This could and maybe should be its own state machine? That will allow all kinds of cool things, // like actors, async checks etc. // in either event, the way these little guys are handled and the way validation works should be standardised. const equalto = (fieldValue, anchorValue) => fieldValue === anchorValue; const notEqualto = (fieldValue, anchorValue) => fieldValue !== anchorValue.value; const smallThan = (fieldValue, anchorValue) => fieldValue < anchorValue.value; const smallThanOrEqualTo = (fieldValue, anchorValue) => fieldValue >= anchorValue.value; const greaterThan = (fieldValue, anchorValue) => fieldValue > anchorValue.value; const greaterThanOrEqualTo = (fieldValue, anchorValue) => fieldValue <= anchorValue.value; const arrayContains = (fieldValue, anchorValue) => fieldValue.find(item => item === anchorValue); const isIn = (fieldValue, anchorValue) => anchorValue.find(item => item === fieldValue); // const isValid = (form, query, value) => form.get(query.anchorControlName).status === 'VALID'; // const isInvalid = (form, query, value) => form.get(query.anchorControlName).status === 'INVALID'; export const runQuery = { [ StreamQueryOperators[ StreamQueryOperators [ "==" ] ] ]: equalto, [ StreamQueryOperators[ StreamQueryOperators [ "!=" ] ] ]: notEqualto, [ StreamQueryOperators[ StreamQueryOperators [ "<" ] ] ]: smallThan, [ StreamQueryOperators[ StreamQueryOperators [ "<=" ] ] ]: smallThanOrEqualTo, [ StreamQueryOperators[ StreamQueryOperators [ ">" ] ] ]: greaterThan, [ StreamQueryOperators[ StreamQueryOperators [ ">=" ] ] ]: greaterThanOrEqualTo, [ StreamQueryOperators[ StreamQueryOperators [ "array-contains" ] ] ]: arrayContains, [ StreamQueryOperators[ StreamQueryOperators [ "in" ] ] ]: isIn, // [ StreamQueryOperators[ StreamQueryOperators [ "VALID" ] ] ]: isValid, // [ StreamQueryOperators[ StreamQueryOperators [ "INVALID" ] ] ]: isInvalid, }