export type BatchHttpClientConfig = { baseUrl?: string; headers?: Record; }; export function normalizeBatchBaseUrl(client: BatchHttpClientConfig): string { return client.baseUrl?.replace(/\/$/, "") ?? ""; } export function buildBatchHeaders( client: Pick, params: { json: boolean }, ): Record { const headers = client.headers ? { ...client.headers } : {}; if (params.json) { if (!headers["Content-Type"] && !headers["content-type"]) { headers["Content-Type"] = "application/json"; } } else { delete headers["Content-Type"]; delete headers["content-type"]; } return headers; } export function splitBatchRequests(requests: T[], maxRequests: number): T[][] { if (requests.length <= maxRequests) { return [requests]; } const groups: T[][] = []; for (let i = 0; i < requests.length; i += maxRequests) { groups.push(requests.slice(i, i + maxRequests)); } return groups; }