{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

module Cardano.Chain.Update.ApplicationName
  ( ApplicationName (..),
    applicationNameMaxLength,
    ApplicationNameError (..),
    checkApplicationName,
  )
where

import Cardano.Binary
  ( Case (..),
    Decoder,
    DecoderError (..),
    FromCBOR (..),
    ToCBOR (..),
    decodeListLen,
    decodeWord8,
    encodeListLen,
    matchSize,
    szCases,
  )
import Cardano.Prelude
import Data.Aeson (ToJSON)
import Data.Data (Data)
import qualified Data.Text as T
import Formatting (bprint, int, stext)
import qualified Formatting.Buildable as B
import NoThunks.Class (NoThunks (..))

newtype ApplicationName = ApplicationName
  { ApplicationName -> Text
unApplicationName :: Text
  }
  deriving (ApplicationName -> ApplicationName -> Bool
(ApplicationName -> ApplicationName -> Bool)
-> (ApplicationName -> ApplicationName -> Bool)
-> Eq ApplicationName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ApplicationName -> ApplicationName -> Bool
$c/= :: ApplicationName -> ApplicationName -> Bool
== :: ApplicationName -> ApplicationName -> Bool
$c== :: ApplicationName -> ApplicationName -> Bool
Eq, Eq ApplicationName
Eq ApplicationName
-> (ApplicationName -> ApplicationName -> Ordering)
-> (ApplicationName -> ApplicationName -> Bool)
-> (ApplicationName -> ApplicationName -> Bool)
-> (ApplicationName -> ApplicationName -> Bool)
-> (ApplicationName -> ApplicationName -> Bool)
-> (ApplicationName -> ApplicationName -> ApplicationName)
-> (ApplicationName -> ApplicationName -> ApplicationName)
-> Ord ApplicationName
ApplicationName -> ApplicationName -> Bool
ApplicationName -> ApplicationName -> Ordering
ApplicationName -> ApplicationName -> ApplicationName
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
min :: ApplicationName -> ApplicationName -> ApplicationName
$cmin :: ApplicationName -> ApplicationName -> ApplicationName
max :: ApplicationName -> ApplicationName -> ApplicationName
$cmax :: ApplicationName -> ApplicationName -> ApplicationName
>= :: ApplicationName -> ApplicationName -> Bool
$c>= :: ApplicationName -> ApplicationName -> Bool
> :: ApplicationName -> ApplicationName -> Bool
$c> :: ApplicationName -> ApplicationName -> Bool
<= :: ApplicationName -> ApplicationName -> Bool
$c<= :: ApplicationName -> ApplicationName -> Bool
< :: ApplicationName -> ApplicationName -> Bool
$c< :: ApplicationName -> ApplicationName -> Bool
compare :: ApplicationName -> ApplicationName -> Ordering
$ccompare :: ApplicationName -> ApplicationName -> Ordering
$cp1Ord :: Eq ApplicationName
Ord, Int -> ApplicationName -> ShowS
[ApplicationName] -> ShowS
ApplicationName -> String
(Int -> ApplicationName -> ShowS)
-> (ApplicationName -> String)
-> ([ApplicationName] -> ShowS)
-> Show ApplicationName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApplicationName] -> ShowS
$cshowList :: [ApplicationName] -> ShowS
show :: ApplicationName -> String
$cshow :: ApplicationName -> String
showsPrec :: Int -> ApplicationName -> ShowS
$cshowsPrec :: Int -> ApplicationName -> ShowS
Show, (forall x. ApplicationName -> Rep ApplicationName x)
-> (forall x. Rep ApplicationName x -> ApplicationName)
-> Generic ApplicationName
forall x. Rep ApplicationName x -> ApplicationName
forall x. ApplicationName -> Rep ApplicationName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ApplicationName x -> ApplicationName
$cfrom :: forall x. ApplicationName -> Rep ApplicationName x
Generic, ApplicationName -> Builder
(ApplicationName -> Builder) -> Buildable ApplicationName
forall p. (p -> Builder) -> Buildable p
build :: ApplicationName -> Builder
$cbuild :: ApplicationName -> Builder
B.Buildable, ApplicationName -> ()
(ApplicationName -> ()) -> NFData ApplicationName
forall a. (a -> ()) -> NFData a
rnf :: ApplicationName -> ()
$crnf :: ApplicationName -> ()
NFData, Context -> ApplicationName -> IO (Maybe ThunkInfo)
Proxy ApplicationName -> String
(Context -> ApplicationName -> IO (Maybe ThunkInfo))
-> (Context -> ApplicationName -> IO (Maybe ThunkInfo))
-> (Proxy ApplicationName -> String)
-> NoThunks ApplicationName
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy ApplicationName -> String
$cshowTypeOf :: Proxy ApplicationName -> String
wNoThunks :: Context -> ApplicationName -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> ApplicationName -> IO (Maybe ThunkInfo)
noThunks :: Context -> ApplicationName -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> ApplicationName -> IO (Maybe ThunkInfo)
NoThunks)

