diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d9743f58..5ae666d4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ [Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.4.0...main) * _Contributing to this repo? Add info about your change here to be included in the next release_ +__New features__ + - Add includeAll computed property to Query and deprecate includeAll() ([#361](https://github.com/parse-community/Parse-Swift/pull/361)), thanks to [Corey Baker](https://github.com/cbaker6). + __Improvements__ - Allow LiveQuery client to be set using ParseLiveQuery.defaultClient and deprecate ParseLiveQuery.setDefault(). Show usage of deprecated code as warnings during compile time and suggest changes ([#360](https://github.com/parse-community/Parse-Swift/pull/360)), thanks to [Corey Baker](https://github.com/cbaker6). diff --git a/ParseSwift.playground/Pages/8 - Pointers.xcplaygroundpage/Contents.swift b/ParseSwift.playground/Pages/8 - Pointers.xcplaygroundpage/Contents.swift index 713a3aed1..3c242e978 100644 --- a/ParseSwift.playground/Pages/8 - Pointers.xcplaygroundpage/Contents.swift +++ b/ParseSwift.playground/Pages/8 - Pointers.xcplaygroundpage/Contents.swift @@ -177,7 +177,7 @@ query2.first { results in objects. */ let query3 = Author.query("name" == "Bruce") - .includeAll() + .includeAll query3.first { results in switch results { @@ -192,7 +192,7 @@ query3.first { results in //: You can also check if a field is equal to a ParseObject. do { let query4 = try Author.query("book" == newBook) - .includeAll() + .includeAll query4.first { results in switch results { diff --git a/Sources/ParseSwift/Objects/ParseInstallation+async.swift b/Sources/ParseSwift/Objects/ParseInstallation+async.swift index f3cdc29a9..0cb176c15 100644 --- a/Sources/ParseSwift/Objects/ParseInstallation+async.swift +++ b/Sources/ParseSwift/Objects/ParseInstallation+async.swift @@ -16,7 +16,7 @@ public extension ParseInstallation { Fetches the `ParseInstallation` *aynchronously* with the current data from the server and sets an error if one occurs. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: Returns saved `ParseInstallation`. @@ -128,7 +128,7 @@ public extension Sequence where Element: ParseInstallation { Fetches a collection of installations *aynchronously* with the current data from the server and sets an error if one occurs. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: Returns an array of Result enums with the object if a save was successful or a diff --git a/Sources/ParseSwift/Objects/ParseInstallation+combine.swift b/Sources/ParseSwift/Objects/ParseInstallation+combine.swift index 2662897a8..4265326df 100644 --- a/Sources/ParseSwift/Objects/ParseInstallation+combine.swift +++ b/Sources/ParseSwift/Objects/ParseInstallation+combine.swift @@ -17,7 +17,7 @@ public extension ParseInstallation { Fetches the `ParseInstallation` *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. @@ -124,7 +124,7 @@ public extension Sequence where Element: ParseInstallation { Fetches a collection of installations *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces an an array of Result enums with the object if a fetch was diff --git a/Sources/ParseSwift/Objects/ParseInstallation.swift b/Sources/ParseSwift/Objects/ParseInstallation.swift index a0a2fc6ac..30770b830 100644 --- a/Sources/ParseSwift/Objects/ParseInstallation.swift +++ b/Sources/ParseSwift/Objects/ParseInstallation.swift @@ -427,7 +427,7 @@ extension ParseInstallation { Fetches the `ParseInstallation` *synchronously* with the current data from the server and sets an error if one occurs. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - throws: An error of `ParseError` type. @@ -448,7 +448,7 @@ extension ParseInstallation { /** Fetches the `ParseInstallation` *asynchronously* and executes the given callback block. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default @@ -1274,7 +1274,7 @@ public extension Sequence where Element: ParseInstallation { /** Fetches a collection of installations *synchronously* all at once and throws an error if necessary. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. @@ -1319,7 +1319,7 @@ public extension Sequence where Element: ParseInstallation { /** Fetches a collection of installations all at once *asynchronously* and executes the completion block when done. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default value of .main. diff --git a/Sources/ParseSwift/Objects/ParseObject+async.swift b/Sources/ParseSwift/Objects/ParseObject+async.swift index d2d15cfb3..aacc46fe3 100644 --- a/Sources/ParseSwift/Objects/ParseObject+async.swift +++ b/Sources/ParseSwift/Objects/ParseObject+async.swift @@ -15,7 +15,7 @@ public extension ParseObject { /** Fetches the `ParseObject` *aynchronously* with the current data from the server and sets an error if one occurs. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: Returns the fetched `ParseObject`. @@ -111,7 +111,7 @@ public extension Sequence where Element: ParseObject { Fetches a collection of objects *aynchronously* with the current data from the server and sets an error if one occurs. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: Returns an array of Result enums with the object if a fetch was successful or a diff --git a/Sources/ParseSwift/Objects/ParseObject+combine.swift b/Sources/ParseSwift/Objects/ParseObject+combine.swift index 925d1570e..cc79fdbc3 100644 --- a/Sources/ParseSwift/Objects/ParseObject+combine.swift +++ b/Sources/ParseSwift/Objects/ParseObject+combine.swift @@ -17,7 +17,7 @@ public extension ParseObject { Fetches the `ParseObject` *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. @@ -118,7 +118,7 @@ public extension Sequence where Element: ParseObject { Fetches a collection of objects *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces an an array of Result enums with the object if a fetch was diff --git a/Sources/ParseSwift/Objects/ParseObject.swift b/Sources/ParseSwift/Objects/ParseObject.swift index b4603a07d..e9b511bca 100644 --- a/Sources/ParseSwift/Objects/ParseObject.swift +++ b/Sources/ParseSwift/Objects/ParseObject.swift @@ -584,7 +584,7 @@ transactions for this call. /** Fetches a collection of objects *synchronously* all at once and throws an error if necessary. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: Returns an array of Result enums with the object if a fetch was successful or a @@ -625,7 +625,7 @@ transactions for this call. /** Fetches a collection of objects all at once *asynchronously* and executes the completion block when done. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default value of .main. @@ -819,7 +819,7 @@ extension ParseObject { /** Fetches the `ParseObject` *synchronously* with the current data from the server and sets an error if one occurs. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - throws: An error of `ParseError` type. @@ -837,7 +837,7 @@ extension ParseObject { /** Fetches the `ParseObject` *asynchronously* and executes the given callback block. - parameter includeKeys: The name(s) of the key(s) to include. Use `["*"]` to include - all keys. + all keys one level deep. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default value of .main. diff --git a/Sources/ParseSwift/Objects/ParseUser+async.swift b/Sources/ParseSwift/Objects/ParseUser+async.swift index affd9040f..725865460 100644 --- a/Sources/ParseSwift/Objects/ParseUser+async.swift +++ b/Sources/ParseSwift/Objects/ParseUser+async.swift @@ -184,7 +184,7 @@ public extension ParseUser { /** Fetches the `ParseUser` *aynchronously* with the current data from the server and sets an error if one occurs. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: Returns the fetched `ParseUser`. @@ -303,7 +303,7 @@ public extension Sequence where Element: ParseUser { Fetches a collection of users *aynchronously* with the current data from the server and sets an error if one occurs. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: Returns an array of Result enums with the object if a fetch was successful or a diff --git a/Sources/ParseSwift/Objects/ParseUser+combine.swift b/Sources/ParseSwift/Objects/ParseUser+combine.swift index 7a6188649..b3245da93 100644 --- a/Sources/ParseSwift/Objects/ParseUser+combine.swift +++ b/Sources/ParseSwift/Objects/ParseUser+combine.swift @@ -174,7 +174,7 @@ public extension ParseUser { Fetches the `ParseUser` *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. @@ -289,7 +289,7 @@ public extension Sequence where Element: ParseUser { Fetches a collection of users *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces an an array of Result enums with the object if a fetch was diff --git a/Sources/ParseSwift/Objects/ParseUser.swift b/Sources/ParseSwift/Objects/ParseUser.swift index 603fb521a..607a48671 100644 --- a/Sources/ParseSwift/Objects/ParseUser.swift +++ b/Sources/ParseSwift/Objects/ParseUser.swift @@ -835,7 +835,7 @@ extension ParseUser { /** Fetches the `ParseUser` *synchronously* with the current data from the server and sets an error if one occurs. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - throws: An error of `ParseError` type. @@ -856,7 +856,7 @@ extension ParseUser { /** Fetches the `ParseUser` *asynchronously* and executes the given callback block. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default @@ -1692,7 +1692,7 @@ public extension Sequence where Element: ParseUser { /** Fetches a collection of users *synchronously* all at once and throws an error if necessary. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. @@ -1735,7 +1735,7 @@ public extension Sequence where Element: ParseUser { /** Fetches a collection of users all at once *asynchronously* and executes the completion block when done. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys one level deep. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default value of .main. diff --git a/Sources/ParseSwift/Types/Query.swift b/Sources/ParseSwift/Types/Query.swift index 477c1ae4e..479f8d842 100644 --- a/Sources/ParseSwift/Types/Query.swift +++ b/Sources/ParseSwift/Types/Query.swift @@ -31,6 +31,29 @@ public struct Query: Encodable, Equatable where T: ParseObject { internal var distinct: String? internal var pipeline: [[String: AnyEncodable]]? internal var fields: Set? + var endpoint: API.Endpoint { + .objects(className: T.className) + } + + /// The className of the `ParseObject` to query. + public static var className: String { + T.className + } + + /// The className of the `ParseObject` to query. + public var className: String { + Self.className + } + + /** + Includes all nested `ParseObject`s one level deep. + - warning: Requires Parse Server 3.0.0+. + */ + public var includeAll: Query { + var mutableQuery = self + mutableQuery.include = ["*"] + return mutableQuery + } struct AggregateBody: Encodable where T: ParseObject { let pipeline: [[String: AnyEncodable]]? @@ -60,6 +83,25 @@ public struct Query: Encodable, Equatable where T: ParseObject { } } + enum CodingKeys: String, CodingKey { + case `where` + case method = "_method" + case limit + case skip + case include + case isCount = "count" + case keys + case order + case explain + case hint + case excludeKeys + case readPreference + case includeReadPreference + case subqueryReadPreference + case distinct + case pipeline + } + /** An enum that determines the order to sort the results based on a given key. @@ -215,11 +257,11 @@ public struct Query: Encodable, Equatable where T: ParseObject { /** Includes all nested `ParseObject`s one level deep. - warning: Requires Parse Server 3.0.0+. + - warning: This will be removed in ParseSwift 5.0.0 in favor of the `includeAll` computed property. */ - public func includeAll() -> Query { - var mutableQuery = self - mutableQuery.include = ["*"] - return mutableQuery + @available(*, deprecated, renamed: "includeAll") + public func includeAll(_ keys: [String]? = nil) -> Query { + self.includeAll } /** @@ -274,6 +316,14 @@ public struct Query: Encodable, Equatable where T: ParseObject { return mutableQuery } + /** + An enum that determines the order to sort the results based on a given key. + - parameter keys: A variadic list of keys to order by. + */ + public func order(_ keys: Order...) -> Query { + self.order(keys) + } + /** An enum that determines the order to sort the results based on a given key. - parameter keys: An array of keys to order by. @@ -319,39 +369,6 @@ public struct Query: Encodable, Equatable where T: ParseObject { } return mutableQuery } - - /// The className of the `ParseObject` to query. - public var className: String { - return Self.className - } - - /// The className of the `ParseObject` to query. - public static var className: String { - return T.className - } - - var endpoint: API.Endpoint { - return .objects(className: T.className) - } - - enum CodingKeys: String, CodingKey { - case `where` - case method = "_method" - case limit - case skip - case include - case isCount = "count" - case keys - case order - case explain - case hint - case excludeKeys - case readPreference - case includeReadPreference - case subqueryReadPreference - case distinct - case pipeline - } } // MARK: Queryable diff --git a/Tests/ParseSwiftTests/ParseQueryTests.swift b/Tests/ParseSwiftTests/ParseQueryTests.swift index 1401046e5..fe7ca8b28 100644 --- a/Tests/ParseSwiftTests/ParseQueryTests.swift +++ b/Tests/ParseSwiftTests/ParseQueryTests.swift @@ -155,7 +155,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length func testOrder() { let query = GameScore.query() XCTAssertNil(query.order) - let query2 = GameScore.query().order([.ascending("yolo")]) + let query2 = GameScore.query().order(.ascending("yolo")) XCTAssertNotNil(query2.order) } @@ -165,8 +165,8 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length XCTAssertNil(query.includeReadPreference) XCTAssertNil(query.subqueryReadPreference) let query2 = GameScore.query().readPreference("PRIMARY", - includeReadPreference: "SECONDARY", - subqueryReadPreference: "SECONDARY_PREFERRED") + includeReadPreference: "SECONDARY", + subqueryReadPreference: "SECONDARY_PREFERRED") XCTAssertNotNil(query2.readPreference) XCTAssertNotNil(query2.includeReadPreference) XCTAssertNotNil(query2.subqueryReadPreference)