DoubleEntryLedger.Utils.Changeset (double_entry_ledger v0.4.0)

View Source

Changeset helpers for error formatting and custom validations.

Summary

Functions

Returns errors grouped by field as a map of lists of {message_template, opts} tuples.

Validates that trace_context is a flat string-valued map with a bounded number of keys.

Functions

all_errors(changeset)

@spec all_errors(Ecto.Changeset.t()) :: String.t()

all_errors_with_opts(changeset)

Returns errors grouped by field as a map of lists of {message_template, opts} tuples.

Messages are not interpolated; templates and their options are preserved for downstream formatting, translation, or logging.

validate_trace_context(changeset, field \\ :trace_context)

@spec validate_trace_context(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()

Validates that trace_context is a flat string-valued map with a bounded number of keys.

The maximum number of keys defaults to 10 and can be overridden via application config:

config :double_entry_ledger, max_trace_context_keys: 20

Rejects nested maps, non-string values, and oversized maps to prevent abuse while remaining vendor-neutral.

Examples

changeset
|> validate_trace_context(:trace_context)