/** * TanStack Query Collection Adapter * * Provides TanStack Query patterns for data fetching with collections. * Supports caching, stale time, and automatic refetching. */ import type { BaseRecord, QueryCollectionOptions, Collection, SyncState } from '../types'; /** * Extended options for QueryCollection with memory management */ export interface QueryCollectionOptionsWithMemory extends QueryCollectionOptions { maxSize?: number; evictionPolicy?: 'lru' | 'fifo'; maxSubscribers?: number; /** Initial data to populate the collection synchronously */ initialData?: T[]; } /** * QueryCollection - A collection that fetches data via TanStack Query patterns */ export declare class QueryCollection implements Collection { readonly id: string; readonly table: string; private items; private itemAccessOrder; private accessCounter; private subscribers; private options; private syncState; private lastFetchAt; private refetchIntervalId; private nextId; private gcTimeoutId; private _finalizeCallbacks; constructor(options: QueryCollectionOptionsWithMemory); /** * Get the query function for direct invocation */ getQueryFn(): (() => Promise) | undefined; /** * Get all items in the collection */ getAll(): T[]; /** * Get item by ID */ get(id: string | number): T | undefined; /** * Check if the cached data is stale */ isStale(): boolean; /** * Get the effective stale time (supports dynamic staleTime based on data) */ private getEffectiveStaleTime; /** * Get optimistic view of collection data merged with optimistic store */ getOptimisticData(store: { getState: () => { applied: Array<{ type: string; recordId: string | number; data: Partial; }>; }; }): T[]; /** * Fetch data from the query function */ fetch(): Promise; /** * Insert a new item */ insert(data: Omit & { id?: T['id']; }): Promise; /** * Update an existing item */ update(id: string | number, data: Partial): Promise; /** * Delete an item */ delete(id: string | number): Promise; /** * Subscribe to changes */ subscribe(callback: (items: T[]) => void): () => void; /** * Subscribe with automatic cleanup after inactivity */ subscribeWithTimeout(callback: (items: T[]) => void, options: { timeoutMs: number; }): () => void; /** * Subscribe with pause/resume capability */ pausableSubscribe(callback: (items: T[]) => void): { pause: () => void; resume: () => void; unsubscribe: () => void; }; /** * Weak subscribe - registers a callback that can be GC'd */ weakSubscribe(callback: (items: T[]) => void): void; /** * Get the current subscriber count for debugging */ getSubscriberCount(): number; /** * Detect orphaned subscriptions for memory debugging */ detectOrphanedSubscriptions(): { count: number; warning: string; }; /** * Register a finalization callback */ onFinalize(callback: () => void): void; /** * Get current sync state */ getSyncState(): SyncState; /** * Start automatic refetching at the configured interval */ startAutoRefetch(): void; /** * Stop automatic refetching */ stopAutoRefetch(): void; /** * Get the count of active timers for debugging */ getActiveTimerCount(): number; /** * Clear all cached data */ clear(): void; /** * Garbage collect stale data */ gc(): void; /** * Dispose of all resources - call when the collection is no longer needed */ dispose(): void; private evictOne; private scheduleGC; private generateId; private notifySubscribers; } /** * Factory function to create a QueryCollection. * * @param options - Configuration including table name, query function, and caching parameters * @returns A new QueryCollection instance configured with the given options * * @example * ```typescript * const users = createQueryCollection({ * id: 'users', * table: 'users', * queryFn: () => fetch('/api/users').then(r => r.json()), * staleTime: 30000, * }) * ``` */ export declare function createQueryCollection(options: QueryCollectionOptions): QueryCollection; //# sourceMappingURL=query-collection.d.ts.map