FSTDatastore.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #include <vector>
  19. #import "Firestore/Source/Core/FSTTypes.h"
  20. #include "Firestore/core/src/firebase/firestore//remote/watch_stream.h"
  21. #include "Firestore/core/src/firebase/firestore//remote/write_stream.h"
  22. #include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
  23. #include "Firestore/core/src/firebase/firestore/core/database_info.h"
  24. #include "Firestore/core/src/firebase/firestore/model/database_id.h"
  25. #include "Firestore/core/src/firebase/firestore/model/document_key.h"
  26. #include "Firestore/core/src/firebase/firestore/remote/datastore.h"
  27. #include "Firestore/core/src/firebase/firestore/util/async_queue.h"
  28. #include "absl/memory/memory.h"
  29. #include "absl/strings/string_view.h"
  30. @class FSTMutation;
  31. @class FSTMutationResult;
  32. @class FSTQueryData;
  33. @class FSTSerializerBeta;
  34. @class FSTWatchChange;
  35. NS_ASSUME_NONNULL_BEGIN
  36. /**
  37. * FSTDatastore represents a proxy for the remote server, hiding details of the RPC layer. It:
  38. *
  39. * - Manages connections to the server
  40. * - Authenticates to the server
  41. * - Manages threading and keeps higher-level code running on the worker queue
  42. * - Serializes internal model objects to and from protocol buffers
  43. *
  44. * The FSTDatastore is generally not responsible for understanding the higher-level protocol
  45. * involved in actually making changes or reading data, and aside from the connections it manages
  46. * is otherwise stateless.
  47. */
  48. @interface FSTDatastore : NSObject
  49. /** Creates a new Datastore instance with the given database info. */
  50. + (instancetype)datastoreWithDatabase:(const firebase::firestore::core::DatabaseInfo *)databaseInfo
  51. workerQueue:(firebase::firestore::util::AsyncQueue *)workerQueue
  52. credentials:(firebase::firestore::auth::CredentialsProvider *)
  53. credentials; // no passing ownership
  54. - (instancetype)init __attribute__((unavailable("Use a static constructor method.")));
  55. - (instancetype)initWithDatabaseInfo:(const firebase::firestore::core::DatabaseInfo *)databaseInfo
  56. workerQueue:(firebase::firestore::util::AsyncQueue *)workerQueue
  57. credentials:(firebase::firestore::auth::CredentialsProvider *)
  58. credentials // no passing ownership
  59. NS_DESIGNATED_INITIALIZER;
  60. - (void)shutdown;
  61. /** Converts the error to a FIRFirestoreErrorDomain error. */
  62. + (NSError *)firestoreErrorForError:(NSError *)error;
  63. /** Returns YES if the given error is a GRPC ABORTED error. **/
  64. + (BOOL)isAbortedError:(NSError *)error;
  65. /** Returns YES if the given error indicates the RPC associated with it may not be retried. */
  66. + (BOOL)isPermanentWriteError:(NSError *)error;
  67. /** Looks up a list of documents in datastore. */
  68. - (void)lookupDocuments:(const std::vector<firebase::firestore::model::DocumentKey> &)keys
  69. completion:(FSTVoidMaybeDocumentArrayErrorBlock)completion;
  70. /** Commits data to datastore. */
  71. - (void)commitMutations:(NSArray<FSTMutation *> *)mutations
  72. completion:(FSTVoidErrorBlock)completion;
  73. /** Creates a new watch stream. */
  74. - (std::shared_ptr<firebase::firestore::remote::WatchStream>)createWatchStreamWithDelegate:
  75. (id<FSTWatchStreamDelegate>)delegate;
  76. /** Creates a new write stream. */
  77. - (std::shared_ptr<firebase::firestore::remote::WriteStream>)createWriteStreamWithDelegate:
  78. (id<FSTWriteStreamDelegate>)delegate;
  79. /** The name of the database and the backend. */
  80. // Does not own this DatabaseInfo.
  81. @property(nonatomic, assign, readonly) const firebase::firestore::core::DatabaseInfo *databaseInfo;
  82. @end
  83. NS_ASSUME_NONNULL_END