mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 14:54:33 +00:00
Merge pull request #717 from realm/al/notifier
Use latest core, sync, and object store
This commit is contained in:
commit
9ddc2065bb
@ -1,5 +1,5 @@
|
|||||||
PACKAGE_NAME=realm-js
|
PACKAGE_NAME=realm-js
|
||||||
VERSION=0.15.1-rc
|
VERSION=0.15.1-rc
|
||||||
REALM_CORE_VERSION=2.1.4
|
REALM_CORE_VERSION=2.2.0
|
||||||
REALM_SYNC_VERSION=1.0.0-BETA-3.3
|
REALM_SYNC_VERSION=1.0.0-BETA-5.0
|
||||||
REALM_OBJECT_SERVER_VERSION=1.0.0-BETA-2.1
|
REALM_OBJECT_SERVER_VERSION=1.0.0-BETA-4.8
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
},
|
},
|
||||||
"source": {
|
"source": {
|
||||||
"include": ["docs"],
|
"include": ["docs"],
|
||||||
"exclude": ["docs/jsdoc-template", "docs/output", "docs/sync.js"]
|
"exclude": ["docs/jsdoc-template", "docs/output"]
|
||||||
},
|
},
|
||||||
"tags": {
|
"tags": {
|
||||||
"allowUnknownTags": false
|
"allowUnknownTags": false
|
||||||
|
72
docs/sync.js
72
docs/sync.js
@ -20,21 +20,28 @@
|
|||||||
* @memberof Realm
|
* @memberof Realm
|
||||||
*/
|
*/
|
||||||
class Sync {
|
class Sync {
|
||||||
|
/**
|
||||||
|
* Add a sync listener to listen to changes across multiple Realms
|
||||||
|
* @param {string} server_url - the sync server to listen to
|
||||||
|
* @param {SyncUser} admin_user - an admin user obtained by calling `new Realm.Sync.User.adminUser`
|
||||||
|
* @param {string} regex - a regular expression used to determine which cahnged Realms should trigger events -
|
||||||
|
* Use `.*` to match all all Realms
|
||||||
|
* @param {function(change_object)} change_callback - called on when changes are made to any Realm which
|
||||||
|
* match the given regular expression
|
||||||
|
*/
|
||||||
|
static addListener(server_url, admin_user, regex, change_callback) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a global listener function.
|
* Remove a previously registered sync listener
|
||||||
* @param {string} local_path - The path to the directory where realm files are stored [deprecated]
|
* @param {string} regex - the regular expression previously used to register the listener
|
||||||
* @param {string} server_url - The sync server to listen to
|
* @param {function(change_object)} change_callback - the previously registered callback to be removed
|
||||||
* @param {SyncUser} admin_user - An admin user obtained by calling `new Realm.Sync.User.Admin`
|
|
||||||
* @param {function(realm_name)} filter_callback - Return true to recieve changes for the given realm
|
|
||||||
* @param {function(realm_name, realm, change_set)} change_callback - called on any realm changes with
|
|
||||||
* the following arguments:
|
|
||||||
* - `realm_name` - path of the Realm on which changes occurred
|
|
||||||
* - `realm` - a `Realm` object for the changed Realm
|
|
||||||
* - `change_set` - a dictionary of object names to arays of indexes indicating the indexes of objects of each type
|
|
||||||
* which have been added, removed, or modified
|
|
||||||
*/
|
*/
|
||||||
static setGlobalListener(local_path, server_url, admin_user, filter_callback, change_callback) {}
|
static removeListener(regex, change_callback) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all previously regiestered listeners
|
||||||
|
*/
|
||||||
|
static removeAllListeners() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the sync log level.
|
* Set the sync log level.
|
||||||
@ -44,6 +51,47 @@ class Sync {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object passed
|
||||||
|
* @memberof Realm.Sync
|
||||||
|
*/
|
||||||
|
class ChangeObject {
|
||||||
|
/**
|
||||||
|
* The path of the changed Realm
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
get path() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The changed realm
|
||||||
|
* @type {Realm}
|
||||||
|
*/
|
||||||
|
get realm() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The changed Realm at the old state before the changes were applied
|
||||||
|
* @type {Realm}
|
||||||
|
*/
|
||||||
|
get oldRealm() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The change indexes for all added, removed, and modified objects in the changed Realm.
|
||||||
|
* This object is a hashmap of object types to arrays of indexes for all changed objects:
|
||||||
|
* @example
|
||||||
|
* {
|
||||||
|
* object_type_1: {
|
||||||
|
* insertions: [indexes...],
|
||||||
|
* deletions: [indexes...],
|
||||||
|
* modifications: [indexes...]
|
||||||
|
* },
|
||||||
|
* object_type_2:
|
||||||
|
* ...
|
||||||
|
* }
|
||||||
|
* @type {object}
|
||||||
|
*/
|
||||||
|
get changes() {}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef Realm.Sync~LogLevel
|
* @typedef Realm.Sync~LogLevel
|
||||||
* @type {("error"|"info"|"debug")}
|
* @type {("error"|"info"|"debug")}
|
||||||
|
@ -27,7 +27,7 @@ if [ "$1" = 'node' ]; then
|
|||||||
PLATFORM_TAG="node-osx-"
|
PLATFORM_TAG="node-osx-"
|
||||||
SYNC_PLATFORM_TAG="node-cocoa-"
|
SYNC_PLATFORM_TAG="node-cocoa-"
|
||||||
CORE_DOWNLOAD_FILE="realm-core-node-osx-$REALM_CORE_VERSION.tar.gz"
|
CORE_DOWNLOAD_FILE="realm-core-node-osx-$REALM_CORE_VERSION.tar.gz"
|
||||||
SYNC_DOWNLOAD_FILE="realm-sync-$SYNC_PLATFORM_TAG$REALM_SYNC_VERSION.zip"
|
SYNC_DOWNLOAD_FILE="realm-sync-$SYNC_PLATFORM_TAG$REALM_SYNC_VERSION.tar.gz"
|
||||||
else
|
else
|
||||||
PLATFORM_TAG="node-linux-"
|
PLATFORM_TAG="node-linux-"
|
||||||
SYNC_PLATFORM_TAG="node-cocoa-"
|
SYNC_PLATFORM_TAG="node-cocoa-"
|
||||||
@ -35,7 +35,7 @@ if [ "$1" = 'node' ]; then
|
|||||||
SYNC_DOWNLOAD_FILE=""
|
SYNC_DOWNLOAD_FILE=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SYNC_EXTRACT="unzip"
|
SYNC_EXTRACT="tar -xvf"
|
||||||
EXTRACTED_DIR="realm-sync-node-cocoa-$REALM_SYNC_VERSION"
|
EXTRACTED_DIR="realm-sync-node-cocoa-$REALM_SYNC_VERSION"
|
||||||
else
|
else
|
||||||
ENABLE_SYNC="yes" # FIXME: This means that both core and sync will be downloaded for non "node" targets.
|
ENABLE_SYNC="yes" # FIXME: This means that both core and sync will be downloaded for non "node" targets.
|
||||||
|
@ -14,7 +14,7 @@ if [ -f object-server-for-testing/node_modules/realm-object-server/CHANGELOG.md
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
object_server_bundle="realm-object-server-bundled_node_darwin-$REALM_OBJECT_SERVER_VERSION.tar.gz"
|
object_server_bundle="realm-object-server-bundled_node_darwin-developer-$REALM_OBJECT_SERVER_VERSION.tar.gz"
|
||||||
curl -f -L "https://static.realm.io/downloads/object-server/$object_server_bundle" -o "$object_server_bundle"
|
curl -f -L "https://static.realm.io/downloads/object-server/$object_server_bundle" -o "$object_server_bundle"
|
||||||
rm -rf object-server-for-testing
|
rm -rf object-server-for-testing
|
||||||
mkdir object-server-for-testing
|
mkdir object-server-for-testing
|
||||||
|
@ -62,9 +62,7 @@ class RealmDelegate : public BindingContext {
|
|||||||
using ObjectDefaultsMap = typename Schema<T>::ObjectDefaultsMap;
|
using ObjectDefaultsMap = typename Schema<T>::ObjectDefaultsMap;
|
||||||
using ConstructorMap = typename Schema<T>::ConstructorMap;
|
using ConstructorMap = typename Schema<T>::ConstructorMap;
|
||||||
|
|
||||||
virtual void did_change(std::vector<ObserverState> const& observers,
|
virtual void did_change(std::vector<ObserverState> const& observers, std::vector<void*> const& invalidated, bool version_changed) {
|
||||||
std::vector<void*> const& invalidated,
|
|
||||||
bool version_changed=true) {
|
|
||||||
notify("change");
|
notify("change");
|
||||||
}
|
}
|
||||||
virtual std::vector<ObserverState> get_observed_rows() {
|
virtual std::vector<ObserverState> get_observed_rows() {
|
||||||
@ -457,14 +455,15 @@ void RealmClass<T>::schema_version(ContextType ctx, ObjectType this_object, size
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void RealmClass<T>::clear_test_state(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
void RealmClass<T>::clear_test_state(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||||
validate_argument_count(argc, 0);
|
validate_argument_count(argc, 0);
|
||||||
|
|
||||||
|
delete_all_realms();
|
||||||
#if REALM_ENABLE_SYNC
|
#if REALM_ENABLE_SYNC
|
||||||
for(auto &user : SyncManager::shared().all_users()) {
|
for(auto &user : SyncManager::shared().all_logged_in_users()) {
|
||||||
user->log_out();
|
user->log_out();
|
||||||
}
|
}
|
||||||
SyncManager::shared().reset_for_testing();
|
SyncManager::shared().reset_for_testing();
|
||||||
SyncManager::shared().configure_file_system(default_realm_file_directory(), SyncManager::MetadataMode::NoEncryption);
|
SyncManager::shared().configure_file_system(default_realm_file_directory(), SyncManager::MetadataMode::NoEncryption);
|
||||||
#endif
|
#endif
|
||||||
delete_all_realms();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -127,8 +127,8 @@ void UserClass<T>::create_user(ContextType ctx, ObjectType this_object, size_t a
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void UserClass<T>::all_users(ContextType ctx, ObjectType object, ReturnValue &return_value) {
|
void UserClass<T>::all_users(ContextType ctx, ObjectType object, ReturnValue &return_value) {
|
||||||
auto users = Object::create_empty(ctx);
|
auto users = Object::create_empty(ctx);
|
||||||
for (auto user : SyncManager::shared().all_users()) {
|
for (auto user : SyncManager::shared().all_logged_in_users()) {
|
||||||
if (user->state() == SyncUser::State::Active) {
|
if (!user->is_admin()) {
|
||||||
Object::set_property(ctx, users, user->identity(), create_object<T, UserClass<T>>(ctx, new SharedUser(user)), ReadOnly | DontDelete);
|
Object::set_property(ctx, users, user->identity(), create_object<T, UserClass<T>>(ctx, new SharedUser(user)), ReadOnly | DontDelete);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,8 +138,8 @@ void UserClass<T>::all_users(ContextType ctx, ObjectType object, ReturnValue &re
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void UserClass<T>::current_user(ContextType ctx, ObjectType object, ReturnValue &return_value) {
|
void UserClass<T>::current_user(ContextType ctx, ObjectType object, ReturnValue &return_value) {
|
||||||
SharedUser *current = nullptr;
|
SharedUser *current = nullptr;
|
||||||
for (auto user : SyncManager::shared().all_users()) {
|
for (auto user : SyncManager::shared().all_logged_in_users()) {
|
||||||
if (user->state() == SyncUser::State::Active) {
|
if (!user->is_admin()) {
|
||||||
if (current != nullptr) {
|
if (current != nullptr) {
|
||||||
throw std::runtime_error("More than one user logged in currently.");
|
throw std::runtime_error("More than one user logged in currently.");
|
||||||
}
|
}
|
||||||
@ -302,7 +302,7 @@ void SyncClass<T>::populate_sync_config(ContextType ctx, ObjectType realm_constr
|
|||||||
std::string raw_realm_url = Object::validated_get_string(ctx, sync_config_object, "url");
|
std::string raw_realm_url = Object::validated_get_string(ctx, sync_config_object, "url");
|
||||||
|
|
||||||
// FIXME - use make_shared
|
// FIXME - use make_shared
|
||||||
config.sync_config = std::shared_ptr<SyncConfig>(new SyncConfig{shared_user, raw_realm_url, SyncSessionStopPolicy::AfterChangesUploaded, handler, [=](int error_code, std::string message, SyncSessionError) {}}
|
config.sync_config = std::shared_ptr<SyncConfig>(new SyncConfig{shared_user, raw_realm_url, SyncSessionStopPolicy::AfterChangesUploaded, handler, [=](auto, int error_code, std::string message, SyncSessionError) {}}
|
||||||
);
|
);
|
||||||
config.schema_mode = SchemaMode::Additive;
|
config.schema_mode = SchemaMode::Additive;
|
||||||
config.path = realm::SyncManager::shared().path_for_realm(shared_user->identity(), raw_realm_url);
|
config.path = realm::SyncManager::shared().path_for_realm(shared_user->identity(), raw_realm_url);
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit ddf845eb23884f6644d15c896952ee0f5ea5ad57
|
Subproject commit 1d635d3e05ac7d86939b03b46833e08c1ffc769e
|
@ -127,7 +127,7 @@ module.exports = {
|
|||||||
assertIsUser(user);
|
assertIsUser(user);
|
||||||
|
|
||||||
Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, user) => {
|
Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, user) => {
|
||||||
assertIsAuthError(error, 613, 'https://realm.io/docs/object-server/problems/existing-account');
|
assertIsAuthError(error, 611, 'https://realm.io/docs/object-server/problems/invalid-credentials');
|
||||||
TestCase.assertUndefined(user);
|
TestCase.assertUndefined(user);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -193,7 +193,7 @@ module.exports = {
|
|||||||
|
|
||||||
testLoginNonExistingUser() {
|
testLoginNonExistingUser() {
|
||||||
return callbackTest((callback) => Realm.Sync.User.login('http://localhost:9080', 'does_not', 'exist', callback), (error, user) => {
|
return callbackTest((callback) => Realm.Sync.User.login('http://localhost:9080', 'does_not', 'exist', callback), (error, user) => {
|
||||||
assertIsAuthError(error, 612, 'https://realm.io/docs/object-server/problems/unknown-account');
|
assertIsAuthError(error, 611, 'https://realm.io/docs/object-server/problems/invalid-credentials');
|
||||||
TestCase.assertUndefined(user);
|
TestCase.assertUndefined(user);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user