import { Observable, ReplaySubject } from "rxjs"; import { NostrEvent } from "../helpers/event.js"; import { Filter } from "../helpers/filter.js"; import { AddressPointer, AddressPointerWithoutD, EventPointer, ProfilePointer } from "../helpers/pointers.js"; import { IAsyncEventStore, IEventStore, IEventSubscriptions, ModelConstructor } from "./interface.js"; /** * Base class that provides model functionality for both sync and async event stores. * This class can be extended by other packages to add additional helpful subscription methods. * * @example * ```ts * // In another package (e.g., applesauce-common) * import { EventModels } from "applesauce-core/event-store"; * * // Add methods to the prototype * EventModels.prototype.mutes = function(user) { * return this.model(MuteModel, user); * }; * * // Extend the type via module augmentation * declare module "applesauce-core/event-store" { * interface EventModels { * mutes(user: string | ProfilePointer): Observable; * } * } * ``` */ export declare class EventModels implements IEventSubscriptions { /** A directory of all active models */ models: Map, Map>>; /** How long a model should be kept "warm" while nothing is subscribed to it */ modelKeepWarm: number; /** * Emits when {@link EventModels.dispose} is called to tear down all models. * A {@link ReplaySubject} so reset notifiers subscribed after disposal fire immediately. */ protected destroy$: ReplaySubject; /** Get or create a model on the event store */ model>(constructor: ModelConstructor, ...args: Args): Observable; /** * Creates an observable that streams all events that match the filter * @param filters * @param [onlyNew=false] Only subscribe to new events */ filters(filters: Filter | Filter[], onlyNew?: boolean): Observable; /** Subscribe to an event by pointer */ event(pointer: string | EventPointer | AddressPointer | AddressPointerWithoutD): Observable; /** Subscribe to a replaceable event by pointer */ replaceable(pointer: AddressPointer | AddressPointerWithoutD): Observable; replaceable(kind: number, pubkey: string, identifier?: string): Observable; /** Subscribe to an addressable event by pointer */ addressable(pointer: AddressPointer): Observable; /** Creates a {@link TimelineModel} */ timeline(filters: Filter | Filter[], includeOldVersion?: boolean): Observable; /** Subscribe to a users profile */ profile(user: string | ProfilePointer): Observable; /** Subscribe to a users contacts */ contacts(user: string | ProfilePointer): Observable; /** Subscribe to a users mailboxes */ mailboxes(user: string | ProfilePointer): Observable<{ inboxes: string[]; outboxes: string[]; } | undefined>; /** * Tears down all models, completing active subscriptions and releasing their keep-warm timers immediately. * @note This is a terminal operation; the instance should be discarded after calling it. */ dispose(): void; }