From b554d73eeabb96f23385b7b093d5609ff6105e99 Mon Sep 17 00:00:00 2001 From: amelia squires Date: Mon, 31 Mar 2025 13:21:27 -0500 Subject: type definitions --- library/lullaby/net.lua | 166 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 library/lullaby/net.lua (limited to 'library/lullaby/net.lua') diff --git a/library/lullaby/net.lua b/library/lullaby/net.lua new file mode 100644 index 0000000..3f9abdc --- /dev/null +++ b/library/lullaby/net.lua @@ -0,0 +1,166 @@ +---@meta + +---@class net +local net = {} + +---@class server-table +local server_table = {} + +---@class res-table +local res_table = {} + +---sends value to client and closes socket +---@param T res-table +---@param value string +function res_table.send(T, value) end + +---autosets Content-Type and sends contents of file to client and closes socket +---@param T res-table +---@param value string +function res_table.sendfile(T, value) end + +---sends value to client and doesn't close the socket +---@param T res-table +---@param value string +function res_table.write(T, value) end + +---closes socket +---@param T res-table +function res_table.close(T) end + +---prevents calling any other selected routes +---@param T res-table +function res_table.stop(T) end + +---key value table containing header values to be sent +res_table.header = {} + +---@class req-table +local req_table = {} + +---"roll" the request forward +---@param T req-table +---@param bytes integer | nil +function req_table.roll(T, bytes) end + +---list of parameters in route +req_table.parameters = {} + +---@deprecated +req_table.client_fd = 0 + +---@deprecated +req_table._bytes = 0 + +---@type integer +req_table.ip = 0 + +---@type string +req_table.Body = "" + +---@type any|nil +req_table.files = {} + +---@type any|nil +req_table.cookies = {} + + +---@param T server-table +---@param route string +---@param callback fun(res: res-table, req: req-table) +function server_table.GET(T, route, callback) end + +---@param T server-table +---@param route string +---@param callback fun(res: res-table, req: req-table) +function server_table.HEAD(T, route, callback) end + +---@param T server-table +---@param route string +---@param callback fun(res: res-table, req: req-table) +function server_table.POST(T, route, callback) end + +---@param T server-table +---@param route string +---@param callback fun(res: res-table, req: req-table) +function server_table.PUT(T, route, callback) end + +---@param T server-table +---@param route string +---@param callback fun(res: res-table, req: req-table) +function server_table.DELETE(T, route, callback) end + +---@param T server-table +---@param route string +---@param callback fun(res: res-table, req: req-table) +function server_table.CONNECT(T, route, callback) end + +---@param T server-table +---@param route string +---@param callback fun(res: res-table, req: req-table) +function server_table.OPTIONS(T, route, callback) end + +---@param T server-table +---@param route string +---@param callback fun(res: res-table, req: req-table) +function server_table.TRACE(T, route, callback) end + +---@param T server-table +---@param route string +---@param callback fun(res: res-table, req: req-table) +function server_table.PATCH(T, route, callback) end + +---@param T server-table +---@param route string +---@param callback fun(res: res-table, req: req-table) +function server_table.all(T, route, callback) end + +---@param server server-table +local function listen_callback(server) end + +---@param callback fun(server: server-table) +---@param port integer +function net.listen(callback, port) end + +---creates an https request +---@param url string +---@param value string | nil +---@param header table | nil +---@param request string | nil +---@return table | error +function net.srequest(url, value, header, request) end + +---@class wss-table +local wss = {} + +---@class wss-read +local wss_read = {} + +---@type string +wss_read.content = "" + +---@type integer +wss_read.opcode = 0 + +---reads oldest unread frame from server +---@param T wss-table +---@return wss-read | error +function wss.read(T) end + +---sents data frame to server +---@param T wss-table +---@param data string +---@return nil | error +function wss.write(T, data) end + +---calls gc early +---@param T wss-table +---@return nil +function wss.close(T) end + +---creates a wss connection +---@param url string +---@return wss-table | error +function net.wss(url) end + +return net -- cgit v1.2.3