Skip to content

Commit 38deb73

Browse files
committed
replace varadic list with array and add tests
1 parent 2cb72fe commit 38deb73

File tree

4 files changed

+387
-57
lines changed

4 files changed

+387
-57
lines changed

Firestore/Swift/Source/ExprImpl.swift

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,20 @@ public extension Expr {
8989
return BooleanExpr("array_contains", [self, Helper.sendableToExpr(element)])
9090
}
9191

92-
func arrayContainsAll(_ values: Expr...) -> BooleanExpr {
93-
return BooleanExpr("array_contains_all", [self] + values)
92+
func arrayContainsAll(_ values: [Expr]) -> BooleanExpr {
93+
return BooleanExpr("array_contains_all", [self, Helper.array(values)])
9494
}
9595

96-
func arrayContainsAll(_ values: Sendable...) -> BooleanExpr {
97-
let exprValues = values.map { Helper.sendableToExpr($0) }
98-
return BooleanExpr("array_contains_all", [self] + exprValues)
96+
func arrayContainsAll(_ values: [Sendable]) -> BooleanExpr {
97+
return BooleanExpr("array_contains_all", [self, Helper.array(values)])
9998
}
10099

101-
func arrayContainsAny(_ values: Expr...) -> BooleanExpr {
102-
return BooleanExpr("array_contains_any", [self] + values)
100+
func arrayContainsAny(_ values: [Expr]) -> BooleanExpr {
101+
return BooleanExpr("array_contains_any", [self, Helper.array(values)])
103102
}
104103

105-
func arrayContainsAny(_ values: Sendable...) -> BooleanExpr {
106-
let exprValues = values.map { Helper.sendableToExpr($0) }
107-
return BooleanExpr("array_contains_any", [self] + exprValues)
104+
func arrayContainsAny(_ values: [Sendable]) -> BooleanExpr {
105+
return BooleanExpr("array_contains_any", [self, Helper.array(values)])
108106
}
109107

110108
func arrayLength() -> FunctionExpr {
@@ -172,31 +170,28 @@ public extension Expr {
172170
return BooleanExpr("eq", [self, exprOther])
173171
}
174172

175-
func neq(_ others: Expr...) -> BooleanExpr {
176-
return BooleanExpr("neq", [self] + others)
173+
func neq(_ others: [Expr]) -> BooleanExpr {
174+
return BooleanExpr("neq", [self, Helper.array(others)])
177175
}
178176

179-
func neq(_ others: Sendable...) -> BooleanExpr {
180-
let exprOthers = others.map { Helper.sendableToExpr($0) }
181-
return BooleanExpr("neq", [self] + exprOthers)
177+
func neq(_ others: [Sendable]) -> BooleanExpr {
178+
return BooleanExpr("neq", [self, Helper.array(others)])
182179
}
183180

184-
func eqAny(_ others: Expr...) -> BooleanExpr {
185-
return BooleanExpr("eq_any", [self] + others)
181+
func eqAny(_ others: [Expr]) -> BooleanExpr {
182+
return BooleanExpr("eq_any", [self, Helper.array(others)])
186183
}
187184

188-
func eqAny(_ others: Sendable...) -> BooleanExpr {
189-
let exprOthers = others.map { Helper.sendableToExpr($0) }
190-
return BooleanExpr("eq_any", [self] + exprOthers)
185+
func eqAny(_ others: [Sendable]) -> BooleanExpr {
186+
return BooleanExpr("eq_any", [self, Helper.array(others)])
191187
}
192188

193-
func notEqAny(_ others: Expr...) -> BooleanExpr {
194-
return BooleanExpr("not_eq_any", [self] + others)
189+
func notEqAny(_ others: [Expr]) -> BooleanExpr {
190+
return BooleanExpr("not_eq_any", [self, Helper.array(others)])
195191
}
196192

197-
func notEqAny(_ others: Sendable...) -> BooleanExpr {
198-
let exprOthers = others.map { Helper.sendableToExpr($0) }
199-
return BooleanExpr("not_eq_any", [self] + exprOthers)
193+
func notEqAny(_ others: [Sendable]) -> BooleanExpr {
194+
return BooleanExpr("not_eq_any", [self, Helper.array(others)])
200195
}
201196

202197
// MARK: Checks
@@ -237,12 +232,12 @@ public extension Expr {
237232
return FunctionExpr("char_length", [self])
238233
}
239234

240-
func like(_ pattern: String) -> FunctionExpr {
241-
return FunctionExpr("like", [self, Helper.sendableToExpr(pattern)])
235+
func like(_ pattern: String) -> BooleanExpr {
236+
return BooleanExpr("like", [self, Helper.sendableToExpr(pattern)])
242237
}
243238

244-
func like(_ pattern: Expr) -> FunctionExpr {
245-
return FunctionExpr("like", [self, pattern])
239+
func like(_ pattern: Expr) -> BooleanExpr {
240+
return BooleanExpr("like", [self, pattern])
246241
}
247242

248243
func regexContains(_ pattern: String) -> BooleanExpr {
@@ -414,13 +409,13 @@ public extension Expr {
414409
}
415410

416411
func logicalMinimum(_ second: Expr, _ others: Expr...) -> FunctionExpr {
417-
return FunctionExpr("logical_min", [self, second] + others)
412+
return FunctionExpr("logical_minimum", [self, second] + others)
418413
}
419414

420415
func logicalMinimum(_ second: Sendable, _ others: Sendable...) -> FunctionExpr {
421416
let exprs = [self] + [Helper.sendableToExpr(second)] + others
422417
.map { Helper.sendableToExpr($0) }
423-
return FunctionExpr("logical_min", exprs)
418+
return FunctionExpr("logical_minimum", exprs)
424419
}
425420

426421
// MARK: Vector Operations

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -239,55 +239,55 @@ public protocol Expr: Sendable {
239239
/// ```swift
240240
/// // Check if 'candidateSkills' contains all skills from 'requiredSkill1' and 'requiredSkill2'
241241
/// fields
242-
/// Field("candidateSkills").arrayContainsAll(Field("requiredSkill1"), Field("requiredSkill2"))
242+
/// Field("candidateSkills").arrayContainsAll([Field("requiredSkill1"), Field("requiredSkill2")])
243243
/// ```
244244
///
245-
/// - Parameter values: A variadic list of `Expr` elements to check for in the array represented
245+
/// - Parameter values: A list of `Expr` elements to check for in the array represented
246246
/// by `self`.
247247
/// - Returns: A new `BooleanExpr` representing the 'array_contains_all' comparison.
248-
func arrayContainsAll(_ values: Expr...) -> BooleanExpr
248+
func arrayContainsAll(_ values: [Expr]) -> BooleanExpr
249249

250250
/// Creates an expression that checks if an array (from `self`) contains all the specified literal
251251
/// elements.
252252
/// Assumes `self` evaluates to an array.
253253
///
254254
/// ```swift
255255
/// // Check if 'tags' contains both "urgent" and "review"
256-
/// Field("tags").arrayContainsAll("urgent", "review")
256+
/// Field("tags").arrayContainsAll(["urgent", "review"])
257257
/// ```
258258
///
259-
/// - Parameter values: A variadic list of `Sendable` literal elements to check for in the array
259+
/// - Parameter values: A list of `Sendable` literal elements to check for in the array
260260
/// represented by `self`.
261261
/// - Returns: A new `BooleanExpr` representing the 'array_contains_all' comparison.
262-
func arrayContainsAll(_ values: Sendable...) -> BooleanExpr
262+
func arrayContainsAll(_ values: [Sendable]) -> BooleanExpr
263263

264264
/// Creates an expression that checks if an array (from `self`) contains any of the specified
265265
/// element expressions.
266266
/// Assumes `self` evaluates to an array.
267267
///
268268
/// ```swift
269269
/// // Check if 'userGroups' contains any group from 'allowedGroup1' or 'allowedGroup2' fields
270-
/// Field("userGroups").arrayContainsAny(Field("allowedGroup1"), Field("allowedGroup2"))
270+
/// Field("userGroups").arrayContainsAny([Field("allowedGroup1"), Field("allowedGroup2")])
271271
/// ```
272272
///
273-
/// - Parameter values: A variadic list of `Expr` elements to check for in the array represented
273+
/// - Parameter values: A list of `Expr` elements to check for in the array represented
274274
/// by `self`.
275275
/// - Returns: A new `BooleanExpr` representing the 'array_contains_any' comparison.
276-
func arrayContainsAny(_ values: Expr...) -> BooleanExpr
276+
func arrayContainsAny(_ values: [Expr]) -> BooleanExpr
277277

278278
/// Creates an expression that checks if an array (from `self`) contains any of the specified
279279
/// literal elements.
280280
/// Assumes `self` evaluates to an array.
281281
///
282282
/// ```swift
283283
/// // Check if 'categories' contains either "electronics" or "books"
284-
/// Field("categories").arrayContainsAny("electronics", "books")
284+
/// Field("categories").arrayContainsAny(["electronics", "books"])
285285
/// ```
286286
///
287-
/// - Parameter values: A variadic list of `Sendable` literal elements to check for in the array
287+
/// - Parameter values: A list of `Sendable` literal elements to check for in the array
288288
/// represented by `self`.
289289
/// - Returns: A new `BooleanExpr` representing the 'array_contains_any' comparison.
290-
func arrayContainsAny(_ values: Sendable...) -> BooleanExpr
290+
func arrayContainsAny(_ values: [Sendable]) -> BooleanExpr
291291

292292
/// Creates an expression that calculates the length of an array.
293293
/// Assumes `self` evaluates to an array.
@@ -341,51 +341,51 @@ public protocol Expr: Sendable {
341341
///
342342
/// ```swift
343343
/// // Check if 'categoryID' field is equal to 'featuredCategory' or 'popularCategory' fields
344-
/// Field("categoryID").eqAny(Field("featuredCategory"), Field("popularCategory"))
344+
/// Field("categoryID").eqAny([Field("featuredCategory"), Field("popularCategory")])
345345
/// ```
346346
///
347-
/// - Parameter others: A variadic list of `Expr` values to check against.
347+
/// - Parameter others: A list of `Expr` values to check against.
348348
/// - Returns: A new `BooleanExpr` representing the 'IN' comparison (eq_any).
349-
func eqAny(_ others: Expr...) -> BooleanExpr
349+
func eqAny(_ others: [Expr]) -> BooleanExpr
350350

351351
/// Creates an expression that checks if this expression is equal to any of the provided literal
352352
/// values.
353353
/// This is similar to an "IN" operator in SQL.
354354
///
355355
/// ```swift
356356
/// // Check if 'category' is "Electronics", "Books", or "Home Goods"
357-
/// Field("category").eqAny("Electronics", "Books", "Home Goods")
357+
/// Field("category").eqAny(["Electronics", "Books", "Home Goods"])
358358
/// ```
359359
///
360-
/// - Parameter others: A variadic list of `Sendable` literal values to check against.
360+
/// - Parameter others: A list of `Sendable` literal values to check against.
361361
/// - Returns: A new `BooleanExpr` representing the 'IN' comparison (eq_any).
362-
func eqAny(_ others: Sendable...) -> BooleanExpr
362+
func eqAny(_ others: [Sendable]) -> BooleanExpr
363363

364364
/// Creates an expression that checks if this expression is not equal to any of the provided
365365
/// expression values.
366366
/// This is similar to a "NOT IN" operator in SQL.
367367
///
368368
/// ```swift
369369
/// // Check if 'statusValue' is not equal to 'archivedStatus' or 'deletedStatus' fields
370-
/// Field("statusValue").notEqAny(Field("archivedStatus"), Field("deletedStatus"))
370+
/// Field("statusValue").notEqAny([Field("archivedStatus"), Field("deletedStatus")])
371371
/// ```
372372
///
373-
/// - Parameter others: A variadic list of `Expr` values to check against.
373+
/// - Parameter others: A list of `Expr` values to check against.
374374
/// - Returns: A new `BooleanExpr` representing the 'NOT IN' comparison (not_eq_any).
375-
func notEqAny(_ others: Expr...) -> BooleanExpr
375+
func notEqAny(_ others: [Expr]) -> BooleanExpr
376376

377377
/// Creates an expression that checks if this expression is not equal to any of the provided
378378
/// literal values.
379379
/// This is similar to a "NOT IN" operator in SQL.
380380
///
381381
/// ```swift
382382
/// // Check if 'status' is neither "pending" nor "archived"
383-
/// Field("status").notEqAny("pending", "archived")
383+
/// Field("status").notEqAny(["pending", "archived"])
384384
/// ```
385385
///
386-
/// - Parameter others: A variadic list of `Sendable` literal values to check against.
386+
/// - Parameter others: A list of `Sendable` literal values to check against.
387387
/// - Returns: A new `BooleanExpr` representing the 'NOT IN' comparison (not_eq_any).
388-
func notEqAny(_ others: Sendable...) -> BooleanExpr
388+
func notEqAny(_ others: [Sendable]) -> BooleanExpr
389389

390390
// MARK: Checks
391391

@@ -495,7 +495,7 @@ public protocol Expr: Sendable {
495495
///
496496
/// - Parameter pattern: The literal string pattern to search for. Use "%" as a wildcard.
497497
/// - Returns: A new `FunctionExpr` representing the 'like' comparison.
498-
func like(_ pattern: String) -> FunctionExpr
498+
func like(_ pattern: String) -> BooleanExpr
499499

500500
/// Creates an expression that performs a case-sensitive string comparison using wildcards against
501501
/// an expression pattern.
@@ -509,7 +509,7 @@ public protocol Expr: Sendable {
509509
/// - Parameter pattern: An `Expr` (evaluating to a string) representing the pattern to search
510510
/// for.
511511
/// - Returns: A new `FunctionExpr` representing the 'like' comparison.
512-
func like(_ pattern: Expr) -> FunctionExpr
512+
func like(_ pattern: Expr) -> BooleanExpr
513513

514514
/// Creates an expression that checks if a string (from `self`) contains a specified regular
515515
/// expression literal as a substring.

Firestore/Swift/Source/SwiftAPI/Pipeline/Expr/FunctionExpr/BooleanExpr.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public class BooleanExpr: FunctionExpr, @unchecked Sendable {
2121
return AggregateFunction("count_if", [self])
2222
}
2323

24+
public func then(_ thenExpr: Expr, else elseExpr: Expr) -> FunctionExpr {
25+
return FunctionExpr("cond", [self, thenExpr, elseExpr])
26+
}
27+
2428
public static func && (lhs: BooleanExpr,
2529
rhs: @autoclosure () throws -> BooleanExpr) rethrows -> BooleanExpr {
2630
try BooleanExpr("and", [lhs, rhs()])

0 commit comments

Comments
 (0)