From ba48933561a85a34a3a34bc2e8aee3b3279eee78 Mon Sep 17 00:00:00 2001 From: Radu Tutueanu Date: Wed, 9 Nov 2016 16:47:17 +0100 Subject: [PATCH] Enable building without sync This is needed because the linux node binding needs to work without sync --- binding.gyp | 21 +++++++++++++-------- src/js_realm.hpp | 37 ++++++++++++++++++++----------------- src/node/gyp/realm.gyp | 4 ++-- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/binding.gyp b/binding.gyp index a0ce0f6f..bb22d6ae 100644 --- a/binding.gyp +++ b/binding.gyp @@ -32,7 +32,7 @@ }, { "target_name": "object-store", - "dependencies": [ "realm-core", "realm-sync" ], + "dependencies": [ "realm-core" ], "type": "static_library", "include_dirs": [ "src/object-store/src", @@ -63,12 +63,6 @@ "src/object-store/src/parser/query_builder.cpp", "src/object-store/src/util/format.cpp", "src/object-store/src/util/thread_id.cpp", - "src/object-store/src/sync/sync_manager.cpp", - "src/object-store/src/sync/sync_user.cpp", - "src/object-store/src/sync/sync_session.cpp", - "src/object-store/src/sync/impl/sync_file.cpp", - "src/object-store/src/sync/impl/sync_metadata.cpp", - "src/object-store/src/impl/apple/keychain_helper.cpp" ], "conditions": [ ["OS=='linux'", { @@ -80,10 +74,21 @@ "sources": [ "src/object-store/src/impl/apple/external_commit_helper.cpp" ] + }], + ["realm_enable_sync", { + "dependencies": [ "realm-sync" ], + "sources": [ + "src/object-store/src/sync/sync_manager.cpp", + "src/object-store/src/sync/sync_user.cpp", + "src/object-store/src/sync/sync_session.cpp", + "src/object-store/src/sync/impl/sync_file.cpp", + "src/object-store/src/sync/impl/sync_metadata.cpp", + "src/object-store/src/impl/apple/keychain_helper.cpp" + ], }] ], "all_dependent_settings": { - "include_dirs": [ + "include_dirs": [ "src/object-store/src", "src/object-store/src/impl", "src/object-store/src/impl/apple", diff --git a/src/js_realm.hpp b/src/js_realm.hpp index 7831419d..9634a431 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -178,17 +178,17 @@ public: static void set_default_path(ContextType, ObjectType, ValueType value); std::string const name = "Realm"; - + MethodMap const static_methods = { {"schemaVersion", wrap}, {"clearTestState", wrap}, {"copyBundledRealmFiles", wrap}, }; - + PropertyMap const static_properties = { {"defaultPath", {wrap, wrap}}, }; - + MethodMap const methods = { {"objects", wrap}, {"objectForPrimaryKey", wrap}, @@ -201,14 +201,14 @@ public: {"removeAllListeners", wrap}, {"close", wrap}, }; - + PropertyMap const properties = { {"path", {wrap, nullptr}}, {"schemaVersion", {wrap, nullptr}}, {"schema", {wrap, nullptr}}, {"readOnly", {wrap, nullptr}}, }; - + private: static std::string validated_notification_name(ContextType ctx, const ValueType &value) { std::string name = Value::validated_to_string(ctx, value, "notification name"); @@ -217,13 +217,13 @@ public: } return name; } - + static const ObjectSchema& validated_object_schema_for_value(ContextType ctx, const SharedRealm &realm, const ValueType &value) { std::string object_type; if (Value::is_constructor(ctx, value)) { FunctionType constructor = Value::to_constructor(ctx, value); - + auto delegate = get_delegate(realm.get()); for (auto &pair : delegate->m_constructors) { if (FunctionType(pair.second) == constructor) { @@ -248,7 +248,7 @@ public: } return *object_schema; } - + static std::string normalize_path(std::string path) { if (path.size() && path[0] != '/' && path[0] != '.') { return default_realm_file_directory() + "/" + path; @@ -282,7 +282,7 @@ inline typename T::Function RealmClass::create_constructor(ContextType ctx) { s_constructor = Protected(ctx, realm_constructor); return realm_constructor; } - + static inline void convert_outdated_datetime_columns(const SharedRealm &realm) { realm::util::Optional old_file_format_version = realm->file_format_upgraded_from_version(); if (old_file_format_version && old_file_format_version < 5) { @@ -294,7 +294,7 @@ static inline void convert_outdated_datetime_columns(const SharedRealm &realm) { if (!realm->is_in_transaction()) { realm->begin_transaction(); } - + for (size_t row_index = 0; row_index < table->size(); row_index++) { if (table->is_null(property.table_column, row_index)) { continue; @@ -337,7 +337,7 @@ void RealmClass::constructor(ContextType ctx, ObjectType this_object, size_t else { config.path = js::default_path(); } - + static const String read_only_string = "readOnly"; ValueType read_only_value = Object::get_property(ctx, object, read_only_string); if (!Value::is_undefined(ctx, read_only_value) && Value::validated_to_boolean(ctx, read_only_value, "readOnly")) { @@ -372,7 +372,7 @@ void RealmClass::constructor(ContextType ctx, ObjectType this_object, size_t create_object>(ctx, old_realm_ptr), create_object>(ctx, realm_ptr) }; - + try { Function::call(ctx, migration_function, 2, arguments); } @@ -382,7 +382,7 @@ void RealmClass::constructor(ContextType ctx, ObjectType this_object, size_t realm_ptr->reset(); throw; } - + old_realm->close(); old_realm_ptr->reset(); realm_ptr->reset(); @@ -403,7 +403,7 @@ void RealmClass::constructor(ContextType ctx, ObjectType this_object, size_t else { throw std::runtime_error("Invalid arguments when constructing 'Realm'"); } - + config.path = normalize_path(config.path); ensure_directory_exists_for_file(config.path); @@ -425,7 +425,7 @@ void RealmClass::constructor(ContextType ctx, ObjectType this_object, size_t js_binding_context->m_defaults = std::move(defaults); js_binding_context->m_constructors = std::move(constructors); } - + // Fix for datetime -> timestamp conversion convert_outdated_datetime_columns(realm); @@ -435,7 +435,7 @@ void RealmClass::constructor(ContextType ctx, ObjectType this_object, size_t template void RealmClass::schema_version(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 1, 2); - + realm::Realm::Config config; config.path = normalize_path(Value::validated_to_string(ctx, arguments[0])); if (argc == 2) { @@ -443,7 +443,7 @@ void RealmClass::schema_version(ContextType ctx, ObjectType this_object, size std::string encryptionKey = NativeAccessor::to_binary(ctx, encryptionKeyValue); config.encryption_key = std::vector(encryptionKey.begin(), encryptionKey.end()); } - + auto version = realm::Realm::get_schema_version(config); if (version == ObjectStore::NotVersioned) { return_value.set(-1); @@ -453,12 +453,15 @@ void RealmClass::schema_version(ContextType ctx, ObjectType this_object, size } } + template void RealmClass::clear_test_state(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 0); +#if REALM_ENABLE_SYNC for(auto &user : SyncManager::shared().all_users()) { user->log_out(); } +#endif delete_all_realms(); } diff --git a/src/node/gyp/realm.gyp b/src/node/gyp/realm.gyp index baeea330..ad41ad71 100644 --- a/src/node/gyp/realm.gyp +++ b/src/node/gyp/realm.gyp @@ -18,7 +18,7 @@ ] }, "all_dependent_settings": { - "defines": [ "REALM_HAVE_CONFIG", "REALM_PLATFORM_NODE=1", "REALM_ENABLE_SYNC=1" ] + "defines": [ "REALM_HAVE_CONFIG", "REALM_PLATFORM_NODE=1", "REALM_ENABLE_SYNC=<(realm_enable_sync)" ] }, "variables": { "prefix": "