UNPKG

harperdb

Version:

HarperDB is a distributed database, caching service, streaming broker, and application development platform focused on performance and ease of use.

73 lines (72 loc) 2.6 kB
import { WebSocket } from 'ws'; import { EventEmitter } from 'events'; import { type Node } from './knownNodes.ts'; export declare const OPERATION_REQUEST = 136; export declare const CONFIRMATION_STATUS_POSITION = 0; export declare const RECEIVED_VERSION_POSITION = 1; export declare const RECEIVED_TIME_POSITION = 2; export declare const SENDING_TIME_POSITION = 3; export declare const LATENCY_POSITION = 4; export declare const RECEIVING_STATUS_POSITION = 5; export declare const BACK_PRESSURE_RATIO_POSITION = 6; export declare const RECEIVING_STATUS_WAITING = 0; export declare const RECEIVING_STATUS_RECEIVING = 1; export declare const tableUpdateListeners: Map<any, any>; export declare const databaseSubscriptions: Map<any, any>; /** * Handles reconnection, and requesting catch-up */ type NodeSubscription = { name: string; replicateByDefault: boolean; tables: string[]; startTime: number; endTime: number; }; export declare function createWebSocket(url: string, options: { authorization?: string; rejectUnauthorized?: boolean; serverName?: string; }): Promise<any>; /** * This represents a persistent connection to a node for replication, which handles * sockets that may be disconnected and reconnected */ export declare class NodeReplicationConnection extends EventEmitter { socket: WebSocket; startTime: number; retryTime: number; retries: number; isConnected: boolean; isFinished: boolean; nodeSubscriptions?: NodeSubscription[]; latency: number; replicateTablesByDefault: boolean; session: any; sessionResolve: Function; sessionReject: Function; url: string; subscription: any; databaseName: string; nodeName?: string; authorization?: string; constructor(url: string, subscription: any, databaseName: string, nodeName?: string, authorization?: string); connect(): Promise<void>; resetSession(): void; subscribe(nodeSubscriptions: any, replicateTablesByDefault: any): void; unsubscribe(): void; getRecord(request: any): any; } /** * This handles both incoming and outgoing WS allowing either one to issue a subscription and get replication and/or handle subscription requests */ export declare function replicateOverWS(ws: WebSocket, options: any, authorization: Promise<Node | undefined>): { end(): void; getRecord(request: any): Promise<unknown>; /** * Send an operation request to the remote node, returning a promise for the result * @param operation */ sendOperation(operation: any): Promise<unknown>; }; export {};