import type { CallOptions, MethodParams, ServerMethods } from '@helenejs/utils'; import { Presentation, PromiseQueue } from '@helenejs/utils'; import { ClientChannel } from './client-channel'; import { ClientHttp } from './client-http'; import { ClientSocket } from './client-socket'; import { IdleTimeout } from './idle-timeout'; import Timeout = NodeJS.Timeout; export type ErrorHandler = (error: Record) => any; export type WebSocketOptions = { path?: string; /** * Workaround for Safari not reconnecting after the app is brought back to the foreground. */ disconnectOnPageHide?: boolean; }; export type WebSocketRequestParams = { [x: string]: any; [x: number]: any; }; /** * Declarative way to define transport mode. Can be changed at runtime. */ export declare enum TransportMode { /** * HTTP Only. No reactivity, no real-time, no nothing. Just plain old HTTP requests. */ HttpOnly = "HTTP_ONLY", /** * Server-Sent Events. It is a one-way communication channel from the server + HTTP calls. */ HttpSSE = "HTTP_SSE", /** * WebSocket. It is a two-way communication channel. */ WebSocket = "WEBSOCKET" } export type ClientOptions = { host?: string; port?: number; mode?: TransportMode; secure?: boolean; ws?: WebSocketOptions; errorHandler?: ErrorHandler; debug?: boolean; allowedContextKeys?: string[]; meta?: Record; idlenessTimeout?: number; }; export type ProxyMethodCall = { [key: string]: ProxyMethodCall; } & ((params?: MethodParams, options?: CallOptions) => Promise); /** * When working with Next.js, it is probably a good idea to not run this in the * server side by using it inside a `useEffect` hook. */ export declare class Client extends ClientChannel { #private; uuid: string; queue: PromiseQueue; clientSocket: ClientSocket; clientHttp: ClientHttp; context: Record; errorHandler: ErrorHandler; channels: Map; timeouts: Set; initialized: boolean; authenticated: boolean; options: ClientOptions; initializing: boolean; idleTimeout: IdleTimeout; m: MethodsType; static ENABLE_HEARTBEAT: boolean; constructor(options?: ClientOptions); mode: { options: ClientOptions; readonly http: boolean; readonly eventsource: boolean; readonly websocket: boolean; }; get isConnecting(): boolean; get isOffline(): boolean; get isOnline(): boolean; get connected(): boolean; connect(): Promise; debugger(...args: any[]): void; loadContext(): void; setContext(context: Record): void; setContextAndReInit(context: Record): Promise; updateContext(context: any): void; clearContext(): void; close(): Promise; /** * Initializes the client. It should be called before any other method. * * It should be called whenever a transport is connected, either on reconnection or from calling `connect`. */ initialize(): Promise; /** * The login method is always called via http so a http-only cookie can be set if the user so prefers. */ login(params: WebSocketRequestParams, opts?: CallOptions): Promise; logout(): Promise; resubscribeAllChannels(): Promise; disconnect(): Promise; /** * Calls a method without expecting a return value. */ void(method: string, params?: MethodParams, { http, httpFallback }?: CallOptions): Promise; call

, R = any>(method: string, params?: P, options?: CallOptions): Promise; typed(types: T): Client; combine(methods: T): Client & MethodsType>; handleError(payload: Presentation.Payload): void; handleEvent(payload: Presentation.Payload): boolean; handleResult(payload: Presentation.Payload): void; payloadRouter(payload: Presentation.Payload): boolean | void; /** * Generates a URL path from string parts. The last argument can be a query * string object definition. */ href(...path: (string | Record)[]): string; channel(name?: string | object): ClientChannel; isConnected(): Promise; attachDevTools(): Promise; fetch(url: string, options: any): Promise; } export type InferClientMethods = T['m'];