Skip to content

Commit

Permalink
refactoring(aeson): drop deriving-aeson
Browse files Browse the repository at this point in the history
  • Loading branch information
blackheaven committed Dec 25, 2023
1 parent 444cb47 commit 9451137
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 58 deletions.
1 change: 0 additions & 1 deletion bloodhound.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 38 additions & 43 deletions src/Database/Bloodhound/Internal/Versions/Common/Types/Reindex.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -55,40 +55,37 @@ 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,
reindexDestVersionType :: Maybe VersionType,
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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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"
21 changes: 7 additions & 14 deletions src/Database/Bloodhound/Internal/Versions/Common/Types/Task.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 9451137

Please sign in to comment.