{-# LANGUAGE GeneralizedNewtypeDeriving, TypeFamilies, OverloadedStrings,
    FlexibleInstances, UndecidableInstances, NoMonomorphismRestriction, FlexibleContexts #-}
-- |
-- Module: NetSpider.Graph.Internal
-- Description: 
-- Maintainer: Toshio Ito <debug.ito@gmail.com>
--
-- __this module is internal. End-users should not use it.__
module NetSpider.Graph.Internal
       ( -- * EID
         EID,
         -- * VNode
         VNode,
         -- * VFoundNode
         VFoundNode,
         VFoundNodeData(..),
         NodeAttributes(..),
         keyTimestamp,
         gSetTimestamp,
         gVFoundNodeData,
         -- * EFinds
         EFinds,
         EFindsData(..),
         LinkAttributes(..),
         gSetLinkState,
         gFindsTarget,
         gEFindsData,
         -- * Reconstruction
         makeFoundNode,
         makeFoundLink
       ) where

import Control.Category ((<<<))
import Data.Aeson (ToJSON(..), FromJSON(..), Value(..))
import Data.Foldable (Foldable)
import Data.Greskell
  ( FromGraphSON(..),
    ElementData(..), Element(..), Vertex, Edge,
    ElementID,
    AVertexProperty, AVertex, AEdge,
    Walk, SideEffect, Transform, unsafeCastEnd,
    Binder, Parser, GValue,
    gIdentity, gProperty, gPropertyV, (=:), gProperties, gInV,
    newBind,
    Key, AsLabel, unKey,
    PMap, Multi, Single, lookupAs, PMapLookupException,
    pMapFromList, pMapToList, pMapToFail,
    gProject, gValueMap, gByL, gId, Keys(..)
  )
import Data.Greskell.NonEmptyLike (NonEmptyLike)
import Data.Greskell.Extra (writePMapProperties)
import Data.Int (Int64)
import Data.Text (Text, unpack, pack)
import Data.Time.LocalTime (TimeZone(..))

import NetSpider.Timestamp (Timestamp(..))
import NetSpider.Found
  ( LinkState, linkStateToText, linkStateFromText,
    FoundLink(..), FoundNode(..)
  )

-- | Generic element ID used in the graph DB.
type EID = ElementID


-- | The \"node\" vertex.
newtype VNode = VNode AVertex
              deriving (Int -> VNode -> ShowS
[VNode] -> ShowS
VNode -> String
(Int -> VNode -> ShowS)
-> (VNode -> String) -> ([VNode] -> ShowS) -> Show VNode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VNode] -> ShowS
$cshowList :: [VNode] -> ShowS
show :: VNode -> String
$cshow :: VNode -> String
showsPrec :: Int -> VNode -> ShowS
$cshowsPrec :: Int -> VNode -> ShowS
Show,VNode -> VNode -> Bool
(VNode -> VNode -> Bool) -> (VNode -> VNode -> Bool) -> Eq VNode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VNode -> VNode -> Bool
$c/= :: VNode -> VNode -> Bool
== :: VNode -> VNode -> Bool
$c== :: VNode -> VNode -> Bool
Eq,VNode -> Text
VNode -> ElementID VNode
(VNode -> ElementID VNode) -> (VNode -> Text) -> ElementData VNode
forall e. (e -> ElementID e) -> (e -> Text) -> ElementData e
elementLabel :: VNode -> Text
$celementLabel :: VNode -> Text
elementId :: VNode -> ElementID VNode
$celementId :: VNode -> ElementID VNode
ElementData,ElementData VNode
ElementData VNode -> Element VNode
forall e. ElementData e -> Element e
Element,Element VNode
Element VNode -> Vertex VNode
forall v. Element v -> Vertex v
Vertex,GValue -> Parser VNode
(GValue -> Parser VNode) -> FromGraphSON VNode
forall a. (GValue -> Parser a) -> FromGraphSON a
parseGraphSON :: GValue -> Parser VNode
$cparseGraphSON :: GValue -> Parser VNode
FromGraphSON)

type TsEpoch = Int64

keyTimestamp :: Key VFoundNode TsEpoch
keyTimestamp :: Key VFoundNode TsEpoch
keyTimestamp = Key VFoundNode TsEpoch
"@timestamp"

keyTzOffset :: Key (AVertexProperty TsEpoch) Int
keyTzOffset :: Key (AVertexProperty TsEpoch) Int
keyTzOffset = Key (AVertexProperty TsEpoch) Int
"@tz_offset_min"

keyTzSummerOnly :: Key (AVertexProperty TsEpoch) Bool
keyTzSummerOnly :: Key (AVertexProperty TsEpoch) Bool
keyTzSummerOnly = Key (AVertexProperty TsEpoch) Bool
"@tz_summer_only"

keyTzName :: Key (AVertexProperty TsEpoch) Text
keyTzName :: Key (AVertexProperty TsEpoch) Text
keyTzName = Key (AVertexProperty TsEpoch) Text
"@tz_name"
  
gSetTimestamp :: Timestamp -> Binder (Walk SideEffect VFoundNode VFoundNode)
gSetTimestamp :: Timestamp -> Binder (Walk SideEffect VFoundNode VFoundNode)
gSetTimestamp Timestamp
ts = do
  Greskell TsEpoch
var_epoch <- TsEpoch -> Binder (Greskell TsEpoch)
forall v. ToJSON v => v -> Binder (Greskell v)
newBind (TsEpoch -> Binder (Greskell TsEpoch))
-> TsEpoch -> Binder (Greskell TsEpoch)
forall a b. (a -> b) -> a -> b
$ Timestamp -> TsEpoch
epochTime Timestamp
ts
  [KeyValue (AVertexProperty TsEpoch)]
meta_props <- Maybe TimeZone -> Binder [KeyValue (AVertexProperty TsEpoch)]
makeMetaProps (Maybe TimeZone -> Binder [KeyValue (AVertexProperty TsEpoch)])
-> Maybe TimeZone -> Binder [KeyValue (AVertexProperty TsEpoch)]
forall a b. (a -> b) -> a -> b
$ Timestamp -> Maybe TimeZone
timeZone Timestamp
ts
  Walk SideEffect VFoundNode VFoundNode
