Skip to content

refactor(solid): edit a document that changes elsewhere with editDocument - #996

Merged
ixuz merged 6 commits into
mainfrom
edit-document
Nov 24, 2026
Merged

ixuz merged 6 commits into
mainfrom
edit-document

Conversation

@ixuz

@ixuz ixuz commented Nov 24, 2026

Copy link
Copy Markdown
Member

What and why

Writes in packages/solid that must hold up while their document changes elsewhere each had their own retry loop. Each loop read the document, changed it, checked it, saved it with If-Match the read, and on a 412 read and changed it again. There were eight copies of that loop and six ATTEMPTS constants. So each adapter mixed its own rules with the write policy: how many tries, the pause between them, which failures call for another try, and where the check runs. A change to the policy had to be made in eight places.

This adds editDocument in datasets.ts, beside saveDataset and PreconditionFailedError, and moves every one of those writes onto it, one adapter per commit:

  • editDocument reads the document and asks the adapter's edit what to make of it: { result, dataset?, subjects?, whole? }, where no dataset means nothing to write. It checks the subjects named, saves with If-Match (one whole PUT with whole), and on a 412 reads and edits again, three tries by default.
    • Only the check and the save are tried again. What the read or the edit throws, a PreconditionFailedError included (addDeck's "already there"), is thrown at once.
    • Options: attempts, pause (before each try after the first), checkWrite, read (getSolidDatasetOrNull by default; the type index uses readDataset, so a missing index still throws) and failure (what a write that fails for good throws instead).
  • Moved onto it:
    • the type index (changeIndex is gone);
    • the catalog's links;
    • removing answers from the log;
    • the deck catalog: addDeck, editDeckTree and editEntry;
    • writeFsrsStates;
    • the digest, with its 6 tries, growing pause and Refused wrapping. The wrapping still applies only to a failed check or save, never a read, so changes refused together are still written one at a time.

The edit's result is one object rather than the issue's { unchanged } | { … } union: TypeScript widens a union of object literals and inferred R | undefined for an edit that returns both.

The tests for the deck and review-state repositories mock the reads of datasets.ts, so their mock now routes an edit's read through the mocked getSolidDatasetOrNull too, as it already did for a removal's read. editDocument's own behavior is tested once, in datasets.edit.test.ts. The adapters' own 412 tests stay, as checks of each adapter's behavior.

What the app writes to a pod, and when it tries again, stays the same. docs/data-model.md names editDocument in the write discipline.

The full check passes on each commit, and reuse lint passes for the new test file.

Left out, as the issue says: a grade's single try on the dataset it holds, removeOwned, and the preference writes. The retry loops in packages/application (cards.ts, writes.ts, releaseDrafts.ts) retry whole use cases a layer up and are not part of this.

Closes: #995

ixuz added 6 commits November 24, 2026 09:22
…ment

Writes that must hold up while their document changes elsewhere each
wrote the same loop by hand: read, change, check, save If-Match the
read, and on a 412 read and change again, a few times in all. The
policy (how many tries, a pause between them, which failures call for
another try, where the check runs) was spread over every adapter that
made such a write, each with its own count and its own comment.

editDocument in datasets.ts is that loop, once, beside saveDataset and
PreconditionFailedError. A caller says only what its edit makes of the
document as read: nothing to write, or the dataset, the subjects to
check and whether to write it whole. The type index's changeIndex,
which already had this shape, is the first to go onto it. What it
writes, and when it tries again, stays the same.

Refs: #995
The catalog's links to drafts and releases were written by a retry
loop of their own, with its own count. They are now an edit of the
catalog made by editDocument, so the catalog's links keep only what is
theirs: none added without a catalog, and none past the limit. What is
written, and when it is tried again, stays the same.

Refs: #995
Removing a day's answers from a month's document tried again on a 412
with a loop and a count of its own. It is now an edit of the document
made by editDocument, and keeps only what it removes: the document's
own answers that the caller picks. What is written, and when it is
tried again, stays the same.

Refs: #995
Adding a deck's entry, editing the deck groups and editing an entry for
a term no shape owns each tried the catalog again on a 412 with a loop
of their own, sharing a count. Each is now an edit of the catalog made
by editDocument: it keeps its own rules (an entry not there yet, the
deck list and the groups within their limits, the subjects it checks)
and leaves the tries to editDocument. What is written, and when it is
tried again, stays the same.

The repository's tests mock the reads of datasets.ts, so an edit's
read goes through that mock too, as a removal's read already does.

Refs: #995
writeFsrsStates read and wrote a deck's reviews document again on a
412 with a loop and a count of its own. It is now an edit of the
document made by editDocument, checked as every other write of the
reviews is (checkedReviews), so it keeps only what it writes: the
FSRS-6 states the caller makes of those read. What is written, and when
it is tried again, stays the same.

A grade is left as it is: it makes one try on the document as last
read or written before it reads it again, not a loop.

Refs: #995
The digest's write was the last loop of its own: read, change, check,
save If-Match, and on a 412 read and change again, with a pause that
grows before each try and six tries in all. It is now an edit of the
digest made by editDocument with that count and pause. A failure of
the check or the save that says the pod or the app refused what was
written is still told apart from one of the read, so changes refused
together are still written again one at a time.

Every write in the Solid adapters that re-applies a change on a 412 now
goes through editDocument, which the data model's write discipline now
says.

Closes: #995
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The Solid adapters each write their own read, change and If-Match save loop for a document that changes elsewhere

1 participant