git.iko.soy/typeable/bloodhound
on master help sign in
Add semigroups instances
0f6becfMichael Xavier
src/Database/V1/Bloodhound/Types.hs+93−86
@@ -365,40 +365,44 @@ module Database.V1.Bloodhound.Types
365 , EsPassword(..)
365 , EsPassword(..)
366 ) where
366 ) where
367
367
368−import Control.Applicative as A
368+import Control.Applicative as A
369−import Control.Arrow (first)
369+import Control.Arrow (first)
370import Control.Monad.Catch
370import Control.Monad.Catch
371import Control.Monad.Except
371import Control.Monad.Except
372import Control.Monad.Reader
372import Control.Monad.Reader
373import Control.Monad.State
373import Control.Monad.State
374−import Control.Monad.Writer
374+import Control.Monad.Writer (MonadWriter)
375import Data.Aeson
375import Data.Aeson
376−import Data.Aeson.Types (Pair, Parser, emptyObject,
376+import Data.Aeson.Types (Pair, Parser,
377+ emptyObject,
377− parseEither, parseMaybe)
378+ parseEither, parseMaybe)
378−import qualified Data.ByteString.Lazy.Char8 as L
379+import qualified Data.ByteString.Lazy.Char8 as L
379import Data.Char
380import Data.Char
380−import Data.Hashable (Hashable)
381+import Data.Hashable (Hashable)
381−import qualified Data.HashMap.Strict as HM
382+import qualified Data.HashMap.Strict as HM
382−import Data.List (foldl', intercalate, nub)
383+import Data.List (foldl', intercalate,
384+ nub)
383−import Data.List.NonEmpty (NonEmpty (..), toList)
385+import Data.List.NonEmpty (NonEmpty (..), toList)
384−import qualified Data.Map.Strict as M
386+import qualified Data.Map.Strict as M
385import Data.Maybe
387import Data.Maybe
386−import Data.Scientific (Scientific)
388+import Data.Scientific (Scientific)
387−import Data.Text (Text)
389+import Data.Semigroup
390+import Data.Text (Text)
388−import qualified Data.Text as T
391+import qualified Data.Text as T
389import Data.Time.Calendar
392import Data.Time.Calendar
390−import Data.Time.Clock (NominalDiffTime, UTCTime)
393+import Data.Time.Clock (NominalDiffTime,
394+ UTCTime)
391import Data.Time.Clock.POSIX
395import Data.Time.Clock.POSIX
392−import qualified Data.Traversable as DT
396+import qualified Data.Traversable as DT
393−import Data.Typeable (Typeable)
397+import Data.Typeable (Typeable)
394−import qualified Data.Vector as V
398+import qualified Data.Vector as V
395−import qualified Data.Version as Vers
399+import qualified Data.Version as Vers
396import GHC.Enum
400import GHC.Enum
397−import GHC.Generics (Generic)
401+import GHC.Generics (Generic)
398import Network.HTTP.Client
402import Network.HTTP.Client
399−import qualified Network.HTTP.Types.Method as NHTM
403+import qualified Network.HTTP.Types.Method as NHTM
400−import qualified Text.ParserCombinators.ReadP as RP
404+import qualified Text.ParserCombinators.ReadP as RP
401−import qualified Text.Read as TR
405+import qualified Text.Read as TR
402
406
403import Database.V1.Bloodhound.Types.Class
407import Database.V1.Bloodhound.Types.Class
404import Database.V1.Bloodhound.Types.Internal
408import Database.V1.Bloodhound.Types.Internal
@@ -1647,12 +1651,12 @@ data SearchHits a =
1647 , maxScore :: Score
1651 , maxScore :: Score
1648 , hits :: [Hit a] } deriving (Eq, Read, Show, Generic, Typeable)
1652 , hits :: [Hit a] } deriving (Eq, Read, Show, Generic, Typeable)
1649
1653
1654+instance Semigroup (SearchHits a) where
1655+ (SearchHits ta ma ha) <> (SearchHits tb mb hb) = SearchHits (ta + tb) (max ma mb) (ha <> hb)
1650
1656
1651instance Monoid (SearchHits a) where
1657instance Monoid (SearchHits a) where
1652 mempty = SearchHits 0 Nothing mempty
1658 mempty = SearchHits 0 Nothing mempty
1653− mappend (SearchHits ta ma ha) (SearchHits tb mb hb) =
1659+ mappend = (<>)
1654− SearchHits (ta + tb) (max ma mb) (ha <> hb)
1655−
1656
1660
1657data Hit a =
1661data Hit a =
1658 Hit { hitIndex :: IndexName
1662 Hit { hitIndex :: IndexName
@@ -1675,7 +1679,7 @@ showText = T.pack . show
1675readMay :: Read a => String -> Maybe a
1679readMay :: Read a => String -> Maybe a
1676readMay s = case reads s of
1680readMay s = case reads s of
1677 (a, ""):_ -> Just a
1681 (a, ""):_ -> Just a
1678− _ -> Nothing
1682+ _ -> Nothing
1679
1683
1680parseReadText :: Read a => Text -> Parser a
1684parseReadText :: Read a => Text -> Parser a
1681parseReadText = maybe mzero return . readMay . T.unpack
1685parseReadText = maybe mzero return . readMay . T.unpack
@@ -1725,8 +1729,8 @@ data Aggregation = TermsAgg TermsAggregation
1725 | ValueCountAgg ValueCountAggregation
1729 | ValueCountAgg ValueCountAggregation
1726 | FilterAgg FilterAggregation
1730 | FilterAgg FilterAggregation
1727 | DateRangeAgg DateRangeAggregation
1731 | DateRangeAgg DateRangeAggregation
1728− | MissingAgg MissingAggregation
1732+ | MissingAgg MissingAggregation
1729− | TopHitsAgg TopHitsAggregation
1733+ | TopHitsAgg TopHitsAggregation
1730 deriving (Eq, Read, Show, Generic, Typeable)
1734 deriving (Eq, Read, Show, Generic, Typeable)
1731
1735
1732data TopHitsAggregation = TopHitsAggregation
1736data TopHitsAggregation = TopHitsAggregation
@@ -1874,11 +1878,11 @@ instance ToJSON Interval where
1874 toJSON (FractionalInterval fraction interval) = toJSON $ show fraction ++ show interval
1878 toJSON (FractionalInterval fraction interval) = toJSON $ show fraction ++ show interval
1875
1879
1876instance Show TimeInterval where
1880instance Show TimeInterval where
1877− show Weeks = "w"
1881+ show Weeks = "w"
1878− show Days = "d"
1882+ show Days = "d"
1879− show Hours = "h"
1883+ show Hours = "h"
1880− show Minutes = "m"
1884+ show Minutes = "m"
1881− show Seconds = "s"
1885+ show Seconds = "s"
1882
1886
1883instance Read TimeInterval where
1887instance Read TimeInterval where
1884 readPrec = f =<< TR.get
1888 readPrec = f =<< TR.get
@@ -1934,7 +1938,7 @@ instance ToJSON Aggregation where
1934 toJSON (MissingAgg (MissingAggregation{..})) =
1938 toJSON (MissingAgg (MissingAggregation{..})) =
1935 object ["missing" .= object ["field" .= maField]]
1939 object ["missing" .= object ["field" .= maField]]
1936
1940
1937− toJSON (TopHitsAgg (TopHitsAggregation mfrom msize msort)) =
1941+ toJSON (TopHitsAgg (TopHitsAggregation mfrom msize msort)) =
1938 omitNulls ["top_hits" .= omitNulls [ "size" .= msize
1942 omitNulls ["top_hits" .= omitNulls [ "size" .= msize
1939 , "from" .= mfrom
1943 , "from" .= mfrom
1940 , "sort" .= msort
1944 , "sort" .= msort
@@ -1949,22 +1953,22 @@ instance ToJSON DateRangeAggregation where
1949 ]
1953 ]
1950
1954
1951instance ToJSON DateRangeAggRange where
1955instance ToJSON DateRangeAggRange where
1952− toJSON (DateRangeFrom e) = object [ "from" .= e ]
1956+ toJSON (DateRangeFrom e) = object [ "from" .= e ]
1953− toJSON (DateRangeTo e) = object [ "to" .= e ]
1957+ toJSON (DateRangeTo e) = object [ "to" .= e ]
1954 toJSON (DateRangeFromAndTo f t) = object [ "from" .= f, "to" .= t ]
1958 toJSON (DateRangeFromAndTo f t) = object [ "from" .= f, "to" .= t ]
1955
1959
1956instance ToJSON DateMathExpr where
1960instance ToJSON DateMathExpr where
1957 toJSON (DateMathExpr a mods) = String (fmtA a <> mconcat (fmtMod <$> mods))
1961 toJSON (DateMathExpr a mods) = String (fmtA a <> mconcat (fmtMod <$> mods))
1958− where fmtA DMNow = "now"
1962+ where fmtA DMNow = "now"
1959 fmtA (DMDate date) = (T.pack $ showGregorian date) <> "||"
1963 fmtA (DMDate date) = (T.pack $ showGregorian date) <> "||"
1960− fmtMod (AddTime n u) = "+" <> showText n <> fmtU u
1964+ fmtMod (AddTime n u) = "+" <> showText n <> fmtU u
1961 fmtMod (SubtractTime n u) = "-" <> showText n <> fmtU u
1965 fmtMod (SubtractTime n u) = "-" <> showText n <> fmtU u
1962− fmtMod (RoundDownTo u) = "/" <> fmtU u
1966+ fmtMod (RoundDownTo u) = "/" <> fmtU u
1963− fmtU DMYear = "y"
1967+ fmtU DMYear = "y"
1964− fmtU DMMonth = "M"
1968+ fmtU DMMonth = "M"
1965− fmtU DMWeek = "w"
1969+ fmtU DMWeek = "w"
1966− fmtU DMDay = "d"
1970+ fmtU DMDay = "d"
1967− fmtU DMHour = "h"
1971+ fmtU DMHour = "h"
1968 fmtU DMMinute = "m"
1972 fmtU DMMinute = "m"
1969 fmtU DMSecond = "s"
1973 fmtU DMSecond = "s"
1970
1974
@@ -2044,8 +2048,8 @@ instance (FromJSON a) => FromJSON (Bucket a) where
2044instance FromJSON BucketValue where
2048instance FromJSON BucketValue where
2045 parseJSON (String t) = return $ TextValue t
2049 parseJSON (String t) = return $ TextValue t
2046 parseJSON (Number s) = return $ ScientificValue s
2050 parseJSON (Number s) = return $ ScientificValue s
2047− parseJSON (Bool b) = return $ BoolValue b
2051+ parseJSON (Bool b) = return $ BoolValue b
2048− parseJSON _ = mempty
2052+ parseJSON _ = mempty
2049
2053
2050instance FromJSON MissingResult where
2054instance FromJSON MissingResult where
2051 parseJSON = withObject "MissingResult" parse
2055 parseJSON = withObject "MissingResult" parse
@@ -2098,9 +2102,12 @@ instance (FromJSON a) => FromJSON (TopHitResult a) where
2098 v .: "hits"
2102 v .: "hits"
2099 parseJSON _ = fail "Failure in FromJSON (TopHitResult a)"
2103 parseJSON _ = fail "Failure in FromJSON (TopHitResult a)"
2100
2104
2105+instance Semigroup Filter where
2106+ a <> b = AndFilter [a, b] defaultCache
2107+
2101instance Monoid Filter where
2108instance Monoid Filter where
2102 mempty = IdentityFilter
2109 mempty = IdentityFilter
2103− mappend a b = AndFilter [a, b] defaultCache
2110+ mappend = (<>)
2104
2111
2105instance Seminearring Filter where
2112instance Seminearring Filter where
2106 a <||> b = OrFilter [a, b] defaultCache
2113 a <||> b = OrFilter [a, b] defaultCache
@@ -2291,11 +2298,11 @@ fieldTagged f o = case HM.toList o of
2291 _ -> fail "Expected object with 1 field-named key"
2298 _ -> fail "Expected object with 1 field-named key"
2292
2299
2293-- Try to get an AggregationResults when we don't know the
2300-- Try to get an AggregationResults when we don't know the
2294−-- field name. We filter out the known keys to try to minimize the noise.
2301+-- field name. We filter out the known keys to try to minimize the noise.
2295getNamedSubAgg :: Object -> [Text] -> Maybe AggregationResults
2302getNamedSubAgg :: Object -> [Text] -> Maybe AggregationResults
2296getNamedSubAgg o knownKeys = maggRes
2303getNamedSubAgg o knownKeys = maggRes
2297 where unknownKeys = HM.filterWithKey (\k _ -> k `notElem` knownKeys) o
2304 where unknownKeys = HM.filterWithKey (\k _ -> k `notElem` knownKeys) o
2298− maggRes
2305+ maggRes
2299 | HM.null unknownKeys = Nothing
2306 | HM.null unknownKeys = Nothing
2300 | otherwise = Just . M.fromList $ HM.toList unknownKeys
2307 | otherwise = Just . M.fromList $ HM.toList unknownKeys
2301
2308
@@ -2470,9 +2477,9 @@ instance FromJSON Query where
2470
2477
2471omitNulls :: [(Text, Value)] -> Value
2478omitNulls :: [(Text, Value)] -> Value
2472omitNulls = object . filter notNull where
2479omitNulls = object . filter notNull where
2473− notNull (_, Null) = False
2480+ notNull (_, Null) = False
2474 notNull (_, Array a) = (not . V.null) a
2481 notNull (_, Array a) = (not . V.null) a
2475− notNull _ = True
2482+ notNull _ = True
2476
2483
2477
2484
2478instance ToJSON SimpleQueryStringQuery where
2485instance ToJSON SimpleQueryStringQuery where
@@ -3025,10 +3032,10 @@ instance FromJSON MultiMatchQuery where
3025 <*> o .:? "lenient"
3032 <*> o .:? "lenient"
3026
3033
3027instance ToJSON MultiMatchQueryType where
3034instance ToJSON MultiMatchQueryType where
3028− toJSON MultiMatchBestFields = "best_fields"
3035+ toJSON MultiMatchBestFields = "best_fields"
3029− toJSON MultiMatchMostFields = "most_fields"
3036+ toJSON MultiMatchMostFields = "most_fields"
3030− toJSON MultiMatchCrossFields = "cross_fields"
3037+ toJSON MultiMatchCrossFields = "cross_fields"
3031− toJSON MultiMatchPhrase = "phrase"
3038+ toJSON MultiMatchPhrase = "phrase"
3032 toJSON MultiMatchPhrasePrefix = "phrase_prefix"
3039 toJSON MultiMatchPhrasePrefix = "phrase_prefix"
3033
3040
3034instance FromJSON MultiMatchQueryType where
3041instance FromJSON MultiMatchQueryType where
@@ -3042,7 +3049,7 @@ instance FromJSON MultiMatchQueryType where
3042
3049
3043instance ToJSON BooleanOperator where
3050instance ToJSON BooleanOperator where
3044 toJSON And = String "and"
3051 toJSON And = String "and"
3045− toJSON Or = String "or"
3052+ toJSON Or = String "or"
3046
3053
3047instance FromJSON BooleanOperator where
3054instance FromJSON BooleanOperator where
3048 parseJSON = withText "BooleanOperator" parse
3055 parseJSON = withText "BooleanOperator" parse
@@ -3061,7 +3068,7 @@ instance FromJSON ZeroTermsQuery where
3061 parse q = fail ("Unexpected ZeroTermsQuery: " <> show q)
3068 parse q = fail ("Unexpected ZeroTermsQuery: " <> show q)
3062
3069
3063instance ToJSON MatchQueryType where
3070instance ToJSON MatchQueryType where
3064− toJSON MatchPhrase = "phrase"
3071+ toJSON MatchPhrase = "phrase"
3065 toJSON MatchPhrasePrefix = "phrase_prefix"
3072 toJSON MatchPhrasePrefix = "phrase_prefix"
3066
3073
3067instance FromJSON MatchQueryType where
3074instance FromJSON MatchQueryType where
@@ -3195,7 +3202,7 @@ instance FromJSON IndexSettingsSummary where
3195 <*> (fmap (filter (not . redundant)) . parseSettings =<< o' .: "settings")
3202 <*> (fmap (filter (not . redundant)) . parseSettings =<< o' .: "settings")
3196 _ -> fail "Expected single-key object with index name"
3203 _ -> fail "Expected single-key object with index name"
3197 redundant (NumberOfReplicas _) = True
3204 redundant (NumberOfReplicas _) = True
3198− redundant _ = False
3205+ redundant _ = False
3199
3206
3200-- | For some reason in several settings APIs, all leaf values get returned
3207-- | For some reason in several settings APIs, all leaf values get returned
3201-- as strings. This function attepmts to recover from this for all
3208-- as strings. This function attepmts to recover from this for all
@@ -3205,7 +3212,7 @@ unStringlyTypeJSON (String "true") = Bool True
3205unStringlyTypeJSON (String "false") = Bool False
3212unStringlyTypeJSON (String "false") = Bool False
3206unStringlyTypeJSON (String "null") = Null
3213unStringlyTypeJSON (String "null") = Null
3207unStringlyTypeJSON v@(String t) = case readMay (T.unpack t) of
3214unStringlyTypeJSON v@(String t) = case readMay (T.unpack t) of
3208− Just n -> Number n
3215+ Just n -> Number n
3209 Nothing -> v
3216 Nothing -> v
3210unStringlyTypeJSON v = v
3217unStringlyTypeJSON v = v
3211
3218
@@ -3222,7 +3229,7 @@ parseSettings o = do
3222 return (catMaybes parses)
3229 return (catMaybes parses)
3223
3230
3224oPath :: ToJSON a => NonEmpty Text -> a -> Value
3231oPath :: ToJSON a => NonEmpty Text -> a -> Value
3225−oPath (k :| []) v = object [k .= v]
3232+oPath (k :| []) v = object [k .= v]
3226oPath (k:| (h:t)) v = object [k .= oPath (h :| t) v]
3233oPath (k:| (h:t)) v = object [k .= oPath (h :| t) v]
3227
3234
3228attrFilterJSON :: NonEmpty NodeAttrFilter -> Value
3235attrFilterJSON :: NonEmpty NodeAttrFilter -> Value
@@ -3232,12 +3239,12 @@ attrFilterJSON fs = object [ n .= T.intercalate "," (toList vs)
3232parseAttrFilter :: Value -> Parser (NonEmpty NodeAttrFilter)
3239parseAttrFilter :: Value -> Parser (NonEmpty NodeAttrFilter)
3233parseAttrFilter = withObject "NonEmpty NodeAttrFilter" parse
3240parseAttrFilter = withObject "NonEmpty NodeAttrFilter" parse
3234 where parse o = case HM.toList o of
3241 where parse o = case HM.toList o of
3235− [] -> fail "Expected non-empty list of NodeAttrFilters"
3242+ [] -> fail "Expected non-empty list of NodeAttrFilters"
3236 x:xs -> DT.mapM (uncurry parse') (x :| xs)
3243 x:xs -> DT.mapM (uncurry parse') (x :| xs)
3237 parse' n = withText "Text" $ \t ->
3244 parse' n = withText "Text" $ \t ->
3238 case T.splitOn "," t of
3245 case T.splitOn "," t of
3239 fv:fvs -> return (NodeAttrFilter (NodeAttrName n) (fv :| fvs))
3246 fv:fvs -> return (NodeAttrFilter (NodeAttrName n) (fv :| fvs))
3240− [] -> fail "Expected non-empty list of filter values"
3247+ [] -> fail "Expected non-empty list of filter values"
3241
3248
3242instance ToJSON ReplicaBounds where
3249instance ToJSON ReplicaBounds where
3243 toJSON (ReplicasBounded a b) = String (showText a <> "-" <> showText b)
3250 toJSON (ReplicasBounded a b) = String (showText a <> "-" <> showText b)
@@ -3291,12 +3298,12 @@ instance ToJSON FSType where
3291
3298
3292instance FromJSON FSType where
3299instance FromJSON FSType where
3293 parseJSON = withText "FSType" parse
3300 parseJSON = withText "FSType" parse
3294− where parse "simple" = pure FSSimple
3301+ where parse "simple" = pure FSSimple
3295 parse "buffered" = pure FSBuffered
3302 parse "buffered" = pure FSBuffered
3296− parse t = fail ("Invalid FSType: " <> show t)
3303+ parse t = fail ("Invalid FSType: " <> show t)
3297
3304
3298instance ToJSON CompoundFormat where
3305instance ToJSON CompoundFormat where
3299− toJSON (CompoundFileFormat x) = Bool x
3306+ toJSON (CompoundFileFormat x) = Bool x
3300 toJSON (MergeSegmentVsTotalIndex x) = toJSON x
3307 toJSON (MergeSegmentVsTotalIndex x) = toJSON x
3301
3308
3302instance FromJSON CompoundFormat where
3309instance FromJSON CompoundFormat where
@@ -3553,8 +3560,8 @@ instance ToJSON SortMode where
3553
3560
3554
3561
3555instance ToJSON Missing where
3562instance ToJSON Missing where
3556− toJSON LastMissing = String "_last"
3563+ toJSON LastMissing = String "_last"
3557− toJSON FirstMissing = String "_first"
3564+ toJSON FirstMissing = String "_first"
3558 toJSON (CustomMissing txt) = String txt
3565 toJSON (CustomMissing txt) = String txt
3559
3566
3560
3567
@@ -3570,7 +3577,7 @@ instance FromJSON ScoreType where
3570 parse "avg" = pure ScoreTypeAvg
3577 parse "avg" = pure ScoreTypeAvg
3571 parse "sum" = pure ScoreTypeSum
3578 parse "sum" = pure ScoreTypeSum
3572 parse "none" = pure ScoreTypeNone
3579 parse "none" = pure ScoreTypeNone
3573− parse t = fail ("Unexpected ScoreType: " <> show t)
3580+ parse t = fail ("Unexpected ScoreType: " <> show t)
3574
3581
3575instance ToJSON Distance where
3582instance ToJSON Distance where
3576 toJSON (Distance dCoefficient dUnit) =
3583 toJSON (Distance dCoefficient dUnit) =
@@ -3588,7 +3595,7 @@ instance FromJSON Distance where
3588 validForNumber '-' = True
3595 validForNumber '-' = True
3589 validForNumber '.' = True
3596 validForNumber '.' = True
3590 validForNumber 'e' = True
3597 validForNumber 'e' = True
3591− validForNumber c = isNumber c
3598+ validForNumber c = isNumber c
3592 parseCoeff "" = fail "Empty string cannot be parsed as number"
3599 parseCoeff "" = fail "Empty string cannot be parsed as number"
3593 parseCoeff s = return (read (T.unpack s))
3600 parseCoeff s = return (read (T.unpack s))
3594
3601
@@ -3615,7 +3622,7 @@ instance FromJSON DistanceUnit where
3615 parse "cm" = pure Centimeters
3622 parse "cm" = pure Centimeters
3616 parse "mm" = pure Millimeters
3623 parse "mm" = pure Millimeters
3617 parse "nmi" = pure NauticalMiles
3624 parse "nmi" = pure NauticalMiles
3618− parse u = fail ("Unrecognized DistanceUnit: " <> show u)
3625+ parse u = fail ("Unrecognized DistanceUnit: " <> show u)
3619
3626
3620instance ToJSON DistanceType where
3627instance ToJSON DistanceType where
3621 toJSON Arc = String "arc"
3628 toJSON Arc = String "arc"
@@ -3624,21 +3631,21 @@ instance ToJSON DistanceType where
3624
3631
3625instance FromJSON DistanceType where
3632instance FromJSON DistanceType where
3626 parseJSON = withText "DistanceType" parse
3633 parseJSON = withText "DistanceType" parse
3627− where parse "arc" = pure Arc
3634+ where parse "arc" = pure Arc
3628 parse "sloppy_arc" = pure SloppyArc
3635 parse "sloppy_arc" = pure SloppyArc
3629− parse "plane" = pure Plane
3636+ parse "plane" = pure Plane
3630− parse t = fail ("Unrecognized DistanceType: " <> show t)
3637+ parse t = fail ("Unrecognized DistanceType: " <> show t)
3631
3638
3632
3639
3633instance ToJSON OptimizeBbox where
3640instance ToJSON OptimizeBbox where
3634− toJSON NoOptimizeBbox = String "none"
3641+ toJSON NoOptimizeBbox = String "none"
3635 toJSON (OptimizeGeoFilterType gft) = toJSON gft
3642 toJSON (OptimizeGeoFilterType gft) = toJSON gft
3636
3643
3637instance FromJSON OptimizeBbox where
3644instance FromJSON OptimizeBbox where
3638 parseJSON v = withText "NoOptimizeBbox" parseNoOptimize v
3645 parseJSON v = withText "NoOptimizeBbox" parseNoOptimize v
3639 <|> parseOptimize v
3646 <|> parseOptimize v
3640 where parseNoOptimize "none" = pure NoOptimizeBbox
3647 where parseNoOptimize "none" = pure NoOptimizeBbox
3641− parseNoOptimize _ = mzero
3648+ parseNoOptimize _ = mzero
3642 parseOptimize = fmap OptimizeGeoFilterType . parseJSON
3649 parseOptimize = fmap OptimizeGeoFilterType . parseJSON
3643
3650
3644instance ToJSON GeoBoundingBoxConstraint where
3651instance ToJSON GeoBoundingBoxConstraint where
@@ -4431,7 +4438,7 @@ instance SnapshotRepo FsSnapshotRepo where
4431
4438
4432parseRepo :: Parser a -> Either SnapshotRepoConversionError a
4439parseRepo :: Parser a -> Either SnapshotRepoConversionError a
4433parseRepo parser = case parseEither (const parser) () of
4440parseRepo parser = case parseEither (const parser) () of
4434− Left e -> Left (OtherRepoConversionError (T.pack e))
4441+ Left e -> Left (OtherRepoConversionError (T.pack e))
4435 Right a -> Right a
4442 Right a -> Right a
4436
4443
4437
4444
@@ -4957,7 +4964,7 @@ instance FromJSON NodeIndicesStats where
4957 where
4964 where
4958 parse o = do
4965 parse o = do
4959 let (.::) mv k = case mv of
4966 let (.::) mv k = case mv of
4960− Just v -> Just <$> v .: k
4967+ Just v -> Just <$> v .: k
4961 Nothing -> pure Nothing
4968 Nothing -> pure Nothing
4962 mRecovery <- o .:? "recovery"
4969 mRecovery <- o .:? "recovery"
4963 mQueryCache <- o .:? "query_cache"
4970 mQueryCache <- o .:? "query_cache"
@@ -5208,8 +5215,8 @@ parseStringInterval s = case span isNumber s of
5208 ("", _) -> fail "Invalid interval"
5215 ("", _) -> fail "Invalid interval"
5209 (nS, unitS) -> case (readMay nS, readMay unitS) of
5216 (nS, unitS) -> case (readMay nS, readMay unitS) of
5210 (Just n, Just unit) -> return (fromInteger (n * unitNDT unit))
5217 (Just n, Just unit) -> return (fromInteger (n * unitNDT unit))
5211− (Nothing, _) -> fail "Invalid interval number"
5218+ (Nothing, _) -> fail "Invalid interval number"
5212− (_, Nothing) -> fail "Invalid interval unit"
5219+ (_, Nothing) -> fail "Invalid interval unit"
5213 where
5220 where
5214 unitNDT Seconds = 1
5221 unitNDT Seconds = 1
5215 unitNDT Minutes = 60
5222 unitNDT Minutes = 60
@@ -5228,8 +5235,8 @@ instance FromJSON ThreadPoolSize where
5228 parseAsString = withText "ThreadPoolSize" $ \t ->
5235 parseAsString = withText "ThreadPoolSize" $ \t ->
5229 case first (readMay . T.unpack) (T.span isNumber t) of
5236 case first (readMay . T.unpack) (T.span isNumber t) of
5230 (Just n, "k") -> return (ThreadPoolBounded (n * 1000))
5237 (Just n, "k") -> return (ThreadPoolBounded (n * 1000))
5231− (Just n, "") -> return (ThreadPoolBounded n)
5238+ (Just n, "") -> return (ThreadPoolBounded n)
5232− _ -> fail ("Invalid thread pool size " <> T.unpack t)
5239+ _ -> fail ("Invalid thread pool size " <> T.unpack t)
5233
5240
5234instance FromJSON ThreadPoolType where
5241instance FromJSON ThreadPoolType where
5235 parseJSON = withText "ThreadPoolType" parse
5242 parseJSON = withText "ThreadPoolType" parse
@@ -5244,10 +5251,10 @@ instance FromJSON NodeTransportInfo where
5244 where
5251 where
5245 parse o = NodeTransportInfo <$> (maybe (return mempty) parseProfiles =<< o .:? "profiles")
5252 parse o = NodeTransportInfo <$> (maybe (return mempty) parseProfiles =<< o .:? "profiles")
5246 <*> parseJSON (Object o)
5253 <*> parseJSON (Object o)
5247− parseProfiles (Object o) | HM.null o = return []
5254+ parseProfiles (Object o) | HM.null o = return []
5248 parseProfiles v@(Array _) = parseJSON v
5255 parseProfiles v@(Array _) = parseJSON v
5249− parseProfiles Null = return []
5256+ parseProfiles Null = return []
5250− parseProfiles _ = fail "Could not parse profiles"
5257+ parseProfiles _ = fail "Could not parse profiles"
5251
5258
5252instance FromJSON NodeNetworkInfo where
5259instance FromJSON NodeNetworkInfo where
5253 parseJSON = withObject "NodeNetworkInfo" parse
5260 parseJSON = withObject "NodeNetworkInfo" parse
@@ -5268,4 +5275,4 @@ newtype MaybeNA a = MaybeNA { unMaybeNA :: Maybe a }
5268
5275
5269instance FromJSON a => FromJSON (MaybeNA a) where
5276instance FromJSON a => FromJSON (MaybeNA a) where
5270 parseJSON (String "NA") = pure $ MaybeNA Nothing
5277 parseJSON (String "NA") = pure $ MaybeNA Nothing
5271− parseJSON o = MaybeNA . Just <$> parseJSON o
5278+ parseJSON o = MaybeNA . Just <$> parseJSON o