mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 14:54:33 +00:00
Support getting all properties except for Lists
There's a big fat TODO left for that one!
This commit is contained in:
parent
e136da5117
commit
6d850cba5e
@ -96,8 +96,7 @@ static RPCObjectID s_id_counter = 0;
|
|||||||
return @{@"error": @(RJSStringForValue(s_context, exception).c_str())};
|
return @{@"error": @(RJSStringForValue(s_context, exception).c_str())};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Convert propertyValue to appropriate type!
|
return @{@"result": [self resultForJSValue:propertyValue]};
|
||||||
return @{};
|
|
||||||
};
|
};
|
||||||
s_requests["/set_property"] = [=](NSDictionary *dict) {
|
s_requests["/set_property"] = [=](NSDictionary *dict) {
|
||||||
JSValueRef exception = NULL;
|
JSValueRef exception = NULL;
|
||||||
@ -157,18 +156,7 @@ static RPCObjectID s_id_counter = 0;
|
|||||||
return @{@"error": @(RJSStringForValue(s_context, exception).c_str())};
|
return @{@"error": @(RJSStringForValue(s_context, exception).c_str())};
|
||||||
}
|
}
|
||||||
|
|
||||||
RPCObjectID newOid = s_id_counter++;
|
return @{@"result": [self resultForJSValue:objectValue]};
|
||||||
JSValueProtect(s_context, objectValue);
|
|
||||||
s_objects[newOid] = (JSObjectRef)objectValue;
|
|
||||||
|
|
||||||
realm::Object *object = RJSGetInternal<realm::Object *>((JSObjectRef)objectValue);
|
|
||||||
return @{
|
|
||||||
@"result": @{
|
|
||||||
@"type": @(RJSTypeGet(realm::PropertyTypeObject).c_str()),
|
|
||||||
@"id": @(newOid),
|
|
||||||
@"schema": [self schemaForObject:object],
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add a handler to respond to GET requests on any URL
|
// Add a handler to respond to GET requests on any URL
|
||||||
@ -184,6 +172,36 @@ static RPCObjectID s_id_counter = 0;
|
|||||||
[webServer startWithPort:8082 bonjourName:nil];
|
[webServer startWithPort:8082 bonjourName:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (NSDictionary *)resultForJSValue:(JSValueRef)value {
|
||||||
|
switch (JSValueGetType(s_context, value)) {
|
||||||
|
case kJSTypeUndefined:
|
||||||
|
return @{};
|
||||||
|
case kJSTypeNull:
|
||||||
|
return @{@"value": [NSNull null]};
|
||||||
|
case kJSTypeBoolean:
|
||||||
|
return @{@"value": @(JSValueToBoolean(s_context, value))};
|
||||||
|
case kJSTypeNumber:
|
||||||
|
return @{@"value": @(JSValueToNumber(s_context, value, NULL))};
|
||||||
|
case kJSTypeString:
|
||||||
|
return @{@"value": @(RJSStringForValue(s_context, value).c_str())};
|
||||||
|
case kJSTypeObject:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
RPCObjectID newOid = s_id_counter++;
|
||||||
|
JSValueProtect(s_context, value);
|
||||||
|
s_objects[newOid] = (JSObjectRef)value;
|
||||||
|
|
||||||
|
// TODO: Check for List object!
|
||||||
|
|
||||||
|
realm::Object *object = RJSGetInternal<realm::Object *>((JSObjectRef)value);
|
||||||
|
return @{
|
||||||
|
@"type": @(RJSTypeGet(realm::PropertyTypeObject).c_str()),
|
||||||
|
@"id": @(newOid),
|
||||||
|
@"schema": [self schemaForObject:object],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
+ (NSDictionary *)schemaForObject:(realm::Object *)object {
|
+ (NSDictionary *)schemaForObject:(realm::Object *)object {
|
||||||
realm::ObjectSchema &objectSchema = object->object_schema;
|
realm::ObjectSchema &objectSchema = object->object_schema;
|
||||||
NSMutableArray *properties = [[NSMutableArray alloc] init];
|
NSMutableArray *properties = [[NSMutableArray alloc] init];
|
||||||
@ -204,6 +222,3 @@ static RPCObjectID s_id_counter = 0;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user