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
81 lines (80 loc) • 2.55 kB
TypeScript
import { IPipelineComposer, Pipeline, ValidationOptions } from "./types";
/**
* Class for composing and reusing MongoDB pipeline segments
*/
export declare class PipelineComposer implements IPipelineComposer {
private pipeline;
/**
* Compose multiple pipelines into one
* @param pipelines The pipelines to compose
*/
compose(...pipelines: Pipeline[]): this;
/**
* Extend an existing pipeline with another pipeline
* @param basePipeline The base pipeline to extend
* @param extension The pipeline to extend with
*/
extend(basePipeline: Pipeline, extension: Pipeline): this;
/**
* Validate a pipeline structure
* @param pipeline The pipeline to validate
* @param options Validation options
*/
validate(pipeline: Pipeline, options?: ValidationOptions): boolean;
/**
* Build the final composed pipeline
*/
build(): Pipeline;
/**
* Clear the current pipeline
*/
clear(): this;
/**
* Get the current number of stages in the pipeline
*/
getStageCount(): number;
/**
* Get a specific stage from the pipeline
* @param index The index of the stage to retrieve
*/
getStage(index: number): import("./types").PipelineStage;
/**
* Check if the pipeline contains a specific stage type
* @param operator The stage operator to check for (e.g., '$match', '$group')
*/
hasStage(operator: string): boolean;
/**
* Get all stages of a specific type
* @param operator The stage operator to filter by
*/
getStagesByType(operator: string): Pipeline;
/**
* Get the pipeline as a JSON string
* @param pretty Whether to format the JSON with indentation
* @returns JSON string representation of the pipeline
*/
toJSON(pretty?: boolean): string;
/**
* Get the pipeline as a plain object (not stringified)
* @returns Object representation of the pipeline
*/
toObject(): Pipeline;
/**
* Export pipeline with metadata
* @param metadata Additional metadata to include
* @returns Object with pipeline and metadata
*/
exportWithMetadata(metadata?: Record<string, any>): {
pipeline: Pipeline;
metadata: {
stageCount: number;
createdAt: string;
[key: string]: any;
};
};
/**
* Get a human-readable string representation of the pipeline
* @returns Formatted string showing pipeline stages
*/
toString(): string;
}