@@ -26,6 +26,7 @@ import type { Bytes } from '../modular/Bytes';
2626export type ExpressionType =
2727 | 'Field'
2828 | 'Constant'
29+ | 'Variable'
2930 | 'Function'
3031 | 'AggregateFunction'
3132 | 'ListOfExpressions'
@@ -148,11 +149,25 @@ export interface ConstantExpression extends FluentExpressionMethods {
148149 readonly _brand ?: 'ConstantExpression' ;
149150}
150151
152+ /**
153+ * @beta
154+ * Variable expression returned by `variable(...)`.
155+ */
156+ export interface VariableExpression extends Selectable , FluentExpressionMethods {
157+ readonly _brand ?: 'VariableExpression' ;
158+ }
159+
151160/**
152161 * @beta
153162 * Expression type for pipeline parameters (field refs, literals, function results).
154163 */
155- export type Expression = Field | FunctionExpression | ConstantExpression | Selectable | string ;
164+ export type Expression =
165+ | Field
166+ | FunctionExpression
167+ | ConstantExpression
168+ | VariableExpression
169+ | Selectable
170+ | string ;
156171
157172/**
158173 * @beta
@@ -258,6 +273,7 @@ type BooleanExpressionNode = RuntimeExpressionNode & RuntimeExpressionMethods &
258273type RuntimeExpressionFluentNode =
259274 | ( RuntimeExpressionNode & RuntimeExpressionMethods & Field )
260275 | ( RuntimeExpressionNode & RuntimeExpressionMethods & FunctionExpression )
276+ | ( RuntimeExpressionNode & RuntimeExpressionMethods & VariableExpression )
261277 | BooleanExpressionNode
262278 | ConstantExpressionNode ;
263279type FieldNode = RuntimeExpressionFluentNode & Field ;
@@ -550,6 +566,16 @@ function createConstant(value: unknown): ConstantExpressionNode {
550566 } ) ;
551567}
552568
569+ function createVariable ( name : unknown ) : RuntimeExpressionFluentNode & VariableExpression {
570+ return createNode ( expressionProto , {
571+ [ RUNTIME_NODE_SYMBOL ] : true ,
572+ __kind : 'expression' ,
573+ exprType : 'Variable' ,
574+ selectable : true ,
575+ name : String ( name ?? '' ) ,
576+ } ) ;
577+ }
578+
553579function normalizeMapLikeValue ( value : Record < string , unknown > ) : Record < string , unknown > {
554580 const output : Record < string , unknown > = { } ;
555581
@@ -842,6 +868,14 @@ export function field(_path: string): Field {
842868 return createField ( _path ) ;
843869}
844870
871+ /**
872+ * @beta
873+ * Returns a variable reference for alias-bound pipeline expressions.
874+ */
875+ export function variable ( _name : string ) : Expression {
876+ return createVariable ( _name ) ;
877+ }
878+
845879/**
846880 * @beta
847881 * Logical AND of boolean expressions.
@@ -1004,9 +1038,6 @@ export function arrayContainsAll(
10041038/**
10051039 * @beta
10061040 * Filters an array using a provided alias and predicate expression.
1007- *
1008- * The alias is serialized for native/web SDKs that support variable-bound
1009- * predicates; RN Firebase does not yet expose the `variable()` helper.
10101041 */
10111042export function arrayFilter (
10121043 _fieldName : string ,
0 commit comments