-> Binder (Walk SideEffect VFoundNode VFoundNode)
forall (m :: * -> *) a. Monad m => a -> m a
return (Walk SideEffect VFoundNode VFoundNode
 -> Binder (Walk SideEffect VFoundNode VFoundNode))
-> Walk SideEffect VFoundNode VFoundNode
-> Binder (Walk SideEffect VFoundNode VFoundNode)
forall a b. (a -> b) -> a -> b
$ Maybe (Greskell Cardinality)
-> Key VFoundNode TsEpoch
-> Greskell TsEpoch
-> [KeyValue (AVertexProperty TsEpoch)]
-> Walk SideEffect VFoundNode VFoundNode
forall e (vp :: * -> *) v.
(Vertex e, vp ~ ElementProperty e, Property vp, Element (vp v)) =>
Maybe (Greskell Cardinality)
-> Key e v
-> Greskell v
-> [KeyValue (vp v)]
-> Walk SideEffect e e
gPropertyV Maybe (Greskell Cardinality)
forall a. Maybe a
Nothing Key VFoundNode TsEpoch
keyTimestamp Greskell TsEpoch
var_epoch [KeyValue (AVertexProperty TsEpoch)]
meta_props
  where
    makeMetaProps :: Maybe TimeZone -> Binder [KeyValue (AVertexProperty TsEpoch)]
makeMetaProps Maybe TimeZone
Nothing = [KeyValue (AVertexProperty TsEpoch)]
-> Binder [KeyValue (AVertexProperty TsEpoch)]
forall (m :: * -> *) a. Monad m => a -> m a
return []
    makeMetaProps (Just TimeZone
tz) = do
      Greskell Int
offset <- Int -> Binder (Greskell Int)
forall v. ToJSON v => v -> Binder (Greskell v)
newBind (Int -> Binder (Greskell Int)) -> Int -> Binder (Greskell Int)
forall a b. (a -> b) -> a -> b
$ TimeZone -> Int
timeZoneMinutes TimeZone
tz
      Greskell Bool
summer <- Bool -> Binder (Greskell Bool)
forall v. ToJSON v => v -> Binder (Greskell v)
newBind (Bool -> Binder (Greskell Bool)) -> Bool -> Binder (Greskell Bool)
forall a b. (a -> b) -> a -> b
$ TimeZone -> Bool
timeZoneSummerOnly TimeZone
tz
      Greskell Text
name <- Text -> Binder (Greskell Text)
forall v. ToJSON v => v -> Binder (Greskell v)
newBind (Text -> Binder (Greskell Text)) -> Text -> Binder (Greskell Text)
forall a b. (a -> b) -> a -> b
$ String -> Text
pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ TimeZone -> String
timeZoneName TimeZone
tz
      [KeyValue (AVertexProperty TsEpoch)]
-> Binder [KeyValue (AVertexProperty TsEpoch)]
forall (m :: * -> *) a. Monad m => a -> m a
return ([KeyValue (AVertexProperty TsEpoch)]
 -> Binder [KeyValue (AVertexProperty TsEpoch)])
-> [KeyValue (AVertexProperty TsEpoch)]
-> Binder [KeyValue (AVertexProperty TsEpoch)]
forall a b. (a -> b) -> a -> b
$ [ Key (AVertexProperty TsEpoch) Int
keyTzOffset Key (AVertexProperty TsEpoch) Int
-> Greskell Int -> KeyValue (AVertexProperty TsEpoch)
forall a b. Key a b -> Greskell b -> KeyValue a
=: Greskell Int
offset,
                 Key (AVertexProperty TsEpoch) Bool
keyTzSummerOnly Key (AVertexProperty TsEpoch) Bool
-> Greskell Bool -> KeyValue (AVertexProperty TsEpoch)
forall a b. Key a b -> Greskell b -> KeyValue a
=: Greskell Bool
summer,
                 Key (AVertexProperty TsEpoch) Text
keyTzName Key (AVertexProperty TsEpoch) Text
-> Greskell Text -> KeyValue (AVertexProperty TsEpoch)
forall a b. Key a b -> Greskell b -> KeyValue a
=: Greskell Text
name
               ]

-- | The \"found_node\" vertex.
newtype VFoundNode = VFoundNode AVertex
                   deriving (Int -> VFoundNode -> ShowS
[VFoundNode] -> ShowS
VFoundNode -> String
(Int -> VFoundNode -> ShowS)
-> (VFoundNode -> String)
-> ([VFoundNode] -> ShowS)
-> Show VFoundNode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VFoundNode] -> ShowS
$cshowList :: [VFoundNode] -> ShowS
show :: VFoundNode -> String
$cshow :: VFoundNode -> String
showsPrec :: Int -> VFoundNode -> ShowS
$cshowsPrec :: Int -> VFoundNode -> ShowS
Show,VFoundNode -> VFoundNode -> Bool
(VFoundNode -> VFoundNode -> Bool)
-> (VFoundNode -> VFoundNode -> Bool) -> Eq VFoundNode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VFoundNode -> VFoundNode -> Bool
$c/= :: VFoundNode -> VFoundNode -> Bool
== :: VFoundNode -> VFoundNode -> Bool
$c== :: VFoundNode -> VFoundNode -> Bool
Eq,VFoundNode -> Text
VFoundNode -> ElementID VFoundNode
(VFoundNode -> ElementID VFoundNode)
-> (VFoundNode -> Text) -> ElementData VFoundNode
forall e. (e -> ElementID e) -> (e -> Text) -> ElementData e
elementLabel :: VFoundNode -> Text
$celementLabel :: VFoundNode -> Text
elementId :: VFoundNode -> ElementID VFoundNode
$celementId :: VFoundNode -> ElementID VFoundNode
ElementData,ElementData VFoundNode
ElementData VFoundNode -> Element VFoundNode
forall e. ElementData e -> Element e
Element,Element VFoundNode
Element VFoundNode -> Vertex VFoundNode
forall v. Element v -> Vertex v
Vertex,GValue -> Parser VFoundNode
(GValue -> Parser VFoundNode) -> FromGraphSON VFoundNode
forall a. (GValue -> Parser a) -> FromGraphSON a
parseGraphSON :: GValue -> Parser VFoundNode
$cparseGraphSON :: GValue -> Parser VFoundNode
FromGraphSON)

-- | Properties of the \"found_node\" vertex.
data VFoundNodeData na =
  VFoundNodeData
  { VFoundNodeData na -> ElementID VFoundNode
vfnId :: EID VFoundNode,
    VFoundNodeData na -> Timestamp
vfnTimestamp :: Timestamp,
    VFoundNodeData na -> na
vfnAttributes :: na
  }
  deriving (Int -> VFoundNodeData na -> ShowS
[VFoundNodeData na] -> ShowS
VFoundNodeData na -> String
(Int -> VFoundNodeData na -> ShowS)
-> (VFoundNodeData na -> String)
-> ([VFoundNodeData na] -> ShowS)
-> Show (VFoundNodeData na)
forall na. Show na => Int -> VFoundNodeData na -> ShowS
forall na. Show na => [VFoundNodeData na] -> ShowS
forall na. Show na => VFoundNodeData na -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VFoundNodeData na] -> ShowS
$cshowList :: forall na. Show na => [VFoundNodeData na] -> ShowS
show :: VFoundNodeData na -> String
$cshow :: forall na. Show na => VFoundNodeData na -> String
showsPrec :: Int -> VFoundNodeData na -> ShowS
$cshowsPrec :: forall na. Show na => Int -> VFoundNodeData na -> ShowS
Show)

labelVProps :: AsLabel (PMap Multi GValue)
labelVProps :: AsLabel (PMap Multi GValue)
labelVProps = AsLabel (PMap Multi GValue)
"props"

labelVFoundNodeID :: AsLabel (ElementID VFoundNode)
labelVFoundNodeID :: AsLabel (ElementID VFoundNode)
labelVFoundNodeID = AsLabel (ElementID VFoundNode)
"vid"

labelMetaProps :: AsLabel (PMap Single GValue)
labelMetaProps :: AsLabel (PMap Single GValue)
labelMetaProps = AsLabel (PMap Single GValue)
"mprops"

gVFoundNodeData :: Walk Transform VFoundNode (VFoundNodeData na)
gVFoundNodeData :: Walk Transform VFoundNode (VFoundNodeData na)
gVFoundNodeData = Walk Transform VFoundNode (PMap Single GValue)
-> Walk Transform VFoundNode (VFoundNodeData na)
forall (g :: * -> * -> * -> *) c s e1 e2.
(ToGTraversal g, WalkType c) =>
g c s e1 -> g c s e2
unsafeCastEnd (Walk Transform VFoundNode (PMap Single GValue)
 -> Walk Transform VFoundNode (VFoundNodeData na))
-> Walk Transform VFoundNode (PMap Single GValue)
-> Walk Transform VFoundNode (VFoundNodeData na)
forall a b. (a -> b) -> a -> b
$ LabeledByProjection VFoundNode
-> [LabeledByProjection VFoundNode]
-> Walk Transform VFoundNode (PMap Single GValue)
forall s.
LabeledByProjection s
-> [LabeledByProjection s] -> Walk Transform s (PMap Single GValue)
gProject
                  ( AsLabel
  (ProjectionLikeEnd
     (Walk Transform VFoundNode (ElementID VFoundNode)))
-> Walk Transform VFoundNode (ElementID VFoundNode)
-> LabeledByProjection
     (ProjectionLikeStart
        (Walk Transform VFoundNode (ElementID VFoundNode)))
forall p.
(ProjectionLike p, ToGreskell p) =>
AsLabel (ProjectionLikeEnd p)
-> p -> LabeledByProjection (ProjectionLikeStart p)
gByL AsLabel
  (ProjectionLikeEnd
     (Walk Transform VFoundNode (ElementID VFoundNode)))
AsLabel (ElementID VFoundNode)
labelVFoundNodeID Walk Transform VFoundNode (ElementID VFoundNode)
forall s. Element s => Walk Transform s (ElementID s)
gId)
                  [ AsLabel
  (ProjectionLikeEnd (Walk Transform VFoundNode (PMap Multi GValue)))
-> Walk Transform VFoundNode (PMap Multi GValue)
-> LabeledByProjection
     (ProjectionLikeStart
        (Walk Transform VFoundNode (PMap Multi GValue)))
forall p.
(ProjectionLike p, ToGreskell p) =>
AsLabel (ProjectionLikeEnd p)
-> p -> LabeledByProjection (ProjectionLikeStart p)
gByL AsLabel
  (ProjectionLikeEnd (Walk Transform VFoundNode (PMap Multi GValue)))
AsLabel (PMap Multi GValue)
labelVProps (Walk Transform VFoundNode (PMap Multi GValue)
 -> LabeledByProjection
      (ProjectionLikeStart
         (Walk Transform VFoundNode (PMap Multi GValue))))
-> Walk Transform VFoundNode (PMap Multi GValue)
-> LabeledByProjection
     (ProjectionLikeStart
        (Walk Transform VFoundNode (PMap Multi GValue)))
forall a b. (a -> b) -> a -> b
$ Keys VFoundNode
-> Walk
     Transform
     VFoundNode
     (PMap (ElementPropertyContainer VFoundNode) GValue)
forall s.
Element s =>
Keys s
-> Walk Transform s (PMap (ElementPropertyContainer s) GValue)
gValueMap Keys VFoundNode
forall a. Keys a
KeysNil,
                    AsLabel
  (ProjectionLikeEnd
     (Walk Transform VFoundNode (PMap Single GValue)))
-> Walk Transform VFoundNode (PMap Single GValue)
-> LabeledByProjection
     (ProjectionLikeStart
        (Walk Transform VFoundNode (PMap Single GValue)))
forall p.
(ProjectionLike p, ToGreskell p) =>
AsLabel (ProjectionLikeEnd p)
-> p -> LabeledByProjection (ProjectionLikeStart p)
gByL AsLabel
  (ProjectionLikeEnd
     (Walk Transform VFoundNode (PMap Single GValue)))
AsLabel (PMap Single GValue)
labelMetaProps (Keys (AVertexProperty TsEpoch)
-> Walk
     Transform
     (AVertexProperty TsEpoch)
     (PMap (ElementPropertyContainer (AVertexProperty TsEpoch)) GValue)
forall s.
Element s =>
Keys s
-> Walk Transform s (PMap (ElementPropertyContainer s) GValue)
gValueMap Keys (AVertexProperty TsEpoch)
forall a. Keys a
KeysNil Walk Transform (AVertexProperty TsEpoch) (PMap Single GValue)
-> Walk Transform VFoundNode (AVertexProperty TsEpoch)
-> Walk Transform VFoundNode (PMap Single GValue)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
<<< [Key VFoundNode TsEpoch]
-> Walk Transform VFoundNode (AVertexProperty TsEpoch)
forall s (p :: * -> *) v.
(Element s, Property p, ElementProperty s ~ p) =>
[Key s v] -> Walk Transform s (p v)
gProperties [Key VFoundNode TsEpoch
keyTimestamp])
                  ]

instance NodeAttributes na => FromGraphSON (VFoundNodeData na) where
  parseGraphSON :: GValue -> Parser (VFoundNodeData na)
parseGraphSON GValue
gv = PMap Single GValue -> Parser (VFoundNodeData na)
forall na.
NodeAttributes na =>
PMap Single GValue -> Parser (VFoundNodeData na)
fromPMap (PMap Single GValue -> Parser (VFoundNodeData na))
-> Parser (PMap Single GValue) -> Parser (VFoundNodeData na)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< GValue -> Parser (PMap Single GValue)
forall a. FromGraphSON a => GValue -> Parser a
parseGraphSON GValue
gv
    where
      lookupAsF :: k -> PMap c GValue -> m (PMapValue k)
lookupAsF k
k PMap c GValue
pm = Either PMapLookupException (PMapValue k) -> m (PMapValue k)
forall (m :: * -> *) a.
MonadFail m =>
Either PMapLookupException a -> m a
pMapToFail (Either PMapLookupException (PMapValue k) -> m (PMapValue k))
-> Either PMapLookupException (PMapValue k) -> m (PMapValue k)
forall a b. (a -> b) -> a -> b
$ k -> PMap c GValue -> Either PMapLookupException (PMapValue k)
forall k (c :: * -> *) a.
(PMapKey k, NonEmptyLike c, PMapValue k ~ a, FromGraphSON a) =>
k -> PMap c GValue -> Either PMapLookupException a
lookupAs k
k PMap c GValue
pm
      fromPMap :: NodeAttributes na => PMap Single GValue -> Parser (VFoundNodeData na)
      fromPMap :: PMap Single GValue -> Parser (VFoundNodeData na)
fromPMap PMap Single GValue
pm = do
        ElementID VFoundNode
eid <- AsLabel (ElementID VFoundNode)
-> PMap Single GValue
-> Parser (PMapValue (AsLabel (ElementID VFoundNode)))
forall (m :: * -> *) k (c :: * -> *).
(MonadFail m, PMapKey k, NonEmptyLike c,
 FromGraphSON (PMapValue k)) =>
k -> PMap c GValue -> m (PMapValue k)
lookupAsF AsLabel (ElementID VFoundNode)
labelVFoundNodeID PMap Single GValue
pm
        PMap Multi GValue
props <- AsLabel (PMap Multi GValue)
-> PMap Single GValue
-> Parser (PMapValue (AsLabel (PMap Multi GValue)))
forall (m :: * -> *) k (c :: * -> *).
(MonadFail m, PMapKey k, NonEmptyLike c,
 FromGraphSON (PMapValue k)) =>
k -> PMap c GValue -> m (PMapValue k)
lookupAsF AsLabel (PMap Multi GValue)
labelVProps PMap Single GValue
pm
        PMap Single GValue
mprops <- AsLabel (PMap Single GValue)
-> PMap Single GValue
-> Parser (PMapValue (AsLabel (PMap Single GValue)))
forall (m :: * -> *) k (c :: * -> *).
(MonadFail m, PMapKey k, NonEmptyLike c,
 FromGraphSON (PMapValue k)) =>
k -> PMap c GValue -> m (PMapValue k)
lookupAsF AsLabel (PMap Single GValue)
labelMetaProps PMap Single GValue
pm
        na
attrs <- PMap Multi GValue -> Parser na
forall ps. NodeAttributes ps => PMap Multi GValue -> Parser ps
parseNodeAttributes PMap Multi GValue
props
        TsEpoch
epoch_ts <- Key VFoundNode TsEpoch
-> PMap Multi GValue -> Parser (PMapValue (Key VFoundNode TsEpoch))
forall (m :: * -> *) k (c :: * -> *).
(MonadFail m, PMapKey k, NonEmptyLike c,
 FromGraphSON (PMapValue k)) =>
k -> PMap c GValue -> m (PMapValue k)
lookupAsF Key VFoundNode TsEpoch
keyTimestamp PMap Multi GValue
props
        Maybe TimeZone
mtz <- PMap Single GValue -> Parser (Maybe TimeZone)
forall (m :: * -> *) (c :: * -> *).
(MonadFail m, NonEmptyLike c) =>
PMap c GValue -> m (Maybe TimeZone)
parseTimeZone PMap Single GValue
mprops
        VFoundNodeData na -> Parser (VFoundNodeData na)
forall (m :: * -> *) a. Monad m => a -> m a
return (VFoundNodeData na -> Parser (VFoundNodeData na))
-> VFoundNodeData na -> Parser (VFoundNodeData na)
forall a b. (a -> b) -> a -> b
$
          VFoundNodeData :: forall na.
ElementID VFoundNode -> Timestamp -> na -> VFoundNodeData na
VFoundNodeData
          { vfnId :: ElementID VFoundNode
vfnId = ElementID VFoundNode
eid,
            vfnTimestamp :: Timestamp
vfnTimestamp = Timestamp :: TsEpoch -> Maybe TimeZone -> Timestamp
Timestamp { epochTime :: TsEpoch
epochTime = TsEpoch
epoch_ts,
                                       timeZone :: Maybe TimeZone
timeZone = Maybe TimeZone
mtz
                                     },
            vfnAttributes :: na
vfnAttributes = na
attrs
          }
      parseTimeZone :: PMap c GValue -> m (Maybe TimeZone)
parseTimeZone PMap c GValue
ts_prop = do
        case (Key (AVertexProperty TsEpoch) Int -> Either PMapLookupException Int
forall b a.
FromGraphSON b =>
Key a b -> Either PMapLookupException b
get Key (AVertexProperty TsEpoch) Int
keyTzOffset, Key (AVertexProperty TsEpoch) Bool
-> Either PMapLookupException Bool
forall b a.
FromGraphSON b =>
Key a b -> Either PMapLookupException b
get Key (AVertexProperty TsEpoch) Bool
keyTzSummerOnly, Key (AVertexProperty TsEpoch) Text
-> Either PMapLookupException Text
forall b a.
FromGraphSON b =>
Key a b -> Either PMapLookupException b
get Key (AVertexProperty TsEpoch) Text
keyTzName) of
          (Left PMapLookupException
_, Left PMapLookupException
_, Left PMapLookupException
_) -> Maybe TimeZone -> m (Maybe TimeZone)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe TimeZone
forall a. Maybe a
Nothing
          (Either PMapLookupException Int
eo, Either PMapLookupException Bool
es, Either PMapLookupException Text
en) -> do
            Int
offset <- Either PMapLookupException Int -> m Int
forall (m :: * -> *) a a.
(MonadFail m, Show a) =>
Either a a -> m a
eToP Either PMapLookupException Int
eo
            Bool
is_summer_only <- Either PMapLookupException Bool -> m Bool
forall (m :: * -> *) a a.
(MonadFail m, Show a) =>
Either a a -> m a
eToP Either PMapLookupException Bool
es
            Text
name <- Either PMapLookupException Text -> m Text
forall (m :: * -> *) a a.
(MonadFail m, Show a) =>
Either a a -> m a
eToP Either PMapLookupException Text
en
            Maybe TimeZone -> m (Maybe TimeZone)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe TimeZone -> m (Maybe TimeZone))
-> Maybe TimeZone -> m (Maybe TimeZone)
forall a b. (a -> b) -> a -> b
$ TimeZone -> Maybe TimeZone
forall a. a -> Maybe a
Just (TimeZone -> Maybe TimeZone) -> TimeZone -> Maybe TimeZone
forall a b. (a -> b) -> a -> b
$ TimeZone :: Int -> Bool -> String -> TimeZone
TimeZone { timeZoneMinutes :: Int
timeZoneMinutes = Int
offset,
                                       timeZoneSummerOnly :: Bool
timeZoneSummerOnly = Bool
is_summer_only,
                                       timeZoneName :: String
timeZoneName = Text -> String
unpack Text
name
                                     }
          where
            get :: FromGraphSON b => Key a b -> Either PMapLookupException b
            get :: Key a b -> Either PMapLookupException b
get Key a b
k = Key a b -> PMap c GValue -> Either PMapLookupException b
forall k (c :: * -> *) a.
(PMapKey k, NonEmptyLike c, PMapValue k ~ a, FromGraphSON a) =>
k -> PMap c GValue -> Either PMapLookupException a
lookupAs Key a b
k PMap c GValue
ts_prop
            eToP :: Either a a -> m a
eToP = (a -> m a) -> (a -> m a) -> Either a a -> m a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m a) -> (a -> String) -> a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall a. Show a => a -> String
show) a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return

-- | \"finds\" edge.
newtype EFinds = EFinds AEdge
               deriving (Int -> EFinds -> ShowS
[EFinds] -> ShowS
EFinds -> String
(Int -> EFinds -> ShowS)
-> (EFinds -> String) -> ([EFinds] -> ShowS) -> Show EFinds
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EFinds] -> ShowS
$cshowList :: [EFinds] -> ShowS
show :: EFinds -> String
$cshow :: EFinds -> String
showsPrec :: Int -> EFinds -> ShowS
$cshowsPrec :: Int -> EFinds -> ShowS
Show,EFinds -> EFinds -> Bool
(EFinds -> EFinds -> Bool)
-> (EFinds -> EFinds -> Bool) -> Eq EFinds
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EFinds -> EFinds -> Bool
$c/= :: EFinds -> EFinds -> Bool
== :: EFinds -> EFinds -> Bool
$c== :: EFinds -> EFinds -> Bool
Eq,EFinds -> Text
EFinds -> ElementID EFinds
(EFinds -> ElementID EFinds)
-> (EFinds -> Text) -> ElementData EFinds
forall e. (e -> ElementID e) -> (e -> Text) -> ElementData e
elementLabel :: EFinds -> Text
$celementLabel :: EFinds -> Text
elementId :: EFinds -> ElementID EFinds
$celementId :: EFinds -> ElementID EFinds
ElementData,ElementData EFinds
ElementData EFinds -> Element EFinds
forall e. ElementData e -> Element e
Element,Element EFinds
Element EFinds -> Edge EFinds
forall e. Element e -> Edge e
Edge,GValue -> Parser EFinds
(GValue -> Parser EFinds) -> FromGraphSON EFinds
forall a. (GValue -> Parser a) -> FromGraphSON a
parseGraphSON :: GValue -> Parser EFinds
$cparseGraphSON :: GValue -> Parser EFinds
FromGraphSON)

-- | Properties of \"finds\" edge.
data EFindsData la =
  EFindsData
  { EFindsData la -> ElementID EFinds
efId :: EID EFinds,
    EFindsData la -> ElementID VNode
efTargetId :: EID VNode,
    EFindsData la -> LinkState
efLinkState :: LinkState,
    EFindsData la -> la
efLinkAttributes :: la
  }
  deriving (Int -> EFindsData la -> ShowS
[EFindsData la] -> ShowS
EFindsData la -> String
(Int -> EFindsData la -> ShowS)
-> (EFindsData la -> String)
-> ([EFindsData la] -> ShowS)
-> Show (EFindsData la)
forall la. Show la => Int -> EFindsData la -> ShowS
forall la. Show la => [EFindsData la] -> ShowS
forall la. Show la => EFindsData la -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EFindsData la] -> ShowS
$cshowList :: forall la. Show la => [EFindsData la] -> ShowS
show :: EFindsData la -> String
$cshow :: forall la. Show la => EFindsData la -> String
showsPrec :: Int -> EFindsData la -> ShowS
$cshowsPrec :: forall la. Show la => Int -> EFindsData la -> ShowS
Show)

keyLinkState :: Key EFinds Text
keyLinkState :: Key EFinds Text
keyLinkState = Key EFinds Text
"@link_state"

gSetLinkState :: LinkState -> Binder (Walk SideEffect EFinds EFinds)
gSetLinkState :: LinkState -> Binder (Walk SideEffect EFinds EFinds)
gSetLinkState LinkState
ls = do
  Greskell Text
