FSTUserDataConverter.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/include/firebase/firestore/timestamp.h"
  19. #include "Firestore/core/src/firebase/firestore/core/user_data.h"
  20. #include "Firestore/core/src/firebase/firestore/model/database_id.h"
  21. #include "Firestore/core/src/firebase/firestore/model/document_key.h"
  22. #include "Firestore/core/src/firebase/firestore/model/field_mask.h"
  23. #include "Firestore/core/src/firebase/firestore/model/field_transform.h"
  24. #include "Firestore/core/src/firebase/firestore/model/precondition.h"
  25. @class FSTObjectValue;
  26. @class FSTFieldValue;
  27. @class FSTMutation;
  28. namespace core = firebase::firestore::core;
  29. namespace model = firebase::firestore::model;
  30. NS_ASSUME_NONNULL_BEGIN
  31. /**
  32. * An internal representation of FIRDocumentReference, representing a key in a specific database.
  33. * This is necessary because keys assume a database from context (usually the current one).
  34. * FSTDocumentKeyReference binds a key to a specific databaseID.
  35. *
  36. * TODO(b/64160088): Make DocumentKey aware of the specific databaseID it is tied to.
  37. */
  38. @interface FSTDocumentKeyReference : NSObject
  39. - (instancetype)init NS_UNAVAILABLE;
  40. - (instancetype)initWithKey:(model::DocumentKey)key
  41. databaseID:(model::DatabaseId)databaseID NS_DESIGNATED_INITIALIZER;
  42. - (const model::DocumentKey &)key;
  43. @property(nonatomic, assign, readonly) const model::DatabaseId &databaseID;
  44. @end
  45. /**
  46. * An interface that allows arbitrary pre-converting of user data.
  47. *
  48. * Returns the converted value (can return back the input to act as a no-op).
  49. */
  50. typedef id _Nullable (^FSTPreConverterBlock)(id _Nullable);
  51. /**
  52. * Helper for parsing raw user input (provided via the API) into internal model classes.
  53. */
  54. @interface FSTUserDataConverter : NSObject
  55. - (instancetype)init NS_UNAVAILABLE;
  56. - (instancetype)initWithDatabaseID:(model::DatabaseId)databaseID
  57. preConverter:(FSTPreConverterBlock)preConverter NS_DESIGNATED_INITIALIZER;
  58. /** Parse document data from a non-merge setData call.*/
  59. - (core::ParsedSetData)parsedSetData:(id)input;
  60. /** Parse document data from a setData call with `merge:YES`. */
  61. - (core::ParsedSetData)parsedMergeData:(id)input fieldMask:(nullable NSArray<id> *)fieldMask;
  62. /** Parse update data from an updateData call. */
  63. - (core::ParsedUpdateData)parsedUpdateData:(id)input;
  64. /** Parse a "query value" (e.g. value in a where filter or a value in a cursor bound). */
  65. - (FSTFieldValue *)parsedQueryValue:(id)input;
  66. @end
  67. NS_ASSUME_NONNULL_END