Skip to content

Commit

Permalink
Improve aggregate by accepting any Encodable type (#122)
Browse files Browse the repository at this point in the history
* Improve aggregate by accepting any type. Remove MasterKey check for File and let server decide to delete file

* Add distinct and testcases

* Fix delete file for Linux

* remove linux tests

* Update playgrounds

* Remove distinct from playgrounds
  • Loading branch information
cbaker6 authored Apr 14, 2021
1 parent ee481d4 commit d666556
Show file tree
Hide file tree
Showing 13 changed files with 832 additions and 173 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Parse-Swift Changelog

### main
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.4.0...main)
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.5.0...main)
* _Contributing to this repo? Add info about your change here to be included in the next release_

### 1.5.0
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.4.0...1.5.0)

__Improvements__
- (Breaking Change) Aggregrate takes any Encodable type. Query planning methods are now: findExlpain, firstEplain, countExplain, etc. The distinct query now works. The client will also not throw an error anymore when attempting to delete a File and the masterKey isn't available. The developer will still need to configure the server to delete the file properly ([#122](https://github.com/parse-community/Parse-Swift/pull/122)), thanks to [Corey Baker](https://github.com/cbaker6).

### 1.4.0
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.3.1...1.4.0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ query2.find { result in
}

//: Explain the previous query.
let explain: AnyDecodable = try query2.first(explain: true)
let explain: AnyDecodable = try query8.firstExplain()
print(explain)

