FSTUserDataConverter.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 <vector>
  18. #include "Firestore/core/src/firebase/firestore/model/database_id.h"
  19. #include "Firestore/core/src/firebase/firestore/model/document_key.h"
  20. #include "Firestore/core/src/firebase/firestore/model/field_mask.h"
  21. #include "Firestore/core/src/firebase/firestore/model/field_transform.h"
  22. #include "Firestore/core/src/firebase/firestore/model/precondition.h"
  23. @class FSTObjectValue;
  24. @class FSTFieldValue;
  25. @class FSTMutation;
  26. @class FSTSnapshotVersion;
  27. NS_ASSUME_NONNULL_BEGIN
  28. /** The result of parsing document data (e.g. for a setData call). */
  29. @interface FSTParsedSetData : NSObject
  30. - (instancetype)init NS_UNAVAILABLE;
  31. - (instancetype)initWithData:(FSTObjectValue *)data
  32. fieldTransforms:
  33. (std::vector<firebase::firestore::model::FieldTransform>)fieldTransforms
  34. NS_DESIGNATED_INITIALIZER;
  35. - (instancetype)initWithData:(FSTObjectValue *)data
  36. fieldMask:(firebase::firestore::model::FieldMask)fieldMask
  37. fieldTransforms:
  38. (std::vector<firebase::firestore::model::FieldTransform>)fieldTransforms
  39. NS_DESIGNATED_INITIALIZER;
  40. - (const std::vector<firebase::firestore::model::FieldTransform> &)fieldTransforms;
  41. @property(nonatomic, strong, readonly) FSTObjectValue *data;
  42. @property(nonatomic, assign, readonly) BOOL isPatch;
  43. /**
  44. * Converts the parsed document data into 1 or 2 mutations (depending on whether there are any
  45. * field transforms) using the specified document key and precondition.
  46. */
  47. - (NSArray<FSTMutation *> *)mutationsWithKey:(const firebase::firestore::model::DocumentKey &)key
  48. precondition:
  49. (const firebase::firestore::model::Precondition &)precondition;
  50. @end
  51. /** The result of parsing "update" data (i.e. for an updateData call). */
  52. @interface FSTParsedUpdateData : NSObject
  53. - (instancetype)init NS_UNAVAILABLE;
  54. - (instancetype)initWithData:(FSTObjectValue *)data
  55. fieldMask:(firebase::firestore::model::FieldMask)fieldMask
  56. fieldTransforms:
  57. (std::vector<firebase::firestore::model::FieldTransform>)fieldTransforms
  58. NS_DESIGNATED_INITIALIZER;
  59. - (const firebase::firestore::model::FieldMask &)fieldMask;
  60. - (const std::vector<firebase::firestore::model::FieldTransform> &)fieldTransforms;
  61. @property(nonatomic, strong, readonly) FSTObjectValue *data;
  62. /**
  63. * Converts the parsed update data into 1 or 2 mutations (depending on whether there are any
  64. * field transforms) using the specified document key and precondition.
  65. */
  66. - (NSArray<FSTMutation *> *)mutationsWithKey:(const firebase::firestore::model::DocumentKey &)key
  67. precondition:
  68. (const firebase::firestore::model::Precondition &)precondition;
  69. @end
  70. /**
  71. * An internal representation of FIRDocumentReference, representing a key in a specific database.
  72. * This is necessary because keys assume a database from context (usually the current one).
  73. * FSTDocumentKeyReference binds a key to a specific databaseID.
  74. *
  75. * TODO(b/64160088): Make DocumentKey aware of the specific databaseID it is tied to.
  76. */
  77. @interface FSTDocumentKeyReference : NSObject
  78. - (instancetype)init NS_UNAVAILABLE;
  79. - (instancetype)initWithKey:(firebase::firestore::model::DocumentKey)key
  80. databaseID:(const firebase::firestore::model::DatabaseId *)databaseID
  81. NS_DESIGNATED_INITIALIZER;
  82. - (const firebase::firestore::model::DocumentKey &)key;
  83. // Does not own the DatabaseId instance.
  84. @property(nonatomic, assign, readonly) const firebase::firestore::model::DatabaseId *databaseID;
  85. @end
  86. /**
  87. * An interface that allows arbitrary pre-converting of user data.
  88. *
  89. * Returns the converted value (can return back the input to act as a no-op).
  90. */
  91. typedef id _Nullable (^FSTPreConverterBlock)(id _Nullable);
  92. /**
  93. * Helper for parsing raw user input (provided via the API) into internal model classes.
  94. */
  95. @interface FSTUserDataConverter : NSObject
  96. - (instancetype)init NS_UNAVAILABLE;
  97. - (instancetype)initWithDatabaseID:(const firebase::firestore::model::DatabaseId *)databaseID
  98. preConverter:(FSTPreConverterBlock)preConverter NS_DESIGNATED_INITIALIZER;
  99. /** Parse document data from a non-merge setData call.*/
  100. - (FSTParsedSetData *)parsedSetData:(id)input;
  101. /** Parse document data from a setData call with `merge:YES`. */
  102. - (FSTParsedSetData *)parsedMergeData:(id)input;
  103. /** Parse update data from an updateData call. */
  104. - (FSTParsedUpdateData *)parsedUpdateData:(id)input;
  105. /** Parse a "query value" (e.g. value in a where filter or a value in a cursor bound). */
  106. - (FSTFieldValue *)parsedQueryValue:(id)input;
  107. @end
  108. NS_ASSUME_NONNULL_END