From 5e6987b1d8a03e7bfaf618c255fa249562973520 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Mon, 13 Jun 2022 13:11:16 +0200 Subject: [PATCH] src: consistently import HashMap as HM, Map as M With both HashMap and Map imported as M in different modules, linter rules prevented ever importing both modules in one place. --- src/PostgREST/App.hs | 12 ++++----- src/PostgREST/Auth.hs | 10 +++---- src/PostgREST/DbStructure.hs | 14 +++++----- src/PostgREST/DbStructure/Proc.hs | 4 +-- src/PostgREST/DbStructure/Relationship.hs | 4 +-- src/PostgREST/DbStructure/Table.hs | 4 +-- src/PostgREST/GucHeader.hs | 4 +-- src/PostgREST/Middleware.hs | 8 +++--- src/PostgREST/OpenAPI.hs | 10 +++---- src/PostgREST/Request/ApiRequest.hs | 32 +++++++++++------------ src/PostgREST/Request/DbRequestBuilder.hs | 6 ++--- src/PostgREST/Request/QueryParams.hs | 12 ++++----- 12 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/PostgREST/App.hs b/src/PostgREST/App.hs index b5d9f59bd..b4555f5b0 100644 --- a/src/PostgREST/App.hs +++ b/src/PostgREST/App.hs @@ -28,7 +28,7 @@ import System.Posix.Types (FileMode) import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Lazy as LBS -import qualified Data.HashMap.Strict as M +import qualified Data.HashMap.Strict as HM import qualified Data.Set as S import qualified Hasql.DynamicStatements.Snippet as SQL (Snippet) import qualified Hasql.Pool as SQL @@ -314,7 +314,7 @@ handleCreate identifier@QualifiedIdentifier{..} context@RequestContext{..} = do let ApiRequest{..} = ctxApiRequest pkCols = if iPreferRepresentation /= None || isJust iPreferResolution - then maybe mempty tablePKCols $ M.lookup identifier $ dbTables ctxDbStructure + then maybe mempty tablePKCols $ HM.lookup identifier $ dbTables ctxDbStructure else mempty WriteQueryResult{..} <- writeQuery MutationCreate identifier True pkCols context @@ -371,7 +371,7 @@ handleUpdate identifier context@(RequestContext _ _ ApiRequest{..} _) = do handleSingleUpsert :: QualifiedIdentifier -> RequestContext-> DbHandler Wai.Response handleSingleUpsert identifier context@(RequestContext _ ctxDbStructure ApiRequest{..} _) = do - let pkCols = maybe mempty tablePKCols $ M.lookup identifier $ dbTables ctxDbStructure + let pkCols = maybe mempty tablePKCols $ HM.lookup identifier $ dbTables ctxDbStructure WriteQueryResult{..} <- writeQuery MutationSingleUpsert identifier False pkCols context @@ -419,7 +419,7 @@ handleInfo identifier RequestContext{..} = Nothing -> throwError Error.NotFound where - tbl = M.lookup identifier (dbTables ctxDbStructure) + tbl = HM.lookup identifier (dbTables ctxDbStructure) allOrigins = ("Access-Control-Allow-Origin", "*") allowH table = ( HTTP.hAllow @@ -489,8 +489,8 @@ handleOpenApi headersOnly tSchema (RequestContext conf@AppConfig{..} dbStructure <*> SQL.statement tSchema (DbStructure.schemaDescription configDbPreparedStatements) OAIgnorePriv -> OpenAPI.encode conf dbStructure - (M.filterWithKey (\(QualifiedIdentifier sch _) _ -> sch == tSchema) $ DbStructure.dbTables dbStructure) - (M.filterWithKey (\(QualifiedIdentifier sch _) _ -> sch == tSchema) $ DbStructure.dbProcs dbStructure) + (HM.filterWithKey (\(QualifiedIdentifier sch _) _ -> sch == tSchema) $ DbStructure.dbTables dbStructure) + (HM.filterWithKey (\(QualifiedIdentifier sch _) _ -> sch == tSchema) $ DbStructure.dbProcs dbStructure) <$> SQL.statement tSchema (DbStructure.schemaDescription configDbPreparedStatements) OADisabled -> pure mempty diff --git a/src/PostgREST/Auth.hs b/src/PostgREST/Auth.hs index 093300d01..5c1f029da 100644 --- a/src/PostgREST/Auth.hs +++ b/src/PostgREST/Auth.hs @@ -22,7 +22,7 @@ import qualified Crypto.JWT as JWT import qualified Data.Aeson as JSON import qualified Data.Aeson.Types as JSON import qualified Data.ByteString.Lazy.Char8 as LBS -import qualified Data.HashMap.Strict as M +import qualified Data.HashMap.Strict as HM import qualified Data.Text.Encoding as T import qualified Data.Vault.Lazy as Vault import qualified Data.Vector as V @@ -45,7 +45,7 @@ import Protolude data AuthResult = AuthResult - { authClaims :: M.HashMap Text JSON.Value + { authClaims :: HM.HashMap Text JSON.Value , authRole :: Text } @@ -78,13 +78,13 @@ parseClaims AppConfig{..} jclaims@(JSON.Object mclaims) = do role <- liftEither . maybeToRight JwtTokenRequired $ unquoted <$> walkJSPath (Just jclaims) configJwtRoleClaimKey <|> configDbAnonRole return AuthResult - { authClaims = mclaims & M.insert "role" (JSON.toJSON role) + { authClaims = mclaims & HM.insert "role" (JSON.toJSON role) , authRole = role } where walkJSPath :: Maybe JSON.Value -> JSPath -> Maybe JSON.Value walkJSPath x [] = x - walkJSPath (Just (JSON.Object o)) (JSPKey key:rest) = walkJSPath (M.lookup key o) rest + walkJSPath (Just (JSON.Object o)) (JSPKey key:rest) = walkJSPath (HM.lookup key o) rest walkJSPath (Just (JSON.Array ar)) (JSPIdx idx:rest) = walkJSPath (ar V.!? idx) rest walkJSPath _ _ = Nothing @@ -92,7 +92,7 @@ parseClaims AppConfig{..} jclaims@(JSON.Object mclaims) = do unquoted (JSON.String t) = t unquoted v = T.decodeUtf8 . LBS.toStrict $ JSON.encode v -- impossible case - just added to please -Wincomplete-patterns -parseClaims _ _ = return AuthResult { authClaims = M.empty, authRole = mempty } +parseClaims _ _ = return AuthResult { authClaims = HM.empty, authRole = mempty } -- | Validate authorization header. -- Parse and store JWT claims for future use in the request. diff --git a/src/PostgREST/DbStructure.hs b/src/PostgREST/DbStructure.hs index 33e3b2098..6a2a5b583 100644 --- a/src/PostgREST/DbStructure.hs +++ b/src/PostgREST/DbStructure.hs @@ -27,7 +27,7 @@ module PostgREST.DbStructure ) where import qualified Data.Aeson as JSON -import qualified Data.HashMap.Strict as M +import qualified Data.HashMap.Strict as HM import qualified Data.Set as S import qualified Hasql.Decoders as HD import qualified Hasql.Encoders as HE @@ -100,16 +100,16 @@ queryDbStructure schemas extraSearchPath prepared = do , dbProcs = procs } where - relsToMap = map sort . M.fromListWith (++) . map ((\(x, fSch, y) -> ((x, fSch), [y])) . addKey) + relsToMap = map sort . HM.fromListWith (++) . map ((\(x, fSch, y) -> ((x, fSch), [y])) . addKey) addKey rel = (relTable rel, qiSchema $ relForeignTable rel, rel) -- | Remove db objects that belong to an internal schema(not exposed through the API) from the DbStructure. removeInternal :: [Schema] -> DbStructure -> DbStructure removeInternal schemas dbStruct = DbStructure { - dbTables = M.filterWithKey (\(QualifiedIdentifier sch _) _ -> sch `elem` schemas) $ dbTables dbStruct + dbTables = HM.filterWithKey (\(QualifiedIdentifier sch _) _ -> sch `elem` schemas) $ dbTables dbStruct , dbRelationships = filter (\r -> qiSchema (relForeignTable r) `elem` schemas && not (hasInternalJunction r)) <$> - M.filterWithKey (\(QualifiedIdentifier sch _, _) _ -> sch `elem` schemas ) (dbRelationships dbStruct) + HM.filterWithKey (\(QualifiedIdentifier sch _, _) _ -> sch `elem` schemas ) (dbRelationships dbStruct) , dbProcs = dbProcs dbStruct -- procs are only obtained from the exposed schemas, no need to filter them. } where @@ -119,7 +119,7 @@ removeInternal schemas dbStruct = decodeTables :: HD.Result TablesMap decodeTables = - M.fromList . map (\tbl@Table{tableSchema, tableName} -> (QualifiedIdentifier tableSchema tableName, tbl)) <$> HD.rowList tblRow + HM.fromList . map (\tbl@Table{tableSchema, tableName} -> (QualifiedIdentifier tableSchema tableName, tbl)) <$> HD.rowList tblRow where tblRow = Table <$> column HD.text @@ -176,7 +176,7 @@ viewKeyDepFromRow (s1,t1,s2,v2,cons,consType,sCols) = ViewKeyDependency (Qualifi decodeProcs :: HD.Result ProcsMap decodeProcs = -- Duplicate rows for a function means they're overloaded, order these by least args according to ProcDescription Ord instance - map sort . M.fromListWith (++) . map ((\(x,y) -> (x, [y])) . addKey) <$> HD.rowList procRow + map sort . HM.fromListWith (++) . map ((\(x,y) -> (x, [y])) . addKey) <$> HD.rowList procRow where procRow = ProcDescription <$> column HD.text @@ -385,7 +385,7 @@ addM2MRels :: TablesMap -> [Relationship] -> [Relationship] addM2MRels tbls rels = rels ++ catMaybes [ let jtCols = S.fromList $ (fst <$> cols) ++ (fst <$> fcols) - pkCols = S.fromList $ maybe mempty tablePKCols $ M.lookup jt1 tbls + pkCols = S.fromList $ maybe mempty tablePKCols $ HM.lookup jt1 tbls in if S.isSubsetOf jtCols pkCols then Just $ Relationship t ft (t == ft) (M2M $ Junction jt1 cons1 cons2 (swap <$> cols) (swap <$> fcols)) tblIsView fTblisView else Nothing diff --git a/src/PostgREST/DbStructure/Proc.hs b/src/PostgREST/DbStructure/Proc.hs index 3ec5817a9..a62f436af 100644 --- a/src/PostgREST/DbStructure/Proc.hs +++ b/src/PostgREST/DbStructure/Proc.hs @@ -15,7 +15,7 @@ module PostgREST.DbStructure.Proc ) where import qualified Data.Aeson as JSON -import qualified Data.HashMap.Strict as M +import qualified Data.HashMap.Strict as HM import PostgREST.DbStructure.Identifiers (QualifiedIdentifier (..), Schema, TableName) @@ -66,7 +66,7 @@ instance Ord ProcDescription where -- | A map of all procs, all of which can be overloaded(one entry will have more than one ProcDescription). -- | It uses a HashMap for a faster lookup. -type ProcsMap = M.HashMap QualifiedIdentifier [ProcDescription] +type ProcsMap = HM.HashMap QualifiedIdentifier [ProcDescription] procReturnsScalar :: ProcDescription -> Bool procReturnsScalar proc = case proc of diff --git a/src/PostgREST/DbStructure/Relationship.hs b/src/PostgREST/DbStructure/Relationship.hs index 0a50c9741..37f839dbc 100644 --- a/src/PostgREST/DbStructure/Relationship.hs +++ b/src/PostgREST/DbStructure/Relationship.hs @@ -9,7 +9,7 @@ module PostgREST.DbStructure.Relationship ) where import qualified Data.Aeson as JSON -import qualified Data.HashMap.Strict as M +import qualified Data.HashMap.Strict as HM import PostgREST.DbStructure.Identifiers (FieldName, QualifiedIdentifier, Schema) @@ -53,4 +53,4 @@ data Junction = Junction deriving (Eq, Ord, Generic, JSON.ToJSON) -- | Key based on the source table and the foreign table schema -type RelationshipsMap = M.HashMap (QualifiedIdentifier, Schema) [Relationship] +type RelationshipsMap = HM.HashMap (QualifiedIdentifier, Schema) [Relationship] diff --git a/src/PostgREST/DbStructure/Table.hs b/src/PostgREST/DbStructure/Table.hs index 3c6ab5a20..31a0770dd 100644 --- a/src/PostgREST/DbStructure/Table.hs +++ b/src/PostgREST/DbStructure/Table.hs @@ -8,7 +8,7 @@ module PostgREST.DbStructure.Table ) where import qualified Data.Aeson as JSON -import qualified Data.HashMap.Strict as M +import qualified Data.HashMap.Strict as HM import PostgREST.DbStructure.Identifiers (FieldName, QualifiedIdentifier (..), @@ -46,4 +46,4 @@ data Column = Column } deriving (Eq, Show, Ord, Generic, JSON.ToJSON) -type TablesMap = M.HashMap QualifiedIdentifier Table +type TablesMap = HM.HashMap QualifiedIdentifier Table diff --git a/src/PostgREST/GucHeader.hs b/src/PostgREST/GucHeader.hs index 23f9db390..5b8b5ebd5 100644 --- a/src/PostgREST/GucHeader.hs +++ b/src/PostgREST/GucHeader.hs @@ -6,7 +6,7 @@ module PostgREST.GucHeader import qualified Data.Aeson as JSON import qualified Data.CaseInsensitive as CI -import qualified Data.HashMap.Strict as M +import qualified Data.HashMap.Strict as HM import Network.HTTP.Types.Header (Header) @@ -21,7 +21,7 @@ newtype GucHeader = GucHeader (CI.CI ByteString, ByteString) instance JSON.FromJSON GucHeader where parseJSON (JSON.Object o) = - case M.toList o of + case HM.toList o of [(k, JSON.String s)] -> pure $ GucHeader (CI.mk $ toUtf8 k, toUtf8 s) _ -> mzero parseJSON _ = mzero diff --git a/src/PostgREST/Middleware.hs b/src/PostgREST/Middleware.hs index a32ee0808..359bd1180 100644 --- a/src/PostgREST/Middleware.hs +++ b/src/PostgREST/Middleware.hs @@ -11,7 +11,7 @@ module PostgREST.Middleware import qualified Data.Aeson as JSON import qualified Data.ByteString.Lazy.Char8 as LBS -import qualified Data.HashMap.Strict as M +import qualified Data.HashMap.Strict as HM import qualified Data.Text as T import qualified Data.Text.Encoding as T import qualified Hasql.Decoders as HD @@ -38,7 +38,7 @@ import PostgREST.Request.Preferences import Protolude -- | Runs local(transaction scoped) GUCs for every request, plus the pre-request function -runPgLocals :: AppConfig -> M.HashMap Text JSON.Value -> Text -> +runPgLocals :: AppConfig -> HM.HashMap Text JSON.Value -> Text -> (ApiRequest -> ExceptT Error SQL.Transaction Wai.Response) -> ApiRequest -> ByteString -> PgVersion -> ExceptT Error SQL.Transaction Wai.Response runPgLocals conf claims role app req jsonDbS actualPgVersion = do @@ -57,7 +57,7 @@ runPgLocals conf claims role app req jsonDbS actualPgVersion = do then setConfigLocal "request.cookie." <$> iCookies req else setConfigLocalJson "request.cookies" (iCookies req) claimsSql = if usesLegacyGucs - then setConfigLocal "request.jwt.claim." <$> [(toUtf8 c, toUtf8 $ unquoted v) | (c,v) <- M.toList claims] + then setConfigLocal "request.jwt.claim." <$> [(toUtf8 c, toUtf8 $ unquoted v) | (c,v) <- HM.toList claims] else [setConfigLocal mempty ("request.jwt.claims", LBS.toStrict $ JSON.encode claims)] roleSql = [setConfigLocal mempty ("role", toUtf8 role)] appSettingsSql = setConfigLocal mempty <$> (join bimap toUtf8 <$> configAppSettings conf) @@ -116,6 +116,6 @@ setConfigLocalJson :: ByteString -> [(ByteString, ByteString)] -> [SQL.Snippet] setConfigLocalJson prefix keyVals = [setConfigLocal mempty (prefix, gucJsonVal keyVals)] where gucJsonVal :: [(ByteString, ByteString)] -> ByteString - gucJsonVal = LBS.toStrict . JSON.encode . M.fromList . arrayByteStringToText + gucJsonVal = LBS.toStrict . JSON.encode . HM.fromList . arrayByteStringToText arrayByteStringToText :: [(ByteString, ByteString)] -> [(Text,Text)] arrayByteStringToText keyVal = (T.decodeUtf8 *** T.decodeUtf8) <$> keyVal diff --git a/src/PostgREST/OpenAPI.hs b/src/PostgREST/OpenAPI.hs index 0a446adff..71363046f 100644 --- a/src/PostgREST/OpenAPI.hs +++ b/src/PostgREST/OpenAPI.hs @@ -9,7 +9,7 @@ module PostgREST.OpenAPI (encode) where import qualified Data.Aeson as JSON import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Lazy as LBS -import qualified Data.HashMap.Strict as M +import qualified Data.HashMap.Strict as HM import qualified Data.HashSet.InsOrd as Set import qualified Data.Text as T import qualified Data.Text.Encoding as T @@ -41,13 +41,13 @@ import PostgREST.ContentType import Protolude hiding (Proxy, get) -encode :: AppConfig -> DbStructure -> TablesMap -> M.HashMap k [ProcDescription] -> Maybe Text -> LBS.ByteString +encode :: AppConfig -> DbStructure -> TablesMap -> HM.HashMap k [ProcDescription] -> Maybe Text -> LBS.ByteString encode conf dbStructure tables procs schemaDescription = JSON.encode $ postgrestSpec (dbRelationships dbStructure) - (concat $ M.elems procs) - (snd <$> M.toList tables) + (concat $ HM.elems procs) + (snd <$> HM.toList tables) (proxyUri conf) schemaDescription @@ -100,7 +100,7 @@ makeProperty tbl rels col = (colName col, Inline s) rel = find (\case Relationship{relCardinality=(M2O _ relColumns)} -> [colName col] == (fst <$> relColumns) _ -> False - ) $ fromMaybe mempty $ M.lookup (QualifiedIdentifier (tableSchema tbl) (tableName tbl), tableSchema tbl) rels + ) $ fromMaybe mempty $ HM.lookup (QualifiedIdentifier (tableSchema tbl) (tableName tbl), tableSchema tbl) rels fCol = (headMay . (\r -> snd <$> relColumns (relCardinality r)) =<< rel) fTbl = qiName . relForeignTable <$> rel fTblCol = (,) <$> fTbl <*> fCol diff --git a/src/PostgREST/Request/ApiRequest.hs b/src/PostgREST/Request/ApiRequest.hs index ef82ba25e..2cd2f309a 100644 --- a/src/PostgREST/Request/ApiRequest.hs +++ b/src/PostgREST/Request/ApiRequest.hs @@ -22,7 +22,7 @@ import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Lazy as LBS import qualified Data.CaseInsensitive as CI import qualified Data.Csv as CSV -import qualified Data.HashMap.Strict as M +import qualified Data.HashMap.Strict as HM import qualified Data.List as L import qualified Data.List.NonEmpty as NonEmptyList import qualified Data.Set as S @@ -129,10 +129,10 @@ toRpcParamValue proc (k, v) | prmIsVariadic k = (k, Variadic [v]) jsonRpcParams :: ProcDescription -> [(Text, Text)] -> Payload jsonRpcParams proc prms = if not $ pdHasVariadic proc then -- if proc has no variadic param, save steps and directly convert to json - ProcessedJSON (JSON.encode $ M.fromList $ second JSON.toJSON <$> prms) (S.fromList $ fst <$> prms) + ProcessedJSON (JSON.encode $ HM.fromList $ second JSON.toJSON <$> prms) (S.fromList $ fst <$> prms) else - let paramsMap = M.fromListWith mergeParams $ toRpcParamValue proc <$> prms in - ProcessedJSON (JSON.encode paramsMap) (S.fromList $ M.keys paramsMap) + let paramsMap = HM.fromListWith mergeParams $ toRpcParamValue proc <$> prms in + ProcessedJSON (JSON.encode paramsMap) (S.fromList $ HM.keys paramsMap) where mergeParams :: RpcParamValue -> RpcParamValue -> RpcParamValue mergeParams (Variadic a) (Variadic b) = Variadic $ b ++ a @@ -153,7 +153,7 @@ targetToJsonRpcParams target params = -} data ApiRequest = ApiRequest { iAction :: Action -- ^ Similar but not identical to HTTP verb, e.g. Create/Invoke both POST - , iRange :: M.HashMap Text NonnegRange -- ^ Requested range of rows within response + , iRange :: HM.HashMap Text NonnegRange -- ^ Requested range of rows within response , iTopLevelRange :: NonnegRange -- ^ Requested range of rows from the top level , iTarget :: Target -- ^ The target, be it calling a proc or accessing a table , iPayload :: Maybe Payload -- ^ Data sent by client and used for mutation actions @@ -252,13 +252,13 @@ apiRequest conf@AppConfig{..} dbStructure req reqBody queryparams@QueryParams{.. json <- csvToJson <$> first BS.pack (CSV.decodeByName reqBody) note "All lines must have same number of fields" $ payloadAttributes (JSON.encode json) json (CTUrlEncoded, _) -> - let paramsMap = M.fromList $ (T.decodeUtf8 *** JSON.String . T.decodeUtf8) <$> parseSimpleQuery (LBS.toStrict reqBody) in - Right $ ProcessedJSON (JSON.encode paramsMap) $ S.fromList (M.keys paramsMap) + let paramsMap = HM.fromList $ (T.decodeUtf8 *** JSON.String . T.decodeUtf8) <$> parseSimpleQuery (LBS.toStrict reqBody) in + Right $ ProcessedJSON (JSON.encode paramsMap) $ S.fromList (HM.keys paramsMap) (CTTextPlain, True) -> Right $ RawPay reqBody (CTTextXML, True) -> Right $ RawPay reqBody (CTOctetStream, True) -> Right $ RawPay reqBody (ct, _) -> Left $ "Content-Type not acceptable: " <> ContentType.toMime ct - topLevelRange = fromMaybe allRange $ M.lookup "limit" ranges -- if no limit is specified, get all the request rows + topLevelRange = fromMaybe allRange $ HM.lookup "limit" ranges -- if no limit is specified, get all the request rows action = case method of -- The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response @@ -335,12 +335,12 @@ apiRequest conf@AppConfig{..} dbStructure req reqBody queryparams@QueryParams{.. lookupHeader = flip lookup hdrs Preferences.Preferences{..} = Preferences.fromHeaders hdrs headerRange = rangeRequested hdrs - limitRange = fromMaybe allRange (M.lookup "limit" qsRanges) + limitRange = fromMaybe allRange (HM.lookup "limit" qsRanges) headerAndLimitRange = rangeIntersection headerRange limitRange -- Bypass all the ranges and send only the limit zero range (0 <= x <= -1) if -- limit=0 is present in the query params (not allowed for the Range header) - ranges = M.insert "limit" (if hasLimitZero limitRange then limitZeroRange else headerAndLimitRange) qsRanges + ranges = HM.insert "limit" (if hasLimitZero limitRange then limitZeroRange else headerAndLimitRange) qsRanges -- The only emptyRange allowed is the limit zero range isInvalidRange = topLevelRange == emptyRange && not (hasLimitZero limitRange) @@ -357,7 +357,7 @@ mutuallyAgreeable sProduces cAccepts = then listToMaybe sProduces else exact -type CsvData = V.Vector (M.HashMap Text LBS.ByteString) +type CsvData = V.Vector (HM.HashMap Text LBS.ByteString) {-| Converts CSV like @@ -376,7 +376,7 @@ csvToJson (_, vals) = JSON.Array $ V.map rowToJsonObj vals where rowToJsonObj = JSON.Object . - M.map (\str -> + HM.map (\str -> if str == "NULL" then JSON.Null else JSON.String . T.decodeUtf8 $ LBS.toStrict str @@ -389,9 +389,9 @@ payloadAttributes raw json = JSON.Array arr -> case arr V.!? 0 of Just (JSON.Object o) -> - let canonicalKeys = S.fromList $ M.keys o + let canonicalKeys = S.fromList $ HM.keys o areKeysUniform = all (\case - JSON.Object x -> S.fromList (M.keys x) == canonicalKeys + JSON.Object x -> S.fromList (HM.keys x) == canonicalKeys _ -> False) arr in if areKeysUniform then Just $ ProcessedJSON raw canonicalKeys @@ -399,7 +399,7 @@ payloadAttributes raw json = Just _ -> Nothing Nothing -> Just emptyPJArray - JSON.Object o -> Just $ ProcessedJSON raw (S.fromList $ M.keys o) + JSON.Object o -> Just $ ProcessedJSON raw (S.fromList $ HM.keys o) -- truncate everything else to an empty array. _ -> Just emptyPJArray @@ -449,7 +449,7 @@ findProc qi argumentsKeys paramsAsSingleObject allProcs contentType isInvPost = ([proc], _) -> Right proc (procs, _) -> Left $ AmbiguousRpc (toList procs) where - matchProc = overloadedProcPartition $ M.lookupDefault mempty qi allProcs -- first find the proc by name + matchProc = overloadedProcPartition $ HM.lookupDefault mempty qi allProcs -- first find the proc by name -- The partition obtained has the form (overloadedProcs,fallbackProcs) -- where fallbackProcs are functions with a single unnamed parameter overloadedProcPartition procs = foldr select ([],[]) procs diff --git a/src/PostgREST/Request/DbRequestBuilder.hs b/src/PostgREST/Request/DbRequestBuilder.hs index ab7fe5d28..8d9fe2e3c 100644 --- a/src/PostgREST/Request/DbRequestBuilder.hs +++ b/src/PostgREST/Request/DbRequestBuilder.hs @@ -21,7 +21,7 @@ module PostgREST.Request.DbRequestBuilder , callRequest ) where -import qualified Data.HashMap.Strict as M +import qualified Data.HashMap.Strict as HM import qualified Data.Set as S import Data.Either.Combinators (mapLeft) @@ -206,7 +206,7 @@ findRel schema allRels origin target hint = -- /users?select=tasks!users_tasks(*) many-to-many between users and tasks matchJunction hnt relCardinality -- users_tasks ) - ) $ fromMaybe mempty $ M.lookup (QualifiedIdentifier schema origin, schema) allRels + ) $ fromMaybe mempty $ HM.lookup (QualifiedIdentifier schema origin, schema) allRels -- previousAlias is only used for the case of self joins addJoinConditions :: Maybe Alias -> ReadRequest -> Either ApiRequestError ReadRequest @@ -283,7 +283,7 @@ addRanges ApiRequest{..} rReq = _ -> foldr addRangeToNode (Right rReq) =<< ranges where ranges :: Either ApiRequestError [(EmbedPath, NonnegRange)] - ranges = first QueryParamError $ QueryParams.pRequestRange `traverse` M.toList iRange + ranges = first QueryParamError $ QueryParams.pRequestRange `traverse` HM.toList iRange addRangeToNode :: (EmbedPath, NonnegRange) -> Either ApiRequestError ReadRequest -> Either ApiRequestError ReadRequest addRangeToNode = updateNode (\r (Node (q,i) f) -> Node (q{range_=r}, i) f) diff --git a/src/PostgREST/Request/QueryParams.hs b/src/PostgREST/Request/QueryParams.hs index d03d72a28..4ebb5d9a5 100644 --- a/src/PostgREST/Request/QueryParams.hs +++ b/src/PostgREST/Request/QueryParams.hs @@ -13,7 +13,7 @@ module PostgREST.Request.QueryParams ) where import qualified Data.ByteString.Char8 as BS -import qualified Data.HashMap.Strict as M +import qualified Data.HashMap.Strict as HM import qualified Data.List as L import qualified Data.Set as S import qualified Data.Text as T @@ -78,7 +78,7 @@ data QueryParams = -- ^ Canonical representation of the query params, sorted alphabetically , qsParams :: [(Text, Text)] -- ^ Parameters for RPC calls - , qsRanges :: M.HashMap Text (Range Integer) + , qsRanges :: HM.HashMap Text (Range Integer) -- ^ Ranges derived from &limit and &offset params , qsOrder :: [(EmbedPath, [OrderTerm])] -- ^ &order parameters for each level @@ -192,8 +192,8 @@ parse qs = isEmbedPath = T.isInfixOf "." replaceLast x s = T.intercalate "." $ L.init (T.split (=='.') s) <> [x] - ranges :: M.HashMap Text (Range Integer) - ranges = M.unionWith f limitParams offsetParams + ranges :: HM.HashMap Text (Range Integer) + ranges = HM.unionWith f limitParams offsetParams where f rl ro = Range (BoundaryBelow o) (BoundaryAbove $ o + l - 1) where @@ -201,10 +201,10 @@ parse qs = o = rangeOffset ro limitParams = - M.fromList [(k, restrictRange (readMaybe v) allRange) | (k,v) <- limits] + HM.fromList [(k, restrictRange (readMaybe v) allRange) | (k,v) <- limits] offsetParams = - M.fromList [(k, maybe allRange rangeGeq (readMaybe v)) | (k,v) <- offsets] + HM.fromList [(k, maybe allRange rangeGeq (readMaybe v)) | (k,v) <- offsets] operator :: Text -> Maybe SimpleOperator operator = \case