    {-# LANGUAGE DefaultSignatures #-}
    {-# LANGUAGE FlexibleContexts #-}
    {-# LANGUAGE FlexibleInstances #-}
    {-# LANGUAGE ScopedTypeVariables #-}
    {-# LANGUAGE TypeFamilies #-}
    {-# LANGUAGE TypeOperators #-}
    {-# LANGUAGE StandaloneDeriving #-}
    {-# LANGUAGE RecordWildCards #-}
    {-# LANGUAGE ConstraintKinds #-}
    {-# LANGUAGE DataKinds #-}
    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    {-# LANGUAGE TypeApplications #-}
    {-# LANGUAGE DeriveFunctor #-}
    module Data.Aeson.Config.FromValue (
      FromValue(..)
    , Parser
    , Result
    , decodeValue

    , Generic
    , GenericDecode
    , genericFromValue
    , Options(..)
    , genericFromValueWith

    , typeMismatch
    , withObject
    , withText
    , withString
    , withArray
    , withNumber
    , withBool

    , parseArray
    , traverseObject

    , (.:)
    , (.:?)

    , Key
    , Value(..)
    , Object
    , Array

    , Alias(..)
    , unAlias
    ) where

    import           Imports

    import           Data.Monoid (Last(..))
    import           GHC.Generics
    import           GHC.TypeLits
    import           Data.Proxy

    import           Data.Map.Lazy (Map)
    import qualified Data.Map.Lazy as Map
    import qualified Data.Vector as V
    import           Data.Aeson.Config.Key (Key)
    import qualified Data.Aeson.Config.Key as Key
    import           Data.Aeson.Config.KeyMap (member)
    import qualified Data.Aeson.Config.KeyMap as KeyMap

    import           Data.Aeson.Types (FromJSON(..))

    import           Data.Aeson.Config.Util
    import           Data.Aeson.Config.Parser

    type Result a = Either String (a, [String], [(String, String)])

    decodeValue :: FromValue a => Value -> Result a
    decodeValue :: forall a. FromValue a => Value -> Result a
    decodeValue = (Value -> Parser a)
    -> Value -> Either String (a, [String], [(String, String)])
    forall a.
    (Value -> Parser a)
    -> Value -> Either String (a, [String], [(String, String)])
    runParser Value -> Parser a
    forall a. FromValue a => Value -> Parser a
    fromValue

    (.:) :: FromValue a => Object -> Key -> Parser a
    .: :: forall a. FromValue a => Object -> Key -> Parser a
    (.:) = (Value -> Parser a) -> Object -> Key -> Parser a
    forall a. (Value -> Parser a) -> Object -> Key -> Parser a
    explicitParseField Value -> Parser a
    forall a. FromValue a => Value -> Parser a
    fromValue

    (.:?) :: FromValue a => Object -> Key -> Parser (Maybe a)
    .:? :: forall a. FromValue a => Object -> Key -> Parser (Maybe a)
    (.:?) = (Value -> Parser a) -> Object -> Key -> Parser (Maybe a)
    forall a. (Value -> Parser a) -> Object -> Key -> Parser (Maybe a)
    explicitParseFieldMaybe Value -> Parser a
    forall a. FromValue a => Value -> Parser a
    fromValue

    class FromValue a where
      fromValue :: Value -> Parser a
      default fromValue :: forall d m. (Generic a, Rep a ~ D1 d m, Datatype d, GenericDecode (Rep a)) => Value -> Parser a
      fromValue = Value -> Parser a
    forall a (d :: Meta) (m :: * -> *).
    (Generic a, Rep a ~ D1 d m, Datatype d, GenericDecode (Rep a)) =>
    Value -> Parser a
    genericFromValue

    genericFromValue :: forall a d m. (Generic a, Rep a ~ D1 d m, Datatype d, GenericDecode (Rep a)) => Value -> Parser a
    genericFromValue :: forall a (d :: Meta) (m :: * -> *).
    (Generic a, Rep a ~ D1 d m, Datatype d, GenericDecode (Rep a)) =>
    Value -> Parser a
    genericFromValue = Options -> Value -> Parser a
    forall a.
    (Generic a, GenericDecode (Rep a)) =>
    Options -> Value -> Parser a
    genericFromValueWith ((String -> String) -> Options
    Options ((String -> String) -> Options) -> (String -> String) -> Options
    forall a b. (a -> b) -> a -> b
    $ String -> String -> String
    hyphenize String
    name)
      where
        name :: String
        name :: String
    name = M1 D d m (ZonkAny 1) -> String
    forall {k} (d :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
           (f :: k1 -> *) (a :: k1).
    Datatype d =>
    t d f a -> String
    forall k1 (t :: Meta -> (k1 -> *) -> k1 -> *) (f :: k1 -> *)
           (a :: k1).
    t d f a -> String
    datatypeName (D1 d m p
    forall {p}. D1 d m p
    forall a. HasCallStack => a
    undefined :: D1 d m p)

    instance FromValue Bool where
      fromValue :: Value -> Parser Bool
    fromValue = Parser Bool -> Parser Bool
    forall a. Parser a -> Parser a
    liftParser (Parser Bool -> Parser Bool)
    -> (Value -> Parser Bool) -> Value -> Parser Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Value -> Parser Bool
    forall a. FromJSON a => Value -> Parser a
    parseJSON

    instance FromValue Int where
      fromValue :: Value -> Parser Int
    fromValue = Parser Int -> Parser Int
    forall a. Parser a -> Parser a
    liftParser (Parser Int -> Parser Int)
    -> (Value -> Parser Int) -> Value -> Parser Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Value -> Parser Int
    forall a. FromJSON a => Value -> Parser a
    parseJSON

    instance FromValue Text where
      fromValue :: Value -> Parser Text
    fromValue = Parser Text -> Parser Text
    forall a. Parser a -> Parser a
    liftParser (Parser Text -> Parser Text)
    -> (Value -> Parser Text) -> Value -> Parser Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Value -> Parser Text
    forall a. FromJSON a => Value -> Parser a
    parseJSON

    instance {-# OVERLAPPING #-} FromValue String where
      fromValue :: Value -> Parser String
    fromValue = Parser String -> Parser String
    forall a. Parser a -> Parser a
    liftParser (Parser String -> Parser String)
    -> (Value -> Parser String) -> Value -> Parser String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Value -> Parser String
    forall a. FromJSON a => Value -> Parser a
    parseJSON

    instance FromValue a => FromValue (Maybe a) where
      fromValue :: Value -> Parser (Maybe a)
    fromValue Value
    value = Parser (Maybe Value) -> Parser (Maybe Value)
    forall a. Parser a -> Parser a
    liftParser (Value -> Parser (Maybe Value)
    forall a. FromJSON a => Value -> Parser a
    parseJSON Value
    value) Parser (Maybe Value)
    -> (Maybe Value -> Parser (Maybe a)) -> Parser (Maybe a)
    forall a b. Parser a -> (a -> Parser b) -> Parser b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= (Value -> Parser a) -> Maybe Value -> Parser (Maybe a)
    forall (t :: * -> *) (f :: * -> *) a b.
    (Traversable t, Applicative f) =>
    (a -> f b) -> t a -> f (t b)
    forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Maybe a -> f (Maybe b)
    traverse Value -> Parser a
    forall a. FromValue a => Value -> Parser a
    fromValue

    instance FromValue a => FromValue [a] where
      fromValue :: Value -> Parser [a]
    fromValue = (Array -> Parser [a]) -> Value -> Parser [a]
    forall a. (Array -> Parser a) -> Value -> Parser a
    withArray ((Value -> Parser a) -> Array -> Parser [a]
    forall a. (Value -> Parser a) -> Array -> Parser [a]
    parseArray Value -> Parser a
    forall a. FromValue a => Value -> Parser a
    fromValue)

    parseArray :: (Value -> Parser a) -> Array -> Parser [a]
    parseArray :: forall a. (Value -> Parser a) -> Array -> Parser [a]
    parseArray Value -> Parser a
    f = (Int -> Value -> Parser a) -> [Int] -> [Value] -> Parser [a]
    forall (m :: * -> *) a b c.
    Applicative m =>
    (a -> b -> m c) -> [a] -> [b] -> m [c]
    zipWithM ((Value -> Parser a) -> Int -> Value -> Parser a
    forall a. (Value -> Parser a) -> Int -> Value -> Parser a
    parseIndexed Value -> Parser a
    f) [Int
    0..] ([Value] -> Parser [a])
    -> (Array -> [Value]) -> Array -> Parser [a]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Array -> [Value]
    forall a. Vector a -> [a]
    V.toList
      where
        parseIndexed :: (Value -> Parser a) -> Int -> Value -> Parser a
        parseIndexed :: forall a. (Value -> Parser a) -> Int -> Value -> Parser a
    parseIndexed Value -> Parser a
    p Int
    n Value
    value = Value -> Parser a
    p Value
    value Parser a -> JSONPathElement -> Parser a
    forall a. Parser a -> JSONPathElement -> Parser a
    <?> Int -> JSONPathElement
    Index Int
    n

    instance FromValue a => FromValue (Map String a) where
      fromValue :: Value -> Parser (Map String a)
    fromValue = (Object -> Parser (Map String a)) -> Value -> Parser (Map String a)
    forall a. (Object -> Parser a) -> Value -> Parser a
    withObject ((Object -> Parser (Map String a))
     -> Value -> Parser (Map String a))
    -> (Object -> Parser (Map String a))
    -> Value
    -> Parser (Map String a)
    forall a b. (a -> b) -> a -> b
    $ \ Object
    o -> do
        xs <- (Value -> Parser a) -> Object -> Parser [(Key, a)]
    forall a. (Value -> Parser a) -> Object -> Parser [(Key, a)]
    traverseObject Value -> Parser a
    forall a. FromValue a => Value -> Parser a
    fromValue Object
    o
        return $ Map.fromList (map (first Key.toString) xs)

    traverseObject :: (Value -> Parser a) -> Object -> Parser [(Key, a)]
    traverseObject :: forall a. (Value -> Parser a) -> Object -> Parser [(Key, a)]
    traverseObject Value -> Parser a
    f Object
    o = do
      [(Key, Value)]
    -> ((Key, Value) -> Parser (Key, a)) -> Parser [(Key, a)]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    t a -> (a -> m b) -> m (t b)
    forM (Object -> [(Key, Value)]
    forall v. KeyMap v -> [(Key, v)]
    KeyMap.toList Object
    o) (((Key, Value) -> Parser (Key, a)) -> Parser [(Key, a)])
    -> ((Key, Value) -> Parser (Key, a)) -> Parser [(Key, a)]
    forall a b. (a -> b) -> a -> b
    $ \ (Key
    name, Value
    value) ->
        (,) Key
    name (a -> (Key, a)) -> Parser a -> Parser (Key, a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Value -> Parser a
    f Value
    value Parser a -> JSONPathElement -> Parser a
    forall a. Parser a -> JSONPathElement -> Parser a
    <?> Key -> JSONPathElement
    Key Key
    name

    instance (FromValue a, FromValue b) => FromValue (a, b) where
      fromValue :: Value -> Parser (a, b)
    fromValue Value
    v = (,) (a -> b -> (a, b)) -> Parser a -> Parser (b -> (a, b))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Value -> Parser a
    forall a. FromValue a => Value -> Parser a
    fromValue Value
    v Parser (b -> (a, b)) -> Parser b -> Parser (a, b)
    forall a b. Parser (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Value -> Parser b
    forall a. FromValue a => Value -> Parser a
    fromValue Value
    v

    instance (FromValue a, FromValue b) => FromValue (Either a b) where
      fromValue :: Value -> Parser (Either a b)
    fromValue Value
    v = a -> Either a b
    forall a b. a -> Either a b
    Left (a -> Either a b) -> Parser a -> Parser (Either a b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Value -> Parser a
    forall a. FromValue a => Value -> Parser a
    fromValue Value
    v Parser (Either a b) -> Parser (Either a b) -> Parser (Either a b)
    forall a. Parser a -> Parser a -> Parser a
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    <|> b -> Either a b
    forall a b. b -> Either a b
    Right (b -> Either a b) -> Parser b -> Parser (Either a b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Value -> Parser b
    forall a. FromValue a => Value -> Parser a
    fromValue Value
    v

    data Options = Options {
      Options -> String -> String
    optionsRecordSelectorModifier :: String -> String
    }

    genericFromValueWith :: (Generic a, GenericDecode (Rep a)) => Options -> Value -> Parser a
    genericFromValueWith :: forall a.
    (Generic a, GenericDecode (Rep a)) =>
    Options -> Value -> Parser a
    genericFromValueWith Options
    opts = (Rep a (ZonkAny 0) -> a) -> Parser (Rep a (ZonkAny 0)) -> Parser a
    forall a b. (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Rep a (ZonkAny 0) -> a
    forall a x. Generic a => Rep a x -> a
    forall x. Rep a x -> a
    to (Parser (Rep a (ZonkAny 0)) -> Parser a)
    -> (Value -> Parser (Rep a (ZonkAny 0))) -> Value -> Parser a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Options -> Value -> Parser (Rep a (ZonkAny 0))
    forall p. Options -> Value -> Parser (Rep a p)
    forall (f :: * -> *) p.
    GenericDecode f =>
    Options -> Value -> Parser (f p)
    genericDecode  Options
    opts

    class GenericDecode f where
      genericDecode :: Options -> Value -> Parser (f p)

    instance (GenericDecode a) => GenericDecode (D1 d a) where
      genericDecode :: forall p. Options -> Value -> Parser (D1 d a p)
    genericDecode Options
    opts = (a p -> D1 d a p) -> Parser (a p) -> Parser (D1 d a p)
    forall a b. (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap a p -> D1 d a p
    forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
    M1 (Parser (a p) -> Parser (D1 d a p))
    -> (Value -> Parser (a p)) -> Value -> Parser (D1 d a p)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Options -> Value -> Parser (a p)
    forall p. Options -> Value -> Parser (a p)
    forall (f :: * -> *) p.
    GenericDecode f =>
    Options -> Value -> Parser (f p)
    genericDecode Options
    opts

    instance (GenericDecode a) => GenericDecode (C1 c a) where
      genericDecode :: forall p. Options -> Value -> Parser (C1 c a p)
    genericDecode Options
    opts = (a p -> C1 c a p) -> Parser (a p) -> Parser (C1 c a p)
    forall a b. (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap a p -> C1 c a p
    forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
    M1 (Parser (a p) -> Parser (C1 c a p))
    -> (Value -> Parser (a p)) -> Value -> Parser (C1 c a p)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Options -> Value -> Parser (a p)
    forall p. Options -> Value -> Parser (a p)
    forall (f :: * -> *) p.
    GenericDecode f =>
    Options -> Value -> Parser (f p)
    genericDecode Options
    opts

    instance (GenericDecode a, GenericDecode b) => GenericDecode (a :*: b) where
      genericDecode :: forall p. Options -> Value -> Parser ((:*:) a b p)
    genericDecode Options
    opts Value
    o = a p -> b p -> (:*:) a b p
    forall k (f :: k -> *) (g :: k -> *) (p :: k).
    f p -> g p -> (:*:) f g p
    (:*:) (a p -> b p -> (:*:) a b p)
    -> Parser (a p) -> Parser (b p -> (:*:) a b p)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Options -> Value -> Parser (a p)
    forall p. Options -> Value -> Parser (a p)
    forall (f :: * -> *) p.
    GenericDecode f =>
    Options -> Value -> Parser (f p)
    genericDecode Options
    opts Value
    o Parser (b p -> (:*:) a b p) -> Parser (b p) -> Parser ((:*:) a b p)
    forall a b. Parser (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Options -> Value -> Parser (b p)
    forall p. Options -> Value -> Parser (b p)
    forall (f :: * -> *) p.
    GenericDecode f =>
    Options -> Value -> Parser (f p)
    genericDecode Options
    opts Value
    o

    type RecordField sel a = S1 sel (Rec0 a)

    instance (Selector sel, FromValue a) => GenericDecode (RecordField sel a) where
      genericDecode :: forall p. Options -> Value -> Parser (RecordField sel a p)
    genericDecode = (Object -> Key -> Parser a)
    -> Options -> Value -> Parser (RecordField sel a p)
    forall (sel :: Meta) a p.
    Selector sel =>
    (Object -> Key -> Parser a)
    -> Options -> Value -> Parser (RecordField sel a p)
    accessFieldWith Object -> Key -> Parser a
    forall a. FromValue a => Object -> Key -> Parser a
    (.:)

    instance {-# OVERLAPPING #-} (Selector sel, FromValue a) => GenericDecode (RecordField sel (Maybe a)) where
      genericDecode :: forall p. Options -> Value -> Parser (RecordField sel (Maybe a) p)
    genericDecode = (Object -> Key -> Parser (Maybe a))
    -> Options -> Value -> Parser (RecordField sel (Maybe a) p)
    forall (sel :: Meta) a p.
    Selector sel =>
    (Object -> Key -> Parser a)
    -> Options -> Value -> Parser (RecordField sel a p)
    accessFieldWith Object -> Key -> Parser (Maybe a)
    forall a. FromValue a => Object -> Key -> Parser (Maybe a)
    (.:?)

    instance {-# OVERLAPPING #-} (Selector sel, FromValue a) => GenericDecode (RecordField sel (Last a)) where
      genericDecode :: forall p. Options -> Value -> Parser (RecordField sel (Last a) p)
    genericDecode = (Object -> Key -> Parser (Last a))
    -> Options -> Value -> Parser (RecordField sel (Last a) p)
    forall (sel :: Meta) a p.
    Selector sel =>
    (Object -> Key -> Parser a)
    -> Options -> Value -> Parser (RecordField sel a p)
    accessFieldWith (\ Object
    value Key
    key -> Maybe a -> Last a
    forall a. Maybe a -> Last a
    Last (Maybe a -> Last a) -> Parser (Maybe a) -> Parser (Last a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (Object
    value Object -> Key -> Parser (Maybe a)
    forall a. FromValue a => Object -> Key -> Parser (Maybe a)
    .:? Key
    key))

    instance {-# OVERLAPPING #-} (Selector sel, FromValue a, KnownBool deprecated, KnownSymbol alias) => GenericDecode (RecordField sel (Alias deprecated alias (Maybe a))) where
      genericDecode :: forall p.
    Options
    -> Value
    -> Parser (RecordField sel (Alias deprecated alias (Maybe a)) p)
    genericDecode = (Object -> Key -> Parser (Alias deprecated alias (Maybe a)))
    -> Options
    -> Value
    -> Parser (RecordField sel (Alias deprecated alias (Maybe a)) p)
    forall (sel :: Meta) a p.
    Selector sel =>
    (Object -> Key -> Parser a)
    -> Options -> Value -> Parser (RecordField sel a p)
    accessFieldWith (\ Object
    value Key
    key -> (Object -> Key -> Parser (Maybe a))
    -> Object
    -> Alias deprecated alias Key
    -> Parser (Alias deprecated alias (Maybe a))
    forall (deprecated :: Bool) (alias :: Symbol) a.
    (KnownBool deprecated, KnownSymbol alias) =>
    (Object -> Key -> Parser a)
    -> Object
    -> Alias deprecated alias Key
    -> Parser (Alias deprecated alias a)
    aliasAccess Object -> Key -> Parser (Maybe a)
    forall a. FromValue a => Object -> Key -> Parser (Maybe a)
    (.:?) Object
    value (Key -> Alias deprecated alias Key
    forall (deprecated :: Bool) (alias :: Symbol) a.
    a -> Alias deprecated alias a
    Alias Key
    key))

    instance {-# OVERLAPPING #-} (Selector sel, FromValue a, KnownBool deprecated, KnownSymbol alias) => GenericDecode (RecordField sel (Alias deprecated alias (Last a))) where
      genericDecode :: forall p.
    Options
    -> Value
    -> Parser (RecordField sel (Alias deprecated alias (Last a)) p)
    genericDecode = (Object -> Key -> Parser (Alias deprecated alias (Last a)))
    -> Options
    -> Value
    -> Parser (RecordField sel (Alias deprecated alias (Last a)) p)
    forall (sel :: Meta) a p.
    Selector sel =>
    (Object -> Key -> Parser a)
    -> Options -> Value -> Parser (RecordField sel a p)
    accessFieldWith (\ Object
    value Key
    key -> (Maybe a -> Last a)
    -> Alias deprecated alias (Maybe a)
    -> Alias deprecated alias (Last a)
    forall a b.
    (a -> b) -> Alias deprecated alias a -> Alias deprecated alias b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Maybe a -> Last a
    forall a. Maybe a -> Last a
    Last (Alias deprecated alias (Maybe a)
     -> Alias deprecated alias (Last a))
    -> Parser (Alias deprecated alias (Maybe a))
    -> Parser (Alias deprecated alias (Last a))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (Object -> Key -> Parser (Maybe a))
    -> Object
    -> Alias deprecated alias Key
    -> Parser (Alias deprecated alias (Maybe a))
    forall (deprecated :: Bool) (alias :: Symbol) a.
    (KnownBool deprecated, KnownSymbol alias) =>
    (Object -> Key -> Parser a)
    -> Object
    -> Alias deprecated alias Key
    -> Parser (Alias deprecated alias a)
    aliasAccess Object -> Key -> Parser (Maybe a)
    forall a. FromValue a => Object -> Key -> Parser (Maybe a)
    (.:?) Object
    value (Key -> Alias deprecated alias Key
    forall (deprecated :: Bool) (alias :: Symbol) a.
    a -> Alias deprecated alias a
    Alias Key
    key))

    aliasAccess :: forall deprecated alias a. (KnownBool deprecated, KnownSymbol alias) => (Object -> Key -> Parser a) -> Object -> (Alias deprecated alias Key) -> Parser (Alias deprecated alias a)
    aliasAccess :: forall (deprecated :: Bool) (alias :: Symbol) a.
    (KnownBool deprecated, KnownSymbol alias) =>
    (Object -> Key -> Parser a)
    -> Object
    -> Alias deprecated alias Key
    -> Parser (Alias deprecated alias a)
    aliasAccess Object -> Key -> Parser a
    op Object
    value (Alias Key
    key)
      | Key
    alias Key -> Object -> Bool
    forall a. Key -> KeyMap a -> Bool
    `member` Object
    value Bool -> Bool -> Bool
    && Bool -> Bool
    not (Key
    key Key -> Object -> Bool
    forall a. Key -> KeyMap a -> Bool
    `member` Object
    value) = a -> Alias deprecated alias a
    forall (deprecated :: Bool) (alias :: Symbol) a.
    a -> Alias deprecated alias a
    Alias (a -> Alias deprecated alias a)
    -> Parser a -> Parser (Alias deprecated alias a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Object
    value Object -> Key -> Parser a
    `op` Key
    alias Parser (Alias deprecated alias a)
    -> Parser () -> Parser (Alias deprecated alias a)
    forall a b. Parser a -> Parser b -> Parser a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* Parser ()
    deprecated
      | Bool
    otherwise = a -> Alias deprecated alias a
    forall (deprecated :: Bool) (alias :: Symbol) a.
    a -> Alias deprecated alias a
    Alias (a -> Alias deprecated alias a)
    -> Parser a -> Parser (Alias deprecated alias a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Object
    value Object -> Key -> Parser a
    `op` Key
    key
      where
        deprecated :: Parser ()
    deprecated = case Proxy deprecated -> Bool
    forall (a :: Bool). KnownBool a => Proxy a -> Bool
    boolVal (forall (t :: Bool). Proxy t
    forall {k} (t :: k). Proxy t
    Proxy @deprecated) of
          Bool
    False -> () -> Parser ()
    forall a. a -> Parser a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
          Bool
    True -> Key -> Key -> Parser ()
    markDeprecated Key
    alias Key
    key
        alias :: Key
    alias = String -> Key
    Key.fromString (Proxy alias -> String
    forall (n :: Symbol) (proxy :: Symbol -> *).
    KnownSymbol n =>
    proxy n -> String
    symbolVal (Proxy alias -> String) -> Proxy alias -> String
    forall a b. (a -> b) -> a -> b
    $ forall {k} (t :: k). Proxy t
    forall (t :: Symbol). Proxy t
    Proxy @alias)

    accessFieldWith :: forall sel a p. Selector sel => (Object -> Key -> Parser a) -> Options -> Value -> Parser (RecordField sel a p)
    accessFieldWith :: forall (sel :: Meta) a p.
    Selector sel =>
    (Object -> Key -> Parser a)
    -> Options -> Value -> Parser (RecordField sel a p)
    accessFieldWith Object -> Key -> Parser a
    op Options{String -> String
    optionsRecordSelectorModifier :: Options -> String -> String
    optionsRecordSelectorModifier :: String -> String
    ..} Value
    v = Rec0 a p -> M1 S sel (Rec0 a) p
    forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
    M1 (Rec0 a p -> M1 S sel (Rec0 a) p)
    -> (a -> Rec0 a p) -> a -> M1 S sel (Rec0 a) p
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> Rec0 a p
    forall k i c (p :: k). c -> K1 i c p
    K1 (a -> M1 S sel (Rec0 a) p)
    -> Parser a -> Parser (M1 S sel (Rec0 a) p)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (Object -> Parser a) -> Value -> Parser a
    forall a. (Object -> Parser a) -> Value -> Parser a
    withObject (Object -> Key -> Parser a
    `op` String -> Key
    Key.fromString String
    label) Value
    v
      where
        label :: String
    label = String -> String
    optionsRecordSelectorModifier (String -> String) -> String -> String
    forall a b. (a -> b) -> a -> b
    $ M1 S sel (Rec0 a) p -> String
    forall {k} (s :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
           (f :: k1 -> *) (a :: k1).
    Selector s =>
    t s f a -> String
    forall k1 (t :: Meta -> (k1 -> *) -> k1 -> *) (f :: k1 -> *)
           (a :: k1).
    t sel f a -> String
    selName (M1 S sel (Rec0 a) p
    forall a. HasCallStack => a
    undefined :: RecordField sel a p)

    newtype Alias (deprecated :: Bool) (alias :: Symbol) a = Alias a
      deriving (Int -> Alias deprecated alias a -> String -> String
    [Alias deprecated alias a] -> String -> String
    Alias deprecated alias a -> String
    (Int -> Alias deprecated alias a -> String -> String)
    -> (Alias deprecated alias a -> String)
    -> ([Alias deprecated alias a] -> String -> String)
    -> Show (Alias deprecated alias a)
    forall (deprecated :: Bool) (alias :: Symbol) a.
    Show a =>
    Int -> Alias deprecated alias a -> String -> String
    forall (deprecated :: Bool) (alias :: Symbol) a.
    Show a =>
    [Alias deprecated alias a] -> String -> String
    forall (deprecated :: Bool) (alias :: Symbol) a.
    Show a =>
    Alias deprecated alias a -> String
    forall a.
    (Int -> a -> String -> String)
    -> (a -> String) -> ([a] -> String -> String) -> Show a
    $cshowsPrec :: forall (deprecated :: Bool) (alias :: Symbol) a.
    Show a =>
    Int -> Alias deprecated alias a -> String -> String
    showsPrec :: Int -> Alias deprecated alias a -> String -> String
    $cshow :: forall (deprecated :: Bool) (alias :: Symbol) a.
    Show a =>
    Alias deprecated alias a -> String
    show :: Alias deprecated alias a -> String
    $cshowList :: forall (deprecated :: Bool) (alias :: Symbol) a.
    Show a =>
    [Alias deprecated alias a] -> String -> String
    showList :: [Alias deprecated alias a] -> String -> String
    Show, Alias deprecated alias a -> Alias deprecated alias a -> Bool
    (Alias deprecated alias a -> Alias deprecated alias a -> Bool)
    -> (Alias deprecated alias a -> Alias deprecated alias a -> Bool)
    -> Eq (Alias deprecated alias a)
    forall (deprecated :: Bool) (alias :: Symbol) a.
    Eq a =>
    Alias deprecated alias a -> Alias deprecated alias a -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall (deprecated :: Bool) (alias :: Symbol) a.
    Eq a =>
    Alias deprecated alias a -> Alias deprecated alias a -> Bool
    == :: Alias deprecated alias a -> Alias deprecated alias a -> Bool
    $c/= :: forall (deprecated :: Bool) (alias :: Symbol) a.
    Eq a =>
    Alias deprecated alias a -> Alias deprecated alias a -> Bool
    /= :: Alias deprecated alias a -> Alias deprecated alias a -> Bool
    Eq, NonEmpty (Alias deprecated alias a) -> Alias deprecated alias a
    Alias deprecated alias a
    -> Alias deprecated alias a -> Alias deprecated alias a
    (Alias deprecated alias a
     -> Alias deprecated alias a -> Alias deprecated alias a)
    -> (NonEmpty (Alias deprecated alias a)
        -> Alias deprecated alias a)
    -> (forall b.
        Integral b =>
        b -> Alias deprecated alias a -> Alias deprecated alias a)
    -> Semigroup (Alias deprecated alias a)
    forall (deprecated :: Bool) (alias :: Symbol) a.
    Semigroup a =>
    NonEmpty (Alias deprecated alias a) -> Alias deprecated alias a
    forall (deprecated :: Bool) (alias :: Symbol) a.
    Semigroup a =>
    Alias deprecated alias a
    -> Alias deprecated alias a -> Alias deprecated alias a
    forall (deprecated :: Bool) (alias :: Symbol) a b.
    (Semigroup a, Integral b) =>
    b -> Alias deprecated alias a -> Alias deprecated alias a
    forall b.
    Integral b =>
    b -> Alias deprecated alias a -> Alias deprecated alias a
    forall a.
    (a -> a -> a)
    -> (NonEmpty a -> a)
    -> (forall b. Integral b => b -> a -> a)
    -> Semigroup a
    $c<> :: forall (deprecated :: Bool) (alias :: Symbol) a.
    Semigroup a =>
    Alias deprecated alias a
    -> Alias deprecated alias a -> Alias deprecated alias a
    <> :: Alias deprecated alias a
    -> Alias deprecated alias a -> Alias deprecated alias a
    $csconcat :: forall (deprecated :: Bool) (alias :: Symbol) a.
    Semigroup a =>
    NonEmpty (Alias deprecated alias a) -> Alias deprecated alias a
    sconcat :: NonEmpty (Alias deprecated alias a) -> Alias deprecated alias a
    $cstimes :: forall (deprecated :: Bool) (alias :: Symbol) a b.
    (Semigroup a, Integral b) =>
    b -> Alias deprecated alias a -> Alias deprecated alias a
    stimes :: forall b.
    Integral b =>
    b -> Alias deprecated alias a -> Alias deprecated alias a
    Semigroup, Semigroup (Alias deprecated alias a)
    Alias deprecated alias a
    Semigroup (Alias deprecated alias a) =>
    Alias deprecated alias a
    -> (Alias deprecated alias a
        -> Alias deprecated alias a -> Alias deprecated alias a)
    -> ([Alias deprecated alias a] -> Alias deprecated alias a)
    -> Monoid (Alias deprecated alias a)
    [Alias deprecated alias a] -> Alias deprecated alias a
    Alias deprecated alias a
    -> Alias deprecated alias a -> Alias deprecated alias a
    forall (deprecated :: Bool) (alias :: Symbol) a.
    Monoid a =>
    Semigroup (Alias deprecated alias a)
    forall (deprecated :: Bool) (alias :: Symbol) a.
    Monoid a =>
    Alias deprecated alias a
    forall (deprecated :: Bool) (alias :: Symbol) a.
    Monoid a =>
    [Alias deprecated alias a] -> Alias deprecated alias a
    forall (deprecated :: Bool) (alias :: Symbol) a.
    Monoid a =>
    Alias deprecated alias a
    -> Alias deprecated alias a -> Alias deprecated alias a
    forall a.
    Semigroup a =>
    a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
    $cmempty :: forall (deprecated :: Bool) (alias :: Symbol) a.
    Monoid a =>
    Alias deprecated alias a
    mempty :: Alias deprecated alias a
    $cmappend :: forall (deprecated :: Bool) (alias :: Symbol) a.
    Monoid a =>
    Alias deprecated alias a
    -> Alias deprecated alias a -> Alias deprecated alias a
    mappend :: Alias deprecated alias a
    -> Alias deprecated alias a -> Alias deprecated alias a
    $cmconcat :: forall (deprecated :: Bool) (alias :: Symbol) a.
    Monoid a =>
    [Alias deprecated alias a] -> Alias deprecated alias a
    mconcat :: [Alias deprecated alias a] -> Alias deprecated alias a
    Monoid, (forall a b.
     (a -> b) -> Alias deprecated alias a -> Alias deprecated alias b)
    -> (forall a b.
        a -> Alias deprecated alias b -> Alias deprecated alias a)
    -> Functor (Alias deprecated alias)
    forall (deprecated :: Bool) (alias :: Symbol) a b.
    a -> Alias deprecated alias b -> Alias deprecated alias a
    forall (deprecated :: Bool) (alias :: Symbol) a b.
    (a -> b) -> Alias deprecated alias a -> Alias deprecated alias b
    forall a b.
    a -> Alias deprecated alias b -> Alias deprecated alias a
    forall a b.
    (a -> b) -> Alias deprecated alias a -> Alias deprecated alias b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall (deprecated :: Bool) (alias :: Symbol) a b.
    (a -> b) -> Alias deprecated alias a -> Alias deprecated alias b
    fmap :: forall a b.
    (a -> b) -> Alias deprecated alias a -> Alias deprecated alias b
    $c<$ :: forall (deprecated :: Bool) (alias :: Symbol) a b.
    a -> Alias deprecated alias b -> Alias deprecated alias a
    <$ :: forall a b.
    a -> Alias deprecated alias b -> Alias deprecated alias a
    Functor)

    unAlias :: Alias deprecated alias a -> a
    unAlias :: forall (deprecated :: Bool) (alias :: Symbol) a.
    Alias deprecated alias a -> a
    unAlias (Alias a
    a) = a
    a

    class KnownBool (a :: Bool) where
      boolVal :: Proxy a -> Bool

    instance KnownBool 'True where
      boolVal :: Proxy 'True -> Bool
    boolVal Proxy 'True
    _ = Bool
    True

    instance KnownBool 'False where
      boolVal :: Proxy 'False -> Bool
    boolVal Proxy 'False
    _ = Bool
    False