]> Git — Sourcephile - gargantext.git/blob - patches/ekg-json/0001-support-and-require-aeson-2.0.patch
build: add nix flake support
[gargantext.git] / patches / ekg-json / 0001-support-and-require-aeson-2.0.patch
1 From 8622c1b8db27c4ab56f5ea5a63a9cd3dcccafa18 Mon Sep 17 00:00:00 2001
2 From: Julien Moutinho <julm+gargantext@sourcephile.fr>
3 Date: Sat, 1 Jul 2023 19:11:34 +0200
4 Subject: [PATCH] support and require aeson >= 2.0
5
6 ---
7 System/Metrics/Json.hs | 24 +++++++++++++-----------
8 ekg-json.cabal | 6 +++---
9 2 files changed, 16 insertions(+), 14 deletions(-)
10
11 diff --git a/System/Metrics/Json.hs b/System/Metrics/Json.hs
12 index 1c58ca5..09a416d 100644
13 --- a/System/Metrics/Json.hs
14 +++ b/System/Metrics/Json.hs
15 @@ -17,8 +17,10 @@ module System.Metrics.Json
16 ) where
17
18 import Data.Aeson ((.=))
19 +import qualified Data.Aeson.Key as AK
20 +import qualified Data.Aeson.KeyMap as AKM
21 import qualified Data.Aeson.Types as A
22 -import qualified Data.HashMap.Strict as M
23 +import qualified Data.HashMap.Strict as HM
24 import Data.Int (Int64)
25 import qualified Data.Text as T
26 import qualified System.Metrics as Metrics
27 @@ -50,22 +52,22 @@ sampleToJson :: Metrics.Sample -> A.Value
28 sampleToJson metrics =
29 buildOne metrics $ A.emptyObject
30 where
31 - buildOne :: M.HashMap T.Text Metrics.Value -> A.Value -> A.Value
32 - buildOne m o = M.foldlWithKey' build o m
33 + buildOne :: HM.HashMap T.Text Metrics.Value -> A.Value -> A.Value
34 + buildOne m o = HM.foldlWithKey' build o m
35
36 build :: A.Value -> T.Text -> Metrics.Value -> A.Value
37 - build m name val = go m (T.splitOn "." name) val
38 + build m name val = go m (AK.fromText <$> T.splitOn "." name) val
39
40 - go :: A.Value -> [T.Text] -> Metrics.Value -> A.Value
41 - go (A.Object m) [str] val = A.Object $ M.insert str metric m
42 + go :: A.Value -> [A.Key] -> Metrics.Value -> A.Value
43 + go (A.Object m) [str] val = A.Object $ AKM.insert str metric m
44 where metric = valueToJson val
45 - go (A.Object m) (str:rest) val = case M.lookup str m of
46 - Nothing -> A.Object $ M.insert str (go A.emptyObject rest val) m
47 - Just m' -> A.Object $ M.insert str (go m' rest val) m
48 + go (A.Object m) (str:rest) val = case AKM.lookup str m of
49 + Nothing -> A.Object $ AKM.insert str (go A.emptyObject rest val) m
50 + Just m' -> A.Object $ AKM.insert str (go m' rest val) m
51 go v _ _ = typeMismatch "Object" v
52
53 sampleFromJson :: A.Value -> A.Parser Metrics.Sample
54 -sampleFromJson v = M.fromList <$> go [] v
55 +sampleFromJson v = HM.fromList <$> go [] v
56 where go :: [T.Text] -> A.Value -> A.Parser [(T.Text, Metrics.Value)]
57 go prefix (A.Object o) = do
58 mtype <- o A..:? "type"
59 @@ -75,7 +77,7 @@ sampleFromJson v = M.fromList <$> go [] v
60 metricsVal <- valueFromJson ty val
61 return [(T.intercalate "." prefix, metricsVal)]
62 Nothing -> concat
63 - <$> traverse (\(k, v) -> go (prefix++[k]) v) (M.toList o)
64 + <$> traverse (\(k, v) -> go (prefix++[AK.toText k]) v) (AKM.toList o)
65 go _ _ = fail "shouldn't happen"
66
67 typeMismatch :: String -- ^ The expected type
68 diff --git a/ekg-json.cabal b/ekg-json.cabal
69 index d48f3c8..fffe463 100644
70 --- a/ekg-json.cabal
71 +++ b/ekg-json.cabal
72 @@ -24,10 +24,10 @@ library
73 exposed-modules:
74 System.Metrics.Json
75 build-depends:
76 - aeson >=0.4 && < 1.6,
77 - base >= 4.6 && < 4.16,
78 + aeson >=2.0 && < 3.0,
79 + base >= 4.6 && < 4.18,
80 ekg-core >= 0.1 && < 0.2,
81 - text < 1.3,
82 + text < 1.3 || >= 2.0 && < 2.1,
83 unordered-containers < 0.3
84
85 default-language: Haskell2010
86 --
87 2.40.1
88