( input: RootStreamBuilder<unknown>, changes: Iterable<ChangeMessage>, )
| 279 | * @returns The number of multiset entries sent |
| 280 | */ |
| 281 | export function sendChangesToInput( |
| 282 | input: RootStreamBuilder<unknown>, |
| 283 | changes: Iterable<ChangeMessage>, |
| 284 | ): number { |
| 285 | const multiSetArray: MultiSetArray<unknown> = [] |
| 286 | for (const change of changes) { |
| 287 | const key = change.key |
| 288 | if (change.type === `insert`) { |
| 289 | multiSetArray.push([[key, change.value], 1]) |
| 290 | } else if (change.type === `update`) { |
| 291 | multiSetArray.push([[key, change.previousValue], -1]) |
| 292 | multiSetArray.push([[key, change.value], 1]) |
| 293 | } else { |
| 294 | // change.type === `delete` |
| 295 | multiSetArray.push([[key, change.value], -1]) |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | if (multiSetArray.length !== 0) { |
| 300 | input.sendData(new MultiSet(multiSetArray)) |
| 301 | } |
| 302 | |
| 303 | return multiSetArray.length |
| 304 | } |
| 305 | |
| 306 | /** Splits updates into a delete of the old value and an insert of the new value */ |
| 307 | export function* splitUpdates< |
no test coverage detected