import type { Did } from '@atcute/lexicons'; import { DevNiblingActorGetKnown, DevNiblingFeedGetRecent, DevNiblingFeedGetTrending } from '@nibling/lexicons'; import { config, serviceClient } from './identity.ts'; /** Recently updated projects from nibling's index. Undefined when no index is configured or it is down. */ export async function getRecent( params: DevNiblingFeedGetRecent.$params = {}, ): Promise { if (!config.index) return undefined; const res = await serviceClient(config.index) .call(DevNiblingFeedGetRecent, { params }) .catch(() => undefined); return res?.ok ? res.data : undefined; } export async function getTrending( params: DevNiblingFeedGetTrending.$params = {}, ): Promise { if (!config.index) return undefined; const res = await serviceClient(config.index) .call(DevNiblingFeedGetTrending, { params }) .catch(() => undefined); return res?.ok ? res.data : undefined; } const KNOWN_BATCH = 100; /** The subset of `dids` that use nibling, in batches the lexicon allows. Undefined when the index is unset or any batch fails. */ export async function getKnown(dids: readonly Did[]): Promise { if (!config.index) return undefined; const client = serviceClient(config.index); const known: Did[] = []; for (let i = 0; i < dids.length; i += KNOWN_BATCH) { const res = await client .call(DevNiblingActorGetKnown, { params: { dids: dids.slice(i, i + KNOWN_BATCH) } }) .catch(() => undefined); if (!res?.ok) return undefined; known.push(...res.data.dids); } return known; }