PlaygroundPage.current.finishExecution()
Expand Down
2 changes: 1 addition & 1 deletion ParseSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ParseSwift"
s.version = "1.4.0"
s.version = "1.5.0"
s.summary = "Parse Pure Swift SDK"
s.homepage = "https://github.com/parse-community/Parse-Swift"
s.authors = {
Expand Down
16 changes: 8 additions & 8 deletions ParseSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2329,7 +2329,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.4.0;
MARKETING_VERSION = 1.5.0;
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
PRODUCT_NAME = ParseSwift;
SKIP_INSTALL = YES;
Expand All @@ -2353,7 +2353,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.4.0;
MARKETING_VERSION = 1.5.0;
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
PRODUCT_NAME = ParseSwift;
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -2419,7 +2419,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.4.0;
MARKETING_VERSION = 1.5.0;
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
PRODUCT_NAME = ParseSwift;
SDKROOT = macosx;
Expand All @@ -2445,7 +2445,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.4.0;
MARKETING_VERSION = 1.5.0;
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
PRODUCT_NAME = ParseSwift;
SDKROOT = macosx;
Expand Down Expand Up @@ -2592,7 +2592,7 @@
INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.4.0;
MARKETING_VERSION = 1.5.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS";
Expand Down Expand Up @@ -2621,7 +2621,7 @@
INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.4.0;
MARKETING_VERSION = 1.5.0;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS";
PRODUCT_NAME = ParseSwift;
Expand All @@ -2648,7 +2648,7 @@
INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.4.0;
MARKETING_VERSION = 1.5.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS";
Expand Down Expand Up @@ -2676,7 +2676,7 @@
INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.4.0;
MARKETING_VERSION = 1.5.0;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS";
PRODUCT_NAME = ParseSwift;
Expand Down
2 changes: 1 addition & 1 deletion Scripts/jazzy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ bundle exec jazzy \
--author_url http://parseplatform.org \
--github_url https://github.com/parse-community/Parse-Swift \
--root-url http://parseplatform.org/Parse-Swift/api/ \
--module-version 1.4.0 \
--module-version 1.5.0 \
--theme fullwidth \
--skip-undocumented \
--output ./docs/api \
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

enum ParseConstants {
static let parseVersion = "1.4.0"
static let parseVersion = "1.5.0"
static let hashingKey = "parseSwift"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Types/ParseFile+combine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public extension ParseFile {

/**
Deletes the file from the Parse Server. Publishes when complete.
- requires: `.useMasterKey` has to be available and passed as one of the set of `options`.
- requires: `.useMasterKey` has to be available.
- 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.
*/
Expand Down
18 changes: 4 additions & 14 deletions Sources/ParseSwift/Types/ParseFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,21 @@ extension ParseFile {
extension ParseFile {
/**
Deletes the file from the Parse cloud.
- requires: `.useMasterKey` has to be available and passed as one of the set of `options`.
- requires: `.useMasterKey` has to be available.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- throws: A `ParseError` if there was an issue deleting the file. Otherwise it was successful.
*/
public func delete(options: API.Options) throws {
var options = options
options.insert(.useMasterKey)
options = options.union(self.options)

if !options.contains(.useMasterKey) {
throw ParseError(code: .unknownError,
message: "You must specify \"useMasterKey\" in \"options\" in order to delete a file.")
}
_ = try deleteFileCommand().execute(options: options, callbackQueue: .main)
}

/**
Deletes the file from the Parse cloud. Completes with `nil` if successful.
- requires: `.useMasterKey` has to be available and passed as one of the set of `options`.
- requires: `.useMasterKey` has to be available.
- 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.
- parameter completion: A block that will be called when file deletes or fails.
Expand All @@ -185,16 +182,9 @@ extension ParseFile {
callbackQueue: DispatchQueue = .main,
completion: @escaping (Result<Void, ParseError>) -> Void) {
var options = options
options.insert(.useMasterKey)
options = options.union(self.options)

if !options.contains(.useMasterKey) {
callbackQueue.async {
completion(.failure(ParseError(code: .unknownError,
// swiftlint:disable:next line_length
message: "You must specify \"useMasterKey\" in \"options\" in order to delete a file.")))
}
return
}
deleteFileCommand().executeAsync(options: options, callbackQueue: callbackQueue) { result in
callbackQueue.async {
switch result {
Expand Down
84 changes: 62 additions & 22 deletions Sources/ParseSwift/Types/Query+combine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@ public extension Query {
}

/**
Finds objects *asynchronously* and publishes when complete.
- parameter explain: Used to toggle the information on the query plan.
Query plan information for finding objects *asynchronously* and publishes when complete.
- 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.
*/
func findPublisher<U: Decodable>(explain: Bool,
options: API.Options = []) -> Future<[U], ParseError> {
func findExplainPublisher<U: Decodable>(options: API.Options = []) -> Future<[U], ParseError> {
Future { promise in
self.find(explain: explain,
options: options,
completion: promise)
self.findExplain(options: options,
completion: promise)
}
}

Expand Down Expand Up @@ -74,17 +71,14 @@ public extension Query {
}

/**
Gets an object *asynchronously* and publishes when complete.
- parameter explain: Used to toggle the information on the query plan.
Query plan information for getting an object *asynchronously* and publishes when complete.
- 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.
*/
func firstPublisher<U: Decodable>(explain: Bool,
options: API.Options = []) -> Future<U, ParseError> {
func firstExplainPublisher<U: Decodable>(options: API.Options = []) -> Future<U, ParseError> {
Future { promise in
self.first(explain: explain,
options: options,
completion: promise)
self.firstExplain(options: options,
completion: promise)
}
}

Expand All @@ -101,35 +95,81 @@ public extension Query {
}

/**
Count objects *asynchronously* and publishes when complete.
Query plan information for counting objects *asynchronously* and publishes when complete.
- parameter explain: Used to toggle the information on the query plan.
- 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.
*/
func countPublisher<U: Decodable>(explain: Bool,
options: API.Options = []) -> Future<U, ParseError> {
func countExplainPublisher<U: Decodable>(options: API.Options = []) -> Future<U, ParseError> {
Future { promise in
self.count(explain: explain,
options: options,
completion: promise)
self.countExplain(options: options,
completion: promise)
}
}

/**
Executes an aggregate query *asynchronously* and publishes when complete.
- requires: `.useMasterKey` has to be available and passed as one of the set of `options`.
- requires: `.useMasterKey` has to be available.
- parameter pipeline: A pipeline of stages to process 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.
*/
func aggregatePublisher(_ pipeline: AggregateType,
func aggregatePublisher(_ pipeline: [[String: Encodable]],
options: API.Options = []) -> Future<[ResultType], ParseError> {
Future { promise in
self.aggregate(pipeline,
options: options,
completion: promise)
}
}

/**
Query plan information for executing an aggregate query *asynchronously* and publishes when complete.
- requires: `.useMasterKey` has to be available.
- parameter pipeline: A pipeline of stages to process 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.
*/
func aggregateExplainPublisher<U: Decodable>(_ pipeline: [[String: Encodable]],
options: API.Options = []) -> Future<[U], ParseError> {
Future { promise in
self.aggregateExplain(pipeline,
options: options,
completion: promise)
}
}

/**
Executes a distinct query *asynchronously* and publishes unique values when complete.
- requires: `.useMasterKey` has to be available.
- parameter key: A field to find distinct values.
- 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.
*/
func distinctPublisher(_ key: String,
options: API.Options = []) -> Future<[ResultType], ParseError> {
Future { promise in
self.distinct(key,
options: options,
completion: promise)
}
}

/**
Query plan information for executing a distinct query *asynchronously* and publishes unique values when complete.
- requires: `.useMasterKey` has to be available.
- parameter key: A field to find distinct values.
- 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.
*/
func distinctExplainPublisher<U: Decodable>(_ key: String,
options: API.Options = []) -> Future<[U], ParseError> {
Future { promise in
self.distinctExplain(key,
options: options,
completion: promise)
}
}
}

#endif
Loading

0 comments on commit d666556

Please sign in to comment.