-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Configuration management library -- -- Library to abstract the parsing of many haskell config values from -- different config sources @package conferer @version 0.4.0.0 module Conferer.Types -- | Core interface for library provided configuration, basically consists -- of getting a Key and informing returning a maybe signaling the -- value and if it's present in that specific source data Source Source :: (Key -> IO (Maybe Text)) -> Source [getKeyInSource] :: Source -> Key -> IO (Maybe Text) -- | The way to index Sources, basically list of names that will be -- adapted to whatever the source needs newtype Key Path :: [Text] -> Key [unKey] :: Key -> [Text] -- | Collapse a key into a textual representation keyName :: Key -> Text -- | Core type that the user of this library interact with, in the future -- it may contain more this besides a list of sources data Config Config :: [Source] -> Map Key Text -> Config [sources] :: Config -> [Source] [defaults] :: Config -> Map Key Text -- | The type for creating a source given a Config, some sources -- require a certain configuration to be initialized (for example: the -- redis source needs connection info to connect to the server) type SourceCreator = Config -> IO Source keyNotPresentError :: forall a. Typeable a => Key -> Proxy a -> FailedToFetchError -- | Default defining instance -- -- Here a Nothing means that the value didn't appear in the -- config, some instances never return a value since they have defaults -- that can never fail class DefaultConfig a configDef :: DefaultConfig a => a -- | Main typeclass for defining the way to get values from config, hiding -- the Text based nature of the Sources. updated using a -- config, so for example a Warp.Settings can get updated from a config, -- but that doesn't make much sense for something like an Int -- -- You'd normally would never implement this typeclass, if you want to -- implement FromConfig you should implement that directly, and if -- you want to use DefaultConfig and FromConfig to -- implement FromConfig you should let the default -- Generics based implementation do it's thing class FromConfig a updateFromConfig :: FromConfig a => Key -> Config -> a -> IO a updateFromConfig :: (FromConfig a, Generic a, Typeable a, FromConfigG (Rep a)) => Key -> Config -> a -> IO a fetchFromConfig :: FromConfig a => Key -> Config -> IO (Maybe a) fetchFromConfig :: (FromConfig a, Generic a, FromConfigG (Rep a)) => Key -> Config -> IO (Maybe a) -- | Purely Generics machinery, ignore... class FromConfigG f updateFromConfigG :: FromConfigG f => Key -> Config -> f a -> IO (f a) fetchFromConfigG :: FromConfigG f => Key -> Config -> IO (Maybe (f a)) data ConfigParsingError ConfigParsingError :: Key -> Text -> TypeRep -> ConfigParsingError data FailedToFetchError FailedToFetchError :: Key -> TypeRep -> FailedToFetchError instance GHC.Classes.Eq Conferer.Types.FailedToFetchError instance GHC.Classes.Eq Conferer.Types.ConfigParsingError instance GHC.Classes.Ord Conferer.Types.Key instance GHC.Classes.Eq Conferer.Types.Key instance GHC.Show.Show Conferer.Types.Key instance GHC.Show.Show Conferer.Types.FailedToFetchError instance GHC.Exception.Type.Exception Conferer.Types.FailedToFetchError instance GHC.Show.Show Conferer.Types.ConfigParsingError instance GHC.Exception.Type.Exception Conferer.Types.ConfigParsingError instance Data.String.IsString Conferer.Types.Key module Conferer.Source.Simple -- | Make a Source from List of Key, Text -- pairs mkMapSource :: [(Key, Text)] -> SourceCreator -- | Make a SourceCreator from a Map mkMapSource' :: Map Key Text -> SourceCreator -- | Make a Source from a Map mkPureMapSource :: Map Key Text -> Source module Conferer.Source.Null -- | Create a null Source mkNullSource :: SourceCreator module Conferer.Source.Namespaced -- | Create a SourceCreator from a prefix and another -- SourceCreator mkNamespacedSource :: Key -> SourceCreator -> SourceCreator module Conferer.Source.Mapping -- | Create a SourceCreator using a Map Key Key -- to transform the supplied keys and another SourceCreator mkMappingSource :: Map Key Key -> SourceCreator -> SourceCreator -- | Create a SourceCreator using a function to transform the -- supplied keys and another SourceCreator mkMappingSource' :: (Key -> Maybe Key) -> SourceCreator -> SourceCreator module Conferer.Source.Env -- | SourceCreator for env Source that uses the real -- lookupEnv function mkEnvSource :: Prefix -> SourceCreator -- | SourceCreator for env Source that allows parameterizing -- the function used to lookup for testing mkEnvSource' :: LookupEnvFunc -> Prefix -> SourceCreator -- | A text to namespace env vars type Prefix = Text -- | Type alias for the function to lookup env vars type LookupEnvFunc = String -> IO (Maybe String) -- | Get the env name from a prefix and a key by uppercasing and -- intercalating underscores -- --
--   >>> keyToEnVar "awesomeapp" "warp.port"
--   "AWESOMEAPP_WARP_PORT"
--   
keyToEnvVar :: Prefix -> Key -> Text module Conferer.Source.CLIArgs -- | Same as mkCLIArgsSource' but using getArgs to provide -- the argument list mkCLIArgsSource :: SourceCreator -- | Create a SourceCreator for CLIArgs from a argument list mkCLIArgsSource' :: [String] -> SourceCreator -- | Parse an argument list into a dictionary suitable for a Source parseArgsIntoKeyValue :: [String] -> [(Key, Text)] module Conferer.Core -- | Most Basic function to interact directly with a Config. It -- always returns Text in the case of success and implements the -- logic to traverse sources inside the Config. getKey :: Key -> Config -> IO (Maybe Text) -- | Fetch a value from a config under some specific key that's parsed -- using the FromConfig instance, and as a default it uses the -- value from DefaultConfig. -- -- Notes: - This function may throw an exception if parsing fails for any -- subkey getFromConfig :: forall a. (Typeable a, FromConfig a, DefaultConfig a) => Key -> Config -> IO a -- | Same as getFromConfig using the root key -- -- Notes: - This function may throw an exception if parsing fails for any -- subkey getFromRootConfig :: forall a. (Typeable a, FromConfig a, DefaultConfig a) => Config -> IO a -- | Same as getFromConfig but with a user defined default (instead -- of DefaultConfig instance) -- -- Useful for fetching primitive types getFromConfigWithDefault :: forall a. (Typeable a, FromConfig a) => Key -> Config -> a -> IO a -- | Fetch a value from a config key that's parsed using the FromConfig -- instance. -- -- Note: This function does not use default so the value must be fully -- defined by the config only, meaning using this function for many -- records will always result in Nothing (if the record contains a -- value that can never be retrieved like a function) safeGetFromConfig :: forall a. (Typeable a, FromConfig a, DefaultConfig a) => Key -> Config -> IO (Maybe a) -- | Same as safeGetFromConfig but with a user defined default safeGetFromConfigWithDefault :: forall a. (Typeable a, FromConfig a) => Key -> Config -> a -> IO (Maybe a) -- | Create a new Key by concatenating two existing keys. (/.) :: Key -> Key -> Key -- | The empty configuration, this Config is used as the base for -- most config creating functions. emptyConfig :: Config withDefaults :: [(Key, Text)] -> Config -> Config -- | Instantiate a SourceCreator using the emptyConfig mkStandaloneSource :: SourceCreator -> IO Source -- | Instantiate a Source using an SourceCretor and a -- Config and add to the config addSource :: SourceCreator -> Config -> IO Config -- | Same as getKey but it throws if the Key isn't found unsafeGetKey :: Key -> Config -> IO Text module Conferer.FromConfig.Basics updateAllAtOnceUsingFetch :: forall a. (FromConfig a, Typeable a) => Key -> Config -> a -> IO a parseBool :: Text -> Maybe Bool updateFromConfigByRead :: (Typeable a, Read a) => Key -> Config -> a -> IO a updateFromConfigByIsString :: (Typeable a, IsString a) => Key -> Config -> a -> IO a fetchFromConfigByRead :: (Typeable a, Read a) => Key -> Config -> IO (Maybe a) fetchFromConfigByIsString :: (Typeable a, IsString a) => Key -> Config -> IO (Maybe a) fromValueWith :: (Text -> Maybe a) -> Text -> Maybe a fetchFromConfigWith :: forall a. Typeable a => (Text -> Maybe a) -> Key -> Config -> IO (Maybe a) updateFromConfigWith :: forall a. Typeable a => (Text -> Maybe a) -> Key -> Config -> a -> IO a -- | Concatenate many transformations to the config based on keys and -- functions findKeyAndApplyConfig :: forall newvalue config. FromConfig newvalue => Config -> Key -> Key -> (config -> newvalue) -> (newvalue -> config -> config) -> config -> IO config class FromConfigWithConNameG f updateFromConfigWithConNameG :: FromConfigWithConNameG f => String -> Key -> Config -> f a -> IO (f a) fetchFromConfigWithConNameG :: FromConfigWithConNameG f => String -> Key -> Config -> IO (Maybe (f a)) instance (Conferer.FromConfig.Basics.FromConfigWithConNameG inner, GHC.Generics.Constructor constructor) => Conferer.Types.FromConfigG (GHC.Generics.C1 constructor inner) instance (Conferer.FromConfig.Basics.FromConfigWithConNameG left, Conferer.FromConfig.Basics.FromConfigWithConNameG right) => Conferer.FromConfig.Basics.FromConfigWithConNameG (left GHC.Generics.:*: right) instance (Conferer.Types.FromConfigG inner, GHC.Generics.Selector selector) => Conferer.FromConfig.Basics.FromConfigWithConNameG (GHC.Generics.S1 selector inner) instance Conferer.Types.FromConfig GHC.Types.Int instance Conferer.Types.FromConfig GHC.Integer.Type.Integer instance Conferer.Types.FromConfig GHC.Types.Float instance Conferer.Types.FromConfig Data.ByteString.Internal.ByteString instance Conferer.Types.DefaultConfig (GHC.Maybe.Maybe a) instance Conferer.Types.FromConfig a => Conferer.Types.FromConfig (GHC.Maybe.Maybe a) instance Conferer.Types.FromConfig GHC.Base.String instance Conferer.Types.FromConfig Data.Text.Internal.Text instance Conferer.Types.FromConfig GHC.Types.Bool instance Conferer.Types.FromConfigG inner => Conferer.Types.FromConfigG (GHC.Generics.D1 metadata inner) instance Conferer.Types.FromConfig inner => Conferer.Types.FromConfigG (GHC.Generics.Rec0 inner) module Conferer.Source.Files fromRight :: a -> Either e a -> a getFilePathFromEnv :: Config -> String -> IO FilePath module Conferer.Source.PropertiesFile -- | SourceCreator for properties file Source that read from -- a config file in config/{env}.properties and parses it as a -- properties file with some.key=a value lines mkPropertiesFileSource :: SourceCreator -- | SourceCreator for properties file Source that only -- parses a given Text as a properties file mkPropertiesFileSource' :: Text -> SourceCreator -- | Transform a line into a key/value pair (or not) lineToKeyValue :: Text -> Maybe (Key, Text) -- | Types and functions for managing configuration effectively module Conferer -- | Main typeclass for defining the way to get values from config, hiding -- the Text based nature of the Sources. updated using a -- config, so for example a Warp.Settings can get updated from a config, -- but that doesn't make much sense for something like an Int -- -- You'd normally would never implement this typeclass, if you want to -- implement FromConfig you should implement that directly, and if -- you want to use DefaultConfig and FromConfig to -- implement FromConfig you should let the default -- Generics based implementation do it's thing class FromConfig a updateFromConfig :: FromConfig a => Key -> Config -> a -> IO a updateFromConfig :: (FromConfig a, Generic a, Typeable a, FromConfigG (Rep a)) => Key -> Config -> a -> IO a fetchFromConfig :: FromConfig a => Key -> Config -> IO (Maybe a) fetchFromConfig :: (FromConfig a, Generic a, FromConfigG (Rep a)) => Key -> Config -> IO (Maybe a) -- | Default defining instance -- -- Here a Nothing means that the value didn't appear in the -- config, some instances never return a value since they have defaults -- that can never fail class DefaultConfig a configDef :: DefaultConfig a => a -- | The type for creating a source given a Config, some sources -- require a certain configuration to be initialized (for example: the -- redis source needs connection info to connect to the server) type SourceCreator = Config -> IO Source -- | Core type that the user of this library interact with, in the future -- it may contain more this besides a list of sources data Config -- | The way to index Sources, basically list of names that will be -- adapted to whatever the source needs newtype Key Path :: [Text] -> Key [unKey] :: Key -> [Text] -- | Core interface for library provided configuration, basically consists -- of getting a Key and informing returning a maybe signaling the -- value and if it's present in that specific source data Source Source :: (Key -> IO (Maybe Text)) -> Source [getKeyInSource] :: Source -> Key -> IO (Maybe Text) -- | Most Basic function to interact directly with a Config. It -- always returns Text in the case of success and implements the -- logic to traverse sources inside the Config. getKey :: Key -> Config -> IO (Maybe Text) -- | Fetch a value from a config under some specific key that's parsed -- using the FromConfig instance, and as a default it uses the -- value from DefaultConfig. -- -- Notes: - This function may throw an exception if parsing fails for any -- subkey getFromConfig :: forall a. (Typeable a, FromConfig a, DefaultConfig a) => Key -> Config -> IO a -- | Same as getFromConfig using the root key -- -- Notes: - This function may throw an exception if parsing fails for any -- subkey getFromRootConfig :: forall a. (Typeable a, FromConfig a, DefaultConfig a) => Config -> IO a -- | Same as getFromConfig but with a user defined default (instead -- of DefaultConfig instance) -- -- Useful for fetching primitive types getFromConfigWithDefault :: forall a. (Typeable a, FromConfig a) => Key -> Config -> a -> IO a -- | Fetch a value from a config key that's parsed using the FromConfig -- instance. -- -- Note: This function does not use default so the value must be fully -- defined by the config only, meaning using this function for many -- records will always result in Nothing (if the record contains a -- value that can never be retrieved like a function) safeGetFromConfig :: forall a. (Typeable a, FromConfig a, DefaultConfig a) => Key -> Config -> IO (Maybe a) -- | Same as safeGetFromConfig but with a user defined default safeGetFromConfigWithDefault :: forall a. (Typeable a, FromConfig a) => Key -> Config -> a -> IO (Maybe a) -- | Create a new Key by concatenating two existing keys. (/.) :: Key -> Key -> Key -- | The empty configuration, this Config is used as the base for -- most config creating functions. emptyConfig :: Config withDefaults :: [(Key, Text)] -> Config -> Config -- | Instantiate a Source using an SourceCretor and a -- Config and add to the config addSource :: SourceCreator -> Config -> IO Config -- | Same as getKey but it throws if the Key isn't found unsafeGetKey :: Key -> Config -> IO Text -- | Default config which reads from command line arguments, env vars and -- property files defaultConfig :: Text -> IO Config -- | Default config which reads from command line arguments, env vars, -- property files and some default key/values defaultConfigWithDefaults :: Text -> [(Key, Text)] -> IO Config -- | The way to index Sources, basically list of names that will be -- adapted to whatever the source needs newtype Key Path :: [Text] -> Key [unKey] :: Key -> [Text] -- | & is a reverse application operator. This provides -- notational convenience. Its precedence is one higher than that of the -- forward application operator $, which allows & to be -- nested in $. -- --
--   >>> 5 & (+1) & show
--   "6"
--   
(&) :: () => a -> (a -> b) -> b infixl 1 &