UNPKG

@ydbjs/core

Version:

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

38 lines 1.42 kB
import { loggers } from '@ydbjs/debug'; import { createChannel, } from 'nice-grpc'; let dbg = loggers.driver.extend('conn'); /** * A single gRPC connection to a YDB node. */ export class GrpcConnection { endpoint; #channel; constructor(endpoint, channelCredentials, channelOptions) { let address = `${endpoint.address}:${endpoint.port}`; // Freeze the value object so hooks receive a stable, immutable reference // without being able to accidentally mutate driver internals. this.endpoint = Object.freeze({ nodeId: BigInt(endpoint.nodeId), address, location: endpoint.location, }); dbg.log('create channel to node id=%d address=%s', this.endpoint.nodeId, address); this.#channel = createChannel(address, channelCredentials, { ...channelOptions, // Required when the TLS certificate CN doesn't match the gRPC endpoint // address (common in YDB deployments behind a load balancer). 'grpc.ssl_target_name_override': endpoint.sslTargetNameOverride, }); } get channel() { return this.#channel; } close() { dbg.log('close channel to node id=%d address=%s', this.endpoint.nodeId, this.endpoint.address); this.#channel.close(); } [Symbol.dispose]() { this.close(); } } //# sourceMappingURL=conn.js.map