RLMSyncUtil_Private.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import <Realm/RLMSyncUtil.h>
  19. #import <Realm/RLMProperty.h>
  20. #import <Realm/RLMRealmConfiguration.h>
  21. #import <Realm/RLMSyncCredentials.h>
  22. typedef NS_ENUM(NSUInteger, RLMSyncSystemErrorKind) {
  23. // Specific
  24. RLMSyncSystemErrorKindClientReset,
  25. // General
  26. RLMSyncSystemErrorKindClient,
  27. RLMSyncSystemErrorKindConnection,
  28. RLMSyncSystemErrorKindSession,
  29. RLMSyncSystemErrorKindUser,
  30. RLMSyncSystemErrorKindUnknown,
  31. };
  32. @class RLMSyncUser;
  33. typedef void(^RLMSyncCompletionBlock)(NSError * _Nullable, NSDictionary * _Nullable);
  34. typedef void(^RLMSyncBasicErrorReportingBlock)(NSError * _Nullable);
  35. typedef NSString* RLMServerPath;
  36. NS_ASSUME_NONNULL_BEGIN
  37. @interface RLMRealmConfiguration (RealmSync)
  38. + (instancetype)managementConfigurationForUser:(RLMSyncUser *)user;
  39. + (instancetype)permissionConfigurationForUser:(RLMSyncUser *)user;
  40. @end
  41. extern RLMIdentityProvider const RLMIdentityProviderAccessToken;
  42. extern RLMIdentityProvider const RLMIdentityProviderRealm;
  43. extern NSString *const kRLMSyncAppIDKey;
  44. extern NSString *const kRLMSyncDataKey;
  45. extern NSString *const kRLMSyncErrorJSONKey;
  46. extern NSString *const kRLMSyncErrorStatusCodeKey;
  47. extern NSString *const kRLMSyncIdentityKey;
  48. extern NSString *const kRLMSyncPasswordKey;
  49. extern NSString *const kRLMSyncPathKey;
  50. extern NSString *const kRLMSyncProviderKey;
  51. extern NSString *const kRLMSyncRegisterKey;
  52. extern NSString *const kRLMSyncUnderlyingErrorKey;
  53. /// Convert sync management object status code (nil, 0 and others) to
  54. /// RLMSyncManagementObjectStatus enum
  55. FOUNDATION_EXTERN RLMSyncManagementObjectStatus RLMMakeSyncManagementObjectStatus(NSNumber<RLMInt> * _Nullable statusCode);
  56. #define RLM_SYNC_UNINITIALIZABLE \
  57. - (instancetype)init __attribute__((unavailable("This type cannot be created directly"))); \
  58. + (instancetype)new __attribute__((unavailable("This type cannot be created directly")));
  59. NS_ASSUME_NONNULL_END
  60. /// A macro to parse a string out of a JSON dictionary, or return nil.
  61. #define RLM_SYNC_PARSE_STRING_OR_ABORT(json_macro_val, key_macro_val, prop_macro_val) \
  62. { \
  63. id data = json_macro_val[key_macro_val]; \
  64. if (![data isKindOfClass:[NSString class]]) { return nil; } \
  65. self.prop_macro_val = data; \
  66. } \
  67. #define RLM_SYNC_PARSE_OPTIONAL_STRING(json_macro_val, key_macro_val, prop_macro_val) \
  68. { \
  69. id data = json_macro_val[key_macro_val]; \
  70. if (![data isKindOfClass:[NSString class]]) { data = nil; } \
  71. self.prop_macro_val = data; \
  72. } \
  73. #define RLM_SYNC_PARSE_OPTIONAL_BOOL(json_macro_val, key_macro_val, prop_macro_val) \
  74. { \
  75. id data = json_macro_val[key_macro_val]; \
  76. if (![data isKindOfClass:[NSNumber class]]) { data = @NO; } \
  77. self.prop_macro_val = [data boolValue]; \
  78. } \
  79. /// A macro to parse a double out of a JSON dictionary, or return nil.
  80. #define RLM_SYNC_PARSE_DOUBLE_OR_ABORT(json_macro_val, key_macro_val, prop_macro_val) \
  81. { \
  82. id data = json_macro_val[key_macro_val]; \
  83. if (![data isKindOfClass:[NSNumber class]]) { return nil; } \
  84. self.prop_macro_val = [data doubleValue]; \
  85. } \
  86. /// A macro to build a sub-model out of a JSON dictionary, or return nil.
  87. #define RLM_SYNC_PARSE_MODEL_OR_ABORT(json_macro_val, key_macro_val, class_macro_val, prop_macro_val) \
  88. { \
  89. id raw = json_macro_val[key_macro_val]; \
  90. if (![raw isKindOfClass:[NSDictionary class]]) { return nil; } \
  91. id model = [[class_macro_val alloc] initWithDictionary:raw]; \
  92. if (!model) { return nil; } \
  93. self.prop_macro_val = model; \
  94. } \
  95. #define RLM_SYNC_PARSE_OPTIONAL_MODEL(json_macro_val, key_macro_val, class_macro_val, prop_macro_val) \
  96. { \
  97. id model; \
  98. id raw = json_macro_val[key_macro_val]; \
  99. if (![raw isKindOfClass:[NSDictionary class]]) { model = nil; } \
  100. else { model = [[class_macro_val alloc] initWithDictionary:raw]; } \
  101. self.prop_macro_val = model; \
  102. } \