CRITICAL CHECKPOINT - DO NOT PUSH TO GITHUB Recovery Status: - Successfully recovered brainy.ts from compiled JavaScript - All core v3.0 API methods functional (add, get, update, delete, relate, find, etc.) - Neural subsystem intact (562KB embedded patterns, NLP working) - Augmentation pipeline operational (20+ augmentations) - HNSW clustering system complete - Triple Intelligence compiled (needs constructor fix) - Test suite validates functionality Changes preserved: - 898 files with changes from last 3 days - 144,475 insertions - All augmentation improvements - All test coverage enhancements - Complete v3.0 feature set This is a LOCAL checkpoint only - contains recovered work after corruption incident. Created backup in .backups/brainy-full-20250910-151314.tar.gz Branch: recovery-checkpoint-20250910-151433 Date: Wed Sep 10 03:18:04 PM PDT 2025
154 lines
4.2 KiB
TypeScript
154 lines
4.2 KiB
TypeScript
/**
|
|
* 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<T = any, R = any> {
|
|
type: StageType;
|
|
name: string;
|
|
process(input: AsyncIterable<T>): AsyncIterable<R>;
|
|
}
|
|
/**
|
|
* Streaming Pipeline Builder
|
|
*/
|
|
export declare class Pipeline<T = any> {
|
|
private brainyInstance?;
|
|
private stages;
|
|
private running;
|
|
private abortController?;
|
|
private metrics;
|
|
constructor(brainyInstance?: Brainy | Brainy<any>);
|
|
/**
|
|
* Add a data source
|
|
*/
|
|
source<S>(generator: AsyncIterable<S> | (() => AsyncIterable<S>) | AsyncGeneratorFunction): Pipeline<S>;
|
|
/**
|
|
* Transform data
|
|
*/
|
|
map<R>(fn: (item: T) => R | Promise<R>): Pipeline<R>;
|
|
/**
|
|
* Filter data
|
|
*/
|
|
filter(predicate: (item: T) => boolean | Promise<boolean>): Pipeline<T>;
|
|
/**
|
|
* Batch items for efficiency
|
|
*/
|
|
batch(size: number, timeoutMs?: number): Pipeline<T[]>;
|
|
/**
|
|
* Sink data to a destination
|
|
*/
|
|
sink(handler: (item: T) => Promise<void> | void): Pipeline<void>;
|
|
/**
|
|
* Sink data to Brainy
|
|
*/
|
|
toBrainy(options?: {
|
|
type?: string;
|
|
metadata?: any;
|
|
batchSize?: number;
|
|
}): Pipeline<void>;
|
|
/**
|
|
* Sink with rate limiting
|
|
*/
|
|
throttledSink(handler: (item: T) => Promise<void> | void, rateLimit: number): Pipeline<void>;
|
|
/**
|
|
* Parallel sink with worker pool
|
|
*/
|
|
parallelSink(handler: (item: T) => Promise<void> | void, workers?: number): Pipeline<void>;
|
|
/**
|
|
* Collect all results
|
|
*/
|
|
collect(): Promise<T[]>;
|
|
/**
|
|
* Window operations for time-based processing
|
|
*/
|
|
window(size: number, type?: 'tumbling' | 'sliding'): Pipeline<T[]>;
|
|
/**
|
|
* Flatmap operation - map and flatten results
|
|
*/
|
|
flatMap<R>(fn: (item: T) => R[] | Promise<R[]>): Pipeline<R>;
|
|
/**
|
|
* Tap into the pipeline for side effects without modifying data
|
|
*/
|
|
tap(fn: (item: T) => void | Promise<void>): Pipeline<T>;
|
|
/**
|
|
* Retry failed operations
|
|
*/
|
|
retry<R>(fn: (item: T) => R | Promise<R>, maxRetries?: number, backoff?: number): Pipeline<R>;
|
|
/**
|
|
* Buffer with backpressure handling
|
|
*/
|
|
buffer(size: number, strategy?: 'drop' | 'block'): Pipeline<T>;
|
|
/**
|
|
* Fork the pipeline into multiple branches
|
|
*/
|
|
fork(...branches: Array<(pipeline: Pipeline<T>) => Pipeline<any>>): Pipeline<T>;
|
|
/**
|
|
* Reduce operation
|
|
*/
|
|
reduce<R>(reducer: (acc: R, item: T) => R, initial: R): Pipeline<R>;
|
|
/**
|
|
* Run the pipeline with metrics tracking
|
|
*/
|
|
run(options?: PipelineOptions): Promise<void>;
|
|
/**
|
|
* Start the pipeline (alias for run)
|
|
*/
|
|
start(options?: PipelineOptions): Promise<void>;
|
|
/**
|
|
* Stop the pipeline
|
|
*/
|
|
stop(): void;
|
|
/**
|
|
* Monitor pipeline metrics
|
|
*/
|
|
monitor(dashboard?: string): Pipeline<T>;
|
|
}
|
|
/**
|
|
* Pipeline factory function
|
|
*/
|
|
export declare function createPipeline(brain?: Brainy): Pipeline;
|
|
/**
|
|
* Backward compatibility exports
|
|
*/
|
|
export declare const pipeline: Pipeline<any>;
|
|
export declare enum ExecutionMode {
|
|
SEQUENTIAL = "sequential",
|
|
PARALLEL = "parallel",
|
|
FIRST_SUCCESS = "firstSuccess",
|
|
FIRST_RESULT = "firstResult",
|
|
THREADED = "threaded"
|
|
}
|
|
export type PipelineResult<T> = {
|
|
success: boolean;
|
|
data: T;
|
|
error?: string;
|
|
};
|
|
export type StreamlinedPipelineOptions = PipelineOptions;
|
|
export type StreamlinedPipelineResult<T> = PipelineResult<T>;
|
|
export { ExecutionMode as StreamlinedExecutionMode };
|