import { Observable, Subject } from "rxjs"; import { NostrEvent } from "../helpers/event.js"; import { Filter } from "../helpers/filter.js"; import { AddressPointer, AddressPointerWithoutD, EventPointer } from "../helpers/pointers.js"; import { EventMemory } from "./event-memory.js"; import { EventModels } from "./event-models.js"; import { IDeleteManager, IEventDatabase, IEventStore, IExpirationManager } from "./interface.js"; export type EventStoreOptions = { /** Keep deleted events in the store */ keepDeleted?: boolean; /** Keep expired events in the store */ keepExpired?: boolean; /** Enable this to keep old versions of replaceable events */ keepOldVersions?: boolean; /** The database to use for storing events */ database?: IEventDatabase; /** Custom {@link IDeleteManager} implementation */ deleteManager?: IDeleteManager; /** Custom {@link IExpirationManager} implementation */ expirationManager?: IExpirationManager; /** The method used to verify events */ verifyEvent?: (event: NostrEvent) => boolean; }; /** A wrapper around an event database that handles replaceable events, deletes, and models */ export declare class EventStore extends EventModels implements IEventStore { database: IEventDatabase; /** Optional memory database for ensuring single event instances */ memory: EventMemory; /** Manager for handling event deletions with authorization */ private deletes; /** Manager for handling event expirations */ private expiration; /** Enable this to keep old versions of replaceable events */ keepOldVersions: boolean; /** Keep expired events in the store */ keepExpired: boolean; /** Keep deleted events in the store */ keepDeleted: boolean; /** The method used to verify events */ private _verifyEventMethod?; /** Get the method used to verify events */ get verifyEvent(): undefined | ((event: NostrEvent) => boolean); /** Sets the method used to verify events */ set verifyEvent(method: undefined | ((event: NostrEvent) => boolean)); /** A stream of new events added to the store */ insert$: Subject; /** A stream of events that have been updated (Warning: this is a very noisy stream, use with caution) */ update$: Subject; /** A stream of events that have been removed */ remove$: Subject; /** A method that will be called when an event isn't found in the store */ eventLoader?: (pointer: EventPointer | AddressPointer | AddressPointerWithoutD) => Observable | Promise; /** Internal subscriptions (delete + expiration managers) torn down on dispose */ private internalSubscriptions; constructor(options?: EventStoreOptions); /** A method to add all events to memory to ensure there is only ever a single instance of an event */ private mapToMemory; /** Handle a delete event by pointer */ private handleDeleteNotification; /** Handle an expired event by id */ private handleExpiredNotification; /** Copies important metadata from and identical event to another */ static copySymbolsToDuplicateEvent(source: NostrEvent, dest: NostrEvent): boolean; /** * Adds an event to the store and update subscriptions * @returns The existing event or the event that was added, if it was ignored returns null */ add(event: NostrEvent, fromRelay?: string): NostrEvent | null; /** Removes an event from the store and updates subscriptions */ remove(event: string | NostrEvent): boolean; /** Remove multiple events that match the given filters */ removeByFilters(filters: Filter | Filter[]): number; /** Add an event to the store and notifies all subscribes it has updated */ update(event: NostrEvent): boolean; /** Check if the store has an event by id */ hasEvent(id: string | EventPointer | AddressPointer | AddressPointerWithoutD): boolean; /** Get an event by id from the store */ getEvent(id: string | EventPointer | AddressPointer | AddressPointerWithoutD): NostrEvent | undefined; /** Check if the store has a replaceable event */ hasReplaceable(kind: number, pubkey: string, d?: string): boolean; /** Gets the latest version of a replaceable event */ getReplaceable(kind: number, pubkey: string, identifier?: string): NostrEvent | undefined; /** Returns all versions of a replaceable event */ getReplaceableHistory(kind: number, pubkey: string, identifier?: string): NostrEvent[] | undefined; /** Get all events matching a filter */ getByFilters(filters: Filter | Filter[]): NostrEvent[]; /** Returns a timeline of events that match filters */ getTimeline(filters: Filter | Filter[]): NostrEvent[]; /** Passthrough method for the database.touch */ touch(event: NostrEvent): void; /** Increments the claim count on the event and touches it */ claim(event: NostrEvent): void; /** Checks if an event is claimed by anything */ isClaimed(event: NostrEvent): boolean; /** Decrements the claim count on an event */ removeClaim(event: NostrEvent): void; /** Removes all claims on an event */ clearClaim(event: NostrEvent): void; /** Pass through method for the database.unclaimed */ unclaimed(): Generator; /** Removes any event that is not being used by a subscription */ prune(limit?: number): number; /** * Tears down the store: disposes the attached event loader, completes the event streams, releases * model keep-warm timers, and unsubscribes internal manager listeners. * @note This is a terminal operation; the store should be discarded after calling it. */ dispose(): void; /** Allows the store to be used with the `using` keyword */ [Symbol.dispose](): void; }