monad-validate 1.2.0.0 → 1.2.0.1
raw patch · 8 files changed
+106/−168 lines, 8 filesdep ~aesondep ~basedep ~mtl
Dependency ranges changed: aeson, base, mtl
Files
- CHANGELOG.md +4/−0
- README.md +1/−1
- monad-validate.cabal +87/−59
- package.yaml +0/−91
- src/Control/Monad/Validate/Class.hs +2/−1
- src/Control/Monad/Validate/Internal.hs +1/−1
- stack.yaml +0/−4
- test/Control/Monad/ValidateSpec.hs +11/−11
CHANGELOG.md view
@@ -1,3 +1,7 @@+# 1.2.0.1 [2022-07-05]++- Added support for GHC 9.0 and 9.2.+ # 1.2.0.0 [2019-08-09] - Added the `exceptToValidate`, `exceptToValidateWith`, `validateToError`, and `validateToErrorWith` functions for converting between different error-raising monads.
README.md view
@@ -1,4 +1,4 @@-# monad-validate+# monad-validate [](https://github.com/lexi-lambda/monad-validate/actions/workflows/build.yml) [][hackage] A Haskell library providing the `ValidateT` monad transformer, designed for writing data validations that provide high-quality error reporting without much effort. `ValidateT` automatically exploits the data dependencies of your program—as encoded implicitly in uses of `fmap`, `<*>`, and `>>=`—to report as many errors as possible upon failure instead of completely aborting at the first one.
monad-validate.cabal view
@@ -1,82 +1,110 @@-cabal-version: 1.12+cabal-version: 2.4+name: monad-validate+version: 1.2.0.1+category: Control+build-type: Simple --- This file has been generated from package.yaml by hpack version 0.31.2.------ see: https://github.com/sol/hpack------ hash: 01f2db430333f42507cd5119f27ea00db52a0c775cf89d589a0dcc045024bf90+synopsis: A monad transformer for data validation.+description:+ Provides the 'ValidateT' monad transformer, designed for writing data+ validations that provide high-quality error reporting without much effort.+ 'ValidateT' automatically exploits the data dependencies of your program—as+ encoded implicitly in uses of 'fmap', '<*>', and '>>='—to report as many+ errors as possible upon failure instead of completely aborting at the first+ one. See "Control.Monad.Validate" for more information. -name: monad-validate-version: 1.2.0.0-synopsis: A monad transformer for data validation.-description: Provides the 'ValidateT' monad transformer, designed for writing data validations that provide- high-quality error reporting without much effort. 'ValidateT' automatically exploits the data- dependencies of your program—as encoded implicitly in uses of 'fmap', '<*>', and '>>='—to report- as many errors as possible upon failure instead of completely aborting at the first one. See- "Control.Monad.Validate" for more information.-category: Control-homepage: https://github.com/hasura/monad-validate#readme-bug-reports: https://github.com/hasura/monad-validate/issues-author: Alexis King <lexi.lambda@gmail.com>-maintainer: Alexis King <lexi.lambda@gmail.com>-copyright: 2019 Hasura-license: ISC-license-file: LICENSE-build-type: Simple+author: Alexis King <lexi.lambda@gmail.com>+maintainer: Alexis King <lexi.lambda@gmail.com>+copyright: 2019 Hasura, 2022 Alexis King+license: ISC+license-file: LICENSE+homepage: https://github.com/lexi-lambda/monad-validate+bug-reports: https://github.com/lexi-lambda/monad-validate/issues+ extra-source-files:- CHANGELOG.md- LICENSE- package.yaml- README.md- stack.yaml+ CHANGELOG.md+ LICENSE+ README.md source-repository head type: git- location: https://github.com/hasura/monad-validate+ location: https://github.com/lexi-lambda/monad-validate -library- exposed-modules:- Control.Monad.Validate- Control.Monad.Validate.Class- Control.Monad.Validate.Internal- other-modules:- Paths_monad_validate- hs-source-dirs:- src- default-extensions: ApplicativeDo BangPatterns ConstraintKinds DataKinds DeriveFoldable DeriveFunctor DeriveGeneric DeriveLift DeriveTraversable DerivingVia EmptyCase ExistentialQuantification FlexibleContexts FlexibleInstances FunctionalDependencies GADTs GeneralizedNewtypeDeriving InstanceSigs KindSignatures LambdaCase MultiParamTypeClasses MultiWayIf NamedFieldPuns OverloadedStrings RankNTypes ScopedTypeVariables StandaloneDeriving TupleSections TypeApplications TypeFamilies- ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints+common common+ ghc-options:+ -Wall+ -Wcompat+ -Wincomplete-record-updates+ -Wincomplete-uni-patterns+ -Wredundant-constraints++ default-language: Haskell2010+ default-extensions:+ ApplicativeDo+ BangPatterns+ ConstraintKinds+ DataKinds+ DeriveFoldable+ DeriveFunctor+ DeriveGeneric+ DeriveLift+ DeriveTraversable+ DerivingVia+ EmptyCase+ ExistentialQuantification+ FlexibleContexts+ FlexibleInstances+ FunctionalDependencies+ GADTs+ GeneralizedNewtypeDeriving+ InstanceSigs+ KindSignatures+ LambdaCase+ MultiParamTypeClasses+ MultiWayIf+ NamedFieldPuns+ OverloadedStrings+ RankNTypes+ ScopedTypeVariables+ StandaloneDeriving+ TupleSections+ TypeApplications+ TypeFamilies+ build-depends:- base >=4.12 && <5+ , base >=4.12 && <5 , exceptions >=0.9 && <1- , monad-control >=1 && <2+ , monad-control ==1.* , mtl , transformers >=0.5.6 , transformers-base <1- default-language: Haskell2010 +library+ import: common+ hs-source-dirs: src+ exposed-modules:+ Control.Monad.Validate+ Control.Monad.Validate.Class+ Control.Monad.Validate.Internal+ test-suite monad-validate-test-suite+ import: common type: exitcode-stdio-1.0- main-is: Main.hs- other-modules:- Control.Monad.ValidateSpec- Paths_monad_validate- hs-source-dirs:- test- default-extensions: ApplicativeDo BangPatterns ConstraintKinds DataKinds DeriveFoldable DeriveFunctor DeriveGeneric DeriveLift DeriveTraversable DerivingVia EmptyCase ExistentialQuantification FlexibleContexts FlexibleInstances FunctionalDependencies GADTs GeneralizedNewtypeDeriving InstanceSigs KindSignatures LambdaCase MultiParamTypeClasses MultiWayIf NamedFieldPuns OverloadedStrings RankNTypes ScopedTypeVariables StandaloneDeriving TupleSections TypeApplications TypeFamilies- ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -rtsopts -threaded -with-rtsopts=-N++ ghc-options: -rtsopts -threaded -with-rtsopts=-N build-depends:- aeson+ , aeson >=2 && <3 , aeson-qq- , base >=4.12 && <5- , exceptions >=0.9 && <1 , hspec- , monad-control >=1 && <2 , monad-validate- , mtl , scientific , text- , transformers >=0.5.6- , transformers-base <1 , unordered-containers , vector- default-language: Haskell2010+ build-tool-depends:+ , hspec-discover:hspec-discover++ hs-source-dirs: test+ main-is: Main.hs+ other-modules:+ Control.Monad.ValidateSpec
− package.yaml
@@ -1,91 +0,0 @@-name: monad-validate-version: 1.2.0.0-category: Control-copyright: 2019 Hasura-license: ISC-author: Alexis King <lexi.lambda@gmail.com>-github: hasura/monad-validate--synopsis: A monad transformer for data validation.-description: |- Provides the 'ValidateT' monad transformer, designed for writing data validations that provide- high-quality error reporting without much effort. 'ValidateT' automatically exploits the data- dependencies of your program—as encoded implicitly in uses of 'fmap', '<*>', and '>>='—to report- as many errors as possible upon failure instead of completely aborting at the first one. See- "Control.Monad.Validate" for more information.--extra-source-files:-- CHANGELOG.md-- LICENSE-- package.yaml-- README.md-- stack.yaml--ghc-options:-- -Wall-- -Wcompat-- -Wincomplete-record-updates-- -Wincomplete-uni-patterns-- -Wredundant-constraints--default-extensions:-- ApplicativeDo-- BangPatterns-- ConstraintKinds-- DataKinds-- DeriveFoldable-- DeriveFunctor-- DeriveGeneric-- DeriveLift-- DeriveTraversable-- DerivingVia-- EmptyCase-- ExistentialQuantification-- FlexibleContexts-- FlexibleInstances-- FunctionalDependencies-- GADTs-- GeneralizedNewtypeDeriving-- InstanceSigs-- KindSignatures-- LambdaCase-- MultiParamTypeClasses-- MultiWayIf-- NamedFieldPuns-- OverloadedStrings-- RankNTypes-- ScopedTypeVariables-- StandaloneDeriving-- TupleSections-- TypeApplications-- TypeFamilies--dependencies:-- base >= 4.12 && < 5-- exceptions >= 0.9 && < 1-- monad-control >= 1 && < 2-- mtl-- transformers >= 0.5.6-- transformers-base < 1--library:- dependencies: []- source-dirs: src--tests:- monad-validate-test-suite:- dependencies:- - aeson- - aeson-qq- - hspec- - monad-validate- - scientific- - text- - unordered-containers- - vector- ghc-options:- - -rtsopts- - -threaded- - -with-rtsopts=-N- main: Main.hs- source-dirs: test
src/Control/Monad/Validate/Class.hs view
@@ -27,6 +27,7 @@ import Control.Monad.Trans.Maybe import Control.Monad.Trans.Reader import Data.Functor+import Data.Kind (Type) {-| The class of validation monads, intended to be used to validate data structures while collecting errors along the way. In a sense, 'MonadValidate' is like a combination of@@ -130,7 +131,7 @@ @ @since 1.2.0.0 -}-newtype WrappedMonadTrans (t :: (* -> *) -> * -> *) (m :: * -> *) (a :: *)+newtype WrappedMonadTrans (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) (a :: Type) = WrapMonadTrans { unwrapMonadTrans :: t m a } deriving (Functor, Applicative, Monad, MonadTrans, MonadTransControl)
src/Control/Monad/Validate/Internal.hs view
@@ -296,7 +296,7 @@ {-# INLINABLE (<*>) #-} instance (Monad m) => Monad (ValidateT e m) where- ValidateT x >>= f = ValidateT (x >>= (getValidateT . f))+ ValidateT m >>= f = ValidateT (m >>= \x -> getValidateT (f x)) {-# INLINE (>>=) #-} instance MonadTrans (ValidateT e) where
− stack.yaml
@@ -1,4 +0,0 @@-resolver: lts-13.30-packages: [.]-extra-deps: []-flags: {}
test/Control/Monad/ValidateSpec.hs view
@@ -5,14 +5,14 @@ module Control.Monad.ValidateSpec (spec) where -import qualified Data.HashMap.Strict as M+import qualified Data.Aeson.KeyMap as KM import qualified Data.Text as T import qualified Data.Vector as V import Control.Monad import Control.Monad.Reader import Control.Monad.Except-import Data.Aeson (Object, Value(..))+import Data.Aeson (Key, Object, Value(..)) import Data.Aeson.QQ (aesonQQ) import Data.Foldable import Data.Functor@@ -37,7 +37,7 @@ data Env = Env { envTables :: [(TableName, TableInfo)]- , envPath :: [Text] }+ , envPath :: [Key] } deriving (Show, Eq) data Query a where@@ -55,14 +55,14 @@ , qrQuery :: Query Integer } deriving (Show, Eq) -data Error = Error { errPath :: [Text], errInfo :: ErrorInfo }+data Error = Error { errPath :: [Key], errInfo :: ErrorInfo } deriving (Show, Eq) data ErrorInfo = JSONBadValue Text Value- | JSONMissingKey Text+ | JSONMissingKey Key | InvalidAuthToken Text | UnknownTableName TableName- | UnknownQueryOperator Text+ | UnknownQueryOperator Key | TypeError TypeRep TypeRep | UnknownColumnName TableName ColumnName | InsufficientPermissions TableName ColumnName@@ -119,7 +119,7 @@ parseColumnName = fmap ColumnName . asString - pushPath :: Text -> m a -> m a+ pushPath :: Key -> m a -> m a pushPath path = local (\env -> env { envPath = path : envPath env }) mkErr info = asks envPath <&> \path -> Error (reverse path) info refuteErr = mkErr >=> \err -> refute [err]@@ -142,11 +142,11 @@ withObject :: Text -> Value -> (Object -> m a) -> m a withObject name v f = case v of { Object o -> f o; _ -> refuteErr $ JSONBadValue name v } - withKey :: Object -> Text -> (Value -> m a) -> m a- withKey o k f = maybe (refuteErr $ JSONMissingKey k) (pushPath k . f) $ M.lookup k o+ withKey :: Object -> Key -> (Value -> m a) -> m a+ withKey o k f = maybe (refuteErr $ JSONMissingKey k) (pushPath k . f) $ KM.lookup k o - withSingleKeyObject :: Text -> Value -> (Text -> Value -> m a) -> m a- withSingleKeyObject name i f = withObject name i $ \o -> case M.toList o of+ withSingleKeyObject :: Text -> Value -> (Key -> Value -> m a) -> m a+ withSingleKeyObject name i f = withObject name i $ \o -> case KM.toList o of { [(k, v)] -> pushPath k $ f k v; _ -> refuteErr $ JSONBadValue name i } spec :: Spec