Upgrade to rbx_dom_weak 2.0 (#377)

* Mostly mechanical port bits

* Almost there

* It builds again!

* Turn on all the code again

* Tests compiling but not passing

* Stub work for value resolution

* Implement resolution minus enums and derived properties

* Implement property descriptor resolution

* Update referent snapshots

* Update unions test project

Using a place file instead of a model yields better
error messages in Roblox Studio.

* Add easy shortcut to testing with local rbx-dom

* Update rbx-dom

* Add enum resolution

* Update init.meta.json to use UnresolvedValue

* Expand value resolution support, add test

* Filter SharedString values from web API

* Add 'property' builder method to InstanceSnapshot

* Change InstanceSnapshot/InstanceBuilder boundary

* Fix remove_file crash

* rustfmt

* Update to latest rbx_dom_lua

* Update dependencies, including rbx_dom_weak

* Update to latest rbx-dom

* Update dependencies

* Update rbx-dom, fixing more bugs

* Remove experimental warning on binary place builds

* Remove unused imports
This commit is contained in:
Lucien Greathouse
2021-02-18 20:56:09 -05:00
committed by GitHub
parent b84aab0960
commit 59ef5f05ea
63 changed files with 45602 additions and 21004 deletions

View File

@@ -1,12 +1,12 @@
//! Defines Rojo's HTTP API, all under /api. These endpoints generally return
//! JSON.
use std::{collections::HashMap, fs, path::PathBuf, sync::Arc};
use std::{collections::HashMap, fs, path::PathBuf, str::FromStr, sync::Arc};
use futures::{Future, Stream};
use hyper::{service::Service, Body, Method, Request, StatusCode};
use rbx_dom_weak::RbxId;
use rbx_dom_weak::types::Ref;
use crate::{
serve_session::ServeSession,
@@ -200,11 +200,11 @@ impl ApiService {
fn handle_api_read(&self, request: Request<Body>) -> <Self as Service>::Future {
let argument = &request.uri().path()["/api/read/".len()..];
let requested_ids: Option<Vec<RbxId>> = argument.split(',').map(RbxId::parse_str).collect();
let requested_ids: Result<Vec<Ref>, _> = argument.split(',').map(Ref::from_str).collect();
let requested_ids = match requested_ids {
Some(ids) => ids,
None => {
Ok(ids) => ids,
Err(_) => {
return json(
ErrorResponse::bad_request("Malformed ID list"),
StatusCode::BAD_REQUEST,
@@ -239,9 +239,9 @@ impl ApiService {
/// Open a script with the given ID in the user's default text editor.
fn handle_api_open(&self, request: Request<Body>) -> <Self as Service>::Future {
let argument = &request.uri().path()["/api/open/".len()..];
let requested_id = match RbxId::parse_str(argument) {
Some(id) => id,
None => {
let requested_id = match Ref::from_str(argument) {
Ok(id) => id,
Err(_) => {
return json(
ErrorResponse::bad_request("Invalid instance ID"),
StatusCode::BAD_REQUEST,

View File

@@ -5,7 +5,7 @@ use std::{
collections::{HashMap, HashSet},
};
use rbx_dom_weak::{RbxId, RbxValue};
use rbx_dom_weak::types::{Ref, Variant};
use serde::{Deserialize, Serialize};
use crate::{
@@ -23,22 +23,22 @@ pub const PROTOCOL_VERSION: u64 = 3;
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubscribeMessage<'a> {
pub removed: Vec<RbxId>,
pub added: HashMap<RbxId, Instance<'a>>,
pub removed: Vec<Ref>,
pub added: HashMap<Ref, Instance<'a>>,
pub updated: Vec<InstanceUpdate>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InstanceUpdate {
pub id: RbxId,
pub id: Ref,
pub changed_name: Option<String>,
pub changed_class_name: Option<String>,
// TODO: Transform from HashMap<String, Option<_>> to something else, since
// null will get lost when decoding from JSON in some languages.
#[serde(default)]
pub changed_properties: HashMap<String, Option<RbxValue>>,
pub changed_properties: HashMap<String, Option<Variant>>,
pub changed_metadata: Option<InstanceMetadata>,
}
@@ -59,23 +59,36 @@ impl InstanceMetadata {
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct Instance<'a> {
pub id: RbxId,
pub parent: Option<RbxId>,
pub id: Ref,
pub parent: Ref,
pub name: Cow<'a, str>,
pub class_name: Cow<'a, str>,
pub properties: Cow<'a, HashMap<String, RbxValue>>,
pub children: Cow<'a, [RbxId]>,
pub properties: HashMap<String, Cow<'a, Variant>>,
pub children: Cow<'a, [Ref]>,
pub metadata: Option<InstanceMetadata>,
}
impl<'a> Instance<'a> {
pub(crate) fn from_rojo_instance(source: InstanceWithMeta<'_>) -> Instance<'_> {
let properties = source
.properties()
.iter()
.filter_map(|(key, value)| {
// SharedString values can't be serialized via Serde
if matches!(value, Variant::SharedString(_)) {
return None;
}
Some((key.clone(), Cow::Borrowed(value)))
})
.collect();
Instance {
id: source.id(),
parent: source.parent(),
name: Cow::Borrowed(source.name()),
class_name: Cow::Borrowed(source.class_name()),
properties: Cow::Borrowed(source.properties()),
properties,
children: Cow::Borrowed(source.children()),
metadata: Some(InstanceMetadata::from_rojo_metadata(source.metadata())),
}
@@ -91,7 +104,7 @@ pub struct ServerInfoResponse {
pub protocol_version: u64,
pub project_name: String,
pub expected_place_ids: Option<HashSet<u64>>,
pub root_instance_id: RbxId,
pub root_instance_id: Ref,
}
/// Response body from /api/read/{id}
@@ -100,17 +113,17 @@ pub struct ServerInfoResponse {
pub struct ReadResponse<'a> {
pub session_id: SessionId,
pub message_cursor: u32,
pub instances: HashMap<RbxId, Instance<'a>>,
pub instances: HashMap<Ref, Instance<'a>>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WriteRequest {
pub session_id: SessionId,
pub removed: Vec<RbxId>,
pub removed: Vec<Ref>,
#[serde(default)]
pub added: HashMap<RbxId, ()>,
pub added: HashMap<Ref, ()>,
pub updated: Vec<InstanceUpdate>,
}

View File

@@ -5,7 +5,7 @@ use std::{borrow::Cow, sync::Arc, time::Duration};
use futures::{future, Future};
use hyper::{header, service::Service, Body, Method, Request, Response, StatusCode};
use maplit::hashmap;
use rbx_dom_weak::{RbxId, RbxValue};
use rbx_dom_weak::types::{Ref, Variant};
use ritz::{html, Fragment, HtmlContent, HtmlSelfClosingTag};
use crate::{
@@ -93,7 +93,7 @@ impl UiService {
.unwrap()
}
fn instance(tree: &RojoTree, id: RbxId) -> HtmlContent<'_> {
fn instance(tree: &RojoTree, id: Ref) -> HtmlContent<'_> {
let instance = tree.get_instance(id).unwrap();
let children_list: Vec<_> = instance
.children()
@@ -126,7 +126,7 @@ impl UiService {
.map(|(key, value)| {
html! {
<div class="instance-property" title={ Self::display_value(value) }>
{ key.clone() } ": " { format!("{:?}", value.get_type()) }
{ key.clone() } ": " { format!("{:?}", value.ty()) }
</div>
}
})
@@ -198,7 +198,7 @@ impl UiService {
html! {
<div class="instance">
<label class="instance-title" for={ format!("instance-{}", id) }>
<label class="instance-title" for={ format!("instance-{:?}", id) }>
{ instance.name().to_owned() }
{ class_name_specifier }
</label>
@@ -209,10 +209,10 @@ impl UiService {
}
}
fn display_value(value: &RbxValue) -> String {
fn display_value(value: &Variant) -> String {
match value {
RbxValue::String { value } => value.clone(),
RbxValue::Bool { value } => value.to_string(),
Variant::String(value) => value.clone(),
Variant::Bool(value) => value.to_string(),
_ => format!("{:?}", value),
}
}
@@ -288,14 +288,14 @@ impl UiService {
struct ExpandableSection<'a> {
title: &'a str,
class_name: &'a str,
id: RbxId,
id: Ref,
expanded: bool,
content: HtmlContent<'a>,
}
impl<'a> ExpandableSection<'a> {
fn render(self) -> HtmlContent<'a> {
let input_id = format!("{}-{}", self.class_name, self.id);
let input_id = format!("{}-{:?}", self.class_name, self.id);
// We need to specify this input manually because Ritz doesn't have
// support for conditional attributes like `checked`.