@@ -461,6 +461,30 @@ public protocol Expression: Sendable {
461461 /// - Returns: A new `FunctionExpression` representing the "arrayGet" operation.
462462 func arrayGet( _ offsetExpression: Expression ) -> FunctionExpression
463463
464+ /// Creates an expression that returns the maximum element of an array.
465+ ///
466+ /// Assumes `self` evaluates to an array.
467+ ///
468+ /// ```swift
469+ /// // Get the maximum value in the "scores" array.
470+ /// Field("scores").arrayMaximum()
471+ /// ```
472+ ///
473+ /// - Returns: A new `FunctionExpression` representing the maximum element of the array.
474+ func arrayMaximum( ) -> FunctionExpression
475+
476+ /// Creates an expression that returns the minimum element of an array.
477+ ///
478+ /// Assumes `self` evaluates to an array.
479+ ///
480+ /// ```swift
481+ /// // Get the minimum value in the "scores" array.
482+ /// Field("scores").arrayMinimum()
483+ /// ```
484+ ///
485+ /// - Returns: A new `FunctionExpression` representing the minimum element of the array.
486+ func arrayMinimum( ) -> FunctionExpression
487+
464488 /// Creates a `BooleanExpression` that returns `true` if this expression is greater
465489 /// than the given expression.
466490 ///
@@ -681,6 +705,18 @@ public protocol Expression: Sendable {
681705 /// - Returns: A new `FunctionExpression` representing the joined string.
682706 func join( delimiter: String ) -> FunctionExpression
683707
708+ /// Creates an expression that splits a string into an array of substrings based on a delimiter.
709+ ///
710+ /// - Parameter delimiter: The string to split on.
711+ /// - Returns: A new `FunctionExpression` representing the array of substrings.
712+ func split( delimiter: String ) -> FunctionExpression
713+
714+ /// Creates an expression that splits a string into an array of substrings based on a delimiter.
715+ ///
716+ /// - Parameter delimiter: An expression that evaluates to a string or bytes to split on.
717+ /// - Returns: A new `FunctionExpression` representing the array of substrings.
718+ func split( delimiter: Expression ) -> FunctionExpression
719+
684720 /// Creates an expression that returns the length of a string.
685721 ///
686722 /// ```swift
@@ -886,6 +922,18 @@ public protocol Expression: Sendable {
886922 /// - Returns: A new `FunctionExpression` representing the uppercase string.
887923 func toUpper( ) -> FunctionExpression
888924
925+ /// Creates an expression that removes leading and trailing whitespace from a string.
926+ ///
927+ /// Assumes `self` evaluates to a string.
928+ ///
929+ /// ```swift
930+ /// // Trim leading/trailing whitespace from the "comment" field.
931+ /// Field("comment").trim()
932+ /// ```
933+ ///
934+ /// - Returns: A new `FunctionExpression` representing the trimmed string.
935+ func trim( ) -> FunctionExpression
936+
889937 /// Creates an expression that removes leading and trailing occurrences of specified characters
890938 /// from a string (from `self`).
891939 /// Assumes `self` evaluates to a string, and `value` evaluates to a string.
@@ -961,8 +1009,8 @@ public protocol Expression: Sendable {
9611009 /// - Returns: A new `FunctionExpression` representing the reversed string.
9621010 func stringReverse( ) -> FunctionExpression
9631011
964- /// Creates an expression that calculates the length of this expression in bytes.
965- /// Assumes `self` evaluates to a string.
1012+ /// Creates an expression that calculates the length of this string or bytes expression in bytes.
1013+ /// Assumes `self` evaluates to a string or bytes .
9661014 ///
9671015 /// ```swift
9681016 /// // Calculate the length of the "myString" field in bytes.
@@ -975,9 +1023,9 @@ public protocol Expression: Sendable {
9751023 /// - Returns: A new `FunctionExpression` representing the length in bytes.
9761024 func byteLength( ) -> FunctionExpression
9771025
978- /// Creates an expression that returns a substring of this expression using
1026+ /// Creates an expression that returns a substring of this expression (String or Bytes) using
9791027 /// literal integers for position and optional length.
980- /// Indexing is 0-based. Assumes `self` evaluates to a string.
1028+ /// Indexing is 0-based. Assumes `self` evaluates to a string or bytes .
9811029 ///
9821030 /// ```swift
9831031 /// // Get substring from index 5 with length 10
@@ -992,9 +1040,9 @@ public protocol Expression: Sendable {
9921040 /// - Returns: A new `FunctionExpression` representing the substring.
9931041 func substring( position: Int , length: Int ? ) -> FunctionExpression
9941042
995- /// Creates an expression that returns a substring of this expression using
1043+ /// Creates an expression that returns a substring of this expression (String or Bytes) using
9961044 /// expressions for position and optional length.
997- /// Indexing is 0-based. Assumes `self` evaluates to a string, and parameters evaluate to
1045+ /// Indexing is 0-based. Assumes `self` evaluates to a string or bytes , and parameters evaluate to
9981046 /// integers.
9991047 ///
10001048 /// ```swift
@@ -1080,34 +1128,6 @@ public protocol Expression: Sendable {
10801128 /// - Returns: A new `FunctionExpression` representing the "map_merge" operation.
10811129 func mapMerge( _ maps: [ Expression ] ) -> FunctionExpression
10821130
1083- /// Creates an expression that adds or updates a specified field in a map.
1084- /// Assumes `self` evaluates to a Map, `key` evaluates to a string, and `value` can be
1085- /// any type.
1086- ///
1087- /// ```swift
1088- /// // Set a field using a key from another field
1089- /// Field("config").mapSet(key: Field("keyName"), value: Field("keyValue"))
1090- /// ```
1091- ///
1092- /// - Parameter key: An `Expression` (evaluating to a string) representing the key of
1093- /// the field to set or update.
1094- /// - Parameter value: The `Expression` representing the value to set for the field.
1095- /// - Returns: A new `FunctionExpression` representing the map with the updated field.
1096- func mapSet( key: Expression , value: Sendable ) -> FunctionExpression
1097-
1098- /// Creates an expression that adds or updates a specified field in a map.
1099- /// Assumes `self` evaluates to a Map.
1100- ///
1101- /// ```swift
1102- /// // Set the "status" field to "active" in the "order" map
1103- /// Field("order").mapSet(key: "status", value: "active")
1104- /// ```
1105- ///
1106- /// - Parameter key: The literal string key of the field to set or update.
1107- /// - Parameter value: The `Sendable` literal value to set for the field.
1108- /// - Returns: A new `FunctionExpression` representing the map with the updated field.
1109- func mapSet( key: String , value: Sendable ) -> FunctionExpression
1110-
11111131 // MARK: Aggregations
11121132
11131133 /// Creates an aggregation that counts the number of distinct values of this expression.
@@ -1429,19 +1449,23 @@ public protocol Expression: Sendable {
14291449 /// Field("timestamp").timestampTruncate(granularity: .day)
14301450 /// ```
14311451 ///
1432- /// - Parameter granularity: A `TimeUnit` enum representing the truncation unit.
1452+ /// - Parameter granularity: A `TimeGranularity` representing the truncation unit.
14331453 /// - Returns: A new `FunctionExpression` representing the truncated timestamp.
1434- func timestampTruncate( granularity: TimeUnit ) -> FunctionExpression
1454+ func timestampTruncate( granularity: TimeGranularity ) -> FunctionExpression
14351455
14361456 /// Creates an expression that truncates a timestamp to a specified granularity.
1437- /// Assumes `self` evaluates to a Timestamp, and `granularity` is a literal string .
1457+ /// Assumes `self` evaluates to a Timestamp.
14381458 ///
14391459 /// ```swift
14401460 /// // Truncate "timestamp" field to the nearest day using a literal string.
14411461 /// Field("timestamp").timestampTruncate(granularity: "day")
1462+ ///
1463+ /// // Truncate "timestamp" field to the nearest day using an expression.
1464+ /// Field("timestamp").timestampTruncate(granularity: Field("granularity_field"))
14421465 /// ```
14431466 ///
1444- /// - Parameter granularity: A `Sendable` literal string specifying the truncation unit.
1467+ /// - Parameter granularity: A `Sendable` literal string or an `Expression` that evaluates to a
1468+ /// string, specifying the truncation unit.
14451469 /// - Returns: A new `FunctionExpression` representing the truncated timestamp.
14461470 func timestampTruncate( granularity: Sendable ) -> FunctionExpression
14471471
@@ -1596,4 +1620,14 @@ public protocol Expression: Sendable {
15961620 /// - Parameter values: The values to concatenate.
15971621 /// - Returns: A new `FunctionExpression` representing the concatenated result.
15981622 func concat( _ values: [ Sendable ] ) -> FunctionExpression
1623+
1624+ /// Creates an expression that returns the type of the expression.
1625+ ///
1626+ /// ```swift
1627+ /// // Get the type of the "rating" field.
1628+ /// Field("rating").type()
1629+ /// ```
1630+ ///
1631+ /// - Returns: A new `FunctionExpression` representing the type of the expression as a string.
1632+ func type( ) -> FunctionExpression
15991633}
0 commit comments