packages feed

etc 0.1.0.0 → 0.2.0.0

raw patch · 6 files changed

+88/−20 lines, 6 filessetup-changedPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- System.Etc.Internal.Config: getAllConfigSources :: (MonadThrow m) => [Text] -> Config -> m (Set ConfigSource)
- System.Etc.Internal.Config: getConfigValue :: (MonadThrow m, FromJSON result) => [Text] -> Config -> m result
- System.Etc.Internal.Config: getConfigValueWith :: MonadThrow m => (Value -> Parser a) -> [Text] -> Config -> m a
- System.Etc.Internal.Config: getSelectedConfigSource :: (MonadThrow m) => [Text] -> Config -> m ConfigSource
+ System.Etc: class IConfig config
+ System.Etc.Internal.Config: _getAllConfigSources :: (MonadThrow m) => [Text] -> Config -> m (Set ConfigSource)
+ System.Etc.Internal.Config: _getConfigValue :: (MonadThrow m, FromJSON result) => [Text] -> Config -> m result
+ System.Etc.Internal.Config: _getConfigValueWith :: MonadThrow m => (Value -> Parser result) -> [Text] -> Config -> m result
+ System.Etc.Internal.Config: _getSelectedConfigSource :: (MonadThrow m) => [Text] -> Config -> m ConfigSource
+ System.Etc.Internal.Config: instance System.Etc.Internal.Types.IConfig System.Etc.Internal.Types.Config
+ System.Etc.Internal.Types: class IConfig config
+ System.Etc.Internal.Types: getAllConfigSources :: (IConfig config, MonadThrow m) => [Text] -> config -> m (Set ConfigSource)
+ System.Etc.Internal.Types: getConfigValue :: (IConfig config, MonadThrow m, FromJSON result) => [Text] -> config -> m result
+ System.Etc.Internal.Types: getConfigValueWith :: (IConfig config, MonadThrow m) => (Value -> Parser result) -> [Text] -> config -> m result
+ System.Etc.Internal.Types: getSelectedConfigSource :: (IConfig config, MonadThrow m) => [Text] -> config -> m ConfigSource
- System.Etc: getAllConfigSources :: (MonadThrow m) => [Text] -> Config -> m (Set ConfigSource)
+ System.Etc: getAllConfigSources :: (IConfig config, MonadThrow m) => [Text] -> config -> m (Set ConfigSource)
- System.Etc: getConfigValue :: (MonadThrow m, FromJSON result) => [Text] -> Config -> m result
+ System.Etc: getConfigValue :: (IConfig config, MonadThrow m, FromJSON result) => [Text] -> config -> m result
- System.Etc: getConfigValueWith :: MonadThrow m => (Value -> Parser a) -> [Text] -> Config -> m a
+ System.Etc: getConfigValueWith :: (IConfig config, MonadThrow m) => (Value -> Parser result) -> [Text] -> config -> m result
- System.Etc: getSelectedConfigSource :: (MonadThrow m) => [Text] -> Config -> m ConfigSource
+ System.Etc: getSelectedConfigSource :: (IConfig config, MonadThrow m) => [Text] -> config -> m ConfigSource

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+0.2.0.0+----+* Move `Config` API to typeclass `IConfig`+* Add a `Setup.hs` file to every hachage repo (issue #5)+* Add example of a project with a config spec embedded in the binary+ 0.1.0.0 ---- * Add support for null values on Default (issue #3)
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
etc.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           etc-version:        0.1.0.0+version:        0.2.0.0 synopsis:       Declarative configuration spec for Haskell projects description:    Please see README.md category:       Configuration, System
src/System/Etc.hs view
@@ -10,6 +10,7 @@   -- * Config   -- $config     Config+  , IConfig   , getConfigValue   , getConfigValueWith   , getSelectedConfigSource@@ -60,7 +61,8 @@   ) where  import System.Etc.Internal.Resolver.Default (resolveDefault)-import System.Etc.Internal.Types            (Config, ConfigSource (..), ConfigValue)+import System.Etc.Internal.Types+    (Config, ConfigSource (..), ConfigValue, IConfig (..)) import System.Etc.Spec     (ConfigSpec, ConfigurationError (..), parseConfigSpec, readConfigSpec) @@ -83,8 +85,7 @@     (hPrintPrettyConfig, printPrettyConfig, renderConfig) #endif -import System.Etc.Internal.Config-    (getAllConfigSources, getConfigValue, getConfigValueWith, getSelectedConfigSource)+import System.Etc.Internal.Config () import System.Etc.Internal.Resolver.Env  (resolveEnv, resolveEnvPure) import System.Etc.Internal.Resolver.File (resolveFiles) 
src/System/Etc/Internal/Config.hs view
@@ -1,3 +1,4 @@+{-# OPTIONS_GHC -fno-warn-orphans #-} {-# OPTIONS_GHC -fno-warn-missing-signatures #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-}@@ -9,6 +10,7 @@  import qualified Data.Aeson          as JSON import qualified Data.Aeson.Internal as JSON (IResult (..), formatError, iparse)+import qualified Data.Aeson.Types    as JSON (Parser) import qualified Data.HashMap.Strict as HashMap import qualified Data.Set            as Set import qualified Data.Text           as Text@@ -36,14 +38,13 @@           HashMap.empty       & JSON.Object --- Can't add signature given JSON.Parser is not exposed ¯\_(ツ)_/¯--- getConfigValueWith---   :: MonadThrow m---   => (JSON.Value -> JSON.Parser value)---   -> [Text]---   -> Config---   -> m value-getConfigValueWith parser keys0 (Config configValue0) =+_getConfigValueWith+  :: MonadThrow m+  => (JSON.Value -> JSON.Parser result)+  -> [Text]+  -> Config+  -> m result+_getConfigValueWith parser keys0 (Config configValue0) =   let     loop keys configValue =       case (keys, configValue) of@@ -89,12 +90,12 @@   in     loop keys0 configValue0 -getSelectedConfigSource+_getSelectedConfigSource   :: (MonadThrow m)   => [Text]   -> Config   -> m ConfigSource-getSelectedConfigSource keys0 (Config configValue0) =+_getSelectedConfigSource keys0 (Config configValue0) =   let     loop keys configValue =       case (keys, configValue) of@@ -119,12 +120,12 @@     loop keys0 configValue0  -getAllConfigSources+_getAllConfigSources   :: (MonadThrow m)   => [Text]   -> Config   -> m (Set ConfigSource)-getAllConfigSources keys0 (Config configValue0) =+_getAllConfigSources keys0 (Config configValue0) =   let     loop keys configValue =       case (keys, configValue) of@@ -143,10 +144,17 @@   in     loop keys0 configValue0 -getConfigValue+_getConfigValue   :: (MonadThrow m, JSON.FromJSON result)   => [Text]   -> Config   -> m result-getConfigValue =-  getConfigValueWith JSON.parseJSON+_getConfigValue =+  _getConfigValueWith JSON.parseJSON+++instance IConfig Config where+  getConfigValue = _getConfigValue+  getConfigValueWith = _getConfigValueWith+  getAllConfigSources = _getAllConfigSources+  getSelectedConfigSource = _getSelectedConfigSource
src/System/Etc/Internal/Types.hs view
@@ -7,10 +7,12 @@   , module System.Etc.Internal.Spec.Types   ) where +import Control.Monad.Catch (MonadThrow)+import Data.HashMap.Strict (HashMap) import Protolude  import qualified Data.Aeson          as JSON-import           Data.HashMap.Strict (HashMap)+import qualified Data.Aeson.Types    as JSON (Parser) import qualified Data.HashMap.Strict as HashMap import qualified Data.Set            as Set @@ -138,3 +140,52 @@           mvalue     Nothing ->       Nothing+++class IConfig config where+  -- | Fetches a configuration value from a given key, if key+  -- is not found, you may pick the failure mode via the 'MonadThrow'+  -- interface.+  --+  -- example:+  --+  -- >>> getConfigValue ["db", "user"] config :: Maybe Text+  -- Just "root"+  -- >>> getConfigValue ["db", "password"] config :: Maybe Text+  -- Nothing+  getConfigValue+    :: (MonadThrow m, JSON.FromJSON result)+    => [Text]   -- ^ Key to fetch from config map+    -> config   -- ^ Config record+    -> m result+  -- | Fetches a configuration value from a given key, normally this key will+  -- point to a sub-config JSON object, which is then passed to the given JSON+  -- parser function. If key is not found, you may pick the failure mode via the+  -- 'MonadThrow' interface.+  --+  -- example:+  --+  -- >>> import qualified Data.Aeson as JSON+  -- >>> import qualified Data.Aeson.Types as JSON (Parser)+  --+  -- >>> connectInfoParser :: JSON.Value -> JSON.Parser DbConnectInfo+  --+  -- >>> getConfigValueWith connectInfoParser ["db"] config+  -- Just (DbConnectInfo {...})+  --+  getConfigValueWith+    :: (MonadThrow m)+    => (JSON.Value -> JSON.Parser result) -- ^ JSON Parser function+    -> [Text]                             -- ^ Key to fetch from config map+    -> config                             -- ^ Config record+    -> m result+  getAllConfigSources+    :: (MonadThrow m)+    => [Text]+    -> config+    -> m (Set ConfigSource)+  getSelectedConfigSource+    :: (MonadThrow m)+    => [Text]+    -> config+    -> m ConfigSource