libero/codegen

Values

pub fn extract_dir(path: String) -> String
pub fn module_to_mjs_path(module_path: String) -> String

Convert a Gleam module path like “shared/discount” to its compiled .mjs bundle path “shared/shared/discount.mjs”. The first segment is the package name (Gleam convention) and is repeated because the bundle layout is <package>/<module_path>.mjs.

pub fn write_atoms(
  config config: config.Config,
  discovered discovered: List(walker.DiscoveredVariant),
) -> Result(Nil, gen_error.GenError)

Generate an Erlang FFI file that pre-registers all constructor atoms discovered by the type graph walker, plus framework atoms used by libero’s wire protocol. Calling ensure/0 from this module creates the atoms in the BEAM atom table so that binary_to_term([safe]) can decode client ETF payloads without rejecting unknown atoms.

pub fn write_config(
  config config: config.Config,
) -> Result(Nil, gen_error.GenError)
pub fn write_dispatch(
  message_modules message_modules: List(scanner.MessageModule),
  server_generated server_generated: String,
  atoms_module atoms_module: String,
) -> Result(Nil, gen_error.GenError)

Generate the server dispatch module at server_generated/dispatch.gleam. The dispatch module decodes incoming wire calls and routes them by module name to the appropriate handler.

pub fn write_push_wrappers(
  message_modules message_modules: List(scanner.MessageModule),
  server_generated server_generated: String,
) -> Result(Nil, List(gen_error.GenError))

Generate per-module push wrapper files under server_generated/. For each message module with has_msg_from_server == True, generates a <module_name>.gleam file with send_to_client and send_to_clients functions that bake in the module string.

pub fn write_register(
  config config: config.Config,
  discovered discovered: List(walker.DiscoveredVariant),
) -> Result(Nil, List(gen_error.GenError))

Write the client-side type registration files (gleam wrapper + mjs FFI). Uses the pre-discovered variant list instead of walking from function signatures.

pub fn write_send_functions(
  message_modules message_modules: List(scanner.MessageModule),
  client_generated client_generated: String,
) -> Result(Nil, List(gen_error.GenError))

Generate per-module send function files under client_generated/. For each message module with has_msg_from_client == True, generates a <module_name>.gleam file with a send_to_server function that wraps rpc.send.

pub fn write_websocket(
  server_generated server_generated: String,
) -> Result(Nil, gen_error.GenError)

Generate the server websocket handler at server_generated/websocket.gleam. Also writes the Erlang FFI for decoding push messages.

Search Document