| 267 | * ``` |
| 268 | */ |
| 269 | export function compareTopologyVersion( |
| 270 | currentTv?: TopologyVersion | null, |
| 271 | newTv?: TopologyVersion | null |
| 272 | ): 0 | -1 | 1 { |
| 273 | if (currentTv == null || newTv == null) { |
| 274 | return -1; |
| 275 | } |
| 276 | |
| 277 | if (!currentTv.processId.equals(newTv.processId)) { |
| 278 | return -1; |
| 279 | } |
| 280 | |
| 281 | // TODO(NODE-2674): Preserve int64 sent from MongoDB |
| 282 | const currentCounter = |
| 283 | typeof currentTv.counter === 'bigint' |
| 284 | ? Long.fromBigInt(currentTv.counter) |
| 285 | : Long.isLong(currentTv.counter) |
| 286 | ? currentTv.counter |
| 287 | : Long.fromNumber(currentTv.counter); |
| 288 | |
| 289 | const newCounter = |
| 290 | typeof newTv.counter === 'bigint' |
| 291 | ? Long.fromBigInt(newTv.counter) |
| 292 | : Long.isLong(newTv.counter) |
| 293 | ? newTv.counter |
| 294 | : Long.fromNumber(newTv.counter); |
| 295 | |
| 296 | return currentCounter.compare(newCounter); |
| 297 | } |