Skip to content

Commit 41fcae2

Browse files
committed
add name tag for FunctionExpression
1 parent 50b673e commit 41fcae2

File tree

10 files changed

+190
-169
lines changed

10 files changed

+190
-169
lines changed

Firestore/Swift/Source/ExpressionImplementation.swift

Lines changed: 164 additions & 146 deletions
Large diffs are not rendered by default.

Firestore/Swift/Source/Helper/PipelineHelper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ enum Helper {
4747
result.append(Constant(key))
4848
result.append(sendableToExpr(value))
4949
}
50-
return FunctionExpression("map", result)
50+
return FunctionExpression(functionName: "map", args: result)
5151
}
5252

5353
static func array(_ elements: [Sendable?]) -> FunctionExpression {
5454
let transformedElements = elements.map { element in
5555
sendableToExpr(element)
5656
}
57-
return FunctionExpression("array", transformedElements)
57+
return FunctionExpression(functionName: "array", args: transformedElements)
5858
}
5959

6060
// This function is used to convert Swift type into Objective-C type.

Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/ArrayExpression.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ public class ArrayExpression: FunctionExpression, @unchecked Sendable {
3838
result.append(Helper.sendableToExpr(element))
3939
}
4040

41-
super.init("array", result)
41+
super.init(functionName: "array", args: result)
4242
}
4343
}

Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/BooleanExpression.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import Foundation
3131
/// )
3232
/// ```
3333
public class BooleanExpression: FunctionExpression, @unchecked Sendable {
34-
override public init(_ functionName: String, _ agrs: [Expression]) {
35-
super.init(functionName, agrs)
34+
override public init(functionName: String, args: [Expression]) {
35+
super.init(functionName: functionName, args: args)
3636
}
3737

3838
/// Creates an aggregation that counts the number of documents for which this boolean expression
@@ -79,7 +79,10 @@ public class BooleanExpression: FunctionExpression, @unchecked Sendable {
7979
/// - Returns: A new `FunctionExpression` representing the conditional logic.
8080
public func then(_ thenExpression: Expression,
8181
else elseExpression: Expression) -> FunctionExpression {
82-
return FunctionExpression("conditional", [self, thenExpression, elseExpression])
82+
return FunctionExpression(
83+
functionName: "conditional",
84+
args: [self, thenExpression, elseExpression]
85+
)
8386
}
8487

8588
/// Combines two boolean expressions with a logical AND (`&&`).
@@ -103,7 +106,7 @@ public class BooleanExpression: FunctionExpression, @unchecked Sendable {
103106
public static func && (lhs: BooleanExpression,
104107
rhs: @autoclosure () throws -> BooleanExpression) rethrows
105108
-> BooleanExpression {
106-
try BooleanExpression("and", [lhs, rhs()])
109+
try BooleanExpression(functionName: "and", args: [lhs, rhs()])
107110
}
108111

109112
/// Combines two boolean expressions with a logical OR (`||`).
@@ -127,7 +130,7 @@ public class BooleanExpression: FunctionExpression, @unchecked Sendable {
127130
public static func || (lhs: BooleanExpression,
128131
rhs: @autoclosure () throws -> BooleanExpression) rethrows
129132
-> BooleanExpression {
130-
try BooleanExpression("or", [lhs, rhs()])
133+
try BooleanExpression(functionName: "or", args: [lhs, rhs()])
131134
}
132135

133136
/// Combines two boolean expressions with a logical XOR (`^`).
@@ -151,7 +154,7 @@ public class BooleanExpression: FunctionExpression, @unchecked Sendable {
151154
public static func ^ (lhs: BooleanExpression,
152155
rhs: @autoclosure () throws -> BooleanExpression) rethrows
153156
-> BooleanExpression {
154-
try BooleanExpression("xor", [lhs, rhs()])
157+
try BooleanExpression(functionName: "xor", args: [lhs, rhs()])
155158
}
156159

157160
/// Negates a boolean expression with a logical NOT (`!`).
@@ -168,6 +171,6 @@ public class BooleanExpression: FunctionExpression, @unchecked Sendable {
168171
/// - Parameter lhs: The boolean expression to negate.
169172
/// - Returns: A new `BooleanExpression` representing the logical NOT.
170173
public static prefix func ! (lhs: BooleanExpression) -> BooleanExpression {
171-
return BooleanExpression("not", [lhs])
174+
return BooleanExpression(functionName: "not", args: [lhs])
172175
}
173176
}

Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/ConditionalExpression.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ public class ConditionalExpression: FunctionExpression, @unchecked Sendable {
4444
public init(_ expr: BooleanExpression,
4545
then thenExpression: Expression,
4646
else elseExpression: Expression) {
47-
super.init("conditional", [expr, thenExpression, elseExpression])
47+
super.init(functionName: "conditional", args: [expr, thenExpression, elseExpression])
4848
}
4949
}

Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/ErrorExpression.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ import Foundation
2323
/// ```
2424
public class ErrorExpression: FunctionExpression, @unchecked Sendable {
2525
public init(_ errorMessage: String) {
26-
super.init("error", [Constant(errorMessage)])
26+
super.init(functionName: "error", args: [Constant(errorMessage)])
2727
}
2828
}

Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/FunctionExpression.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public class FunctionExpression: Expression, BridgeWrapper, @unchecked Sendable
1616
let bridge: ExprBridge
1717

1818
let functionName: String
19-
let agrs: [Expression]
19+
let args: [Expression]
2020

21-
public init(_ functionName: String, _ agrs: [Expression]) {
21+
public init(functionName: String, args: [Expression]) {
2222
self.functionName = functionName
23-
self.agrs = agrs
23+
self.args = args
2424
bridge = FunctionExprBridge(
2525
name: functionName,
26-
args: self.agrs.map { $0.toBridge()
26+
args: self.args.map { $0.toBridge()
2727
}
2828
)
2929
}

Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/MapExpression.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public class MapExpression: FunctionExpression, @unchecked Sendable {
3636
result.append(Helper.sendableToExpr(element.value))
3737
}
3838

39-
super.init("map", result)
39+
super.init(functionName: "map", args: result)
4040
}
4141
}

Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/RandomExpression.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
public class RandomExpression: FunctionExpression, @unchecked Sendable {
3030
/// Creates a new `RandomExpression` that generates a random number.
3131
public init() {
32-
super.init("rand", [])
32+
super.init(functionName: "rand", args: [])
3333
}
3434
}

Firestore/Swift/Tests/Integration/PipelineTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,7 +2758,7 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
27582758
.limit(1)
27592759
.select(
27602760
[
2761-
FunctionExpression("add", [Field("rating"), Constant(1)]).as(
2761+
FunctionExpression(functionName: "add", args: [Field("rating"), Constant(1)]).as(
27622762
"rating"
27632763
),
27642764
]
@@ -2786,7 +2786,7 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
27862786
let pipeline = db.pipeline()
27872787
.collection(collRef.path)
27882788
.where(
2789-
BooleanExpression("and", [Field("rating").greaterThan(0),
2789+
BooleanExpression(functionName: "and", args: [Field("rating").greaterThan(0),
27902790
Field("title").charLength().lessThan(5),
27912791
Field("tags").arrayContains("propaganda")])
27922792
)
@@ -2810,8 +2810,8 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
28102810
let pipeline = db.pipeline()
28112811
.collection(collRef.path)
28122812
.where(BooleanExpression(
2813-
"array_contains_any",
2814-
[Field("tags"), ArrayExpression(["politics"])]
2813+
functionName: "array_contains_any",
2814+
args: [Field("tags"), ArrayExpression(["politics"])]
28152815
))
28162816
.select([Field("title")])
28172817

@@ -2858,7 +2858,7 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
28582858
.collection(collRef.path)
28592859
.sort(
28602860
[
2861-
FunctionExpression("char_length", [Field("title")]).ascending(),
2861+
FunctionExpression(functionName: "char_length", args: [Field("title")]).ascending(),
28622862
Field("__name__").descending(),
28632863
]
28642864
)

0 commit comments

Comments
 (0)