@@ -51,7 +51,11 @@ module Database.Bloodhound.Types
5151 , omitNulls
5252 , BH(..)
5353 , runBH
54− , BHEnv(..)
54+ , BHEnv
55+ , bhServer
56+ , bhManager
57+ , bhRequestHook
58+ , mkBHEnv
5559 , MonadBH(..)
5660 , Version(..)
5761 , Status(..)
@@ -258,6 +262,9 @@ module Database.Bloodhound.Types
258262 , TermsResult(..)
259263 , DateHistogramResult(..)
260264 , DateRangeResult(..)
265+
266+ , EsUsername(..)
267+ , EsPassword(..)
261268 ) where
262269
263270import Control.Applicative
@@ -267,30 +274,31 @@ import Control.Monad.Reader
267274import Control.Monad.State
268275import Control.Monad.Writer
269276import Data.Aeson
270−import Data.Aeson.Types (Pair, Parser, emptyObject,
271− parseMaybe)
272−import qualified Data.ByteString.Lazy.Char8 as L
277+import Data.Aeson.Types (Pair, Parser, emptyObject,
278+ parseMaybe)
279+import qualified Data.ByteString.Lazy.Char8 as L
273280import Data.Char
274−import Data.Hashable (Hashable)
275−import qualified Data.HashMap.Strict as HM
276−import Data.List (foldl', nub)
277−import Data.List.NonEmpty (NonEmpty (..), toList)
278−import qualified Data.Map.Strict as M
281+import Data.Hashable (Hashable)
282+import qualified Data.HashMap.Strict as HM
283+import Data.List (foldl', nub)
284+import Data.List.NonEmpty (NonEmpty (..), toList)
285+import qualified Data.Map.Strict as M
279286import Data.Maybe
280−import Data.Text (Text)
281−import qualified Data.Text as T
287+import Data.Text (Text)
288+import qualified Data.Text as T
282289import Data.Time.Calendar
283−import Data.Time.Clock (NominalDiffTime, UTCTime)
290+import Data.Time.Clock (NominalDiffTime, UTCTime)
284291import Data.Time.Clock.POSIX
285−import qualified Data.Traversable as DT
286−import Data.Typeable (Typeable)
287−import qualified Data.Vector as V
292+import qualified Data.Traversable as DT
293+import Data.Typeable (Typeable)
294+import qualified Data.Vector as V
288295import GHC.Enum
289−import GHC.Generics (Generic)
296+import GHC.Generics (Generic)
290297import Network.HTTP.Client
291−import qualified Network.HTTP.Types.Method as NHTM
298+import qualified Network.HTTP.Types.Method as NHTM
292299
293300import Database.Bloodhound.Types.Class
301+import Database.Bloodhound.Types.Internal
294302
295303-- $setup
296304-- >>> :set -XOverloadedStrings
@@ -303,20 +311,12 @@ import Database.Bloodhound.Types.Class
303311-- defaultIndexSettings is exported by Database.Bloodhound as well
304312-- no trailing slashes in servers, library handles building the path.
305313
306−{-| Common environment for Elasticsearch calls. Connections will be
307− pipelined according to the provided HTTP connection manager.
308−-}
309−data BHEnv = BHEnv { bhServer :: Server
310− , bhManager :: Manager
311− }
312−
313−{-| All API calls to Elasticsearch operate within
314− MonadBH. The idea is that it can be easily embedded in your
315− own monad transformer stack. A default instance for a ReaderT and
316− alias 'BH' is provided for the simple case.
317−-}
318−class (Functor m, Applicative m, MonadIO m) => MonadBH m where
319− getBHEnv :: m BHEnv
314+-- | Create a 'BHEnv' with all optional fields defaulted. HTTP hook
315+-- will be a noop. You can use the exported fields to customize it further, e.g.:
316+--
317+-- >> (mkBHEnv myServer myManager) { bhRequestHook = customHook }
318+mkBHEnv :: Server -> Manager -> BHEnv
319+mkBHEnv s m = BHEnv s m return
320320
321321newtype BH m a = BH {
322322 unBH :: ReaderT BHEnv m a
@@ -345,10 +345,6 @@ instance (MonadReader r m) => MonadReader r (BH m) where
345345instance (Functor m, Applicative m, MonadIO m) => MonadBH (BH m) where
346346 getBHEnv = BH getBHEnv
347347
348−
349−instance (Functor m, Applicative m, MonadIO m) => MonadBH (ReaderT BHEnv m) where
350− getBHEnv = ask
351−
352348runBH :: BHEnv -> BH m a -> m a
353349runBH e f = runReaderT (unBH f) e
354350
@@ -479,9 +475,9 @@ data CompoundFormat = CompoundFileFormat Bool
479475
480476newtype NominalDiffTimeJSON = NominalDiffTimeJSON { ndtJSON :: NominalDiffTime }
481477
482−data IndexSettingsSummary = IndexSettingsSummary { sSummaryIndexName :: IndexName
478+data IndexSettingsSummary = IndexSettingsSummary { sSummaryIndexName :: IndexName
483479 , sSummaryFixedSettings :: IndexSettings
484− , sSummaryUpdateable :: [UpdatableIndexSetting]}
480+ , sSummaryUpdateable :: [UpdatableIndexSetting]}
485481 deriving (Eq, Show, Generic, Typeable)
486482
487483{-| 'Reply' and 'Method' are type synonyms from 'Network.HTTP.Types.Method.Method' -}
@@ -764,10 +760,6 @@ newtype ShardCount = ShardCount Int deriving (Eq, Show, Generic, ToJSON, Typeabl
764760-}
765761newtype ReplicaCount = ReplicaCount Int deriving (Eq, Show, Generic, ToJSON, Typeable)
766762
767−{-| 'Server' is used with the client functions to point at the ES instance
768−-}
769−newtype Server = Server Text deriving (Eq, Show, Generic, Typeable)
770−
771763{-| 'IndexName' is used to describe which index to query/create/delete
772764-}
773765newtype IndexName = IndexName Text deriving (Eq, Generic, Show, ToJSON, FromJSON, Typeable)
@@ -3544,3 +3536,9 @@ instance Enum DocVersion where
35443536 fromEnum = docVersionNumber
35453537 enumFrom = boundedEnumFrom
35463538 enumFromThen = boundedEnumFromThen
3539+
3540+-- | Username type used for HTTP Basic authentication. See 'basicAuthHook'.
3541+newtype EsUsername = EsUsername { esUsername :: Text } deriving (Show, Eq)
3542+
3543+-- | Password type used for HTTP Basic authentication. See 'basicAuthHook'.
3544+newtype EsPassword = EsPassword { esPassword :: Text } deriving (Show, Eq)