Caravela.IR (Caravela v0.9.1)

Copy Markdown View Source

Public, JSON-serializable view of a compiled Caravela domain.

The internal Caravela.Schema.Domain struct is for generator and compiler consumption. Caravela.IR is the stable shape external tools, LLMs, and documentation readers consume — a plain map of atom keys and primitive values (strings, booleans, integers, maps, lists, nil) that encodes cleanly through Jason.encode/1.

Anonymous functions inside policies (scope closures, field-rule predicates) are not included. The IR records only their metadata (the fact that a rule exists, its arity, its entity) — the implementations live as compiled function clauses on the domain module and are not serializable.

Usage

iex> Caravela.IR.of(MyApp.Domains.Library)
%{
  domain: "MyApp.Domains.Library",
  caravela_version: "0.8.1",
  multi_tenant: false,
  default_policy: "deny",
  version: nil,
  entities: [...],
  relations: [...],
  hooks: [...]
}

Accepts either a domain module (atom) or a compiled %Caravela.Schema.Domain{} struct.

Stability

The top-level keys and the shape of entities / fields / relations / policies / auth are semver-stable starting in 0.9. New keys may be added without a major bump; existing keys keep their shape.

Summary

Functions

Build an IR map for domain_or_module. Accepts a domain module atom (which must expose __caravela_domain__/0) or a compiled Caravela.Schema.Domain struct.

Serialize the IR to a JSON string. Requires :jason.

Functions

of(domain_module)

@spec of(module() | Caravela.Schema.Domain.t()) :: map()

Build an IR map for domain_or_module. Accepts a domain module atom (which must expose __caravela_domain__/0) or a compiled Caravela.Schema.Domain struct.

to_json(ir, opts \\ [])

@spec to_json(
  map(),
  keyword()
) :: String.t()

Serialize the IR to a JSON string. Requires :jason.