diff --git a/plugin/src/ApiContext.lua b/plugin/src/ApiContext.lua index c6e89a93..2f094558 100644 --- a/plugin/src/ApiContext.lua +++ b/plugin/src/ApiContext.lua @@ -158,19 +158,35 @@ end function ApiContext:write(patch) local url = ("%s/api/write"):format(self.__baseUrl) - local body = { - sessionId = self.__sessionId, - removed = patch.removed, - updated = patch.updated, - } + local updated = {} + for _, update in ipairs(patch.updated) do + local fixedUpdate = { + id = update.id, + changedName = update.changedName, + } + + if next(update.changedProperties) ~= nil then + fixedUpdate.changedProperties = update.changedProperties + end + + table.insert(updated, fixedUpdate) + end -- Only add the 'added' field if the table is non-empty, or else Roblox's -- JSON implementation will turn the table into an array instead of an -- object, causing API validation to fail. + local added if next(patch.added) ~= nil then - body.added = patch.added + added = patch.added end + local body = { + sessionId = self.__sessionId, + removed = patch.removed, + updated = updated, + added = added, + } + body = Http.jsonEncode(body) return Http.post(url, body) diff --git a/src/web/interface.rs b/src/web/interface.rs index dc315ca7..d2b5cd52 100644 --- a/src/web/interface.rs +++ b/src/web/interface.rs @@ -34,8 +34,10 @@ pub struct InstanceUpdate { pub id: RbxId, pub changed_name: Option, pub changed_class_name: Option, + // TODO: Transform from HashMap> to something else, since // null will get lost when decoding from JSON in some languages. + #[serde(default)] pub changed_properties: HashMap>, pub changed_metadata: Option, }