MCPcopy Index your code
hub / github.com/npmx-dev/npmx.dev / useRepoMeta

Function useRepoMeta

app/composables/useRepoMeta.ts:4–48  ·  view source on GitHub ↗
(repositoryUrl: MaybeRefOrGetter<string | null | undefined>)

Source from the content-addressed store, hash-verified

2import { getRepoMeta, type RepoMeta } from '#shared/utils/repository-meta'
3
4export function useRepoMeta(repositoryUrl: MaybeRefOrGetter<string | null | undefined>) {
5 // Get cachedFetch in setup context (outside async handler)
6 const cachedFetch = useCachedFetch()
7
8 const repoRef = computed(() => {
9 const url = toValue(repositoryUrl)
10 if (!url) return null
11 return parseRepoUrl(url)
12 })
13
14 const { data, pending, error, refresh } = useLazyAsyncData<RepoMeta | null>(
15 () =>
16 repoRef.value
17 ? `repo-meta:${repoRef.value.provider}:${repoRef.value.owner}/${repoRef.value.repo}`
18 : 'repo-meta:none',
19 async (_nuxtApp, { signal }) => {
20 const ref = repoRef.value
21 if (!ref) return null
22
23 return await getRepoMeta(cachedFetch, ref, { signal })
24 },
25 )
26
27 const meta = computed<RepoMeta | null>(() => data.value ?? null)
28
29 return {
30 repoRef,
31 meta,
32
33 // TODO(serhalp): Consider removing the zero fallback so callers can make a distinction between
34 // "unresolved data" and "zero value"
35 stars: computed(() => meta.value?.stars ?? 0),
36 forks: computed(() => meta.value?.forks ?? 0),
37 watchers: computed(() => meta.value?.watchers ?? 0),
38
39 starsLink: computed(() => meta.value?.links.stars ?? null),
40 forksLink: computed(() => meta.value?.links.forks ?? null),
41 watchersLink: computed(() => meta.value?.links.watchers ?? null),
42 repoLink: computed(() => meta.value?.links.repo ?? null),
43
44 pending,
45 error,
46 refresh,
47 }
48}

Callers

nothing calls this directly

Calls 3

parseRepoUrlFunction · 0.90
getRepoMetaFunction · 0.90
useCachedFetchFunction · 0.85

Tested by

no test coverage detected