Caravela.Policy (Caravela v0.9.2)

Copy Markdown View Source

Intermediate Representation for Caravela's triple-target policy system.

A policy :entity do ... end block in the domain DSL parses into a Caravela.Policy.Entry struct that captures three categories of rules:

  • scope — a 2-arity function (query, actor) -> query compiled into the context's apply_scope/3 helper (Ecto WHERE clauses).
  • field rules — per-field visibility predicates of arity 1 or 2 (fn actor -> bool end or fn actor, record -> bool end). Field rules compile into compute_field_access/2 and project_fields/3 on the context, and into the field_access prop reaching Svelte via LiveSvelte.
  • allow action gates — one per {:create, :update, :delete}.

The Caravela.Policy module itself only holds the structs. Caravela.Policy.Compiler emits the matching __caravela_policy_*__ function clauses into the domain module.