From 79f09deecb584ac58a7808267a8ec5a45115a22f Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Tue, 1 Oct 2019 18:37:35 -0700 Subject: [PATCH] Add strong type checking to plugin API client --- plugin/src/ApiContext.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugin/src/ApiContext.lua b/plugin/src/ApiContext.lua index 930ca2f3..4501e7c8 100644 --- a/plugin/src/ApiContext.lua +++ b/plugin/src/ApiContext.lua @@ -3,6 +3,11 @@ local Http = require(script.Parent.Parent.Http) local Config = require(script.Parent.Config) 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 = {} ApiContext.__index = ApiContext @@ -82,6 +87,8 @@ function ApiContext:connect() return Promise.reject(message) end + assert(validateApiInfo(body)) + if body.expectedPlaceIds ~= nil then local foundId = false @@ -130,6 +137,8 @@ function ApiContext:read(ids) return Promise.reject("Server changed ID") end + assert(validateApiRead(body)) + self.messageCursor = body.messageCursor return body @@ -159,6 +168,8 @@ function ApiContext:retrieveMessages() return Promise.reject("Server changed ID") end + assert(validateApiSubscribe(body)) + self.messageCursor = body.messageCursor return body.messages