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

Function getTransactionMergeableChangesImpl

src/mergeable-store/index.ts:423–483  ·  view source on GitHub ↗
(
    withHashes: boolean,
    encoded = false,
  )

Source from the content-addressed store, hash-verified

421 ];
422
423 const getTransactionMergeableChangesImpl = (
424 withHashes: boolean,
425 encoded = false,
426 ): MergeableChanges<typeof withHashes> => {
427 const [
428 [tableStampMaps, tablesHlc, tablesHash],
429 [valueStampMaps, valuesHlc, valuesHash],
430 ] = contentStampMap;
431
432 const newStamp = withHashes ? stampNewWithHash : stampNew;
433
434 const tablesObj: TablesStamp<typeof withHashes>[0] = {};
435 collForEach(touchedCells, (touchedTable, tableId) =>
436 ifNotUndefined(
437 mapGet(tableStampMaps, tableId),
438 ([rowStampMaps, tableHlc, tableHash]) => {
439 const tableObj: TableStamp<typeof withHashes>[0] = {};
440 collForEach(touchedTable, (touchedRow, rowId) =>
441 ifNotUndefined(
442 mapGet(rowStampMaps, rowId),
443 ([cellStampMaps, rowHlc, rowHash]) => {
444 const rowObj: RowStamp<typeof withHashes>[0] = {};
445 collForEach(touchedRow, (cellId) => {
446 ifNotUndefined(
447 mapGet(cellStampMaps, cellId),
448 ([cell, time, hash]) =>
449 (rowObj[cellId] = newStamp(
450 encoded ? cell : decodeIfJson(cell),
451 time,
452 hash,
453 )),
454 );
455 });
456 tableObj[rowId] = newStamp(rowObj, rowHlc, rowHash);
457 },
458 ),
459 );
460 tablesObj[tableId] = newStamp(tableObj, tableHlc, tableHash);
461 },
462 ),
463 );
464
465 const valuesObj: ValuesStamp<typeof withHashes>[0] = {};
466 collForEach(touchedValues, (valueId) =>
467 ifNotUndefined(
468 mapGet(valueStampMaps, valueId),
469 ([value, time, hash]) =>
470 (valuesObj[valueId] = newStamp(
471 encoded ? value : decodeIfJson(value),
472 time,
473 hash,
474 )),
475 ),
476 );
477
478 return [
479 newStamp(tablesObj, tablesHlc, tablesHash),
480 newStamp(valuesObj, valuesHlc, valuesHash),

Calls 3

collForEachFunction · 0.90
mapGetFunction · 0.90
decodeIfJsonFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…