export * from './index'; export interface KabelPeer { readonly __kabelPeerBrand: never; } /** A token, or a source read at every connection and for refreshes. */ export type KabelToken = string | (() => string | Promise); export interface KabelPeerOptions { token?: KabelToken; onAuth?: (principal: Record) => void; onError?: (error: any) => void; } export type KabelStatus = | 'connecting' | 'connected' | 'authenticated' | 'disconnected' | 'failed' | 'stopped'; export interface KabelStatusEvent { status: KabelStatus; attempt?: number; error?: string; reason?: string; principal?: Record; [key: string]: unknown; } export interface KabelMaintainOptions { onStatus?: (event: KabelStatusEvent) => void; backoff?: { 'initial-ms'?: number; 'max-ms'?: number; factor?: number; jitter?: number }; maxAttempts?: number; } export interface KabelMaintainHandle { /** Stop reconnecting and close the current connection. */ stop: () => void; /** Resolves once the reconnection loop has ended. */ done: Promise; } export interface KabelWriterConfig { backend: ':kabel'; 'peer-id': import('./index').DatahikeUuid; 'local-peer': KabelPeer; url?: string; } export function createKabelPeer( clientId: import('./index').DatahikeUuid, options?: KabelPeerOptions ): KabelPeer; /** Connect once; resolves with the server's peer id when remote calls work. */ export function connectKabelPeer(peer: KabelPeer, url: string): Promise; /** Keep the peer connected across drops, with backoff and status events. */ export function maintainKabelPeer(peer: KabelPeer, url: string, options?: KabelMaintainOptions): KabelMaintainHandle; /** Replace the token on the live connection; resolves with the accepted principal. */ export function refreshKabelToken(peer: KabelPeer, token?: string): Promise>; /** Invoke a function served by the peer remoteId, by its 'namespace/name'. */ export function invokeRemote( peer: KabelPeer, remoteId: import('./index').DatahikeUuid, fnName: string, args?: Record ): Promise; /** Serve a function from this process; the server may call back into it. */ export function registerRemoteFn( fnName: string, fn: (args: Record) => unknown | Promise ): string; export function unregisterRemoteFn(fnName: string): void; export function stopKabelPeer(peer: KabelPeer): Promise;