UNPKG

@ydbjs/core

Version:

Core driver for YDB: manages connections, endpoint discovery, authentication, and service client creation. Foundation for all YDB client operations.

39 lines 1.29 kB
import { loggers } from '@ydbjs/debug'; import { createChannel, } from 'nice-grpc'; let dbg = loggers.driver.extend('conn'); export class LazyConnection { #endpoint; #channel = null; #channelOptions; #channelCredentials; pessimizedUntil; constructor(endpoint, channelCredentials, channelOptions) { this.#endpoint = endpoint; this.#channelOptions = { ...channelOptions, 'grpc.ssl_target_name_override': endpoint.sslTargetNameOverride, }; this.#channelCredentials = channelCredentials; } get nodeId() { return BigInt(this.#endpoint.nodeId); } get address() { return `${this.#endpoint.address}:${this.#endpoint.port}`; } get channel() { if (this.#channel === null) { dbg.log('create channel to node id=%d address=%s', this.nodeId, this.address); this.#channel = createChannel(this.address, this.#channelCredentials, this.#channelOptions); } return this.#channel; } close() { if (this.#channel) { dbg.log('close channel to node id=%d address=%s', this.nodeId, this.address); this.#channel.close(); this.#channel = null; } } } //# sourceMappingURL=conn.js.map