@@ -2050,6 +2050,71 @@ export abstract class Expression implements ProtoValueSerializable, UserData {
2050
2050
return new FunctionExpression ( 'string_reverse' , [ this ] ) ;
2051
2051
}
2052
2052
2053
+ /**
2054
+ * Creates an expression that returns the `elseValue` argument if this expression results in an absent value, else
2055
+ * return the result of the this expression evaluation.
2056
+ *
2057
+ * ```typescript
2058
+ * // Returns the value of the optional field 'optional_field', or returns 'default_value'
2059
+ * // if the field is absent.
2060
+ * field("optional_field").ifAbsent("default_value")
2061
+ * ```
2062
+ *
2063
+ * @param elseValue The value that will be returned if this Expression evaluates to an absent value.
2064
+ * @return A new [Expression] representing the ifAbsent operation.
2065
+ */
2066
+ ifAbsent ( elseValue : unknown ) : Expression ;
2067
+
2068
+ /**
2069
+ * Creates an expression that returns the `elseValue` argument if this expression results in an absent value, else
2070
+ * return the result of this expression evaluation.
2071
+ *
2072
+ * ```typescript
2073
+ * // Returns the value of the optional field 'optional_field', or if that is
2074
+ * // absent, then returns the value of the field `
2075
+ * field("optional_field").ifAbsent(field('default_field'))
2076
+ * ```
2077
+ *
2078
+ * @param elseExpression The Expression that will be evaluated if this Expression evaluates to an absent value.
2079
+ * @return A new [Expression] representing the ifAbsent operation.
2080
+ */
2081
+ ifAbsent ( elseExpression : unknown ) : Expression ;
2082
+
2083
+ ifAbsent ( elseValueOrExpression : Expression | unknown ) : Expression {
2084
+ return new FunctionExpression ( 'if_absent' , [ this , valueToDefaultExpr ( elseValueOrExpression ) ] , 'ifAbsent' ) ;
2085
+ }
2086
+
2087
+ /**
2088
+ * Creates an expression that joins the elements of an array into a string.
2089
+ *
2090
+ * ```typescript
2091
+ * // Join the elements of the 'tags' field with the delimiter from the 'separator' field.
2092
+ * field("tags").join(field("separator"))
2093
+ * ```
2094
+ *
2095
+ * @param delimiterExpression The expression that evaluates to the delimiter string.
2096
+ * @return A new Expression representing the join operation.
2097
+ */
2098
+ join ( delimiterExpression : Expression ) : Expression ;
2099
+
2100
+ /**
2101
+ * Creates an expression that joins the elements of an array field into a string.
2102
+ *
2103
+ * ```typescript
2104
+ * // Join the elements of the 'tags' field with a comma and space.
2105
+ * field("tags").join(", ")
2106
+ * ```
2107
+ *
2108
+ * @param delimiter The string to use as a delimiter.
2109
+ * @return A new Expression representing the join operation.
2110
+ */
2111
+ join ( delimiter : string ) : Expression ;
2112
+
2113
+ join ( delimeterValueOrExpression : string | Expression ) : Expression {
2114
+ return new FunctionExpression ( 'join' , [ this , valueToDefaultExpr ( delimeterValueOrExpression ) ] , 'join' ) ;
2115
+ }
2116
+
2117
+
2053
2118
// TODO(new-expression): Add new expression method definitions above this line
2054
2119
2055
2120
/**
@@ -6768,6 +6833,37 @@ export function timestampSubtract(
6768
6833
) ;
6769
6834
}
6770
6835
6836
+ /**
6837
+ * @beta
6838
+ *
6839
+ * Creates an expression that evaluates to the current server timestamp.
6840
+ *
6841
+ * ```typescript
6842
+ * // Get the current server timestamp
6843
+ * currentTimestamp()
6844
+ * ```
6845
+ *
6846
+ * @return A new Expression representing the current server timestamp.
6847
+ */
6848
+ export function currentTimestamp ( ) : FunctionExpression {
6849
+ return new FunctionExpression ( 'current_timestamp' , [ ] , 'currentTimestamp' ) ;
6850
+ }
6851
+
6852
+ /**
6853
+ * Creates an expression that raises an error with the given message. This could be useful for
6854
+ * debugging purposes.
6855
+ *
6856
+ * ```typescript
6857
+ * // Raise an error with the message "simulating an evaluation error".
6858
+ * error("simulating an evaluation error")
6859
+ * ```
6860
+ *
6861
+ * @return A new Expression representing the error() operation.
6862
+ */
6863
+ export function error ( message : string ) : Expression {
6864
+ return new FunctionExpression ( 'error' , [ constant ( message ) ] , 'currentTimestamp' ) ;
6865
+ }
6866
+
6771
6867
/**
6772
6868
* @beta
6773
6869
*
@@ -7232,6 +7328,133 @@ export function abs(expr: Expression | string): FunctionExpression {
7232
7328
return fieldOrExpression ( expr ) . abs ( ) ;
7233
7329
}
7234
7330
7331
+ /**
7332
+ * Creates an expression that returns the `elseExpr` argument if `ifExpr` is absent, else return
7333
+ * the result of the `ifExpr` argument evaluation.
7334
+ *
7335
+ * ```typescript
7336
+ * // Returns the value of the optional field 'optional_field', or returns 'default_value'
7337
+ * // if the field is absent.
7338
+ * ifAbsent(field("optional_field"), constant("default_value"))
7339
+ * ```
7340
+ *
7341
+ * @param ifExpr The expression to check for absence.
7342
+ * @param elseExpr The expression that will be evaluated and returned if [ifExpr] is absent.
7343
+ * @return A new Expression representing the ifAbsent operation.
7344
+ */
7345
+ export function ifAbsent ( ifExpr : Expression , elseExpr : Expression ) : Expression ;
7346
+
7347
+ /**
7348
+ * Creates an expression that returns the `elseValue` argument if `ifExpr` is absent, else
7349
+ * return the result of the `ifExpr` argument evaluation.
7350
+ *
7351
+ * ```typescript
7352
+ * // Returns the value of the optional field 'optional_field', or returns 'default_value'
7353
+ * // if the field is absent.
7354
+ * ifAbsent(field("optional_field"), "default_value")
7355
+ * ```
7356
+ *
7357
+ * @param ifExpr The expression to check for absence.
7358
+ * @param elseValue The value that will be returned if `ifExpr` evaluates to an absent value.
7359
+ * @return A new [Expression] representing the ifAbsent operation.
7360
+ */
7361
+ export function ifAbsent ( ifExpr : Expression , elseValue : unknown ) : Expression ;
7362
+
7363
+ /**
7364
+ * Creates an expression that returns the `elseExpr` argument if `ifFieldName` is absent, else
7365
+ * return the value of the field.
7366
+ *
7367
+ * ```typescript
7368
+ * // Returns the value of the optional field 'optional_field', or returns the value of
7369
+ * // 'default_field' if 'optional_field' is absent.
7370
+ * ifAbsent("optional_field", field("default_field"))
7371
+ * ```
7372
+ *
7373
+ * @param ifFieldName The field to check for absence.
7374
+ * @param elseExpr The expression that will be evaluated and returned if `ifFieldName` is
7375
+ * absent.
7376
+ * @return A new Expression representing the ifAbsent operation.
7377
+ */
7378
+ export function ifAbsent ( ifFieldName : string , elseExpr : Expression ) : Expression ;
7379
+
7380
+ /**
7381
+ * Creates an expression that returns the `elseValue` argument if `ifFieldName` is absent, else
7382
+ * return the value of the field.
7383
+ *
7384
+ * ```typescript
7385
+ * // Returns the value of the optional field 'optional_field', or returns 'default_value'
7386
+ * // if the field is absent.
7387
+ * ifAbsent("optional_field", "default_value")
7388
+ * ```
7389
+ *
7390
+ * @param ifFieldName The field to check for absence.
7391
+ * @param elseValue The value that will be returned if [ifFieldName] is absent.
7392
+ * @return A new Expression representing the ifAbsent operation.
7393
+ */
7394
+ export function ifAbsent ( ifFieldName : string | Expression , elseValue : Expression | unknown ) : Expression ;
7395
+ export function ifAbsent ( fieldNameOrExpression : string | Expression , elseValue : Expression | unknown ) : Expression {
7396
+ return fieldOrExpression ( fieldNameOrExpression ) . ifAbsent ( valueToDefaultExpr ( elseValue ) ) ;
7397
+ }
7398
+
7399
+ /**
7400
+ * Creates an expression that joins the elements of an array into a string.
7401
+ *
7402
+ * ```typescript
7403
+ * // Join the elements of the 'tags' field with a comma and space.
7404
+ * join("tags", ", ")
7405
+ * ```
7406
+ *
7407
+ * @param arrayFieldName The name of the field containing the array.
7408
+ * @param delimiter The string to use as a delimiter.
7409
+ * @return A new Expression representing the join operation.
7410
+ */
7411
+ export function join ( arrayFieldName : string , delimiter : string ) : Expression ;
7412
+
7413
+ /**
7414
+ * Creates an expression that joins the elements of an array into a string.
7415
+ *
7416
+ * ```typescript
7417
+ * // Join an array of string using the delimiter from the 'separator' field.
7418
+ * join(array(['foo', 'bar']), field("separator"))
7419
+ * ```
7420
+ *
7421
+ * @param arrayExpression An expression that evaluates to an array.
7422
+ * @param delimiterExpression The expression that evaluates to the delimiter string.
7423
+ * @return A new Expression representing the join operation.
7424
+ */
7425
+ export function join ( arrayExpression : Expression , delimiterExpression : Expression ) : Expression ;
7426
+
7427
+ /**
7428
+ * Creates an expression that joins the elements of an array into a string.
7429
+ *
7430
+ * ```typescript
7431
+ * // Join the elements of the 'tags' field with a comma and space.
7432
+ * join(field("tags"), ", ")
7433
+ * ```
7434
+ *
7435
+ * @param arrayExpression An expression that evaluates to an array.
7436
+ * @param delimiter The string to use as a delimiter.
7437
+ * @return A new Expression representing the join operation.
7438
+ */
7439
+ export function join ( arrayExpression : Expression , delimiter : string ) : Expression ;
7440
+
7441
+ /**
7442
+ * Creates an expression that joins the elements of an array into a string.
7443
+ *
7444
+ * ```typescript
7445
+ * // Join the elements of the 'tags' field with the delimiter from the 'separator' field.
7446
+ * join('tags', field("separator"))
7447
+ * ```
7448
+ *
7449
+ * @param arrayFieldName The name of the field containing the array.
7450
+ * @param delimiterExpression The expression that evaluates to the delimiter string.
7451
+ * @return A new Expression representing the join operation.
7452
+ */
7453
+ export function join ( arrayFieldName : string , delimiterExpression : Expression ) : Expression ;
7454
+ export function join ( fieldNameOrExpression : string | Expression , delimiterValueOrExpression : Expression | string ) : Expression {
7455
+ return fieldOrExpression ( fieldNameOrExpression ) . join ( valueToDefaultExpr ( delimiterValueOrExpression ) ) ;
7456
+ }
7457
+
7235
7458
// TODO(new-expression): Add new top-level expression function definitions above this line
7236
7459
7237
7460
/**
0 commit comments