refactor: OpenAPI as Response submodule

* body after dbstructure
* rename runPgLocals to setPgLocals
This commit is contained in:
steve-chavez
2022-10-01 11:05:49 -05:00
committed by Steve Chavez
parent f54dc2e20e
commit fd67c8480c
5 changed files with 12 additions and 12 deletions
+1 -1
View File
@@ -55,7 +55,6 @@ library
PostgREST.Logger PostgREST.Logger
PostgREST.Middleware PostgREST.Middleware
PostgREST.MediaType PostgREST.MediaType
PostgREST.OpenAPI
PostgREST.Query PostgREST.Query
PostgREST.Query.QueryBuilder PostgREST.Query.QueryBuilder
PostgREST.Query.SqlFragment PostgREST.Query.SqlFragment
@@ -69,6 +68,7 @@ library
PostgREST.Request.ReadQuery PostgREST.Request.ReadQuery
PostgREST.Request.Types PostgREST.Request.Types
PostgREST.Response PostgREST.Response
PostgREST.Response.OpenAPI
PostgREST.Version PostgREST.Version
PostgREST.Workers PostgREST.Workers
other-modules: Paths_postgrest other-modules: Paths_postgrest
+3 -3
View File
@@ -167,8 +167,6 @@ postgrestResponse
-> Wai.Request -> Wai.Request
-> Handler IO Wai.Response -> Handler IO Wai.Response
postgrestResponse appState conf@AppConfig{..} maybeDbStructure jsonDbS pgVer AuthResult{..} req = do postgrestResponse appState conf@AppConfig{..} maybeDbStructure jsonDbS pgVer AuthResult{..} req = do
body <- lift $ Wai.strictRequestBody req
dbStructure <- dbStructure <-
case maybeDbStructure of case maybeDbStructure of
Just dbStructure -> Just dbStructure ->
@@ -176,6 +174,8 @@ postgrestResponse appState conf@AppConfig{..} maybeDbStructure jsonDbS pgVer Aut
Nothing -> Nothing ->
throwError Error.NoSchemaCacheError throwError Error.NoSchemaCacheError
body <- lift $ Wai.strictRequestBody req
apiRequest <- apiRequest <-
liftEither . mapLeft Error.ApiRequestError $ liftEither . mapLeft Error.ApiRequestError $
ApiRequest.userApiRequest conf dbStructure req body ApiRequest.userApiRequest conf dbStructure req body
@@ -187,7 +187,7 @@ postgrestResponse appState conf@AppConfig{..} maybeDbStructure jsonDbS pgVer Aut
else else
runDbHandler appState (Query.txMode apiRequest) (Just authRole /= configDbAnonRole) configDbPreparedStatements . runDbHandler appState (Query.txMode apiRequest) (Just authRole /= configDbAnonRole) configDbPreparedStatements .
Middleware.optionalRollback conf apiRequest $ do Middleware.optionalRollback conf apiRequest $ do
Query.runPgLocals conf authClaims authRole apiRequest jsonDbS pgVer Query.setPgLocals conf authClaims authRole apiRequest jsonDbS pgVer
handleRequest (ctx apiRequest) handleRequest (ctx apiRequest)
runDbHandler :: AppState.AppState -> SQL.Mode -> Bool -> Bool -> DbHandler b -> Handler IO b runDbHandler :: AppState.AppState -> SQL.Mode -> Bool -> Bool -> DbHandler b -> Handler IO b
+3 -3
View File
@@ -8,7 +8,7 @@ module PostgREST.Query
, singleUpsertQuery , singleUpsertQuery
, txMode , txMode
, updateQuery , updateQuery
, runPgLocals , setPgLocals
, DbHandler , DbHandler
) where ) where
@@ -228,9 +228,9 @@ failsChangesOffLimits (Just maxChanges) RSStandard{rsQueryTotal=queryTotal} =
throwError $ Error.OffLimitsChangesError queryTotal maxChanges throwError $ Error.OffLimitsChangesError queryTotal maxChanges
-- | Runs local(transaction scoped) GUCs for every request, plus the pre-request function -- | Runs local(transaction scoped) GUCs for every request, plus the pre-request function
runPgLocals :: AppConfig -> KM.KeyMap JSON.Value -> Text -> setPgLocals :: AppConfig -> KM.KeyMap JSON.Value -> Text ->
ApiRequest -> ByteString -> PgVersion -> DbHandler () ApiRequest -> ByteString -> PgVersion -> DbHandler ()
runPgLocals conf claims role req jsonDbS actualPgVersion = do setPgLocals conf claims role req jsonDbS actualPgVersion = do
lift $ SQL.statement mempty $ SQL.dynamicallyParameterized lift $ SQL.statement mempty $ SQL.dynamicallyParameterized
("select " <> intercalateSnippet ", " (searchPathSql : roleSql ++ claimsSql ++ [methodSql, pathSql] ++ headersSql ++ cookiesSql ++ appSettingsSql ++ specSql)) ("select " <> intercalateSnippet ", " (searchPathSql : roleSql ++ claimsSql ++ [methodSql, pathSql] ++ headersSql ++ cookiesSql ++ appSettingsSql ++ specSql))
HD.noResult (configDbPreparedStatements conf) HD.noResult (configDbPreparedStatements conf)
+4 -4
View File
@@ -23,10 +23,10 @@ import qualified Network.HTTP.Types.Status as HTTP
import qualified Network.HTTP.Types.URI as HTTP import qualified Network.HTTP.Types.URI as HTTP
import qualified Network.Wai as Wai import qualified Network.Wai as Wai
import qualified PostgREST.Error as Error import qualified PostgREST.Error as Error
import qualified PostgREST.MediaType as MediaType import qualified PostgREST.MediaType as MediaType
import qualified PostgREST.OpenAPI as OpenAPI import qualified PostgREST.RangeQuery as RangeQuery
import qualified PostgREST.RangeQuery as RangeQuery import qualified PostgREST.Response.OpenAPI as OpenAPI
import PostgREST.Config (AppConfig (..)) import PostgREST.Config (AppConfig (..))
import PostgREST.DbStructure (DbStructure (..)) import PostgREST.DbStructure (DbStructure (..))
@@ -4,7 +4,7 @@ Description : Generates the OpenAPI output
-} -}
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE RecordWildCards #-}
module PostgREST.OpenAPI (encode) where module PostgREST.Response.OpenAPI (encode) where
import qualified Data.Aeson as JSON import qualified Data.Aeson as JSON
import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Char8 as BS