import { PrintJobStatus, PrintJobPriority } from '../queue/PrintQueue'; /** * Print history entry */ export interface PrintHistoryEntry { /** Unique entry ID */ id: string; /** Job ID from PrintJobManager */ jobId?: string; /** Print data size in bytes */ dataSize: number; /** Job status */ status: PrintJobStatus | 'unknown'; /** Priority */ priority: PrintJobPriority; /** Creation timestamp */ createdAt: number; /** Start timestamp */ startedAt?: number; /** Completion timestamp */ completedAt?: number; /** Duration in milliseconds */ duration?: number; /** Error message if failed */ error?: string; /** Device ID */ deviceId?: string; /** Device name */ deviceName?: string; /** Metadata */ metadata?: Record; } /** * History statistics */ export interface PrintHistoryStats { /** Total jobs */ total: number; /** Completed jobs */ completed: number; /** Failed jobs */ failed: number; /** Cancelled jobs */ cancelled: number; /** Average duration in ms */ avgDuration: number; /** Total bytes printed */ totalBytes: number; /** Success rate */ successRate: number; } /** * Query options for history */ export interface HistoryQueryOptions { /** Start date filter */ startDate?: number; /** End date filter */ endDate?: number; /** Status filter */ status?: PrintJobStatus | PrintJobStatus[]; /** Device ID filter */ deviceId?: string; /** Limit results */ limit?: number; /** Offset for pagination */ offset?: number; } /** * Print History Service */ export declare class PrintHistory { private readonly logger; private readonly entries; private counter; /** Default maximum number of history entries */ private static readonly DEFAULT_MAX_ENTRIES; private readonly maxEntries; /** Ordered index of entry IDs by createdAt (ascending) for fast pruning */ private readonly orderedIds; /** * Creates a new PrintHistory instance * @param maxEntries - Maximum number of entries to keep (default: 1000) */ constructor(maxEntries?: number); /** * Add a new print job to history */ addJob(params: { jobId?: string; data: Uint8Array; status: PrintJobStatus | 'unknown'; priority?: PrintJobPriority; deviceId?: string; deviceName?: string; metadata?: Record; }): string; /** * Update job status */ updateJob(id: string, updates: Partial<{ status: PrintJobStatus | 'unknown'; startedAt: number; completedAt: number; error: string; }>): void; /** * Get entry by ID */ getEntry(id: string): PrintHistoryEntry | undefined; /** * Get recent jobs */ getRecent(count?: number): PrintHistoryEntry[]; /** * Query history with filters */ query(options?: HistoryQueryOptions): PrintHistoryEntry[]; /** * Get statistics */ getStats(options?: { days?: number; }): PrintHistoryStats; /** * Clear all history */ clear(): void; /** * Export history as JSON */ export(): string; /** * Import history from JSON */ import(json: string): number; /** * Generate unique ID */ private generateId; /** * Enforce maximum entries limit using the ordered index. * Instead of full-sorting, we use the pre-sorted index to find and remove the oldest entries. */ private enforceMaxEntries; /** * Binary search to find the insertion position for a given timestamp * in the orderedIds array (ascending order). */ private findInsertPosition; /** * Rebuild the ordered index from the entries map. * Used after bulk operations like import. */ private rebuildIndex; } export declare const printHistory: PrintHistory;