@@ -19,7 +19,6 @@ import Data.Traversable
19import Data.Vector qualified as V
19import Data.Vector qualified as V
20import GHC.Generics (Generic)
20import GHC.Generics (Generic)
21import Network.Wai.Handler.Warp qualified as Warp
21import Network.Wai.Handler.Warp qualified as Warp
22−import Network.Wai.Logger (withStdoutLogger)
23import Options.Applicative
22import Options.Applicative
24import ProjectM36.Base
23import ProjectM36.Base
25import ProjectM36.Client
24import ProjectM36.Client
@@ -98,23 +97,25 @@ encodeRelation (Relation (Attributes attrs) (RelationTupleSet tuples)) =
98 "vals" A..= (tuples <&> (\(RelationTuple _ atoms) -> encodeAtom <$> atoms))
97 "vals" A..= (tuples <&> (\(RelationTuple _ atoms) -> encodeAtom <$> atoms))
101−decodeRelationType :: V.Vector (Text, A.Value) -> A.Parser (V.Vector Attribute)
100+decodeRelationType :: A.Array -> A.Parser (V.Vector Attribute)
102−decodeRelationType =
101+decodeRelationType o =
103− traverse
102+ traverse parseJSON o
104− ( \(key, v) ->
104+ ( \(key, v) ->
105− Attribute key <$> case v of
105+ Attribute (Key.toText key) <$> case v of
106− A.String "int" -> pure IntAtomType
106+ A.String "int" -> pure IntAtomType
107− A.String "integer" -> pure IntegerAtomType
107+ A.String "integer" -> pure IntegerAtomType
108− A.String "scientific" -> pure ScientificAtomType
108+ A.String "scientific" -> pure ScientificAtomType
109− A.String "double" -> pure DoubleAtomType
109+ A.String "double" -> pure DoubleAtomType
110− A.String "text" -> pure TextAtomType
110+ A.String "text" -> pure TextAtomType
111− A.String "day" -> pure DayAtomType
111+ A.String "day" -> pure DayAtomType
112− A.String "datetime" -> pure DateTimeAtomType
112+ A.String "datetime" -> pure DateTimeAtomType
113− A.String "bytestring" -> pure ByteStringAtomType
113+ A.String "bytestring" -> pure ByteStringAtomType
114− A.String "bool" -> pure BoolAtomType
114+ A.String "bool" -> pure BoolAtomType
115− A.String "uuid" -> pure UUIDAtomType
115+ A.String "uuid" -> pure UUIDAtomType
116− x -> parseJSON x >>= fmap (RelationAtomType . Attributes) . decodeRelationType
116+ A.Array x -> RelationAtomType . Attributes <$> decodeRelationType x
117+ _ -> fail $ "unknown type: " <> show v
119decodeExpr :: A.Value -> A.Parser RelationalExpr
120decodeExpr :: A.Value -> A.Parser RelationalExpr
120decodeExpr = withObject "Expr" $ \o -> case KeyMap.toList o of
121decodeExpr = withObject "Expr" $ \o -> case KeyMap.toList o of
@@ -224,12 +225,8 @@ run = do
224 Right x -> pure x
225 Right x -> pure x
227− ( \conn -> withStdoutLogger $ \logger ->
228+ ( \conn ->
228 Warp.runSettings
229 Warp.runSettings
229− ( Warp.defaultSettings
230− & Warp.setServerName "project-m36-rest"
230+ (Warp.defaultSettings & Warp.setServerName "project-m36-rest" & Warp.setPort opts.port)
231− & Warp.setPort opts.port
232− & Warp.setLogger logger
234 (genericServe (server conn))
231 (genericServe (server conn))