module Hydra.Dsl.Annotations where
import Hydra.Core
import Hydra.Compute
import Hydra.Annotations
import Hydra.Tools.Formatting
import Hydra.Dsl.Terms as Terms
import qualified Hydra.Dsl.Types as Types
import qualified Data.Map as M
import qualified Data.Maybe as Y
key_deprecated :: Name
key_deprecated = String -> Name
Name String
"_deprecated"
key_maxLength :: Name
key_maxLength = String -> Name
Name String
"_maxLength"
key_minLength :: Name
key_minLength = String -> Name
Name String
"_minLength"
key_preserveFieldName :: Name
key_preserveFieldName = String -> Name
Name String
"_preserveFieldName"
annotateTerm :: Name -> Y.Maybe Term -> Term -> Term
annotateTerm :: Name -> Maybe Term -> Term -> Term
annotateTerm = Name -> Maybe Term -> Term -> Term
setTermAnnotation
annotateType :: Name -> Y.Maybe Term -> Type -> Type
annotateType :: Name -> Maybe Term -> Type -> Type
annotateType = Name -> Maybe Term -> Type -> Type
setTypeAnnotation
bounded :: Maybe Int -> Maybe Int -> Type -> Type
bounded :: Maybe Int -> Maybe Int -> Type -> Type
bounded Maybe Int
min Maybe Int
max = Type -> Type
annotMin (Type -> Type) -> (Type -> Type) -> Type -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> Type
annotMax
where
annotMax :: Type -> Type
annotMax Type
t = Type -> (Int -> Type) -> Maybe Int -> Type
forall b a. b -> (a -> b) -> Maybe a -> b
Y.maybe Type
t (Int -> Type -> Type
`setMaxLength` Type
t) Maybe Int
max
annotMin :: Type -> Type
annotMin Type
t = Type -> (Int -> Type) -> Maybe Int -> Type
forall b a. b -> (a -> b) -> Maybe a -> b
Y.maybe Type
t (Int -> Type -> Type
`setMinLength` Type
t) Maybe Int
max
boundedList :: Maybe Int -> Maybe Int -> Type -> Type
boundedList :: Maybe Int -> Maybe Int -> Type -> Type
boundedList Maybe Int
min Maybe Int
max Type
et = Maybe Int -> Maybe Int -> Type -> Type
bounded Maybe Int
min Maybe Int
max (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Type -> Type
Types.list Type
et
boundedSet :: Maybe Int -> Maybe Int -> Type -> Type
boundedSet :: Maybe Int -> Maybe Int -> Type -> Type
boundedSet Maybe Int
min Maybe Int
max Type
et = Maybe Int -> Maybe Int -> Type -> Type
bounded Maybe Int
min Maybe Int
max (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Type -> Type
Types.set Type
et
boundedString :: Maybe Int -> Maybe Int -> Type
boundedString :: Maybe Int -> Maybe Int -> Type
boundedString Maybe Int
min Maybe Int
max = Maybe Int -> Maybe Int -> Type -> Type
bounded Maybe Int
min Maybe Int
max Type
Types.string
deprecated :: Type -> Type
deprecated :: Type -> Type
deprecated = Name -> Maybe Term -> Type -> Type
setTypeAnnotation Name
key_deprecated (Term -> Maybe Term
forall a. a -> Maybe a
Just (Term -> Maybe Term) -> Term -> Maybe Term
forall a b. (a -> b) -> a -> b
$ Bool -> Term
Terms.boolean Bool
True)
doc :: String -> Type -> Type
doc :: String -> Type -> Type
doc String
s = Maybe String -> Type -> Type
setTypeDescription (String -> Maybe String
forall a. a -> Maybe a
Just String
s)
doc70 :: String -> Type -> Type
doc70 :: String -> Type -> Type
doc70 = String -> Type -> Type
doc (String -> Type -> Type)
-> (String -> String) -> String -> Type -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> String
wrapLine Int
70
doc80 :: String -> Type -> Type
doc80 :: String -> Type -> Type
doc80 = String -> Type -> Type
doc (String -> Type -> Type)
-> (String -> String) -> String -> Type -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> String
wrapLine Int
80
dataDoc :: String -> Term -> Term
dataDoc :: String -> Term -> Term
dataDoc String
s = Maybe String -> Term -> Term
setTermDescription (String -> Maybe String
forall a. a -> Maybe a
Just String
s)
minLengthList :: Int -> Type -> Type
minLengthList :: Int -> Type -> Type
minLengthList Int
len = Maybe Int -> Maybe Int -> Type -> Type
boundedList (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
len) Maybe Int
forall a. Maybe a
Nothing
nonemptyList :: Type -> Type
nonemptyList :: Type -> Type
nonemptyList = Int -> Type -> Type
minLengthList Int
1
note :: String -> Type -> Type
note :: String -> Type -> Type
note String
s = String -> Type -> Type
doc (String -> Type -> Type) -> String -> Type -> Type
forall a b. (a -> b) -> a -> b
$ String
"Note: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s
preserveFieldName :: Type -> Type
preserveFieldName :: Type -> Type
preserveFieldName = Name -> Maybe Term -> Type -> Type
setTypeAnnotation Name
key_preserveFieldName (Term -> Maybe Term
forall a. a -> Maybe a
Just (Term -> Maybe Term) -> Term -> Maybe Term
forall a b. (a -> b) -> a -> b
$ Bool -> Term
Terms.boolean Bool
True)
see :: String -> Type -> Type
see :: String -> Type -> Type
see String
s = String -> Type -> Type
doc (String -> Type -> Type) -> String -> Type -> Type
forall a b. (a -> b) -> a -> b
$ String
"See " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s
setMaxLength :: Int -> Type -> Type
setMaxLength :: Int -> Type -> Type
setMaxLength Int
m = Name -> Maybe Term -> Type -> Type
setTypeAnnotation Name
key_maxLength (Term -> Maybe Term
forall a. a -> Maybe a
Just (Term -> Maybe Term) -> Term -> Maybe Term
forall a b. (a -> b) -> a -> b
$ Int -> Term
Terms.int32 Int
m)
setMinLength :: Int -> Type -> Type
setMinLength :: Int -> Type -> Type
setMinLength Int
m = Name -> Maybe Term -> Type -> Type
setTypeAnnotation Name
key_minLength (Term -> Maybe Term
forall a. a -> Maybe a
Just (Term -> Maybe Term) -> Term -> Maybe Term
forall a b. (a -> b) -> a -> b
$ Int -> Term
Terms.int32 Int
m)
twoOrMoreList :: Type -> Type
twoOrMoreList :: Type -> Type
twoOrMoreList = Maybe Int -> Maybe Int -> Type -> Type
boundedList (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
2) Maybe Int
forall a. Maybe a
Nothing