{-|
Module      : Gargantext.Database.Types.Nodes
Description : Main Types of Nodes in Database
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

-}

{-# OPTIONS_GHC -fno-warn-orphans #-}

{-# LANGUAGE BangPatterns               #-}
{-# LANGUAGE TemplateHaskell            #-}

-- {-# LANGUAGE DuplicateRecordFields #-}

module Gargantext.Database.Admin.Types.Node
  where

import Codec.Serialise (Serialise())
import Control.Monad (mzero)
import Data.Aeson
import Data.Aeson.TH (deriveJSON)
import Data.Either
import Data.Hashable (Hashable)
import Data.Morpheus.Types (GQLType)
import Data.Swagger
import Data.Text (Text, unpack)
import Data.Time (UTCTime)
import Database.PostgreSQL.Simple.FromField (FromField, fromField)
import Database.PostgreSQL.Simple.ToField (ToField, toField)
import GHC.Generics (Generic)
import Servant
import qualified Opaleye as O
import Opaleye (DefaultFromField, defaultFromField, PGInt4, PGText, PGTSVector, Nullable, fieldQueryRunnerColumn)
import Test.QuickCheck (elements)
import Gargantext.Prelude.Crypto.Hash (Hash)
import Test.QuickCheck.Arbitrary
import Test.QuickCheck.Instances.Text ()
import Test.QuickCheck.Instances.Time ()
import Text.Read (read)

import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger, wellNamedSchema)
-- import Gargantext.Database.Prelude (fromField')
import Gargantext.Database.Schema.Node
import Gargantext.Prelude

type UserId = Int
type MasterUserId = UserId
------------------------------------------------------------------------
-- | NodePoly indicates that Node has a Polymorphism Type
type Node json   = NodePoly NodeId (Maybe Hash) NodeTypeId UserId (Maybe ParentId) NodeName UTCTime json

-- | NodeSearch (queries)
-- type NodeSearch json   = NodePolySearch NodeId NodeTypeId UserId (Maybe ParentId) NodeName UTCTime json (Maybe TSVector)

------------------------------------------------------------------------

instance (Typeable hyperdata, ToSchema hyperdata) =>
         ToSchema (NodePoly NodeId Hash NodeTypeId
                            (Maybe UserId)
                            ParentId NodeName
                            UTCTime hyperdata
                  ) where
  declareNamedSchema :: Proxy
  (NodePoly
     NodeId Hash Int (Maybe Int) NodeId Hash UTCTime hyperdata)
-> Declare (Definitions Schema) NamedSchema
declareNamedSchema = Hash
-> Proxy
     (NodePoly
        NodeId Hash Int (Maybe Int) NodeId Hash UTCTime hyperdata)
-> Declare (Definitions Schema) NamedSchema
forall a.
(Typeable a, Generic a, GToSchema (Rep a),
 GenericHasSimpleShape
   a
   "genericDeclareNamedSchemaUnrestricted"
   (GenericShape (Rep a))) =>
Hash -> Proxy a -> Declare (Definitions Schema) NamedSchema
wellNamedSchema Hash
"_node_"

instance (Typeable hyperdata, ToSchema hyperdata) =>
         ToSchema (NodePoly NodeId Hash NodeTypeId
                            UserId
                            (Maybe ParentId) NodeName
                            UTCTime hyperdata
                  ) where
  declareNamedSchema :: Proxy
  (NodePoly
     NodeId Hash Int Int (Maybe NodeId) Hash UTCTime hyperdata)
-> Declare (Definitions Schema) NamedSchema
declareNamedSchema = Hash
-> Proxy
     (NodePoly
        NodeId Hash Int Int (Maybe NodeId) Hash UTCTime hyperdata)
-> Declare (Definitions Schema) NamedSchema
forall a.
(Typeable a, Generic a, GToSchema (Rep a),
 GenericHasSimpleShape
   a
   "genericDeclareNamedSchemaUnrestricted"
   (GenericShape (Rep a))) =>
Hash -> Proxy a -> Declare (Definitions Schema) NamedSchema
wellNamedSchema Hash
"_node_"

instance (Typeable hyperdata, ToSchema hyperdata) =>
         ToSchema (NodePoly NodeId (Maybe Hash) NodeTypeId
                            UserId
                            (Maybe ParentId) NodeName
                            UTCTime hyperdata
                  ) where
  declareNamedSchema :: Proxy
  (NodePoly
     NodeId (Maybe Hash) Int Int (Maybe NodeId) Hash UTCTime hyperdata)
-> Declare (Definitions Schema) NamedSchema
declareNamedSchema = Hash
-> Proxy
     (NodePoly
        NodeId (Maybe Hash) Int Int (Maybe NodeId) Hash UTCTime hyperdata)
-> Declare (Definitions Schema) NamedSchema
forall a.
(Typeable a, Generic a, GToSchema (Rep a),
 GenericHasSimpleShape
   a
   "genericDeclareNamedSchemaUnrestricted"
   (GenericShape (Rep a))) =>
Hash -> Proxy a -> Declare (Definitions Schema) NamedSchema
wellNamedSchema Hash
"_node_"

instance (Typeable hyperdata, ToSchema hyperdata) =>
         ToSchema (NodePolySearch NodeId
                                  NodeTypeId
                                  (Maybe UserId)
                                  ParentId
                                  NodeName
                                  UTCTime
                                  hyperdata
                                  (Maybe TSVector)
                  ) where
  declareNamedSchema :: Proxy
  (NodePolySearch
     NodeId Int (Maybe Int) NodeId Hash UTCTime hyperdata (Maybe Hash))
-> Declare (Definitions Schema) NamedSchema
declareNamedSchema = Hash
-> Proxy
     (NodePolySearch
        NodeId Int (Maybe Int) NodeId Hash UTCTime hyperdata (Maybe Hash))
-> Declare (Definitions Schema) NamedSchema
forall a.
(Typeable a, Generic a, GToSchema (Rep a),
 GenericHasSimpleShape
   a
   "genericDeclareNamedSchemaUnrestricted"
   (GenericShape (Rep a))) =>
Hash -> Proxy a -> Declare (Definitions Schema) NamedSchema
wellNamedSchema Hash
"_ns_"

instance (Typeable hyperdata, ToSchema hyperdata) =>
         ToSchema (NodePolySearch NodeId
                                  NodeTypeId
                                  UserId
                                  (Maybe ParentId)
                                  NodeName
                                  UTCTime
                                  hyperdata
                                  (Maybe TSVector)
                  ) where
  declareNamedSchema :: Proxy
  (NodePolySearch
     NodeId Int Int (Maybe NodeId) Hash UTCTime hyperdata (Maybe Hash))
-> Declare (Definitions Schema) NamedSchema
declareNamedSchema = Hash
-> Proxy
     (NodePolySearch
        NodeId Int Int (Maybe NodeId) Hash UTCTime hyperdata (Maybe Hash))
-> Declare (Definitions Schema) NamedSchema
forall a.
(Typeable a, Generic a, GToSchema (Rep a),
 GenericHasSimpleShape
   a
   "genericDeclareNamedSchemaUnrestricted"
   (GenericShape (Rep a))) =>
Hash -> Proxy a -> Declare (Definitions Schema) NamedSchema
wellNamedSchema Hash
"_ns_"

instance (Arbitrary nodeId
         ,Arbitrary hashId
         ,Arbitrary toDBid
         ,Arbitrary userId
         ,Arbitrary nodeParentId
         , Arbitrary hyperdata
         ) => Arbitrary (NodePoly nodeId hashId toDBid userId nodeParentId
                                  NodeName UTCTime hyperdata) where
    --arbitrary = Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (arbitrary) (Just "")
    arbitrary :: Gen
  (NodePoly
     nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
arbitrary = nodeId
-> hashId
-> toDBid
-> userId
-> nodeParentId
-> Hash
-> UTCTime
-> hyperdata
-> NodePoly
     nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata
forall id hash_id typename user_id parent_id name date hyperdata.
id
-> hash_id
-> typename
-> user_id
-> parent_id
-> name
-> date
-> hyperdata
-> NodePoly
     id hash_id typename user_id parent_id name date hyperdata
Node (nodeId
 -> hashId
 -> toDBid
 -> userId
 -> nodeParentId
 -> Hash
 -> UTCTime
 -> hyperdata
 -> NodePoly
      nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
-> Gen nodeId
-> Gen
     (hashId
      -> toDBid
      -> userId
      -> nodeParentId
      -> Hash
      -> UTCTime
      -> hyperdata
      -> NodePoly
           nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen nodeId
forall a. Arbitrary a => Gen a
arbitrary Gen
  (hashId
   -> toDBid
   -> userId
   -> nodeParentId
   -> Hash
   -> UTCTime
   -> hyperdata
   -> NodePoly
        nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
-> Gen hashId
-> Gen
     (toDBid
      -> userId
      -> nodeParentId
      -> Hash
      -> UTCTime
      -> hyperdata
      -> NodePoly
           nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen hashId
forall a. Arbitrary a => Gen a
arbitrary Gen
  (toDBid
   -> userId
   -> nodeParentId
   -> Hash
   -> UTCTime
   -> hyperdata
   -> NodePoly
        nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
-> Gen toDBid
-> Gen
     (userId
      -> nodeParentId
      -> Hash
      -> UTCTime
      -> hyperdata
      -> NodePoly
           nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen toDBid
forall a. Arbitrary a => Gen a
arbitrary
                     Gen
  (userId
   -> nodeParentId
   -> Hash
   -> UTCTime
   -> hyperdata
   -> NodePoly
        nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
-> Gen userId
-> Gen
     (nodeParentId
      -> Hash
      -> UTCTime
      -> hyperdata
      -> NodePoly
           nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen userId
forall a. Arbitrary a => Gen a
arbitrary Gen
  (nodeParentId
   -> Hash
   -> UTCTime
   -> hyperdata
   -> NodePoly
        nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
-> Gen nodeParentId
-> Gen
     (Hash
      -> UTCTime
      -> hyperdata
      -> NodePoly
           nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen nodeParentId
forall a. Arbitrary a => Gen a
arbitrary Gen
  (Hash
   -> UTCTime
   -> hyperdata
   -> NodePoly
        nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
-> Gen Hash
-> Gen
     (UTCTime
      -> hyperdata
      -> NodePoly
           nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Hash
forall a. Arbitrary a => Gen a
arbitrary
                     Gen
  (UTCTime
   -> hyperdata
   -> NodePoly
        nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
-> Gen UTCTime
-> Gen
     (hyperdata
      -> NodePoly
           nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen UTCTime
forall a. Arbitrary a => Gen a
arbitrary Gen
  (hyperdata
   -> NodePoly
        nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
-> Gen hyperdata
-> Gen
     (NodePoly
        nodeId hashId toDBid userId nodeParentId Hash UTCTime hyperdata)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen hyperdata
forall a. Arbitrary a => Gen a
arbitrary

instance (Arbitrary hyperdata
         ,Arbitrary nodeId
         ,Arbitrary toDBid
         ,Arbitrary userId
         ,Arbitrary nodeParentId
         ) => Arbitrary (NodePolySearch nodeId
                                        toDBid
                                        userId
                                        nodeParentId
                                        NodeName
                                        UTCTime
                                        hyperdata
                                        (Maybe TSVector)
                        ) where
    --arbitrary = Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (arbitrary) (Just "")
    arbitrary :: Gen
  (NodePolySearch
     nodeId
     toDBid
     userId
     nodeParentId
     Hash
     UTCTime
     hyperdata
     (Maybe Hash))
arbitrary = nodeId
-> toDBid
-> userId
-> nodeParentId
-> Hash
-> UTCTime
-> hyperdata
-> Maybe Hash
-> NodePolySearch
     nodeId
     toDBid
     userId
     nodeParentId
     Hash
     UTCTime
     hyperdata
     (Maybe Hash)
forall id typename user_id parent_id name date hyperdata search.
id
-> typename
-> user_id
-> parent_id
-> name
-> date
-> hyperdata
-> search
-> NodePolySearch
     id typename user_id parent_id name date hyperdata search
NodeSearch (nodeId
 -> toDBid
 -> userId
 -> nodeParentId
 -> Hash
 -> UTCTime
 -> hyperdata
 -> Maybe Hash
 -> NodePolySearch
      nodeId
      toDBid
      userId
      nodeParentId
      Hash
      UTCTime
      hyperdata
      (Maybe Hash))
-> Gen nodeId
-> Gen
     (toDBid
      -> userId
      -> nodeParentId
      -> Hash
      -> UTCTime
      -> hyperdata
      -> Maybe Hash
      -> NodePolySearch
           nodeId
           toDBid
           userId
           nodeParentId
           Hash
           UTCTime
           hyperdata
           (Maybe Hash))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen nodeId
forall a. Arbitrary a => Gen a
arbitrary
                           Gen
  (toDBid
   -> userId
   -> nodeParentId
   -> Hash
   -> UTCTime
   -> hyperdata
   -> Maybe Hash
   -> NodePolySearch
        nodeId
        toDBid
        userId
        nodeParentId
        Hash
        UTCTime
        hyperdata
        (Maybe Hash))
-> Gen toDBid
-> Gen
     (userId
      -> nodeParentId
      -> Hash
      -> UTCTime
      -> hyperdata
      -> Maybe Hash
      -> NodePolySearch
           nodeId
           toDBid
           userId
           nodeParentId
           Hash
           UTCTime
           hyperdata
           (Maybe Hash))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen toDBid
forall a. Arbitrary a => Gen a
arbitrary
                           Gen
  (userId
   -> nodeParentId
   -> Hash
   -> UTCTime
   -> hyperdata
   -> Maybe Hash
   -> NodePolySearch
        nodeId
        toDBid
        userId
        nodeParentId
        Hash
        UTCTime
        hyperdata
        (Maybe Hash))
-> Gen userId
-> Gen
     (nodeParentId
      -> Hash
      -> UTCTime
      -> hyperdata
      -> Maybe Hash
      -> NodePolySearch
           nodeId
           toDBid
           userId
           nodeParentId
           Hash
           UTCTime
           hyperdata
           (Maybe Hash))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen userId
forall a. Arbitrary a => Gen a
arbitrary
                           Gen
  (nodeParentId
   -> Hash
   -> UTCTime
   -> hyperdata
   -> Maybe Hash
   -> NodePolySearch
        nodeId
        toDBid
        userId
        nodeParentId
        Hash
        UTCTime
        hyperdata
        (Maybe Hash))
-> Gen nodeParentId
-> Gen
     (Hash
      -> UTCTime
      -> hyperdata
      -> Maybe Hash
      -> NodePolySearch
           nodeId
           toDBid
           userId
           nodeParentId
           Hash
           UTCTime
           hyperdata
           (Maybe Hash))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen nodeParentId
forall a. Arbitrary a => Gen a
arbitrary
                           Gen
  (Hash
   -> UTCTime
   -> hyperdata
   -> Maybe Hash
   -> NodePolySearch
        nodeId
        toDBid
        userId
        nodeParentId
        Hash
        UTCTime
        hyperdata
        (Maybe Hash))
-> Gen Hash
-> Gen
     (UTCTime
      -> hyperdata
      -> Maybe Hash
      -> NodePolySearch
           nodeId
           toDBid
           userId
           nodeParentId
           Hash
           UTCTime
           hyperdata
           (Maybe Hash))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Hash
forall a. Arbitrary a => Gen a
arbitrary
                           Gen
  (UTCTime
   -> hyperdata
   -> Maybe Hash
   -> NodePolySearch
        nodeId
        toDBid
        userId
        nodeParentId
        Hash
        UTCTime
        hyperdata
        (Maybe Hash))
-> Gen UTCTime
-> Gen
     (hyperdata
      -> Maybe Hash
      -> NodePolySearch
           nodeId
           toDBid
           userId
           nodeParentId
           Hash
           UTCTime
           hyperdata
           (Maybe Hash))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen UTCTime
forall a. Arbitrary a => Gen a
arbitrary
                           Gen
  (hyperdata
   -> Maybe Hash
   -> NodePolySearch
        nodeId
        toDBid
        userId
        nodeParentId
        Hash
        UTCTime
        hyperdata
        (Maybe Hash))
-> Gen hyperdata
-> Gen
     (Maybe Hash
      -> NodePolySearch
           nodeId
           toDBid
           userId
           nodeParentId
           Hash
           UTCTime
           hyperdata
           (Maybe Hash))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen hyperdata
forall a. Arbitrary a => Gen a
arbitrary
                           Gen
  (Maybe Hash
   -> NodePolySearch
        nodeId
        toDBid
        userId
        nodeParentId
        Hash
        UTCTime
        hyperdata
        (Maybe Hash))
-> Gen (Maybe Hash)
-> Gen
     (NodePolySearch
        nodeId
        toDBid
        userId
        nodeParentId
        Hash
        UTCTime
        hyperdata
        (Maybe Hash))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Maybe Hash)
forall a. Arbitrary a => Gen a
arbitrary

------------------------------------------------------------------------
pgNodeId :: NodeId -> O.Column O.PGInt4
pgNodeId :: NodeId -> Column PGInt4
pgNodeId = Int -> Field PGInt4
Int -> Column PGInt4
O.sqlInt4 (Int -> Column PGInt4)
-> (NodeId -> Int) -> NodeId -> Column PGInt4
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NodeId -> Int
id2int
  where
    id2int :: NodeId -> Int
    id2int :: NodeId -> Int
id2int (NodeId Int
n) = Int
n

------------------------------------------------------------------------
newtype NodeId = NodeId Int
  deriving (ReadPrec [NodeId]
ReadPrec NodeId
Int -> ReadS NodeId
ReadS [NodeId]
(Int -> ReadS NodeId)
-> ReadS [NodeId]
-> ReadPrec NodeId
-> ReadPrec [NodeId]
-> Read NodeId
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NodeId]
$creadListPrec :: ReadPrec [NodeId]
readPrec :: ReadPrec NodeId
$creadPrec :: ReadPrec NodeId
readList :: ReadS [NodeId]
$creadList :: ReadS [NodeId]
readsPrec :: Int -> ReadS NodeId
$creadsPrec :: Int -> ReadS NodeId
Read, (forall x. NodeId -> Rep NodeId x)
-> (forall x. Rep NodeId x -> NodeId) -> Generic NodeId
forall x. Rep NodeId x -> NodeId
forall x. NodeId -> Rep NodeId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NodeId x -> NodeId
$cfrom :: forall x. NodeId -> Rep NodeId x
Generic, Integer -> NodeId
NodeId -> NodeId
NodeId -> NodeId -> NodeId
(NodeId -> NodeId -> NodeId)
-> (NodeId -> NodeId -> NodeId)
-> (NodeId -> NodeId -> NodeId)
-> (NodeId -> NodeId)
-> (NodeId -> NodeId)
-> (NodeId -> NodeId)
-> (Integer -> NodeId)
-> Num NodeId
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> NodeId
$cfromInteger :: Integer -> NodeId
signum :: NodeId -> NodeId
$csignum :: NodeId -> NodeId
abs :: NodeId -> NodeId
$cabs :: NodeId -> NodeId
negate :: NodeId -> NodeId
$cnegate :: NodeId -> NodeId
* :: NodeId -> NodeId -> NodeId
$c* :: NodeId -> NodeId -> NodeId
- :: NodeId -> NodeId -> NodeId
$c- :: NodeId -> NodeId -> NodeId
+ :: NodeId -> NodeId -> NodeId
$c+ :: NodeId -> NodeId -> NodeId
Num, NodeId -> NodeId -> Bool
(NodeId -> NodeId -> Bool)
-> (NodeId -> NodeId -> Bool) -> Eq NodeId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NodeId -> NodeId -> Bool
$c/= :: NodeId -> NodeId -> Bool
== :: NodeId -> NodeId -> Bool
$c== :: NodeId -> NodeId -> Bool
Eq, Eq NodeId
Eq NodeId
-> (NodeId -> NodeId -> Ordering)
-> (NodeId -> NodeId -> Bool)
-> (NodeId -> NodeId -> Bool)
-> (NodeId -> NodeId -> Bool)
-> (NodeId -> NodeId -> Bool)
-> (NodeId -> NodeId -> NodeId)
-> (NodeId -> NodeId -> NodeId)
-> Ord NodeId
NodeId -> NodeId -> Bool
NodeId -> NodeId -> Ordering
NodeId -> NodeId -> NodeId
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: NodeId -> NodeId -> NodeId
$cmin :: NodeId -> NodeId -> NodeId
max :: NodeId -> NodeId -> NodeId
$cmax :: NodeId -> NodeId -> NodeId
>= :: NodeId -> NodeId -> Bool
$c>= :: NodeId -> NodeId -> Bool
> :: NodeId -> NodeId -> Bool
$c> :: NodeId -> NodeId -> Bool
<= :: NodeId -> NodeId -> Bool
$c<= :: NodeId -> NodeId -> Bool
< :: NodeId -> NodeId -> Bool
$c< :: NodeId -> NodeId -> Bool
compare :: NodeId -> NodeId -> Ordering
$ccompare :: NodeId -> NodeId -> Ordering
$cp1Ord :: Eq NodeId
Ord, Int -> NodeId
NodeId -> Int
NodeId -> [NodeId]
NodeId -> NodeId
NodeId -> NodeId -> [NodeId]
NodeId -> NodeId -> NodeId -> [NodeId]
(NodeId -> NodeId)
-> (NodeId -> NodeId)
-> (Int -> NodeId)
-> (NodeId -> Int)
-> (NodeId -> [NodeId])
-> (NodeId -> NodeId -> [NodeId])
-> (NodeId -> NodeId -> [NodeId])
-> (NodeId -> NodeId -> NodeId -> [NodeId])
-> Enum NodeId
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: NodeId -> NodeId -> NodeId -> [NodeId]
$cenumFromThenTo :: NodeId -> NodeId -> NodeId -> [NodeId]
enumFromTo :: NodeId -> NodeId -> [NodeId]
$cenumFromTo :: NodeId -> NodeId -> [NodeId]
enumFromThen :: NodeId -> NodeId -> [NodeId]
$cenumFromThen :: NodeId -> NodeId -> [NodeId]
enumFrom :: NodeId -> [NodeId]
$cenumFrom :: NodeId -> [NodeId]
fromEnum :: NodeId -> Int
$cfromEnum :: NodeId -> Int
toEnum :: Int -> NodeId
$ctoEnum :: Int -> NodeId
pred :: NodeId -> NodeId
$cpred :: NodeId -> NodeId
succ :: NodeId -> NodeId
$csucc :: NodeId -> NodeId
Enum, ToJSONKeyFunction [NodeId]
ToJSONKeyFunction NodeId
ToJSONKeyFunction NodeId
-> ToJSONKeyFunction [NodeId] -> ToJSONKey NodeId
forall a.
ToJSONKeyFunction a -> ToJSONKeyFunction [a] -> ToJSONKey a
toJSONKeyList :: ToJSONKeyFunction [NodeId]
$ctoJSONKeyList :: ToJSONKeyFunction [NodeId]
toJSONKey :: ToJSONKeyFunction NodeId
$ctoJSONKey :: ToJSONKeyFunction NodeId
ToJSONKey, FromJSONKeyFunction [NodeId]
FromJSONKeyFunction NodeId
FromJSONKeyFunction NodeId
-> FromJSONKeyFunction [NodeId] -> FromJSONKey NodeId
forall a.
FromJSONKeyFunction a -> FromJSONKeyFunction [a] -> FromJSONKey a
fromJSONKeyList :: FromJSONKeyFunction [NodeId]
$cfromJSONKeyList :: FromJSONKeyFunction [NodeId]
fromJSONKey :: FromJSONKeyFunction NodeId
$cfromJSONKey :: FromJSONKeyFunction NodeId
FromJSONKey, [NodeId] -> Encoding
[NodeId] -> Value
NodeId -> Encoding
NodeId -> Value
(NodeId -> Value)
-> (NodeId -> Encoding)
-> ([NodeId] -> Value)
-> ([NodeId] -> Encoding)
-> ToJSON NodeId
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [NodeId] -> Encoding
$ctoEncodingList :: [NodeId] -> Encoding
toJSONList :: [NodeId] -> Value
$ctoJSONList :: [NodeId] -> Value
toEncoding :: NodeId -> Encoding
$ctoEncoding :: NodeId -> Encoding
toJSON :: NodeId -> Value
$ctoJSON :: NodeId -> Value
ToJSON, Value -> Parser [NodeId]
Value -> Parser NodeId
(Value -> Parser NodeId)
-> (Value -> Parser [NodeId]) -> FromJSON NodeId
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [NodeId]
$cparseJSONList :: Value -> Parser [NodeId]
parseJSON :: Value -> Parser NodeId
$cparseJSON :: Value -> Parser NodeId
FromJSON, Int -> NodeId -> Int
NodeId -> Int
(Int -> NodeId -> Int) -> (NodeId -> Int) -> Hashable NodeId
forall a. (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: NodeId -> Int
$chash :: NodeId -> Int
hashWithSalt :: Int -> NodeId -> Int
$chashWithSalt :: Int -> NodeId -> Int
Hashable)
instance GQLType NodeId
instance Show NodeId where
  show :: NodeId -> String
show (NodeId Int
n) = String
"nodeId-" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
n
instance Serialise NodeId
instance ToField NodeId where
  toField :: NodeId -> Action
toField (NodeId Int
n) = Int -> Action
forall a. ToField a => a -> Action
toField Int
n
instance FromField NodeId where
  fromField :: FieldParser NodeId
fromField Field
field Maybe ByteString
mdata = do
    Int
n <- FieldParser Int
forall a. FromField a => FieldParser a
fromField Field
field Maybe ByteString
mdata
    if (Int
n :: Int) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
       then NodeId -> Conversion NodeId
forall (m :: * -> *) a. Monad m => a -> m a
return (NodeId -> Conversion NodeId) -> NodeId -> Conversion NodeId
forall a b. (a -> b) -> a -> b
$ Int -> NodeId
NodeId Int
n
       else Conversion NodeId
forall (m :: * -> *) a. MonadPlus m => m a
mzero
instance ToSchema NodeId

unNodeId :: NodeId -> Int
unNodeId :: NodeId -> Int
unNodeId (NodeId Int
n) = Int
n

type NodeTypeId   = Int
type NodeName     = Text
type TSVector     = Text

------------------------------------------------------------------------
------------------------------------------------------------------------
instance FromHttpApiData NodeId where
  parseUrlPiece :: Hash -> Either Hash NodeId
parseUrlPiece Hash
n = NodeId -> Either Hash NodeId
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NodeId -> Either Hash NodeId) -> NodeId -> Either Hash NodeId
forall a b. (a -> b) -> a -> b
$ Int -> NodeId
NodeId (Int -> NodeId) -> Int -> NodeId
forall a b. (a -> b) -> a -> b
$ (String -> Int
forall a. Read a => String -> a
read (String -> Int) -> (Hash -> String) -> Hash -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash -> String
forall a b. ConvertibleStrings a b => a -> b
cs) Hash
n

instance ToParamSchema NodeId
instance Arbitrary NodeId where
  arbitrary :: Gen NodeId
arbitrary = Int -> NodeId
NodeId (Int -> NodeId) -> Gen Int -> Gen NodeId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Int
forall a. Arbitrary a => Gen a
arbitrary

type ParentId = NodeId
type CorpusId    = NodeId
type CommunityId = NodeId
type ListId   = NodeId
type DocumentId = NodeId
type DocId      = NodeId
type RootId     = NodeId
type MasterCorpusId = CorpusId
type UserCorpusId   = CorpusId

type GraphId  = NodeId
type PhyloId  = NodeId
type AnnuaireId = NodeId
type ContactId  = NodeId

------------------------------------------------------------------------
data Status  = Status { Status -> Int
status_failed    :: !Int
                      , Status -> Int
status_succeeded :: !Int
                      , Status -> Int
status_remaining :: !Int
                      } deriving (Int -> Status -> ShowS
[Status] -> ShowS
Status -> String
(Int -> Status -> ShowS)
-> (Status -> String) -> ([Status] -> ShowS) -> Show Status
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Status] -> ShowS
$cshowList :: [Status] -> ShowS
show :: Status -> String
$cshow :: Status -> String
showsPrec :: Int -> Status -> ShowS
$cshowsPrec :: Int -> Status -> ShowS
Show, (forall x. Status -> Rep Status x)
-> (forall x. Rep Status x -> Status) -> Generic Status
forall x. Rep Status x -> Status
forall x. Status -> Rep Status x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Status x -> Status
$cfrom :: forall x. Status -> Rep Status x
Generic)
$(deriveJSON (unPrefix "status_") ''Status)

instance Arbitrary Status where
  arbitrary :: Gen Status
arbitrary = Int -> Int -> Int -> Status
Status (Int -> Int -> Int -> Status)
-> Gen Int -> Gen (Int -> Int -> Status)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Int
forall a. Arbitrary a => Gen a
arbitrary Gen (Int -> Int -> Status) -> Gen Int -> Gen (Int -> Status)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Int
forall a. Arbitrary a => Gen a
arbitrary Gen (Int -> Status) -> Gen Int -> Gen Status
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Int
forall a. Arbitrary a => Gen a
arbitrary


------------------------------------------------------------------------
data LanguageNodes = LanguageNodes { LanguageNodes -> [Int]
languageNodes___unknown__ :: [Int]}
    deriving (Int -> LanguageNodes -> ShowS
[LanguageNodes] -> ShowS
LanguageNodes -> String
(Int -> LanguageNodes -> ShowS)
-> (LanguageNodes -> String)
-> ([LanguageNodes] -> ShowS)
-> Show LanguageNodes
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LanguageNodes] -> ShowS
$cshowList :: [LanguageNodes] -> ShowS
show :: LanguageNodes -> String
$cshow :: LanguageNodes -> String
showsPrec :: Int -> LanguageNodes -> ShowS
$cshowsPrec :: Int -> LanguageNodes -> ShowS
Show, (forall x. LanguageNodes -> Rep LanguageNodes x)
-> (forall x. Rep LanguageNodes x -> LanguageNodes)
-> Generic LanguageNodes
forall x. Rep LanguageNodes x -> LanguageNodes
forall x. LanguageNodes -> Rep LanguageNodes x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LanguageNodes x -> LanguageNodes
$cfrom :: forall x. LanguageNodes -> Rep LanguageNodes x
Generic)
$(deriveJSON (unPrefix "languageNodes_") ''LanguageNodes)

------------------------------------------------------------------------
-- level: debug | dev  (fatal = critical)
data EventLevel = CRITICAL | FATAL | ERROR | WARNING | INFO | DEBUG
  deriving (Int -> EventLevel -> ShowS
[EventLevel] -> ShowS
EventLevel -> String
(Int -> EventLevel -> ShowS)
-> (EventLevel -> String)
-> ([EventLevel] -> ShowS)
-> Show EventLevel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EventLevel] -> ShowS
$cshowList :: [EventLevel] -> ShowS
show :: EventLevel -> String
$cshow :: EventLevel -> String
showsPrec :: Int -> EventLevel -> ShowS
$cshowsPrec :: Int -> EventLevel -> ShowS
Show, (forall x. EventLevel -> Rep EventLevel x)
-> (forall x. Rep EventLevel x -> EventLevel) -> Generic EventLevel
forall x. Rep EventLevel x -> EventLevel
forall x. EventLevel -> Rep EventLevel x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EventLevel x -> EventLevel
$cfrom :: forall x. EventLevel -> Rep EventLevel x
Generic, Int -> EventLevel
EventLevel -> Int
EventLevel -> [EventLevel]
EventLevel -> EventLevel
EventLevel -> EventLevel -> [EventLevel]
EventLevel -> EventLevel -> EventLevel -> [EventLevel]
(EventLevel -> EventLevel)
-> (EventLevel -> EventLevel)
-> (Int -> EventLevel)
-> (EventLevel -> Int)
-> (EventLevel -> [EventLevel])
-> (EventLevel -> EventLevel -> [EventLevel])
-> (EventLevel -> EventLevel -> [EventLevel])
-> (EventLevel -> EventLevel -> EventLevel -> [EventLevel])
-> Enum EventLevel
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: EventLevel -> EventLevel -> EventLevel -> [EventLevel]
$cenumFromThenTo :: EventLevel -> EventLevel -> EventLevel -> [EventLevel]
enumFromTo :: EventLevel -> EventLevel -> [EventLevel]
$cenumFromTo :: EventLevel -> EventLevel -> [EventLevel]
enumFromThen :: EventLevel -> EventLevel -> [EventLevel]
$cenumFromThen :: EventLevel -> EventLevel -> [EventLevel]
enumFrom :: EventLevel -> [EventLevel]
$cenumFrom :: EventLevel -> [EventLevel]
fromEnum :: EventLevel -> Int
$cfromEnum :: EventLevel -> Int
toEnum :: Int -> EventLevel
$ctoEnum :: Int -> EventLevel
pred :: EventLevel -> EventLevel
$cpred :: EventLevel -> EventLevel
succ :: EventLevel -> EventLevel
$csucc :: EventLevel -> EventLevel
Enum, EventLevel
EventLevel -> EventLevel -> Bounded EventLevel
forall a. a -> a -> Bounded a
maxBound :: EventLevel
$cmaxBound :: EventLevel
minBound :: EventLevel
$cminBound :: EventLevel
Bounded)

instance FromJSON EventLevel
instance ToJSON EventLevel

instance Arbitrary EventLevel where
  arbitrary :: Gen EventLevel
arbitrary = [EventLevel] -> Gen EventLevel
forall a. [a] -> Gen a
elements [EventLevel
forall a. Bounded a => a
minBound..EventLevel
forall a. Bounded a => a
maxBound]

instance ToSchema EventLevel where
  declareNamedSchema :: Proxy EventLevel -> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy EventLevel
proxy = SchemaOptions
-> Proxy EventLevel -> Declare (Definitions Schema) NamedSchema
forall a.
(Generic a, GToSchema (Rep a),
 TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
SchemaOptions
-> Proxy a -> Declare (Definitions Schema) NamedSchema
genericDeclareNamedSchema SchemaOptions
defaultSchemaOptions Proxy EventLevel
proxy

------------------------------------------------------------------------
data Event = Event { Event -> EventLevel
event_level   :: !EventLevel
                   , Event -> Hash
event_message :: !Text
                   , Event -> UTCTime
event_date    :: !UTCTime
            } deriving (Int -> Event -> ShowS
[Event] -> ShowS
Event -> String
(Int -> Event -> ShowS)
-> (Event -> String) -> ([Event] -> ShowS) -> Show Event
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Event] -> ShowS
$cshowList :: [Event] -> ShowS
show :: Event -> String
$cshow :: Event -> String
showsPrec :: Int -> Event -> ShowS
$cshowsPrec :: Int -> Event -> ShowS
Show, (forall x. Event -> Rep Event x)
-> (forall x. Rep Event x -> Event) -> Generic Event
forall x. Rep Event x -> Event
forall x. Event -> Rep Event x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Event x -> Event
$cfrom :: forall x. Event -> Rep Event x
Generic)
$(deriveJSON (unPrefix "event_") ''Event)

instance Arbitrary Event where
  arbitrary :: Gen Event
arbitrary = EventLevel -> Hash -> UTCTime -> Event
Event (EventLevel -> Hash -> UTCTime -> Event)
-> Gen EventLevel -> Gen (Hash -> UTCTime -> Event)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen EventLevel
forall a. Arbitrary a => Gen a
arbitrary Gen (Hash -> UTCTime -> Event)
-> Gen Hash -> Gen (UTCTime -> Event)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Hash
forall a. Arbitrary a => Gen a
arbitrary Gen (UTCTime -> Event) -> Gen UTCTime -> Gen Event
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen UTCTime
forall a. Arbitrary a => Gen a
arbitrary

instance ToSchema Event where
  declareNamedSchema :: Proxy Event -> Declare (Definitions Schema) NamedSchema
declareNamedSchema = SchemaOptions
-> Proxy Event -> Declare (Definitions Schema) NamedSchema
forall a.
(Generic a, GToSchema (Rep a),
 TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
SchemaOptions
-> Proxy a -> Declare (Definitions Schema) NamedSchema
genericDeclareNamedSchema (String -> SchemaOptions
unPrefixSwagger String
"event_")

------------------------------------------------------------------------
data Resource = Resource { Resource -> Maybe Hash
resource_path    :: !(Maybe Text)
                         , Resource -> Maybe Hash
resource_scraper :: !(Maybe Text)
                         , Resource -> Maybe Hash
resource_query   :: !(Maybe Text)
                         , Resource -> [Event]
resource_events  :: !([Event])
                         , Resource -> Status
resource_status  :: !Status
                         , Resource -> UTCTime
resource_date    :: !UTCTime
                         } deriving (Int -> Resource -> ShowS
[Resource] -> ShowS
Resource -> String
(Int -> Resource -> ShowS)
-> (Resource -> String) -> ([Resource] -> ShowS) -> Show Resource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Resource] -> ShowS
$cshowList :: [Resource] -> ShowS
show :: Resource -> String
$cshow :: Resource -> String
showsPrec :: Int -> Resource -> ShowS
$cshowsPrec :: Int -> Resource -> ShowS
Show, (forall x. Resource -> Rep Resource x)
-> (forall x. Rep Resource x -> Resource) -> Generic Resource
forall x. Rep Resource x -> Resource
forall x. Resource -> Rep Resource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Resource x -> Resource
$cfrom :: forall x. Resource -> Rep Resource x
Generic)
$(deriveJSON (unPrefix "resource_") ''Resource)

instance Arbitrary Resource where
    arbitrary :: Gen Resource
arbitrary = Maybe Hash
-> Maybe Hash
-> Maybe Hash
-> [Event]
-> Status
-> UTCTime
-> Resource
Resource (Maybe Hash
 -> Maybe Hash
 -> Maybe Hash
 -> [Event]
 -> Status
 -> UTCTime
 -> Resource)
-> Gen (Maybe Hash)
-> Gen
     (Maybe Hash
      -> Maybe Hash -> [Event] -> Status -> UTCTime -> Resource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Maybe Hash)
forall a. Arbitrary a => Gen a
arbitrary
                         Gen
  (Maybe Hash
   -> Maybe Hash -> [Event] -> Status -> UTCTime -> Resource)
-> Gen (Maybe Hash)
-> Gen (Maybe Hash -> [Event] -> Status -> UTCTime -> Resource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Maybe Hash)
forall a. Arbitrary a => Gen a
arbitrary
                         Gen (Maybe Hash -> [Event] -> Status -> UTCTime -> Resource)
-> Gen (Maybe Hash)
-> Gen ([Event] -> Status -> UTCTime -> Resource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Maybe Hash)
forall a. Arbitrary a => Gen a
arbitrary
                         Gen ([Event] -> Status -> UTCTime -> Resource)
-> Gen [Event] -> Gen (Status -> UTCTime -> Resource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen [Event]
forall a. Arbitrary a => Gen a
arbitrary
                         Gen (Status -> UTCTime -> Resource)
-> Gen Status -> Gen (UTCTime -> Resource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Status
forall a. Arbitrary a => Gen a
arbitrary
                         Gen (UTCTime -> Resource) -> Gen UTCTime -> Gen Resource
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen UTCTime
forall a. Arbitrary a => Gen a
arbitrary

instance ToSchema Resource where
  declareNamedSchema :: Proxy Resource -> Declare (Definitions Schema) NamedSchema
declareNamedSchema = SchemaOptions
-> Proxy Resource -> Declare (Definitions Schema) NamedSchema
forall a.
(Generic a, GToSchema (Rep a),
 TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
SchemaOptions
-> Proxy a -> Declare (Definitions Schema) NamedSchema
genericDeclareNamedSchema (String -> SchemaOptions
unPrefixSwagger String
"resource_")

------------------------------------------------------------------------
-- | Then a Node can be either a Folder or a Corpus or a Document
data NodeType = NodeUser
              | NodeFolderPrivate
              | NodeFolderShared | NodeTeam
              | NodeFolderPublic
              | NodeFolder

              -- | NodeAnalysis | NodeCommunity

              | NodeCorpus     | NodeCorpusV3 | NodeTexts | NodeDocument
              | NodeAnnuaire   | NodeContact
              | NodeGraph      | NodePhylo
              | NodeDashboard  -- | NodeChart    | NodeNoteBook
              | NodeList       | NodeModel
              | NodeListCooc

{-
              -- | Metrics
              -- | NodeOccurrences
              -- | Classification
-}

              -- Optional Nodes
              | NodeFrameWrite | NodeFrameCalc | NodeFrameVisio | NodeFrameNotebook
              | NodeFile

  deriving (Int -> NodeType -> ShowS
[NodeType] -> ShowS
NodeType -> String
(Int -> NodeType -> ShowS)
-> (NodeType -> String) -> ([NodeType] -> ShowS) -> Show NodeType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NodeType] -> ShowS
$cshowList :: [NodeType] -> ShowS
show :: NodeType -> String
$cshow :: NodeType -> String
showsPrec :: Int -> NodeType -> ShowS
$cshowsPrec :: Int -> NodeType -> ShowS
Show, ReadPrec [NodeType]
ReadPrec NodeType
Int -> ReadS NodeType
ReadS [NodeType]
(Int -> ReadS NodeType)
-> ReadS [NodeType]
-> ReadPrec NodeType
-> ReadPrec [NodeType]
-> Read NodeType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NodeType]
$creadListPrec :: ReadPrec [NodeType]
readPrec :: ReadPrec NodeType
$creadPrec :: ReadPrec NodeType
readList :: ReadS [NodeType]
$creadList :: ReadS [NodeType]
readsPrec :: Int -> ReadS NodeType
$creadsPrec :: Int -> ReadS NodeType
Read, NodeType -> NodeType -> Bool
(NodeType -> NodeType -> Bool)
-> (NodeType -> NodeType -> Bool) -> Eq NodeType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NodeType -> NodeType -> Bool
$c/= :: NodeType -> NodeType -> Bool
== :: NodeType -> NodeType -> Bool
$c== :: NodeType -> NodeType -> Bool
Eq, (forall x. NodeType -> Rep NodeType x)
-> (forall x. Rep NodeType x -> NodeType) -> Generic NodeType
forall x. Rep NodeType x -> NodeType
forall x. NodeType -> Rep NodeType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NodeType x -> NodeType
$cfrom :: forall x. NodeType -> Rep NodeType x
Generic, NodeType
NodeType -> NodeType -> Bounded NodeType
forall a. a -> a -> Bounded a
maxBound :: NodeType
$cmaxBound :: NodeType
minBound :: NodeType
$cminBound :: NodeType
Bounded, Int -> NodeType
NodeType -> Int
NodeType -> [NodeType]
NodeType -> NodeType
NodeType -> NodeType -> [NodeType]
NodeType -> NodeType -> NodeType -> [NodeType]
(NodeType -> NodeType)
-> (NodeType -> NodeType)
-> (Int -> NodeType)
-> (NodeType -> Int)
-> (NodeType -> [NodeType])
-> (NodeType -> NodeType -> [NodeType])
-> (NodeType -> NodeType -> [NodeType])
-> (NodeType -> NodeType -> NodeType -> [NodeType])
-> Enum NodeType
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: NodeType -> NodeType -> NodeType -> [NodeType]
$cenumFromThenTo :: NodeType -> NodeType -> NodeType -> [NodeType]
enumFromTo :: NodeType -> NodeType -> [NodeType]
$cenumFromTo :: NodeType -> NodeType -> [NodeType]
enumFromThen :: NodeType -> NodeType -> [NodeType]
$cenumFromThen :: NodeType -> NodeType -> [NodeType]
enumFrom :: NodeType -> [NodeType]
$cenumFrom :: NodeType -> [NodeType]
fromEnum :: NodeType -> Int
$cfromEnum :: NodeType -> Int
toEnum :: Int -> NodeType
$ctoEnum :: Int -> NodeType
pred :: NodeType -> NodeType
$cpred :: NodeType -> NodeType
succ :: NodeType -> NodeType
$csucc :: NodeType -> NodeType
Enum)


allNodeTypes :: [NodeType]
allNodeTypes :: [NodeType]
allNodeTypes = [NodeType
forall a. Bounded a => a
minBound ..]

defaultName :: NodeType -> Text
defaultName :: NodeType -> Hash
defaultName NodeType
NodeUser       = Hash
"User"
defaultName NodeType
NodeContact    = Hash
"Contact"

defaultName NodeType
NodeCorpus     = Hash
"Corpus"
defaultName NodeType
NodeCorpusV3   = Hash
"Corpus"
defaultName NodeType
NodeAnnuaire   = Hash
"Annuaire"

defaultName NodeType
NodeDocument   = Hash
"Doc"
defaultName NodeType
NodeTexts      = Hash
"Docs"
defaultName NodeType
NodeList       = Hash
"List"
defaultName NodeType
NodeListCooc   = Hash
"List"
defaultName NodeType
NodeModel      = Hash
"Model"

defaultName NodeType
NodeFolder     = Hash
"Folder"
defaultName NodeType
NodeFolderPrivate = Hash
"Private Folder"
defaultName NodeType
NodeFolderShared  = Hash
"Shared Folder"
defaultName NodeType
NodeTeam          = Hash
"Folder"
defaultName NodeType
NodeFolderPublic  = Hash
"Public Folder"

defaultName NodeType
NodeDashboard     = Hash
"Board"
defaultName NodeType
NodeGraph         = Hash
"Graph"
defaultName NodeType
NodePhylo         = Hash
"Phylo"

defaultName NodeType
NodeFrameWrite    = Hash
"Frame Write"
defaultName NodeType
NodeFrameCalc     = Hash
"Frame Calc"
defaultName NodeType
NodeFrameVisio    = Hash
"Frame Visio"
defaultName NodeType
NodeFrameNotebook     = Hash
"Frame Code"

defaultName NodeType
NodeFile          = Hash
"File"


instance FromJSON NodeType
instance ToJSON NodeType

instance FromHttpApiData NodeType
  where
      parseUrlPiece :: Hash -> Either Hash NodeType
parseUrlPiece = NodeType -> Either Hash NodeType
forall a b. b -> Either a b
Right (NodeType -> Either Hash NodeType)
-> (Hash -> NodeType) -> Hash -> Either Hash NodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> NodeType
forall a. Read a => String -> a
read (String -> NodeType) -> (Hash -> String) -> Hash -> NodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash -> String
unpack

instance ToParamSchema NodeType
instance ToSchema      NodeType

instance Arbitrary NodeType where
  arbitrary :: Gen NodeType
arbitrary = [NodeType] -> Gen NodeType
forall a. [a] -> Gen a
elements [NodeType]
allNodeTypes



------------------------------------------------------------------------
-- Instances
------------------------------------------------------------------------
instance ToSchema Status where
  declareNamedSchema :: Proxy Status -> Declare (Definitions Schema) NamedSchema
declareNamedSchema = SchemaOptions
-> Proxy Status -> Declare (Definitions Schema) NamedSchema
forall a.
(Generic a, GToSchema (Rep a),
 TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
SchemaOptions
-> Proxy a -> Declare (Definitions Schema) NamedSchema
genericDeclareNamedSchema (String -> SchemaOptions
unPrefixSwagger String
"status_")

------------------------------------------------------------------------
{-
instance FromField (NodeId, Text)
  where
    fromField = fromField'
-}
------------------------------------------------------------------------
instance DefaultFromField PGTSVector (Maybe TSVector)
  where
    defaultFromField :: FromField PGTSVector (Maybe Hash)
defaultFromField = FromField PGTSVector (Maybe Hash)
forall haskell pgType.
FromField haskell =>
FromField pgType haskell
fieldQueryRunnerColumn

instance DefaultFromField PGInt4 (Maybe NodeId)
  where
    defaultFromField :: FromField PGInt4 (Maybe NodeId)
defaultFromField = FromField PGInt4 (Maybe NodeId)
forall haskell pgType.
FromField haskell =>
FromField pgType haskell
fieldQueryRunnerColumn

instance DefaultFromField PGInt4 NodeId
  where
    defaultFromField :: FromField PGInt4 NodeId
defaultFromField = FromField PGInt4 NodeId
forall haskell pgType.
FromField haskell =>
FromField pgType haskell
fieldQueryRunnerColumn

instance DefaultFromField (Nullable PGInt4) NodeId
  where
    defaultFromField :: FromField (Nullable PGInt4) NodeId
defaultFromField = FromField (Nullable PGInt4) NodeId
forall haskell pgType.
FromField haskell =>
FromField pgType haskell
fieldQueryRunnerColumn

instance (DefaultFromField (Nullable O.PGTimestamptz) UTCTime)
  where
    defaultFromField :: FromField (Nullable PGTimestamptz) UTCTime
defaultFromField = FromField (Nullable PGTimestamptz) UTCTime
forall haskell pgType.
FromField haskell =>
FromField pgType haskell
fieldQueryRunnerColumn

instance DefaultFromField PGText (Maybe Hash)
  where
    defaultFromField :: FromField PGText (Maybe Hash)
defaultFromField = FromField PGText (Maybe Hash)
forall haskell pgType.
FromField haskell =>
FromField pgType haskell
fieldQueryRunnerColumn