Engine

7.2. Statements of Events🔗

The exact statements behind the claims on the page Events.

def engineFieldNames : List String := ["entity", "type", "key", "at", "revision", "expected_revision", "position"]

proof: spec/Spec/Semantics.lean:35

theorem every_event_has_its_engine_fields (e : Event) : e.get "entity" = .str e.entity ∧ e.get "type" = .str e.type ∧ e.get "key" = .str e.key ∧ e.get "at" = .timestamp e.at ∧ e.get "revision" = .num e.revision

proof: spec/Spec/Facts.lean:272

theorem every_engine_field_is_a_value_sent_only_or_the_position (e : Event) : ∀ f ∈ engineFieldNames, (∃ v, e.engineField? f = some v) ∨ f = "expected_revision" ∨ f = "position"

proof: spec/Spec/Meaning.lean:506

theorem a_field_may_have_any_type_but_a_date_range (t : Ty) : t.allowedAsFieldType = true ↔ t ≠ .dateRange

proof: spec/Spec/Meaning.lean:41

theorem deploy_rejects_field_named_like_an_engine_field {st : State} {sc : Schema} {fs : List RuleFile} {ent : String} {ts : List EventSchema} (hts : (ent, ts) ∈ sc) {es : EventSchema} (hes : es ∈ ts) {f : String} {t : Ty} (hf : (f, t) ∈ es.fields) (hn : f ∈ engineFieldNames) : st.deploy sc fs = none

proof: spec/Spec/Meaning.lean:94

theorem deploy_rejects_field_of_date_range_type {st : State} {sc : Schema} {fs : List RuleFile} {ent : String} {ts : List EventSchema} (hts : (ent, ts) ∈ sc) {es : EventSchema} (hes : es ∈ ts) {f : String} (hf : (f, Ty.dateRange) ∈ es.fields) : st.deploy sc fs = none

proof: spec/Spec/Meaning.lean:104

theorem deploy_rejects_entity_declared_twice {st : State} {sc : Schema} {fs : List RuleFile} (h : ¬ (sc.map (·.1)).Nodup) : st.deploy sc fs = none

proof: spec/Spec/Meaning.lean:71

theorem deploy_rejects_type_declared_twice {st : State} {sc : Schema} {fs : List RuleFile} {ent : String} {ts : List EventSchema} (hts : (ent, ts) ∈ sc) (h : ¬ (ts.map (·.name)).Nodup) : st.deploy sc fs = none

proof: spec/Spec/Meaning.lean:78

theorem deploy_rejects_field_declared_twice {st : State} {sc : Schema} {fs : List RuleFile} {ent : String} {ts : List EventSchema} (hts : (ent, ts) ∈ sc) {es : EventSchema} (hes : es ∈ ts) (h : ¬ (es.fields.map (·.1)).Nodup) : st.deploy sc fs = none

proof: spec/Spec/Meaning.lean:86

theorem deploy_rejects_optional_field_that_is_not_declared {st : State} {sc : Schema} {fs : List RuleFile} {ent : String} {ts : List EventSchema} (hts : (ent, ts) ∈ sc) {es : EventSchema} (hes : es ∈ ts) {f : String} (hopt : f ∈ es.optional) (hno : f ∉ es.fields.map (·.1)) : st.deploy sc fs = none

proof: spec/Spec/Meaning.lean:113

theorem appended_event_is_valid {acc} {st st' : State} {e : Event} (h : st.appendWith acc e = some st') : e.valid st.schema = true

proof: spec/Spec/Facts.lean:22

theorem event_with_empty_key_is_invalid {sc : Schema} {e : Event} (h : e.key = "") : e.valid sc = false

proof: spec/Spec/Meaning.lean:201

theorem event_of_unknown_type_is_invalid {sc : Schema} {e : Event} (h : (sc.lookup e.entity).bind (·.find? (·.name == e.type)) = none) : e.valid sc = false

proof: spec/Spec/Meaning.lean:206

theorem required_field_must_be_present {es : EventSchema} {fs : List (String × Value)} {f : String} {t : Ty} (hf : (f, t) ∈ es.fields) (hreq : f ∉ es.optional) (hmiss : f ∉ fs.map (·.1)) : es.accepts fs = false

proof: spec/Spec/Meaning.lean:125

theorem optional_field_may_be_missing {es : EventSchema} {fs : List (String × Value)} {f : String} (hacc : es.accepts fs = true) (hopt : f ∈ es.optional) : es.accepts (fs.filter fun p => p.1 != f) = true

