diff --git a/CHANGELOG.md b/CHANGELOG.md index 88573553..7297b559 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,13 @@ x.x.x Release notes (yyyy-MM-dd) ============================================================= ### Breaking changes -* `Realm.Sync.initialize()` must be called prior to any interaction with any Realm Object Server. +* None. ### Enhancements * None. ### Bug fixes -* None. +* Configuration of file system is delay to after module import (#1351). 2.0.0 Release notes (2017-9-26) diff --git a/docs/sync.js b/docs/sync.js index a547fff9..09ffc302 100644 --- a/docs/sync.js +++ b/docs/sync.js @@ -20,11 +20,6 @@ * @memberof Realm */ class Sync { - /** - * Initialize the interaction with Realm Object Server. It should only be called once. - */ - static initialize() {} - /** * Add a sync listener to listen to changes across multiple Realms * @param {string} server_url - the sync server to listen to diff --git a/lib/index.d.ts b/lib/index.d.ts index 6f7f4177..06637d21 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -396,7 +396,6 @@ declare namespace Realm.Sync { function removeListener(regex: string, name: string, changeCallback: (changeEvent: ChangeEvent) => void): void; function setLogLevel(logLevel: 'all' | 'trace' | 'debug' | 'detail' | 'info' | 'warn' | 'error' | 'fatal' | 'off'): void; function setFeatureToken(token: string): void; - function initialize(): void; /** * @deprecated, to be removed in 2.0 diff --git a/src/js_sync.hpp b/src/js_sync.hpp index b637b17e..a9875953 100644 --- a/src/js_sync.hpp +++ b/src/js_sync.hpp @@ -39,6 +39,19 @@ namespace realm { namespace js { +static bool config_fs_done = false; + +realm::SyncManager& syncManagerShared() { + realm::SyncManager& shared = SyncManager::shared(); + if (!config_fs_done) { + // setup synced realmFile paths + ensure_directory_exists_for_file(default_realm_file_directory()); + shared.configure_file_system(default_realm_file_directory(), SyncManager::MetadataMode::NoEncryption); + config_fs_done = true; + } + return shared; +} + using SharedUser = std::shared_ptr; using WeakSession = std::weak_ptr; @@ -127,7 +140,7 @@ void UserClass::create_user(ContextType ctx, FunctionType, ObjectType this_ob Value::validated_to_string(ctx, arguments[1], "identity"), Value::validated_to_string(ctx, arguments[0], "authServerUrl") }; - SharedUser *user = new SharedUser(SyncManager::shared().get_user( + SharedUser *user = new SharedUser(syncManagerShared().get_user( userIdentifier, Value::validated_to_string(ctx, arguments[2], "refreshToken") )); @@ -141,7 +154,7 @@ void UserClass::create_user(ContextType ctx, FunctionType, ObjectType this_ob template void UserClass::admin_user(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 2, 2); - SharedUser *user = new SharedUser(SyncManager::shared().get_admin_token_user( + SharedUser *user = new SharedUser(syncManagerShared().get_admin_token_user( Value::validated_to_string(ctx, arguments[0], "authServerUrl"), Value::validated_to_string(ctx, arguments[1], "refreshToken") )); @@ -151,7 +164,7 @@ void UserClass::admin_user(ContextType ctx, FunctionType, ObjectType this_obj template void UserClass::all_users(ContextType ctx, ObjectType object, ReturnValue &return_value) { auto users = Object::create_empty(ctx); - for (auto user : SyncManager::shared().all_logged_in_users()) { + for (auto user : syncManagerShared().all_logged_in_users()) { if (user->token_type() == SyncUser::TokenType::Normal) { Object::set_property(ctx, users, user->identity(), create_object>(ctx, new SharedUser(user)), ReadOnly | DontDelete); } @@ -516,7 +529,6 @@ public: static FunctionType create_constructor(ContextType); static void set_sync_log_level(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &); - static void initialize(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &); // private static std::function session_bind_callback(ContextType ctx, ObjectType sync_constructor); @@ -527,7 +539,6 @@ public: MethodMap const static_methods = { {"setLogLevel", wrap}, - {"initialize", wrap}, }; }; @@ -553,7 +564,7 @@ void SyncClass::set_sync_log_level(ContextType ctx, FunctionType, ObjectType in >> log_level_2; // Throws if (!in || !in.eof()) throw std::runtime_error("Bad log level"); - realm::SyncManager::shared().set_log_level(log_level_2); + syncManagerShared().set_log_level(log_level_2); } template @@ -637,7 +648,7 @@ void SyncClass::populate_sync_config(ContextType ctx, ObjectType realm_constr config.schema_mode = SchemaMode::Additive; - config.path = realm::SyncManager::shared().path_for_realm(*shared_user, raw_realm_url); + config.path = syncManagerShared().path_for_realm(*shared_user, raw_realm_url); if (!config.encryption_key.empty()) { config.sync_config->realm_encryption_key = std::array(); @@ -645,13 +656,5 @@ void SyncClass::populate_sync_config(ContextType ctx, ObjectType realm_constr } } } - -template -void SyncClass::initialize(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { - // setup synced realmFile paths - ensure_directory_exists_for_file(default_realm_file_directory()); - SyncManager::shared().configure_file_system(default_realm_file_directory(), SyncManager::MetadataMode::NoEncryption); - return_value.set_undefined(); -} } // js } // realm diff --git a/tests/js/download-api-helper.js b/tests/js/download-api-helper.js index ae892753..fd899431 100644 --- a/tests/js/download-api-helper.js +++ b/tests/js/download-api-helper.js @@ -30,7 +30,6 @@ function createObjects(user) { setTimeout(() => process.exit(0), 3000); } -Realm.Sync.initialize(); Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, registeredUser) => { if (error) { const registrationError = JSON.stringify(error);