-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Haskell binding for Gremlin graph query language - core data types and tools -- -- Haskell binding for Gremlin graph query language. See -- README.md for detail. -- -- This package contains only core data types and tools used commonly by -- other related packages. @package greskell-core @version 1.0.0.0 -- | This module is for advanced use. Most users should just use -- Data.Greskell.GraphSON. -- -- This module defines GValue and exposes its deconstructors. module Data.Greskell.GraphSON.GValue -- | An Aeson Value wrapped in GraphSON wrapper type. -- Basically this type is the Haskell representaiton of a -- GraphSON-encoded document. -- -- This type is used to parse GraphSON documents. See also -- FromGraphSON class. newtype GValue GValue :: GraphSON GValueBody -> GValue [unGValue] :: GValue -> GraphSON GValueBody -- | GValue without the top-level GraphSON wrapper. data GValueBody GObject :: !KeyMap GValue -> GValueBody GArray :: !Vector GValue -> GValueBody GString :: !Text -> GValueBody GNumber :: !Scientific -> GValueBody GBool :: !Bool -> GValueBody GNull :: GValueBody -- | Create a GValue without "@type" field. nonTypedGValue :: GValueBody -> GValue -- | Create a GValue with the given "@type" field. typedGValue' :: Text -> GValueBody -> GValue -- | Remove all GraphSON wrappers recursively from GValue. unwrapAll :: GValue -> Value -- | Remove the top-level GraphSON wrapper, but leave other wrappers -- as-is. The remaining wrappers are reconstructed by toJSON to -- make them into Value. unwrapOne :: GValue -> Value -- | Get the GValueBody from GValue. gValueBody :: GValue -> GValueBody -- | Get the gsonType field from GValue. gValueType :: GValue -> Maybe Text instance GHC.Generics.Generic Data.Greskell.GraphSON.GValue.GValue instance GHC.Classes.Eq Data.Greskell.GraphSON.GValue.GValue instance GHC.Show.Show Data.Greskell.GraphSON.GValue.GValue instance GHC.Generics.Generic Data.Greskell.GraphSON.GValue.GValueBody instance GHC.Classes.Eq Data.Greskell.GraphSON.GValue.GValueBody instance GHC.Show.Show Data.Greskell.GraphSON.GValue.GValueBody instance Data.Hashable.Class.Hashable Data.Greskell.GraphSON.GValue.GValue instance Data.Hashable.Class.Hashable Data.Greskell.GraphSON.GValue.GValueBody instance Data.Aeson.Types.FromJSON.FromJSON Data.Greskell.GraphSON.GValue.GValue instance Data.Aeson.Types.ToJSON.ToJSON Data.Greskell.GraphSON.GValue.GValue instance Data.Aeson.Types.ToJSON.ToJSON Data.Greskell.GraphSON.GValue.GValueBody -- | This module defines types for parsing a "g:Map" GraphSON object. -- Usually users only have to use GMapEntry, because other types -- are just used internally to implement GraphSON parsers. module Data.Greskell.GMap -- | JSON encoding of a map as an array of flattened key-value pairs. -- -- ToJSON instance of this type encodes the internal map as an -- array of keys and values. FromJSON instance of this type parses -- that flattened map. -- --
-- >>> let decode s = Aeson.eitherDecode s :: Either String (FlattenedMap HashMap Int String) -- -- >>> let toSortedList = sort . HashMap.toList . unFlattenedMap -- -- >>> fmap toSortedList $ decode "[10, \"ten\", 11, \"eleven\"]" -- Right [(10,"ten"),(11,"eleven")] -- -- >>> fmap toSortedList $ decode "[]" -- Right [] -- -- >>> let (Left err_msg) = decode "[10, \"ten\", 11]" -- -- >>> err_msg -- ...odd number of elements... -- -- >>> Aeson.encode $ FlattenedMap $ (HashMap.fromList [(10, "ten")] :: HashMap Int String) -- "[10,\"ten\"]" --newtype FlattenedMap c k v FlattenedMap :: c k v -> FlattenedMap c k v [unFlattenedMap] :: FlattenedMap c k v -> c k v -- | General parser for FlattenedMap. parseToFlattenedMap :: (IsList (c k v), Item (c k v) ~ (k, v)) => (s -> Parser k) -> (s -> Parser v) -> Vector s -> Parser (FlattenedMap c k v) -- | Haskell representation of g:Map type. -- -- GraphSON v1 and v2 encode Java Map type as a JSON Object, -- while GraphSON v3 encodes it as an array of flattened keys and values -- (like FlattenedMap.) GMap type handles both encoding -- schemes. -- --
-- >>> Aeson.eitherDecode "{\"ten\": 10}" :: Either String (GMap HashMap Text Int)
-- Right (GMap {gmapFlat = False, gmapValue = fromList [("ten",10)]})
--
-- >>> Aeson.eitherDecode "[\"ten\", 10]" :: Either String (GMap HashMap Text Int)
-- Right (GMap {gmapFlat = True, gmapValue = fromList [("ten",10)]})
--
-- >>> Aeson.encode $ GMap False (HashMap.fromList [(9, "nine")] :: HashMap Int Text)
-- "{\"9\":\"nine\"}"
--
-- >>> Aeson.encode $ GMap True (HashMap.fromList [(9, "nine")] :: HashMap Int Text)
-- "[9,\"nine\"]"
--
data GMap c k v
GMap :: !Bool -> !c k v -> GMap c k v
-- | If True, the map is encoded as an array. If False, it's
-- encoded as a JSON Object.
[gmapFlat] :: GMap c k v -> !Bool
-- | Map implementation.
[gmapValue] :: GMap c k v -> !c k v
-- | Get the map implementation from GMap.
unGMap :: GMap c k v -> c k v
-- | Create GMap that has the single GMapEntry.
singleton :: (IsList (c k v), Item (c k v) ~ (k, v)) => GMapEntry k v -> GMap c k v
-- | Deconstruct GMap into a list of GMapEntrys.
toList :: (IsList (c k v), Item (c k v) ~ (k, v)) => GMap c k v -> [GMapEntry k v]
-- | General parser for GMap.
parseToGMap :: (IsList (c k v), Item (c k v) ~ (k, v)) => (s -> Parser k) -> (s -> Parser v) -> (KeyMap s -> Parser (c k v)) -> Either (KeyMap s) (Vector s) -> Parser (GMap c k v)
-- | Haskell representation of Map.Entry type.
--
-- Basically GraphSON encodes Java's Map.Entry type as if it
-- were a Map with a single entry. Thus its encoded form is
-- either a JSON object or a flattened key-values, as explained in
-- GMap.
--
--
-- >>> Aeson.eitherDecode "{\"1\": \"one\"}" :: Either String (GMapEntry Int Text)
-- Right (GMapEntry {gmapEntryFlat = False, gmapEntryKey = 1, gmapEntryValue = "one"})
--
-- >>> Aeson.eitherDecode "[1, \"one\"]" :: Either String (GMapEntry Int Text)
-- Right (GMapEntry {gmapEntryFlat = True, gmapEntryKey = 1, gmapEntryValue = "one"})
--
-- >>> Aeson.encode (GMapEntry False "one" 1 :: GMapEntry Text Int)
-- "{\"one\":1}"
--
-- >>> Aeson.encode (GMapEntry True "one" 1 :: GMapEntry Text Int)
-- "[\"one\",1]"
--
--
-- In old versions of TinkerPop, Map.Entry is encoded as a JSON
-- object with "key" and "value" fields. FromJSON instance of
-- GMapEntry supports this format as well, but ToJSON
-- instance doesn't support it.
--
--
-- >>> Aeson.eitherDecode "{\"key\":1, \"value\": \"one\"}" :: Either String (GMapEntry Int Text)
-- Right (GMapEntry {gmapEntryFlat = False, gmapEntryKey = 1, gmapEntryValue = "one"})
--
data GMapEntry k v
GMapEntry :: !Bool -> !k -> !v -> GMapEntry k v
[gmapEntryFlat] :: GMapEntry k v -> !Bool
[gmapEntryKey] :: GMapEntry k v -> !k
[gmapEntryValue] :: GMapEntry k v -> !v
-- | Get the key-value pair from GMapEntry.
unGMapEntry :: GMapEntry k v -> (k, v)
-- | General parser for GMapEntry.
parseToGMapEntry :: FromJSONKey k => (s -> Parser k) -> (s -> Parser v) -> Either (KeyMap s) (Vector s) -> Parser (GMapEntry k v)
instance GHC.Base.Functor (c k) => GHC.Base.Functor (Data.Greskell.GMap.FlattenedMap c k)
instance Data.Traversable.Traversable (c k) => Data.Traversable.Traversable (Data.Greskell.GMap.FlattenedMap c k)
instance Data.Foldable.Foldable (c k) => Data.Foldable.Foldable (Data.Greskell.GMap.FlattenedMap c k)
instance GHC.Classes.Ord (c k v) => GHC.Classes.Ord (Data.Greskell.GMap.FlattenedMap c k v)
instance GHC.Classes.Eq (c k v) => GHC.Classes.Eq (Data.Greskell.GMap.FlattenedMap c k v)
instance GHC.Show.Show (c k v) => GHC.Show.Show (Data.Greskell.GMap.FlattenedMap c k v)
instance GHC.Base.Functor (c k) => GHC.Base.Functor (Data.Greskell.GMap.GMap c k)
instance Data.Traversable.Traversable (c k) => Data.Traversable.Traversable (Data.Greskell.GMap.GMap c k)
instance Data.Foldable.Foldable (c k) => Data.Foldable.Foldable (Data.Greskell.GMap.GMap c k)
instance GHC.Classes.Eq (c k v) => GHC.Classes.Eq (Data.Greskell.GMap.GMap c k v)
instance GHC.Show.Show (c k v) => GHC.Show.Show (Data.Greskell.GMap.GMap c k v)
instance GHC.Base.Functor (Data.Greskell.GMap.GMapEntry k)
instance Data.Traversable.Traversable (Data.Greskell.GMap.GMapEntry k)
instance Data.Foldable.Foldable (Data.Greskell.GMap.GMapEntry k)
instance (GHC.Classes.Ord k, GHC.Classes.Ord v) => GHC.Classes.Ord (Data.Greskell.GMap.GMapEntry k v)
instance (GHC.Classes.Eq k, GHC.Classes.Eq v) => GHC.Classes.Eq (Data.Greskell.GMap.GMapEntry k v)
instance (GHC.Show.Show k, GHC.Show.Show v) => GHC.Show.Show (Data.Greskell.GMap.GMapEntry k v)
instance Data.Greskell.GraphSON.GraphSONTyped.GraphSONTyped (Data.Greskell.GMap.GMapEntry k v)
instance (Data.Aeson.Types.FromJSON.FromJSON k, Data.Aeson.Types.FromJSON.FromJSONKey k, Data.Aeson.Types.FromJSON.FromJSON v) => Data.Aeson.Types.FromJSON.FromJSON (Data.Greskell.GMap.GMapEntry k v)
instance (Data.Aeson.Types.ToJSON.ToJSON k, Data.Aeson.Types.ToJSON.ToJSONKey k, GHC.Classes.Ord k, Data.Aeson.Types.ToJSON.ToJSON v) => Data.Aeson.Types.ToJSON.ToJSON (Data.Greskell.GMap.GMapEntry k v)
instance (Data.Aeson.Types.FromJSON.FromJSON k, Data.Aeson.Types.FromJSON.FromJSON v, GHC.Exts.IsList (c k v), GHC.Exts.Item (c k v) GHC.Types.~ (k, v), Data.Aeson.Types.FromJSON.FromJSON (c k v)) => Data.Aeson.Types.FromJSON.FromJSON (Data.Greskell.GMap.GMap c k v)
instance (Data.Aeson.Types.ToJSON.ToJSON k, Data.Aeson.Types.ToJSON.ToJSON v, GHC.Exts.IsList (c k v), GHC.Exts.Item (c k v) GHC.Types.~ (k, v), Data.Aeson.Types.ToJSON.ToJSON (c k v)) => Data.Aeson.Types.ToJSON.ToJSON (Data.Greskell.GMap.GMap c k v)
instance Data.Greskell.GraphSON.GraphSONTyped.GraphSONTyped (Data.Greskell.GMap.GMap c k v)
instance (Data.Aeson.Types.FromJSON.FromJSON k, Data.Aeson.Types.FromJSON.FromJSON v, GHC.Exts.IsList (c k v), GHC.Exts.Item (c k v) GHC.Types.~ (k, v)) => Data.Aeson.Types.FromJSON.FromJSON (Data.Greskell.GMap.FlattenedMap c k v)
instance (Data.Aeson.Types.ToJSON.ToJSON k, Data.Aeson.Types.ToJSON.ToJSON v, GHC.Exts.IsList (c k v), GHC.Exts.Item (c k v) GHC.Types.~ (k, v)) => Data.Aeson.Types.ToJSON.ToJSON (Data.Greskell.GMap.FlattenedMap c k v)
instance Data.Greskell.GraphSON.GraphSONTyped.GraphSONTyped (Data.Greskell.GMap.FlattenedMap c k v)
module Data.Greskell.GraphSON
-- | Wrapper for "typed JSON object" introduced in GraphSON version 2. See
-- http://tinkerpop.apache.org/docs/current/dev/io/#graphson
--
-- This data type is useful for encoding/decoding GraphSON text.
--
--
-- >>> Aeson.decode "1000" :: Maybe (GraphSON Int32)
-- Just (GraphSON {gsonType = Nothing, gsonValue = 1000})
--
-- >>> Aeson.decode "{\"@type\": \"g:Int32\", \"@value\": 1000}" :: Maybe (GraphSON Int32)
-- Just (GraphSON {gsonType = Just "g:Int32", gsonValue = 1000})
--
--
-- Note that encoding of the "g:Map" type is inconsistent between
-- GraphSON v1 and v2, v3. To handle the encoding, use
-- Data.Greskell.GMap.
data GraphSON v
GraphSON :: Maybe Text -> v -> GraphSON v
-- | Type ID, corresponding to @type field.
[gsonType] :: GraphSON v -> Maybe Text
-- | Value, correspoding to @value field.
[gsonValue] :: GraphSON v -> v
-- | Types that have an intrinsic type ID for gsonType field.
class GraphSONTyped a
-- | Type ID for gsonType.
gsonTypeFor :: GraphSONTyped a => a -> Text
-- | Create a GraphSON without gsonType.
--
--
-- >>> nonTypedGraphSON (10 :: Int)
-- GraphSON {gsonType = Nothing, gsonValue = 10}
--
nonTypedGraphSON :: v -> GraphSON v
-- | Create a GraphSON with its type ID.
--
--
-- >>> typedGraphSON (10 :: Int32)
-- GraphSON {gsonType = Just "g:Int32", gsonValue = 10}
--
typedGraphSON :: GraphSONTyped v => v -> GraphSON v
-- | Create a GraphSON with the given type ID.
--
--
-- >>> typedGraphSON' "g:Int32" (10 :: Int)
-- GraphSON {gsonType = Just "g:Int32", gsonValue = 10}
--
typedGraphSON' :: Text -> v -> GraphSON v
-- | Parse GraphSON v, but it checks gsonType. If
-- gsonType is Nothing or it's not equal to
-- gsonTypeFor, the Parser fails.
parseTypedGraphSON :: (GraphSONTyped v, FromJSON v) => Value -> Parser (GraphSON v)
-- | An Aeson Value wrapped in GraphSON wrapper type.
-- Basically this type is the Haskell representaiton of a
-- GraphSON-encoded document.
--
-- This type is used to parse GraphSON documents. See also
-- FromGraphSON class.
data GValue
-- | GValue without the top-level GraphSON wrapper.
data GValueBody
GObject :: !KeyMap GValue -> GValueBody
GArray :: !Vector GValue -> GValueBody
GString :: !Text -> GValueBody
GNumber :: !Scientific -> GValueBody
GBool :: !Bool -> GValueBody
GNull :: GValueBody
-- | Create a GValue without "@type" field.
nonTypedGValue :: GValueBody -> GValue
-- | Create a GValue with the given "@type" field.
typedGValue' :: Text -> GValueBody -> GValue
-- | Types that can be constructed from GValue. This is analogous to
-- FromJSON class.
--
-- Instances of basic types are implemented based on the following rule.
--
-- -- >>> toGremlin $ string "foo bar" -- "\"foo bar\"" -- -- >>> toGremlin $ string "escape newline\n escape dollar $" -- "\"escape newline\\n escape dollar \\$\"" --string :: Text -> Greskell Text -- | Boolean true literal. -- --
-- >>> toGremlin true -- "true" --true :: Greskell Bool -- | Boolean false literal. -- --
-- >>> toGremlin false -- "false" --false :: Greskell Bool -- | List literal. -- --
-- >>> toGremlin $ list ([100, 200, 300] :: [Greskell Int]) -- "[100,200,300]" --list :: [Greskell a] -> Greskell [a] -- | Make a list with a single object. Useful to prevent the Gremlin Server -- from automatically iterating the result object. -- --
-- >>> toGremlin $ single ("hoge" :: Greskell Text)
-- "[\"hoge\"]"
--
single :: Greskell a -> Greskell [a]
-- | Arbitrary precision number literal, like "123e8".
--
-- -- >>> toGremlin $ number 123e8 -- "1.23e10" --number :: Scientific -> Greskell Scientific -- | Aeson Value literal. -- --
-- >>> toGremlin $ value Aeson.Null -- "null" -- -- >>> toGremlin $ value $ Aeson.toJSON $ ([10, 20, 30] :: [Int]) -- "[10.0,20.0,30.0]" -- -- >>> toGremlin $ value $ Aeson.Object mempty -- "[:]" ---- -- Note that Number does not distinguish integers from -- floating-point numbers, so value function may format an integer -- as a floating-point number. To ensure formatting as integers, use -- valueInt. value :: Value -> Greskell Value -- | Integer literal as Value type. -- --
-- >>> toGremlin $ valueInt (100 :: Int) -- "100" --valueInt :: Integral a => a -> Greskell Value -- | Value literal as GValue type. gvalue :: Value -> Greskell GValue -- | Integer literal as GValue type. -- --
-- >>> toGremlin $ gvalueInt (256 :: Int) -- "256" --gvalueInt :: Integral a => a -> Greskell GValue -- | Unsafely create a Greskell of arbitrary type. The given Gremlin -- script is printed as-is. -- --
-- >>> toGremlin $ unsafeGreskell "x + 100" -- "x + 100" --unsafeGreskell :: Text -> Greskell a -- | Same as unsafeGreskell, but it takes lazy Text. unsafeGreskellLazy :: Text -> Greskell a -- | Unsafely create a Greskell that calls the given function with -- the given arguments. -- --
-- >>> toGremlin $ unsafeFunCall "add" ["10", "20"] -- "add(10,20)" --unsafeFunCall :: Text -> [Text] -> Greskell a -- | Unsafely create a Greskell that calls the given object method -- call with the given target and arguments. -- --
-- >>> toGremlin $ unsafeMethodCall ("foobar" :: Greskell Text) "length" []
-- "(\"foobar\").length()"
--
unsafeMethodCall :: Greskell a -> Text -> [Text] -> Greskell b
instance GHC.Classes.Ord (Data.Greskell.Greskell.Greskell a)
instance GHC.Classes.Eq (Data.Greskell.Greskell.Greskell a)
instance GHC.Show.Show (Data.Greskell.Greskell.Greskell a)
instance Data.Greskell.Greskell.ToGreskell (Data.Greskell.Greskell.Greskell a)
instance Data.String.IsString a => Data.String.IsString (Data.Greskell.Greskell.Greskell a)
instance GHC.Base.Functor Data.Greskell.Greskell.Greskell
instance GHC.Num.Num a => GHC.Num.Num (Data.Greskell.Greskell.Greskell a)
instance GHC.Real.Fractional a => GHC.Real.Fractional (Data.Greskell.Greskell.Greskell a)
instance Data.String.IsString a => GHC.Base.Semigroup (Data.Greskell.Greskell.Greskell a)
instance Data.String.IsString a => GHC.Base.Monoid (Data.Greskell.Greskell.Greskell a)