Skip to content

Commit af33109

Browse files
committed
merge in main branch
2 parents 1c9df2a + 680503d commit af33109

File tree

4 files changed

+110
-221
lines changed

4 files changed

+110
-221
lines changed

Firestore/Swift/Source/ExpressionImplementation.swift

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -373,17 +373,6 @@ extension Expression {
373373
func stringReplace(_ find: Expression, with replace: Expression) -> FunctionExpression {
374374
return FunctionExpression(functionName: "string_replace", args: [self, find, replace])
375375
}
376-
377-
// MARK: Equivalence Operations
378-
379-
/// Creates a `BooleanExpr` that returns `true` if this expression is equivalent
380-
/// to the given value.
381-
///
382-
/// - Parameter other: The value to compare against.
383-
/// - Returns: A `BooleanExpr` that can be used in `where` clauses.
384-
func equivalent(_ other: Sendable) -> BooleanExpression {
385-
return BooleanExpression(functionName: "equivalent", args: [self, Helper.sendableToExpr(other)])
386-
}
387376
}
388377

389378
public extension Expression {
@@ -709,8 +698,15 @@ public extension Expression {
709698
return FunctionExpression(functionName: "to_upper", args: [self])
710699
}
711700

712-
func trim() -> FunctionExpression {
713-
return FunctionExpression(functionName: "trim", args: [self])
701+
func trim(_ value: String) -> FunctionExpression {
702+
return FunctionExpression(
703+
functionName: "trim",
704+
args: [self, Helper.sendableToExpr(value)]
705+
)
706+
}
707+
708+
func trim(_ value: Expression) -> FunctionExpression {
709+
return FunctionExpression(functionName: "trim", args: [self, value])
714710
}
715711

716712
func stringConcat(_ strings: [Expression]) -> FunctionExpression {
@@ -731,7 +727,7 @@ public extension Expression {
731727
}
732728

733729
func byteLength() -> FunctionExpression {
734-
return FunctionExpression(functionName: "byte_length", args: [self])
730+
return FunctionExpression("byte_length", [self])
735731
}
736732

737733
func substring(position: Int, length: Int? = nil) -> FunctionExpression {

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,31 @@
2222
import Foundation
2323

2424
@objc public extension Firestore {
25-
/// Creates a `PipelineSource` that can be used to build and execute a pipeline of operations on
26-
/// the Firestore database.
25+
/// Creates a new `PipelineSource` to build and execute a data pipeline.
2726
///
28-
/// A pipeline is a sequence of stages that are executed in order. Each stage can perform an
29-
/// operation on the data, such as filtering, sorting, or transforming it.
27+
/// A pipeline is composed of a sequence of stages. Each stage processes the
28+
/// output from the previous one, and the final stage's output is the result of the
29+
/// pipeline's execution.
3030
///
3131
/// Example usage:
3232
/// ```swift
33-
/// let db = Firestore.firestore()
34-
/// let pipeline = db.pipeline()
33+
/// let pipeline = firestore.pipeline()
3534
/// .collection("books")
3635
/// .where(Field("rating").isGreaterThan(4.5))
37-
/// .sort([Field("rating").descending()])
36+
/// .sort(Field("rating").descending())
3837
/// .limit(2)
39-
///
40-
/// do {
41-
/// let snapshot = try await pipeline.execute()
42-
/// for doc in snapshot.results {
43-
/// print(doc.data())
44-
/// }
45-
/// } catch {
46-
/// print("Error executing pipeline: \(error)")
47-
/// }
4838
/// ```
4939
///
50-
/// - Returns: A `PipelineSource` that can be used to build and execute a pipeline.
40+
/// Note on Execution: The stages are conceptual. The Firestore backend may
41+
/// optimize execution (e.g., reordering or merging stages) as long as the
42+
/// final result remains the same.
43+
///
44+
/// Important Limitations:
45+
/// - Pipelines operate on a request/response basis only.
46+
/// - They do not utilize or update the local SDK cache.
47+
/// - They do not support realtime snapshot listeners.
48+
///
49+
/// - Returns: A `PipelineSource` to begin defining the pipeline's stages.
5150
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
5251
@nonobjc func pipeline() -> PipelineSource {
5352
return PipelineSource(db: self) { stages, db in

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

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -466,83 +466,96 @@ public protocol Expression: Sendable {
466466
///
467467
/// - Parameter other: The expression to compare against.
468468
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
469+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
470+
/// boolean expressions.
469471
func greaterThan(_ other: Expression) -> BooleanExpression
470472

471473
/// Creates a `BooleanExpression` that returns `true` if this expression is greater
472474
/// than the given value.
473475
///
474476
/// - Parameter other: The value to compare against.
475-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
477+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
478+
/// boolean expressions.
476479
func greaterThan(_ other: Sendable) -> BooleanExpression
477480

478481
/// Creates a `BooleanExpression` that returns `true` if this expression is
479482
/// greater than or equal to the given expression.
480483
///
481484
/// - Parameter other: The expression to compare against.
482-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
485+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
486+
/// boolean expressions.
483487
func greaterThanOrEqual(_ other: Expression) -> BooleanExpression
484488

485489
/// Creates a `BooleanExpression` that returns `true` if this expression is
486490
/// greater than or equal to the given value.
487491
///
488492
/// - Parameter other: The value to compare against.
489-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
493+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
494+
/// boolean expressions.
490495
func greaterThanOrEqual(_ other: Sendable) -> BooleanExpression
491496

492497
/// Creates a `BooleanExpression` that returns `true` if this expression is less
493498
/// than the given expression.
494499
///
495500
/// - Parameter other: The expression to compare against.
496-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
501+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
502+
/// boolean expressions.
497503
func lessThan(_ other: Expression) -> BooleanExpression
498504

499505
/// Creates a `BooleanExpression` that returns `true` if this expression is less
500506
/// than the given value.
501507
///
502508
/// - Parameter other: The value to compare against.
503-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
509+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
510+
/// boolean expressions.
504511
func lessThan(_ other: Sendable) -> BooleanExpression
505512

506513
/// Creates a `BooleanExpression` that returns `true` if this expression is less
507514
/// than or equal to the given expression.
508515
///
509516
/// - Parameter other: The expression to compare against.
510-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
517+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
518+
/// boolean expressions.
511519
func lessThanOrEqual(_ other: Expression) -> BooleanExpression
512520

513521
/// Creates a `BooleanExpression` that returns `true` if this expression is less
514522
/// than or equal to the given value.
515523
///
516524
/// - Parameter other: The value to compare against.
517-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
525+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
526+
/// boolean expressions.
518527
func lessThanOrEqual(_ other: Sendable) -> BooleanExpression
519528

520529
/// Creates a `BooleanExpression` that returns `true` if this expression is equal
521530
/// to the given expression.
522531
///
523532
/// - Parameter other: The expression to compare against.
524-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
533+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
534+
/// boolean expressions.
525535
func equal(_ other: Expression) -> BooleanExpression
526536

527537
/// Creates a `BooleanExpression` that returns `true` if this expression is equal
528538
/// to the given value.
529539
///
530540
/// - Parameter other: The value to compare against.
531-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
541+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
542+
/// boolean expressions.
532543
func equal(_ other: Sendable) -> BooleanExpression
533544

534545
/// Creates a `BooleanExpression` that returns `true` if this expression is not
535546
/// equal to the given expression.
536547
///
537548
/// - Parameter other: The expression to compare against.
538-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
549+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
550+
/// boolean expressions.
539551
func notEqual(_ other: Expression) -> BooleanExpression
540552

541553
/// Creates a `BooleanExpression` that returns `true` if this expression is not
542554
/// equal to the given value.
543555
///
544556
/// - Parameter other: The value to compare against.
545-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
557+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
558+
/// boolean expressions.
546559
func notEqual(_ other: Sendable) -> BooleanExpression
547560

548561
/// Creates an expression that checks if this expression is equal to any of the provided
@@ -554,7 +567,8 @@ public protocol Expression: Sendable {
554567
/// ```
555568
///
556569
/// - Parameter others: An array of at least one `Expression` value to check against.
557-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
570+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
571+
/// boolean expressions.
558572
func equalAny(_ others: [Expression]) -> BooleanExpression
559573

560574
/// Creates an expression that checks if this expression is equal to any of the provided literal
@@ -566,7 +580,8 @@ public protocol Expression: Sendable {
566580
/// ```
567581
///
568582
/// - Parameter others: An array of at least one `Sendable` literal value to check against.
569-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
583+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
584+
/// boolean expressions.
570585
func equalAny(_ others: [Sendable]) -> BooleanExpression
571586

572587
/// Creates an expression that checks if this expression is equal to any of the provided
@@ -578,7 +593,8 @@ public protocol Expression: Sendable {
578593
/// ```
579594
///
580595
/// - Parameter arrayExpression: An `Expression` elements evaluated to be array.
581-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
596+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
597+
/// boolean expressions.
582598
func equalAny(_ arrayExpression: Expression) -> BooleanExpression
583599

584600
/// Creates an expression that checks if this expression is not equal to any of the provided
@@ -590,7 +606,8 @@ public protocol Expression: Sendable {
590606
/// ```
591607
///
592608
/// - Parameter others: An array of at least one `Expression` value to check against.
593-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
609+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
610+
/// boolean expressions.
594611
func notEqualAny(_ others: [Expression]) -> BooleanExpression
595612

596613
/// Creates an expression that checks if this expression is not equal to any of the provided
@@ -602,7 +619,8 @@ public protocol Expression: Sendable {
602619
/// ```
603620
///
604621
/// - Parameter others: An array of at least one `Sendable` literal value to check against.
605-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
622+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
623+
/// boolean expressions.
606624
func notEqualAny(_ others: [Sendable]) -> BooleanExpression
607625

608626
/// Creates an expression that checks if this expression is equal to any of the provided
@@ -614,7 +632,8 @@ public protocol Expression: Sendable {
614632
/// ```
615633
///
616634
/// - Parameter arrayExpression: An `Expression` elements evaluated to be array.
617-
/// - Returns: A `BooleanExpression` that can be used in `where` clauses.
635+
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
636+
/// boolean expressions.
618637
func notEqualAny(_ arrayExpression: Expression) -> BooleanExpression
619638

620639
/// Creates an expression that checks if a field exists in the document.
@@ -721,7 +740,7 @@ public protocol Expression: Sendable {
721740
/// ```
722741
///
723742
/// - Parameter pattern: The literal string regular expression to use for the search.
724-
/// - Returns: A new `BooleanExpression` representing the "regex_contains" comparison.
743+
/// - Returns: A new `BooleanExpr` representing the "regex_contains" comparison.
725744
func regexContains(_ pattern: String) -> BooleanExpression
726745

727746
/// Creates an expression that checks if a string (from `self`) contains a specified regular
@@ -868,17 +887,32 @@ public protocol Expression: Sendable {
868887
/// - Returns: A new `FunctionExpression` representing the uppercase string.
869888
func toUpper() -> FunctionExpression
870889

871-
/// Creates an expression that removes leading and trailing whitespace from a string (from
872-
/// `self`).
873-
/// Assumes `self` evaluates to a string.
890+
/// Creates an expression that removes leading and trailing occurrences of specified characters
891+
/// from a string (from `self`).
892+
/// Assumes `self` evaluates to a string, and `value` evaluates to a string.
893+
///
894+
/// ```swift
895+
/// // Trim leading/trailing "xy" from field
896+
/// Field("code").trim(characters: "xy")
897+
/// ```
898+
///
899+
/// - Parameter value: A `String` containing the characters to trim.
900+
/// - Returns: A new `FunctionExpression` representing the trimmed string.
901+
func trim(_ value: String) -> FunctionExpression
902+
903+
/// Creates an expression that removes leading and trailing occurrences of specified string
904+
/// (from an expression) from a string (from `self`).
905+
/// Assumes `self` evaluates to a string, and `value` evaluates to a string.
874906
///
875907
/// ```swift
876-
/// // Trim whitespace from the "userInput" field
877-
/// Field("userInput").trim()
908+
/// // Trim characters specified by the "trimChars" field from "data"
909+
/// Field("data").trim(characters: Field("trimChars"))
878910
/// ```
879911
///
912+
/// - Parameter value: An `Expression` (evaluating to a string) containing the characters to
913+
/// trim.
880914
/// - Returns: A new `FunctionExpression` representing the trimmed string.
881-
func trim() -> FunctionExpression
915+
func trim(_ value: Expression) -> FunctionExpression
882916

883917
/// Creates an expression that concatenates this string expression with other string expressions.
884918
/// Assumes `self` and all parameters evaluate to strings.

0 commit comments

Comments
 (0)