RLMSyncUtil.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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/RLMConstants.h>
  19. /// A token originating from the Realm Object Server.
  20. typedef NSString* RLMServerToken;
  21. NS_ASSUME_NONNULL_BEGIN
  22. /// A user info key for use with `RLMSyncErrorClientResetError`.
  23. extern NSString *const kRLMSyncPathOfRealmBackupCopyKey;
  24. /// A user info key for use with `RLMSyncErrorClientResetError`.
  25. extern NSString *const kRLMSyncInitiateClientResetBlockKey;
  26. /**
  27. The error domain string for all SDK errors related to errors reported
  28. by the synchronization manager error handler, as well as general sync
  29. errors that don't fall into any of the other categories.
  30. */
  31. extern NSString *const RLMSyncErrorDomain;
  32. /**
  33. The error domain string for all SDK errors related to the authentication
  34. endpoint.
  35. */
  36. extern NSString *const RLMSyncAuthErrorDomain;
  37. /**
  38. The error domain string for all SDK errors related to the permissions
  39. system and APIs.
  40. */
  41. extern NSString *const RLMSyncPermissionErrorDomain;
  42. /**
  43. An error related to a problem that might be reported by the synchronization manager
  44. error handler, or a callback on a sync-related API that performs asynchronous work.
  45. */
  46. typedef RLM_ERROR_ENUM(NSInteger, RLMSyncError, RLMSyncErrorDomain) {
  47. /**
  48. An error that indicates that the response received from the
  49. authentication server was malformed.
  50. @warning This error is deprecated, and has been replaced by
  51. `RLMSyncAuthErrorBadResponse`.
  52. */
  53. RLMSyncErrorBadResponse __deprecated_msg("This error has been replaced by 'RLMSyncAuthErrorBadResponse'") = 1,
  54. /// An error that indicates a problem with the session (a specific Realm opened for sync).
  55. RLMSyncErrorClientSessionError = 4,
  56. /// An error that indicates a problem with a specific user.
  57. RLMSyncErrorClientUserError = 5,
  58. /**
  59. An error that indicates an internal, unrecoverable problem
  60. with the underlying synchronization engine.
  61. */
  62. RLMSyncErrorClientInternalError = 6,
  63. /**
  64. An error that indicates the Realm needs to be reset.
  65. A synced Realm may need to be reset because the Realm Object Server encountered an
  66. error and had to be restored from a backup. If the backup copy of the remote Realm
  67. is of an earlier version than the local copy of the Realm, the server will ask the
  68. client to reset the Realm.
  69. The reset process is as follows: the local copy of the Realm is copied into a recovery
  70. directory for safekeeping, and then deleted from the original location. The next time
  71. the Realm for that URL is opened, the Realm will automatically be re-downloaded from the
  72. Realm Object Server, and can be used as normal.
  73. Data written to the Realm after the local copy of the Realm diverged from the backup
  74. remote copy will be present in the local recovery copy of the Realm file. The
  75. re-downloaded Realm will initially contain only the data present at the time the Realm
  76. was backed up on the server.
  77. The client reset process can be initiated in one of two ways. The block provided in the
  78. `userInfo` dictionary under `kRLMSyncInitiateClientResetBlockKey` can be called to
  79. initiate the reset process. This block can be called any time after the error is
  80. received, but should only be called if and when your app closes and invalidates every
  81. instance of the offending Realm on all threads (note that autorelease pools may make this
  82. difficult to guarantee).
  83. If the block is not called, the client reset process will be automatically carried out
  84. the next time the app is launched and the `RLMSyncManager` singleton is accessed.
  85. The value for the `kRLMSyncPathOfRealmBackupCopyKey` key in the `userInfo` dictionary
  86. describes the path of the recovered copy of the Realm. This copy will not actually be
  87. created until the client reset process is initiated.
  88. @see `-[NSError rlmSync_clientResetBlock]`, `-[NSError rlmSync_clientResetBackedUpRealmPath]`
  89. */
  90. RLMSyncErrorClientResetError = 7,
  91. /**
  92. An error that indicates an authentication error occurred.
  93. The `kRLMSyncUnderlyingErrorKey` key in the user info dictionary will contain the
  94. underlying error, which is guaranteed to be under the `RLMSyncAuthErrorDomain`
  95. error domain.
  96. */
  97. RLMSyncErrorUnderlyingAuthError = 8,
  98. };
  99. /// An error which is related to authentication to a Realm Object Server.
  100. typedef RLM_ERROR_ENUM(NSInteger, RLMSyncAuthError, RLMSyncAuthErrorDomain) {
  101. /// An error that indicates that the response received from the authentication server was malformed.
  102. RLMSyncAuthErrorBadResponse = 1,
  103. /// An error that indicates that the supplied Realm path was invalid, or could not be resolved by the authentication
  104. /// server.
  105. RLMSyncAuthErrorBadRemoteRealmPath = 2,
  106. /// An error that indicates that the response received from the authentication server was an HTTP error code. The
  107. /// `userInfo` dictionary contains the actual error code value.
  108. RLMSyncAuthErrorHTTPStatusCodeError = 3,
  109. /// An error that indicates a problem with the session (a specific Realm opened for sync).
  110. RLMSyncAuthErrorClientSessionError = 4,
  111. /// An error that indicates that the provided credentials are invalid.
  112. RLMSyncAuthErrorInvalidCredential = 611,
  113. /// An error that indicates that the user with provided credentials does not exist.
  114. RLMSyncAuthErrorUserDoesNotExist = 612,
  115. /// An error that indicates that the user cannot be registered as it exists already.
  116. RLMSyncAuthErrorUserAlreadyExists = 613,
  117. };
  118. /**
  119. An error related to the permissions subsystem.
  120. */
  121. typedef RLM_ERROR_ENUM(NSInteger, RLMSyncPermissionError, RLMSyncPermissionErrorDomain) {
  122. /**
  123. An error that indicates a permission change operation failed. The `userInfo`
  124. dictionary contains the underlying error code and a message (if any).
  125. */
  126. RLMSyncPermissionErrorChangeFailed = 1,
  127. /**
  128. An error that indicates that attempting to retrieve permissions failed.
  129. */
  130. RLMSyncPermissionErrorGetFailed = 2,
  131. };
  132. /// An enum representing the different states a sync management object can take.
  133. typedef NS_ENUM(NSUInteger, RLMSyncManagementObjectStatus) {
  134. /// The management object has not yet been processed by the object server.
  135. RLMSyncManagementObjectStatusNotProcessed,
  136. /// The operations encoded in the management object have been successfully
  137. /// performed by the object server.
  138. RLMSyncManagementObjectStatusSuccess,
  139. /**
  140. The operations encoded in the management object were not successfully
  141. performed by the object server.
  142. Refer to the `statusCode` and `statusMessage` properties for more details
  143. about the error.
  144. */
  145. RLMSyncManagementObjectStatusError,
  146. };
  147. NS_ASSUME_NONNULL_END