FSTUserDataReader.h 3.4 KB

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