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

Function mergeContentOrChanges

src/mergeable-store/index.ts:184–269  ·  view source on GitHub ↗
(
    contentOrChanges: MergeableChanges | MergeableContent,
    isContent: 0 | 1 = 0,
  )

Source from the content-addressed store, hash-verified

182 };
183
184 const mergeContentOrChanges = (
185 contentOrChanges: MergeableChanges | MergeableContent,
186 isContent: 0 | 1 = 0,
187 ): Changes => {
188 const tablesChanges = {};
189 const valuesChanges = {};
190 const [
191 [tablesObj, incomingTablesHlc = EMPTY_STRING, incomingTablesHash = 0],
192 values,
193 ] = contentOrChanges as typeof isContent extends 1
194 ? MergeableContent
195 : MergeableChanges;
196 const [tablesStampMap, valuesStampMap] = contentStampMap;
197 const [tableStampMaps, oldTablesHlc, oldTablesHash] = tablesStampMap;
198
199 let tablesHash = isContent ? incomingTablesHash : oldTablesHash;
200 let tablesHlc = incomingTablesHlc;
201 objForEach(
202 tablesObj,
203 (
204 [rowsObj, incomingTableHlc = EMPTY_STRING, incomingTableHash = 0],
205 tableId,
206 ) => {
207 const tableStampMap = mapEnsure<Id, TableStampMap>(
208 tableStampMaps,
209 tableId,
210 stampNewMap,
211 );
212 const [rowStampMaps, oldTableHlc, oldTableHash] = tableStampMap;
213 let tableHash = isContent ? incomingTableHash : oldTableHash;
214 let tableHlc = incomingTableHlc;
215 objForEach(rowsObj, (row, rowId) => {
216 const [rowHlc, oldRowHash, rowHash] = mergeCellsOrValues(
217 row,
218 mapEnsure<Id, RowStampMap>(rowStampMaps, rowId, stampNewMap),
219 objEnsure<IdObj<CellOrUndefined>>(
220 objEnsure<IdObj<IdObj<CellOrUndefined>>>(
221 tablesChanges,
222 tableId,
223 objNew,
224 ),
225 rowId,
226 objNew,
227 ),
228 isContent,
229 );
230
231 tableHash ^= isContent
232 ? 0
233 : addOrRemoveHash(
234 oldRowHash ? getValueInValuesHash(rowId, oldRowHash) : 0,
235 getValueInValuesHash(rowId, rowHash),
236 );
237 tableHlc = getLatestHlc(tableHlc, rowHlc);
238 });
239
240 tableHash ^= isContent
241 ? 0

Callers 4

cellChangedFunction · 0.70
valueChangedFunction · 0.70
setMergeableContentFunction · 0.70
applyMergeableChangesFunction · 0.70

Calls 10

objForEachFunction · 0.90
mapEnsureFunction · 0.90
objEnsureFunction · 0.90
addOrRemoveHashFunction · 0.90
getValueInValuesHashFunction · 0.90
getLatestHlcFunction · 0.90
replaceHlcHashFunction · 0.90
stampUpdateFunction · 0.90
mergeCellsOrValuesFunction · 0.70
seenHlcFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…