Skip to content

Commit a54bd45

Browse files
committed
address API feedbacks
1 parent 5a50bd6 commit a54bd45

File tree

10 files changed

+86
-103
lines changed

10 files changed

+86
-103
lines changed

Firestore/Swift/Source/ExprImpl.swift

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -121,80 +121,80 @@ public extension Expression {
121121
}
122122

123123
func greaterThan(_ other: Expression) -> BooleanExpression {
124-
return BooleanExpression("gt", [self, other])
124+
return BooleanExpression("greater_than", [self, other])
125125
}
126126

127127
func greaterThan(_ other: Sendable) -> BooleanExpression {
128128
let exprOther = Helper.sendableToExpr(other)
129-
return BooleanExpression("gt", [self, exprOther])
129+
return BooleanExpression("greater_than", [self, exprOther])
130130
}
131131

132132
func greaterThanOrEqual(_ other: Expression) -> BooleanExpression {
133-
return BooleanExpression("gte", [self, other])
133+
return BooleanExpression("greater_than_or_equal", [self, other])
134134
}
135135

136136
func greaterThanOrEqual(_ other: Sendable) -> BooleanExpression {
137137
let exprOther = Helper.sendableToExpr(other)
138-
return BooleanExpression("gte", [self, exprOther])
138+
return BooleanExpression("greater_than_or_equal", [self, exprOther])
139139
}
140140

141141
func lessThan(_ other: Expression) -> BooleanExpression {
142-
return BooleanExpression("lt", [self, other])
142+
return BooleanExpression("less_than", [self, other])
143143
}
144144

145145
func lessThan(_ other: Sendable) -> BooleanExpression {
146146
let exprOther = Helper.sendableToExpr(other)
147-
return BooleanExpression("lt", [self, exprOther])
147+
return BooleanExpression("less_than", [self, exprOther])
148148
}
149149

150150
func lessThanOrEqual(_ other: Expression) -> BooleanExpression {
151-
return BooleanExpression("lte", [self, other])
151+
return BooleanExpression("less_than_or_equal", [self, other])
152152
}
153153

154154
func lessThanOrEqual(_ other: Sendable) -> BooleanExpression {
155155
let exprOther = Helper.sendableToExpr(other)
156-
return BooleanExpression("lte", [self, exprOther])
156+
return BooleanExpression("less_than_or_equal", [self, exprOther])
157157
}
158158

159159
func equal(_ other: Expression) -> BooleanExpression {
160-
return BooleanExpression("eq", [self, other])
160+
return BooleanExpression("equal", [self, other])
161161
}
162162

163163
func equal(_ other: Sendable) -> BooleanExpression {
164164
let exprOther = Helper.sendableToExpr(other)
165-
return BooleanExpression("eq", [self, exprOther])
165+
return BooleanExpression("equal", [self, exprOther])
166166
}
167167

168168
func notEqual(_ other: Expression) -> BooleanExpression {
169-
return BooleanExpression("neq", [self, other])
169+
return BooleanExpression("not_equal", [self, other])
170170
}
171171

172172
func notEqual(_ other: Sendable) -> BooleanExpression {
173-
return BooleanExpression("neq", [self, Helper.sendableToExpr(other)])
173+
return BooleanExpression("not_equal", [self, Helper.sendableToExpr(other)])
174174
}
175175

176176
func equalAny(_ others: [Expression]) -> BooleanExpression {
177-
return BooleanExpression("eq_any", [self, Helper.array(others)])
177+
return BooleanExpression("equal_any", [self, Helper.array(others)])
178178
}
179179

180180
func equalAny(_ others: [Sendable]) -> BooleanExpression {
181-
return BooleanExpression("eq_any", [self, Helper.array(others)])
181+
return BooleanExpression("equal_any", [self, Helper.array(others)])
182182
}
183183

184184
func equalAny(_ arrayExpression: Expression) -> BooleanExpression {
185-
return BooleanExpression("eq_any", [self, arrayExpression])
185+
return BooleanExpression("equal_any", [self, arrayExpression])
186186
}
187187

188188
func notEqualAny(_ others: [Expression]) -> BooleanExpression {
189-
return BooleanExpression("not_eq_any", [self, Helper.array(others)])
189+
return BooleanExpression("not_equal_any", [self, Helper.array(others)])
190190
}
191191

192192
func notEqualAny(_ others: [Sendable]) -> BooleanExpression {
193-
return BooleanExpression("not_eq_any", [self, Helper.array(others)])
193+
return BooleanExpression("not_equal_any", [self, Helper.array(others)])
194194
}
195195

196196
func notEqualAny(_ arrayExpression: Expression) -> BooleanExpression {
197-
return BooleanExpression("not_eq_any", [self, arrayExpression])
197+
return BooleanExpression("not_equal_any", [self, arrayExpression])
198198
}
199199

200200
// MARK: Checks
@@ -260,11 +260,11 @@ public extension Expression {
260260
}
261261

