Repository: realm/realm-swift
File: RealmSwift/Sync.swift (Swift)

Code before:
                                         afterReset: (@Sendable (_ before: Realm, _ after: Realm) -> Void)? = nil)
    /// - seeAlso: ``RLMClientResetModeManual``
    ///
    /// The manual client reset mode handler can be set in two places:
    /// 1. As an ErrorReportingBlock argument in the ClientResetMode enum (``ErrorReportingBlock?` = nil`).
    /// 2. As an ErrorReportingBlock in the ``SyncManager.errorHandler`` property.
    /// - seeAlso: ``RLMSyncManager.errorHandler``
    ///
    /// During an ``RLMSyncErrorClientResetError`` the block executed is determined by the following rules
    /// - If an error reporting block is set in ``ClientResetMode`` and the ``SyncManager``, the ``ClientResetMode`` block will be executed.
    /// - If an error reporting block is set in either the ``ClientResetMode`` or the ``SyncManager``, but not both, the single block will execute.
    /// - If no block is set in either location, the client reset will not be handled. The application will likely need to be restarted and unsynced local changes may be lost.
    /// - note: The ``SyncManager.errorHandler`` is still invoked under all ``RLMSyncError``s *other than* ``RLMSyncErrorClientResetError``.
    /// - seeAlso ``RLMSyncError`` for an exhaustive list.
    @preconcurrency
    case manual(errorHandler: ErrorReportingBlock? = nil)
}

/**
 A configuration controlling how the initial subscriptions are populated when a Realm file is first opened.

 - seeAlso ``Realm.subscriptions``
 - seeAlso https://www.mongodb.com/docs/atlas/device-sdks/sdk/swift/sync/flexible-sync/ for more information
   about managing subscriptions with flexible sync.
 */
@frozen public struct InitialSubscriptionsConfiguration: Sendable {
    /**
     Controls whether to re-run ``callback`` every time the Realm is opened.
     */
    public var rerunOnOpen: Bool {
        config.rerunOnOpen
    }

    /**
     A callback that's executed in an update block to populate the initial subscriptions for that Realm.

     This callback will only be executed when the Realm is first created, unless ``rerunOnOpen`` is `true`, in which case it will be executed every time
     the Realm is opened.
     */
    public var callback: @Sendable (SyncSubscriptionSet) -> Void {
        ObjectiveCSupport.convert(block: config.callback)
    }

    @Unchecked internal var config: RLMInitialSubscriptionsConfiguration
    internal init(config: RLMInitialSubscriptionsConfiguration) {
        self.config = config
    }}

/**
 A `SyncConfiguration` represents configuration parameters for Realms intended to sync with
 Atlas App Services.

Review comment (suggestion):
There doesn't appear to be any need for this wrapper as it's not exposing a different API from the obj-c type.

Code after:
                                         afterReset: (@Sendable (_ before: Realm, _ after: Realm) -> Void)? = nil)
    /// - seeAlso: ``RLMClientResetModeManual``
    ///
    /// The manual client reset mode handler can be set in two places:
    /// 1. As an ErrorReportingBlock argument in the ClientResetMode enum (``ErrorReportingBlock?` = nil`).
    /// 2. As an ErrorReportingBlock in the ``SyncManager.errorHandler`` property.
    /// - seeAlso: ``RLMSyncManager.errorHandler``
    ///
    /// During an ``RLMSyncErrorClientResetError`` the block executed is determined by the following rules
    /// - If an error reporting block is set in ``ClientResetMode`` and the ``SyncManager``, the ``ClientResetMode`` block will be executed.
    /// - If an error reporting block is set in either the ``ClientResetMode`` or the ``SyncManager``, but not both, the single block will execute.
    /// - If no block is set in either location, the client reset will not be handled. The application will likely need to be restarted and unsynced local changes may be lost.
    /// - note: The ``SyncManager.errorHandler`` is still invoked under all ``RLMSyncError``s *other than* ``RLMSyncErrorClientResetError``.
    /// - seeAlso ``RLMSyncError`` for an exhaustive list.
    @preconcurrency
    case manual(errorHandler: ErrorReportingBlock? = nil)
}


/**
 A configuration controlling how the initial subscriptions are populated when a Realm file is first opened.

 - see: `RLMInitialSubscriptionsConfiguration`
 */
public typealias InitialSubscriptionsConfiguration = RLMInitialSubscriptionsConfiguration

/**
 A `SyncConfiguration` represents configuration parameters for Realms intended to sync with
 Atlas App Services.
 */
@frozen public struct SyncConfiguration: Sendable {
    /// The `SyncUser` who owns the Realm that this configuration should open.
    public var user: User {
        config.user
    }

    /**
     The value this Realm is partitioned on. The partition key is a property defined in
     Atlas App Services. All classes with a property with this value will be synchronized to the
     Realm.
     */
    public var partitionValue: AnyBSON? {
        ObjectiveCSupport.convert(object: config.partitionValue)
    }

    /**
     An enum which determines file recovery behavior in the event of a client reset.
     - note: Defaults to ``.recoverUnsyncedChanges``

     - see: ``ClientResetMode`` and ``RLMClientResetMode``
     - see: https://docs.mongodb.com/realm/sync/error-handling/client-resets/