FSTFirestoreClient.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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)clientWithDatabaseInfo:(const firebase::firestore::core::DatabaseInfo &)databaseInfo
  51. usePersistence:(BOOL)usePersistence
  52. credentialsProvider:(firebase::firestore::auth::CredentialsProvider *)
  53. credentialsProvider // no passing ownership
  54. userExecutor:
  55. (std::unique_ptr<firebase::firestore::util::internal::Executor>)
  56. userExecutor
  57. workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue;
  58. - (instancetype)init __attribute__((unavailable("Use static constructor method.")));
  59. /** Shuts down this client, cancels all writes / listeners, and releases all resources. */
  60. - (void)shutdownWithCompletion:(nullable FSTVoidErrorBlock)completion;
  61. /** Disables the network connection. Pending operations will not complete. */
  62. - (void)disableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion;
  63. /** Enables the network connection and requeues all pending operations. */
  64. - (void)enableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion;
  65. /** Starts listening to a query. */
  66. - (FSTQueryListener *)listenToQuery:(FSTQuery *)query
  67. options:(FSTListenOptions *)options
  68. viewSnapshotHandler:(FSTViewSnapshotHandler)viewSnapshotHandler;
  69. /** Stops listening to a query previously listened to. */
  70. - (void)removeListener:(FSTQueryListener *)listener;
  71. /**
  72. * Retrieves a document from the cache via the indicated completion. If the doc
  73. * doesn't exist, an error will be sent to the completion.
  74. */
  75. - (void)getDocumentFromLocalCache:(FIRDocumentReference *)doc
  76. completion:(void (^)(FIRDocumentSnapshot *_Nullable document,
  77. NSError *_Nullable error))completion;
  78. /**
  79. * Retrieves a (possibly empty) set of documents from the cache via the
  80. * indicated completion.
  81. */
  82. - (void)getDocumentsFromLocalCache:(FIRQuery *)query
  83. completion:(void (^)(FIRQuerySnapshot *_Nullable query,
  84. NSError *_Nullable error))completion;
  85. /** Write mutations. completion will be notified when it's written to the backend. */
  86. - (void)writeMutations:(NSArray<FSTMutation *> *)mutations
  87. completion:(nullable FSTVoidErrorBlock)completion;
  88. /** Tries to execute the transaction in updateBlock up to retries times. */
  89. - (void)transactionWithRetries:(int)retries
  90. updateBlock:(FSTTransactionBlock)updateBlock
  91. completion:(FSTVoidIDErrorBlock)completion;
  92. /** The database ID of the databaseInfo this client was initialized with. */
  93. // Ownes a DatabaseInfo instance, which contains the id here.
  94. @property(nonatomic, assign, readonly) const firebase::firestore::model::DatabaseId *databaseID;
  95. /**
  96. * Dispatch queue for user callbacks / events. This will often be the "Main Dispatch Queue" of the
  97. * app but the developer can configure it to a different queue if they so choose.
  98. */
  99. - (firebase::firestore::util::internal::Executor *)userExecutor;
  100. @end
  101. NS_ASSUME_NONNULL_END