hook up new object store apis

This commit is contained in:
Ari Lazier 2016-10-19 17:55:46 -07:00
parent c49727913c
commit 92adb669d5
14 changed files with 5078 additions and 242 deletions

View File

@ -32,7 +32,7 @@
}, },
{ {
"target_name": "object-store", "target_name": "object-store",
"dependencies": [ "realm-core" ], "dependencies": [ "realm-core", "realm-sync" ],
"type": "static_library", "type": "static_library",
"include_dirs": [ "include_dirs": [
"src/object-store/src", "src/object-store/src",
@ -62,7 +62,13 @@
"src/object-store/src/parser/parser.cpp", "src/object-store/src/parser/parser.cpp",
"src/object-store/src/parser/query_builder.cpp", "src/object-store/src/parser/query_builder.cpp",
"src/object-store/src/util/format.cpp", "src/object-store/src/util/format.cpp",
"src/object-store/src/util/thread_id.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": [ "conditions": [
["OS=='linux'", { ["OS=='linux'", {
@ -74,13 +80,6 @@
"sources": [ "sources": [
"src/object-store/src/impl/apple/external_commit_helper.cpp" "src/object-store/src/impl/apple/external_commit_helper.cpp"
] ]
}],
["realm_enable_sync", {
"dependencies": [ "realm-sync" ],
"sources": [
"src/object-store/src/sync_manager.cpp",
"src/object-store/src/sync_session.cpp"
]
}] }]
], ],
"all_dependent_settings": { "all_dependent_settings": {

View File

@ -24,7 +24,7 @@ module.exports = function(realmConstructor) {
// Add sync methods // Add sync methods
if (realmConstructor.Sync) { if (realmConstructor.Sync) {
realmConstructor.Sync.User = require('./sync').User; Object.defineProperties(realmConstructor.Sync.User, require('./user-methods')(realmConstructor));
realmConstructor.Sync.AuthError = require('./errors').AuthError; realmConstructor.Sync.AuthError = require('./errors').AuthError;
if (realmConstructor.Sync.cleanup) { if (realmConstructor.Sync.cleanup) {

View File

@ -1,141 +0,0 @@
'use strict';
const AuthError = require('./errors').AuthError;
function node_require(module) {
return require(module);
}
var post;
if (typeof fetch != 'undefined') {
post = function(options, callback) {
options.method = 'POST';
fetch(options.url, options)
.then((response) => {
if (response.status != 200) {
callback(undefined, {statusCode: response.status});
}
else {
return response.text();
}
})
.then((body) => {
callback(undefined, {statusCode: 200}, body)
})
.catch((error) => {
callback(error);
});
}
}
else {
post = node_require('request').post;
}
const url = require("url");
const postHeaders = {
'content-type': 'application/json;charset=utf-8',
'accept': 'application/json'
};
function _authenticate(server, json, callback) {
json.app_id = '';
var options = {
url: server + '/auth',
body: JSON.stringify(json),
headers: postHeaders
};
post(options, function(error, response, body) {
if (error) {
callback(error);
}
else if (response.statusCode != 200) {
callback(new AuthError(JSON.parse(body)));
}
else {
let rjson = JSON.parse(body);
// TODO: validate JSON
const token = rjson.refresh_token.token;
const identity = rjson.refresh_token.token_data.identity;
callback(undefined, new User(server, identity, token));
}
});
}
function User(server, identity, token) {
this.server = server;
this.identity = identity;
this.token = token;
this.isAdmin = false;
User.activeUsers[identity] = this;
}
User.adminUser = function(server, token) {
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
var user = new User(server, uuid, token);
user.isAdmin = true;
return user;
}
User.activeUsers = {};
User.login = function(server, username, password, callback) {
_authenticate(server, {
provider: 'password',
user_info: { password: password },
data: username
}, callback);
}
User.loginWithProvider = function(server, provider, providerToken, callback) {
_authenticate(server, {
provider: provider,
data: providerToken
}, callback);
}
User.create = function(server, username, password, callback) {
_authenticate(server, {
provider: 'password',
user_info: { password: password, register: true },
data: username
}, callback);
}
User.authenticateRealm = function(fileUrl, realmUrl, callback) {
var options = {
url: this.server + '/auth',
body: JSON.stringify({
data: this.token,
path: url.parse(realmUrl).path,
provider: 'realm',
app_id: ''
}),
headers: postHeaders
};
post(options, function(error, response, body) {
if (error) {
callback(error);
}
else if (response.statusCode != 200) {
callback(new AuthError(JSON.parse(body)));
}
else {
var json = JSON.parse(body);
// TODO: validate JSON
callback(undefined, {
token: json.access_token.token,
file_url: url.parse(fileUrl).path,
resolved_realm_url: 'realm://' + url.parse(realmUrl).host + json.access_token.token_data.path
});
}
});
}
exports['User'] = User;

138
lib/user-methods.js Normal file
View File

@ -0,0 +1,138 @@
'use strict';
function node_require(module) {
return require(module);
}
var post;
if (typeof fetch != 'undefined') {
post = function(options, callback) {
options.method = 'POST';
fetch(options.url, options)
.then((response) => {
if (response.status != 200) {
callback(undefined, {statusCode: response.status});
}
else {
return response.text();
}
})
.then((body) => {
callback(undefined, {statusCode: 200}, body)
})
.catch((error) => {
callback(error);
});
}
}
else {
post = node_require('request').post;
}
const url = require("url");
const postHeaders = {
'content-type': 'application/json;charset=utf-8',
'accept': 'application/json'
};
module.exports = function(realmConstructor) {
function _authenticate(server, json, callback) {
json.app_id = '';
var options = {
url: server + 'auth',
body: JSON.stringify(json),
headers: postHeaders
};
post(options, function(error, response, body) {
if (error) {
console.log(error);
callback(error);
}
else if (response.statusCode != 200) {
console.log('Bad response: ' + response.statusCode);
callback(new Error('Bad response: ' + response.statusCode));
}
else {
var rjson = JSON.parse(body);
// TODO: validate JSON
const token = rjson.refresh_token.token;
const identity = rjson.refresh_token.token_data.identity;
callback(undefined, realmConstructor.Sync.User.createUser(server, identity, token, false));
}
});
}
var methods = {};
methods['adminUser'] = function(server, token) {
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
var user = realmConstructor.Sync.User.createUser(server, uuid, token, true);
return user;
}
methods['login'] = function(server, username, password, callback) {
_authenticate(server, {
provider: 'password',
user_info: { password: password },
data: username
}, callback);
}
methods['loginWithProvider'] = function(server, provider, providerToken, callback) {
_authenticate(server, {
provider: provider,
data: providerToken
}, callback);
}
methods['create'] = function(server, username, password, callback) {
_authenticate(server, {
provider: 'password',
user_info: { password: password, register: true },
data: username
}, callback);
}
methods['_authenticateRealm'] = function(fileUrl, realmUrl, callback) {
var options = {
url: this.server + 'auth',
body: JSON.stringify({
data: this.token,
path: url.parse(realmUrl).path,
provider: 'realm',
app_id: ''
}),
headers: postHeaders
};
post(options, function(error, response, body) {
if (error) {
console.log(error);
callback(error);
}
else if (response.statusCode != 200) {
console.log('Bad response: ' + response.statusCode + body);
callback(new Error('Bad response: ' + response.statusCode));
}
else {
var json = JSON.parse(body);
// TODO: validate JSON
callback(undefined, {
token: json.access_token.token,
file_url: url.parse(fileUrl).path,
resolved_realm_url: 'realm://' + url.parse(realmUrl).host + json.access_token.token_data.path
});
}
});
}
for (var name in methods) {
methods[name] = {value: methods[name], configurable: true, writable: true}
}
return methods;
}

View File

@ -10,9 +10,6 @@
02022A581DA476CD000F0C4F /* external_commit_helper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A411DA47489000F0C4F /* external_commit_helper.cpp */; }; 02022A581DA476CD000F0C4F /* external_commit_helper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A411DA47489000F0C4F /* external_commit_helper.cpp */; };
02022A5A1DA476CD000F0C4F /* weak_realm_notifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A4A1DA475A9000F0C4F /* weak_realm_notifier.cpp */; }; 02022A5A1DA476CD000F0C4F /* weak_realm_notifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A4A1DA475A9000F0C4F /* weak_realm_notifier.cpp */; };
02022A5B1DA476CD000F0C4F /* placeholder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A4C1DA475C0000F0C4F /* placeholder.cpp */; }; 02022A5B1DA476CD000F0C4F /* placeholder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A4C1DA475C0000F0C4F /* placeholder.cpp */; };
02022A5C1DA476CD000F0C4F /* sync_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A4E1DA475C0000F0C4F /* sync_manager.cpp */; };
02022A5D1DA476CD000F0C4F /* sync_metadata.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A501DA475C0000F0C4F /* sync_metadata.cpp */; };
02022A5E1DA476CD000F0C4F /* sync_session.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A521DA475C0000F0C4F /* sync_session.cpp */; };
02022A671DA47BD7000F0C4F /* parser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A611DA47B8B000F0C4F /* parser.cpp */; }; 02022A671DA47BD7000F0C4F /* parser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A611DA47B8B000F0C4F /* parser.cpp */; };
02022A681DA47BD7000F0C4F /* query_builder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A631DA47B8B000F0C4F /* query_builder.cpp */; }; 02022A681DA47BD7000F0C4F /* query_builder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A631DA47B8B000F0C4F /* query_builder.cpp */; };
02022A7C1DA47EC8000F0C4F /* format.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A731DA47EC8000F0C4F /* format.cpp */; }; 02022A7C1DA47EC8000F0C4F /* format.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02022A731DA47EC8000F0C4F /* format.cpp */; };
@ -28,6 +25,12 @@
027A23131CD3E379000543AE /* libRealmJS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F63FF2B11C1241E500B3B8E0 /* libRealmJS.a */; }; 027A23131CD3E379000543AE /* libRealmJS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F63FF2B11C1241E500B3B8E0 /* libRealmJS.a */; };
02D041F71CE11159000E4250 /* dates-v3.realm in Resources */ = {isa = PBXBuildFile; fileRef = 02D041F61CE11159000E4250 /* dates-v3.realm */; }; 02D041F71CE11159000E4250 /* dates-v3.realm in Resources */ = {isa = PBXBuildFile; fileRef = 02D041F61CE11159000E4250 /* dates-v3.realm */; };
02D8D1F71B601984006DB49D /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; }; 02D8D1F71B601984006DB49D /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; };
02E315C91DB80DDD00555337 /* sync_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02E315C31DB80DDD00555337 /* sync_manager.cpp */; };
02E315CA1DB80DDD00555337 /* sync_session.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02E315C51DB80DDD00555337 /* sync_session.cpp */; };
02E315CB1DB80DDD00555337 /* sync_user.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02E315C71DB80DDD00555337 /* sync_user.cpp */; };
02E315D21DB80DF200555337 /* sync_file.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02E315CE1DB80DF200555337 /* sync_file.cpp */; };
02E315D31DB80DF200555337 /* sync_metadata.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02E315D01DB80DF200555337 /* sync_metadata.cpp */; };
02E315E01DB8233E00555337 /* keychain_helper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02E315DE1DB8233E00555337 /* keychain_helper.cpp */; };
02F59EBF1C88F17D007F774C /* index_set.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02F59EAF1C88F17D007F774C /* index_set.cpp */; }; 02F59EBF1C88F17D007F774C /* index_set.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02F59EAF1C88F17D007F774C /* index_set.cpp */; };
02F59EC01C88F17D007F774C /* list.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02F59EB11C88F17D007F774C /* list.cpp */; }; 02F59EC01C88F17D007F774C /* list.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02F59EB11C88F17D007F774C /* list.cpp */; };
02F59EC11C88F17D007F774C /* object_schema.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02F59EB41C88F17D007F774C /* object_schema.cpp */; }; 02F59EC11C88F17D007F774C /* object_schema.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02F59EB41C88F17D007F774C /* object_schema.cpp */; };
@ -100,16 +103,8 @@
02022A411DA47489000F0C4F /* external_commit_helper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = external_commit_helper.cpp; sourceTree = "<group>"; }; 02022A411DA47489000F0C4F /* external_commit_helper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = external_commit_helper.cpp; sourceTree = "<group>"; };
02022A421DA47489000F0C4F /* external_commit_helper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = external_commit_helper.hpp; sourceTree = "<group>"; }; 02022A421DA47489000F0C4F /* external_commit_helper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = external_commit_helper.hpp; sourceTree = "<group>"; };
02022A481DA474A7000F0C4F /* weak_realm_notifier.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = weak_realm_notifier.hpp; sourceTree = "<group>"; }; 02022A481DA474A7000F0C4F /* weak_realm_notifier.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = weak_realm_notifier.hpp; sourceTree = "<group>"; };
02022A491DA475A9000F0C4F /* sync_client.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = sync_client.hpp; sourceTree = "<group>"; };
02022A4A1DA475A9000F0C4F /* weak_realm_notifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = weak_realm_notifier.cpp; sourceTree = "<group>"; }; 02022A4A1DA475A9000F0C4F /* weak_realm_notifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = weak_realm_notifier.cpp; sourceTree = "<group>"; };
02022A4C1DA475C0000F0C4F /* placeholder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = placeholder.cpp; path = src/placeholder.cpp; sourceTree = "<group>"; }; 02022A4C1DA475C0000F0C4F /* placeholder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = placeholder.cpp; path = src/placeholder.cpp; sourceTree = "<group>"; };
02022A4D1DA475C0000F0C4F /* sync_config.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sync_config.hpp; path = src/sync_config.hpp; sourceTree = "<group>"; };
02022A4E1DA475C0000F0C4F /* sync_manager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sync_manager.cpp; path = src/sync_manager.cpp; sourceTree = "<group>"; };
02022A4F1DA475C0000F0C4F /* sync_manager.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sync_manager.hpp; path = src/sync_manager.hpp; sourceTree = "<group>"; };
02022A501DA475C0000F0C4F /* sync_metadata.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sync_metadata.cpp; path = src/sync_metadata.cpp; sourceTree = "<group>"; };
02022A511DA475C0000F0C4F /* sync_metadata.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sync_metadata.hpp; path = src/sync_metadata.hpp; sourceTree = "<group>"; };
02022A521DA475C0000F0C4F /* sync_session.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sync_session.cpp; path = src/sync_session.cpp; sourceTree = "<group>"; };
02022A531DA475C0000F0C4F /* sync_session.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sync_session.hpp; path = src/sync_session.hpp; sourceTree = "<group>"; };
02022A611DA47B8B000F0C4F /* parser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parser.cpp; sourceTree = "<group>"; }; 02022A611DA47B8B000F0C4F /* parser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parser.cpp; sourceTree = "<group>"; };
02022A621DA47B8B000F0C4F /* parser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = parser.hpp; sourceTree = "<group>"; }; 02022A621DA47B8B000F0C4F /* parser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = parser.hpp; sourceTree = "<group>"; };
02022A631DA47B8B000F0C4F /* query_builder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = query_builder.cpp; sourceTree = "<group>"; }; 02022A631DA47B8B000F0C4F /* query_builder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = query_builder.cpp; sourceTree = "<group>"; };
@ -161,6 +156,20 @@
02B58CBC1AE99CEC009B348C /* RealmJSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RealmJSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 02B58CBC1AE99CEC009B348C /* RealmJSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RealmJSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
02D041F61CE11159000E4250 /* dates-v3.realm */ = {isa = PBXFileReference; lastKnownFileType = file; path = "dates-v3.realm"; sourceTree = "<group>"; }; 02D041F61CE11159000E4250 /* dates-v3.realm */ = {isa = PBXFileReference; lastKnownFileType = file; path = "dates-v3.realm"; sourceTree = "<group>"; };
02E315C21DB80DDD00555337 /* sync_config.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sync_config.hpp; path = src/sync/sync_config.hpp; sourceTree = "<group>"; };
02E315C31DB80DDD00555337 /* sync_manager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sync_manager.cpp; path = src/sync/sync_manager.cpp; sourceTree = "<group>"; };
02E315C41DB80DDD00555337 /* sync_manager.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sync_manager.hpp; path = src/sync/sync_manager.hpp; sourceTree = "<group>"; };
02E315C51DB80DDD00555337 /* sync_session.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sync_session.cpp; path = src/sync/sync_session.cpp; sourceTree = "<group>"; };
02E315C61DB80DDD00555337 /* sync_session.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sync_session.hpp; path = src/sync/sync_session.hpp; sourceTree = "<group>"; };
02E315C71DB80DDD00555337 /* sync_user.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sync_user.cpp; path = src/sync/sync_user.cpp; sourceTree = "<group>"; };
02E315C81DB80DDD00555337 /* sync_user.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sync_user.hpp; path = src/sync/sync_user.hpp; sourceTree = "<group>"; };
02E315CD1DB80DF200555337 /* sync_client.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sync_client.hpp; path = src/sync/impl/sync_client.hpp; sourceTree = "<group>"; };
02E315CE1DB80DF200555337 /* sync_file.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sync_file.cpp; path = src/sync/impl/sync_file.cpp; sourceTree = "<group>"; };
02E315CF1DB80DF200555337 /* sync_file.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sync_file.hpp; path = src/sync/impl/sync_file.hpp; sourceTree = "<group>"; };
02E315D01DB80DF200555337 /* sync_metadata.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sync_metadata.cpp; path = src/sync/impl/sync_metadata.cpp; sourceTree = "<group>"; };
02E315D11DB80DF200555337 /* sync_metadata.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sync_metadata.hpp; path = src/sync/impl/sync_metadata.hpp; sourceTree = "<group>"; };
02E315DE1DB8233E00555337 /* keychain_helper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = keychain_helper.cpp; sourceTree = "<group>"; };
02E315DF1DB8233E00555337 /* keychain_helper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = keychain_helper.hpp; sourceTree = "<group>"; };
02F59EAE1C88F17D007F774C /* binding_context.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = binding_context.hpp; path = src/binding_context.hpp; sourceTree = "<group>"; }; 02F59EAE1C88F17D007F774C /* binding_context.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = binding_context.hpp; path = src/binding_context.hpp; sourceTree = "<group>"; };
02F59EAF1C88F17D007F774C /* index_set.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = index_set.cpp; path = src/index_set.cpp; sourceTree = "<group>"; }; 02F59EAF1C88F17D007F774C /* index_set.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = index_set.cpp; path = src/index_set.cpp; sourceTree = "<group>"; };
02F59EB01C88F17D007F774C /* index_set.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = index_set.hpp; path = src/index_set.hpp; sourceTree = "<group>"; }; 02F59EB01C88F17D007F774C /* index_set.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = index_set.hpp; path = src/index_set.hpp; sourceTree = "<group>"; };
@ -441,6 +450,25 @@
path = data; path = data;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
02E315CC1DB80DE000555337 /* sync */ = {
isa = PBXGroup;
children = (
02E315CD1DB80DF200555337 /* sync_client.hpp */,
02E315CE1DB80DF200555337 /* sync_file.cpp */,
02E315CF1DB80DF200555337 /* sync_file.hpp */,
02E315D01DB80DF200555337 /* sync_metadata.cpp */,
02E315D11DB80DF200555337 /* sync_metadata.hpp */,
02E315C21DB80DDD00555337 /* sync_config.hpp */,
02E315C31DB80DDD00555337 /* sync_manager.cpp */,
02E315C41DB80DDD00555337 /* sync_manager.hpp */,
02E315C51DB80DDD00555337 /* sync_session.cpp */,
02E315C61DB80DDD00555337 /* sync_session.hpp */,
02E315C71DB80DDD00555337 /* sync_user.cpp */,
02E315C81DB80DDD00555337 /* sync_user.hpp */,
);
name = sync;
sourceTree = "<group>";
};
F62A35131C18E6E2004A917D /* iOS */ = { F62A35131C18E6E2004A917D /* iOS */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -454,6 +482,7 @@
F62A35141C18E783004A917D /* Object Store */ = { F62A35141C18E783004A917D /* Object Store */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
02E315CC1DB80DE000555337 /* sync */,
02022A6B1DA47EC8000F0C4F /* util */, 02022A6B1DA47EC8000F0C4F /* util */,
F63117EA1CEB0BFA00ECB2DE /* impl */, F63117EA1CEB0BFA00ECB2DE /* impl */,
F63117EC1CEB0C8100ECB2DE /* parser */, F63117EC1CEB0C8100ECB2DE /* parser */,
@ -470,13 +499,6 @@
02F59EB61C88F17D007F774C /* object_store.cpp */, 02F59EB61C88F17D007F774C /* object_store.cpp */,
02F59EB71C88F17D007F774C /* object_store.hpp */, 02F59EB71C88F17D007F774C /* object_store.hpp */,
02022A4C1DA475C0000F0C4F /* placeholder.cpp */, 02022A4C1DA475C0000F0C4F /* placeholder.cpp */,
02022A4D1DA475C0000F0C4F /* sync_config.hpp */,
02022A4E1DA475C0000F0C4F /* sync_manager.cpp */,
02022A4F1DA475C0000F0C4F /* sync_manager.hpp */,
02022A501DA475C0000F0C4F /* sync_metadata.cpp */,
02022A511DA475C0000F0C4F /* sync_metadata.hpp */,
02022A521DA475C0000F0C4F /* sync_session.cpp */,
02022A531DA475C0000F0C4F /* sync_session.hpp */,
02F59EB81C88F17D007F774C /* property.hpp */, 02F59EB81C88F17D007F774C /* property.hpp */,
02F59EB91C88F17D007F774C /* results.cpp */, 02F59EB91C88F17D007F774C /* results.cpp */,
02F59EBA1C88F17D007F774C /* results.hpp */, 02F59EBA1C88F17D007F774C /* results.hpp */,
@ -536,7 +558,6 @@
02F59EDD1C88F2BB007F774C /* transact_log_handler.cpp */, 02F59EDD1C88F2BB007F774C /* transact_log_handler.cpp */,
02F59EDE1C88F2BB007F774C /* transact_log_handler.hpp */, 02F59EDE1C88F2BB007F774C /* transact_log_handler.hpp */,
02022A481DA474A7000F0C4F /* weak_realm_notifier.hpp */, 02022A481DA474A7000F0C4F /* weak_realm_notifier.hpp */,
02022A491DA475A9000F0C4F /* sync_client.hpp */,
02022A4A1DA475A9000F0C4F /* weak_realm_notifier.cpp */, 02022A4A1DA475A9000F0C4F /* weak_realm_notifier.cpp */,
); );
name = impl; name = impl;
@ -546,6 +567,8 @@
F63117EB1CEB0C1B00ECB2DE /* apple */ = { F63117EB1CEB0C1B00ECB2DE /* apple */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
02E315DE1DB8233E00555337 /* keychain_helper.cpp */,
02E315DF1DB8233E00555337 /* keychain_helper.hpp */,
02022A411DA47489000F0C4F /* external_commit_helper.cpp */, 02022A411DA47489000F0C4F /* external_commit_helper.cpp */,
02022A421DA47489000F0C4F /* external_commit_helper.hpp */, 02022A421DA47489000F0C4F /* external_commit_helper.hpp */,
); );
@ -906,14 +929,13 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
02E315C91DB80DDD00555337 /* sync_manager.cpp in Sources */,
02022A671DA47BD7000F0C4F /* parser.cpp in Sources */, 02022A671DA47BD7000F0C4F /* parser.cpp in Sources */,
02022A681DA47BD7000F0C4F /* query_builder.cpp in Sources */, 02022A681DA47BD7000F0C4F /* query_builder.cpp in Sources */,
02E315E01DB8233E00555337 /* keychain_helper.cpp in Sources */,
02022A581DA476CD000F0C4F /* external_commit_helper.cpp in Sources */, 02022A581DA476CD000F0C4F /* external_commit_helper.cpp in Sources */,
02022A5A1DA476CD000F0C4F /* weak_realm_notifier.cpp in Sources */, 02022A5A1DA476CD000F0C4F /* weak_realm_notifier.cpp in Sources */,
02022A5B1DA476CD000F0C4F /* placeholder.cpp in Sources */, 02022A5B1DA476CD000F0C4F /* placeholder.cpp in Sources */,
02022A5C1DA476CD000F0C4F /* sync_manager.cpp in Sources */,
02022A5D1DA476CD000F0C4F /* sync_metadata.cpp in Sources */,
02022A5E1DA476CD000F0C4F /* sync_session.cpp in Sources */,
5DC74A7A1D623CA800D77A4F /* thread_confined.cpp in Sources */, 5DC74A7A1D623CA800D77A4F /* thread_confined.cpp in Sources */,
02414BA51CE6ABCF00A8669F /* collection_change_builder.cpp in Sources */, 02414BA51CE6ABCF00A8669F /* collection_change_builder.cpp in Sources */,
02414BA61CE6ABCF00A8669F /* collection_notifier.cpp in Sources */, 02414BA61CE6ABCF00A8669F /* collection_notifier.cpp in Sources */,
@ -923,6 +945,7 @@
02F59EE31C88F2BB007F774C /* transact_log_handler.cpp in Sources */, 02F59EE31C88F2BB007F774C /* transact_log_handler.cpp in Sources */,
5DC74A781D623C9800D77A4F /* handover.cpp in Sources */, 5DC74A781D623C9800D77A4F /* handover.cpp in Sources */,
F63FF2E81C159C4B00B3B8E0 /* platform.mm in Sources */, F63FF2E81C159C4B00B3B8E0 /* platform.mm in Sources */,
02E315CA1DB80DDD00555337 /* sync_session.cpp in Sources */,
02F59EC31C88F17D007F774C /* results.cpp in Sources */, 02F59EC31C88F17D007F774C /* results.cpp in Sources */,
F63FF2E21C15921A00B3B8E0 /* base64.cpp in Sources */, F63FF2E21C15921A00B3B8E0 /* base64.cpp in Sources */,
F63FF2C61C12469E00B3B8E0 /* jsc_init.cpp in Sources */, F63FF2C61C12469E00B3B8E0 /* jsc_init.cpp in Sources */,
@ -933,9 +956,12 @@
02F59EE21C88F2BB007F774C /* realm_coordinator.cpp in Sources */, 02F59EE21C88F2BB007F774C /* realm_coordinator.cpp in Sources */,
02F59EC41C88F17D007F774C /* schema.cpp in Sources */, 02F59EC41C88F17D007F774C /* schema.cpp in Sources */,
F63FF2CD1C12469E00B3B8E0 /* rpc.cpp in Sources */, F63FF2CD1C12469E00B3B8E0 /* rpc.cpp in Sources */,
02E315D21DB80DF200555337 /* sync_file.cpp in Sources */,
02F59EC21C88F17D007F774C /* object_store.cpp in Sources */, 02F59EC21C88F17D007F774C /* object_store.cpp in Sources */,
02022A7C1DA47EC8000F0C4F /* format.cpp in Sources */, 02022A7C1DA47EC8000F0C4F /* format.cpp in Sources */,
02022A7D1DA47EC8000F0C4F /* thread_id.cpp in Sources */, 02022A7D1DA47EC8000F0C4F /* thread_id.cpp in Sources */,
02E315CB1DB80DDD00555337 /* sync_user.cpp in Sources */,
02E315D31DB80DF200555337 /* sync_metadata.cpp in Sources */,
02F59EC11C88F17D007F774C /* object_schema.cpp in Sources */, 02F59EC11C88F17D007F774C /* object_schema.cpp in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;

View File

@ -32,7 +32,7 @@
#if REALM_ENABLE_SYNC #if REALM_ENABLE_SYNC
#include "js_sync.hpp" #include "js_sync.hpp"
#include "sync_config.hpp" #include "sync/sync_config.hpp"
#endif #endif
#include "shared_realm.hpp" #include "shared_realm.hpp"
@ -146,6 +146,7 @@ class RealmClass : public ClassDefinition<T, SharedRealm, ObservableClass<T>> {
public: public:
static FunctionType create_constructor(ContextType); static FunctionType create_constructor(ContextType);
static Protected<FunctionType> s_constructor;
// methods // methods
static void objects(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); static void objects(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &);
@ -255,6 +256,9 @@ public:
} }
}; };
template<typename T>
Protected<typename T::Function> RealmClass<T>::s_constructor;
template<typename T> template<typename T>
inline typename T::Function RealmClass<T>::create_constructor(ContextType ctx) { inline typename T::Function RealmClass<T>::create_constructor(ContextType ctx) {
FunctionType realm_constructor = ObjectWrap<T, RealmClass<T>>::create_constructor(ctx); FunctionType realm_constructor = ObjectWrap<T, RealmClass<T>>::create_constructor(ctx);
@ -274,6 +278,7 @@ inline typename T::Function RealmClass<T>::create_constructor(ContextType ctx) {
Object::set_property(ctx, realm_constructor, "Sync", sync_constructor, attributes); Object::set_property(ctx, realm_constructor, "Sync", sync_constructor, attributes);
#endif #endif
s_constructor = Protected<FunctionType>(ctx, realm_constructor);
return realm_constructor; return realm_constructor;
} }
@ -390,7 +395,7 @@ void RealmClass<T>::constructor(ContextType ctx, ObjectType this_object, size_t
config.encryption_key = std::vector<char>(encryption_key.begin(), encryption_key.end()); config.encryption_key = std::vector<char>(encryption_key.begin(), encryption_key.end());
} }
#if REALM_ENABLE_SYNC #if REALM_ENABLE_SYNC
SyncClass<T>::populate_sync_config(ctx, object, config); SyncClass<T>::populate_sync_config(ctx, s_constructor, object, config);
#endif #endif
} }
} }

View File

@ -22,17 +22,93 @@
#include <map> #include <map>
#include <set> #include <set>
#include "platform.hpp"
#include "js_class.hpp" #include "js_class.hpp"
#include "js_collection.hpp" #include "js_collection.hpp"
#include "sync_manager.hpp" #include "sync/sync_manager.hpp"
#include "sync_config.hpp" #include "sync/sync_config.hpp"
#include "sync_session.hpp" #include "sync/sync_session.hpp"
#include "sync/sync_user.hpp"
#include "realm/util/logger.hpp" #include "realm/util/logger.hpp"
#include "realm/util/uri.hpp" #include "realm/util/uri.hpp"
namespace realm { namespace realm {
namespace js { namespace js {
using SharedUser = std::shared_ptr<realm::SyncUser>;
template<typename T>
class UserClass : public ClassDefinition<T, SharedUser> {
using GlobalContextType = typename T::GlobalContext;
using ContextType = typename T::Context;
using FunctionType = typename T::Function;
using ObjectType = typename T::Object;
using ValueType = typename T::Value;
using String = js::String<T>;
using Object = js::Object<T>;
using Value = js::Value<T>;
using Function = js::Function<T>;
using ReturnValue = js::ReturnValue<T>;
using NativeAccessor = realm::NativeAccessor<ValueType, ContextType>;
public:
std::string const name = "User";
static FunctionType create_constructor(ContextType);
static void get_server(ContextType, ObjectType, ReturnValue &);
static void get_identity(ContextType, ObjectType, ReturnValue &);
static void get_token(ContextType, ObjectType, ReturnValue &);
static void is_admin(ContextType, ObjectType, ReturnValue &);
PropertyMap<T> const properties = {
{"server", {wrap<get_server>, nullptr}},
{"identity", {wrap<get_identity>, nullptr}},
{"token", {wrap<get_token>, nullptr}},
{"isAdmin", {wrap<is_admin>, nullptr}},
};
static void create_user(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &);
MethodMap<T> const static_methods = {
{"createUser", wrap<create_user>}
};
};
template<typename T>
void UserClass<T>::get_server(ContextType ctx, ObjectType object, ReturnValue &return_value) {
std::string server = get_internal<T, UserClass<T>>(object)->get()->server_url;
return_value.set(server);
}
template<typename T>
void UserClass<T>::get_identity(ContextType ctx, ObjectType object, ReturnValue &return_value) {
std::string identity = get_internal<T, UserClass<T>>(object)->get()->identity();
return_value.set(identity);
}
template<typename T>
void UserClass<T>::get_token(ContextType ctx, ObjectType object, ReturnValue &return_value) {
std::string token = get_internal<T, UserClass<T>>(object)->get()->refresh_token();
return_value.set(token);
}
template<typename T>
void UserClass<T>::is_admin(ContextType ctx, ObjectType object, ReturnValue &return_value) {
return_value.set(get_internal<T, UserClass<T>>(object)->get()->is_admin());
}
template<typename T>
void UserClass<T>::create_user(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
validate_argument_count(argc, 3, 4);
SharedUser *user = new SharedUser(SyncManager::shared().get_user(Value::validated_to_string(ctx, arguments[1]),
Value::validated_to_string(ctx, arguments[2]),
Value::validated_to_boolean(ctx, arguments[3])));
user->get()->server_url = Value::validated_to_string(ctx, arguments[0]);
return_value.set(create_object<T, UserClass<T>>(ctx, user));
}
template<typename T> template<typename T>
class SyncClass : public ClassDefinition<T, void *> { class SyncClass : public ClassDefinition<T, void *> {
using GlobalContextType = typename T::GlobalContext; using GlobalContextType = typename T::GlobalContext;
@ -57,7 +133,7 @@ public:
// private // private
static void refresh_access_token(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); static void refresh_access_token(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &);
static void populate_sync_config(ContextType, ObjectType config_object, Realm::Config&); static void populate_sync_config(ContextType, FunctionType realm_constructor, ObjectType config_object, Realm::Config&);
// static properties // static properties
static void get_is_developer_edition(ContextType, ObjectType, ReturnValue &); static void get_is_developer_edition(ContextType, ObjectType, ReturnValue &);
@ -71,53 +147,19 @@ public:
template<typename T> template<typename T>
inline typename T::Function SyncClass<T>::create_constructor(ContextType ctx) { inline typename T::Function SyncClass<T>::create_constructor(ContextType ctx) {
// 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);
FunctionType sync_constructor = ObjectWrap<T, SyncClass<T>>::create_constructor(ctx); FunctionType sync_constructor = ObjectWrap<T, SyncClass<T>>::create_constructor(ctx);
Protected<ValueType> refresh(ctx, Object::validated_get_function(ctx, sync_constructor, std::string("refreshAccessToken"))); PropertyAttributes attributes = ReadOnly | DontEnum | DontDelete;
Protected<ObjectType> protected_sync(ctx, sync_constructor); Object::set_property(ctx, sync_constructor, "User", ObjectWrap<T, UserClass<T>>::create_constructor(ctx), attributes);
Protected<typename T::GlobalContext> protected_ctx(Context<T>::get_global_context(ctx));
realm::SyncManager::shared().set_login_function([=](const std::string& path, const realm::SyncConfig& config) {
typename T::HandleScope handle_scope;
FunctionType user_constructor = Object::validated_get_function(protected_ctx, protected_sync, std::string("User"));
FunctionType authenticate = Object::validated_get_function(protected_ctx, user_constructor, "authenticateRealm");
ObjectType users = Object::validated_get_object(protected_ctx, user_constructor, std::string("activeUsers"));
ObjectType user = Object::validated_get_object(protected_ctx, users, config.user_tag.c_str(), "Invalid user identity");
if (Object::validated_get_boolean(protected_ctx, user, "isAdmin")) {
std::string token = Object::validated_get_string(protected_ctx, user, "token");
// FIXME: This log-in callback is called while the object store still holds some sync-related locks.
// Notify the object store of the access token asynchronously to avoid the deadlock that would result
// from reentering the object store here.
auto thread = std::thread([path, config, token]{
auto session = SyncManager::shared().get_existing_active_session(path);
session->refresh_access_token(token, config.realm_url);
});
thread.detach();
}
else {
ValueType arguments[3];
arguments[0] = Value::from_string(protected_ctx, path.c_str());
arguments[1] = Value::from_string(protected_ctx, config.realm_url.c_str());
arguments[2] = refresh;
Function::call(protected_ctx, authenticate, user, 3, arguments);
}
});
realm::SyncManager::shared().set_error_handler([=](int error_code, std::string message) { realm::SyncManager::shared().set_error_handler([=](int error_code, std::string message) {
std::cout << error_code << " " << message << std::endl; std::cout << error_code << " " << message << std::endl;
}); });
#if REALM_PLATFORM_NODE
// AtExit is called before the V8 VM is disposed. We use it to clean the captured JS objects in the login function.
// Should they be destructed after the VM is disposed, there will be a segmentation fault during node's shutdown.
::node::AtExit([](void*) {
realm::SyncManager::shared().set_login_function(nullptr);
});
#endif
return sync_constructor; return sync_constructor;
} }
@ -165,18 +207,51 @@ void SyncClass<T>::refresh_access_token(ContextType ctx, ObjectType this_object,
} }
template<typename T> template<typename T>
void SyncClass<T>::populate_sync_config(ContextType ctx, ObjectType config_object, Realm::Config& config) { void SyncClass<T>::populate_sync_config(ContextType ctx, FunctionType realm_constructor, ObjectType config_object, Realm::Config& config) {
ValueType sync_config_value = Object::get_property(ctx, config_object, "sync"); ValueType sync_config_value = Object::get_property(ctx, config_object, "sync");
if (!Value::is_undefined(ctx, sync_config_value)) { if (!Value::is_undefined(ctx, sync_config_value)) {
auto sync_config_object = Value::validated_to_object(ctx, sync_config_value); auto sync_config_object = Value::validated_to_object(ctx, sync_config_value);
ObjectType sync_constructor = Object::validated_get_object(ctx, realm_constructor, std::string("Sync"));
Protected<ValueType> refresh(ctx, Object::validated_get_function(ctx, sync_constructor, std::string("refreshAccessToken")));
Protected<ObjectType> protected_sync(ctx, sync_constructor);
Protected<typename T::GlobalContext> protected_ctx(Context<T>::get_global_context(ctx));
auto handler = [=](const std::string& path, const realm::SyncConfig& config, std::shared_ptr<SyncSession>) {
typename T::HandleScope handle_scope;
if (config.user->is_admin()) {
// FIXME: This log-in callback is called while the object store still holds some sync-related locks.
// Notify the object store of the access token asynchronously to avoid the deadlock that would result
// from reentering the object store here.
auto thread = std::thread([path, config]{
auto session = SyncManager::shared().get_existing_active_session(path);
session->refresh_access_token(config.user->refresh_token(), config.realm_url);
});
thread.detach();
}
else {
ObjectType user_constructor = Object::validated_get_object(ctx, protected_sync, std::string("User"));
FunctionType authenticate = Object::validated_get_function(ctx, user_constructor, std::string("_authenticateRealm"));
ValueType arguments[3];
arguments[0] = Value::from_string(protected_ctx, path.c_str());
arguments[1] = Value::from_string(protected_ctx, config.realm_url.c_str());
arguments[2] = refresh;
ObjectType user = create_object<T, UserClass<T>>(ctx, new SharedUser(config.user));
Function::call(protected_ctx, authenticate, user, 3, arguments);
}
};
ObjectType user = Object::validated_get_object(ctx, sync_config_object, "user"); ObjectType user = Object::validated_get_object(ctx, sync_config_object, "user");
SharedUser shared_user = *get_internal<T, UserClass<T>>(user);
std::string raw_realm_url = Object::validated_get_string(ctx, sync_config_object, "url");
// FIXME - use make_shared
config.sync_config = std::shared_ptr<SyncConfig>( config.sync_config = std::shared_ptr<SyncConfig>(
new SyncConfig(Object::validated_get_string(ctx, user, "identity"), new SyncConfig(shared_user, raw_realm_url, SyncSessionStopPolicy::AfterChangesUploaded, handler)
Object::validated_get_string(ctx, sync_config_object, "url"),
{}, SyncSessionStopPolicy::AfterChangesUploaded)
); );
config.schema_mode = SchemaMode::Additive; config.schema_mode = SchemaMode::Additive;
config.path = realm::SyncManager::shared().path_for_realm(shared_user->identity(), raw_realm_url);
} }
} }

View File

@ -57,6 +57,7 @@ class Protected<JSGlobalContextRef> {
template<> template<>
class Protected<JSValueRef> { class Protected<JSValueRef> {
protected:
JSGlobalContextRef m_context; JSGlobalContextRef m_context;
JSValueRef m_value; JSValueRef m_value;
@ -112,7 +113,8 @@ class Protected<JSObjectRef> : public Protected<JSValueRef> {
} }
Protected<JSObjectRef>& operator=(Protected<JSObjectRef> other) { Protected<JSObjectRef>& operator=(Protected<JSObjectRef> other) {
std::swap(*this, other); std::swap(m_context, other.m_context);
std::swap(m_value, other.m_value);
return *this; return *this;
} }
}; };

View File

@ -18,7 +18,7 @@
] ]
}, },
"all_dependent_settings": { "all_dependent_settings": {
"defines": [ "REALM_HAVE_CONFIG", "REALM_PLATFORM_NODE=1", "REALM_ENABLE_SYNC=<(realm_enable_sync)" ] "defines": [ "REALM_HAVE_CONFIG", "REALM_PLATFORM_NODE=1", "REALM_ENABLE_SYNC=1" ]
}, },
"variables": { "variables": {
"prefix": "<!(echo $REALM_CORE_PREFIX)" "prefix": "<!(echo $REALM_CORE_PREFIX)"
@ -96,4 +96,4 @@
} }
] ]
} }

@ -1 +1 @@
Subproject commit 158a45a7a50ff2273c70e75d84d15a6a9d51402b Subproject commit d2ccd87ac6312f3a75eaae3725892c89937f2207

24
test.js
View File

@ -36,21 +36,19 @@ var access_token = 'ewoJImlkZW50aXR5IjogImFkbWluIiwKCSJhY2Nlc3MiOiBbInVwbG9hZCIs
var admin_user = new Realm.Sync.User.adminUser('http://127.0.0.1:9080/', access_token); var admin_user = new Realm.Sync.User.adminUser('http://127.0.0.1:9080/', access_token);
Realm.Sync.setLogLevel('error'); Realm.Sync.setLogLevel('error');
Realm.Sync.setGlobalListener(notifier_dir, 'realm://127.0.0.1:9080', admin_user, // Realm.Sync.setGlobalListener(notifier_dir, 'realm://127.0.0.1:9080', admin_user,
(name) => { // (name) => {
console.log('filter: ' + name); // console.log('filter: ' + name);
return true; // return true;
}, // },
(name, realm, changes) => { // (name, realm, changes) => {
console.log('change: ' + name); // console.log('change: ' + name);
console.log(changes); // console.log(changes);
} // }
); // );
console.log('global notifier listening...'); // console.log('global notifier listening...');
Realm.Sync.User.login('http://127.0.0.1:9080/', 'ari', 'aaa', function(error, user) { Realm.Sync.User.login('http://127.0.0.1:9080/', 'ari', 'aaa', function(error, user) {
console.log(user);
var realm = new Realm({ var realm = new Realm({
sync: { sync: {
user: user, user: user,

View File

@ -1 +0,0 @@
../../src/object-store/tests/query.json

View File

@ -586,7 +586,7 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "[ -s \"${HOME}/.nvm/nvm.sh\" ] && . \"${HOME}/.nvm/nvm.sh\" \nif [ -z \"$TEST_SCRIPT\" ]; then\n #npm install realm realm-tests\n echo a\nfi\ncp ../../../src/object-store/tests/query.json ../node_modules/realm-tests/query-tests.json\n"; shellScript = "[ -s \"${HOME}/.nvm/nvm.sh\" ] && . \"${HOME}/.nvm/nvm.sh\" \nif [ -z \"$TEST_SCRIPT\" ]; then\n #npm install realm realm-tests\n echo a\nfi\ncp \"${SRCROOT}/../../../src/object-store/tests/query.json\" \"${SRCROOT}/../node_modules/realm-tests/query-tests.json\"\n";
}; };
F6EDE5BF1C49007200B1085F /* Bundle React Native code and images */ = { F6EDE5BF1C49007200B1085F /* Bundle React Native code and images */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;

File diff suppressed because it is too large Load Diff