{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
module Web.ArchLinux.Types
(
Repo (..),
Arch (..),
License (..),
licenseId,
parseLicense,
PackageInformation (..),
PackageFiles (..),
Flagged (..),
ArchLinuxResponse (..),
AurSearch (..),
AurInfo (..),
AurResponseType (..),
AurResponse (..),
)
where
import Data.Aeson
import Data.Char (toUpper)
import Data.Maybe (fromJust, fromMaybe)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Time (UTCTime)
import Deriving.Aeson
import Servant.API (ToHttpApiData (..))
import Web.ArchLinux.Internal.KnownSPDXLoader
type ArchLinuxJSON = CustomJSON '[FieldLabelModifier (StripPrefix "_", CamelToSnake)]
unString :: Value -> Text
unString :: Value -> Text
unString (String Text
x) = Text
x
unString Value
_ = Text
forall a. HasCallStack => a
undefined
toQueryParamViaJSON :: (ToJSON a) => a -> Text
toQueryParamViaJSON :: forall a. ToJSON a => a -> Text
toQueryParamViaJSON = Value -> Text
unString (Value -> Text) -> (a -> Value) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Value -> Value
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Value -> Value) -> (a -> Maybe Value) -> a -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Maybe Value
forall a. FromJSON a => ByteString -> Maybe a
decode (ByteString -> Maybe Value)
-> (a -> ByteString) -> a -> Maybe Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ByteString
forall a. ToJSON a => a -> ByteString
encode
data AurModifier
instance StringModifier AurModifier where
getStringModifier :: String -> String
getStringModifier (String -> Text
T.pack -> Text
t) = Text -> String
T.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Text -> Text
eat Text
"Url" Text
"URL" (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Text -> Text
eat Text
"Id" Text
"ID" Text
upper
where
upper :: Text
upper =
case Text -> Maybe (Char, Text)
T.uncons Text
t of
Just (Char
h, Text
s) -> Char -> Text -> Text
T.cons (Char -> Char
toUpper Char
h) Text
s
Maybe (Char, Text)
_ -> String -> Text
forall a. HasCallStack => String -> a
error String
"impossible"
eat :: Text -> Text -> Text -> Text
eat Text
prefix Text
to Text
input = case Text -> Text -> Maybe Text
T.stripPrefix Text
prefix Text
input of
Just Text
x -> Text
to Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
x
Maybe Text
_ -> Text
input
type AurJSON = CustomJSON '[FieldLabelModifier (StripPrefix "_", AurModifier)]
data Repo
= Core
| CoreTesting
|
|
| Multilib
| MultilibTesting
| GnomeUnstable
| KDEUnstable
deriving stock (Int -> Repo -> String -> String
[Repo] -> String -> String
Repo -> String
(Int -> Repo -> String -> String)
-> (Repo -> String) -> ([Repo] -> String -> String) -> Show Repo
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> Repo -> String -> String
showsPrec :: Int -> Repo -> String -> String
$cshow :: Repo -> String
show :: Repo -> String
$cshowList :: [Repo] -> String -> String
showList :: [Repo] -> String -> String
Show, Repo -> Repo -> Bool
(Repo -> Repo -> Bool) -> (Repo -> Repo -> Bool) -> Eq Repo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Repo -> Repo -> Bool
== :: Repo -> Repo -> Bool
$c/= :: Repo -> Repo -> Bool
/= :: Repo -> Repo -> Bool
Eq, Eq Repo
Eq Repo =>
(Repo -> Repo -> Ordering)
-> (Repo -> Repo -> Bool)
-> (Repo -> Repo -> Bool)
-> (Repo -> Repo -> Bool)
-> (Repo -> Repo -> Bool)
-> (Repo -> Repo -> Repo)
-> (Repo -> Repo -> Repo)
-> Ord Repo
Repo -> Repo -> Bool
Repo -> Repo -> Ordering
Repo -> Repo -> Repo
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 :: Repo -> Repo -> Ordering
compare :: Repo -> Repo -> Ordering
$c< :: Repo -> Repo -> Bool
< :: Repo -> Repo -> Bool
$c<= :: Repo -> Repo -> Bool
<= :: Repo -> Repo -> Bool
$c> :: Repo -> Repo -> Bool
> :: Repo -> Repo -> Bool
$c>= :: Repo -> Repo -> Bool
>= :: Repo -> Repo -> Bool
$cmax :: Repo -> Repo -> Repo
max :: Repo -> Repo -> Repo
$cmin :: Repo -> Repo -> Repo
min :: Repo -> Repo -> Repo
Ord, Int -> Repo
Repo -> Int
Repo -> [Repo]
Repo -> Repo
Repo -> Repo -> [Repo]
Repo -> Repo -> Repo -> [Repo]
(Repo -> Repo)
-> (Repo -> Repo)
-> (Int -> Repo)
-> (Repo -> Int)
-> (Repo -> [Repo])
-> (Repo -> Repo -> [Repo])
-> (Repo -> Repo -> [Repo])
-> (Repo -> Repo -> Repo -> [Repo])
-> Enum Repo
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Repo -> Repo
succ :: Repo -> Repo
$cpred :: Repo -> Repo
pred :: Repo -> Repo
$ctoEnum :: Int -> Repo
toEnum :: Int -> Repo
$cfromEnum :: Repo -> Int
fromEnum :: Repo -> Int
$cenumFrom :: Repo -> [Repo]
enumFrom :: Repo -> [Repo]
$cenumFromThen :: Repo -> Repo -> [Repo]
enumFromThen :: Repo -> Repo -> [Repo]
$cenumFromTo :: Repo -> Repo -> [Repo]
enumFromTo :: Repo -> Repo -> [Repo]
$cenumFromThenTo :: Repo -> Repo -> Repo -> [Repo]
enumFromThenTo :: Repo -> Repo -> Repo -> [Repo]
Enum, (forall x. Repo -> Rep Repo x)
-> (forall x. Rep Repo x -> Repo) -> Generic Repo
forall x. Rep Repo x -> Repo
forall x. Repo -> Rep Repo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Repo -> Rep Repo x
from :: forall x. Repo -> Rep Repo x
$cto :: forall x. Rep Repo x -> Repo
to :: forall x. Rep Repo x -> Repo
Generic)
deriving (Maybe Repo
Value -> Parser [Repo]
Value -> Parser Repo
(Value -> Parser Repo)
-> (Value -> Parser [Repo]) -> Maybe Repo -> FromJSON Repo
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Repo
parseJSON :: Value -> Parser Repo
$cparseJSONList :: Value -> Parser [Repo]
parseJSONList :: Value -> Parser [Repo]
$comittedField :: Maybe Repo
omittedField :: Maybe Repo
FromJSON, [Repo] -> Value
[Repo] -> Encoding
Repo -> Bool
Repo -> Value
Repo -> Encoding
(Repo -> Value)
-> (Repo -> Encoding)
-> ([Repo] -> Value)
-> ([Repo] -> Encoding)
-> (Repo -> Bool)
-> ToJSON Repo
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Repo -> Value
toJSON :: Repo -> Value
$ctoEncoding :: Repo -> Encoding
toEncoding :: Repo -> Encoding
$ctoJSONList :: [Repo] -> Value
toJSONList :: [Repo] -> Value
$ctoEncodingList :: [Repo] -> Encoding
toEncodingList :: [Repo] -> Encoding
$comitField :: Repo -> Bool
omitField :: Repo -> Bool
ToJSON) via CustomJSON '[ConstructorTagModifier CamelToKebab] Repo
instance ToHttpApiData Repo where
toQueryParam :: Repo -> Text
toQueryParam (Repo -> Text
forall a. ToJSON a => a -> Text
toQueryParamViaJSON -> Text
x) = case HasCallStack => Text -> Text -> (Text, Text)
Text -> Text -> (Text, Text)
T.breakOn Text
"-" Text
x of
(Text -> Maybe (Char, Text)
T.uncons -> Just (Char
h, Text
s), Text
"") -> Char -> Text -> Text
T.cons (Char -> Char
toUpper Char
h) Text
s
(Text -> Maybe (Char, Text)
T.uncons -> Just (Char
h1, Text
s1), Text -> Maybe (Char, Text)
T.uncons -> Just (Char
'-', Text -> Maybe (Char, Text)
T.uncons -> Just (Char
h2, Text
s2))) ->
Char -> Text -> Text
T.cons (Char -> Char
toUpper Char
h1) Text
s1 Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Char -> Text -> Text
T.cons (Char -> Char
toUpper Char
h2) Text
s2
(Text, Text)
_ -> Text
forall a. HasCallStack => a
undefined
data Arch
= Any
| I686
| X86_64
deriving stock (Int -> Arch -> String -> String
[Arch] -> String -> String
Arch -> String
(Int -> Arch -> String -> String)
-> (Arch -> String) -> ([Arch] -> String -> String) -> Show Arch
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> Arch -> String -> String
showsPrec :: Int -> Arch -> String -> String
$cshow :: Arch -> String
show :: Arch -> String
$cshowList :: [Arch] -> String -> String
showList :: [Arch] -> String -> String
Show, Arch -> Arch -> Bool
(Arch -> Arch -> Bool) -> (Arch -> Arch -> Bool) -> Eq Arch
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Arch -> Arch -> Bool
== :: Arch -> Arch -> Bool
$c/= :: Arch -> Arch -> Bool
/= :: Arch -> Arch -> Bool
Eq, Eq Arch
Eq Arch =>
(Arch -> Arch -> Ordering)
-> (Arch -> Arch -> Bool)
-> (Arch -> Arch -> Bool)
-> (Arch -> Arch -> Bool)
-> (Arch -> Arch -> Bool)
-> (Arch -> Arch -> Arch)
-> (Arch -> Arch -> Arch)
-> Ord Arch
Arch -> Arch -> Bool
Arch -> Arch -> Ordering
Arch -> Arch -> Arch
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 :: Arch -> Arch -> Ordering
compare :: Arch -> Arch -> Ordering
$c< :: Arch -> Arch -> Bool
< :: Arch -> Arch -> Bool
$c<= :: Arch -> Arch -> Bool
<= :: Arch -> Arch -> Bool
$c> :: Arch -> Arch -> Bool
> :: Arch -> Arch -> Bool
$c>= :: Arch -> Arch -> Bool
>= :: Arch -> Arch -> Bool
$cmax :: Arch -> Arch -> Arch
max :: Arch -> Arch -> Arch
$cmin :: Arch -> Arch -> Arch
min :: Arch -> Arch -> Arch
Ord, Int -> Arch
Arch -> Int
Arch -> [Arch]
Arch -> Arch
Arch -> Arch -> [Arch]
Arch -> Arch -> Arch -> [Arch]
(Arch -> Arch)
-> (Arch -> Arch)
-> (Int -> Arch)
-> (Arch -> Int)
-> (Arch -> [Arch])
-> (Arch -> Arch -> [Arch])
-> (Arch -> Arch -> [Arch])
-> (Arch -> Arch -> Arch -> [Arch])
-> Enum Arch
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Arch -> Arch
succ :: Arch -> Arch
$cpred :: Arch -> Arch
pred :: Arch -> Arch
$ctoEnum :: Int -> Arch
toEnum :: Int -> Arch
$cfromEnum :: Arch -> Int
fromEnum :: Arch -> Int
$cenumFrom :: Arch -> [Arch]
enumFrom :: Arch -> [Arch]
$cenumFromThen :: Arch -> Arch -> [Arch]
enumFromThen :: Arch -> Arch -> [Arch]
$cenumFromTo :: Arch -> Arch -> [Arch]
enumFromTo :: Arch -> Arch -> [Arch]
$cenumFromThenTo :: Arch -> Arch -> Arch -> [Arch]
enumFromThenTo :: Arch -> Arch -> Arch -> [Arch]
Enum, (forall x. Arch -> Rep Arch x)
-> (forall x. Rep Arch x -> Arch) -> Generic Arch
forall x. Rep Arch x -> Arch
forall x. Arch -> Rep Arch x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Arch -> Rep Arch x
from :: forall x. Arch -> Rep Arch x
$cto :: forall x. Rep Arch x -> Arch
to :: forall x. Rep Arch x -> Arch
Generic)
deriving (Maybe Arch
Value -> Parser [Arch]
Value -> Parser Arch
(Value -> Parser Arch)
-> (Value -> Parser [Arch]) -> Maybe Arch -> FromJSON Arch
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Arch
parseJSON :: Value -> Parser Arch
$cparseJSONList :: Value -> Parser [Arch]
parseJSONList :: Value -> Parser [Arch]
$comittedField :: Maybe Arch
omittedField :: Maybe Arch
FromJSON, [Arch] -> Value
[Arch] -> Encoding
Arch -> Bool
Arch -> Value
Arch -> Encoding
(Arch -> Value)
-> (Arch -> Encoding)
-> ([Arch] -> Value)
-> ([Arch] -> Encoding)
-> (Arch -> Bool)
-> ToJSON Arch
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Arch -> Value
toJSON :: Arch -> Value
$ctoEncoding :: Arch -> Encoding
toEncoding :: Arch -> Encoding
$ctoJSONList :: [Arch] -> Value
toJSONList :: [Arch] -> Value
$ctoEncodingList :: [Arch] -> Encoding
toEncodingList :: [Arch] -> Encoding
$comitField :: Arch -> Bool
omitField :: Arch -> Bool
ToJSON) via CustomJSON '[ConstructorTagModifier CamelToSnake] Arch
instance ToHttpApiData Arch where
toQueryParam :: Arch -> Text
toQueryParam = Arch -> Text
forall a. ToJSON a => a -> Text
toQueryParamViaJSON
$