Different approach to commands (#34)

* different approach to command types (WIP)

* PartyProtocol class and other commands

* pretty-print scenarion

* remove old files

* remove unused prf/predicate templates

* remove NoImplicitePrelude from doctest (although there are no doctests atm)
This commit is contained in:
Evgeny Poberezkin
2020-05-31 21:51:15 +01:00
committed by GitHub
parent dc7835992c
commit cc55bf3e6b
16 changed files with 525 additions and 976 deletions

View File

@@ -1,109 +1,126 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Simplex.Messaging.ServerAPI
( ServerAPI
, serverApiIntro
, serverApiExtra
) where
( ServerAPI,
serverApiIntro,
serverApiExtra,
)
where
import ClassyPrelude
import Control.Lens
import Data.Function()
import Data.Function ()
import Servant
import Servant.Docs
import Simplex.Messaging.Types
type ServerAPI =
CreateConnection
:<|> SecureConnection
:<|> DeleteConnection
:<|> GetMessages
:<|> DeleteMessage
:<|> SendMessage
CreateConnection
:<|> SecureConnection
:<|> DeleteConnection
:<|> GetMessages
:<|> DeleteMessage
:<|> SendMessage
type CreateConnection = "connection" :> ReqBody '[JSON] CreateConnRequest
:> PostCreated '[JSON] CreateConnResponse
type CreateConnection =
"connection" :> ReqBody '[JSON] CreateConnRequest
:> PostCreated '[JSON] CreateConnResponse
type SecureConnection = "connection" :> Capture "connectionId" Base64EncodedString
:> ReqBody '[JSON] SecureConnRequest
:> Put '[JSON] NoContent
type SecureConnection =
"connection" :> Capture "connectionId" Base64EncodedString
:> ReqBody '[JSON] SecureConnRequest
:> Put '[JSON] NoContent
type DeleteConnection = "connection" :> Capture "connectionId" Base64EncodedString
:> Delete '[JSON] NoContent
type DeleteConnection =
"connection" :> Capture "connectionId" Base64EncodedString
:> Delete '[JSON] NoContent
type GetMessages = "connection" :> Capture "connectionId" Base64EncodedString :>
"messages" :> QueryParam "fromMessageId" (Maybe Base64EncodedString)
:> Get '[JSON] MessagesResponse
type GetMessages =
"connection" :> Capture "connectionId" Base64EncodedString
:> "messages"
:> QueryParam "fromMessageId" (Maybe Base64EncodedString)
:> Get '[JSON] MessagesResponse
type DeleteMessage = "connection" :> Capture "connectionId" Base64EncodedString :>
"messages" :> Capture "messageId" Base64EncodedString
:> Delete '[JSON] NoContent
type DeleteMessage =
"connection" :> Capture "connectionId" Base64EncodedString
:> "messages"
:> Capture "messageId" Base64EncodedString
:> Delete '[JSON] NoContent
type SendMessage = "connection" :> Capture "senderConnectionId" Base64EncodedString :>
"messages" :> ReqBody '[JSON] SendMessageRequest
:> PostCreated '[JSON] NoContent
type SendMessage =
"connection" :> Capture "senderConnectionId" Base64EncodedString
:> "messages"
:> ReqBody '[JSON] SendMessageRequest
:> PostCreated '[JSON] NoContent
-- API docs
serverApiIntro :: DocIntro
serverApiIntro = DocIntro "Simplex messaging protocol REST API"
[ "This document lists all required REST endpoints of simplex messaging API."
, "Also see [Simplex messaging protocol implementation](simplex-messaging-implementation.md) for more details."
]
serverApiIntro =
DocIntro
"Simplex messaging protocol REST API"
[ "This document lists all required REST endpoints of simplex messaging API.",
"Also see [Simplex messaging protocol implementation](simplex-messaging-implementation.md) for more details."
]
serverApiExtra :: ExtraInfo ServerAPI
serverApiExtra =
info (Proxy :: Proxy CreateConnection)
info
(Proxy :: Proxy CreateConnection)
"Create connection"
[]
<>
info (Proxy :: Proxy SecureConnection)
"Secure connection"
[]
<>
info (Proxy :: Proxy DeleteConnection)
"Delete connection"
[]
<>
info (Proxy :: Proxy GetMessages)
"Get messages"
[]
<>
info (Proxy :: Proxy DeleteMessage)
"Delete message"
[]
<>
info (Proxy :: Proxy SendMessage)
"Send message"
[]
<> info
(Proxy :: Proxy SecureConnection)
"Secure connection"
[]
<> info
(Proxy :: Proxy DeleteConnection)
"Delete connection"
[]
<> info
(Proxy :: Proxy GetMessages)
"Get messages"
[]
<> info
(Proxy :: Proxy DeleteMessage)
"Delete message"
[]
<> info
(Proxy :: Proxy SendMessage)
"Send message"
[]
where
info p title comments =
extraInfo p $ defAction & notes <>~ [DocNote title comments]
where
info p title comments =
extraInfo p $ defAction & notes <>~ [ DocNote title comments ]
instance ToCapture (Capture "connectionId" Text) where
instance ToCapture (Capture "connectionId" String) where
toCapture _ =
DocCapture "connectionId"
"Recipient connection ID - unique connection ID to be used by connection recipient"
DocCapture
"connectionId"
"Recipient connection ID - unique connection ID to be used by connection recipient"
instance ToCapture (Capture "senderConnectionId" Text) where
instance ToCapture (Capture "senderConnectionId" String) where
toCapture _ =
DocCapture "senderConnectionId"
"Sender connection ID - unique connection ID to be used by connection sender"
DocCapture
"senderConnectionId"
"Sender connection ID - unique connection ID to be used by connection sender"
instance ToCapture (Capture "messageId" Text) where
instance ToCapture (Capture "messageId" String) where
toCapture _ =
DocCapture "messageId"
"Message ID - unique message ID to be used by connection recipient"
DocCapture
"messageId"
"Message ID - unique message ID to be used by connection recipient"
instance ToParam (QueryParam "fromMessageId" (Maybe Base64EncodedString)) where
toParam _ =
DocQueryParam "fromMessageId"
["message ID, e.g., `p8PCiGPZ`"]
"if set, the server will respond with the messages received starting from the message with server message ID (unique per server) passed in this parameter."
Normal
DocQueryParam
"fromMessageId"
["message ID, e.g., `p8PCiGPZ`"]
"if set, the server will respond with the messages received starting from the message with server message ID (unique per server) passed in this parameter."
Normal
instance ToSample CreateConnRequest where
toSamples _ = singleSample $ CreateConnRequest "BODbZxmtKUUF1l8pj4nVjQ"
@@ -115,19 +132,24 @@ instance ToSample SecureConnRequest where
toSamples _ = singleSample $ SecureConnRequest "XPaVEVNunkYKqqK0dnAT5Q"
dummyMessage :: Message
dummyMessage = Message
{ connId = "p8PCiGPZ"
, ts = "2020-03-15T19:58:33.695Z"
, msg = "OQLMXoEA4iv-aR46puPJuY1Rdoc1KY0gfq8oElJwtAs"
}
dummyMessage =
Message
{ msgId = "p8PCiGPZ",
ts = "2020-03-15T19:58:33.695Z",
msg = "OQLMXoEA4iv-aR46puPJuY1Rdoc1KY0gfq8oElJwtAs"
}
instance ToSample MessagesResponse where
toSamples _ = singleSample $ MessagesResponse
{ messages = [dummyMessage]
, nextMessageId = Nothing
}
toSamples _ =
singleSample $
MessagesResponse
{ messages = [dummyMessage],
nextMessageId = Nothing
}
instance ToSample SendMessageRequest where
toSamples _ = singleSample $ SendMessageRequest
{ msg = "OQLMXoEA4iv-aR46puPJuY1Rdoc1KY0gfq8oElJwtAs"
}
toSamples _ =
singleSample $
SendMessageRequest
{ msg = "OQLMXoEA4iv-aR46puPJuY1Rdoc1KY0gfq8oElJwtAs"
}