packages feed

haspara 0.0.0.7 → 0.0.0.8

raw patch · 15 files changed

+79/−9 lines, 15 filesdep ~hashabledep ~template-haskelldep ~time

Dependency ranges changed: hashable, template-haskell, time

Files

CHANGELOG.md view
@@ -2,11 +2,28 @@ ## [Unreleased]  +<a name="0.0.0.8"></a>+## [0.0.0.8] - 2022-11-21+### Chore+- bump development version to 0.0.0.8+- **nix:** make it more convenient to test against different ghc versions+- **nix:** make default haspara Nix package come with haddock++### Fix+- add explicit Aeson.ToJSON.toEncoding implementations+- **deps:** support ghc92++### Pull Requests+- Merge pull request [#17](https://github.com/telostat/haspara/issues/17) from telostat/15-make-it-more-convenient-to-test-against-different-ghc-versions+- Merge pull request [#16](https://github.com/telostat/haspara/issues/16) from telostat/vst/aeson-encoding++ <a name="0.0.0.7"></a> ## [0.0.0.7] - 2022-11-17 ### Chore - bump development version to 0.0.0.7 - **dev:** document pre-release checks+- **release:** 0.0.0.7  ### Docs - add missing Haddock documentation for function@@ -166,7 +183,8 @@ - Merge pull request [#1](https://github.com/telostat/haspara/issues/1) from telostat/init  -[Unreleased]: https://github.com/telostat/haspara/compare/0.0.0.7...HEAD+[Unreleased]: https://github.com/telostat/haspara/compare/0.0.0.8...HEAD+[0.0.0.8]: https://github.com/telostat/haspara/compare/0.0.0.7...0.0.0.8 [0.0.0.7]: https://github.com/telostat/haspara/compare/0.0.0.6...0.0.0.7 [0.0.0.6]: https://github.com/telostat/haspara/compare/0.0.0.5...0.0.0.6 [0.0.0.5]: https://github.com/telostat/haspara/compare/0.0.0.4...0.0.0.5
README.md view
@@ -13,6 +13,28 @@ *haspara* is a Haskell library that provides monetary definitions and a rudimentary (and experimental) accounting functionality. +## Supported GHC Versions++1. `ghc90`+1. `ghc92`++At the moment, there is no particular reason for not supporting+`ghc94` except that required settings are not done yet in Nix support+files, in particular for Cabal dependency.++## Testing Against GHC Versions++You can use Nix support to test against different GHC versions:++```sh+nix-build --arg compiler "\"ghc92\""+nix-build --arg compiler "\"ghc90\""+```++`nix-build` command will default to `ghc90`. Check `./default.nix`+file for the default `ghc` version in case that this documentation is+out of date.+ ## Development  Before committing code to repository, reformat the code:@@ -65,6 +87,8 @@     cabal build -O0     cabal test -O0     cabal haddock -O0+    nix-build --arg compiler "\"ghc92\""+    nix-build --arg compiler "\"ghc90\""     ```  4. Update [CHANGELOG.md](./CHANGELOG.md) file:
haspara.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           haspara-version:        0.0.0.7+version:        0.0.0.8 synopsis:       A library providing definitions to work with monetary values. description:    Please see the README on GitHub at <https://github.com/telostat/haspara#readme> category:       Finance@@ -54,15 +54,15 @@     , containers >=0.6.4.1 && <0.7     , data-default ==0.7.*     , exceptions >=0.10.4 && <0.11-    , hashable >=1.3.0.0 && <1.4+    , hashable >=1.3.0.0 && <1.5     , megaparsec >=9.0.1 && <9.3     , mtl >=2.2.2 && <2.3     , refined >=0.6.3 && <0.7     , safe-decimal >=0.2.1.0 && <0.3     , scientific >=0.3.7.0 && <0.4-    , template-haskell >=2.16.0.0 && <2.18+    , template-haskell >=2.16.0.0 && <2.19     , text >=1.2.4.1 && <1.3-    , time >=1.9.3 && <1.10+    , time >=1.9.3 && <1.12   default-language: Haskell2010  test-suite haspara-doctest
src/Haspara/Accounting/Account.hs view
@@ -69,6 +69,7 @@  instance Aeson.ToJSON AccountKind where   toJSON = Aeson.genericToJSON $ aesonOptionsForSingleTag "AccountKind"+  toEncoding = Aeson.genericToEncoding $ aesonOptionsForSingleTag "AccountKind"   -- | Provides textual representation of a given 'AccountKind'.@@ -125,3 +126,4 @@  instance Aeson.ToJSON o => Aeson.ToJSON (Account o) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "account"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "account"
src/Haspara/Accounting/Amount.hs view
@@ -54,6 +54,7 @@ -- Right (Amount {amountSide = SideCredit, amountValue = Refined 42.00}) instance KnownNat precision => Aeson.ToJSON (Amount precision) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "amount"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "amount"   -- | Returns the debit value of the 'Amount', if any.
src/Haspara/Accounting/Balance.hs view
@@ -63,9 +63,9 @@ -- >>> import Haspara.Accounting.Side -- >>> import Haspara.Quantity -- >>> Aeson.encode (Balance SideDebit (mkQuantity 42 :: Quantity 2) def)--- "{\"inventory\":{\"current\":[],\"history\":[],\"total\":0.0},\"side\":\"db\",\"value\":42.0}"+-- "{\"side\":\"db\",\"value\":42.0,\"inventory\":{\"total\":0.0,\"current\":[],\"history\":[]}}" -- >>> Aeson.encode (Balance SideCredit (mkQuantity 42 :: Quantity 2) def)--- "{\"inventory\":{\"current\":[],\"history\":[],\"total\":0.0},\"side\":\"cr\",\"value\":42.0}"+-- "{\"side\":\"cr\",\"value\":42.0,\"inventory\":{\"total\":0.0,\"current\":[],\"history\":[]}}" -- >>> Aeson.eitherDecode (Aeson.encode (Balance SideDebit (mkQuantity 42 :: Quantity 2) def)) :: Either String (Balance 2) -- Right (Balance {balanceSide = SideDebit, balanceValue = 42.00, balanceInventory = MkInventory {inventoryTotal = 0.000000000000, inventoryCurrent = fromList [], inventoryHistory = fromList []}}) -- >>> Aeson.eitherDecode (Aeson.encode (Balance SideCredit (mkQuantity 42 :: Quantity 2) def)) :: Either String (Balance 2)@@ -74,15 +74,16 @@ -- For negative balances: -- -- >>> Aeson.encode (Balance SideDebit (mkQuantity (-42) :: Quantity 2) def)--- "{\"inventory\":{\"current\":[],\"history\":[],\"total\":0.0},\"side\":\"db\",\"value\":-42.0}"+-- "{\"side\":\"db\",\"value\":-42.0,\"inventory\":{\"total\":0.0,\"current\":[],\"history\":[]}}" -- >>> Aeson.encode (Balance SideCredit (mkQuantity (-42) :: Quantity 2) def)--- "{\"inventory\":{\"current\":[],\"history\":[],\"total\":0.0},\"side\":\"cr\",\"value\":-42.0}"+-- "{\"side\":\"cr\",\"value\":-42.0,\"inventory\":{\"total\":0.0,\"current\":[],\"history\":[]}}" -- >>> Aeson.eitherDecode (Aeson.encode (Balance SideDebit (mkQuantity (-42) :: Quantity 2) def)) :: Either String (Balance 2) -- Right (Balance {balanceSide = SideDebit, balanceValue = -42.00, balanceInventory = MkInventory {inventoryTotal = 0.000000000000, inventoryCurrent = fromList [], inventoryHistory = fromList []}}) -- >>> Aeson.eitherDecode (Aeson.encode (Balance SideCredit (mkQuantity (-42) :: Quantity 2) def)) :: Either String (Balance 2) -- Right (Balance {balanceSide = SideCredit, balanceValue = -42.00, balanceInventory = MkInventory {inventoryTotal = 0.000000000000, inventoryCurrent = fromList [], inventoryHistory = fromList []}}) instance KnownNat precision => Aeson.ToJSON (Balance precision) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "balance"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "balance"   -- | Returns the debit quantity, if any.
src/Haspara/Accounting/Inventory.hs view
@@ -55,6 +55,7 @@  instance (KnownNat pprec, KnownNat sprec, KnownNat vprec) => Aeson.ToJSON (Inventory pprec sprec vprec) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "inventory"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "inventory"   -- | Data definition for inventory events.@@ -77,6 +78,7 @@  instance (KnownNat pprec, KnownNat sprec) => Aeson.ToJSON (InventoryEvent pprec sprec) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "inventoryEvent"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "inventoryEvent"   -- | Data definition for PnL-taking inventory history items.@@ -110,6 +112,7 @@  instance (KnownNat pprec, KnownNat sprec, KnownNat vprec) => Aeson.ToJSON (InventoryHistoryItem pprec sprec vprec) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "inventoryHistoryItem"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "inventoryHistoryItem"   -- * Operations
src/Haspara/Accounting/Journal.hs view
@@ -35,6 +35,7 @@  instance (KnownNat precision, Aeson.ToJSON account, Aeson.ToJSON event) => Aeson.ToJSON (Journal precision account event) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "journal"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "journal"   -- | Data definition for a journal entry.@@ -57,6 +58,7 @@  instance (KnownNat precision, Aeson.ToJSON account, Aeson.ToJSON event) => Aeson.ToJSON (JournalEntry precision account event) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "journalEntry"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "journalEntry"   -- | Returns the total debit amount of a journal entry.@@ -118,6 +120,7 @@  instance (KnownNat precision, Aeson.ToJSON account, Aeson.ToJSON event) => Aeson.ToJSON (JournalEntryItem precision account event) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "journalEntryItem"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "journalEntryItem"   -- | Data definition for inventory event.@@ -135,6 +138,7 @@  instance (Aeson.ToJSON account, Aeson.ToJSON event) => Aeson.ToJSON (JournalEntryItemInventoryEvent account event) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "journalEntryItemInventoryEvent"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "journalEntryItemInventoryEvent"   -- | Creates a 'JournalEntryItem' from the given signed /value/, the account it
src/Haspara/Accounting/Ledger.hs view
@@ -40,6 +40,7 @@  instance (KnownNat precision, Aeson.ToJSON account, Aeson.ToJSON event) => Aeson.ToJSON (GeneralLedger precision account event) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "generalLedger"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "generalLedger"   -- | Data definition for a ledger.@@ -58,6 +59,7 @@ instance (KnownNat precision, Aeson.ToJSON account, Aeson.ToJSON event) => Aeson.ToJSON (Ledger precision account event) where   -- TODO: Add ledgerClosing, too.   toJSON = Aeson.genericToJSON $ commonAesonOptions "ledger"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "ledger"   -- | Returns the closing balance of a ledger.@@ -86,6 +88,7 @@  instance (KnownNat precision, Aeson.ToJSON event) => Aeson.ToJSON (LedgerEntry precision event) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "ledgerEntry"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "ledgerEntry"   -- | Initializes an empty ledger for a given account.
src/Haspara/Accounting/Side.hs view
@@ -14,6 +14,7 @@ module Haspara.Accounting.Side where  import qualified Data.Aeson as Aeson+import qualified Data.Aeson.Encoding as Aeson.Encoding import qualified Data.Text as T import GHC.TypeLits (KnownNat) import Haspara.Accounting.Account (AccountKind (..))@@ -54,6 +55,10 @@ instance Aeson.ToJSON Side where   toJSON SideDebit = Aeson.String "db"   toJSON SideCredit = Aeson.String "cr"+++  toEncoding SideDebit = Aeson.Encoding.text "db"+  toEncoding SideCredit = Aeson.Encoding.text "cr"   -- | Gives the other side.
src/Haspara/Accounting/TrialBalance.hs view
@@ -29,6 +29,7 @@  instance (KnownNat precision, Aeson.ToJSON account, Aeson.ToJSON event) => Aeson.ToJSON (TrialBalance precision account event) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "trialBalance"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "trialBalance"   -- | Data definition for a trial balance item.@@ -45,6 +46,7 @@  instance (KnownNat precision, Aeson.ToJSON account, Aeson.ToJSON event) => Aeson.ToJSON (TrialBalanceItem precision account event) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "trialBalanceItem"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "trialBalanceItem"   -- | Returns the amount of the trial balance item. This is a simple conversion
src/Haspara/Currency.hs view
@@ -10,6 +10,7 @@  import Control.Monad.Except (MonadError (throwError)) import qualified Data.Aeson as Aeson+import qualified Data.Aeson.Encoding as Aeson.Encoding import Data.Hashable (Hashable) import Data.String (IsString (..)) import qualified Data.Text as T@@ -87,6 +88,7 @@ -- "\"USD\"" instance Aeson.ToJSON Currency where   toJSON (MkCurrency c) = Aeson.String c+  toEncoding (MkCurrency c) = Aeson.Encoding.text c   -- | Smart constructor for 'Currency' values within 'MonadError' context.@@ -185,6 +187,7 @@  instance Aeson.ToJSON CurrencyPair where   toJSON = Aeson.genericToJSON $ commonAesonOptions "currencyPair"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "currencyPair"   -- | 'Show' instance for 'CurrencyPair'.
src/Haspara/FxQuote.hs view
@@ -50,6 +50,7 @@  instance KnownNat s => Aeson.ToJSON (FxQuote s) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "fxQuote"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "fxQuote"   -- | Smart constructor for 'FxQuote' values within @'MonadError' 'T.Text'@
src/Haspara/Monetary.hs view
@@ -45,6 +45,7 @@  instance KnownNat s => Aeson.ToJSON (Money s) where   toJSON = Aeson.genericToJSON $ commonAesonOptions "money"+  toEncoding = Aeson.genericToEncoding $ commonAesonOptions "money"   -- | Type encoding of a monetary context.
src/Haspara/Quantity.hs view
@@ -18,6 +18,7 @@ import Control.Applicative (liftA2) import Control.Monad.Except (MonadError (throwError)) import qualified Data.Aeson as Aeson+import qualified Data.Aeson.Encoding as Aeson.Encoding import Data.Either (fromRight) import Data.Proxy (Proxy (..)) import Data.Scientific (FPFormat (Fixed), Scientific, formatScientific)@@ -100,6 +101,7 @@ -- "0.42" instance (KnownNat s) => Aeson.ToJSON (Quantity s) where   toJSON = Aeson.Number . D.toScientificDecimal . unQuantity+  toEncoding = Aeson.Encoding.scientific . D.toScientificDecimal . unQuantity   -- | Numeric arithmetic over 'Quantity' values.