libero/scanner

Scanning for handler-as-contract endpoints.

Walks a source tree to discover handler functions whose signatures define the wire contract: public functions with a server_ prefix, a context parameter, and a Result return type.

Types

A single handler endpoint discovered by scanning function signatures. Each represents one RPC function that clients can call.

pub type HandlerEndpoint {
  HandlerEndpoint(
    module_path: String,
    fn_name: String,
    return_ok: field_type.FieldType,
    return_err: field_type.FieldType,
    params: List(#(String, field_type.FieldType)),
    mutates_context: Bool,
    msg_type: option.Option(#(String, String)),
  )
}

Constructors

  • HandlerEndpoint(
      module_path: String,
      fn_name: String,
      return_ok: field_type.FieldType,
      return_err: field_type.FieldType,
      params: List(#(String, field_type.FieldType)),
      mutates_context: Bool,
      msg_type: option.Option(#(String, String)),
    )

    Arguments

    module_path

    Handler module path, e.g. “pages/login”

    fn_name

    Function name WITHOUT the server_ prefix, e.g. “login”

    return_ok

    Ok payload of the handler’s Result.

    return_err

    Err payload of the handler’s Result.

    params

    Parameters excluding the context param, with labels and resolved types. Each entry is #(label, FieldType).

    mutates_context

    True when the handler returns #(Result(_, _), ContextType), signalling it may have produced a new context value. False when the handler returns a bare Result(_, _).

    msg_type

    When set, the handler takes a single message type param instead of individual params. Dispatch passes the whole coerced message. The params list still contains the type’s fields (for wire contract).

Values

pub fn build_alias_resolution_map(
  imports: List(glance.Definition(glance.Import)),
) -> dict.Dict(String, String)

Build a map from import aliases (and bare module names) to the full module path.

pub fn build_type_alias_originals(
  imports: List(glance.Definition(glance.Import)),
) -> dict.Dict(String, String)

Map locally-bound type names back to their original names from the source module. Only populated when an import uses type X as Y.

pub fn build_type_import_map(
  imports: List(glance.Definition(glance.Import)),
) -> dict.Dict(String, String)

Build a map from unqualified type names to the full module path of their import.

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

Collect type seeds from scanned endpoints for the walker. Returns #(module_path, type_name) pairs from all param and return types.

pub fn derive_module_path(file_path file_path: String) -> String

Derive the Gleam module path from a file path by finding the last occurrence of /src/ and taking everything after it, then stripping the .gleam extension.

pub fn parse_module(
  file_path file_path: String,
) -> Result(glance.Module, gen_error.GenError)

Read a .gleam file and parse it via glance, surfacing both I/O and parser failures as GenError variants tagged with the file path.

pub fn scan(
  src_dir src_dir: String,
  context_type_name context_type_name: String,
) -> Result(List(HandlerEndpoint), List(gen_error.GenError))

Scan a source directory for handler functions. Looks for: pub fn server_*(args…, context: T) -> Result(ok, err) Returns the endpoint list or structured errors.

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

Like scan, but filters out handler params whose resolved type matches any #(module_path, type_name) in exclude_param_types. Filtered params are removed before message-type resolution, so a handler with one message param plus an excluded param still resolves the message type correctly.

pub fn walk_directory(
  path path: String,
) -> Result(List(String), gen_error.GenError)

Recursively walk a directory, returning every .gleam file found. Skips any subdirectory named generated.

Search Document