A peer-to-peer stack for code collaboration
Add Value content type. (#588)
James Haydon9c1619a2e300
diff --git a/package.yaml b/package.yamlindex 8aab39a..4cc589d 100644--- a/package.yaml+++ b/package.yaml@@ -49,6 +49,7 @@ library:- http-client- http-conduit- http-types+ - http-media- ipld-cid- megaparsec- mtldiff --git a/src/Radicle/Daemon/HttpApi.hs b/src/Radicle/Daemon/HttpApi.hsindex ee5f8be..8eeae68 100644--- a/src/Radicle/Daemon/HttpApi.hs+++ b/src/Radicle/Daemon/HttpApi.hs@@ -25,12 +25,27 @@ import Data.Aeson ((.:), (.=))import qualified Data.Aeson as Aimport Data.Swaggerimport Data.Version (showVersion)+import qualified Network.HTTP.Media as HttpMediaimport Radicle.Daemon.Ipfsimport Servant.APIimport Servant.Swaggerimport qualified Paths_radicle as Radicle+import qualified Radicle.Internal.Annotation as Annimport Radicle.Internal.Core+import Radicle.Internal.Parse+import Radicle.Internal.Pretty++data RadicleData++instance Accept RadicleData where+ contentType _ = "application" HttpMedia.// "radicle"++instance ToRad Ann.WithPos a => MimeRender RadicleData a where+ mimeRender _ = toS . renderCompactPretty . (toRad :: a -> Value)++instance FromRad Ann.WithPos a => MimeUnrender RadicleData a where+ mimeUnrender _ = first toS . (fromRad <=< parse "[daemon]") . toSinstance FromHttpApiData MachineId whereparseUrlPiece = Right . MachineId . toS@@ -42,6 +57,9 @@ instance ToHttpApiData MachineId wherenewtype QueryRequest = QueryRequest { expression :: Value }deriving (Generic)+instance FromRad Ann.WithPos QueryRequest+instance ToRad Ann.WithPos QueryRequest+instance A.ToJSON QueryRequest wheretoJSON QueryRequest{..} = A.object[ "expression" .= valueToJson expression@@ -54,6 +72,9 @@ instance A.FromJSON QueryRequest wherenewtype QueryResponse = QueryResponse { result :: Value }deriving (Generic)+instance FromRad Ann.WithPos QueryResponse+instance ToRad Ann.WithPos QueryResponse+instance A.ToJSON QueryResponse wheretoJSON QueryResponse{..} = A.object[ "result" .= valueToJson result@@ -66,6 +87,9 @@ instance A.FromJSON QueryResponse wherenewtype SendRequest = SendRequest { expressions :: [Value] }deriving (Generic)+instance FromRad Ann.WithPos SendRequest+instance ToRad Ann.WithPos SendRequest+instance A.FromJSON SendRequest whereparseJSON = A.withObject "SendRequest" $ \o -> doexpressions <- o .: "expressions" >>= traverse jsonToValue@@ -79,6 +103,9 @@ newtype SendResponse = SendResponse{ results :: [Value]} deriving (Generic)+instance FromRad Ann.WithPos SendResponse+instance ToRad Ann.WithPos SendResponse+instance A.FromJSON SendResponse whereparseJSON = A.withObject "SendResponse" $ \o -> doresults <- o .: "results" >>= traverse jsonToValue@@ -92,23 +119,31 @@ newtype NewResponse = NewResponse{ machineId :: MachineId} deriving (Generic)+instance ToRad Ann.WithPos MachineId+instance FromRad Ann.WithPos MachineId++instance ToRad Ann.WithPos NewResponse+instance FromRad Ann.WithPos NewResponse+instance A.ToJSON NewResponseinstance A.FromJSON NewResponse-- * APIs+type Formats = '[JSON, RadicleData]+type MachinesEndpoint t = "v0" :> "machines" :> ttype MachineEndpoint t = MachinesEndpoint (Capture "machineId" MachineId :> t)-type MachineQueryEndpoint = MachineEndpoint ("query" :> ReqBody '[JSON] QueryRequest :> Post '[JSON] QueryResponse)+type MachineQueryEndpoint = MachineEndpoint ("query" :> ReqBody Formats QueryRequest :> Post Formats QueryResponse)machineQueryEndpoint :: Proxy MachineQueryEndpointmachineQueryEndpoint = Proxy-type MachineSendEndpoint = MachineEndpoint ("send" :> ReqBody '[JSON] SendRequest :> Post '[JSON] SendResponse)+type MachineSendEndpoint = MachineEndpoint ("send" :> ReqBody Formats SendRequest :> Post Formats SendResponse)machineSendEndpoint :: Proxy MachineSendEndpointmachineSendEndpoint = Proxy-type NewMachineEndpoint = MachinesEndpoint ("new" :> Post '[JSON] NewResponse)+type NewMachineEndpoint = MachinesEndpoint ("new" :> Post Formats NewResponse)newMachineEndpoint :: Proxy NewMachineEndpointnewMachineEndpoint = Proxy