/** * Streaming Pipeline System for Brainy * * Real implementation of streaming data pipelines with: * - Async iterators for streaming * - Backpressure handling * - Auto-scaling workers * - Checkpointing for recovery * - Error boundaries */ import { Brainy } from '../brainy.js'; /** * Pipeline stage types */ export type StageType = 'source' | 'transform' | 'filter' | 'batch' | 'sink' | 'branch' | 'merge' | 'window' | 'reduce'; /** * Pipeline execution options */ export interface PipelineOptions { workers?: number | 'auto'; checkpoint?: boolean | string; monitoring?: boolean; maxThroughput?: number; backpressure?: 'drop' | 'buffer' | 'pause'; retries?: number; errorHandler?: (error: Error, item: any) => void; bufferSize?: number; } /** * Base interface for pipeline stages */ export interface PipelineStage { type: StageType; name: string; process(input: AsyncIterable): AsyncIterable; } /** * Streaming Pipeline Builder */ export declare class Pipeline { private brainyInstance?; private stages; private running; private abortController?; private metrics; constructor(brainyInstance?: Brainy | Brainy); /** * Add a data source */ source(generator: AsyncIterable | (() => AsyncIterable) | AsyncGeneratorFunction): Pipeline; /** * Transform data */ map(fn: (item: T) => R | Promise): Pipeline; /** * Filter data */ filter(predicate: (item: T) => boolean | Promise): Pipeline; /** * Batch items for efficiency */ batch(size: number, timeoutMs?: number): Pipeline; /** * Sink data to a destination */ sink(handler: (item: T) => Promise | void): Pipeline; /** * Sink data to Brainy */ toBrainy(options?: { type?: string; metadata?: any; batchSize?: number; }): Pipeline; /** * Sink with rate limiting */ throttledSink(handler: (item: T) => Promise | void, rateLimit: number): Pipeline; /** * Parallel sink with worker pool */ parallelSink(handler: (item: T) => Promise | void, workers?: number): Pipeline; /** * Collect all results */ collect(): Promise; /** * Window operations for time-based processing */ window(size: number, type?: 'tumbling' | 'sliding'): Pipeline; /** * Flatmap operation - map and flatten results */ flatMap(fn: (item: T) => R[] | Promise): Pipeline; /** * Tap into the pipeline for side effects without modifying data */ tap(fn: (item: T) => void | Promise): Pipeline; /** * Retry failed operations */ retry(fn: (item: T) => R | Promise, maxRetries?: number, backoff?: number): Pipeline; /** * Buffer with backpressure handling */ buffer(size: number, strategy?: 'drop' | 'block'): Pipeline; /** * Fork the pipeline into multiple branches */ fork(...branches: Array<(pipeline: Pipeline) => Pipeline>): Pipeline; /** * Reduce operation */ reduce(reducer: (acc: R, item: T) => R, initial: R): Pipeline; /** * Run the pipeline with metrics tracking */ run(options?: PipelineOptions): Promise; /** * Start the pipeline (alias for run) */ start(options?: PipelineOptions): Promise; /** * Stop the pipeline */ stop(): void; /** * Monitor pipeline metrics */ monitor(dashboard?: string): Pipeline; } /** * Pipeline factory function */ export declare function createPipeline(brain?: Brainy): Pipeline; /** * Backward compatibility exports */ export declare const pipeline: Pipeline; export declare enum ExecutionMode { SEQUENTIAL = "sequential", PARALLEL = "parallel", FIRST_SUCCESS = "firstSuccess", FIRST_RESULT = "firstResult", THREADED = "threaded" } export type PipelineResult = { success: boolean; data: T; error?: string; }; export type StreamlinedPipelineOptions = PipelineOptions; export type StreamlinedPipelineResult = PipelineResult; export { ExecutionMode as StreamlinedExecutionMode };