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
208 lines (207 loc) • 6.07 kB
TypeScript
import { IPipelineBuilder, Pipeline, PipelineStage } from "./types";
/**
* Main class for building MongoDB aggregation pipelines
*/
export declare class PipelineBuilder implements IPipelineBuilder {
private stages;
/**
* Add a custom stage to the pipeline
* @param stage The pipeline stage to add
*/
addStage(stage: PipelineStage): this;
/**
* Add a $addFields stage to the pipeline
* @param fields The fields to add
*/
addFields(fields: object): this;
/**
* Add a $bucket stage to the pipeline
* @param options The bucket options
*/
bucket(options: object): this;
/**
* Add a $bucketAuto stage to the pipeline
* @param options The bucketAuto options
*/
bucketAuto(options: object): this;
/**
* Add a $collStats stage to the pipeline
* @param options The collStats options
*/
collStats(options: object): this;
/**
* Add a $count stage to the pipeline
* @param fieldName The name of the output field
*/
count(fieldName: string): this;
/**
* Add a $facet stage to the pipeline
* @param options The facet options
*/
facet(options: object): this;
/**
* Add a $geoNear stage to the pipeline
* @param options The geoNear options
*/
geoNear(options: object): this;
/**
* Add a $graphLookup stage to the pipeline
* @param options The graphLookup options
*/
graphLookup(options: object): this;
/**
* Add a $group stage to the pipeline
* @param expression The group expression
*/
group(expression: object): this;
/**
* Add a $indexStats stage to the pipeline
* @param options The indexStats options
*/
indexStats(options: object): this;
/**
* Add a $limit stage to the pipeline
* @param n The number of documents to limit to
*/
limit(n: number): this;
/**
* Add a $lookup stage to the pipeline
* @param options The lookup options
*/
lookup(options: object): this;
/**
* Add a $match stage to the pipeline
* @param condition The match condition
*/
match(condition: object): this;
/**
* Add a $merge stage to the pipeline
* @param options The merge options
*/
merge(options: object): this;
/**
* Add an $out stage to the pipeline
* @param collection The output collection name or options
*/
out(collection: string | object): this;
/**
* Add a $project stage to the pipeline
* @param projection The projection specification
*/
project(projection: object): this;
/**
* Add a $redact stage to the pipeline
* @param expression The redact expression
*/
redact(expression: object): this;
/**
* Add a $replaceRoot stage to the pipeline
* @param newRoot The new root document
*/
replaceRoot(newRoot: object): this;
/**
* Add a $replaceWith stage to the pipeline
* @param newRoot The new root document
*/
replaceWith(newRoot: object): this;
/**
* Add a $sample stage to the pipeline
* @param options The sample options
*/
sample(options: {
size: number;
}): this;
/**
* Add a $setWindowFields stage to the pipeline
* @param options The setWindowFields options
*/
setWindowFields(options: object): this;
/**
* Add a $skip stage to the pipeline
* @param n The number of documents to skip
*/
skip(n: number): this;
/**
* Add a $sort stage to the pipeline
* @param sort The sort specification
*/
sort(sort: object): this;
/**
* Add a $sortByCount stage to the pipeline
* @param expression The expression to group by
*/
sortByCount(expression: any): this;
/**
* Add a $unionWith stage to the pipeline
* @param options The collection to union with, or options object
*/
unionWith(options: string | object): this;
/**
* Add an $unset stage to the pipeline
* @param fields The field or fields to remove
*/
unset(fields: string | string[]): this;
/**
* Add a $unwind stage to the pipeline
* @param field The field path to unwind or an object with unwind options
*/
unwind(field: string | object): this;
/**
* Build the final pipeline
* @returns The complete pipeline array
*/
build(): Pipeline;
/**
* Clear all stages from the 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): PipelineStage | undefined;
/**
* Replace a stage in the pipeline
* @param index The index of the stage to replace
* @param stage The new stage
*/
replaceStage(index: number, stage: PipelineStage): this;
/**
* Remove a stage from the pipeline
* @param index The index of the stage to remove
*/
removeStage(index: number): this;
/**
* 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;
}