mirror of
https://github.com/Start9Labs/registry.git
synced 2026-04-04 05:39:44 +00:00
emver for registry appears complete, more testing required but should be ready for beta testing
This commit is contained in:
35
src/Orphans/Emver.hs
Normal file
35
src/Orphans/Emver.hs
Normal file
@@ -0,0 +1,35 @@
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
-- | This module is here for the express purpose of keeping ecosystem dependencies separate from the core library.
|
||||
-- The core library should in theory be only dependent on base, text, and attoparsec. These are reasonable dependencies.
|
||||
-- aeson, persistent, and yesod are not. So we put those here as they will not be extracted into a separate library.
|
||||
module Orphans.Emver where
|
||||
|
||||
import Startlude
|
||||
|
||||
import Data.Aeson
|
||||
import qualified Data.Attoparsec.Text as Atto
|
||||
|
||||
import Lib.Types.Emver
|
||||
import Database.Persist.Sql
|
||||
import qualified Data.Text as T
|
||||
import Control.Monad.Fail ( MonadFail(fail) )
|
||||
|
||||
instance FromJSON Version where
|
||||
parseJSON = withText "Emver Version" $ either fail pure . Atto.parseOnly parseVersion
|
||||
instance ToJSON Version where
|
||||
toJSON = String . show
|
||||
instance FromJSON VersionRange where
|
||||
parseJSON = withText "Emver" $ either fail pure . Atto.parseOnly parseRange
|
||||
instance ToJSON VersionRange where
|
||||
toJSON = String . show
|
||||
|
||||
instance PersistField Version where
|
||||
toPersistValue = PersistText . show
|
||||
fromPersistValue = first T.pack . Atto.parseOnly parseVersion <=< fromPersistValue
|
||||
instance PersistFieldSql Version where
|
||||
sqlType _ = SqlString
|
||||
instance PersistField VersionRange where
|
||||
toPersistValue = PersistText . show
|
||||
fromPersistValue = first T.pack . Atto.parseOnly parseRange <=< fromPersistValue
|
||||
instance PersistFieldSql VersionRange where
|
||||
sqlType _ = SqlString
|
||||
Reference in New Issue
Block a user