MCPcopy
hub / github.com/npmx-dev/npmx.dev / fetchRepoRefsForPackages

Function fetchRepoRefsForPackages

app/composables/useCharts.ts:454–499  ·  view source on GitHub ↗
(
    packageNames: MaybeRefOrGetter<string[]>,
  )

Source from the content-addressed store, hash-verified

452 }
453
454 async function fetchRepoRefsForPackages(
455 packageNames: MaybeRefOrGetter<string[]>,
456 ): Promise<Record<string, RepoRef | null>> {
457 const names = (toValue(packageNames) ?? []).map(n => String(n).trim()).filter(Boolean)
458 if (!import.meta.client || !names.length) return {}
459
460 const settled = await Promise.allSettled(
461 names.map(async name => {
462 const cacheKey = name
463 const cache = repoMetaCache
464 if (cache?.has(cacheKey)) {
465 const ref = await cache.get(cacheKey)!
466 return { name, ref }
467 }
468
469 const promise = $fetch<PackageMetaResponse>(
470 `/api/registry/package-meta/${encodePackageName(name)}`,
471 )
472 .then(meta => {
473 const repoUrl = meta?.links?.repository
474 return repoUrl ? parseRepoUrl(repoUrl) : null
475 })
476 .catch(error => {
477 cache?.delete(cacheKey)
478 throw error
479 })
480
481 cache?.set(cacheKey, promise)
482 const ref = await promise
483 return { name, ref }
484 }),
485 )
486
487 const next: Record<string, RepoRef | null> = {}
488 for (const [index, entry] of settled.entries()) {
489 const name = names[index]
490 if (!name) continue
491 if (entry.status === 'fulfilled') {
492 next[name] = entry.value.ref ?? null
493 } else {
494 next[name] = null
495 }
496 }
497
498 return next
499 }
500
501 return {
502 fetchPackageDownloadEvolution,

Callers

nothing calls this directly

Calls 5

parseRepoUrlFunction · 0.85
getMethod · 0.65
deleteMethod · 0.65
setMethod · 0.65
encodePackageNameFunction · 0.50

Tested by

no test coverage detected