proof: spec/Spec/Meaning.lean:139

theorem null_is_only_allowed_for_an_optional_field {es : EventSchema} {fs : List (String × Value)} {f : String} (hacc : es.accepts fs = true) (hm : (f, Value.null) ∈ fs) : f ∈ es.optional

proof: spec/Spec/Meaning.lean:158

theorem field_of_wrong_type_is_rejected {es : EventSchema} {fs : List (String × Value)} {f : String} {t : Ty} {v : Value} (ht : es.fields.lookup f = some t) (hm : (f, v) ∈ fs) (hnn : v ≠ .null) (hty : v.ty? ≠ some t) : es.accepts fs = false

proof: spec/Spec/Meaning.lean:169

theorem unlisted_field_is_rejected {es : EventSchema} {fs : List (String × Value)} {f : String} {v : Value} (hm : (f, v) ∈ fs) (hno : es.fields.lookup f = none) : es.accepts fs = false

proof: spec/Spec/Meaning.lean:181

theorem field_sent_twice_is_rejected {es : EventSchema} {fs : List (String × Value)} (h : ¬ (fs.map (·.1)).Nodup) : es.accepts fs = false

proof: spec/Spec/Meaning.lean:192

theorem the_latest_at_is_not_before_the_clock (clock : Rat) (h : List Event) : clock ≤ latestAt clock h

proof: spec/Spec/Meaning.lean:213

theorem the_latest_at_is_not_before_the_history (clock : Rat) (h : List Event) : ∀ x ∈ h, x.at ≤ latestAt clock h

proof: spec/Spec/Meaning.lean:223

theorem the_latest_at_is_the_clock_or_an_at_of_the_history (clock : Rat) (h : List Event) : latestAt clock h = clock ∨ ∃ x ∈ h, latestAt clock h = x.at

proof: spec/Spec/Meaning.lean:241

theorem the_stored_at_is_the_clock_or_the_latest_at_of_the_key (st : State) (e : Event) : (st.stamp e).at = latestAt e.at (keyHistory st.store e.entity e.key)

proof: spec/Spec/Meaning.lean:270

theorem the_stored_revision_is_the_number_of_events_of_the_key_plus_one (st : State) (e : Event) : (st.stamp e).revision = (keyHistory st.store e.entity e.key).length + 1

proof: spec/Spec/Meaning.lean:266

theorem stored_event_keeps_what_was_sent (st : State) (e : Event) : (st.stamp e).entity = e.entity ∧ (st.stamp e).type = e.type ∧ (st.stamp e).key = e.key ∧ (st.stamp e).fields = e.fields ∧ (st.stamp e).expected_revision = none

proof: spec/Spec/Meaning.lean:274

theorem a_key_history_is_the_stored_events_of_its_entity_and_key {store : List Event} {ent k : String} {e : Event} : e ∈ keyHistory store ent k ↔ e ∈ store ∧ e.entity = ent ∧ e.key = k

proof: spec/Spec/Meaning.lean:280

theorem a_key_history_is_a_sublist_of_the_store (store : List Event) (ent k : String) : (keyHistory store ent k).Sublist store

proof: spec/Spec/Meaning.lean:286

theorem at_never_decreases_per_key {st : State} (hr : Reachable st) (ent k : String) : (keyHistory st.store ent k).Pairwise fun a b => a.at ≤ b.at

proof: spec/Spec/Meaning.lean:331

theorem the_stored_at_is_not_before_any_at_of_the_key_history {st : State} (e : Event) : ∀ x ∈ keyHistory st.store e.entity e.key, x.at ≤ (st.stamp e).at

proof: spec/Spec/Proofs.lean:356

theorem revisions_are_one_to_n {st : State} (hr : Reachable st) (ent k : String) : (keyHistory st.store ent k).map (·.revision) = List.range' 1 (keyHistory st.store ent k).length

proof: spec/Spec/Proofs.lean:300

theorem appended_event_position_is_store_length_plus_one {acc} {st st' : State} {e : Event} (h : st.appendWith acc e = some st') : st'.store[st.store.length]? = some (st.stamp e) ∧ st'.store.length = st.store.length + 1

proof: spec/Spec/Meaning.lean:515

theorem an_event_is_stored_only_if_its_expected_revision_matches_the_count {acc} {st st' : State} {e : Event} {r : Nat} (h : st.appendWith acc e = some st') (hr : e.expected_revision = some r) : (keyHistory st.store e.entity e.key).length = r

proof: spec/Spec/Proofs.lean:362

