(
packageName: MaybeRefOrGetter<string>,
evolutionOptions: MaybeRefOrGetter<EvolutionOptions>,
)
| 361 | } |
| 362 | |
| 363 | async function fetchPackageLikesEvolution( |
| 364 | packageName: MaybeRefOrGetter<string>, |
| 365 | evolutionOptions: MaybeRefOrGetter<EvolutionOptions>, |
| 366 | ): Promise<DailyDataPoint[] | WeeklyDataPoint[] | MonthlyDataPoint[] | YearlyDataPoint[]> { |
| 367 | const resolvedPackageName = toValue(packageName) |
| 368 | const resolvedOptions = toValue(evolutionOptions) |
| 369 | |
| 370 | // Fetch daily likes data (with client-side promise caching) |
| 371 | const cache = likesEvolutionCache |
| 372 | const cacheKey = resolvedPackageName |
| 373 | |
| 374 | let dailyLikesPromise: Promise<DailyRawPoint[]> |
| 375 | |
| 376 | if (cache?.has(cacheKey)) { |
| 377 | dailyLikesPromise = cache.get(cacheKey)! |
| 378 | } else { |
| 379 | dailyLikesPromise = $fetch<Array<{ day: string; likes: number }>>( |
| 380 | `/api/social/likes-evolution/${resolvedPackageName}`, |
| 381 | ) |
| 382 | .then(data => (data ?? []).map(d => ({ day: d.day, value: d.likes }))) |
| 383 | .catch(error => { |
| 384 | cache?.delete(cacheKey) |
| 385 | throw error |
| 386 | }) |
| 387 | |
| 388 | cache?.set(cacheKey, dailyLikesPromise) |
| 389 | } |
| 390 | |
| 391 | const sortedDaily = await dailyLikesPromise |
| 392 | |
| 393 | const { start, end } = resolveDateRange(resolvedOptions, null) |
| 394 | const startIso = toIsoDate(start) |
| 395 | const endIso = toIsoDate(end) |
| 396 | |
| 397 | const filteredDaily = sortedDaily.filter(d => d.day >= startIso && d.day <= endIso) |
| 398 | |
| 399 | if (resolvedOptions.granularity === 'day') return buildDailyEvolution(filteredDaily) |
| 400 | if (resolvedOptions.granularity === 'week') |
| 401 | return buildWeeklyEvolution(filteredDaily, startIso, endIso) |
| 402 | if (resolvedOptions.granularity === 'month') |
| 403 | return buildMonthlyEvolution(filteredDaily, startIso, endIso) |
| 404 | return buildYearlyEvolution(filteredDaily, startIso, endIso) |
| 405 | } |
| 406 | |
| 407 | async function fetchRepoContributorsEvolution( |
| 408 | repoRef: MaybeRefOrGetter<RepoRef | null | undefined>, |
no test coverage detected