FSTQueryData.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/snapshot_version.h"
  18. #include "Firestore/core/src/firebase/firestore/model/types.h"
  19. @class FSTQuery;
  20. NS_ASSUME_NONNULL_BEGIN
  21. /** An enumeration of the different purposes we have for queries. */
  22. typedef NS_ENUM(NSInteger, FSTQueryPurpose) {
  23. /** A regular, normal query. */
  24. FSTQueryPurposeListen,
  25. /** The query was used to refill a query after an existence filter mismatch. */
  26. FSTQueryPurposeExistenceFilterMismatch,
  27. /** The query was used to resolve a limbo document. */
  28. FSTQueryPurposeLimboResolution,
  29. };
  30. /** An immutable set of metadata that the store will need to keep track of for each query. */
  31. @interface FSTQueryData : NSObject
  32. - (instancetype)initWithQuery:(FSTQuery *)query
  33. targetID:(firebase::firestore::model::TargetId)targetID
  34. listenSequenceNumber:(firebase::firestore::model::ListenSequenceNumber)sequenceNumber
  35. purpose:(FSTQueryPurpose)purpose
  36. snapshotVersion:(firebase::firestore::model::SnapshotVersion)snapshotVersion
  37. resumeToken:(NSData *)resumeToken NS_DESIGNATED_INITIALIZER;
  38. /** Convenience initializer for use when creating an FSTQueryData for the first time. */
  39. - (instancetype)initWithQuery:(FSTQuery *)query
  40. targetID:(firebase::firestore::model::TargetId)targetID
  41. listenSequenceNumber:(firebase::firestore::model::ListenSequenceNumber)sequenceNumber
  42. purpose:(FSTQueryPurpose)purpose;
  43. - (instancetype)init NS_UNAVAILABLE;
  44. /**
  45. * Creates a new query data instance with an updated snapshot version, resume token, and sequence
  46. * number.
  47. */
  48. - (instancetype)
  49. queryDataByReplacingSnapshotVersion:(firebase::firestore::model::SnapshotVersion)snapshotVersion
  50. resumeToken:(NSData *)resumeToken
  51. sequenceNumber:
  52. (firebase::firestore::model::ListenSequenceNumber)sequenceNumber;
  53. /** The latest snapshot version seen for this target. */
  54. - (const firebase::firestore::model::SnapshotVersion &)snapshotVersion;
  55. /** The query being listened to. */
  56. @property(nonatomic, strong, readonly) FSTQuery *query;
  57. /**
  58. * The targetID to which the query corresponds, assigned by the FSTLocalStore for user queries or
  59. * the FSTSyncEngine for limbo queries.
  60. */
  61. @property(nonatomic, assign, readonly) firebase::firestore::model::TargetId targetID;
  62. @property(nonatomic, assign, readonly)
  63. firebase::firestore::model::ListenSequenceNumber sequenceNumber;
  64. /** The purpose of the query. */
  65. @property(nonatomic, assign, readonly) FSTQueryPurpose purpose;
  66. /**
  67. * An opaque, server-assigned token that allows watching a query to be resumed after disconnecting
  68. * without retransmitting all the data that matches the query. The resume token essentially
  69. * identifies a point in time from which the server should resume sending results.
  70. */
  71. @property(nonatomic, copy, readonly) NSData *resumeToken;
  72. @end
  73. NS_ASSUME_NONNULL_END