module Data.JLD.Model.GraphObject (isGraphObject, isNotGraphObject, toGraphObject) where import Data.JLD.Prelude import Data.JLD.Model.Keyword (Keyword (..), isKeyword) import Data.Aeson (Object, Value (..)) import Data.Aeson.Key qualified as K (toText) import Data.Aeson.KeyMap qualified as KM (keys, singleton, member) import Data.Vector qualified as V (singleton) isGraphObject :: Value -> Bool isGraphObject (Object o) | KM.member (show KeywordGraph) o = all (`isKeyword` [KeywordGraph, KeywordId, KeywordIndex, KeywordContext]) (K.toText <$> KM.keys o) isGraphObject _ = False isNotGraphObject :: Value -> Bool isNotGraphObject = isGraphObject .> not toGraphObject :: Value -> Object toGraphObject = V.singleton .> Array .> KM.singleton (show KeywordGraph)