import { ClientMessage, RemoteMessage } from './contract.js'; import { default as RPCSourceChannel } from './RPCSourceChannel.js'; import { MetaScopeValue } from './type-utils.js'; export type RPCSourceConnection = (onMessage: (...messages: ClientMessage) => void, onClose: (reason?: any) => void) => (...messages: RemoteMessage) => void; export type RPCHandler = any> = (channel: RPCSource.Channel, path: string[], args: any[], newChannel: boolean) => any | Promise | RPCSource; type EventPath = (K extends (string | number) ? (T[K] extends infer P ? (0 extends (1 & P) ? (K | [K, ...(number | string)[]]) : P extends unknown[] ? (K | [K]) : [ K, ...(EventPath extends infer NEXT extends ((string | number) | (string | number)[]) ? (NEXT extends any[] ? NEXT : [NEXT]) : never) ]) : never) : never); type EventPathArgs = (0 extends (1 & FORM) ? any[] : PATH extends (number | string) ? EventPathArgs<[PATH], FORM> : PATH extends [] ? FORM extends any[] ? 0 extends (1 & FORM) ? any[] : FORM : never : PATH extends [infer PROP, ...infer TAIL extends (number | string)[]] ? (PROP extends keyof FORM ? EventPathArgs : never) : never); type BoxMethods = { [KEY in keyof T as KEY extends `${PREFIX}${infer NAME}` ? NAME : never]: T[KEY]; }; declare class RPCSource | string) = {}, STATE = undefined, EVENTS = any> implements Disposable { #private; static with = {}, BIND_STATE = undefined, const BIND_EVENTS = {}>(): { [K in keyof typeof RPCSource]: (typeof RPCSource)[K]; } & { new | string = BIND_METHODS, STATE = BIND_STATE, EVENTS = BIND_EVENTS>(methods: METHODS, state?: STATE): RPCSource; }; static with | string = {}, BIND_STATE = undefined, const BIND_EVENTS = {}>(methods: BIND_METHODS | RPCHandler): { [K in keyof typeof RPCSource]: (typeof RPCSource)[K]; } & { new (state?: STATE): RPCSource; }; static with | string = {}, BIND_STATE = undefined, const BIND_EVENTS = {}>(methods: BIND_METHODS | RPCHandler, state: BIND_STATE): { [K in keyof typeof RPCSource]: (typeof RPCSource)[K]; } & { new (): RPCSource; }; [Symbol.unscopables]: MetaScopeValue : METHODS, EVENTS, STATE>; get channel(): RPCSource.Channel; static get channel(): RPCSource.Channel>; get context(): any; static get context(): any; get state(): STATE; constructor(handler?: RPCHandler | METHODS, initialState?: STATE); static createDefaultHandler(parameters: { methods: any; thisValue?: any; }, prefix?: string): RPCHandler; static normalize, args: any[]) => boolean | readonly any[]) | ((this: RPCSource, args: any[]) => args is any[]), A extends (this: RPCSource, ...args: (V extends ((args: any[]) => args is infer R extends any[]) ? R : (V extends ((args: any[]) => false | infer R extends readonly any[]) ? R : (Parameters[0])))) => any>(normalizer: V, handler: A): NoInfer; static validate: typeof RPCSource.normalize; withEventTypes(): RPCSource; setState(changeState: (oldState: STATE) => STATE): STATE; setState(newState: STATE extends (...args: any) => any ? never : STATE): STATE; withState(): RPCSource; withState(state: S): RPCSource; get disposed(): boolean; emit

>(event: P, ...args: 0 extends (1 & EVENTS) ? any[] : EventPathArgs): this; dispose(reason?: any): void; [Symbol.dispose](): void; static start(rpcSource: RPCSource, connection: RPCSourceConnection, { maxChannelsPerClient, context, onCreateChannel }?: { maxChannelsPerClient?: number; context?: any; onCreateChannel?: (channel: RPCSource.Channel, parentChannel: RPCSource.Channel | undefined) => void; }): (reason?: any) => void; static Channel: typeof RPCSourceChannel; } declare namespace RPCSource { type Channel = RPCSource> = RPCSourceChannel; } export default RPCSource;