packages feed

himari 1.1.1.0 → 1.1.2.0

raw patch · 20 files changed

+116/−26 lines, 20 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Himari.Env.Simple: mkSimpleEnv :: MonadIO m => m SimpleEnv
+ Himari.Logger: defaultLogAction :: LogAction
+ Himari.Logger: defaultMonadLoggerLog :: (HasLogAction env LogAction, ToLogStr msg) => Loc -> LogSource -> LogLevel -> msg -> Himari env ()

Files

CHANGELOG.md view
@@ -7,6 +7,25 @@  ## [Unreleased] +## [1.1.2.0] - 2026-05-25++### Added++- `mkSimpleEnv` export in `Himari.Env.Simple` to construct a `SimpleEnv`+  with the default settings separately from running it+- `defaultMonadLoggerLog` export in `Himari.Logger`,+  a reusable `monadLoggerLog` implementation for any `HasLogAction` environment+- `defaultLogAction` export in `Himari.Logger`+  for the default `LogAction` that writes to standard error+- Safe Haskell annotations.+  Modules that expose only safe APIs and import only safe modules are marked `Safe`;+  they disable `TemplateHaskell`, `DerivingVia`, and `GeneralizedNewtypeDeriving`,+  which are enabled globally but not allowed under Safe Haskell.+  Modules that expose only safe APIs but cannot be inferred `Safe`+  (because a dependency is not marked safe,+  or because they use Template Haskell or `GeneralizedNewtypeDeriving` internally)+  are marked `Trustworthy`.+ ## [1.1.1.0] - 2026-05-24  ### Added
example/anomaly-monitor/Cpu.hs view
@@ -86,7 +86,7 @@     Right content -> pure $ parseCpuStats content  -- | Format CPU threshold and other config values as text.-showIOCpuThreshold :: (MonadIO m, MonadReader MonitorEnv m) => m Text+showIOCpuThreshold :: (MonadIO m, MonadReader Env m) => m Text showIOCpuThreshold = do   config' <- view config   return $
example/anomaly-monitor/Env.hs view
@@ -1,8 +1,8 @@ module Env-  ( MonitorEnv (..)+  ( Env (..)   , HasLogAction (..)   , HasConfig (..)-  , mkEnv+  , newEnv   ) where  import Config@@ -10,7 +10,7 @@  -- | Custom environment for the monitoring application. -- This demonstrates how to create your own Env instead of using SimpleEnv.-data MonitorEnv = MonitorEnv+data Env = Env   { logAction :: LogAction   -- ^ Log output function.   , config :: MonitorConfig@@ -18,20 +18,17 @@   }   deriving (Generic) -makeFieldsId ''MonitorEnv+makeFieldsId ''Env  -- | Enable MonadLogger for our custom environment. -- This is the key instance that allows us to use logging functions.-instance MonadLogger (Himari MonitorEnv) where-  monadLoggerLog loc src level msg = do-    logAction' <- view logAction-    liftIO . logAction' loc src level $ toLogStr msg+instance MonadLogger (Himari Env) where+  monadLoggerLog = defaultMonadLoggerLog --- | Create the monitoring environment by loading configuration from command line arguments.-mkEnv :: (MonadIO m) => m MonitorEnv-mkEnv = do+-- | Create the application environment by loading configuration from command line arguments.+newEnv :: (MonadIO m) => m Env+newEnv = do   -- Get config file path from command line args (optional)   args <- getArgs-  let logAction' = defaultOutput stderr -- use stderr for logging   config' <- runSimpleEnv . loadConfig $ listToMaybe args-  return $ MonitorEnv{logAction = logAction', config = config'}+  return $ Env{logAction = defaultLogAction, config = config'}
example/anomaly-monitor/Loop.hs view
@@ -10,7 +10,7 @@  -- | Run monitoring loop. monitorLoop-  :: (MonadLogger m, MonadReader MonitorEnv m, MonadUnliftIO m)+  :: (MonadLogger m, MonadReader Env m, MonadUnliftIO m)   => CpuStats   -> Int   -> m ()
example/anomaly-monitor/Main.hs view
@@ -15,5 +15,5 @@ -- | Main entry point. main :: IO () main = do-  initialEnv <- mkEnv+  initialEnv <- newEnv   runHimari initialEnv runAnomalyMonitor
example/anomaly-monitor/Run.hs view
@@ -9,7 +9,7 @@ import Loop  -- | Run application.-runAnomalyMonitor :: (MonadLogger m, MonadReader MonitorEnv m, MonadUnliftIO m) => m ()+runAnomalyMonitor :: (MonadLogger m, MonadReader Env m, MonadUnliftIO m) => m () runAnomalyMonitor = do   logInfoN "Initializing Anomaly Monitoring System..."   printBanner
himari.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.12 name: himari-version: 1.1.1.0+version: 1.1.2.0 synopsis: A standard library for Haskell as an alternative to rio description:   A standard library for Haskell inspired by rio.
src/Himari/Char.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE Trustworthy #-}+ -- | Safe alternatives to partial functions from "Data.Char". module Himari.Char   ( digitToIntMay
src/Himari/Env.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE Trustworthy #-}+ -- | Core environment monad for Himari. module Himari.Env   ( Himari (..)
src/Himari/Env/Simple.hs view
@@ -1,9 +1,12 @@+{-# LANGUAGE Trustworthy #-}+ -- | 基本的な環境を提供するモジュール。 -- 単純に実行だけをしたい場合、これで十分結果を手に入れられることが多いです。 module Himari.Env.Simple   ( SimpleEnv   , runSimpleEnv   , runSimpleEnvWith+  , mkSimpleEnv   ) where  import Himari.Env@@ -21,20 +24,26 @@ makeFieldsId ''SimpleEnv  instance MonadLogger (Himari SimpleEnv) where-  monadLoggerLog loc src level msg = do-    logAction' <- view logAction-    liftIO . logAction' loc src level $ toLogStr msg+  monadLoggerLog = defaultMonadLoggerLog --- | `SimpleEnv`をデフォルト設定で実行する。+-- | `SimpleEnv`のコンテキストのアクションをデフォルト設定で実行します。 runSimpleEnv :: (MonadIO m) => Himari SimpleEnv a -> m a-runSimpleEnv = runSimpleEnvWith $ defaultOutput stderr+runSimpleEnv f = do+  env <- mkSimpleEnv+  runHimari env f --- | `SimpleEnv`をカスタム出力で実行します。+-- | `SimpleEnv`のコンテキストのアクションをカスタム出力で実行します。 runSimpleEnvWith   :: (MonadIO m)   => LogAction-  -- ^ ログの出力方法。例えば`defaultOutput stdout`にすれば標準出力にログが出力されます。+  -- ^ ログの出力方法。+  -- 例えば`defaultOutput stderr`にすれば標準エラー出力にログが出力されます。+  -- `defaultOutput stdout`にすれば標準出力にログが出力されます。   -> Himari SimpleEnv a   -- ^ 実行したいアクション。   -> m a runSimpleEnvWith logAction' = runHimari (SimpleEnv logAction')++-- | `SimpleEnv`をデフォルト設定で作成します。+mkSimpleEnv :: (MonadIO m) => m SimpleEnv+mkSimpleEnv = return $ SimpleEnv{logAction = defaultLogAction}
src/Himari/Logger.hs view
@@ -1,16 +1,35 @@+{-# LANGUAGE Trustworthy #-}+ -- | Logger utilities for Himari. module Himari.Logger   ( HasLogAction (..)   , LogAction+  , defaultMonadLoggerLog+  , defaultLogAction   ) where +import Himari.Env import Himari.Prelude  -- | ログ出力を行う能力があることを検査するための型クラス。--- lensと互換性を持たせているので適切にフィールド名を設定してTemplate Haskellで生成すれば自動で実装されます。+-- lensと互換性を持たせているので適切にフィールド名を設定して、+-- Template Haskellで生成すれば自動で実装されます。 class HasLogAction s a | s -> a where   logAction :: Lens' s a  -- | ログ出力を行う関数の型。 -- 出力をカスタムしたい場合、このシグネチャに合わせた関数を作成するとやりやすい。 type LogAction = Loc -> LogSource -> LogLevel -> LogStr -> IO ()++-- | "MonadLogger".'monadLoggerLog'に渡せるデフォルトの実装。+defaultMonadLoggerLog+  :: (HasLogAction env LogAction, ToLogStr msg)+  => Loc -> LogSource -> LogLevel -> msg -> Himari env ()+defaultMonadLoggerLog loc src level msg = do+  logAction' <- view logAction+  liftIO . logAction' loc src level $ toLogStr msg++-- | デフォルトのログ出力。+-- 標準エラー出力にログを出力します。+defaultLogAction :: LogAction+defaultLogAction = defaultOutput stderr
src/Himari/Prelude/Arrow.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE Safe #-}+{-# LANGUAGE NoDerivingVia #-}+{-# LANGUAGE NoGeneralizedNewtypeDeriving #-}+{-# LANGUAGE NoTemplateHaskell #-}+ -- | "Control.Arrow" re-exports, hiding symbols that conflict with "Data.Bifunctor". module Himari.Prelude.Arrow   ( module Export
src/Himari/Prelude/Catch.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE Safe #-}+{-# LANGUAGE NoDerivingVia #-}+{-# LANGUAGE NoGeneralizedNewtypeDeriving #-}+{-# LANGUAGE NoTemplateHaskell #-}+ -- | Re-exports from "Control.Monad.Catch" that don't conflict with "UnliftIO". -- -- Functions that conflict with "UnliftIO" are hidden.
src/Himari/Prelude/Category.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE Safe #-}+{-# LANGUAGE NoDerivingVia #-}+{-# LANGUAGE NoGeneralizedNewtypeDeriving #-}+{-# LANGUAGE NoTemplateHaskell #-}+ -- | "Control.Category" re-exports, hiding symbols that conflict with "Prelude". module Himari.Prelude.Category   ( module Export
src/Himari/Prelude/Data.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE Safe #-}+{-# LANGUAGE NoDerivingVia #-}+{-# LANGUAGE NoGeneralizedNewtypeDeriving #-}+{-# LANGUAGE NoTemplateHaskell #-}+ -- | "Data.Data" re-exports, hiding symbols that conflict with "GHC.Generics". module Himari.Prelude.Data   ( module Export
src/Himari/Prelude/FilePath.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE Safe #-}+{-# LANGUAGE NoDerivingVia #-}+{-# LANGUAGE NoGeneralizedNewtypeDeriving #-}+{-# LANGUAGE NoTemplateHaskell #-}+ -- | "System.FilePath" re-exports, hiding symbols that conflict with "Control.Lens". module Himari.Prelude.FilePath   ( module Export
src/Himari/Prelude/Generics.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE Safe #-}+{-# LANGUAGE NoDerivingVia #-}+{-# LANGUAGE NoGeneralizedNewtypeDeriving #-}+{-# LANGUAGE NoTemplateHaskell #-}+ -- | "GHC.Generics" re-exports, hiding symbols that conflict with "Control.Lens". module Himari.Prelude.Generics   ( module Export
src/Himari/Prelude/Monoid.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE Safe #-}+{-# LANGUAGE NoDerivingVia #-}+{-# LANGUAGE NoGeneralizedNewtypeDeriving #-}+{-# LANGUAGE NoTemplateHaskell #-}+ -- | "Data.Monoid" and "Data.Semigroup" re-exports, hiding conflicting symbols. module Himari.Prelude.Monoid   ( module Export
src/Himari/Prelude/Safe.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE Safe #-}+{-# LANGUAGE NoDerivingVia #-}+{-# LANGUAGE NoGeneralizedNewtypeDeriving #-}+{-# LANGUAGE NoTemplateHaskell #-}+ -- | "Safe", "Safe.Exact", and "Safe.Foldable" re-exports. -- Only total functions are exported; partial functions are hidden. -- "Safe.Foldable" is preferred for more generic versions,
src/Himari/Prelude/Type.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE Trustworthy #-}+ -- | Type-only re-exports from various modules. -- -- Includes types from "Data.ByteString", "Data.HashMap.Strict",