From 00b08000e8a6cf7db3f00c36dcf0a1609a29b1b6 Mon Sep 17 00:00:00 2001 From: Diana Maria Perez Afanador Date: Fri, 26 Apr 2024 11:35:00 +0200 Subject: [PATCH 1/5] Add support for updating Atlas Device Sync's base url. --- CHANGELOG.md | 3 +++ Realm/ObjectServerTests/AsyncSyncTests.swift | 9 +++++++++ Realm/RLMApp.mm | 18 ++++++++++++++++++ Realm/RLMApp_Private.h | 7 +++++++ dependencies.list | 2 +- 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad74450074..ceb4cbf1cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,9 @@ x.y.z Release notes (yyyy-MM-dd) to "Embed & Sign" in the "Frameworks, Libraries, and Embedded Content" section on the General tab of your target's settings. ([#8561](https://github.com/realm/realm-swift/pull/8561)). + UUID/ObjectId types. ([.Net * #3566](https://github.com/realm/realm-dotnet/issues/3566)) +* Added `SyncConfiguration.initialSubscriptions` which describes the initial subscription configuration that was passed when constructing the `SyncConfiguration`. ([#8548](https://github.com/realm/realm-swift/issues/8548)) +* Added support for updating Atlas Device Sync's base url, in case the need to roam between servers (cloud and/or edge server). ([#8486](https://github.com/realm/realm-swift/issues/8486)) ### Fixed * `-[RLMUser allSessions]` did not include sessions which were currently diff --git a/Realm/ObjectServerTests/AsyncSyncTests.swift b/Realm/ObjectServerTests/AsyncSyncTests.swift index 4cecbe9912..a246aaeb67 100644 --- a/Realm/ObjectServerTests/AsyncSyncTests.swift +++ b/Realm/ObjectServerTests/AsyncSyncTests.swift @@ -78,6 +78,15 @@ class AsyncAwaitSyncTests: SwiftSyncTestCase { } } + func testUpdateBaseUrl() async throws { + let app = App(id: appId) + XCTAssertNotNil(app.baseURL) + XCTAssertEqual(app.baseURL, "http://localhost:9090") + + try await app.updateBaseUrl(to: "http://localhost:8080") + XCTAssertEqual(app.baseURL, "http://localhost:8080") + } + @MainActor func testAsyncOpenStandalone() async throws { try autoreleasepool { let configuration = Realm.Configuration(objectTypes: [SwiftPerson.self]) diff --git a/Realm/RLMApp.mm b/Realm/RLMApp.mm index 23330aeffc..1743e47988 100644 --- a/Realm/RLMApp.mm +++ b/Realm/RLMApp.mm @@ -414,6 +414,24 @@ - (RLMEmailPasswordAuth *)emailPasswordAuth { return [[RLMEmailPasswordAuth alloc] initWithApp:_app]; } +- (NSString *)baseUrl { + return getOptionalString(_app->get_base_url()) ?: RLMStringViewToNSString(_app->default_base_url()); +} + +- (void)updateBaseUrl:(NSString *)baseURL + completion:(RLMOptionalErrorBlock)completionHandler { + auto completion = ^(std::optional error) { + if (error) { + return completionHandler(makeError(*error)); + } + + completionHandler(nil); + }; + return RLMTranslateError([&] { + return _app->update_base_url(baseURL.UTF8String, completion); + }); +} + - (void)loginWithCredential:(RLMCredentials *)credentials completion:(RLMUserCompletionBlock)completionHandler { auto completion = ^(std::shared_ptr user, std::optional error) { diff --git a/Realm/RLMApp_Private.h b/Realm/RLMApp_Private.h index 0624f063c9..954a576bd0 100644 --- a/Realm/RLMApp_Private.h +++ b/Realm/RLMApp_Private.h @@ -31,6 +31,8 @@ typedef void(^RLMAppNotificationBlock)(RLMApp *); @end @interface RLMApp () +/// A custom base URL to request against. If not set or set to nil, the default base url for app services will be returned. +@property (nonatomic, readonly) NSString *baseURL; /// Returns all currently cached Apps + (NSArray *)allApps; /// Subscribe to notifications for this RLMApp. @@ -40,6 +42,11 @@ typedef void(^RLMAppNotificationBlock)(RLMApp *); + (RLMApp *_Nullable)cachedAppWithId:(NSString *)appId; + (void)resetAppCache; + +/// Updates the base url used by Atlas device sync, in case the need to roam between servers (cloud and/or edge server). +/// @param baseURL The new base url to connect to. +- (void)updateBaseURL:(NSString *)baseURL + completion:(RLMOptionalErrorBlock)completionHandler NS_SWIFT_NAME(updateBaseUrl(to:completion:)); @end @interface RLMAppConfiguration () diff --git a/dependencies.list b/dependencies.list index bd8c069450..ed8bd588a5 100755 --- a/dependencies.list +++ b/dependencies.list @@ -1,3 +1,3 @@ VERSION=10.49.2 REALM_CORE_VERSION=v14.6.0-7-gb2bb4f550 -STITCH_VERSION=8bf8ebcff6e804586c30a6ccbadb060753071a42 +STITCH_VERSION=40f356fbaf61e8df4f897e58357cd6a2c211825a From b4bebd67740f34d418a02127369a874b90614184 Mon Sep 17 00:00:00 2001 From: Diana Maria Perez Afanador Date: Tue, 30 Apr 2024 18:03:16 +0200 Subject: [PATCH 2/5] Solve PR comments --- CHANGELOG.md | 1 - Realm/ObjectServerTests/AsyncSyncTests.swift | 6 +++++ .../ObjectServerTests/RLMObjectServerTests.mm | 26 +++++++++++++++++++ Realm/RLMApp.mm | 6 +++-- Realm/RLMApp_Private.h | 4 +-- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ceb4cbf1cd..cfe99ea5e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,6 @@ x.y.z Release notes (yyyy-MM-dd) section on the General tab of your target's settings. ([#8561](https://github.com/realm/realm-swift/pull/8561)). UUID/ObjectId types. ([.Net * #3566](https://github.com/realm/realm-dotnet/issues/3566)) -* Added `SyncConfiguration.initialSubscriptions` which describes the initial subscription configuration that was passed when constructing the `SyncConfiguration`. ([#8548](https://github.com/realm/realm-swift/issues/8548)) * Added support for updating Atlas Device Sync's base url, in case the need to roam between servers (cloud and/or edge server). ([#8486](https://github.com/realm/realm-swift/issues/8486)) ### Fixed diff --git a/Realm/ObjectServerTests/AsyncSyncTests.swift b/Realm/ObjectServerTests/AsyncSyncTests.swift index a246aaeb67..53c3b4117d 100644 --- a/Realm/ObjectServerTests/AsyncSyncTests.swift +++ b/Realm/ObjectServerTests/AsyncSyncTests.swift @@ -85,6 +85,12 @@ class AsyncAwaitSyncTests: SwiftSyncTestCase { try await app.updateBaseUrl(to: "http://localhost:8080") XCTAssertEqual(app.baseURL, "http://localhost:8080") + + try await app.updateBaseUrl(to: "http://localhost:7070/") + XCTAssertEqual(app.baseURL, "http://localhost:7070") + + try await app.updateBaseUrl(to: nil) + XCTAssertEqual(app.baseURL, "https://realm.mongodb.com") } @MainActor func testAsyncOpenStandalone() async throws { diff --git a/Realm/ObjectServerTests/RLMObjectServerTests.mm b/Realm/ObjectServerTests/RLMObjectServerTests.mm index c6d0f65f82..11a9a4e5fe 100644 --- a/Realm/ObjectServerTests/RLMObjectServerTests.mm +++ b/Realm/ObjectServerTests/RLMObjectServerTests.mm @@ -81,6 +81,32 @@ - (NSArray *)defaultObjectTypes { #pragma mark - Authentication and Tokens +- (void)testUpdateBaseUrl { + RLMApp *app = self.app; + XCTAssertEqual(app.baseURL, @"http://localhost:9090"); + + XCTestExpectation *expectation = [self expectationWithDescription:@"should update base url"]; + [app updateBaseURL:@"http://localhost:8080" completion:^(NSError *error) { + XCTAssertNil(error); + [expectation fulfill]; + }]; + XCTAssertEqual(app.baseURL, @"http://localhost:8080"); + + XCTestExpectation *expectation1 = [self expectationWithDescription:@"should update base url"]; + [app updateBaseURL:@"http://localhost:7070/" completion:^(NSError *error) { + XCTAssertNil(error); + [expectation1 fulfill]; + }]; + XCTAssertEqual(app.baseURL, @"http://localhost:7070"); + + XCTestExpectation *expectation2 = [self expectationWithDescription:@"should update base url to default value"]; + [app updateBaseURL:nil completion:^(NSError *error) { + XCTAssertNil(error); + [expectation2 fulfill]; + }]; + XCTAssertEqual(app.baseURL, @"https://realm.mongodb.com"); +} + - (void)testAnonymousAuthentication { RLMUser *syncUser = self.anonymousUser; RLMUser *currentUser = [self.app currentUser]; diff --git a/Realm/RLMApp.mm b/Realm/RLMApp.mm index 1743e47988..b09f69b548 100644 --- a/Realm/RLMApp.mm +++ b/Realm/RLMApp.mm @@ -418,7 +418,7 @@ - (NSString *)baseUrl { return getOptionalString(_app->get_base_url()) ?: RLMStringViewToNSString(_app->default_base_url()); } -- (void)updateBaseUrl:(NSString *)baseURL +- (void)updateBaseUrl:(NSString *_Nullable)baseURL completion:(RLMOptionalErrorBlock)completionHandler { auto completion = ^(std::optional error) { if (error) { @@ -428,7 +428,9 @@ - (void)updateBaseUrl:(NSString *)baseURL completionHandler(nil); }; return RLMTranslateError([&] { - return _app->update_base_url(baseURL.UTF8String, completion); + NSString *url = (baseURL ?: @""); + NSString *newUrl = [url stringByReplacingOccurrencesOfString:@"/" withString:@"" options:0 range:NSMakeRange(url.length, url.length-1)]; + return _app->update_base_url(newUrl.UTF8String, completion); }); } diff --git a/Realm/RLMApp_Private.h b/Realm/RLMApp_Private.h index 954a576bd0..ad0ccce70b 100644 --- a/Realm/RLMApp_Private.h +++ b/Realm/RLMApp_Private.h @@ -44,8 +44,8 @@ typedef void(^RLMAppNotificationBlock)(RLMApp *); + (void)resetAppCache; /// Updates the base url used by Atlas device sync, in case the need to roam between servers (cloud and/or edge server). -/// @param baseURL The new base url to connect to. -- (void)updateBaseURL:(NSString *)baseURL +/// @param baseURL The new base url to connect to. Setting `nil` will reset the base url to the default url. +- (void)updateBaseURL:(NSString *_Nullable)baseURL completion:(RLMOptionalErrorBlock)completionHandler NS_SWIFT_NAME(updateBaseUrl(to:completion:)); @end From 8985c0585433bac9a8dada489ad7a4a89b01143c Mon Sep 17 00:00:00 2001 From: Diana Maria Perez Afanador Date: Wed, 1 May 2024 13:40:03 +0200 Subject: [PATCH 3/5] Solve PR comments and solve private API issues --- CHANGELOG.md | 12 +++++- Realm/ObjectServerTests/AsyncSyncTests.swift | 4 +- .../ObjectServerTests/RLMObjectServerTests.mm | 2 +- .../SwiftObjectServerTests.swift | 41 +++++++++++++++++- Realm/RLMApp.mm | 5 +-- Realm/RLMApp_Private.h | 4 +- RealmSwift/App.swift | 42 ++++++++++++++++--- 7 files changed, 94 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfe99ea5e5..1c01a03514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,16 @@ x.y.z Release notes (yyyy-MM-dd) ([Core #7552](https://github.com/realm/realm-core/pull/7552)). * Improve perfomance of IN queries and chained OR equality queries for UUID/ObjectId types. ([.Net #3566](https://github.com/realm/realm-dotnet/issues/3566)) + UUID/ObjectId types. ([.Net * #3566](https://github.com/realm/realm-dotnet/issues/3566)) +* Added support for updating Atlas Device Sync's base url, in case the need to roam between + servers (cloud and/or edge server). This API is private and can only be imported using + `@_spi(Private)` + ```swift + @_spi(Private) import RealmSwift + + try await app.updateBaseUrl(to: "https://services.cloud.mongodb.com") + ``` + ([#8486](https://github.com/realm/realm-swift/issues/8486)). * Enable building RealmSwift as a dynamic framework when installing via SPM, which lets us supply a privacy manifest. When RealmSwift is built as a static library you must supply your own manifest, as Xcode does not build static @@ -24,8 +34,6 @@ x.y.z Release notes (yyyy-MM-dd) to "Embed & Sign" in the "Frameworks, Libraries, and Embedded Content" section on the General tab of your target's settings. ([#8561](https://github.com/realm/realm-swift/pull/8561)). - UUID/ObjectId types. ([.Net * #3566](https://github.com/realm/realm-dotnet/issues/3566)) -* Added support for updating Atlas Device Sync's base url, in case the need to roam between servers (cloud and/or edge server). ([#8486](https://github.com/realm/realm-swift/issues/8486)) ### Fixed * `-[RLMUser allSessions]` did not include sessions which were currently diff --git a/Realm/ObjectServerTests/AsyncSyncTests.swift b/Realm/ObjectServerTests/AsyncSyncTests.swift index 53c3b4117d..328693f2cd 100644 --- a/Realm/ObjectServerTests/AsyncSyncTests.swift +++ b/Realm/ObjectServerTests/AsyncSyncTests.swift @@ -20,7 +20,7 @@ import Realm import Realm.Private -import RealmSwift +@_spi(Private) import RealmSwift import XCTest #if canImport(RealmTestSupport) @@ -90,7 +90,7 @@ class AsyncAwaitSyncTests: SwiftSyncTestCase { XCTAssertEqual(app.baseURL, "http://localhost:7070") try await app.updateBaseUrl(to: nil) - XCTAssertEqual(app.baseURL, "https://realm.mongodb.com") + XCTAssertEqual(app.baseURL, "https://services.cloud.mongodb.com") } @MainActor func testAsyncOpenStandalone() async throws { diff --git a/Realm/ObjectServerTests/RLMObjectServerTests.mm b/Realm/ObjectServerTests/RLMObjectServerTests.mm index 11a9a4e5fe..9eea48cb6f 100644 --- a/Realm/ObjectServerTests/RLMObjectServerTests.mm +++ b/Realm/ObjectServerTests/RLMObjectServerTests.mm @@ -104,7 +104,7 @@ - (void)testUpdateBaseUrl { XCTAssertNil(error); [expectation2 fulfill]; }]; - XCTAssertEqual(app.baseURL, @"https://realm.mongodb.com"); + XCTAssertEqual(app.baseURL, @"https://services.cloud.mongodb.com"); } - (void)testAnonymousAuthentication { diff --git a/Realm/ObjectServerTests/SwiftObjectServerTests.swift b/Realm/ObjectServerTests/SwiftObjectServerTests.swift index 4fe8b94290..e94c8e8311 100644 --- a/Realm/ObjectServerTests/SwiftObjectServerTests.swift +++ b/Realm/ObjectServerTests/SwiftObjectServerTests.swift @@ -21,7 +21,7 @@ import Combine import Realm import Realm.Private -import RealmSwift +@_spi(Private) import RealmSwift import XCTest #if canImport(RealmTestSupport) @@ -62,6 +62,45 @@ class SwiftObjectServerTests: SwiftSyncTestCase { ] } + func testUpdateBaseUrl() { + let app = App(id: appId) + XCTAssertNotNil(app.baseURL) + XCTAssertEqual(app.baseURL, "http://localhost:9090") + + let ex = expectation(description: "update base url") + app.updateBaseUrl(to: "http://localhost:8080", { result in + switch result { + case .success(let realm): + ex.fulfill() + case .failure(let error): + XCTFail("Should not return an error") + } + }) + XCTAssertEqual(app.baseURL, "http://localhost:8080") + + let ex1 = expectation(description: "update base url") + app.updateBaseUrl(to: "http://localhost:7070/", { result in + switch result { + case .success(let realm): + ex1.fulfill() + case .failure(let error): + XCTFail("Should not return an error") + } + }) + XCTAssertEqual(app.baseURL, "http://localhost:7070") + + let ex2 = expectation(description: "update base url") + app.updateBaseUrl(to: nil, { result in + switch result { + case .success(let realm): + ex2.fulfill() + case .failure(let error): + XCTFail("Should not return an error") + } + }) + XCTAssertEqual(app.baseURL, "https://services.cloud.mongodb.com") + } + func testBasicSwiftSync() throws { XCTAssert(try openRealm().isEmpty, "Freshly synced Realm was not empty...") } diff --git a/Realm/RLMApp.mm b/Realm/RLMApp.mm index b09f69b548..5778e3ced3 100644 --- a/Realm/RLMApp.mm +++ b/Realm/RLMApp.mm @@ -418,8 +418,7 @@ - (NSString *)baseUrl { return getOptionalString(_app->get_base_url()) ?: RLMStringViewToNSString(_app->default_base_url()); } -- (void)updateBaseUrl:(NSString *_Nullable)baseURL - completion:(RLMOptionalErrorBlock)completionHandler { +- (void)updateBaseURL:(NSString * _Nullable)baseURL completion:(nonnull RLMOptionalErrorBlock)completionHandler { auto completion = ^(std::optional error) { if (error) { return completionHandler(makeError(*error)); @@ -429,7 +428,7 @@ - (void)updateBaseUrl:(NSString *_Nullable)baseURL }; return RLMTranslateError([&] { NSString *url = (baseURL ?: @""); - NSString *newUrl = [url stringByReplacingOccurrencesOfString:@"/" withString:@"" options:0 range:NSMakeRange(url.length, url.length-1)]; + NSString *newUrl = [url stringByReplacingOccurrencesOfString:@"/" withString:@"" options:0 range:NSMakeRange(url.length-1, 1)]; return _app->update_base_url(newUrl.UTF8String, completion); }); } diff --git a/Realm/RLMApp_Private.h b/Realm/RLMApp_Private.h index ad0ccce70b..1f00557a64 100644 --- a/Realm/RLMApp_Private.h +++ b/Realm/RLMApp_Private.h @@ -45,8 +45,10 @@ typedef void(^RLMAppNotificationBlock)(RLMApp *); /// Updates the base url used by Atlas device sync, in case the need to roam between servers (cloud and/or edge server). /// @param baseURL The new base url to connect to. Setting `nil` will reset the base url to the default url. +/// @note Updating the base URL would trigger a client reset. - (void)updateBaseURL:(NSString *_Nullable)baseURL - completion:(RLMOptionalErrorBlock)completionHandler NS_SWIFT_NAME(updateBaseUrl(to:completion:)); + completion:(RLMOptionalErrorBlock)completionHandler NS_REFINED_FOR_SWIFT; + @end @interface RLMAppConfiguration () diff --git a/RealmSwift/App.swift b/RealmSwift/App.swift index 83956d006c..02f88ccd55 100644 --- a/RealmSwift/App.swift +++ b/RealmSwift/App.swift @@ -237,21 +237,51 @@ public extension App { } } - /// Login to a user for the Realm app. - /// @param credentials The credentials identifying the user. - /// @returns A publisher that eventually return `User` or `Error`. + /** + Updates the base url used by Atlas device sync, in case the need to roam between servers (cloud and/or edge server). + - parameter url: The new base url to connect to. Setting `nil` will reset the base url to the default url. + - note: Updating the base URL would trigger a client reset. + */ + @preconcurrency + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) + @_spi(Private) func updateBaseUrl(to url: String?, _ completion: @Sendable @escaping (Result) -> Void) { + self.__updateBaseURL(url) { error in + if let error = error { + completion(.failure(error)) + } else { + completion(.success(())) + } + } + } + + /** + Login to a user for the Realm app. + - parameter credentials: The credentials identifying the user. + - returns: A publisher that eventually return `User` or `Error`. + */ @available(macOS 10.15, watchOS 6.0, iOS 13.0, tvOS 13.0, *) func login(credentials: Credentials) -> Future { return future { self.login(credentials: credentials, $0) } } - /// Login to a user for the Realm app. - /// @param credentials The credentials identifying the user. - /// @returns A publisher that eventually return `User` or `Error`. + /** + Login to a user for the Realm app. + - parameter credentials: The credentials identifying the user. + */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) func login(credentials: Credentials) async throws -> User { try await __login(withCredential: ObjectiveCSupport.convert(object: credentials)) } + + /** + Updates the base url used by Atlas device sync, in case the need to roam between servers (cloud and/or edge server). + - parameter url: The new base url to connect to. Setting `nil` will reset the base url to the default url. + - note: Updating the base URL would trigger a client reset. + */ + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) + @_spi(Private) func updateBaseUrl(to url: String?) async throws { + try await __updateBaseURL(url) + } } /// Use this delegate to be provided a callback once authentication has succeed or failed From ead92bc2bfea4fdcb1e6a45681aa8ae18084170b Mon Sep 17 00:00:00 2001 From: Diana Maria Perez Afanador Date: Wed, 1 May 2024 18:58:09 +0200 Subject: [PATCH 4/5] Solve PR comments --- CHANGELOG.md | 3 +-- Realm/ObjectServerTests/AsyncSyncTests.swift | 2 +- .../SwiftObjectServerTests.swift | 14 +++++------ RealmSwift/App.swift | 23 +++++++++++++++---- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c01a03514..a059c8d67b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,11 @@ x.y.z Release notes (yyyy-MM-dd) ([Core #7552](https://github.com/realm/realm-core/pull/7552)). * Improve perfomance of IN queries and chained OR equality queries for UUID/ObjectId types. ([.Net #3566](https://github.com/realm/realm-dotnet/issues/3566)) - UUID/ObjectId types. ([.Net * #3566](https://github.com/realm/realm-dotnet/issues/3566)) * Added support for updating Atlas Device Sync's base url, in case the need to roam between servers (cloud and/or edge server). This API is private and can only be imported using `@_spi(Private)` ```swift - @_spi(Private) import RealmSwift + @_spi(RealmSwiftExperimental) import RealmSwift try await app.updateBaseUrl(to: "https://services.cloud.mongodb.com") ``` diff --git a/Realm/ObjectServerTests/AsyncSyncTests.swift b/Realm/ObjectServerTests/AsyncSyncTests.swift index 328693f2cd..a3ccb65f3c 100644 --- a/Realm/ObjectServerTests/AsyncSyncTests.swift +++ b/Realm/ObjectServerTests/AsyncSyncTests.swift @@ -20,7 +20,7 @@ import Realm import Realm.Private -@_spi(Private) import RealmSwift +@_spi(RealmSwiftExperimental) import RealmSwift import XCTest #if canImport(RealmTestSupport) diff --git a/Realm/ObjectServerTests/SwiftObjectServerTests.swift b/Realm/ObjectServerTests/SwiftObjectServerTests.swift index e94c8e8311..1d087b13c3 100644 --- a/Realm/ObjectServerTests/SwiftObjectServerTests.swift +++ b/Realm/ObjectServerTests/SwiftObjectServerTests.swift @@ -21,7 +21,7 @@ import Combine import Realm import Realm.Private -@_spi(Private) import RealmSwift +@_spi(RealmSwiftExperimental) import RealmSwift import XCTest #if canImport(RealmTestSupport) @@ -70,9 +70,9 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let ex = expectation(description: "update base url") app.updateBaseUrl(to: "http://localhost:8080", { result in switch result { - case .success(let realm): + case .success: ex.fulfill() - case .failure(let error): + case .failure: XCTFail("Should not return an error") } }) @@ -81,9 +81,9 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let ex1 = expectation(description: "update base url") app.updateBaseUrl(to: "http://localhost:7070/", { result in switch result { - case .success(let realm): + case .success: ex1.fulfill() - case .failure(let error): + case .failure: XCTFail("Should not return an error") } }) @@ -92,9 +92,9 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let ex2 = expectation(description: "update base url") app.updateBaseUrl(to: nil, { result in switch result { - case .success(let realm): + case .success: ex2.fulfill() - case .failure(let error): + case .failure: XCTFail("Should not return an error") } }) diff --git a/RealmSwift/App.swift b/RealmSwift/App.swift index 02f88ccd55..8bc9a16ba2 100644 --- a/RealmSwift/App.swift +++ b/RealmSwift/App.swift @@ -220,6 +220,20 @@ let credentials = Credentials.JWT(token: myToken) public typealias App = RLMApp public extension App { + /** + Updates the base url used by Atlas device sync, in case the need to roam between servers (cloud and/or edge server). + - parameter url: The new base url to connect to. Setting `nil` will reset the base url to the default url. + - parameter completion: A callback invoked after completion. + - note: Updating the base URL would trigger a client reset. + */ + @preconcurrency + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) + @_spi(RealmSwiftExperimental) func updateBaseUrl(to url: String?, _ completion: @Sendable @escaping (Error?) -> Void) { + self.__updateBaseURL(url, completion: { error in + completion(error) + }) + } + /** Login to a user for the Realm app. @@ -240,18 +254,19 @@ public extension App { /** Updates the base url used by Atlas device sync, in case the need to roam between servers (cloud and/or edge server). - parameter url: The new base url to connect to. Setting `nil` will reset the base url to the default url. + - parameter completion: A callback invoked after completion. Will return `Result.success` or `Result.failure(Error)`. - note: Updating the base URL would trigger a client reset. */ @preconcurrency @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) - @_spi(Private) func updateBaseUrl(to url: String?, _ completion: @Sendable @escaping (Result) -> Void) { - self.__updateBaseURL(url) { error in + @_spi(RealmSwiftExperimental) func updateBaseUrl(to url: String?, _ completion: @Sendable @escaping (Result) -> Void) { + self.__updateBaseURL(url, completion: { error in if let error = error { completion(.failure(error)) } else { completion(.success(())) } - } + }) } /** @@ -279,7 +294,7 @@ public extension App { - note: Updating the base URL would trigger a client reset. */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) - @_spi(Private) func updateBaseUrl(to url: String?) async throws { + @_spi(RealmSwiftExperimental) func updateBaseUrl(to url: String?) async throws { try await __updateBaseURL(url) } } From 226c96f10485c33abc25834ad94e4025dad82fa3 Mon Sep 17 00:00:00 2001 From: Nikola Irinchev Date: Thu, 2 May 2024 01:30:02 +0200 Subject: [PATCH 5/5] Don't wrap callback --- RealmSwift/App.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/RealmSwift/App.swift b/RealmSwift/App.swift index 8bc9a16ba2..c79afad2b3 100644 --- a/RealmSwift/App.swift +++ b/RealmSwift/App.swift @@ -229,9 +229,7 @@ public extension App { @preconcurrency @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) @_spi(RealmSwiftExperimental) func updateBaseUrl(to url: String?, _ completion: @Sendable @escaping (Error?) -> Void) { - self.__updateBaseURL(url, completion: { error in - completion(error) - }) + self.__updateBaseURL(url, completion: completion) } /**