import WebinyError from "@webiny/error" ; import { Condition } from "../types" ; import betweenCondition from "./between" ; import containsCondition from "./contains" ; import eqCondition from "./eq" ; import gtCondition from "./gt" ; import gteCondition from "./gte" ; import ltCondition from "./lt" ; import lteCondition from "./lte" ; import inCondition from "./in" ; class ConditionContainer { private readonly _items : Map < string , Condition > = new Map ( ) ; public register ( item , withNegate ? ) { this . _items . set ( item . key , item ) ; if ( ! withNegate ) { return ; } const key = `not_${ item . key }` ; this . _items . set ( key , { ... item , key , negate : true } ) ; } public unregister ( item ) { const key = typeof item === "string" ? item : item . key ; this . _items . delete ( key ) ; this . _items . delete ( `not_${ key }` ) ; } public clear ( ) { this . _items . clear ( ) ; } public all ( ) { return Array . from ( this . _items . values ( ) ) ; } public get ( key ) { if ( ! this . _items . has ( key ) ) { throw new WebinyError ( `Unknown condition "${ key }".` , "CONDITION_CONTAINER_ERROR" , { key } ) ; } return this . _items . get ( key ) ; } } const conditions = new ConditionContainer ( ) ; conditions . register ( eqCondition , true ) ; conditions . register ( gtCondition , true ) ; conditions . register ( gteCondition , true ) ; conditions . register ( ltCondition , true ) ; conditions . register ( lteCondition , true ) ; conditions . register ( inCondition , true ) ; conditions . register ( containsCondition , true ) ; conditions . register ( betweenCondition , true ) ; export default conditions ;