Fix hlint warnings for hlint v2.1.20 (#1320)
* Apply some hlint suggestions. * Simplify config parser (to avoid hlint error) * Reorganize for clarity (and fix hlint error) * Remove redundant language extension * Reformat slice more conventionally to avoid hlint bug * Refactor for clarity (and to avoid hlint error) * Simplify (and avoid hlint error) * Fix hlint complaint
This commit is contained in:
+2
-2
@@ -135,8 +135,8 @@ connectionStatus pool =
|
|||||||
|
|
||||||
shouldRetry :: RetryStatus -> ConnectionStatus -> IO Bool
|
shouldRetry :: RetryStatus -> ConnectionStatus -> IO Bool
|
||||||
shouldRetry rs isConnSucc = do
|
shouldRetry rs isConnSucc = do
|
||||||
delay <- pure $ fromMaybe 0 (rsPreviousDelay rs) `div` 1000000
|
let delay = fromMaybe 0 (rsPreviousDelay rs) `div` 1000000
|
||||||
itShould <- pure $ NotConnected == isConnSucc
|
itShould = NotConnected == isConnSucc
|
||||||
when itShould $
|
when itShould $
|
||||||
putStrLn $ "Attempting to reconnect to the database in " <> (show delay::Text) <> " seconds..."
|
putStrLn $ "Attempting to reconnect to the database in " <> (show delay::Text) <> " seconds..."
|
||||||
return itShould
|
return itShould
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ userApiRequest schema req reqBody
|
|||||||
, iColumns = columns
|
, iColumns = columns
|
||||||
, iOrder = [(toS k, toS $ fromJust v) | (k,v) <- qParams, isJust v, endingIn ["order"] k ]
|
, iOrder = [(toS k, toS $ fromJust v) | (k,v) <- qParams, isJust v, endingIn ["order"] k ]
|
||||||
, iCanonicalQS = toS $ urlEncodeVars
|
, iCanonicalQS = toS $ urlEncodeVars
|
||||||
. L.sortBy (comparing fst)
|
. L.sortOn fst
|
||||||
. map (join (***) toS . second (fromMaybe BS.empty))
|
. map (join (***) toS . second (fromMaybe BS.empty))
|
||||||
$ queryStringWPlus
|
$ queryStringWPlus
|
||||||
, iJWT = tokenStr
|
, iJWT = tokenStr
|
||||||
|
|||||||
+16
-10
@@ -146,18 +146,18 @@ readOptions = do
|
|||||||
AppConfig
|
AppConfig
|
||||||
<$> reqString "db-uri"
|
<$> reqString "db-uri"
|
||||||
<*> reqString "db-anon-role"
|
<*> reqString "db-anon-role"
|
||||||
<*> (mfilter (/= "") <$> optString "server-proxy-uri")
|
<*> optString "server-proxy-uri"
|
||||||
<*> reqString "db-schema"
|
<*> reqString "db-schema"
|
||||||
<*> (fromMaybe "!4" . mfilter (/= "") <$> optString "server-host")
|
<*> (fromMaybe "!4" <$> optString "server-host")
|
||||||
<*> (fromMaybe 3000 . join . fmap coerceInt <$> optValue "server-port")
|
<*> (fromMaybe 3000 <$> optInt "server-port")
|
||||||
<*> optString "server-unix-socket"
|
<*> optString "server-unix-socket"
|
||||||
<*> (fmap encodeUtf8 . mfilter (/= "") <$> optString "jwt-secret")
|
<*> (fmap encodeUtf8 <$> optString "jwt-secret")
|
||||||
<*> (fromMaybe False . join . fmap coerceBool <$> optValue "secret-is-base64")
|
<*> (fromMaybe False <$> optBool "secret-is-base64")
|
||||||
<*> parseJwtAudience "jwt-aud"
|
<*> parseJwtAudience "jwt-aud"
|
||||||
<*> (fromMaybe 10 . join . fmap coerceInt <$> optValue "db-pool")
|
<*> (fromMaybe 10 <$> optInt "db-pool")
|
||||||
<*> (fromMaybe 10 . join . fmap coerceInt <$> optValue "db-pool-timeout")
|
<*> (fromMaybe 10 <$> optInt "db-pool-timeout")
|
||||||
<*> (join . fmap coerceInt <$> optValue "max-rows")
|
<*> optInt "max-rows"
|
||||||
<*> (mfilter (/= "") <$> optString "pre-request")
|
<*> optString "pre-request"
|
||||||
<*> pure False
|
<*> pure False
|
||||||
<*> (fmap (fmap coerceText) <$> C.subassocs "app.settings" C.value)
|
<*> (fmap (fmap coerceText) <$> C.subassocs "app.settings" C.value)
|
||||||
<*> (maybe (Right [JSPKey "role"]) parseRoleClaimKey <$> optValue "role-claim-key")
|
<*> (maybe (Right [JSPKey "role"]) parseRoleClaimKey <$> optValue "role-claim-key")
|
||||||
@@ -176,11 +176,17 @@ readOptions = do
|
|||||||
reqString k = C.required k C.string
|
reqString k = C.required k C.string
|
||||||
|
|
||||||
optString :: C.Key -> C.Parser C.Config (Maybe Text)
|
optString :: C.Key -> C.Parser C.Config (Maybe Text)
|
||||||
optString k = C.optional k C.string
|
optString k = mfilter (/= "") <$> C.optional k C.string
|
||||||
|
|
||||||
optValue :: C.Key -> C.Parser C.Config (Maybe C.Value)
|
optValue :: C.Key -> C.Parser C.Config (Maybe C.Value)
|
||||||
optValue k = C.optional k C.value
|
optValue k = C.optional k C.value
|
||||||
|
|
||||||
|
optInt :: (Read i, Integral i) => C.Key -> C.Parser C.Config (Maybe i)
|
||||||
|
optInt k = join <$> C.optional k (coerceInt <$> C.value)
|
||||||
|
|
||||||
|
optBool :: C.Key -> C.Parser C.Config (Maybe Bool)
|
||||||
|
optBool k = join <$> C.optional k (coerceBool <$> C.value)
|
||||||
|
|
||||||
coerceText :: C.Value -> Text
|
coerceText :: C.Value -> Text
|
||||||
coerceText (C.String s) = s
|
coerceText (C.String s) = s
|
||||||
coerceText v = show v
|
coerceText v = show v
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ addForeignKeys :: [Relation] -> [Column] -> [Column]
|
|||||||
addForeignKeys rels = map addFk
|
addForeignKeys rels = map addFk
|
||||||
where
|
where
|
||||||
addFk col = col { colFK = fk col }
|
addFk col = col { colFK = fk col }
|
||||||
fk col = join $ relToFk col <$> find (lookupFn col) rels
|
fk col = find (lookupFn col) rels >>= relToFk col
|
||||||
lookupFn :: Column -> Relation -> Bool
|
lookupFn :: Column -> Relation -> Bool
|
||||||
lookupFn c Relation{relColumns=cs, relType=rty} = c `elem` cs && rty==Child
|
lookupFn c Relation{relColumns=cs, relType=rty} = c `elem` cs && rty==Child
|
||||||
relToFk col Relation{relColumns=cols, relFColumns=colsF} = do
|
relToFk col Relation{relColumns=cols, relFColumns=colsF} = do
|
||||||
@@ -295,19 +295,28 @@ addViewChildRelations allSyns = concatMap (\rel ->
|
|||||||
-- Relation is dependent on the order of relColumns and relFColumns to get the join conditions right in the generated query.
|
-- Relation is dependent on the order of relColumns and relFColumns to get the join conditions right in the generated query.
|
||||||
-- So we need to change the order of the synonyms to match the relColumns
|
-- So we need to change the order of the synonyms to match the relColumns
|
||||||
-- This could be avoided if the Relation type is improved with a structure that maintains the association of relColumns and relFColumns
|
-- This could be avoided if the Relation type is improved with a structure that maintains the association of relColumns and relFColumns
|
||||||
syns `sortAccordingTo` columns = sortOn (\(k, _) -> L.lookup k $ zip columns [0::Int ..]) syns in
|
syns `sortAccordingTo` columns = sortOn (\(k, _) -> L.lookup k $ zip columns [0::Int ..]) syns
|
||||||
|
|
||||||
-- View Table Child Relations
|
viewTableChild =
|
||||||
[Relation (getView syns) (snd <$> syns `sortAccordingTo` relColumns) relFTable relFColumns Child Nothing Nothing Nothing
|
[ Relation (getView syns) (snd <$> syns `sortAccordingTo` relColumns)
|
||||||
| syns <- colsSyns, syns `allSynsOf` relColumns] ++
|
relFTable relFColumns
|
||||||
|
Child Nothing Nothing Nothing
|
||||||
|
| syns <- colsSyns, syns `allSynsOf` relColumns ]
|
||||||
|
|
||||||
-- Table View Child Relations
|
tableViewChild =
|
||||||
[Relation relTable relColumns (getView fSyns) (snd <$> fSyns `sortAccordingTo` relFColumns) Child Nothing Nothing Nothing
|
[ Relation relTable relColumns
|
||||||
| fSyns <- fColsSyns, fSyns `allSynsOf` relFColumns] ++
|
(getView fSyns) (snd <$> fSyns `sortAccordingTo` relFColumns)
|
||||||
|
Child Nothing Nothing Nothing
|
||||||
|
| fSyns <- fColsSyns, fSyns `allSynsOf` relFColumns ]
|
||||||
|
|
||||||
-- View View Child Relations
|
viewViewChild =
|
||||||
[Relation (getView syns) (snd <$> syns `sortAccordingTo` relColumns) (getView fSyns) (snd <$> fSyns `sortAccordingTo` relFColumns) Child Nothing Nothing Nothing
|
[ Relation (getView syns) (snd <$> syns `sortAccordingTo` relColumns)
|
||||||
| syns <- colsSyns, fSyns <- fColsSyns, syns `allSynsOf` relColumns, fSyns `allSynsOf` relFColumns]
|
(getView fSyns) (snd <$> fSyns `sortAccordingTo` relFColumns)
|
||||||
|
Child Nothing Nothing Nothing
|
||||||
|
| syns <- colsSyns, syns `allSynsOf` relColumns
|
||||||
|
, fSyns <- fColsSyns, fSyns `allSynsOf` relFColumns ]
|
||||||
|
|
||||||
|
in viewTableChild ++ tableViewChild ++ viewViewChild
|
||||||
|
|
||||||
_ -> [])
|
_ -> [])
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ Module : PostgREST.Error
|
|||||||
Description : PostgREST error HTTP responses
|
Description : PostgREST error HTTP responses
|
||||||
-}
|
-}
|
||||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||||
{-# LANGUAGE FlexibleInstances #-}
|
{-# LANGUAGE FlexibleInstances #-}
|
||||||
{-# LANGUAGE TypeSynonymInstances #-}
|
|
||||||
|
|
||||||
module PostgREST.Error (
|
module PostgREST.Error (
|
||||||
errorResponseFor
|
errorResponseFor
|
||||||
|
|||||||
@@ -349,7 +349,7 @@ isUriValid:: URI -> Bool
|
|||||||
isUriValid = fAnd [isSchemeValid, isQueryValid, isAuthorityValid]
|
isUriValid = fAnd [isSchemeValid, isQueryValid, isAuthorityValid]
|
||||||
|
|
||||||
fAnd :: [a -> Bool] -> a -> Bool
|
fAnd :: [a -> Bool] -> a -> Bool
|
||||||
fAnd fs x = all ($x) fs
|
fAnd fs x = all ($ x) fs
|
||||||
|
|
||||||
isSchemeValid :: URI -> Bool
|
isSchemeValid :: URI -> Bool
|
||||||
isSchemeValid URI {uriScheme = s}
|
isSchemeValid URI {uriScheme = s}
|
||||||
|
|||||||
@@ -56,9 +56,11 @@ pRequestLogicTree (k, v) = mapError $ (,) <$> embedPath <*> logicTree
|
|||||||
where
|
where
|
||||||
path = parse pLogicPath ("failed to parser logic path (" ++ toS k ++ ")") $ toS k
|
path = parse pLogicPath ("failed to parser logic path (" ++ toS k ++ ")") $ toS k
|
||||||
embedPath = fst <$> path
|
embedPath = fst <$> path
|
||||||
op = snd <$> path
|
logicTree = do
|
||||||
-- Concat op and v to make pLogicTree argument regular, in the form of "?and=and(.. , ..)" instead of "?and=(.. , ..)"
|
op <- snd <$> path
|
||||||
logicTree = join $ parse pLogicTree ("failed to parse logic tree (" ++ toS v ++ ")") . toS <$> ((<>) <$> op <*> pure v)
|
-- Concat op and v to make pLogicTree argument regular,
|
||||||
|
-- in the form of "?and=and(.. , ..)" instead of "?and=(.. , ..)"
|
||||||
|
parse pLogicTree ("failed to parse logic tree (" ++ toS v ++ ")") $ toS (op <> v)
|
||||||
|
|
||||||
pRequestColumns :: Maybe Text -> Either ApiRequestError (Maybe (S.Set FieldName))
|
pRequestColumns :: Maybe Text -> Either ApiRequestError (Maybe (S.Set FieldName))
|
||||||
pRequestColumns colStr =
|
pRequestColumns colStr =
|
||||||
|
|||||||
+11
-10
@@ -91,20 +91,21 @@ instance Ord ProcDescription where
|
|||||||
| otherwise = (name1, des1, args1, rt1, vol1) `compare` (name2, des2, args2, rt2, vol2)
|
| otherwise = (name1, des1, args1, rt1, vol1) `compare` (name2, des2, args2, rt2, vol2)
|
||||||
|
|
||||||
{-|
|
{-|
|
||||||
Search a pg procedure by its parameters, since a function can be overloaded the name is not enough to find it.
|
Search a pg procedure by its parameters. Since a function can be overloaded, the name is not enough to find it.
|
||||||
An overloaded function can have a different volatility or even a different return type.
|
An overloaded function can have a different volatility or even a different return type.
|
||||||
-}
|
-}
|
||||||
findProc :: QualifiedIdentifier -> S.Set Text -> Bool -> M.HashMap Text [ProcDescription] -> Maybe ProcDescription
|
findProc :: QualifiedIdentifier -> S.Set Text -> Bool -> M.HashMap Text [ProcDescription] -> Maybe ProcDescription
|
||||||
findProc qi payloadKeys paramsAsSingleObject allProcs =
|
findProc qi payloadKeys paramsAsSingleObject allProcs =
|
||||||
let procs = M.lookup (qiName qi) allProcs in
|
case M.lookup (qiName qi) allProcs of
|
||||||
-- Handle overloaded functions case
|
Nothing -> Nothing
|
||||||
join $ (case length <$> procs of
|
Just [proc] -> Just proc -- if it's not an overloaded function then immediately get the ProcDescription
|
||||||
Just 1 -> headMay -- if it's not an overloaded function then immediatly get the ProcDescription
|
Just procs -> find matches procs -- Handle overloaded functions case
|
||||||
_ -> find (\x ->
|
where
|
||||||
if paramsAsSingleObject
|
matches proc =
|
||||||
then length (pdArgs x) == 1 -- if the arg is not of json type let the db give the err
|
if paramsAsSingleObject
|
||||||
else payloadKeys `S.isSubsetOf` S.fromList (pgaName <$> pdArgs x))
|
-- if the arg is not of json type let the db give the err
|
||||||
) <$> procs
|
then length (pdArgs proc) == 1
|
||||||
|
else payloadKeys `S.isSubsetOf` S.fromList (pgaName <$> pdArgs proc)
|
||||||
|
|
||||||
{-|
|
{-|
|
||||||
Search the procedure parameters by matching them with the specified keys.
|
Search the procedure parameters by matching them with the specified keys.
|
||||||
|
|||||||
+1
-1
@@ -55,7 +55,7 @@ main = do
|
|||||||
ver <- getPgVersion
|
ver <- getPgVersion
|
||||||
HT.transaction HT.ReadCommitted HT.Read $ getDbStructure "test" ver
|
HT.transaction HT.ReadCommitted HT.Read $ getDbStructure "test" ver
|
||||||
|
|
||||||
dbStructure <- pure $ either (panic.show) id result
|
let dbStructure = either (panic.show) id result
|
||||||
|
|
||||||
getTime <- mkAutoUpdate defaultUpdateSettings { updateAction = getCurrentTime }
|
getTime <- mkAutoUpdate defaultUpdateSettings { updateAction = getCurrentTime }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user