Bosatsu packages

Yichus/Frontend

Builtin package (resource frontend.bosatsu). This is the complete package source used by this build. The export list names its public API; definitions below give the types and behavior.

New to the API? Start with Make a calculator or Build an API, then use this page to look up a definition.

package Yichus/Frontend

# Canonical frontend configuration for a verified Yichus API. A FrontendSpec
# selects and titles views over routes that already exist in a ServiceDef;
# field schemas and handler arities come from the typed IR, not from this
# spec. Generation refuses unless api_verify is proven and every view path
# matches a declared route.

from Bosatsu/Predef import List

export (
  Presentation(),
  View(),
  FrontendSpec(),
  FieldWording(),
  RowLink(),
  ScreenSpec(),
)

# How a view is presented. The handler's extra parameters (after Db and
# Principal) still come from the IR: ListView shows the result, Form
# collects extras as inputs, Action is a button with no extra fields.
enum Presentation:
  ListView
  Form
  Action

# One screen: a ServiceDef route path, a title, and a presentation.
struct View(path: String, title: String, presentation: Presentation)

# The complete declared frontend of an API module. Discovery is structural
# (any binding whose checked type is FrontendSpec participates).
struct FrontendSpec(app_name: String, views: List[View])

# How one field reads on the app's screens, named by the field's name in
# the API (`reply_cap`). Labeled gives it the app's own words wherever it
# shows: a form control's label, a result's field or column, a refusal's
# detail. Unshown keeps an answer's field off the screen; it stays in the
# Raw response. A field no wording names reads as its name, humanized.
# Generation refuses a wording naming no field a view types, unless some
# view answers with a Yichus/Service::Response: its JSON body's keys are
# text to the compiler, so such a wording is taken on trust.
enum FieldWording:
  Labeled(field: String, label: String)
  Unshown(field: String)

# A row of a list view's answer that opens another view: each row holding
# the field `row_field` gets a button, titled as the view at `view_path`,
# that opens that view with its input `input_field` filled from the row.
# When that input is the view's only one, the button also submits it.
# The list view must answer with a Yichus/Service::Response, so
# `row_field` is a key of its JSON body and is not checked: a misspelled
# one shows no buttons. The paths and `input_field` are checked.
struct RowLink(list_path: String, row_field: String, view_path: String, input_field: String)

# How the screens of the app a FrontendSpec declares read and connect.
# Compiled with that spec and discovered, like it, by its checked type; at
# most one.
struct ScreenSpec(wordings: List[FieldWording], row_links: List[RowLink])