FSTFirestoreClient.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import "Firestore/Source/Core/FSTTypes.h"
  18. #import "Firestore/Source/Core/FSTViewSnapshot.h"
  19. #import "Firestore/Source/Remote/FSTRemoteStore.h"
  20. #include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
  21. #include "Firestore/core/src/firebase/firestore/core/database_info.h"
  22. #include "Firestore/core/src/firebase/firestore/model/database_id.h"
  23. @class FIRDocumentReference;
  24. @class FIRDocumentSnapshot;
  25. @class FIRQuery;
  26. @class FIRQuerySnapshot;
  27. @class FSTDatabaseID;
  28. @class FSTDatabaseInfo;
  29. @class FSTDispatchQueue;
  30. @class FSTDocument;
  31. @class FSTListenOptions;
  32. @class FSTMutation;
  33. @class FSTQuery;
  34. @class FSTQueryListener;
  35. @class FSTTransaction;
  36. NS_ASSUME_NONNULL_BEGIN
  37. /**
  38. * FirestoreClient is a top-level class that constructs and owns all of the pieces of the client
  39. * SDK architecture. It is responsible for creating the worker queue that is shared by all of the
  40. * other components in the system.
  41. */
  42. @interface FSTFirestoreClient : NSObject <FSTOnlineStateDelegate>
  43. /**
  44. * Creates and returns a FSTFirestoreClient with the given parameters.
  45. *
  46. * All callbacks and events will be triggered on the provided userDispatchQueue.
  47. */
  48. + (instancetype)clientWithDatabaseInfo:(const firebase::firestore::core::DatabaseInfo &)databaseInfo
  49. usePersistence:(BOOL)usePersistence
  50. credentialsProvider:(firebase::firestore::auth::CredentialsProvider *)
  51. credentialsProvider // no passing ownership
  52. userDispatchQueue:(FSTDispatchQueue *)userDispatchQueue
  53. workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue;
  54. - (instancetype)init __attribute__((unavailable("Use static constructor method.")));
  55. /** Shuts down this client, cancels all writes / listeners, and releases all resources. */
  56. - (void)shutdownWithCompletion:(nullable FSTVoidErrorBlock)completion;
  57. /** Disables the network connection. Pending operations will not complete. */
  58. - (void)disableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion;
  59. /** Enables the network connection and requeues all pending operations. */
  60. - (void)enableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion;
  61. /** Starts listening to a query. */
  62. - (FSTQueryListener *)listenToQuery:(FSTQuery *)query
  63. options:(FSTListenOptions *)options
  64. viewSnapshotHandler:(FSTViewSnapshotHandler)viewSnapshotHandler;
  65. /** Stops listening to a query previously listened to. */
  66. - (void)removeListener:(FSTQueryListener *)listener;
  67. /**
  68. * Retrieves a document from the cache via the indicated completion. If the doc
  69. * doesn't exist, an error will be sent to the completion.
  70. */
  71. - (void)getDocumentFromLocalCache:(FIRDocumentReference *)doc
  72. completion:(void (^)(FIRDocumentSnapshot *_Nullable document,
  73. NSError *_Nullable error))completion;
  74. /**
  75. * Retrieves a (possibly empty) set of documents from the cache via the
  76. * indicated completion.
  77. */
  78. - (void)getDocumentsFromLocalCache:(FIRQuery *)query
  79. completion:(void (^)(FIRQuerySnapshot *_Nullable query,
  80. NSError *_Nullable error))completion;
  81. /** Write mutations. completion will be notified when it's written to the backend. */
  82. - (void)writeMutations:(NSArray<FSTMutation *> *)mutations
  83. completion:(nullable FSTVoidErrorBlock)completion;
  84. /** Tries to execute the transaction in updateBlock up to retries times. */
  85. - (void)transactionWithRetries:(int)retries
  86. updateBlock:(FSTTransactionBlock)updateBlock
  87. completion:(FSTVoidIDErrorBlock)completion;
  88. /** The database ID of the databaseInfo this client was initialized with. */
  89. // Ownes a DatabaseInfo instance, which contains the id here.
  90. @property(nonatomic, assign, readonly) const firebase::firestore::model::DatabaseId *databaseID;
  91. /**
  92. * Dispatch queue for user callbacks / events. This will often be the "Main Dispatch Queue" of the
  93. * app but the developer can configure it to a different queue if they so choose.
  94. */
  95. @property(nonatomic, strong, readonly) FSTDispatchQueue *userDispatchQueue;
  96. @end
  97. NS_ASSUME_NONNULL_END