262262
func strContains(_ substring: String) -> BooleanExpression {
263-
return BooleanExpression("str_contains", [self, Helper.sendableToExpr(substring)])
263+
return BooleanExpression("string_contains", [self, Helper.sendableToExpr(substring)])
264264
}
265265

266266
func strContains(_ expr: Expression) -> BooleanExpression {
267-
return BooleanExpression("str_contains", [self, expr])
267+
return BooleanExpression("string_contains", [self, expr])
268268
}
269269

270270
func startsWith(_ prefix: String) -> BooleanExpression {
@@ -283,11 +283,11 @@ public extension Expression {
283283
return BooleanExpression("ends_with", [self, suffix])
284284
}
285285

286-
func lowercased() -> FunctionExpression {
286+
func toLower() -> FunctionExpression {
287287
return FunctionExpression("to_lower", [self])
288288
}
289289

290-
func uppercased() -> FunctionExpression {
290+
func toUpper() -> FunctionExpression {
291291
return FunctionExpression("to_upper", [self])
292292
}
293293

@@ -296,7 +296,7 @@ public extension Expression {
296296
}
297297

298298
func strConcat(_ strings: [Expression]) -> FunctionExpression {
299-
return FunctionExpression("str_concat", [self] + strings)
299+
return FunctionExpression("string_concat", [self] + strings)
300300
}
301301

302302
func reverse() -> FunctionExpression {
@@ -380,35 +380,35 @@ public extension Expression {
380380
}
381381

382382
func average() -> AggregateFunction {
383-
return AggregateFunction("avg", [self])
383+
return AggregateFunction("average", [self])
384384
}
385385

386386
func minimum() -> AggregateFunction {
387-
return AggregateFunction("min", [self])
387+
return AggregateFunction("minimum", [self])
388388
}
389389

390390
func maximum() -> AggregateFunction {
391-
return AggregateFunction("max", [self])
391+
return AggregateFunction("maximum", [self])
392392
}
393393

394394
// MARK: Logical min/max
395395

396396
func logicalMaximum(_ expressions: [Expression]) -> FunctionExpression {
397-
return FunctionExpression("max", [self] + expressions)
397+
return FunctionExpression("logical_maximum", [self] + expressions)
398398
}
399399

400400
func logicalMaximum(_ values: [Sendable]) -> FunctionExpression {
401401
let exprs = [self] + values.map { Helper.sendableToExpr($0) }
402-
return FunctionExpression("max", exprs)
402+
return FunctionExpression("logical_maximum", exprs)
403403
}
404404

405405
func logicalMinimum(_ expressions: [Expression]) -> FunctionExpression {
406-
return FunctionExpression("min", [self] + expressions)
406+
return FunctionExpression("logical_minimum", [self] + expressions)
407407
}
408408

409409
func logicalMinimum(_ values: [Sendable]) -> FunctionExpression {
410410
let exprs = [self] + values.map { Helper.sendableToExpr($0) }
411-
return FunctionExpression("min", exprs)
411+
return FunctionExpression("logical_minimum", exprs)
412412
}
413413

414414
// MARK: Vector Operations
@@ -503,12 +503,12 @@ public extension Expression {
503503
}
504504

505505
func timestampSub(amount: Expression, unit: Expression) -> FunctionExpression {
506-
return FunctionExpression("timestamp_sub", [self, unit, amount])
506+
return FunctionExpression("timestamp_subtract", [self, unit, amount])
507507
}
508508

509509
func timestampSub(_ amount: Int, _ unit: TimeUnit) -> FunctionExpression {
510510
return FunctionExpression(
511-
"timestamp_sub",
511+
"timestamp_subtract",
512512
[self, Helper.sendableToExpr(unit), Helper.sendableToExpr(amount)]
513513
)
514514
}

Firestore/Swift/Source/SwiftAPI/Pipeline/Expression.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,22 +779,22 @@ public protocol Expression: Sendable {
779779
///
780780
/// ```swift
781781
/// // Convert the "name" field to lowercase
782-
/// Field("name").lowercased()
782+
/// Field("name").toLower()
783783
/// ```
784784
///
785785
/// - Returns: A new `FunctionExpression` representing the lowercase string.
786-
func lowercased() -> FunctionExpression
786+
func toLower() -> FunctionExpression
787787

788788
/// Creates an expression that converts a string (from `self`) to uppercase.
789789
/// Assumes `self` evaluates to a string.
790790
///
791791
/// ```swift
792-
/// // Convert the "title" field to uppercase3
793-
/// Field("title").uppercased()
792+
/// // Convert the "title" field to uppercase
793+
/// Field("title").toUpper()
794794
/// ```
795795
///
796796
/// - Returns: A new `FunctionExpression` representing the uppercase string.
797-
func uppercased() -> FunctionExpression
797+
func toUpper() -> FunctionExpression
798798

799799
/// Creates an expression that removes leading and trailing whitespace from a string (from
800800
/// `self`).

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
/// An expression that represents an array of values.
16+
///
17+
/// `ArrayExpression` is used to construct an array from a list of `Sendable`
18+
/// values, which can include literals (like numbers and strings) as well as other
19+
/// `Expression` instances. This allows for the creation of dynamic arrays within
20+
21+
/// a pipeline.
22+
///
23+
/// Example:
24+
/// ```swift
25+
/// ArrayExpression([
26+
/// 1,
27+
/// 2,
28+
/// Field("genre"),
29+
/// Field("rating").multiply(10),
30+
/// ArrayExpression([Field("title")]),
31+
/// MapExpression(["published": Field("published")]),
32+
/// ]).as("metadataArray")
33+
/// ```
1534
public class ArrayExpression: FunctionExpression, @unchecked Sendable {
1635
var result: [Expression] = []
1736
public init(_ elements: [Sendable]) {
@@ -21,4 +40,4 @@ public class ArrayExpression: FunctionExpression, @unchecked Sendable {
2140

2241
super.init("array", result)
2342
}
24-
}
43+
}

Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/DocumentId.swift

Lines changed: 0 additions & 48 deletions
This file was deleted.

Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/Field.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
public class Field: ExprBridge, Expression, Selectable, BridgeWrapper, SelectableWrapper,
15+
public struct Field: Expression, Selectable, BridgeWrapper, SelectableWrapper,
1616
@unchecked Sendable {
1717
let bridge: ExprBridge
1818

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Foundation
1818
/// A `BooleanExpression` is a specialized `FunctionExpression` that evaluates to a boolean value.
1919
///
2020
/// It is used to construct conditional logic within Firestore pipelines, such as in `where`
21-
/// clauses or `cond` expressions. `BooleanExpression` instances can be combined using standard
21+
/// clauses or `ConditionalExpression`. `BooleanExpression` instances can be combined using standard
2222
/// logical operators (`&&`, `||`, `!`, `^`) to create complex conditions.
2323
///
2424
/// Example usage in a `where` clause:
@@ -79,7 +79,7 @@ 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("cond", [self, thenExpression, elseExpression])
82+
return FunctionExpression("conditional", [self, thenExpression, elseExpression])
8383
}
8484

8585
/// Combines two boolean expressions with a logical AND (`&&`).

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
/// An expression that represents a map (or dictionary) of key-value pairs.
16+
///
17+
/// `MapExpression` is used to construct a map from a dictionary of `String` keys
18+
/// and `Sendable` values. The values can be literals (like numbers and strings)
19+
/// or other `Expression` instances, allowing for the creation of dynamic nested
20+
/// objects within a pipeline.
21+
///
22+
/// Example:
23+
/// ```swift
24+
/// MapExpression([
25+
/// "genre": Field("genre"),
26+
/// "rating": Field("rating").multiply(10),
27+
/// "nestedArray": ArrayExpression([Field("title")]),
28+
/// "nestedMap": MapExpression(["published": Field("published")]),
29+
/// ]).as("metadata")
30+
/// ```
1531
public class MapExpression: FunctionExpression, @unchecked Sendable {
1632
var result: [Expression] = []
1733
public init(_ elements: [String: Sendable]) {
@@ -22,4 +38,4 @@ public class MapExpression: FunctionExpression, @unchecked Sendable {
2238

2339
super.init("map", result)
2440
}
25-
}
41+
}

Firestore/Swift/Source/SwiftAPI/Pipeline/Pipeline.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public struct Pipeline: @unchecked Sendable {
183183
/// - `String`: Name of an existing field (implicitly converted to `Field`).
184184
/// - `Field`: References an existing field.
185185
/// - `FunctionExpression`: Represents the result of a function with an assigned alias
186-
/// (e.g., `Field("address").uppercased().as("upperAddress")`).
186+
/// (e.g., `Field("address").toUpper().as("upperAddress")`).
187187
///
188188
/// If no selections are provided, the output of this stage is typically empty.
189189
/// Use `addFields` if only additions are desired without replacing the existing document
@@ -194,7 +194,7 @@ public struct Pipeline: @unchecked Sendable {
194194
/// let projectedPipeline = pipeline.select([
195195
/// Field("firstName"),
196196
/// Field("lastName"),
197-
/// Field("address").uppercased().as("upperAddress")
197+
/// Field("address").toUpper().as("upperAddress")
198198
/// ])
199199
/// // let results = try await projectedPipeline.execute()
200200
/// ```
@@ -335,7 +335,7 @@ public struct Pipeline: @unchecked Sendable {
335335
/// // let pipeline: Pipeline = ... // Assume initial pipeline.
336336
/// // Get unique uppercase author names and genre combinations.
337337
/// let distinctPipeline = pipeline.distinct(
338-
/// Field("author").uppercased().as("authorName"),
338+
/// Field("author").toUpper().as("authorName"),
339339
/// Field("genre")
340340
/// )
341341
/// // To select only the transformed author name:

0 commit comments

Comments
 (0)