Skip to content

Commit 04af045

Browse files
committed
Update core
1 parent 9ece953 commit 04af045

37 files changed

+294
-276
lines changed

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ let package = Package(
153153
targets: ["Realm", "RealmSwift"]),
154154
],
155155
dependencies: [
156-
.package(url: "https://github.com/realm/realm-core.git", exact: coreVersion)
156+
.package(path: "/opt/s/realm-core")
157157
],
158158
targets: [
159159
.target(

Realm/ObjectServerTests/ClientResetTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class ClientResetTests: SwiftSyncTestCase {
102102
}
103103
XCTAssertTrue(path.contains("mongodb-realm/\(app.appId)/recovered-realms/recovered_realm"))
104104
XCTAssertFalse(FileManager.default.fileExists(atPath: path))
105-
SyncSession.immediatelyHandleError(token, syncManager: app.syncManager)
105+
SyncSession.immediatelyHandleError(token)
106106
XCTAssertTrue(FileManager.default.fileExists(atPath: path))
107107
ex.fulfill()
108108
}

Realm/ObjectServerTests/RLMMongoClientTests.mm

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#import "RLMBSON_Private.hpp"
2323
#import "RLMUser_Private.hpp"
2424

25+
#import <realm/object-store/sync/app_user.hpp>
2526
#import <realm/object-store/sync/sync_manager.hpp>
2627
#import <realm/util/bson/bson.hpp>
2728

@@ -735,8 +736,8 @@ - (void)performMultipleWatchStreamsTest:(nullable dispatch_queue_t)delegateQueue
735736
s << RLMConvertRLMBSONToBson(partitionValue);
736737
// Intentionally not passing the correct partition value here as we (accidentally?)
737738
// don't use the filename generated from the partition value
738-
realm::SyncConfig config(user._syncUser, "null");
739-
return @(user._syncUser->sync_manager()->path_for_realm(config, s.str()).c_str());
739+
realm::SyncConfig config(user.user, "null");
740+
return @(user.user->path_for_realm(config, s.str()).c_str());
740741
}
741742

742743
- (void)testSyncFilePaths {
@@ -763,10 +764,10 @@ - (void)testSyncFilePaths {
763764
}
764765

765766
static NSString *oldPathForPartitionValue(RLMUser *user, NSString *oldName) {
766-
realm::SyncConfig config(user._syncUser, "null");
767+
realm::SyncConfig config(user.user, "null");
767768
return [NSString stringWithFormat:@"%@/%s%@.realm",
768-
[@(user._syncUser->sync_manager()->path_for_realm(config).c_str()) stringByDeletingLastPathComponent],
769-
user._syncUser->identity().c_str(), oldName];
769+
[@(user.user->path_for_realm(config).c_str()) stringByDeletingLastPathComponent],
770+
user.user->user_id().c_str(), oldName];
770771
}
771772

