import { type ValidateFunction } from 'ajv'; import Type from 'typebox'; import { type JSONRPCErrorData } from './JSONRPCError.js'; export interface JSONRPCServerServerMethodConfig { schema?: TSchema; } export type ParamsSchema = readonly Type.TSchema[]; export type ParamsSchemaToParams = TParamsSchema extends readonly [ infer TParamSchema extends Type.TSchema, ...infer TRestParamsSchema extends ParamsSchema ] ? readonly [ Type.Static, ...ParamsSchemaToParams ] : readonly []; export type ParamsSchemaToParamsValidate = TParamsSchema extends readonly [ infer TParamSchema extends Type.TSchema, ...infer TRestParamsSchema extends ParamsSchema ] ? readonly [ ValidateFunction>, ...ParamsSchemaToParamsValidate ] : readonly []; export type JSONRPCServerServerMethodFn = (...args: ParamsSchemaToParams) => TOutput | Promise; export declare class JSONRPCServerMethod { readonly name: string; readonly schema: TParamsSchema; readonly validate: ParamsSchemaToParamsValidate; readonly fn: JSONRPCServerServerMethodFn; constructor(name: string, fn: JSONRPCServerServerMethodFn); constructor(name: string, config: JSONRPCServerServerMethodConfig, fn: JSONRPCServerServerMethodFn); call(params: unknown): Promise; } export type JSONRPCResponseFulfilled = { jsonrpc: '2.0'; id: string; result: unknown; }; export type JSONRPCResponseRejected = { jsonrpc: '2.0'; id: string; error: { code: number; message: string; data?: JSONRPCErrorData; }; }; export type JSONRPCServerSend = (message: string) => void | Promise; /** The part of a {@link JSONRPCServerMethod} that the server uses, whatever its type arguments are. */ export interface AnyJSONRPCServerMethod { readonly name: string; call(params: unknown): Promise; } export declare class JSONRPCServer { private readonly methods; private readonly send; constructor(methods: readonly AnyJSONRPCServerMethod[], send: JSONRPCServerSend); handle(message: unknown): Promise; private sendError; notify(method: string, ...params: unknown[]): Promise; }