rally/types

Central type vocabulary for the codegen pipeline.

These types flow between the scanner, parser, and generators. The scanner produces ScannedRoutes. The parser produces PageContracts. The generators consume both to emit server handlers, client packages, and everything in between. ScanConfig carries the per-namespace configuration that drives the whole pipeline.

Types

Auth configuration for a namespace. Present when the namespace has an auth.gleam that exports Identity, resolve, is_authenticated, and redirect_url.

pub type AuthConfig {
  AuthConfig(auth_module: String)
}

Constructors

  • AuthConfig(auth_module: String)

    Gleam module path for the auth module (e.g., “admin/auth”).

What the parser extracted from a client_context.gleam file. Created by parser.parse_client_context, consumed by client package generation to wire up context init and update in the generated app.

pub type ClientContextContract {
  ClientContextContract(
    context_variants: List(VariantInfo),
    msg_variants: List(VariantInfo),
    has_init: Bool,
    has_update: Bool,
  )
}

Constructors

  • ClientContextContract(
      context_variants: List(VariantInfo),
      msg_variants: List(VariantInfo),
      has_init: Bool,
      has_update: Bool,
    )

    Arguments

    context_variants

    Variants of the ClientContext type.

    msg_variants

    Variants of the ClientContextMsg type.

    has_init

    Whether client_context.gleam exports pub fn init.

    has_update

    Whether client_context.gleam exports pub fn update.

Everything the parser extracted from a single page module. Created by parser.parse_page, consumed by every generator. This is the contract that tells generators what the page exports, what types it defines, and what features it opts into.

pub type PageContract {
  PageContract(
    model_variants: List(VariantInfo),
    msg_variants: List(VariantInfo),
    has_load: Bool,
    has_init: Bool,
    has_init_loaded: Bool,
    has_model: Bool,
    updates_client_context: Bool,
    param_names: List(String),
    source: String,
    view_source: String,
    init_source: String,
    update_source: String,
    has_page_auth: Bool,
    page_auth_required: Bool,
    has_authorize: Bool,
  )
}

Constructors

  • PageContract(
      model_variants: List(VariantInfo),
      msg_variants: List(VariantInfo),
      has_load: Bool,
      has_init: Bool,
      has_init_loaded: Bool,
      has_model: Bool,
      updates_client_context: Bool,
      param_names: List(String),
      source: String,
      view_source: String,
      init_source: String,
      update_source: String,
      has_page_auth: Bool,
      page_auth_required: Bool,
      has_authorize: Bool,
    )

    Arguments

    model_variants

    Variants of the page’s pub type Model.

    msg_variants

    Variants of the page’s pub type Msg.

    has_load

    Page exports pub fn load (SSR data loading).

    has_init

    Page exports pub fn init (client-side initialization).

    has_init_loaded

    Page exports pub fn init_loaded (client init from SSR-loaded data).

    has_model

    Page defines a Model type (custom type or alias). Pages without a Model are static content with no client-side state.

    updates_client_context

    The update function returns a 3-tuple including Option(ClientContextMsg), meaning this page can modify shared client context.

    param_names

    Parameter names from the init function signature. Used to generate route-param threading in the client app (e.g., [“id”, “slug”]).

    source

    Full source text of the page file. Kept for tree-shaking.

    view_source

    Extracted source of the view function. Used by client codegen.

    init_source

    Extracted source of the init function. Used by client codegen.

    update_source

    Extracted source of the update function. Used by client codegen.

    has_page_auth

    Page declares pub const page_auth (Required or Optional).

    page_auth_required

    page_auth is auth.Required (must be authenticated to view).

    has_authorize

    Page exports pub fn authorize (role/permission-level access control).

How a dynamic URL segment’s value is parsed. The scanner assigns IntParam to segments named “id” or ending in “_id”, and StringParam to everything else.

pub type ParamType {
  IntParam
  StringParam
}

Constructors

  • IntParam
  • StringParam

Configuration for one codegen run. Each tools.rally.clients entry in gleam.toml becomes one ScanConfig. Created in rally.gleam from TOML parsing, threaded through the entire pipeline.

