Skip to content

Commit 705561b

Browse files
Solve PR comments
1 parent b4e84ff commit 705561b

File tree

3 files changed

+29
-90
lines changed

3 files changed

+29
-90
lines changed

CHANGELOG.md

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
11
x.y.z Release notes (yyyy-MM-dd)
22
=============================================================
33
### Enhancements
4-
* Redesign `@AsyncOpen` and `@AutoOpen` initialisers to allow setting a client reset modes for any sync configuration,
5-
and avoid confusion with the injected configuration and the sync configuration from the user on each intialiser.
4+
* Fix `@AsyncOpen` and `@AutoOpen` not using the syncConfiguration passed through
5+
the `configuration`, this is not allowing for the `initialSubscription` and
6+
`clientResetMode` to be passed in the initialiser or as an environment value.
67

78
### Fixed
89
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-swift/issues/????), since v?.?.?)
910
* None.
1011

11-
### Breaking Changes
12-
* `AsyncOpen.init(appId:partitionValue:configuration:timeout)` and
13-
`AutoOpen.init(appId:partitionValue:configuration:timeout)` will change behavior. Previously
14-
injecting both the configuration and a partition value will make the property wrappers to set
15-
the injected configuration (if not nil) combine with the syncConfiguration from the
16-
`user.configuration(partitionValue:)`. This will change to either user the injected configuration (if not nil)
17-
or the configuration obtained from `user.configuration(partitionValue:)` for the current logged user.
18-
This API will be deprecated on the next major release.
19-
* `AsyncOpen.init(appId:configuration:timeout)` and `AutoOpen.init(appId:configuration:timeout)`
20-
will change behavior. Previously this initialiser will set the injected configuration (if present)
21-
combine with the flexible sync configuration `user.flexibleSyncConfiguration` from the logged user.
22-
This will change to use the injected configuration which should already include a sync configuration.
23-
* `AsyncOpen.init(appId:partitionValue:timeout)` and `AutoOpen.init(appId:partitionValue:timeout)`
24-
are two new initialisers which allow us to configure the property wrappers for a partition based sync
25-
configuration for the current logged user.
26-
* `AsyncOpen.init(appId:timeout)` and `AutoOpen.init(appId:timeout)` are two new initialisers which
27-
allow us to configure the property wrappers for a flexible sync configuration for the current logged user.
28-
2912
### Compatibility
3013
* Realm Studio: 14.0.1 or later.
3114
* APIs are backwards compatible with all previous releases in the 10.x.y series.

