/** * Base Collection Module * * Provides shared functionality for all collection types to reduce code duplication. * This module extracts common patterns used across QueryCollection, SyncCollection, * and PGLiteCollection. */ import type { BaseRecord, SyncState } from '../types'; /** * Configuration for subscriber management */ export interface SubscriberConfig { /** Maximum number of subscribers before warning (helps detect memory leaks) */ maxSubscribers?: number; /** Whether to log warnings when subscriber threshold is exceeded */ warnOnThresholdExceeded?: boolean; } /** * Default sync state for new collections */ export declare const DEFAULT_SYNC_STATE: SyncState; /** * Generate a unique ID with optional prefix * * @param prefix - Optional prefix for the ID (e.g., collection ID) * @returns A unique string ID */ export declare function generateUniqueId(prefix?: string): string; /** * Generate a mutation ID for tracking optimistic updates * * @param prefix - Optional prefix (defaults to 'mut') * @returns A unique mutation ID */ export declare function generateMutationId(prefix?: string): string; /** * Subscriber management mixin * * Provides type-safe subscriber management with optional threshold warnings * to help detect memory leaks from components not unsubscribing. */ export declare class SubscriberManager { private subscribers; private config; private collectionId; constructor(collectionId: string, config?: SubscriberConfig); /** * Add a subscriber * * @param callback - Function to call when data changes * @returns Unsubscribe function */ subscribe(callback: (data: T) => void): () => void; /** * Notify all subscribers with new data * * @param data - Data to send to subscribers */ notify(data: T): void; /** * Get current subscriber count */ getCount(): number; /** * Clear all subscribers */ clear(): void; /** * Check if there are any active subscribers */ hasSubscribers(): boolean; /** * Detect orphaned subscriptions (for debugging) */ detectOrphans(): { count: number; warning: string; }; } /** * Update sync state immutably, removing lastError if not provided * * @param current - Current sync state * @param updates - Partial updates to apply * @returns New sync state object */ export declare function updateSyncState(current: SyncState, updates: Partial & { clearError?: boolean; }): SyncState; /** * Create a defensive copy of sync state for external consumers * * @param state - Internal sync state * @returns A copy safe for external use */ export declare function copySyncState(state: SyncState): SyncState; /** * Type guard for checking if an ID is a string */ export declare function isStringId(id: string | number): id is string; /** * Type guard for checking if an ID is a number */ export declare function isNumberId(id: string | number): id is number; /** * Determine ID type from a collection of existing IDs * * @param existingIds - Array of existing IDs * @returns 'string' or 'number' based on the majority type */ export declare function inferIdType(existingIds: Array): 'string' | 'number'; /** * Auto-increment ID generator for collections using numeric IDs */ export declare class NumericIdGenerator { private nextId; /** * Get the next ID and increment the counter */ next(): number; /** * Update the counter if a higher ID is encountered * * @param id - ID to check against current counter */ track(id: number): void; /** * Reset the counter */ reset(): void; } /** * Timer manager for handling intervals and timeouts with proper cleanup */ export declare class TimerManager { private intervals; private timeouts; /** * Create a managed interval */ setInterval(callback: () => void, ms: number): ReturnType; /** * Clear a managed interval */ clearInterval(id: ReturnType): void; /** * Create a managed timeout */ setTimeout(callback: () => void, ms: number): ReturnType; /** * Clear a managed timeout */ clearTimeout(id: ReturnType): void; /** * Get total count of active timers */ getActiveCount(): number; /** * Clear all managed timers */ clearAll(): void; } /** * Item store with optional LRU eviction support */ export declare class ItemStore { private items; private accessOrder; private accessCounter; private maxSize; private evictionPolicy; constructor(options?: { maxSize?: number; evictionPolicy?: 'lru' | 'fifo'; }); /** * Get an item by ID, updating access order for LRU */ get(id: string | number): T | undefined; /** * Set an item, evicting if necessary */ set(id: string | number, item: T): void; /** * Delete an item */ delete(id: string | number): boolean; /** * Check if an item exists */ has(id: string | number): boolean; /** * Get all items as an array */ getAll(): T[]; /** * Get all IDs */ keys(): IterableIterator; /** * Get the current size */ get size(): number; /** * Clear all items */ clear(): void; /** * Evict one item based on the eviction policy */ private evictOne; } //# sourceMappingURL=base-collection.d.ts.map