var_ls <- Text -> Binder (Greskell Text)
forall v. ToJSON v => v -> Binder (Greskell v)
newBind (Text -> Binder (Greskell Text)) -> Text -> Binder (Greskell Text)
forall a b. (a -> b) -> a -> b
$ LinkState -> Text
linkStateToText (LinkState -> Text) -> LinkState -> Text
forall a b. (a -> b) -> a -> b
$ LinkState
ls
  Walk SideEffect EFinds EFinds
-> Binder (Walk SideEffect EFinds EFinds)
forall (m :: * -> *) a. Monad m => a -> m a
return (Walk SideEffect EFinds EFinds
 -> Binder (Walk SideEffect EFinds EFinds))
-> Walk SideEffect EFinds EFinds
-> Binder (Walk SideEffect EFinds EFinds)
forall a b. (a -> b) -> a -> b
$ Key EFinds Text -> Greskell Text -> Walk SideEffect EFinds EFinds
forall e v.
Element e =>
Key e v -> Greskell v -> Walk SideEffect e e
gProperty Key EFinds Text
keyLinkState Greskell Text
var_ls

gFindsTarget :: Walk Transform EFinds VNode
gFindsTarget :: Walk Transform EFinds VNode
gFindsTarget = Walk Transform EFinds VNode
forall e v. (Edge e, Vertex v) => Walk Transform e v
gInV

labelEProps :: AsLabel (PMap Single GValue)
labelEProps :: AsLabel (PMap Single GValue)
labelEProps = AsLabel (PMap Single GValue)
"eprops"

labelEFindsID :: AsLabel (ElementID EFinds)
labelEFindsID :: AsLabel (ElementID EFinds)
labelEFindsID = AsLabel (ElementID EFinds)
"eid"

labelEFindsTarget :: AsLabel (ElementID VNode)
labelEFindsTarget :: AsLabel (ElementID VNode)
labelEFindsTarget = AsLabel (ElementID VNode)
"vnode"

gEFindsData :: Walk Transform EFinds (EFindsData la)
gEFindsData :: Walk Transform EFinds (EFindsData la)
gEFindsData = Walk Transform EFinds (PMap Single GValue)
-> Walk Transform EFinds (EFindsData la)
forall (g :: * -> * -> * -> *) c s e1 e2.
(ToGTraversal g, WalkType c) =>
g c s e1 -> g c s e2
unsafeCastEnd (Walk Transform EFinds (PMap Single GValue)
 -> Walk Transform EFinds (EFindsData la))
-> Walk Transform EFinds (PMap Single GValue)
-> Walk Transform EFinds (EFindsData la)
forall a b. (a -> b) -> a -> b
$ LabeledByProjection EFinds
-> [LabeledByProjection EFinds]
-> Walk Transform EFinds (PMap Single GValue)
forall s.
LabeledByProjection s
-> [LabeledByProjection s] -> Walk Transform s (PMap Single GValue)
gProject
              ( AsLabel
  (ProjectionLikeEnd (Walk Transform EFinds (PMap Single GValue)))
-> Walk Transform EFinds (PMap Single GValue)
-> LabeledByProjection
     (ProjectionLikeStart (Walk Transform EFinds (PMap Single GValue)))
forall p.
(ProjectionLike p, ToGreskell p) =>
AsLabel (ProjectionLikeEnd p)
-> p -> LabeledByProjection (ProjectionLikeStart p)
gByL AsLabel
  (ProjectionLikeEnd (Walk Transform EFinds (PMap Single GValue)))
AsLabel (PMap Single GValue)
labelEProps (Walk Transform EFinds (PMap Single GValue)
 -> LabeledByProjection
      (ProjectionLikeStart (Walk Transform EFinds (PMap Single GValue))))
-> Walk Transform EFinds (PMap Single GValue)
-> LabeledByProjection
     (ProjectionLikeStart (Walk Transform EFinds (PMap Single GValue)))
forall a b. (a -> b) -> a -> b
$ Keys EFinds
-> Walk
     Transform EFinds (PMap (ElementPropertyContainer EFinds) GValue)
forall s.
Element s =>
Keys s
-> Walk Transform s (PMap (ElementPropertyContainer s) GValue)
gValueMap Keys EFinds
forall a. Keys a
KeysNil )
              [ AsLabel
  (ProjectionLikeEnd (Walk Transform EFinds (ElementID EFinds)))
-> Walk Transform EFinds (ElementID EFinds)
-> LabeledByProjection
     (ProjectionLikeStart (Walk Transform EFinds (ElementID EFinds)))
forall p.
(ProjectionLike p, ToGreskell p) =>
AsLabel (ProjectionLikeEnd p)
-> p -> LabeledByProjection (ProjectionLikeStart p)
gByL AsLabel
  (ProjectionLikeEnd (Walk Transform EFinds (ElementID EFinds)))
AsLabel (ElementID EFinds)
labelEFindsID (Walk Transform EFinds (ElementID EFinds)
 -> LabeledByProjection
      (ProjectionLikeStart (Walk Transform EFinds (ElementID EFinds))))
-> Walk Transform EFinds (ElementID EFinds)
-> LabeledByProjection
     (ProjectionLikeStart (Walk Transform EFinds (ElementID EFinds)))
forall a b. (a -> b) -> a -> b
$ Walk Transform EFinds (ElementID EFinds)
forall s. Element s => Walk Transform s (ElementID s)
gId,
                AsLabel
  (ProjectionLikeEnd (Walk Transform EFinds (ElementID VNode)))
-> Walk Transform EFinds (ElementID VNode)
-> LabeledByProjection
     (ProjectionLikeStart (Walk Transform EFinds (ElementID VNode)))
forall p.
(ProjectionLike p, ToGreskell p) =>
AsLabel (ProjectionLikeEnd p)
-> p -> LabeledByProjection (ProjectionLikeStart p)
gByL AsLabel
  (ProjectionLikeEnd (Walk Transform EFinds (ElementID VNode)))
AsLabel (ElementID VNode)
labelEFindsTarget (Walk Transform VNode (ElementID VNode)
forall s. Element s => Walk Transform s (ElementID s)
gId Walk Transform VNode (ElementID VNode)
-> Walk Transform EFinds VNode
-> Walk Transform EFinds (ElementID VNode)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
<<< Walk Transform EFinds VNode
gFindsTarget)
              ]

