diff --git a/Firestore/Swift/Source/ExprImpl.swift b/Firestore/Swift/Source/ExprImpl.swift index 51a82966b86..d16f81d46e5 100644 --- a/Firestore/Swift/Source/ExprImpl.swift +++ b/Firestore/Swift/Source/ExprImpl.swift @@ -12,72 +12,72 @@ // See the License for the specific language governing permissions and // limitations under the License. -extension Expr { +extension Expression { func toBridge() -> ExprBridge { return (self as! BridgeWrapper).bridge } } -public extension Expr { - func `as`(_ name: String) -> ExprWithAlias { - return ExprWithAlias(self, name) +public extension Expression { + func `as`(_ name: String) -> AliasedExpression { + return AliasedExpression(self, name) } // MARK: Arithmetic Operators - func add(_ value: Expr) -> FunctionExpr { - return FunctionExpr("add", [self, value]) + func add(_ value: Expression) -> FunctionExpression { + return FunctionExpression("add", [self, value]) } - func add(_ value: Sendable) -> FunctionExpr { - return FunctionExpr("add", [self, Helper.sendableToExpr(value)]) + func add(_ value: Sendable) -> FunctionExpression { + return FunctionExpression("add", [self, Helper.sendableToExpr(value)]) } - func subtract(_ other: Expr) -> FunctionExpr { - return FunctionExpr("subtract", [self, other]) + func subtract(_ other: Expression) -> FunctionExpression { + return FunctionExpression("subtract", [self, other]) } - func subtract(_ other: Sendable) -> FunctionExpr { - return FunctionExpr("subtract", [self, Helper.sendableToExpr(other)]) + func subtract(_ other: Sendable) -> FunctionExpression { + return FunctionExpression("subtract", [self, Helper.sendableToExpr(other)]) } - func multiply(_ value: Expr) -> FunctionExpr { - return FunctionExpr("multiply", [self, value]) + func multiply(_ value: Expression) -> FunctionExpression { + return FunctionExpression("multiply", [self, value]) } - func multiply(_ value: Sendable) -> FunctionExpr { - return FunctionExpr("multiply", [self, Helper.sendableToExpr(value)]) + func multiply(_ value: Sendable) -> FunctionExpression { + return FunctionExpression("multiply", [self, Helper.sendableToExpr(value)]) } - func divide(_ other: Expr) -> FunctionExpr { - return FunctionExpr("divide", [self, other]) + func divide(_ other: Expression) -> FunctionExpression { + return FunctionExpression("divide", [self, other]) } - func divide(_ other: Sendable) -> FunctionExpr { - return FunctionExpr("divide", [self, Helper.sendableToExpr(other)]) + func divide(_ other: Sendable) -> FunctionExpression { + return FunctionExpression("divide", [self, Helper.sendableToExpr(other)]) } - func mod(_ other: Expr) -> FunctionExpr { - return FunctionExpr("mod", [self, other]) + func mod(_ other: Expression) -> FunctionExpression { + return FunctionExpression("mod", [self, other]) } - func mod(_ other: Sendable) -> FunctionExpr { - return FunctionExpr("mod", [self, Helper.sendableToExpr(other)]) + func mod(_ other: Sendable) -> FunctionExpression { + return FunctionExpression("mod", [self, Helper.sendableToExpr(other)]) } // MARK: Array Operations - func arrayConcat(_ secondArray: Expr, _ otherArrays: Expr...) -> FunctionExpr { - return FunctionExpr("array_concat", [self, secondArray] + otherArrays) + func arrayConcat(_ secondArray: Expression, _ otherArrays: Expression...) -> FunctionExpression { + return FunctionExpression("array_concat", [self, secondArray] + otherArrays) } - func arrayConcat(_ secondArray: [Sendable], _ otherArrays: [Sendable]...) -> FunctionExpr { + func arrayConcat(_ secondArray: [Sendable], _ otherArrays: [Sendable]...) -> FunctionExpression { let exprs = [self] + [Helper.sendableToExpr(secondArray)] + otherArrays .map { Helper.sendableToExpr($0) } - return FunctionExpr("array_concat", exprs) + return FunctionExpression("array_concat", exprs) } - func arrayContains(_ element: Expr) -> BooleanExpr { + func arrayContains(_ element: Expression) -> BooleanExpr { return BooleanExpr("array_contains", [self, element]) } @@ -85,7 +85,7 @@ public extension Expr { return BooleanExpr("array_contains", [self, Helper.sendableToExpr(element)]) } - func arrayContainsAll(_ values: [Expr]) -> BooleanExpr { + func arrayContainsAll(_ values: [Expression]) -> BooleanExpr { return BooleanExpr("array_contains_all", [self, Helper.array(values)]) } @@ -93,7 +93,7 @@ public extension Expr { return BooleanExpr("array_contains_all", [self, Helper.array(values)]) } - func arrayContainsAny(_ values: [Expr]) -> BooleanExpr { + func arrayContainsAny(_ values: [Expression]) -> BooleanExpr { return BooleanExpr("array_contains_any", [self, Helper.array(values)]) } @@ -101,19 +101,19 @@ public extension Expr { return BooleanExpr("array_contains_any", [self, Helper.array(values)]) } - func arrayLength() -> FunctionExpr { - return FunctionExpr("array_length", [self]) + func arrayLength() -> FunctionExpression { + return FunctionExpression("array_length", [self]) } - func arrayGet(_ offset: Int) -> FunctionExpr { - return FunctionExpr("array_get", [self, Helper.sendableToExpr(offset)]) + func arrayGet(_ offset: Int) -> FunctionExpression { + return FunctionExpression("array_get", [self, Helper.sendableToExpr(offset)]) } - func arrayGet(_ offsetExpr: Expr) -> FunctionExpr { - return FunctionExpr("array_get", [self, offsetExpr]) + func arrayGet(_ offsetExpr: Expression) -> FunctionExpression { + return FunctionExpression("array_get", [self, offsetExpr]) } - func gt(_ other: Expr) -> BooleanExpr { + func gt(_ other: Expression) -> BooleanExpr { return BooleanExpr("gt", [self, other]) } @@ -124,7 +124,7 @@ public extension Expr { // MARK: - Greater Than or Equal (gte) - func gte(_ other: Expr) -> BooleanExpr { + func gte(_ other: Expression) -> BooleanExpr { return BooleanExpr("gte", [self, other]) } @@ -135,7 +135,7 @@ public extension Expr { // MARK: - Less Than (lt) - func lt(_ other: Expr) -> BooleanExpr { + func lt(_ other: Expression) -> BooleanExpr { return BooleanExpr("lt", [self, other]) } @@ -146,7 +146,7 @@ public extension Expr { // MARK: - Less Than or Equal (lte) - func lte(_ other: Expr) -> BooleanExpr { + func lte(_ other: Expression) -> BooleanExpr { return BooleanExpr("lte", [self, other]) } @@ -157,7 +157,7 @@ public extension Expr { // MARK: - Equal (eq) - func eq(_ other: Expr) -> BooleanExpr { + func eq(_ other: Expression) -> BooleanExpr { return BooleanExpr("eq", [self, other]) } @@ -166,7 +166,7 @@ public extension Expr { return BooleanExpr("eq", [self, exprOther]) } - func neq(_ other: Expr) -> BooleanExpr { + func neq(_ other: Expression) -> BooleanExpr { return BooleanExpr("neq", [self, other]) } @@ -174,7 +174,7 @@ public extension Expr { return BooleanExpr("neq", [self, Helper.sendableToExpr(other)]) } - func eqAny(_ others: [Expr]) -> BooleanExpr { + func eqAny(_ others: [Expression]) -> BooleanExpr { return BooleanExpr("eq_any", [self, Helper.array(others)]) } @@ -182,7 +182,7 @@ public extension Expr { return BooleanExpr("eq_any", [self, Helper.array(others)]) } - func notEqAny(_ others: [Expr]) -> BooleanExpr { + func notEqAny(_ others: [Expression]) -> BooleanExpr { return BooleanExpr("not_eq_any", [self, Helper.array(others)]) } @@ -224,15 +224,15 @@ public extension Expr { // --- Added String Operations --- - func charLength() -> FunctionExpr { - return FunctionExpr("char_length", [self]) + func charLength() -> FunctionExpression { + return FunctionExpression("char_length", [self]) } func like(_ pattern: String) -> BooleanExpr { return BooleanExpr("like", [self, Helper.sendableToExpr(pattern)]) } - func like(_ pattern: Expr) -> BooleanExpr { + func like(_ pattern: Expression) -> BooleanExpr { return BooleanExpr("like", [self, pattern]) } @@ -240,7 +240,7 @@ public extension Expr { return BooleanExpr("regex_contains", [self, Helper.sendableToExpr(pattern)]) } - func regexContains(_ pattern: Expr) -> BooleanExpr { + func regexContains(_ pattern: Expression) -> BooleanExpr { return BooleanExpr("regex_contains", [self, pattern]) } @@ -248,7 +248,7 @@ public extension Expr { return BooleanExpr("regex_match", [self, Helper.sendableToExpr(pattern)]) } - func regexMatch(_ pattern: Expr) -> BooleanExpr { + func regexMatch(_ pattern: Expression) -> BooleanExpr { return BooleanExpr("regex_match", [self, pattern]) } @@ -256,7 +256,7 @@ public extension Expr { return BooleanExpr("str_contains", [self, Helper.sendableToExpr(substring)]) } - func strContains(_ expr: Expr) -> BooleanExpr { + func strContains(_ expr: Expression) -> BooleanExpr { return BooleanExpr("str_contains", [self, expr]) } @@ -264,7 +264,7 @@ public extension Expr { return BooleanExpr("starts_with", [self, Helper.sendableToExpr(prefix)]) } - func startsWith(_ prefix: Expr) -> BooleanExpr { + func startsWith(_ prefix: Expression) -> BooleanExpr { return BooleanExpr("starts_with", [self, prefix]) } @@ -272,102 +272,102 @@ public extension Expr { return BooleanExpr("ends_with", [self, Helper.sendableToExpr(suffix)]) } - func endsWith(_ suffix: Expr) -> BooleanExpr { + func endsWith(_ suffix: Expression) -> BooleanExpr { return BooleanExpr("ends_with", [self, suffix]) } - func lowercased() -> FunctionExpr { - return FunctionExpr("to_lower", [self]) + func lowercased() -> FunctionExpression { + return FunctionExpression("to_lower", [self]) } - func uppercased() -> FunctionExpr { - return FunctionExpr("to_upper", [self]) + func uppercased() -> FunctionExpression { + return FunctionExpression("to_upper", [self]) } - func trim() -> FunctionExpr { - return FunctionExpr("trim", [self]) + func trim() -> FunctionExpression { + return FunctionExpression("trim", [self]) } - func strConcat(_ secondString: Expr, _ otherStrings: Expr...) -> FunctionExpr { - return FunctionExpr("str_concat", [self, secondString] + otherStrings) + func strConcat(_ secondString: Expression, _ otherStrings: Expression...) -> FunctionExpression { + return FunctionExpression("str_concat", [self, secondString] + otherStrings) } - func strConcat(_ secondString: String, _ otherStrings: String...) -> FunctionExpr { + func strConcat(_ secondString: String, _ otherStrings: String...) -> FunctionExpression { let exprs = [self] + [Helper.sendableToExpr(secondString)] + otherStrings .map { Helper.sendableToExpr($0) } - return FunctionExpr("str_concat", exprs) + return FunctionExpression("str_concat", exprs) } - func reverse() -> FunctionExpr { - return FunctionExpr("reverse", [self]) + func reverse() -> FunctionExpression { + return FunctionExpression("reverse", [self]) } - func replaceFirst(_ find: String, _ replace: String) -> FunctionExpr { - return FunctionExpr( + func replaceFirst(_ find: String, _ replace: String) -> FunctionExpression { + return FunctionExpression( "replace_first", [self, Helper.sendableToExpr(find), Helper.sendableToExpr(replace)] ) } - func replaceFirst(_ find: Expr, _ replace: Expr) -> FunctionExpr { - return FunctionExpr("replace_first", [self, find, replace]) + func replaceFirst(_ find: Expression, _ replace: Expression) -> FunctionExpression { + return FunctionExpression("replace_first", [self, find, replace]) } - func replaceAll(_ find: String, _ replace: String) -> FunctionExpr { - return FunctionExpr( + func replaceAll(_ find: String, _ replace: String) -> FunctionExpression { + return FunctionExpression( "replace_all", [self, Helper.sendableToExpr(find), Helper.sendableToExpr(replace)] ) } - func replaceAll(_ find: Expr, _ replace: Expr) -> FunctionExpr { - return FunctionExpr("replace_all", [self, find, replace]) + func replaceAll(_ find: Expression, _ replace: Expression) -> FunctionExpression { + return FunctionExpression("replace_all", [self, find, replace]) } - func byteLength() -> FunctionExpr { - return FunctionExpr("byte_length", [self]) + func byteLength() -> FunctionExpression { + return FunctionExpression("byte_length", [self]) } - func substr(_ position: Int, _ length: Int? = nil) -> FunctionExpr { + func substr(_ position: Int, _ length: Int? = nil) -> FunctionExpression { let positionExpr = Helper.sendableToExpr(position) if let length = length { - return FunctionExpr("substr", [self, positionExpr, Helper.sendableToExpr(length)]) + return FunctionExpression("substr", [self, positionExpr, Helper.sendableToExpr(length)]) } else { - return FunctionExpr("substr", [self, positionExpr]) + return FunctionExpression("substr", [self, positionExpr]) } } - func substr(_ position: Expr, _ length: Expr? = nil) -> FunctionExpr { + func substr(_ position: Expression, _ length: Expression? = nil) -> FunctionExpression { if let length = length { - return FunctionExpr("substr", [self, position, length]) + return FunctionExpression("substr", [self, position, length]) } else { - return FunctionExpr("substr", [self, position]) + return FunctionExpression("substr", [self, position]) } } // --- Added Map Operations --- - func mapGet(_ subfield: String) -> FunctionExpr { - return FunctionExpr("map_get", [self, Constant(subfield)]) + func mapGet(_ subfield: String) -> FunctionExpression { + return FunctionExpression("map_get", [self, Constant(subfield)]) } - func mapRemove(_ key: String) -> FunctionExpr { - return FunctionExpr("map_remove", [self, Helper.sendableToExpr(key)]) + func mapRemove(_ key: String) -> FunctionExpression { + return FunctionExpression("map_remove", [self, Helper.sendableToExpr(key)]) } - func mapRemove(_ keyExpr: Expr) -> FunctionExpr { - return FunctionExpr("map_remove", [self, keyExpr]) + func mapRemove(_ keyExpr: Expression) -> FunctionExpression { + return FunctionExpression("map_remove", [self, keyExpr]) } func mapMerge(_ secondMap: [String: Sendable], - _ otherMaps: [String: Sendable]...) -> FunctionExpr { + _ otherMaps: [String: Sendable]...) -> FunctionExpression { let secondMapExpr = Helper.sendableToExpr(secondMap) let otherMapExprs = otherMaps.map { Helper.sendableToExpr($0) } - return FunctionExpr("map_merge", [self, secondMapExpr] + otherMapExprs) + return FunctionExpression("map_merge", [self, secondMapExpr] + otherMapExprs) } - func mapMerge(_ secondMap: Expr, _ otherMaps: Expr...) -> FunctionExpr { - return FunctionExpr("map_merge", [self, secondMap] + otherMaps) + func mapMerge(_ secondMap: Expression, _ otherMaps: Expression...) -> FunctionExpression { + return FunctionExpression("map_merge", [self, secondMap] + otherMaps) } // --- Added Aggregate Operations (on Expr) --- @@ -394,123 +394,123 @@ public extension Expr { // MARK: Logical min/max - func logicalMaximum(_ second: Expr, _ others: Expr...) -> FunctionExpr { - return FunctionExpr("logical_maximum", [self, second] + others) + func logicalMaximum(_ second: Expression, _ others: Expression...) -> FunctionExpression { + return FunctionExpression("logical_maximum", [self, second] + others) } - func logicalMaximum(_ second: Sendable, _ others: Sendable...) -> FunctionExpr { + func logicalMaximum(_ second: Sendable, _ others: Sendable...) -> FunctionExpression { let exprs = [self] + [Helper.sendableToExpr(second)] + others .map { Helper.sendableToExpr($0) } - return FunctionExpr("logical_maximum", exprs) + return FunctionExpression("logical_maximum", exprs) } - func logicalMinimum(_ second: Expr, _ others: Expr...) -> FunctionExpr { - return FunctionExpr("logical_minimum", [self, second] + others) + func logicalMinimum(_ second: Expression, _ others: Expression...) -> FunctionExpression { + return FunctionExpression("logical_minimum", [self, second] + others) } - func logicalMinimum(_ second: Sendable, _ others: Sendable...) -> FunctionExpr { + func logicalMinimum(_ second: Sendable, _ others: Sendable...) -> FunctionExpression { let exprs = [self] + [Helper.sendableToExpr(second)] + others .map { Helper.sendableToExpr($0) } - return FunctionExpr("logical_minimum", exprs) + return FunctionExpression("logical_minimum", exprs) } // MARK: Vector Operations - func vectorLength() -> FunctionExpr { - return FunctionExpr("vector_length", [self]) + func vectorLength() -> FunctionExpression { + return FunctionExpression("vector_length", [self]) } - func cosineDistance(_ other: Expr) -> FunctionExpr { - return FunctionExpr("cosine_distance", [self, other]) + func cosineDistance(_ other: Expression) -> FunctionExpression { + return FunctionExpression("cosine_distance", [self, other]) } - func cosineDistance(_ other: VectorValue) -> FunctionExpr { - return FunctionExpr("cosine_distance", [self, Helper.sendableToExpr(other)]) + func cosineDistance(_ other: VectorValue) -> FunctionExpression { + return FunctionExpression("cosine_distance", [self, Helper.sendableToExpr(other)]) } - func cosineDistance(_ other: [Double]) -> FunctionExpr { - return FunctionExpr("cosine_distance", [self, Helper.sendableToExpr(other)]) + func cosineDistance(_ other: [Double]) -> FunctionExpression { + return FunctionExpression("cosine_distance", [self, Helper.sendableToExpr(other)]) } - func dotProduct(_ other: Expr) -> FunctionExpr { - return FunctionExpr("dot_product", [self, other]) + func dotProduct(_ other: Expression) -> FunctionExpression { + return FunctionExpression("dot_product", [self, other]) } - func dotProduct(_ other: VectorValue) -> FunctionExpr { - return FunctionExpr("dot_product", [self, Helper.sendableToExpr(other)]) + func dotProduct(_ other: VectorValue) -> FunctionExpression { + return FunctionExpression("dot_product", [self, Helper.sendableToExpr(other)]) } - func dotProduct(_ other: [Double]) -> FunctionExpr { - return FunctionExpr("dot_product", [self, Helper.sendableToExpr(other)]) + func dotProduct(_ other: [Double]) -> FunctionExpression { + return FunctionExpression("dot_product", [self, Helper.sendableToExpr(other)]) } - func euclideanDistance(_ other: Expr) -> FunctionExpr { - return FunctionExpr("euclidean_distance", [self, other]) + func euclideanDistance(_ other: Expression) -> FunctionExpression { + return FunctionExpression("euclidean_distance", [self, other]) } - func euclideanDistance(_ other: VectorValue) -> FunctionExpr { - return FunctionExpr("euclidean_distance", [self, Helper.sendableToExpr(other)]) + func euclideanDistance(_ other: VectorValue) -> FunctionExpression { + return FunctionExpression("euclidean_distance", [self, Helper.sendableToExpr(other)]) } - func euclideanDistance(_ other: [Double]) -> FunctionExpr { - return FunctionExpr("euclidean_distance", [self, Helper.sendableToExpr(other)]) + func euclideanDistance(_ other: [Double]) -> FunctionExpression { + return FunctionExpression("euclidean_distance", [self, Helper.sendableToExpr(other)]) } - func manhattanDistance(_ other: Expr) -> FunctionExpr { - return FunctionExpr("manhattan_distance", [self, other]) + func manhattanDistance(_ other: Expression) -> FunctionExpression { + return FunctionExpression("manhattan_distance", [self, other]) } - func manhattanDistance(_ other: VectorValue) -> FunctionExpr { - return FunctionExpr("manhattan_distance", [self, Helper.sendableToExpr(other)]) + func manhattanDistance(_ other: VectorValue) -> FunctionExpression { + return FunctionExpression("manhattan_distance", [self, Helper.sendableToExpr(other)]) } - func manhattanDistance(_ other: [Double]) -> FunctionExpr { - return FunctionExpr("manhattan_distance", [self, Helper.sendableToExpr(other)]) + func manhattanDistance(_ other: [Double]) -> FunctionExpression { + return FunctionExpression("manhattan_distance", [self, Helper.sendableToExpr(other)]) } // MARK: Timestamp operations - func unixMicrosToTimestamp() -> FunctionExpr { - return FunctionExpr("unix_micros_to_timestamp", [self]) + func unixMicrosToTimestamp() -> FunctionExpression { + return FunctionExpression("unix_micros_to_timestamp", [self]) } - func timestampToUnixMicros() -> FunctionExpr { - return FunctionExpr("timestamp_to_unix_micros", [self]) + func timestampToUnixMicros() -> FunctionExpression { + return FunctionExpression("timestamp_to_unix_micros", [self]) } - func unixMillisToTimestamp() -> FunctionExpr { - return FunctionExpr("unix_millis_to_timestamp", [self]) + func unixMillisToTimestamp() -> FunctionExpression { + return FunctionExpression("unix_millis_to_timestamp", [self]) } - func timestampToUnixMillis() -> FunctionExpr { - return FunctionExpr("timestamp_to_unix_millis", [self]) + func timestampToUnixMillis() -> FunctionExpression { + return FunctionExpression("timestamp_to_unix_millis", [self]) } - func unixSecondsToTimestamp() -> FunctionExpr { - return FunctionExpr("unix_seconds_to_timestamp", [self]) + func unixSecondsToTimestamp() -> FunctionExpression { + return FunctionExpression("unix_seconds_to_timestamp", [self]) } - func timestampToUnixSeconds() -> FunctionExpr { - return FunctionExpr("timestamp_to_unix_seconds", [self]) + func timestampToUnixSeconds() -> FunctionExpression { + return FunctionExpression("timestamp_to_unix_seconds", [self]) } - func timestampAdd(_ unit: Expr, _ amount: Expr) -> FunctionExpr { - return FunctionExpr("timestamp_add", [self, unit, amount]) + func timestampAdd(_ unit: Expression, _ amount: Expression) -> FunctionExpression { + return FunctionExpression("timestamp_add", [self, unit, amount]) } - func timestampAdd(_ unit: TimeUnit, _ amount: Int) -> FunctionExpr { - return FunctionExpr( + func timestampAdd(_ unit: TimeUnit, _ amount: Int) -> FunctionExpression { + return FunctionExpression( "timestamp_add", [self, Helper.sendableToExpr(unit), Helper.sendableToExpr(amount)] ) } - func timestampSub(_ unit: Expr, _ amount: Expr) -> FunctionExpr { - return FunctionExpr("timestamp_sub", [self, unit, amount]) + func timestampSub(_ unit: Expression, _ amount: Expression) -> FunctionExpression { + return FunctionExpression("timestamp_sub", [self, unit, amount]) } - func timestampSub(_ unit: TimeUnit, _ amount: Int) -> FunctionExpr { - return FunctionExpr( + func timestampSub(_ unit: TimeUnit, _ amount: Int) -> FunctionExpression { + return FunctionExpression( "timestamp_sub", [self, Helper.sendableToExpr(unit), Helper.sendableToExpr(amount)] ) @@ -518,72 +518,72 @@ public extension Expr { // MARK: - Bitwise operations - func bitAnd(_ otherBits: Int) -> FunctionExpr { - return FunctionExpr("bit_and", [self, Helper.sendableToExpr(otherBits)]) + func bitAnd(_ otherBits: Int) -> FunctionExpression { + return FunctionExpression("bit_and", [self, Helper.sendableToExpr(otherBits)]) } - func bitAnd(_ otherBits: UInt8) -> FunctionExpr { - return FunctionExpr("bit_and", [self, Helper.sendableToExpr(otherBits)]) + func bitAnd(_ otherBits: UInt8) -> FunctionExpression { + return FunctionExpression("bit_and", [self, Helper.sendableToExpr(otherBits)]) } - func bitAnd(_ bitsExpression: Expr) -> FunctionExpr { - return FunctionExpr("bit_and", [self, bitsExpression]) + func bitAnd(_ bitsExpression: Expression) -> FunctionExpression { + return FunctionExpression("bit_and", [self, bitsExpression]) } - func bitOr(_ otherBits: Int) -> FunctionExpr { - return FunctionExpr("bit_or", [self, Helper.sendableToExpr(otherBits)]) + func bitOr(_ otherBits: Int) -> FunctionExpression { + return FunctionExpression("bit_or", [self, Helper.sendableToExpr(otherBits)]) } - func bitOr(_ otherBits: UInt8) -> FunctionExpr { - return FunctionExpr("bit_or", [self, Helper.sendableToExpr(otherBits)]) + func bitOr(_ otherBits: UInt8) -> FunctionExpression { + return FunctionExpression("bit_or", [self, Helper.sendableToExpr(otherBits)]) } - func bitOr(_ bitsExpression: Expr) -> FunctionExpr { - return FunctionExpr("bit_or", [self, bitsExpression]) + func bitOr(_ bitsExpression: Expression) -> FunctionExpression { + return FunctionExpression("bit_or", [self, bitsExpression]) } - func bitXor(_ otherBits: Int) -> FunctionExpr { - return FunctionExpr("bit_xor", [self, Helper.sendableToExpr(otherBits)]) + func bitXor(_ otherBits: Int) -> FunctionExpression { + return FunctionExpression("bit_xor", [self, Helper.sendableToExpr(otherBits)]) } - func bitXor(_ otherBits: UInt8) -> FunctionExpr { - return FunctionExpr("bit_xor", [self, Helper.sendableToExpr(otherBits)]) + func bitXor(_ otherBits: UInt8) -> FunctionExpression { + return FunctionExpression("bit_xor", [self, Helper.sendableToExpr(otherBits)]) } - func bitXor(_ bitsExpression: Expr) -> FunctionExpr { - return FunctionExpr("bit_xor", [self, bitsExpression]) + func bitXor(_ bitsExpression: Expression) -> FunctionExpression { + return FunctionExpression("bit_xor", [self, bitsExpression]) } - func bitNot() -> FunctionExpr { - return FunctionExpr("bit_not", [self]) + func bitNot() -> FunctionExpression { + return FunctionExpression("bit_not", [self]) } - func bitLeftShift(_ y: Int) -> FunctionExpr { - return FunctionExpr("bit_left_shift", [self, Helper.sendableToExpr(y)]) + func bitLeftShift(_ y: Int) -> FunctionExpression { + return FunctionExpression("bit_left_shift", [self, Helper.sendableToExpr(y)]) } - func bitLeftShift(_ numberExpr: Expr) -> FunctionExpr { - return FunctionExpr("bit_left_shift", [self, numberExpr]) + func bitLeftShift(_ numberExpr: Expression) -> FunctionExpression { + return FunctionExpression("bit_left_shift", [self, numberExpr]) } - func bitRightShift(_ y: Int) -> FunctionExpr { - return FunctionExpr("bit_right_shift", [self, Helper.sendableToExpr(y)]) + func bitRightShift(_ y: Int) -> FunctionExpression { + return FunctionExpression("bit_right_shift", [self, Helper.sendableToExpr(y)]) } - func bitRightShift(_ numberExpr: Expr) -> FunctionExpr { - return FunctionExpr("bit_right_shift", [self, numberExpr]) + func bitRightShift(_ numberExpr: Expression) -> FunctionExpression { + return FunctionExpression("bit_right_shift", [self, numberExpr]) } - func documentId() -> FunctionExpr { - return FunctionExpr("document_id", [self]) + func documentId() -> FunctionExpression { + return FunctionExpression("document_id", [self]) } - func ifError(_ catchExpr: Expr) -> FunctionExpr { - return FunctionExpr("if_error", [self, catchExpr]) + func ifError(_ catchExpr: Expression) -> FunctionExpression { + return FunctionExpression("if_error", [self, catchExpr]) } - func ifError(_ catchValue: Sendable) -> FunctionExpr { - return FunctionExpr("if_error", [self, Helper.sendableToExpr(catchValue)]) + func ifError(_ catchValue: Sendable) -> FunctionExpression { + return FunctionExpression("if_error", [self, Helper.sendableToExpr(catchValue)]) } // MARK: Sorting diff --git a/Firestore/Swift/Source/Helper/PipelineHelper.swift b/Firestore/Swift/Source/Helper/PipelineHelper.swift index 0d0e6b55d59..b5b38e8dbfe 100644 --- a/Firestore/Swift/Source/Helper/PipelineHelper.swift +++ b/Firestore/Swift/Source/Helper/PipelineHelper.swift @@ -13,12 +13,12 @@ // limitations under the License. enum Helper { - static func sendableToExpr(_ value: Sendable?) -> Expr { + static func sendableToExpr(_ value: Sendable?) -> Expression { guard let value = value else { return Constant.nil } - if let exprValue = value as? Expr { + if let exprValue = value as? Expression { return exprValue } else if let dictionaryValue = value as? [String: Sendable?] { return map(dictionaryValue) @@ -31,8 +31,8 @@ enum Helper { } } - static func selectablesToMap(selectables: [Selectable]) -> [String: Expr] { - let exprMap = selectables.reduce(into: [String: Expr]()) { result, selectable in + static func selectablesToMap(selectables: [Selectable]) -> [String: Expression] { + let exprMap = selectables.reduce(into: [String: Expression]()) { result, selectable in guard let value = selectable as? SelectableWrapper else { fatalError("Selectable class must conform to SelectableWrapper.") } @@ -41,20 +41,20 @@ enum Helper { return exprMap } - static func map(_ elements: [String: Sendable?]) -> FunctionExpr { - var result: [Expr] = [] + static func map(_ elements: [String: Sendable?]) -> FunctionExpression { + var result: [Expression] = [] for (key, value) in elements { result.append(Constant(key)) result.append(sendableToExpr(value)) } - return FunctionExpr("map", result) + return FunctionExpression("map", result) } - static func array(_ elements: [Sendable?]) -> FunctionExpr { + static func array(_ elements: [Sendable?]) -> FunctionExpression { let transformedElements = elements.map { element in sendableToExpr(element) } - return FunctionExpr("array", transformedElements) + return FunctionExpression("array", transformedElements) } // This function is used to convert Swift type into Objective-C type. @@ -63,7 +63,7 @@ enum Helper { return Constant.nil.bridge } - if let exprValue = value as? Expr { + if let exprValue = value as? Expression { return exprValue.toBridge() } else if let aggregateFunctionValue = value as? AggregateFunction { return aggregateFunctionValue.toBridge() diff --git a/Firestore/Swift/Source/PipelineWrapper.swift b/Firestore/Swift/Source/PipelineWrapper.swift index a057c2e4ea2..f0310a535cc 100644 --- a/Firestore/Swift/Source/PipelineWrapper.swift +++ b/Firestore/Swift/Source/PipelineWrapper.swift @@ -22,5 +22,5 @@ protocol AggregateBridgeWrapper { protocol SelectableWrapper: Sendable { var alias: String { get } - var expr: Expr { get } + var expr: Expression { get } } diff --git a/Firestore/Swift/Source/SwiftAPI/Pipeline/Aggregation/AggregateFunction.swift b/Firestore/Swift/Source/SwiftAPI/Pipeline/Aggregation/AggregateFunction.swift index 6d7e05098a9..3adf83239db 100644 --- a/Firestore/Swift/Source/SwiftAPI/Pipeline/Aggregation/AggregateFunction.swift +++ b/Firestore/Swift/Source/SwiftAPI/Pipeline/Aggregation/AggregateFunction.swift @@ -22,9 +22,9 @@ public class AggregateFunction: AggregateBridgeWrapper, @unchecked Sendable { let bridge: AggregateFunctionBridge let functionName: String - let args: [Expr] + let args: [Expression] - public init(_ functionName: String, _ args: [Expr]) { + public init(_ functionName: String, _ args: [Expression]) { self.functionName = functionName self.args = args bridge = AggregateFunctionBridge( @@ -34,7 +34,7 @@ public class AggregateFunction: AggregateBridgeWrapper, @unchecked Sendable { ) } - public func `as`(_ name: String) -> AggregateWithAlias { - return AggregateWithAlias(aggregate: self, alias: name) + public func `as`(_ name: String) -> AliasedAggregate { + return AliasedAggregate(aggregate: self, alias: name) } } diff --git a/Firestore/Swift/Source/SwiftAPI/Pipeline/Aggregation/AggregateWithAlias.swift b/Firestore/Swift/Source/SwiftAPI/Pipeline/Aggregation/AliasedAggregate.swift similarity index 94% rename from Firestore/Swift/Source/SwiftAPI/Pipeline/Aggregation/AggregateWithAlias.swift rename to Firestore/Swift/Source/SwiftAPI/Pipeline/Aggregation/AliasedAggregate.swift index 8a1871907c6..5c16126c6a8 100644 --- a/Firestore/Swift/Source/SwiftAPI/Pipeline/Aggregation/AggregateWithAlias.swift +++ b/Firestore/Swift/Source/SwiftAPI/Pipeline/Aggregation/AliasedAggregate.swift @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -public struct AggregateWithAlias { +public struct AliasedAggregate { public let aggregate: AggregateFunction public let alias: String } diff --git a/Firestore/Swift/Source/SwiftAPI/Pipeline/ExprWithAlias.swift b/Firestore/Swift/Source/SwiftAPI/Pipeline/AliasedExpression.swift similarity index 81% rename from Firestore/Swift/Source/SwiftAPI/Pipeline/ExprWithAlias.swift rename to Firestore/Swift/Source/SwiftAPI/Pipeline/AliasedExpression.swift index 247427f2fd8..4c026ec34e7 100644 --- a/Firestore/Swift/Source/SwiftAPI/Pipeline/ExprWithAlias.swift +++ b/Firestore/Swift/Source/SwiftAPI/Pipeline/AliasedExpression.swift @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -public struct ExprWithAlias: Selectable, SelectableWrapper, Sendable { +public struct AliasedExpression: Selectable, SelectableWrapper, Sendable { public var alias: String - public var expr: Expr + public var expr: Expression - init(_ expr: Expr, _ alias: String) { + init(_ expr: Expression, _ alias: String) { self.alias = alias self.expr = expr } diff --git a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr.swift b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expression.swift similarity index 91% rename from Firestore/Swift/Source/SwiftAPI/Pipeline/Expr.swift rename to Firestore/Swift/Source/SwiftAPI/Pipeline/Expression.swift index d05c6a4c251..1a91fb005b0 100644 --- a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr.swift +++ b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expression.swift @@ -19,8 +19,7 @@ #endif // SWIFT_PACKAGE import Foundation -// TODO: the implementation of `Expr` is not complete -public protocol Expr: Sendable { +public protocol Expression: Sendable { /// Assigns an alias to this expression. /// /// Aliases are useful for renaming fields in the output of a stage or for giving meaningful @@ -33,7 +32,7 @@ public protocol Expr: Sendable { /// /// - Parameter name: The alias to assign to this expression. /// - Returns: A new `ExprWithAlias` wrapping this expression with the alias. - func `as`(_ name: String) -> ExprWithAlias + func `as`(_ name: String) -> AliasedExpression // --- Added Mathematical Operations --- @@ -50,8 +49,8 @@ public protocol Expr: Sendable { /// ``` /// /// - Parameter value: Expr` values to add. - /// - Returns: A new `FunctionExpr` representing the addition operation. - func add(_ value: Expr) -> FunctionExpr + /// - Returns: A new `FunctionExpression` representing the addition operation. + func add(_ value: Expression) -> FunctionExpression /// Creates an expression that adds this expression to one or more literal values. /// Assumes `self` and all parameters evaluate to compatible types for addition. @@ -65,8 +64,8 @@ public protocol Expr: Sendable { /// ``` /// /// - Parameter value: Expr` value to add. - /// - Returns: A new `FunctionExpr` representing the addition operation. - func add(_ value: Sendable) -> FunctionExpr + /// - Returns: A new `FunctionExpression` representing the addition operation. + func add(_ value: Sendable) -> FunctionExpression /// Creates an expression that subtracts another expression from this expression. /// Assumes `self` and `other` evaluate to numeric types. @@ -78,7 +77,7 @@ public protocol Expr: Sendable { /// /// - Parameter other: The `Expr` (evaluating to a number) to subtract from this expression. /// - Returns: A new `FunctionExpr` representing the subtraction operation. - func subtract(_ other: Expr) -> FunctionExpr + func subtract(_ other: Expression) -> FunctionExpression /// Creates an expression that subtracts a literal value from this expression. /// Assumes `self` evaluates to a numeric type. @@ -90,7 +89,7 @@ public protocol Expr: Sendable { /// /// - Parameter other: The `Sendable` literal (numeric) value to subtract from this expression. /// - Returns: A new `FunctionExpr` representing the subtraction operation. - func subtract(_ other: Sendable) -> FunctionExpr + func subtract(_ other: Sendable) -> FunctionExpression /// Creates an expression that multiplies this expression by one or more other expressions. /// Assumes `self` and all parameters evaluate to numeric types. @@ -105,7 +104,7 @@ public protocol Expr: Sendable { /// /// - Parameter value: `Expr` value to multiply by. /// - Returns: A new `FunctionExpr` representing the multiplication operation. - func multiply(_ value: Expr) -> FunctionExpr + func multiply(_ value: Expression) -> FunctionExpression /// Creates an expression that multiplies this expression by one or more literal values. /// Assumes `self` evaluates to a numeric type. @@ -120,7 +119,7 @@ public protocol Expr: Sendable { /// /// - Parameter value: `Sendable` literal value to multiply by. /// - Returns: A new `FunctionExpr` representing the multiplication operation. - func multiply(_ value: Sendable) -> FunctionExpr + func multiply(_ value: Sendable) -> FunctionExpression /// Creates an expression that divides this expression by another expression. /// Assumes `self` and `other` evaluate to numeric types. @@ -132,7 +131,7 @@ public protocol Expr: Sendable { /// /// - Parameter other: The `Expr` (evaluating to a number) to divide by. /// - Returns: A new `FunctionExpr` representing the division operation. - func divide(_ other: Expr) -> FunctionExpr + func divide(_ other: Expression) -> FunctionExpression /// Creates an expression that divides this expression by a literal value. /// Assumes `self` evaluates to a numeric type. @@ -144,7 +143,7 @@ public protocol Expr: Sendable { /// /// - Parameter other: The `Sendable` literal (numeric) value to divide by. /// - Returns: A new `FunctionExpr` representing the division operation. - func divide(_ other: Sendable) -> FunctionExpr + func divide(_ other: Sendable) -> FunctionExpression /// Creates an expression that calculates the modulo (remainder) of dividing this expression by /// another expression. @@ -157,7 +156,7 @@ public protocol Expr: Sendable { /// /// - Parameter other: The `Expr` (evaluating to a number) to use as the divisor. /// - Returns: A new `FunctionExpr` representing the modulo operation. - func mod(_ other: Expr) -> FunctionExpr + func mod(_ other: Expression) -> FunctionExpression /// Creates an expression that calculates the modulo (remainder) of dividing this expression by a /// literal value. @@ -170,7 +169,7 @@ public protocol Expr: Sendable { /// /// - Parameter other: The `Sendable` literal (numeric) value to use as the divisor. /// - Returns: A new `FunctionExpr` representing the modulo operation. - func mod(_ other: Sendable) -> FunctionExpr + func mod(_ other: Sendable) -> FunctionExpression // --- Added Array Operations --- @@ -186,7 +185,7 @@ public protocol Expr: Sendable { /// - Parameter otherArrays: Optional additional `Expr` values (evaluating to arrays) to /// concatenate. /// - Returns: A new `FunctionExpr` representing the concatenated array. - func arrayConcat(_ secondArray: Expr, _ otherArrays: Expr...) -> FunctionExpr + func arrayConcat(_ secondArray: Expression, _ otherArrays: Expression...) -> FunctionExpression /// Creates an expression that concatenates an array expression (from `self`) with one or more /// array literals. @@ -200,7 +199,7 @@ public protocol Expr: Sendable { /// - Parameter otherArrays: Optional additional array literals of `Sendable` values to /// concatenate. /// - Returns: A new `FunctionExpr` representing the concatenated array. - func arrayConcat(_ secondArray: [Sendable], _ otherArrays: [Sendable]...) -> FunctionExpr + func arrayConcat(_ secondArray: [Sendable], _ otherArrays: [Sendable]...) -> FunctionExpression /// Creates an expression that checks if an array (from `self`) contains a specific element /// expression. @@ -213,7 +212,7 @@ public protocol Expr: Sendable { /// /// - Parameter element: The `Expr` representing the element to search for in the array. /// - Returns: A new `BooleanExpr` representing the 'array_contains' comparison. - func arrayContains(_ element: Expr) -> BooleanExpr + func arrayContains(_ element: Expression) -> BooleanExpr /// Creates an expression that checks if an array (from `self`) contains a specific literal /// element. @@ -241,7 +240,7 @@ public protocol Expr: Sendable { /// - Parameter values: A list of `Expr` elements to check for in the array represented /// by `self`. /// - Returns: A new `BooleanExpr` representing the 'array_contains_all' comparison. - func arrayContainsAll(_ values: [Expr]) -> BooleanExpr + func arrayContainsAll(_ values: [Expression]) -> BooleanExpr /// Creates an expression that checks if an array (from `self`) contains all the specified literal /// elements. @@ -269,7 +268,7 @@ public protocol Expr: Sendable { /// - Parameter values: A list of `Expr` elements to check for in the array represented /// by `self`. /// - Returns: A new `BooleanExpr` representing the 'array_contains_any' comparison. - func arrayContainsAny(_ values: [Expr]) -> BooleanExpr + func arrayContainsAny(_ values: [Expression]) -> BooleanExpr /// Creates an expression that checks if an array (from `self`) contains any of the specified /// literal elements. @@ -294,7 +293,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the length of the array. - func arrayLength() -> FunctionExpr + func arrayLength() -> FunctionExpression /// Creates an expression that accesses an element in an array (from `self`) at the specified /// integer offset. @@ -311,7 +310,7 @@ public protocol Expr: Sendable { /// /// - Parameter offset: The literal `Int` offset of the element to return. /// - Returns: A new `FunctionExpr` representing the 'arrayGet' operation. - func arrayGet(_ offset: Int) -> FunctionExpr + func arrayGet(_ offset: Int) -> FunctionExpression /// Creates an expression that accesses an element in an array (from `self`) at the offset /// specified by an expression. @@ -327,7 +326,7 @@ public protocol Expr: Sendable { /// - Parameter offsetExpr: An `Expr` (evaluating to an Int) representing the offset of the /// element to return. /// - Returns: A new `FunctionExpr` representing the 'arrayGet' operation. - func arrayGet(_ offsetExpr: Expr) -> FunctionExpr + func arrayGet(_ offsetExpr: Expression) -> FunctionExpression // MARK: Equality with Sendable @@ -342,7 +341,7 @@ public protocol Expr: Sendable { /// /// - Parameter others: A list of `Expr` values to check against. /// - Returns: A new `BooleanExpr` representing the 'IN' comparison (eq_any). - func eqAny(_ others: [Expr]) -> BooleanExpr + func eqAny(_ others: [Expression]) -> BooleanExpr /// Creates an expression that checks if this expression is equal to any of the provided literal /// values. @@ -368,7 +367,7 @@ public protocol Expr: Sendable { /// /// - Parameter others: A list of `Expr` values to check against. /// - Returns: A new `BooleanExpr` representing the 'NOT IN' comparison (not_eq_any). - func notEqAny(_ others: [Expr]) -> BooleanExpr + func notEqAny(_ others: [Expression]) -> BooleanExpr /// Creates an expression that checks if this expression is not equal to any of the provided /// literal values. @@ -478,7 +477,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the length of the string. - func charLength() -> FunctionExpr + func charLength() -> FunctionExpression /// Creates an expression that performs a case-sensitive string comparison using wildcards against /// a literal pattern. @@ -505,7 +504,7 @@ public protocol Expr: Sendable { /// - Parameter pattern: An `Expr` (evaluating to a string) representing the pattern to search /// for. /// - Returns: A new `FunctionExpr` representing the 'like' comparison. - func like(_ pattern: Expr) -> BooleanExpr + func like(_ pattern: Expression) -> BooleanExpr /// Creates an expression that checks if a string (from `self`) contains a specified regular /// expression literal as a substring. @@ -532,7 +531,7 @@ public protocol Expr: Sendable { /// - Parameter pattern: An `Expr` (evaluating to a string) representing the regular expression to /// use for the search. /// - Returns: A new `BooleanExpr` representing the 'regex_contains' comparison. - func regexContains(_ pattern: Expr) -> BooleanExpr + func regexContains(_ pattern: Expression) -> BooleanExpr /// Creates an expression that checks if a string (from `self`) matches a specified regular /// expression literal entirely. @@ -559,7 +558,7 @@ public protocol Expr: Sendable { /// - Parameter pattern: An `Expr` (evaluating to a string) representing the regular expression to /// use for the match. /// - Returns: A new `BooleanExpr` representing the regular expression match. - func regexMatch(_ pattern: Expr) -> BooleanExpr + func regexMatch(_ pattern: Expression) -> BooleanExpr /// Creates an expression that checks if a string (from `self`) contains a specified literal /// substring (case-sensitive). @@ -585,7 +584,7 @@ public protocol Expr: Sendable { /// /// - Parameter expr: An `Expr` (evaluating to a string) representing the substring to search for. /// - Returns: A new `BooleanExpr` representing the 'str_contains' comparison. - func strContains(_ expr: Expr) -> BooleanExpr + func strContains(_ expr: Expression) -> BooleanExpr /// Creates an expression that checks if a string (from `self`) starts with a given literal prefix /// (case-sensitive). @@ -611,7 +610,7 @@ public protocol Expr: Sendable { /// /// - Parameter prefix: An `Expr` (evaluating to a string) representing the prefix to check for. /// - Returns: A new `BooleanExpr` representing the 'starts_with' comparison. - func startsWith(_ prefix: Expr) -> BooleanExpr + func startsWith(_ prefix: Expression) -> BooleanExpr /// Creates an expression that checks if a string (from `self`) ends with a given literal suffix /// (case-sensitive). @@ -637,7 +636,7 @@ public protocol Expr: Sendable { /// /// - Parameter suffix: An `Expr` (evaluating to a string) representing the suffix to check for. /// - Returns: A new `BooleanExpr` representing the 'ends_with' comparison. - func endsWith(_ suffix: Expr) -> BooleanExpr + func endsWith(_ suffix: Expression) -> BooleanExpr /// Creates an expression that converts a string (from `self`) to lowercase. /// Assumes `self` evaluates to a string. @@ -648,7 +647,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the lowercase string. - func lowercased() -> FunctionExpr + func lowercased() -> FunctionExpression /// Creates an expression that converts a string (from `self`) to uppercase. /// Assumes `self` evaluates to a string. @@ -659,7 +658,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the uppercase string. - func uppercased() -> FunctionExpr + func uppercased() -> FunctionExpression /// Creates an expression that removes leading and trailing whitespace from a string (from /// `self`). @@ -671,7 +670,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the trimmed string. - func trim() -> FunctionExpr + func trim() -> FunctionExpression /// Creates an expression that concatenates this string expression with other string expressions. /// Assumes `self` evaluates to a string. @@ -684,7 +683,7 @@ public protocol Expr: Sendable { /// - Parameter secondString: An `Expr` (evaluating to a string) to concatenate. /// - Parameter otherStrings: Optional additional `Expr` (evaluating to strings) to concatenate. /// - Returns: A new `FunctionExpr` representing the concatenated string. - func strConcat(_ secondString: Expr, _ otherStrings: Expr...) -> FunctionExpr + func strConcat(_ secondString: Expression, _ otherStrings: Expression...) -> FunctionExpression /// Creates an expression that concatenates this string expression with other string literals. /// Assumes `self` evaluates to a string. @@ -697,7 +696,7 @@ public protocol Expr: Sendable { /// - Parameter secondString: A string literal to concatenate. /// - Parameter otherStrings: Optional additional string literals to concatenate. /// - Returns: A new `FunctionExpr` representing the concatenated string. - func strConcat(_ secondString: String, _ otherStrings: String...) -> FunctionExpr + func strConcat(_ secondString: String, _ otherStrings: String...) -> FunctionExpression /// Creates an expression that reverses this string expression. /// Assumes `self` evaluates to a string. @@ -708,7 +707,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the reversed string. - func reverse() -> FunctionExpr + func reverse() -> FunctionExpression /// Creates an expression that replaces the first occurrence of a literal substring within this /// string expression with another literal substring. @@ -722,7 +721,7 @@ public protocol Expr: Sendable { /// - Parameter find: The literal string substring to search for. /// - Parameter replace: The literal string substring to replace the first occurrence with. /// - Returns: A new `FunctionExpr` representing the string with the first occurrence replaced. - func replaceFirst(_ find: String, _ replace: String) -> FunctionExpr + func replaceFirst(_ find: String, _ replace: String) -> FunctionExpression /// Creates an expression that replaces the first occurrence of a substring (from an expression) /// within this string expression with another substring (from an expression). @@ -737,7 +736,7 @@ public protocol Expr: Sendable { /// - Parameter replace: An `Expr` (evaluating to a string) for the substring to replace the first /// occurrence with. /// - Returns: A new `FunctionExpr` representing the string with the first occurrence replaced. - func replaceFirst(_ find: Expr, _ replace: Expr) -> FunctionExpr + func replaceFirst(_ find: Expression, _ replace: Expression) -> FunctionExpression /// Creates an expression that replaces all occurrences of a literal substring within this string /// expression with another literal substring. @@ -751,7 +750,7 @@ public protocol Expr: Sendable { /// - Parameter find: The literal string substring to search for. /// - Parameter replace: The literal string substring to replace all occurrences with. /// - Returns: A new `FunctionExpr` representing the string with all occurrences replaced. - func replaceAll(_ find: String, _ replace: String) -> FunctionExpr + func replaceAll(_ find: String, _ replace: String) -> FunctionExpression /// Creates an expression that replaces all occurrences of a substring (from an expression) within /// this string expression with another substring (from an expression). @@ -766,7 +765,7 @@ public protocol Expr: Sendable { /// - Parameter replace: An `Expr` (evaluating to a string) for the substring to replace all /// occurrences with. /// - Returns: A new `FunctionExpr` representing the string with all occurrences replaced. - func replaceAll(_ find: Expr, _ replace: Expr) -> FunctionExpr + func replaceAll(_ find: Expression, _ replace: Expression) -> FunctionExpression /// Creates an expression that calculates the length of this string or bytes expression in bytes. /// Assumes `self` evaluates to a string or bytes. @@ -780,7 +779,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the length in bytes. - func byteLength() -> FunctionExpr + func byteLength() -> FunctionExpression /// Creates an expression that returns a substring of this expression (String or Bytes) using /// literal integers for position and optional length. @@ -799,7 +798,7 @@ public protocol Expr: Sendable { /// - Parameter position: Literal `Int` index of the first character/byte. /// - Parameter length: Optional literal `Int` length of the substring. If `nil`, goes to the end. /// - Returns: A new `FunctionExpr` representing the substring. - func substr(_ position: Int, _ length: Int?) -> FunctionExpr + func substr(_ position: Int, _ length: Int?) -> FunctionExpression /// Creates an expression that returns a substring of this expression (String or Bytes) using /// expressions for position and optional length. @@ -821,7 +820,7 @@ public protocol Expr: Sendable { /// - Parameter length: Optional `Expr` (evaluating to an Int) for the length of the substring. If /// `nil`, goes to the end. /// - Returns: A new `FunctionExpr` representing the substring. - func substr(_ position: Expr, _ length: Expr?) -> FunctionExpr + func substr(_ position: Expression, _ length: Expression?) -> FunctionExpression // MARK: Map Operations @@ -835,7 +834,7 @@ public protocol Expr: Sendable { /// /// - Parameter subfield: The literal string key to access in the map. /// - Returns: A new `FunctionExpr` representing the value associated with the given key. - func mapGet(_ subfield: String) -> FunctionExpr + func mapGet(_ subfield: String) -> FunctionExpression /// Creates an expression that removes a key (specified by a literal string) from the map produced /// by evaluating this expression. @@ -850,7 +849,7 @@ public protocol Expr: Sendable { /// /// - Parameter key: The literal string key to remove from the map. /// - Returns: A new `FunctionExpr` representing the 'map_remove' operation. - func mapRemove(_ key: String) -> FunctionExpr + func mapRemove(_ key: String) -> FunctionExpression /// Creates an expression that removes a key (specified by an expression) from the map produced by /// evaluating this expression. @@ -866,7 +865,7 @@ public protocol Expr: Sendable { /// - Parameter keyExpr: An `Expr` (evaluating to a string) representing the key to remove from /// the map. /// - Returns: A new `FunctionExpr` representing the 'map_remove' operation. - func mapRemove(_ keyExpr: Expr) -> FunctionExpr + func mapRemove(_ keyExpr: Expression) -> FunctionExpression /// Creates an expression that merges this map with multiple other map literals. /// Assumes `self` evaluates to a Map. Later maps overwrite keys from earlier maps. @@ -883,7 +882,8 @@ public protocol Expr: Sendable { /// - Parameter otherMaps: Optional additional maps (dictionary literals with `Sendable` values) /// to merge. /// - Returns: A new `FunctionExpr` representing the 'map_merge' operation. - func mapMerge(_ secondMap: [String: Sendable], _ otherMaps: [String: Sendable]...) -> FunctionExpr + func mapMerge(_ secondMap: [String: Sendable], _ otherMaps: [String: Sendable]...) + -> FunctionExpression /// Creates an expression that merges this map with multiple other map expressions. /// Assumes `self` and other arguments evaluate to Maps. Later maps overwrite keys from earlier @@ -899,7 +899,7 @@ public protocol Expr: Sendable { /// - Parameter secondMap: A required second `Expr` (evaluating to a Map) to merge. /// - Parameter otherMaps: Optional additional `Expr` (evaluating to Maps) to merge. /// - Returns: A new `FunctionExpr` representing the 'map_merge' operation. - func mapMerge(_ secondMap: Expr, _ otherMaps: Expr...) -> FunctionExpr + func mapMerge(_ secondMap: Expression, _ otherMaps: Expression...) -> FunctionExpression // MARK: Aggregations @@ -973,7 +973,7 @@ public protocol Expr: Sendable { /// - Parameter second: The second `Expr` to compare with. /// - Parameter others: Optional additional `Expr` values to compare with. /// - Returns: A new `FunctionExpr` representing the logical max operation. - func logicalMaximum(_ second: Expr, _ others: Expr...) -> FunctionExpr + func logicalMaximum(_ second: Expression, _ others: Expression...) -> FunctionExpression /// Creates an expression that returns the larger value between this expression and other literal /// values, based on Firestore's value type ordering. @@ -986,7 +986,7 @@ public protocol Expr: Sendable { /// - Parameter second: The second literal `Sendable` value to compare with. /// - Parameter others: Optional additional literal `Sendable` values to compare with. /// - Returns: A new `FunctionExpr` representing the logical max operation. - func logicalMaximum(_ second: Sendable, _ others: Sendable...) -> FunctionExpr + func logicalMaximum(_ second: Sendable, _ others: Sendable...) -> FunctionExpression /// Creates an expression that returns the smaller value between this expression and other /// expressions, based on Firestore's value type ordering. @@ -999,7 +999,7 @@ public protocol Expr: Sendable { /// - Parameter second: The second `Expr` to compare with. /// - Parameter others: Optional additional `Expr` values to compare with. /// - Returns: A new `FunctionExpr` representing the logical min operation. - func logicalMinimum(_ second: Expr, _ others: Expr...) -> FunctionExpr + func logicalMinimum(_ second: Expression, _ others: Expression...) -> FunctionExpression /// Creates an expression that returns the smaller value between this expression and other literal /// values, based on Firestore's value type ordering. @@ -1012,7 +1012,7 @@ public protocol Expr: Sendable { /// - Parameter second: The second literal `Sendable` value to compare with. /// - Parameter others: Optional additional literal `Sendable` values to compare with. /// - Returns: A new `FunctionExpr` representing the logical min operation. - func logicalMinimum(_ second: Sendable, _ others: Sendable...) -> FunctionExpr + func logicalMinimum(_ second: Sendable, _ others: Sendable...) -> FunctionExpression // MARK: Vector Operations @@ -1026,7 +1026,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the length of the vector. - func vectorLength() -> FunctionExpr + func vectorLength() -> FunctionExpression /// Calculates the cosine distance between this vector expression and another vector expression. /// Assumes both `self` and `other` evaluate to Vectors. @@ -1038,7 +1038,7 @@ public protocol Expr: Sendable { /// /// - Parameter other: The other vector as an `Expr` to compare against. /// - Returns: A new `FunctionExpr` representing the cosine distance. - func cosineDistance(_ other: Expr) -> FunctionExpr + func cosineDistance(_ other: Expression) -> FunctionExpression /// Calculates the cosine distance between this vector expression and another vector literal /// (`VectorValue`). @@ -1051,7 +1051,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter other: The other vector as a `VectorValue` to compare against. /// - Returns: A new `FunctionExpr` representing the cosine distance. - func cosineDistance(_ other: VectorValue) -> FunctionExpr + func cosineDistance(_ other: VectorValue) -> FunctionExpression /// Calculates the cosine distance between this vector expression and another vector literal /// (`[Double]`). @@ -1063,7 +1063,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter other: The other vector as `[Double]` to compare against. /// - Returns: A new `FunctionExpr` representing the cosine distance. - func cosineDistance(_ other: [Double]) -> FunctionExpr + func cosineDistance(_ other: [Double]) -> FunctionExpression /// Calculates the dot product between this vector expression and another vector expression. /// Assumes both `self` and `other` evaluate to Vectors. @@ -1075,7 +1075,7 @@ public protocol Expr: Sendable { /// /// - Parameter other: The other vector as an `Expr` to calculate with. /// - Returns: A new `FunctionExpr` representing the dot product. - func dotProduct(_ other: Expr) -> FunctionExpr + func dotProduct(_ other: Expression) -> FunctionExpression /// Calculates the dot product between this vector expression and another vector literal /// (`VectorValue`). @@ -1088,7 +1088,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter other: The other vector as a `VectorValue` to calculate with. /// - Returns: A new `FunctionExpr` representing the dot product. - func dotProduct(_ other: VectorValue) -> FunctionExpr + func dotProduct(_ other: VectorValue) -> FunctionExpression /// Calculates the dot product between this vector expression and another vector literal /// (`[Double]`). @@ -1100,7 +1100,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter other: The other vector as `[Double]` to calculate with. /// - Returns: A new `FunctionExpr` representing the dot product. - func dotProduct(_ other: [Double]) -> FunctionExpr + func dotProduct(_ other: [Double]) -> FunctionExpression /// Calculates the Euclidean distance between this vector expression and another vector /// expression. @@ -1113,7 +1113,7 @@ public protocol Expr: Sendable { /// /// - Parameter other: The other vector as an `Expr` to compare against. /// - Returns: A new `FunctionExpr` representing the Euclidean distance. - func euclideanDistance(_ other: Expr) -> FunctionExpr + func euclideanDistance(_ other: Expression) -> FunctionExpression /// Calculates the Euclidean distance between this vector expression and another vector literal /// (`VectorValue`). @@ -1125,7 +1125,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter other: The other vector as a `VectorValue` to compare against. /// - Returns: A new `FunctionExpr` representing the Euclidean distance. - func euclideanDistance(_ other: VectorValue) -> FunctionExpr + func euclideanDistance(_ other: VectorValue) -> FunctionExpression /// Calculates the Euclidean distance between this vector expression and another vector literal /// (`[Double]`). @@ -1137,7 +1137,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter other: The other vector as `[Double]` to compare against. /// - Returns: A new `FunctionExpr` representing the Euclidean distance. - func euclideanDistance(_ other: [Double]) -> FunctionExpr + func euclideanDistance(_ other: [Double]) -> FunctionExpression /// Calculates the Manhattan (L1) distance between this vector expression and another vector /// expression. @@ -1152,7 +1152,7 @@ public protocol Expr: Sendable { /// /// - Parameter other: The other vector as an `Expr` to compare against. /// - Returns: A new `FunctionExpr` representing the Manhattan distance. - func manhattanDistance(_ other: Expr) -> FunctionExpr + func manhattanDistance(_ other: Expression) -> FunctionExpression /// Calculates the Manhattan (L1) distance between this vector expression and another vector /// literal (`VectorValue`). @@ -1164,7 +1164,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter other: The other vector as a `VectorValue` to compare against. /// - Returns: A new `FunctionExpr` representing the Manhattan distance. - func manhattanDistance(_ other: VectorValue) -> FunctionExpr + func manhattanDistance(_ other: VectorValue) -> FunctionExpression /// Calculates the Manhattan (L1) distance between this vector expression and another vector /// literal (`[Double]`). @@ -1177,7 +1177,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter other: The other vector as `[Double]` to compare against. /// - Returns: A new `FunctionExpr` representing the Manhattan distance. - func manhattanDistance(_ other: [Double]) -> FunctionExpr + func manhattanDistance(_ other: [Double]) -> FunctionExpression // MARK: Timestamp operations @@ -1191,7 +1191,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the timestamp. - func unixMicrosToTimestamp() -> FunctionExpr + func unixMicrosToTimestamp() -> FunctionExpression /// Creates an expression that converts this timestamp expression to the number of microseconds /// since the Unix epoch. Assumes `self` evaluates to a Timestamp. @@ -1202,7 +1202,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the number of microseconds. - func timestampToUnixMicros() -> FunctionExpr + func timestampToUnixMicros() -> FunctionExpression /// Creates an expression that interprets this expression (evaluating to a number) as milliseconds /// since the Unix epoch and returns a timestamp. @@ -1214,7 +1214,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the timestamp. - func unixMillisToTimestamp() -> FunctionExpr + func unixMillisToTimestamp() -> FunctionExpression /// Creates an expression that converts this timestamp expression to the number of milliseconds /// since the Unix epoch. Assumes `self` evaluates to a Timestamp. @@ -1225,7 +1225,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the number of milliseconds. - func timestampToUnixMillis() -> FunctionExpr + func timestampToUnixMillis() -> FunctionExpression /// Creates an expression that interprets this expression (evaluating to a number) as seconds /// since the Unix epoch and returns a timestamp. @@ -1237,7 +1237,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the timestamp. - func unixSecondsToTimestamp() -> FunctionExpr + func unixSecondsToTimestamp() -> FunctionExpression /// Creates an expression that converts this timestamp expression to the number of seconds /// since the Unix epoch. Assumes `self` evaluates to a Timestamp. @@ -1248,7 +1248,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the number of seconds. - func timestampToUnixSeconds() -> FunctionExpr + func timestampToUnixSeconds() -> FunctionExpression /// Creates an expression that adds a specified amount of time to this timestamp expression, /// where unit and amount are provided as expressions. @@ -1265,7 +1265,7 @@ public protocol Expr: Sendable { /// 'day'. /// - Parameter amount: An `Expr` evaluating to the amount (Int) of the unit to add. /// - Returns: A new `FunctionExpr` representing the resulting timestamp. - func timestampAdd(_ unit: Expr, _ amount: Expr) -> FunctionExpr + func timestampAdd(_ unit: Expression, _ amount: Expression) -> FunctionExpression /// Creates an expression that adds a specified amount of time to this timestamp expression, /// where unit and amount are provided as literals. @@ -1279,7 +1279,7 @@ public protocol Expr: Sendable { /// - Parameter unit: The `TimeUnit` enum representing the unit of time. /// - Parameter amount: The literal `Int` amount of the unit to add. /// - Returns: A new `FunctionExpr` representing the resulting timestamp. - func timestampAdd(_ unit: TimeUnit, _ amount: Int) -> FunctionExpr + func timestampAdd(_ unit: TimeUnit, _ amount: Int) -> FunctionExpression /// Creates an expression that subtracts a specified amount of time from this timestamp /// expression, @@ -1297,7 +1297,7 @@ public protocol Expr: Sendable { /// 'day'. /// - Parameter amount: An `Expr` evaluating to the amount (Int) of the unit to subtract. /// - Returns: A new `FunctionExpr` representing the resulting timestamp. - func timestampSub(_ unit: Expr, _ amount: Expr) -> FunctionExpr + func timestampSub(_ unit: Expression, _ amount: Expression) -> FunctionExpression /// Creates an expression that subtracts a specified amount of time from this timestamp /// expression, @@ -1312,7 +1312,7 @@ public protocol Expr: Sendable { /// - Parameter unit: The `TimeUnit` enum representing the unit of time. /// - Parameter amount: The literal `Int` amount of the unit to subtract. /// - Returns: A new `FunctionExpr` representing the resulting timestamp. - func timestampSub(_ unit: TimeUnit, _ amount: Int) -> FunctionExpr + func timestampSub(_ unit: TimeUnit, _ amount: Int) -> FunctionExpression // MARK: - Bitwise operations @@ -1328,7 +1328,7 @@ public protocol Expr: Sendable { /// /// - Parameter otherBits: The integer literal operand. /// - Returns: A new `FunctionExpr` representing the bitwise AND operation. - func bitAnd(_ otherBits: Int) -> FunctionExpr + func bitAnd(_ otherBits: Int) -> FunctionExpression /// Creates an expression applying bitwise AND between this expression and a UInt8 literal (often /// for byte masks). @@ -1340,7 +1340,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter otherBits: The UInt8 literal operand. /// - Returns: A new `FunctionExpr` representing the bitwise AND operation. - func bitAnd(_ otherBits: UInt8) -> FunctionExpr + func bitAnd(_ otherBits: UInt8) -> FunctionExpression /// Creates an expression applying bitwise AND between this expression and another expression. /// Assumes `self` and `bitsExpression` evaluate to Integer or Bytes. @@ -1352,7 +1352,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter bitsExpression: The other `Expr` operand. /// - Returns: A new `FunctionExpr` representing the bitwise AND operation. - func bitAnd(_ bitsExpression: Expr) -> FunctionExpr + func bitAnd(_ bitsExpression: Expression) -> FunctionExpression /// Creates an expression applying bitwise OR between this expression and an integer literal. /// Assumes `self` evaluates to an Integer or Bytes. @@ -1366,7 +1366,7 @@ public protocol Expr: Sendable { /// /// - Parameter otherBits: The integer literal operand. /// - Returns: A new `FunctionExpr` representing the bitwise OR operation. - func bitOr(_ otherBits: Int) -> FunctionExpr + func bitOr(_ otherBits: Int) -> FunctionExpression /// Creates an expression applying bitwise OR between this expression and a UInt8 literal. /// Assumes `self` evaluates to an Integer or Bytes. @@ -1377,7 +1377,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter otherBits: The UInt8 literal operand. /// - Returns: A new `FunctionExpr` representing the bitwise OR operation. - func bitOr(_ otherBits: UInt8) -> FunctionExpr + func bitOr(_ otherBits: UInt8) -> FunctionExpression /// Creates an expression applying bitwise OR between this expression and another expression. /// Assumes `self` and `bitsExpression` evaluate to Integer or Bytes. @@ -1389,7 +1389,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter bitsExpression: The other `Expr` operand. /// - Returns: A new `FunctionExpr` representing the bitwise OR operation. - func bitOr(_ bitsExpression: Expr) -> FunctionExpr + func bitOr(_ bitsExpression: Expression) -> FunctionExpression /// Creates an expression applying bitwise XOR between this expression and an integer literal. /// Assumes `self` evaluates to an Integer or Bytes. @@ -1403,7 +1403,7 @@ public protocol Expr: Sendable { /// /// - Parameter otherBits: The integer literal operand. /// - Returns: A new `FunctionExpr` representing the bitwise XOR operation. - func bitXor(_ otherBits: Int) -> FunctionExpr + func bitXor(_ otherBits: Int) -> FunctionExpression /// Creates an expression applying bitwise XOR between this expression and a UInt8 literal. /// Assumes `self` evaluates to an Integer or Bytes. @@ -1414,7 +1414,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter otherBits: The UInt8 literal operand. /// - Returns: A new `FunctionExpr` representing the bitwise XOR operation. - func bitXor(_ otherBits: UInt8) -> FunctionExpr + func bitXor(_ otherBits: UInt8) -> FunctionExpression /// Creates an expression applying bitwise XOR between this expression and another expression. /// Assumes `self` and `bitsExpression` evaluate to Integer or Bytes. @@ -1426,7 +1426,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter bitsExpression: The other `Expr` operand. /// - Returns: A new `FunctionExpr` representing the bitwise XOR operation. - func bitXor(_ bitsExpression: Expr) -> FunctionExpr + func bitXor(_ bitsExpression: Expression) -> FunctionExpression /// Creates an expression applying bitwise NOT to this expression. /// Assumes `self` evaluates to an Integer or Bytes. @@ -1439,7 +1439,7 @@ public protocol Expr: Sendable { /// ``` /// /// - Returns: A new `FunctionExpr` representing the bitwise NOT operation. - func bitNot() -> FunctionExpr + func bitNot() -> FunctionExpression /// Creates an expression applying bitwise left shift to this expression by a literal number of /// bits. @@ -1454,7 +1454,7 @@ public protocol Expr: Sendable { /// /// - Parameter y: The number of bits (Int literal) to shift by. /// - Returns: A new `FunctionExpr` representing the bitwise left shift operation. - func bitLeftShift(_ y: Int) -> FunctionExpr + func bitLeftShift(_ y: Int) -> FunctionExpression /// Creates an expression applying bitwise left shift to this expression by a number of bits /// specified by an expression. @@ -1467,7 +1467,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter numberExpr: An `Expr` (evaluating to an Int) for the number of bits to shift by. /// - Returns: A new `FunctionExpr` representing the bitwise left shift operation. - func bitLeftShift(_ numberExpr: Expr) -> FunctionExpr + func bitLeftShift(_ numberExpr: Expression) -> FunctionExpression /// Creates an expression applying bitwise right shift to this expression by a literal number of /// bits. @@ -1482,7 +1482,7 @@ public protocol Expr: Sendable { /// /// - Parameter y: The number of bits (Int literal) to shift by. /// - Returns: A new `FunctionExpr` representing the bitwise right shift operation. - func bitRightShift(_ y: Int) -> FunctionExpr + func bitRightShift(_ y: Int) -> FunctionExpression /// Creates an expression applying bitwise right shift to this expression by a number of bits /// specified by an expression. @@ -1495,7 +1495,7 @@ public protocol Expr: Sendable { /// ``` /// - Parameter numberExpr: An `Expr` (evaluating to an Int) for the number of bits to shift by. /// - Returns: A new `FunctionExpr` representing the bitwise right shift operation. - func bitRightShift(_ numberExpr: Expr) -> FunctionExpr + func bitRightShift(_ numberExpr: Expression) -> FunctionExpression /// Creates an expression that returns the result of `catchExpr` if this expression produces an /// error during evaluation, @@ -1510,7 +1510,7 @@ public protocol Expr: Sendable { /// /// - Parameter catchExpr: The `Expr` to evaluate and return if this expression errors. /// - Returns: A new `FunctionExpr` representing the 'ifError' operation. - func ifError(_ catchExpr: Expr) -> FunctionExpr + func ifError(_ catchExpr: Expression) -> FunctionExpression /// Creates an expression that returns the literal `catchValue` if this expression produces an /// error during evaluation, @@ -1525,7 +1525,7 @@ public protocol Expr: Sendable { /// /// - Parameter catchValue: The literal `Sendable` value to return if this expression errors. /// - Returns: A new `FunctionExpr` representing the 'ifError' operation. - func ifError(_ catchValue: Sendable) -> FunctionExpr + func ifError(_ catchValue: Sendable) -> FunctionExpression // MARK: Sorting diff --git a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/ArrayExpression.swift b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/ArrayExpression.swift similarity index 87% rename from Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/ArrayExpression.swift rename to Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/ArrayExpression.swift index e1f5d749c5f..673485d6e59 100644 --- a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/ArrayExpression.swift +++ b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/ArrayExpression.swift @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -public class ArrayExpression: FunctionExpr, @unchecked Sendable { - var result: [Expr] = [] +public class ArrayExpression: FunctionExpression, @unchecked Sendable { + var result: [Expression] = [] public init(_ elements: [Sendable]) { for element in elements { result.append(Helper.sendableToExpr(element)) diff --git a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/Constant.swift b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/Constant.swift similarity index 96% rename from Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/Constant.swift rename to Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/Constant.swift index 8f6b3709892..4505133f148 100644 --- a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/Constant.swift +++ b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/Constant.swift @@ -18,7 +18,7 @@ @_exported import FirebaseFirestoreInternal #endif // SWIFT_PACKAGE -public struct Constant: Expr, BridgeWrapper, @unchecked Sendable { +public struct Constant: Expression, BridgeWrapper, @unchecked Sendable { let bridge: ExprBridge let value: Any? diff --git a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/DocumentId.swift b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/DocumentId.swift similarity index 100% rename from Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/DocumentId.swift rename to Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/DocumentId.swift diff --git a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/Field.swift b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/Field.swift similarity index 90% rename from Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/Field.swift rename to Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/Field.swift index 99dc7e1b21d..4ec5dfb0d78 100644 --- a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/Field.swift +++ b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/Field.swift @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -public class Field: ExprBridge, Expr, Selectable, BridgeWrapper, SelectableWrapper, +public class Field: ExprBridge, Expression, Selectable, BridgeWrapper, SelectableWrapper, @unchecked Sendable { let bridge: ExprBridge var alias: String - var expr: Expr { + var expr: Expression { return self } diff --git a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/FunctionExpr.swift b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpression.swift similarity index 82% rename from Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/FunctionExpr.swift rename to Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpression.swift index 533f6a5ef51..825487c9a56 100644 --- a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/FunctionExpr.swift +++ b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpression.swift @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -public class FunctionExpr: Expr, BridgeWrapper, @unchecked Sendable { +public class FunctionExpression: Expression, BridgeWrapper, @unchecked Sendable { let bridge: ExprBridge let functionName: String - let agrs: [Expr] + let agrs: [Expression] - public init(_ functionName: String, _ agrs: [Expr]) { + public init(_ functionName: String, _ agrs: [Expression]) { self.functionName = functionName self.agrs = agrs bridge = FunctionExprBridge( diff --git a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/FunctionExpr/BooleanExpr.swift b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/BooleanExpr.swift similarity index 82% rename from Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/FunctionExpr/BooleanExpr.swift rename to Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/BooleanExpr.swift index 701276d51f7..6a3d2dc0d4f 100644 --- a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/FunctionExpr/BooleanExpr.swift +++ b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/BooleanExpr.swift @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -public class BooleanExpr: FunctionExpr, @unchecked Sendable { - override public init(_ functionName: String, _ agrs: [Expr]) { +public class BooleanExpr: FunctionExpression, @unchecked Sendable { + override public init(_ functionName: String, _ agrs: [Expression]) { super.init(functionName, agrs) } @@ -21,8 +21,8 @@ public class BooleanExpr: FunctionExpr, @unchecked Sendable { return AggregateFunction("count_if", [self]) } - public func then(_ thenExpr: Expr, else elseExpr: Expr) -> FunctionExpr { - return FunctionExpr("cond", [self, thenExpr, elseExpr]) + public func then(_ thenExpr: Expression, else elseExpr: Expression) -> FunctionExpression { + return FunctionExpression("cond", [self, thenExpr, elseExpr]) } public static func && (lhs: BooleanExpr, diff --git a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/FunctionExpr/RandomExpr.swift b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/RandomExpression.swift similarity index 89% rename from Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/FunctionExpr/RandomExpr.swift rename to Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/RandomExpression.swift index 5ea39db81fc..a2a7ea41fe0 100644 --- a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/FunctionExpr/RandomExpr.swift +++ b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/RandomExpression.swift @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -public class RandomExpr: FunctionExpr, @unchecked Sendable { +public class RandomExpression: FunctionExpression, @unchecked Sendable { public init() { super.init("rand", []) } diff --git a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/MapExpression.swift b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/MapExpression.swift similarity index 88% rename from Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/MapExpression.swift rename to Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/MapExpression.swift index 93d9bb4859b..78f05c0fba1 100644 --- a/Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/MapExpression.swift +++ b/Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/MapExpression.swift @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -public class MapExpression: FunctionExpr, @unchecked Sendable { - var result: [Expr] = [] +public class MapExpression: FunctionExpression, @unchecked Sendable { + var result: [Expression] = [] public init(_ elements: [String: Sendable]) { for element in elements { result.append(Constant(element.key)) diff --git a/Firestore/Swift/Source/SwiftAPI/Pipeline/Ordering.swift b/Firestore/Swift/Source/SwiftAPI/Pipeline/Ordering.swift index 9659e95e682..4eae5eefafb 100644 --- a/Firestore/Swift/Source/SwiftAPI/Pipeline/Ordering.swift +++ b/Firestore/Swift/Source/SwiftAPI/Pipeline/Ordering.swift @@ -15,18 +15,18 @@ */ public class Ordering: @unchecked Sendable { - let expr: Expr + let expr: Expression let direction: Direction let bridge: OrderingBridge - init(expr: Expr, direction: Direction) { + init(expr: Expression, direction: Direction) { self.expr = expr self.direction = direction bridge = OrderingBridge(expr: expr.toBridge(), direction: direction.rawValue) } } -public struct Direction: Sendable, Equatable, Hashable { +struct Direction: Sendable, Equatable, Hashable { let kind: Kind let rawValue: String @@ -35,11 +35,11 @@ public struct Direction: Sendable, Equatable, Hashable { case descending } - public static var ascending: Direction { + static var ascending: Direction { return self.init(kind: .ascending, rawValue: "ascending") } - public static var descending: Direction { + static var descending: Direction { return self.init(kind: .descending, rawValue: "descending") } diff --git a/Firestore/Swift/Source/SwiftAPI/Pipeline/Pipeline.swift b/Firestore/Swift/Source/SwiftAPI/Pipeline/Pipeline.swift index 6c2a6e34053..6f641af0879 100644 --- a/Firestore/Swift/Source/SwiftAPI/Pipeline/Pipeline.swift +++ b/Firestore/Swift/Source/SwiftAPI/Pipeline/Pipeline.swift @@ -147,8 +147,7 @@ public struct Pipeline: @unchecked Sendable { /// - Parameter field: The first field to add to the documents, specified as a `Selectable`. /// - Parameter additionalFields: Optional additional fields to add, specified as `Selectable`s. /// - Returns: A new `Pipeline` object with this stage appended. - public func addFields(_ field: Selectable, _ additionalFields: Selectable...) -> Pipeline { - let fields = [field] + additionalFields + public func addFields(_ fields: [AliasedExpression]) -> Pipeline { return Pipeline(stages: stages + [AddFields(fields: fields)], db: db) } @@ -163,9 +162,9 @@ public struct Pipeline: @unchecked Sendable { /// - Parameter field: The first field to remove, specified as a `Field` instance. /// - Parameter additionalFields: Optional additional fields to remove. /// - Returns: A new `Pipeline` object with this stage appended. - public func removeFields(_ field: Field, _ additionalFields: Field...) -> Pipeline { + public func removeFields(_ fields: [Field]) -> Pipeline { return Pipeline( - stages: stages + [RemoveFieldsStage(fields: [field] + additionalFields)], + stages: stages + [RemoveFieldsStage(fields: fields)], db: db ) } @@ -182,9 +181,9 @@ public struct Pipeline: @unchecked Sendable { /// - Parameter field: The name of the first field to remove. /// - Parameter additionalFields: Optional additional field names to remove. /// - Returns: A new `Pipeline` object with this stage appended. - public func removeFields(_ field: String, _ additionalFields: String...) -> Pipeline { + public func removeFields(_ fields: [String]) -> Pipeline { return Pipeline( - stages: stages + [RemoveFieldsStage(fields: [field] + additionalFields)], + stages: stages + [RemoveFieldsStage(fields: fields)], db: db ) } @@ -216,8 +215,7 @@ public struct Pipeline: @unchecked Sendable { /// - Parameter additionalSelections: Optional additional fields to include, specified as /// `Selectable`s. /// - Returns: A new `Pipeline` object with this stage appended. - public func select(_ selection: Selectable, _ additionalSelections: Selectable...) -> Pipeline { - let selections = [selection] + additionalSelections + public func select(_ selections: [Selectable]) -> Pipeline { return Pipeline( stages: stages + [Select(selections: selections)], db: db @@ -238,15 +236,8 @@ public struct Pipeline: @unchecked Sendable { /// - Parameter selection: The name of the first field to include in the output documents. /// - Parameter additionalSelections: Optional additional field names to include. /// - Returns: A new `Pipeline` object with this stage appended. - public func select(_ selection: String, _ additionalSelections: String...) -> Pipeline { - let selections = ([selection] + additionalSelections).map { Field($0) } - return Pipeline( - stages: stages + [Select(selections: selections)], - db: db - ) - } - - public func select(_ selections: [Selectable]) -> Pipeline { + public func select(_ selections: [String]) -> Pipeline { + let selections = selections.map { Field($0) } return Pipeline( stages: stages + [Select(selections: selections)], db: db @@ -339,8 +330,8 @@ public struct Pipeline: @unchecked Sendable { /// - Parameter group: The name of the first field for distinct value combinations. /// - Parameter additionalGroups: Optional additional field names. /// - Returns: A new `Pipeline` object with this stage appended. - public func distinct(_ group: String, _ additionalGroups: String...) -> Pipeline { - let selections = ([group] + additionalGroups).map { Field($0) } + public func distinct(_ groups: [String]) -> Pipeline { + let selections = groups.map { Field($0) } return Pipeline(stages: stages + [Distinct(groups: selections)], db: db) } @@ -369,42 +360,10 @@ public struct Pipeline: @unchecked Sendable { /// - Parameter group: The first `Selectable` expression to consider. /// - Parameter additionalGroups: Optional additional `Selectable` expressions. /// - Returns: A new `Pipeline` object with this stage appended. - public func distinct(_ group: Selectable, _ additionalGroups: Selectable...) -> Pipeline { - let groups = [group] + additionalGroups + public func distinct(_ groups: [Selectable]) -> Pipeline { return Pipeline(stages: stages + [Distinct(groups: groups)], db: db) } - /// Performs aggregation operations on all documents from previous stages. - /// - /// Computes aggregate values (e.g., sum, average, count) over the entire set of documents - /// from the previous stage. Aggregations are defined using `AggregateWithAlias`, - /// which pairs an `Accumulator` (e.g., `avg(Field("price"))`) with a result field name. - /// - /// ```swift - /// // let pipeline: Pipeline = ... // Assume pipeline from a "books" collection. - /// // Calculate the average rating and total number of books. - /// let aggregatedPipeline = pipeline.aggregate( - /// AggregateWithas(aggregate: avg(Field("rating")), alias: "averageRating"), - /// AggregateWithas(aggregate: countAll(), alias: "totalBooks") - /// ) - /// // let results = try await aggregatedPipeline.execute() - /// // results.documents might be: [["averageRating": 4.2, "totalBooks": 150]] - /// ``` - /// - /// - Parameter accumulator: The first `AggregateWithAlias` expression. - /// - Parameter additionalAccumulators: Optional additional `AggregateWithAlias` expressions. - /// - Returns: A new `Pipeline` object with this stage appended. - public func aggregate(_ accumulator: AggregateWithAlias, - _ additionalAccumulators: AggregateWithAlias...) -> Pipeline { - return Pipeline( - stages: stages + [Aggregate( - accumulators: [accumulator] + additionalAccumulators, - groups: nil // No grouping: aggregate over all documents. - )], - db: db - ) - } - /// Performs optionally grouped aggregation operations on documents from previous stages. /// /// Calculates aggregate values, optionally grouping documents by fields or `Selectable` @@ -435,42 +394,9 @@ public struct Pipeline: @unchecked Sendable { /// - groups: Optional array of `Selectable` expressions for grouping. If `nil` or empty, /// aggregates across all documents. /// - Returns: A new `Pipeline` object with this stage appended. - public func aggregate(_ accumulator: [AggregateWithAlias], + public func aggregate(_ aggregates: [AliasedAggregate], groups: [Selectable]? = nil) -> Pipeline { - return Pipeline(stages: stages + [Aggregate(accumulators: accumulator, groups: groups)], db: db) - } - - /// Performs optionally grouped aggregation operations using field names for grouping. - /// - /// Similar to the other `aggregate` method, but `groups` are specified as an array of `String` - /// field names. - /// - /// ```swift - /// // let pipeline: Pipeline = ... // Assume pipeline from "books" collection. - /// // Count books for each publisher. - /// let groupedByPublisherPipeline = pipeline.aggregate( - /// [AggregateWithas(aggregate: countAll(), alias: "book_count")], - /// groups: ["publisher"] // Group by the "publisher" field name. - /// ) - /// // let results = try await groupedByPublisherPipeline.execute() - /// // results.documents might be: - /// // [ - /// // ["publisher": "Penguin", "book_count": 50], - /// // ["publisher": "HarperCollins", "book_count": 35] - /// // ] - /// ``` - /// - /// - Parameters: - /// - accumulator: An array of `AggregateWithAlias` expressions. - /// - groups: An optional array of `String` field names for grouping. - /// - Returns: A new `Pipeline` object with this stage appended. - public func aggregate(_ accumulator: [AggregateWithAlias], - groups: [String]? = nil) -> Pipeline { - let selectables = groups?.map { Field($0) } - return Pipeline( - stages: stages + [Aggregate(accumulators: accumulator, groups: selectables)], - db: db - ) + return Pipeline(stages: stages + [Aggregate(accumulators: aggregates, groups: groups)], db: db) } /// Performs a vector similarity search, ordering results by similarity. @@ -537,8 +463,7 @@ public struct Pipeline: @unchecked Sendable { /// - Parameter additionalOrdering: Optional additional `Ordering` criteria for secondary sorting, /// etc. /// - Returns: A new `Pipeline` object with this stage appended. - public func sort(_ ordering: Ordering, _ additionalOrdering: Ordering...) -> Pipeline { - let orderings = [ordering] + additionalOrdering + public func sort(_ orderings: [Ordering]) -> Pipeline { return Pipeline(stages: stages + [Sort(orderings: orderings)], db: db) } @@ -562,7 +487,7 @@ public struct Pipeline: @unchecked Sendable { /// /// - Parameter expr: The `Expr` (typically a `Field`) that resolves to the nested map. /// - Returns: A new `Pipeline` object with this stage appended. - public func replace(with expr: Expr) -> Pipeline { + public func replace(with expr: Expression) -> Pipeline { return Pipeline(stages: stages + [ReplaceWith(expr: expr)], db: db) } diff --git a/Firestore/Swift/Source/SwiftAPI/Stages.swift b/Firestore/Swift/Source/SwiftAPI/Stages.swift index 9f6d071d9ff..1308395482f 100644 --- a/Firestore/Swift/Source/SwiftAPI/Stages.swift +++ b/Firestore/Swift/Source/SwiftAPI/Stages.swift @@ -218,10 +218,10 @@ class Distinct: Stage { class Aggregate: Stage { let name: String = "aggregate" let bridge: StageBridge - private var accumulators: [AggregateWithAlias] - private var groups: [String: Expr] = [:] + private var accumulators: [AliasedAggregate] + private var groups: [String: Expression] = [:] - init(accumulators: [AggregateWithAlias], groups: [Selectable]?) { + init(accumulators: [AliasedAggregate], groups: [Selectable]?) { self.accumulators = accumulators if groups != nil { self.groups = Helper.selectablesToMap(selectables: groups!) @@ -283,9 +283,9 @@ class Sort: Stage { class ReplaceWith: Stage { let name: String = "replaceWith" let bridge: StageBridge - private var expr: Expr + private var expr: Expression - init(expr: Expr) { + init(expr: Expression) { self.expr = expr bridge = ReplaceWithStageBridge(expr: expr.toBridge()) } @@ -327,8 +327,8 @@ class Union: Stage { class Unnest: Stage { let name: String = "unnest" let bridge: StageBridge - private var alias: Expr - private var field: Expr + private var alias: Expression + private var field: Expression private var indexField: String? init(field: Selectable, indexField: String? = nil) { diff --git a/Firestore/Swift/Tests/Integration/PipelineApiTests.swift b/Firestore/Swift/Tests/Integration/PipelineApiTests.swift index f712cceca1f..2aa3e4f04ec 100644 --- a/Firestore/Swift/Tests/Integration/PipelineApiTests.swift +++ b/Firestore/Swift/Tests/Integration/PipelineApiTests.swift @@ -59,15 +59,15 @@ final class PipelineTests: FSTIntegrationTestCase { // { title: 'title3', price: 5, discount: 0.66 } // An expression that will compute price from the value of msrp field and discount field - let priceExpr: FunctionExpr = Field("msrp").multiply(Field("discount")) + let priceExpr: FunctionExpression = Field("msrp").multiply(Field("discount")) // An expression becomes a Selectable when given an alias. In this case // the alias is 'salePrice' - let priceSelectableExpr: Selectable = priceExpr.as("salePrice") + let priceSelectableExpr: AliasedExpression = priceExpr.as("salePrice") _ = db.pipeline().collection("books") .addFields( - priceSelectableExpr // Add field `salePrice` based computed from msrp and discount + [priceSelectableExpr] // Add field `salePrice` based computed from msrp and discount ) // We don't expect customers to separate the Expression definition from the @@ -76,8 +76,9 @@ final class PipelineTests: FSTIntegrationTestCase { // is to inline the Expr definition _ = db.pipeline().collection("books") .addFields( - Field("msrp").multiply(Field("discount")).as("salePrice"), - Field("author") + [ + Field("msrp").multiply(Field("discount")).as("salePrice"), + ] ) // Output @@ -88,10 +89,10 @@ final class PipelineTests: FSTIntegrationTestCase { func testRemoveFieldsStage() async throws { // removes field 'rating' and 'cost' from the previous stage outputs. - _ = db.pipeline().collection("books").removeFields("rating", "cost") + _ = db.pipeline().collection("books").removeFields(["rating", "cost"]) // removes field 'rating'. - _ = db.pipeline().collection("books").removeFields(Field("rating")) + _ = db.pipeline().collection("books").removeFields([Field("rating")]) } func testSelectStage() async throws { @@ -103,11 +104,13 @@ final class PipelineTests: FSTIntegrationTestCase { // Overload for string and Selectable _ = db.pipeline().collection("books") .select( - Field("title"), // Field class inheritates Selectable - Field("msrp").multiply(Field("discount")).as("salePrice") + [ + Field("title"), // Field class inheritates Selectable + Field("msrp").multiply(Field("discount")).as("salePrice"), + ] ) - _ = db.pipeline().collection("books").select("title", "author") + _ = db.pipeline().collection("books").select(["title", "author"]) // Output // { title: 'title1', salePrice: 8.0}, @@ -120,22 +123,24 @@ final class PipelineTests: FSTIntegrationTestCase { // with the same rating _ = db.pipeline().collection("books") .sort( - Field("rating").descending(), - Ascending("title") // alternative API offered + [ + Field("rating").descending(), + Ascending("title"), // alternative API offered + ] ) } func testLimitStage() async throws { // Limit the results to the top 10 highest-rated books _ = db.pipeline().collection("books") - .sort(Field("rating").descending()) + .sort([Field("rating").descending()]) .limit(10) } func testOffsetStage() async throws { // Retrieve the second page of 20 results _ = db.pipeline().collection("books") - .sort(Field("published").descending()) + .sort([Field("published").descending()]) .offset(20) // Skip the first 20 results. Note that this must come // before .limit(...) unlike in Query where the order did not matter. .limit(20) // Take the next 20 results @@ -150,8 +155,10 @@ final class PipelineTests: FSTIntegrationTestCase { // Get a list of unique author names in uppercase and genre combinations. _ = db.pipeline().collection("books") .distinct( - Field("author").uppercased().as("authorName"), - Field("genre") + [ + Field("author").uppercased().as("authorName"), + Field("genre"), + ] ) // Output @@ -168,8 +175,10 @@ final class PipelineTests: FSTIntegrationTestCase { // Calculate the average rating and the total number of books _ = db.pipeline().collection("books") .aggregate( - Field("rating").avg().as("averageRating"), - CountAll().as("totalBooks") + [ + Field("rating").avg().as("averageRating"), + CountAll().as("totalBooks"), + ] ) // Output @@ -186,7 +195,7 @@ final class PipelineTests: FSTIntegrationTestCase { Field("rating").avg().as("averageRating"), CountAll().as("totalBooks"), ], - groups: ["genre"]) + groups: [Field("genre")]) // Output // { genre: 'genreA', totalBooks: 1, averageRating: 5.0 } @@ -270,7 +279,7 @@ final class PipelineTests: FSTIntegrationTestCase { _ = db.pipeline().collection("books") .rawStage(name: "where", params: [Field("published").lt(1900)]) - .select("title", "author") + .select(["title", "author"]) // In cases where the stage also supports named argument values, then these can be // provided with a third argument that maps the argument name to value. @@ -279,7 +288,7 @@ final class PipelineTests: FSTIntegrationTestCase { .rawStage(name: "where", params: [Field("published").lt(1900)], options: ["someOptionalParamName": "the argument value for this param"]) - .select("title", "author") + .select(["title", "author"]) } func testField() async throws { @@ -288,21 +297,24 @@ final class PipelineTests: FSTIntegrationTestCase { // An expression that will return the value of the field `description` in the document // Field is a sub-type of Expr, so we can also declare our var of type Expr - let descriptionField: Expr = Field("description") + let descriptionField = Field("description") // USAGE: anywhere an Expr type is accepted // Use a field in a pipeline _ = db.pipeline().collection("books") .addFields( - Field("rating").as("bookRating") // Duplicate field 'rating' as 'bookRating' + [ + Field("rating").as("bookRating"), // Duplicate field 'rating' as 'bookRating' + ] ) // One special Field value is conveniently exposed as static function to help the user reference // reserved field values of __name__. - _ = db.pipeline().collection("books") - .addFields( - DocumentId() - ) + // TBD +// _ = db.pipeline().collection("books") +// .addFields( +// DocumentId() +// ) } func testConstant() async throws { @@ -313,22 +325,22 @@ final class PipelineTests: FSTIntegrationTestCase { let name = Constant("Expressions API") // Const is a sub-type of Expr, so we can also declare our var of type Expr - let nothing: Expr = Constant.nil + let nothing = Constant.nil // USAGE: Anywhere an Expr type is accepted // Add field `fromTheLibraryOf: 'Rafi'` to every document in the collection. _ = db.pipeline().collection("books") - .addFields(Constant("Rafi").as("fromTheLibraryOf")) + .addFields([Constant("Rafi").as("fromTheLibraryOf")]) } func testFunctionExpr() async throws { let secondsField = Field("seconds") // Create a FunctionExpr using the multiply function to compute milliseconds - let milliseconds: FunctionExpr = secondsField.multiply(1000) + let milliseconds: FunctionExpression = secondsField.multiply(1000) // A firestore function is also a sub-type of Expr - let myExpr: Expr = milliseconds + let myExpr = milliseconds } func testBooleanExpr() async throws { @@ -348,7 +360,7 @@ final class PipelineTests: FSTIntegrationTestCase { // Add (or overwrite) the 'milliseconds` field to each of our documents using the // `.addFields(...)` stage. _ = db.pipeline().collection("lapTimes") - .addFields(secondsField.multiply(1000).as("milliseconds")) + .addFields([secondsField.multiply(1000).as("milliseconds")]) // NOTE: Field implements Selectable, the alias is the same as the name let secondsSelectable: Selectable = secondsField @@ -357,13 +369,13 @@ final class PipelineTests: FSTIntegrationTestCase { func testAggregateExpr() async throws { let lapTimeSum: AggregateFunction = Field("seconds").sum() - let lapTimeSumTarget: AggregateWithAlias = lapTimeSum.as("totalTrackTime") + let lapTimeSumTarget: AliasedAggregate = lapTimeSum.as("totalTrackTime") // USAGE: stage aggregate accepts expressions of type AggregateWithAlias // A pipeline that will return one document with one field `totalTrackTime` that // is the sum of all laps ever taken on the track. _ = db.pipeline().collection("lapTimes") - .aggregate(lapTimeSum.as("totalTrackTime")) + .aggregate([lapTimeSum.as("totalTrackTime")]) } func testOrdering() async throws { @@ -371,29 +383,29 @@ final class PipelineTests: FSTIntegrationTestCase { // USAGE: stage sort accepts objects of type Ordering // Use this ordering to sort our lap times collection from fastest to slowest - _ = db.pipeline().collection("lapTimes").sort(fastestToSlowest) + _ = db.pipeline().collection("lapTimes").sort([fastestToSlowest]) } func testExpr() async throws { // An expression that computes the area of a circle // by chaining together two calls to the multiply function - let radiusField: Expr = Field("radius") - let radiusSq: Expr = radiusField.multiply(Field("radius")) - let areaExpr: Expr = radiusSq.multiply(3.14) + let radiusField = Field("radius") + let radiusSq = radiusField.multiply(Field("radius")) + let areaExpr = radiusSq.multiply(3.14) // Or define this expression in one clean, fluent statement - let areaOfCircle: Selectable = Field("radius") + let areaOfCircle = Field("radius") .multiply(Field("radius")) .multiply(3.14) .as("area") // And pass the expression to a Pipeline for evaluation - _ = db.pipeline().collection("circles").addFields(areaOfCircle) + _ = db.pipeline().collection("circles").addFields([areaOfCircle]) } func testGeneric() async throws { // This is the same of the logicalMin('price', 0)', if it did not exist - let myLm = FunctionExpr("logicalMin", [Field("price"), Constant(0)]) + let myLm = FunctionExpression("logicalMin", [Field("price"), Constant(0)]) // Create a generic BooleanExpr for use where BooleanExpr is required let myEq = BooleanExpr("eq", [Field("price"), Constant(10)]) diff --git a/Firestore/Swift/Tests/Integration/PipelineTests.swift b/Firestore/Swift/Tests/Integration/PipelineTests.swift index f05a7dcc9eb..1045ffd3220 100644 --- a/Firestore/Swift/Tests/Integration/PipelineTests.swift +++ b/Firestore/Swift/Tests/Integration/PipelineTests.swift @@ -267,7 +267,7 @@ class PipelineIntegrationTests: FSTIntegrationTestCase { let pipeline = db.pipeline() .collection(collRef.path) - .aggregate(Field("rating").avg().as("avgRating")) + .aggregate([Field("rating").avg().as("avgRating")]) let snapshot = try await pipeline.execute() XCTAssertEqual(snapshot.results.count, 1, "Aggregate query should return a single result") @@ -284,7 +284,7 @@ class PipelineIntegrationTests: FSTIntegrationTestCase { .collection(collRef.path) .aggregate( [Field("rating").avg().as("avgRating")], - groups: ["genre"] + groups: [Field("genre")] ) // Make sure 'groupBy' and 'average' are correct let snapshot = try await pipeline.execute() @@ -395,7 +395,7 @@ class PipelineIntegrationTests: FSTIntegrationTestCase { let pipeline = db.pipeline() .collectionGroup(randomSubCollectionId) - .sort(Field("order").ascending()) + .sort([Field("order").ascending()]) let snapshot = try await pipeline.execute() @@ -2252,7 +2252,7 @@ class PipelineIntegrationTests: FSTIntegrationTestCase { .sort(Field("rating").descending()) .limit(1) .select( - FunctionExpr("add", [Field("rating"), Constant(1)]).as( + FunctionExpression("add", [Field("rating"), Constant(1)]).as( "rating" ) ) @@ -2346,7 +2346,7 @@ class PipelineIntegrationTests: FSTIntegrationTestCase { let pipeline = db.pipeline() .collection(collRef.path) .sort( - FunctionExpr("char_length", [Field("title")]).ascending(), + FunctionExpression("char_length", [Field("title")]).ascending(), Field("__name__").descending() ) .limit(3) @@ -2372,7 +2372,7 @@ class PipelineIntegrationTests: FSTIntegrationTestCase { let pipeline = db.pipeline() .collection(collRef.path) .limit(10) - .select(RandomExpr().as("result")) + .select(RandomExpression().as("result")) let snapshot = try await pipeline.execute()