Update object store

This commit is contained in:
blagoev 2017-08-16 18:11:46 +03:00 committed by Thomas Goyne
parent 614c699385
commit 736cbd3ef3
5 changed files with 41 additions and 29 deletions

View File

@ -49,6 +49,7 @@
"src/object-store/src/index_set.cpp", "src/object-store/src/index_set.cpp",
"src/object-store/src/list.cpp", "src/object-store/src/list.cpp",
"src/object-store/src/object.cpp", "src/object-store/src/object.cpp",
"src/object-store/src/placeholder.cpp",
"src/object-store/src/object_schema.cpp", "src/object-store/src/object_schema.cpp",
"src/object-store/src/object_store.cpp", "src/object-store/src/object_store.cpp",
"src/object-store/src/results.cpp", "src/object-store/src/results.cpp",
@ -66,6 +67,7 @@
"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/uuid.cpp",
], ],
"conditions": [ "conditions": [
["OS=='win'", { ["OS=='win'", {

View File

@ -14,6 +14,7 @@ if [ -f object-server-for-testing/node_modules/realm-object-server-developer/pac
fi fi
object_server_bundle="realm-object-server-bundled_node_darwin-developer-$REALM_OBJECT_SERVER_VERSION.tar.gz" object_server_bundle="realm-object-server-bundled_node_darwin-developer-$REALM_OBJECT_SERVER_VERSION.tar.gz"
echo "Downloading https://static.realm.io/downloads/object-server/$object_server_bundle"
curl -f -L "https://static.realm.io/downloads/object-server/$object_server_bundle" -o "$object_server_bundle" curl -f -L "https://static.realm.io/downloads/object-server/$object_server_bundle" -o "$object_server_bundle"
rm -rf object-server-for-testing rm -rf object-server-for-testing
mkdir object-server-for-testing mkdir object-server-for-testing

View File

@ -53,7 +53,7 @@ struct Schema {
template<typename T> template<typename T>
typename T::Object Schema<T>::dict_for_property_array(ContextType ctx, const ObjectSchema &object_schema, ObjectType array) { typename T::Object Schema<T>::dict_for_property_array(ContextType ctx, const ObjectSchema &object_schema, ObjectType array) {
size_t count = object_schema.persisted_properties.size(); size_t count = object_schema.persisted_properties.size();
if (count != Object::validated_get_length(ctx, array)) { if (count != Object::validated_get_length(ctx, array)) {
throw std::runtime_error("Array must contain values for all object properties"); throw std::runtime_error("Array must contain values for all object properties");
} }
@ -76,26 +76,32 @@ Property Schema<T>::parse_property(ContextType ctx, ValueType attributes, std::s
static const String object_type_string = "objectType"; static const String object_type_string = "objectType";
static const String optional_string = "optional"; static const String optional_string = "optional";
static const String property_string = "property"; static const String property_string = "property";
Property prop; Property prop;
prop.name = property_name; prop.name = property_name;
ObjectType property_object = {}; ObjectType property_object = {};
std::string type; std::string type;
if (Value::is_object(ctx, attributes)) { if (Value::is_object(ctx, attributes)) {
property_object = Value::validated_to_object(ctx, attributes); property_object = Value::validated_to_object(ctx, attributes);
type = Object::validated_get_string(ctx, property_object, type_string); type = Object::validated_get_string(ctx, property_object, type_string);
ValueType optional_value = Object::get_property(ctx, property_object, optional_string); ValueType optional_value = Object::get_property(ctx, property_object, optional_string);
if (!Value::is_undefined(ctx, optional_value)) { if (!Value::is_undefined(ctx, optional_value)) {
prop.is_nullable = Value::validated_to_boolean(ctx, optional_value, "optional"); auto isNullableValue = Value::validated_to_boolean(ctx, optional_value, "optional");
if (isNullableValue) {
prop.type |= realm::PropertyType::Nullable;
}
else {
prop.type &= ~realm::PropertyType::Nullable;
}
} }
} }
else { else {
type = Value::validated_to_string(ctx, attributes); type = Value::validated_to_string(ctx, attributes);
} }
if (type == "bool") { if (type == "bool") {
prop.type = realm::PropertyType::Bool; prop.type = realm::PropertyType::Bool;
} }
@ -135,8 +141,8 @@ Property Schema<T>::parse_property(ContextType ctx, ValueType attributes, std::s
} }
else if (type == "object") { else if (type == "object") {
prop.type = realm::PropertyType::Object; prop.type = realm::PropertyType::Object;
prop.is_nullable = true; prop.type |= realm::PropertyType::Nullable;
if (!Value::is_valid(property_object)) { if (!Value::is_valid(property_object)) {
throw std::runtime_error("Object property must specify 'objectType'"); throw std::runtime_error("Object property must specify 'objectType'");
} }
@ -145,22 +151,22 @@ Property Schema<T>::parse_property(ContextType ctx, ValueType attributes, std::s
else { else {
// The type could be the name of another object type in the same schema. // The type could be the name of another object type in the same schema.
prop.type = realm::PropertyType::Object; prop.type = realm::PropertyType::Object;
prop.is_nullable = true; prop.type |= realm::PropertyType::Nullable;
prop.object_type = type; prop.object_type = type;
} }
if (Value::is_valid(property_object)) { if (Value::is_valid(property_object)) {
ValueType default_value = Object::get_property(ctx, property_object, default_string); ValueType default_value = Object::get_property(ctx, property_object, default_string);
if (!Value::is_undefined(ctx, default_value)) { if (!Value::is_undefined(ctx, default_value)) {
object_defaults.emplace(prop.name, Protected<ValueType>(ctx, default_value)); object_defaults.emplace(prop.name, Protected<ValueType>(ctx, default_value));
} }
ValueType indexed_value = Object::get_property(ctx, property_object, indexed_string); ValueType indexed_value = Object::get_property(ctx, property_object, indexed_string);
if (!Value::is_undefined(ctx, indexed_value)) { if (!Value::is_undefined(ctx, indexed_value)) {
prop.is_indexed = Value::validated_to_boolean(ctx, indexed_value); prop.is_indexed = Value::validated_to_boolean(ctx, indexed_value);
} }
} }
return prop; return prop;
} }
@ -170,17 +176,17 @@ ObjectSchema Schema<T>::parse_object_schema(ContextType ctx, ObjectType object_s
static const String primary_string = "primaryKey"; static const String primary_string = "primaryKey";
static const String properties_string = "properties"; static const String properties_string = "properties";
static const String schema_string = "schema"; static const String schema_string = "schema";
FunctionType object_constructor = {}; FunctionType object_constructor = {};
if (Value::is_constructor(ctx, object_schema_object)) { if (Value::is_constructor(ctx, object_schema_object)) {
object_constructor = Value::to_constructor(ctx, object_schema_object); object_constructor = Value::to_constructor(ctx, object_schema_object);
object_schema_object = Object::validated_get_object(ctx, object_constructor, schema_string, "Realm object constructor must have a 'schema' property."); object_schema_object = Object::validated_get_object(ctx, object_constructor, schema_string, "Realm object constructor must have a 'schema' property.");
} }
ObjectDefaults object_defaults; ObjectDefaults object_defaults;
ObjectSchema object_schema; ObjectSchema object_schema;
object_schema.name = Object::validated_get_string(ctx, object_schema_object, name_string); object_schema.name = Object::validated_get_string(ctx, object_schema_object, name_string);
ObjectType properties_object = Object::validated_get_object(ctx, object_schema_object, properties_string, "ObjectSchema must have a 'properties' object."); ObjectType properties_object = Object::validated_get_object(ctx, object_schema_object, properties_string, "ObjectSchema must have a 'properties' object.");
if (Value::is_array(ctx, properties_object)) { if (Value::is_array(ctx, properties_object)) {
uint32_t length = Object::validated_get_length(ctx, properties_object); uint32_t length = Object::validated_get_length(ctx, properties_object);
@ -194,7 +200,7 @@ ObjectSchema Schema<T>::parse_object_schema(ContextType ctx, ObjectType object_s
else { else {
object_schema.persisted_properties.emplace_back(std::move(property)); object_schema.persisted_properties.emplace_back(std::move(property));
} }
} }
} }
else { else {
@ -220,14 +226,14 @@ ObjectSchema Schema<T>::parse_object_schema(ContextType ctx, ObjectType object_s
} }
property->is_primary = true; property->is_primary = true;
} }
// Store prototype so that objects of this type will have their prototype set to this prototype object. // Store prototype so that objects of this type will have their prototype set to this prototype object.
if (Value::is_valid(object_constructor)) { if (Value::is_valid(object_constructor)) {
constructors.emplace(object_schema.name, Protected<FunctionType>(ctx, object_constructor)); constructors.emplace(object_schema.name, Protected<FunctionType>(ctx, object_constructor));
} }
defaults.emplace(object_schema.name, std::move(object_defaults)); defaults.emplace(object_schema.name, std::move(object_defaults));
return object_schema; return object_schema;
} }
@ -308,7 +314,7 @@ typename T::Object Schema<T>::object_for_property(ContextType ctx, const Propert
} }
static const String optional_string = "optional"; static const String optional_string = "optional";
if (property.is_nullable) { if (is_nullable(property.type)) {
Object::set_property(ctx, object, optional_string, Value::from_boolean(ctx, true)); Object::set_property(ctx, object, optional_string, Value::from_boolean(ctx, true));
} }

View File

@ -119,11 +119,14 @@ void UserClass<T>::is_admin(ContextType ctx, ObjectType object, ReturnValue &ret
template<typename T> template<typename T>
void UserClass<T>::create_user(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { void UserClass<T>::create_user(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
validate_argument_count(argc, 3, 5); validate_argument_count(argc, 3, 5);
SyncUserIdentifier userIdentifier {
(std::string)Value::validated_to_string(ctx, arguments[1], "identity"),
(std::string)Value::validated_to_string(ctx, arguments[0], "authServerUrl")
};
SharedUser *user = new SharedUser(SyncManager::shared().get_user( SharedUser *user = new SharedUser(SyncManager::shared().get_user(
Value::validated_to_string(ctx, arguments[1], "identity"), userIdentifier,
Value::validated_to_string(ctx, arguments[2], "refreshToken"), (std::string)Value::validated_to_string(ctx, arguments[2], "refreshToken")
(std::string)Value::validated_to_string(ctx, arguments[0], "authServerUrl"), ));
Value::validated_to_boolean(ctx, arguments[3], "isAdminToken") ? SyncUser::TokenType::Admin : SyncUser::TokenType::Normal));
if (argc == 5) { if (argc == 5) {
(*user)->set_is_admin(Value::validated_to_boolean(ctx, arguments[4], "isAdmin")); (*user)->set_is_admin(Value::validated_to_boolean(ctx, arguments[4], "isAdmin"));
@ -432,7 +435,7 @@ void SyncClass<T>::populate_sync_config(ContextType ctx, ObjectType realm_constr
nullptr, util::none, nullptr, util::none,
client_validate_ssl, ssl_trust_certificate_path}); client_validate_ssl, ssl_trust_certificate_path});
config.schema_mode = SchemaMode::Additive; config.schema_mode = SchemaMode::Additive;
config.path = realm::SyncManager::shared().path_for_realm(shared_user->identity(), raw_realm_url); config.path = realm::SyncManager::shared().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>();

View File

@ -83,10 +83,10 @@ public:
std::string const& prefix() const { return m_prefix; } std::string const& prefix() const { return m_prefix; }
std::string const& type() const { return m_type; } std::string const& type() const { return m_type; }
TypeErrorException(std::string prefix, std::string type) : TypeErrorException(std::string prefix, std::string type) :
std::invalid_argument(prefix + " must be of type: " + type), std::invalid_argument(prefix + " must be of type: " + type),
m_prefix(std::move(prefix)), m_prefix(std::move(prefix)),
m_type(std::move(type)) m_type(std::move(type))
{} {}
private: private:
@ -352,7 +352,7 @@ REALM_JS_INLINE void set_internal(const typename T::Object &object, typename Cla
template<typename T> template<typename T>
inline bool Value<T>::is_valid_for_property(ContextType context, const ValueType &value, const Property& prop) inline bool Value<T>::is_valid_for_property(ContextType context, const ValueType &value, const Property& prop)
{ {
if (prop.is_nullable && (is_null(context, value) || is_undefined(context, value))) { if (is_nullable(prop.type) && (is_null(context, value) || is_undefined(context, value))) {
return true; return true;
} }