@firebase/firestore
Version:
The Cloud Firestore component of the Firebase JS SDK.
1,249 lines (1,236 loc) • 136 kB
JavaScript
import { O as _, av as n, aw as s, ax as k, g, s as x, ay as E, az as T, af as A, j as w, aA as I, aB as V, aq as R, am as $, aC as F, aD as U, aE as M, M as L, aF as q, aG as N, w as rt, aH as B, aI as H, aJ as G, aK as W, aL as K, I as J, C as j, J as Q, aM as X, f as d, e as f, k as P, i as p, aN as Y, F as h } from "./common.browser.js";
import "@firebase/util";
import "@firebase/logger";
import "@firebase/webchannel-wrapper/bloom-blob";
import "@firebase/app";
/**
* @license
* Copyright 2025 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.
*/ class OptionsUtil {
constructor(e) {
this.optionDefinitions = e;
}
_getKnownOptions(e, t) {
const r = _.empty();
// SERIALIZE KNOWN OPTIONS
for (const i in this.optionDefinitions) if (this.optionDefinitions.hasOwnProperty(i)) {
const o = this.optionDefinitions[i];
if (i in e) {
const a = e[i];
let u;
if (o.nestedOptions && n(a)) {
u = {
mapValue: {
fields: new OptionsUtil(o.nestedOptions).getOptionsProto(t, a)
}
};
} else a && (u = s(a, t) ?? void 0);
u && r.set(k.fromServerFormat(o.serverName), u);
}
}
return r;
}
getOptionsProto(e, n, t) {
const r = this._getKnownOptions(n, e);
// APPLY OPTIONS OVERRIDES
if (t) {
const n = new Map(g(t, ((n, t) => [ k.fromServerFormat(t), void 0 !== n ? s(n, e) : null ])));
r.setAll(n);
}
// Return MapValue from `result` or empty map value
return r.value.mapValue.fields ?? {};
}
}
/**
* @license
* Copyright 2025 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.
*/ class __PRIVATE_StructuredPipelineOptions {
constructor(e = {}, n = {}) {
this.Z = e, this.ee = n, this.ne = new OptionsUtil({
indexMode: {
serverName: "index_mode"
}
});
}
_readUserData(e) {
this.proto = this.ne.getOptionsProto(e, this.Z, this.ee);
}
}
class StructuredPipeline {
constructor(e, n) {
this.pipeline = e, this.options = n;
}
_toProto(e) {
return {
pipeline: this.pipeline._toProto(e),
options: this.options.proto
};
}
}
/**
* @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.
*/
/* eslint @typescript-eslint/no-explicit-any: 0 */ function __PRIVATE_isFirestoreValue(e) {
return "object" == typeof e && null !== e && !!("nullValue" in e && (null === e.nullValue || "NULL_VALUE" === e.nullValue) || "booleanValue" in e && (null === e.booleanValue || "boolean" == typeof e.booleanValue) || "integerValue" in e && (null === e.integerValue || "number" == typeof e.integerValue || "string" == typeof e.integerValue) || "doubleValue" in e && (null === e.doubleValue || "number" == typeof e.doubleValue) || "timestampValue" in e && (null === e.timestampValue || function __PRIVATE_isITimestamp(e) {
return "object" == typeof e && null !== e && "seconds" in e && (null === e.seconds || "number" == typeof e.seconds || "string" == typeof e.seconds) && "nanos" in e && (null === e.nanos || "number" == typeof e.nanos);
}(e.timestampValue)) || "stringValue" in e && (null === e.stringValue || "string" == typeof e.stringValue) || "bytesValue" in e && (null === e.bytesValue || e.bytesValue instanceof Uint8Array) || "referenceValue" in e && (null === e.referenceValue || "string" == typeof e.referenceValue) || "geoPointValue" in e && (null === e.geoPointValue || function __PRIVATE_isILatLng(e) {
return "object" == typeof e && null !== e && "latitude" in e && (null === e.latitude || "number" == typeof e.latitude) && "longitude" in e && (null === e.longitude || "number" == typeof e.longitude);
}(e.geoPointValue)) || "arrayValue" in e && (null === e.arrayValue || function __PRIVATE_isIArrayValue(e) {
return "object" == typeof e && null !== e && !(!("values" in e) || null !== e.values && !Array.isArray(e.values));
}(e.arrayValue)) || "mapValue" in e && (null === e.mapValue || function __PRIVATE_isIMapValue(e) {
return "object" == typeof e && null !== e && !(!("fields" in e) || null !== e.fields && !n(e.fields));
}(e.mapValue)) || "fieldReferenceValue" in e && (null === e.fieldReferenceValue || "string" == typeof e.fieldReferenceValue) || "functionValue" in e && (null === e.functionValue || function __PRIVATE_isIFunction(e) {
return "object" == typeof e && null !== e && !(!("name" in e) || null !== e.name && "string" != typeof e.name || !("args" in e) || null !== e.args && !Array.isArray(e.args));
}(e.functionValue)) || "pipelineValue" in e && (null === e.pipelineValue || function __PRIVATE_isIPipeline(e) {
return "object" == typeof e && null !== e && !(!("stages" in e) || null !== e.stages && !Array.isArray(e.stages));
}(e.pipelineValue)));
// Check optional properties and their types
}
/**
* @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.
*/
/**
* Converts a value to an Expression, Returning either a Constant, MapFunction,
* ArrayFunction, or the input itself (if it's already an expression).
*
* @private
* @internal
* @param value
*/ function __PRIVATE_valueToDefaultExpr$1(e) {
let t;
return e instanceof Expression ? e : (t = n(e) ? __PRIVATE__map(e) : e instanceof Array ? array(e) : __PRIVATE__constant(e, void 0),
t);
}
/**
* Converts a value to an Expression, Returning either a Constant, MapFunction,
* ArrayFunction, or the input itself (if it's already an expression).
*
* @private
* @internal
* @param value
*/ function __PRIVATE_vectorToExpr$1(e) {
if (e instanceof Expression) return e;
if (e instanceof R) return constant(e);
if (Array.isArray(e)) return constant($(e));
throw new Error("Unsupported value: " + typeof e);
}
/**
* Converts a value to an Expression, Returning either a Constant, MapFunction,
* ArrayFunction, or the input itself (if it's already an expression).
* If the input is a string, it is assumed to be a field name, and a
* field(value) is returned.
*
* @private
* @internal
* @param value
*/ function __PRIVATE_fieldOrExpression$1(e) {
if (E(e)) {
return field(e);
}
return __PRIVATE_valueToDefaultExpr$1(e);
}
/**
* @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.
*/ class Expression {
constructor() {
this._protoValueType = "ProtoValue";
}
/**
* 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(e) {
return new FunctionExpression("add", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "add");
}
/**
* @beta
* Wraps the expression in a [BooleanExpression].
*
* @returns A [BooleanExpression] representing the same expression.
*/ asBoolean() {
if (this instanceof BooleanExpression) return this;
if (this instanceof Constant) return new __PRIVATE_BooleanConstant(this);
if (this instanceof Field) return new __PRIVATE_BooleanField(this);
if (this instanceof FunctionExpression) return new __PRIVATE_BooleanFunctionExpression(this);
throw new x("invalid-argument", `Conversion of type ${typeof this} to BooleanExpression not supported.`);
}
subtract(e) {
return new FunctionExpression("subtract", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "subtract");
}
/**
* @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(e) {
return new FunctionExpression("multiply", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "multiply");
}
divide(e) {
return new FunctionExpression("divide", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "divide");
}
mod(e) {
return new FunctionExpression("mod", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "mod");
}
equal(e) {
return new FunctionExpression("equal", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "equal").asBoolean();
}
notEqual(e) {
return new FunctionExpression("not_equal", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "notEqual").asBoolean();
}
lessThan(e) {
return new FunctionExpression("less_than", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "lessThan").asBoolean();
}
lessThanOrEqual(e) {
return new FunctionExpression("less_than_or_equal", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "lessThanOrEqual").asBoolean();
}
greaterThan(e) {
return new FunctionExpression("greater_than", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "greaterThan").asBoolean();
}
greaterThanOrEqual(e) {
return new FunctionExpression("greater_than_or_equal", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "greaterThanOrEqual").asBoolean();
}
/**
* @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(e, ...n) {
const t = [ e, ...n ].map((e => __PRIVATE_valueToDefaultExpr$1(e)));
return new FunctionExpression("array_concat", [ this, ...t ], "arrayConcat");
}
arrayContains(e) {
return new FunctionExpression("array_contains", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "arrayContains").asBoolean();
}
arrayContainsAll(e) {
const n = Array.isArray(e) ? new __PRIVATE_ListOfExprs(e.map(__PRIVATE_valueToDefaultExpr$1), "arrayContainsAll") : e;
return new FunctionExpression("array_contains_all", [ this, n ], "arrayContainsAll").asBoolean();
}
arrayContainsAny(e) {
const n = Array.isArray(e) ? new __PRIVATE_ListOfExprs(e.map(__PRIVATE_valueToDefaultExpr$1), "arrayContainsAny") : e;
return new FunctionExpression("array_contains_any", [ this, n ], "arrayContainsAny").asBoolean();
}
/**
* @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() {
return new FunctionExpression("array_reverse", [ this ]);
}
/**
* @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() {
return new FunctionExpression("array_length", [ this ], "arrayLength");
}
equalAny(e) {
const n = Array.isArray(e) ? new __PRIVATE_ListOfExprs(e.map(__PRIVATE_valueToDefaultExpr$1), "equalAny") : e;
return new FunctionExpression("equal_any", [ this, n ], "equalAny").asBoolean();
}
notEqualAny(e) {
const n = Array.isArray(e) ? new __PRIVATE_ListOfExprs(e.map(__PRIVATE_valueToDefaultExpr$1), "notEqualAny") : e;
return new FunctionExpression("not_equal_any", [ this, n ], "notEqualAny").asBoolean();
}
/**
* @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() {
return new FunctionExpression("exists", [ this ], "exists").asBoolean();
}
/**
* @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() {
return new FunctionExpression("char_length", [ this ], "charLength");
}
like(e) {
return new FunctionExpression("like", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "like").asBoolean();
}
regexContains(e) {
return new FunctionExpression("regex_contains", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "regexContains").asBoolean();
}
regexFind(e) {
return new FunctionExpression("regex_find", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "regexFind");
}
regexFindAll(e) {
return new FunctionExpression("regex_find_all", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "regexFindAll");
}
regexMatch(e) {
return new FunctionExpression("regex_match", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "regexMatch").asBoolean();
}
stringContains(e) {
return new FunctionExpression("string_contains", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "stringContains").asBoolean();
}
startsWith(e) {
return new FunctionExpression("starts_with", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "startsWith").asBoolean();
}
endsWith(e) {
return new FunctionExpression("ends_with", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "endsWith").asBoolean();
}
/**
* @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() {
return new FunctionExpression("to_lower", [ this ], "toLower");
}
/**
* @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() {
return new FunctionExpression("to_upper", [ this ], "toUpper");
}
/**
* @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(e) {
const n = [ this ];
return e && n.push(__PRIVATE_valueToDefaultExpr$1(e)), new FunctionExpression("trim", n, "trim");
}
/**
* @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(e) {
const n = [ this ];
return e && n.push(__PRIVATE_valueToDefaultExpr$1(e)), new FunctionExpression("ltrim", n, "ltrim");
}
/**
* @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(e) {
const n = [ this ];
return e && n.push(__PRIVATE_valueToDefaultExpr$1(e)), new FunctionExpression("rtrim", n, "rtrim");
}
/**
* @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() {
return new FunctionExpression("type", [ this ]);
}
/**
* @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(e) {
return new FunctionExpression("is_type", [ this, constant(e) ], "isType").asBoolean();
}
/**
* @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(e, ...n) {
const t = [ e, ...n ].map(__PRIVATE_valueToDefaultExpr$1);
return new FunctionExpression("string_concat", [ this, ...t ], "stringConcat");
}
/**
* @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(e) {
return new FunctionExpression("string_index_of", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "stringIndexOf");
}
/**
* @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(e) {
return new FunctionExpression("string_repeat", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "stringRepeat");
}
/**
* @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(e, n) {
return new FunctionExpression("string_replace_all", [ this, __PRIVATE_valueToDefaultExpr$1(e), __PRIVATE_valueToDefaultExpr$1(n) ], "stringReplaceAll");
}
/**
* @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(e, n) {
return new FunctionExpression("string_replace_one", [ this, __PRIVATE_valueToDefaultExpr$1(e), __PRIVATE_valueToDefaultExpr$1(n) ], "stringReplaceOne");
}
/**
* @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(e, ...n) {
const t = [ e, ...n ].map(__PRIVATE_valueToDefaultExpr$1);
return new FunctionExpression("concat", [ this, ...t ], "concat");
}
/**
* @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() {
return new FunctionExpression("reverse", [ this ], "reverse");
}
/**
* @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() {
return new FunctionExpression("array_first", [ this ], "arrayFirst");
}
arrayFirstN(e) {
return new FunctionExpression("array_first_n", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "arrayFirstN");
}
/**
* @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() {
return new FunctionExpression("array_last", [ this ], "arrayLast");
}
arrayLastN(e) {
return new FunctionExpression("array_last_n", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "arrayLastN");
}
/**
* @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() {
return new FunctionExpression("maximum", [ this ], "arrayMaximum");
}
arrayMaximumN(e) {
return new FunctionExpression("maximum_n", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "arrayMaximumN");
}
/**
* @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() {
return new FunctionExpression("minimum", [ this ], "arrayMinimum");
}
arrayMinimumN(e) {
return new FunctionExpression("minimum_n", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "arrayMinimumN");
}
arrayIndexOf(e) {
return new FunctionExpression("array_index_of", [ this, __PRIVATE_valueToDefaultExpr$1(e), __PRIVATE_valueToDefaultExpr$1("first") ], "arrayIndexOf");
}
arrayLastIndexOf(e) {
return new FunctionExpression("array_index_of", [ this, __PRIVATE_valueToDefaultExpr$1(e), __PRIVATE_valueToDefaultExpr$1("last") ], "arrayLastIndexOf");
}
arrayIndexOfAll(e) {
return new FunctionExpression("array_index_of_all", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "arrayIndexOfAll");
}
/**
* @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() {
return new FunctionExpression("byte_length", [ this ], "byteLength");
}
/**
* @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() {
return new FunctionExpression("ceil", [ this ]);
}
/**
* @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() {
return new FunctionExpression("floor", [ this ]);
}
/**
* @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() {
return new FunctionExpression("abs", [ this ]);
}
/**
* @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() {
return new FunctionExpression("exp", [ this ]);
}
/**
* @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.
*/ mapGet(e) {
return new FunctionExpression("map_get", [ this, constant(e) ], "mapGet");
}
/**
* @beta
* Creates an expression that returns a new map with the specified entries added or updated.
*
* @remarks
* Note that `mapSet` only performs shallow updates to the map. Setting a value to `null`
* will retain the key with a `null` value. To remove a key entirely, use `mapRemove`.
*
* @example
* ```typescript
* // Set the 'city' to "San Francisco" in the 'address' map
* field("address").mapSet("city", "San Francisco");
* ```
*
* @param key - The key to set. Must be a string or a constant string expression.
* @param value - The value to set.
* @param moreKeyValues - Additional key-value pairs to set.
* @returns A new `Expression` representing the map with the entries set.
*/ mapSet(e, n, ...t) {
const r = [ this, __PRIVATE_valueToDefaultExpr$1(e), __PRIVATE_valueToDefaultExpr$1(n), ...t.map(__PRIVATE_valueToDefaultExpr$1) ];
return new FunctionExpression("map_set", r, "mapSet");
}
/**
* @beta
* Creates an expression that returns the keys of a map.
*
* @remarks
* While the backend generally preserves insertion order, relying on the
* order of the output array is not guaranteed and should be avoided.
*
* @example
* ```typescript
* // Get the keys of the 'address' map
* field("address").mapKeys();
* ```
*
* @returns A new `Expression` representing the keys of the map.
*/ mapKeys() {
return new FunctionExpression("map_keys", [ this ], "mapKeys");
}
/**
* @beta
* Creates an expression that returns the values of a map.
*
* @remarks
* While the backend generally preserves insertion order, relying on the
* order of the output array is not guaranteed and should be avoided.
*
* @example
* ```typescript
* // Get the values of the 'address' map
* field("address").mapValues();
* ```
*
* @returns A new `Expression` representing the values of the map.
*/ mapValues() {
return new FunctionExpression("map_values", [ this ], "mapValues");
}
/**
* @beta
* Creates an expression that returns the entries of a map as an array of maps,
* where each map contains a `"k"` property for the key and a `"v"` property for the value.
* For example: `[{ k: "key1", v: "value1" }, ...]`.
*
* @example
* ```typescript
* // Get the entries of the 'address' map
* field("address").mapEntries();
* ```
*
* @returns A new `Expression` representing the entries of the map.
*/ mapEntries() {
return new FunctionExpression("map_entries", [ this ], "mapEntries");
}
/**
* @beta
* Creates an aggregation that counts the number of stage inputs with valid evaluations of the
* expression or field.
*
* @example
* ```typescript
* // Count the total number of products
* field("productId").count().as("totalProducts");
* ```
*
* @returns A new `AggregateFunction` representing the 'count' aggregation.
*/ count() {
return AggregateFunction._create("count", [ this ], "count");
}
/**
* @beta
* Creates an aggregation that calculates the sum of a numeric field across multiple stage inputs.
*
* @example
* ```typescript
* // Calculate the total revenue from a set of orders
* field("orderAmount").sum().as("totalRevenue");
* ```
*
* @returns A new `AggregateFunction` representing the 'sum' aggregation.
*/ sum() {
return AggregateFunction._create("sum", [ this ], "sum");
}
/**
* @beta
* Creates an aggregation that calculates the average (mean) of a numeric field across multiple
* stage inputs.
*
* @example
* ```typescript
* // Calculate the average age of users
* field("age").average().as("averageAge");
* ```
*
* @returns A new `AggregateFunction` representing the 'average' aggregation.
*/ average() {
return AggregateFunction._create("average", [ this ], "average");
}
/**
* @beta
* Creates an aggregation that finds the minimum value of a field across multiple stage inputs.
*
* @example
* ```typescript
* // Find the lowest price of all products
* field("price").minimum().as("lowestPrice");
* ```
*
* @returns A new `AggregateFunction` representing the 'minimum' aggregation.
*/ minimum() {
return AggregateFunction._create("minimum", [ this ], "minimum");
}
/**
* @beta
* Creates an aggregation that finds the maximum value of a field across multiple stage inputs.
*
* @example
* ```typescript
* // Find the highest score in a leaderboard
* field("score").maximum().as("highestScore");
* ```
*
* @returns A new `AggregateFunction` representing the 'maximum' aggregation.
*/ maximum() {
return AggregateFunction._create("maximum", [ this ], "maximum");
}
/**
* @beta
* Creates an aggregation that finds the first value of an expression across multiple stage inputs.
*
* @example
* ```typescript
* // Find the first value of the 'rating' field
* field("rating").first().as("firstRating");
* ```
*
* @returns A new `AggregateFunction` representing the 'first' aggregation.
*/ first() {
return AggregateFunction._create("first", [ this ], "first");
}
/**
* @beta
* Creates an aggregation that finds the last value of an expression across multiple stage inputs.
*
* @example
* ```typescript
* // Find the last value of the 'rating' field
* field("rating").last().as("lastRating");
* ```
*
* @returns A new `AggregateFunction` representing the 'last' aggregation.
*/ last() {
return AggregateFunction._create("last", [ this ], "last");
}
/**
* @beta
* Creates an aggregation that collects all values of an expression across multiple stage inputs
* into an array.
*
* @remarks
* If the expression resolves to an absent value, it is converted to `null`.
* The order of elements in the output array is not stable and shouldn't be relied upon.
*
* @example
* ```typescript
* // Collect all tags from books into an array
* field("tags").arrayAgg().as("allTags");
* ```
*
* @returns A new `AggregateFunction` representing the 'array_agg' aggregation.
*/ arrayAgg() {
return AggregateFunction._create("array_agg", [ this ], "arrayAgg");
}
/**
* @beta
* Creates an aggregation that collects all distinct values of an expression across multiple stage
* inputs into an array.
*
* @remarks
* If the expression resolves to an absent value, it is converted to `null`.
* The order of elements in the output array is not stable and shouldn't be relied upon.
*
* @example
* ```typescript
* // Collect all distinct tags from books into an array
* field("tags").arrayAggDistinct().as("allDistinctTags");
* ```
*
* @returns A new `AggregateFunction` representing the 'array_agg_distinct' aggregation.
*/ arrayAggDistinct() {
return AggregateFunction._create("array_agg_distinct", [ this ], "arrayAggDistinct");
}
/**
* @beta
* Creates an aggregation that counts the number of distinct values of the expression or field.
*
* @example
* ```typescript
* // Count the distinct number of products
* field("productId").countDistinct().as("distinctProducts");
* ```
*
* @returns A new `AggregateFunction` representing the 'count_distinct' aggregation.
*/ countDistinct() {
return AggregateFunction._create("count_distinct", [ this ], "countDistinct");
}
/**
* @beta
* Creates an expression that returns the larger value between this expression and another expression, based on Firestore's value type ordering.
*
* @example
* ```typescript
* // Returns the larger value between the 'timestamp' field and the current timestamp.
* field("timestamp").logicalMaximum(currentTimestamp());
* ```
*
* @param second - The second expression or literal to compare with.
* @param others - Optional additional expressions or literals to compare with.
* @returns A new {@link @firebase/firestore/pipelines#Expression} representing the logical maximum operation.
*/ logicalMaximum(e, ...n) {
const t = [ e, ...n ];
return new FunctionExpression("maximum", [ this, ...t.map(__PRIVATE_valueToDefaultExpr$1) ], "logicalMaximum");
}
/**
* @beta
* Creates an expression that returns the smaller value between this expression and another expression, based on Firestore's value type ordering.
*
* @example
* ```typescript
* // Returns the smaller value between the 'timestamp' field and the current timestamp.
* field("timestamp").logicalMinimum(currentTimestamp());
* ```
*
* @param second - The second expression or literal to compare with.
* @param others - Optional additional expressions or literals to compare with.
* @returns A new {@link @firebase/firestore/pipelines#Expression} representing the logical minimum operation.
*/ logicalMinimum(e, ...n) {
const t = [ e, ...n ];
return new FunctionExpression("minimum", [ this, ...t.map(__PRIVATE_valueToDefaultExpr$1) ], "minimum");
}
/**
* @beta
* Creates an expression that calculates the length (number of dimensions) of this Firestore Vector expression.
*
* @example
* ```typescript
* // Get the vector length (dimension) of the field 'embedding'.
* field("embedding").vectorLength();
* ```
*
* @returns A new {@link @firebase/firestore/pipelines#Expression} representing the length of the vector.
*/ vectorLength() {
return new FunctionExpression("vector_length", [ this ], "vectorLength");
}
cosineDistance(e) {
return new FunctionExpression("cosine_distance", [ this, __PRIVATE_vectorToExpr$1(e) ], "cosineDistance");
}
dotProduct(e) {
return new FunctionExpression("dot_product", [ this, __PRIVATE_vectorToExpr$1(e) ], "dotProduct");
}
euclideanDistance(e) {
return new FunctionExpression("euclidean_distance", [ this, __PRIVATE_vectorToExpr$1(e) ], "euclideanDistance");
}
/**
* @beta
* Creates an expression that interprets this expression as the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC)
* and returns a timestamp.
*
* @example
* ```typescript
* // Interpret the 'microseconds' field as microseconds since epoch.
* field("microseconds").unixMicrosToTimestamp();
* ```
*
* @returns A new {@link @firebase/firestore/pipelines#Expression} representing the timestamp.
*/ unixMicrosToTimestamp() {
return new FunctionExpression("unix_micros_to_timestamp", [ this ], "unixMicrosToTimestamp");
}
/**
* @beta
* Creates an expression that converts this timestamp expression to the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC).
*
* @example
* ```typescript
* // Convert the 'timestamp' field to microseconds since epoch.
* field("timestamp").timestampToUnixMicros();
* ```
*
* @returns A new {@link @firebase/firestore/pipelines#Expression} representing the number of microseconds since epoch.
*/ timestampToUnixMicros() {
return new FunctionExpression("timestamp_to_unix_micros", [ this ], "timestampToUnixMicros");
}
/**
* @beta
* Creates an expression that interprets this expression as the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC)
* and returns a timestamp.
*
* @example
* ```typescript
* // Interpret the 'milliseconds' field as milliseconds since epoch.
* field("milliseconds").unixMillisToTimestamp();
* ```
*
* @returns A new {@link @firebase/firestore/pipelines#Expression} representing the timestamp.
*/ unixMillisToTimestamp() {
return new FunctionExpression("unix_millis_to_timestamp", [ this ], "unixMillisToTimestamp");
}
/**
* @beta
* Creates an expression that converts this timestamp expression to the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC).
*
* @example
* ```typescript
* // Convert the 'timestamp' field to milliseconds since epoch.
* field("timestamp").timestampToUnixMillis();
* ```
*
* @returns A new {@link @firebase/firestore/pipelines#Expression} representing the number of milliseconds since epoch.
*/ timestampToUnixMillis() {
return new FunctionExpression("timestamp_to_unix_millis", [ this ], "timestampToUnixMillis");
}
/**
* @beta
* Creates an expression that interprets this expression as the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC)
* and returns a timestamp.
*
* @example
* ```typescript
* // Interpret the 'seconds' field as seconds since epoch.
* field("seconds").unixSecondsToTimestamp();
* ```
*
* @returns A new {@link @firebase/firestore/pipelines#Expression} representing the timestamp.
*/ unixSecondsToTimestamp() {
return new FunctionExpression("unix_seconds_to_timestamp", [ this ], "unixSecondsToTimestamp");
}
/**
* @beta
* Creates an expression that converts this timestamp expression to the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC).
*
* @example
* ```typescript
* // Convert the 'timestamp' field to seconds since epoch.
* field("timestamp").timestampToUnixSeconds();
* ```
*
* @returns A new {@link @firebase/firestore/pipelines#Expression} representing the number of seconds since epoch.
*/ timestampToUnixSeconds() {
return new FunctionExpression("timestamp_to_unix_seconds", [ this ], "timestampToUnixSeconds");
}
timestampAdd(e, n) {
return new FunctionExpression("timestamp_add", [ this, __PRIVATE_valueToDefaultExpr$1(e), __PRIVATE_valueToDefaultExpr$1(n) ], "timestampAdd");
}
timestampSubtract(e, n) {
return new FunctionExpression("timestamp_subtract", [ this, __PRIVATE_valueToDefaultExpr$1(e), __PRIVATE_valueToDefaultExpr$1(n) ], "timestampSubtract");
}
/**
* @beta
*
* Creates an expression that returns the document ID from a path.
*
* @example
* ```typescript
* // Get the document ID from a path.
* field("__path__").documentId();
* ```
*
* @returns A new {@link @firebase/firestore/pipelines#Expression} representing the documentId operation.
*/ documentId() {
return new FunctionExpression("document_id", [ this ], "documentId");
}
substring(e, n) {
const t = __PRIVATE_valueToDefaultExpr$1(e);
return new FunctionExpression("substring", void 0 === n ? [ this, t ] : [ this, t, __PRIVATE_valueToDefaultExpr$1(n) ], "substring");
}
arrayGet(e) {
return new FunctionExpression("array_get", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "arrayGet");
}
/**
* @beta
*
* Creates an expression that checks if a given expression produces an error.
*
* @example
* ```typescript
* // Check if the result of a calculation is an error
* field("title").arrayContains(1).isError();
* ```
*
* @returns A new {@link @firebase/firestore/pipelines#BooleanExpression} representing the 'isError' check.
*/ isError() {
return new FunctionExpression("is_error", [ this ], "isError").asBoolean();
}
ifError(e) {
const n = new FunctionExpression("if_error", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "ifError");
return e instanceof BooleanExpression ? n.asBoolean() : n;
}
/**
* @beta
*
* Creates an expression that returns `true` if the result of this expression
* is absent. Otherwise, returns `false` even if the value is `null`.
*
* @example
* ```typescript
* // Check if the field `value` is absent.
* field("value").isAbsent();
* ```
*
* @returns A new {@link @firebase/firestore/pipelines#BooleanExpression} representing the 'isAbsent' check.
*/ isAbsent() {
return new FunctionExpression("is_absent", [ this ], "isAbsent").asBoolean();
}
mapRemove(e) {
return new FunctionExpression("map_remove", [ this, __PRIVATE_valueToDefaultExpr$1(e) ], "mapRemove");
}
/**
* @beta
*
* Creates an expression that merges multiple map values.
*
* @example
* ```
* // Merges the map in the settings field with, a map literal, and a map in
* // that is conditionally returned by another expression
* field('settings').mapMerge({ enabled: true }, conditional(field('isAdmin'), { admin: true}, {})
* ```
*
* @param secondMap - A required second map to merge. Represented as a literal or
* an expression that returns a map.
* @param otherMaps - Optional additional maps to merge. Each map is represented
* as a literal or an expression that returns a map.
*