theorem expected_revision_zero_means_new_key {acc} {st st' : State} {e : Event} (h : st.appendWith acc e = some st') (h0 : e.expected_revision = some 0) : keyHistory st.store e.entity e.key = []

proof: spec/Spec/Facts.lean:91

theorem append_rejects_wrong_expected_revision {acc} {st : State} {e : Event} {r : Nat} (hr : e.expected_revision = some r) (hne : (keyHistory st.store e.entity e.key).length ≠ r) : st.appendWith acc e = none

proof: spec/Spec/Meaning.lean:318

theorem stored_events_have_no_expected_revision {st : State} (hr : Reachable st) : ∀ e ∈ st.store, e.expected_revision = none

proof: spec/Spec/Facts.lean:78

theorem two_writers_with_the_same_expected_revision_cannot_both_append {acc acc'} {st st1 st2 : State} {e e2 : Event} {r : Nat} (h1 : st.appendWith acc e = some st1) (hr : e.expected_revision = some r) (hext : st1.store <+: st2.store) (hent : e2.entity = e.entity) (hkey : e2.key = e.key) (hr2 : e2.expected_revision = some r) : st2.appendWith acc' e2 = none

proof: spec/Spec/Proofs.lean:386

theorem same_event_stored_twice_without_rule : ((State.deploy {} depositSchema []).bind (·.appendBatch [deposit "D1", deposit "D1"])).map (·.store.length) = some 2

proof: spec/Spec/Facts.lean:673

theorem domain_id_rule_rejects_retry : once.bind (·.appendBatch [deposit "D1"]) = none ∧ (once.bind (·.appendBatch [deposit "D2"])).map (·.store.length) = some 2

proof: spec/Spec/Facts.lean:680

theorem may_add_an_optional_field : schemaChangeAllowed base (sch [("charge_id", .str), ("note", .str)] ["note"]) oneOpened = true

proof: spec/Spec/Facts.lean:631

theorem may_make_a_required_field_optional : schemaChangeAllowed base (sch [("charge_id", .str)] ["charge_id"]) oneOpened = true

proof: spec/Spec/Facts.lean:636

theorem may_remove_a_type_without_events : schemaChangeAllowed base [("folio", [{ name := "FolioOpened", fields := [("reservation_id", .str), ("currency", .str)], optional := [] }])] oneOpened = true

proof: spec/Spec/Facts.lean:641

theorem may_not_add_a_required_field : schemaChangeAllowed base (sch [("charge_id", .str), ("note", .str)] []) oneOpened = false

proof: spec/Spec/Facts.lean:647

theorem may_not_make_an_optional_field_required : schemaChangeAllowed (sch [("charge_id", .str)] ["charge_id"]) base oneOpened = false

proof: spec/Spec/Facts.lean:652

theorem may_not_retype_a_field : schemaChangeAllowed base (sch [("charge_id", .num)] []) oneOpened = false

proof: spec/Spec/Facts.lean:657

theorem may_not_remove_a_field : schemaChangeAllowed base (sch [] []) oneOpened = false

proof: spec/Spec/Facts.lean:662

theorem may_not_remove_a_type_with_events : schemaChangeAllowed base [("folio", [{ name := "ChargePosted", fields := [("charge_id", .str)], optional := [] }])] oneOpened = false

proof: spec/Spec/Facts.lean:667

theorem deploy_rejects_schema_change_not_allowed {st : State} {sc : Schema} {fs : List RuleFile} (h : schemaChangeAllowed st.schema sc st.store = false) : st.deploy sc fs = none

proof: spec/Spec/Facts.lean:103

theorem a_deploy_keeps_the_store {st st' : State} {sc : Schema} {fs : List RuleFile} (h : st.deploy sc fs = some st') : st'.store = st.store

proof: spec/Spec/Facts.lean:38

theorem an_allowed_schema_change_keeps_stored_events_valid {sc sc' : Schema} {store : List Event} (hwf : sc'.valid = true) (hok : schemaChangeAllowed sc sc' store = true) {e : Event} (he : e ∈ store) (hv : e.valid sc = true) : e.valid sc' = true

proof: spec/Spec/Schemas.lean:66

theorem stored_events_valid_in_reachable_states {st : State} (hr : Reachable st) : ∀ e ∈ st.store, e.valid st.schema = true

proof: spec/Spec/Meaning.lean:337

theorem schema_well_formed_in_reachable_states {st : State} (hr : Reachable st) : st.schema.valid = true

proof: spec/Spec/Schemas.lean:175