import type { Sponsoring } from '@/types/nostr' import { objectCache } from './objectCache' import { getCachedObjectById } from './helpers/queryHelpers' export async function getSponsoringById(sponsoringId: string, _timeoutMs: number = 5000): Promise { return getCachedObjectById('sponsoring', sponsoringId) } export async function getSponsoringByAuthor(authorPubkey: string, _timeoutMs: number = 5000): Promise { // Read only from IndexedDB cache const allSponsoring = await objectCache.getAll('sponsoring') const sponsoring = allSponsoring as Sponsoring[] // Filter by authorPubkey const authorSponsoring = sponsoring.filter((s) => s.authorPubkey === authorPubkey) // Sort by creation date descending return authorSponsoring.sort((a, b) => b.createdAt - a.createdAt) }