FSTUserDataConverter.h 3.0 KB

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