mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 06:46:03 +00:00
Merge pull request #1353 from realm/kneth/lazy-enable-sync
Enable SyncManager late
This commit is contained in:
commit
fc4f6f6c20
15
CHANGELOG.md
15
CHANGELOG.md
@ -1,3 +1,15 @@
|
|||||||
|
x.x.x Release notes (yyyy-MM-dd)
|
||||||
|
=============================================================
|
||||||
|
### Breaking changes
|
||||||
|
* None.
|
||||||
|
|
||||||
|
### Enhancements
|
||||||
|
* None.
|
||||||
|
|
||||||
|
### Bug fixes
|
||||||
|
* Configuration of sync file system is not done on module import but later when actually needed by sync (#1351)
|
||||||
|
|
||||||
|
|
||||||
2.0.0 Release notes (2017-9-28)
|
2.0.0 Release notes (2017-9-28)
|
||||||
=============================================================
|
=============================================================
|
||||||
### Breaking changes
|
### Breaking changes
|
||||||
@ -25,6 +37,9 @@
|
|||||||
* Alignment of permission schemas.
|
* Alignment of permission schemas.
|
||||||
* Updating sync (2.0.0-rc24).
|
* Updating sync (2.0.0-rc24).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
2.0.0-rc10 Release notes (2017-9-19)
|
2.0.0-rc10 Release notes (2017-9-19)
|
||||||
=============================================================
|
=============================================================
|
||||||
### Breaking changes
|
### Breaking changes
|
||||||
|
72
lib/index.d.ts
vendored
72
lib/index.d.ts
vendored
@ -288,7 +288,7 @@ declare namespace Realm.Sync {
|
|||||||
openManagementRealm(): Realm;
|
openManagementRealm(): Realm;
|
||||||
retrieveAccount(provider: string, username: string): Promise<Account>;
|
retrieveAccount(provider: string, username: string): Promise<Account>;
|
||||||
|
|
||||||
getGrantedPermissions(recipient: 'any' | 'currentUser' | 'otherUser'): Results<Permission>;
|
getGrantedPermissions(recipient: 'any' | 'currentUser' | 'otherUser'): Results<Permission>;
|
||||||
applyPermissions(condition: PermissionCondition, realmUrl: string, accessLevel: AccessLevel): Promise<PermissionChange>;
|
applyPermissions(condition: PermissionCondition, realmUrl: string, accessLevel: AccessLevel): Promise<PermissionChange>;
|
||||||
offerPermissions(realmUrl: string, accessLevel: AccessLevel, expiresAt?: Date): Promise<string>;
|
offerPermissions(realmUrl: string, accessLevel: AccessLevel, expiresAt?: Date): Promise<string>;
|
||||||
acceptPermissionOffer(token: string): Promise<string>
|
acceptPermissionOffer(token: string): Promise<string>
|
||||||
@ -296,49 +296,49 @@ declare namespace Realm.Sync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PermissionCondition = {
|
type PermissionCondition = {
|
||||||
userId: string |
|
userId: string |
|
||||||
{ metadataKey: string, metadataValue: string }
|
{ metadataKey: string, metadataValue: string }
|
||||||
};
|
};
|
||||||
|
|
||||||
type AccessLevel = 'none' | 'read' | 'write' | 'admin';
|
type AccessLevel = 'none' | 'read' | 'write' | 'admin';
|
||||||
|
|
||||||
class Permission {
|
class Permission {
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
readonly updatedAt: Date;
|
readonly updatedAt: Date;
|
||||||
readonly userId: string;
|
readonly userId: string;
|
||||||
readonly path: string;
|
readonly path: string;
|
||||||
readonly mayRead?: boolean;
|
readonly mayRead?: boolean;
|
||||||
readonly mayWrite?: boolean;
|
readonly mayWrite?: boolean;
|
||||||
readonly mayManage?: boolean;
|
readonly mayManage?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PermissionChange {
|
class PermissionChange {
|
||||||
id: string;
|
id: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
statusCode?: number;
|
statusCode?: number;
|
||||||
statusMessage?: string;
|
statusMessage?: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
metadataKey?: string;
|
metadataKey?: string;
|
||||||
metadataValue?: string;
|
metadataValue?: string;
|
||||||
realmUrl: string;
|
realmUrl: string;
|
||||||
mayRead?: boolean;
|
mayRead?: boolean;
|
||||||
mayWrite?: boolean;
|
mayWrite?: boolean;
|
||||||
mayManage?: boolean;
|
mayManage?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PermissionOffer {
|
class PermissionOffer {
|
||||||
id: string;
|
id: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
statusCode?: number;
|
statusCode?: number;
|
||||||
statusMessage?: string;
|
statusMessage?: string;
|
||||||
token?: string;
|
token?: string;
|
||||||
realmUrl: string;
|
realmUrl: string;
|
||||||
mayRead?: boolean;
|
mayRead?: boolean;
|
||||||
mayWrite?: boolean;
|
mayWrite?: boolean;
|
||||||
mayManage?: boolean;
|
mayManage?: boolean;
|
||||||
expiresAt?: Date;
|
expiresAt?: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrorCallback = (message?: string, isFatal?: boolean, category?: string, code?: number) => void;
|
type ErrorCallback = (message?: string, isFatal?: boolean, category?: string, code?: number) => void;
|
||||||
@ -436,8 +436,8 @@ declare namespace Realm.Sync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface ProgressPromise extends Promise<Realm> {
|
interface ProgressPromise extends Promise<Realm> {
|
||||||
progress(callback: Realm.Sync.ProgressNotificationCallback) : Promise<Realm>
|
progress(callback: Realm.Sync.ProgressNotificationCallback): Promise<Realm>
|
||||||
}
|
}
|
||||||
|
|
||||||
declare class Realm {
|
declare class Realm {
|
||||||
|
@ -39,6 +39,15 @@
|
|||||||
namespace realm {
|
namespace realm {
|
||||||
namespace js {
|
namespace js {
|
||||||
|
|
||||||
|
inline realm::SyncManager& syncManagerShared() {
|
||||||
|
static bool configured = []{
|
||||||
|
ensure_directory_exists_for_file(default_realm_file_directory());
|
||||||
|
SyncManager::shared().configure_file_system(default_realm_file_directory(), SyncManager::MetadataMode::NoEncryption);
|
||||||
|
return true;
|
||||||
|
}();
|
||||||
|
return SyncManager::shared();
|
||||||
|
}
|
||||||
|
|
||||||
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>;
|
||||||
|
|
||||||
@ -127,7 +136,7 @@ void UserClass<T>::create_user(ContextType ctx, FunctionType, ObjectType this_ob
|
|||||||
Value::validated_to_string(ctx, arguments[1], "identity"),
|
Value::validated_to_string(ctx, arguments[1], "identity"),
|
||||||
Value::validated_to_string(ctx, arguments[0], "authServerUrl")
|
Value::validated_to_string(ctx, arguments[0], "authServerUrl")
|
||||||
};
|
};
|
||||||
SharedUser *user = new SharedUser(SyncManager::shared().get_user(
|
SharedUser *user = new SharedUser(syncManagerShared().get_user(
|
||||||
userIdentifier,
|
userIdentifier,
|
||||||
Value::validated_to_string(ctx, arguments[2], "refreshToken")
|
Value::validated_to_string(ctx, arguments[2], "refreshToken")
|
||||||
));
|
));
|
||||||
@ -141,7 +150,7 @@ void UserClass<T>::create_user(ContextType ctx, FunctionType, ObjectType this_ob
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void UserClass<T>::admin_user(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
void UserClass<T>::admin_user(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||||
validate_argument_count(argc, 2, 2);
|
validate_argument_count(argc, 2, 2);
|
||||||
SharedUser *user = new SharedUser(SyncManager::shared().get_admin_token_user(
|
SharedUser *user = new SharedUser(syncManagerShared().get_admin_token_user(
|
||||||
Value::validated_to_string(ctx, arguments[0], "authServerUrl"),
|
Value::validated_to_string(ctx, arguments[0], "authServerUrl"),
|
||||||
Value::validated_to_string(ctx, arguments[1], "refreshToken")
|
Value::validated_to_string(ctx, arguments[1], "refreshToken")
|
||||||
));
|
));
|
||||||
@ -151,7 +160,7 @@ void UserClass<T>::admin_user(ContextType ctx, FunctionType, ObjectType this_obj
|
|||||||
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_logged_in_users()) {
|
for (auto user : syncManagerShared().all_logged_in_users()) {
|
||||||
if (user->token_type() == SyncUser::TokenType::Normal) {
|
if (user->token_type() == SyncUser::TokenType::Normal) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -537,10 +546,6 @@ 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
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,7 +560,7 @@ void SyncClass<T>::set_sync_log_level(ContextType ctx, FunctionType, ObjectType
|
|||||||
in >> log_level_2; // Throws
|
in >> log_level_2; // Throws
|
||||||
if (!in || !in.eof())
|
if (!in || !in.eof())
|
||||||
throw std::runtime_error("Bad log level");
|
throw std::runtime_error("Bad log level");
|
||||||
realm::SyncManager::shared().set_log_level(log_level_2);
|
syncManagerShared().set_log_level(log_level_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -639,7 +644,7 @@ void SyncClass<T>::populate_sync_config(ContextType ctx, ObjectType realm_constr
|
|||||||
|
|
||||||
|
|
||||||
config.schema_mode = SchemaMode::Additive;
|
config.schema_mode = SchemaMode::Additive;
|
||||||
config.path = realm::SyncManager::shared().path_for_realm(*shared_user, raw_realm_url);
|
config.path = syncManagerShared().path_for_realm(*shared_user, raw_realm_url);
|
||||||
|
|
||||||
if (!config.encryption_key.empty()) {
|
if (!config.encryption_key.empty()) {
|
||||||
config.sync_config->realm_encryption_key = std::array<char, 64>();
|
config.sync_config->realm_encryption_key = std::array<char, 64>();
|
||||||
|
@ -46,7 +46,6 @@ if (global.enableSyncTests) {
|
|||||||
// FIXME: Permission tests currently fail in chrome debugging mode.
|
// FIXME: Permission tests currently fail in chrome debugging mode.
|
||||||
if (typeof navigator === 'undefined' ||
|
if (typeof navigator === 'undefined' ||
|
||||||
!/Chrome/.test(navigator.userAgent)) { // eslint-disable-line no-undef
|
!/Chrome/.test(navigator.userAgent)) { // eslint-disable-line no-undef
|
||||||
|
|
||||||
//TESTS.PermissionTests = require('./permission-tests');
|
//TESTS.PermissionTests = require('./permission-tests');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user