Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track patch sources, make the plugin ignore its own changes #479

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion plugin/http/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ function Http.jsonDecode(source)
return HttpService:JSONDecode(source)
end

return Http
function Http.generateGuid()
return HttpService:GenerateGUID(false):lower()
end

return Http
5 changes: 4 additions & 1 deletion plugin/src/ApiContext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ function ApiContext.new(baseUrl)
assert(type(baseUrl) == "string")

local self = {
clientId = Http.generateGuid(),

__baseUrl = baseUrl,
__sessionId = nil,
__messageCursor = -1,
Expand Down Expand Up @@ -182,6 +184,7 @@ function ApiContext:write(patch)

local body = {
sessionId = self.__sessionId,
source = self.clientId,
removed = patch.removed,
updated = updated,
added = added,
Expand Down Expand Up @@ -248,4 +251,4 @@ function ApiContext:open(id)
end)
end

return ApiContext
return ApiContext
6 changes: 5 additions & 1 deletion plugin/src/ServeSession.lua
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ function ServeSession:__mainSyncLoop()
return self.__apiContext:retrieveMessages()
:andThen(function(messages)
for _, message in ipairs(messages) do
if message.source == self.__apiContext.clientId then
continue
end

local unappliedPatch = self.__reconciler:applyPatch(message)

if not PatchSet.isEmpty(unappliedPatch) then
Expand Down Expand Up @@ -305,4 +309,4 @@ function ServeSession:__setStatus(status, detail)
end
end

return ServeSession
return ServeSession
2 changes: 2 additions & 0 deletions plugin/src/Types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ local ApiInstanceUpdate = t.interface({
})

local ApiSubscribeMessage = t.interface({
source = t.string,
removed = t.array(RbxId),
added = t.map(RbxId, ApiInstance),
updated = t.array(ApiInstanceUpdate),
})

local ApiInfoResponse = t.interface({
sessionId = t.string,
serverId = t.string,
serverVersion = t.string,
protocolVersion = t.number,
expectedPlaceIds = t.optional(t.array(t.number)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
---
source: tests/tests/serve.rs
expression: "read_response.intern_and_redact(&mut redactions, root_id)"

---
instances:
id-2:
id-3:
Children:
- id-3
- id-4
ClassName: Folder
Id: id-2
Id: id-3
Metadata:
ignoreUnknownInstances: false
Name: add_folder
Parent: "00000000000000000000000000000000"
Properties: {}
id-3:
id-4:
Children: []
ClassName: Folder
Id: id-3
Id: id-4
Metadata:
ignoreUnknownInstances: false
Name: my-new-folder
Parent: id-2
Parent: id-3
Properties: {}
messageCursor: 1
sessionId: id-1

Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
---
source: tests/tests/serve.rs
expression: "read_response.intern_and_redact(&mut redactions, root_id)"

---
instances:
id-2:
id-3:
Children: []
ClassName: Folder
Id: id-2
Id: id-3
Metadata:
ignoreUnknownInstances: false
Name: add_folder
Parent: "00000000000000000000000000000000"
Properties: {}
messageCursor: 0
sessionId: id-1

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ gameId: ~
placeId: ~
projectName: add_folder
protocolVersion: 4
rootInstanceId: id-2
rootInstanceId: id-3
serverId: id-2
serverVersion: "[server-version]"
sessionId: id-1

Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
---
source: tests/tests/serve.rs
expression: "subscribe_response.intern_and_redact(&mut redactions, ())"

---
messageCursor: 1
messages:
- added:
id-3:
id-4:
Children: []
ClassName: Folder
Id: id-3
Id: id-4
Metadata:
ignoreUnknownInstances: false
Name: my-new-folder
Parent: id-2
Parent: id-3
Properties: {}
removed: []
source: id-2
updated: []
sessionId: id-1

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ expression: "read_response.intern_and_redact(&mut redactions, root_id)"

---
instances:
id-2:
id-3:
Children: []
ClassName: ModuleScript
Id: id-2
Id: id-3
Metadata:
ignoreUnknownInstances: false
Name: edit_init
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ expression: "read_response.intern_and_redact(&mut redactions, root_id)"

---
instances:
id-2:
id-3:
Children: []
ClassName: ModuleScript
Id: id-2
Id: id-3
Metadata:
ignoreUnknownInstances: false
Name: edit_init
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ gameId: ~
placeId: ~
projectName: edit_init
protocolVersion: 4
rootInstanceId: id-2
rootInstanceId: id-3
serverId: id-2
serverVersion: "[server-version]"
sessionId: id-1

Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ messageCursor: 1
messages:
- added: {}
removed: []
source: id-2
updated:
- changedClassName: ~
changedMetadata: ~
changedName: ~
changedProperties:
Source:
String: "-- Edited contents"
id: id-2
id: id-3
sessionId: id-1

Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
---
source: tests/tests/serve.rs
expression: "read_response.intern_and_redact(&mut redactions, root_id)"

---
instances:
id-2:
id-3:
Children: []
ClassName: Folder
Id: id-2
Id: id-3
Metadata:
ignoreUnknownInstances: true
Name: empty
Parent: "00000000000000000000000000000000"
Properties: {}
messageCursor: 0
sessionId: id-1

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ gameId: ~
placeId: ~
projectName: empty
protocolVersion: 4
rootInstanceId: id-2
rootInstanceId: id-3
serverId: id-2
serverVersion: "[server-version]"
sessionId: id-1

Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ expression: "read_response.intern_and_redact(&mut redactions, root_id)"

---
instances:
id-2:
id-3:
Children:
- id-3
- id-4
ClassName: Folder
Id: id-2
Id: id-3
Metadata:
ignoreUnknownInstances: false
Name: empty_folder
Parent: "00000000000000000000000000000000"
Properties: {}
id-3:
id-4:
Children: []
ClassName: Model
Id: id-3
Id: id-4
Metadata:
ignoreUnknownInstances: false
Name: test
Parent: id-2
Parent: id-3
Properties: {}
messageCursor: 1
sessionId: id-1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ expression: "read_response.intern_and_redact(&mut redactions, root_id)"

---
instances:
id-2:
id-3:
Children: []
ClassName: Folder
Id: id-2
Id: id-3
Metadata:
ignoreUnknownInstances: false
Name: empty_folder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ gameId: ~
placeId: ~
projectName: empty_folder
protocolVersion: 4
rootInstanceId: id-2
rootInstanceId: id-3
serverId: id-2
serverVersion: "[server-version]"
sessionId: id-1

Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ expression: "subscribe_response.intern_and_redact(&mut redactions, ())"
messageCursor: 1
messages:
- added:
id-3:
id-4:
Children: []
ClassName: Model
Id: id-3
Id: id-4
Metadata:
ignoreUnknownInstances: false
Name: test
Parent: id-2
Parent: id-3
Properties: {}
removed: []
source: id-2
updated: []
sessionId: id-1

Loading