Env.Typed
- Package
- purescript-env
- Repository
- m-rinaldi/purescript-env
The typed half: the variables a program needs, named and typed once as a record, read from an environment in one go, with every missing or malformed one reported together.
type Variables = ( "PORT" :: Maybe Int, "DB_PATH" :: String )
Env.Typed.read (Proxy :: _ (Record Variables)) env
:: Either Errors { "PORT" :: Maybe Int, "DB_PATH" :: String }
#read Source
read :: forall r rl. RowToList r rl => ReadRecord rl r => Proxy (Record r) -> Object String -> Either Errors (Record r)The variables the record names, from an environment. Every field is a
variable: "PORT" :: Int has to be there and parse, "PORT" :: Maybe Int
may be missing but has to parse if it is there. A field of a type of your
own needs a ParseValue instance. All problems are reported together.
#Errors Source
type Errors = NonEmptyList EnvErrorWhat stopped a record from being read: for each variable, that it is
missing (EnvLookupError) or does not parse (EnvParseError), by name.
At least one, or the record would have been read.
#printErrors Source
printErrors :: Errors -> StringOne message naming every variable in question, for a log or a stderr line before exiting.
#ParseValue Source
class ParseValue ty whereHow a variable's text becomes a value of the field's type. Write an
instance for a type of your own. A Left is the reason the text does not
parse, and completes the sentence The variable "NAME" …: "is not an
integer", "is not one of console, resend", "is empty".
Members
parseValue :: String -> Either String ty
Instances
#ReadVariable Source
class ReadVariable ty whereLooks a variable up and parses it: a Maybe field may be missing, any
other has to be there. Exported because the compiler solves it where
read is called; there is nothing to write an instance of it for.
Members
Instances
(ParseValue a) => ReadVariable (Maybe a)(ParseValue a) => ReadVariable a
#ReadRecord Source
class ReadRecord :: RowList Type -> Row Type -> Constraintclass ReadRecord (rl :: RowList Type) (rout :: Row Type) | rl -> rout where
Builds the record field by field from the row's list, collecting the errors of every field instead of stopping at the first.
Members
Instances
(IsSymbol name, ReadVariable ty, ListToRow tail tailRout, ReadRecord tail tailRout, Cons name ty tailRout rout, Lacks name tailRout) => ReadRecord (Cons name ty tail) routReadRecord Nil ()
true,yes,on,enabledand1, orfalse,no,off,disabledand0, in any case.