context api

type UserId = String where NonEmpty

type Note = {
  id: String,
  owner: String,
}

-- A route served to either an authenticated User (Bearer) or an anonymous
-- Visitor (None) — an ordered sum of peer actors, resolved first-wins. The
-- body matches on the resolved actor; `Visitor` (the catch-all) comes last.
actor User { auth = Bearer(secret = "AUTH_JWT_SECRET"), identity = UserId }

service api from http {
  on GET("/notes/:id") by who: User | Visitor (id: String) -> Effect[HttpResult[Note]] {
    match who {
      User(u) => Ok(Note { id: id, owner: u })
      Visitor => Ok(Note { id: id, owner: "public" })
    }
  }
}
