mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-17 09:06:26 +00:00
support getting the schema version from unopened realms
This commit is contained in:
parent
071a65b449
commit
324c3d702b
@ -149,6 +149,13 @@ static bool SetDefaultPath(JSContextRef ctx, JSObjectRef object, JSStringRef pro
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::string RJSNormalizePath(std::string path) {
|
||||||
|
if (path.size() && path[0] != '/') {
|
||||||
|
return default_realm_file_directory() + "/" + path;
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
JSObjectRef RealmConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) {
|
JSObjectRef RealmConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) {
|
||||||
try {
|
try {
|
||||||
Realm::Config config;
|
Realm::Config config;
|
||||||
@ -202,9 +209,7 @@ JSObjectRef RealmConstructor(JSContextRef ctx, JSObjectRef constructor, size_t a
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.path.size() && config.path[0] != '/') {
|
config.path = RJSNormalizePath(config.path);
|
||||||
config.path = default_realm_file_directory() + "/" + config.path;
|
|
||||||
}
|
|
||||||
|
|
||||||
ensure_directory_exists_for_file(config.path);
|
ensure_directory_exists_for_file(config.path);
|
||||||
SharedRealm realm = Realm::get_shared_realm(config);
|
SharedRealm realm = Realm::get_shared_realm(config);
|
||||||
@ -232,6 +237,27 @@ static const JSStaticValue RealmStaticProperties[] = {
|
|||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
JSValueRef RealmSchemaVersion(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) {
|
||||||
|
try {
|
||||||
|
RJSValidateArgumentCount(argumentCount, 1);
|
||||||
|
|
||||||
|
Realm::Config config;
|
||||||
|
config.path = RJSNormalizePath(RJSValidatedStringForValue(ctx, arguments[0]));
|
||||||
|
return JSValueMakeNumber(ctx, Realm::get_schema_version(config));
|
||||||
|
}
|
||||||
|
catch (std::exception &exp) {
|
||||||
|
if (jsException) {
|
||||||
|
*jsException = RJSMakeError(ctx, exp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const JSStaticFunction RealmConstructorFuncs[] = {
|
||||||
|
{"schemaVersion", RealmSchemaVersion, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
|
||||||
|
{NULL, NULL},
|
||||||
|
};
|
||||||
|
|
||||||
JSClassRef RJSRealmConstructorClass() {
|
JSClassRef RJSRealmConstructorClass() {
|
||||||
JSClassDefinition realmConstructorDefinition = kJSClassDefinitionEmpty;
|
JSClassDefinition realmConstructorDefinition = kJSClassDefinitionEmpty;
|
||||||
realmConstructorDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
|
realmConstructorDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
|
||||||
@ -239,6 +265,7 @@ JSClassRef RJSRealmConstructorClass() {
|
|||||||
realmConstructorDefinition.callAsConstructor = RealmConstructor;
|
realmConstructorDefinition.callAsConstructor = RealmConstructor;
|
||||||
realmConstructorDefinition.hasInstance = RealmHasInstance;
|
realmConstructorDefinition.hasInstance = RealmHasInstance;
|
||||||
realmConstructorDefinition.staticValues = RealmStaticProperties;
|
realmConstructorDefinition.staticValues = RealmStaticProperties;
|
||||||
|
realmConstructorDefinition.staticFunctions = RealmConstructorFuncs;
|
||||||
return JSClassCreate(&realmConstructorDefinition);
|
return JSClassCreate(&realmConstructorDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user