hydra-pg-0.17.0: src/main/haskell/Hydra/Decode/Pg/Model.hs
-- Note: this is an automatically generated file. Do not edit.
-- | Term decoders for hydra.pg.model
module Hydra.Decode.Pg.Model where
import qualified Hydra.Core as Core
import qualified Hydra.Decode.Core as DecodeCore
import qualified Hydra.Errors as Errors
import qualified Hydra.Extract.Core as ExtractCore
import qualified Hydra.Graph as Graph
import qualified Hydra.Lexical as Lexical
import qualified Hydra.Overlay.Haskell.Lib.Eithers as Eithers
import qualified Hydra.Overlay.Haskell.Lib.Maps as Maps
import qualified Hydra.Overlay.Haskell.Lib.Optionals as Optionals
import qualified Hydra.Overlay.Haskell.Lib.Strings as Strings
import qualified Hydra.Pg.Model as Model
import qualified Hydra.Rewriting as Rewriting
import qualified Hydra.Util as Util
import Prelude hiding (Enum, Ordering, decodeFloat, encodeFloat, fail, map, pure, sum)
import qualified Data.Scientific as Sci
-- | Decoder for hydra.pg.model.AdjacentEdge
adjacentEdge :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError v) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.AdjacentEdge v)
adjacentEdge v cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "label" edgeLabel fieldMap cx) (\field_label -> Eithers.bind (ExtractCore.requireField "id" v fieldMap cx) (\field_id -> Eithers.bind (ExtractCore.requireField "vertex" v fieldMap cx) (\field_vertex -> Eithers.bind (ExtractCore.requireField "properties" (ExtractCore.decodeMap propertyKey v) fieldMap cx) (\field_properties -> Right (Model.AdjacentEdge {
Model.adjacentEdgeLabel = field_label,
Model.adjacentEdgeId = field_id,
Model.adjacentEdgeVertex = field_vertex,
Model.adjacentEdgeProperties = field_properties}))))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.pg.model.AdjacentEdge")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.Direction
direction :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Model.Direction
direction cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermInject v0 ->
let field = Core.injectionField v0
fname = Core.fieldName field
fterm = Core.fieldTerm field
variantMap =
Maps.fromList [
(Core.Name "out", (\input -> Eithers.map (\t -> Model.DirectionOut) (ExtractCore.decodeUnit cx input))),
(Core.Name "in", (\input -> Eithers.map (\t -> Model.DirectionIn) (ExtractCore.decodeUnit cx input))),
(Core.Name "both", (\input -> Eithers.map (\t -> Model.DirectionBoth) (ExtractCore.decodeUnit cx input))),
(Core.Name "undirected", (\input -> Eithers.map (\t -> Model.DirectionUndirected) (ExtractCore.decodeUnit cx input)))]
in (Optionals.cases (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.cat [
"no such field ",
(Core.unName fname),
" in union"]))) (\f -> f fterm))
_ -> Left (Errors.DecodingError "expected union")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.Edge
edge :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError v) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.Edge v)
edge v cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "label" edgeLabel fieldMap cx) (\field_label -> Eithers.bind (ExtractCore.requireField "id" v fieldMap cx) (\field_id -> Eithers.bind (ExtractCore.requireField "out" v fieldMap cx) (\field_out -> Eithers.bind (ExtractCore.requireField "in" v fieldMap cx) (\field_in -> Eithers.bind (ExtractCore.requireField "properties" (ExtractCore.decodeMap propertyKey v) fieldMap cx) (\field_properties -> Right (Model.Edge {
Model.edgeLabel = field_label,
Model.edgeId = field_id,
Model.edgeOut = field_out,
Model.edgeIn = field_in,
Model.edgeProperties = field_properties})))))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.pg.model.Edge")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.EdgeLabel
edgeLabel :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Model.EdgeLabel
edgeLabel cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermWrap v0 -> Eithers.map (\b -> Model.EdgeLabel b) ((\raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralString v2 -> Right v2
_ -> Left (Errors.DecodingError "expected string literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx raw2)) (Core.wrappedTermBody v0))
_ -> Left (Errors.DecodingError "expected wrapped type")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.EdgeType
edgeType :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError t) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.EdgeType t)
edgeType t cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "label" edgeLabel fieldMap cx) (\field_label -> Eithers.bind (ExtractCore.requireField "id" t fieldMap cx) (\field_id -> Eithers.bind (ExtractCore.requireField "out" vertexLabel fieldMap cx) (\field_out -> Eithers.bind (ExtractCore.requireField "in" vertexLabel fieldMap cx) (\field_in -> Eithers.bind (ExtractCore.requireField "properties" (ExtractCore.decodeList (propertyType t)) fieldMap cx) (\field_properties -> Right (Model.EdgeType {
Model.edgeTypeLabel = field_label,
Model.edgeTypeId = field_id,
Model.edgeTypeOut = field_out,
Model.edgeTypeIn = field_in,
Model.edgeTypeProperties = field_properties})))))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.pg.model.EdgeType")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.Element
element :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError v) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.Element v)
element v cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermInject v0 ->
let field = Core.injectionField v0
fname = Core.fieldName field
fterm = Core.fieldTerm field
variantMap =
Maps.fromList [
(Core.Name "vertex", (\input -> Eithers.map (\t -> Model.ElementVertex t) (vertex v cx input))),
(Core.Name "edge", (\input -> Eithers.map (\t -> Model.ElementEdge t) (edge v cx input)))]
in (Optionals.cases (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.cat [
"no such field ",
(Core.unName fname),
" in union"]))) (\f -> f fterm))
_ -> Left (Errors.DecodingError "expected union")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.ElementKind
elementKind :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Model.ElementKind
elementKind cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermInject v0 ->
let field = Core.injectionField v0
fname = Core.fieldName field
fterm = Core.fieldTerm field
variantMap =
Maps.fromList [
(Core.Name "vertex", (\input -> Eithers.map (\t -> Model.ElementKindVertex) (ExtractCore.decodeUnit cx input))),
(Core.Name "edge", (\input -> Eithers.map (\t -> Model.ElementKindEdge) (ExtractCore.decodeUnit cx input)))]
in (Optionals.cases (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.cat [
"no such field ",
(Core.unName fname),
" in union"]))) (\f -> f fterm))
_ -> Left (Errors.DecodingError "expected union")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.ElementTree
elementTree :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError v) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.ElementTree v)
elementTree v cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "self" (element v) fieldMap cx) (\field_self -> Eithers.bind (ExtractCore.requireField "dependencies" (ExtractCore.decodeList (elementTree v)) fieldMap cx) (\field_dependencies -> Right (Model.ElementTree {
Model.elementTreeSelf = field_self,
Model.elementTreeDependencies = field_dependencies}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.pg.model.ElementTree")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.ElementType
elementType :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError t) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.ElementType t)
elementType t cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermInject v0 ->
let field = Core.injectionField v0
fname = Core.fieldName field
fterm = Core.fieldTerm field
variantMap =
Maps.fromList [
(Core.Name "vertex", (\input -> Eithers.map (\t2 -> Model.ElementTypeVertex t2) (vertexType t cx input))),
(Core.Name "edge", (\input -> Eithers.map (\t2 -> Model.ElementTypeEdge t2) (edgeType t cx input)))]
in (Optionals.cases (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.cat [
"no such field ",
(Core.unName fname),
" in union"]))) (\f -> f fterm))
_ -> Left (Errors.DecodingError "expected union")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.ElementTypeTree
elementTypeTree :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError t) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.ElementTypeTree t)
elementTypeTree t cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "self" (elementType t) fieldMap cx) (\field_self -> Eithers.bind (ExtractCore.requireField "dependencies" (ExtractCore.decodeList (elementTypeTree t)) fieldMap cx) (\field_dependencies -> Right (Model.ElementTypeTree {
Model.elementTypeTreeSelf = field_self,
Model.elementTypeTreeDependencies = field_dependencies}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.pg.model.ElementTypeTree")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.Graph
graph :: Ord v => ((Graph.Graph -> Core.Term -> Either Errors.DecodingError v) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.Graph v))
graph v cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "vertices" (ExtractCore.decodeMap v (vertex v)) fieldMap cx) (\field_vertices -> Eithers.bind (ExtractCore.requireField "edges" (ExtractCore.decodeMap v (edge v)) fieldMap cx) (\field_edges -> Right (Model.Graph {
Model.graphVertices = field_vertices,
Model.graphEdges = field_edges}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.pg.model.Graph")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.GraphSchema
graphSchema :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError t) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.GraphSchema t)
graphSchema t cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "vertices" (ExtractCore.decodeMap vertexLabel (vertexType t)) fieldMap cx) (\field_vertices -> Eithers.bind (ExtractCore.requireField "edges" (ExtractCore.decodeMap edgeLabel (edgeType t)) fieldMap cx) (\field_edges -> Right (Model.GraphSchema {
Model.graphSchemaVertices = field_vertices,
Model.graphSchemaEdges = field_edges}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.pg.model.GraphSchema")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.Label
label :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Model.Label
label cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermInject v0 ->
let field = Core.injectionField v0
fname = Core.fieldName field
fterm = Core.fieldTerm field
variantMap =
Maps.fromList [
(Core.Name "vertex", (\input -> Eithers.map (\t -> Model.LabelVertex t) (vertexLabel cx input))),
(Core.Name "edge", (\input -> Eithers.map (\t -> Model.LabelEdge t) (edgeLabel cx input)))]
in (Optionals.cases (Maps.lookup fname variantMap) (Left (Errors.DecodingError (Strings.cat [
"no such field ",
(Core.unName fname),
" in union"]))) (\f -> f fterm))
_ -> Left (Errors.DecodingError "expected union")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.LazyGraph
lazyGraph :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError v) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.LazyGraph v)
lazyGraph v cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "vertices" (ExtractCore.decodeList (vertex v)) fieldMap cx) (\field_vertices -> Eithers.bind (ExtractCore.requireField "edges" (ExtractCore.decodeList (edge v)) fieldMap cx) (\field_edges -> Right (Model.LazyGraph {
Model.lazyGraphVertices = field_vertices,
Model.lazyGraphEdges = field_edges}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.pg.model.LazyGraph")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.Property
property :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError v) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.Property v)
property v cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "key" propertyKey fieldMap cx) (\field_key -> Eithers.bind (ExtractCore.requireField "value" v fieldMap cx) (\field_value -> Right (Model.Property {
Model.propertyKey = field_key,
Model.propertyValue = field_value}))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.pg.model.Property")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.PropertyKey
propertyKey :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Model.PropertyKey
propertyKey cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermWrap v0 -> Eithers.map (\b -> Model.PropertyKey b) ((\raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralString v2 -> Right v2
_ -> Left (Errors.DecodingError "expected string literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx raw2)) (Core.wrappedTermBody v0))
_ -> Left (Errors.DecodingError "expected wrapped type")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.PropertyType
propertyType :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError t) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.PropertyType t)
propertyType t cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "key" propertyKey fieldMap cx) (\field_key -> Eithers.bind (ExtractCore.requireField "value" t fieldMap cx) (\field_value -> Eithers.bind (ExtractCore.requireField "required" (\cx2 -> \raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralBoolean v2 -> Right v2
_ -> Left (Errors.DecodingError "expected boolean literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx2 raw2)) fieldMap cx) (\field_required -> Right (Model.PropertyType {
Model.propertyTypeKey = field_key,
Model.propertyTypeValue = field_value,
Model.propertyTypeRequired = field_required})))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.pg.model.PropertyType")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.Vertex
vertex :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError v) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.Vertex v)
vertex v cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "label" vertexLabel fieldMap cx) (\field_label -> Eithers.bind (ExtractCore.requireField "id" v fieldMap cx) (\field_id -> Eithers.bind (ExtractCore.requireField "properties" (ExtractCore.decodeMap propertyKey v) fieldMap cx) (\field_properties -> Right (Model.Vertex {
Model.vertexLabel = field_label,
Model.vertexId = field_id,
Model.vertexProperties = field_properties})))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.pg.model.Vertex")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.VertexLabel
vertexLabel :: Graph.Graph -> Core.Term -> Either Errors.DecodingError Model.VertexLabel
vertexLabel cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermWrap v0 -> Eithers.map (\b -> Model.VertexLabel b) ((\raw2 -> Eithers.either (\err -> Left err) (\stripped2 -> case stripped2 of
Core.TermLiteral v1 -> case v1 of
Core.LiteralString v2 -> Right v2
_ -> Left (Errors.DecodingError "expected string literal")
_ -> Left (Errors.DecodingError "expected literal")) (ExtractCore.stripWithDecodingError cx raw2)) (Core.wrappedTermBody v0))
_ -> Left (Errors.DecodingError "expected wrapped type")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.VertexType
vertexType :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError t) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.VertexType t)
vertexType t cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "label" vertexLabel fieldMap cx) (\field_label -> Eithers.bind (ExtractCore.requireField "id" t fieldMap cx) (\field_id -> Eithers.bind (ExtractCore.requireField "properties" (ExtractCore.decodeList (propertyType t)) fieldMap cx) (\field_properties -> Right (Model.VertexType {
Model.vertexTypeLabel = field_label,
Model.vertexTypeId = field_id,
Model.vertexTypeProperties = field_properties})))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.pg.model.VertexType")) (ExtractCore.stripWithDecodingError cx raw)
-- | Decoder for hydra.pg.model.VertexWithAdjacentEdges
vertexWithAdjacentEdges :: (Graph.Graph -> Core.Term -> Either Errors.DecodingError v) -> Graph.Graph -> Core.Term -> Either Errors.DecodingError (Model.VertexWithAdjacentEdges v)
vertexWithAdjacentEdges v cx raw =
Eithers.either (\err -> Left err) (\stripped -> case stripped of
Core.TermRecord v0 ->
let fieldMap = ExtractCore.toFieldMap v0
in (Eithers.bind (ExtractCore.requireField "vertex" (vertex v) fieldMap cx) (\field_vertex -> Eithers.bind (ExtractCore.requireField "ins" (ExtractCore.decodeList (adjacentEdge v)) fieldMap cx) (\field_ins -> Eithers.bind (ExtractCore.requireField "outs" (ExtractCore.decodeList (adjacentEdge v)) fieldMap cx) (\field_outs -> Right (Model.VertexWithAdjacentEdges {
Model.vertexWithAdjacentEdgesVertex = field_vertex,
Model.vertexWithAdjacentEdgesIns = field_ins,
Model.vertexWithAdjacentEdgesOuts = field_outs})))))
_ -> Left (Errors.DecodingError "expected a record of type hydra.pg.model.VertexWithAdjacentEdges")) (ExtractCore.stripWithDecodingError cx raw)