postgres-websockets 0.4.2.0 → 0.4.2.1
raw patch · 6 files changed
+17/−20 lines, 6 files
Files
- app/Config.hs +4/−7
- app/Main.hs +2/−2
- postgres-websockets.cabal +2/−2
- src/PostgresWebsockets.hs +3/−3
- test/DatabaseSpec.hs +2/−2
- test/HasqlBroadcastSpec.hs +4/−4
app/Config.hs view
@@ -29,7 +29,7 @@ import Data.Text.Encoding (encodeUtf8) import Data.Version (versionBranch) import Options.Applicative hiding (str)-import Paths_postgrest_ws (version)+import Paths_postgres_websockets (version) import Text.Heredoc import Text.PrettyPrint.ANSI.Leijen hiding ((<>)) import qualified Text.PrettyPrint.ANSI.Leijen as L@@ -80,9 +80,9 @@ opts = info (helper <*> pathParser) $ fullDesc <> progDesc (- "PostgREST "+ "postgres-websockets " <> toS prettyVersion- <> " / create a REST API to an existing Postgres database"+ <> " / Connects websockets to PostgreSQL asynchronous notifications." ) <> footerDoc (Just $ text "Example Config File:"@@ -97,10 +97,7 @@ missingKeyHint :: C.KeyError -> IO a missingKeyHint (C.KeyError n) = die $- "Required config parameter \"" <> n <> "\" is missing or of wrong type.\n" <>- "Documentation for configuration options available at\n" <>- "\thttp://postgrest.com/en/v0.4/admin.html#configuration\n\n" <>- "Try the --example-config option to see how to configure PostgREST."+ "Required config parameter \"" <> n <> "\" is missing or of wrong type.\n" exampleCfg :: Doc exampleCfg = vsep . map (text . toS) . lines $
app/Main.hs view
@@ -46,7 +46,7 @@ pgSettings = toS (configDatabase conf) appSettings = setHost ((fromString . toS) host) . setPort port- . setServerName (toS $ "postgrest/" <> prettyVersion)+ . setServerName (toS $ "postgres-websockets/" <> prettyVersion) . setTimeout 3600 $ defaultSettings @@ -56,7 +56,7 @@ multi <- newHasqlBroadcaster pgSettings runSettings appSettings $- postgrestWsMiddleware (toS <$> configAuditChannel conf) (configJwtSecret conf) pool multi $+ postgresWsMiddleware (toS <$> configAuditChannel conf) (configJwtSecret conf) pool multi $ logStdout $ staticApp $ defaultFileServerSettings $ toS $ configPath conf loadSecretFile :: AppConfig -> IO AppConfig
postgres-websockets.cabal view
@@ -1,6 +1,6 @@ name: postgres-websockets-version: 0.4.2.0-synopsis: PostgREST extension to map LISTEN/NOTIFY messages to Websockets+version: 0.4.2.1+synopsis: Middleware to map LISTEN/NOTIFY messages to Websockets description: Please see README.md homepage: https://github.com/diogob/postgres-websockets#readme license: BSD3
src/PostgresWebsockets.hs view
@@ -4,7 +4,7 @@ {-# LANGUAGE DeriveGeneric #-} module PostgresWebsockets- ( postgrestWsMiddleware+ ( postgresWsMiddleware -- * Re-exports , newHasqlBroadcaster , newHasqlBroadcasterOrError@@ -37,8 +37,8 @@ instance A.ToJSON Message -- | Given a secret, a function to fetch the system time, a Hasql Pool and a Multiplexer this will give you a WAI middleware.-postgrestWsMiddleware :: Maybe ByteString -> ByteString -> H.Pool -> Multiplexer -> Wai.Application -> Wai.Application-postgrestWsMiddleware =+postgresWsMiddleware :: Maybe ByteString -> ByteString -> H.Pool -> Multiplexer -> Wai.Application -> Wai.Application+postgresWsMiddleware = WS.websocketsOr WS.defaultConnectionOptions `compose` wsApp where compose = (.) . (.) . (.) . (.)
test/DatabaseSpec.hs view
@@ -12,14 +12,14 @@ spec = describe "waitForNotifications" $ it "does not block the connection ann trigger action upon notification" $ do- conOrError <- H.acquire "postgres://localhost/postgrest_test"+ conOrError <- H.acquire "postgres://localhost/postgres_ws_test" let con = either (panic . show) id conOrError :: H.Connection notification <- liftIO newEmptyMVar waitForNotifications (curry $ putMVar notification) con listen con $ toPgIdentifier "test" - conOrError2 <- H.acquire "postgres://localhost/postgrest_test"+ conOrError2 <- H.acquire "postgres://localhost/postgres_ws_test" let con2 = either (panic . show) id conOrError2 :: H.Connection void $ notify con2 (toPgIdentifier "test") "hello there"
test/HasqlBroadcastSpec.hs view
@@ -24,8 +24,8 @@ <$> acquire connStr it "start listening on a database connection as we send an Open command" $ do- con <- newConnection "postgres://localhost/postgrest_test"- multi <- liftIO $ newHasqlBroadcaster "postgres://localhost/postgrest_test"+ con <- newConnection "postgres://localhost/postgres_ws_test"+ multi <- liftIO $ newHasqlBroadcaster "postgres://localhost/postgres_ws_test" atomically $ openChannelProducer multi "test channel" threadDelay 1000000@@ -36,8 +36,8 @@ booleanQueryShouldReturn con query True it "stops listening on a database connection as we send a Close command" $ do- con <- newConnection "postgres://localhost/postgrest_test"- multi <- liftIO $ newHasqlBroadcaster "postgres://localhost/postgrest_test"+ con <- newConnection "postgres://localhost/postgres_ws_test"+ multi <- liftIO $ newHasqlBroadcaster "postgres://localhost/postgres_ws_test" atomically $ closeChannelProducer multi "test channel" threadDelay 1000000