aboutsummaryrefslogtreecommitdiffstats
path: root/src/Data/JLD/Model/GraphObject.hs
blob: 4d7d3ad82f7759531c53c29e796e4be488137101 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Data.JLD.Model.GraphObject (isGraphObject, isGraphObject', isNotGraphObject, 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, member, singleton)

isGraphObject :: Value -> Bool
isGraphObject (Object o) = isGraphObject' o
isGraphObject _ = False

isGraphObject' :: Object -> Bool
isGraphObject' o =
    KM.member (show KeywordGraph) o
        && all (`isKeyword` [KeywordGraph, KeywordId, KeywordIndex, KeywordContext]) (K.toText <$> KM.keys o)

isNotGraphObject :: Value -> Bool
isNotGraphObject = isGraphObject .> not

isNotGraphObject' :: Object -> Bool
isNotGraphObject' = isGraphObject' .> not

toGraphObject :: Value -> Object
toGraphObject = pure .> Array .> KM.singleton (show KeywordGraph)