dhall: create a package for config [skip ci]
This commit is contained in:
parent
0c835d0daf
commit
44025ccd36
12
config/schema/package.dhall
Normal file
12
config/schema/package.dhall
Normal file
@ -0,0 +1,12 @@
|
||||
{ Schema =
|
||||
./schema.dhall
|
||||
sha256:1e8d4a3e16af1fa5b9b602a62c59440b933652c04b695095651ee04194b97138
|
||||
? ./schema.dhall
|
||||
, Schema/validate =
|
||||
./validate.dhall
|
||||
sha256:eb0df6eb95180f502ec1fbdf62ba6010e2cfc82b3dfe75163fa686d98c31eb6b
|
||||
? ./validate.dhall
|
||||
, Prelude =
|
||||
./prelude.dhall
|
||||
sha256:a6036bc38d883450598d1de7c98ead113196fe2db02e9733855668b18096f07b
|
||||
}
|
8
config/schema/prelude.dhall
Normal file
8
config/schema/prelude.dhall
Normal file
@ -0,0 +1,8 @@
|
||||
{-
|
||||
the env env will only be resolved if this file is imported locally, i.e. for
|
||||
local development.
|
||||
for remote scenarios the env will fall back to the integrity-protected import.
|
||||
-}
|
||||
env:DHALL_PRELUDE
|
||||
? https://prelude.dhall-lang.org/v20.2.0/package.dhall
|
||||
sha256:a6036bc38d883450598d1de7c98ead113196fe2db02e9733855668b18096f07b
|
24
config/schema/schema.dhall
Normal file
24
config/schema/schema.dhall
Normal file
@ -0,0 +1,24 @@
|
||||
let Schema =
|
||||
-- | define a configuration schema.
|
||||
{ Type =
|
||||
{ Host : Text
|
||||
, Port : Natural
|
||||
, AppName : Text
|
||||
, LiveMode : Bool
|
||||
, DevelMode : Bool
|
||||
, SessionCookieName : Optional Text
|
||||
, SessionCookieSecret : Optional Text
|
||||
}
|
||||
, default =
|
||||
-- | have sane defaults.
|
||||
{ Host = ""
|
||||
, Port = 3000
|
||||
, AppName = "pcmt"
|
||||
, LiveMode = False
|
||||
, DevelMode = False
|
||||
, SessionCookieName = None Text
|
||||
, SessionCookieSecret = None Text
|
||||
}
|
||||
}
|
||||
|
||||
in Schema
|
27
config/schema/validate.dhall
Normal file
27
config/schema/validate.dhall
Normal file
@ -0,0 +1,27 @@
|
||||
let Prelude =
|
||||
{- this will have to get bumped when prelude is updated -}
|
||||
./prelude.dhall
|
||||
sha256:a6036bc38d883450598d1de7c98ead113196fe2db02e9733855668b18096f07b
|
||||
|
||||
let Schema =
|
||||
./schema.dhall
|
||||
sha256:1e8d4a3e16af1fa5b9b602a62c59440b933652c04b695095651ee04194b97138
|
||||
? ./schema.dhall
|
||||
|
||||
let Schema/validate
|
||||
: Schema.Type -> Type
|
||||
=
|
||||
-- | define validation.
|
||||
\(c : Schema.Type) ->
|
||||
let expected = { validPort = True }
|
||||
|
||||
let actual =
|
||||
{ validPort =
|
||||
-- | make sure port number belongs to the <1;65535> range.
|
||||
Prelude.Natural.lessThanEqual 1 c.Port
|
||||
&& Prelude.Natural.lessThanEqual c.Port 65535
|
||||
}
|
||||
|
||||
in expected === actual
|
||||
|
||||
in Schema/validate
|
Loading…
Reference in New Issue
Block a user