FSTDatastore.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 FSTWatchChange;
  30. @class FSTWatchStream;
  31. @class FSTWriteStream;
  32. @class GRPCCall;
  33. @class GRXWriter;
  34. NS_ASSUME_NONNULL_BEGIN
  35. /**
  36. * FSTDatastore represents a proxy for the remote server, hiding details of the RPC layer. It:
  37. *
  38. * - Manages connections to the server
  39. * - Authenticates to the server
  40. * - Manages threading and keeps higher-level code running on the worker queue
  41. * - Serializes internal model objects to and from protocol buffers
  42. *
  43. * The FSTDatastore is generally not responsible for understanding the higher-level protocol
  44. * involved in actually making changes or reading data, and aside from the connections it manages
  45. * is otherwise stateless.
  46. */
  47. @interface FSTDatastore : NSObject
  48. /** Creates a new Datastore instance with the given database info. */
  49. + (instancetype)datastoreWithDatabase:(const firebase::firestore::core::DatabaseInfo *)databaseInfo
  50. workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue
  51. credentials:(firebase::firestore::auth::CredentialsProvider *)
  52. credentials; // no passing ownership
  53. - (instancetype)init __attribute__((unavailable("Use a static constructor method.")));
  54. - (instancetype)initWithDatabaseInfo:(const firebase::firestore::core::DatabaseInfo *)databaseInfo
  55. workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue
  56. credentials:(firebase::firestore::auth::CredentialsProvider *)
  57. credentials // no passing ownership
  58. NS_DESIGNATED_INITIALIZER;
  59. /**
  60. * Takes a dictionary of (HTTP) response headers and returns the set of whitelisted headers
  61. * (for logging purposes).
  62. */
  63. + (NSDictionary<NSString *, NSString *> *)extractWhiteListedHeaders:
  64. (NSDictionary<NSString *, NSString *> *)header;
  65. /** Converts the error to a FIRFirestoreErrorDomain error. */
  66. + (NSError *)firestoreErrorForError:(NSError *)error;
  67. /** Returns YES if the given error is a GRPC ABORTED error. **/
  68. + (BOOL)isAbortedError:(NSError *)error;
  69. /** Returns YES if the given error indicates the RPC associated with it may not be retried. */
  70. + (BOOL)isPermanentWriteError:(NSError *)error;
  71. /** Adds headers to the RPC including any OAuth access token if provided .*/
  72. + (void)prepareHeadersForRPC:(GRPCCall *)rpc
  73. databaseID:(const firebase::firestore::model::DatabaseId *)databaseID
  74. token:(const absl::string_view)token;
  75. /** Looks up a list of documents in datastore. */
  76. - (void)lookupDocuments:(const std::vector<firebase::firestore::model::DocumentKey> &)keys
  77. completion:(FSTVoidMaybeDocumentArrayErrorBlock)completion;
  78. /** Commits data to datastore. */
  79. - (void)commitMutations:(NSArray<FSTMutation *> *)mutations
  80. completion:(FSTVoidErrorBlock)completion;
  81. /** Creates a new watch stream. */
  82. - (FSTWatchStream *)createWatchStream;
  83. /** Creates a new write stream. */
  84. - (FSTWriteStream *)createWriteStream;
  85. /** The name of the database and the backend. */
  86. // Does not own this DatabaseInfo.
  87. @property(nonatomic, assign, readonly) const firebase::firestore::core::DatabaseInfo *databaseInfo;
  88. @end
  89. NS_ASSUME_NONNULL_END