Skip to content

Commit

Permalink
add lua language server annotations
Browse files Browse the repository at this point in the history
- req.valid for validator middleware
- req.body and req.bodydata for body-parser
- req.cookies for cookie-parser
  • Loading branch information
AMD-NICK committed Dec 11, 2023
1 parent 873e568 commit 4a9e198
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lua/body-parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ local function parse_query_string(str)
return params
end

--- @class ExpressRequest
--- @field bodydata string | nil raw body data
--- @field body table | nil parsed body data

--- @return fun(req: ExpressRequest, res: ExpressResponse, next: fun(err?: any))
function bodyparser.urlencoded(opts)
local typ = opts and opts.type or "application/x-www-form-urlencoded"

Expand Down
4 changes: 4 additions & 0 deletions lua/cookie-parser.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
--- @usage
--- local cookie_parser = require("cookie-parser")
--- app:use(cookie_parser())

--- @class ExpressRequest
--- @field cookies table | nil -- table of parsed cookies

return function(opts)
-- todo? signed cookies

Expand Down
6 changes: 6 additions & 0 deletions lua/validator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,15 @@ local function validate_all(params_rules, params_values, messages)
return formatted_values, nil
end

--- @class ExpressRequest
--- @field valid table | nil validated parameters by [validator middleware](https://github.com/TRIGONIM/lua-express-middlewares)

-- Извлекает параметры из запроса в соответствии с правилами и проверяет их
-- Если указан messages, то в случае ошибки будет использовано сообщение из него
local function express_middleware(params_with_rules, messages) -- messages may be nil
--- @param req ExpressRequest
--- @param _ ExpressResponse
--- @param next fun(err?: any)
return function(req, _, next)
local params_values = {}
for param_name in pairs(params_with_rules) do
Expand Down

0 comments on commit 4a9e198

Please sign in to comment.