Lavash.Form.ConstraintTranspiler (Lavash v0.3.0-rc.0)

Copy Markdown View Source

Transpiles Ash resource constraints to rx() expressions for client-side validation.

This allows form validation to be driven from a single source of truth (the Ash resource) while still providing instant client-side feedback.

Supported constraints:

  • String: min_length, max_length, match (regex)
  • Integer: min, max
  • All types: allow_nil? (required fields)

Summary

Functions

Generates an rx() expression AST for a field's validity check.

Returns all error checks with their messages for a validation.

Returns the error message for a constraint type.

Generates validation info for all attributes of a resource that have transpilable constraints.

Checks if an attribute has any constraints we can transpile to JS.

Functions

build_valid_expression(validation, params_field)

Generates an rx() expression AST for a field's validity check.

The expression references @<params_field>["<field_name>"] for the value.

error_checks(validation)

Returns all error checks with their messages for a validation.

Each check is a tuple of {check_type, constraint_value, error_message}. Used to generate error list calculations.

error_message(atom, min)

Returns the error message for a constraint type.

extract_validations(resource)

Generates validation info for all attributes of a resource that have transpilable constraints.

Returns a list of field validation specs that can be used to generate calculate declarations.

has_transpilable_constraints?(attr)

Checks if an attribute has any constraints we can transpile to JS.