Skip to content

Commit

Permalink
Solve PR comments and solve private API issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaafanador3 committed May 1, 2024
1 parent b4bebd6 commit 8985c05
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 16 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Realm/ObjectServerTests/AsyncSyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import Realm
import Realm.Private
import RealmSwift
@_spi(Private) import RealmSwift

Check notice on line 23 in Realm/ObjectServerTests/AsyncSyncTests.swift

View check run for this annotation

Xcode Cloud / RealmSwift | sync_15.3 | Test - macOS

Realm/ObjectServerTests/AsyncSyncTests.swift#L23

Add '@preconcurrency' to suppress 'Sendable'-related warnings from module 'RealmSwift'
import XCTest

#if canImport(RealmTestSupport)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Realm/ObjectServerTests/RLMObjectServerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
41 changes: 40 additions & 1 deletion Realm/ObjectServerTests/SwiftObjectServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import Combine
import Realm
import Realm.Private
import RealmSwift
@_spi(Private) import RealmSwift
import XCTest

#if canImport(RealmTestSupport)
Expand Down Expand Up @@ -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):

Check notice on line 73 in Realm/ObjectServerTests/SwiftObjectServerTests.swift

View check run for this annotation

Xcode Cloud / RealmSwift | sync_15.3 | Test - macOS

Realm/ObjectServerTests/SwiftObjectServerTests.swift#L73

Immutable value 'realm' was never used; consider replacing with '_' or removing it
ex.fulfill()
case .failure(let error):

Check notice on line 75 in Realm/ObjectServerTests/SwiftObjectServerTests.swift

View check run for this annotation

Xcode Cloud / RealmSwift | sync_15.3 | Test - macOS

Realm/ObjectServerTests/SwiftObjectServerTests.swift#L75

Immutable value 'error' was never used; consider replacing with '_' or removing it
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):

Check notice on line 84 in Realm/ObjectServerTests/SwiftObjectServerTests.swift

View check run for this annotation

Xcode Cloud / RealmSwift | sync_15.3 | Test - macOS

Realm/ObjectServerTests/SwiftObjectServerTests.swift#L84

Immutable value 'realm' was never used; consider replacing with '_' or removing it
ex1.fulfill()
case .failure(let error):

Check notice on line 86 in Realm/ObjectServerTests/SwiftObjectServerTests.swift

View check run for this annotation

Xcode Cloud / RealmSwift | sync_15.3 | Test - macOS

Realm/ObjectServerTests/SwiftObjectServerTests.swift#L86

Immutable value 'error' was never used; consider replacing with '_' or removing it
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):

Check notice on line 95 in Realm/ObjectServerTests/SwiftObjectServerTests.swift

View check run for this annotation

Xcode Cloud / RealmSwift | sync_15.3 | Test - macOS

Realm/ObjectServerTests/SwiftObjectServerTests.swift#L95

Immutable value 'realm' was never used; consider replacing with '_' or removing it
ex2.fulfill()
case .failure(let error):

Check notice on line 97 in Realm/ObjectServerTests/SwiftObjectServerTests.swift

View check run for this annotation

Xcode Cloud / RealmSwift | sync_15.3 | Test - macOS

Realm/ObjectServerTests/SwiftObjectServerTests.swift#L97

Immutable value 'error' was never used; consider replacing with '_' or removing it
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...")
}
Expand Down
5 changes: 2 additions & 3 deletions Realm/RLMApp.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<app::AppError> error) {
if (error) {
return completionHandler(makeError(*error));
Expand All @@ -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);
});
}
Expand Down
4 changes: 3 additions & 1 deletion Realm/RLMApp_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
42 changes: 36 additions & 6 deletions RealmSwift/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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, Error>) -> 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<User, Error> {
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
Expand Down

0 comments on commit 8985c05

Please sign in to comment.