RLMSyncUtil.h 8.8 KB

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