From fa4df95f55b8a5be2c451ca350f1ed76fa415fbc Mon Sep 17 00:00:00 2001 From: monacoremo <59358383+monacoremo@users.noreply.github.com> Date: Sun, 7 Nov 2021 14:53:02 +0100 Subject: [PATCH] refactor: Remove Protolude.Conv from Parsers --- src/PostgREST/Request/ApiRequest.hs | 6 +++--- src/PostgREST/Request/Parsers.hs | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/PostgREST/Request/ApiRequest.hs b/src/PostgREST/Request/ApiRequest.hs index 233be0637..51f79eaaa 100644 --- a/src/PostgREST/Request/ApiRequest.hs +++ b/src/PostgREST/Request/ApiRequest.hs @@ -152,7 +152,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 ByteString NonnegRange -- ^ Requested range of rows within response + , iRange :: M.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 @@ -362,9 +362,9 @@ userApiRequest conf@AppConfig{..} dbStructure req reqBody headerRange = rangeRequested hdrs replaceLast x s = T.intercalate "." $ L.init (T.split (=='.') s) ++ [x] - limitParams :: M.HashMap ByteString NonnegRange + limitParams :: M.HashMap Text NonnegRange limitParams = M.fromList [(toS (replaceLast "limit" k), restrictRange (readMaybe . toS =<< v) allRange) | (k,v) <- qParams, isJust v, endingIn ["limit"] k] - offsetParams :: M.HashMap ByteString NonnegRange + offsetParams :: M.HashMap Text NonnegRange offsetParams = M.fromList [(toS (replaceLast "limit" k), maybe allRange rangeGeq (readMaybe . toS =<< v)) | (k,v) <- qParams, isJust v, endingIn ["offset"] k] urlRange = M.unionWith f limitParams offsetParams diff --git a/src/PostgREST/Request/Parsers.hs b/src/PostgREST/Request/Parsers.hs index ee480990c..cd78e639e 100644 --- a/src/PostgREST/Request/Parsers.hs +++ b/src/PostgREST/Request/Parsers.hs @@ -47,8 +47,7 @@ import PostgREST.RangeQuery (NonnegRange) import PostgREST.Request.Types -import Protolude hiding (intercalate, option, replace, toS, try) -import Protolude.Conv (toS) +import Protolude hiding (intercalate, option, replace, try) pRequestSelect :: Text -> Either ApiRequestError [Tree SelectItem] pRequestSelect selStr = @@ -73,7 +72,7 @@ pRequestOrder (k, v) = mapError $ (,) <$> path <*> ord' path = fst <$> treePath ord' = parse pOrder ("failed to parse order (" ++ toS v ++ ")") $ toS v -pRequestRange :: (ByteString, NonnegRange) -> Either ApiRequestError (EmbedPath, NonnegRange) +pRequestRange :: (Text, NonnegRange) -> Either ApiRequestError (EmbedPath, NonnegRange) pRequestRange (k, v) = mapError $ (,) <$> path <*> pure v where treePath = parse pTreePath ("failed to parser tree path (" ++ toS k ++ ")") $ toS k @@ -117,7 +116,7 @@ pFieldForest = pFieldTree `sepBy1` lexeme (char ',') Node <$> pFieldSelect <*> pure [] pStar :: Parser Text -pStar = toS <$> (string "*" $> ("*"::ByteString)) +pStar = string "*" $> "*" pFieldName :: Parser Text pFieldName =