FSTFirestoreClient.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #include <memory>
  18. #import "Firestore/Source/Core/FSTTypes.h"
  19. #import "Firestore/Source/Core/FSTViewSnapshot.h"
  20. #import "Firestore/Source/Remote/FSTRemoteStore.h"
  21. #include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
  22. #include "Firestore/core/src/firebase/firestore/core/database_info.h"
  23. #include "Firestore/core/src/firebase/firestore/model/database_id.h"
  24. #include "Firestore/core/src/firebase/firestore/util/executor.h"
  25. @class FIRDocumentReference;
  26. @class FIRDocumentSnapshot;
  27. @class FIRQuery;
  28. @class FIRQuerySnapshot;
  29. @class FSTDatabaseID;
  30. @class FSTDatabaseInfo;
  31. @class FSTDispatchQueue;
  32. @class FSTDocument;
  33. @class FSTListenOptions;
  34. @class FSTMutation;
  35. @class FSTQuery;
  36. @class FSTQueryListener;
  37. @class FSTTransaction;
  38. NS_ASSUME_NONNULL_BEGIN
  39. /**
  40. * FirestoreClient is a top-level class that constructs and owns all of the pieces of the client
  41. * SDK architecture. It is responsible for creating the worker queue that is shared by all of the
  42. * other components in the system.
  43. */
  44. @interface FSTFirestoreClient : NSObject <FSTOnlineStateDelegate>
  45. /**
  46. * Creates and returns a FSTFirestoreClient with the given parameters.
  47. *
  48. * All callbacks and events will be triggered on the provided userExecutor.
  49. */
  50. + (instancetype)
  51. clientWithDatabaseInfo:(const firebase::firestore::core::DatabaseInfo &)databaseInfo
  52. usePersistence:(BOOL)usePersistence
  53. credentialsProvider:(firebase::firestore::auth::CredentialsProvider *)
  54. credentialsProvider // no passing ownership
  55. userExecutor:(std::unique_ptr<firebase::firestore::util::internal::Executor>)userExecutor
  56. workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue;
  57. - (instancetype)init __attribute__((unavailable("Use static constructor method.")));
  58. /** Shuts down this client, cancels all writes / listeners, and releases all resources. */
  59. - (void)shutdownWithCompletion:(nullable FSTVoidErrorBlock)completion;
  60. /** Disables the network connection. Pending operations will not complete. */
  61. - (void)disableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion;
  62. /** Enables the network connection and requeues all pending operations. */
  63. - (void)enableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion;
  64. /** Starts listening to a query. */
  65. - (FSTQueryListener *)listenToQuery:(FSTQuery *)query
  66. options:(FSTListenOptions *)options
  67. viewSnapshotHandler:(FSTViewSnapshotHandler)viewSnapshotHandler;
  68. /** Stops listening to a query previously listened to. */
  69. - (void)removeListener:(FSTQueryListener *)listener;
  70. /**
  71. * Retrieves a document from the cache via the indicated completion. If the doc
  72. * doesn't exist, an error will be sent to the completion.
  73. */
  74. - (void)getDocumentFromLocalCache:(FIRDocumentReference *)doc
  75. completion:(void (^)(FIRDocumentSnapshot *_Nullable document,
  76. NSError *_Nullable error))completion;
  77. /**
  78. * Retrieves a (possibly empty) set of documents from the cache via the
  79. * indicated completion.
  80. */
  81. - (void)getDocumentsFromLocalCache:(FIRQuery *)query
  82. completion:(void (^)(FIRQuerySnapshot *_Nullable query,
  83. NSError *_Nullable error))completion;
  84. /** Write mutations. completion will be notified when it's written to the backend. */
  85. - (void)writeMutations:(NSArray<FSTMutation *> *)mutations
  86. completion:(nullable FSTVoidErrorBlock)completion;
  87. /** Tries to execute the transaction in updateBlock up to retries times. */
  88. - (void)transactionWithRetries:(int)retries
  89. updateBlock:(FSTTransactionBlock)updateBlock
  90. completion:(FSTVoidIDErrorBlock)completion;
  91. /** The database ID of the databaseInfo this client was initialized with. */
  92. // Ownes a DatabaseInfo instance, which contains the id here.
  93. @property(nonatomic, assign, readonly) const firebase::firestore::model::DatabaseId *databaseID;
  94. /**
  95. * Dispatch queue for user callbacks / events. This will often be the "Main Dispatch Queue" of the
  96. * app but the developer can configure it to a different queue if they so choose.
  97. */
  98. - (firebase::firestore::util::internal::Executor *)userExecutor;
  99. @end
  100. NS_ASSUME_NONNULL_END