instance ToCBOR ApplicationName where
  toCBOR :: ApplicationName -> Encoding
toCBOR ApplicationName
appName = Text -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (ApplicationName -> Text
unApplicationName ApplicationName
appName)
  encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy ApplicationName -> Size
encodedSizeExpr forall t. ToCBOR t => Proxy t -> Size
_ Proxy ApplicationName
_ =
    Size
1
      Size -> Size -> Size
forall a. Num a => a -> a -> a
+ [Case Size] -> Size
szCases
        [ Text -> Size -> Case Size
forall t. Text -> t -> Case t
Case Text
"minBound" Size
0,
          Text -> Size -> Case Size
forall t. Text -> t -> Case t
Case Text
"maxBound" (Integer -> Size
forall a. Num a => Integer -> a
fromInteger Integer
forall i. Integral i => i
applicationNameMaxLength)
        ]

instance FromCBOR ApplicationName where
  fromCBOR :: Decoder s ApplicationName
fromCBOR = Text -> ApplicationName
ApplicationName (Text -> ApplicationName)
-> Decoder s Text -> Decoder s ApplicationName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Text
forall a s. FromCBOR a => Decoder s a
fromCBOR

data ApplicationNameError
  = ApplicationNameTooLong Text
  | ApplicationNameNotAscii Text
  deriving (Typeable ApplicationNameError
DataType
Constr
Typeable ApplicationNameError
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> ApplicationNameError
    -> c ApplicationNameError)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ApplicationNameError)
-> (ApplicationNameError -> Constr)
-> (ApplicationNameError -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ApplicationNameError))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ApplicationNameError))
-> ((forall b. Data b => b -> b)
    -> ApplicationNameError -> ApplicationNameError)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ApplicationNameError -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ApplicationNameError -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> ApplicationNameError -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ApplicationNameError -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> ApplicationNameError -> m ApplicationNameError)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> ApplicationNameError -> m ApplicationNameError)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> ApplicationNameError -> m ApplicationNameError)