instance LinkAttributes la => FromGraphSON (EFindsData la) where
  parseGraphSON :: GValue -> Parser (EFindsData la)
parseGraphSON GValue
gv = PMap Single GValue -> Parser (EFindsData la)
forall la.
LinkAttributes la =>
PMap Single GValue -> Parser (EFindsData la)
fromPMap (PMap Single GValue -> Parser (EFindsData la))
-> Parser (PMap Single GValue) -> Parser (EFindsData la)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< GValue -> Parser (PMap Single GValue)
forall a. FromGraphSON a => GValue -> Parser a
parseGraphSON GValue
gv
    where
      lookupAsF :: k -> PMap c GValue -> m (PMapValue k)
lookupAsF k
k PMap c GValue
pm = Either PMapLookupException (PMapValue k) -> m (PMapValue k)
forall (m :: * -> *) a.
MonadFail m =>
Either PMapLookupException a -> m a
pMapToFail (Either PMapLookupException (PMapValue k) -> m (PMapValue k))
-> Either PMapLookupException (PMapValue k) -> m (PMapValue k)
forall a b. (a -> b) -> a -> b
$ k -> PMap c GValue -> Either PMapLookupException (PMapValue k)
forall k (c :: * -> *) a.
(PMapKey k, NonEmptyLike c, PMapValue k ~ a, FromGraphSON a) =>
k -> PMap c GValue -> Either PMapLookupException a
lookupAs k
k PMap c GValue
pm
      fromPMap :: LinkAttributes la => PMap Single GValue -> Parser (EFindsData la)
      fromPMap :: PMap Single GValue -> Parser (EFindsData la)
fromPMap PMap Single GValue
pm = do
        PMap Single GValue
props <- AsLabel (PMap Single GValue)
-> PMap Single GValue
-> Parser (PMapValue (AsLabel (PMap Single GValue)))
forall (m :: * -> *) k (c :: * -> *).
(MonadFail m, PMapKey k, NonEmptyLike c,
 FromGraphSON (PMapValue k)) =>
k -> PMap c GValue -> m (PMapValue k)
lookupAsF AsLabel (PMap Single GValue)
labelEProps PMap Single GValue
pm
        ElementID EFinds
eid <- AsLabel (ElementID EFinds)
-> PMap Single GValue
-> Parser (PMapValue (AsLabel (ElementID EFinds)))
forall (m :: * -> *) k (c :: * -> *).
(MonadFail m, PMapKey k, NonEmptyLike c,
 FromGraphSON (PMapValue k)) =>
k -> PMap c GValue -> m (PMapValue k)
lookupAsF AsLabel (ElementID EFinds)
labelEFindsID PMap Single GValue
pm
        ElementID VNode
target <- AsLabel (ElementID VNode)
-> PMap Single GValue
-> Parser (PMapValue (AsLabel (ElementID VNode)))
forall (m :: * -> *) k (c :: * -> *).
(MonadFail m, PMapKey k, NonEmptyLike c,
 FromGraphSON (PMapValue k)) =>
k -> PMap c GValue -> m (PMapValue k)
lookupAsF AsLabel (ElementID VNode)
labelEFindsTarget PMap Single GValue
pm
        LinkState
ls <- Text -> Parser LinkState
forall (m :: * -> *). MonadFail m => Text -> m LinkState
parseLinkState (Text -> Parser LinkState) -> Parser Text -> Parser LinkState
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Key EFinds Text
-> PMap Single GValue -> Parser (PMapValue (Key EFinds Text))
forall (m :: * -> *) k (c :: * -> *).
(MonadFail m, PMapKey k, NonEmptyLike c,
 FromGraphSON (PMapValue k)) =>
k -> PMap c GValue -> m (PMapValue k)
lookupAsF Key EFinds Text
keyLinkState PMap Single GValue
props
        la
attrs <- PMap Single GValue -> Parser la
forall ps. LinkAttributes ps => PMap Single GValue -> Parser ps
parseLinkAttributes PMap Single GValue
props
        EFindsData la -> Parser (EFindsData la)
forall (m :: * -> *) a. Monad m => a -> m a
return (EFindsData la -> Parser (EFindsData la))
-> EFindsData la -> Parser (EFindsData la)
forall a b. (a -> b) -> a -> b
$
          EFindsData :: forall la.
ElementID EFinds
-> ElementID VNode -> LinkState -> la -> EFindsData la
EFindsData
          { efId :: ElementID EFinds
efId = ElementID EFinds
eid,
            efTargetId :: ElementID VNode
efTargetId = ElementID VNode
target,
            efLinkState :: LinkState
efLinkState = LinkState
ls,
            efLinkAttributes :: la
efLinkAttributes = la
attrs
          }
      parseLinkState :: Text -> m LinkState
parseLinkState Text
t =
        case Text -> Maybe LinkState
linkStateFromText Text
t of
          Maybe LinkState
Nothing -> String -> m LinkState
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"Failed to parse " String -> ShowS
forall a. [a] -> [a] -> [a]
++ (Text -> String
unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ Key EFinds Text -> Text
forall a b. Key a b -> Text
unKey (Key EFinds Text -> Text) -> Key EFinds Text -> Text
forall a b. (a -> b) -> a -> b
$ Key EFinds Text
keyLinkState) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" field.")
          Just LinkState
a -> LinkState -> m LinkState
forall (m :: * -> *) a. Monad m => a -> m a
return LinkState
a

-- | Class of user-defined types for node attributes. Its content is
-- stored in the NetSpider database.
class NodeAttributes ps where
  writeNodeAttributes :: ps -> Binder (Walk SideEffect VFoundNode VFoundNode)
  -- ^ Return 'Walk' to write the attributes to the 'VFoundNode'.
  parseNodeAttributes :: PMap Multi GValue -> Parser ps
  -- ^ Parse the vertex proprerties into the attributes.

-- | No attributes.
instance NodeAttributes () where
  writeNodeAttributes :: () -> Binder (Walk SideEffect VFoundNode VFoundNode)
writeNodeAttributes ()
_ = Walk SideEffect VFoundNode VFoundNode
-> Binder (Walk SideEffect VFoundNode VFoundNode)
forall (m :: * -> *) a. Monad m => a -> m a
return Walk SideEffect VFoundNode VFoundNode
forall c s. WalkType c => Walk c s s
gIdentity
  parseNodeAttributes :: PMap Multi GValue -> Parser ()
