FSTUserDataConverter.h 5.2 KB

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