FSTDocument.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "Firestore/core/src/firebase/firestore/model/document_key.h"
  18. #include "Firestore/core/src/firebase/firestore/model/field_path.h"
  19. #include "Firestore/core/src/firebase/firestore/model/field_value.h"
  20. #include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
  21. #include "absl/types/optional.h"
  22. @class GCFSDocument;
  23. namespace firebase {
  24. namespace firestore {
  25. namespace model {
  26. enum class DocumentState;
  27. } // namespace model
  28. } // namespace firestore
  29. } // namespace firebase
  30. namespace model = firebase::firestore::model;
  31. NS_ASSUME_NONNULL_BEGIN
  32. /**
  33. * The result of a lookup for a given path may be an existing document or a tombstone that marks
  34. * the path deleted.
  35. */
  36. @interface FSTMaybeDocument : NSObject <NSCopying>
  37. - (id)init __attribute__((unavailable("Abstract base class")));
  38. - (const model::DocumentKey &)key;
  39. - (const model::SnapshotVersion &)version;
  40. /**
  41. * Whether this document has a local mutation applied that has not yet been acknowledged by Watch.
  42. */
  43. - (bool)hasPendingWrites;
  44. @end
  45. @interface FSTDocument : FSTMaybeDocument
  46. + (instancetype)documentWithData:(model::ObjectValue)data
  47. key:(model::DocumentKey)key
  48. version:(model::SnapshotVersion)version
  49. state:(model::DocumentState)state;
  50. + (instancetype)documentWithData:(model::ObjectValue)data
  51. key:(model::DocumentKey)key
  52. version:(model::SnapshotVersion)version
  53. state:(model::DocumentState)state
  54. proto:(GCFSDocument *)proto;
  55. - (absl::optional<model::FieldValue>)fieldForPath:(const model::FieldPath &)path;
  56. - (bool)hasLocalMutations;
  57. - (bool)hasCommittedMutations;
  58. @property(nonatomic, assign, readonly) const model::ObjectValue &data;
  59. @property(nonatomic, assign, readonly) model::DocumentState documentState;
  60. /**
  61. * Memoized serialized form of the document for optimization purposes (avoids repeated
  62. * serialization). Might be nil.
  63. */
  64. @property(nullable, nonatomic, strong, readonly) GCFSDocument *proto;
  65. @end
  66. @interface FSTDeletedDocument : FSTMaybeDocument
  67. + (instancetype)documentWithKey:(model::DocumentKey)key
  68. version:(model::SnapshotVersion)version
  69. hasCommittedMutations:(bool)committedMutations;
  70. - (bool)hasCommittedMutations;
  71. @end
  72. @interface FSTUnknownDocument : FSTMaybeDocument
  73. + (instancetype)documentWithKey:(model::DocumentKey)key version:(model::SnapshotVersion)version;
  74. @end
  75. NS_ASSUME_NONNULL_END