/** * Profile caching (kind 0 events) */ import { getDB } from './indexeddb-store.js'; import type { NostrEvent } from '../../types/nostr.js'; import { KIND } from '../../types/kind-lookup.js'; export interface CachedProfile { pubkey: string; event: NostrEvent; cached_at: number; } /** * Store a profile in cache */ export async function cacheProfile(event: NostrEvent): Promise { if (event.kind !== KIND.METADATA) throw new Error('Not a profile event'); try { const db = await getDB(); const cached: CachedProfile = { pubkey: event.pubkey, event, cached_at: Date.now() }; await db.put('profiles', cached); } catch (error) { // Cache write failed (non-critical) // Don't throw - caching failures shouldn't break the app } } /** * Get profile by pubkey from cache */ export async function getProfile(pubkey: string): Promise { try { const db = await getDB(); return await db.get('profiles', pubkey); } catch (error) { // Cache read failed (non-critical) return undefined; } } /** * Get multiple profiles */ export async function getProfiles(pubkeys: string[]): Promise> { try { const db = await getDB(); const profiles = new Map(); const tx = db.transaction('profiles', 'readonly'); for (const pubkey of pubkeys) { const profile = await tx.store.get(pubkey); if (profile) { profiles.set(pubkey, profile); } } await tx.done; return profiles; } catch (error) { // Cache read failed (non-critical) return new Map(); } }