Module

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 EnvError

What 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.

#EnvError Source

data EnvError

What went wrong with one variable: it is not set, or its text does not parse, with the name and then the instance's reason.

Constructors

Instances

#printErrors Source

printErrors :: Errors -> String

One message naming every variable in question, for a log or a stderr line before exiting.

#ParseValue Source

class ParseValue ty  where

How 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

Instances

#ReadVariable Source

class ReadVariable ty  where

Looks 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

#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