CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
events.ts220 linesDownload Raw Back to sdam
1import type { Document } from '../bson';2import {3  SERVER_CLOSED,4  SERVER_DESCRIPTION_CHANGED,5  SERVER_HEARTBEAT_FAILED,6  SERVER_HEARTBEAT_STARTED,7  SERVER_HEARTBEAT_SUCCEEDED,8  SERVER_OPENING,9  TOPOLOGY_CLOSED,10  TOPOLOGY_DESCRIPTION_CHANGED,11  TOPOLOGY_OPENING12} from '../constants';13import type { ServerDescription } from './server_description';14import type { TopologyDescription } from './topology_description';15 16/**17 * Emitted when server description changes, but does NOT include changes to the RTT.18 * @public19 * @category Event20 */21export class ServerDescriptionChangedEvent {22  /** A unique identifier for the topology */23  topologyId: number;24  /** The address (host/port pair) of the server */25  address: string;26  /** The previous server description */27  previousDescription: ServerDescription;28  /** The new server description */29  newDescription: ServerDescription;30  name = SERVER_DESCRIPTION_CHANGED;31 32  /** @internal */33  constructor(34    topologyId: number,35    address: string,36    previousDescription: ServerDescription,37    newDescription: ServerDescription38  ) {39    this.topologyId = topologyId;40    this.address = address;41    this.previousDescription = previousDescription;42    this.newDescription = newDescription;43  }44}45 46/**47 * Emitted when server is initialized.48 * @public49 * @category Event50 */51export class ServerOpeningEvent {52  /** A unique identifier for the topology */53  topologyId: number;54  /** The address (host/port pair) of the server */55  address: string;56  /** @internal */57  name = SERVER_OPENING;58 59  /** @internal */60  constructor(topologyId: number, address: string) {61    this.topologyId = topologyId;62    this.address = address;63  }64}65 66/**67 * Emitted when server is closed.68 * @public69 * @category Event70 */71export class ServerClosedEvent {72  /** A unique identifier for the topology */73  topologyId: number;74  /** The address (host/port pair) of the server */75  address: string;76  /** @internal */77  name = SERVER_CLOSED;78 79  /** @internal */80  constructor(topologyId: number, address: string) {81    this.topologyId = topologyId;82    this.address = address;83  }84}85 86/**87 * Emitted when topology description changes.88 * @public89 * @category Event90 */91export class TopologyDescriptionChangedEvent {92  /** A unique identifier for the topology */93  topologyId: number;94  /** The old topology description */95  previousDescription: TopologyDescription;96  /** The new topology description */97  newDescription: TopologyDescription;98  /** @internal */99  name = TOPOLOGY_DESCRIPTION_CHANGED;100 101  /** @internal */102  constructor(103    topologyId: number,104    previousDescription: TopologyDescription,105    newDescription: TopologyDescription106  ) {107    this.topologyId = topologyId;108    this.previousDescription = previousDescription;109    this.newDescription = newDescription;110  }111}112 113/**114 * Emitted when topology is initialized.115 * @public116 * @category Event117 */118export class TopologyOpeningEvent {119  /** A unique identifier for the topology */120  topologyId: number;121  /** @internal */122  name = TOPOLOGY_OPENING;123 124  /** @internal */125  constructor(topologyId: number) {126    this.topologyId = topologyId;127  }128}129 130/**131 * Emitted when topology is closed.132 * @public133 * @category Event134 */135export class TopologyClosedEvent {136  /** A unique identifier for the topology */137  topologyId: number;138  /** @internal */139  name = TOPOLOGY_CLOSED;140 141  /** @internal */142  constructor(topologyId: number) {143    this.topologyId = topologyId;144  }145}146 147/**148 * Emitted when the server monitor’s hello command is started - immediately before149 * the hello command is serialized into raw BSON and written to the socket.150 *151 * @public152 * @category Event153 */154export class ServerHeartbeatStartedEvent {155  /** The connection id for the command */156  connectionId: string;157  /** Is true when using the streaming protocol */158  awaited: boolean;159  /** @internal */160  name = SERVER_HEARTBEAT_STARTED;161 162  /** @internal */163  constructor(connectionId: string, awaited: boolean) {164    this.connectionId = connectionId;165    this.awaited = awaited;166  }167}168 169/**170 * Emitted when the server monitor’s hello succeeds.171 * @public172 * @category Event173 */174export class ServerHeartbeatSucceededEvent {175  /** The connection id for the command */176  connectionId: string;177  /** The execution time of the event in ms */178  duration: number;179  /** The command reply */180  reply: Document;181  /** Is true when using the streaming protocol */182  awaited: boolean;183  /** @internal */184  name = SERVER_HEARTBEAT_SUCCEEDED;185 186  /** @internal */187  constructor(connectionId: string, duration: number, reply: Document | null, awaited: boolean) {188    this.connectionId = connectionId;189    this.duration = duration;190    this.reply = reply ?? {};191    this.awaited = awaited;192  }193}194 195/**196 * Emitted when the server monitor’s hello fails, either with an “ok: 0” or a socket exception.197 * @public198 * @category Event199 */200export class ServerHeartbeatFailedEvent {201  /** The connection id for the command */202  connectionId: string;203  /** The execution time of the event in ms */204  duration: number;205  /** The command failure */206  failure: Error;207  /** Is true when using the streaming protocol */208  awaited: boolean;209  /** @internal */210  name = SERVER_HEARTBEAT_FAILED;211 212  /** @internal */213  constructor(connectionId: string, duration: number, failure: Error, awaited: boolean) {214    this.connectionId = connectionId;215    this.duration = duration;216    this.failure = failure;217    this.awaited = awaited;218  }219}220