FSTDocument.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/snapshot_version.h"
  20. @class FSTFieldValue;
  21. @class FSTObjectValue;
  22. NS_ASSUME_NONNULL_BEGIN
  23. /** Describes the `hasPendingWrites` state of a document. */
  24. typedef NS_ENUM(NSInteger, FSTDocumentState) {
  25. /** Local mutations applied via the mutation queue. Document is potentially inconsistent. */
  26. FSTDocumentStateLocalMutations,
  27. /** Mutations applied based on a write acknowledgment. Document is potentially inconsistent. */
  28. FSTDocumentStateCommittedMutations,
  29. /** No mutations applied. Document was sent to us by Watch. */
  30. FSTDocumentStateSynced
  31. };
  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 firebase::firestore::model::DocumentKey &)key;
  39. - (const firebase::firestore::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:(FSTObjectValue *)data
  47. key:(firebase::firestore::model::DocumentKey)key
  48. version:(firebase::firestore::model::SnapshotVersion)version
  49. state:(FSTDocumentState)state;
  50. - (nullable FSTFieldValue *)fieldForPath:(const firebase::firestore::model::FieldPath &)path;
  51. - (BOOL)hasLocalMutations;
  52. - (BOOL)hasCommittedMutations;
  53. @property(nonatomic, strong, readonly) FSTObjectValue *data;
  54. @end
  55. @interface FSTDeletedDocument : FSTMaybeDocument
  56. + (instancetype)documentWithKey:(firebase::firestore::model::DocumentKey)key
  57. version:(firebase::firestore::model::SnapshotVersion)version
  58. hasCommittedMutations:(BOOL)committedMutations;
  59. - (BOOL)hasCommittedMutations;
  60. @end
  61. @interface FSTUnknownDocument : FSTMaybeDocument
  62. + (instancetype)documentWithKey:(firebase::firestore::model::DocumentKey)key
  63. version:(firebase::firestore::model::SnapshotVersion)version;
  64. @end
  65. /** An NSComparator suitable for comparing docs using only their keys. */
  66. extern const NSComparator FSTDocumentComparatorByKey;
  67. NS_ASSUME_NONNULL_END