MCPcopy
hub / github.com/mongodb/node-mongodb-native / compareTopologyVersion

Function compareTopologyVersion

src/sdam/server_description.ts:269–297  ·  view source on GitHub ↗
(
  currentTv?: TopologyVersion | null,
  newTv?: TopologyVersion | null
)

Source from the content-addressed store, hash-verified

267 * ```
268 */
269export 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}

Callers 4

isStaleServerDescriptionFunction · 0.90
isStaleErrorFunction · 0.90
equalsMethod · 0.85

Calls 1

equalsMethod · 0.45

Tested by 1