mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-22 13:21:38 +00:00
Add strong type checking to plugin API client
This commit is contained in:
parent
c4a7f8675f
commit
79f09deecb
1 changed files with 11 additions and 0 deletions
|
|
@ -3,6 +3,11 @@ local Http = require(script.Parent.Parent.Http)
|
||||||
|
|
||||||
local Config = require(script.Parent.Config)
|
local Config = require(script.Parent.Config)
|
||||||
local Version = require(script.Parent.Version)
|
local Version = require(script.Parent.Version)
|
||||||
|
local Types = require(script.Parent.Types)
|
||||||
|
|
||||||
|
local validateApiInfo = Types.ifEnabled(Types.ApiInfoResponse)
|
||||||
|
local validateApiRead = Types.ifEnabled(Types.ApiReadResponse)
|
||||||
|
local validateApiSubscribe = Types.ifEnabled(Types.ApiSubscribeResponse)
|
||||||
|
|
||||||
local ApiContext = {}
|
local ApiContext = {}
|
||||||
ApiContext.__index = ApiContext
|
ApiContext.__index = ApiContext
|
||||||
|
|
@ -82,6 +87,8 @@ function ApiContext:connect()
|
||||||
return Promise.reject(message)
|
return Promise.reject(message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assert(validateApiInfo(body))
|
||||||
|
|
||||||
if body.expectedPlaceIds ~= nil then
|
if body.expectedPlaceIds ~= nil then
|
||||||
local foundId = false
|
local foundId = false
|
||||||
|
|
||||||
|
|
@ -130,6 +137,8 @@ function ApiContext:read(ids)
|
||||||
return Promise.reject("Server changed ID")
|
return Promise.reject("Server changed ID")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assert(validateApiRead(body))
|
||||||
|
|
||||||
self.messageCursor = body.messageCursor
|
self.messageCursor = body.messageCursor
|
||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
@ -159,6 +168,8 @@ function ApiContext:retrieveMessages()
|
||||||
return Promise.reject("Server changed ID")
|
return Promise.reject("Server changed ID")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assert(validateApiSubscribe(body))
|
||||||
|
|
||||||
self.messageCursor = body.messageCursor
|
self.messageCursor = body.messageCursor
|
||||||
|
|
||||||
return body.messages
|
return body.messages
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue