import type { BaseItem } from './Collection'; import type { ReplicatedCollectionOptions } from './ReplicatedCollection'; import ReplicatedCollection from './ReplicatedCollection'; import type Selector from './types/Selector'; interface AutoFetchOptions, I> { fetchQueryItems: (selector: Selector) => ReturnType['pull']>; purgeDelay?: number; registerRemoteChange?: (onChange: () => Promise) => Promise; mergeItems?: (itemA: T, itemB: T) => T; } export type AutoFetchCollectionOptions, I, E extends BaseItem = T, U = E> = Omit, 'pull' | 'registerRemoteChange'> & AutoFetchOptions; /** * A special collection that automatically fetches items when they are needed. */ export default class AutoFetchCollection = BaseItem, I = any, E extends BaseItem = T, U = E> extends ReplicatedCollection { private activeObservers; private observerTimeouts; private purgeDelay; private idQueryCache; private itemsCache; private fetchQueryItems; private triggerReload; private reactivityAdapter; private loadingSignals; private isFetchingSignal; private mergeItems; /** * @param options {Object} - Options for the collection. * @param options.fetchQueryItems {Function} - A function that fetches items from the server. It takes the selector as an argument and returns a promise that resolves to an object with an `items` property. * @param options.purgeDelay {Number} - The delay in milliseconds before purging an item from the cache. */ constructor(options: AutoFetchCollectionOptions); /** * Registers a query manually that items should be fetched for it * @param selector {Object} Selector of the query */ registerQuery(selector: Selector): void; /** * Unregisters a query manually that items are not fetched anymore for it * @param selector {Object} Selector of the query */ unregisterQuery(selector: Selector): void; private getKeyForSelector; private forceRefetch; private fetchSelector; private handleObserverCreation; private handleObserverDisposal; private ensureSignal; private setLoading; /** * Indicates wether a query is currently been loaded * ⚡️ this function is reactive! * @param selector {Object} Selector of the query * @returns The loading state */ isLoading(selector?: Selector): boolean; } export {};