aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-10-12 12:14:33 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-10-12 12:23:14 +0200
commit7555ced42cf727639ed2767e930afbc8eaf35615 (patch)
tree2a8fb35b31529056d91587710de26ad361fcb1d9 /common
parent0678aaf256203458cd2fd35f820fdcfc8724a709 (diff)
support ?schemaVersion
Diffstat (limited to 'common')
-rw-r--r--common/src/Version.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/common/src/Version.hs b/common/src/Version.hs
index cb568e6..6970968 100644
--- a/common/src/Version.hs
+++ b/common/src/Version.hs
@@ -8,16 +8,24 @@ where
import Data.Aeson qualified as A
import Data.Aeson.Types qualified as A
+import Data.Function (on)
import Data.List
import Data.List.Split
+import Data.Maybe (fromMaybe)
+import Data.String (IsString (..))
import Data.Text qualified as T
data Version = Version Int Int Int
deriving (Show, Eq)
+instance Ord Version where
+ compare = compare `on` toTriple
+
+toTriple :: Version -> (Int, Int, Int)
+toTriple (Version major minor patch) = (major, minor, patch)
+
instance A.ToJSON Version where
- toJSON =
- A.toJSON . versionToString
+ toJSON = A.toJSON . versionToString
instance A.FromJSON Version where
parseJSON (A.String (versionFromText -> Just version)) = pure version
@@ -34,3 +42,6 @@ versionFromString _ = Nothing
versionFromText :: T.Text -> Maybe Version
versionFromText = versionFromString . T.unpack
+
+instance IsString Version where
+ fromString = fromMaybe (error "") . versionFromString