import type { Maybe } from "@welshman/lib"; import type { Filter, TrustedEvent } from "@welshman/util"; import type { Tracker } from "../tracker.js"; import type { Unsubscriber } from "../svelte.js"; export type RepositoryUpdate = { added: TrustedEvent[]; removed: Set; }; export declare const mergeRepositoryUpdates: (updates: RepositoryUpdate[]) => RepositoryUpdate; export type QueryOptions = { includeDeleted?: boolean; includeExpired?: boolean; /** Only events the repository's tracker has seen on this relay, applied before any limit. */ relay?: string; /** Rejects the query with the signal's reason if it aborts before the repository answers. */ signal?: AbortSignal; }; export type CountTagsOptions = Pick; export type RepositoryEvents = { update: [RepositoryUpdate]; clear: []; }; export type RepositoryOptions = { /** Defaults to a new Tracker; repositories holding different events can share one. */ tracker?: Tracker; }; export type RepositoryFactory = (options: RepositoryOptions) => R | Promise; /** Where an app's events live. Reads are async; `tracker` and `isDeleted` are synchronous. */ export interface Repository { tracker: Tracker; query(filters: Filter[], options?: QueryOptions): Promise; count(filters: Filter[], options?: QueryOptions): Promise; /** How many visible events carry each value of the single-letter tag `name`. */ countTags(name: string, options?: CountTagsOptions): Promise>; getEvent(idOrAddress: string): Promise>; isDeleted(event: TrustedEvent): boolean; /** Stores `event`, resolving whether a query would now return it. */ publish(event: TrustedEvent): Promise; removeEvent(idOrAddress: string): Promise; /** Settles once every write so far is reported, or is undefined when none is outstanding. */ pendingWrites(): Maybe>; clear(): Promise; observe(options: ObserveOptions): Unsubscriber; on(event: E, listener: (...args: RepositoryEvents[E]) => void): unknown; off(event: E, listener: (...args: RepositoryEvents[E]) => void): unknown; } export type ObserveOptions = { filters: Filter[]; onUpdate: (update: RepositoryUpdate) => void; /** Receives the read's events reconciled with changes made meanwhile, and again after a clear. */ onLoad?: (events: TrustedEvent[]) => void; /** Receives a read that fails. Without it, the failure is logged. */ onError?: (error: unknown) => void; /** Also reports deleted events, and no removals. */ includeDeleted?: boolean; /** Only events the tracker has seen on this relay. */ relay?: string; }; /** Reads the stored events matching `filters`, then reports each change until unsubscribed. */ export declare const observeRepository: (repository: Repository, { filters, onUpdate, onLoad, onError, includeDeleted, relay }: ObserveOptions) => Unsubscriber; export type DeleteRecord = Pick; /** Who deleted what: each id or address a delete names, and what each delete named. */ export declare class DeleteIndex { deletes: Map; deletedBy: Map; add: (event: DeleteRecord, key: string) => void; withdraw: (id: string) => string[]; isDeletedById: (event: TrustedEvent) => boolean; isDeletedByAddress: (event: TrustedEvent) => boolean; isDeleted: (event: TrustedEvent) => boolean; clear: () => void; } //# sourceMappingURL=core.d.ts.map