March Docs

ConnStates

Bastion.ConnStates — phantom type state tags for the typed middleware pipeline.

These singleton types are used as type parameters in Conn(a) to track which middleware transformations have been applied at compile time.

The intended pipeline state machine:

Raw  ->  Parsed  ->  WithSession  ->  Authenticated
                           |
                         WithDB (composable at any stage)

When the March type system supports parameterized types, the compiler will enforce ordering: passing Conn(Raw) to load_session is a type error. Functions document their intended type signatures in comments for now.

Example pipeline:

conn
|> TypedMiddleware.parse_body()           -- Conn(Raw) -> Conn(Parsed)
|> TypedMiddleware.load_session(secret)   -- Conn(Parsed) -> Conn(WithSession)
|> TypedMiddleware.with_db(pool)          -- Conn(WithSession) -> Conn(WithSession & WithDB)
|> MyApp.Router.route()

Types

typeRawRaw = Raw#
typeParsedParsed = Parsed#
typeWithSessionWithSession = WithSession#
typeAuthenticatedAuthenticated = Authenticated#
typeWithDBWithDB = WithDB#
typeTypedConnTypedConn(s) = TypedConn(Conn)#
typeSessionSession = Session(String, List((String, String)))#
typeUserUser = User(Int, String, String)#

Functions

fnempty_sessionempty_session(id)#

Build a new empty session with the given ID.

fnmake_usermake_user(id, email, name)#

Build a User from its component parts.

fnsession_deletesession_delete(session, key)#

Returns a new Session with the given key removed.

fnsession_getsession_get(session, key)#

Look up a value in the session by key. Returns None if absent.

fnsession_idsession_id(session)#

Returns the session ID string.

fnsession_pairssession_pairs(session)#

Returns all session data as a list of (key, value) pairs.

fnsession_putsession_put(session, key, value)#

Returns a new Session with an additional key/value pair.

fnuser_emailuser_email(user)#

Returns the user's email address.

fnuser_iduser_id(user)#

Returns the user's integer ID.

fnuser_nameuser_name(user)#

Returns the user's display name.