/** * RPC Request Batcher with throttling * * Collects RPC requests over a short time window and sends them in a single * HTTP request. Each request includes its own auth credentials in the JSON body, * allowing true batching of authenticated requests. */ export interface RpcRequest { method: string; params?: any; } /** * Per-request authentication credentials */ export interface RequestAuth { publicKey: string; timestamp: number; nonce: string; signature: string; } export interface RpcResponse { success: boolean; result?: any; error?: string; errorCode?: string; } export interface BatcherOptions { /** Delay in ms before flushing queued requests (default: 10) */ delay?: number; /** Maximum batch size (default: 50) */ maxBatchSize?: number; } /** * RpcBatcher - Batches RPC requests with throttling * * All requests (authenticated and unauthenticated) are batched together * into a single HTTP request. Auth credentials are included per-request * in the JSON body. * * @example * ```typescript * const batcher = new RpcBatcher('https://api.example.com', { * delay: 10, * maxBatchSize: 50 * }) * * // Requests made within the delay window are batched into ONE HTTP call * const [result1, result2] = await Promise.all([ * batcher.add({ method: 'publish', params: {...} }, auth1), * batcher.add({ method: 'discover', params: {...} }, auth2) * ]) * ``` */ export declare class RpcBatcher { private readonly baseUrl; private queue; private flushTimer; private readonly delay; private readonly maxBatchSize; constructor(baseUrl: string, options?: BatcherOptions); /** * Add a request to the batch queue * @param request - The RPC request * @param auth - Per-request auth credentials, null for unauthenticated * @returns Promise that resolves with the request result */ add(request: RpcRequest, auth: RequestAuth | null): Promise; /** * Schedule a flush after the delay */ private scheduleFlush; /** * Flush all queued requests */ private flush; /** * Send a batch of requests in a single HTTP call * Each request includes its own auth credentials in the JSON body */ private sendBatch; /** * Flush immediately (useful for cleanup/testing) */ flushNow(): Promise; }