-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A Haskell client for the Cayley graph database
--   
--   cayley-client implements the RESTful API of the Cayley graph database.
@package cayley-client
@version 0.4.5

module Database.Cayley.Types
data APIVersion
V1 :: APIVersion
data QueryLang
Gremlin :: QueryLang
MQL :: QueryLang
data CayleyConfig
CayleyConfig :: Int -> String -> APIVersion -> QueryLang -> CayleyConfig
[serverPort] :: CayleyConfig -> Int
[serverName] :: CayleyConfig -> String
[apiVersion] :: CayleyConfig -> APIVersion
[queryLang] :: CayleyConfig -> QueryLang

-- | CayleyConfig { serverPort = 64210 , serverName = "localhost" ,
--   apiVersion = V1 , queryLang = Gremlin }
defaultCayleyConfig :: CayleyConfig
data CayleyConnection
CayleyConnection :: (CayleyConfig, Manager) -> CayleyConnection
data Quad
Quad :: !Text -> !Text -> !Text -> !(Maybe Text) -> Quad

-- | Subject node
[subject] :: Quad -> !Text

-- | Predicate node
[predicate] :: Quad -> !Text

-- | Object node
[object] :: Quad -> !Text

-- | Label node
[label] :: Quad -> !(Maybe Text)

-- | Two quads are equals when subject, predicate, object <i>and</i> label
--   are equals.
data Shape
Shape :: ![Node] -> ![Link] -> Shape
[nodes] :: Shape -> ![Node]
[links] :: Shape -> ![Link]
parseNode :: Value -> Parser Node
parseLink :: Value -> Parser Link
data Node
Node :: !Integer -> !(Maybe [Tag]) -> !(Maybe [Value]) -> !Bool -> !Bool -> Node
[id] :: Node -> !Integer

-- | list of tags from the query
[tags] :: Node -> !(Maybe [Tag])

-- | Known values from the query
[values] :: Node -> !(Maybe [Value])

-- | Does the node represent the link or the node (the oval shapes)
[isLinkNode] :: Node -> !Bool

-- | Is the node a fixed starting point of the query
[isFixed] :: Node -> !Bool
data Link
Link :: !Integer -> !Integer -> !Integer -> Link

-- | Node ID
[source] :: Link -> !Integer

-- | Node ID
[target] :: Link -> !Integer

-- | Node ID
[linkNode] :: Link -> !Integer
type Query = Text
type Subject = Text
type Predicate = Text
type Object = Text
type Label = Text
type Tag = Text
type Value = Text
instance GHC.Show.Show Database.Cayley.Types.Shape
instance GHC.Classes.Eq Database.Cayley.Types.Shape
instance GHC.Show.Show Database.Cayley.Types.Node
instance GHC.Classes.Eq Database.Cayley.Types.Node
instance GHC.Show.Show Database.Cayley.Types.Link
instance GHC.Classes.Eq Database.Cayley.Types.Link
instance GHC.Generics.Generic Database.Cayley.Types.Quad
instance GHC.Show.Show Database.Cayley.Types.CayleyConfig
instance Data.Aeson.Types.FromJSON.FromJSON Database.Cayley.Types.Shape
instance Data.Binary.Class.Binary Database.Cayley.Types.Quad
instance GHC.Show.Show Database.Cayley.Types.Quad
instance GHC.Classes.Eq Database.Cayley.Types.Quad
instance Data.Aeson.Types.ToJSON.ToJSON Database.Cayley.Types.Quad
instance Data.Aeson.Types.FromJSON.FromJSON Database.Cayley.Types.Quad
instance GHC.Show.Show Database.Cayley.Types.QueryLang
instance GHC.Show.Show Database.Cayley.Types.APIVersion

module Database.Cayley.Client
data Quad
Quad :: !Text -> !Text -> !Text -> !(Maybe Text) -> Quad

-- | Subject node
[subject] :: Quad -> !Text

-- | Predicate node
[predicate] :: Quad -> !Text

-- | Object node
[object] :: Quad -> !Text

-- | Label node
[label] :: Quad -> !(Maybe Text)

-- | CayleyConfig { serverPort = 64210 , serverName = "localhost" ,
--   apiVersion = V1 , queryLang = Gremlin }
defaultCayleyConfig :: CayleyConfig

-- | Get a connection to Cayley with the given configuration.
--   
--   <pre>
--   λ&gt; conn &lt;- connectCayley defaultCayleyConfig
--   </pre>
connectCayley :: CayleyConfig -> IO CayleyConnection

-- | Perform a query, in Gremlin graph query language per default (or in
--   MQL).
--   
--   <pre>
--   λ&gt; query conn "graph.Vertex('Humphrey Bogart').In('name').All()"
--   Right (Array (fromList [Object (fromList [("id",String "/en/humphrey_bogart")])]))
--   </pre>
query :: CayleyConnection -> Query -> IO (Either String Value)
data Shape

-- | Return the description of the given executed query.
queryShape :: CayleyConnection -> Query -> IO (Either String Shape)

-- | Write the given <a>Quad</a>.
write :: CayleyConnection -> Quad -> IO (Maybe Value)

-- | Write a <a>Quad</a> with the given subject, predicate, object and
--   optional label. Throw result or extract amount of query <a>results</a>
--   from it.
--   
--   <pre>
--   λ&gt; writeQuad conn "Humphrey" "loves" "Lauren" (Just "In love")
--   Just (Object (fromList [("result",String "Successfully wrote 1 quads.")]))
--   </pre>
writeQuad :: CayleyConnection -> Subject -> Predicate -> Object -> Maybe Label -> IO (Maybe Value)

-- | Write the given list of <a>Quad</a>(s).
writeQuads :: CayleyConnection -> [Quad] -> IO (Maybe Value)

-- | Write a N-Quad file.
--   
--   <pre>
--   λ&gt; writeNQuadFile conn "testdata.nq"
--   Just (Object (fromList [("result",String "Successfully wrote 11 quads.")]))
--   </pre>
writeNQuadFile :: (MonadThrow m, MonadIO m) => CayleyConnection -> FilePath -> m (Maybe Value)

-- | Delete the given <a>Quad</a>.
delete :: CayleyConnection -> Quad -> IO (Maybe Value)

-- | Delete the <a>Quad</a> defined by the given subject, predicate, object
--   and optional label.
deleteQuad :: CayleyConnection -> Subject -> Predicate -> Object -> Maybe Label -> IO (Maybe Value)

-- | Delete the given list of <a>Quad</a>(s).
deleteQuads :: CayleyConnection -> [Quad] -> IO (Maybe Value)

-- | Given a subject, a predicate, an object and an optional label, create
--   a valid <a>Quad</a>.
createQuad :: Subject -> Predicate -> Object -> Maybe Label -> Maybe Quad

-- | A valid <a>Quad</a> has its subject, predicate and object not empty.
isValid :: Quad -> Bool

-- | Get amount of results from a write/delete <a>Quad</a>(s) operation, or
--   an explicite error message.
--   
--   <pre>
--   λ&gt; writeNQuadFile conn "testdata.nq" &gt;&gt;= results
--   Right 11
--   </pre>
results :: Maybe Value -> IO (Either String Int)