-> Data ApplicationNameError
ApplicationNameError -> DataType
ApplicationNameError -> Constr
(forall b. Data b => b -> b)
-> ApplicationNameError -> ApplicationNameError
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ApplicationNameError
-> c ApplicationNameError
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ApplicationNameError
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> ApplicationNameError -> u
forall u.
(forall d. Data d => d -> u) -> ApplicationNameError -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ApplicationNameError -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ApplicationNameError -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ApplicationNameError -> m ApplicationNameError
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ApplicationNameError -> m ApplicationNameError
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ApplicationNameError
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ApplicationNameError
-> c ApplicationNameError
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ApplicationNameError)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ApplicationNameError)
$cApplicationNameNotAscii :: Constr
$cApplicationNameTooLong :: Constr
$tApplicationNameError :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> ApplicationNameError -> m ApplicationNameError
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ApplicationNameError -> m ApplicationNameError
gmapMp :: (forall d. Data d => d -> m d)
-> ApplicationNameError -> m ApplicationNameError
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ApplicationNameError -> m ApplicationNameError
gmapM :: (forall d. Data d => d -> m d)
-> ApplicationNameError -> m ApplicationNameError
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ApplicationNameError -> m ApplicationNameError
gmapQi :: Int -> (forall d. Data d => d -> u) -> ApplicationNameError -> u
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> ApplicationNameError -> u
gmapQ :: (forall d. Data d => d -> u) -> ApplicationNameError -> [u]
$cgmapQ :: forall u.
(forall d. Data d => d -> u) -> ApplicationNameError -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ApplicationNameError -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ApplicationNameError -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ApplicationNameError -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ApplicationNameError -> r
gmapT :: (forall b. Data b => b -> b)
-> ApplicationNameError -> ApplicationNameError
$cgmapT :: (forall b. Data b => b -> b)
-> ApplicationNameError -> ApplicationNameError
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ApplicationNameError)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ApplicationNameError)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c ApplicationNameError)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ApplicationNameError)
dataTypeOf :: ApplicationNameError -> DataType
$cdataTypeOf :: ApplicationNameError -> DataType
toConstr :: ApplicationNameError -> Constr
$ctoConstr :: ApplicationNameError -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ApplicationNameError
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ApplicationNameError
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ApplicationNameError
-> c ApplicationNameError
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ApplicationNameError
-> c ApplicationNameError
$cp1Data :: Typeable ApplicationNameError
Data, ApplicationNameError -> ApplicationNameError -> Bool
(ApplicationNameError -> ApplicationNameError -> Bool)
-> (ApplicationNameError -> ApplicationNameError -> Bool)
-> Eq ApplicationNameError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ApplicationNameError -> ApplicationNameError -> Bool
$c/= :: ApplicationNameError -> ApplicationNameError -> Bool
== :: ApplicationNameError -> ApplicationNameError -> Bool
$c== :: ApplicationNameError -> ApplicationNameError -> Bool
Eq, Int -> ApplicationNameError -> ShowS
[ApplicationNameError] -> ShowS
ApplicationNameError -> String
(Int -> ApplicationNameError -> ShowS)
-> (ApplicationNameError -> String)
-> ([ApplicationNameError] -> ShowS)
-> Show ApplicationNameError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApplicationNameError] -> ShowS
$cshowList :: [ApplicationNameError] -> ShowS
show :: ApplicationNameError -> String
$cshow :: ApplicationNameError -> String
showsPrec :: Int -> ApplicationNameError -> ShowS
$cshowsPrec :: Int -> ApplicationNameError -> ShowS
Show)

-- Used for debugging purposes only
instance ToJSON ApplicationName

instance ToCBOR ApplicationNameError where
  toCBOR :: ApplicationNameError -> Encoding
toCBOR ApplicationNameError
err = case ApplicationNameError
err of
    ApplicationNameTooLong Text
appName ->
      Word -> Encoding
encodeListLen Word
2
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word8 -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Word8
0 :: Word8)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Text -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Text
appName
    ApplicationNameNotAscii Text
appName ->
      Word -> Encoding
encodeListLen Word
2
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word8 -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Word8
1 :: Word8)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Text -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Text
appName

instance FromCBOR ApplicationNameError where
  fromCBOR :: Decoder s ApplicationNameError
fromCBOR = do
    Int
len <- Decoder s Int
forall s. Decoder s Int
decodeListLen
    let checkSize :: Int -> Decoder s ()
        checkSize :: Int -> Decoder s ()
checkSize Int
size = Text -> Int -> Int -> Decoder s ()
forall s. Text -> Int -> Int -> Decoder s ()
matchSize Text
"ApplicationNameError" Int
size Int
len
    Word8
tag <- Decoder s Word8
forall s. Decoder s Word8
decodeWord8
    case Word8
tag of
      Word8
0 -> Int -> Decoder s ()
forall s. Int -> Decoder s ()
checkSize Int
2 Decoder s ()
-> Decoder s ApplicationNameError -> Decoder s ApplicationNameError
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Text -> ApplicationNameError
ApplicationNameTooLong (Text -> ApplicationNameError)
-> Decoder s Text -> Decoder s ApplicationNameError
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Text
forall a s. FromCBOR a => Decoder s a
fromCBOR
      Word8
