type ArgumentsType = T extends (...args: infer A) => any ? A : never; type ReturnType = T extends (...args: any) => infer R ? R : never; type PromisifyFn = ReturnType extends Promise ? T : (...args: ArgumentsType) => Promise>>; type BirpcResolver = (name: string, resolved: (...args: unknown[]) => unknown) => ((...args: unknown[]) => unknown) | undefined; interface ChannelOptions { /** * Function to post raw message */ post: (data: any, ...extras: any[]) => any | Promise; /** * Listener to receive raw message */ on: (fn: (data: any, ...extras: any[]) => void) => any | Promise; /** * Clear the listener when `$close` is called */ off?: (fn: (data: any, ...extras: any[]) => void) => any | Promise; /** * Custom function to serialize data * * by default it passes the data as-is */ serialize?: (data: any) => any; /** * Custom function to deserialize data * * by default it passes the data as-is */ deserialize?: (data: any) => any; /** * Call the methods with the RPC context or the original functions object */ bind?: 'rpc' | 'functions'; } interface EventOptions { /** * Names of remote functions that do not need response. */ eventNames?: (keyof Remote)[]; /** * Maximum timeout for waiting for response, in milliseconds. * * @default 60_000 */ timeout?: number; /** * Custom resolver to resolve function to be called * * For advanced use cases only */ resolver?: BirpcResolver; /** * Custom error handler */ onError?: (error: Error, functionName: string, args: any[]) => boolean | void; /** * Custom error handler for timeouts */ onTimeoutError?: (functionName: string, args: any[]) => boolean | void; } type BirpcOptions = EventOptions & ChannelOptions; type BirpcFn = PromisifyFn & { /** * Send event without asking for response */ asEvent: (...args: ArgumentsType) => void; }; interface BirpcGroupFn { /** * Call the remote function and wait for the result. */ (...args: ArgumentsType): Promise>[]>; /** * Send event without asking for response */ asEvent: (...args: ArgumentsType) => void; } type BirpcReturn> = { [K in keyof RemoteFunctions]: BirpcFn; } & { $functions: LocalFunctions; $close: () => void; }; type BirpcGroupReturn = { [K in keyof RemoteFunctions]: BirpcGroupFn; }; interface BirpcGroup> { readonly clients: BirpcReturn[]; readonly functions: LocalFunctions; readonly broadcast: BirpcGroupReturn; updateChannels: (fn?: ((channels: ChannelOptions[]) => void)) => BirpcReturn[]; } declare const DEFAULT_TIMEOUT = 60000; declare function createBirpc, LocalFunctions extends object = Record>(functions: LocalFunctions, options: BirpcOptions): BirpcReturn; declare function cachedMap(items: T[], fn: ((i: T) => R)): R[]; declare function createBirpcGroup, LocalFunctions extends object = Record>(functions: LocalFunctions, channels: ChannelOptions[] | (() => ChannelOptions[]), options?: EventOptions): BirpcGroup; export { type ArgumentsType, type BirpcFn, type BirpcGroup, type BirpcGroupFn, type BirpcGroupReturn, type BirpcOptions, type BirpcResolver, type BirpcReturn, type ChannelOptions, DEFAULT_TIMEOUT, type EventOptions, type PromisifyFn, type ReturnType, cachedMap, createBirpc, createBirpcGroup };