fix: Put entry and index before setting heads to avoid retrieving a head not in the database.

This commit is contained in:
Hayden Young 2025-05-17 01:22:58 +02:00
parent dc150b9cc2
commit 6f72fdddfe
3 changed files with 1118 additions and 2789 deletions

3899
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -35,7 +35,7 @@
"c8": "^8.0.1",
"cross-env": "^7.0.3",
"fs-extra": "^11.2.0",
"helia": "^5.2.1",
"helia": "^5.3.0",
"it-all": "^3.0.4",
"jsdoc": "^4.0.2",
"mocha": "^10.2.0",

View File

@ -48,12 +48,12 @@ const OplogStore = async ({ logHeads, entryStorage, headsStorage, indexStorage,
const setHead = async (entry) => {
const { hash, bytes } = await Entry.encode(entry, encryptEntryFn, encryptPayloadFn)
// The appended entry is now the latest head
await _heads.set([{ hash, next: entry.next }])
// Add entry to the entry storage
await _entries.put(hash, bytes)
// Add entry to the entry index
await _index.put(hash, true)
// The appended entry is now the latest head
await _heads.set([{ hash, next: entry.next }])
return hash
}