Field types, modifiers, ledgers, and rollups.
Entities and fields
A field is name: type followed by any modifiers:
app billing "Billing" {}
entity Invoice "Invoice" plural "Invoices" {
number: text required
customer: ref Account on delete restrict
issued_on: date
total: money USD
terms: longtext help "Shown on the printed invoice."
ssn: text pii hidden
status: enum draft, sent, paid
net: computed number = total - discount
notes: json
age_days: number validate age_days >= 0 "Age cannot be negative."
}
The types are text, longtext, number, money <currency>,
boolean, date, datetime, file, json, enum, ref and
computed. The modifiers are required, pii, hidden,
label, help and validate <expr> "<message>".
Two things worth calling out. pii is not decoration — it marks the
field as personal data for the platform's handling of it. And a ref
must say what happens when its target is deleted (restrict, nullify
or cascade); there is no silent default, because the wrong answer is
discovered in production.
Two entity shapes exist beyond the ordinary one — an append-only
ledger, and a rollup that is derived rather than written:
app ledgers "Ledgers" {}
entity AuditEntry ledger {
actor: text
reason: text
}
entity AccountTotal rollup over Invoice sum total by customer where status == "paid"