module Ecluse.Core.Registry.Npm.Wire (
Person (..),
personFromFields,
License (..),
licenseFromFields,
Dist (..),
distFields,
distFromFields,
VersionManifest (..),
availability,
) where
import Data.Aeson (
FromJSON (parseJSON),
Value (Bool, Object, String),
withObject,
(.!=),
(.:),
(.:?),
)
import Ecluse.Core.Json.Lenient (lenientOptional, typeMismatchOneOf)
import Ecluse.Core.Package (Availability (Available, Deprecated))
import Ecluse.Core.Registry.Npm.DependencySource (ExternalDependency, externalDependencyOf)
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 ->
Parser (Maybe Text)
-> Parser (Maybe Text) -> Parser (Maybe Text) -> Parser Person
forall (f :: * -> *).
Applicative f =>
f (Maybe Text) -> f (Maybe Text) -> f (Maybe Text) -> f Person
personFromFields (Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"name") (Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"email") (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
personFromFields :: (Applicative f) => f (Maybe Text) -> f (Maybe Text) -> f (Maybe Text) -> f Person
personFromFields :: forall (f :: * -> *).
Applicative f =>
f (Maybe Text) -> f (Maybe Text) -> f (Maybe Text) -> f Person
personFromFields f (Maybe Text)
name f (Maybe Text)
email f (Maybe Text)
url = Text -> Maybe Text -> Maybe Text -> Person
Person (Text -> Maybe Text -> Maybe Text -> Person)
-> (Maybe Text -> Text)
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Person
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" (Maybe Text -> Maybe Text -> Maybe Text -> Person)
-> f (Maybe Text) -> f (Maybe Text -> Maybe Text -> Person)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (Maybe Text)
name f (Maybe Text -> Maybe Text -> Person)
-> f (Maybe Text) -> f (Maybe Text -> Person)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (Maybe Text)
email f (Maybe Text -> Person) -> f (Maybe Text) -> f Person
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (Maybe Text)
url
{-# INLINE personFromFields #-}
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 ->
Parser (Maybe Text) -> Parser (Maybe Text) -> Parser License
forall (f :: * -> *).
Applicative f =>
f (Maybe Text) -> f (Maybe Text) -> f License
licenseFromFields (Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"type") (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
licenseFromFields :: (Applicative f) => f (Maybe Text) -> f (Maybe Text) -> f License
licenseFromFields :: forall (f :: * -> *).
Applicative f =>
f (Maybe Text) -> f (Maybe Text) -> f License
licenseFromFields f (Maybe Text)
kind f (Maybe Text)
url = Text -> Maybe Text -> License
LicenseObject (Text -> Maybe Text -> License)
-> (Maybe Text -> Text) -> Maybe Text -> Maybe Text -> License
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" (Maybe Text -> Maybe Text -> License)
-> f (Maybe Text) -> f (Maybe Text -> License)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (Maybe Text)
kind f (Maybe Text -> License) -> f (Maybe Text) -> f License
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (Maybe Text)
url
{-# INLINE licenseFromFields #-}
data Dist = Dist
{ Dist -> Text
distTarball :: Text
, Dist -> Maybe Text
distShasum :: Maybe Text
, Dist -> Maybe Text
distIntegrity :: Maybe Text
, Dist -> Maybe Int
distUnpackedSize :: Maybe Int
}
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)
distFields :: [Text]
distFields :: [Text]
distFields = [Text
"tarball", Text
"shasum", Text
"integrity", Text
"unpackedSize"]
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 ->
Parser Text
-> Parser (Maybe Text)
-> Parser (Maybe Text)
-> Parser (Maybe Int)
-> Parser Dist
forall (f :: * -> *).
Applicative f =>
f Text
-> f (Maybe Text) -> f (Maybe Text) -> f (Maybe Int) -> f Dist
distFromFields (Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"tarball") (Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"shasum") (Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"integrity") (Object -> Key -> Parser (Maybe Int)
forall a.
(FromJSON a, NFData a) =>
Object -> Key -> Parser (Maybe a)
lenientOptional Object
o Key
"unpackedSize")
distFromFields :: (Applicative f) => f Text -> f (Maybe Text) -> f (Maybe Text) -> f (Maybe Int) -> f Dist
distFromFields :: forall (f :: * -> *).
Applicative f =>
f Text
-> f (Maybe Text) -> f (Maybe Text) -> f (Maybe Int) -> f Dist
distFromFields f Text
tarball f (Maybe Text)
shasum f (Maybe Text)
integrity f (Maybe Int)
size = Text -> Maybe Text -> Maybe Text -> Maybe Int -> Dist
Dist (Text -> Maybe Text -> Maybe Text -> Maybe Int -> Dist)
-> f Text -> f (Maybe Text -> Maybe Text -> Maybe Int -> Dist)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f Text
tarball f (Maybe Text -> Maybe Text -> Maybe Int -> Dist)
-> f (Maybe Text) -> f (Maybe Text -> Maybe Int -> Dist)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (Maybe Text)
shasum f (Maybe Text -> Maybe Int -> Dist)
-> f (Maybe Text) -> f (Maybe Int -> Dist)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (Maybe Text)
integrity f (Maybe Int -> Dist) -> f (Maybe Int) -> f Dist
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (Maybe Int)
size
{-# INLINE distFromFields #-}
data VersionManifest = VersionManifest
{ VersionManifest -> Text
vmName :: Text
, VersionManifest -> Text
vmVersion :: Text
, VersionManifest -> Dist
vmDist :: Dist
, VersionManifest -> Availability
vmAvailability :: Availability
, VersionManifest -> Maybe Bool
vmHasInstallScript :: Maybe Bool
, VersionManifest -> Map Text Text
vmScripts :: Map Text Text
, VersionManifest -> Maybe License
vmLicense :: Maybe License
, VersionManifest -> Maybe ExternalDependency
vmExternalDependency :: Maybe ExternalDependency
}
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
-> Availability
-> Maybe Bool
-> Map Text Text
-> Maybe License
-> Maybe ExternalDependency
-> VersionManifest
VersionManifest
(Text
-> Text
-> Dist
-> Availability
-> Maybe Bool
-> Map Text Text
-> Maybe License
-> Maybe ExternalDependency
-> VersionManifest)
-> Parser Text
-> Parser
(Text
-> Dist
-> Availability
-> Maybe Bool
-> Map Text Text
-> Maybe License
-> Maybe ExternalDependency
-> 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
-> Availability
-> Maybe Bool
-> Map Text Text
-> Maybe License
-> Maybe ExternalDependency
-> VersionManifest)
-> Parser Text
-> Parser
(Dist
-> Availability
-> Maybe Bool
-> Map Text Text
-> Maybe License
-> Maybe ExternalDependency
-> 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
-> Availability
-> Maybe Bool
-> Map Text Text
-> Maybe License
-> Maybe ExternalDependency
-> VersionManifest)
-> Parser Dist
-> Parser
(Availability
-> Maybe Bool
-> Map Text Text
-> Maybe License
-> Maybe ExternalDependency
-> 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
(Availability
-> Maybe Bool
-> Map Text Text
-> Maybe License
-> Maybe ExternalDependency
-> VersionManifest)
-> Parser Availability
-> Parser
(Maybe Bool
-> Map Text Text
-> Maybe License
-> Maybe ExternalDependency
-> 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 -> Availability
availability (Maybe Value -> Availability)
-> Parser (Maybe Value) -> Parser Availability
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
-> Maybe ExternalDependency
-> VersionManifest)
-> Parser (Maybe Bool)
-> Parser
(Map Text Text
-> Maybe License -> Maybe ExternalDependency -> 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 -> Maybe ExternalDependency -> VersionManifest)
-> Parser (Map Text Text)
-> Parser
(Maybe License -> Maybe ExternalDependency -> 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 -> Maybe ExternalDependency -> VersionManifest)
-> Parser (Maybe License)
-> Parser (Maybe ExternalDependency -> 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"
Parser (Maybe ExternalDependency -> VersionManifest)
-> Parser (Maybe ExternalDependency) -> 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
<*> Maybe ExternalDependency -> Parser (Maybe ExternalDependency)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Object -> Maybe ExternalDependency
externalDependencyOf Object
o)
availability :: Maybe Value -> Availability
availability :: Maybe Value -> Availability
availability = \case
Just (String Text
"") -> Availability
Available
Just (String Text
_) -> Availability
Deprecated
Just (Bool Bool
True) -> Availability
Deprecated
Maybe Value
_ -> Availability
Available