JSPM

  • Created
  • Published
  • Downloads 699
  • Score
    100M100P100Q102958F
  • License Apache-2.0

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

Package Exports

  • @ydbjs/core

Readme

@ydbjs/core

The @ydbjs/core package provides the core driver and connection management for YDB in JavaScript/TypeScript. It is the foundation for all YDB client operations, handling connection pooling, service client creation, authentication, and middleware.

Features

  • Connection pooling and load balancing for YDB endpoints
  • Service client creation for any YDB gRPC API
  • Pluggable authentication via @ydbjs/auth providers
  • Automatic endpoint discovery and failover
  • TypeScript support with type definitions
  • Compatible with Node.js and modern runtimes

Installation

npm install @ydbjs/core@alpha

How It Works

  • Driver: The main entry point. Manages connections, endpoint discovery, and authentication.
  • Connection Pool: Maintains and balances gRPC channels to YDB endpoints.
  • Service Clients: Use driver.createClient(ServiceDefinition) to get a typed client for any YDB gRPC service (from @ydbjs/api).
  • Authentication: Pass a credentials provider from @ydbjs/auth to the driver for static, token, anonymous, or cloud metadata authentication.
  • Middleware: Internal middleware handles metadata, authentication, and debugging.

Usage

Basic Example

import { Driver } from '@ydbjs/core';
import { DiscoveryServiceDefinition } from '@ydbjs/api/discovery';

const driver = new Driver('grpc://localhost:2136/local');
await driver.ready();

const discovery = driver.createClient(DiscoveryServiceDefinition);
const endpoints = await discovery.listEndpoints({ database: '/local' });
console.log(endpoints);

await driver.close();

Using Authentication Providers

import { Driver } from '@ydbjs/core';
import { StaticCredentialsProvider } from '@ydbjs/auth/static';

const driver = new Driver('grpc://localhost:2136/local', {
  credentialsProvider: new StaticCredentialsProvider({
    username: 'user',
    password: 'pass',
  }),
});
await driver.ready();
// ...

You can also use AccessTokenCredentialsProvider, AnonymousCredentialsProvider, or MetadataCredentialsProvider from @ydbjs/auth.

Closing the Driver

Always close the driver when done to release resources:

driver.close();

Development

Building the Package

npm run build

Running Tests

npm test

For watch mode during development:

npm run test:watch

License

This project is licensed under the Apache 2.0 License.