* Create a ServerDescription * @internal * * @param address - The address of the server * @param hello - An optional hello response for this server
(
address: HostAddress | string,
hello?: Document,
options: ServerDescriptionOptions = {}
)
| 95 | * @param hello - An optional hello response for this server |
| 96 | */ |
| 97 | constructor( |
| 98 | address: HostAddress | string, |
| 99 | hello?: Document, |
| 100 | options: ServerDescriptionOptions = {} |
| 101 | ) { |
| 102 | if (address == null || address === '') { |
| 103 | throw new MongoRuntimeError('ServerDescription must be provided with a non-empty address'); |
| 104 | } |
| 105 | |
| 106 | this.address = |
| 107 | typeof address === 'string' |
| 108 | ? HostAddress.fromString(address).toString() // Use HostAddress to normalize |
| 109 | : address.toString(); |
| 110 | this.type = parseServerType(hello, options); |
| 111 | this.hosts = hello?.hosts?.map((host: string) => host.toLowerCase()) ?? []; |
| 112 | this.passives = hello?.passives?.map((host: string) => host.toLowerCase()) ?? []; |
| 113 | this.arbiters = hello?.arbiters?.map((host: string) => host.toLowerCase()) ?? []; |
| 114 | this.tags = hello?.tags ?? {}; |
| 115 | this.minWireVersion = hello?.minWireVersion ?? 0; |
| 116 | this.maxWireVersion = hello?.maxWireVersion ?? 0; |
| 117 | this.roundTripTime = options?.roundTripTime ?? -1; |
| 118 | this.minRoundTripTime = options?.minRoundTripTime ?? 0; |
| 119 | this.lastUpdateTime = processTimeMS(); |
| 120 | this.lastWriteDate = hello?.lastWrite?.lastWriteDate ?? 0; |
| 121 | // NOTE: This actually builds the stack string instead of holding onto the getter and all its |
| 122 | // associated references. This is done to prevent a memory leak. |
| 123 | this.error = options.error ?? null; |
| 124 | this.error?.stack; |
| 125 | // TODO(NODE-2674): Preserve int64 sent from MongoDB |
| 126 | this.topologyVersion = this.error?.topologyVersion ?? hello?.topologyVersion ?? null; |
| 127 | this.setName = hello?.setName ?? null; |
| 128 | this.setVersion = hello?.setVersion ?? null; |
| 129 | this.electionId = hello?.electionId ?? null; |
| 130 | this.logicalSessionTimeoutMinutes = hello?.logicalSessionTimeoutMinutes ?? null; |
| 131 | this.maxMessageSizeBytes = hello?.maxMessageSizeBytes ?? null; |
| 132 | this.maxWriteBatchSize = hello?.maxWriteBatchSize ?? null; |
| 133 | this.maxBsonObjectSize = hello?.maxBsonObjectSize ?? null; |
| 134 | this.primary = hello?.primary ?? null; |
| 135 | this.me = hello?.me?.toLowerCase() ?? null; |
| 136 | this.$clusterTime = hello?.$clusterTime ?? null; |
| 137 | this.iscryptd = Boolean(hello?.iscryptd); |
| 138 | } |
| 139 | |
| 140 | get hostAddress(): HostAddress { |
| 141 | return HostAddress.fromString(this.address); |
nothing calls this directly
no test coverage detected