FSTUserDataConverter.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. @class FIRSetOptions;
  18. @class FSTDatabaseID;
  19. @class FSTDocumentKey;
  20. @class FSTObjectValue;
  21. @class FSTFieldMask;
  22. @class FSTFieldValue;
  23. @class FSTFieldTransform;
  24. @class FSTMutation;
  25. @class FSTPrecondition;
  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. fieldMask:(nullable FSTFieldMask *)fieldMask
  33. fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms
  34. NS_DESIGNATED_INITIALIZER;
  35. @property(nonatomic, strong, readonly) FSTObjectValue *data;
  36. @property(nonatomic, strong, readonly, nullable) FSTFieldMask *fieldMask;
  37. @property(nonatomic, strong, readonly) NSArray<FSTFieldTransform *> *fieldTransforms;
  38. /**
  39. * Converts the parsed document data into 1 or 2 mutations (depending on whether there are any
  40. * field transforms) using the specified document key and precondition.
  41. */
  42. - (NSArray<FSTMutation *> *)mutationsWithKey:(FSTDocumentKey *)key
  43. precondition:(FSTPrecondition *)precondition;
  44. @end
  45. /** The result of parsing "update" data (i.e. for an updateData call). */
  46. @interface FSTParsedUpdateData : NSObject
  47. - (instancetype)init NS_UNAVAILABLE;
  48. - (instancetype)initWithData:(FSTObjectValue *)data
  49. fieldMask:(FSTFieldMask *)fieldMask
  50. fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms
  51. NS_DESIGNATED_INITIALIZER;
  52. @property(nonatomic, strong, readonly) FSTObjectValue *data;
  53. @property(nonatomic, strong, readonly) FSTFieldMask *fieldMask;
  54. @property(nonatomic, strong, readonly) NSArray<FSTFieldTransform *> *fieldTransforms;
  55. /**
  56. * Converts the parsed update data into 1 or 2 mutations (depending on whether there are any
  57. * field transforms) using the specified document key and precondition.
  58. */
  59. - (NSArray<FSTMutation *> *)mutationsWithKey:(FSTDocumentKey *)key
  60. precondition:(FSTPrecondition *)precondition;
  61. @end
  62. /**
  63. * An internal representation of FIRDocumentReference, representing a key in a specific database.
  64. * This is necessary because keys assume a database from context (usually the current one).
  65. * FSTDocumentKeyReference binds a key to a specific databaseID.
  66. *
  67. * TODO(b/64160088): Make FSTDocumentKey aware of the specific databaseID it is tied to.
  68. */
  69. @interface FSTDocumentKeyReference : NSObject
  70. - (instancetype)init NS_UNAVAILABLE;
  71. - (instancetype)initWithKey:(FSTDocumentKey *)key
  72. databaseID:(FSTDatabaseID *)databaseID NS_DESIGNATED_INITIALIZER;
  73. @property(nonatomic, strong, readonly) FSTDocumentKey *key;
  74. @property(nonatomic, strong, readonly) FSTDatabaseID *databaseID;
  75. @end
  76. /**
  77. * An interface that allows arbitrary pre-converting of user data.
  78. *
  79. * Returns the converted value (can return back the input to act as a no-op).
  80. */
  81. typedef id _Nullable (^FSTPreConverterBlock)(id _Nullable);
  82. /**
  83. * Helper for parsing raw user input (provided via the API) into internal model classes.
  84. */
  85. @interface FSTUserDataConverter : NSObject
  86. - (instancetype)init NS_UNAVAILABLE;
  87. - (instancetype)initWithDatabaseID:(FSTDatabaseID *)databaseID
  88. preConverter:(FSTPreConverterBlock)preConverter NS_DESIGNATED_INITIALIZER;
  89. /** Parse document data from a non-merge setData call.*/
  90. - (FSTParsedSetData *)parsedSetData:(id)input;
  91. /** Parse document data from a setData call with '[FIRSetOptions merge]'. */
  92. - (FSTParsedSetData *)parsedMergeData:(id)input;
  93. /** Parse update data from an updateData call. */
  94. - (FSTParsedUpdateData *)parsedUpdateData:(id)input;
  95. /** Parse a "query value" (e.g. value in a where filter or a value in a cursor bound). */
  96. - (FSTFieldValue *)parsedQueryValue:(id)input;
  97. @end
  98. NS_ASSUME_NONNULL_END