MCPcopy
hub / github.com/tinyplex/tinybase / createMergeableStore

Function createMergeableStore

docs/pseudo.esm.sh/tinybase@9.0.0/index.js:2552–2969  ·  view source on GitHub ↗
(uniqueId, getNow)

Source from the content-addressed store, hash-verified

2550 )
2551);
2552var createMergeableStore = (uniqueId, getNow) => {
2553 let listeningToRawStoreChanges = 1;
2554 let contentStampMap = newContentStampMap();
2555 let defaultingContent = 0;
2556 let mutated = 0;
2557 const touchedCells = mapNew();
2558 const touchedValues = setNew();
2559 const [getNextHlc, seenHlc] = getHlcFunctions(uniqueId, getNow);
2560 const store = createStore();
2561 const disableListeningToRawStoreChanges = (actions) => {
2562 const wasListening = listeningToRawStoreChanges;
2563 listeningToRawStoreChanges = 0;
2564 actions();
2565 listeningToRawStoreChanges = wasListening;
2566 return mergeableStore;
2567 };
2568 const mergeContentOrChanges = (contentOrChanges, isContent = 0) => {
2569 const tablesChanges = {};
2570 const valuesChanges = {};
2571 const [
2572 [tablesObj, incomingTablesHlc = EMPTY_STRING, incomingTablesHash = 0],
2573 values
2574 ] = contentOrChanges;
2575 const [tablesStampMap, valuesStampMap] = contentStampMap;
2576 const [tableStampMaps, oldTablesHlc, oldTablesHash] = tablesStampMap;
2577 let tablesHash = isContent ? incomingTablesHash : oldTablesHash;
2578 let tablesHlc = incomingTablesHlc;
2579 objForEach(
2580 tablesObj,
2581 ([rowsObj, incomingTableHlc = EMPTY_STRING, incomingTableHash = 0], tableId) => {
2582 const tableStampMap = mapEnsure(tableStampMaps, tableId, stampNewMap);
2583 const [rowStampMaps, oldTableHlc, oldTableHash] = tableStampMap;
2584 let tableHash = isContent ? incomingTableHash : oldTableHash;
2585 let tableHlc = incomingTableHlc;
2586 objForEach(rowsObj, (row, rowId) => {
2587 const [rowHlc, oldRowHash, rowHash] = mergeCellsOrValues(
2588 row,
2589 mapEnsure(rowStampMaps, rowId, stampNewMap),
2590 objEnsure(objEnsure(tablesChanges, tableId, objNew), rowId, objNew),
2591 isContent
2592 );
2593 tableHash ^= isContent ? 0 : addOrRemoveHash(
2594 oldRowHash ? getValueInValuesHash(rowId, oldRowHash) : 0,
2595 getValueInValuesHash(rowId, rowHash)
2596 );
2597 tableHlc = getLatestHlc(tableHlc, rowHlc);
2598 });
2599 tableHash ^= isContent ? 0 : replaceHlcHash(oldTableHlc, incomingTableHlc);
2600 stampUpdate(tableStampMap, incomingTableHlc, tableHash);
2601 tablesHash ^= isContent ? 0 : addOrRemoveHash(
2602 oldTableHash ? getValueInValuesHash(tableId, oldTableHash) : 0,
2603 getValueInValuesHash(tableId, tableStampMap[2])
2604 );
2605 tablesHlc = getLatestHlc(tablesHlc, tableHlc);
2606 }
2607 );
2608 tablesHash ^= isContent ? 0 : replaceHlcHash(oldTablesHlc, incomingTablesHlc);
2609 stampUpdate(tablesStampMap, incomingTablesHlc, tablesHash);

Calls 9

newContentStampMapFunction · 0.70
mapNewFunction · 0.70
setNewFunction · 0.70
getHlcFunctionsFunction · 0.70
createStoreFunction · 0.70
objMapFunction · 0.70
strStartsWithFunction · 0.70
strEndsWithFunction · 0.70
sliceFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…