Skip to content

Events

An Event is a named occurrence appended to a Workspace’s Event history with a payload. Events describe what happened alongside the Items’ current state; a Runtime never rebuilds Item state from them. This chapter defines Event identity, origin, publishing, processing and the bounds on Event chains.

  • An Event is declared on an App, a Template or a Union with addEvent and named by a PRN.
  • Every appended Event has an Identifier, a Workspace, an Event PRN, the Item it was published against, a creation time, a payload and a trace Identifier. An Event declared on an App is published against the Workspace Item.
  • The payload is parsed against the Event’s declared input Properties at publish time. A payload that fails parsing is rejected before anything is appended.
  • An Event carries the Identifier of the principal that caused it when the publishing context is principal, masquerade or sudo.
  • An Event carries its lineage: the Identifier of the parent Event being processed when it was published, the Identifier of the root Event of the chain, and the Event PRNs from the root to the parent. An Event with no parent starts a new chain.
  • A Runtime never modifies an appended Event’s identity, payload or lineage.
  • An external Event enters the Workspace from outside any execution: a user action, a schedule or an external system. publishExternalEvent enqueues one for processing. execute('readwrite', event, fn) takes the Event being processed as its first argument, so every write and every Event published inside fn carries its lineage.
  • An internal Event is published from inside a write execution with publish or immediate. Its parent is the Event the execution is processing.
  • Starting a write execution with origin metadata appends nothing. Only publish, immediate and publishExternalEvent append Events.
  • A schedule (addSchedule) publishes an external Event on each due tick: one against the Workspace Item for an App Event, or one per Item of the Template for a Template Event, restricted to the states the schedule names when it names any. Timing is best effort.
  • publish appends one Event per payload for asynchronous processing. Awaiting publish awaits the append within the active execution, not the Listeners.
  • An Event appended during a write execution becomes eligible for processing when the execution commits. A failed execution leaves no Event.
  • immediate appends the Event and runs its Listeners inline, inside the active execution, before returning. The reactor never processes an immediate Event.
  • Processing an asynchronously published Event runs each Listener registered on the Event, then each parent Listener registered on the Templates along the Item’s parent chain below the Workspace Item, in one write execution under a system context. That execution is deduplicated by Event Identifier, so the Listeners of one Event are applied at most once.
  • Neither publish nor immediate returning implies that projections or external effects have completed. Unit of Work defines the commit and failure rules.
  • Every Template exposes events.created. Reading it declares an Event keyed created on the Template, described as “The item has been created”, with no input Properties. Enumerating events does not declare it.
  • When a write execution creates an Item of a Template that declares created, with createChild, upsertChildByKey or upsertChildrenByKey, the Runtime publishes created against the new Item with a {} payload, as publish does. An upsert that updates an existing child publishes nothing.
  • created is reserved: addEvent('created') fails with error-002-key-in-use.
  • Only the Runtime publishes created: a Write Item’s events does not include it.
  • A Query runs in a read execution and publishes no Events.
  • Mutations, Listeners, parent Listeners and App Hooks run in write executions and may publish Events.
  • A Listener receives the Event, the Item it was published against, the App instance that declared the Listener and the write context. A parent Listener also receives the parent Item.
  • An App Hook (onCreate, onSeed) is a lifecycle Listener. It runs when a Workspace is created or seeded, receives a system write context and a prev chain, and is not triggered by Item Events.
  • Child Event declarations (addChildEvent) must not form a cycle. The Builder rejects a Definition whose declared child Events are circular.
  • A Runtime must reject publishing an Event whose PRN already appears in the lineage of the Event being processed. The rule applies to publish and immediate alike.
  • A Runtime must bound Event chain depth at 20: an Event whose lineage already holds 20 PRNs cannot publish a child. The bound applies to inline and asynchronous chains alike (Limits and errors).