import type { Actor } from 'wildebeest/backend/src/activitypub/actors' import * as actors from 'wildebeest/backend/src/activitypub/actors' import type { OrderedCollection } from 'wildebeest/backend/src/activitypub/objects/collection' import { getMetadata, loadItems } from 'wildebeest/backend/src/activitypub/objects/collection' export async function countFollowing(actor: Actor): Promise { const collection = await getMetadata(actor.following) return collection.totalItems } export async function countFollowers(actor: Actor): Promise { const collection = await getMetadata(actor.followers) return collection.totalItems } export async function getFollowers(actor: Actor): Promise> { const collection = await getMetadata(actor.followers) collection.items = await loadItems(collection) return collection } export async function getFollowing(actor: Actor): Promise> { const collection = await getMetadata(actor.following) collection.items = await loadItems(collection) return collection } export async function loadActors(db: D1Database, collection: OrderedCollection): Promise> { const promises = collection.items.map((item) => { const actorId = new URL(item) return actors.getAndCache(actorId, db) }) return Promise.all(promises) }