Closed jchris closed 5 months ago
Some work has been done, check out the refactored commit internal: https://github.com/fireproof-storage/fireproof/blob/f0f64b8d727651c3a0ba56749439d885c24b4400/packages/fireproof/src/loader.ts#L182
if anyone wants a fun refactor, you could change loader.ts commit into commitFiles, commitIndex, and commitTransaction, and update the callpoints in transaction.ts and crtd-helpers.ts -- you should be able to get away with only changing loader.test.js to get it working
released in 0.16 and available here https://www.npmjs.com/package/@fireproof/encrypted-blockstore
From: https://fireproof.storage/posts/roadmap-to-1.0/
Going through the codebase, here are some refactors that could pave the way for extracting the blockstore:
The Loader / Loaders
Currently there are DbLoader, FileLoader, and IndexLoader classes. They are use by the blockstore to fetch blocks by cid, and to commit new transactions (which are sets of blocks with cids). The differences are in the car file header they write, and the work they do to the internal metadata when they commit. There are also differences in the callback they use when updates come from the cloud. The db header application handles the CRDT merging etc. The idx header handles snapping to the new index head, and the files headers are never applied because they are lazy loaded.
Transaction
Transactions are triggerd by
blockstore.transaction(tblocks => tblocks.put(cid, bytes))
The transaction blockstore takes care of serving blocks from memory when available, and loading from the loader when needed. Transactions are written through the loader.
The transaction is committed in
loader.ts
Here are the internal steps of that function:
So it should probably be split into different implementations for indexer, db, file, instead of sharing one function.
RemoteWAL
The remote wal accumulates outbound writes before a connector is applied, so it needs to be in the main package. It also shares the build issues with the local data adapter.