/** * JSON-RPC Manager * * Clean JSON-RPC 2.0 implementation for communication. * Provides method registration, routing, and lifecycle management. */ import { ErrorCode } from "./ErrorCode"; import { JSONRPCCall } from "./util_pending"; import { JSONRPCErrorCode } from "./schemas/jsonrpc"; import type { JSONRPCRequest, JSONRPCMessage, JSONRPCError, JSONRPCParams } from "./schemas/jsonrpc"; /** * Method handler function signature */ type JSONRPCMethodHandler = (params: T, context?: TContext) => Promise | any; /** * Method registration configuration */ interface JSONRPCMethodConfig { /** Method handler function */ handler: JSONRPCMethodHandler; /** Optional parameter validation schema */ paramSchema?: any; /** Optional method description */ description?: string; /** Whether this method requires authentication */ requiresAuth?: boolean; /** Rate limiting configuration */ rateLimit?: { maxCalls: number; windowMs: number; }; } /** * JSON-RPC Manager configuration */ export interface JSONRPCManagerConfig { /** Enable strict JSON-RPC 2.0 validation */ strictValidation?: boolean; /** Default timeout for requests */ defaultTimeout?: number; /** Maximum batch size for batch requests */ maxBatchSize?: number; /** Custom error handler */ errorHandler?: (error: Error, context?: TContext) => JSONRPCError; } /** * JSON-RPC Manager Event Handlers */ export interface JSONRPCManagerEvents { onMethodCall?: (method: string, params: any, context: TContext) => void; onMethodResponse?: (method: string, result: any, context: TContext) => void; onMethodError?: (method: string, error: JSONRPCError, context: TContext) => void; } export declare class ERROR_METHOD_NOT_FOUND extends ErrorCode { readonly code = JSONRPCErrorCode.METHOD_NOT_FOUND; } /** * Central JSON-RPC Manager class */ export declare abstract class JSONRPCManager extends JSONRPCCall { private methods; private config; private eventHandlers; constructor(config?: JSONRPCManagerConfig, eventHandlers?: JSONRPCManagerEvents); /** * Process incoming JSON-RPC message (supports batch requests) */ private processMessage; /** * Process a JSON-RPC request */ private processMethod; /** * Process a JSON-RPC notification */ private processNotification; /** * Process a JSON-RPC batch request */ private processBatchRequest; /** * Default error handler */ private defaultErrorHandler; /** * Send a message (to be overridden by implementation) */ protected abstract sendMessage(message: JSONRPCMessage, options?: TContext): any; /** * Send a JSON-RPC notification (no response expected) */ protected sendNotification(method: string, params: any, options: TContext): void; /** * Register a JSON-RPC method */ registerMethod(methodName: string, config: JSONRPCMethodConfig): void; /** * Unregister a JSON-RPC method */ unregisterMethod(methodName: string): boolean; /** * Get registered method names */ getRegisteredMethods(): string[]; /** * Send a JSON-RPC request and return a promise for the response */ handleRequest(method: string, params?: any, options?: any): { promise: Promise; request: JSONRPCRequest; result: any; }; /** * Process incoming WebSocket message */ validateMessage(data: string | Buffer | Record, options?: any): Promise; /** * Get manager statistics */ getStats(): { registeredMethods: number; methodNames: string[]; pendingRequests: import("./util_pending").PendingOperationStats; }; /** * Clean up resources */ destroy(): void; } export {};