@@ -2881,35 +2881,41 @@ export abstract class Expression
28812881 * Creates an expression that returns the `elseValue` argument if this expression results in a null value, else
28822882 * return the result of this expression evaluation.
28832883 *
2884+ * @remarks
2885+ * This function provides a fallback for both absent and explicit null values. In contrast, {@link ifAbsent}
2886+ * only triggers for missing fields.
2887+ *
28842888 * @example
28852889 * ```typescript
2886- * // Returns the value of the 'optional_field', or returns 'default_value'
2887- * // if the field is null.
2888- * field("optional_field").ifNull("default_value")
2890+ * // Returns the user's preferred name, or if that is null or absent, returns their full name.
2891+ * field("preferredName").ifNull(field("fullName"))
28892892 * ```
28902893 *
2891- * @param elseValue The value that will be returned if this Expression evaluates to a null value.
2894+ * @param elseExpression The Expression that will be evaluated if this Expression evaluates to a null or absent value.
28922895 * @returns A new [Expression] representing the ifNull operation.
28932896 */
2894- ifNull ( elseValue : unknown ) : Expression ;
2897+ ifNull ( elseExpression : Expression ) : FunctionExpression ;
28952898
28962899 /**
28972900 * @beta
28982901 * Creates an expression that returns the `elseValue` argument if this expression results in a null value, else
28992902 * return the result of this expression evaluation.
29002903 *
2904+ * @remarks
2905+ * This function provides a fallback for both absent and explicit null values. In contrast, {@link ifAbsent}
2906+ * only triggers for missing fields.
2907+ *
29012908 * @example
29022909 * ```typescript
2903- * // Returns the value of the 'optional_field', or if that is
2904- * // null, then returns the value of the field `
2905- * field("optional_field").ifNull(field('default_field'))
2910+ * // Returns the user's display name, or returns "Anonymous" if the field is null or absent.
2911+ * field("displayName").ifNull("Anonymous")
29062912 * ```
29072913 *
2908- * @param elseExpression The Expression that will be evaluated if this Expression evaluates to a null value.
2914+ * @param elseValue The value that will be returned if this Expression evaluates to a null or absent value.
29092915 * @returns A new [Expression] representing the ifNull operation.
29102916 */
2911- ifNull ( elseExpression : unknown ) : Expression ;
2912- ifNull ( elseValueOrExpression : Expression | unknown ) : Expression {
2917+ ifNull ( elseValue : unknown ) : FunctionExpression ;
2918+ ifNull ( elseValueOrExpression : Expression | unknown ) : FunctionExpression {
29132919 return new FunctionExpression ( 'if_null' , [
29142920 this ,
29152921 valueToDefaultExpr ( elseValueOrExpression ) ,
@@ -2918,26 +2924,25 @@ export abstract class Expression
29182924
29192925 /**
29202926 * @beta
2921- * Creates an expression that Returns the first non-null, non-absent argument, without evaluating
2927+ * Creates an expression that returns the first non-null, non-absent argument, without evaluating
29222928 * the rest of the arguments. When all arguments are null or absent, returns the last argument.
29232929 *
29242930 * @example
29252931 * ```typescript
2926- * // Return "Anonymous" if the 'name' field is null.
2927- * field("name").coalesce("Anonymous");
2928- * // Return "val1" if "val1" is not null, otherwise "val2", or "default" if both are null.
2929- * field("val1").coalesce(field("val2"), "default");
2932+ * // Returns the value of the first non-null, non-absent field among 'preferredName', 'fullName',
2933+ * // or the last argument if all previous fields are null.
2934+ * field("preferredName").coalesce(field("fullName"), "Anonymous");
29302935 * ```
29312936 *
29322937 * @param replacement - The value to use if this expression evaluates to null.
29332938 * @param others - Optional additional values to check if previous values are null.
29342939 * @returns A new [Expression] representing the coalesce operation.
29352940 */
29362941 coalesce (
2937- second : Expression | unknown ,
2942+ replacement : Expression | unknown ,
29382943 ...others : Array < Expression | unknown >
2939- ) : Expression {
2940- const values = [ second , ...others ] ;
2944+ ) : FunctionExpression {
2945+ const values = [ replacement , ...others ] ;
29412946 return new FunctionExpression ( 'coalesce' , [
29422947 this ,
29432948 ...values . map ( valueToDefaultExpr ) ,
@@ -9258,95 +9263,119 @@ export function ifAbsent(
92589263
92599264/**
92609265 * @beta
9261- * Creates an expression that returns the `elseExpr` argument if `ifExpr` is null or absent , else
9266+ * Creates an expression that returns the `elseExpr` argument if `ifExpr` is null, else
92629267 * return the result of the `ifExpr` argument evaluation.
92639268 *
9269+ * @remarks
9270+ * This function provides a fallback for both absent and explicit null values. In contrast,
9271+ * {@link ifAbsent} only triggers for missing fields.
9272+ *
92649273 * @example
92659274 * ```typescript
9266- * // Returns the value of the 'optional_field', or returns value of the 'default_field'
9267- * // if the 'optional_field' value is null or absent.
9268- * ifNull(field("optional_field"), field("default_field"))
9275+ * // Returns the user's preferred name, or if that is null or absent, returns their full name.
9276+ * ifNull(field("preferredName"), field("fullName"))
92699277 * ```
92709278 *
92719279 * @param ifExpr The expression to check for null or absence.
92729280 * @param elseExpr The expression that will be evaluated and returned if `ifExpr` is null or absent.
92739281 * @returns A new `Expression` representing the ifNull operation.
92749282 */
9275- export function ifNull ( ifExpr : Expression , elseExpr : Expression ) : Expression ;
9283+ export function ifNull (
9284+ ifExpr : Expression ,
9285+ elseExpr : Expression ,
9286+ ) : FunctionExpression ;
92769287
92779288/**
92789289 * @beta
9279- * Creates an expression that returns the `elseValue` argument if `ifExpr` is null or absent , else
9290+ * Creates an expression that returns the `elseValue` argument if `ifExpr` is null, else
92809291 * return the result of the `ifExpr` argument evaluation.
92819292 *
9293+ * @remarks
9294+ * This function provides a fallback for both absent and explicit null values. In contrast,
9295+ * {@link ifAbsent} only triggers for missing fields.
9296+ *
92829297 * @example
92839298 * ```typescript
9284- * // Returns the value of the 'optional_field', or returns 'default_value'
9285- * // if the 'optional_field' value is null or absent.
9286- * ifNull(field("optional_field"), "default_value")
9299+ * // Returns the user's display name, or returns "Anonymous" if the field is null or absent.
9300+ * ifNull(field("displayName"), "Anonymous")
92879301 * ```
92889302 *
9289- * @param ifExpr The expression to check for absence.
9303+ * @param ifExpr The expression to check for null or absence.
92909304 * @param elseValue The value that will be returned if `ifExpr` evaluates to a null or absent value.
92919305 * @returns A new `Expression` representing the ifNull operation.
92929306 */
9293- export function ifNull ( ifExpr : Expression , elseValue : unknown ) : Expression ;
9307+ export function ifNull (
9308+ ifExpr : Expression ,
9309+ elseValue : unknown ,
9310+ ) : FunctionExpression ;
92949311
92959312/**
92969313 * @beta
9297- * Creates an expression that returns the `elseExpr` argument if `ifFieldName` is null or absent , else
9314+ * Creates an expression that returns the `elseExpr` argument if `ifFieldName` is null, else
92989315 * return the value of the field.
92999316 *
9317+ * @remarks
9318+ * This function provides a fallback for both absent and explicit null values. In contrast,
9319+ * {@link ifAbsent} only triggers for missing fields.
9320+ *
93009321 * @example
93019322 * ```typescript
9302- * // Returns the value of the 'optional_field', or returns the value of
9303- * // 'default_field' if 'optional_field' is null or absent.
9304- * ifNull("optional_field", field("default_field"))
9323+ * // Returns the user's preferred name, or if that is null or absent, returns their full name.
9324+ * ifNull("preferredName", field("fullName"))
93059325 * ```
93069326 *
93079327 * @param ifFieldName The field to check for null or absence.
93089328 * @param elseExpr The expression that will be evaluated and returned if `ifFieldName` is
93099329 * null or absent.
93109330 * @returns A new `Expression` representing the ifNull operation.
93119331 */
9312- export function ifNull ( ifFieldName : string , elseExpr : Expression ) : Expression ;
9332+ export function ifNull (
9333+ ifFieldName : string ,
9334+ elseExpr : Expression ,
9335+ ) : FunctionExpression ;
93139336
93149337/**
93159338 * @beta
9316- * Creates an expression that returns the `elseValue` argument if `ifFieldName` is null or absent , else
9339+ * Creates an expression that returns the `elseValue` argument if `ifFieldName` is null, else
93179340 * return the value of the field.
93189341 *
9342+ * @remarks
9343+ * This function provides a fallback for both absent and explicit null values. In contrast,
9344+ * {@link ifAbsent} only triggers for missing fields.
9345+ *
93199346 * @example
93209347 * ```typescript
9321- * // Returns the value of the 'optional_field', or returns 'default_value'
9322- * // if the field is null or absent.
9323- * ifNull("optional_field", "default_value")
9348+ * // Returns the user's display name, or returns "Anonymous" if the field is null or absent.
9349+ * ifNull("displayName", "Anonymous")
93249350 * ```
93259351 *
93269352 * @param ifFieldName The field to check for null or absence.
93279353 * @param elseValue The value that will be returned if `ifFieldName` is null or absent.
93289354 * @returns A new `Expression` representing the ifNull operation.
93299355 */
9330- export function ifNull ( ifFieldName : string , elseValue : unknown ) : Expression ;
9356+ export function ifNull (
9357+ ifFieldName : string ,
9358+ elseValue : unknown ,
9359+ ) : FunctionExpression ;
93319360export function ifNull (
93329361 fieldNameOrExpression : string | Expression ,
93339362 elseValue : Expression | unknown ,
9334- ) : Expression {
9363+ ) : FunctionExpression {
93359364 return fieldOrExpression ( fieldNameOrExpression ) . ifNull (
93369365 valueToDefaultExpr ( elseValue ) ,
93379366 ) ;
93389367}
93399368
93409369/**
93419370 * @beta
9342- * Returns the first non-null, non-absent argument, without evaluating
9371+ * Creates an expression that returns the first non-null, non-absent argument, without evaluating
93439372 * the rest of the arguments. When all arguments are null or absent, returns the last argument.
93449373 *
93459374 * @example
93469375 * ```typescript
9347- * // Returns the value of 'optional_field', or if that is
9348- * // null, then returns the value of 'default_field'
9349- * coalesce(field("optional_field "), field("default_field "))
9376+ * // Returns the value of the first non-null, non-absent field among 'preferredName', 'fullName',
9377+ * // or the last argument if all previous fields are null.
9378+ * coalesce(field("preferredName "), field("fullName"), constant("Anonymous "))
93509379 * ```
93519380 *
93529381 * @param expression The first expression to check for null.
@@ -9358,18 +9387,18 @@ export function coalesce(
93589387 expression : Expression ,
93599388 replacement : Expression | unknown ,
93609389 ...others : Array < Expression | unknown >
9361- ) : Expression ;
9390+ ) : FunctionExpression ;
93629391
93639392/**
93649393 * @beta
9365- * Returns the first non-null, non-absent argument, without evaluating
9394+ * Creates an expression that returns the first non-null, non-absent argument, without evaluating
93669395 * the rest of the arguments. When all arguments are null or absent, returns the last argument.
93679396 *
93689397 * @example
93699398 * ```typescript
9370- * // Returns the value of 'optional_field', or if that is
9371- * // null, then returns the value of 'default_field'
9372- * coalesce("optional_field ", field("default_field "))
9399+ * // Returns the value of the first non-null, non-absent field among 'preferredName', 'fullName',
9400+ * // or the last argument if all previous fields are null.
9401+ * coalesce("preferredName ", field("fullName"), constant("Anonymous "))
93739402 * ```
93749403 *
93759404 * @param fieldName The name of the first field to check for null.
@@ -9381,14 +9410,16 @@ export function coalesce(
93819410 fieldName : string ,
93829411 replacement : Expression | unknown ,
93839412 ...others : Array < Expression | unknown >
9384- ) : Expression ;
9385-
9413+ ) : FunctionExpression ;
93869414export function coalesce (
9387- first : Expression | string ,
9388- second : Expression | unknown ,
9415+ fieldNameOrExpression : Expression | string ,
9416+ replacement : Expression | unknown ,
93899417 ...others : Array < Expression | unknown >
9390- ) : Expression {
9391- return fieldOrExpression ( first ) . coalesce ( second , ...others ) ;
9418+ ) : FunctionExpression {
9419+ return fieldOrExpression ( fieldNameOrExpression ) . coalesce (
9420+ replacement ,
9421+ ...others ,
9422+ ) ;
93929423}
93939424
93949425/**
0 commit comments