| 2297 | } |
| 2298 | |
| 2299 | function accumulateChanges<T>( |
| 2300 | acc: Map<unknown, Changes<T>>, |
| 2301 | [[key, tupleData], multiplicity]: [ |
| 2302 | [unknown, [any, string | undefined]], |
| 2303 | number, |
| 2304 | ], |
| 2305 | ) { |
| 2306 | // All queries now consistently return [value, orderByIndex] format |
| 2307 | // where orderByIndex is undefined for queries without ORDER BY |
| 2308 | const [value, orderByIndex] = tupleData as [T, string | undefined] |
| 2309 | |
| 2310 | const changes = acc.get(key) || { |
| 2311 | deletes: 0, |
| 2312 | inserts: 0, |
| 2313 | value, |
| 2314 | orderByIndex, |
| 2315 | } |
| 2316 | if (multiplicity < 0) { |
| 2317 | changes.deletes += Math.abs(multiplicity) |
| 2318 | } else if (multiplicity > 0) { |
| 2319 | changes.inserts += multiplicity |
| 2320 | // Update value to the latest version for this key |
| 2321 | changes.value = value |
| 2322 | if (orderByIndex !== undefined) { |
| 2323 | changes.orderByIndex = orderByIndex |
| 2324 | } |
| 2325 | } |
| 2326 | acc.set(key, changes) |
| 2327 | return acc |
| 2328 | } |