pub type ScanConfig {
  ScanConfig(
    pages_root: String,
    output_route: String,
    output_dispatch: String,
    output_server_dispatch: String,
    output_server_atoms: String,
    atoms_module: String,
    output_server_wire: String,
    wire_module: String,
    output_ssr: String,
    output_ws: String,
    output_http: String,
    client_root: String,
    route_root: String,
    rally_package_path: String,
    shell_file: String,
    server_deps: dict.Dict(String, tom.Toml),
    protocol: String,
  )
}

Constructors

  • ScanConfig(
      pages_root: String,
      output_route: String,
      output_dispatch: String,
      output_server_dispatch: String,
      output_server_atoms: String,
      atoms_module: String,
      output_server_wire: String,
      wire_module: String,
      output_ssr: String,
      output_ws: String,
      output_http: String,
      client_root: String,
      route_root: String,
      rally_package_path: String,
      shell_file: String,
      server_deps: dict.Dict(String, tom.Toml),
      protocol: String,
    )

    Arguments

    pages_root

    Filesystem path to the pages directory (e.g., “src/public/pages”).

    output_route

    Output path for generated router.gleam.

    output_dispatch

    Output path for generated page_dispatch.gleam (PageModel/PageMsg unions).

    output_server_dispatch

    Output path for generated rpc_dispatch.gleam (libero RPC dispatch).

    output_server_atoms

    Output path for the Erlang atoms module (ETF type registrations).

    atoms_module

    Erlang module name for the atoms file (e.g., “generated@public@rpc_atoms”).

    output_server_wire

    Output path for the Erlang wire module (ETF encode/decode dispatch).

    wire_module

    Erlang module name for the wire file.

    output_ssr

    Output path for generated ssr_handler.gleam.

    output_ws

    Output path for generated ws_handler.gleam.

    output_http

    Output path for generated http_handler.gleam.

    client_root

    Root of the generated client package (e.g., “.generated_clients/public”).

    route_root

    URL prefix for this namespace’s routes (e.g., “/admin”). Defaults to “/”.

    rally_package_path

    Filesystem path to the rally package itself (for copying transport_ffi.mjs).

    shell_file

    Path to the HTML shell template (e.g., “src/public/shell.html”).

    server_deps

    The [dependencies] table from gleam.toml, used when generating the client package’s gleam.toml.

    protocol

    Wire protocol: “etf” (default) or “json”.

A route discovered by the scanner from the filesystem. Created by scanner.scan, consumed by every generator module.

pub type ScannedRoute {
  ScannedRoute(
    segments: List(UrlSegment),
    variant_name: String,
    params: List(#(String, ParamType)),
    module_path: String,
    layout_module: option.Option(String),
  )
}

Constructors

  • ScannedRoute(
      segments: List(UrlSegment),
      variant_name: String,
      params: List(#(String, ParamType)),
      module_path: String,
      layout_module: option.Option(String),
    )

    Arguments

    segments

    URL path broken into static and dynamic parts.

    variant_name

    PascalCase name for the Route type variant (e.g., “SettingsGeneral”).

    params

    Dynamic segments extracted as a flat list for codegen convenience.

    module_path

    Gleam module path relative to src/ (e.g., “public/pages/settings/general”).

    layout_module

    Nearest ancestor layout.gleam, if one exists in the directory tree.

One segment of a URL path. StaticSegment is a literal match (“settings”), DynamicSegment captures a value from the URL (“id_” becomes :id).

pub type UrlSegment {
  StaticSegment(name: String)
  DynamicSegment(param_name: String, param_type: ParamType)
}

Constructors

  • StaticSegment(name: String)
  • DynamicSegment(param_name: String, param_type: ParamType)

A single field in a variant constructor. The label is the field name, type_ is the resolved FieldType from libero’s type system.

pub type VariantField {
  VariantField(label: String, type_: field_type.FieldType)
}

Constructors

A single variant in a custom type. Used to represent Model variants, Msg variants, ClientContext variants, and handler message types.

pub type VariantInfo {
  VariantInfo(name: String, fields: List(VariantField))
}

Constructors

Search Document