aboutsummaryrefslogtreecommitdiffstats
path: root/src/Data/JLD/Model/GraphObject.hs
blob: 3db9e6b07176859daffa8c5c03557516816cdcf6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)