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.Middleware
PostgREST.MediaType
PostgREST.OpenAPI
PostgREST.Query
PostgREST.Query.QueryBuilder
PostgREST.Query.SqlFragment
@@ -69,6 +68,7 @@ library
PostgREST.Request.ReadQuery
PostgREST.Request.Types
PostgREST.Response
PostgREST.Response.OpenAPI
PostgREST.Version
PostgREST.Workers
other-modules: Paths_postgrest
+3 -3
View File
@@ -167,8 +167,6 @@ postgrestResponse
-> Wai.Request
-> Handler IO Wai.Response
postgrestResponse appState conf@AppConfig{..} maybeDbStructure jsonDbS pgVer AuthResult{..} req = do
body <- lift $ Wai.strictRequestBody req
dbStructure <-
case maybeDbStructure of
Just dbStructure ->
@@ -176,6 +174,8 @@ postgrestResponse appState conf@AppConfig{..} maybeDbStructure jsonDbS pgVer Aut
Nothing ->
throwError Error.NoSchemaCacheError
body <- lift $ Wai.strictRequestBody req
apiRequest <-
liftEither . mapLeft Error.ApiRequestError $
ApiRequest.userApiRequest conf dbStructure req body
@@ -187,7 +187,7 @@ postgrestResponse appState conf@AppConfig{..} maybeDbStructure jsonDbS pgVer Aut
else
runDbHandler appState (Query.txMode apiRequest) (Just authRole /= configDbAnonRole) configDbPreparedStatements .
Middleware.optionalRollback conf apiRequest $ do
Query.runPgLocals conf authClaims authRole apiRequest jsonDbS pgVer
Query.setPgLocals conf authClaims authRole apiRequest jsonDbS pgVer
handleRequest (ctx apiRequest)
runDbHandler :: AppState.AppState -> SQL.Mode -> Bool -> Bool -> DbHandler b -> Handler IO b
+3 -3
View File
@@ -8,7 +8,7 @@ module PostgREST.Query
, singleUpsertQuery
, txMode
, updateQuery
, runPgLocals
, setPgLocals
, DbHandler
) where
@@ -228,9 +228,9 @@ failsChangesOffLimits (Just maxChanges) RSStandard{rsQueryTotal=queryTotal} =
throwError $ Error.OffLimitsChangesError queryTotal maxChanges
-- | 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 ()
runPgLocals conf claims role req jsonDbS actualPgVersion = do
setPgLocals conf claims role req jsonDbS actualPgVersion = do
lift $ SQL.statement mempty $ SQL.dynamicallyParameterized
("select " <> intercalateSnippet ", " (searchPathSql : roleSql ++ claimsSql ++ [methodSql, pathSql] ++ headersSql ++ cookiesSql ++ appSettingsSql ++ specSql))
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.Wai as Wai
import qualified PostgREST.Error as Error
import qualified PostgREST.MediaType as MediaType
import qualified PostgREST.OpenAPI as OpenAPI
import qualified PostgREST.RangeQuery as RangeQuery
import qualified PostgREST.Error as Error
import qualified PostgREST.MediaType as MediaType
import qualified PostgREST.RangeQuery as RangeQuery
import qualified PostgREST.Response.OpenAPI as OpenAPI
import PostgREST.Config (AppConfig (..))
import PostgREST.DbStructure (DbStructure (..))
@@ -4,7 +4,7 @@ Description : Generates the OpenAPI output
-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}
module PostgREST.OpenAPI (encode) where
module PostgREST.Response.OpenAPI (encode) where
import qualified Data.Aeson as JSON
import qualified Data.ByteString.Char8 as BS