FSTDatastore.h 3.7 KB

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