@ydbjs/core
Version:
Core driver for YDB: manages connections, endpoint discovery, authentication, and service client creation. Foundation for all YDB client operations.
85 lines • 3.29 kB
TypeScript
import * as tls from 'node:tls';
import type { CredentialsProvider } from '@ydbjs/auth';
import { type ChannelOptions, type Client, type CompatServiceDefinition } from 'nice-grpc';
import type { DriverIdentity } from './driver-identity.js';
import type { DriverHooks, EndpointInfo } from './hooks.js';
export type { DriverHooks, EndpointInfo };
export type DriverOptions = {
/**
* SSL/TLS options for secure connections.
*
* @deprecated Use `secureOptions` instead.
*/
ssl?: tls.SecureContextOptions;
secureOptions?: tls.SecureContextOptions | undefined;
channelOptions?: ChannelOptions;
credentialsProvider?: CredentialsProvider;
/**
* Optional driver hooks.
*
* Hooks are synchronous, zero-cost when unused, and fire in the caller's
* AsyncLocalStorage context so OpenTelemetry trace.getActiveSpan() works.
*
* @example
* ```ts
* hooks: {
* onCall(event) {
* let span = tracer.startSpan('ydb.rpc')
* return (complete) => { span.end() }
* },
* onPessimize(event) {
* console.warn('node pessimized', event.endpoint.address)
* },
* }
* ```
*/
hooks?: DriverHooks;
'ydb.sdk.application'?: string;
'ydb.sdk.ready_timeout_ms'?: number;
'ydb.sdk.token_timeout_ms'?: number;
'ydb.sdk.enable_discovery'?: boolean;
'ydb.sdk.discovery_timeout_ms'?: number;
'ydb.sdk.discovery_interval_ms'?: number;
'ydb.sdk.connection_idle_timeout_ms'?: number;
'ydb.sdk.connection_idle_interval_ms'?: number;
'ydb.sdk.connection_pessimization_timeout_ms'?: number;
};
export declare const kRegisterLibrary: unique symbol;
export declare class Driver implements Disposable {
#private;
readonly cs: URL;
readonly options: DriverOptions;
constructor(connectionString: string, userOptions?: Readonly<DriverOptions>);
get token(): Promise<string>;
get database(): string;
get isSecure(): boolean;
get application(): string;
/**
* Stable identity stamped onto every `diagnostics_channel` payload so
* subscribers can attribute events to a specific Driver instance without
* any AsyncLocalStorage cooperation from the publisher.
*
* Returns the same frozen object for the lifetime of the driver —
* subscribers may use it as a Map key for per-driver state.
*/
get identity(): DriverIdentity;
ready(signal?: AbortSignal): Promise<void>;
close(): void;
/**
* Create a nice-grpc client for the given service.
*
* When discovery is enabled, each RPC is routed through a BalancedChannel
* that acquires a connection from the pool exactly once per RPC.
*
* When discovery is disabled, the single initial connection is used directly
* (no pool, no balancing).
*
* @param service gRPC service definition
* @param preferNodeId Optional nodeId hint — route RPCs to this node when possible.
*/
createClient<Service extends CompatServiceDefinition>(service: Service, preferNodeId?: bigint): Client<Service>;
[Symbol.dispose](): void;
[Symbol.asyncDispose](): PromiseLike<void>;
[kRegisterLibrary](name: string, version: string): void;
}
//# sourceMappingURL=driver.d.ts.map