FSTTransaction.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/core/user_data.h"
  20. #include "Firestore/core/src/firebase/firestore/model/document_key.h"
  21. #include "Firestore/core/src/firebase/firestore/remote/datastore.h"
  22. @class FSTMaybeDocument;
  23. @class FSTObjectValue;
  24. @class FSTParsedUpdateData;
  25. NS_ASSUME_NONNULL_BEGIN
  26. #pragma mark - FSTTransaction
  27. /** Provides APIs to use in a transaction context. */
  28. @interface FSTTransaction : NSObject
  29. /** Creates a new transaction object, which can only be used for one transaction attempt. **/
  30. + (instancetype)transactionWithDatastore:(firebase::firestore::remote::Datastore *)datastore;
  31. /**
  32. * Takes a set of keys and asynchronously attempts to fetch all the documents from the backend,
  33. * ignoring any local changes.
  34. */
  35. - (void)lookupDocumentsForKeys:(const std::vector<firebase::firestore::model::DocumentKey> &)keys
  36. completion:(FSTVoidMaybeDocumentArrayErrorBlock)completion;
  37. /**
  38. * Stores mutation for the given key and set data, to be committed when commitWithCompletion is
  39. * called.
  40. */
  41. - (void)setData:(firebase::firestore::core::ParsedSetData &&)data
  42. forDocument:(const firebase::firestore::model::DocumentKey &)key;
  43. /**
  44. * Stores mutations for the given key and update data, to be committed when commitWithCompletion
  45. * is called.
  46. */
  47. - (void)updateData:(firebase::firestore::core::ParsedUpdateData &&)data
  48. forDocument:(const firebase::firestore::model::DocumentKey &)key;
  49. /**
  50. * Stores a delete mutation for the given key, to be committed when commitWithCompletion is called.
  51. */
  52. - (void)deleteDocument:(const firebase::firestore::model::DocumentKey &)key;
  53. /**
  54. * Attempts to commit the mutations set on this transaction. Calls the given completion block when
  55. * finished. Once this is called, no other mutations or commits are allowed on the transaction.
  56. */
  57. - (void)commitWithCompletion:(FSTVoidErrorBlock)completion;
  58. @end
  59. NS_ASSUME_NONNULL_END