FSTWatchChange.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #import "Firestore/Source/Core/FSTTypes.h"
  18. @class FSTDocumentKey;
  19. @class FSTExistenceFilter;
  20. @class FSTMaybeDocument;
  21. @class FSTSnapshotVersion;
  22. NS_ASSUME_NONNULL_BEGIN
  23. /**
  24. * FSTWatchChange is the internal representation of the watcher API protocol buffers.
  25. * This is an empty abstract class so that all the different kinds of changes can have a common
  26. * base class.
  27. */
  28. @interface FSTWatchChange : NSObject
  29. @end
  30. /**
  31. * FSTDocumentWatchChange represents a changed document and a list of target ids to which this
  32. * change applies. If the document has been deleted, the deleted document will be provided.
  33. */
  34. @interface FSTDocumentWatchChange : FSTWatchChange
  35. - (instancetype)initWithUpdatedTargetIDs:(NSArray<NSNumber *> *)updatedTargetIDs
  36. removedTargetIDs:(NSArray<NSNumber *> *)removedTargetIDs
  37. documentKey:(FSTDocumentKey *)documentKey
  38. document:(nullable FSTMaybeDocument *)document
  39. NS_DESIGNATED_INITIALIZER;
  40. - (instancetype)init NS_UNAVAILABLE;
  41. /** The new document applies to all of these targets. */
  42. @property(nonatomic, strong, readonly) NSArray<NSNumber *> *updatedTargetIDs;
  43. /** The new document is removed from all of these targets. */
  44. @property(nonatomic, strong, readonly) NSArray<NSNumber *> *removedTargetIDs;
  45. /** The key of the document for this change. */
  46. @property(nonatomic, strong, readonly) FSTDocumentKey *documentKey;
  47. /**
  48. * The new document or DeletedDocument if it was deleted. Is null if the document went out of
  49. * view without the server sending a new document.
  50. */
  51. @property(nonatomic, strong, readonly, nullable) FSTMaybeDocument *document;
  52. @end
  53. /**
  54. * An ExistenceFilterWatchChange applies to the targets and is required to verify the current client
  55. * state against expected state sent from the server.
  56. */
  57. @interface FSTExistenceFilterWatchChange : FSTWatchChange
  58. + (instancetype)changeWithFilter:(FSTExistenceFilter *)filter targetID:(FSTTargetID)targetID;
  59. - (instancetype)init NS_UNAVAILABLE;
  60. @property(nonatomic, strong, readonly) FSTExistenceFilter *filter;
  61. @property(nonatomic, assign, readonly) FSTTargetID targetID;
  62. @end
  63. /** FSTWatchTargetChangeState is the kind of change that happened to the watch target. */
  64. typedef NS_ENUM(NSInteger, FSTWatchTargetChangeState) {
  65. FSTWatchTargetChangeStateNoChange,
  66. FSTWatchTargetChangeStateAdded,
  67. FSTWatchTargetChangeStateRemoved,
  68. FSTWatchTargetChangeStateCurrent,
  69. FSTWatchTargetChangeStateReset,
  70. };
  71. /** FSTWatchTargetChange is a change to a watch target. */
  72. @interface FSTWatchTargetChange : FSTWatchChange
  73. - (instancetype)initWithState:(FSTWatchTargetChangeState)state
  74. targetIDs:(NSArray<NSNumber *> *)targetIDs
  75. resumeToken:(NSData *)resumeToken
  76. cause:(nullable NSError *)cause NS_DESIGNATED_INITIALIZER;
  77. - (instancetype)init NS_UNAVAILABLE;
  78. /** What kind of change occurred to the watch target. */
  79. @property(nonatomic, assign, readonly) FSTWatchTargetChangeState state;
  80. /** The target IDs that were added/removed/set. */
  81. @property(nonatomic, strong, readonly) NSArray<NSNumber *> *targetIDs;
  82. /**
  83. * An opaque, server-assigned token that allows watching a query to be resumed after disconnecting
  84. * without retransmitting all the data that matches the query. The resume token essentially
  85. * identifies a point in time from which the server should resume sending results.
  86. */
  87. @property(nonatomic, strong, readonly) NSData *resumeToken;
  88. /** An RPC error indicating why the watch failed. */
  89. @property(nonatomic, strong, readonly, nullable) NSError *cause;
  90. @end
  91. NS_ASSUME_NONNULL_END