mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-18 17:47:32 +00:00
wip
This commit is contained in:
parent
87ab6dd6d3
commit
f4248f5d30
@ -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
|
||||||
|
@ -11,9 +11,9 @@ var Realm = require(realmModule);
|
|||||||
|
|
||||||
function createObjects(user) {
|
function createObjects(user) {
|
||||||
const config = {
|
const config = {
|
||||||
sync: { user,
|
sync: { user,
|
||||||
url: `realm://localhost:9080/~/${realmName}`,
|
url: `realm://localhost:9080/~/${realmName}`,
|
||||||
error: err => console.log(err)
|
error: err => console.log(err)
|
||||||
},
|
},
|
||||||
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
||||||
};
|
};
|
||||||
@ -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);
|
||||||
@ -43,8 +44,8 @@ Realm.Sync.User.register('http://localhost:9080', username, 'password', (error,
|
|||||||
createObjects(loggedUser);
|
createObjects(loggedUser);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
createObjects(registeredUser);
|
createObjects(registeredUser);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -29,7 +29,7 @@ const isNodeProccess = (typeof process === 'object' && process + '' === '[object
|
|||||||
|
|
||||||
function node_require(module) {
|
function node_require(module) {
|
||||||
return require(module);
|
return require(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
let tmp;
|
let tmp;
|
||||||
let fs;
|
let fs;
|
||||||
@ -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();
|
||||||
}
|
}
|
||||||
@ -275,7 +275,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
testProgressNotificationsForRealmOpenAsync() {
|
testProgressNotificationsForRealmOpenAsync() {
|
||||||
if (!isNodeProccess) {
|
if (!isNodeProccess) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
@ -292,7 +292,7 @@ module.exports = {
|
|||||||
let progressNotificationCalled = false;
|
let progressNotificationCalled = false;
|
||||||
let config = {
|
let config = {
|
||||||
sync: { user, url: `realm://localhost:9080/~/${realmName}`,
|
sync: { user, url: `realm://localhost:9080/~/${realmName}`,
|
||||||
_onDownloadProgress: (transferred, total) => {
|
_onDownloadProgress: (transferred, total) => {
|
||||||
progressNotificationCalled = true
|
progressNotificationCalled = true
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -486,7 +486,7 @@ module.exports = {
|
|||||||
const progressCallback = (transferred, total) => {
|
const progressCallback = (transferred, total) => {
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
realm.syncSession.addProgressNotification('download', 'reportIndefinitely', progressCallback);
|
realm.syncSession.addProgressNotification('download', 'reportIndefinitely', progressCallback);
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@ -495,7 +495,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
testProgressNotificationsUnregisterForRealmConstructor() {
|
testProgressNotificationsUnregisterForRealmConstructor() {
|
||||||
if (!isNodeProccess) {
|
if (!isNodeProccess) {
|
||||||
@ -519,7 +519,7 @@ module.exports = {
|
|||||||
|
|
||||||
let realm = new Realm(config);
|
let realm = new Realm(config);
|
||||||
let unregisterFunc;
|
let unregisterFunc;
|
||||||
|
|
||||||
let writeDataFunc = () => {
|
let writeDataFunc = () => {
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
for (let i = 1; i <= 3; i++) {
|
for (let i = 1; i <= 3; i++) {
|
||||||
@ -534,14 +534,14 @@ module.exports = {
|
|||||||
if (failOnCall) {
|
if (failOnCall) {
|
||||||
reject(new Error("Progress callback should not be called after removeProgressNotification"));
|
reject(new Error("Progress callback should not be called after removeProgressNotification"));
|
||||||
}
|
}
|
||||||
|
|
||||||
syncFinished = transferred === total;
|
syncFinished = transferred === total;
|
||||||
|
|
||||||
//unregister and write some new data.
|
//unregister and write some new data.
|
||||||
if (syncFinished) {
|
if (syncFinished) {
|
||||||
failOnCall = true;
|
failOnCall = true;
|
||||||
unregisterFunc();
|
unregisterFunc();
|
||||||
|
|
||||||
//use second callback to wait for sync finished
|
//use second callback to wait for sync finished
|
||||||
realm.syncSession.addProgressNotification('upload', 'reportIndefinitely', (x, y) => {
|
realm.syncSession.addProgressNotification('upload', 'reportIndefinitely', (x, y) => {
|
||||||
if (x === y) {
|
if (x === y) {
|
||||||
@ -551,9 +551,9 @@ module.exports = {
|
|||||||
writeDataFunc();
|
writeDataFunc();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
realm.syncSession.addProgressNotification('upload', 'reportIndefinitely', progressCallback);
|
realm.syncSession.addProgressNotification('upload', 'reportIndefinitely', progressCallback);
|
||||||
|
|
||||||
unregisterFunc = () => {
|
unregisterFunc = () => {
|
||||||
realm.syncSession.removeProgressNotification(progressCallback);
|
realm.syncSession.removeProgressNotification(progressCallback);
|
||||||
};
|
};
|
||||||
@ -601,7 +601,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
testProgressNotificationsForRealmOpenAsync2() {
|
testProgressNotificationsForRealmOpenAsync2() {
|
||||||
if (!isNodeProccess) {
|
if (!isNodeProccess) {
|
||||||
@ -624,14 +624,14 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let progressCalled = false;
|
let progressCalled = false;
|
||||||
|
|
||||||
Realm.openAsync(config,
|
Realm.openAsync(config,
|
||||||
(error, realm) => {
|
(error, realm) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCase.assertTrue(progressCalled);
|
TestCase.assertTrue(progressCalled);
|
||||||
resolve();
|
resolve();
|
||||||
},
|
},
|
||||||
@ -645,5 +645,5 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -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",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user