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