Records a lifecycle hides
A query leaves out the records its entity's
lifecycle hides, such as enquiries in the bin.
include_hidden: true says it reads them too, beside the visible ones.
A bin view is that with a condition on the field the lifecycle sets, and
a guard that must count binned records says it inside exists(...):
use desk/entities { Customer, Deskhand }type EnquiryTitle = Text { min_length: 1 max_length: 200}/// Something a customer asked for, kept in the bin for 30 days.entity Enquiry { id: Uuid title: EnquiryTitle customer_id: Customer.id { on_delete: OnDelete.restricted } deskhand_id: Deskhand.id { on_delete: OnDelete.restricted } binned_at: Instant? lifecycle: { visible: binned_at == none transitions: { delete: { when: binned_at == none set: { binned_at: clock.now } } restore: { reaches: hidden set: { binned_at: none } } } purge: { after: 30d since: binned_at } } policy: { create: [Access.authenticated] read: [deskhand_id] update: [deskhand_id] delete: [deskhand_id] }}
use desk/entities { Enquiry }use desk/types { EnquiryRow }/// The caller's enquiries in the bin, which `Enquiry.restore` brings back.query binned_enquiries(caller: Principal.user) -> List<EnquiryRow> { from: Enquiry where: Enquiry.binned_at != none order: [Enquiry.title asc] limit: 50 include_hidden: true}
use desk/entities { Customer, Enquiry }use desk/types { CustomerRow }/// The customer, while they have no enquiries at all, binned ones included.query without_enquiries(customer_id: Customer.id) -> CustomerRow? { from: Customer where: Customer.id == customer_id where: not exists(Enquiry.customer_id, include_hidden: true)}
- Only what the lifecycle hides.
include_hidden: trueleaves out the entity'svisible:and nothing else. Its read policy still holds in full, so above, a deskhand's bin holds only their own enquiries, and a call with no caller runs without policy, as every read does (Calls with no caller). A person's record that erasure kept stays out: onlyinclude_erased: truereaches that (The person's own record), and a query may say both. - Where it is said. On a query, for the records
from:reads, a list's, a page's, one record's or an aggregate's; and last insideexists(...), for the related records:exists(Enquiry.customer_id, include_hidden: true). An include's children still leave hidden records out, and a parent is read whether its lifecycle hides it or not (Children and parents). It takes onlytrue(type.setting_value), and only for an entity whose lifecycle has avisible:(query.include_hidden_unused). - Bringing one back. A query reads hidden records; only a transition
marked
reaches: hiddenchanges one (Restoring a hidden record), so a bin view lists whatEnquiry.restorecan bring back. - A delete a binned record blocks. A
restrictedreference holds whether the record holding it is hidden or not, so above, deleting a customer with only binned enquiries is refused with the conflict itsconflict:maps, until purge removes them (Conflicts). The guard query says the same thing first, so an action can answer before it tries. - Shown where it is read.
jadpo explainlists, beside the entity's lifecycle, each query that reads its hidden records, and marks each route that runs one. - Its index. The index a query saying
include_hidden: trueneeds holds every record, not only thosevisible:lets through (How the derived indexes are chosen).
A guess at another spelling, include_deleted: or include_binned:, is
query.unknown_section, whose next: names include_hidden:.
Markdown for agents: /docs/records-a-lifecycle-hides.md.Built from Jadpo's main branch at commit 9080dc3.