UNPKG

@firebase/firestore

Version:

The Cloud Firestore component of the Firebase JS SDK.

1,377 lines (1,376 loc) • 297 kB
/** * @license * Copyright 2024 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. */ import { ParseContext } from '../api/parse_context'; import { FieldPath as InternalFieldPath } from '../model/path'; import { Value as ProtoValue } from '../protos/firestore_proto_api'; import { JsonProtoSerializer, ProtoValueSerializable } from '../remote/serializer'; import { Bytes } from './bytes'; import { FieldPath } from './field_path'; import { GeoPoint } from './geo_point'; import { DocumentReference } from './reference'; import { Timestamp } from './timestamp'; import { UserData } from './user_data_reader'; import { VectorValue } from './vector_value'; /** * @beta * * An enumeration of the different types of expressions. */ export type ExpressionType = 'Field' | 'Constant' | 'Function' | 'AggregateFunction' | 'ListOfExpressions' | 'AliasedExpression'; /** * @beta * * An enumeration of the different types generated by the Firestore backend. * * <ul> * <li>Numerics evaluate directly to backend representation (`int64` or `float64`), not JS `number`.</li> * <li>JavaScript `Date` and firestore `Timestamp` objects strictly evaluate to `'timestamp'`.</li> * <li>Advanced configurations parsing backend types (such as `decimal128`, `max_key` or `min_key` from BSON) are also incorporated in this union string type. Note that `decimal128` is a backend-only numeric type that the JavaScript SDK cannot create natively, but can be evaluated in pipelines.</li> * </ul> */ export type Type = 'null' | 'array' | 'boolean' | 'bytes' | 'timestamp' | 'geo_point' | 'number' | 'int32' | 'int64' | 'float64' | 'decimal128' | 'map' | 'reference' | 'string' | 'vector' | 'max_key' | 'min_key' | 'object_id' | 'regex' | 'request_timestamp'; /** * @beta * * Represents an expression that can be evaluated to a value within the execution of a {@link * @firebase/firestore/pipelines#Pipeline}. * * Expressions are the building blocks for creating complex queries and transformations in * Firestore pipelines. They can represent: * * - **Field references:** Access values from document fields. * - **Literals:** Represent constant values (strings, numbers, booleans). * - **Function calls:** Apply functions to one or more expressions. * * The `Expression` class provides a fluent API for building expressions. You can chain together * method calls to create complex expressions. */ export declare abstract class Expression implements ProtoValueSerializable, UserData { abstract readonly expressionType: ExpressionType; abstract readonly _methodName?: string; /** * @private * @internal */ abstract _toProto(serializer: JsonProtoSerializer): ProtoValue; _protoValueType: "ProtoValue"; /** * @private * @internal */ abstract _readUserData(context: ParseContext): void; /** * Creates an expression that adds this expression to another expression. * * @example * ```typescript * // Add the value of the 'quantity' field and the 'reserve' field. * field("quantity").add(field("reserve")); * ``` * * @param second - The expression or literal to add to this expression. * @param others - Optional additional expressions or literals to add to this expression. * @returns A new `Expression` representing the addition operation. */ add(second: Expression | unknown): FunctionExpression; /** * @beta * Wraps the expression in a [BooleanExpression]. * * @returns A [BooleanExpression] representing the same expression. */ asBoolean(): BooleanExpression; /** * @beta * Creates an expression that subtracts another expression from this expression. * * @example * ```typescript * // Subtract the 'discount' field from the 'price' field * field("price").subtract(field("discount")); * ``` * * @param subtrahend - The expression to subtract from this expression. * @returns A new `Expression` representing the subtraction operation. */ subtract(subtrahend: Expression): FunctionExpression; /** * @beta * Creates an expression that subtracts a constant value from this expression. * * @example * ```typescript * // Subtract 20 from the value of the 'total' field * field("total").subtract(20); * ``` * * @param subtrahend - The constant value to subtract. * @returns A new `Expression` representing the subtraction operation. */ subtract(subtrahend: number): FunctionExpression; /** * @beta * Creates an expression that multiplies this expression by another expression. * * @example * ```typescript * // Multiply the 'quantity' field by the 'price' field * field("quantity").multiply(field("price")); * ``` * * @param second - The second expression or literal to multiply by. * @param others - Optional additional expressions or literals to multiply by. * @returns A new `Expression` representing the multiplication operation. */ multiply(second: Expression | number): FunctionExpression; /** * @beta * Creates an expression that divides this expression by another expression. * * @example * ```typescript * // Divide the 'total' field by the 'count' field * field("total").divide(field("count")); * ``` * * @param divisor - The expression to divide by. * @returns A new `Expression` representing the division operation. */ divide(divisor: Expression): FunctionExpression; /** * @beta * Creates an expression that divides this expression by a constant value. * * @example * ```typescript * // Divide the 'value' field by 10 * field("value").divide(10); * ``` * * @param divisor - The constant value to divide by. * @returns A new `Expression` representing the division operation. */ divide(divisor: number): FunctionExpression; /** * @beta * Creates an expression that calculates the modulo (remainder) of dividing this expression by another expression. * * @example * ```typescript * // Calculate the remainder of dividing the 'value' field by the 'divisor' field * field("value").mod(field("divisor")); * ``` * * @param expression - The expression to divide by. * @returns A new `Expression` representing the modulo operation. */ mod(expression: Expression): FunctionExpression; /** * @beta * Creates an expression that calculates the modulo (remainder) of dividing this expression by a constant value. * * @example * ```typescript * // Calculate the remainder of dividing the 'value' field by 10 * field("value").mod(10); * ``` * * @param value - The constant value to divide by. * @returns A new `Expression` representing the modulo operation. */ mod(value: number): FunctionExpression; /** * @beta * Creates an expression that checks if this expression is equal to another expression. * * @example * ```typescript * // Check if the 'age' field is equal to 21 * field("age").equal(21); * ``` * * @param expression - The expression to compare for equality. * @returns A new `Expression` representing the equality comparison. */ equal(expression: Expression): BooleanExpression; /** * @beta * Creates an expression that checks if this expression is equal to a constant value. * * @example * ```typescript * // Check if the 'city' field is equal to "London" * field("city").equal("London"); * ``` * * @param value - The constant value to compare for equality. * @returns A new `Expression` representing the equality comparison. */ equal(value: unknown): BooleanExpression; /** * @beta * Creates an expression that checks if this expression is not equal to another expression. * * @example * ```typescript * // Check if the 'status' field is not equal to "completed" * field("status").notEqual("completed"); * ``` * * @param expression - The expression to compare for inequality. * @returns A new `Expression` representing the inequality comparison. */ notEqual(expression: Expression): BooleanExpression; /** * @beta * Creates an expression that checks if this expression is not equal to a constant value. * * @example * ```typescript * // Check if the 'country' field is not equal to "USA" * field("country").notEqual("USA"); * ``` * * @param value - The constant value to compare for inequality. * @returns A new `Expression` representing the inequality comparison. */ notEqual(value: unknown): BooleanExpression; /** * @beta * Creates an expression that checks if this expression is less than another expression. * * @example * ```typescript * // Check if the 'age' field is less than 'limit' * field("age").lessThan(field('limit')); * ``` * * @param experession - The expression to compare for less than. * @returns A new `Expression` representing the less than comparison. */ lessThan(experession: Expression): BooleanExpression; /** * @beta * Creates an expression that checks if this expression is less than a constant value. * * @example * ```typescript * // Check if the 'price' field is less than 50 * field("price").lessThan(50); * ``` * * @param value - The constant value to compare for less than. * @returns A new `Expression` representing the less than comparison. */ lessThan(value: unknown): BooleanExpression; /** * @beta * Creates an expression that checks if this expression is less than or equal to another * expression. * * @example * ```typescript * // Check if the 'quantity' field is less than or equal to 20 * field("quantity").lessThan(constant(20)); * ``` * * @param expression - The expression to compare for less than or equal to. * @returns A new `Expression` representing the less than or equal to comparison. */ lessThanOrEqual(expression: Expression): BooleanExpression; /** * @beta * Creates an expression that checks if this expression is less than or equal to a constant value. * * @example * ```typescript * // Check if the 'score' field is less than or equal to 70 * field("score").lessThan(70); * ``` * * @param value - The constant value to compare for less than or equal to. * @returns A new `Expression` representing the less than or equal to comparison. */ lessThanOrEqual(value: unknown): BooleanExpression; /** * @beta * Creates an expression that checks if this expression is greater than another expression. * * @example * ```typescript * // Check if the 'age' field is greater than the 'limit' field * field("age").greaterThan(field("limit")); * ``` * * @param expression - The expression to compare for greater than. * @returns A new `Expression` representing the greater than comparison. */ greaterThan(expression: Expression): BooleanExpression; /** * @beta * Creates an expression that checks if this expression is greater than a constant value. * * @example * ```typescript * // Check if the 'price' field is greater than 100 * field("price").greaterThan(100); * ``` * * @param value - The constant value to compare for greater than. * @returns A new `Expression` representing the greater than comparison. */ greaterThan(value: unknown): BooleanExpression; /** * @beta * Creates an expression that checks if this expression is greater than or equal to another * expression. * * @example * ```typescript * // Check if the 'quantity' field is greater than or equal to field 'requirement' plus 1 * field("quantity").greaterThanOrEqual(field('requirement').add(1)); * ``` * * @param expression - The expression to compare for greater than or equal to. * @returns A new `Expression` representing the greater than or equal to comparison. */ greaterThanOrEqual(expression: Expression): BooleanExpression; /** * @beta * Creates an expression that checks if this expression is greater than or equal to a constant * value. * * @example * ```typescript * // Check if the 'score' field is greater than or equal to 80 * field("score").greaterThanOrEqual(80); * ``` * * @param value - The constant value to compare for greater than or equal to. * @returns A new `Expression` representing the greater than or equal to comparison. */ greaterThanOrEqual(value: unknown): BooleanExpression; /** * @beta * Creates an expression that concatenates an array expression with one or more other arrays. * * @example * ```typescript * // Combine the 'items' array with another array field. * field("items").arrayConcat(field("otherItems")); * ``` * @param secondArray - Second array expression or array literal to concatenate. * @param otherArrays - Optional additional array expressions or array literals to concatenate. * @returns A new `Expression` representing the concatenated array. */ arrayConcat(secondArray: Expression | unknown[], ...otherArrays: Array<Expression | unknown[]>): FunctionExpression; /** * @beta * Creates an expression that checks if an array contains a specific element. * * @example * ```typescript * // Check if the 'sizes' array contains the value from the 'selectedSize' field * field("sizes").arrayContains(field("selectedSize")); * ``` * * @param expression - The element to search for in the array. * @returns A new `Expression` representing the 'array_contains' comparison. */ arrayContains(expression: Expression): BooleanExpression; /** * @beta * Creates an expression that checks if an array contains a specific value. * * @example * ```typescript * // Check if the 'colors' array contains "red" * field("colors").arrayContains("red"); * ``` * * @param value - The element to search for in the array. * @returns A new `Expression` representing the 'array_contains' comparison. */ arrayContains(value: unknown): BooleanExpression; /** * @beta * Creates an expression that checks if an array contains all the specified elements. * * @example * ```typescript * // Check if the 'tags' array contains both the value in field "tag1" and the literal value "tag2" * field("tags").arrayContainsAll([field("tag1"), "tag2"]); * ``` * * @param values - The elements to check for in the array. * @returns A new `Expression` representing the 'array_contains_all' comparison. */ arrayContainsAll(values: Array<Expression | unknown>): BooleanExpression; /** * @beta * Creates an expression that checks if an array contains all the specified elements. * * @example * ```typescript * // Check if the 'tags' array contains both of the values from field "tag1" and the literal value "tag2" * field("tags").arrayContainsAll(array([field("tag1"), "tag2"])); * ``` * * @param arrayExpression - The elements to check for in the array. * @returns A new `Expression` representing the 'array_contains_all' comparison. */ arrayContainsAll(arrayExpression: Expression): BooleanExpression; /** * @beta * Creates an expression that checks if an array contains any of the specified elements. * * @example * ```typescript * // Check if the 'categories' array contains either values from field "cate1" or "cate2" * field("categories").arrayContainsAny([field("cate1"), field("cate2")]); * ``` * * @param values - The elements to check for in the array. * @returns A new `Expression` representing the 'array_contains_any' comparison. */ arrayContainsAny(values: Array<Expression | unknown>): BooleanExpression; /** * @beta * Creates an expression that checks if an array 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" * field("groups").arrayContainsAny(array([field("userGroup"), "guest"])); * ``` * * @param arrayExpression - The elements to check for in the array. * @returns A new `Expression` representing the 'array_contains_any' comparison. */ arrayContainsAny(arrayExpression: Expression): BooleanExpression; /** * @beta * Creates an expression that reverses an array. * * @example * ```typescript * // Reverse the value of the 'myArray' field. * field("myArray").arrayReverse(); * ``` * * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the reversed array. */ arrayReverse(): FunctionExpression; /** * @beta * Creates an expression that calculates the length of an array. * * @example * ```typescript * // Get the number of items in the 'cart' array * field("cart").arrayLength(); * ``` * * @returns A new `Expression` representing the length of the array. */ arrayLength(): FunctionExpression; /** * @beta * Creates an expression that checks if this expression is equal to any of the provided values or * expressions. * * @example * ```typescript * // Check if the 'category' field is either "Electronics" or value of field 'primaryType' * field("category").equalAny(["Electronics", field("primaryType")]); * ``` * * @param values - The values or expressions to check against. * @returns A new `Expression` representing the 'IN' comparison. */ equalAny(values: Array<Expression | unknown>): BooleanExpression; /** * @beta * Creates an expression that checks if this expression is equal to any of the provided values or * expressions. * * @example * ```typescript * // Check if the 'category' field is either "Electronics" or value of field 'primaryType' * field("category").equalAny(array(["Electronics", field("primaryType")])); * ``` * * @param arrayExpression - An expression that evaluates to an array of values to check against. * @returns A new `Expression` representing the 'IN' comparison. */ equalAny(arrayExpression: Expression): BooleanExpression; /** * @beta * Creates an expression that checks if this expression is not equal to any of the provided values or * expressions. * * @example * ```typescript * // Check if the 'status' field is neither "pending" nor the value of 'rejectedStatus' * field("status").notEqualAny(["pending", field("rejectedStatus")]); * ``` * * @param values - The values or expressions to check against. * @returns A new `Expression` representing the 'notEqualAny' comparison. */ notEqualAny(values: Array<Expression | unknown>): BooleanExpression; /** * @beta * Creates an expression that checks if this expression is not equal to any of the values in the evaluated expression. * * @example * ```typescript * // Check if the 'status' field is not equal to any value in the field 'rejectedStatuses' * field("status").notEqualAny(field('rejectedStatuses')); * ``` * * @param arrayExpression - The values or expressions to check against. * @returns A new `Expression` representing the 'notEqualAny' comparison. */ notEqualAny(arrayExpression: Expression): BooleanExpression; /** * @beta * Creates an expression that checks if a field exists in the document. * * @example * ```typescript * // Check if the document has a field named "phoneNumber" * field("phoneNumber").exists(); * ``` * * @returns A new `Expression` representing the 'exists' check. */ exists(): BooleanExpression; /** * @beta * Creates an expression that calculates the character length of a string in UTF-8. * * @example * ```typescript * // Get the character length of the 'name' field in its UTF-8 form. * field("name").charLength(); * ``` * * @returns A new `Expression` representing the length of the string. */ charLength(): FunctionExpression; /** * @beta * Creates an expression that performs a case-sensitive string comparison. * * @example * ```typescript * // Check if the 'title' field contains the word "guide" (case-sensitive) * field("title").like("%guide%"); * ``` * * @param pattern - The pattern to search for. You can use "%" as a wildcard character. * @returns A new `Expression` representing the 'like' comparison. */ like(pattern: string): BooleanExpression; /** * @beta * Creates an expression that performs a case-sensitive string comparison. * * @example * ```typescript * // Check if the 'title' field contains the word "guide" (case-sensitive) * field("title").like("%guide%"); * ``` * * @param pattern - The pattern to search for. You can use "%" as a wildcard character. * @returns A new `Expression` representing the 'like' comparison. */ like(pattern: Expression): BooleanExpression; /** * @beta * Creates an expression that checks if a string contains a specified regular expression as a * substring. * * @example * ```typescript * // Check if the 'description' field contains "example" (case-insensitive) * field("description").regexContains("(?i)example"); * ``` * * @param pattern - The regular expression to use for the search. * @returns A new `Expression` representing the 'contains' comparison. */ regexContains(pattern: string): BooleanExpression; /** * @beta * Creates an expression that checks if a string contains a specified regular expression as a * substring. * * @example * ```typescript * // Check if the 'description' field contains the regular expression stored in field 'regex' * field("description").regexContains(field("regex")); * ``` * * @param pattern - The regular expression to use for the search. * @returns A new `Expression` representing the 'contains' comparison. */ regexContains(pattern: Expression): BooleanExpression; /** * @beta * Creates an expression that returns the first substring of a string expression that matches * a specified regular expression. * * This expression uses the {@link https://github.com/google/re2/wiki/Syntax | RE2} regular expression syntax. * * @example * ```typescript * // Extract the domain from an email address * field("email").regexFind("@.+") * ``` * * @param pattern - The regular expression to search for. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the regular expression find function. */ regexFind(pattern: string): FunctionExpression; /** * @beta * Creates an expression that returns the first substring of a string expression that matches * a specified regular expression. * * This expression uses the {@link https://github.com/google/re2/wiki/Syntax | RE2} regular expression syntax. * * @example * ```typescript * // Extract the domain from an email address * field("email").regexFind(field("domain")) * ``` * * @param pattern - The regular expression to search for. * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the regular expression find function. */ regexFind(pattern: Expression): FunctionExpression; /** * @beta * * Creates an expression that evaluates to a list of all substrings in this string expression that * match a specified regular expression. * * This expression uses the {@link https://github.com/google/re2/wiki/Syntax | RE2} regular expression syntax. * * @example * ```typescript * // Extract all hashtags from a post content field * field("content").regexFindAll("#[A-Za-z0-9_]+") * ``` * * @param pattern - The regular expression to search for. * @returns A new {@link @firebase/firestore/pipelines#Expression} that evaluates to an array of matched substrings. */ regexFindAll(pattern: string): FunctionExpression; /** * @beta * * Creates an expression that evaluates to a list of all substrings in this string expression that * match a specified regular expression. * * This expression uses the {@link https://github.com/google/re2/wiki/Syntax | RE2} regular expression syntax. * * @example * ```typescript * // Extract all names from a post content field * field("content").regexFindAll(field("names")) * ``` * * @param pattern - The regular expression to search for. * @returns A new {@link @firebase/firestore/pipelines#Expression} that evaluates to an array of matched substrings. */ regexFindAll(pattern: Expression): FunctionExpression; /** * @beta * Creates an expression that checks if a string matches a specified regular expression. * * @example * ```typescript * // Check if the 'email' field matches a valid email pattern * field("email").regexMatch("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"); * ``` * * @param pattern - The regular expression to use for the match. * @returns A new `Expression` representing the regular expression match. */ regexMatch(pattern: string): BooleanExpression; /** * @beta * Creates an expression that checks if a string matches a specified regular expression. * * @example * ```typescript * // Check if the 'email' field matches a regular expression stored in field 'regex' * field("email").regexMatch(field("regex")); * ``` * * @param pattern - The regular expression to use for the match. * @returns A new `Expression` representing the regular expression match. */ regexMatch(pattern: Expression): BooleanExpression; /** * @beta * Creates an expression that checks if a string contains a specified substring. * * @example * ```typescript * // Check if the 'description' field contains "example". * field("description").stringContains("example"); * ``` * * @param substring - The substring to search for. * @returns A new `Expression` representing the 'contains' comparison. */ stringContains(substring: string): BooleanExpression; /** * @beta * Creates an expression that checks if a string contains the string represented by another expression. * * @example * ```typescript * // Check if the 'description' field contains the value of the 'keyword' field. * field("description").stringContains(field("keyword")); * ``` * * @param expr - The expression representing the substring to search for. * @returns A new `Expression` representing the 'contains' comparison. */ stringContains(expr: Expression): BooleanExpression; /** * @beta * Creates an expression that checks if a string starts with a given prefix. * * @example * ```typescript * // Check if the 'name' field starts with "Mr." * field("name").startsWith("Mr."); * ``` * * @param prefix - The prefix to check for. * @returns A new `Expression` representing the 'starts with' comparison. */ startsWith(prefix: string): BooleanExpression; /** * @beta * Creates an expression that checks if a string starts with a given prefix (represented as an * expression). * * @example * ```typescript * // Check if the 'fullName' field starts with the value of the 'firstName' field * field("fullName").startsWith(field("firstName")); * ``` * * @param prefix - The prefix expression to check for. * @returns A new `Expression` representing the 'starts with' comparison. */ startsWith(prefix: Expression): BooleanExpression; /** * @beta * Creates an expression that checks if a string ends with a given postfix. * * @example * ```typescript * // Check if the 'filename' field ends with ".txt" * field("filename").endsWith(".txt"); * ``` * * @param suffix - The postfix to check for. * @returns A new `Expression` representing the 'ends with' comparison. */ endsWith(suffix: string): BooleanExpression; /** * @beta * Creates an expression that checks if a string ends with a given postfix (represented as an * expression). * * @example * ```typescript * // Check if the 'url' field ends with the value of the 'extension' field * field("url").endsWith(field("extension")); * ``` * * @param suffix - The postfix expression to check for. * @returns A new `Expression` representing the 'ends with' comparison. */ endsWith(suffix: Expression): BooleanExpression; /** * @beta * Creates an expression that converts a string to lowercase. * * @example * ```typescript * // Convert the 'name' field to lowercase * field("name").toLower(); * ``` * * @returns A new `Expression` representing the lowercase string. */ toLower(): FunctionExpression; /** * @beta * Creates an expression that converts a string to uppercase. * * @example * ```typescript * // Convert the 'title' field to uppercase * field("title").toUpper(); * ``` * * @returns A new `Expression` representing the uppercase string. */ toUpper(): FunctionExpression; /** * @beta * Creates an expression that removes leading and trailing characters from a string or byte array. * * @example * ```typescript * // Trim whitespace from the 'userInput' field * field("userInput").trim(); * * // Trim quotes from the 'userInput' field * field("userInput").trim('"'); * ``` * @param valueToTrim - Optional This parameter is treated as a set of characters or bytes that will be * trimmed from the input. If not specified, then whitespace will be trimmed. * @returns A new `Expression` representing the trimmed string or byte array. */ trim(valueToTrim?: string | Expression | Bytes): FunctionExpression; /** * @beta * Trims whitespace or a specified set of characters/bytes from the beginning of a string or byte array. * * @example * ```typescript * // Trim whitespace from the beginning of the 'userInput' field * field("userInput").ltrim(); * * // Trim quotes from the beginning of the 'userInput' field * field("userInput").ltrim('"'); * ``` * * @param valueToTrim - Optional. A string or byte array containing the characters/bytes to trim. * If not specified, whitespace will be trimmed. * @returns A new `Expression` representing the trimmed string. */ ltrim(valueToTrim?: string | Expression | Bytes): FunctionExpression; /** * @beta * Trims whitespace or a specified set of characters/bytes from the end of a string or byte array. * * @example * ```typescript * // Trim whitespace from the end of the 'userInput' field * field("userInput").rtrim(); * * // Trim quotes from the end of the 'userInput' field * field("userInput").rtrim('"'); * ``` * * @param valueToTrim - Optional. A string or byte array containing the characters/bytes to trim. * If not specified, whitespace will be trimmed. * @returns A new `Expression` representing the trimmed string or byte array. */ rtrim(valueToTrim?: string | Expression | Bytes): FunctionExpression; /** * @beta * Creates an expression that returns the data type of this expression's result, as a string. * * @remarks * This is evaluated on the backend. This means: * 1. Generic typed elements (like `array<string>`) evaluate strictly to the primitive `'array'`. * 2. Any custom `FirestoreDataConverter` mappings are ignored. * 3. For numeric values, the backend does not yield the JavaScript `"number"` type; it evaluates * precisely as `"int64"` or `"float64"`. * 4. For date or timestamp objects, the backend evaluates to `"timestamp"`. * * @example * ```typescript * // Get the data type of the value in field 'title' * field('title').type() * ``` * * @returns A new `Expression` representing the data type. */ type(): FunctionExpression; /** * @beta * Creates an expression that checks if the result of this expression is of the given type. * * @remarks Null or undefined fields evaluate to skip/error. Use `ifAbsent()` / `isAbsent()` to evaluate missing data. * * @example * ```typescript * // Check if the 'price' field is specifically an integer (not just 'number') * field('price').isType('int64'); * ``` * * @param type - The type to check for. * @returns A new `BooleanExpression` that evaluates to true if the expression's result is of the given type, false otherwise. */ isType(type: Type): BooleanExpression; /** * @beta * Creates an expression that concatenates string expressions together. * * @example * ```typescript * // Combine the 'firstName', " ", and 'lastName' fields into a single string * field("firstName").stringConcat(constant(" "), field("lastName")); * ``` * * @param secondString - The additional expression or string literal to concatenate. * @param otherStrings - Optional additional expressions or string literals to concatenate. * @returns A new `Expression` representing the concatenated string. */ stringConcat(secondString: Expression | string, ...otherStrings: Array<Expression | string>): FunctionExpression; /** * @beta * Creates an expression that finds the index of the first occurrence of a substring or byte sequence. * * @example * ```typescript * // Find the index of "foo" in the 'text' field * field("text").stringIndexOf("foo"); * ``` * * @param search - The substring or byte sequence to search for. * @returns A new `Expression` representing the index of the first occurrence. */ stringIndexOf(search: string | Expression | Bytes): FunctionExpression; /** * @beta * Creates an expression that repeats a string or byte array a specified number of times. * * @example * ```typescript * // Repeat the 'label' field 3 times * field("label").stringRepeat(3); * ``` * * @param repetitions - The number of times to repeat the string or byte array. * @returns A new `Expression` representing the repeated string or byte array. */ stringRepeat(repetitions: number | Expression): FunctionExpression; /** * @beta * Creates an expression that replaces all occurrences of a substring or byte sequence with a replacement. * * @example * ```typescript * // Replace all occurrences of "foo" with "bar" in the 'text' field * field("text").stringReplaceAll("foo", "bar"); * ``` * * @param find - The substring or byte sequence to search for. * @param replacement - The replacement string or byte sequence. * @returns A new `Expression` representing the string or byte array with replacements. */ stringReplaceAll(find: string | Expression | Bytes, replacement: string | Expression | Bytes): FunctionExpression; /** * @beta * Creates an expression that replaces the first occurrence of a substring or byte sequence with a replacement. * * @example * ```typescript * // Replace the first occurrence of "foo" with "bar" in the 'text' field * field("text").stringReplaceOne("foo", "bar"); * ``` * * @param find - The substring or byte sequence to search for. * @param replacement - The replacement string or byte sequence. * @returns A new `Expression` representing the string or byte array with the replacement. */ stringReplaceOne(find: string | Expression | Bytes, replacement: string | Expression | Bytes): FunctionExpression; /** * @beta * Creates an expression that concatenates expression results together. * * @example * ```typescript * // Combine the 'firstName', ' ', and 'lastName' fields into a single value. * field("firstName").concat(constant(" "), field("lastName")); * ``` * * @param second - The additional expression or literal to concatenate. * @param others - Optional additional expressions or literals to concatenate. * @returns A new `Expression` representing the concatenated value. */ concat(second: Expression | unknown, ...others: Array<Expression | unknown>): FunctionExpression; /** * @beta * Creates an expression that reverses this string expression. * * @example * ```typescript * // Reverse the value of the 'myString' field. * field("myString").reverse(); * ``` * * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the reversed string. */ reverse(): FunctionExpression; /** * @beta * Returns the first element of the array. * * @example * ```typescript * // Get the first element of the 'myArray' field. * field("myArray").arrayFirst(); * ``` * * @returns A new `Expression` representing the first element. */ arrayFirst(): FunctionExpression; /** * @beta * Returns the first `n` elements of the array. * * @example * ```typescript * // Get the first 3 elements of the 'myArray' field. * field("myArray").arrayFirstN(3); * ``` * * @param n - The number of elements to return. * @returns A new `Expression` representing the first `n` elements. */ arrayFirstN(n: number): FunctionExpression; /** * @beta * Returns the first `n` elements of the array. * * @example * ```typescript * // Get the first n elements of the 'myArray' field. * field("myArray").arrayFirstN(field("count")); * ``` * * @param n - An expression evaluating to the number of elements to return. * @returns A new `Expression` representing the first `n` elements. */ arrayFirstN(n: Expression): FunctionExpression; /** * @beta * Returns the last element of the array. * * @example * ```typescript * // Get the last element of the 'myArray' field. * field("myArray").arrayLast(); * ``` * * @returns A new `Expression` representing the last element. */ arrayLast(): FunctionExpression; /** * @beta * Returns the last `n` elements of the array. * * @example * ```typescript * // Get the last 3 elements of the 'myArray' field. * field("myArray").arrayLastN(3); * ``` * * @param n - The number of elements to return. * @returns A new `Expression` representing the last `n` elements. */ arrayLastN(n: number): FunctionExpression; /** * @beta * Returns the last `n` elements of the array. * * @example * ```typescript * // Get the last n elements of the 'myArray' field. * field("myArray").arrayLastN(field("count")); * ``` * * @param n - An expression evaluating to the number of elements to return. * @returns A new `Expression` representing the last `n` elements. */ arrayLastN(n: Expression): FunctionExpression; /** * @beta * Returns the maximum value in the array. * * @example * ```typescript * // Get the maximum value of the 'myArray' field. * field("myArray").arrayMaximum(); * ``` * * @returns A new `Expression` representing the maximum value. */ arrayMaximum(): FunctionExpression; /** * @beta * Returns the largest `n` elements of the array. * * Note: Returns the n largest non-null elements in the array, in descending * order. This does not use a stable sort, meaning the order of equivalent * elements is undefined. * * @example * ```typescript * // Get the largest 3 elements of the 'myArray' field. * field("myArray").arrayMaximumN(3); * ``` * * @param n - The number of elements to return. * @returns A new `Expression` representing the largest `n` elements. */ arrayMaximumN(n: number): FunctionExpression; /** * @beta * Returns the largest `n` elements of the array. * * Note: Returns the n largest non-null elements in the array, in descending * order. This does not use a stable sort, meaning the order of equivalent * elements is undefined. * * @example * ```typescript * // Get the largest n elements of the 'myArray' field. * field("myArray").arrayMaximumN(field("count")); * ``` * * @param n - An expression evaluating to the number of elements to return. * @returns A new `Expression` representing the largest `n` elements. */ arrayMaximumN(n: Expression): FunctionExpression; /** * @beta * Returns the minimum value in the array. * * @example * ```typescript * // Get the minimum value of the 'myArray' field. * field("myArray").arrayMinimum(); * ``` * * @returns A new `Expression` representing the minimum value. */ arrayMinimum(): FunctionExpression; /** * @beta * Returns the smallest `n` elements of the array. * * Note: Returns the n smallest non-null elements in the array, in ascending * order. This does not use a stable sort, meaning the order of equivalent * elements is undefined. * * @example * ```typescript * // Get the smallest 3 elements of the 'myArray' field. * field("myArray").arrayMinimumN(3); * ``` * * @param n - The number of elements to return. * @returns A new `Expression` representing the smallest `n` elements. */ arrayMinimumN(n: number): FunctionExpression; /** * @beta * Returns the smallest `n` elements of the array. * * Note: Returns the n smallest non-null elements in the array, in ascending * order. This does not use a stable sort, meaning the order of equivalent * elements is undefined. * * @example * ```typescript * // Get the smallest n elements of the 'myArray' field. * field("myArray").arrayMinimumN(field("count")); * ``` * * @param n - An expression evaluating to the number of elements to return. * @returns A new `Expression` representing the smallest `n` elements. */ arrayMinimumN(n: Expression): FunctionExpression; /** * @beta * Returns the first index of the search value in the array, or -1 if not found. * * @example * ```typescript * // Get the first index of the value 3 in the 'myArray' field. * field("myArray").arrayIndexOf(3); * ``` * * @param search - The value to search for. * @returns A new `Expression` representing the index. */ arrayIndexOf(search: unknown): FunctionExpression; /** * @beta * Returns the first index of the search value in the array, or -1 if not found. * * @example * ```typescript * // Get the first index of the value in 'searchVal' field in the 'myArray' field. * field("myArray").arrayIndexOf(field("searchVal")); * ``` * * @param search - An expression evaluating to the value to search for. * @returns A new `Expression` representing the index. */ arrayIndexOf(search: Expression): FunctionExpression; /** * @beta * Returns the last index of the search value in the array, or -1 if not found. * * @example * ```typescript * // Get the last index of the value 3 in the 'myArray' field. * field("myArray").arrayLastIndexOf(3); * ``` * * @param search - The value to search for. * @returns A new `Expression` representing the index. */ arrayLastIndexOf(search: unknown): FunctionExpression; /** * @beta * Returns the last index of the search value in the array, or -1 if not found. * * @example * ```typescript * // Get the last index of the value in 'searchVal' field in the 'myArray' field. * field("myArray").arrayLastIndexOf(field("searchVal")); * ``` * * @param search - An expression evaluating to the value to search for. * @returns A new `Expression` representing the index. */ arrayLastIndexOf(search: Expression): FunctionExpression; /** * @beta * Returns all indices of the search value in the array. * * @example * ```typescript * // Get all indices of the value 3 in the 'myArray' field. * field("myArray").arrayIndexOfAll(3); * ``` * * @param search - The value to search for. * @returns A new `Expression` representing the indices. */ arrayIndexOfAll(search: unknown): FunctionExpression; /** * @beta * Returns all indices of the search value in the array. * * @example * ```typescript * // Get all indices of the value in 'searchVal' field in the 'myArray' field. * field("myArray").arrayIndexOfAll(field("searchVal")); * ``` * * @param search - An expression evaluating to the value to search for. * @returns A new `Expression` representing the indices. */ arrayIndexOfAll(search: Expression): FunctionExpression; /** * @beta * Creates an expression that calculates the length of this string expression in bytes. * * @example * ```typescript * // Calculate the length of the 'myString' field in bytes. * field("myString").byteLength(); * ``` * * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the length of the string in bytes. */ byteLength(): FunctionExpression; /** * @beta * Creates an expression that computes the ceiling of a numeric value. * * @example * ```typescript * // Compute the ceiling of the 'price' field. * field("price").ceil(); * ``` * * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the ceiling of the numeric value. */ ceil(): FunctionExpression; /** * @beta * Creates an expression that computes the floor of a numeric value. * * @example * ```typescript * // Compute the floor of the 'price' field. * field("price").floor(); * ``` * * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the floor of the numeric value. */ floor(): FunctionExpression; /** * @beta * Creates an expression that computes the absolute value of a numeric value. * * @example * ```typescript * // Compute the absolute value of the 'price' field. * field("price").abs(); * ``` * * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the absolute value of the numeric value. */ abs(): FunctionExpression; /** * @beta * Creates an expression that computes e to the power of this expression. * * @example * ```typescript * // Compute e to the power of the 'value' field. * field("value").exp(); * ``` * * @returns A new {@link @firebase/firestore/pipelines#Expression} representing the exp of the numeric value. */ exp(): FunctionExpression; /** * @beta * Accesses a value from a map (object) field using the provided key. * * @example * ```typescript * // Get the 'city' value from the 'address' map field * field("address").mapGet("city"); * ``` * * @param subfield - The key to access in the map. * @returns A new `Expression` representing the value associated with the given key in the map.