Realm/ObjectServerTests/SwiftUIServerTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class SwiftUIServerTests: SwiftSyncTestCase {
348348
func testAsyncOpenPBSWithConfiguration() throws {
349349
let user = try logInUser(for: basicCredentials())
350350
if !isParent {
351-
populateRealm(user: user, partitionValue: #function)
351+
try populateRealm(user: user, partitionValue: #function)
352352
return
353353
}
354354
executeChild()
@@ -809,7 +809,7 @@ class SwiftUIServerTests: SwiftSyncTestCase {
809809
func testAutoOpenPBSWithConfiguration() throws {
810810
let user = try logInUser(for: basicCredentials())
811811
if !isParent {
812-
populateRealm(user: user, partitionValue: #function)
812+
try populateRealm(user: user, partitionValue: #function)
813813
return
814814
}
815815
executeChild()

RealmSwift/SwiftUI.swift

Lines changed: 24 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,22 +1526,33 @@ private class ObservableAsyncOpenStorage: ObservableObject {
15261526
}
15271527

15281528
private func asyncOpenForUser(_ user: User) {
1529-
// Set the `syncConfiguration` depending if there is partition value (pbs) or not (flx).
15301529
var config: Realm.Configuration
15311530

1532-
if let configuration = configuration {
1533-
// We want to throw if the configuration doesn't contain a `SyncConfiguration`
1534-
guard configuration.syncConfiguration != nil else {
1535-
throwRealmException("The used configuration was not configured with sync.")
1536-
}
1531+
if let configuration = self.configuration {
15371532
config = configuration
1533+
var syncConfig: SyncConfiguration?
1534+
if let syncConfiguration = configuration.syncConfiguration {
1535+
if let partitionValue = partitionValue {
1536+
syncConfig = user.configuration(partitionValue: partitionValue, clientResetMode: syncConfiguration.clientResetMode).syncConfiguration
1537+
}
1538+
} else {
1539+
if let partitionValue = partitionValue {
1540+
syncConfig = user.configuration(partitionValue: partitionValue).syncConfiguration
1541+
} else {
1542+
syncConfig = user.flexibleSyncConfiguration().syncConfiguration
1543+
}
1544+
}
1545+
if let syncConfig = syncConfig {
1546+
config.syncConfiguration = syncConfig
1547+
}
15381548
} else {
15391549
if let partitionValue = partitionValue {
15401550
config = user.configuration(partitionValue: partitionValue)
15411551
} else {
15421552
config = user.flexibleSyncConfiguration()
15431553
}
15441554
}
1555+
15451556
let syncConfiguration = config.syncConfiguration
15461557
syncConfiguration?.config.cancelAsyncOpenOnNonFatalErrors = true
15471558
config.syncConfiguration = syncConfiguration
@@ -1586,7 +1597,7 @@ private class ObservableAsyncOpenStorage: ObservableObject {
15861597
}
15871598

15881599
// We don't want to use the `defaultConfiguration` from the environment, we only want to use this environment value in @AsyncOpen if is not the default one
1589-
if configuration != .defaultConfiguration, self.configuration != configuration {
1600+
if configuration == .defaultConfiguration, self.configuration != configuration {
15901601
if let partitionValue = configuration.syncConfiguration?.partitionValue {
15911602
self.partitionValue = partitionValue
15921603
}
@@ -1705,9 +1716,9 @@ private class ObservableAsyncOpenStorage: ObservableObject {
17051716
- parameter timeout: The maximum number of milliseconds to allow for a connection to
17061717
become fully established., if empty or `nil` no connection timeout is set.
17071718

1708-
- note: This intialiser will use either the configuration or build a configuration from the partition value using `user.configuration(partitionValue:)`.
1719+
- note: This intializer will use either the configuration (if not nil) with the given partition value, or build a configuration from the
1720+
partition value using `user.configuration(partitionValue:)`.
17091721
*/
1710-
@available(*, deprecated, message: "This API will be deprecated. Use init(appId:partitionValue:timeout) if you want are connecting to a partition based sync without a configuration, or init(appId:configuration:timeout) in case you are using a configuration")
17111722
public init<Partition>(appId: String? = nil,
17121723
partitionValue: Partition,
17131724
configuration: Realm.Configuration? = nil,
@@ -1718,11 +1729,14 @@ private class ObservableAsyncOpenStorage: ObservableObject {
17181729
}
17191730

17201731
/**
1721-
Initialize the property wrapper with a configuration.
1732+
Initialize the property wrapper for a flexible sync app.
17221733
- parameter appId: The unique identifier of your Realm app, if empty or `nil` will try to retrieve latest singular cached app.
17231734
- parameter configuration: A configuration `Realm.configuration` to use when opening the Realm.
17241735
- parameter timeout: The maximum number of milliseconds to allow for a connection to
17251736
become fully established., if empty or `nil` no connection timeout is set.
1737+
1738+
- note: This intializer will use either the configuration (if not nil), or build a configuration from the
1739+
partition value using `user.flexibleSyncConfiguration()`.
17261740
*/
17271741
public init(appId: String? = nil,
17281742
configuration: Realm.Configuration? = nil,
@@ -1732,34 +1746,6 @@ private class ObservableAsyncOpenStorage: ObservableObject {
17321746
storage = ObservableAsyncOpenStorage(asyncOpenKind: .asyncOpen, app: app, configuration: configuration, partitionValue: nil)
17331747
}
17341748

1735-
/**
1736-
Initialize the property wrapper for a partition sync based sync app.
1737-
- parameter appId: The unique identifier of your Realm app, if empty or `nil` will try to retrieve latest singular cached app.
1738-
- parameter partitionValue: The `BSON` value the Realm is partitioned on.
1739-
- parameter timeout: The maximum number of milliseconds to allow for a connection to
1740-
become fully established., if empty or `nil` no connection timeout is set.
1741-
*/
1742-
public init<Partition>(appId: String? = nil,
1743-
partitionValue: Partition,
1744-
timeout: UInt? = nil) where Partition: BSON {
1745-
let app = ObservableAsyncOpenStorage.configureApp(appId: appId, timeout: timeout)
1746-
// Store property wrapper values on the storage
1747-
storage = ObservableAsyncOpenStorage(asyncOpenKind: .asyncOpen, app: app, configuration: nil, partitionValue: AnyBSON(partitionValue))
1748-
}
1749-
1750-
/**
1751-
Initialize the property wrapper for a flexible sync app.
1752-
- parameter appId: The unique identifier of your Realm app, if empty or `nil` will try to retrieve latest singular cached app.
1753-
- parameter timeout: The maximum number of milliseconds to allow for a connection to
1754-
become fully established., if empty or `nil` no connection timeout is set.
1755-
*/
1756-
public init(appId: String? = nil,
1757-
timeout: UInt? = nil) {
1758-
let app = ObservableAsyncOpenStorage.configureApp(appId: appId, timeout: timeout)
1759-
// Store property wrapper values on the storage
1760-
storage = ObservableAsyncOpenStorage(asyncOpenKind: .asyncOpen, app: app, configuration: nil, partitionValue: nil)
1761-
}
1762-
17631749
nonisolated public func update() {
17641750
assumeOnMainActorExecutor {
17651751
storage.update(partitionValue, configuration)
@@ -1846,7 +1832,6 @@ private class ObservableAsyncOpenStorage: ObservableObject {
18461832

18471833
- note: This intialiser will use either the configuration or build a configuration from the partition value using `user.configuration(partitionValue:)`.
18481834
*/
1849-
@available(*, deprecated, message: "This API will be deprecated. Use init(appId:partitionValue:timeout) if you want are connecting to a partition based sync without a configuration, or init(appId:configuration:timeout) in case you are using a configuration")
18501835
public init<Partition>(appId: String? = nil,
18511836
partitionValue: Partition,
18521837
configuration: Realm.Configuration? = nil,
@@ -1871,35 +1856,6 @@ private class ObservableAsyncOpenStorage: ObservableObject {
18711856
storage = ObservableAsyncOpenStorage(asyncOpenKind: .autoOpen, app: app, configuration: configuration, partitionValue: nil)
18721857
}
18731858

1874-
/**
1875-
Initialize the property wrapper for a partition sync based sync app.
1876-
- parameter appId: The unique identifier of your Realm app, if empty or `nil` will try to retrieve latest singular cached app.
1877-
- parameter partitionValue: The `BSON` value the Realm is partitioned on.
1878-
- parameter timeout: The maximum number of milliseconds to allow for a connection to
1879-
become fully established., if empty or `nil` no connection timeout is set.
1880-
*/
1881-
public init<Partition>(appId: String? = nil,
1882-
partitionValue: Partition,
1883-
timeout: UInt? = nil) where Partition: BSON {
1884-
let app = ObservableAsyncOpenStorage.configureApp(appId: appId, timeout: timeout)
1885-
// Store property wrapper values on the storage
1886-
storage = ObservableAsyncOpenStorage(asyncOpenKind: .autoOpen, app: app, configuration: nil, partitionValue: AnyBSON(partitionValue))
1887-
}
1888-
1889-
/**
1890-
Initialize the property wrapper for a flexible sync app.
1891-
- parameter appId: The unique identifier of your Realm app, if empty or `nil` will try to retrieve latest singular cached app.
1892-
- parameter timeout: The maximum number of milliseconds to allow for a connection to
1893-
become fully established., if empty or `nil` no connection timeout is set.
1894-
*/
1895-
public init(appId: String? = nil,
1896-
timeout: UInt? = nil) {
1897-
let app = ObservableAsyncOpenStorage.configureApp(appId: appId, timeout: timeout)
1898-
// Store property wrapper values on the storage
1899-
storage = ObservableAsyncOpenStorage(asyncOpenKind: .autoOpen, app: app, configuration: nil, partitionValue: nil)
1900-
}
1901-
1902-
19031859
nonisolated public func update() {
19041860
assumeOnMainActorExecutor {
19051861
storage.update(partitionValue, configuration)

0 commit comments

Comments
 (0)