Interface NDKCacheAdapter

interface NDKCacheAdapter {
    getProfiles?: ((filter: ((pubkey: string, profile: NDKUserProfile) => boolean)) => Promise<undefined | Map<string, NDKUserProfile>>);
    locking: boolean;
    ready?: boolean;
    addUnpublishedEvent?(event: NDKEvent, relayUrls: string[]): void;
    deleteEvent?(event: NDKEvent): Promise<void>;
    discardUnpublishedEvent?(eventId: string): void;
    fetchProfile?(pubkey: string): Promise<null | NDKCacheEntry<NDKUserProfile>>;
    getRelayStatus?(relayUrl: string): undefined | NDKCacheRelayInfo;
    getUnpublishedEvents?(): Promise<{
        event: NDKEvent;
        lastTryAt?: number;
        relays?: string[];
    }[]>;
    loadNip05?(nip05: string, maxAgeForMissing?: number): Promise<null | ProfilePointer | "missing">;
    loadUsersLNURLDoc?(pubkey: string, maxAgeInSecs?: number, maxAgeForMissing?: number): Promise<null | "missing" | NDKLnUrlData>;
    onReady?(callback: (() => void)): void;
    query(subscription: NDKSubscription): Promise<void>;
    saveNip05?(nip05: string, profile: null | ProfilePointer): void;
    saveProfile?(pubkey: string, profile: NDKUserProfile): void;
    saveUsersLNURLDoc?(pubkey: string, doc: null | NDKLnUrlData): void;
    setEvent(event: NDKEvent, filters: NDKFilter[], relay?: NDKRelay): Promise<void>;
    updateRelayStatus?(relayUrl: string, info: NDKCacheRelayInfo): void;
}

Properties

getProfiles?: ((filter: ((pubkey: string, profile: NDKUserProfile) => boolean)) => Promise<undefined | Map<string, NDKUserProfile>>)

Fetches profiles that match the given filter.

Type declaration

const searchFunc = (pubkey, profile) => profile.name.toLowerCase().includes("alice");
const allAliceProfiles = await cache.getProfiles(searchFunc);
locking: boolean

Whether this cache adapter is expected to be fast. If this is true, the cache will be queried before the relays. When this is false, the cache will be queried in addition to the relays.

ready?: boolean

Weather the cache is ready.

Methods

  • Tracks a publishing event.

    Parameters

    • event: NDKEvent
    • relayUrls: string[]

      List of relays that the event will be published to.

    Returns void

  • Called when an event is deleted by the client. Cache adapters should remove the event from their cache.

    Parameters

    • event: NDKEvent

      The event that was deleted.

    Returns Promise<void>

  • Removes an unpublished event.

    Parameters

    • eventId: string

    Returns void

  • Fetches all unpublished events.

    Returns Promise<{
        event: NDKEvent;
        lastTryAt?: number;
        relays?: string[];
    }[]>

  • Fetches a user's LNURL data from the cache.

    Parameters

    • pubkey: string

      The pubkey of the user to fetch the LNURL data for.

    • OptionalmaxAgeInSecs: number

      The maximum age of the data in seconds.

    • OptionalmaxAgeForMissing: number

      The maximum age of the data in seconds if it is missing before it returns that it should be refetched.

    Returns Promise<null | "missing" | NDKLnUrlData>

    The LNURL data, null if it is not in the cache and under the maxAgeForMissing, or "missing" if it should be refetched.

  • Called when the cache is ready.

    Parameters

    • callback: (() => void)
        • (): void
        • Returns void

    Returns void