on: S requires: C
Constructor
Spec.Pre.mk
A precondition says when an event may happen: on picks the events it applies to, requires is a condition on the history before the event. This one allows a minibar charge only after check-in:
- on: ChargePosted where charge_type = 'Minibar'
requires: ever ReservationCheckedInminibarText · checked against the spec · Minibar precondition loads without errors. A minibar charge on a folio that is not checked in is rejected.
A minibar charge on a folio that has only been opened is rejected: A minibar charge on a folio that is not checked in is rejected.
A precondition can read the event being appended: $field is its field, now() its time, and X(field) picks the earlier events of type X whose field equals the incoming one. The account's $amount > 0 and the shift's EmployeeAssigned(employee_id) use these; a person is assigned to a shift once because the count of earlier assignments of that employee_id must equal the count of earlier unassignments:
- on: EmployeeAssigned
requires: count(EmployeeAssigned(employee_id)) = count(EmployeeUnassigned(employee_id)) and count(EmployeeAssigned) - count(EmployeeUnassigned) < (last of ShiftCreated).staff_neededshiftText · checked against the spec · Assigning the same person twice is rejected. Assigning a second person to a full shift is rejected.
Assigning Anna twice is rejected (Assigning the same person twice is rejected. ), and so is assigning Ben to a shift that needs one person and has Anna (Assigning a second person to a full shift is rejected. ).
X(f1, ..., fn) correlates on several fields at once: the events of type X that agree with the incoming event on every listed field. Each field must exist on X and on the incoming event, with one type, and be listed once. A person is assigned to a shift at most once:
- on: PersonAssigned
requires: never PersonAssigned(shift_id, person_id)rosterText · checked against the spec · Roster precondition loads without errors. The same person on the same shift twice is rejected.
What holds of the stored events: a precondition is satisfied by every picked event when each event its on picks had its requires on the history before it. A store's preconditions held when each was accepted by every event in its lifetime. On the shift, every EmployeeUnassigned in the store had a matching earlier EmployeeAssigned, because rule 5 accepted it:
A charge can only be voided once it was posted and not yet voided:
- on: ChargeVoided
requires: ever ChargePosted(charge_id) and never ChargeVoided(charge_id)chargeVoidedText · checked against the spec ·
Nothing but a reopening is allowed on a closed folio:
- on: any except FolioReopened
requires: not (last of [FolioClosed, FolioReopened] is FolioClosed)folioReopenedText · checked against the spec ·
At most 3 failed logins an hour: the fourth is allowed, the fifth rejected (The fourth failed login in an hour is allowed and the fifth is rejected. ):
- on: LoginFailed
requires: at most 3 LoginFailed within 1 hourloginFailedText · checked against the spec · Login limit precondition loads without errors. The fourth failed login in an hour is allowed and the fifth is rejected.
A session may start only after recent activity:
- on: SessionStarted
requires: (last of (any except ReminderSent)).at > now() - 90 dayssessionStartedText · checked against the spec ·
A charge needs a reservation that is not cancelled, which is another entity's events (in):
- on: ChargePosted
requires: never ReservationCancelled in reservation((last of FolioOpened).reservation_id)reservationCancelledText · checked against the spec ·