From 6d9f85759e670db934c8712a17e9b3ab5e3bf7a4 Mon Sep 17 00:00:00 2001 From: blagoev Date: Fri, 29 Sep 2017 21:43:04 +0300 Subject: [PATCH] Fix IncompatibleSyncedRealm support --- dependencies.list | 2 +- lib/errors.js | 16 ----- lib/extensions.js | 8 +-- src/js_realm.hpp | 50 ++++++++-------- tests/data/sync-1.x.realm | Bin 81920 -> 0 bytes tests/js/session-tests.js | 120 ++++++++++++++++++++++++++++++++++---- 6 files changed, 134 insertions(+), 62 deletions(-) delete mode 100644 tests/data/sync-1.x.realm diff --git a/dependencies.list b/dependencies.list index 2d143cdb..5c6a21d7 100644 --- a/dependencies.list +++ b/dependencies.list @@ -2,4 +2,4 @@ PACKAGE_NAME=realm-js VERSION=2.0.0-rc13 REALM_CORE_VERSION=3.2.1 REALM_SYNC_VERSION=2.0.0-rc24 -REALM_OBJECT_SERVER_VERSION=2.0.0-alpha.36 +REALM_OBJECT_SERVER_VERSION=2.0.0-alpha.40 diff --git a/lib/errors.js b/lib/errors.js index 54fd3b7d..197d5ba4 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -32,19 +32,3 @@ AuthError.__proto__ = Error; AuthError.prototype.__proto__ = Error.prototype; exports['AuthError'] = AuthError; - - -function IncompatibleSyncedRealmError(configuration) { - const error = Error.call(this); - - this.name = 'IncompatibleSyncedRealmError'; - this.message = error.message; - this.stack = error.stack; - - Object.assign(this, configuration); -} - -IncompatibleSyncedRealmError.__proto__ = Error; -IncompatibleSyncedRealmError.prototype.__proto__ = Error.prototype; - -exports['IncompatibleSyncedRealmError'] = IncompatibleSyncedRealmError; diff --git a/lib/extensions.js b/lib/extensions.js index 295c06b8..1c4b8b1d 100644 --- a/lib/extensions.js +++ b/lib/extensions.js @@ -19,7 +19,7 @@ 'use strict'; const IncompatibleSyncedRealmError = require('./errors').IncompatibleSyncedRealmError; - + let getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function(obj) { return Object.getOwnPropertyNames(obj).reduce(function (descriptors, name) { descriptors[name] = Object.getOwnPropertyDescriptor(obj, name); @@ -61,9 +61,6 @@ module.exports = function(realmConstructor) { //FIXME: RN hangs here. Remove when node's makeCallback alternative is implemented setTimeout(() => { resolve(syncedRealm); }, 1); } catch (e) { - if (e.message === 'IncompatibleSyncedRealm') { - reject(new IncompatibleSyncedRealmError(e.configuration)); - } reject(e); } } @@ -101,9 +98,6 @@ module.exports = function(realmConstructor) { //FIXME: RN hangs here. Remove when node's makeCallback alternative is implemented setTimeout(() => { callback(null, syncedRealm); }, 1); } catch (e) { - if (e.message === 'IncompatibleSyncedRealm') { - throw new IncompatibleSyncedRealmError(e.configuration); - } setTimeout(() => { callback(e); }, 1); } } diff --git a/src/js_realm.hpp b/src/js_realm.hpp index b1f387b0..f8454d0b 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -252,32 +252,24 @@ public: }; private: - static void translateSharedGroupOpenException(ContextType ctx, realm::Realm::Config config) { - try { - throw; - } - catch (RealmFileException const& ex) { - switch (ex.kind()) { - case RealmFileException::Kind::IncompatibleSyncedRealm: { - // create an object which is going to be used as exception: - // { message: 'IncompatibleSyncedRealmException', configuration: { path: ... } } - - ObjectType configuration = Object::create_empty(ctx); - Object::set_property(ctx, configuration, "path", Value::from_string(ctx, ex.path())); - Object::set_property(ctx, configuration, "schema_mode", Value::from_string(ctx, "readOnly")); - if (!config.encryption_key.empty()) { - Object::set_property(ctx, configuration, "encryption_key", Value::from_binary(ctx, BinaryData(&config.encryption_key[0], 64))); - } - - ObjectType object = Object::create_empty(ctx); - Object::set_property(ctx, object, "message", Value::from_string(ctx, "IncompatibleSyncedRealm")); - Object::set_property(ctx, object, "configuration", configuration); - throw Exception(ctx, object); + static void handleRealmFileException(ContextType ctx, realm::Realm::Config config, const RealmFileException& ex) { + switch (ex.kind()) { + case RealmFileException::Kind::IncompatibleSyncedRealm: { + ObjectType configuration = Object::create_empty(ctx); + Object::set_property(ctx, configuration, "path", Value::from_string(ctx, ex.path())); + Object::set_property(ctx, configuration, "readOnly", Value::from_boolean(ctx, true)); + if (!config.encryption_key.empty()) { + Object::set_property(ctx, configuration, "encryption_key", Value::from_binary(ctx, BinaryData(&config.encryption_key[0], 64))); } - default: - throw; + + ObjectType object = Object::create_empty(ctx); + Object::set_property(ctx, object, "name", Value::from_string(ctx, "IncompatibleSyncedRealmError")); + Object::set_property(ctx, object, "configuration", configuration); + throw Exception(ctx, object); } - } + default: + throw; + } } static std::string validated_notification_name(ContextType ctx, const ValueType &value) { @@ -514,8 +506,11 @@ SharedRealm RealmClass::create_shared_realm(ContextType ctx, realm::Realm::Co try { realm = realm::Realm::get_shared_realm(config); } + catch (const RealmFileException& ex) { + handleRealmFileException(ctx, config, ex); + } catch (...) { - translateSharedGroupOpenException(ctx, config); + throw; } GlobalContextType global_context = Context::get_global_context(ctx); @@ -729,8 +724,11 @@ void RealmClass::wait_for_download_completion(ContextType ctx, ObjectType thi try { realm = realm::Realm::get_shared_realm(config); } + catch (const RealmFileException& ex) { + handleRealmFileException(ctx, config, ex); + } catch (...) { - translateSharedGroupOpenException(ctx, config); + throw; } if (auto sync_config = config.sync_config) diff --git a/tests/data/sync-1.x.realm b/tests/data/sync-1.x.realm deleted file mode 100644 index 8d4afd3c162cbc71e380bdcf40ad79650788581d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 81920 zcmeHwOH3nKy5>0%4r6Qs25e*Arg%BYBr(sVx~saKNoFmjC7&|!GHeucmDH;IL>l9KnY&!N9;!4Og??m)I`W*xD-MZuhGot7N83szA2~P zW_8}&1azU8FX+W`1)E%`2No5>s$u6TA!;O+WGcwl2(N({JhD(0@-)=zpjGOufpm@&yEg7wWeY<%^|sCc8zJ@;kY*UR-_q z2Ys_lR&wQJF|(a2R-WsXuQTQJ?^D?woikrno~FtvPQ2R5W-$v(oHJH)FH^bHdwuJT zUMeqTQ>79~riyy5Of1nSm9j8uH7=!7A`Gh$0-9dnmTOvPXX>>s%w200f!6gYn00*% zX8jm!+&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zZcQ)kWXsSYBbIRp(rc?#uc*~gdnUHYMpKO!Fd7+SMy&Y&ggh@&#@rB8nzh%PFrfui zFEo}j<((}(=<+thn}GKQ0h871R2Dw29(GgzO6l?T+st>VEPRAA*kmnwVUH`Egq0|> zxdb0f&%DcQ0&qC@m%`0T+iC&9OJyH#Z9!$0V0qD=ZKpEXpwCgTA%DwQSb(RIah6-n z!ifVfW;ENE9BjVFnroL;Y@aaOt$7C9@0;z`G=uFASmj*vI%zaJy*^~k*S$`e?X_Ox zW_zvIX%@{*^*V!E&P5r6oxMd3invE<#&v;D9CNn{`}-6xz6~)xPN$Li+ogNd+5xw4 zt9Z+_YLDd6t-}6kSFPhT>D*0tJnmHXQ$sX gMw4X>UX930A|Mfv2uK7Z0ulj { return new Promise((resolve, _reject) => { - const config = { path: 'sync-1.x.realm', sync: { user, url: 'realm:://localhost:9080/~/sync-1.x' } }; - try { - const realm = new Realm(config); - } - catch (e) { - if (e instanceof IncompatibleSyncedRealmError) { - const backupRealm = new Realm(e.configuration); - TestCase.assertNotEqual(backupRealm.objects('Person').length, 0); - resolve(); + const config = { + path: realm, + sync: { + user, + error : err => cosole.log(err), + url: 'realm://localhost:9080/~/sync-v1' + } + }; + + Realm.open(config) + .then(realm => + _reject("Should fail with IncompatibleSyncedRealmError")) + .catch(e => { + if (e.name == "IncompatibleSyncedRealmError") { + const backupRealm = new Realm(e.configuration); + TestCase.assertEqual(backupRealm.objects('Dog').length, 3); + resolve(); + return; + } + + _reject("Failed with unexpected error" + JSON.stringify(e)); + }); + }); + }); + }, + + testIncompatibleSyncedRealmOpenAsync() { + let realm = "sync-v1.realm"; + if (isNodeProccess) { + realm = copyFileToTempDir(path.join(process.cwd(), "data", realm)); + } + + return Realm.Sync.User.register('http://localhost:9080', uuid(), 'password').then(user => { + return new Promise((resolve, _reject) => { + const config = { + path: realm, + sync: { + user, + error : err => cosole.log(err), + url: 'realm://localhost:9080/~/sync-v1' + } + }; + + Realm.openAsync(config, (error, realm) => { + if (!error) { + _reject("Should fail with IncompatibleSyncedRealmError"); + return; + } + + if (error.name == "IncompatibleSyncedRealmError") { + const backupRealm = new Realm(error.configuration); + TestCase.assertEqual(backupRealm.objects('Dog').length, 3); + resolve(); + return; + } + + _reject("Failed with unexpected error" + JSON.stringify(error)); + }); + }); + }); + }, + + testIncompatibleSyncedRealmConsructor() { + let realm = "sync-v1.realm"; + if (isNodeProccess) { + realm = copyFileToTempDir(path.join(process.cwd(), "data", realm)); + } + + return Realm.Sync.User.register('http://localhost:9080', uuid(), 'password').then(user => { + return new Promise((resolve, _reject) => { + const config = { + path: realm, + sync: { + user, + error : err => cosole.log(err), + url: 'realm://localhost:9080/~/sync-v1' + } + }; + + try { + const realm = new Realm(config); + _reject("Should fail with IncompatibleSyncedRealmError"); + } + catch (e) { + if (e.name == "IncompatibleSyncedRealmError") { + const backupRealm = new Realm(e.configuration); + TestCase.assertEqual(backupRealm.objects('Dog').length, 3); + resolve(); + return; + } + + _reject("Failed with unexpected error" + JSON.stringify(e)); } - } - _reject(); }); }); },