import { EventEmitter } from 'events'; import { CommandType } from '../tcp/types/command.types'; import { AxioDBCloudOptions, AuthenticatedUser, ConnectionState } from './types/client.types'; import DatabaseProxy from './DatabaseProxy'; /** * AxioDBCloud - TCP Client for remote AxioDB access * * Maintains a pool of `maxPoolSize` concurrent TCP connections (default: 10, mirrors * MongoDB's driver default naming/behavior) to the same server. Commands are routed to * whichever connected pool member has the fewest in-flight requests, so a slow command * on one connection doesn't queue new commands behind it while other members sit idle; * each member independently reconnects (with exponential backoff) and re-authenticates, * so one dropped connection never affects the others or blocks in-flight commands routed * to healthy members. */ export declare class AxioDBCloud extends EventEmitter { private host; private port; private pool; private options; private credentials?; private readonly tlsCA?; constructor(connectionString: string, options?: AxioDBCloudOptions); /** * Parse connection string: axiodb://host:port */ private parseConnectionString; /** * Open the connection pool. Authenticates the first connection alone (if credentials are * provided) before opening the rest of the pool - this avoids multiplying failed-login * attempts against the server's shared per-IP rate limiter N times over for a single bad * -credentials connect() call, and ensures a bad-credentials failure never leaves any pool * member mid-reconnect. * * The first connection must succeed or `connect()` rejects entirely (it's the signal that * the server is reachable and credentials are valid at all). The rest of the pool uses * allSettled rather than all: if `maxPoolSize` asks for more connections than the server * allows from this IP (see the server's per-IP connection cap) or a handful hit a transient * error, the pool still comes up with however many succeeded instead of failing outright - * a smaller-than-requested pool is far more useful to the caller than no pool at all. */ connect(): Promise; private createPooledConnection; /** * Authenticate with username/password (same RBAC users as the GUI Control Server). * Only required when the server was started with `TCPAuth: true`. * * Authenticates every currently-connected pool member and stashes the credentials so a * later automatic reconnect replays login on any member that drops - otherwise a network * blip after a runtime `login()` call would silently leave the reconnected member * unauthenticated. */ login(username: string, password: string): Promise; /** * The currently authenticated identity, if `login()` (or constructor credentials) * succeeded on at least one pool member. */ get authenticatedUser(): AuthenticatedUser | undefined; sendCommand(command: CommandType, params: any): Promise; /** * Picks the connected pool member with the fewest in-flight requests (least-busy), * rather than round-robin, so a connection stuck on a slow command doesn't receive * more work while other members are idle. */ private pickConnection; disconnect(): Promise; createDB(name: string): Promise; deleteDatabase(name: string): Promise; isDatabaseExists(name: string): Promise; getInstanceInfo(): Promise; /** * Get current connection state - CONNECTED if at least one pool member is connected, * otherwise the "best" state across the pool (RECONNECTING > CONNECTING > FAILED). */ get state(): ConnectionState; /** True when at least one pool member is connected (not necessarily all). */ get isConnected(): boolean; }