FSTDocument.h 3.2 KB

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