Skip to content

Commit 2a32091

Browse files
committed
Run style.sh
1 parent 76d0ae8 commit 2a32091

File tree

8 files changed

+249
-178
lines changed

8 files changed

+249
-178
lines changed

Firestore/Example/Tests/Integration/API/FIRGetOptionsTests.m

Lines changed: 153 additions & 134 deletions
Large diffs are not rendered by default.

Firestore/Example/Tests/Util/FSTIntegrationTestCase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ extern "C" {
7373

7474
- (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref;
7575

76-
- (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref options:(FIRGetOptions *)options;
76+
- (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref
77+
options:(FIRGetOptions *)options;
7778

7879
- (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query;
7980

Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,17 @@ - (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref {
212212
return [self readDocumentForRef:ref options:[FIRGetOptions defaultOptions]];
213213
}
214214

215-
- (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref options:(FIRGetOptions *)options {
215+
- (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref
216+
options:(FIRGetOptions *)options {
216217
__block FIRDocumentSnapshot *result;
217218

218219
XCTestExpectation *expectation = [self expectationWithDescription:@"getData"];
219-
[ref getDocumentWithOptions:options completion:^(FIRDocumentSnapshot *doc, NSError *_Nullable error) {
220-
XCTAssertNil(error);
221-
result = doc;
222-
[expectation fulfill];
223-
}];
220+
[ref getDocumentWithOptions:options
221+
completion:^(FIRDocumentSnapshot *doc, NSError *_Nullable error) {
222+
XCTAssertNil(error);
223+
result = doc;
224+
[expectation fulfill];
225+
}];
224226
[self awaitExpectations];
225227

226228
return result;
@@ -234,11 +236,12 @@ - (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query options:(FIRGetOpt
234236
__block FIRQuerySnapshot *result;
235237

236238
XCTestExpectation *expectation = [self expectationWithDescription:@"getData"];
237-
[query getDocumentsWithOptions:options completion:^(FIRQuerySnapshot *documentSet, NSError *error) {
238-
XCTAssertNil(error);
239-
result = documentSet;
240-
[expectation fulfill];
241-
}];
239+
[query getDocumentsWithOptions:options
240+
completion:^(FIRQuerySnapshot *documentSet, NSError *error) {
241+
XCTAssertNil(error);
242+
result = documentSet;
243+
[expectation fulfill];
244+
}];
242245
[self awaitExpectations];
243246

244247
return result;

Firestore/Source/API/FIRDocumentReference.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ - (void)getDocumentWithCompletion:(void (^)(FIRDocumentSnapshot *_Nullable docum
213213
return [self getDocumentWithOptions:[FIRGetOptions defaultOptions] completion:completion];
214214
}
215215

216-
- (void)getDocumentWithOptions:(FIRGetOptions *)options completion:(void (^)(FIRDocumentSnapshot *_Nullable document,
217-
NSError *_Nullable error))completion {
216+
- (void)getDocumentWithOptions:(FIRGetOptions *)options
217+
completion:(void (^)(FIRDocumentSnapshot *_Nullable document,
218+
NSError *_Nullable error))completion {
218219
if (options.source == FIRCache) {
219220
[self.firestore.client getDocumentFromLocalCache:self completion:completion];
220221
return;
@@ -255,7 +256,15 @@ - (void)getDocumentWithOptions:(FIRGetOptions *)options completion:(void (^)(FIR
255256
@"Failed to get document because the client is offline.",
256257
}]);
257258
} else if (snapshot.exists && snapshot.metadata.fromCache && options.source == FIRServer) {
258-
completion(nil, [NSError errorWithDomain:FIRFirestoreErrorDomain code:FIRFirestoreErrorCodeUnavailable userInfo:@{NSLocalizedDescriptionKey: @"Failed to get document from server. (However, this document does exist in the local cache. Run again without setting FIRServer in the GetOptions to retrieve the cached document.)"}]);
259+
completion(nil, [NSError errorWithDomain:FIRFirestoreErrorDomain
260+
code:FIRFirestoreErrorCodeUnavailable
261+
userInfo:@{
262+
NSLocalizedDescriptionKey :
263+
@"Failed to get document from server. (However, this "
264+
@"document does exist in the local cache. Run again "
265+
@"without setting FIRServer in the GetOptions to "
266+
@"retrieve the cached document.)"
267+
}]);
259268
} else {
260269
completion(snapshot, nil);
261270
}

Firestore/Source/API/FIRQuery.m

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,18 @@ - (void)getDocumentsWithCompletion:(void (^)(FIRQuerySnapshot *_Nullable snapsho
135135
[self getDocumentsWithOptions:[FIRGetOptions defaultOptions] completion:completion];
136136
}
137137

138-
- (void)getDocumentsWithOptions:(FIRGetOptions *)options completion:(void (^)(FIRQuerySnapshot *_Nullable snapshot, NSError *_Nullable error))completion {
138+
- (void)getDocumentsWithOptions:(FIRGetOptions *)options
139+
completion:(void (^)(FIRQuerySnapshot *_Nullable snapshot,
140+
NSError *_Nullable error))completion {
139141
if (options.source == FIRCache) {
140142
[self.firestore.client getDocumentsFromLocalCache:self completion:completion];
141143
return;
142144
}
143145

144-
FSTListenOptions *listenOptions = [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:YES
145-
includeDocumentMetadataChanges:YES
146-
waitForSyncWhenOnline:YES];
146+
FSTListenOptions *listenOptions =
147+
[[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:YES
148+
includeDocumentMetadataChanges:YES
149+
waitForSyncWhenOnline:YES];
147150

148151
dispatch_semaphore_t registered = dispatch_semaphore_create(0);
149152
__block id<FIRListenerRegistration> listenerRegistration;
@@ -159,13 +162,22 @@ - (void)getDocumentsWithOptions:(FIRGetOptions *)options completion:(void (^)(FI
159162
[listenerRegistration remove];
160163

161164
if (snapshot.metadata.fromCache && options.source == FIRServer) {
162-
completion(nil, [NSError errorWithDomain:FIRFirestoreErrorDomain code:FIRFirestoreErrorCodeUnavailable userInfo:@{NSLocalizedDescriptionKey: @"Failed to get documents from server. (However, these documents may exist in the local cache. Run again without setting FIRServer in the GetOptions to retrieve the cached documents.)"}]);
165+
completion(nil, [NSError errorWithDomain:FIRFirestoreErrorDomain
166+
code:FIRFirestoreErrorCodeUnavailable
167+
userInfo:@{
168+
NSLocalizedDescriptionKey :
169+
@"Failed to get documents from server. (However, these "
170+
@"documents may exist in the local cache. Run again "
171+
@"without setting FIRServer in the GetOptions to "
172+
@"retrieve the cached documents.)"
173+
}]);
163174
} else {
164175
completion(snapshot, nil);
165176
}
166177
};
167178

168-
listenerRegistration = [self addSnapshotListenerInternalWithOptions:listenOptions listener:listener];
179+
listenerRegistration =
180+
[self addSnapshotListenerInternalWithOptions:listenOptions listener:listener];
169181
dispatch_semaphore_signal(registered);
170182
}
171183

Firestore/Source/Core/FSTFirestoreClient.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,17 @@ NS_ASSUME_NONNULL_BEGIN
7878
* Retrieves a document from the cache via the indicated completion. If the doc
7979
* doesn't exist, an error will be sent to the completion.
8080
*/
81-
- (void)getDocumentFromLocalCache:(FIRDocumentReference *)doc completion:(void (^)(FIRDocumentSnapshot *_Nullable document, NSError *_Nullable error))completion;
81+
- (void)getDocumentFromLocalCache:(FIRDocumentReference *)doc
82+
completion:(void (^)(FIRDocumentSnapshot *_Nullable document,
83+
NSError *_Nullable error))completion;
8284

8385
/**
8486
* Retrieves a (possibly empty) set of documents from the cache via the
8587
* indicated completion.
8688
*/
87-
- (void)getDocumentsFromLocalCache:(FIRQuery *)query completion:(void (^)(FIRQuerySnapshot *_Nullable query, NSError *_Nullable error))completion;
89+
- (void)getDocumentsFromLocalCache:(FIRQuery *)query
90+
completion:(void (^)(FIRQuerySnapshot *_Nullable query,
91+
NSError *_Nullable error))completion;
8892

8993
/** Write mutations. completion will be notified when it's written to the backend. */
9094
- (void)writeMutations:(NSArray<FSTMutation *> *)mutations

Firestore/Source/Core/FSTFirestoreClient.m

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@
1717
#import "Firestore/Source/Core/FSTFirestoreClient.h"
1818

1919
#import "FIRFirestoreErrors.h"
20+
#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
21+
#import "Firestore/Source/API/FIRDocumentSnapshot+Internal.h"
22+
#import "Firestore/Source/API/FIRQuery+Internal.h"
23+
#import "Firestore/Source/API/FIRQuerySnapshot+Internal.h"
24+
#import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h"
2025
#import "Firestore/Source/Auth/FSTCredentialsProvider.h"
2126
#import "Firestore/Source/Core/FSTDatabaseInfo.h"
2227
#import "Firestore/Source/Core/FSTEventManager.h"
28+
#import "Firestore/Source/Core/FSTQuery.h"
2329
#import "Firestore/Source/Core/FSTSyncEngine.h"
2430
#import "Firestore/Source/Core/FSTTransaction.h"
25-
#import "Firestore/Source/Core/FSTQuery.h"
2631
#import "Firestore/Source/Local/FSTEagerGarbageCollector.h"
2732
#import "Firestore/Source/Local/FSTLevelDB.h"
2833
#import "Firestore/Source/Local/FSTLocalSerializer.h"
@@ -38,12 +43,6 @@
3843
#import "Firestore/Source/Util/FSTClasses.h"
3944
#import "Firestore/Source/Util/FSTDispatchQueue.h"
4045
#import "Firestore/Source/Util/FSTLogger.h"
41-
#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
42-
#import "Firestore/Source/API/FIRDocumentSnapshot+Internal.h"
43-
#import "Firestore/Source/API/FIRQuery+Internal.h"
44-
#import "Firestore/Source/API/FIRQuerySnapshot+Internal.h"
45-
#import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h"
46-
4746

4847
NS_ASSUME_NONNULL_BEGIN
4948

@@ -259,31 +258,59 @@ - (void)removeListener:(FSTQueryListener *)listener {
259258
}];
260259
}
261260

262-
- (void)getDocumentFromLocalCache:(FIRDocumentReference *)doc completion:(void (^)(FIRDocumentSnapshot *_Nullable document, NSError *_Nullable error))completion {
261+
- (void)getDocumentFromLocalCache:(FIRDocumentReference *)doc
262+
completion:(void (^)(FIRDocumentSnapshot *_Nullable document,
263+
NSError *_Nullable error))completion {
263264
[self.workerDispatchQueue dispatchAsync:^{
264265
FSTMaybeDocument *maybeDoc = [self.localStore readDocument:doc.key];
265266
if (maybeDoc) {
266-
completion([FIRDocumentSnapshot snapshotWithFirestore:doc.firestore documentKey:doc.key document:(FSTDocument *)maybeDoc fromCache:YES], nil);
267+
completion([FIRDocumentSnapshot snapshotWithFirestore:doc.firestore
268+
documentKey:doc.key
269+
document:(FSTDocument *)maybeDoc
270+
fromCache:YES],
271+
nil);
267272
} else {
268-
completion(nil, [NSError errorWithDomain:FIRFirestoreErrorDomain code:FIRFirestoreErrorCodeUnavailable userInfo:@{NSLocalizedDescriptionKey: @"Failed to get document from cache. (However, this document may exist on the server. Run again without setting FIRCache in the GetOptions to attempt to retrieve the document from the server.)",}]);
273+
completion(nil, [NSError errorWithDomain:FIRFirestoreErrorDomain
274+
code:FIRFirestoreErrorCodeUnavailable
275+
userInfo:@{
276+
NSLocalizedDescriptionKey :
277+
@"Failed to get document from cache. (However, this "
278+
@"document may exist on the server. Run again without "
279+
@"setting FIRCache in the GetOptions to attempt to "
280+
@"retrieve the document from the server.)",
281+
}]);
269282
}
270283
}];
271284
}
272285

273-
- (void)getDocumentsFromLocalCache:(FIRQuery *)query completion:(void (^)(FIRQuerySnapshot *_Nullable query, NSError *_Nullable error))completion {
286+
- (void)getDocumentsFromLocalCache:(FIRQuery *)query
287+
completion:(void (^)(FIRQuerySnapshot *_Nullable query,
288+
NSError *_Nullable error))completion {
274289
[self.workerDispatchQueue dispatchAsync:^{
275290
FSTDocumentDictionary *docs = [self.localStore executeQuery:query.query];
276291

277-
__block FSTDocumentSet *documents = [FSTDocumentSet documentSetWithComparator:query.query.comparator];
292+
__block FSTDocumentSet *documents =
293+
[FSTDocumentSet documentSetWithComparator:query.query.comparator];
278294
FSTDocumentSet *oldDocuments = documents;
279295
[docs enumerateKeysAndObjectsUsingBlock:^(FSTDocumentKey *key, FSTDocument *value, BOOL *stop) {
280296
documents = [documents documentSetByAddingDocument:value];
281297
}];
282298

283-
FSTViewSnapshot *snapshot = [[FSTViewSnapshot alloc] initWithQuery:query.query documents:documents oldDocuments:oldDocuments documentChanges:@[] fromCache:YES hasPendingWrites:NO syncStateChanged:NO];
284-
FIRSnapshotMetadata *metadata = [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:NO fromCache:YES];
285-
286-
completion([FIRQuerySnapshot snapshotWithFirestore:query.firestore originalQuery:query.query snapshot:snapshot metadata:metadata], nil);
299+
FSTViewSnapshot *snapshot = [[FSTViewSnapshot alloc] initWithQuery:query.query
300+
documents:documents
301+
oldDocuments:oldDocuments
302+
documentChanges:@[]
303+
fromCache:YES
304+
hasPendingWrites:NO
305+
syncStateChanged:NO];
306+
FIRSnapshotMetadata *metadata =
307+
[FIRSnapshotMetadata snapshotMetadataWithPendingWrites:NO fromCache:YES];
308+
309+
completion([FIRQuerySnapshot snapshotWithFirestore:query.firestore
310+
originalQuery:query.query
311+
snapshot:snapshot
312+
metadata:metadata],
313+
nil);
287314
}];
288315
}
289316

Firestore/Source/Public/FIRGetOptions.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ NS_SWIFT_NAME(GetOptions)
5353
* stale with respect to the value on the server.) For a single document, the
5454
* get will fail if the document doesn't exist.
5555
*/
56-
typedef NS_ENUM(NSUInteger, FIRSource) {
57-
FIRDefault,
58-
FIRServer,
59-
FIRCache
60-
} NS_SWIFT_NAME(Source);
56+
typedef NS_ENUM(NSUInteger, FIRSource) { FIRDefault, FIRServer, FIRCache } NS_SWIFT_NAME(Source);
6157

6258
/**
6359
* Initializes the get options with the specified source.

0 commit comments

Comments
 (0)