* API limit workaround: * If the requested range is larger than the API allows (≈18 months), * split into multiple requests, then merge/sum by day.
(packageName: string, startIso: string, endIso: string)
| 250 | * split into multiple requests, then merge/sum by day. |
| 251 | */ |
| 252 | async function fetchDailyRangeChunked(packageName: string, startIso: string, endIso: string) { |
| 253 | const maximumDaysPerRequest = 540 |
| 254 | const ranges = splitIsoRangeIntoChunksInclusive(startIso, endIso, maximumDaysPerRequest) |
| 255 | |
| 256 | if (ranges.length === 1) { |
| 257 | return fetchDailyRangeCached(packageName, startIso, endIso) |
| 258 | } |
| 259 | |
| 260 | const parts = await mapWithConcurrency( |
| 261 | ranges, |
| 262 | range => fetchDailyRangeCached(packageName, range.startIso, range.endIso), |
| 263 | 10, |
| 264 | ) |
| 265 | const all = parts.flat() |
| 266 | |
| 267 | return mergeDailyPoints(all) |
| 268 | } |
| 269 | |
| 270 | function toDateOnly(value?: string): string | null { |
| 271 | if (!value) return null |
no test coverage detected