libero/codegen

Cross-cutting helpers used by codegen submodules.

Naming helpers and small predicates over field_type.FieldType graphs.

Values

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

Build a resolver function that maps a module path to its import alias. Uses the last segment when unique, or the full underscored path when two or more modules share the same last segment.

pub fn collect_endpoint_type_imports(
  endpoints endpoints: List(scanner.HandlerEndpoint),
  include_return include_return: Bool,
  resolve_alias resolve_alias: fn(String) -> String,
) -> List(String)

Collect import <module> lines for every module path referenced (transitively) by the endpoints’ parameter types and, optionally, return types. Uses aliases from resolve_alias so that modules with the same last segment get distinct names.

pub fn collect_endpoint_type_modules(
  endpoints endpoints: List(scanner.HandlerEndpoint),
  include_return include_return: Bool,
) -> List(String)

Collect every module path referenced by endpoint parameter types and, optionally, return types. Kept separate from import rendering so callers can compare exact module paths before aliases and strings enter the mix.

pub fn emit_client_msg_variants(
  endpoints endpoints: List(scanner.HandlerEndpoint),
  resolve_alias resolve_alias: fn(String) -> String,
) -> List(String)

Emit the body lines of the generated ClientMsg type. Uses resolve_alias to qualify user-defined types with the correct import alias (needed when multiple modules share the same last segment, e.g. two different id_ modules).

pub fn endpoints_contain(
  endpoints endpoints: List(scanner.HandlerEndpoint),
  predicate predicate: fn(field_type.FieldType) -> Bool,
) -> Bool

True if any endpoint’s parameter or return type (transitively) satisfies predicate.

pub fn import_if(
  endpoints endpoints: List(scanner.HandlerEndpoint),
  predicate predicate: fn(field_type.FieldType) -> Bool,
  import_line import_line: String,
) -> String

Emit import_line (with a leading newline) iff any endpoint type transitively satisfies predicate; otherwise the empty string.

pub fn is_dict(ft: field_type.FieldType) -> Bool
pub fn is_option(ft: field_type.FieldType) -> Bool
pub fn module_to_mjs_path(
  module_path module_path: String,
  package package: String,
) -> String

Convert a Gleam module path to its compiled .mjs bundle path. The package name is the Gleam package that owns the module (determines the top-level directory in the JS build output).

pub fn module_to_underscored(module_path: String) -> String

Convert a Gleam module path like “shared/discount” to a flat underscore-separated alias. e.g. “shared/discount” -> “shared_discount”.

pub fn to_pascal_case(name: String) -> String

Convert a snake_case name to PascalCase.

pub fn variant_pattern(
  variant_name variant_name: String,
  params params: List(#(String, field_type.FieldType)),
) -> String

Emit a constructor / pattern shape like Variant(label1:, label2:) or just Variant when there are no parameters.

Search Document