import type { Maybe, MaybeAsync } from "@welshman/lib"; import type { Filter, TrustedEvent } from "@welshman/util"; import type { Readable, Unsubscriber } from "./svelte.js"; import type { Projection } from "./misc.js"; import type { Repository } from "./repository/core.js"; /** A `Projection` whose value comes from a `Repository`, with `load` for a fresh read. */ export type AsyncProjection = Projection & { load: () => Promise; }; /** Build an `AsyncProjection` derived from another, whose `load` reads `src` fresh. */ export declare const projectAsync: (src: AsyncProjection, read: ($: S) => U) => AsyncProjection; export type EventsById = Map; export type EventsByIdOptions = { filters: Filter[]; repository: Repository; includeDeleted?: boolean; }; export declare const getEventsById: ({ filters, repository, includeDeleted }: EventsByIdOptions) => Promise>; /** The events matching `filters`, kept current. It holds its last value until the read answers. */ export declare const deriveEventsById: (options: EventsByIdOptions) => AsyncProjection; export type ObserveEventsByIdOptions = EventsByIdOptions & { onEvents: (eventsById: EventsById) => void; }; /** Calls `onEvents` with the matches once the read answers, then on each change, until stopped. */ export declare const observeEventsById: ({ filters, repository, includeDeleted, onEvents, }: ObserveEventsByIdOptions) => Unsubscriber; export declare const deriveArray: (itemsById: Projection>) => Projection; export declare const deriveEventsArray: (eventsById: AsyncProjection) => AsyncProjection; export declare const deriveEventsAsc: (eventsById: AsyncProjection) => AsyncProjection; export declare const deriveEventsDesc: (eventsById: AsyncProjection) => AsyncProjection; export declare const deriveEvents: (options: EventsByIdOptions) => AsyncProjection; export type EventOptions = { repository: Repository; includeDeleted?: boolean; onDerive?: (filters: Filter[], ...args: any[]) => void; }; export declare const makeDeriveEvent: ({ repository, includeDeleted, onDerive }: EventOptions) => (idOrAddress: string, ...args: any[]) => AsyncProjection>; export type EventsByIdByUrl = Map; export declare const getEventsByIdByUrl: ({ filters, repository, includeDeleted, }: EventsByIdOptions) => Promise; /** The events matching `filters`, grouped by each relay the tracker has seen them on. */ export declare const deriveEventsByIdByUrl: (options: EventsByIdOptions) => AsyncProjection; export type EventsByIdForUrlOptions = EventsByIdOptions & { url: string; }; /** The events one relay has been seen to hold, with any limit counting only those events. */ export declare const getEventsByIdForUrl: ({ url, filters, repository, includeDeleted, }: EventsByIdForUrlOptions) => Promise>; export declare const deriveEventsByIdForUrl: (options: EventsByIdForUrlOptions) => AsyncProjection; export type ItemsByKey = Map; export type EventToItem = (event: TrustedEvent) => MaybeAsync>; export type GetItem = (key: string, ...args: any[]) => MaybeAsync>; /** Items keyed from events, with a `read` that waits out the query and parses still pending. */ export type ItemCollection = Projection> & { read: (key: string) => MaybeAsync>; }; export type ItemsByKeyOptions = { getKey: (item: T) => string; filters: Filter[]; repository: Repository; eventToItem: EventToItem; includeDeleted?: boolean; }; export declare const deriveItemsByKey: ({ getKey, filters, repository, eventToItem, includeDeleted, }: ItemsByKeyOptions) => ItemCollection; export type ItemsByKeyByUrlOptions = { getKey: (item: T, url: string) => string | undefined; filters: Filter[]; repository: Repository; eventToItem: EventToItem; includeDeleted?: boolean; revalidateOn?: Readable; }; /** Like `deriveItemsByKey`, but keying each event once per relay the tracker has seen it on. */ export declare const deriveItemsByKeyByUrl: ({ getKey, filters, repository, eventToItem, includeDeleted, revalidateOn, }: ItemsByKeyByUrlOptions) => ItemCollection; export declare const deriveItems: (itemsByKeyStore: Readable>) => Readable; export declare const deriveItemsSorted: (sortFn: (item: T) => number, itemsStore: Readable) => Readable; export declare const makeDeriveItem: (itemsByKeyStore: Readable>, onDerive?: (key: string, ...args: any[]) => unknown) => (key?: string, ...args: any[]) => Readable; export type LoadItem = (key: string, ...args: any[]) => Promise; export declare const makeForceLoadItem: (loadItem: LoadItem, getItem: GetItem) => (key: string, ...args: any[]) => Promise>; export type MakeLoadItemOptions = { getFetched?: (key: string) => number; setFetched?: (key: string, ts: number) => void; getSource?: (...args: any[]) => string; maxSize?: number; timeout?: number; }; export declare const makeLoadItem: (loadItem: LoadItem, getItem: GetItem, options?: MakeLoadItemOptions) => (key: string, ...args: any[]) => Promise>; export declare const deriveIsDeleted: (repository: Repository, event: TrustedEvent) => Projection; //# sourceMappingURL=derive.d.ts.map