story-research-zapwall/lib/sponsoringQueries.ts
2026-01-07 03:10:40 +01:00

20 lines
842 B
TypeScript

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<Sponsoring | null> {
return await getCachedObjectById<Sponsoring>('sponsoring', sponsoringId)
}
export async function getSponsoringByAuthor(authorPubkey: string, _timeoutMs: number = 5000): Promise<Sponsoring[]> {
// 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)
}