pcmt/config.dhall

92 lines
2.3 KiB
Haskell
Raw Normal View History

-- convenience funcs for validation.
let Prelude =
https://prelude.dhall-lang.org/v20.2.0/package.dhall
sha256:a6036bc38d883450598d1de7c98ead113196fe2db02e9733855668b18096f07b
let NuConfig =
-- | define a configuration schema.
{ Type =
{ Port : Natural
, AppName : Text
, LiveMode : Bool
, DevelMode : Bool
, LoginCookieName : Optional Text
}
, default =
{ Port = 3000
, AppName = "pcmt"
, LiveMode = False
, DevelMode = False
, LoginCookieName = None Text
}
}
let NuConfig/validate
: NuConfig.Type -> Type
=
-- | define validation.
\(c : NuConfig.Type) ->
let expected = { validPort = True }
let actual =
{ validPort =
-- | make sure port number belongs to the <1;65565> range.
Prelude.Natural.lessThanEqual 1 c.Port
&& Prelude.Natural.lessThanEqual c.Port 65565
}
in expected === actual
let nuconf = NuConfig::{ LiveMode = True, DevelMode = True }
let _ =
-- | validate the configuration.
assert : NuConfig/validate nuconf
let Config =
-- | define configuration schema.
{ Port : Natural
, AppName : Text
, LiveMode : Bool
, DevelMode : Bool
, LoginCookieName : Optional Text
}
let defconf
-- | a full default configuration.
-- | TODO: have this reside on the Internet and import it similar to how
-- | the Dhall Prelude is imported.
: Config
= { Port = 3000
, AppName = "pcmt"
, LiveMode = False
, DevelMode = False
, LoginCookieName = None Text
}
let conf
: Config
= defconf // { LiveMode = True, DevelMode = False }
let Config/validate
: Config -> Type
=
-- | define validation.
\(config : Config) ->
let expected = { validPort = True }
let actual =
{ validPort =
-- | make sure port number belongs to the <1;65565> range.
Prelude.Natural.lessThanEqual 1 config.Port
&& Prelude.Natural.lessThanEqual config.Port 65565
}
in expected === actual
let _ =
-- | validate the configuration.
assert : Config/validate conf
in nuconf