autodocodec-nix 0.0.0.1 → 0.0.1.0
raw patch · 3 files changed
+26/−5 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Autodocodec.Nix: OptionTypeEnum :: ![Expr] -> OptionType
+ Autodocodec.Nix: instance GHC.Classes.Eq Autodocodec.Nix.Expr
+ Autodocodec.Nix: instance GHC.Classes.Ord Autodocodec.Nix.Expr
+ Autodocodec.Nix: instance GHC.Show.Show Autodocodec.Nix.Expr
Files
- CHANGELOG.md +5/−1
- autodocodec-nix.cabal +1/−1
- src/Autodocodec/Nix.hs +20/−3
CHANGELOG.md view
@@ -1,6 +1,10 @@ # Changelog -## [0.0.0.1] - 2024-07-26+## [0.0.1.0] - 2024-07-31++### Changed++* More precise types for `EqCodec` codecs like enums. ## [0.0.0.0] - 2024-07-19
autodocodec-nix.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: autodocodec-nix-version: 0.0.0.1+version: 0.0.1.0 synopsis: Autodocodec interpreters for nix homepage: https://github.com/NorfairKing/autodocodec#readme bug-reports: https://github.com/NorfairKing/autodocodec/issues
src/Autodocodec/Nix.hs view
@@ -30,6 +30,7 @@ where import Autodocodec+import Control.Applicative import Data.Aeson as JSON import qualified Data.Aeson.Key as Key import qualified Data.Aeson.KeyMap as KeyMap@@ -91,7 +92,7 @@ ValueCodec -> Just (OptionTypeSimple "lib.types.unspecified") ArrayOfCodec _ c -> Just $ OptionTypeListOf $ mTyp $ go c ObjectOfCodec _ oc -> Just (OptionTypeSubmodule (objectCodecNixOptions oc))- EqCodec _ _ -> Nothing -- TODO+ EqCodec v c -> Just $ OptionTypeEnum [jsonValueExpr $ toJSONVia c v] BimapCodec _ _ c -> go c EitherCodec _ c1 c2 -> Just $ OptionTypeOneOf (map mTyp [go c1, go c2]) CommentCodec _ c -> go c@@ -122,7 +123,7 @@ ( \t1 t2 -> Option { optionType = Just $ OptionTypeOneOf $ map (fromMaybe (OptionTypeSimple "lib.types.anything") . optionType) [t1, t2],- optionDescription = Nothing, -- TODO+ optionDescription = optionDescription t1 <|> optionDescription t2, -- TODO optionDefault = Nothing } )@@ -184,6 +185,7 @@ data OptionType = OptionTypeNull | OptionTypeSimple !Text+ | OptionTypeEnum ![Expr] | OptionTypeNullOr !OptionType | OptionTypeListOf !OptionType | OptionTypeAttrsOf !OptionType@@ -197,6 +199,7 @@ go = \case OptionTypeNull -> OptionTypeNull OptionTypeSimple t -> OptionTypeSimple t+ OptionTypeEnum es -> OptionTypeEnum es OptionTypeNullOr t -> case t of OptionTypeNull -> OptionTypeNull OptionTypeNullOr t' -> go $ OptionTypeNullOr t'@@ -204,11 +207,23 @@ _ -> OptionTypeNullOr $ go t OptionTypeListOf o -> OptionTypeListOf $ go o OptionTypeAttrsOf o -> OptionTypeAttrsOf $ go o- OptionTypeOneOf os -> case nubOrd $ concatMap goOr os of+ OptionTypeOneOf os -> case goEnums $ nubOrd $ concatMap goOr os of [ot] -> ot os' -> OptionTypeOneOf os' OptionTypeSubmodule m -> OptionTypeSubmodule $ M.map goOpt m + goEnums :: [OptionType] -> [OptionType]+ goEnums = goEnum []+ where+ goEnum :: [Expr] -> [OptionType] -> [OptionType]+ goEnum es = \case+ [] -> case es of+ [] -> []+ _ -> [OptionTypeEnum es]+ (t : rest) -> case t of+ OptionTypeEnum es' -> goEnum (es ++ es') rest+ _ -> t : goEnum es rest+ goOpt o = o {optionType = go <$> optionType o} goOr = \case@@ -257,6 +272,7 @@ go = \case OptionTypeNull -> ExprVar "lib.types.null" OptionTypeSimple s -> ExprVar s+ OptionTypeEnum es -> ExprAp (ExprVar "lib.types.enum") (ExprLitList es) OptionTypeNullOr ot -> ExprAp (ExprVar "lib.types.nullOr") (go ot) OptionTypeListOf ot -> ExprAp@@ -295,6 +311,7 @@ | ExprAp !Expr !Expr | ExprFun ![Text] !Expr | ExprWith !Text !Expr+ deriving (Show, Eq, Ord) renderExpr :: Expr -> Text renderExpr = T.unlines . go 0