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