packages feed

autodocodec 0.2.0.0 → 0.2.0.1

raw patch · 6 files changed

+24/−7 lines, 6 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Autodocodec: class HasObjectCodec object
+ Autodocodec: objectCodec :: HasObjectCodec object => JSONObjectCodec object
+ Autodocodec.Class: class HasObjectCodec object
+ Autodocodec.Class: objectCodec :: HasObjectCodec object => JSONObjectCodec object

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # Changelog +## [0.2.0.1] - 2022-10-06++### Added++* The `HasObjectCodec` type class+ ## [0.2.0.0] - 2022-07-21  ### Added
autodocodec.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           autodocodec-version:        0.2.0.0+version:        0.2.0.1 synopsis:       Self-documenting encoder and decoder homepage:       https://github.com/NorfairKing/autodocodec#readme bug-reports:    https://github.com/NorfairKing/autodocodec/issues
src/Autodocodec.hs view
@@ -19,6 +19,7 @@     JSONCodec,     JSONObjectCodec,     HasCodec (..),+    HasObjectCodec (..),      -- * Writing a codec     object,
src/Autodocodec/Aeson/Decode.hs view
@@ -112,7 +112,7 @@       DiscriminatedUnionCodec propertyName _ m -> do         discriminatorValue <- (value :: JSON.Object) JSON..: Compat.toKey propertyName         case HashMap.lookup discriminatorValue m of-          Nothing -> fail $ "Unexpected discriminator value: " <> T.unpack discriminatorValue+          Nothing -> fail $ "Unexpected discriminator value: " <> show discriminatorValue           Just (_, c) ->             go value c       CommentCodec _ c -> go value c
src/Autodocodec/Class.hs view
@@ -153,6 +153,16 @@ instance HasCodec DiffTime where   codec = dimapCodec realToFrac realToFrac (codec :: JSONCodec Scientific) +-- | A class for values which have a canonical object codec.+--+-- There are no formal laws for this class.+-- If you really want a law, it should be "Whomever uses the 'codec' from your instance should not be surprised."+class HasObjectCodec object where+  -- | A object codec for the value+  --+  -- See the sections on helper functions for implementing this for plenty of examples.+  objectCodec :: JSONObjectCodec object+ -- | A required field -- -- During decoding, the field must be in the object.
src/Autodocodec/Codec.hs view
@@ -58,7 +58,7 @@ -- -- also called an "Autodocodec". ----- In an ideal situation, this type would have only one type paramater: 'Codec value'.+-- In an ideal situation, this type would have only one type parameter: 'Codec value'. -- This does not work very well because we want to be able to implement 'Functor' and 'Applicative', which each require a kind '* -> *'. -- So instead we use two type parameters. --@@ -539,7 +539,7 @@ -- -- === 'HasCodec' instance for sum types with an encoding that is definitely disjoint. ----- The 'eitherCodec' can be used to implement 'HasCodec' instances sum types+-- The 'eitherCodec' can be used to implement 'HasCodec' instances for sum types -- for which the encoding is definitely disjoint. -- -- >>> data War = WorldWar Word8 | OtherWar Text deriving (Show, Eq)@@ -1497,7 +1497,7 @@ -- -- > disjointMatchChoiceCodec = matchChoicesCodecAs DisjointUnion matchChoicesCodec ::-  -- | Codecs, each which their own rendering matcher+  -- | Codecs, each with their own rendering matcher   [(input -> Maybe input, Codec context input output)] ->   -- | Fallback codec, in case none of the matchers in the list match   Codec context input output ->@@ -1513,7 +1513,7 @@ -- -- > disjointMatchChoiceCodec = matchChoicesCodecAs DisjointUnion disjointMatchChoicesCodec ::-  -- | Codecs, each which their own rendering matcher+  -- | Codecs, each with their own rendering matcher   [(input -> Maybe input, Codec context input output)] ->   -- | Fallback codec, in case none of the matchers in the list match   Codec context input output ->@@ -1523,7 +1523,7 @@ -- | An even more general version of 'matchChoicesCodec' and 'disjointMatchChoicesCodec' matchChoicesCodecAs ::   Union ->-  -- | Codecs, each which their own rendering matcher+  -- | Codecs, each with their own rendering matcher   [(input -> Maybe input, Codec context input output)] ->   -- | Fallback codec, in case none of the matchers in the list match   Codec context input output ->