MCPcopy Index your code
hub / github.com/tinyplex/tinybase / getChangesFromOtherStore

Function getChangesFromOtherStore

src/synchronizers/index.ts:155–224  ·  view source on GitHub ↗
(
    otherClientId: IdOrNull = null,
    otherContentHashes?: ContentHashes,
    transactionId: Id = getTransactionId(),
  )

Source from the content-addressed store, hash-verified

153 };
154
155 const getChangesFromOtherStore = (
156 otherClientId: IdOrNull = null,
157 otherContentHashes?: ContentHashes,
158 transactionId: Id = getTransactionId(),
159 ): Promise<MergeableChanges | void> =>
160 tryCatch(async () => {
161 if (isUndefined(otherContentHashes)) {
162 [otherContentHashes, otherClientId, transactionId] =
163 await request<ContentHashes>(
164 null,
165 MessageValues.GetContentHashes,
166 EMPTY_STRING,
167 transactionId,
168 );
169 }
170 const [otherTablesHash, otherValuesHash] = otherContentHashes;
171 const [tablesHash, valuesHash] = store.getMergeableContentHashes();
172
173 let tablesChanges: TablesStamp = stampNewObj();
174 if (tablesHash != otherTablesHash) {
175 const [newTables, differentTableHashes] = (
176 await request<[TablesStamp, TableHashes]>(
177 otherClientId,
178 MessageValues.GetTableDiff,
179 store.getMergeableTableHashes(),
180 transactionId,
181 )
182 )[0];
183 tablesChanges = newTables;
184
185 if (!objIsEmpty(differentTableHashes)) {
186 const [newRows, differentRowHashes] = (
187 await request<[TablesStamp, RowHashes]>(
188 otherClientId,
189 MessageValues.GetRowDiff,
190 store.getMergeableRowHashes(differentTableHashes),
191 transactionId,
192 )
193 )[0];
194 mergeTablesStamps(tablesChanges, newRows);
195
196 if (!objIsEmpty(differentRowHashes)) {
197 const newCells = (
198 await request<TablesStamp>(
199 otherClientId,
200 MessageValues.GetCellDiff,
201 store.getMergeableCellHashes(differentRowHashes),
202 transactionId,
203 )
204 )[0];
205 mergeTablesStamps(tablesChanges, newCells);
206 }
207 }
208 }
209
210 return [
211 tablesChanges,
212 valuesHash == otherValuesHash

Callers 2

getPersistedFunction · 0.70
createCustomSynchronizerFunction · 0.70

Calls 11

tryCatchFunction · 0.90
isUndefinedFunction · 0.90
stampNewObjFunction · 0.90
objIsEmptyFunction · 0.90
getTransactionIdFunction · 0.70
mergeTablesStampsFunction · 0.70
getMergeableRowHashesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…