UNPKG

@firebase/firestore

Version:

The Cloud Firestore component of the Firebase JS SDK.

1,418 lines (1,348 loc) • 506 kB
/** * Cloud Firestore * * @packageDocumentation */ import { DocumentData as DocumentData_2 } from '@firebase/firestore-types'; import { EmulatorMockTokenOptions } from '@firebase/util'; import { FirebaseApp } from '@firebase/app'; import { FirebaseError } from '@firebase/util'; import { _FirebaseService } from '@firebase/app'; import { SetOptions as SetOptions_2 } from '@firebase/firestore-types'; /** * @beta * Creates an expression that computes the absolute value of a numeric value. * * @param expr - The expression to compute the absolute value of. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the absolute value of the numeric value. */ export declare function abs(expr: Expression): FunctionExpression; /** * @beta * Creates an expression that computes the absolute value of a numeric value. * * @param fieldName - The field to compute the absolute value of. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the absolute value of the numeric value. */ export declare function abs(fieldName: string): FunctionExpression; /** * Converts Firestore's internal types to the JavaScript types that we expose * to the user. * * @internal */ declare abstract class AbstractUserDataWriter { convertValue(value: Value, serverTimestampBehavior?: ServerTimestampBehavior): unknown; private convertObject; /** * @internal */ convertObjectMap(fields: ApiClientObjectMap<Value> | undefined, serverTimestampBehavior?: ServerTimestampBehavior): DocumentData_2; /** * @internal */ convertVectorValue(mapValue: MapValue): VectorValue; private convertGeoPoint; private convertArray; private convertServerTimestamp; private convertTimestamp; protected convertDocumentKey(name: string, expectedDatabaseId: DatabaseId): DocumentKey; protected abstract convertReference(name: string): unknown; protected abstract convertBytes(bytes: ByteString): unknown; } /** * Describes a map whose keys are active target ids. We do not care about the type of the * values. */ declare type ActiveTargets = SortedMap<TargetId, unknown>; /** * @beta * * Creates an expression that adds two expressions together. * * @example * ```typescript * // Add the value of the 'quantity' field and the 'reserve' field. * add(field("quantity"), field("reserve")); * ``` * * @param first - The first expression to add. * @param second - The second expression or literal to add. * @param others - Optional other expressions or literals to add. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the addition operation. */ export declare function add(first: Expression, second: Expression | unknown): FunctionExpression; /** * @beta * * Creates an expression that adds a field's value to an expression. * * @example * ```typescript * // Add the value of the 'quantity' field and the 'reserve' field. * add("quantity", field("reserve")); * ``` * * @param fieldName - The name of the field containing the value to add. * @param second - The second expression or literal to add. * @param others - Optional other expressions or literals to add. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the addition operation. */ export declare function add(fieldName: string, second: Expression | unknown): FunctionExpression; /** * @beta * Options defining how an AddFieldsStage is evaluated. See {@link @firebase/firestore/pipelines#Pipeline.(addFields:1)}. */ export declare type AddFieldsStageOptions = StageOptions & { /** * @beta * The fields to add to each document, specified as a {@link @firebase/firestore/pipelines#Selectable}. * At least one field is required. */ fields: Selectable[]; }; /** * @beta * * A class that represents an aggregate function. */ export declare class AggregateFunction implements ProtoValueSerializable, UserData { private name; private params; exprType: ExpressionType; /** * @internal */ _methodName?: string; constructor(name: string, params: Expression[]); /** * @internal * @private */ static _create(name: string, params: Expression[], methodName: string): AggregateFunction; /** * @beta * Assigns an alias to this AggregateFunction. The alias specifies the name that * the aggregated value will have in the output document. * * @example * ```typescript * // Calculate the average price of all items and assign it the alias "averagePrice". * firestore.pipeline().collection("items") * .aggregate(field("price").average().as("averagePrice")); * ``` * * @param name - The alias to assign to this AggregateFunction. * @returns A new {@link @firebase/firestore/pipelines#AliasedAggregate} that wraps this * AggregateFunction and associates it with the provided alias. */ as(name: string): AliasedAggregate; /** * @private * @internal */ _toProto(serializer: JsonProtoSerializer): Value; _protoValueType: "ProtoValue"; /** * @private * @internal */ _readUserData(context: ParseContext): void; } /** * @beta * Options defining how an AggregateStage is evaluated. See {@link @firebase/firestore/pipelines#Pipeline.(aggregate:1)}. */ export declare type AggregateStageOptions = StageOptions & { /** * @beta * The {@link @firebase/firestore/pipelines#AliasedAggregate} values specifying aggregate operations to * perform on the input documents. */ accumulators: AliasedAggregate[]; /** * @beta * The {@link @firebase/firestore/pipelines#Selectable} expressions or field names to consider when determining * distinct value combinations (groups), which will be aggregated over. */ groups?: Array<string | Selectable>; }; /** * @beta * * An AggregateFunction with alias. */ export declare class AliasedAggregate implements UserData { readonly aggregate: AggregateFunction; readonly alias: string; readonly _methodName: string | undefined; constructor(aggregate: AggregateFunction, alias: string, _methodName: string | undefined); /** * @private * @internal */ _readUserData(context: ParseContext): void; } /** * @beta */ export declare class AliasedExpression implements Selectable, UserData { readonly expr: Expression; readonly alias: string; readonly _methodName: string | undefined; exprType: ExpressionType; selectable: true; constructor(expr: Expression, alias: string, _methodName: string | undefined); /** * @private * @internal */ _readUserData(context: ParseContext): void; } /** * @beta * * Creates an expression that performs a logical 'AND' operation on multiple filter conditions. * * @example * ```typescript * // Check if the 'age' field is greater than 18 AND the 'city' field is "London" AND * // the 'status' field is "active" * const condition = and(greaterThan("age", 18), equal("city", "London"), equal("status", "active")); * ``` * * @param first - The first filter condition. * @param second - The second filter condition. * @param more - Additional filter conditions to 'AND' together. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the logical 'AND' operation. */ export declare function and(first: BooleanExpression, second: BooleanExpression, ...more: BooleanExpression[]): BooleanExpression; declare interface ApiClientObjectMap<T> { [k: string]: T; } /** * @beta * * Creates an expression that creates a Firestore array value from an input array. * * @example * ```typescript * // Create an array value from the input array and reference the 'baz' field value from the input document. * array(['bar', Field.of('baz')]).as('foo'); * ``` * * @param elements - The input array to evaluate in the expression. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the array function. */ export declare function array(elements: unknown[]): FunctionExpression; /** * @beta * * Creates an expression that concatenates an array expression with other arrays. * * @example * ```typescript * // Combine the 'items' array with two new item arrays * arrayConcat(field("items"), [field("newItems"), field("otherItems")]); * ``` * * @param firstArray - The first array expression to concatenate to. * @param secondArray - The second array expression or array literal to concatenate to. * @param otherArrays - Optional additional array expressions or array literals to concatenate. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the concatenated array. */ export declare function arrayConcat(firstArray: Expression, secondArray: Expression | unknown[], ...otherArrays: Array<Expression | unknown[]>): FunctionExpression; /** * @beta * * Creates an expression that concatenates a field's array value with other arrays. * * @example * ```typescript * // Combine the 'items' array with two new item arrays * arrayConcat("items", [field("newItems"), field("otherItems")]); * ``` * * @param firstArrayField - The first array to concatenate to. * @param secondArray - The second array expression or array literal to concatenate to. * @param otherArrays - Optional additional array expressions or array literals to concatenate. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the concatenated array. */ export declare function arrayConcat(firstArrayField: string, secondArray: Expression | unknown[], ...otherArrays: Array<Expression | unknown[]>): FunctionExpression; /** * @beta * * Creates an expression that checks if an array expression contains a specific element. * * @example * ```typescript * // Check if the 'colors' array contains the value of field 'selectedColor' * arrayContains(field("colors"), field("selectedColor")); * ``` * * @param array - The array expression to check. * @param element - The element to search for in the array. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'array_contains' comparison. */ export declare function arrayContains(array: Expression, element: Expression): BooleanExpression; /** * @beta * * Creates an expression that checks if an array expression contains a specific element. * * @example * ```typescript * // Check if the 'colors' array contains "red" * arrayContains(field("colors"), "red"); * ``` * * @param array - The array expression to check. * @param element - The element to search for in the array. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'array_contains' comparison. */ export declare function arrayContains(array: Expression, element: unknown): BooleanExpression; /** * @beta * * Creates an expression that checks if a field's array value contains a specific element. * * @example * ```typescript * // Check if the 'colors' array contains the value of field 'selectedColor' * arrayContains("colors", field("selectedColor")); * ``` * * @param fieldName - The field name to check. * @param element - The element to search for in the array. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'array_contains' comparison. */ export declare function arrayContains(fieldName: string, element: Expression): BooleanExpression; /** * @beta * * Creates an expression that checks if a field's array value contains a specific value. * * @example * ```typescript * // Check if the 'colors' array contains "red" * arrayContains("colors", "red"); * ``` * * @param fieldName - The field name to check. * @param element - The element to search for in the array. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'array_contains' comparison. */ export declare function arrayContains(fieldName: string, element: unknown): BooleanExpression; /** * @beta * * Creates an expression that checks if an array expression contains all the specified elements. * * @example * ```typescript * // Check if the "tags" array contains all of the values: "SciFi", "Adventure", and the value from field "tag1" * arrayContainsAll(field("tags"), [field("tag1"), constant("SciFi"), "Adventure"]); * ``` * * @param array - The array expression to check. * @param values - The elements to check for in the array. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'array_contains_all' comparison. */ export declare function arrayContainsAll(array: Expression, values: Array<Expression | unknown>): BooleanExpression; /** * @beta * * Creates an expression that checks if a field's array value contains all the specified values or * expressions. * * @example * ```typescript * // Check if the 'tags' array contains both of the values from field 'tag1', the value "SciFi", and "Adventure" * arrayContainsAll("tags", [field("tag1"), "SciFi", "Adventure"]); * ``` * * @param fieldName - The field name to check. * @param values - The elements to check for in the array. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'array_contains_all' comparison. */ export declare function arrayContainsAll(fieldName: string, values: Array<Expression | unknown>): BooleanExpression; /** * @beta * * Creates an expression that checks if an array expression contains all the specified elements. * * @example * ```typescript * // Check if the "tags" array contains all of the values: "SciFi", "Adventure", and the value from field "tag1" * arrayContainsAll(field("tags"), [field("tag1"), constant("SciFi"), "Adventure"]); * ``` * * @param array - The array expression to check. * @param arrayExpression - The elements to check for in the array. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'array_contains_all' comparison. */ export declare function arrayContainsAll(array: Expression, arrayExpression: Expression): BooleanExpression; /** * @beta * * Creates an expression that checks if a field's array value contains all the specified values or * expressions. * * @example * ```typescript * // Check if the 'tags' array contains both of the values from field 'tag1', the value "SciFi", and "Adventure" * arrayContainsAll("tags", [field("tag1"), "SciFi", "Adventure"]); * ``` * * @param fieldName - The field name to check. * @param arrayExpression - The elements to check for in the array. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'array_contains_all' comparison. */ export declare function arrayContainsAll(fieldName: string, arrayExpression: Expression): BooleanExpression; /** * @beta * * Creates an expression that checks if an array expression contains any of the specified * elements. * * @example * ```typescript * // Check if the 'categories' array contains either values from field "cate1" or "Science" * arrayContainsAny(field("categories"), [field("cate1"), "Science"]); * ``` * * @param array - The array expression to check. * @param values - The elements to check for in the array. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'array_contains_any' comparison. */ export declare function arrayContainsAny(array: Expression, values: Array<Expression | unknown>): BooleanExpression; /** * @beta * * Creates an expression that checks if a field's array value contains any of the specified * elements. * * @example * ```typescript * // Check if the 'groups' array contains either the value from the 'userGroup' field * // or the value "guest" * arrayContainsAny("categories", [field("cate1"), "Science"]); * ``` * * @param fieldName - The field name to check. * @param values - The elements to check for in the array. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'array_contains_any' comparison. */ export declare function arrayContainsAny(fieldName: string, values: Array<Expression | unknown>): BooleanExpression; /** * @beta * * Creates an expression that checks if an array expression contains any of the specified * elements. * * @example * ```typescript * // Check if the 'categories' array contains either values from field "cate1" or "Science" * arrayContainsAny(field("categories"), array([field("cate1"), "Science"])); * ``` * * @param array - The array expression to check. * @param values - An expression that evaluates to an array, whose elements to check for in the array. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'array_contains_any' comparison. */ export declare function arrayContainsAny(array: Expression, values: Expression): BooleanExpression; /** * @beta * * Creates an expression that checks if a field's array value contains any of the specified * elements. * * @example * ```typescript * // Check if the 'groups' array contains either the value from the 'userGroup' field * // or the value "guest" * arrayContainsAny("categories", array([field("cate1"), "Science"])); * ``` * * @param fieldName - The field name to check. * @param values - An expression that evaluates to an array, whose elements to check for in the array field. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'array_contains_any' comparison. */ export declare function arrayContainsAny(fieldName: string, values: Expression): BooleanExpression; /** * @beta * Creates an expression that indexes into an array from the beginning or end * and return the element. If the offset exceeds the array length, an error is * returned. A negative offset, starts from the end. * * @example * ```typescript * // Return the value in the tags field array at index 1. * arrayGet('tags', 1); * ``` * * @param arrayField - The name of the array field. * @param offset - The index of the element to return. * @returns A new `Expression` representing the 'arrayGet' operation. */ export declare function arrayGet(arrayField: string, offset: number): FunctionExpression; /** * @beta * Creates an expression that indexes into an array from the beginning or end * and return the element. If the offset exceeds the array length, an error is * returned. A negative offset, starts from the end. * * @example * ```typescript * // Return the value in the tags field array at index specified by field * // 'favoriteTag'. * arrayGet('tags', field('favoriteTag')); * ``` * * @param arrayField - The name of the array field. * @param offsetExpr - An `Expression` evaluating to the index of the element to return. * @returns A new `Expression` representing the 'arrayGet' operation. */ export declare function arrayGet(arrayField: string, offsetExpr: Expression): FunctionExpression; /** * @beta * Creates an expression that indexes into an array from the beginning or end * and return the element. If the offset exceeds the array length, an error is * returned. A negative offset, starts from the end. * * @example * ```typescript * // Return the value in the tags field array at index 1. * arrayGet(field('tags'), 1); * ``` * * @param arrayExpression - An `Expression` evaluating to an array. * @param offset - The index of the element to return. * @returns A new `Expression` representing the 'arrayGet' operation. */ export declare function arrayGet(arrayExpression: Expression, offset: number): FunctionExpression; /** * @beta * Creates an expression that indexes into an array from the beginning or end * and return the element. If the offset exceeds the array length, an error is * returned. A negative offset, starts from the end. * * @example * ```typescript * // Return the value in the tags field array at index specified by field * // 'favoriteTag'. * arrayGet(field('tags'), field('favoriteTag')); * ``` * * @param arrayExpression - An `Expression` evaluating to an array. * @param offsetExpr - An `Expression` evaluating to the index of the element to return. * @returns A new `Expression` representing the 'arrayGet' operation. */ export declare function arrayGet(arrayExpression: Expression, offsetExpr: Expression): FunctionExpression; /** * @beta * * Creates an expression that calculates the length of an array in a specified field. * * @example * ```typescript * // Get the number of items in field 'cart' * arrayLength('cart'); * ``` * * @param fieldName - The name of the field containing an array to calculate the length of. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the length of the array. */ export declare function arrayLength(fieldName: string): FunctionExpression; /** * @beta * * Creates an expression that calculates the length of an array expression. * * @example * ```typescript * // Get the number of items in the 'cart' array * arrayLength(field("cart")); * ``` * * @param array - The array expression to calculate the length of. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the length of the array. */ export declare function arrayLength(array: Expression): FunctionExpression; /** * @beta * Creates an expression that computes the sum of the elements in an array. * * @example * ```typescript * // Compute the sum of the elements in the 'scores' field. * arraySum("scores"); * ``` * * @param fieldName - The name of the field to compute the sum of. * @returns A new `Expression` representing the sum of the elements in the array. */ export declare function arraySum(fieldName: string): FunctionExpression; /** * @beta * Creates an expression that computes the sum of the elements in an array. * * @example * ```typescript * // Compute the sum of the elements in the 'scores' field. * arraySum(field("scores")); * ``` * * @param expression - An expression evaluating to a numeric array, which the sum will be computed for. * @returns A new `Expression` representing the sum of the elements in the array. */ export declare function arraySum(expression: Expression): FunctionExpression; /** * @beta * * Creates an {@link @firebase/firestore/pipelines#Ordering} that sorts documents in ascending order based on an expression. * * @example * ```typescript * // Sort documents by the 'name' field in lowercase in ascending order * firestore.pipeline().collection("users") * .sort(ascending(field("name").toLower())); * ``` * * @param expr - The expression to create an ascending ordering for. * @returns A new `Ordering` for ascending sorting. */ export declare function ascending(expr: Expression): Ordering; /** * @beta * * Creates an {@link @firebase/firestore/pipelines#Ordering} that sorts documents in ascending order based on a field. * * @example * ```typescript * // Sort documents by the 'name' field in ascending order * firestore.pipeline().collection("users") * .sort(ascending("name")); * ``` * * @param fieldName - The field to create an ascending ordering for. * @returns A new `Ordering` for ascending sorting. */ export declare function ascending(fieldName: string): Ordering; declare interface AsyncQueue { readonly isShuttingDown: boolean; /** * Adds a new operation to the queue without waiting for it to complete (i.e. * we ignore the Promise result). */ enqueueAndForget<T extends unknown>(op: () => Promise<T>): void; /** * Regardless if the queue has initialized shutdown, adds a new operation to the * queue without waiting for it to complete (i.e. we ignore the Promise result). */ enqueueAndForgetEvenWhileRestricted<T extends unknown>(op: () => Promise<T>): void; /** * Initialize the shutdown of this queue. Once this method is called, the * only possible way to request running an operation is through * `enqueueEvenWhileRestricted()`. * * @param purgeExistingTasks - Whether already enqueued tasked should be * rejected (unless enqueued with `enqueueEvenWhileRestricted()`). Defaults * to false. */ enterRestrictedMode(purgeExistingTasks?: boolean): void; /** * Adds a new operation to the queue. Returns a promise that will be resolved * when the promise returned by the new operation is (with its value). */ enqueue<T extends unknown>(op: () => Promise<T>): Promise<T>; /** * Enqueue a retryable operation. * * A retryable operation is rescheduled with backoff if it fails with a * IndexedDbTransactionError (the error type used by SimpleDb). All * retryable operations are executed in order and only run if all prior * operations were retried successfully. */ enqueueRetryable(op: () => Promise<void>): void; /** * Schedules an operation to be queued on the AsyncQueue once the specified * `delayMs` has elapsed. The returned DelayedOperation can be used to cancel * or fast-forward the operation prior to its running. */ enqueueAfterDelay<T extends unknown>(timerId: TimerId, delayMs: number, op: () => Promise<T>): DelayedOperation<T>; /** * Verifies there's an operation currently in-progress on the AsyncQueue. * Unfortunately we can't verify that the running code is in the promise chain * of that operation, so this isn't a foolproof check, but it should be enough * to catch some bugs. */ verifyOperationInProgress(): void; } /** * @internal */ declare type AuthTokenFactory = () => string; /** * @beta * * Creates an aggregation that calculates the average (mean) of values from an expression across * multiple stage inputs. * * @example * ```typescript * // Calculate the average age of users * average(field("age")).as("averageAge"); * ``` * * @param expression - The expression representing the values to average. * @returns A new {@link @firebase/firestore/pipelines#AggregateFunction} representing the 'average' aggregation. */ export declare function average(expression: Expression): AggregateFunction; /** * @beta * * Creates an aggregation that calculates the average (mean) of a field's values across multiple * stage inputs. * * @example * ```typescript * // Calculate the average age of users * average("age").as("averageAge"); * ``` * * @param fieldName - The name of the field containing numeric values to average. * @returns A new {@link @firebase/firestore/pipelines#AggregateFunction} representing the 'average' aggregation. */ export declare function average(fieldName: string): AggregateFunction; /** * Path represents an ordered sequence of string segments. */ declare abstract class BasePath<B extends BasePath<B>> { private segments; private offset; private len; constructor(segments: string[], offset?: number, length?: number); /** * Abstract constructor method to construct an instance of B with the given * parameters. */ protected abstract construct(segments: string[], offset?: number, length?: number): B; /** * Returns a String representation. * * Implementing classes are required to provide deterministic implementations as * the String representation is used to obtain canonical Query IDs. */ abstract toString(): string; get length(): number; isEqual(other: B): boolean; child(nameOrPath: string | B): B; /** The index of one past the last segment of the path. */ private limit; popFirst(size?: number): B; popLast(): B; firstSegment(): string; lastSegment(): string; get(index: number): string; isEmpty(): boolean; isPrefixOf(other: this): boolean; isImmediateParentOf(potentialChild: this): boolean; forEach(fn: (segment: string) => void): void; toArray(): string[]; /** * Compare 2 paths segment by segment, prioritizing numeric IDs * (e.g., "__id123__") in numeric ascending order, followed by string * segments in lexicographical order. */ static comparator<T extends BasePath<T>>(p1: BasePath<T>, p2: BasePath<T>): number; private static compareSegments; private static isNumericId; private static extractNumericId; } /** * @license * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file 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. */ /** * BatchID is a locally assigned ID for a batch of mutations that have been * applied. */ declare type BatchId = number; /** * @beta * * An interface that represents a filter condition. */ export declare abstract class BooleanExpression extends Expression { abstract get _expr(): Expression; get _methodName(): string | undefined; /** * @beta * Creates an aggregation that finds the count of input documents satisfying * this boolean expression. * * @example * ```typescript * // Find the count of documents with a score greater than 90 * field("score").greaterThan(90).countIf().as("highestScore"); * ``` * * @returns A new `AggregateFunction` representing the 'countIf' aggregation. */ countIf(): AggregateFunction; /** * @beta * Creates an expression that negates this boolean expression. * * @example * ```typescript * // Find documents where the 'tags' field does not contain 'completed' * field("tags").arrayContains("completed").not(); * ``` * * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the negated filter condition. */ not(): BooleanExpression; /** * @beta * Creates a conditional expression that evaluates to the 'then' expression * if `this` expression evaluates to `true`, * or evaluates to the 'else' expression if `this` expressions evaluates `false`. * * @example * ```typescript * // If 'age' is greater than 18, return "Adult"; otherwise, return "Minor". * field("age").greaterThanOrEqual(18).conditional(constant("Adult"), constant("Minor")); * ``` * * @param thenExpr - The expression to evaluate if the condition is true. * @param elseExpr - The expression to evaluate if the condition is false. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the conditional expression. */ conditional(thenExpr: Expression, elseExpr: Expression): FunctionExpression; /** * @beta * * Creates an expression that returns the `catch` argument if there is an * error, else return the result of this expression. * * @example * ```typescript * // Create an expression that protects against a divide by zero error * // but always returns a boolean expression. * constant(50).divide('length').gt(1).ifError(constant(false)); * ``` * * @param catchValue - The value that will be returned if this expression * produces an error. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'ifError' operation. */ ifError(catchValue: BooleanExpression): BooleanExpression; /** * @beta * * Creates an expression that returns the `catch` argument if there is an * error, else return the result of this expression. * * @example * ```typescript * // Create an expression that protects against a divide by zero error * // but always returns a boolean expression. * constant(50).divide('length').gt(1).ifError(false); * ``` * * @param catchValue - The value that will be returned if this expression * produces an error. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'ifError' operation. */ ifError(catchValue: boolean): BooleanExpression; /** * @beta * * Creates an expression that returns the `catch` argument if there is an * error, else return the result of this expression. * * @example * ```typescript * // Create an expression that protects against a divide by zero error. * constant(50).divide('length').gt(1).ifError(constant(0)); * ``` * * @param catchValue - The value that will be returned if this expression * produces an error. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'ifError' operation. */ ifError(catchValue: Expression): FunctionExpression; /** * @beta * * Creates an expression that returns the `catch` argument if there is an * error, else return the result of this expression. * * @example * ```typescript * // Create an expression that protects against a divide by zero error. * constant(50).divide('length').gt(1).ifError(0); * ``` * * @param catchValue - The value that will be returned if this expression * produces an error. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the 'ifError' operation. */ ifError(catchValue: unknown): FunctionExpression; /** * @private * @internal */ _toProto(serializer: JsonProtoSerializer): Value; /** * @private * @internal */ _readUserData(context: ParseContext): void; } /** * Represents a bound of a query. * * The bound is specified with the given components representing a position and * whether it's just before or just after the position (relative to whatever the * query order is). * * The position represents a logical index position for a query. It's a prefix * of values for the (potentially implicit) order by clauses of a query. * * Bound provides a function to determine whether a document comes before or * after a bound. This is influenced by whether the position is just before or * just after the provided values. */ declare class Bound { readonly position: Value[]; readonly inclusive: boolean; constructor(position: Value[], inclusive: boolean); } /** * Provides interfaces to save and read Firestore bundles. */ declare interface BundleCache { /** * Gets the saved `BundleMetadata` for a given `bundleId`, returns undefined * if no bundle metadata is found under the given id. */ getBundleMetadata(transaction: PersistenceTransaction, bundleId: string): PersistencePromise<BundleMetadata | undefined>; /** * Saves a `BundleMetadata` from a bundle into local storage, using its id as * the persistent key. */ saveBundleMetadata(transaction: PersistenceTransaction, metadata: BundleMetadata_2): PersistencePromise<void>; /** * Gets a saved `NamedQuery` for the given query name. Returns undefined if * no queries are found under the given name. */ getNamedQuery(transaction: PersistenceTransaction, queryName: string): PersistencePromise<NamedQuery | undefined>; /** * Saves a `NamedQuery` from a bundle, using its name as the persistent key. */ saveNamedQuery(transaction: PersistenceTransaction, query: NamedQuery_2): PersistencePromise<void>; } /** Properties of a BundledQuery. */ declare interface BundledQuery { /** BundledQuery parent */ parent?: string | null; /** BundledQuery structuredQuery */ structuredQuery?: StructuredQuery | null; /** BundledQuery limitType */ limitType?: LimitType_2 | null; } /** * Represents a Firestore bundle saved by the SDK in its local storage. */ declare interface BundleMetadata { /** * Id of the bundle. It is used together with `createTime` to determine if a * bundle has been loaded by the SDK. */ readonly id: string; /** Schema version of the bundle. */ readonly version: number; /** * Set to the snapshot version of the bundle if created by the Server SDKs. * Otherwise set to SnapshotVersion.MIN. */ readonly createTime: SnapshotVersion; } /** Properties of a BundleMetadata. */ declare interface BundleMetadata_2 { /** BundleMetadata id */ id?: string | null; /** BundleMetadata createTime */ createTime?: Timestamp_2 | null; /** BundleMetadata version */ version?: number | null; /** BundleMetadata totalDocuments */ totalDocuments?: number | null; /** BundleMetadata totalBytes */ totalBytes?: number | null; } /** * @beta * * Creates an expression that calculates the byte length of a string in UTF-8, or just the length of a Blob. * * @example * ```typescript * // Calculate the length of the 'myString' field in bytes. * byteLength(field("myString")); * ``` * * @param expr - The expression representing the string. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the length of the string in bytes. */ export declare function byteLength(expr: Expression): FunctionExpression; /** * @beta * * Creates an expression that calculates the length of a string represented by a field in UTF-8 bytes, or just the length of a Blob. * * @example * ```typescript * // Calculate the length of the 'myString' field in bytes. * byteLength("myString"); * ``` * * @param fieldName - The name of the field containing the string. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the length of the string in bytes. */ export declare function byteLength(fieldName: string): FunctionExpression; /** * An immutable object representing an array of bytes. */ export declare class Bytes { _byteString: ByteString; /** @hideconstructor */ constructor(byteString: ByteString); /** * Creates a new `Bytes` object from the given Base64 string, converting it to * bytes. * * @param base64 - The Base64 string used to create the `Bytes` object. */ static fromBase64String(base64: string): Bytes; /** * Creates a new `Bytes` object from the given Uint8Array. * * @param array - The Uint8Array used to create the `Bytes` object. */ static fromUint8Array(array: Uint8Array): Bytes; /** * Returns the underlying bytes as a Base64-encoded string. * * @returns The Base64-encoded string created from the `Bytes` object. */ toBase64(): string; /** * Returns the underlying bytes in a new `Uint8Array`. * * @returns The Uint8Array created from the `Bytes` object. */ toUint8Array(): Uint8Array; /** * Returns a string representation of the `Bytes` object. * * @returns A string representation of the `Bytes` object. */ toString(): string; /** * Returns true if this `Bytes` object is equal to the provided one. * * @param other - The `Bytes` object to compare against. * @returns true if this `Bytes` object is equal to the provided one. */ isEqual(other: Bytes): boolean; static _jsonSchemaVersion: string; static _jsonSchema: { type: Property<"string">; bytes: Property<"string">; }; /** * Returns a JSON-serializable representation of this `Bytes` instance. * * @returns a JSON representation of this object. */ toJSON(): object; /** * Builds a `Bytes` instance from a JSON object created by {@link Bytes.toJSON}. * * @param json - a JSON object represention of a `Bytes` instance * @returns an instance of {@link Bytes} if the JSON object could be parsed. Throws a * {@link FirestoreError} if an error occurs. */ static fromJSON(json: object): Bytes; } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file 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. */ /** * Immutable class that represents a "proto" byte string. * * Proto byte strings can either be Base64-encoded strings or Uint8Arrays when * sent on the wire. This class abstracts away this differentiation by holding * the proto byte string in a common class that must be converted into a string * before being sent as a proto. * @internal */ declare class ByteString { private readonly binaryString; static readonly EMPTY_BYTE_STRING: ByteString; private constructor(); static fromBase64String(base64: string): ByteString; static fromUint8Array(array: Uint8Array): ByteString; [Symbol.iterator](): Iterator<number>; toBase64(): string; toUint8Array(): Uint8Array; approximateByteSize(): number; compareTo(other: ByteString): number; isEqual(other: ByteString): boolean; } /** * @beta * Creates an expression that computes the ceiling of a numeric value. * * @example * ```typescript * // Compute the ceiling of the 'price' field. * ceil("price"); * ``` * * @param fieldName - The name of the field to compute the ceiling of. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the ceiling of the numeric value. */ export declare function ceil(fieldName: string): FunctionExpression; /** * @beta * Creates an expression that computes the ceiling of a numeric value. * * @example * ```typescript * // Compute the ceiling of the 'price' field. * ceil(field("price")); * ``` * * @param expression - An expression evaluating to a numeric value, which the ceiling will be computed for. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the ceiling of the numeric value. */ export declare function ceil(expression: Expression): FunctionExpression; declare const enum ChangeType { Added = 0, Removed = 1, Modified = 2, Metadata = 3 } /** * @beta * * Creates an expression that calculates the character length of a string field in UTF8. * * @example * ```typescript * // Get the character length of the 'name' field in UTF-8. * strLength("name"); * ``` * * @param fieldName - The name of the field containing the string. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the length of the string. */ export declare function charLength(fieldName: string): FunctionExpression; /** * @beta * * Creates an expression that calculates the character length of a string expression in UTF-8. * * @example * ```typescript * // Get the character length of the 'name' field in UTF-8. * strLength(field("name")); * ``` * * @param stringExpression - The expression representing the string to calculate the length of. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the length of the string. */ export declare function charLength(stringExpression: Expression): FunctionExpression; /** * A randomly-generated key assigned to each Firestore instance at startup. */ declare type ClientId = string; /** * @beta * Defines the configuration options for a CollectionGroupStage within a pipeline. * This type extends {@link @firebase/firestore/pipelines#StageOptions} and provides specific settings for how a collection group * is identified and processed during pipeline execution. * * See {@link @firebase/firestore/pipelines#PipelineSource.(collectionGroup:1)} to create a collection group stage. */ export declare type CollectionGroupStageOptions = StageOptions & { /** * @beta * ID of the collection group to use as the Pipeline source. */ collectionId: string; /** * @beta * Specifies the name of an index to be used for a query, overriding the query optimizer's default choice. * This can be useful for performance tuning in specific scenarios where the default index selection * does not yield optimal performance. * * @remarks This property is optional. When provided, it should be the exact name of the index to force. */ forceIndex?: string; }; /** * @beta * Creates an expression that returns the collection ID from a path. * * @example * ```typescript * // Get the collection ID from a path. * collectionId("__name__"); * ``` * * @param fieldName - The name of the field to get the collection ID from. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the collectionId operation. */ export declare function collectionId(fieldName: string): FunctionExpression; /** * @beta * Creates an expression that returns the collection ID from a path. * * @example * ```typescript * // Get the collection ID from a path. * collectionId(field("__name__")); * ``` * * @param expression - An expression evaluating to a path, which the collection ID will be extracted from. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the collectionId operation. */ export declare function collectionId(expression: Expression): FunctionExpression; /** * A `CollectionReference` object can be used for adding documents, getting * document references, and querying for documents (using {@link (query:1)}). */ declare class CollectionReference<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData> extends Query<AppModelType, DbModelType> { readonly _path: ResourcePath; /** The type of this Firestore reference. */ readonly type = "collection"; /** @hideconstructor */ constructor(firestore: Firestore_2, converter: FirestoreDataConverter_2<AppModelType, DbModelType> | null, _path: ResourcePath); /** The collection's identifier. */ get id(): string; /** * A string representing the path of the referenced collection (relative * to the root of the database). */ get path(): string; /** * A reference to the containing `DocumentReference` if this is a * subcollection. If this isn't a subcollection, the reference is null. */ get parent(): DocumentReference<DocumentData, DocumentData> | null; /** * Applies a custom data converter to this `CollectionReference`, allowing you * to use your own custom model objects with Firestore. When you call {@link * addDoc} with the returned `CollectionReference` instance, the provided * converter will convert between Firestore data of type `NewDbModelType` and * your custom type `NewAppModelType`. * * @param converter - Converts objects to and from Firestore. * @returns A `CollectionReference` that uses the provided converter. */ withConverter<NewAppModelType, NewDbModelType extends DocumentData = DocumentData>(converter: FirestoreDataConverter_2<NewAppModelType, NewDbModelType>): CollectionReference<NewAppModelType, NewDbModelType>; /** * Removes the current converter. * * @param converter - `null` removes the current converter. * @returns A `CollectionReference<DocumentData, DocumentData>` that does not * use a converter. */ withConverter(converter: null): CollectionReference<DocumentData, DocumentData>; } /** * @beta * Options defining how a CollectionStage is evaluated. See {@link @firebase/firestore/pipelines#PipelineSource.(collection:1)}. */ export declare type CollectionStageOptions = StageOptions & { /** * @beta * Name or reference to the collection that will be used as the Pipeline source. */ collection: string | CollectionReference; /** * @beta * Specifies the name of an index to be used for a query, overriding the query optimizer's default choice. * This can be useful for performance tuning in specific scenarios where the default index selection * does not yield optimal performance. * * @remarks This property is optional. When provided, it should be the exact name of the index to force. */ forceIndex?: string; }; /** * @license * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file 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. */ declare type Comparator<K> = (key1: K, key2: K) => number; declare interface ComponentConfiguration { asyncQueue: AsyncQueue; databaseInfo: DatabaseInfo; authCredentials: CredentialsProvider<User>; appCheckCredentials: CredentialsProvider<string>; clientId: ClientId; initialUser: User; maxConcurrentLimboResolutions: number; } declare type CompositeFilterOp = 'OPERATOR_UNSPECIFIED' | 'AND' | 'OR'; /** * @beta * Creates an expression that concatenates strings, arrays, or blobs. Types cannot be mixed. * * @example * ```typescript * // Concatenate the 'firstName' and 'lastName' fields with a space in between. * concat(field("firstName"), " ", fie