RLMSyncUtil_Private.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. RLMSyncSystemErrorKindPermissionDenied,
  26. // General
  27. RLMSyncSystemErrorKindClient,
  28. RLMSyncSystemErrorKindConnection,
  29. RLMSyncSystemErrorKindSession,
  30. RLMSyncSystemErrorKindUser,
  31. RLMSyncSystemErrorKindUnknown,
  32. };
  33. @class RLMSyncUser;
  34. typedef void(^RLMSyncCompletionBlock)(NSError * _Nullable, NSDictionary * _Nullable);
  35. typedef void(^RLMSyncBasicErrorReportingBlock)(NSError * _Nullable);
  36. typedef NSString* RLMServerPath;
  37. NS_ASSUME_NONNULL_BEGIN
  38. @interface RLMRealmConfiguration (RealmSync)
  39. + (instancetype)managementConfigurationForUser:(RLMSyncUser *)user;
  40. + (instancetype)permissionConfigurationForUser:(RLMSyncUser *)user;
  41. @end
  42. extern RLMIdentityProvider const RLMIdentityProviderAccessToken;
  43. extern RLMIdentityProvider const RLMIdentityProviderRealm;
  44. extern NSString *const kRLMSyncAppIDKey;
  45. extern NSString *const kRLMSyncDataKey;
  46. extern NSString *const kRLMSyncErrorJSONKey;
  47. extern NSString *const kRLMSyncErrorStatusCodeKey;
  48. extern NSString *const kRLMSyncIdentityKey;
  49. extern NSString *const kRLMSyncPasswordKey;
  50. extern NSString *const kRLMSyncPathKey;
  51. extern NSString *const kRLMSyncTokenKey;
  52. extern NSString *const kRLMSyncProviderKey;
  53. extern NSString *const kRLMSyncProviderIDKey;
  54. extern NSString *const kRLMSyncRegisterKey;
  55. extern NSString *const kRLMSyncUnderlyingErrorKey;
  56. /// Convert sync management object status code (nil, 0 and others) to
  57. /// RLMSyncManagementObjectStatus enum
  58. FOUNDATION_EXTERN RLMSyncManagementObjectStatus RLMMakeSyncManagementObjectStatus(NSNumber<RLMInt> * _Nullable statusCode);
  59. #define RLM_SYNC_UNINITIALIZABLE \
  60. - (instancetype)init __attribute__((unavailable("This type cannot be created directly"))); \
  61. + (instancetype)new __attribute__((unavailable("This type cannot be created directly")));
  62. NS_ASSUME_NONNULL_END
  63. /// A macro to parse a string out of a JSON dictionary, or return nil.
  64. #define RLM_SYNC_PARSE_STRING_OR_ABORT(json_macro_val, key_macro_val, prop_macro_val) \
  65. { \
  66. id data = json_macro_val[key_macro_val]; \
  67. if (![data isKindOfClass:[NSString class]]) { return nil; } \
  68. self.prop_macro_val = data; \
  69. } \
  70. #define RLM_SYNC_PARSE_OPTIONAL_STRING(json_macro_val, key_macro_val, prop_macro_val) \
  71. { \
  72. id data = json_macro_val[key_macro_val]; \
  73. if (![data isKindOfClass:[NSString class]]) { data = nil; } \
  74. self.prop_macro_val = data; \
  75. } \
  76. #define RLM_SYNC_PARSE_OPTIONAL_BOOL(json_macro_val, key_macro_val, prop_macro_val) \
  77. { \
  78. id data = json_macro_val[key_macro_val]; \
  79. if (![data isKindOfClass:[NSNumber class]]) { data = @NO; } \
  80. self.prop_macro_val = [data boolValue]; \
  81. } \
  82. /// A macro to parse a double out of a JSON dictionary, or return nil.
  83. #define RLM_SYNC_PARSE_DOUBLE_OR_ABORT(json_macro_val, key_macro_val, prop_macro_val) \
  84. { \
  85. id data = json_macro_val[key_macro_val]; \
  86. if (![data isKindOfClass:[NSNumber class]]) { return nil; } \
  87. self.prop_macro_val = [data doubleValue]; \
  88. } \
  89. /// A macro to build a sub-model out of a JSON dictionary, or return nil.
  90. #define RLM_SYNC_PARSE_MODEL_OR_ABORT(json_macro_val, key_macro_val, class_macro_val, prop_macro_val) \
  91. { \
  92. id raw = json_macro_val[key_macro_val]; \
  93. if (![raw isKindOfClass:[NSDictionary class]]) { return nil; } \
  94. id model = [[class_macro_val alloc] initWithDictionary:raw]; \
  95. if (!model) { return nil; } \
  96. self.prop_macro_val = model; \
  97. } \
  98. #define RLM_SYNC_PARSE_OPTIONAL_MODEL(json_macro_val, key_macro_val, class_macro_val, prop_macro_val) \
  99. { \
  100. id model; \
  101. id raw = json_macro_val[key_macro_val]; \
  102. if (![raw isKindOfClass:[NSDictionary class]]) { model = nil; } \
  103. else { model = [[class_macro_val alloc] initWithDictionary:raw]; } \
  104. self.prop_macro_val = model; \
  105. } \