@@ -19,6 +19,7 @@ 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)
22import Options.Applicative
23import Options.Applicative
23import ProjectM36.Base
24import ProjectM36.Base
24import ProjectM36.Client
25import ProjectM36.Client
@@ -97,25 +98,23 @@ encodeRelation (Relation (Attributes attrs) (RelationTupleSet tuples)) =
97 "vals" A..= (tuples <&> (\(RelationTuple _ atoms) -> encodeAtom <$> atoms))
98 "vals" A..= (tuples <&> (\(RelationTuple _ atoms) -> encodeAtom <$> atoms))
100−decodeRelationType :: A.Array -> A.Parser (V.Vector Attribute)
101+decodeRelationType :: V.Vector (Text, A.Value) -> A.Parser (V.Vector Attribute)
101−decodeRelationType o =
102+decodeRelationType =
102− traverse parseJSON o
103+ traverse
104− ( \(key, v) ->
104+ ( \(key, v) ->
105− Attribute (Key.toText key) <$> case v of
105+ Attribute 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− A.Array x -> RelationAtomType . Attributes <$> decodeRelationType x
116+ x -> parseJSON x >>= fmap (RelationAtomType . Attributes) . decodeRelationType
117− _ -> fail $ "unknown type: " <> show v
120decodeExpr :: A.Value -> A.Parser RelationalExpr
119decodeExpr :: A.Value -> A.Parser RelationalExpr
121decodeExpr = withObject "Expr" $ \o -> case KeyMap.toList o of
120decodeExpr = withObject "Expr" $ \o -> case KeyMap.toList o of
@@ -225,8 +224,12 @@ run = do
225 Right x -> pure x
224 Right x -> pure x
228− ( \conn ->
227+ ( \conn -> withStdoutLogger $ \logger ->
229 Warp.runSettings
228 Warp.runSettings
229+ ( Warp.defaultSettings
230− (Warp.defaultSettings & Warp.setServerName "project-m36-rest" & Warp.setPort opts.port)
230+ & Warp.setServerName "project-m36-rest"
231+ & Warp.setPort opts.port
232+ & Warp.setLogger logger
231 (genericServe (server conn))
234 (genericServe (server conn))