Skip to content

Commit d666556

Browse files
authored
Improve aggregate by accepting any Encodable type (#122)
* 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
1 parent ee481d4 commit d666556

File tree

13 files changed

+832
-173
lines changed

13 files changed

+832
-173
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Parse-Swift Changelog
22

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

7+
### 1.5.0
8+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.4.0...1.5.0)
9+
10+
__Improvements__
11+
- (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).
12+
713
### 1.4.0
814
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.3.1...1.4.0)
915

ParseSwift.playground/Pages/7 - GeoPoint.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ query2.find { result in
196196
}
197197

198198
//: Explain the previous query.
199-
let explain: AnyDecodable = try query2.first(explain: true)
199+
let explain: AnyDecodable = try query8.firstExplain()
200200
print(explain)
201201

202202
PlaygroundPage.current.finishExecution()

ParseSwift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "ParseSwift"
3-
s.version = "1.4.0"
3+
s.version = "1.5.0"
44
s.summary = "Parse Pure Swift SDK"
55
s.homepage = "https://github.com/parse-community/Parse-Swift"
66
s.authors = {

ParseSwift.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,7 +2329,7 @@
23292329
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
23302330
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
23312331
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2332-
MARKETING_VERSION = 1.4.0;
2332+
MARKETING_VERSION = 1.5.0;
23332333
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
23342334
PRODUCT_NAME = ParseSwift;
23352335
SKIP_INSTALL = YES;
@@ -2353,7 +2353,7 @@
23532353
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
23542354
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
23552355
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2356-
MARKETING_VERSION = 1.4.0;
2356+
MARKETING_VERSION = 1.5.0;
23572357
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
23582358
PRODUCT_NAME = ParseSwift;
23592359
SKIP_INSTALL = YES;
@@ -2419,7 +2419,7 @@
24192419
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
24202420
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
24212421
MACOSX_DEPLOYMENT_TARGET = 10.13;
2422-
MARKETING_VERSION = 1.4.0;
2422+
MARKETING_VERSION = 1.5.0;
24232423
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
24242424
PRODUCT_NAME = ParseSwift;
24252425
SDKROOT = macosx;
@@ -2445,7 +2445,7 @@
24452445
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
24462446
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
24472447
MACOSX_DEPLOYMENT_TARGET = 10.13;
2448-
MARKETING_VERSION = 1.4.0;
2448+
MARKETING_VERSION = 1.5.0;
24492449
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
24502450
PRODUCT_NAME = ParseSwift;
24512451
SDKROOT = macosx;
@@ -2592,7 +2592,7 @@
25922592
INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist";
25932593
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
25942594
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2595-
MARKETING_VERSION = 1.4.0;
2595+
MARKETING_VERSION = 1.5.0;
25962596
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
25972597
MTL_FAST_MATH = YES;
25982598
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS";
@@ -2621,7 +2621,7 @@
26212621
INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist";
26222622
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
26232623
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2624-
MARKETING_VERSION = 1.4.0;
2624+
MARKETING_VERSION = 1.5.0;
26252625
MTL_FAST_MATH = YES;
26262626
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS";
26272627
PRODUCT_NAME = ParseSwift;
@@ -2648,7 +2648,7 @@
26482648
INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist";
26492649
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
26502650
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2651-
MARKETING_VERSION = 1.4.0;
2651+
MARKETING_VERSION = 1.5.0;
26522652
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
26532653
MTL_FAST_MATH = YES;
26542654
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS";
@@ -2676,7 +2676,7 @@
26762676
INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist";
26772677
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
26782678
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2679-
MARKETING_VERSION = 1.4.0;
2679+
MARKETING_VERSION = 1.5.0;
26802680
MTL_FAST_MATH = YES;
26812681
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS";
26822682
PRODUCT_NAME = ParseSwift;

Scripts/jazzy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ bundle exec jazzy \
55
--author_url http://parseplatform.org \
66
--github_url https://github.com/parse-community/Parse-Swift \
77
--root-url http://parseplatform.org/Parse-Swift/api/ \
8-
--module-version 1.4.0 \
8+
--module-version 1.5.0 \
99
--theme fullwidth \
1010
--skip-undocumented \
1111
--output ./docs/api \

Sources/ParseSwift/ParseConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
enum ParseConstants {
12-
static let parseVersion = "1.4.0"
12+
static let parseVersion = "1.5.0"
1313
static let hashingKey = "parseSwift"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"

Sources/ParseSwift/Types/ParseFile+combine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public extension ParseFile {
8080

8181
/**
8282
Deletes the file from the Parse Server. Publishes when complete.
83-
- requires: `.useMasterKey` has to be available and passed as one of the set of `options`.
83+
- requires: `.useMasterKey` has to be available.
8484
- parameter options: A set of header options sent to the server. Defaults to an empty set.
8585
- returns: A publisher that eventually produces a single value and then finishes or fails.
8686
*/

Sources/ParseSwift/Types/ParseFile.swift

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,21 @@ extension ParseFile {
158158
extension ParseFile {
159159
/**
160160
Deletes the file from the Parse cloud.
161-
- requires: `.useMasterKey` has to be available and passed as one of the set of `options`.
161+
- requires: `.useMasterKey` has to be available.
162162
- parameter options: A set of header options sent to the server. Defaults to an empty set.
163163
- throws: A `ParseError` if there was an issue deleting the file. Otherwise it was successful.
164164
*/
165165
public func delete(options: API.Options) throws {
166166
var options = options
167+
options.insert(.useMasterKey)
167168
options = options.union(self.options)
168169

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

176173
/**
177174
Deletes the file from the Parse cloud. Completes with `nil` if successful.
178-
- requires: `.useMasterKey` has to be available and passed as one of the set of `options`.
175+
- requires: `.useMasterKey` has to be available.
179176
- parameter options: A set of header options sent to the server. Defaults to an empty set.
180177
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
181178
- parameter completion: A block that will be called when file deletes or fails.
@@ -185,16 +182,9 @@ extension ParseFile {
185182
callbackQueue: DispatchQueue = .main,
186183
completion: @escaping (Result<Void, ParseError>) -> Void) {
187184
var options = options
185+
options.insert(.useMasterKey)
188186
options = options.union(self.options)
189187

190-
if !options.contains(.useMasterKey) {
191-
callbackQueue.async {
192-
completion(.failure(ParseError(code: .unknownError,
193-
// swiftlint:disable:next line_length
194-
message: "You must specify \"useMasterKey\" in \"options\" in order to delete a file.")))
195-
}
196-
return
197-
}
198188
deleteFileCommand().executeAsync(options: options, callbackQueue: callbackQueue) { result in
199189
callbackQueue.async {
200190
switch result {

Sources/ParseSwift/Types/Query+combine.swift

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,14 @@ public extension Query {
2929
}
3030

3131
/**
32-
Finds objects *asynchronously* and publishes when complete.
33-
- parameter explain: Used to toggle the information on the query plan.
32+
Query plan information for finding objects *asynchronously* and publishes when complete.
3433
- parameter options: A set of header options sent to the server. Defaults to an empty set.
3534
- returns: A publisher that eventually produces a single value and then finishes or fails.
3635
*/
37-
func findPublisher<U: Decodable>(explain: Bool,
38-
options: API.Options = []) -> Future<[U], ParseError> {
36+
func findExplainPublisher<U: Decodable>(options: API.Options = []) -> Future<[U], ParseError> {
3937
Future { promise in
40-
self.find(explain: explain,
41-
options: options,
42-
completion: promise)
38+
self.findExplain(options: options,
39+
completion: promise)
4340
}
4441
}
4542

@@ -74,17 +71,14 @@ public extension Query {
7471
}
7572

7673
/**
77-
Gets an object *asynchronously* and publishes when complete.
78-
- parameter explain: Used to toggle the information on the query plan.
74+
Query plan information for getting an object *asynchronously* and publishes when complete.
7975
- parameter options: A set of header options sent to the server. Defaults to an empty set.
8076
- returns: A publisher that eventually produces a single value and then finishes or fails.
8177
*/
82-
func firstPublisher<U: Decodable>(explain: Bool,
83-
options: API.Options = []) -> Future<U, ParseError> {
78+
func firstExplainPublisher<U: Decodable>(options: API.Options = []) -> Future<U, ParseError> {
8479
Future { promise in
85-
self.first(explain: explain,
86-
options: options,
87-
completion: promise)
80+
self.firstExplain(options: options,
81+
completion: promise)
8882
}
8983
}
9084

@@ -101,35 +95,81 @@ public extension Query {
10195
}
10296

10397
/**
104-
Count objects *asynchronously* and publishes when complete.
98+
Query plan information for counting objects *asynchronously* and publishes when complete.
10599
- parameter explain: Used to toggle the information on the query plan.
106100
- parameter options: A set of header options sent to the server. Defaults to an empty set.
107101
- returns: A publisher that eventually produces a single value and then finishes or fails.
108102
*/
109-
func countPublisher<U: Decodable>(explain: Bool,
110-
options: API.Options = []) -> Future<U, ParseError> {
103+
func countExplainPublisher<U: Decodable>(options: API.Options = []) -> Future<U, ParseError> {
111104
Future { promise in
112-
self.count(explain: explain,
113-
options: options,
114-
completion: promise)
105+
self.countExplain(options: options,
106+
completion: promise)
115107
}
116108
}
117109

118110
/**
119111
Executes an aggregate query *asynchronously* and publishes when complete.
120-
- requires: `.useMasterKey` has to be available and passed as one of the set of `options`.
112+
- requires: `.useMasterKey` has to be available.
121113
- parameter pipeline: A pipeline of stages to process query.
122114
- parameter options: A set of header options sent to the server. Defaults to an empty set.
123115
- returns: A publisher that eventually produces a single value and then finishes or fails.
124116
*/
125-
func aggregatePublisher(_ pipeline: AggregateType,
117+
func aggregatePublisher(_ pipeline: [[String: Encodable]],
126118
options: API.Options = []) -> Future<[ResultType], ParseError> {
127119
Future { promise in
128120
self.aggregate(pipeline,
129121
options: options,
130122
completion: promise)
131123
}
132124
}
125+
126+
/**
127+
Query plan information for executing an aggregate query *asynchronously* and publishes when complete.
128+
- requires: `.useMasterKey` has to be available.
129+
- parameter pipeline: A pipeline of stages to process query.
130+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
131+
- returns: A publisher that eventually produces a single value and then finishes or fails.
132+
*/
133+
func aggregateExplainPublisher<U: Decodable>(_ pipeline: [[String: Encodable]],
134+
options: API.Options = []) -> Future<[U], ParseError> {
135+
Future { promise in
136+
self.aggregateExplain(pipeline,
137+
options: options,
138+
completion: promise)
139+
}
140+
}
141+
142+
/**
143+
Executes a distinct query *asynchronously* and publishes unique values when complete.
144+
- requires: `.useMasterKey` has to be available.
145+
- parameter key: A field to find distinct values.
146+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
147+
- returns: A publisher that eventually produces a single value and then finishes or fails.
148+
*/
149+
func distinctPublisher(_ key: String,
150+
options: API.Options = []) -> Future<[ResultType], ParseError> {
151+
Future { promise in
152+
self.distinct(key,
153+
options: options,
154+
completion: promise)
155+
}
156+
}
157+
158+
/**
159+
Query plan information for executing a distinct query *asynchronously* and publishes unique values when complete.
160+
- requires: `.useMasterKey` has to be available.
161+
- parameter key: A field to find distinct values.
162+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
163+
- returns: A publisher that eventually produces a single value and then finishes or fails.
164+
*/
165+
func distinctExplainPublisher<U: Decodable>(_ key: String,
166+
options: API.Options = []) -> Future<[U], ParseError> {
167+
Future { promise in
168+
self.distinctExplain(key,
169+
options: options,
170+
completion: promise)
171+
}
172+
}
133173
}
134174

135175
#endif

0 commit comments

Comments
 (0)