import type { Series } from '@/types/nostr' import { objectCache } from './objectCache' import { getCachedObjectById } from './helpers/queryHelpers' export async function getSeriesByAuthor(authorPubkey: string, _timeoutMs: number = 5000): Promise { // Read only from IndexedDB cache const allSeries = await objectCache.getAll('series') const series = allSeries as Series[] // Filter by author pubkey const authorSeries = series.filter((s) => s.pubkey === authorPubkey) // Sort by hash (newest first - hash contains timestamp information) // Since Series doesn't have createdAt, we sort by id which contains version/index return authorSeries.sort((a, b) => { // Sort by version descending, then by index descending if (b.version !== a.version) { return b.version - a.version } return b.index - a.index }) } export async function getSeriesById(seriesId: string, _timeoutMs: number = 2000): Promise { return getCachedObjectById('series', seriesId) }