This commit is contained in:
Kenneth Geisshirt 2017-09-27 15:59:21 +02:00
parent 87ab6dd6d3
commit f4248f5d30
4 changed files with 40 additions and 29 deletions

View File

@ -42,6 +42,8 @@ namespace js {
using SharedUser = std::shared_ptr<realm::SyncUser>; using SharedUser = std::shared_ptr<realm::SyncUser>;
using WeakSession = std::weak_ptr<realm::SyncSession>; using WeakSession = std::weak_ptr<realm::SyncSession>;
static bool config_fs_done;
template<typename T> template<typename T>
class UserClass : public ClassDefinition<T, SharedUser> { class UserClass : public ClassDefinition<T, SharedUser> {
using GlobalContextType = typename T::GlobalContext; using GlobalContextType = typename T::GlobalContext;
@ -516,6 +518,7 @@ public:
static FunctionType create_constructor(ContextType); static FunctionType create_constructor(ContextType);
static void set_sync_log_level(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &); 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 // private
static std::function<SyncBindSessionHandler> session_bind_callback(ContextType ctx, ObjectType sync_constructor); static std::function<SyncBindSessionHandler> session_bind_callback(ContextType ctx, ObjectType sync_constructor);
@ -526,6 +529,7 @@ public:
MethodMap<T> const static_methods = { MethodMap<T> const static_methods = {
{"setLogLevel", wrap<set_sync_log_level>}, {"setLogLevel", wrap<set_sync_log_level>},
{"initialize", wrap<initialize>},
}; };
}; };
@ -537,10 +541,7 @@ inline typename T::Function SyncClass<T>::create_constructor(ContextType ctx) {
Object::set_property(ctx, sync_constructor, "User", ObjectWrap<T, UserClass<T>>::create_constructor(ctx), attributes); Object::set_property(ctx, sync_constructor, "User", ObjectWrap<T, UserClass<T>>::create_constructor(ctx), attributes);
Object::set_property(ctx, sync_constructor, "Session", ObjectWrap<T, SessionClass<T>>::create_constructor(ctx), attributes); Object::set_property(ctx, sync_constructor, "Session", ObjectWrap<T, SessionClass<T>>::create_constructor(ctx), attributes);
// setup synced realmFile paths config_fs_done = false;
ensure_directory_exists_for_file(default_realm_file_directory());
SyncManager::shared().configure_file_system(default_realm_file_directory(), SyncManager::MetadataMode::NoEncryption);
return sync_constructor; return sync_constructor;
} }
@ -647,5 +648,13 @@ void SyncClass<T>::populate_sync_config(ContextType ctx, ObjectType realm_constr
} }
} }
} }
template<typename T>
void SyncClass<T>::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(Nan::Undefined());
}
} // js } // js
} // realm } // realm

View File

@ -30,6 +30,7 @@ function createObjects(user) {
setTimeout(() => process.exit(0), 3000); setTimeout(() => process.exit(0), 3000);
} }
Realm.Sync.initialize();
Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, registeredUser) => { Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, registeredUser) => {
if (error) { if (error) {
const registrationError = JSON.stringify(error); const registrationError = JSON.stringify(error);

View File

@ -37,7 +37,7 @@ let execFile;
if (isNodeProccess) { if (isNodeProccess) {
tmp = node_require('tmp'); tmp = node_require('tmp');
fs = node_require('fs'); fs = node_require('fs-extra');
execFile = node_require('child_process').execFile; execFile = node_require('child_process').execFile;
tmp.setGracefulCleanup(); tmp.setGracefulCleanup();
} }

View File

@ -11,7 +11,8 @@
"terminate": "^1.0.8", "terminate": "^1.0.8",
"tmp": "^0.0.30", "tmp": "^0.0.30",
"url-parse": "^1.1.7", "url-parse": "^1.1.7",
"typescript": "^2.5.2" "typescript": "^2.5.2",
"fs-extra": "^4.0.2"
}, },
"scripts": { "scripts": {
"check-typescript" : "tsc --noEmit --alwaysStrict ./../lib/index.d.ts", "check-typescript" : "tsc --noEmit --alwaysStrict ./../lib/index.d.ts",