Add arbitrary API request batching
The Issue & Context
Previously, the TypeScript API clients handled requests individually, which could lead to inefficiencies when multiple API calls were made in quick succession, especially in asynchronous contexts.
Root Cause Analysis
Lack of support for batching arbitrary API requests caused overhead and reduced performance when multiple requests were issued separately, without a unified mechanism to group and process them efficiently.
Solution Strategy & Architectural Pattern
Introduced a new batchRequests method across backend, sync, and async API clients to allow multiple API calls to be sent and processed as a single batch. Additionally, implemented automatic tick-based batching for the async API that groups requests made within the same event loop tick. A batchContext API was also added for manual control over batching in async scenarios, improving flexibility. Error handling was enhanced to support per-request errors within batches.
Key Takeaway for Contributors
This PR significantly improves API efficiency by enabling both automatic and manual batching of requests, reducing overhead and latency in common usage patterns. While manual batching remains available for fine-grained control, automatic tick-based batching will likely suffice for most async API consumers, simplifying usage without sacrificing performance.