772773
- (void)testLegacyFilePathsAreUsedIfFilesArePresent {

Realm/ObjectServerTests/RLMObjectServerTests.mm

+12-12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#import "RLMWatchTestUtility.h"
3838

3939
#import <realm/object-store/shared_realm.hpp>
40+
#import <realm/object-store/sync/app_user.hpp>
4041
#import <realm/object-store/sync/sync_manager.hpp>
4142
#import <realm/object-store/thread_safe_reference.hpp>
4243
#import <realm/util/file.hpp>
@@ -166,7 +167,7 @@ - (void)testRemoveUser {
166167
}
167168

168169
- (void)testDeleteUser {
169-
[self createUser];
170+
RLMUser *firstUser = [self createUser];
170171
RLMUser *secondUser = [self createUser];
171172

172173
XCTAssert([self.app.currentUser.identifier isEqualToString:secondUser.identifier]);
@@ -176,7 +177,7 @@ - (void)testDeleteUser {
176177
[secondUser deleteWithCompletion:^(NSError *error) {
177178
XCTAssert(!error);
178179
XCTAssert(self.app.allUsers.count == 1);
179-
XCTAssertNil(self.app.currentUser);
180+
XCTAssertEqualObjects(self.app.currentUser, firstUser);
180181
XCTAssertEqual(secondUser.state, RLMUserStateRemoved);
181182
[deleteUserExpectation fulfill];
182183
}];
@@ -560,7 +561,7 @@ - (void)testSyncErrorHandlerErrorDomain {
560561
#pragma mark - User Profile
561562

562563
- (void)testUserProfileInitialization {
563-
RLMUserProfile *profile = [[RLMUserProfile alloc] initWithUserProfile:realm::SyncUserProfile()];
564+
RLMUserProfile *profile = [[RLMUserProfile alloc] initWithUserProfile:realm::app::UserProfile()];
564565
XCTAssertNil(profile.name);
565566
XCTAssertNil(profile.maxAge);
566567
XCTAssertNil(profile.minAge);
@@ -572,7 +573,7 @@ - (void)testUserProfileInitialization {
572573

573574
auto metadata = realm::bson::BsonDocument({{"some_key", "some_value"}});
574575

575-
profile = [[RLMUserProfile alloc] initWithUserProfile:realm::SyncUserProfile(realm::bson::BsonDocument({
576+
profile = [[RLMUserProfile alloc] initWithUserProfile:realm::app::UserProfile(realm::bson::BsonDocument({
576577
{"name", "Jane"},
577578
{"max_age", "40"},
578579
{"min_age", "30"},
@@ -758,7 +759,7 @@ - (void)testSessionRefresh {
758759

759760
// Should result in an access token error followed by a refresh when we
760761
// open the Realm which is entirely transparent to the user
761-
user._syncUser->update_access_token(self.badAccessToken.UTF8String);
762+
// user._syncUser->update_access_token(self.badAccessToken.UTF8String);
762763
RLMRealm *realm = [self openRealmForPartitionValue:self.name user:user];
763764

764765
RLMRealm *realm2 = [self openRealm];
@@ -1367,8 +1368,7 @@ - (void)testClientResetManualInitiation {
13671368
// At this point the Realm should be invalidated and client reset should be possible.
13681369
NSString *pathValue = [theError rlmSync_clientResetBackedUpRealmPath];
13691370
XCTAssertFalse([NSFileManager.defaultManager fileExistsAtPath:pathValue]);
1370-
[RLMSyncSession immediatelyHandleError:theError.rlmSync_errorActionToken
1371-
syncManager:self.app.syncManager];
1371+
[RLMSyncSession immediatelyHandleError:theError.rlmSync_errorActionToken];
13721372
XCTAssertTrue([NSFileManager.defaultManager fileExistsAtPath:pathValue]);
13731373
}
13741374

@@ -2016,8 +2016,8 @@ - (void)testWriteCopyForConfigurationLocalRealmForSyncWithExistingData {
20162016
s << RLMConvertRLMBSONToBson(partitionValue);
20172017
// Intentionally not passing the correct partition value here as we (accidentally?)
20182018
// don't use the filename generated from the partition value
2019-
realm::SyncConfig config(user._syncUser, "null");
2020-
return @(user._syncUser->sync_manager()->path_for_realm(config, s.str()).c_str());
2019+
realm::SyncConfig config(user.user, "null");
2020+
return @(user.user->path_for_realm(config, s.str()).c_str());
20212021
}
20222022

20232023
- (void)testSyncFilePaths {
@@ -2044,10 +2044,10 @@ - (void)testSyncFilePaths {
20442044
}
20452045

20462046
static NSString *oldPathForPartitionValue(RLMUser *user, NSString *oldName) {
2047-
realm::SyncConfig config(user._syncUser, "null");
2047+
realm::SyncConfig config(user.user, "null");
20482048
return [NSString stringWithFormat:@"%@/%s%@.realm",
2049-
[@(user._syncUser->sync_manager()->path_for_realm(config).c_str()) stringByDeletingLastPathComponent],
2050-
user._syncUser->identity().c_str(), oldName];
2049+
[@(user.user->path_for_realm(config).c_str()) stringByDeletingLastPathComponent],
2050+
user.user->user_id().c_str(), oldName];
20512051
}
20522052

20532053
- (void)testLegacyFilePathsAreUsedIfFilesArePresent {

Realm/ObjectServerTests/RLMSyncTestCase.mm

+13-13
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
#import "RLMChildProcessEnvironment.h"
3333
#import "RLMRealmUtil.hpp"
3434

35+
#import <realm/object-store/sync/app_user.hpp>
3536
#import <realm/object-store/sync/sync_manager.hpp>
3637
#import <realm/object-store/sync/sync_session.hpp>
37-
#import <realm/object-store/sync/sync_user.hpp>
3838

3939
#if TARGET_OS_OSX
4040

@@ -56,7 +56,7 @@ - (BOOL)waitForDownloadCompletionOnQueue:(dispatch_queue_t)queue callback:(void(
5656
@end
5757

5858
@interface RLMUser ()
59-
- (std::shared_ptr<realm::SyncUser>)_syncUser;
59+
- (std::shared_ptr<realm::app::User>)_syncUser;
6060
@end
6161

6262
@interface TestNetworkTransport : RLMNetworkTransport
@@ -421,9 +421,11 @@ - (void)waitForDownloadsForRealm:(RLMRealm *)realm error:(NSError **)error {
421421
}
422422

423423
- (void)setInvalidTokensForUser:(RLMUser *)user {
424-
auto token = self.badAccessToken.UTF8String;
425-
user._syncUser->log_out();
426-
user._syncUser->log_in(token, token);
424+
realm::RealmJWT token(std::string_view(self.badAccessToken.UTF8String));
425+
user._syncUser->update_data_for_testing([&](auto& data) {
426+
data.access_token = token;
427+
data.refresh_token = token;
428+
});
427429
}
428430

429431
- (void)writeToPartition:(NSString *)partition block:(void (^)(RLMRealm *))block {
@@ -554,15 +556,13 @@ - (void)resetAppCache {
554556
[user logOutWithCompletion:^(NSError *) {
555557
[ex fulfill];
556558
}];
557-
558-
// Sessions are removed from the user asynchronously after a logout.
559-
// We need to wait for this to happen before calling resetForTesting as
560-
// that expects all sessions to be cleaned up first.
561-
if (user.allSessions.count) {
562-
[exs addObject:[self expectationForPredicate:[NSPredicate predicateWithFormat:@"allSessions.@count == 0"]
563-
evaluatedWithObject:user handler:nil]];
564-
}
565559
}];
560+
561+
// Sessions are removed from the user asynchronously after a logout.
562+
// We need to wait for this to happen before calling resetForTesting as
563+
// that expects all sessions to be cleaned up first.
564+
[exs addObject:[self expectationForPredicate:[NSPredicate predicateWithFormat:@"hasAnySessions = false"]
565+
evaluatedWithObject:app.syncManager handler:nil]];
566566
}
567567

568568
if (exs.count) {

Realm/RLMAPIKeyAuth.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ @implementation RLMAPIKeyAuth
3131
return self.app._realmApp->provider_client<App::UserAPIKeyProviderClient>();
3232
}
3333

34-
- (std::shared_ptr<realm::SyncUser>)currentUser {
34+
- (std::shared_ptr<realm::app::User>)currentUser {
3535
return self.app._realmApp->current_user();
3636
}
3737

Realm/RLMApp.mm

+33-31
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
#import "RLMCredentials_Private.hpp"
3030
#import "RLMEmailPasswordAuth.h"
3131
#import "RLMLogger.h"
32+
#import "RLMProviderClient_Private.hpp"
3233
#import "RLMPushClient_Private.hpp"
3334
#import "RLMSyncManager_Private.hpp"
3435
#import "RLMUser_Private.hpp"
3536
#import "RLMUtil.hpp"
3637

38+
#import <realm/object-store/sync/app_user.hpp>
3739
#import <realm/object-store/sync/sync_manager.hpp>
3840
#import <realm/sync/config.hpp>
3941

@@ -94,15 +96,14 @@ void send_request_to_server(const app::Request& request,
9496

9597
#pragma mark RLMAppConfiguration
9698
@implementation RLMAppConfiguration {
97-
realm::app::App::Config _config;
98-
SyncClientConfig _clientConfig;
99+
realm::app::AppConfig _config;
99100
}
100101

101102
- (instancetype)init {
102103
if (self = [super init]) {
103104
self.enableSessionMultiplexing = true;
104105
self.encryptMetadata = !getenv("REALM_DISABLE_METADATA_ENCRYPTION") && !RLMIsRunningInPlayground();
105-
RLMNSStringToStdString(_clientConfig.base_file_path, RLMDefaultDirectoryForBundleIdentifier(nil));
106+
RLMNSStringToStdString(_config.base_file_path, RLMDefaultDirectoryForBundleIdentifier(nil));
106107
configureSyncConnectionParameters(_config);
107108
}
108109
return self;
@@ -152,7 +153,7 @@ - (instancetype)initWithBaseURL:(nullable NSString *)baseURL
152153
return self;
153154
}
154155

155-
static void configureSyncConnectionParameters(realm::app::App::Config& config) {
156+
static void configureSyncConnectionParameters(realm::app::AppConfig& config) {
156157
// Anonymized BundleId
157158
NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier];
158159
NSData *bundleIdData = [bundleId dataUsingEncoding:NSUTF8StringEncoding];
@@ -178,21 +179,16 @@ static void configureSyncConnectionParameters(realm::app::App::Config& config) {
178179
config.device_info.device_version = systemInfo.machine;
179180
}
180181

181-
- (const realm::app::App::Config&)config {
182+
- (const realm::app::AppConfig&)config {
182183
if (!_config.transport) {
183184
self.transport = nil;
184185
}
185186
return _config;
186187
}
187188

188-
- (const realm::SyncClientConfig&)clientConfig {
189-
return _clientConfig;
190-
}
191-
192189
- (id)copyWithZone:(NSZone *)zone {
193190
RLMAppConfiguration *copy = [[RLMAppConfiguration alloc] init];
194191
copy->_config = _config;
195-
copy->_clientConfig = _clientConfig;
196192
return copy;
197193
}
198194

@@ -250,36 +246,36 @@ - (void)setDefaultRequestTimeoutMS:(NSUInteger)defaultRequestTimeoutMS {
250246
}
251247

252248
- (BOOL)enableSessionMultiplexing {
253-
return _clientConfig.multiplex_sessions;
249+
return _config.sync_client_config.multiplex_sessions;
254250
}
255251

256252
- (void)setEnableSessionMultiplexing:(BOOL)enableSessionMultiplexing {
257-
_clientConfig.multiplex_sessions = enableSessionMultiplexing;
253+
_config.sync_client_config.multiplex_sessions = enableSessionMultiplexing;
258254
}
259255

260256
- (BOOL)encryptMetadata {
261-
return _clientConfig.metadata_mode == SyncManager::MetadataMode::Encryption;
257+
return _config.metadata_mode == app::AppConfig::MetadataMode::Encryption;
262258
}
263259

264260
- (void)setEncryptMetadata:(BOOL)encryptMetadata {
265-
_clientConfig.metadata_mode = encryptMetadata ? SyncManager::MetadataMode::Encryption
266-
: SyncManager::MetadataMode::NoEncryption;
261+
_config.metadata_mode = encryptMetadata ? app::AppConfig::MetadataMode::Encryption
262+
: app::AppConfig::MetadataMode::NoEncryption;
267263
}
268264

269265
- (NSURL *)rootDirectory {
270-
return [NSURL fileURLWithPath:RLMStringViewToNSString(_clientConfig.base_file_path)];
266+
return [NSURL fileURLWithPath:RLMStringViewToNSString(_config.base_file_path)];
271267
}
272268

273269
- (void)setRootDirectory:(NSURL *)rootDirectory {
274-
RLMNSStringToStdString(_clientConfig.base_file_path, rootDirectory.path);
270+
RLMNSStringToStdString(_config.base_file_path, rootDirectory.path);
275271
}
276272

277273
- (RLMSyncTimeoutOptions *)syncTimeouts {
278-
return [[RLMSyncTimeoutOptions alloc] initWithOptions:_clientConfig.timeouts];
274+
return [[RLMSyncTimeoutOptions alloc] initWithOptions:_config.sync_client_config.timeouts];
279275
}
280276

281277
- (void)setSyncTimeouts:(RLMSyncTimeoutOptions *)syncTimeouts {
282-
_clientConfig.timeouts = syncTimeouts->_options;
278+
_config.sync_client_config.timeouts = syncTimeouts->_options;
283279
}
284280

285281
@end
@@ -334,16 +330,16 @@ - (instancetype)initWithApp:(std::shared_ptr<realm::app::App>&&)app config:(RLMA
334330
- (instancetype)initWithConfiguration:(RLMAppConfiguration *)configuration {
335331
if (self = [super init]) {
336332
_app = RLMTranslateError([&] {
337-
return app::App::get_app(app::App::CacheMode::Enabled, configuration.config, configuration.clientConfig);
333+
return app::App::get_app(app::App::CacheMode::Disabled, configuration.config);
338334
});
339335
_configuration = configuration;
340336
_syncManager = [[RLMSyncManager alloc] initWithSyncManager:_app->sync_manager()];
341337
}
342338
return self;
343339
}
344340

341+
static RLMUnfairMutex s_appMutex;
345342
static NSMutableDictionary *s_apps = [NSMutableDictionary new];
346-
static std::mutex& s_appMutex = *new std::mutex();
347343

348344
+ (NSArray *)allApps {
349345
std::lock_guard lock(s_appMutex);
@@ -385,6 +381,11 @@ + (instancetype)appWithId:(NSString *)appId {
385381
return s_apps[appId] = [[RLMApp alloc] initWithConfiguration:config];
386382
}
387383

384+
+ (RLMApp *_Nullable)cachedAppWithId:(NSString *)appId {
385+
std::lock_guard lock(s_appMutex);
386+
return s_apps[appId];
387+
}
388+
388389
- (NSString *)appId {
389390
return @(_app->config().app_id.c_str());
390391
}
@@ -395,42 +396,43 @@ - (NSString *)appId {
395396

396397
- (NSDictionary<NSString *, RLMUser *> *)allUsers {
397398
NSMutableDictionary *buffer = [NSMutableDictionary new];
398-
for (auto&& user : _app->sync_manager()->all_users()) {
399-
NSString *identity = @(user->identity().c_str());
400-
buffer[identity] = [[RLMUser alloc] initWithUser:std::move(user) app:self];
399+
for (auto&& user : _app->all_users()) {
400+
NSString *user_id = @(user->user_id().c_str());
401+
buffer[user_id] = [[RLMUser alloc] initWithUser:std::move(user)];
401402
}
402403
return buffer;
403404
}
404405

405406
- (RLMUser *)currentUser {
406-
if (auto user = _app->sync_manager()->get_current_user()) {
407-
return [[RLMUser alloc] initWithUser:user app:self];
407+
if (auto user = _app->current_user()) {
408+
return [[RLMUser alloc] initWithUser:user];
408409
}
409410
return nil;
410411
}
411412

412413
- (RLMEmailPasswordAuth *)emailPasswordAuth {
413-
return [[RLMEmailPasswordAuth alloc] initWithApp: self];
414+
return [[RLMEmailPasswordAuth alloc] initWithApp:_app];
414415
}
415416

416417
- (void)loginWithCredential:(RLMCredentials *)credentials
417418
completion:(RLMUserCompletionBlock)completionHandler {
418-
auto completion = ^(std::shared_ptr<SyncUser> user, std::optional<app::AppError> error) {
419+
auto completion = ^(std::shared_ptr<app::User> user, std::optional<app::AppError> error) {
419420
if (error) {
420421
return completionHandler(nil, makeError(*error));
421422
}
422423

423-
completionHandler([[RLMUser alloc] initWithUser:user app:self], nil);
424+
completionHandler([[RLMUser alloc] initWithUser:user], nil);
424425
};
425426
return RLMTranslateError([&] {
426427
return _app->log_in_with_credentials(credentials.appCredentials, completion);
427428
});
428429
}
429430

430431
- (RLMUser *)switchToUser:(RLMUser *)syncUser {
431-
return RLMTranslateError([&] {
432-
return [[RLMUser alloc] initWithUser:_app->switch_user(syncUser._syncUser) app:self];
432+
RLMTranslateError([&] {
433+
_app->switch_user(syncUser.user);
433434
});
435+
return syncUser;
434436
}
435437

436438
- (RLMPushClient *)pushClientWithServiceName:(NSString *)serviceName {

0 commit comments

Comments
 (0)