FSTDatastore.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 <vector>
  18. #import "Firestore/Source/Core/FSTTypes.h"
  19. #include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
  20. #include "Firestore/core/src/firebase/firestore/core/database_info.h"
  21. #include "Firestore/core/src/firebase/firestore/model/database_id.h"
  22. #include "Firestore/core/src/firebase/firestore/model/document_key.h"
  23. #include "absl/strings/string_view.h"
  24. @class FSTDispatchQueue;
  25. @class FSTMutation;
  26. @class FSTMutationResult;
  27. @class FSTQueryData;
  28. @class FSTSerializerBeta;
  29. @class FSTSnapshotVersion;
  30. @class FSTWatchChange;
  31. @class FSTWatchStream;
  32. @class FSTWriteStream;
  33. @class GRPCCall;
  34. @class GRXWriter;
  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. workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue
  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. workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue
  57. credentials:(firebase::firestore::auth::CredentialsProvider *)
  58. credentials // no passing ownership
  59. NS_DESIGNATED_INITIALIZER;
  60. /**
  61. * Takes a dictionary of (HTTP) response headers and returns the set of whitelisted headers
  62. * (for logging purposes).
  63. */
  64. + (NSDictionary<NSString *, NSString *> *)extractWhiteListedHeaders:
  65. (NSDictionary<NSString *, NSString *> *)header;
  66. /** Converts the error to a FIRFirestoreErrorDomain error. */
  67. + (NSError *)firestoreErrorForError:(NSError *)error;
  68. /** Returns YES if the given error is a GRPC ABORTED error. **/
  69. + (BOOL)isAbortedError:(NSError *)error;
  70. /** Returns YES if the given error indicates the RPC associated with it may not be retried. */
  71. + (BOOL)isPermanentWriteError:(NSError *)error;
  72. /** Adds headers to the RPC including any OAuth access token if provided .*/
  73. + (void)prepareHeadersForRPC:(GRPCCall *)rpc
  74. databaseID:(const firebase::firestore::model::DatabaseId *)databaseID
  75. token:(const absl::string_view)token;
  76. /** Looks up a list of documents in datastore. */
  77. - (void)lookupDocuments:(const std::vector<firebase::firestore::model::DocumentKey> &)keys
  78. completion:(FSTVoidMaybeDocumentArrayErrorBlock)completion;
  79. /** Commits data to datastore. */
  80. - (void)commitMutations:(NSArray<FSTMutation *> *)mutations
  81. completion:(FSTVoidErrorBlock)completion;
  82. /** Creates a new watch stream. */
  83. - (FSTWatchStream *)createWatchStream;
  84. /** Creates a new write stream. */
  85. - (FSTWriteStream *)createWriteStream;
  86. /** The name of the database and the backend. */
  87. // Does not own this DatabaseInfo.
  88. @property(nonatomic, assign, readonly) const firebase::firestore::core::DatabaseInfo *databaseInfo;
  89. @end
  90. NS_ASSUME_NONNULL_END