UNPKG

@sourceregistry/node-ovsdb

Version:

Open vSwitch Database Management Protocol typescript client

83 lines (82 loc) 3.15 kB
import { DatabaseOperation, DatabaseSchema, JsonValue, MonitorConfig, OvsdbResult, TableUpdate } from './types'; /** * Options for configuring the OVSDBClient. */ export interface OvsdbClientOptions { socketPath?: string; timeout?: number; } /** * A lightweight, typesafe client for interacting with the OVSDB over a Unix socket. * Implements the AsyncDisposable interface for resource management. * No extra functionality should be added to this client than only interact with the low-level database functions of ovs */ export declare class OVSDBClient implements AsyncDisposable { private readonly socketPath; private readonly timeout; private socket; private requestId; private pendingRequests; private isConnected; /** * Creates a new OVSDBClient instance. * @param options - Configuration options for the client. */ constructor(options?: OvsdbClientOptions); /** * Connects to the OVSDB Unix socket. * @returns A promise that resolves when connected. * @throws An error if the socket file does not exist or the connection fails. */ connect(): Promise<this>; /** * Sends a JSON-RPC request to the OVSDB server. * @param method - The RPC method name. * @param params - The parameters for the RPC method. * @returns A promise that resolves with the result. * @throws An error if not connected, if the request times out, or if there is a network error. */ request<T>(method: string, params: JsonValue[]): Promise<T>; listDbs(): Promise<string[]>; getSchema(dbName?: string): Promise<DatabaseSchema>; transact(dbName: string, operations: DatabaseOperation[]): Promise<Array<OvsdbResult<unknown>>>; monitor(dbName: string, monitorId: JsonValue, monitorRequests: Record<string, MonitorConfig[]>): Promise<Record<string, TableUpdate>>; monitorCancel(monitorId: JsonValue): Promise<Record<string, never>>; echo(payload?: JsonValue): Promise<JsonValue[]>; /** * Closes the connection to the OVSDB server. * @returns A promise that resolves when the connection is closed. */ close(): Promise<void>; /** * Implements the AsyncDisposable interface for use with 'using' statements. * This method is called automatically when exiting a 'using' block. * @returns A promise that resolves when cleanup is complete. */ [Symbol.asyncDispose](): Promise<void>; /** * Cleans up the connection and pending requests. * @private */ private _cleanup; /** * Handles incoming data from the socket. * @private * @param data - The raw data received. */ private _handleData; /** * Handles a parsed JSON-RPC response. * @private * @param response - The JSON-RPC response object. */ private _handleResponse; /** * Handles JSON-RPC notifications (e.g., "update", "locked", "stolen"). * This can be overridden by subclasses or event listeners. * @private * @param notification - The notification object. */ private _handleNotification; } export * from './types';