FSTDocument.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 GCFSDocument;
  22. @class FSTObjectValue;
  23. NS_ASSUME_NONNULL_BEGIN
  24. /** Describes the `hasPendingWrites` state of a document. */
  25. typedef NS_ENUM(NSInteger, FSTDocumentState) {
  26. /** Local mutations applied via the mutation queue. Document is potentially inconsistent. */
  27. FSTDocumentStateLocalMutations,
  28. /** Mutations applied based on a write acknowledgment. Document is potentially inconsistent. */
  29. FSTDocumentStateCommittedMutations,
  30. /** No mutations applied. Document was sent to us by Watch. */
  31. FSTDocumentStateSynced
  32. };
  33. /**
  34. * The result of a lookup for a given path may be an existing document or a tombstone that marks
  35. * the path deleted.
  36. */
  37. @interface FSTMaybeDocument : NSObject <NSCopying>
  38. - (id)init __attribute__((unavailable("Abstract base class")));
  39. - (const firebase::firestore::model::DocumentKey &)key;
  40. - (const firebase::firestore::model::SnapshotVersion &)version;
  41. /**
  42. * Whether this document has a local mutation applied that has not yet been acknowledged by Watch.
  43. */
  44. - (BOOL)hasPendingWrites;
  45. @end
  46. @interface FSTDocument : FSTMaybeDocument
  47. + (instancetype)documentWithData:(FSTObjectValue *)data
  48. key:(firebase::firestore::model::DocumentKey)key
  49. version:(firebase::firestore::model::SnapshotVersion)version
  50. state:(FSTDocumentState)state;
  51. + (instancetype)documentWithData:(FSTObjectValue *)data
  52. key:(firebase::firestore::model::DocumentKey)key
  53. version:(firebase::firestore::model::SnapshotVersion)version
  54. state:(FSTDocumentState)state
  55. proto:(GCFSDocument *)proto;
  56. - (nullable FSTFieldValue *)fieldForPath:(const firebase::firestore::model::FieldPath &)path;
  57. - (BOOL)hasLocalMutations;
  58. - (BOOL)hasCommittedMutations;
  59. @property(nonatomic, strong, readonly) FSTObjectValue *data;
  60. /**
  61. * Memoized serialized form of the document for optimization purposes (avoids repeated
  62. * serialization). Might be nil.
  63. */
  64. @property(nonatomic, strong, readonly) GCFSDocument *proto;
  65. @end
  66. @interface FSTDeletedDocument : FSTMaybeDocument
  67. + (instancetype)documentWithKey:(firebase::firestore::model::DocumentKey)key
  68. version:(firebase::firestore::model::SnapshotVersion)version
  69. hasCommittedMutations:(BOOL)committedMutations;
  70. - (BOOL)hasCommittedMutations;
  71. @end
  72. @interface FSTUnknownDocument : FSTMaybeDocument
  73. + (instancetype)documentWithKey:(firebase::firestore::model::DocumentKey)key
  74. version:(firebase::firestore::model::SnapshotVersion)version;
  75. @end
  76. /** An NSComparator suitable for comparing docs using only their keys. */
  77. extern const NSComparator FSTDocumentComparatorByKey;
  78. NS_ASSUME_NONNULL_END