/* * Copyright (c) 2016-present Invertase Limited & Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this library except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ import type { PipelineAggregateOptions, PipelineDistinctOptions, PipelineDefineOptions, PipelineFindNearestOptions, PipelineReplaceWithOptions, PipelineSampleOptions, PipelineSearchOptions, PipelineUnionOptions, PipelineUnnestOptions, PipelineRawStageOptions, DefineStageOptions, SearchStageOptions, } from './stage_options'; import type { BooleanExpression, Selectable, Field, Ordering, AliasedAggregate, AliasedExpression, FunctionExpression, } from './expressions'; import type { DocumentData } from '../types/firestore'; import type { FirestorePipelineSerializedInternal } from '../types/internal'; /** @internal Serialized pipeline payload shape forwarded to native/web executors. */ export type SerializedPipeline = FirestorePipelineSerializedInternal; /** * @beta * Pipeline with chained stages. Each stage returns a new Pipeline (immutable chain). */ export interface Pipeline { /** * @internal * Serializes the source + stage chain to the wire format. */ serialize(): SerializedPipeline; where(condition: BooleanExpression): Pipeline; where(options: { condition: BooleanExpression }): Pipeline; select(...selection: (Selectable | string)[]): Pipeline; select(options: { selection: (Selectable | string)[] }): Pipeline; addFields(...field: Selectable[]): Pipeline; addFields(options: { field: Selectable[] }): Pipeline; removeFields(...field: (Field | string)[]): Pipeline; removeFields(options: { field: (Field | string)[] }): Pipeline; sort(...ordering: Ordering[]): Pipeline; sort(options: { ordering: Ordering[] }): Pipeline; limit(n: number): Pipeline; limit(options: { n: number }): Pipeline; offset(n: number): Pipeline; offset(options: { n: number }): Pipeline; aggregate(...accumulator: AliasedAggregate[]): Pipeline; aggregate(options: PipelineAggregateOptions): Pipeline; distinct(...group: (Field | string)[]): Pipeline; distinct(options: PipelineDistinctOptions): Pipeline; findNearest(options: PipelineFindNearestOptions): Pipeline; /** * @beta * Add a search stage to the pipeline (full-text and geo search). Must be the first stage. */ search(options: PipelineSearchOptions): Pipeline; search(options: SearchStageOptions): Pipeline; /** * @beta * Defines one or more variables in the pipeline scope for reuse via variable(). */ define( aliasedExpression: AliasedExpression, ...additionalExpressions: AliasedExpression[] ): Pipeline; define(options: DefineStageOptions): Pipeline; define(options: PipelineDefineOptions): Pipeline; replaceWith(fieldName: string): Pipeline; replaceWith(expr: Selectable): Pipeline; replaceWith(options: PipelineReplaceWithOptions): Pipeline; sample(n: number): Pipeline; sample(options: PipelineSampleOptions): Pipeline; union(otherPipeline: Pipeline): Pipeline; union(options: PipelineUnionOptions): Pipeline; unnest(selectable: Selectable, indexField?: string): Pipeline; unnest(options: PipelineUnnestOptions): Pipeline; rawStage( name: string, params: Record, options?: PipelineRawStageOptions, ): Pipeline; /** * @beta * Converts this pipeline into an expression that evaluates to an array of results. */ toArrayExpression(): FunctionExpression; /** * @beta * Converts this pipeline into an expression that evaluates to a scalar result. */ toScalarExpression(): FunctionExpression; }