@@ -885,6 +885,21 @@ export abstract class Expr implements ProtoSerializable<ProtoValue>, UserData {
885
885
return new IsNan ( this ) ;
886
886
}
887
887
888
+ /**
889
+ * Creates an expression that checks if this expression evaluates to `null`.
890
+ *
891
+ * ```typescript
892
+ * // Check if a field is set to value `null`. Returns false if it is set to
893
+ * // other values or is not set at all.
894
+ * Field.of("value").isNull();
895
+ * ```
896
+ *
897
+ * @return A new `Expr` representing the 'isNull' check.
898
+ */
899
+ isNull ( ) : IsNan {
900
+ return new IsNull ( this ) ;
901
+ }
902
+
888
903
/**
889
904
* Creates an expression that checks if a field exists in the document.
890
905
*
@@ -1923,7 +1938,7 @@ export class Field extends Expr implements Selectable {
1923
1938
* @private
1924
1939
*/
1925
1940
constructor (
1926
- private fieldPath : InternalFieldPath ,
1941
+ readonly fieldPath : InternalFieldPath ,
1927
1942
private pipeline : Pipeline | null = null
1928
1943
) {
1929
1944
super ( ) ;
@@ -1957,7 +1972,7 @@ export class Field extends Expr implements Selectable {
1957
1972
if ( DOCUMENT_KEY_NAME === pipelineOrName ) {
1958
1973
return new Field ( documentId ( ) . _internalPath ) ;
1959
1974
}
1960
- return new Field ( fieldPathFromArgument ( 'of' , pipelineOrName ) ) ;
1975
+ return new Field ( InternalFieldPath . fromServerFormat ( pipelineOrName ) ) ;
1961
1976
} else if ( pipelineOrName instanceof FieldPath ) {
1962
1977
if ( documentId ( ) . isEqual ( pipelineOrName ) ) {
1963
1978
return new Field ( documentId ( ) . _internalPath ) ;
@@ -2576,6 +2591,16 @@ export class IsNan extends FirestoreFunction implements FilterCondition {
2576
2591
filterable = true as const ;
2577
2592
}
2578
2593
2594
+ /**
2595
+ * @beta
2596
+ */
2597
+ export class IsNull extends FirestoreFunction implements FilterCondition {
2598
+ constructor ( readonly expr : Expr ) {
2599
+ super ( 'is_null' , [ expr ] ) ;
2600
+ }
2601
+ filterable = true as const ;
2602
+ }
2603
+
2579
2604
/**
2580
2605
* @beta
2581
2606
*/
@@ -4897,6 +4922,41 @@ export function isNan(value: Expr | string): IsNan {
4897
4922
return new IsNan ( valueExpr ) ;
4898
4923
}
4899
4924
4925
+ /**
4926
+ * @beta
4927
+ *
4928
+ * Creates an expression that checks if an expression evaluates to 'null'.
4929
+ *
4930
+ * ```typescript
4931
+ * // Check if the field is set to 'null'. Returns false if it is not set, or
4932
+ * // set to any other value.
4933
+ * isNull(Field.of("value"));
4934
+ * ```
4935
+ *
4936
+ * @param value The expression to check.
4937
+ * @return A new {@code Expr} representing the 'isNull' check.
4938
+ */
4939
+ export function isNull ( value : Expr ) : IsNull ;
4940
+
4941
+ /**
4942
+ * @beta
4943
+ *
4944
+ * Creates an expression that checks if a field's value evaluates to 'null'.
4945
+ *
4946
+ * ```typescript
4947
+ * // Check if the result of a calculation is null.
4948
+ * isNull("value");
4949
+ * ```
4950
+ *
4951
+ * @param value The name of the field to check.
4952
+ * @return A new {@code Expr} representing the 'isNull' check.
4953
+ */
4954
+ export function isNull ( value : string ) : IsNull ;
4955
+ export function isNull ( value : Expr | string ) : IsNull {
4956
+ const valueExpr = value instanceof Expr ? value : Field . of ( value ) ;
4957
+ return new IsNull ( valueExpr ) ;
4958
+ }
4959
+
4900
4960
/**
4901
4961
* @beta
4902
4962
*
0 commit comments