UNPKG

@dstanesc/o-o-o-o-o-o-o

Version:

O-O-O-O-O-O-O is a collection of content addressed persistent data structures

67 lines 2.53 kB
import { blockIndexFactory } from './block-index'; const stagingBlockStoreFactory = (linkCodec, stage) => { const { put, get } = stage; const pushMany = async (cids, otherStore) => { for (const cid of cids) { const bytes = await get(cid); await otherStore.put({ cid, bytes }); } }; const loadMany = async (cids, fromStore) => { for (const cid of cids) { const bytes = await fromStore.get(cid); await put({ cid, bytes }); } }; const pushVersion = async (versionRoot, otherStore) => { const { buildRootIndex } = blockIndexFactory({ linkCodec, blockStore: stage, }); const { index } = await buildRootIndex(versionRoot); const { vertexIndex, edgeIndex, propIndex, valueIndex, indexIndex, vertexRoot, edgeRoot, propRoot, valueRoot, indexRoot, } = index; const indexes = [ vertexIndex, edgeIndex, propIndex, valueIndex, indexIndex, ]; const roots = [vertexRoot, edgeRoot, propRoot, valueRoot, indexRoot]; for (const idx of indexes) { const { startOffsets } = idx.indexStruct; await pushMany(startOffsets.values(), otherStore); } for (const root of roots) { await pushMany([root], otherStore); } await pushMany([versionRoot], otherStore); }; const loadVersion = async (versionRoot, fromStore) => { const { buildRootIndex } = blockIndexFactory({ linkCodec, blockStore: fromStore, }); const { index } = await buildRootIndex(versionRoot); const { vertexIndex, edgeIndex, propIndex, valueIndex, indexIndex, vertexRoot, edgeRoot, propRoot, valueRoot, indexRoot, } = index; const indexes = [ vertexIndex, edgeIndex, propIndex, valueIndex, indexIndex, ]; const roots = [vertexRoot, edgeRoot, propRoot, valueRoot, indexRoot]; for (const index of indexes) { const { startOffsets } = index.indexStruct; await loadMany(startOffsets.values(), fromStore); } for (const root of roots) { await loadMany([root], fromStore); } await loadMany([versionRoot], fromStore); }; return { get, put, pushVersion, loadVersion }; }; export { stagingBlockStoreFactory }; //# sourceMappingURL=block-store-staging.js.map