typed-uuid 0.1.0.0 → 0.2.0.0
raw patch · 3 files changed
+26/−23 lines, 3 filesdep +autodocodecdep −yamlparse-applicative
Dependencies added: autodocodec
Dependencies removed: yamlparse-applicative
Files
- ChangeLog.md +6/−2
- src/Data/UUID/Typed.hs +15/−16
- typed-uuid.cabal +5/−5
ChangeLog.md view
@@ -1,6 +1,10 @@-# Changelog for typed-uuid+# Changelog -## Unreleased changes+## [0.2.0.0] - 2021-11-20++### Changed++* Replaced `yamlparse-applicative` by `autodocodec`. ## [0.1.0.0] - 2020-05-10
src/Data/UUID/Typed.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE DerivingVia #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-} @@ -14,9 +15,12 @@ parseUUIDString, parseUUIDAsciiBytes, parseUUIDLazyAsciiBytes,+ jsonParseUUID,+ textJSONParseUUID, ) where +import Autodocodec import Control.DeepSeq import Control.Monad.IO.Class import Data.Aeson as JSON@@ -26,7 +30,6 @@ import qualified Data.ByteString.Lazy as LB import Data.Data import Data.Hashable-import qualified Data.Text as T import Data.Text (Text) import qualified Data.UUID as UUID import qualified Data.UUID.V4 as UUID@@ -35,15 +38,15 @@ import Foreign.Storable import GHC.Generics import System.Random-import Text.Read import Web.HttpApiData-import YamlParse.Applicative (YamlKeySchema (..), YamlSchema (..), extraParser, viaYamlSchema) newtype UUID a = UUID { unUUID :: UUID.UUID }- deriving (Eq, Ord, Generic, Data, Storable, Binary, NFData, Hashable, Random, Show, Read, Validity)+ deriving stock (Eq, Ord, Generic, Show, Read, Data)+ deriving newtype (Storable, Binary, NFData, Hashable, Random, Validity)+ deriving (FromJSON, ToJSON) via (Autodocodec (UUID a)) -- | See 'UUID.toText' uuidText :: UUID a -> Text@@ -87,26 +90,22 @@ instance ToJSONKey (UUID a) where toJSONKey = toJSONKeyText (UUID.toText . unUUID) -instance FromJSON (UUID a) where- parseJSON = viaYamlSchema--instance YamlSchema (UUID a) where- yamlSchema = extraParser textJSONParseUUID yamlSchema--instance YamlKeySchema (UUID a) where- yamlKeySchema = extraParser textJSONParseUUID yamlKeySchema- jsonParseUUID :: Value -> Parser (UUID a) jsonParseUUID = withText "UUID" textJSONParseUUID +instance HasCodec (UUID a) where+ codec = bimapCodec f uuidText codec+ where+ f t =+ case UUID.fromText t of+ Nothing -> Left "Invalid Text when parsing UUID"+ Just u -> Right $ UUID u+ textJSONParseUUID :: Text -> Parser (UUID a) textJSONParseUUID t = case UUID.fromText t of Nothing -> fail "Invalid Text when parsing UUID" Just u -> pure $ UUID u--instance ToJSON (UUID a) where- toJSON (UUID u) = JSON.String $ UUID.toText u instance FromHttpApiData (UUID a) where parseUrlPiece t =
typed-uuid.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.33.0.+-- This file has been generated from package.yaml by hpack version 0.34.4. -- -- see: https://github.com/sol/hpack ----- hash: 3beab03fce46280926d3d2293c040ade8b4b61d482353da4ed41730cda4b0cc2+-- hash: 1235b07162ca1fe1139a223b3863aaf2c7fc25e74589485f95b5191f2baca3b4 name: typed-uuid-version: 0.1.0.0+version: 0.2.0.0 synopsis: Phantom-Typed version of UUID description: Please see the README on Github at <https://github.com/NorfairKing/typed-uuid#readme> category: Data@@ -36,6 +36,7 @@ src build-depends: aeson+ , autodocodec , base >=4.11 && <5 , binary , bytestring@@ -44,8 +45,7 @@ , http-api-data , random , text- , uuid >=1.3 && <1.4+ , uuid ==1.3.* , validity , validity-uuid >=0.0- , yamlparse-applicative default-language: Haskell2010