libero

Libero: RPC plumbing library for Gleam.

Provides handler scanning, dispatch codegen, ETF wire protocol, and decoder generation.

Run gleam run -m libero to generate the RPC pipeline into src/generated/libero/. Or call the library functions directly for programmatic use (e.g. from a framework).

Types

Re-export so consumers can build extra dispatch parameters.

pub type ExtraParam =
  codegen_dispatch.ExtraParam

The wire protocol: ETF (Erlang Term Format) or JSON.

pub type Protocol =
  protocol.Protocol

Re-export so consumers can construct push dispatch entries without reaching into libero/etf/codegen_erl directly.

pub type PushDispatch =
  codegen_erl.PushDispatch

Values

pub fn client_output_dir_from_env(
  env_value: option.Option(String),
) -> option.Option(String)

Resolve the optional client output directory from environment config. Set LIBERO_CLIENT_OUT_DIR to opt in to client-side decoder writes.

pub fn collect_seeds(
  endpoints: List(scanner.HandlerEndpoint),
) -> List(#(String, String))

Extract type seeds from endpoints for the walker.

pub fn generate_atoms(
  endpoints endpoints: List(scanner.HandlerEndpoint),
  discovered discovered: List(walker.DiscoveredType),
  atoms_module atoms_module: String,
  wire_module wire_module: option.Option(String),
) -> String

Generate the Erlang atoms pre-registration file content. Module name uses Gleam’s @-separated convention (e.g. “generated@rpc_atoms”).

pub fn generate_decoders_ffi(
  discovered discovered: List(walker.DiscoveredType),
  endpoints endpoints: List(scanner.HandlerEndpoint),
  package package: String,
) -> String

Generate the JS typed decoder FFI source. package is the Gleam package name that owns the modules (determines the top-level directory in the JS build output).

pub fn generate_decoders_gleam() -> String

Generate the Gleam wrapper for the typed decoder FFI.

pub fn generate_dispatch(
  endpoints endpoints: List(scanner.HandlerEndpoint),
  atoms_module atoms_module: option.Option(String),
  wire_module wire_module: option.Option(String),
) -> String

Generate the server dispatch module source.

pub fn generate_dispatch_with_extra_params(
  endpoints endpoints: List(scanner.HandlerEndpoint),
  atoms_module atoms_module: option.Option(String),
  wire_module wire_module: option.Option(String),
  extra_params extra_params: List(codegen_dispatch.ExtraParam),
) -> String

Generate dispatch with extra pass-through parameters on handle() and every handler call.

pub fn generate_json_contract(
  endpoints endpoints: List(scanner.HandlerEndpoint),
  discovered discovered: List(walker.DiscoveredType),
  push_types push_types: List(contract.PushContract),
  ssr_models ssr_models: List(contract.SsrModelContract),
) -> String

Generate a deterministic JSON contract artifact from discovered types and handler endpoints. The artifact describes every type, variant, and endpoint that crosses the wire so external tools and SDKs can generate clients from it.

pub fn generate_wire_erl(
  discovered discovered: List(walker.DiscoveredType),
  wire_module wire_module: String,
  endpoints endpoints: List(scanner.HandlerEndpoint),
  push_dispatches push_dispatches: List(codegen_erl.PushDispatch),
) -> Result(String, gen_error.GenError)

Generate the per-type wire-transformer Erlang module.

pub fn main() -> Nil

Run the full generation pipeline, writing files to src/generated/libero/.

pub fn qualified_atom_name(
  module_path module_path: String,
  variant_name variant_name: String,
) -> String

Re-export so consumers can build qualified atom names for push dispatch entries using the same logic as the codegen.

pub fn scan() -> Result(
  List(scanner.HandlerEndpoint),
  List(gen_error.GenError),
)

Scan src/ for handler endpoints. Context type is always ServerContext. Skips src/generated/.

pub fn scan_excluding(
  exclude_param_types exclude_param_types: List(#(String, String)),
) -> Result(
  List(scanner.HandlerEndpoint),
  List(gen_error.GenError),
)

Like scan, but excludes handler params whose resolved type matches any #(module_path, type_name) in exclude_param_types. This lets frameworks strip server-injected params (e.g. auth identity) before message-type resolution, so the scanner sees only the client-facing payload.

pub fn walk(
  seeds: List(#(String, String)),
) -> Result(List(walker.DiscoveredType), List(gen_error.GenError))

Walk the type graph from seeds. File paths are derived from this package’s src/ directory. Frameworks that generate clients from a different package layout should call the lower-level walker APIs with their own file list.

Search Document