Skip to content

Commit

Permalink
Update naming convention (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
chiroptical authored Mar 21, 2024
1 parent ede70a2 commit 056a715
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/Moat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module Moat
lowerFirstField,
omitFields,
omitCases,
strictFields,
fieldsRequiredByClients,
strictCases,
makeBase,
sumOfProductEncodingOptions,
Expand Down Expand Up @@ -507,7 +507,7 @@ data MoatError
| ImproperNewtypeConstructorInfo
{ _conInfo :: ConstructorInfo
}
| MissingStrictFields
| MissingRequiredFields
{ _missingFields :: [String]
}
| MissingStrictCases
Expand Down Expand Up @@ -577,8 +577,8 @@ prettyMoatError = \case
ImproperNewtypeConstructorInfo conInfo ->
"Expected `ConstructorInfo` with single field, but got "
++ show conInfo
MissingStrictFields missingFields ->
"Removing these fields will break clients: " ++ L.unwords missingFields
MissingRequiredFields missingFields ->
"These fields are required by clients: " ++ L.unwords missingFields
MissingStrictCases missingCases ->
"Removing these cases will break clients: " ++ L.unwords missingCases

Expand Down Expand Up @@ -1029,15 +1029,15 @@ mkProd o@Options {..} typName parentDoc instTys ts = \case
zipFields :: Options -> [Name] -> [Type] -> [Maybe String] -> MoatM [Exp]
zipFields o ns ts ds = do
let fields = nameStr <$> ns
missingFields = strictFields o L.\\ fields
missingFields = fieldsRequiredByClients o L.\\ fields
if null missingFields
then pure $ catMaybes $ zipWith3 mkField ns ts ds
else throwError $ MissingStrictFields missingFields
else throwError $ MissingRequiredFields missingFields
where
mkField :: Name -> Type -> Maybe String -> Maybe Exp
mkField n t d =
let fieldStr = nameStr n
in case (fieldStr `elem` strictFields o, omitFields o fieldStr) of
in case (fieldStr `elem` fieldsRequiredByClients o, omitFields o fieldStr) of
(True, _) -> Just $ prettyField o n t d
(False, Keep) -> Just $ prettyField o n t d
(False, Discard) -> Nothing
Expand Down
6 changes: 3 additions & 3 deletions src/Moat/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ data Options = Options
-- ^ A function to apply to enum cases and choose whether, or not, to keep them
--
-- The default (@const Keep@) will omit nothing.
, strictFields :: [String]
-- ^ These fields are relied upon and must exist in the record.
, fieldsRequiredByClients :: [String]
-- ^ These fields are relied upon by clients.
--
-- The default @[]@ will not require any fields to exist.
--
Expand Down Expand Up @@ -573,7 +573,7 @@ defaultOptions =
, lowerFirstCase = True
, omitFields = const Keep
, omitCases = const Keep
, strictFields = []
, fieldsRequiredByClients = []
, strictCases = []
, makeBase = (False, Nothing, [])
, optionalExpand = False
Expand Down
4 changes: 2 additions & 2 deletions test/StrictFieldsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data RecordA = RecordA
-- | Note: you can't discard a strict field
mobileGenWith
( defaultOptions
{ strictFields = ["fieldA"]
{ fieldsRequiredByClients = ["fieldA"]
, omitFields = const Discard
}
)
Expand All @@ -32,7 +32,7 @@ mobileGenWith
{ fieldLabelModifier = \case
xs | Just rest <- stripPrefix "field" xs -> rest
xs -> xs
, strictFields = ["fieldC"]
, fieldsRequiredByClients = ["fieldC"]
, omitFields = const Discard
}
)
Expand Down

0 comments on commit 056a715

Please sign in to comment.