1 -> Int -> Decoder s ()
forall s. Int -> Decoder s ()
checkSize Int
2 Decoder s ()
-> Decoder s ApplicationNameError -> Decoder s ApplicationNameError
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Text -> ApplicationNameError
ApplicationNameNotAscii (Text -> ApplicationNameError)
-> Decoder s Text -> Decoder s ApplicationNameError
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Text
forall a s. FromCBOR a => Decoder s a
fromCBOR
      Word8
_ -> DecoderError -> Decoder s ApplicationNameError
forall e s a. Buildable e => e -> Decoder s a
cborError (DecoderError -> Decoder s ApplicationNameError)
-> DecoderError -> Decoder s ApplicationNameError
forall a b. (a -> b) -> a -> b
$ Text -> Word8 -> DecoderError
DecoderErrorUnknownTag Text
"ApplicationNameError" Word8
tag

instance B.Buildable ApplicationNameError where
  build :: ApplicationNameError -> Builder
build = \case
    ApplicationNameTooLong Text
name ->
      Format Builder (Text -> Int -> Builder) -> Text -> Int -> Builder
forall a. Format Builder a -> a
bprint
        (Format (Text -> Int -> Builder) (Text -> Int -> Builder)
"ApplicationName, " Format (Text -> Int -> Builder) (Text -> Int -> Builder)
-> Format Builder (Text -> Int -> Builder)
-> Format Builder (Text -> Int -> Builder)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format (Int -> Builder) (Text -> Int -> Builder)
forall r. Format r (Text -> r)
stext Format (Int -> Builder) (Text -> Int -> Builder)
-> Format Builder (Int -> Builder)
-> Format Builder (Text -> Int -> Builder)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format (Int -> Builder) (Int -> Builder)
", exceeds limit of " Format (Int -> Builder) (Int -> Builder)
-> Format Builder (Int -> Builder)
-> Format Builder (Int -> Builder)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format Builder (Int -> Builder)
forall a r. Integral a => Format r (a -> r)
int)
        Text
name
        (Int
forall i. Integral i => i
applicationNameMaxLength :: Int)
    ApplicationNameNotAscii Text
name ->
      Format Builder (Text -> Builder) -> Text -> Builder
forall a. Format Builder a -> a
bprint
        (Format (Text -> Builder) (Text -> Builder)
"ApplicationName, " Format (Text -> Builder) (Text -> Builder)
-> Format Builder (Text -> Builder)
-> Format Builder (Text -> Builder)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format Builder (Text -> Builder)
forall r. Format r (Text -> r)
stext Format Builder (Text -> Builder)
-> Format Builder Builder -> Format Builder (Text -> Builder)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format Builder Builder
", contains non-ascii characters")
        Text
name

-- | Smart constructor of 'ApplicationName'
checkApplicationName ::
  MonadError ApplicationNameError m => ApplicationName -> m ()
checkApplicationName :: ApplicationName -> m ()
checkApplicationName (ApplicationName Text
appName)
  | Text -> Int
T.length Text
appName Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
forall i. Integral i => i
applicationNameMaxLength =
      ApplicationNameError -> m ()
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (ApplicationNameError -> m ()) -> ApplicationNameError -> m ()
forall a b. (a -> b) -> a -> b
$
        Text -> ApplicationNameError
ApplicationNameTooLong Text
appName
  | (Char -> Bool) -> Text -> Bool
T.any (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Char -> Bool
isAscii) Text
appName = ApplicationNameError -> m ()
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (ApplicationNameError -> m ()) -> ApplicationNameError -> m ()
forall a b. (a -> b) -> a -> b
$ Text -> ApplicationNameError
ApplicationNameNotAscii Text
appName
  | Bool
otherwise = () -> m ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()

applicationNameMaxLength :: Integral i => i
applicationNameMaxLength :: i
applicationNameMaxLength = i
12