import { DomainSeederConfig, IStreamingSeeder, SeederResult, SeedableAggregate } from './shared-seeder-types.js'; import { EventEmitter } from 'events'; /** * Configuration for streaming behavior and performance tuning */ export interface StreamingConfig { /** Batch size for each generation cycle */ batchSize?: number; /** Enable backpressure handling */ enableBackpressure?: boolean; /** High water mark for backpressure (items in memory) */ highWaterMark?: number; /** Enable progress tracking and metrics */ enableProgressTracking?: boolean; /** Progress reporting interval (number of items) */ progressInterval?: number; /** Maximum concurrent batch processing */ maxConcurrency?: number; /** Enable memory monitoring and garbage collection hints */ enableMemoryManagement?: boolean; /** Memory limit in MB before forcing GC */ memoryLimit?: number; /** Delay between batches in milliseconds (for throttling) */ batchDelay?: number; /** Enable detailed performance metrics */ enableMetrics?: boolean; } /** * Progress information for streaming operations */ export interface StreamingProgress { /** Number of items completed */ completed: number; /** Total items to process */ total: number; /** Current processing rate (items per second) */ rate: number; /** Estimated time remaining in milliseconds */ estimatedTimeRemaining: number; /** Current memory usage in MB */ memoryUsage?: number; /** Number of errors encountered */ errorCount: number; /** Current batch being processed */ currentBatch: number; /** Total number of batches */ totalBatches: number; } /** * Performance metrics for streaming operations */ export interface StreamingMetrics { /** Total items processed */ totalItems: number; /** Total processing time in milliseconds */ totalTime: number; /** Average items per second */ averageRate: number; /** Peak items per second */ peakRate: number; /** Memory usage statistics */ memoryStats: { peak: number; average: number; current: number; }; /** Error statistics */ errorStats: { total: number; byType: Map; failureRate: number; }; /** Batch processing statistics */ batchStats: { totalBatches: number; averageBatchTime: number; slowestBatch: number; fastestBatch: number; }; } /** * Streaming seeder implementation with high-performance architecture. * * This seeder is specifically designed for large-scale data generation * scenarios where memory efficiency and performance are critical. * It provides streaming interfaces that can handle millions of records * without overwhelming system resources. * * The architecture includes: * - Lazy evaluation with generator functions * - Configurable batch processing * - Memory management with garbage collection hints * - Backpressure handling to prevent resource exhaustion * - Comprehensive metrics and progress tracking * - Error recovery with partial failure tolerance */ export declare class StreamingSeeder extends EventEmitter implements IStreamingSeeder { private readonly aggregateSeeder; private readonly config; private metrics; private isStreaming; private shouldStop; /** * Creates a new StreamingSeeder instance. * * @param AggregateClass Constructor for the aggregate type * @param globalConfig Global seeder configuration * @param streamingConfig Streaming-specific configuration */ constructor(AggregateClass: new (...args: any[]) => T, globalConfig?: DomainSeederConfig, streamingConfig?: StreamingConfig); /** * Configures batch processing parameters. * * @param size Batch size for each generation cycle * @returns StreamingSeeder instance for method chaining */ withBatchSize(size: number): this; /** * Configures backpressure handling. * * @param config Backpressure configuration * @returns StreamingSeeder instance for method chaining */ withBackpressure(config: { highWaterMark: number; }): this; /** * Configures progress tracking. * * @param enabled Whether to enable progress tracking * @param interval Optional interval for progress reports * @returns StreamingSeeder instance for method chaining */ withProgressTracking(enabled: boolean, interval?: number): this; /** * Configures memory management settings. * * @param limit Memory limit in MB * @param enableGC Whether to enable garbage collection hints * @returns StreamingSeeder instance for method chaining */ withMemoryManagement(limit: number, enableGC?: boolean): this; /** * Configures concurrency settings. * * @param maxConcurrency Maximum concurrent batch processing * @returns StreamingSeeder instance for method chaining */ withConcurrency(maxConcurrency: number): this; /** * Creates a streaming iterator for large-scale aggregate generation. * * @param count Total number of aggregates to generate * @param batchSize Optional batch size override * @returns Async iterable of aggregate results */ stream(count: number, batchSize?: number): AsyncIterable>; /** * Implements the ISeeder interface for single item generation. * Note: This delegates to the underlying AggregateSeeder. */ build(): Promise>; /** * Implements the ISeeder interface for multiple item generation. * Note: For large counts, prefer using the stream() method. */ buildMany(count: number): Promise>; /** * Stops the streaming process gracefully. */ stop(): void; /** * Gets current streaming metrics. * * @returns Current metrics object */ getMetrics(): Readonly; /** * Resets streaming metrics. */ resetMetrics(): void; /** * Checks if streaming is currently active. * * @returns True if streaming is in progress */ isActive(): boolean; /** * Gets streaming configuration. * * @returns Current streaming configuration */ getConfig(): Readonly; /** * Reports progress to listeners. */ private reportProgress; /** * Handles batch processing errors. */ private handleBatchError; /** * Updates batch processing statistics. */ private updateBatchStats; /** * Gets current memory usage in MB. */ private getCurrentMemoryUsage; /** * Triggers garbage collection if available. */ private triggerGarbageCollection; /** * Waits for backpressure relief. */ private waitForBackpressureRelief; /** * Simple delay utility. */ private delay; }