From 945113721891a76830415e53e832770aeb0c2f1b Mon Sep 17 00:00:00 2001 From: Gautier DI FOLCO Date: Mon, 25 Dec 2023 18:48:08 +0100 Subject: [PATCH] refactoring(aeson): drop deriving-aeson --- bloodhound.cabal | 1 - .../Internal/Versions/Common/Types/Reindex.hs | 81 +++++++++---------- .../Internal/Versions/Common/Types/Task.hs | 21 ++--- 3 files changed, 45 insertions(+), 58 deletions(-) diff --git a/bloodhound.cabal b/bloodhound.cabal index 9ecc0f5..54dcf57 100644 --- a/bloodhound.cabal +++ b/bloodhound.cabal @@ -71,7 +71,6 @@ library , base >=4.14 && <5 , blaze-builder , bytestring >=0.10.0 - , deriving-aeson >= 0.2.7 , containers >=0.5.0.0 , exceptions , hashable diff --git a/src/Database/Bloodhound/Internal/Versions/Common/Types/Reindex.hs b/src/Database/Bloodhound/Internal/Versions/Common/Types/Reindex.hs index ac09e8f..4cfe0d1 100644 --- a/src/Database/Bloodhound/Internal/Versions/Common/Types/Reindex.hs +++ b/src/Database/Bloodhound/Internal/Versions/Common/Types/Reindex.hs @@ -9,10 +9,11 @@ module Database.Bloodhound.Internal.Versions.Common.Types.Reindex where import Data.Aeson import Data.List.NonEmpty import Data.Text (Text) +import Database.Bloodhound.Internal.Utils.Imports (optionsDerivingStrippingPrefix) import Database.Bloodhound.Internal.Versions.Common.Types.Newtypes (IndexName) import Database.Bloodhound.Internal.Versions.Common.Types.Query (Query) import Database.Bloodhound.Internal.Versions.Common.Types.Script (ScriptLanguage) -import Deriving.Aeson +import GHC.Generics data ReindexRequest = ReindexRequest { reindexConflicts :: Maybe ReindexConflicts, @@ -21,13 +22,12 @@ data ReindexRequest = ReindexRequest reindexScript :: Maybe ReindexScript } deriving (Show, Eq, Generic) - deriving - (FromJSON, ToJSON) - via CustomJSON - '[ OmitNothingFields, - FieldLabelModifier (StripPrefix "reindex", CamelToSnake) - ] - ReindexRequest + +instance ToJSON ReindexRequest where + toEncoding = genericToEncoding $ optionsDerivingStrippingPrefix "reindex" + +instance FromJSON ReindexRequest where + parseJSON = genericParseJSON $ optionsDerivingStrippingPrefix "reindex" data ReindexConflicts = ReindexAbortOnConflicts @@ -55,26 +55,24 @@ data ReindexSource = ReindexSource reindexSourceSlice :: Maybe ReindexSlice } deriving (Show, Eq, Generic) - deriving - (FromJSON, ToJSON) - via CustomJSON - '[ OmitNothingFields, - FieldLabelModifier (StripPrefix "reindexSource", CamelToSnake) - ] - ReindexSource + +instance ToJSON ReindexSource where + toEncoding = genericToEncoding $ optionsDerivingStrippingPrefix "reindexSource" + +instance FromJSON ReindexSource where + parseJSON = genericParseJSON $ optionsDerivingStrippingPrefix "reindexSource" data ReindexSlice = ReindexSlice { reindexSliceId :: Maybe Int, reindexSliceMax :: Maybe Int } deriving (Show, Eq, Generic) - deriving - (FromJSON, ToJSON) - via CustomJSON - '[ OmitNothingFields, - FieldLabelModifier (StripPrefix "reindexSlice", CamelToSnake) - ] - ReindexSlice + +instance ToJSON ReindexSlice where + toEncoding = genericToEncoding $ optionsDerivingStrippingPrefix "reindexSlice" + +instance FromJSON ReindexSlice where + parseJSON = genericParseJSON $ optionsDerivingStrippingPrefix "reindexSlice" data ReindexDest = ReindexDest { reindexDestIndex :: IndexName, @@ -82,13 +80,12 @@ data ReindexDest = ReindexDest reindexDestOpType :: Maybe ReindexOpType } deriving (Show, Eq, Generic) - deriving - (FromJSON, ToJSON) - via CustomJSON - '[ OmitNothingFields, - FieldLabelModifier (StripPrefix "reindexDest", CamelToSnake) - ] - ReindexDest + +instance ToJSON ReindexDest where + toEncoding = genericToEncoding $ optionsDerivingStrippingPrefix "reindexDest" + +instance FromJSON ReindexDest where + parseJSON = genericParseJSON $ optionsDerivingStrippingPrefix "reindexDest" data VersionType = VersionTypeInternal @@ -133,13 +130,12 @@ data ReindexScript = ReindexScript reindexScriptSource :: Text } deriving (Show, Eq, Generic) - deriving - (FromJSON, ToJSON) - via CustomJSON - '[ OmitNothingFields, - FieldLabelModifier (StripPrefix "reindexScript", CamelToSnake) - ] - ReindexScript + +instance ToJSON ReindexScript where + toEncoding = genericToEncoding $ optionsDerivingStrippingPrefix "reindexScript" + +instance FromJSON ReindexScript where + parseJSON = genericParseJSON $ optionsDerivingStrippingPrefix "reindexScript" mkReindexRequest :: IndexName -> IndexName -> ReindexRequest mkReindexRequest src dst = @@ -171,10 +167,9 @@ data ReindexResponse = ReindexResponse reindexResponseThrottledMillis :: Int } deriving (Show, Eq, Generic) - deriving - (FromJSON, ToJSON) - via CustomJSON - '[ OmitNothingFields, - FieldLabelModifier (StripPrefix "reindexResponse", CamelToSnake) - ] - ReindexResponse + +instance ToJSON ReindexResponse where + toEncoding = genericToEncoding $ optionsDerivingStrippingPrefix "reindexResponse" + +instance FromJSON ReindexResponse where + parseJSON = genericParseJSON $ optionsDerivingStrippingPrefix "reindexResponse" diff --git a/src/Database/Bloodhound/Internal/Versions/Common/Types/Task.hs b/src/Database/Bloodhound/Internal/Versions/Common/Types/Task.hs index bf48463..df40aa5 100644 --- a/src/Database/Bloodhound/Internal/Versions/Common/Types/Task.hs +++ b/src/Database/Bloodhound/Internal/Versions/Common/Types/Task.hs @@ -7,6 +7,7 @@ module Database.Bloodhound.Internal.Versions.Common.Types.Task where import Data.Aeson import Data.Text (Text) +import Database.Bloodhound.Internal.Utils.Imports (optionsDerivingStrippingPrefix) import Deriving.Aeson data TaskResponse a = TaskResponse @@ -16,13 +17,9 @@ data TaskResponse a = TaskResponse taskResponseError :: Maybe Object } deriving (Show, Eq, Generic) - deriving - (FromJSON) - via CustomJSON - '[ OmitNothingFields, - FieldLabelModifier (StripPrefix "taskResponse", CamelToSnake) - ] - (TaskResponse a) + +instance (FromJSON a) => FromJSON (TaskResponse a) where + parseJSON = genericParseJSON $ optionsDerivingStrippingPrefix "taskResponse" data Task a = Task { taskNode :: Text, @@ -36,13 +33,9 @@ data Task a = Task taskCancellable :: Bool } deriving (Show, Eq, Generic) - deriving - (FromJSON) - via CustomJSON - '[ OmitNothingFields, - FieldLabelModifier (StripPrefix "task", CamelToSnake) - ] - (Task a) + +instance (FromJSON a) => FromJSON (Task a) where + parseJSON = genericParseJSON $ optionsDerivingStrippingPrefix "task" newtype TaskNodeId = TaskNodeId Text deriving (Show, Eq)