Repository navigation
refactor(solid): edit a document that changes elsewhere with editDocument - #996
Merged
Merged
Conversation
…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
ixuz
enabled stacked auto-merge
November 24, 2026 08:38
ixuz
disabled stacked auto-merge
November 24, 2026 08:46
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Writes in
packages/solidthat 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 withIf-Matchthe read, and on a 412 read and changed it again. There were eight copies of that loop and sixATTEMPTSconstants. 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
editDocumentindatasets.ts, besidesaveDatasetandPreconditionFailedError, and moves every one of those writes onto it, one adapter per commit:editDocumentreads the document and asks the adapter's edit what to make of it:{ result, dataset?, subjects?, whole? }, where nodatasetmeans nothing to write. It checks the subjects named, saves withIf-Match(one whole PUT withwhole), and on a 412 reads and edits again, three tries by default.PreconditionFailedErrorincluded (addDeck's "already there"), is thrown at once.attempts,pause(before each try after the first),checkWrite,read(getSolidDatasetOrNullby default; the type index usesreadDataset, so a missing index still throws) andfailure(what a write that fails for good throws instead).changeIndexis gone);addDeck,editDeckTreeandeditEntry;writeFsrsStates;Refusedwrapping. 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 inferredR | undefinedfor 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 mockedgetSolidDatasetOrNulltoo, as it already did for a removal's read.editDocument's own behavior is tested once, indatasets.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.mdnameseditDocumentin the write discipline.The full check passes on each commit, and
reuse lintpasses 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 inpackages/application(cards.ts,writes.ts,releaseDrafts.ts) retry whole use cases a layer up and are not part of this.Closes: #995