Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage: Use OverloadedRecordDot instead of RecordWildCards #2671

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let
src =
pkgs.lib.sourceFilesBySuffices
(pkgs.gitignoreSource ./.)
[ ".cabal" ".hs" ".lhs" "LICENSE" ];
[ ".cabal" ".hs" ".hs-boot" ".lhs" "LICENSE" ];

allOverlays =
import nix/overlays;
Expand Down
9 changes: 5 additions & 4 deletions src/PostgREST/Admin.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedRecordDot #-}

module PostgREST.Admin
( runAdmin
Expand Down Expand Up @@ -30,17 +31,17 @@ import Protolude
runAdmin :: AppState -> Warp.Settings -> IO ()
runAdmin appState settings = do
AppConfig{configAdminServerPort} <- AppState.getConfig appState
whenJust (AppState.getSocketAdmin appState) $ \adminSocket -> do
whenJust appState.socketAdmin $ \adminSocket -> do
observer $ AdminStartObs configAdminServerPort
void . forkIO $ Warp.runSettingsSocket settings adminSocket adminApp
where
adminApp = admin appState
observer = AppState.getObserver appState
observer = appState.observer

-- | PostgREST admin application
admin :: AppState.AppState -> Wai.Application
admin appState req respond = do
isMainAppReachable <- isRight <$> reachMainApp (AppState.getSocketREST appState)
isMainAppReachable <- isRight <$> reachMainApp appState.socketREST
isLoaded <- AppState.isLoaded appState
isPending <- AppState.isPending appState

Expand Down
26 changes: 13 additions & 13 deletions src/PostgREST/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Some of its functionality includes:
- Producing HTTP Headers according to RFCs.
- Content Negotiation
-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE RecordWildCards #-}
module PostgREST.App
( postgrest
, run
Expand Down Expand Up @@ -40,8 +41,7 @@ import qualified PostgREST.Response as Response
import qualified PostgREST.Unix as Unix (installSignalHandlers)

import PostgREST.ApiRequest (ApiRequest (..))
import PostgREST.AppState (AppState)
import PostgREST.Auth (AuthResult (..))
import PostgREST.AppState (AppState (..))
import PostgREST.Config (AppConfig (..), LogLevel (..))
import PostgREST.Config.PgVersion (PgVersion (..))
import PostgREST.Error (Error)
Expand All @@ -62,28 +62,28 @@ type Handler = ExceptT Error

run :: AppState -> IO ()
run appState = do
let observer = AppState.getObserver appState
let observer = appState.observer
conf@AppConfig{..} <- AppState.getConfig appState

observer $ AppStartObs prettyVersion

AppState.connectionWorker appState -- Loads the initial SchemaCache
Unix.installSignalHandlers (AppState.getMainThreadId appState) (AppState.connectionWorker appState) (AppState.reReadConfig False appState)
appState.debouncedConnectionWorker -- Loads the initial SchemaCache
Unix.installSignalHandlers appState.mainThreadId appState.debouncedConnectionWorker (AppState.reReadConfig False appState)
-- reload schema cache + config on NOTIFY
AppState.runListener appState

Admin.runAdmin appState (serverSettings conf)

let app = postgrest configLogLevel appState (AppState.connectionWorker appState)
let app = postgrest configLogLevel appState appState.debouncedConnectionWorker

case configServerUnixSocket of
Just path -> do
observer $ AppServerUnixObs path
Nothing -> do
port <- NS.socketPort $ AppState.getSocketREST appState
port <- NS.socketPort appState.socketREST
observer $ AppServerPortObs port

Warp.runSettingsSocket (serverSettings conf) (AppState.getSocketREST appState) app
Warp.runSettingsSocket (serverSettings conf) appState.socketREST app

serverSettings :: AppConfig -> Warp.Settings
serverSettings AppConfig{..} =
Expand All @@ -100,7 +100,7 @@ postgrest logLevel appState connWorker =
Auth.middleware appState .
Logger.middleware logLevel Auth.getRole $
-- fromJust can be used, because the auth middleware will **always** add
-- some AuthResult to the vault.
-- some Auth.Result to the vault.
\req respond -> case fromJust $ Auth.getResult req of
Left err -> respond $ Error.errorResponseFor err
Right authResult -> do
Expand Down Expand Up @@ -128,10 +128,10 @@ postgrestResponse
-> AppConfig
-> Maybe SchemaCache
-> PgVersion
-> AuthResult
-> Auth.Result
-> Wai.Request
-> Handler IO Wai.Response
postgrestResponse appState conf@AppConfig{..} maybeSchemaCache pgVer authResult@AuthResult{..} req = do
postgrestResponse appState conf@AppConfig{..} maybeSchemaCache pgVer authResult req = do
sCache <-
case maybeSchemaCache of
Just sCache ->
Expand All @@ -145,7 +145,7 @@ postgrestResponse appState conf@AppConfig{..} maybeSchemaCache pgVer authResult@

(parseTime, apiReq@ApiRequest{..}) <- withTiming $ liftEither . mapLeft Error.ApiRequestError $ ApiRequest.userApiRequest conf req body sCache
(planTime, plan) <- withTiming $ liftEither $ Plan.actionPlan iAction conf apiReq sCache
(queryTime, queryResult) <- withTiming $ Query.runQuery appState conf authResult apiReq plan sCache pgVer (Just authRole /= configDbAnonRole)
(queryTime, queryResult) <- withTiming $ Query.runQuery appState conf authResult apiReq plan sCache pgVer (Just authResult.role /= configDbAnonRole)
(respTime, resp) <- withTiming $ liftEither $ Response.actionResponse queryResult apiReq (T.decodeUtf8 prettyVersion, docsVersion) conf sCache iSchema iNegotiatedByProfile

return $ toWaiResponse (ServerTiming jwtTime parseTime planTime queryTime respTime) resp
Expand Down
Loading
Loading