FSTQueryData.h 3.5 KB

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