mongo-pipeline-kit
Version:
A feature-rich MongoDB pipeline builder kit for creating, reusing, and managing aggregation pipelines with enhanced JSON support and advanced utilities
100 lines (99 loc) • 3.4 kB
TypeScript
import { Pipeline, PipelineStage, ValidationOptions } from "./types";
/**
* Utility class for pipeline operations
*/
export declare class PipelineUtils {
/**
* Parse a JSON string into a pipeline
* @param jsonString JSON string representation of a pipeline
* @returns Parsed pipeline
*/
static fromJSON(jsonString: string): Pipeline;
/**
* Convert pipeline to JSON string
* @param pipeline The pipeline to convert
* @param pretty Whether to format the JSON with indentation
* @returns JSON string representation
*/
static toJSON(pipeline: Pipeline, pretty?: boolean): string;
/**
* Validate pipeline structure
* @param pipeline The pipeline to validate
* @param options Validation options
* @returns True if valid, throws error if invalid
*/
static validate(pipeline: Pipeline, options?: ValidationOptions): boolean;
/**
* Clone a pipeline (deep copy)
* @param pipeline The pipeline to clone
* @returns Cloned pipeline
*/
static clone(pipeline: Pipeline): Pipeline;
/**
* Get pipeline statistics
* @param pipeline The pipeline to analyze
* @returns Statistics about the pipeline
*/
static getStats(pipeline: Pipeline): {
stageCount: number;
stageTypes: Record<string, number>;
totalSize: number;
estimatedComplexity: number;
};
/**
* Filter pipeline stages by type
* @param pipeline The pipeline to filter
* @param operator The stage operator to filter by
* @returns Filtered pipeline stages
*/
static filterByStageType(pipeline: Pipeline, operator: string): PipelineStage[];
/**
* Remove stages by type
* @param pipeline The pipeline to modify
* @param operator The stage operator to remove
* @returns New pipeline without the specified stage type
*/
static removeStageType(pipeline: Pipeline, operator: string): Pipeline;
/**
* Insert a stage at a specific position
* @param pipeline The pipeline to modify
* @param index The position to insert at
* @param stage The stage to insert
* @returns New pipeline with inserted stage
*/
static insertStage(pipeline: Pipeline, index: number, stage: PipelineStage): Pipeline;
/**
* Replace a stage at a specific position
* @param pipeline The pipeline to modify
* @param index The position to replace
* @param stage The new stage
* @returns New pipeline with replaced stage
*/
static replaceStage(pipeline: Pipeline, index: number, stage: PipelineStage): Pipeline;
/**
* Get a human-readable description of the pipeline
* @param pipeline The pipeline to describe
* @returns Formatted description
*/
static describe(pipeline: Pipeline): string;
/**
* Compare two pipelines
* @param pipeline1 First pipeline
* @param pipeline2 Second pipeline
* @returns Comparison result
*/
static compare(pipeline1: Pipeline, pipeline2: Pipeline): {
areEqual: boolean;
differences: {
stageCount: {
p1: number;
p2: number;
};
stageTypes: {
p1: Record<string, number>;
p2: Record<string, number>;
};
commonStages: number;
};
};
}