From df58c0f1c02665334f6addb138a1d62449da0a90 Mon Sep 17 00:00:00 2001 From: Maxim Avanov Date: Mon, 19 Apr 2021 17:08:40 +0100 Subject: [PATCH] Some comments --- .gitignore | 4 +++- CHANGELOG.md | 4 ++++ README.md | 21 +++++++++++++++++++++ servant-event-stream.cabal | 12 ++++++++++-- src/Servant/{ => API}/EventStream.hs | 10 +++++++++- tests/Spec.hs | 2 ++ 6 files changed, 49 insertions(+), 4 deletions(-) rename src/Servant/{ => API}/EventStream.hs (85%) create mode 100644 tests/Spec.hs diff --git a/.gitignore b/.gitignore index a7a832d..58fe346 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ dist/ dist-newstyle/ .ghc.environment.* -.stack-work/ \ No newline at end of file +.stack-work/ +# nix results +result \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 4020391..d2f891b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Revision history for servant-event-stream +## 0.2.0.0 -- 2021-04-x + +* `Servant.EventStream` was moved to `Servant.API.EventStream` to adhere existing [upstream layout](https://hackage.haskell.org/package/servant-0.18.2/docs/Servant-API-Stream.html). + ## 0.1.0.0 -- 2018-04-30 * First version. Released on an unsuspecting world. diff --git a/README.md b/README.md index e69de29..d8f282f 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,21 @@ +servant-event-stream +==================== + +This library adds necessary type combinators to support [Server Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) +within [Servant ecosystem](https://github.com/haskell-servant/). + +Dev Environment +--------------- + +Dev env is based on [Nix](https://nixos.org) and [Niv](https://github.com/nmattia/niv). + +To enter the dev shell, run +```bash + +nix-shell +``` + +You can build the project with +```bash +nix-build +``` \ No newline at end of file diff --git a/servant-event-stream.cabal b/servant-event-stream.cabal index 35bad60..24ae57e 100644 --- a/servant-event-stream.cabal +++ b/servant-event-stream.cabal @@ -1,6 +1,6 @@ cabal-version: >=1.10 name: servant-event-stream -version: 0.1.0.0 +version: 0.2.0.0 stability: alpha synopsis: Servant support for Server-Sent events @@ -26,7 +26,7 @@ source-repository head library exposed-modules: - Servant.EventStream + Servant.API.EventStream default-extensions: MultiParamTypeClasses @@ -48,3 +48,11 @@ library hs-source-dirs: src default-language: Haskell2010 ghc-options: -Wall + +test-suite tests-default + type: exitcode-stdio-1.0 + main-is: Spec.hs + hs-source-dirs: + tests + build-depends: + base \ No newline at end of file diff --git a/src/Servant/EventStream.hs b/src/Servant/API/EventStream.hs similarity index 85% rename from src/Servant/EventStream.hs rename to src/Servant/API/EventStream.hs index ca9bc5e..6fb29ac 100644 --- a/src/Servant/EventStream.hs +++ b/src/Servant/API/EventStream.hs @@ -8,7 +8,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} -module Servant.EventStream +module Servant.API.EventStream ( ServerSentEvents , EventStream , EventSource @@ -52,6 +52,7 @@ instance HasServer ServerSentEvents context where hoistServerWithContext Proxy = hoistServerWithContext (Proxy :: Proxy (StreamGet NoFraming EventStream EventSourceHdr)) +-- | a helper instance for instance (HasForeignType lang ftype EventSourceHdr) => HasForeign lang ftype ServerSentEvents where type Foreign ftype ServerSentEvents = Req ftype @@ -65,6 +66,9 @@ instance (HasForeignType lang ftype EventSourceHdr) retType = typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy EventSourceHdr) method = reflectMethod (Proxy :: Proxy 'GET) +-- | A type representation of an event stream. It's responsible for setting proper content-type +-- and buffering headers, as well as for providing parser implementations for the streams. +-- Read more on data EventStream instance Accept EventStream where @@ -72,8 +76,12 @@ instance Accept EventStream where type EventSource = SourceIO ServerEvent +-- | This is mostly to guide reverse-proxies like +-- type EventSourceHdr = Headers '[Header "X-Accel-Buffering" Text] EventSource +-- | See details at +-- https://hackage.haskell.org/package/wai-extra-3.1.6/docs/Network-Wai-EventSource-EventStream.html#v:eventToBuilder instance MimeRender EventStream ServerEvent where mimeRender _ = maybe "" toLazyByteString . eventToBuilder diff --git a/tests/Spec.hs b/tests/Spec.hs new file mode 100644 index 0000000..cd4753f --- /dev/null +++ b/tests/Spec.hs @@ -0,0 +1,2 @@ +main :: IO () +main = putStrLn "Test suite not yet implemented"