module Ecluse.Core.Registry.Npm.Wire (
Person (..),
Repository (..),
Bugs (..),
License (..),
Dist (..),
Signature (..),
VersionManifest (..),
Packument (..),
AbbreviatedPackument (..),
ErrorResponse (..),
ErrorBody (..),
errorMessage,
) where
import Data.Aeson (
FromJSON (parseJSON),
Object,
Value (Array, Bool, Null, Number, Object, String),
withObject,
(.!=),
(.:),
(.:?),
)
import Data.Aeson.Key (Key)
import Data.Aeson.Types (Parser, parseMaybe)
import Data.Map.Strict qualified as Map
import Data.Time (UTCTime)
data Person = Person
{ Person -> Text
personName :: Text
, Person -> Maybe Text
personEmail :: Maybe Text
, Person -> Maybe Text
personUrl :: Maybe Text
}
deriving stock (Person -> Person -> Bool
(Person -> Person -> Bool)
-> (Person -> Person -> Bool) -> Eq Person
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Person -> Person -> Bool
== :: Person -> Person -> Bool
$c/= :: Person -> Person -> Bool
/= :: Person -> Person -> Bool
Eq, Eq Person
Eq Person =>
(Person -> Person -> Ordering)
-> (Person -> Person -> Bool)
-> (Person -> Person -> Bool)
-> (Person -> Person -> Bool)
-> (Person -> Person -> Bool)
-> (Person -> Person -> Person)
-> (Person -> Person -> Person)
-> Ord Person
Person -> Person -> Bool
Person -> Person -> Ordering
Person -> Person -> Person
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Person -> Person -> Ordering
compare :: Person -> Person -> Ordering
$c< :: Person -> Person -> Bool
< :: Person -> Person -> Bool
$c<= :: Person -> Person -> Bool
<= :: Person -> Person -> Bool
$c> :: Person -> Person -> Bool
> :: Person -> Person -> Bool
$c>= :: Person -> Person -> Bool
>= :: Person -> Person -> Bool
$cmax :: Person -> Person -> Person
max :: Person -> Person -> Person
$cmin :: Person -> Person -> Person
min :: Person -> Person -> Person
Ord, Int -> Person -> ShowS
[Person] -> ShowS
Person -> String
(Int -> Person -> ShowS)
-> (Person -> String) -> ([Person] -> ShowS) -> Show Person
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Person -> ShowS
showsPrec :: Int -> Person -> ShowS
$cshow :: Person -> String
show :: Person -> String
$cshowList :: [Person] -> ShowS
showList :: [Person] -> ShowS
Show)
instance FromJSON Person where
parseJSON :: Value -> Parser Person
parseJSON = \case
String Text
name -> Person -> Parser Person
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> Maybe Text -> Maybe Text -> Person
Person Text
name Maybe Text
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing)
Object Object
o ->
Text -> Maybe Text -> Maybe Text -> Person
Person
(Text -> Maybe Text -> Maybe Text -> Person)
-> Parser Text -> Parser (Maybe Text -> Maybe Text -> Person)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"name" Parser (Maybe Text) -> Text -> Parser Text
forall a. Parser (Maybe a) -> a -> Parser a
.!= Text
""
Parser (Maybe Text -> Maybe Text -> Person)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Person)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"email"
Parser (Maybe Text -> Person)
-> Parser (Maybe Text) -> Parser Person
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"url"
Value
other -> String -> Value -> Parser Person
forall a. String -> Value -> Parser a
typeMismatchOneOf String
"Person (object or string)" Value
other
data Repository = Repository
{ Repository -> Maybe Text
repoType :: Maybe Text
, Repository -> Text
repoUrl :: Text
}
deriving stock (Repository -> Repository -> Bool
(Repository -> Repository -> Bool)
-> (Repository -> Repository -> Bool) -> Eq Repository
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Repository -> Repository -> Bool
== :: Repository -> Repository -> Bool
$c/= :: Repository -> Repository -> Bool
/= :: Repository -> Repository -> Bool
Eq, Eq Repository
Eq Repository =>
(Repository -> Repository -> Ordering)
-> (Repository -> Repository -> Bool)
-> (Repository -> Repository -> Bool)
-> (Repository -> Repository -> Bool)
-> (Repository -> Repository -> Bool)
-> (Repository -> Repository -> Repository)
-> (Repository -> Repository -> Repository)
-> Ord Repository
Repository -> Repository -> Bool
Repository -> Repository -> Ordering
Repository -> Repository -> Repository
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Repository -> Repository -> Ordering
compare :: Repository -> Repository -> Ordering
$c< :: Repository -> Repository -> Bool
< :: Repository -> Repository -> Bool
$c<= :: Repository -> Repository -> Bool
<= :: Repository -> Repository -> Bool
$c> :: Repository -> Repository -> Bool
> :: Repository -> Repository -> Bool
$c>= :: Repository -> Repository -> Bool
>= :: Repository -> Repository -> Bool
$cmax :: Repository -> Repository -> Repository
max :: Repository -> Repository -> Repository
$cmin :: Repository -> Repository -> Repository
min :: Repository -> Repository -> Repository
Ord, Int -> Repository -> ShowS
[Repository] -> ShowS
Repository -> String
(Int -> Repository -> ShowS)
-> (Repository -> String)
-> ([Repository] -> ShowS)
-> Show Repository
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Repository -> ShowS
showsPrec :: Int -> Repository -> ShowS
$cshow :: Repository -> String
show :: Repository -> String
$cshowList :: [Repository] -> ShowS
showList :: [Repository] -> ShowS
Show)
instance FromJSON Repository where
parseJSON :: Value -> Parser Repository
parseJSON = \case
String Text
url -> Repository -> Parser Repository
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Text -> Text -> Repository
Repository Maybe Text
forall a. Maybe a
Nothing Text
url)
Object Object
o ->
Maybe Text -> Text -> Repository
Repository
(Maybe Text -> Text -> Repository)
-> Parser (Maybe Text) -> Parser (Text -> Repository)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"type"
Parser (Text -> Repository) -> Parser Text -> Parser Repository
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"url" Parser (Maybe Text) -> Text -> Parser Text
forall a. Parser (Maybe a) -> a -> Parser a
.!= Text
""
Value
other -> String -> Value -> Parser Repository
forall a. String -> Value -> Parser a
typeMismatchOneOf String
"Repository (object or string)" Value
other
data Bugs = Bugs
{ Bugs -> Maybe Text
bugsUrl :: Maybe Text
, Bugs -> Maybe Text
bugsEmail :: Maybe Text
}
deriving stock (Bugs -> Bugs -> Bool
(Bugs -> Bugs -> Bool) -> (Bugs -> Bugs -> Bool) -> Eq Bugs
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Bugs -> Bugs -> Bool
== :: Bugs -> Bugs -> Bool
$c/= :: Bugs -> Bugs -> Bool
/= :: Bugs -> Bugs -> Bool
Eq, Eq Bugs
Eq Bugs =>
(Bugs -> Bugs -> Ordering)
-> (Bugs -> Bugs -> Bool)
-> (Bugs -> Bugs -> Bool)
-> (Bugs -> Bugs -> Bool)
-> (Bugs -> Bugs -> Bool)
-> (Bugs -> Bugs -> Bugs)
-> (Bugs -> Bugs -> Bugs)
-> Ord Bugs
Bugs -> Bugs -> Bool
Bugs -> Bugs -> Ordering
Bugs -> Bugs -> Bugs
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Bugs -> Bugs -> Ordering
compare :: Bugs -> Bugs -> Ordering
$c< :: Bugs -> Bugs -> Bool
< :: Bugs -> Bugs -> Bool
$c<= :: Bugs -> Bugs -> Bool
<= :: Bugs -> Bugs -> Bool
$c> :: Bugs -> Bugs -> Bool
> :: Bugs -> Bugs -> Bool
$c>= :: Bugs -> Bugs -> Bool
>= :: Bugs -> Bugs -> Bool
$cmax :: Bugs -> Bugs -> Bugs
max :: Bugs -> Bugs -> Bugs
$cmin :: Bugs -> Bugs -> Bugs
min :: Bugs -> Bugs -> Bugs
Ord, Int -> Bugs -> ShowS
[Bugs] -> ShowS
Bugs -> String
(Int -> Bugs -> ShowS)
-> (Bugs -> String) -> ([Bugs] -> ShowS) -> Show Bugs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Bugs -> ShowS
showsPrec :: Int -> Bugs -> ShowS
$cshow :: Bugs -> String
show :: Bugs -> String
$cshowList :: [Bugs] -> ShowS
showList :: [Bugs] -> ShowS
Show)
instance FromJSON Bugs where
parseJSON :: Value -> Parser Bugs
parseJSON = \case
String Text
url -> Bugs -> Parser Bugs
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Text -> Maybe Text -> Bugs
Bugs (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
url) Maybe Text
forall a. Maybe a
Nothing)
Object Object
o ->
Maybe Text -> Maybe Text -> Bugs
Bugs
(Maybe Text -> Maybe Text -> Bugs)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Bugs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"url"
Parser (Maybe Text -> Bugs) -> Parser (Maybe Text) -> Parser Bugs
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"email"
Value
other -> String -> Value -> Parser Bugs
forall a. String -> Value -> Parser a
typeMismatchOneOf String
"Bugs (object or string)" Value
other
data License
=
LicenseSpdx Text
|
LicenseObject Text (Maybe Text)
deriving stock (License -> License -> Bool
(License -> License -> Bool)
-> (License -> License -> Bool) -> Eq License
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: License -> License -> Bool
== :: License -> License -> Bool
$c/= :: License -> License -> Bool
/= :: License -> License -> Bool
Eq, Eq License
Eq License =>
(License -> License -> Ordering)
-> (License -> License -> Bool)
-> (License -> License -> Bool)
-> (License -> License -> Bool)
-> (License -> License -> Bool)
-> (License -> License -> License)
-> (License -> License -> License)
-> Ord License
License -> License -> Bool
License -> License -> Ordering
License -> License -> License
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: License -> License -> Ordering
compare :: License -> License -> Ordering
$c< :: License -> License -> Bool
< :: License -> License -> Bool
$c<= :: License -> License -> Bool
<= :: License -> License -> Bool
$c> :: License -> License -> Bool
> :: License -> License -> Bool
$c>= :: License -> License -> Bool
>= :: License -> License -> Bool
$cmax :: License -> License -> License
max :: License -> License -> License
$cmin :: License -> License -> License
min :: License -> License -> License
Ord, Int -> License -> ShowS
[License] -> ShowS
License -> String
(Int -> License -> ShowS)
-> (License -> String) -> ([License] -> ShowS) -> Show License
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> License -> ShowS
showsPrec :: Int -> License -> ShowS
$cshow :: License -> String
show :: License -> String
$cshowList :: [License] -> ShowS
showList :: [License] -> ShowS
Show)
instance FromJSON License where
parseJSON :: Value -> Parser License
parseJSON = \case
String Text
spdx -> License -> Parser License
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> License
LicenseSpdx Text
spdx)
Object Object
o ->
Text -> Maybe Text -> License
LicenseObject
(Text -> Maybe Text -> License)
-> Parser Text -> Parser (Maybe Text -> License)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"type" Parser (Maybe Text) -> Text -> Parser Text
forall a. Parser (Maybe a) -> a -> Parser a
.!= Text
""
Parser (Maybe Text -> License)
-> Parser (Maybe Text) -> Parser License
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"url"
Value
other -> String -> Value -> Parser License
forall a. String -> Value -> Parser a
typeMismatchOneOf String
"License (object or string)" Value
other
data Signature = Signature
{ Signature -> Text
sigSig :: Text
, Signature -> Text
sigKeyid :: Text
}
deriving stock (Signature -> Signature -> Bool
(Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool) -> Eq Signature
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Signature -> Signature -> Bool
== :: Signature -> Signature -> Bool
$c/= :: Signature -> Signature -> Bool
/= :: Signature -> Signature -> Bool
Eq, Eq Signature
Eq Signature =>
(Signature -> Signature -> Ordering)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Signature)
-> (Signature -> Signature -> Signature)
-> Ord Signature
Signature -> Signature -> Bool
Signature -> Signature -> Ordering
Signature -> Signature -> Signature
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Signature -> Signature -> Ordering
compare :: Signature -> Signature -> Ordering
$c< :: Signature -> Signature -> Bool
< :: Signature -> Signature -> Bool
$c<= :: Signature -> Signature -> Bool
<= :: Signature -> Signature -> Bool
$c> :: Signature -> Signature -> Bool
> :: Signature -> Signature -> Bool
$c>= :: Signature -> Signature -> Bool
>= :: Signature -> Signature -> Bool
$cmax :: Signature -> Signature -> Signature
max :: Signature -> Signature -> Signature
$cmin :: Signature -> Signature -> Signature
min :: Signature -> Signature -> Signature
Ord, Int -> Signature -> ShowS
[Signature] -> ShowS
Signature -> String
(Int -> Signature -> ShowS)
-> (Signature -> String)
-> ([Signature] -> ShowS)
-> Show Signature
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Signature -> ShowS
showsPrec :: Int -> Signature -> ShowS
$cshow :: Signature -> String
show :: Signature -> String
$cshowList :: [Signature] -> ShowS
showList :: [Signature] -> ShowS
Show)
instance FromJSON Signature where
parseJSON :: Value -> Parser Signature
parseJSON = String -> (Object -> Parser Signature) -> Value -> Parser Signature
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Signature" ((Object -> Parser Signature) -> Value -> Parser Signature)
-> (Object -> Parser Signature) -> Value -> Parser Signature
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Text -> Text -> Signature
Signature
(Text -> Text -> Signature)
-> Parser Text -> Parser (Text -> Signature)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"sig"
Parser (Text -> Signature) -> Parser Text -> Parser Signature
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"keyid"
data Dist = Dist
{ Dist -> Text
distTarball :: Text
, Dist -> Maybe Text
distShasum :: Maybe Text
, Dist -> Maybe Text
distIntegrity :: Maybe Text
, Dist -> Maybe Int
distFileCount :: Maybe Int
, Dist -> Maybe Int
distUnpackedSize :: Maybe Int
, Dist -> [Signature]
distSignatures :: [Signature]
}
deriving stock (Dist -> Dist -> Bool
(Dist -> Dist -> Bool) -> (Dist -> Dist -> Bool) -> Eq Dist
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Dist -> Dist -> Bool
== :: Dist -> Dist -> Bool
$c/= :: Dist -> Dist -> Bool
/= :: Dist -> Dist -> Bool
Eq, Eq Dist
Eq Dist =>
(Dist -> Dist -> Ordering)
-> (Dist -> Dist -> Bool)
-> (Dist -> Dist -> Bool)
-> (Dist -> Dist -> Bool)
-> (Dist -> Dist -> Bool)
-> (Dist -> Dist -> Dist)
-> (Dist -> Dist -> Dist)
-> Ord Dist
Dist -> Dist -> Bool
Dist -> Dist -> Ordering
Dist -> Dist -> Dist
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Dist -> Dist -> Ordering
compare :: Dist -> Dist -> Ordering
$c< :: Dist -> Dist -> Bool
< :: Dist -> Dist -> Bool
$c<= :: Dist -> Dist -> Bool
<= :: Dist -> Dist -> Bool
$c> :: Dist -> Dist -> Bool
> :: Dist -> Dist -> Bool
$c>= :: Dist -> Dist -> Bool
>= :: Dist -> Dist -> Bool
$cmax :: Dist -> Dist -> Dist
max :: Dist -> Dist -> Dist
$cmin :: Dist -> Dist -> Dist
min :: Dist -> Dist -> Dist
Ord, Int -> Dist -> ShowS
[Dist] -> ShowS
Dist -> String
(Int -> Dist -> ShowS)
-> (Dist -> String) -> ([Dist] -> ShowS) -> Show Dist
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Dist -> ShowS
showsPrec :: Int -> Dist -> ShowS
$cshow :: Dist -> String
show :: Dist -> String
$cshowList :: [Dist] -> ShowS
showList :: [Dist] -> ShowS
Show)
instance FromJSON Dist where
parseJSON :: Value -> Parser Dist
parseJSON = String -> (Object -> Parser Dist) -> Value -> Parser Dist
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Dist" ((Object -> Parser Dist) -> Value -> Parser Dist)
-> (Object -> Parser Dist) -> Value -> Parser Dist
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Text
-> Maybe Text
-> Maybe Text
-> Maybe Int
-> Maybe Int
-> [Signature]
-> Dist
Dist
(Text
-> Maybe Text
-> Maybe Text
-> Maybe Int
-> Maybe Int
-> [Signature]
-> Dist)
-> Parser Text
-> Parser
(Maybe Text
-> Maybe Text -> Maybe Int -> Maybe Int -> [Signature] -> Dist)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"tarball"
Parser
(Maybe Text
-> Maybe Text -> Maybe Int -> Maybe Int -> [Signature] -> Dist)
-> Parser (Maybe Text)
-> Parser
(Maybe Text -> Maybe Int -> Maybe Int -> [Signature] -> Dist)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"shasum"
Parser
(Maybe Text -> Maybe Int -> Maybe Int -> [Signature] -> Dist)
-> Parser (Maybe Text)
-> Parser (Maybe Int -> Maybe Int -> [Signature] -> Dist)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"integrity"
Parser (Maybe Int -> Maybe Int -> [Signature] -> Dist)
-> Parser (Maybe Int) -> Parser (Maybe Int -> [Signature] -> Dist)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
lenientOptional Object
o Key
"fileCount"
Parser (Maybe Int -> [Signature] -> Dist)
-> Parser (Maybe Int) -> Parser ([Signature] -> Dist)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
lenientOptional Object
o Key
"unpackedSize"
Parser ([Signature] -> Dist) -> Parser [Signature] -> Parser Dist
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> Parser [Signature]
lenientSignatures Object
o
lenientOptional :: (FromJSON a) => Object -> Key -> Parser (Maybe a)
lenientOptional :: forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
lenientOptional Object
o Key
k = do
mv <- Object
o Object -> Key -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
k
pure (mv >>= parseMaybe parseJSON)
lenientSignatures :: Object -> Parser [Signature]
lenientSignatures :: Object -> Parser [Signature]
lenientSignatures Object
o = do
mv <- Object
o Object -> Key -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"signatures"
pure $ case mv of
Just (Array Array
xs) -> (Value -> Maybe Signature) -> [Value] -> [Signature]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe ((Value -> Parser Signature) -> Value -> Maybe Signature
forall a b. (a -> Parser b) -> a -> Maybe b
parseMaybe Value -> Parser Signature
forall a. FromJSON a => Value -> Parser a
parseJSON) (Array -> [Value]
forall a. Vector a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList Array
xs)
Maybe Value
_ -> []
data VersionManifest = VersionManifest
{ VersionManifest -> Text
vmName :: Text
, VersionManifest -> Text
vmVersion :: Text
, VersionManifest -> Dist
vmDist :: Dist
, VersionManifest -> Maybe Text
vmDeprecated :: Maybe Text
, VersionManifest -> Maybe Bool
vmHasInstallScript :: Maybe Bool
, VersionManifest -> Map Text Text
vmScripts :: Map Text Text
, VersionManifest -> Maybe License
vmLicense :: Maybe License
}
deriving stock (VersionManifest -> VersionManifest -> Bool
(VersionManifest -> VersionManifest -> Bool)
-> (VersionManifest -> VersionManifest -> Bool)
-> Eq VersionManifest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VersionManifest -> VersionManifest -> Bool
== :: VersionManifest -> VersionManifest -> Bool
$c/= :: VersionManifest -> VersionManifest -> Bool
/= :: VersionManifest -> VersionManifest -> Bool
Eq, Int -> VersionManifest -> ShowS
[VersionManifest] -> ShowS
VersionManifest -> String
(Int -> VersionManifest -> ShowS)
-> (VersionManifest -> String)
-> ([VersionManifest] -> ShowS)
-> Show VersionManifest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VersionManifest -> ShowS
showsPrec :: Int -> VersionManifest -> ShowS
$cshow :: VersionManifest -> String
show :: VersionManifest -> String
$cshowList :: [VersionManifest] -> ShowS
showList :: [VersionManifest] -> ShowS
Show)
instance FromJSON VersionManifest where
parseJSON :: Value -> Parser VersionManifest
parseJSON = String
-> (Object -> Parser VersionManifest)
-> Value
-> Parser VersionManifest
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"VersionManifest" ((Object -> Parser VersionManifest)
-> Value -> Parser VersionManifest)
-> (Object -> Parser VersionManifest)
-> Value
-> Parser VersionManifest
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Text
-> Text
-> Dist
-> Maybe Text
-> Maybe Bool
-> Map Text Text
-> Maybe License
-> VersionManifest
VersionManifest
(Text
-> Text
-> Dist
-> Maybe Text
-> Maybe Bool
-> Map Text Text
-> Maybe License
-> VersionManifest)
-> Parser Text
-> Parser
(Text
-> Dist
-> Maybe Text
-> Maybe Bool
-> Map Text Text
-> Maybe License
-> VersionManifest)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
Parser
(Text
-> Dist
-> Maybe Text
-> Maybe Bool
-> Map Text Text
-> Maybe License
-> VersionManifest)
-> Parser Text
-> Parser
(Dist
-> Maybe Text
-> Maybe Bool
-> Map Text Text
-> Maybe License
-> VersionManifest)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"version"
Parser
(Dist
-> Maybe Text
-> Maybe Bool
-> Map Text Text
-> Maybe License
-> VersionManifest)
-> Parser Dist
-> Parser
(Maybe Text
-> Maybe Bool -> Map Text Text -> Maybe License -> VersionManifest)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Dist
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"dist"
Parser
(Maybe Text
-> Maybe Bool -> Map Text Text -> Maybe License -> VersionManifest)
-> Parser (Maybe Text)
-> Parser
(Maybe Bool -> Map Text Text -> Maybe License -> VersionManifest)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Maybe Value -> Maybe Text
deprecatedNotice (Maybe Value -> Maybe Text)
-> Parser (Maybe Value) -> Parser (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"deprecated")
Parser
(Maybe Bool -> Map Text Text -> Maybe License -> VersionManifest)
-> Parser (Maybe Bool)
-> Parser (Map Text Text -> Maybe License -> VersionManifest)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"hasInstallScript"
Parser (Map Text Text -> Maybe License -> VersionManifest)
-> Parser (Map Text Text)
-> Parser (Maybe License -> VersionManifest)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe (Map Text Text))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"scripts" Parser (Maybe (Map Text Text))
-> Map Text Text -> Parser (Map Text Text)
forall a. Parser (Maybe a) -> a -> Parser a
.!= Map Text Text
forall a. Monoid a => a
mempty
Parser (Maybe License -> VersionManifest)
-> Parser (Maybe License) -> Parser VersionManifest
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe License)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"license"
deprecatedNotice :: Maybe Value -> Maybe Text
deprecatedNotice :: Maybe Value -> Maybe Text
deprecatedNotice = \case
Just (String Text
message) -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
message
Just (Bool Bool
True) -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
""
Maybe Value
_ -> Maybe Text
forall a. Maybe a
Nothing
lenientVersionMap :: Object -> Parser (Map Text VersionManifest)
lenientVersionMap :: Object -> Parser (Map Text VersionManifest)
lenientVersionMap Object
o = do
raw <- Object
o Object -> Key -> Parser (Maybe (Map Text Value))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"versions" Parser (Maybe (Map Text Value))
-> Map Text Value -> Parser (Map Text Value)
forall a. Parser (Maybe a) -> a -> Parser a
.!= Map Text Value
forall a. Monoid a => a
mempty
pure (Map.mapMaybe (parseMaybe parseJSON) raw)
data Packument = Packument
{ Packument -> Text
pkmtName :: Text
, Packument -> Map Text Text
pkmtDistTags :: Map Text Text
, Packument -> Map Text VersionManifest
pkmtVersions :: Map Text VersionManifest
, Packument -> Map Text UTCTime
pkmtTime :: Map Text UTCTime
, Packument -> [Person]
pkmtMaintainers :: [Person]
, Packument -> Maybe Text
pkmtDescription :: Maybe Text
, Packument -> Maybe Text
pkmtHomepage :: Maybe Text
, Packument -> Maybe Repository
pkmtRepository :: Maybe Repository
, Packument -> Maybe Bugs
pkmtBugs :: Maybe Bugs
, Packument -> Maybe License
pkmtLicense :: Maybe License
, Packument -> [Text]
pkmtKeywords :: [Text]
}
deriving stock (Packument -> Packument -> Bool
(Packument -> Packument -> Bool)
-> (Packument -> Packument -> Bool) -> Eq Packument
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Packument -> Packument -> Bool
== :: Packument -> Packument -> Bool
$c/= :: Packument -> Packument -> Bool
/= :: Packument -> Packument -> Bool
Eq, Int -> Packument -> ShowS
[Packument] -> ShowS
Packument -> String
(Int -> Packument -> ShowS)
-> (Packument -> String)
-> ([Packument] -> ShowS)
-> Show Packument
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Packument -> ShowS
showsPrec :: Int -> Packument -> ShowS
$cshow :: Packument -> String
show :: Packument -> String
$cshowList :: [Packument] -> ShowS
showList :: [Packument] -> ShowS
Show)
instance FromJSON Packument where
parseJSON :: Value -> Parser Packument
parseJSON = String -> (Object -> Parser Packument) -> Value -> Parser Packument
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Packument" ((Object -> Parser Packument) -> Value -> Parser Packument)
-> (Object -> Parser Packument) -> Value -> Parser Packument
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Text
-> Map Text Text
-> Map Text VersionManifest
-> Map Text UTCTime
-> [Person]
-> Maybe Text
-> Maybe Text
-> Maybe Repository
-> Maybe Bugs
-> Maybe License
-> [Text]
-> Packument
Packument
(Text
-> Map Text Text
-> Map Text VersionManifest
-> Map Text UTCTime
-> [Person]
-> Maybe Text
-> Maybe Text
-> Maybe Repository
-> Maybe Bugs
-> Maybe License
-> [Text]
-> Packument)
-> Parser Text
-> Parser
(Map Text Text
-> Map Text VersionManifest
-> Map Text UTCTime
-> [Person]
-> Maybe Text
-> Maybe Text
-> Maybe Repository
-> Maybe Bugs
-> Maybe License
-> [Text]
-> Packument)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
Parser
(Map Text Text
-> Map Text VersionManifest
-> Map Text UTCTime
-> [Person]
-> Maybe Text
-> Maybe Text
-> Maybe Repository
-> Maybe Bugs
-> Maybe License
-> [Text]
-> Packument)
-> Parser (Map Text Text)
-> Parser
(Map Text VersionManifest
-> Map Text UTCTime
-> [Person]
-> Maybe Text
-> Maybe Text
-> Maybe Repository
-> Maybe Bugs
-> Maybe License
-> [Text]
-> Packument)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe (Map Text Text))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"dist-tags" Parser (Maybe (Map Text Text))
-> Map Text Text -> Parser (Map Text Text)
forall a. Parser (Maybe a) -> a -> Parser a
.!= Map Text Text
forall a. Monoid a => a
mempty
Parser
(Map Text VersionManifest
-> Map Text UTCTime
-> [Person]
-> Maybe Text
-> Maybe Text
-> Maybe Repository
-> Maybe Bugs
-> Maybe License
-> [Text]
-> Packument)
-> Parser (Map Text VersionManifest)
-> Parser
(Map Text UTCTime
-> [Person]
-> Maybe Text
-> Maybe Text
-> Maybe Repository
-> Maybe Bugs
-> Maybe License
-> [Text]
-> Packument)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> Parser (Map Text VersionManifest)
lenientVersionMap Object
o
Parser
(Map Text UTCTime
-> [Person]
-> Maybe Text
-> Maybe Text
-> Maybe Repository
-> Maybe Bugs
-> Maybe License
-> [Text]
-> Packument)
-> Parser (Map Text UTCTime)
-> Parser
([Person]
-> Maybe Text
-> Maybe Text
-> Maybe Repository
-> Maybe Bugs
-> Maybe License
-> [Text]
-> Packument)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe (Map Text UTCTime))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"time" Parser (Maybe (Map Text UTCTime))
-> Map Text UTCTime -> Parser (Map Text UTCTime)
forall a. Parser (Maybe a) -> a -> Parser a
.!= Map Text UTCTime
forall a. Monoid a => a
mempty
Parser
([Person]
-> Maybe Text
-> Maybe Text
-> Maybe Repository
-> Maybe Bugs
-> Maybe License
-> [Text]
-> Packument)
-> Parser [Person]
-> Parser
(Maybe Text
-> Maybe Text
-> Maybe Repository
-> Maybe Bugs
-> Maybe License
-> [Text]
-> Packument)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe [Person])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"maintainers" Parser (Maybe [Person]) -> [Person] -> Parser [Person]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
Parser
(Maybe Text
-> Maybe Text
-> Maybe Repository
-> Maybe Bugs
-> Maybe License
-> [Text]
-> Packument)
-> Parser (Maybe Text)
-> Parser
(Maybe Text
-> Maybe Repository
-> Maybe Bugs
-> Maybe License
-> [Text]
-> Packument)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"description"
Parser
(Maybe Text
-> Maybe Repository
-> Maybe Bugs
-> Maybe License
-> [Text]
-> Packument)
-> Parser (Maybe Text)
-> Parser
(Maybe Repository
-> Maybe Bugs -> Maybe License -> [Text] -> Packument)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"homepage"
Parser
(Maybe Repository
-> Maybe Bugs -> Maybe License -> [Text] -> Packument)
-> Parser (Maybe Repository)
-> Parser (Maybe Bugs -> Maybe License -> [Text] -> Packument)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Repository)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"repository"
Parser (Maybe Bugs -> Maybe License -> [Text] -> Packument)
-> Parser (Maybe Bugs)
-> Parser (Maybe License -> [Text] -> Packument)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Bugs)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"bugs"
Parser (Maybe License -> [Text] -> Packument)
-> Parser (Maybe License) -> Parser ([Text] -> Packument)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe License)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"license"
Parser ([Text] -> Packument) -> Parser [Text] -> Parser Packument
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"keywords" Parser (Maybe [Text]) -> [Text] -> Parser [Text]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
data AbbreviatedPackument = AbbreviatedPackument
{ AbbreviatedPackument -> Text
apkmtName :: Text
, AbbreviatedPackument -> UTCTime
apkmtModified :: UTCTime
, AbbreviatedPackument -> Map Text Text
apkmtDistTags :: Map Text Text
, AbbreviatedPackument -> Map Text VersionManifest
apkmtVersions :: Map Text VersionManifest
}
deriving stock (AbbreviatedPackument -> AbbreviatedPackument -> Bool
(AbbreviatedPackument -> AbbreviatedPackument -> Bool)
-> (AbbreviatedPackument -> AbbreviatedPackument -> Bool)
-> Eq AbbreviatedPackument
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AbbreviatedPackument -> AbbreviatedPackument -> Bool
== :: AbbreviatedPackument -> AbbreviatedPackument -> Bool
$c/= :: AbbreviatedPackument -> AbbreviatedPackument -> Bool
/= :: AbbreviatedPackument -> AbbreviatedPackument -> Bool
Eq, Int -> AbbreviatedPackument -> ShowS
[AbbreviatedPackument] -> ShowS
AbbreviatedPackument -> String
(Int -> AbbreviatedPackument -> ShowS)
-> (AbbreviatedPackument -> String)
-> ([AbbreviatedPackument] -> ShowS)
-> Show AbbreviatedPackument
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AbbreviatedPackument -> ShowS
showsPrec :: Int -> AbbreviatedPackument -> ShowS
$cshow :: AbbreviatedPackument -> String
show :: AbbreviatedPackument -> String
$cshowList :: [AbbreviatedPackument] -> ShowS
showList :: [AbbreviatedPackument] -> ShowS
Show)
instance FromJSON AbbreviatedPackument where
parseJSON :: Value -> Parser AbbreviatedPackument
parseJSON = String
-> (Object -> Parser AbbreviatedPackument)
-> Value
-> Parser AbbreviatedPackument
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"AbbreviatedPackument" ((Object -> Parser AbbreviatedPackument)
-> Value -> Parser AbbreviatedPackument)
-> (Object -> Parser AbbreviatedPackument)
-> Value
-> Parser AbbreviatedPackument
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Text
-> UTCTime
-> Map Text Text
-> Map Text VersionManifest
-> AbbreviatedPackument
AbbreviatedPackument
(Text
-> UTCTime
-> Map Text Text
-> Map Text VersionManifest
-> AbbreviatedPackument)
-> Parser Text
-> Parser
(UTCTime
-> Map Text Text
-> Map Text VersionManifest
-> AbbreviatedPackument)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
Parser
(UTCTime
-> Map Text Text
-> Map Text VersionManifest
-> AbbreviatedPackument)
-> Parser UTCTime
-> Parser
(Map Text Text -> Map Text VersionManifest -> AbbreviatedPackument)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser UTCTime
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"modified"
Parser
(Map Text Text -> Map Text VersionManifest -> AbbreviatedPackument)
-> Parser (Map Text Text)
-> Parser (Map Text VersionManifest -> AbbreviatedPackument)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe (Map Text Text))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"dist-tags" Parser (Maybe (Map Text Text))
-> Map Text Text -> Parser (Map Text Text)
forall a. Parser (Maybe a) -> a -> Parser a
.!= Map Text Text
forall a. Monoid a => a
mempty
Parser (Map Text VersionManifest -> AbbreviatedPackument)
-> Parser (Map Text VersionManifest) -> Parser AbbreviatedPackument
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> Parser (Map Text VersionManifest)
lenientVersionMap Object
o
data ErrorResponse
=
ErrorObject ErrorBody
|
ErrorString Text
deriving stock (ErrorResponse -> ErrorResponse -> Bool
(ErrorResponse -> ErrorResponse -> Bool)
-> (ErrorResponse -> ErrorResponse -> Bool) -> Eq ErrorResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ErrorResponse -> ErrorResponse -> Bool
== :: ErrorResponse -> ErrorResponse -> Bool
$c/= :: ErrorResponse -> ErrorResponse -> Bool
/= :: ErrorResponse -> ErrorResponse -> Bool
Eq, Int -> ErrorResponse -> ShowS
[ErrorResponse] -> ShowS
ErrorResponse -> String
(Int -> ErrorResponse -> ShowS)
-> (ErrorResponse -> String)
-> ([ErrorResponse] -> ShowS)
-> Show ErrorResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ErrorResponse -> ShowS
showsPrec :: Int -> ErrorResponse -> ShowS
$cshow :: ErrorResponse -> String
show :: ErrorResponse -> String
$cshowList :: [ErrorResponse] -> ShowS
showList :: [ErrorResponse] -> ShowS
Show)
data ErrorBody = ErrorBody
{ ErrorBody -> Maybe Text
errMessage :: Maybe Text
, ErrorBody -> Maybe Text
errError :: Maybe Text
}
deriving stock (ErrorBody -> ErrorBody -> Bool
(ErrorBody -> ErrorBody -> Bool)
-> (ErrorBody -> ErrorBody -> Bool) -> Eq ErrorBody
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ErrorBody -> ErrorBody -> Bool
== :: ErrorBody -> ErrorBody -> Bool
$c/= :: ErrorBody -> ErrorBody -> Bool
/= :: ErrorBody -> ErrorBody -> Bool
Eq, Int -> ErrorBody -> ShowS
[ErrorBody] -> ShowS
ErrorBody -> String
(Int -> ErrorBody -> ShowS)
-> (ErrorBody -> String)
-> ([ErrorBody] -> ShowS)
-> Show ErrorBody
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ErrorBody -> ShowS
showsPrec :: Int -> ErrorBody -> ShowS
$cshow :: ErrorBody -> String
show :: ErrorBody -> String
$cshowList :: [ErrorBody] -> ShowS
showList :: [ErrorBody] -> ShowS
Show)
instance FromJSON ErrorResponse where
parseJSON :: Value -> Parser ErrorResponse
parseJSON = \case
String Text
msg -> ErrorResponse -> Parser ErrorResponse
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> ErrorResponse
ErrorString Text
msg)
Object Object
o ->
(ErrorBody -> ErrorResponse)
-> Parser ErrorBody -> Parser ErrorResponse
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ErrorBody -> ErrorResponse
ErrorObject (Parser ErrorBody -> Parser ErrorResponse)
-> Parser ErrorBody -> Parser ErrorResponse
forall a b. (a -> b) -> a -> b
$
Maybe Text -> Maybe Text -> ErrorBody
ErrorBody
(Maybe Text -> Maybe Text -> ErrorBody)
-> Parser (Maybe Text) -> Parser (Maybe Text -> ErrorBody)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"message"
Parser (Maybe Text -> ErrorBody)
-> Parser (Maybe Text) -> Parser ErrorBody
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"error"
Value
other -> String -> Value -> Parser ErrorResponse
forall a. String -> Value -> Parser a
typeMismatchOneOf String
"ErrorResponse (object or string)" Value
other
errorMessage :: ErrorResponse -> Maybe Text
errorMessage :: ErrorResponse -> Maybe Text
errorMessage = \case
ErrorString Text
msg -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
msg
ErrorObject ErrorBody
body -> ErrorBody -> Maybe Text
errMessage ErrorBody
body Maybe Text -> Maybe Text -> Maybe Text
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ErrorBody -> Maybe Text
errError ErrorBody
body
typeMismatchOneOf :: String -> Value -> Parser a
typeMismatchOneOf :: forall a. String -> Value -> Parser a
typeMismatchOneOf String
expected Value
actual =
String -> Parser a
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"expected " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
expected String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
", but encountered " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Value -> String
valueKind Value
actual)
valueKind :: Value -> String
valueKind :: Value -> String
valueKind = \case
Object{} -> String
"an object"
String{} -> String
"a string"
Array{} -> String
"an array"
Number{} -> String
"a number"
Bool{} -> String
"a boolean"
Value
Null -> String
"null"