parseNodeAttributes PMap Multi GValue
_ = () -> Parser ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Straightforward implementation.
--
-- @since 0.4.0.0
instance (FromGraphSON v, ToJSON v, Foldable c, Traversable c, NonEmptyLike c) => NodeAttributes (PMap c v) where
  writeNodeAttributes :: PMap c v -> Binder (Walk SideEffect VFoundNode VFoundNode)
writeNodeAttributes = PMap c v -> Binder (Walk SideEffect VFoundNode VFoundNode)
forall (c :: * -> *) v e.
(Foldable c, ToJSON v, Element e) =>
PMap c v -> Binder (Walk SideEffect e e)
writePMapProperties
  parseNodeAttributes :: PMap Multi GValue -> Parser (PMap c v)
parseNodeAttributes = (GValue -> Parser v) -> PMap c GValue -> Parser (PMap c v)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse GValue -> Parser v
forall a. FromGraphSON a => GValue -> Parser a
parseGraphSON (PMap c GValue -> Parser (PMap c v))
-> (PMap Multi GValue -> PMap c GValue)
-> PMap Multi GValue
-> Parser (PMap c v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Text, GValue)] -> PMap c GValue
forall (c :: * -> *) v. NonEmptyLike c => [(Text, v)] -> PMap c v
pMapFromList ([(Text, GValue)] -> PMap c GValue)
-> (PMap Multi GValue -> [(Text, GValue)])
-> PMap Multi GValue
-> PMap c GValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PMap Multi GValue -> [(Text, GValue)]
forall (c :: * -> *) v. Foldable c => PMap c v -> [(Text, v)]
pMapToList

-- | Class of user-defined types for link attributes. Its content is
-- stored in the NetSpider database.
class LinkAttributes ps where
  writeLinkAttributes :: ps -> Binder (Walk SideEffect EFinds EFinds)
  -- ^ Return 'Walk' to write the attributes to the 'EFinds'.
  parseLinkAttributes :: PMap Single GValue -> Parser ps
  -- ^ Parse the edge proprerties into the attributes.

-- | No attributes.
instance LinkAttributes () where
  writeLinkAttributes :: () -> Binder (Walk SideEffect EFinds EFinds)
writeLinkAttributes ()
_ = Walk SideEffect EFinds EFinds
-> Binder (Walk SideEffect EFinds EFinds)
forall (m :: * -> *) a. Monad m => a -> m a
return Walk SideEffect EFinds EFinds
forall c s. WalkType c => Walk c s s
gIdentity
  parseLinkAttributes :: PMap Single GValue -> Parser ()
parseLinkAttributes PMap Single GValue
_ = () -> Parser ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Straightforward implementation.
--
-- @since 0.4.0.0
instance (FromGraphSON v, ToJSON v, Foldable c, Traversable c, NonEmptyLike c) => LinkAttributes (PMap c v) where
  writeLinkAttributes :: PMap c v -> Binder (Walk SideEffect EFinds EFinds)
writeLinkAttributes = PMap c v -> Binder (Walk SideEffect EFinds EFinds)
forall (c :: * -> *) v e.
(Foldable c, ToJSON v, Element e) =>
PMap c v -> Binder (Walk SideEffect e e)
writePMapProperties
  parseLinkAttributes :: PMap Single GValue -> Parser (PMap c v)
parseLinkAttributes = (GValue -> Parser v) -> PMap c GValue -> Parser (PMap c v)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse GValue -> Parser v
forall a. FromGraphSON a => GValue -> Parser a
parseGraphSON (PMap c GValue -> Parser (PMap c v))
-> (PMap Single GValue -> PMap c GValue)
-> PMap Single GValue
-> Parser (PMap c v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Text, GValue)] -> PMap c GValue
forall (c :: * -> *) v. NonEmptyLike c => [(Text, v)] -> PMap c v
pMapFromList ([(Text, GValue)] -> PMap c GValue)
-> (PMap Single GValue -> [(Text, GValue)])
-> PMap Single GValue
-> PMap c GValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PMap Single GValue -> [(Text, GValue)]
forall (c :: * -> *) v. Foldable c => PMap c v -> [(Text, v)]
pMapToList
  
-- | Make 'FoundLink' out of 'EFindsData'.
makeFoundLink :: n -- ^ Target node ID
              -> EFindsData la -- ^ Attributes of \"finds\" edge
              -> FoundLink n la
makeFoundLink :: n -> EFindsData la -> FoundLink n la
makeFoundLink n
target_nid EFindsData la
ef_data =
  FoundLink :: forall n la. n -> LinkState -> la -> FoundLink n la
FoundLink
  { targetNode :: n
targetNode = n
target_nid,
    linkState :: LinkState
linkState = EFindsData la -> LinkState
forall la. EFindsData la -> LinkState
efLinkState EFindsData la
ef_data,
    linkAttributes :: la
linkAttributes = EFindsData la -> la
forall la. EFindsData la -> la
efLinkAttributes EFindsData la
ef_data
  }

-- | Make 'FoundNode' out of 'VFoundNodeData' and other graph
-- elements.
makeFoundNode :: n -- ^ Subject node ID
              -> VFoundNodeData na -- ^ Attributes of the 'FoundNode'.
              -> [FoundLink n la] -- ^ neighbor links
              -> FoundNode n na la
makeFoundNode :: n -> VFoundNodeData na -> [FoundLink n la] -> FoundNode n na la
makeFoundNode n
subject_nid VFoundNodeData na
vfn [FoundLink n la]
neighbors =
  FoundNode :: forall n na la.
n -> Timestamp -> [FoundLink n la] -> na -> FoundNode n na la
FoundNode
  { subjectNode :: n
subjectNode = n
subject_nid,
    foundAt :: Timestamp
foundAt = VFoundNodeData na -> Timestamp
forall na. VFoundNodeData na -> Timestamp
vfnTimestamp VFoundNodeData na
vfn,
    neighborLinks :: [FoundLink n la]
neighborLinks = [FoundLink n la]
neighbors,
    nodeAttributes :: na
nodeAttributes = VFoundNodeData na -> na
forall na. VFoundNodeData na -> na
vfnAttributes VFoundNodeData na
vfn
  }