MCPcopy Create free account
hub / github.com/TanStack/db / processMoveOutEvent

Function processMoveOutEvent

packages/electric-db-collection/src/electric.ts:1215–1252  ·  view source on GitHub ↗
(
    patterns: Array<MovePattern>,
    begin: () => void,
    write: (message: ChangeMessageOrDeleteKeyMessage<T>) => void,
    transactionStarted: boolean,
  )

Source from the content-addressed store, hash-verified

1213 * Process move-out event: remove matching tags from rows and delete rows with empty tag sets
1214 */
1215 const processMoveOutEvent = (
1216 patterns: Array<MovePattern>,
1217 begin: () => void,
1218 write: (message: ChangeMessageOrDeleteKeyMessage<T>) => void,
1219 transactionStarted: boolean,
1220 ): boolean => {
1221 if (tagLength === undefined) {
1222 debug(
1223 `${collectionId ? `[${collectionId}] ` : ``}Received move-out message but no tag length set yet, ignoring`,
1224 )
1225 return transactionStarted
1226 }
1227
1228 let txStarted = transactionStarted
1229
1230 // Process all patterns and collect rows to delete
1231 for (const pattern of patterns) {
1232 // Find all rows that match this pattern
1233 const affectedRowIds = findRowsMatchingPattern(pattern, tagIndex)
1234
1235 for (const rowId of affectedRowIds) {
1236 if (removeMatchingTagsFromRow(rowId, pattern)) {
1237 // Delete rows with empty tag sets
1238 if (!txStarted) {
1239 begin()
1240 txStarted = true
1241 }
1242
1243 write({
1244 type: `delete`,
1245 key: rowId,
1246 })
1247 }
1248 }
1249 }
1250
1251 return txStarted
1252 }
1253
1254 /**
1255 * Process move-in event: re-activate conditions for rows matching the patterns.

Callers 1

createElectricSyncFunction · 0.85

Calls 3

findRowsMatchingPatternFunction · 0.90
debugFunction · 0.85

Tested by

no test coverage detected