diff options
| author | eunhhu <[email protected]> | 2026-10-18 18:52:48 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-10-18 18:52:48 +0100 |
| commit | 8709c7fdb9d18e30e6bb776f536aa230389fa527 (patch) | |
| tree | 94f08b1646ae39fd56568ca029d4c457fe0b957d /examples/documents.aup | |
| parent | 3d7765e116c7852c63237bf25dbfb785843de916 (diff) | |
| download | aup-8709c7fdb9d18e30e6bb776f536aa230389fa527.tar.gz aup-8709c7fdb9d18e30e6bb776f536aa230389fa527.zip | |
Bytes in a record field (Pure 027's 4b-1): body: bytes (= "..." its default's bytes), x.body.bytes its length (LEN), a text going there only as bytes(t); no list keyed by bytes or by a list; examples/documents.aup: keyed byte documents as a keyed list of records, each edit checked against the revision it was made on; documents_model: random shows and edits (stale revisions, past the end, any bytes, up to 5,000 at once) against a model, in memory and on a store restarting six times (half of the runs in bursts), four seeds alike (1,280 steps); four diagnostics
Diffstat (limited to 'examples/documents.aup')
| -rw-r--r-- | examples/documents.aup | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/documents.aup b/examples/documents.aup new file mode 100644 index 0000000..4671464 --- /dev/null +++ b/examples/documents.aup @@ -0,0 +1,39 @@ +# Revision-checked byte edits of keyed documents. A document is an item of a +# keyed list; an edit names the revision it was made against and commits only +# if that is still the document's (0 for one not there yet), and a failed +# event leaves everything as it was. +record Doc { + id: text + body: bytes + revision: i64 +} +state docs: list of Doc by id + +input show = message { + id: text +} +input edit = message { + id: text + base: i64 + start: u32 + remove: u32 + insert: bytes +} + +on show { + reply docs[show.id].body +} + +on edit { + if docs.has(edit.id) { + let d = docs[edit.id] + require d.revision == edit.base + require edit.start + edit.remove <= d.body.bytes + docs[edit.id].body = d.body[0 .. edit.start] + edit.insert + d.body[edit.start + edit.remove .. d.body.bytes] + docs[edit.id].revision = d.revision + 1 + } else { + require edit.base == 0 && edit.start == 0 && edit.remove == 0 + docs.add(Doc { id: edit.id, body: edit.insert, revision: 1 }) + } + reply edit.insert +} |
