Skip to content

Commit 91b0dec

Browse files
committed
add documentations
1 parent a4d33e4 commit 91b0dec

File tree

13 files changed

+107
-12
lines changed

13 files changed

+107
-12
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,33 @@
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 the Firestore database.
26+
///
27+
/// A pipeline is a sequence of stages that are executed in order. Each stage can perform an operation on the data, such as filtering, sorting, or transforming it.
28+
///
29+
/// Example usage:
30+
/// ```swift
31+
/// let db = Firestore.firestore()
32+
/// let pipeline = db.pipeline()
33+
/// .collection("books")
34+
/// .where(Field("rating").isGreaterThan(4.5))
35+
/// .sort([Field("rating").descending()])
36+
/// .limit(2)
37+
/// ```
38+
///
39+
/// - Returns: A `PipelineSource` that can be used to build and execute a pipeline.
2540
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
2641
@nonobjc func pipeline() -> PipelineSource {
2742
return PipelineSource(db: self) { stages, db in
2843
Pipeline(stages: stages, db: db)
2944
}
3045
}
3146

47+
/// Creates a `RealtimePipelineSource` for building and executing a realtime pipeline.
48+
///
49+
/// This is an internal method and should not be used directly.
50+
///
51+
/// - Returns: A `RealtimePipelineSource` for building a realtime pipeline.
3252
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
3353
@nonobjc internal func realtimePipeline() -> RealtimePipelineSource {
3454
return RealtimePipelineSource(db: self) { stages, db in

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,23 @@ extension AggregateFunction {
1818
}
1919
}
2020

21+
/// Represents an aggregate function in a pipeline.
22+
///
23+
/// An `AggregateFunction` is a function that computes a single value from a set of input values.
24+
///
25+
/// `AggregateFunction`s are typically used in the `aggregate` stage of a pipeline.
2126
public class AggregateFunction: AggregateBridgeWrapper, @unchecked Sendable {
2227
let bridge: AggregateFunctionBridge
2328

2429
let functionName: String
2530
let args: [Expression]
2631

27-
public init(_ functionName: String, _ args: [Expression]) {
32+
/// Creates a new `AggregateFunction`.
33+
///
34+
/// - Parameters:
35+
/// - functionName: The name of the aggregate function.
36+
/// - args: The arguments to the aggregate function.
37+
public init(functionName: String, args: [Expression]) {
2838
self.functionName = functionName
2939
self.args = args
3040
bridge = AggregateFunctionBridge(
@@ -34,6 +44,10 @@ public class AggregateFunction: AggregateBridgeWrapper, @unchecked Sendable {
3444
)
3545
}
3646

47+
/// Creates an `AliasedAggregate` from this aggregate function.
48+
///
49+
/// - Parameter name: The alias for the aggregate function.
50+
/// - Returns: An `AliasedAggregate` with the given alias.
3751
public func `as`(_ name: String) -> AliasedAggregate {
3852
return AliasedAggregate(aggregate: self, alias: name)
3953
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
/// An `AggregateFunction` that has been given an alias.
1516
public struct AliasedAggregate {
16-
public let aggregate: AggregateFunction
17-
public let alias: String
17+
let aggregate: AggregateFunction
18+
19+
let alias: String
1820
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@
3838
public class CountAll: AggregateFunction, @unchecked Sendable {
3939
/// Initializes a new `CountAll` aggregation.
4040
public init() {
41-
super.init("count", [])
41+
super.init(functionName: "count", args: [])
4242
}
4343
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import Foundation
2222

23+
/// Represents the distance measure to be used in a vector similarity search.
2324
public struct DistanceMeasure: Sendable, Equatable, Hashable {
2425
let kind: Kind
2526

@@ -29,10 +30,13 @@ public struct DistanceMeasure: Sendable, Equatable, Hashable {
2930
case dotProduct = "dot_product"
3031
}
3132

33+
/// The Euclidean distance measure.
3234
public static let euclidean: DistanceMeasure = .init(kind: .euclidean)
3335

36+
/// The Cosine distance measure.
3437
public static let cosine: DistanceMeasure = .init(kind: .cosine)
3538

39+
/// The Dot Product distance measure.
3640
public static let dotProduct: DistanceMeasure = .init(kind: .dotProduct)
3741

3842
init(kind: Kind) {

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

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

15+
/// An `Expression` that has been given an alias.
1516
public struct AliasedExpression: Selectable, SelectableWrapper, Sendable {
1617
let alias: String
1718

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

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

15-
///
1615
/// A `Field` is an `Expression` that represents a field in a Firestore document.
1716
///
1817
/// It is a central component for building queries and transformations in Firestore pipelines.
@@ -42,9 +41,12 @@ public struct Field: Expression, Selectable, BridgeWrapper, SelectableWrapper,
4241
return self
4342
}
4443

44+
/// The name of the field.
4545
public let fieldName: String
4646

4747
/// Creates a new `Field` expression from a field name.
48+
///
49+
/// - Parameter name: The name of the field.
4850
public init(_ name: String) {
4951
let fieldBridge = FieldBridge(name: name)
5052
bridge = fieldBridge
@@ -53,6 +55,8 @@ public struct Field: Expression, Selectable, BridgeWrapper, SelectableWrapper,
5355
}
5456

5557
/// Creates a new `Field` expression from a `FieldPath`.
58+
///
59+
/// - Parameter path: The `FieldPath` of the field.
5660
public init(_ path: FieldPath) {
5761
let fieldBridge = FieldBridge(path: path)
5862
bridge = fieldBridge

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

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

15+
/// Represents a function call in a pipeline.
16+
///
17+
/// A `FunctionExpression` is an expression that represents a function call with a given name and arguments.
18+
///
19+
/// `FunctionExpression`s are typically used to perform operations on data in a pipeline, such as mathematical calculations, string manipulations, or array operations.
1520
public class FunctionExpression: Expression, BridgeWrapper, @unchecked Sendable {
1621
let bridge: ExprBridge
1722

1823
let functionName: String
1924
let args: [Expression]
2025

26+
/// Creates a new `FunctionExpression`.
27+
///
28+
/// - Parameters:
29+
/// - functionName: The name of the function.
30+
/// - args: The arguments to the function.
2131
public init(functionName: String, args: [Expression]) {
2232
self.functionName = functionName
2333
self.args = args

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17+
/// An ordering for the documents in a pipeline.
1718
public struct Ordering: @unchecked Sendable {
19+
/// The expression to order by.
1820
public let expression: Expression
21+
/// The direction to order in.
1922
public let direction: Direction
23+
2024
let bridge: OrderingBridge
2125

2226
init(expression: Expression, direction: Direction) {
@@ -26,6 +30,7 @@ public struct Ordering: @unchecked Sendable {
2630
}
2731
}
2832

33+
/// A direction to order results in.
2934
public struct Direction: Sendable, Equatable, Hashable {
3035
let kind: Kind
3136
public let rawValue: String
@@ -35,8 +40,10 @@ public struct Direction: Sendable, Equatable, Hashable {
3540
case descending
3641
}
3742

43+
/// The ascending direction.
3844
static let ascending = Direction(kind: .ascending, rawValue: "ascending")
3945

46+
/// The descending direction.
4047
static let descending = Direction(kind: .descending, rawValue: "descending")
4148

4249
init(kind: Kind, rawValue: String) {

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,11 @@ import Foundation
2424
///
2525
/// A pipeline takes data sources, such as Firestore collections or collection groups, and applies
2626
/// a series of stages that are chained together. Each stage takes the output from the previous
27-
/// stage
28-
/// (or the data source) and produces an output for the next stage (or as the final output of the
27+
/// stage (or the data source) and produces an output for the next stage (or as the final output of the
2928
/// pipeline).
3029
///
3130
/// Expressions can be used within each stage to filter and transform data through the stage.
3231
///
33-
/// NOTE: The chained stages do not prescribe exactly how Firestore will execute the pipeline.
34-
/// Instead, Firestore only guarantees that the result is the same as if the chained stages were
35-
/// executed in order.
36-
///
3732
/// ## Usage Examples
3833
///
3934
/// The following examples assume you have a `Firestore` instance named `db`.
@@ -88,6 +83,7 @@ public struct Pipeline: @unchecked Sendable {
8883
bridge = PipelineBridge(stages: stages.map { $0.bridge }, db: db)
8984
}
9085

86+
/// A `Pipeline.Snapshot` contains the results of a pipeline execution.
9187
public struct Snapshot: Sendable {
9288
/// An array of all the results in the `Pipeline.Snapshot`.
9389
public let results: [PipelineResult]

0 commit comments

Comments
 (0)