CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
common.ts75 linesDownload Raw Back to sdam
1import type { Binary, Long, Timestamp } from '../bson';2import type { ClientSession } from '../sessions';3import type { Topology } from './topology';4 5// shared state names6export const STATE_CLOSING = 'closing';7export const STATE_CLOSED = 'closed';8export const STATE_CONNECTING = 'connecting';9export const STATE_CONNECTED = 'connected';10 11/**12 * An enumeration of topology types we know about13 * @public14 */15export const TopologyType = Object.freeze({16  Single: 'Single',17  ReplicaSetNoPrimary: 'ReplicaSetNoPrimary',18  ReplicaSetWithPrimary: 'ReplicaSetWithPrimary',19  Sharded: 'Sharded',20  Unknown: 'Unknown',21  LoadBalanced: 'LoadBalanced'22} as const);23 24/** @public */25export type TopologyType = (typeof TopologyType)[keyof typeof TopologyType];26 27/**28 * An enumeration of server types we know about29 * @public30 */31export const ServerType = Object.freeze({32  Standalone: 'Standalone',33  Mongos: 'Mongos',34  PossiblePrimary: 'PossiblePrimary',35  RSPrimary: 'RSPrimary',36  RSSecondary: 'RSSecondary',37  RSArbiter: 'RSArbiter',38  RSOther: 'RSOther',39  RSGhost: 'RSGhost',40  Unknown: 'Unknown',41  LoadBalancer: 'LoadBalancer'42} as const);43 44/** @public */45export type ServerType = (typeof ServerType)[keyof typeof ServerType];46 47/**48 * @public49 * Gossiped in component for the cluster time tracking the state of user databases50 * across the cluster. It may optionally include a signature identifying the process that51 * generated such a value.52 */53export interface ClusterTime {54  clusterTime: Timestamp;55  /** Used to validate the identity of a request or response's ClusterTime. */56  signature?: {57    hash: Binary;58    keyId: Long;59  };60}61 62/** Shared function to determine clusterTime for a given topology or session */63export function _advanceClusterTime(64  entity: Topology | ClientSession,65  $clusterTime: ClusterTime66): void {67  if (entity.clusterTime == null) {68    entity.clusterTime = $clusterTime;69  } else {70    if ($clusterTime.clusterTime.greaterThan(entity.clusterTime.clusterTime)) {71      entity.clusterTime = $clusterTime;72    }73  }74}75